mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Lagrangian: Rewrite of the particle tracking algorithm to function in
terms of the local barycentric coordinates of the current tetrahedron, rather than the global coordinate system. Barycentric tracking works on any mesh, irrespective of mesh quality. Particles do not get "lost", and tracking does not require ad-hoc "corrections" or "rescues" to function robustly, because the calculation of particle-face intersections is unambiguous and reproducible, even at small angles of incidence. Each particle position is defined by topology (i.e. the decomposed tet cell it is in) and geometry (i.e. where it is in the cell). No search operations are needed on restart or reconstruct, unlike when particle positions are stored in the global coordinate system. The particle positions file now contains particles' local coordinates and topology, rather than the global coordinates and cell. This change to the output format is not backwards compatible. Existing cases with Lagrangian data will not restart, but they will still run from time zero without any modification. This change was necessary in order to guarantee that the loaded particle is valid, and therefore fundamentally prevent "loss" and "search-failure" type bugs (e.g., 2517, 2442, 2286, 1836, 1461, 1341, 1097). The tracking functions have also been converted to function in terms of displacement, rather than end position. This helps remove floating point error issues, particularly towards the end of a tracking step. Wall bounded streamlines have been removed. The implementation proved incompatible with the new tracking algorithm. ParaView has a surface LIC plugin which provides equivalent, or better, functionality. Additionally, bug report <https://bugs.openfoam.org/view.php?id=2517> is resolved by this change.
This commit is contained in:
committed by
Andrew Heather
parent
dd3be135de
commit
743dea87d2
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -26,35 +26,8 @@ License
|
||||
#include "streamLineParticle.H"
|
||||
#include "vectorFieldIOField.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
// defineParticleTypeNameAndDebug(streamLineParticle, 0);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
Foam::scalar Foam::streamLineParticle::calcSubCycleDeltaT
|
||||
(
|
||||
trackingData& td,
|
||||
const scalar dt,
|
||||
const vector& U
|
||||
) const
|
||||
{
|
||||
particle testParticle(*this);
|
||||
|
||||
bool oldKeepParticle = td.keepParticle;
|
||||
bool oldSwitchProcessor = td.switchProcessor;
|
||||
scalar fraction = testParticle.trackToFace(position()+dt*U, td);
|
||||
td.keepParticle = oldKeepParticle;
|
||||
td.switchProcessor = oldSwitchProcessor;
|
||||
// Adapt the dt to subdivide the trajectory into substeps.
|
||||
return dt*fraction/td.nSubCycle_;
|
||||
}
|
||||
|
||||
|
||||
Foam::vector Foam::streamLineParticle::interpolateFields
|
||||
(
|
||||
const trackingData& td,
|
||||
@ -129,7 +102,6 @@ Foam::streamLineParticle::streamLineParticle
|
||||
{
|
||||
if (readFields)
|
||||
{
|
||||
//if (is.format() == IOstream::ASCII)
|
||||
List<scalarList> sampledScalars;
|
||||
List<vectorList> sampledVectors;
|
||||
|
||||
@ -169,31 +141,22 @@ Foam::streamLineParticle::streamLineParticle
|
||||
bool Foam::streamLineParticle::move
|
||||
(
|
||||
trackingData& td,
|
||||
const scalar trackTime
|
||||
const scalar
|
||||
)
|
||||
{
|
||||
streamLineParticle& p = static_cast<streamLineParticle&>(*this);
|
||||
|
||||
td.switchProcessor = false;
|
||||
td.keepParticle = true;
|
||||
|
||||
scalar tEnd = (1.0 - stepFraction())*trackTime;
|
||||
scalar maxDt = mesh_.bounds().mag();
|
||||
const scalar maxDt = mesh().bounds().mag();
|
||||
|
||||
while
|
||||
(
|
||||
td.keepParticle
|
||||
&& !td.switchProcessor
|
||||
&& lifeTime_ > 0
|
||||
)
|
||||
while (td.keepParticle && !td.switchProcessor && lifeTime_ > 0)
|
||||
{
|
||||
// set the lagrangian time-step
|
||||
scalar dt = maxDt;
|
||||
|
||||
// Cross cell in steps:
|
||||
// - at subiter 0 calculate dt to cross cell in nSubCycle steps
|
||||
// - at the last subiter do all of the remaining track
|
||||
for (label subIter = 0; subIter < td.nSubCycle_; subIter++)
|
||||
for (label subIter = 0; subIter < max(1, td.nSubCycle_); subIter++)
|
||||
{
|
||||
--lifeTime_;
|
||||
|
||||
@ -219,37 +182,27 @@ bool Foam::streamLineParticle::move
|
||||
|
||||
if (td.trackLength_ < GREAT)
|
||||
{
|
||||
// No sub-cycling. Track a set length on each step.
|
||||
dt = td.trackLength_;
|
||||
//Pout<< " subiteration " << subIter
|
||||
// << " : fixed length: updated dt:" << dt << endl;
|
||||
}
|
||||
else if (subIter == 0 && td.nSubCycle_ > 1)
|
||||
else if (subIter == 0)
|
||||
{
|
||||
// Adapt dt to cross cell in a few steps
|
||||
dt = calcSubCycleDeltaT(td, dt, U);
|
||||
// Sub-cycling. Cross the cell in nSubCycle steps.
|
||||
particle copy(*this);
|
||||
copy.trackToFace(maxDt*U, 1);
|
||||
dt *= (copy.stepFraction() - stepFraction())/td.nSubCycle_;
|
||||
}
|
||||
else if (subIter == td.nSubCycle_ - 1)
|
||||
{
|
||||
// Do full step on last subcycle
|
||||
// Sub-cycling. Track the whole cell on the last step.
|
||||
dt = maxDt;
|
||||
}
|
||||
|
||||
|
||||
scalar fraction = trackToFace(position() + dt*U, td);
|
||||
dt *= fraction;
|
||||
|
||||
tEnd -= dt;
|
||||
stepFraction() = 1.0 - tEnd/trackTime;
|
||||
|
||||
if (tEnd <= ROOTVSMALL)
|
||||
{
|
||||
// Force removal
|
||||
lifeTime_ = 0;
|
||||
}
|
||||
trackToFace(dt*U, 0, td);
|
||||
|
||||
if
|
||||
(
|
||||
face() != -1
|
||||
onFace()
|
||||
|| !td.keepParticle
|
||||
|| td.switchProcessor
|
||||
|| lifeTime_ == 0
|
||||
@ -260,17 +213,16 @@ bool Foam::streamLineParticle::move
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!td.keepParticle || lifeTime_ == 0)
|
||||
{
|
||||
if (lifeTime_ == 0)
|
||||
{
|
||||
// Failure exit. Particle stagnated or it's life ran out.
|
||||
if (debug)
|
||||
{
|
||||
Pout<< "streamLineParticle : Removing stagnant particle:"
|
||||
<< p.position()
|
||||
<< " sampled positions:" << sampledPositions_.size()
|
||||
<< endl;
|
||||
Pout<< "streamLineParticle: Removing stagnant particle:"
|
||||
<< position() << " sampled positions:"
|
||||
<< sampledPositions_.size() << endl;
|
||||
}
|
||||
td.keepParticle = false;
|
||||
}
|
||||
@ -282,29 +234,25 @@ bool Foam::streamLineParticle::move
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Pout<< "streamLineParticle : Removing particle:"
|
||||
<< p.position()
|
||||
Pout<< "streamLineParticle: Removing particle:" << position()
|
||||
<< " sampled positions:" << sampledPositions_.size()
|
||||
<< endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Transfer particle data into trackingData.
|
||||
//td.allPositions_.append(sampledPositions_);
|
||||
td.allPositions_.append(vectorList());
|
||||
vectorList& top = td.allPositions_.last();
|
||||
top.transfer(sampledPositions_);
|
||||
|
||||
forAll(sampledScalars_, i)
|
||||
{
|
||||
//td.allScalars_[i].append(sampledScalars_[i]);
|
||||
td.allScalars_[i].append(scalarList());
|
||||
scalarList& top = td.allScalars_[i].last();
|
||||
top.transfer(sampledScalars_[i]);
|
||||
}
|
||||
forAll(sampledVectors_, i)
|
||||
{
|
||||
//td.allVectors_[i].append(sampledVectors_[i]);
|
||||
td.allVectors_[i].append(vectorList());
|
||||
vectorList& top = td.allVectors_[i].last();
|
||||
top.transfer(sampledVectors_[i]);
|
||||
@ -428,18 +376,11 @@ void Foam::streamLineParticle::readFields(Cloud<streamLineParticle>& c)
|
||||
);
|
||||
c.checkFieldIOobject(c, sampledPositions);
|
||||
|
||||
// vectorFieldIOField sampleVelocity
|
||||
// (
|
||||
// c.fieldIOobject("sampleVelocity", IOobject::MUST_READ)
|
||||
// );
|
||||
// c.checkFieldIOobject(c, sampleVelocity);
|
||||
|
||||
label i = 0;
|
||||
forAllIter(Cloud<streamLineParticle>, c, iter)
|
||||
{
|
||||
iter().lifeTime_ = lifeTime[i];
|
||||
iter().sampledPositions_.transfer(sampledPositions[i]);
|
||||
// iter().sampleVelocity_.transfer(sampleVelocity[i]);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
@ -461,24 +402,17 @@ void Foam::streamLineParticle::writeFields(const Cloud<streamLineParticle>& c)
|
||||
c.fieldIOobject("sampledPositions", IOobject::NO_READ),
|
||||
np
|
||||
);
|
||||
// vectorFieldIOField sampleVelocity
|
||||
// (
|
||||
// c.fieldIOobject("sampleVelocity", IOobject::NO_READ),
|
||||
// np
|
||||
// );
|
||||
|
||||
label i = 0;
|
||||
forAllConstIter(Cloud<streamLineParticle>, c, iter)
|
||||
{
|
||||
lifeTime[i] = iter().lifeTime_;
|
||||
sampledPositions[i] = iter().sampledPositions_;
|
||||
// sampleVelocity[i] = iter().sampleVelocity_;
|
||||
i++;
|
||||
}
|
||||
|
||||
lifeTime.write();
|
||||
sampledPositions.write();
|
||||
// sampleVelocity.write();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user