Add the OpenFOAM source tree

This commit is contained in:
Henry
2014-12-10 22:40:10 +00:00
parent ee487c860d
commit 446e5777f0
13379 changed files with 3983377 additions and 0 deletions

View File

@ -0,0 +1,15 @@
surfaceMeshWriter.C
foamToVTK.C
internalWriter.C
lagrangianWriter.C
patchWriter.C
writeFuns.C
writeFaceSet.C
writePointSet.C
writeSurfFields.C
vtkMesh.C
vtkTopo.C
EXE = $(FOAM_APPBIN)/foamToVTK

View File

@ -0,0 +1,11 @@
EXE_INC = \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
EXE_LIBS = \
-lfiniteVolume \
-llagrangian \
-lgenericPatchFields \
-lmeshTools

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,165 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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 "internalWriter.H"
#include "writeFuns.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::internalWriter::internalWriter
(
const vtkMesh& vMesh,
const bool binary,
const fileName& fName
)
:
vMesh_(vMesh),
binary_(binary),
fName_(fName),
os_(fName.c_str())
{
const fvMesh& mesh = vMesh_.mesh();
const vtkTopo& topo = vMesh_.topo();
// Write header
writeFuns::writeHeader(os_, binary_, mesh.time().caseName());
os_ << "DATASET UNSTRUCTURED_GRID" << std::endl;
//------------------------------------------------------------------
//
// Write topology
//
//------------------------------------------------------------------
const labelList& addPointCellLabels = topo.addPointCellLabels();
const label nTotPoints = mesh.nPoints() + addPointCellLabels.size();
os_ << "POINTS " << nTotPoints << " float" << std::endl;
DynamicList<floatScalar> ptField(3*nTotPoints);
writeFuns::insert(mesh.points(), ptField);
const pointField& ctrs = mesh.cellCentres();
forAll(addPointCellLabels, api)
{
writeFuns::insert(ctrs[addPointCellLabels[api]], ptField);
}
writeFuns::write(os_, binary_, ptField);
//
// Write cells
//
const labelListList& vtkVertLabels = topo.vertLabels();
// Count total number of vertices referenced.
label nFaceVerts = 0;
forAll(vtkVertLabels, cellI)
{
nFaceVerts += vtkVertLabels[cellI].size() + 1;
}
os_ << "CELLS " << vtkVertLabels.size() << ' ' << nFaceVerts << std::endl;
DynamicList<label> vertLabels(nFaceVerts);
forAll(vtkVertLabels, cellI)
{
const labelList& vtkVerts = vtkVertLabels[cellI];
vertLabels.append(vtkVerts.size());
writeFuns::insert(vtkVerts, vertLabels);
}
writeFuns::write(os_, binary_, vertLabels);
const labelList& vtkCellTypes = topo.cellTypes();
os_ << "CELL_TYPES " << vtkCellTypes.size() << std::endl;
// Make copy since writing might swap stuff.
DynamicList<label> cellTypes(vtkCellTypes.size());
writeFuns::insert(vtkCellTypes, cellTypes);
writeFuns::write(os_, binary_, cellTypes);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::internalWriter::writeCellIDs()
{
const fvMesh& mesh = vMesh_.mesh();
const vtkTopo& topo = vMesh_.topo();
const labelList& vtkCellTypes = topo.cellTypes();
const labelList& superCells = topo.superCells();
// Cell ids first
os_ << "cellID 1 " << vtkCellTypes.size() << " int" << std::endl;
labelList cellId(vtkCellTypes.size());
label labelI = 0;
if (vMesh_.useSubMesh())
{
const labelList& cMap = vMesh_.subsetter().cellMap();
forAll(mesh.cells(), cellI)
{
cellId[labelI++] = cMap[cellI];
}
forAll(superCells, superCellI)
{
label origCellI = cMap[superCells[superCellI]];
cellId[labelI++] = origCellI;
}
}
else
{
forAll(mesh.cells(), cellI)
{
cellId[labelI++] = cellI;
}
forAll(superCells, superCellI)
{
label origCellI = superCells[superCellI];
cellId[labelI++] = origCellI;
}
}
writeFuns::write(os_, binary_, cellId);
}
// ************************************************************************* //

View File

@ -0,0 +1,122 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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/>.
Class
Foam::internalWriter
Description
Write fields (internal).
SourceFiles
internalWriter.C
internalWriterTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef internalWriter_H
#define internalWriter_H
#include "OFstream.H"
#include "volFields.H"
#include "pointFields.H"
#include "vtkMesh.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class volPointInterpolation;
/*---------------------------------------------------------------------------*\
Class internalWriter Declaration
\*---------------------------------------------------------------------------*/
class internalWriter
{
const vtkMesh& vMesh_;
const bool binary_;
const fileName fName_;
std::ofstream os_;
public:
// Constructors
//- Construct from components
internalWriter
(
const vtkMesh&,
const bool binary,
const fileName&
);
// Member Functions
std::ofstream& os()
{
return os_;
}
//- Write cellIDs
void writeCellIDs();
//- Write generic GeometricFields
template<class Type, template<class> class PatchField, class GeoMesh>
void write
(
const PtrList<GeometricField<Type, PatchField, GeoMesh> >&
);
//- Interpolate and write volFields
template<class Type>
void write
(
const volPointInterpolation&,
const PtrList<GeometricField<Type, fvPatchField, volMesh> >&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "internalWriterTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,65 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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 "internalWriter.H"
#include "writeFuns.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::internalWriter::write
(
const PtrList<GeometricField<Type, PatchField, GeoMesh> >& flds
)
{
forAll(flds, i)
{
writeFuns::write(os_, binary_, flds[i], vMesh_);
}
}
template<class Type>
void Foam::internalWriter::write
(
const volPointInterpolation& pInterp,
const PtrList<GeometricField<Type, fvPatchField, volMesh> >& flds
)
{
forAll(flds, i)
{
writeFuns::write
(
os_,
binary_,
flds[i],
pInterp.interpolate(flds[i])(),
vMesh_
);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,89 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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 "lagrangianWriter.H"
#include "writeFuns.H"
#include "Cloud.H"
#include "passiveParticle.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::lagrangianWriter::lagrangianWriter
(
const vtkMesh& vMesh,
const bool binary,
const fileName& fName,
const word& cloudName,
const bool dummyCloud
)
:
vMesh_(vMesh),
binary_(binary),
fName_(fName),
cloudName_(cloudName),
os_(fName.c_str())
{
const fvMesh& mesh = vMesh_.mesh();
// Write header
writeFuns::writeHeader(os_, binary_, mesh.time().caseName());
os_ << "DATASET POLYDATA" << std::endl;
if (dummyCloud)
{
nParcels_ = 0;
os_ << "POINTS " << nParcels_ << " float" << std::endl;
}
else
{
Cloud<passiveParticle> parcels(mesh, cloudName_, false);
nParcels_ = parcels.size();
os_ << "POINTS " << nParcels_ << " float" << std::endl;
DynamicList<floatScalar> partField(3*parcels.size());
forAllConstIter(Cloud<passiveParticle>, parcels, elmnt)
{
writeFuns::insert(elmnt().position(), partField);
}
writeFuns::write(os_, binary_, partField);
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::lagrangianWriter::writeParcelHeader(const label nFields)
{
os_ << "POINT_DATA " << nParcels_ << std::endl
<< "FIELD attributes " << nFields
<< std::endl;
}
// ************************************************************************* //

View File

@ -0,0 +1,118 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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/>.
Class
Foam::lagrangianWriter
Description
Write fields (internal).
SourceFiles
lagrangianWriter.C
lagrangianWriterTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef lagrangianWriter_H
#define lagrangianWriter_H
#include "OFstream.H"
#include "Cloud.H"
#include "volFields.H"
#include "pointFields.H"
#include "vtkMesh.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class volPointInterpolation;
/*---------------------------------------------------------------------------*\
Class lagrangianWriter Declaration
\*---------------------------------------------------------------------------*/
class lagrangianWriter
{
const vtkMesh& vMesh_;
const bool binary_;
const fileName fName_;
const word cloudName_;
std::ofstream os_;
label nParcels_;
public:
// Constructors
//- Construct from components
lagrangianWriter
(
const vtkMesh&,
const bool binary,
const fileName&,
const word&,
const bool dummyCloud
);
// Member Functions
std::ofstream& os()
{
return os_;
}
void writeParcelHeader(const label nFields);
//- Write IOField
template<class Type>
void writeIOField(const wordList&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "lagrangianWriterTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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 "lagrangianWriter.H"
#include "writeFuns.H"
#include "IOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::lagrangianWriter::writeIOField(const wordList& objects)
{
forAll(objects, i)
{
const word& object = objects[i];
IOobject header
(
object,
vMesh_.mesh().time().timeName(),
cloud::prefix/cloudName_,
vMesh_.mesh(),
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
);
IOField<Type> fld(header);
os_ << object << ' ' << pTraits<Type>::nComponents << ' '
<< fld.size() << " float" << std::endl;
DynamicList<floatScalar> fField(pTraits<Type>::nComponents*fld.size());
writeFuns::insert(fld, fField);
writeFuns::write(os_, binary_, fField);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,139 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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 "patchWriter.H"
#include "writeFuns.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::patchWriter::patchWriter
(
const vtkMesh& vMesh,
const bool binary,
const bool nearCellValue,
const fileName& fName,
const labelList& patchIDs
)
:
vMesh_(vMesh),
binary_(binary),
nearCellValue_(nearCellValue),
fName_(fName),
patchIDs_(patchIDs),
os_(fName.c_str())
{
const fvMesh& mesh = vMesh_.mesh();
const polyBoundaryMesh& patches = mesh.boundaryMesh();
// Write header
if (patchIDs_.size() == 1)
{
writeFuns::writeHeader(os_, binary_, patches[patchIDs_[0]].name());
}
else
{
writeFuns::writeHeader(os_, binary_, "patches");
}
os_ << "DATASET POLYDATA" << std::endl;
// Write topology
nPoints_ = 0;
nFaces_ = 0;
label nFaceVerts = 0;
forAll(patchIDs_, i)
{
const polyPatch& pp = patches[patchIDs_[i]];
nPoints_ += pp.nPoints();
nFaces_ += pp.size();
forAll(pp, faceI)
{
nFaceVerts += pp[faceI].size() + 1;
}
}
os_ << "POINTS " << nPoints_ << " float" << std::endl;
DynamicList<floatScalar> ptField(3*nPoints_);
forAll(patchIDs_, i)
{
const polyPatch& pp = patches[patchIDs_[i]];
writeFuns::insert(pp.localPoints(), ptField);
}
writeFuns::write(os_, binary_, ptField);
os_ << "POLYGONS " << nFaces_ << ' ' << nFaceVerts << std::endl;
DynamicList<label> vertLabels(nFaceVerts);
label offset = 0;
forAll(patchIDs_, i)
{
const polyPatch& pp = patches[patchIDs_[i]];
forAll(pp, faceI)
{
const face& f = pp.localFaces()[faceI];
vertLabels.append(f.size());
writeFuns::insert(f + offset, vertLabels);
}
offset += pp.nPoints();
}
writeFuns::write(os_, binary_, vertLabels);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::patchWriter::writePatchIDs()
{
const fvMesh& mesh = vMesh_.mesh();
DynamicList<floatScalar> fField(nFaces_);
os_ << "patchID 1 " << nFaces_ << " float" << std::endl;
forAll(patchIDs_, i)
{
label patchI = patchIDs_[i];
const polyPatch& pp = mesh.boundaryMesh()[patchI];
if (!isA<emptyPolyPatch>(pp))
{
writeFuns::insert(scalarField(pp.size(), patchI), fField);
}
}
writeFuns::write(os_, binary_, fField);
}
// ************************************************************************* //

View File

@ -0,0 +1,152 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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/>.
Class
Foam::patchWriter
Description
Write patch fields
SourceFiles
patchWriter.C
patchWriterTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef patchWriter_H
#define patchWriter_H
#include "pointMesh.H"
#include "OFstream.H"
#include "volFields.H"
#include "pointFields.H"
#include "vtkMesh.H"
#include "indirectPrimitivePatch.H"
#include "PrimitivePatchInterpolation.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class volPointInterpolation;
/*---------------------------------------------------------------------------*\
Class patchWriter Declaration
\*---------------------------------------------------------------------------*/
class patchWriter
{
const vtkMesh& vMesh_;
const bool binary_;
const bool nearCellValue_;
const fileName fName_;
const labelList patchIDs_;
std::ofstream os_;
label nPoints_;
label nFaces_;
public:
// Constructors
//- Construct from components
patchWriter
(
const vtkMesh&,
const bool binary,
const bool nearCellValue,
const fileName&,
const labelList& patchIDs
);
// Member Functions
std::ofstream& os()
{
return os_;
}
label nPoints() const
{
return nPoints_;
}
label nFaces() const
{
return nFaces_;
}
//- Write cellIDs
void writePatchIDs();
//- Write volFields
template<class Type>
void write
(
const PtrList<GeometricField<Type, fvPatchField, volMesh> >&
);
//- Write pointFields
template<class Type>
void write
(
const PtrList<GeometricField<Type, pointPatchField, pointMesh> >&
);
//- Interpolate and write volFields
template<class Type>
void write
(
const PrimitivePatchInterpolation<primitivePatch>&,
const PtrList<GeometricField<Type, fvPatchField, volMesh> >&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "patchWriterTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,142 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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 "patchWriter.H"
#include "writeFuns.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::patchWriter::write
(
const PtrList<GeometricField<Type, fvPatchField, volMesh> >& flds
)
{
forAll(flds, fieldI)
{
const GeometricField<Type, fvPatchField, volMesh>& fld = flds[fieldI];
os_ << fld.name() << ' ' << pTraits<Type>::nComponents << ' '
<< nFaces_ << " float" << std::endl;
DynamicList<floatScalar> fField(pTraits<Type>::nComponents*nFaces_);
forAll(patchIDs_, j)
{
label patchI = patchIDs_[j];
const fvPatchField<Type>& pfld = fld.boundaryField()[patchI];
if (nearCellValue_)
{
writeFuns::insert(pfld.patchInternalField()(), fField);
}
else
{
writeFuns::insert(pfld, fField);
}
}
writeFuns::write(os_, binary_, fField);
}
}
template<class Type>
void Foam::patchWriter::write
(
const PtrList<GeometricField<Type, pointPatchField, pointMesh> >& flds
)
{
forAll(flds, fieldI)
{
const GeometricField<Type, pointPatchField, pointMesh>& fld =
flds[fieldI];
os_ << fld.name() << ' ' << pTraits<Type>::nComponents << ' '
<< nPoints_ << " float" << std::endl;
DynamicList<floatScalar> fField(pTraits<Type>::nComponents*nPoints_);
forAll(patchIDs_, j)
{
label patchI = patchIDs_[j];
const pointPatchField<Type>& pfld = fld.boundaryField()[patchI];
writeFuns::insert(pfld.patchInternalField()(), fField);
}
writeFuns::write(os_, binary_, fField);
}
}
template<class Type>
void Foam::patchWriter::write
(
const PrimitivePatchInterpolation<primitivePatch>& pInter,
const PtrList<GeometricField<Type, fvPatchField, volMesh> >& flds
)
{
forAll(flds, fieldI)
{
const GeometricField<Type, fvPatchField, volMesh>& fld = flds[fieldI];
os_ << fld.name() << ' ' << pTraits<Type>::nComponents << ' '
<< nPoints_ << " float" << std::endl;
DynamicList<floatScalar> fField(pTraits<Type>::nComponents*nPoints_);
forAll(patchIDs_, j)
{
label patchI = patchIDs_[j];
const fvPatchField<Type>& pfld = fld.boundaryField()[patchI];
if (nearCellValue_)
{
writeFuns::insert
(
pInter.faceToPointInterpolate
(
pfld.patchInternalField()()
)(),
fField
);
}
else
{
writeFuns::insert
(
pInter.faceToPointInterpolate(pfld)(),
fField
);
}
}
writeFuns::write(os_, binary_, fField);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,81 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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 "readFields.H"
#include "IOobjectList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
template<class GeoField>
void readFields
(
const vtkMesh& vMesh,
const typename GeoField::Mesh& mesh,
const IOobjectList& objects,
const HashSet<word>& selectedFields,
PtrList<GeoField>& fields
)
{
// Search list of objects for volScalarFields
IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
// Construct the vol scalar fields
fields.setSize(fieldObjects.size());
label nFields = 0;
forAllIter(IOobjectList, fieldObjects, iter)
{
if (selectedFields.empty() || selectedFields.found(iter()->name()))
{
fields.set
(
nFields,
vMesh.interpolate
(
GeoField
(
*iter(),
mesh
)
)
);
nFields++;
}
}
fields.setSize(nFields);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,70 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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/>.
InClass
Foam::readFields
Description
SourceFiles
readFields.C
\*---------------------------------------------------------------------------*/
#ifndef readFields_H
#define readFields_H
#include "fvMesh.H"
#include "PtrList.H"
#include "IOobjectList.H"
#include "HashSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Read the fields and optionally subset and put on the pointer list
template<class GeoField>
void readFields
(
const vtkMesh& vMesh,
const typename GeoField::Mesh& mesh,
const IOobjectList& objects,
const HashSet<word>& selectedFields,
PtrList<GeoField>& fields
);
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "readFields.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,79 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 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 "surfaceMeshWriter.H"
#include "writeFuns.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::surfaceMeshWriter::surfaceMeshWriter
(
const bool binary,
const indirectPrimitivePatch& pp,
const word& name,
const fileName& fName
)
:
binary_(binary),
pp_(pp),
fName_(fName),
os_(fName.c_str())
{
// Write header
writeFuns::writeHeader(os_, binary_, name);
os_ << "DATASET POLYDATA" << std::endl;
// Write topology
label nFaceVerts = 0;
forAll(pp, faceI)
{
nFaceVerts += pp[faceI].size() + 1;
}
os_ << "POINTS " << pp.nPoints() << " float" << std::endl;
DynamicList<floatScalar> ptField(3*pp.nPoints());
writeFuns::insert(pp.localPoints(), ptField);
writeFuns::write(os_, binary, ptField);
os_ << "POLYGONS " << pp.size() << ' ' << nFaceVerts << std::endl;
DynamicList<label> vertLabels(nFaceVerts);
forAll(pp, faceI)
{
const face& f = pp.localFaces()[faceI];
vertLabels.append(f.size());
writeFuns::insert(f, vertLabels);
}
writeFuns::write(os_, binary_, vertLabels);
}
// ************************************************************************* //

View File

@ -0,0 +1,122 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 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/>.
Class
Foam::surfaceMeshWriter
Description
Write faces with fields
SourceFiles
surfaceMeshWriter.C
surfaceMeshWriterTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef surfaceMeshWriter_H
#define surfaceMeshWriter_H
#include "pointMesh.H"
#include "OFstream.H"
#include "volFields.H"
#include "surfaceFields.H"
#include "vtkMesh.H"
#include "indirectPrimitivePatch.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class volPointInterpolation;
/*---------------------------------------------------------------------------*\
Class surfaceMeshWriter Declaration
\*---------------------------------------------------------------------------*/
class surfaceMeshWriter
{
const bool binary_;
const indirectPrimitivePatch& pp_;
const fileName fName_;
std::ofstream os_;
public:
// Constructors
//- Construct from components
surfaceMeshWriter
(
const bool binary,
const indirectPrimitivePatch& pp,
const word& name,
const fileName&
);
// Member Functions
std::ofstream& os()
{
return os_;
}
//- Extract face data
template<class Type>
tmp<Field<Type> > getFaceField
(
const GeometricField<Type, fvsPatchField, surfaceMesh>&
) const;
//- Write surfaceFields
template<class Type>
void write
(
const PtrList<GeometricField<Type, fvsPatchField, surfaceMesh> >&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "surfaceMeshWriterTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,84 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 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 "surfaceMeshWriter.H"
#include "writeFuns.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
Foam::tmp<Field<Type> > Foam::surfaceMeshWriter::getFaceField
(
const GeometricField<Type, fvsPatchField, surfaceMesh>& sfld
) const
{
const polyBoundaryMesh& patches = sfld.mesh().boundaryMesh();
tmp<Field<Type> > tfld(new Field<Type>(pp_.size()));
Field<Type>& fld = tfld();
forAll(pp_.addressing(), i)
{
label faceI = pp_.addressing()[i];
label patchI = patches.whichPatch(faceI);
if (patchI == -1)
{
fld[i] = sfld[faceI];
}
else
{
label localFaceI = faceI - patches[patchI].start();
fld[i] = sfld.boundaryField()[patchI][localFaceI];
}
}
return tfld;
}
template<class Type>
void Foam::surfaceMeshWriter::write
(
const PtrList<GeometricField<Type, fvsPatchField, surfaceMesh> >& sflds
)
{
forAll(sflds, fieldI)
{
const GeometricField<Type, fvsPatchField, surfaceMesh>& fld =
sflds[fieldI];
os_ << fld.name() << ' ' << pTraits<Type>::nComponents << ' '
<< pp_.size() << " float" << std::endl;
DynamicList<floatScalar> fField(pTraits<Type>::nComponents*pp_.size());
writeFuns::insert(getFaceField(fld)(), fField);
writeFuns::write(os_, binary_, fField);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,82 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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

@ -0,0 +1,179 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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/>.
Class
Foam::vtkMesh
Description
Encapsulation of VTK mesh data. Holds mesh or meshsubset and
polyhedral-cell decomposition on it.
SourceFiles
vtkMesh.C
\*---------------------------------------------------------------------------*/
#ifndef vtkMesh_H
#define vtkMesh_H
#include "vtkTopo.H"
#include "fvMeshSubset.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class Time;
/*---------------------------------------------------------------------------*\
Class vtkMesh Declaration
\*---------------------------------------------------------------------------*/
class vtkMesh
{
// 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&);
//- Disallow default bitwise assignment
void operator=(const vtkMesh&);
public:
// Constructors
//- Construct from components
vtkMesh(fvMesh& baseMesh, const word& 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
const vtkTopo& topo() const
{
if (topoPtr_.empty())
{
topoPtr_.reset(new vtkTopo(mesh()));
}
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
{
return topo().cellTypes().size();
}
//- Number of field points
label nFieldPoints() const
{
return mesh().nPoints() + topo().addPointCellLabels().size();
}
// 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
{
if (useSubMesh())
{
tmp<GeoField> subFld = subsetter_.interpolate(fld);
subFld().rename(fld.name());
return subFld;
}
else
{
return fld;
}
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,373 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 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/>.
Description
Note: bug in vtk displaying wedges? Seems to display ok if we decompose
them. Should be thoroughly tested!
(they appear rarely in polyhedral meshes, do appear in some cut meshes)
\*---------------------------------------------------------------------------*/
#include "vtkTopo.H"
#include "polyMesh.H"
#include "cellShape.H"
#include "cellModeller.H"
#include "Swap.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
bool Foam::vtkTopo::decomposePoly = true;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::vtkTopo::vtkTopo(const polyMesh& mesh)
:
mesh_(mesh),
vertLabels_(),
cellTypes_(),
addPointCellLabels_(),
superCells_()
{
const cellModel& tet = *(cellModeller::lookup("tet"));
const cellModel& pyr = *(cellModeller::lookup("pyr"));
const cellModel& prism = *(cellModeller::lookup("prism"));
const cellModel& wedge = *(cellModeller::lookup("wedge"));
const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
const cellModel& hex = *(cellModeller::lookup("hex"));
const cellShapeList& cellShapes = mesh_.cellShapes();
// Number of additional points needed by the decomposition of polyhedra
label nAddPoints = 0;
// Number of additional cells generated by the decomposition of polyhedra
label nAddCells = 0;
// face owner is needed to determine the face orientation
const labelList& owner = mesh.faceOwner();
// Scan for cells which need to be decomposed and count additional points
// and cells
if (decomposePoly)
{
forAll(cellShapes, cellI)
{
const cellModel& model = cellShapes[cellI].model();
if
(
model != hex
&& model != wedge // See above.
&& model != prism
&& model != pyr
&& model != tet
&& model != tetWedge
)
{
const cell& cFaces = mesh_.cells()[cellI];
forAll(cFaces, cFaceI)
{
const face& f = mesh_.faces()[cFaces[cFaceI]];
label nQuads = 0;
label nTris = 0;
f.nTrianglesQuads(mesh_.points(), nTris, nQuads);
nAddCells += nQuads + nTris;
}
nAddCells--;
nAddPoints++;
}
}
}
// Set size of additional point addressing array
// (from added point to original cell)
addPointCellLabels_.setSize(nAddPoints);
// Set size of additional cells mapping array
// (from added cell to original cell)
superCells_.setSize(nAddCells);
// List of vertex labels in VTK ordering
vertLabels_.setSize(cellShapes.size() + nAddCells);
// Label of vtk type
cellTypes_.setSize(cellShapes.size() + nAddCells);
// Set counters for additional points and additional cells
label addPointI = 0, addCellI = 0;
forAll(cellShapes, cellI)
{
const cellShape& cellShape = cellShapes[cellI];
const cellModel& cellModel = cellShape.model();
labelList& vtkVerts = vertLabels_[cellI];
if (cellModel == tet)
{
vtkVerts = cellShape;
cellTypes_[cellI] = VTK_TETRA;
}
else if (cellModel == pyr)
{
vtkVerts = cellShape;
cellTypes_[cellI] = VTK_PYRAMID;
}
else if (cellModel == prism)
{
// VTK has a different node order for VTK_WEDGE
// their triangles point outwards!
vtkVerts = cellShape;
Foam::Swap(vtkVerts[1], vtkVerts[2]);
Foam::Swap(vtkVerts[4], vtkVerts[5]);
cellTypes_[cellI] = VTK_WEDGE;
}
else if (cellModel == tetWedge)
{
// Treat as squeezed prism
vtkVerts.setSize(6);
vtkVerts[0] = cellShape[0];
vtkVerts[1] = cellShape[2];
vtkVerts[2] = cellShape[1];
vtkVerts[3] = cellShape[3];
vtkVerts[4] = cellShape[4];
vtkVerts[5] = cellShape[4];
cellTypes_[cellI] = VTK_WEDGE;
}
else if (cellModel == wedge)
{
// Treat as squeezed hex
vtkVerts.setSize(8);
vtkVerts[0] = cellShape[0];
vtkVerts[1] = cellShape[1];
vtkVerts[2] = cellShape[2];
vtkVerts[3] = cellShape[2];
vtkVerts[4] = cellShape[3];
vtkVerts[5] = cellShape[4];
vtkVerts[6] = cellShape[5];
vtkVerts[7] = cellShape[6];
cellTypes_[cellI] = VTK_HEXAHEDRON;
}
else if (cellModel == hex)
{
vtkVerts = cellShape;
cellTypes_[cellI] = VTK_HEXAHEDRON;
}
else if (decomposePoly)
{
// Polyhedral cell. Decompose into tets + pyramids.
// Mapping from additional point to cell
addPointCellLabels_[addPointI] = cellI;
// The new vertex from the cell-centre
const label newVertexLabel = mesh_.nPoints() + addPointI;
// Whether to insert cell in place of original or not.
bool substituteCell = true;
const labelList& cFaces = mesh_.cells()[cellI];
forAll(cFaces, cFaceI)
{
const face& f = mesh_.faces()[cFaces[cFaceI]];
const bool isOwner = (owner[cFaces[cFaceI]] == cellI);
// Number of triangles and quads in decomposition
label nTris = 0;
label nQuads = 0;
f.nTrianglesQuads(mesh_.points(), nTris, nQuads);
// Do actual decomposition into triFcs and quadFcs.
faceList triFcs(nTris);
faceList quadFcs(nQuads);
label trii = 0;
label quadi = 0;
f.trianglesQuads(mesh_.points(), trii, quadi, triFcs, quadFcs);
forAll(quadFcs, quadI)
{
label thisCellI;
if (substituteCell)
{
thisCellI = cellI;
substituteCell = false;
}
else
{
thisCellI = mesh_.nCells() + addCellI;
superCells_[addCellI++] = cellI;
}
labelList& addVtkVerts = vertLabels_[thisCellI];
addVtkVerts.setSize(5);
const face& quad = quadFcs[quadI];
// Ensure we have the correct orientation for the
// base of the primitive cell shape.
// If the cell is face owner, the orientation needs to be
// flipped.
// At the moment, VTK doesn't actually seem to care if
// negative cells are defined, but we'll do it anyhow
// (for safety).
if (isOwner)
{
addVtkVerts[0] = quad[3];
addVtkVerts[1] = quad[2];
addVtkVerts[2] = quad[1];
addVtkVerts[3] = quad[0];
}
else
{
addVtkVerts[0] = quad[0];
addVtkVerts[1] = quad[1];
addVtkVerts[2] = quad[2];
addVtkVerts[3] = quad[3];
}
addVtkVerts[4] = newVertexLabel;
cellTypes_[thisCellI] = VTK_PYRAMID;
}
forAll(triFcs, triI)
{
label thisCellI;
if (substituteCell)
{
thisCellI = cellI;
substituteCell = false;
}
else
{
thisCellI = mesh_.nCells() + addCellI;
superCells_[addCellI++] = cellI;
}
labelList& addVtkVerts = vertLabels_[thisCellI];
const face& tri = triFcs[triI];
addVtkVerts.setSize(4);
// See note above about the orientation.
if (isOwner)
{
addVtkVerts[0] = tri[2];
addVtkVerts[1] = tri[1];
addVtkVerts[2] = tri[0];
}
else
{
addVtkVerts[0] = tri[0];
addVtkVerts[1] = tri[1];
addVtkVerts[2] = tri[2];
}
addVtkVerts[3] = newVertexLabel;
cellTypes_[thisCellI] = VTK_TETRA;
}
}
addPointI++;
}
else
{
// Polyhedral cell - not decomposed
cellTypes_[cellI] = VTK_POLYHEDRON;
const labelList& cFaces = mesh_.cells()[cellI];
// space for the number of faces and size of each face
label nData = 1 + cFaces.size();
// count total number of face points
forAll(cFaces, cFaceI)
{
const face& f = mesh.faces()[cFaces[cFaceI]];
nData += f.size(); // space for the face labels
}
vtkVerts.setSize(nData);
nData = 0;
vtkVerts[nData++] = cFaces.size();
// build face stream
forAll(cFaces, cFaceI)
{
const face& f = mesh.faces()[cFaces[cFaceI]];
const bool isOwner = (owner[cFaces[cFaceI]] == cellI);
// number of labels for this face
vtkVerts[nData++] = f.size();
if (isOwner)
{
forAll(f, fp)
{
vtkVerts[nData++] = f[fp];
}
}
else
{
// fairly immaterial if we reverse the list
// or use face::reverseFace()
forAllReverse(f, fp)
{
vtkVerts[nData++] = f[fp];
}
}
}
}
}
if (decomposePoly)
{
Pout<< " Original cells:" << mesh_.nCells()
<< " points:" << mesh_.nPoints()
<< " Additional cells:" << superCells_.size()
<< " additional points:" << addPointCellLabels_.size()
<< nl << endl;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,139 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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/>.
Class
Foam::vtkTopo
Description
Polyhedral cell decomposition for VTK.
SourceFiles
vtkTopo.C
\*---------------------------------------------------------------------------*/
#ifndef vtkTopo_H
#define vtkTopo_H
#include "labelList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class polyMesh;
/*---------------------------------------------------------------------------*\
Class vtkTopo Declaration
\*---------------------------------------------------------------------------*/
class vtkTopo
{
// Private data
const polyMesh& mesh_;
//- Vertices per cell (including added cells) in vtk ordering
labelListList vertLabels_;
//- Cell types (including added cells) in vtk numbering
labelList cellTypes_;
labelList addPointCellLabels_;
labelList superCells_;
// Private Member Functions
//- Disallow default bitwise copy construct
vtkTopo(const vtkTopo&);
//- Disallow default bitwise assignment
void operator=(const vtkTopo&);
public:
// Public static data
//- equivalent to enumeration in "vtkCellType.h"
enum vtkTypes
{
VTK_TRIANGLE = 5,
VTK_POLYGON = 7,
VTK_QUAD = 9,
VTK_TETRA = 10,
VTK_HEXAHEDRON = 12,
VTK_WEDGE = 13,
VTK_PYRAMID = 14,
VTK_POLYHEDRON = 42
};
//- Enable/disable polyhedron decomposition. Default = true
static bool decomposePoly;
// Constructors
//- Construct from components
vtkTopo(const polyMesh&);
// Member Functions
// Access
const labelListList& vertLabels() const
{
return vertLabels_;
}
const labelList& cellTypes() const
{
return cellTypes_;
}
const labelList& addPointCellLabels() const
{
return addPointCellLabels_;
}
const labelList& superCells() const
{
return superCells_;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,127 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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 "writeFaceSet.H"
#include "OFstream.H"
#include "writeFuns.H"
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
void Foam::writeFaceSet
(
const bool binary,
const vtkMesh& vMesh,
const faceSet& set,
const fileName& fileName
)
{
const faceList& faces = vMesh.mesh().faces();
std::ofstream ostr(fileName.c_str());
writeFuns::writeHeader
(
ostr,
binary,
set.name()
);
ostr<< "DATASET POLYDATA" << std::endl;
//------------------------------------------------------------------
//
// Write topology
//
//------------------------------------------------------------------
// Construct primitivePatch of faces in faceSet.
faceList setFaces(set.size());
labelList setFaceLabels(set.size());
label setFaceI = 0;
forAllConstIter(faceSet, set, iter)
{
setFaceLabels[setFaceI] = iter.key();
setFaces[setFaceI] = faces[iter.key()];
setFaceI++;
}
primitiveFacePatch fp(setFaces, vMesh.mesh().points());
// Write points and faces as polygons
ostr<< "POINTS " << fp.nPoints() << " float" << std::endl;
DynamicList<floatScalar> ptField(3*fp.nPoints());
writeFuns::insert(fp.localPoints(), ptField);
writeFuns::write(ostr, binary, ptField);
label nFaceVerts = 0;
forAll(fp.localFaces(), faceI)
{
nFaceVerts += fp.localFaces()[faceI].size() + 1;
}
ostr<< "POLYGONS " << fp.size() << ' ' << nFaceVerts << std::endl;
DynamicList<label> vertLabels(nFaceVerts);
forAll(fp.localFaces(), faceI)
{
const face& f = fp.localFaces()[faceI];
vertLabels.append(f.size());
writeFuns::insert(f, vertLabels);
}
writeFuns::write(ostr, binary, vertLabels);
//-----------------------------------------------------------------
//
// Write data
//
//-----------------------------------------------------------------
// Write faceID
ostr
<< "CELL_DATA " << fp.size() << std::endl
<< "FIELD attributes 1" << std::endl;
// Cell ids first
ostr<< "faceID 1 " << fp.size() << " int" << std::endl;
writeFuns::write(ostr, binary, setFaceLabels);
}
// ************************************************************************* //

View File

@ -0,0 +1,63 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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/>.
InClass
Foam::writeFaceSet
Description
Write faceSet to vtk polydata file. Only one data which is original
faceID.
SourceFiles
writeFaceSet.C
\*---------------------------------------------------------------------------*/
#ifndef writeFaceSet_H
#define writeFaceSet_H
#include "vtkMesh.H"
#include "faceSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Write lagrangian fields.
void writeFaceSet
(
const bool binary,
const vtkMesh& vMesh,
const faceSet& set,
const fileName& fileName
);
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,288 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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 "writeFuns.H"
#include "vtkTopo.H"
#if defined(__mips) && !defined(__SICORTEX__)
#include <standards.h>
#include <sys/endian.h>
#endif
// MacOSX
#ifdef __DARWIN_BYTE_ORDER
#if __DARWIN_BYTE_ORDER==__DARWIN_BIG_ENDIAN
#undef LITTLE_ENDIAN
#else
#undef BIG_ENDIAN
#endif
#endif
#if defined(LITTLE_ENDIAN) \
|| defined(_LITTLE_ENDIAN) \
|| defined(__LITTLE_ENDIAN)
# define LITTLEENDIAN 1
#elif defined(BIG_ENDIAN) || defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN)
# undef LITTLEENDIAN
#else
# error "Cannot find LITTLE_ENDIAN or BIG_ENDIAN symbol defined."
# error "Please add to compilation options"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
void Foam::writeFuns::swapWord(label& word32)
{
char* mem = reinterpret_cast<char*>(&word32);
char a = mem[0];
mem[0] = mem[3];
mem[3] = a;
a = mem[1];
mem[1] = mem[2];
mem[2] = a;
}
void Foam::writeFuns::swapWords(const label nWords, label* words32)
{
for (label i = 0; i < nWords; i++)
{
swapWord(words32[i]);
}
}
void Foam::writeFuns::write
(
std::ostream& os,
const bool binary,
List<floatScalar>& fField
)
{
if (binary)
{
# ifdef LITTLEENDIAN
swapWords(fField.size(), reinterpret_cast<label*>(fField.begin()));
# endif
os.write
(
reinterpret_cast<char*>(fField.begin()),
fField.size()*sizeof(float)
);
os << std::endl;
}
else
{
forAll(fField, i)
{
os << fField[i];
if (i > 0 && (i % 10) == 0)
{
os << std::endl;
}
else
{
os << ' ';
}
}
os << std::endl;
}
}
void Foam::writeFuns::write
(
std::ostream& os,
const bool binary,
DynamicList<floatScalar>& fField
)
{
List<floatScalar>& fld = fField.shrink();
write(os, binary, fld);
}
void Foam::writeFuns::write
(
std::ostream& os,
const bool binary,
labelList& elems
)
{
if (binary)
{
# ifdef LITTLEENDIAN
swapWords(elems.size(), reinterpret_cast<label*>(elems.begin()));
# endif
os.write
(
reinterpret_cast<char*>(elems.begin()),
elems.size()*sizeof(label)
);
os << std::endl;
}
else
{
forAll(elems, i)
{
os << elems[i];
if (i > 0 && (i % 10) == 0)
{
os << std::endl;
}
else
{
os << ' ';
}
}
os << std::endl;
}
}
void Foam::writeFuns::write
(
std::ostream& os,
const bool binary,
DynamicList<label>& elems
)
{
labelList& fld = elems.shrink();
write(os, binary, fld);
}
void Foam::writeFuns::writeHeader
(
std::ostream& os,
const bool binary,
const std::string& title
)
{
os << "# vtk DataFile Version 2.0" << std::endl
<< title << std::endl;
if (binary)
{
os << "BINARY" << std::endl;
}
else
{
os << "ASCII" << std::endl;
}
}
void Foam::writeFuns::writeCellDataHeader
(
std::ostream& os,
const label nCells,
const label nFields
)
{
os << "CELL_DATA " << nCells << std::endl
<< "FIELD attributes " << nFields << std::endl;
}
void Foam::writeFuns::writePointDataHeader
(
std::ostream& os,
const label nPoints,
const label nFields
)
{
os << "POINT_DATA " << nPoints << std::endl
<< "FIELD attributes " << nFields << std::endl;
}
void Foam::writeFuns::insert(const scalar src, DynamicList<floatScalar>& dest)
{
dest.append(float(src));
}
void Foam::writeFuns::insert(const vector& src, DynamicList<floatScalar>& dest)
{
for (direction cmpt = 0; cmpt < vector::nComponents; ++cmpt)
{
dest.append(float(src[cmpt]));
}
}
void Foam::writeFuns::insert
(
const sphericalTensor& src,
DynamicList<floatScalar>& dest
)
{
for (direction cmpt = 0; cmpt < sphericalTensor::nComponents; ++cmpt)
{
dest.append(float(src[cmpt]));
}
}
void Foam::writeFuns::insert
(
const symmTensor& src,
DynamicList<floatScalar>& dest
)
{
dest.append(float(src.xx()));
dest.append(float(src.yy()));
dest.append(float(src.zz()));
dest.append(float(src.xy()));
dest.append(float(src.yz()));
dest.append(float(src.xz()));
}
void Foam::writeFuns::insert(const tensor& src, DynamicList<floatScalar>& dest)
{
for (direction cmpt = 0; cmpt < tensor::nComponents; ++cmpt)
{
dest.append(float(src[cmpt]));
}
}
void Foam::writeFuns::insert(const labelList& src, DynamicList<label>& dest)
{
dest.append(src);
}
// ************************************************************************* //

View File

@ -0,0 +1,180 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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/>.
Class
Foam::writeFuns
Description
Various functions for collecting and writing binary data.
SourceFiles
writeFuns.C
\*---------------------------------------------------------------------------*/
#ifndef writeFuns_H
#define writeFuns_H
#include "floatScalar.H"
#include "DynamicList.H"
#include "volFieldsFwd.H"
#include "pointFieldsFwd.H"
#include "vtkMesh.H"
#include "volPointInterpolation.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class writeFuns Declaration
\*---------------------------------------------------------------------------*/
class writeFuns
{
// Private Member Functions
// Swap halves of word.
static void swapWord(label& word32);
static void swapWords(const label nWords, label* words32);
public:
// Write ascii or binary. If binary optionally in-place swaps argument
static void write(std::ostream&, const bool, List<floatScalar>&);
static void write(std::ostream&, const bool, DynamicList<floatScalar>&);
static void write(std::ostream&, const bool, labelList&);
static void write(std::ostream&, const bool, DynamicList<label>&);
// Write header
static void writeHeader
(
std::ostream&,
const bool isBinary,
const std::string& title
);
static void writeCellDataHeader
(
std::ostream&,
const label nCells,
const label nFields
);
static void writePointDataHeader
(
std::ostream&,
const label nPoints,
const label nFields
);
// Convert to VTK and store
static void insert(const scalar, DynamicList<floatScalar>&);
static void insert(const point&, DynamicList<floatScalar>&);
static void insert(const sphericalTensor&, DynamicList<floatScalar>&);
static void insert(const symmTensor&, DynamicList<floatScalar>&);
static void insert(const tensor&, DynamicList<floatScalar>&);
//- Append elements to DynamicList
static void insert(const labelList&, DynamicList<label>&);
template<class Type>
static void insert(const List<Type>&, DynamicList<floatScalar>&);
//- Write volField with cell values (including decomposed cells)
template<class Type>
static void write
(
std::ostream&,
const bool binary,
const GeometricField<Type, fvPatchField, volMesh>&,
const vtkMesh&
);
//- Write pointField on all mesh points. Interpolate to cell centre
// for decomposed cell centres.
template<class Type>
static void write
(
std::ostream&,
const bool binary,
const GeometricField<Type, pointPatchField, pointMesh>&,
const vtkMesh&
);
//- Write interpolated field on points and original cell values on
// decomposed cell centres.
template<class Type>
static void write
(
std::ostream&,
const bool binary,
const GeometricField<Type, fvPatchField, volMesh>&,
const GeometricField<Type, pointPatchField, pointMesh>&,
const vtkMesh&
);
//- Write generic GeometricFields
template<class Type, template<class> class PatchField, class GeoMesh>
static void write
(
std::ostream&,
const bool binary,
const PtrList<GeometricField<Type, PatchField, GeoMesh> >&,
const vtkMesh&
);
//- Interpolate and write volFields
template<class Type>
static void write
(
std::ostream&,
const bool binary,
const volPointInterpolation&,
const PtrList<GeometricField<Type, fvPatchField, volMesh> >&,
const vtkMesh&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "writeFunsTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,192 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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 "writeFuns.H"
#include "interpolatePointToCell.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Store List in dest
template<class Type>
void Foam::writeFuns::insert
(
const List<Type>& source,
DynamicList<floatScalar>& dest
)
{
forAll(source, i)
{
insert(source[i], dest);
}
}
//// Store List (indexed through map) in dest
//template<class Type>
//void Foam::writeFuns::insert
//(
// const labelList& map,
// const List<Type>& source,
// DynamicList<floatScalar>& dest
//)
//{
// forAll(map, i)
// {
// insert(source[map[i]], dest);
// }
//}
template<class Type>
void Foam::writeFuns::write
(
std::ostream& os,
const bool binary,
const GeometricField<Type, fvPatchField, volMesh>& vvf,
const vtkMesh& vMesh
)
{
const fvMesh& mesh = vMesh.mesh();
const labelList& superCells = vMesh.topo().superCells();
label nValues = mesh.nCells() + superCells.size();
os << vvf.name() << ' ' << pTraits<Type>::nComponents << ' '
<< nValues << " float" << std::endl;
DynamicList<floatScalar> fField(pTraits<Type>::nComponents*nValues);
insert(vvf.internalField(), fField);
forAll(superCells, superCellI)
{
label origCellI = superCells[superCellI];
insert(vvf[origCellI], fField);
}
write(os, binary, fField);
}
template<class Type>
void Foam::writeFuns::write
(
std::ostream& os,
const bool binary,
const GeometricField<Type, pointPatchField, pointMesh>& pvf,
const vtkMesh& vMesh
)
{
const fvMesh& mesh = vMesh.mesh();
const vtkTopo& topo = vMesh.topo();
const labelList& addPointCellLabels = topo.addPointCellLabels();
const label nTotPoints = mesh.nPoints() + addPointCellLabels.size();
os << pvf.name() << ' ' << pTraits<Type>::nComponents << ' '
<< nTotPoints << " float" << std::endl;
DynamicList<floatScalar> fField(pTraits<Type>::nComponents*nTotPoints);
insert(pvf, fField);
forAll(addPointCellLabels, api)
{
label origCellI = addPointCellLabels[api];
insert(interpolatePointToCell(pvf, origCellI), fField);
}
write(os, binary, fField);
}
template<class Type>
void Foam::writeFuns::write
(
std::ostream& os,
const bool binary,
const GeometricField<Type, fvPatchField, volMesh>& vvf,
const GeometricField<Type, pointPatchField, pointMesh>& pvf,
const vtkMesh& vMesh
)
{
const fvMesh& mesh = vMesh.mesh();
const vtkTopo& topo = vMesh.topo();
const labelList& addPointCellLabels = topo.addPointCellLabels();
const label nTotPoints = mesh.nPoints() + addPointCellLabels.size();
os << vvf.name() << ' ' << pTraits<Type>::nComponents << ' '
<< nTotPoints << " float" << std::endl;
DynamicList<floatScalar> fField(pTraits<Type>::nComponents*nTotPoints);
insert(pvf, fField);
forAll(addPointCellLabels, api)
{
label origCellI = addPointCellLabels[api];
insert(vvf[origCellI], fField);
}
write(os, binary, fField);
}
template<class Type, template<class> class PatchField, class GeoMesh>
void Foam::writeFuns::write
(
std::ostream& os,
const bool binary,
const PtrList<GeometricField<Type, PatchField, GeoMesh> >& flds,
const vtkMesh& vMesh
)
{
forAll(flds, i)
{
write(os, binary, flds[i], vMesh);
}
}
template<class Type>
void Foam::writeFuns::write
(
std::ostream& os,
const bool binary,
const volPointInterpolation& pInterp,
const PtrList<GeometricField<Type, fvPatchField, volMesh> >& flds,
const vtkMesh& vMesh
)
{
forAll(flds, i)
{
write(os, binary, flds[i], pInterp.interpolate(flds[i])(), vMesh);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,103 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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 "writePointSet.H"
#include "OFstream.H"
#include "writeFuns.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
void writePointSet
(
const bool binary,
const vtkMesh& vMesh,
const pointSet& set,
const fileName& fileName
)
{
std::ofstream ostr(fileName.c_str());
writeFuns::writeHeader
(
ostr,
binary,
set.name()
);
ostr<< "DATASET POLYDATA" << std::endl;
//------------------------------------------------------------------
//
// Write topology
//
//------------------------------------------------------------------
// Write points
ostr<< "POINTS " << set.size() << " float" << std::endl;
DynamicList<floatScalar> ptField(3*set.size());
writeFuns::insert
(
UIndirectList<point>(vMesh.mesh().points(), set.toc())(),
ptField
);
writeFuns::write(ostr, binary, ptField);
//-----------------------------------------------------------------
//
// Write data
//
//-----------------------------------------------------------------
// Write faceID
ostr
<< "POINT_DATA " << set.size() << std::endl
<< "FIELD attributes 1" << std::endl;
// Cell ids first
ostr<< "pointID 1 " << set.size() << " int" << std::endl;
labelList pointIDs(set.toc());
writeFuns::write(ostr, binary, pointIDs);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,63 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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/>.
InClass
Foam::writePointSet
Description
Write pointSet to vtk polydata file. Only one data which is original
pointID.
SourceFiles
writePointSet.C
\*---------------------------------------------------------------------------*/
#ifndef writePointSet_H
#define writePointSet_H
#include "vtkMesh.H"
#include "pointSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Write lagrangian fields.
void writePointSet
(
const bool binary,
const vtkMesh& vMesh,
const pointSet& set,
const fileName& fileName
);
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,124 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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 "writeSurfFields.H"
#include "OFstream.H"
#include "floatScalar.H"
#include "writeFuns.H"
#include "emptyFvsPatchFields.H"
#include "fvsPatchFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
void writeSurfFields
(
const bool binary,
const vtkMesh& vMesh,
const fileName& fileName,
const PtrList<surfaceVectorField>& surfVectorFields
)
{
const fvMesh& mesh = vMesh.mesh();
std::ofstream str(fileName.c_str());
writeFuns::writeHeader
(
str,
binary,
"surfaceFields"
);
str << "DATASET POLYDATA" << std::endl;
const pointField& fc = mesh.faceCentres();
str << "POINTS " << mesh.nFaces() << " float" << std::endl;
DynamicList<floatScalar> pField(3*mesh.nFaces());
for (label faceI = 0; faceI < mesh.nFaces(); faceI++)
{
writeFuns::insert(fc[faceI], pField);
}
writeFuns::write(str, binary, pField);
str << "POINT_DATA " << mesh.nFaces() << std::endl
<< "FIELD attributes " << surfVectorFields.size() << std::endl;
// surfVectorFields
forAll(surfVectorFields, fieldI)
{
const surfaceVectorField& svf = surfVectorFields[fieldI];
str << svf.name() << " 3 "
<< mesh.nFaces() << " float" << std::endl;
DynamicList<floatScalar> fField(3*mesh.nFaces());
for (label faceI = 0; faceI < mesh.nInternalFaces(); faceI++)
{
writeFuns::insert(svf[faceI], fField);
}
forAll(svf.boundaryField(), patchI)
{
const fvsPatchVectorField& pf = svf.boundaryField()[patchI];
const fvPatch& pp = mesh.boundary()[patchI];
if (isA<emptyFvsPatchVectorField>(pf))
{
// Note: loop over polypatch size, not fvpatch size.
forAll(pp.patch(), i)
{
writeFuns::insert(vector::zero, fField);
}
}
else
{
forAll(pf, i)
{
writeFuns::insert(pf[i], fField);
}
}
}
writeFuns::write(str, binary, fField);
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -0,0 +1,63 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 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/>.
InClass
Foam::writeSurfFields
Description
Write a patch with its data.
SourceFiles
writeSurfFields.C
\*---------------------------------------------------------------------------*/
#ifndef writeSurfFields_H
#define writeSurfFields_H
#include "vtkMesh.H"
#include "surfaceMesh.H"
#include "surfaceFieldsFwd.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Write surface vector fields
void writeSurfFields
(
const bool binary,
const vtkMesh& vMesh,
const fileName& fileName,
const PtrList<surfaceVectorField>& surfVectorFields
);
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //