Peano
Loading...
Searching...
No Matches
Project.py
Go to the documentation of this file.
1import peano4
3
4import dastgen2
5
6from .MatrixFreeMain import MatrixFreeMain
7
8import os,sys
9
10class Project:
11 """!
12
13 Here we recreate a multigrid project, without using PETSc.
14
15 We keep some of the basic steps:
16 - _algorithm_step_create_grid
17 - _algorithm_step_enumerate_and_init_solution
18 - _algorithm_step_solve
19 - _algorithm_step_plot
20
21 The rest is yet to be fleshed out.
22
23 Now that we have multiple solvers in a project, we may not
24 want to use all of them for stopping criteria. Hence, we
25 have a second array for solvers which participate, but are
26 not asked if their stopping criteria have been reached.
27
28 @todo I think all projects should share certain commonalities
29 @todo I want to have some feature to set the MPI timeout
30
31 """
32
33 """
34 The standard extensions that are used for Peano and ExaHyPE.
35 """
36 LibraryDebug = "_debug"
37 LibraryRelease = ""
38 LibraryTrace = "_trace"
39 LibraryAsserts = "_asserts"
40 LibraryStats = "_stats"
41
42 def __init__(self,
43 namespace,
44 project_name,
45 directory = ".",
46 executable = "peano4matrixfree",
47 subdirectory="",
48 abstract_overwrite=True,
49 ):
50 """!
51
52 Create a matrix project
53
54 """
55 self._project = peano4.Project(namespace, project_name, directory, subdirectory)
56
57 # what to do about this line?
58 # self._project.output.makefile.add_cmake_core_library("petsc")
59 self._subdirectory = subdirectory
60 self._abstract_overwrite = abstract_overwrite
61
62 # does this get overwritten later?
63 self._domain_offset = [0.0, 0.0, 0.0]
64 self._domain_size = [1.0, 1.0, 1.0]
65 self._dimensions = 2
66
70
71 # does this get overwritten later?
72 self._build_mode = peano4.output.CompileMode.Asserts
73 self._executable_name = executable
74 self._output_path = "./"
75
76 self._solvers = []
77# @todo remove
78 self._aux_solvers = []
79
83
85
87 offset = [0.0, 0.0],
88 domain_size = [1.0, 1.0],
89 plot_after_each_mesh_sweep = False,
90 )
91
92 self._multicore_orchestration = "::tarch::multicore::orchestration::createDefaultStrategy()"
93
94 def set_load_balancing(self, load_balancer_name, load_balancer_arguments):
95 """!
96
97 Set the load balancing scheme
98
99 @param load_balancer_name: string
100 Should be full-qualified name of the load balancer.
101 By default, I recommend to pass "toolbox::loadbalancing::RecursiveSubdivision"
102
103 @param load_balancer_arguments: string
104 If your load balancing requires parameters, add them
105 here. It is a string that will be copied into the C++ class instantiation.
106 Please add the brackets yourself, i.e. "(3,4,5)" is fine, but "3,4,5" is not.
107 The only exception is the empty parameter list. Here, you can/should simply
108 add the empty string.
109
110 """
111 self._load_balancer_name = load_balancer_name
112 self._load_balancer_arguments = load_balancer_arguments
113
114 def set_Peano4_installation(self, src_path, mode=peano4.output.CompileMode.Release ):
115 """!
116
117 Tell the project where to find Peano
118
119 Once we know where to find Peano, we can parse the configuration/makefile
120 there and know which compile parameters to use. We also know then where to
121 search for the static libraries.
122
123 @param src_path: string
124 Path (relative or absolute) to the src directory of Peano. This path
125 should hold both the headers (in subdirectories) and all the static
126 libraries.
127
128 @param mode: peano4.output.CompileMode
129
130 """
131 self._Peano_src_directory = src_path
132 self._build_mode = mode
133
134
136 """!
137
138 Parse makefile of Peano to extract the configuration settings
139
140 We parse the configure script's/CMAKE outcome first via parse_configure_script_outcome().
141 After that, we set the dimension manually as well as the executable name and
142 the build mode. The values for these parameters step from set_Peano4_installation().
143
144 """
145 self._project.output.makefile.parse_configure_script_outcome( self._Peano_src_directory )
146 self._project.output.makefile.set_dimension(self._dimensions)
147 self._project.output.makefile.set_executable_name(self._executable_name)
148 self._project.output.makefile.set_mode(self._build_mode)
149
151
153 dimensions,
154 offset,
155 domain_size,
156 plot_after_each_mesh_sweep,
157 max_iterations=100,
158 plotter_precision = 5,
159 ):
160 """
161
162 Configure global simulation settings
163
164 @param offset: [Float]
165
166 @param size: [Float]
167 should be lists with dimensions double entries.
168
169 """
170 self._domain_offset = offset
171 self._domain_size = domain_size
172 self._dimensions = dimensions
173 self._plot_after_each_mesh_sweep = plot_after_each_mesh_sweep
174 self._max_iterations = max_iterations
175 self._plotter_precision = plotter_precision
176 if plotter_precision<=0:
177 raise Exception( "Plotter precision has to be bigger than 0" )
178
179 def set_output_path(self,path):
180 self._output_path = path
181 if not self._output_path.endswith( "/" ):
182 self._output_path += "/"
183
184
185 def generate_Peano4_project(self, verbose=False):
186 """!
187
188 Build project
189
190 Construct and return the Peano4 project, i.e. all the action sets et al that
191 you require to run this Peano4 application with PETSc.
192
193 """
194 self._project.main = MatrixFreeMain(self._project,
195 self._domain_offset,
196 self._domain_size,
198 self._max_iterations
199 )
200
201 self._project.solversteps.add_step(self.algorithm_step_create_grid)
202 self._project.solversteps.add_step(self.algorithm_step_init_solution)
203 self._project.solversteps.add_step(self.algorithm_step_solve)
204 self._project.solversteps.add_step(self.algorithm_step_plot)
205
208
209 self._project.output.readme.add_package_description( """
210
211
212""" )
213
214 return self._project
215
216
218 self.dictionary = {
219 "SOLVER_INSTANCES": [(x.typename(), x.instance_name()) for x in self._solvers ],
220 "AUX_SOLVER_INSTANCES": [(x.typename(), x.instance_name()) for x in self._aux_solvers ],
221 "LOAD_BALANCER": self._load_balancer_name,
222 "LOAD_BALANCER_ARGUMENTS": self._load_balancer_arguments,
223 "MULTICORE_ORCHESTRATION": self._multicore_orchestration,
224 }
225
227 # make sure solver repository dict is set
229
230 templatefile_prefix = os.path.realpath(__file__).replace( ".pyc", "" ).replace( ".py", "" )
231 template_name = templatefile_prefix + ".SolverRepository.template"
233 template_name + ".h",
234 template_name + ".cpp",
235 "SolverRepository",
236 self._project.namespace, # + ["repositories"],
237 self._project.subdirectory + "repositories",
238 self.dictionary,
239 True,
240 True)
241
242 self._project.output.add( generated_repository_files )
243 self._project.output.makefile.add_h_file( self._project.subdirectory + "repositories/SolverRepository.h", generated=True )
244 self._project.output.makefile.add_cpp_file( self._project.subdirectory + "repositories/SolverRepository.cpp", generated=True )
245
246 def add_solver( self, solver, auxiliary=False ):
247 """!
248
249 Add a new solver
250
251 Takes the solver and runs through the individual steps of the algorithm.
252 Per step, it tells the solver to inject its particular stuff to the
253 underlying observers.
254
255 The auxiliary flag allows us to distinguish the "main" solver from the
256 helpers. The rationale for this is that we only want to measure the
257 termination conditions for a subset of the solvers.
258
259 """
260 print( "---------------------------------------")
261 print( "Create data for solver " +solver._name )
262 print( "---------------------------------------")
263 print( solver )
264
265 solver.add_to_Peano4_datamodel( self._project.datamodel, verbose=False )
266
267 solver.add_use_statements(self.algorithm_step_create_grid)
268 solver.add_use_statements(self.algorithm_step_init_solution)
269 solver.add_use_statements(self.algorithm_step_solve)
270 solver.add_use_statements(self.algorithm_step_plot)
271
272
273 solver.add_to_create_grid (self.algorithm_step_create_grid)
274 solver.add_to_init_solution(self.algorithm_step_init_solution)
275 solver.add_to_solve (self.algorithm_step_solve)
276
277 solver.add_to_plot (self.algorithm_step_plot)
278
279 if self._abstract_overwrite==False:
280 solver.add_implementation_files_to_project( self._project.namespace, self._project.output, self._subdirectory, self._abstract_overwrite )
281 else:
282 solver.add_implementation_files_to_project( self._project.namespace, self._project.output, self._subdirectory )
283
284 '''
285 This is for two-grid setup - we mark the correction solver as "auxiliary", so that we
286 don't exit early before the main solver has reached tolerance.
287 '''
288 if auxiliary:
289 self._aux_solvers.append( solver )
290 else:
291 self._solvers.append( solver )
292
293 pass
294
296 """!
297
298 Export all the constrants of the project into a Configure.h file
299
300 We export ExaHyPE's constants. Besides the constants from ExaHyPE,
301 I also export some parameters from Peano onto the ExaHyPE constants
302 file. Therefore, it is important that you parse the configure output
303 before we export the constants.
304
305 """
306 self._project.constants.clear()
307 offset_string = "{" + str(self._domain_offset[0])
308 size_string = "{" + str(self._domain_size[0])
309 for i in range(1, self._dimensions):
310 offset_string += ","
311 size_string += ","
312 offset_string += str(self._domain_offset[i])
313 size_string += str(self._domain_size[i])
314 offset_string += "}"
315 size_string += "}"
316 self._project.constants.add_include("""#include <bitset>""")
317 self._project.constants.add_include("""#include "tarch/la/Vector.h" """)
318 self._project.constants.add_include("""#include "peano4/utils/Globals.h" """)
319 self._project.constants.export_const_with_type(
320 "DomainOffset", offset_string, "tarch::la::Vector<Dimensions,double>"
321 )
322 self._project.constants.export_const_with_type(
323 "DomainSize", size_string, "tarch::la::Vector<Dimensions,double>"
324 )
325 self._project.constants.export("PlotterPrecision", str(self._plotter_precision))
326
327 build_string = "python3 "
328 for i in sys.argv:
329 build_string += " "
330 build_string += i
331 self._project.constants.export_string("BuildInformation", build_string)
332 self._project.constants.export_string(
333 "ConfigureInformation", self._project.output.makefile.configure_call
334 )
335
336 self._project.output.readme.add_package_description(
337 """!
338
339### Peano's multigrid extension
340
341This is yet to be written, and we need to have a paper on our work.
342
343 @article{Reinarz:2020:ExaHyPE,
344 title = {ExaHyPE: An engine for parallel dynamically adaptive simulations of wave problems},
345 journal = {Computer Physics Communications},
346 volume = {254},
347 pages = {107251},
348 year = {2020},
349 issn = {0010-4655},
350 doi = {https://doi.org/10.1016/j.cpc.2020.107251},
351 url = {https://www.sciencedirect.com/science/article/pii/S001046552030076X},
352 author = {Anne Reinarz and Dominic E. Charrier and Michael Bader and Luke Bovard and Michael Dumbser and Kenneth Duru and Francesco Fambri and Alice-Agnes Gabriel and Jean-Matthieu Gallard and Sven K\"oppel and Lukas Krenz and Leonhard Rannabauer and Luciano Rezzolla and Philipp Samfass and Maurizio Tavelli and Tobias Weinzierl},
353 keywords = {Hyperbolic, PDE, ADER-DG, Finite volumes, AMR, MPI, TBB, MPI+X},
354 abstract = {ExaHyPE (An Exascale Hyperbolic PDE Engine) is a software engine for solving systems of first-order hyperbolic partial differential equations (PDEs). Hyperbolic PDEs are typically derived from the conservation laws of physics and are useful in a wide range of application areas. Applications powered by ExaHyPE can be run on a student's laptop, but are also able to exploit thousands of processor cores on state-of-the-art supercomputers. The engine is able to dynamically increase the accuracy of the simulation using adaptive mesh refinement where required. Due to the robustness and shock capturing abilities of ExaHyPE's numerical methods, users of the engine can simulate linear and non-linear hyperbolic PDEs with very high accuracy. Users can tailor the engine to their particular PDE by specifying evolved quantities, fluxes, and source terms. A complete simulation code for a new hyperbolic PDE can often be realised within a few hours - a task that, traditionally, can take weeks, months, often years for researchers starting from scratch. In this paper, we showcase ExaHyPE's workflow and capabilities through real-world scenarios from our two main application areas: seismology and astrophysics.
355 Program summary
356 Program title: ExaHyPE-Engine Program Files doi: http://dx.doi.org/10.17632/6sz8h6hnpz.1 Licensing provisions: BSD 3-clause Programming languages: C++, Python, Fortran Nature of Problem: The ExaHyPE PDE engine offers robust algorithms to solve linear and non-linear hyperbolic systems of PDEs written in first order form. The systems may contain both conservative and non-conservative terms. Solution method: ExaHyPE employs the discontinuous Galerkin (DG) method combined with explicit one-step ADER (arbitrary high-order derivative) time-stepping. An a-posteriori limiting approach is applied to the ADER-DG solution, whereby spurious solutions are discarded and recomputed with a robust, patch-based finite volume scheme. ExaHyPE uses dynamical adaptive mesh refinement to enhance the accuracy of the solution around shock waves, complex geometries, and interesting features.
357 }
358 }
359"""
360 )
361
362 for i in self._solvers:
363 self._project.output.readme.add_entry(
364 i.create_readme_descriptor()
365 )
366
367 @property
368 def subdirectory(self):
369 return self._subdirectory
370
371
372# @todo timtout
373 def set_mpi_timeout(self,value):
374 pass
375
376
378 """! Set orchestration
379
380 value has to be a string which creates an orchestration object,
381 i.e., an object of the type tarch::multicore::orchestration::Orchestration.
382 You can either create it directly (in this case you need to add a new),
383 or you can use a factory method such as
384 "tarch::multicore::orchestration::StrategyFactory::createDefaultStrategy()".
385
386 A typical usage looks similar to
387
388 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
389project.set_multicore_orchestration( "new ::tarch::multicore::orchestration::Hardcoded(8,256,tarch::multicore::Task::Host,::tarch::multicore::orchestration::Hardcoded::NoNestedParallelism,::tarch::multicore::orchestration::FusionImplementation::LazyEvaluation)" )
390 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
391 """
392 self._multicore_orchestration = value
Here we recreate a multigrid project, without using PETSc.
Definition Project.py:10
set_global_simulation_parameters(self, dimensions, offset, domain_size, plot_after_each_mesh_sweep, max_iterations=100, plotter_precision=5)
Configure global simulation settings.
Definition Project.py:159
set_Peano4_installation(self, src_path, mode=peano4.output.CompileMode.Release)
Tell the project where to find Peano.
Definition Project.py:114
set_global_simulation_parameters(self, dimensions, offset, domain_size, plotter_precision=5)
offset and size should be lists with dimensions double entries.
Definition Project.py:165
__generate_solver_repository(self)
Definition Project.py:226
__export_constants(self)
Export all the constrants of the project into a Configure.h file.
Definition Project.py:295
set_mpi_timeout(self, value)
Definition Project.py:373
__set_solver_repository_dict(self)
Definition Project.py:217
set_output_path(self, path)
Definition Project.py:179
generate_Peano4_project(self, verbose=False)
Build project.
Definition Project.py:185
__configure_makefile(self)
Parse makefile of Peano to extract the configuration settings.
Definition Project.py:135
set_multicore_orchestration(self, value)
Set orchestration.
Definition Project.py:377
set_load_balancing(self, load_balancer_name, load_balancer_arguments)
Set the load balancing scheme.
Definition Project.py:94
__init__(self, namespace, project_name, directory=".", executable="peano4matrixfree", subdirectory="", abstract_overwrite=True)
Create a matrix project.
Definition Project.py:49
add_solver(self, solver, auxiliary=False)
Add a new solver.
Definition Project.py:246
Represents a Peano 4 project.
Definition Project.py:16