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 "PARAMETERS": "".join(
55 f",\n fineGridCell{auxiliary.patch.name}.value + "
56 f"peano4::utils::dLinearised(gridCell,{self._solver.numerical_scheme.patch_size}) * {auxiliary.size}"
57 for auxiliary in self._solver.auxiliary_variables
58 ),
59 "UNKNOWN_IDENTIFIER": self._solver._unknown_identifier(),
60 "SOLVER_INSTANCE": self._solver.get_name_of_global_instance(),
61 }
62 result = jinja2.Template(self.TemplateInitialCondition).render(**d)
63
64 return result
65
66 def get_guard_of_operation(self, operation_name):
67 if (
68 operation_name
69 == peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
70 ):
71 return self.guard
72 return "true"
73
75 return __name__.replace(".py", "").replace(".", "_")
76
77 TemplateInitialCondition = """
78 logTraceIn( "touchCellFirstTime(...)---InitialCondition" );
79 parallelDfor( gridCell, {{NUMBER_OF_GRID_CELLS_PER_AXIS}} ) {
80 int index = peano4::utils::dLinearised(gridCell,{{NUMBER_OF_GRID_CELLS_PER_AXIS}}) * {{NUMBER_OF_UNKNOWNS}};
81 repositories::{{SOLVER_INSTANCE}}.initPointWisely(
82 ::exahype2::fd::getGridCellCentre( marker.x(), marker.h(), {{NUMBER_OF_GRID_CELLS_PER_AXIS}}, gridCell),
83 fineGridCell{{UNKNOWN_IDENTIFIER}}.value + index{{PARAMETERS}}
84 );
85 } endParallelDfor
86
87 logTraceOut( "touchCellFirstTime(...)---InitialCondition" );
88"""
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.