ENH: relocate meshSubsetHelper into dynamicMesh for re-use

- reuse for foamToTecplot360 and foamToVTK.
- remove dependency on vtkMesh where possible.
This commit is contained in:
Mark Olesen
2016-11-09 23:33:24 +01:00
parent af02ff3600
commit e5d9fd13c2
32 changed files with 209 additions and 583 deletions

View File

@ -410,7 +410,6 @@ int main(int argc, char *argv[])
args.optionReadIfPresent("pointSet", pointSetName);
instantList timeDirs = timeSelector::select0(runTime, args);
#include "createNamedMesh.H"
@ -450,7 +449,7 @@ int main(int argc, char *argv[])
mkDir(fvPath);
// Mesh wrapper; does subsetting and decomposition
// Mesh wrapper: does subsetting and decomposition
vtkMesh vMesh(mesh, cellSetName);
Info<< "VTK mesh topology: "
@ -503,7 +502,7 @@ int main(int argc, char *argv[])
Info<< " FaceSet : " << patchFileName << endl;
writeFaceSet(binary, vMesh, set, patchFileName);
writeFaceSet(binary, vMesh.mesh(), set, patchFileName);
continue;
}
@ -526,7 +525,7 @@ int main(int argc, char *argv[])
Info<< " pointSet : " << patchFileName << endl;
writePointSet(binary, vMesh, set, patchFileName);
writePointSet(binary, vMesh.mesh(), set, patchFileName);
continue;
}
@ -849,7 +848,7 @@ int main(int argc, char *argv[])
writeSurfFields
(
binary,
vMesh,
vMesh.mesh(),
surfFileName,
svf
);
@ -892,7 +891,7 @@ int main(int argc, char *argv[])
patchWriter writer
(
vMesh,
vMesh.mesh(),
binary,
nearCellValue,
patchFileName,
@ -970,7 +969,7 @@ int main(int argc, char *argv[])
patchWriter writer
(
vMesh,
vMesh.mesh(),
binary,
nearCellValue,
patchFileName,
@ -1188,7 +1187,7 @@ int main(int argc, char *argv[])
lagrangianWriter writer
(
vMesh,
vMesh.mesh(),
binary,
lagrFileName,
cloudName,
@ -1218,7 +1217,7 @@ int main(int argc, char *argv[])
{
lagrangianWriter writer
(
vMesh,
vMesh.mesh(),
binary,
lagrFileName,
cloudName,

View File

@ -6,7 +6,6 @@ writeFuns.C
writeFaceSet.C
writePointSet.C
writeSurfFields.C
vtkMesh.C
vtkTopo.C
writeVTK/writeVTK.C

View File

@ -41,8 +41,6 @@ SourceFiles
#include "pointFields.H"
#include "vtkMesh.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam

View File

@ -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) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,23 +32,21 @@ License
Foam::lagrangianWriter::lagrangianWriter
(
const vtkMesh& vMesh,
const fvMesh& mesh,
const bool binary,
const fileName& fName,
const word& cloudName,
const bool dummyCloud
)
:
vMesh_(vMesh),
mesh_(mesh),
binary_(binary),
fName_(fName),
cloudName_(cloudName),
os_(fName.c_str())
{
const fvMesh& mesh = vMesh_.mesh();
// Write header
writeFuns::writeHeader(os_, binary_, mesh.time().caseName());
writeFuns::writeHeader(os_, binary_, mesh_.time().caseName());
os_ << "DATASET POLYDATA" << std::endl;
if (dummyCloud)

View File

@ -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) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -40,9 +40,6 @@ SourceFiles
#include "Cloud.H"
#include "volFields.H"
#include "pointFields.H"
#include "vtkMesh.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -57,7 +54,7 @@ class volPointInterpolation;
class lagrangianWriter
{
const vtkMesh& vMesh_;
const fvMesh& mesh_;
const bool binary_;
@ -77,7 +74,7 @@ public:
//- Construct from components
lagrangianWriter
(
const vtkMesh&,
const fvMesh&,
const bool binary,
const fileName&,
const word&,

View File

@ -39,9 +39,9 @@ void Foam::lagrangianWriter::writeIOField(const wordList& objects)
IOobject header
(
object,
vMesh_.mesh().time().timeName(),
mesh_.time().timeName(),
cloud::prefix/cloudName_,
vMesh_.mesh(),
mesh_,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false

View File

@ -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) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -30,21 +30,20 @@ License
Foam::patchWriter::patchWriter
(
const vtkMesh& vMesh,
const fvMesh& mesh,
const bool binary,
const bool nearCellValue,
const fileName& fName,
const labelList& patchIDs
)
:
vMesh_(vMesh),
mesh_(mesh),
binary_(binary),
nearCellValue_(nearCellValue),
fName_(fName),
patchIDs_(patchIDs),
os_(fName.c_str())
{
const fvMesh& mesh = vMesh_.mesh();
const polyBoundaryMesh& patches = mesh.boundaryMesh();
// Write header
@ -115,8 +114,6 @@ Foam::patchWriter::patchWriter
void Foam::patchWriter::writePatchIDs()
{
const fvMesh& mesh = vMesh_.mesh();
DynamicList<floatScalar> fField(nFaces_);
os_ << "patchID 1 " << nFaces_ << " float" << std::endl;
@ -125,7 +122,7 @@ void Foam::patchWriter::writePatchIDs()
{
label patchi = patchIDs_[i];
const polyPatch& pp = mesh.boundaryMesh()[patchi];
const polyPatch& pp = mesh_.boundaryMesh()[patchi];
if (!isA<emptyPolyPatch>(pp))
{

View File

@ -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) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -40,12 +40,9 @@ SourceFiles
#include "OFstream.H"
#include "volFields.H"
#include "pointFields.H"
#include "vtkMesh.H"
#include "indirectPrimitivePatch.H"
#include "PrimitivePatchInterpolation.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
@ -59,7 +56,8 @@ class volPointInterpolation;
class patchWriter
{
const vtkMesh& vMesh_;
//- Reference to the OpenFOAM mesh (or subset)
const fvMesh& mesh_;
const bool binary_;
@ -82,7 +80,7 @@ public:
//- Construct from components
patchWriter
(
const vtkMesh&,
const fvMesh&,
const bool binary,
const bool nearCellValue,
const fileName&,

View File

@ -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) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,37 +36,32 @@ namespace Foam
template<class GeoField>
void readFields
(
const vtkMesh& vMesh,
const meshSubsetHelper& helper,
const typename GeoField::Mesh& mesh,
const IOobjectList& objects,
const HashSet<word>& selectedFields,
PtrList<const GeoField>& fields
)
{
// Search list of objects for volScalarFields
// Search list of objects for fields of type GeomField
IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
// Construct the vol scalar fields
// Construct the fields
fields.setSize(fieldObjects.size());
label nFields = 0;
forAllIter(IOobjectList, fieldObjects, iter)
forAllConstIter(IOobjectList, fieldObjects, iter)
{
if (selectedFields.empty() || selectedFields.found(iter()->name()))
{
fields.set
(
nFields,
vMesh.interpolate
nFields++,
helper.interpolate
(
GeoField
(
*iter(),
mesh
)
GeoField(*iter(), mesh)
).ptr()
);
nFields++;
}
}

View File

@ -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) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -34,7 +34,7 @@ SourceFiles
#ifndef readFields_H
#define readFields_H
#include "fvMesh.H"
#include "meshSubsetHelper.H"
#include "PtrList.H"
#include "IOobjectList.H"
#include "HashSet.H"
@ -48,7 +48,7 @@ namespace Foam
template<class GeoField>
void readFields
(
const vtkMesh& vMesh,
const meshSubsetHelper&,
const typename GeoField::Mesh& mesh,
const IOobjectList& objects,
const HashSet<word>& selectedFields,

View File

@ -40,11 +40,8 @@ SourceFiles
#include "OFstream.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "vtkMesh.H"
#include "indirectPrimitivePatch.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam

View File

@ -29,7 +29,8 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
Foam::tmp<Field<Type>> Foam::surfaceMeshWriter::getFaceField
Foam::tmp<Foam::Field<Type>>
Foam::surfaceMeshWriter::getFaceField
(
const GeometricField<Type, fvsPatchField, surfaceMesh>& sfld
) const

View File

@ -1,82 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "vtkMesh.H"
#include "fvMeshSubset.H"
#include "Time.H"
#include "cellSet.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::vtkMesh::vtkMesh
(
fvMesh& baseMesh,
const word& setName
)
:
baseMesh_(baseMesh),
subsetter_(baseMesh),
setName_(setName)
{
if (setName.size())
{
// Read cellSet using whole mesh
cellSet currentSet(baseMesh_, setName_);
// Set current subset
subsetter_.setLargeCellSubset(currentSet);
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::polyMesh::readUpdateState Foam::vtkMesh::readUpdate()
{
polyMesh::readUpdateState meshState = baseMesh_.readUpdate();
if (meshState != polyMesh::UNCHANGED)
{
// Note: since fvMeshSubset has no movePoints() functionality,
// reconstruct the subset even if only movement.
topoPtr_.clear();
if (setName_.size())
{
Info<< "Subsetting mesh based on cellSet " << setName_ << endl;
// Read cellSet using whole mesh
cellSet currentSet(baseMesh_, setName_);
subsetter_.setLargeCellSubset(currentSet);
}
}
return meshState;
}
// ************************************************************************* //

View File

@ -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) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,46 +36,35 @@ SourceFiles
#ifndef vtkMesh_H
#define vtkMesh_H
#include "meshSubsetHelper.H"
#include "vtkTopo.H"
#include "fvMeshSubset.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class Time;
/*---------------------------------------------------------------------------*\
Class vtkMesh Declaration
\*---------------------------------------------------------------------------*/
class vtkMesh
:
public meshSubsetHelper
{
// Private data
//- Reference to mesh
fvMesh& baseMesh_;
//- Subsetting engine + sub-fvMesh
fvMeshSubset subsetter_;
//- Current cellSet (or empty)
const word setName_;
//- Current decomposition of topology
mutable autoPtr<vtkTopo> topoPtr_;
// Private Member Functions
//- Disallow default bitwise copy construct
vtkMesh(const vtkMesh&);
vtkMesh(const vtkMesh&) = delete;
//- Disallow default bitwise assignment
void operator=(const vtkMesh&);
void operator=(const vtkMesh&) = delete;
public:
@ -83,31 +72,17 @@ public:
// Constructors
//- Construct from components
vtkMesh(fvMesh& baseMesh, const word& setName = "");
vtkMesh(fvMesh& baseMesh, const word& setName = word::null)
:
meshSubsetHelper(baseMesh, meshSubsetHelper::SET, setName)
{}
// Member Functions
// Access
//- Whole mesh
const fvMesh& baseMesh() const
{
return baseMesh_;
}
const fvMeshSubset& subsetter() const
{
return subsetter_;
}
//- Check if running subMesh
bool useSubMesh() const
{
return setName_.size();
}
//- topology
//- Topology
const vtkTopo& topo() const
{
if (topoPtr_.empty())
@ -117,18 +92,6 @@ public:
return topoPtr_();
}
//- Access either mesh or submesh
const fvMesh& mesh() const
{
if (useSubMesh())
{
return subsetter_.subMesh();
}
else
{
return baseMesh_;
}
}
//- Number of field cells
label nFieldCells() const
@ -136,6 +99,7 @@ public:
return topo().cellTypes().size();
}
//- Number of field points
label nFieldPoints() const
{
@ -145,26 +109,20 @@ public:
// Edit
//- Read mesh
polyMesh::readUpdateState readUpdate();
//- Map volume field (does in fact do very little interpolation;
// just copied from fvMeshSubset)
template<class GeoField>
tmp<GeoField> interpolate(const GeoField& fld) const
//- Read mesh, forcing topo update if necessary
polyMesh::readUpdateState readUpdate()
{
if (useSubMesh())
polyMesh::readUpdateState meshState
= meshSubsetHelper::readUpdate();
if (meshState != polyMesh::UNCHANGED)
{
tmp<GeoField> subFld = subsetter_.interpolate(fld);
subFld.ref().rename(fld.name());
return subFld;
}
else
{
return fld;
topoPtr_.clear();
}
return meshState;
}
};

View File

@ -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) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,12 +32,12 @@ License
void Foam::writeFaceSet
(
const bool binary,
const vtkMesh& vMesh,
const fvMesh& mesh,
const faceSet& set,
const fileName& fileName
)
{
const faceList& faces = vMesh.mesh().faces();
const faceList& faces = mesh.faces();
std::ofstream ostr(fileName.c_str());
@ -69,7 +69,7 @@ void Foam::writeFaceSet
setFaces[setFacei] = faces[iter.key()];
setFacei++;
}
primitiveFacePatch fp(setFaces, vMesh.mesh().points());
primitiveFacePatch fp(setFaces, mesh.points());
// Write points and faces as polygons

View File

@ -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) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,7 +36,7 @@ SourceFiles
#ifndef writeFaceSet_H
#define writeFaceSet_H
#include "vtkMesh.H"
#include "fvMesh.H"
#include "faceSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -48,7 +48,7 @@ namespace Foam
void writeFaceSet
(
const bool binary,
const vtkMesh& vMesh,
const fvMesh&,
const faceSet& set,
const fileName& fileName
);

View File

@ -37,7 +37,7 @@ namespace Foam
void writePointSet
(
const bool binary,
const vtkMesh& vMesh,
const fvMesh& mesh,
const pointSet& set,
const fileName& fileName
)
@ -68,7 +68,7 @@ void writePointSet
writeFuns::insert
(
UIndirectList<point>(vMesh.mesh().points(), set.toc())(),
UIndirectList<point>(mesh.points(), set.toc())(),
ptField
);

View File

@ -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) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -36,7 +36,7 @@ SourceFiles
#ifndef writePointSet_H
#define writePointSet_H
#include "vtkMesh.H"
#include "fvMesh.H"
#include "pointSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -48,7 +48,7 @@ namespace Foam
void writePointSet
(
const bool binary,
const vtkMesh& vMesh,
const fvMesh& mesh,
const pointSet& set,
const fileName& fileName
);

View File

@ -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) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -35,13 +35,11 @@ License
void Foam::writeSurfFields
(
const bool binary,
const vtkMesh& vMesh,
const fvMesh& mesh,
const fileName& fileName,
const UPtrList<const surfaceVectorField>& surfVectorFields
)
{
const fvMesh& mesh = vMesh.mesh();
std::ofstream str(fileName.c_str());
writeFuns::writeHeader

View File

@ -35,7 +35,7 @@ SourceFiles
#ifndef writeSurfFields_H
#define writeSurfFields_H
#include "vtkMesh.H"
#include "fvMesh.H"
#include "surfaceMesh.H"
#include "surfaceFieldsFwd.H"
@ -48,7 +48,7 @@ namespace Foam
void writeSurfFields
(
const bool binary,
const vtkMesh& vMesh,
const fvMesh&,
const fileName& fileName,
const UPtrList<const surfaceVectorField>& surfVectorFields
);