Peano
Loading...
Searching...
No Matches
ProjectOntoFaces.py
Go to the documentation of this file.
1from peano4.solversteps.ActionSet import ActionSet
2
3import peano4
4import jinja2
5
6
8 """!
9
10 This is for DG solver
11
12 @todo There's documentation missing
13
14 """
15
16 templateTouchCellFirstTime="""
17 /*
18 all we need to do here is project updated solution u^c onto the faces
19 */
20
21 if (
22 fineGridCell{{SOLVER_NAME}}.getType() != celldata::{{SOLVER_NAME}}::Type::Coarse
23 and
24 repositories::{{SOLVER_INSTANCE}}.projectOntoFaces()
25 ) {
26 // apply cell to face projection, store it in faceProjections
27 // no tricky indexing needed here, since the whole of the cell
28 // solution vector is in scope here.
29 tarch::la::Vector< repositories::{{SOLVER_INSTANCE}}.FaceUnknownsProjection * TwoTimesD, double > faceProjections =
30 repositories::{{SOLVER_INSTANCE}}. getFaceFromCellMatrix(marker.x(), marker.h()) * fineGridCell{{SOLVER_NAME}}.getSolution();
31
32 logTraceInWith3Arguments("ProjectOntoFace", marker.toString(), faceProjections, fineGridCell{{SOLVER_NAME}}.getSolution());
33
34 // write these values into the faces themselves
35 for (int f=0; f<TwoTimesD; f++)
36 {
37 logTraceInWith2Arguments("ProjectOntoFaces::FaceLoop", f, fineGridFaces{{SOLVER_NAME}}(f).getProjection())
38 /*
39 This loop is crucial - we have a lot of redundant zeros and we don't wanna overwrite eg negative
40 projections when we are dealing with face 0. So, some tricky indexing needed
41 */
42 // skip halfway along the projection vector if we are on face 0 or 1
43 int startIndexProjection =
44 f < Dimensions ?
45 repositories::{{SOLVER_INSTANCE}}.NodesPerFace * repositories::{{SOLVER_INSTANCE}}.ProjectionsPerFaceNode :
46 0;
47
48 // previously, this loop would go up to total number of projections.
49 // but we only want half this number, since we skip the projections
50 // that should be written to by the other face
51 for (int p=0; p<repositories::{{SOLVER_INSTANCE}}.NodesPerFace * repositories::{{SOLVER_INSTANCE}}.ProjectionsPerFaceNode; p++)
52 {
53 fineGridFaces{{SOLVER_NAME}}(f).setProjection(
54 p + startIndexProjection,
55 faceProjections( f*repositories::{{SOLVER_INSTANCE}}.FaceUnknownsProjection + p + startIndexProjection )
56 );
57 }
58 logTraceOutWith2Arguments("ProjectOntoFaces::FaceLoop", f, fineGridFaces{{SOLVER_NAME}}(f).getProjection())
59
60 }
61
62 logTraceOut("ProjectOntoFace");
63 }
64"""
65
66
67 def __init__(self,
68 solver,
69 descend_invocation_order=0,
70 parallel=True):
71 super( ProjectOntoFaces, self ).__init__(
72 descend_invocation_order,
73 parallel
74 )
75 self.d = {}
76 self.d["SOLVER_INSTANCE"] = solver.instance_name()
77 self.d["SOLVER_NAME"] = solver.typename()
78
79 def get_body_of_operation(self,operation_name):
80 result = ""
81 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
82 result = jinja2.Template(self.templateTouchCellFirstTime).render(**self.d)
83 pass
84 return result
85
87 """!
88
89 Configure name of generated C++ action set
90
91 This action set will end up in the directory observers with a name that
92 reflects how the observer (initialisation) is mapped onto this action
93 set. The name pattern is ObserverName2ActionSetIdentifier where this
94 routine co-determines the ActionSetIdentifier. We make is reflect the
95 Python class name.
96
97 """
98 return __name__.replace(".py", "").replace(".", "_") + "_ProjectOntoFaces"
99
101 """!
102
103 The action set that Peano will generate that corresponds to this class
104 should not be modified by users and can safely be overwritten every time
105 we run the Python toolkit.
106
107 """
108 return False
109
110 def get_includes(self):
111 """!
112
113 We need the solver repository in this action set, as we directly access
114 the solver object. We also need access to Peano's d-dimensional loops.
115
116 """
117 return """
118#include "../repositories/SolverRepository.h"
119#include "peano4/utils/Loop.h"
120"""
get_action_set_name(self)
Configure name of generated C++ action set.
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_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
__init__(self, solver, descend_invocation_order=0, parallel=True)
Action set (reactions to events)
Definition ActionSet.py:6