Loading [MathJax]/extensions/tex2jax.js
Cantera  3.2.0a1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Flow1D.cpp
Go to the documentation of this file.
1//! @file Flow1D.cpp
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
8#include "cantera/oneD/refine.h"
12#include "cantera/base/global.h"
13
14using namespace std;
15
16namespace Cantera
17{
18
19Flow1D::Flow1D(ThermoPhase* ph, size_t nsp, size_t points) :
20 Domain1D(nsp+c_offset_Y, points),
21 m_nsp(nsp)
22{
23 m_points = points;
24
25 if (ph == 0) {
26 return; // used to create a dummy object
27 }
28 m_thermo = ph;
29
30 size_t nsp2 = m_thermo->nSpecies();
31 if (nsp2 != m_nsp) {
32 m_nsp = nsp2;
34 }
35
36 // make a local copy of the species molecular weight vector
38
39 // set pressure based on associated thermo object
41
42 // the species mass fractions are the last components in the solution
43 // vector, so the total number of components is the number of species
44 // plus the offset of the first mass fraction.
46
47 // Turn off the energy equation at all points
48 m_do_energy.resize(m_points,false);
49
50 m_diff.resize(m_nsp*m_points);
55 m_dhk_dz.resize(m_nsp, m_points - 1, 0.0);
56 m_ybar.resize(m_nsp);
57 m_qdotRadiation.resize(m_points, 0.0);
58
59 //-------------- default solution bounds --------------------
60 setBounds(c_offset_U, -1e20, 1e20); // no bounds on u
61 setBounds(c_offset_V, -1e20, 1e20); // no bounds on V
62 setBounds(c_offset_T, 200.0, 2*m_thermo->maxTemp()); // temperature bounds
63 setBounds(c_offset_L, -1e20, 1e20); // lambda should be negative
64 setBounds(c_offset_E, -1e20, 1e20); // no bounds on electric field
65 setBounds(c_offset_Uo, -1e20, 1e20); // no bounds on Uo
66 // mass fraction bounds
67 for (size_t k = 0; k < m_nsp; k++) {
68 setBounds(c_offset_Y+k, -1.0e-7, 1.0e5);
69 }
70
71 //-------------------- grid refinement -------------------------
72 m_refiner->setActive(c_offset_U, false);
73 m_refiner->setActive(c_offset_V, false);
74 m_refiner->setActive(c_offset_T, false);
75 m_refiner->setActive(c_offset_L, false);
76 m_refiner->setActive(c_offset_Uo, false);
77
78 vector<double> gr;
79 for (size_t ng = 0; ng < m_points; ng++) {
80 gr.push_back(1.0*ng/m_points);
81 }
82 setupGrid(m_points, gr.data());
83
84 // Find indices for radiating species
85 m_kRadiating.resize(2, npos);
88}
89
90Flow1D::Flow1D(shared_ptr<ThermoPhase> th, size_t nsp, size_t points)
91 : Flow1D(th.get(), nsp, points)
92{
93 auto sol = Solution::create();
94 sol->setThermo(th);
95 setSolution(sol);
96}
97
98Flow1D::Flow1D(shared_ptr<Solution> sol, const string& id, size_t points)
99 : Flow1D(sol->thermo().get(), sol->thermo()->nSpecies(), points)
100{
101 setSolution(sol);
102 m_id = id;
103 m_kin = m_solution->kinetics().get();
104 m_trans = m_solution->transport().get();
105 if (m_trans->transportModel() == "none") {
106 throw CanteraError("Flow1D::Flow1D",
107 "An appropriate transport model\nshould be set when instantiating the "
108 "Solution ('gas') object.");
109 }
110 m_solution->registerChangedCallback(this, [this]() {
111 setKinetics(m_solution->kinetics());
112 setTransport(m_solution->transport());
113 });
114}
115
116Flow1D::~Flow1D()
117{
118 if (m_solution) {
119 m_solution->removeChangedCallback(this);
120 }
121}
122
123string Flow1D::domainType() const {
124 if (m_isFree) {
125 return "free-flow";
126 }
127 if (m_usesLambda) {
128 return "axisymmetric-flow";
129 }
130 return "unstrained-flow";
131}
132
133void Flow1D::setKinetics(shared_ptr<Kinetics> kin)
134{
135 m_kin = kin.get();
136 m_solution->setKinetics(kin);
137}
138
139void Flow1D::setTransport(shared_ptr<Transport> trans)
140{
141 if (!trans) {
142 throw CanteraError("Flow1D::setTransport", "Unable to set empty transport.");
143 }
144 m_trans = trans.get();
145 if (m_trans->transportModel() == "none") {
146 throw CanteraError("Flow1D::setTransport", "Invalid Transport model 'none'.");
147 }
148 m_do_multicomponent = (m_trans->transportModel() == "multicomponent" ||
149 m_trans->transportModel() == "multicomponent-CK");
150
151 m_diff.resize(m_nsp * m_points);
155 }
156 m_solution->setTransport(trans);
157}
158
159void Flow1D::resize(size_t ncomponents, size_t points)
160{
161 Domain1D::resize(ncomponents, points);
162 m_rho.resize(m_points, 0.0);
163 m_wtm.resize(m_points, 0.0);
164 m_cp.resize(m_points, 0.0);
165 m_visc.resize(m_points, 0.0);
166 m_tcon.resize(m_points, 0.0);
167
168 m_diff.resize(m_nsp*m_points);
172 }
175 m_hk.resize(m_nsp, m_points, 0.0);
176 m_dhk_dz.resize(m_nsp, m_points - 1, 0.0);
177 m_do_energy.resize(m_points,false);
178 m_qdotRadiation.resize(m_points, 0.0);
179 m_fixedtemp.resize(m_points);
180
181 m_dz.resize(m_points-1);
182 m_z.resize(m_points);
183}
184
185void Flow1D::setupGrid(size_t n, const double* z)
186{
187 resize(m_nv, n);
188
189 m_z[0] = z[0];
190 for (size_t j = 1; j < m_points; j++) {
191 if (z[j] <= z[j-1]) {
192 throw CanteraError("Flow1D::setupGrid",
193 "grid points must be monotonically increasing");
194 }
195 m_z[j] = z[j];
196 m_dz[j-1] = m_z[j] - m_z[j-1];
197 }
198}
199
201{
202 double* x = xg + loc();
203 for (size_t j = 0; j < m_points; j++) {
204 double* Y = x + m_nv*j + c_offset_Y;
207 }
208}
209
210void Flow1D::setTransportModel(const string& model)
211{
212 if (model == "none") {
213 throw CanteraError("Flow1D::setTransportModel",
214 "Invalid Transport model 'none'.");
215 }
216 m_solution->setTransportModel(model);
217 Flow1D::setTransport(m_solution->transport());
218}
219
221 return m_trans->transportModel();
222}
223
226 if (transportModel() != "mixture-averaged-CK" &&
227 transportModel() != "mixture-averaged") {
228 warn_user("Flow1D::setFluxGradientBasis",
229 "Setting fluxGradientBasis only affects "
230 "the mixture-averaged diffusion model.");
231 }
232}
233
235{
236 for (size_t j = 0; j < m_points; j++) {
237 T(x,j) = m_thermo->temperature();
238 m_thermo->getMassFractions(&Y(x, 0, j));
239 m_rho[j] = m_thermo->density();
240 }
241}
242
243void Flow1D::setGas(const double* x, size_t j)
244{
246 const double* yy = x + m_nv*j + c_offset_Y;
249}
250
251void Flow1D::setGasAtMidpoint(const double* x, size_t j)
252{
253 m_thermo->setTemperature(0.5*(T(x,j)+T(x,j+1)));
254 const double* yy_j = x + m_nv*j + c_offset_Y;
255 const double* yy_j_plus1 = x + m_nv*(j+1) + c_offset_Y;
256 for (size_t k = 0; k < m_nsp; k++) {
257 m_ybar[k] = 0.5*(yy_j[k] + yy_j_plus1[k]);
258 }
261}
262
263void Flow1D::_finalize(const double* x)
264{
266 throw CanteraError("Flow1D::_finalize",
267 "Thermal diffusion (the Soret effect) is enabled, and requires "
268 "using a multicomponent transport model.");
269 }
270
271 size_t nz = m_zfix.size();
272 bool e = m_do_energy[0];
273 for (size_t j = 0; j < m_points; j++) {
274 if (e || nz == 0) {
275 m_fixedtemp[j] = T(x, j);
276 } else {
277 double zz = (z(j) - z(0))/(z(m_points - 1) - z(0));
278 double tt = linearInterp(zz, m_zfix, m_tfix);
279 m_fixedtemp[j] = tt;
280 }
281 }
282 if (e) {
284 }
285
286 if (m_isFree) {
287 // If the domain contains the temperature fixed point, make sure that it
288 // is correctly set. This may be necessary when the grid has been modified
289 // externally.
290 if (m_tfixed != Undef) {
291 for (size_t j = 0; j < m_points; j++) {
292 if (z(j) == m_zfixed) {
293 return; // fixed point is already set correctly
294 }
295 }
296
297 for (size_t j = 0; j < m_points - 1; j++) {
298 // Find where the temperature profile crosses the current
299 // fixed temperature.
300 if ((T(x, j) - m_tfixed) * (T(x, j+1) - m_tfixed) <= 0.0) {
301 m_tfixed = T(x, j+1);
302 m_zfixed = z(j+1);
303 return;
304 }
305 }
306 }
307 }
308}
309
310void Flow1D::eval(size_t jGlobal, double* xGlobal, double* rsdGlobal,
311 integer* diagGlobal, double rdt)
312{
313 // If evaluating a Jacobian, and the global point is outside the domain of
314 // influence for this domain, then skip evaluating the residual
315 if (jGlobal != npos && (jGlobal + 1 < firstPoint() || jGlobal > lastPoint() + 1)) {
316 return;
317 }
318
319 // start of local part of global arrays
320 double* x = xGlobal + loc();
321 double* rsd = rsdGlobal + loc();
322 integer* diag = diagGlobal + loc();
323
324 size_t jmin, jmax;
325 if (jGlobal == npos) { // evaluate all points
326 jmin = 0;
327 jmax = m_points - 1;
328 } else { // evaluate points for Jacobian
329 size_t jpt = (jGlobal == 0) ? 0 : jGlobal - firstPoint();
330 jmin = std::max<size_t>(jpt, 1) - 1;
331 jmax = std::min(jpt+1,m_points-1);
332 }
333
334 updateProperties(jGlobal, x, jmin, jmax);
335
336 if (m_do_radiation) { // Calculation of qdotRadiation
337 computeRadiation(x, jmin, jmax);
338 }
339
340 evalContinuity(x, rsd, diag, rdt, jmin, jmax);
341 evalMomentum(x, rsd, diag, rdt, jmin, jmax);
342 evalEnergy(x, rsd, diag, rdt, jmin, jmax);
343 evalLambda(x, rsd, diag, rdt, jmin, jmax);
344 evalElectricField(x, rsd, diag, rdt, jmin, jmax);
345 evalUo(x, rsd, diag, rdt, jmin, jmax);
346 evalSpecies(x, rsd, diag, rdt, jmin, jmax);
347}
348
349void Flow1D::updateProperties(size_t jg, double* x, size_t jmin, size_t jmax)
350{
351 // properties are computed for grid points from j0 to j1
352 size_t j0 = std::max<size_t>(jmin, 1) - 1;
353 size_t j1 = std::min(jmax+1,m_points-1);
354
355 updateThermo(x, j0, j1);
356 if (jg == npos || m_force_full_update) {
357 // update transport properties only if a Jacobian is not being
358 // evaluated, or if specifically requested
359 updateTransport(x, j0, j1);
360 }
361 if (jg == npos) {
362 double* Yleft = x + index(c_offset_Y, jmin);
363 m_kExcessLeft = distance(Yleft, max_element(Yleft, Yleft + m_nsp));
364 double* Yright = x + index(c_offset_Y, jmax);
365 m_kExcessRight = distance(Yright, max_element(Yright, Yright + m_nsp));
366 }
367
368 // update the species diffusive mass fluxes whether or not a
369 // Jacobian is being evaluated
370 updateDiffFluxes(x, j0, j1);
371}
372
373void Flow1D::updateTransport(double* x, size_t j0, size_t j1)
374{
376 for (size_t j = j0; j < j1; j++) {
377 setGasAtMidpoint(x,j);
378 double wtm = m_thermo->meanMolecularWeight();
379 double rho = m_thermo->density();
380 m_visc[j] = (m_dovisc ? m_trans->viscosity() : 0.0);
382
383 // Use m_diff as storage for the factor outside the summation
384 for (size_t k = 0; k < m_nsp; k++) {
385 m_diff[k+j*m_nsp] = m_wt[k] * rho / (wtm*wtm);
386 }
387
389 if (m_do_soret) {
391 }
392 }
393 } else { // mixture averaged transport
394 for (size_t j = j0; j < j1; j++) {
395 setGasAtMidpoint(x,j);
396 m_visc[j] = (m_dovisc ? m_trans->viscosity() : 0.0);
397
398 if (m_fluxGradientBasis == ThermoBasis::molar) {
400 } else {
402 }
403
404 double rho = m_thermo->density();
405
406 if (m_fluxGradientBasis == ThermoBasis::molar) {
407 double wtm = m_thermo->meanMolecularWeight();
408 for (size_t k=0; k < m_nsp; k++) {
409 m_diff[k+j*m_nsp] *= m_wt[k] * rho / wtm;
410 }
411 } else {
412 for (size_t k=0; k < m_nsp; k++) {
413 m_diff[k+j*m_nsp] *= rho;
414 }
415 }
417 }
418 }
419}
420
421void Flow1D::updateDiffFluxes(const double* x, size_t j0, size_t j1)
422{
424 for (size_t j = j0; j < j1; j++) {
425 double dz = z(j+1) - z(j);
426 for (size_t k = 0; k < m_nsp; k++) {
427 double sum = 0.0;
428 for (size_t m = 0; m < m_nsp; m++) {
429 sum += m_wt[m] * m_multidiff[mindex(k,m,j)] * (X(x,m,j+1)-X(x,m,j));
430 }
431 m_flux(k,j) = sum * m_diff[k+j*m_nsp] / dz;
432 }
433 }
434 } else {
435 for (size_t j = j0; j < j1; j++) {
436 double sum = 0.0;
437 double dz = z(j+1) - z(j);
438 if (m_fluxGradientBasis == ThermoBasis::molar) {
439 for (size_t k = 0; k < m_nsp; k++) {
440 m_flux(k,j) = m_diff[k+m_nsp*j] * (X(x,k,j) - X(x,k,j+1))/dz;
441 sum -= m_flux(k,j);
442 }
443 } else {
444 for (size_t k = 0; k < m_nsp; k++) {
445 m_flux(k,j) = m_diff[k+m_nsp*j] * (Y(x,k,j) - Y(x,k,j+1))/dz;
446 sum -= m_flux(k,j);
447 }
448 }
449 // correction flux to ensure that \sum_k Y_k V_k = 0.
450 for (size_t k = 0; k < m_nsp; k++) {
451 m_flux(k,j) += sum*Y(x,k,j);
452 }
453 }
454 }
455
456 if (m_do_soret) {
457 for (size_t m = j0; m < j1; m++) {
458 double gradlogT = 2.0 * (T(x,m+1) - T(x,m)) /
459 ((T(x,m+1) + T(x,m)) * (z(m+1) - z(m)));
460 for (size_t k = 0; k < m_nsp; k++) {
461 m_flux(k,m) -= m_dthermal(k,m)*gradlogT;
462 }
463 }
464 }
465}
466
467void Flow1D::computeRadiation(double* x, size_t jmin, size_t jmax)
468{
469 // Variable definitions for the Planck absorption coefficient and the
470 // radiation calculation:
471 double k_P_ref = 1.0*OneAtm;
472
473 // Polynomial coefficients:
474 const double c_H2O[6] = {-0.23093, -1.12390, 9.41530, -2.99880,
475 0.51382, -1.86840e-5};
476 const double c_CO2[6] = {18.741, -121.310, 273.500, -194.050,
477 56.310, -5.8169};
478
479 // Calculation of the two boundary values
480 double boundary_Rad_left = m_epsilon_left * StefanBoltz * pow(T(x, 0), 4);
481 double boundary_Rad_right = m_epsilon_right * StefanBoltz * pow(T(x, m_points - 1), 4);
482
483 for (size_t j = jmin; j < jmax; j++) {
484 // calculation of the mean Planck absorption coefficient
485 double k_P = 0;
486 // Absorption coefficient for H2O
487 if (m_kRadiating[1] != npos) {
488 double k_P_H2O = 0;
489 for (size_t n = 0; n <= 5; n++) {
490 k_P_H2O += c_H2O[n] * pow(1000 / T(x, j), (double) n);
491 }
492 k_P_H2O /= k_P_ref;
493 k_P += m_press * X(x, m_kRadiating[1], j) * k_P_H2O;
494 }
495 // Absorption coefficient for CO2
496 if (m_kRadiating[0] != npos) {
497 double k_P_CO2 = 0;
498 for (size_t n = 0; n <= 5; n++) {
499 k_P_CO2 += c_CO2[n] * pow(1000 / T(x, j), (double) n);
500 }
501 k_P_CO2 /= k_P_ref;
502 k_P += m_press * X(x, m_kRadiating[0], j) * k_P_CO2;
503 }
504
505 // Calculation of the radiative heat loss term
506 double radiative_heat_loss = 2 * k_P *(2 * StefanBoltz * pow(T(x, j), 4)
507 - boundary_Rad_left - boundary_Rad_right);
508
509 // set the radiative heat loss vector
510 m_qdotRadiation[j] = radiative_heat_loss;
511 }
512}
513
514void Flow1D::evalContinuity(double* x, double* rsd, int* diag,
515 double rdt, size_t jmin, size_t jmax)
516{
517 // The left boundary has the same form for all cases.
518 if (jmin == 0) { // left boundary
519 rsd[index(c_offset_U, jmin)] = -(rho_u(x, jmin+1) - rho_u(x, jmin))/m_dz[jmin]
520 -(density(jmin+1)*V(x, jmin+1)
521 + density(jmin)*V(x, jmin));
522 diag[index(c_offset_U, jmin)] = 0; // Algebraic constraint
523 }
524
525 if (jmax == m_points - 1) { // right boundary
526 if (m_usesLambda) { // zero mass flux
527 rsd[index(c_offset_U, jmax)] = rho_u(x, jmax);
528 } else { // zero gradient, same for unstrained or free-flow
529 rsd[index(c_offset_U, jmax)] = rho_u(x, jmax) - rho_u(x, jmax-1);
530 }
531 diag[index(c_offset_U, jmax)] = 0; // Algebraic constraint
532 }
533
534 // j0 and j1 are constrained to only interior points
535 size_t j0 = std::max<size_t>(jmin, 1);
536 size_t j1 = std::min(jmax, m_points-2);
537 if (m_usesLambda) { // "axisymmetric-flow"
538 for (size_t j = j0; j <= j1; j++) { // interior points
539 // For "axisymmetric-flow", the continuity equation propagates the
540 // mass flow rate information to the left (j+1 -> j) from the value
541 // specified at the right boundary. The lambda information propagates
542 // in the opposite direction.
543 rsd[index(c_offset_U, j)] = -(rho_u(x, j+1) - rho_u(x, j))/m_dz[j]
544 -(density(j+1)*V(x, j+1) + density(j)*V(x, j));
545 diag[index(c_offset_U, j)] = 0; // Algebraic constraint
546 }
547 } else if (m_isFree) { // "free-flow"
548 for (size_t j = j0; j <= j1; j++) {
549 // terms involving V are zero as V=0 by definition
550 if (z(j) > m_zfixed) {
551 rsd[index(c_offset_U, j)] = -(rho_u(x, j) - rho_u(x, j-1))/m_dz[j-1];
552 } else if (z(j) == m_zfixed) {
553 if (m_do_energy[j]) {
554 rsd[index(c_offset_U, j)] = (T(x, j) - m_tfixed);
555 } else {
556 rsd[index(c_offset_U, j)] = (rho_u(x, j) - m_rho[0]*0.3); // why 0.3?
557 }
558 } else { // z(j) < m_zfixed
559 rsd[index(c_offset_U, j)] = -(rho_u(x, j+1) - rho_u(x, j))/m_dz[j];
560 }
561 diag[index(c_offset_U, j)] = 0; // Algebraic constraint
562 }
563 } else { // "unstrained-flow" (fixed mass flow rate)
564 for (size_t j = j0; j <= j1; j++) {
565 rsd[index(c_offset_U, j)] = rho_u(x, j) - rho_u(x, j-1);
566 diag[index(c_offset_U, j)] = 0; // Algebraic constraint
567 }
568 }
569}
570
571void Flow1D::evalMomentum(double* x, double* rsd, int* diag,
572 double rdt, size_t jmin, size_t jmax)
573{
574 if (!m_usesLambda) { //disable this equation
575 for (size_t j = jmin; j <= jmax; j++) {
576 rsd[index(c_offset_V, j)] = V(x, j);
577 diag[index(c_offset_V, j)] = 0;
578 }
579 return;
580 }
581
582 if (jmin == 0) { // left boundary
583 rsd[index(c_offset_V, jmin)] = V(x, jmin);
584 }
585
586 if (jmax == m_points - 1) { // right boundary
587 rsd[index(c_offset_V, jmax)] = V(x, jmax);
588 diag[index(c_offset_V, jmax)] = 0;
589 }
590
591 // j0 and j1 are constrained to only interior points
592 size_t j0 = std::max<size_t>(jmin, 1);
593 size_t j1 = std::min(jmax, m_points-2);
594 for (size_t j = j0; j <= j1; j++) { // interior points
595 rsd[index(c_offset_V, j)] = (shear(x, j) - lambda(x, j)
596 - rho_u(x, j) * dVdz(x, j)
597 - m_rho[j] * V(x, j) * V(x, j)) / m_rho[j];
598 if (!m_twoPointControl) {
599 rsd[index(c_offset_V, j)] -= rdt * (V(x, j) - V_prev(j));
600 diag[index(c_offset_V, j)] = 1;
601 } else {
602 diag[index(c_offset_V, j)] = 0;
603 }
604 }
605}
606
607void Flow1D::evalLambda(double* x, double* rsd, int* diag,
608 double rdt, size_t jmin, size_t jmax)
609{
610 if (!m_usesLambda) { // disable this equation
611 for (size_t j = jmin; j <= jmax; j++) {
612 rsd[index(c_offset_L, j)] = lambda(x, j);
613 diag[index(c_offset_L, j)] = 0;
614 }
615 return;
616 }
617
618 if (jmin == 0) { // left boundary
619 if (m_twoPointControl) {
620 rsd[index(c_offset_L, jmin)] = lambda(x, jmin+1) - lambda(x, jmin);
621 } else {
622 rsd[index(c_offset_L, jmin)] = -rho_u(x, jmin);
623 }
624 }
625
626 if (jmax == m_points - 1) { // right boundary
627 rsd[index(c_offset_L, jmax)] = lambda(x, jmax) - lambda(x, jmax-1);
628 diag[index(c_offset_L, jmax)] = 0;
629 }
630
631 // j0 and j1 are constrained to only interior points
632 size_t j0 = std::max<size_t>(jmin, 1);
633 size_t j1 = std::min(jmax, m_points-2);
634 for (size_t j = j0; j <= j1; j++) { // interior points
635 if (m_twoPointControl) {
636 if (z(j) == m_zLeft) {
637 rsd[index(c_offset_L, j)] = T(x,j) - m_tLeft;
638 } else if (z(j) > m_zLeft) {
639 rsd[index(c_offset_L, j)] = lambda(x, j) - lambda(x, j-1);
640 } else if (z(j) < m_zLeft) {
641 rsd[index(c_offset_L, j)] = lambda(x, j) - lambda(x, j+1);
642 }
643 } else {
644 rsd[index(c_offset_L, j)] = lambda(x, j) - lambda(x, j-1);
645 }
646 diag[index(c_offset_L, j)] = 0;
647 }
648}
649
650void Flow1D::evalEnergy(double* x, double* rsd, int* diag,
651 double rdt, size_t jmin, size_t jmax)
652{
653 if (jmin == 0) { // left boundary
654 rsd[index(c_offset_T, jmin)] = T(x, jmin);
655 }
656
657 if (jmax == m_points - 1) { // right boundary
658 rsd[index(c_offset_T, jmax)] = T(x, jmax);
659 }
660
661 // j0 and j1 are constrained to only interior points
662 size_t j0 = std::max<size_t>(jmin, 1);
663 size_t j1 = std::min(jmax, m_points-2);
664 for (size_t j = j0; j <= j1; j++) {
665 if (m_do_energy[j]) {
666 grad_hk(x, j);
667 double sum = 0.0;
668 for (size_t k = 0; k < m_nsp; k++) {
669 double flxk = 0.5*(m_flux(k, j-1) + m_flux(k, j));
670 sum += m_wdot(k, j)*m_hk(k, j);
671 sum += flxk * m_dhk_dz(k, j) / m_wt[k];
672 }
673
674 rsd[index(c_offset_T, j)] = - m_cp[j]*rho_u(x, j)*dTdz(x, j)
675 - conduction(x, j) - sum;
676 rsd[index(c_offset_T, j)] /= (m_rho[j]*m_cp[j]);
677 rsd[index(c_offset_T, j)] -= (m_qdotRadiation[j] / (m_rho[j] * m_cp[j]));
678 if (!m_twoPointControl || (m_z[j] != m_tLeft && m_z[j] != m_tRight)) {
679 rsd[index(c_offset_T, j)] -= rdt*(T(x, j) - T_prev(j));
680 diag[index(c_offset_T, j)] = 1;
681 } else {
682 diag[index(c_offset_T, j)] = 0;
683 }
684 } else {
685 // residual equations if the energy equation is disabled
686 rsd[index(c_offset_T, j)] = T(x, j) - T_fixed(j);
687 diag[index(c_offset_T, j)] = 0;
688 }
689 }
690}
691
692void Flow1D::evalUo(double* x, double* rsd, int* diag,
693 double rdt, size_t jmin, size_t jmax)
694{
695 if (!m_twoPointControl) { // disable this equation
696 for (size_t j = jmin; j <= jmax; j++) {
697 rsd[index(c_offset_Uo, j)] = Uo(x, j);
698 diag[index(c_offset_Uo, j)] = 0;
699 }
700 return;
701 }
702
703 if (jmin == 0) { // left boundary
704 rsd[index(c_offset_Uo, jmin)] = Uo(x, jmin+1) - Uo(x, jmin);
705 diag[index(c_offset_Uo, jmin)] = 0;
706 }
707
708 if (jmax == m_points - 1) { // right boundary
710 rsd[index(c_offset_Uo, jmax)] = Uo(x, jmax) - Uo(x, jmax-1);
711 }
712 diag[index(c_offset_Uo, jmax)] = 0;
713 }
714
715 // j0 and j1 are constrained to only interior points
716 size_t j0 = std::max<size_t>(jmin, 1);
717 size_t j1 = std::min(jmax, m_points-2);
718 for (size_t j = j0; j <= j1; j++) { // interior points
719 if (m_twoPointControl) {
720 if (z(j) == m_zRight) {
721 rsd[index(c_offset_Uo, j)] = T(x, j) - m_tRight;
722 } else if (z(j) > m_zRight) {
723 rsd[index(c_offset_Uo, j)] = Uo(x, j) - Uo(x, j-1);
724 } else if (z(j) < m_zRight) {
725 rsd[index(c_offset_Uo, j)] = Uo(x, j) - Uo(x, j+1);
726 }
727 }
728 diag[index(c_offset_Uo, j)] = 0;
729 }
730}
731
732void Flow1D::evalSpecies(double* x, double* rsd, int* diag,
733 double rdt, size_t jmin, size_t jmax)
734{
735 if (jmin == 0) { // left boundary
736 double sum = 0.0;
737 for (size_t k = 0; k < m_nsp; k++) {
738 sum += Y(x,k,jmin);
739 rsd[index(c_offset_Y+k, jmin)] = -(m_flux(k, jmin) +
740 rho_u(x, jmin) * Y(x, k, jmin));
741 }
742 rsd[index(c_offset_Y + leftExcessSpecies(), jmin)] = 1.0 - sum;
743 diag[index(c_offset_Y + leftExcessSpecies(), jmin)] = 0;
744 }
745
746 if (jmax == m_points - 1) { // right boundary
747 double sum = 0.0;
748 for (size_t k = 0; k < m_nsp; k++) {
749 sum += Y(x,k,jmax);
750 rsd[index(k+c_offset_Y, jmax)] = m_flux(k, jmax-1) +
751 rho_u(x, jmax)*Y(x, k, jmax);
752 }
753 rsd[index(c_offset_Y + rightExcessSpecies(), jmax)] = 1.0 - sum;
754 diag[index(c_offset_Y + rightExcessSpecies(), jmax)] = 0;
755 }
756
757 // j0 and j1 are constrained to only interior points
758 size_t j0 = std::max<size_t>(jmin, 1);
759 size_t j1 = std::min(jmax, m_points-2);
760 for (size_t j = j0; j <= j1; j++) {
761 for (size_t k = 0; k < m_nsp; k++) {
762 double convec = rho_u(x, j)*dYdz(x, k, j);
763 double diffus = 2*(m_flux(k, j) - m_flux(k, j-1)) / (z(j+1) - z(j-1));
764 rsd[index(c_offset_Y + k, j)] = (m_wt[k]*m_wdot(k, j)
765 - convec - diffus) / m_rho[j]
766 - rdt*(Y(x, k, j) - Y_prev(k, j));
767 diag[index(c_offset_Y + k, j)] = 1;
768 }
769 }
770}
771
772void Flow1D::evalElectricField(double* x, double* rsd, int* diag,
773 double rdt, size_t jmin, size_t jmax)
774{
775 for (size_t j = jmin; j <= jmax; j++) {
776 // The same value is used for left/right/interior points
777 rsd[index(c_offset_E, j)] = x[index(c_offset_E, j)];
778 }
779}
780
781void Flow1D::show(const double* x)
782{
783 writelog(" Pressure: {:10.4g} Pa\n", m_press);
784
786
787 if (m_do_radiation) {
788 writeline('-', 79, false, true);
789 writelog("\n z radiative heat loss");
790 writeline('-', 79, false, true);
791 for (size_t j = 0; j < m_points; j++) {
792 writelog("\n {:10.4g} {:10.4g}", m_z[j], m_qdotRadiation[j]);
793 }
794 writelog("\n");
795 }
796}
797
798string Flow1D::componentName(size_t n) const
799{
800 switch (n) {
801 case c_offset_U:
802 return "velocity";
803 case c_offset_V:
804 return "spread_rate";
805 case c_offset_T:
806 return "T";
807 case c_offset_L:
808 return "lambda";
809 case c_offset_E:
810 return "eField";
811 case c_offset_Uo:
812 return "Uo";
813 default:
814 if (n >= c_offset_Y && n < (c_offset_Y + m_nsp)) {
815 return m_thermo->speciesName(n - c_offset_Y);
816 } else {
817 return "<unknown>";
818 }
819 }
820}
821
822size_t Flow1D::componentIndex(const string& name) const
823{
824 if (name=="velocity") {
825 return c_offset_U;
826 } else if (name=="spread_rate") {
827 return c_offset_V;
828 } else if (name=="T") {
829 return c_offset_T;
830 } else if (name=="lambda") {
831 return c_offset_L;
832 } else if (name == "eField") {
833 return c_offset_E;
834 } else if (name == "Uo") {
835 return c_offset_Uo;
836 } else {
837 for (size_t n=c_offset_Y; n<m_nsp+c_offset_Y; n++) {
838 if (componentName(n)==name) {
839 return n;
840 }
841 }
842 throw CanteraError("Flow1D1D::componentIndex",
843 "no component named " + name);
844 }
845}
846
847bool Flow1D::componentActive(size_t n) const
848{
849 switch (n) {
850 case c_offset_V: // spread_rate
851 return m_usesLambda;
852 case c_offset_L: // lambda
853 return m_usesLambda;
854 case c_offset_E: // eField
855 return false;
856 case c_offset_Uo: // oxidizer velocity for two-point control
857 return twoPointControlEnabled();
858 default:
859 return true;
860 }
861}
862
864{
865 AnyMap state = Domain1D::getMeta();
866 state["transport-model"] = m_trans->transportModel();
867
868 state["phase"]["name"] = m_thermo->name();
869 AnyValue source = m_thermo->input().getMetadata("filename");
870 state["phase"]["source"] = source.empty() ? "<unknown>" : source.asString();
871
872 state["radiation-enabled"] = m_do_radiation;
873 if (m_do_radiation) {
874 state["emissivity-left"] = m_epsilon_left;
875 state["emissivity-right"] = m_epsilon_right;
876 }
877
878 set<bool> energy_flags(m_do_energy.begin(), m_do_energy.end());
879 if (energy_flags.size() == 1) {
880 state["energy-enabled"] = m_do_energy[0];
881 } else {
882 state["energy-enabled"] = m_do_energy;
883 }
884
885 state["Soret-enabled"] = m_do_soret;
886
887 state["flux-gradient-basis"] = static_cast<long int>(m_fluxGradientBasis);
888
889 state["refine-criteria"]["ratio"] = m_refiner->maxRatio();
890 state["refine-criteria"]["slope"] = m_refiner->maxDelta();
891 state["refine-criteria"]["curve"] = m_refiner->maxSlope();
892 state["refine-criteria"]["prune"] = m_refiner->prune();
893 state["refine-criteria"]["grid-min"] = m_refiner->gridMin();
894 state["refine-criteria"]["max-points"] =
895 static_cast<long int>(m_refiner->maxPoints());
896
897 if (m_zfixed != Undef) {
898 state["fixed-point"]["location"] = m_zfixed;
899 state["fixed-point"]["temperature"] = m_tfixed;
900 }
901
902 // Two-point control meta data
903 if (m_twoPointControl) {
904 state["continuation-method"]["type"] = "two-point";
905 state["continuation-method"]["left-location"] = m_zLeft;
906 state["continuation-method"]["right-location"] = m_zRight;
907 state["continuation-method"]["left-temperature"] = m_tLeft;
908 state["continuation-method"]["right-temperature"] = m_tRight;
909 }
910
911 return state;
912}
913
914shared_ptr<SolutionArray> Flow1D::asArray(const double* soln) const
915{
916 auto arr = SolutionArray::create(
917 m_solution, static_cast<int>(nPoints()), getMeta());
918 arr->addExtra("grid", false); // leading entry
920 value = m_z;
921 arr->setComponent("grid", value);
922 vector<double> data(nPoints());
923 for (size_t i = 0; i < nComponents(); i++) {
924 if (componentActive(i)) {
925 auto name = componentName(i);
926 for (size_t j = 0; j < nPoints(); j++) {
927 data[j] = soln[index(i, j)];
928 }
929 if (!arr->hasComponent(name)) {
930 arr->addExtra(name, componentIndex(name) > c_offset_Y);
931 }
932 value = data;
933 arr->setComponent(name, value);
934 }
935 }
936 value = m_rho;
937 arr->setComponent("D", value); // use density rather than pressure
938
939 if (m_do_radiation) {
940 arr->addExtra("radiative-heat-loss", true); // add at end
942 arr->setComponent("radiative-heat-loss", value);
943 }
944
945 return arr;
946}
947
948void Flow1D::fromArray(SolutionArray& arr, double* soln)
949{
950 Domain1D::setMeta(arr.meta());
951 arr.setLoc(0);
952 auto phase = arr.thermo();
954
955 const auto grid = arr.getComponent("grid").as<vector<double>>();
956 setupGrid(nPoints(), &grid[0]);
957 setMeta(arr.meta()); // can affect which components are active
958
959 for (size_t i = 0; i < nComponents(); i++) {
960 if (!componentActive(i)) {
961 continue;
962 }
963 string name = componentName(i);
964 if (arr.hasComponent(name)) {
965 const vector<double> data = arr.getComponent(name).as<vector<double>>();
966 for (size_t j = 0; j < nPoints(); j++) {
967 soln[index(i,j)] = data[j];
968 }
969 } else {
970 warn_user("Flow1D::fromArray", "Saved state does not contain values for "
971 "component '{}' in domain '{}'.", name, id());
972 }
973 }
974
975 updateProperties(npos, soln + loc(), 0, m_points - 1);
976}
977
978void Flow1D::setMeta(const AnyMap& state)
979{
980 if (state.hasKey("energy-enabled")) {
981 const AnyValue& ee = state["energy-enabled"];
982 if (ee.isScalar()) {
983 m_do_energy.assign(nPoints(), ee.asBool());
984 } else {
985 m_do_energy = ee.asVector<bool>(nPoints());
986 }
987 }
988
989 if (state.hasKey("transport-model")) {
990 setTransportModel(state["transport-model"].asString());
991 }
992
993 if (state.hasKey("Soret-enabled")) {
994 m_do_soret = state["Soret-enabled"].asBool();
995 }
996
997 if (state.hasKey("flux-gradient-basis")) {
998 m_fluxGradientBasis = static_cast<ThermoBasis>(
999 state["flux-gradient-basis"].asInt());
1000 }
1001
1002 if (state.hasKey("radiation-enabled")) {
1003 m_do_radiation = state["radiation-enabled"].asBool();
1004 if (m_do_radiation) {
1005 m_epsilon_left = state["emissivity-left"].asDouble();
1006 m_epsilon_right = state["emissivity-right"].asDouble();
1007 }
1008 }
1009
1010 if (state.hasKey("refine-criteria")) {
1011 const AnyMap& criteria = state["refine-criteria"].as<AnyMap>();
1012 double ratio = criteria.getDouble("ratio", m_refiner->maxRatio());
1013 double slope = criteria.getDouble("slope", m_refiner->maxDelta());
1014 double curve = criteria.getDouble("curve", m_refiner->maxSlope());
1015 double prune = criteria.getDouble("prune", m_refiner->prune());
1016 m_refiner->setCriteria(ratio, slope, curve, prune);
1017
1018 if (criteria.hasKey("grid-min")) {
1019 m_refiner->setGridMin(criteria["grid-min"].asDouble());
1020 }
1021 if (criteria.hasKey("max-points")) {
1022 m_refiner->setMaxPoints(criteria["max-points"].asInt());
1023 }
1024 }
1025
1026 if (state.hasKey("fixed-point")) {
1027 m_zfixed = state["fixed-point"]["location"].asDouble();
1028 m_tfixed = state["fixed-point"]["temperature"].asDouble();
1029 }
1030
1031 // Two-point control meta data
1032 if (state.hasKey("continuation-method")) {
1033 const AnyMap& cm = state["continuation-method"].as<AnyMap>();
1034 if (cm["type"] == "two-point") {
1035 m_twoPointControl = true;
1036 m_zLeft = cm["left-location"].asDouble();
1037 m_zRight = cm["right-location"].asDouble();
1038 m_tLeft = cm["left-temperature"].asDouble();
1039 m_tRight = cm["right-temperature"].asDouble();
1040 } else {
1041 warn_user("Flow1D::setMeta", "Unknown continuation method '{}'.",
1042 cm["type"].asString());
1043 }
1044 }
1045}
1046
1048{
1049 bool changed = false;
1050 if (j == npos) {
1051 for (size_t i = 0; i < m_points; i++) {
1052 if (!m_do_energy[i]) {
1053 changed = true;
1054 }
1055 m_do_energy[i] = true;
1056 }
1057 } else {
1058 if (!m_do_energy[j]) {
1059 changed = true;
1060 }
1061 m_do_energy[j] = true;
1062 }
1063 m_refiner->setActive(c_offset_U, true);
1064 m_refiner->setActive(c_offset_V, true);
1065 m_refiner->setActive(c_offset_T, true);
1066 if (changed) {
1067 needJacUpdate();
1068 }
1069}
1070
1072{
1073 throw NotImplementedError("Flow1D::getSolvingStage",
1074 "Not used by '{}' objects.", type());
1075}
1076
1077void Flow1D::setSolvingStage(const size_t stage)
1078{
1079 throw NotImplementedError("Flow1D::setSolvingStage",
1080 "Not used by '{}' objects.", type());
1081}
1082
1084{
1085 throw NotImplementedError("Flow1D::solveElectricField",
1086 "Not used by '{}' objects.", type());
1087}
1088
1090{
1091 throw NotImplementedError("Flow1D::fixElectricField",
1092 "Not used by '{}' objects.", type());
1093}
1094
1095bool Flow1D::doElectricField(size_t j) const
1096{
1097 throw NotImplementedError("Flow1D::doElectricField",
1098 "Not used by '{}' objects.", type());
1099}
1100
1101void Flow1D::setBoundaryEmissivities(double e_left, double e_right)
1102{
1103 if (e_left < 0 || e_left > 1) {
1104 throw CanteraError("Flow1D::setBoundaryEmissivities",
1105 "The left boundary emissivity must be between 0.0 and 1.0!");
1106 } else if (e_right < 0 || e_right > 1) {
1107 throw CanteraError("Flow1D::setBoundaryEmissivities",
1108 "The right boundary emissivity must be between 0.0 and 1.0!");
1109 } else {
1110 m_epsilon_left = e_left;
1111 m_epsilon_right = e_right;
1112 }
1113}
1114
1116{
1117 bool changed = false;
1118 if (j == npos) {
1119 for (size_t i = 0; i < m_points; i++) {
1120 if (m_do_energy[i]) {
1121 changed = true;
1122 }
1123 m_do_energy[i] = false;
1124 }
1125 } else {
1126 if (m_do_energy[j]) {
1127 changed = true;
1128 }
1129 m_do_energy[j] = false;
1130 }
1131 m_refiner->setActive(c_offset_U, false);
1132 m_refiner->setActive(c_offset_V, false);
1133 m_refiner->setActive(c_offset_T, false);
1134 if (changed) {
1135 needJacUpdate();
1136 }
1137}
1138
1139void Flow1D::grad_hk(const double* x, size_t j)
1140{
1141 size_t jloc = (u(x, j) > 0.0 ? j : j + 1);
1142 for(size_t k = 0; k < m_nsp; k++) {
1143 m_dhk_dz(k, j) = (m_hk(k, jloc) - m_hk(k, jloc-1))/m_dz[jloc-1];
1144 }
1145}
1146
1147// Two-point control functions
1149{
1150 if (m_twoPointControl) {
1151 if (m_zLeft != Undef) {
1152 return m_tLeft;
1153 } else {
1154 throw CanteraError("Flow1D::leftControlPointTemperature",
1155 "Invalid operation: left control point location is not set");
1156 }
1157 } else {
1158 throw CanteraError("Flow1D::leftControlPointTemperature",
1159 "Invalid operation: two-point control is not enabled.");
1160 }
1161}
1162
1164{
1165 if (m_twoPointControl) {
1166 if (m_zLeft != Undef) {
1167 return m_zLeft;
1168 } else {
1169 throw CanteraError("Flow1D::leftControlPointCoordinate",
1170 "Invalid operation: left control point location is not set");
1171 }
1172 } else {
1173 throw CanteraError("Flow1D::leftControlPointCoordinate",
1174 "Invalid operation: two-point control is not enabled.");
1175 }
1176}
1177
1179{
1180 if (m_twoPointControl) {
1181 if (m_zLeft != Undef) {
1182 m_tLeft = temperature;
1183 } else {
1184 throw CanteraError("Flow1D::setLeftControlPointTemperature",
1185 "Invalid operation: left control point location is not set");
1186 }
1187 } else {
1188 throw CanteraError("Flow1D::setLeftControlPointTemperature",
1189 "Invalid operation: two-point control is not enabled.");
1190 }
1191}
1192
1194{
1195 if (m_twoPointControl) {
1196 m_zLeft = z_left;
1197 } else {
1198 throw CanteraError("Flow1D::setLeftControlPointCoordinate",
1199 "Invalid operation: two-point control is not enabled.");
1200 }
1201}
1202
1204{
1205 if (m_twoPointControl) {
1206 if (m_zRight != Undef) {
1207 return m_tRight;
1208 } else {
1209 throw CanteraError("Flow1D::rightControlPointTemperature",
1210 "Invalid operation: right control point location is not set");
1211 }
1212 } else {
1213 throw CanteraError("Flow1D::rightControlPointTemperature",
1214 "Invalid operation: two-point control is not enabled.");
1215 }
1216}
1217
1219{
1220 if (m_twoPointControl) {
1221 if (m_zRight != Undef) {
1222 return m_zRight;
1223 } else {
1224 throw CanteraError("Flow1D::rightControlPointCoordinate",
1225 "Invalid operation: right control point location is not set");
1226 }
1227 } else {
1228 throw CanteraError("Flow1D::rightControlPointCoordinate",
1229 "Invalid operation: two-point control is not enabled.");
1230 }
1231}
1232
1234{
1235 if (m_twoPointControl) {
1236 if (m_zRight != Undef) {
1237 m_tRight = temperature;
1238 } else {
1239 throw CanteraError("Flow1D::setRightControlPointTemperature",
1240 "Invalid operation: right control point location is not set");
1241 }
1242 } else {
1243 throw CanteraError("Flow1D::setRightControlPointTemperature",
1244 "Invalid operation: two-point control is not enabled.");
1245 }
1246}
1247
1249{
1250 if (m_twoPointControl) {
1251 m_zRight = z_right;
1252 } else {
1253 throw CanteraError("Flow1D::setRightControlPointCoordinate",
1254 "Invalid operation: two-point control is not enabled.");
1255 }
1256}
1257
1258void Flow1D::enableTwoPointControl(bool twoPointControl)
1259{
1260 if (isStrained()) {
1261 m_twoPointControl = twoPointControl;
1262 // Prevent finding spurious solutions with negative velocity (outflow) at either
1263 // inlet.
1264 setBounds(c_offset_V, -1e-5, 1e20);
1265 } else {
1266 throw CanteraError("Flow1D::enableTwoPointControl",
1267 "Invalid operation: two-point control can only be used"
1268 "with axisymmetric flames.");
1269 }
1270}
1271
1272} // namespace
Header file defining class TransportFactory (see TransportFactory)
Headers for the Transport object, which is the virtual base class for all transport property evaluato...
const AnyValue & getMetadata(const string &key) const
Get a value from the metadata applicable to the AnyMap tree containing this node.
Definition AnyMap.cpp:623
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:432
double getDouble(const string &key, double default_) const
If key exists, return it as a double, otherwise return default_.
Definition AnyMap.cpp:1580
bool hasKey(const string &key) const
Returns true if the map contains an item named key.
Definition AnyMap.cpp:1477
A wrapper for a variable whose type is determined at runtime.
Definition AnyMap.h:88
const string & asString() const
Return the held value, if it is a string.
Definition AnyMap.cpp:782
bool & asBool()
Return the held value, if it is a bool.
Definition AnyMap.cpp:914
bool empty() const
Return boolean indicating whether AnyValue is empty.
Definition AnyMap.cpp:690
bool isScalar() const
Returns true if the held value is a scalar type (such as double, long int, string,...
Definition AnyMap.cpp:694
const vector< T > & asVector(size_t nMin=npos, size_t nMax=npos) const
Return the held value, if it is a vector of type T.
Definition AnyMap.inl.h:109
const T & as() const
Get the value of this key as the specified type.
Definition AnyMap.inl.h:16
double * ptrColumn(size_t j)
Return a pointer to the top of column j, columns are contiguous in memory.
Definition Array.h:203
virtual void resize(size_t n, size_t m, double v=0.0)
Resize the array, and fill the new entries with 'v'.
Definition Array.cpp:47
Base class for exceptions thrown by Cantera classes.
Base class for one-dimensional domains.
Definition Domain1D.h:29
size_t lastPoint() const
The index of the last (that is, right-most) grid point belonging to this domain.
Definition Domain1D.h:420
shared_ptr< Solution > m_solution
Composite thermo/kinetics/transport handler.
Definition Domain1D.h:602
size_t nComponents() const
Number of components at each grid point.
Definition Domain1D.h:148
virtual void setMeta(const AnyMap &meta)
Retrieve meta data.
Definition Domain1D.cpp:173
string id() const
Returns the identifying tag for this domain.
Definition Domain1D.h:471
vector< double > & grid()
Access the array of grid coordinates [m].
Definition Domain1D.h:505
size_t m_nv
Number of solution components.
Definition Domain1D.h:564
size_t nPoints() const
Number of grid points in this domain.
Definition Domain1D.h:170
bool m_force_full_update
see forceFullUpdate()
Definition Domain1D.h:599
virtual void resize(size_t nv, size_t np)
Resize the domain to have nv components and np grid points.
Definition Domain1D.cpp:44
double z(size_t jlocal) const
Get the coordinate [m] of the point with local index jlocal
Definition Domain1D.h:484
virtual void show(const double *x)
Print the solution.
Definition Domain1D.cpp:235
void setSolution(shared_ptr< Solution > sol)
Set the solution manager.
Definition Domain1D.cpp:31
vector< double > m_z
1D spatial grid coordinates
Definition Domain1D.h:573
size_t m_points
Number of grid points.
Definition Domain1D.h:565
string m_id
Identity tag for the domain.
Definition Domain1D.h:595
string type() const
String indicating the domain implemented.
Definition Domain1D.h:50
unique_ptr< Refiner > m_refiner
Refiner object used for placing grid points.
Definition Domain1D.h:596
void setBounds(size_t n, double lower, double upper)
Set the upper and lower bounds for a solution component, n.
Definition Domain1D.h:209
double value(const double *x, size_t n, size_t j) const
Returns the value of solution component n at grid point j of the solution vector x.
Definition Domain1D.h:347
size_t firstPoint() const
The index of the first (that is, left-most) grid point belonging to this domain.
Definition Domain1D.h:415
void needJacUpdate()
Set this if something has changed in the governing equations (for example, the value of a constant ha...
Definition Domain1D.cpp:113
size_t index(size_t n, size_t j) const
Returns the index of the solution vector, which corresponds to component n at grid point j.
Definition Domain1D.h:335
virtual size_t loc(size_t j=0) const
Location of the start of the local solution vector in the global solution vector.
Definition Domain1D.h:410
virtual AnyMap getMeta() const
Retrieve meta data.
Definition Domain1D.cpp:121
This class represents 1D flow domains that satisfy the one-dimensional similarity solution for chemic...
Definition Flow1D.h:46
double dYdz(const double *x, size_t k, size_t j) const
Calculates the spatial derivative of the species mass fraction with respect to z for species k at po...
Definition Flow1D.h:753
void setLeftControlPointTemperature(double temperature)
Sets the temperature of the left control point.
Definition Flow1D.cpp:1178
ThermoPhase * m_thermo
Phase object used for calculating thermodynamic properties.
Definition Flow1D.h:889
void eval(size_t jGlobal, double *xGlobal, double *rsdGlobal, integer *diagGlobal, double rdt) override
Evaluate the residual functions for axisymmetric stagnation flow.
Definition Flow1D.cpp:310
void setLeftControlPointCoordinate(double z_left)
Sets the coordinate of the left control point.
Definition Flow1D.cpp:1193
double dTdz(const double *x, size_t j) const
Calculates the spatial derivative of temperature T with respect to z at point j using upwind differen...
Definition Flow1D.h:767
vector< double > m_zfix
Relative coordinates used to specify a fixed temperature profile.
Definition Flow1D.h:968
double density(size_t j) const
Get the density [kg/m³] at point j
Definition Flow1D.h:350
size_t m_kExcessLeft
Index of species with a large mass fraction at the left boundary, for which the mass fraction may be ...
Definition Flow1D.h:976
void setMeta(const AnyMap &state) override
Retrieve meta data.
Definition Flow1D.cpp:978
double m_zLeft
Location of the left control point when two-point control is enabled.
Definition Flow1D.h:983
void fixTemperature(size_t j=npos)
Specify that the the temperature should be held fixed at point j.
Definition Flow1D.cpp:1115
vector< double > m_tfix
Fixed temperature values at the relative coordinates specified in m_zfix.
Definition Flow1D.h:972
void setRightControlPointCoordinate(double z_right)
Sets the coordinate of the right control point.
Definition Flow1D.cpp:1248
double X(const double *x, size_t k, size_t j) const
Get the mole fraction of species k at point j from the local state vector x.
Definition Flow1D.h:700
void setTransport(shared_ptr< Transport > trans) override
Set the transport manager used for transport property calculations.
Definition Flow1D.cpp:139
ThermoPhase & phase()
Access the phase object used to compute thermodynamic properties for points in this domain.
Definition Flow1D.h:82
void setKinetics(shared_ptr< Kinetics > kin) override
Set the Kinetics object used for reaction rate calculations.
Definition Flow1D.cpp:133
double T_prev(size_t j) const
Get the temperature at point j from the previous time step.
Definition Flow1D.h:642
void resetBadValues(double *xg) override
When called, this function should reset "bad" values in the state vector such as negative species con...
Definition Flow1D.cpp:200
bool twoPointControlEnabled() const
Returns the status of the two-point control.
Definition Flow1D.h:328
size_t rightExcessSpecies() const
Index of the species on the right boundary with the largest mass fraction.
Definition Flow1D.h:409
bool m_do_soret
true if the Soret diffusion term should be calculated.
Definition Flow1D.h:918
Kinetics * m_kin
Kinetics object used for calculating species production rates.
Definition Flow1D.h:892
vector< double > m_qdotRadiation
radiative heat loss vector
Definition Flow1D.h:953
virtual void evalMomentum(double *x, double *rsd, int *diag, double rdt, size_t jmin, size_t jmax)
Evaluate the momentum equation residual.
Definition Flow1D.cpp:571
void updateThermo(const double *x, size_t j0, size_t j1)
Update the thermodynamic properties from point j0 to point j1 (inclusive), based on solution x.
Definition Flow1D.h:436
double m_tLeft
Temperature of the left control point when two-point control is enabled.
Definition Flow1D.h:986
void setRightControlPointTemperature(double temperature)
Sets the temperature of the right control point.
Definition Flow1D.cpp:1233
void resize(size_t components, size_t points) override
Change the grid size. Called after grid refinement.
Definition Flow1D.cpp:159
double dVdz(const double *x, size_t j) const
Calculates the spatial derivative of velocity V with respect to z at point j using upwind differencin...
Definition Flow1D.h:738
bool m_usesLambda
Flag that is true for counterflow configurations that use the pressure eigenvalue in the radial mome...
Definition Flow1D.h:946
vector< double > m_fixedtemp
Fixed values of the temperature at each grid point that are used when solving with the energy equatio...
Definition Flow1D.h:961
virtual void evalContinuity(double *x, double *rsd, int *diag, double rdt, size_t jmin, size_t jmax)
Evaluate the continuity equation residual.
Definition Flow1D.cpp:514
vector< double > m_cp
Specific heat capacity at each grid point.
Definition Flow1D.h:853
void enableTwoPointControl(bool twoPointControl)
Sets the status of the two-point control.
Definition Flow1D.cpp:1258
double m_tRight
Temperature of the right control point when two-point control is enabled.
Definition Flow1D.h:992
void setBoundaryEmissivities(double e_left, double e_right)
Set the emissivities for the boundary values.
Definition Flow1D.cpp:1101
double shear(const double *x, size_t j) const
Compute the shear term from the momentum equation using a central three-point differencing scheme.
Definition Flow1D.h:795
ThermoBasis m_fluxGradientBasis
Determines whether diffusive fluxes are computed using gradients of mass fraction or mole fraction.
Definition Flow1D.h:923
void setFluxGradientBasis(ThermoBasis fluxGradientBasis)
Compute species diffusive fluxes with respect to their mass fraction gradients (fluxGradientBasis = T...
Definition Flow1D.cpp:224
virtual void evalEnergy(double *x, double *rsd, int *diag, double rdt, size_t jmin, size_t jmax)
Evaluate the energy equation residual.
Definition Flow1D.cpp:650
void solveEnergyEqn(size_t j=npos)
Specify that the energy equation should be solved at point j.
Definition Flow1D.cpp:1047
vector< double > m_rho
Density at each grid point.
Definition Flow1D.h:850
vector< bool > m_do_energy
For each point in the domain, true if energy equation is solved or false if temperature is held const...
Definition Flow1D.h:915
double m_epsilon_right
Emissivity of the surface to the right of the domain.
Definition Flow1D.h:903
Flow1D(ThermoPhase *ph=0, size_t nsp=1, size_t points=1)
Create a new flow domain.
Definition Flow1D.cpp:19
vector< double > m_tcon
Thermal conductivity at each grid point [W/m/K].
Definition Flow1D.h:857
vector< double > m_diff
Coefficient used in diffusion calculations for each species at each grid point.
Definition Flow1D.h:865
double Y_prev(size_t k, size_t j) const
Get the mass fraction of species k at point j from the previous time step.
Definition Flow1D.h:694
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
Definition Flow1D.cpp:914
size_t componentIndex(const string &name) const override
index of component with name name.
Definition Flow1D.cpp:822
vector< double > m_dz
Grid spacing. Element j holds the value of z(j+1) - z(j).
Definition Flow1D.h:847
Array2D m_flux
Array of size m_nsp by m_points for saving diffusive mass fluxes.
Definition Flow1D.h:875
void setGas(const double *x, size_t j)
Set the gas object state to be consistent with the solution at point j.
Definition Flow1D.cpp:243
ThermoBasis fluxGradientBasis() const
Compute species diffusive fluxes with respect to their mass fraction gradients (fluxGradientBasis = T...
Definition Flow1D.h:132
vector< double > m_visc
Dynamic viscosity at each grid point [Pa∙s].
Definition Flow1D.h:856
double Uo(const double *x, size_t j) const
Get the oxidizer inlet velocity [m/s] linked to point j from the local state vector x.
Definition Flow1D.h:677
double m_epsilon_left
Emissivity of the surface to the left of the domain.
Definition Flow1D.h:899
Transport * m_trans
Transport object used for calculating transport properties.
Definition Flow1D.h:895
double m_tfixed
Temperature at the point used to fix the flame location.
Definition Flow1D.h:999
virtual bool componentActive(size_t n) const
Returns true if the specified component is an active part of the solver state.
Definition Flow1D.cpp:847
Array2D m_wdot
Array of size m_nsp by m_points for saving species production rates.
Definition Flow1D.h:884
Array2D m_hk
Array of size m_nsp by m_points for saving molar enthalpies.
Definition Flow1D.h:878
double m_press
pressure [Pa]
Definition Flow1D.h:844
double lambda(const double *x, size_t j) const
Get the radial pressure gradient [N/m⁴] at point j from the local state vector x
Definition Flow1D.h:669
virtual bool doElectricField(size_t j) const
Retrieve flag indicating whether electric field is solved or not (used by IonFlow specialization)
Definition Flow1D.cpp:1095
virtual void evalSpecies(double *x, double *rsd, int *diag, double rdt, size_t jmin, size_t jmax)
Evaluate the species equations' residuals.
Definition Flow1D.cpp:732
size_t mindex(size_t k, size_t j, size_t m)
Array access mapping for a 3D array stored in a 1D vector.
Definition Flow1D.h:824
bool m_do_multicomponent
true if transport fluxes are computed using the multicomponent diffusion coefficients,...
Definition Flow1D.h:927
double V_prev(size_t j) const
Get the spread rate [1/s] at point j from the previous time step.
Definition Flow1D.h:663
double conduction(const double *x, size_t j) const
Compute the conduction term from the energy equation using a central three-point differencing scheme.
Definition Flow1D.h:810
vector< double > m_wt
Molecular weight of each species.
Definition Flow1D.h:852
double Y(const double *x, size_t k, size_t j) const
Get the mass fraction of species k at point j from the local state vector x.
Definition Flow1D.h:683
void setupGrid(size_t n, const double *z) override
called to set up initial grid, and after grid refinement
Definition Flow1D.cpp:185
double T(const double *x, size_t j) const
Get the temperature at point j from the local state vector x.
Definition Flow1D.h:633
size_t leftExcessSpecies() const
Index of the species on the left boundary with the largest mass fraction.
Definition Flow1D.h:404
bool m_isFree
Flag that is true for freely propagating flames anchored by a temperature fixed point.
Definition Flow1D.h:941
Array2D m_dhk_dz
Array of size m_nsp by m_points-1 for saving enthalpy fluxes.
Definition Flow1D.h:881
virtual void evalElectricField(double *x, double *rsd, int *diag, double rdt, size_t jmin, size_t jmax)
Evaluate the electric field equation residual to be zero everywhere.
Definition Flow1D.cpp:772
vector< double > m_wtm
Mean molecular weight at each grid point.
Definition Flow1D.h:851
vector< double > m_multidiff
Vector of size m_nsp × m_nsp × m_points for saving multicomponent diffusion coefficients.
Definition Flow1D.h:869
bool m_twoPointControl
Flag for activating two-point flame control.
Definition Flow1D.h:949
double m_zfixed
Location of the point where temperature is fixed.
Definition Flow1D.h:996
void _finalize(const double *x) override
In some cases, a domain may need to set parameters that depend on the initial solution estimate.
Definition Flow1D.cpp:263
virtual size_t getSolvingStage() const
Get the solving stage (used by IonFlow specialization)
Definition Flow1D.cpp:1071
size_t m_nsp
Number of species in the mechanism.
Definition Flow1D.h:886
virtual void evalLambda(double *x, double *rsd, int *diag, double rdt, size_t jmin, size_t jmax)
Evaluate the lambda equation residual.
Definition Flow1D.cpp:607
double rho_u(const double *x, size_t j) const
Get the axial mass flux [kg/m²/s] at point j from the local state vector x.
Definition Flow1D.h:647
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
Definition Flow1D.cpp:948
double leftControlPointCoordinate() const
Returns the z-coordinate of the left control point.
Definition Flow1D.cpp:1163
AnyMap getMeta() const override
Retrieve meta data.
Definition Flow1D.cpp:863
virtual void updateDiffFluxes(const double *x, size_t j0, size_t j1)
Update the diffusive mass fluxes.
Definition Flow1D.cpp:421
double leftControlPointTemperature() const
Returns the temperature at the left control point.
Definition Flow1D.cpp:1148
string componentName(size_t n) const override
Name of component n. May be overloaded.
Definition Flow1D.cpp:798
void setGasAtMidpoint(const double *x, size_t j)
Set the gas state to be consistent with the solution at the midpoint between j and j + 1.
Definition Flow1D.cpp:251
virtual void grad_hk(const double *x, size_t j)
Compute the spatial derivative of species specific molar enthalpies using upwind differencing.
Definition Flow1D.cpp:1139
bool isStrained() const
Retrieve flag indicating whether flow uses radial momentum.
Definition Flow1D.h:371
string transportModel() const
Retrieve transport model.
Definition Flow1D.cpp:220
double rightControlPointCoordinate() const
Returns the z-coordinate of the right control point.
Definition Flow1D.cpp:1218
double V(const double *x, size_t j) const
Get the spread rate (tangential velocity gradient) [1/s] at point j from the local state vector x.
Definition Flow1D.h:658
Array2D m_dthermal
Array of size m_nsp by m_points for saving thermal diffusion coefficients.
Definition Flow1D.h:872
void computeRadiation(double *x, size_t jmin, size_t jmax)
Computes the radiative heat loss vector over points jmin to jmax and stores the data in the qdotRadia...
Definition Flow1D.cpp:467
virtual void updateProperties(size_t jg, double *x, size_t jmin, size_t jmax)
Update the properties (thermo, transport, and diffusion flux).
Definition Flow1D.cpp:349
virtual void evalUo(double *x, double *rsd, int *diag, double rdt, size_t jmin, size_t jmax)
Evaluate the oxidizer axial velocity equation residual.
Definition Flow1D.cpp:692
string domainType() const override
Domain type flag.
Definition Flow1D.cpp:123
void show(const double *x) override
Print the solution.
Definition Flow1D.cpp:781
bool m_dovisc
Determines whether the viscosity term in the momentum equation is calculated.
Definition Flow1D.h:936
virtual void setSolvingStage(const size_t stage)
Solving stage mode for handling ionized species (used by IonFlow specialization)
Definition Flow1D.cpp:1077
void setPressure(double p)
Set the pressure.
Definition Flow1D.h:138
virtual void fixElectricField(size_t j=npos)
Set to fix voltage in a point (used by IonFlow specialization)
Definition Flow1D.cpp:1089
virtual void updateTransport(double *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 Flow1D.cpp:373
double m_zRight
Location of the right control point when two-point control is enabled.
Definition Flow1D.h:989
virtual void solveElectricField(size_t j=npos)
Set to solve electric field in a point (used by IonFlow specialization)
Definition Flow1D.cpp:1083
double u(const double *x, size_t j) const
Get the axial velocity [m/s] at point j from the local state vector x.
Definition Flow1D.h:652
size_t m_kExcessRight
Index of species with a large mass fraction at the right boundary, for which the mass fraction may be...
Definition Flow1D.h:980
void _getInitialSoln(double *x) override
Write the initial solution estimate into array x.
Definition Flow1D.cpp:234
vector< size_t > m_kRadiating
Indices within the ThermoPhase of the radiating species.
Definition Flow1D.h:907
void setTransportModel(const string &model) override
Set the transport model.
Definition Flow1D.cpp:210
double rightControlPointTemperature() const
Returns the temperature at the right control point.
Definition Flow1D.cpp:1203
double T_fixed(size_t j) const
The fixed temperature value at point j.
Definition Flow1D.h:170
vector< double > m_ybar
Holds the average of the species mass fractions between grid points j and j+1.
Definition Flow1D.h:1005
bool m_do_radiation
Determines whether radiative heat loss is calculated.
Definition Flow1D.h:931
An error indicating that an unimplemented function has been called.
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:232
virtual void setMassFractions_NoNorm(const double *const y)
Set the mass fractions to the specified values without normalizing.
Definition Phase.cpp:355
double temperature() const
Temperature (K).
Definition Phase.h:563
virtual void setPressure(double p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition Phase.h:617
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:656
string speciesName(size_t k) const
Name of the species with index k.
Definition Phase.cpp:142
const vector< double > & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition Phase.cpp:395
size_t speciesIndex(const string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition Phase.cpp:129
virtual double density() const
Density (kg/m^3).
Definition Phase.h:588
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
Definition Phase.h:624
virtual void setMassFractions(const double *const y)
Set the mass fractions to the specified values and normalize them.
Definition Phase.cpp:341
void getMassFractions(double *const y) const
Get the species mass fractions.
Definition Phase.cpp:471
virtual double pressure() const
Return the thermodynamic pressure (Pa).
Definition Phase.h:581
string name() const
Return the name of the phase.
Definition Phase.cpp:20
A container class holding arrays of state information.
void setLoc(int loc, bool restore=true)
Update the buffered location used to access SolutionArray entries.
AnyValue getComponent(const string &name) const
Retrieve a component of the SolutionArray by name.
bool hasComponent(const string &name) const
Check whether SolutionArray contains a component.
AnyMap & meta()
SolutionArray meta data.
shared_ptr< ThermoPhase > thermo()
Retrieve associated ThermoPhase object.
static shared_ptr< SolutionArray > create(const shared_ptr< Solution > &sol, int size=0, const AnyMap &meta={})
Instantiate a new SolutionArray reference.
static shared_ptr< Solution > create()
Create an empty Solution object.
Definition Solution.h:54
Base class for a phase with thermodynamic properties.
virtual double maxTemp(size_t k=npos) const
Maximum temperature for which the thermodynamic data for the species are valid.
const AnyMap & input() const
Access input data associated with the phase description.
virtual void getThermalDiffCoeffs(double *const dt)
Return a vector of Thermal diffusion coefficients [kg/m/sec].
Definition Transport.h:271
virtual string transportModel() const
Identifies the model represented by this Transport object.
Definition Transport.h:93
virtual void getMixDiffCoeffs(double *const d)
Returns a vector of mixture averaged diffusion coefficients.
Definition Transport.h:315
virtual double thermalConductivity()
Returns the mixture thermal conductivity in W/m/K.
Definition Transport.h:155
virtual void getMixDiffCoeffsMass(double *const d)
Returns a vector of mixture averaged diffusion coefficients.
Definition Transport.h:327
virtual double viscosity()
The viscosity in Pa-s.
Definition Transport.h:122
virtual void getMultiDiffCoeffs(const size_t ld, double *const d)
Return the Multicomponent diffusion coefficients. Units: [m^2/s].
Definition Transport.h:300
Header for a file containing miscellaneous numerical functions.
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
void writelog(const string &fmt, const Args &... args)
Write a formatted message to the screen.
Definition global.h:171
double linearInterp(double x, const vector< double > &xpts, const vector< double > &fpts)
Linearly interpolate a function defined on a discrete grid.
Definition funcs.cpp:13
const double OneAtm
One atmosphere [Pa].
Definition ct_defs.h:96
const double StefanBoltz
Stefan-Boltzmann constant [W/m2/K4].
Definition ct_defs.h:128
void warn_user(const string &method, const string &msg, const Args &... args)
Print a user warning raised from method as CanteraWarning.
Definition global.h:263
Namespace for the Cantera kernel.
Definition AnyMap.cpp:595
const size_t npos
index returned by functions to indicate "no position"
Definition ct_defs.h:180
const double Undef
Fairly random number to be used to initialize variables against to see if they are subsequently defin...
Definition ct_defs.h:164
@ c_offset_U
axial velocity [m/s]
Definition Flow1D.h:25
@ c_offset_L
(1/r)dP/dr
Definition Flow1D.h:28
@ c_offset_V
strain rate
Definition Flow1D.h:26
@ c_offset_E
electric field
Definition Flow1D.h:29
@ c_offset_Y
mass fractions
Definition Flow1D.h:31
@ c_offset_Uo
oxidizer axial velocity [m/s]
Definition Flow1D.h:30
@ c_offset_T
temperature [kelvin]
Definition Flow1D.h:27
ThermoBasis
Differentiate between mole fractions and mass fractions for input mixture composition.