Peano
Loading...
Searching...
No Matches
InsertPatchInterior.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 .AbstractFVActionSet import AbstractFVActionSet
4from .DiscardPatchInterior import wait_for_patch_interior_update, WAIT_INCLUDES
5
6import peano4.api
7
8
10 """!
11
12 Insert the patch interior into the patch
13
14 Copies solver._patch_interior, i.e. the result of
15 exahype2.api.fv.actionsets.UpdateCellInterior, into the patch interior
16 of solver._patch. Afterwards, the first entry of solver._max_eigenvalue_and_time_step_sizes
17 holds the maximum of its first entry (the maximum eigenvalue of the
18 shell) and its third entry (the maximum eigenvalue of the patch
19 interior), i.e. the maximum eigenvalue of the whole patch (@see
20 exahype2.api.fv.RusanovWithOptimisticExplicitEuler).
21
22 If the patch interior is updated by a task (@see
23 exahype2.api.fv.actionsets.SpawnTaskToUpdateCellInterior), the action
24 set first waits for this task.
25
26 """
27
28 def __init__(self, solver, patch_size, overlap, guard, task_number=None):
29 """!
30
31 @param solver: exahype2.api.Solver
32 Has to have solver._patch, solver._patch_interior and
33 solver._max_eigenvalue_and_time_step_sizes set - @see
34 exahype2.api.fv.RusanovWithOptimisticExplicitEuler.
35
36 @param patch_size: int
37 Number of Finite Volumes per axis within one patch.
38
39 @param overlap: int
40 Thickness of the shell, i.e. the patch interior has
41 patch_size-2*overlap Finite Volumes per axis.
42
43 @param guard: str
44 C++ boolean expression, evaluated per cell in touchCellFirstTime,
45 guarding whether that cell's patch interior is inserted.
46
47 @param task_number: peano4.api.datamodel.DaStGen2
48 Cell data holding the number of the task updating the patch
49 interior. If given, the action set waits for this task before it
50 copies the patch interior. None if the patch interior is not
51 updated by a task.
52
53 """
54 AbstractFVActionSet.__init__(self, solver)
55 self.task_number = task_number
56 self.patch_size = patch_size
57 self.overlap = overlap
58 self.guard = guard
59
60 def get_body_of_operation(self, operation_name):
61 result = ""
62 if operation_name == peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
63 unknowns = self._solver.unknowns + self._solver.auxiliary_variables
64 interior_size = self.patch_size - 2 * self.overlap
65 max_eigenvalue = f"fineGridCell{self._solver._max_eigenvalue_and_time_step_sizes.name}"
66 if self.task_number is not None:
67 result = wait_for_patch_interior_update(self._solver, self.task_number)
68 result += f"""
69 dfor(interiorVolume,{interior_size}) {{
70 tarch::la::Vector<Dimensions,int> patchVolume = interiorVolume + tarch::la::Vector<Dimensions,int>({self.overlap});
71 int interiorVolumeSerialised = peano4::utils::dLinearised(interiorVolume,{interior_size});
72 int patchVolumeSerialised = peano4::utils::dLinearised(patchVolume,{self.patch_size});
73 for (int j=0; j<{unknowns}; j++) {{
74 fineGridCell{self._solver._patch.name}.value[patchVolumeSerialised*{unknowns}+j] = fineGridCell{self._solver._patch_interior.name}.value[interiorVolumeSerialised*{unknowns}+j];
75 }}
76 }}
77
78 {max_eigenvalue}.setMaxEigenvalue( 0, std::max( {max_eigenvalue}.getMaxEigenvalue(0), {max_eigenvalue}.getMaxEigenvalue(2) ) );
79"""
80 return result
81
82 def get_guard_of_operation(self, operation_name):
83 if operation_name == peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
84 return self.guard
85 return "true"
86
87 def get_includes(self):
88 result = super().get_includes() + """
89#include "peano4/utils/Loop.h"
90"""
91 if self.task_number is not None:
92 result += WAIT_INCLUDES
93 return result
94
96 return __name__.replace(".py", "").replace(".", "_")
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_action_set_name(self)
You should replicate this function in each subclass, so you get meaningful action set names (otherwis...
__init__(self, solver, patch_size, overlap, guard, task_number=None)
get_guard_of_operation(self, operation_name)
Return the guard of an operation.