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

@ -1,6 +1,4 @@
ensightOutputCloud.C
meshSubsetHelper.C
foamToEnsight.C
EXE = $(FOAM_APPBIN)/foamToEnsight

View File

@ -291,7 +291,7 @@ int main(int argc, char *argv[])
<< mesh.boundaryMesh()[0].name() << ")"
<< endl;
}
meshSubsetHelper myMesh(mesh, cellZoneName);
meshSubsetHelper myMesh(mesh, meshSubsetHelper::ZONE, cellZoneName);
//
// Open new ensight case file, initialize header etc.

View File

@ -1,91 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ 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 "meshSubsetHelper.H"
#include "cellSet.H"
#include "cellZone.H"
#include "Time.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::meshSubsetHelper::meshSubsetHelper
(
fvMesh& baseMesh,
const word& name,
const bool isCellSet
)
:
baseMesh_(baseMesh),
subsetter_(baseMesh),
name_(name),
type_(name_.empty() ? 0 : isCellSet ? 1 : 2)
{
correct();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::meshSubsetHelper::correct(bool verbose)
{
if (type_ == 1)
{
if (verbose)
{
Info<< "Subsetting mesh based on cellSet " << name_ << endl;
}
cellSet subset(baseMesh_, name_);
subsetter_.setLargeCellSubset(subset);
}
else if (type_ == 2)
{
if (verbose)
{
Info<< "Subsetting mesh based on cellZone " << name_ << endl;
}
labelHashSet subset(baseMesh_.cellZones()[name_]);
subsetter_.setLargeCellSubset(subset, 0);
}
}
Foam::polyMesh::readUpdateState Foam::meshSubsetHelper::readUpdate()
{
polyMesh::readUpdateState meshState = baseMesh_.readUpdate();
if (meshState != polyMesh::UNCHANGED)
{
correct(true);
}
return meshState;
}
// ************************************************************************* //

View File

@ -1,193 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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/>.
Class
Foam::meshSubsetHelper
Description
Simple helper to hold a mesh or mesh-subset and provide uniform access.
SourceFiles
meshSubsetHelper.C
meshSubsetHelperTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef meshSubsetHelper_H
#define meshSubsetHelper_H
#include "fvMeshSubset.H"
#include "zeroGradientFvPatchField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class Time;
/*---------------------------------------------------------------------------*\
Class meshSubsetHelper Declaration
\*---------------------------------------------------------------------------*/
class meshSubsetHelper
{
// Private data
//- Reference to mesh
fvMesh& baseMesh_;
//- Subsetting engine + sub-fvMesh
fvMeshSubset subsetter_;
//- Name of current cellSet/cellZone (or empty)
const word name_;
//- Internal book-keeping. 0 = unused, 1 = set, 2 = zone
const int type_;
// Private Member Functions
//- Disallow default bitwise copy construct
meshSubsetHelper(const meshSubsetHelper&) = delete;
//- Disallow default bitwise assignment
void operator=(const meshSubsetHelper&) = delete;
public:
// Constructors
//- Construct from components
meshSubsetHelper
(
fvMesh& baseMesh,
const word& name = word::null,
const bool isCellSet = false
);
// Member Functions
// Access
//- The entire base mesh
inline const fvMesh& baseMesh() const
{
return baseMesh_;
}
//- The mesh subsetter
inline const fvMeshSubset& subsetter() const
{
return subsetter_;
}
//- Check if running a sub-mesh is being used
inline bool useSubMesh() const
{
return type_;
}
//- Access either mesh or submesh
inline const fvMesh& mesh() const
{
if (useSubMesh())
{
return subsetter_.subMesh();
}
else
{
return baseMesh_;
}
}
// Edit
//- Update mesh subset
void correct(bool verbose = false);
//- Read mesh
polyMesh::readUpdateState readUpdate();
//- Construct volField (with zeroGradient) from an internal field
template<class Type>
static tmp<GeometricField<Type, fvPatchField, volMesh>>
zeroGradientField
(
const typename GeometricField
<
Type,
fvPatchField,
volMesh
>::Internal& df
);
//- Wrapper for field or the subsetted field.
// Map volume field (does in fact do very little interpolation;
// just copied from fvMeshSubset)
template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh>>
interpolate
(
const GeometricField<Type, fvPatchField, volMesh>&
) const;
//- Convert an internal field to a volume field
template<class Type>
tmp<GeometricField<Type, fvPatchField, volMesh>>
interpolate
(
const typename GeometricField
<
Type,
fvPatchField,
volMesh
>::Internal&
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "meshSubsetHelperTemplates.C"
#endif
#endif
// ************************************************************************* //

View File

@ -1,119 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "meshSubsetHelper.H"
#include "fvMesh.H"
#include "volFields.H"
#include "globalIndex.H"
#include "zeroGradientFvPatchField.H"
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>>
Foam::meshSubsetHelper::zeroGradientField
(
const typename GeometricField
<
Type,
fvPatchField,
volMesh
>::Internal& df
)
{
IOobject io(df);
io.readOpt() = IOobject::NO_READ;
io.writeOpt() = IOobject::NO_WRITE;
io.registerObject() = false;
tmp<GeometricField<Type, fvPatchField, volMesh>> tvf
(
new GeometricField<Type, fvPatchField, volMesh>
(
io,
df.mesh(),
dimensioned<Type>("0", df.dimensions(), Zero),
zeroGradientFvPatchField<Type>::typeName
)
);
tvf.ref().primitiveFieldRef() = df;
tvf.ref().correctBoundaryConditions();
return tvf;
}
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>>
Foam::meshSubsetHelper::interpolate
(
const GeometricField<Type, fvPatchField, volMesh>& vf
) const
{
if (subsetter_.hasSubMesh())
{
tmp<GeometricField<Type, fvPatchField, volMesh>> tfld
(
subsetter_.interpolate(vf)
);
tfld.ref().checkOut();
tfld.ref().rename(vf.name());
return tfld;
}
else
{
return vf;
}
}
template<class Type>
Foam::tmp<Foam::GeometricField<Type, Foam::fvPatchField, Foam::volMesh>>
Foam::meshSubsetHelper::interpolate
(
const typename GeometricField
<
Type,
fvPatchField,
volMesh
>::Internal& df
) const
{
tmp<GeometricField<Type, fvPatchField, volMesh>> tvf =
zeroGradientField<Type>(df);
if (subsetter_.hasSubMesh())
{
return interpolate<Type>(tvf());
}
else
{
return tvf;
}
}
// ************************************************************************* //