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 5f85fc260..dae322af5 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 @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2012-2017 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -115,6 +115,10 @@ Foam::automatic::automatic featureProximityFile_(coeffsDict_.lookup("featureProximityFile")), readInternalCloseness_(Switch(coeffsDict_.lookup("internalCloseness"))), internalClosenessFile_(coeffsDict_.lookup("internalClosenessFile")), + internalClosenessCellSizeCoeff_ + ( + readScalar(coeffsDict_.lookup("internalClosenessCellSizeCoeff")) + ), curvatureCellSizeCoeff_ ( readScalar(coeffsDict_.lookup("curvatureCellSizeCoeff")) @@ -203,7 +207,7 @@ Foam::tmp Foam::automatic::load() Info<< indent << "Reading internal closeness: " << internalClosenessFile_ << endl; - triSurfaceScalarField internalCloseness + triSurfacePointScalarField internalClosenessPointField ( IOobject ( @@ -219,17 +223,13 @@ Foam::tmp Foam::automatic::load() true ); - scalarField internalClosenessPointField - ( - patchInterpolate.faceToPointInterpolate(internalCloseness) - ); - forAll(pointCellSize, pI) { pointCellSize[pI] = min ( - internalClosenessPointField[meshPointMap[pI]], + (1.0/internalClosenessCellSizeCoeff_) + *internalClosenessPointField[meshPointMap[pI]], pointCellSize[pI] ); } diff --git a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.H b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.H index 07f4e9442..577f0617a 100644 --- a/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.H +++ b/applications/utilities/mesh/generation/foamyMesh/conformalVoronoiMesh/cellSizeControlSurfaces/surfaceCellSizeFunction/cellSizeCalculationType/automatic/automatic.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -74,6 +74,10 @@ private: const Switch readInternalCloseness_; const word internalClosenessFile_; + //- The internalCloseness values are multiplied by the inverse + // of this value to get the cell size + const scalar internalClosenessCellSizeCoeff_; + //- The curvature values are multiplied by the inverse of this value to // get the cell size const scalar curvatureCellSizeCoeff_; diff --git a/applications/utilities/surface/surfaceFeatureExtract/Make/files b/applications/utilities/surface/surfaceFeatureExtract/Make/files index a57125cd6..f8ead594d 100644 --- a/applications/utilities/surface/surfaceFeatureExtract/Make/files +++ b/applications/utilities/surface/surfaceFeatureExtract/Make/files @@ -1,3 +1,6 @@ +surfaceExtractCloseness.C +surfaceExtractPointCloseness.C +surfaceFeatureExtractUtilities.C surfaceFeatureExtract.C EXE = $(FOAM_APPBIN)/surfaceFeatureExtract diff --git a/applications/utilities/surface/surfaceFeatureExtract/surfaceExtractCloseness.C b/applications/utilities/surface/surfaceFeatureExtract/surfaceExtractCloseness.C new file mode 100644 index 000000000..1c6fb0521 --- /dev/null +++ b/applications/utilities/surface/surfaceFeatureExtract/surfaceExtractCloseness.C @@ -0,0 +1,155 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2018 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 "surfaceFeatureExtract.H" +#include "Time.H" +#include "triSurfaceMesh.H" +#include "vtkSurfaceWriter.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +void Foam::extractCloseness +( + const fileName &sFeatFileName, + const Time& runTime, + const triSurface &surf, + const bool writeVTK +) +{ + // Searchable triSurface + const triSurfaceMesh searchSurf + ( + IOobject + ( + sFeatFileName + ".closeness", + runTime.constant(), + "triSurface", + runTime + ), + surf + ); + + + // Prepare start and end points for intersection tests + + const vectorField& normals = searchSurf.faceNormals(); + + const scalar span = searchSurf.bounds().mag(); + + const pointField start(searchSurf.faceCentres() - span*normals); + const pointField end(searchSurf.faceCentres() + span*normals); + const pointField& faceCentres = searchSurf.faceCentres(); + + List> allHitinfo; + + // Find all intersections (in order) + searchSurf.findLineAll(start, end, allHitinfo); + + scalarField internalCloseness(start.size(), GREAT); + scalarField externalCloseness(start.size(), GREAT); + + forAll(allHitinfo, fi) + { + const List& hitInfo = allHitinfo[fi]; + + processHit + ( + internalCloseness[fi], + externalCloseness[fi], + fi, + surf, + start[fi], + faceCentres[fi], + end[fi], + normals[fi], + normals, + hitInfo + ); + } + + triSurfaceScalarField internalClosenessField + ( + IOobject + ( + sFeatFileName + ".internalCloseness", + runTime.constant(), + "triSurface", + runTime + ), + surf, + dimLength, + internalCloseness + ); + + internalClosenessField.write(); + + triSurfaceScalarField externalClosenessField + ( + IOobject + ( + sFeatFileName + ".externalCloseness", + runTime.constant(), + "triSurface", + runTime + ), + surf, + dimLength, + externalCloseness + ); + + externalClosenessField.write(); + + if (writeVTK) + { + const faceList faces(surf.faces()); + + vtkSurfaceWriter().write + ( + runTime.constantPath()/"triSurface",// outputDir + sFeatFileName, // surfaceName + surf.points(), + faces, + "internalCloseness", // fieldName + internalCloseness, + false, // isNodeValues + true // verbose + ); + + vtkSurfaceWriter().write + ( + runTime.constantPath()/"triSurface",// outputDir + sFeatFileName, // surfaceName + surf.points(), + faces, + "externalCloseness", // fieldName + externalCloseness, + false, // isNodeValues + true // verbose + ); + } +} + + +// ************************************************************************* // diff --git a/applications/utilities/surface/surfaceFeatureExtract/surfaceExtractPointCloseness.C b/applications/utilities/surface/surfaceFeatureExtract/surfaceExtractPointCloseness.C new file mode 100644 index 000000000..a0b2bde71 --- /dev/null +++ b/applications/utilities/surface/surfaceFeatureExtract/surfaceExtractPointCloseness.C @@ -0,0 +1,314 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2018 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 "surfaceFeatureExtract.H" +#include "Time.H" +#include "triSurfaceMesh.H" +#include "vtkSurfaceWriter.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +void Foam::processHit +( + scalar& internalCloseness, + scalar& externalCloseness, + const label fi, + const triSurface& surf, + const point& start, + const point& p, + const point& end, + const vector& normal, + const vectorField& normals, + const List& hitInfo +) +{ + if (hitInfo.size() < 1) + { + drawHitProblem(fi, surf, start, p, end, hitInfo); + } + else if (hitInfo.size() == 1) + { + if (!hitInfo[0].hit()) + { + } + else if (hitInfo[0].index() != fi) + { + drawHitProblem(fi, surf, start, p, end, hitInfo); + } + } + else + { + label ownHiti = -1; + + forAll(hitInfo, hI) + { + // Find the hit on the triangle that launched the ray + + if (hitInfo[hI].index() == fi) + { + ownHiti = hI; + break; + } + } + + if (ownHiti < 0) + { + drawHitProblem(fi, surf, start, p, end, hitInfo); + } + else if (ownHiti == 0) + { + // There are no internal hits, the first hit is the + // closest external hit + + if + ( + (normal & normals[hitInfo[ownHiti + 1].index()]) + < externalToleranceCosAngle + ) + { + externalCloseness = min + ( + externalCloseness, + mag(p - hitInfo[ownHiti + 1].hitPoint()) + ); + } + } + else if (ownHiti == hitInfo.size() - 1) + { + // There are no external hits, the last but one hit is + // the closest internal hit + + if + ( + (normal & normals[hitInfo[ownHiti - 1].index()]) + < internalToleranceCosAngle + ) + { + internalCloseness = min + ( + internalCloseness, + mag(p - hitInfo[ownHiti - 1].hitPoint()) + ); + } + } + else + { + if + ( + (normal & normals[hitInfo[ownHiti + 1].index()]) + < externalToleranceCosAngle + ) + { + externalCloseness = min + ( + externalCloseness, + mag(p - hitInfo[ownHiti + 1].hitPoint()) + ); + } + + if + ( + (normal & normals[hitInfo[ownHiti - 1].index()]) + < internalToleranceCosAngle + ) + { + internalCloseness = min + ( + internalCloseness, + mag(p - hitInfo[ownHiti - 1].hitPoint()) + ); + } + } + } +} + + +void Foam::extractPointCloseness +( + const fileName &sFeatFileName, + const Time& runTime, + const triSurface &surf, + const bool writeVTK +) +{ + // Searchable triSurface + const triSurfaceMesh searchSurf + ( + IOobject + ( + sFeatFileName + ".closeness", + runTime.constant(), + "triSurface", + runTime + ), + surf + ); + + + // Prepare start and end points for intersection tests + + const pointField& points = searchSurf.points(); + const labelList& meshPoints = searchSurf.meshPoints(); + const pointField& faceCentres = searchSurf.faceCentres(); + const vectorField& normals = searchSurf.faceNormals(); + const labelListList& pointFaces = searchSurf.pointFaces(); + + const scalar span = searchSurf.bounds().mag(); + + label nPointFaces = 0; + forAll(pointFaces, pfi) + { + nPointFaces += pointFaces[pfi].size(); + } + + pointField facePoints(nPointFaces); + pointField start(nPointFaces); + pointField end(nPointFaces); + + label i = 0; + forAll(points, pi) + { + forAll(pointFaces[pi], pfi) + { + const label fi = pointFaces[pi][pfi]; + + facePoints[i] = (0.9*points[meshPoints[pi]] + 0.1*faceCentres[fi]); + const vector& n = normals[fi]; + + start[i] = facePoints[i] - span*n; + end[i] = facePoints[i] + span*n; + + i++; + } + } + + List> allHitinfo; + + // Find all intersections (in order) + searchSurf.findLineAll(start, end, allHitinfo); + + scalarField internalCloseness(points.size(), GREAT); + scalarField externalCloseness(points.size(), GREAT); + + i = 0; + forAll(points, pi) + { + forAll(pointFaces[pi], pfi) + { + const label fi = pointFaces[pi][pfi]; + const List& hitInfo = allHitinfo[i]; + + processHit + ( + internalCloseness[pi], + externalCloseness[pi], + fi, + surf, + start[i], + facePoints[i], + end[i], + normals[fi], + normals, + hitInfo + ); + + i++; + } + } + + triSurfacePointScalarField internalClosenessPointField + ( + IOobject + ( + sFeatFileName + ".internalPointCloseness", + runTime.constant(), + "triSurface", + runTime + ), + surf, + dimLength, + internalCloseness + ); + + internalClosenessPointField.write(); + + triSurfacePointScalarField externalClosenessPointField + ( + IOobject + ( + sFeatFileName + ".externalPointCloseness", + runTime.constant(), + "triSurface", + runTime + ), + surf, + dimLength, + externalCloseness + ); + + externalClosenessPointField.write(); + + if (writeVTK) + { + const faceList faces(surf.faces()); + const Map