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

ENH: Lagrangian - added functions to add particle data as fields on an object registry

parent 271c8c8c
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -36,7 +36,6 @@ namespace Foam
word cloud::defaultName("defaultCloud");
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::cloud::cloud(const objectRegistry& obr, const word& cloudName)
......@@ -70,4 +69,10 @@ void Foam::cloud::autoMap(const mapPolyMesh&)
}
void Foam::cloud::writeObjects(objectRegistry& obr) const
{
NotImplemented;
}
// ************************************************************************* //
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -36,6 +36,7 @@ SourceFiles
#define cloud_H
#include "objectRegistry.H"
#include "IOField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -92,6 +93,24 @@ public:
//- Remap the cells of particles corresponding to the
// mesh topology change
virtual void autoMap(const mapPolyMesh&);
// I-O
//- Read particle fields from objects in the obr registry
//virtual void readObjects(objectRegistry& obr);
//- Write particle fields as objects into the obr registry
virtual void writeObjects(objectRegistry& obr) const;
//- Helper to construct IOField on a supplied object registry
template<class Type>
static IOField<Type>& createIOField
(
const word& fieldName,
const label nParticle,
objectRegistry& obr
);
};
......@@ -101,6 +120,12 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
#include "cloudTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
......@@ -574,6 +574,10 @@ public:
template<class CloudType>
static void writeFields(const CloudType& c);
//- Write particle fields as objects into the obr registry
template<class CloudType>
static void writeObjects(const CloudType& c, objectRegistry& obr);
//- Write the particle position and cell
void writePosition(Ostream&) const;
......
......@@ -162,7 +162,7 @@ void Foam::particle::writeFields(const CloudType& c)
IOPosition<CloudType> ioP(c);
ioP.write();
label np = c.size();
label np = c.size();
IOField<label> origProc
(
......@@ -184,6 +184,29 @@ void Foam::particle::writeFields(const CloudType& c)
}
template<class CloudType>
void Foam::particle::writeObjects(const CloudType& c, objectRegistry& obr)
{
label np = c.size();
IOField<vector>& position
(
cloud::createIOField<vector>("position", np, obr)
);
IOField<label>& origProc(cloud::createIOField<label>("origProc", np, obr));
IOField<label>& origId(cloud::createIOField<label>("origId", np, obr));
label i = 0;
forAllConstIter(typename CloudType, c, iter)
{
position[i] = iter().position_;
origProc[i] = iter().origProc_;
origId[i] = iter().origId_;
i++;
}
}
template<class TrackData>
Foam::label Foam::particle::track(const vector& endPosition, TrackData& td)
{
......
......@@ -895,4 +895,11 @@ void Foam::KinematicCloud<CloudType>::info()
}
template<class CloudType>
void Foam::KinematicCloud<CloudType>::writeObjects(objectRegistry& obr) const
{
parcelType::writeObjects(*this, obr);
}
// ************************************************************************* //
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -612,6 +612,9 @@ public:
//- Print cloud information
void info();
//- Write particle fields as objects into the obr registry
virtual void writeObjects(objectRegistry& obr) const;
};
......
......@@ -362,4 +362,11 @@ void Foam::ReactingCloud<CloudType>::writeFields() const
}
template<class CloudType>
void Foam::ReactingCloud<CloudType>::writeObjects(objectRegistry& obr) const
{
CloudType::particleType::writeObjects(*this, this->composition(), obr);
}
// ************************************************************************* //
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -313,6 +313,9 @@ public:
//- Write the field data for the cloud
virtual void writeFields() const;
//- Write particle fields as objects into the obr registry
virtual void writeObjects(objectRegistry& obr) const;
};
......
......@@ -63,11 +63,15 @@ public:
//- Runtime type information
TypeName("kinematicCloud");
// Constructors
//- Null constructor
kinematicCloud();
//- Destructor
virtual ~kinematicCloud();
// Member functions
......@@ -92,26 +96,22 @@ public:
virtual scalar Dmax() const = 0;
// Fields
// Fields
//- Volume swept rate of parcels per cell
virtual const tmp<volScalarField> vDotSweep() const = 0;
//- Volume swept rate of parcels per cell
virtual const tmp<volScalarField> vDotSweep() const = 0;
//- Return the particle volume fraction field
// Note: for particles belonging to this cloud only
virtual const tmp<volScalarField> theta() const = 0;
//- Return the particle volume fraction field
// Note: for particles belonging to this cloud only
virtual const tmp<volScalarField> theta() const = 0;
//- Return the particle mass fraction field
// Note: for particles belonging to this cloud only
virtual const tmp<volScalarField> alpha() const = 0;
//- Return the particle mass fraction field
// Note: for particles belonging to this cloud only
virtual const tmp<volScalarField> alpha() const = 0;
//- Return the particle effective density field
// Note: for particles belonging to this cloud only
virtual const tmp<volScalarField> rhoEff() const = 0;
//- Destructor
virtual ~kinematicCloud();
//- Return the particle effective density field
// Note: for particles belonging to this cloud only
virtual const tmp<volScalarField> rhoEff() const = 0;
};
......
......@@ -307,6 +307,10 @@ public:
template<class CloudType>
static void writeFields(const CloudType& c);
//- Write particle fields as objects into the obr registry
template<class CloudType>
static void writeObjects(const CloudType& c, objectRegistry& obr);
// Ostream Operator
......
......@@ -274,6 +274,39 @@ void Foam::CollidingParcel<ParcelType>::writeFields(const CloudType& c)
}
template<class ParcelType>
template<class CloudType>
void Foam::CollidingParcel<ParcelType>::writeObjects
(
const CloudType& c,
objectRegistry& obr
)
{
ParcelType::writeObjects(c, obr);
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));
label i = 0;
forAllConstIter(typename CloudType, c, iter)
{
const CollidingParcel<ParcelType>& p = iter();
f[i] = p.f();
angularMomentum[i] = p.angularMomentum();
torque[i] = p.torque();
i++;
}
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class ParcelType>
......
......@@ -660,6 +660,10 @@ public:
template<class CloudType>
static void writeFields(const CloudType& c);
//- Write particle fields as objects into the obr registry
template<class CloudType>
static void writeObjects(const CloudType& c, objectRegistry& obr);
// Ostream Operator
......
......@@ -171,7 +171,7 @@ void Foam::KinematicParcel<ParcelType>::writeFields(const CloudType& c)
{
ParcelType::writeFields(c);
label np = c.size();
label np = c.size();
IOField<label> active(c.fieldIOobject("active", IOobject::NO_READ), np);
IOField<label> typeId(c.fieldIOobject("typeId", IOobject::NO_READ), np);
......@@ -221,6 +221,55 @@ void Foam::KinematicParcel<ParcelType>::writeFields(const CloudType& c)
}
template<class ParcelType>
template<class CloudType>
void Foam::KinematicParcel<ParcelType>::writeObjects
(
const CloudType& c,
objectRegistry& obr
)
{
DebugInFunction << endl;
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));
label i = 0;
forAllConstIter(typename CloudType, c, iter)
{
const KinematicParcel<ParcelType>& p = iter();
active[i] = p.active();
typeId[i] = p.typeId();
nParticle[i] = p.nParticle();
d[i] = p.d();
dTarget[i] = p.dTarget();
U[i] = p.U();
rho[i] = p.rho();
age[i] = p.age();
tTurb[i] = p.tTurb();
UTurb[i] = p.UTurb();
i++;
}
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class ParcelType>
......
......@@ -297,6 +297,10 @@ public:
template<class CloudType>
static void writeFields(const CloudType& c);
//- Write particle fields as objects into the obr registry
template<class CloudType>
static void writeObjects(const CloudType& c, objectRegistry& obr);
// Ostream operator
......
......@@ -110,7 +110,7 @@ void Foam::MPPICParcel<ParcelType>::writeFields(const CloudType& c)
{
ParcelType::writeFields(c);
label np = c.size();
label np = c.size();
IOField<vector>
UCorrect(c.fieldIOobject("UCorrect", IOobject::NO_READ), np);
......@@ -130,6 +130,34 @@ void Foam::MPPICParcel<ParcelType>::writeFields(const CloudType& c)
}
template<class ParcelType>
template<class CloudType>
void Foam::MPPICParcel<ParcelType>::writeObjects
(
const CloudType& c,
objectRegistry& obr
)
{
ParcelType::writeObjects(c, obr);
label np = c.size();
IOField<vector>&
UCorrect(cloud::createIOField<vector>("UCorrect", np, obr));
label i = 0;
forAllConstIter(typename CloudType, c, iter)
{
const MPPICParcel<ParcelType>& p = iter();
UCorrect[i] = p.UCorrect();
i++;
}
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class ParcelType>
......
......@@ -433,7 +433,7 @@ public:
// I-O
//- Read
//- Read - composition supplied
template<class CloudType, class CompositionType>
static void readFields
(
......@@ -445,7 +445,7 @@ public:
template<class CloudType>
static void readFields(CloudType& c);
//- Write
//- Write - composition supplied
template<class CloudType, class CompositionType>
static void writeFields
(
......@@ -453,10 +453,28 @@ public:
const CompositionType& compModel
);
//- Read - composition supplied
//- Read - no composition
template<class CloudType>
static void writeFields(const CloudType& c);
//- Write particle fields as objects into the obr registry
// - no composition
template<class CloudType>
static void writeObjects
(
const CloudType& c,
objectRegistry& obr
);
//- Write particle fields as objects into the obr registry
template<class CloudType, class CompositionType>
static void writeObjects
(
const CloudType& c,
const CompositionType& compModel,
objectRegistry& obr
);
// Ostream Operator
......
......@@ -327,6 +327,108 @@ void Foam::ReactingMultiphaseParcel<ParcelType>::writeFields
}
template<class ParcelType>
template<class CloudType>
void Foam::ReactingMultiphaseParcel<ParcelType>::writeObjects
(
const CloudType& c,
objectRegistry& obr
)
{
ParcelType::writeObjects(c, obr);
}
template<class ParcelType>
template<class CloudType, class CompositionType>
void Foam::ReactingMultiphaseParcel<ParcelType>::writeObjects
(
const CloudType& c,
const CompositionType& compModel,
objectRegistry& obr
)
{
ParcelType::writeObjects(c, obr);
label np = c.size();
// Write the composition fractions
if (np > 0)
{
const wordList& stateLabels = compModel.stateLabels();
const label idGas = compModel.idGas();
const wordList& gasNames = compModel.componentNames(idGas);
forAll(gasNames, j)
{
const word fieldName = "Y" + gasNames[j] + stateLabels[idGas];
IOField<scalar>& YGas
(
cloud::createIOField<scalar>(fieldName, np, obr)
);
label i = 0;
forAllConstIter
(
typename Cloud<ReactingMultiphaseParcel<ParcelType>>,
c,
iter
)
{
const ReactingMultiphaseParcel<ParcelType>& p0 = iter();
YGas[i++] = p0.YGas()[j]*p0.Y()[GAS];
}
}
const label idLiquid = compModel.idLiquid();
const wordList& liquidNames = compModel.componentNames(idLiquid);
forAll(liquidNames, j)
{
const word fieldName = "Y" + liquidNames[j] + stateLabels[idLiquid];
IOField<scalar>& YLiquid
(
cloud::createIOField<scalar>(fieldName, np, obr)
);
label i = 0;
forAllConstIter
(
typename Cloud<ReactingMultiphaseParcel<ParcelType>>,
c,
iter
)
{
const ReactingMultiphaseParcel<ParcelType>& p0 = iter();
YLiquid[i++] = p0.YLiquid()[j]*p0.Y()[LIQ];
}
}
const label idSolid = compModel.idSolid();
const wordList& solidNames = compModel.componentNames(idSolid);
forAll(solidNames, j)
{
const word fieldName = "Y" + solidNames[j] + stateLabels[idSolid];
IOField<scalar>& YSolid
(
cloud::createIOField<scalar>(fieldName, np, obr)
);
label i = 0;
forAllConstIter
(
typename Cloud<ReactingMultiphaseParcel<ParcelType>>,
c,
iter
)
{