Peano
Loading...
Searching...
No Matches
InitialCondition.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
3from .AbstractRKFD4ActionSet import AbstractRKFD4ActionSet
4
5import peano4.api
6import jinja2
7
8
10 """!
11
12 Fill a patch's initial condition, one grid cell at a time, by calling
13 the solver's exahype2.api.InitPointWisely PDE term once per grid cell
14 with that grid cell's centre.
15
16 The Finite Differences of @ref exahype2.api.rkfd4 are cell-centred, i.e.
17 each patch hosts patch_size^d grid cells and the unknowns are located at
18 their centres. The action set is a copy of
19 exahype2.api.fv.actionsets.InitialCondition, which places the unknowns
20 in the very same way, as rkfd4 does not depend on the Finite Volume
21 package.
22
23 Checkpoint-restart support has deliberately not been ported: it relies
24 on Solver attributes that do not exist in the new exahype2.api yet.
25
26 """
27
28 def __init__(self, solver, guard):
29 """!
30
31 @param solver: exahype2.api.Solver
32 Has to have an InitPointWisely PDE term registered - @ref
33 exahype2.api.rkfd4.SetupSimulationOverRegularGrid asserts this
34 before it attaches an instance of this action set.
35
36 @param guard: str
37 C++ boolean expression, evaluated per cell, guarding whether the
38 initial condition is (re)written for that cell.
39
40 """
41 AbstractRKFD4ActionSet.__init__(self, solver)
42 self.guard = guard
43
44 def get_body_of_operation(self, operation_name):
45 result = ""
46
47 if (
48 operation_name
49 == peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
50 ):
51 d = {
52 "NUMBER_OF_GRID_CELLS_PER_AXIS": self._solver.numerical_scheme.patch_size,
53 "NUMBER_OF_UNKNOWNS": self._solver.unknowns,
54 "NUMBER_OF_AUXILIARY_VARIABLES": self._solver.auxiliary_variables,
55 "UNKNOWN_IDENTIFIER": self._solver._unknown_identifier(),
56 "SOLVER_INSTANCE": self._solver.get_name_of_global_instance(),
57 }
58 result = jinja2.Template(self.TemplateInitialCondition).render(**d)
59
60 return result
61
62 def get_guard_of_operation(self, operation_name):
63 if (
64 operation_name
65 == peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
66 ):
67 return self.guard
68 return "true"
69
71 return __name__.replace(".py", "").replace(".", "_")
72
73 TemplateInitialCondition = """
74 logTraceIn( "touchCellFirstTime(...)---InitialCondition" );
75 parallelDfor( gridCell, {{NUMBER_OF_GRID_CELLS_PER_AXIS}} ) {
76 int index = peano4::utils::dLinearised(gridCell,{{NUMBER_OF_GRID_CELLS_PER_AXIS}}) * ({{NUMBER_OF_UNKNOWNS}} + {{NUMBER_OF_AUXILIARY_VARIABLES}});
77 repositories::{{SOLVER_INSTANCE}}.initPointWisely(
78 ::exahype2::fd::getGridCellCentre( marker.x(), marker.h(), {{NUMBER_OF_GRID_CELLS_PER_AXIS}}, gridCell),
79 fineGridCell{{UNKNOWN_IDENTIFIER}}.value + index
80 );
81 } endParallelDfor
82
83 logTraceOut( "touchCellFirstTime(...)---InitialCondition" );
84"""
Base class of the action sets of exahype2.api.rkfd4 which work against the solver.
Fill a patch's initial condition, one grid cell at a time, by calling the solver's exahype2....
get_guard_of_operation(self, operation_name)
Return the guard of an operation.
get_action_set_name(self)
You should replicate this function in each subclass, so you get meaningful action set names (otherwis...
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.