8 templateTouchCellFirstTime=
"""
10 fineGridCell{{SOLVER_NAME}}.getType() != celldata::{{SOLVER_NAME}}::Type::Coarse
12 repositories::{{SOLVER_INSTANCE}}.projectOntoCells()
14 logTraceInWith2Arguments( "ProjectOntoCells", fineGridCell{{SOLVER_NAME}}.getResidual(), fineGridCell{{SOLVER_NAME}}.getSolution() );
16 // we intend that the internal residual vector should be reset and updated in the
17 // cell update procedure
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);
25 // next, we need to project solution on face onto the cell...
26 auto projection = repositories::{{SOLVER_INSTANCE}}.applyCellFromFaceMatrix(marker.x(), marker.h(), faceSol);
28 // loop over each face, finish updating residual as we go
29 for (int f=0; f<repositories::{{SOLVER_INSTANCE}}.CellUnknowns; f++)
31 // project the face solution onto the cell; add to r
32 fineGridCell{{SOLVER_NAME}}.setResidual(f,
33 fineGridCell{{SOLVER_NAME}}.getResidual(f)- projection(f));
36 // update global residual before multiplying by the preconditioner
37 for (int i=0; i<fineGridCell{{SOLVER_NAME}}.getSolution().size(); i++) {
38 double res = fineGridCell{{SOLVER_NAME}}.getResidual( i );
39 _solverStatistics.updateGlobalResidual(res, marker.h());
42 // multiply by "smoother" / preconditioner
43 fineGridCell{{SOLVER_NAME}}.setResidual( repositories::{{SOLVER_INSTANCE}}.applyInvertedApproxSystemMatrix(
46 fineGridCell{{SOLVER_NAME}}.getResidual()
49 for (int i=0; i<fineGridCell{{SOLVER_NAME}}.getSolution().size(); i++) {
50 double res = fineGridCell{{SOLVER_NAME}}.getResidual( i );
51 double du = repositories::{{SOLVER_INSTANCE}}.OmegaCell * res;
52 fineGridCell{{SOLVER_NAME}}.setSolution( i,
53 fineGridCell{{SOLVER_NAME}}.getSolution( i ) + du
55 _solverStatistics.updateGlobalSolutionUpdates(du, marker.h()(0));
56 _solverStatistics.updateMinMaxMeshSize( marker.h() );
59 logTraceOutWith2Arguments( "ProjectOntoCells", fineGridCell{{SOLVER_NAME}}.getResidual(), fineGridCell{{SOLVER_NAME}}.getSolution() );
65 descend_invocation_order=0,
67 super( ProjectIntoCellAndUpdateCellSolution, self ).
__init__(
68 descend_invocation_order,
72 self.
d[
"SOLVER_INSTANCE"] = solver.instance_name()
73 self.
d[
"SOLVER_NAME"] = solver.typename()
77 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
80 if operation_name==peano4.solversteps.ActionSet.OPERATION_BEGIN_TRAVERSAL:
81 result = jinja2.Template(
"""
82 _solverStatistics.clearGlobalPrecondResidualUpdate();
83 _solverStatistics.clearGlobalResidualAndSolutionUpdate();
85 if operation_name==peano4.solversteps.ActionSet.OPERATION_END_TRAVERSAL:
86 result = jinja2.Template(
"""
87 repositories::{{SOLVER_INSTANCE}}.merge( _solverStatistics );
94 Configure name of generated C++ action set
96 This action set will end up in the directory observers with a name that
97 reflects how the observer (initialisation) is mapped onto this action
98 set. The name pattern is ObserverName2ActionSetIdentifier where this
99 routine co-determines the ActionSetIdentifier. We make is reflect the
103 return __name__.replace(
".py",
"").replace(
".",
"_") +
"_ProjectIntoCellAndUpdateCellSolution"
108 The action set that Peano will generate that corresponds to this class
109 should not be modified by users and can safely be overwritten every time
110 we run the Python toolkit.
118 We need the solver repository in this action set, as we directly access
119 the solver object. We also need access to Peano's d-dimensional loops.
123#include "../repositories/SolverRepository.h"
124#include "peano4/utils/Loop.h"
130 Return attributes as copied and pasted into the generated class.
132 Please note that action sets are not persistent, i.e. there is one
133 object creation per grid sweep per tree.
137 ::mghype::matrixfree::solvers::SolverStatistics _solverStatistics;
Action set (reactions to events)
__init__(self, solver, descend_invocation_order=0, parallel=True)
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.
str templateTouchCellFirstTime
user_should_modify_template(self)
The action set that Peano will generate that corresponds to this class should not be modified by user...
get_action_set_name(self)
Configure name of generated C++ action set.
get_attributes(self)
Return attributes as copied and pasted into the generated class.