-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumerical_analysis.py
More file actions
77 lines (62 loc) · 3.07 KB
/
numerical_analysis.py
File metadata and controls
77 lines (62 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import fdm as fdm
import numpy as np
import argparse
def generate_consecutive_array(first, last):
return list(range(first, last + 1))
def scheme_analysis():
print( " You are analysing a numerical scheme through giving a set of stencils **")
print( " A scheme should have a L.H.S stencil and a R.H.S. stencil **")
print( " First you need to input the range of the stencils, **")
print( " for example, for a stencil ranging from i-1 to i+2, you need to first input -1, and then input 1")
print(" >> The first node of the L.H.S. stencil: ", end='')
number_1 = int(input())
print(" >> The last node of the L.H.S. stencil: ", end='')
number_2 = int(input())
rhs_stencil = generate_consecutive_array(number_1,number_2)
rhs_stencil = np.array(rhs_stencil)
print(" >> The first node of the R.H.S. stencil: ", end='')
number_1 = int(input())
print(" >> The last node of the R.H.S. stencil: ", end='')
number_2 = int(input())
lhs_stencil = generate_consecutive_array(number_1,number_2)
lhs_stencil = np.array(lhs_stencil)
fdm.scheme_analysis_stencil(rhs_stencil,lhs_stencil)
def scheme_derive():
first_node_left,last_node_left = input(" >> input the first and last nodes on the LHS of the scheme: ").split()
first_node_left = int(first_node_left)
last_node_left = int(last_node_left)
first_node_right,last_node_right = input(" >> input the first and last nodes on the RHS of the scheme: ").split()
first_node_right = int(first_node_right)
last_node_right = int(last_node_right)
order_of_accuracy = input(" >> input the order of the scheme: ")
order_of_accuracy = int(order_of_accuracy)
fdm.scheme_derive_parameter(first_node_left,last_node_left,first_node_right,last_node_right,order_of_accuracy)
# this is to show the scheme definition:
def filter_analysis():
print( " You are analysing a filter scheme through giving a set of stencils **")
print( " A sfilter cheme should have a L.H.S stencil and a R.H.S. stencil **")
print( " First you need to input the range of the stencils, **")
print( " for example, for a stencil ranging from i-1 to i+2, you need to first input -1, and then input 1")
print(" >> The first node of the L.H.S. stencil: ", end='')
number_1 = int(input())
print(" >> The last node of the L.H.S. stencil: ", end='')
number_2 = int(input())
lhs_stencil = generate_consecutive_array(number_1,number_2)
lhs_stencil = np.array(lhs_stencil)
print(" >> The first node of the R.H.S. stencil: ", end='')
number_1 = int(input())
print(" >> The last node of the R.H.S. stencil: ", end='')
number_2 = int(input())
rhs_stencil = generate_consecutive_array(number_1,number_2)
rhs_stencil = np.array(rhs_stencil)
fdm.filter_analysis_stencil(lhs_stencil,rhs_stencil)
def main():
mode = input("Select analysis mode [[f]ilter/[d]erivative]: ").strip().lower()
if mode == "f":
filter_analysis()
elif mode == "d":
scheme_analysis()
else:
print("Invalid input. Please enter 'filter' or 'derivative'.")
if __name__ == '__main__':
main()