ENH: lazier demand-driven evaluation in faOption

STYLE: namespace qualifiers on fa/fv option
This commit is contained in:
Mark Olesen
2021-05-02 13:10:13 +02:00
parent 0abafd98c7
commit 0a5a0c29d7
32 changed files with 185 additions and 136 deletions

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -40,17 +40,6 @@ namespace Foam
}
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
void Foam::fa::option::constructMeshObjects()
{
regionMeshPtr_.reset(new faMesh(mesh_));
vsmPtr_.reset(new volSurfaceMapping(regionMeshPtr_()));
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fa::option::option
@ -67,16 +56,15 @@ Foam::fa::option::option
patch_(patch),
dict_(dict),
coeffs_(dict.optionalSubDict(modelType + "Coeffs")),
active_(dict.getOrDefault<Switch>("active", true)),
fieldNames_(),
applied_(),
regionName_(dict.get<word>("region")),
regionMeshPtr_(nullptr),
vsmPtr_(nullptr)
vsmPtr_(nullptr),
active_(dict.getOrDefault("active", true)),
log(true)
{
constructMeshObjects();
Info<< incrIndent << indent << "Source: " << name_ << endl << decrIndent;
Log << incrIndent << indent << "Source: " << name_ << endl << decrIndent;
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -75,13 +75,12 @@ SourceFiles
#ifndef faOption_H
#define faOption_H
#include "faMatrices.H"
#include "areaFields.H"
#include "faMatricesFwd.H"
#include "areaFieldsFwd.H"
#include "dictionary.H"
#include "Switch.H"
#include "runTimeSelectionTables.H"
#include "fvMesh.H"
#include "volSurfaceMapping.H"
#include "runTimeSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -124,27 +123,35 @@ protected:
//- Dictionary containing source coefficients
dictionary coeffs_;
//- Source active flag
Switch active_;
//- Field names to apply source to - populated by derived models
wordList fieldNames_;
//- Applied flag list - corresponds to each fieldNames_ entry
List<bool> applied_;
//- Region name
//- Region name (finite-area)
word regionName_;
//- Pointer to the region mesh database
autoPtr<faMesh> regionMeshPtr_;
private:
//-Volume-to surface mapping
autoPtr<volSurfaceMapping> vsmPtr_;
// Private Data
//- Demand-driven: pointer to region mesh database
mutable autoPtr<faMesh> regionMeshPtr_;
//- Demand-driven: volume-to-surface mapping
mutable autoPtr<volSurfaceMapping> vsmPtr_;
//- Source active flag
bool active_;
public:
//- Switch write log to Info
bool log;
//- Runtime type information
TypeName("option");
@ -188,7 +195,6 @@ public:
//- on the freestore from an Istream
class iNew
{
//- Reference to the patch
const fvPatch& patch_;
@ -239,37 +245,37 @@ public:
// Access
//- Return const access to the source name
inline const word& name() const;
inline const word& name() const noexcept;
//- Return const access to the mesh database
inline const fvMesh& mesh() const;
inline const fvMesh& mesh() const noexcept;
//- Return const access to fvPatch
inline const fvPatch& patch() const;
inline const fvPatch& patch() const noexcept;
//- Return dictionary
inline const dictionary& coeffs() const;
inline const dictionary& coeffs() const noexcept;
//- Return const access to the source active flag
inline bool active() const;
inline bool active() const noexcept;
//- Set the applied flag to true for field index fieldi
inline void setApplied(const label fieldi);
//- Return the region mesh database
//- The region name
inline const word& regionName() const noexcept;
//- Return the region mesh database (demand-driven)
inline const faMesh& regionMesh() const;
//- Return volSurfaceMapping
//- Return volSurfaceMapping (demand-driven)
inline const volSurfaceMapping& vsm() const;
//- Region name
inline const word& regionName() const;
// Edit
//- Return access to the source active flag
inline Switch& active();
//- Change source active flag, return previous value
inline bool active(const bool on) noexcept;
// Checks

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,49 +27,51 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::word& Foam::fa::option::name() const
inline const Foam::word& Foam::fa::option::name() const noexcept
{
return name_;
}
inline const Foam::fvMesh& Foam::fa::option::mesh() const
inline const Foam::fvMesh& Foam::fa::option::mesh() const noexcept
{
return mesh_;
}
inline const Foam::fvPatch& Foam::fa::option::patch() const
inline const Foam::fvPatch& Foam::fa::option::patch() const noexcept
{
return patch_;
}
inline const Foam::dictionary& Foam::fa::option::coeffs() const
inline const Foam::dictionary& Foam::fa::option::coeffs() const noexcept
{
return coeffs_;
}
inline bool Foam::fa::option::active() const
inline bool Foam::fa::option::active() const noexcept
{
return active_;
}
inline bool Foam::fa::option::active(const bool on) noexcept
{
bool old(active_);
active_ = on;
return old;
}
inline void Foam::fa::option::setApplied(const label fieldi)
{
applied_[fieldi] = true;
}
inline Foam::Switch& Foam::fa::option::active()
{
return active_;
}
inline const Foam::word& Foam::fa::option::regionName() const
inline const Foam::word& Foam::fa::option::regionName() const noexcept
{
return regionName_;
}
@ -77,31 +79,21 @@ inline const Foam::word& Foam::fa::option::regionName() const
inline const Foam::faMesh& Foam::fa::option::regionMesh() const
{
if (regionMeshPtr_.valid())
if (!regionMeshPtr_)
{
return regionMeshPtr_();
regionMeshPtr_.reset(new faMesh(mesh_));
}
else
{
FatalErrorInFunction
<< "Region mesh not available" << abort(FatalError);
}
return *(new faMesh(mesh_));
return *regionMeshPtr_;
}
inline const Foam::volSurfaceMapping& Foam::fa::option::vsm() const
{
if (vsmPtr_.valid())
if (!vsmPtr_)
{
return vsmPtr_();
vsmPtr_.reset(new volSurfaceMapping(this->regionMesh()));
}
else
{
FatalErrorInFunction
<< "vsmPtr not available" << abort(FatalError);
}
return *(new volSurfaceMapping(regionMeshPtr_()));
return *vsmPtr_;
}

View File

@ -92,7 +92,7 @@ Foam::fa::optionList::optionList
const dictionary& dict
)
:
PtrList<option>(),
PtrList<fa::option>(),
mesh_(p.boundaryMesh().mesh()),
patch_(p),
checkTimeIndex_(mesh_.time().startTimeIndex() + 2)
@ -103,7 +103,7 @@ Foam::fa::optionList::optionList
Foam::fa::optionList::optionList(const fvPatch& p)
:
PtrList<option>(),
PtrList<fa::option>(),
mesh_(p.boundaryMesh().mesh()),
patch_(p),
checkTimeIndex_(mesh_.time().startTimeIndex() + 2)

View File

@ -46,10 +46,9 @@ SourceFile
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Forward Declarations
namespace Foam
{
// Forward declaration of friend functions and operators
namespace fa
{
class optionList;
@ -66,7 +65,7 @@ namespace fa
class optionList
:
public PtrList<option>
public PtrList<fa::option>
{
protected:
@ -118,7 +117,7 @@ public:
// Constructors
//- Construct null
//- Construct from patch
optionList(const fvPatch& p);
//- Construct from mesh and dictionary
@ -126,8 +125,7 @@ public:
//- Destructor
virtual ~optionList()
{}
virtual ~optionList() = default;
// Member Functions

View File

@ -26,6 +26,7 @@ License
\*---------------------------------------------------------------------------*/
#include "profiling.H"
#include "areaFields.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -102,7 +102,7 @@ namespace fa
class faceSetOption
:
public option
public fa::option
{
public:

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -98,7 +98,7 @@ namespace fa
class contactHeatFluxSource
:
public faceSetOption,
public fa::faceSetOption,
public temperatureCoupledBase
{
// Private Data

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,8 +26,8 @@ License
\*---------------------------------------------------------------------------*/
#include "externalFileSource.H"
#include "faMatrices.H"
#include "faCFD.H"
#include "fam.H"
#include "faScalarMatrix.H"
#include "zeroGradientFaPatchFields.H"
#include "addToRunTimeSelectionTable.H"

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -89,7 +89,7 @@ namespace fa
class externalFileSource
:
public faceSetOption
public fa::faceSetOption
{
// Private Data

View File

@ -26,7 +26,8 @@ License
\*---------------------------------------------------------------------------*/
#include "externalHeatFluxSource.H"
#include "addToRunTimeSelectionTable.H"
#include "fam.H"
#include "faScalarMatrix.H"
#include "physicoChemicalConstants.H"
#include "zeroGradientFaPatchFields.H"
#include "addToRunTimeSelectionTable.H"

View File

@ -121,7 +121,6 @@ SourceFiles
#include "Function1.H"
#include "areaFields.H"
#include "faceSetOption.H"
#include "faCFD.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -136,7 +135,7 @@ namespace fa
class externalHeatFluxSource
:
public faceSetOption
public fa::faceSetOption
{
public:

View File

@ -26,8 +26,8 @@ License
\*---------------------------------------------------------------------------*/
#include "jouleHeatingSource.H"
#include "faMatrices.H"
#include "faCFD.H"
#include "fam.H"
#include "faScalarMatrix.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -156,7 +156,7 @@ namespace fa
class jouleHeatingSource
:
public faceSetOption
public fa::faceSetOption
{
// Private Data

View File

@ -0,0 +1,59 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
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/>.
Description
Forward declarations of standard faMatrix types/specializations.
\*---------------------------------------------------------------------------*/
#ifndef faMatricesFwd_H
#define faMatricesFwd_H
#include "fieldTypes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type> class faMatrix;
typedef faMatrix<scalar> faScalarMatrix;
typedef faMatrix<vector> faVectorMatrix;
typedef faMatrix<sphericalTensor> faSphericalTensorMatrix;
typedef faMatrix<symmTensor> faSymmTensorMatrix;
typedef faMatrix<tensor> faTensorMatrix;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -58,9 +58,9 @@ Foam::fv::option::option
mesh_(mesh),
dict_(dict),
coeffs_(dict.optionalSubDict(modelType + "Coeffs")),
active_(dict_.getOrDefault<Switch>("active", true)),
fieldNames_(),
applied_(),
active_(dict_.getOrDefault("active", true)),
log(true)
{
Log << incrIndent << indent << "Source: " << name_ << endl << decrIndent;
@ -101,7 +101,7 @@ Foam::autoPtr<Foam::fv::option> Foam::fv::option::New
) << exit(FatalIOError);
}
return autoPtr<option>(cstrIter()(name, modelType, coeffs, mesh));
return autoPtr<fv::option>(cstrIter()(name, modelType, coeffs, mesh));
}

View File

@ -113,23 +113,25 @@ protected:
//- Dictionary containing source coefficients
dictionary coeffs_;
//- Source active flag
Switch active_;
//- Field names to apply source to - populated by derived models
wordList fieldNames_;
//- Applied flag list - corresponds to each fieldNames_ entry
List<bool> applied_;
//- Source active flag
bool active_;
public:
//- Switch write log to Info
bool log;
//- Runtime type information
TypeName("option");
//- Switch write log to Info
bool log;
// Declare run-time constructor selection table
@ -219,16 +221,16 @@ public:
// Access
//- Return const access to the source name
inline const word& name() const;
inline const word& name() const noexcept;
//- Return const access to the mesh database
inline const fvMesh& mesh() const;
inline const fvMesh& mesh() const noexcept;
//- Return dictionary
inline const dictionary& coeffs() const;
inline const dictionary& coeffs() const noexcept;
//- Return const access to the source active flag
inline bool active() const;
//- True if source is active
inline bool active() const noexcept;
//- Set the applied flag to true for field index fieldi
inline void setApplied(const label fieldi);
@ -236,8 +238,8 @@ public:
// Edit
//- Return access to the source active flag
inline Switch& active();
//- Change source active flag, return previous value
inline bool active(const bool on) noexcept;
// Checks

View File

@ -6,6 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,40 +28,42 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::word& Foam::fv::option::name() const
inline const Foam::word& Foam::fv::option::name() const noexcept
{
return name_;
}
inline const Foam::fvMesh& Foam::fv::option::mesh() const
inline const Foam::fvMesh& Foam::fv::option::mesh() const noexcept
{
return mesh_;
}
inline const Foam::dictionary& Foam::fv::option::coeffs() const
inline const Foam::dictionary& Foam::fv::option::coeffs() const noexcept
{
return coeffs_;
}
inline bool Foam::fv::option::active() const
inline bool Foam::fv::option::active() const noexcept
{
return active_;
}
inline bool Foam::fv::option::active(const bool on) noexcept
{
bool old(active_);
active_ = on;
return old;
}
inline void Foam::fv::option::setApplied(const label fieldi)
{
applied_[fieldi] = true;
}
inline Foam::Switch& Foam::fv::option::active()
{
return active_;
}
// ************************************************************************* //

View File

@ -89,7 +89,7 @@ void Foam::fv::optionList::checkApplied() const
Foam::fv::optionList::optionList(const fvMesh& mesh, const dictionary& dict)
:
PtrList<option>(),
PtrList<fv::option>(),
mesh_(mesh),
checkTimeIndex_(mesh_.time().startTimeIndex() + 2)
{
@ -99,7 +99,7 @@ Foam::fv::optionList::optionList(const fvMesh& mesh, const dictionary& dict)
Foam::fv::optionList::optionList(const fvMesh& mesh)
:
PtrList<option>(),
PtrList<fv::option>(),
mesh_(mesh),
checkTimeIndex_(mesh_.time().startTimeIndex() + 2)
{}

View File

@ -69,7 +69,7 @@ namespace fv
class optionList
:
public PtrList<option>
public PtrList<fv::option>
{
protected:

View File

@ -117,7 +117,7 @@ namespace fv
class cellSetOption
:
public option
public fv::option
{
public:

View File

@ -87,7 +87,7 @@ namespace fv
class interRegionOption
:
public option
public fv::option
{
protected:

View File

@ -118,7 +118,7 @@ namespace fv
class buoyancyEnergy
:
public option
public fv::option
{
// Private Data

View File

@ -110,7 +110,7 @@ namespace fv
class buoyancyForce
:
public option
public fv::option
{
// Private Data

View File

@ -175,7 +175,7 @@ namespace fv
class jouleHeatingSource
:
public option
public fv::option
{
// Private Data

View File

@ -133,7 +133,7 @@ namespace fv
class multiphaseStabilizedTurbulence
:
public option
public fv::option
{
// Private Data

View File

@ -108,7 +108,7 @@ namespace fv
template<class Type>
class PhaseLimitStabilization
:
public option
public fv::option
{
// Private Data

View File

@ -87,7 +87,7 @@ namespace fv
class tabulatedAccelerationSource
:
public option
public fv::option
{
protected:

View File

@ -111,7 +111,7 @@ namespace fv
class viscousDissipation
:
public option
public fv::option
{
// Private Data

View File

@ -80,7 +80,7 @@ namespace fv
class radiation
:
public option
public fv::option
{
// Private Data

View File

@ -50,7 +50,7 @@ SourceFiles
namespace Foam
{
// Forward declarations
// Forward Declarations
class MangrovesModel;
namespace fv
@ -62,7 +62,7 @@ namespace fv
class multiphaseMangrovesSource
:
public option
public fv::option
{
// Private Member Functions

View File

@ -59,7 +59,7 @@ namespace fv
class multiphaseMangrovesTurbulenceModel
:
public option
public fv::option
{
// Private Member Functions