Commit 660f3e54 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: cleanup autoPtr class (issue #639)

Improve alignment of its behaviour with std::unique_ptr

  - element_type typedef
  - release() method - identical to ptr() method
  - get() method to get the pointer without checking and without releasing it.
  - operator*() for dereferencing

Method name changes

  - renamed rawPtr() to get()
  - renamed rawRef() to ref(), removed unused const version.

Removed methods/operators

  - assignment from a raw pointer was deleted (was rarely used).
    Can be convenient, but uncontrolled and potentially unsafe.
    Do allow assignment from a literal nullptr though, since this
    can never leak (and also corresponds to the unique_ptr API).

Additional methods

  - clone() method: forwards to the clone() method of the underlying
    data object with argument forwarding.

  - reset(autoPtr&&) as an alternative to operator=(autoPtr&&)

STYLE: avoid implicit conversion from autoPtr to object type in many places

- existing implementation has the following:

     operator c...
parent fc92d30e
......@@ -165,7 +165,7 @@ IOdictionary PDRProperties
autoPtr<PDRDragModel> drag = PDRDragModel::New
(
PDRProperties,
turbulence,
*turbulence,
rho,
U,
phi
......@@ -176,7 +176,7 @@ autoPtr<XiModel> flameWrinkling = XiModel::New
(
PDRProperties,
thermo,
turbulence,
*turbulence,
Su,
rho,
b,
......
......@@ -89,22 +89,22 @@ public:
const rhoThermo& thermo1() const
{
return thermo1_();
return *thermo1_;
}
const rhoThermo& thermo2() const
{
return thermo2_();
return *thermo2_;
}
rhoThermo& thermo1()
{
return thermo1_();
return *thermo1_;
}
rhoThermo& thermo2()
{
return thermo2_();
return *thermo2_;
}
//- Correct the thermodynamics of each phase
......
......@@ -81,7 +81,7 @@ Foam::phaseModel::phaseModel
Foam::autoPtr<Foam::phaseModel> Foam::phaseModel::clone() const
{
NotImplemented;
return autoPtr<phaseModel>(nullptr);
return autoPtr<phaseModel>();
}
......
......@@ -120,13 +120,13 @@ public:
//- Return const-access to phase rhoThermo
const rhoThermo& thermo() const
{
return thermo_();
return *thermo_;
}
//- Return access to phase rhoThermo
rhoThermo& thermo()
{
return thermo_();
return *thermo_;
}
//- Return const-access to phase divergence
......
......@@ -106,13 +106,13 @@ public:
//- Return const-access to the mixture viscosityModel
const mixtureViscosityModel& muModel() const
{
return muModel_();
return *muModel_;
}
//- Return const-access to the continuous-phase viscosityModel
const viscosityModel& nucModel() const
{
return nucModel_();
return *nucModel_;
}
//- Return const-access to the dispersed-phase density
......
......@@ -181,19 +181,19 @@ public:
//- Return const-access to phase1 viscosityModel
const viscosityModel& nuModel1() const
{
return nuModel1_();
return *nuModel1_;
}
//- Return const-access to phase2 viscosityModel
const viscosityModel& nuModel2() const
{
return nuModel2_();
return *nuModel2_;
}
//- Return const-access to phase3 viscosityModel
const viscosityModel& nuModel3() const
{
return nuModel3_();
return *nuModel3_;
}
//- Return the dynamic laminar viscosity
......
......@@ -205,7 +205,7 @@ Foam::phaseModel::~phaseModel()
Foam::autoPtr<Foam::phaseModel> Foam::phaseModel::clone() const
{
NotImplemented;
return autoPtr<phaseModel>(nullptr);
return autoPtr<phaseModel>();
}
......
......@@ -190,12 +190,12 @@ public:
const surfaceScalarField& phi() const
{
return phiPtr_();
return *phiPtr_;
}
surfaceScalarField& phi()
{
return phiPtr_();
return *phiPtr_;
}
const surfaceScalarField& alphaPhi() const
......
......@@ -68,7 +68,7 @@ Foam::phase::phase
Foam::autoPtr<Foam::phase> Foam::phase::clone() const
{
NotImplemented;
return autoPtr<phase>(nullptr);
return autoPtr<phase>();
}
......
......@@ -120,7 +120,7 @@ public:
//- Return const-access to phase1 viscosityModel
const viscosityModel& nuModel() const
{
return nuModel_();
return *nuModel_;
}
//- Return the kinematic laminar viscosity
......
......@@ -59,14 +59,9 @@ HeatAndMassTransferPhaseSystem
massTransferModels_
);
forAllConstIter
(
phaseSystem::phasePairTable,
this->phasePairs_,
phasePairIter
)
forAllConstIters(this->phasePairs_, phasePairIter)
{
const phasePair& pair(phasePairIter());
const phasePair& pair = *(phasePairIter.object());
if (pair.ordered())
{
......@@ -197,14 +192,9 @@ Foam::HeatAndMassTransferPhaseSystem<BasePhaseSystem>::dmdt
)
);
forAllConstIter
(
phaseSystem::phasePairTable,
this->phasePairs_,
phasePairIter
)
forAllConstIters(this->phasePairs_, phasePairIter)
{
const phasePair& pair(phasePairIter());
const phasePair& pair = *(phasePairIter.object());
if (pair.ordered())
{
......@@ -239,14 +229,9 @@ Foam::HeatAndMassTransferPhaseSystem<BasePhaseSystem>::momentumTransfer() const
phaseSystem::momentumTransferTable& eqns = eqnsPtr();
// Source term due to mass trasfer
forAllConstIter
(
phaseSystem::phasePairTable,
this->phasePairs_,
phasePairIter
)
forAllConstIters(this->phasePairs_, phasePairIter)
{
const phasePair& pair(phasePairIter());
const phasePair& pair = *(phasePairIter.object());
if (pair.ordered())
{
......@@ -291,17 +276,10 @@ Foam::HeatAndMassTransferPhaseSystem<BasePhaseSystem>::heatTransfer() const
}
// Heat transfer with the interface
forAllConstIter
(
heatTransferModelTable,
heatTransferModels_,
heatTransferModelIter
)
forAllConstIters(heatTransferModels_, heatTransferModelIter)
{
const phasePair& pair
(
this->phasePairs_[heatTransferModelIter.key()]
);
const phasePair& pair =
*(this->phasePairs_[heatTransferModelIter.key()]);
const phaseModel* phase = &pair.phase1();
const phaseModel* otherPhase = &pair.phase2();
......@@ -344,14 +322,9 @@ Foam::HeatAndMassTransferPhaseSystem<BasePhaseSystem>::heatTransfer() const
}
// Source term due to mass transfer
forAllConstIter
(
phaseSystem::phasePairTable,
this->phasePairs_,
phasePairIter
)
forAllConstIters(this->phasePairs_, phasePairIter)
{
const phasePair& pair(phasePairIter());
const phasePair& pair = *(phasePairIter.object());
if (pair.ordered())
{
......
......@@ -128,16 +128,12 @@ Foam::HeatTransferPhaseSystem<BasePhaseSystem>::heatTransfer() const
);
}
forAllConstIter
(
heatTransferModelTable,
heatTransferModels_,
heatTransferModelIter
)
forAllConstIters(heatTransferModels_, heatTransferModelIter)
{
const volScalarField K(heatTransferModelIter()->K());
const phasePair& pair =
*(this->phasePairs_[heatTransferModelIter.key()]);
const phasePair& pair(this->phasePairs_[heatTransferModelIter.key()]);
const volScalarField K(heatTransferModelIter()->K());
const phaseModel* phase = &pair.phase1();
const phaseModel* otherPhase = &pair.phase2();
......
......@@ -86,14 +86,9 @@ massTransfer() const
}
// Reset the interfacial mass flow rates
forAllConstIter
(
phaseSystem::phasePairTable,
this->phasePairs_,
phasePairIter
)
forAllConstIters(this->phasePairs_, phasePairIter)
{
const phasePair& pair(phasePairIter());
const phasePair& pair = *(phasePairIter.object());
if (pair.ordered())
{
......@@ -108,22 +103,18 @@ massTransfer() const
}
// Sum up the contribution from each interface composition model
forAllConstIter
forAllConstIters
(
interfaceCompositionModelTable,
interfaceCompositionModels_,
interfaceCompositionModelIter
)
{
const interfaceCompositionModel& compositionModel
(
interfaceCompositionModelIter()
);
const phasePair& pair =
*(this->phasePairs_[interfaceCompositionModelIter.key()]);
const interfaceCompositionModel& compositionModel =
*(interfaceCompositionModelIter.object());
const phasePair& pair
(
this->phasePairs_[interfaceCompositionModelIter.key()]
);
const phaseModel& phase = pair.phase1();
const phaseModel& otherPhase = pair.phase2();
const phasePairKey key(phase.name(), otherPhase.name());
......@@ -209,14 +200,9 @@ correctThermo()
// Yfi is likely to be a strong non-linear (typically exponential) function
// of Tf, so the solution for the temperature is newton-accelerated
forAllConstIter
(
phaseSystem::phasePairTable,
this->phasePairs_,
phasePairIter
)
forAllConstIters(this->phasePairs_, phasePairIter)
{
const phasePair& pair(phasePairIter());
const phasePair& pair = *(phasePairIter.object());
if (pair.ordered())
{
......
......@@ -82,14 +82,10 @@ MomentumTransferPhaseSystem
turbulentDispersionModels_
);
forAllConstIter
(
dragModelTable,
dragModels_,
dragModelIter
)
forAllConstIters(dragModels_, dragModelIter)
{
const phasePair& pair(this->phasePairs_[dragModelIter.key()]);
const phasePair& pair =
*(this->phasePairs_[dragModelIter.key()]);
Kds_.insert
(
......@@ -102,14 +98,10 @@ MomentumTransferPhaseSystem
);
}
forAllConstIter
(
virtualMassModelTable,
virtualMassModels_,
virtualMassModelIter
)
forAllConstIters(virtualMassModels_, virtualMassModelIter)
{
const phasePair& pair(this->phasePairs_[virtualMassModelIter.key()]);
const phasePair& pair =
*(this->phasePairs_[virtualMassModelIter.key()]);
Vms_.insert
(
......@@ -183,16 +175,11 @@ Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::Kd
)
);
forAllConstIter
(
phaseSystem::KdTable,
Kds_,
KdIter
)
forAllConstIters(Kds_, KdIter)
{
const volScalarField& K(*KdIter());
const phasePair& pair = *(this->phasePairs_[KdIter.key()]);
const phasePair& pair(this->phasePairs_[KdIter.key()]);
const volScalarField& K(*KdIter());
const phaseModel* phase1 = &pair.phase1();
const phaseModel* phase2 = &pair.phase2();
......@@ -430,27 +417,17 @@ Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::momentumTransfer() const
}
// Update the drag coefficients
forAllConstIter
(
dragModelTable,
dragModels_,
dragModelIter
)
forAllConstIters(dragModels_, dragModelIter)
{
*Kds_[dragModelIter.key()] = dragModelIter()->K();
}
// Add the implicit part of the drag force
forAllConstIter
(
phaseSystem::KdTable,
Kds_,
KdIter
)
forAllConstIters(Kds_, KdIter)
{
const volScalarField& K(*KdIter());
const phasePair& pair = *(this->phasePairs_[KdIter.key()]);
const phasePair& pair(this->phasePairs_[KdIter.key()]);
const volScalarField& K(*KdIter());
const phaseModel* phase = &pair.phase1();
const phaseModel* otherPhase = &pair.phase2();
......@@ -466,27 +443,17 @@ Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::momentumTransfer() const
}
// Update the virtual mass coefficients
forAllConstIter
(
virtualMassModelTable,
virtualMassModels_,
virtualMassModelIter
)
forAllConstIters(virtualMassModels_, virtualMassModelIter)
{
*Vms_[virtualMassModelIter.key()] = virtualMassModelIter()->K();
}
// Add the virtual mass force
forAllConstIter
(
phaseSystem::VmTable,
Vms_,
VmIter
)
forAllConstIters(Vms_, VmIter)
{
const volScalarField& Vm(*VmIter());
const phasePair& pair = *(this->phasePairs_[VmIter.key()]);
const phasePair& pair(this->phasePairs_[VmIter.key()]);
const volScalarField& Vm(*VmIter());
const phaseModel* phase = &pair.phase1();
const phaseModel* otherPhase = &pair.phase2();
......@@ -557,33 +524,22 @@ Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::Fs() const
PtrList<volVectorField>& Fs = tFs();
// Add the lift force
forAllConstIter
(
liftModelTable,
liftModels_,
liftModelIter
)
forAllConstIters(liftModels_, modelIter)
{
const volVectorField F(liftModelIter()->F<vector>());
const phasePair& pair = *(this->phasePairs_[modelIter.key()]);
const phasePair& pair(this->phasePairs_[liftModelIter.key()]);
const volVectorField F(modelIter()->template F<vector>());
setF(Fs, pair.phase1().index()) += F;
setF(Fs, pair.phase2().index()) -= F;
}
// Add the wall lubrication force
forAllConstIter
(
wallLubricationModelTable,
wallLubricationModels_,
wallLubricationModelIter
)
forAllConstIters(wallLubricationModels_, modelIter)
{
const volVectorField F(wallLubricationModelIter()->F<vector>());
const phasePair& pair = *(this->phasePairs_[modelIter.key()]);
const phasePair&
pair(this->phasePairs_[wallLubricationModelIter.key()]);
const volVectorField F(modelIter()->template F<vector>());
setF(Fs, pair.phase1().index()) += F;
setF(Fs, pair.phase2().index()) -= F;
......@@ -647,15 +603,10 @@ Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::phiDs
PtrList<surfaceScalarField>& phiDs = tphiDs();
// Add the turbulent dispersion force
forAllConstIter
(
turbulentDispersionModelTable,
turbulentDispersionModels_,
turbulentDispersionModelIter
)
forAllConstIters(turbulentDispersionModels_, turbulentDispersionModelIter)
{
const phasePair&
pair(this->phasePairs_[turbulentDispersionModelIter.key()]);
const phasePair& pair =
*(this->phasePairs_[turbulentDispersionModelIter.key()]);
const volScalarField D(turbulentDispersionModelIter()->D());
const surfaceScalarField snGradAlpha1
......
......@@ -42,14 +42,9 @@ ThermalPhaseChangePhaseSystem
massTransfer_(this->lookup("massTransfer"))
{
forAllConstIter
(
phaseSystem::phasePairTable,
this->phasePairs_,
phasePairIter
)
forAllConstIters(this->phasePairs_, phasePairIter)
{
const phasePair& pair(phasePairIter());