Peano
Loading...
Searching...
No Matches
InitVertexDoFs.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 mesh
13
14This simple action set plugs into the situations where we touch a vertex
15for the first time throughout a mesh traversal. Of these events, it ignores
16all those for refined vertices, i.e. it solely handles the unrefined
17vertices in the spacetree. If focuses on the fine grid. The same is done
18for the cells and the vertices.
19
20The injected code snippet is simple and basically asks if a vertex will be
21refined. If not, it invokes the initialisation routine of the solver. For
22this, the action set has to know the typename and the instance name of the
23solver. Besides the actual behaviour, the action set also has to include
24the solver in the first place. This happens in get_includes().
25
26 """
27 TemplateInitVertex = """
28 if ( fineGridVertex{{SOLVER_NAME}}PETScData.getType() != vertexdata::{{SOLVER_NAME}}PETScData::Type::Coarse ) {
29
30 tarch::la::Vector<{{VERTEX_CARDINALITY}}, double> value;
31 tarch::la::Vector<{{VERTEX_CARDINALITY}}, double> rhs;
32
33 // use initVertex to get all the values we want to place
34 // into each vertex dof
35 repositories::{{SOLVER_INSTANCE}}.initVertex(
36 marker.x(),
37 marker.h(),
38 value,
39 rhs
40 );
41
42 for (int i=0; i<{{VERTEX_CARDINALITY}}; i++)
43 {
44 fineGridVertex{{SOLVER_NAME}}.setValue(i, value[i]);
45 fineGridVertex{{SOLVER_NAME}}.setRhs(i, rhs[i]);
46 }
47 }
48"""
49
50 def __init__(self,
51 solver):
52 """!
53
54Initialise vertex-associated degrees of freedom
55
56The initialisation requires a solver object, as we have to know what C++
57object this solver will produce.
58
59solver: petsc.solvers.CollocatedLowOrderDiscretisation or similar solver where
60 degrees of freedom are assigned exclusively to the vertices.
61
62 """
63 super( InitVertexDoFs, self ).__init__()
64 self.d = {}
65 self.d["SOLVER_INSTANCE"] = solver.instance_name()
66 self.d["SOLVER_NAME"] = solver.typename()
67 self.d["VERTEX_CARDINALITY"] = solver.number_of_matrix_entries_per_vertex
68 self.d["FACE_CARDINALITY"] = solver.number_of_matrix_entries_per_face
69 self.d["CELL_CARDINALITY"] = solver.number_of_matrix_entries_per_cell
70
71
72 def get_body_of_operation(self,operation_name):
73 """!
74
75Provide C++ code snippet for peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME
76
77Only touchVertexFirstTime is an event where this action set actually
78does something: It inserts the template TemplateInitVertex and
79replaces it with entries from the dictionary. The latter is befilled
80in init().
81
82 """
83 result = ""
84 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME:
85 result = jinja2.Template(self.TemplateInitVertex).render(**self.d)
86 pass
87 return result
88
89
91 """!
92
93 Configure name of generated C++ action set
94
95 This action set will end up in the directory observers with a name that
96 reflects how the observer (initialisation) is mapped onto this action
97 set. The name pattern is ObserverName2ActionSetIdentifier where this
98 routine co-determines the ActionSetIdentifier. We make is reflect the
99 Python class name.
100
101 """
102 return __name__.replace(".py", "").replace(".", "_")
103
104
106 """!
107
108 The action set that Peano will generate that corresponds to this class
109 should not be modified by users and can safely be overwritten every time
110 we run the Python toolkit.
111
112 """
113 return False
114
115
116 def get_includes(self):
117 """!
118
119 Add some additional includes
120
121 We need the solver repository here as we access hte solver object, and we
122 also need access to all of Peano's d-dimensional for loops.
123
124 """
125 return """
126#include "../repositories/SolverRepository.h"
127#include "peano4/utils/Loop.h"
128"""
129
Initialise degrees of freedom associated with the mesh.
get_action_set_name(self)
Configure name of generated C++ action set.
get_includes(self)
Add some additional includes.
user_should_modify_template(self)
The action set that Peano will generate that corresponds to this class should not be modified by user...
get_body_of_operation(self, operation_name)
Provide C++ code snippet for peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME
__init__(self, solver)
Initialise vertex-associated degrees of freedom.
Action set (reactions to events)
Definition ActionSet.py:6