Cantera  3.1.0b1
Loading...
Searching...
No Matches
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& trans)
211{
212 m_solution->setTransportModel(trans);
213}
214
216 return m_trans->transportModel();
217}
218
221 if (transportModel() != "mixture-averaged-CK" &&
222 transportModel() != "mixture-averaged") {
223 warn_user("Flow1D::setFluxGradientBasis",
224 "Setting fluxGradientBasis only affects "
225 "the mixture-averaged diffusion model.");
226 }
227}
228
230{
231 for (size_t j = 0; j < m_points; j++) {
232 T(x,j) = m_thermo->temperature();
233 m_thermo->getMassFractions(&Y(x, 0, j));
234 m_rho[j] = m_thermo->density();
235 }
236}
237
238void Flow1D::setGas(const double* x, size_t j)
239{
241 const double* yy = x + m_nv*j + c_offset_Y;
244}
245
246void Flow1D::setGasAtMidpoint(const double* x, size_t j)
247{
248 m_thermo->setTemperature(0.5*(T(x,j)+T(x,j+1)));
249 const double* yy_j = x + m_nv*j + c_offset_Y;
250 const double* yy_j_plus1 = x + m_nv*(j+1) + c_offset_Y;
251 for (size_t k = 0; k < m_nsp; k++) {
252 m_ybar[k] = 0.5*(yy_j[k] + yy_j_plus1[k]);
253 }
256}
257
258void Flow1D::_finalize(const double* x)
259{
261 throw CanteraError("Flow1D::_finalize",
262 "Thermal diffusion (the Soret effect) is enabled, and requires "
263 "using a multicomponent transport model.");
264 }
265
266 size_t nz = m_zfix.size();
267 bool e = m_do_energy[0];
268 for (size_t j = 0; j < m_points; j++) {
269 if (e || nz == 0) {
270 m_fixedtemp[j] = T(x, j);
271 } else {
272 double zz = (z(j) - z(0))/(z(m_points - 1) - z(0));
273 double tt = linearInterp(zz, m_zfix, m_tfix);
274 m_fixedtemp[j] = tt;
275 }
276 }
277 if (e) {
279 }
280
281 if (m_isFree) {
282 // If the domain contains the temperature fixed point, make sure that it
283 // is correctly set. This may be necessary when the grid has been modified
284 // externally.
285 if (m_tfixed != Undef) {
286 for (size_t j = 0; j < m_points; j++) {
287 if (z(j) == m_zfixed) {
288 return; // fixed point is already set correctly
289 }
290 }
291
292 for (size_t j = 0; j < m_points - 1; j++) {
293 // Find where the temperature profile crosses the current
294 // fixed temperature.
295 if ((T(x, j) - m_tfixed) * (T(x, j+1) - m_tfixed) <= 0.0) {
296 m_tfixed = T(x, j+1);
297 m_zfixed = z(j+1);
298 return;
299 }
300 }
301 }
302 }
303}
304
305void Flow1D::eval(size_t jGlobal, double* xGlobal, double* rsdGlobal,
306 integer* diagGlobal, double rdt)
307{
308 // If evaluating a Jacobian, and the global point is outside the domain of
309 // influence for this domain, then skip evaluating the residual
310 if (jGlobal != npos && (jGlobal + 1 < firstPoint() || jGlobal > lastPoint() + 1)) {
311 return;
312 }
313
314 // start of local part of global arrays
315 double* x = xGlobal + loc();
316 double* rsd = rsdGlobal + loc();
317 integer* diag = diagGlobal + loc();
318
319 size_t jmin, jmax;
320 if (jGlobal == npos) { // evaluate all points
321 jmin = 0;
322 jmax = m_points - 1;
323 } else { // evaluate points for Jacobian
324 size_t jpt = (jGlobal == 0) ? 0 : jGlobal - firstPoint();
325 jmin = std::max<size_t>(jpt, 1) - 1;
326 jmax = std::min(jpt+1,m_points-1);
327 }
328
329 updateProperties(jGlobal, x, jmin, jmax);
330
331 if (m_do_radiation) { // Calculation of qdotRadiation
332 computeRadiation(x, jmin, jmax);
333 }
334
335 evalContinuity(x, rsd, diag, rdt, jmin, jmax);
336 evalMomentum(x, rsd, diag, rdt, jmin, jmax);
337 evalEnergy(x, rsd, diag, rdt, jmin, jmax);
338 evalLambda(x, rsd, diag, rdt, jmin, jmax);
339 evalElectricField(x, rsd, diag, rdt, jmin, jmax);
340 evalUo(x, rsd, diag, rdt, jmin, jmax);
341 evalSpecies(x, rsd, diag, rdt, jmin, jmax);
342}
343
344void Flow1D::updateProperties(size_t jg, double* x, size_t jmin, size_t jmax)
345{
346 // properties are computed for grid points from j0 to j1
347 size_t j0 = std::max<size_t>(jmin, 1) - 1;
348 size_t j1 = std::min(jmax+1,m_points-1);
349
350 updateThermo(x, j0, j1);
351 if (jg == npos || m_force_full_update) {
352 // update transport properties only if a Jacobian is not being
353 // evaluated, or if specifically requested
354 updateTransport(x, j0, j1);
355 }
356 if (jg == npos) {
357 double* Yleft = x + index(c_offset_Y, jmin);
358 m_kExcessLeft = distance(Yleft, max_element(Yleft, Yleft + m_nsp));
359 double* Yright = x + index(c_offset_Y, jmax);
360 m_kExcessRight = distance(Yright, max_element(Yright, Yright + m_nsp));
361 }
362
363 // update the species diffusive mass fluxes whether or not a
364 // Jacobian is being evaluated
365 updateDiffFluxes(x, j0, j1);
366}
367
368void Flow1D::updateTransport(double* x, size_t j0, size_t j1)
369{
371 for (size_t j = j0; j < j1; j++) {
372 setGasAtMidpoint(x,j);
373 double wtm = m_thermo->meanMolecularWeight();
374 double rho = m_thermo->density();
375 m_visc[j] = (m_dovisc ? m_trans->viscosity() : 0.0);
377
378 // Use m_diff as storage for the factor outside the summation
379 for (size_t k = 0; k < m_nsp; k++) {
380 m_diff[k+j*m_nsp] = m_wt[k] * rho / (wtm*wtm);
381 }
382
384 if (m_do_soret) {
386 }
387 }
388 } else { // mixture averaged transport
389 for (size_t j = j0; j < j1; j++) {
390 setGasAtMidpoint(x,j);
391 m_visc[j] = (m_dovisc ? m_trans->viscosity() : 0.0);
392
393 if (m_fluxGradientBasis == ThermoBasis::molar) {
395 } else {
397 }
398
399 double rho = m_thermo->density();
400
401 if (m_fluxGradientBasis == ThermoBasis::molar) {
402 double wtm = m_thermo->meanMolecularWeight();
403 for (size_t k=0; k < m_nsp; k++) {
404 m_diff[k+j*m_nsp] *= m_wt[k] * rho / wtm;
405 }
406 } else {
407 for (size_t k=0; k < m_nsp; k++) {
408 m_diff[k+j*m_nsp] *= rho;
409 }
410 }
412 }
413 }
414}
415
416void Flow1D::updateDiffFluxes(const double* x, size_t j0, size_t j1)
417{
419 for (size_t j = j0; j < j1; j++) {
420 double dz = z(j+1) - z(j);
421 for (size_t k = 0; k < m_nsp; k++) {
422 double sum = 0.0;
423 for (size_t m = 0; m < m_nsp; m++) {
424 sum += m_wt[m] * m_multidiff[mindex(k,m,j)] * (X(x,m,j+1)-X(x,m,j));
425 }
426 m_flux(k,j) = sum * m_diff[k+j*m_nsp] / dz;
427 }
428 }
429 } else {
430 for (size_t j = j0; j < j1; j++) {
431 double sum = 0.0;
432 double dz = z(j+1) - z(j);
433 if (m_fluxGradientBasis == ThermoBasis::molar) {
434 for (size_t k = 0; k < m_nsp; k++) {
435 m_flux(k,j) = m_diff[k+m_nsp*j] * (X(x,k,j) - X(x,k,j+1))/dz;
436 sum -= m_flux(k,j);
437 }
438 } else {
439 for (size_t k = 0; k < m_nsp; k++) {
440 m_flux(k,j) = m_diff[k+m_nsp*j] * (Y(x,k,j) - Y(x,k,j+1))/dz;
441 sum -= m_flux(k,j);
442 }
443 }
444 // correction flux to ensure that \sum_k Y_k V_k = 0.
445 for (size_t k = 0; k < m_nsp; k++) {
446 m_flux(k,j) += sum*Y(x,k,j);
447 }
448 }
449 }
450
451 if (m_do_soret) {
452 for (size_t m = j0; m < j1; m++) {
453 double gradlogT = 2.0 * (T(x,m+1) - T(x,m)) /
454 ((T(x,m+1) + T(x,m)) * (z(m+1) - z(m)));
455 for (size_t k = 0; k < m_nsp; k++) {
456 m_flux(k,m) -= m_dthermal(k,m)*gradlogT;
457 }
458 }
459 }
460}
461
462void Flow1D::computeRadiation(double* x, size_t jmin, size_t jmax)
463{
464 // Variable definitions for the Planck absorption coefficient and the
465 // radiation calculation:
466 double k_P_ref = 1.0*OneAtm;
467
468 // Polynomial coefficients:
469 const double c_H2O[6] = {-0.23093, -1.12390, 9.41530, -2.99880,
470 0.51382, -1.86840e-5};
471 const double c_CO2[6] = {18.741, -121.310, 273.500, -194.050,
472 56.310, -5.8169};
473
474 // Calculation of the two boundary values
475 double boundary_Rad_left = m_epsilon_left * StefanBoltz * pow(T(x, 0), 4);
476 double boundary_Rad_right = m_epsilon_right * StefanBoltz * pow(T(x, m_points - 1), 4);
477
478 for (size_t j = jmin; j < jmax; j++) {
479 // calculation of the mean Planck absorption coefficient
480 double k_P = 0;
481 // Absorption coefficient for H2O
482 if (m_kRadiating[1] != npos) {
483 double k_P_H2O = 0;
484 for (size_t n = 0; n <= 5; n++) {
485 k_P_H2O += c_H2O[n] * pow(1000 / T(x, j), (double) n);
486 }
487 k_P_H2O /= k_P_ref;
488 k_P += m_press * X(x, m_kRadiating[1], j) * k_P_H2O;
489 }
490 // Absorption coefficient for CO2
491 if (m_kRadiating[0] != npos) {
492 double k_P_CO2 = 0;
493 for (size_t n = 0; n <= 5; n++) {
494 k_P_CO2 += c_CO2[n] * pow(1000 / T(x, j), (double) n);
495 }
496 k_P_CO2 /= k_P_ref;
497 k_P += m_press * X(x, m_kRadiating[0], j) * k_P_CO2;
498 }
499
500 // Calculation of the radiative heat loss term
501 double radiative_heat_loss = 2 * k_P *(2 * StefanBoltz * pow(T(x, j), 4)
502 - boundary_Rad_left - boundary_Rad_right);
503
504 // set the radiative heat loss vector
505 m_qdotRadiation[j] = radiative_heat_loss;
506 }
507}
508
509void Flow1D::evalContinuity(double* x, double* rsd, int* diag,
510 double rdt, size_t jmin, size_t jmax)
511{
512 // The left boundary has the same form for all cases.
513 if (jmin == 0) { // left boundary
514 rsd[index(c_offset_U, jmin)] = -(rho_u(x, jmin+1) - rho_u(x, jmin))/m_dz[jmin]
515 -(density(jmin+1)*V(x, jmin+1)
516 + density(jmin)*V(x, jmin));
517 diag[index(c_offset_U, jmin)] = 0; // Algebraic constraint
518 }
519
520 if (jmax == m_points - 1) { // right boundary
521 if (m_usesLambda) { // zero mass flux
522 rsd[index(c_offset_U, jmax)] = rho_u(x, jmax);
523 } else { // zero gradient, same for unstrained or free-flow
524 rsd[index(c_offset_U, jmax)] = rho_u(x, jmax) - rho_u(x, jmax-1);
525 }
526 diag[index(c_offset_U, jmax)] = 0; // Algebraic constraint
527 }
528
529 // j0 and j1 are constrained to only interior points
530 size_t j0 = std::max<size_t>(jmin, 1);
531 size_t j1 = std::min(jmax, m_points-2);
532 if (m_usesLambda) { // "axisymmetric-flow"
533 for (size_t j = j0; j <= j1; j++) { // interior points
534 // For "axisymmetric-flow", the continuity equation propagates the
535 // mass flow rate information to the left (j+1 -> j) from the value
536 // specified at the right boundary. The lambda information propagates
537 // in the opposite direction.
538 rsd[index(c_offset_U, j)] = -(rho_u(x, j+1) - rho_u(x, j))/m_dz[j]
539 -(density(j+1)*V(x, j+1) + density(j)*V(x, j));
540 diag[index(c_offset_U, j)] = 0; // Algebraic constraint
541 }
542 } else if (m_isFree) { // "free-flow"
543 for (size_t j = j0; j <= j1; j++) {
544 // terms involving V are zero as V=0 by definition
545 if (z(j) > m_zfixed) {
546 rsd[index(c_offset_U, j)] = -(rho_u(x, j) - rho_u(x, j-1))/m_dz[j-1];
547 } else if (z(j) == m_zfixed) {
548 if (m_do_energy[j]) {
549 rsd[index(c_offset_U, j)] = (T(x, j) - m_tfixed);
550 } else {
551 rsd[index(c_offset_U, j)] = (rho_u(x, j) - m_rho[0]*0.3); // why 0.3?
552 }
553 } else { // z(j) < m_zfixed
554 rsd[index(c_offset_U, j)] = -(rho_u(x, j+1) - rho_u(x, j))/m_dz[j];
555 }
556 diag[index(c_offset_U, j)] = 0; // Algebraic constraint
557 }
558 } else { // "unstrained-flow" (fixed mass flow rate)
559 for (size_t j = j0; j <= j1; j++) {
560 rsd[index(c_offset_U, j)] = rho_u(x, j) - rho_u(x, j-1);
561 diag[index(c_offset_U, j)] = 0; // Algebraic constraint
562 }
563 }
564}
565
566void Flow1D::evalMomentum(double* x, double* rsd, int* diag,
567 double rdt, size_t jmin, size_t jmax)
568{
569 if (!m_usesLambda) { //disable this equation
570 for (size_t j = jmin; j <= jmax; j++) {
571 rsd[index(c_offset_V, j)] = V(x, j);
572 diag[index(c_offset_V, j)] = 0;
573 }
574 return;
575 }
576
577 if (jmin == 0) { // left boundary
578 rsd[index(c_offset_V, jmin)] = V(x, jmin);
579 }
580
581 if (jmax == m_points - 1) { // right boundary
582 rsd[index(c_offset_V, jmax)] = V(x, jmax);
583 diag[index(c_offset_V, jmax)] = 0;
584 }
585
586 // j0 and j1 are constrained to only interior points
587 size_t j0 = std::max<size_t>(jmin, 1);
588 size_t j1 = std::min(jmax, m_points-2);
589 for (size_t j = j0; j <= j1; j++) { // interior points
590 rsd[index(c_offset_V, j)] = (shear(x, j) - lambda(x, j)
591 - rho_u(x, j) * dVdz(x, j)
592 - m_rho[j] * V(x, j) * V(x, j)) / m_rho[j];
593 if (!m_twoPointControl) {
594 rsd[index(c_offset_V, j)] -= rdt * (V(x, j) - V_prev(j));
595 diag[index(c_offset_V, j)] = 1;
596 } else {
597 diag[index(c_offset_V, j)] = 0;
598 }
599 }
600}
601
602void Flow1D::evalLambda(double* x, double* rsd, int* diag,
603 double rdt, size_t jmin, size_t jmax)
604{
605 if (!m_usesLambda) { // disable this equation
606 for (size_t j = jmin; j <= jmax; j++) {
607 rsd[index(c_offset_L, j)] = lambda(x, j);
608 diag[index(c_offset_L, j)] = 0;
609 }
610 return;
611 }
612
613 if (jmin == 0) { // left boundary
614 if (m_twoPointControl) {
615 rsd[index(c_offset_L, jmin)] = lambda(x, jmin+1) - lambda(x, jmin);
616 } else {
617 rsd[index(c_offset_L, jmin)] = -rho_u(x, jmin);
618 }
619 }
620
621 if (jmax == m_points - 1) { // right boundary
622 rsd[index(c_offset_L, jmax)] = lambda(x, jmax) - lambda(x, jmax-1);
623 diag[index(c_offset_L, jmax)] = 0;
624 }
625
626 // j0 and j1 are constrained to only interior points
627 size_t j0 = std::max<size_t>(jmin, 1);
628 size_t j1 = std::min(jmax, m_points-2);
629 for (size_t j = j0; j <= j1; j++) { // interior points
630 if (m_twoPointControl) {
631 if (z(j) == m_zLeft) {
632 rsd[index(c_offset_L, j)] = T(x,j) - m_tLeft;
633 } else if (z(j) > m_zLeft) {
634 rsd[index(c_offset_L, j)] = lambda(x, j) - lambda(x, j-1);
635 } else if (z(j) < m_zLeft) {
636 rsd[index(c_offset_L, j)] = lambda(x, j) - lambda(x, j+1);
637 }
638 } else {
639 rsd[index(c_offset_L, j)] = lambda(x, j) - lambda(x, j-1);
640 }
641 diag[index(c_offset_L, j)] = 0;
642 }
643}
644
645void Flow1D::evalEnergy(double* x, double* rsd, int* diag,
646 double rdt, size_t jmin, size_t jmax)
647{
648 if (jmin == 0) { // left boundary
649 rsd[index(c_offset_T, jmin)] = T(x, jmin);
650 }
651
652 if (jmax == m_points - 1) { // right boundary
653 rsd[index(c_offset_T, jmax)] = T(x, jmax);
654 }
655
656 // j0 and j1 are constrained to only interior points
657 size_t j0 = std::max<size_t>(jmin, 1);
658 size_t j1 = std::min(jmax, m_points-2);
659 for (size_t j = j0; j <= j1; j++) {
660 if (m_do_energy[j]) {
661 grad_hk(x, j);
662 double sum = 0.0;
663 for (size_t k = 0; k < m_nsp; k++) {
664 double flxk = 0.5*(m_flux(k, j-1) + m_flux(k, j));
665 sum += m_wdot(k, j)*m_hk(k, j);
666 sum += flxk * m_dhk_dz(k, j) / m_wt[k];
667 }
668
669 rsd[index(c_offset_T, j)] = - m_cp[j]*rho_u(x, j)*dTdz(x, j)
670 - conduction(x, j) - sum;
671 rsd[index(c_offset_T, j)] /= (m_rho[j]*m_cp[j]);
672 rsd[index(c_offset_T, j)] -= (m_qdotRadiation[j] / (m_rho[j] * m_cp[j]));
673 if (!m_twoPointControl || (m_z[j] != m_tLeft && m_z[j] != m_tRight)) {
674 rsd[index(c_offset_T, j)] -= rdt*(T(x, j) - T_prev(j));
675 diag[index(c_offset_T, j)] = 1;
676 } else {
677 diag[index(c_offset_T, j)] = 0;
678 }
679 } else {
680 // residual equations if the energy equation is disabled
681 rsd[index(c_offset_T, j)] = T(x, j) - T_fixed(j);
682 diag[index(c_offset_T, j)] = 0;
683 }
684 }
685}
686
687void Flow1D::evalUo(double* x, double* rsd, int* diag,
688 double rdt, size_t jmin, size_t jmax)
689{
690 if (!m_twoPointControl) { // disable this equation
691 for (size_t j = jmin; j <= jmax; j++) {
692 rsd[index(c_offset_Uo, j)] = Uo(x, j);
693 diag[index(c_offset_Uo, j)] = 0;
694 }
695 return;
696 }
697
698 if (jmin == 0) { // left boundary
699 rsd[index(c_offset_Uo, jmin)] = Uo(x, jmin+1) - Uo(x, jmin);
700 diag[index(c_offset_Uo, jmin)] = 0;
701 }
702
703 if (jmax == m_points - 1) { // right boundary
705 rsd[index(c_offset_Uo, jmax)] = Uo(x, jmax) - Uo(x, jmax-1);
706 }
707 diag[index(c_offset_Uo, jmax)] = 0;
708 }
709
710 // j0 and j1 are constrained to only interior points
711 size_t j0 = std::max<size_t>(jmin, 1);
712 size_t j1 = std::min(jmax, m_points-2);
713 for (size_t j = j0; j <= j1; j++) { // interior points
714 if (m_twoPointControl) {
715 if (z(j) == m_zRight) {
716 rsd[index(c_offset_Uo, j)] = T(x, j) - m_tRight;
717 } else if (z(j) > m_zRight) {
718 rsd[index(c_offset_Uo, j)] = Uo(x, j) - Uo(x, j-1);
719 } else if (z(j) < m_zRight) {
720 rsd[index(c_offset_Uo, j)] = Uo(x, j) - Uo(x, j+1);
721 }
722 }
723 diag[index(c_offset_Uo, j)] = 0;
724 }
725}
726
727void Flow1D::evalSpecies(double* x, double* rsd, int* diag,
728 double rdt, size_t jmin, size_t jmax)
729{
730 if (jmin == 0) { // left boundary
731 double sum = 0.0;
732 for (size_t k = 0; k < m_nsp; k++) {
733 sum += Y(x,k,jmin);
734 rsd[index(c_offset_Y+k, jmin)] = -(m_flux(k, jmin) +
735 rho_u(x, jmin) * Y(x, k, jmin));
736 }
737 rsd[index(c_offset_Y + leftExcessSpecies(), jmin)] = 1.0 - sum;
738 diag[index(c_offset_Y + leftExcessSpecies(), jmin)] = 0;
739 }
740
741 if (jmax == m_points - 1) { // right boundary
742 double sum = 0.0;
743 for (size_t k = 0; k < m_nsp; k++) {
744 sum += Y(x,k,jmax);
745 rsd[index(k+c_offset_Y, jmax)] = m_flux(k, jmax-1) +
746 rho_u(x, jmax)*Y(x, k, jmax);
747 }
748 rsd[index(c_offset_Y + rightExcessSpecies(), jmax)] = 1.0 - sum;
749 diag[index(c_offset_Y + rightExcessSpecies(), jmax)] = 0;
750 }
751
752 // j0 and j1 are constrained to only interior points
753 size_t j0 = std::max<size_t>(jmin, 1);
754 size_t j1 = std::min(jmax, m_points-2);
755 for (size_t j = j0; j <= j1; j++) {
756 for (size_t k = 0; k < m_nsp; k++) {
757 double convec = rho_u(x, j)*dYdz(x, k, j);
758 double diffus = 2*(m_flux(k, j) - m_flux(k, j-1)) / (z(j+1) - z(j-1));
759 rsd[index(c_offset_Y + k, j)] = (m_wt[k]*m_wdot(k, j)
760 - convec - diffus) / m_rho[j]
761 - rdt*(Y(x, k, j) - Y_prev(k, j));
762 diag[index(c_offset_Y + k, j)] = 1;
763 }
764 }
765}
766
767void Flow1D::evalElectricField(double* x, double* rsd, int* diag,
768 double rdt, size_t jmin, size_t jmax)
769{
770 for (size_t j = jmin; j <= jmax; j++) {
771 // The same value is used for left/right/interior points
772 rsd[index(c_offset_E, j)] = x[index(c_offset_E, j)];
773 }
774}
775
776void Flow1D::evalContinuity(size_t j, double* x, double* rsd, int* diag, double rdt)
777{
778 throw CanteraError("Flow1D::evalContinuity",
779 "Overloaded by StFlow; to be removed after Cantera 3.1");
780}
781
782void Flow1D::show(const double* x)
783{
784 writelog(" Pressure: {:10.4g} Pa\n", m_press);
785
787
788 if (m_do_radiation) {
789 writeline('-', 79, false, true);
790 writelog("\n z radiative heat loss");
791 writeline('-', 79, false, true);
792 for (size_t j = 0; j < m_points; j++) {
793 writelog("\n {:10.4g} {:10.4g}", m_z[j], m_qdotRadiation[j]);
794 }
795 writelog("\n");
796 }
797}
798
799string Flow1D::componentName(size_t n) const
800{
801 switch (n) {
802 case c_offset_U:
803 return "velocity";
804 case c_offset_V:
805 return "spread_rate";
806 case c_offset_T:
807 return "T";
808 case c_offset_L:
809 return "lambda";
810 case c_offset_E:
811 return "eField";
812 case c_offset_Uo:
813 return "Uo";
814 default:
815 if (n >= c_offset_Y && n < (c_offset_Y + m_nsp)) {
816 return m_thermo->speciesName(n - c_offset_Y);
817 } else {
818 return "<unknown>";
819 }
820 }
821}
822
823size_t Flow1D::componentIndex(const string& name) const
824{
825 if (name=="velocity") {
826 return c_offset_U;
827 } else if (name=="spread_rate") {
828 return c_offset_V;
829 } else if (name=="T") {
830 return c_offset_T;
831 } else if (name=="lambda") {
832 return c_offset_L;
833 } else if (name == "eField") {
834 return c_offset_E;
835 } else if (name == "Uo") {
836 return c_offset_Uo;
837 } else {
838 for (size_t n=c_offset_Y; n<m_nsp+c_offset_Y; n++) {
839 if (componentName(n)==name) {
840 return n;
841 }
842 }
843 throw CanteraError("Flow1D1D::componentIndex",
844 "no component named " + name);
845 }
846}
847
848bool Flow1D::componentActive(size_t n) const
849{
850 switch (n) {
851 case c_offset_V: // spread_rate
852 return m_usesLambda;
853 case c_offset_L: // lambda
854 return m_usesLambda;
855 case c_offset_E: // eField
856 return false;
857 case c_offset_Uo: // oxidizer velocity for two-point control
858 return twoPointControlEnabled();
859 default:
860 return true;
861 }
862}
863
865{
866 AnyMap state = Domain1D::getMeta();
867 state["transport-model"] = m_trans->transportModel();
868
869 state["phase"]["name"] = m_thermo->name();
870 AnyValue source = m_thermo->input().getMetadata("filename");
871 state["phase"]["source"] = source.empty() ? "<unknown>" : source.asString();
872
873 state["radiation-enabled"] = m_do_radiation;
874 if (m_do_radiation) {
875 state["emissivity-left"] = m_epsilon_left;
876 state["emissivity-right"] = m_epsilon_right;
877 }
878
879 set<bool> energy_flags(m_do_energy.begin(), m_do_energy.end());
880 if (energy_flags.size() == 1) {
881 state["energy-enabled"] = m_do_energy[0];
882 } else {
883 state["energy-enabled"] = m_do_energy;
884 }
885
886 state["Soret-enabled"] = m_do_soret;
887
888 state["flux-gradient-basis"] = static_cast<long int>(m_fluxGradientBasis);
889
890 state["refine-criteria"]["ratio"] = m_refiner->maxRatio();
891 state["refine-criteria"]["slope"] = m_refiner->maxDelta();
892 state["refine-criteria"]["curve"] = m_refiner->maxSlope();
893 state["refine-criteria"]["prune"] = m_refiner->prune();
894 state["refine-criteria"]["grid-min"] = m_refiner->gridMin();
895 state["refine-criteria"]["max-points"] =
896 static_cast<long int>(m_refiner->maxPoints());
897
898 if (m_zfixed != Undef) {
899 state["fixed-point"]["location"] = m_zfixed;
900 state["fixed-point"]["temperature"] = m_tfixed;
901 }
902
903 // Two-point control meta data
904 if (m_twoPointControl) {
905 state["continuation-method"]["type"] = "two-point";
906 state["continuation-method"]["left-location"] = m_zLeft;
907 state["continuation-method"]["right-location"] = m_zRight;
908 state["continuation-method"]["left-temperature"] = m_tLeft;
909 state["continuation-method"]["right-temperature"] = m_tRight;
910 }
911
912 return state;
913}
914
915shared_ptr<SolutionArray> Flow1D::asArray(const double* soln) const
916{
917 auto arr = SolutionArray::create(
918 m_solution, static_cast<int>(nPoints()), getMeta());
919 arr->addExtra("grid", false); // leading entry
921 value = m_z;
922 arr->setComponent("grid", value);
923 vector<double> data(nPoints());
924 for (size_t i = 0; i < nComponents(); i++) {
925 if (componentActive(i)) {
926 auto name = componentName(i);
927 for (size_t j = 0; j < nPoints(); j++) {
928 data[j] = soln[index(i, j)];
929 }
930 if (!arr->hasComponent(name)) {
931 arr->addExtra(name, componentIndex(name) > c_offset_Y);
932 }
933 value = data;
934 arr->setComponent(name, value);
935 }
936 }
937 value = m_rho;
938 arr->setComponent("D", value); // use density rather than pressure
939
940 if (m_do_radiation) {
941 arr->addExtra("radiative-heat-loss", true); // add at end
943 arr->setComponent("radiative-heat-loss", value);
944 }
945
946 return arr;
947}
948
949void Flow1D::fromArray(SolutionArray& arr, double* soln)
950{
951 Domain1D::setMeta(arr.meta());
952 arr.setLoc(0);
953 auto phase = arr.thermo();
955
956 const auto grid = arr.getComponent("grid").as<vector<double>>();
957 setupGrid(nPoints(), &grid[0]);
958 setMeta(arr.meta()); // can affect which components are active
959
960 for (size_t i = 0; i < nComponents(); i++) {
961 if (!componentActive(i)) {
962 continue;
963 }
964 string name = componentName(i);
965 if (arr.hasComponent(name)) {
966 const vector<double> data = arr.getComponent(name).as<vector<double>>();
967 for (size_t j = 0; j < nPoints(); j++) {
968 soln[index(i,j)] = data[j];
969 }
970 } else {
971 warn_user("Flow1D::fromArray", "Saved state does not contain values for "
972 "component '{}' in domain '{}'.", name, id());
973 }
974 }
975
976 updateProperties(npos, soln + loc(), 0, m_points - 1);
977}
978
979void Flow1D::setMeta(const AnyMap& state)
980{
981 if (state.hasKey("energy-enabled")) {
982 const AnyValue& ee = state["energy-enabled"];
983 if (ee.isScalar()) {
984 m_do_energy.assign(nPoints(), ee.asBool());
985 } else {
986 m_do_energy = ee.asVector<bool>(nPoints());
987 }
988 }
989
990 setTransportModel(state.getString("transport-model", "mixture-averaged"));
991
992 if (state.hasKey("Soret-enabled")) {
993 m_do_soret = state["Soret-enabled"].asBool();
994 }
995
996 if (state.hasKey("flux-gradient-basis")) {
997 m_fluxGradientBasis = static_cast<ThermoBasis>(
998 state["flux-gradient-basis"].asInt());
999 }
1000
1001 if (state.hasKey("radiation-enabled")) {
1002 m_do_radiation = state["radiation-enabled"].asBool();
1003 if (m_do_radiation) {
1004 m_epsilon_left = state["emissivity-left"].asDouble();
1005 m_epsilon_right = state["emissivity-right"].asDouble();
1006 }
1007 }
1008
1009 if (state.hasKey("refine-criteria")) {
1010 const AnyMap& criteria = state["refine-criteria"].as<AnyMap>();
1011 double ratio = criteria.getDouble("ratio", m_refiner->maxRatio());
1012 double slope = criteria.getDouble("slope", m_refiner->maxDelta());
1013 double curve = criteria.getDouble("curve", m_refiner->maxSlope());
1014 double prune = criteria.getDouble("prune", m_refiner->prune());
1015 m_refiner->setCriteria(ratio, slope, curve, prune);
1016
1017 if (criteria.hasKey("grid-min")) {
1018 m_refiner->setGridMin(criteria["grid-min"].asDouble());
1019 }
1020 if (criteria.hasKey("max-points")) {
1021 m_refiner->setMaxPoints(criteria["max-points"].asInt());
1022 }
1023 }
1024
1025 if (state.hasKey("fixed-point")) {
1026 m_zfixed = state["fixed-point"]["location"].asDouble();
1027 m_tfixed = state["fixed-point"]["temperature"].asDouble();
1028 }
1029
1030 // Two-point control meta data
1031 if (state.hasKey("continuation-method")) {
1032 const AnyMap& cm = state["continuation-method"].as<AnyMap>();
1033 if (cm["type"] == "two-point") {
1034 m_twoPointControl = true;
1035 m_zLeft = cm["left-location"].asDouble();
1036 m_zRight = cm["right-location"].asDouble();
1037 m_tLeft = cm["left-temperature"].asDouble();
1038 m_tRight = cm["right-temperature"].asDouble();
1039 } else {
1040 warn_user("Flow1D::setMeta", "Unknown continuation method '{}'.",
1041 cm["type"].asString());
1042 }
1043 }
1044}
1045
1047{
1048 bool changed = false;
1049 if (j == npos) {
1050 for (size_t i = 0; i < m_points; i++) {
1051 if (!m_do_energy[i]) {
1052 changed = true;
1053 }
1054 m_do_energy[i] = true;
1055 }
1056 } else {
1057 if (!m_do_energy[j]) {
1058 changed = true;
1059 }
1060 m_do_energy[j] = true;
1061 }
1062 m_refiner->setActive(c_offset_U, true);
1063 m_refiner->setActive(c_offset_V, true);
1064 m_refiner->setActive(c_offset_T, true);
1065 if (changed) {
1066 needJacUpdate();
1067 }
1068}
1069
1071{
1072 throw NotImplementedError("Flow1D::getSolvingStage",
1073 "Not used by '{}' objects.", type());
1074}
1075
1076void Flow1D::setSolvingStage(const size_t stage)
1077{
1078 throw NotImplementedError("Flow1D::setSolvingStage",
1079 "Not used by '{}' objects.", type());
1080}
1081
1083{
1084 throw NotImplementedError("Flow1D::solveElectricField",
1085 "Not used by '{}' objects.", type());
1086}
1087
1089{
1090 throw NotImplementedError("Flow1D::fixElectricField",
1091 "Not used by '{}' objects.", type());
1092}
1093
1094bool Flow1D::doElectricField(size_t j) const
1095{
1096 throw NotImplementedError("Flow1D::doElectricField",
1097 "Not used by '{}' objects.", type());
1098}
1099
1100void Flow1D::setBoundaryEmissivities(double e_left, double e_right)
1101{
1102 if (e_left < 0 || e_left > 1) {
1103 throw CanteraError("Flow1D::setBoundaryEmissivities",
1104 "The left boundary emissivity must be between 0.0 and 1.0!");
1105 } else if (e_right < 0 || e_right > 1) {
1106 throw CanteraError("Flow1D::setBoundaryEmissivities",
1107 "The right boundary emissivity must be between 0.0 and 1.0!");
1108 } else {
1109 m_epsilon_left = e_left;
1110 m_epsilon_right = e_right;
1111 }
1112}
1113
1115{
1116 bool changed = false;
1117 if (j == npos) {
1118 for (size_t i = 0; i < m_points; i++) {
1119 if (m_do_energy[i]) {
1120 changed = true;
1121 }
1122 m_do_energy[i] = false;
1123 }
1124 } else {
1125 if (m_do_energy[j]) {
1126 changed = true;
1127 }
1128 m_do_energy[j] = false;
1129 }
1130 m_refiner->setActive(c_offset_U, false);
1131 m_refiner->setActive(c_offset_V, false);
1132 m_refiner->setActive(c_offset_T, false);
1133 if (changed) {
1134 needJacUpdate();
1135 }
1136}
1137
1138void Flow1D::grad_hk(const double* x, size_t j)
1139{
1140 size_t jloc = (u(x, j) > 0.0 ? j : j + 1);
1141 for(size_t k = 0; k < m_nsp; k++) {
1142 m_dhk_dz(k, j) = (m_hk(k, jloc) - m_hk(k, jloc-1))/m_dz[jloc-1];
1143 }
1144}
1145
1146// Two-point control functions
1148{
1149 if (m_twoPointControl) {
1150 if (m_zLeft != Undef) {
1151 return m_tLeft;
1152 } else {
1153 throw CanteraError("Flow1D::leftControlPointTemperature",
1154 "Invalid operation: left control point location is not set");
1155 }
1156 } else {
1157 throw CanteraError("Flow1D::leftControlPointTemperature",
1158 "Invalid operation: two-point control is not enabled.");
1159 }
1160}
1161
1163{
1164 if (m_twoPointControl) {
1165 if (m_zLeft != Undef) {
1166 return m_zLeft;
1167 } else {
1168 throw CanteraError("Flow1D::leftControlPointCoordinate",
1169 "Invalid operation: left control point location is not set");
1170 }
1171 } else {
1172 throw CanteraError("Flow1D::leftControlPointCoordinate",
1173 "Invalid operation: two-point control is not enabled.");
1174 }
1175}
1176
1178{
1179 if (m_twoPointControl) {
1180 if (m_zLeft != Undef) {
1181 m_tLeft = temperature;
1182 } else {
1183 throw CanteraError("Flow1D::setLeftControlPointTemperature",
1184 "Invalid operation: left control point location is not set");
1185 }
1186 } else {
1187 throw CanteraError("Flow1D::setLeftControlPointTemperature",
1188 "Invalid operation: two-point control is not enabled.");
1189 }
1190}
1191
1193{
1194 if (m_twoPointControl) {
1195 m_zLeft = z_left;
1196 } else {
1197 throw CanteraError("Flow1D::setLeftControlPointCoordinate",
1198 "Invalid operation: two-point control is not enabled.");
1199 }
1200}
1201
1203{
1204 if (m_twoPointControl) {
1205 if (m_zRight != Undef) {
1206 return m_tRight;
1207 } else {
1208 throw CanteraError("Flow1D::rightControlPointTemperature",
1209 "Invalid operation: right control point location is not set");
1210 }
1211 } else {
1212 throw CanteraError("Flow1D::rightControlPointTemperature",
1213 "Invalid operation: two-point control is not enabled.");
1214 }
1215}
1216
1218{
1219 if (m_twoPointControl) {
1220 if (m_zRight != Undef) {
1221 return m_zRight;
1222 } else {
1223 throw CanteraError("Flow1D::rightControlPointCoordinate",
1224 "Invalid operation: right control point location is not set");
1225 }
1226 } else {
1227 throw CanteraError("Flow1D::rightControlPointCoordinate",
1228 "Invalid operation: two-point control is not enabled.");
1229 }
1230}
1231
1233{
1234 if (m_twoPointControl) {
1235 if (m_zRight != Undef) {
1236 m_tRight = temperature;
1237 } else {
1238 throw CanteraError("Flow1D::setRightControlPointTemperature",
1239 "Invalid operation: right control point location is not set");
1240 }
1241 } else {
1242 throw CanteraError("Flow1D::setRightControlPointTemperature",
1243 "Invalid operation: two-point control is not enabled.");
1244 }
1245}
1246
1248{
1249 if (m_twoPointControl) {
1250 m_zRight = z_right;
1251 } else {
1252 throw CanteraError("Flow1D::setRightControlPointCoordinate",
1253 "Invalid operation: two-point control is not enabled.");
1254 }
1255}
1256
1257void Flow1D::enableTwoPointControl(bool twoPointControl)
1258{
1259 if (isStrained()) {
1260 m_twoPointControl = twoPointControl;
1261 // Prevent finding spurious solutions with negative velocity (outflow) at either
1262 // inlet.
1263 setBounds(c_offset_V, -1e-5, 1e20);
1264 } else {
1265 throw CanteraError("Flow1D::enableTwoPointControl",
1266 "Invalid operation: two-point control can only be used"
1267 "with axisymmetric flames.");
1268 }
1269}
1270
1271} // 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:431
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
const string & getString(const string &key, const string &default_) const
If key exists, return it as a string, otherwise return default_.
Definition AnyMap.cpp:1590
A wrapper for a variable whose type is determined at runtime.
Definition AnyMap.h:87
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:428
shared_ptr< Solution > m_solution
Composite thermo/kinetics/transport handler.
Definition Domain1D.h:624
size_t nComponents() const
Number of components at each grid point.
Definition Domain1D.h:151
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:479
vector< double > & grid()
Access the array of grid coordinates [m].
Definition Domain1D.h:520
size_t m_nv
Number of solution components.
Definition Domain1D.h:586
size_t nPoints() const
Number of grid points in this domain.
Definition Domain1D.h:173
bool m_force_full_update
see forceFullUpdate()
Definition Domain1D.h:621
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:499
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:595
size_t m_points
Number of grid points.
Definition Domain1D.h:587
string m_id
Identity tag for the domain.
Definition Domain1D.h:617
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:618
void setBounds(size_t n, double lower, double upper)
Set the upper and lower bounds for a solution component, n.
Definition Domain1D.h:212
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:350
size_t firstPoint() const
The index of the first (that is, left-most) grid point belonging to this domain.
Definition Domain1D.h:423
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:338
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:418
virtual AnyMap getMeta() const
Retrieve meta data.
Definition Domain1D.cpp:121
virtual void show(std::ostream &s, const double *x)
Print the solution.
Definition Domain1D.h:489
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:759
void setLeftControlPointTemperature(double temperature)
Sets the temperature of the left control point.
Definition Flow1D.cpp:1177
ThermoPhase * m_thermo
Phase object used for calculating thermodynamic properties.
Definition Flow1D.h:895
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:305
void setLeftControlPointCoordinate(double z_left)
Sets the coordinate of the left control point.
Definition Flow1D.cpp:1192
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:773
vector< double > m_zfix
Relative coordinates used to specify a fixed temperature profile.
Definition Flow1D.h:974
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:982
void setMeta(const AnyMap &state) override
Retrieve meta data.
Definition Flow1D.cpp:979
double m_zLeft
Location of the left control point when two-point control is enabled.
Definition Flow1D.h:989
void setTransportModel(const string &trans)
Set the transport model.
Definition Flow1D.cpp:210
void fixTemperature(size_t j=npos)
Specify that the the temperature should be held fixed at point j.
Definition Flow1D.cpp:1114
vector< double > m_tfix
Fixed temperature values at the relative coordinates specified in m_zfix.
Definition Flow1D.h:978
void setRightControlPointCoordinate(double z_right)
Sets the coordinate of the right control point.
Definition Flow1D.cpp:1247
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:706
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:648
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:924
Kinetics * m_kin
Kinetics object used for calculating species production rates.
Definition Flow1D.h:898
vector< double > m_qdotRadiation
radiative heat loss vector
Definition Flow1D.h:959
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:566
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:992
void setRightControlPointTemperature(double temperature)
Sets the temperature of the right control point.
Definition Flow1D.cpp:1232
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:744
bool m_usesLambda
Flag that is true for counterflow configurations that use the pressure eigenvalue in the radial mome...
Definition Flow1D.h:952
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:967
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:509
vector< double > m_cp
Specific heat capacity at each grid point.
Definition Flow1D.h:859
void enableTwoPointControl(bool twoPointControl)
Sets the status of the two-point control.
Definition Flow1D.cpp:1257
double m_tRight
Temperature of the right control point when two-point control is enabled.
Definition Flow1D.h:998
void setBoundaryEmissivities(double e_left, double e_right)
Set the emissivities for the boundary values.
Definition Flow1D.cpp:1100
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:801
ThermoBasis m_fluxGradientBasis
Determines whether diffusive fluxes are computed using gradients of mass fraction or mole fraction.
Definition Flow1D.h:929
void setFluxGradientBasis(ThermoBasis fluxGradientBasis)
Compute species diffusive fluxes with respect to their mass fraction gradients (fluxGradientBasis = T...
Definition Flow1D.cpp:219
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:645
void solveEnergyEqn(size_t j=npos)
Specify that the energy equation should be solved at point j.
Definition Flow1D.cpp:1046
vector< double > m_rho
Density at each grid point.
Definition Flow1D.h:856
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:921
double m_epsilon_right
Emissivity of the surface to the right of the domain.
Definition Flow1D.h:909
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:863
vector< double > m_diff
Coefficient used in diffusion calculations for each species at each grid point.
Definition Flow1D.h:871
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:700
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
Definition Flow1D.cpp:915
size_t componentIndex(const string &name) const override
index of component with name name.
Definition Flow1D.cpp:823
vector< double > m_dz
Grid spacing. Element j holds the value of z(j+1) - z(j).
Definition Flow1D.h:853
Array2D m_flux
Array of size m_nsp by m_points for saving diffusive mass fluxes.
Definition Flow1D.h:881
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:238
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:862
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:683
double m_epsilon_left
Emissivity of the surface to the left of the domain.
Definition Flow1D.h:905
Transport * m_trans
Transport object used for calculating transport properties.
Definition Flow1D.h:901
double m_tfixed
Temperature at the point used to fix the flame location.
Definition Flow1D.h:1005
virtual bool componentActive(size_t n) const
Returns true if the specified component is an active part of the solver state.
Definition Flow1D.cpp:848
Array2D m_wdot
Array of size m_nsp by m_points for saving species production rates.
Definition Flow1D.h:890
Array2D m_hk
Array of size m_nsp by m_points for saving molar enthalpies.
Definition Flow1D.h:884
double m_press
pressure [Pa]
Definition Flow1D.h:850
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:675
virtual bool doElectricField(size_t j) const
Retrieve flag indicating whether electric field is solved or not (used by IonFlow specialization)
Definition Flow1D.cpp:1094
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:727
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:830
bool m_do_multicomponent
true if transport fluxes are computed using the multicomponent diffusion coefficients,...
Definition Flow1D.h:933
double V_prev(size_t j) const
Get the spread rate [1/s] at point j from the previous time step.
Definition Flow1D.h:669
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:816
vector< double > m_wt
Molecular weight of each species.
Definition Flow1D.h:858
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:689
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:639
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:947
Array2D m_dhk_dz
Array of size m_nsp by m_points-1 for saving enthalpy fluxes.
Definition Flow1D.h:887
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:767
vector< double > m_wtm
Mean molecular weight at each grid point.
Definition Flow1D.h:857
vector< double > m_multidiff
Vector of size m_nsp × m_nsp × m_points for saving multicomponent diffusion coefficients.
Definition Flow1D.h:875
bool m_twoPointControl
Flag for activating two-point flame control.
Definition Flow1D.h:955
double m_zfixed
Location of the point where temperature is fixed.
Definition Flow1D.h:1002
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:258
virtual size_t getSolvingStage() const
Get the solving stage (used by IonFlow specialization)
Definition Flow1D.cpp:1070
size_t m_nsp
Number of species in the mechanism.
Definition Flow1D.h:892
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:602
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:653
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
Definition Flow1D.cpp:949
double leftControlPointCoordinate() const
Returns the z-coordinate of the left control point.
Definition Flow1D.cpp:1162
AnyMap getMeta() const override
Retrieve meta data.
Definition Flow1D.cpp:864
virtual void updateDiffFluxes(const double *x, size_t j0, size_t j1)
Update the diffusive mass fluxes.
Definition Flow1D.cpp:416
double leftControlPointTemperature() const
Returns the temperature at the left control point.
Definition Flow1D.cpp:1147
string componentName(size_t n) const override
Name of component n. May be overloaded.
Definition Flow1D.cpp:799
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:246
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:1138
bool isStrained() const
Retrieve flag indicating whether flow uses radial momentum.
Definition Flow1D.h:371
string transportModel() const
Retrieve transport model.
Definition Flow1D.cpp:215
double rightControlPointCoordinate() const
Returns the z-coordinate of the right control point.
Definition Flow1D.cpp:1217
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:664
Array2D m_dthermal
Array of size m_nsp by m_points for saving thermal diffusion coefficients.
Definition Flow1D.h:878
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:462
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:344
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:687
string domainType() const override
Domain type flag.
Definition Flow1D.cpp:123
void show(const double *x) override
Print the solution.
Definition Flow1D.cpp:782
bool m_dovisc
Determines whether the viscosity term in the momentum equation is calculated.
Definition Flow1D.h:942
virtual void setSolvingStage(const size_t stage)
Solving stage mode for handling ionized species (used by IonFlow specialization)
Definition Flow1D.cpp:1076
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:1088
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:368
double m_zRight
Location of the right control point when two-point control is enabled.
Definition Flow1D.h:995
virtual void solveElectricField(size_t j=npos)
Set to solve electric field in a point (used by IonFlow specialization)
Definition Flow1D.cpp:1082
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:658
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:986
void _getInitialSoln(double *x) override
Write the initial solution estimate into array x.
Definition Flow1D.cpp:229
vector< size_t > m_kRadiating
Indices within the ThermoPhase of the radiating species.
Definition Flow1D.h:913
double rightControlPointTemperature() const
Returns the temperature at the right control point.
Definition Flow1D.cpp:1202
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:1011
bool m_do_radiation
Determines whether radiative heat loss is calculated.
Definition Flow1D.h:937
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:231
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:562
virtual void setPressure(double p)
Set the internally stored pressure (Pa) at constant temperature and composition.
Definition Phase.h:616
double meanMolecularWeight() const
The mean molecular weight. Units: (kg/kmol)
Definition Phase.h:655
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:587
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
Definition Phase.h:623
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:580
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.