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:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2015-2018 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 2015-2017 OpenFOAM Foundation
|
||||
\\ / A nd | Copyright (C) 2015-2018 OpenFOAM Foundation
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
@ -242,9 +242,6 @@ Foam::HeatAndMassTransferPhaseSystem<BasePhaseSystem>::heatTransfer() const
|
||||
this->phasePairs_[heatTransferModelIter.key()]
|
||||
);
|
||||
|
||||
const phaseModel* phase = &pair.phase1();
|
||||
const phaseModel* otherPhase = &pair.phase2();
|
||||
|
||||
const volScalarField& Tf(*Tf_[pair]);
|
||||
|
||||
const volScalarField K1
|
||||
@ -270,14 +267,15 @@ Foam::HeatAndMassTransferPhaseSystem<BasePhaseSystem>::heatTransfer() const
|
||||
|
||||
forAllConstIter(phasePair, pair, iter)
|
||||
{
|
||||
const volScalarField& he(phase->thermo().he());
|
||||
volScalarField Cpv(phase->thermo().Cpv());
|
||||
const phaseModel& phase = iter();
|
||||
|
||||
*eqns[phase->name()] +=
|
||||
(*K)*(Tf - phase->thermo().T())
|
||||
const volScalarField& he(phase.thermo().he());
|
||||
volScalarField Cpv(phase.thermo().Cpv());
|
||||
|
||||
*eqns[phase.name()] +=
|
||||
(*K)*(Tf - phase.thermo().T())
|
||||
+ KEff/Cpv*he - fvm::Sp(KEff/Cpv, he);
|
||||
|
||||
Swap(phase, otherPhase);
|
||||
Swap(K, otherK);
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,19 +146,17 @@ Foam::HeatTransferPhaseSystem<BasePhaseSystem>::heatTransfer() const
|
||||
|
||||
const phasePair& pair(this->phasePairs_[heatTransferModelIter.key()]);
|
||||
|
||||
const phaseModel* phase = &pair.phase1();
|
||||
const phaseModel* otherPhase = &pair.phase2();
|
||||
|
||||
forAllConstIter(phasePair, pair, iter)
|
||||
{
|
||||
const volScalarField& he(phase->thermo().he());
|
||||
volScalarField Cpv(phase->thermo().Cpv());
|
||||
const phaseModel& phase = iter();
|
||||
const phaseModel& otherPhase = iter.otherPhase();
|
||||
|
||||
*eqns[phase->name()] +=
|
||||
K*(otherPhase->thermo().T() - phase->thermo().T() + he/Cpv)
|
||||
const volScalarField& he(phase.thermo().he());
|
||||
volScalarField Cpv(phase.thermo().Cpv());
|
||||
|
||||
*eqns[phase.name()] +=
|
||||
K*(otherPhase.thermo().T() - phase.thermo().T() + he/Cpv)
|
||||
- fvm::Sp(K/Cpv, he);
|
||||
|
||||
Swap(phase, otherPhase);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -159,7 +159,7 @@ Foam::InterfaceCompositionPhaseChangePhaseSystem<BasePhaseSystem>::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
|
||||
(
|
||||
phasePairKey(phase.name(), pair.other(phase).name(), false)
|
||||
phasePairKey(phase.name(), pair.otherPhase(phase).name(), false)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -554,19 +554,11 @@ Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::momentumTransfer() const
|
||||
)
|
||||
{
|
||||
const volScalarField& K(*KdIter());
|
||||
|
||||
const phasePair& pair(this->phasePairs_[KdIter.key()]);
|
||||
|
||||
const phaseModel* phase = &pair.phase1();
|
||||
const phaseModel* otherPhase = &pair.phase2();
|
||||
|
||||
forAllConstIter(phasePair, pair, iter)
|
||||
{
|
||||
const volVectorField& U = phase->U();
|
||||
|
||||
*eqns[phase->name()] -= fvm::Sp(K, U);
|
||||
|
||||
Swap(phase, otherPhase);
|
||||
*eqns[iter().name()] -= fvm::Sp(K, iter().U()());
|
||||
}
|
||||
}
|
||||
|
||||
@ -591,28 +583,25 @@ Foam::MomentumTransferPhaseSystem<BasePhaseSystem>::momentumTransfer() const
|
||||
)
|
||||
{
|
||||
const volScalarField& Vm(*VmIter());
|
||||
|
||||
const phasePair& pair(this->phasePairs_[VmIter.key()]);
|
||||
|
||||
const phaseModel* phase = &pair.phase1();
|
||||
const phaseModel* otherPhase = &pair.phase2();
|
||||
|
||||
forAllConstIter(phasePair, pair, iter)
|
||||
{
|
||||
const volVectorField& U = phase->U();
|
||||
const surfaceScalarField& phi = phase->phi();
|
||||
const phaseModel& phase = iter();
|
||||
const phaseModel& otherPhase = iter.otherPhase();
|
||||
|
||||
*eqns[phase->name()] -=
|
||||
const volVectorField& U = phase.U();
|
||||
const surfaceScalarField& phi = phase.phi();
|
||||
|
||||
*eqns[phase.name()] -=
|
||||
Vm
|
||||
*(
|
||||
fvm::ddt(U)
|
||||
+ fvm::div(phi, U)
|
||||
- fvm::Sp(fvc::div(phi), U)
|
||||
- otherPhase->DUDt()
|
||||
- otherPhase.DUDt()
|
||||
)
|
||||
+ this->MRF_.DDt(Vm, U - otherPhase->U());
|
||||
|
||||
Swap(phase, otherPhase);
|
||||
+ this->MRF_.DDt(Vm, U - otherPhase.U());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -191,7 +191,7 @@ Foam::PopulationBalancePhaseSystem<BasePhaseSystem>::dmdt
|
||||
{
|
||||
tDmdtFromKey.ref() += this->dmdt
|
||||
(
|
||||
phasePairKey(phase.name(), pair.other(phase).name(), false)
|
||||
phasePairKey(phase.name(), pair.otherPhase(phase).name(), false)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -190,7 +190,7 @@ Foam::ThermalPhaseChangePhaseSystem<BasePhaseSystem>::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
|
||||
(
|
||||
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
|
||||
(
|
||||
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;
|
||||
|
||||
bool wallBoilingActive = false;
|
||||
const phaseModel* phase1Ptr = &phase1;
|
||||
const phaseModel* phase2Ptr = &phase2;
|
||||
|
||||
forAllConstIter(phasePair, pair, iter)
|
||||
{
|
||||
const phaseModel& phase = iter();
|
||||
const phaseModel& otherPhase = iter.otherPhase();
|
||||
|
||||
if
|
||||
(
|
||||
phase1Ptr->mesh().foundObject<volScalarField>
|
||||
phase.mesh().foundObject<volScalarField>
|
||||
(
|
||||
"alphat." + phase1Ptr->name()
|
||||
"alphat." + phase.name()
|
||||
)
|
||||
)
|
||||
{
|
||||
const volScalarField& alphat =
|
||||
phase1Ptr->mesh().lookupObject<volScalarField>
|
||||
phase.mesh().lookupObject<volScalarField>
|
||||
(
|
||||
"alphat." + phase1Ptr->name()
|
||||
"alphat." + phase.name()
|
||||
);
|
||||
|
||||
const fvPatchList& patches = this->mesh().boundary();
|
||||
@ -620,10 +621,9 @@ void Foam::ThermalPhaseChangePhaseSystem<BasePhaseSystem>::correctThermo()
|
||||
(
|
||||
alphat.boundaryField()[patchi]
|
||||
);
|
||||
phasePairKey key
|
||||
(
|
||||
phase1Ptr->name(), phase2Ptr->name(), false
|
||||
);
|
||||
|
||||
phasePairKey key(phase.name(), otherPhase.name());
|
||||
|
||||
if (PCpatch.activePhasePair(key))
|
||||
{
|
||||
wallBoilingActive = true;
|
||||
@ -649,8 +649,6 @@ void Foam::ThermalPhaseChangePhaseSystem<BasePhaseSystem>::correctThermo()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Swap(phase1Ptr, phase2Ptr);
|
||||
}
|
||||
|
||||
if (wallBoilingActive)
|
||||
|
||||
@ -162,10 +162,63 @@ public:
|
||||
//- Return the other phase relative to the given phase
|
||||
// Generates a FatalError if this phasePair does not contain
|
||||
// the given phase
|
||||
inline const phaseModel& other(const phaseModel& phase) const;
|
||||
inline const phaseModel& otherPhase(const phaseModel& phase) const;
|
||||
|
||||
//- Return gravitation acceleration
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -229,7 +229,7 @@ while (pimple.correct())
|
||||
|
||||
if (pair.contains(phase))
|
||||
{
|
||||
const phaseModel& otherPhase = pair.other(phase);
|
||||
const phaseModel& otherPhase = pair.otherPhase(phase);
|
||||
|
||||
phiHbyAs[phasei] +=
|
||||
fvc::interpolate(rAUs[phasei]*K)
|
||||
|
||||
@ -62,7 +62,7 @@ PtrList<fvVectorMatrix> UEqns(phases.size());
|
||||
|
||||
if (pair.contains(phase))
|
||||
{
|
||||
const phaseModel& otherPhase = pair.other(phase);
|
||||
const phaseModel& otherPhase = pair.otherPhase(phase);
|
||||
|
||||
UEqns[phasei] +=
|
||||
Vm
|
||||
|
||||
@ -197,7 +197,7 @@ while (pimple.correct())
|
||||
if (pair.contains(phase))
|
||||
{
|
||||
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]
|
||||
*(
|
||||
Vmf*byDt(MRF.absolute(phase.phi().oldTime()))
|
||||
+ Vmf*ddtPhis[pair.other(phase).index()]
|
||||
+ Vmf*ddtPhis[pair.otherPhase(phase).index()]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user