Peano
gaussian-explosion.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 os
4 import sys
5 
6 import peano4
7 import exahype2
8 
9 sys.path.insert(0, os.path.abspath(".."))
10 from PDE import max_eigenvalue, flux
11 
12 initial_conditions = """
13  /**
14  * With plain DG, Rusanov, and without an additional limiter, we cannot solve
15  * discontinuous initial conditions. At the moment, most of the scenarios
16  * are physically meaningless. The only setup that should work
17  * out-of-the-box is the Gaussian, as it is infinitely smooth. Having said
18  * this, the Gaussian still can run into problems if it is too steep: If the
19  * polynomial order and mesh resolution are too low, the Gaussian continues
20  * to look like a discontinuous initial condition and thus introduces
21  * problems. Therefore, we scale its diameter with the maximum cell width. In
22  * a real setup, we should also take the polynomial order into account.
23  */
24 
25  // Manual offset to make the wave originate slightly to the left of the center
26  // --- helps to detect if wave is moving to the left or right.
27 #if DIMENSIONS == 2
28  const tarch::la::Vector<DIMENSIONS, double> circleCentre = {0.5, 0.3};
29 #else
30  const tarch::la::Vector<DIMENSIONS, double> circleCentre = {0.18, 0.3, 0.6};
31 #endif
32 
33  const double peakDeviation = MaxAdmissibleCellH;
34  const double distance = tarch::la::norm2(x - circleCentre);
35  const double exponent = -(distance * distance) / 2.0 / peakDeviation / peakDeviation;
36 
37  Q[Shortcuts::rho] = 0.1;
38  Q[Shortcuts::rhoU + 0] = 0.0;
39  Q[Shortcuts::rhoU + 1] = 0.0;
40 #if DIMENSIONS == 3
41  Q[Shortcuts::rhoU + 2] = 0.0;
42 #endif
43  Q[Shortcuts::rhoE] = 1.0 + std::exp(exponent);
44 """
45 
46 boundary_conditions = """
47  // Reflective boundary conditions
48  Qoutside[Shortcuts::rho] = Qinside[Shortcuts::rho];
49  Qoutside[Shortcuts::rhoU + 0] = -Qinside[Shortcuts::rhoU + 0];
50  Qoutside[Shortcuts::rhoU + 1] = -Qinside[Shortcuts::rhoU + 1];
51 #if DIMENSIONS == 3
52  Qoutside[Shortcuts::rhoU + 2] = -Qinside[Shortcuts::rhoU + 2];
53 #endif
54  Qoutside[Shortcuts::rhoE] = Qinside[Shortcuts::rhoE];
55 """
56 
57 refinement_criterion = """
58  auto result = ::exahype2::RefinementCommand::Keep;
59 
60 #if DIMENSIONS == 3
61  tarch::la::Vector<DIMENSIONS, double> circleCentre = {0.5, 0.5, 0.5};
62 #else
63  tarch::la::Vector<DIMENSIONS, double> circleCentre = {0.5, 0.5};
64 #endif
65 
66  if (tarch::la::equals(t, 0.0)) {
67  if (tarch::la::norm2(x - circleCentre) < 0.1) {
68  result = ::exahype2::RefinementCommand::Refine;
69  }
70  }
71 
72  return result;
73 """
74 
75 parser = exahype2.ArgumentParser(
76  "ExaHyPE 2 Euler Gaussian Explosion Argument Parser"
77 )
78 parser.set_defaults(
79  min_depth=6,
80  degrees_of_freedom=16,
81 )
82 args = parser.parse_args()
83 
84 size = [1.0, 1.0, 1.0]
85 max_h = 1.1 * min(size) / (3.0**args.min_depth)
86 min_h = max_h * 3.0 ** (-args.amr_levels)
87 
88 riemann_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
89  name="FVSolver",
90  patch_size=args.degrees_of_freedom,
91  unknowns={"rho": 1, "rhoU": args.dimensions, "rhoE": 1},
92  auxiliary_variables=0,
93  min_volume_h=min_h,
94  max_volume_h=max_h,
95  time_step_relaxation=args.time_step_relaxation,
96  use_enclave_tasking=args.enclave_tasking,
97  number_of_enclave_tasks=args.ntasks,
98 )
99 
100 riemann_solver.set_implementation(
101  initial_conditions=initial_conditions,
102  boundary_conditions=boundary_conditions,
103  refinement_criterion=refinement_criterion,
104  max_eigenvalue=max_eigenvalue,
105  flux=flux,
106 )
107 
108 riemann_solver.set_plotter(args.plotter)
109 
110 project = exahype2.Project(
111  namespace=["applications", "exahype2", "euler"],
112  project_name="GaussianExplosion",
113  directory=".",
114  executable="Euler",
115 )
116 project.add_solver(riemann_solver)
117 
118 if args.number_of_snapshots <= 0:
119  time_in_between_plots = 0.0
120 else:
121  time_in_between_plots = args.end_time / args.number_of_snapshots
122  project.set_output_path(args.output)
123 
124 project.set_global_simulation_parameters(
125  dimensions=args.dimensions,
126  size=size[0 : args.dimensions],
127  offset=[0.0, 0.0, 0.0][0 : args.dimensions],
128  min_end_time=args.end_time,
129  max_end_time=args.end_time,
130  first_plot_time_stamp=0.0,
131  time_in_between_plots=time_in_between_plots,
132  periodic_BC=[
133  args.periodic_boundary_conditions_x,
134  args.periodic_boundary_conditions_y,
135  args.periodic_boundary_conditions_z,
136  ],
137 )
138 
139 project.set_load_balancer(
140  f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees}, {args.trees})"
141 )
142 project.set_Peano4_installation(
143  "../../../../", mode=peano4.output.string_to_mode(args.build_mode)
144 )
145 project = project.generate_Peano4_project(verbose=False)
146 project.set_fenv_handler(args.fpe)
147 project.output.makefile.set_target_device(args.target_device)
148 project.output.makefile.add_CXX_flag("-DGAMMA=1.4")
149 project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
static double min(double const x, double const y)