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

View File

@ -27,6 +27,8 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "basicThermo.H" #include "basicThermo.H"
#include "stringOps.H"
#include "wordIOList.H"
#include "zeroGradientFvPatchFields.H" #include "zeroGradientFvPatchFields.H"
#include "fixedEnergyFvPatchScalarField.H" #include "fixedEnergyFvPatchScalarField.H"
#include "gradientEnergyFvPatchScalarField.H" #include "gradientEnergyFvPatchScalarField.H"
@ -47,6 +49,115 @@ namespace Foam
const Foam::word Foam::basicThermo::dictName("thermophysicalProperties"); 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 * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
@ -60,14 +171,17 @@ Foam::wordList Foam::basicThermo::heBoundaryBaseTypes()
{ {
if (isA<fixedJumpFvPatchScalarField>(tbf[patchi])) if (isA<fixedJumpFvPatchScalarField>(tbf[patchi]))
{ {
const fixedJumpFvPatchScalarField& pf = const auto& pf =
dynamic_cast<const fixedJumpFvPatchScalarField&>(tbf[patchi]); dynamic_cast<const fixedJumpFvPatchScalarField&>
(
tbf[patchi]
);
hbt[patchi] = pf.interfaceFieldType(); hbt[patchi] = pf.interfaceFieldType();
} }
else if (isA<fixedJumpAMIFvPatchScalarField>(tbf[patchi])) else if (isA<fixedJumpAMIFvPatchScalarField>(tbf[patchi]))
{ {
const fixedJumpAMIFvPatchScalarField& pf = const auto& pf =
dynamic_cast<const fixedJumpAMIFvPatchScalarField&> dynamic_cast<const fixedJumpAMIFvPatchScalarField&>
( (
tbf[patchi] tbf[patchi]
@ -345,13 +459,14 @@ const Foam::basicThermo& Foam::basicThermo::lookupThermo
forAllConstIters(thermos, iter) forAllConstIters(thermos, iter)
{ {
thermo = iter.val();
if if
( (
&(iter()->he().internalField()) &(thermo->he().internalField())
== &(pf.internalField()) == &(pf.internalField())
) )
{ {
return *iter(); return *thermo;
} }
} }
@ -455,61 +570,30 @@ void Foam::basicThermo::validate
Foam::wordList Foam::basicThermo::splitThermoName Foam::wordList Foam::basicThermo::splitThermoName
( (
const word& thermoName, const std::string& thermoName,
const int nCmpt 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; const auto parsed = stringOps::splitAny<std::string>(thermoName, " ,<>");
int i = 0; const int nParsed(parsed.size());
while wordList cmpts;
(
(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;
}
if (beg < end) if (!nExpectedCmpts || nParsed == nExpectedCmpts)
{ {
cmpts[i] = thermoName.substr(beg, end-beg); cmpts.resize(nParsed);
cmpts[i++].replaceAll(">","");
// If the number of number of components in the name auto iter = cmpts.begin();
// is greater than nCmpt return an empty list for (const auto& sub : parsed)
if (i == nCmpt)
{ {
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; return cmpts;
} }

View File

@ -65,6 +65,55 @@ class basicThermo
: :
public IOdictionary 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:
// Protected Data // Protected Data
@ -96,14 +145,6 @@ protected:
// Protected Member Functions // 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 //- Return the enthalpy/internal energy field boundary types
//- by interrogating the temperature field boundary types //- by interrogating the temperature field boundary types
wordList heBoundaryTypes(); wordList heBoundaryTypes();
@ -173,24 +214,6 @@ public:
// Selectors // 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 //- Generic New for each of the related thermodynamics packages
template<class Thermo> template<class Thermo>
static autoPtr<Thermo> New static autoPtr<Thermo> New
@ -249,6 +272,14 @@ public:
static const basicThermo& lookupThermo(const fvPatchScalarField& pf); 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 //- Check that the thermodynamics package is consistent
// with energy forms supported by the application // with energy forms supported by the application
void validate void validate
@ -287,11 +318,14 @@ public:
const word& const word&
) const; ) 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 static wordList splitThermoName
( (
const word& thermoName, const std::string& thermoName,
const int nCmpt const int nExpectedCmpts
); );
//- Update properties //- Update properties

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2012-2017 OpenFOAM Foundation Copyright (C) 2012-2017 OpenFOAM Foundation
Copyright (C) 2017-2019 OpenCFD Ltd. Copyright (C) 2017-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -28,166 +28,105 @@ License
#include "basicThermo.H" #include "basicThermo.H"
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Thermo, class Table> template<class Thermo, class ThermoConstructTable>
typename Table::iterator Foam::basicThermo::lookupThermo typename ThermoConstructTable::mapped_type
Foam::basicThermo::getThermoOrDie
( (
const dictionary& thermoTypeDict, const dictionary& thermoTypeDict,
Table* tablePtr, ThermoConstructTable& thermoTable,
std::initializer_list<const char*> cmptNames, const word& thermoTypeName,
const word& thermoTypeName const wordList& cmptNames
) )
{ {
// Lookup the thermo package // Lookup the thermo package
// Table iterator, not const_iterator auto ctorIter = thermoTable.cfind(thermoTypeName);
auto cstrIter = tablePtr->find(thermoTypeName);
// Print error message if package not found in the table // 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 FatalIOErrorInLookup
( (
thermoTypeDict, thermoTypeDict,
Thermo::typeName, Thermo::typeName,
word::null, // Suppress long name? Just output dictionary (above) word::null, // Suppress long name? Just output dictionary (above)
*tablePtr thermoTable
); );
// Table of available packages (as constituent parts) basicThermo::printThermoNames
printTable(validCmpts, FatalIOError) (
<< exit(FatalIOError); FatalIOError,
cmptNames,
thermoTable.sortedToc()
) << exit(FatalIOError);
// return nullptr;
} }
return cstrIter; return ctorIter.val();
} }
template<class Thermo, class Table> template<class Thermo, class ThermoConstructTable>
typename Table::iterator Foam::basicThermo::lookupThermo typename ThermoConstructTable::mapped_type
Foam::basicThermo::getThermoOrDie
( (
const dictionary& thermoDict, 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; Info<< "Selecting thermodynamics package " << thermoTypeDict << endl;
if (thermoTypeDict.found("properties")) return getThermoOrDie<Thermo, ThermoConstructTable>
{
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>
( (
thermoTypeDict, thermoTypeDict,
tablePtr, thermoTable,
cmptNames, thermoTypeName,
thermoTypeName *cmptHeaderPtr
); );
} }
else 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")); const word thermoTypeName(thermoDict.get<word>("thermoType"));
Info<< "Selecting thermodynamics package " << thermoTypeName << endl; Info<< "Selecting thermodynamics package " << thermoTypeName << endl;
// Table iterator, not const_iterator auto ctorIter = thermoTable.cfind(thermoTypeName);
auto cstrIter = tablePtr->find(thermoTypeName);
if (!cstrIter.found()) if (!ctorIter.found())
{ {
FatalIOErrorInLookup FatalIOErrorInLookup
( (
thermoDict, thermoDict,
Thermo::typeName, Thermo::typeName,
thermoTypeName, thermoTypeName,
*tablePtr thermoTable
) << exit(FatalIOError); ) << exit(FatalIOError);
} }
return cstrIter; return ctorIter.val();
} }
} }
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
template<class Thermo> template<class Thermo>
Foam::autoPtr<Thermo> Foam::basicThermo::New Foam::autoPtr<Thermo> Foam::basicThermo::New
( (
@ -208,14 +147,13 @@ Foam::autoPtr<Thermo> Foam::basicThermo::New
) )
); );
auto cstrIter = auto* ctorPtr = getThermoOrDie<Thermo>
lookupThermo<Thermo, typename Thermo::fvMeshConstructorTable>
( (
thermoDict, 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 const word& phaseName
) )
{ {
auto cstrIter = auto* ctorPtr = getThermoOrDie<Thermo>
lookupThermo<Thermo, typename Thermo::dictionaryConstructorTable>
( (
dict, 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 = auto* ctorPtr = getThermoOrDie<Thermo>
lookupThermo<Thermo, typename Thermo::fvMeshDictPhaseConstructorTable>
( (
thermoDict, 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 | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenFOAM Foundation Copyright (C) 2016-2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -51,23 +51,26 @@ Foam::chemistryReductionMethod<CompType, ThermoType>::New
+ '<' + CompType::typeName + ',' + ThermoType::typeName() + '>' + '<' + CompType::typeName + ',' + ThermoType::typeName() + '>'
); );
auto cstrIter = dictionaryConstructorTablePtr_->cfind(methodTypeName); const auto& cnstrTable = *(dictionaryConstructorTablePtr_);
auto cstrIter = cnstrTable.cfind(methodTypeName);
if (!cstrIter.found()) if (!cstrIter.found())
{ {
const wordList names(cnstrTable.sortedToc());
constexpr const int nCmpt = 7; constexpr const int nCmpt = 7;
wordList thisCmpts; /// DynamicList<word> thisCmpts(6);
thisCmpts.append(word::null); /// thisCmpts.append(CompType::typeName);
thisCmpts.append(CompType::typeName); /// thisCmpts.append
thisCmpts.append /// (
( /// basicThermo::splitThermoName(ThermoType::typeName(), 5)
basicThermo::splitThermoName(ThermoType::typeName(), 5) /// );
); ///
/// DynamicList<word> validNames;
wordList validNames; DynamicList<wordList> validCmpts;
List<wordList> validCmpts;
validCmpts.append validCmpts.append
( (
// Header // Header
@ -83,42 +86,38 @@ Foam::chemistryReductionMethod<CompType, ThermoType>::New
}) })
); );
for for (const word& validName : names)
(
const word& validName
: dictionaryConstructorTablePtr_->sortedToc()
)
{ {
validCmpts.append wordList cmpts(basicThermo::splitThermoName(validName, nCmpt));
(
basicThermo::splitThermoName(validName, nCmpt)
);
const wordList& cmpts = validCmpts.last();
bool isValid = true; if (!cmpts.empty())
for (label i = 1; i < cmpts.size() && isValid; ++i)
{ {
isValid = isValid && cmpts[i] == thisCmpts[i]; /// if (thisCmpts == SubList<word>(cmpts, 6, 1))
} /// {
/// validNames.append(cmpts[0]);
if (isValid) /// }
{ validCmpts.append(std::move(cmpts));
validNames.append(cmpts[0]);
} }
} }
FatalErrorInLookup FatalErrorInLookup
( (
typeName_(), typeName_(),
methodName, methodName,
*dictionaryConstructorTablePtr_ cnstrTable
) );
if (validCmpts.size() > 1)
{
FatalError
<< "All " << validCmpts[0][0] << '/' << validCmpts[0][1] << "All " << validCmpts[0][0] << '/' << validCmpts[0][1]
<< "/thermoPhysics combinations:" << nl << nl; << "/thermoPhysics combinations:" << nl << nl;
// Table of available packages (as constituent parts) // Table of available packages (as constituent parts)
printTable(validCmpts, FatalErrorInFunction) printTable(validCmpts, FatalError) << nl;
}
FatalError
<< exit(FatalError); << exit(FatalError);
} }

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2013-2017 OpenFOAM Foundation Copyright (C) 2013-2017 OpenFOAM Foundation
Copyright (C) 2019 OpenCFD Ltd. Copyright (C) 2019-2021 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -51,23 +51,6 @@ Foam::basicSolidChemistryModel::New(solidReactionThermo& thermo)
Info<< "Selecting chemistry type " << chemistryTypeDict << endl; 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 const IOdictionary thermoDict
( (
IOobject IOobject
@ -112,48 +95,48 @@ Foam::basicSolidChemistryModel::New(solidReactionThermo& thermo)
Info<< "chemistryTypeName " << chemistryTypeName << endl; 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 FatalIOErrorInLookup
( (
chemistryTypeDict, chemistryTypeDict,
typeName, typeName,
word::null, // Suppress long name? Just output dictionary (above) word::null, // Suppress long name? Just output dictionary (above)
*thermoConstructorTablePtr_ cnstrTable
); );
// Table of available packages (as constituent parts) // 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); << exit(FatalIOError);
} }
return return autoPtr<basicSolidChemistryModel>(ctorIter()(thermo));
autoPtr<basicSolidChemistryModel>(cstrIter()(thermo));
} }