-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_diffusion_1d.py
More file actions
137 lines (104 loc) · 2.63 KB
/
Copy pathrun_diffusion_1d.py
File metadata and controls
137 lines (104 loc) · 2.63 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
"""Run the 1D diffusion solver and generate solution plots."""
import numpy as np
from core import (
Diffusion1DConfig,
hat_initial_condition_1d,
make_x_grid,
solve_diffusion_1d,
)
from post_processing import (
show_solution_1d_animation,
show_solution_contour_map,
show_solution_overview,
show_solution_surface,
show_solution_traces,
)
# Pre-processing
# Simulation parameters
domain_length_x = 2.0
num_grid_points_x = 41
max_iterations = 41
sigma = 0.2
viscosity = 0.3
hat_start = 0.5
hat_end = 1.0
u_min = 1.0
u_max = 2.0
# Visualization parameters
step_stride = 20
case_name = '1d diffusion'
title = True
save = False
show_individual_plots = False
# Create the configuration object
diffusion_1d_config = Diffusion1DConfig(
domain_length_x=domain_length_x,
num_grid_points_x=num_grid_points_x,
max_iterations=max_iterations,
sigma=sigma,
viscosity=viscosity,
hat_start=hat_start,
hat_end=hat_end,
u_min=u_min,
u_max=u_max,
)
# Generate the grid and time array
x_array = make_x_grid(diffusion_1d_config)
time_array = np.arange(0, diffusion_1d_config.max_iterations + 1)
# Initialize the initial condition
initial_condition = hat_initial_condition_1d(x_array, diffusion_1d_config)
# Solve the diffusion equation
solution_history = solve_diffusion_1d(initial_condition, diffusion_1d_config)
# Post-processing
if show_individual_plots:
show_solution_traces(
x_values=x_array,
cut_values=time_array,
num_solution_matrix=solution_history,
step_stride=step_stride,
case_name=case_name,
title=title,
save=save,
)
show_solution_traces(
x_values=time_array,
cut_values=x_array,
num_solution_matrix=solution_history,
axis=1,
step_stride=step_stride,
cut_label='x',
case_name=case_name,
title=title,
save=save,
)
show_solution_contour_map(
x_values=x_array,
y_values=time_array,
solution_matrix=solution_history,
case_name=case_name,
title=title,
save=save,
)
show_solution_surface(
x_values=x_array,
y_values=time_array,
solution_matrix=solution_history,
case_name=case_name,
title=title,
save=save,
)
show_solution_overview(
x_values=x_array,
y_values=time_array,
num_solution_matrix=solution_history,
step_stride=step_stride,
case_name=case_name,
title=title,
save=save,
)
show_solution_1d_animation(
x_values=x_array,
num_solution_history=solution_history,
case_name=case_name,
save=save,
)