Commit 181c974b authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: improved sample surfaces and surface writers (#1206)

- The writers have changed from being a generic state-less set of
  routines to more properly conforming to the normal notion of a writer.
  These changes allow us to combine output fields (eg, in a single
  VTK/vtp file for each timestep).

  Parallel data reduction and any associated bookkeeping is now part
  of the surface writers.
  This improves their re-usability and avoids unnecessary
  and premature data reduction at the sampling stage.

  It is now possible to have different output formats on a per-surface
  basis.

- A new feature of the surface sampling is the ability to "store" the
  sampled surfaces and fields onto a registry for reuse by other
  function objects.

  Additionally, the "store" can be triggered at the execution phase
  as well
parent 16bc6386
......@@ -8,7 +8,6 @@
#include "wedgePolyPatch.H"
#include "unitConversion.H"
#include "polyMeshTetDecomposition.H"
#include "surfaceWriter.H"
#include "checkTools.H"
#include "functionObject.H"
......@@ -482,7 +481,7 @@ Foam::label Foam::checkGeometry
(
const polyMesh& mesh,
const bool allGeometry,
const autoPtr<surfaceWriter>& surfWriter,
autoPtr<surfaceWriter>& surfWriter,
const autoPtr<writer<scalar>>& setWriter
)
{
......@@ -542,7 +541,7 @@ Foam::label Foam::checkGeometry
nonAlignedPoints.write();
if (setWriter.valid())
{
mergeAndWrite(setWriter(), nonAlignedPoints);
mergeAndWrite(*setWriter, nonAlignedPoints);
}
}
}
......@@ -576,7 +575,7 @@ Foam::label Foam::checkGeometry
cells.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), cells);
mergeAndWrite(*surfWriter, cells);
}
}
}
......@@ -592,7 +591,7 @@ Foam::label Foam::checkGeometry
aspectCells.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), aspectCells);
mergeAndWrite(*surfWriter, aspectCells);
}
}
}
......@@ -613,7 +612,7 @@ Foam::label Foam::checkGeometry
faces.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), faces);
mergeAndWrite(*surfWriter, faces);
}
}
}
......@@ -635,7 +634,7 @@ Foam::label Foam::checkGeometry
cells.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), cells);
mergeAndWrite(*surfWriter, cells);
}
}
}
......@@ -658,7 +657,7 @@ Foam::label Foam::checkGeometry
faces.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), faces);
mergeAndWrite(*surfWriter, faces);
}
}
}
......@@ -680,7 +679,7 @@ Foam::label Foam::checkGeometry
faces.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), faces);
mergeAndWrite(*surfWriter, faces);
}
}
}
......@@ -702,7 +701,7 @@ Foam::label Foam::checkGeometry
faces.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), faces);
mergeAndWrite(*surfWriter, faces);
}
}
}
......@@ -726,7 +725,7 @@ Foam::label Foam::checkGeometry
faces.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), faces);
mergeAndWrite(*surfWriter, faces);
}
}
}
......@@ -759,7 +758,7 @@ Foam::label Foam::checkGeometry
faces.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), faces);
mergeAndWrite(*surfWriter, faces);
}
}
}
......@@ -784,7 +783,7 @@ Foam::label Foam::checkGeometry
points.write();
if (setWriter.valid())
{
mergeAndWrite(setWriter(), points);
mergeAndWrite(*setWriter, points);
}
}
}
......@@ -807,7 +806,7 @@ Foam::label Foam::checkGeometry
nearPoints.write();
if (setWriter.valid())
{
mergeAndWrite(setWriter(), nearPoints);
mergeAndWrite(*setWriter, nearPoints);
}
}
}
......@@ -831,7 +830,7 @@ Foam::label Foam::checkGeometry
faces.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), faces);
mergeAndWrite(*surfWriter, faces);
}
}
}
......@@ -854,7 +853,7 @@ Foam::label Foam::checkGeometry
faces.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), faces);
mergeAndWrite(*surfWriter, faces);
}
}
}
......@@ -875,7 +874,7 @@ Foam::label Foam::checkGeometry
cells.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), cells);
mergeAndWrite(*surfWriter, cells);
}
}
}
......@@ -895,7 +894,7 @@ Foam::label Foam::checkGeometry
cells.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), cells);
mergeAndWrite(*surfWriter, cells);
}
}
}
......@@ -916,7 +915,7 @@ Foam::label Foam::checkGeometry
faces.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), faces);
mergeAndWrite(*surfWriter, faces);
}
}
}
......@@ -937,7 +936,7 @@ Foam::label Foam::checkGeometry
faces.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), faces);
mergeAndWrite(*surfWriter, faces);
}
}
}
......@@ -952,14 +951,10 @@ Foam::label Foam::checkGeometry
autoPtr<surfaceWriter> patchWriter;
if (!surfWriter.valid())
{
patchWriter.reset(new vtkSurfaceWriter());
patchWriter.reset(new surfaceWriters::vtkWriter());
}
const surfaceWriter& wr =
(
surfWriter.valid()
? surfWriter()
: patchWriter()
);
surfaceWriter& wr = (surfWriter.valid() ? *surfWriter : *patchWriter);
// Currently only do AMI checks
......@@ -1017,22 +1012,22 @@ Foam::label Foam::checkGeometry
if (Pstream::master())
{
wr.write
const word fName
(
outputDir,
(
"patch" + Foam::name(cpp.index())
+ "-src_" + tmName
),
meshedSurfRef
(
mergedPoints,
mergedFaces
),
"weightsSum",
mergedWeights,
false
"patch" + Foam::name(cpp.index())
+ "-src_" + tmName
);
wr.open
(
mergedPoints,
mergedFaces,
(outputDir / fName),
false // serial - already merged
);
wr.write("weightsSum", mergedWeights);
wr.clear();
}
if (isA<cyclicACMIPolyPatch>(pbm[patchi]))
......@@ -1049,22 +1044,22 @@ Foam::label Foam::checkGeometry
if (Pstream::master())
{
wr.write
const word fName
(
outputDir,
(
"patch" + Foam::name(cpp.index())
+ "-src_" + tmName
),
meshedSurfRef
(
mergedPoints,
mergedFaces
),
"mask",
mergedMask,
false
"patch" + Foam::name(cpp.index())
+ "-src_" + tmName
);
wr.open
(
mergedPoints,
mergedFaces,
(outputDir / fName),
false // serial - already merged
);
wr.write("mask", mergedMask);
wr.clear();
}
}
}
......@@ -1101,22 +1096,22 @@ Foam::label Foam::checkGeometry
if (Pstream::master())
{
wr.write
const word fName
(
outputDir,
(
"patch" + Foam::name(cpp.index())
+ "-tgt_" + tmName
),
meshedSurfRef
(
mergedPoints,
mergedFaces
),
"weightsSum",
mergedWeights,
false
"patch" + Foam::name(cpp.index())
+ "-tgt_" + tmName
);
wr.open
(
mergedPoints,
mergedFaces,
(outputDir / fName),
false // serial - already merged
);
wr.write("weightsSum", mergedWeights);
wr.clear();
}
if (isA<cyclicACMIPolyPatch>(pbm[patchi]))
......@@ -1129,24 +1124,25 @@ Foam::label Foam::checkGeometry
pp.neighbPatch().mask(),
mergedMask
);
if (Pstream::master())
{
wr.write
const word fName
(
outputDir,
(
"patch" + Foam::name(cpp.index())
+ "-tgt_" + tmName
),
meshedSurfRef
(
mergedPoints,
mergedFaces
),
"mask",
mergedMask,
false
"patch" + Foam::name(cpp.index())
+ "-tgt_" + tmName
);
wr.open
(
mergedPoints,
mergedFaces,
(outputDir / fName),
false // serial - already merged
);
wr.write("mask", mergedMask);
wr.clear();
}
}
}
......
......@@ -27,7 +27,7 @@ namespace Foam
(
const polyMesh& mesh,
const bool allGeometry,
const autoPtr<surfaceWriter>&,
const autoPtr<writer<scalar>>&
autoPtr<surfaceWriter>& surfWriter,
const autoPtr<writer<scalar>>& setWriter
);
}
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015-2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2017 OpenFOAM Foundation
......@@ -67,8 +67,8 @@ Usage
#include "Time.H"
#include "fvMesh.H"
#include "globalMeshData.H"
#include "surfaceWriter.H"
#include "vtkSetWriter.H"
#include "vtkSurfaceWriter.H"
#include "IOdictionary.H"
#include "checkTools.H"
......@@ -149,16 +149,19 @@ int main(int argc, char *argv[])
);
if (!writeFields && args.found("writeAllFields"))
{
selectedFields.insert("nonOrthoAngle");
selectedFields.insert("faceWeight");
selectedFields.insert("skewness");
selectedFields.insert("cellDeterminant");
selectedFields.insert("aspectRatio");
selectedFields.insert("cellShapes");
selectedFields.insert("cellVolume");
selectedFields.insert("cellVolumeRatio");
selectedFields.insert("minTetVolume");
selectedFields.insert("cellRegion");
selectedFields.insert
({
"nonOrthoAngle",
"faceWeight",
"skewness",
"cellDeterminant",
"aspectRatio",
"cellShapes",
"cellVolume",
"cellVolumeRatio",
"minTetVolume",
"cellRegion"
});
}
......
......@@ -10,7 +10,7 @@ Foam::label Foam::checkMeshQuality
(
const polyMesh& mesh,
const dictionary& dict,
const autoPtr<surfaceWriter>& writer
autoPtr<surfaceWriter>& writer
)
{
label noFailedChecks = 0;
......@@ -29,9 +29,10 @@ Foam::label Foam::checkMeshQuality
<< " faces in error to set " << faces.name() << endl;
faces.instance() = mesh.pointsInstance();
faces.write();
if (writer.valid())
{
mergeAndWrite(writer(), faces);
mergeAndWrite(*writer, faces);
}
}
}
......
......@@ -6,8 +6,8 @@ namespace Foam
label checkMeshQuality
(
const polyMesh&,
const dictionary&,
const autoPtr<surfaceWriter>&
const polyMesh& mesh,
const dictionary& dict,
autoPtr<surfaceWriter>& writer
);
}
......@@ -209,7 +209,7 @@ void Foam::printMeshStats(const polyMesh& mesh, const bool allTopology)
void Foam::mergeAndWrite
(
const polyMesh& mesh,
const surfaceWriter& writer,
surfaceWriter& writer,
const word& name,
const indirectPrimitivePatch& setPatch,
const fileName& outputDir
......@@ -242,37 +242,37 @@ void Foam::mergeAndWrite
// Write
if (Pstream::master())
{
writer.write
writer.open
(
outputDir,
name,
meshedSurfRef
(
mergedPoints,
mergedFaces
)
mergedPoints,
mergedFaces,
(outputDir / name),
false // serial - already merged
);
writer.writeGeometry();
writer.clear();
}
}
else
{
writer.write
writer.open
(
outputDir,
name,
meshedSurfRef
(
setPatch.localPoints(),
setPatch.localFaces()
)
setPatch.localPoints(),
setPatch.localFaces(),
(outputDir / name),
false // serial - already merged
);
writer.writeGeometry();
writer.clear();
}
}
void Foam::mergeAndWrite
(
const surfaceWriter& writer,
surfaceWriter& writer,
const faceSet& set
)
{
......@@ -299,7 +299,7 @@ void Foam::mergeAndWrite
void Foam::mergeAndWrite
(
const surfaceWriter& writer,
surfaceWriter& writer,
const cellSet& set
)
{
......
......@@ -5,12 +5,12 @@
namespace Foam
{
class polyMesh;
class surfaceWriter;
class pointSet;
class faceSet;
class cellSet;
class fileName;
class polyMesh;
class surfaceWriter;
void printMeshStats(const polyMesh& mesh, const bool allTopology);
......@@ -19,7 +19,7 @@ namespace Foam
void mergeAndWrite
(
const polyMesh& mesh,
const surfaceWriter& writer,
surfaceWriter& writer,
const word& name,
const indirectPrimitivePatch& setPatch,
const fileName& outputDir
......@@ -27,15 +27,15 @@ namespace Foam
//- Write vtk representation of (assembled) faceSet to surface file in
// postProcessing/ directory
void mergeAndWrite(const surfaceWriter&, const faceSet&);
void mergeAndWrite(surfaceWriter& writer, const faceSet& set);
//- Write vtk representation of (assembled) cellSet to surface file in
// postProcessing/ directory
void mergeAndWrite(const surfaceWriter&, const cellSet&);
void mergeAndWrite(surfaceWriter& writer, const cellSet& set);
//- Write vtk representation of (assembled) pointSet to 'set' file in
// postProcessing/ directory
void mergeAndWrite(const writer<scalar>&, const pointSet&);
void mergeAndWrite(const writer<scalar>& writer, const pointSet& set);
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation
......@@ -35,7 +35,7 @@ License
#include "IOmanip.H"
#include "emptyPolyPatch.H"
#include "processorPolyPatch.H"
#include "surfaceWriter.H"
#include "vtkSurfaceWriter.H"
#include "checkTools.H"
#include "treeBoundBox.H"
......@@ -114,7 +114,7 @@ Foam::label Foam::checkTopology
const polyMesh& mesh,
const bool allTopology,
const bool allGeometry,
const autoPtr<surfaceWriter>& surfWriter,
autoPtr<surfaceWriter>& surfWriter,
const autoPtr<writer<scalar>>& setWriter
)
{
......@@ -203,7 +203,7 @@ Foam::label Foam::checkTopology
cells.write();
if (surfWriter.valid())
{
mergeAndWrite(surfWriter(), cells);
mergeAndWrite(*surfWriter, cells);
}
}
else
......@@ -227,7 +227,7 @@ Foam::label Foam::checkTopology
points.write();
if (setWriter.valid())
{
mergeAndWrite(setWriter(), points);
mergeAndWrite(*setWriter, points);