ENH: -exclude-fields, -no-fields options for foamToEnsight, foamToVTK

- additional verbosity option for conversions

- ignore old `-finite-area` option and always convert available
  finiteArea mesh/fields unless `-no-finite-area` is specified (#2374)

ENH: simplify point offset handling for ensight output

- extend writing to include compact face/cell lists
This commit is contained in:
Mark Olesen
2022-03-07 15:15:21 +01:00
parent 730ce92b68
commit c4d4becbac
28 changed files with 642 additions and 240 deletions

View File

@ -110,7 +110,8 @@ Foam::ensightMesh::ensightMesh
:
options_(new options(opts)),
mesh_(mesh),
needsUpdate_(true)
needsUpdate_(true),
verbose_(0)
{
if (!option().lazy())
{
@ -121,6 +122,20 @@ Foam::ensightMesh::ensightMesh
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
int Foam::ensightMesh::verbose() const noexcept
{
return verbose_;
}
int Foam::ensightMesh::verbose(const int level) noexcept
{
int old(verbose_);
verbose_ = level;
return old;
}
void Foam::ensightMesh::correct()
{
clear();
@ -214,6 +229,10 @@ void Foam::ensightMesh::correct()
// Finalize
part.reduce();
if (verbose_)
{
Info<< part.info();
}
}
}
@ -235,6 +254,10 @@ void Foam::ensightMesh::correct()
// Finalize
part.reduce();
if (verbose_)
{
Info<< part.info();
}
}
else
{
@ -253,6 +276,10 @@ void Foam::ensightMesh::correct()
// Finalize
part.reduce();
if (verbose_)
{
Info<< part.info();
}
}
}
@ -345,7 +372,10 @@ void Foam::ensightMesh::correct()
// Finalize
part.reduce();
if (verbose_)
{
Info<< part.info();
}
if (!part.total())
{
boundaryParts_.erase(patchId);
@ -379,7 +409,10 @@ void Foam::ensightMesh::correct()
// Finalize
part.reduce();
if (verbose_)
{
Info<< part.info();
}
if (!part.total())
{
faceZoneParts_.erase(zoneId);

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -57,8 +57,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef ensightMesh_H
#define ensightMesh_H
#ifndef Foam_ensightMesh_H
#define Foam_ensightMesh_H
#include "Map.H"
#include "ensightCells.H"
@ -114,6 +114,9 @@ private:
//- Track if it needs an update
mutable bool needsUpdate_;
//- Output verbosity level
int verbose_;
// Private Member Functions
@ -143,6 +146,14 @@ public:
// Member Functions
//- Output verbosity level
int verbose() const noexcept;
//- Change the output verbosity level.
// \return old level
int verbose(const int level) noexcept;
// Access
//- Reference to the underlying polyMesh

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,7 +26,6 @@ License
\*---------------------------------------------------------------------------*/
#include "ensightOutput.H"
#include "cell.H"
#include "cellShape.H"
#include "face.H"
@ -133,20 +132,29 @@ Foam::labelList Foam::ensightOutput::Detail::getPolysNPointsPerFace
}
void Foam::ensightOutput::writeFaceList
void Foam::ensightOutput::Detail::writeLabelListList
(
ensightGeoFile& os,
const UList<face>& faces
const labelUList& offsets,
const labelUList& values,
const label pointOffset
)
{
for (const face& f : faces)
{
for (const label labi : f)
{
os.write(labi + 1);
}
const label off = (pointOffset + 1); // 1-based for Ensight
os.newline();
const label nLists = (offsets.size() - 1);
for (label i = 0; i < nLists; ++i)
{
const labelUList list
(
values.slice(offsets[i], (offsets[i+i] - offsets[i]))
);
for (const label pointi : list)
{
os.write(pointi + off);
}
os.newline(); // One list (cell/faces) per line (ASCII)
}
}
@ -154,40 +162,119 @@ void Foam::ensightOutput::writeFaceList
void Foam::ensightOutput::writeFaceList
(
ensightGeoFile& os,
const UIndirectList<face>& faces
const UList<face>& faces,
const label pointOffset
)
{
for (const face& f : faces)
{
for (const label labi : f)
{
os.write(labi + 1);
}
ensightOutput::Detail::writeLabelListList(os, faces, pointOffset);
}
os.newline();
}
void Foam::ensightOutput::writeFaceList
(
ensightGeoFile& os,
const UIndirectList<face>& faces,
const label pointOffset
)
{
ensightOutput::Detail::writeLabelListList(os, faces, pointOffset);
}
void Foam::ensightOutput::writeFaceList
(
ensightGeoFile& os,
const CompactListList<label>& faces,
const label pointOffset
)
{
ensightOutput::Detail::writeLabelListList(os, faces, pointOffset);
}
void Foam::ensightOutput::writeCellShapes
(
ensightGeoFile& os,
const UList<cellShape>& shapes
const UList<cellShape>& shapes,
const label pointOffset
)
{
for (const cellShape& cellPoints : shapes)
ensightOutput::Detail::writeLabelListList(os, shapes, pointOffset);
}
Foam::CompactListList<Foam::label>
Foam::ensightOutput::Detail::getPolysFacePoints
(
const polyMesh& mesh,
const labelUList& addr,
const labelList& pointMap
)
{
const cellList& meshCells = mesh.cells();
const faceList& meshFaces = mesh.faces();
const labelList& owner = mesh.faceOwner();
// The caller should have already checked for possible overflow,
// so can skip that here.
// but still need the sizing for allocations
label nFaces = 0, nPoints = 0;
for (const label cellId : addr)
{
// Convert global -> local index
// (note: Ensight indices start with 1)
nFaces += meshCells[cellId].size();
// In ASCII, write one cell per line
for (const label pointi : cellPoints)
for (const label faceId : meshCells[cellId])
{
os.write(pointi + 1);
nPoints += meshFaces[faceId].size();
}
os.newline();
}
CompactListList<label> compact(nFaces, nPoints);
labelList& offsets = compact.offsets();
labelList& verts = compact.values();
// Restart counts
nFaces = nPoints = 0;
for (const label cellId : addr)
{
for (const label faceId : meshCells[cellId])
{
const face& f = meshFaces[faceId];
offsets[nFaces++] = nPoints;
if (faceId < owner.size() && owner[faceId] != cellId)
{
// The neighbour of an internal face
// - handle like face::reverseFace()
verts[nPoints++] = pointMap[f[0]];
for (label pti = f.size()-1; pti > 0; --pti)
{
verts[nPoints++] = pointMap[f[pti]];
}
}
else
{
for (const label pointi : f)
{
verts[nPoints++] = pointMap[pointi];
}
}
}
}
// Finally
if (nFaces)
{
offsets[nFaces] = nPoints;
}
return compact;
}
@ -203,6 +290,8 @@ void Foam::ensightOutput::writePolysPoints
const faceList& meshFaces = mesh.faces();
const labelList& owner = mesh.faceOwner();
const label off = (1); // 1-based for Ensight
for (const label cellId : addr)
{
for (const label faceId : meshCells[cellId])
@ -214,21 +303,21 @@ void Foam::ensightOutput::writePolysPoints
// The neighbour of an internal face
// - write as face::reverseFace()
os.write(pointMap[f[0]] + 1);
os.write(pointMap[f[0]] + off);
for (label pti = f.size()-1; pti > 0; --pti)
{
os.write(pointMap[f[pti]] + 1);
os.write(pointMap[f[pti]] + off);
}
}
else
{
for (const label pointi : f)
{
os.write(pointMap[pointi] + 1);
os.write(pointMap[pointi] + off);
}
}
os.newline();
os.newline(); // One face per line (ASCII)
}
}
}
@ -243,6 +332,8 @@ void Foam::ensightOutput::writePolysPoints
const labelUList& owner
)
{
const label off = (1); // 1-based for Ensight
for (const label cellId : addr)
{
for (const label faceId : meshCells[cellId])
@ -254,21 +345,21 @@ void Foam::ensightOutput::writePolysPoints
// The neighbour of an internal face
// - write as face::reverseFace()
os.write(f[0] + 1);
os.write(f[0] + off);
for (label pti = f.size()-1; pti > 0; --pti)
{
os.write(f[pti] + 1);
os.write(f[pti] + off);
}
}
else
{
for (const label pointi : f)
{
os.write(pointi + 1);
os.write(pointi + off);
}
}
os.newline();
os.newline(); // One face per line (ASCII)
}
}
}

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2021 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -35,8 +35,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef ensightOutput_H
#define ensightOutput_H
#ifndef Foam_ensightOutput_H
#define Foam_ensightOutput_H
#include "ensightFile.H"
#include "ensightGeoFile.H"
@ -50,6 +50,7 @@ SourceFiles
#include "ListOps.H"
#include "ListListOps.H"
#include "IndirectList.H"
#include "CompactListList.H"
#include "DynamicList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -127,21 +128,32 @@ namespace ensightOutput
void writeFaceList
(
ensightGeoFile& os,
const UList<face>& faces
const UList<face>& faces,
const label pointOffset = 0 //!< Additional point offset for each face
);
//- Write list of faces
//- Write list of faces (indirect addressing)
void writeFaceList
(
ensightGeoFile& os,
const UIndirectList<face>& faces
const UIndirectList<face>& faces,
const label pointOffset = 0 //!< Additional point offset for each face
);
//- Write list of faces (stored in compact form)
void writeFaceList
(
ensightGeoFile& os,
const CompactListList<label>& faces,
const label pointOffset = 0 //!< Additional point offset for each face
);
//- Write cell connectivity via cell shapes
void writeCellShapes
(
ensightGeoFile& os,
const UList<cellShape>& shapes
const UList<cellShape>& shapes,
const label pointOffset = 0 //!< Additional point offset
);
@ -260,6 +272,35 @@ labelList getPolysNFaces(const polyMesh& mesh, const labelUList& addr);
//- The number of points for each face of the poly elements
labelList getPolysNPointsPerFace(const polyMesh& mesh, const labelUList& addr);
//- Generate 0-based point ids for each poly element face
// The returned CompactListList is divided per output face
CompactListList<label> getPolysFacePoints
(
const polyMesh& mesh,
const labelUList& addr, //!< Cell ids to write
const labelList& pointMap //!< Point map to use
);
//- Write CompactListList<label> by components
void writeLabelListList
(
ensightGeoFile& os,
const labelUList& offsets,
const labelUList& values,
const label pointOffset
);
//- Write a list of faces or cell shapes with one-entity per line
template<class LabelListListType>
void writeLabelListList
(
ensightGeoFile& os,
const LabelListListType& listOfLists,
const label pointOffset
);
//- Copy specified field component into a scalar buffer
//- works for various lists types. Must be adequately sized before calling

View File

@ -31,6 +31,27 @@ License
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class LabelListListType>
void Foam::ensightOutput::Detail::writeLabelListList
(
ensightGeoFile& os,
const LabelListListType& listOfLists,
const label pointOffset
)
{
const label off = (pointOffset + 1); // 1-based for Ensight
forAll(listOfLists, listi)
{
for (const label pointi : listOfLists[listi])
{
os.write(pointi + off);
}
os.newline(); // One list (cell/faces) per line (ASCII)
}
}
template<template<typename> class FieldContainer, class Type>
void Foam::ensightOutput::Detail::copyComponent
(

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2020 OpenCFD Ltd.
Copyright (C) 2016-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -32,8 +32,8 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef ensightCells_H
#define ensightCells_H
#ifndef Foam_ensightCells_H
#define Foam_ensightCells_H
#include "ensightPart.H"
#include "FixedList.H"
@ -47,6 +47,7 @@ namespace Foam
// Forward Declarations
class bitSet;
class polyMesh;
template<class T> class InfoProxy;
/*---------------------------------------------------------------------------*\
Class ensightCells Declaration
@ -161,7 +162,6 @@ public:
virtual ~ensightCells() = default;
// Member Functions
// Access
@ -245,6 +245,10 @@ public:
// Output
//- Return info proxy
InfoProxy<ensightCells> info() const { return *this; }
//- Globally unique mesh points. Required when writing point fields.
label uniqueMeshPoints
(
@ -268,6 +272,10 @@ public:
};
template<>
Ostream& operator<<(Ostream&, const InfoProxy<ensightCells>&);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam

View File

@ -106,7 +106,7 @@ Foam::label Foam::ensightCells::meshPointMapppings
uniqueMeshPointLabels
);
nPoints = globalPointsPtr().size(); // nPoints (global)
nPoints = globalPointsPtr().totalSize(); // nPoints (global)
}
else
{
@ -125,7 +125,7 @@ Foam::label Foam::ensightCells::meshPointMapppings
uniqueMeshPointLabels
);
nPoints = globalPointsPtr().size(); // nPoints (global)
nPoints = globalPointsPtr().totalSize(); // nPoints (global)
meshPointMap.clear();

View File

@ -27,6 +27,7 @@ License
#include "ensightCells.H"
#include "ensightOutput.H"
#include "InfoProxy.H"
#include "polyMesh.H"
#include "globalIndex.H"
#include "globalMeshData.H"
@ -326,4 +327,30 @@ void Foam::ensightCells::write
}
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
template<>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const InfoProxy<ensightCells>& ip
)
{
const ensightCells& part = ip.t_;
os << part.name().c_str();
for (label typei=0; typei < ensightCells::nTypes; ++typei)
{
const auto etype = ensightCells::elemType(typei);
os << ' ' << ensightCells::elemNames[etype]
<< ':' << part.total(etype);
}
os << nl;
return os;
}
// ************************************************************************* //

View File

@ -49,8 +49,8 @@ Description
\*---------------------------------------------------------------------------*/
#ifndef ensightFaces_H
#define ensightFaces_H
#ifndef Foam_ensightFaces_H
#define Foam_ensightFaces_H
#include "ensightPart.H"
#include "face.H"
@ -64,6 +64,7 @@ namespace Foam
// Forward Declarations
class polyMesh;
template<class T> class InfoProxy;
/*---------------------------------------------------------------------------*\
Class ensightFaces Declaration
@ -243,6 +244,10 @@ public:
// Output
//- Return info proxy
InfoProxy<ensightFaces> info() const { return *this; }
//- Globally unique mesh points.
//- Required when writing point fields.
label uniqueMeshPoints
@ -266,6 +271,10 @@ public:
};
template<>
Ostream& operator<<(Ostream&, const InfoProxy<ensightFaces>&);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam

View File

@ -76,7 +76,7 @@ Foam::label Foam::ensightFaces::uniqueMeshPoints
uniqueMeshPointLabels
);
nPoints = globalPointsPtr().size(); // nPoints (global)
nPoints = globalPointsPtr().totalSize(); // nPoints (global)
}
else
{

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2020 OpenCFD Ltd.
Copyright (C) 2020-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -27,7 +27,7 @@ License
#include "ensightFaces.H"
#include "ensightOutput.H"
#include "InfoProxy.H"
#include "polyMesh.H"
#include "globalIndex.H"
#include "globalMeshData.H"
@ -78,7 +78,7 @@ void Foam::ensightFaces::write
uniqueMeshPointLabels
);
nPoints = globalPointsPtr().size(); // nPoints (global)
nPoints = globalPointsPtr().totalSize(); // nPoints (global)
}
else
{
@ -135,4 +135,30 @@ void Foam::ensightFaces::write
}
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
template<>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const InfoProxy<ensightFaces>& ip
)
{
const ensightFaces& part = ip.t_;
os << part.name().c_str();
for (label typei=0; typei < ensightFaces::nTypes; ++typei)
{
const auto etype = ensightFaces::elemType(typei);
os << ' ' << ensightFaces::elemNames[etype]
<< ':' << part.total(etype);
}
os << nl;
return os;
}
// ************************************************************************* //

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -53,7 +53,8 @@ Foam::ensightFaMesh::ensightFaMesh
)
:
mesh_(mesh),
needsUpdate_(true)
needsUpdate_(true),
verbose_(0)
{
// Lazy?
if (true)
@ -65,6 +66,20 @@ Foam::ensightFaMesh::ensightFaMesh
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
int Foam::ensightFaMesh::verbose() const noexcept
{
return verbose_;
}
int Foam::ensightFaMesh::verbose(const int level) noexcept
{
int old(verbose_);
verbose_ = level;
return old;
}
void Foam::ensightFaMesh::correct()
{
clear();
@ -87,6 +102,11 @@ void Foam::ensightFaMesh::correct()
// Finalize
part.reduce();
if (verbose_)
{
Info<< part.info();
}
// if (!part.total())
// {
// areaParts_.erase(areaId);

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2021 OpenCFD Ltd.
Copyright (C) 2021-2022 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -41,8 +41,8 @@ SourceFiles
\*---------------------------------------------------------------------------*/
#ifndef fa_ensightMesh_H
#define fa_ensightMesh_H
#ifndef Foam_fa_ensightMesh_H
#define Foam_fa_ensightMesh_H
#include "ensightFaces.H"
@ -73,6 +73,9 @@ class ensightFaMesh
//- Track if it needs an update
mutable bool needsUpdate_;
//- Output verbosity level
int verbose_;
// Private Member Functions
@ -99,6 +102,14 @@ public:
// Member Functions
//- Output verbosity level
int verbose() const noexcept;
//- Change the output verbosity level.
// \return old level
int verbose(const int level) noexcept;
// Access
//- Reference to the underlying faMesh