20#include <boost/algorithm/string.hpp>
30 "Requires associated 'ThermoPhase'");
39 "Requires associated 'ThermoPhase'");
76 "Unable to set Transport model without valid ThermoPhase object.");
88 "Solution '{}' already contains an adjacent phase named '{}'.",
95 "Adjacent phases should have higher dimensionality than the reacting ",
96 "phase.\n'{}' is {}-dimensional while '{}' is {}-dimensional",
104AnyMap Solution::parameters(
bool withInput)
const
112 out[
"transport"] = empty;
113 }
else if (
m_transport->transportModel() ==
"none") {
114 out[
"transport"] = empty;
121 if (input.hasKey(
"reactions")) {
123 input.erase(
"reactions");
126 if (input.hasKey(
"transport")) {
131 if (out[
"transport"] == empty) {
132 out.
erase(
"transport");
149 return source.empty() ?
"<unknown>" :
source.asString();
158 shared_ptr<ExternalHandle> handle)
168 return shared_ptr<ExternalHandle>();
184 const string &transport,
185 const vector<shared_ptr<Solution>> &adjacent)
188 size_t dot = infile.find_last_of(
".");
194 if (extension ==
"cti" || extension ==
"xml") {
196 "The CTI and XML formats are no longer supported.");
201 AnyMap& phaseNode = rootNode[
"phases"].getMapWhere(
"name", name);
202 auto sol =
newSolution(phaseNode, rootNode, transport, adjacent);
203 sol->setSource(infile);
207shared_ptr<Solution>
newSolution(
const string& infile,
const string& name,
208 const string& transport,
const vector<string>& adjacent)
211 AnyMap& phaseNode = rootNode[
"phases"].getMapWhere(
"name", name);
213 vector<shared_ptr<Solution>> adjPhases;
215 for (
auto& name : adjacent) {
216 auto& adjNode = rootNode[
"phases"].getMapWhere(
"name", name);
217 adjPhases.push_back(
newSolution(adjNode, rootNode));
219 return newSolution(phaseNode, rootNode, transport, adjPhases);
224 const string& transport,
225 const vector<shared_ptr<Solution>>& adjacent,
226 const map<
string, shared_ptr<Solution>>& related)
229 auto thermo =
newThermo(phaseNode, rootNode);
232 shared_ptr<Solution> sol;
233 switch (thermo->nDim()) {
240 sol->setSource(
"custom YAML");
241 sol->setThermo(thermo);
244 for (
auto& adj : adjacent) {
245 sol->addAdjacent(adj);
250 if (adjacent.empty() && phaseNode.
hasKey(
"adjacent-phases")) {
251 auto all_related = related;
252 for (
auto& phase : adjacent) {
253 all_related[phase->name()] = phase;
260 if (!all_related.count(name)) {
263 "", {}, all_related);
264 all_related[name] = adj;
265 for (
size_t i = 0; i < adj->nAdjacent(); i++) {
266 all_related[adj->adjacent(i)->name()] = adj->adjacent(i);
269 sol->addAdjacent(all_related[name]);
272 auto& adjPhases = phaseNode[
"adjacent-phases"];
273 if (adjPhases.is<vector<string>>()) {
275 for (
auto& phase : adjPhases.as<vector<string>>()) {
276 addPhase(rootNode[
"phases"], rootNode, phase);
278 }
else if (adjPhases.is<vector<AnyMap>>()) {
282 for (
auto& item : adjPhases.asVector<
AnyMap>()) {
283 const string& source = item.begin()->first;
284 const auto& names = item.begin()->second.asVector<
string>();
285 const auto& slash = boost::ifind_last(source,
"/");
288 string fileName(source.begin(), slash.begin());
289 string node(slash.end(), source.end());
292 for (
auto& phase : names) {
293 addPhase(phaseSource[node], phaseSource, phase);
295 }
else if (rootNode.
hasKey(source)) {
297 for (
auto& phase : names) {
298 addPhase(rootNode[source], rootNode, phase);
302 "Could not find a phases section named '{}'.", source);
307 "Could not parse adjacent phase declaration of type '{}'",
308 adjPhases.type_str());
313 vector<shared_ptr<ThermoPhase>> phases;
314 phases.push_back(sol->thermo());
315 for (
size_t i = 0; i < sol->nAdjacent(); i++) {
316 phases.push_back(sol->adjacent(i)->thermo());
318 sol->setKinetics(
newKinetics(phases, phaseNode, rootNode, sol));
321 sol->setTransportModel(transport);
325 for (
const auto& [key, value] : rootNode.ordered()) {
326 if (key ==
"phases") {
329 }
else if (key !=
"units") {
333 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.
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.
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 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.
void setTransportModel(const string &model="")
Set the Transport object by name.
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.