Peano
Loading...
Searching...
No Matches
InitFaceDoFs.py
Go to the documentation of this file.
1# This file is part of the Peano's PETSc extension. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from peano4.solversteps.ActionSet import ActionSet
4
5import peano4
6import jinja2
7
8
10 """!
11
12Initialise degrees of freedom associated with the cells and Faces.
13
14Much the same as the old code to init DoFs on vertices, except here
15we also make the call to the localtoglobalmap. ie we both init the
16degrees of freedom and the global mapping for indices on faces and cells
17
18 """
19
20 TemplateInitFace="""
21 @todo This is a left-over. Not yet maintained
22
23
24 // lambda to determine the pair of vertices that determine
25 // whether face i is on the boundary or not
26 // eg if vertices 0 and 1 are both dirichlet, then face 1 must
27 // be on the boundary
28 auto getCrucialIndices = [](int i) -> const std::pair<int,int>{
29 static constexpr std::pair<int,int> v0 = {0,2};
30 static constexpr std::pair<int,int> v1 = {0,1};
31 static constexpr std::pair<int,int> v2 = {1,3};
32 static constexpr std::pair<int,int> v3 = {2,3};
33 if (i==0) return v0;
34 else if (i==1) return v1;
35 else if (i==2) return v2;
36 else if (i==3) return v3;
37 else throw std::runtime_error("invalid index passed!");
38 };
39
40 if (!marker.willBeRefined()){
41 logTraceIn( "touchFaceFirstTime(...)---InitialCondition" );
42
43 int faceNumber = marker.getSelectedFaceNumber();
44 std::pair<int,int> crucialIndices = getCrucialIndices(faceNumber);
45 if(
46 fineGridVertices{{SOLVER_NAME}}(crucialIndices.first).getType() == vertexdata::{{SOLVER_NAME}}::Type::Dirichlet
47 and
48 fineGridVertices{{SOLVER_NAME}}(crucialIndices.second).getType() == vertexdata::{{SOLVER_NAME}}::Type::Dirichlet
49 ){
50 fineGridFace{{SOLVER_NAME}}.setType(facedata::{{SOLVER_NAME}}::Type::Boundary);
51 }
52 else{
53 fineGridFace{{SOLVER_NAME}}.setType(facedata::{{SOLVER_NAME}}::Type::Interior);
54 }
55
56 //init vectors for value and rhs. modify them in initFace()
57 tarch::la::Vector<{{FACE_CARDINALITY}}, double> value;
58 tarch::la::Vector<{{FACE_CARDINALITY}}, double> rhs;
59
60 repositories::{{SOLVER_INSTANCE}}.initFace(
61 marker.x(),
62 marker.h(),
63 value,
64 rhs
65 );
66
67 //place these values into the mesh
68 fineGridFace{{SOLVER_NAME}}.setValue( value );
69 fineGridFace{{SOLVER_NAME}}.setRhs( rhs );
70
71 logTraceOut( "touchFaceFirstTime(...)---InitialCondition" );
72
73 }
74 """
75
76
77 def __init__(self,
78 solver):
79 """!
80
81Initialise vertex-associated degrees of freedom
82
83The initialisation requires a solver object, as we have to know what C++
84object this solver will produce.
85
86solver: petsc.solvers.CollocatedLowOrderDiscretisation or similar solver where
87 degrees of freedom are assigned exclusively to the vertices.
88
89 """
90 super( InitFaceAndCellDoFs, self ).__init__()
91 self.d = {}
92 self.d["SOLVER_INSTANCE"] = solver.instance_name()
93 self.d["SOLVER_NAME"] = solver.typename()
94# self.d["FACE_CARDINALITY"] = solver.number_of_face_unknowns
95# self.d["FACE_DOFS"] = solver.number_of_face_dofs
96# self.d["CELL_CARDINALITY"] = solver.number_of_cell_unknowns
97# self.d["CELL_DOFS"] = solver.number_of_cell_dofs
98
99 def get_body_of_operation(self,operation_name):
100 """!
101
102
103 """
104 result = ""
105 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_FACE_FIRST_TIME:
106 result = jinja2.Template(self.TemplateInitFace).render(**self.d)
107 pass
108
109 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
110 result = jinja2.Template(self.TemplateInitCell).render(**self.d)
111 pass
112
113 return result
114
115
117 """!
118
119 Configure name of generated C++ action set
120
121 This action set will end up in the directory observers with a name that
122 reflects how the observer (initialisation) is mapped onto this action
123 set. The name pattern is ObserverName2ActionSetIdentifier where this
124 routine co-determines the ActionSetIdentifier. We make is reflect the
125 Python class name.
126
127 """
128 return __name__.replace(".py", "").replace(".", "_")
129
130
132 """!
133
134 The action set that Peano will generate that corresponds to this class
135 should not be modified by users and can safely be overwritten every time
136 we run the Python toolkit.
137
138 """
139 return False
140
141 def get_attributes(self):
142 """!
143 """
144 return """
145"""
146
148 return """
149"""
150
151 def get_includes(self):
152 """!
153
154Consult petsc.Project for details
155
156"""
157 return """
158#include "../repositories/SolverRepository.h"
159"""
Initialise degrees of freedom associated with the cells and Faces.
get_includes(self)
Consult petsc.Project for details.
get_action_set_name(self)
Configure name of generated C++ action set.
__init__(self, solver)
Initialise vertex-associated degrees of freedom.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_constructor_body(self)
Define a tailored constructor body.
get_attributes(self)
Return attributes as copied and pasted into the generated class.
user_should_modify_template(self)
The action set that Peano will generate that corresponds to this class should not be modified by user...
Action set (reactions to events)
Definition ActionSet.py:6