Peano
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages Concepts
Project.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3import peano4
5
6import dastgen2
7
8import os
9import sys
10import itertools
11
12from .PETScMain import PETScMain
13
14
15
16
17class Project(object):
18 """!
19
20Multigrid solver project
21
22A project hosts a set of multigrid solvers for different PDEs (which you might
23eventually want to couple). Other than that, each project generates exactly
24one main file and a solver repository. The main file is represented by
25petsc.PETScMain, while the repository is generated directly by the project.
26Consult generate_Peano4_project() for the latter.
27
28
29## Algorithmic steps
30
31Every PETSc project runs through the following steps:
32
33 - algorithm_step_create_grid
34 - algorithm_step_enumerate_and_init_solution
35 - _algorithm_step_init_petsc
36 - algorithm_step_assemble
37 - _algorithm_step_solve
38 - algorithm_step_map_solution_onto_mesh
39 - algorithm_step_plot
40
41Each of these steps is mapped onto one observer. It is clear that not all
42steps actually lead to mesh traversals and, therefore, are not to be modified
43by users. They are simply there to allow the main function to pick a step and
44to tell all MPI ranks to run the same step on all local trees. I therefore
45mark these steps as private via a leading underscore.
46
47
48## Attributes
49
50 \param _solvers: [Solver]
51 List of tuples of typename and names of solvers that this project should use simultaneously.
52 \param preconditioner_type: String
53 Preconditioner type to be used. This part of the string should match the final
54 part of the enum class in src/petsc/LinearEquationSystem.h. The namespaceing is
55 taken care of downstream.
56 \param solver_type: String
57 Solver type to be used. This part of the string should match the final
58 part of the enum class in src/petsc/LinearEquationSystem.h. The namespaceing is
59 taken care of downstream.
60
61 """
62 def __init__(self,
63 namespace,
64 project_name,
65 directory = ".",
66 executable = "peano4petsc",
67 preconditioner_type = "None",
68 solver_type = "GMRES",
69 subdirectory="",
70 ):
71 self._project = peano4.Project(namespace, project_name, directory, subdirectory)
72 self._project.output.makefile.add_cmake_core_library("petsc")
73 self._subdirectory = subdirectory
74
75 self._domain_offset = [0.0, 0.0, 0.0]
76 self._domain_size = [1.0, 1.0, 1.0]
77 self._dimensions = 2
78 self._load_balancer_name = ""
80 self._Peano_src_directory = "."
81 self._build_mode = peano4.output.CompileMode.Asserts
82 self._executable_name = executable
83 self._output_path = "./"
84
85 self._solvers = []
86
87 self.algorithm_step_create_grid = peano4.solversteps.Step( "CreateGrid", False )
88 self.algorithm_step_enumerate_and_init_solution = peano4.solversteps.Step( "EnumerateAndInitSolution", False )
93 self.algorithm_step_plot = peano4.solversteps.Step( "Plot", False )
94
95 self.preconditioner_type = preconditioner_type
96 self.solver_type = solver_type
97
98 def set_load_balancing(self, load_balancer_name, load_balancer_arguments):
99 """
100
101 load_balancer_name: string
102 Should be full-qualified name of the load balancer.
103 By default, I recommend to pass "toolbox::loadbalancing::RecursiveSubdivision"
104
105 load_balancer_arguments: string
106 If your load balancing requires parameters, add them
107 here. It is a string that will be copied into the C++ class instantiation.
108 Please add the brackets yourself, i.e. "(3,4,5)" is fine, but "3,4,5" is not.
109 The only exception is the empty parameter list. Here, you can/should simply
110 add the empty string.
111
112 """
113 self._load_balancer_name = load_balancer_name
114 self._load_balancer_arguments = load_balancer_arguments
115
116
117 """
118 The standard extensions that I use for both Peano and ExaHyPE.
119 """
120 LibraryDebug = "_debug"
121 LibraryRelease = ""
122 LibraryTrace = "_trace"
123 LibraryAsserts = "_asserts"
124 LibraryStats = "_stats"
125
126
127 def set_Peano4_installation(self, src_path, mode=peano4.output.CompileMode.Release ):
128 """!
129
130src_path: string
131 Path (relative or absolute) to the src directory of Peano. This path
132 should hold both the headers (in subdirectories) and all the static
133 libraries.
134
135mode: peano4.output.CompileMode
136
137 """
138 self._Peano_src_directory = src_path
139 self._build_mode = mode
140
141
143 """!
144
145Configure the makefile of the PETSc project
146
147We parse the configure script's/CMAKE outcome first via parse_configure_script_outcome().
148After that, we set the dimension manually as well as the executable name and
149the build mode. The values for these parameters step from set_Peano4_installation().
150
151 """
152 self._project.output.makefile.parse_configure_script_outcome( self._Peano_src_directory )
153 self._project.output.makefile.set_dimension(self._dimensions)
154 self._project.output.makefile.set_executable_name(self._executable_name)
155 self._project.output.makefile.set_mode(self._build_mode)
156
158
159
161 dimensions,
162 offset,
163 domain_size,
164 plotter_precision = 5,
165 ):
166 """
167
168 offset and size should be lists with dimensions double entries.
169
170 """
171 self._domain_offset = offset
172 self._domain_size = domain_size
173 self._dimensions = dimensions
174 self._plotter_precision = plotter_precision
175 if plotter_precision<=0:
176 raise Exception( "Plotter precision has to be bigger than 0" )
177
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
188Build project
189
190Construct and return the Peano4 project, i.e. all the action sets et al that
191you require to run this Peano4 application with PETSc.
192
193This routine generates a Peano project, i.e. the domain-specific
194view is translated into a Peano model. Once you have called this routine,
195any changes to the PETSc project configuration do not propagate into the Peano
196setup anymore. If you alter the project setup, you have to call
197generate_Peano4_project() again to get a new snapshot/version of the
198Peano setup.
199
200The function runs through various steps:
201
2021. We create an instance of PETScMain that represents the C++ main file.
203
2042. We add the essential algorithmic steps to the result project. At this
205 point, they should all be configured properly
206
2073. We configure the makefile via __configure_makefile().
208
2094. Add the repository holding the instances of the solver.
210
2115. Ensure that the generated readme file holds all relevant literature and
212 links.
213
214 """
215 self._project.main = PETScMain(self._project,
216 self._domain_offset,
217 self._domain_size,
218 )
219
220 self._project.solversteps.add_step(self.algorithm_step_create_grid)
221 self._project.solversteps.add_step(self.algorithm_step_enumerate_and_init_solution)
222 self._project.solversteps.add_step(self._algorithm_step_init_petsc)
223 self._project.solversteps.add_step(self.algorithm_step_assemble)
224 self._project.solversteps.add_step(self._algorithm_step_solve)
225 self._project.solversteps.add_step(self.algorithm_step_map_solution_onto_mesh)
226 self._project.solversteps.add_step(self.algorithm_step_plot)
227
230
231 self._project.output.readme.add_package_description( """
232
233### Peano4 PETSc backend
234
235This yet has to be written.
236
237""" )
238
239 return self._project
240
241
243 self.dictionary = {}
244 self.dictionary[ "SOLVER_INSTANCES"] = [(x.typename(), x.instance_name()) for x in self._solvers ]
245 self.dictionary[ "PRECONDITIONER_TYPE" ] = "::petsc::LinearEquationSystem::PreconditionerType::" + self.preconditioner_type
246 self.dictionary[ "SOLVER_TYPE" ] = "::petsc::LinearEquationSystem::KSPSolverType::" + self.solver_type
247
248
250 """!
251
252 type_name_of_solvers: [String]
253 Name of the solvers that we should instantiate and use in the main.
254
255
256 """
258
259 templatefile_prefix = os.path.realpath(__file__).replace( ".pyc", "" ).replace( ".py", "" )
260 template_name = templatefile_prefix + ".SolverRepository.template"
262 template_name + ".h",
263 template_name + ".cpp",
264 "SolverRepository",
265 self._project.namespace,
266 self._project.subdirectory + "repositories",
267 self.dictionary,
268 True,
269 True)
270
271 self._project.output.add( generated_repository_files )
272 self._project.output.makefile.add_h_file( self._project.subdirectory + "repositories/SolverRepository.h", generated=True )
273 self._project.output.makefile.add_cpp_file( self._project.subdirectory + "repositories/SolverRepository.cpp", generated=True )
274
275
276 def add_solver( self, solver ):
277 """
278
279 Takes the solver and runs through the individual steps of the algorithm.
280 Per step, it tells the solver to inject its particular stuff to the
281 underlying observers.
282
283 """
284 print( "---------------------------------------")
285 print( "Create data for solver " +solver._name )
286 print( "---------------------------------------")
287 print( str(solver) )
288
289 solver.add_to_Peano4_datamodel( self._project.datamodel, verbose=False )
290
291 solver.add_use_statements(self.algorithm_step_create_grid)
292 solver.add_use_statements(self.algorithm_step_enumerate_and_init_solution)
293 solver.add_use_statements(self._algorithm_step_init_petsc)
294 solver.add_use_statements(self.algorithm_step_assemble)
295 solver.add_use_statements(self.algorithm_step_map_solution_onto_mesh)
296 solver.add_use_statements(self.algorithm_step_plot)
297
298 solver.add_to_create_grid (self.algorithm_step_create_grid)
299 solver.add_to_enumerate_and_init_solution(self.algorithm_step_enumerate_and_init_solution)
300 solver.add_to_init_petsc (self._algorithm_step_init_petsc)
301 solver.add_to_assemble (self.algorithm_step_assemble)
302 solver.add_to_map_solution_onto_mesh (self.algorithm_step_map_solution_onto_mesh)
303 solver.add_to_plot (self.algorithm_step_plot)
304
305 solver.add_implementation_files_to_project( self._project.namespace, self._project.output, self._subdirectory )
306
307 self._solvers.append( solver )
308
309 pass
310
311
313 """
314 We export ExaHyPE's constants. Besides the constants from ExaHyPE,
315 I also export some parameters from Peano onto the ExaHyPE constants
316 file. Therefore, it is important that you parse the configure output
317 before we export the constants.
318 """
319 self._project.constants.clear()
320 offset_string = "{" + str(self._domain_offset[0])
321 size_string = "{" + str(self._domain_size[0])
322 for i in range(1, self._dimensions):
323 offset_string += ","
324 size_string += ","
325 offset_string += str(self._domain_offset[i])
326 size_string += str(self._domain_size[i])
327 offset_string += "}"
328 size_string += "}"
329 self._project.constants.add_include("""#include <bitset>""")
330 self._project.constants.add_include("""#include "tarch/la/Vector.h" """)
331 self._project.constants.add_include("""#include "peano4/utils/Globals.h" """)
332 self._project.constants.export_const_with_type(
333 "DomainOffset", offset_string, "tarch::la::Vector<Dimensions,double>"
334 )
335 self._project.constants.export_const_with_type(
336 "DomainSize", size_string, "tarch::la::Vector<Dimensions,double>"
337 )
338 self._project.constants.export("PlotterPrecision", str(self._plotter_precision))
339
340 build_string = "python3 "
341 for i in sys.argv:
342 build_string += " "
343 build_string += i
344 self._project.constants.export_string("BuildInformation", build_string)
345 self._project.constants.export_string(
346 "ConfigureInformation", self._project.output.makefile.configure_call
347 )
348
349 self._project.output.readme.add_package_description(
350 """
351
352### Peano's multigrid extension
353
354This is yet to be written, and we need to have a paper on our work.
355
356 @article{Reinarz:2020:ExaHyPE,
357 title = {ExaHyPE: An engine for parallel dynamically adaptive simulations of wave problems},
358 journal = {Computer Physics Communications},
359 volume = {254},
360 pages = {107251},
361 year = {2020},
362 issn = {0010-4655},
363 doi = {https://doi.org/10.1016/j.cpc.2020.107251},
364 url = {https://www.sciencedirect.com/science/article/pii/S001046552030076X},
365 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},
366 keywords = {Hyperbolic, PDE, ADER-DG, Finite volumes, AMR, MPI, TBB, MPI+X},
367 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.
368 Program summary
369 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.
370 }
371 }
372"""
373 )
374
375 for i in self._solvers:
376 self._project.output.readme.add_entry(
377 i.create_readme_descriptor()
378 )
379
380
381 @property
382 def subdirectory(self):
383 return self._subdirectory
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
__generate_solver_repository(self)
Definition Project.py:218
algorithm_step_map_solution_onto_mesh
Definition Project.py:92
__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
algorithm_step_enumerate_and_init_solution
Definition Project.py:88
Represents a Peano 4 project.
Definition Project.py:16