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