Skip to content

Commit f3e840d

Browse files
committed
[Thermo] Add factory methods returning shared_ptr
1 parent 25b3ce3 commit f3e840d

File tree

8 files changed

+64
-24
lines changed

8 files changed

+64
-24
lines changed

include/cantera/base/Interface.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Interface : public Solution
5252

5353
//! Create and initialize a new Interface from an input file
5454
/*!
55-
* This constructor wraps newPhase() and newKinetics()
55+
* This constructor wraps newThermoPhase() and newKinetics()
5656
*
5757
* @param infile name of the input file
5858
* @param name name of the surface phase in the file.
@@ -68,7 +68,7 @@ shared_ptr<Interface> newInterface(const std::string& infile,
6868

6969
//! Create and initialize a new Interface from an input file
7070
/*!
71-
* This constructor wraps newPhase() and newKinetics()
71+
* This constructor wraps newThermoPhase() and newKinetics()
7272
*
7373
* @param infile name of the input file
7474
* @param name name of the phase in the file. If this is the empty string, the first
@@ -82,7 +82,7 @@ shared_ptr<Interface> newInterface(const std::string& infile,
8282

8383
//! Create and initialize a new Interface from AnyMap objects
8484
/*!
85-
* This constructor wraps newPhase() and newKinetics()
85+
* This constructor wraps newThermoPhase() and newKinetics()
8686
*
8787
* @param phaseNode the node containing the phase definition (that is, thermo model,
8888
* list of species, and initial state)

include/cantera/base/Solution.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class Solution : public std::enable_shared_from_this<Solution>
148148

149149
//! Create and initialize a new Solution from an input file
150150
/*!
151-
* This constructor wraps newPhase(), newKinetics() and newTransport() routines
151+
* This constructor wraps newThermoPhase(), newKinetics() and newTransport() routines
152152
* for initialization.
153153
*
154154
* @param infile name of the input file
@@ -166,8 +166,8 @@ shared_ptr<Solution> newSolution(const std::string& infile, const std::string& n
166166

167167
//! Create and initialize a new Solution manager from an input file
168168
/*!
169-
* This constructor wraps newPhase(), newKinetics() and newTransport() routines for
170-
* initialization.
169+
* This constructor wraps newThermoPhase(), newKinetics() and newTransport() routines
170+
* for initialization.
171171
*
172172
* @param infile name of the input file
173173
* @param name name of the phase in the file.
@@ -184,8 +184,8 @@ shared_ptr<Solution> newSolution(const std::string& infile,
184184

185185
//! Create and initialize a new Solution manager from AnyMap objects
186186
/*!
187-
* This constructor wraps newPhase(), newKinetics() and newTransport() routines for
188-
* initialization.
187+
* This constructor wraps newThermoPhase(), newKinetics() and newTransport() routines
188+
* for initialization.
189189
*
190190
* @param phaseNode the node containing the phase definition (that is, thermo model,
191191
* list of species, and initial state)

include/cantera/thermo/ThermoFactory.h

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class ThermoFactory : public Factory<ThermoPhase>
4444
* @param model The name of the thermo model
4545
* @returns a pointer to a new ThermoPhase object of the type specified. Throws a
4646
* CanteraError if the named model isn't registered with ThermoFactory.
47+
* @deprecated To be removed after Cantera 3.0; superseded by newThermo()
4748
*/
4849
virtual ThermoPhase* newThermoPhase(const std::string& model);
4950

@@ -58,13 +59,15 @@ class ThermoFactory : public Factory<ThermoPhase>
5859
static std::mutex thermo_mutex;
5960
};
6061

61-
//! @copydoc ThermoFactory::newThermoPhase
62+
//! @copydoc ThermoFactory::newThermo(const string&)
63+
//! @deprecated To be removed after Cantera 3.0; superseded by newThermo()
6264
ThermoPhase* newThermoPhase(const string& model);
6365

6466
//! Create a new ThermoPhase instance.
6567
/*!
6668
* @param model String to look up the model against
67-
* @returns a shared pointer to a new ThermoPhase instance matching the model string.
69+
* @returns a shared pointer to a new ThermoPhase object of the type specified. Throws a
70+
* CanteraError if the named model is not registered with ThermoFactory.
6871
*/
6972
shared_ptr<ThermoPhase> newThermo(const string& model);
7073

@@ -76,6 +79,11 @@ shared_ptr<ThermoPhase> newThermo(const string& model);
7679
* which will be used as the default location from which to read species
7780
* definitions.
7881
*/
82+
shared_ptr<ThermoPhase> newThermoPhase(const AnyMap& phaseNode,
83+
const AnyMap& rootNode=AnyMap());
84+
85+
//! @copydoc ThermoFactory::newThermoPhase(const AnyMap&, const AnyMap&)
86+
//! @deprecated To be removed after Cantera 3.0; superseded by newThermoPhase()
7987
unique_ptr<ThermoPhase> newPhase(const AnyMap& phaseNode,
8088
const AnyMap& rootNode=AnyMap());
8189

@@ -90,6 +98,10 @@ unique_ptr<ThermoPhase> newPhase(const AnyMap& phaseNode,
9098
* If this is blank, the first phase in the file is used.
9199
* @returns an initialized ThermoPhase object.
92100
*/
101+
shared_ptr<ThermoPhase> newThermoPhase(const string& infile, const string& id);
102+
103+
//! @copydoc ThermoFactory::newThermoPhase(const string&, const string&)
104+
//! @deprecated To be removed after Cantera 3.0; superseded by newThermoPhase()
93105
ThermoPhase* newPhase(const std::string& infile, std::string id="");
94106

95107
//! Initialize a ThermoPhase object

include/cantera/thermo/ThermoPhase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,7 @@ class ThermoPhase : public Phase
16631663
const AnyMap& rootNode=AnyMap());
16641664

16651665
//! Returns the parameters of a ThermoPhase object such that an identical
1666-
//! one could be reconstructed using the newPhase(AnyMap&) function.
1666+
//! one could be reconstructed using the newThermoPhase(AnyMap&) function.
16671667
//! @param withInput If true, include additional input data fields associated
16681668
//! with the phase description, such as user-defined fields from a YAML input
16691669
//! file, as returned by the input() method.
@@ -1799,7 +1799,7 @@ class ThermoPhase : public Phase
17991799

18001800
protected:
18011801
//! Store the parameters of a ThermoPhase object such that an identical
1802-
//! one could be reconstructed using the newPhase(AnyMap&) function. This
1802+
//! one could be reconstructed using the newThermoPhase(AnyMap&) function. This
18031803
//! does not include user-defined fields available in input().
18041804
virtual void getParameters(AnyMap& phaseNode) const;
18051805

src/base/Solution.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ shared_ptr<Solution> newSolution(const std::string &infile,
182182
}
183183

184184
if (extension == "cti" || extension == "xml") {
185-
throw CanteraError("newPhase",
185+
throw CanteraError("newSolution",
186186
"The CTI and XML formats are no longer supported.");
187187
}
188188

@@ -216,7 +216,7 @@ shared_ptr<Solution> newSolution(const AnyMap& phaseNode,
216216
const std::map<std::string, shared_ptr<Solution>>& related)
217217
{
218218
// thermo phase
219-
auto thermo = shared_ptr<ThermoPhase>(newPhase(phaseNode, rootNode));
219+
auto thermo = newThermoPhase(phaseNode, rootNode);
220220

221221
// instantiate Solution object of the correct derived type
222222
shared_ptr<Solution> sol;

src/thermo/IonsFromNeutralVPSSTP.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,10 +478,10 @@ void IonsFromNeutralVPSSTP::initThermo()
478478
AnyMap infile = AnyMap::fromYamlFile(fileName,
479479
m_input.getString("__file__", ""));
480480
AnyMap& phaseNode = infile["phases"].getMapWhere("name", neutralName);
481-
setNeutralMoleculePhase(newPhase(phaseNode, infile));
481+
setNeutralMoleculePhase(newThermoPhase(phaseNode, infile));
482482
} else {
483483
AnyMap& phaseNode = m_rootNode["phases"].getMapWhere("name", neutralName);
484-
setNeutralMoleculePhase(newPhase(phaseNode, m_rootNode));
484+
setNeutralMoleculePhase(newThermoPhase(phaseNode, m_rootNode));
485485
}
486486
}
487487

src/thermo/LatticeSolidPhase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ void LatticeSolidPhase::initThermo()
306306
compositionMap composition = m_input["composition"].asMap<double>();
307307
for (auto& item : composition) {
308308
AnyMap& node = m_rootNode["phases"].getMapWhere("name", item.first);
309-
addLattice(newPhase(node, m_rootNode));
309+
addLattice(newThermoPhase(node, m_rootNode));
310310
}
311311
setLatticeStoichiometry(composition);
312312
}

src/thermo/ThermoFactory.cpp

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,17 @@ void ThermoFactory::deleteFactory()
122122
s_factory = 0;
123123
}
124124

125+
ThermoPhase* ThermoFactory::newThermoPhase(const std::string& model)
126+
{
127+
warn_deprecated("newThermoPhase",
128+
"To be removed after Cantera 3.0; superseded by newThermo.");
129+
return create(model);
130+
}
131+
125132
ThermoPhase* newThermoPhase(const string& model)
126133
{
134+
warn_deprecated("newThermoPhase",
135+
"To be removed after Cantera 3.0; superseded by newThermo.");
127136
return ThermoFactory::factory()->create(model);
128137
}
129138

@@ -133,13 +142,23 @@ shared_ptr<ThermoPhase> newThermo(const string& model)
133142
return tptr;
134143
}
135144

136-
ThermoPhase* ThermoFactory::newThermoPhase(const std::string& model)
145+
shared_ptr<ThermoPhase> newThermoPhase(const AnyMap& phaseNode, const AnyMap& rootNode)
137146
{
138-
return create(model);
147+
if (!phaseNode.hasKey("kinetics") && phaseNode.hasKey("reactions")) {
148+
throw InputFileError("newPhase", phaseNode["reactions"],
149+
"Phase entry includes a 'reactions' field but does not "
150+
"specify a kinetics model.");
151+
}
152+
shared_ptr<ThermoPhase> t = newThermo(phaseNode["thermo"].asString());
153+
setupPhase(*t, phaseNode, rootNode);
154+
return t;
139155
}
140156

141157
unique_ptr<ThermoPhase> newPhase(const AnyMap& phaseNode, const AnyMap& rootNode)
142158
{
159+
warn_deprecated("newPhase",
160+
"To be removed after Cantera 3.0; superseded by\n"
161+
"newThermoPhase(const AnyMap&, const AnyMap&).");
143162
if (!phaseNode.hasKey("kinetics") && phaseNode.hasKey("reactions")) {
144163
throw InputFileError("newPhase", phaseNode["reactions"],
145164
"Phase entry includes a 'reactions' field but does not "
@@ -150,24 +169,33 @@ unique_ptr<ThermoPhase> newPhase(const AnyMap& phaseNode, const AnyMap& rootNode
150169
return t;
151170
}
152171

153-
ThermoPhase* newPhase(const std::string& infile, std::string id)
172+
shared_ptr<ThermoPhase> newThermoPhase(const string& infile, const string& id)
154173
{
155174
size_t dot = infile.find_last_of(".");
156175
string extension;
157176
if (dot != npos) {
158177
extension = toLowerCopy(infile.substr(dot+1));
159178
}
179+
string id_ = id;
160180
if (id == "-") {
161-
id = "";
181+
id_ = "";
162182
}
163183
if (extension == "cti" || extension == "xml") {
164-
throw CanteraError("newPhase",
184+
throw CanteraError("newThermo",
165185
"The CTI and XML formats are no longer supported.");
166186
}
167187

168188
AnyMap root = AnyMap::fromYamlFile(infile);
169-
AnyMap& phase = root["phases"].getMapWhere("name", id);
170-
return newPhase(phase, root).release();
189+
AnyMap& phase = root["phases"].getMapWhere("name", id_);
190+
return newThermoPhase(phase, root);
191+
}
192+
193+
ThermoPhase* newPhase(const std::string& infile, std::string id)
194+
{
195+
warn_deprecated("newPhase",
196+
"To be removed after Cantera 3.0; superseded by\n"
197+
"newThermoPhase(const std::string&, const std::string&).");
198+
return newThermoPhase(infile, id).get();
171199
}
172200

173201
void addDefaultElements(ThermoPhase& thermo, const vector<string>& element_names) {

0 commit comments

Comments
 (0)