Peano
Loading...
Searching...
No Matches
ConsumeRefinementRequests.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 peano4.api.solversteps.ActionSet import ActionSet
4
5
7 """!
8
9 Hand the refine and erase requests of the last time step over to Peano,
10 and restart the time stepping if the mesh has changed
11
12 The last task of each time step collects refine and erase requests
13 within ::exahype2::RefinementControlService
14 (@ref exahype2.api.blockstructured.DynamicMeshRefinement). The mesh
15 adaptation phase hosts this action set in its repeating task. The action
16 set does not issue any further request. It
17
18 - hands the service's committed events over to Peano
19 (createGridControlEventsForNextTraversal()), so Peano realises them,
20 - calls the service's finishStep() once per rank after each mesh
21 sweep, so the events expire after their lifetime. The repeating task
22 runs until the service holds no events anymore, i.e. no request
23 survives into the next time step, and
24 - keeps track of whether a mesh sweep has created or destroyed any cell.
25 If so, it resets the solver's time step size to zero
26 (exahype2::Solver::resetTimeStepSize()) at the end of the sweep. The
27 time step size of the old mesh might violate the CFL condition on the
28 new mesh. With a time step size of zero, the subsequent time step does
29 not advance in time but derives a new admissible time step size from
30 the new mesh.
31
32 Whether the mesh has changed is reduced over all ranks, so all ranks
33 reset the time step size consistently.
34
35 """
36
37 def __init__(self, solver):
38 """!
39
40 @param solver: exahype2.api.Solver
41 The solver whose time step size is reset if the mesh changes.
42
43 """
44 super().__init__(descend_invocation_order=1, parallel=False)
45 self._solver = solver
46
48 return ""
49
51 return ""
52
54 return " return ::exahype2::RefinementControlService::getInstance().createGridControlEventsForNextTraversal();\n"
55
57 return " _meshHasChanged = false;\n"
58
60 return f"""
61 ::exahype2::RefinementControlService::getInstance().finishStep();
62
63 int localMeshHasChanged = _meshHasChanged ? 1 : 0;
64 int globalMeshHasChanged = localMeshHasChanged;
65 #ifdef Parallel
66 tarch::mpi::Rank::getInstance().allReduce(
67 &localMeshHasChanged, &globalMeshHasChanged, 1, MPI_INT, MPI_MAX,
68 [&]() -> void {{ tarch::services::ServiceRepository::getInstance().receiveDanglingMessages(); }}
69 );
70 #endif
71 if (globalMeshHasChanged > 0) {{
72 logInfo( "unprepareTraversal()", "mesh has changed, reset time step size of {self._solver.name} to zero" );
73 repositories::{self._solver.get_name_of_global_instance()}.resetTimeStepSize();
74 }}
75"""
76
77 def get_body_of_operation(self, operation_name):
78 if operation_name in [
79 ActionSet.OPERATION_CREATE_CELL,
80 ActionSet.OPERATION_DESTROY_CELL,
81 ]:
82 return " _meshHasChanged = true;\n"
83 return ""
84
85 def get_attributes(self):
86 return """
87 static std::atomic<bool> _meshHasChanged;
88"""
89
90 def get_static_initialisations(self, full_qualified_classname):
91 return (
92 f"std::atomic<bool> {full_qualified_classname}::_meshHasChanged(false);\n"
93 )
94
96 return __name__.replace(".py", "").replace(".", "_")
97
99 return False
100
101 def get_includes(self):
102 return (
103 """
104#include <atomic>
105#include "exahype2/RefinementControlService.h"
106#include "tarch/mpi/Rank.h"
107#include "tarch/services/ServiceRepository.h"
108"""
109 + self._solver._get_default_includes()
110 + self._solver.user_solver_includes
111 )
Hand the refine and erase requests of the last time step over to Peano, and restart the time stepping...
get_attributes(self)
Return attributes as copied and pasted into the generated class.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_body_of_createGridControlEventsForNextTraversal(self)
Return the grid control events that this action set wants to trigger.
Action set (reactions to events)
Definition ActionSet.py:6