From 0a5a0c29d71aafa5c7aa99001ab8927660d72d87 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Sun, 2 May 2021 13:10:13 +0200 Subject: [PATCH 01/10] ENH: lazier demand-driven evaluation in faOption STYLE: namespace qualifiers on fa/fv option --- src/faOptions/faOption/faOption.C | 22 ++----- src/faOptions/faOption/faOption.H | 58 ++++++++++-------- src/faOptions/faOption/faOptionI.H | 50 +++++++--------- src/faOptions/faOption/faOptionList.C | 4 +- src/faOptions/faOption/faOptionList.H | 10 ++-- .../faOption/faOptionListTemplates.C | 1 + src/faOptions/faceSetOption/faceSetOption.H | 4 +- .../contactHeatFluxSource.H | 4 +- .../externalFileSource/externalFileSource.C | 6 +- .../externalFileSource/externalFileSource.H | 4 +- .../externalHeatFluxSource.C | 3 +- .../externalHeatFluxSource.H | 3 +- .../jouleHeatingSource/jouleHeatingSource.C | 4 +- .../jouleHeatingSource/jouleHeatingSource.H | 4 +- src/finiteArea/faMatrices/faMatricesFwd.H | 59 +++++++++++++++++++ .../cfdTools/general/fvOptions/fvOption.C | 4 +- .../cfdTools/general/fvOptions/fvOption.H | 26 ++++---- .../cfdTools/general/fvOptions/fvOptionI.H | 23 ++++---- .../cfdTools/general/fvOptions/fvOptionList.C | 4 +- .../cfdTools/general/fvOptions/fvOptionList.H | 2 +- src/fvOptions/cellSetOption/cellSetOption.H | 2 +- .../interRegionOption/interRegionOption.H | 2 +- .../derived/buoyancyEnergy/buoyancyEnergy.H | 2 +- .../derived/buoyancyForce/buoyancyForce.H | 2 +- .../jouleHeatingSource/jouleHeatingSource.H | 2 +- .../multiphaseStabilizedTurbulence.H | 2 +- .../PhaseLimitStabilization.H | 2 +- .../tabulatedAccelerationSource.H | 2 +- .../viscousDissipation/viscousDissipation.H | 2 +- .../radiation/fvOptions/radiation/radiation.H | 2 +- .../multiphaseMangrovesSource.H | 4 +- .../multiphaseMangrovesTurbulenceModel.H | 2 +- 32 files changed, 185 insertions(+), 136 deletions(-) create mode 100644 src/finiteArea/faMatrices/faMatricesFwd.H diff --git a/src/faOptions/faOption/faOption.C b/src/faOptions/faOption/faOption.C index 708f738851..9f98da33fe 100644 --- a/src/faOptions/faOption/faOption.C +++ b/src/faOptions/faOption/faOption.C @@ -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("active", true)), fieldNames_(), applied_(), regionName_(dict.get("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; } diff --git a/src/faOptions/faOption/faOption.H b/src/faOptions/faOption/faOption.H index 253c26e2b1..c8d69e473f 100644 --- a/src/faOptions/faOption/faOption.H +++ b/src/faOptions/faOption/faOption.H @@ -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 applied_; - //- Region name + //- Region name (finite-area) word regionName_; - //- Pointer to the region mesh database - autoPtr regionMeshPtr_; +private: - //-Volume-to surface mapping - autoPtr vsmPtr_; + // Private Data + + //- Demand-driven: pointer to region mesh database + mutable autoPtr regionMeshPtr_; + + //- Demand-driven: volume-to-surface mapping + mutable autoPtr 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 diff --git a/src/faOptions/faOption/faOptionI.H b/src/faOptions/faOption/faOptionI.H index a541123f27..42ef920af6 100644 --- a/src/faOptions/faOption/faOptionI.H +++ b/src/faOptions/faOption/faOptionI.H @@ -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_; } diff --git a/src/faOptions/faOption/faOptionList.C b/src/faOptions/faOption/faOptionList.C index 80de3cf682..b722e457a6 100644 --- a/src/faOptions/faOption/faOptionList.C +++ b/src/faOptions/faOption/faOptionList.C @@ -92,7 +92,7 @@ Foam::fa::optionList::optionList const dictionary& dict ) : - PtrList