-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_burgers_equation_1d_vs_cole_hopf.py
More file actions
152 lines (116 loc) · 3.16 KB
/
Copy pathrun_burgers_equation_1d_vs_cole_hopf.py
File metadata and controls
152 lines (116 loc) · 3.16 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
"""Run the 1D Burgers' & Cole-Hopf solvers and generate solution & comparision plots."""
import numpy as np
from core import (
BurgersEquation1DConfig,
cole_hopf_initial_condition_1d,
make_cole_hopf_x_grid,
solve_burgers_equation_1d,
solve_cole_hopf_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 = 6.0
num_grid_points_x = 101
max_iterations = 100
time_step = 0.0025
grid_type: str = "cole_hopf"
sigma = 0.02
viscosity = 0.07
hat_start = 0.5
hat_end = 1.0
u_min = 1.0
u_max = 2.0
# Visualization parameters
step_stride = 20
case_name = '1d burgers vs cole-hopf'
title = True
save = False
show_individual_plots = False
# Create the configuration object
burgers_1d_config = BurgersEquation1DConfig(
domain_length_x=domain_length_x,
num_grid_points_x=num_grid_points_x,
max_iterations=max_iterations,
time_step=time_step,
grid_type=grid_type,
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_cole_hopf_x_grid(burgers_1d_config)
time_array = np.arange(0, burgers_1d_config.max_iterations + 1)
# Initialize the initial condition
initial_condition = cole_hopf_initial_condition_1d(x_array, burgers_1d_config)
# Solve
# Numerical Burgers' equation
solution_history_num = solve_burgers_equation_1d(initial_condition, burgers_1d_config)
# Analytical Cole-Hopf equation
solution_history_ana = solve_cole_hopf_1d(x_array, burgers_1d_config)
# Post-processing
if show_individual_plots:
show_solution_traces(
x_values=x_array,
cut_values=time_array,
num_solution_matrix=solution_history_num,
ana_solution_matrix=solution_history_ana,
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_num,
axis=1,
ana_solution_matrix=solution_history_ana,
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_num,
case_name=case_name,
title=title,
save=save,
)
show_solution_surface(
x_values=x_array,
y_values=time_array,
solution_matrix=solution_history_num,
case_name=case_name,
title=title,
save=save,
)
show_solution_overview(
x_values=x_array,
y_values=time_array,
num_solution_matrix=solution_history_num,
ana_solution_matrix=solution_history_ana,
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_num,
ana_solution_history=solution_history_ana,
case_name=case_name,
save=save,
)