Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 #include <iostream>
13 
14 namespace Cantera
15 {
16 
18 {
19 
20  size_t n = m_comp.size();
21 
22  // if already checked and not valid, return
23  if (m_sign == -999) {
24  return;
25  }
26 
27  m_sign = 0;
28  bool ok = true;
29  for (size_t m = 0; m < n; m++) {
30  if (m_comp[m] != 0) {
31  if (m_sign == 0) {
32  m_sign = m_comp[m]/abs(m_comp[m]);
33  } else if (m_sign * m_comp[m] < 0) {
34  ok = false;
35  break;
36  }
37  }
38  }
39  if (!ok) {
40  m_sign = -999;
41  m_comp.resize(n,0);
42  }
43 }
44 
45 std::ostream& Group::fmt(std::ostream& s,
46  const std::vector<std::string>& esymbols) const
47 {
48  s << "(";
49  int nm;
50  bool first = true;
51  size_t n = m_comp.size();
52  for (size_t m = 0; m < n; m++) {
53  nm = m_comp[m];
54  if (nm != 0) {
55  if (!first) {
56  s << "-";
57  }
58  s << esymbols[m];
59  if (nm != 1) {
60  s << nm;
61  }
62  first = false;
63  }
64  }
65  s << ")";
66  return s;
67 }
68 
69 std::ostream& operator<<(std::ostream& s, const Cantera::Group& g)
70 {
71  if (g.valid()) {
72  s << g.m_comp;
73  } else {
74  s << "<none>";
75  }
76  return s;
77 }
78 
79 }
bool valid() const
True if all non-zero atom numbers have the same sign.
Definition: Group.h:113
void validate()
Definition: Group.cpp:17
Class Group is an internal class used by class ReactionPath.
Definition: Group.h:19