[Kinetics] Update factory constructors

This commit is contained in:
Ingmar Schoegl 2023-03-02 12:08:18 -06:00
parent 125a440b9c
commit 604f9dfcbc
4 changed files with 71 additions and 13 deletions

View File

@ -59,7 +59,14 @@ shared_ptr<Kinetics> newKinetics(const string& model);
* @param rootNode The root node of the file containing the phase definition,
* which will be treated as the default source for reactions
*/
shared_ptr<Kinetics> newKinetics(const std::vector<ThermoPhase*>& phases,
shared_ptr<Kinetics> newKinetics(const vector<shared_ptr<ThermoPhase>>& phases,
const AnyMap& phaseNode,
const AnyMap& rootNode=AnyMap());
//! @copydoc KineticsFactory::newKinetics(const vector<shared_ptr<ThermoPhase>>&, const AnyMap&, const AnyMap&)
//! @deprecated To be removed after Cantera 3.0;
//! superseded by newKinetics() returning shared_ptr
unique_ptr<Kinetics> newKinetics(const std::vector<ThermoPhase*>& phases,
const AnyMap& phaseNode,
const AnyMap& rootNode=AnyMap());
@ -74,7 +81,14 @@ shared_ptr<Kinetics> newKinetics(const std::vector<ThermoPhase*>& phases,
* @param phase_name The name of the reacting phase in the input file (that is, the
* name of the first phase in the `phases` vector)
*/
shared_ptr<Kinetics> newKinetics(const std::vector<ThermoPhase*>& phases,
shared_ptr<Kinetics> newKinetics(const vector<shared_ptr<ThermoPhase>>& phases,
const string& filename,
const string& phase_name);
//! @copydoc KineticsFactory::newKinetics(const vector<shared_ptr<ThermoPhase>>&, const string&, const string&)
//! @deprecated To be removed after Cantera 3.0;
//! superseded by newKinetics() returning shared_ptr
unique_ptr<Kinetics> newKinetics(const std::vector<ThermoPhase*>& phases,
const std::string& filename,
const std::string& phase_name);

View File

@ -300,10 +300,10 @@ shared_ptr<Solution> newSolution(const AnyMap& phaseNode,
}
// kinetics
std::vector<ThermoPhase*> phases;
phases.push_back(sol->thermo().get());
vector<shared_ptr<ThermoPhase>> phases;
phases.push_back(sol->thermo());
for (size_t i = 0; i < sol->nAdjacent(); i++) {
phases.push_back(sol->adjacent(i)->thermo().get());
phases.push_back(sol->adjacent(i)->thermo());
}
sol->setKinetics(newKinetics(phases, phaseNode, rootNode));

View File

@ -1013,16 +1013,16 @@ extern "C" {
int neighbor3, int neighbor4)
{
try {
vector<ThermoPhase*> phases;
phases.push_back(ThermoCabinet::at(reactingPhase).get());
vector<shared_ptr<ThermoPhase>> phases;
phases.push_back(ThermoCabinet::at(reactingPhase));
if (neighbor1 >= 0) {
phases.push_back(ThermoCabinet::at(neighbor1).get());
phases.push_back(ThermoCabinet::at(neighbor1));
if (neighbor2 >= 0) {
phases.push_back(ThermoCabinet::at(neighbor2).get());
phases.push_back(ThermoCabinet::at(neighbor2));
if (neighbor3 >= 0) {
phases.push_back(ThermoCabinet::at(neighbor3).get());
phases.push_back(ThermoCabinet::at(neighbor3));
if (neighbor4 >= 0) {
phases.push_back(ThermoCabinet::at(neighbor4).get());
phases.push_back(ThermoCabinet::at(neighbor4));
}
}
}

View File

@ -67,7 +67,7 @@ shared_ptr<Kinetics> newKinetics(const string& model)
return kin;
}
shared_ptr<Kinetics> newKinetics(const vector<ThermoPhase*>& phases,
shared_ptr<Kinetics> newKinetics(const vector<shared_ptr<ThermoPhase>>& phases,
const AnyMap& phaseNode,
const AnyMap& rootNode)
{
@ -96,10 +96,54 @@ shared_ptr<Kinetics> newKinetics(const vector<ThermoPhase*>& phases,
return kin;
}
shared_ptr<Kinetics> newKinetics(const std::vector<ThermoPhase*>& phases,
unique_ptr<Kinetics> newKinetics(const vector<ThermoPhase*>& phases,
const AnyMap& phaseNode,
const AnyMap& rootNode)
{
warn_deprecated("newKinetics",
"To be removed after Cantera 3.0; superseded by\nnewKinetics"
"(const vector<shared_ptr<ThermoPhase>>&, const AnyMap&, const AnyMap&).");
std::string kinType = phaseNode.getString("kinetics", "none");
kinType = KineticsFactory::factory()->canonicalize(kinType);
if (kinType == "none") {
// determine phase with minimum number of dimensions
size_t nDim = 3;
for (auto& phase : phases) {
nDim = std::min(phase->nDim(), nDim);
}
// change kinetics type as necessary
if (nDim == 2) {
kinType = "surface";
} else if (nDim == 1) {
kinType = "edge";
}
}
unique_ptr<Kinetics> kin(KineticsFactory::factory()->newKinetics(kinType));
for (auto& phase : phases) {
kin->addPhase(*phase);
}
kin->init();
addReactions(*kin, phaseNode, rootNode);
return kin;
}
shared_ptr<Kinetics> newKinetics(const vector<shared_ptr<ThermoPhase>>& phases,
const string& filename,
const string& phase_name)
{
AnyMap root = AnyMap::fromYamlFile(filename);
AnyMap& phaseNode = root["phases"].getMapWhere("name", phase_name);
return newKinetics(phases, phaseNode, root);
}
unique_ptr<Kinetics> newKinetics(const std::vector<ThermoPhase*>& phases,
const std::string& filename,
const std::string& phase_name)
{
warn_deprecated("newKinetics",
"To be removed after Cantera 3.0; superseded by\nnewKinetics"
"(const vector<shared_ptr<ThermoPhase>>&, const string&, const string&).");
AnyMap root = AnyMap::fromYamlFile(filename);
AnyMap& phaseNode = root["phases"].getMapWhere("name", phase_name);
return newKinetics(phases, phaseNode, root);