foamMultiRun: Added automatic region prefixing to the Info statements in the log

e.g. for the rivuletBox case the output for a time-step now looks like:

film  Courant Number mean: 0.0003701330848 max: 0.1862204919
panel Diffusion Number mean: 0.007352456305 max: 0.1276468109
box   Courant Number mean: 0.006324172752 max: 0.09030825997
      deltaT = 0.001550908752
      Time = 0.08294s

film  diagonal:  Solving for alpha, Initial residual = 0, Final residual = 0, No Iterations 0
film  diagonal:  Solving for alpha, Initial residual = 0, Final residual = 0, No Iterations 0
box   diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
film  DILUPBiCGStab:  Solving for Ux, Initial residual = 0.009869417958, Final residual = 2.132619614e-11, No Iterations 2
film  DILUPBiCGStab:  Solving for Uy, Initial residual = 0.0002799662756, Final residual = 6.101011285e-12, No Iterations 1
film  DILUPBiCGStab:  Solving for Uz, Initial residual = 1, Final residual = 1.854120599e-12, No Iterations 2
box   DILUPBiCGStab:  Solving for Ux, Initial residual = 0.004071057403, Final residual = 4.79249226e-07, No Iterations 1
box   DILUPBiCGStab:  Solving for Uy, Initial residual = 0.006370817152, Final residual = 9.606673696e-07, No Iterations 1
box   DILUPBiCGStab:  Solving for Uz, Initial residual = 0.0158299327, Final residual = 2.104129791e-06, No Iterations 1
film  DILUPBiCGStab:  Solving for e, Initial residual = 0.0002888908396, Final residual = 2.301587523e-11, No Iterations 1
panel GAMG:  Solving for e, Initial residual = 0.00878508958, Final residual = 7.807579738e-12, No Iterations 1
box   DILUPBiCGStab:  Solving for h, Initial residual = 0.004403989559, Final residual = 1.334113552e-06, No Iterations 1
film  DILUPBiCGStab:  Solving for alpha, Initial residual = 0.0002760406755, Final residual = 2.267583256e-14, No Iterations 1
film  time step continuity errors : sum local = 9.01334987e-12, global = 2.296671859e-13, cumulative = 1.907846466e-08
box   GAMG:  Solving for p_rgh, Initial residual = 0.002842335602, Final residual = 1.036572819e-05, No Iterations 4
box   diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
box   time step continuity errors : sum local = 4.538744531e-07, global = 1.922637799e-08, cumulative = -6.612579497e-09
box   GAMG:  Solving for p_rgh, Initial residual = 1.283128787e-05, Final residual = 7.063185653e-07, No Iterations 2
box   diagonal:  Solving for rho, Initial residual = 0, Final residual = 0, No Iterations 0
box   time step continuity errors : sum local = 3.069629869e-08, global = 3.780547824e-10, cumulative = -6.234524715e-09
      ExecutionTime = 19.382601 s  ClockTime = 20 s

film  Courant Number mean: 0.0003684434169 max: 0.1840342756
panel Diffusion Number mean: 0.007352456305 max: 0.1276468109
box   Courant Number mean: 0.006292704463 max: 0.09016861809
      deltaT = 0.001550908752
      Time = 0.0844909s

where each line printed by each region solver is prefixed by the region name.
Global messages for the time-step and time are just prefixed with spaces to
align them with the region output.
This commit is contained in:
Henry Weller
2023-03-08 10:59:13 +00:00
parent 8397d21905
commit 4d63b39e3e
6 changed files with 353 additions and 47 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -84,7 +84,6 @@ Usage
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "solver.H"
#include "regionSolvers.H"
#include "pimpleMultiRegionControl.H"
#include "setDeltaT.H"
@ -98,33 +97,8 @@ int main(int argc, char *argv[])
#include "setRootCase.H"
#include "createTime.H"
regionSolvers regionSolvers(runTime);
PtrList<fvMesh> regions(regionSolvers.size());
PtrList<solver> solvers(regionSolvers.size());
forAll(regionSolvers, i)
{
regions.set
(
i,
new fvMesh
(
IOobject
(
regionSolvers[i].first(),
runTime.name(),
runTime,
IOobject::MUST_READ
)
)
);
solvers.set
(
i,
solver::New(regionSolvers[i].second(), regions[i])
);
}
// Create the region meshes and solvers
regionSolvers solvers(runTime);
// Create the outer PIMPLE loop and control structure
pimpleMultiRegionControl pimple(runTime, solvers);
@ -143,6 +117,8 @@ int main(int argc, char *argv[])
solvers[i].preSolve();
}
solvers.setGlobalPrefix();
// Adjust the time-step according to the solver maxDeltaT
adjustDeltaT(runTime, solvers);
@ -192,6 +168,8 @@ int main(int argc, char *argv[])
solvers[i].postSolve();
}
solvers.setGlobalPrefix();
runTime.write();
Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"

View File

@ -31,6 +31,8 @@ License
Foam::regionSolvers::regionSolvers(const Time& runTime)
{
List<Pair<word>> regionSolverNames;
if (runTime.controlDict().found("regionSolvers"))
{
const dictionary& regionSolversDict =
@ -41,10 +43,7 @@ Foam::regionSolvers::regionSolvers(const Time& runTime)
const word regionName(iter().keyword());
const word solverName(iter().stream());
// Load the solver library
solver::load(solverName);
append(Pair<word>(regionName, solverName));
regionSolverNames.append(Pair<word>(regionName, solverName));
}
}
else
@ -77,7 +76,10 @@ Foam::regionSolvers::regionSolvers(const Time& runTime)
const wordList& fluidRegions = regions["solid"];
forAll(fluidRegions, i)
{
append(Pair<word>(fluidRegions[i], "solid"));
regionSolverNames.append
(
Pair<word>(fluidRegions[i], "solid")
);
}
}
@ -86,7 +88,10 @@ Foam::regionSolvers::regionSolvers(const Time& runTime)
const wordList& fluidRegions = regions["fluid"];
forAll(fluidRegions, i)
{
append(Pair<word>(fluidRegions[i], "fluid"));
regionSolverNames.append
(
Pair<word>(fluidRegions[i], "fluid")
);
}
}
}
@ -98,6 +103,50 @@ Foam::regionSolvers::regionSolvers(const Time& runTime)
<< exit(FatalIOError);
}
}
regions_.setSize(regionSolverNames.size());
solvers_.setSize(regionSolverNames.size());
prefixes_.setSize(regionSolverNames.size());
string::size_type nRegionNameChars = 0;
forAll(regionSolverNames, i)
{
const word& regionName = regionSolverNames[i].first();
const word& solverName = regionSolverNames[i].second();
// Load the solver library
solver::load(solverName);
regions_.set
(
i,
new fvMesh
(
IOobject
(
regionName,
runTime.name(),
runTime,
IOobject::MUST_READ
)
)
);
solvers_.set(i, solver::New(solverName, regions_[i]));
prefixes_[i] = regionName;
nRegionNameChars = max(nRegionNameChars, regionName.size());
}
nRegionNameChars++;
prefix0_.append(nRegionNameChars, ' ');
forAll(regionSolverNames, i)
{
prefixes_[i].append(nRegionNameChars - prefixes_[i].size(), ' ');
}
}
@ -107,4 +156,33 @@ Foam::regionSolvers::~regionSolvers()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::regionSolvers::setGlobalPrefix() const
{
Sout.prefix() = prefix0_;
}
void Foam::regionSolvers::setPrefix(const label i) const
{
Sout.prefix() = prefixes_[i];
}
void Foam::regionSolvers::resetPrefix() const
{
Sout.prefix() = string::null;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
Foam::solver& Foam::regionSolvers::operator[](const label i)
{
setPrefix(i);
return solvers_[i];
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2022-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -25,7 +25,40 @@ Class
Foam::regionSolvers
Description
Simple class to hold the list of region solvers
Class to hold the lists of region meshes and solvers
Also provides loop and iteration functionality which automatically set the
region Info prefix for each of the solvers returned by the '[]' operator or
iterator.
Usage
Given the \c regionSolvers named solvers:
\verbatim
// Create the region meshes and solvers
regionSolvers solvers(runTime);
\endverbatim
The list of solvers can be looped over:
\verbatim
forAll(solvers, i)
{
solvers[i].momentumPredictor();
}
\endverbatim
where the '[]' operator sets the region Info prefix. After the loop the
region Info prefix remains set to the last region prefix and so for global
messages, e.g. the global time-step the Info prefix must be specifically
reset to spaces by calling the \c setGlobalPrefix() function.
Alternatively the list of solvers can be iterated over:
\verbatim
forAllIter(regionSolvers, solvers, solver)
{
solver->momentumPredictor();
}
\endverbatim
where the iterator increment sets the region \c Info prefix and at the end
automatically resets the \c Info prefix to spaces.
SourceFiles
regionSolvers.C
@ -35,24 +68,34 @@ SourceFiles
#ifndef regionSolvers_H
#define regionSolvers_H
#include "word.H"
#include "Pair.H"
#include "solver.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class Time;
/*---------------------------------------------------------------------------*\
Class regionSolvers Declaration
\*---------------------------------------------------------------------------*/
class regionSolvers
:
public List<Pair<word>>
{
// Private Member Data
//- Region meshes
PtrList<fvMesh> regions_;
//- Region solvers
PtrList<solver> solvers_;
//- Global space padding prefix
string prefix0_;
//- List of space padded region prefixes
stringList prefixes_;
public:
// Constructors
@ -68,12 +111,81 @@ public:
~regionSolvers();
// Member Functions
//- Return the number of region solvers
inline label size() const;
//- Set the Info prefix to space padding for global messages
void setGlobalPrefix() const;
//- Set the Info prefix to the space padded region name
void setPrefix(const label i) const;
//- Reset the Info prefix to null
void resetPrefix() const;
// Iterator
class iterator;
friend class iterator;
// Iterator class to loop over the solvers, setting the prefix for each
class iterator
{
// Private Data
//- Reference to the regionSolvers
regionSolvers& regionSolvers_;
//- Current solver index
label index_;
public:
friend class regionSolvers;
// Constructors
//- Construct for the regionSolvers
inline explicit iterator(regionSolvers&);
// Member Operators
inline bool operator==(const iterator&) const;
inline bool operator!=(const iterator&) const;
inline solver& operator*();
inline solver& operator()();
inline solver* operator->();
inline iterator operator++();
inline iterator operator++(int);
};
//- Return an iterator to begin traversing the solvers
inline iterator begin();
//- Return an iterator to end traversing the solvers
inline iterator end();
// Member Operators
//- Cast to the list of solvers
inline operator PtrList<solver>&();
//- Set the region i prefix and return the corresponding solver
solver& operator[](const label i);
//- Disallow default bitwise assignment
void operator=(const regionSolvers&) = delete;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "regionSolversI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -0,0 +1,138 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2023 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/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline Foam::label Foam::regionSolvers::size() const
{
return solvers_.size();
}
// * * * * * * * * * * * * * * * * Iterators * * * * * * * * * * * * * * * * //
inline Foam::regionSolvers::iterator::iterator(regionSolvers& rs)
:
regionSolvers_(rs),
index_(0)
{}
inline bool Foam::regionSolvers::iterator::operator==
(
const iterator& iter
) const
{
return index_ == iter.index_;
}
inline bool Foam::regionSolvers::iterator::operator!=
(
const iterator& iter
) const
{
return !operator==(iter);
}
inline Foam::solver& Foam::regionSolvers::iterator::operator*()
{
return regionSolvers_.solvers_[index_];
}
inline Foam::solver& Foam::regionSolvers::iterator::operator()()
{
return regionSolvers_.solvers_[index_];
}
inline Foam::solver* Foam::regionSolvers::iterator::operator->()
{
return regionSolvers_.solvers_(index_);
}
inline Foam::regionSolvers::iterator
Foam::regionSolvers::iterator::operator++()
{
if (++index_ >= regionSolvers_.solvers_.size())
{
// Set index to -1 to indicate end
index_ = -1;
// Reset the prefix to global space padding
regionSolvers_.setGlobalPrefix();
}
else
{
// Set the prefix for region corresponding to index_
regionSolvers_.setPrefix(index_);
}
return *this;
}
inline Foam::regionSolvers::iterator
Foam::regionSolvers::iterator::operator++(int)
{
iterator tmp(*this);
operator++();
return tmp;
}
inline Foam::regionSolvers::iterator Foam::regionSolvers::begin()
{
// Set the prefix for region 0
setPrefix(0);
// Return the iterator for region 0
return iterator(*this);
}
inline Foam::regionSolvers::iterator Foam::regionSolvers::end()
{
iterator endIter(*this);
// Set index to -1 to indicate end
endIter.index_ = -1;
return endIter;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
inline Foam::regionSolvers::operator PtrList<solver>&()
{
return solvers_;
}
// ************************************************************************* //