ENH: provide faMesh static accessors for registry and single-region

- the fields for finite-area are currently stored directly on the
  polyMesh registry, but for future relocation to a sub-registry
  provide a uniform accessor.

ENH: use thisDb() for faMatrix access and extrapolatedCalculated
This commit is contained in:
Mark Olesen
2023-12-10 17:08:40 +01:00
parent 05f2d54979
commit 2fa0c7520c
5 changed files with 55 additions and 23 deletions

View File

@ -2108,18 +2108,12 @@ Foam::operator&
const DimensionedField<Type, areaMesh>& psi const DimensionedField<Type, areaMesh>& psi
) )
{ {
auto tMphi = tmp<GeometricField<Type, faPatchField, areaMesh>>::New auto tMphi = GeometricField<Type, faPatchField, areaMesh>::New
(
IOobject
( (
"M&" + psi.name(), "M&" + psi.name(),
psi.instance(),
psi.mesh().mesh(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
psi.mesh(), psi.mesh(),
M.dimensions()/dimArea M.dimensions()/dimArea,
faPatchFieldBase::extrapolatedCalculatedType()
); );
auto& Mphi = tMphi.ref(); auto& Mphi = tMphi.ref();

View File

@ -68,6 +68,25 @@ Foam::word Foam::faMesh::meshSubDir = "faMesh";
const int Foam::faMesh::quadricsFit_ = 0; // Tuning (experimental) const int Foam::faMesh::quadricsFit_ = 0; // Tuning (experimental)
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
const Foam::objectRegistry* Foam::faMesh::registry(const polyMesh& pMesh)
{
// This will change in the near future
return &static_cast<const objectRegistry&>(pMesh);
}
const Foam::faMesh& Foam::faMesh::mesh
(
const polyMesh& pMesh
)
{
// This will change in the near future
return pMesh.lookupObject<faMesh>("faMesh");
}
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace Foam namespace Foam

View File

@ -625,6 +625,14 @@ public:
// Database // Database
//- The parent registry containing all finite-area meshes
//- on the polyMesh.
static const objectRegistry* registry(const polyMesh& pMesh);
//- The single-region finite-area region on the polyMesh.
//- Uses lookupObject semantics - Fatal if non-existent
static const faMesh& mesh(const polyMesh& pMesh);
//- Return access to polyMesh //- Return access to polyMesh
inline const polyMesh& mesh() const; inline const polyMesh& mesh() const;

View File

@ -148,20 +148,26 @@ bool Foam::areaWrite::read(const dictionary& dict)
verbose_ = dict.getOrDefault("verbose", false); verbose_ = dict.getOrDefault("verbose", false);
// Registry containing all finite-area meshes on the polyMesh
const auto* faRegistry = faMesh::registry(mesh_);
dict.readIfPresent("areas", selectAreas_); dict.readIfPresent("areas", selectAreas_);
if (selectAreas_.empty()) if (selectAreas_.empty())
{ {
word areaName; word areaName;
if (!dict.readIfPresent("area", areaName)) if (!dict.readIfPresent("area", areaName))
{ {
wordList available = obr().sortedNames<faMesh>(); if (faRegistry)
{
if (available.size()) wordList available = faRegistry->sortedNames<faMesh>();
if (!available.empty())
{ {
areaName = available.front(); areaName = available.front();
} }
} }
}
if (!areaName.empty()) if (!areaName.empty())
{ {
@ -171,7 +177,12 @@ bool Foam::areaWrite::read(const dictionary& dict)
} }
// Restrict to specified meshes // Restrict to specified meshes
meshes_ = obr().csorted<faMesh>(selectAreas_); meshes_.clear();
if (faRegistry)
{
meshes_ = faRegistry->csorted<faMesh>(selectAreas_);
}
dict.readEntry("fields", fieldSelection_); dict.readEntry("fields", fieldSelection_);
fieldSelection_.uniq(); fieldSelection_.uniq();
@ -252,7 +263,7 @@ bool Foam::areaWrite::write()
selected.clear(); selected.clear();
IOobjectList objects(0); IOobjectList objects;
if (loadFromFiles_) if (loadFromFiles_)
{ {
@ -279,7 +290,7 @@ bool Foam::areaWrite::write()
{ {
if (!ListOps::found(allFields, fieldSelection_[i])) if (!ListOps::found(allFields, fieldSelection_[i]))
{ {
missed.append(i); missed.push_back(i);
} }
} }
@ -304,8 +315,8 @@ bool Foam::areaWrite::write()
if if
( (
fieldTypes::area.found(clsName) fieldTypes::area.contains(clsName)
|| fieldTypes::area_internal.found(clsName) || fieldTypes::area_internal.contains(clsName)
) )
{ {
nAreaFields += n; nAreaFields += n;

View File

@ -75,8 +75,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef areaWrite_H #ifndef Foam_areaWrite_H
#define areaWrite_H #define Foam_areaWrite_H
#include "fvMeshFunctionObject.H" #include "fvMeshFunctionObject.H"
#include "polyMesh.H" #include "polyMesh.H"
@ -191,8 +191,8 @@ public:
const dictionary& dict const dictionary& dict
); );
//- Construct for given objectRegistry and dictionary //- Construct for given objectRegistry and dictionary.
// allow the possibility to load fields from files //- Allow the possibility to load fields from files
areaWrite areaWrite
( (
const word& name, const word& name,