mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
sampledSet/midPoint, midPointAndFace: Improved robustness of the mid-point cell seaching and selecting
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -25,6 +25,7 @@ License
|
||||
|
||||
#include "midPointSet.H"
|
||||
#include "polyMesh.H"
|
||||
#include "meshSearch.H"
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
@ -47,58 +48,46 @@ void Foam::midPointSet::genSamples()
|
||||
labelList midSegments(2*size());
|
||||
scalarList midCurveDist(2*size());
|
||||
|
||||
label midI = 0;
|
||||
label mSamplei = 0;
|
||||
label samplei = 0;
|
||||
|
||||
label sampleI = 0;
|
||||
|
||||
while(true && size()>0)
|
||||
while (size() > 0)
|
||||
{
|
||||
// calculate midpoint between sampleI and sampleI+1 (if in same segment)
|
||||
// Calculate midpoint between samplei and samplei+1 (if in same segment)
|
||||
while
|
||||
(
|
||||
(sampleI < size() - 1)
|
||||
&& (segments_[sampleI] == segments_[sampleI+1])
|
||||
(samplei < size() - 1)
|
||||
&& (segments_[samplei] == segments_[samplei+1])
|
||||
)
|
||||
{
|
||||
midPoints[midI] =
|
||||
0.5*(operator[](sampleI) + operator[](sampleI+1));
|
||||
point midPoint(0.5*(operator[](samplei) + operator[](samplei+1)));
|
||||
label cellm = pointInCell(midPoint, samplei);
|
||||
|
||||
label cell1 = getCell(faces_[sampleI], midPoints[midI]);
|
||||
label cell2 = getCell(faces_[sampleI+1], midPoints[midI]);
|
||||
|
||||
if (cell1 != cell2)
|
||||
if (cellm != -1)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< " midI:" << midI
|
||||
<< " sampleI:" << sampleI
|
||||
<< " pts[sampleI]:" << operator[](sampleI)
|
||||
<< " face[sampleI]:" << faces_[sampleI]
|
||||
<< " pts[sampleI+1]:" << operator[](sampleI+1)
|
||||
<< " face[sampleI+1]:" << faces_[sampleI+1]
|
||||
<< " cell1:" << cell1
|
||||
<< " cell2:" << cell2
|
||||
<< abort(FatalError);
|
||||
midPoints[mSamplei] = midPoint;
|
||||
midCells[mSamplei] = cellm;
|
||||
midSegments[mSamplei] = segments_[samplei];
|
||||
midCurveDist[mSamplei] = mag(midPoints[mSamplei] - start());
|
||||
mSamplei++;
|
||||
}
|
||||
|
||||
midCells[midI] = cell1;
|
||||
midSegments[midI] = segments_[sampleI];
|
||||
midCurveDist[midI] = mag(midPoints[midI] - start());
|
||||
|
||||
midI++;
|
||||
sampleI++;
|
||||
samplei++;
|
||||
}
|
||||
|
||||
if (sampleI == size() - 1)
|
||||
if (samplei == size() - 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
sampleI++;
|
||||
|
||||
samplei++;
|
||||
}
|
||||
|
||||
midPoints.setSize(midI);
|
||||
midCells.setSize(midI);
|
||||
midSegments.setSize(midI);
|
||||
midCurveDist.setSize(midI);
|
||||
midPoints.setSize(mSamplei);
|
||||
midCells.setSize(mSamplei);
|
||||
midSegments.setSize(mSamplei);
|
||||
midCurveDist.setSize(mSamplei);
|
||||
|
||||
setSamples
|
||||
(
|
||||
midPoints,
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -39,101 +39,83 @@ namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
// Rework faceOnlySet samples.
|
||||
// Take two consecutive samples
|
||||
void Foam::midPointAndFaceSet::genSamples()
|
||||
{
|
||||
// Generate midpoints and add to face points
|
||||
|
||||
List<point> newSamplePoints(3*size());
|
||||
labelList newSampleCells(3*size());
|
||||
labelList newSampleFaces(3*size());
|
||||
labelList newSampleSegments(3*size());
|
||||
scalarList newSampleCurveDist(3*size());
|
||||
List<point> mpfSamplePoints(3*size());
|
||||
labelList mpfSampleCells(3*size());
|
||||
labelList mpfSampleFaces(3*size());
|
||||
labelList mpfSampleSegments(3*size());
|
||||
scalarList mpfSampleCurveDist(3*size());
|
||||
|
||||
label newSampleI = 0;
|
||||
label mpfSamplei = 0;
|
||||
label samplei = 0;
|
||||
|
||||
label sampleI = 0;
|
||||
|
||||
while(true && size()>0)
|
||||
while (size() > 0)
|
||||
{
|
||||
// sampleI is start of segment
|
||||
|
||||
// Add sampleI
|
||||
newSamplePoints[newSampleI] = operator[](sampleI);
|
||||
newSampleCells[newSampleI] = cells_[sampleI];
|
||||
newSampleFaces[newSampleI] = faces_[sampleI];
|
||||
newSampleSegments[newSampleI] = segments_[sampleI];
|
||||
newSampleCurveDist[newSampleI] = curveDist_[sampleI];
|
||||
newSampleI++;
|
||||
// Add first face
|
||||
mpfSamplePoints[mpfSamplei] = operator[](samplei);
|
||||
mpfSampleCells[mpfSamplei] = cells_[samplei];
|
||||
mpfSampleFaces[mpfSamplei] = faces_[samplei];
|
||||
mpfSampleSegments[mpfSamplei] = segments_[samplei];
|
||||
mpfSampleCurveDist[mpfSamplei] = curveDist_[samplei];
|
||||
mpfSamplei++;
|
||||
|
||||
while
|
||||
(
|
||||
(sampleI < size() - 1)
|
||||
&& (segments_[sampleI] == segments_[sampleI+1])
|
||||
(samplei < size() - 1)
|
||||
&& (segments_[samplei] == segments_[samplei+1])
|
||||
)
|
||||
{
|
||||
// Add mid point
|
||||
const point mid = 0.5*(operator[](sampleI) + operator[](sampleI+1));
|
||||
point midPoint(0.5*(operator[](samplei) + operator[](samplei+1)));
|
||||
label cellm = pointInCell(midPoint, samplei);
|
||||
|
||||
label cell1 = getCell(faces_[sampleI], mid);
|
||||
label cell2 = getCell(faces_[sampleI+1], mid);
|
||||
|
||||
if (cell1 != cell2)
|
||||
if (cellm != -1)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< " newSampleI:" << newSampleI
|
||||
<< " pts[sampleI]:" << operator[](sampleI)
|
||||
<< " face[sampleI]:" << faces_[sampleI]
|
||||
<< " pts[sampleI+1]:" << operator[](sampleI+1)
|
||||
<< " face[sampleI+1]:" << faces_[sampleI+1]
|
||||
<< " cell1:" << cell1
|
||||
<< " cell2:" << cell2
|
||||
<< abort(FatalError);
|
||||
mpfSamplePoints[mpfSamplei] = midPoint;
|
||||
mpfSampleCells[mpfSamplei] = cellm;
|
||||
mpfSampleFaces[mpfSamplei] = -1;
|
||||
mpfSampleSegments[mpfSamplei] = segments_[samplei];
|
||||
mpfSampleCurveDist[mpfSamplei] =
|
||||
mag(mpfSamplePoints[mpfSamplei] - start());
|
||||
|
||||
mpfSamplei++;
|
||||
}
|
||||
|
||||
newSamplePoints[newSampleI] = mid;
|
||||
newSampleCells[newSampleI] = cell1;
|
||||
newSampleFaces[newSampleI] = -1;
|
||||
newSampleSegments[newSampleI] = segments_[sampleI];
|
||||
newSampleCurveDist[newSampleI] =
|
||||
mag(newSamplePoints[newSampleI] - start());
|
||||
// Add second face
|
||||
mpfSamplePoints[mpfSamplei] = operator[](samplei+1);
|
||||
mpfSampleCells[mpfSamplei] = cells_[samplei+1];
|
||||
mpfSampleFaces[mpfSamplei] = faces_[samplei+1];
|
||||
mpfSampleSegments[mpfSamplei] = segments_[samplei+1];
|
||||
mpfSampleCurveDist[mpfSamplei] =
|
||||
mag(mpfSamplePoints[mpfSamplei] - start());
|
||||
|
||||
newSampleI++;
|
||||
mpfSamplei++;
|
||||
|
||||
// Add sampleI+1
|
||||
newSamplePoints[newSampleI] = operator[](sampleI+1);
|
||||
newSampleCells[newSampleI] = cells_[sampleI+1];
|
||||
newSampleFaces[newSampleI] = faces_[sampleI+1];
|
||||
newSampleSegments[newSampleI] = segments_[sampleI+1];
|
||||
newSampleCurveDist[newSampleI] =
|
||||
mag(newSamplePoints[newSampleI] - start());
|
||||
|
||||
newSampleI++;
|
||||
|
||||
sampleI++;
|
||||
samplei++;
|
||||
}
|
||||
|
||||
if (sampleI == size() - 1)
|
||||
if (samplei == size() - 1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
sampleI++;
|
||||
samplei++;
|
||||
}
|
||||
|
||||
newSamplePoints.setSize(newSampleI);
|
||||
newSampleCells.setSize(newSampleI);
|
||||
newSampleFaces.setSize(newSampleI);
|
||||
newSampleSegments.setSize(newSampleI);
|
||||
newSampleCurveDist.setSize(newSampleI);
|
||||
mpfSamplePoints.setSize(mpfSamplei);
|
||||
mpfSampleCells.setSize(mpfSamplei);
|
||||
mpfSampleFaces.setSize(mpfSamplei);
|
||||
mpfSampleSegments.setSize(mpfSamplei);
|
||||
mpfSampleCurveDist.setSize(mpfSamplei);
|
||||
|
||||
setSamples
|
||||
(
|
||||
newSamplePoints,
|
||||
newSampleCells,
|
||||
newSampleFaces,
|
||||
newSampleSegments,
|
||||
newSampleCurveDist
|
||||
mpfSamplePoints,
|
||||
mpfSampleCells,
|
||||
mpfSampleFaces,
|
||||
mpfSampleSegments,
|
||||
mpfSampleCurveDist
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@ -47,61 +47,57 @@ Foam::label Foam::sampledSet::getBoundaryCell(const label faceI) const
|
||||
}
|
||||
|
||||
|
||||
Foam::label Foam::sampledSet::getCell
|
||||
Foam::label Foam::sampledSet::pointInCell
|
||||
(
|
||||
const label faceI,
|
||||
const point& sample
|
||||
const point& p,
|
||||
const label samplei
|
||||
) const
|
||||
{
|
||||
if (faceI == -1)
|
||||
const label cellio = mesh().faceOwner()[faces_[samplei]];
|
||||
const label cellin = mesh().faceNeighbour()[faces_[samplei]];
|
||||
const label celljo = mesh().faceOwner()[faces_[samplei+1]];
|
||||
const label celljn = mesh().faceNeighbour()[faces_[samplei+1]];
|
||||
|
||||
// If mid-point is in the cell including the sampled faces
|
||||
// include in list otherwise ignore
|
||||
|
||||
label cellm =
|
||||
(cellio == celljo || cellio == celljn) ? cellio
|
||||
: (cellin == celljo || cellin == celljn) ? cellin
|
||||
: -1;
|
||||
|
||||
if (cellm != -1)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Illegal face label " << faceI
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
if (faceI >= mesh().nInternalFaces())
|
||||
{
|
||||
label cellI = getBoundaryCell(faceI);
|
||||
|
||||
if (!mesh().pointInCell(sample, cellI, searchEngine_.decompMode()))
|
||||
// Check the mid-point is in the cell otherwise ignore
|
||||
if (!mesh().pointInCell(p, cellm, searchEngine_.decompMode()))
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Found cell " << cellI << " using face " << faceI
|
||||
<< ". But cell does not contain point " << sample
|
||||
<< abort(FatalError);
|
||||
}
|
||||
return cellI;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Try owner and neighbour to see which one contains sample
|
||||
cellm = -1;
|
||||
|
||||
label cellI = mesh().faceOwner()[faceI];
|
||||
|
||||
if (mesh().pointInCell(sample, cellI, searchEngine_.decompMode()))
|
||||
{
|
||||
return cellI;
|
||||
}
|
||||
else
|
||||
{
|
||||
cellI = mesh().faceNeighbour()[faceI];
|
||||
|
||||
if (mesh().pointInCell(sample, cellI, searchEngine_.decompMode()))
|
||||
if (debug)
|
||||
{
|
||||
return cellI;
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "None of the neighbours of face "
|
||||
<< faceI << " contains point " << sample
|
||||
<< abort(FatalError);
|
||||
|
||||
return -1;
|
||||
WarningInFunction
|
||||
<< "Could not find mid-point " << p
|
||||
<< " cell " << cellm << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (debug)
|
||||
{
|
||||
WarningInFunction
|
||||
<< "Could not find cell for mid-point" << nl
|
||||
<< " samplei: " << samplei
|
||||
<< " pts[samplei]: " << operator[](samplei)
|
||||
<< " face[samplei]: " << faces_[samplei]
|
||||
<< " pts[samplei+1]: " << operator[](samplei+1)
|
||||
<< " face[samplei+1]: " << faces_[samplei+1]
|
||||
<< " cellio: " << cellio
|
||||
<< " cellin: " << cellin
|
||||
<< " celljo: " << celljo
|
||||
<< " celljn: " << celljn
|
||||
<< endl;
|
||||
}
|
||||
|
||||
return cellm;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -92,12 +92,9 @@ protected:
|
||||
//- Returns cell next to boundary face
|
||||
label getBoundaryCell(const label) const;
|
||||
|
||||
//- Returns cell using face and containing sample
|
||||
label getCell
|
||||
(
|
||||
const label faceI,
|
||||
const point& sample
|
||||
) const;
|
||||
//- Return the cell in which the point on the sample line
|
||||
// resides if found otherwise return -1
|
||||
label pointInCell(const point& p, const label samplei) const;
|
||||
|
||||
//- Calculates inproduct of face normal and vector sample-face centre
|
||||
// <0 if sample inside.
|
||||
|
||||
Reference in New Issue
Block a user