6We import the required modules for this project.
7We always need the 'peano4' module as this is our core project.
8Since we are creating a SymHyPE/ExaHyPE 2 application, we additionally
9need to import the 'exahype2' and 'symhype' modules.
16We specify the space dimensions here.
17We support either 2- or 3-dimensional problems.
22The number of finite volumes per axis in one patch.
27The number of levels the mesh is refined.
32The simulation end time.
37Define the advection speed.
42Choose domain size and offset.
45offset = [0.0, 0.0, 0.0]
48Choose how often a snapshot is written.
50time_in_between_two_snapshots = end_time / 10
54Switch between 'Release', 'Debug', 'Asserts', 'Trace', 'Stats'.
56compile_mode =
"Release"
59We first create a new ExaHyPE 2 project.
60For this, we specify the (nested) namespaces, the name of our main file and our executable name.
62my_project = exahype2.Project(
63 namespace=[
"tutorials",
"symhype",
"advection"],
64 project_name=
"Advection",
66 executable=
"Advection",
70Add the Finite Volumes solver using named arguments.
71This is the way you can add further PDE terms.
72This requires the 'BlockStructured' toolbox and 'ExaHyPE' to be built.
74my_solver = exahype2.solvers.fv.godunov.GlobalAdaptiveTimeStep(
76 patch_size=patch_size,
78 auxiliary_variables=0,
79 min_volume_h=(1.1 * min(size[0:dimensions]) / (3.0**depth)),
80 max_volume_h=(1.1 * min(size[0:dimensions]) / (3.0**depth)),
81 time_step_relaxation=0.5,
85We want to define our PDE symbolically.
87my_pde = symhype.FirstOrderConservativePDEFormulation(
88 unknowns=dimensions, auxiliary_variables=0, dimensions=dimensions
90v = my_pde.name_Q_entries(0, dimensions,
"v")
94Define the equation system
102 my_pde.F[1, 1] = v[1]
104 my_pde.F[0, 0] = v[0]
109 my_pde.F[1, 1] = v[1]
114 my_pde.F[2, 2] = v[2]
118 my_pde.eigenvalues[0] = c
119 my_pde.eigenvalues[1] = c
121 my_pde.eigenvalues[0] = c
122 my_pde.eigenvalues[1] = c
123 my_pde.eigenvalues[2] = c
125my_pde.substitute_expression(c, advection_speed)
128Since 'my_pde' only holds the PDE without initial- or boundary conditions,
129we still need to properly define initial- and boundary conditions.
130This gives us then a complete description of a 'scenario'.
134my_pde.initial_values[0] = my_pde.x[0]
135my_pde.initial_values[1] = my_pde.x[1]
137 my_pde.initial_values[2] = my_pde.x[2]
140Specify which implementation our solvers uses.
141Here we want to set the implementation we get from our symbolically defined PDE,
142i.e., we get the C++ implementation which is generated by SymHyPE.
144my_solver.set_implementation(
145 initial_conditions=my_pde.implementation_of_initial_conditions(),
146 boundary_conditions=my_pde.implementation_of_homogeneous_Neumann_BC(),
147 flux=my_pde.implementation_of_flux(),
148 max_eigenvalue=my_pde.implementation_of_max_eigenvalue(),
152To see which variables (unknowns + auxiliary variables) we can visualise,
153let's add a plot description for the variables to our solver.
155my_solver.plot_description = my_pde.unknown_identifier_for_plotter()
158Add the solver to our project
160my_project.add_solver(my_solver)
163Configure some global parameters
165my_project.set_global_simulation_parameters(
166 dimensions=dimensions,
167 size=size[0:dimensions],
168 offset=offset[0:dimensions],
169 min_end_time=end_time,
170 max_end_time=end_time,
171 first_plot_time_stamp=0.0,
172 time_in_between_plots=time_in_between_two_snapshots,
173 periodic_BC=[
False,
False,
False],
177This defines where the output files should go.
178If you omit this, output files are automatically put into the application's folder.
180my_project.set_output_path(
"solutions")
183Configure load balancer for parallel execution.
185my_project.set_load_balancer(
"new ::exahype2::LoadBalancingConfiguration")
188We need to set the location of our core libraries ('Peano4').
189This helps us to resolve any dependencies.
190Additionally, we specify the build mode which you can also change to a different mode.
192my_project.set_Peano4_installation(
193 "../../../", mode=peano4.output.string_to_mode(compile_mode)
197We generate and grab the underlying core project of 'Peano4'.
198This gives us access to some functions we want to use to finalise and build this project.
200my_project = my_project.generate_Peano4_project(verbose=
False)
203Finally, we want to build our project.
204First, all of the necessary glue code is generated in the application folder,
205then 'make' is invoked automatically which compiles the generated code and links against our core libraries
206and toolboxes which have been built before.
207You can also always invoke 'make' yourself to compile, or cleanup with 'make clean'.
209my_project.build(make=
True, make_clean_first=
True, throw_away_data_after_build=
True)
212print(my_pde.__str__())