Peano
Loading...
Searching...
No Matches
ComputeMaxEigenvalue.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
5from ...AuxiliaryVariables import code_to_assemble_kernel_input
6import peano4.api
7
8
10 """!
11
12 Store the maximum eigenvalue over the volumes of a patch
13
14 The action set runs after the patch update, i.e. it sees the updated
15 solution in solver._patch. It invokes the eigenvalue kernel, which is a
16 kernel of its own and not a by-product of the time step kernel, and
17 stores the outcome in the first entry of the cell data
18 max_eigenvalue (by default solver._max_eigenvalue). It does nothing
19 else: the reduction over the cells is a task of its own
20 (@ref exahype2.api.fv.actionsets.ReduceMaxEigenvalue), and
21 exahype2.api.fv.actionsets.ComputeGlobalCFLCondition derives the next
22 time step size from its outcome. The task graph compiler can fuse the
23 update, the eigenvalue computation and the reduction into one mesh
24 traversal.
25
26 """
27
28 def __init__(self, solver, guard, max_eigenvalue=None):
29 """!
30
31 @param solver: exahype2.api.Solver
32 Has to have solver._patch and solver._max_eigenvalue set, and
33 solver.numerical_scheme.max_eigenvalue_kernel_call constructed -
34 @see exahype2.api.fv.RusanovWithExplicitEuler.
35
36 @param guard: str
37 C++ boolean expression, evaluated per cell in touchCellFirstTime.
38
39 @param max_eigenvalue: peano4.api.datamodel.DaStGen2
40 The cell data the maximum eigenvalue goes into (first entry).
41 Defaults to solver._max_eigenvalue.
42
43 """
44 AbstractFVActionSet.__init__(self, solver)
45 self.guard = guard
47 max_eigenvalue if max_eigenvalue is not None else solver._max_eigenvalue
48 )
49
50 def get_body_of_operation(self, operation_name):
51 if (
52 operation_name
53 != peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
54 ):
55 return ""
56 solver = self._solver
57 unknowns = f"fineGridCell{solver._patch.name}.value"
58 has_parameters = len(solver.auxiliary_variables) > 0
59 kernel_in = "kernelIn.data()" if has_parameters else unknowns
60 return f"""
61 {code_to_assemble_kernel_input(solver, "kernelIn", unknowns, 0, lambda auxiliary: f"fineGridCell{auxiliary.patch.name}.value")}
62 ::exahype2::CellData patchData(
63 {kernel_in},
64 marker.x(),
65 marker.h(),
66 repositories::{solver.get_name_of_global_instance()}.getMinTimeStamp(),
67 repositories::{solver.get_name_of_global_instance()}.getMinTimeStepSize(),
68 {unknowns}
69 );
70 {solver.numerical_scheme.max_eigenvalue_kernel_call}
71 fineGridCell{self._max_eigenvalue.name}.setMaxEigenvalue( 0, patchData.maxEigenvalue[0] );
72"""
73
74 def get_guard_of_operation(self, operation_name):
75 if (
76 operation_name
77 == peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
78 ):
79 return self.guard
80 return "true"
81
83 return __name__.replace(".py", "").replace(".", "_")
Store the maximum eigenvalue over the volumes of a patch.
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...
get_guard_of_operation(self, operation_name)
Return the guard of an operation.