mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add caching selector to PatchFunction1
- extend handling of uniform PatchFunction1 to include new Function1 types and pass through the objectRegistry information
This commit is contained in:
@ -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;
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -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)
|
||||
{}
|
||||
|
||||
|
||||
|
||||
@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -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 * * * * * * * * * * * * * //
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
Reference in New Issue
Block a user