From 181c974b11fa80aec773a7d71162337557a9b699 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Thu, 7 Feb 2019 18:11:34 +0100 Subject: [PATCH] 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 --- .../manipulation/checkMesh/checkGeometry.C | 162 +++-- .../manipulation/checkMesh/checkGeometry.H | 4 +- .../mesh/manipulation/checkMesh/checkMesh.C | 27 +- .../manipulation/checkMesh/checkMeshQuality.C | 5 +- .../manipulation/checkMesh/checkMeshQuality.H | 6 +- .../mesh/manipulation/checkMesh/checkTools.C | 38 +- .../mesh/manipulation/checkMesh/checkTools.H | 10 +- .../manipulation/checkMesh/checkTopology.C | 26 +- .../manipulation/checkMesh/checkTopology.H | 12 +- .../surface/surfaceCheck/surfaceCheck.C | 150 ++-- .../surfaceFieldValue/surfaceFieldValue.C | 23 +- .../surfaceFieldValueTemplates.C | 18 +- .../FacePostProcessing/FacePostProcessing.C | 41 +- .../ParticleCollector/ParticleCollector.C | 50 +- .../noiseModels/surfaceNoise/surfaceNoise.C | 49 +- .../noiseModels/surfaceNoise/surfaceNoise.H | 4 +- src/sampling/Make/files | 23 +- .../sampledSurface/sampledSurface.C | 17 +- .../sampledSurface/sampledSurface.H | 155 ++++- .../sampledSurface/sampledSurfaceRegister.C | 255 ++----- .../sampledSurface/sampledSurfaceTemplates.C | 98 ++- .../sampledSurfaces/sampledSurfaces.C | 658 ++++++++++++------ .../sampledSurfaces/sampledSurfaces.H | 158 +++-- .../sampledSurfaces/sampledSurfacesGrouping.C | 89 --- .../sampledSurfacesTemplates.C | 251 ++++--- .../boundaryData/boundaryDataSurfaceWriter.C | 116 --- .../boundaryData/boundaryDataSurfaceWriter.H | 231 ------ .../boundaryDataSurfaceWriterImpl.C | 132 ---- .../writers/ensight/ensightSurfaceWriter.H | 259 ------- .../ensight/ensightSurfaceWriterImpl.C | 531 -------------- .../writers/foam/foamSurfaceWriter.C | 98 --- .../writers/foam/foamSurfaceWriter.H | 209 ------ .../writers/foam/foamSurfaceWriterImpl.C | 77 -- .../writers/raw/rawSurfaceWriter.C | 136 ---- .../writers/raw/rawSurfaceWriter.H | 220 ------ .../writers/starcd/starcdSurfaceWriter.H | 215 ------ .../writers/starcd/starcdSurfaceWriterImpl.C | 94 --- .../sampledSurface/writers/surfaceWriter.C | 126 ---- .../sampledSurface/writers/surfaceWriter.H | 230 ------ .../writers/vtk/vtkSurfaceWriter.C | 192 ----- .../writers/vtk/vtkSurfaceWriter.H | 251 ------- .../writers/vtk/vtkSurfaceWriterImpl.C | 153 ---- .../surfMeshSamplers/surfMeshSamplers.C | 17 +- src/surfMesh/Make/files | 16 + .../boundaryData/boundaryDataSurfaceWriter.C | 275 ++++++++ .../boundaryData/boundaryDataSurfaceWriter.H | 187 +++++ .../writers/ensight/ensightSurfaceWriter.C | 205 +++--- .../writers/ensight/ensightSurfaceWriter.H | 198 ++++++ .../ensight/ensightSurfaceWriterCollated.C | 376 ++++++++++ .../ensight/ensightSurfaceWriterUncollated.C | 252 +++++++ src/surfMesh/writers/foam/foamSurfaceWriter.C | 208 ++++++ src/surfMesh/writers/foam/foamSurfaceWriter.H | 163 +++++ .../writers/nastran/nastranSurfaceWriter.C | 134 ++-- .../writers/nastran/nastranSurfaceWriter.H | 139 ++-- .../nastran/nastranSurfaceWriterImpl.C | 138 ++-- src/surfMesh/writers/null/nullSurfaceWriter.C | 121 ++++ src/surfMesh/writers/null/nullSurfaceWriter.H | 149 ++++ .../writers/proxy/proxySurfaceWriter.C | 103 ++- .../writers/proxy/proxySurfaceWriter.H | 73 +- src/surfMesh/writers/raw/rawSurfaceWriter.C | 185 +++++ src/surfMesh/writers/raw/rawSurfaceWriter.H | 172 +++++ .../writers/raw/rawSurfaceWriterImpl.C | 120 ++-- .../writers/starcd/starcdSurfaceWriter.C | 217 ++++++ .../writers/starcd/starcdSurfaceWriter.H | 170 +++++ src/surfMesh/writers/surfaceWriter.C | 458 ++++++++++++ src/surfMesh/writers/surfaceWriter.H | 491 +++++++++++++ .../writers/surfaceWriterI.H} | 115 +-- .../writers/surfaceWriterMethods.H} | 43 +- src/surfMesh/writers/vtk/vtkSurfaceWriter.C | 291 ++++++++ src/surfMesh/writers/vtk/vtkSurfaceWriter.H | 203 ++++++ 70 files changed, 6034 insertions(+), 4784 deletions(-) delete mode 100644 src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C delete mode 100644 src/sampling/sampledSurface/writers/boundaryData/boundaryDataSurfaceWriter.C delete mode 100644 src/sampling/sampledSurface/writers/boundaryData/boundaryDataSurfaceWriter.H delete mode 100644 src/sampling/sampledSurface/writers/boundaryData/boundaryDataSurfaceWriterImpl.C delete mode 100644 src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H delete mode 100644 src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriterImpl.C delete mode 100644 src/sampling/sampledSurface/writers/foam/foamSurfaceWriter.C delete mode 100644 src/sampling/sampledSurface/writers/foam/foamSurfaceWriter.H delete mode 100644 src/sampling/sampledSurface/writers/foam/foamSurfaceWriterImpl.C delete mode 100644 src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C delete mode 100644 src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H delete mode 100644 src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.H delete mode 100644 src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriterImpl.C delete mode 100644 src/sampling/sampledSurface/writers/surfaceWriter.C delete mode 100644 src/sampling/sampledSurface/writers/surfaceWriter.H delete mode 100644 src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C delete mode 100644 src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H delete mode 100644 src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriterImpl.C create mode 100644 src/surfMesh/writers/boundaryData/boundaryDataSurfaceWriter.C create mode 100644 src/surfMesh/writers/boundaryData/boundaryDataSurfaceWriter.H rename src/{sampling/sampledSurface => surfMesh}/writers/ensight/ensightSurfaceWriter.C (53%) create mode 100644 src/surfMesh/writers/ensight/ensightSurfaceWriter.H create mode 100644 src/surfMesh/writers/ensight/ensightSurfaceWriterCollated.C create mode 100644 src/surfMesh/writers/ensight/ensightSurfaceWriterUncollated.C create mode 100644 src/surfMesh/writers/foam/foamSurfaceWriter.C create mode 100644 src/surfMesh/writers/foam/foamSurfaceWriter.H rename src/{sampling/sampledSurface => surfMesh}/writers/nastran/nastranSurfaceWriter.C (76%) rename src/{sampling/sampledSurface => surfMesh}/writers/nastran/nastranSurfaceWriter.H (55%) rename src/{sampling/sampledSurface => surfMesh}/writers/nastran/nastranSurfaceWriterImpl.C (63%) create mode 100644 src/surfMesh/writers/null/nullSurfaceWriter.C create mode 100644 src/surfMesh/writers/null/nullSurfaceWriter.H rename src/{sampling/sampledSurface => surfMesh}/writers/proxy/proxySurfaceWriter.C (53%) rename src/{sampling/sampledSurface => surfMesh}/writers/proxy/proxySurfaceWriter.H (61%) create mode 100644 src/surfMesh/writers/raw/rawSurfaceWriter.C create mode 100644 src/surfMesh/writers/raw/rawSurfaceWriter.H rename src/{sampling/sampledSurface => surfMesh}/writers/raw/rawSurfaceWriterImpl.C (61%) create mode 100644 src/surfMesh/writers/starcd/starcdSurfaceWriter.C create mode 100644 src/surfMesh/writers/starcd/starcdSurfaceWriter.H create mode 100644 src/surfMesh/writers/surfaceWriter.C create mode 100644 src/surfMesh/writers/surfaceWriter.H rename src/{sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.C => surfMesh/writers/surfaceWriterI.H} (50%) rename src/{sampling/sampledSurface/writers/makeSurfaceWriterMethods.H => surfMesh/writers/surfaceWriterMethods.H} (54%) create mode 100644 src/surfMesh/writers/vtk/vtkSurfaceWriter.C create mode 100644 src/surfMesh/writers/vtk/vtkSurfaceWriter.H diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.C b/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.C index 5c8f4da2d7..4f1f821681 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.C @@ -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& surfWriter, + autoPtr& surfWriter, const autoPtr>& 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 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(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(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(); } } } diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.H b/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.H index d0111fd1e1..acd3d401be 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.H +++ b/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.H @@ -27,7 +27,7 @@ namespace Foam ( const polyMesh& mesh, const bool allGeometry, - const autoPtr&, - const autoPtr>& + autoPtr& surfWriter, + const autoPtr>& setWriter ); } diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkMesh.C b/applications/utilities/mesh/manipulation/checkMesh/checkMesh.C index 8b3eb25cc7..fbd24180c4 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkMesh.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkMesh.C @@ -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" + }); } diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkMeshQuality.C b/applications/utilities/mesh/manipulation/checkMesh/checkMeshQuality.C index a6a01c7336..26dfbb6d20 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkMeshQuality.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkMeshQuality.C @@ -10,7 +10,7 @@ Foam::label Foam::checkMeshQuality ( const polyMesh& mesh, const dictionary& dict, - const autoPtr& writer + autoPtr& 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); } } } diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkMeshQuality.H b/applications/utilities/mesh/manipulation/checkMesh/checkMeshQuality.H index 52507986bf..0ad3f74487 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkMeshQuality.H +++ b/applications/utilities/mesh/manipulation/checkMesh/checkMeshQuality.H @@ -6,8 +6,8 @@ namespace Foam label checkMeshQuality ( - const polyMesh&, - const dictionary&, - const autoPtr& + const polyMesh& mesh, + const dictionary& dict, + autoPtr& writer ); } diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkTools.C b/applications/utilities/mesh/manipulation/checkMesh/checkTools.C index 060c60b0fc..4b530ee9ef 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkTools.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkTools.C @@ -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 ) { diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkTools.H b/applications/utilities/mesh/manipulation/checkMesh/checkTools.H index adb98089b5..79c68b6673 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkTools.H +++ b/applications/utilities/mesh/manipulation/checkMesh/checkTools.H @@ -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&, const pointSet&); + void mergeAndWrite(const writer& writer, const pointSet& set); } diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkTopology.C b/applications/utilities/mesh/manipulation/checkMesh/checkTopology.C index fb0d1c6ccf..25c8e43de8 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkTopology.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkTopology.C @@ -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& surfWriter, + autoPtr& surfWriter, const autoPtr>& 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); } } } @@ -249,7 +249,7 @@ Foam::label Foam::checkTopology faces.write(); if (surfWriter.valid()) { - mergeAndWrite(surfWriter(), faces); + mergeAndWrite(*surfWriter, faces); } } } @@ -269,7 +269,7 @@ Foam::label Foam::checkTopology faces.write(); if (surfWriter.valid()) { - mergeAndWrite(surfWriter(), faces); + mergeAndWrite(*surfWriter, faces); } } } @@ -290,7 +290,7 @@ Foam::label Foam::checkTopology cells.write(); if (surfWriter.valid()) { - mergeAndWrite(surfWriter(), cells); + mergeAndWrite(*surfWriter, cells); } } @@ -314,7 +314,7 @@ Foam::label Foam::checkTopology faces.write(); if (surfWriter.valid()) { - mergeAndWrite(surfWriter(), faces); + mergeAndWrite(*surfWriter, faces); } } } @@ -369,7 +369,7 @@ Foam::label Foam::checkTopology oneCells.write(); if (surfWriter.valid()) { - mergeAndWrite(surfWriter(), oneCells); + mergeAndWrite(*surfWriter, oneCells); } } @@ -385,7 +385,7 @@ Foam::label Foam::checkTopology twoCells.write(); if (surfWriter.valid()) { - mergeAndWrite(surfWriter(), twoCells); + mergeAndWrite(*surfWriter, twoCells); } } } @@ -530,7 +530,7 @@ Foam::label Foam::checkTopology points.write(); if (setWriter.valid()) { - mergeAndWrite(setWriter(), points); + mergeAndWrite(*setWriter, points); } } } @@ -641,7 +641,7 @@ Foam::label Foam::checkTopology points.write(); if (setWriter.valid()) { - mergeAndWrite(setWriter(), points); + mergeAndWrite(*setWriter, points); } } diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkTopology.H b/applications/utilities/mesh/manipulation/checkMesh/checkTopology.H index 7320cb0e56..bd93afc3db 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkTopology.H +++ b/applications/utilities/mesh/manipulation/checkMesh/checkTopology.H @@ -5,8 +5,8 @@ namespace Foam { class polyMesh; - class surfaceWriter; class pointSet; + class surfaceWriter; template void checkPatch @@ -19,10 +19,10 @@ namespace Foam label checkTopology ( - const polyMesh&, - const bool, - const bool, - const autoPtr&, - const autoPtr>& + const polyMesh& mesh, + const bool allTopology, + const bool allGeometry, + autoPtr& surfWriter, + const autoPtr>& setWriter ); } diff --git a/applications/utilities/surface/surfaceCheck/surfaceCheck.C b/applications/utilities/surface/surfaceCheck/surfaceCheck.C index 57afe5931f..c42f3e3fe8 100644 --- a/applications/utilities/surface/surfaceCheck/surfaceCheck.C +++ b/applications/utilities/surface/surfaceCheck/surfaceCheck.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -128,7 +128,7 @@ labelList countBins void writeZoning ( - const surfaceWriter& writer, + surfaceWriter& writer, const triSurface& surf, const labelList& faceZone, const word& fieldName, @@ -136,43 +136,23 @@ void writeZoning const fileName& surfFileNameBase ) { - Info<< "Writing zoning to " - << fileName - ( - surfFilePath - / fieldName - + '_' - + surfFileNameBase - + '.' - + writer.type() - ) - << " ..." << endl << endl; + // Transcribe faces + faceList faces; + surf.triFaceFaces(faces); - // Convert data - scalarField scalarFaceZone(faceZone.size()); - forAll(faceZone, i) - { - scalarFaceZone[i] = faceZone[i]; - } - faceList faces(surf.size()); - forAll(surf, i) - { - faces[i] = surf[i]; - } - - writer.write + writer.open ( - surfFilePath, - surfFileNameBase, - meshedSurfRef - ( - surf.points(), - faces - ), - fieldName, - scalarFaceZone, - false // face based data + surf.points(), + faces, + (surfFilePath / surfFileNameBase), + false // serial - already merged ); + + fileName outputName = writer.write(fieldName, labelField(faceZone)); + + writer.clear(); + + Info<< "Wrote zoning to " << outputName << nl << endl; } @@ -213,7 +193,7 @@ void writeParts fileName subName ( surfFilePath - /surfFileNameBase + "_" + name(zone) + ".obj" + / surfFileNameBase + "_" + name(zone) + ".obj" ); Info<< "writing part " << zone << " size " << subSurf.size() @@ -377,6 +357,7 @@ int main(int argc, char *argv[]) if (writeSets) { surfWriter = surfaceWriter::New(surfaceFormat); + // Option1: hard-coded format edgeFormat = "obj"; //// Option2: same type as surface format. Problem is e.g. .obj format @@ -514,38 +495,29 @@ int main(int argc, char *argv[]) ) ); - const fileName qualityName + + // Transcribe faces + faceList faces; + subSurf.triFaceFaces(faces); + + surfWriter->open ( - surfFilePath - / "illegal" - + '_' - + surfFileNameBase - + '.' - + surfWriter().type() + subSurf.points(), + faces, + (surfFilePath / surfFileNameBase), + false // serial - already merged ); - Info<< "Writing illegal triangles to " - << qualityName << " ..." << endl << endl; - // Convert data - faceList faces(subSurf.size()); - forAll(subSurf, i) - { - faces[i] = subSurf[i]; - } - - surfWriter().write + fileName outputName = surfWriter->write ( - surfFilePath, - surfFileNameBase, - meshedSurfRef - ( - subSurf.points(), - faces - ), "illegal", - scalarField(subSurf.size(), Zero), - false // face based data + scalarField(subSurf.size(), Zero) ); + + surfWriter->clear(); + + Info<< "Wrote illegal triangles to " + << outputName << nl << endl; } else if (outputThreshold > 0) { @@ -645,38 +617,24 @@ int main(int argc, char *argv[]) // Dump for subsetting if (surfWriter.valid()) { - const fileName qualityName - ( - surfFilePath - / "quality" - + '_' - + surfFileNameBase - + '.' - + surfWriter().type() - ); - Info<< "Writing triangle-quality to " - << qualityName << " ..." << endl << endl; - - // Convert data + // Transcribe faces faceList faces(surf.size()); - forAll(surf, i) - { - faces[i] = surf[i]; - } + surf.triFaceFaces(faces); - surfWriter().write + surfWriter->open ( - surfFilePath, - surfFileNameBase, - meshedSurfRef - ( - surf.points(), - faces - ), - "quality", - triQ, - false // face based data + surf.points(), + faces, + (surfFilePath / surfFileNameBase), + false // serial - already merged ); + + fileName outputName = surfWriter->write("quality", triQ); + + surfWriter->clear(); + + Info<< "Wrote triangle-quality to " + << outputName << nl << endl; } else if (outputThreshold > 0) { @@ -926,11 +884,12 @@ int main(int argc, char *argv[]) if (!surfWriter.valid()) { - surfWriter.reset(new vtkSurfaceWriter()); + surfWriter.reset(new surfaceWriters::vtkWriter()); } + writeZoning ( - surfWriter(), + *surfWriter, surf, faceZone, "zone", @@ -991,11 +950,12 @@ int main(int argc, char *argv[]) { if (!surfWriter.valid()) { - surfWriter.reset(new vtkSurfaceWriter()); + surfWriter.reset(new surfaceWriters::vtkWriter()); } + writeZoning ( - surfWriter(), + *surfWriter, surf, normalZone, "normal", diff --git a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C index 1df74fc79d..056b00a0c5 100644 --- a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C +++ b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValue.C @@ -953,20 +953,23 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::read { const word formatName(dict.get("surfaceFormat")); - if (formatName != "none") - { - surfaceWriterPtr_.reset + surfaceWriterPtr_.reset + ( + surfaceWriter::New ( - surfaceWriter::New - ( - formatName, - dict.subOrEmptyDict("formatOptions") - .subOrEmptyDict(formatName) - ) - ); + formatName, + dict.subOrEmptyDict("formatOptions").subOrEmptyDict(formatName) + ) + ); + if (surfaceWriterPtr_->enabled()) + { Info<< " surfaceFormat = " << formatName << nl; } + else + { + surfaceWriterPtr_->clear(); + } } Info<< nl << endl; diff --git a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C index 56c3bc8ed9..d665e74d58 100644 --- a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C +++ b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C @@ -384,22 +384,26 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::writeValues Field values(getFieldValues(fieldName, true)); // Write raw values on surface if specified - if (surfaceWriterPtr_.valid()) + if (surfaceWriterPtr_.valid() && surfaceWriterPtr_->enabled()) { Field allValues(values); combineFields(allValues); if (Pstream::master()) { - surfaceWriterPtr_->write + surfaceWriterPtr_->open ( - outputDir(), - regionTypeNames_[regionType_] + ("_" + regionName_), surfToWrite, - fieldName, - allValues, - false + ( + outputDir() + / regionTypeNames_[regionType_] + ("_" + regionName_) + ), + false // serial - already merged ); + + surfaceWriterPtr_->write(fieldName, allValues); + + surfaceWriterPtr_->clear(); } } diff --git a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/FacePostProcessing/FacePostProcessing.C b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/FacePostProcessing/FacePostProcessing.C index 5c228621bd..4c859a885f 100644 --- a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/FacePostProcessing/FacePostProcessing.C +++ b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/FacePostProcessing/FacePostProcessing.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2017 OpenFOAM Foundation @@ -28,8 +28,8 @@ License #include "FacePostProcessing.H" #include "Pstream.H" #include "ListListOps.H" -#include "surfaceWriter.H" #include "globalIndex.H" +#include "surfaceWriter.H" // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // @@ -194,35 +194,26 @@ void Foam::FacePostProcessing::write() ) ); - autoPtr writer + auto writer = surfaceWriter::New ( - surfaceWriter::New - ( - surfaceFormat_, - this->coeffDict().subOrEmptyDict("formatOptions"). - subOrEmptyDict(surfaceFormat_) - ) + surfaceFormat_, + this->coeffDict().subOrEmptyDict("formatOptions") + .subOrEmptyDict(surfaceFormat_) ); - writer->write + writer->open ( - this->writeTimeDir(), - fZone.name(), - meshedSurfRef(allPoints, allFaces), - "massTotal", - zoneMassTotal[zoneI], - false + allPoints, + allFaces, + (this->writeTimeDir() / fZone.name()), + false // serial - already merged ); - writer->write - ( - this->writeTimeDir(), - fZone.name(), - meshedSurfRef(allPoints, allFaces), - "massFlowRate", - zoneMassFlowRate[zoneI], - false - ); + writer->write("massTotal", zoneMassTotal[zoneI]); + + writer->write("massFlowRate", zoneMassFlowRate[zoneI]); + + writer->clear(); } } } diff --git a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleCollector/ParticleCollector.C b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleCollector/ParticleCollector.C index 381c36077b..6f0eaf15c5 100644 --- a/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleCollector/ParticleCollector.C +++ b/src/lagrangian/intermediate/submodels/CloudFunctionObjects/ParticleCollector/ParticleCollector.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2015-2016 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2012-2017 OpenFOAM Foundation @@ -462,40 +462,26 @@ void Foam::ParticleCollector::write() << endl; - if (surfaceFormat_ != "none") + if (surfaceFormat_ != "none" && Pstream::master()) { - if (Pstream::master()) - { - autoPtr writer - ( - surfaceWriter::New - ( - surfaceFormat_, - this->coeffDict().subOrEmptyDict("formatOptions"). - subOrEmptyDict(surfaceFormat_) - ) - ); + auto writer = surfaceWriter::New + ( + surfaceFormat_, + this->coeffDict().subOrEmptyDict("formatOptions") + .subOrEmptyDict(surfaceFormat_) + ); - writer->write - ( - this->writeTimeDir(), - "collector", - meshedSurfRef(points_, faces_), - "massTotal", - faceMassTotal, - false - ); + writer->open + ( + points_, + faces_, + (this->writeTimeDir() / "collector"), + false // serial - already merged + ); - writer->write - ( - this->writeTimeDir(), - "collector", - meshedSurfRef(points_, faces_), - "massFlowRate", - faceMassFlowRate, - false - ); - } + writer->write("massFlowRate", faceMassFlowRate); + + writer->write("massTotal", faceMassTotal); } diff --git a/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C b/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C index bf53217d1a..b97622dd4a 100644 --- a/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C +++ b/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -275,22 +275,19 @@ Foam::scalar surfaceNoise::writeSurfaceData } } - // Could also have meshedSurface implement meshedSurf if (writeSurface) { - fileName outFileName = writerPtr_->write + writerPtr_->open ( - outDir, - fName, - meshedSurfRef - ( - surf.points(), - surf.surfFaces() - ), - title, - allData, - false + surf.points(), + surf.surfFaces(), + (outDir / fName), + false // serial - already merged ); + + writerPtr_->write(title, allData); + + writerPtr_->clear(); } // TO BE VERIFIED: area-averaged values @@ -305,22 +302,19 @@ Foam::scalar surfaceNoise::writeSurfaceData { const meshedSurface& surf = readerPtr_->geometry(); - // Could also have meshedSurface implement meshedSurf if (writeSurface) { - writerPtr_->write + writerPtr_->open ( - outDir, - fName, - meshedSurfRef - ( - surf.points(), - surf.surfFaces() - ), - title, - data, - false + surf.points(), + surf.surfFaces(), + (outDir / fName), + false // serial - already merged ); + + writerPtr_->write(title, data); + + writerPtr_->clear(); } // TO BE VERIFIED: area-averaged values @@ -442,13 +436,12 @@ bool surfaceNoise::read(const dictionary& dict) const word writerType(dict.get("writer")); - dictionary optDict + writerPtr_ = surfaceWriter::New ( + writerType, dict.subOrEmptyDict("writeOptions").subOrEmptyDict(writerType) ); - writerPtr_ = surfaceWriter::New(writerType, optDict); - return true; } diff --git a/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.H b/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.H index 55d4e6e334..38073c5f2b 100644 --- a/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.H +++ b/src/randomProcesses/noise/noiseModels/surfaceNoise/surfaceNoise.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2015-2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2015-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -111,7 +111,7 @@ SeeAlso namespace Foam { -// Forward declaration of classes +// Forward declarations class surfaceReader; class surfaceWriter; diff --git a/src/sampling/Make/files b/src/sampling/Make/files index dbef3b3987..83403b64a2 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -50,8 +50,8 @@ sampledSurface/distanceSurface/sampledDistanceSurface.C sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C sampledSurface/sampledCuttingSurface/sampledCuttingSurface.C sampledSurface/sampledSurface/sampledSurface.C +sampledSurface/sampledSurface/sampledSurfaceRegister.C sampledSurface/sampledSurfaces/sampledSurfaces.C -sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMeshNormal.C sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C @@ -59,24 +59,11 @@ sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C /* Proof-of-concept: */ /* sampledSurface/triSurfaceMesh/sampledDiscreteSurface.C */ +readers = sampledSurface/readers -surfWriters = sampledSurface/writers - -$(surfWriters)/surfaceWriter.C -$(surfWriters)/ensight/ensightSurfaceWriter.C -$(surfWriters)/foam/foamSurfaceWriter.C -$(surfWriters)/nastran/nastranSurfaceWriter.C -$(surfWriters)/proxy/proxySurfaceWriter.C -$(surfWriters)/raw/rawSurfaceWriter.C -$(surfWriters)/starcd/starcdSurfaceWriter.C -$(surfWriters)/vtk/vtkSurfaceWriter.C -$(surfWriters)/boundaryData/boundaryDataSurfaceWriter.C - -surfReaders = sampledSurface/readers - -$(surfReaders)/surfaceReader.C -$(surfReaders)/surfaceReaderNew.C -$(surfReaders)/ensight/ensightSurfaceReader.C +$(readers)/surfaceReader.C +$(readers)/surfaceReaderNew.C +$(readers)/ensight/ensightSurfaceReader.C graphField/writePatchGraph.C graphField/writeCellGraph.C diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurface.C b/src/sampling/sampledSurface/sampledSurface/sampledSurface.C index d326e7e3ca..ebb5048e53 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurface.C +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurface.C @@ -38,6 +38,17 @@ namespace Foam } +const Foam::wordList Foam::sampledSurface::surfaceFieldTypes +({ + "surfaceScalarField", + "surfaceVectorField", + "surfaceSphericalTensorField", + "surfaceSymmTensorField", + "surfaceTensorField" +}); + + + // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // void Foam::sampledSurface::clearGeom() const @@ -57,10 +68,8 @@ Foam::autoPtr Foam::sampledSurface::New { const word sampleType(dict.get("type")); - if (debug) - { - Info<< "Selecting sampledType " << sampleType << endl; - } + DebugInfo + << "Selecting sampledType " << sampleType << endl; auto cstrIter = wordConstructorTablePtr_->cfind(sampleType); diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurface.H b/src/sampling/sampledSurface/sampledSurface/sampledSurface.H index bf279805db..ba6a84a15f 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurface.H +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurface.H @@ -65,17 +65,15 @@ SourceFiles #ifndef sampledSurface_H #define sampledSurface_H -#include "meshedSurf.H" -#include "word.H" -#include "labelList.H" -#include "faceList.H" +#include "polySurface.H" +#include "surfMesh.H" #include "typeInfo.H" #include "runTimeSelectionTables.H" #include "autoPtr.H" +#include "polyMesh.H" #include "volFieldsFwd.H" #include "surfaceFieldsFwd.H" #include "surfaceMesh.H" -#include "polyMesh.H" #include "interpolation.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -84,18 +82,26 @@ namespace Foam { /*---------------------------------------------------------------------------*\ - Class sampledSurface Declaration + Class sampledSurface Declaration \*---------------------------------------------------------------------------*/ class sampledSurface : public meshedSurf { +public: + + // Public Static Data + + //- Class names for surface field types + static const wordList surfaceFieldTypes; + + private: // Private Data - //- Name of sample surface + //- The name of the sample surface word name_; //- Reference to mesh @@ -104,15 +110,13 @@ private: //- Should surface sampling be enabled? bool enabled_; - //- Do we intend to interpolate the information? - const bool interpolate_; + //- Interpolate information to the nodes? + bool interpolate_; //- Total surface area (demand-driven) mutable scalar area_; - - protected: // Protected Member Functions @@ -163,9 +167,7 @@ public: ); - // iNew helper class - - //- Class for PtrList read-construction + //- PtrList read-construction helper class iNew { //- Reference to the volume mesh @@ -188,6 +190,34 @@ public: }; + //- PtrList read-construction helper that captures dictionaries used + //- during creation. + class iNewCapture + { + //- Reference to the volume mesh + const polyMesh& mesh_; + + //- Captured (recorded) dictionaries + DynamicList& capture_; + + public: + + iNewCapture(const polyMesh& mesh, DynamicList& capture) + : + mesh_(mesh), + capture_(capture) + {} + + autoPtr operator()(Istream& is) const + { + word name(is); + capture_.append(dictionary(is)); + + return sampledSurface::New(name, mesh_, capture_.last()); + } + }; + + // Constructors //- Construct from name, mesh @@ -245,13 +275,13 @@ public: return name_; } - //- Sampling is enabled + //- Surface is enabled bool enabled() const { return enabled_; } - //- Interpolation requested for surface + //- interpolation to nodes requested for surface bool interpolate() const { return interpolate_; @@ -301,6 +331,99 @@ public: } + // General registry storage (optional) + + //- Get surface from registry if available. + // \param obr The objectRegistry to use + // \param lookupName Optional lookup name, use surface name if empty + // \return surface or nullptr + polySurface* getRegistrySurface + ( + const objectRegistry& obr, + word lookupName = "" + ) const; + + //- Copy surface into registry. + // \param obr The objectRegistry to use + // \param lookupName Optional lookup name, use surface name if empty + // \return surface or nullptr it surface should not be stored + polySurface* storeRegistrySurface + ( + objectRegistry& obr, + word lookupName = "" + ) const; + + //- Remove surface from registry. + // \param obr The objectRegistry to use + // \param lookupName Optional lookup name, use surface name if empty + // \return True if surface existed and was removed + bool removeRegistrySurface + ( + objectRegistry& obr, + word lookupName = "" + ) const; + + //- Copy/store sampled field onto registered surface (if it exists) + template + bool storeRegistryField + ( + const objectRegistry& obr, + const word& fieldName, + const dimensionSet& dims, + const Field& values, + word lookupName = "" + ) const; + + //- Move/store sampled field onto registered surface (if it exists) + template + bool storeRegistryField + ( + const objectRegistry& obr, + const word& fieldName, + const dimensionSet& dims, + Field&& values, + word lookupName = "" + ) const; + + + // Specialized surfMesh storage (optional) + + //- Get surface from registry if available. + // \param lookupName Optional lookup name, use surface name if empty + // \return surface or nullptr + surfMesh* getSurfMesh(word lookupName = "") const; + + //- Copy surface into registry. + // \param lookupName Optional lookup name, use surface name if empty + // \return surface or nullptr it surface should not be stored + surfMesh* storeSurfMesh(word lookupName = "") const; + + //- Remove surface from registry. + // \param lookupName Optional lookup name, use surface name if empty + // \return True if surface existed and was removed + bool removeSurfMesh(word lookupName = "") const; + + //- Copy/store sampled Face field onto surfMesh (if it exists) + template + bool storeSurfMeshField + ( + const word& fieldName, + const dimensionSet& dims, + const Field& values, + word lookupName = "" + ) const; + + //- Move/store sampled Face field onto surfMesh (if it exists) + template + bool storeSurfMeshField + ( + const word& fieldName, + const dimensionSet& dims, + Field&& values, + word lookupName = "" + ) const; + + // Sample (faces) //- Sample volume field onto surface faces diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurfaceRegister.C b/src/sampling/sampledSurface/sampledSurface/sampledSurfaceRegister.C index c7fa0297d0..ab2438fc64 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurfaceRegister.C +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurfaceRegister.C @@ -2,10 +2,8 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2004-2010, 2018-2019 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2019 OpenCFD Ltd. \\/ M anipulation | -------------------------------------------------------------------------------- - | Copyright (C) 2011-2016 OpenFOAM Foundation ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -26,200 +24,12 @@ License \*---------------------------------------------------------------------------*/ #include "sampledSurface.H" -#include "polyMesh.H" +#include "fvMesh.H" +#include "MeshedSurface.H" #include "demandDrivenData.H" -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -namespace Foam -{ - defineTypeNameAndDebug(sampledSurface, 0); - defineRunTimeSelectionTable(sampledSurface, word); -} - - -const Foam::wordList Foam::sampledSurface::surfaceFieldTypes -({ - "surfaceScalarField", - "surfaceVectorField", - "surfaceSphericalTensorField", - "surfaceSymmTensorField", - "surfaceTensorField" -}); - - - -// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // - -void Foam::sampledSurface::clearGeom() const -{ - area_ = -1; -} - - -// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * // - -Foam::autoPtr Foam::sampledSurface::New -( - const word& name, - const polyMesh& mesh, - const dictionary& dict -) -{ - const word sampleType(dict.get("type")); - - if (debug) - { - Info<< "Selecting sampledType " << sampleType << endl; - } - - auto cstrIter = wordConstructorTablePtr_->cfind(sampleType); - - if (!cstrIter.found()) - { - FatalErrorInFunction - << "Unknown sample type " - << sampleType << nl << nl - << "Valid sample types :" << endl - << wordConstructorTablePtr_->sortedToc() - << exit(FatalError); - } - - return autoPtr(cstrIter()(name, mesh, dict)); -} - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::sampledSurface::sampledSurface(const word& name, std::nullptr_t) -: - name_(name), - mesh_(NullObjectRef()), - enabled_(true), - interpolate_(false), - area_(-1), - writerType_(), - formatOptions_() -{} - - -Foam::sampledSurface::sampledSurface -( - const word& name, - const polyMesh& mesh, - const bool interpolate -) -: - name_(name), - mesh_(mesh), - enabled_(true), - interpolate_(interpolate), - area_(-1), - writerType_(), - formatOptions_() -{} - - -Foam::sampledSurface::sampledSurface -( - const word& name, - const polyMesh& mesh, - const dictionary& dict -) -: - name_(dict.lookupOrDefault("name", name)), - mesh_(mesh), - enabled_(dict.lookupOrDefault("enabled", true)), - interpolate_(dict.lookupOrDefault("interpolate", false)), - area_(-1), - writerType_(dict.lookupOrDefault("surfaceFormat", "")), - formatOptions_(dict.subOrEmptyDict("formatOptions")) -{} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::sampledSurface::~sampledSurface() -{ - clearGeom(); -} - - // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -Foam::scalar Foam::sampledSurface::area() const -{ - if (area_ < 0) - { - area_ = gSum(magSf()); - } - - return area_; -} - - -bool Foam::sampledSurface::withSurfaceFields() const -{ - return false; -} - - -Foam::tmp Foam::sampledSurface::sample -( - const surfaceScalarField& sField -) const -{ - NotImplemented; - return nullptr; -} - - -Foam::tmp Foam::sampledSurface::sample -( - const surfaceVectorField& sField -) const -{ - NotImplemented; - return nullptr; -} - - -Foam::tmp Foam::sampledSurface::sample -( - const surfaceSphericalTensorField& sField -) const -{ - NotImplemented; - return nullptr; -} - - -Foam::tmp Foam::sampledSurface::sample -( - const surfaceSymmTensorField& sField -) const -{ - NotImplemented; - return nullptr; -} - - -Foam::tmp Foam::sampledSurface::sample -( - const surfaceTensorField& sField -) const -{ - NotImplemented; - return nullptr; -} - - -void Foam::sampledSurface::print(Ostream& os) const -{ - os << type(); -} - - Foam::polySurface* Foam::sampledSurface::getRegistrySurface ( const objectRegistry& obr, @@ -250,15 +60,11 @@ Foam::polySurface* Foam::sampledSurface::storeRegistrySurface if (!surfptr) { - surfptr = new polySurface - ( - lookupName, - obr, - true // Add to registry - owned by registry - ); + // Construct null and add to registry (owned by registry) + surfptr = new polySurface(lookupName, obr, true); } - surfptr->deepCopy(*this); // Copy in geometry (removes old fields) + surfptr->copySurface(*this); // Copy in geometry (removes old fields) return surfptr; } @@ -281,13 +87,50 @@ bool Foam::sampledSurface::removeRegistrySurface } -// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // - -Foam::Ostream& Foam::operator<<(Ostream& os, const sampledSurface& s) +Foam::surfMesh* Foam::sampledSurface::getSurfMesh(word lookupName) const { - s.print(os); - os.check(FUNCTION_NAME); - return os; + if (lookupName.empty()) + { + lookupName = this->name(); + } + + return mesh().getObjectPtr(lookupName); +} + + +Foam::surfMesh* Foam::sampledSurface::storeSurfMesh(word lookupName) const +{ + if (lookupName.empty()) + { + lookupName = this->name(); + } + + surfMesh* surfptr = getSurfMesh(); + + if (!surfptr) + { + // Construct null and add owned by registry + surfptr = new surfMesh(lookupName, mesh()); + + surfptr->store(); // Add to registry - owned by registry + } + + surfptr->copySurface(*this); // Copy in geometry (removes old fields) + + return surfptr; +} + + +bool Foam::sampledSurface::removeSurfMesh(word lookupName) const +{ + surfMesh* surfptr = getSurfMesh(lookupName); + + if (surfptr) + { + return mesh().checkOut(*surfptr); + } + + return false; } diff --git a/src/sampling/sampledSurface/sampledSurface/sampledSurfaceTemplates.C b/src/sampling/sampledSurface/sampledSurface/sampledSurfaceTemplates.C index 31794db898..3d07a7a2ae 100644 --- a/src/sampling/sampledSurface/sampledSurface/sampledSurfaceTemplates.C +++ b/src/sampling/sampledSurface/sampledSurface/sampledSurfaceTemplates.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- | Copyright (C) 2011-2016 OpenFOAM Foundation @@ -116,4 +116,100 @@ Foam::sampledSurface::pointAverage } +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +bool Foam::sampledSurface::storeRegistryField +( + const objectRegistry& obr, + const word& fieldName, + const dimensionSet& dims, + const Field& values, + word lookupName +) const +{ + polySurface* surfptr = this->getRegistrySurface(obr, lookupName); + + if (surfptr) + { + surfptr->storeField + ( + fieldName, dims, values + ); + } + + return surfptr; +} + + +template +bool Foam::sampledSurface::storeRegistryField +( + const objectRegistry& obr, + const word& fieldName, + const dimensionSet& dims, + Field&& values, + word lookupName +) const +{ + polySurface* surfptr = this->getRegistrySurface(obr, lookupName); + + if (surfptr) + { + surfptr->storeField + ( + fieldName, dims, std::move(values) + ); + } + + return surfptr; +} + + +template +bool Foam::sampledSurface::storeSurfMeshField +( + const word& fieldName, + const dimensionSet& dims, + const Field& values, + word lookupName +) const +{ + surfMesh* surfptr = this->getSurfMesh(lookupName); + + if (surfptr) + { + surfptr->storeField + ( + fieldName, dims, values + ); + } + + return surfptr; +} + + +template +bool Foam::sampledSurface::storeSurfMeshField +( + const word& fieldName, + const dimensionSet& dims, + Field&& values, + word lookupName +) const +{ + surfMesh* surfptr = this->getSurfMesh(lookupName); + + if (surfptr) + { + surfptr->storeField + ( + fieldName, dims, std::move(values) + ); + } + + return surfptr; +} + + // ************************************************************************* // diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C index c72f0ce2ec..5256a377ef 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C @@ -26,15 +26,15 @@ License \*---------------------------------------------------------------------------*/ #include "sampledSurfaces.H" -#include "volFields.H" -#include "dictionary.H" -#include "Time.H" -#include "IOmanip.H" -#include "interpolationCell.H" -#include "volPointInterpolation.H" -#include "PatchTools.H" +#include "polySurface.H" + #include "mapPolyMesh.H" -#include "sampledTriSurfaceMesh.H" +#include "stringListOps.H" +#include "volFields.H" +#include "HashOps.H" +#include "PstreamCombineReduceOps.H" +#include "Time.H" +#include "UIndirectList.H" #include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -51,66 +51,154 @@ namespace Foam ); } -bool Foam::sampledSurfaces::verbose_ = false; Foam::scalar Foam::sampledSurfaces::mergeTol_ = 1e-10; // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // -void Foam::sampledSurfaces::writeGeometry() const +Foam::polySurface* Foam::sampledSurfaces::getRegistrySurface +( + const sampledSurface& s +) const { - // Write to time directory under outputPath_ - // Skip surfaces without faces (eg, a failed cut-plane) + return s.getRegistrySurface + ( + storedObjects(), + IOobject::groupName(name(), s.name()) + ); +} - const fileName outputDir = outputPath_/time_.timeName(); - forAll(*this, surfi) +Foam::polySurface* Foam::sampledSurfaces::storeRegistrySurface +( + const sampledSurface& s +) +{ + return s.storeRegistrySurface + ( + storedObjects(), + IOobject::groupName(name(), s.name()) + ); +} + + +bool Foam::sampledSurfaces::removeRegistrySurface +( + const sampledSurface& s +) +{ + return s.removeRegistrySurface + ( + storedObjects(), + IOobject::groupName(name(), s.name()) + ); +} + + +void Foam::sampledSurfaces::countFields() +{ + wordList allFields; // Just needed for warnings + HashTable selected; + + if (loadFromFiles_) { - const sampledSurface& s = operator[](surfi); + // Check files for a particular time + IOobjectList objects(obr_, obr_.time().timeName()); - if (Pstream::parRun()) + allFields = objects.names(); + selected = objects.classes(fieldSelection_); + } + else + { + // Check currently available fields + allFields = obr_.names(); + selected = obr_.classes(fieldSelection_); + } + + if (Pstream::parRun()) + { + Pstream::mapCombineGather(selected, HashSetOps::plusEqOp()); + Pstream::mapCombineScatter(selected); + } + + + DynamicList