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
7 """!
8 In touchVertexFirstTime, we set the type of vertex we see (either Interior, Boundary or Coarse),
9 as well as sending some values to the solver implementation file to be placed into the mesh.
10
11 In touchCellFirstTime, we just determine the type, as we don't store anything on cells in
12 this solver.
13 """
14
15 templateTouchVertexFirstTime = """
16 // this is done inside getDofType. included here for sanity check
17 auto isOnBoundary = [&]( const tarch::la::Vector< Dimensions, double > & x ) -> bool{
18 bool isOnBoundary = false;
19 for (int d=0; d<Dimensions; d++) {
20 isOnBoundary |= tarch::la::smallerEquals( x(d), DomainOffset(d) );
21 isOnBoundary |= tarch::la::greaterEquals( x(d), DomainOffset(d)+DomainSize(d) );
22 }
23 return isOnBoundary;
24 };
25
26 // update min/max mesh size
27 repositories::{{SOLVER_INSTANCE}}.updateMinMaxMeshSize( marker.h() );
28
29 logTraceInWith3Arguments("InitDofs::touchVertexFirstTime", marker.toString(), isOnBoundary(marker.x()), fineGridVertex{{SOLVER_NAME}}.toString());
30
31 vertexdata::{{SOLVER_NAME}}::Type dofType = repositories::{{SOLVER_INSTANCE}}.getVertexType(marker.x(),marker.h());
32
33 switch(dofType)
34 {
35 case vertexdata::{{SOLVER_NAME}}::Type::Boundary:
36 {
37 if ( marker.willBeRefined() )
38 {
39 // Coarse grid vertex. Mark it as such for later
40 fineGridVertex{{SOLVER_NAME}}.setType( vertexdata::{{SOLVER_NAME}}::Type::Coarse );
41 }
42 else
43 {
44 // we have boundary vertex
45 fineGridVertex{{SOLVER_NAME}}.setType( vertexdata::{{SOLVER_NAME}}::Type::Boundary );
46 // init its value too
47 tarch::la::Vector<{{VERTEX_CARDINALITY}}, double> value;
48 tarch::la::Vector<{{VERTEX_CARDINALITY}}, double> rhs;
49
50 // send these into init
51 repositories::{{SOLVER_INSTANCE}}.initVertex( marker.x(), marker.h(), value, rhs );
52
53 // store
54 for (int dof=0; dof<{{VERTEX_CARDINALITY}}; dof++)
55 {
56 fineGridVertex{{SOLVER_NAME}}.setU( dof, value(dof));
57 fineGridVertex{{SOLVER_NAME}}.setRhs( dof, rhs(dof));
58 }
59
60 }
61 }
62 break;
63
64 case vertexdata::{{SOLVER_NAME}}::Type::Interior:
65 {
66 if (isOnBoundary(marker.x()))
67 {
68 logWarning( "touchVertexFirstTime(...)", "vertex at " << marker.toString() << " labelled as interior even though it is located at global domain boundary" );
69 }
70
71 if ( marker.willBeRefined() )
72 {
73 fineGridVertex{{SOLVER_NAME}}.setType( vertexdata::{{SOLVER_NAME}}::Type::Coarse );
74 }
75
76 else
77 {
78 fineGridVertex{{SOLVER_NAME}}.setType( vertexdata::{{SOLVER_NAME}}::Type::Interior );
79
80 // init its value too
81 tarch::la::Vector<{{VERTEX_CARDINALITY}}, double> value;
82 tarch::la::Vector<{{VERTEX_CARDINALITY}}, double> rhs;
83
84 // send these into init
85 repositories::{{SOLVER_INSTANCE}}.initVertex( marker.x(), marker.h(), value, rhs );
86
87 // store
88 for (int dof=0; dof<{{VERTEX_CARDINALITY}}; dof++)
89 {
90 fineGridVertex{{SOLVER_NAME}}.setU( dof, value(dof));
91 fineGridVertex{{SOLVER_NAME}}.setRhs( dof, rhs(dof));
92 }
93 }
94 }
95 break;
96
97 case vertexdata::{{SOLVER_NAME}}::Type::Coarse:
98 assertionMsg(false, "should not be returned by user" );
99 break;
100
101 case vertexdata::{{SOLVER_NAME}}::Type::Undefined:
102 assertionMsg(false, "should not be returned by user" );
103 break;
104 }
105
106
107 logTraceOutWith3Arguments("InitDofs::touchVertexFirstTime", marker.toString(), isOnBoundary(marker.x()), fineGridVertex{{SOLVER_NAME}}.toString());
108 """
109
110 templateTouchCellFirstTime = """
111 logTraceInWith2Arguments("InitDofs::touchCellFirstTime", marker.toString(), fineGridCell{{SOLVER_NAME}}.toString());
112
113 celldata::{{SOLVER_NAME}}::Type dofType = repositories::{{SOLVER_INSTANCE}}.getCellType(marker.x(),marker.h());
114
115 switch(dofType)
116 {
117 case celldata::{{SOLVER_NAME}}::Type::Outside:
118 {
119 if ( marker.willBeRefined() ) // make it coarse
120 {
121 fineGridCell{{SOLVER_NAME}}.setType( celldata::{{SOLVER_NAME}}::Type::Coarse );
122 }
123 else
124 {
125 fineGridCell{{SOLVER_NAME}}.setType( celldata::{{SOLVER_NAME}}::Type::Outside );
126 }
127 }
128 break;
129
130 case celldata::{{SOLVER_NAME}}::Type::Interior:
131 {
132 if ( marker.willBeRefined() )
133 {
134 fineGridCell{{SOLVER_NAME}}.setType( celldata::{{SOLVER_NAME}}::Type::Coarse );
135 }
136 else
137 {
138 fineGridCell{{SOLVER_NAME}}.setType( celldata::{{SOLVER_NAME}}::Type::Interior );
139 }
140 }
141 break;
142
143 }
144
145 logTraceOutWith2Arguments("InitDofs::touchCellFirstTime", marker.toString(), fineGridCell{{SOLVER_NAME}}.toString());
146 """
147
148 def __init__(self,
149 solver):
150 super( InitDofsCollocated, self ).__init__()
151 self.d = {}
152 self.d["SOLVER_INSTANCE"] = solver.instance_name()
153 self.d["SOLVER_NAME"] = solver.typename()
154 self.d["VERTEX_CARDINALITY"] = solver._unknowns_per_vertex_node
155
156 def get_body_of_operation(self,operation_name):
157 result = ""
158 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME:
159 result = jinja2.Template(self.templateTouchVertexFirstTime).render(**self.d)
160 pass
161 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
162 result = jinja2.Template(self.templateTouchCellFirstTime).render(**self.d)
163 pass
164 return result
165
167 """!
168
169 Configure name of generated C++ action set
170
171 This action set will end up in the directory observers with a name that
172 reflects how the observer (initialisation) is mapped onto this action
173 set. The name pattern is ObserverName2ActionSetIdentifier where this
174 routine co-determines the ActionSetIdentifier. We make is reflect the
175 Python class name.
176
177 """
178 return __name__.replace(".py", "").replace(".", "_")
179
181 """!
182
183 The action set that Peano will generate that corresponds to this class
184 should not be modified by users and can safely be overwritten every time
185 we run the Python toolkit.
186
187 """
188 return False
189
190 def get_includes(self):
191 """!
192
193 We need the solver repository in this action set, as we directly access
194 the solver object. We also need access to Peano's d-dimensional loops.
195
196 """
197 return """
198#include "../repositories/SolverRepository.h"
199#include "peano4/utils/Loop.h"
200"""
Action set (reactions to events)
Definition ActionSet.py:6
In touchVertexFirstTime, we set the type of vertex we see (either Interior, Boundary or Coarse),...
Definition InitDofs.py:6
get_action_set_name(self)
Configure name of generated C++ action set.
Definition InitDofs.py:166
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
Definition InitDofs.py:156
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:180
get_includes(self)
We need the solver repository in this action set, as we directly access the solver object.
Definition InitDofs.py:190