Peano
Loading...
Searching...
No Matches
fv-static-amr.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 - Finite Volumes Static AMR Testing Script")
7available_precisions = ["float", "double"]
8parser.add_argument(
9 "-pr", "--precision", default="double", help="|".join(available_precisions)
10)
11parser.set_defaults(
12 min_depth=4,
13 amr_levels=2,
14 degrees_of_freedom=16,
15 end_time=0.1,
16)
17args = parser.parse_args()
18
19max_h = 1.1 / 3.0**args.min_depth
20min_h = max_h * 3.0 ** (-args.amr_levels)
21
22initial_conditions = """
23 Q[Shortcuts::rho] = 1.0;
24 Q[Shortcuts::rhoU + 0] = 0.0;
25 Q[Shortcuts::rhoU + 1] = 0.0;
26#if DIMENSIONS == 2
27 Q[Shortcuts::rhoE] = ((std::sqrt(std::pow(0.5 - x(0), 2) + std::pow(0.5 - x(1), 2)) < 0.2) ? (1.0) : (1.01));
28#else
29 Q[Shortcuts::rhoU + 2] = 0.0;
30 Q[Shortcuts::rhoE] = ((std::sqrt(std::pow(0.5 - x(0), 2) + std::pow(0.5 - x(1), 2) + std::pow(0.5 - x(2), 2)) < 0.2) ? (1.0) : (1.01));
31#endif
32"""
33
34boundary_conditions = """
35 // Reflective boundary conditions
36 Qoutside[Shortcuts::rho] = Qinside[Shortcuts::rho];
37 Qoutside[Shortcuts::rhoU + 0] = -Qinside[Shortcuts::rhoU + 0];
38 Qoutside[Shortcuts::rhoU + 1] = -Qinside[Shortcuts::rhoU + 1];
39#if DIMENSIONS == 3
40 Qoutside[Shortcuts::rhoU + 2] = -Qinside[Shortcuts::rhoU + 2];
41#endif
42 Qoutside[Shortcuts::rhoE] = Qinside[Shortcuts::rhoE];
43"""
44
45refinement_criterion = """
46 auto result = ::exahype2::RefinementCommand::Keep;
47
48#if DIMENSIONS == 3
49 tarch::la::Vector<DIMENSIONS, double> circleCentre = {0.5, 0.5, 0.5};
50#else
51 tarch::la::Vector<DIMENSIONS, double> circleCentre = {0.5, 0.5};
52#endif
53
54 if (tarch::la::equals(t, 0.0)) {
55 if (tarch::la::norm2(x - circleCentre) < 0.1) {
56 result = ::exahype2::RefinementCommand::Refine;
57 }
58 }
59
60 return result;
61"""
62
63compute_primitive_variables = r"""
64 const auto irho = 1.0 / Q[Shortcuts::rho];
65 const auto u0 = Q[Shortcuts::rhoU + 0] * irho;
66 const auto u1 = Q[Shortcuts::rhoU + 1] * irho;
67#if DIMENSIONS == 3
68 const auto u2 = Q[Shortcuts::rhoU + 2] * irho;
69#endif
70
71#if DIMENSIONS == 3
72 const auto uSq = u0 * u0 + u1 * u1 + u2 * u2;
73 const auto u_n = (normal == 0) ? u0 : (normal == 1) ? u1 : u2;
74#else
75 const auto uSq = u0 * u0 + u1 * u1;
76 const auto u_n = (normal == 0) ? u0 : u1;
77#endif
78
79 const auto internalE = Q[Shortcuts::rhoE] - 0.5 * Q[Shortcuts::rho] * uSq;
80 const auto p = (GAMMA - 1.0) * internalE;
81"""
82
83max_eigenvalue = r"""
84 {compute_primitive_variables}
85 const auto speedOfSound = std::sqrt(GAMMA * p * irho);
86 auto result = std::fmax(0.0, std::fabs(u_n - speedOfSound));
87 result = std::fmax(result, std::fabs(u_n + speedOfSound));
88 return result;
89""".format(
90 compute_primitive_variables=compute_primitive_variables
91)
92
93flux = r"""
94 {compute_primitive_variables}
95
96 F[Shortcuts::rho] = Q[Shortcuts::rhoU + normal];
97
98 F[Shortcuts::rhoU + 0] = Q[Shortcuts::rhoU + 0] * u_n;
99 F[Shortcuts::rhoU + 1] = Q[Shortcuts::rhoU + 1] * u_n;
100#if DIMENSIONS == 3
101 F[Shortcuts::rhoU + 2] = Q[Shortcuts::rhoU + 2] * u_n;
102#endif
103
104 F[Shortcuts::rhoU + normal] += p;
105
106 F[Shortcuts::rhoE] = (Q[Shortcuts::rhoE] + p) * u_n;
107""".format(
108 compute_primitive_variables=compute_primitive_variables
109)
110
111fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
112 name="FVSolver",
113 patch_size=args.degrees_of_freedom,
114 unknowns={"rho": 1, "rhoU": args.dimensions, "rhoE": 1},
115 auxiliary_variables=0,
116 min_volume_h=min_h,
117 max_volume_h=max_h,
118 time_step_relaxation=0.5,
119 use_enclave_tasking=args.enclave_tasking,
120 number_of_enclave_tasks=args.ntasks,
121)
122
123fv_solver.set_implementation(
124 initial_conditions=initial_conditions,
125 boundary_conditions=boundary_conditions,
126 refinement_criterion=refinement_criterion,
127 max_eigenvalue=max_eigenvalue,
128 flux=flux,
129)
130
131fv_solver.set_solver_precisions(
132 storage_precision=args.precision, compute_precision=args.precision
133)
134
135project = exahype2.Project(
136 namespace=["tests", "exahype2", "fv"],
137 project_name=".",
138 directory=".",
139 executable="ExaHyPE",
140)
141project.add_solver(fv_solver)
142
143if args.number_of_snapshots <= 0:
144 time_in_between_plots = 0.0
145else:
146 time_in_between_plots = args.end_time / args.number_of_snapshots
147 project.set_output_path(args.output)
148
149project.set_global_simulation_parameters(
150 dimensions=args.dimensions,
151 size=[1.0, 1.0, 1.0][0 : args.dimensions],
152 offset=[0.0, 0.0, 0.0][0 : args.dimensions],
153 min_end_time=args.end_time,
154 max_end_time=args.end_time,
155 first_plot_time_stamp=0.0,
156 time_in_between_plots=time_in_between_plots,
157 periodic_BC=[
158 args.periodic_boundary_conditions_x,
159 args.periodic_boundary_conditions_y,
160 args.periodic_boundary_conditions_z,
161 ],
162)
163
164project.set_load_balancer("new ::exahype2::LoadBalancingConfiguration")
165project.set_build_mode(mode=peano4.output.string_to_mode(args.build_mode))
166project = project.generate_Peano4_project(verbose=False)
167project.output.makefile.set_target_device(args.target_device)
168project.output.makefile.add_CXX_flag("-DGAMMA=1.4")
169project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)