9 "release": peano4.output.CompileMode.Release,
10 "trace": peano4.output.CompileMode.Trace,
11 "assert": peano4.output.CompileMode.Asserts,
"stats": peano4.output.CompileMode.Stats,
12 "debug": peano4.output.CompileMode.Debug,
16 "GLMc0":1.5,
"GLMc":1.2,
"GLMd":2.0,
"GLMepsA":1.0,
"GLMepsP":1.0,
17 "GLMepsD":1.0,
"itau":1.0,
"k1":0.0,
"k2":0.0,
"k3":0.0,
"eta":0.0,
18 "f":0.0,
"g":0.0,
"xi":0.0,
"e":1.0,
"c":1.0,
"mu":0.2,
"ds":1.0,
20 intparams = {
"LapseType":0}
22 if __name__ ==
"__main__":
23 parser = argparse.ArgumentParser(description=
'ExaHyPE 2 - MGCCZ4 script')
24 parser.add_argument(
"-cs",
"--cell-size", dest=
"max_h", type=float, default=0.4, help=
"Mesh size" )
25 parser.add_argument(
"-ps",
"--patch-size", dest=
"patch_size", type=int, default=6, help=
"Patch size, i.e. number of volumes per cell per direction" )
26 parser.add_argument(
"-plt",
"--plot-step-size", dest=
"plot_step_size", type=float, default=0.04, help=
"Plot step size (0 to switch it off)" )
27 parser.add_argument(
"-m",
"--mode", dest=
"mode", default=
"release", help=
"|".join(modes.keys()) )
28 parser.add_argument(
"-ext",
"--extension", dest=
"extension", choices=[
"none",
"gradient",
"adm"], default=
"none", help=
"Pick extension, i.e. what should be plotted on top. Default is none" )
29 parser.add_argument(
"-impl",
"--implementation", dest=
"implementation", choices=[
"ader-fixed",
"fv-fixed",
"fv-fixed-enclave",
"fv-adaptive" ,
"fv-adaptive-enclave",
"fv-optimistic-enclave",
"fv-fixed-gpu"], required=
"True", help=
"Pick solver type" )
30 parser.add_argument(
"-no-pbc",
"--no-periodic-boundary-conditions", dest=
"periodic_bc", action=
"store_false", default=
"True", help=
"switch on or off the periodic BC" )
31 parser.add_argument(
"-et",
"--end-time", dest=
"end_time", type=float, default=1.0, help=
"End (terminal) time" )
34 for k, v
in floatparams.items(): parser.add_argument(
"--{}".format(k), dest=
"MGCCZ4{}".format(k), type=float, default=v, help=
"default: %(default)s")
35 for k, v
in intparams.items(): parser.add_argument(
"--{}".format(k), dest=
"MGCCZ4{}".format(k), type=int, default=v, help=
"default: %(default)s")
37 args = parser.parse_args()
41 if args.implementation==
"fv-fixed":
42 SuperClass = exahype2.solvers.fv.GenericRusanovFixedTimeStepSize
43 if args.implementation==
"fv-fixed-enclave":
44 SuperClass = exahype2.solvers.fv.GenericRusanovFixedTimeStepSizeWithEnclaves
45 if args.implementation==
"fv-adaptive":
46 SuperClass = exahype2.solvers.fv.GenericRusanovAdaptiveTimeStepSize
47 if args.implementation==
"fv-adaptive-enclave":
48 SuperClass = exahype2.solvers.fv.GenericRusanovAdaptiveTimeStepSizeWithEnclaves
49 if args.implementation==
"fv-optimistic-enclave":
50 SuperClass = exahype2.solvers.fv.GenericRusanovOptimisticTimeStepSizeWithEnclaves
51 if args.implementation==
"ader-fixed":
52 SuperClass = exahype2.solvers.aderdg.NonFusedGenericRusanovFixedTimeStepSize
53 if args.implementation==
"fv-fixed-gpu":
54 SuperClass = exahype2.solvers.fv.GenericRusanovFixedTimeStepSizeWithAccelerator
57 def __init__(self, name, patch_size, min_h, max_h ):
82 number_of_unknowns = sum(unknowns.values())
84 if SuperClass==exahype2.solvers.fv.GenericRusanovFixedTimeStepSize
or \
85 SuperClass==exahype2.solvers.fv.GenericRusanovFixedTimeStepSizeWithAccelerator
or \
86 SuperClass==exahype2.solvers.fv.GenericRusanovFixedTimeStepSizeWithEnclaves:
89 name=name, patch_size=patch_size,
90 unknowns=number_of_unknowns,
91 auxiliary_variables=0,
92 min_h=min_h, max_h=max_h,
98 name=name, patch_size=patch_size,
99 unknowns=number_of_unknowns,
100 auxiliary_variables=0,
101 min_h=min_h, max_h=max_h,
102 time_step_relaxation=0.1
109 self.set_implementation(
110 boundary_conditions=exahype2.solvers.PDETerms.User_Defined_Implementation,
111 flux=exahype2.solvers.PDETerms.None_Implementation,
112 ncp=exahype2.solvers.PDETerms.User_Defined_Implementation,
113 source_term=exahype2.solvers.PDETerms.User_Defined_Implementation
118 We take this routine to add a few additional include statements.
120 return SuperClass.get_user_action_set_includes(self) +
"""
121 #include "../MGCCZ4Kernels.h"
122 #include "exahype2/PatchUtils.h"
129 Add the constraint verification code
131 We introduce new auxiliary variables. Prior to each time step, I
132 compute the Laplacian and store it in the auxiliary variable. This
133 is kind of a material parameter F(Q) which does not feed back into
136 Changing the number of unknowns a posteriori is a delicate update
137 to the solver, so we invoke the constructor again to be on the safe
143 self.set_preprocess_reconstructed_patch_kernel(
"""
144 const int patchSize = """ +
str( self._patch.dim[0] ) +
""";
145 double volumeH = ::exahype2::getVolumeLength(marker.h(),patchSize);
147 dfor(cell,patchSize) {
148 tarch::la::Vector<DIMENSIONS,int> currentCell = cell + tarch::la::Vector<DIMENSIONS,int>(1);
150 // This constraint routine will evaluate both the solution per voxel
151 // plus the derivative. The latter is something that we don't have, i.e.
152 // we have to reconstruct it manually.
154 // See the docu in PDE.h
155 double gradQ[3*64]={ 0 };
157 // Lets look left vs right and compute the gradient. Then, lets
158 // loop up and down. So we look three times for the respective
159 // directional gradients
160 for (int d=0; d<3; d++) {
161 tarch::la::Vector<DIMENSIONS,int> leftCell = currentCell;
162 tarch::la::Vector<DIMENSIONS,int> rightCell = currentCell;
165 const int leftCellSerialised = peano4::utils::dLinearised(leftCell, patchSize + 2*1);
166 const int rightCellSerialised = peano4::utils::dLinearised(rightCell,patchSize + 2*1);
167 for(int i=0; i<64; i++) {
168 gradQ[d*64+i] = ( oldQWithHalo[rightCellSerialised*(64+n_a_v)+i] - oldQWithHalo[leftCellSerialised*(64+n_a_v)+i] ) / 2.0 / volumeH;
172 // We will use a Fortran routine to compute the constraints per
174 double constraints[n_a_v]={ 0 };
177 const int cellSerialised = peano4::utils::dLinearised(currentCell, patchSize + 2*1);
179 admconstraints(constraints,oldQWithHalo+cellSerialised*(64+n_a_v),gradQ);
181 for(int i=0;i<n_a_v;i++){
182 oldQWithHalo[cellSerialised*(64+n_a_v)+64+i] = constraints[i];
187 self.create_data_structures()
188 self.create_action_sets()
194 Add the constraint verification code
196 We introduce new auxiliary variables. Prior to each time step, I
197 compute the Laplacian and store it in the auxiliary variable. This
198 is kind of a material parameter F(Q) which does not feed back into
201 Changing the number of unknowns a posteriori is a delicate update
202 to the solver, so we invoke the constructor again to be on the safe
208 self.set_preprocess_reconstructed_patch_kernel(
"""
209 const int patchSize = """ +
str( self._patch.dim[0] ) +
""";
210 double volumeH = ::exahype2::getVolumeLength(marker.h(),patchSize);
211 dfor(cell,patchSize) {
212 tarch::la::Vector<DIMENSIONS,int> currentCell = cell + tarch::la::Vector<DIMENSIONS,int>(1);
213 const int cellSerialised = peano4::utils::dLinearised(currentCell, patchSize + 2*1);
215 // Lets look left vs right and compute the gradient. Then, lets
216 // loop up and down. So we look three times for the respective
217 // directional gradients
218 for (int d=0; d<3; d++) {
219 tarch::la::Vector<DIMENSIONS,int> leftCell = currentCell;
220 tarch::la::Vector<DIMENSIONS,int> rightCell = currentCell;
223 const int leftCellSerialised = peano4::utils::dLinearised(leftCell, patchSize + 2*1);
224 const int rightCellSerialised = peano4::utils::dLinearised(rightCell,patchSize + 2*1);
225 for (int i=0; i<64; i++) {
226 oldQWithHalo[cellSerialised*(64*4)+64+i*3+d] =
227 ( oldQWithHalo[rightCellSerialised*(64*4)+i] - oldQWithHalo[leftCellSerialised*(64*4)+i] ) / 2.0 / volumeH;
233 self.create_data_structures()
234 self.create_action_sets()
240 project = exahype2.Project( [
"examples",
"exahype2",
"mgccz4"],
"mgccz4" )
243 solver_name =
"MGCCZ4"
245 if SuperClass==exahype2.solvers.aderdg.NonFusedGenericRusanovFixedTimeStepSize:
249 time_step_size = 0.001
250 except Exception
as e:
251 msg =
"Warning: ADER-DG no supported on this machine"
253 userwarnings.append((msg,e))
256 solver_name =
"ADERDG" + solver_name
258 solver_name =
"FiniteVolume" + solver_name
260 if SuperClass == exahype2.solvers.fv.GenericRusanovFixedTimeStepSizeWithAccelerator:
261 solver_name +=
"OnGPU"
264 my_solver = exahype2.solvers.aderdg.NonFusedGenericRusanovFixedTimeStepSize(
265 solver_name, order, unknowns, 0,
266 exahype2.solvers.aderdg.Polynomials.Gauss_Legendre,
267 args.max_h, args.max_h, time_step_size,
269 ncp = exahype2.solvers.PDETerms.User_Defined_Implementation,
270 sources = exahype2.solvers.PDETerms.User_Defined_Implementation
273 my_solver =
MGCCZ4Solver(solver_name, args.patch_size, args.max_h, args.max_h)
275 if args.extension==
"gradient":
276 my_solver.add_derivative_calculation()
277 if args.extension==
"adm":
278 my_solver.add_constraint_verification()
283 for k, v
in floatparams.items(): solverconstants+=
"static constexpr double {} = {};\n".format(
"MGCCZ4{}".format(k), eval(
'args.MGCCZ4{}'.format(k)))
284 for k, v
in intparams.items(): solverconstants+=
"static constexpr int {} = {};\n".format(
"MGCCZ4{}".format(k), eval(
'args.MGCCZ4{}'.format(k)))
285 solverconstants+=
"static constexpr int Scenario = {};\n".format(myscenario)
287 my_solver.setSolverConstants(solverconstants)
289 project.add_solver(my_solver)
292 build_mode = modes[args.mode]
297 print(
"Periodic BC set")
298 periodic_boundary_conditions = [
True,
True,
True]
300 msg =
"WARNING: Periodic BC deactivated"
302 periodic_boundary_conditions = [
False,
False,
False]
303 userwarnings.append((msg,
None))
305 project.set_global_simulation_parameters(
307 [-0.5, -0.5, -0.5], [1.0, 1.0, 1.0],
309 0.0, args.plot_step_size,
310 periodic_boundary_conditions
313 project.set_Peano4_installation(
"../../..", build_mode)
319 peano4_project = project.generate_Peano4_project(verbose=
True)
321 peano4_project.output.makefile.add_CXX_flag(
"-DMGCCZ4EINSTEIN" )
322 peano4_project.output.makefile.add_cpp_file(
"InitialValues.cpp" )
323 peano4_project.output.makefile.add_cpp_file(
"MGCCZ4Kernels.cpp" )
328 peano4_project.output.makefile.add_Fortran_flag(
"-DMGCCZ4EINSTEIN -DDim3" )
329 peano4_project.output.makefile.add_Fortran_flag(
"-lstdc++ -fdefault-real-8 -fdefault-double-8 -cpp -std=legacy -ffree-line-length-512 -fPIC" )
331 peano4_project.output.makefile.add_linker_flag(
"-lstdc++ -fPIC -lgfortran" )
339 peano4_project.output.makefile.add_Fortran_module(
"MainVariables.f90" )
341 peano4_project.output.makefile.add_Fortran_files(
356 peano4_project.generate( throw_away_data_after_generation=
False )
358 peano4_project.build( make_clean_first =
True )
361 if len(userwarnings) >0:
362 print(
"Please note that these warning occured before the build:")
363 for msg, exception
in userwarnings:
364 if exception
is None:
366 else: print(msg,
"Exception: {}".format(exception))
def __init__(self, name, patch_size, min_h, max_h)
def get_user_action_set_includes(self)
We take this routine to add a few additional include statements.
def add_derivative_calculation(self)
_solver_template_file_class_name
def add_constraint_verification(self)