mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add static set/get dimensionSet::checking() method
- encapsulates toggling STYLE: noexcept for some Time methods
This commit is contained in:
@ -678,7 +678,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
// Disable dimension checking during operations
|
||||
dimensionSet::debug = false;
|
||||
dimensionSet::checking(false);
|
||||
|
||||
#include "createNamedMesh.H"
|
||||
|
||||
|
||||
@ -197,7 +197,6 @@ public:
|
||||
|
||||
//- Search the case for the time closest to the given time
|
||||
instant findClosestTime(const scalar t) const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2018 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -92,13 +92,13 @@ public:
|
||||
inline scalar timeOutputValue() const;
|
||||
|
||||
//- Return current time index
|
||||
inline label timeIndex() const;
|
||||
inline label timeIndex() const noexcept;
|
||||
|
||||
//- Return time step value
|
||||
inline scalar deltaTValue() const;
|
||||
inline scalar deltaTValue() const noexcept;
|
||||
|
||||
//- Return old time step value
|
||||
inline scalar deltaT0Value() const;
|
||||
inline scalar deltaT0Value() const noexcept;
|
||||
|
||||
//- Return time step
|
||||
inline dimensionedScalar deltaT() const;
|
||||
@ -109,12 +109,12 @@ public:
|
||||
|
||||
// Check
|
||||
|
||||
//- Return true if this is a write time
|
||||
inline bool writeTime() const;
|
||||
//- True if this is a write time
|
||||
inline bool writeTime() const noexcept;
|
||||
|
||||
//- Deprecated(2016-05) return true if this is a write time.
|
||||
// \deprecated(2016-05) - use writeTime() method
|
||||
inline bool outputTime() const { return this->writeTime(); }
|
||||
bool outputTime() const noexcept { return this->writeTime(); }
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016 OpenFOAM Foundation
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -33,19 +34,19 @@ inline Foam::scalar Foam::TimeState::timeOutputValue() const
|
||||
}
|
||||
|
||||
|
||||
inline Foam::label Foam::TimeState::timeIndex() const
|
||||
inline Foam::label Foam::TimeState::timeIndex() const noexcept
|
||||
{
|
||||
return timeIndex_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::scalar Foam::TimeState::deltaTValue() const
|
||||
inline Foam::scalar Foam::TimeState::deltaTValue() const noexcept
|
||||
{
|
||||
return deltaT_;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::scalar Foam::TimeState::deltaT0Value() const
|
||||
inline Foam::scalar Foam::TimeState::deltaT0Value() const noexcept
|
||||
{
|
||||
return deltaT0_;
|
||||
}
|
||||
@ -63,7 +64,7 @@ inline Foam::dimensionedScalar Foam::TimeState::deltaT0() const
|
||||
}
|
||||
|
||||
|
||||
inline bool Foam::TimeState::writeTime() const
|
||||
inline bool Foam::TimeState::writeTime() const noexcept
|
||||
{
|
||||
return writeTime_;
|
||||
}
|
||||
|
||||
@ -33,12 +33,6 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::timeSelector::timeSelector()
|
||||
:
|
||||
scalarRanges()
|
||||
{}
|
||||
|
||||
|
||||
Foam::timeSelector::timeSelector(const std::string& str)
|
||||
:
|
||||
scalarRanges(str)
|
||||
|
||||
@ -82,7 +82,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
// Forward Declarations
|
||||
class argList;
|
||||
class Time;
|
||||
|
||||
@ -98,11 +98,11 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
timeSelector();
|
||||
//- Default construct
|
||||
timeSelector() = default;
|
||||
|
||||
//- Construct by parsing string for time ranges
|
||||
timeSelector(const std::string& str);
|
||||
explicit timeSelector(const std::string& str);
|
||||
|
||||
|
||||
// Member Functions
|
||||
@ -165,7 +165,6 @@ public:
|
||||
Time& runTime,
|
||||
const argList& args
|
||||
);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -202,7 +202,7 @@ bool Foam::dimensionSet::operator!=(const dimensionSet& ds) const
|
||||
|
||||
bool Foam::dimensionSet::operator=(const dimensionSet& ds) const
|
||||
{
|
||||
if (dimensionSet::debug)
|
||||
if (dimensionSet::checking())
|
||||
{
|
||||
checkDims("(a = b)", *this, ds);
|
||||
}
|
||||
@ -213,7 +213,7 @@ bool Foam::dimensionSet::operator=(const dimensionSet& ds) const
|
||||
|
||||
bool Foam::dimensionSet::operator+=(const dimensionSet& ds) const
|
||||
{
|
||||
if (dimensionSet::debug)
|
||||
if (dimensionSet::checking())
|
||||
{
|
||||
checkDims("(a += b)", *this, ds);
|
||||
}
|
||||
@ -224,7 +224,7 @@ bool Foam::dimensionSet::operator+=(const dimensionSet& ds) const
|
||||
|
||||
bool Foam::dimensionSet::operator-=(const dimensionSet& ds) const
|
||||
{
|
||||
if (dimensionSet::debug)
|
||||
if (dimensionSet::checking())
|
||||
{
|
||||
checkDims("(a -= b)", *this, ds);
|
||||
}
|
||||
@ -253,7 +253,7 @@ bool Foam::dimensionSet::operator/=(const dimensionSet& ds)
|
||||
|
||||
Foam::dimensionSet Foam::min(const dimensionSet& ds1, const dimensionSet& ds2)
|
||||
{
|
||||
if (dimensionSet::debug)
|
||||
if (dimensionSet::checking())
|
||||
{
|
||||
checkDims("min(a, b)", ds1, ds2);
|
||||
}
|
||||
@ -264,7 +264,7 @@ Foam::dimensionSet Foam::min(const dimensionSet& ds1, const dimensionSet& ds2)
|
||||
|
||||
Foam::dimensionSet Foam::max(const dimensionSet& ds1, const dimensionSet& ds2)
|
||||
{
|
||||
if (dimensionSet::debug)
|
||||
if (dimensionSet::checking())
|
||||
{
|
||||
checkDims("max(a, b)", ds1, ds2);
|
||||
}
|
||||
@ -275,7 +275,7 @@ Foam::dimensionSet Foam::max(const dimensionSet& ds1, const dimensionSet& ds2)
|
||||
|
||||
Foam::dimensionSet Foam::clip(const dimensionSet& ds1, const dimensionSet& ds2)
|
||||
{
|
||||
if (dimensionSet::debug)
|
||||
if (dimensionSet::checking())
|
||||
{
|
||||
checkDims("clip(a, b)", ds1, ds2);
|
||||
}
|
||||
@ -325,7 +325,7 @@ Foam::dimensionSet Foam::pow
|
||||
const dimensionedScalar& dS
|
||||
)
|
||||
{
|
||||
if (dimensionSet::debug && !dS.dimensions().dimensionless())
|
||||
if (dimensionSet::checking() && !dS.dimensions().dimensionless())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Exponent of pow is not dimensionless" << endl
|
||||
@ -344,7 +344,7 @@ Foam::dimensionSet Foam::pow
|
||||
{
|
||||
if
|
||||
(
|
||||
dimensionSet::debug
|
||||
dimensionSet::checking()
|
||||
&& !dS.dimensions().dimensionless()
|
||||
&& !ds.dimensionless()
|
||||
)
|
||||
@ -483,7 +483,7 @@ Foam::dimensionSet Foam::inv(const dimensionSet& ds)
|
||||
|
||||
Foam::dimensionSet Foam::trans(const dimensionSet& ds)
|
||||
{
|
||||
if (dimensionSet::debug && !ds.dimensionless())
|
||||
if (dimensionSet::checking() && !ds.dimensionless())
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Argument of trancendental function not dimensionless" << nl
|
||||
@ -496,7 +496,7 @@ Foam::dimensionSet Foam::trans(const dimensionSet& ds)
|
||||
|
||||
Foam::dimensionSet Foam::atan2(const dimensionSet& ds1, const dimensionSet& ds2)
|
||||
{
|
||||
if (dimensionSet::debug)
|
||||
if (dimensionSet::checking())
|
||||
{
|
||||
checkDims("atan2(a, b)", ds1, ds2);
|
||||
}
|
||||
@ -507,7 +507,7 @@ Foam::dimensionSet Foam::atan2(const dimensionSet& ds1, const dimensionSet& ds2)
|
||||
|
||||
Foam::dimensionSet Foam::hypot(const dimensionSet& ds1, const dimensionSet& ds2)
|
||||
{
|
||||
if (dimensionSet::debug)
|
||||
if (dimensionSet::checking())
|
||||
{
|
||||
checkDims("hypot(a, b)", ds1, ds2);
|
||||
}
|
||||
@ -548,7 +548,7 @@ Foam::dimensionSet Foam::operator+
|
||||
const dimensionSet& ds2
|
||||
)
|
||||
{
|
||||
if (dimensionSet::debug)
|
||||
if (dimensionSet::checking())
|
||||
{
|
||||
checkDims("(a + b)", ds1, ds2);
|
||||
}
|
||||
@ -563,7 +563,7 @@ Foam::dimensionSet Foam::operator-
|
||||
const dimensionSet& ds2
|
||||
)
|
||||
{
|
||||
if (dimensionSet::debug)
|
||||
if (dimensionSet::checking())
|
||||
{
|
||||
checkDims("(a - b)", ds1, ds2);
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -54,7 +54,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declarations
|
||||
// Forward Declarations
|
||||
|
||||
class dimensionSet;
|
||||
class dimensionSets;
|
||||
@ -97,17 +97,17 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
//- The array of dimension exponents
|
||||
list_type exponents_;
|
||||
|
||||
|
||||
// Private classes
|
||||
// Private Classes
|
||||
|
||||
class tokeniser
|
||||
{
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
Istream& is_;
|
||||
|
||||
@ -171,6 +171,24 @@ public:
|
||||
ClassName("dimensionSet");
|
||||
|
||||
|
||||
// Static Functions
|
||||
|
||||
//- Turn dimension checking on/off.
|
||||
// \return the previous value
|
||||
static bool checking(const bool on) noexcept
|
||||
{
|
||||
bool old(debug);
|
||||
debug = static_cast<int>(on);
|
||||
return old;
|
||||
}
|
||||
|
||||
//- True if dimension checking is enabled (the usual default)
|
||||
static bool checking() noexcept
|
||||
{
|
||||
return static_cast<bool>(debug);
|
||||
}
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Default construct (dimensionless).
|
||||
|
||||
@ -100,7 +100,7 @@ inline dimensioned<MinMax<T>> makeDimensionedMinMax
|
||||
const dimensioned<T>& maxVal
|
||||
)
|
||||
{
|
||||
// Dimension check when (dimensionSet::debug)
|
||||
// Dimension check when dimensionSet::checking()
|
||||
return dimensioned<MinMax<T>>
|
||||
(
|
||||
name,
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016-2017 Wikki Ltd
|
||||
Copyright (C) 2019-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -1049,7 +1049,11 @@ void Foam::checkMethod
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
if (dimensionSet::debug && fam1.dimensions() != fam2.dimensions())
|
||||
if
|
||||
(
|
||||
dimensionSet::checking()
|
||||
&& fam1.dimensions() != fam2.dimensions()
|
||||
)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "incompatible dimensions for operation "
|
||||
@ -1070,7 +1074,11 @@ void Foam::checkMethod
|
||||
const char* op
|
||||
)
|
||||
{
|
||||
if (dimensionSet::debug && fam.dimensions()/dimArea != vf.dimensions())
|
||||
if
|
||||
(
|
||||
dimensionSet::checking()
|
||||
&& fam.dimensions()/dimArea != vf.dimensions()
|
||||
)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "incompatible dimensions for operation "
|
||||
@ -1091,7 +1099,11 @@ void Foam::checkMethod
|
||||
const char* op
|
||||
)
|
||||
{
|
||||
if (dimensionSet::debug && fam.dimensions()/dimArea != dt.dimensions())
|
||||
if
|
||||
(
|
||||
dimensionSet::checking()
|
||||
&& fam.dimensions()/dimArea != dt.dimensions()
|
||||
)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "incompatible dimensions for operation "
|
||||
|
||||
@ -405,8 +405,7 @@ Foam::tmp<GeomField> Foam::expressions::fvExprDriver::getOrReadFieldImpl
|
||||
}
|
||||
|
||||
// Switch dimension checking off
|
||||
const int oldDebug = dimensionSet::debug;
|
||||
dimensionSet::debug = 0;
|
||||
const bool oldDimChecking = dimensionSet::checking(false);
|
||||
|
||||
// go through ALL old times
|
||||
GeomField* fp = &(fld);
|
||||
@ -418,7 +417,7 @@ Foam::tmp<GeomField> Foam::expressions::fvExprDriver::getOrReadFieldImpl
|
||||
}
|
||||
|
||||
// Restore old value of dimension checking
|
||||
dimensionSet::debug = oldDebug;
|
||||
dimensionSet::checking(oldDimChecking);
|
||||
}
|
||||
}
|
||||
else if (mandatory)
|
||||
|
||||
@ -1992,7 +1992,11 @@ void Foam::checkMethod
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
if (dimensionSet::debug && fvm1.dimensions() != fvm2.dimensions())
|
||||
if
|
||||
(
|
||||
dimensionSet::checking()
|
||||
&& fvm1.dimensions() != fvm2.dimensions()
|
||||
)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "incompatible dimensions for operation "
|
||||
@ -2013,7 +2017,11 @@ void Foam::checkMethod
|
||||
const char* op
|
||||
)
|
||||
{
|
||||
if (dimensionSet::debug && fvm.dimensions()/dimVolume != df.dimensions())
|
||||
if
|
||||
(
|
||||
dimensionSet::checking()
|
||||
&& fvm.dimensions()/dimVolume != df.dimensions()
|
||||
)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< endl << " "
|
||||
@ -2033,7 +2041,11 @@ void Foam::checkMethod
|
||||
const char* op
|
||||
)
|
||||
{
|
||||
if (dimensionSet::debug && fvm.dimensions()/dimVolume != dt.dimensions())
|
||||
if
|
||||
(
|
||||
dimensionSet::checking()
|
||||
&& fvm.dimensions()/dimVolume != dt.dimensions()
|
||||
)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "incompatible dimensions for operation "
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2019 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2021 OpenCFD Ltd.
|
||||
------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -50,13 +50,12 @@ bool Foam::functionObjects::log::calc()
|
||||
{
|
||||
const volScalarField& x = lookupObject<volScalarField>(fieldName_);
|
||||
|
||||
// Cache the current debug setting for dimensionSet
|
||||
const bool dimensionSetDebug = dimensionSet::debug;
|
||||
|
||||
// Switch-off dimension checking if requested
|
||||
const bool oldDimChecking = dimensionSet::checking();
|
||||
|
||||
if (!checkDimensions_)
|
||||
{
|
||||
dimensionSet::debug = 0;
|
||||
dimensionSet::checking(false);
|
||||
}
|
||||
|
||||
bool stored = store
|
||||
@ -68,7 +67,7 @@ bool Foam::functionObjects::log::calc()
|
||||
// Reinstate dimension checking
|
||||
if (!checkDimensions_)
|
||||
{
|
||||
dimensionSet::debug = dimensionSetDebug;
|
||||
dimensionSet::checking(oldDimChecking);
|
||||
}
|
||||
|
||||
return stored;
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2021 OpenCFD Ltd.
|
||||
------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -49,13 +49,12 @@ bool Foam::functionObjects::pow::calc()
|
||||
{
|
||||
const volScalarField& x = lookupObject<volScalarField>(fieldName_);
|
||||
|
||||
// Cache the current debug setting for dimensionSet
|
||||
const bool dimensionSetDebug = dimensionSet::debug;
|
||||
|
||||
// Switch-off dimension checking if requested
|
||||
const bool oldDimChecking = dimensionSet::checking();
|
||||
|
||||
if (!checkDimensions_)
|
||||
{
|
||||
dimensionSet::debug = 0;
|
||||
dimensionSet::checking(false);
|
||||
}
|
||||
|
||||
bool stored = store
|
||||
@ -67,7 +66,7 @@ bool Foam::functionObjects::pow::calc()
|
||||
// Reinstate dimension checking
|
||||
if (!checkDimensions_)
|
||||
{
|
||||
dimensionSet::debug = dimensionSetDebug;
|
||||
dimensionSet::checking(oldDimChecking);
|
||||
}
|
||||
|
||||
return stored;
|
||||
|
||||
Reference in New Issue
Block a user