ENH: zone improvements

- retain group information when copying zones
- support construct empty (add details later)
- improve consistency for zone and boundaryMesh construction

- support front/back/both selection for faceZoneToCell

STYLE: prefer faceZone patch() method instead of operator()

STYLE: use std::unique_ptr instead of manual pointer management

- for zones and core patch types.
  Easier data management, allows default destructors (for example)
This commit is contained in:
Mark Olesen
2023-09-01 14:10:29 +02:00
parent 59c366525e
commit 6aa8b82744
41 changed files with 1322 additions and 629 deletions

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\ /*--------------------------------*- C++ -*----------------------------------*\
| ========= | | | ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2306 | | \\ / O peration | Version: v2312 |
| \\ / A nd | Website: www.openfoam.com | | \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | | | \\/ M anipulation | |
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -71,14 +71,14 @@ cellSet_doc
} }
//- Cells on master or slave side of faceZone //- Cells on front/back/both side of faceZone
{ {
source faceZoneToCell; source faceZoneToCell;
zones (".*Zone"); // Names of faceZones, word or regex zones (".*Zone"); // Names of faceZones, word or regex
// or // or
zone ".*Zone"; // Name of faceZone, word or regex zone ".*Zone"; // Name of faceZone, word or regex
option master; // master/slave option front; // front/back/both
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2013 OpenFOAM Foundation Copyright (C) 2011-2013 OpenFOAM Foundation
Copyright (C) 2020-2021 OpenCFD Ltd. Copyright (C) 2020-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -81,14 +81,31 @@ Foam::patchIdentifier::patchIdentifier
Foam::patchIdentifier::patchIdentifier Foam::patchIdentifier::patchIdentifier
( (
const patchIdentifier& ident, const patchIdentifier& ident,
const label index const label newIndex
) )
: :
name_(ident.name_), patchIdentifier(ident)
index_(index), {
physicalType_(ident.physicalType_), if (newIndex >= 0)
inGroups_(ident.inGroups_) {
{} index_ = newIndex;
}
}
Foam::patchIdentifier::patchIdentifier
(
patchIdentifier&& ident,
const label newIndex
)
:
patchIdentifier(std::move(ident))
{
if (newIndex >= 0)
{
index_ = newIndex;
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

View File

@ -90,16 +90,22 @@ public:
//- Copy construct //- Copy construct
patchIdentifier(const patchIdentifier&) = default; patchIdentifier(const patchIdentifier&) = default;
//- Move construct
patchIdentifier(patchIdentifier&&) = default;
//- Copy assignment //- Copy assignment
patchIdentifier& operator=(const patchIdentifier&) = default; patchIdentifier& operator=(const patchIdentifier&) = default;
//- Move assignment
patchIdentifier& operator=(patchIdentifier&&) = default;
//- Destructor //- Destructor
virtual ~patchIdentifier() = default; virtual ~patchIdentifier() = default;
// Constructors // Constructors
//- Default construct. Uses name="", index=0 //- Default construct: name="", index=0
patchIdentifier(); patchIdentifier();
//- Construct from mandatory components //- Construct from mandatory components
@ -122,11 +128,18 @@ public:
const label index const label index
); );
//- Copy construct, resetting the index //- Copy construct, resetting the index (if non-negative)
patchIdentifier patchIdentifier
( (
const patchIdentifier& ident, const patchIdentifier& ident,
const label index const label newIndex
);
//- Move construct, resetting the index (if non-negative)
patchIdentifier
(
patchIdentifier&& ident,
const label newIndex
); );

View File

@ -80,14 +80,31 @@ Foam::zoneIdentifier::zoneIdentifier
Foam::zoneIdentifier::zoneIdentifier Foam::zoneIdentifier::zoneIdentifier
( (
const zoneIdentifier& ident, const zoneIdentifier& ident,
const label index const label newIndex
) )
: :
name_(ident.name_), zoneIdentifier(ident)
index_(index), {
physicalType_(ident.physicalType_), if (newIndex >= 0)
inGroups_(ident.inGroups_) {
{} index_ = newIndex;
}
}
Foam::zoneIdentifier::zoneIdentifier
(
zoneIdentifier&& ident,
const label newIndex
)
:
zoneIdentifier(std::move(ident))
{
if (newIndex >= 0)
{
index_ = newIndex;
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

View File

@ -78,16 +78,22 @@ public:
//- Copy construct //- Copy construct
zoneIdentifier(const zoneIdentifier&) = default; zoneIdentifier(const zoneIdentifier&) = default;
//- Move construct
zoneIdentifier(zoneIdentifier&&) = default;
//- Copy assignment //- Copy assignment
zoneIdentifier& operator=(const zoneIdentifier&) = default; zoneIdentifier& operator=(const zoneIdentifier&) = default;
//- Move assignment
zoneIdentifier& operator=(zoneIdentifier&&) = default;
//- Destructor //- Destructor
virtual ~zoneIdentifier() = default; virtual ~zoneIdentifier() = default;
// Constructors // Constructors
//- Default construct. Uses name="", index=0 //- Default construct: name="", index=0
zoneIdentifier(); zoneIdentifier();
//- Construct from mandatory components //- Construct from mandatory components
@ -110,11 +116,18 @@ public:
const label index const label index
); );
//- Copy construct, resetting the index //- Copy construct, resetting the index (if non-negative)
zoneIdentifier zoneIdentifier
( (
const zoneIdentifier& ident, const zoneIdentifier& ident,
const label index const label newIndex
);
//- Move construct, resetting the index (if non-negative)
zoneIdentifier
(
zoneIdentifier&& ident,
const label newIndex
); );

View File

@ -81,7 +81,7 @@ Foam::mapPolyMesh::mapPolyMesh(const polyMesh& mesh)
forAll(faceZonePointMap_, zonei) forAll(faceZonePointMap_, zonei)
{ {
faceZonePointMap_[zonei] = faceZonePointMap_[zonei] =
identity(mesh.faceZones()[zonei]().meshPoints().size()); identity(mesh.faceZones()[zonei].patch().meshPoints().size());
} }
forAll(faceZoneFaceMap_, zonei) forAll(faceZoneFaceMap_, zonei)

View File

@ -105,12 +105,12 @@ void Foam::polyBoundaryMesh::calcGroupIDs() const
} }
bool Foam::polyBoundaryMesh::readContents(const bool allowReadIfPresent) bool Foam::polyBoundaryMesh::readContents(const bool allowOptionalRead)
{ {
if if
( (
this->isReadRequired() this->isReadRequired()
|| (allowReadIfPresent && this->isReadOptional() && this->headerOk()) || (allowOptionalRead && this->isReadOptional() && this->headerOk())
) )
{ {
// Warn for MUST_READ_IF_MODIFIED // Warn for MUST_READ_IF_MODIFIED
@ -118,12 +118,11 @@ bool Foam::polyBoundaryMesh::readContents(const bool allowReadIfPresent)
polyPatchList& patches = *this; polyPatchList& patches = *this;
// Read polyPatchList // Read entries
Istream& is = readStream(typeName); Istream& is = readStream(typeName);
// Read patches as entries PtrList<entry> entries(is);
PtrList<entry> patchEntries(is); patches.resize_null(entries.size());
patches.resize(patchEntries.size());
// Transcribe // Transcribe
forAll(patches, patchi) forAll(patches, patchi)
@ -133,8 +132,8 @@ bool Foam::polyBoundaryMesh::readContents(const bool allowReadIfPresent)
patchi, patchi,
polyPatch::New polyPatch::New
( (
patchEntries[patchi].keyword(), entries[patchi].keyword(),
patchEntries[patchi].dict(), entries[patchi].dict(),
patchi, patchi,
*this *this
) )
@ -146,6 +145,7 @@ bool Foam::polyBoundaryMesh::readContents(const bool allowReadIfPresent)
return true; return true;
} }
// Nothing read
return false; return false;
} }
@ -162,10 +162,23 @@ Foam::polyBoundaryMesh::polyBoundaryMesh
regIOobject(io), regIOobject(io),
mesh_(mesh) mesh_(mesh)
{ {
readContents(false); // READ_IF_PRESENT allowed: False readContents(false); // allowOptionalRead = false
} }
Foam::polyBoundaryMesh::polyBoundaryMesh
(
const IOobject& io,
const polyMesh& pm,
Foam::zero
)
:
polyPatchList(),
regIOobject(io),
mesh_(pm)
{}
Foam::polyBoundaryMesh::polyBoundaryMesh Foam::polyBoundaryMesh::polyBoundaryMesh
( (
const IOobject& io, const IOobject& io,
@ -183,20 +196,22 @@ Foam::polyBoundaryMesh::polyBoundaryMesh
( (
const IOobject& io, const IOobject& io,
const polyMesh& pm, const polyMesh& pm,
const polyPatchList& ppl const polyPatchList& list
) )
: :
polyPatchList(), polyPatchList(),
regIOobject(io), regIOobject(io),
mesh_(pm) mesh_(pm)
{ {
if (!readContents(true)) // READ_IF_PRESENT allowed: True if (!readContents(true)) // allowOptionalRead = true
{ {
// Nothing read. Use supplied patches
polyPatchList& patches = *this; polyPatchList& patches = *this;
patches.resize(ppl.size()); patches.resize(list.size());
forAll(patches, patchi) forAll(patches, patchi)
{ {
patches.set(patchi, ppl[patchi].clone(*this)); patches.set(patchi, list[patchi].clone(*this));
} }
} }
} }

View File

@ -91,8 +91,9 @@ class polyBoundaryMesh
//- Calculate group name to patch ids lookup //- Calculate group name to patch ids lookup
void calcGroupIDs() const; void calcGroupIDs() const;
//- Read if IOobject flags set. Return true if read. //- Return true if contents were read
bool readContents(const bool allowReadIfPresent); //- (controlled by IOobject readOption flags).
bool readContents(const bool allowOptionalRead);
public: public:
@ -114,15 +115,24 @@ public:
// Constructors // Constructors
//- Read constructor given IOobject and a polyMesh reference //- Read construct given IOobject and a mesh reference.
// Note point pointers are unset, only used in copying meshes //- It will only read for MUST_READ variants (not READ_IF_PRESENT).
polyBoundaryMesh polyBoundaryMesh
( (
const IOobject& io, const IOobject& io,
const polyMesh& mesh const polyMesh& mesh
); );
//- Construct given size //- Construct empty with IOobject properties and a mesh reference.
//- Does not read.
polyBoundaryMesh
(
const IOobject& io,
const polyMesh& mesh,
Foam::zero
);
//- Construct with specified size. Does not read.
polyBoundaryMesh polyBoundaryMesh
( (
const IOobject& io, const IOobject& io,
@ -130,12 +140,13 @@ public:
const label size const label size
); );
//- Construct given polyPatchList //- Read construct (mandatory, optional) based on IOobject properties
//- or use the fallback PtrList (with cloning).
polyBoundaryMesh polyBoundaryMesh
( (
const IOobject& io, const IOobject& io,
const polyMesh& mesh, const polyMesh& mesh,
const polyPatchList& ppl const polyPatchList& list
); );

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2012 OpenFOAM Foundation Copyright (C) 2011-2012 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd. Copyright (C) 2020-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,6 +27,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "polyBoundaryMeshEntries.H" #include "polyBoundaryMeshEntries.H"
#include "processorPolyPatch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -36,4 +37,29 @@ namespace Foam
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::polyBoundaryMeshEntries::removeProcPatches()
{
// Truncate at the first processor patch entry
PtrList<entry>& entries = *this;
label nNonProcessor = entries.size();
forAll(entries, patchi)
{
const dictionary& dict = entries[patchi].dict();
const word pType = dict.get<word>("type");
if (pType == processorPolyPatch::typeName)
{
nNonProcessor = patchi;
break;
}
}
entries.resize(nNonProcessor);
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -53,8 +53,8 @@ namespace Foam
class polyBoundaryMeshEntries class polyBoundaryMeshEntries
: :
public regIOobject, public PtrList<entry>,
public PtrList<entry> public regIOobject
{ {
public: public:
@ -64,20 +64,28 @@ public:
// Constructors // Constructors
//- Read construct from IOobject
explicit polyBoundaryMeshEntries(const IOobject& io) explicit polyBoundaryMeshEntries(const IOobject& io)
: :
regIOobject(io), regIOobject(io)
PtrList<entry>()
{ {
if (isReadRequired() || (isReadOptional() && headerOk())) if (isReadRequired() || (isReadOptional() && headerOk()))
{ {
readStream(typeName) >> *this; // Read as entries
Istream& is = readStream(typeName);
is >> *this;
close();
} }
} }
// Member Functions // Member Functions
//- Truncate at the first processor patch entry
void removeProcPatches();
//- The class is probably read-only
bool writeData(Ostream&) const bool writeData(Ostream&) const
{ {
NotImplemented; NotImplemented;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2020 OpenCFD Ltd. Copyright (C) 2015-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -30,7 +30,6 @@ License
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "polyBoundaryMesh.H" #include "polyBoundaryMesh.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "demandDrivenData.H"
#include "OFstream.H" #include "OFstream.H"
#include "matchPoints.H" #include "matchPoints.H"
#include "edgeHashes.H" #include "edgeHashes.H"
@ -50,7 +49,7 @@ namespace Foam
} }
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::label Foam::cyclicPolyPatch::findMaxArea Foam::label Foam::cyclicPolyPatch::findMaxArea
( (
@ -813,10 +812,7 @@ Foam::cyclicPolyPatch::cyclicPolyPatch
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::cyclicPolyPatch::~cyclicPolyPatch() Foam::cyclicPolyPatch::~cyclicPolyPatch()
{ {}
deleteDemandDrivenData(coupledPointsPtr_);
deleteDemandDrivenData(coupledEdgesPtr_);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -1022,8 +1018,8 @@ void Foam::cyclicPolyPatch::initUpdateMesh(PstreamBuffers& pBufs)
void Foam::cyclicPolyPatch::updateMesh(PstreamBuffers& pBufs) void Foam::cyclicPolyPatch::updateMesh(PstreamBuffers& pBufs)
{ {
polyPatch::updateMesh(pBufs); polyPatch::updateMesh(pBufs);
deleteDemandDrivenData(coupledPointsPtr_); coupledPointsPtr_.reset(nullptr);
deleteDemandDrivenData(coupledEdgesPtr_); coupledEdgesPtr_.reset(nullptr);
} }
@ -1063,8 +1059,8 @@ const Foam::edgeList& Foam::cyclicPolyPatch::coupledPoints() const
} }
} }
coupledPointsPtr_ = new edgeList(nPoints()); coupledPointsPtr_.reset(new edgeList(nPoints()));
edgeList& connected = *coupledPointsPtr_; auto& connected = *coupledPointsPtr_;
// Extract coupled points. // Extract coupled points.
label connectedI = 0; label connectedI = 0;
@ -1153,8 +1149,8 @@ const Foam::edgeList& Foam::cyclicPolyPatch::coupledEdges() const
const labelList& mp = meshPoints(); const labelList& mp = meshPoints();
coupledEdgesPtr_ = new edgeList(edgeMap.size()); coupledEdgesPtr_.reset(new edgeList(edgeMap.size()));
edgeList& coupledEdges = *coupledEdgesPtr_; auto& coupledEdges = *coupledEdgesPtr_;
label coupleI = 0; label coupleI = 0;
forAll(neighbPatch, patchFacei) forAll(neighbPatch, patchFacei)
@ -1275,10 +1271,10 @@ bool Foam::cyclicPolyPatch::order
<< " neighbour:" << neighbPatchName() << " neighbour:" << neighbPatchName()
<< endl; << endl;
} }
faceMap.setSize(pp.size()); faceMap.resize_nocopy(pp.size());
faceMap = -1; faceMap = -1;
rotation.setSize(pp.size()); rotation.resize_nocopy(pp.size());
rotation = 0; rotation = 0;
if (transform() == NOORDERING) if (transform() == NOORDERING)
@ -1434,7 +1430,7 @@ bool Foam::cyclicPolyPatch::order
} }
} }
ownerPatchPtr_.clear(); ownerPatchPtr_.reset(nullptr);
// Return false if no change necessary, true otherwise. // Return false if no change necessary, true otherwise.

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -46,8 +46,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef cyclicPolyPatch_H #ifndef Foam_cyclicPolyPatch_H
#define cyclicPolyPatch_H #define Foam_cyclicPolyPatch_H
#include "coupledPolyPatch.H" #include "coupledPolyPatch.H"
#include "edgeList.H" #include "edgeList.H"
@ -68,7 +68,7 @@ class cyclicPolyPatch
: :
public coupledPolyPatch public coupledPolyPatch
{ {
// Private data // Private Data
//- Name of other half //- Name of other half
mutable word neighbPatchName_; mutable word neighbPatchName_;
@ -93,16 +93,19 @@ class cyclicPolyPatch
vector separationVector_; vector separationVector_;
//- List of edges formed from connected points. e[0] is the point on //- List of edges formed from connected points.
// the first half of the patch, e[1] the corresponding point on the // From first half of the patch to the corresponding point
// second half. // on the second half.
mutable edgeList* coupledPointsPtr_; mutable std::unique_ptr<edgeList> coupledPointsPtr_;
//- List of connected edges. e[0] is the edge on the first half of the //- List of connected edges.
// patch, e[1] the corresponding edge on the second half. // From first half of the patch to the corresponding edge
mutable edgeList* coupledEdgesPtr_; // on the second half.
mutable std::unique_ptr<edgeList> coupledEdgesPtr_;
//- Temporary storage of owner side patch during ordering. //- Temporary storage of owner side patch during ordering.
// Saved as autoPtr instead of std::unique_ptr to allow
// extra nullptr checking
mutable autoPtr<primitivePatch> ownerPatchPtr_; mutable autoPtr<primitivePatch> ownerPatchPtr_;
@ -424,19 +427,19 @@ public:
} }
//- Axis of rotation for rotational cyclics //- Axis of rotation for rotational cyclics
const vector& rotationAxis() const const vector& rotationAxis() const noexcept
{ {
return rotationAxis_; return rotationAxis_;
} }
//- Point on axis of rotation for rotational cyclics //- Point on axis of rotation for rotational cyclics
const point& rotationCentre() const const point& rotationCentre() const noexcept
{ {
return rotationCentre_; return rotationCentre_;
} }
//- Translation vector for translational cyclics //- Translation vector for translational cyclics
const vector& separationVector() const const vector& separationVector() const noexcept
{ {
return separationVector_; return separationVector_;
} }

View File

@ -35,7 +35,6 @@ License
#include "entry.H" #include "entry.H"
#include "dictionary.H" #include "dictionary.H"
#include "pointPatchField.H" #include "pointPatchField.H"
#include "demandDrivenData.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -260,7 +259,7 @@ Foam::polyPatch::polyPatch
: :
polyPatch(p) polyPatch(p)
{ {
faceCellsPtr_ = new labelList::subList(faceCells, faceCells.size()); faceCellsPtr_.reset(new labelList::subList(faceCells, faceCells.size()));
} }
@ -374,9 +373,12 @@ const Foam::labelUList& Foam::polyPatch::faceCells() const
{ {
if (!faceCellsPtr_) if (!faceCellsPtr_)
{ {
faceCellsPtr_ = new labelList::subList faceCellsPtr_.reset
(
new labelList::subList
( (
patchSlice(boundaryMesh().mesh().faceOwner()) patchSlice(boundaryMesh().mesh().faceOwner())
)
); );
} }
@ -388,7 +390,8 @@ const Foam::labelList& Foam::polyPatch::meshEdges() const
{ {
if (!mePtr_) if (!mePtr_)
{ {
mePtr_ = mePtr_.reset
(
new labelList new labelList
( (
primitivePatch::meshEdges primitivePatch::meshEdges
@ -396,6 +399,7 @@ const Foam::labelList& Foam::polyPatch::meshEdges() const
boundaryMesh().mesh().edges(), boundaryMesh().mesh().edges(),
boundaryMesh().mesh().pointEdges() boundaryMesh().mesh().pointEdges()
) )
)
); );
} }
@ -407,8 +411,8 @@ void Foam::polyPatch::clearAddressing()
{ {
primitivePatch::clearTopology(); primitivePatch::clearTopology();
primitivePatch::clearPatchMeshAddr(); primitivePatch::clearPatchMeshAddr();
deleteDemandDrivenData(faceCellsPtr_); faceCellsPtr_.reset(nullptr);
deleteDemandDrivenData(mePtr_); mePtr_.reset(nullptr);
} }

View File

@ -83,10 +83,10 @@ class polyPatch
const polyBoundaryMesh& boundaryMesh_; const polyBoundaryMesh& boundaryMesh_;
//- Demand-driven: face-cell addressing //- Demand-driven: face-cell addressing
mutable labelList::subList* faceCellsPtr_; mutable std::unique_ptr<labelList::subList> faceCellsPtr_;
//- Demand-driven: global edge addressing //- Demand-driven: global edge addressing
mutable labelList* mePtr_; mutable std::unique_ptr<labelList> mePtr_;
protected: protected:
@ -500,8 +500,8 @@ public:
// Member Operators // Member Operators
//- Assignment //- Copy assignment
void operator=(const polyPatch&); void operator=(const polyPatch& p);
// Ostream Operator // Ostream Operator

View File

@ -47,6 +47,22 @@ namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class ZoneType, class MeshType>
Foam::label Foam::ZoneMesh<ZoneType, MeshType>::totalSize() const
{
// Count number of objects in all zones
const PtrList<ZoneType>& zones = *this;
label total = 0;
for (const ZoneType& zn : zones)
{
total += zn.size();
}
return total;
}
template<class ZoneType, class MeshType> template<class ZoneType, class MeshType>
void Foam::ZoneMesh<ZoneType, MeshType>::calcZoneMap() const void Foam::ZoneMesh<ZoneType, MeshType>::calcZoneMap() const
{ {
@ -58,31 +74,22 @@ void Foam::ZoneMesh<ZoneType, MeshType>::calcZoneMap() const
} }
else else
{ {
// Count number of objects in all zones zoneMapPtr_.reset(new Map<label>());
label nObjects = 0; auto& map = *zoneMapPtr_;
const PtrList<ZoneType>& zones = *this;
for (const ZoneType& zn : zones)
{
nObjects += zn.size();
}
zoneMapPtr_.emplace(2*nObjects);
auto& zm = *zoneMapPtr_;
// Fill in objects of all zones into the map. // Fill in objects of all zones into the map.
// The key is the global object index, value is the zone index // The key is the global object index, value is the zone index
map.reserve(this->totalSize());
const PtrList<ZoneType>& zones = *this;
label zonei = 0; label zonei = 0;
for (const ZoneType& zn : zones) for (const ZoneType& zn : zones)
{ {
const labelList& labels = zn; for (const label id : static_cast<const labelList&>(zn))
for (const label idx : labels)
{ {
zm.insert(idx, zonei); map.insert(id, zonei);
} }
++zonei; ++zonei;
@ -122,7 +129,7 @@ void Foam::ZoneMesh<ZoneType, MeshType>::calcGroupIDs() const
return; // Or FatalError return; // Or FatalError
} }
groupIDsPtr_.emplace(16); groupIDsPtr_.reset(new HashTable<labelList>(16));
auto& groupLookup = *groupIDsPtr_; auto& groupLookup = *groupIDsPtr_;
const PtrList<ZoneType>& zones = *this; const PtrList<ZoneType>& zones = *this;
@ -151,20 +158,27 @@ void Foam::ZoneMesh<ZoneType, MeshType>::calcGroupIDs() const
template<class ZoneType, class MeshType> template<class ZoneType, class MeshType>
bool Foam::ZoneMesh<ZoneType, MeshType>::readContents() bool Foam::ZoneMesh<ZoneType, MeshType>::readContents
(
const bool allowOptionalRead
)
{ {
if (isReadRequired() || (isReadOptional() && headerOk())) if
(
isReadRequired()
|| (allowOptionalRead && isReadOptional() && headerOk())
)
{ {
// Warn for MUST_READ_IF_MODIFIED // Warn for MUST_READ_IF_MODIFIED
warnNoRereading<ZoneMesh<ZoneType, MeshType>>(); warnNoRereading<ZoneMesh<ZoneType, MeshType>>();
PtrList<ZoneType>& zones = *this; PtrList<ZoneType>& zones = *this;
// Read zones as entries // Read entries
Istream& is = readStream(typeName); Istream& is = readStream(typeName);
PtrList<entry> patchEntries(is); PtrList<entry> entries(is);
zones.resize(patchEntries.size()); zones.resize_null(entries.size());
// Transcribe // Transcribe
forAll(zones, zonei) forAll(zones, zonei)
@ -174,8 +188,8 @@ bool Foam::ZoneMesh<ZoneType, MeshType>::readContents()
zonei, zonei,
ZoneType::New ZoneType::New
( (
patchEntries[zonei].keyword(), entries[zonei].keyword(),
patchEntries[zonei].dict(), entries[zonei].dict(),
zonei, zonei,
*this *this
) )
@ -205,10 +219,26 @@ Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh
regIOobject(io), regIOobject(io),
mesh_(mesh) mesh_(mesh)
{ {
readContents(); // Note: this is inconsistent with polyBoundaryMesh
// which does not permit optional reading
readContents(true); // allowOptionalRead = true
} }
template<class ZoneType, class MeshType>
Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh
(
const IOobject& io,
const MeshType& mesh,
Foam::zero
)
:
PtrList<ZoneType>(),
regIOobject(io),
mesh_(mesh)
{}
template<class ZoneType, class MeshType> template<class ZoneType, class MeshType>
Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh
( (
@ -221,8 +251,9 @@ Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh
regIOobject(io), regIOobject(io),
mesh_(mesh) mesh_(mesh)
{ {
// Optionally read contents, otherwise keep size // Note: this is inconsistent with polyBoundaryMesh
readContents(); // which does not read all
readContents(true); // allowOptionalRead = true
} }
@ -231,36 +262,27 @@ Foam::ZoneMesh<ZoneType, MeshType>::ZoneMesh
( (
const IOobject& io, const IOobject& io,
const MeshType& mesh, const MeshType& mesh,
const PtrList<ZoneType>& pzm const PtrList<ZoneType>& list
) )
: :
PtrList<ZoneType>(), PtrList<ZoneType>(),
regIOobject(io), regIOobject(io),
mesh_(mesh) mesh_(mesh)
{ {
if (!readContents()) if (!readContents(true)) // allowOptionalRead = true
{ {
// Nothing read. Use supplied zones // Nothing read. Use supplied zones
PtrList<ZoneType>& zones = *this; PtrList<ZoneType>& zones = *this;
zones.resize(pzm.size()); zones.resize(list.size());
forAll(zones, zonei) forAll(zones, zonei)
{ {
zones.set(zonei, pzm[zonei].clone(*this)); zones.set(zonei, list[zonei].clone(*this));
} }
} }
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class ZoneType, class MeshType>
Foam::ZoneMesh<ZoneType, MeshType>::~ZoneMesh()
{
clearAddressing();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ZoneType, class MeshType> template<class ZoneType, class MeshType>
@ -710,7 +732,7 @@ void Foam::ZoneMesh<ZoneType, MeshType>::setGroup
const labelUList& zoneIDs const labelUList& zoneIDs
) )
{ {
groupIDsPtr_.clear(); groupIDsPtr_.reset(nullptr);
PtrList<ZoneType>& zones = *this; PtrList<ZoneType>& zones = *this;
@ -740,8 +762,8 @@ void Foam::ZoneMesh<ZoneType, MeshType>::setGroup
template<class ZoneType, class MeshType> template<class ZoneType, class MeshType>
void Foam::ZoneMesh<ZoneType, MeshType>::clearAddressing() void Foam::ZoneMesh<ZoneType, MeshType>::clearAddressing()
{ {
zoneMapPtr_.clear(); zoneMapPtr_.reset(nullptr);
groupIDsPtr_.clear(); groupIDsPtr_.reset(nullptr);
PtrList<ZoneType>& zones = *this; PtrList<ZoneType>& zones = *this;
@ -752,6 +774,18 @@ void Foam::ZoneMesh<ZoneType, MeshType>::clearAddressing()
} }
template<class ZoneType, class MeshType>
void Foam::ZoneMesh<ZoneType, MeshType>::clearPrimitives()
{
PtrList<ZoneType>& zones = *this;
for (ZoneType& zn : zones)
{
zn.clearPrimitives();
}
}
template<class ZoneType, class MeshType> template<class ZoneType, class MeshType>
void Foam::ZoneMesh<ZoneType, MeshType>::clear() void Foam::ZoneMesh<ZoneType, MeshType>::clear()
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd. Copyright (C) 2016-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -74,16 +74,20 @@ class ZoneMesh
const MeshType& mesh_; const MeshType& mesh_;
//- Demand-driven: map of zone labels for given element //- Demand-driven: map of zone labels for given element
mutable autoPtr<Map<label>> zoneMapPtr_; mutable std::unique_ptr<Map<label>> zoneMapPtr_;
//- Demand-driven: list of zone ids per group //- Demand-driven: list of zone ids per group
mutable autoPtr<HashTable<labelList>> groupIDsPtr_; mutable std::unique_ptr<HashTable<labelList>> groupIDsPtr_;
// Private Member Functions // Private Member Functions
//- Read if IOobject flags set. Return true if read. //- Return true if contents were read
bool readContents(); //- (controlled by IOobject readOption flags).
bool readContents(const bool allowOptionalRead);
//- Total of number of addressed items (all zones)
label totalSize() const;
//- Create zone map //- Create zone map
void calcZoneMap() const; void calcZoneMap() const;
@ -109,14 +113,25 @@ public:
// Constructors // Constructors
//- Read constructor given IOobject and a MeshType reference //- Read construct from IOobject and mesh reference
//- Any reading (mandatory, optional) based on IOobject properties.
ZoneMesh ZoneMesh
( (
const IOobject& io, const IOobject& io,
const MeshType& mesh const MeshType& mesh
); );
//- Construct given size //- Construct empty with IOobject properties and a mesh reference.
//- Does not read.
ZoneMesh
(
const IOobject& io,
const MeshType& mesh,
Foam::zero
);
//- Construct with specified size if not read.
//- Any reading (mandatory, optional) based on IOobject properties.
ZoneMesh ZoneMesh
( (
const IOobject& io, const IOobject& io,
@ -124,26 +139,24 @@ public:
const label size const label size
); );
//- Construct given a PtrList //- Read construct (mandatory, optional) based on IOobject properties
//- or use the fallback PtrList (with cloning).
ZoneMesh ZoneMesh
( (
const IOobject& io, const IOobject& io,
const MeshType& mesh, const MeshType& mesh,
const PtrList<ZoneType>& pzm const PtrList<ZoneType>& list
); );
//- Destructor //- Destructor
~ZoneMesh(); ~ZoneMesh() = default;
// Member Functions // Member Functions
//- Return the mesh reference //- Return the mesh reference
const MeshType& mesh() const noexcept const MeshType& mesh() const noexcept { return mesh_; }
{
return mesh_;
}
//- Map of zones containing zone index for all zoned elements //- Map of zones containing zone index for all zoned elements
// Return -1 if the object is not in the zone // Return -1 if the object is not in the zone
@ -280,6 +293,9 @@ public:
//- Clear addressing //- Clear addressing
void clearAddressing(); void clearAddressing();
//- Clear primitive addressing
void clearPrimitives();
//- Clear the zones //- Clear the zones
void clear(); void clear();

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -47,6 +47,12 @@ const char * const Foam::cellZone::labelsName = "cellLabels";
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::cellZone::cellZone(const cellZoneMesh& zm)
:
cellZone(word::null, 0, zm)
{}
Foam::cellZone::cellZone Foam::cellZone::cellZone
( (
const word& name, const word& name,
@ -100,28 +106,56 @@ Foam::cellZone::cellZone
Foam::cellZone::cellZone Foam::cellZone::cellZone
( (
const cellZone& origZone, const cellZone& originalZone,
const labelUList& addr, const Foam::zero,
const label index, const cellZoneMesh& zm,
const cellZoneMesh& zm const label newIndex
) )
: :
zone(origZone, addr, index), zone(originalZone, labelList(), newIndex),
zoneMesh_(zm) zoneMesh_(zm)
{} {}
Foam::cellZone::cellZone Foam::cellZone::cellZone
( (
const cellZone& origZone, const cellZone& originalZone,
const Foam::zero,
const label index,
const cellZoneMesh& zm
)
:
zone(originalZone, labelList(), index),
zoneMesh_(zm)
{}
Foam::cellZone::cellZone
(
const cellZone& originalZone,
const labelUList& addr,
const label index,
const cellZoneMesh& zm
)
:
cellZone(originalZone, Foam::zero{}, index, zm)
{
labelList::operator=(addr);
}
Foam::cellZone::cellZone
(
const cellZone& originalZone,
labelList&& addr, labelList&& addr,
const label index, const label index,
const cellZoneMesh& zm const cellZoneMesh& zm
) )
: :
zone(origZone, std::move(addr), index), cellZone(originalZone, Foam::zero{}, index, zm)
zoneMesh_(zm) {
{} labelList::transfer(addr);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -150,12 +184,56 @@ void Foam::cellZone::writeDict(Ostream& os) const
} }
void Foam::cellZone::resetAddressing(cellZone&& zn)
{
if (this == &zn)
{
return; // Self-assignment is a no-op
}
clearAddressing();
labelList::transfer(static_cast<labelList&>(zn));
zn.clearAddressing();
}
void Foam::cellZone::resetAddressing(const cellZone& zn)
{
if (this == &zn)
{
return; // Self-assignment is a no-op
}
clearAddressing();
labelList::operator=(static_cast<const labelList&>(zn));
}
void Foam::cellZone::resetAddressing(const labelUList& addr)
{
clearAddressing();
labelList::operator=(addr);
}
void Foam::cellZone::resetAddressing(labelList&& addr)
{
clearAddressing();
labelList::transfer(addr);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::cellZone::operator=(const cellZone& zn) void Foam::cellZone::operator=(const cellZone& zn)
{ {
if (this == &zn)
{
return; // Self-assignment is a no-op
}
clearAddressing(); clearAddressing();
labelList::operator=(zn); labelList::operator=(static_cast<const labelList&>(zn));
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -41,8 +41,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef cellZone_H #ifndef Foam_cellZone_H
#define cellZone_H #define Foam_cellZone_H
#include "zone.H" #include "zone.H"
#include "cellZoneMeshFwd.H" #include "cellZoneMeshFwd.H"
@ -70,12 +70,6 @@ class cellZone
const cellZoneMesh& zoneMesh_; const cellZoneMesh& zoneMesh_;
// Private Member Functions
//- No copy construct
cellZone(const cellZone&) = delete;
public: public:
// Static Data Members // Static Data Members
@ -108,7 +102,13 @@ public:
// Constructors // Constructors
//- Construct an empty zone //- No copy construct
cellZone(const cellZone&) = delete;
//- Construct an empty zone - name="", index=0
explicit cellZone(const cellZoneMesh& zm);
//- Construct an empty zone with specified name and index
cellZone cellZone
( (
const word& name, const word& name,
@ -143,21 +143,41 @@ public:
const cellZoneMesh& zm const cellZoneMesh& zm
); );
//- Construct given the original zone (name is used), //- Construct empty with original zone information (name, index, groups)
//- and resetting the cell list and zone mesh information //- and mesh reference. Optionally specify a new index.
cellZone cellZone
( (
const cellZone& origZone, const cellZone& originalZone,
const Foam::zero,
const cellZoneMesh& zm,
const label newIndex = -1
);
//- Construct empty with original zone information (name, groups),
//- resetting the index and zone mesh reference.
cellZone
(
const cellZone& originalZone,
const Foam::zero,
const label index,
const cellZoneMesh& zm
);
//- Construct with original zone information (name, groups),
//- resetting the cell list, the index and zone mesh reference.
cellZone
(
const cellZone& originalZone,
const labelUList& addr, const labelUList& addr,
const label index, const label index,
const cellZoneMesh& zm const cellZoneMesh& zm
); );
//- Construct with a new index and zone mesh information, the name //- Construct with original zone information (name, groups),
//- of the original zone, resetting the cell addressing. //- resetting the cell list, the index and zone mesh reference.
cellZone cellZone
( (
const cellZone& origZone, const cellZone& originalZone,
labelList&& addr, labelList&& addr,
const label index, const label index,
const cellZoneMesh& zm const cellZoneMesh& zm
@ -203,9 +223,12 @@ public:
// Member Functions // Member Functions
//- Return reference to the zone mesh //- Return reference to the zone mesh
const cellZoneMesh& zoneMesh() const noexcept const cellZoneMesh& zoneMesh() const noexcept { return zoneMesh_; }
//- The addressing (cell IDs) used for the zone
const labelList& addressing() const noexcept
{ {
return zoneMesh_; return static_cast<const labelList&>(*this);
} }
//- Helper function to re-direct to zone::localID(...) //- Helper function to re-direct to zone::localID(...)
@ -226,7 +249,19 @@ public:
virtual void writeDict(Ostream& os) const; virtual void writeDict(Ostream& os) const;
// Member Operators // Assign addressing
//- Move reset addressing from another zone
virtual void resetAddressing(cellZone&& zn);
//- Copy reset addressing from another zone
virtual void resetAddressing(const cellZone& zn);
//- Copy assign addressing
virtual void resetAddressing(const labelUList& addr);
//- Move assign addressing
virtual void resetAddressing(labelList&& addr);
//- Assign addressing, clearing demand-driven data //- Assign addressing, clearing demand-driven data
void operator=(const cellZone& zn); void operator=(const cellZone& zn);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -31,7 +31,6 @@ License
#include "faceZoneMesh.H" #include "faceZoneMesh.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "primitiveMesh.H" #include "primitiveMesh.H"
#include "demandDrivenData.H"
#include "mapPolyMesh.H" #include "mapPolyMesh.H"
#include "syncTools.H" #include "syncTools.H"
@ -52,16 +51,8 @@ const char* const Foam::faceZone::labelsName = "faceLabels";
void Foam::faceZone::setFlipMap(const bool val) void Foam::faceZone::setFlipMap(const bool val)
{ {
// Match size for flipMap // Match size for flipMap
if (flipMap_.size() == this->size()) flipMap_.resize_nocopy(this->size());
{
flipMap_ = val; flipMap_ = val;
}
else
{
// Avoid copying old values on resize
flipMap_.clear();
flipMap_.resize(this->size(), val);
}
} }
@ -78,23 +69,24 @@ void Foam::faceZone::calcFaceZonePatch() const
<< abort(FatalError); << abort(FatalError);
} }
patchPtr_ = patchPtr_.reset
(
new primitiveFacePatch new primitiveFacePatch
( (
faceList(size()), faceList(size()),
zoneMesh().mesh().points() zoneMesh().mesh().points()
)
); );
auto& patch = *patchPtr_;
primitiveFacePatch& patch = *patchPtr_;
const faceList& f = zoneMesh().mesh().faces(); const faceList& f = zoneMesh().mesh().faces();
const labelList& addr = *this; const labelList& addr = *this;
const boolList& flip = flipMap(); const boolList& flips = flipMap();
forAll(addr, facei) forAll(addr, facei)
{ {
if (flip[facei]) if (flips[facei])
{ {
patch[facei] = f[addr[facei]].reverseFace(); patch[facei] = f[addr[facei]].reverseFace();
} }
@ -110,11 +102,9 @@ void Foam::faceZone::calcFaceZonePatch() const
void Foam::faceZone::calcCellLayers() const void Foam::faceZone::calcCellLayers() const
{ {
DebugInFunction << "Calculating master cells" << endl; DebugInFunction << "Calculating cell layers" << endl;
// It is an error to attempt to recalculate edgeCells if (frontCellsPtr_ || backCellsPtr_)
// if the pointer is already set
if (masterCellsPtr_ || slaveCellsPtr_)
{ {
FatalErrorInFunction FatalErrorInFunction
<< "cell layers already calculated" << "cell layers already calculated"
@ -122,48 +112,82 @@ void Foam::faceZone::calcCellLayers() const
} }
else else
{ {
// Go through all the faces in the master zone. Choose the // Go through all the faces in the zone.
// master or slave cell based on the face flip // Choose the front/back cell based on the face flip
const labelList& own = zoneMesh().mesh().faceOwner(); const labelList& own = zoneMesh().mesh().faceOwner();
const labelList& nei = zoneMesh().mesh().faceNeighbour(); const labelList& nei = zoneMesh().mesh().faceNeighbour();
const labelList& mf = *this; const labelList& addr = *this;
const boolList& flips = flipMap();
const boolList& faceFlip = flipMap(); frontCellsPtr_.reset(new labelList(addr.size()));
backCellsPtr_.reset(new labelList(addr.size()));
masterCellsPtr_ = new labelList(mf.size()); auto& fronts = *frontCellsPtr_;
labelList& mc = *masterCellsPtr_; auto& backs = *backCellsPtr_;
slaveCellsPtr_ = new labelList(mf.size()); forAll(addr, facei)
labelList& sc = *slaveCellsPtr_;
forAll(mf, facei)
{ {
const label ownCelli = own[mf[facei]]; const label ownCelli = own[addr[facei]];
const label neiCelli = const label neiCelli =
( (
zoneMesh().mesh().isInternalFace(mf[facei]) zoneMesh().mesh().isInternalFace(addr[facei])
? nei[mf[facei]] ? nei[addr[facei]]
: -1 : -1
); );
if (!faceFlip[facei]) if (flips[facei])
{ {
// Face is oriented correctly, no flip needed fronts[facei] = ownCelli;
mc[facei] = neiCelli; backs[facei] = neiCelli;
sc[facei] = ownCelli;
} }
else else
{ {
mc[facei] = ownCelli; fronts[facei] = neiCelli;
sc[facei] = neiCelli; backs[facei] = ownCelli;
} }
} }
} }
} }
// Foam::label Foam::faceZone::getLayerCell
// (
// const side which,
// const label i
// ) const
// {
// const label facei = labelList::operator[](i);
// const bool flipped = flipMap_[i];
//
// if (which == side::FRONT ? flipped : !flipped)
// {
// return zoneMesh().mesh().faceOwner()[facei];
// }
// else if (zoneMesh().mesh().isInternalFace(facei))
// {
// return zoneMesh().mesh().faceNeighbour()[facei];
// }
// else
// {
// return -1;
// }
// }
//
//
// Foam::label Foam::faceZone::frontCell(const label i) const
// {
// return getLayerCell(side::FRONT, i);
// }
//
//
// Foam::label Foam::faceZone::backCell(const label i) const
// {
// return getLayerCell(side::BACK, i);
// }
void Foam::faceZone::checkAddressing() const void Foam::faceZone::checkAddressing() const
{ {
const labelList& addr = *this; const labelList& addr = *this;
@ -194,6 +218,12 @@ void Foam::faceZone::checkAddressing() const
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::faceZone::faceZone(const faceZoneMesh& zm)
:
faceZone(word::null, 0, zm)
{}
Foam::faceZone::faceZone Foam::faceZone::faceZone
( (
const word& name, const word& name,
@ -202,12 +232,7 @@ Foam::faceZone::faceZone
) )
: :
zone(name, index), zone(name, index),
flipMap_(), zoneMesh_(zm)
zoneMesh_(zm),
patchPtr_(nullptr),
masterCellsPtr_(nullptr),
slaveCellsPtr_(nullptr),
mePtr_(nullptr)
{} {}
@ -220,15 +245,11 @@ Foam::faceZone::faceZone
const faceZoneMesh& zm const faceZoneMesh& zm
) )
: :
zone(name, addr, index), faceZone(name, index, zm)
flipMap_(),
zoneMesh_(zm),
patchPtr_(nullptr),
masterCellsPtr_(nullptr),
slaveCellsPtr_(nullptr),
mePtr_(nullptr)
{ {
flipMap_.resize(size(), flipMapValue); labelList::operator=(addr);
flipMap_.resize(labelList::size(), flipMapValue);
checkAddressing(); checkAddressing();
} }
@ -242,15 +263,10 @@ Foam::faceZone::faceZone
const faceZoneMesh& zm const faceZoneMesh& zm
) )
: :
zone(name, std::move(addr), index), faceZone(name, index, zm)
flipMap_(),
zoneMesh_(zm),
patchPtr_(nullptr),
masterCellsPtr_(nullptr),
slaveCellsPtr_(nullptr),
mePtr_(nullptr)
{ {
flipMap_.resize(size(), flipMapValue); labelList::transfer(addr);
flipMap_.resize(labelList::size(), flipMapValue);
checkAddressing(); checkAddressing();
} }
@ -264,14 +280,18 @@ Foam::faceZone::faceZone
const faceZoneMesh& zm const faceZoneMesh& zm
) )
: :
zone(name, addr, index), faceZone(name, index, zm)
flipMap_(fm),
zoneMesh_(zm),
patchPtr_(nullptr),
masterCellsPtr_(nullptr),
slaveCellsPtr_(nullptr),
mePtr_(nullptr)
{ {
labelList::operator=(addr);
flipMap_ = fm;
// TBD
// if (flipMap_.empty())
// {
// // An empty flipMap is treated like 'false' instead of as an error
// flipMap_.resize(labelList::size(), false);
// }
checkAddressing(); checkAddressing();
} }
@ -285,14 +305,18 @@ Foam::faceZone::faceZone
const faceZoneMesh& zm const faceZoneMesh& zm
) )
: :
zone(name, std::move(addr), index), faceZone(name, index, zm)
flipMap_(std::move(fm)),
zoneMesh_(zm),
patchPtr_(nullptr),
masterCellsPtr_(nullptr),
slaveCellsPtr_(nullptr),
mePtr_(nullptr)
{ {
labelList::transfer(addr);
flipMap_.transfer(fm);
// TBD
// if (flipMap_.empty())
// {
// // An empty flipMap is treated like 'false' instead of as an error
// flipMap_.resize(labelList::size(), false);
// }
checkAddressing(); checkAddressing();
} }
@ -306,12 +330,8 @@ Foam::faceZone::faceZone
) )
: :
zone(name, dict, this->labelsName, index), zone(name, dict, this->labelsName, index),
flipMap_(dict.lookup("flipMap")), flipMap_(dict.lookup("flipMap")), // OR: dict.get<boolList>("flipMap")
zoneMesh_(zm), zoneMesh_(zm)
patchPtr_(nullptr),
masterCellsPtr_(nullptr),
slaveCellsPtr_(nullptr),
mePtr_(nullptr)
{ {
checkAddressing(); checkAddressing();
} }
@ -319,54 +339,66 @@ Foam::faceZone::faceZone
Foam::faceZone::faceZone Foam::faceZone::faceZone
( (
const faceZone& origZone, const faceZone& originalZone,
const Foam::zero,
const faceZoneMesh& zm,
const label newIndex
)
:
zone(originalZone, labelList(), newIndex),
zoneMesh_(zm)
{}
Foam::faceZone::faceZone
(
const faceZone& originalZone,
const Foam::zero,
const label index,
const faceZoneMesh& zm
)
:
zone(originalZone, labelList(), index),
zoneMesh_(zm)
{}
Foam::faceZone::faceZone
(
const faceZone& originalZone,
const labelUList& addr, const labelUList& addr,
const boolUList& fm, const boolUList& fm,
const label index, const label index,
const faceZoneMesh& zm const faceZoneMesh& zm
) )
: :
zone(origZone, addr, index), faceZone(originalZone, Foam::zero{}, index, zm)
flipMap_(fm),
zoneMesh_(zm),
patchPtr_(nullptr),
masterCellsPtr_(nullptr),
slaveCellsPtr_(nullptr),
mePtr_(nullptr)
{ {
labelList::operator=(addr);
flipMap_ = fm;
checkAddressing(); checkAddressing();
} }
Foam::faceZone::faceZone Foam::faceZone::faceZone
( (
const faceZone& origZone, const faceZone& originalZone,
labelList&& addr, labelList&& addr,
boolList&& fm, boolList&& fm,
const label index, const label index,
const faceZoneMesh& zm const faceZoneMesh& zm
) )
: :
zone(origZone, std::move(addr), index), faceZone(originalZone, Foam::zero{}, index, zm)
flipMap_(std::move(fm)),
zoneMesh_(zm),
patchPtr_(nullptr),
masterCellsPtr_(nullptr),
slaveCellsPtr_(nullptr),
mePtr_(nullptr)
{ {
labelList::transfer(addr);
flipMap_.transfer(fm);
checkAddressing(); checkAddressing();
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::faceZone::~faceZone()
{
clearAddressing();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::faceZone::whichFace(const label globalFaceID) const Foam::label Foam::faceZone::whichFace(const label globalFaceID) const
@ -375,36 +407,33 @@ Foam::label Foam::faceZone::whichFace(const label globalFaceID) const
} }
const Foam::primitiveFacePatch& Foam::faceZone::operator()() const const Foam::primitiveFacePatch& Foam::faceZone::patch() const
{ {
if (!patchPtr_) if (!patchPtr_)
{ {
calcFaceZonePatch(); calcFaceZonePatch();
} }
return *patchPtr_; return *patchPtr_;
} }
const Foam::labelList& Foam::faceZone::masterCells() const const Foam::labelList& Foam::faceZone::frontCells() const
{ {
if (!masterCellsPtr_) if (!frontCellsPtr_)
{ {
calcCellLayers(); calcCellLayers();
} }
return *frontCellsPtr_;
return *masterCellsPtr_;
} }
const Foam::labelList& Foam::faceZone::slaveCells() const const Foam::labelList& Foam::faceZone::backCells() const
{ {
if (!slaveCellsPtr_) if (!backCellsPtr_)
{ {
calcCellLayers(); calcCellLayers();
} }
return *backCellsPtr_;
return *slaveCellsPtr_;
} }
@ -412,14 +441,16 @@ const Foam::labelList& Foam::faceZone::meshEdges() const
{ {
if (!mePtr_) if (!mePtr_)
{ {
mePtr_ = mePtr_.reset
(
new labelList new labelList
( (
operator()().meshEdges this->patch().meshEdges
( (
zoneMesh().mesh().edges(), zoneMesh().mesh().edges(),
zoneMesh().mesh().pointEdges() zoneMesh().mesh().pointEdges()
) )
)
); );
} }
@ -427,16 +458,55 @@ const Foam::labelList& Foam::faceZone::meshEdges() const
} }
void Foam::faceZone::clearGeom()
{
patchPtr_.reset(nullptr);
frontCellsPtr_.reset(nullptr);
backCellsPtr_.reset(nullptr);
mePtr_.reset(nullptr);
}
void Foam::faceZone::clearAddressing() void Foam::faceZone::clearAddressing()
{ {
zone::clearAddressing(); zone::clearAddressing();
clearGeom();
}
deleteDemandDrivenData(patchPtr_);
deleteDemandDrivenData(masterCellsPtr_); void Foam::faceZone::clearPrimitives()
deleteDemandDrivenData(slaveCellsPtr_); {
zone::clearPrimitives();
flipMap_.clear();
}
deleteDemandDrivenData(mePtr_);
void Foam::faceZone::resetAddressing(faceZone&& zn)
{
// TDB: clearGeom();
if (this == &zn)
{
return; // Self-assignment is a no-op
}
clearAddressing();
labelList::transfer(static_cast<labelList&>(zn));
flipMap_.transfer(zn.flipMap_);
zn.clearAddressing();
}
void Foam::faceZone::resetAddressing(const faceZone& zn)
{
// TDB: clearGeom();
if (this == &zn)
{
return; // Self-assignment is a no-op
}
clearAddressing();
labelList::operator=(static_cast<const labelList&>(zn));
flipMap_ = zn.flipMap_;
} }
@ -452,6 +522,18 @@ void Foam::faceZone::resetAddressing
} }
void Foam::faceZone::resetAddressing
(
labelList&& addr,
const bool flipMapValue
)
{
clearAddressing();
labelList::transfer(addr);
setFlipMap(flipMapValue);
}
void Foam::faceZone::resetAddressing void Foam::faceZone::resetAddressing
( (
const labelUList& addr, const labelUList& addr,
@ -464,18 +546,6 @@ void Foam::faceZone::resetAddressing
} }
void Foam::faceZone::resetAddressing
(
labelList&& addr,
const bool flipMapValue
)
{
clearAddressing();
labelList::transfer(addr);
setFlipMap(flipMapValue);
}
void Foam::faceZone::updateMesh(const mapPolyMesh& mpm) void Foam::faceZone::updateMesh(const mapPolyMesh& mpm)
{ {
clearAddressing(); clearAddressing();
@ -485,6 +555,7 @@ void Foam::faceZone::updateMesh(const mapPolyMesh& mpm)
label nFaces = 0; label nFaces = 0;
const labelList& addr = *this; const labelList& addr = *this;
const boolList& flips = flipMap();
const labelList& faceMap = mpm.reverseFaceMap(); const labelList& faceMap = mpm.reverseFaceMap();
forAll(addr, i) forAll(addr, i)
@ -494,15 +565,15 @@ void Foam::faceZone::updateMesh(const mapPolyMesh& mpm)
if (faceMap[facei] >= 0) if (faceMap[facei] >= 0)
{ {
newAddressing[nFaces] = faceMap[facei]; newAddressing[nFaces] = faceMap[facei];
newFlipMap[nFaces] = flipMap_[i]; // Keep flip map. newFlipMap[nFaces] = flips[i]; // Keep flip map
nFaces++; ++nFaces;
} }
} }
newAddressing.setSize(nFaces); newAddressing.resize(nFaces);
newFlipMap.setSize(nFaces); newFlipMap.resize(nFaces);
transfer(newAddressing); labelList::transfer(newAddressing);
flipMap_.transfer(newFlipMap); flipMap_.transfer(newFlipMap);
} }
@ -526,6 +597,7 @@ bool Foam::faceZone::checkParallelSync(const bool report) const
{ {
const labelList& addr = *this; const labelList& addr = *this;
const boolList& flips = flipMap();
boolList neiZoneFace(mesh.nBoundaryFaces(), false); boolList neiZoneFace(mesh.nBoundaryFaces(), false);
boolList neiZoneFlip(mesh.nBoundaryFaces(), false); boolList neiZoneFlip(mesh.nBoundaryFaces(), false);
@ -536,13 +608,14 @@ bool Foam::faceZone::checkParallelSync(const bool report) const
if (!mesh.isInternalFace(facei)) if (!mesh.isInternalFace(facei))
{ {
neiZoneFace[facei-mesh.nInternalFaces()] = true; const label bFacei = facei-mesh.nInternalFaces();
neiZoneFlip[facei-mesh.nInternalFaces()] = flipMap()[i]; neiZoneFace[bFacei] = true;
neiZoneFlip[bFacei] = flips[i];
} }
} }
boolList myZoneFace(neiZoneFace); boolList myZoneFace(neiZoneFace);
syncTools::swapBoundaryFaceList(mesh, neiZoneFace);
boolList myZoneFlip(neiZoneFlip); boolList myZoneFlip(neiZoneFlip);
syncTools::swapBoundaryFaceList(mesh, neiZoneFace);
syncTools::swapBoundaryFaceList(mesh, neiZoneFlip); syncTools::swapBoundaryFaceList(mesh, neiZoneFlip);
forAll(addr, i) forAll(addr, i)
@ -564,9 +637,8 @@ bool Foam::faceZone::checkParallelSync(const bool report) const
Pout<< " ***Problem with faceZone " << index() Pout<< " ***Problem with faceZone " << index()
<< " named " << name() << " named " << name()
<< ". Face " << facei << ". Face " << facei
<< " on coupled patch " << " on coupled patch " << bm[patchi].name()
<< bm[patchi].name() << " is inconsistent with its coupled neighbour."
<< " is not consistent with its coupled neighbour."
<< endl; << endl;
} }
else else
@ -585,10 +657,8 @@ bool Foam::faceZone::checkParallelSync(const bool report) const
Pout<< " ***Problem with faceZone " << index() Pout<< " ***Problem with faceZone " << index()
<< " named " << name() << " named " << name()
<< ". Face " << facei << ". Face " << facei
<< " on coupled patch " << " on coupled patch " << bm[patchi].name()
<< bm[patchi].name() << " has inconsistent flipMap across coupled faces."
<< " does not have consistent flipMap"
<< " across coupled faces."
<< endl; << endl;
} }
else else
@ -634,6 +704,21 @@ void Foam::faceZone::writeDict(Ostream& os) const
} }
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::faceZone::operator=(const faceZone& zn)
{
if (this == &zn)
{
return; // Self-assignment is a no-op
}
clearAddressing();
labelList::operator=(static_cast<const labelList&>(zn));
flipMap_ = zn.flipMap_;
}
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const faceZone& zn) Foam::Ostream& Foam::operator<<(Ostream& os, const faceZone& zn)

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -66,6 +66,16 @@ class faceZone
: :
public zone public zone
{ {
// // Public Data Types
//
// //- Side of the face zone
// enum side
// {
// FRONT = 1, //!< The front (positive normal) side of the face
// BACK = -1, //!< The back (negative normal) side of the face
// };
// Private Data // Private Data
//- Flip map for all faces in the zone. //- Flip map for all faces in the zone.
@ -76,16 +86,16 @@ class faceZone
const faceZoneMesh& zoneMesh_; const faceZoneMesh& zoneMesh_;
//- Demand-driven: Primitive patch of correctly flipped faces //- Demand-driven: Primitive patch of correctly flipped faces
mutable primitiveFacePatch* patchPtr_; mutable std::unique_ptr<primitiveFacePatch> patchPtr_;
//- Demand-driven: Master cell layer //- Demand-driven: front cell layer (positive normal) side of faces
mutable labelList* masterCellsPtr_; mutable std::unique_ptr<labelList> frontCellsPtr_;
//- Demand-driven: Slave cell layer //- Demand-driven: back cell layer (negative normal) side of faces
mutable labelList* slaveCellsPtr_; mutable std::unique_ptr<labelList> backCellsPtr_;
//- Demand-driven: Global edge addressing //- Demand-driven: Global edge addressing
mutable labelList* mePtr_; mutable std::unique_ptr<labelList> mePtr_;
// Private Member Functions // Private Member Functions
@ -96,19 +106,14 @@ class faceZone
//- Build primitive patch //- Build primitive patch
void calcFaceZonePatch() const; void calcFaceZonePatch() const;
//- Calculate master and slave face layer //- Calculate front/back cell layers
void calcCellLayers() const; void calcCellLayers() const;
//- Check addressing //- Check addressing
void checkAddressing() const; void checkAddressing() const;
//- Clear out geometry and demand-driven data
//- No copy construct void clearGeom();
faceZone(const faceZone&) = delete;
//- No copy assignment
void operator=(const faceZone&) = delete;
public: public:
@ -142,7 +147,13 @@ public:
// Constructors // Constructors
//- Construct an empty zone //- No copy construct
faceZone(const faceZone&) = delete;
//- Construct an empty zone - name="", index=0
explicit faceZone(const faceZoneMesh& zm);
//- Construct an empty zone with specified name and index
faceZone faceZone
( (
const word& name, const word& name,
@ -171,7 +182,7 @@ public:
const faceZoneMesh& zm const faceZoneMesh& zm
); );
//- Construct from components //- Construct from components, copying addressing
faceZone faceZone
( (
const word& name, const word& name,
@ -200,12 +211,32 @@ public:
const faceZoneMesh& zm const faceZoneMesh& zm
); );
//- Construct empty with original zone information (name, index, groups)
//- and mesh reference. Optionally specify a new index.
faceZone
(
const faceZone& originalZone,
const Foam::zero,
const faceZoneMesh& zm,
const label newIndex = -1
);
//- Construct empty with original zone information (name, groups),
//- resetting the index and zone mesh reference.
faceZone
(
const faceZone& originalZone,
const Foam::zero,
const label index,
const faceZoneMesh& zm
);
//- Construct with a new index and zone mesh information, the name //- Construct with a new index and zone mesh information, the name
//- of the original zone, resetting the face addressing //- of the original zone, resetting the face addressing
//- and flip-map. //- and flip-map.
faceZone faceZone
( (
const faceZone& origZone, const faceZone& originalZone,
const labelUList& addr, const labelUList& addr,
const boolUList& fm, const boolUList& fm,
const label index, const label index,
@ -217,7 +248,7 @@ public:
//- and flip-map. //- and flip-map.
faceZone faceZone
( (
const faceZone& origZone, const faceZone& originalZone,
labelList&& addr, labelList&& addr,
boolList&& fm, boolList&& fm,
const label index, const label index,
@ -258,71 +289,46 @@ public:
//- Destructor //- Destructor
virtual ~faceZone(); virtual ~faceZone() = default;
// Member Functions // Member Functions
//- Return reference to the zone mesh //- Return reference to the zone mesh
const faceZoneMesh& zoneMesh() const noexcept const faceZoneMesh& zoneMesh() const noexcept { return zoneMesh_; }
//- The addressing (face IDs) used for the zone
const labelList& addressing() const noexcept
{ {
return zoneMesh_; return static_cast<const labelList&>(*this);
} }
//- Return face flip map //- Return face flip map
const boolList& flipMap() const noexcept const boolList& flipMap() const noexcept { return flipMap_; }
{
return flipMap_;
}
//- Helper function to re-direct to zone::localID(...) //- Helper function to re-direct to zone::localID(...)
label whichFace(const label globalCellID) const; label whichFace(const label globalCellID) const;
//- Return reference to primitive patch //- Return [demand-driven] reference to an equivalent primitive patch,
const primitiveFacePatch& operator()() const; //- with faces oriented according to flipMap()
const primitiveFacePatch& patch() const;
// Addressing into mesh // Addressing into mesh
//- Return labels of master cells (cells next to the master face //- The front cells layer.
//- zone in the prescribed direction) //- Cells on the positive normal side of faces.
const labelList& masterCells() const; // \warning may contain negative indices for boundary faces!
const labelList& frontCells() const;
//- Return labels of slave cells //- The back cells layer.
const labelList& slaveCells() const; //- Cells on the negative normal side of faces.
// \warning may contain negative indices for boundary faces!
const labelList& backCells() const;
//- Return global edge index for local edges //- Return global edge index for local edges
const labelList& meshEdges() const; const labelList& meshEdges() const;
//- Clear addressing
virtual void clearAddressing();
//- Reset addressing - use uniform flip map value
// Clears demand-driven data.
virtual void resetAddressing
(
const labelUList& addr,
const bool flipMapValue
);
//- Reset addressing and flip map.
// Clears demand-driven data.
virtual void resetAddressing
(
const labelUList& addr,
const boolUList& flipMap
);
//- Move reset addressing - use uniform flip map value
// Clears demand-driven data.
virtual void resetAddressing
(
labelList&& addr,
const bool flipMapValue
);
//- Check zone definition. Return true if in error. //- Check zone definition. Return true if in error.
virtual bool checkDefinition(const bool report = false) const; virtual bool checkDefinition(const bool report = false) const;
@ -343,10 +349,68 @@ public:
virtual void writeDict(Ostream& os) const; virtual void writeDict(Ostream& os) const;
// Assign addressing
//- Clear addressing
//- (remove lookup maps, patch/geometric information)
virtual void clearAddressing();
//- Clear primitive addressing
virtual void clearPrimitives();
//- Move reset addressing and flip map from another zone
virtual void resetAddressing(faceZone&& zn);
//- Copy reset addressing and flip map from another zone
virtual void resetAddressing(const faceZone& zn);
//- Reset addressing - use uniform flip map value
// Clears demand-driven data.
virtual void resetAddressing
(
const labelUList& addr,
const bool flipMapValue
);
//- Move reset addressing - use uniform flip map value
// Clears demand-driven data.
virtual void resetAddressing
(
labelList&& addr,
const bool flipMapValue
);
//- Copy reset addressing and flip map.
// Clears demand-driven data.
virtual void resetAddressing
(
const labelUList& addr,
const boolUList& flipMap
);
//- Assign addressing, clearing demand-driven data
void operator=(const faceZone& zn);
// I-O // I-O
//- Ostream Operator //- Ostream Operator
friend Ostream& operator<<(Ostream& os, const faceZone& zn); friend Ostream& operator<<(Ostream& os, const faceZone& zn);
// Housekeeping
//- Deprecated(2023-09) same as patch()
// \deprecated(2023-09) same as patch()
const primitiveFacePatch& operator()() const { return this->patch(); }
//- Deprecated(2023-09) same as frontCells
// \deprecated(2023-09) same as frontCells #1832
const labelList& masterCells() const { return frontCells(); }
//- Deprecated(2023-09) same as backCells
// \deprecated(2023-09) same as backCells #1832
const labelList& slaveCells() const { return backCells(); }
}; };

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -47,6 +47,12 @@ const char* const Foam::pointZone::labelsName = "pointLabels";
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::pointZone::pointZone(const pointZoneMesh& zm)
:
pointZone(word::null, 0, zm)
{}
Foam::pointZone::pointZone Foam::pointZone::pointZone
( (
const word& name, const word& name,
@ -100,28 +106,56 @@ Foam::pointZone::pointZone
Foam::pointZone::pointZone Foam::pointZone::pointZone
( (
const pointZone& origZone, const pointZone& originalZone,
const labelUList& addr, const Foam::zero,
const label index, const pointZoneMesh& zm,
const pointZoneMesh& zm const label newIndex
) )
: :
zone(origZone, addr, index), zone(originalZone, labelList(), newIndex),
zoneMesh_(zm) zoneMesh_(zm)
{} {}
Foam::pointZone::pointZone Foam::pointZone::pointZone
( (
const pointZone& origZone, const pointZone& originalZone,
const Foam::zero,
const label index,
const pointZoneMesh& zm
)
:
zone(originalZone, labelList(), index),
zoneMesh_(zm)
{}
Foam::pointZone::pointZone
(
const pointZone& originalZone,
const labelUList& addr,
const label index,
const pointZoneMesh& zm
)
:
pointZone(originalZone, Foam::zero{}, index, zm)
{
labelList::operator=(addr);
}
Foam::pointZone::pointZone
(
const pointZone& originalZone,
labelList&& addr, labelList&& addr,
const label index, const label index,
const pointZoneMesh& zm const pointZoneMesh& zm
) )
: :
zone(origZone, std::move(addr), index), pointZone(originalZone, Foam::zero{}, index, zm)
zoneMesh_(zm) {
{} labelList::transfer(addr);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -204,12 +238,56 @@ void Foam::pointZone::writeDict(Ostream& os) const
} }
void Foam::pointZone::resetAddressing(pointZone&& zn)
{
if (this == &zn)
{
return; // Self-assignment is a no-op
}
clearAddressing();
labelList::transfer(static_cast<labelList&>(zn));
zn.clearAddressing();
}
void Foam::pointZone::resetAddressing(const pointZone& zn)
{
if (this == &zn)
{
return; // Self-assignment is a no-op
}
clearAddressing();
labelList::operator=(static_cast<const labelList&>(zn));
}
void Foam::pointZone::resetAddressing(const labelUList& addr)
{
clearAddressing();
labelList::operator=(addr);
}
void Foam::pointZone::resetAddressing(labelList&& addr)
{
clearAddressing();
labelList::transfer(addr);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::pointZone::operator=(const pointZone& zn) void Foam::pointZone::operator=(const pointZone& zn)
{ {
if (this == &zn)
{
return; // Self-assignment is a no-op
}
clearAddressing(); clearAddressing();
labelList::operator=(zn); labelList::operator=(static_cast<const labelList&>(zn));
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -43,8 +43,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef pointZone_H #ifndef Foam_pointZone_H
#define pointZone_H #define Foam_pointZone_H
#include "zone.H" #include "zone.H"
#include "pointZoneMeshFwd.H" #include "pointZoneMeshFwd.H"
@ -72,13 +72,6 @@ class pointZone
//- Reference to zone list //- Reference to zone list
const pointZoneMesh& zoneMesh_; const pointZoneMesh& zoneMesh_;
// Private Member Functions
//- No copy construct
pointZone(const pointZone&) = delete;
public: public:
// Static Data Members // Static Data Members
@ -111,7 +104,13 @@ public:
// Constructors // Constructors
//- Construct an empty zone //- No copy construct
pointZone(const pointZone&) = delete;
//- Construct an empty zone - name="", index=0
explicit pointZone(const pointZoneMesh& zm);
//- Construct an empty zone with specified name and index
pointZone pointZone
( (
const word& name, const word& name,
@ -146,11 +145,31 @@ public:
const pointZoneMesh& zm const pointZoneMesh& zm
); );
//- Construct with a new index and zone mesh information, the name //- Construct empty with original zone information (name, index, groups)
//- of the original zone, resetting the point addressing. //- and mesh reference. Optionally specify a new index.
pointZone pointZone
( (
const pointZone& origZone, const pointZone& originalZone,
const Foam::zero,
const pointZoneMesh& zm,
const label newIndex = -1
);
//- Construct empty with original zone information (name, groups),
//- resetting the index and zone mesh reference.
pointZone
(
const pointZone& originalZone,
const Foam::zero,
const label index,
const pointZoneMesh& zm
);
//- Construct with original zone information (name, groups),
//- resetting the point addressing, the index and zone mesh reference.
pointZone
(
const pointZone& originalZone,
const labelUList& addr, const labelUList& addr,
const label index, const label index,
const pointZoneMesh& zm const pointZoneMesh& zm
@ -160,7 +179,7 @@ public:
//- of the original zone, (move) resetting the point addressing. //- of the original zone, (move) resetting the point addressing.
pointZone pointZone
( (
const pointZone& origZone, const pointZone& originalZone,
labelList&& addr, labelList&& addr,
const label index, const label index,
const pointZoneMesh& zm const pointZoneMesh& zm
@ -206,9 +225,12 @@ public:
// Member Functions // Member Functions
//- Return reference to the zone mesh //- Return reference to the zone mesh
const pointZoneMesh& zoneMesh() const noexcept const pointZoneMesh& zoneMesh() const noexcept { return zoneMesh_; }
//- The addressing (point IDs) used for the zone
const labelList& addressing() const noexcept
{ {
return zoneMesh_; return static_cast<const labelList&>(*this);
} }
//- Helper function to re-direct to zone::localID(...) //- Helper function to re-direct to zone::localID(...)
@ -230,7 +252,19 @@ public:
virtual void writeDict(Ostream& os) const; virtual void writeDict(Ostream& os) const;
// Member Operators // Assign addressing
//- Move reset addressing from another zone.
virtual void resetAddressing(pointZone&& zn);
//- Copy reset addressing from another zone
virtual void resetAddressing(const pointZone& zn);
//- Copy assign addressing
virtual void resetAddressing(const labelUList& addr);
//- Move assign addressing
virtual void resetAddressing(labelList&& addr);
//- Assign addressing, clearing demand-driven data //- Assign addressing, clearing demand-driven data
void operator=(const pointZone& zn); void operator=(const pointZone& zn);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2022 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -30,13 +30,12 @@ License
#include "dictionary.H" #include "dictionary.H"
#include "HashSet.H" #include "HashSet.H"
#include "IOstream.H" #include "IOstream.H"
#include "demandDrivenData.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
defineTypeNameAndDebug(zone, 0); defineTypeName(zone);
} }
@ -65,10 +64,10 @@ Foam::zone::zone
const label index const label index
) )
: :
zoneIdentifier(name, index), zone(name, index)
labelList(addr), {
lookupMapPtr_(nullptr) labelList::operator=(addr);
{} }
Foam::zone::zone Foam::zone::zone
@ -78,10 +77,10 @@ Foam::zone::zone
const label index const label index
) )
: :
zoneIdentifier(name, index), zone(name, index)
labelList(std::move(addr)), {
lookupMapPtr_(nullptr) labelList::transfer(addr);
{} }
Foam::zone::zone Foam::zone::zone
@ -100,50 +99,44 @@ Foam::zone::zone
Foam::zone::zone Foam::zone::zone
( (
const zone& origZone, const zone& originalZone,
const labelUList& addr, const labelUList& addr,
const label index const label newIndex
) )
: :
zone(origZone.name(), addr, index) zoneIdentifier(originalZone, newIndex),
labelList(addr),
lookupMapPtr_(nullptr)
{} {}
Foam::zone::zone Foam::zone::zone
( (
const zone& origZone, const zone& originalZone,
labelList&& addr, labelList&& addr,
const label index const label newIndex
) )
: :
zone(origZone.name(), std::move(addr), index) zoneIdentifier(originalZone, newIndex),
labelList(std::move(addr)),
lookupMapPtr_(nullptr)
{} {}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::zone::~zone()
{
clearAddressing();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::Map<Foam::label>& Foam::zone::lookupMap() const const Foam::Map<Foam::label>& Foam::zone::lookupMap() const
{ {
if (!lookupMapPtr_) if (!lookupMapPtr_)
{ {
DebugInFunction << "Calculating lookup map" << endl;
const labelList& addr = *this; const labelList& addr = *this;
lookupMapPtr_ = new Map<label>(2*addr.size()); lookupMapPtr_.reset(new Map<label>(2*addr.size()));
auto& lm = *lookupMapPtr_; auto& map = *lookupMapPtr_;
forAll(addr, i) for (const label id : addr)
{ {
lm.insert(addr[i], i); map.insert(id, map.size());
} }
} }
@ -159,7 +152,13 @@ Foam::label Foam::zone::localID(const label globalID) const
void Foam::zone::clearAddressing() void Foam::zone::clearAddressing()
{ {
deleteDemandDrivenData(lookupMapPtr_); lookupMapPtr_.reset(nullptr);
}
void Foam::zone::clearPrimitives()
{
static_cast<labelList&>(*this).clear();
} }
@ -170,11 +169,11 @@ bool Foam::zone::checkDefinition(const label maxSize, const bool report) const
bool hasError = false; bool hasError = false;
// To check for duplicate entries // To check for duplicate entries
labelHashSet elems(size()); labelHashSet elems(2*size());
for (const label idx : addr) for (const label id : addr)
{ {
if (idx < 0 || idx >= maxSize) if (id < 0 || id >= maxSize)
{ {
hasError = true; hasError = true;
@ -182,7 +181,7 @@ bool Foam::zone::checkDefinition(const label maxSize, const bool report) const
{ {
SeriousErrorInFunction SeriousErrorInFunction
<< "Zone " << this->name() << "Zone " << this->name()
<< " contains invalid index label " << idx << nl << " contains invalid index label " << id << nl
<< "Valid index labels are 0.." << "Valid index labels are 0.."
<< maxSize-1 << endl; << maxSize-1 << endl;
} }
@ -192,13 +191,13 @@ bool Foam::zone::checkDefinition(const label maxSize, const bool report) const
break; break;
} }
} }
else if (!elems.insert(idx)) else if (!elems.insert(id))
{ {
if (report) if (report)
{ {
WarningInFunction WarningInFunction
<< "Zone " << this->name() << "Zone " << this->name()
<< " contains duplicate index label " << idx << endl; << " contains duplicate index label " << id << endl;
} }
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2021 OpenCFD Ltd. Copyright (C) 2017-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -38,8 +38,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef zone_H #ifndef Foam_zone_H
#define zone_H #define Foam_zone_H
#include "zoneIdentifier.H" #include "zoneIdentifier.H"
#include "labelList.H" #include "labelList.H"
@ -69,13 +69,13 @@ class zone
// Private Data // Private Data
//- Demand-driven: map of labels in zone for fast location lookup //- Demand-driven: map of labels in zone for fast location lookup
mutable Map<label>* lookupMapPtr_; mutable std::unique_ptr<Map<label>> lookupMapPtr_;
public: public:
//- Runtime type information //- Runtime type information
TypeName("zone"); TypeNameNoDebug("zone");
// Constructors // Constructors
@ -83,7 +83,7 @@ public:
//- Default construct //- Default construct
zone(); zone();
//- Construct an empty zone //- Construct an empty zone with specified name and index
zone(const word& name, const label index); zone(const word& name, const label index);
//- Copy construct from components //- Copy construct from components
@ -112,26 +112,26 @@ public:
); );
//- Construct given the name of the original zone (name is used) //- Construct given the name of the original zone (name is used)
//- and resetting addressing and index. //- with new addressing and index (-ve: retain zone index).
zone zone
( (
const zone& origZone, const zone& originalZone,
const labelUList& addr, const labelUList& addr,
const label index const label index
); );
//- Construct given the name of the original zone (name is used) //- Construct given the name of the original zone (name is used)
//- and (move) resetting addressing and index. //- and (move) resetting addressing and index (-ve: retain zone index).
zone zone
( (
const zone& origZone, const zone& originalZone,
labelList&& addr, labelList&& addr,
const label index const label index
); );
//- Destructor //- Destructor
virtual ~zone(); virtual ~zone() = default;
// Member Functions // Member Functions
@ -143,7 +143,6 @@ public:
// \return the local address, or -1 if the item is not in the zone // \return the local address, or -1 if the item is not in the zone
label localID(const label globalID) const; label localID(const label globalID) const;
//- The addressing used by the zone //- The addressing used by the zone
const labelList& addressing() const noexcept const labelList& addressing() const noexcept
{ {
@ -151,8 +150,11 @@ public:
} }
//- Clear addressing //- Clear addressing
//- (remove lookup maps and other auxiliary information)
virtual void clearAddressing(); virtual void clearAddressing();
//- Clear primitive addressing
virtual void clearPrimitives();
//- Check zone definition. Return true if in error. //- Check zone definition. Return true if in error.
virtual bool checkDefinition(const bool report = false) const = 0; virtual bool checkDefinition(const bool report = false) const = 0;

View File

@ -51,19 +51,19 @@ bool Foam::polyTopoChanger::readContents()
// Read modifiers // Read modifiers
Istream& is = readStream(typeName); Istream& is = readStream(typeName);
PtrList<entry> patchEntries(is); PtrList<entry> entries(is);
modifiers.setSize(patchEntries.size()); modifiers.resize_null(entries.size());
forAll(modifiers, modifierI) forAll(modifiers, modifieri)
{ {
modifiers.set modifiers.set
( (
modifierI, modifieri,
polyMeshModifier::New polyMeshModifier::New
( (
patchEntries[modifierI].keyword(), entries[modifieri].keyword(),
patchEntries[modifierI].dict(), entries[modifieri].dict(),
modifierI, modifieri,
*this *this
) )
); );
@ -101,7 +101,6 @@ Foam::polyTopoChanger::polyTopoChanger
( (
polyMesh& mesh, polyMesh& mesh,
IOobjectOption::readOption rOpt IOobjectOption::readOption rOpt
) )
: :
polyTopoChanger polyTopoChanger

View File

@ -101,12 +101,12 @@ void Foam::faBoundaryMesh::calcGroupIDs() const
} }
bool Foam::faBoundaryMesh::readContents(const bool allowReadIfPresent) bool Foam::faBoundaryMesh::readContents(const bool allowOptionalRead)
{ {
if if
( (
isReadRequired() isReadRequired()
|| (allowReadIfPresent && isReadOptional() && headerOk()) || (allowOptionalRead && this->isReadOptional() && this->headerOk())
) )
{ {
// Warn for MUST_READ_IF_MODIFIED // Warn for MUST_READ_IF_MODIFIED
@ -114,12 +114,11 @@ bool Foam::faBoundaryMesh::readContents(const bool allowReadIfPresent)
faPatchList& patches = *this; faPatchList& patches = *this;
// Read faPatch list // Read entries
Istream& is = readStream(typeName); Istream& is = readStream(typeName);
// Read patches as entries PtrList<entry> entries(is);
PtrList<entry> patchEntries(is); patches.resize_null(entries.size());
patches.resize(patchEntries.size());
// Transcribe // Transcribe
forAll(patches, patchi) forAll(patches, patchi)
@ -129,8 +128,8 @@ bool Foam::faBoundaryMesh::readContents(const bool allowReadIfPresent)
patchi, patchi,
faPatch::New faPatch::New
( (
patchEntries[patchi].keyword(), entries[patchi].keyword(),
patchEntries[patchi].dict(), entries[patchi].dict(),
patchi, patchi,
*this *this
) )
@ -142,6 +141,7 @@ bool Foam::faBoundaryMesh::readContents(const bool allowReadIfPresent)
return true; return true;
} }
// Nothing read
return false; return false;
} }
@ -158,10 +158,23 @@ Foam::faBoundaryMesh::faBoundaryMesh
regIOobject(io), regIOobject(io),
mesh_(mesh) mesh_(mesh)
{ {
readContents(false); // READ_IF_PRESENT allowed: False readContents(false); // allowOptionalRead = false
} }
Foam::faBoundaryMesh::faBoundaryMesh
(
const IOobject& io,
const faMesh& pm,
Foam::zero
)
:
faPatchList(),
regIOobject(io),
mesh_(pm)
{}
Foam::faBoundaryMesh::faBoundaryMesh Foam::faBoundaryMesh::faBoundaryMesh
( (
const IOobject& io, const IOobject& io,
@ -175,6 +188,31 @@ Foam::faBoundaryMesh::faBoundaryMesh
{} {}
Foam::faBoundaryMesh::faBoundaryMesh
(
const IOobject& io,
const faMesh& fam,
const faPatchList& list
)
:
faPatchList(),
regIOobject(io),
mesh_(fam)
{
if (!readContents(true)) // allowOptionalRead = true
{
// Nothing read. Use supplied patches
faPatchList& patches = *this;
patches.resize(list.size());
forAll(patches, patchi)
{
patches.set(patchi, list[patchi].clone(*this));
}
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
void Foam::faBoundaryMesh::clear() void Foam::faBoundaryMesh::clear()
@ -360,7 +398,7 @@ void Foam::faBoundaryMesh::setGroup
const labelUList& patchIDs const labelUList& patchIDs
) )
{ {
groupIDsPtr_.clear(); groupIDsPtr_.reset(nullptr);
faPatchList& patches = *this; faPatchList& patches = *this;

View File

@ -87,8 +87,9 @@ class faBoundaryMesh
//- Calculate group name to patch ids lookup //- Calculate group name to patch ids lookup
void calcGroupIDs() const; void calcGroupIDs() const;
//- Read if IOobject flags set. Return true if read. //- Return true if contents were read
bool readContents(const bool allowReadIfPresent); //- (controlled by IOobject readOption flags).
bool readContents(const bool allowOptionalRead);
public: public:
@ -108,14 +109,24 @@ public:
// Constructors // Constructors
//- Construct from faMesh //- Read construct given IOobject and a mesh reference.
//- It will only read for MUST_READ variants (not READ_IF_PRESENT).
faBoundaryMesh faBoundaryMesh
( (
const IOobject& io, const IOobject& io,
const faMesh& fam const faMesh& fam
); );
//- Construct from faMesh and given size //- Construct empty with IOobject properties and a mesh reference.
//- Does not read.
faBoundaryMesh
(
const IOobject& io,
const faMesh& fam,
Foam::zero
);
//- Construct with specified size. Does not read.
faBoundaryMesh faBoundaryMesh
( (
const IOobject& io, const IOobject& io,
@ -123,6 +134,15 @@ public:
const label size const label size
); );
//- Read construct (mandatory, optional) based on IOobject properties
//- or use the fallback PtrList (with cloning).
faBoundaryMesh
(
const IOobject& io,
const faMesh& fam,
const faPatchList& list
);
//- Destructor //- Destructor
~faBoundaryMesh() = default; ~faBoundaryMesh() = default;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2022 OpenCFD Ltd. Copyright (C) 2022-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -26,6 +26,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "faBoundaryMeshEntries.H" #include "faBoundaryMeshEntries.H"
#include "processorFaPatch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -34,4 +35,30 @@ namespace Foam
defineTypeName(faBoundaryMeshEntries); defineTypeName(faBoundaryMeshEntries);
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::faBoundaryMeshEntries::removeProcPatches()
{
// Truncate at the first processor patch entry
PtrList<entry>& entries = *this;
label nNonProcessor = entries.size();
forAll(entries, patchi)
{
const dictionary& dict = entries[patchi].dict();
const word pType = dict.get<word>("type");
if (pType == processorFaPatch::typeName)
{
nNonProcessor = patchi;
break;
}
}
entries.resize(nNonProcessor);
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -52,8 +52,8 @@ namespace Foam
class faBoundaryMeshEntries class faBoundaryMeshEntries
: :
public regIOobject, public PtrList<entry>,
public PtrList<entry> public regIOobject
{ {
public: public:
@ -66,18 +66,25 @@ public:
//- Read construct from IOobject //- Read construct from IOobject
explicit faBoundaryMeshEntries(const IOobject& io) explicit faBoundaryMeshEntries(const IOobject& io)
: :
regIOobject(io), regIOobject(io)
PtrList<entry>()
{ {
if (isReadRequired() || (isReadOptional() && headerOk())) if (isReadRequired() || (isReadOptional() && headerOk()))
{ {
readStream(typeName) >> *this; // Read as entries
Istream& is = readStream(typeName);
is >> *this;
close();
} }
} }
// Member Functions // Member Functions
//- Truncate at the first processor patch entry
void removeProcPatches();
//- The class is probably read-only
bool writeData(Ostream&) const bool writeData(Ostream&) const
{ {
NotImplemented; NotImplemented;

View File

@ -36,7 +36,6 @@ License
#include "polyMesh.H" #include "polyMesh.H"
#include "polyPatch.H" #include "polyPatch.H"
//#include "pointPatchField.H" //#include "pointPatchField.H"
#include "demandDrivenData.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -85,9 +84,9 @@ Foam::wordList Foam::faPatch::constraintTypes()
void Foam::faPatch::clearOut() void Foam::faPatch::clearOut()
{ {
deleteDemandDrivenData(edgeFacesPtr_); edgeFacesPtr_.reset(nullptr);
deleteDemandDrivenData(pointLabelsPtr_); pointLabelsPtr_.reset(nullptr);
deleteDemandDrivenData(pointEdgesPtr_); pointEdgesPtr_.reset(nullptr);
} }
@ -332,8 +331,9 @@ void Foam::faPatch::calcPointLabels() const
} }
// Transfer to plain list (reuse storage) // Transfer to plain list (reuse storage)
pointLabelsPtr_ = new labelList(std::move(dynEdgePoints)); pointLabelsPtr_.reset(new labelList(std::move(dynEdgePoints)));
/// const labelList& edgePoints = *pointLabelsPtr_;
/// const auto& edgePoints = *pointLabelsPtr_;
/// ///
/// // Cannot use invertManyToMany - we have non-local edge numbering /// // Cannot use invertManyToMany - we have non-local edge numbering
/// ///
@ -350,7 +350,7 @@ void Foam::faPatch::calcPointLabels() const
/// } /// }
/// ///
/// // Flatten to regular list /// // Flatten to regular list
/// pointEdgesPtr_ = new labelListList(edgePoints.size()); /// pointEdgesPtr_.reset(new labelListList(edgePoints.size()));
/// auto& pEdges = *pointEdgesPtr_; /// auto& pEdges = *pointEdgesPtr_;
/// ///
/// forAll(pEdges, pointi) /// forAll(pEdges, pointi)
@ -381,7 +381,7 @@ void Foam::faPatch::calcPointEdges() const
} }
// Flatten to regular list // Flatten to regular list
pointEdgesPtr_ = new labelListList(edgePoints.size()); pointEdgesPtr_.reset(new labelListList(edgePoints.size()));
auto& pEdges = *pointEdgesPtr_; auto& pEdges = *pointEdgesPtr_;
forAll(pEdges, pointi) forAll(pEdges, pointi)
@ -441,9 +441,12 @@ const Foam::labelUList& Foam::faPatch::edgeFaces() const
{ {
if (!edgeFacesPtr_) if (!edgeFacesPtr_)
{ {
edgeFacesPtr_ = new labelList::subList edgeFacesPtr_.reset
(
new labelList::subList
( (
patchSlice(boundaryMesh().mesh().edgeOwner()) patchSlice(boundaryMesh().mesh().edgeOwner())
)
); );
} }

View File

@ -86,13 +86,13 @@ class faPatch
const faBoundaryMesh& boundaryMesh_; const faBoundaryMesh& boundaryMesh_;
//- Demand-driven: edge-face addressing //- Demand-driven: edge-face addressing
mutable labelList::subList* edgeFacesPtr_; mutable std::unique_ptr<labelList::subList> edgeFacesPtr_;
//- Demand-driven: local points labels //- Demand-driven: local points labels
mutable labelList* pointLabelsPtr_; mutable std::unique_ptr<labelList> pointLabelsPtr_;
//- Demand-driven: point-edge addressing //- Demand-driven: point-edge addressing
mutable labelListList* pointEdgesPtr_; mutable std::unique_ptr<labelListList> pointEdgesPtr_;
// Private Member Functions // Private Member Functions

View File

@ -70,14 +70,6 @@ class fvBoundaryMesh
//- Assign fvPatches corresponding to the given polyBoundaryMesh //- Assign fvPatches corresponding to the given polyBoundaryMesh
void addPatches(const polyBoundaryMesh& pbm); void addPatches(const polyBoundaryMesh& pbm);
//- No copy construct
fvBoundaryMesh(const fvBoundaryMesh&) = delete;
//- No copy assignment
void operator=(const fvBoundaryMesh&) = delete;
protected: protected:
//- Update boundary based on new polyBoundaryMesh //- Update boundary based on new polyBoundaryMesh
@ -86,9 +78,19 @@ protected:
public: public:
//- Declare friendship with fvMesh
friend class fvMesh; friend class fvMesh;
// Generated Methods
//- No copy construct
fvBoundaryMesh(const fvBoundaryMesh&) = delete;
//- No copy assignment
void operator=(const fvBoundaryMesh&) = delete;
// Constructors // Constructors
//- Construct zero size with mesh reference //- Construct zero size with mesh reference
@ -101,10 +103,7 @@ public:
// Member Functions // Member Functions
//- Return the mesh reference //- Return the mesh reference
const fvMesh& mesh() const noexcept const fvMesh& mesh() const noexcept { return mesh_; }
{
return mesh_;
}
//- Return a list of faceCells for each patch //- Return a list of faceCells for each patch
UPtrList<const labelUList> faceCells() const; UPtrList<const labelUList> faceCells() const;

View File

@ -30,7 +30,6 @@ License
#include "primitiveMesh.H" #include "primitiveMesh.H"
#include "HashSet.H" #include "HashSet.H"
#include "Map.H" #include "Map.H"
#include "demandDrivenData.H"
#include "ListOps.H" #include "ListOps.H"
#include "meshTools.H" #include "meshTools.H"
@ -257,9 +256,8 @@ void Foam::cellFeatures::calcSuperFaces() const
// Construct superFaces // Construct superFaces
facesPtr_ = new faceList(superFacei); facesPtr_.reset(new faceList(superFacei));
auto& faces = *facesPtr_;
faceList& faces = *facesPtr_;
forAll(cFaces, cFacei) forAll(cFaces, cFacei)
{ {
@ -390,16 +388,13 @@ Foam::cellFeatures::cellFeatures
featureEdge_.insert(edgeI); featureEdge_.insert(edgeI);
} }
} }
} }
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::cellFeatures::~cellFeatures() Foam::cellFeatures::~cellFeatures()
{ {}
deleteDemandDrivenData(facesPtr_);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

View File

@ -39,8 +39,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef cellFeatures_H #ifndef Foam_cellFeatures_H
#define cellFeatures_H #define Foam_cellFeatures_H
#include "faceList.H" #include "faceList.H"
#include "labelList.H" #include "labelList.H"
@ -54,7 +54,7 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of classes // Forward Declarations
class primitiveMesh; class primitiveMesh;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
@ -77,7 +77,7 @@ class cellFeatures
labelHashSet featureEdge_; labelHashSet featureEdge_;
//- (demand driven) Faces after removing internal points&edges //- (demand driven) Faces after removing internal points&edges
mutable faceList* facesPtr_; mutable std::unique_ptr<faceList> facesPtr_;
//- New to old face mapping //- New to old face mapping
mutable List<DynamicList<label>> faceMap_; mutable List<DynamicList<label>> faceMap_;

View File

@ -1865,7 +1865,7 @@ void Foam::polyTopoChange::calcFaceZonePointMap
{ {
const faceZone& newZone = faceZones[zonei]; const faceZone& newZone = faceZones[zonei];
const labelList& newZoneMeshPoints = newZone().meshPoints(); const labelList& newZoneMeshPoints = newZone.patch().meshPoints();
const Map<label>& oldZoneMeshPointMap = oldFaceZoneMeshPointMaps[zonei]; const Map<label>& oldZoneMeshPointMap = oldFaceZoneMeshPointMaps[zonei];
@ -2146,7 +2146,7 @@ void Foam::polyTopoChange::compactAndReorder
{ {
const faceZone& oldZone = mesh.faceZones()[zonei]; const faceZone& oldZone = mesh.faceZones()[zonei];
oldFaceZoneMeshPointMaps[zonei] = oldZone().meshPointMap(); oldFaceZoneMeshPointMaps[zonei] = oldZone.patch().meshPointMap();
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2021 OpenCFD Ltd. Copyright (C) 2016-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -45,8 +45,8 @@ namespace Foam
Foam::topoSetSource::addToUsageTable Foam::faceZoneToCell::usage_ Foam::topoSetSource::addToUsageTable Foam::faceZoneToCell::usage_
( (
faceZoneToCell::typeName, faceZoneToCell::typeName,
"\n Usage: faceZoneToCell zone master|slave\n\n" "\n Usage: faceZoneToCell zone front|back|both\n\n"
" Select master or slave side of the faceZone." " Select front, back or both sides of the faceZone."
" Note:accepts wildcards for zone.\n\n" " Note:accepts wildcards for zone.\n\n"
); );
@ -57,9 +57,12 @@ const Foam::Enum
> >
Foam::faceZoneToCell::faceActionNames_ Foam::faceZoneToCell::faceActionNames_
({ ({
{ faceAction::MASTER, "master" }, { faceAction::FRONT, "front" },
{ faceAction::SLAVE, "slave" }, { faceAction::BACK, "back" },
//TBD: { faceAction::BOTH, "attached" }, { faceAction::BOTH, "both" },
// Compatibility
{ faceAction::FRONT, "master" },
{ faceAction::BACK, "slave" },
}); });
@ -89,23 +92,33 @@ void Foam::faceZoneToCell::combine
const auto& zone = mesh_.faceZones()[zonei]; const auto& zone = mesh_.faceZones()[zonei];
const labelList& cellLabels = if (verbosity)
( {
option_ == MASTER Info<< " Using matching zone " << zone.name();
? zone.masterCells()
: zone.slaveCells() if (option_ == faceAction::FRONT)
); {
Info<< " [front] cells:";
}
else if (option_ == faceAction::BACK)
{
Info<< " : [back] cells:";
}
if (option_ == faceAction::BOTH)
{
Info<< " : [front/back] cells:";
}
}
if (option_ == faceAction::FRONT || option_ == faceAction::BOTH)
{
const labelList& cellLabels = zone.frontCells();
if (verbosity) if (verbosity)
{ {
Info<< " Using matching zone " << zone.name() << " with " Info<< ' ' << returnReduce(cellLabels.size(), sumOp<label>());
<< returnReduce(cellLabels.size(), sumOp<label>())
<< " cells on "
<< faceActionNames_[option_] << " side" << endl;
} }
// NOTE could also handle both sides directly if required
for (const label celli : cellLabels) for (const label celli : cellLabels)
{ {
// Only do active cells // Only do active cells
@ -115,6 +128,31 @@ void Foam::faceZoneToCell::combine
} }
} }
} }
if (option_ == faceAction::BACK || option_ == faceAction::BOTH)
{
const labelList& cellLabels = zone.backCells();
if (verbosity)
{
Info<< ' ' << returnReduce(cellLabels.size(), sumOp<label>());
}
for (const label celli : cellLabels)
{
// Only do active cells
if (celli >= 0 && celli < mesh_.nCells())
{
addOrDelete(set, celli, add);
}
}
}
if (verbosity)
{
Info<< endl;
}
}
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011 OpenFOAM Foundation Copyright (C) 2011 OpenFOAM Foundation
Copyright (C) 2018-2021 OpenCFD Ltd. Copyright (C) 2018-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -28,8 +28,8 @@ Class
Foam::faceZoneToCell Foam::faceZoneToCell
Description Description
A \c topoSetCellSource to select cells based on \c master A \c topoSetCellSource to select cells based on \c front
or \c slave side of given \c faceZone(s). or \c back side of given \c faceZone(s).
Operands: Operands:
\table \table
@ -86,8 +86,9 @@ Usage
Options for the \c option entry: Options for the \c option entry:
\verbatim \verbatim
master | Master side of the faceZone front | Cells on the front side of the faceZone (also as 'master')
slave | Slave side of the faceZone back | Cells on the back side of the faceZone (also as 'slave')
both | Both front and back side of the faceZone
\endverbatim \endverbatim
Options for the conditional mandatory entries: Options for the conditional mandatory entries:
@ -134,8 +135,11 @@ public:
//- Enumeration defining the valid options //- Enumeration defining the valid options
enum faceAction enum faceAction
{ {
MASTER, FRONT, //!< The front (positive normal) side of the faces
SLAVE BACK, //!< The back (negative normal) side of the faces
BOTH, //!< Both front and back side of faces
// Compatibility
MASTER = FRONT, SLAVE = BACK
}; };

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2022 OpenCFD Ltd. Copyright (C) 2018-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -36,6 +36,56 @@ namespace Foam
} }
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::surfZoneIOList::readContents()
{
if
(
this->isReadRequired()
)
{
surfZoneList& zones = *this;
// Read entries
Istream& is = readStream(typeName);
PtrList<entry> entries(is);
zones.resize(entries.size());
// Transcribe
label startOffset = 0;
forAll(zones, zonei)
{
zones[zonei] = surfZone
(
entries[zonei].keyword(),
entries[zonei].dict(),
zonei
);
if (zones[zonei].start() != startOffset)
{
FatalErrorInFunction
<< "surfZones are not ordered. Start of zone " << zonei
<< " does not correspond to sum of preceding zones." << nl
<< "while reading " << this->objectRelPath() << endl
<< exit(FatalError);
}
startOffset += zones[zonei].size();
}
is.check(FUNCTION_NAME);
close();
return true;
}
// Nothing read
return false;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::surfZoneIOList::surfZoneIOList Foam::surfZoneIOList::surfZoneIOList
@ -46,40 +96,7 @@ Foam::surfZoneIOList::surfZoneIOList
regIOobject(io), regIOobject(io),
surfZoneList() surfZoneList()
{ {
if (isReadRequired()) readContents(); // allowOptionalRead = false
{
surfZoneList& zones = *this;
Istream& is = readStream(typeName);
PtrList<entry> dictEntries(is);
zones.resize(dictEntries.size());
label facei = 0;
forAll(zones, zonei)
{
zones[zonei] = surfZone
(
dictEntries[zonei].keyword(),
dictEntries[zonei].dict(),
zonei
);
if (zones[zonei].start() != facei)
{
FatalErrorInFunction
<< "surfZones are not ordered. Start of zone " << zonei
<< " does not correspond to sum of preceding zones." << nl
<< "while reading " << io.objectPath() << endl
<< exit(FatalError);
}
facei += zones[zonei].size();
}
is.check(FUNCTION_NAME);
close();
}
} }
@ -110,11 +127,11 @@ Foam::surfZoneIOList::surfZoneIOList
bool Foam::surfZoneIOList::writeData(Ostream& os) const bool Foam::surfZoneIOList::writeData(Ostream& os) const
{ {
const surfZoneList& zones = *this; const surfZoneList& zones = *this;
const label sz = zones.size(); const label len = zones.size();
if (sz) if (len)
{ {
os << sz << nl << token::BEGIN_LIST << incrIndent << nl; os << len << nl << token::BEGIN_LIST << incrIndent << nl;
for (const surfZone& zn : zones) for (const surfZone& zn : zones)
{ {
@ -125,7 +142,7 @@ bool Foam::surfZoneIOList::writeData(Ostream& os) const
} }
else else
{ {
os << sz << token::BEGIN_LIST << token::END_LIST; os << len << token::BEGIN_LIST << token::END_LIST;
} }
return os.good(); return os.good();

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -35,8 +35,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef surfZoneIOList_H #ifndef Foam_surfZoneIOList_H
#define surfZoneIOList_H #define Foam_surfZoneIOList_H
#include "surfZoneList.H" #include "surfZoneList.H"
#include "regIOobject.H" #include "regIOobject.H"
@ -56,6 +56,13 @@ class surfZoneIOList
public regIOobject, public regIOobject,
public surfZoneList public surfZoneList
{ {
// Private Member Functions
//- Return true if contents were read
//- (controlled by IOobject readOption flags).
bool readContents();
public: public:
//- Runtime type information //- Runtime type information

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\ /*--------------------------------*- C++ -*----------------------------------*\
| ========= | | | ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2306 | | \\ / O peration | Version: v2312 |
| \\ / A nd | Website: www.openfoam.com | | \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | | | \\/ M anipulation | |
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -30,17 +30,8 @@ actions
name c1; name c1;
type cellSet; type cellSet;
action new; action new;
source faceZoneToCell;//zoneToCel; source faceZoneToCell;
option master; option both;
zones (domain0_to_v_CPU);
}
{
name c1;
type cellSet;
action add;
source faceZoneToCell;//zoneToCel;
option slave;
zones (domain0_to_v_CPU); zones (domain0_to_v_CPU);
} }

View File

@ -1,7 +1,7 @@
/*--------------------------------*- C++ -*----------------------------------*\ /*--------------------------------*- C++ -*----------------------------------*\
| ========= | | | ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: v2306 | | \\ / O peration | Version: v2312 |
| \\ / A nd | Website: www.openfoam.com | | \\ / A nd | Website: www.openfoam.com |
| \\/ M anipulation | | | \\/ M anipulation | |
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
@ -589,7 +589,7 @@ actions
type cellSet; type cellSet;
action new; action new;
source faceZoneToCell; source faceZoneToCell;
option slave; option back;
zones zones
( (
faceZone1 faceZone1
@ -601,7 +601,7 @@ actions
type cellSet; type cellSet;
action new; action new;
source faceZoneToCell; source faceZoneToCell;
option master; option front;
zone faceZone1; zone faceZone1;
} }