Commit dbd4ccf5 authored by Lukas Riedel's avatar Lukas Riedel

fixed bug where time step could become negative. Controller can now deal with last changeTime=tEnd

parent bb5573a1
...@@ -14,8 +14,8 @@ private: ...@@ -14,8 +14,8 @@ private:
R dt; //!< current time step R dt; //!< current time step
int it; //!< current number of allowed iterations for Newton solver int it; //!< current number of allowed iterations for Newton solver
int verbose; //!< verbosity level int verbose; //!< verbosity level
const R eps; //!< error margin
const R dtmax, dtmin; //!< time step limits const R dtmax, dtmin; //!< time step limits
const R eps; //!< error margin
const R dtinc, dtdec; //!< time step mutliplicators const R dtinc, dtdec; //!< time step mutliplicators
R tEnd; //!< simulation time limits R tEnd; //!< simulation time limits
const R itmax,itmin; //!< newton iteration limits const R itmax,itmin; //!< newton iteration limits
...@@ -32,9 +32,9 @@ public: ...@@ -32,9 +32,9 @@ public:
: time(config.get<R>("time.start")) : time(config.get<R>("time.start"))
, dt(config.get<R>("time.startTimestep")) , dt(config.get<R>("time.startTimestep"))
, verbose(config.get<int>("output.verbose")) , verbose(config.get<int>("output.verbose"))
, eps(1e-5)
, dtmax(config.get<R>("time.maxTimestep")) , dtmax(config.get<R>("time.maxTimestep"))
, dtmin(config.get<R>("time.minTimestep")) , dtmin(config.get<R>("time.minTimestep"))
, eps(dtmin/10.0)
, dtinc(config.get<R>("time.timestepIncreaseFactor")) , dtinc(config.get<R>("time.timestepIncreaseFactor"))
, dtdec(config.get<R>("time.timestepDecreaseFactor")) , dtdec(config.get<R>("time.timestepDecreaseFactor"))
, tEnd(config.get<R>("time.end")) , tEnd(config.get<R>("time.end"))
...@@ -48,8 +48,8 @@ public: ...@@ -48,8 +48,8 @@ public:
userInputCheck(); userInputCheck();
// Check whether first time step needs adjustment // Check whether first time step needs adjustment
R changeTime = tsc.getNextTimeStamp(time); const R changeTime = tsc.getNextTimeStamp(time);
if(changeTime>0.0 && changeTime-time < dt){ if(changeTime>0.0 && time+dt >= changeTime){
dt = changeTime-time-eps; dt = changeTime-time-eps;
if(verbose>2){ if(verbose>2){
std::cout << "ADAPTING TIME STEP: DT : " std::cout << "ADAPTING TIME STEP: DT : "
...@@ -106,26 +106,26 @@ public: ...@@ -106,26 +106,26 @@ public:
if (!exc) // solution was successfully computed if (!exc) // solution was successfully computed
{ {
// time has advanced after calculation // time has advanced after calculation
time+=dt; time += dt;
if(time>=tEnd) // Simulation has ended. Do nothing if(time >= tEnd-eps) // Simulation has ended. Do nothing
return true; return true;
dt = std::min(dt*dtinc,dtmax); dt = std::min(dt*dtinc,dtmax);
changeTime = tsc.getNextTimeStamp(time); changeTime = tsc.getNextTimeStamp(time);
if(changeTime==time+eps){ if(time >= changeTime-eps && time <= changeTime){
// small step to ensure that next time step starts with new BC // small step to ensure that next time step starts with new BC
time = changeTime; time = changeTime;
changeTime = tsc.getNextTimeStamp(time); changeTime = tsc.getNextTimeStamp(time);
} }
if(changeTime<0.0 && time+dt>tEnd){ if(changeTime < 0.0 && time+dt > tEnd){
// time step adjustment to tEnd // time step adjustment to tEnd
dt = tEnd-time; dt = tEnd-time;
adapt_to_end = true; adapt_to_end = true;
} }
else if(changeTime>0.0 && time+dt>=changeTime){ else if(changeTime > 0.0 && time+dt >= changeTime){
// time step adjustment to BC Change // time step adjustment to BC Change
dt = changeTime-time-eps; dt = changeTime-time-eps;
adapt_to_bc = true; adapt_to_bc = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment