Peano
Loading...
Searching...
No Matches
Prolongation.py
Go to the documentation of this file.
1from peano4.solversteps.ActionSet import ActionSet
2
3import peano4
4import jinja2
5
6
8 """!
9 This also should be called before the solver stuff
10 """
11 templateTouchVertexFirstTime="""
12 if (
13 repositories::{{SOLVER_INSTANCE}}.prolongate()
14 and
15 fineGridVertex{{SOLVER_NAME}}.getLevel() == repositories::{{SOLVER_INSTANCE}}.getActiveLevel() - 1
16 ) {
17 logTraceInWith1Argument("prolongate::setDelta", fineGridVertex{{SOLVER_NAME}}.toString());
18 for (int i=0; i<{{VERTEX_CARDINALITY}}; i++)
19 fineGridVertex{{SOLVER_NAME}}.setDelta(
20 i,
21 fineGridVertex{{SOLVER_NAME}}.getU(i) - fineGridVertex{{SOLVER_NAME}}.getOldU(i)
22 );
23 logTraceOutWith1Argument("prolongate::setDelta", fineGridVertex{{SOLVER_NAME}}.toString());
24 }
25
26 else if (
27 repositories::{{SOLVER_INSTANCE}}.prolongate()
28 and
29 fineGridVertex{{SOLVER_NAME}}.getLevel() == repositories::{{SOLVER_INSTANCE}}.getActiveLevel()
30 ) {
31 // do some real prolongation...
32 mghype::matrixfree::solvers::cgmultigrid::prolongate<{{SOLVER_NAME}}>(
33 repositories::{{SOLVER_INSTANCE}}.getProlongationMatrix(marker.x(), marker.h()),
34 coarseGridVertices{{SOLVER_NAME}},
35 fineGridVertex{{SOLVER_NAME}},
36 marker
37 );
38 }
39 """
40
41 def __init__(self,
42 solver,
43 descend_invocation_order=0,
44 parallel=False):
45 super( Prolongation, self ).__init__(
46 descend_invocation_order,
47 parallel
48 )
49 self.d = {}
50 self.d["SOLVER_INSTANCE"] = solver.instance_name()
51 self.d["SOLVER_NAME"] = solver.typename()
52 self.d["VERTEX_CARDINALITY"] = solver._unknowns_per_vertex_node
53
54 def get_body_of_operation(self,operation_name):
55 result = ""
56 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME:
57 result = jinja2.Template(self.templateTouchVertexFirstTime).render(**self.d)
58 pass
59 # if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_LAST_TIME:
60 # result = jinja2.Template(self.templateTouchVertexLastTime).render(**self.d)
61 # pass
62 return result
63
65 """!
66
67 The action set that Peano will generate that corresponds to this class
68 should not be modified by users and can safely be overwritten every time
69 we run the Python toolkit.
70
71 """
72 return False
73
74 def get_includes(self):
75 """!
76
77 We need the solver repository in this action set, as we directly access
78 the solver object. We also need access to Peano's d-dimensional loops.
79
80 """
81 return """
82#include "repositories/SolverRepository.h"
83#include "peano4/utils/Loop.h"
84#include "mghype/matrixfree/solvers/CGMultigrid.h"
85"""
86
88 """!
89
90 Configure name of generated C++ action set
91
92 This action set will end up in the directory observers with a name that
93 reflects how the observer (initialisation) is mapped onto this action
94 set. The name pattern is ObserverName2ActionSetIdentifier where this
95 routine co-determines the ActionSetIdentifier. We make is reflect the
96 Python class name.
97
98 """
99 return __name__.replace(".py", "").replace(".", "_") + "_Prolongation"
100
This also should be called before the solver stuff.
get_includes(self)
We need the solver repository in this action set, as we directly access the solver object.
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
get_action_set_name(self)
Configure name of generated C++ action set.
__init__(self, solver, descend_invocation_order=0, parallel=False)
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