20#include <boost/algorithm/string.hpp>
30 "Requires associated 'ThermoPhase'");
39 "Requires associated 'ThermoPhase'");
76 "Unable to set Transport model without valid ThermoPhase object.");
84 "Solution '{}' already contains an adjacent phase named '{}'.",
91 "Adjacent phases should have higher dimensionality than the reacting ",
92 "phase.\n'{}' is {}-dimensional while '{}' is {}-dimensional",
100AnyMap Solution::parameters(
bool withInput)
const
108 out[
"transport"] = empty;
109 }
else if (
m_transport->transportModel() ==
"none") {
110 out[
"transport"] = empty;
117 if (input.hasKey(
"reactions")) {
119 input.erase(
"reactions");
122 if (input.hasKey(
"transport")) {
127 if (out[
"transport"] == empty) {
128 out.
erase(
"transport");
145 return source.empty() ?
"<unknown>" :
source.asString();
154 shared_ptr<ExternalHandle> handle)
164 return shared_ptr<ExternalHandle>();
180 const string &transport,
181 const vector<shared_ptr<Solution>> &adjacent)
184 size_t dot = infile.find_last_of(
".");
190 if (extension ==
"cti" || extension ==
"xml") {
192 "The CTI and XML formats are no longer supported.");
198 auto sol =
newSolution(phaseNode, rootNode, transport, adjacent);
199 sol->setSource(infile);
203shared_ptr<Solution>
newSolution(
const string& infile,
const string& name,
204 const string& transport,
const vector<string>& adjacent)
209 vector<shared_ptr<Solution>> adjPhases;
211 for (
auto& name : adjacent) {
212 const auto& adjNode = rootNode.
at(
"phases").
getMapWhere(
"name", name);
213 adjPhases.push_back(
newSolution(adjNode, rootNode));
215 return newSolution(phaseNode, rootNode, transport, adjPhases);
220 const string& transport,
221 const vector<shared_ptr<Solution>>& adjacent,
222 const map<
string, shared_ptr<Solution>>& related)
225 auto thermo =
newThermo(phaseNode, rootNode);
228 shared_ptr<Solution> sol;
229 switch (thermo->nDim()) {
236 sol->setSource(
"custom YAML");
237 sol->setThermo(thermo);
240 for (
auto& adj : adjacent) {
241 sol->addAdjacent(adj);
246 if (adjacent.empty() && phaseNode.
hasKey(
"adjacent-phases")) {
247 auto all_related = related;
248 for (
auto& phase : adjacent) {
249 all_related[phase->name()] = phase;
256 if (!all_related.count(name)) {
259 "default", {}, all_related);
260 all_related[name] = adj;
261 for (
size_t i = 0; i < adj->nAdjacent(); i++) {
262 all_related[adj->adjacent(i)->name()] = adj->adjacent(i);
265 sol->addAdjacent(all_related[name]);
268 auto& adjPhases = phaseNode[
"adjacent-phases"];
269 if (adjPhases.is<vector<string>>()) {
271 for (
auto& phase : adjPhases.as<vector<string>>()) {
272 addPhase(rootNode[
"phases"], rootNode, phase);
274 }
else if (adjPhases.is<vector<AnyMap>>()) {
278 for (
auto& item : adjPhases.asVector<
AnyMap>()) {
279 const string& source = item.begin()->first;
280 const auto& names = item.begin()->second.asVector<
string>();
281 const auto& slash = boost::ifind_last(source,
"/");
284 string fileName(source.begin(), slash.begin());
285 string node(slash.end(), source.end());
288 for (
auto& phase : names) {
289 addPhase(phaseSource[node], phaseSource, phase);
291 }
else if (rootNode.
hasKey(source)) {
293 for (
auto& phase : names) {
294 addPhase(rootNode[source], rootNode, phase);
298 "Could not find a phases section named '{}'.", source);
303 "Could not parse adjacent phase declaration of type '{}'",
304 adjPhases.type_str());
309 vector<shared_ptr<ThermoPhase>> phases;
310 phases.push_back(sol->thermo());
311 for (
size_t i = 0; i < sol->nAdjacent(); i++) {
312 phases.push_back(sol->adjacent(i)->thermo());
314 sol->setKinetics(
newKinetics(phases, phaseNode, rootNode, sol));
317 sol->setTransportModel(transport);
321 for (
const auto& [key, value] : rootNode.
ordered()) {
322 if (key ==
"phases") {
328 sol->header() = header;
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
Headers for the factory class that can create known ThermoPhase objects (see Thermodynamic Properties...
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
Header file defining class TransportFactory (see TransportFactory)
Headers for the Transport object, which is the virtual base class for all transport property evaluato...
const AnyValue & getMetadata(const string &key) const
Get a value from the metadata applicable to the AnyMap tree containing this node.
A map of string keys to values whose type can vary at runtime.
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
void setMetadata(const string &key, const AnyValue &value)
Set a metadata value that applies to this AnyMap and its children.
OrderedProxy ordered(bool withUnits=false) const
Return a proxy object that allows iteration in an order determined by the order of insertion,...
const string & getString(const string &key, const string &default_) const
If key exists, return it as a string, otherwise return default_.
void erase(const string &key)
Erase the value held by key.
static AnyMap fromYamlFile(const string &name, const string &parent_name="")
Create an AnyMap from a YAML file.
const AnyValue & at(const string &key) const
Get the value of the item stored in key.
void update(const AnyMap &other, bool keepExisting=true)
Add items from other to this AnyMap.
A wrapper for a variable whose type is determined at runtime.
AnyMap & getMapWhere(const string &key, const string &value, bool create=false)
Treating the value as vector<AnyMap>, return the item where the given key has the specified value.
Base class for exceptions thrown by Cantera classes.
static shared_ptr< Interface > create()
Create an empty Interface object.
static shared_ptr< Solution > create()
Create an empty Solution object.
vector< shared_ptr< Solution > > m_adjacent
Adjacent phases, for access by index.
void removeChangedCallback(void *id)
Remove the callback function associated with the specified object.
map< string, shared_ptr< Solution > > m_adjacentByName
Adjacent phases, for access by name.
void setSource(const string &source)
Overwrite source (only required if object is not created using newSolution)
shared_ptr< Kinetics > kinetics()
Accessor for the Kinetics pointer.
void setTransportModel(const string &model="default")
Set the Transport object by name.
void addAdjacent(shared_ptr< Solution > adjacent)
Add a phase adjacent to this phase.
void setName(const string &name)
Set the name of this Solution object.
shared_ptr< Kinetics > m_kinetics
Kinetics manager.
virtual void setThermo(shared_ptr< ThermoPhase > thermo)
Set the ThermoPhase object.
map< string, shared_ptr< ExternalHandle > > m_externalHandles
Wrappers for this Solution object in extension languages, for evaluation of user-defined reaction rat...
shared_ptr< ThermoPhase > m_thermo
ThermoPhase manager.
void registerChangedCallback(void *id, const function< void()> &callback)
Register a function to be called if any of the Solution's thermo, kinetics, or transport objects is r...
AnyMap m_header
Additional input fields; usually from a YAML input file.
void holdExternalHandle(const string &name, shared_ptr< ExternalHandle > handle)
Store a handle to a wrapper for this Solution object from an external language interface (for example...
map< void *, function< void()> > m_changeCallbacks
Callback functions that are invoked when the therm, kinetics, or transport members of the Solution ar...
const string source() const
Retrieve source used for object creation; usually an input file name.
virtual void setTransport(shared_ptr< Transport > transport)
Set the Transport object directly.
shared_ptr< ThermoPhase > thermo()
Accessor for the ThermoPhase pointer.
shared_ptr< Transport > transport()
Accessor for the Transport pointer.
const AnyMap & header() const
Access input data associated with header definition.
shared_ptr< Solution > adjacent(size_t i)
Get the Solution object for an adjacent phase by index.
shared_ptr< Transport > m_transport
Transport manager.
virtual void setKinetics(shared_ptr< Kinetics > kinetics)
Set the Kinetics object.
shared_ptr< ExternalHandle > getExternalHandle(const string &name) const
Get the handle for a wrapper for this Solution object from an external language interface.
string name() const
Return the name of this Solution object.
string toLowerCopy(const string &input)
Convert to lower case.
shared_ptr< Kinetics > newKinetics(const string &model)
Create a new Kinetics instance.
double dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
shared_ptr< Solution > newSolution(const string &infile, const string &name, const string &transport, const vector< shared_ptr< Solution > > &adjacent)
Create and initialize a new Solution manager from an input file.
shared_ptr< ThermoPhase > newThermo(const AnyMap &phaseNode, const AnyMap &rootNode)
Create a new ThermoPhase object and initialize it.
shared_ptr< Transport > newTransport(shared_ptr< ThermoPhase > thermo, const string &model)
Create a new Transport instance.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
Contains declarations for string manipulation functions within Cantera.