From b8448671125c506b044dc05896d94a7a336c87fb Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 28 Oct 2016 16:48:30 +0200 Subject: [PATCH 1/4] BUG: etc/bashrc incorrect behaviour if sourced locally (issue #280) - It is incorrect to prefix the assignment with an 'export' since this automatically marks the overall command as successful and circumvents the fallback. There is no simple way to have proper behaviour when sourced with a local directory path, but at least it now uses the fallback. It is still easy to wreak the mechanism with valid but confusing input. For example, ". /path/to/openfoam/etc/././bashrc" The only real certainty is that "${BASH_SOURCE%/*}" should point to the 'etc/' directory. In which case, cd ${BASH_SOURCE%/*} # <- now in the etc/ directory pwd=$(pwd -P) # <- fully-qualified path to etc/ pwd=${pwd%/*/*} # <- up two parent levels - This works with ". ./bashrc", but fails with ". bashrc" (probably not so common). - Con: The construct requires an additional sub-shell. --- etc/bashrc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/etc/bashrc b/etc/bashrc index 01115f2600..c65f5fab04 100644 --- a/etc/bashrc +++ b/etc/bashrc @@ -42,15 +42,15 @@ export WM_PROJECT_VERSION=plus # # Please set to the appropriate path if the default is not correct. # -[ $BASH_SOURCE ] && \ -export FOAM_INST_DIR=$(\cd ${BASH_SOURCE%/*/*/*} && pwd -P) || \ -export FOAM_INST_DIR=$HOME/$WM_PROJECT -# export FOAM_INST_DIR=~$WM_PROJECT -# export FOAM_INST_DIR=/opt/$WM_PROJECT -# export FOAM_INST_DIR=/usr/local/$WM_PROJECT +[ $BASH_SOURCE ] && FOAM_INST_DIR=$(\cd ${BASH_SOURCE%/*/*/*} && \pwd -P) || \ +FOAM_INST_DIR=$HOME/$WM_PROJECT +# FOAM_INST_DIR=~$WM_PROJECT +# FOAM_INST_DIR=/opt/$WM_PROJECT +# FOAM_INST_DIR=/usr/local/$WM_PROJECT # # END OF (NORMAL) USER EDITABLE PART ################################################################################ +export FOAM_INST_DIR # The default environment variables below can be overridden in a prefs.sh file # located in ~/.OpenFOAM/$WM_PROJECT_VERSION, ~/.OpenFOAM, From a05493db41869231b2032b5bf2107c5dfb56cc0e Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 31 Oct 2016 07:00:57 +0100 Subject: [PATCH 2/4] CONFIG: csh not unsetting old paraview/cmake environment (related to #281) - On the first call, ParaView_DIR is unset and thus the clean-path fails with the warning "ParaView_DIR: Undefined variable." This looks messy, but is of no _major_ consequence since paraview doesn't need to be removed anyhow. The only slight risk is that the path to a third-party cmake might not be cleaned. - Patch as per Bruno's suggestion. --- etc/config.csh/paraview | 1 + 1 file changed, 1 insertion(+) diff --git a/etc/config.csh/paraview b/etc/config.csh/paraview index ba718b0c0c..ef697365a1 100644 --- a/etc/config.csh/paraview +++ b/etc/config.csh/paraview @@ -59,6 +59,7 @@ set cmake_version=cmake-system #------------------------------------------------------------------------------ # Clean the PATH +if ( ! $?ParaView_DIR ) setenv ParaView_DIR set cleaned=`$WM_PROJECT_DIR/bin/foamCleanPath "$PATH" "$ParaView_DIR $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/cmake- $WM_THIRD_PARTY_DIR/platforms/$WM_ARCH$WM_COMPILER/paraview-"` if ( $status == 0 ) setenv PATH $cleaned From c836a017e67b503b490875ccbedf29eb34210132 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 31 Oct 2016 08:26:06 +0100 Subject: [PATCH 3/4] ENH: allow specific restart time for field averaging (issue #282) - Can currently have a periodic restart, but for simulations with a known run-up, it can be useful to have a specific time to restart the averaging. - Note that the restartTime acts as a 'single-shot'. If the restartTime is already in the past when a simulation is started, it is ignored. If, during a simulation, the restartTime is crossed, it will be triggered and then set itself to be ignored in the future. --- .../field/fieldAverage/fieldAverage.C | 34 ++++++++++++++++++- .../field/fieldAverage/fieldAverage.H | 6 +++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/functionObjects/field/fieldAverage/fieldAverage.C b/src/functionObjects/field/fieldAverage/fieldAverage.C index cf076159c4..d7cd691bf2 100644 --- a/src/functionObjects/field/fieldAverage/fieldAverage.C +++ b/src/functionObjects/field/fieldAverage/fieldAverage.C @@ -141,12 +141,24 @@ void Foam::functionObjects::fieldAverage::calcAverages() prevTimeIndex_ = currentTimeIndex; } + bool doRestart = false; if (periodicRestart_ && currentTime > restartPeriod_*periodIndex_) { - restart(); + doRestart = true; periodIndex_++; } + if (currentTime >= restartTime_) + { + doRestart = true; // Restart is overdue. + restartTime_ = GREAT; // Avoid triggering again + } + + if (doRestart) + { + restart(); + } + Log << type() << " " << name() << " write:" << nl << " Calculating averages" << nl; @@ -262,6 +274,7 @@ Foam::functionObjects::fieldAverage::fieldAverage restartOnOutput_(false), periodicRestart_(false), restartPeriod_(GREAT), + restartTime_(GREAT), initialised_(false), faItems_(), totalIter_(), @@ -296,6 +309,25 @@ bool Foam::functionObjects::fieldAverage::read(const dictionary& dict) if (periodicRestart_) { dict.lookup("restartPeriod") >> restartPeriod_; + Log + << " Restart period " << restartPeriod_ + << nl << endl; + } + + restartTime_ = GREAT; + if (dict.readIfPresent("restartTime", restartTime_)) + { + if (restartTime_ < obr_.time().value()) + { + // The restart time is already in the past - ignore + restartTime_ = GREAT; + } + else + { + Log + << " Restart scheduled at time " << restartTime_ + << nl << endl; + } } readAveragingProperties(); diff --git a/src/functionObjects/field/fieldAverage/fieldAverage.H b/src/functionObjects/field/fieldAverage/fieldAverage.H index 0fd49c9bd6..31a4763bfa 100644 --- a/src/functionObjects/field/fieldAverage/fieldAverage.H +++ b/src/functionObjects/field/fieldAverage/fieldAverage.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -106,6 +106,7 @@ Usage restartOnOutput | Restart the averaging on output | no | no periodicRestart | Periodically restart the averaging | no | no restartPeriod | Periodic restart period | conditional | + restartTime | One-shot reset of the averaging | no | great fields | list of fields and averaging options | yes | \endtable @@ -166,6 +167,9 @@ protected: //- Restart period scalar restartPeriod_; + //- Specific restart time + scalar restartTime_; + //- Initialised flag bool initialised_; From 4bcb0d71ca9324a8c7e5ebd3134873c6526d9b09 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 31 Oct 2016 13:09:54 +0100 Subject: [PATCH 4/4] ENH: Provide boundary field writeEntries method (issue #283) - Write the individual contents, without a surrounding 'boundaryField' block. Similar to what dictionary::writeEntries() offers. --- .../GeometricField/GeometricBoundaryField.C | 26 ++++++++++++------- .../GeometricField/GeometricField.H | 5 +++- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C index 7e273aa9fd..5eb896084a 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricBoundaryField.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -83,7 +83,7 @@ readField // 2. Patch-groups. (using non-wild card entries of dictionaries) // (patchnames already matched above) // Note: in reverse order of entries in the dictionary (last - // patchGroups wins). This is so is consistent with dictionary wildcard + // patchGroups wins). This is so it is consistent with dictionary wildcard // behaviour if (dict.size()) { @@ -570,14 +570,7 @@ void Foam::GeometricField::Boundary:: writeEntry(const word& keyword, Ostream& os) const { os.beginBlock(keyword); - - forAll(*this, patchi) - { - os.beginBlock(this->operator[](patchi).patch().name()); - os << this->operator[](patchi); - os.endBlock(); - } - + this->writeEntries(os); os.endBlock() << flush; // Check state of IOstream @@ -589,6 +582,19 @@ writeEntry(const word& keyword, Ostream& os) const } +template class PatchField, class GeoMesh> +void Foam::GeometricField::Boundary:: +writeEntries(Ostream& os) const +{ + forAll(*this, patchi) + { + os.beginBlock(this->operator[](patchi).patch().name()); + os << this->operator[](patchi); + os.endBlock(); + } +} + + // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // template class PatchField, class GeoMesh> diff --git a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H index 01337ebe66..c56bcd9a59 100644 --- a/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H +++ b/src/OpenFOAM/fields/GeometricFields/GeometricField/GeometricField.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd. + \\/ M anipulation | Copyright (C) 2015-2016 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -218,6 +218,9 @@ public: //- Write boundary field as dictionary entry void writeEntry(const word& keyword, Ostream& os) const; + //- Write dictionary entries of the individual boundary fields. + void writeEntries(Ostream& os) const; + // Member operators