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
surfaceWriterPtr_->useTimeDir() = true;
surfaceWriterPtr_->useTimeDir(true);
}
}

View File

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

View File

@ -109,9 +109,11 @@ Foam::areaWrite::areaWrite
// * * * * * * * * * * * * * * * 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);
// Use outputDir/TIME/surface-name
surfWriter->useTimeDir() = true;
surfWriter->verbose() = verbose_;
surfWriter->useTimeDir(true);
surfWriter->verbose(verbose_);
writers_.set(areaName, surfWriter);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -41,10 +41,6 @@ namespace Foam
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::blockVertex::blockVertex()
{}
Foam::autoPtr<Foam::blockVertex> Foam::blockVertex::clone() const
{
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");
if (varDictPtr)

View File

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

View File

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

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2018 OpenCFD Ltd.
Copyright (C) 2015-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -150,9 +150,11 @@ Foam::sampledSets::sampledSets
// * * * * * * * * * * * * * * * 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
//- Set verbosity level
void verbose(const bool verbosity = true);
//- Enable/disable verbose output
// \return old value
bool verbose(const bool on);
//- Read the sampledSets
virtual bool read(const dictionary&);

View File

@ -270,9 +270,11 @@ Foam::sampledSurfaces::sampledSurfaces
// * * * * * * * * * * * * * * * 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();
// Use outputDir/TIME/surface-name
writers_[surfi].useTimeDir() = true;
writers_[surfi].verbose() = verbose_;
writers_[surfi].useTimeDir(true);
writers_[surfi].verbose(verbose_);
++surfi;
}
@ -427,8 +429,8 @@ bool Foam::sampledSurfaces::read(const dictionary& dict)
writers_[surfi].isPointData() = surfs[surfi].interpolate();
// Use outputDir/TIME/surface-name
writers_[surfi].useTimeDir() = true;
writers_[surfi].verbose() = verbose_;
writers_[surfi].useTimeDir(true);
writers_[surfi].verbose(verbose_);
++surfi;
}

View File

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

View File

@ -391,13 +391,21 @@ public:
//- Should a time directory be spliced into the output path?
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.
inline bool& useTimeDir();
//- Get output verbosity
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();
//- The current value of the point merge dimension (metre)

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
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()
{
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()
{
return verbose_;