Peano
Loading...
Searching...
No Matches
posteriori-limiting-euler-shock.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3import peano4
4import exahype2
5
6project = exahype2.Project(
7 ["tests", "exahype2", "aderdg"], ".", executable="ADERDG-Limiting"
8)
9
10parser = exahype2.ArgumentParser("ExaHyPE 2 - ADER-DG Limiting Testing Script")
11parser.set_defaults(
12 min_depth=3,
13 degrees_of_freedom=6,
14)
15args = parser.parse_args()
16
17use_aderdg = True
18use_fv = True
19use_limiting = use_aderdg and use_fv
20with_limiting = 1 # 0 - all ADER, 1 - limit, 2 - all FV
21
22dimensions = 2
23order = args.degrees_of_freedom - 1
24end_time = 2.0
25plot_interval = 0.00 # 0.05
26CFL = 0.5
27unknowns = {"rho": 1, "rhoU": 1, "rhoV": 1, "rhoE": 1}
28auxiliary = {}
29
30size = [2.0, 2.0, 2.0][0:dimensions]
31offset = [-1.0, -1.0, -1.0][0:dimensions]
32max_h = 1.1 * min(size) / (3.0**args.min_depth)
33min_h = max_h / (3.0**args.amr_levels)
34
35Gamma = 1.4
36OriginalShockPosition = 0.111
37pZero = 1e-4
38
39initial_conditions = f"""
40 constexpr double OriginalShockPosition = {OriginalShockPosition};
41 constexpr double Gamma = {Gamma};
42 const double p = (x[0] < -OriginalShockPosition && x[1] < -OriginalShockPosition) ? 0.1 : 1.0;
43
44 Q[0] = (x[0] < -OriginalShockPosition && x[1] < -OriginalShockPosition) ? 0.125 : 1.0;
45 Q[1] = 0.0;
46 Q[2] = 0.0;
47 Q[3] = p / (Gamma - 1.0);
48"""
49
50boundary_conditions = f"""
51 constexpr double OriginalShockPosition = {OriginalShockPosition};
52 constexpr double Gamma = {Gamma};
53 const double p = (x[0] < -OriginalShockPosition && x[1] < -OriginalShockPosition) ? 0.1 : 1.0;
54
55 Qoutside[0] = (x[0] < -OriginalShockPosition && x[1] < -OriginalShockPosition) ? 0.125 : 1.0;
56 Qoutside[1] = 0.0;
57 Qoutside[2] = 0.0;
58 Qoutside[3] = p / (Gamma - 1.0);
59"""
60
61flux = f"""
62 constexpr double Gamma = {Gamma};
63 constexpr double pZero = {pZero};
64 const double irho = Q[0] > 0.0 ? 1.0 / Q[0] : 0.0;
65 const double p = (Gamma - 1.0) * (Q[3] - 0.5 * irho * (Q[1]*Q[1]+Q[2]*Q[2]));
66
67 if (tarch::la::greater(p, pZero)) {{
68 F[0] = Q[normal + 1];
69 F[1] = Q[normal + 1] * Q[1] * irho;
70 F[2] = Q[normal + 1] * Q[2] * irho;
71 F[3] = Q[normal + 1] * irho * (Q[3] + p);
72 F[normal+1] += p;
73 }} else {{
74 F[0] = 0.0;
75 F[1] = 0.0;
76 F[2] = 0.0;
77 F[3] = 0.0;
78 }}
79"""
80
81max_eval = f"""
82 constexpr double Gamma = {Gamma};
83 constexpr double pZero = {pZero};
84 const double irho = Q[0] > 0.0 ? 1.0 / Q[0] : 0.0;
85 const double p = (Gamma - 1.0) * (Q[3] - 0.5 * irho*(Q[1]*Q[1]+Q[2]*Q[2]));
86
87 if (tarch::la::greater(p, pZero)) {{
88 const double c = std::sqrt(Gamma * p * irho);
89 const double un = Q[normal + 1] * irho;
90 return std::fmax(std::fabs(un - c), std::fabs(un + c));
91 }}
92 return 0.0;
93"""
94
95adjust_solution = f"""
96 constexpr double pZero = {pZero};
97 constexpr double Gamma = {Gamma};
98 const double irho = Q[0] > 0.0 ? 1.0 / Q[0] : 0.0;
99 const double p = (Gamma - 1.0) * (Q[3] - 0.5 * irho * (Q[1]*Q[1]+Q[2]*Q[2]));
100
101 if (tarch::la::smaller(p, pZero)) {{
102 Q[0] = 0.0;
103 Q[1] = 0.0;
104 Q[2] = 0.0;
105 Q[3] = 0.0;
106 }}
107"""
108
109isPhysicallyAdmissible = "return true;"
110if with_limiting == 0:
111 isPhysicallyAdmissible = "return true; //all ADERDG"
112elif with_limiting == 1:
113 isPhysicallyAdmissible = f"""
114 constexpr double Gamma = {Gamma};
115 constexpr double pZero = {pZero};
116 const double irho = Q[0] > 0.0 ? 1.0 / Q[0] : 0.0;
117 const double p = (Gamma - 1.0) * (Q[3] - 0.5 * irho * (Q[1]*Q[1]+Q[2]*Q[2]));
118
119 // Pressure, Density and Energy should be positive
120 if ((tarch::la::smaller(p, pZero)) // Pressure should be positive
121 or (Q[0] < 0.0) // Density should be positive
122 or (Q[3] < 0.0) // Energy should be positive
123 ) {{
124 return false;
125 }}
126
127 // Pressure, Density and Energy should be finite.
128 // If non-physical oscillations occur, the wave speed might receive a negative value under the square root.
129 // It results in eigenvalues becoming NaN, which are not marked as TROUBLED, if no isfinite check is performed.
130 for (int i = 0; i < {len(unknowns)}; ++i) {{
131 if (!std::isfinite(Q[i])) {{
132 return false;
133 }}
134 }}
135
136 return true;
137"""
138else:
139 isPhysicallyAdmissible = "return false; //all FV"
140
141if use_aderdg:
142 aderdg_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
143 name="ADERDGSolver",
144 order=order,
145 unknowns=unknowns,
146 auxiliary_variables=auxiliary,
147 min_cell_h=min_h,
148 max_cell_h=max_h,
149 time_step_relaxation=CFL,
150
151 )
152 aderdg_solver.set_implementation(
153 flux=flux,
154 max_eigenvalue=max_eval,
155 initial_conditions=initial_conditions,
156 boundary_conditions=boundary_conditions,
157 )
158 project.add_solver(aderdg_solver)
159
160if use_fv:
161 fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
162 name="FVSolver",
163 patch_size=2 * order + 1,
164 unknowns=unknowns,
165 auxiliary_variables=auxiliary,
166 min_volume_h=min_h,
167 max_volume_h=max_h,
168 time_step_relaxation=CFL,
169 )
170 fv_solver.set_implementation(
171 flux=flux,
172 max_eigenvalue=max_eval,
173 initial_conditions=initial_conditions,
174 boundary_conditions=boundary_conditions,
175 adjust_solution=adjust_solution,
176 )
177 project.add_solver(fv_solver)
178
179if use_limiting:
180 limiter = exahype2.solvers.limiting.PosterioriLimiting(
181 name="LimitingSolver",
182 regular_solver=aderdg_solver,
183 limiting_solver=fv_solver,
184 number_of_dmp_observables=len(unknowns),
185 dmp_relaxation_parameter=0.01, # 0.02 works for depth 2, 0.01 works for depth 3
186 dmp_differences_scaling=0.03, # 0.04 works for depth 2, 0.02 works for depth 3
187 physical_admissibility_criterion=isPhysicallyAdmissible,
188 )
189 project.add_solver(limiter)
190
191project.set_output_path("solutions")
192
193project.set_global_simulation_parameters(
194 dimensions=dimensions,
195 offset=offset[0:dimensions],
196 size=size[0:dimensions],
197 min_end_time=end_time,
198 max_end_time=end_time,
199 first_plot_time_stamp=0.0,
200 time_in_between_plots=plot_interval,
201 periodic_BC=[False, False, False][0:dimensions],
202)
203
204project.set_load_balancer("new ::exahype2::LoadBalancingConfiguration")
205project.set_Peano4_installation("../../../", mode=peano4.output.string_to_mode(args.build_mode))
206project = project.generate_Peano4_project(verbose=False)
207project.set_fenv_handler(True)
208project.build()