Merge pull request #662 from dr-robertk/timestepcontrol

Timestepcontrol
This commit is contained in:
Atgeirr Flø Rasmussen 2014-10-20 12:40:21 +02:00
commit 978e32de16
8 changed files with 748 additions and 0 deletions

View File

@ -97,7 +97,9 @@ list (APPEND MAIN_SOURCE_FILES
opm/core/props/satfunc/SatFuncStone2.cpp
opm/core/props/satfunc/SaturationPropsBasic.cpp
opm/core/props/satfunc/SaturationPropsFromDeck.cpp
opm/core/simulator/AdaptiveSimulatorTimer.cpp
opm/core/simulator/BlackoilState.cpp
opm/core/simulator/PIDTimeStepControl.cpp
opm/core/simulator/SimulatorCompressibleTwophase.cpp
opm/core/simulator/SimulatorIncompTwophase.cpp
opm/core/simulator/SimulatorOutput.cpp
@ -333,14 +335,19 @@ list (APPEND PUBLIC_HEADER_FILES
opm/core/props/satfunc/SaturationPropsFromDeck.hpp
opm/core/props/satfunc/SaturationPropsFromDeck_impl.hpp
opm/core/props/satfunc/SaturationPropsInterface.hpp
opm/core/simulator/AdaptiveSimulatorTimer.hpp
opm/core/simulator/AdaptiveTimeStepping.hpp
opm/core/simulator/AdaptiveTimeStepping_impl.hpp
opm/core/simulator/BlackoilState.hpp
opm/core/simulator/EquilibrationHelpers.hpp
opm/core/simulator/PIDTimeStepControl.hpp
opm/core/simulator/SimulatorCompressibleTwophase.hpp
opm/core/simulator/SimulatorIncompTwophase.hpp
opm/core/simulator/SimulatorOutput.hpp
opm/core/simulator/SimulatorReport.hpp
opm/core/simulator/SimulatorState.hpp
opm/core/simulator/SimulatorTimer.hpp
opm/core/simulator/TimeStepControlInterface.hpp
opm/core/simulator/TwophaseState.hpp
opm/core/simulator/TwophaseState_impl.hpp
opm/core/simulator/WellState.hpp

View File

@ -0,0 +1,158 @@
/*
Copyright 2014 IRIS AS
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <opm/core/utility/Units.hpp>
#include <opm/core/simulator/AdaptiveSimulatorTimer.hpp>
namespace Opm
{
AdaptiveSimulatorTimer::
AdaptiveSimulatorTimer( const double start_time, const double total_time, const double lastDt )
: start_time_( start_time )
, total_time_( total_time )
, current_time_( start_time_ )
, dt_( computeInitialTimeStep( lastDt ) )
, current_step_( 0 )
, steps_()
, suggestedMax_( 0.0 )
, suggestedAverage_( 0.0 )
{
// reserve memory for sub steps
steps_.reserve( 10 );
}
AdaptiveSimulatorTimer& AdaptiveSimulatorTimer::operator++ ()
{
++current_step_;
current_time_ += dt_;
// store used time step sizes
steps_.push_back( dt_ );
return *this;
}
void AdaptiveSimulatorTimer::
provideTimeStepEstimate( const double dt_estimate )
{
// store some information about the time steps suggested
suggestedMax_ = std::max( dt_estimate, suggestedMax_ );
suggestedAverage_ += dt_estimate;
double remaining = (total_time_ - current_time_);
if( remaining > 0 ) {
// set new time step (depending on remaining time)
if( 1.5 * dt_estimate > remaining ) {
dt_ = remaining;
return ;
}
// check for half interval step to avoid very small step at the end
// remaining *= 0.5;
if( 2.25 * dt_estimate > remaining ) {
dt_ = 0.5 * remaining;
return ;
}
}
// otherwise set dt_estimate as is
dt_ = dt_estimate;
}
int AdaptiveSimulatorTimer::
currentStepNum () const { return current_step_; }
double AdaptiveSimulatorTimer::currentStepLength () const
{
assert( ! done () );
return dt_;
}
double AdaptiveSimulatorTimer::totalTime() const { return total_time_; }
double AdaptiveSimulatorTimer::simulationTimeElapsed() const { return current_time_; }
bool AdaptiveSimulatorTimer::done () const { return (current_time_ >= total_time_) ; }
double AdaptiveSimulatorTimer::averageStepLength() const
{
const int size = steps_.size();
if( size == 0 ) return 0.0;
const double sum = std::accumulate(steps_.begin(), steps_.end(), 0.0);
return sum / double(size);
}
/// \brief return max step length used so far
double AdaptiveSimulatorTimer::maxStepLength () const
{
if( steps_.size() == 0 ) return 0.0;
return *(std::max_element( steps_.begin(), steps_.end() ));
}
/// \brief return min step length used so far
double AdaptiveSimulatorTimer::minStepLength () const
{
if( steps_.size() == 0 ) return 0.0;
return *(std::min_element( steps_.begin(), steps_.end() ));
}
/// \brief return max suggested step length
double AdaptiveSimulatorTimer::suggestedMax () const { return suggestedMax_; }
/// \brief return average suggested step length
double AdaptiveSimulatorTimer::suggestedAverage () const
{
const int size = steps_.size();
return (size > 0 ) ? (suggestedAverage_ / double(size)) : suggestedAverage_;
}
/// \brief report start and end time as well as used steps so far
void AdaptiveSimulatorTimer::
report(std::ostream& os) const
{
os << "Sub steps started at time = " << unit::convert::to( start_time_, unit::day ) << " (days)" << std::endl;
for( size_t i=0; i<steps_.size(); ++i )
{
os << " step[ " << i << " ] = " << unit::convert::to( steps_[ i ], unit::day ) << " (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

View File

@ -0,0 +1,102 @@
/*
Copyright 2014 IRIS AS
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_ADAPTIVESIMULATORTIMER_HEADER_INCLUDED
#define OPM_ADAPTIVESIMULATORTIMER_HEADER_INCLUDED
#include <cassert>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
namespace Opm
{
/////////////////////////////////////////////////////////
///
/// \brief Simulation timer for adaptive time stepping
///
/////////////////////////////////////////////////////////
class AdaptiveSimulatorTimer
{
public:
/// \brief constructor taking a simulator timer to determine start and end time
/// \param start_time start time of timer
/// \param total_time total time of timer
/// \param lastDt last suggested length of time step interval
AdaptiveSimulatorTimer( const double start_time, const double total_time, const double lastDt );
/// \brief advance time by currentStepLength
AdaptiveSimulatorTimer& operator++ ();
/// \brief provide and estimate for new time step size
void provideTimeStepEstimate( const double dt_estimate );
/// \brief \copydoc SimulationTimer::currentStepNum
int currentStepNum () const;
/// \brief \copydoc SimulationTimer::currentStepLength
double currentStepLength () const;
/// \brief \copydoc SimulationTimer::totalTime
double totalTime() const;
/// \brief \copydoc SimulationTimer::simulationTimeElapsed
double simulationTimeElapsed() const;
/// \brief \copydoc SimulationTimer::done
bool done () const;
/// \brief return average step length used so far
double averageStepLength() const;
/// \brief return max step length used so far
double maxStepLength () const;
/// \brief return min step length used so far
double minStepLength () const;
/// \brief return max suggested step length
double suggestedMax () const;
/// \brief return average suggested step length
double suggestedAverage () const;
/// \brief report start and end time as well as used steps so far
void report(std::ostream& os) const;
protected:
const double start_time_;
const double total_time_;
double current_time_;
double dt_;
int current_step_;
std::vector< double > steps_;
double suggestedMax_;
double suggestedAverage_;
double computeInitialTimeStep( const double lastDt ) const;
};
} // namespace Opm
#endif // OPM_SIMULATORTIMER_HEADER_INCLUDED

View File

@ -0,0 +1,49 @@
#ifndef OPM_SUBSTEPPING_HEADER_INCLUDED
#define OPM_SUBSTEPPING_HEADER_INCLUDED
#include <iostream>
#include <utility>
#include <opm/core/utility/parameters/ParameterGroup.hpp>
#include <opm/core/utility/ErrorMacros.hpp>
#include <opm/core/simulator/TimeStepControlInterface.hpp>
namespace Opm {
// AdaptiveTimeStepping
//---------------------
class AdaptiveTimeStepping
{
public:
//! \brief contructor taking parameter object
AdaptiveTimeStepping( const parameter::ParameterGroup& param );
/** \brief step method that acts like the solver::step method
in a sub cycle of time steps
\param solver solver object that must implement a method step( dt, state, well_state )
\param state current state of the solution variables
\param well_state additional well state object
\param time current simulation time
\param timestep current time step length that is to be sub cycled
*/
template <class Solver, class State, class WellState>
void step( Solver& solver, State& state, WellState& well_state,
const double time, const double timestep );
protected:
typedef std::unique_ptr< TimeStepControlInterface > TimeStepControlType;
TimeStepControlType timeStepControl_; //!< time step control object
const double initial_fraction_; //!< fraction to take as a guess for initial time interval
const double restart_factor_; //!< factor to multiply time step with when solver fails to converge
const int solver_restart_max_; //!< how many restart of solver are allowed
const bool solver_verbose_; //!< solver verbosity
const bool timestep_verbose_; //!< timestep verbosity
double last_timestep_; //!< size of last timestep
};
}
#include <opm/core/simulator/AdaptiveTimeStepping_impl.hpp>
#endif

View File

@ -0,0 +1,146 @@
#ifndef OPM_ADAPTIVETIMESTEPPING_IMPL_HEADER_INCLUDED
#define OPM_ADAPTIVETIMESTEPPING_IMPL_HEADER_INCLUDED
#include <iostream>
#include <string>
#include <utility>
#include <opm/core/simulator/AdaptiveSimulatorTimer.hpp>
#include <opm/core/simulator/PIDTimeStepControl.hpp>
namespace Opm {
// AdaptiveTimeStepping
//---------------------
AdaptiveTimeStepping::AdaptiveTimeStepping( const parameter::ParameterGroup& param )
: timeStepControl_()
, initial_fraction_( param.getDefault("solver.initialfraction", double(0.25) ) )
, restart_factor_( param.getDefault("solver.restartfactor", double(0.1) ) )
, solver_restart_max_( param.getDefault("solver.restart", int(3) ) )
, solver_verbose_( param.getDefault("solver.verbose", bool(false) ) )
, timestep_verbose_( param.getDefault("timestep.verbose", bool(false) ) )
, last_timestep_( -1.0 )
{
// valid are "pid" and "pid+iteration"
std::string control = param.getDefault("timestep.control", std::string("pid") );
const double tol = param.getDefault("timestep.control.tol", double(1e-3) );
if( control == "pid" ) {
timeStepControl_ = TimeStepControlType( new PIDTimeStepControl( tol ) );
}
else if ( control == "pid+iteration" )
{
const int iterations = param.getDefault("timestep.control.targetiteration", int(25) );
timeStepControl_ = TimeStepControlType( new PIDAndIterationCountTimeStepControl( iterations, tol ) );
}
else
OPM_THROW(std::runtime_error,"Unsupported time step control selected "<< control );
}
template <class Solver, class State, class WellState>
void AdaptiveTimeStepping::
step( Solver& solver, State& state, WellState& well_state,
const double time, const double timestep )
{
// init last time step as a fraction of the given time step
if( last_timestep_ < 0 ) {
last_timestep_ = initial_fraction_ * timestep ;
}
// create adaptive step timer with previously used sub step size
AdaptiveSimulatorTimer timer( time, time+timestep, last_timestep_ );
// copy states in case solver has to be restarted (to be revised)
State last_state( state );
WellState last_well_state( well_state );
// counter for solver restarts
int restarts = 0;
// sub step time loop
while( ! timer.done() )
{
// get current delta t
const double dt = timer.currentStepLength() ;
// initialize time step control in case current state is needed later
timeStepControl_->initialize( state );
int linearIterations = -1;
try {
// (linearIterations < 0 means on convergence in solver)
linearIterations = solver.step( dt, state, well_state);
if( solver_verbose_ ) {
// report number of linear iterations
std::cout << "Overall linear iterations used: " << linearIterations << std::endl;
}
}
catch (Opm::NumericalProblem e) {
std::cerr << e.what() << std::endl;
// since linearIterations is < 0 this will restart the solver
}
catch (std::runtime_error e) {
std::cerr << e.what() << std::endl;
// also catch linear solver not converged
}
// (linearIterations < 0 means no convergence in solver)
if( linearIterations >= 0 )
{
// advance by current dt
++timer;
// compute new time step estimate
const double dtEstimate =
timeStepControl_->computeTimeStepSize( dt, linearIterations, state );
if( timestep_verbose_ )
std::cout << "Suggested time step size = " << unit::convert::to(dtEstimate, unit::day) << " (days)" << std::endl;
// set new time step length
timer.provideTimeStepEstimate( dtEstimate );
// update states
last_state = state ;
last_well_state = well_state;
}
else // in case of no convergence (linearIterations < 0)
{
// increase restart counter
if( restarts >= solver_restart_max_ ) {
OPM_THROW(Opm::NumericalProblem,"Solver failed to converge after " << restarts << " restarts.");
}
const double newTimeStep = restart_factor_ * dt;
// we need to revise this
timer.provideTimeStepEstimate( newTimeStep );
if( solver_verbose_ )
std::cerr << "Solver convergence failed, restarting solver with new time step ("
<< unit::convert::to( newTimeStep, unit::day ) <<" days)." << std::endl;
// reset states
state = last_state;
well_state = last_well_state;
++restarts;
}
}
// store last small time step for next reportStep
last_timestep_ = timer.suggestedAverage();
if( timestep_verbose_ )
{
timer.report( std::cout );
std::cout << "Last suggested step size = " << unit::convert::to( last_timestep_, unit::day ) << " (days)" << std::endl;
}
if( ! std::isfinite( last_timestep_ ) ) { // check for NaN
last_timestep_ = timestep;
}
}
}
#endif

View File

@ -0,0 +1,125 @@
/*
Copyright 2014 IRIS AS
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#include <cassert>
#include <cmath>
#include <iostream>
#include <opm/core/utility/Units.hpp>
#include <opm/core/simulator/PIDTimeStepControl.hpp>
namespace Opm
{
PIDTimeStepControl::PIDTimeStepControl( const double tol, const bool verbose )
: p0_()
, sat0_()
, tol_( tol )
, errors_( 3, tol_ )
, verbose_( verbose )
{}
void PIDTimeStepControl::initialize( const SimulatorState& state )
{
// store current state for later time step computation
p0_ = state.pressure();
sat0_ = state.saturation();
}
double PIDTimeStepControl::
computeTimeStepSize( const double dt, const int /* iterations */, const SimulatorState& state ) const
{
const std::size_t pSize = p0_.size();
assert( state.pressure().size() == pSize );
const std::size_t satSize = sat0_.size();
assert( state.saturation().size() == satSize );
// compute u^n - u^n+1
for( std::size_t i=0; i<pSize; ++i ) {
p0_[ i ] -= state.pressure()[ i ];
}
for( std::size_t i=0; i<satSize; ++i ) {
sat0_[ i ] -= state.saturation()[ i ];
}
// compute || u^n - u^n+1 ||
const double stateOld = euclidianNormSquared( p0_.begin(), p0_.end() ) +
euclidianNormSquared( sat0_.begin(), sat0_.end() );
// compute || u^n+1 ||
const double stateNew = euclidianNormSquared( state.pressure().begin(), state.pressure().end() ) +
euclidianNormSquared( state.saturation().begin(), state.saturation().end() );
// shift errors
for( int i=0; i<2; ++i ) {
errors_[ i ] = errors_[i+1];
}
// store new error
const double error = stateOld / stateNew;
errors_[ 2 ] = error ;
if( error > tol_ )
{
// adjust dt by given tolerance
const double newDt = dt * tol_ / error;
if( verbose_ )
std::cout << "Computed step size (tol): " << unit::convert::to( newDt, unit::day ) << " (days)" << std::endl;
return newDt;
}
else
{
// values taking from turek time stepping paper
const double kP = 0.075 ;
const double kI = 0.175 ;
const double kD = 0.01 ;
const double newDt = (dt * std::pow( errors_[ 1 ] / errors_[ 2 ], kP ) *
std::pow( tol_ / errors_[ 2 ], kI ) *
std::pow( errors_[0]*errors_[0]/errors_[ 1 ]/errors_[ 2 ], kD ));
if( verbose_ )
std::cout << "Computed step size (pow): " << unit::convert::to( newDt, unit::day ) << " (days)" << std::endl;
return newDt;
}
}
PIDAndIterationCountTimeStepControl::
PIDAndIterationCountTimeStepControl( const int target_iterations,
const double tol,
const bool verbose)
: BaseType( tol, verbose )
, target_iterations_( target_iterations )
{}
double PIDAndIterationCountTimeStepControl::
computeTimeStepSize( const double dt, const int iterations, const SimulatorState& state ) const
{
double dtEstimate = BaseType :: computeTimeStepSize( dt, iterations, state );
// further reduce step size if to many iterations were used
if( iterations > target_iterations_ )
{
// if iterations was the same or dts were the same, do some magic
dtEstimate *= double( target_iterations_ ) / double(iterations);
}
return dtEstimate;
}
} // end namespace Opm

View File

@ -0,0 +1,108 @@
/*
Copyright 2014 IRIS AS
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_PIDTIMESTEPCONTROL_HEADER_INCLUDED
#define OPM_PIDTIMESTEPCONTROL_HEADER_INCLUDED
#include <vector>
#include <opm/core/simulator/TimeStepControlInterface.hpp>
namespace Opm
{
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///
/// PID controller based adaptive time step control as suggested in:
/// Turek and Kuzmin. Algebraic Flux Correction III. Incompressible Flow Problems. Uni Dortmund.
///
/// See also:
/// D. Kuzmin and S.Turek. Numerical simulation of turbulent bubbly flows. Techreport Uni Dortmund. 2004
///
/// and the original article:
/// Valli, Coutinho, and Carey. Adaptive Control for Time Step Selection in Finite Element
/// Simulation of Coupled Viscous Flow and Heat Transfer. Proc of the 10th
/// International Conference on Numerical Methods in Fluids. 1998.
///
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
class PIDTimeStepControl : public TimeStepControlInterface
{
public:
/// \brief constructor
/// \param tol tolerance for the relative changes of the numerical solution to be accepted
/// in one time step (default is 1e-3)
/// \param verbose if true get some output (default = false)
PIDTimeStepControl( const double tol = 1e-3, const bool verbose = false );
/// \brief \copydoc TimeStepControlInterface::initialize
void initialize( const SimulatorState& state );
/// \brief \copydoc TimeStepControlInterface::computeTimeStepSize
double computeTimeStepSize( const double dt, const int /* iterations */, const SimulatorState& state ) const;
protected:
// return inner product for given container, here std::vector
template <class Iterator>
double euclidianNormSquared( Iterator it, const Iterator end ) const
{
double product = 0.0 ;
for( ; it != end; ++it ) {
product += ( *it * *it );
}
return product;
}
protected:
mutable std::vector<double> p0_;
mutable std::vector<double> sat0_;
const double tol_;
mutable std::vector< double > errors_;
const bool verbose_;
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
///
/// PID controller based adaptive time step control as above that also takes
/// an target iteration into account.
//
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
class PIDAndIterationCountTimeStepControl : public PIDTimeStepControl
{
typedef PIDTimeStepControl BaseType;
public:
/// \brief constructor
/// \param target_iterations number of desired iterations per time step
/// \param tol tolerance for the relative changes of the numerical solution to be accepted
/// in one time step (default is 1e-3)
/// \param verbose if true get some output (default = false)
PIDAndIterationCountTimeStepControl( const int target_iterations = 20,
const double tol = 1e-3,
const bool verbose = false);
/// \brief \copydoc TimeStepControlInterface::computeTimeStepSize
double computeTimeStepSize( const double dt, const int iterations, const SimulatorState& state ) const;
protected:
const int target_iterations_;
};
} // end namespace Opm
#endif

View File

@ -0,0 +1,53 @@
/*
Copyright 2014 IRIS AS
This file is part of the Open Porous Media project (OPM).
OPM is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OPM is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OPM. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPM_TIMESTEPCONTROLINTERFACE_HEADER_INCLUDED
#define OPM_TIMESTEPCONTROLINTERFACE_HEADER_INCLUDED
#include <opm/core/simulator/SimulatorState.hpp>
namespace Opm
{
///////////////////////////////////////////////////////////////////
///
/// TimeStepControlInterface
///
///////////////////////////////////////////////////////////////////
class TimeStepControlInterface
{
protected:
TimeStepControlInterface() {}
public:
/// \param state simulation state before computing update in the solver (default is empty)
virtual void initialize( const SimulatorState& state ) {}
/// compute new time step size suggestions based on the PID controller
/// \param dt time step size used in the current step
/// \param iterations number of iterations used (linear/nonlinear)
/// \param state new solution state
///
/// \return suggested time step size for the next step
virtual double computeTimeStepSize( const double dt, const int iterations, const SimulatorState& ) const = 0;
/// virtual destructor (empty)
virtual ~TimeStepControlInterface () {}
};
}
#endif