Cantera  2.5.1
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 
12 namespace 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 
39 std::ostream& Group::fmt(std::ostream& s,
40  const std::vector<std::string>& esymbols) const
41 {
42  s << "(";
43  bool first = true;
44  for (size_t m = 0; m < m_comp.size(); m++) {
45  int nm = m_comp[m];
46  if (nm != 0) {
47  if (!first) {
48  s << "-";
49  }
50  s << esymbols[m];
51  if (nm != 1) {
52  s << nm;
53  }
54  first = false;
55  }
56  }
57  s << ")";
58  return s;
59 }
60 
61 std::ostream& operator<<(std::ostream& s, const Group& g)
62 {
63  if (g.valid()) {
64  s << g.m_comp;
65  } else {
66  s << "<none>";
67  }
68  return s;
69 }
70 
71 }
void validate()
Definition: Group.cpp:15
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264