20#include <boost/algorithm/string.hpp>
30 "Requires associated 'ThermoPhase'");
39 "Requires associated 'ThermoPhase'");
45 m_thermo->setSolution(weak_from_this());
68 "The Transport object is not initialized.");
86 "Unable to set Transport model without valid ThermoPhase object.");
97 "Solution '{}' already contains an adjacent phase named '{}'.",
104 "Adjacent phases should have higher dimensionality than the reacting ",
105 "phase.\n'{}' is {}-dimensional while '{}' is {}-dimensional",
113AnyMap Solution::parameters(
bool withInput)
const
121 out[
"transport"] = empty;
122 }
else if (
m_transport->transportModel() ==
"none") {
123 out[
"transport"] = empty;
130 if (input.hasKey(
"reactions")) {
132 input.erase(
"reactions");
135 if (input.hasKey(
"transport")) {
140 if (out[
"transport"] == empty) {
141 out.
erase(
"transport");
158 return source.empty() ?
"<unknown>" :
source.asString();
167 shared_ptr<ExternalHandle> handle)
177 return shared_ptr<ExternalHandle>();
193 const string &transport,
194 const vector<shared_ptr<Solution>> &adjacent)
197 size_t dot = infile.find_last_of(
".");
203 if (extension ==
"cti" || extension ==
"xml") {
205 "The CTI and XML formats are no longer supported.");
211 auto sol =
newSolution(phaseNode, rootNode, transport, adjacent);
212 sol->setSource(infile);
216shared_ptr<Solution>
newSolution(
const string& infile,
const string& name,
217 const string& transport,
const vector<string>& adjacent)
222 vector<shared_ptr<Solution>> adjPhases;
224 for (
auto& name : adjacent) {
225 const auto& adjNode = rootNode.
at(
"phases").
getMapWhere(
"name", name);
226 adjPhases.push_back(
newSolution(adjNode, rootNode));
228 return newSolution(phaseNode, rootNode, transport, adjPhases);
233 const string& transport,
234 const vector<shared_ptr<Solution>>& adjacent,
235 const map<
string, shared_ptr<Solution>>& related)
238 auto thermo =
newThermo(phaseNode, rootNode);
241 shared_ptr<Solution> sol;
242 switch (thermo->nDim()) {
249 sol->setSource(
"custom YAML");
250 sol->setThermo(thermo);
253 for (
auto& adj : adjacent) {
254 sol->addAdjacent(adj);
259 if (adjacent.empty() && phaseNode.
hasKey(
"adjacent-phases")) {
260 auto all_related = related;
261 for (
auto& phase : adjacent) {
262 all_related[phase->name()] = phase;
269 if (!all_related.count(name)) {
272 "default", {}, all_related);
273 all_related[name] = adj;
274 for (
size_t i = 0; i < adj->nAdjacent(); i++) {
275 all_related[adj->adjacent(i)->name()] = adj->adjacent(i);
278 sol->addAdjacent(all_related[name]);
281 auto& adjPhases = phaseNode[
"adjacent-phases"];
282 if (adjPhases.is<vector<string>>()) {
284 for (
auto& phase : adjPhases.as<vector<string>>()) {
285 addPhase(rootNode[
"phases"], rootNode, phase);
287 }
else if (adjPhases.is<vector<AnyMap>>()) {
291 for (
auto& item : adjPhases.asVector<
AnyMap>()) {
292 const string& source = item.begin()->first;
293 const auto& names = item.begin()->second.asVector<
string>();
294 const auto& slash = boost::ifind_last(source,
"/");
297 string fileName(source.begin(), slash.begin());
298 string node(slash.end(), source.end());
301 for (
auto& phase : names) {
302 addPhase(phaseSource[node], phaseSource, phase);
304 }
else if (rootNode.
hasKey(source)) {
306 for (
auto& phase : names) {
307 addPhase(rootNode[source], rootNode, phase);
311 "Could not find a phases section named '{}'.", source);
316 "Could not parse adjacent phase declaration of type '{}'",
317 adjPhases.type_str());
322 vector<shared_ptr<ThermoPhase>> phases;
323 phases.push_back(sol->thermo());
324 for (
size_t i = 0; i < sol->nAdjacent(); i++) {
325 phases.push_back(sol->adjacent(i)->thermo());
327 sol->setKinetics(
newKinetics(phases, phaseNode, rootNode, sol));
330 sol->setTransportModel(transport);
334 for (
const auto& [key, value] : rootNode.
ordered()) {
335 if (key ==
"phases") {
341 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.
string transportModel()
Retrieve transport model name.
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.