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
5import mghype
6
8 """!
9 This should be identical to the original, with the only difference that we
10 do stuff when we touch the vertex for the last time
11 """
12
13 templateTouchVertexLastTime = """
14 if (
15 fineGridVertex{{SOLVER_NAME}}.getType() == vertexdata::{{SOLVER_NAME}}::Type::Interior
16 and
17 repositories::{{SOLVER_INSTANCE}}.updateSolution( fineGridVertex{{SOLVER_NAME}}.getLevel() )
18 ) {
19 logTraceInWith3Arguments("TouchVertexLastTime", fineGridVertex{{SOLVER_NAME}}.toString(), marker.x(), marker.h());
20
21 for (int unknown=0; unknown<{{VERTEX_CARDINALITY}}; unknown++)
22 {
23 logTraceInWith3Arguments("updateValue", fineGridVertex{{SOLVER_NAME}}.getU(unknown), fineGridVertex{{SOLVER_NAME}}.getDiag(unknown), fineGridVertex{{SOLVER_NAME}}.getResidual(unknown));
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
31 fineGridVertex{{SOLVER_NAME}}.setU(unknown, fineGridVertex{{SOLVER_NAME}}.getU(unknown) + du);
32 logTraceOutWith1Argument("updateValue", fineGridVertex{{SOLVER_NAME}}.getU(unknown));
33 }
34 logTraceOutWith1Argument("TouchVertexLastTime", fineGridVertex{{SOLVER_NAME}}.toString());
35 }
36 // only care about solution on finest level...
37 if (
38 fineGridVertex{{SOLVER_NAME}}.getType() == vertexdata::{{SOLVER_NAME}}::Type::Interior
39 and
40 repositories::{{SOLVER_INSTANCE}}.reportSolutionUpdates( fineGridVertex{{SOLVER_NAME}}.getLevel() )
41 ) {
42 for (int unknown=0; unknown<{{VERTEX_CARDINALITY}}; unknown++) {
43 double r = fineGridVertex{{SOLVER_NAME}}.getResidual(unknown);
44 double du = repositories::{{SOLVER_INSTANCE}}.Omega
45 * 1.0 / fineGridVertex{{SOLVER_NAME}}.getDiag(unknown) * r;
46
47 repositories::{{SOLVER_INSTANCE}}.updateGlobalResidual(r, marker.h());
48 repositories::{{SOLVER_INSTANCE}}.updateGlobalSolutionUpdates(du, marker.h()(0));
49 }
50 }
51 """
52
53 def __init__(self,
54 solver,
55 descend_invocation_order=0,
56 parallel=False):
57 super( UpdateSolution, self ).__init__(
58 descend_invocation_order,
59 parallel
60 )
61 self.d = {}
62 self.d["SOLVER_INSTANCE"] = solver.instance_name()
63 self.d["SOLVER_NAME"] = solver.typename()
64 self.d["VERTEX_CARDINALITY"] = solver._unknowns_per_vertex_node
65
66 def get_body_of_operation(self,operation_name):
67 result = ""
68 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_VERTEX_LAST_TIME:
69 result = jinja2.Template(self.templateTouchVertexLastTime).render(**self.d)
70 pass
71 return result
72
74 """!
75
76 The action set that Peano will generate that corresponds to this class
77 should not be modified by users and can safely be overwritten every time
78 we run the Python toolkit.
79
80 """
81 return False
82
83 def get_includes(self):
84 """!
85
86 We need the solver repository in this action set, as we directly access
87 the solver object. We also need access to Peano's d-dimensional loops.
88
89 """
90 return """
91#include "repositories/SolverRepository.h"
92#include "peano4/utils/Loop.h"
93#include "mghype/matrixfree/solvers/CGMultigrid.h"
94"""
95
97 """!
98
99 Configure name of generated C++ action set
100
101 This action set will end up in the directory observers with a name that
102 reflects how the observer (initialisation) is mapped onto this action
103 set. The name pattern is ObserverName2ActionSetIdentifier where this
104 routine co-determines the ActionSetIdentifier. We make is reflect the
105 Python class name.
106
107 """
108 return __name__.replace(".py", "").replace(".", "_")
Action set (reactions to events)
Definition ActionSet.py:6
This should be identical to the original, with the only difference that we do stuff when we touch the...
__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.