diff --git a/etc/config/settings.csh b/etc/config/settings.csh index 93f3e506abdff716446fbfd173f00d76a5e42fb6..fbb9f042702ac6f4bcad21b1c304ae251e8d7cdf 100644 --- a/etc/config/settings.csh +++ b/etc/config/settings.csh @@ -487,9 +487,31 @@ case QSMPI: breaksw case SGIMPI: - setenv FOAM_MPI ${MPI_ROOT##*/} + if ( ! $?MPI_ROOT) setenv MPI_ROOT /dummy + + if ( ! -d "$MPI_ROOT" ) then + echo "Warning in $WM_PROJECT_DIR/etc/config/settings.csh:" + echo " MPI_ROOT not a valid mpt installation directory." + echo " Please set MPI_ROOT to the mpt installation directory." + echo " (usually done by loading the mpt module)" + echo " MPI_ROOT currently set to '$MPI_ROOT'" + endif + + if ( "${MPI_ROOT:h}/" == $MPI_ROOT ) then + setenv MPI_ROOT ${MPI_ROOT:h} + endif + + setenv FOAM_MPI ${MPI_ROOT:t} setenv MPI_ARCH_PATH $MPI_ROOT + + if ($?FOAM_VERBOSE && $?prompt) then + echo "Using SGI MPT:" + echo " MPI_ROOT : $MPI_ROOT" + echo " FOAM_MPI : $FOAM_MPI" + endif + + _foamAddPath $MPI_ARCH_PATH/bin _foamAddLib $MPI_ARCH_PATH/lib breaksw diff --git a/etc/config/settings.sh b/etc/config/settings.sh index 5111ef405a3152cf02d526e1322127e6a346e0a3..837dc7c5f9a938d1afce3b2367cc7a344784b805 100644 --- a/etc/config/settings.sh +++ b/etc/config/settings.sh @@ -511,9 +511,30 @@ QSMPI) ;; SGIMPI) + lastCharID=$(( ${#MPI_ROOT} - 1 )) + if [ "${MPI_ROOT:$lastCharID:1}" == '/' ] + then + MPI_ROOT=${MPI_ROOT:0:$lastCharID} + fi + export FOAM_MPI=${MPI_ROOT##*/} export MPI_ARCH_PATH=$MPI_ROOT + if [ -d "$MPI_ROOT" -o -z "$MPI_ARCH_PATH" ] + then + echo "Warning in $WM_PROJECT_DIR/etc/config/settings.sh:" 1>&2 + echo " MPI_ROOT not a valid mpt installation directory or ending in a '/'." 1>&2 + echo " Please set MPI_ROOT to the mpt installation directory." 1>&2 + echo " MPI_ROOT currently set to '$MPI_ROOT'" 1>&2 + fi + + if [ "$FOAM_VERBOSE" -a "$PS1" ] + then + echo "Using SGI MPT:" + echo " MPI_ROOT : $MPI_ROOT" + echo " FOAM_MPI : $FOAM_MPI" + fi + _foamAddPath $MPI_ARCH_PATH/bin _foamAddLib $MPI_ARCH_PATH/lib ;; diff --git a/etc/controlDict b/etc/controlDict index c367f5d85329c3751b5297a6ae88008d9d531b66..7a14e9036c0c1e10af492423710bf0cf488fdbf0 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 c7396b63452db5569a2c52116371d2fa3e50aaba..90dc5bc92ec2924ed922296b620d8be742091f91 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/POSIX.C b/src/OSspecific/POSIX/POSIX.C index 7ab46939cdbe5b08aaacd6f64eca01aaf5392254..e214e7eecabcf09054838adbc52bfe67ab84a420 100644 --- a/src/OSspecific/POSIX/POSIX.C +++ b/src/OSspecific/POSIX/POSIX.C @@ -123,7 +123,7 @@ bool Foam::setEnv } -Foam::word Foam::hostName(bool full) +Foam::string Foam::hostName(bool full) { char buf[128]; ::gethostname(buf, sizeof(buf)); @@ -142,7 +142,7 @@ Foam::word Foam::hostName(bool full) } -Foam::word Foam::domainName() +Foam::string Foam::domainName() { char buf[128]; ::gethostname(buf, sizeof(buf)); @@ -159,11 +159,11 @@ Foam::word Foam::domainName() } } - return word::null; + return string::null; } -Foam::word Foam::userName() +Foam::string Foam::userName() { struct passwd* pw = ::getpwuid(::getuid()); @@ -173,7 +173,7 @@ Foam::word Foam::userName() } else { - return word::null; + return string::null; } } @@ -209,7 +209,7 @@ Foam::fileName Foam::home() } -Foam::fileName Foam::home(const word& userName) +Foam::fileName Foam::home(const string& userName) { struct passwd* pw; @@ -1069,7 +1069,7 @@ void Foam::fdClose(const int fd) bool Foam::ping ( - const word& destName, + const string& destName, const label destPort, const label timeOut ) @@ -1083,7 +1083,7 @@ bool Foam::ping { FatalErrorIn ( - "Foam::ping(const word&, ...)" + "Foam::ping(const string&, ...)" ) << "gethostbyname error " << h_errno << " for host " << destName << abort(FatalError); } @@ -1097,7 +1097,7 @@ bool Foam::ping { FatalErrorIn ( - "Foam::ping(const word&, const label)" + "Foam::ping(const string&, const label)" ) << "socket error" << abort(FatalError); } @@ -1149,7 +1149,7 @@ bool Foam::ping } -bool Foam::ping(const word& hostname, const label timeOut) +bool Foam::ping(const string& hostname, const label timeOut) { return ping(hostname, 222, timeOut) || ping(hostname, 22, timeOut); } diff --git a/src/OSspecific/POSIX/signals/sigStopAtWriteNow.C b/src/OSspecific/POSIX/signals/sigStopAtWriteNow.C new file mode 100644 index 0000000000000000000000000000000000000000..09d862ca5d78199aaa08545959edaf0a737a9509 --- /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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#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 0000000000000000000000000000000000000000..4c07248eb21be8c29325914f1dcbc99bb72c86d0 --- /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 <http://www.gnu.org/licenses/>. + +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 <signal.h> + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +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 0000000000000000000000000000000000000000..6ad98a6190d88bac2a87ad29edf3416da049d917 --- /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 <http://www.gnu.org/licenses/>. + +\*---------------------------------------------------------------------------*/ + +#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 0000000000000000000000000000000000000000..871b980edd99da64f7c44583692b8685acf21aed --- /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 <http://www.gnu.org/licenses/>. + +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 <signal.h> + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +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 727f21c98ceb1217d2eb3751e55c076049651d04..0051d23153104f301817f973b09f813bc0de8932 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<label>()); + + if (flag & 1) + { + stopAt_ = saWriteNow; + } + if (flag & 2) + { + writeOnce_ = true; + } + } + + + outputTime_ = false; + switch (writeControl_) { case wcTimeStep: @@ -964,10 +1018,6 @@ Foam::Time& Foam::Time::operator++() outputTime_ = true; outputTimeIndex_ = outputIndex; } - else - { - outputTime_ = false; - } } break; @@ -983,10 +1033,6 @@ Foam::Time& Foam::Time::operator++() outputTime_ = true; outputTimeIndex_ = outputIndex; } - else - { - outputTime_ = false; - } } break; @@ -1002,14 +1048,69 @@ Foam::Time& Foam::Time::operator++() outputTime_ = true; outputTimeIndex_ = outputIndex; } - else + } + break; + } + + + // Adapt for secondaryWrite controls + switch (secondaryWriteControl_) + { + case wcTimeStep: + outputTime_ = + outputTime_ + || !(timeIndex_ % label(secondaryWriteInterval_)); + break; + + case wcRunTime: + case wcAdjustableRunTime: + { + label outputIndex = label + ( + ((value() - startTime_) + 0.5*deltaT_) + / secondaryWriteInterval_ + ); + + if (outputIndex > outputTimeIndex_) + { + outputTime_ = true; + outputTimeIndex_ = outputIndex; + } + } + break; + + case wcCpuTime: + { + label outputIndex = label + ( + returnReduce(elapsedCpuTime(), maxOp<double>()) + / secondaryWriteInterval_ + ); + if (outputIndex > outputTimeIndex_) { - outputTime_ = false; + outputTime_ = true; + outputTimeIndex_ = outputIndex; + } + } + break; + + case wcClockTime: + { + label outputIndex = label + ( + returnReduce(label(elapsedClockTime()), maxOp<label>()) + / secondaryWriteInterval_ + ); + if (outputIndex > outputTimeIndex_) + { + outputTime_ = true; + outputTimeIndex_ = outputIndex; } } break; } + // see if endTime needs adjustment to stop at the next run()/end() check if (!end()) { @@ -1027,6 +1128,14 @@ Foam::Time& Foam::Time::operator++() endTime_ = value(); } } + + // Override outputTime if one-shot writing + if (writeOnce_) + { + outputTime_ = true; + writeOnce_ = false; + } + } return *this; diff --git a/src/OpenFOAM/db/Time/Time.H b/src/OpenFOAM/db/Time/Time.H index a84b558a38ff04ef59e141fae2571ffb8155ffaa..0cfe4c51fa9888c5bbebfecf8d271d939207fee8 100644 --- a/src/OpenFOAM/db/Time/Time.H +++ b/src/OpenFOAM/db/Time/Time.H @@ -52,6 +52,8 @@ SourceFiles #include "dlLibraryTable.H" #include "functionObjectList.H" #include "fileMonitor.H" +#include "sigWriteNow.H" +#include "sigStopAtWriteNow.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -130,15 +132,35 @@ protected: scalar writeInterval_; + // Additional writing + + writeControls secondaryWriteControl_; + + scalar secondaryWriteInterval_; + + label purgeWrite_; mutable FIFOStack<word> previousOutputTimes_; + // One-shot writing + bool writeOnce_; + //- Is the time currently being sub-cycled? bool subCycling_; //- If time is being sub-cycled this is the previous TimeState autoPtr<TimeState> prevTimeState_; + + // Signal handlers for secondary writing + + //- Enable one-shot writing upon signal + sigWriteNow sigWriteNow_; + + //- Enable write and clean exit upon signal + sigStopAtWriteNow sigStopAtWriteNow_; + + //- Time directory name format static fmtflags format_; @@ -357,12 +379,16 @@ public: IOstream::compressionType ) const; - //- Write the objects now and continue the run + //- Write the objects now (not at end of iteration) and continue + // the run bool writeNow(); - //- Write the objects now and end the run + //- Write the objects now (not at end of iteration) and end the run bool writeAndEnd(); + //- Write the objects once (one shot) and continue the run + void writeOnce(); + // Access diff --git a/src/OpenFOAM/db/Time/TimeIO.C b/src/OpenFOAM/db/Time/TimeIO.C index 905e508a6aa4d989d5e6764ba698e4ff43d13113..9ed963127d8f7eba9b3dbf92189cd64b2b7075a9 100644 --- a/src/OpenFOAM/db/Time/TimeIO.C +++ b/src/OpenFOAM/db/Time/TimeIO.C @@ -58,6 +58,45 @@ void Foam::Time::readDict() controlDict_.lookup("writeFrequency") >> writeInterval_; } + + // Additional writing + if (controlDict_.found("secondaryWriteControl")) + { + secondaryWriteControl_ = writeControlNames_.read + ( + controlDict_.lookup("secondaryWriteControl") + ); + + if + ( + controlDict_.readIfPresent + ( + "secondaryWriteInterval", + secondaryWriteInterval_ + ) + ) + { + if + ( + secondaryWriteControl_ + == wcTimeStep && label(secondaryWriteInterval_) < 1 + ) + { + FatalIOErrorIn("Time::readDict()", controlDict_) + << "secondaryWriteInterval < 1" + << " for secondaryWriteControl timeStep" + << exit(FatalIOError); + } + } + else + { + controlDict_.lookup("secondaryWriteFrequency") + >> secondaryWriteInterval_; + } + } + + + if (oldWriteInterval != writeInterval_) { switch (writeControl_) @@ -310,4 +349,10 @@ bool Foam::Time::writeAndEnd() } +void Foam::Time::writeOnce() +{ + writeOnce_ = true; +} + + // ************************************************************************* // diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index 3c42659bf20572a86372c9c7ec0f9162bf9f4129..5d8758e2d2978145f83e5e15935c7b254ab7e582 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -726,7 +726,7 @@ Foam::argList::argList } - wordList slaveProcs; + stringList slaveProcs; // collect slave machine/pid if (parRunControl_.parRun()) @@ -734,7 +734,7 @@ Foam::argList::argList if (Pstream::master()) { slaveProcs.setSize(Pstream::nProcs() - 1); - word slaveMachine; + string slaveMachine; label slavePid; label procI = 0; diff --git a/src/OpenFOAM/include/OSspecific.H b/src/OpenFOAM/include/OSspecific.H index dc12ef753f8e1b94ae24f429c5893b4136a90a73..d39a1c54cbb2e4b931cdf768215525a23ef14e3a 100644 --- a/src/OpenFOAM/include/OSspecific.H +++ b/src/OpenFOAM/include/OSspecific.H @@ -69,13 +69,13 @@ bool setEnv(const word& name, const std::string& value, const bool overwrite); //- Return the system's host name, as per hostname(1) // Optionally with the full name (as per the '-f' option) -word hostName(const bool full=false); +string hostName(const bool full=false); //- Return the system's domain name, as per hostname(1) with the '-d' option -word domainName(); +string domainName(); //- Return the user's login name -word userName(); +string userName(); //- Is user administrator bool isAdministrator(); @@ -84,7 +84,7 @@ bool isAdministrator(); fileName home(); //- Return home directory path name for a particular user -fileName home(const word& userName); +fileName home(const string& userName); //- Return current working directory path name fileName cwd(); @@ -189,10 +189,10 @@ unsigned int sleep(const unsigned int); void fdClose(const int); //- Check if machine is up by pinging given port -bool ping(const word&, const label port, const label timeOut); +bool ping(const string&, const label port, const label timeOut); //- Check if machine is up by pinging port 22 (ssh) and 222 (rsh) -bool ping(const word&, const label timeOut=10); +bool ping(const string&, const label timeOut=10); //- Execute the specified command int system(const std::string& command); diff --git a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C index 69f07a6372a42d631591380e45316baa0b3a1977..5e8909549815b851539bb97315976c77649158ea 100644 --- a/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C +++ b/src/OpenFOAM/interpolations/interpolationTable/interpolationTable.C @@ -88,7 +88,7 @@ Foam::interpolationTable<Type>::interpolationTable(const fileName& fName) List<Tuple2<scalar, Type> >(), boundsHandling_(interpolationTable::WARN), fileName_(fName), - reader_(new openFoamTableReader<Type>()) + reader_(new openFoamTableReader<Type>(dictionary())) { readTable(); } diff --git a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C index 32e88b16f80b03d8bb9b85796679d617efc7a226..e7493b78e954694fa8b4f5e956b51a86f512133b 100644 --- a/src/OpenFOAM/primitives/strings/stringOps/stringOps.C +++ b/src/OpenFOAM/primitives/strings/stringOps/stringOps.C @@ -548,7 +548,7 @@ Foam::string& Foam::stringOps::inplaceExpand // ~OpenFOAM => site/user OpenFOAM configuration directory // ~user => home directory for specified user - word user; + string user; fileName file; if ((begVar = s.find('/')) != string::npos) diff --git a/src/Pstream/dummy/UIPread.C b/src/Pstream/dummy/UIPread.C index 1dc91fe038d3ccdb6104b706bf983b426d714092..fc3b4466e2a32bad3e4e4c1c4b74e39f78bbf488 100644 --- a/src/Pstream/dummy/UIPread.C +++ b/src/Pstream/dummy/UIPread.C @@ -53,15 +53,42 @@ Foam::UIPstream::UIPstream { notImplemented ( - "UIPstream::UIPstream" - "(" - "const commsTypes," - "const int fromProcNo," - "DynamicList<char>&," - "label&," - "const int tag," - "const bool," - "streamFormat, versionNumber" + "UIPstream::UIPstream\n" + "(\n" + "const commsTypes,\n" + "const int,\n" + "DynamicList<char>&,\n" + "label&,\n" + "const int,\n" + "const bool,\n" + "streamFormat,\n" + "versionNumber\n" + ")" + ); +} + + +Foam::UIPstream::UIPstream +( + const int fromProcNo, + PstreamBuffers& buffers +) +: + UPstream(buffers.commsType_), + Istream(buffers.format_, buffers.version_), + fromProcNo_(fromProcNo), + externalBuf_(buffers.recvBuf_[fromProcNo]), + externalBufPosition_(buffers.recvBufPos_[fromProcNo]), + tag_(buffers.tag_), + clearAtEnd_(true), + messageSize_(0) +{ + notImplemented + ( + "UIPstream::UIPstream\n" + "(\n" + "const int,\n" + "PstreamBuffers&\n" ")" ); } diff --git a/tutorials/incompressible/icoFoam/cavity/system/controlDict b/tutorials/incompressible/icoFoam/cavity/system/controlDict index d2fa09cc526b96181407595f79c0968a81be7c44..8016db385c2528d5d285b268fea33f6a968f984c 100644 --- a/tutorials/incompressible/icoFoam/cavity/system/controlDict +++ b/tutorials/incompressible/icoFoam/cavity/system/controlDict @@ -31,6 +31,10 @@ writeControl timeStep; writeInterval 20; +//- Additional dump every hour of cpuTime for e.g. restarts +//secondaryWriteControl cpuTime; +//secondaryWriteInterval 3600; + purgeWrite 0; writeFormat ascii; diff --git a/wmake/wmakeScheduler b/wmake/wmakeScheduler index aa6fb1ec81bd963412192fff74fcbda92d50a46e..f614e73758b03de205de3f69022053b56cf04b13 100755 --- a/wmake/wmakeScheduler +++ b/wmake/wmakeScheduler @@ -151,7 +151,8 @@ set -o pipefail # colourPipe() { - if [ "$1" ] + + if tty -s <&1 # [ "$1" ] then ( while read line