Peano
Loading...
Searching...
No Matches
InitCellDoFs.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 cells
13
14 """
15 TemplateInitCell = """
16 if ( fineGridCell{{SOLVER_NAME}}PETScData.getType() == celldata::{{SOLVER_NAME}}PETScData::Type::Interior ) {
17 int dof = 0;
18 dfor( k, {{POLYNOMIAL_DEGREE+1}} ) {
19 {% if CELL_UNKNOWNS>1 %}
20 xxxx
21 {% else %}
22 double value, rhs, exactSol;
23 tarch::la::Vector<Dimensions,double> x = marker.getOffset();
24 for (int d=0; d<Dimensions; d++) {
25 x(d) += repositories::{{SOLVER_INSTANCE}}.QuadraturePointsInUnitInterval[ k(d) ] * marker.h()(d);
26 }
27 repositories::{{SOLVER_INSTANCE}}.initNode(
28 x,
29 marker.h(),
30 value,
31 rhs,
32 exactSol
33 );
34 fineGridCell{{SOLVER_NAME}}.setValue(dof,value);
35 fineGridCell{{SOLVER_NAME}}.setRhs(dof,rhs);
36 fineGridCell{{SOLVER_NAME}}.setExactSol(dof,exactSol);
37 dof++;
38 {% endif %}
39 }
40 }
41"""
42
43 def __init__(self,
44 solver):
45 """!
46
47Initialise vertex-associated degrees of freedom
48
49The initialisation requires a solver object, as we have to know what C++
50object this solver will produce.
51
52solver: petsc.solvers.CollocatedLowOrderDiscretisation or similar solver where
53 degrees of freedom are assigned exclusively to the vertices.
54
55 """
56 super( InitCellDoFs, self ).__init__()
57 self.d = {}
58 self.d["SOLVER_INSTANCE"] = solver.instance_name()
59 self.d["SOLVER_NAME"] = solver.typename()
60 self.d["CELL_UNKNOWNS"] = solver.cell_unknowns
61 self.d["POLYNOMIAL_DEGREE"] = solver.polynomial_degree
62
63
64 def get_body_of_operation(self,operation_name):
65 """!
66
67Provide C++ code snippet for peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME
68
69Only touchVertexFirstTime is an event where this action set actually
70does something: It inserts the template TemplateInitVertex and
71replaces it with entries from the dictionary. The latter is befilled
72in init().
73
74 """
75 result = ""
76 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
77 result = jinja2.Template(self.TemplateInitCell).render(**self.d)
78 pass
79 return result
80
81
83 """!
84
85 Configure name of generated C++ action set
86
87 This action set will end up in the directory observers with a name that
88 reflects how the observer (initialisation) is mapped onto this action
89 set. The name pattern is ObserverName2ActionSetIdentifier where this
90 routine co-determines the ActionSetIdentifier. We make is reflect the
91 Python class name.
92
93 """
94 return __name__.replace(".py", "").replace(".", "_")
95
96
98 """!
99
100 The action set that Peano will generate that corresponds to this class
101 should not be modified by users and can safely be overwritten every time
102 we run the Python toolkit.
103
104 """
105 return False
106
107
108 def get_includes(self):
109 """!
110
111 We need the solver repository in this action set, as we directly access
112 the solver object. We also need access to Peano's d-dimensional loops.
113
114 """
115 return """
116#include "../repositories/SolverRepository.h"
117#include "peano4/utils/Loop.h"
118"""
119
Initialise degrees of freedom associated with cells.
get_includes(self)
We need the solver repository in this action set, as we directly access the solver object.
user_should_modify_template(self)
The action set that Peano will generate that corresponds to this class should not be modified by user...
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)
Provide C++ code snippet for peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME
Action set (reactions to events)
Definition ActionSet.py:6