Commit cf07fdc9 authored by Henry's avatar Henry
Browse files

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
parent 5daf22d9
......@@ -41,7 +41,6 @@ SourceFiles
#include "IOstream.H"
#include "autoPtr.H"
#include "contiguous.H"
#include "DSMCCloud.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -70,6 +69,12 @@ class DSMCParcel
:
public ParcelType
{
// Private member data
//- Size in bytes of the fields
static const std::size_t sizeofFields_;
public:
//- Class to hold DSMC particle constant properties
......@@ -92,7 +97,7 @@ public:
public:
// Constrcutors
// Constructors
//- Null constructor, allows List of constantProperties to be
// created before the contents is initialised
......@@ -104,10 +109,10 @@ public:
// Member functions
//- Return const access to the particle density
//- Return const access to the particle mass [kg]
inline scalar mass() const;
//- Return const access to the minimum particle mass
//- Return const access to the hard sphere diameter [m]
inline scalar d() const;
//- Return the reference total collision cross section
......@@ -152,7 +157,7 @@ protected:
vector U_;
//- Internal energy of the Parcel, covering all non-translational
// degrees of freedom [J]
// degrees of freedom [J]
scalar Ei_;
//- Parcel type id
......@@ -196,7 +201,6 @@ public:
return autoPtr<particle>(new DSMCParcel<ParcelType>(*this));
}
//- Factory class to read-construct particles used for
// parallel transfer
class iNew
......@@ -233,6 +237,7 @@ public:
//- Return const access to internal energy
inline scalar Ei() const;
// Edit
//- Return access to velocity
......
......@@ -28,6 +28,15 @@ License
#include "IOField.H"
#include "Cloud.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class ParcelType>
const std::size_t Foam::DSMCParcel<ParcelType>::sizeofFields_
(
sizeof(DSMCParcel<ParcelType>) - sizeof(ParcelType)
);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ParcelType>
......@@ -53,13 +62,7 @@ Foam::DSMCParcel<ParcelType>::DSMCParcel
}
else
{
is.read
(
reinterpret_cast<char*>(&U_),
sizeof(U_)
+ sizeof(Ei_)
+ sizeof(typeId_)
);
is.read(reinterpret_cast<char*>(&U_), sizeofFields_);
}
}
......@@ -157,9 +160,7 @@ Foam::Ostream& Foam::operator<<
os.write
(
reinterpret_cast<const char*>(&p.U_),
sizeof(p.U())
+ sizeof(p.Ei())
+ sizeof(p.typeId())
DSMCParcel<ParcelType>::sizeofFields_
);
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -68,11 +68,7 @@ bool Foam::IOPosition<CloudType>::writeData(Ostream& os) const
forAllConstIter(typename CloudType, cloud_, iter)
{
const typename CloudType::particleType& p = iter();
// Prevent writing additional fields
p.write(os, false);
iter().writePosition(os);
os << nl;
}
......@@ -100,7 +96,7 @@ void Foam::IOPosition<CloudType>::readData(CloudType& c, bool checkClass)
for (label i=0; i<s; i++)
{
// Do not read any fields, position only
// Read position only
c.append(new typename CloudType::particleType(mesh, is, false));
}
......@@ -129,7 +125,8 @@ void Foam::IOPosition<CloudType>::readData(CloudType& c, bool checkClass)
)
{
is.putBack(lastToken);
// Do not read any fields, position only
// Write position only
c.append(new typename CloudType::particleType(mesh, is, false));
is >> lastToken;
}
......
......@@ -80,6 +80,15 @@ class particle
:
public IDLList<particle>::link
{
// Private member data
//- Size in bytes of the position data
static const std::size_t sizeofPosition_;
//- Size in bytes of the fields
static const std::size_t sizeofFields_;
public:
template<class CloudType>
......@@ -358,7 +367,6 @@ public:
return autoPtr<particle>(new particle(*this));
}
//- Factory class to read-construct particles used for
// parallel transfer
class iNew
......@@ -556,8 +564,8 @@ public:
template<class CloudType>
static void writeFields(const CloudType& c);
//- Write the particle data
void write(Ostream& os, bool writeFields) const;
//- Write the particle position and cell
void writePosition(Ostream&) const;
// Friend Operators
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -25,12 +25,21 @@ License
#include "particle.H"
#include "IOstreams.H"
#include "IOPosition.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
Foam::string Foam::particle::propertyList_ = Foam::particle::propertyList();
const std::size_t Foam::particle::sizeofPosition_
(
offsetof(particle, faceI_) - offsetof(particle, position_)
);
const std::size_t Foam::particle::sizeofFields_
(
sizeof(particle) - offsetof(particle, position_)
);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
......@@ -46,45 +55,29 @@ Foam::particle::particle(const polyMesh& mesh, Istream& is, bool readFields)
origProc_(Pstream::myProcNo()),
origId_(-1)
{
// readFields : read additional data. Should be consistent with writeFields.
if (is.format() == IOstream::ASCII)
{
is >> position_ >> cellI_;
if (readFields)
{
is >> tetFaceI_ >> tetPtI_ >> origProc_ >> origId_;
is >> faceI_
>> stepFraction_
>> tetFaceI_
>> tetPtI_
>> origProc_
>> origId_;
}
}
else
{
// In binary read all particle data - needed for parallel transfer
if (readFields)
{
is.read
(
reinterpret_cast<char*>(&position_),
sizeof(position_)
+ sizeof(cellI_)
+ sizeof(faceI_)
+ sizeof(stepFraction_)
+ sizeof(tetFaceI_)
+ sizeof(tetPtI_)
+ sizeof(origProc_)
+ sizeof(origId_)
);
is.read(reinterpret_cast<char*>(&position_), sizeofFields_);
}
else
{
is.read
(
reinterpret_cast<char*>(&position_),
sizeof(position_)
+ sizeof(cellI_)
+ sizeof(faceI_)
+ sizeof(stepFraction_)
);
is.read(reinterpret_cast<char*>(&position_), sizeofPosition_);
}
}
......@@ -93,66 +86,43 @@ Foam::particle::particle(const polyMesh& mesh, Istream& is, bool readFields)
}
void Foam::particle::write(Ostream& os, bool writeFields) const
void Foam::particle::writePosition(Ostream& os) const
{
if (os.format() == IOstream::ASCII)
{
if (writeFields)
{
// Write the additional entries
os << position_
<< token::SPACE << cellI_
<< token::SPACE << tetFaceI_
<< token::SPACE << tetPtI_
<< token::SPACE << origProc_
<< token::SPACE << origId_;
}
else
{
os << position_
<< token::SPACE << cellI_;
}
os << position_ << token::SPACE << cellI_;
}
else
{
// In binary write both cellI_ and faceI_, needed for parallel transfer
if (writeFields)
{
os.write
(
reinterpret_cast<const char*>(&position_),
sizeof(position_)
+ sizeof(cellI_)
+ sizeof(faceI_)
+ sizeof(stepFraction_)
+ sizeof(tetFaceI_)
+ sizeof(tetPtI_)
+ sizeof(origProc_)
+ sizeof(origId_)
);
}
else
{
os.write
(
reinterpret_cast<const char*>(&position_),
sizeof(position_)
+ sizeof(cellI_)
+ sizeof(faceI_)
+ sizeof(stepFraction_)
);
}
os.write(reinterpret_cast<const char*>(&position_), sizeofPosition_);
}
// Check state of Ostream
os.check("particle::write(Ostream& os, bool) const");
os.check("particle::writePosition(Ostream& os, bool) const");
}
Foam::Ostream& Foam::operator<<(Ostream& os, const particle& p)
{
// Write all data
p.write(os, true);
if (os.format() == IOstream::ASCII)
{
os << p.position_
<< token::SPACE << p.cellI_
<< token::SPACE << p.faceI_
<< token::SPACE << p.stepFraction_
<< token::SPACE << p.tetFaceI_
<< token::SPACE << p.tetPtI_
<< token::SPACE << p.origProc_
<< token::SPACE << p.origId_;
}
else
{
os.write
(
reinterpret_cast<const char*>(&p.position_),
particle::sizeofFields_
);
}
return os;
}
......
......@@ -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
......@@ -38,12 +38,10 @@ SourceFiles
#define CollidingParcel_H
#include "particle.H"
#include "CollisionRecordList.H"
#include "labelFieldIOField.H"
#include "vectorFieldIOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
......@@ -74,6 +72,12 @@ class CollidingParcel
:
public ParcelType
{
// Private member data
//- Size in bytes of the fields
static const std::size_t sizeofFields_;
public:
//- Class to hold thermo particle constant properties
......
......@@ -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
......@@ -33,6 +33,13 @@ template<class ParcelType>
Foam::string Foam::CollidingParcel<ParcelType>::propertyList_ =
Foam::CollidingParcel<ParcelType>::propertyList();
template<class ParcelType>
const std::size_t Foam::CollidingParcel<ParcelType>::sizeofFields_
(
offsetof(CollidingParcel<ParcelType>, collisionRecords_)
- offsetof(CollidingParcel<ParcelType>, f_)
);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
......@@ -60,13 +67,7 @@ Foam::CollidingParcel<ParcelType>::CollidingParcel
}
else
{
is.read
(
reinterpret_cast<char*>(&f_),
+ sizeof(f_)
+ sizeof(angularMomentum_)
+ sizeof(torque_)
);
is.read(reinterpret_cast<char*>(&f_), sizeofFields_);
}
is >> collisionRecords_;
......@@ -285,10 +286,10 @@ Foam::Ostream& Foam::operator<<
if (os.format() == IOstream::ASCII)
{
os << static_cast<const ParcelType&>(p)
<< token::SPACE << p.f()
<< token::SPACE << p.angularMomentum()
<< token::SPACE << p.torque()
<< token::SPACE << p.collisionRecords();
<< token::SPACE << p.f_
<< token::SPACE << p.angularMomentum_
<< token::SPACE << p.torque_
<< token::SPACE << p.collisionRecords_;
}
else
{
......@@ -296,9 +297,7 @@ Foam::Ostream& Foam::operator<<
os.write
(
reinterpret_cast<const char*>(&p.f_),
+ sizeof(p.f())
+ sizeof(p.angularMomentum())
+ sizeof(p.torque())
CollidingParcel<ParcelType>::sizeofFields_
);
os << p.collisionRecords();
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -78,6 +78,15 @@ class KinematicParcel
:
public ParcelType
{
// Private data
//- Size in bytes of the fields
static const std::size_t sizeofFields_;
//- Number of particle tracking attempts before we assume that it stalls
static label maxTrackAttempts;
public:
//- Class to hold kinematic particle constant properties
......@@ -137,7 +146,7 @@ public:
//- Return const access to the particle density
inline scalar rho0() const;
//- Return const access to the minimum particle mass
//- Return const access to the minimum parcel mass
inline scalar minParcelMass() const;
};
......@@ -218,10 +227,6 @@ public:
};
//- Number of particle tracking attempts before we assume that it stalls
static label maxTrackAttempts;
protected:
// Protected data
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -34,6 +34,14 @@ template<class ParcelType>
Foam::string Foam::KinematicParcel<ParcelType>::propertyList_ =
Foam::KinematicParcel<ParcelType>::propertyList();
template<class ParcelType>
const std::size_t Foam::KinematicParcel<ParcelType>::sizeofFields_
(
offsetof(KinematicParcel<ParcelType>, rhoc_)
- offsetof(KinematicParcel<ParcelType>, active_)
);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ParcelType>
......@@ -76,8 +84,7 @@ Foam::KinematicParcel<ParcelType>::KinematicParcel
}
else
{
label size = long(&UTurb_) - long(&active_) + sizeof(UTurb_);
is.read(reinterpret_cast<char*>(&active_), size);
is.read(reinterpret_cast<char*>(&active_), sizeofFields_);
}
}
......@@ -236,9 +243,11 @@ Foam::Ostream& Foam::operator<<
else
{
os << static_cast<const ParcelType&>(p);
label size = long(&p.UTurb_) - long(&p.active_) + sizeof(p.UTurb_);
os.write(reinterpret_cast<const char*>(&p.active_), size);
os.write
(
reinterpret_cast<const char*>(&p.active_),
KinematicParcel<ParcelType>::sizeofFields_
);
}
// Check state of Ostream
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -73,6 +73,12 @@ class MPPICParcel
:
public ParcelType
{
// Private data
//- Size in bytes of the fields
static const std::size_t sizeofFields_;
public:
template<class CloudType>
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2013-2015 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -33,6 +33,12 @@ template<class ParcelType>
Foam::string Foam::MPPICParcel<ParcelType>::propertyList_ =
Foam::MPPICParcel<ParcelType>::propertyList();
template<class ParcelType>
const std::size_t Foam::MPPICParcel<ParcelType>::sizeofFields_
(
sizeof(MPPICParcel<ParcelType>) - sizeof(ParcelType)
);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
......@@ -55,11 +61,7 @@ Foam::MPPICParcel<ParcelType>::MPPICParcel
}
else
{
is.read
(
reinterpret_cast<char*>(&UCorrect_),
+ sizeof(UCorrect_)
);
is.read(reinterpret_cast<char*>(&UCorrect_), sizeofFields_);
}
}
......@@ -144,7 +146,7 @@ Foam::Ostream& Foam::operator<<
os.write
(
reinterpret_cast<const char*>(&p.UCorrect_),
+ sizeof(p.UCorrect())
MPPICParcel<ParcelType>::sizeofFields_
);