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 """
29
30 """
31 The standard extensions that are used for Peano and ExaHyPE.
32 """
33 LibraryDebug = "_debug"
34 LibraryRelease = ""
35 LibraryTrace = "_trace"
36 LibraryAsserts = "_asserts"
37 LibraryStats = "_stats"
38
39 def __init__(self,
40 namespace,
41 project_name,
42 directory = ".",
43 executable = "peano4matrixfree",
44 subdirectory="",
45 abstract_overwrite=True,
46 ):
47 """!
48
49 Create a matrix project
50
51 """
52 self._project = peano4.Project(namespace, project_name, directory, subdirectory)
53
54 # what to do about this line?
55 # self._project.output.makefile.add_cmake_core_library("petsc")
56 self._subdirectory = subdirectory
57 self._abstract_overwrite = abstract_overwrite
58
59 # does this get overwritten later?
60 self._domain_offset = [0.0, 0.0, 0.0]
61 self._domain_size = [1.0, 1.0, 1.0]
62 self._dimensions = 2
63
67
68 # does this get overwritten later?
69 self._build_mode = peano4.output.CompileMode.Asserts
70 self._executable_name = executable
71 self._output_path = "./"
72
73 self._solvers = []
74# @todo remove
75 self._aux_solvers = []
76
80
82
84 offset = [0.0, 0.0],
85 domain_size = [1.0, 1.0],
86 plot_after_each_mesh_sweep = False,
87 )
88
89
90 def set_load_balancing(self, load_balancer_name, load_balancer_arguments):
91 """!
92
93 Set the load balancing scheme
94
95 @param load_balancer_name: string
96 Should be full-qualified name of the load balancer.
97 By default, I recommend to pass "toolbox::loadbalancing::RecursiveSubdivision"
98
99 @param load_balancer_arguments: string
100 If your load balancing requires parameters, add them
101 here. It is a string that will be copied into the C++ class instantiation.
102 Please add the brackets yourself, i.e. "(3,4,5)" is fine, but "3,4,5" is not.
103 The only exception is the empty parameter list. Here, you can/should simply
104 add the empty string.
105
106 """
107 self._load_balancer_name = load_balancer_name
108 self._load_balancer_arguments = load_balancer_arguments
109
110 def set_Peano4_installation(self, src_path, mode=peano4.output.CompileMode.Release ):
111 """!
112
113 Tell the project where to find Peano
114
115 Once we know where to find Peano, we can parse the configuration/makefile
116 there and know which compile parameters to use. We also know then where to
117 search for the static libraries.
118
119 @param src_path: string
120 Path (relative or absolute) to the src directory of Peano. This path
121 should hold both the headers (in subdirectories) and all the static
122 libraries.
123
124 @param mode: peano4.output.CompileMode
125
126 """
127 self._Peano_src_directory = src_path
128 self._build_mode = mode
129
130
132 """!
133
134 Parse makefile of Peano to extract the configuration settings
135
136 We parse the configure script's/CMAKE outcome first via parse_configure_script_outcome().
137 After that, we set the dimension manually as well as the executable name and
138 the build mode. The values for these parameters step from set_Peano4_installation().
139
140 """
141 self._project.output.makefile.parse_configure_script_outcome( self._Peano_src_directory )
142 self._project.output.makefile.set_dimension(self._dimensions)
143 self._project.output.makefile.set_executable_name(self._executable_name)
144 self._project.output.makefile.set_mode(self._build_mode)
145
147
149 dimensions,
150 offset,
151 domain_size,
152 plot_after_each_mesh_sweep,
153 max_iterations=100,
154 plotter_precision = 5,
155 ):
156 """
157
158 Configure global simulation settings
159
160 @param offset: [Float]
161
162 @param size: [Float]
163 should be lists with dimensions double entries.
164
165 """
166 self._domain_offset = offset
167 self._domain_size = domain_size
168 self._dimensions = dimensions
169 self._plot_after_each_mesh_sweep = plot_after_each_mesh_sweep
170 self._max_iterations = max_iterations
171 self._plotter_precision = plotter_precision
172 if plotter_precision<=0:
173 raise Exception( "Plotter precision has to be bigger than 0" )
174
175 def set_output_path(self,path):
176 self._output_path = path
177 if not self._output_path.endswith( "/" ):
178 self._output_path += "/"
179
180
181 def generate_Peano4_project(self, verbose=False):
182 """!
183
184 Build project
185
186 Construct and return the Peano4 project, i.e. all the action sets et al that
187 you require to run this Peano4 application with PETSc.
188
189 """
190 self._project.main = MatrixFreeMain(self._project,
191 self._domain_offset,
192 self._domain_size,
194 self._max_iterations
195 )
196
197 self._project.solversteps.add_step(self.algorithm_step_create_grid)
198 self._project.solversteps.add_step(self.algorithm_step_init_solution)
199 self._project.solversteps.add_step(self.algorithm_step_solve)
200 self._project.solversteps.add_step(self.algorithm_step_plot)
201
204
205 self._project.output.readme.add_package_description( """
206
207
208""" )
209
210 return self._project
211
212
214 self.dictionary = {}
215 self.dictionary[ "SOLVER_INSTANCES"] = [(x.typename(), x.instance_name()) for x in self._solvers ]
216 self.dictionary[ "AUX_SOLVER_INSTANCES"] = [(x.typename(), x.instance_name()) for x in self._aux_solvers ]
217
219 # make sure solver repository dict is set
221
222 templatefile_prefix = os.path.realpath(__file__).replace( ".pyc", "" ).replace( ".py", "" )
223 template_name = templatefile_prefix + ".SolverRepository.template"
225 template_name + ".h",
226 template_name + ".cpp",
227 "SolverRepository",
228 self._project.namespace, # + ["repositories"],
229 self._project.subdirectory + "repositories",
230 self.dictionary,
231 True,
232 True)
233
234 self._project.output.add( generated_repository_files )
235 self._project.output.makefile.add_h_file( self._project.subdirectory + "repositories/SolverRepository.h", generated=True )
236 self._project.output.makefile.add_cpp_file( self._project.subdirectory + "repositories/SolverRepository.cpp", generated=True )
237
238 def add_solver( self, solver, auxiliary=False ):
239 """!
240
241 Add a new solver
242
243 Takes the solver and runs through the individual steps of the algorithm.
244 Per step, it tells the solver to inject its particular stuff to the
245 underlying observers.
246
247 The auxiliary flag allows us to distinguish the "main" solver from the
248 helpers. The rationale for this is that we only want to measure the
249 termination conditions for a subset of the solvers.
250
251 """
252 print( "---------------------------------------")
253 print( "Create data for solver " +solver._name )
254 print( "---------------------------------------")
255 print( solver )
256
257 solver.add_to_Peano4_datamodel( self._project.datamodel, verbose=False )
258
259 solver.add_use_statements(self.algorithm_step_create_grid)
260 solver.add_use_statements(self.algorithm_step_init_solution)
261 solver.add_use_statements(self.algorithm_step_solve)
262 solver.add_use_statements(self.algorithm_step_plot)
263
264
265 solver.add_to_create_grid (self.algorithm_step_create_grid)
266 solver.add_to_init_solution(self.algorithm_step_init_solution)
267 solver.add_to_solve (self.algorithm_step_solve)
268
269 solver.add_to_plot (self.algorithm_step_plot)
270
271 if self._abstract_overwrite==False:
272 solver.add_implementation_files_to_project( self._project.namespace, self._project.output, self._subdirectory, self._abstract_overwrite )
273 else:
274 solver.add_implementation_files_to_project( self._project.namespace, self._project.output, self._subdirectory )
275
276 # @todo das muss raus
277 if auxiliary:
278 self._aux_solvers.append( solver )
279 else:
280 self._solvers.append( solver )
281
282 pass
283
285 """!
286
287 Export all the constrants of the project into a Configure.h file
288
289 We export ExaHyPE's constants. Besides the constants from ExaHyPE,
290 I also export some parameters from Peano onto the ExaHyPE constants
291 file. Therefore, it is important that you parse the configure output
292 before we export the constants.
293
294 """
295 self._project.constants.clear()
296 offset_string = "{" + str(self._domain_offset[0])
297 size_string = "{" + str(self._domain_size[0])
298 for i in range(1, self._dimensions):
299 offset_string += ","
300 size_string += ","
301 offset_string += str(self._domain_offset[i])
302 size_string += str(self._domain_size[i])
303 offset_string += "}"
304 size_string += "}"
305 self._project.constants.add_include("""#include <bitset>""")
306 self._project.constants.add_include("""#include "tarch/la/Vector.h" """)
307 self._project.constants.add_include("""#include "peano4/utils/Globals.h" """)
308 self._project.constants.export_const_with_type(
309 "DomainOffset", offset_string, "tarch::la::Vector<Dimensions,double>"
310 )
311 self._project.constants.export_const_with_type(
312 "DomainSize", size_string, "tarch::la::Vector<Dimensions,double>"
313 )
314 self._project.constants.export("PlotterPrecision", str(self._plotter_precision))
315
316 build_string = "python3 "
317 for i in sys.argv:
318 build_string += " "
319 build_string += i
320 self._project.constants.export_string("BuildInformation", build_string)
321 self._project.constants.export_string(
322 "ConfigureInformation", self._project.output.makefile.configure_call
323 )
324
325 self._project.output.readme.add_package_description(
326 """!
327
328### Peano's multigrid extension
329
330This is yet to be written, and we need to have a paper on our work.
331
332 @article{Reinarz:2020:ExaHyPE,
333 title = {ExaHyPE: An engine for parallel dynamically adaptive simulations of wave problems},
334 journal = {Computer Physics Communications},
335 volume = {254},
336 pages = {107251},
337 year = {2020},
338 issn = {0010-4655},
339 doi = {https://doi.org/10.1016/j.cpc.2020.107251},
340 url = {https://www.sciencedirect.com/science/article/pii/S001046552030076X},
341 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},
342 keywords = {Hyperbolic, PDE, ADER-DG, Finite volumes, AMR, MPI, TBB, MPI+X},
343 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.
344 Program summary
345 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.
346 }
347 }
348"""
349 )
350
351 for i in self._solvers:
352 self._project.output.readme.add_entry(
353 i.create_readme_descriptor()
354 )
355
356 @property
357 def subdirectory(self):
358 return self._subdirectory
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:155
set_Peano4_installation(self, src_path, mode=peano4.output.CompileMode.Release)
Tell the project where to find Peano.
Definition Project.py:110
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:218
__export_constants(self)
Export all the constrants of the project into a Configure.h file.
Definition Project.py:284
__set_solver_repository_dict(self)
Definition Project.py:213
set_output_path(self, path)
Definition Project.py:175
generate_Peano4_project(self, verbose=False)
Build project.
Definition Project.py:181
__configure_makefile(self)
Parse makefile of Peano to extract the configuration settings.
Definition Project.py:131
set_load_balancing(self, load_balancer_name, load_balancer_arguments)
Set the load balancing scheme.
Definition Project.py:90
__init__(self, namespace, project_name, directory=".", executable="peano4matrixfree", subdirectory="", abstract_overwrite=True)
Create a matrix project.
Definition Project.py:46
add_solver(self, solver, auxiliary=False)
Add a new solver.
Definition Project.py:238
Represents a Peano 4 project.
Definition Project.py:16