Peano
Loading...
Searching...
No Matches
ImposeDirichletBoundaryConditions.py
Go to the documentation of this file.
1# This file is part of the Peano multigrid project. For conditions of
2# distribution and use, please see the copyright notice at www.peano-framework.org
3from peano4.solversteps.ActionSet import ActionSet
4
5import peano4
6import jinja2
7
8
9
11 """!
12
13 @todo This version is not yet implemented, and maybe we don't need it ever!
14
15
16 Add those contributions to matrix which impose the boundary conditions
17
18 Dirichlet (and really all boundary) faces do not hold any artificial or real
19 degrees of freedom in our code. So the core assembly ignores these faces and
20 we end up with a linear equation system which is not coupled to the PDE's
21 boundary conditions. This additional action sets runs over the mesh and adds
22 the missing coupling.
23
24 For every cell that we visit (and that is not outside the computational
25 domain), we check its 2d faces, i.e. the left and right face along each
26 axis. If this face is an interior, nothing is to be done. We only have to do
27 something for boundary faces. In this action set, we assume that each face
28 is a Dirichlet face.
29
30 If a face is a Dirichlet face, we loop over the nodes on the face. For
31 this, we emply Peano's exclusive d-dimensional for (dfore), which is a
32 d-dimensional for loop skipping one dimension. Per dof, we compute the
33 dof's coordinate x and ask the user's solver what the value there should be.
34 This gives us the right-hand side for the equation system row that
35 imposes the condition.
36
37 Next, we use compute the projection of the solution to the boundary. This
38 might be a different projection than used for the faces, even though the
39 code is basically the same. For some solvers, we project solely the
40 derivatives along the normal onto the face, for others, we
41
42
43 @todo We need the projection matrix for the solution!
44 @todo We have to add the corresponding matrix entries below, as well as
45 the right-hand side
46
47 """
48 TemplateTouchCellFirstTime = """
49 if (fineGridCell{{SOLVER_NAME}}PETScData.getType() == celldata::{{SOLVER_NAME}}PETScData::Type::Interior) {
50 std::pair<int,int> localCellIndex = std::make_pair(_spacetreeId, fineGridCell{{SOLVER_NAME}}PETScData.getUnknownBaseNumber());
51 int globalCellIndex = repositories::{{SOLVER_INSTANCE}}.getLocalToGlobalMap().getGlobalIndex(localCellIndex, ::petsc::LocalToGlobalMap::Type::Cell);
52
53 assertion( globalCellIndex>=0 );
54
55 for (int d=0; d<Dimensions; d++) {
56 // =================================
57 // Look at left face along axis d
58 // =================================
59 if ( fineGridFaces{{SOLVER_NAME}}PETScData(d).getType()==facedata::{{SOLVER_NAME}}PETScData::Type::Boundary ) {
60 assertion( repositories::{{SOLVER_INSTANCE}}.CellUnknowns==1 );
61
62 int row = 0;
63
64 // Loop over all projections of the solution onto the face. See docu on
65 // dfore in Peano's utilities
66 dfore(faceNode, repositories::{{SOLVER_INSTANCE}}.Order+1, d, 0) {
67 tarch::la::Vector<Dimensions,double> x = marker.getOffset(); // left bottom vertex of cell
68 for (int dd=0; dd<Dimensions; dd++) {
69 if (dd!=d) {
70 x(dd) += repositories::{{SOLVER_INSTANCE}}.QuadraturePointsInUnitInterval[ faceNode(dd) ] * marker.h()(dd);
71 }
72 }
73
74 // Look up the value: rhs is not relevant here, but I want to reuse the existing signatures
75 double value, rhs, exact;
76 repositories::{{SOLVER_INSTANCE}}.initNode(
77 x,
78 marker.h(),
79 value,
80 rhs,
81 exact
82 );
83
84 // @todo We have to discuss this
85 int rhsRow = 0;
86 repositories::{{SOLVER_INSTANCE}}.getLinearEquationSystem().insert( rhsRow, value );
87 for (int col=0; col<repositories::{{SOLVER_INSTANCE}}.DoFsPerCell; col++) {
88 //repositories::{{SOLVER_INSTANCE}}.getLinearEquationSystem().insert(
89 // rhsRow,
90 // globalCellIndex+col,
91 // projectionCellToFaceMatrix(d * dofsPerFace + row,col)
92 //);
93 }
94
95 row++;
96 }
97 }
98
99 // =================================
100 // Look at right face along axis d
101 // =================================
102 if ( fineGridFaces{{SOLVER_NAME}}PETScData(d+Dimensions).getType()==facedata::{{SOLVER_NAME}}PETScData::Type::Boundary ) {
103 // @todo Later
104 }
105 }
106 }
107 """
108
109 def __init__(self,
110 solver,
111 ):
112 """!
113
114 Yet to be written
115
116 """
117
118 super( ImposeDirichletBoundaryConditions, self ).__init__()
119 self.d = {}
120 self.d["SOLVER_INSTANCE"] = solver.instance_name()
121 self.d["SOLVER_NAME"] = solver.typename()
122
123
124 def get_body_of_operation(self,operation_name):
125 """!
126
127Provide C++ code snippet for peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME
128Provide C++ code snippet for peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
129
130Only touchVertexFirstTime is an event where this action set actually
131does something: It inserts the template TemplateTouchVertexFirstTime and
132replaces it with entries from the dictionary. The latter is befilled
133in init().
134
135We actually do something during touchVertexFirstTime and touchCellFirstTime. We insert the
136appropriate template into each.
137
138 """
139 result = ""
140 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
141 result = jinja2.Template(self.TemplateTouchCellFirstTime).render(**self.d)
142 pass
143 return result
144
145
147 """!
148
149 Configure name of generated C++ action set
150
151 This action set will end up in the directory observers with a name that
152 reflects how the observer (initialisation) is mapped onto this action
153 set. The name pattern is ObserverName2ActionSetIdentifier where this
154 routine co-determines the ActionSetIdentifier. We make is reflect the
155 Python class name.
156
157 """
158 return __name__.replace(".py", "").replace(".", "_")
159
160
162 """!
163
164 The action set that Peano will generate that corresponds to this class
165 should not be modified by users and can safely be overwritten every time
166 we run the Python toolkit.
167
168 """
169 return False
170
171
172 def get_includes(self):
173 """!
174
175Consult petsc.Project for details
176
177"""
178 return """
179#include "../repositories/SolverRepository.h"
180#include "tarch/la/Matrix.h"
181#include "peano4/utils/Loop.h"
182"""
183
184 def get_attributes(self):
185 """!
186
187
188 """
189 return f"""
190 int _spacetreeId;
191"""
192
194 """!
195
196Define body of constructor
197
198@see get_attributes()
199
200 """
201 return f"""
202 _spacetreeId = treeNumber;
203"""
user_should_modify_template(self)
The action set that Peano will generate that corresponds to this class should not be modified by user...
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 Provide...
Action set (reactions to events)
Definition ActionSet.py:6