Peano
Loading...
Searching...
No Matches
InitDofs.py
Go to the documentation of this file.
1"""!
2The action sets in this file are intended for use with new MG solvers.
3
4We have a mix of behaviours to add in - namely determining max refinement
5level during our first descent, as well as standard stuff eg determining
6which facets are boundary / interior etc.
7
8For the CG, we need to determine:
9 - the number of refinement levels available
10 - the level of the finest level
11
12We need to add some bookkeeping to the abstract solver to keep track of
13these, because the solver level matters.
14
15We need to associate an int "level" with each vertex, so we give each Vertex
16this attribute (Level) and set it to -1 initially. Then during
17touchVertexFirstTime, we set the "level" of the fineGridVertex to be one more
18than the level of the coarse vertex
19
20Slight problem is that we don't have the coarse vertex in scope at this stage.
21So we need to maintain this hierarchy for the cells, as well as setting the
22level of the vertices to be one more than the coarse cells.
23"""
24
25
26from peano4.solversteps.ActionSet import ActionSet
27
28import peano4
29import jinja2
30
32 templateTouchCellFirstTime="""
33
34 // set the level...
35 fineGridCell{{SOLVER_NAME}}.setLevel(
36 coarseGridCell{{SOLVER_NAME}}.getLevel() + 1
37 );
38
39 celldata::{{SOLVER_NAME}}::Type dofType = repositories::{{SOLVER_INSTANCE}}.getCellDoFType(marker.x(),marker.h());
40 switch(dofType)
41 {
42 case celldata::{{SOLVER_NAME}}::Type::Outside:
43 {
44 assertion(false);
45 }
46 break;
47
48 case celldata::{{SOLVER_NAME}}::Type::Interior:
49 {
50 fineGridCell{{SOLVER_NAME}}.setType( celldata::{{SOLVER_NAME}}::Type::Interior );
51 repositories::{{SOLVER_INSTANCE}}.updateMinMaxMeshSize( marker.h() );
52 }
53 break;
54 }
55
56 """
57
58 templateTouchVertexFirstTime="""
59
60 // set its level...
61 fineGridVertex{{SOLVER_NAME}}.setLevel(
62 coarseGridCell{{SOLVER_NAME}}.getLevel() + 1
63 );
64
65 tarch::la::Vector<{{VERTEX_CARDINALITY}}, double> zeroes { 0 };
66 fineGridVertex{{SOLVER_NAME}}.setResidual( zeroes );
67 fineGridVertex{{SOLVER_NAME}}.setDelta( zeroes );
68 fineGridVertex{{SOLVER_NAME}}.setOldU( zeroes );
69 fineGridVertex{{SOLVER_NAME}}.setDiag( zeroes );
70
71 vertexdata::{{SOLVER_NAME}}::Type dofType = repositories::{{SOLVER_INSTANCE}}.getVertexDoFType(marker.x(),marker.h());
72
73 switch(dofType)
74 {
75 case vertexdata::{{SOLVER_NAME}}::Type::Boundary:
76 {
77 fineGridVertex{{SOLVER_NAME}}.setType( vertexdata::{{SOLVER_NAME}}::Type::Boundary );
78 if ( !marker.willBeRefined() ) {
79 // we have boundary vertex
80 // init its solution too
81 tarch::la::Vector<{{VERTEX_CARDINALITY}}, double> u;
82 tarch::la::Vector<{{VERTEX_CARDINALITY}}, double> rhs;
83
84 // send these into init
85 repositories::{{SOLVER_INSTANCE}}.initVertex( marker.x(), marker.h(), u, rhs );
86
87 // store
88 fineGridVertex{{SOLVER_NAME}}.setU( u );
89 fineGridVertex{{SOLVER_NAME}}.setRhs( rhs );
90
91 // if we are on the finest level, we need to alert the abstract solver...
92 repositories::{{SOLVER_INSTANCE}}.setActiveLevel( fineGridVertex{{SOLVER_NAME}}.getLevel() );
93 repositories::{{SOLVER_INSTANCE}}.setFinestLevel( fineGridVertex{{SOLVER_NAME}}.getLevel() );
94 }
95 }
96 break;
97
98 case vertexdata::{{SOLVER_NAME}}::Type::Interior:
99 {
100 fineGridVertex{{SOLVER_NAME}}.setType( vertexdata::{{SOLVER_NAME}}::Type::Interior );
101
102 if ( !marker.willBeRefined() ){
103 // init its solution since we are on the finest level
104 tarch::la::Vector<{{VERTEX_CARDINALITY}}, double> u;
105 tarch::la::Vector<{{VERTEX_CARDINALITY}}, double> rhs;
106
107 // send these into init
108 repositories::{{SOLVER_INSTANCE}}.initVertex( marker.x(), marker.h(), u, rhs );
109
110 // store
111 fineGridVertex{{SOLVER_NAME}}.setU( u );
112 fineGridVertex{{SOLVER_NAME}}.setRhs( rhs );
113
114 // if we are on the finest level, we need to alert the abstract solver...
115 repositories::{{SOLVER_INSTANCE}}.setActiveLevel( fineGridVertex{{SOLVER_NAME}}.getLevel() );
116 repositories::{{SOLVER_INSTANCE}}.setFinestLevel( fineGridVertex{{SOLVER_NAME}}.getLevel() );
117 }
118 }
119 break;
120
121 case vertexdata::{{SOLVER_NAME}}::Type::Coarse:
122 assertionMsg(false, "should not be returned by user" );
123 break;
124
125 case vertexdata::{{SOLVER_NAME}}::Type::Undefined:
126 assertionMsg(false, "should not be returned by user" );
127 break;
128 }
129
130
131 """
132 def __init__(self,
133 solver):
134 super( InitDofsCollocatedMG, self ).__init__()
135 self.d = {}
136 self.d["SOLVER_INSTANCE"] = solver.instance_name()
137 self.d["SOLVER_NAME"] = solver.typename()
138 self.d["VERTEX_CARDINALITY"] = solver._unknowns_per_vertex_node
139
140 def get_body_of_operation(self,operation_name):
141 result = ""
142 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME:
143 result = jinja2.Template(self.templateTouchVertexFirstTime).render(**self.d)
144 pass
145 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
146 result = jinja2.Template(self.templateTouchCellFirstTime).render(**self.d)
147 pass
148 return result
149
151 """!
152
153 Configure name of generated C++ action set
154
155 This action set will end up in the directory observers with a name that
156 reflects how the observer (initialisation) is mapped onto this action
157 set. The name pattern is ObserverName2ActionSetIdentifier where this
158 routine co-determines the ActionSetIdentifier. We make is reflect the
159 Python class name.
160
161 """
162 return __name__.replace(".py", "").replace(".", "_")
163
165 """!
166
167 The action set that Peano will generate that corresponds to this class
168 should not be modified by users and can safely be overwritten every time
169 we run the Python toolkit.
170
171 """
172 return False
173
174 def get_includes(self):
175 """!
176
177 We need the solver repository in this action set, as we directly access
178 the solver object. We also need access to Peano's d-dimensional loops.
179
180 """
181 return """
182#include "repositories/SolverRepository.h"
183#include "peano4/utils/Loop.h"
184"""
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
Definition InitDofs.py:140
get_includes(self)
We need the solver repository in this action set, as we directly access the solver object.
Definition InitDofs.py:174
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:164
get_action_set_name(self)
Configure name of generated C++ action set.
Definition InitDofs.py:150
Action set (reactions to events)
Definition ActionSet.py:6