Peano
static-limiting-tohoku.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, exahype2
4 
5 from FWave import fWave, rusanov
6 
7 project = exahype2.Project(
8  ["tests", "exahype2", "aderdg"], ".", executable="ADERDG-Limiting"
9 )
10 
11 dimensions = 2
12 min_level = 4
13 max_depth = 0
14 order = 5
15 end_time = 7000.0
16 plot_interval = 500.0
17 
18 offset = [0.0, 1.2e6]
19 size = [2.0e6, 2.0e6]
20 
21 max_h = 1.1 * min(size) / (3.0**min_level)
22 min_h = max_h / (3.0**max_depth)
23 
24 initial_conditions = """
25  static tarch::reader::TopologyParser topologyParser(
26  \"tohoku_gebco_ucsb3_2000m_hawaii_bath.nc\",
27  \"tohoku_gebco_ucsb3_2000m_hawaii_displ.nc\",
28  7000000,//DomainSize(0),
29  4000000,//DomainSize(1),
30  0.,//DomainOffset(0),
31  0.//DomainOffset(1)
32  );
33 
34  const double bathymetryBeforeEarthquake = topologyParser.sampleBathymetry(x(0), x(1));
35  const double displacement = topologyParser.sampleDisplacement(x(0), x(1));
36  const double bathymetryAfterEarthquake = bathymetryBeforeEarthquake + displacement;
37 
38  Q[0] = -1*std::min(bathymetryBeforeEarthquake, 0.0);
39  Q[1] = 0.0;
40  Q[2] = 0.0;
41  Q[3] = bathymetryAfterEarthquake;
42 """
43 
44 boundary_conditions = """
45  initialCondition(
46  Qoutside, x, h, false
47  );
48 """
49 
50 flux = """
51  double ih = 1.0 / Q[0];
52 
53  F[0] = Q[1 + normal];
54  F[1] = Q[1 + normal] * Q[1] * ih;
55  F[2] = Q[1 + normal] * Q[2] * ih;
56  F[3] = 0.0;
57 """
58 
59 ncp = """
60  std::fill_n(BTimesDeltaQ, NumberOfUnknowns, 0.0);
61 
62  constexpr double grav = 9.81;
63  BTimesDeltaQ[normal+1] = grav * Q[0] * (deltaQ[0] + deltaQ[3]);
64 """
65 
66 max_eval = """
67  constexpr double grav = 9.81;
68 
69  const double u = Q[1 + normal] / Q[0];
70  const double c = std::sqrt(grav * Q[0]);
71 
72  return std::max(std::abs(u + c), std::abs(u - c));
73 """
74 
75 limiting_criterion = """
76 if(x[0]<=0.5*DomainSize[0]){
77  return Q[0] > 100.0;
78 }
79 else{
80  return true;
81 }
82 """
83 
84 aderdg_solver = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
85  name="ADERDGSolver",
86  order=order,
87  unknowns=4,
88  auxiliary_variables=0,
89  min_cell_h=min_h,
90  max_cell_h=max_h,
91  time_step_relaxation=0.9,
92  flux=flux, ncp=ncp,
93  eigenvalues=max_eval,
94  initial_conditions=initial_conditions,
95  boundary_conditions=boundary_conditions,
96 )
97 aderdg_solver.add_kernel_optimisations(
98  polynomials=exahype2.solvers.aderdg.Polynomials.Gauss_Lobatto,
99  riemann_solver_implementation = rusanov,
100 # precision = args.precision
101 )
102 aderdg_solver.add_user_solver_includes("""
103 #include "tarch/reader/TopologyParser.h"
104 """)
105 project.add_solver(aderdg_solver)
106 
107 
108 
109 # aderdg_solver2 = exahype2.solvers.aderdg.GlobalAdaptiveTimeStep(
110 # name="ADERDGSolver2",
111 # order=order,
112 # unknowns=4,
113 # auxiliary_variables=0,
114 # min_cell_h=min_h,
115 # max_cell_h=max_h,
116 # time_step_relaxation=0.9,
117 # flux=flux, ncp=ncp,
118 # eigenvalues=max_eval,
119 # initial_conditions=initial_conditions,
120 # boundary_conditions=boundary_conditions,
121 # )
122 # aderdg_solver2.add_kernel_optimisations(
123 # polynomials=exahype2.solvers.aderdg.Polynomials.Gauss_Lobatto,
124 # riemann_solver_implementation = rusanov,
125 # precision = "fp64"
126 # )
127 # aderdg_solver2.add_user_solver_includes("""
128 # #include "tarch/reader/TopologyParser.h"
129 # """)
130 # project.add_solver(aderdg_solver2)
131 
132 # ##########################################
133 
134 # from fuseADERSolvers import fuseADERSolvers
135 
136 # fuseADERSolvers(
137 # aderdg_solver, aderdg_solver2,
138 # "\nmarker.x()[0]<=(DomainOffset[0]+0.5*DomainSize[0]+0.51*marker.h()[0])\n",
139 # "\nmarker.x()[0]>=(DomainOffset[0]+0.5*DomainSize[0]+0.49*marker.h()[0])\n"
140 # )
141 
142 
143 
144 fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
145  name="FVSolver",
146  patch_size=2 * order + 1,
147  unknowns={"h": 1, "hu": 1, "hv": 1},
148  auxiliary_variables={"b": 1},
149  min_volume_h=min_h,
150  max_volume_h=max_h,
151  time_step_relaxation=0.9,
152 
153 )
154 fv_solver.set_implementation(
155  flux=flux,
156  ncp=ncp,
157  max_eigenvalue=max_eval,
158  initial_conditions=initial_conditions,
159  boundary_conditions=boundary_conditions,
160  riemann_solver=fWave
161 )
162 fv_solver.add_user_solver_includes("""
163 #include "tarch/reader/TopologyParser.h"
164 """)
165 project.add_solver(fv_solver)
166 
167 
168 
169 limiter = exahype2.solvers.limiting.StaticLimiting(
170  name="LimitingSolver",
171  regular_solver=aderdg_solver,
172  limiting_solver=fv_solver,
173  limiting_criterion_implementation=limiting_criterion,
174 )
175 project.add_solver(limiter)
176 
177 
183 
184 # compute_time_step_size = """
185 # double timeStepSize = std::min( repositories::instanceOfADERDGSolver.getAdmissibleTimeStepSize(),
186 # std::min( repositories::instanceOfADERDGSolver2.getAdmissibleTimeStepSize(),
187 # repositories::instanceOfFVSolver.getAdmissibleTimeStepSize()
188 # ));
189 # """
190 
191 # aderdg_solver._compute_time_step_size = compute_time_step_size
192 # aderdg_solver2._compute_time_step_size = compute_time_step_size
193 # fv_solver._compute_time_step_size = compute_time_step_size
194 
195 
196 project.set_output_path("solutions")
197 
198 build_mode = peano4.output.CompileMode.Release
199 
200 project.set_global_simulation_parameters(
201  dimensions=dimensions,
202  offset=offset[0:dimensions],
203  size=size[0:dimensions],
204  min_end_time=end_time,
205  max_end_time=end_time,
206  first_plot_time_stamp=0.0,
207  time_in_between_plots=plot_interval,
208  periodic_BC=[False, False, False][0:dimensions],
209 )
210 
211 project.set_load_balancing(
212  "toolbox::loadbalancing::strategies::SpreadOut",
213  "new ::exahype2::LoadBalancingConfiguration()",
214 )
215 project.set_Peano4_installation("../../../", build_mode)
216 project = project.generate_Peano4_project(verbose=False)
217 # project.set_fenv_handler(True) # TODO: Static limiter crashes with this
218 project.build(make_clean_first=True)
static double min(double const x, double const y)