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