diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.C b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.C index 209b45e368..49cc85a356 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.C +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.C @@ -308,12 +308,12 @@ Foam::tmp Foam::automatic::load() ( surface_.searchableSurface::time() ), - surfaceName_.lessExt().name(), + "cellSize_" + surfaceName_.lessExt().name(), surface_.points(), faces, + true, "cellSize", - pointCellSize, - true + pointCellSize ); } diff --git a/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.C b/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.C index f3db6f64dc..f539b5ef14 100644 --- a/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.C +++ b/applications/utilities/mesh/manipulation/checkMesh/checkGeometry.C @@ -526,12 +526,12 @@ void Foam::writeAMIWeightsSum vtkSurfaceWriter(mesh.time().writeFormat()).write ( file.path(), - file.name(), + "weightsSum_" + file.name(), mergedPoints, mergedFaces, + false, "weightsSum", - mergedWeights, - false + mergedWeights ); } } diff --git a/applications/utilities/surface/surfaceCheck/surfaceCheck.C b/applications/utilities/surface/surfaceCheck/surfaceCheck.C index f323bc6345..8c8c748a70 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 | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -632,12 +632,12 @@ int main(int argc, char *argv[]) vtkSurfaceWriter(IOstream::ASCII).write ( surfFileName.path(), - surfFileNameBase, + "zone_" + surfFileNameBase, surf.points(), faces, + false, // face based data "zone", - scalarFaceZone, - false // face based data + scalarFaceZone ); } diff --git a/applications/utilities/surface/surfaceFeatures/Make/options b/applications/utilities/surface/surfaceFeatures/Make/options index e96fbb3687..d10c147f3e 100644 --- a/applications/utilities/surface/surfaceFeatures/Make/options +++ b/applications/utilities/surface/surfaceFeatures/Make/options @@ -3,9 +3,11 @@ EXE_INC = \ -I$(LIB_SRC)/meshTools/lnInclude \ -I$(LIB_SRC)/triSurface/lnInclude \ -I$(LIB_SRC)/surfMesh/lnInclude \ - -I$(LIB_SRC)/sampling/lnInclude + -I$(LIB_SRC)/sampling/lnInclude \ + -I$(LIB_SRC)/fileFormats/lnInclude EXE_LIBS = \ -lmeshTools \ -ltriSurface \ - -lsampling + -lsampling \ + -lfileFormats diff --git a/applications/utilities/surface/surfaceFeatures/surfaceFeatures.C b/applications/utilities/surface/surfaceFeatures/surfaceFeatures.C index 8d6d47df37..a538fedb0c 100644 --- a/applications/utilities/surface/surfaceFeatures/surfaceFeatures.C +++ b/applications/utilities/surface/surfaceFeatures/surfaceFeatures.C @@ -34,7 +34,7 @@ Description #include "extendedFeatureEdgeMesh.H" #include "surfaceFeatures.H" #include "triSurfaceFields.H" -#include "vtkSurfaceWriter.H" +#include "vtkWritePolyData.H" #include "systemDict.H" using namespace Foam; @@ -426,6 +426,13 @@ namespace Foam bfeMesh.regIOobject::write(); + // Data to write out in VTK format + wordList writeVTKFieldNames; + boolList writeVTKFieldIsPointValues; + #define DeclareWriteVTKFieldTypeValues(Type, nullArg) \ + PtrList> writeVTKField##Type##Values; + FOR_ALL_FIELD_TYPES(DeclareWriteVTKFieldTypeValues); + #undef DeclareWriteVTKFieldTypeValues // Find distance between close features if (dict.isDict("closeness")) @@ -490,32 +497,18 @@ namespace Foam if (writeVTK) { - const faceList faces(searchSurf.faces()); - - vtkSurfaceWriter(runTime.writeFormat()).write + writeVTKFieldNames.append("internalCloseness"); + writeVTKFieldIsPointValues.append(false); + writeVTKFieldscalarValues.append ( - runTime.path() - /runTime.constant() - /searchableSurface::geometryDir(runTime), - searchSurf.objectRegistry::name(), - searchSurf.points(), - faces, - "internalCloseness", // fieldName - closenessFields.first(), - false // isNodeValues + new scalarField(closenessFields.first()) ); - vtkSurfaceWriter(runTime.writeFormat()).write + writeVTKFieldNames.append("externalCloseness"); + writeVTKFieldIsPointValues.append(false); + writeVTKFieldscalarValues.append ( - runTime.path() - /runTime.constant() - /searchableSurface::geometryDir(runTime), - searchSurf.objectRegistry::name(), - searchSurf.points(), - faces, - "externalCloseness", // fieldName - closenessFields.second(), - false // isNodeValues + new scalarField(closenessFields.second()) ); } } @@ -562,30 +555,18 @@ namespace Foam externalClosenessPointField[meshPointMap[pi]]; } - vtkSurfaceWriter(runTime.writeFormat()).write + writeVTKFieldNames.append("internalPointCloseness"); + writeVTKFieldIsPointValues.append(true); + writeVTKFieldscalarValues.append ( - runTime.path() - /runTime.constant() - /searchableSurface::geometryDir(runTime), - searchSurf.objectRegistry::name(), - searchSurf.points(), - faces, - "internalPointCloseness", // fieldName - internalCloseness, - true // isNodeValues + new scalarField(internalCloseness) ); - vtkSurfaceWriter(runTime.writeFormat()).write + writeVTKFieldNames.append("externalPointCloseness"); + writeVTKFieldIsPointValues.append(true); + writeVTKFieldscalarValues.append ( - runTime.path() - /runTime.constant() - /searchableSurface::geometryDir(runTime), - searchSurf.objectRegistry::name(), - searchSurf.points(), - faces, - "externalPointCloseness", // fieldName - externalCloseness, - true // isNodeValues + new scalarField(externalCloseness) ); } } @@ -615,18 +596,9 @@ namespace Foam if (writeVTK) { - vtkSurfaceWriter(runTime.writeFormat()).write - ( - runTime.path() - /runTime.constant() - /searchableSurface::geometryDir(runTime), - sFeatFileName, - surf.points(), - faces, - "curvature", // fieldName - k, - true // isNodeValues - ); + writeVTKFieldNames.append("curvature"); + writeVTKFieldIsPointValues.append(true); + writeVTKFieldscalarValues.append(new scalarField(k)); } } @@ -689,21 +661,44 @@ namespace Foam if (writeVTK) { - vtkSurfaceWriter(runTime.writeFormat()).write + writeVTKFieldNames.append("featureProximity"); + writeVTKFieldIsPointValues.append(false); + writeVTKFieldscalarValues.append ( - runTime.path() - /runTime.constant() - /searchableSurface::geometryDir(runTime), - sFeatFileName, - surf.points(), - faces, - "featureProximity", // fieldName - featureProximity, - false // isNodeValues + new scalarField(featureProximity) ); } } + if (writeVTK) + { + #define WriteVTKResizeFieldTypeValues(Type, nullArg) \ + writeVTKField##Type##Values.resize(writeVTKFieldNames.size()); + FOR_ALL_FIELD_TYPES(WriteVTKResizeFieldTypeValues) + #undef WriteVTKResizeFieldTypeValues + + vtkWritePolyData::write + ( + runTime.path() + /runTime.constant() + /searchableSurface::geometryDir(runTime) + /sFeatFileName + "Features.vtk", + sFeatFileName, + runTime.writeFormat() == IOstream::BINARY, + surf.points(), + labelList(), + labelListList(), + faces, + writeVTKFieldNames, + writeVTKFieldIsPointValues, + UPtrList>(writeVTKFieldNames.size()) + #define WriteVTKFieldTypeValuesParameter(Type, nullArg) \ + , UPtrList>(writeVTKField##Type##Values) + FOR_ALL_FIELD_TYPES(WriteVTKFieldTypeValuesParameter) + #undef WriteVTKFieldTypeValuesParameter + ); + } + Info<< endl; } diff --git a/src/fileFormats/vtk/vtkWritePolyData.H b/src/fileFormats/vtk/vtkWritePolyData.H index 685f163428..db2f5cf18e 100644 --- a/src/fileFormats/vtk/vtkWritePolyData.H +++ b/src/fileFormats/vtk/vtkWritePolyData.H @@ -36,6 +36,7 @@ SourceFiles #define vtkWritePolyData_H #include "vtkWriteOps.H" +#include "boolList.H" #include "fileName.H" #include "Field.H" diff --git a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C index 843ac7f006..8276c3408e 100644 --- a/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C +++ b/src/functionObjects/field/fieldValues/surfaceFieldValue/surfaceFieldValueTemplates.C @@ -322,12 +322,14 @@ bool Foam::functionObjects::fieldValues::surfaceFieldValue::writeValues surfaceWriterPtr_->write ( outputDir(), - regionTypeNames_[regionType_] + ("_" + regionName_), + fieldName + + '_' + regionTypeNames_[regionType_] + + '_' + regionName_, points, faces, + false, fieldName, - writeValues, - false + writeValues ); } } diff --git a/src/lagrangian/parcel/submodels/CloudFunctionObjects/FacePostProcessing/FacePostProcessing.C b/src/lagrangian/parcel/submodels/CloudFunctionObjects/FacePostProcessing/FacePostProcessing.C index 665581131d..5b0cedaefc 100644 --- a/src/lagrangian/parcel/submodels/CloudFunctionObjects/FacePostProcessing/FacePostProcessing.C +++ b/src/lagrangian/parcel/submodels/CloudFunctionObjects/FacePostProcessing/FacePostProcessing.C @@ -203,20 +203,11 @@ void Foam::FacePostProcessing::write() fZone.name(), allPoints, allFaces, + false, "massTotal", zoneMassTotal[zoneI], - false - ); - - writer->write - ( - this->writeTimeDir(), - fZone.name(), - allPoints, - allFaces, "massFlowRate", - zoneMassFlowRate[zoneI], - false + zoneMassFlowRate[zoneI] ); } } diff --git a/src/lagrangian/parcel/submodels/CloudFunctionObjects/ParticleCollector/ParticleCollector.C b/src/lagrangian/parcel/submodels/CloudFunctionObjects/ParticleCollector/ParticleCollector.C index 32abf356d5..e507419797 100644 --- a/src/lagrangian/parcel/submodels/CloudFunctionObjects/ParticleCollector/ParticleCollector.C +++ b/src/lagrangian/parcel/submodels/CloudFunctionObjects/ParticleCollector/ParticleCollector.C @@ -462,20 +462,11 @@ void Foam::ParticleCollector::write() "collector", points_, faces_, + false, "massTotal", faceMassTotal, - false - ); - - writer->write - ( - this->writeTimeDir(), - "collector", - points_, - faces_, "massFlowRate", - faceMassFlowRate, - false + faceMassFlowRate ); } } diff --git a/src/sampling/Make/files b/src/sampling/Make/files index f416982149..c0e5dcf233 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -44,7 +44,6 @@ sampledSurface/distanceSurface/distanceSurface.C sampledSurface/sampledCuttingPlane/sampledCuttingPlane.C sampledSurface/sampledSurface/sampledSurface.C sampledSurface/sampledSurfaces/sampledSurfaces.C -sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C sampledSurface/sampledTriSurfaceMesh/sampledTriSurfaceMesh.C sampledSurface/thresholdCellFaces/thresholdCellFaces.C sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C @@ -56,10 +55,8 @@ $(surfWriters)/none/noSurfaceWriter.C $(surfWriters)/ensight/ensightSurfaceWriter.C $(surfWriters)/ensight/ensightPTraits.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 graphField/writePatchGraph.C diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C index 4c85563644..effcea847f 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.C @@ -51,46 +51,6 @@ bool Foam::functionObjects::sampledSurfaces::verbose_ = false; Foam::scalar Foam::functionObjects::sampledSurfaces::mergeTol_ = 1e-10; -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -void Foam::functionObjects::sampledSurfaces::writeGeometry() const -{ - // Write to time directory under outputPath_ - // Skip surface without faces (eg, a failed cut-plane) - - const fileName outputDir = outputPath_/mesh_.time().timeName(); - - forAll(*this, si) - { - const sampledSurface& s = operator[](si); - - if (Pstream::parRun()) - { - if (Pstream::master() && mergeList_[si].faces.size()) - { - formatter_->write - ( - outputDir, - s.name(), - mergeList_[si].points, - mergeList_[si].faces - ); - } - } - else if (s.faces().size()) - { - formatter_->write - ( - outputDir, - s.name(), - s.points(), - s.faces() - ); - } - } -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::functionObjects::sampledSurfaces::sampledSurfaces @@ -100,18 +60,8 @@ Foam::functionObjects::sampledSurfaces::sampledSurfaces const dictionary& dict ) : - functionObject(name), + fvMeshFunctionObject(name, t, dict), PtrList(), - mesh_ - ( - refCast - ( - t.lookupObject - ( - dict.lookupOrDefault("region", polyMesh::defaultRegion) - ) - ) - ), outputPath_(fileName::null), fields_(), interpolationScheme_(word::null), @@ -157,8 +107,7 @@ bool Foam::functionObjects::sampledSurfaces::write() // Finalise surfaces, merge points etc. update(); - const label nFields = classifyFields(); - + // Create the output directory if (Pstream::master()) { if (debug) @@ -171,24 +120,81 @@ bool Foam::functionObjects::sampledSurfaces::write() mkDir(outputPath_/mesh_.time().timeName()); } - // Write geometry first if required, - // or when no fields would otherwise be written - if (nFields == 0 || formatter_->separateGeometry()) + // Create a list of names of fields that are actually available + wordList fieldNames; + forAll(fields_, fieldi) { - writeGeometry(); + #define FoundFieldType(Type, nullArg) \ + || foundObject>(fields_[fieldi]) \ + || foundObject>(fields_[fieldi]) + if (false FOR_ALL_FIELD_TYPES(FoundFieldType)) + { + fieldNames.append(fields_[fieldi]); + } + else + { + cannotFindObject(fields_[fieldi]); + } + #undef FoundFieldType } - sampleAndWrite(); - sampleAndWrite(); - sampleAndWrite(); - sampleAndWrite(); - sampleAndWrite(); + // Create table of cached interpolations, to prevent unnecessary work + // when interpolating fields over multiple surfaces + #define DeclareInterpolations(Type, nullArg) \ + HashPtrTable> interpolation##Type##s; + FOR_ALL_FIELD_TYPES(DeclareInterpolations); + #undef DeclareInterpolations - sampleAndWrite(); - sampleAndWrite(); - sampleAndWrite(); - sampleAndWrite(); - sampleAndWrite(); + // Sample and write the surfaces + forAll(*this, surfi) + { + const sampledSurface& s = operator[](surfi); + + #define GenerateFieldTypeValues(Type, nullArg) \ + PtrList> field##Type##Values = \ + sampleType(surfi, fieldNames, interpolation##Type##s); + FOR_ALL_FIELD_TYPES(GenerateFieldTypeValues); + #undef GenerateFieldTypeValues + + if (Pstream::parRun()) + { + if (Pstream::master() && mergeList_[surfi].faces.size()) + { + formatter_->write + ( + outputPath_/mesh_.time().timeName(), + s.name(), + mergeList_[surfi].points, + mergeList_[surfi].faces, + fieldNames, + s.interpolate() + #define FieldTypeValuesParameter(Type, nullArg) \ + , field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesParameter) + #undef FieldTypeValuesParameter + ); + } + } + else + { + if (s.faces().size()) + { + formatter_->write + ( + outputPath_/mesh_.time().timeName(), + s.name(), + s.points(), + s.faces(), + fieldNames, + s.interpolate() + #define FieldTypeValuesParameter(Type, nullArg) \ + , field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesParameter) + #undef FieldTypeValuesParameter + ); + } + } + } } return true; diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H index b5b794cb54..abea70919d 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfaces.H @@ -75,7 +75,7 @@ SourceFiles #ifndef functionObjects_sampledSurfaces_H #define functionObjects_sampledSurfaces_H -#include "functionObject.H" +#include "fvMeshFunctionObject.H" #include "sampledSurface.H" #include "surfaceWriter.H" #include "volFieldsFwd.H" @@ -101,7 +101,7 @@ namespace functionObjects class sampledSurfaces : - public functionObject, + public fvMeshFunctionObject, public PtrList { // Private classes @@ -135,9 +135,6 @@ class sampledSurfaces // Private Data - //- Const reference to fvMesh - const fvMesh& mesh_; - //- Output path fileName outputPath_; @@ -165,41 +162,25 @@ class sampledSurfaces // Private Member Functions - - //- Return number of fields - label classifyFields(); - - //- Write geometry only - void writeGeometry() const; - - //- Write sampled fieldName on surface and on outputDir path + //- Sample all fields of a type on a given surface template - void writeSurface + PtrList> sampleLocalType ( - const Field& values, - const label surfI, - const word& fieldName, - const fileName& outputDir + const label surfi, + const wordList& fieldNames, + HashPtrTable>& interpolations ); - //- Sample and write a particular volume field + //- Sample all fields of a type on a given surface and combine on the + // master for writing template - void sampleAndWrite + PtrList> sampleType ( - const GeometricField& + const label surfi, + const wordList& fieldNames, + HashPtrTable>& interpolations ); - //- Sample and write a particular surface field - template - void sampleAndWrite - ( - const GeometricField& - ); - - //- Sample and write all sampled fields - template - void sampleAndWrite(); - public: diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C deleted file mode 100644 index c6fe8fc135..0000000000 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesGrouping.C +++ /dev/null @@ -1,53 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "sampledSurfaces.H" - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -Foam::label Foam::functionObjects::sampledSurfaces::classifyFields() -{ - label nFields = 0; - - // Check currently available fields - forAll(fields_, i) - { - if (mesh_.objectRegistry::found(fields_[i])) - { - nFields++; - } - else - { - WarningInFunction - << "Cannot find registered field matching " - << fields_[i] << endl; - } - } - - return nFields; -} - - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C index cd0fd152ef..65905be4ca 100644 --- a/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C +++ b/src/sampling/sampledSurface/sampledSurfaces/sampledSurfacesTemplates.C @@ -32,157 +32,151 @@ License // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template -void Foam::functionObjects::sampledSurfaces::writeSurface +Foam::PtrList> +Foam::functionObjects::sampledSurfaces::sampleLocalType ( - const Field& values, - const label surfI, - const word& fieldName, - const fileName& outputDir + const label surfi, + const wordList& fieldNames, + HashPtrTable>& interpolations ) { - const sampledSurface& s = operator[](surfI); + PtrList> fieldTypeValues(fieldNames.size()); + + const sampledSurface& s = operator[](surfi); + + autoPtr> interpolationPtr; + + forAll(fieldNames, fieldi) + { + const word& name = fieldNames[fieldi]; + + if (mesh_.foundObject>(name)) + { + const VolField& vf = + mesh_.lookupObject>(name); + + if (s.interpolate()) + { + if (!interpolations.found(name)) + { + interpolations.insert + ( + name, + interpolation::New + ( + interpolationScheme_, + vf + ).ptr() + ); + } + + fieldTypeValues.set + ( + fieldi, + s.interpolate(*interpolations[name]).ptr() + ); + } + else + { + fieldTypeValues.set(fieldi, s.sample(vf).ptr()); + } + } + else if (mesh_.foundObject>(name)) + { + const SurfaceField& sf = + mesh_.lookupObject>(name); + + fieldTypeValues.set(fieldi, s.sample(sf).ptr()); + } + } + + return fieldTypeValues; +} + + +template +Foam::PtrList> +Foam::functionObjects::sampledSurfaces::sampleType +( + const label surfi, + const wordList& fieldNames, + HashPtrTable>& interpolations +) +{ + // Generate local samples + PtrList> fieldTypeValues = + sampleLocalType(surfi, fieldNames, interpolations); if (Pstream::parRun()) { // Collect values from all processors - List> gatheredValues(Pstream::nProcs()); - gatheredValues[Pstream::myProcNo()] = values; - Pstream::gatherList(gatheredValues); + PtrList>> gatheredTypeValues(fieldNames.size()); + forAll(fieldNames, fieldi) + { + if (fieldTypeValues.set(fieldi)) + { + gatheredTypeValues.set + ( + fieldi, + new List>(Pstream::nProcs()) + ); + gatheredTypeValues[fieldi][Pstream::myProcNo()] = + fieldTypeValues[fieldi]; + Pstream::gatherList(gatheredTypeValues[fieldi]); + } + } + // Clear the local field values + fieldTypeValues.clear(); + fieldTypeValues.resize(fieldNames.size()); + + // Combine on the master if (Pstream::master()) { // Combine values into single field - Field allValues - ( - ListListOps::combine> - ( - gatheredValues, - accessOp>() - ) - ); - - // Renumber (point data) to correspond to merged points - if (mergeList_[surfI].pointsMap.size() == allValues.size()) + forAll(fieldNames, fieldi) { - inplaceReorder(mergeList_[surfI].pointsMap, allValues); - allValues.setSize(mergeList_[surfI].points.size()); + if (gatheredTypeValues.set(fieldi)) + { + fieldTypeValues.set + ( + fieldi, + new Field + ( + ListListOps::combine> + ( + gatheredTypeValues[fieldi], + accessOp>() + ) + ) + ); + } } - // Write to time directory under outputPath_ - // skip surface without faces (eg, a failed cut-plane) - if (mergeList_[surfI].faces.size()) + // Renumber point data to correspond to merged points + forAll(fieldNames, fieldi) { - formatter_->write - ( - outputDir, - s.name(), - mergeList_[surfI].points, - mergeList_[surfI].faces, - fieldName, - allValues, - s.interpolate() - ); + if (fieldTypeValues.set(fieldi)) + { + if + ( + mergeList_[surfi].pointsMap.size() + == fieldTypeValues[fieldi].size() + ) + { + Field f(fieldTypeValues[fieldi]); + + inplaceReorder(mergeList_[surfi].pointsMap, f); + f.setSize(mergeList_[surfi].points.size()); + + fieldTypeValues.set(fieldi, new Field(f, true)); + } + } } } } - else - { - // Write to time directory under outputPath_ - // skip surface without faces (eg, a failed cut-plane) - if (s.faces().size()) - { - formatter_->write - ( - outputDir, - s.name(), - s.points(), - s.faces(), - fieldName, - values, - s.interpolate() - ); - } - } -} - -template -void Foam::functionObjects::sampledSurfaces::sampleAndWrite -( - const GeometricField& vField -) -{ - // interpolator for this field - autoPtr> interpolatorPtr; - - const word& fieldName = vField.name(); - const fileName outputDir = outputPath_/vField.time().timeName(); - - forAll(*this, surfI) - { - const sampledSurface& s = operator[](surfI); - - Field values; - - if (s.interpolate()) - { - if (interpolatorPtr.empty()) - { - interpolatorPtr = interpolation::New - ( - interpolationScheme_, - vField - ); - } - - values = s.interpolate(interpolatorPtr()); - } - else - { - values = s.sample(vField); - } - - writeSurface(values, surfI, fieldName, outputDir); - } -} - - -template -void Foam::functionObjects::sampledSurfaces::sampleAndWrite -( - const GeometricField& sField -) -{ - const word& fieldName = sField.name(); - const fileName outputDir = outputPath_/sField.time().timeName(); - - forAll(*this, surfI) - { - const sampledSurface& s = operator[](surfI); - Field values(s.sample(sField)); - writeSurface(values, surfI, fieldName, outputDir); - } -} - - -template -void Foam::functionObjects::sampledSurfaces::sampleAndWrite() -{ - forAll(fields_, fieldi) - { - if (mesh_.thisDb().foundObject(fields_[fieldi])) - { - if (Pstream::master() && verbose_) - { - Pout<< "sampleAndWrite: " << fields_[fieldi] << endl; - } - - sampleAndWrite - ( - mesh_.thisDb().lookupObject(fields_[fieldi]) - ); - } - } + return fieldTypeValues; } diff --git a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C index 519486c31d..935afab3a3 100644 --- a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -29,87 +29,17 @@ License #include "IOmanip.H" #include "ensightPartFaces.H" #include "ensightPTraits.H" -#include "makeSurfaceWriterMethods.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { - makeSurfaceWriterType(ensightSurfaceWriter); + defineTypeNameAndDebug(ensightSurfaceWriter, 0); addToRunTimeSelectionTable(surfaceWriter, ensightSurfaceWriter, wordDict); } -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -template -void Foam::ensightSurfaceWriter::Write -( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues -) const -{ - if (!isDir(outputDir/fieldName)) - { - mkDir(outputDir/fieldName); - } - - // const scalar timeValue = Foam::name(this->mesh().time().timeValue()); - const scalar timeValue = 0.0; - - OFstream osCase(outputDir/fieldName/surfaceName + ".case"); - ensightGeoFile osGeom - ( - outputDir/fieldName/surfaceName + ".000.mesh", - writeFormat_ - ); - ensightFile osField - ( - outputDir/fieldName/surfaceName + ".000." + fieldName, - writeFormat_ - ); - - if (debug) - { - Info<< "Writing case file to " << osCase.name() << endl; - } - - osCase - << "FORMAT" << nl - << "type: ensight gold" << nl - << nl - << "GEOMETRY" << nl - << "model: 1 " << osGeom.name().name() << nl - << nl - << "VARIABLE" << nl - << ensightPTraits::typeName << " per " - << word(isNodeValues ? "node:" : "element:") << setw(10) << 1 - << " " << fieldName - << " " << surfaceName.c_str() << ".***." << fieldName << nl - << nl - << "TIME" << nl - << "time set: 1" << nl - << "number of steps: 1" << nl - << "filename start number: 0" << nl - << "filename increment: 1" << nl - << "time values:" << nl - << timeValue << nl - << nl; - - ensightPartFaces ensPart(0, osGeom.name().name(), points, faces, true); - osGeom << ensPart; - - // Write field - osField.writeKeyword(ensightPTraits::typeName); - ensPart.writeField(osField, values, isNodeValues); -} - - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::ensightSurfaceWriter::ensightSurfaceWriter @@ -140,7 +70,13 @@ void Foam::ensightSurfaceWriter::write const fileName& outputDir, const fileName& surfaceName, const pointField& points, - const faceList& faces + const faceList& faces, + const wordList& fieldNames, + const bool writePointValues + #define FieldTypeValuesConstArg(Type, nullArg) \ + , const UPtrList>& field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesConstArg) + #undef FieldTypeValuesConstArg ) const { if (!isDir(outputDir)) @@ -166,10 +102,34 @@ void Foam::ensightSurfaceWriter::write osCase << "FORMAT" << nl << "type: ensight gold" << nl - << nl + << nl; + + osCase << "GEOMETRY" << nl << "model: 1 " << osGeom.name().name() << nl - << nl + << nl; + + osCase + << "VARIABLE" << nl; + forAll(fieldNames, fieldi) + { + #define WriteTypeCase(Type, nullArg) \ + if (field##Type##Values.set(fieldi)) \ + { \ + osCase \ + << ensightPTraits::typeName << " per " \ + << word(writePointValues? "node:" : "element:") \ + << setw(10) << 1 << " " << fieldNames[fieldi] \ + << " " << surfaceName.c_str() << ".***." \ + << fieldNames[fieldi] << nl; \ + } + FOR_ALL_FIELD_TYPES(WriteTypeCase); + #undef WriteTypeCase + } + osCase + << nl; + + osCase << "TIME" << nl << "time set: 1" << nl << "number of steps: 1" << nl @@ -181,11 +141,31 @@ void Foam::ensightSurfaceWriter::write ensightPartFaces ensPart(0, osGeom.name().name(), points, faces, true); osGeom << ensPart; + + forAll(fieldNames, fieldi) + { + #define WriteTypeValues(Type, nullArg) \ + if (field##Type##Values.set(fieldi)) \ + { \ + ensightFile osField \ + ( \ + outputDir/surfaceName \ + + ".000." \ + + fieldNames[fieldi], \ + writeFormat_ \ + ); \ + osField.writeKeyword(ensightPTraits::typeName); \ + ensPart.writeField \ + ( \ + osField, \ + field##Type##Values[fieldi], \ + writePointValues \ + ); \ + } + FOR_ALL_FIELD_TYPES(WriteTypeValues); + #undef WriteTypeValues + } } -// create write methods -defineSurfaceWriterWriteFields(Foam::ensightSurfaceWriter); - - // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H index bec28a7b07..00eef78dfc 100644 --- a/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/ensight/ensightSurfaceWriter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -50,22 +50,6 @@ class ensightSurfaceWriter : public surfaceWriter { - // Private Member Functions - - //- Templated write operation - template - void Write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues - ) const; - - public: //- Runtime type information @@ -87,88 +71,23 @@ public: // Member Functions - //- True if the surface format supports geometry in a separate file. - // False if geometry and field must be in a single file - virtual bool separateGeometry() - { - return true; - } - - - //- Write single surface geometry to file. - virtual void write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces - ) const; - - - //- Write scalarField for a single surface to file. - // One value per face or vertex (isNodeValues = true) + //- Write fields for a single surface to file. virtual void write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface const pointField& points, const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues + const wordList& fieldNames, // names of fields + const bool writePointValues + #define FieldTypeValuesConstArg(Type, nullArg) \ + , const UPtrList>& field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesConstArg) + #undef FieldTypeValuesConstArg ) const; - //- Write vectorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; - - //- Write sphericalTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; - - //- Write symmTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; - - //- Write tensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; + //- Inherit base class templated write + using surfaceWriter::write; }; diff --git a/src/sampling/sampledSurface/writers/foam/foamSurfaceWriter.C b/src/sampling/sampledSurface/writers/foam/foamSurfaceWriter.C index bccc4b06b4..94f27ee34a 100644 --- a/src/sampling/sampledSurface/writers/foam/foamSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/foam/foamSurfaceWriter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -26,54 +26,14 @@ License #include "foamSurfaceWriter.H" #include "OFstream.H" #include "OSspecific.H" -#include "makeSurfaceWriterMethods.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { - makeSurfaceWriterType(foamSurfaceWriter); -} - - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -template -void Foam::foamSurfaceWriter::Write -( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues -) const -{ - const fileName surfaceDir(outputDir/surfaceName); - - if (!isDir(surfaceDir)) - { - mkDir(surfaceDir); - } - - if (debug) - { - Info<< "Writing field " << fieldName << " to " << surfaceDir << endl; - } - - // Geometry should already have been written - // Values to separate directory (e.g. "scalarField/p") - - const fileName foamName(pTraits::typeName); - const fileName valuesDir(surfaceDir/(foamName + Field::typeName)); - - if (!isDir(valuesDir)) - { - mkDir(valuesDir); - } - - OFstream(valuesDir/fieldName, writeFormat_)() << values; + defineTypeNameAndDebug(foamSurfaceWriter, 0); + addToRunTimeSelectionTable(surfaceWriter, foamSurfaceWriter, word); } @@ -101,7 +61,13 @@ void Foam::foamSurfaceWriter::write const fileName& outputDir, const fileName& surfaceName, const pointField& points, - const faceList& faces + const faceList& faces, + const wordList& fieldNames, + const bool writePointValues + #define FieldTypeValuesConstArg(Type, nullArg) \ + , const UPtrList>& field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesConstArg) + #undef FieldTypeValuesConstArg ) const { const fileName surfaceDir(outputDir/surfaceName); @@ -125,18 +91,45 @@ void Foam::foamSurfaceWriter::write // Face centers. Not really necessary but very handy when reusing as inputs // for e.g. timeVaryingMapped bc. pointField faceCentres(faces.size(), Zero); - forAll(faces, facei) { faceCentres[facei] = faces[facei].centre(points); } - OFstream(surfaceDir/"faceCentres", writeFormat_)() << faceCentres; + + // Fields + forAll(fieldNames, fieldi) + { + if (debug) + { + Info<< "Writing field " << fieldNames[fieldi] << " to " + << surfaceDir << endl; + } + + #define WriteFieldType(Type, nullArg) \ + if (field##Type##Values.set(fieldi)) \ + { \ + const fileName valuesDir \ + ( \ + surfaceDir \ + /( \ + word(pTraits::typeName) \ + + word(Field::typeName) \ + ) \ + ); \ + \ + if (!isDir(valuesDir)) \ + { \ + mkDir(valuesDir); \ + } \ + \ + OFstream(valuesDir/fieldNames[fieldi], writeFormat_)() \ + << field##Type##Values[fieldi]; \ + } + FOR_ALL_FIELD_TYPES(WriteFieldType); + #undef WriteFieldType + } } -// Create write methods -defineSurfaceWriterWriteFields(Foam::foamSurfaceWriter); - - // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/foam/foamSurfaceWriter.H b/src/sampling/sampledSurface/writers/foam/foamSurfaceWriter.H index 2487fba2b8..22d734f2ca 100644 --- a/src/sampling/sampledSurface/writers/foam/foamSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/foam/foamSurfaceWriter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -51,22 +51,6 @@ class foamSurfaceWriter : public surfaceWriter { - // Private Member Functions - - //- Templated write operation - template - void Write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues - ) const; - - public: //- Runtime type information @@ -85,87 +69,23 @@ public: // Member Functions - //- True if the surface format supports geometry in a separate file. - // False if geometry and field must be in a single file - virtual bool separateGeometry() - { - return true; - } - - //- Write single surface geometry to file. - virtual void write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces - ) const; - - - //- Write scalarField for a single surface to file. - // One value per face or vertex (isNodeValues = true) + //- Write fields for a single surface to file. virtual void write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface const pointField& points, const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues + const wordList& fieldNames, // names of fields + const bool writePointValues + #define FieldTypeValuesConstArg(Type, nullArg) \ + , const UPtrList>& field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesConstArg) + #undef FieldTypeValuesConstArg ) const; - //- Write vectorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; - - //- Write sphericalTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; - - //- Write symmTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; - - //- Write tensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; + //- Inherit base class templated write + using surfaceWriter::write; }; diff --git a/src/sampling/sampledSurface/writers/makeSurfaceWriterMethods.H b/src/sampling/sampledSurface/writers/makeSurfaceWriterMethods.H deleted file mode 100644 index ef61dd6bf7..0000000000 --- a/src/sampling/sampledSurface/writers/makeSurfaceWriterMethods.H +++ /dev/null @@ -1,90 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -InClass - Foam::makeSurfaceWriterMethods - -Description - Convenience macros for instantiating writer methods for surfaceWriter - classes. - -\*---------------------------------------------------------------------------*/ - -#ifndef makeSurfaceWriterMethods_H -#define makeSurfaceWriterMethods_H - -#include "surfaceWriter.H" -#include "addToRunTimeSelectionTable.H" - -namespace Foam -{ - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#define makeSurfaceWriterType(ThisClass) \ - defineTypeNameAndDebug(ThisClass, 0); \ - addToRunTimeSelectionTable(surfaceWriter, ThisClass, word) - - -#define defineSurfaceWriterWriteField(ThisClass, FieldType) \ - void ThisClass::write \ - ( \ - const fileName& outputDir, \ - const fileName& surfaceName, \ - const pointField& points, \ - const faceList& faces, \ - const word& fieldName, \ - const Field& values, \ - const bool isNodeValues \ - ) const \ - { \ - Write \ - ( \ - outputDir, \ - surfaceName, \ - points, \ - faces, \ - fieldName, \ - values, \ - isNodeValues \ - ); \ - } - - -#define defineSurfaceWriterWriteFields(ThisClass) \ - defineSurfaceWriterWriteField(ThisClass, scalar); \ - defineSurfaceWriterWriteField(ThisClass, vector); \ - defineSurfaceWriterWriteField(ThisClass, sphericalTensor); \ - defineSurfaceWriterWriteField(ThisClass, symmTensor); \ - defineSurfaceWriterWriteField(ThisClass, tensor) - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.C b/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.C deleted file mode 100644 index 2efc345062..0000000000 --- a/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.C +++ /dev/null @@ -1,406 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2021 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "nastranSurfaceWriter.H" -#include "polygonTriangulate.H" -#include "makeSurfaceWriterMethods.H" - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -namespace Foam -{ - makeSurfaceWriterType(nastranSurfaceWriter); - addToRunTimeSelectionTable(surfaceWriter, nastranSurfaceWriter, wordDict); - - // create write methods - defineSurfaceWriterWriteFields(nastranSurfaceWriter); - - template<> - const char* NamedEnum::names[] = - { - "short", - "long", - "free" - }; - - const NamedEnum - nastranSurfaceWriter::formatNames_; -} - - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -void Foam::nastranSurfaceWriter::formatOS(OFstream& os) const -{ - os.setf(ios_base::scientific); - - // Capitalise the E marker - os.setf(ios_base::uppercase); - - label prec = 0; - label offset = 7; - switch (format_) - { - case (wfShort): - case (wfFree): - { - prec = 8 - offset; - break; - } - case (wfLong): - { - prec = 16 - offset; - break; - } - default: - { - } - } - - os.precision(prec); -} - - -void Foam::nastranSurfaceWriter::writeCoord -( - const point& p, - const label pointi, - OFstream& os -) const -{ - // Fixed short/long formats: - // 1 GRID - // 2 ID : point ID - requires starting index of 1 - // 3 CP : co-ordinate system ID (blank) - // 4 X1 : point x cp-ordinate - // 5 X2 : point x cp-ordinate - // 6 X3 : point x cp-ordinate - // 7 CD : co-ordinate system for displacements (blank) - // 8 PS : single point constraints (blank) - // 9 SEID : super-element ID - - switch (format_) - { - case wfShort: - { - os.setf(ios_base::left); - os << setw(8) << "GRID"; - os.unsetf(ios_base::left); - os.setf(ios_base::right); - os << setw(8) << pointi + 1 - << " " - << setw(8) << p.x() - << setw(8) << p.y() - << setw(8) << p.z() - << nl; - os.unsetf(ios_base::right); - - break; - } - case wfLong: - { - os.setf(ios_base::left); - os << setw(8) << "GRID*"; - os.unsetf(ios_base::left); - os.setf(ios_base::right); - os << setw(16) << pointi + 1 - << " " - << setw(16) << p.x() - << setw(16) << p.y() - << nl; - os.unsetf(ios_base::right); - os.setf(ios_base::left); - os << setw(8) << "*"; - os.unsetf(ios_base::left); - os.setf(ios_base::right); - os << setw(16) << p.z() - << nl; - os.unsetf(ios_base::right); - - break; - } - case wfFree: - { - os << "GRID" - << ',' << pointi + 1 - << ',' - << ',' << p.x() - << ',' << p.y() - << ',' << p.z() - << nl; - - break; - } - default: - { - FatalErrorInFunction - << "Unknown format enumeration" << abort(FatalError); - } - } -} - -void Foam::nastranSurfaceWriter::writeFace -( - const word& faceType, - const labelList& facePts, - label& nFace, - OFstream& os -) const -{ - // Only valid surface elements are CTRIA3 and CQUAD4 - - // Fixed short/long formats: - // 1 CQUAD4 - // 2 EID : element ID - // 3 PID : property element ID; default = EID (blank) - // 4 G1 : grid point index - requires starting index of 1 - // 5 G2 : grid point index - // 6 G3 : grid point index - // 7 G4 : grid point index - // 8 onwards - not used - - // For CTRIA3 elements, cols 7 onwards are not used - - switch (format_) - { - case wfShort: - { - os.setf(ios_base::left); - os << setw(8) << faceType; - os.unsetf(ios_base::left); - os.setf(ios_base::right); - os << setw(8) << nFace++ - << " "; - - forAll(facePts, i) - { - os << setw(8) << facePts[i] + 1; - } - - os << nl; - os.unsetf(ios_base::right); - - break; - } - case wfLong: - { - os.setf(ios_base::left); - os << setw(8) << word(faceType + "*"); - os.unsetf(ios_base::left); - os.setf(ios_base::right); - os << setw(16) << nFace++ - << " "; - - forAll(facePts, i) - { - os << setw(16) << facePts[i] + 1; - if (i == 1) - { - os << nl; - os.unsetf(ios_base::right); - os.setf(ios_base::left); - os << setw(8) << "*"; - os.unsetf(ios_base::left); - os.setf(ios_base::right); - } - } - - os << nl; - os.unsetf(ios_base::right); - - break; - } - case wfFree: - { - os << faceType << ',' - << ++nFace << ','; - - forAll(facePts, i) - { - os << ',' << facePts[i] + 1; - } - - os << nl; - - break; - } - default: - { - FatalErrorInFunction - << "Unknown format enumeration" << abort(FatalError); - } - } - -} - - -void Foam::nastranSurfaceWriter::writeGeometry -( - const pointField& points, - const faceList& faces, - List>& decomposedFaces, - OFstream& os -) const -{ - // write points - - os << "$" << nl - << "$ Points" << nl - << "$" << nl; - - forAll(points, pointi) - { - writeCoord(points[pointi], pointi, os); - } - - - // write faces - - os << "$" << nl - << "$ Faces" << nl - << "$" << nl; - - label nFace = 1; - - polygonTriangulate triEngine; - - forAll(faces, facei) - { - const face& f = faces[facei]; - - if (f.size() == 3) - { - writeFace("CTRIA3", faces[facei], nFace, os); - decomposedFaces[facei].append(faces[facei]); - } - else if (f.size() == 4) - { - writeFace("CQUAD4", faces[facei], nFace, os); - decomposedFaces[facei].append(faces[facei]); - } - else - { - // decompose poly face into tris - triEngine.triangulate(UIndirectList(points, f)); - forAll(triEngine.triPoints(), triI) - { - const face f(triEngine.triPoints(triI, f)); - writeFace("CTRIA3", f, nFace, os); - decomposedFaces[facei].append(f); - } - } - } -} - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::nastranSurfaceWriter::nastranSurfaceWriter -( - const IOstream::streamFormat writeFormat -) -: - surfaceWriter(writeFormat), - format_(wfShort), - fieldMap_(), - scale_(1.0) -{} - - -Foam::nastranSurfaceWriter::nastranSurfaceWriter(const dictionary& optDict) -: - surfaceWriter(optDict), - format_(wfLong), - fieldMap_(), - scale_(1.0) -{ - const dictionary& nastranDict(optDict.lookup("nastranOptions")); - - if (nastranDict.found("format")) - { - format_ = formatNames_.read(nastranDict.lookup("format")); - } - - List> fieldSet(nastranDict.lookup("fields")); - - forAll(fieldSet, i) - { - fieldMap_.insert(fieldSet[i].first(), fieldSet[i].second()); - } - - if (nastranDict.found("scale")) - { - nastranDict.lookup("scale") >> scale_; - } -} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::nastranSurfaceWriter::~nastranSurfaceWriter() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -void Foam::nastranSurfaceWriter::write -( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces -) const -{ - if (!isDir(outputDir)) - { - mkDir(outputDir); - } - - OFstream os(outputDir/surfaceName + ".dat"); - formatOS(os); - - if (debug) - { - Info<< "Writing nastran file to " << os.name() << endl; - } - - os << "TITLE=OpenFOAM " << surfaceName.c_str() << " mesh" << nl - << "$" << nl - << "BEGIN BULK" << nl; - - List> decomposedFaces(faces.size()); - - writeGeometry(points, faces, decomposedFaces, os); - - if (!isDir(outputDir)) - { - mkDir(outputDir); - } - - os << "ENDDATA" << endl; -} - - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.H b/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.H deleted file mode 100644 index 5f561a800a..0000000000 --- a/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriter.H +++ /dev/null @@ -1,267 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2020 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -Class - Foam::nastranSurfaceWriter - -Description - A surface writer for the Nastran file format - both surface mesh and fields - - nastranOptions - { - // From OpenFOAM field name to Nastran field name - fields ((pMean PLOAD2)); - - // Optional scale - scale 2.0; - - // Optional format - format free; // short, long, free - } - -SourceFiles - nastranSurfaceWriter.C - nastranSurfaceWriterTemplates.C - -\*---------------------------------------------------------------------------*/ - -#ifndef nastranSurfaceWriter_H -#define nastranSurfaceWriter_H - -#include "surfaceWriter.H" -#include "NamedEnum.H" -#include "OFstream.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -/*---------------------------------------------------------------------------*\ - Class nastranSurfaceWriter Declaration -\*---------------------------------------------------------------------------*/ - -class nastranSurfaceWriter -: - public surfaceWriter -{ -public: - - enum format - { - wfShort, - wfLong, - wfFree - }; - - static const NamedEnum formatNames_; - - -private: - - // Private Data - - //- Write option - format format_; - - //- Map of OpenFOAM field name vs nastran field name - HashTable fieldMap_; - - //- Scale to apply to values (default = 1.0) - scalar scale_; - - - // Private Member Functions - - //- Initialise the output stream format params - void formatOS(OFstream& os) const; - - //- Write a co-ordinate - void writeCoord - ( - const point& p, - const label pointi, - OFstream& os - ) const; - - //- Write a face element (CTRIA3 or CQUAD4) - void writeFace - ( - const word& faceType, - const labelList& facePts, - label& nFace, - OFstream& os - ) const; - - //- Main driver to write the surface mesh geometry - void writeGeometry - ( - const pointField& points, - const faceList& faces, - List>& decomposedFaces, - OFstream& os - ) const; - - //- Write a face-based value - template - void writeFaceValue - ( - const word& nasFieldName, - const Type& value, - const label EID, - OFstream& os - ) const; - - //- Templated write operation - template - void Write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues - ) const; - - -public: - - //- Runtime type information - TypeName("nastran"); - - - // Constructors - - //- Construct given write format - nastranSurfaceWriter(const IOstream::streamFormat writeFormat); - - //- Construct with some output options - nastranSurfaceWriter(const dictionary& optDict); - - - //- Destructor - virtual ~nastranSurfaceWriter(); - - - // Member Functions - - //- True if the surface format supports geometry in a separate file. - // False if geometry and field must be in a single file - virtual bool separateGeometry() - { - return false; - } - - //- Write single surface geometry to file. - virtual void write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces - ) const; - - //- Write scalarField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues - ) const; - - //- Write vectorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues - ) const; - - //- Write sphericalTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues - ) const; - - //- Write symmTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues - ) const; - - //- Write tensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues - ) const; -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#ifdef NoRepository - #include "nastranSurfaceWriterTemplates.C" -#endif - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriterTemplates.C b/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriterTemplates.C deleted file mode 100644 index 7d0d709ce8..0000000000 --- a/src/sampling/sampledSurface/writers/nastran/nastranSurfaceWriterTemplates.C +++ /dev/null @@ -1,215 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2012-2020 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "OFstream.H" -#include "IOmanip.H" -#include "OSspecific.H" - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -template -void Foam::nastranSurfaceWriter::writeFaceValue -( - const word& nasFieldName, - const Type& value, - const label EID, - OFstream& os -) const -{ - // Fixed short/long formats: - // 1 Nastran distributed load type, e.g. PLOAD4 - // 2 SID : load set ID - // 3 EID : element ID - // 4 onwards: load values - - label SID = 1; - - Type scaledValue = scale_*value; - - switch (format_) - { - case wfShort: - { - os.setf(ios_base::left); - os << setw(8) << nasFieldName; - os.unsetf(ios_base::left); - os.setf(ios_base::right); - os << setw(8) << SID - << setw(8) << EID; - - for (direction dirI = 0; dirI < pTraits::nComponents; dirI++) - { - os << setw(8) << component(scaledValue, dirI); - } - - os.unsetf(ios_base::right); - - break; - } - case wfLong: - { - os.setf(ios_base::left); - os << setw(8) << word(nasFieldName + "*"); - os.unsetf(ios_base::left); - os.setf(ios_base::right); - os << setw(16) << SID - << setw(16) << EID; - - for (direction dirI = 0; dirI < pTraits::nComponents; dirI++) - { - os << setw(16) << component(scaledValue, dirI); - } - - os.unsetf(ios_base::right); - - os << nl; - - os.setf(ios_base::left); - os << '*'; - os.unsetf(ios_base::left); - - break; - } - case wfFree: - { - os << nasFieldName << ',' - << SID << ',' - << EID; - - for (direction dirI = 0; dirI < pTraits::nComponents; dirI++) - { - os << ',' << component(scaledValue, dirI); - } - - break; - } - default: - { - } - } - - os << nl; -} - - -template -void Foam::nastranSurfaceWriter::Write -( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues -) const -{ - if (!fieldMap_.found(fieldName)) - { - WarningInFunction - << "No mapping found between field " << fieldName - << " and corresponding Nastran field. Available types are:" - << fieldMap_ - << exit(FatalError); - - return; - } - - const word& nasFieldName(fieldMap_[fieldName]); - - if (!isDir(outputDir/fieldName)) - { - mkDir(outputDir/fieldName); - } - - // const scalar timeValue = Foam::name(this->mesh().time().timeValue()); - const scalar timeValue = 0.0; - - OFstream os(outputDir/fieldName/surfaceName + ".dat"); - formatOS(os); - - if (debug) - { - Info<< "Writing nastran file to " << os.name() << endl; - } - - os << "TITLE=OpenFOAM " << surfaceName.c_str() << " " << fieldName - << " data" << nl - << "$" << nl - << "TIME " << timeValue << nl - << "$" << nl - << "BEGIN BULK" << nl; - - List> decomposedFaces(faces.size()); - - writeGeometry(points, faces, decomposedFaces, os); - - - os << "$" << nl - << "$ Field data" << nl - << "$" << nl; - - if (isNodeValues) - { - label n = 0; - - forAll(decomposedFaces, i) - { - const DynamicList& dFaces = decomposedFaces[i]; - forAll(dFaces, facei) - { - Type v = Zero; - const face& f = dFaces[facei]; - - forAll(f, fptI) - { - v += values[f[fptI]]; - } - v /= f.size(); - - writeFaceValue(nasFieldName, v, ++n, os); - } - } - } - else - { - label n = 0; - - forAll(decomposedFaces, i) - { - const DynamicList& dFaces = decomposedFaces[i]; - - forAll(dFaces, facei) - { - writeFaceValue(nasFieldName, values[facei], ++n, os); - } - } - } - - os << "ENDDATA" << endl; -} - - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/none/noSurfaceWriter.C b/src/sampling/sampledSurface/writers/none/noSurfaceWriter.C index 98105b798c..3ff186cdad 100644 --- a/src/sampling/sampledSurface/writers/none/noSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/none/noSurfaceWriter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2019-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2019-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -24,13 +24,14 @@ License \*---------------------------------------------------------------------------*/ #include "noSurfaceWriter.H" -#include "makeSurfaceWriterMethods.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { - makeSurfaceWriterType(noSurfaceWriter); + defineTypeNameAndDebug(noSurfaceWriter, 0); + addToRunTimeSelectionTable(surfaceWriter, noSurfaceWriter, word); } diff --git a/src/sampling/sampledSurface/writers/none/noSurfaceWriter.H b/src/sampling/sampledSurface/writers/none/noSurfaceWriter.H index 2856bc8f10..2286690b96 100644 --- a/src/sampling/sampledSurface/writers/none/noSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/none/noSurfaceWriter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2019-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2019-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -69,85 +69,24 @@ public: // Member Functions - //- Write single surface geometry to file. - virtual void write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces - ) const - {} - - //- Write scalarField for a single surface to file. - // One value per face or vertex (isNodeValues = true) + //- Write fields for a single surface to file. virtual void write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface const pointField& points, const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues + const wordList& fieldNames, // names of fields + const bool writePointValues + #define FieldTypeValuesConstArg(Type, nullArg) \ + , const UPtrList>& field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesConstArg) + #undef FieldTypeValuesConstArg ) const {} - //- Write vectorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const - {} - - //- Write sphericalTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const - {} - - //- Write symmTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const - {} - - //- Write tensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const - {} + //- Inherit base class templated write + using surfaceWriter::write; }; diff --git a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C index aeef6e984d..06b8983d88 100644 --- a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -25,7 +25,6 @@ License #include "proxySurfaceWriter.H" #include "MeshedSurfaceProxy.H" -#include "makeSurfaceWriterMethods.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // @@ -57,7 +56,13 @@ void Foam::proxySurfaceWriter::write const fileName& outputDir, const fileName& surfaceName, const pointField& points, - const faceList& faces + const faceList& faces, + const wordList& fieldNames, + const bool writePointValues + #define FieldTypeValuesConstArg(Type, nullArg) \ + , const UPtrList>& field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesConstArg) + #undef FieldTypeValuesConstArg ) const { // avoid bad values diff --git a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H index ae3f51b717..46d136f189 100644 --- a/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/proxy/proxySurfaceWriter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -51,12 +51,12 @@ class proxySurfaceWriter : public surfaceWriter { - // Private Data //- The associated file extension word ext_; + public: //- Runtime type information @@ -75,93 +75,20 @@ public: // Member Functions - - //- True if the surface format supports geometry in a separate file. - // False if geometry and field must be in a single file - virtual bool separateGeometry() - { - return true; - } - - - //- Write single surface geometry to file. + //- Write fields for a single surface to file. virtual void write ( - const fileName& outputDir, - const fileName& surfaceName, + const fileName& outputDir, // /surface/TIME + const fileName& surfaceName, // name of surface const pointField& points, - const faceList& faces + const faceList& faces, + const wordList& fieldNames, // names of fields + const bool writePointValues + #define FieldTypeValuesConstArg(Type, nullArg) \ + , const UPtrList>& field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesConstArg) + #undef FieldTypeValuesConstArg ) const; - - //- Write scalarField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const - {} - - //- Write vectorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const - {} - - //- Write sphericalTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const - {} - - //- Write symmTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const - {} - - //- Write tensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const - {} }; diff --git a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C index 577bf376b6..51cb9acdc1 100644 --- a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -26,13 +26,13 @@ License #include "rawSurfaceWriter.H" #include "OFstream.H" #include "OSspecific.H" -#include "makeSurfaceWriterMethods.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { - makeSurfaceWriterType(rawSurfaceWriter); + defineTypeNameAndDebug(rawSurfaceWriter, 0); addToRunTimeSelectionTable(surfaceWriter, rawSurfaceWriter, wordDict); } @@ -64,213 +64,45 @@ inline void Foam::rawSurfaceWriter::writeLocation } -namespace Foam +template +void Foam::rawSurfaceWriter::writeHeader +( + Ostream& os, + const word& fieldName +) { - template<> - void Foam::rawSurfaceWriter::writeHeader - ( - Ostream& os, - const word& fieldName, - const Field& values - ) + const label nCmpt = pTraits::nComponents; + + for (direction cmpt = 0; cmpt < nCmpt; ++ cmpt) { - os << values.size() << nl - << "# x y z " << fieldName << nl; + const bool separator = + !fieldName.empty() + && strlen(pTraits::componentNames[cmpt]) > 0; + + if (cmpt) os << token::SPACE; + os << fieldName << (separator ? "_" : "") + << pTraits::componentNames[cmpt]; } - - - template<> - void Foam::rawSurfaceWriter::writeHeader - ( - Ostream& os, - const word& fieldName, - const Field& values - ) - { - os << values.size() << nl - << "# x y z " - << fieldName << "_x " - << fieldName << "_y " - << fieldName << "_z " - << endl; - } - - - template<> - void Foam::rawSurfaceWriter::writeHeader - ( - Ostream& os, - const word& fieldName, - const Field& values - ) - { - os << values.size() << nl - << "# ii " - << fieldName << "_ii" << nl; - } - - - template<> - void Foam::rawSurfaceWriter::writeHeader - ( - Ostream& os, - const word& fieldName, - const Field& values - ) - { - os << values.size() << nl - << "# xx xy xz yy yz "; - for (int i=0; i<6; ++i) - { - os << fieldName << "_" << i << " "; - } - os << endl; - } - - - template<> - void Foam::rawSurfaceWriter::writeHeader - ( - Ostream& os, - const word& fieldName, - const Field& values - ) - { - os << values.size() << nl - << "# xx xy xz yx yy yz zx zy zz"; - for (int i=0; i<9; ++i) - { - os << fieldName << "_" << i << " "; - } - os << nl; - } - - - template<> - inline void Foam::rawSurfaceWriter::writeData - ( - Ostream& os, - const scalar& v - ) - { - os << v << nl; - } - - - template<> - inline void Foam::rawSurfaceWriter::writeData - ( - Ostream& os, - const vector& v - ) - { - os << v[0] << ' ' << v[1] << ' ' << v[2] << nl; - } - - - template<> - inline void Foam::rawSurfaceWriter::writeData - ( - Ostream& os, - const sphericalTensor& v - ) - { - os << v[0] << nl; - } - - - template<> - inline void Foam::rawSurfaceWriter::writeData - ( - Ostream& os, - const symmTensor& v - ) - { - os << v[0] << ' ' << v[1] << ' ' << v[2] << ' ' - << v[3] << ' ' << v[4] << ' ' << v[5] << nl; - } - - - template<> - inline void Foam::rawSurfaceWriter::writeData - ( - Ostream& os, - const tensor& v - ) - { - os << v[0] << ' ' << v[1] << ' ' << v[2] << ' ' - << v[3] << ' ' << v[4] << ' ' << v[5] << ' ' - << v[6] << ' ' << v[7] << ' ' << v[8] << nl; - } - } template -void Foam::rawSurfaceWriter::Write +inline void Foam::rawSurfaceWriter::writeData ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues -) const + Ostream& os, + const Type& v +) { - if (!isDir(outputDir)) - { - mkDir(outputDir); - } + const label nCmpt = pTraits::nComponents; - OFstream os - ( - outputDir/fieldName + '_' + surfaceName + ".raw", - IOstream::ASCII, - IOstream::currentVersion, - writeCompression_ - ); - - if (debug) + for (direction cmpt = 0; cmpt < nCmpt; ++ cmpt) { - Info<< "Writing field " << fieldName << " to " << os.name() << endl; - } - - // Header - os << "# " << fieldName; - if (isNodeValues) - { - os << " POINT_DATA "; - } - else - { - os << " FACE_DATA "; - } - - // Header - writeHeader(os, fieldName, values); - - // Values - if (isNodeValues) - { - forAll(values, elemI) - { - writeLocation(os, points, elemI); - writeData(os, values[elemI]); - } - } - else - { - forAll(values, elemI) - { - writeLocation(os, points, faces, elemI); - writeData(os, values[elemI]); - } + if (cmpt) os << token::SPACE; + os << component(v, cmpt); } } - // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // Foam::rawSurfaceWriter::rawSurfaceWriter @@ -309,7 +141,13 @@ void Foam::rawSurfaceWriter::write const fileName& outputDir, const fileName& surfaceName, const pointField& points, - const faceList& faces + const faceList& faces, + const wordList& fieldNames, + const bool writePointValues + #define FieldTypeValuesConstArg(Type, nullArg) \ + , const UPtrList>& field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesConstArg) + #undef FieldTypeValuesConstArg ) const { if (!isDir(outputDir)) @@ -325,31 +163,71 @@ void Foam::rawSurfaceWriter::write writeCompression_ ); - if (debug) + // Get the number of values + label nValues = 0; + #define GetNValues(Type, nullArg) \ + if (field##Type##Values.set(0)) \ + { \ + nValues = field##Type##Values[0].size(); \ + } + FOR_ALL_FIELD_TYPES(GetNValues); + #undef GetNValues + + // Top header + os << "# " << (writePointValues ? "POINT_DATA " : "FACE_DATA ") + << nValues << nl; + + // Column headers + os << "# "; + writeHeader(os, word::null); + forAll(fieldNames, fieldi) { - Info<< "Writing geometry to " << os.name() << endl; + os << token::SPACE; + + #define WriteTypeHeader(Type, nullArg) \ + if (field##Type##Values.set(fieldi)) \ + { \ + writeHeader(os, fieldNames[fieldi]); \ + } + FOR_ALL_FIELD_TYPES(WriteTypeHeader); + #undef WriteTypeHeader } + os << nl; - - // Header - os << "# geometry NO_DATA " << faces.size() << nl - << "# x y z" << nl; - - // Write faces centres - forAll(faces, elemI) + // Write the values + #define WriteTypeValues(Type, nullArg) \ + if (field##Type##Values.set(fieldi)) \ + { \ + writeData(os, field##Type##Values[fieldi][i]); \ + } + if (writePointValues) { - writeLocation(os, points, faces, elemI); - os << nl; + for (label i = 0; i < nValues; ++ i) + { + writeLocation(os, points, i); + forAll(fieldNames, fieldi) + { + if (fieldi) os << token::SPACE; + FOR_ALL_FIELD_TYPES(WriteTypeValues); + } + os << nl; + } } - - os << nl; + else + { + for (label i = 0; i < nValues; ++ i) + { + writeLocation(os, points, faces, i); + forAll(fieldNames, fieldi) + { + if (fieldi) os << token::SPACE; + FOR_ALL_FIELD_TYPES(WriteTypeValues); + } + os << nl; + } + } + #undef WriteTypeValues } -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -// Create write methods -defineSurfaceWriterWriteFields(Foam::rawSurfaceWriter); - - // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H index ed6ddedb3d..5adfffdbdb 100644 --- a/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/raw/rawSurfaceWriter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -59,6 +59,7 @@ class rawSurfaceWriter // Private Member Functions + //- Write a point location static inline void writeLocation ( Ostream&, @@ -66,6 +67,7 @@ class rawSurfaceWriter const label pointi ); + //- Write a face location static inline void writeLocation ( Ostream&, @@ -74,32 +76,19 @@ class rawSurfaceWriter const label facei ); + //- Write the column header for a given field template static void writeHeader ( Ostream&, - const word& fieldName, - const Field& + const word& fieldName ); + //- Write a piece of data template static inline void writeData(Ostream&, const Type&); - //- Templated write operation - template - void Write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues - ) const; - - public: //- Runtime type information @@ -121,79 +110,19 @@ public: // Member Functions - //- Write single surface geometry to file. - virtual void write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces - ) const; - - - //- Write scalarField for a single surface to file. - // One value per face or vertex (isNodeValues = true) + //- Write fields for a single surface to file. virtual void write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface const pointField& points, const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; - - //- Write vectorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; - - //- Write sphericalTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; - - //- Write symmTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; - - //- Write tensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues + const wordList& fieldNames, // names of fields + const bool writePointValues + #define FieldTypeValuesConstArg(Type, nullArg) \ + , const UPtrList>& field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesConstArg) + #undef FieldTypeValuesConstArg ) const; }; diff --git a/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.C b/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.C deleted file mode 100644 index 75fb78a4a3..0000000000 --- a/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.C +++ /dev/null @@ -1,169 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -\*---------------------------------------------------------------------------*/ - -#include "starcdSurfaceWriter.H" -#include "MeshedSurfaceProxy.H" -#include "makeSurfaceWriterMethods.H" - -// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // - -namespace Foam -{ - makeSurfaceWriterType(starcdSurfaceWriter); -} - - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -namespace Foam -{ - template<> - inline void Foam::starcdSurfaceWriter::writeData - ( - Ostream& os, - const scalar& v - ) - { - os << v << nl; - } - - - template<> - inline void Foam::starcdSurfaceWriter::writeData - ( - Ostream& os, - const vector& v - ) - { - os << v[0] << ' ' << v[1] << ' ' << v[2] << nl; - } - - - template<> - inline void Foam::starcdSurfaceWriter::writeData - ( - Ostream& os, - const sphericalTensor& v - ) - { - os << v[0] << nl; - } - -} - - -template -inline void Foam::starcdSurfaceWriter::writeData -( - Ostream& os, - const Type& v -) -{} - - -template -void Foam::starcdSurfaceWriter::Write -( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues -) const -{ - if (!isDir(outputDir)) - { - mkDir(outputDir); - } - - OFstream os(outputDir/fieldName + '_' + surfaceName + ".usr"); - - if (debug) - { - Info<< "Writing field " << fieldName << " to " << os.name() << endl; - } - - // no header, just write values - forAll(values, elemI) - { - os << elemI+1 << ' '; - writeData(os, values[elemI]); - } -} - - - -// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // - -Foam::starcdSurfaceWriter::starcdSurfaceWriter -( - const IOstream::streamFormat writeFormat -) -: - surfaceWriter(writeFormat) -{} - - -// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // - -Foam::starcdSurfaceWriter::~starcdSurfaceWriter() -{} - - -// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // - -void Foam::starcdSurfaceWriter::write -( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces -) const -{ - if (!isDir(outputDir)) - { - mkDir(outputDir); - } - - fileName outName(outputDir/surfaceName + ".inp"); - - if (debug) - { - Info<< "Writing geometry to " << outName << endl; - } - - MeshedSurfaceProxy(points, faces).write(outName); -} - - -// create write methods -defineSurfaceWriterWriteField(Foam::starcdSurfaceWriter, scalar); -defineSurfaceWriterWriteField(Foam::starcdSurfaceWriter, vector); -defineSurfaceWriterWriteField(Foam::starcdSurfaceWriter, sphericalTensor); - - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.H b/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.H deleted file mode 100644 index 13fbce3f78..0000000000 --- a/src/sampling/sampledSurface/writers/starcd/starcdSurfaceWriter.H +++ /dev/null @@ -1,203 +0,0 @@ -/*---------------------------------------------------------------------------*\ - ========= | - \\ / F ield | OpenFOAM: The Open Source CFD Toolbox - \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation - \\/ M anipulation | -------------------------------------------------------------------------------- -License - This file is part of OpenFOAM. - - OpenFOAM is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - OpenFOAM is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - for more details. - - You should have received a copy of the GNU General Public License - along with OpenFOAM. If not, see . - -Class - Foam::starcdSurfaceWriter - -Description - A surfaceWriter for STARCD files. - - The geometry is written via the MeshedSurfaceProxy, the fields - are written in a trivial ASCII format with ID and VALUE as - so-called user data. These \c .usr files can be read into proSTAR - with these types of commands. For element data: - \verbatim - getuser FILENAME.usr cell scalar free - getuser FILENAME.usr cell vector free - \endverbatim - and for vertex data: - \verbatim - getuser FILENAME.usr vertex scalar free - getuser FILENAME.usr vertex vector free - \endverbatim - -Note - Only scalar and vector fields are supported directly. - A sphericalTensor is written as a scalar. - Other field types are not written. - -SourceFiles - starcdSurfaceWriter.C - -\*---------------------------------------------------------------------------*/ - -#ifndef starcdSurfaceWriter_H -#define starcdSurfaceWriter_H - -#include "surfaceWriter.H" - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -namespace Foam -{ - -/*---------------------------------------------------------------------------*\ - Class starcdSurfaceWriter Declaration -\*---------------------------------------------------------------------------*/ - -class starcdSurfaceWriter -: - public surfaceWriter -{ - // Private Member Functions - - template - static inline void writeData(Ostream&, const Type&); - - - //- Templated write operation - template - void Write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues - ) const; - - -public: - - //- Runtime type information - TypeName("starcd"); - - - // Constructors - - //- Construct given write format - starcdSurfaceWriter(const IOstream::streamFormat writeFormat); - - - //- Destructor - virtual ~starcdSurfaceWriter(); - - - // Member Functions - - //- True if the surface format supports geometry in a separate file. - // False if geometry and field must be in a single file - virtual bool separateGeometry() - { - return true; - } - - //- Write single surface geometry to file. - virtual void write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces - ) const; - - //- Write scalarField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; - - //- Write vectorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; - - //- Write sphericalTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; - - //- Write symmTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const - {} - - //- Write tensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const - {} -}; - - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -} // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - -// ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/surfaceWriter.H b/src/sampling/sampledSurface/writers/surfaceWriter.H index 7a7b5a4f0b..4675541c21 100644 --- a/src/sampling/sampledSurface/writers/surfaceWriter.H +++ b/src/sampling/sampledSurface/writers/surfaceWriter.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org - \\ / A nd | Copyright (C) 2011-2020 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2021 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -55,6 +55,75 @@ namespace Foam class surfaceWriter { +private: + + //- Helper for variadic write + template + static inline void setFieldTypeValue + ( + UPtrList>& fieldTypeValues, + const label fieldi, + const Field& fieldTypeValue + ) + {} + + //- Helper for variadic write + template + static inline void setFieldTypeValue + ( + UPtrList>& fieldTypeValues, + const label fieldi, + const Field& fieldTypeValue + ) + { + fieldTypeValues.set(fieldi, &fieldTypeValue); + } + + //- Helper for variadic write + static inline void unpackFieldTypeValues + ( + wordList& fieldNames + #define FieldTypeValuesNonConstArg(Type, nullArg) \ + , UPtrList>& field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesNonConstArg) + #undef FieldTypeValuesNonConstArg + ) + {} + + //- Helper for variadic write + template + static inline void unpackFieldTypeValues + ( + wordList& fieldNames + #define FieldTypeValuesNonConstArg(Type, nullArg) \ + , UPtrList>& field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesNonConstArg), + #undef FieldTypeValuesNonConstArg + const word& fieldName, + const Field& fieldTypeValue, + Args& ... args + ) + { + const label fieldi = fieldNames.size() - 1 - sizeof...(Args)/2; + + fieldNames[fieldi] = fieldName; + #define SetFieldTypeValue(Type, nullArg) \ + setFieldTypeValue(field##Type##Values, fieldi, fieldTypeValue); + FOR_ALL_FIELD_TYPES(SetFieldTypeValue); + #undef SetFieldTypeValue + + unpackFieldTypeValues + ( + fieldNames + #define FieldTypeValuesParameter(Type, nullArg) \ + , field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesParameter), + #undef FieldTypeValuesParameter + args ... + ); + } + + protected: // Protected Data @@ -126,86 +195,105 @@ public: // Member Functions - //- True if the surface format supports geometry in a separate file. - // False if geometry and field must be in a single file - virtual bool separateGeometry() - { - return false; - } - - //- Write single surface geometry to file. + //- Write fields for a single surface to file. virtual void write + ( + const fileName& outputDir, // /surface/TIME + const fileName& surfaceName, // name of surface + const pointField& points, + const faceList& faces, + const wordList& fieldNames, // names of fields + const bool writePointValues + #define FieldTypeValuesConstArg(Type, nullArg) \ + , const UPtrList>& field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesConstArg) + #undef FieldTypeValuesConstArg + ) const = 0; + + //- Write the surface geometry only. + void inline write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface const pointField& points, const faceList& faces - ) const = 0; + ) const + { + write + ( + outputDir, + surfaceName, + points, + faces, + wordList(), + false + #define FieldTypeValuesParameter(Type, nullArg) \ + , UPtrList>() + FOR_ALL_FIELD_TYPES(FieldTypeValuesParameter) + #undef FieldTypeValuesParameter + ); + } - //- Write scalarField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write + //- Write fields for a single surface to file. For use in code where + // the fields that are to be written are known. Takes any number of + // name, values arguments at the end. E.g.: + // + // write + // ( + // // Output options + // "myDirectory", "mySurface", + // + // // Geometry + // pp.localPoints(), pp.localFaces(), + // + // // Fields + // "p", Field(pp.size(), ...), + // "U", Field(pp.size(), ...) + // ); + // + template + void inline write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface const pointField& points, const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const = 0; + const bool writePointValues, + const Args& ... args + ) const + { + const label nFields = sizeof...(Args)/2; - //- Write vectorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const = 0; + wordList fieldNames(nFields); + #define DeclareFieldTypeValues(Type, nullArg) \ + UPtrList> field##Type##Values(nFields); + FOR_ALL_FIELD_TYPES(DeclareFieldTypeValues); + #undef DeclareFieldTypeValues - //- Write sphericalTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const = 0; + unpackFieldTypeValues + ( + fieldNames + #define FieldTypeValuesParameter(Type, nullArg) \ + , field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesParameter), + #undef FieldTypeValuesParameter + args ... + ); - //- Write symmTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const = 0; - - //- Write tensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const = 0; + write + ( + outputDir, + surfaceName, + points, + faces, + fieldNames, + writePointValues + #define FieldTypeValuesParameter(Type, nullArg) \ + , field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesParameter) + #undef FieldTypeValuesParameter + ); + } }; diff --git a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C index 033c1c965d..34a58e0114 100644 --- a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C +++ b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.C @@ -24,52 +24,16 @@ License \*---------------------------------------------------------------------------*/ #include "vtkSurfaceWriter.H" -#include "OFstream.H" -#include "boolList.H" -#include "OSspecific.H" -#include "makeSurfaceWriterMethods.H" #include "vtkWritePolyData.H" +#include "OSspecific.H" +#include "addToRunTimeSelectionTable.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { - makeSurfaceWriterType(vtkSurfaceWriter); -} - - -// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // - -template -void Foam::vtkSurfaceWriter::Write -( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues -) const -{ - if (!isDir(outputDir)) - { - mkDir(outputDir); - } - - vtkWritePolyData::write - ( - outputDir/fieldName + '_' + surfaceName + ".vtk", - "sampleSurface", - writeFormat_ == IOstream::BINARY, - points, - labelList(), - edgeList(), - faces, - fieldName, - isNodeValues, - values - ); + defineTypeNameAndDebug(vtkSurfaceWriter, 0); + addToRunTimeSelectionTable(surfaceWriter, vtkSurfaceWriter, word); } @@ -97,7 +61,13 @@ void Foam::vtkSurfaceWriter::write const fileName& outputDir, const fileName& surfaceName, const pointField& points, - const faceList& faces + const faceList& faces, + const wordList& fieldNames, + const bool writePointValues + #define FieldTypeValuesConstArg(Type, nullArg) \ + , const UPtrList>& field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesConstArg) + #undef FieldTypeValuesConstArg ) const { if (!isDir(outputDir)) @@ -113,13 +83,15 @@ void Foam::vtkSurfaceWriter::write points, labelList(), edgeList(), - faces + faces, + fieldNames, + boolList(fieldNames.size(), writePointValues), + UPtrList>(fieldNames.size()) + #define FieldTypeValuesParameter(Type, nullArg) , field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesParameter) + #undef FieldTypeValuesParameter ); } -// Create write methods -defineSurfaceWriterWriteFields(Foam::vtkSurfaceWriter); - - // ************************************************************************* // diff --git a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H index 514ca31075..36a8a439f6 100644 --- a/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H +++ b/src/sampling/sampledSurface/writers/vtk/vtkSurfaceWriter.H @@ -51,22 +51,6 @@ class vtkSurfaceWriter : public surfaceWriter { - // Private Member Functions - - //- Templated write operation - template - void Write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces, - const word& fieldName, - const Field& values, - const bool isNodeValues - ) const; - - public: //- Runtime type information @@ -85,79 +69,23 @@ public: // Member Functions - //- Write single surface geometry to file. - virtual void write - ( - const fileName& outputDir, - const fileName& surfaceName, - const pointField& points, - const faceList& faces - ) const; - - //- Write scalarField for a single surface to file. - // One value per face or vertex (isNodeValues = true) + //- Write fields for a single surface to file. virtual void write ( const fileName& outputDir, // /surface/TIME const fileName& surfaceName, // name of surface const pointField& points, const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues + const wordList& fieldNames, // names of fields + const bool writePointValues + #define FieldTypeValuesConstArg(Type, nullArg) \ + , const UPtrList>& field##Type##Values + FOR_ALL_FIELD_TYPES(FieldTypeValuesConstArg) + #undef FieldTypeValuesConstArg ) const; - //- Write vectorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; - - //- Write sphericalTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; - - //- Write symmTensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; - - //- Write tensorField for a single surface to file. - // One value per face or vertex (isNodeValues = true) - virtual void write - ( - const fileName& outputDir, // /surface/TIME - const fileName& surfaceName, // name of surface - const pointField& points, - const faceList& faces, - const word& fieldName, // name of field - const Field& values, - const bool isNodeValues - ) const; + //- Inherit base class templated write + using surfaceWriter::write; };