Peano
aderdg-wetting-drying.py
Go to the documentation of this file.
1 import os, sys
2 import peano4, exahype2
3 
4 project = exahype2.Project(["exahype", "limiting", "swe"], ".", executable="SWE")
5 
6 min_level = 3
7 max_depth = 0
8 order = 5
9 
10 # scenario = "simple_beach"
11 scenario = "oscillating_lake"
12 
13 if scenario=="simple_beach":
14  e_t = 100.0 #end_time
15  offset = [-10.0, 0.0]
16  size = [ 70.0, 70.0]
17  init = """
18  constexpr double Hd = 0.0185;
19  constexpr double d = 0.3;
20 
21  constexpr double H = Hd * d;
22  constexpr double beta = std::atan(1/19.85);
23 
24  constexpr double gamma = std::sqrt((3*H)/(4*d));
25  constexpr double x0 = d * cos(beta)/sin(beta);
26  constexpr double L = d * std::log(std::sqrt(20) + std::sqrt(20 - 1)) / gamma;
27  const double eta = H * (1/(std::cosh(gamma*(x[0]-(x0 + L))/d))) * (1/(std::cosh(gamma*(x[0]-(x0 + L))/d)));
28 
29  if (x[0] < 0){
30  Q[0] = 0;
31  Q[3] = -x[0] * std::sin(beta)/std::cos(beta) + d;
32  }
33  else if (x[0] <= x0){
34  Q[0] = x[0] * std::sin(beta)/std::cos(beta);
35  Q[3] = d - Q[0];
36  }
37  else{
38  Q[0] = H * (1/(std::cosh(gamma*(x[0]-(x0 + L))/d))) * (1/(std::cosh(gamma*(x[0]-(x0 + L))/d))) + d;
39  Q[3] = 0;
40  }
41  Q[1] = -eta * std::sqrt(9.81/d) * Q[0];
42  Q[2] = 0.0;
43 """
44 
45 elif scenario=="oscillating_lake":
46  e_t = 3.0 #end_time
47  offset = [-2.0, -2.0]
48  size = [ 4.0, 4.0]
49  init = """
50 
51  /*
52  Q[3] = 0.1 * (x[0]*x[0] + x[1]*x[1]);
53  Q[0] = std::max(0.0, 0.1 * (x[0] * cos(omega * 0) + x[1] * sin(omega * 0)) + 0.075 - Q[3]);
54  Q[1] = 0.5 * omega * sin(omega * 0) * Q[0];
55  Q[2] = 0.5 * omega * cos(omega * 0) * Q[0];
56  */
57 
58  //Original source:
59  // doi: 10.1017/S0022112081001882
60 
61  //More legible, translated into the form we are using:
62  // doi: 10.4208/cicp.070114.271114a
63 
64  constexpr double a = 1.0;
65  constexpr double h0 = 0.1;
66  constexpr double sigma = 0.5;
67  const double omega = std::sqrt(2*9.81*h0)/a;
68 
69  Q[3] = (h0 / (a*a)) * (x[0]*x[0] + x[1]*x[1]) ;
70  Q[0] = std::max(0.0, (sigma*h0/(a*a)) * (2 * x[0] * cos(omega * 0) + 2 * x[1] * sin(omega * 0) - sigma) + h0 - Q[3]);
71  Q[1] = -sigma * omega * sin(omega * 0) * Q[0];
72  Q[2] = sigma * omega * cos(omega * 0) * Q[0];
73 """
74 
75 
76 max_h = 1.1 * min(size) / (3.0**min_level)
77 min_h = max_h / (3.0**max_depth)
78 
79 
80 boundary_conditions = """
81  std::copy_n(Qinside, 4, Qoutside);
82  Qoutside[normal+1] = -Qinside[normal+1];
83 """
84 
85 aderSolver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
86  name = "aderSWE", order = 3,
87  min_cell_h = min_h, max_cell_h = max_h,
88  time_step_relaxation = 0.9,
89  unknowns = 4,
90  auxiliary_variables = 0,
91 )
92 
93 aderSolver.set_implementation(
94  initial_conditions = init,
95  boundary_conditions = boundary_conditions,
96  max_eigenvalue = exahype2.solvers.PDETerms.User_Defined_Implementation,
97  flux = exahype2.solvers.PDETerms.User_Defined_Implementation,
98  ncp = exahype2.solvers.PDETerms.User_Defined_Implementation,
99 # refinement_criterion = exahype2.solvers.PDETerms.User_Defined_Implementation,
100  riemann_solver=exahype2.solvers.PDETerms.User_Defined_Implementation,
101 )
102 
103 aderSolver.add_kernel_optimisations(
104  polynomials=exahype2.solvers.aderdg.ADERDG.Polynomials.Gauss_Lobatto,
105 )
106 
107 project.add_solver(aderSolver)
108 
109 fvSolver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
110  name = "fvSWE",
111  patch_size = 2*order+1,
112  min_volume_h = min_h,
113  max_volume_h = max_h,
114  time_step_relaxation = 0.9,
115  unknowns = 3,
116  auxiliary_variables = 1,
117 )
118 fvSolver.set_implementation(
119  initial_conditions = "", #get set by ader solver
120  boundary_conditions = boundary_conditions,
121  eigenvalues = exahype2.solvers.PDETerms.User_Defined_Implementation,
122  flux = exahype2.solvers.PDETerms.User_Defined_Implementation,
123  riemann_solver = exahype2.solvers.PDETerms.User_Defined_Implementation
124 )
125 project.add_solver(fvSolver)
126 
127 #actual limiting solver
128 limiter = exahype2.solvers.limiting.PosterioriLimiting(
129  name = "limitingSolver",
130  regular_solver = aderSolver,
131  limiting_solver = fvSolver,
132  number_of_dmp_observables = 0,
133  dmp_relaxation_parameter = 0.001,
134  dmp_differences_scaling = 0.02,
135  physical_admissibility_criterion = """
136  if(Q[0] == 0.0)
137  return true;
138  if(Q[0] <= 20 * 1e-3)
139  return false;
140  return true;"""
141 )
142 project.add_solver(limiter)
143 
144 project.set_output_path(
145  "posterioriSolutions_o_" + str(order)
146  + "_l_" + str(min_level)
147  + "_d_" + str(max_depth)
148 )
149 
150 dimensions = 2
151 build_mode = peano4.output.CompileMode.Release
152 
153 project.set_global_simulation_parameters(
154  dimensions = dimensions,
155  offset = offset[0:dimensions],
156  size = size[0:dimensions],
157  min_end_time = e_t,
158  max_end_time = e_t,
159  first_plot_time_stamp = 0.0,
160  time_in_between_plots = 0.1,
161  periodic_BC=[False, False, False][0:dimensions]
162 )
163 
164 project._project.output.makefile.set_Fortran_compiler("gfortran")
165 # project._project.output.makefile.add_Fortran_file("rpn2_testing.f90")
166 project._project.output.makefile.add_cpp_file("fvSWE.cpp")
167 project._project.output.makefile.add_cpp_file("aderSWE.cpp")
168 
169 project.set_load_balancer("new ::exahype2::LoadBalancingConfiguration")
170 project.set_Peano4_installation("../../../", build_mode)
171 peano4_project = project.generate_Peano4_project(verbose=False)
172 peano4_project.build(make_clean_first=True)
static double min(double const x, double const y)
str
Definition: ccz4.py:55