use unit::convert::to instead of hard coded 86400 factor.

This commit is contained in:
Robert Kloefkorn 2014-10-07 09:48:57 +02:00
parent 355e68c63b
commit b250383ae0
4 changed files with 29 additions and 23 deletions

View File

@ -24,6 +24,7 @@
#include <algorithm> #include <algorithm>
#include <numeric> #include <numeric>
#include <opm/core/utility/Units.hpp>
#include <opm/core/simulator/AdaptiveSimulatorTimer.hpp> #include <opm/core/simulator/AdaptiveSimulatorTimer.hpp>
namespace Opm namespace Opm
@ -131,15 +132,27 @@ namespace Opm
} }
/// \brief report start and end time as well as used steps so far /// \brief report start and end time as well as used steps so far
void AdaptiveSimulatorTimer::report(std::ostream& os) const void AdaptiveSimulatorTimer::
report(std::ostream& os) const
{ {
const double factor = 86400.0; os << "Sub steps started at time = " << unit::convert::to( start_time_, unit::day ) << " (days)" << std::endl;
os << "Sub steps started at time = " << start_time_/factor << " (days)" << std::endl;
for( size_t i=0; i<steps_.size(); ++i ) for( size_t i=0; i<steps_.size(); ++i )
{ {
os << " step[ " << i << " ] = " << steps_[ i ]/factor << " (days)" << std::endl; os << " step[ " << i << " ] = " << unit::convert::to( steps_[ i ], unit::day ) << " (days)" << std::endl;
} }
std::cout << "sub steps end time = " << simulationTimeElapsed()/factor << " (days)" << std::endl; std::cout << "sub steps end time = " << unit::convert::to( simulationTimeElapsed(), unit::day ) << " (days)" << std::endl;
}
double AdaptiveSimulatorTimer::
computeInitialTimeStep( const double lastDt ) const
{
const double maxTimeStep = total_time_ - start_time_;
const double fraction = (lastDt / maxTimeStep);
// when lastDt and maxTimeStep are close together, choose the max time step
if( fraction > 0.95 ) return maxTimeStep;
// otherwise choose lastDt
return std::min( lastDt, maxTimeStep );
} }
} // namespace Opm } // namespace Opm

View File

@ -94,16 +94,7 @@ namespace Opm
double suggestedMax_; double suggestedMax_;
double suggestedAverage_; double suggestedAverage_;
double computeInitialTimeStep( const double lastDt ) const double computeInitialTimeStep( const double lastDt ) const;
{
const double maxTimeStep = total_time_ - start_time_;
const double fraction = (lastDt / maxTimeStep);
// when lastDt and maxTimeStep are close together, choose the max time step
if( fraction > 0.95 ) return maxTimeStep;
// otherwise choose lastDt
return std::min( lastDt, maxTimeStep );
}
}; };
} // namespace Opm } // namespace Opm

View File

@ -83,7 +83,7 @@ namespace Opm {
const double dtEstimate = const double dtEstimate =
timeStepControl_->computeTimeStepSize( timer.currentStepLength(), linearIterations, state ); timeStepControl_->computeTimeStepSize( timer.currentStepLength(), linearIterations, state );
if( timestep_verbose_ ) if( timestep_verbose_ )
std::cout << "Suggested time step size = " << dtEstimate/86400.0 << " (days)" << std::endl; std::cout << "Suggested time step size = " << unit::convert::to(dtEstimate, unit::day) << " (days)" << std::endl;
// set new time step length // set new time step length
timer.provideTimeStepEstimate( dtEstimate ); timer.provideTimeStepEstimate( dtEstimate );
@ -119,7 +119,7 @@ namespace Opm {
if( timestep_verbose_ ) if( timestep_verbose_ )
{ {
timer.report( std::cout ); timer.report( std::cout );
std::cout << "Last suggested step size = " << last_timestep_/86400.0 << " (days)" << std::endl; std::cout << "Last suggested step size = " << unit::convert::to( last_timestep_, unit::day ) << " (days)" << std::endl;
} }
if( ! std::isfinite( last_timestep_ ) ) // check for NaN if( ! std::isfinite( last_timestep_ ) ) // check for NaN

View File

@ -21,6 +21,7 @@
#include <cmath> #include <cmath>
#include <iostream> #include <iostream>
#include <opm/core/utility/Units.hpp>
#include <opm/core/simulator/PIDTimeStepControl.hpp> #include <opm/core/simulator/PIDTimeStepControl.hpp>
namespace Opm namespace Opm
@ -74,9 +75,10 @@ namespace Opm
if( error > tol_ ) if( error > tol_ )
{ {
// adjust dt by given tolerance // adjust dt by given tolerance
const double newDt = dt * tol_ / error;
if( verbose_ ) if( verbose_ )
std::cout << "Computed step size (tol): " << (dt * tol_ / error )/86400.0 << " (days)" << std::endl; std::cout << "Computed step size (tol): " << unit::convert::to( newDt, unit::day ) << " (days)" << std::endl;
return (dt * tol_ / error ); return newDt;
} }
else else
{ {
@ -84,11 +86,11 @@ namespace Opm
const double kP = 0.075 ; const double kP = 0.075 ;
const double kI = 0.175 ; const double kI = 0.175 ;
const double kD = 0.01 ; const double kD = 0.01 ;
double newDt = (dt * std::pow( errors_[ 1 ] / errors_[ 2 ], kP ) * const double newDt = (dt * std::pow( errors_[ 1 ] / errors_[ 2 ], kP ) *
std::pow( tol_ / errors_[ 2 ], kI ) * std::pow( tol_ / errors_[ 2 ], kI ) *
std::pow( errors_[0]*errors_[0]/errors_[ 1 ]/errors_[ 2 ], kD )); std::pow( errors_[0]*errors_[0]/errors_[ 1 ]/errors_[ 2 ], kD ));
if( verbose_ ) if( verbose_ )
std::cout << "Computed step size (pow): " << newDt/86400.0 << " (days)" << std::endl; std::cout << "Computed step size (pow): " << unit::convert::to( newDt, unit::day ) << " (days)" << std::endl;
return newDt; return newDt;
} }
} }