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

This commit is contained in:
Andrew Heather
2016-11-30 17:18:48 +00:00
parent 271c8c8c6e
commit 99a1eee024
24 changed files with 617 additions and 30 deletions

View File

@ -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;
}
// ************************************************************************* //

View File

@ -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
// ************************************************************************* //

View File

@ -0,0 +1,60 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "Time.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class Type>
Foam::IOField<Type>& Foam::cloud::createIOField
(
const word& fieldName,
const label nParticle,
objectRegistry& obr
)
{
IOField<Type>* fieldPtr
(
new IOField<Type>
(
IOobject
(
fieldName,
obr.time().timeName(),
obr,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
nParticle
)
);
fieldPtr->store();
return *fieldPtr;
}
// ************************************************************************* //

View File

@ -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;

View File

@ -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)
{

View File

@ -895,4 +895,11 @@ void Foam::KinematicCloud<CloudType>::info()
}
template<class CloudType>
void Foam::KinematicCloud<CloudType>::writeObjects(objectRegistry& obr) const
{
parcelType::writeObjects(*this, obr);
}
// ************************************************************************* //

View File

@ -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;
};

View File

@ -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);
}
// ************************************************************************* //

View File

@ -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;
};

View File

@ -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;
};

View File

@ -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

View File

@ -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>

View File

@ -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

View File

@ -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>

View File

@ -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

View File

@ -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>

View File

@ -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

View File

@ -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
)
{
const ReactingMultiphaseParcel<ParcelType>& p0 = iter();
YSolid[i++] = p0.YSolid()[j]*p0.Y()[SLD];
}
}
}
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class ParcelType>

View File

@ -391,7 +391,7 @@ public:
// I-O
//- Read
//- Read - composition supplied
template<class CloudType, class CompositionType>
static void readFields
(
@ -403,7 +403,7 @@ public:
template<class CloudType>
static void readFields(CloudType& c);
//- Write
//- Write - composition supplied
template<class CloudType, class CompositionType>
static void writeFields
(
@ -411,11 +411,29 @@ public:
const CompositionType& compModel
);
//- Write - composition supplied
//- Write - 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
friend Ostream& operator<< <ParcelType>

View File

@ -234,6 +234,76 @@ void Foam::ReactingParcel<ParcelType>::writeFields
}
template<class ParcelType>
template<class CloudType>
void Foam::ReactingParcel<ParcelType>::writeObjects
(
const CloudType& c,
objectRegistry& obr
)
{
ParcelType::writeObjects(c, obr);
}
template<class ParcelType>
template<class CloudType, class CompositionType>
void Foam::ReactingParcel<ParcelType>::writeObjects
(
const CloudType& c,
const CompositionType& compModel,
objectRegistry& obr
)
{
DebugInFunction << endl;
ParcelType::writeObjects(c, obr);
label np = c.size();
if (np > 0)
{
IOField<scalar>& mass0(cloud::createIOField<scalar>("mass0", np, obr));
label i = 0;
forAllConstIter(typename Cloud<ReactingParcel<ParcelType>>, c, iter)
{
const ReactingParcel<ParcelType>& p = iter();
mass0[i++] = p.mass0_;
}
// Write the composition fractions
const wordList& phaseTypes = compModel.phaseTypes();
wordList stateLabels(phaseTypes.size(), "");
if (compModel.nPhase() == 1)
{
stateLabels = compModel.stateLabels()[0];
}
forAll(phaseTypes, j)
{
const word fieldName = "Y" + phaseTypes[j] + stateLabels[j];
IOField<scalar>& Y
(
cloud::createIOField<scalar>(fieldName, np, obr)
);
label i = 0;
forAllConstIter
(
typename Cloud<ReactingParcel<ParcelType>>,
c,
iter
)
{
const ReactingParcel<ParcelType>& p = iter();
Y[i++] = p.Y()[j];
}
}
}
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class ParcelType>

View File

@ -450,6 +450,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

View File

@ -137,6 +137,34 @@ void Foam::ThermoParcel<ParcelType>::writeFields(const CloudType& c)
}
template<class ParcelType>
template<class CloudType>
void Foam::ThermoParcel<ParcelType>::writeObjects
(
const CloudType& c,
objectRegistry& obr
)
{
DebugInFunction << endl;
ParcelType::writeObjects(c, obr);
label np = c.size();
IOField<scalar>& T(cloud::createIOField<scalar>("T", np, obr));
IOField<scalar>& Cp(cloud::createIOField<scalar>("Cp", np, obr));
label i = 0;
forAllConstIter(typename Cloud<ThermoParcel<ParcelType>>, c, iter)
{
const ThermoParcel<ParcelType>& p = iter();
T[i] = p.T_;
Cp[i] = p.Cp_;
i++;
}
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class ParcelType>

View File

@ -506,6 +506,24 @@ public:
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

View File

@ -283,6 +283,76 @@ void Foam::SprayParcel<ParcelType>::writeFields
}
template<class ParcelType>
template<class CloudType>
void Foam::SprayParcel<ParcelType>::writeObjects
(
const CloudType& c,
objectRegistry& obr
)
{
ParcelType::writeObjects(c, obr);
}
template<class ParcelType>
template<class CloudType, class CompositionType>
void Foam::SprayParcel<ParcelType>::writeObjects
(
const CloudType& c,
const CompositionType& compModel,
objectRegistry& obr
)
{
ParcelType::writeObjects(c, compModel, obr);
label np = c.size();
IOField<scalar>& d0(cloud::createIOField<scalar>("d0", np, obr));
IOField<vector>& position0
(
cloud::createIOField<vector>("position0", np, obr)
);
IOField<scalar>& sigma(cloud::createIOField<scalar>("sigma", np, obr));
IOField<scalar>& mu(cloud::createIOField<scalar>("mu", np, obr));
IOField<scalar>& liquidCore
(
cloud::createIOField<scalar>("liquidCore", np, obr)
);
IOField<scalar>& KHindex(cloud::createIOField<scalar>("KHindex", np, obr));
IOField<scalar>& y(cloud::createIOField<scalar>("y", np, obr));
IOField<scalar>& yDot(cloud::createIOField<scalar>("yDot", np, obr));
IOField<scalar>& tc(cloud::createIOField<scalar>("tc", np, obr));
IOField<scalar>& ms(cloud::createIOField<scalar>("ms", np, obr));
IOField<scalar>& injector
(
cloud::createIOField<scalar>("injector", np, obr)
);
IOField<scalar>& tMom(cloud::createIOField<scalar>("tMom", np, obr));
IOField<scalar>& user(cloud::createIOField<scalar>("user", np, obr));
label i = 0;
forAllConstIter(typename Cloud<SprayParcel<ParcelType>>, c, iter)
{
const SprayParcel<ParcelType>& p = iter();
d0[i] = p.d0_;
position0[i] = p.position0_;
sigma[i] = p.sigma_;
mu[i] = p.mu_;
liquidCore[i] = p.liquidCore_;
KHindex[i] = p.KHindex_;
y[i] = p.y_;
yDot[i] = p.yDot_;
tc[i] = p.tc_;
ms[i] = p.ms_;
injector[i] = p.injector_;
tMom[i] = p.tMom_;
user[i] = p.user_;
i++;
}
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class ParcelType>