diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/Make/files b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/Make/files index e42c52451f..bc4a363517 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/Make/files +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/Make/files @@ -64,6 +64,7 @@ initialPointsMethod/bodyCentredCubic/bodyCentredCubic.C initialPointsMethod/faceCentredCubic/faceCentredCubic.C initialPointsMethod/pointFile/pointFile.C initialPointsMethod/autoDensity/autoDensity.C +initialPointsMethod/rayShooting/rayShooting.C relaxationModel/relaxationModel/relaxationModel.C relaxationModel/adaptiveLinear/adaptiveLinear.C diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C index 6f137249c1..e580febdd8 100644 --- a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/conformalVoronoiMesh/conformalVoronoiMesh.C @@ -1249,7 +1249,7 @@ void Foam::conformalVoronoiMesh::move() if ( ( - (vA->internalPoint() && vB->internalPoint()) + (vA->internalPoint() || vB->internalPoint()) && (!vA->referred() || !vB->referred()) // || // ( diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/initialPointsMethod/rayShooting/rayShooting.C b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/initialPointsMethod/rayShooting/rayShooting.C new file mode 100644 index 0000000000..c4beb20b8e --- /dev/null +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/initialPointsMethod/rayShooting/rayShooting.C @@ -0,0 +1,218 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 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 "rayShooting.H" +#include "addToRunTimeSelectionTable.H" +#include "triSurfaceMesh.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // + +defineTypeNameAndDebug(rayShooting, 0); +addToRunTimeSelectionTable(initialPointsMethod, rayShooting, dictionary); + +// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // + +rayShooting::rayShooting +( + const dictionary& initialPointsDict, + const Time& runTime, + Random& rndGen, + const conformationSurfaces& geometryToConformTo, + const cellShapeControl& cellShapeControls, + const autoPtr& decomposition +) +: + initialPointsMethod + ( + typeName, + initialPointsDict, + runTime, + rndGen, + geometryToConformTo, + cellShapeControls, + decomposition + ), + maxRayLength_(readScalar(detailsDict().lookup("maxRayLength"))), + randomiseInitialGrid_(detailsDict().lookup("randomiseInitialGrid")), + randomPerturbationCoeff_ + ( + readScalar(detailsDict().lookup("randomPerturbationCoeff")) + ) +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +List rayShooting::initialPoints() const +{ + // Loop over surface faces + const searchableSurfaces& surfaces = geometryToConformTo().geometry(); + const labelList& surfacesToConformTo = geometryToConformTo().surfaces(); + + // Initialise points list + label initialPointsSize = 0; + forAll(surfaces, surfI) + { + initialPointsSize += surfaces[surfI].size(); + } + + DynamicList initialPoints(initialPointsSize); + + forAll(surfacesToConformTo, surfI) + { + const searchableSurface& s = surfaces[surfacesToConformTo[surfI]]; + + tmp faceCentresTmp(s.coordinates()); + const pointField& faceCentres = faceCentresTmp(); + + Info<< " Shoot rays from " << s.name() << nl + << " nRays = " << faceCentres.size() << endl; + + + forAll(faceCentres, fcI) + { + const Foam::point& fC = faceCentres[fcI]; + + if + ( + Pstream::parRun() + && !decomposition().positionOnThisProcessor(fC) + ) + { + continue; + } + + const scalar pert = + randomPerturbationCoeff_ + *cellShapeControls().cellSize(fC); + + pointIndexHit surfHitStart; + label hitSurfaceStart; + + // Face centres should be on the surface so search distance can be + // small + geometryToConformTo().findSurfaceNearest + ( + fC, + sqr(SMALL), + surfHitStart, + hitSurfaceStart + ); + + vectorField normStart(1, vector::min); + geometryToConformTo().getNormal + ( + hitSurfaceStart, + List(1, surfHitStart), + normStart + ); + + pointIndexHit surfHitEnd; + label hitSurfaceEnd; + + geometryToConformTo().findSurfaceNearestIntersection + ( + fC - normStart[0]*SMALL, + fC - normStart[0]*maxRayLength_, + surfHitEnd, + hitSurfaceEnd + ); + + vectorField normEnd(1, vector::min); + geometryToConformTo().getNormal + ( + hitSurfaceEnd, + List(1, surfHitEnd), + normEnd + ); + + if + ( + surfHitEnd.hit() + && ((normStart[0] & normEnd[0]) < 0) + ) + { + line l(fC, surfHitEnd.hitPoint()); + + if (Pstream::parRun()) + { + // Clip the line in parallel + pointIndexHit procIntersection = + decomposition().findLine + ( + l.start() + l.vec()*SMALL, + l.end() - l.vec()*maxRayLength_ + ); + + if (procIntersection.hit()) + { + l = + line + ( + l.start(), + procIntersection.hitPoint() + ); + } + } + + Foam::point midPoint(l.centre()); + + const scalar minDistFromSurfaceSqr = + minimumSurfaceDistanceCoeffSqr_ + *sqr(cellShapeControls().cellSize(midPoint)); + + if + ( + magSqr(midPoint - l.start()) > minDistFromSurfaceSqr + && magSqr(midPoint - l.end()) > minDistFromSurfaceSqr + ) + { + if (randomiseInitialGrid_) + { + midPoint.x() += pert*(rndGen().scalar01() - 0.5); + midPoint.y() += pert*(rndGen().scalar01() - 0.5); + midPoint.z() += pert*(rndGen().scalar01() - 0.5); + } + + initialPoints.append(toPoint(midPoint)); + } + } + } + } + + return initialPoints.shrink(); +} + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// ************************************************************************* // diff --git a/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/initialPointsMethod/rayShooting/rayShooting.H b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/initialPointsMethod/rayShooting/rayShooting.H new file mode 100644 index 0000000000..c199a31e0a --- /dev/null +++ b/applications/utilities/mesh/generation/foamyHexMesh/conformalVoronoiMesh/initialPointsMethod/rayShooting/rayShooting.H @@ -0,0 +1,105 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2013 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::rayShooting + +Description + +SourceFiles + rayShooting.C + +\*---------------------------------------------------------------------------*/ + +#ifndef rayShooting_H +#define rayShooting_H + +#include "initialPointsMethod.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +namespace Foam +{ + +/*---------------------------------------------------------------------------*\ + Class rayShooting Declaration +\*---------------------------------------------------------------------------*/ + +class rayShooting +: + public initialPointsMethod +{ + +private: + + // Private data + + const scalar maxRayLength_; + + //- Should the initial positions be randomised + Switch randomiseInitialGrid_; + + //- Randomise the initial positions by fraction of the initialCellSize_ + scalar randomPerturbationCoeff_; + + +public: + + //- Runtime type information + TypeName("rayShooting"); + + // Constructors + + //- Construct from components + rayShooting + ( + const dictionary& initialPointsDict, + const Time& runTime, + Random& rndGen, + const conformationSurfaces& geometryToConformTo, + const cellShapeControl& cellShapeControls, + const autoPtr& decomposition + ); + + + //- Destructor + virtual ~rayShooting() + {} + + + // Member Functions + + //- Return the initial points for the conformalVoronoiMesh + virtual List initialPoints() const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* //