@@ -16,23 +16,29 @@ def solve(self):
16
16
:return: the solver instance with the computed temperature values
17
17
"""
18
18
19
- x = self .equation .generate_x_grid ( )
20
- dx = x [ 1 ] - x [ 0 ]
19
+ x = self .equation .generate_grid ( self . equation . length , self . equation . x_nodes )
20
+ t = self . equation . generate_grid ( self . equation . time , self . equation . t_nodes )
21
21
22
+ dx = x [1 ] - x [0 ]
22
23
dt_max = 0.5 * (dx ** 2 ) / self .equation .k
23
- dt = 0.8 * dt_max
24
- time_step = int (self .equation .time / dt )
25
- self .equation .t_nodes = time_step
26
24
27
- t = np .linspace (0 , self .equation .time , self .equation .t_nodes )
25
+ if self .equation .t_nodes is None :
26
+ dt = 0.8 * dt_max
27
+ self .equation .t_nodes = int (self .equation .time / dt )
28
+ dt = self .equation .time / self .equation .t_nodes
29
+ else :
30
+ dt = t [1 ] - t [0 ]
28
31
29
- u = np .zeros ((time_step , self .equation .x_nodes ))
32
+ if dt > dt_max :
33
+ raise ValueError ("User-defined t nodes is too small and exceeds the CFL condition. Possible action: Increase number of t nodes for stability!" )
34
+
35
+ u = np .zeros ((self .equation .t_nodes , self .equation .x_nodes ))
30
36
31
37
u [0 , :] = self .equation .get_initial_temp (x )
32
38
u [:, 0 ] = self .equation .get_left_boundary (t )
33
39
u [:, - 1 ] = self .equation .get_right_boundary (t )
34
40
35
- for tau in range (0 , time_step - 1 ):
41
+ for tau in range (0 , self . equation . t_nodes - 1 ):
36
42
for i in range (1 , self .equation .x_nodes - 1 ):
37
43
u [tau + 1 ,i ] = u [tau , i ] + (dt * self .equation .k * (u [tau , i - 1 ] - 2 * u [tau , i ] + u [tau , i + 1 ]) / dx ** 2 )
38
44
@@ -49,8 +55,8 @@ def solve(self):
49
55
:return: the solver instance with the computed temperature values
50
56
"""
51
57
52
- x = self .equation .generate_x_grid ( )
53
- t = self .equation .generate_t_grid ( )
58
+ x = self .equation .generate_grid ( self . equation . length , self . equation . x_nodes )
59
+ t = self .equation .generate_grid ( self . equation . time , self . equation . t_nodes )
54
60
55
61
dx = x [1 ] - x [0 ]
56
62
dt = t [1 ] - t [0 ]
0 commit comments