From aa6710901e003434dbee0e060217a396ac6e538c Mon Sep 17 00:00:00 2001 From: henry <Henry Weller h.weller@opencfd.co.uk> Date: Tue, 17 Feb 2009 22:00:59 +0000 Subject: [PATCH] Added Time::loop() to allow the while(runTime.loop()) { ... } idiom. Demonstrated in the shallowWaterFoam solver. --- .../shallowWaterFoam/shallowWaterFoam.C | 4 +--- src/OpenFOAM/db/Time/Time.C | 13 +++++++++++++ src/OpenFOAM/db/Time/Time.H | 17 ++++++++++++++++- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/applications/solvers/incompressible/shallowWaterFoam/shallowWaterFoam.C b/applications/solvers/incompressible/shallowWaterFoam/shallowWaterFoam.C index 5a031c63523..4b9c2311807 100644 --- a/applications/solvers/incompressible/shallowWaterFoam/shallowWaterFoam.C +++ b/applications/solvers/incompressible/shallowWaterFoam/shallowWaterFoam.C @@ -48,10 +48,8 @@ int main(int argc, char *argv[]) Info<< "\nStarting time loop\n" << endl; - while (runTime.run()) + while (runTime.loop()) { - runTime++; - Info<< "\n Time = " << runTime.timeName() << nl << endl; #include "readPISOControls.H" diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index f52303220f2..0a3cbedc187 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -507,6 +507,19 @@ bool Foam::Time::run() const } +bool Foam::Time::loop() +{ + bool running = run(); + + if (running) + { + operator++(); + } + + return running; +} + + bool Foam::Time::end() const { return value() > (endTime_ + 0.5*deltaT_); diff --git a/src/OpenFOAM/db/Time/Time.H b/src/OpenFOAM/db/Time/Time.H index 70f6985b414..261d9eb0a23 100644 --- a/src/OpenFOAM/db/Time/Time.H +++ b/src/OpenFOAM/db/Time/Time.H @@ -352,7 +352,7 @@ public: // also invokes the functionObjectList::end() method // when the time goes out of range // @note - // For correct baheviour, the following style of time-loop + // For correct behaviour, the following style of time-loop // is recommended: // @code // while (runTime.run()) @@ -364,6 +364,21 @@ public: // @endcode virtual bool run() const; + //- Return true if run should continue and if so increment time + // also invokes the functionObjectList::end() method + // when the time goes out of range + // @note + // For correct behaviour, the following style of time-loop + // is recommended: + // @code + // while (runTime.loop()) + // { + // solve; + // runTime.write(); + // } + // @endcode + virtual bool loop(); + //- Return true if end of run, // does not invoke any functionObject methods // @note -- GitLab