Peano
Loading...
Searching...
No Matches
OptimisticAdaptiveTimeSteppingCodeSnippets.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
4
5
7 """
8
9 Code snippet generator for fixed time stepping in the Runge-Kutta schemes
10
11 """
12 def __init__(self, time_step_relaxation):
13 self._time_step_relaxation = time_step_relaxation
14
15
17 return """
18 if (
19 tarch::mpi::Rank::getInstance().isGlobalMaster()
20 and
21 _maxGridCellHThisTimeStep>0.0
22 and
23 isFirstGridSweepOfTimeStep()
24 ) {
25 logInfo( "startTimeStep()", "Solver {{SOLVER_NAME}}:" );
26 logInfo( "startTimeStep()", "t = " << _minTimeStampThisTimeStep );
27 logInfo( "startTimeStep()", "dt = " << getAdmissibleTimeStepSize() );
28 if (_cancelOptimisticTasks) {
29 logInfo( "startTimeStep()", "dt_{predicted} = " << getPredictedAdmissibleTimeStepSize() << " [cancel predicted tasks]" );
30 }
31 else {
32 logInfo( "startTimeStep()", "dt_{predicted} = " << getPredictedAdmissibleTimeStepSize() );
33 }
34 logInfo( "startTimeStep()", "h_{min} = " << _minGridCellHThisTimeStep << " (individual grid cell within a patch)");
35 logInfo( "startTimeStep()", "h_{max} = " << _maxGridCellHThisTimeStep << " (individual grid cell within a patch)" );
36 logInfo( "startTimeStep()", "lambda_{max} = " << _maxEigenvalue );
37 }
38
39 if (isFirstGridSweepOfTimeStep()) {
40 _maxEigenvalue = 0.0;
41 }
42"""
43
44
46 """
47
48 The superclass takes the admissible cell size and divides it by the
49 maximum eigenvalue. The Finite Volume solvers however operate with
50 patches, i.e. we have to devide by the volume count per axis.
51
52 """
53 return super( OptimisticAdaptiveTimeSteppingCodeSnippets, self ).create_finish_time_step_implementation() + """
54 if (
55 isLastGridSweepOfTimeStep()
56 and
57 tarch::la::greater(_maxEigenvalue, 0.0 )
58 ) {
59 const double optimalTimeStepSize = """ + str(self._time_step_relaxation) + """ * _minGridCellHThisTimeStep / _maxEigenvalue / (2*{{RK_ORDER}}-1);
60
61 const double Threshold = 0.95;
62
63 if (
64 tarch::la::smallerEquals(_predictedAdmissibleTimeStepSize,optimalTimeStepSize)
65 and
66 tarch::la::greaterEquals(_predictedAdmissibleTimeStepSize,optimalTimeStepSize*Threshold)
67 ) {
68 _admissibleTimeStepSize = _predictedAdmissibleTimeStepSize;
69 _predictedAdmissibleTimeStepSize = 0.5 * (optimalTimeStepSize + _predictedAdmissibleTimeStepSize);
70 _cancelOptimisticTasks = false;
71 }
72 else {
73 _admissibleTimeStepSize = optimalTimeStepSize;
74 _predictedAdmissibleTimeStepSize = Threshold * optimalTimeStepSize;
75 _cancelOptimisticTasks = true;
76 }
77
78 if ( std::isnan(_admissibleTimeStepSize) or std::isinf(_admissibleTimeStepSize) ) {
79 ::tarch::triggerNonCriticalAssertion( __FILE__, __LINE__, "_admissibleTimeStepSize>0", "invalid (NaN of inf) time step size: " + std::to_string(_admissibleTimeStepSize) );
80 }
81 if (tarch::la::smallerEquals(_admissibleTimeStepSize,0.0,1e-10) ) {
82 logWarning( "finishTimeStep(...)", "degenerated time step size of " << std::to_string(_admissibleTimeStepSize) << ". Problem might be extremely stiff (and can't be solved) or there could be a bug in the eigenvalue computation" );
83 }
84 }
85"""