Peano
Loading...
Searching...
No Matches
DiscardPatchInterior.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
4
5import peano4.api
6
7
8def wait_for_patch_interior_update(solver, task_number) -> str:
9 """!
10
11 C++ code which waits for the task updating the patch interior
12
13 The code waits only if the cell holds a task number, and never in the
14 very first time step, where the task number has not been set yet (@see
15 exahype2.api.fv.actionsets.SpawnTaskToUpdateCellInterior). Afterwards,
16 it releases the task number.
17
18 @param solver: exahype2.api.Solver
19 The solver the patch interior belongs to.
20
21 @param task_number: peano4.api.datamodel.DaStGen2
22 Cell data holding the task number.
23
24 """
25 data = f"fineGridCell{task_number.name}"
26 return f"""
27 if (
28 not tarch::la::equals(repositories::{solver.get_name_of_global_instance()}.getAdmissibleTimeStepSize(), 0.0)
29 and
30 {data}.getTaskNumber()>=0
31 ) {{
32 tarch::multicore::waitForTask( {data}.getTaskNumber() );
33 {data}.getTaskEnumerator().releaseNumber( {data}.getTaskNumber() );
34 {data}.setTaskNumber( tarch::multicore::TaskEnumerator::NoNumber );
35 }}
36"""
37
38
39WAIT_INCLUDES = """
40#include "tarch/la/ScalarOperations.h"
41#include "tarch/multicore/multicore.h"
42#include "tarch/multicore/TaskEnumerator.h"
43"""
44
45
47 """!
48
49 Discard the patch interior
50
51 Counterpart of exahype2.api.fv.actionsets.InsertPatchInterior
52 (@see exahype2.api.fv.RusanovWithOptimisticExplicitEuler).
53
54 If the patch interior is updated by a task (@see
55 exahype2.api.fv.actionsets.SpawnTaskToUpdateCellInterior), the action
56 set waits for this task, as it would otherwise still write into the
57 patch interior while the next task is spawned. It does nothing with the
58 task's outcome afterwards. If the patch interior is not updated by a
59 task, the action set does nothing at all.
60
61 """
62
63 def __init__(self, solver, guard, task_number=None):
64 """!
65
66 @param solver: exahype2.api.Solver
67 The solver the patch interior belongs to.
68
69 @param guard: str
70 C++ boolean expression, evaluated per cell in touchCellFirstTime,
71 guarding whether that cell's patch interior is discarded.
72
73 @param task_number: peano4.api.datamodel.DaStGen2
74 Cell data holding the number of the task updating the patch
75 interior, or None if the patch interior is not updated by a task.
76
77 """
78 AbstractFVActionSet.__init__(self, solver)
79 self.task_number = task_number
80 self.guard = guard
81
82 def get_body_of_operation(self, operation_name):
83 if (
84 self.task_number is not None
85 and operation_name == peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
86 ):
87 return wait_for_patch_interior_update(self._solver_solver, self.task_number)
88 return ""
89
90 def get_includes(self):
91 result = super().get_includes()
92 if self.task_number is not None:
93 result += WAIT_INCLUDES
94 return result
95
96 def get_guard_of_operation(self, operation_name):
97 if operation_name == peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
98 return self.guard
99 return "true"
100
102 return __name__.replace(".py", "").replace(".", "_")
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.