ENH: use static to define default blockMesh verbosity

- make handling of verbosity more consistent.

  Make all setter return the old value, remove (unused) default
  parameter as being counter-intuitive.  This makes it easier to
  restore the original values.

  For example,

     const bool oldVerbose = sampler.verbose(false);
     ...
     sampler.verbose(oldVerbose);
This commit is contained in:
Mark Olesen
2020-10-25 21:45:21 +01:00
parent f959c8eb36
commit f999013f41
22 changed files with 115 additions and 67 deletions

View File

@ -169,7 +169,7 @@ bool Foam::functionObjects::Curle::read(const dictionary& dict)
); );
// Use outputDir/TIME/surface-name // Use outputDir/TIME/surface-name
surfaceWriterPtr_->useTimeDir() = true; surfaceWriterPtr_->useTimeDir(true);
} }
} }

View File

@ -969,7 +969,7 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::read
if (debug) if (debug)
{ {
surfaceWriterPtr_->verbose() = true; surfaceWriterPtr_->verbose(true);
} }
if (surfaceWriterPtr_->enabled()) if (surfaceWriterPtr_->enabled())

View File

@ -109,9 +109,11 @@ Foam::areaWrite::areaWrite
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::areaWrite::verbose(const bool verbosity) bool Foam::areaWrite::verbose(const bool on)
{ {
verbose_ = verbosity; bool old(verbose_);
verbose_ = on;
return old;
} }
@ -188,8 +190,8 @@ bool Foam::areaWrite::read(const dictionary& dict)
auto surfWriter = surfaceWriter::New(writerType, writerOptions); auto surfWriter = surfaceWriter::New(writerType, writerOptions);
// Use outputDir/TIME/surface-name // Use outputDir/TIME/surface-name
surfWriter->useTimeDir() = true; surfWriter->useTimeDir(true);
surfWriter->verbose() = verbose_; surfWriter->verbose(verbose_);
writers_.set(areaName, surfWriter); writers_.set(areaName, surfWriter);
} }

View File

@ -205,8 +205,9 @@ public:
// Member Functions // Member Functions
//- Set verbosity level //- Enable/disable verbose output
void verbose(const bool verbosity = true); // \return old value
bool verbose(const bool on);
//- Read the areaWrite dictionary //- Read the areaWrite dictionary
virtual bool read(const dictionary& dict); virtual bool read(const dictionary& dict);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2019 OpenCFD Ltd. Copyright (C) 2016-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -204,7 +204,7 @@ void Foam::FacePostProcessing<CloudType>::write()
if (debug) if (debug)
{ {
writer->verbose() = true; writer->verbose(true);
} }
writer->open writer->open

View File

@ -474,7 +474,7 @@ void Foam::ParticleCollector<CloudType>::write()
if (debug) if (debug)
{ {
writer->verbose() = true; writer->verbose(true);
} }
writer->open writer->open

View File

@ -36,6 +36,8 @@ namespace Foam
defineDebugSwitch(blockMesh, 0); defineDebugSwitch(blockMesh, 0);
} }
bool Foam::blockMesh::verboseOutput = true;
const Foam::Enum<Foam::blockMesh::mergeStrategy> const Foam::Enum<Foam::blockMesh::mergeStrategy>
Foam::blockMesh::strategyNames_ Foam::blockMesh::strategyNames_
@ -55,7 +57,7 @@ Foam::blockMesh::blockMesh
) )
: :
meshDict_(dict), meshDict_(dict),
verboseOutput(meshDict_.getOrDefault("verbose", true)), verbose_(meshDict_.getOrDefault("verbose", verboseOutput)),
checkFaceCorrespondence_ checkFaceCorrespondence_
( (
meshDict_.getOrDefault("checkFaceCorrespondence", true) meshDict_.getOrDefault("checkFaceCorrespondence", true)
@ -117,14 +119,14 @@ bool Foam::blockMesh::valid() const noexcept
bool Foam::blockMesh::verbose() const noexcept bool Foam::blockMesh::verbose() const noexcept
{ {
return verboseOutput; return verbose_;
} }
bool Foam::blockMesh::verbose(const bool on) noexcept bool Foam::blockMesh::verbose(const bool on) noexcept
{ {
bool old(verboseOutput); bool old(verbose_);
verboseOutput = on; verbose_ = on;
return old; return old;
} }

View File

@ -63,7 +63,8 @@ SourceFiles
#define blockMesh_H #define blockMesh_H
#include "Enum.H" #include "Enum.H"
#include "blockList.H" #include "block.H"
#include "PtrList.H"
#include "searchableSurfaces.H" #include "searchableSurfaces.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "IOdictionary.H" #include "IOdictionary.H"
@ -82,10 +83,16 @@ namespace Foam
class blockMesh class blockMesh
: :
public blockList public PtrList<block>
{ {
public: public:
// Typedefs
//- The list of blocks is stored as a PtrList
typedef PtrList<block> blockList;
// Data Types // Data Types
//- The block merging strategy //- The block merging strategy
@ -110,8 +117,8 @@ private:
//- Reference to mesh dictionary //- Reference to mesh dictionary
const IOdictionary& meshDict_; const IOdictionary& meshDict_;
//- Switch for verbose output //- Output verbosity
bool verboseOutput; bool verbose_;
//- Switch checking face consistency (defaults to true) //- Switch checking face consistency (defaults to true)
bool checkFaceCorrespondence_; bool checkFaceCorrespondence_;
@ -218,6 +225,12 @@ private:
public: public:
// Static Data
//- The default verbosity (true)
static bool verboseOutput;
//- Runtime type information //- Runtime type information
ClassName("blockMesh"); ClassName("blockMesh");
@ -301,10 +314,10 @@ public:
// Verbosity // Verbosity
//- Verbose information? //- Verbose output
bool verbose() const noexcept; bool verbose() const noexcept;
//- Enable/disable verbose information about the progress //- Enable/disable verbose output
// \return old value // \return old value
bool verbose(const bool on) noexcept; bool verbose(const bool on) noexcept;

View File

@ -143,7 +143,7 @@ void Foam::blockMesh::check(const polyMesh& bm, const dictionary& dict) const
} }
if (verboseOutput) if (verbose_)
{ {
Info<< nl << tab << "Basic statistics" << nl Info<< nl << tab << "Basic statistics" << nl
<< tab << tab << "Number of internal faces : " << tab << tab << "Number of internal faces : "
@ -219,7 +219,7 @@ void Foam::blockMesh::check(const polyMesh& bm, const dictionary& dict) const
} }
} }
if (verboseOutput) if (verbose_)
{ {
Info<< endl; Info<< endl;
} }

View File

@ -36,7 +36,7 @@ void Foam::blockMesh::createPoints() const
{ {
const blockList& blocks = *this; const blockList& blocks = *this;
if (verboseOutput) if (verbose_)
{ {
Info<< "Creating points with scale " << scaleFactor_ << endl; Info<< "Creating points with scale " << scaleFactor_ << endl;
} }
@ -47,7 +47,7 @@ void Foam::blockMesh::createPoints() const
{ {
const pointField& blockPoints = blocks[blocki].points(); const pointField& blockPoints = blocks[blocki].points();
if (verboseOutput) if (verbose_)
{ {
const label nx = blocks[blocki].density().x(); const label nx = blocks[blocki].density().x();
const label ny = blocks[blocki].density().y(); const label ny = blocks[blocki].density().y();
@ -102,7 +102,7 @@ void Foam::blockMesh::createCells() const
const blockList& blocks = *this; const blockList& blocks = *this;
const cellModel& hex = cellModel::ref(cellModel::HEX); const cellModel& hex = cellModel::ref(cellModel::HEX);
if (verboseOutput) if (verbose_)
{ {
Info<< "Creating cells" << endl; Info<< "Creating cells" << endl;
} }
@ -257,7 +257,7 @@ void Foam::blockMesh::createPatches() const
{ {
const polyPatchList& topoPatches = topology().boundaryMesh(); const polyPatchList& topoPatches = topology().boundaryMesh();
if (verboseOutput) if (verbose_)
{ {
Info<< "Creating patches" << endl; Info<< "Creating patches" << endl;
} }
@ -278,7 +278,7 @@ Foam::blockMesh::mesh(const IOobject& io) const
{ {
const blockMesh& blkMesh = *this; const blockMesh& blkMesh = *this;
if (verboseOutput) if (verbose_)
{ {
Info<< nl << "Creating polyMesh from blockMesh" << endl; Info<< nl << "Creating polyMesh from blockMesh" << endl;
} }
@ -303,7 +303,7 @@ Foam::blockMesh::mesh(const IOobject& io) const
{ {
polyMesh& pmesh = *meshPtr; polyMesh& pmesh = *meshPtr;
if (verboseOutput) if (verbose_)
{ {
Info<< "Adding cell zones" << endl; Info<< "Adding cell zones" << endl;
} }
@ -340,7 +340,7 @@ Foam::blockMesh::mesh(const IOobject& io) const
zoneMap.insert(zoneName, zonei); zoneMap.insert(zoneName, zonei);
++freeZonei; ++freeZonei;
if (verboseOutput) if (verbose_)
{ {
Info<< " " << zonei << '\t' << zoneName << endl; Info<< " " << zonei << '\t' << zoneName << endl;
} }

View File

@ -34,7 +34,7 @@ void Foam::blockMesh::calcGeometricalMerge()
{ {
const blockList& blocks = *this; const blockList& blocks = *this;
if (verboseOutput) if (verbose_)
{ {
Info<< "Creating block offsets" << endl; Info<< "Creating block offsets" << endl;
} }
@ -53,7 +53,7 @@ void Foam::blockMesh::calcGeometricalMerge()
} }
if (verboseOutput) if (verbose_)
{ {
Info<< "Creating merge list (geometric search).." << flush; Info<< "Creating merge list (geometric search).." << flush;
} }
@ -407,7 +407,7 @@ void Foam::blockMesh::calcGeometricalMerge()
} }
} }
} }
if (verboseOutput) if (verbose_)
{ {
Info<< '.' << flush; Info<< '.' << flush;
} }
@ -421,7 +421,7 @@ void Foam::blockMesh::calcGeometricalMerge()
} }
while (changedPointMerge); while (changedPointMerge);
if (verboseOutput) if (verbose_)
{ {
Info<< endl; Info<< endl;
} }

View File

@ -308,7 +308,7 @@ void Foam::blockMesh::calcTopologicalMerge()
const blockList& blocks = *this; const blockList& blocks = *this;
if (verboseOutput) if (verbose_)
{ {
Info<< "Creating block offsets" << endl; Info<< "Creating block offsets" << endl;
} }
@ -326,7 +326,7 @@ void Foam::blockMesh::calcTopologicalMerge()
nCells_ += blocks[blocki].nCells(); nCells_ += blocks[blocki].nCells();
} }
if (verboseOutput) if (verbose_)
{ {
Info<< "Creating merge list (topological search).." << flush; Info<< "Creating merge list (topological search).." << flush;
} }
@ -547,7 +547,7 @@ void Foam::blockMesh::calcTopologicalMerge()
} }
} }
if (verboseOutput) if (verbose_)
{ {
Info<< '.' << flush; Info<< '.' << flush;
} }
@ -561,7 +561,7 @@ void Foam::blockMesh::calcTopologicalMerge()
} while (changedPointMerge); } while (changedPointMerge);
if (verboseOutput) if (verbose_)
{ {
Info<< endl; Info<< endl;
} }

View File

@ -369,7 +369,7 @@ Foam::autoPtr<Foam::polyMesh> Foam::blockMesh::createTopology
// Read the block edges // Read the block edges
if (meshDescription.found("edges")) if (meshDescription.found("edges"))
{ {
if (verboseOutput) if (verbose_)
{ {
Info<< "Creating block edges" << endl; Info<< "Creating block edges" << endl;
} }
@ -382,7 +382,7 @@ Foam::autoPtr<Foam::polyMesh> Foam::blockMesh::createTopology
edges_.transfer(edges); edges_.transfer(edges);
} }
else if (verboseOutput) else if (verbose_)
{ {
Info<< "No non-linear block edges defined" << endl; Info<< "No non-linear block edges defined" << endl;
} }
@ -391,7 +391,7 @@ Foam::autoPtr<Foam::polyMesh> Foam::blockMesh::createTopology
// Read the block faces // Read the block faces
if (meshDescription.found("faces")) if (meshDescription.found("faces"))
{ {
if (verboseOutput) if (verbose_)
{ {
Info<< "Creating block faces" << endl; Info<< "Creating block faces" << endl;
} }
@ -404,14 +404,14 @@ Foam::autoPtr<Foam::polyMesh> Foam::blockMesh::createTopology
faces_.transfer(faces); faces_.transfer(faces);
} }
else if (verboseOutput) else if (verbose_)
{ {
Info<< "No non-planar block faces defined" << endl; Info<< "No non-planar block faces defined" << endl;
} }
// Create the blocks // Create the blocks
if (verboseOutput) if (verbose_)
{ {
Info<< "Creating topology blocks" << endl; Info<< "Creating topology blocks" << endl;
} }
@ -430,7 +430,7 @@ Foam::autoPtr<Foam::polyMesh> Foam::blockMesh::createTopology
// Create the patches // Create the patches
if (verboseOutput) if (verbose_)
{ {
Info<< "Creating topology patches" << endl; Info<< "Creating topology patches" << endl;
} }

View File

@ -41,10 +41,6 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::blockVertex::blockVertex()
{}
Foam::autoPtr<Foam::blockVertex> Foam::blockVertex::clone() const Foam::autoPtr<Foam::blockVertex> Foam::blockVertex::clone() const
{ {
NotImplemented; NotImplemented;
@ -103,7 +99,11 @@ Foam::autoPtr<Foam::blockVertex> Foam::blockVertex::New
} }
Foam::label Foam::blockVertex::read(Istream& is, const dictionary& dict) Foam::label Foam::blockVertex::read
(
Istream& is,
const dictionary& dict
)
{ {
const dictionary* varDictPtr = dict.findDict("namedVertices"); const dictionary* varDictPtr = dict.findDict("namedVertices");
if (varDictPtr) if (varDictPtr)

View File

@ -76,8 +76,8 @@ public:
// Constructors // Constructors
//- Construct null //- Default construct
blockVertex(); blockVertex() noexcept = default;
//- Clone function //- Clone function
virtual autoPtr<blockVertex> clone() const; virtual autoPtr<blockVertex> clone() const;

View File

@ -456,7 +456,7 @@ bool surfaceNoise::read(const dictionary& dict)
); );
// Use outputDir/TIME/surface-name // Use outputDir/TIME/surface-name
writerPtr_->useTimeDir() = true; writerPtr_->useTimeDir(true);
return true; return true;
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2018 OpenCFD Ltd. Copyright (C) 2015-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -150,9 +150,11 @@ Foam::sampledSets::sampledSets
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::sampledSets::verbose(const bool verbosity) bool Foam::sampledSets::verbose(const bool on)
{ {
verbose_ = verbosity; bool old(verbose_);
verbose_ = on;
return old;
} }

View File

@ -283,8 +283,9 @@ public:
// Member Functions // Member Functions
//- Set verbosity level //- Enable/disable verbose output
void verbose(const bool verbosity = true); // \return old value
bool verbose(const bool on);
//- Read the sampledSets //- Read the sampledSets
virtual bool read(const dictionary&); virtual bool read(const dictionary&);

View File

@ -270,9 +270,11 @@ Foam::sampledSurfaces::sampledSurfaces
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::sampledSurfaces::verbose(const bool verbosity) bool Foam::sampledSurfaces::verbose(const bool on)
{ {
verbose_ = verbosity; bool old(verbose_);
verbose_ = on;
return old;
} }
@ -361,8 +363,8 @@ bool Foam::sampledSurfaces::read(const dictionary& dict)
writers_[surfi].isPointData() = surfs[surfi].interpolate(); writers_[surfi].isPointData() = surfs[surfi].interpolate();
// Use outputDir/TIME/surface-name // Use outputDir/TIME/surface-name
writers_[surfi].useTimeDir() = true; writers_[surfi].useTimeDir(true);
writers_[surfi].verbose() = verbose_; writers_[surfi].verbose(verbose_);
++surfi; ++surfi;
} }
@ -427,8 +429,8 @@ bool Foam::sampledSurfaces::read(const dictionary& dict)
writers_[surfi].isPointData() = surfs[surfi].interpolate(); writers_[surfi].isPointData() = surfs[surfi].interpolate();
// Use outputDir/TIME/surface-name // Use outputDir/TIME/surface-name
writers_[surfi].useTimeDir() = true; writers_[surfi].useTimeDir(true);
writers_[surfi].verbose() = verbose_; writers_[surfi].verbose(verbose_);
++surfi; ++surfi;
} }

View File

@ -348,8 +348,9 @@ public:
// Member Functions // Member Functions
//- Set verbosity level //- Enable/disable verbose output
void verbose(const bool verbosity = true); // \return old value
bool verbose(const bool on);
//- Read the sampledSurfaces dictionary //- Read the sampledSurfaces dictionary
virtual bool read(const dictionary& dict); virtual bool read(const dictionary& dict);

View File

@ -391,13 +391,21 @@ public:
//- Should a time directory be spliced into the output path? //- Should a time directory be spliced into the output path?
inline bool useTimeDir() const; inline bool useTimeDir() const;
//- Enable/disable use of spliced output path
// \return old value
inline bool useTimeDir(const bool on);
//- Change handling of spliced output path. //- Change handling of spliced output path.
inline bool& useTimeDir(); inline bool& useTimeDir();
//- Get output verbosity //- Get output verbosity
inline bool verbose() const; inline bool verbose() const;
//- Set output verbosity //- Enable/disable verbose output
// \return old value
inline bool verbose(const bool on);
//- Access output verbosity
inline bool& verbose(); inline bool& verbose();
//- The current value of the point merge dimension (metre) //- The current value of the point merge dimension (metre)

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2020 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -57,6 +57,14 @@ inline bool Foam::surfaceWriter::useTimeDir() const
} }
inline bool Foam::surfaceWriter::useTimeDir(const bool on)
{
bool old(useTimeDir_);
useTimeDir_ = on;
return old;
}
inline bool& Foam::surfaceWriter::useTimeDir() inline bool& Foam::surfaceWriter::useTimeDir()
{ {
return useTimeDir_; return useTimeDir_;
@ -69,6 +77,14 @@ inline bool Foam::surfaceWriter::verbose() const
} }
inline bool Foam::surfaceWriter::verbose(const bool on)
{
bool old(verbose_);
verbose_ = on;
return old;
}
inline bool& Foam::surfaceWriter::verbose() inline bool& Foam::surfaceWriter::verbose()
{ {
return verbose_; return verbose_;