Commit afa6bd50 authored by mattijs's avatar mattijs
Browse files

ENH: snappyHexMesh: added to automatic gap-refinement capabilities

1. multi-ray shooting. It now shoots rays in all the 3 coordinate directions
from the cell centre. Before it would shoot just a single ray from the
nearest point on the surface, going through the cell centre.

There is a cost overhead in that now it shoots 6 rays (+-x, +-y, +-z)
instead of just 1.

2. bleeding of refinement. It marks the cells inside a gap and walks out
the gap-size to neighbouring cells (which are just outside the gap). This
should make for a smoother refinement pattern.
parent 71db9357
......@@ -244,8 +244,17 @@ castellatedMeshControls
}
//sphere.stl
//{
// mode distance;
// levels ((1.0 5) (2.0 3));
// mode inside;
// levels ((1.0 4));
// // Optional override of uniform refinement level such
// // that in small gaps we're getting more cells.
// // The specification is
// // - numGapCells : minimum number of cells in the gap
// // - minLevel : min refinement level at which to kick in
// // - maxLevel : upper refinement level
// // All three settings can be overridden on a surface by
// // surface basis in the refinementSurfaces section.
// gapLevel (<numGapCells> <minLevel> <maxlevel>);
//}
}
......
......@@ -109,6 +109,7 @@ class autoRefineDriver
label bigGapOnlyRefine
(
const refinementParameters& refineParams,
const bool spreadGapSize,
const label maxIter
);
......
......@@ -55,6 +55,7 @@ SourceFiles
#include "wordPairHashTable.H"
#include "surfaceZonesInfo.H"
#include "volumeType.H"
#include "DynamicField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -353,8 +354,23 @@ private:
label& nRefine
) const;
//- Generate single ray for cell to detect gap
bool generateRay
//- Generate single ray from nearPoint in direction of nearNormal
label generateRays
(
const point& nearPoint,
const vector& nearNormal,
const FixedList<label, 3>& gapInfo,
const volumeType& mode,
const label cLevel,
DynamicField<point>& start,
DynamicField<point>& end
) const;
//- Generate pairs of rays through cell centre
// Each ray pair has start, end, and expected gap size
label generateRays
(
const bool useSurfaceNormal,
......@@ -366,10 +382,13 @@ private:
const point& cc,
const label cLevel,
point& start,
point& end,
point& start2,
point& end2
DynamicField<point>& start,
DynamicField<point>& end,
DynamicField<scalar>& gapSize,
DynamicField<point>& start2,
DynamicField<point>& end2,
DynamicField<scalar>& gapSize2
) const;
//- Select candidate cells (cells inside a shell with gapLevel
......@@ -400,9 +419,12 @@ private:
label markInternalGapRefinement
(
const scalar planarCos,
const bool spreadGapSize,
const label nAllowRefine,
labelList& refineCell,
label& nRefine
label& nRefine,
labelList& numGapCells,
scalarField& gapSize
) const;
//- Refine cells containing small gaps
......@@ -958,6 +980,7 @@ public:
const bool smallFeatureRefinement,
const bool gapRefinement,
const bool bigGapRefinement,
const bool spreadGapSize,
const label maxGlobalCells,
const label maxLocalCells
) const;
......
......@@ -2055,6 +2055,7 @@ Foam::labelList Foam::meshRefinement::refineCandidates
const bool smallFeatureRefinement,
const bool gapRefinement,
const bool bigGapRefinement,
const bool spreadGapSize,
const label maxGlobalCells,
const label maxLocalCells
) const
......@@ -2290,12 +2291,18 @@ Foam::labelList Foam::meshRefinement::refineCandidates
{
// Refine based on gap information provided by shell and nearest
// surface
labelList numGapCells;
scalarField gapSize;
label nGap = markInternalGapRefinement
(
planarCos,
spreadGapSize,
nAllowRefine,
refineCell,
nRefine
nRefine,
numGapCells,
gapSize
);
Info<< "Marked for refinement due to opposite surfaces"
<< " "
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 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::transportData
Description
Holds information (coordinate and distance). Walks out 0.5*distance.
SourceFiles
transportDataI.H
transportData.C
\*---------------------------------------------------------------------------*/
#ifndef transportData_H
#define transportData_H
#include "wallPointData.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class polyMesh;
class hexRef8;
/*---------------------------------------------------------------------------*\
Class transportData Declaration
\*---------------------------------------------------------------------------*/
class transportData
:
public wallPointData<scalar>
{
private:
// Private Member Functions
//- Evaluate distance to point. Update distSqr, origin from whomever
// is nearer pt. Return true if w2 is closer to point,
// false otherwise.
template<class TrackingData>
inline bool update
(
const point&,
const transportData& w2,
const scalar tol,
TrackingData& td
);
public:
// Constructors
//- Construct null
inline transportData();
//- Construct from origin, gapSize, distance
inline transportData
(
const point& origin,
const scalar gapSize,
const scalar distSqr
);
// Member Functions
// Needed by FaceCellWave
//- Influence of neighbouring face.
// Calls update(...) with cellCentre of cellI
template<class TrackingData>
inline bool updateCell
(
const polyMesh& mesh,
const label thisCellI,
const label neighbourFaceI,
const transportData& neighbourWallInfo,
const scalar tol,
TrackingData& td
);
//- Influence of neighbouring cell.
// Calls update(...) with faceCentre of faceI
template<class TrackingData>
inline bool updateFace
(
const polyMesh& mesh,
const label thisFaceI,
const label neighbourCellI,
const transportData& neighbourWallInfo,
const scalar tol,
TrackingData& td
);
//- Influence of different value on same face.
// Merge new and old info.
// Calls update(...) with faceCentre of faceI
template<class TrackingData>
inline bool updateFace
(
const polyMesh& mesh,
const label thisFaceI,
const transportData& neighbourWallInfo,
const scalar tol,
TrackingData& td
);
};
//- Data associated with transportData type is same as underlying
template<>
inline bool contiguous<transportData>()
{
return contiguous<wallPointData<scalar> >();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "transportDataI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2015 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 "polyMesh.H"
#include "transform.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Update this with w2 if w2 nearer to pt.
template<class TrackingData>
inline bool Foam::transportData::update
(
const point& pt,
const transportData& w2,
const scalar tol,
TrackingData& td
)
{
scalar dist2 = magSqr(pt - w2.origin());
if (valid(td))
{
scalar diff = distSqr() - dist2;
if (diff < 0)
{
// Already nearer to pt
return false;
}
if ((diff < SMALL) || ((distSqr() > SMALL) && (diff/distSqr() < tol)))
{
// Don't propagate small changes
return false;
}
}
// Either *this is not yet valid or w2 is closer
{
// current not yet set so use any value
distSqr() = dist2;
origin() = w2.origin();
data() = w2.data();
if (distSqr() > sqr(0.25*data()))
{
// No need to transport gap data since too far away
return false;
}
return true;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::transportData::transportData()
:
wallPointData<scalar>()
{}
inline Foam::transportData::transportData
(
const point& origin,
const scalar gapSize,
const scalar distSqr
)
:
wallPointData<scalar>(origin, gapSize, distSqr)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class TrackingData>
inline bool Foam::transportData::updateCell
(
const polyMesh& mesh,
const label cellI,
const label,
const transportData& neighbourWallInfo,
const scalar tol,
TrackingData& td
)
{
const vectorField& cellCentres = mesh.primitiveMesh::cellCentres();
bool updated = update
(
cellCentres[cellI],
neighbourWallInfo,
tol,
td
);
return updated;
}
template<class TrackingData>
inline bool Foam::transportData::updateFace
(
const polyMesh& mesh,
const label thisFaceI,
const label neighbourCellI,
const transportData& neighbourWallInfo,
const scalar tol,
TrackingData& td
)
{
return update
(
mesh.faceCentres()[thisFaceI],
neighbourWallInfo,
tol,
td
);
}
template<class TrackingData>
inline bool Foam::transportData::updateFace
(
const polyMesh& mesh,
const label thisFaceI,
const transportData& neighbourWallInfo,
const scalar tol,
TrackingData& td
)
{
return update
(
mesh.faceCentres()[thisFaceI],
neighbourWallInfo,
tol,
td
);
}
// ************************************************************************* //
......@@ -1373,6 +1373,56 @@ void Foam::refinementSurfaces::findNearestIntersection
}
void Foam::refinementSurfaces::findNearestIntersection
(
const pointField& start,
const pointField& end,
labelList& surface1,
List<pointIndexHit>& hitInfo1,
vectorField& normal1
) const
{
// 1. intersection from start to end
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Initialize arguments
surface1.setSize(start.size());
surface1 = -1;
hitInfo1.setSize(start.size());
hitInfo1 = pointIndexHit();
normal1.setSize(start.size());
normal1 = vector::zero;
// Current end of segment to test.
pointField nearest(end);
// Work array
List<pointIndexHit> nearestInfo(start.size());
labelList region;
vectorField normal;
forAll(surfaces_, surfI)
{
const searchableSurface& geom = allGeometry_[surfaces_[surfI]];
// See if any intersection between start and current nearest
geom.findLine(start, nearest, nearestInfo);
geom.getNormal(nearestInfo, normal);
forAll(nearestInfo, pointI)
{
if (nearestInfo[pointI].hit())
{
surface1[pointI] = surfI;
hitInfo1[pointI] = nearestInfo[pointI];
normal1[pointI] = normal[pointI];
nearest[pointI] = nearestInfo[pointI].hitPoint();
}
}
}
}
void Foam::refinementSurfaces::findAnyIntersection
(
const pointField& start,
......
......@@ -350,6 +350,16 @@ public:
vectorField& normal
) const;
//- Find nearest (to start only) intersection of edge
void findNearestIntersection
(
const pointField& start,
const pointField& end,
labelList& surfaces,
List<pointIndexHit>&,
vectorField& normal
) const;
//- Used for debugging only: find intersection of edge.
void findAnyIntersection
(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment