Peano
Loading...
Searching...
No Matches
ComputeLinearCombination.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
3import peano4.api
4
5from ...rungekutta.LinearCombination import create_linear_combination_call
6from .AbstractRKFD4ActionSet import AbstractRKFD4ActionSet
7
8
10 """!
11
12 Combine the solution with the right-hand side estimates of the
13 Runge-Kutta stages
14
15 The action set computes
16
17 @f$ Q_{out} = Q^n + \\Delta t \\sum _j w_j K_j @f$
18
19 per grid cell through the kernel of @ref exahype2.api.rungekutta.LinearCombination,
20 with @f$ Q^n @f$ being solver._patch and the @f$ K_j @f$ the estimates in
21 solver._rhs_estimates. The weights are either a row of the Butcher
22 tableau's weight matrix, which yields the input of a stage, or the
23 final estimate weights, which yield the solution of the next time step.
24 In the latter case, the output is solver._patch itself.
25
26 The auxiliary variables are copied from solver._patch.
27
28 """
29
30 def __init__(self, solver, weights, output, guard):
31 """!
32
33 @param solver: exahype2.api.Solver
34 Has to have an exahype2.api.rkfd4.CentralDifferencesWithRungeKutta
35 as numerical scheme.
36
37 @param weights: [float]
38 One weight per Runge-Kutta stage.
39
40 @param output: peano4.api.datamodel.Patch
41 The cell data to write the outcome into, i.e. solver._stage_input
42 or solver._patch.
43
44 @param guard: str
45 C++ boolean expression, evaluated per cell in touchCellFirstTime.
46
47 """
48 AbstractRKFD4ActionSet.__init__(self, solver)
49 self.weights = list(weights)
50 self.output = output
51 self.guard = guard
52
53 def get_body_of_operation(self, operation_name):
54 if (
55 operation_name
56 != peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
57 ):
58 return ""
59 scheme = self._solver.numerical_scheme
60 n = scheme.patch_size
61
62 def call(number_of_dofs):
63 return create_linear_combination_call(
64 namespace=scheme.kernel_namespace,
65 number_of_dofs=number_of_dofs,
66 unknowns=self._solver.unknowns,
67 auxiliary_variables=self._solver.auxiliary_variables,
68 weights=self.weights,
69 solution=f"fineGridCell{self._solver._patch.name}.value",
70 estimates=f"fineGridCell{self._solver._rhs_estimates.name}.value",
71 output=f"fineGridCell{self.output.name}.value",
72 time_step_size=f"repositories::{self._solver.get_name_of_global_instance()}.getMinTimeStepSize()",
73 )
74
75 return f"""
76 #if Dimensions==2
77 {call(n * n)}
78 #else
79 {call(n * n * n)}
80 #endif
81"""
82
83 def get_guard_of_operation(self, operation_name):
84 if (
85 operation_name
86 == peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
87 ):
88 return self.guard
89 return "true"
90
92 return __name__.replace(".py", "").replace(".", "_")
Base class of the action sets of exahype2.api.rkfd4 which work against the solver.
Combine the solution with the right-hand side estimates of the Runge-Kutta stages.
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.