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