Peano
Loading...
Searching...
No Matches
fv-tracers.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 Particle Tracing Testing Script"
8)
9available_precisions = ["float", "double"]
10parser.add_argument(
11 "-pr", "--precision", default="double", help="|".join(available_precisions)
12)
13parser.set_defaults(
14 min_depth=6,
15 degrees_of_freedom=16,
16 number_of_snapshots=0,
17 periodic_boundary_conditions_x=False, # Throws assertion in the TracersSet when set to True
18 periodic_boundary_conditions_y=False,
19 periodic_boundary_conditions_z=False,
20)
21args = parser.parse_args()
22
23max_h = 1.1 / 3.0**args.min_depth
24min_h = max_h * 3.0 ** (-args.amr_levels)
25
26initial_conditions = """
27 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
28 Q[i] = std::sin(x(0) * tarch::la::PI) * std::sin(x(1) * tarch::la::PI)
29#if DIMENSIONS == 3
30 * std::sin(x(2) * tarch::la::PI)
31#endif
32 ;
33 }
34"""
35
36boundary_conditions = """
37 for (int i = 0; i < NumberOfUnknowns + NumberOfAuxiliaryVariables; i++) {
38 Qoutside[i] = Qinside[i];
39 }
40"""
41
42refinement_criterion = """
43 auto result = ::exahype2::RefinementCommand::Keep;
44
45 if (x(0) > 0.5) {
46 result = ::exahype2::RefinementCommand::Refine;
47 } else {
48 result = ::exahype2::RefinementCommand::Erase;
49 }
50
51 return result;
52"""
53
54fv_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
55 name="FVSolver",
56 patch_size=args.degrees_of_freedom,
57 unknowns={"v": args.dimensions},
58 auxiliary_variables=0,
59 min_volume_h=min_h,
60 max_volume_h=max_h,
61 time_step_relaxation=0.5,
62)
63
64fv_solver.set_implementation(
65 initial_conditions=initial_conditions,
66 boundary_conditions=boundary_conditions,
67 refinement_criterion=refinement_criterion,
68 flux="""
69 for (int i = 0; i < NumberOfUnknowns; i++) {
70 F[i] = 0.0;
71 }
72 F[normal] = Q[normal];
73""",
74 max_eigenvalue="return 1.0;",
75)
76
77fv_solver.set_solver_precisions(
78 storage_precision=args.precision, compute_precision=args.precision
79)
80
81project = exahype2.Project(
82 namespace=["tests", "exahype2", "fv"],
83 project_name=".",
84 directory=".",
85 executable="ExaHyPE",
86)
87project.add_solver(fv_solver)
88
89if args.number_of_snapshots <= 0:
90 time_in_between_plots = 0.0
91else:
92 time_in_between_plots = args.end_time / args.number_of_snapshots
93 project.set_output_path(
94 args.output
95 ) # Needs to be set BEFORE we add the particle tracers to the project -> not nice!
96
97tracers = project.add_tracer(
98 name="Tracers",
99 particle_attributes={
100 "unknowns": {
101 "rho": 1,
102 "fluid_u": 1,
103 "fluid_v": 1,
104 "fluid_w": 1, # Interpolated fluid velocity
105 "u": 1,
106 "v": 1,
107 "w": 1, # Particle's own velocity
108 "a_x": 1,
109 "a_y": 1,
110 "a_z": 1,
111 "d": 1,
112 }
113 if args.dimensions == 3
114 else {
115 "rho": 1,
116 "fluid_u": 1,
117 "fluid_v": 1, # Interpolated fluid velocity
118 "u": 1,
119 "v": 1, # Particle's own velocity
120 "a_x": 1,
121 "a_y": 1,
122 "d": 1,
123 }
124 },
125)
126
127init_tracers = exahype2.tracer.InsertParticlesFromFile(
128 particle_set=tracers,
129 filename="InitTracers.dat",
130 scale_factor=1.0,
131)
132
133init_tracers.descend_invocation_order = 0 # TODO: Why?
134project.add_action_set_to_initialisation(
135 init_tracers
136) # TODO: Is there not an easier way to expose the API to the user?
137
138# TODO: Why do we need this? Why not just fv_solver.addTracers(...)
139# TODO: Don't make the API too hard to understand for the user!
140tracing_action_set = exahype2.tracer.FiniteVolumesTracing(
141 tracers,
142 fv_solver,
143 project_on_tracer_properties_kernel="::exahype2::fv::updateParticleState<0, 1, 2>",
144 projection_kernel_arguments=""" // TODO: Also way too complicated!
145 *p,
146 fineGridCell{{SOLVER_NAME}}CellLabel.getTimeStepSize(),
147 marker,
148 {{PATCH_SIZE}},
149 {{NUMBER_OF_UNKNOWNS}}+{{NUMBER_OF_AUXILIARY_VARIABLES}},
150 fineGridCell{{SOLVER_NAME}}Q.value,
151 {1,1,1},
152 {0,0,0},
153 {1,0,0}
154""",
155)
156tracing_action_set.descend_invocation_order = (
157 fv_solver._action_set_update_patch.descend_invocation_order
158 + 1 # TODO: Why does the user need to do this advanced setting?
159)
160# TODO: This is all too complicated!
161project.add_action_set_to_initialisation(tracing_action_set)
162project.add_action_set_to_timestepping(tracing_action_set)
163
164project.set_global_simulation_parameters(
165 dimensions=args.dimensions,
166 size=[1.0, 1.0, 1.0][0 : args.dimensions],
167 offset=[0.0, 0.0, 0.0][0 : args.dimensions],
168 min_end_time=args.end_time,
169 max_end_time=args.end_time,
170 first_plot_time_stamp=0.0,
171 time_in_between_plots=time_in_between_plots,
172 periodic_BC=[
173 args.periodic_boundary_conditions_x,
174 args.periodic_boundary_conditions_y,
175 args.periodic_boundary_conditions_z,
176 ],
177)
178
179project.set_load_balancer("new ::exahype2::LoadBalancingConfiguration")
180project.set_Peano4_installation(
181 "../../../", mode=peano4.output.string_to_mode(args.build_mode)
182)
183project = project.generate_Peano4_project(verbose=False)
184project.set_fenv_handler(args.fpe)
185project.build(make=True, make_clean_first=True, throw_away_data_after_build=True)