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