Peano
Loading...
Searching...
No Matches
acoustic-point-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
3import peano4
4import exahype2
5
6parser = exahype2.ArgumentParser(
7 "ExaHyPE 2 - Finite Volumes Dynamic AMR Testing Script"
8)
9parser.set_defaults(
10 min_depth=2,
11 amr_levels=2,
12 degrees_of_freedom=4,
13 end_time=3.0,
14)
15args = parser.parse_args()
16
17max_patch_size = 1.1 * 10.0 / (3.0**args.min_depth)
18max_h = max_patch_size / args.degrees_of_freedom
19min_h = 0.9 * max_h * 3.0 ** (-args.amr_levels)
20
21initial_conditions = """
22 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
23 Q[i] = 0.0;
24 }
25"""
26
27boundary_conditions = """
28 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
29 Qoutside[i] = 0.0;
30 }
31"""
32
33refinement_criterion = """
34 auto result = ::exahype2::RefinementCommand::Keep;
35
36 static constexpr double sourceRadius = 0.5;
37 const tarch::la::Vector<DIMENSIONS, double> sourceCentre(1.0);
38
39 static constexpr double t0 = 0.7;
40 if (tarch::la::greaterEquals(t, 0.0) and tarch::la::smallerEquals(t, t0)) {
41 if (tarch::la::smallerEquals(tarch::la::norm2(x - sourceCentre), sourceRadius)) {
42 result = ::exahype2::RefinementCommand::Refine;
43 }
44 return result;
45 }
46
47 const double pAbs = std::abs(Q[Shortcuts::p]);
48
49 double u2 = 0.0;
50 for (int i = 0; i < DIMENSIONS; i++) {
51 const double ui = Q[Shortcuts::u + i];
52 u2 += ui * ui;
53 }
54 const double uMag = std::sqrt(u2);
55
56 const double indicator = std::max(pAbs, (RHO * WAVE_SPEED) * uMag);
57
58 static constexpr double refineThreshold = 0.20;
59 static constexpr double eraseThreshold = 0.10;
60
61 if (tarch::la::greaterEquals(indicator, refineThreshold)) {
62 result = ::exahype2::RefinementCommand::Refine;
63 } else if (tarch::la::smallerEquals(indicator, eraseThreshold)) {
64 result = ::exahype2::RefinementCommand::Erase;
65 }
66
67 return result;
68"""
69
70fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
71 name="FVSolver",
72 patch_size=args.degrees_of_freedom,
73 unknowns={"p": 1, "u": args.dimensions},
74 auxiliary_variables=0,
75 min_volume_h=min_h,
76 max_volume_h=max_h,
77 time_step_relaxation=0.5,
78)
79
80fv_solver.set_implementation(
81 initial_conditions=initial_conditions,
82 boundary_conditions=boundary_conditions,
83 refinement_criterion=refinement_criterion,
84 flux="""
85 static constexpr double K0 = RHO * WAVE_SPEED * WAVE_SPEED;
86
87 F[Shortcuts::p] = K0 * Q[normal + 1];
88 F[Shortcuts::u + 0] = 0.0;
89 F[Shortcuts::u + 1] = 0.0;
90#if DIMENSIONS == 3
91 F[Shortcuts::u + 2] = 0.0;
92#endif
93 F[normal + 1] = (1.0 / RHO) * Q[Shortcuts::p];
94
95""",
96 max_eigenvalue="return WAVE_SPEED;",
97 source_term="""
98 S[Shortcuts::p] = 0.0;
99 S[Shortcuts::u + 0] = 0.0;
100 S[Shortcuts::u + 1] = 0.0;
101#if DIMENSIONS == 3
102 S[Shortcuts::u + 2] = 0.0;
103#endif
104
105#if DIMENSIONS == 2
106 constexpr double sourceRadius = 0.10;
107 const bool sourceLocation = tarch::la::norm2(x - tarch::la::Vector<DIMENSIONS, double>({1.0, 1.0})) <= sourceRadius;
108#else
109 constexpr double sourceRadius = 0.10;
110 const bool sourceLocation = tarch::la::norm2(x - tarch::la::Vector<DIMENSIONS, double>({1.0, 1.0, 1.0})) <= sourceRadius;
111#endif
112
113 if (sourceLocation) {
114 static constexpr double t0 = 0.7;
115 static constexpr double M0 = 1000.0;
116 const double force = M0 * std::exp(-((t - t0) * (t - t0)) / (2.0 * SIGMA * SIGMA));
117 S[Shortcuts::p] = force;
118 }
119""",
120)
121
122project = exahype2.Project(
123 namespace=["tests", "exahype2", "fv"],
124 project_name=".",
125 directory=".",
126 executable="ExaHyPE",
127)
128project.add_solver(fv_solver)
129
130if args.number_of_snapshots <= 0:
131 time_in_between_plots = 0.0
132else:
133 time_in_between_plots = args.end_time / args.number_of_snapshots
134 project.set_output_path(args.output)
135
136project.set_global_simulation_parameters(
137 dimensions=args.dimensions,
138 size=[10.0, 10.0, 10.0][0 : args.dimensions],
139 offset=[0.0, 0.0, 0.0][0 : args.dimensions],
140 min_end_time=args.end_time,
141 max_end_time=args.end_time,
142 first_plot_time_stamp=0.0,
143 time_in_between_plots=time_in_between_plots,
144 periodic_BC=[
145 False,
146 False,
147 False,
148 ],
149)
150
151project.set_load_balancer("new ::exahype2::LoadBalancingConfiguration")
152project.set_build_mode(mode=peano4.output.string_to_mode(args.build_mode))
153project = project.generate_Peano4_project(verbose=False)
154project.output.makefile.set_target_device(args.target_device)
155project.output.makefile.add_CXX_flag("-DRHO=2.7")
156project.output.makefile.add_CXX_flag("-DWAVE_SPEED=6.0")
157project.output.makefile.add_CXX_flag("-DSIGMA=0.1149")
158project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)