reactingEulerFoam::phasePair: Added const_iterator

which provides access to the current phase and the corresponding other phase for
each of the phases in the pair.  This allows some simplification of the phase
pair loops in several sub-models and avoids the need for pointer swaps.
This commit is contained in:
Henry Weller
2018-01-04 15:17:56 +00:00
parent 4cf2b466e6
commit 7fb371eb03
14 changed files with 218 additions and 69 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -216,7 +216,7 @@ Foam::interfaceCompositionModels::NonRandomTwoLiquid<Thermo, OtherThermo>::Yf
*speciesModel1_->Yf(speciesName, Tf) *speciesModel1_->Yf(speciesName, Tf)
*gamma1_; *gamma1_;
} }
else if(speciesName == species2Name_) else if (speciesName == species2Name_)
{ {
return return
this->otherThermo_.composition().Y(speciesName) this->otherThermo_.composition().Y(speciesName)
@ -248,7 +248,7 @@ YfPrime
*speciesModel1_->YfPrime(speciesName, Tf) *speciesModel1_->YfPrime(speciesName, Tf)
*gamma1_; *gamma1_;
} }
else if(speciesName == species2Name_) else if (speciesName == species2Name_)
{ {
return return
this->otherThermo_.composition().Y(speciesName) this->otherThermo_.composition().Y(speciesName)

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation \\ / A nd | Copyright (C) 2015-2018 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -242,9 +242,6 @@ Foam::HeatAndMassTransferPhaseSystem<BasePhaseSystem>::heatTransfer() const
this->phasePairs_[heatTransferModelIter.key()] this->phasePairs_[heatTransferModelIter.key()]
); );
const phaseModel* phase = &pair.phase1();
const phaseModel* otherPhase = &pair.phase2();
const volScalarField& Tf(*Tf_[pair]); const volScalarField& Tf(*Tf_[pair]);
const volScalarField K1 const volScalarField K1
@ -270,14 +267,15 @@ Foam::HeatAndMassTransferPhaseSystem<BasePhaseSystem>::heatTransfer() const
forAllConstIter(phasePair, pair, iter) forAllConstIter(phasePair, pair, iter)
{ {
const volScalarField& he(phase->thermo().he()); const phaseModel& phase = iter();
volScalarField Cpv(phase->thermo().Cpv());
*eqns[phase->name()] += const volScalarField& he(phase.thermo().he());
(*K)*(Tf - phase->thermo().T()) volScalarField Cpv(phase.thermo().Cpv());
*eqns[phase.name()] +=
(*K)*(Tf - phase.thermo().T())
+ KEff/Cpv*he - fvm::Sp(KEff/Cpv, he); + KEff/Cpv*he - fvm::Sp(KEff/Cpv, he);
Swap(phase, otherPhase);
Swap(K, otherK); Swap(K, otherK);
} }
} }

View File

@ -146,19 +146,17 @@ Foam::HeatTransferPhaseSystem<BasePhaseSystem>::heatTransfer() const
const phasePair& pair(this->phasePairs_[heatTransferModelIter.key()]); const phasePair& pair(this->phasePairs_[heatTransferModelIter.key()]);
const phaseModel* phase = &pair.phase1();
const phaseModel* otherPhase = &pair.phase2();
forAllConstIter(phasePair, pair, iter) forAllConstIter(phasePair, pair, iter)
{ {
const volScalarField& he(phase->thermo().he()); const phaseModel& phase = iter();
volScalarField Cpv(phase->thermo().Cpv()); const phaseModel& otherPhase = iter.otherPhase();
*eqns[phase->name()] += const volScalarField& he(phase.thermo().he());
K*(otherPhase->thermo().T() - phase->thermo().T() + he/Cpv) volScalarField Cpv(phase.thermo().Cpv());
*eqns[phase.name()] +=
K*(otherPhase.thermo().T() - phase.thermo().T() + he/Cpv)
- fvm::Sp(K/Cpv, he); - fvm::Sp(K/Cpv, he);
Swap(phase, otherPhase);
} }
} }

View File

@ -159,7 +159,7 @@ Foam::InterfaceCompositionPhaseChangePhaseSystem<BasePhaseSystem>::iDmdt
{ {
tiDmdt.ref() += this->iDmdt tiDmdt.ref() += this->iDmdt
( (
phasePairKey(phase.name(), pair.other(phase).name(), false) phasePairKey(phase.name(), pair.otherPhase(phase).name(), false)
); );
} }
} }
@ -208,7 +208,7 @@ Foam::InterfaceCompositionPhaseChangePhaseSystem<BasePhaseSystem>::dmdt
{ {
tDmdt.ref() += this->dmdt tDmdt.ref() += this->dmdt
( (
phasePairKey(phase.name(), pair.other(phase).name(), false) phasePairKey(phase.name(), pair.otherPhase(phase).name(), false)
); );
} }
} }

View File

@ -554,19 +554,11 @@ Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::momentumTransfer() const
) )
{ {
const volScalarField& K(*KdIter()); const volScalarField& K(*KdIter());
const phasePair& pair(this->phasePairs_[KdIter.key()]); const phasePair& pair(this->phasePairs_[KdIter.key()]);
const phaseModel* phase = &pair.phase1();
const phaseModel* otherPhase = &pair.phase2();
forAllConstIter(phasePair, pair, iter) forAllConstIter(phasePair, pair, iter)
{ {
const volVectorField& U = phase->U(); *eqns[iter().name()] -= fvm::Sp(K, iter().U()());
*eqns[phase->name()] -= fvm::Sp(K, U);
Swap(phase, otherPhase);
} }
} }
@ -591,28 +583,25 @@ Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::momentumTransfer() const
) )
{ {
const volScalarField& Vm(*VmIter()); const volScalarField& Vm(*VmIter());
const phasePair& pair(this->phasePairs_[VmIter.key()]); const phasePair& pair(this->phasePairs_[VmIter.key()]);
const phaseModel* phase = &pair.phase1();
const phaseModel* otherPhase = &pair.phase2();
forAllConstIter(phasePair, pair, iter) forAllConstIter(phasePair, pair, iter)
{ {
const volVectorField& U = phase->U(); const phaseModel& phase = iter();
const surfaceScalarField& phi = phase->phi(); const phaseModel& otherPhase = iter.otherPhase();
*eqns[phase->name()] -= const volVectorField& U = phase.U();
const surfaceScalarField& phi = phase.phi();
*eqns[phase.name()] -=
Vm Vm
*( *(
fvm::ddt(U) fvm::ddt(U)
+ fvm::div(phi, U) + fvm::div(phi, U)
- fvm::Sp(fvc::div(phi), U) - fvm::Sp(fvc::div(phi), U)
- otherPhase->DUDt() - otherPhase.DUDt()
) )
+ this->MRF_.DDt(Vm, U - otherPhase->U()); + this->MRF_.DDt(Vm, U - otherPhase.U());
Swap(phase, otherPhase);
} }
} }

View File

@ -191,7 +191,7 @@ Foam::PopulationBalancePhaseSystem<BasePhaseSystem>::dmdt
{ {
tDmdtFromKey.ref() += this->dmdt tDmdtFromKey.ref() += this->dmdt
( (
phasePairKey(phase.name(), pair.other(phase).name(), false) phasePairKey(phase.name(), pair.otherPhase(phase).name(), false)
); );
} }
} }

View File

@ -190,7 +190,7 @@ Foam::ThermalPhaseChangePhaseSystem<BasePhaseSystem>::iDmdt
{ {
tiDmdt.ref() += this->iDmdt tiDmdt.ref() += this->iDmdt
( (
phasePairKey(phase.name(), pair.other(phase).name(), false) phasePairKey(phase.name(), pair.otherPhase(phase).name())
); );
} }
} }
@ -252,7 +252,7 @@ Foam::ThermalPhaseChangePhaseSystem<BasePhaseSystem>::wDmdt
{ {
twDmdt.ref() += this->wDmdt twDmdt.ref() += this->wDmdt
( (
phasePairKey(phase.name(), pair.other(phase).name(), false) phasePairKey(phase.name(), pair.otherPhase(phase).name())
); );
} }
} }
@ -301,7 +301,7 @@ Foam::ThermalPhaseChangePhaseSystem<BasePhaseSystem>::dmdt
{ {
tDmdt.ref() += this->dmdt tDmdt.ref() += this->dmdt
( (
phasePairKey(phase.name(), pair.other(phase).name(), false) phasePairKey(phase.name(), pair.otherPhase(phase).name())
); );
} }
} }
@ -583,23 +583,24 @@ void Foam::ThermalPhaseChangePhaseSystem<BasePhaseSystem>::correctThermo()
wMDotL *= 0; wMDotL *= 0;
bool wallBoilingActive = false; bool wallBoilingActive = false;
const phaseModel* phase1Ptr = &phase1;
const phaseModel* phase2Ptr = &phase2;
forAllConstIter(phasePair, pair, iter) forAllConstIter(phasePair, pair, iter)
{ {
const phaseModel& phase = iter();
const phaseModel& otherPhase = iter.otherPhase();
if if
( (
phase1Ptr->mesh().foundObject<volScalarField> phase.mesh().foundObject<volScalarField>
( (
"alphat." + phase1Ptr->name() "alphat." + phase.name()
) )
) )
{ {
const volScalarField& alphat = const volScalarField& alphat =
phase1Ptr->mesh().lookupObject<volScalarField> phase.mesh().lookupObject<volScalarField>
( (
"alphat." + phase1Ptr->name() "alphat." + phase.name()
); );
const fvPatchList& patches = this->mesh().boundary(); const fvPatchList& patches = this->mesh().boundary();
@ -620,11 +621,10 @@ void Foam::ThermalPhaseChangePhaseSystem<BasePhaseSystem>::correctThermo()
( (
alphat.boundaryField()[patchi] alphat.boundaryField()[patchi]
); );
phasePairKey key
( phasePairKey key(phase.name(), otherPhase.name());
phase1Ptr->name(), phase2Ptr->name(), false
); if (PCpatch.activePhasePair(key))
if(PCpatch.activePhasePair(key))
{ {
wallBoilingActive = true; wallBoilingActive = true;
@ -649,8 +649,6 @@ void Foam::ThermalPhaseChangePhaseSystem<BasePhaseSystem>::correctThermo()
} }
} }
} }
Swap(phase1Ptr, phase2Ptr);
} }
if (wallBoilingActive) if (wallBoilingActive)

View File

@ -162,10 +162,63 @@ public:
//- Return the other phase relative to the given phase //- Return the other phase relative to the given phase
// Generates a FatalError if this phasePair does not contain // Generates a FatalError if this phasePair does not contain
// the given phase // the given phase
inline const phaseModel& other(const phaseModel& phase) const; inline const phaseModel& otherPhase(const phaseModel& phase) const;
//- Return gravitation acceleration //- Return gravitation acceleration
inline const uniformDimensionedVectorField& g() const; inline const uniformDimensionedVectorField& g() const;
//- STL const_iterator
class const_iterator
{
// Private data
//- Reference to the pair for which this is an iterator
const phasePair& pair_;
//- Current index
label index_;
//- Construct an iterator with the given index
inline const_iterator(const phasePair&, const label index);
public:
friend class phasePair;
// Constructors
//- Construct from pair, moving to its 'begin' position
inline explicit const_iterator(const phasePair&);
// Member operators
inline bool operator==(const const_iterator&) const;
inline bool operator!=(const const_iterator&) const;
inline const phaseModel& operator*() const;
inline const phaseModel& operator()() const;
inline const phaseModel& otherPhase() const;
inline const_iterator& operator++();
inline const_iterator operator++(int);
};
//- const_iterator set to the beginning of the pair
inline const_iterator cbegin() const;
//- const_iterator set to beyond the end of the pair
inline const_iterator cend() const;
//- const_iterator set to the beginning of the pair
inline const_iterator begin() const;
//- const_iterator set to beyond the end of the pair
inline const_iterator end() const;
}; };

View File

@ -43,7 +43,7 @@ inline bool Foam::phasePair::contains(const phaseModel& phase) const
} }
inline const Foam::phaseModel& Foam::phasePair::other inline const Foam::phaseModel& Foam::phasePair::otherPhase
( (
const phaseModel& phase const phaseModel& phase
) const ) const
@ -73,4 +73,117 @@ inline const Foam::uniformDimensionedVectorField& Foam::phasePair::g() const
} }
// * * * * * * * * * * * * * * * * Iterators * * * * * * * * * * * * * * * * //
inline Foam::phasePair::const_iterator::const_iterator
(
const phasePair& pair,
const label index
)
:
pair_(pair),
index_(index)
{}
inline Foam::phasePair::const_iterator::const_iterator(const phasePair& pair)
:
const_iterator(pair, 0)
{}
inline bool Foam::phasePair::const_iterator::operator==
(
const const_iterator& iter
) const
{
return (this->index_ == iter.index_);
}
inline bool Foam::phasePair::const_iterator::operator!=
(
const const_iterator& iter
) const
{
return !(this->operator==(iter));
}
inline const Foam::phaseModel&
Foam::phasePair::const_iterator::operator*() const
{
if (index_ == 0)
{
return pair_.phase1_;
}
else
{
return pair_.phase2_;
}
}
inline const Foam::phaseModel&
Foam::phasePair::const_iterator::operator()() const
{
return operator*();
}
inline const Foam::phaseModel&
Foam::phasePair::const_iterator::otherPhase() const
{
if (index_ == 0)
{
return pair_.phase2_;
}
else
{
return pair_.phase1_;
}
}
inline Foam::phasePair::const_iterator&
Foam::phasePair::const_iterator::operator++()
{
index_++;
return *this;
}
inline Foam::phasePair::const_iterator
Foam::phasePair::const_iterator::operator++(int)
{
const_iterator old = *this;
this->operator++();
return old;
}
inline Foam::phasePair::const_iterator Foam::phasePair::cbegin() const
{
return const_iterator(*this);
}
inline Foam::phasePair::const_iterator Foam::phasePair::cend() const
{
return const_iterator(*this, 2);
}
inline Foam::phasePair::const_iterator Foam::phasePair::begin() const
{
return const_iterator(*this);
}
inline Foam::phasePair::const_iterator Foam::phasePair::end() const
{
return const_iterator(*this, 2);
}
// ************************************************************************* // // ************************************************************************* //

View File

@ -127,7 +127,7 @@ Foam::Istream& Foam::operator>>(Istream& is, phasePairKey& key)
{ {
key.ordered_ = false; key.ordered_ = false;
} }
else if(temp[1] == "in") else if (temp[1] == "in")
{ {
key.ordered_ = true; key.ordered_ = true;
} }

View File

@ -40,12 +40,12 @@ void Foam::diameterModels::populationBalanceModel::registerVelocityGroups()
{ {
forAll(fluid_.phases(), phasei) forAll(fluid_.phases(), phasei)
{ {
if(isA<velocityGroup>(fluid_.phases()[phasei].dPtr()())) if (isA<velocityGroup>(fluid_.phases()[phasei].dPtr()()))
{ {
const velocityGroup& velGroup = const velocityGroup& velGroup =
refCast<const velocityGroup>(fluid_.phases()[phasei].dPtr()()); refCast<const velocityGroup>(fluid_.phases()[phasei].dPtr()());
if(velGroup.popBalName() == this->name()) if (velGroup.popBalName() == this->name())
{ {
velocityGroups_.append(&const_cast<velocityGroup&>(velGroup)); velocityGroups_.append(&const_cast<velocityGroup&>(velGroup));

View File

@ -229,7 +229,7 @@ while (pimple.correct())
if (pair.contains(phase)) if (pair.contains(phase))
{ {
const phaseModel& otherPhase = pair.other(phase); const phaseModel& otherPhase = pair.otherPhase(phase);
phiHbyAs[phasei] += phiHbyAs[phasei] +=
fvc::interpolate(rAUs[phasei]*K) fvc::interpolate(rAUs[phasei]*K)

View File

@ -62,7 +62,7 @@ PtrList<fvVectorMatrix> UEqns(phases.size());
if (pair.contains(phase)) if (pair.contains(phase))
{ {
const phaseModel& otherPhase = pair.other(phase); const phaseModel& otherPhase = pair.otherPhase(phase);
UEqns[phasei] += UEqns[phasei] +=
Vm Vm

View File

@ -197,7 +197,7 @@ while (pimple.correct())
if (pair.contains(phase)) if (pair.contains(phase))
{ {
phiHbyAs[phasei] += phiHbyAs[phasei] +=
rAUfs[phasei]*Kf*MRF.absolute(pair.other(phase).phi()); rAUfs[phasei]*Kf*MRF.absolute(pair.otherPhase(phase).phi());
} }
} }
@ -219,7 +219,7 @@ while (pimple.correct())
rAUfs[phasei] rAUfs[phasei]
*( *(
Vmf*byDt(MRF.absolute(phase.phi().oldTime())) Vmf*byDt(MRF.absolute(phase.phi().oldTime()))
+ Vmf*ddtPhis[pair.other(phase).index()] + Vmf*ddtPhis[pair.otherPhase(phase).index()]
); );
} }
} }