Peano
Loading...
Searching...
No Matches
static-limiting-euler-airfoil.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=4,
13 degrees_of_freedom=6,
14)
15args = parser.parse_args()
16
17dimensions = 2
18order = args.degrees_of_freedom - 1
19end_time = 10
20plot_interval = 0.0 # 0.5
21
22size = [120, 120]
23offset = [-10, -60]
24max_h = 1.1 * min(size) / (3.0**args.min_depth)
25min_h = max_h / (3.0**args.amr_levels)
26
27init = """
28 // Parameters which define a symmetric NACA airfoil
29 constexpr double c = 100.;
30 constexpr double t = 0.12;
31
32 Q[0] = 1.0;
33 Q[1] = 0.1;
34 Q[2] = 0.0;
35 Q[3] = 1.0;
36
37 double yl = x[1] - h[1]/2;
38 double yu = x[1] + h[1]/2;
39 double volumePercentage = 1.0;
40
41 constexpr int nI = 50; // NumberOfIntegrationMeasurementPoints
42 const double hI = h[0] / nI;
43
44 for(int i=0; i<nI; i++){
45 double xI = x[0] + i * hI;
46 double yI = 5.0 * t * c * (
47 0.2969 * sqrt ( xI / c )
48 + ((((
49 - 0.1015 ) * ( xI / c )
50 + 0.2843 ) * ( xI / c )
51 - 0.3516 ) * ( xI / c )
52 - 0.1260 ) * ( xI / c ) ); // Specific function for a symmetric NACA airfoil
53
54 if( -yI<yl && yI>yu ){ // fully within the airfoil
55 volumePercentage -= hI ;
56 }
57 else if ( yI>yl && yI<yu && -yI<yl ){ // y in cell, -y below
58 volumePercentage -= hI*(yI - yl) / (yu - yl);
59 }
60 else if ( -yI<yu && -yI>yl && yI>yu){ // -y in cell, y above
61 volumePercentage -= hI*(yu + yI) / (yu - yl);
62 }
63 else if ( yI>yl && yI<yu && -yI<yu && -yI>yl ){ // -y and y both in cell
64 volumePercentage -= hI*( 2*yI ) / (yu - yl);
65 }
66 }
67
68 Q[4] = std::max(0.0, std::min(1.0, volumePercentage));
69"""
70
71boundaryCondition = """
72 if (normal == 0 && x[0] == DomainOffset[0]) {
73 Qoutside[0] = 1.0;
74 Qoutside[1] = 0.1;
75 Qoutside[2] = 0.0;
76 Qoutside[3] = 1.0;
77 Qoutside[4] = 1.0;
78 } else {
79 Qoutside[0] = Qinside[0];
80 Qoutside[1] = Qinside[1];
81 Qoutside[2] = Qinside[2];
82 Qoutside[3] = Qinside[3];
83 Qoutside[4] = 1.0;
84 }
85"""
86
87flux = """
88 const double irho = 1.0 / Q[0];
89 constexpr double Gamma = 1.4;
90 const double p = (Gamma - 1) * (Q[3] - 0.5 * irho * (Q[1]*Q[1]+Q[2]*Q[2]));
91
92 F[0] = Q[normal+1];
93 F[1] = Q[normal+1] * Q[1] * irho;
94 F[2] = Q[normal+1] * Q[2] * irho;
95 F[3] = Q[normal+1] * irho * (Q[3] + p);
96
97 F[normal+1] += p;
98"""
99
100eigenvalues = """
101 const double irho = 1.0 / Q[0];
102 constexpr double Gamma = 1.4;
103 const double p = (Gamma - 1) * (Q[3] - 0.5 * irho * (Q[1]*Q[1]+Q[2]*Q[2]));
104
105 const double c = std::sqrt(Gamma * p * irho);
106 const double u = Q[normal + 1] * irho;
107"""
108
109aderdg_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
110 name="ADERDGSolver",
111 order=order,
112 min_cell_h=min_h,
113 max_cell_h=max_h,
114 time_step_relaxation=0.5,
115 unknowns=4,
116 auxiliary_variables=1,
117)
118aderdg_solver.set_implementation(
119 initial_conditions=init,
120 boundary_conditions=boundaryCondition,
121 flux=flux,
122 max_eigenvalue=eigenvalues
123 + """
124 return std::fmax(std::fabs(u - c), std::fabs(u + c));""",
125)
126aderdg_solver.add_kernel_optimisations(
127 polynomials=exahype2.solvers.aderdg.ADERDG.Polynomials.Gauss_Lobatto
128)
129project.add_solver(aderdg_solver)
130
131fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
132 name="FVSolver",
133 patch_size=2 * order + 1,
134 min_volume_h=min_h,
135 max_volume_h=max_h,
136 time_step_relaxation=0.5,
137 unknowns=4,
138 auxiliary_variables=1
139)
140fv_solver.set_implementation(
141 flux=flux,
142 boundary_conditions=boundaryCondition,
143 initial_conditions=init,
144 riemann_solver="""
145 double LL[4];
146 double LR[4];
147 auto eigenvalues = [](
148 const double* const Q,
149 const tarch::la::Vector<DIMENSIONS, double>& x,
150 const tarch::la::Vector<DIMENSIONS, double>& h,
151 double t,
152 double dt,
153 int normal,
154 double* const L
155 ) -> void {
156 const double irho = 1.0 / Q[0];
157 constexpr double Gamma = 1.4;
158 const double p = (Gamma - 1) * (Q[3] - 0.5 * irho * (Q[1]*Q[1]+Q[2]*Q[2]));
159
160 const double c = std::sqrt(Gamma * p * irho);
161 const double u = Q[normal + 1] * irho;
162
163 L[0] = u - c;
164 L[1] = -u + c;
165 L[2] = u + c;
166 L[3] = -u + c;
167 };
168 eigenvalues(QL, x, h, t, dt, normal, LL);
169 eigenvalues(QR, x, h, t, dt, normal, LR);
170 const double sMax = std::max(*std::max_element(LL, LL + 4), *std::max_element(LR, LR + 4));
171
172 double fluxLeft[4];
173 double fluxRight[4];
174 flux(QL, x, h, t, dt, normal, fluxLeft);
175 flux(QR, x, h, t, dt, normal, fluxRight);
176
177 const double vL = QL[4];
178 const double vR = QR[4];
179
180 /*
181 Assuming anything that can't get into the other is reflected back to me.
182 own + what's reflected from what I send + what was sent to me and not reflected
183 Rl = vl*Fl + vl*Fl*(1-vr) + vr*Fr*vl
184 Rr = vr*Fr + vr*Fr*(1-vl) + vl*Fl*vr
185 */
186 for(int i=0; i<4; i++){
187 const double FLe = 0.5*vL*(fluxLeft[i]+sMax*QL[i]);
188 const double FRe = 0.5*vR*(fluxRight[i]-sMax*QR[i]);
189
190 //left going update
191 FL[i] = FLe*(2-vR) + vL*FRe;
192 //right going update
193 FR[i] = FRe*(2-vL) + vR*FLe;
194 }
195
196 return sMax;""",
197)
198project.add_solver(fv_solver)
199
200limiter = exahype2.solvers.limiting.StaticLimiting(
201 name="LimitingSolver",
202 regular_solver=aderdg_solver,
203 limiting_solver=fv_solver,
204 physical_admissibility_criterion="""return (Q[4] == 1.0);""",
205)
206project.add_solver(limiter)
207
208project.set_output_path("solutions")
209
210project.set_global_simulation_parameters(
211 dimensions=dimensions,
212 offset=offset[0:dimensions],
213 size=size[0:dimensions],
214 min_end_time=end_time,
215 max_end_time=end_time,
216 first_plot_time_stamp=0.0,
217 time_in_between_plots=plot_interval,
218 periodic_BC=[False, False],
219)
220
221project.set_load_balancer("new ::exahype2::LoadBalancingConfiguration")
222project.set_Peano4_installation("../../../", mode=peano4.output.string_to_mode(args.build_mode))
223project = project.generate_Peano4_project(verbose=False)
224project.set_fenv_handler(False)
225project.build()