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