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.
This commit is contained in:
Mark Olesen
2017-10-04 08:19:39 +02:00
parent b9d97d96c1
commit 1cfb59fe1a
3 changed files with 49 additions and 37 deletions

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,7 +27,6 @@ Application
Group Group
grpMeshManipulationUtilities grpMeshManipulationUtilities
Description Description
'Stitches' a mesh. 'Stitches' a mesh.
@ -332,7 +331,8 @@ int main(int argc, char *argv[])
isf[i] = masterPatch.start() + i; isf[i] = masterPatch.start() + i;
} }
polyTopoChanger stitcher(mesh); polyTopoChanger stitcher(mesh, IOobject::NO_READ);
stitcher.clear();
stitcher.setSize(1); stitcher.setSize(1);
mesh.pointZones().clearAddressing(); mesh.pointZones().clearAddressing();
@ -414,7 +414,6 @@ int main(int argc, char *argv[])
); );
} }
// Search for list of objects for this time // Search for list of objects for this time
IOobjectList objects(mesh, runTime.timeName()); IOobjectList objects(mesh, runTime.timeName());
@ -435,7 +434,7 @@ int main(int argc, char *argv[])
PtrList<volTensorField> volTensorFields; PtrList<volTensorField> volTensorFields;
ReadFields(mesh, objects, 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; //Info<< "Reading all current surfaceFields" << endl;
//PtrList<surfaceScalarField> surfaceScalarFields; //PtrList<surfaceScalarField> surfaceScalarFields;
//ReadFields(mesh, objects, surfaceScalarFields); //ReadFields(mesh, objects, surfaceScalarFields);
@ -469,7 +468,7 @@ int main(int argc, char *argv[])
// Bypass runTime write (since only writes at writeTime) // Bypass runTime write (since only writes at writeTime)
if if
( (
!runTime.objectRegistry::writeObject !runTime.objectRegistry::writeObject
( (
runTime.writeFormat(), runTime.writeFormat(),
IOstream::currentVersion, IOstream::currentVersion,

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -36,7 +36,7 @@ namespace Foam
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::polyTopoChanger::readModifiers() void Foam::polyTopoChanger::readModifiers()
{ {
@ -73,7 +73,6 @@ void Foam::polyTopoChanger::readModifiers()
); );
} }
// Check state of IOstream
is.check(FUNCTION_NAME); is.check(FUNCTION_NAME);
close(); close();
@ -81,6 +80,8 @@ void Foam::polyTopoChanger::readModifiers()
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::polyTopoChanger::polyTopoChanger Foam::polyTopoChanger::polyTopoChanger
( (
const IOobject& io, 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<polyMeshModifier>(), polyTopoChanger
regIOobject
( (
IOobject IOobject
( (
@ -107,32 +112,36 @@ Foam::polyTopoChanger::polyTopoChanger(polyMesh& mesh)
( (
mesh.meshDir(), mesh.meshDir(),
"meshModifiers", "meshModifiers",
IOobject::READ_IF_PRESENT rOpt
), ),
mesh.meshSubDir, mesh.meshSubDir,
mesh, mesh,
IOobject::READ_IF_PRESENT, rOpt,
IOobject::NO_WRITE IOobject::NO_WRITE
) ),
), mesh
mesh_(mesh) )
{ {}
readModifiers();
}
Foam::polyTopoChanger::polyTopoChanger(polyMesh& mesh)
:
polyTopoChanger(mesh, IOobject::readOption::READ_IF_PRESENT)
{}
Foam::wordList Foam::polyTopoChanger::types() const Foam::wordList Foam::polyTopoChanger::types() const
{ {
const PtrList<polyMeshModifier>& modifiers = *this; const PtrList<polyMeshModifier>& 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<polyMeshModifier>& modifiers = *this; const PtrList<polyMeshModifier>& 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;
} }

View File

@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -69,13 +69,13 @@ class polyTopoChanger
{ {
// Private Member Functions // Private Member Functions
void readModifiers();
//- Disallow default bitwise copy construct //- Disallow default bitwise copy construct
polyTopoChanger(const polyTopoChanger&); polyTopoChanger(const polyTopoChanger&) = delete;
//- Disallow default bitwise assignment //- Disallow default bitwise assignment
void operator=(const polyTopoChanger&); void operator=(const polyTopoChanger&) = delete;
void readModifiers();
protected: protected:
@ -93,11 +93,15 @@ public:
// Constructors // Constructors
//- Read constructor given IOobject and a polyMesh //- Read construct given IOobject and a polyMesh
polyTopoChanger(const IOobject&, polyMesh&); polyTopoChanger(const IOobject& io, polyMesh& mesh);
//- Read constructor for given polyMesh //- Read construct for given polyMesh and read-option
explicit polyTopoChanger(polyMesh&); polyTopoChanger(polyMesh& mesh, const IOobject::readOption rOpt);
//- Read construct for given polyMesh.
// Uses read-option READ_IF_PRESENT
explicit polyTopoChanger(polyMesh& mesh);
//- Destructor //- Destructor