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