mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: mappedPatch: survive neg-tet volume cells
In case of point not being found re-search for nearest
This commit is contained in:
@ -41,6 +41,7 @@ License
|
|||||||
#include "triPointRef.H"
|
#include "triPointRef.H"
|
||||||
#include "syncTools.H"
|
#include "syncTools.H"
|
||||||
#include "treeDataCell.H"
|
#include "treeDataCell.H"
|
||||||
|
#include "DynamicField.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -52,14 +53,15 @@ namespace Foam
|
|||||||
const char* Foam::NamedEnum
|
const char* Foam::NamedEnum
|
||||||
<
|
<
|
||||||
Foam::mappedPatchBase::sampleMode,
|
Foam::mappedPatchBase::sampleMode,
|
||||||
5
|
6
|
||||||
>::names[] =
|
>::names[] =
|
||||||
{
|
{
|
||||||
"nearestCell",
|
"nearestCell",
|
||||||
"nearestPatchFace",
|
"nearestPatchFace",
|
||||||
"nearestPatchFaceAMI",
|
"nearestPatchFaceAMI",
|
||||||
"nearestPatchPoint",
|
"nearestPatchPoint",
|
||||||
"nearestFace"
|
"nearestFace",
|
||||||
|
"nearestOnlyCell"
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
@ -76,7 +78,7 @@ namespace Foam
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const Foam::NamedEnum<Foam::mappedPatchBase::sampleMode, 5>
|
const Foam::NamedEnum<Foam::mappedPatchBase::sampleMode, 6>
|
||||||
Foam::mappedPatchBase::sampleModeNames_;
|
Foam::mappedPatchBase::sampleModeNames_;
|
||||||
|
|
||||||
const Foam::NamedEnum<Foam::mappedPatchBase::offsetMode, 3>
|
const Foam::NamedEnum<Foam::mappedPatchBase::offsetMode, 3>
|
||||||
@ -187,6 +189,7 @@ void Foam::mappedPatchBase::collectSamples
|
|||||||
// for samples being found in two processors.
|
// for samples being found in two processors.
|
||||||
void Foam::mappedPatchBase::findSamples
|
void Foam::mappedPatchBase::findSamples
|
||||||
(
|
(
|
||||||
|
const sampleMode mode,
|
||||||
const pointField& samples,
|
const pointField& samples,
|
||||||
labelList& sampleProcs,
|
labelList& sampleProcs,
|
||||||
labelList& sampleIndices,
|
labelList& sampleIndices,
|
||||||
@ -199,7 +202,7 @@ void Foam::mappedPatchBase::findSamples
|
|||||||
// All the info for nearest. Construct to miss
|
// All the info for nearest. Construct to miss
|
||||||
List<nearInfo> nearest(samples.size());
|
List<nearInfo> nearest(samples.size());
|
||||||
|
|
||||||
switch (mode_)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case NEARESTCELL:
|
case NEARESTCELL:
|
||||||
{
|
{
|
||||||
@ -210,7 +213,7 @@ void Foam::mappedPatchBase::findSamples
|
|||||||
"mappedPatchBase::findSamples(const pointField&,"
|
"mappedPatchBase::findSamples(const pointField&,"
|
||||||
" labelList&, labelList&, pointField&) const"
|
" labelList&, labelList&, pointField&) const"
|
||||||
) << "No need to supply a patch name when in "
|
) << "No need to supply a patch name when in "
|
||||||
<< sampleModeNames_[mode_] << " mode." << exit(FatalError);
|
<< sampleModeNames_[mode] << " mode." << exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Note: face-diagonal decomposition
|
//- Note: face-diagonal decomposition
|
||||||
@ -244,6 +247,36 @@ void Foam::mappedPatchBase::findSamples
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case NEARESTONLYCELL:
|
||||||
|
{
|
||||||
|
if (samplePatch_.size() && samplePatch_ != "none")
|
||||||
|
{
|
||||||
|
FatalErrorIn
|
||||||
|
(
|
||||||
|
"mappedPatchBase::findSamples(const pointField&,"
|
||||||
|
" labelList&, labelList&, pointField&) const"
|
||||||
|
) << "No need to supply a patch name when in "
|
||||||
|
<< sampleModeNames_[mode] << " mode." << exit(FatalError);
|
||||||
|
}
|
||||||
|
|
||||||
|
//- Note: face-diagonal decomposition
|
||||||
|
const indexedOctree<Foam::treeDataCell>& tree = mesh.cellTree();
|
||||||
|
|
||||||
|
forAll(samples, sampleI)
|
||||||
|
{
|
||||||
|
const point& sample = samples[sampleI];
|
||||||
|
|
||||||
|
nearest[sampleI].first() = tree.findNearest(sample, sqr(GREAT));
|
||||||
|
nearest[sampleI].second().first() = magSqr
|
||||||
|
(
|
||||||
|
nearest[sampleI].first().hitPoint()
|
||||||
|
-sample
|
||||||
|
);
|
||||||
|
nearest[sampleI].second().second() = Pstream::myProcNo();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case NEARESTPATCHFACE:
|
case NEARESTPATCHFACE:
|
||||||
{
|
{
|
||||||
Random rndGen(123456);
|
Random rndGen(123456);
|
||||||
@ -398,7 +431,7 @@ void Foam::mappedPatchBase::findSamples
|
|||||||
"mappedPatchBase::findSamples(const pointField&,"
|
"mappedPatchBase::findSamples(const pointField&,"
|
||||||
" labelList&, labelList&, pointField&) const"
|
" labelList&, labelList&, pointField&) const"
|
||||||
) << "No need to supply a patch name when in "
|
) << "No need to supply a patch name when in "
|
||||||
<< sampleModeNames_[mode_] << " mode." << exit(FatalError);
|
<< sampleModeNames_[mode] << " mode." << exit(FatalError);
|
||||||
}
|
}
|
||||||
|
|
||||||
//- Note: face-diagonal decomposition
|
//- Note: face-diagonal decomposition
|
||||||
@ -565,7 +598,7 @@ void Foam::mappedPatchBase::calcMapping() const
|
|||||||
labelList sampleProcs;
|
labelList sampleProcs;
|
||||||
labelList sampleIndices;
|
labelList sampleIndices;
|
||||||
pointField sampleLocations;
|
pointField sampleLocations;
|
||||||
findSamples(samples, sampleProcs, sampleIndices, sampleLocations);
|
findSamples(mode_, samples, sampleProcs, sampleIndices, sampleLocations);
|
||||||
|
|
||||||
// Check for samples that were not found. This will only happen for
|
// Check for samples that were not found. This will only happen for
|
||||||
// NEARESTCELL since finds cell containing a location
|
// NEARESTCELL since finds cell containing a location
|
||||||
@ -607,32 +640,36 @@ void Foam::mappedPatchBase::calcMapping() const
|
|||||||
hasWarned = true;
|
hasWarned = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset the samples that cannot be found to the cell centres.
|
// Collect the samples that cannot be found
|
||||||
pointField patchCc;
|
DynamicList<label> subMap;
|
||||||
{
|
DynamicField<point> subSamples;
|
||||||
List<pointField> globalCc(Pstream::nProcs());
|
|
||||||
globalCc[Pstream::myProcNo()] = patch_.faceCellCentres();
|
|
||||||
Pstream::gatherList(globalCc);
|
|
||||||
Pstream::scatterList(globalCc);
|
|
||||||
patchCc = ListListOps::combine<pointField>
|
|
||||||
(
|
|
||||||
globalCc,
|
|
||||||
accessOp<pointField>()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
forAll(sampleProcs, sampleI)
|
forAll(sampleProcs, sampleI)
|
||||||
{
|
{
|
||||||
if (sampleProcs[sampleI] == -1)
|
if (sampleProcs[sampleI] == -1)
|
||||||
{
|
{
|
||||||
// Reset to cell centres
|
subMap.append(sampleI);
|
||||||
samples[sampleI] = patchCc[sampleI];
|
subSamples.append(samples[sampleI]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// And re-search. Note: could be optimised to only search missing
|
// And re-search for pure nearest (should not fail)
|
||||||
// points.
|
labelList subSampleProcs;
|
||||||
findSamples(samples, sampleProcs, sampleIndices, sampleLocations);
|
labelList subSampleIndices;
|
||||||
|
pointField subSampleLocations;
|
||||||
|
findSamples
|
||||||
|
(
|
||||||
|
NEARESTONLYCELL,
|
||||||
|
subSamples,
|
||||||
|
subSampleProcs,
|
||||||
|
subSampleIndices,
|
||||||
|
subSampleLocations
|
||||||
|
);
|
||||||
|
|
||||||
|
// Insert
|
||||||
|
UIndirectList<label>(sampleProcs, subMap) = subSampleProcs;
|
||||||
|
UIndirectList<label>(sampleIndices, subMap) = subSampleIndices;
|
||||||
|
UIndirectList<point>(sampleLocations, subMap) = subSampleLocations;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
========= |
|
========= |
|
||||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
\\ / O peration |
|
\\ / O peration |
|
||||||
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
|
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
|
||||||
\\/ M anipulation |
|
\\/ M anipulation |
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
License
|
License
|
||||||
@ -34,6 +34,8 @@ Description
|
|||||||
|
|
||||||
// What to sample:
|
// What to sample:
|
||||||
// - nearestCell : sample cell containing point
|
// - nearestCell : sample cell containing point
|
||||||
|
// - nearestOnlyCell : nearest sample cell (even if not containing
|
||||||
|
// point)
|
||||||
// - nearestPatchFace : nearest face on selected patch
|
// - nearestPatchFace : nearest face on selected patch
|
||||||
// - nearestPatchFaceAMI : nearest face on selected patch
|
// - nearestPatchFaceAMI : nearest face on selected patch
|
||||||
- patches need not conform
|
- patches need not conform
|
||||||
@ -107,11 +109,12 @@ public:
|
|||||||
//- Mesh items to sample
|
//- Mesh items to sample
|
||||||
enum sampleMode
|
enum sampleMode
|
||||||
{
|
{
|
||||||
NEARESTCELL, // nearest cell
|
NEARESTCELL, // nearest cell containing sample
|
||||||
NEARESTPATCHFACE, // nearest face on selected patch
|
NEARESTPATCHFACE, // nearest face on selected patch
|
||||||
NEARESTPATCHFACEAMI, // nearest patch face + AMI interpolation
|
NEARESTPATCHFACEAMI, // nearest patch face + AMI interpolation
|
||||||
NEARESTPATCHPOINT, // nearest point on selected patch
|
NEARESTPATCHPOINT, // nearest point on selected patch
|
||||||
NEARESTFACE // nearest face
|
NEARESTFACE, // nearest face
|
||||||
|
NEARESTONLYCELL // nearest cell (even if not containing cell)
|
||||||
};
|
};
|
||||||
|
|
||||||
//- How to project face centres
|
//- How to project face centres
|
||||||
@ -122,7 +125,7 @@ public:
|
|||||||
NORMAL // use face normal + distance
|
NORMAL // use face normal + distance
|
||||||
};
|
};
|
||||||
|
|
||||||
static const NamedEnum<sampleMode, 5> sampleModeNames_;
|
static const NamedEnum<sampleMode, 6> sampleModeNames_;
|
||||||
|
|
||||||
static const NamedEnum<offsetMode, 3> offsetModeNames_;
|
static const NamedEnum<offsetMode, 3> offsetModeNames_;
|
||||||
|
|
||||||
@ -255,6 +258,7 @@ protected:
|
|||||||
//- Find cells/faces containing samples
|
//- Find cells/faces containing samples
|
||||||
void findSamples
|
void findSamples
|
||||||
(
|
(
|
||||||
|
const sampleMode mode, // search mode
|
||||||
const pointField&,
|
const pointField&,
|
||||||
labelList& sampleProcs, // processor containing sample
|
labelList& sampleProcs, // processor containing sample
|
||||||
labelList& sampleIndices, // local index of cell/face
|
labelList& sampleIndices, // local index of cell/face
|
||||||
|
|||||||
Reference in New Issue
Block a user