Peano
Loading...
Searching...
No Matches
CollocatedDLinearDiscretisationWithPointJacobi.Abstract.template.cpp
Go to the documentation of this file.
1#include "{{CLASSNAME}}.h"
2#include "mghype/mghype.h"
3
4
5tarch::logging::Log {{NAMESPACE | join("::")}}::{{CLASSNAME}}::_log( "{{NAMESPACE | join("::")}}::{{CLASSNAME}}" );
6
7{{NAMESPACE | join("::")}}::{{CLASSNAME}}::{{CLASSNAME}}():
8 Solver("{{CLASSNAME}}", {{SOLVER_TOLERANCE}} ),
9 _state(State::Solve), _updateSolution(false)
10{}
11
12
13{{NAMESPACE | join("::")}}::{{CLASSNAME}}::~{{CLASSNAME}}() {}
14
15
16{% if CUSTOM_INIT_VERTEX!="" %}
17void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::initVertex(
20 tarch::la::Vector< {{VERTEX_CARDINALITY}}, double >& value,
21 tarch::la::Vector< {{VERTEX_CARDINALITY}}, double >& rhs
22) {
23{{CUSTOM_INIT_VERTEX}}
24}
25{% endif %}
26
27
28{% if CUSTOM_BOUNDARY_CONDITIONS!="" %}
29void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::setBoundaryConditions(
32 tarch::la::Vector< {{VERTEX_CARDINALITY}}, double >& value
33) {
34{{CUSTOM_BOUNDARY_CONDITIONS}}
35}
36{% endif %}
37
38
39{% if LOCAL_ASSEMBLY_MATRIX is defined %}
40tarch::la::Matrix< {{VERTEX_CARDINALITY}}*TwoPowerD, {{VERTEX_CARDINALITY}}*TwoPowerD, double > {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getLocalAssemblyMatrix(
43) {
44 logTraceInWith2Arguments("getLocalAssemblyMatrix", cellCentre, cellSize);
45 static std::vector< tarch::la::Matrix< {{VERTEX_CARDINALITY}}*TwoPowerD, {{VERTEX_CARDINALITY}}*TwoPowerD, double > > matrices = {
46 {% for MATRIX in LOCAL_ASSEMBLY_MATRIX %}
47 {
48 {{MATRIX[0]| join(", ")}}
49 {% for ROW in MATRIX[1:] %}
50 ,{{ROW | join(", ")}}
51 {% endfor %}
52 },
53 {% endfor %}
54 };
55
56 {% if LOCAL_ASSEMBLY_MATRIX_SCALING is not defined %}
57 #error If matrices are predefined, scaling has to be defined, too
58 {% endif %}
59
60 static std::vector<int> scaleFactors = {
61 {% for el in LOCAL_ASSEMBLY_MATRIX_SCALING %}
62 {{el}},
63 {% endfor %}
64 };
65
66 // may not be static, as it depends upon h
67 tarch::la::Matrix< {{VERTEX_CARDINALITY}}*TwoPowerD, {{VERTEX_CARDINALITY}}*TwoPowerD, double > result = ::mghype::composeMatrixFromHWeightedLinearCombination( matrices, scaleFactors, cellSize );
68
69 logTraceOutWith1Argument("getLocalAssemblyMatrix", result);
70 return result;
71}
72{% endif %}
73
74
75{% if MASS_MATRIX is defined %}
76tarch::la::Matrix< {{VERTEX_CARDINALITY}}*TwoPowerD, {{VERTEX_CARDINALITY}}*TwoPowerD, double > {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getRhsMatrix(
79) {
80 static std::vector< tarch::la::Matrix< {{VERTEX_CARDINALITY}}*TwoPowerD, {{VERTEX_CARDINALITY}}*TwoPowerD, double > > matrices = {
81 {% for MATRIX in MASS_MATRIX %}
82 // {# MASS_MATRIX is an array, possible of length 1 #}
83 {
84 {{MATRIX[0]| join(", ")}}
85 {% for ROW in MATRIX[1:] %}
86 ,{{ROW | join(", ")}}
87 {% endfor %}
88 },
89 {% endfor %}
90 };
91
92 {% if MASS_MATRIX_SCALING is not defined %}
93 #error If matrices are predefined, scaling has to be defined, too
94 {% endif %}
95
96 static std::vector<int> scaleFactors = {
97 {% for el in MASS_MATRIX_SCALING %}
98 {{el}},
99 {% endfor %}
100 };
101
102 // may not be static, as it depends upon h
103 tarch::la::Matrix< {{VERTEX_CARDINALITY}}*TwoPowerD, {{VERTEX_CARDINALITY}}*TwoPowerD, double > result = ::mghype::composeMatrixFromHWeightedLinearCombination( matrices, scaleFactors, cellSize );
104
105 return result;
106}
107{% endif %}
108
109
110{{NAMESPACE | join("::")}}::vertexdata::{{SOLVER_NAME}}::Type {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getVertexType(
113) {
114 auto isOnBoundary = [&]( const tarch::la::Vector< Dimensions, double > & x ) -> bool{
115 bool isOnBoundary = false;
116 for (int d=0; d<Dimensions; d++) {
117 isOnBoundary |= tarch::la::smallerEquals( x(d), DomainOffset(d) );
118 isOnBoundary |= tarch::la::greaterEquals( x(d), DomainOffset(d)+DomainSize(d) );
119 }
120 return isOnBoundary;
121 };
122
123 return isOnBoundary(x) ? vertexdata::{{SOLVER_NAME}}::Type::Boundary : vertexdata::{{SOLVER_NAME}}::Type::Interior;
124}
125
126
127{{NAMESPACE | join("::")}}::celldata::{{SOLVER_NAME}}::Type {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getCellType(
130) {
131 return celldata::{{SOLVER_NAME}}::Type::Interior;
132}
133
134
135void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::suspend() {
136 _state = State::Suspend;
137
138 // we don't want to update the solution immediately when we
139 // revisit this solver. We will have updated the solution itself
140 // during the DGCGCoupling, and we don't want to re-update the
141 // solution with an out-of-date residual.
142 _updateSolution = false;
143}
144
145bool {{NAMESPACE | join("::")}}::{{CLASSNAME}}::isSuspended() const {
146 return _state == State::Suspend;
147}
148
149void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::beginMeshSweep() {
150 clearGlobalResidualAndSolutionUpdate();
151}
152
153
154void {{NAMESPACE | join("::")}}::{{CLASSNAME}}::endMeshSweep() {
155 if ( _state == State::Solve ) {
156 synchroniseGlobalResidualAndSolutionUpdate();
157
158 // if we were already in State::Solve, then we've done at
159 // least one sweep, and we can safely re-enable solution updates.
160 _updateSolution = true;
161 }
162
163 if (
164 tarch::mpi::Rank::getInstance().isGlobalMaster()
165 and
166 _state == State::Solve
167 ) {
168 logInfo( "endMeshSweep()", toString() );
169 }
170
171 _state = State::Solve;
172}
173
174bool {{NAMESPACE | join("::")}}::{{CLASSNAME}}::updateSolution() const {
175 return
176 _state == State::Solve
177 and
179}
180
181
182bool {{NAMESPACE | join("::")}}::{{CLASSNAME}}::updateResidual() const {
183 return _state == State::Solve;
184}
185
186{{NAMESPACE | join("::")}}::{{CLASSNAME}}::State {{NAMESPACE | join("::")}}::{{CLASSNAME}}::getState() const {
187 return _state;
188}
189{{ABSTRACT_SOLVER_IMPLEMENTATION_EXTRAS}}
#define TwoPowerD
Definition Globals.h:19
#define logTraceOutWith1Argument(methodName, argument0)
Definition Log.h:380
#define logTraceInWith2Arguments(methodName, argument0, argument1)
Definition Log.h:371
#define logInfo(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
Definition Log.h:411
Static (i.e.
Definition Matrix.h:42
Log Device.
Definition Log.h:516
static Rank & getInstance()
This operation returns the singleton instance.
Definition Rank.cpp:539
std::string toString(Filter filter)
Definition convert.cpp:170
tarch::logging::Log _log("exahype2::fv")
tarch::la::Matrix< Rows, Cols, double > composeMatrixFromHWeightedLinearCombination(const std::vector< tarch::la::Matrix< Rows, Cols, double > > &matrices, const std::vector< int > &scaleFactors, const tarch::la::Vector< Dimensions, double > &h)
Compute a weighted linear combination of matrices.
Definition mghype.cpph:5
bool greaterEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool smallerEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
Simple vector class.
Definition Vector.h:150