diff --git a/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1.H b/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1.H index b6039cf3d5c5f210812064bf0ba6043000d19a3a..8072fb0193b1f515c5ccc460a7838ef172cc7f1a 100644 --- a/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1.H +++ b/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -49,6 +49,7 @@ SeeAlso #include "patchFunction1Base.H" #include "coordinateScaling.H" #include "Field.H" +#include "HashPtrTable.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -192,6 +193,22 @@ public: ); + // Caching Selectors - accept wildcards in dictionary + + //- Selector with external storage. + //- This also allows wildcard matches in a dictionary + static refPtr<PatchFunction1<Type>> New + ( + HashPtrTable<PatchFunction1<Type>>& cache, + const polyPatch& pp, + const word& entryName, + const dictionary& dict, + enum keyType::option matchOpt = keyType::LITERAL, + const bool faceValues = true, + const bool mandatory = true + ); + + //- Destructor virtual ~PatchFunction1() = default; diff --git a/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1New.C b/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1New.C index 93372133130a24e7f8e5514b7bd5735fbdfe0c0e..f371329280638830770c45d3d309a4f7f6fb84c2 100644 --- a/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1New.C +++ b/src/meshTools/PatchFunction1/PatchFunction1/PatchFunction1New.C @@ -223,4 +223,78 @@ Foam::PatchFunction1<Type>::NewIfPresent } +template<class Type> +Foam::refPtr<Foam::PatchFunction1<Type>> +Foam::PatchFunction1<Type>::New +( + HashPtrTable<PatchFunction1<Type>>& cache, + + const polyPatch& pp, + const word& entryName, + const dictionary& dict, + enum keyType::option matchOpt, + const bool faceValues, + const bool mandatory +) +{ + // See corresponding comments in Function1::New (caching version) + + refPtr<PatchFunction1<Type>> fref; // return value + + // Try for direct cache hit + fref.cref(cache.get(entryName)); + + if (fref) + { + return fref; + } + + + // Lookup from dictionary + const entry* eptr = dict.findEntry(entryName, matchOpt); + + if (eptr) + { + // Use keyword (potentially a wildcard) instead of entry name + const auto& kw = eptr->keyword(); + + // Try for a cache hit + fref.cref(cache.get(kw)); + + if (!fref) + { + // Create new entry + auto fauto + ( + PatchFunction1<Type>::New + ( + pp, + kw, + eptr, // Already resolved + dict, + faceValues, + mandatory + ) + ); + + if (fauto) + { + // Cache the newly created function + fref.cref(fauto.get()); + cache.set(kw, fauto); + } + } + } + + if (mandatory && !fref) + { + FatalIOErrorInFunction(dict) + << "No match for " << entryName << nl + << exit(FatalIOError); + } + + return fref; +} + + // ************************************************************************* // diff --git a/src/meshTools/PatchFunction1/PatchFunction1/patchFunction1Base.C b/src/meshTools/PatchFunction1/PatchFunction1/patchFunction1Base.C index 6902e773bd61959e5242a71afcae2771f84cc38e..7a80721fd8e5cbde400917434745cdc27edf6eb6 100644 --- a/src/meshTools/PatchFunction1/PatchFunction1/patchFunction1Base.C +++ b/src/meshTools/PatchFunction1/PatchFunction1/patchFunction1Base.C @@ -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. @@ -26,7 +26,10 @@ License \*---------------------------------------------------------------------------*/ #include "patchFunction1Base.H" +#include "polyBoundaryMesh.H" +#include "polyMesh.H" #include "polyPatch.H" +#include "objectRegistry.H" #include "Time.H" // * * * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * * * // @@ -81,7 +84,25 @@ Foam::patchFunction1Base::patchFunction1Base // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -void Foam::patchFunction1Base::convertTimeBase(const Time&) +const Foam::objectRegistry* Foam::patchFunction1Base::obrPtr() const +{ + return &(patch_.boundaryMesh().mesh()); // mesh registry +} + + +const Foam::objectRegistry& Foam::patchFunction1Base::obr() const +{ + return patch_.boundaryMesh().mesh(); // mesh registry +} + + +const Foam::Time& Foam::patchFunction1Base::time() const +{ + return patch_.boundaryMesh().mesh().time(); +} + + +void Foam::patchFunction1Base::convertTimeBase(const Time& t) {} diff --git a/src/meshTools/PatchFunction1/PatchFunction1/patchFunction1Base.H b/src/meshTools/PatchFunction1/PatchFunction1/patchFunction1Base.H index f2c60158e5c20b7e7f31f9ed3333dca955774833..d4065c0f2138d0872a036088c0b9a4f7e9c56d7c 100644 --- a/src/meshTools/PatchFunction1/PatchFunction1/patchFunction1Base.H +++ b/src/meshTools/PatchFunction1/PatchFunction1/patchFunction1Base.H @@ -51,6 +51,7 @@ namespace Foam { // Forward Declarations +class objectRegistry; class Time; /*---------------------------------------------------------------------------*\ @@ -77,6 +78,9 @@ protected: // Protected Member Functions + //- Return the object registry (ie, the mesh) as pointer + const objectRegistry* obrPtr() const; + //- No copy assignment void operator=(const patchFunction1Base&) = delete; @@ -122,19 +126,19 @@ public: // Access //- The name of the entry - const word& name() const + const word& name() const noexcept { return name_; } //- Reference to the patch - const polyPatch& patch() const + const polyPatch& patch() const noexcept { return patch_; } //- Generate face or point values on patch? - bool faceValues() const + bool faceValues() const noexcept { return faceValues_; } @@ -145,11 +149,29 @@ public: return (faceValues_ ? patch_.size() : patch_.nPoints()); } + //- Has an associated objectRegistry (ie, from mesh) + /// bool hasDb() const noexcept + /// { + /// return true; + /// } + + //- Return the object registry (ie, the mesh) + const objectRegistry& obr() const; + + //- False: not created with time + /// bool isTime() const noexcept + /// { + /// return false; + /// } + + //- Return the time database + const Time& time() const; + // Manipulation //- Convert time - virtual void convertTimeBase(const Time&); + virtual void convertTimeBase(const Time& t); }; diff --git a/src/meshTools/PatchFunction1/UniformValueField/UniformValueField.C b/src/meshTools/PatchFunction1/UniformValueField/UniformValueField.C index d18b0795154c5db92b8758cbe657ab3fbdeeed1a..aabdc82bd6d944dca6810a0e734cfaf3e6590517 100644 --- a/src/meshTools/PatchFunction1/UniformValueField/UniformValueField.C +++ b/src/meshTools/PatchFunction1/UniformValueField/UniformValueField.C @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -47,7 +47,8 @@ Foam::PatchFunction1Types::UniformValueField<Type>::UniformValueField ( entryName, dict, - redirectType + redirectType, + patchFunction1Base::obrPtr() // mesh registry ) ) {} @@ -72,7 +73,12 @@ Foam::PatchFunction1Types::UniformValueField<Type>::UniformValueField : PatchFunction1<Type>(rhs, pp), uniformValuePtr_(rhs.uniformValuePtr_.clone()) -{} +{ + if (uniformValuePtr_) + { + uniformValuePtr_->resetDb(patchFunction1Base::obrPtr()); + } +} // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // diff --git a/src/meshTools/PatchFunction1/UniformValueField/UniformValueField.H b/src/meshTools/PatchFunction1/UniformValueField/UniformValueField.H index 70b1e1170a2ad740229168bc77d4dfbeff27a8ca..b942323531ea08b9c315f21eaa4ef6cb39db38d7 100644 --- a/src/meshTools/PatchFunction1/UniformValueField/UniformValueField.H +++ b/src/meshTools/PatchFunction1/UniformValueField/UniformValueField.H @@ -5,7 +5,7 @@ \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- - Copyright (C) 2018-2020 OpenCFD Ltd. + Copyright (C) 2018-2021 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -173,6 +173,17 @@ public: } // End namespace PatchFunction1Types } // End namespace Foam +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// Macros + +#undef addUniformValueFieldFunction1s +#define addUniformValueFieldFunction1s(F1Name, Type) \ + PatchFunction1<Type>::adddictionaryConstructorToTable \ + <PatchFunction1Types::UniformValueField<Type>> \ + add##F1Name##UniformValueField##Type##ConstructorToTable_(#F1Name); + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #include "UniformValueFieldI.H" diff --git a/src/meshTools/PatchFunction1/makePatchFunction1s.C b/src/meshTools/PatchFunction1/makePatchFunction1s.C index d2c3e324de2752300af515839c19b200fbcbfc4c..53619a4e60171450cb78ddc35853a181a2abebe1 100644 --- a/src/meshTools/PatchFunction1/makePatchFunction1s.C +++ b/src/meshTools/PatchFunction1/makePatchFunction1s.C @@ -29,9 +29,10 @@ License #include "fieldTypes.H" #include "ConstantField.H" #include "UniformValueField.H" +#include "FunctionObjectValue.H" #include "MappedFile.H" -#include "addToRunTimeSelectionTable.H" #include "Table.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -41,11 +42,6 @@ License makePatchFunction1Type(MappedFile, Type); \ makePatchFunction1Type(UniformValueField, Type); -#define addUniformValueFieldFunction1s(F1Type, Type) \ - PatchFunction1<Type>::adddictionaryConstructorToTable \ - <PatchFunction1Types::UniformValueField<Type>> \ - add##F1Type##UniformValueField##Type##ConstructorToTable_(#F1Type); - namespace Foam { makePatchFunction1(label); @@ -121,6 +117,12 @@ namespace Foam addUniformValueFieldFunction1s(scale, symmTensor); addUniformValueFieldFunction1s(scale, tensor); + addUniformValueFieldFunction1s(functionObjectValue, scalar); + addUniformValueFieldFunction1s(functionObjectValue, vector); + addUniformValueFieldFunction1s(functionObjectValue, sphericalTensor); + addUniformValueFieldFunction1s(functionObjectValue, symmTensor); + addUniformValueFieldFunction1s(functionObjectValue, tensor); + ////- Option2 : at static initialisation add all Function1 types. //// This does not work because we cannot guarantee that the Function1 diff --git a/src/sampling/functions/Function1/makeFunction1s.C b/src/sampling/functions/Function1/makeFunction1s.C index 7739a872e7e33d929469fd497b28d2c356af26c6..a8e80122fb4fcd0e126a5afdf8eaef9c40beceb2 100644 --- a/src/sampling/functions/Function1/makeFunction1s.C +++ b/src/sampling/functions/Function1/makeFunction1s.C @@ -26,6 +26,7 @@ License \*---------------------------------------------------------------------------*/ #include "SampleFunction1.H" +#include "UniformValueField.H" #include "fieldTypes.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -40,7 +41,12 @@ namespace Foam makeFunction1s(sphericalTensor); makeFunction1s(symmTensor); makeFunction1s(tensor); -} + addUniformValueFieldFunction1s(sample, scalar); + addUniformValueFieldFunction1s(sample, vector); + addUniformValueFieldFunction1s(sample, sphericalTensor); + addUniformValueFieldFunction1s(sample, symmTensor); + addUniformValueFieldFunction1s(sample, tensor); +} // ************************************************************************* //