Commit 1083147a authored by Andrew Heather's avatar Andrew Heather
Browse files

added proc-local id and orig proc id to particle base class

parent 5309f35f
......@@ -22,12 +22,77 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "IOPosition.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class ParticleType>
Foam::word Foam::IOPosition<ParticleType>::particlePropertiesName
(
"particleProperties"
);
// * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * * //
template<class ParticleType>
void Foam::IOPosition<ParticleType>::readParticleProperties()
{
IOobject propsDictHeader
(
particlePropertiesName,
cloud_.db().time().timeName(),
"uniform"/cloud::prefix/cloud_.name(),
cloud_.db(),
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
);
if (propsDictHeader.headerOk())
{
const IOdictionary propsDict(propsDictHeader);
word procName("processor" + Foam::name(Pstream::myProcNo()));
if (propsDict.found(procName))
{
propsDict.subDict(procName).lookup("particleCount")
>> Particle<ParticleType>::particleCount;
}
}
}
template<class ParticleType>
void Foam::IOPosition<ParticleType>::writeParticleProperties() const
{
IOdictionary propsDict
(
IOobject
(
particlePropertiesName,
cloud_.db().time().timeName(),
"uniform"/cloud::prefix/cloud_.name(),
cloud_.db(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
)
);
word procName("processor" + Foam::name(Pstream::myProcNo()));
propsDict.add(procName, dictionary());
propsDict.subDict(procName).add
(
"particleCount",
Particle<ParticleType>::particleCount
);
propsDict.regIOobject::write();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ParticleType>
......@@ -70,6 +135,8 @@ bool Foam::IOPosition<ParticleType>::write() const
template<class ParticleType>
bool Foam::IOPosition<ParticleType>::writeData(Ostream& os) const
{
writeParticleProperties();
os<< cloud_.size() << nl << token::BEGIN_LIST << nl;
forAllConstIter(typename Cloud<ParticleType>, cloud_, iter)
......@@ -90,6 +157,8 @@ void Foam::IOPosition<ParticleType>::readData
bool checkClass
)
{
readParticleProperties();
Istream& is = readStream(checkClass ? typeName : "");
token firstToken(is);
......
......@@ -59,30 +59,38 @@ class IOPosition
const Cloud<ParticleType>& cloud_;
// Private member functions
//- Read particle properties dictionary
void readParticleProperties();
//- Write particle properties dictionary
void writeParticleProperties() const;
public:
//- Runtime type name information
virtual const word& type() const
{
return cloud_.type();
}
// Static data
//- Runtime type name information
virtual const word& type() const
{
return cloud_.type();
}
//- Name of particle properties dictionary
static word particlePropertiesName;
// Constructors
//- Construct from cloud
IOPosition
(
const Cloud<ParticleType>&
);
IOPosition(const Cloud<ParticleType>&);
// Member functions
void readData
(
Cloud<ParticleType>& c,
bool checkClass
);
void readData(Cloud<ParticleType>& c, bool checkClass);
bool write() const;
......
......@@ -33,6 +33,12 @@ License
#include "wallPolyPatch.H"
#include "transform.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class ParticleType>
Foam::label Foam::Particle<ParticleType>::particleCount = 0;
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class ParticleType>
......@@ -69,7 +75,7 @@ void Foam::Particle<ParticleType>::findFaces
DynamicList<label>& faceList
) const
{
const polyMesh& mesh = cloud_.polyMesh_;
const polyMesh& mesh = cloud_.mesh();
const labelList& faces = mesh.cells()[celli];
const vector& C = mesh.cellCentres()[celli];
......@@ -176,7 +182,9 @@ Foam::Particle<ParticleType>::Particle
position_(position),
celli_(celli),
facei_(-1),
stepFraction_(0.0)
stepFraction_(0.0),
origProc_(Pstream::myProcNo()),
origId_(particleCount++)
{}
......@@ -187,7 +195,9 @@ Foam::Particle<ParticleType>::Particle(const Particle<ParticleType>& p)
position_(p.position_),
celli_(p.celli_),
facei_(p.facei_),
stepFraction_(p.stepFraction_)
stepFraction_(p.stepFraction_),
origProc_(p.origProc_),
origId_(p.origId_)
{}
......
......@@ -127,6 +127,12 @@ protected:
//- Fraction of time-step completed
scalar stepFraction_;
//- Originating processor id
label origProc_;
//- Local particle id on originating processor
label origId_;
// Private member functions
......@@ -267,11 +273,14 @@ public:
// Static data members
//- Runtime type information
TypeName("Particle");
//- String representation of properties
static string propHeader;
//- Runtime type information
TypeName("Particle");
//- Cumulative particle count used for particle id
static label particleCount;
// Constructors
......@@ -396,6 +405,12 @@ public:
//- Return the fraction of time-step completed
inline scalar stepFraction() const;
//- Return the originating processor id
inline label origProc() const;
//- Return the particle id on originating processor
inline label origId() const;
// Track
......
......@@ -26,15 +26,10 @@ License
#include "polyMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class ParticleType>
inline scalar Particle<ParticleType>::lambda
inline Foam::scalar Foam::Particle<ParticleType>::lambda
(
const vector& from,
const vector& to,
......@@ -182,7 +177,7 @@ inline scalar Particle<ParticleType>::lambda
template<class ParticleType>
inline scalar Particle<ParticleType>::lambda
inline Foam::scalar Foam::Particle<ParticleType>::lambda
(
const vector& from,
const vector& to,
......@@ -234,7 +229,7 @@ inline scalar Particle<ParticleType>::lambda
template<class ParticleType>
inline bool Particle<ParticleType>::inCell() const
inline bool Foam::Particle<ParticleType>::inCell() const
{
DynamicList<label>& faces = cloud_.labels_;
findFaces(position_, faces);
......@@ -244,7 +239,7 @@ inline bool Particle<ParticleType>::inCell() const
template<class ParticleType>
inline bool Particle<ParticleType>::inCell
inline bool Foam::Particle<ParticleType>::inCell
(
const vector& position,
const label celli,
......@@ -261,7 +256,7 @@ inline bool Particle<ParticleType>::inCell
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ParticleType>
inline Particle<ParticleType>::trackData::trackData
inline Foam::Particle<ParticleType>::trackData::trackData
(
Cloud<ParticleType>& cloud
)
......@@ -269,8 +264,10 @@ inline Particle<ParticleType>::trackData::trackData
cloud_(cloud)
{}
template<class ParticleType>
inline Cloud<ParticleType>& Particle<ParticleType>::trackData::cloud()
inline Foam::Cloud<ParticleType>&
Foam::Particle<ParticleType>::trackData::cloud()
{
return cloud_;
}
......@@ -279,76 +276,92 @@ inline Cloud<ParticleType>& Particle<ParticleType>::trackData::cloud()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ParticleType>
inline const Cloud<ParticleType>& Particle<ParticleType>::cloud() const
inline const Foam::Cloud<ParticleType>&
Foam::Particle<ParticleType>::cloud() const
{
return cloud_;
}
template<class ParticleType>
inline const vector& Particle<ParticleType>::position() const
inline const Foam::vector& Foam::Particle<ParticleType>::position() const
{
return position_;
}
template<class ParticleType>
inline vector& Particle<ParticleType>::position()
inline Foam::vector& Foam::Particle<ParticleType>::position()
{
return position_;
}
template<class ParticleType>
inline label Particle<ParticleType>::cell() const
inline Foam::label Foam::Particle<ParticleType>::cell() const
{
return celli_;
}
template<class ParticleType>
inline label& Particle<ParticleType>::cell()
inline Foam::label& Foam::Particle<ParticleType>::cell()
{
return celli_;
}
template<class ParticleType>
inline label Particle<ParticleType>::face() const
inline Foam::label Foam::Particle<ParticleType>::face() const
{
return facei_;
}
template<class ParticleType>
inline bool Particle<ParticleType>::onBoundary() const
inline bool Foam::Particle<ParticleType>::onBoundary() const
{
return facei_ != -1 && facei_ >= cloud_.pMesh().nInternalFaces();
}
template<class ParticleType>
inline scalar& Particle<ParticleType>::stepFraction()
inline Foam::scalar& Foam::Particle<ParticleType>::stepFraction()
{
return stepFraction_;
}
template<class ParticleType>
inline scalar Particle<ParticleType>::stepFraction() const
inline Foam::scalar Foam::Particle<ParticleType>::stepFraction() const
{
return stepFraction_;
}
template<class ParticleType>
inline bool Particle<ParticleType>::softImpact() const
inline Foam::label Foam::Particle<ParticleType>::origProc() const
{
return origProc_;
}
template<class ParticleType>
inline Foam::label Foam::Particle<ParticleType>::origId() const
{
return origId_;
}
template<class ParticleType>
inline bool Foam::Particle<ParticleType>::softImpact() const
{
return false;
}
template<class ParticleType>
inline scalar Particle<ParticleType>::currentTime() const
inline Foam::scalar Foam::Particle<ParticleType>::currentTime() const
{
return
cloud_.pMesh().time().value()
......@@ -357,14 +370,14 @@ inline scalar Particle<ParticleType>::currentTime() const
template<class ParticleType>
inline label Particle<ParticleType>::patch(const label facei) const
inline Foam::label Foam::Particle<ParticleType>::patch(const label facei) const
{
return cloud_.facePatch(facei);
}
template<class ParticleType>
inline label Particle<ParticleType>::patchFace
inline Foam::label Foam::Particle<ParticleType>::patchFace
(
const label patchi,
const label facei
......@@ -375,21 +388,18 @@ inline label Particle<ParticleType>::patchFace
template<class ParticleType>
inline scalar Particle<ParticleType>::wallImpactDistance(const vector&) const
inline Foam::scalar
Foam::Particle<ParticleType>::wallImpactDistance(const vector&) const
{
return 0.0;
}
template<class ParticleType>
inline label Particle<ParticleType>::faceInterpolation() const
inline Foam::label Foam::Particle<ParticleType>::faceInterpolation() const
{
return facei_;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //
......@@ -31,12 +31,11 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class ParticleType>
Foam::string Foam::Particle<ParticleType>::propHeader = "(Px Py Pz) cellI";
Foam::string Foam::Particle<ParticleType>::propHeader =
"(Px Py Pz) cellI origProc origId";
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from Istream
template<class ParticleType>
Foam::Particle<ParticleType>::Particle
(
......@@ -47,20 +46,26 @@ Foam::Particle<ParticleType>::Particle
:
cloud_(cloud),
facei_(-1),
stepFraction_(0.0)
stepFraction_(0.0),
origProc_(Pstream::myProcNo()),
origId_(-1)
{
if (is.format() == IOstream::ASCII)
{
is >> position_ >> celli_;
is >> position_ >> celli_ >> origProc_ >> origId_;
}
else
{
// In binary read both celli_ and facei_, needed for parallel transfer
// In binary read all particle data - needed for parallel transfer
is.read
(
reinterpret_cast<char*>(&position_),
sizeof(position_) + sizeof(celli_)
+ sizeof(facei_) + sizeof(stepFraction_)
sizeof(position_)
+ sizeof(celli_)
+ sizeof(facei_)
+ sizeof(stepFraction_)
+ sizeof(origProc_)
+ sizeof(origId_)
);
}
......@@ -92,7 +97,9 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const Particle<ParticleType>& p)
if (os.format() == IOstream::ASCII)
{
os << p.position_
<< token::SPACE << p.celli_;
<< token::SPACE << p.celli_
<< token::SPACE << p.origProc_
<< token::SPACE << p.origId_;
}
else
{
......@@ -100,8 +107,12 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const Particle<ParticleType>& p)
os.write
(
reinterpret_cast<const char*>(&p.position_),
sizeof(p.position_) + sizeof(p.celli_)
+ sizeof(p.facei_) + sizeof(p.stepFraction_)
sizeof(p.position_)
+ sizeof(p.celli_)
+ sizeof(p.facei_)
+ sizeof(p.stepFraction_)
+ sizeof(p.origProc_)
+ sizeof(p.origId_)
);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment