Peano
Loading...
Searching...
No Matches
InitDofs.py
Go to the documentation of this file.
1from peano4.solversteps.ActionSet import ActionSet
2
3import peano4
4import jinja2
5
6
8 """!
9 Redoing this class for discontinuous galerkin solver.
10
11 This time, we store values only in the cells and just
12 determine the type of vertex we see.
13 """
14 templateTouchVertexFirstTime = """
15
16 //logTraceInWith3Arguments("InitDofsDG::touchVertexFirstTime", marker.toString(), isOnBoundary(marker.x()), fineGridVertex{{SOLVER_NAME}}.toString());
17
18 vertexdata::{{SOLVER_NAME}}::Type dofType = repositories::{{SOLVER_INSTANCE}}.getVertexDoFType(marker.x(),marker.h());
19
20 switch(dofType)
21 {
22
23 case vertexdata::{{SOLVER_NAME}}::Type::Interior:
24 {
25 if ( marker.willBeRefined() )
26 {
27 fineGridVertex{{SOLVER_NAME}}.setType( vertexdata::{{SOLVER_NAME}}::Type::Coarse );
28 }
29
30 else
31 {
32 fineGridVertex{{SOLVER_NAME}}.setType( vertexdata::{{SOLVER_NAME}}::Type::Interior );
33 }
34 }
35 break;
36
37 case vertexdata::{{SOLVER_NAME}}::Type::Coarse:
38 assertionMsg(false, "should not be returned by user" );
39 break;
40
41 case vertexdata::{{SOLVER_NAME}}::Type::Undefined:
42 assertionMsg(false, "should not be returned by user" );
43 break;
44 }
45
46
47 //logTraceOutWith2Arguments("InitDofsDG::touchVertexFirstTime", marker.toString(), fineGridVertex{{SOLVER_NAME}}.toString());
48 """
49
50 templateTouchCellFirstTime = """
51 logTraceInWith2Arguments("InitDofs::touchCellFirstTime", marker.toString(), fineGridCell{{SOLVER_NAME}}.toString());
52
53 celldata::{{SOLVER_NAME}}::Type dofType = repositories::{{SOLVER_INSTANCE}}.getCellDoFType(marker.x(),marker.h());
54
55 switch(dofType)
56 {
57 case celldata::{{SOLVER_NAME}}::Type::Outside:
58 {
59 if ( marker.willBeRefined() ) // make it coarse
60 {
61 fineGridCell{{SOLVER_NAME}}.setType( celldata::{{SOLVER_NAME}}::Type::Coarse );
62 }
63 else
64 {
65 fineGridCell{{SOLVER_NAME}}.setType( celldata::{{SOLVER_NAME}}::Type::Outside );
66 }
67 }
68 break;
69
70 case celldata::{{SOLVER_NAME}}::Type::Interior:
71 {
72 if ( marker.willBeRefined() )
73 {
74 fineGridCell{{SOLVER_NAME}}.setType( celldata::{{SOLVER_NAME}}::Type::Coarse );
75 }
76 else
77 {
78 fineGridCell{{SOLVER_NAME}}.setType( celldata::{{SOLVER_NAME}}::Type::Interior );
79
80 // create vectors to send to implementation
81 tarch::la::Vector< repositories::{{SOLVER_INSTANCE}}.CellUnknowns, double > value;
82 tarch::la::Vector< repositories::{{SOLVER_INSTANCE}}.CellUnknowns, double > rhs;
83 // send to init
84 repositories::{{SOLVER_INSTANCE}}.initCell(marker.x(), marker.h(), value, rhs);
85
86 logTraceInWith5Arguments("touchCellFirstTime::Interior", fineGridCell{{SOLVER_NAME}}.getSolution(), fineGridCell{{SOLVER_NAME}}.getRhs(), marker.toString(), value, rhs);
87
88 // adding junk data to the solution and rhs for development purposes
89 for (int i=0; i<repositories::{{SOLVER_INSTANCE}}.CellUnknowns; i++)
90 {
91 fineGridCell{{SOLVER_NAME}}.setSolution(i,value(i));
92 fineGridCell{{SOLVER_NAME}}.setRhs(i,rhs(i));
93 }
94
95 logTraceOutWith2Arguments("touchCellFirstTime::Interior", fineGridCell{{SOLVER_NAME}}.getSolution(), fineGridCell{{SOLVER_NAME}}.getRhs());
96 }
97 }
98 break;
99
100 }
101
102 logTraceOutWith2Arguments("InitDofs::touchCellFirstTime", marker.toString(), fineGridCell{{SOLVER_NAME}}.toString());
103 """
104
105 templatetouchFaceFirstTime = """
106 logTraceInWith2Arguments("InitDofs::touchFaceFirstTime", marker.toString(), fineGridFace{{SOLVER_NAME}}.toString());
107
108 facedata::{{SOLVER_NAME}}::Type dofType = repositories::{{SOLVER_INSTANCE}}.getFaceDoFType(marker.x(),marker.h());
109
110 switch(dofType)
111 {
112 case facedata::{{SOLVER_NAME}}::Type::Outside:
113 {
114 if ( marker.willBeRefined() ) // make it coarse
115 {
116 fineGridFace{{SOLVER_NAME}}.setType( facedata::{{SOLVER_NAME}}::Type::Coarse );
117 }
118 else
119 {
120 fineGridFace{{SOLVER_NAME}}.setType( facedata::{{SOLVER_NAME}}::Type::Outside );
121 }
122 } break;
123
124 case facedata::{{SOLVER_NAME}}::Type::Interior:
125 {
126 if ( marker.willBeRefined() )
127 {
128 fineGridFace{{SOLVER_NAME}}.setType( facedata::{{SOLVER_NAME}}::Type::Coarse );
129 }
130 else
131 {
132 fineGridFace{{SOLVER_NAME}}.setType( facedata::{{SOLVER_NAME}}::Type::Interior );
133
134 // vectors to be passed into face
135 tarch::la::Vector< repositories::{{SOLVER_INSTANCE}}.FaceUnknownsSolution, double > sol;
136 tarch::la::Vector< repositories::{{SOLVER_INSTANCE}}.FaceUnknownsProjection, double > projection;
137
138 // send to init
139 repositories::{{SOLVER_INSTANCE}}.initFace(marker.x(), marker.h(), sol, projection);
140
141 // put into mesh
142 fineGridFace{{SOLVER_NAME}}.setSolution(sol);
143 fineGridFace{{SOLVER_NAME}}.setProjection(projection);
144
145 }
146 } break;
147
148 case facedata::{{SOLVER_NAME}}::Type::Boundary:
149 {
150 if ( marker.willBeRefined() )
151 {
152 fineGridFace{{SOLVER_NAME}}.setType( facedata::{{SOLVER_NAME}}::Type::Coarse );
153 }
154 else
155 {
156 fineGridFace{{SOLVER_NAME}}.setType( facedata::{{SOLVER_NAME}}::Type::Boundary );
157
158 // vectors to be passed into face
159 tarch::la::Vector< repositories::{{SOLVER_INSTANCE}}.FaceUnknownsSolution, double > sol;
160 tarch::la::Vector< repositories::{{SOLVER_INSTANCE}}.FaceUnknownsProjection, double > projection;
161
162 // send to init
163 repositories::{{SOLVER_INSTANCE}}.initFace(marker.x(), marker.h(), sol, projection);
164
165 // put into mesh
166 fineGridFace{{SOLVER_NAME}}.setSolution(sol);
167 fineGridFace{{SOLVER_NAME}}.setProjection(projection);
168 }
169 } break;
170
171
172 }
173
174 logTraceOutWith2Arguments("InitDofs::touchFaceFirstTime", marker.toString(), fineGridFace{{SOLVER_NAME}}.toString());
175 """
176
177 def __init__(self,
178 solver):
179 super( InitDofsDG, self ).__init__()
180 self.d = {}
181 self.d["SOLVER_INSTANCE"] = solver.instance_name()
182 self.d["SOLVER_NAME"] = solver.typename()
183 # self.d["VERTEX_CARDINALITY"] = solver._unknowns_per_vertex
184
185 def get_body_of_operation(self,operation_name):
186 result = ""
187 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME:
188 result = jinja2.Template(self.templateTouchVertexFirstTime).render(**self.d)
189 pass
190 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
191 result = jinja2.Template(self.templateTouchCellFirstTime).render(**self.d)
192 pass
193 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME:
194 result = jinja2.Template(self.templatetouchFaceFirstTime).render(**self.d)
195 pass
196 return result
197
199 """!
200
201 Configure name of generated C++ action set
202
203 This action set will end up in the directory observers with a name that
204 reflects how the observer (initialisation) is mapped onto this action
205 set. The name pattern is ObserverName2ActionSetIdentifier where this
206 routine co-determines the ActionSetIdentifier. We make is reflect the
207 Python class name.
208
209 """
210 return __name__.replace(".py", "").replace(".", "_")
211
213 """!
214
215 The action set that Peano will generate that corresponds to this class
216 should not be modified by users and can safely be overwritten every time
217 we run the Python toolkit.
218
219 """
220 return False
221
222 def get_includes(self):
223 """!
224
225 We need the solver repository in this action set, as we directly access
226 the solver object. We also need access to Peano's d-dimensional loops.
227
228 """
229 return """
230#include "../repositories/SolverRepository.h"
231#include "peano4/utils/Loop.h"
232"""
233
Redoing this class for discontinuous galerkin solver.
Definition InitDofs.py:7
str templateTouchCellFirstTime
Definition InitDofs.py:50
__init__(self, solver)
Definition InitDofs.py:178
str templatetouchFaceFirstTime
Definition InitDofs.py:105
str templateTouchVertexFirstTime
Definition InitDofs.py:14
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
Definition InitDofs.py:185
get_includes(self)
We need the solver repository in this action set, as we directly access the solver object.
Definition InitDofs.py:222
user_should_modify_template(self)
The action set that Peano will generate that corresponds to this class should not be modified by user...
Definition InitDofs.py:212
get_action_set_name(self)
Configure name of generated C++ action set.
Definition InitDofs.py:198
Action set (reactions to events)
Definition ActionSet.py:6