ENH: Ensight output for sampledSurfaces

This commit is contained in:
mattijs
2010-11-09 18:04:32 +00:00
parent b3e023bda2
commit 0db9fa5702
18 changed files with 593 additions and 12 deletions

View File

@ -27,6 +27,7 @@ setFormat raw;
// Surface output format. Choice of
// null : suppress output
// ensight : Ensight Gold format, one field per case file
// foamFile : separate points, faces and values file
// dx : DX scalar or vector format
// vtk : VTK ascii format

View File

@ -46,6 +46,7 @@ surfWriters = sampledSurface/writers
$(surfWriters)/surfaceWriters.C
$(surfWriters)/dx/dxSurfaceWriterRunTime.C
$(surfWriters)/ensight/ensightSurfaceWriterRunTime.C
$(surfWriters)/foamFile/foamFileSurfaceWriterRunTime.C
$(surfWriters)/null/nullSurfaceWriterRunTime.C
$(surfWriters)/proxy/proxySurfaceWriterRunTime.C

View File

@ -103,7 +103,8 @@ void Foam::sampledSurfaces::sampleAndWrite
mergeList_[surfI].points,
mergeList_[surfI].faces,
fieldName,
allValues
allValues,
s.interpolate()
);
}
}
@ -121,7 +122,8 @@ void Foam::sampledSurfaces::sampleAndWrite
s.points(),
s.faces(),
fieldName,
values
values,
s.interpolate()
);
}
}

View File

@ -250,6 +250,7 @@ void Foam::dxSurfaceWriter<Type>::write
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose
) const
{
@ -272,7 +273,7 @@ void Foam::dxSurfaceWriter<Type>::write
writeData(os, values);
if (values.size() == points.size())
if (isNodeValues)
{
os << nl << "attribute \"dep\" string \"positions\""
<< nl << nl;

View File

@ -88,6 +88,7 @@ public:
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose = false
) const;
};

View File

@ -0,0 +1,372 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2010-2010 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 "ensightSurfaceWriter.H"
#include "OFstream.H"
#include "OSspecific.H"
#include "IOmanip.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
void Foam::ensightSurfaceWriter<Type>::binShapes
(
const pointField& points,
const faceList& faces,
DynamicList<label>& tris,
DynamicList<label>& quads,
DynamicList<label>& polys
)
{
tris.setCapacity(faces.size());
quads.setCapacity(faces.size());
polys.setCapacity(faces.size());
forAll(faces, i)
{
const face& f = faces[i];
if (f.size() == 3)
{
tris.append(i);
}
else if (f.size() == 4)
{
quads.append(i);
}
else
{
polys.append(i);
}
}
}
template<class Type>
void Foam::ensightSurfaceWriter<Type>::writeGeometry
(
const fileName& surfaceName,
Ostream& os,
const pointField& points,
const faceList& faces,
const DynamicList<label>& tris,
const DynamicList<label>& quads,
const DynamicList<label>& polys
)
{
os << "EnSight Geometry File" << nl
<< (string("written by OpenFOAM-") + Foam::FOAMversion).c_str() << nl
<< "node id assign" << nl
<< "element id assign" << nl
<< "part" << nl
<< setw(10) << 1 << nl
<< surfaceName.c_str() << nl;
os << "coordinates" << nl
<< setw(10) << points.size() << nl;
for (direction cmpt = 0; cmpt < vector::nComponents; cmpt++)
{
scalarField v = points.component(cmpt);
forAll(v, i)
{
os << v[i] << nl;
}
}
if (tris.size())
{
os << "tria3" << nl
<< setw(10) << tris.size() << nl;
forAll(tris, i)
{
const face& f = faces[tris[i]];
forAll(f, fp)
{
os << setw(10) << f[fp]+1;
}
os << nl;
}
}
if (quads.size())
{
os << "quad4" << nl
<< setw(10) << quads.size() << nl;
forAll(quads, i)
{
const face& f = faces[quads[i]];
forAll(f, fp)
{
os << setw(10) << f[fp]+1;
}
os << nl;
}
}
if (polys.size())
{
os << "nsided" << nl
<< setw(10) << polys.size() << nl;
forAll(polys, i)
{
const face& f = faces[polys[i]];
forAll(f, fp)
{
os << setw(10) << f[fp]+1;
}
os << nl;
}
}
}
namespace Foam
{
// Write scalarField in ensight format
template<>
void Foam::ensightSurfaceWriter<Foam::scalar>::writeData
(
Ostream& os,
const Field<Foam::scalar>& values
)
{
forAll(values, i)
{
os << values[i] << nl;
}
}
// Write booField in ensight format
template<>
void Foam::ensightSurfaceWriter<bool>::writeData
(
Ostream& os,
const Field<bool>& values
)
{
forAll(values, i)
{
os << values[i] << nl;
}
}
}
// Write generic field in ensight format
template<class Type>
void Foam::ensightSurfaceWriter<Type>::writeData
(
Ostream& os,
const Field<Type>& values
)
{
for (direction cmpt = 0; cmpt < vector::nComponents; cmpt++)
{
scalarField v = values.component(cmpt);
forAll(v, i)
{
os << v[i] << nl;
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
template<class Type>
Foam::ensightSurfaceWriter<Type>::ensightSurfaceWriter()
:
surfaceWriter<Type>()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::ensightSurfaceWriter<Type>::~ensightSurfaceWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::ensightSurfaceWriter<Type>::write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const bool verbose
) const
{
if (!isDir(outputDir))
{
mkDir(outputDir);
}
//const scalar timeValue = Foam::name(this->mesh().time().timeValue());
const scalar timeValue = 0.0;
OFstream caseStr(outputDir/surfaceName + ".case");
OFstream geomStr(outputDir/surfaceName + ".***.mesh");
if (verbose)
{
Info<< "Writing case file to " << caseStr.name() << endl;
}
caseStr
<< "FORMAT" << nl
<< "type: ensight gold" << nl
<< nl
<< "GEOMETRY" << nl
<< "model: 1 " << geomStr.name().name() << nl
<< nl
<< "TIME" << nl
<< "time set: 1" << nl
<< "number of steps: 1" << nl
<< "filename start number: 0" << nl
<< "filename increment: 1" << nl
<< "time values:" << nl
<< timeValue << nl
<< nl;
DynamicList<label> tris;
DynamicList<label> quads;
DynamicList<label> polys;
binShapes(points, faces, tris, quads, polys);
writeGeometry(surfaceName, geomStr, points, faces, tris, quads, polys);
}
template<class Type>
void Foam::ensightSurfaceWriter<Type>::write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose
) const
{
if (!isDir(outputDir/fieldName))
{
mkDir(outputDir/fieldName);
}
//const scalar timeValue = Foam::name(this->mesh().time().timeValue());
const scalar timeValue = 0.0;
OFstream caseStr(outputDir/fieldName/surfaceName + ".case");
OFstream geomStr(outputDir/fieldName/surfaceName + ".000.mesh");
OFstream fieldStr(outputDir/fieldName/surfaceName + ".000." + fieldName);
if (verbose)
{
Info<< "Writing case file to " << caseStr.name() << endl;
}
caseStr
<< "FORMAT" << nl
<< "type: ensight gold" << nl
<< nl
<< "GEOMETRY" << nl
<< "model: 1 " << geomStr.name().name() << nl
<< nl
<< "VARIABLE" << nl;
if (isNodeValues)
{
caseStr
<< pTraits<Type>::typeName << " per node:" << setw(10) << 1
<< " " << fieldName
<< " " << surfaceName.c_str() << ".***." << fieldName << nl;
}
else
{
caseStr
<< pTraits<Type>::typeName << " per element:" << setw(10) << 1
<< " " << fieldName
<< " " << surfaceName.c_str() << ".***." << fieldName << nl;
}
caseStr
<< nl
<< "TIME" << nl
<< "time set: 1" << nl
<< "number of steps: 1" << nl
<< "filename start number: 0" << nl
<< "filename increment: 1" << nl
<< "time values:" << nl
<< timeValue << nl
<< nl;
DynamicList<label> tris;
DynamicList<label> quads;
DynamicList<label> polys;
binShapes(points, faces, tris, quads, polys);
writeGeometry(surfaceName, geomStr, points, faces, tris, quads, polys);
// Write field
fieldStr
<< pTraits<Type>::typeName << nl
<< "part" << nl
<< setw(10) << 1 << nl;
if (isNodeValues)
{
fieldStr << "coordinates" << nl;
writeData(fieldStr, values);
}
else
{
if (tris.size())
{
fieldStr << "tria3" << nl;
writeData(fieldStr, Field<Type>(values, tris));
}
if (quads.size())
{
fieldStr << "quad4" << nl;
writeData(fieldStr, Field<Type>(values, quads));
}
if (polys.size())
{
fieldStr << "nsided" << nl;
writeData(fieldStr, Field<Type>(values, polys));
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,138 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2010-2010 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/>.
Class
Foam::ensightSurfaceWriter
Description
SourceFiles
ensightSurfaceWriter.C
\*---------------------------------------------------------------------------*/
#ifndef ensightSurfaceWriter_H
#define ensightSurfaceWriter_H
#include "surfaceWriter.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class ensightSurfaceWriter Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class ensightSurfaceWriter
:
public surfaceWriter<Type>
{
// Private Member Functions
static void binShapes
(
const pointField& points,
const faceList& faces,
DynamicList<label>& tris,
DynamicList<label>& quads,
DynamicList<label>& polys
);
static void writeGeometry
(
const fileName&,
Ostream&,
const pointField&,
const faceList&,
const DynamicList<label>&,
const DynamicList<label>&,
const DynamicList<label>&
);
static void writeData(Ostream&, const Field<Type>& values);
public:
//- Runtime type information
TypeName("ensight");
// Constructors
//- Construct null
ensightSurfaceWriter();
//- Destructor
virtual ~ensightSurfaceWriter();
// Member Functions
// Write
//- Write geometry to file.
virtual void write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const bool verbose = false
) const;
//- Writes single surface to file.
virtual void write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose = false
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "ensightSurfaceWriter.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,44 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2010-2010 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 "ensightSurfaceWriter.H"
#include "surfaceWriters.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeSurfaceWriterType(ensightSurfaceWriter, bool);
makeSurfaceWriters(ensightSurfaceWriter);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -96,6 +96,7 @@ void Foam::foamFileSurfaceWriter<Type>::write
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose
) const
{

View File

@ -95,6 +95,7 @@ public:
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose = false
) const;
};

View File

@ -54,6 +54,7 @@ void Foam::nullSurfaceWriter<Type>::write
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose
) const
{}

View File

@ -80,6 +80,7 @@ public:
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose = false
) const;
};

View File

@ -102,6 +102,7 @@ public:
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose = false
) const
{}

View File

@ -68,6 +68,7 @@ void Foam::rawSurfaceWriter<Type>::writeData
const pointField& points,
const faceList& faces,
const scalarField& values,
const bool isNodeValues,
Ostream& os
)
{
@ -75,7 +76,7 @@ void Foam::rawSurfaceWriter<Type>::writeData
os << "# x y z " << fieldName << endl;
// Write data
if (values.size() == points.size())
if (isNodeValues)
{
forAll(values, elemI)
{
@ -104,6 +105,7 @@ void Foam::rawSurfaceWriter<Type>::writeData
const pointField& points,
const faceList& faces,
const vectorField& values,
const bool isNodeValues,
Ostream& os
)
{
@ -115,7 +117,7 @@ void Foam::rawSurfaceWriter<Type>::writeData
<< endl;
// Write data
if (values.size() == points.size())
if (isNodeValues)
{
forAll(values, elemI)
{
@ -147,6 +149,7 @@ void Foam::rawSurfaceWriter<Type>::writeData
const pointField& points,
const faceList& faces,
const sphericalTensorField& values,
const bool isNodeValues,
Ostream& os
)
{
@ -155,7 +158,7 @@ void Foam::rawSurfaceWriter<Type>::writeData
os << fieldName << "_ii" << endl;
// Write data
if (values.size() == points.size())
if (isNodeValues)
{
forAll(values, elemI)
{
@ -186,6 +189,7 @@ void Foam::rawSurfaceWriter<Type>::writeData
const pointField& points,
const faceList& faces,
const symmTensorField& values,
const bool isNodeValues,
Ostream& os
)
{
@ -198,7 +202,7 @@ void Foam::rawSurfaceWriter<Type>::writeData
os << endl;
// Write data
if (values.size() == points.size())
if (isNodeValues)
{
forAll(values, elemI)
{
@ -233,6 +237,7 @@ void Foam::rawSurfaceWriter<Type>::writeData
const pointField& points,
const faceList& faces,
const tensorField& values,
const bool isNodeValues,
Ostream& os
)
{
@ -245,7 +250,7 @@ void Foam::rawSurfaceWriter<Type>::writeData
os << endl;
// Write data
if (values.size() == points.size())
if (isNodeValues)
{
forAll(values, elemI)
{
@ -343,6 +348,7 @@ namespace Foam
const faceList& faces,
const word& fieldName,
const Field<bool>& values,
const bool isNodeValues,
const bool verbose
) const
{}
@ -358,6 +364,7 @@ void Foam::rawSurfaceWriter<Type>::write
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose
) const
{
@ -379,7 +386,7 @@ void Foam::rawSurfaceWriter<Type>::write
// header
os << "# " << fieldName;
if (values.size() == points.size())
if (isNodeValues)
{
os << " POINT_DATA ";
}
@ -390,7 +397,7 @@ void Foam::rawSurfaceWriter<Type>::write
os << values.size() << nl;
writeData(fieldName, points, faces, values, os);
writeData(fieldName, points, faces, values, isNodeValues, os);
}

View File

@ -73,6 +73,7 @@ class rawSurfaceWriter
const pointField& points,
const faceList& faces,
const scalarField& values,
const bool isNodeValues,
Ostream& os
);
@ -82,6 +83,7 @@ class rawSurfaceWriter
const pointField& points,
const faceList& faces,
const vectorField& values,
const bool isNodeValues,
Ostream& os
);
@ -91,6 +93,7 @@ class rawSurfaceWriter
const pointField& points,
const faceList& faces,
const sphericalTensorField& values,
const bool isNodeValues,
Ostream& os
);
@ -100,6 +103,7 @@ class rawSurfaceWriter
const pointField& points,
const faceList& faces,
const symmTensorField& values,
const bool isNodeValues,
Ostream& os
);
@ -109,6 +113,7 @@ class rawSurfaceWriter
const pointField& points,
const faceList& faces,
const tensorField& values,
const bool isNodeValues,
Ostream& os
);
@ -152,6 +157,7 @@ public:
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose = false
) const;
};

View File

@ -119,7 +119,7 @@ public:
//- Writes single surface to file. Either one value per vertex or
// one value per face (detected by values.size()==faces.size())
// one value per face (isNodeValues = false)
virtual void write
(
const fileName& outputDir, // <root>/<case>/surface/TIME
@ -128,6 +128,7 @@ public:
const faceList& faces,
const word& fieldName, // name of field
const Field<Type>& values,
const bool isNodeValues,
const bool verbose = false
) const = 0;
};

View File

@ -267,6 +267,7 @@ void Foam::vtkSurfaceWriter<Type>::write
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose
) const
{
@ -288,7 +289,7 @@ void Foam::vtkSurfaceWriter<Type>::write
writeGeometry(os, points, faces);
// start writing data
if (values.size() == points.size())
if (isNodeValues)
{
os << "POINT_DATA ";
}

View File

@ -97,6 +97,7 @@ public:
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose = false
) const;
};