From f4ae4f7b2c6e7c8a4a2adc9315b521908049ac6e Mon Sep 17 00:00:00 2001 From: mattijs Date: Thu, 2 Aug 2018 16:39:06 +0100 Subject: [PATCH] ENH: snappyHexMesh. Added leak-path detection. Detects connections (during refinement) between locationsInsideMesh and locationsOutsideMesh and writes a sampledSet for postprocessing. --- .../generation/snappyHexMesh/snappyHexMesh.C | 20 +- .../snappyHexMesh/snappyHexMeshDict | 4 + .../redistributePar/Make/options | 1 + src/fileFormats/Make/files | 1 + .../nastran/nastranSetWriter.C | 228 + .../nastran/nastranSetWriter.H | 131 + .../nastran/nastranSetWriterRunTime.C | 37 + src/mesh/snappyHexMesh/Make/options | 1 + .../meshRefinement/meshRefinement.C | 178 +- .../meshRefinement/meshRefinement.H | 17 +- .../meshRefinement/meshRefinementBaffles.C | 20 +- .../snappyHexMeshDriver/snappyRefineDriver.C | 24 +- .../snappyHexMeshDriver/snappyRefineDriver.H | 7 +- .../sampledSet/sampledSet/sampledSet.C | 11 +- .../sampledSet/sampledSet/sampledSet.H | 6 +- .../sampledSet/sampledSets/sampledSets.C | 3 +- .../sampledSet/shortestPath/shortestPathSet.C | 800 +- .../sampledSet/shortestPath/shortestPathSet.H | 84 +- .../motorBike_leakDetection/0.orig/U | 52 + .../0.orig/include/fixedInlet | 15 + .../0.orig/include/frontBackUpperPatches | 19 + .../0.orig/include/initialConditions | 14 + .../motorBike_leakDetection/0.orig/k | 53 + .../motorBike_leakDetection/0.orig/nut | 64 + .../motorBike_leakDetection/0.orig/omega | 52 + .../motorBike_leakDetection/0.orig/p | 51 + .../motorBike_leakDetection/Allclean | 11 + .../motorBike_leakDetection/Allrun | 27 + .../constant/transportProperties | 21 + .../constant/triSurface/README | 4 + .../constant/triSurface/bag_open.obj | 134 + ...rBike-wo-visor-w-deletedElementsOnBack.obj | 461333 ++++++++++++++ .../triSurface/motorBike-wo-visor.obj | 462403 +++++++++++++++ .../constant/turbulenceProperties | 28 + .../system/blockMeshDict | 86 + .../system/controlDict | 98 + .../system/cuttingPlane | 37 + .../system/decomposeParDict.6 | 30 + .../system/ensightWrite | 17 + .../system/forceCoeffs | 41 + .../motorBike_leakDetection/system/fvSchemes | 58 + .../motorBike_leakDetection/system/fvSolution | 86 + .../system/meshQualityDict | 24 + .../system/snappyHexMeshDict | 340 + .../system/streamLines | 58 + .../system/surfaceFeatureExtractDict | 45 + .../system/wallBoundedStreamLines | 100 + 47 files changed, 926746 insertions(+), 128 deletions(-) create mode 100644 src/fileFormats/sampledSetWriters/nastran/nastranSetWriter.C create mode 100644 src/fileFormats/sampledSetWriters/nastran/nastranSetWriter.H create mode 100644 src/fileFormats/sampledSetWriters/nastran/nastranSetWriterRunTime.C create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/0.orig/U create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/0.orig/include/fixedInlet create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/0.orig/include/frontBackUpperPatches create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/0.orig/include/initialConditions create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/0.orig/k create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/0.orig/nut create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/0.orig/omega create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/0.orig/p create mode 100755 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/Allclean create mode 100755 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/Allrun create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/constant/transportProperties create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/constant/triSurface/README create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/constant/triSurface/bag_open.obj create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/constant/triSurface/motorBike-wo-visor-w-deletedElementsOnBack.obj create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/constant/triSurface/motorBike-wo-visor.obj create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/constant/turbulenceProperties create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/system/blockMeshDict create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/system/controlDict create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/system/cuttingPlane create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/system/decomposeParDict.6 create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/system/ensightWrite create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/system/forceCoeffs create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/system/fvSchemes create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/system/fvSolution create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/system/meshQualityDict create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/system/snappyHexMeshDict create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/system/streamLines create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/system/surfaceFeatureExtractDict create mode 100644 tutorials/mesh/snappyHexMesh/motorBike_leakDetection/system/wallBoundedStreamLines diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C index 61d6f2bb9a..60ba3f5463 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMesh.C @@ -62,6 +62,7 @@ Description #include "fvMeshTools.H" #include "profiling.H" #include "processorMeshes.H" +#include "vtkSetWriter.H" using namespace Foam; @@ -788,6 +789,20 @@ int main(int argc, char *argv[]) const bool keepPatches(meshDict.lookupOrDefault("keepPatches", false)); + // format to be used for writing lines + const word setFormat + ( + meshDict.lookupOrDefault + ( + "setFormat", + vtkSetWriter::typeName + ) + ); + const autoPtr> setFormatter + ( + writer::New(setFormat) + ); + // Read decomposePar dictionary dictionary decomposeDict; @@ -1038,7 +1053,7 @@ int main(int argc, char *argv[]) ( 100.0, // max size ratio 1e-9, // intersection tolerance - autoPtr>(new vtkSetWriter()), + setFormatter, 0.01, // min triangle quality true ); @@ -1476,7 +1491,8 @@ int main(int argc, char *argv[]) decomposer, distributor, globalToMasterPatch, - globalToSlavePatch + globalToSlavePatch, + setFormatter ); diff --git a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict index ad91050e82..b724e020f5 100644 --- a/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict +++ b/applications/utilities/mesh/generation/snappyHexMesh/snappyHexMeshDict @@ -785,6 +785,10 @@ meshQualityControls // layerFields // write volScalarField for layer coverage //); + +//// Format for writing lines. E.g. leak path. Default is vtk format. +//setFormat ensight; + // Merge tolerance. Is fraction of overall bounding box of initial mesh. // Note: the write tolerance needs to be higher than this. mergeTolerance 1e-6; diff --git a/applications/utilities/parallelProcessing/redistributePar/Make/options b/applications/utilities/parallelProcessing/redistributePar/Make/options index 56880b114a..cbfc82794d 100644 --- a/applications/utilities/parallelProcessing/redistributePar/Make/options +++ b/applications/utilities/parallelProcessing/redistributePar/Make/options @@ -3,6 +3,7 @@ EXE_INC = \ -I$(LIB_SRC)/parallel/decompose/decompose/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \ -I$(LIB_SRC)/meshTools/lnInclude \ + -I$(LIB_SRC)/fileFormats/lnInclude \ -I$(LIB_SRC)/lagrangian/basic/lnInclude \ -I$(LIB_SRC)/regionModels/regionModel/lnInclude \ -I$(LIB_SRC)/dynamicMesh/lnInclude \ diff --git a/src/fileFormats/Make/files b/src/fileFormats/Make/files index 2ed0cc373a..71fc592e3d 100644 --- a/src/fileFormats/Make/files +++ b/src/fileFormats/Make/files @@ -52,5 +52,6 @@ $(setWriters)/raw/rawSetWriterRunTime.C $(setWriters)/vtk/vtkSetWriterRunTime.C $(setWriters)/xmgrace/xmgraceSetWriterRunTime.C $(setWriters)/csv/csvSetWriterRunTime.C +$(setWriters)/nastran/nastranSetWriterRunTime.C LIB = $(FOAM_LIBBIN)/libfileFormats diff --git a/src/fileFormats/sampledSetWriters/nastran/nastranSetWriter.C b/src/fileFormats/sampledSetWriters/nastran/nastranSetWriter.C new file mode 100644 index 0000000000..98a4c1a805 --- /dev/null +++ b/src/fileFormats/sampledSetWriters/nastran/nastranSetWriter.C @@ -0,0 +1,228 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\/ 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 "nastranSetWriter.H" +#include "coordSet.H" +#include "IOmanip.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +template +Foam::nastranSetWriter::nastranSetWriter() +: + writer() +{} + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::nastranSetWriter::~nastranSetWriter() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +Foam::fileName Foam::nastranSetWriter::getFileName +( + const coordSet& points, + const wordList& valueSetNames +) const +{ + return this->getBaseName(points, valueSetNames) + ".nas"; +} + + +template +void Foam::nastranSetWriter::write +( + const coordSet& points, + const wordList& valueSetNames, + const List*>& valueSets, + Ostream& os +) const +{ + os << "TITLE=OpenFOAM " + << this->getBaseName(points, valueSetNames).c_str() + << nl + << "$" << nl + << "BEGIN BULK" << nl; + + forAll(points, pointi) + { + fileFormats::NASCore::writeKeyword(os, "GRID", fieldFormat::FREE); + + const point& pt = points[pointi]; + + //os.setf(std::ios_base::right); + //os << setw(8) << pointi+1 + // << setw(8) << ' ' + // << setw(8) << float(pt.x()) + // << setw(8) << float(pt.y()) + // << setw(8) << float(pt.z()) + // << nl; + //os.unsetf(std::ios_base::right); + os << ',' << pointi+1 + << ',' + << ',' << float(pt.x()) + << ',' << float(pt.y()) + << ',' << float(pt.z()) + << nl; + } + + if (false) + { + // Single track with multiple segments + const label nEdges = points.size()-1; + for (label edgei = 0; edgei < nEdges; ++edgei) + { + fileFormats::NASCore::writeKeyword + ( + os, + "PLOTEL", + fieldFormat::FREE + ); + + //os.setf(std::ios_base::right); + //os << setw(8) << edgei+1 + // << setw(8) << edgei+1 + // << setw(8) << edgei+2 + // << nl; + //os.unsetf(std::ios_base::right); + os << ',' << edgei+1 + << ',' << edgei+1 + << ',' << edgei+2 + << nl; + } + } + + os << "ENDDATA" << nl; +} + + +template +void Foam::nastranSetWriter::write +( + const bool writeTracks, + const PtrList& tracks, + const wordList& valueSetNames, + const List>>& valueSets, + Ostream& os +) const +{ + if (valueSets.size() != valueSetNames.size()) + { + FatalErrorInFunction + << "Number of variables:" << valueSetNames.size() << endl + << "Number of valueSets:" << valueSets.size() + << exit(FatalError); + } + if (tracks.empty()) + { + return; + } + + os << "TITLE=OpenFOAM " + << this->getBaseName(tracks[0], valueSetNames).c_str() + << nl + << "$" << nl + << "BEGIN BULK" << nl; + +// label nTracks = tracks.size(); +// label nPoints = 0; +// forAll(tracks, i) +// { +// nPoints += tracks[i].size(); +// } + + label globalPti = 0; + forAll(tracks, tracki) + { + const coordSet& points = tracks[tracki]; + forAll(points, pointi) + { + fileFormats::NASCore::writeKeyword(os, "GRID", fieldFormat::FREE); + + const point& pt = points[pointi]; + + //os.setf(std::ios_base::right); + //os << setw(8) << globalPti++ + // << setw(8) << ' ' + // << setw(8) << float(pt.x()) + // << setw(8) << float(pt.y()) + // << setw(8) << float(pt.z()) + // << nl; + //os.unsetf(std::ios_base::right); + os << ',' << globalPti++ + << ',' + << ',' << float(pt.x()) + << ',' << float(pt.y()) + << ',' << float(pt.z()) + << nl; + } + } + + if (writeTracks) + { + // Write ids of track points to file + label globalEdgei = 0; + label globalPointi = 0; + forAll(tracks, tracki) + { + const coordSet& points = tracks[tracki]; + + const label nEdges = points.size()-1; + for (label edgei = 0; edgei < nEdges; ++edgei) + { + fileFormats::NASCore::writeKeyword + ( + os, + "PLOTEL", + fieldFormat::FREE + ); + + //os.setf(std::ios_base::right); + //os << setw(8) << globalEdgei+1 + // << setw(8) << globalPointi+1 + // << setw(8) << globalPointi+2 + // << nl; + //os.unsetf(std::ios_base::right); + + os << ',' << globalEdgei+1 + << ',' << globalPointi+1 + << ',' << globalPointi+2 + << nl; + globalEdgei++; + globalPointi++; + } + } + } + + os << "ENDDATA" << nl; +} + + +// ************************************************************************* // diff --git a/src/fileFormats/sampledSetWriters/nastran/nastranSetWriter.H b/src/fileFormats/sampledSetWriters/nastran/nastranSetWriter.H new file mode 100644 index 0000000000..00d3278c04 --- /dev/null +++ b/src/fileFormats/sampledSetWriters/nastran/nastranSetWriter.H @@ -0,0 +1,131 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\/ 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::nastranSetWriter + +Description + Line format in Nastran (currently hardcoded to 'free' format) + + Does not do field data. + +SourceFiles + nastranSetWriter.C + +\*---------------------------------------------------------------------------*/ + +#ifndef nastranSetWriter_H +#define nastranSetWriter_H + +#include "writer.H" +#include "NASCore.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class nastranSetWriter Declaration +\*---------------------------------------------------------------------------*/ + +template +class nastranSetWriter +: + public writer +{ +public: + + //- File field formats + using fieldFormat = Foam::fileFormats::NASCore::fieldFormat; + +private: + + // Private Member Functions + + //- Write the formatted keyword to the output stream + Ostream& writeKeyword + ( + Ostream& os, + const word& keyword + ) const; + + +public: + + //- Runtime type information + TypeName("nastran"); + + + // Constructors + + //- Construct null + nastranSetWriter(); + + + //- Destructor + virtual ~nastranSetWriter(); + + + // Member Functions + + virtual fileName getFileName + ( + const coordSet&, + const wordList& + ) const; + + virtual void write + ( + const coordSet&, + const wordList&, + const List*>&, + Ostream& + ) const; + + virtual void write + ( + const bool writeTracks, + const PtrList&, + const wordList& valueSetNames, + const List>>&, + Ostream& + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository + #include "nastranSetWriter.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/fileFormats/sampledSetWriters/nastran/nastranSetWriterRunTime.C b/src/fileFormats/sampledSetWriters/nastran/nastranSetWriterRunTime.C new file mode 100644 index 0000000000..b0fac981a8 --- /dev/null +++ b/src/fileFormats/sampledSetWriters/nastran/nastranSetWriterRunTime.C @@ -0,0 +1,37 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 OpenCFD Ltd. + \\/ 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 "nastranSetWriter.H" +#include "writers.H" +#include "addToRunTimeSelectionTable.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + makeSetWriters(nastranSetWriter); +} + +// ************************************************************************* // diff --git a/src/mesh/snappyHexMesh/Make/options b/src/mesh/snappyHexMesh/Make/options index 9a7fe18cd6..bff1be5f77 100644 --- a/src/mesh/snappyHexMesh/Make/options +++ b/src/mesh/snappyHexMesh/Make/options @@ -2,6 +2,7 @@ EXE_INC = \ -I$(LIB_SRC)/parallel/decompose/decompositionMethods/lnInclude \ -I$(LIB_SRC)/dynamicMesh/lnInclude \ -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/sampling/lnInclude \ -I$(LIB_SRC)/lagrangian/basic/lnInclude \ -I$(LIB_SRC)/fileFormats/lnInclude \ -I$(LIB_SRC)/surfMesh/lnInclude \ diff --git a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C index 198f51586f..3a538119b5 100644 --- a/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C +++ b/src/mesh/snappyHexMesh/meshRefinement/meshRefinement.C @@ -57,6 +57,10 @@ License #include "motionSmoother.H" #include "faceSet.H" +// Leak path +#include "shortestPathSet.H" +#include "meshSearch.H" + // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam @@ -2220,8 +2224,10 @@ Foam::label Foam::meshRefinement::findRegions const vector& perturbVec, const pointField& locationsInMesh, const pointField& locationsOutsideMesh, + const writer& leakPathFormatter, const label nRegions, - labelList& cellRegion + labelList& cellRegion, + const boolList& blockedFace ) { bitSet insideCell(mesh.nCells()); @@ -2273,11 +2279,170 @@ Foam::label Foam::meshRefinement::findRegions label index = insideRegions.find(regioni); if (index != -1) { + const polyBoundaryMesh& pbm = mesh.boundaryMesh(); + + fileName outputDir; + if (Pstream::master()) + { + outputDir = + mesh.time().path() + / (Pstream::parRun() ? ".." : "") + / functionObject::outputPrefix + / mesh.pointsInstance(); + outputDir.clean(); + mkDir(outputDir); + } + + + // Write the leak path + + meshSearch searchEngine(mesh); + shortestPathSet leakPath + ( + "leakPath", + mesh, + searchEngine, + coordSet::coordFormatNames[coordSet::coordFormat::DISTANCE], + false, //true, + 50, // tbd. Number of iterations + pbm.groupPatchIDs()["wall"], + locationsInMesh, + locationsOutsideMesh, + blockedFace + ); + + // Split leak path according to segment. Note: segment index + // is global (= index in locationsInsideMesh) + List segmentPoints; + List segmentDist; + { + label nSegments = 0; + if (leakPath.segments().size()) + { + nSegments = max(leakPath.segments())+1; + } + reduce(nSegments, maxOp