From 6d06f737cdca3992c0e560f229df7475cb3ed17e Mon Sep 17 00:00:00 2001 From: Will Bainbridge Date: Fri, 20 Oct 2017 15:10:39 +0100 Subject: [PATCH] functionObjects: nearWallFields: Fixed failed patch faces Corrected a few issues with the utilisation of the tracking within the nearWallFields function object. The tracking is now done over a displacement from the initial location, which prevents trying to track to a location outside the mesh when the patch face is warped and the centre lies outside the tracking decomposition. Also fixed the end criteria so that it does not suffer from round off error in the step fraction. The upshot of these changes is that the faces on which the near wall cells were not being set are now being set properly, and uninitialised data is no longer being written out. --- .../field/nearWallFields/findCellParticle.C | 27 +++++++------- .../field/nearWallFields/findCellParticle.H | 35 ++++++------------- .../field/nearWallFields/nearWallFields.C | 11 +++--- 3 files changed, 26 insertions(+), 47 deletions(-) diff --git a/src/functionObjects/field/nearWallFields/findCellParticle.C b/src/functionObjects/field/nearWallFields/findCellParticle.C index 756bd50200..b23d408020 100644 --- a/src/functionObjects/field/nearWallFields/findCellParticle.C +++ b/src/functionObjects/field/nearWallFields/findCellParticle.C @@ -34,13 +34,12 @@ Foam::findCellParticle::findCellParticle const label celli, const label tetFacei, const label tetPtI, - const point& end, + const vector& displacement, const label data ) : particle(mesh, coordinates, celli, tetFacei, tetPtI), - start_(position()), - end_(end), + displacement_(displacement), data_(data) {} @@ -50,13 +49,12 @@ Foam::findCellParticle::findCellParticle const polyMesh& mesh, const vector& position, const label celli, - const point& end, + const vector& displacement, const label data ) : particle(mesh, position, celli), - start_(this->position()), - end_(end), + displacement_(displacement), data_(data) {} @@ -74,15 +72,15 @@ Foam::findCellParticle::findCellParticle { if (is.format() == IOstream::ASCII) { - is >> start_ >> end_; + is >> displacement_; data_ = readLabel(is); } else { is.read ( - reinterpret_cast(&start_), - sizeof(start_) + sizeof(end_) + sizeof(data_) + reinterpret_cast(&displacement_), + sizeof(displacement_) + sizeof(data_) ); } } @@ -111,10 +109,10 @@ bool Foam::findCellParticle::move while (td.keepParticle && !td.switchProcessor && stepFraction() < 1) { const scalar f = 1 - stepFraction(); - trackToAndHitFace(f*(end_ - start_), f, cloud, td); + trackToAndHitFace(f*displacement_, f, cloud, td); } - if (stepFraction() == 1 || !td.keepParticle) + if (!td.switchProcessor) { // Hit endpoint or patch. If patch hit could do fancy stuff but just // to use the patch point is good enough for now. @@ -229,8 +227,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const findCellParticle& p) if (os.format() == IOstream::ASCII) { os << static_cast(p) - << token::SPACE << p.start_ - << token::SPACE << p.end_ + << token::SPACE << p.displacement_ << token::SPACE << p.data_; } else @@ -238,8 +235,8 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const findCellParticle& p) os << static_cast(p); os.write ( - reinterpret_cast(&p.start_), - sizeof(p.start_) + sizeof(p.end_) + sizeof(p.data_) + reinterpret_cast(&p.displacement_), + sizeof(p.displacement_) + sizeof(p.data_) ); } diff --git a/src/functionObjects/field/nearWallFields/findCellParticle.H b/src/functionObjects/field/nearWallFields/findCellParticle.H index f8a88ae115..4e883760a8 100644 --- a/src/functionObjects/field/nearWallFields/findCellParticle.H +++ b/src/functionObjects/field/nearWallFields/findCellParticle.H @@ -63,11 +63,8 @@ class findCellParticle { // Private data - //- Start point to track from - point start_; - - //- End point to track to - point end_; + //- Displacement over which to track + vector displacement_; //- Passive data label data_; @@ -126,7 +123,7 @@ public: const label celli, const label tetFacei, const label tetPtI, - const point& end, + const vector& displacement, const label data ); @@ -137,7 +134,7 @@ public: const polyMesh& mesh, const vector& position, const label celli, - const point& end, + const vector& displacement, const label data ); @@ -180,28 +177,16 @@ public: // Member Functions - //- Point to track from - const point& start() const + //- Displacement over which to track + const vector& displacement() const { - return start_; + return displacement_; } - //- Point to track from - point& start() + //- Displacement over which to track + vector& displacement() { - return start_; - } - - //- Point to track to - const point& end() const - { - return end_; - } - - //- Point to track to - point& end() - { - return end_; + return displacement_; } //- Transported label diff --git a/src/functionObjects/field/nearWallFields/nearWallFields.C b/src/functionObjects/field/nearWallFields/nearWallFields.C index fa4e086ee2..3c79c2b221 100644 --- a/src/functionObjects/field/nearWallFields/nearWallFields.C +++ b/src/functionObjects/field/nearWallFields/nearWallFields.C @@ -79,17 +79,14 @@ void Foam::functionObjects::nearWallFields::calcAddressing() forAll(patch, patchFacei) { - const point& start = patch.Cf()[patchFacei]; - const point end = start - distance_*nf[patchFacei]; - cloud.addParticle ( new findCellParticle ( mesh_, - start, + patch.Cf()[patchFacei], patch.faceCells()[patchFacei], - end, + - distance_*nf[patchFacei], globalWalls.toGlobal(nPatchFaces) // passive data ) ); @@ -112,8 +109,8 @@ void Foam::functionObjects::nearWallFields::calcAddressing() forAllConstIter(Cloud, cloud, iter) { - const findCellParticle& tp = iter(); - str.write(linePointRef(tp.position(), tp.end())); + const vector p = iter().position(); + str.write(linePointRef(p, p + iter().displacement())); } }