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 Code snippet generator for fixed time stepping in the Runge-Kutta schemes
9
10 adaptive_starting_timeStep_size: none, hard, soft
11 """
12 def __init__(self, time_step_relaxation, adaptive_starting_timeStep_size="none"):
13 self._time_step_relaxation = time_step_relaxation
14 self._adaptive_starting_timeStep_size = adaptive_starting_timeStep_size
15
17 return """
18 if (
19 tarch::mpi::Rank::getInstance().isGlobalMaster()
20 and
21 (_maxVolumeH > 0.0 or _maxVolumeHThisTimeStep > 0.0)
22 and
23 isFirstGridSweepOfTimeStep()
24 ) {
25 logInfo("startTimeStep(...)", "Solver {{SOLVER_NAME}}:");
26 logInfo("startTimeStep(...)", "t = " << _minTimeStampThisTimeStep);
27 logInfo("startTimeStep(...)", "dt = " << getAdmissibleTimeStepSize());
28 logInfo("startTimeStep(...)", "h_{min} = " << _minVolumeHThisTimeStep << " (volume size)");
29 logInfo("startTimeStep(...)", "h_{max} = " << _maxVolumeHThisTimeStep << " (volume size)");
30 logInfo("startTimeStep(...)", "lambda_{max} = " << _maxEigenvalue);
31 }
32
33 if (isFirstGridSweepOfTimeStep()) {
34 _maxEigenvalue = 0.0;
35 }
36"""
37
39 """
40 The superclass takes the admissible cell size and divides it by the
41 maximum eigenvalue. The Finite Volume solvers however operate with
42 patches, i.e. we have to divide by the volume count per axis.
43 """
44
45 temp_implementation=super(AdaptiveTimeSteppingCodeSnippets, self).create_finish_time_step_implementation() + """
46 if (
47 isLastGridSweepOfTimeStep()
48 and
49 tarch::la::greater(_maxEigenvalue, 0.0)
50 ) {
51 _admissibleTimeStepSize = """ + str(self._time_step_relaxation) + """ * _minVolumeHThisTimeStep / _maxEigenvalue;
52"""
53
55 temp_implementation +="""
56 if (tarch::la::equals(_minTimeStampThisTimeStep, 0, 1e-8)) {_admissibleTimeStepSize *= 1e-3;}
57 if (CheckpointTimeStamp != 0 and tarch::la::equals(_minTimeStampThisTimeStep, CheckpointTimeStamp, 1e-8)) {_admissibleTimeStepSize *= 1e-3;}
58"""
59 if self._adaptive_starting_timeStep_size == "soft":
60 temp_implementation +="""
61 if (_previousTimeStepSize != 0.0 and _previousTimeStepSize<_admissibleTimeStepSize)
62 {_admissibleTimeStepSize = 0.2*_admissibleTimeStepSize + 0.8*_previousTimeStepSize;}
63 _previousTimeStepSize = _admissibleTimeStepSize;
64"""
65
66 temp_implementation +="""
67 if (std::isnan(_admissibleTimeStepSize) or std::isinf(_admissibleTimeStepSize)) {
68 ::tarch::triggerNonCriticalAssertion( __FILE__, __LINE__, "_admissibleTimeStepSize > 0", "invalid (NaN of inf) time step size: " + std::to_string(_admissibleTimeStepSize) );
69 }
70 if (::tarch::la::smallerEquals(_admissibleTimeStepSize, 0.0, 1e-10)) {
71 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");
72 }
73 }
74"""
75
76 return temp_implementation
77
create_finish_time_step_implementation(self)
This routine is inserted after we have reduced all global quantities.