Commit 77752b9e authored by Andrew Heather's avatar Andrew Heather
Browse files

Added copy/clone functionality to templated clouds

parent c1678f89
......@@ -28,10 +28,10 @@ License
#include "interpolation.H"
#include "subCycleTime.H"
#include "CollisionModel.H"
#include "DispersionModel.H"
#include "DragModel.H"
#include "InjectionModel.H"
#include "CollisionModel.H"
#include "PatchInteractionModel.H"
#include "PostProcessingModel.H"
#include "SurfaceFilmModel.H"
......@@ -42,6 +42,7 @@ template<class ParcelType>
void Foam::KinematicCloud<ParcelType>::cloudSolution::read()
{
dict_.lookup("coupled") >> coupled_;
dict_.lookup("cellValueSourceCorrection") >> cellValueSourceCorrection_;
}
......@@ -55,7 +56,8 @@ Foam::KinematicCloud<ParcelType>::cloudSolution::cloudSolution
mesh_(mesh),
dict_(dict),
active_(dict.lookup("active")),
coupled_(false)
coupled_(false),
cellValueSourceCorrection_(false)
{
if (active_)
{
......@@ -73,7 +75,8 @@ Foam::KinematicCloud<ParcelType>::cloudSolution::cloudSolution
mesh_(cs.mesh_),
dict_(cs.dict_),
active_(cs.active_),
coupled_(cs.coupled_)
coupled_(cs.coupled_),
cellValueSourceCorrection_(cs.cellValueSourceCorrection_)
{}
......@@ -86,7 +89,8 @@ Foam::KinematicCloud<ParcelType>::cloudSolution::cloudSolution
mesh_(mesh),
dict_(dictionary::null),
active_(false),
coupled_(false)
coupled_(false),
cellValueSourceCorrection_(false)
{}
......@@ -95,6 +99,29 @@ Foam::KinematicCloud<ParcelType>::cloudSolution::~cloudSolution()
{}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class ParcelType>
void Foam::KinematicCloud<ParcelType>::storeState()
{
cloudCopyPtr_.reset
(
static_cast<KinematicCloud<ParcelType>*>
(
clone(this->name() + "Copy").ptr()
)
);
}
template<class ParcelType>
void Foam::KinematicCloud<ParcelType>::restoreState()
{
cloudReset(cloudCopyPtr_());
cloudCopyPtr_.clear();
}
// * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
template<class ParcelType>
......@@ -259,6 +286,24 @@ void Foam::KinematicCloud<ParcelType>::postEvolve()
}
template<class ParcelType>
void Foam::KinematicCloud<ParcelType>::cloudReset(KinematicCloud<ParcelType>& c)
{
Cloud<ParcelType>::cloudReset(c);
rndGen_ = c.rndGen_;
collisionModel_ = c.collisionModel_->clone();
dispersionModel_= c.dispersionModel_->clone();
dragModel_ = c.dragModel_->clone();
injectionModel_ = c.injectionModel_->clone();
patchInteractionModel_ = c.patchInteractionModel_->clone();
postProcessingModel_ = c.postProcessingModel_->clone();
UIntegrator_ = c.UIntegrator_->clone();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ParcelType>
......@@ -274,6 +319,7 @@ Foam::KinematicCloud<ParcelType>::KinematicCloud
:
Cloud<ParcelType>(rho.mesh(), cloudName, false),
kinematicCloud(),
cloudCopyPtr_(NULL),
mesh_(rho.mesh()),
particleProperties_
(
......@@ -289,10 +335,6 @@ Foam::KinematicCloud<ParcelType>::KinematicCloud
solution_(mesh_, particleProperties_.subDict("solution")),
constProps_(particleProperties_),
subModelProperties_(particleProperties_.subDict("subModels")),
cellValueSourceCorrection_
(
particleProperties_.lookup("cellValueSourceCorrection")
),
rndGen_
(
label(0),
......@@ -304,33 +346,33 @@ Foam::KinematicCloud<ParcelType>::KinematicCloud
mu_(mu),
g_(g),
forces_(mesh_, particleProperties_, g_.value()),
dispersionModel_
collisionModel_
(
DispersionModel<KinematicCloud<ParcelType> >::New
CollisionModel<KinematicCloud<ParcelType> >::New
(
subModelProperties_,
*this
)
),
dragModel_
dispersionModel_
(
DragModel<KinematicCloud<ParcelType> >::New
DispersionModel<KinematicCloud<ParcelType> >::New
(
subModelProperties_,
*this
)
),
injectionModel_
dragModel_
(
InjectionModel<KinematicCloud<ParcelType> >::New
DragModel<KinematicCloud<ParcelType> >::New
(
subModelProperties_,
*this
)
),
collisionModel_
injectionModel_
(
CollisionModel<KinematicCloud<ParcelType> >::New
InjectionModel<KinematicCloud<ParcelType> >::New
(
subModelProperties_,
*this
......@@ -371,17 +413,20 @@ Foam::KinematicCloud<ParcelType>::KinematicCloud
),
UTrans_
(
IOobject
new DimensionedField<vector, volMesh>
(
this->name() + "UTrans",
this->db().time().timeName(),
this->db(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
mesh_,
dimensionedVector("zero", dimMass*dimVelocity, vector::zero)
IOobject
(
this->name() + "UTrans",
this->db().time().timeName(),
this->db(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
mesh_,
dimensionedVector("zero", dimMass*dimVelocity, vector::zero)
)
)
{
if (readFields)
......@@ -391,6 +436,103 @@ Foam::KinematicCloud<ParcelType>::KinematicCloud
}
template<class ParcelType>
Foam::KinematicCloud<ParcelType>::KinematicCloud
(
KinematicCloud<ParcelType>& c,
const word& name
)
:
Cloud<ParcelType>(c.mesh(), name, c),
kinematicCloud(),
cloudCopyPtr_(NULL),
mesh_(c.mesh()),
particleProperties_(c.particleProperties_),
solution_(c.solution_),
constProps_(c.constProps_),
subModelProperties_(c.subModelProperties_),
rndGen_(c.rndGen_, true),
cellOccupancyPtr_(c.cellOccupancyPtr_->clone()),
rho_(c.rho_),
U_(c.U_),
mu_(c.mu_),
g_(c.g_),
forces_(c.forces_),
collisionModel_(c.collisionModel_->clone()),
dispersionModel_(c.dispersionModel_->clone()),
dragModel_(c.dragModel_->clone()),
injectionModel_(c.injectionModel_->clone()),
patchInteractionModel_(c.patchInteractionModel_->clone()),
postProcessingModel_(c.postProcessingModel_->clone()),
surfaceFilmModel_(c.surfaceFilmModel_->clone()),
UIntegrator_(c.UIntegrator_->clone()),
UTrans_
(
new DimensionedField<vector, volMesh>
(
IOobject
(
this->name() + "UTrans",
this->db().time().timeName(),
this->db(),
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
mesh_,
c.UTrans_().dimensions(),
c.UTrans_().field()
)
)
{}
template<class ParcelType>
Foam::KinematicCloud<ParcelType>::KinematicCloud
(
const fvMesh& mesh,
const word& name,
const KinematicCloud<ParcelType>& c
)
:
Cloud<ParcelType>(mesh, name, IDLList<ParcelType>()),
kinematicCloud(),
cloudCopyPtr_(NULL),
mesh_(mesh),
particleProperties_
(
IOobject
(
name + "Properties",
mesh.time().constant(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
)
),
solution_(mesh),
constProps_(dictionary::null),
subModelProperties_(dictionary::null),
rndGen_(0, 0),
cellOccupancyPtr_(NULL),
rho_(c.rho_),
U_(c.U_),
mu_(c.mu_),
g_(c.g_),
forces_(mesh),
collisionModel_(NULL),
dispersionModel_(NULL),
dragModel_(NULL),
injectionModel_(NULL),
patchInteractionModel_(NULL),
postProcessingModel_(NULL),
surfaceFilmModel_(NULL),
UIntegrator_(NULL),
UTrans_(NULL)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class ParcelType>
......@@ -421,7 +563,7 @@ void Foam::KinematicCloud<ParcelType>::checkParcelProperties
template<class ParcelType>
void Foam::KinematicCloud<ParcelType>::resetSourceTerms()
{
UTrans_.field() = vector::zero;
UTrans_->field() = vector::zero;
}
......
......@@ -64,6 +64,9 @@ namespace Foam
// Forward declaration of classes
template<class CloudType>
class CollisionModel;
template<class CloudType>
class DispersionModel;
......@@ -73,9 +76,6 @@ class DragModel;
template<class CloudType>
class InjectionModel;
template<class CloudType>
class CollisionModel;
template<class CloudType>
class PatchInteractionModel;
......@@ -96,8 +96,20 @@ class KinematicCloud
public Cloud<ParcelType>,
public kinematicCloud
{
// Private data
//- Cloud copy pointer
autoPtr<KinematicCloud<ParcelType> > cloudCopyPtr_;
// Private Member Functions
//- Store the current cloud state
void storeState();
//- Reset the current cloud to the previously stored state
void restoreState();
//- Disallow default bitwise copy construct
KinematicCloud(const KinematicCloud&);
......@@ -201,10 +213,6 @@ protected:
//- Sub-models dictionary
const dictionary& subModelProperties_;
//- Flag to correct cell values with latest transfer information
// during the lagrangian timestep
const Switch cellValueSourceCorrection_;
//- Random number generator - used by some injection routines
cachedRandom rndGen_;
......@@ -236,6 +244,10 @@ protected:
// References to the cloud sub-models
//- Collision model
autoPtr<CollisionModel<KinematicCloud<ParcelType> > >
collisionModel_;
//- Dispersion model
autoPtr<DispersionModel<KinematicCloud<ParcelType> > >
dispersionModel_;
......@@ -247,10 +259,6 @@ protected:
autoPtr<InjectionModel<KinematicCloud<ParcelType> > >
injectionModel_;
//- Collision model
autoPtr<CollisionModel<KinematicCloud<ParcelType> > >
collisionModel_;
//- Patch interaction model
autoPtr<PatchInteractionModel<KinematicCloud<ParcelType> > >
patchInteractionModel_;
......@@ -273,7 +281,7 @@ protected:
// Sources
//- Momentum
DimensionedField<vector, volMesh> UTrans_;
autoPtr<DimensionedField<vector, volMesh> > UTrans_;
// Cloud evolution functions
......@@ -300,6 +308,9 @@ protected:
//- Post-evolve
void postEvolve();
//- Reset state of cloud
void cloudReset(KinematicCloud<ParcelType>& c);
public:
......@@ -316,6 +327,35 @@ public:
bool readFields = true
);
//- Copy constructor with new name
KinematicCloud(KinematicCloud<ParcelType>& c, const word& name);
//- Copy constructor with new name - creates bare cloud
KinematicCloud
(
const fvMesh& mesh,
const word& name,
const KinematicCloud<ParcelType>& c
);
//- Construct and return clone based on (this) with new name
virtual autoPtr<Cloud<ParcelType> > clone(const word& name)
{
return autoPtr<Cloud<ParcelType> >
(
new KinematicCloud(*this, name)
);
}
//- Construct and return bare clone based on (this) with new name
virtual autoPtr<Cloud<ParcelType> > cloneBare(const word& name) const
{
return autoPtr<Cloud<ParcelType> >
(
new KinematicCloud(this->mesh(), name, *this)
);
}
//- Destructor
virtual ~KinematicCloud();
......@@ -391,6 +431,14 @@ public:
// Sub-models
//- Return const access to the collision model
inline const CollisionModel<KinematicCloud<ParcelType> >&
collision() const;
//- Return reference to the collision model
inline CollisionModel<KinematicCloud<ParcelType> >&
collision();
//- Return const-access to the dispersion model
inline const DispersionModel<KinematicCloud<ParcelType> >&
dispersion() const;
......@@ -411,15 +459,6 @@ public:
inline InjectionModel<KinematicCloud<ParcelType> >&
injection();
//- Return const access to the collision model
inline
const CollisionModel<KinematicCloud<ParcelType> >&
collision() const;
//- Return reference to the collision model
inline CollisionModel<KinematicCloud<ParcelType> >&
collision();
//- Return const-access to the patch interaction model
inline const PatchInteractionModel<KinematicCloud<ParcelType> >&
patchInteraction() const;
......@@ -450,6 +489,10 @@ public:
//- Return reference to momentum source
inline DimensionedField<vector, volMesh>& UTrans();
//- Return const reference to momentum source
inline const DimensionedField<vector, volMesh>&
UTrans() const;
//- Return tmp momentum source term - fully explicit
inline tmp<DimensionedField<vector, volMesh> > SU() const;
......
......@@ -170,6 +170,22 @@ Foam::KinematicCloud<ParcelType>::forces() const
}
template<class ParcelType>
inline const Foam::CollisionModel<Foam::KinematicCloud<ParcelType> >&
Foam::KinematicCloud<ParcelType>::collision() const
{
return collisionModel_();
}
template<class ParcelType>
inline Foam::CollisionModel<Foam::KinematicCloud<ParcelType> >&
Foam::KinematicCloud<ParcelType>::collision()
{
return collisionModel_();
}
template<class ParcelType>
inline const Foam::DispersionModel<Foam::KinematicCloud<ParcelType> >&
Foam::KinematicCloud<ParcelType>::dispersion() const
......@@ -218,22 +234,6 @@ Foam::KinematicCloud<ParcelType>::injection()
}
template<class ParcelType>
inline const Foam::CollisionModel<Foam::KinematicCloud<ParcelType> >&
Foam::KinematicCloud<ParcelType>::collision() const
{
return collisionModel_();
}
template<class ParcelType>
inline Foam::CollisionModel<Foam::KinematicCloud<ParcelType> >&
Foam::KinematicCloud<ParcelType>::collision()
{
return collisionModel_();
}
template<class ParcelType>
inline Foam::PostProcessingModel<Foam::KinematicCloud<ParcelType> >&
Foam::KinematicCloud<ParcelType>::postProcessing()
......@@ -357,7 +357,15 @@ template<class ParcelType>
inline Foam::DimensionedField<Foam::vector, Foam::volMesh>&
Foam::KinematicCloud<ParcelType>::UTrans()
{
return UTrans_;
return UTrans_();
}
template<class ParcelType>
inline const Foam::DimensionedField<Foam::vector, Foam::volMesh>&
Foam::KinematicCloud<ParcelType>::UTrans() const
{
return UTrans_();
}
......@@ -388,7 +396,7 @@ Foam::KinematicCloud<ParcelType>::SU() const
);
vectorField& SU = tSU().field();
SU = UTrans_/(mesh_.V()*this->db().time().deltaT());
SU = UTrans()/(mesh_.V()*this->db().time().deltaT());
return tSU;
}
......
......@@ -28,6 +28,29 @@ License
#include "CompositionModel.H"
#include "PhaseChangeModel.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class ParcelType>
void Foam::ReactingCloud<ParcelType>::storeState()
{
cloudCopyPtr_.reset
(
static_cast<ReactingCloud<ParcelType>*>
(
clone(this->name() + "Copy").ptr()
)
);
}
template<class ParcelType>
void Foam::ReactingCloud<ParcelType>::restoreState()
{
cloudReset(cloudCopyPtr_());
cloudCopyPtr_.clear();
}
// * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * * //
template<class ParcelType>
......@@ -112,6 +135,18 @@ void Foam::ReactingCloud<ParcelType>::postEvolve()
}
template<class ParcelType>
void Foam::ReactingCloud<ParcelType>::cloudReset(ReactingCloud<ParcelType>& c)
{
ThermoCloud<ParcelType>::cloudReset(c);
compositionModel_ = c.compositionModel_->clone();
phaseChangeModel_ = c.phaseChangeModel_->clone();
dMassPhaseChange_ = c.dMassPhaseChange_;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ParcelType>
......@@ -127,6 +162,7 @@ Foam::ReactingCloud<ParcelType>::ReactingCloud
:
ThermoCloud<ParcelType>(cloudName, rho, U, g, thermo, false),
reactingCloud(),
cloudCopyPtr_(NULL),
constProps_(this->particleProperties()),
compositionModel_
(
......@@ -178,6 +214,52 @@ Foam::ReactingCloud<ParcelType>::ReactingCloud