Cantera  3.1.0a1
Loading...
Searching...
No Matches
Group.cpp
Go to the documentation of this file.
1/**
2 * @file Group.cpp Implementation file for the Group class used in reaction path
3 * analysis.
4 */
5
6// This file is part of Cantera. See License.txt in the top-level directory or
7// at https://cantera.org/license.txt for license and copyright information.
8
10#include <iostream>
11
12namespace Cantera
13{
14
16{
17 // if already checked and not valid, return
18 if (m_sign == -999) {
19 return;
20 }
21
22 m_sign = 0;
23 bool ok = true;
24 for (size_t m = 0; m < m_comp.size(); m++) {
25 if (m_comp[m] != 0) {
26 if (m_sign == 0) {
27 m_sign = m_comp[m]/abs(m_comp[m]);
28 } else if (m_sign * m_comp[m] < 0) {
29 ok = false;
30 break;
31 }
32 }
33 }
34 if (!ok) {
35 m_sign = -999;
36 }
37}
38
39std::ostream& Group::fmt(std::ostream& s, const vector<string>& esymbols) const
40{
41 s << "(";
42 bool first = true;
43 for (size_t m = 0; m < m_comp.size(); m++) {
44 int nm = m_comp[m];
45 if (nm != 0) {
46 if (!first) {
47 s << "-";
48 }
49 s << esymbols[m];
50 if (nm != 1) {
51 s << nm;
52 }
53 first = false;
54 }
55 }
56 s << ")";
57 return s;
58}
59
60std::ostream& operator<<(std::ostream& s, const Group& g)
61{
62 if (g.valid()) {
63 s << g.m_comp;
64 } else {
65 s << "<none>";
66 }
67 return s;
68}
69
70}
void validate()
Definition Group.cpp:15
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
std::ostream & operator<<(std::ostream &s, const Array2D &m)
Output the current contents of the Array2D object.
Definition Array.cpp:100