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