Cantera  2.3.0
StFlow.h
Go to the documentation of this file.
1 //! @file StFlow.h
2 
3 // This file is part of Cantera. See License.txt in the top-level directory or
4 // at http://www.cantera.org/license.txt for license and copyright information.
5 
6 #ifndef CT_STFLOW_H
7 #define CT_STFLOW_H
8 
9 #include "Domain1D.h"
10 #include "cantera/base/Array.h"
13 
14 namespace Cantera
15 {
16 
17 //------------------------------------------
18 // constants
19 //------------------------------------------
20 
21 // Offsets of solution components in the solution array.
22 const size_t c_offset_U = 0; // axial velocity
23 const size_t c_offset_V = 1; // strain rate
24 const size_t c_offset_T = 2; // temperature
25 const size_t c_offset_L = 3; // (1/r)dP/dr
26 const size_t c_offset_Y = 4; // mass fractions
27 
28 class Transport;
29 
30 /**
31  * This class represents 1D flow domains that satisfy the one-dimensional
32  * similarity solution for chemically-reacting, axisymmetric flows.
33  * @ingroup onedim
34  */
35 class StFlow : public Domain1D
36 {
37 public:
38  //--------------------------------
39  // construction and destruction
40  //--------------------------------
41 
42  //! Create a new flow domain.
43  //! @param ph Object representing the gas phase. This object will be used
44  //! to evaluate all thermodynamic, kinetic, and transport properties.
45  //! @param nsp Number of species.
46  //! @param points Initial number of grid points
47  StFlow(IdealGasPhase* ph = 0, size_t nsp = 1, size_t points = 1);
48 
49  //! @name Problem Specification
50  //! @{
51 
52  virtual void setupGrid(size_t n, const doublereal* z);
53 
54  virtual void resetBadValues(double* xg);
55 
56 
57  thermo_t& phase() {
58  return *m_thermo;
59  }
60  Kinetics& kinetics() {
61  return *m_kin;
62  }
63 
64  /**
65  * Set the thermo manager. Note that the flow equations assume
66  * the ideal gas equation.
67  */
69  m_thermo = &th;
70  }
71 
72  //! Set the kinetics manager. The kinetics manager must
73  void setKinetics(Kinetics& kin) {
74  m_kin = &kin;
75  }
76 
77  //! set the transport manager
78  void setTransport(Transport& trans);
79 
80  //! set the transport manager
81  /*!
82  * @deprecated The withSoret argument is deprecated and unused.
83  * Use the form of setTransport with signature setTransport(Transport& trans).
84  * To be removed after Cantera 2.3.
85  */
86  void setTransport(Transport& trans, bool withSoret);
87 
88  void enableSoret(bool withSoret);
89  bool withSoret() const {
90  return m_do_soret;
91  }
92 
93  //! Set the pressure. Since the flow equations are for the limit of small
94  //! Mach number, the pressure is very nearly constant throughout the flow.
95  void setPressure(doublereal p) {
96  m_press = p;
97  }
98 
99  //! The current pressure [Pa].
100  doublereal pressure() const {
101  return m_press;
102  }
103 
104  //! Write the initial solution estimate into array x.
105  virtual void _getInitialSoln(double* x);
106 
107  virtual void _finalize(const doublereal* x);
108 
109  //! Sometimes it is desired to carry out the simulation using a specified
110  //! temperature profile, rather than computing it by solving the energy
111  //! equation. This method specifies this profile.
112  void setFixedTempProfile(vector_fp& zfixed, vector_fp& tfixed) {
113  m_zfix = zfixed;
114  m_tfix = tfixed;
115  }
116 
117  /*!
118  * Set the temperature fixed point at grid point j, and disable the energy
119  * equation so that the solution will be held to this value.
120  */
121  void setTemperature(size_t j, doublereal t) {
122  m_fixedtemp[j] = t;
123  m_do_energy[j] = false;
124  }
125 
126  //! The fixed temperature value at point j.
127  doublereal T_fixed(size_t j) const {
128  return m_fixedtemp[j];
129  }
130 
131  // @}
132 
133  virtual std::string componentName(size_t n) const;
134 
135  virtual size_t componentIndex(const std::string& name) const;
136 
137  //! Print the solution.
138  virtual void showSolution(const doublereal* x);
139 
140  //! Save the current solution for this domain into an XML_Node
141  /*!
142  * @param o XML_Node to save the solution to.
143  * @param sol Current value of the solution vector. The object will pick
144  * out which part of the solution vector pertains to this
145  * object.
146  */
147  virtual XML_Node& save(XML_Node& o, const doublereal* const sol);
148 
149  virtual void restore(const XML_Node& dom, doublereal* soln,
150  int loglevel);
151 
152  // overloaded in subclasses
153  virtual std::string flowType() {
154  return "<none>";
155  }
156 
157  void solveEnergyEqn(size_t j=npos);
158 
159  //! Turn radiation on / off.
160  /*!
161  * The simple radiation model used was established by Y. Liu and B. Rogg
162  * [Y. Liu and B. Rogg, Modelling of thermally radiating diffusion flames
163  * with detailed chemistry and transport, EUROTHERM Seminars, 17:114-127,
164  * 1991]. This model considers the radiation of CO2 and H2O.
165  */
166  void enableRadiation(bool doRadiation) {
167  m_do_radiation = doRadiation;
168  }
169 
170  //! Returns `true` if the radiation term in the energy equation is enabled
171  bool radiationEnabled() const {
172  return m_do_radiation;
173  }
174 
175  //! Set the emissivities for the boundary values
176  /*!
177  * Reads the emissivities for the left and right boundary values in the
178  * radiative term and writes them into the variables, which are used for the
179  * calculation.
180  */
181  void setBoundaryEmissivities(doublereal e_left, doublereal e_right);
182 
183  void fixTemperature(size_t j=npos);
184 
185  bool doEnergy(size_t j) {
186  return m_do_energy[j];
187  }
188 
189  //! Change the grid size. Called after grid refinement.
190  void resize(size_t components, size_t points);
191 
192  virtual void setFixedPoint(int j0, doublereal t0) {}
193 
194  //! Set the gas object state to be consistent with the solution at point j.
195  void setGas(const doublereal* x, size_t j);
196 
197  //! Set the gas state to be consistent with the solution at the midpoint
198  //! between j and j + 1.
199  void setGasAtMidpoint(const doublereal* x, size_t j);
200 
201  doublereal density(size_t j) const {
202  return m_rho[j];
203  }
204 
205  virtual bool fixed_mdot() {
206  return true;
207  }
208  void setViscosityFlag(bool dovisc) {
209  m_dovisc = dovisc;
210  }
211 
212  /*!
213  * Evaluate the residual function for axisymmetric stagnation flow. If
214  * j == npos, the residual function is evaluated at all grid points.
215  * Otherwise, the residual function is only evaluated at grid points
216  * j-1, j, and j+1. This option is used to efficiently evaluate the
217  * Jacobian numerically.
218  */
219  virtual void eval(size_t j, doublereal* x, doublereal* r,
220  integer* mask, doublereal rdt);
221 
222  //! Evaluate all residual components at the right boundary.
223  virtual void evalRightBoundary(doublereal* x, doublereal* res,
224  integer* diag, doublereal rdt) = 0;
225 
226  //! Evaluate the residual corresponding to the continuity equation at all
227  //! interior grid points.
228  virtual void evalContinuity(size_t j, doublereal* x, doublereal* r,
229  integer* diag, doublereal rdt) = 0;
230 
231  //! Index of the species on the left boundary with the largest mass fraction
232  size_t leftExcessSpecies() const {
233  return m_kExcessLeft;
234  }
235 
236  //! Index of the species on the right boundary with the largest mass fraction
237  size_t rightExcessSpecies() const {
238  return m_kExcessRight;
239  }
240 
241 protected:
242  doublereal wdot(size_t k, size_t j) const {
243  return m_wdot(k,j);
244  }
245 
246  //! Write the net production rates at point `j` into array `m_wdot`
247  void getWdot(doublereal* x, size_t j) {
248  setGas(x,j);
249  m_kin->getNetProductionRates(&m_wdot(0,j));
250  }
251 
252  /**
253  * Update the thermodynamic properties from point j0 to point j1
254  * (inclusive), based on solution x.
255  */
256  void updateThermo(const doublereal* x, size_t j0, size_t j1) {
257  for (size_t j = j0; j <= j1; j++) {
258  setGas(x,j);
259  m_rho[j] = m_thermo->density();
260  m_wtm[j] = m_thermo->meanMolecularWeight();
261  m_cp[j] = m_thermo->cp_mass();
262  }
263  }
264 
265  //! @name Solution components
266  //! @{
267 
268  doublereal T(const doublereal* x, size_t j) const {
269  return x[index(c_offset_T, j)];
270  }
271  doublereal& T(doublereal* x, size_t j) {
272  return x[index(c_offset_T, j)];
273  }
274  doublereal T_prev(size_t j) const {
275  return prevSoln(c_offset_T, j);
276  }
277 
278  doublereal rho_u(const doublereal* x, size_t j) const {
279  return m_rho[j]*x[index(c_offset_U, j)];
280  }
281 
282  doublereal u(const doublereal* x, size_t j) const {
283  return x[index(c_offset_U, j)];
284  }
285 
286  doublereal V(const doublereal* x, size_t j) const {
287  return x[index(c_offset_V, j)];
288  }
289  doublereal V_prev(size_t j) const {
290  return prevSoln(c_offset_V, j);
291  }
292 
293  doublereal lambda(const doublereal* x, size_t j) const {
294  return x[index(c_offset_L, j)];
295  }
296 
297  doublereal Y(const doublereal* x, size_t k, size_t j) const {
298  return x[index(c_offset_Y + k, j)];
299  }
300 
301  doublereal& Y(doublereal* x, size_t k, size_t j) {
302  return x[index(c_offset_Y + k, j)];
303  }
304 
305  doublereal Y_prev(size_t k, size_t j) const {
306  return prevSoln(c_offset_Y + k, j);
307  }
308 
309  doublereal X(const doublereal* x, size_t k, size_t j) const {
310  return m_wtm[j]*Y(x,k,j)/m_wt[k];
311  }
312 
313  doublereal flux(size_t k, size_t j) const {
314  return m_flux(k, j);
315  }
316  //! @}
317 
318  //! @name convective spatial derivatives.
319  //! These use upwind differencing, assuming u(z) is negative
320  //! @{
321  doublereal dVdz(const doublereal* x, size_t j) const {
322  size_t jloc = (u(x,j) > 0.0 ? j : j + 1);
323  return (V(x,jloc) - V(x,jloc-1))/m_dz[jloc-1];
324  }
325 
326  doublereal dYdz(const doublereal* x, size_t k, size_t j) const {
327  size_t jloc = (u(x,j) > 0.0 ? j : j + 1);
328  return (Y(x,k,jloc) - Y(x,k,jloc-1))/m_dz[jloc-1];
329  }
330 
331  doublereal dTdz(const doublereal* x, size_t j) const {
332  size_t jloc = (u(x,j) > 0.0 ? j : j + 1);
333  return (T(x,jloc) - T(x,jloc-1))/m_dz[jloc-1];
334  }
335  //! @}
336 
337  doublereal shear(const doublereal* x, size_t j) const {
338  doublereal c1 = m_visc[j-1]*(V(x,j) - V(x,j-1));
339  doublereal c2 = m_visc[j]*(V(x,j+1) - V(x,j));
340  return 2.0*(c2/(z(j+1) - z(j)) - c1/(z(j) - z(j-1)))/(z(j+1) - z(j-1));
341  }
342 
343  doublereal divHeatFlux(const doublereal* x, size_t j) const {
344  doublereal c1 = m_tcon[j-1]*(T(x,j) - T(x,j-1));
345  doublereal c2 = m_tcon[j]*(T(x,j+1) - T(x,j));
346  return -2.0*(c2/(z(j+1) - z(j)) - c1/(z(j) - z(j-1)))/(z(j+1) - z(j-1));
347  }
348 
349  size_t mindex(size_t k, size_t j, size_t m) {
350  return m*m_nsp*m_nsp + m_nsp*j + k;
351  }
352 
353  //! Update the diffusive mass fluxes.
354  void updateDiffFluxes(const doublereal* x, size_t j0, size_t j1);
355 
356  //---------------------------------------------------------
357  // member data
358  //---------------------------------------------------------
359 
360  doublereal m_press; // pressure
361 
362  // grid parameters
363  vector_fp m_dz;
364 
365  // mixture thermo properties
366  vector_fp m_rho;
367  vector_fp m_wtm;
368 
369  // species thermo properties
370  vector_fp m_wt;
371  vector_fp m_cp;
372 
373  // transport properties
374  vector_fp m_visc;
375  vector_fp m_tcon;
376  vector_fp m_diff;
377  vector_fp m_multidiff;
378  Array2D m_dthermal;
379  Array2D m_flux;
380 
381  // production rates
382  Array2D m_wdot;
383 
384  size_t m_nsp;
385 
386  IdealGasPhase* m_thermo;
387  Kinetics* m_kin;
388  Transport* m_trans;
389 
390  // boundary emissivities for the radiation calculations
391  doublereal m_epsilon_left;
392  doublereal m_epsilon_right;
393 
394  //! Indices within the ThermoPhase of the radiating species. First index is
395  //! for CO2, second is for H2O.
396  std::vector<size_t> m_kRadiating;
397 
398  // flags
399  std::vector<bool> m_do_energy;
400  bool m_do_soret;
401  std::vector<bool> m_do_species;
402  bool m_do_multicomponent;
403 
404  //! flag for the radiative heat loss
406 
407  //! radiative heat loss vector
409 
410  // fixed T and Y values
411  vector_fp m_fixedtemp;
412  vector_fp m_zfix;
413  vector_fp m_tfix;
414 
415  //! Index of species with a large mass fraction at each boundary, for which
416  //! the mass fraction may be calculated as 1 minus the sum of the other mass
417  //! fractions
419  size_t m_kExcessRight;
420 
421  bool m_dovisc;
422 
423  //! Update the transport properties at grid points in the range from `j0`
424  //! to `j1`, based on solution `x`.
425  void updateTransport(doublereal* x, size_t j0, size_t j1);
426 
427 private:
428  vector_fp m_ybar;
429 };
430 
431 /**
432  * A class for axisymmetric stagnation flows.
433  * @ingroup onedim
434  */
435 class AxiStagnFlow : public StFlow
436 {
437 public:
438  AxiStagnFlow(IdealGasPhase* ph = 0, size_t nsp = 1, size_t points = 1) :
439  StFlow(ph, nsp, points) {
440  m_dovisc = true;
441  }
442 
443  virtual void evalRightBoundary(doublereal* x, doublereal* res,
444  integer* diag, doublereal rdt);
445  virtual void evalContinuity(size_t j, doublereal* x, doublereal* r,
446  integer* diag, doublereal rdt);
447 
448  virtual std::string flowType() {
449  return "Axisymmetric Stagnation";
450  }
451 };
452 
453 /**
454  * A class for freely-propagating premixed flames.
455  * @ingroup onedim
456  */
457 class FreeFlame : public StFlow
458 {
459 public:
460  FreeFlame(IdealGasPhase* ph = 0, size_t nsp = 1, size_t points = 1);
461  virtual void evalRightBoundary(doublereal* x, doublereal* res,
462  integer* diag, doublereal rdt);
463  virtual void evalContinuity(size_t j, doublereal* x, doublereal* r,
464  integer* diag, doublereal rdt);
465 
466  virtual std::string flowType() {
467  return "Free Flame";
468  }
469  virtual bool fixed_mdot() {
470  return false;
471  }
472  virtual void _finalize(const doublereal* x);
473  virtual void restore(const XML_Node& dom, doublereal* soln, int loglevel);
474 
475  virtual XML_Node& save(XML_Node& o, const doublereal* const sol);
476 
477  //! Location of the point where temperature is fixed
478  doublereal m_zfixed;
479 
480  //! Temperature at the point used to fix the flame location
481  doublereal m_tfixed;
482 };
483 
484 }
485 
486 #endif
virtual std::string componentName(size_t n) const
Name of the nth component. May be overloaded.
Definition: StFlow.cpp:556
virtual void _finalize(const doublereal *x)
In some cases, a domain may need to set parameters that depend on the initial solution estimate...
Definition: StFlow.cpp:980
void setKinetics(Kinetics &kin)
Set the kinetics manager. The kinetics manager must.
Definition: StFlow.h:73
void updateThermo(const doublereal *x, size_t j0, size_t j1)
Update the thermodynamic properties from point j0 to point j1 (inclusive), based on solution x...
Definition: StFlow.h:256
virtual void evalRightBoundary(doublereal *x, doublereal *res, integer *diag, doublereal rdt)=0
Evaluate all residual components at the right boundary.
bool m_do_radiation
flag for the radiative heat loss
Definition: StFlow.h:405
size_t leftExcessSpecies() const
Index of the species on the left boundary with the largest mass fraction.
Definition: StFlow.h:232
This class represents 1D flow domains that satisfy the one-dimensional similarity solution for chemic...
Definition: StFlow.h:35
doublereal pressure() const
The current pressure [Pa].
Definition: StFlow.h:100
virtual void evalRightBoundary(doublereal *x, doublereal *res, integer *diag, doublereal rdt)
Evaluate all residual components at the right boundary.
Definition: StFlow.cpp:928
doublereal cp_mass() const
Specific heat at constant pressure. Units: J/kg/K.
Definition: ThermoPhase.h:784
Class IdealGasPhase represents low-density gases that obey the ideal gas equation of state...
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:165
A class for axisymmetric stagnation flows.
Definition: StFlow.h:435
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
Definition: StFlow.cpp:1005
virtual void _finalize(const doublereal *x)
In some cases, a domain may need to set parameters that depend on the initial solution estimate...
Definition: StFlow.cpp:217
virtual void evalContinuity(size_t j, doublereal *x, doublereal *r, integer *diag, doublereal rdt)
Evaluate the residual corresponding to the continuity equation at all interior grid points...
Definition: StFlow.cpp:899
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:97
virtual XML_Node & save(XML_Node &o, const doublereal *const sol)
Save the current solution for this domain into an XML_Node.
Definition: StFlow.cpp:1012
Base class for transport property managers.
void setPressure(doublereal p)
Set the pressure.
Definition: StFlow.h:95
virtual doublereal density() const
Density (kg/m^3).
Definition: Phase.h:607
virtual void evalContinuity(size_t j, doublereal *x, doublereal *r, integer *diag, doublereal rdt)=0
Evaluate the residual corresponding to the continuity equation at all interior grid points...
A class for freely-propagating premixed flames.
Definition: StFlow.h:457
doublereal m_tfixed
Temperature at the point used to fix the flame location.
Definition: StFlow.h:481
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
Definition: StFlow.cpp:596
virtual void getNetProductionRates(doublereal *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Definition: Kinetics.cpp:473
Base class for a phase with thermodynamic properties.
Definition: ThermoPhase.h:93
Header file for class Cantera::Array2D.
Base class for one-dimensional domains.
Definition: Domain1D.h:36
vector_fp m_qdotRadiation
radiative heat loss vector
Definition: StFlow.h:408
ThermoPhase object for the ideal gas equation of state - workhorse for Cantera (see Thermodynamic Pro...
virtual void evalRightBoundary(doublereal *x, doublereal *res, integer *diag, doublereal rdt)
Evaluate all residual components at the right boundary.
Definition: StFlow.cpp:878
void setThermo(IdealGasPhase &th)
Set the thermo manager.
Definition: StFlow.h:68
bool radiationEnabled() const
Returns true if the radiation term in the energy equation is enabled.
Definition: StFlow.h:171
void setFixedTempProfile(vector_fp &zfixed, vector_fp &tfixed)
Sometimes it is desired to carry out the simulation using a specified temperature profile...
Definition: StFlow.h:112
void setTransport(Transport &trans)
set the transport manager
Definition: StFlow.cpp:166
Public interface for kinetics managers.
Definition: Kinetics.h:111
virtual void resetBadValues(double *xg)
Definition: StFlow.cpp:135
Base class for kinetics managers and also contains the kineticsmgr module documentation (see Kinetics...
void setTemperature(size_t j, doublereal t)
Definition: StFlow.h:121
std::vector< size_t > m_kRadiating
Indices within the ThermoPhase of the radiating species.
Definition: StFlow.h:396
doublereal m_zfixed
Location of the point where temperature is fixed.
Definition: StFlow.h:478
void getWdot(doublereal *x, size_t j)
Write the net production rates at point j into array m_wdot
Definition: StFlow.h:247
double prevSoln(size_t n, size_t j) const
Value of component n at point j in the previous solution.
Definition: Domain1D.h:454
virtual void evalContinuity(size_t j, doublereal *x, doublereal *r, integer *diag, doublereal rdt)
Evaluate the residual corresponding to the continuity equation at all interior grid points...
Definition: StFlow.cpp:952
void setGas(const doublereal *x, size_t j)
Set the gas object state to be consistent with the solution at point j.
Definition: StFlow.cpp:197
virtual void showSolution(const doublereal *x)
Print the solution.
Definition: StFlow.cpp:497
void updateTransport(doublereal *x, size_t j0, size_t j1)
Update the transport properties at grid points in the range from j0 to j1, based on solution x...
Definition: StFlow.cpp:467
virtual void setupGrid(size_t n, const doublereal *z)
called to set up initial grid, and after grid refinement
Definition: StFlow.cpp:120
void enableRadiation(bool doRadiation)
Turn radiation on / off.
Definition: StFlow.h:166
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:157
void setGasAtMidpoint(const doublereal *x, size_t j)
Set the gas state to be consistent with the solution at the midpoint between j and j + 1...
Definition: StFlow.cpp:205
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition: Phase.h:661
void updateDiffFluxes(const doublereal *x, size_t j0, size_t j1)
Update the diffusive mass fluxes.
Definition: StFlow.cpp:514
doublereal T_fixed(size_t j) const
The fixed temperature value at point j.
Definition: StFlow.h:127
size_t rightExcessSpecies() const
Index of the species on the right boundary with the largest mass fraction.
Definition: StFlow.h:237
size_t m_kExcessLeft
Index of species with a large mass fraction at each boundary, for which the mass fraction may be calc...
Definition: StFlow.h:418
virtual void _getInitialSoln(double *x)
Write the initial solution estimate into array x.
Definition: StFlow.cpp:189
void resize(size_t components, size_t points)
Change the grid size. Called after grid refinement.
Definition: StFlow.cpp:96
StFlow(IdealGasPhase *ph=0, size_t nsp=1, size_t points=1)
Create a new flow domain.
Definition: StFlow.cpp:16
Namespace for the Cantera kernel.
Definition: application.cpp:29
void setBoundaryEmissivities(doublereal e_left, doublereal e_right)
Set the emissivities for the boundary values.
Definition: StFlow.cpp:840
virtual void eval(size_t j, doublereal *x, doublereal *r, integer *mask, doublereal rdt)
Definition: StFlow.cpp:235
virtual XML_Node & save(XML_Node &o, const doublereal *const sol)
Save the current solution for this domain into an XML_Node.
Definition: StFlow.cpp:758