Peano
gaussian-bell.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  Q[Shortcuts::rho] = 0.02 * (1.0 + std::exp(-0.5 * tarch::la::norm2(x) * tarch::la::norm2(x) / 0.01));
14 
15  Q[Shortcuts::rhoU + 0] = 1.0 * Q[Shortcuts::rho];
16  Q[Shortcuts::rhoU + 1] = 1.0 * Q[Shortcuts::rho];
17 #if DIMENSIONS == 3
18  Q[Shortcuts::rhoU + 2] = 1.0 * Q[Shortcuts::rho];
19 #endif
20 
21  const tarch::la::Vector<DIMENSIONS, double> momenta(1.0 * Q[Shortcuts::rho]);
22 
23  // Should lead to a constant pressure over the domain given the initial conditions
24  Q[Shortcuts::rhoE] = PRESSURE / (GAMMA - 1.0) + 0.5 * (momenta * momenta) / Q[Shortcuts::rho];
25 """
26 
27 analytical_solution = """
28  // The initial condition is transported without deformation in a periodic
29  // domain [-.5, +.5], i.e. the value at a given point is the value at the
30  // position x - v*t but accounting for periodicity.
31  // Therefore we find the point x - v*t, and then shift this by instances
32  // of 1.0 until we find the point within the domain.
33 #if DIMENSIONS == 2
34  tarch::la::Vector<DIMENSIONS, double> pos = { (x[0] - t) + (int)(t + .5 - x[0]),
35  (x[1] - t) + (int)(t + .5 - x[1]) };
36 #else
37  tarch::la::Vector<DIMENSIONS, double> pos = { (x[0] - t) + (int)(t + .5 - x[0]),
38  (x[1] - t) + (int)(t + .5 - x[1]),
39  (x[2] - t) + (int)(t + .5 - x[2]) };
40 #endif
41 
42  solution[Shortcuts::rho] = 0.02 * (1.0 + std::exp(-0.5 * tarch::la::norm2(pos) * tarch::la::norm2(pos) / 0.01));
43  solution[Shortcuts::rhoU + 0] = 1.0 * solution[Shortcuts::rho];
44  solution[Shortcuts::rhoU + 1] = 1.0 * solution[Shortcuts::rho];
45 #if DIMENSIONS == 3
46  solution[Shortcuts::rhoU + 2] = 1.0 * solution[Shortcuts::rho];
47 #endif
48 
49  const tarch::la::Vector<DIMENSIONS, double> momenta(1.0 * solution[Shortcuts::rho]);
50 
51  // Should lead to a constant p over the domain given the initial conditions
52  solution[Shortcuts::rhoE] = PRESSURE / (GAMMA - 1.0) + 0.5 * (momenta * momenta) / solution[Shortcuts::rho];
53 """
54 
55 parser = exahype2.ArgumentParser(
56  "ExaHyPE 2 Euler Gaussian Bell Argument Parser"
57 )
58 parser.set_defaults(
59  min_depth=6,
60  #end_time=2.0,
61  degrees_of_freedom=16,
62  periodic_boundary_conditions_x=True,
63  periodic_boundary_conditions_y=True,
64  periodic_boundary_conditions_z=True,
65 )
66 args = parser.parse_args()
67 
68 size = [1.0, 1.0, 1.0]
69 max_h = 1.1 * min(size) / (3.0**args.min_depth)
70 min_h = max_h * 3.0 ** (-args.amr_levels)
71 
72 riemann_solver = exahype2.solvers.fv.musclhancock.GlobalAdaptiveTimeStep(
73  name="MUSCLHancockSolver",
74  patch_size=args.degrees_of_freedom,
75  unknowns={"rho": 1, "rhoU": args.dimensions, "rhoE": 1},
76  auxiliary_variables=0,
77  min_volume_h=min_h,
78  max_volume_h=max_h,
79  time_step_relaxation=args.time_step_relaxation,
80 )
81 
82 riemann_solver.set_implementation(
83  initial_conditions=initial_conditions,
84  flux=flux,
85  max_eigenvalue=max_eigenvalue,
86  limiter=exahype2.solvers.fv.musclhancock.Limiter.minmod,
87 )
88 
89 riemann_solver.set_plotter(args.plotter)
90 
91 exahype2.solvers.fv.ErrorMeasurement(
92  riemann_solver,
93  error_measurement_implementation=analytical_solution,
94  output_file_name="Error",
95 )
96 
97 project = exahype2.Project(
98  namespace=["applications", "exahype2", "euler"],
99  project_name="GaussianBell",
100  directory=".",
101  executable="Euler",
102 )
103 
104 project.add_solver(riemann_solver)
105 
106 if args.number_of_snapshots <= 0:
107  time_in_between_plots = 0.0
108 else:
109  time_in_between_plots = args.end_time / args.number_of_snapshots
110  project.set_output_path(args.output)
111 
112 project.set_global_simulation_parameters(
113  dimensions=args.dimensions,
114  size=size[0 : args.dimensions],
115  offset=[-0.5, -0.5, -0.5][0 : args.dimensions],
116  min_end_time=args.end_time,
117  max_end_time=args.end_time,
118  first_plot_time_stamp=0.0,
119  time_in_between_plots=time_in_between_plots,
120  periodic_BC=[
121  args.periodic_boundary_conditions_x,
122  args.periodic_boundary_conditions_y,
123  args.periodic_boundary_conditions_z,
124  ],
125 )
126 
127 project.set_load_balancer(
128  f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees}, {args.trees})"
129 )
130 project.set_Peano4_installation(
131  "../../../../", mode=peano4.output.string_to_mode(args.build_mode)
132 )
133 project = project.generate_Peano4_project(verbose=False)
134 project.set_fenv_handler(args.fpe)
135 project.output.makefile.set_target_device(args.target_device)
136 project.output.makefile.add_CXX_flag("-DGAMMA=1.4")
137 project.output.makefile.add_CXX_flag("-DPRESSURE=1.0")
138 project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)
static double min(double const x, double const y)