Peano
Loading...
Searching...
No Matches
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
3import os
4import sys
5
6import peano4
7import exahype2
8
9sys.path.insert(0, os.path.abspath(".."))
10from PDE import max_eigenvalue, flux
11
12initial_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
27analytical_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
55parser = exahype2.ArgumentParser("ExaHyPE 2 - Euler Gaussian Bell Argument Parser")
56parser.set_defaults(
57 min_depth=6,
58 # end_time=2.0,
59 degrees_of_freedom=16,
60 periodic_boundary_conditions_x=True,
61 periodic_boundary_conditions_y=True,
62 periodic_boundary_conditions_z=True,
63)
64args = parser.parse_args()
65
66size = [1.0, 1.0, 1.0]
67max_h = 1.1 * min(size) / (3.0**args.min_depth)
68min_h = max_h * 3.0 ** (-args.amr_levels)
69
70riemann_solver = exahype2.solvers.fv.musclhancock.GlobalAdaptiveTimeStep(
71 name="MUSCLHancockSolver",
72 patch_size=args.degrees_of_freedom,
73 unknowns={"rho": 1, "rhoU": args.dimensions, "rhoE": 1},
74 auxiliary_variables=0,
75 min_volume_h=min_h,
76 max_volume_h=max_h,
77 time_step_relaxation=0.5,
78)
79
80riemann_solver.set_implementation(
81 initial_conditions=initial_conditions,
82 flux=flux,
83 max_eigenvalue=max_eigenvalue,
84 limiter=exahype2.solvers.fv.musclhancock.Limiter.minmod,
85)
86
87riemann_solver.set_plotter(args.plotter)
88
89exahype2.solvers.fv.ErrorMeasurement(
90 riemann_solver,
91 error_measurement_implementation=analytical_solution,
92 output_file_name="Error",
93)
94
95project = exahype2.Project(
96 namespace=["applications", "exahype2", "euler"],
97 project_name="GaussianBell",
98 directory=".",
99 executable="Euler",
100)
101
102project.add_solver(riemann_solver)
103
104if args.number_of_snapshots <= 0:
105 time_in_between_plots = 0.0
106else:
107 time_in_between_plots = args.end_time / args.number_of_snapshots
108 project.set_output_path(args.output)
109
110project.set_global_simulation_parameters(
111 dimensions=args.dimensions,
112 size=size[0 : args.dimensions],
113 offset=[-0.5, -0.5, -0.5][0 : args.dimensions],
114 min_end_time=args.end_time,
115 max_end_time=args.end_time,
116 first_plot_time_stamp=0.0,
117 time_in_between_plots=time_in_between_plots,
118 periodic_BC=[
119 args.periodic_boundary_conditions_x,
120 args.periodic_boundary_conditions_y,
121 args.periodic_boundary_conditions_z,
122 ],
123)
124
125project.set_load_balancer(
126 f"new ::exahype2::LoadBalancingConfiguration({args.load_balancing_quality}, 1, {args.trees}, {args.trees})"
127)
128project.set_Peano4_installation(
129 "../../../../", mode=peano4.output.string_to_mode(args.build_mode)
130)
131project = project.generate_Peano4_project(verbose=False)
132project.set_fenv_handler(args.fpe)
133project.output.makefile.set_target_device(args.target_device)
134project.output.makefile.add_CXX_flag("-DGAMMA=1.4")
135project.output.makefile.add_CXX_flag("-DPRESSURE=1.0")
136project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)