Commit 3dd1a13b authored by Mark Olesen's avatar Mark Olesen

ENH: restructuring of ensight output files

- changed ensightOutput from a class solely comprising static methods to
  a namespace and added in sub-namespaces Detail and Serial.

  This makes it easier to "mix-in" functions at different levels.
  Refactored and combined some serial/parallel code where possible.

  The general ensightOutput namespace has now shifted to be in the
  fileFormats lib, while leaving volField outputs in the conversion lib
  and cloud outputs in the lagrangian-intermediate lib.

  The ensightCloud namespace is now simply folded into the new
  ensightOutput namespace.

  These changes clean up some code, reduce fragmentation and
  duplication and removes the previous libconversion dependency for
  sampling.

- use int for ensight nTypes constexpr

Note: issue #1176 is unaffected except for the change in file name:

   ensightOutputTemplates.C -> ensightOutputVolFieldTemplates.C
parent 9042bc2b
...@@ -56,7 +56,7 @@ if (doLagrangian) ...@@ -56,7 +56,7 @@ if (doLagrangian)
{ {
autoPtr<ensightFile> os = ensCase.newCloud(cloudName); autoPtr<ensightFile> os = ensCase.newCloud(cloudName);
ensightCloud::writePositions ensightOutput::writeCloudPositions
( (
mesh, mesh,
cloudName, cloudName,
...@@ -104,7 +104,7 @@ if (doLagrangian) ...@@ -104,7 +104,7 @@ if (doLagrangian)
autoPtr<ensightFile> os = autoPtr<ensightFile> os =
ensCase.newCloudData<scalar>(cloudName, fieldName); ensCase.newCloudData<scalar>(cloudName, fieldName);
wrote = ensightCloud::writeCloudField<scalar> wrote = ensightOutput::writeCloudField<scalar>
( (
fieldObject, fieldExists, os fieldObject, fieldExists, os
); );
...@@ -114,7 +114,7 @@ if (doLagrangian) ...@@ -114,7 +114,7 @@ if (doLagrangian)
autoPtr<ensightFile> os = autoPtr<ensightFile> os =
ensCase.newCloudData<vector>(cloudName, fieldName); ensCase.newCloudData<vector>(cloudName, fieldName);
wrote = ensightCloud::writeCloudField<vector> wrote = ensightOutput::writeCloudField<vector>
( (
fieldObject, fieldExists, os fieldObject, fieldExists, os
); );
......
...@@ -99,8 +99,8 @@ Note ...@@ -99,8 +99,8 @@ Note
#include "ensightCase.H" #include "ensightCase.H"
#include "ensightGeoFile.H" #include "ensightGeoFile.H"
#include "ensightMesh.H" #include "ensightMesh.H"
#include "ensightOutput.H"
#include "ensightOutputCloud.H" #include "ensightOutputCloud.H"
#include "ensightOutputVolField.H"
#include "fvMeshSubsetProxy.H" #include "fvMeshSubsetProxy.H"
// local files // local files
......
...@@ -62,11 +62,11 @@ bool writeVolField ...@@ -62,11 +62,11 @@ bool writeVolField
autoPtr<ensightFile> os = ensCase.newData<Type>(field.name()); autoPtr<ensightFile> os = ensCase.newData<Type>(field.name());
bool wrote = ensightOutput::writeField<Type> bool wrote = ensightOutput::writeVolField<Type>
( (
field, field,
ensMesh, ensMesh,
os, os.ref(),
nodeValues nodeValues
); );
......
...@@ -55,7 +55,7 @@ if (doLagrangian) ...@@ -55,7 +55,7 @@ if (doLagrangian)
{ {
autoPtr<ensightFile> os = ensCase.newCloud(cloudName); autoPtr<ensightFile> os = ensCase.newCloud(cloudName);
ensightCloud::writePositions ensightOutput::writeCloudPositions
( (
mesh, mesh,
cloudName, cloudName,
...@@ -103,7 +103,7 @@ if (doLagrangian) ...@@ -103,7 +103,7 @@ if (doLagrangian)
autoPtr<ensightFile> os = autoPtr<ensightFile> os =
ensCase.newCloudData<scalar>(cloudName, fieldName); ensCase.newCloudData<scalar>(cloudName, fieldName);
wrote = ensightCloud::writeCloudField<scalar> wrote = ensightOutput::writeCloudField<scalar>
( (
fieldObject, fieldExists, os fieldObject, fieldExists, os
); );
...@@ -113,7 +113,7 @@ if (doLagrangian) ...@@ -113,7 +113,7 @@ if (doLagrangian)
autoPtr<ensightFile> os = autoPtr<ensightFile> os =
ensCase.newCloudData<vector>(cloudName, fieldName); ensCase.newCloudData<vector>(cloudName, fieldName);
wrote = ensightCloud::writeCloudField<vector> wrote = ensightOutput::writeCloudField<vector>
( (
fieldObject, fieldExists, os fieldObject, fieldExists, os
); );
......
...@@ -94,8 +94,8 @@ Note ...@@ -94,8 +94,8 @@ Note
#include "ensightCase.H" #include "ensightCase.H"
#include "ensightGeoFile.H" #include "ensightGeoFile.H"
#include "ensightParts.H" #include "ensightParts.H"
#include "ensightSerialOutput.H"
#include "ensightOutputCloud.H" #include "ensightOutputCloud.H"
#include "ensightOutputVolField.H"
#include "fvMeshSubsetProxy.H" #include "fvMeshSubsetProxy.H"
// local files // local files
......
...@@ -61,11 +61,12 @@ bool writeVolField ...@@ -61,11 +61,12 @@ bool writeVolField
autoPtr<ensightFile> os = ensCase.newData<Type>(field.name()); autoPtr<ensightFile> os = ensCase.newData<Type>(field.name());
bool wrote = ensightSerialOutput::writeField<Type> // Currently serial only
bool wrote = ensightOutput::Serial::writeVolField<Type>
( (
field, field,
ensParts, ensParts,
os os.ref()
); );
tfield.clear(); tfield.clear();
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -21,25 +21,22 @@ License ...@@ -21,25 +21,22 @@ License
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class InNamespace
Foam::ensightSerialOutput Foam::ensightOutput
Description Description
A collection of functions for writing ensight file content in serial. A collection of functions for writing volField content in ensight format.
Can be considered transitional and may eventually merge with ensightOutput.
SourceFiles
ensightSerialOutputTemplates.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef ensightSerialOutput_H #ifndef ensightOutputVolField_H
#define ensightSerialOutput_H #define ensightOutputVolField_H
#include "ensightOutput.H"
#include "ensightPart.H" #include "ensightPart.H"
#include "ensightParts.H"
#include "ensightPartFaces.H" #include "ensightPartFaces.H"
#include "ensightPartCells.H" #include "ensightPartCells.H"
#include "ensightParts.H"
#include "volFields.H" #include "volFields.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
...@@ -47,98 +44,103 @@ SourceFiles ...@@ -47,98 +44,103 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declarations
class ensightMesh;
namespace ensightOutput
{
/*---------------------------------------------------------------------------*\
Namespace ensightOutput::Detail
\*---------------------------------------------------------------------------*/
namespace Detail
{
//- Write volume field component-wise
template<class Type>
bool writeVolField
(
const GeometricField<Type, fvPatchField, volMesh>& vf,
const ensightMesh& ensMesh,
ensightFile& os
);
//- Write point field component-wise
template<class Type>
bool writePointField
(
const GeometricField<Type, pointPatchField, pointMesh>& pf,
const ensightMesh& ensMesh,
ensightFile& os
);
} // End namespace Detail
/*---------------------------------------------------------------------------*\
Namespace ensightOutput
\*---------------------------------------------------------------------------*/
//- Write volume field component-wise
template<class Type>
bool writeVolField
(
const GeometricField<Type, fvPatchField, volMesh>&,
const ensightMesh& ensMesh,
ensightFile& os,
const bool nodeValues = false
);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class ensightSerialOutput Declaration Namespace ensightOutput::Serial
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class ensightSerialOutput namespace Serial
{ {
// Private Methods
//- Write volume field component-wise for specified faces
//- Write field content (component-wise) for the given ensight element type template<class Type>
template<template<typename> class FieldContainer, class Type> bool writeVolField
static void writeFieldContent (
( const GeometricField<Type, fvPatchField, volMesh>& vf,
const word& key, const ensightPartFaces& part,
const FieldContainer<Type>& fld, ensightFile& os
ensightFile& os );
);
//- No null constructor //- Write volume field component-wise for specified cells
ensightSerialOutput() = delete; template<class Type>
bool writeVolField
(
public: const GeometricField<Type, fvPatchField, volMesh>& vf,
const ensightPartCells& part,
// Public Methods ensightFile& os
);
//- Write field component-wise
template<class Type>
static bool writeField //- Write volume field component-wise
( template<class Type>
const Field<Type>&, bool writeVolField
const ensightPartFaces& part, (
ensightFile& os, const GeometricField<Type, fvPatchField, volMesh>& vf,
const bool nodeValues const ensightParts& list,
); ensightFile& os
);
//- Write volume field component-wise } // End namespace Serial
template<class Type>
static bool writeField
(
const GeometricField<Type, fvPatchField, volMesh>&,
const ensightPartCells& part,
ensightFile& os
);
//- Write volume field component-wise
template<class Type>
static bool writeField
(
const GeometricField<Type, fvPatchField, volMesh>&,
const ensightParts& list,
ensightFile& os
);
//- Write volume field component-wise
template<class Type>
static inline bool writeField
(
const GeometricField<Type, fvPatchField, volMesh>& vf,
const ensightPartCells& part,
autoPtr<ensightFile>& output
)
{
return writeField(vf, part, output.ref());
}
//- Write volume field component-wise
template<class Type>
static inline bool writeField
(
const GeometricField<Type, fvPatchField, volMesh>& vf,
const ensightParts& list,
autoPtr<ensightFile>& output
)
{
return writeField(vf, list, output.ref());
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace ensightOutput
} // End namespace Foam } // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository #ifdef NoRepository
#include "ensightSerialOutputTemplates.C" #include "ensightOutputVolFieldTemplates.C"
#endif #endif
#endif #endif
......
...@@ -23,191 +23,29 @@ License ...@@ -23,191 +23,29 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "ensightFile.H" #include "ensightOutputVolField.H"
#include "ensightOutput.H" #include "ensightMesh.H"
#include "ensightPTraits.H"
#include "fvMesh.H" #include "fvMesh.H"
#include "volFields.H"
#include "IOField.H"
#include "OFstream.H"
#include "IOmanip.H"
#include "Time.H"
#include "volPointInterpolation.H"
#include "globalIndex.H" #include "globalIndex.H"
#include "uindirectPrimitivePatch.H" #include "volPointInterpolation.H"
#include "interpolation.H" #include "interpolation.H"
#include "linear.H" #include "linear.H"
#include "processorFvPatch.H" #include "processorFvPatch.H"
#include "uindirectPrimitivePatch.H"
// * * * * * * * * * * Static Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Detail * * * * * * * * * * * * * * * * * //
template<template<typename> class FieldContainer, class Type>
void Foam::ensightOutput::writeFieldContent
(
const char* key,
const FieldContainer<Type>& fld,
ensightFile& os
)
{
if (returnReduce(fld.size(), sumOp<label>()) > 0)
{
if (Pstream::master())
{
os.writeKeyword(key);
for (direction d=0; d < pTraits<Type>::nComponents; ++d)
{
const label cmpt = ensightPTraits<Type>::componentOrder[d];
os.writeList(fld.component(cmpt));
for (int slave=1; slave<Pstream::nProcs(); ++slave)
{
IPstream fromSlave(Pstream::commsTypes::scheduled, slave);
scalarField received(fromSlave);
os.writeList(received);
}
}
}
else
{
for (direction d=0; d < pTraits<Type>::nComponents; ++d)
{
const label cmpt = ensightPTraits<Type>::componentOrder[d];
OPstream toMaster
(
Pstream::commsTypes::scheduled,
Pstream::masterNo()
);
toMaster
<< fld.component(cmpt);
}
}
}
}
template<class Type>
bool Foam::ensightOutput::writeFaceField
(
const Field<Type>& pf,
const ensightFaces& ensFaces,
Foam::ensightFile& os
)
{
if (ensFaces.total())
{
if (Pstream::master())
{
os.beginPart(ensFaces.index());
}
for (label typei=0; typei < ensightFaces::nTypes; ++typei)
{
const ensightFaces::elemType what =
ensightFaces::elemType(typei);
writeFieldContent
(
ensightFaces::key(what),
Field<Type>(pf, ensFaces.faceIds(what)),
os
);
}
return true;
}
return false;
}
template<class Type>
bool Foam::ensightOutput::writeFaceSubField
(
const Field<Type>& pf,
const ensightFaces& ensFaces,
Foam::ensightFile& os
)
{
if (ensFaces.total())
{
if (Pstream::master())
{
os.beginPart(ensFaces.index());
}
label start = 0; // start of sublist
for (label typei=0; typei < ensightFaces::nTypes; ++typei)
{
const ensightFaces::elemType what =
ensightFaces::elemType(typei);
const label size = ensFaces.faceIds(what).size();
writeFieldContent
(
ensightFaces::key(what),
SubField<Type>(pf, size, start),
os
);
start += size; // start of next sublist
}
return true;
}
return false;
}
template<class Type>
bool Foam::ensightOutput::writeCellField
(
const Field<Type>& vf,
const ensightCells& ensCells,
ensightFile& os
)
{
if (ensCells.total())
{
if (Pstream::master())
{
os.beginPart(ensCells.index());
}
for (label typei=0; typei < ensightCells::nTypes; ++typei)
{
const ensightCells::elemType what =
ensightCells::elemType(typei);
writeFieldContent
(
ensightCells::key(what),
Field<Type>(vf, ensCells.cellIds(what)),
os
);
}
return true;
}