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")
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()
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 project.set_load_balancing(
"toolbox::loadbalancing::strategies::RecursiveSubdivision")
321 peano4_project = project.generate_Peano4_project(verbose=
True)
323 peano4_project.output.makefile.add_CXX_flag(
"-DMGCCZ4EINSTEIN" )
324 peano4_project.output.makefile.add_cpp_file(
"InitialValues.cpp" )
325 peano4_project.output.makefile.add_cpp_file(
"MGCCZ4Kernels.cpp" )
330 peano4_project.output.makefile.add_Fortran_flag(
"-DMGCCZ4EINSTEIN -DDim3" )
331 peano4_project.output.makefile.add_Fortran_flag(
"-lstdc++ -fdefault-real-8 -fdefault-double-8 -cpp -std=legacy -ffree-line-length-512 -fPIC" )
333 peano4_project.output.makefile.add_linker_flag(
"-lstdc++ -fPIC -lgfortran" )
341 peano4_project.output.makefile.add_Fortran_module(
"MainVariables.f90" )
343 peano4_project.output.makefile.add_Fortran_files(
358 peano4_project.generate( throw_away_data_after_generation=
False )
360 peano4_project.build( make_clean_first =
True )
363 if len(userwarnings) >0:
364 print(
"Please note that these warning occured before the build:")
365 for msg, exception
in userwarnings:
366 if exception
is None:
368 else: print(msg,
"Exception: {}".format(exception))