Peano
Loading...
Searching...
No Matches
AdaptiveTimeSteppingCodeSnippets.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 adaptive_starting_timeStep_size: none, hard, soft
12
13 """
14 def __init__(self, time_step_relaxation, adaptive_starting_timeStep_size="none"):
15 self._time_step_relaxation = time_step_relaxation
16 self._adaptive_starting_timeStep_size = adaptive_starting_timeStep_size
17
18
20 return """
21 if (
22 tarch::mpi::Rank::getInstance().isGlobalMaster()
23 and
24 _maxGridCellHThisTimeStep>0.0
25 and
26 isFirstGridSweepOfTimeStep()
27 ) {
28 logInfo( "startTimeStep()", "Solver {{SOLVER_NAME}}:" );
29 logInfo( "startTimeStep()", "t = " << _minTimeStampThisTimeStep );
30 logInfo( "startTimeStep()", "dt = " << getAdmissibleTimeStepSize() );
31 logInfo( "startTimeStep()", "h_{min} = " << _minGridCellHThisTimeStep << " (individual grid cell within a patch)");
32 logInfo( "startTimeStep()", "h_{max} = " << _maxGridCellHThisTimeStep << " (individual grid cell within a patch)" );
33 logInfo( "startTimeStep()", "lambda_{max} = " << _maxEigenvalue );
34 }
35
36 if (isFirstGridSweepOfTimeStep()) {
37 _maxEigenvalue = 0.0;
38 }
39"""
40
41
43 """
44
45 The superclass takes the admissible cell size and divides it by the
46 maximum eigenvalue.
47
48 """
49
50 temp_implementation=super( AdaptiveTimeSteppingCodeSnippets, self ).create_finish_time_step_implementation() + """
51 if (
52 isLastGridSweepOfTimeStep()
53 and
54 tarch::la::greater(_maxEigenvalue, 0.0 )
55 ) {
56 _admissibleTimeStepSize = """ + str(self._time_step_relaxation) + """ * _minGridCellHThisTimeStep / _maxEigenvalue / (2*{{RK_ORDER}}-1);
57"""
58
60 temp_implementation +="""
61 if (tarch::la::equals(_minTimeStampThisTimeStep, 0, 1e-8)) {_admissibleTimeStepSize *= 1e-3;}
62 if (CheckpointTimeStamp != 0 and tarch::la::equals(_minTimeStampThisTimeStep, CheckpointTimeStamp, 1e-8)) {_admissibleTimeStepSize *= 1e-3;}
63"""
64 if self._adaptive_starting_timeStep_size == "soft":
65 temp_implementation +="""
66 if (_previousTimeStepSize != 0.0 and _previousTimeStepSize<_admissibleTimeStepSize)
67 {_admissibleTimeStepSize = 0.2*_admissibleTimeStepSize + 0.8*_previousTimeStepSize;}
68 _previousTimeStepSize = _admissibleTimeStepSize;
69"""
70
71 temp_implementation +="""
72 if ( std::isnan(_admissibleTimeStepSize) or std::isinf(_admissibleTimeStepSize) ) {
73 ::tarch::triggerNonCriticalAssertion( __FILE__, __LINE__, "_admissibleTimeStepSize>0", "invalid (NaN of inf) time step size: " + std::to_string(_admissibleTimeStepSize) );
74 }
75 if (tarch::la::smallerEquals(_admissibleTimeStepSize,0.0,1e-10) ) {
76 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" );
77 }
78 }
79"""
80 return temp_implementation
create_finish_time_step_implementation(self)
This routine is inserted after we have reduced all global quantities.