Peano 4
Loading...
Searching...
No Matches
TimeStepping.cpp
Go to the documentation of this file.
1#include "TimeStepping.h"
2
3#include "tarch/Assertions.h"
4#include "tarch/la/la.h"
5
6
7
8std::pair<double,double> exahype2::getInterpolationWeights( double oldTimeStampOnFace, double newTimeStampOnFace, double cellTimeStamp ) {
9 static tarch::logging::Log _log( "exahype2" );
10
11 double timeSpan = newTimeStampOnFace - oldTimeStampOnFace;
12 assertion4( tarch::la::greaterEquals(timeSpan,0.0), timeSpan, oldTimeStampOnFace, newTimeStampOnFace, cellTimeStamp );
13 if ( tarch::la::equals(timeSpan,0.0) ) {
14 logDebug( "getInterpolationWeights(double,double,double)", "time span equals zero" );
15 return std::pair<double,double>(0.0,1.0);
16 }
17 else {
18 double newWeight = (cellTimeStamp - oldTimeStampOnFace) / timeSpan;
19
20 assertion5( tarch::la::greaterEquals(newWeight,0.0), newWeight, timeSpan, oldTimeStampOnFace, newTimeStampOnFace, cellTimeStamp );
21 assertion5( tarch::la::smallerEquals(newWeight,1.0), newWeight, timeSpan, oldTimeStampOnFace, newTimeStampOnFace, cellTimeStamp );
22
23 logDebug( "getInterpolationWeights(double,double,double)", "timeSpan" << timeSpan );
24
25 return std::pair<double,double>(1.0-newWeight,newWeight);
26 }
27}
28
29
31 double cellTimeStepSize,
32 double maxGlobalTimeStepSize,
33 int discretisationStepsSize
34) {
35 static tarch::logging::Log _log( "exahype2" );
36
37 if (tarch::la::greater(maxGlobalTimeStepSize,0.0) and cellTimeStepSize>maxGlobalTimeStepSize*3.0) {
39 "discretiseAndTruncateTimeStepSizes(double,double,int)",
40 "truncate cell time step size from " << cellTimeStepSize << " due to max global dt=" << maxGlobalTimeStepSize
41 );
42 cellTimeStepSize = maxGlobalTimeStepSize*3.0;
43 }
44
45 if (discretisationStepsSize<=0) {
46 return cellTimeStepSize;
47 }
48
49 static double maxCurrentTimeStepSize = -1.0;
50
51 if (maxCurrentTimeStepSize<=0.0) {
52 maxCurrentTimeStepSize = cellTimeStepSize;
53 }
54 else if (maxGlobalTimeStepSize>maxCurrentTimeStepSize) {
55 maxCurrentTimeStepSize *= 3.0;
56 }
57
58 double result = maxCurrentTimeStepSize;
59 while (result > cellTimeStepSize) {
60 result /= 3.0;
61 }
62
63 if (discretisationStepsSize>1) {
64 const double incrementOnThisLevel = result / discretisationStepsSize;
65
66 do {
67 result += incrementOnThisLevel;
68 } while (result<cellTimeStepSize);
69 result -= incrementOnThisLevel;
70 }
71
72 logDebug( "discretiseAndTruncateTimeStepSizes(double,double,int)", "reduce dt=" << cellTimeStepSize << " to " << result );
73 return result;
74}
#define assertion4(expr, param0, param1, param2, param3)
#define assertion5(expr, param0, param1, param2, param3, param4)
#define logDebug(methodName, logMacroMessageStream)
Definition Log.h:50
Log Device.
Definition Log.h:516
std::pair< double, double > getInterpolationWeights(double oldTimeStampOnFace, double newTimeStampOnFace, double cellTimeStamp)
double discretiseAndTruncateTimeStepSizes(double cellTimeStepSize, double maxGlobalTimeStepSize, int discretisationStepsSize)
Discretise (bucket) time step sizes and truncate it.
bool greater(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool greaterEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool smallerEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
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")