lagrangian: Improved handling of binary transfers

Now using memory offsets to calculate transfer block sizes rather than
sum of 'sizeof' to ensure word alignment is accounted for
This commit is contained in:
Henry
2015-02-22 12:14:46 +00:00
parent 44ad48906b
commit 1d4ce1f660
26 changed files with 286 additions and 455 deletions

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -24,88 +24,23 @@ License
\*---------------------------------------------------------------------------*/
#include "wallBoundedParticle.H"
#include "vectorFieldIOField.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
// defineParticleTypeNameAndDebug(wallBoundedParticle, 0);
}
const std::size_t Foam::wallBoundedParticle::sizeofFields_
(
sizeof(wallBoundedParticle) - sizeof(particle)
);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
//// Check position is inside tet
//void Foam::wallBoundedParticle::checkInside() const
//{
// const tetIndices ti(currentTetIndices());
// const tetPointRef tpr(ti.tet(mesh_));
// if (!tpr.inside(position()))
// {
// FatalErrorIn("wallBoundedParticle::checkInside(..)")
// << "Particle:" //<< static_cast<const particle&>(*this)
// << info()
// << "is not inside " << tpr
// << abort(FatalError);
// }
//}
//
//
//void Foam::wallBoundedParticle::checkOnEdge() const
//{
// // Check that edge (as indicated by meshEdgeStart_, diagEdge_) is
// // indeed one that contains the position.
// const edge e = currentEdge();
//
// linePointRef ln(e.line(mesh_.points()));
//
// pointHit ph(ln.nearestDist(position()));
//
// if (ph.distance() > 1e-6)
// {
// FatalErrorIn
// (
// "wallBoundedParticle::checkOnEdge()"
// ) << "Problem :"
// << " particle:" //<< static_cast<const particle&>(*this)
// << info()
// << "edge:" << e
// << " at:" << ln
// << " distance:" << ph.distance()
// << abort(FatalError);
// }
//}
//
//
//void Foam::wallBoundedParticle::checkOnTriangle(const point& p)
//const
//{
// const triFace tri(currentTetIndices().faceTriIs(mesh_));
// pointHit ph = tri.nearestPoint(p, mesh_.points());
// if (ph.distance() > 1e-9)
// {
// FatalErrorIn
// (
// "wallBoundedParticle::checkOnTriangle(const point&)"
// ) << "Problem :"
// << " particle:" //<< static_cast<const particle&>(*this)
// << info()
// << "point:" << p
// << " distance:" << ph.distance()
// << abort(FatalError);
// }
//}
// Construct the edge the particle is on (according to meshEdgeStart_,
// diagEdge_)
Foam::edge Foam::wallBoundedParticle::currentEdge() const
{
if ((meshEdgeStart_ != -1) == (diagEdge_ != -1))
{
FatalErrorIn("wallBoundedParticle::currentEdge() const")
<< "Particle:" //<< static_cast<const particle&>(*this)
<< "Particle:"
<< info()
<< "cannot both be on a mesh edge and a face-diagonal edge."
<< " meshEdgeStart_:" << meshEdgeStart_
@ -123,6 +58,7 @@ Foam::edge Foam::wallBoundedParticle::currentEdge() const
{
label faceBasePtI = mesh_.tetBasePtIs()[tetFace()];
label diagPtI = (faceBasePtI+diagEdge_)%f.size();
return edge(f[faceBasePtI], f[diagPtI]);
}
}
@ -133,15 +69,12 @@ void Foam::wallBoundedParticle::crossEdgeConnectedFace
const edge& meshEdge
)
{
//label oldFaceI = tetFace();
// Update tetFace, tetPt
particle::crossEdgeConnectedFace(cell(), tetFace(), tetPt(), meshEdge);
// Update face to be same as tracking one
face() = tetFace();
// And adapt meshEdgeStart_.
const Foam::face& f = mesh_.faces()[tetFace()];
label fp = findIndex(f, meshEdge[0]);
@ -165,7 +98,7 @@ void Foam::wallBoundedParticle::crossEdgeConnectedFace
"wallBoundedParticle::crossEdgeConnectedFace"
"(const edge&)"
) << "Problem :"
<< " particle:" //<< static_cast<const particle&>(*this)
<< " particle:"
<< info()
<< "face:" << tetFace()
<< " verts:" << f
@ -176,14 +109,7 @@ void Foam::wallBoundedParticle::crossEdgeConnectedFace
diagEdge_ = -1;
//Pout<< " crossed meshEdge "
// << meshEdge.line(mesh().points())
// << " from face:" << oldFaceI
// << " to face:" << tetFace() << endl;
// Check that still on same mesh edge
const edge eNew(f[meshEdgeStart_], f.nextLabel(meshEdgeStart_));
if (eNew != meshEdge)
{
@ -193,11 +119,6 @@ void Foam::wallBoundedParticle::crossEdgeConnectedFace
"(const edge&)"
) << "Problem" << abort(FatalError);
}
// Check that edge (as indicated by meshEdgeStart_) is indeed one that
// contains the position.
//checkOnEdge();
}
@ -206,20 +127,18 @@ void Foam::wallBoundedParticle::crossDiagonalEdge()
if (diagEdge_ == -1)
{
FatalErrorIn("wallBoundedParticle::crossDiagonalEdge()")
<< "Particle:" //<< static_cast<const particle&>(*this)
<< "Particle:"
<< info()
<< "not on a diagonal edge" << abort(FatalError);
}
if (meshEdgeStart_ != -1)
{
FatalErrorIn("wallBoundedParticle::crossDiagonalEdge()")
<< "Particle:" //<< static_cast<const particle&>(*this)
<< "Particle:"
<< info()
<< "meshEdgeStart_:" << meshEdgeStart_ << abort(FatalError);
}
//label oldTetPt = tetPt();
const Foam::face& f = mesh_.faces()[tetFace()];
// tetPtI starts from 1, goes up to f.size()-2
@ -238,7 +157,7 @@ void Foam::wallBoundedParticle::crossDiagonalEdge()
else
{
FatalErrorIn("wallBoundedParticle::crossDiagonalEdge()")
<< "Particle:" //<< static_cast<const particle&>(*this)
<< "Particle:"
<< info()
<< "tetPt:" << tetPt()
<< " diagEdge:" << diagEdge_ << abort(FatalError);
@ -246,17 +165,9 @@ void Foam::wallBoundedParticle::crossDiagonalEdge()
}
meshEdgeStart_ = -1;
//Pout<< " crossed diagonalEdge "
// << currentEdge().line(mesh().points())
// << " from tetPt:" << oldTetPt
// << " to tetPt:" << tetPt() << endl;
}
//- Track through a single triangle.
// Gets passed tet+triangle the particle is in. Updates position() but nothing
// else. Returns the triangle edge the particle is now on.
Foam::scalar Foam::wallBoundedParticle::trackFaceTri
(
const vector& endPosition,
@ -266,14 +177,6 @@ Foam::scalar Foam::wallBoundedParticle::trackFaceTri
// Track p from position to endPosition
const triFace tri(currentTetIndices().faceTriIs(mesh_));
vector n = tri.normal(mesh_.points());
//if (mag(n) < sqr(SMALL))
//{
// FatalErrorIn("wallBoundedParticle::trackFaceTri(..)")
// << "Small triangle." //<< static_cast<const particle&>(*this)
// << info()
// << "n:" << n
// << abort(FatalError);
//}
n /= mag(n)+VSMALL;
// Check which edge intersects the trajectory.
@ -281,9 +184,6 @@ Foam::scalar Foam::wallBoundedParticle::trackFaceTri
minEdgeI = -1;
scalar minS = 1; // end position
//const point oldPosition(position());
edge currentE(-1, -1);
if (meshEdgeStart_ != -1 || diagEdge_ != -1)
{
@ -309,21 +209,6 @@ Foam::scalar Foam::wallBoundedParticle::trackFaceTri
// Outwards pointing normal
vector edgeNormal = (pt1-pt0)^n;
//if (mag(edgeNormal) < SMALL)
//{
// FatalErrorIn("wallBoundedParticle::trackFaceTri(..)")
// << "Edge not perpendicular to triangle."
// //<< static_cast<const particle&>(*this)
// << info()
// << "triangle n:" << n
// << " edgeNormal:" << edgeNormal
// << " on tri:" << tri
// << " at:" << pt0
// << " at:" << pt1
// << abort(FatalError);
//}
edgeNormal /= mag(edgeNormal)+VSMALL;
// Determine whether position and end point on either side of edge.
@ -362,25 +247,10 @@ Foam::scalar Foam::wallBoundedParticle::trackFaceTri
const point& triPt = mesh_.points()[tri[0]];
position() -= ((position()-triPt)&n)*n;
//Pout<< " tracked from:" << oldPosition << " to:" << position()
// << " projectedEnd:" << endPosition
// << " at s:" << minS << endl;
//if (minEdgeI != -1)
//{
// Pout<< " on edge:" << minEdgeI
// << " on edge:"
// << mesh_.points()[tri[minEdgeI]]
// << mesh_.points()[tri[tri.fcIndex(minEdgeI)]]
// << endl;
//}
return minS;
}
// See if the current triangle has got a point on the
// correct side of the edge.
bool Foam::wallBoundedParticle::isTriAlongTrack
(
const point& endPosition
@ -454,18 +324,7 @@ Foam::wallBoundedParticle::wallBoundedParticle
particle(mesh, position, cellI, tetFaceI, tetPtI),
meshEdgeStart_(meshEdgeStart),
diagEdge_(diagEdge)
{
//checkInside();
//if (meshEdgeStart_ != -1 || diagEdge_ != -1)
//{
// checkOnEdge();
//}
// Unfortunately have no access to trackdata so cannot check if particle
// is on a wallPatch or has an mesh edge set (either of which is
// a requirement).
}
{}
Foam::wallBoundedParticle::wallBoundedParticle
@ -514,46 +373,6 @@ Foam::wallBoundedParticle::wallBoundedParticle
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::wallBoundedParticle::write(Ostream& os, bool writeFields) const
{
const particle& p = static_cast<const particle&>(*this);
if (os.format() == IOstream::ASCII)
{
// Write base particle
p.write(os, writeFields);
if (writeFields)
{
// Write the additional entries
os << token::SPACE << meshEdgeStart_
<< token::SPACE << diagEdge_;
}
}
else
{
// Write base particle
p.write(os, writeFields);
// Write additional entries
if (writeFields)
{
os.write
(
reinterpret_cast<const char*>(&meshEdgeStart_),
sizeof(meshEdgeStart_)
+ sizeof(diagEdge_)
);
}
}
// Check state of Ostream
os.check("wallBoundedParticle::write(Ostream& os, bool) const");
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<
@ -562,8 +381,21 @@ Foam::Ostream& Foam::operator<<
const wallBoundedParticle& p
)
{
// Write all data
p.write(os, true);
if (os.format() == IOstream::ASCII)
{
os << static_cast<const particle&>(p)
<< token::SPACE << p.meshEdgeStart_
<< token::SPACE << p.diagEdge_;
}
else
{
os << static_cast<const particle&>(p);
os.write
(
reinterpret_cast<const char*>(&p.meshEdgeStart_),
wallBoundedParticle::sizeofFields_
);
}
return os;
}
@ -602,5 +434,4 @@ Foam::Ostream& Foam::operator<<
}
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -54,6 +54,11 @@ class wallBoundedParticle
:
public particle
{
// Private data
//- Size in bytes of the fields
static const std::size_t sizeofFields_;
public:
@ -317,9 +322,6 @@ public:
template<class CloudType>
static void writeFields(const CloudType&);
//- Write the particle data
void write(Ostream& os, bool writeFields) const;
// Ostream Operator