Cloud: Delete all particles that fail to map

This commit is contained in:
Will Bainbridge
2023-08-22 11:38:31 +01:00
parent bf8b8596f8
commit be88a99ecd
5 changed files with 149 additions and 72 deletions

View File

@ -180,6 +180,16 @@ void Foam::Cloud<ParticleType>::storeRays() const
}
template<class ParticleType>
Foam::string Foam::Cloud<ParticleType>::mapOutsideMsg(const point& position)
{
OStringStream oss;
oss << "Particle at " << position << " mapped to a location outside of "
<< "the new mesh. This particle will be removed.";
return oss.str();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ParticleType>
@ -439,8 +449,14 @@ void Foam::Cloud<ParticleType>::topoChange(const polyTopoChangeMap& map)
label particlei = 0;
forAllIter(typename Cloud<ParticleType>, *this, iter)
{
const point& pos = positions[particlei ++];
const label celli = map.reverseCellMap()[iter().cell()];
iter().map(pMesh_, positions[particlei++], celli);
if (!iter().map(pMesh_, pos, celli, mapOutsideMsg))
{
this->remove(iter);
}
}
}
@ -482,22 +498,26 @@ void Foam::Cloud<ParticleType>::mapMesh(const polyMeshMap& map)
const remote tgtProcCell =
map.mapper().srcToTgtPoint(iter().cell(), pos);
const label proci = tgtProcCell.proci;
const label celli = tgtProcCell.elementi;
if (tgtProcCell == remote())
{
WarningInFunction
<< "Particle at " << pos << " mapped to a location outside "
<< "of the new mesh. This particle will be removed." << nl;
WarningInFunction << mapOutsideMsg(pos) << nl;
this->remove(iter);
}
else if (tgtProcCell.proci == Pstream::myProcNo())
else if (proci == Pstream::myProcNo())
{
iter().map(pMesh_, pos, tgtProcCell.elementi);
if (!iter().map(pMesh_, pos, celli, mapOutsideMsg))
{
this->remove(iter);
}
}
else
{
sendCellIndices[tgtProcCell.proci].append(tgtProcCell.elementi);
sendPositions[tgtProcCell.proci].append(pos);
sendParticles[tgtProcCell.proci].append(this->remove(iter));
sendCellIndices[proci].append(celli);
sendPositions[proci].append(pos);
sendParticles[proci].append(this->remove(iter));
}
}
}
@ -546,8 +566,10 @@ void Foam::Cloud<ParticleType>::mapMesh(const polyMeshMap& map)
const label celli = receiveCellIndices[particlei];
const vector& pos = receivePositions[particlei ++];
iter().map(pMesh_, pos, celli);
this->append(receiveParticles.remove(iter));
if (iter().map(pMesh_, pos, celli, mapOutsideMsg))
{
this->append(receiveParticles.remove(iter));
}
}
}
}
@ -646,9 +668,10 @@ void Foam::Cloud<ParticleType>::distribute(const polyDistributionMap& map)
{
const point& pos = cellParticlePositions[celli][cellParticlei++];
iter().map(pMesh_, pos, celli);
this->append(cellParticles[celli].remove(iter));
if (iter().map(pMesh_, pos, celli, mapOutsideMsg))
{
this->append(cellParticles[celli].remove(iter));
}
}
}
}

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -119,6 +119,9 @@ class Cloud
//- Store rays necessary for non conformal cyclic transfer
void storeRays() const;
//- Generate a "mapped outside" warning messgage
static string mapOutsideMsg(const point& position);
public:

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -369,13 +369,11 @@ void Foam::particle::changeCell(const polyMesh& mesh)
}
void Foam::particle::locate
bool Foam::particle::locate
(
const polyMesh& mesh,
const vector& position,
label celli,
const bool boundaryFail,
const string boundaryMsg
label celli
)
{
if (debug)
@ -421,7 +419,7 @@ void Foam::particle::locate
if (tetTriI == -1)
{
return;
return true;
}
if (f < minF)
@ -444,31 +442,10 @@ void Foam::particle::locate
track(mesh, displacement, 0);
if (!onFace())
{
return;
return true;
}
// If we are here then we hit a boundary
if (boundaryFail)
{
FatalErrorInFunction << boundaryMsg << exit(FatalError);
}
else
{
static label nWarnings = 0;
static const label maxNWarnings = 100;
if (nWarnings < maxNWarnings)
{
WarningInFunction << boundaryMsg.c_str() << endl;
++ nWarnings;
}
if (nWarnings == maxNWarnings)
{
WarningInFunction
<< "Suppressing any further warnings about particles being "
<< "located outside of the mesh." << endl;
++ nWarnings;
}
}
return false;
}
@ -515,13 +492,21 @@ Foam::particle::particle
origProc_(Pstream::myProcNo()),
origId_(getNewParticleID())
{
auto boundaryMsg = [](const point& position)
{
OStringStream oss;
oss << "Particle at " << position << " initialised in a location "
<< "outside of the mesh.";
return oss.str();
};
locate
(
mesh,
position,
celli,
false,
"Particle initialised with a location outside of the mesh."
boundaryMsg
);
}
@ -1118,6 +1103,15 @@ void Foam::particle::correctAfterNonConformalCyclicTransfer
coordinates_.d()
);
auto boundaryMsg = [&nccpp](const point& position)
{
return
"Particle at " + name(position) + " crossed between "
+ nonConformalCyclicPolyPatch::typeName + " patches "
+ nccpp.name() + " and " + nccpp.nbrPatch().name()
+ " to a location outside of the mesh.";
};
// Locate the particle on the receiving side
locate
(
@ -1125,9 +1119,7 @@ void Foam::particle::correctAfterNonConformalCyclicTransfer
receivePos,
mesh.faceOwner()[facei_ + nccpp.origPatch().start()],
false,
"Particle crossed between " + nonConformalCyclicPolyPatch::typeName +
" patches " + nccpp.name() + " and " + nccpp.nbrPatch().name() +
" to a location outside of the mesh."
boundaryMsg
);
// The particle must remain associated with a face for the tracking to
@ -1228,24 +1220,6 @@ Foam::label Foam::particle::procTetPt
}
void Foam::particle::map
(
const polyMesh& mesh,
const vector& position,
const label celli
)
{
locate
(
mesh,
position,
celli,
true,
"Particle mapped to a location outside of the mesh."
);
}
// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
bool Foam::operator==(const particle& pA, const particle& pB)

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -301,13 +301,22 @@ private:
// Geometry changes
//- Locate the particle at the given position
void locate
bool locate
(
const polyMesh& mesh,
const vector& position,
label celli
);
//- Locate the particle at the given position
template<class BoundaryMsg>
bool locate
(
const polyMesh& mesh,
const vector& position,
label celli,
const bool boundaryFail,
const string boundaryMsg
BoundaryMsg boundaryMsg
);
@ -694,11 +703,13 @@ public:
// Mapping
//- Map after a mesh change
void map
template<class BoundaryMsg>
bool map
(
const polyMesh& mesh,
const point& position,
const label celli
const label celli,
BoundaryMsg boundaryMsg
);

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2023 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -35,8 +35,74 @@ License
#include "wedgePolyPatch.H"
#include "meshTools.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class BoundaryMsg>
bool Foam::particle::locate
(
const polyMesh& mesh,
const vector& position,
label celli,
const bool boundaryFail,
BoundaryMsg boundaryMsg
)
{
if (locate(mesh, position, celli))
{
return true;
}
// If we are here then we hit a boundary
if (boundaryFail)
{
FatalErrorInFunction << boundaryMsg(position).c_str()
<< exit(FatalError);
}
else
{
static label nWarnings = 0;
static const label maxNWarnings = 100;
if (nWarnings < maxNWarnings)
{
WarningInFunction << boundaryMsg(position).c_str() << endl;
++ nWarnings;
}
if (nWarnings == maxNWarnings)
{
WarningInFunction
<< "Suppressing any further warnings about particles being "
<< "located outside of the mesh." << endl;
++ nWarnings;
}
}
return false;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class BoundaryMsg>
bool Foam::particle::map
(
const polyMesh& mesh,
const vector& position,
const label celli,
BoundaryMsg boundaryMsg
)
{
return
locate
(
mesh,
position,
celli,
true,
boundaryMsg
);
}
template<class TrackCloudType>
void Foam::particle::readFields(TrackCloudType& c)
{