From 8ede7fdda49613fa406b0cb3f306f9f0c22b8974 Mon Sep 17 00:00:00 2001 From: Sergio Ferraris Date: Wed, 5 Oct 2011 13:37:07 +0100 Subject: [PATCH 01/30] ENH: Changing Yt to "calculated" to avoid division by zero --- .../multiComponentMixture/multiComponentMixture.C | 3 ++- .../fireFoam/les/oppositeBurningPanels/0/N2 | 15 +++++---------- .../combustion/fireFoam/les/smallPoolFire2D/0/N2 | 13 ++++--------- .../combustion/fireFoam/les/smallPoolFire3D/0/N2 | 13 ++++--------- .../reactingFoam/ras/counterFlowFlame2D/0/N2 | 11 +++-------- 5 files changed, 18 insertions(+), 37 deletions(-) diff --git a/src/thermophysicalModels/reactionThermo/mixtures/multiComponentMixture/multiComponentMixture.C b/src/thermophysicalModels/reactionThermo/mixtures/multiComponentMixture/multiComponentMixture.C index 394e35e536..d5707fe8fd 100644 --- a/src/thermophysicalModels/reactionThermo/mixtures/multiComponentMixture/multiComponentMixture.C +++ b/src/thermophysicalModels/reactionThermo/mixtures/multiComponentMixture/multiComponentMixture.C @@ -49,7 +49,8 @@ const ThermoType& Foam::multiComponentMixture::constructSpeciesData template void Foam::multiComponentMixture::correctMassFractions() { - volScalarField Yt("Yt", Y_[0]); + // It changes Yt patches to "calculated" + volScalarField Yt("Yt", 1.0*Y_[0]); for (label n=1; n Date: Wed, 5 Oct 2011 17:31:12 +0100 Subject: [PATCH 02/30] ENH: Time: secondary write controls, signal handling --- etc/controlDict | 5 + src/OSspecific/POSIX/Make/files | 2 + .../POSIX/signals/sigStopAtWriteNow.C | 140 ++++++++++++++++++ .../POSIX/signals/sigStopAtWriteNow.H | 99 +++++++++++++ src/OSspecific/POSIX/signals/sigWriteNow.C | 122 +++++++++++++++ src/OSspecific/POSIX/signals/sigWriteNow.H | 99 +++++++++++++ src/OpenFOAM/db/Time/Time.C | 131 ++++++++++++++-- src/OpenFOAM/db/Time/Time.H | 30 +++- src/OpenFOAM/db/Time/TimeIO.C | 45 ++++++ .../icoFoam/cavity/system/controlDict | 4 + 10 files changed, 664 insertions(+), 13 deletions(-) create mode 100644 src/OSspecific/POSIX/signals/sigStopAtWriteNow.C create mode 100644 src/OSspecific/POSIX/signals/sigStopAtWriteNow.H create mode 100644 src/OSspecific/POSIX/signals/sigWriteNow.C create mode 100644 src/OSspecific/POSIX/signals/sigWriteNow.H diff --git a/etc/controlDict b/etc/controlDict index c367f5d853..7a14e9036c 100644 --- a/etc/controlDict +++ b/etc/controlDict @@ -58,6 +58,11 @@ OptimisationSwitches commsType nonBlocking; //scheduled; //blocking; floatTransfer 0; nProcsSimpleSum 0; + + // Force dumping (at next timestep) upon signal (-1 to disable) + writeNowSignal -1; //10; + // Force dumping (at next timestep) upon signal (-1 to disable) and exit + stopAtWriteNowSignal -1; } diff --git a/src/OSspecific/POSIX/Make/files b/src/OSspecific/POSIX/Make/files index c7396b6345..90dc5bc92e 100644 --- a/src/OSspecific/POSIX/Make/files +++ b/src/OSspecific/POSIX/Make/files @@ -2,6 +2,8 @@ signals/sigFpe.C signals/sigSegv.C signals/sigInt.C signals/sigQuit.C +signals/sigStopAtWriteNow.C +signals/sigWriteNow.C regExp.C timer.C fileStat.C diff --git a/src/OSspecific/POSIX/signals/sigStopAtWriteNow.C b/src/OSspecific/POSIX/signals/sigStopAtWriteNow.C new file mode 100644 index 0000000000..09d862ca5d --- /dev/null +++ b/src/OSspecific/POSIX/signals/sigStopAtWriteNow.C @@ -0,0 +1,140 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "sigStopAtWriteNow.H" +#include "error.H" +#include "JobInfo.H" +#include "IOstreams.H" +#include "Time.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +// Signal number to catch +int Foam::sigStopAtWriteNow::signal_ +( + debug::optimisationSwitch("stopAtWriteNowSignal", -1) +); + +static Foam::Time const* runTimePtr_ = NULL; + + +struct sigaction Foam::sigStopAtWriteNow::oldAction_; + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::sigStopAtWriteNow::sigHandler(int) +{ + // Reset old handling + if (sigaction(signal_, &oldAction_, NULL) < 0) + { + FatalErrorIn + ( + "Foam::sigStopAtWriteNow::sigHandler(int)" + ) << "Cannot reset " << signal_ << " trapping" + << abort(FatalError); + } + + // Update jobInfo file + jobInfo.signalEnd(); + + Info<< "sigStopAtWriteNow :" + << " setting up write and stop at end of the next iteration" + << nl << endl; + runTimePtr_->stopAt(Time::saWriteNow); + + //// Throw signal (to old handler) + //raise(signal_); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::sigStopAtWriteNow::sigStopAtWriteNow(){} + + +Foam::sigStopAtWriteNow::sigStopAtWriteNow +( + const bool verbose, + const Time& runTime +) +{ + if (signal_ > 0) + { + // Store runTime + runTimePtr_ = &runTime; + + struct sigaction newAction; + newAction.sa_handler = sigHandler; + newAction.sa_flags = SA_NODEFER; + sigemptyset(&newAction.sa_mask); + if (sigaction(signal_, &newAction, &oldAction_) < 0) + { + FatalErrorIn + ( + "Foam::sigStopAtWriteNow::sigStopAtWriteNow" + "(const bool, const Time&)" + ) << "Cannot set " << signal_ << " trapping" + << abort(FatalError); + } + + if (verbose) + { + Info<< "sigStopAtWriteNow :" + << " Enabling writing and stopping upon signal " << signal_ + << endl; + } + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::sigStopAtWriteNow::~sigStopAtWriteNow() +{ + // Reset old handling + if (signal_ > 0) + { + if (sigaction(signal_, &oldAction_, NULL) < 0) + { + FatalErrorIn + ( + "Foam::sigStopAtWriteNow::~sigStopAtWriteNow()" + ) << "Cannot reset " << signal_ << " trapping" + << abort(FatalError); + } + } +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::sigStopAtWriteNow::active() const +{ + return signal_ > 0; +} + + +// ************************************************************************* // diff --git a/src/OSspecific/POSIX/signals/sigStopAtWriteNow.H b/src/OSspecific/POSIX/signals/sigStopAtWriteNow.H new file mode 100644 index 0000000000..4c07248eb2 --- /dev/null +++ b/src/OSspecific/POSIX/signals/sigStopAtWriteNow.H @@ -0,0 +1,99 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see . + +Class + Foam::sigStopAtWriteNow + +Description + Signal handler for interupt defined by + OptimisationSwitches::stopAtWriteNowSignal + + Write and stop the job. + +SourceFiles + sigStopAtWriteNow.C + +\*---------------------------------------------------------------------------*/ + +#ifndef sigStopAtWriteNow_H +#define sigStopAtWriteNow_H + +#include + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class Time; + +/*---------------------------------------------------------------------------*\ + Class sigStopAtWriteNow Declaration +\*---------------------------------------------------------------------------*/ + +class sigStopAtWriteNow +{ + // Private data + + //- number of signal to use + static int signal_; + + //- Saved old signal trapping setting + static struct sigaction oldAction_; + + // Private Member Functions + + static void sigHandler(int); + + +public: + + // Constructors + + //- Construct null + sigStopAtWriteNow(); + + //- Construct from components + sigStopAtWriteNow(const bool verbose, const Time& runTime); + + + //- Destructor + ~sigStopAtWriteNow(); + + + // Member functions + + //- Is active? + bool active() const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OSspecific/POSIX/signals/sigWriteNow.C b/src/OSspecific/POSIX/signals/sigWriteNow.C new file mode 100644 index 0000000000..6ad98a6190 --- /dev/null +++ b/src/OSspecific/POSIX/signals/sigWriteNow.C @@ -0,0 +1,122 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see . + +\*---------------------------------------------------------------------------*/ + +#include "sigWriteNow.H" +#include "error.H" +#include "JobInfo.H" +#include "IOstreams.H" +#include "Time.H" + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +// Signal number to catch +int Foam::sigWriteNow::signal_ +( + debug::optimisationSwitch("writeNowSignal", -1) +); + +static Foam::Time* runTimePtr_ = NULL; + + +struct sigaction Foam::sigWriteNow::oldAction_; + + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::sigWriteNow::sigHandler(int) +{ + Info<< "sigWriteNow :" + << " setting up write at end of the next iteration" << nl << endl; + runTimePtr_->writeOnce(); + + //// Throw signal (to old handler) + //raise(signal_); +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::sigWriteNow::sigWriteNow() +{} + + +Foam::sigWriteNow::sigWriteNow(const bool verbose, Time& runTime) +{ + if (signal_ >= 0) + { + // Store runTime + runTimePtr_ = &runTime; + + struct sigaction newAction; + newAction.sa_handler = sigHandler; + newAction.sa_flags = SA_NODEFER; + sigemptyset(&newAction.sa_mask); + if (sigaction(signal_, &newAction, &oldAction_) < 0) + { + FatalErrorIn + ( + "Foam::sigWriteNow::sigWriteNow(const bool, const Time&)" + ) << "Cannot set " << signal_ << " trapping" + << abort(FatalError); + } + + if (verbose) + { + Info<< "sigWriteNow :" + << " Enabling writing upon signal " << signal_ + << endl; + } + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::sigWriteNow::~sigWriteNow() +{ + // Reset old handling + if (signal_ > 0) + { + if (sigaction(signal_, &oldAction_, NULL) < 0) + { + FatalErrorIn + ( + "Foam::sigWriteNow::~sigWriteNow()" + ) << "Cannot reset " << signal_ << " trapping" + << abort(FatalError); + } + } +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::sigWriteNow::active() const +{ + return signal_ > 0; +} + + +// ************************************************************************* // diff --git a/src/OSspecific/POSIX/signals/sigWriteNow.H b/src/OSspecific/POSIX/signals/sigWriteNow.H new file mode 100644 index 0000000000..871b980edd --- /dev/null +++ b/src/OSspecific/POSIX/signals/sigWriteNow.H @@ -0,0 +1,99 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM 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. + + OpenFOAM 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 OpenFOAM. If not, see . + +Class + Foam::sigWriteNow + +Description + Signal handler for interupt defined by OptimisationSwitches::writeNowSignal + + Write once and continue. + +SourceFiles + sigWriteNow.C + +\*---------------------------------------------------------------------------*/ + +#ifndef sigWriteNow_H +#define sigWriteNow_H + +#include + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +class Time; + +/*---------------------------------------------------------------------------*\ + Class sigWriteNow Declaration +\*---------------------------------------------------------------------------*/ + +class sigWriteNow +{ + // Private data + + //- number of signal to use + static int signal_; + + //- Saved old signal trapping setting + static struct sigaction oldAction_; + + // Private Member Functions + + static void sigHandler(int); + + +public: + + // Constructors + + //- Construct null + sigWriteNow(); + + //- Construct from components + sigWriteNow(const bool verbose, Time& runTime); + + + //- Destructor + ~sigWriteNow(); + + + // Member functions + + //- Is active? + bool active() const; + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/OpenFOAM/db/Time/Time.C b/src/OpenFOAM/db/Time/Time.C index 727f21c98c..0051d23153 100644 --- a/src/OpenFOAM/db/Time/Time.C +++ b/src/OpenFOAM/db/Time/Time.C @@ -81,10 +81,17 @@ void Foam::Time::adjustDeltaT() { if (writeControl_ == wcAdjustableRunTime) { + scalar interval = writeInterval_; + if (secondaryWriteControl_ == wcAdjustableRunTime) + { + interval = min(interval, secondaryWriteInterval_); + } + + scalar timeToNextWrite = max ( 0.0, - (outputTimeIndex_ + 1)*writeInterval_ - (value() - startTime_) + (outputTimeIndex_ + 1)*interval - (value() - startTime_) ); scalar nSteps = timeToNextWrite/deltaT_ - SMALL; @@ -252,8 +259,13 @@ Foam::Time::Time stopAt_(saEndTime), writeControl_(wcTimeStep), writeInterval_(GREAT), + secondaryWriteControl_(wcTimeStep), + secondaryWriteInterval_(labelMax), purgeWrite_(0), + writeOnce_(false), subCycling_(false), + sigWriteNow_(true, *this), + sigStopAtWriteNow_(true, *this), writeFormat_(IOstream::ASCII), writeVersion_(IOstream::currentVersion), @@ -339,8 +351,13 @@ Foam::Time::Time stopAt_(saEndTime), writeControl_(wcTimeStep), writeInterval_(GREAT), + secondaryWriteControl_(wcTimeStep), + secondaryWriteInterval_(labelMax), purgeWrite_(0), + writeOnce_(false), subCycling_(false), + sigWriteNow_(true, *this), + sigStopAtWriteNow_(true, *this), writeFormat_(IOstream::ASCII), writeVersion_(IOstream::currentVersion), @@ -429,8 +446,13 @@ Foam::Time::Time stopAt_(saEndTime), writeControl_(wcTimeStep), writeInterval_(GREAT), + secondaryWriteControl_(wcTimeStep), + secondaryWriteInterval_(labelMax), purgeWrite_(0), + writeOnce_(false), subCycling_(false), + sigWriteNow_(true, *this), + sigStopAtWriteNow_(true, *this), writeFormat_(IOstream::ASCII), writeVersion_(IOstream::currentVersion), @@ -521,7 +543,10 @@ Foam::Time::Time stopAt_(saEndTime), writeControl_(wcTimeStep), writeInterval_(GREAT), + secondaryWriteControl_(wcTimeStep), + secondaryWriteInterval_(labelMax), purgeWrite_(0), + writeOnce_(false), subCycling_(false), writeFormat_(IOstream::ASCII), @@ -944,6 +969,35 @@ Foam::Time& Foam::Time::operator++() if (!subCycling_) { + if (sigStopAtWriteNow_.active() || sigWriteNow_.active()) + { + // A signal might have been sent on one processor only + // Reduce so all decide the same. + + label flag = 0; + if (sigStopAtWriteNow_.active() && stopAt_ == saWriteNow) + { + flag += 1; + } + if (sigWriteNow_.active() && writeOnce_) + { + flag += 2; + } + reduce(flag, maxOp