Cantera  2.0
writelog.cpp
Go to the documentation of this file.
1 /**
2  * @file converters/writelog.cpp
3  *
4  */
5 
6 // Copyright 2001 California Institute of Technology
7 
8 #include <cstdio>
9 #include "writelog.h"
10 
11 using namespace std;
12 
13 namespace ckr
14 {
15 
16 
17 /// format a string for the log file message printed when starting a new task
18 string newTask(std::string msg)
19 {
20  string s = "\n";
21  s += msg + "...\n";
22  return s;
23 }
24 
25 
26 /// print the falloff parameters for a pressure-dependent reaction
27 bool writeFalloff(int type, const vector_fp& c, std::ostream& log)
28 {
29 
30  log.precision(6);
31  log.width(0);
32  log.flags(ios::uppercase);
33 
34  // bool ok = true;
35  switch (type) {
36 
37  case Lindemann:
38  log << " Lindemann falloff function" << endl;
39  return true;
40 
41  case Troe:
42  log << " Troe falloff function: " << endl;
43  if (c.size() == 3) {
44  log << " alpha, T***, T* = (" << c[0] << ", " << c[1]
45  << ", " << c[2] << ")" << endl;
46  } else if (c.size() == 4) {
47  log << " alpha, T***, T*, T** = (" << c[0] << ", " << c[1]
48  << ", " << c[2] << ", " << c[3] << ")" << endl;
49  } else {
50  for (size_t n = 0; n < c.size(); n++) {
51  log << c[n] << ", ";
52  log << endl;
53  }
54  log << "###### ERROR ##### incorrect number of parameters" << endl;
55  return false;
56  }
57  return true;
58 
59  case SRI:
60  log << " SRI falloff function: " << endl;
61  if (c.size() == 3) {
62  log << " a, b, c = (" << c[0] << ", " << c[1]
63  << ", " << c[2] << ")" << endl;
64  } else if (c.size() == 5) {
65  log << " a, b, c, d, e = (" << c[0] << ", " << c[1]
66  << ", " << c[2] << ", " << c[3] << ", " << c[4]
67  << ")" << endl;
68  } else {
69  for (size_t n = 0; n < c.size(); n++) {
70  log << c[n] << ", ";
71  log << endl;
72  }
73  log << "##### ERROR ##### incorrect number of parameters" << endl;
74  return false;
75  }
76  return true;
77 
78  default:
79  log << "unknown falloff type: " << type << endl;
80  return false;
81  }
82 }
83 
84 
85 /// print the rate coefficient parameters
86 bool writeRateCoeff(const RateCoeff& k, std::ostream& log)
87 {
88  log.precision(10);
89  log.width(0);
90  log.flags(ios::uppercase);
91 
92  bool ok = true;
93  size_t nb;
94 
95  switch (k.type) {
96 
97  case Arrhenius:
98  log <<" A, n, E = (" << k.A << ", " << k.n
99  << ", " << k.E << ")" << endl;
100  break;
101 
102  case LandauTeller:
103  log << "A, n, E, B, C = (" << k.A << ", " << k.n
104  << ", " << k.E << ", " << k.B << ", " << k.C
105  << ") *** Landau-Teller ***" << endl;
106  break;
107 
108  case Jan:
109  log <<" A, n, E = (" << k.A << ", " << k.n
110  << ", " << k.E << ") *** JAN *** " << endl;
111  nb = k.b.size();
112  for (size_t n = 0; n < nb; n++) {
113  log << " b" << n+1 << ": " << k.b[n] << endl;
114  }
115  if (nb != 9) log
116  << "warning: number of b coefficients should be 9."
117  << endl;
118  break;
119 
120  case Fit1:
121  log <<" A, n, E = (" << k.A << ", " << k.n
122  << ", " << k.E << ") *** FIT1 *** " << endl;
123  nb = k.b.size();
124  for (size_t n = 0; n < nb; n++) {
125  log << " b" << n+1 << ": " << k.b[n] << endl;
126  }
127  if (nb != 9) log
128  << "warning: number of b coefficients should be 4."
129  << endl;
130  break;
131 
132  default:
133  log << "unknown rate coefficient type: " << k.type << endl;
134  ok = false;
135  }
136  return ok;
137 }
138 
139 /**
140  * Write onto an output stream the chemical equation for a reaction.
141  */
142 void printReactionEquation(std::ostream& f, const Reaction& r)
143 {
144  // r.write(f);
145  f << reactionEquation(r);
146 }
147 
148 
149 /**
150  * Write to a string the chemical equation for a reaction.
151  */
152 string reactionEquation(const Reaction& r)
153 {
154  string s = "";
155  int nr = static_cast<int>(r.reactants.size());
156  int np = static_cast<int>(r.products.size());
157  int k;
158  double m;
159  char buf[20];
160 
161  for (k = 0; k < nr; k++) {
162  m = r.reactants[k].number;
163  if (m != 1.0) {
164  sprintf(buf,"%g",m);
165  s += string(buf);
166  s += " ";
167  }
168  s += r.reactants[k].name;
169  if (k < nr - 1) {
170  s += " + ";
171  }
172  }
173 
174  if (r.isFalloffRxn) {
175  s += " (+ " + r.thirdBody + ")";
176  } else if (r.isThreeBodyRxn) {
177  s += " + " + r.thirdBody;
178  }
179  if (r.isReversible) {
180  s += " <=> ";
181  } else {
182  s += " => ";
183  }
184 
185  for (k = 0; k < np; k++) {
186  m = r.products[k].number;
187  if (m != 1.0) {
188  sprintf(buf,"%g",m);
189  s += string(buf);
190  s += " ";
191  }
192  s += r.products[k].name;
193  if (k < np - 1) {
194  s += " + ";
195  }
196  }
197  if (r.isFalloffRxn) {
198  s += " (+ " + r.thirdBody + ")";
199  } else if (r.isThreeBodyRxn) {
200  s += " + " + r.thirdBody;
201  }
202  return s;
203 }
204 
205 
206 
207 /**
208  *
209  * Write a summary of the properties of one species to the log file.
210  * @param log log file output stream
211  * @param spec instance of Species class
212  */
213 
214 void writeSpeciesData(std::ostream& log, const Species& spec)
215 {
216 
217  if (!spec.id.empty()) {
218  log << endl << " id/date: " << spec.id << endl;
219  } else {
220  log << " ... " << endl;
221  }
222 
223  log << " phase: "
224  << spec.phase << endl
225  << " composition: (";
226 
227  for (size_t ie = 0; ie < spec.elements.size(); ie++) {
228  if (!spec.elements[ie].name.empty()) {
229  log.flags(ios::fixed);
230  log.precision(0);
231  if (ie > 0) {
232  log << ", ";
233  }
234  log << spec.elements[ie].number << " "
235  << spec.elements[ie].name;
236  }
237  }
238  log << ")";
239 
240  if (spec.thermoFormatType == 0) {
241  log.flags(ios::showpoint | ios::fixed);
242  log.precision(2);
243  log << endl << " Tlow, Tmid, Thigh: (" << spec.tlow << ", " <<
244  spec.tmid << ", " << spec.thigh << ")" << endl << endl;
245  log << " coefficients (low, high):" << endl;
246  log.flags(ios::scientific | ios::uppercase | ios::internal);
247  log.precision(8);
248  for (int j = 0; j < 7; j++) {
249  log << " a" << j + 1;
250  log.setf(ios::showpos);
251  log << " \t" << spec.lowCoeffs[j]
252  << " \t" << spec.highCoeffs[j] << endl;
253  log.unsetf(ios::showpos);
254  }
255  log << endl;
256  } else if (spec.thermoFormatType == 1) {
257  log.flags(ios::showpoint | ios::fixed);
258  log.precision(2);
259  log << endl;
260  log << "Number of temp regions = " << spec.nTempRegions << endl;
261  for (int i = 0; i < spec.nTempRegions; i++) {
262  log << " Tlow, Thigh: (" << spec.minTemps[i] << ", "
263  << spec.maxTemps[i] << ")" << endl << endl;
264  log << " coefficients :" << endl;
265  log.flags(ios::scientific | ios::uppercase | ios::internal);
266  log.precision(8);
267  vector_fp& cc = *spec.region_coeffs[i];
268  for (int j = 0; j < 9; j++) {
269  log << " a" << j + 1;
270  log.setf(ios::showpos);
271  log << " \t" << cc[j] << endl;
272  log.unsetf(ios::showpos);
273  }
274  log << endl;
275  }
276  }
277 }
278 
279 
280 }
281 
282