Peano
Loading...
Searching...
No Matches
UpdateSolution.py
Go to the documentation of this file.
1from peano4.solversteps.ActionSet import ActionSet
2
3import peano4
4import jinja2
5
7 """!
8 This action set goes first, so that if we've done at least one sweep, we can update the
9 solution based on the residual and diag.
10
11 We wait until the next sweep so that vertices that are shared across multiple spacetrees
12 have a chance to agree on a value for residual and diag, since not all contributions
13 will be registered.
14 """
15
16 templateTouchVertexFirstTime="""
17 if (
18 fineGridVertex{{SOLVER_NAME}}.getType() == vertexdata::{{SOLVER_NAME}}::Type::Interior
19 and
20 repositories::{{SOLVER_INSTANCE}}.updateSolution()
21 ) {
22 for (int unknown=0; unknown<{{VERTEX_CARDINALITY}}; unknown++)
23 {
24 assertion( fineGridVertex{{SOLVER_NAME}}.getDiag(unknown) > 0 );
25
26 double r = fineGridVertex{{SOLVER_NAME}}.getResidual(unknown);
27 double du = repositories::{{SOLVER_INSTANCE}}.Omega
28 * 1.0 / fineGridVertex{{SOLVER_NAME}}.getDiag(unknown) * r;
29
30 repositories::{{SOLVER_INSTANCE}}.updateGlobalResidual(
31 r, marker.h()
32 );
33 repositories::{{SOLVER_INSTANCE}}.updateGlobalSolutionUpdates(
34 du, marker.h()(0)
35 );
36
37 fineGridVertex{{SOLVER_NAME}}.setU(unknown, fineGridVertex{{SOLVER_NAME}}.getU(unknown) + du );
38 }
39 }
40
41 if ( fineGridVertex{{SOLVER_NAME}}.getType() == vertexdata::{{SOLVER_NAME}}::Type::Boundary ) {
42 auto value = 0.0;
43 for (int unknown=0; unknown<{{VERTEX_CARDINALITY}}; unknown++) {
44 fineGridVertex{{SOLVER_NAME}}.setU(unknown, value);
45 }
46 }
47 """
48
49 def __init__(self,
50 solver,
51 descend_invocation_order=0,
52 parallel=False
53 ):
54 super( UpdateSolution, self ).__init__(
55 descend_invocation_order,
56 parallel
57 )
58 self.d = {}
59 self.d["SOLVER_INSTANCE"] = solver.instance_name()
60 self.d["SOLVER_NAME"] = solver.typename()
61 self.d["VERTEX_CARDINALITY"] = solver._unknowns_per_vertex_node
62
63 def get_body_of_operation(self,operation_name):
64 result = ""
65 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_FIRST_TIME:
66 result = jinja2.Template(self.templateTouchVertexFirstTime).render(**self.d)
67 pass
68 return result
69
71 """!
72
73 Configure name of generated C++ action set
74
75 This action set will end up in the directory observers with a name that
76 reflects how the observer (initialisation) is mapped onto this action
77 set. The name pattern is ObserverName2ActionSetIdentifier where this
78 routine co-determines the ActionSetIdentifier. We make is reflect the
79 Python class name.
80
81 """
82 return __name__.replace(".py", "").replace(".", "_")
83
85 """!
86
87 The action set that Peano will generate that corresponds to this class
88 should not be modified by users and can safely be overwritten every time
89 we run the Python toolkit.
90
91 """
92 return False
93
94 def get_includes(self):
95 """!
96
97 We need the solver repository in this action set, as we directly access
98 the solver object. We also need access to Peano's d-dimensional loops.
99
100 """
101 return """
102#include "../repositories/SolverRepository.h"
103#include "peano4/utils/Loop.h"
104"""
Action set (reactions to events)
Definition ActionSet.py:6
This action set goes first, so that if we've done at least one sweep, we can update the solution base...
__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...
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.