Peano
Loading...
Searching...
No Matches
ProjectPETScSolutionBackOntoMesh.py
Go to the documentation of this file.
1# This file is part of the Peano's PETSc extension. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from peano4.solversteps.ActionSet import ActionSet
4
5import peano4
6import jinja2
7
8
10 """!
11
12Project solution vector from PETSc back onto vertices
13
14This action set works if and only if your PETSc data is associated with
15the vertices only. If runs over through the mesh. Each mesh vertex has
16a tree number and a (local) number. We take this tuple and ask the
17map what the global dof index is. With this index, we ask PETSc what the
18corresponding entry in the solution vector reads like.
19
20 """
21
22
23 TemplateTouchCellFirstTime = """
24 if ( fineGridCell{{SOLVER_NAME}}PETScData.getType() == celldata::{{SOLVER_NAME}}PETScData::Type::Interior ) {
25 logTraceIn( "touchCellFirstTime(...)" );
26
27 std::pair<int,int> localIndex( _spacetreeId, fineGridCell{{SOLVER_NAME}}PETScData.getUnknownBaseNumber() );
28 int globalIndex = repositories::{{SOLVER_INSTANCE}}.getLocalToGlobalMap().getGlobalIndex(localIndex, ::petsc::LocalToGlobalMap::Type::Cell);
29
30 for (int i=0; i<{{CELL_CARDINALITY}}; i++){
31 // place values into mesh
32 fineGridCell{{SOLVER_NAME}}.setValue( i,
33 repositories::{{SOLVER_INSTANCE}}.getLinearEquationSystem().get(globalIndex + i) );
34 }
35
36 logTraceOut( "touchCellFirstTime(...)" );
37 }
38"""
39
40 def __init__(self,
41 solver):
42 """!
43
44Initialise vertex-associated degrees of freedom
45
46The initialisation requires a solver object, as we have to know what C++
47object this solver will produce.
48
49solver: petsc.solvers.CollocatedLowOrderDiscretisation or similar solver where
50 degrees of freedom are assigned exclusively to the vertices.
51
52 """
53 super( ProjectPETScSolutionOnCellsBackOntoMesh, self ).__init__()
54 self.d = {}
55 self.d["SOLVER_INSTANCE"] = solver.instance_name()
56 self.d["SOLVER_NAME"] = solver.typename()
57 self.d["CELL_CARDINALITY"] = solver.number_of_matrix_entries_per_cell
58
59
60
61 def get_body_of_operation(self,operation_name):
62 """!
63
64Provide C++ code snippet for peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME
65
66Only touchVertexFirstTime is an event where this action set actually
67does something: It inserts the template TemplateInitVertex and
68replaces it with entries from the dictionary. The latter is befilled
69in init().
70
71 """
72 result = ""
73 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
74 result = jinja2.Template(self.TemplateTouchCellFirstTime).render(**self.d)
75 pass
76 return result
77
78
80 """!
81
82 Configure name of generated C++ action set
83
84 This action set will end up in the directory observers with a name that
85 reflects how the observer (initialisation) is mapped onto this action
86 set. The name pattern is ObserverName2ActionSetIdentifier where this
87 routine co-determines the ActionSetIdentifier. We make is reflect the
88 Python class name.
89
90 """
91 return __name__.replace(".py", "").replace(".", "_")
92
93
95 """!
96
97 The action set that Peano will generate that corresponds to this class
98 should not be modified by users and can safely be overwritten every time
99 we run the Python toolkit.
100
101 """
102 return False
103
104
105 def get_includes(self):
106 """!
107
108Consult petsc.Project for details
109
110"""
111 return """
112#include "../repositories/SolverRepository.h"
113"""
114
115 def get_attributes(self):
116 """!
117
118
119 """
120 return """
121 int _spacetreeId;
122"""
123
125 """!
126
127Define body of constructor
128
129Consult the superclass' description of the function for results. I
130basically initialise the _localMap with the correct tree number.
131
132@see get_attributes()
133
134 """
135 return """
136 _spacetreeId = treeNumber;
137"""
138
139
141 """!
142
143Project solution vector from PETSc back onto vertices
144
145This action set works if and only if your PETSc data is associated with
146the vertices only. If runs over through the mesh. Each mesh vertex has
147a tree number and a (local) number. We take this tuple and ask the
148map what the global dof index is. With this index, we ask PETSc what the
149corresponding entry in the solution vector reads like.
150
151 """
152
153 TemplateTouchVertexFirstTime = """
154 if (fineGridVertex{{SOLVER_NAME}}PETScData.getType() == vertexdata::{{SOLVER_NAME}}PETScData::Type::Interior) {
155 std::pair<int,int> localIndex = std::make_pair(_spacetreeId, fineGridVertex{{SOLVER_NAME}}PETScData.getUnknownBaseNumber());
156 int globalIndex = repositories::{{SOLVER_INSTANCE}}.getLocalToGlobalMap().getGlobalIndex(localIndex, ::petsc::LocalToGlobalMap::Type::Vertex);
157
158 for (int i=0; i<{{VERTEX_CARDINALITY}}; i++){
159 fineGridVertex{{SOLVER_NAME}}.setValue(
160 i,
161 repositories::{{SOLVER_INSTANCE}}.getLinearEquationSystem().get(globalIndex+i)
162 );
163 }
164 }
165"""
166
167
168 def __init__(self,
169 solver):
170 """!
171
172Initialise vertex-associated degrees of freedom
173
174The initialisation requires a solver object, as we have to know what C++
175object this solver will produce.
176
177solver: petsc.solvers.CollocatedLowOrderDiscretisation or similar solver where
178 degrees of freedom are assigned exclusively to the vertices.
179
180 """
181 super( ProjectPETScSolutionOnVerticesBackOntoMesh, self ).__init__()
182 self.d = {}
183 self.d["SOLVER_INSTANCE"] = solver.instance_name()
184 self.d["SOLVER_NAME"] = solver.typename()
185 self.d["VERTEX_CARDINALITY"] = solver.number_of_matrix_entries_per_vertex
186
187
188
189 def get_body_of_operation(self,operation_name):
190 """!
191
192Provide C++ code snippet for peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME
193
194Only touchVertexFirstTime is an event where this action set actually
195does something: It inserts the template TemplateTouchVertexFirstTime and
196replaces it with entries from the dictionary. The latter is befilled
197in init().
198
199 """
200 result = ""
201 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME:
202 result = jinja2.Template(self.TemplateTouchVertexFirstTime).render(**self.d)
203 pass
204 return result
205
206
208 """!
209
210 Configure name of generated C++ action set
211
212 This action set will end up in the directory observers with a name that
213 reflects how the observer (initialisation) is mapped onto this action
214 set. The name pattern is ObserverName2ActionSetIdentifier where this
215 routine co-determines the ActionSetIdentifier. We make is reflect the
216 Python class name.
217
218 """
219 return __name__.replace(".py", "").replace(".", "_")
220
221
223 """!
224
225 The action set that Peano will generate that corresponds to this class
226 should not be modified by users and can safely be overwritten every time
227 we run the Python toolkit.
228
229 """
230 return False
231
232
233 def get_includes(self):
234 """!
235
236Consult petsc.Project for details
237
238"""
239 return """
240#include "../repositories/SolverRepository.h"
241"""
242
243 def get_attributes(self):
244 """!
245
246
247 """
248 return """
249 int _spacetreeId;
250"""
251
253 """!
254
255Define body of constructor
256
257Consult the superclass' description of the function for results. I
258basically initialise the _localMap with the correct tree number.
259
260@see get_attributes()
261
262 """
263 return """
264 _spacetreeId = treeNumber;
265"""
266
user_should_modify_template(self)
The action set that Peano will generate that corresponds to this class should not be modified by user...
get_body_of_operation(self, operation_name)
Provide C++ code snippet for peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME
get_attributes(self)
Return attributes as copied and pasted into the generated class.
get_body_of_operation(self, operation_name)
Provide C++ code snippet for peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME
user_should_modify_template(self)
The action set that Peano will generate that corresponds to this class should not be modified by user...
Action set (reactions to events)
Definition ActionSet.py:6