From 1cfb59fe1a4bc72bd036cfee9a2d4facde9a106c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Wed, 4 Oct 2017 08:19:39 +0200 Subject: [PATCH] ENH: add read-option for polyTopoChanger (issue #608) - avoid meshModifier contents from being read immediately upon construction, since this recreates an existing modifier instead of allowing us to specify our own. --- .../mesh/manipulation/stitchMesh/stitchMesh.C | 11 ++-- .../polyTopoChanger/polyTopoChanger.C | 53 +++++++++++-------- .../polyTopoChanger/polyTopoChanger.H | 22 ++++---- 3 files changed, 49 insertions(+), 37 deletions(-) diff --git a/applications/utilities/mesh/manipulation/stitchMesh/stitchMesh.C b/applications/utilities/mesh/manipulation/stitchMesh/stitchMesh.C index 9723c1cdb7..ca0289a10e 100644 --- a/applications/utilities/mesh/manipulation/stitchMesh/stitchMesh.C +++ b/applications/utilities/mesh/manipulation/stitchMesh/stitchMesh.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -27,7 +27,6 @@ Application Group grpMeshManipulationUtilities - Description 'Stitches' a mesh. @@ -332,7 +331,8 @@ int main(int argc, char *argv[]) isf[i] = masterPatch.start() + i; } - polyTopoChanger stitcher(mesh); + polyTopoChanger stitcher(mesh, IOobject::NO_READ); + stitcher.clear(); stitcher.setSize(1); mesh.pointZones().clearAddressing(); @@ -414,7 +414,6 @@ int main(int argc, char *argv[]) ); } - // Search for list of objects for this time IOobjectList objects(mesh, runTime.timeName()); @@ -435,7 +434,7 @@ int main(int argc, char *argv[]) PtrList volTensorFields; ReadFields(mesh, objects, volTensorFields); - //- Uncomment if you want to interpolate surface fields (usually bad idea) + //- Uncomment if you want to interpolate surface fields (usually a bad idea) //Info<< "Reading all current surfaceFields" << endl; //PtrList surfaceScalarFields; //ReadFields(mesh, objects, surfaceScalarFields); @@ -469,7 +468,7 @@ int main(int argc, char *argv[]) // Bypass runTime write (since only writes at writeTime) if ( - !runTime.objectRegistry::writeObject + !runTime.objectRegistry::writeObject ( runTime.writeFormat(), IOstream::currentVersion, diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChanger/polyTopoChanger.C b/src/dynamicMesh/polyTopoChange/polyTopoChanger/polyTopoChanger.C index 8023a5d98b..ee40ecc48a 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChanger/polyTopoChanger.C +++ b/src/dynamicMesh/polyTopoChange/polyTopoChanger/polyTopoChanger.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -36,7 +36,7 @@ namespace Foam } -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // +// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // void Foam::polyTopoChanger::readModifiers() { @@ -73,7 +73,6 @@ void Foam::polyTopoChanger::readModifiers() ); } - // Check state of IOstream is.check(FUNCTION_NAME); close(); @@ -81,6 +80,8 @@ void Foam::polyTopoChanger::readModifiers() } +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + Foam::polyTopoChanger::polyTopoChanger ( const IOobject& io, @@ -95,10 +96,14 @@ Foam::polyTopoChanger::polyTopoChanger } -Foam::polyTopoChanger::polyTopoChanger(polyMesh& mesh) +Foam::polyTopoChanger::polyTopoChanger +( + polyMesh& mesh, + const IOobject::readOption rOpt + +) : - PtrList(), - regIOobject + polyTopoChanger ( IOobject ( @@ -107,32 +112,36 @@ Foam::polyTopoChanger::polyTopoChanger(polyMesh& mesh) ( mesh.meshDir(), "meshModifiers", - IOobject::READ_IF_PRESENT + rOpt ), mesh.meshSubDir, mesh, - IOobject::READ_IF_PRESENT, + rOpt, IOobject::NO_WRITE - ) - ), - mesh_(mesh) -{ - readModifiers(); -} + ), + mesh + ) +{} + + +Foam::polyTopoChanger::polyTopoChanger(polyMesh& mesh) +: + polyTopoChanger(mesh, IOobject::readOption::READ_IF_PRESENT) +{} Foam::wordList Foam::polyTopoChanger::types() const { const PtrList& modifiers = *this; - wordList t(modifiers.size()); + wordList lst(modifiers.size()); - forAll(modifiers, modifierI) + forAll(modifiers, i) { - t[modifierI] = modifiers[modifierI].type(); + lst[i] = modifiers[i].type(); } - return t; + return lst; } @@ -140,14 +149,14 @@ Foam::wordList Foam::polyTopoChanger::names() const { const PtrList& modifiers = *this; - wordList t(modifiers.size()); + wordList lst(modifiers.size()); - forAll(modifiers, modifierI) + forAll(modifiers, i) { - t[modifierI] = modifiers[modifierI].name(); + lst[i] = modifiers[i].name(); } - return t; + return lst; } diff --git a/src/dynamicMesh/polyTopoChange/polyTopoChanger/polyTopoChanger.H b/src/dynamicMesh/polyTopoChange/polyTopoChanger/polyTopoChanger.H index b9f4cbff2e..94ff7bea97 100644 --- a/src/dynamicMesh/polyTopoChange/polyTopoChanger/polyTopoChanger.H +++ b/src/dynamicMesh/polyTopoChange/polyTopoChanger/polyTopoChanger.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -69,13 +69,13 @@ class polyTopoChanger { // Private Member Functions + void readModifiers(); + //- Disallow default bitwise copy construct - polyTopoChanger(const polyTopoChanger&); + polyTopoChanger(const polyTopoChanger&) = delete; //- Disallow default bitwise assignment - void operator=(const polyTopoChanger&); - - void readModifiers(); + void operator=(const polyTopoChanger&) = delete; protected: @@ -93,11 +93,15 @@ public: // Constructors - //- Read constructor given IOobject and a polyMesh - polyTopoChanger(const IOobject&, polyMesh&); + //- Read construct given IOobject and a polyMesh + polyTopoChanger(const IOobject& io, polyMesh& mesh); - //- Read constructor for given polyMesh - explicit polyTopoChanger(polyMesh&); + //- Read construct for given polyMesh and read-option + polyTopoChanger(polyMesh& mesh, const IOobject::readOption rOpt); + + //- Read construct for given polyMesh. + // Uses read-option READ_IF_PRESENT + explicit polyTopoChanger(polyMesh& mesh); //- Destructor