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