Commit ffbb0710 authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

ENH: add cloud::readObjects(const objectRegistry&)

- this can be use for situations where the cloud data has been
  provided by a non-file transport.
parent 1d8ea918
......@@ -86,6 +86,12 @@ void Foam::cloud::autoMap(const mapPolyMesh&)
}
void Foam::cloud::readObjects(const objectRegistry& obr)
{
NotImplemented;
}
void Foam::cloud::writeObjects(objectRegistry& obr) const
{
NotImplemented;
......
......@@ -121,7 +121,7 @@ public:
// I-O
//- Read particle fields from objects in the obr registry
//virtual void readObjects(objectRegistry& obr);
virtual void readObjects(const objectRegistry& obr);
//- Write particle fields as objects into the obr registry
virtual void writeObjects(objectRegistry& obr) const;
......
......@@ -220,6 +220,13 @@ public:
//- Write fields
static void writeFields(const Cloud<injectedParticle>& c);
//- Read particle fields as objects from the obr registry
static void readObjects
(
Cloud<injectedParticle>& c,
const objectRegistry& obr
);
//- Write particle fields as objects into the obr registry
static void writeObjects
(
......
......@@ -68,6 +68,12 @@ Foam::injectedParticleCloud::~injectedParticleCloud()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::injectedParticleCloud::readObjects(const objectRegistry& obr)
{
injectedParticle::readObjects(*this, obr);
}
void Foam::injectedParticleCloud::writeObjects(objectRegistry& obr) const
{
injectedParticle::writeObjects(*this, obr);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -98,6 +98,9 @@ public:
// I-O
//- Read particle fields as objects from the obr registry
virtual void readObjects(const objectRegistry& obr);
//- Write particle fields as objects into the obr registry
virtual void writeObjects(objectRegistry& obr) const;
};
......
......@@ -158,6 +158,35 @@ void Foam::injectedParticle::writeFields(const Cloud<injectedParticle>& c)
}
void Foam::injectedParticle::readObjects
(
Cloud<injectedParticle>& c,
const objectRegistry& obr
)
{
particle::readObjects(c, obr);
if (!c.size()) return;
const auto& tag = cloud::lookupIOField<label>("tag", obr);
const auto& soi = cloud::lookupIOField<scalar>("soi", obr);
const auto& d = cloud::lookupIOField<scalar>("d", obr);
const auto& U = cloud::lookupIOField<vector>("U", obr);
label i = 0;
for (injectedParticle& p : c)
{
p.tag() = tag[i];
p.soi() = soi[i];
p.d() = d[i];
p.U() = U[i];
++i;
}
}
void Foam::injectedParticle::writeObjects
(
const Cloud<injectedParticle>& c,
......@@ -167,12 +196,12 @@ void Foam::injectedParticle::writeObjects
// Always writes "position", not "coordinates"
particle::writeObjects(c, obr);
label np = c.size();
const label np = c.size();
IOField<label>& tag(cloud::createIOField<label>("tag", np, obr));
IOField<scalar>& soi(cloud::createIOField<scalar>("soi", np, obr));
IOField<scalar>& d(cloud::createIOField<scalar>("d", np, obr));
IOField<vector>& U(cloud::createIOField<vector>("U", np, obr));
auto& tag = cloud::createIOField<label>("tag", np, obr);
auto& soi = cloud::createIOField<scalar>("soi", np, obr);
auto& d = cloud::createIOField<scalar>("d", np, obr);
auto& U = cloud::createIOField<vector>("U", np, obr);
label i = 0;
......
......@@ -673,6 +673,10 @@ public:
template<class TrackCloudType>
static void writeFields(const TrackCloudType& c);
//- Read particle fields as objects from the obr registry
template<class CloudType>
static void readObjects(CloudType& c, const objectRegistry& obr);
//- Write particle fields as objects into the obr registry
// Always writes "position", not "coordinate"
template<class CloudType>
......
......@@ -46,7 +46,7 @@ void Foam::particle::readFields(TrackCloudType& c)
IOobject procIO(c.fieldIOobject("origProcId", IOobject::MUST_READ));
bool haveFile = procIO.typeHeaderOk<IOField<label>>(true);
const bool haveFile = procIO.typeHeaderOk<IOField<label>>(true);
IOField<label> origProcId(procIO, valid && haveFile);
c.checkFieldIOobject(c, origProcId);
......@@ -63,6 +63,7 @@ void Foam::particle::readFields(TrackCloudType& c)
{
p.origProc_ = origProcId[i];
p.origId_ = origId[i];
++i;
}
}
......@@ -72,11 +73,12 @@ template<class TrackCloudType>
void Foam::particle::writeFields(const TrackCloudType& c)
{
const label np = c.size();
const bool valid = np;
if (writeLagrangianCoordinates)
{
IOPosition<TrackCloudType> ioP(c);
ioP.write(np > 0);
ioP.write(valid);
}
else if (!writeLagrangianPositions)
{
......@@ -93,7 +95,7 @@ void Foam::particle::writeFields(const TrackCloudType& c)
c,
cloud::geometryType::POSITIONS
);
ioP.write(np > 0);
ioP.write(valid);
}
IOField<label> origProc
......@@ -116,8 +118,57 @@ void Foam::particle::writeFields(const TrackCloudType& c)
++i;
}
origProc.write(np > 0);
origId.write(np > 0);
origProc.write(valid);
origId.write(valid);
}
template<class CloudType>
void Foam::particle::readObjects(CloudType& c, const objectRegistry& obr)
{
typedef typename CloudType::parcelType parcelType;
const auto* positionPtr = cloud::findIOPosition(obr);
const label np = c.size();
const label newNp = (positionPtr ? positionPtr->size() : 0);
// Remove excess parcels
for (label i = newNp; i < np; ++i)
{
parcelType* p = c.last();
c.deleteParticle(*p);
}
if (newNp)
{
const auto& position = *positionPtr;
const auto& origProcId = cloud::lookupIOField<label>("origProc", obr);
const auto& origId = cloud::lookupIOField<label>("origId", obr);
// Create new parcels
for (label i = np; i < newNp; ++i)
{
c.addParticle(new parcelType(c.pMesh(), position[i], -1));
}
label i = 0;
for (particle& p : c)
{
p.origProc_ = origProcId[i];
p.origId_ = origId[i];
if (i < np)
{
// Use relocate for old particles, not new ones
p.relocate(position[i]);
}
++i;
}
}
}
......@@ -126,9 +177,9 @@ void Foam::particle::writeObjects(const CloudType& c, objectRegistry& obr)
{
const label np = c.size();
IOField<label>& origProc(cloud::createIOField<label>("origProc", np, obr));
IOField<label>& origId(cloud::createIOField<label>("origId", np, obr));
IOField<point>& position(cloud::createIOField<point>("position", np, obr));
auto& origProc = cloud::createIOField<label>("origProc", np, obr);
auto& origId = cloud::createIOField<label>("origId", np, obr);
auto& position = cloud::createIOField<point>("position", np, obr);
label i = 0;
for (const particle& p : c)
......
......@@ -793,6 +793,13 @@ void Foam::KinematicCloud<CloudType>::info()
}
template<class CloudType>
void Foam::KinematicCloud<CloudType>::readObjects(const objectRegistry& obr)
{
parcelType::readObjects(*this, obr);
}
template<class CloudType>
void Foam::KinematicCloud<CloudType>::writeObjects(objectRegistry& obr) const
{
......
......@@ -628,6 +628,9 @@ public:
//- Print cloud information
void info();
//- Read particle fields from objects in the obr registry
virtual void readObjects(const objectRegistry& obr);
//- Write particle fields as objects into the obr registry
virtual void writeObjects(objectRegistry& obr) const;
};
......
......@@ -237,6 +237,14 @@ void Foam::ReactingHeterogeneousCloud<CloudType>::writeFields() const
}
template<class CloudType>
void Foam::ReactingHeterogeneousCloud<CloudType>::
readObjects(const objectRegistry& obr)
{
CloudType::particleType::readObjects(*this, this->composition(), obr);
}
template<class CloudType>
void Foam::ReactingHeterogeneousCloud<CloudType>::
writeObjects(objectRegistry& obr) const
......
......@@ -243,6 +243,9 @@ public:
//- Print cloud information
void info();
//- Read particle fields as objects from the obr registry
virtual void readObjects(const objectRegistry& obr);
//- Write the field data for the cloud
virtual void writeFields() const;
......
......@@ -322,6 +322,10 @@ public:
template<class CloudType>
static void writeFields(const CloudType& c);
//- Read particle fields as objects from the obr registry
template<class CloudType>
static void readObjects(CloudType& c, const objectRegistry& obr);
//- Write particle fields as objects into the obr registry
template<class CloudType>
static void writeObjects(const CloudType& c, objectRegistry& obr);
......
......@@ -84,7 +84,7 @@ template<class ParcelType>
template<class CloudType>
void Foam::CollidingParcel<ParcelType>::readFields(CloudType& c)
{
bool valid = c.size();
const bool valid = c.size();
ParcelType::readFields(c);
......@@ -192,10 +192,12 @@ void Foam::CollidingParcel<ParcelType>::writeFields(const CloudType& c)
{
ParcelType::writeFields(c);
label np = c.size();
const label np = c.size();
const bool valid = np;
IOField<vector> f(c.fieldIOobject("f", IOobject::NO_READ), np);
IOField<vector> angularMomentum
IOField<vector> angMom
(
c.fieldIOobject("angularMomentum", IOobject::NO_READ),
np
......@@ -246,7 +248,7 @@ void Foam::CollidingParcel<ParcelType>::writeFields(const CloudType& c)
for (const CollidingParcel<ParcelType>& p : c)
{
f[i] = p.f();
angularMomentum[i] = p.angularMomentum();
angMom[i] = p.angularMomentum();
torque[i] = p.torque();
collisionRecordsPairAccessed[i] = p.collisionRecords().pairAccessed();
......@@ -262,10 +264,8 @@ void Foam::CollidingParcel<ParcelType>::writeFields(const CloudType& c)
++i;
}
const bool valid = (np > 0);
f.write(valid);
angularMomentum.write(valid);
angMom.write(valid);
torque.write(valid);
collisionRecordsPairAccessed.write(valid);
......@@ -278,6 +278,34 @@ void Foam::CollidingParcel<ParcelType>::writeFields(const CloudType& c)
}
template<class ParcelType>
template<class CloudType>
void Foam::CollidingParcel<ParcelType>::readObjects
(
CloudType& c,
const objectRegistry& obr
)
{
ParcelType::readObjects(c, obr);
if (!c.size()) return;
const auto& f = cloud::lookupIOField<vector>("f", obr);
const auto& angMom = cloud::lookupIOField<vector>("angularMomentum", obr);
const auto& torque = cloud::lookupIOField<vector>("torque", obr);
label i = 0;
for (CollidingParcel<ParcelType>& p : c)
{
p.f_ = f[i];
p.angularMomentum_ = angMom[i];
p.torque_ = torque[i];
++i;
}
}
template<class ParcelType>
template<class CloudType>
void Foam::CollidingParcel<ParcelType>::writeObjects
......@@ -288,20 +316,17 @@ void Foam::CollidingParcel<ParcelType>::writeObjects
{
ParcelType::writeObjects(c, obr);
label np = c.size();
const label np = c.size();
IOField<vector>& f(cloud::createIOField<vector>("f", np, obr));
IOField<vector>& angularMomentum
(
cloud::createIOField<vector>("angularMomentum", np, obr)
);
IOField<vector>& torque(cloud::createIOField<vector>("torque", np, obr));
auto& f = cloud::createIOField<vector>("f", np, obr);
auto& angMom = cloud::createIOField<vector>("angularMomentum", np, obr);
auto& torque = cloud::createIOField<vector>("torque", np, obr);
label i = 0;
for (const CollidingParcel<ParcelType>& p : c)
{
f[i] = p.f();
angularMomentum[i] = p.angularMomentum();
angMom[i] = p.angularMomentum();
torque[i] = p.torque();
++i;
......
......@@ -658,6 +658,10 @@ public:
template<class TrackCloudType>
static void writeFields(const TrackCloudType& c);
//- Read particle fields as objects from the obr registry
template<class CloudType>
static void readObjects(CloudType& c, const objectRegistry& obr);
//- Write particle fields as objects into the obr registry
template<class CloudType>
static void writeObjects(const CloudType& c, objectRegistry& obr);
......
......@@ -97,7 +97,7 @@ template<class ParcelType>
template<class CloudType>
void Foam::KinematicParcel<ParcelType>::readFields(CloudType& c)
{
bool valid = c.size();
const bool valid = c.size();
ParcelType::readFields(c);
......@@ -197,7 +197,8 @@ void Foam::KinematicParcel<ParcelType>::writeFields(const CloudType& c)
{
ParcelType::writeFields(c);
label np = c.size();
const label np = c.size();
const bool valid = np;
IOField<label> active(c.fieldIOobject("active", IOobject::NO_READ), np);
IOField<label> typeId(c.fieldIOobject("typeId", IOobject::NO_READ), np);
......@@ -232,8 +233,6 @@ void Foam::KinematicParcel<ParcelType>::writeFields(const CloudType& c)
++i;
}
const bool valid = np > 0;
active.write(valid);
typeId.write(valid);
nParticle.write(valid);
......@@ -247,6 +246,49 @@ void Foam::KinematicParcel<ParcelType>::writeFields(const CloudType& c)
}
template<class ParcelType>
template<class CloudType>
void Foam::KinematicParcel<ParcelType>::readObjects
(
CloudType& c,
const objectRegistry& obr
)
{
ParcelType::readObjects(c, obr);
if (!c.size()) return;
const auto& active = cloud::lookupIOField<label>("active", obr);
const auto& typeId = cloud::lookupIOField<label>("typeId", obr);
const auto& nParticle = cloud::lookupIOField<scalar>("nParticle", obr);
const auto& d = cloud::lookupIOField<scalar>("d", obr);
const auto& dTarget = cloud::lookupIOField<scalar>("dTarget", obr);
const auto& U = cloud::lookupIOField<vector>("U", obr);
const auto& rho = cloud::lookupIOField<scalar>("rho", obr);
const auto& age = cloud::lookupIOField<scalar>("age", obr);
const auto& tTurb = cloud::lookupIOField<scalar>("tTurb", obr);
const auto& UTurb = cloud::lookupIOField<vector>("UTurb", obr);
label i = 0;
for (KinematicParcel<ParcelType>& p : c)
{
p.active_ = active[i];
p.typeId_ = typeId[i];
p.nParticle_ = nParticle[i];
p.d_ = d[i];
p.dTarget_ = dTarget[i];
p.U_ = U[i];
p.rho_ = rho[i];
p.age_ = age[i];
p.tTurb_ = tTurb[i];
p.UTurb_ = UTurb[i];
++i;
}
}
template<class ParcelType>
template<class CloudType>
void Foam::KinematicParcel<ParcelType>::writeObjects
......@@ -257,21 +299,18 @@ void Foam::KinematicParcel<ParcelType>::writeObjects
{
ParcelType::writeObjects(c, obr);
label np = c.size();
IOField<label>& active(cloud::createIOField<label>("active", np, obr));
IOField<label>& typeId(cloud::createIOField<label>("typeId", np, obr));
IOField<scalar>& nParticle
(
cloud::createIOField<scalar>("nParticle", np, obr)
);
IOField<scalar>& d(cloud::createIOField<scalar>("d", np, obr));
IOField<scalar>& dTarget(cloud::createIOField<scalar>("dTarget", np, obr));
IOField<vector>& U(cloud::createIOField<vector>("U", np, obr));
IOField<scalar>& rho(cloud::createIOField<scalar>("rho", np, obr));
IOField<scalar>& age(cloud::createIOField<scalar>("age", np, obr));
IOField<scalar>& tTurb(cloud::createIOField<scalar>("tTurb", np, obr));
IOField<vector>& UTurb(cloud::createIOField<vector>("UTurb", np, obr));
const label np = c.size();
auto& active = cloud::createIOField<label>("active", np, obr);
auto& typeId = cloud::createIOField<label>("typeId", np, obr);
auto& nParticle = cloud::createIOField<scalar>("nParticle", np, obr);
auto& d = cloud::createIOField<scalar>("d", np, obr);
auto& dTarget = cloud::createIOField<scalar>("dTarget", np, obr);
auto& U = cloud::createIOField<vector>("U", np, obr);
auto& rho = cloud::createIOField<scalar>("rho", np, obr);
auto& age = cloud::createIOField<scalar>("age", np, obr);
auto& tTurb = cloud::createIOField<scalar>("tTurb", np, obr);
auto&& UTurb = cloud::createIOField<vector>("UTurb", np, obr);
label i = 0;
......
......@@ -307,6 +307,10 @@ public:
template<class CloudType>
static void writeFields(const CloudType& c);
//- Read particle fields as objects from the obr registry
template<class CloudType>
static void readObjects(CloudType& c, const objectRegistry& obr);
//- Write particle fields as objects into the obr registry
template<class CloudType>
static void writeObjects(const CloudType& c, objectRegistry& obr);
......
......@@ -104,7 +104,7 @@ void Foam::MPPICParcel<ParcelType>::writeFields(const CloudType& c)
{
ParcelType::writeFields(c);
label np = c.size();
const label np = c.size();
IOField<vector>
UCorrect(c.fieldIOobject("UCorrect", IOobject::NO_READ), np);
......@@ -122,6 +122,30 @@ void Foam::MPPICParcel<ParcelType>::writeFields(const CloudType& c)
}
template<class ParcelType>
template<class CloudType>
void Foam::MPPICParcel<ParcelType>::readObjects
(