Commit f4ae4f7b authored by mattijs's avatar mattijs
Browse files

ENH: snappyHexMesh. Added leak-path detection.

Detects connections (during refinement) between
locationsInsideMesh and locationsOutsideMesh and
writes a sampledSet for postprocessing.
parent 8f858af6
......@@ -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<scalar>::typeName
)
);
const autoPtr<writer<scalar>> setFormatter
(
writer<scalar>::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<writer<scalar>>(new vtkSetWriter<scalar>()),
setFormatter,
0.01, // min triangle quality
true
);
......@@ -1476,7 +1491,8 @@ int main(int argc, char *argv[])
decomposer,
distributor,
globalToMasterPatch,
globalToSlavePatch
globalToSlavePatch,
setFormatter
);
......
......@@ -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;
......
......@@ -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 \
......
......@@ -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
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "nastranSetWriter.H"
#include "coordSet.H"
#include "IOmanip.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::nastranSetWriter<Type>::nastranSetWriter()
:
writer<Type>()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::nastranSetWriter<Type>::~nastranSetWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Foam::fileName Foam::nastranSetWriter<Type>::getFileName
(
const coordSet& points,
const wordList& valueSetNames
) const
{
return this->getBaseName(points, valueSetNames) + ".nas";
}
template<class Type>
void Foam::nastranSetWriter<Type>::write
(
const coordSet& points,
const wordList& valueSetNames,
const List<const Field<Type>*>& 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<class Type>
void Foam::nastranSetWriter<Type>::write
(
const bool writeTracks,
const PtrList<coordSet>& tracks,
const wordList& valueSetNames,
const List<List<Field<Type>>>& 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;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
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 Type>
class nastranSetWriter
:
public writer<Type>
{
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<const Field<Type>*>&,
Ostream&
) const;
virtual void write
(
const bool writeTracks,
const PtrList<coordSet>&,
const wordList& valueSetNames,
const List<List<Field<Type>>>&,
Ostream&
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "nastranSetWriter.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "nastranSetWriter.H"
#include "writers.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
makeSetWriters(nastranSetWriter);
}
// ************************************************************************* //
......@@ -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 \
......
......@@ -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<scalar>& 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<pointList> segmentPoints;
List<scalarList> segmentDist;
{
label nSegments = 0;
if (leakPath.segments().size())
{
nSegments = max(leakPath.segments())+1;
}
reduce(nSegments, maxOp<label>());
labelList nElemsPerSegment(nSegments, 0);
for (label segmenti : leakPath.segments())
{
nElemsPerSegment[segmenti]++;
}
segmentPoints.setSize(nElemsPerSegment.size());
segmentDist.setSize(nElemsPerSegment.size());
forAll(nElemsPerSegment, i)
{
segmentPoints[i].setSize(nElemsPerSegment[i]);
segmentDist[i].setSize(nElemsPerSegment[i]);
}
nElemsPerSegment = 0;
forAll(leakPath, elemi)
{
label segmenti = leakPath.segments()[elemi];
pointList& points = segmentPoints[segmenti];
scalarList& dist = segmentDist[segmenti];
label& n = nElemsPerSegment[segmenti];
points[n] = leakPath[elemi];
dist[n] = leakPath.curveDist()[elemi];
n++;
}
}
PtrList<coordSet> allLeakPaths(segmentPoints.size());
forAll(allLeakPaths, segmenti)
{
// Collect data from all processors
List<pointList> gatheredPts(Pstream::nProcs());
gatheredPts[Pstream::myProcNo()] =
std::move(segmentPoints[segmenti]);