Peano
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
3 import peano4
4 import exahype2
5 
6 project = exahype2.Project(
7  ["tests", "exahype2", "aderdg"], ".", executable="ADERDG-Limiting"
8 )
9 
10 parser = exahype2.ArgumentParser("ExaHyPE 2 - ADER-DG Limiting Testing Script")
11 parser.set_defaults(
12  min_depth=4,
13  degrees_of_freedom=6,
14 )
15 args = parser.parse_args()
16 
17 dimensions = 2
18 order = args.degrees_of_freedom - 1
19 end_time = 10
20 plot_interval = 0.0 # 0.5
21 
22 size = [120, 120]
23 offset = [-10, -60]
24 max_h = 1.1 * min(size) / (3.0**args.min_depth)
25 min_h = max_h / (3.0**args.amr_levels)
26 
27 init = """
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 
71 boundaryCondition = """
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 
87 flux = """
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 
100 eigenvalues = """
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 
109 aderdg_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 )
118 aderdg_solver.set_implementation(
119  initial_conditions=init,
120  boundary_conditions=boundaryCondition,
121  flux=flux,
122  max_eigenvalue=eigenvalues
123  + """
124  return std::max(std::abs(u-c), std::abs(u+c));""",
125 )
126 aderdg_solver.add_kernel_optimisations(
127  polynomials=exahype2.solvers.aderdg.ADERDG.Polynomials.Gauss_Lobatto
128 )
129 project.add_solver(aderdg_solver)
130 
131 fv_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 )
140 fv_solver.set_implementation(
141  flux=flux,
142  boundary_conditions=boundaryCondition,
143  initial_conditions=init,
144  eigenvalues=eigenvalues
145  + """
146  L[0] = u-c;
147  L[1] = -u+c;
148  L[2] = u+c;
149  L[3] = -u+c;""",
150  riemann_solver="""
151  double LL[4];
152  double LR[4];
153  eigenvalues(QL, x, h, t, dt, normal, LL);
154  eigenvalues(QR, x, h, t, dt, normal, LR);
155  const double sMax = std::max(*std::max_element(LL, LL+4), *std::max_element(LR, LR+4));
156 
157  double fluxLeft[4];
158  double fluxRight[4];
159  flux(QL, x, h, t, dt, normal, fluxLeft);
160  flux(QR, x, h, t, dt, normal, fluxRight);
161 
162  const double vL = QL[4];
163  const double vR = QR[4];
164 
165  /*
166  Assuming anything that can't get into the other is reflected back to me.
167  own + what's reflected from what I send + what was sent to me and not reflected
168  Rl = vl*Fl + vl*Fl*(1-vr) + vr*Fr*vl
169  Rr = vr*Fr + vr*Fr*(1-vl) + vl*Fl*vr
170  */
171  for(int i=0; i<4; i++){
172  const double FLe = 0.5*vL*(fluxLeft[i]+sMax*QL[i]);
173  const double FRe = 0.5*vR*(fluxRight[i]-sMax*QR[i]);
174 
175  //left going update
176  FL[i] = FLe*(2-vR) + vL*FRe;
177  //right going update
178  FR[i] = FRe*(2-vL) + vR*FLe;
179  }
180 
181  return sMax;""",
182 )
183 project.add_solver(fv_solver)
184 
185 limiter = exahype2.solvers.limiting.StaticLimiting(
186  name="LimitingSolver",
187  regular_solver=aderdg_solver,
188  limiting_solver=fv_solver,
189  limiting_criterion_implementation="""return (Q[4] == 1.0);""",
190 )
191 project.add_solver(limiter)
192 
193 project.set_output_path("solutions")
194 
195 project.set_global_simulation_parameters(
196  dimensions=dimensions,
197  offset=offset[0:dimensions],
198  size=size[0:dimensions],
199  min_end_time=end_time,
200  max_end_time=end_time,
201  first_plot_time_stamp=0.0,
202  time_in_between_plots=plot_interval,
203  periodic_BC=[False, False],
204 )
205 
206 project.set_load_balancer("new ::exahype2::LoadBalancingConfiguration")
207 project.set_Peano4_installation("../../../", mode=peano4.output.string_to_mode(args.build_mode))
208 project = project.generate_Peano4_project(verbose=False)
209 project.set_fenv_handler(False)
210 project.build()
static double min(double const x, double const y)