ENH: soft update of autoPtr<fileOperation> to refPtr<fileOperation>

Co-authored-by: mattijs <mattijs>
This commit is contained in:
Mark Olesen
2023-05-12 18:43:32 +02:00
parent 8a060e87cb
commit 8d2bf3fc2e
5 changed files with 30 additions and 54 deletions

View File

@ -551,7 +551,7 @@ void correctCoupledBoundaryConditions(fvMesh& mesh)
// Inplace redistribute mesh and any fields // Inplace redistribute mesh and any fields
autoPtr<mapDistributePolyMesh> redistributeAndWrite autoPtr<mapDistributePolyMesh> redistributeAndWrite
( (
autoPtr<fileOperation>&& writeHandler, refPtr<fileOperation>& writeHandler,
const Time& baseRunTime, const Time& baseRunTime,
const fileName& proc0CaseName, const fileName& proc0CaseName,
@ -834,18 +834,12 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
} }
else else
{ {
autoPtr<fileOperation> defaultHandler; auto oldHandler = fileOperation::fileHandler(writeHandler);
if (writeHandler)
{
defaultHandler = fileHandler(std::move(writeHandler));
}
mesh.write(); mesh.write();
if (defaultHandler) writeHandler = fileOperation::fileHandler(oldHandler);
{
writeHandler = fileHandler(std::move(defaultHandler));
}
topoSet::removeFiles(mesh); topoSet::removeFiles(mesh);
} }
Info<< "Written redistributed mesh to " Info<< "Written redistributed mesh to "
@ -861,7 +855,7 @@ autoPtr<mapDistributePolyMesh> redistributeAndWrite
mesh, mesh,
distMap(), distMap(),
decompose, decompose,
std::move(writeHandler) writeHandler
); );
} }
else else
@ -1064,7 +1058,7 @@ int main(int argc, char *argv[])
// than it writes to // than it writes to
// - reconstruct - reads parallel, write on master only and to parent // - reconstruct - reads parallel, write on master only and to parent
// directory // directory
autoPtr<fileOperation> writeHandler; refPtr<fileOperation> writeHandler;
if if
( (
fileHandler().type() fileHandler().type()
@ -1072,7 +1066,8 @@ int main(int argc, char *argv[])
) )
{ {
// Install 'uncollated' as fileHandler. Save old one in writeHandler. // Install 'uncollated' as fileHandler. Save old one in writeHandler.
writeHandler = fileHandler(fileOperation::NewUncollated()); writeHandler =
fileOperation::fileHandler(fileOperation::NewUncollated());
} }
// Switch off parallel synchronisation of cached time directories // Switch off parallel synchronisation of cached time directories
@ -1582,7 +1577,7 @@ int main(int argc, char *argv[])
redistributeAndWrite redistributeAndWrite
( (
std::move(writeHandler), writeHandler,
baseRunTime, baseRunTime,
proc0CaseName, proc0CaseName,
@ -1713,7 +1708,7 @@ int main(int argc, char *argv[])
areaBaseMeshPtr(), // Reconstruct location areaBaseMeshPtr(), // Reconstruct location
faDistMap, faDistMap,
false, // decompose=false false, // decompose=false
std::move(writeHandler), writeHandler,
areaMeshPtr.get() // procMesh areaMeshPtr.get() // procMesh
); );
} }
@ -2502,7 +2497,7 @@ int main(int argc, char *argv[])
// - but not lagrangian fields; these are done later // - but not lagrangian fields; these are done later
autoPtr<mapDistributePolyMesh> distMap = redistributeAndWrite autoPtr<mapDistributePolyMesh> distMap = redistributeAndWrite
( (
std::move(writeHandler), writeHandler,
baseRunTime, baseRunTime,
proc0CaseName, proc0CaseName,
@ -2575,11 +2570,7 @@ int main(int argc, char *argv[])
} }
else else
{ {
autoPtr<fileOperation> defaultHandler; auto oldHandler = fileOperation::fileHandler(writeHandler);
if (writeHandler)
{
defaultHandler = fileHandler(std::move(writeHandler));
}
IOmapDistributePolyMeshRef IOmapDistributePolyMeshRef
( (
@ -2598,10 +2589,7 @@ int main(int argc, char *argv[])
areaProcMeshPtr->write(); areaProcMeshPtr->write();
if (defaultHandler) writeHandler = fileOperation::fileHandler(oldHandler);
{
writeHandler = fileHandler(std::move(defaultHandler));
}
if (decompose) if (decompose)
{ {
@ -2610,7 +2598,7 @@ int main(int argc, char *argv[])
areaProcMeshPtr(), areaProcMeshPtr(),
faDistMap, faDistMap,
decompose, decompose,
std::move(writeHandler) writeHandler
); );
} }
} }

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.
@ -50,6 +50,7 @@ namespace Foam
{ {
// Forward Declarations // Forward Declarations
class fileOperation;
class mapDistributePolyMesh; class mapDistributePolyMesh;
class polyMesh; class polyMesh;
class IOobject; class IOobject;
@ -121,7 +122,7 @@ public:
const faMesh& mesh, const faMesh& mesh,
const mapDistributePolyMesh& faDistMap, const mapDistributePolyMesh& faDistMap,
const bool decompose, const bool decompose,
autoPtr<fileOperation>&& writeHandler, refPtr<fileOperation>& writeHandler,
const faMesh* procMesh = nullptr const faMesh* procMesh = nullptr
); );

View File

@ -309,7 +309,7 @@ void Foam::faMeshTools::writeProcAddressing
const faMesh& mesh, const faMesh& mesh,
const mapDistributePolyMesh& map, const mapDistributePolyMesh& map,
const bool decompose, const bool decompose,
autoPtr<fileOperation>&& writeHandler, refPtr<fileOperation>& writeHandler,
const faMesh* procMesh const faMesh* procMesh
) )
{ {
@ -398,11 +398,7 @@ void Foam::faMeshTools::writeProcAddressing
); );
} }
autoPtr<fileOperation> defaultHandler; auto oldHandler = fileOperation::fileHandler(writeHandler);
if (writeHandler)
{
defaultHandler = fileHandler(std::move(writeHandler));
}
// If we want procAddressing, need to manually write it ourselves // If we want procAddressing, need to manually write it ourselves
@ -434,11 +430,11 @@ void Foam::faMeshTools::writeProcAddressing
// Reconstruct: "procAddressing" only meaningful for rank 0 // Reconstruct: "procAddressing" only meaningful for rank 0
// and written into base (serial) location (if at all). // and written into base (serial) location (if at all).
if (Pstream::master()) if (UPstream::master())
{ {
const bool oldParRun = Pstream::parRun(false); const bool oldParRun = UPstream::parRun(false);
procAddrMap.write(); procAddrMap.write();
Pstream::parRun(oldParRun); UPstream::parRun(oldParRun);
} }
} }
@ -448,10 +444,7 @@ void Foam::faMeshTools::writeProcAddressing
const bool pointOk = pointMap.write(); const bool pointOk = pointMap.write();
const bool patchOk = patchMap.write(); const bool patchOk = patchMap.write();
if (defaultHandler) writeHandler = fileOperation::fileHandler(oldHandler);
{
writeHandler = fileHandler(std::move(defaultHandler));
}
if (!edgeOk || !faceOk || !pointOk || !patchOk) if (!edgeOk || !faceOk || !pointOk || !patchOk)
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2016 OpenFOAM Foundation Copyright (C) 2012-2016 OpenFOAM Foundation
Copyright (C) 2015-2022 OpenCFD Ltd. Copyright (C) 2015-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -48,6 +48,7 @@ namespace Foam
{ {
// Forward Declarations // Forward Declarations
class fileOperation;
class mapDistributePolyMesh; class mapDistributePolyMesh;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
@ -192,7 +193,7 @@ public:
const fvMesh& procMesh, const fvMesh& procMesh,
const mapDistributePolyMesh& map, const mapDistributePolyMesh& map,
const bool decompose, const bool decompose,
autoPtr<fileOperation>&& writeHandler refPtr<fileOperation>& writeHandler
); );
}; };

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2015-2022 OpenCFD Ltd. Copyright (C) 2015-2023 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -303,7 +303,7 @@ void Foam::fvMeshTools::writeProcAddressing
const fvMesh& mesh, const fvMesh& mesh,
const mapDistributePolyMesh& map, const mapDistributePolyMesh& map,
const bool decompose, const bool decompose,
autoPtr<fileOperation>&& writeHandler refPtr<fileOperation>& writeHandler
) )
{ {
Info<< "Writing (" Info<< "Writing ("
@ -421,21 +421,14 @@ void Foam::fvMeshTools::writeProcAddressing
); );
} }
autoPtr<fileOperation> defaultHandler; auto oldHandler = fileOperation::fileHandler(writeHandler);
if (writeHandler)
{
defaultHandler = fileHandler(std::move(writeHandler));
}
const bool cellOk = cellMap.write(); const bool cellOk = cellMap.write();
const bool faceOk = faceMap.write(); const bool faceOk = faceMap.write();
const bool pointOk = pointMap.write(); const bool pointOk = pointMap.write();
const bool patchOk = patchMap.write(); const bool patchOk = patchMap.write();
if (defaultHandler) writeHandler = fileOperation::fileHandler(oldHandler);
{
writeHandler = fileHandler(std::move(defaultHandler));
}
if (!cellOk || !faceOk || !pointOk || !patchOk) if (!cellOk || !faceOk || !pointOk || !patchOk)
{ {