Skip to content
Snippets Groups Projects
Commit ffedbafe authored by Henry Weller's avatar Henry Weller
Browse files

reactingEulerFoam/phaseSystem: Create an ordered container for phaseModels

The previous method using a HashTable required a separate ordered list
of names which is hard to work with and maintain.
parent 363cd93d
Branches
Tags
No related merge requests found
Showing
with 214 additions and 84 deletions
...@@ -254,14 +254,14 @@ public: ...@@ -254,14 +254,14 @@ public:
virtual volScalarField& he() virtual volScalarField& he()
{ {
notImplemented("multiphaseMixtureThermo::he()"); notImplemented("multiphaseMixtureThermo::he()");
return phases_[0]->thermo().he(); return phases_[0].thermo().he();
} }
//- Enthalpy/Internal energy [J/kg] //- Enthalpy/Internal energy [J/kg]
virtual const volScalarField& he() const virtual const volScalarField& he() const
{ {
notImplemented("multiphaseMixtureThermo::he() const"); notImplemented("multiphaseMixtureThermo::he() const");
return phases_[0]->thermo().he(); return phases_[0].thermo().he();
} }
//- Enthalpy/Internal energy //- Enthalpy/Internal energy
......
...@@ -50,7 +50,7 @@ Foam::ThermoPhaseModel<BasePhaseModel, ThermoType>::ThermoPhaseModel ...@@ -50,7 +50,7 @@ Foam::ThermoPhaseModel<BasePhaseModel, ThermoType>::ThermoPhaseModel
{ {
thermoPtr_.set thermoPtr_.set
( (
ThermoType::New(fluid.mesh(), phaseName).ptr() ThermoType::New(fluid.mesh(), this->name()).ptr()
); );
thermo_ = thermoPtr_.ptr(); thermo_ = thermoPtr_.ptr();
......
...@@ -72,6 +72,13 @@ Foam::phaseModel::phaseModel ...@@ -72,6 +72,13 @@ Foam::phaseModel::phaseModel
} }
Foam::autoPtr<Foam::phaseModel> Foam::phaseModel::clone() const
{
notImplemented("phaseModel::clone() const");
return autoPtr<phaseModel>(NULL);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::phaseModel::~phaseModel() Foam::phaseModel::~phaseModel()
...@@ -86,6 +93,12 @@ const Foam::word& Foam::phaseModel::name() const ...@@ -86,6 +93,12 @@ const Foam::word& Foam::phaseModel::name() const
} }
const Foam::word& Foam::phaseModel::keyword() const
{
return name_;
}
const Foam::phaseSystem& Foam::phaseModel::fluid() const const Foam::phaseSystem& Foam::phaseModel::fluid() const
{ {
return fluid_; return fluid_;
......
...@@ -107,9 +107,8 @@ public: ...@@ -107,9 +107,8 @@ public:
const word& phaseName const word& phaseName
); );
//- Return clone
//- Destructor autoPtr<phaseModel> clone() const;
virtual ~phaseModel();
// Selectors // Selectors
...@@ -120,12 +119,43 @@ public: ...@@ -120,12 +119,43 @@ public:
const word& phaseName const word& phaseName
); );
//- Return a pointer to a new phase created on freestore
// from Istream
class iNew
{
const phaseSystem& fluid_;
public:
iNew
(
const phaseSystem& fluid
)
:
fluid_(fluid)
{}
autoPtr<phaseModel> operator()(Istream& is) const
{
return autoPtr<phaseModel>
(
phaseModel::New(fluid_, word(is))
);
}
};
//- Destructor
virtual ~phaseModel();
// Member Functions // Member Functions
//- Return the name of this phase //- Return the name of this phase
const word& name() const; const word& name() const;
const word& keyword() const;
//- Return the system to which this phase belongs //- Return the system to which this phase belongs
const phaseSystem& fluid() const; const phaseSystem& fluid() const;
......
...@@ -41,31 +41,7 @@ const Foam::word Foam::phaseSystem::propertiesName("phaseProperties"); ...@@ -41,31 +41,7 @@ const Foam::word Foam::phaseSystem::propertiesName("phaseProperties");
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
Foam::phaseSystem::phaseModelTable Foam::tmp<Foam::surfaceScalarField> Foam::phaseSystem::calcPhi
Foam::phaseSystem::generatePhaseModels(const wordList& phaseNames) const
{
phaseModelTable phaseModels;
forAllConstIter(wordList, phaseNames, phaseNameIter)
{
phaseModels.insert
(
*phaseNameIter,
phaseModel::New
(
*this,
*phaseNameIter
)
);
}
// normalise ?
return phaseModels;
}
Foam::tmp<Foam::surfaceScalarField> Foam::phaseSystem::generatePhi
( (
const phaseModelTable& phaseModels const phaseModelTable& phaseModels
) const ) const
...@@ -77,7 +53,7 @@ Foam::tmp<Foam::surfaceScalarField> Foam::phaseSystem::generatePhi ...@@ -77,7 +53,7 @@ Foam::tmp<Foam::surfaceScalarField> Foam::phaseSystem::generatePhi
new surfaceScalarField new surfaceScalarField
( (
"phi", "phi",
fvc::interpolate(phaseModelIter()())*phaseModelIter()->phi() fvc::interpolate(phaseModelIter())*phaseModelIter().phi()
) )
); );
...@@ -86,8 +62,8 @@ Foam::tmp<Foam::surfaceScalarField> Foam::phaseSystem::generatePhi ...@@ -86,8 +62,8 @@ Foam::tmp<Foam::surfaceScalarField> Foam::phaseSystem::generatePhi
for (; phaseModelIter != phaseModels.end(); ++ phaseModelIter) for (; phaseModelIter != phaseModels.end(); ++ phaseModelIter)
{ {
tmpPhi() += tmpPhi() +=
fvc::interpolate(phaseModelIter()()) fvc::interpolate(phaseModelIter())
*phaseModelIter()->phi(); *phaseModelIter().phi();
} }
return tmpPhi; return tmpPhi;
...@@ -167,11 +143,9 @@ Foam::phaseSystem::phaseSystem ...@@ -167,11 +143,9 @@ Foam::phaseSystem::phaseSystem
mesh_(mesh), mesh_(mesh),
phaseNames_(lookup("phases")), phaseModels_(lookup("phases"), phaseModel::iNew(*this)),
phaseModels_(generatePhaseModels(phaseNames_)),
phi_(generatePhi(phaseModels_)), phi_(calcPhi(phaseModels_)),
dpdt_ dpdt_
( (
...@@ -197,7 +171,7 @@ Foam::phaseSystem::phaseSystem ...@@ -197,7 +171,7 @@ Foam::phaseSystem::phaseSystem
blendingMethod::New blendingMethod::New
( (
iter().dict(), iter().dict(),
wordList(lookup("phases")) phaseModels_.toc()
) )
); );
} }
...@@ -224,12 +198,12 @@ Foam::tmp<Foam::volScalarField> Foam::phaseSystem::rho() const ...@@ -224,12 +198,12 @@ Foam::tmp<Foam::volScalarField> Foam::phaseSystem::rho() const
tmp<volScalarField> tmpRho tmp<volScalarField> tmpRho
( (
phaseModelIter()()*phaseModelIter()->rho() phaseModelIter()*phaseModelIter().rho()
); );
for (; phaseModelIter != phaseModels_.end(); ++ phaseModelIter) for (; phaseModelIter != phaseModels_.end(); ++ phaseModelIter)
{ {
tmpRho() += phaseModelIter()()*phaseModelIter()->rho(); tmpRho() += phaseModelIter()*phaseModelIter().rho();
} }
return tmpRho; return tmpRho;
...@@ -242,12 +216,12 @@ Foam::tmp<Foam::volVectorField> Foam::phaseSystem::U() const ...@@ -242,12 +216,12 @@ Foam::tmp<Foam::volVectorField> Foam::phaseSystem::U() const
tmp<volVectorField> tmpU tmp<volVectorField> tmpU
( (
phaseModelIter()()*phaseModelIter()->U() phaseModelIter()*phaseModelIter().U()
); );
for (; phaseModelIter != phaseModels_.end(); ++ phaseModelIter) for (; phaseModelIter != phaseModels_.end(); ++ phaseModelIter)
{ {
tmpU() += phaseModelIter()()*phaseModelIter()->U(); tmpU() += phaseModelIter()*phaseModelIter().U();
} }
return tmpU; return tmpU;
...@@ -292,7 +266,7 @@ void Foam::phaseSystem::correct() ...@@ -292,7 +266,7 @@ void Foam::phaseSystem::correct()
{ {
forAllIter(phaseModelTable, phaseModels_, phaseModelIter) forAllIter(phaseModelTable, phaseModels_, phaseModelIter)
{ {
phaseModelIter()->correct(); phaseModelIter().correct();
} }
} }
...@@ -303,15 +277,17 @@ void Foam::phaseSystem::correctKinematics() ...@@ -303,15 +277,17 @@ void Foam::phaseSystem::correctKinematics()
forAllIter(phaseModelTable, phaseModels_, phaseModelIter) forAllIter(phaseModelTable, phaseModels_, phaseModelIter)
{ {
phaseModelIter()->correctKinematics(); phaseModelIter().correctKinematics();
updateDpdt = updateDpdt || phaseModelIter()->thermo().dpdt(); updateDpdt = updateDpdt || phaseModelIter().thermo().dpdt();
} }
//phaseModelTable::iterator iter = phaseModels_.begin();
// Update the pressure time-derivative if required // Update the pressure time-derivative if required
if (updateDpdt) if (updateDpdt)
{ {
dpdt_ = fvc::ddt(phaseModels_.begin()()().thermo().p()); dpdt_ = fvc::ddt(phaseModels_.begin()()->thermo().p());
} }
} }
...@@ -320,7 +296,7 @@ void Foam::phaseSystem::correctThermo() ...@@ -320,7 +296,7 @@ void Foam::phaseSystem::correctThermo()
{ {
forAllIter(phaseModelTable, phaseModels_, phaseModelIter) forAllIter(phaseModelTable, phaseModels_, phaseModelIter)
{ {
phaseModelIter()->correctThermo(); phaseModelIter().correctThermo();
} }
} }
...@@ -329,7 +305,7 @@ void Foam::phaseSystem::correctTurbulence() ...@@ -329,7 +305,7 @@ void Foam::phaseSystem::correctTurbulence()
{ {
forAllIter(phaseModelTable, phaseModels_, phaseModelIter) forAllIter(phaseModelTable, phaseModels_, phaseModelIter)
{ {
phaseModelIter()->correctTurbulence(); phaseModelIter().correctTurbulence();
} }
} }
...@@ -338,7 +314,7 @@ void Foam::phaseSystem::correctEnergyTransport() ...@@ -338,7 +314,7 @@ void Foam::phaseSystem::correctEnergyTransport()
{ {
forAllIter(phaseModelTable, phaseModels_, phaseModelIter) forAllIter(phaseModelTable, phaseModels_, phaseModelIter)
{ {
phaseModelIter()->correctEnergyTransport(); phaseModelIter().correctEnergyTransport();
} }
} }
...@@ -351,7 +327,7 @@ bool Foam::phaseSystem::read() ...@@ -351,7 +327,7 @@ bool Foam::phaseSystem::read()
forAllIter(phaseModelTable, phaseModels_, phaseModelIter) forAllIter(phaseModelTable, phaseModels_, phaseModelIter)
{ {
readOK &= phaseModelIter()->read(); readOK &= phaseModelIter().read();
} }
// models ... // models ...
......
...@@ -42,6 +42,7 @@ SourceFiles ...@@ -42,6 +42,7 @@ SourceFiles
#include "phasePair.H" #include "phasePair.H"
#include "orderedPhasePair.H" #include "orderedPhasePair.H"
#include "HashPtrTable.H" #include "HashPtrTable.H"
#include "PtrDictionary.H"
#include "IOMRFZoneList.H" #include "IOMRFZoneList.H"
#include "fvIOoptionList.H" #include "fvIOoptionList.H"
...@@ -117,15 +118,17 @@ public: ...@@ -117,15 +118,17 @@ public:
> >
massTransferTable; massTransferTable;
// typedef
// HashTable<autoPtr<phaseModel>, word, word::hash>
// phaseModelTable;
typedef PtrDictionary<phaseModel> phaseModelTable;
protected: protected:
// Protected typedefs // Protected typedefs
typedef
HashTable<autoPtr<phaseModel>, word, word::hash>
phaseModelTable;
typedef typedef
HashTable<dictionary, phasePairKey, phasePairKey::hash> HashTable<dictionary, phasePairKey, phasePairKey::hash>
dictTable; dictTable;
...@@ -162,9 +165,6 @@ protected: ...@@ -162,9 +165,6 @@ protected:
//- Reference to the mesh //- Reference to the mesh
const fvMesh& mesh_; const fvMesh& mesh_;
//- Phase names
wordList phaseNames_;
//- Phase models //- Phase models
phaseModelTable phaseModels_; phaseModelTable phaseModels_;
...@@ -198,16 +198,10 @@ protected: ...@@ -198,16 +198,10 @@ protected:
// Protected member functions // Protected member functions
//- Generate the phases //- Calculate and return the mixture flux
HashTable<autoPtr<phaseModel> > generatePhaseModels tmp<surfaceScalarField> calcPhi
( (
const wordList& names const phaseModelTable& phaseModels
) const;
//- Generate the mixture flux
tmp<surfaceScalarField> generatePhi
(
const HashTable<autoPtr<phaseModel> >& phaseModels
) const; ) const;
//- Generate pairs //- Generate pairs
...@@ -360,6 +354,12 @@ public: ...@@ -360,6 +354,12 @@ public:
//- Constant access the mesh //- Constant access the mesh
inline const fvMesh& mesh() const; inline const fvMesh& mesh() const;
//- Constant access the phase models
inline const phaseModelTable& phases() const;
//- Access the phase models
inline phaseModelTable& phases();
//- Constant access the mixture flux //- Constant access the mixture flux
inline const surfaceScalarField& phi() const; inline const surfaceScalarField& phi() const;
......
...@@ -31,6 +31,20 @@ inline const Foam::fvMesh& Foam::phaseSystem::mesh() const ...@@ -31,6 +31,20 @@ inline const Foam::fvMesh& Foam::phaseSystem::mesh() const
} }
inline const Foam::phaseSystem::phaseModelTable&
Foam::phaseSystem::phases() const
{
return phaseModels_;
}
inline Foam::phaseSystem::phaseModelTable&
Foam::phaseSystem::phases()
{
return phaseModels_;
}
inline const Foam::surfaceScalarField& Foam::phaseSystem::phi() const inline const Foam::surfaceScalarField& Foam::phaseSystem::phi() const
{ {
return phi_; return phi_;
......
...@@ -151,12 +151,12 @@ void Foam::phaseSystem::generatePairsAndSubModels ...@@ -151,12 +151,12 @@ void Foam::phaseSystem::generatePairsAndSubModels
HashTable<autoPtr<modelType>, phasePairKey, phasePairKey::hash> HashTable<autoPtr<modelType>, phasePairKey, phasePairKey::hash>
modelTypeTable; modelTypeTable;
forAllConstIter(wordList, phaseNames_, phaseNameIter) forAllConstIter(phaseModelTable, phaseModels_, phaseModelIter)
{ {
modelTypeTable tempModels; modelTypeTable tempModels;
generatePairsAndSubModels generatePairsAndSubModels
( (
IOobject::groupName(modelName, *phaseNameIter), IOobject::groupName(modelName, phaseModelIter().name()),
tempModels tempModels
); );
...@@ -175,7 +175,7 @@ void Foam::phaseSystem::generatePairsAndSubModels ...@@ -175,7 +175,7 @@ void Foam::phaseSystem::generatePairsAndSubModels
models[tempModelIter.key()].insert models[tempModelIter.key()].insert
( (
*phaseNameIter, phaseModelIter().name(),
*tempModelIter *tempModelIter
); );
} }
......
...@@ -72,7 +72,6 @@ setRefCell ...@@ -72,7 +72,6 @@ setRefCell
pRefValue pRefValue
); );
mesh.setFluxRequired(p_rgh.name()); mesh.setFluxRequired(p_rgh.name());
mesh.setFluxRequired(alpha1.name());
const IOMRFZoneList& MRF = fluid.MRF(); const IOMRFZoneList& MRF = fluid.MRF();
fv::IOoptionList& fvOptions = fluid.fvOptions(); fv::IOoptionList& fvOptions = fluid.fvOptions();
...@@ -57,10 +57,13 @@ Foam::twoPhaseSystem::twoPhaseSystem ...@@ -57,10 +57,13 @@ Foam::twoPhaseSystem::twoPhaseSystem
) )
: :
phaseSystem(mesh), phaseSystem(mesh),
phase1_(phaseModels_[phaseNames_[0]]()), phase1_(phaseModels_.first()),
phase2_(phaseModels_[phaseNames_[1]]()) phase2_(phaseModels_.last())
{ {
phase2_.volScalarField::operator=(scalar(1) - phase1_); phase2_.volScalarField::operator=(scalar(1) - phase1_);
volScalarField& alpha1 = phase1_;
mesh.setFluxRequired(alpha1.name());
} }
......
...@@ -2,7 +2,7 @@ ...@@ -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) 2011-2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -146,6 +146,7 @@ public: ...@@ -146,6 +146,7 @@ public:
// and annul the argument. // and annul the argument.
void transfer(DictionaryBase<IDLListType, T>&); void transfer(DictionaryBase<IDLListType, T>&);
// Member operators // Member operators
void operator=(const DictionaryBase&); void operator=(const DictionaryBase&);
......
...@@ -2,7 +2,7 @@ ...@@ -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) 2011-2013 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -73,6 +73,21 @@ public: ...@@ -73,6 +73,21 @@ public:
//- Construct from Istream //- Construct from Istream
PtrDictionary(Istream&); PtrDictionary(Istream&);
// Member operators
//- Find and return entry
const T& operator[](const word& key) const
{
return *DictionaryBase<DLPtrList<T>, T>::operator[](key);
}
//- Find and return entry
T& operator[](const word& key)
{
return *DictionaryBase<DLPtrList<T>, T>::operator[](key);
}
}; };
......
...@@ -2,7 +2,7 @@ ...@@ -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) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -203,6 +203,7 @@ public: ...@@ -203,6 +203,7 @@ public:
// and annul the argument list. // and annul the argument list.
void transfer(LList<LListBase, T>&); void transfer(LList<LListBase, T>&);
// Member operators // Member operators
void operator=(const LList<LListBase, T>&); void operator=(const LList<LListBase, T>&);
...@@ -265,6 +266,16 @@ public: ...@@ -265,6 +266,16 @@ public:
} }
}; };
inline iterator begin()
{
return LListBase::begin();
}
inline const iterator& end()
{
return static_cast<const iterator&>(LListBase::end());
}
// STL const_iterator // STL const_iterator
...@@ -313,6 +324,26 @@ public: ...@@ -313,6 +324,26 @@ public:
} }
}; };
inline const_iterator cbegin() const
{
return LListBase::cbegin();
}
inline const const_iterator& cend() const
{
return static_cast<const const_iterator&>(LListBase::cend());
}
inline const_iterator begin() const
{
return LListBase::begin();
}
inline const const_iterator& end() const
{
return static_cast<const const_iterator&>(LListBase::end());
}
// IOstream operators // IOstream operators
......
...@@ -209,6 +209,16 @@ public: ...@@ -209,6 +209,16 @@ public:
} }
}; };
inline iterator begin()
{
return LListBase::begin();
}
inline const iterator& end()
{
return static_cast<const iterator&>(LListBase::end());
}
// STL const_iterator // STL const_iterator
...@@ -256,6 +266,26 @@ public: ...@@ -256,6 +266,26 @@ public:
} }
}; };
inline const_iterator cbegin() const
{
return LListBase::cbegin();
}
inline const const_iterator& cend() const
{
return static_cast<const const_iterator&>(LListBase::cend());
}
inline const_iterator begin() const
{
return LListBase::begin();
}
inline const const_iterator& end() const
{
return static_cast<const const_iterator&>(LListBase::end());
}
// STL const_reverse_iterator // STL const_reverse_iterator
...@@ -298,6 +328,29 @@ public: ...@@ -298,6 +328,29 @@ public:
} }
}; };
inline const_reverse_iterator crbegin() const
{
return LListBase::crbegin();
}
inline const const_reverse_iterator& crend() const
{
return
static_cast<const const_reverse_iterator&>(LListBase::crend());
}
inline const_reverse_iterator rbegin() const
{
return LListBase::rbegin();
}
inline const const_reverse_iterator& rend() const
{
return
static_cast<const const_reverse_iterator&>(LListBase::rend());
}
// STL member operators // STL member operators
......
...@@ -263,6 +263,7 @@ public: ...@@ -263,6 +263,7 @@ public:
inline const_iterator begin() const; inline const_iterator begin() const;
inline const const_iterator& end() const; inline const const_iterator& end() const;
// STL const_reverse_iterator // STL const_reverse_iterator
//- An STL-conforming const_reverse_iterator //- An STL-conforming const_reverse_iterator
...@@ -300,6 +301,7 @@ public: ...@@ -300,6 +301,7 @@ public:
inline const_reverse_iterator rbegin() const; inline const_reverse_iterator rbegin() const;
inline const const_reverse_iterator& rend() const; inline const const_reverse_iterator& rend() const;
private: private:
//- Iterator returned by end() //- Iterator returned by end()
...@@ -310,7 +312,6 @@ private: ...@@ -310,7 +312,6 @@ private:
//- const_reverse_iterator returned by end() //- const_reverse_iterator returned by end()
static const_reverse_iterator endConstRevIter_; static const_reverse_iterator endConstRevIter_;
}; };
......
...@@ -2,7 +2,7 @@ ...@@ -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) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -58,12 +58,6 @@ public: ...@@ -58,12 +58,6 @@ public:
DLPtrList() DLPtrList()
{} {}
//- Construct given initial T
DLPtrList(T a)
:
LPtrList<DLListBase, T>(a)
{}
//- Construct from Istream using given Istream constructor class //- Construct from Istream using given Istream constructor class
template<class INew> template<class INew>
DLPtrList(Istream& is, const INew& inewt) DLPtrList(Istream& is, const INew& inewt)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment