Cantera 2.6.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 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
14namespace Cantera
15{
16
17//------------------------------------------
18// constants
19//------------------------------------------
20
21// Offsets of solution components in the solution array.
22const size_t c_offset_U = 0; // axial velocity
23const size_t c_offset_V = 1; // strain rate
24const size_t c_offset_T = 2; // temperature
25const size_t c_offset_L = 3; // (1/r)dP/dr
26const size_t c_offset_E = 4; // electric poisson's equation
27const size_t c_offset_Y = 5; // mass fractions
28
29class 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 */
36class StFlow : public Domain1D
37{
38public:
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 ThermoPhase& 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 //! Returns true if the specified component is an active part of the solver state
141 virtual bool componentActive(size_t n) const;
142
143 //! Print the solution.
144 virtual void showSolution(const doublereal* x);
145
146 //! Save the current solution for this domain into an XML_Node
147 /*!
148 * @param o XML_Node to save the solution to.
149 * @param sol Current value of the solution vector. The object will pick
150 * out which part of the solution vector pertains to this
151 * object.
152 *
153 * @deprecated The XML output format is deprecated and will be removed in
154 * Cantera 3.0.
155 */
156 virtual XML_Node& save(XML_Node& o, const doublereal* const sol);
157
158 virtual void restore(const XML_Node& dom, doublereal* soln,
159 int loglevel);
160
161 virtual AnyMap serialize(const double* soln) const;
162 virtual void restore(const AnyMap& state, double* soln, int loglevel);
163
164 //! Set flow configuration for freely-propagating flames, using an internal
165 //! point with a fixed temperature as the condition to determine the inlet
166 //! mass flux.
167 void setFreeFlow() {
168 m_type = cFreeFlow;
169 m_dovisc = false;
170 }
171
172 //! Set flow configuration for axisymmetric counterflow or burner-stabilized
173 //! flames, using specified inlet mass fluxes.
175 m_type = cAxisymmetricStagnationFlow;
176 m_dovisc = true;
177 }
178
179 //! Return the type of flow domain being represented, either "Free Flame" or
180 //! "Axisymmetric Stagnation".
181 //! @see setFreeFlow setAxisymmetricFlow
182 virtual std::string flowType() const {
183 if (m_type == cFreeFlow) {
184 return "Free Flame";
185 } else if (m_type == cAxisymmetricStagnationFlow) {
186 return "Axisymmetric Stagnation";
187 } else {
188 throw CanteraError("StFlow::flowType", "Unknown value for 'm_type'");
189 }
190 }
191
192 void solveEnergyEqn(size_t j=npos);
193
194 //! Turn radiation on / off.
195 /*!
196 * The simple radiation model used was established by Y. Liu and B. Rogg
197 * [Y. Liu and B. Rogg, Modelling of thermally radiating diffusion flames
198 * with detailed chemistry and transport, EUROTHERM Seminars, 17:114-127,
199 * 1991]. This model considers the radiation of CO2 and H2O.
200 */
201 void enableRadiation(bool doRadiation) {
202 m_do_radiation = doRadiation;
203 }
204
205 //! Returns `true` if the radiation term in the energy equation is enabled
206 bool radiationEnabled() const {
207 return m_do_radiation;
208 }
209
210 //! Return radiative heat loss at grid point j
211 double radiativeHeatLoss(size_t j) const {
212 return m_qdotRadiation[j];
213 }
214
215 //! Set the emissivities for the boundary values
216 /*!
217 * Reads the emissivities for the left and right boundary values in the
218 * radiative term and writes them into the variables, which are used for the
219 * calculation.
220 */
221 void setBoundaryEmissivities(double e_left, double e_right);
222
223 //! Return emissivitiy at left boundary
224 double leftEmissivity() const { return m_epsilon_left; }
225
226 //! Return emissivitiy at right boundary
227 double rightEmissivity() const { return m_epsilon_right; }
228
229 void fixTemperature(size_t j=npos);
230
231 bool doEnergy(size_t j) {
232 return m_do_energy[j];
233 }
234
235 //! Change the grid size. Called after grid refinement.
236 virtual void resize(size_t components, size_t points);
237
238 //! Set the gas object state to be consistent with the solution at point j.
239 void setGas(const doublereal* x, size_t j);
240
241 //! Set the gas state to be consistent with the solution at the midpoint
242 //! between j and j + 1.
243 void setGasAtMidpoint(const doublereal* x, size_t j);
244
245 doublereal density(size_t j) const {
246 return m_rho[j];
247 }
248
249 virtual bool fixed_mdot() {
250 return (domainType() != cFreeFlow);
251 }
252 void setViscosityFlag(bool dovisc) {
253 m_dovisc = dovisc;
254 }
255
256 /*!
257 * Evaluate the residual function for axisymmetric stagnation flow. If
258 * j == npos, the residual function is evaluated at all grid points.
259 * Otherwise, the residual function is only evaluated at grid points
260 * j-1, j, and j+1. This option is used to efficiently evaluate the
261 * Jacobian numerically.
262 */
263 virtual void eval(size_t j, doublereal* x, doublereal* r,
264 integer* mask, doublereal rdt);
265
266 //! Evaluate all residual components at the right boundary.
267 virtual void evalRightBoundary(double* x, double* res, int* diag,
268 double rdt);
269
270 //! Evaluate the residual corresponding to the continuity equation at all
271 //! interior grid points.
272 virtual void evalContinuity(size_t j, double* x, double* r,
273 int* diag, double rdt);
274
275 //! Index of the species on the left boundary with the largest mass fraction
276 size_t leftExcessSpecies() const {
277 return m_kExcessLeft;
278 }
279
280 //! Index of the species on the right boundary with the largest mass fraction
281 size_t rightExcessSpecies() const {
282 return m_kExcessRight;
283 }
284
285protected:
286 doublereal wdot(size_t k, size_t j) const {
287 return m_wdot(k,j);
288 }
289
290 //! Write the net production rates at point `j` into array `m_wdot`
291 void getWdot(doublereal* x, size_t j) {
292 setGas(x,j);
293 m_kin->getNetProductionRates(&m_wdot(0,j));
294 }
295
296 //! Update the properties (thermo, transport, and diffusion flux).
297 //! This function is called in eval after the points which need
298 //! to be updated are defined.
299 virtual void updateProperties(size_t jg, double* x, size_t jmin, size_t jmax);
300
301 //! Evaluate the residual function. This function is called in eval
302 //! after updateProperties is called.
303 virtual void evalResidual(double* x, double* rsd, int* diag,
304 double rdt, size_t jmin, size_t jmax);
305
306 /**
307 * Update the thermodynamic properties from point j0 to point j1
308 * (inclusive), based on solution x.
309 */
310 void updateThermo(const doublereal* x, size_t j0, size_t j1) {
311 for (size_t j = j0; j <= j1; j++) {
312 setGas(x,j);
313 m_rho[j] = m_thermo->density();
314 m_wtm[j] = m_thermo->meanMolecularWeight();
315 m_cp[j] = m_thermo->cp_mass();
316 }
317 }
318
319 //! @name Solution components
320 //! @{
321
322 doublereal T(const doublereal* x, size_t j) const {
323 return x[index(c_offset_T, j)];
324 }
325 doublereal& T(doublereal* x, size_t j) {
326 return x[index(c_offset_T, j)];
327 }
328 doublereal T_prev(size_t j) const {
329 return prevSoln(c_offset_T, j);
330 }
331
332 doublereal rho_u(const doublereal* x, size_t j) const {
333 return m_rho[j]*x[index(c_offset_U, j)];
334 }
335
336 doublereal u(const doublereal* x, size_t j) const {
337 return x[index(c_offset_U, j)];
338 }
339
340 doublereal V(const doublereal* x, size_t j) const {
341 return x[index(c_offset_V, j)];
342 }
343 doublereal V_prev(size_t j) const {
344 return prevSoln(c_offset_V, j);
345 }
346
347 doublereal lambda(const doublereal* x, size_t j) const {
348 return x[index(c_offset_L, j)];
349 }
350
351 doublereal Y(const doublereal* x, size_t k, size_t j) const {
352 return x[index(c_offset_Y + k, j)];
353 }
354
355 doublereal& Y(doublereal* x, size_t k, size_t j) {
356 return x[index(c_offset_Y + k, j)];
357 }
358
359 doublereal Y_prev(size_t k, size_t j) const {
360 return prevSoln(c_offset_Y + k, j);
361 }
362
363 doublereal X(const doublereal* x, size_t k, size_t j) const {
364 return m_wtm[j]*Y(x,k,j)/m_wt[k];
365 }
366
367 doublereal flux(size_t k, size_t j) const {
368 return m_flux(k, j);
369 }
370 //! @}
371
372 //! @name convective spatial derivatives.
373 //! These use upwind differencing, assuming u(z) is negative
374 //! @{
375 doublereal dVdz(const doublereal* x, size_t j) const {
376 size_t jloc = (u(x,j) > 0.0 ? j : j + 1);
377 return (V(x,jloc) - V(x,jloc-1))/m_dz[jloc-1];
378 }
379
380 doublereal dYdz(const doublereal* x, size_t k, size_t j) const {
381 size_t jloc = (u(x,j) > 0.0 ? j : j + 1);
382 return (Y(x,k,jloc) - Y(x,k,jloc-1))/m_dz[jloc-1];
383 }
384
385 doublereal dTdz(const doublereal* x, size_t j) const {
386 size_t jloc = (u(x,j) > 0.0 ? j : j + 1);
387 return (T(x,jloc) - T(x,jloc-1))/m_dz[jloc-1];
388 }
389 //! @}
390
391 doublereal shear(const doublereal* x, size_t j) const {
392 doublereal c1 = m_visc[j-1]*(V(x,j) - V(x,j-1));
393 doublereal c2 = m_visc[j]*(V(x,j+1) - V(x,j));
394 return 2.0*(c2/(z(j+1) - z(j)) - c1/(z(j) - z(j-1)))/(z(j+1) - z(j-1));
395 }
396
397 doublereal divHeatFlux(const doublereal* x, size_t j) const {
398 doublereal c1 = m_tcon[j-1]*(T(x,j) - T(x,j-1));
399 doublereal c2 = m_tcon[j]*(T(x,j+1) - T(x,j));
400 return -2.0*(c2/(z(j+1) - z(j)) - c1/(z(j) - z(j-1)))/(z(j+1) - z(j-1));
401 }
402
403 size_t mindex(size_t k, size_t j, size_t m) {
404 return m*m_nsp*m_nsp + m_nsp*j + k;
405 }
406
407 //! Update the diffusive mass fluxes.
408 virtual void updateDiffFluxes(const doublereal* x, size_t j0, size_t j1);
409
410 //---------------------------------------------------------
411 // member data
412 //---------------------------------------------------------
413
414 doublereal m_press; // pressure
415
416 // grid parameters
417 vector_fp m_dz;
418
419 // mixture thermo properties
420 vector_fp m_rho;
421 vector_fp m_wtm;
422
423 // species thermo properties
424 vector_fp m_wt;
425 vector_fp m_cp;
426
427 // transport properties
428 vector_fp m_visc;
429 vector_fp m_tcon;
430 vector_fp m_diff;
431 vector_fp m_multidiff;
432 Array2D m_dthermal;
433 Array2D m_flux;
434
435 // production rates
436 Array2D m_wdot;
437
438 size_t m_nsp;
439
440 IdealGasPhase* m_thermo;
441 Kinetics* m_kin;
442 Transport* m_trans;
443
444 // boundary emissivities for the radiation calculations
445 doublereal m_epsilon_left;
446 doublereal m_epsilon_right;
447
448 //! Indices within the ThermoPhase of the radiating species. First index is
449 //! for CO2, second is for H2O.
450 std::vector<size_t> m_kRadiating;
451
452 // flags
453 std::vector<bool> m_do_energy;
454 bool m_do_soret;
455 std::vector<bool> m_do_species;
456 bool m_do_multicomponent;
457
458 //! flag for the radiative heat loss
460
461 //! radiative heat loss vector
463
464 // fixed T and Y values
465 vector_fp m_fixedtemp;
466 vector_fp m_zfix;
467 vector_fp m_tfix;
468
469 //! Index of species with a large mass fraction at each boundary, for which
470 //! the mass fraction may be calculated as 1 minus the sum of the other mass
471 //! fractions
473 size_t m_kExcessRight;
474
475 bool m_dovisc;
476
477 //! Update the transport properties at grid points in the range from `j0`
478 //! to `j1`, based on solution `x`.
479 virtual void updateTransport(doublereal* x, size_t j0, size_t j1);
480
481public:
482 //! Location of the point where temperature is fixed
483 double m_zfixed;
484
485 //! Temperature at the point used to fix the flame location
486 double m_tfixed;
487
488private:
489 vector_fp m_ybar;
490};
491
492}
493
494#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...
A map of string keys to values whose type can vary at runtime.
Definition: AnyMap.h:399
Base class for exceptions thrown by Cantera classes.
Definition: ctexceptions.h:61
Base class for one-dimensional domains.
Definition: Domain1D.h:38
int domainType()
Domain type flag.
Definition: Domain1D.h:53
double prevSoln(size_t n, size_t j) const
Value of component n at point j in the previous solution.
Definition: Domain1D.h:424
Class IdealGasPhase represents low-density gases that obey the ideal gas equation of state.
Public interface for kinetics managers.
Definition: Kinetics.h:114
virtual void getNetProductionRates(doublereal *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Definition: Kinetics.cpp:484
doublereal meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition: Phase.h:751
virtual double density() const
Density (kg/m^3).
Definition: Phase.h:679
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:295
virtual void evalRightBoundary(double *x, double *res, int *diag, double rdt)
Evaluate all residual components at the right boundary.
Definition: StFlow.cpp:1061
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:1092
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:472
virtual AnyMap serialize(const double *soln) const
Save the state of this domain as an AnyMap.
Definition: StFlow.cpp:863
double leftEmissivity() const
Return emissivitiy at left boundary.
Definition: StFlow.h:224
virtual void showSolution(const doublereal *x)
Print the solution.
Definition: StFlow.cpp:519
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:184
size_t rightExcessSpecies() const
Index of the species on the right boundary with the largest mass fraction.
Definition: StFlow.h:281
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:20
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:1023
void enableRadiation(bool doRadiation)
Turn radiation on / off.
Definition: StFlow.h:201
std::vector< size_t > m_kRadiating
Indices within the ThermoPhase of the radiating species.
Definition: StFlow.h:450
virtual void eval(size_t j, doublereal *x, doublereal *r, integer *mask, doublereal rdt)
Definition: StFlow.cpp:243
double rightEmissivity() const
Return emissivitiy at right boundary.
Definition: StFlow.h:227
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:804
double m_tfixed
Temperature at the point used to fix the flame location.
Definition: StFlow.h:486
bool radiationEnabled() const
Returns true if the radiation term in the energy equation is enabled.
Definition: StFlow.h:206
virtual bool componentActive(size_t n) const
Returns true if the specified component is an active part of the solver state.
Definition: StFlow.cpp:623
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:637
void getWdot(doublereal *x, size_t j)
Write the net production rates at point j into array m_wdot
Definition: StFlow.h:291
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:167
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:196
virtual std::string componentName(size_t n) const
Name of the nth component. May be overloaded.
Definition: StFlow.cpp:578
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:176
virtual void updateDiffFluxes(const doublereal *x, size_t j0, size_t j1)
Update the diffusive mass fluxes.
Definition: StFlow.cpp:536
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:107
size_t leftExcessSpecies() const
Index of the species on the left boundary with the largest mass fraction.
Definition: StFlow.h:276
double radiativeHeatLoss(size_t j) const
Return radiative heat loss at grid point j.
Definition: StFlow.h:211
double m_zfixed
Location of the point where temperature is fixed.
Definition: StFlow.h:483
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:310
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:489
vector_fp m_qdotRadiation
radiative heat loss vector
Definition: StFlow.h:462
void setKinetics(Kinetics &kin)
Set the kinetics manager. The kinetics manager must.
Definition: StFlow.h:79
virtual void resetBadValues(double *xg)
Definition: StFlow.cpp:146
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:168
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:271
virtual std::string flowType() const
Return the type of flow domain being represented, either "Free Flame" or "Axisymmetric Stagnation".
Definition: StFlow.h:182
virtual void setupGrid(size_t n, const doublereal *z)
called to set up initial grid, and after grid refinement
Definition: StFlow.cpp:131
void setTransport(Transport &trans)
set the transport manager
Definition: StFlow.cpp:156
void setAxisymmetricFlow()
Set flow configuration for axisymmetric counterflow or burner-stabilized flames, using specified inle...
Definition: StFlow.h:174
virtual size_t componentIndex(const std::string &name) const
index of component with name name.
Definition: StFlow.cpp:600
bool m_do_radiation
flag for the radiative heat loss
Definition: StFlow.h:459
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:768
Base class for transport property managers.
Class XML_Node is a tree-based representation of the contents of an XML file.
Definition: xml.h:103
Namespace for the Cantera kernel.
Definition: AnyMap.h:29
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:192
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:184