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