From 610c2909695aea1c114cd574a6eb0990a082cba7 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 28 Nov 2017 10:00:15 +0100 Subject: [PATCH 1/4] ENH: added functionObject::execute(int) method - this is a provision for defining execute actions that can be called largely independently of the normal time-loop constraints. This can be useful to provide hooks for sub-cycling, or to define an action that can be triggered manually or on some other event. --- .../functionObject/functionObject.C | 6 +++ .../functionObject/functionObject.H | 10 ++++- .../functionObjectList/functionObjectList.C | 45 +++++++++++++++++++ .../functionObjectList/functionObjectList.H | 32 +++++++++---- .../timeControl/timeControlFunctionObject.C | 18 ++++++-- .../timeControl/timeControlFunctionObject.H | 3 ++ 6 files changed, 100 insertions(+), 14 deletions(-) diff --git a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C index 51e1323ec8..a13a044157 100644 --- a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C +++ b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.C @@ -141,6 +141,12 @@ bool Foam::functionObject::read(const dictionary& dict) } +bool Foam::functionObject::execute(const label) +{ + return true; +} + + bool Foam::functionObject::end() { return true; diff --git a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H index febb76de10..3f47feba8c 100644 --- a/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H +++ b/src/OpenFOAM/db/functionObjects/functionObject/functionObject.H @@ -222,13 +222,19 @@ public: const word& name() const; //- Read and set the function object if its data have changed - virtual bool read(const dictionary&); + virtual bool read(const dictionary& dict); //- Called at each ++ or += of the time-loop. // postProcess overrides the usual executeControl behaviour and // forces execution (used in post-processing mode) virtual bool execute() = 0; + //- Execute using the specified subIndex. + // The base implementation is a no-op. + // \param subIndex an execution sub-index corresponding to a + // sub-cycle or something similar. + virtual bool execute(const label subIndex); + //- Called at each ++ or += of the time-loop. // postProcess overrides the usual writeControl behaviour and // forces writing always (used in post-processing mode) @@ -245,9 +251,11 @@ public: virtual bool filesModified() const; //- Update for changes of mesh + // The base implementation is a no-op. virtual void updateMesh(const mapPolyMesh& mpm); //- Update for changes of mesh + // The base implementation is a no-op. virtual void movePoints(const polyMesh& mesh); }; diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C index 31bf1d40d7..98174a669e 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.C @@ -32,6 +32,7 @@ License //#include "IFstream.H" #include "dictionaryEntry.H" #include "stringOps.H" +#include "wordRes.H" #include "Tuple2.H" #include "etcFiles.H" #include "IOdictionary.H" @@ -579,6 +580,7 @@ bool Foam::functionObjectList::execute() } } } + // Force writing of state dictionary after function object execution if (time_.writeTime()) { @@ -600,6 +602,49 @@ bool Foam::functionObjectList::execute() } +bool Foam::functionObjectList::execute(const label subIndex) +{ + bool ok = execution_; + + if (ok) + { + forAll(*this, obji) + { + functionObject& funcObj = operator[](obji); + + ok = funcObj.execute(subIndex) && ok; + } + } + + return ok; +} + + +bool Foam::functionObjectList::execute +( + const wordRes& functionNames, + const label subIndex +) +{ + bool ok = execution_; + + if (ok && functionNames.size()) + { + forAll(*this, obji) + { + functionObject& funcObj = operator[](obji); + + if (functionNames.match(funcObj.name())) + { + ok = funcObj.execute(subIndex) && ok; + } + } + } + + return ok; +} + + bool Foam::functionObjectList::end() { bool ok = true; diff --git a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H index c90318727b..e32b01e25b 100644 --- a/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H +++ b/src/OpenFOAM/db/functionObjects/functionObjectList/functionObjectList.H @@ -52,8 +52,10 @@ SourceFiles namespace Foam { -class mapPolyMesh; +// Forward declarations class argList; +class mapPolyMesh; +class wordRes; /*---------------------------------------------------------------------------*\ Class functionObjectList Declaration @@ -94,19 +96,19 @@ class functionObjectList void createStateDict() const; //- Remove and return the function object pointer by name, - // and returns the old index via the parameter. + //- and returns the old index via the parameter. // Returns a nullptr (and index -1) if it didn't exist - functionObject* remove(const word&, label& oldIndex); + functionObject* remove(const word& key, label& oldIndex); //- Search the specified directory for functionObject - // configuration files, add to the given map and recurse + //- configuration files, add to the given map and recurse static void listDir(const fileName& dir, HashSet& foMap); //- Disallow default bitwise copy construct - functionObjectList(const functionObjectList&); + functionObjectList(const functionObjectList&) = delete; //- Disallow default bitwise assignment - void operator=(const functionObjectList&); + void operator=(const functionObjectList&) = delete; public: @@ -114,7 +116,7 @@ public: // Static data members //- Default relative path to the directory structure - // containing the functionObject dictionary files + //- containing the functionObject dictionary files static fileName functionObjectDictPath; @@ -188,7 +190,7 @@ public: label findObjectID(const word& name) const; //- Print a list of functionObject configuration files in - // user/group/shipped directories. + //- user/group/shipped directories. // The search scheme allows for version-specific and // version-independent files using the following hierarchy: // - \b user settings: @@ -205,7 +207,7 @@ public: static void list(); //- Search for functionObject dictionary file in - // user/group/shipped directories. + //- user/group/shipped directories. // The search scheme allows for version-specific and // version-independent files using the following hierarchy: // - \b user settings: @@ -258,6 +260,18 @@ public: // forces execution (used in post-processing mode) bool execute(); + //- Execute function objects using the specified subIndex. + // \param subIndex an execution sub-index corresponding to a + // sub-cycle or something similar + bool execute(const label subIndex); + + //- Execute a subset of function objects using the specified subIndex. + // \param functionNames names or regex of existing functions to + // execute + // \param subIndex an execution sub-index corresponding to a + // sub-cycle or something similar + bool execute(const wordRes& functionNames, const label subIndex); + //- Called when Time::run() determines that the time-loop exits bool end(); diff --git a/src/OpenFOAM/db/functionObjects/timeControl/timeControlFunctionObject.C b/src/OpenFOAM/db/functionObjects/timeControl/timeControlFunctionObject.C index bbb495cb98..96e088fe2d 100644 --- a/src/OpenFOAM/db/functionObjects/timeControl/timeControlFunctionObject.C +++ b/src/OpenFOAM/db/functionObjects/timeControl/timeControlFunctionObject.C @@ -450,6 +450,18 @@ bool Foam::functionObjects::timeControl::execute() } +bool Foam::functionObjects::timeControl::execute(const label subIndex) +{ + if (active()) + { + // Call underlying function object directly + foPtr_->execute(subIndex); + } + + return true; +} + + bool Foam::functionObjects::timeControl::write() { if (active() && (postProcess || writeControl_.execute())) @@ -726,10 +738,8 @@ bool Foam::functionObjects::timeControl::read(const dictionary& dict) return true; } - else - { - return false; - } + + return false; } diff --git a/src/OpenFOAM/db/functionObjects/timeControl/timeControlFunctionObject.H b/src/OpenFOAM/db/functionObjects/timeControl/timeControlFunctionObject.H index 4b4bca78e1..18a3e51461 100644 --- a/src/OpenFOAM/db/functionObjects/timeControl/timeControlFunctionObject.H +++ b/src/OpenFOAM/db/functionObjects/timeControl/timeControlFunctionObject.H @@ -206,6 +206,9 @@ public: // forces execution (used in post-processing mode) virtual bool execute(); + //- Execute using the specified subIndex. + virtual bool execute(const label subIndex); + //- Called at each ++ or += of the time-loop. // postProcess overrides the usual writeControl behaviour and // forces writing (used in post-processing mode) From 96ed3638e468be8680689ef05ef6f520f9539556 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 5 Dec 2017 12:00:00 +0100 Subject: [PATCH 2/4] ENH: basic support for generic solution loop-control --- src/finiteVolume/Make/files | 1 + .../solutionControl/loopControl/fvSolution | 47 +++ .../solutionControl/loopControl/loopControl.C | 280 ++++++++++++++++++ .../solutionControl/loopControl/loopControl.H | 227 ++++++++++++++ 4 files changed, 555 insertions(+) create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/loopControl/fvSolution create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/loopControl/loopControl.C create mode 100644 src/finiteVolume/cfdTools/general/solutionControl/loopControl/loopControl.H diff --git a/src/finiteVolume/Make/files b/src/finiteVolume/Make/files index db88df52ae..e7023dea21 100644 --- a/src/finiteVolume/Make/files +++ b/src/finiteVolume/Make/files @@ -425,6 +425,7 @@ $(coupling)/externalFileCoupler.C solutionControl = $(general)/solutionControl $(solutionControl)/solutionControl/solutionControl.C +$(solutionControl)/loopControl/loopControl.C $(solutionControl)/simpleControl/simpleControl.C $(solutionControl)/pimpleControl/pimpleControl.C $(solutionControl)/pisoControl/pisoControl.C diff --git a/src/finiteVolume/cfdTools/general/solutionControl/loopControl/fvSolution b/src/finiteVolume/cfdTools/general/solutionControl/loopControl/fvSolution new file mode 100644 index 0000000000..19d8b0fe0b --- /dev/null +++ b/src/finiteVolume/cfdTools/general/solutionControl/loopControl/fvSolution @@ -0,0 +1,47 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: plus | +| \\ / A nd | Web: www.OpenFOAM.com | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object fvSolution; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + + +SIMPLE +{ + energyCoupling + { + // (Max) number of loops + iterations 200; + + // The interval to execute onLoop function-objects + interval 0; + + // Convergence criteria to terminate loop + convergence + { + "h" 1e-3; + } + + // Names of function objects to fire with execute(int) when looping + onLoop ( ); + + // Names of function objects to fire with execute(int) when converged + onConverged ( ); + + // Names of function objects to fire with execute(int) when loop ends + // without convergence + onEnd ( ); + } +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/solutionControl/loopControl/loopControl.C b/src/finiteVolume/cfdTools/general/solutionControl/loopControl/loopControl.C new file mode 100644 index 0000000000..f453124368 --- /dev/null +++ b/src/finiteVolume/cfdTools/general/solutionControl/loopControl/loopControl.C @@ -0,0 +1,280 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ 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 "loopControl.H" +#include "fvSolution.H" +#include "wordRes.H" +#include "solutionControl.H" + +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // + +void Foam::loopControl::clear() +{ + total_ = 0; + interval_ = 0; + + convergenceDict_.clear(); + onLoop_.clear(); + onConverged_.clear(); + onEnd_.clear(); + + converged_ = false; +} + + +void Foam::loopControl::read(const dictionary& dict) +{ + clear(); + + bool enabled = dict.lookupOrDefault("enabled", true); + + if (enabled) + { + scalar timeStart; + if (dict.readIfPresent("timeStart", timeStart)) + { + timeStart = time_.userTimeToTime(timeStart); + + enabled = + ( + enabled + && time_.value() >= (timeStart - 0.5*time_.deltaTValue()) + ); + } + + scalar timeEnd; + if (dict.readIfPresent("timeEnd", timeEnd)) + { + timeEnd = time_.userTimeToTime(timeEnd); + + enabled = + ( + enabled + && time_.value() <= (timeEnd + 0.5*time_.deltaTValue()) + ); + } + } + + if (!enabled) + { + return; + } + + dict.readIfPresent("iterations", total_); + dict.readIfPresent("interval", interval_); + + convergenceDict_ = dict.subOrEmptyDict("convergence"); + + dict.readIfPresent("onLoop", onLoop_); + dict.readIfPresent("onConverged", onConverged_); + dict.readIfPresent("onEnd", onEnd_); +} + + +bool Foam::loopControl::checkConverged() const +{ + if (convergenceDict_.empty()) + { + return false; + } + + HashTable meshes = time_.lookupClass(); + + bool achieved = true; + bool checked = false; // safety that some checks were indeed performed + + forAllConstIters(meshes, meshIter) + { + const fvMesh& regionMesh = *(meshIter.object()); + + const dictionary& solverDict = regionMesh.solverPerformanceDict(); + + forAllConstIters(solverDict, iter) + { + const entry& dataDictEntry = *iter; + + const word& variableName = dataDictEntry.keyword(); + + const scalar absTol = + convergenceDict_.lookupOrDefault(variableName, -1); + + if (absTol > 0) + { + // Treat like a SIMPLE control + + Pair residuals = + solutionControl::maxResidual + ( + regionMesh, + dataDictEntry + ); + + checked = true; + achieved = achieved && (residuals.first() < absTol); + } + } + } + + return checked && achieved; +} + + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +Foam::loopControl::loopControl +( + Time& runTime, + const label nCycles, + const word& loopName +) +: + subLoopTime(runTime, nCycles), + name_(loopName), + interval_(0), + convergenceDict_(), + onLoop_(), + onConverged_(), + onEnd_(), + converged_(false) +{} + + +Foam::loopControl::loopControl +( + Time& runTime, + const dictionary& algorithmDict, + const word& dictName +) +: + loopControl(runTime, 0, dictName) +{ + // The loop sub-dictionary + const dictionary* dictptr = algorithmDict.subDictPtr(dictName); + + if (dictptr) + { + // Info<< dictName << *dictptr << endl; + read(*dictptr); + } +} + + +Foam::loopControl::loopControl +( + Time& runTime, + const word& algorithmName, + const word& dictName +) +: + loopControl(runTime, 0, dictName) +{ + fvSolution fvsol(time_); + + // Eg, PIMPLE or SIMPLE from + const dictionary* dictptr = + fvsol.solutionDict().subDictPtr(algorithmName); + + if (dictptr) + { + // The loop sub-dictionary + dictptr = dictptr->subDictPtr(dictName); + + if (dictptr) + { + // Info<< dictName << *dictptr << endl; + read(*dictptr); + } + } +} + + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +Foam::loopControl::~loopControl() +{ + stop(); +} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +bool Foam::loopControl::loop() +{ + bool active = (index_ < total_); // as per status() + + if (active) + { + operator++(); + + converged_ = checkConverged(); + + if (converged_) + { + time_.functionObjects().execute(onConverged_, index_); + stop(); + return false; + } + else if + ( + interval_ && !(index_ % interval_) + && !onLoop_.empty() + ) + { + time_.functionObjects().execute(onLoop_, index_); + } + } + else if (index_) + { + // Not active, the loop condition has now exiting on the last subloop + + if (!converged_ && !onEnd_.empty()) + { + time_.functionObjects().execute(onEnd_, index_); + } + } + + return active; +} + + +// * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * * // + +Foam::Ostream& Foam::operator<<(Ostream& os, const loopControl& ctrl) +{ + os << ctrl.name() << ": "; + if (ctrl.nCycles() && ctrl.index() <= ctrl.nCycles()) + { + os << ctrl.index() << '/' << ctrl.nCycles(); + } + else + { + os << "off"; + } + + return os; +} + + +// ************************************************************************* // diff --git a/src/finiteVolume/cfdTools/general/solutionControl/loopControl/loopControl.H b/src/finiteVolume/cfdTools/general/solutionControl/loopControl/loopControl.H new file mode 100644 index 0000000000..ced72d57e3 --- /dev/null +++ b/src/finiteVolume/cfdTools/general/solutionControl/loopControl/loopControl.H @@ -0,0 +1,227 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2017 OpenCFD Ltd. + \\/ 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::loopControl + +Description + A class for managing arbitrary loops with the ability to invoke + function object execution. + +Usage + Examples of function object specification: + \verbatim + SIMPLE + { + energyCoupling + { + iterations 100; + onLoop (); + onConverged ( externalCoupled "loopThings.*" ); + + convergence + { + "h" 1e-3; + } + } + } + + Where the loop entries comprise: + \table + Property | Description | Required | Default + enabled | active/deactive loop | no | true + iteration | times to loop | no | 0 + timeStart | begin time for loop activation | no | -VGREAT + timeEnd | end time of loop activation | no | VGREAT + interval | sub-interval to execute onLoop | no | 0 + onLoop | function object names to call at executeInterval | no + onConverged | function object names to call when converged | no + onEnd | function object names to call when loop ends | no + convergence | dictionary of convergence values to check | no + \endtable + + The function object names listed by \c onLoop, \c onConverged, \c onEnd + must implement an \c execute(int) method. + If the time controls \c timeStart or \c timeEnd are used for the loop, + these values are only inspected upon creation, not during execution. + +SeeAlso + fvSolution + +SourceFiles + loopControl.C + +\*---------------------------------------------------------------------------*/ + +#ifndef loopControl_H +#define loopControl_H + +#include "subLoopTime.H" +#include "dictionary.H" +#include "wordReList.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class loopControl Declaration +\*---------------------------------------------------------------------------*/ + +class loopControl +: + public subLoopTime +{ + // Private Member Functions + + //- Reset + void clear(); + + //- Read settings from dictionary + void read(const dictionary& dict); + + //- Execute specified function names + bool checkConverged() const; + + //- Disallow default bitwise copy construct + loopControl(const loopControl&) = delete; + + //- Disallow default bitwise assignment + void operator=(const loopControl&) = delete; + +protected: + + // Protected data + + //- Name of the loop control (the lookup dictionary name). + word name_; + + //- The interval to execute onLoop function-objects + label interval_; + + //- Dictionary for checking convergence (all regions) + dictionary convergenceDict_; + + //- Function object names to fire during the loop (at executeInterval) + List onLoop_; + + //- Function object names to fire on convergence + List onConverged_; + + //- Function object names to fire when the loop exits without + //- convergence + List onEnd_; + + //- Convergence tests passed + bool converged_; + +public: + + // Constructors + + //- Construct from time with fixed number of cycles + // \param runTime the top-level time + // \param nCycles the number of times to loop + // \param loopName the name of the loop + loopControl + ( + Time& runTime, + const label nCycles, + const word& dictName = "loop" + ); + + //- Construct from fvSolution dictionary based on time and the name + //- of the controlling algorithm + // \param runTime the top-level time + // \param algorithmName the name of the fvSolution dictionary, + // typically PIMPLE or SIMPLE + // \param dictName the name of the control dictionary + loopControl + ( + Time& runTime, + const word& algorithmName, + const word& dictName = "loop" + ); + + //- Construct from fvSolution dictionary based on time and the name + //- of the controlling algorithm + // \param runTime the top-level time + // \param algorithmDict the fvSolution algorithm dictionary, + // typically PIMPLE or SIMPLE + // \param dictName the name of the control dictionary + loopControl + ( + Time& runTime, + const dictionary& algorithmDict, + const word& dictName = "loop" + ); + + + //- Destructor + ~loopControl(); + + + // Member Functions + + //- Name of the loop control + inline const word& name() const + { + return name_; + } + + //- The interval to execute onLoop function-objects + inline label interval() const + { + return interval_; + } + + //- True if looping is active, increments the index and executes + //- the onLoop and onConverged functions. + // Example usage, + // \code + // while (control.loop()) + // { + // solve; + // } + // \endcode + bool loop(); + + + // IOstream operators + + //- Write name and state (on/off, index/total) to Ostream + friend Ostream& operator<<(Ostream& os, const loopControl& ctrl); + +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // From 0e2798399e10f87f10f2b2577d816372af4bb25d Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 5 Dec 2017 12:00:00 +0100 Subject: [PATCH 3/4] ENH: add enthalpy sub-looping for chtMultiRegion* solvers --- .../chtMultiRegionFoam/chtMultiRegionFoam.C | 37 ++++++++-- .../chtMultiRegionSimpleFoam.C | 33 ++++++++- .../fluid/setRegionFluidFields.H | 17 ++--- .../solid/solveSolid.H | 12 ++-- .../fluid/createFluidFields.H | 12 ++-- .../fluid/setRegionFluidFields.H | 7 +- .../solid/createSolidMeshes.H | 10 +-- .../chtMultiRegionFoam/solid/solveSolid.H | 12 ++-- .../field/externalCoupled/externalCoupled.C | 70 ++++++++++++------- .../field/externalCoupled/externalCoupled.H | 18 +++-- .../externalCoupledMixedFvPatchField.H | 17 +++-- ...oupledTemperatureMixedFvPatchScalarField.H | 35 +++++----- .../regionProperties/regionProperties.H | 6 +- 13 files changed, 189 insertions(+), 97 deletions(-) diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionFoam.C b/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionFoam.C index 155b08a0f8..80e7e78fbb 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionFoam.C +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionFoam.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) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -47,6 +47,7 @@ Description #include "radiationModel.H" #include "fvOptions.H" #include "coordinateSystem.H" +#include "loopControl.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -89,11 +90,10 @@ int main(int argc, char *argv[]) } } - // --- PIMPLE loop - for (int oCorr=0; oCorr 1) + { + loopControl looping(runTime, pimple, "energyCoupling"); + + while (looping.loop()) + { + Info<< nl << looping << nl; + + forAll(fluidRegions, i) + { + Info<< "\nSolving for fluid region " + << fluidRegions[i].name() << endl; + #include "setRegionFluidFields.H" + #include "readFluidMultiRegionPIMPLEControls.H" + frozenFlow = true; + #include "solveFluid.H" + } + + forAll(solidRegions, i) + { + Info<< "\nSolving for solid region " + << solidRegions[i].name() << endl; + #include "setRegionSolidFields.H" + #include "readSolidMultiRegionPIMPLEControls.H" + #include "solveSolid.H" + } + } + } } runTime.write(); diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/chtMultiRegionSimpleFoam.C b/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/chtMultiRegionSimpleFoam.C index ea89befe12..20aa2d59cd 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/chtMultiRegionSimpleFoam.C +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/chtMultiRegionSimpleFoam.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) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -42,6 +42,7 @@ Description #include "radiationModel.H" #include "fvOptions.H" #include "coordinateSystem.H" +#include "loopControl.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -57,7 +58,6 @@ int main(int argc, char *argv[]) #include "createFields.H" #include "initContinuityErrs.H" - while (runTime.loop()) { Info<< "Time = " << runTime.timeName() << nl << endl; @@ -80,6 +80,35 @@ int main(int argc, char *argv[]) #include "solveSolid.H" } + // Additional loops for energy solution only + { + loopControl looping(runTime, "SIMPLE", "energyCoupling"); + + while (looping.loop()) + { + Info<< nl << looping << nl; + + forAll(fluidRegions, i) + { + Info<< "\nSolving for fluid region " + << fluidRegions[i].name() << endl; + #include "setRegionFluidFields.H" + #include "readFluidMultiRegionSIMPLEControls.H" + frozenFlow = true; + #include "solveFluid.H" + } + + forAll(solidRegions, i) + { + Info<< "\nSolving for solid region " + << solidRegions[i].name() << endl; + #include "setRegionSolidFields.H" + #include "readSolidMultiRegionSIMPLEControls.H" + #include "solveSolid.H" + } + } + } + runTime.write(); Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/fluid/setRegionFluidFields.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/fluid/setRegionFluidFields.H index 6cde0ec06b..119c2ad7ea 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/fluid/setRegionFluidFields.H +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/fluid/setRegionFluidFields.H @@ -12,6 +12,14 @@ volScalarField& p = thermo.p(); const volScalarField& psi = thermo.psi(); + volScalarField& p_rgh = p_rghFluid[i]; + + const dimensionedVector& g = gFluid[i]; + const volScalarField& gh = ghFluid[i]; + const surfaceScalarField& ghf = ghfFluid[i]; + + radiation::radiationModel& rad = radiation[i]; + IOMRFZoneList& MRF = MRFfluid[i]; fv::options& fvOptions = fluidFvOptions[i]; @@ -22,14 +30,7 @@ initialMassFluid[i] ); - radiation::radiationModel& rad = radiation[i]; + bool frozenFlow = frozenFlowFluid[i]; const label pRefCell = pRefCellFluid[i]; const scalar pRefValue = pRefValueFluid[i]; - const bool frozenFlow = frozenFlowFluid[i]; - - volScalarField& p_rgh = p_rghFluid[i]; - - const dimensionedVector& g = gFluid[i]; - const volScalarField& gh = ghFluid[i]; - const surfaceScalarField& ghf = ghfFluid[i]; diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/solid/solveSolid.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/solid/solveSolid.H index 0600a1c650..2b6306e5c2 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/solid/solveSolid.H +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/chtMultiRegionSimpleFoam/solid/solveSolid.H @@ -1,5 +1,5 @@ { - for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++) + for (int nonOrth=0; nonOrth<=nNonOrthCorr; ++nonOrth) { fvScalarMatrix hEqn ( @@ -20,9 +20,9 @@ fvOptions.correct(h); } + + thermo.correct(); + + Info<< "Min/max T:" << min(thermo.T()).value() << ' ' + << max(thermo.T()).value() << endl; } - -thermo.correct(); - -Info<< "Min/max T:" << min(thermo.T()).value() << ' ' - << max(thermo.T()).value() << endl; diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/createFluidFields.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/createFluidFields.H index 87e372fcae..15aba4cb27 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/createFluidFields.H +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/createFluidFields.H @@ -19,8 +19,8 @@ List frozenFlowFluid(fluidRegions.size(), false); PtrList MRFfluid(fluidRegions.size()); PtrList fluidFvOptions(fluidRegions.size()); -List