ReactionList: Simplified and rationalised

so that it can be used as the container for the reaction system in reactingMixture.
This commit is contained in:
Henry Weller
2019-08-03 09:22:43 +01:00
parent 5acfe8b20a
commit 509133ecbb
8 changed files with 152 additions and 260 deletions

View File

@ -24,7 +24,7 @@ License
\*---------------------------------------------------------------------------*/
#include "chemkinReader.H"
#include <fstream>
#include "IFstream.H"
#include "atomicWeights.H"
#include "ReactionProxy.H"
#include "IrreversibleReaction.H"
@ -839,7 +839,6 @@ Foam::chemkinReader::chemkinReader
lineNo_(1),
specieNames_(10),
speciesTable_(species),
reactions_(speciesTable_, speciesThermo_),
newFormat_(newFormat),
imbalanceTol_(rootSmall)
{
@ -856,7 +855,6 @@ Foam::chemkinReader::chemkinReader
lineNo_(1),
specieNames_(10),
speciesTable_(species),
reactions_(speciesTable_, speciesThermo_),
newFormat_(thermoDict.lookupOrDefault("newFormat", false)),
imbalanceTol_(thermoDict.lookupOrDefault("imbalanceTolerance", rootSmall))
{

View File

@ -100,25 +100,7 @@ int main(int argc, char *argv[])
}
thermoDict.write(OFstream(args[5])(), false);
OFstream reactionsFile(args[4]);
cr.reactions().write(reactionsFile);
reactionsFile << nl;
writeEntry
(
reactionsFile,
"Tlow",
Reaction<gasHThermoPhysics>::TlowDefault
);
writeEntry
(
reactionsFile,
"Thigh",
Reaction<gasHThermoPhysics>::ThighDefault
);
cr.reactions().write(OFstream(args[4])());
Info<< "End\n" << endl;

View File

@ -28,21 +28,79 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class ThermoType>
const ThermoType& Foam::multiComponentMixture<ThermoType>::constructSpeciesData
Foam::PtrList<ThermoType>
Foam::multiComponentMixture<ThermoType>::readSpeciesData
(
const dictionary& thermoDict
)
) const
{
PtrList<ThermoType> speciesData(species_.size());
forAll(species_, i)
{
speciesData_.set
speciesData.set
(
i,
new ThermoType(thermoDict.subDict(species_[i]))
);
}
return speciesData_[0];
return speciesData;
}
template<class ThermoType>
typename Foam::multiComponentMixture<ThermoType>::speciesCompositionTable
Foam::multiComponentMixture<ThermoType>::readSpeciesComposition
(
const dictionary& thermoDict,
const speciesTable& species
) const
{
speciesCompositionTable speciesComposition_;
// Loop through all species in thermoDict to retrieve
// the species composition
forAll(species, si)
{
if (thermoDict.subDict(species[si]).isDict("elements"))
{
dictionary currentElements
(
thermoDict.subDict(species[si]).subDict("elements")
);
wordList currentElementsName(currentElements.toc());
List<specieElement> currentComposition(currentElementsName.size());
forAll(currentElementsName, eni)
{
currentComposition[eni].name() = currentElementsName[eni];
currentComposition[eni].nAtoms() =
currentElements.lookupOrDefault
(
currentElementsName[eni],
0
);
}
// Add current specie composition to the hash table
speciesCompositionTable::iterator specieCompositionIter
(
speciesComposition_.find(species[si])
);
if (specieCompositionIter != speciesComposition_.end())
{
speciesComposition_.erase(specieCompositionIter);
}
speciesComposition_.insert(species[si], currentComposition);
}
}
return speciesComposition_;
}
@ -88,8 +146,9 @@ Foam::multiComponentMixture<ThermoType>::multiComponentMixture
mesh,
phaseName
),
speciesData_(species_.size()),
mixture_("mixture", constructSpeciesData(thermoDict)),
speciesData_(readSpeciesData(thermoDict)),
speciesComposition_(readSpeciesComposition(thermoDict, species())),
mixture_("mixture", speciesData_[0]),
mixtureVol_("volMixture", speciesData_[0])
{
correctMassFractions();

View File

@ -37,6 +37,7 @@ SourceFiles
#include "basicSpecieMixture.H"
#include "HashPtrTable.H"
#include "specieElement.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -57,6 +58,11 @@ class multiComponentMixture
//- Species data
PtrList<ThermoType> speciesData_;
typedef HashTable<List<specieElement>> speciesCompositionTable;
//- Table of species composition
speciesCompositionTable speciesComposition_;
//- Temporary storage for the cell/face mixture thermo data
mutable ThermoType mixture_;
@ -67,16 +73,19 @@ class multiComponentMixture
// Private Member Functions
//- Construct the species data from the given dictionary and return the
// data for the first specie to initialise the mixture thermo data
const ThermoType& constructSpeciesData(const dictionary& thermoDict);
//- Read the species data from the given dictionary and return
PtrList<ThermoType> readSpeciesData(const dictionary& thermoDict) const;
//- Read the species composition from the given dictionary and return
speciesCompositionTable readSpeciesComposition
(
const dictionary& thermoDict,
const speciesTable& speciesTable_
) const;
//- Correct the mass fractions to sum to 1
void correctMassFractions();
//- Construct as copy (not implemented)
multiComponentMixture(const multiComponentMixture<ThermoType>&);
public:
@ -89,6 +98,12 @@ public:
//- Construct from dictionary, mesh and phase name
multiComponentMixture(const dictionary&, const fvMesh&, const word&);
//- Disallow default bitwise copy construction
multiComponentMixture
(
const multiComponentMixture<ThermoType>&
) = delete;
//- Destructor
virtual ~multiComponentMixture()
@ -103,6 +118,18 @@ public:
return "multiComponentMixture<" + ThermoType::typeName() + '>';
}
//- Return the raw specie thermodynamic data
const PtrList<ThermoType>& speciesData() const
{
return speciesData_;
}
//- Return the table of species composition
const speciesCompositionTable& specieComposition() const
{
return speciesComposition_;
}
const ThermoType& cellMixture(const label celli) const;
const ThermoType& patchFaceMixture
@ -126,12 +153,6 @@ public:
const label facei
) const;
//- Return the raw specie thermodynamic data
const PtrList<ThermoType>& speciesData() const
{
return speciesData_;
}
//- Read dictionary
void read(const dictionary&);

View File

@ -26,63 +26,6 @@ License
#include "reactingMixture.H"
#include "fvMesh.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class ThermoType>
Foam::speciesCompositionTable
Foam::reactingMixture<ThermoType>::readSpeciesComposition
(
const dictionary& thermoDict,
const speciesTable& species
) const
{
speciesCompositionTable speciesComposition_;
// Loop through all species in thermoDict to retrieve
// the species composition
forAll(species, si)
{
if (thermoDict.subDict(species[si]).isDict("elements"))
{
dictionary currentElements
(
thermoDict.subDict(species[si]).subDict("elements")
);
wordList currentElementsName(currentElements.toc());
List<specieElement> currentComposition(currentElementsName.size());
forAll(currentElementsName, eni)
{
currentComposition[eni].name() = currentElementsName[eni];
currentComposition[eni].nAtoms() =
currentElements.lookupOrDefault
(
currentElementsName[eni],
0
);
}
// Add current specie composition to the hash table
speciesCompositionTable::iterator specieCompositionIter
(
speciesComposition_.find(species[si])
);
if (specieCompositionIter != speciesComposition_.end())
{
speciesComposition_.erase(specieCompositionIter);
}
speciesComposition_.insert(species[si], currentComposition);
}
}
return speciesComposition_;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ThermoType>
@ -99,36 +42,7 @@ Foam::reactingMixture<ThermoType>::reactingMixture
mesh,
phaseName
),
speciesComposition_(readSpeciesComposition(thermoDict, this->species()))
{
HashPtrTable<ThermoType> thermoDatabase;
const PtrList<ThermoType>& speciesData = this->speciesData();
forAll(speciesData, i)
{
thermoDatabase.insert
(
speciesData[i].name(),
speciesData[i].clone().ptr()
);
}
reactions_ = PtrList<Reaction<ThermoType>>
(
ReactionList<ThermoType>
(
this->species(),
thermoDatabase,
thermoDict
)
);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ThermoType>
void Foam::reactingMixture<ThermoType>::read(const dictionary& thermoDict)
reactions_(thermoDict, this->species(), this->speciesData())
{}

View File

@ -37,15 +37,12 @@ SourceFiles
#include "multiComponentMixture.H"
#include "ReactionList.H"
#include "specieElement.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef HashTable<List<specieElement>> speciesCompositionTable;
/*---------------------------------------------------------------------------*\
Class reactingMixture Declaration
\*---------------------------------------------------------------------------*/
@ -57,24 +54,11 @@ class reactingMixture
{
// Private member data
//- Table of species composition
speciesCompositionTable speciesComposition_;
PtrList<Reaction<ThermoType>> reactions_;
speciesCompositionTable readSpeciesComposition
(
const dictionary& thermoDict,
const speciesTable& speciesTable_
) const;
ReactionList<ThermoType> reactions_;
public:
//- The type of thermo package this mixture is instantiated for
typedef ThermoType thermoType;
// Constructors
//- Construct from dictionary, mesh and phase name
@ -97,20 +81,11 @@ public:
return "reactingMixture<" + ThermoType::typeName() + '>';
}
//- Read dictionary
void read(const dictionary&);
const PtrList<Reaction<ThermoType>>& reactions() const
{
return reactions_;
}
//- Table of species composition
const speciesCompositionTable& specieComposition() const
{
return speciesComposition_;
}
// Member Operators

View File

@ -24,109 +24,84 @@ License
\*---------------------------------------------------------------------------*/
#include "ReactionList.H"
#include "IFstream.H"
#include "SLPtrList.H"
#include "HashPtrTable.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class ThermoType>
Foam::ReactionList<ThermoType>::ReactionList
(
const dictionary& dict,
const speciesTable& species,
const HashPtrTable<ThermoType>& thermoDb
const PtrList<ThermoType>& speciesThermo
)
:
SLPtrList<Reaction<ThermoType>>(),
species_(species),
thermoDb_(thermoDb),
dict_(dictionary::null)
{}
template<class ThermoType>
Foam::ReactionList<ThermoType>::ReactionList
(
const speciesTable& species,
const HashPtrTable<ThermoType>& thermoDb,
const dictionary& dict
)
:
SLPtrList<Reaction<ThermoType>>(),
species_(species),
thermoDb_(thermoDb),
dict_(dict)
{
readReactionDict();
}
template<class ThermoType>
Foam::ReactionList<ThermoType>::ReactionList(const ReactionList& reactions)
:
SLPtrList<Reaction<ThermoType>>(reactions),
species_(reactions.species_),
thermoDb_(reactions.thermoDb_),
dict_(reactions.dict_)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class ThermoType>
Foam::ReactionList<ThermoType>::~ReactionList()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ThermoType>
bool Foam::ReactionList<ThermoType>::readReactionDict()
{
const dictionary& reactions(dict_.subDict("reactions"));
// Set general temperature limits from the dictionary
Reaction<ThermoType>::TlowDefault =
dict_.lookupOrDefault<scalar>("Tlow", 0);
dict.lookupOrDefault<scalar>("Tlow", 0);
Reaction<ThermoType>::ThighDefault =
dict_.lookupOrDefault<scalar>("Thigh", great);
dict.lookupOrDefault<scalar>("Thigh", great);
forAllConstIter(dictionary, reactions, iter)
const dictionary& reactions(dict.subDict("reactions"));
HashPtrTable<ThermoType> thermoDatabase;
forAll(speciesThermo, i)
{
const word reactionName = iter().keyword();
this->append
thermoDatabase.insert
(
Reaction<ThermoType>::New
(
species_,
thermoDb_,
reactions.subDict(reactionName)
).ptr()
speciesThermo[i].name(),
speciesThermo[i].clone().ptr()
);
}
return true;
this->setSize(reactions.size());
label i = 0;
forAllConstIter(dictionary, reactions, iter)
{
this->set
(
i++,
Reaction<ThermoType>::New
(
species,
thermoDatabase,
reactions.subDict(iter().keyword())
).ptr()
);
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class ThermoType>
void Foam::ReactionList<ThermoType>::write(Ostream& os) const
{
os << "reactions" << nl;
os << token::BEGIN_BLOCK << incrIndent << nl;
forAllConstIter(typename SLPtrList<Reaction<ThermoType>>, *this, iter)
forAll(*this, i)
{
const Reaction<ThermoType>& r = iter();
const Reaction<ThermoType>& r = this->operator[](i);
os << indent << r.name() << nl
<< indent << token::BEGIN_BLOCK << incrIndent << nl;
writeEntry(os, "type", r.type());
r.write(os);
os << decrIndent << indent << token::END_BLOCK << nl;
}
os << decrIndent << token::END_BLOCK << nl;
writeEntry(os, "Tlow", Reaction<ThermoType>::TlowDefault);
writeEntry(os, "Thigh", Reaction<ThermoType>::ThighDefault);
os << nl;
}

View File

@ -35,12 +35,9 @@ SourceFiles
#ifndef ReactionList_H
#define ReactionList_H
#include "PtrList.H"
#include "SLPtrList.H"
#include "speciesTable.H"
#include "HashPtrTable.H"
#include "Reaction.H"
#include "fileName.H"
#include "speciesTable.H"
#include "PtrList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -54,60 +51,31 @@ namespace Foam
template<class ThermoType>
class ReactionList
:
public SLPtrList<Reaction<ThermoType>>
public PtrList<Reaction<ThermoType>>
{
// Private Data
//- Reference to the table of species
const speciesTable& species_;
//- Reference to the thermo database
const HashPtrTable<ThermoType>& thermoDb_;
//- The dictionary used for construction
const dictionary dict_;
public:
// Constructors
//- Construct null
ReactionList
(
const speciesTable& species,
const HashPtrTable<ThermoType>& thermoDatabase
);
//- Construct from thermoDatabase and dictionary
ReactionList
(
const speciesTable& species,
const HashPtrTable<ThermoType>& thermoDatabase,
const dictionary& dict
);
//- Construct empty
ReactionList()
{}
//- Construct from thermo list and dictionary
ReactionList
(
const dictionary& dict,
const speciesTable& species,
const PtrList<ThermoType>& thermoDatabase,
const dictionary& dict
const PtrList<ThermoType>& thermoDatabase
);
//- Construct copy
ReactionList(const ReactionList<ThermoType>& reactions);
//- Destructor
~ReactionList();
ReactionList(const ReactionList<ThermoType>& reactions) = delete;
// Public Member Functions
//- Read reactions from dictionary
bool readReactionDict();
//- Write
void write(Ostream& os) const;