Peano
Loading...
Searching...
No Matches
UpdateCell.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3from peano4.solversteps.ActionSet import ActionSet
4
5import peano4
6import jinja2
7
8
10 """!
11
12 Action set implementing the cell update of the continuous Galerkin solver
13
14 If you apply only this action set (and it makes sense to try this out to get
15 a better grip on what's going on), then you will obtain a result similar to
16 the one below:
17
18 @image html UpdateCellWithoutBoundaryUpdates.png
19
20 The individual cells are all nicely updated, but the boundaries in-between
21 the cells are not updated at all. Effectively, we solve a set of tiny
22 boundary value problems that are decoupled from each other.
23
24 """
25 templateTouchCellFirstTime="""
26 if (
27 fineGridCell{{SOLVER_NAME}}.getType() != celldata::{{SOLVER_NAME}}::Type::Coarse
28// and
29 // only one condition here - ensures that we don't do this when restricting the residual
30// repositories::{{SOLVER_INSTANCE}}.updateResidual()
31 ) {
32 logTraceInWith4Arguments("updateResidual",
33 fineGridCell{{SOLVER_NAME}}.getSolution(),
34 fineGridCell{{SOLVER_NAME}}.getRhs(),
35 marker.toString(),
36 repositories::{{SOLVER_INSTANCE}}.getRhsMatrix( marker.x(), marker.h() )
37 );
38
39 // Compute cell residual. Will be incomplete for boundary nodes
40 tarch::la::Vector< repositories::{{SOLVER_INSTANCE}}.CellUnknowns, double > r =
41 repositories::{{SOLVER_INSTANCE}}.getRhsMatrix( marker.x(), marker.h() ) * fineGridCell{{SOLVER_NAME}}.getRhs();
42 r = r - repositories::{{SOLVER_INSTANCE}}.getLocalAssemblyMatrix(marker.x(), marker.h()) * fineGridCell{{SOLVER_NAME}}.getSolution();
43
44 // @todo This is not nice. As we already book the memory anyway, we should not
45 // allocate r and instead work directly against r. Alternatively, kick out the
46 // residual (as long as we are not in debug mode). That would actually be the
47 // prime version. Or at least make it not persistent.
48 fineGridCell{{SOLVER_NAME}}.setResidual( r );
49
50 tarch::la::Matrix<repositories::{{SOLVER_INSTANCE}}.InnerCellUnknowns, repositories::{{SOLVER_INSTANCE}}.InnerCellUnknowns, double>
51 innerMatrix = repositories::{{SOLVER_INSTANCE}}.NarrowToInteriorMatrix
52 * repositories::{{SOLVER_INSTANCE}}.getLocalAssemblyMatrix(marker.x(), marker.h())
53 * tarch::la::transpose(repositories::{{SOLVER_INSTANCE}}.NarrowToInteriorMatrix);
54
55 tarch::la::Vector< repositories::{{SOLVER_INSTANCE}}.CellUnknowns, double > du =
56 repositories::{{SOLVER_INSTANCE}}.OmegaCell
57 * tarch::la::transpose(repositories::{{SOLVER_INSTANCE}}.NarrowToInteriorMatrix)
58 * tarch::la::invert(innerMatrix)
59 * repositories::{{SOLVER_INSTANCE}}.NarrowToInteriorMatrix
60 * r;
61
62 fineGridCell{{SOLVER_NAME}}.setSolution(
63 fineGridCell{{SOLVER_NAME}}.getSolution()
64 +
65 du
66 );
67
68 repositories::{{SOLVER_INSTANCE}}.updateMinMaxMeshSize( marker.h() );
69 dfor( k, repositories::{{SOLVER_INSTANCE}}.PolyDegree-1 ) {
70 int i = peano4::utils::dLinearised( k + tarch::la::Vector< Dimensions, int >(1), repositories::{{SOLVER_INSTANCE}}.PolyDegree+1 );
71 repositories::{{SOLVER_INSTANCE}}.updateGlobalResidual( r(i), marker.h() );
72 repositories::{{SOLVER_INSTANCE}}.updateGlobalSolutionUpdates( du(i), marker.h() );
73 }
74
75 logTraceOut("updateResidual");
76 }
77 """
78
79 def __init__(self,
80 solver):
81 super( UpdateCell, self ).__init__()
82 self.d = {}
83 self.d["SOLVER_INSTANCE"] = solver.instance_name()
84 self.d["SOLVER_NAME"] = solver.typename()
85
86 def get_body_of_operation(self,operation_name):
87 result = ""
88 if operation_name==peano4.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME:
89 result = jinja2.Template(self.templateTouchCellFirstTime).render(**self.d)
90 pass
91 return result
92
94 """!
95
96 Configure name of generated C++ action set
97
98 This action set will end up in the directory observers with a name that
99 reflects how the observer (initialisation) is mapped onto this action
100 set. The name pattern is ObserverName2ActionSetIdentifier where this
101 routine co-determines the ActionSetIdentifier. We make is reflect the
102 Python class name.
103
104 """
105 return __name__.replace(".py", "").replace(".", "_")
106
108 """!
109
110 The action set that Peano will generate that corresponds to this class
111 should not be modified by users and can safely be overwritten every time
112 we run the Python toolkit.
113
114 """
115 return False
116
117 def get_includes(self):
118 """!
119
120 We need the solver repository in this action set, as we directly access
121 the solver object. We also need access to Peano's d-dimensional loops.
122
123 """
124 return """
125#include "../repositories/SolverRepository.h"
126#include "peano4/utils/Loop.h"
127#include "tarch/la/LUDecomposition.h"
128"""
Action set implementing the cell update of the continuous Galerkin solver.
Definition UpdateCell.py:9
get_body_of_operation(self, operation_name)
Return actual C++ code snippets to be inserted into C++ code.
Definition UpdateCell.py:86
get_includes(self)
We need the solver repository in this action set, as we directly access the solver object.
__init__(self, solver)
Definition UpdateCell.py:80
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.
Definition UpdateCell.py:93
Action set (reactions to events)
Definition ActionSet.py:6