Peano 4
Loading...
Searching...
No Matches
TimeStepping.h
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
3#pragma once
4
5
7#include "tarch/logging/Log.h"
8
10
11#include <utility>
12
13
14namespace exahype2 {
15 namespace internal {
20 template <typename FaceLabel>
23 ) {
24 double result = std::numeric_limits<double>::max();
25
26 for (int d=0; d<Dimensions; d++) {
27 result = std::min(result, faceLabelEnumerator(d).getNewTimeStamp(0) );
28 result = std::min(result, faceLabelEnumerator(d+Dimensions).getNewTimeStamp(1) );
29 }
30
31 return result;
32 }
33 }
34
60 template <typename CellLabel, typename FaceLabel>
62 const CellLabel& cellLabel,
64 ) {
65 double result = std::numeric_limits<double>::max();
66 bool oneIsAhead = false;
67 bool oneIsBehind = false;
68
69 for (int d=0; d<Dimensions; d++) {
70 double leftNeighbourTimeStamp = faceLabelEnumerator(d).getNewTimeStamp(0);
71 if (
72 not faceLabelEnumerator(d).getBoundary()
73 and
74 tarch::la::greater(leftNeighbourTimeStamp,cellLabel.getTimeStamp())
75 ) {
76 result = std::min(result,leftNeighbourTimeStamp);
77 oneIsAhead = true;
78 }
79 if (
80 not faceLabelEnumerator(d).getBoundary()
81 and
82 tarch::la::smaller(leftNeighbourTimeStamp,cellLabel.getTimeStamp())
83 ) {
84 oneIsBehind = true;
85 }
86
87 double rightNeighbourTimeStamp = faceLabelEnumerator(d+Dimensions).getNewTimeStamp(1);
88 if (
89 not faceLabelEnumerator(d+Dimensions).getBoundary()
90 and
91 tarch::la::greater(rightNeighbourTimeStamp,cellLabel.getTimeStamp())
92 ) {
93 result = std::min(result,rightNeighbourTimeStamp);
94 oneIsAhead = true;
95 }
96 if (
97 not faceLabelEnumerator(d+Dimensions).getBoundary()
98 and
99 tarch::la::smaller(rightNeighbourTimeStamp,cellLabel.getTimeStamp())
100 ) {
101 oneIsBehind = true;
102 }
103 }
104
105 if (oneIsAhead and not oneIsBehind) {
106 assertion(result>cellLabel.getTimeStamp());
107 return result;
108 }
109 else {
110 return cellLabel.getTimeStamp();
111 }
112 }
113
131 template <typename CellLabel, typename FaceLabel>
133 const CellLabel& cellLabel,
135 double globalMinTimeStamp
136 ) {
137 double cellTimeStamp = cellLabel.getTimeStamp();
138 double cellTimeStepSize = cellLabel.getTimeStepSize();
139
140 const double Tolerance = 0.01;
141
142 bool result = tarch::la::greaterEquals( ::exahype2::internal::getMinTimeStampOfNeighbours(faceLabelEnumerator), cellTimeStamp, Tolerance*cellTimeStepSize )
143 or tarch::la::equals(cellTimeStamp, globalMinTimeStamp);
144
145 // @todo das ist net das Problem. Das Problem ist, dass ich u.U. keine Eigenwerte habe
146 if (not result) {
147// std::cout << "skip " << cellLabel.toString() << " as neighbours have t_min=" << ::exahype2::internal::getMinTimeStampOfNeighbours(faceLabelEnumerator) << std::endl;
148 }
149 return result;
150 }
151
152
199 template <typename CellLabel, typename FaceLabel>
201 const CellLabel& cellLabel,
203 double timeStepSize
204 ) {
205 static tarch::logging::Log _log( "exahype2" );
206
207 const double Tolerance = 0.01;
208 double relativeTolerance = tarch::la::equals(timeStepSize,0.0) ? tarch::la::NUMERICAL_ZERO_DIFFERENCE : Tolerance * timeStepSize;
209
210 double maxOfMatchingTimeStamps = -1.0;
211 const double currentFutureTimeStamp = cellLabel.getTimeStamp() + timeStepSize;
212 for (int d=0; d<Dimensions; d++) {
213 if (
214 not faceLabelEnumerator(d).getBoundary()
215 and
216 tarch::la::equals( faceLabelEnumerator(d).getNewTimeStamp(0), currentFutureTimeStamp, relativeTolerance)
217 ) {
218 maxOfMatchingTimeStamps = std::max(maxOfMatchingTimeStamps,faceLabelEnumerator(d).getNewTimeStamp(0));
219 }
220 if (
221 not faceLabelEnumerator(d).getBoundary()
222 and
223 tarch::la::equals( faceLabelEnumerator(d+Dimensions).getNewTimeStamp(1), currentFutureTimeStamp, relativeTolerance)
224 ) {
225 maxOfMatchingTimeStamps = std::max(maxOfMatchingTimeStamps,faceLabelEnumerator(d+Dimensions).getNewTimeStamp(1));
226 }
227 }
228
229 if ( maxOfMatchingTimeStamps>0.0 ) {
230 double tweakedTimeStepSize = maxOfMatchingTimeStamps - cellLabel.getTimeStamp();
231 assertion2( tarch::la::greaterEquals( tweakedTimeStepSize,timeStepSize ), tweakedTimeStepSize, timeStepSize );
232 if (tweakedTimeStepSize>timeStepSize) {
233 logDebug( "removeTimeStepAccummulationErrorsFromCell(...)", "adopt local time step from " << timeStepSize << " to " << tweakedTimeStepSize );
234 }
235 timeStepSize = tweakedTimeStepSize;
236 }
237
238 logDebug( "removeTimeStepAccummulationErrorsFromCell(...)", "dt=" << timeStepSize << ", max-match=" << maxOfMatchingTimeStamps );
239 return timeStepSize;
240 }
241
242
258 std::pair<double,double> getInterpolationWeights( double oldTimeStampOnFace, double newTimeStampOnFace, double cellTimeStamp );
259
306 double cellTimeStepSize,
307 double maxGlobalTimeStepSize,
308 int discretisationStepsSize
309 );
310}
311
#define assertion2(expr, param0, param1)
#define assertion(expr)
#define logDebug(methodName, logMacroMessageStream)
Definition Log.h:50
Enumerator over an array of faces.
Log Device.
Definition Log.h:516
double getMinTimeStampOfNeighbours(const peano4::datamanagement::FaceEnumerator< FaceLabel > &faceLabelEnumerator)
Run over all neighbours and analyse their time stamp.
Common routines required for a variety of Riemann solvers.
Definition AderUtils.h:16
double removeTimeStepAccumulationErrorsFromCell(const CellLabel &cellLabel, const peano4::datamanagement::FaceEnumerator< FaceLabel > &faceLabelEnumerator, double timeStepSize)
Remove accumulation errors from cell time stamps.
double getMinTimeStampOfNeighboursAhead(const CellLabel &cellLabel, const peano4::datamanagement::FaceEnumerator< FaceLabel > &faceLabelEnumerator)
Similar to getMinTimeStampOfNeighbours(), but we minimise only over those neighbours that are actuall...
std::pair< double, double > getInterpolationWeights(double oldTimeStampOnFace, double newTimeStampOnFace, double cellTimeStamp)
bool runTimeStepOnCell(const CellLabel &cellLabel, const peano4::datamanagement::FaceEnumerator< FaceLabel > &faceLabelEnumerator, double globalMinTimeStamp)
Determine whether to run a time step on a cell by analysing the neighbouring cells' timestamp.
double discretiseAndTruncateTimeStepSizes(double cellTimeStepSize, double maxGlobalTimeStepSize, int discretisationStepsSize)
Discretise (bucket) time step sizes and truncate it.
static bool smaller(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE) InlineMethod
Smaller operator for floating point values.
bool greater(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool greaterEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
constexpr double NUMERICAL_ZERO_DIFFERENCE
Definition Scalar.h:17
bool equals(const Matrix< Rows, Cols, Scalar > &lhs, const Matrix< Rows, Cols, Scalar > &rhs, const Scalar &tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares to matrices on equality by means of a numerical accuracy.
tarch::logging::Log _log("examples::unittests")