ENH: add writeContents() static methods for IOList etc.

- encapsulates IOListRef etc into a simpler syntax

ENH: use UList instead of refPtr for IOListRef (avoids List cast etc)
This commit is contained in:
Mark Olesen 2025-04-09 14:23:49 +02:00
parent 6c20df2808
commit a7e8a43f4a
18 changed files with 110 additions and 82 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2017 OpenFOAM Foundation
Copyright (C) 2019-2022 OpenCFD Ltd.
Copyright (C) 2019-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -269,7 +269,7 @@ int main(int argc, char *argv[])
ioOutput.rename(args.executable() + "-labels");
Info<< "write " << ioOutput.objectRelPath() << endl;
{
IOListRef<label>(ioOutput, ints).write();
IOList<label>::writeContents(ioOutput, ints);
}
ioOutput.rename(args.executable() + "-points");

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2023 OpenCFD Ltd.
Copyright (C) 2017-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -700,19 +700,11 @@ Foam::label Foam::checkTopology
<< mesh.time().timeName()/"cellToRegion"
<< endl;
IOListRef<label>
IOList<label>::writeContents
(
IOobject
(
"cellToRegion",
mesh.time().timeName(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
),
IOobject("cellToRegion", mesh.time().timeName(), mesh),
rs
).write();
);
// Points in multiple regions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2024 OpenCFD Ltd.
Copyright (C) 2016-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -1913,13 +1913,13 @@ int main(int argc, char *argv[])
);
meshMapIO.resetHeader("cellMap");
IOListRef<label>(meshMapIO, map().cellMap()).write();
IOList<label>::writeContents(meshMapIO, map().cellMap());
meshMapIO.resetHeader("faceMap");
IOListRef<label>(meshMapIO, map().faceMap()).write();
IOList<label>::writeContents(meshMapIO, map().faceMap());
meshMapIO.resetHeader("pointMap");
IOListRef<label>(meshMapIO, map().pointMap()).write();
IOList<label>::writeContents(meshMapIO, map().pointMap());
}
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2024 OpenCFD Ltd.
Copyright (C) 2019-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -846,12 +846,9 @@ bool Foam::domainDecomposition::writeDecomposition(const bool decomposeSets)
"boundaryProcAddressing",
procMesh.facesInstance(),
polyMesh::meshSubDir/pointMesh::meshSubDir,
procPointMesh.thisDb(),
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
procPointMesh.thisDb()
);
IOListRef<label>(ioAddr, boundaryProcAddressing).write();
IOList<label>::writeContents(ioAddr, boundaryProcAddressing);
}
}
@ -1013,15 +1010,15 @@ bool Foam::domainDecomposition::writeDecomposition(const bool decomposeSets)
// pointProcAddressing
ioAddr.rename("pointProcAddressing");
IOListRef<label>(ioAddr, procPointAddressing_[proci]).write();
IOList<label>::writeContents(ioAddr, procPointAddressing_[proci]);
// faceProcAddressing
ioAddr.rename("faceProcAddressing");
IOListRef<label>(ioAddr, procFaceAddressing_[proci]).write();
IOList<label>::writeContents(ioAddr, procFaceAddressing_[proci]);
// cellProcAddressing
ioAddr.rename("cellProcAddressing");
IOListRef<label>(ioAddr, procCellAddressing_[proci]).write();
IOList<label>::writeContents(ioAddr, procCellAddressing_[proci]);
// Write patch map for backwards compatibility.
// (= identity map for original patches, -1 for processor patches)
@ -1031,7 +1028,7 @@ bool Foam::domainDecomposition::writeDecomposition(const bool decomposeSets)
// boundaryProcAddressing
ioAddr.rename("boundaryProcAddressing");
IOListRef<label>(ioAddr, procBoundaryAddr).write();
IOList<label>::writeContents(ioAddr, procBoundaryAddr);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2024 OpenCFD Ltd.
Copyright (C) 2016-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -502,7 +502,7 @@ void writeMaps
Info<< " pointProcAddressing" << endl;
ioAddr.rename("pointProcAddressing");
IOListRef<label>(ioAddr, pointProcAddressing).write();
IOList<label>::writeContents(ioAddr, pointProcAddressing);
// From processor face to reconstructed mesh face
Info<< " faceProcAddressing" << endl;
@ -551,13 +551,13 @@ void writeMaps
// From processor cell to reconstructed mesh cell
Info<< " cellProcAddressing" << endl;
ioAddr.rename("cellProcAddressing");
IOListRef<label>(ioAddr, cellProcAddressing).write();
IOList<label>::writeContents(ioAddr, cellProcAddressing);
// From processor patch to reconstructed mesh patch
Info<< " boundaryProcAddressing" << endl;
ioAddr.rename("boundaryProcAddressing");
IOListRef<label>(ioAddr, boundProcAddressing).write();
IOList<label>::writeContents(ioAddr, boundProcAddressing);
Info<< endl;
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2024 OpenCFD Ltd.
Copyright (C) 2015-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -461,19 +461,12 @@ void writeDecomposition
{
// Write the decomposition as labelList for use with 'manual'
// decomposition method.
IOListRef<label>
IOList<label>::writeContents
(
IOobject
(
"cellDecomposition",
mesh.facesInstance(), // mesh read from facesInstance
mesh,
IOobjectOption::NO_READ,
IOobjectOption::NO_WRITE,
IOobjectOption::NO_REGISTER
),
// NB: mesh read from facesInstance
IOobject("cellDecomposition", mesh.facesInstance(), mesh),
decomp
).write();
);
InfoOrPout
<< "Writing wanted cell distribution to volScalarField " << name
@ -991,7 +984,8 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
polyMesh::meshSubDir,
mesh.thisDb(),
IOobjectOption::NO_READ,
IOobjectOption::AUTO_WRITE
IOobjectOption::AUTO_WRITE,
IOobjectOption::REGISTER
),
distMap()
);
@ -3029,20 +3023,17 @@ int main(int argc, char *argv[])
{
auto oldHandler = fileOperation::fileHandler(writeHandler);
IOmapDistributePolyMeshRef
IOmapDistributePolyMesh::writeContents
(
IOobject
(
"procAddressing",
areaProcMeshPtr->facesInstance(),
faMesh::meshSubDir,
areaProcMeshPtr->thisDb(),
IOobjectOption::NO_READ,
IOobjectOption::NO_WRITE,
IOobjectOption::NO_REGISTER
areaProcMeshPtr->thisDb()
),
faDistMap
).write();
);
areaProcMeshPtr->write();

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2024 OpenCFD Ltd.
Copyright (C) 2016-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -118,7 +118,7 @@ template<class T>
Foam::IOListRef<T>::IOListRef
(
const IOobject& io,
const List<T>& content
const UList<T>& content
)
:
regIOobject(io),
@ -143,6 +143,23 @@ Foam::List<T> Foam::IOList<T>::readContents(const IOobject& io)
}
template<class T>
void Foam::IOList<T>::writeContents
(
const IOobject& io,
const UList<T>& content
)
{
IOListRef<T> writer
(
IOobject(io, IOobjectOption::NO_REGISTER),
content
);
writer.write();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
@ -156,7 +173,7 @@ bool Foam::IOList<T>::writeData(Ostream& os) const
template<class T>
bool Foam::IOListRef<T>::writeData(Ostream& os) const
{
os << contentRef_.cref();
os << contentRef_;
return os.good();
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2024 OpenCFD Ltd.
Copyright (C) 2018-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -96,6 +96,10 @@ public:
//- Read and return contents. The IOobject is never registered
static List<T> readContents(const IOobject& io);
//- Write contents. The IOobject is never registered.
// Uses IOListRef internally.
static void writeContents(const IOobject& io, const UList<T>& content);
//- Destructor
virtual ~IOList() = default;
@ -121,7 +125,7 @@ public:
Class IOListRef Declaration
\*---------------------------------------------------------------------------*/
//- A IOList wrapper for writing external data.
//- A IOList wrapper for writing external List data
template<class T>
class IOListRef
:
@ -130,7 +134,7 @@ class IOListRef
// Private Data
//- Reference to the external content
refPtr<List<T>> contentRef_;
UList<T> contentRef_;
public:
@ -161,7 +165,7 @@ public:
// Constructors
//- Construct from IOobject and const data reference
IOListRef(const IOobject& io, const List<T>& content);
IOListRef(const IOobject& io, const UList<T>& content);
//- Destructor
@ -171,10 +175,9 @@ public:
// Member Functions
//- Allow cast to const content
// Fatal if content is not set
operator const List<T>&() const
operator const UList<T>&() const
{
return contentRef_.cref();
return contentRef_;
}
//- The writeData method for regIOobject write operation

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2022-2024 OpenCFD Ltd.
Copyright (C) 2022-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -124,6 +124,23 @@ Foam::IOmapDistributePolyMeshRef::IOmapDistributePolyMeshRef
/// contentRef_.ref(map); // writable reference
/// }
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
void Foam::IOmapDistributePolyMesh::writeContents
(
const IOobject& io,
const mapDistributePolyMesh& map
)
{
IOmapDistributePolyMeshRef writer
(
IOobject(io, IOobjectOption::NO_REGISTER),
map
);
writer.write();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2015 OpenFOAM Foundation
Copyright (C) 2022-2024 OpenCFD Ltd.
Copyright (C) 2022-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -88,6 +88,17 @@ public:
);
// Factory Methods
//- Write contents. The IOobject is never registered.
// Uses IOmapDistributePolyMeshRef internally.
static void writeContents
(
const IOobject& io,
const mapDistributePolyMesh& map
);
//- Destructor
virtual ~IOmapDistributePolyMesh() = default;

View File

@ -393,7 +393,7 @@ private:
(
const objectRegistry& registry,
const word& propertyName,
const labelList& list,
const labelUList& list,
IOstreamOption streamOpt
) const;

View File

@ -145,7 +145,7 @@ void Foam::ccm::reader::writeMeshLabelList
(
const objectRegistry& registry,
const word& propertyName,
const labelList& list,
const labelUList& list,
IOstreamOption streamOpt
) const
{

View File

@ -192,7 +192,7 @@ private:
(
const objectRegistry& registry,
const word& propertyName,
const labelList& list,
const labelUList& list,
IOstreamOption streamOpt
) const;

View File

@ -108,7 +108,7 @@ void Foam::meshReader::writeMeshLabelList
(
const objectRegistry& registry,
const word& propertyName,
const labelList& list,
const labelUList& list,
IOstreamOption streamOpt
) const
{

View File

@ -101,8 +101,8 @@ Foam::hexRef8Data::hexRef8Data
(
const IOobject& io,
const hexRef8Data& data,
const labelList& cellMap,
const labelList& pointMap
const labelUList& cellMap,
const labelUList& pointMap
)
{
if (data.cellLevelPtr_)

View File

@ -93,8 +93,8 @@ public:
(
const IOobject& io,
const hexRef8Data&,
const labelList& cellMap,
const labelList& pointMap
const labelUList& cellMap,
const labelUList& pointMap
);
//- Construct from multiple hexRef8Data

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2018-2024 OpenCFD Ltd.
Copyright (C) 2018-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -1318,19 +1318,19 @@ bool Foam::faMeshDecomposition::writeDecomposition()
// pointProcAddressing
ioAddr.rename("pointProcAddressing");
IOListRef<label>(ioAddr, procPatchPointAddressing_[procI]).write();
IOList<label>::writeContents(ioAddr, procPatchPointAddressing_[procI]);
// edgeProcAddressing
ioAddr.rename("edgeProcAddressing");
IOListRef<label>(ioAddr, procEdgeAddressing_[procI]).write();
IOList<label>::writeContents(ioAddr, procEdgeAddressing_[procI]);
// faceProcAddressing
ioAddr.rename("faceProcAddressing");
IOListRef<label>(ioAddr, procFaceAddressing_[procI]).write();
IOList<label>::writeContents(ioAddr, procFaceAddressing_[procI]);
// boundaryProcAddressing
ioAddr.rename("boundaryProcAddressing");
IOListRef<label>(ioAddr, procBoundaryAddressing_[procI]).write();
IOList<label>::writeContents(ioAddr, procBoundaryAddressing_[procI]);
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021-2024 OpenCFD Ltd.
Copyright (C) 2021-2025 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -693,19 +693,19 @@ void Foam::faMeshReconstructor::writeAddressing
// boundaryProcAddressing
ioAddr.rename("boundaryProcAddressing");
IOListRef<label>(ioAddr, faBoundaryProcAddr).write();
IOList<label>::writeContents(ioAddr, faBoundaryProcAddr);
// faceProcAddressing
ioAddr.rename("faceProcAddressing");
IOListRef<label>(ioAddr, faFaceProcAddr).write();
IOList<label>::writeContents(ioAddr, faFaceProcAddr);
// pointProcAddressing
ioAddr.rename("pointProcAddressing");
IOListRef<label>(ioAddr, faPointProcAddr).write();
IOList<label>::writeContents(ioAddr, faPointProcAddr);
// edgeProcAddressing
ioAddr.rename("edgeProcAddressing");
IOListRef<label>(ioAddr, faEdgeProcAddr).write();
IOList<label>::writeContents(ioAddr, faEdgeProcAddr);
}
@ -760,7 +760,7 @@ void Foam::faMeshReconstructor::writeMesh
IOobject io(fullMesh.boundary());
io.rename("faceLabels");
IOListRef<label>(io, singlePatchFaceLabels).write();
IOList<label>::writeContents(io, singlePatchFaceLabels);
fullMesh.boundary().write();