Peano
Loading...
Searching...
No Matches
ProjectIntoCellAndUpdateCellSolution.py
Go to the documentation of this file.
1from peano4.solversteps.ActionSet import ActionSet
2
3import peano4
4import jinja2
5
6
8 templateTouchCellFirstTime="""
9 if (
10 fineGridCell{{SOLVER_NAME}}.getType() != celldata::{{SOLVER_NAME}}::Type::Coarse
11 and
12 repositories::{{SOLVER_INSTANCE}}.projectOntoCells()
13 ) {
14 logTraceInWith2Arguments( "ProjectOntoCells", fineGridCell{{SOLVER_NAME}}.getResidual(), fineGridCell{{SOLVER_NAME}}.getSolution() );
15
16 // we intend that the internal residual vector should be reset and updated in the
17 // cell update procedure
18
19 // This vector faceSol will contain: soln on face 0 | soln on face 1 | soln on face 2 | .....
20 tarch::la::Vector< repositories::{{SOLVER_INSTANCE}}.FaceUnknownsSolution*TwoTimesD, double > faceSol;
21 for (int f=0; f<TwoTimesD; f++)
22 for (int s=0; s<repositories::{{SOLVER_INSTANCE}}.FaceUnknownsSolution; s++)
23 faceSol( f*repositories::{{SOLVER_INSTANCE}}.FaceUnknownsSolution + s ) = fineGridFaces{{SOLVER_NAME}}(f).getSolution(s);
24
25 // next, we need to project solution on face onto the cell...
26 auto projection = repositories::{{SOLVER_INSTANCE}}.getCellFromFaceMatrix(marker.x(), marker.h()) * faceSol;
27 // loop over each face, finish updating residual as we go
28 for (int f=0; f<repositories::{{SOLVER_INSTANCE}}.CellUnknowns; f++)
29 {
30 // project the face solution onto the cell; add to r
31 fineGridCell{{SOLVER_NAME}}.setResidual(f,
32 fineGridCell{{SOLVER_NAME}}.getResidual(f)- projection(f));
33 }
34
35 // multiply by "smoother" / preconditioner
36 fineGridCell{{SOLVER_NAME}}.setResidual(
37 repositories::{{SOLVER_INSTANCE}}.getInvertedApproxSystemMatrix(marker.x(),marker.h())
38 * fineGridCell{{SOLVER_NAME}}.getResidual()
39 );
40
41 for (int i=0; i<fineGridCell{{SOLVER_NAME}}.getSolution().size(); i++) {
42 double res = fineGridCell{{SOLVER_NAME}}.getResidual( i );
43 double du = repositories::{{SOLVER_INSTANCE}}.OmegaCell * res;
44 fineGridCell{{SOLVER_NAME}}.setSolution( i,
45 fineGridCell{{SOLVER_NAME}}.getSolution( i ) + du
46 );
47 repositories::{{SOLVER_INSTANCE}}.updateGlobalResidual(res, marker.h());
48 repositories::{{SOLVER_INSTANCE}}.updateGlobalSolutionUpdates(du, marker.h()(0));
49 repositories::{{SOLVER_INSTANCE}}.updateMinMaxMeshSize( marker.h() );
50 }
51
52 logTraceOutWith2Arguments( "ProjectOntoCells", fineGridCell{{SOLVER_NAME}}.getResidual(), fineGridCell{{SOLVER_NAME}}.getSolution() );
53 }
54
55 """
56 def __init__(self,
57 solver,
58 descend_invocation_order=0,
59 parallel=True):
60 super( ProjectIntoCellAndUpdateCellSolution, self ).__init__(
61 descend_invocation_order,
62 parallel
63 )
64 self.d = {}
65 self.d["SOLVER_INSTANCE"] = solver.instance_name()
66 self.d["SOLVER_NAME"] = solver.typename()
67
68 def get_body_of_operation(self,operation_name):
69 result = ""
70 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
71 result = jinja2.Template(self.templateTouchCellFirstTime).render(**self.d)
72 pass
73 return result
74
76 """!
77
78 Configure name of generated C++ action set
79
80 This action set will end up in the directory observers with a name that
81 reflects how the observer (initialisation) is mapped onto this action
82 set. The name pattern is ObserverName2ActionSetIdentifier where this
83 routine co-determines the ActionSetIdentifier. We make is reflect the
84 Python class name.
85
86 """
87 return __name__.replace(".py", "").replace(".", "_") + "_ProjectIntoCellAndUpdateCellSolution"
88
90 """!
91
92 The action set that Peano will generate that corresponds to this class
93 should not be modified by users and can safely be overwritten every time
94 we run the Python toolkit.
95
96 """
97 return False
98
99 def get_includes(self):
100 """!
101
102 We need the solver repository in this action set, as we directly access
103 the solver object. We also need access to Peano's d-dimensional loops.
104
105 """
106 return """
107#include "../repositories/SolverRepository.h"
108#include "peano4/utils/Loop.h"
109"""
110
111
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
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...
Action set (reactions to events)
Definition ActionSet.py:6