Peano
Loading...
Searching...
No Matches
mgccz4.py
Go to the documentation of this file.
1import os
2import argparse
3
4import peano4
5import exahype2
6
7
8modes = {
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,
13}
14
15floatparams = {
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,
19 "sk":0.0, "bs":0.0}
20intparams = {"LapseType":0}
21
22if __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" )
32
33
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")
36
37 args = parser.parse_args()
38
39 SuperClass = None
40
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
55
56 class MGCCZ4Solver( SuperClass ):
57 def __init__(self, name, patch_size, min_h, max_h ):
58 unknowns = {
59 "G":6,
60 "K":6,
61 "theta":1,
62 "Z":3,
63 "lapse":1,
64 "shift":3,
65 "b":3,
66 "dLapse":3,
67 "dxShift":3,
68 "dyShift":3,
69 "dzShift":3,
70 "dxG":6,
71 "dyG":6,
72 "dzG":6,
73 "traceK":1,
74 "phi":1,
75 "P":3,
76 "K0":1,
77 "MGphi":1,
78 "Kphi":1,
79 "Pi":3
80 }
81
82 number_of_unknowns = sum(unknowns.values())
83
84 if SuperClass==exahype2.solvers.fv.GenericRusanovFixedTimeStepSize or \
85 SuperClass==exahype2.solvers.fv.GenericRusanovFixedTimeStepSizeWithAccelerator or \
86 SuperClass==exahype2.solvers.fv.GenericRusanovFixedTimeStepSizeWithEnclaves:
87 SuperClass.__init__(
88 self,
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,
93 time_step_size=1e-2
94 )
95 else:
96 SuperClass.__init__(
97 self,
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
103 )
104
105 self._solver_template_file_class_name = SuperClass.__name__
106
107 #pde = exahype2.sympy.PDE(unknowns=self._unknowns,auxiliary_variables=self._auxiliary_variables,dimensions=3)
108
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
114 )
115
117 """
118 We take this routine to add a few additional include statements.
119 """
120 return SuperClass.get_user_action_set_includes(self) + """
121 #include "../MGCCZ4Kernels.h"
122 #include "exahype2/PatchUtils.h"
123 """
124
125
127 """
128
129 Add the constraint verification code
130
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
134 the solution.
135
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
138 side.
139
140 """
142
143 self.set_preprocess_reconstructed_patch_kernel( """
144 const int patchSize = """ + str( self._patch.dim[0] ) + """;
145 double volumeH = ::exahype2::getVolumeLength(marker.h(),patchSize);
146 const int n_a_v=6;
147 dfor(cell,patchSize) {
148 tarch::la::Vector<Dimensions,int> currentCell = cell + tarch::la::Vector<Dimensions,int>(1);
149
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.
153
154 // See the docu in PDE.h
155 double gradQ[3*64]={ 0 };
156
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;
163 leftCell(d) -= 1;
164 rightCell(d) += 1;
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;
169 }
170 }
171
172 // We will use a Fortran routine to compute the constraints per
173 // Finite Volume
174 double constraints[n_a_v]={ 0 };
175
176 // Central cell
177 const int cellSerialised = peano4::utils::dLinearised(currentCell, patchSize + 2*1);
178
179 admconstraints(constraints,oldQWithHalo+cellSerialised*(64+n_a_v),gradQ);
180
181 for(int i=0;i<n_a_v;i++){
182 oldQWithHalo[cellSerialised*(64+n_a_v)+64+i] = constraints[i];
183 }
184 }
185 """)
186
187 self.create_data_structures()
188 self.create_action_sets()
189
190
192 """
193
194 Add the constraint verification code
195
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
199 the solution.
200
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
203 side.
204
205 """
206 self._auxiliary_variables = 64*3
207
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);
214
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;
221 leftCell(d) -= 1;
222 rightCell(d) += 1;
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;
228 }
229 }
230 }
231 """)
232
233 self.create_data_structures()
234 self.create_action_sets()
235
236
237
238 userwarnings = []
239
240 project = exahype2.Project( ["examples", "exahype2", "mgccz4"], "mgccz4" )
241
242 is_aderdg = False
243 solver_name = "MGCCZ4"
244 try:
245 if SuperClass==exahype2.solvers.aderdg.NonFusedGenericRusanovFixedTimeStepSize:
246 is_aderdg = True
247 order = 3
248 unknowns = 64
249 time_step_size = 0.001
250 except Exception as e:
251 msg = "Warning: ADER-DG no supported on this machine"
252 print(msg)
253 userwarnings.append((msg,e))
254
255 if is_aderdg:
256 solver_name = "ADERDG" + solver_name
257 else:
258 solver_name = "FiniteVolume" + solver_name
259
260 if SuperClass == exahype2.solvers.fv.GenericRusanovFixedTimeStepSizeWithAccelerator:
261 solver_name += "OnGPU"
262
263 if is_aderdg:
264 my_solver = exahype2.solvers.aderdg.NonFusedGenericRusanovFixedTimeStepSize(
265 solver_name, order, unknowns, 0, #auxiliary_variables
266 exahype2.solvers.aderdg.Polynomials.Gauss_Legendre,
267 args.max_h, args.max_h, time_step_size,
268 flux = None,
269 ncp = exahype2.solvers.PDETerms.User_Defined_Implementation,
270 sources = exahype2.solvers.PDETerms.User_Defined_Implementation
271 )
272 else:
273 my_solver = MGCCZ4Solver(solver_name, args.patch_size, args.max_h, args.max_h)
274
275 if args.extension=="gradient":
276 my_solver.add_derivative_calculation()
277 if args.extension=="adm":
278 my_solver.add_constraint_verification()
279
280 myscenario = 2 # 0...gaugewave-c++ 1...linearwave 2...forcedflat
281
282 solverconstants=""
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)
286
287 my_solver.setSolverConstants(solverconstants)
288
289 project.add_solver(my_solver)
290
291
292 build_mode = modes[args.mode]
293
294 dimensions = 3
295
296 if args.periodic_bc:
297 print( "Periodic BC set")
298 periodic_boundary_conditions = [True,True,True] # Periodic BC
299 else:
300 msg = "WARNING: Periodic BC deactivated"
301 print(msg)
302 periodic_boundary_conditions = [False,False,False]
303 userwarnings.append((msg,None))
304
305 project.set_global_simulation_parameters(
306 dimensions, # dimensions
307 [-0.5, -0.5, -0.5], [1.0, 1.0, 1.0],
308 args.end_time, # end time
309 0.0, args.plot_step_size, # snapshots
310 periodic_boundary_conditions
311 )
312
313 project.set_Peano4_installation("../../..", build_mode)
314
315 #project.set_output_path( "/cosma6/data/dp004/dc-zhan3/tem" )
316 #probe_point = [0,0,0]
317 #project.add_plot_filter( probe_point,[0.0,0.0,0.0],1 )
318
319 project.set_load_balancing("toolbox::loadbalancing::strategies::RecursiveSubdivision")
320
321 peano4_project = project.generate_Peano4_project(verbose=True)
322
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" )
326
327 # NOTE these lines are required to build with the fortran routines --- this will also require to uncomment some
328 # includes etc
329 #
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" )
332 # peano4_project.output.makefile.add_CXX_flag( "-fPIE -DMGCCZ4EINSTEIN" )
333 peano4_project.output.makefile.add_linker_flag( "-lstdc++ -fPIC -lgfortran" )
334 # peano4_project.output.makefile.add_linker_flag( "-lstdc++ -fPIC -L/usr/lib/x86_64-linux-gnu -lgfortran" )
335
336 # This might work for Intel (not tested)
337 #peano4_project.output.makefile.add_Fortran_flag( "-r8 -cpp -auto -qopenmp-simd -O2" )
338 #peano4_project.output.makefile.add_linker_flag( "-lstdc++ -fPIC" )
339 # you might need -lifcore
340
341 peano4_project.output.makefile.add_Fortran_module( "MainVariables.f90" )
342
343 peano4_project.output.makefile.add_Fortran_files(
344 ["PDE.f90 "]
345 )
346
347
348 # peano4_project.constants.export_string( "Scenario", "gaugewave-c++" )
349 # peano4_project.constants.add_target_begin()
350 # for k, v in floatparams.items(): peano4_project.constants.export_constexpr_with_type("MGCCZ4{}".format(k), eval('args.MGCCZ4{}'.format(k)), "double")
351 # peano4_project.constants.add_target_end()
352 # peano4_project.constants.add_target_begin()
353 # for k, v in intparams.items(): peano4_project.constants.export_constexpr_with_type("MGCCZ4{}".format(k), eval('args.MGCCZ4{}'.format(k)), "int")
354 # peano4_project.constants.add_target_end()
355 # project.export_const_with_type("NumberOfUnknowns", 64, "int")
356 #peano4_project.constants.export_string( "Scenario", "linearwave-c++" )
357
358 peano4_project.generate( throw_away_data_after_generation=False )
359
360 peano4_project.build( make_clean_first = True )
361
362 # Remind the user of warnings!
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:
367 print(msg)
368 else: print(msg, "Exception: {}".format(exception))
ExaHyPE 2 project.
Definition Project.py:14
__init__(self, name, patch_size, min_h, max_h)
Definition mgccz4.py:57
add_constraint_verification(self)
Add the constraint verification code.
Definition mgccz4.py:126
get_user_action_set_includes(self)
We take this routine to add a few additional include statements.
Definition mgccz4.py:116
add_derivative_calculation(self)
Add the constraint verification code.
Definition mgccz4.py:191