Cantera  2.1.2
Group.cpp
Go to the documentation of this file.
1 /**
2  * @file Group.cpp
3  *
4  * Implementation file for the Group class used in reaction path analysis.
5  */
6 
7 // Copyright 2001 California Institute of Technology
8 
9 // reaction path analysis support
10 
11 #include "cantera/kinetics/Group.h"
12 
13 namespace Cantera
14 {
15 
17 {
18 
19  size_t n = m_comp.size();
20 
21  // if already checked and not valid, return
22  if (m_sign == -999) {
23  return;
24  }
25 
26  m_sign = 0;
27  bool ok = true;
28  for (size_t m = 0; m < n; m++) {
29  if (m_comp[m] != 0) {
30  if (m_sign == 0) {
31  m_sign = m_comp[m]/abs(m_comp[m]);
32  } else if (m_sign * m_comp[m] < 0) {
33  ok = false;
34  break;
35  }
36  }
37  }
38  if (!ok) {
39  m_sign = -999;
40  m_comp.resize(n,0);
41  }
42 }
43 
44 std::ostream& Group::fmt(std::ostream& s,
45  const std::vector<std::string>& esymbols) const
46 {
47  s << "(";
48  int nm;
49  bool first = true;
50  size_t n = m_comp.size();
51  for (size_t m = 0; m < n; m++) {
52  nm = m_comp[m];
53  if (nm != 0) {
54  if (!first) {
55  s << "-";
56  }
57  s << esymbols[m];
58  if (nm != 1) {
59  s << nm;
60  }
61  first = false;
62  }
63  }
64  s << ")";
65  return s;
66 }
67 
68 std::ostream& operator<<(std::ostream& s, const Cantera::Group& g)
69 {
70  if (g.valid()) {
71  s << g.m_comp;
72  } else {
73  s << "<none>";
74  }
75  return s;
76 }
77 
78 }
bool valid() const
True if all non-zero atom numbers have the same sign.
Definition: Group.h:115
void validate()
Definition: Group.cpp:16
Class Group is an internal class used by class ReactionPath.
Definition: Group.h:21