22Solution::Solution() {}
29 "Requires associated 'ThermoPhase'");
38 "Requires associated 'ThermoPhase'");
57 "Solution '{}' already contains an adjacent phase named '{}'.",
64 "Adjacent phases should have higher dimensionality than the reacting ",
65 "phase.\n'{}' is {}-dimensional while '{}' is {}-dimensional",
73AnyMap Solution::parameters(
bool withInput)
const
81 out[
"transport"] = empty;
82 }
else if (
m_transport->transportType() ==
"None") {
83 out[
"transport"] = empty;
91 if (input.hasKey(
"transport")) {
96 if (out[
"transport"] == empty) {
97 out.
erase(
"transport");
114 return source.empty() ?
"<unknown>" :
source.asString();
123 const std::string& name,
124 const std::string& transport,
125 const std::vector<shared_ptr<Solution>>& adjacent)
128 size_t dot = infile.find_last_of(
".");
129 std::string extension;
134 if (extension ==
"yml" || extension ==
"yaml") {
137 AnyMap& phaseNode = rootNode[
"phases"].getMapWhere(
"name", name);
138 auto sol =
newSolution(phaseNode, rootNode, transport, adjacent);
139 sol->setSource(infile);
145 sol->setSource(infile);
148 sol->setThermo(shared_ptr<ThermoPhase>(
newPhase(infile, name)));
151 std::vector<ThermoPhase*> phases;
152 phases.push_back(sol->thermo().get());
153 for (
auto& adj : adjacent) {
154 phases.push_back(adj->thermo().get());
156 sol->setKinetics(
newKinetics(phases, infile, name));
159 if (transport ==
"") {
160 sol->setTransport(shared_ptr<Transport>(
162 }
else if (transport ==
"None") {
165 sol->setTransport(shared_ptr<Transport>(
172shared_ptr<Solution>
newSolution(
const std::string& infile,
const std::string& name,
173 const std::string& transport,
const std::vector<std::string>& adjacent)
177 size_t dot = infile.find_last_of(
".");
178 std::string extension;
183 if (extension ==
"xml" || extension ==
"cti") {
184 throw CanteraError(
"newSolution(string infile, string name, string transport, "
185 "vector<string> adjacent)",
186 "This constructor is only compatible with YAML input files");
190 AnyMap& phaseNode = rootNode[
"phases"].getMapWhere(
"name", name);
192 std::vector<shared_ptr<Solution>> adjPhases;
194 for (
auto& name : adjacent) {
195 auto& adjNode = rootNode[
"phases"].getMapWhere(
"name", name);
196 adjPhases.push_back(
newSolution(adjNode, rootNode));
198 return newSolution(phaseNode, rootNode, transport, adjPhases);
203 const std::string& transport,
204 const std::vector<shared_ptr<Solution>>& adjacent,
205 const std::map<std::string, shared_ptr<Solution>>& related)
208 auto thermo = shared_ptr<ThermoPhase>(
newPhase(phaseNode, rootNode));
211 shared_ptr<Solution> sol;
212 switch (thermo->nDim()) {
219 sol->setSource(
"custom YAML");
220 sol->setThermo(thermo);
223 for (
auto& adj : adjacent) {
224 sol->addAdjacent(adj);
229 if (adjacent.empty() && phaseNode.
hasKey(
"adjacent-phases")) {
230 auto all_related = related;
231 for (
auto& phase : adjacent) {
232 all_related[phase->name()] = phase;
237 const std::string& name)
239 if (!all_related.count(name)) {
242 "", {}, all_related);
243 all_related[name] = adj;
244 for (
size_t i = 0; i < adj->nAdjacent(); i++) {
245 all_related[adj->adjacent(i)->name()] = adj->adjacent(i);
248 sol->addAdjacent(all_related[name]);
251 auto& adjPhases = phaseNode[
"adjacent-phases"];
252 if (adjPhases.is<std::vector<std::string>>()) {
254 for (
auto& phase : adjPhases.as<std::vector<std::string>>()) {
255 addPhase(rootNode[
"phases"], rootNode, phase);
257 }
else if (adjPhases.is<std::vector<AnyMap>>()) {
261 for (
auto& item : adjPhases.asVector<
AnyMap>()) {
262 const std::string& source = item.begin()->first;
263 const auto& names = item.begin()->second.asVector<std::string>();
264 const auto& slash = boost::ifind_last(source,
"/");
267 std::string fileName(source.begin(), slash.begin());
268 std::string node(slash.end(), source.end());
271 for (
auto& phase : names) {
272 addPhase(phaseSource[node], phaseSource, phase);
274 }
else if (rootNode.
hasKey(source)) {
276 for (
auto& phase : names) {
277 addPhase(rootNode[source], rootNode, phase);
281 "Could not find a phases section named '{}'.", source);
286 "Could not parse adjacent phase declaration of type '{}'",
287 adjPhases.type_str());
292 std::vector<ThermoPhase*> phases;
293 phases.push_back(sol->thermo().get());
294 for (
size_t i = 0; i < sol->nAdjacent(); i++) {
295 phases.push_back(sol->adjacent(i)->thermo().get());
297 sol->setKinetics(
newKinetics(phases, phaseNode, rootNode));
300 if (transport ==
"") {
301 sol->setTransport(shared_ptr<Transport>(
303 }
else if (transport ==
"None") {
306 sol->setTransport(shared_ptr<Transport>(
312 for (
const auto& item : rootNode.ordered()) {
313 std::string key = item.first;
314 if (key ==
"phases") {
317 }
else if (key !=
"units") {
318 header[key] = item.second;
321 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,...
Headers for the Transport object, which is the virtual base class for all transport property evaluato...
Header file defining class TransportFactory (see TransportFactory)
const AnyValue & getMetadata(const std::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.
const std::string & getString(const std::string &key, const std::string &default_) const
If key exists, return it as a string, otherwise return default_.
static AnyMap fromYamlFile(const std::string &name, const std::string &parent_name="")
Create an AnyMap from a YAML file.
void erase(const std::string &key)
Erase the value held by key.
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
void update(const AnyMap &other, bool keepExisting=true)
Add items from other to this AnyMap.
void setMetadata(const std::string &key, const AnyValue &value)
Set a metadata value that applies to this AnyMap and its children.
A wrapper for a variable whose type is determined at runtime.
AnyMap & getMapWhere(const std::string &key, const std::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.
std::string name() const
Return the name of this Solution object.
shared_ptr< Kinetics > kinetics()
Accessor for the Kinetics pointer.
void addAdjacent(shared_ptr< Solution > adjacent)
Add a phase adjacent to this phase.
void setSource(const std::string &source)
Overwrite source (only required if object is not created using newSolution)
shared_ptr< Kinetics > m_kinetics
Kinetics manager.
virtual void setThermo(shared_ptr< ThermoPhase > thermo)
Set the ThermoPhase object.
shared_ptr< ThermoPhase > m_thermo
ThermoPhase manager.
std::map< std::string, shared_ptr< Solution > > m_adjacentByName
Adjacent phases, for access by name.
void setName(const std::string &name)
Set the name of this Solution object.
AnyMap m_header
Additional input fields; usually from a YAML input file.
std::vector< shared_ptr< Solution > > m_adjacent
Adjacent phases, for access by index.
virtual void setTransport(shared_ptr< Transport > transport)
Set the Transport object.
const std::string source() const
Retrieve source used for object creation; usually an input file name.
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.
Transport * newDefaultTransportMgr(ThermoPhase *thermo, int loglevel=0)
Create a new transport manager instance.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
doublereal dot(InputIter x_begin, InputIter x_end, InputIter2 y_begin)
Function that calculates a templated inner product.
Transport * newTransportMgr(const std::string &model="", ThermoPhase *thermo=0, int log_level=0)
Build a new transport manager using a transport manager that may not be the same as in the phase desc...
shared_ptr< Solution > newSolution(const std::string &infile, const std::string &name, const std::string &transport, const std::vector< std::string > &adjacent)
Create and initialize a new Solution from an input file.
std::string toLowerCopy(const std::string &input)
Convert to lower case.
shared_ptr< Kinetics > newKinetics(const std::string &model)
Create a new Kinetics instance.
Contains declarations for string manipulation functions within Cantera.