Peano
Loading...
Searching...
No Matches
InitPetsc.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
12 use this class to store some indices on each vertex inside touchCellFirstTime!
13
14 """
15
16 templateTouchCellFirstTime="""
17 //lambda to insert a value into first uninitialised position.
18 //these vectors attached to cells will have all their entries
19 //initialised to -1 otherwise
20
21 auto insertValueIntoVertex = [&](const int& vertex, const int& dofIndex){
22 //here we will insert dofIndex into the first empty position in the
23 //vector held by fineGridVertices{{SOLVER_NAME}}(vertex)
24 int indexWithinVector = 2*TwoPowerD; //deliberately set it to be too large
25
26 //we have TwoPowerD entries in this vector
27 for (int i=0; i<TwoPowerD; i++){
28 if ( fineGridVertices{{SOLVER_NAME}}(vertex).getDofIndices(i) == -1 )
29 indexWithinVector = std::min(i, indexWithinVector);
30 }
31 if(indexWithinVector < 0 or indexWithinVector > TwoPowerD)
32 throw std::runtime_error("error in inserting to vector!");
33 fineGridVertices{{SOLVER_NAME}}(vertex).setDofIndices(indexWithinVector,dofIndex);
34 };
35
36 if (not marker.willBeRefined()){
37 //get global index for the index held by this cell
38 std::pair<int,int> localIndex( _spacetreeId, fineGridCell{{SOLVER_NAME}}.getNumber() );
39 int globalIndex = repositories::getGlobalCellIndex( localIndex );
40
41 //vertex 0 takes the globalIndex + 0;
42 //vertex 1 takes the globalIndex + n; etc
43 static_assert(Dimensions==2, "hardcoding 2d for time being");
44
45 //worry about boundary when it comes to assembly time
46 insertValueIntoVertex(0, globalIndex);
47 insertValueIntoVertex(1, globalIndex + {{POLYNOMIAL_DEGREE}});
48 insertValueIntoVertex(2, globalIndex + {{DEGPLUS1POWERD}} - ({{POLYNOMIAL_DEGREE}} + 1));
49 insertValueIntoVertex(3, globalIndex + {{DEGPLUS1POWERD}} - 1);
50
51 }
52
53 """
54
55
56 def __init__(self,
57 solver):
58 """!
59
60
61 """
62 super( SendDofsToVertices, self ).__init__()
63 self.d = {}
64 self.d["SOLVER_INSTANCE"] = solver.instance_name()
65 self.d["SOLVER_NAME"] = solver.typename()
66 self.d["POLYNOMIAL_DEGREE"] = solver.polynomial_degree
67 self.d["DEGPLUS1POWERD"] = (solver.polynomial_degree+1) ** solver.dimensions
68
69 def get_body_of_operation(self,operation_name):
70 """!
71
72 """
73 result = ""
74 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
75 result = jinja2.Template(self.templateTouchCellFirstTime).render(**self.d)
76 pass
77 return result
78
79
81 """!
82
83Configure name of generated C++ action set
84
85This action set will end up in the directory observers with a name that
86reflects how the observer (initialisation) is mapped onto this action
87set. The name pattern is ObserverName2ActionSetIdentifier where this
88routine co-determines the ActionSetIdentifier. We make is reflect the
89Python class name.
90
91 """
92 return __name__.replace(".py", "").replace(".", "_")
93
94
96 """!
97
98 The action set that Peano will generate that corresponds to this class
99 should not be modified by users and can safely be overwritten every time
100 we run the Python toolkit.
101
102 """
103 return False
104
105
106 def get_attributes(self):
107 """!
108
109Define the local map
110
111Every action set has excactly one attribute and that's an instance of
112petsc::LocalToGlobalMap. Before we run through a local mesh partition,
113the corresponding observer object will create a copy of the action set
114for this traversal. In the corresponding constructor, we initialise
115our thread-local copy of the map with the correct tree number.
116
117 """
118 return """
119 int _spacetreeId;
120
121"""
122
124 """!
125
126Define body of constructor
127
128Consult the superclass' description of the function for results. I
129basically initialise the _localMap with the correct tree number.
130
131@see get_attributes()
132
133 """
134 return """
135 _spacetreeId = treeNumber;
136
137"""
138
139
140 def get_includes(self):
141 """!
142
143Consult petsc.Project for details
144
145"""
146 return """
147#include "../repositories/SolverRepository.h"
148"""
use this class to store some indices on each vertex inside touchCellFirstTime!
Definition InitPetsc.py:9
get_action_set_name(self)
Configure name of generated C++ action set.
Definition InitPetsc.py:80
get_attributes(self)
Define the local map.
Definition InitPetsc.py:106
get_constructor_body(self)
Define body of constructor.
Definition InitPetsc.py:123
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
Definition InitPetsc.py:69
get_includes(self)
Consult petsc.Project for details.
Definition InitPetsc.py:140
user_should_modify_template(self)
The action set that Peano will generate that corresponds to this class should not be modified by user...
Definition InitPetsc.py:95
Action set (reactions to events)
Definition ActionSet.py:6