Peano
Loading...
Searching...
No Matches
ScalarJacobiWithRediscretisation.py
Go to the documentation of this file.
1# This file is part of the Peano project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from peano4.solversteps.ActionSet import ActionSet
4
5
6import jinja2
7
8
10
11
12 def __init__(self,
13 vertex_data,
14 relaxation_coefficient,
15 rhs_expr,
16 unknown_setter="setU",
17 unknown_getter="getU",
18 residual_setter="setResidual",
19 residual_getter="getResidual",
20 store_residual_persistently_and_update_in_touch_first = True,
21 guard="true"
22 ):
23 """
24
25 :Attibutes:
26
27 vertex_data: DaStGen object
28 This object must have at least two attributes: A double value u and a double
29 value residual.
30
31 kappa_expr: C++ code (string)
32 Material parameter. Pass in 1.0 if there's no jump anywhere.
33
34
35 """
36 self.d = {}
37 self.d[ "UNKNOWN" ] = vertex_data.name
38 self.d[ "UNKNOWN_SETTER" ] = unknown_setter
39 self.d[ "UNKNOWN_GETTER" ] = unknown_getter
40 self.d[ "RESIDUAL_SETTER" ] = residual_setter
41 self.d[ "RESIDUAL_GETTER" ] = residual_getter
42 self.d[ "OMEGA" ] = relaxation_coefficient
43 self.d[ "RHS" ] = rhs_expr
44 self.d[ "GUARD" ] = guard
46 self._store_residual_persistently_and_update_in_touch_first = store_residual_persistently_and_update_in_touch_first
47
48
50 return " return std::vector< peano4::grid::GridControlEvent >();\n"
51
52
54 return __name__.replace(".py", "").replace(".", "_")
55
56
58 return False
59
60
61 __Template_Constructor = jinja2.Template("""
62 _cellStiffnessMatrix = toolbox::finiteelements::StencilFactory::getLaplacian( 0.0, 1.0 );
63""")
64
65
66 #def get_constructor_body(self):
67 # return self.__Template_Constructor.format(**self.d)
68
69
70 Template_ResetResidual = """
71 fineGridVertex{{UNKNOWN}}.{{RESIDUAL_SETTER}}(0.0);
72"""
73
74
75 """
76
77 This is where you should interpolate
78
79 @todo Einbauen! Obwohl wir wissen, dass es ueberschrieben wird
80
81 """
82 Template_CreateHangingVertex = """
83 fineGridVertex{{UNKNOWN}}.{{RESIDUAL_SETTER}}(0.0);
84"""
85
86
87 Template_TouchCellFirstTime = """
88 if ({{GUARD}}) {
89 const tarch::la::Vector<ThreePowerD,double> stencil = toolbox::finiteelements::getLaplacian(
90 marker.h(), 1.0
91 );
92 const toolbox::finiteelements::ElementWiseAssemblyMatrix A = toolbox::finiteelements::getElementWiseAssemblyMatrix(
93 stencil
94 );
95
96 tarch::la::Vector<TwoPowerD,double> u;
97 for (int i=0; i<TwoPowerD; i++) {
98 u(i) = fineGridVertices{{UNKNOWN}}(i).{{UNKNOWN_GETTER}}();
99 }
100
101 tarch::la::Vector<TwoPowerD,double> r = A * u;
102
103 for (int i=0; i<TwoPowerD; i++) {
104 fineGridVertices{{UNKNOWN}}(i).{{RESIDUAL_SETTER}}(
105 fineGridVertices{{UNKNOWN}}(i).{{RESIDUAL_GETTER}}() + r(i)
106 );
107 }
108 }
109"""
110
111
112 Template_UpdateValue = """
113 const tarch::la::Vector<ThreePowerD,double> stencil = toolbox::finiteelements::getLaplacian(
114 marker.h(), 1.0
115 );
116 const double diag = stencil(ThreePowerD/2);
117 const double residual = {{RHS}} * tarch::la::volume(marker.h()) - fineGridVertex{{UNKNOWN}}.{{RESIDUAL_GETTER}}();
118 fineGridVertex{{UNKNOWN}}.{{UNKNOWN_SETTER}}(
119 fineGridVertex{{UNKNOWN}}.{{UNKNOWN_GETTER}}()
120 +
121 {{OMEGA}} * residual / diag
122 );
123
124 if ( marker.coincidesWithCoarseGridVertex() ) {
125 tarch::la::Vector<Dimensions,int> parent = marker.getRelativePositionWithinFatherCell() / 3;
126 coarseGridVertices{{UNKNOWN}}( peano4::utils::dLinearised(parent,2) ).{{UNKNOWN_SETTER}}(
127 fineGridVertex{{UNKNOWN}}.{{UNKNOWN_GETTER}}()
128 );
129 }
130"""
131
132
133 Template_CreatePersistentVertex = """
134"""
135
136 def get_body_of_operation(self,operation_name):
137 result = "\n"
138 if operation_name==ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME:
139 result = """
140logTraceIn( "touchVertexFirstTime()" );
141"""
143 result += jinja2.Template(self.Template_UpdateValue).render(**self.d)
144 result += jinja2.Template(self.Template_ResetResidual).render(**self.d)
145 result += """
146logTraceOut( "touchVertexFirstTime()" );
147"""
148 if operation_name==ActionSet.OPERATION_CREATE_HANGING_VERTEX:
149 result = """
150logTraceIn( "createHangingVertex()" );
151"""
152 result += jinja2.Template(self.Template_CreateHangingVertex).render(**self.d)
153 result += """
154logTraceOut( "createHangingVertex()" );
155"""
156 if operation_name==ActionSet.OPERATION_CREATE_PERSISTENT_VERTEX:
157 result = """
158logTraceIn( "createPersistentVertex()" );
159"""
160 result += jinja2.Template(self.Template_CreatePersistentVertex).render(**self.d)
161 result += """
162logTraceOut( "createPersistentVertex()" );
163"""
164 if operation_name==ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
165 result = """
166logTraceIn( "touchCellFirstTime()" );
167"""
168 result += jinja2.Template(self.Template_TouchCellFirstTime).render(**self.d)
169 result += """
170logTraceOut( "touchCellFirstTime()" );
171"""
172 if operation_name==ActionSet.OPERATION_TOUCH_VERTEX_LAST_TIME:
173 result = """
174logTraceIn( "touchVertexLastTime()" );
175"""
177 result += jinja2.Template(self.Template_UpdateValue).render(**self.d)
178 result += """
179logTraceOut( "touchVertexLastTime()" );
180"""
181 return result
182
183
184 def get_attributes(self):
185 return """
186 toolbox::finiteelements::ElementWiseAssemblyMatrix _cellStiffnessMatrix;
187"""
188
189
190 def get_includes(self):
191 return """
192#include "toolbox/finiteelements/ElementMatrix.h"
193#include "toolbox/finiteelements/StencilFactory.h"
194
195#include "peano4/utils/Loop.h"
196""" + self.additional_includes
Action set (reactions to events)
Definition ActionSet.py:6
__init__(self, vertex_data, relaxation_coefficient, rhs_expr, unknown_setter="setU", unknown_getter="getU", residual_setter="setResidual", residual_getter="getResidual", store_residual_persistently_and_update_in_touch_first=True, guard="true")
:Attibutes:
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.