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.api.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 const tarch::la::Vector<ThreePowerD,double> stencil = toolbox::finiteelements::getLaplacian(
89 marker.h(), 1.0
90 );
91 const toolbox::finiteelements::ElementWiseAssemblyMatrix A = toolbox::finiteelements::getElementWiseAssemblyMatrix(
92 stencil
93 );
94
95 tarch::la::Vector<TwoPowerD,double> u;
96 for (int i=0; i<TwoPowerD; i++) {
97 u(i) = fineGridVertices{{UNKNOWN}}(i).{{UNKNOWN_GETTER}}();
98 }
99
100 tarch::la::Vector<TwoPowerD,double> r = A * u;
101
102 for (int i=0; i<TwoPowerD; i++) {
103 fineGridVertices{{UNKNOWN}}(i).{{RESIDUAL_SETTER}}(
104 fineGridVertices{{UNKNOWN}}(i).{{RESIDUAL_GETTER}}() + r(i)
105 );
106 }
107"""
108
109
110 Template_UpdateValue = """
111 const tarch::la::Vector<ThreePowerD,double> stencil = toolbox::finiteelements::getLaplacian(
112 marker.h(), 1.0
113 );
114 const double diag = stencil(ThreePowerD/2);
115 const double residual = {{RHS}} * tarch::la::volume(marker.h()) - fineGridVertex{{UNKNOWN}}.{{RESIDUAL_GETTER}}();
116 fineGridVertex{{UNKNOWN}}.{{UNKNOWN_SETTER}}(
117 fineGridVertex{{UNKNOWN}}.{{UNKNOWN_GETTER}}()
118 +
119 {{OMEGA}} * residual / diag
120 );
121
122 if ( marker.coincidesWithCoarseGridVertex() ) {
123 tarch::la::Vector<Dimensions,int> parent = marker.getRelativePositionWithinFatherCell() / 3;
124 coarseGridVertices{{UNKNOWN}}( peano4::utils::dLinearised(parent,2) ).{{UNKNOWN_SETTER}}(
125 fineGridVertex{{UNKNOWN}}.{{UNKNOWN_GETTER}}()
126 );
127 }
128"""
129
130
131 Template_CreatePersistentVertex = """
132"""
133
134 def get_body_of_operation(self,operation_name):
135 result = "\n"
136 if operation_name==ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME:
137 result = """
138logTraceIn( "touchVertexFirstTime()" );
139"""
141 result += jinja2.Template(self.Template_UpdateValue).render(**self.d)
142 result += jinja2.Template(self.Template_ResetResidual).render(**self.d)
143 result += """
144logTraceOut( "touchVertexFirstTime()" );
145"""
146 if operation_name==ActionSet.OPERATION_CREATE_HANGING_VERTEX:
147 result = """
148logTraceIn( "createHangingVertex()" );
149"""
150 result += jinja2.Template(self.Template_CreateHangingVertex).render(**self.d)
151 result += """
152logTraceOut( "createHangingVertex()" );
153"""
154 if operation_name==ActionSet.OPERATION_CREATE_PERSISTENT_VERTEX:
155 result = """
156logTraceIn( "createPersistentVertex()" );
157"""
158 result += jinja2.Template(self.Template_CreatePersistentVertex).render(**self.d)
159 result += """
160logTraceOut( "createPersistentVertex()" );
161"""
162 if operation_name==ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
163 result = """
164logTraceIn( "touchCellFirstTime()" );
165"""
166 result += jinja2.Template(self.Template_TouchCellFirstTime).render(**self.d)
167 result += """
168logTraceOut( "touchCellFirstTime()" );
169"""
170 if operation_name==ActionSet.OPERATION_TOUCH_VERTEX_LAST_TIME:
171 result = """
172logTraceIn( "touchVertexLastTime()" );
173"""
175 result += jinja2.Template(self.Template_UpdateValue).render(**self.d)
176 result += """
177logTraceOut( "touchVertexLastTime()" );
178"""
179 return result
180
181
182 def get_guard_of_operation(self,operation_name):
183 if operation_name==ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
184 return self.d[ "GUARD" ]
185 return "true"
186
187
188 def get_attributes(self):
189 return """
190 toolbox::finiteelements::ElementWiseAssemblyMatrix _cellStiffnessMatrix;
191"""
192
193
194 def get_includes(self):
195 return """
196#include "toolbox/finiteelements/ElementMatrix.h"
197#include "toolbox/finiteelements/StencilFactory.h"
198
199#include "peano4/utils/Loop.h"
200""" + self.additional_includes
Action set (reactions to events)
Definition ActionSet.py:6
get_body_of_createGridControlEventsForNextTraversal(self)
Return the grid control events that this action set wants to trigger.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
__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: