ENH: improve isolation of basicThermo internals (as private)

- getThermoOrDie: returns constructor pointer, or FatalError.
  Better isolation and avoids additional template/typename previously
  needed with ambiguous method name (lookupThermo).

- makeThermoName: centralize dictionary -> stringified name

- splitThermoName: use stringOps functionality
This commit is contained in:
Mark Olesen 2021-07-14 11:12:08 +02:00
parent 9e56dd4098
commit 3416151dee
9 changed files with 468 additions and 424 deletions

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -73,6 +73,7 @@ Foam::autoPtr<CombustionModel> Foam::combustionModel::New
<< "combustion model " << combModelName << "." << endl;
}
const word compCombModelName
(
combModelName + '<' + CombustionModel::reactionThermo::typeName + '>'
@ -87,20 +88,27 @@ Foam::autoPtr<CombustionModel> Foam::combustionModel::New
const auto& cnstrTable = *(CombustionModel::dictionaryConstructorTablePtr_);
auto compCstrIter = cnstrTable.cfind(compCombModelName);
auto ctorIter = cnstrTable.cfind(thermoCombModelName);
auto thermoCstrIter = cnstrTable.cfind(thermoCombModelName);
if (!compCstrIter.found() && !thermoCstrIter.found())
if (!ctorIter.found())
{
wordList thisCmpts;
thisCmpts.append(word::null);
thisCmpts.append(CombustionModel::reactionThermo::typeName);
thisCmpts.append(basicThermo::splitThermoName(thermo.thermoName(), 5));
ctorIter = cnstrTable.cfind(compCombModelName);
}
wordList validNames;
if (!ctorIter.found())
{
const wordList names(cnstrTable.sortedToc());
List<wordList> validCmpts2;
/// DynamicList<word> thisCmpts(6);
/// thisCmpts.append(CombustionModel::reactionThermo::typeName);
/// thisCmpts.append(basicThermo::splitThermoName
/// (
/// basicThermo::splitThermoName(thermo.thermoName(), 5)
/// );
///
/// DynamicList<word> validNames;
DynamicList<wordList> validCmpts2;
validCmpts2.append
(
// Header
@ -112,7 +120,7 @@ Foam::autoPtr<CombustionModel> Foam::combustionModel::New
})
);
List<wordList> validCmpts7;
DynamicList<wordList> validCmpts7;
validCmpts7.append
(
// Header
@ -129,61 +137,56 @@ Foam::autoPtr<CombustionModel> Foam::combustionModel::New
})
);
for (const word& validName : cnstrTable.sortedToc())
for (const word& validName : names)
{
wordList cmpts(basicThermo::splitThermoName(validName, 2));
wordList cmpts(basicThermo::splitThermoName(validName, 0));
if (cmpts.size() == 2)
{
validCmpts2.append(cmpts);
validCmpts2.append(std::move(cmpts));
}
else
else if (cmpts.size() == 7)
{
cmpts = basicThermo::splitThermoName(validName, 7);
if (cmpts.size() == 7)
{
validCmpts7.append(cmpts);
/// if (thisCmpts == SubList<word>(cmpts, 6, 1))
/// {
/// validNames.append(cmpts[0]);
/// }
validCmpts7.append(std::move(cmpts));
}
}
bool isValid = true;
for (label i = 1; i < cmpts.size() && isValid; ++i)
{
isValid = isValid && cmpts[i] == thisCmpts[i];
}
if (isValid)
{
validNames.append(cmpts[0]);
}
}
FatalErrorInLookup
(
combustionModel::typeName,
combModelName,
cnstrTable
)
);
if (validCmpts2.size() > 1)
{
FatalError
<< "All " << validCmpts2[0][0] << '/' << validCmpts2[0][1]
<< " combinations are:" << nl << nl;
printTable(validCmpts2, FatalErrorInFunction)
<< nl;
printTable(validCmpts2, FatalError) << nl;
}
FatalErrorInFunction
if (validCmpts7.size() > 1)
{
FatalError
<< "All " << validCmpts7[0][0] << '/' << validCmpts7[0][1]
<< "/thermoPhysics combinations are:" << nl << nl;
printTable(validCmpts7, FatalErrorInFunction)
printTable(validCmpts7, FatalError) << nl;
}
FatalError
<< exit(FatalError);
}
return autoPtr<CombustionModel>
(
thermoCstrIter.found()
? thermoCstrIter()(combModelName, thermo, turb, combustionProperties)
: compCstrIter()(combModelName, thermo, turb, combustionProperties)
ctorIter()(combModelName, thermo, turb, combustionProperties)
);
}

View File

@ -27,6 +27,8 @@ License
\*---------------------------------------------------------------------------*/
#include "basicThermo.H"
#include "stringOps.H"
#include "wordIOList.H"
#include "zeroGradientFvPatchFields.H"
#include "fixedEnergyFvPatchScalarField.H"
#include "gradientEnergyFvPatchScalarField.H"
@ -47,6 +49,115 @@ namespace Foam
const Foam::word Foam::basicThermo::dictName("thermophysicalProperties");
const Foam::wordList Foam::basicThermo::componentHeader4
({
"type",
"mixture",
"properties",
"energy"
});
const Foam::wordList Foam::basicThermo::componentHeader7
({
"type",
"mixture",
"transport",
"thermo",
"equationOfState",
"specie",
"energy"
});
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::Ostream& Foam::basicThermo::printThermoNames
(
Ostream& os,
const wordList& cmptNames,
const wordList& thermoNames
)
{
const int nCmpt = cmptNames.size();
// Build a table of constituent parts by split name into constituent parts
// - remove incompatible entries from the list
// - note: row-0 contains the names of constituent parts (ie, the header)
DynamicList<wordList> outputTbl;
outputTbl.resize(thermoNames.size()+1);
label rowi = 0;
// Header
outputTbl[rowi] = cmptNames;
if (!outputTbl[rowi].empty())
{
++rowi;
}
for (const word& thermoName : thermoNames)
{
outputTbl[rowi] = basicThermo::splitThermoName(thermoName, nCmpt);
if (!outputTbl[rowi].empty())
{
++rowi;
}
}
if (rowi > 1)
{
outputTbl.resize(rowi);
Foam::printTable(outputTbl, os);
}
return os;
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::word Foam::basicThermo::makeThermoName
(
const dictionary& thermoTypeDict,
const wordList*& cmptHeaderPtr
)
{
if (thermoTypeDict.found("properties"))
{
if (cmptHeaderPtr)
{
cmptHeaderPtr = &(componentHeader4);
}
return word
(
thermoTypeDict.get<word>("type") + '<'
+ thermoTypeDict.get<word>("mixture") + '<'
+ thermoTypeDict.get<word>("properties") + ','
+ thermoTypeDict.get<word>("energy") + ">>"
);
}
else
{
if (cmptHeaderPtr)
{
cmptHeaderPtr = &(componentHeader7);
}
return word
(
thermoTypeDict.get<word>("type") + '<'
+ thermoTypeDict.get<word>("mixture") + '<'
+ thermoTypeDict.get<word>("transport") + '<'
+ thermoTypeDict.get<word>("thermo") + '<'
+ thermoTypeDict.get<word>("equationOfState") + '<'
+ thermoTypeDict.get<word>("specie") + ">>,"
+ thermoTypeDict.get<word>("energy") + ">>>"
);
}
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
@ -60,14 +171,17 @@ Foam::wordList Foam::basicThermo::heBoundaryBaseTypes()
{
if (isA<fixedJumpFvPatchScalarField>(tbf[patchi]))
{
const fixedJumpFvPatchScalarField& pf =
dynamic_cast<const fixedJumpFvPatchScalarField&>(tbf[patchi]);
const auto& pf =
dynamic_cast<const fixedJumpFvPatchScalarField&>
(
tbf[patchi]
);
hbt[patchi] = pf.interfaceFieldType();
}
else if (isA<fixedJumpAMIFvPatchScalarField>(tbf[patchi]))
{
const fixedJumpAMIFvPatchScalarField& pf =
const auto& pf =
dynamic_cast<const fixedJumpAMIFvPatchScalarField&>
(
tbf[patchi]
@ -345,13 +459,14 @@ const Foam::basicThermo& Foam::basicThermo::lookupThermo
forAllConstIters(thermos, iter)
{
thermo = iter.val();
if
(
&(iter()->he().internalField())
&(thermo->he().internalField())
== &(pf.internalField())
)
{
return *iter();
return *thermo;
}
}
@ -455,61 +570,30 @@ void Foam::basicThermo::validate
Foam::wordList Foam::basicThermo::splitThermoName
(
const word& thermoName,
const int nCmpt
const std::string& thermoName,
const int nExpectedCmpts
)
{
wordList cmpts(nCmpt);
// Split on ",<>" but include space for good measure.
// Splits things like
// "hePsiThermo<pureMixture<const<hConst<perfectGas<specie>>,enthalpy>>>"
string::size_type beg=0, end=0, endb=0, endc=0;
int i = 0;
const auto parsed = stringOps::splitAny<std::string>(thermoName, " ,<>");
const int nParsed(parsed.size());
while
(
(endb = thermoName.find('<', beg)) != string::npos
|| (endc = thermoName.find(',', beg)) != string::npos
)
{
if (endb == string::npos)
{
end = endc;
}
else if ((endc = thermoName.find(',', beg)) != string::npos)
{
end = std::min(endb, endc);
}
else
{
end = endb;
}
wordList cmpts;
if (beg < end)
if (!nExpectedCmpts || nParsed == nExpectedCmpts)
{
cmpts[i] = thermoName.substr(beg, end-beg);
cmpts[i++].replaceAll(">","");
cmpts.resize(nParsed);
// If the number of number of components in the name
// is greater than nCmpt return an empty list
if (i == nCmpt)
auto iter = cmpts.begin();
for (const auto& sub : parsed)
{
return wordList::null();
*iter = word(sub.str());
++iter;
}
}
beg = end + 1;
}
// If the number of number of components in the name is not equal to nCmpt
// return an empty list
if (i + 1 != nCmpt)
{
return wordList::null();
}
if (beg < thermoName.size())
{
cmpts[i] = thermoName.substr(beg, string::npos);
cmpts[i].replaceAll(">","");
}
return cmpts;
}

View File

@ -65,6 +65,55 @@ class basicThermo
:
public IOdictionary
{
// Private Data
//- Components names/order
static const wordList componentHeader4;
//- Components names/order
static const wordList componentHeader7;
// Private Member Functions
//- Construct name of thermo package from dictionary components
static word makeThermoName
(
const dictionary& dict,
const wordList*& cmptHeaderPtr
);
//- Look up field from registry or construct and store
static volScalarField& lookupOrConstruct
(
const fvMesh& mesh,
const word& fieldName,
bool& isOwner //!< Stored to registry by this instance
);
//- Generic lookup for thermodynamics package thermoTypeName
// \return constructor pointer, or FatalError
template<class Thermo, class ThermoConstructTable>
static typename ThermoConstructTable::mapped_type
getThermoOrDie
(
const dictionary& thermoTypeDict,
ThermoConstructTable& thermoTable,
const word& thermoTypeName,
const wordList& cmptNames
);
//- Generic lookup for each of the related thermodynamics packages
// \return constructor pointer, or FatalError
template<class Thermo, class ThermoConstructTable>
static typename ThermoConstructTable::mapped_type
getThermoOrDie
(
const dictionary& thermoDict,
ThermoConstructTable& thermoTable
);
protected:
// Protected Data
@ -96,14 +145,6 @@ protected:
// Protected Member Functions
//- Look up field from registry or construct and store
static volScalarField& lookupOrConstruct
(
const fvMesh& mesh,
const word& fieldName,
bool& isOwner //!< Stored to registry by this instance
);
//- Return the enthalpy/internal energy field boundary types
//- by interrogating the temperature field boundary types
wordList heBoundaryTypes();
@ -173,24 +214,6 @@ public:
// Selectors
//- Generic lookup for thermodynamics package thermoTypeName
template<class Thermo, class Table>
static typename Table::iterator lookupThermo
(
const dictionary& thermoTypeDict,
Table* tablePtr,
std::initializer_list<const char*> cmptNames,
const word& thermoTypeName
);
//- Generic lookup for each of the related thermodynamics packages
template<class Thermo, class Table>
static typename Table::iterator lookupThermo
(
const dictionary& thermoDict,
Table* tablePtr
);
//- Generic New for each of the related thermodynamics packages
template<class Thermo>
static autoPtr<Thermo> New
@ -249,6 +272,14 @@ public:
static const basicThermo& lookupThermo(const fvPatchScalarField& pf);
//- Print (filtered) table of thermo names, splits on \c " ,<>"
static Ostream& printThermoNames
(
Ostream& os,
const wordList& cmptNames,
const wordList& thermoNames
);
//- Check that the thermodynamics package is consistent
// with energy forms supported by the application
void validate
@ -287,11 +318,14 @@ public:
const word&
) const;
//- Split name of thermo package into a list of the components names
//- Split thermo package name into a list of components names
// Splits on \c " ,<>"
// \return empty list if the split name does not have the
// expected number of components (non-zero).
static wordList splitThermoName
(
const word& thermoName,
const int nCmpt
const std::string& thermoName,
const int nExpectedCmpts
);
//- Update properties

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd.
Copyright (C) 2017-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -28,166 +28,105 @@ License
#include "basicThermo.H"
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Thermo, class Table>
typename Table::iterator Foam::basicThermo::lookupThermo
template<class Thermo, class ThermoConstructTable>
typename ThermoConstructTable::mapped_type
Foam::basicThermo::getThermoOrDie
(
const dictionary& thermoTypeDict,
Table* tablePtr,
std::initializer_list<const char*> cmptNames,
const word& thermoTypeName
ThermoConstructTable& thermoTable,
const word& thermoTypeName,
const wordList& cmptNames
)
{
// Lookup the thermo package
// Table iterator, not const_iterator
auto cstrIter = tablePtr->find(thermoTypeName);
auto ctorIter = thermoTable.cfind(thermoTypeName);
// Print error message if package not found in the table
if (!cstrIter.found())
if (!ctorIter.found())
{
const int nCmpt = cmptNames.size();
// Build a table of the thermo packages constituent parts
// Note: row-0 contains the names of constituent parts
List<wordList> validCmpts(tablePtr->size()+1);
// Header (row 0)
validCmpts[0].resize(nCmpt);
std::copy(cmptNames.begin(), cmptNames.end(), validCmpts[0].begin());
// Split the thermo package names into their constituent parts
// Removing incompatible entries from the list
label rowi = 1;
for (const word& validName : tablePtr->sortedToc())
{
validCmpts[rowi] = Thermo::splitThermoName(validName, nCmpt);
if (validCmpts[rowi].size())
{
++rowi;
}
}
validCmpts.resize(rowi);
FatalIOErrorInLookup
(
thermoTypeDict,
Thermo::typeName,
word::null, // Suppress long name? Just output dictionary (above)
*tablePtr
thermoTable
);
// Table of available packages (as constituent parts)
printTable(validCmpts, FatalIOError)
<< exit(FatalIOError);
basicThermo::printThermoNames
(
FatalIOError,
cmptNames,
thermoTable.sortedToc()
) << exit(FatalIOError);
// return nullptr;
}
return cstrIter;
return ctorIter.val();
}
template<class Thermo, class Table>
typename Table::iterator Foam::basicThermo::lookupThermo
template<class Thermo, class ThermoConstructTable>
typename ThermoConstructTable::mapped_type
Foam::basicThermo::getThermoOrDie
(
const dictionary& thermoDict,
Table* tablePtr
ThermoConstructTable& thermoTable
)
{
if (thermoDict.isDict("thermoType"))
const dictionary* dictptr = thermoDict.findDict("thermoType");
if (dictptr)
{
const dictionary& thermoTypeDict = thermoDict.subDict("thermoType");
const auto& thermoTypeDict = *dictptr;
const wordList* cmptHeaderPtr = &(wordList::null());
// Thermo package name, constructed from components
const word thermoTypeName
(
basicThermo::makeThermoName(thermoTypeDict, cmptHeaderPtr)
);
Info<< "Selecting thermodynamics package " << thermoTypeDict << endl;
if (thermoTypeDict.found("properties"))
{
std::initializer_list<const char*> cmptNames
{
"type",
"mixture",
"properties",
"energy"
};
// Construct the name of the thermo package from the components
const word thermoTypeName
(
thermoTypeDict.get<word>("type") + '<'
+ thermoTypeDict.get<word>("mixture") + '<'
+ thermoTypeDict.get<word>("properties") + ','
+ thermoTypeDict.get<word>("energy") + ">>"
);
return lookupThermo<Thermo, Table>
return getThermoOrDie<Thermo, ThermoConstructTable>
(
thermoTypeDict,
tablePtr,
cmptNames,
thermoTypeName
thermoTable,
thermoTypeName,
*cmptHeaderPtr
);
}
else
{
std::initializer_list<const char*> cmptNames
{
"type",
"mixture",
"transport",
"thermo",
"equationOfState",
"specie",
"energy"
};
// Construct the name of the thermo package from the components
const word thermoTypeName
(
thermoTypeDict.get<word>("type") + '<'
+ thermoTypeDict.get<word>("mixture") + '<'
+ thermoTypeDict.get<word>("transport") + '<'
+ thermoTypeDict.get<word>("thermo") + '<'
+ thermoTypeDict.get<word>("equationOfState") + '<'
+ thermoTypeDict.get<word>("specie") + ">>,"
+ thermoTypeDict.get<word>("energy") + ">>>"
);
return lookupThermo<Thermo, Table>
(
thermoTypeDict,
tablePtr,
cmptNames,
thermoTypeName
);
}
}
else
{
const word thermoTypeName(thermoDict.get<word>("thermoType"));
Info<< "Selecting thermodynamics package " << thermoTypeName << endl;
// Table iterator, not const_iterator
auto cstrIter = tablePtr->find(thermoTypeName);
auto ctorIter = thermoTable.cfind(thermoTypeName);
if (!cstrIter.found())
if (!ctorIter.found())
{
FatalIOErrorInLookup
(
thermoDict,
Thermo::typeName,
thermoTypeName,
*tablePtr
thermoTable
) << exit(FatalIOError);
}
return cstrIter;
return ctorIter.val();
}
}
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
template<class Thermo>
Foam::autoPtr<Thermo> Foam::basicThermo::New
(
@ -208,14 +147,13 @@ Foam::autoPtr<Thermo> Foam::basicThermo::New
)
);
auto cstrIter =
lookupThermo<Thermo, typename Thermo::fvMeshConstructorTable>
auto* ctorPtr = getThermoOrDie<Thermo>
(
thermoDict,
Thermo::fvMeshConstructorTablePtr_
*(Thermo::fvMeshConstructorTablePtr_)
);
return autoPtr<Thermo>(cstrIter()(mesh, phaseName));
return autoPtr<Thermo>(ctorPtr(mesh, phaseName));
}
@ -227,14 +165,13 @@ Foam::autoPtr<Thermo> Foam::basicThermo::New
const word& phaseName
)
{
auto cstrIter =
lookupThermo<Thermo, typename Thermo::dictionaryConstructorTable>
auto* ctorPtr = getThermoOrDie<Thermo>
(
dict,
Thermo::dictionaryConstructorTablePtr_
*(Thermo::dictionaryConstructorTablePtr_)
);
return autoPtr<Thermo>(cstrIter()(mesh, dict, phaseName));
return autoPtr<Thermo>(ctorPtr(mesh, dict, phaseName));
}
@ -259,16 +196,14 @@ Foam::autoPtr<Thermo> Foam::basicThermo::New
)
);
auto cstrIter =
lookupThermo<Thermo, typename Thermo::fvMeshDictPhaseConstructorTable>
auto* ctorPtr = getThermoOrDie<Thermo>
(
thermoDict,
Thermo::fvMeshDictPhaseConstructorTablePtr_
*(Thermo::fvMeshDictPhaseConstructorTablePtr_)
);
return autoPtr<Thermo>(cstrIter()(mesh, phaseName, dictName));
return autoPtr<Thermo>(ctorPtr(mesh, phaseName, dictName));
}
// ************************************************************************* //

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -51,23 +51,26 @@ Foam::chemistryReductionMethod<CompType, ThermoType>::New
+ '<' + CompType::typeName + ',' + ThermoType::typeName() + '>'
);
auto cstrIter = dictionaryConstructorTablePtr_->cfind(methodTypeName);
const auto& cnstrTable = *(dictionaryConstructorTablePtr_);
auto cstrIter = cnstrTable.cfind(methodTypeName);
if (!cstrIter.found())
{
const wordList names(cnstrTable.sortedToc());
constexpr const int nCmpt = 7;
wordList thisCmpts;
thisCmpts.append(word::null);
thisCmpts.append(CompType::typeName);
thisCmpts.append
(
basicThermo::splitThermoName(ThermoType::typeName(), 5)
);
/// DynamicList<word> thisCmpts(6);
/// thisCmpts.append(CompType::typeName);
/// thisCmpts.append
/// (
/// basicThermo::splitThermoName(ThermoType::typeName(), 5)
/// );
///
/// DynamicList<word> validNames;
wordList validNames;
List<wordList> validCmpts;
DynamicList<wordList> validCmpts;
validCmpts.append
(
// Header
@ -83,42 +86,38 @@ Foam::chemistryReductionMethod<CompType, ThermoType>::New
})
);
for
(
const word& validName
: dictionaryConstructorTablePtr_->sortedToc()
)
for (const word& validName : names)
{
validCmpts.append
(
basicThermo::splitThermoName(validName, nCmpt)
);
const wordList& cmpts = validCmpts.last();
wordList cmpts(basicThermo::splitThermoName(validName, nCmpt));
bool isValid = true;
for (label i = 1; i < cmpts.size() && isValid; ++i)
if (!cmpts.empty())
{
isValid = isValid && cmpts[i] == thisCmpts[i];
}
if (isValid)
{
validNames.append(cmpts[0]);
/// if (thisCmpts == SubList<word>(cmpts, 6, 1))
/// {
/// validNames.append(cmpts[0]);
/// }
validCmpts.append(std::move(cmpts));
}
}
FatalErrorInLookup
(
typeName_(),
methodName,
*dictionaryConstructorTablePtr_
)
cnstrTable
);
if (validCmpts.size() > 1)
{
FatalError
<< "All " << validCmpts[0][0] << '/' << validCmpts[0][1]
<< "/thermoPhysics combinations:" << nl << nl;
// Table of available packages (as constituent parts)
printTable(validCmpts, FatalErrorInFunction)
printTable(validCmpts, FatalError) << nl;
}
FatalError
<< exit(FatalError);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -39,7 +39,7 @@ Foam::chemistryTabulationMethod<CompType, ThermoType>::New
TDACChemistryModel<CompType, ThermoType>& chemistry
)
{
const dictionary& tabulationDict(dict.subDict("tabulation"));
const dictionary& tabulationDict = dict.subDict("tabulation");
const word methodName(tabulationDict.get<word>("method"));
@ -50,21 +50,26 @@ Foam::chemistryTabulationMethod<CompType, ThermoType>::New
+ '<' + CompType::typeName + ',' + ThermoType::typeName() + '>'
);
auto cstrIter = dictionaryConstructorTablePtr_->cfind(methodTypeName);
const auto& cnstrTable = *(dictionaryConstructorTablePtr_);
auto cstrIter = cnstrTable.cfind(methodTypeName);
if (!cstrIter.found())
{
wordList thisCmpts;
thisCmpts.append(word::null);
thisCmpts.append(CompType::typeName);
thisCmpts.append
(
basicThermo::splitThermoName(ThermoType::typeName(), 5)
);
const wordList names(cnstrTable.sortedToc());
wordList validNames;
constexpr const int nCmpt = 7;
List<wordList> validCmpts;
/// DynamicList<word> thisCmpts(6);
/// thisCmpts.append(CompType::typeName);
/// thisCmpts.append
/// (
/// basicThermo::splitThermoName(ThermoType::typeName(), 5)
/// );
///
/// DynamicList<word> validNames;
DynamicList<wordList> validCmpts;
validCmpts.append
(
wordList
@ -79,27 +84,17 @@ Foam::chemistryTabulationMethod<CompType, ThermoType>::New
})
);
for
(
const word& validName
: dictionaryConstructorTablePtr_->sortedToc()
)
for (const word& validName : names)
{
validCmpts.append
(
basicThermo::splitThermoName(validName, 7)
);
const wordList& cmpts = validCmpts.last();
wordList cmpts(basicThermo::splitThermoName(validName, nCmpt));
bool isValid = true;
for (label i = 1; i < cmpts.size() && isValid; ++i)
if (!cmpts.empty())
{
isValid = isValid && cmpts[i] == thisCmpts[i];
}
if (isValid)
{
validNames.append(cmpts[0]);
/// if (thisCmpts == SubList<word>(cmpts, 6, 1))
/// {
/// validNames.append(cmpts[0]);
/// }
validCmpts.append(std::move(cmpts));
}
}
@ -108,13 +103,20 @@ Foam::chemistryTabulationMethod<CompType, ThermoType>::New
(
typeName_(),
methodName,
*dictionaryConstructorTablePtr_
)
cnstrTable
);
if (validCmpts.size() > 1)
{
FatalError
<< "All " << validCmpts[0][0] << '/' << validCmpts[0][1]
<< "/thermoPhysics combinations:" << nl << nl;
// Table of available packages (as constituent parts)
printTable(validCmpts, FatalErrorInFunction)
printTable(validCmpts, FatalError) << nl;
}
FatalError
<< exit(FatalError);
}
@ -122,7 +124,6 @@ Foam::chemistryTabulationMethod<CompType, ThermoType>::New
(
cstrIter()(dict, chemistry)
);
}

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -87,13 +87,14 @@ Foam::autoPtr<ChemistryModel> Foam::basicChemistryModel::New
)
);
{
dictionary chemistryTypeDictNew;
chemistryTypeDictNew.add("solver", solverName);
chemistryTypeDictNew.add("method", methodName);
Info<< "Selecting chemistry solver " << chemistryTypeDictNew << endl;
const auto& cnstrTable = *(ChemistryModel::thermoConstructorTablePtr_);
}
const word chemSolverCompThermoName
(
@ -102,30 +103,32 @@ Foam::autoPtr<ChemistryModel> Foam::basicChemistryModel::New
+ thermo.thermoName() + ">>"
);
auto cstrIter = cnstrTable.cfind(chemSolverCompThermoName);
if (!cstrIter.found())
const auto& cnstrTable = *(ChemistryModel::thermoConstructorTablePtr_);
auto ctorIter = cnstrTable.cfind(chemSolverCompThermoName);
if (!ctorIter.found())
{
const wordList names(cnstrTable.sortedToc());
constexpr const int nCmpt = 8;
wordList thisCmpts;
thisCmpts.append(word::null);
thisCmpts.append(word::null);
DynamicList<word> thisCmpts(6);
thisCmpts.append(ChemistryModel::reactionThermo::typeName);
thisCmpts.append
(
basicThermo::splitThermoName(thermo.thermoName(), 5)
);
List<wordList> validNames;
DynamicList<wordList> validNames;
validNames.append
(
// Header
wordList({"solver", "method"})
);
List<wordList> validCmpts;
DynamicList<wordList> validCmpts(names.size() + 1);
validCmpts.append
(
// Header
@ -142,48 +145,50 @@ Foam::autoPtr<ChemistryModel> Foam::basicChemistryModel::New
})
);
for (const word& validName : cnstrTable.sortedToc())
for (const word& validName : names)
{
validCmpts.append
(
basicThermo::splitThermoName(validName, nCmpt)
);
wordList cmpts(basicThermo::splitThermoName(validName, nCmpt));
const wordList& cmpts = validCmpts.last();
bool isValid = true;
for (label i = 2; i < cmpts.size() && isValid; ++i)
if (!cmpts.empty())
{
isValid = isValid && cmpts[i] == thisCmpts[i];
}
if (isValid)
if (thisCmpts == SubList<word>(cmpts, 6, 2))
{
validNames.append(SubList<word>(cmpts, 2));
}
validCmpts.append(std::move(cmpts));
}
}
FatalErrorInFunction
<< "Unknown " << typeName_() << " type " << solverName << nl << nl;
FatalErrorInFunction
if (validNames.size() > 1)
{
FatalError
<< "All " << validNames[0][0] << '/' << validNames[0][1]
<< "combinations for this thermodynamic model:" << nl << nl;
// Table of available packages (as constituent parts)
printTable(validNames, FatalErrorInFunction)
<< nl
<< "All " << validCmpts[0][0] << '/' << validCmpts[0][1] << '/'
<< validCmpts[0][2] << "/thermoPhysics combinations are:"
<< " combinations for this thermodynamic model:"
<< nl << nl;
// Table of available packages (as constituent parts)
printTable(validCmpts, FatalErrorInFunction)
printTable(validNames, FatalError) << nl;
}
if (validCmpts.size() > 1)
{
FatalError
<< "All " << validCmpts[0][0] << '/' << validCmpts[0][1] << '/'
<< validCmpts[0][2] << "/thermoPhysics combinations:"
<< nl << nl;
// Table of available packages (as constituent parts)
printTable(validCmpts, FatalError) << nl;
}
FatalError
<< exit(FatalError);
}
return autoPtr<ChemistryModel>(cstrIter()(thermo));
return autoPtr<ChemistryModel>(ctorIter()(thermo));
}
// ************************************************************************* //

View File

@ -32,7 +32,7 @@ Description
SourceFiles
basicSolidChemistryModelI.H
basicSolidChemistryModel.C
newChemistrySolidModel.C
basicSolidChemistryModelNew.C
\*---------------------------------------------------------------------------*/
@ -50,11 +50,11 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
// Forward Declarations
class fvMesh;
/*---------------------------------------------------------------------------*\
class basicSolidChemistryModel Declaration
Class basicSolidChemistryModel Declaration
\*---------------------------------------------------------------------------*/
class basicSolidChemistryModel
@ -72,7 +72,7 @@ class basicSolidChemistryModel
protected:
// Protected data
// Protected Data
//- Solid thermo
solidReactionThermo& solidThermo_;

View File

@ -6,7 +6,7 @@
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2013-2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd.
Copyright (C) 2019-2021 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -51,23 +51,6 @@ Foam::basicSolidChemistryModel::New(solidReactionThermo& thermo)
Info<< "Selecting chemistry type " << chemistryTypeDict << endl;
std::initializer_list<const char*> cmptNames
{
"chemistrySolver",
"chemistryThermo",
"baseChemistry",
"transport",
"thermo",
"equationOfState",
"specie",
"energy",
"transport",
"thermo",
"equationOfState",
"specie",
"energy"
};
const IOdictionary thermoDict
(
IOobject
@ -112,48 +95,48 @@ Foam::basicSolidChemistryModel::New(solidReactionThermo& thermo)
Info<< "chemistryTypeName " << chemistryTypeName << endl;
auto cstrIter = thermoConstructorTablePtr_->cfind(chemistryTypeName);
const auto& cnstrTable = *(thermoConstructorTablePtr_);
if (!cstrIter.found())
auto ctorIter = cnstrTable.cfind(chemistryTypeName);
if (!ctorIter.found())
{
const int nCmpt = cmptNames.size();
// Build a table of the thermo packages constituent parts
// Note: row-0 contains the names of constituent parts
List<wordList> validCmpts(thermoConstructorTablePtr_->size()+1);
// Header (row 0)
validCmpts[0].resize(nCmpt);
std::copy(cmptNames.begin(), cmptNames.end(), validCmpts[0].begin());
label rowi = 1;
for (const word& validName : thermoConstructorTablePtr_->sortedToc())
{
validCmpts[rowi] = basicThermo::splitThermoName(validName, nCmpt);
if (validCmpts[rowi].size())
{
++rowi;
}
}
validCmpts.resize(rowi);
FatalIOErrorInLookup
(
chemistryTypeDict,
typeName,
word::null, // Suppress long name? Just output dictionary (above)
*thermoConstructorTablePtr_
cnstrTable
);
// Table of available packages (as constituent parts)
printTable(validCmpts, FatalIOError)
basicThermo::printThermoNames
(
FatalIOError,
wordList
({
"chemistrySolver",
"chemistryThermo",
"baseChemistry",
"transport",
"thermo", // solid
"equationOfState",
"specie",
"energy",
"transport",
"thermo", // gas
"equationOfState",
"specie",
"energy"
}),
cnstrTable.sortedToc()
);
FatalIOError
<< exit(FatalIOError);
}
return
autoPtr<basicSolidChemistryModel>(cstrIter()(thermo));
return autoPtr<basicSolidChemistryModel>(ctorIter()(thermo));
}