Peano
Loading...
Searching...
No Matches
LinearCombinationOfEstimates.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
3
4from .AbstractRungeKuttaDGActionSet import AbstractRungeKuttaDGActionSet
5from exahype2.solvers.ButcherTableau import ButcherTableau
6
7import peano4
8import jinja2
9
11 r"""
12
13 Computes a linear combination of all of the estimates according to the
14 Butcher Tableau.
15
16 The linear combination is a volumetric representation which includes both
17 the degrees of freedom and the auxiliary variables. However, the auxiliary
18 variables are not developing over time. In Runge-Kutta, I have estimates
19 for the right-hand side, i.e. for the derivatives
20
21 @f$ \partial _t Q = F(Q) @f$
22
23 This is the stuff stored in RhsEstimates. It does not comprise any auxiliary
24 variables. So I have to copy the auxiliary variables from the last valid
25 time step every time I reconstruct a new guess.
26
27 """
28
29 TemplateLinearCombination = """
30 // Set the variable
31 // double timeStepSize
32 {{COMPUTE_TIME_STEP_SIZE}}
33
34 {% for PREDICATE_NO in range(0,PREDICATES|length) %}
35 if ({{PREDICATES[PREDICATE_NO]}}) {
36 ::exahype2::enumerator::AoSLexicographicEnumerator enumeratorWithAuxiliaryVariables ( 1, {{ORDER}}+1, 0, {{NUMBER_OF_UNKNOWNS}}, {{NUMBER_OF_AUXILIARY_VARIABLES}});
37 ::exahype2::enumerator::AoSLexicographicEnumerator enumeratorWithoutAuxiliaryVariables( {{RK_STEPS}}, {{ORDER}}+1, 0, {{NUMBER_OF_UNKNOWNS}}, 0 );
38
39 dfor( dof, {{ORDER}}+1 ) {
40 for (int unknown=0; unknown<{{NUMBER_OF_UNKNOWNS}}; unknown++) {
41 fineGridCell{{UNKNOWN_IDENTIFIER}}LinearCombination.value[ enumeratorWithAuxiliaryVariables(0,dof,unknown) ] =
42 fineGridCell{{UNKNOWN_IDENTIFIER}}.value[ enumeratorWithAuxiliaryVariables(0,dof,unknown) ];
43
44 {% for WEIGHT_NO in range(0,BUTCHER_TABLEAU_WEIGHTS[PREDICATE_NO]|length) %}
45 {% if BUTCHER_TABLEAU_WEIGHTS[PREDICATE_NO][WEIGHT_NO]!=0 %}
46 fineGridCell{{UNKNOWN_IDENTIFIER}}LinearCombination.value[ enumeratorWithAuxiliaryVariables(0,dof,unknown) ] +=
47 timeStepSize * {{BUTCHER_TABLEAU_WEIGHTS[PREDICATE_NO][WEIGHT_NO]}} *
48 fineGridCell{{UNKNOWN_IDENTIFIER}}RhsEstimates.value[ enumeratorWithoutAuxiliaryVariables({{WEIGHT_NO}},dof,unknown) ];
49 {% endif %}
50 {% endfor %}
51 }
52 for (int unknown={{NUMBER_OF_UNKNOWNS}}; unknown<{{NUMBER_OF_UNKNOWNS}}+{{NUMBER_OF_AUXILIARY_VARIABLES}}; unknown++) {
53 fineGridCell{{UNKNOWN_IDENTIFIER}}LinearCombination.value[ enumeratorWithAuxiliaryVariables(0,dof,unknown) ] =
54 fineGridCell{{UNKNOWN_IDENTIFIER}}.value[ enumeratorWithAuxiliaryVariables(0,dof,unknown) ];
55 }
56 }
57
58 {% if PREDICATE_NO==0 %}
59 {{PREPROCESS_UPDATED_CELL}}
60 {% endif %}
61 }
62 {% endfor %}
63"""
64
65 def __init__(self,solver):
66 """
67
68 guard: [String] (C++ code)
69 Sequence of predicates which determine when we compute the respective RK
70 linear combination. Can be empty.
71
72 """
73 super(LinearCombinationOfEstimates,self).__init__(solver)
74 self._guards = []
76
77
78 @property
79 def guards(self):
80 if self._guards==[]:
81 raise Exception( "Guards are not initialised" )
82 return self._guards
83
84
85 @guards.setter
86 def guards(self,new_guards):
87 if new_guards!=[] and len(new_guards)!=self._solver.number_of_Runge_Kutta_steps():
88 raise Exception( "Expect one guard per Runge Kutta step. Have {} steps but got guards {}".format(solver.number_of_Runge_Kutta_steps(),guards) )
89 self._guards = new_guards
90
91
92 def get_body_of_operation(self,operation_name):
93 result = ""
94 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
95 d = {}
96 self._solver._init_dictionary_with_default_parameters(d)
97 self._solver.add_entries_to_text_replacement_dictionary(d)
98 d[ "PREDICATES" ] = self.guardsguards
99 d[ "BUTCHER_TABLEAU_WEIGHTS" ] = self._butcher_tableau.weight_matrix()
100 d[ "BUTCHER_TABLEAU_RELATIVE_TIME_STEP_SIZES" ] = self._butcher_tableau.time_step_sizes()
101 result = jinja2.Template(self.TemplateLinearCombination).render(**d)
102 pass
103 return result
104
105
107 return __name__.replace(".py", "").replace(".", "_")
108
109
110 def get_includes(self):
111 return super(LinearCombinationOfEstimates,self).get_includes() + """
112#include "exahype2/enumerator/AoSLexicographicEnumerator.h"
113"""
Computes a linear combination of all of the estimates according to the Butcher Tableau.
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)
guard: [String] (C++ code) Sequence of predicates which determine when we compute the respective RK l...