Cantera  3.2.0
Loading...
Searching...
No Matches
Boundary1D.cpp
Go to the documentation of this file.
1//! @file Boundary1D.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
10
11using namespace std;
12
13namespace Cantera
14{
15
17{
18}
19
20void Boundary1D::_init(size_t n)
21{
22 if (m_index == npos) {
23 throw CanteraError("Boundary1D::_init",
24 "install in container before calling init.");
25 }
26
27 // A boundary object contains only one grid point
28 resize(n,1);
29
30 m_left_nsp = 0;
31 m_right_nsp = 0;
32
33 // check for left and right flow objects
34 if (m_index > 0) {
36 if (!r.isConnector()) { // multi-point domain
38 if (m_left_nv > c_offset_Y) {
40 } else {
41 m_left_nsp = 0;
42 }
43 m_flow_left = dynamic_cast<Flow1D*>(&r);
44 if (m_flow_left != nullptr) {
46 }
47 } else {
48 throw CanteraError("Boundary1D::_init",
49 "Boundary domains can only be connected on the left to flow "
50 "domains, not '{}' domains.", r.type());
51 }
52 }
53
54 // if this is not the last domain, see what is connected on the right
55 if (m_index + 1 < container().nDomains()) {
57 if (!r.isConnector()) { // multi-point domain
59 if (m_right_nv > c_offset_Y) {
61 } else {
62 m_right_nsp = 0;
63 }
64 m_flow_right = dynamic_cast<Flow1D*>(&r);
65 if (m_flow_right != nullptr) {
66 m_phase_right = &m_flow_right->phase();
67 }
68 } else {
69 throw CanteraError("Boundary1D::_init",
70 "Boundary domains can only be connected on the right to flow "
71 "domains, not '{}' domains.", r.type());
72 }
73 }
74}
75
76void Boundary1D::fromArray(const shared_ptr<SolutionArray>& arr)
77{
78 setMeta(arr->meta());
79}
80
81// ---------------- Inlet1D methods ----------------
82
84{
85}
86
87Inlet1D::Inlet1D(shared_ptr<Solution> phase, const string& id)
88 : Inlet1D()
89{
91 m_solution->thermo()->addSpeciesLock();
92 m_id = id;
93 auto thermo = phase->thermo();
94 m_temp = thermo->temperature();
95 m_press = thermo->pressure();
96 m_nsp = thermo->nSpecies();
97 m_yin.resize(m_nsp);
98 thermo->getMassFractions(m_yin.data());
99}
100
101//! set spreading rate
103{
104 m_V0 = V0;
106}
107
109{
111 // Adjust flow domain temperature bounds based on inlet temperature
112 if (m_flow != nullptr && m_flow->lowerBound(c_offset_T) >= m_temp) {
114 }
115}
116
117void Inlet1D::show(const double* x)
118{
119 writelog(" Mass Flux: {:10.4g} kg/m^2/s \n", m_mdot);
120 writelog(" Temperature: {:10.4g} K \n", m_temp);
121 if (m_flow) {
122 writelog(" Mass Fractions: \n");
123 for (size_t k = 0; k < m_flow->phase().nSpecies(); k++) {
124 if (m_yin[k] != 0.0) {
125 writelog(" {:>16s} {:10.4g} \n",
126 m_flow->phase().speciesName(k), m_yin[k]);
127 }
128 }
129 }
130 writelog("\n");
131}
132
133void Inlet1D::setMoleFractions(const string& xin)
134{
135 if (m_solution) {
136 auto thermo = m_solution->thermo();
137 thermo->setMoleFractionsByName(xin);
138 thermo->getMassFractions(m_yin.data());
140 } else {
141 m_xstr = xin;
142 }
143}
144
145void Inlet1D::setMoleFractions(const double* xin)
146{
147 if (m_solution) {
148 auto thermo = m_solution->thermo();
149 thermo->setMoleFractions(xin);
150 thermo->getMassFractions(m_yin.data());
152 }
153}
154
155void Inlet1D::updateState(size_t loc)
156{
157 if (m_flow) {
159 }
160 m_solution->thermo()->setState_TPY(m_temp, m_press, m_yin.data());
161}
162
164{
165 _init(0);
166
167 // if a flow domain is present on the left, then this must be a right inlet.
168 // Note that an inlet object can only be a terminal object - it cannot have
169 // flows on both the left and right
170 if (m_flow_left && !m_flow_right) {
171 if (!m_flow_left->isStrained()) {
172 throw CanteraError("Inlet1D::init",
173 "Right inlets with right-to-left flow are only supported for "
174 "strained flow configurations.");
175 }
178 } else if (m_flow_right) {
180 m_flow = m_flow_right;
181 } else {
182 throw CanteraError("Inlet1D::init", "Inlet1D is not properly connected.");
183 }
185
186 // components = u, V, T, Lambda, + mass fractions
187 if (!m_nsp) {
188 m_nsp = m_flow->phase().nSpecies();
189 m_yin.resize(m_nsp, 0.0);
190 m_yin[0] = 1.0;
191 }
192 if (m_temp > 0) {
194 }
195 if (m_xstr != "") {
197 }
198}
199
200void Inlet1D::eval(size_t jg, double* xg, double* rg,
201 integer* diagg, double rdt)
202{
203 if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) {
204 return;
205 }
206
207 if (m_ilr == LeftInlet) {
208 // Array elements corresponding to the first point of the flow domain
209 double* xb = xg + m_flow->loc();
210 double* rb = rg + m_flow->loc();
211
212 // The first flow residual is for u. This, however, is not modified by
213 // the inlet, since this is set within the flow domain from the
214 // continuity equation.
215
216 if (m_flow->doEnergy(0)) {
217 // The third flow residual is for T, where it is set to T(0). Subtract
218 // the local temperature to hold the flow T to the inlet T.
219 rb[c_offset_T] -= m_temp;
220 } else {
221 rb[c_offset_T] -= m_flow->T_fixed(0);
222 }
223
224 if (m_flow->isFree()) {
225 // if the flow is a freely-propagating flame, mdot is not specified.
226 // Set mdot equal to rho*u.
227 m_mdot = m_flow->density(0) * xb[c_offset_U];
228 } else if (m_flow->isStrained()) { // axisymmetric flow
230 // When using two-point control, the mass flow rate at the left inlet is
231 // not specified. Instead, the mass flow rate is dictated by the
232 // velocity at the left inlet, which comes from the U variable. The
233 // default boundary condition specified in the Flow1D.cpp file already
234 // handles this case. We only need to update the stored value of m_mdot
235 // so that other equations that use the quantity are consistent.
237 } else {
238 // The flow domain sets this to -rho*u. Add mdot to specify the mass
239 // flow rate
240 rb[c_offset_L] += m_mdot;
241 }
242
243 // spreading rate. The flow domain sets this to V(0),
244 // so for finite spreading rate subtract m_V0.
245 rb[c_offset_V] -= m_V0;
246 } else { // unstrained flow
247 rb[c_offset_U] = m_flow->density(0) * xb[c_offset_U] - m_mdot;
248 }
249
250 // add the convective term to the species residual equations
251 for (size_t k = 0; k < m_nsp; k++) {
252 if (k != m_flow_right->leftExcessSpecies()) {
253 rb[c_offset_Y+k] += m_mdot*m_yin[k];
254 }
255 }
256
257 } else {
258 // right inlet (should only be used for counter-flow flames)
259 // Array elements corresponding to the last point in the flow domain
260 double* rb = rg + loc() - m_flow->nComponents();
261 double* xb = xg + loc() - m_flow->nComponents();
262 size_t last_index = m_flow->nPoints() - 1;
263
264 rb[c_offset_V] -= m_V0;
265 if (m_flow->doEnergy(m_flow->nPoints() - 1)) {
266 rb[c_offset_T] -= m_temp; // T
267 } else {
268 rb[c_offset_T] -= m_flow->T_fixed(m_flow->nPoints() - 1);
269 }
270
271 if (m_flow->twoPointControlEnabled()) { // For point control adjustments
272 // At the right boundary, the mdot is dictated by the velocity at the right
273 // boundary, which comes from the Uo variable. The variable Uo is the
274 // left-moving velocity and has a negative value, so the mass flow has to be
275 // negated to give a positive value when using Uo.
276 m_mdot = -m_flow->density(last_index) * xb[c_offset_Uo];
277 }
278 rb[c_offset_U] += m_mdot;
279
280 for (size_t k = 0; k < m_nsp; k++) {
281 if (k != m_flow_left->rightExcessSpecies()) {
282 rb[c_offset_Y+k] += m_mdot * m_yin[k];
283 }
284 }
285 }
286}
287
288shared_ptr<SolutionArray> Inlet1D::toArray(bool normalize)
289{
291 meta["mass-flux"] = m_mdot;
292 auto arr = SolutionArray::create(m_solution, 1, meta);
293
294 // set gas state (using pressure from adjacent domain)
295 double pressure = m_flow->phase().pressure();
296 auto thermo = m_solution->thermo();
297 thermo->setState_TPY(m_temp, pressure, m_yin.data());
298 vector<double> data(thermo->stateSize());
299 thermo->saveState(data);
300
301 arr->setState(0, data);
302 if (normalize) {
303 arr->normalize();
304 }
305 return arr;
306}
307
308void Inlet1D::fromArray(const shared_ptr<SolutionArray>& arr)
309{
310 Boundary1D::setMeta(arr->meta());
311 arr->setLoc(0);
312 auto thermo = arr->thermo();
313 auto meta = arr->meta();
314 m_temp = thermo->temperature();
315 if (meta.hasKey("mass-flux")) {
316 m_mdot = meta.at("mass-flux").asDouble();
317 } else {
318 // convert data format used by Python h5py export (Cantera < 3.0)
319 auto aux = arr->getAuxiliary(0);
320 m_mdot = thermo->density() * aux.at("velocity").as<double>();
321 }
322 thermo->getMassFractions(m_yin.data());
323}
324
325// ------------- Empty1D -------------
326
328{
329 _init(0);
330}
331
332void Empty1D::eval(size_t jg, double* xg, double* rg,
333 integer* diagg, double rdt)
334{
335}
336
337shared_ptr<SolutionArray> Empty1D::toArray(bool normalize)
338{
340 return SolutionArray::create(m_solution, 0, meta);
341}
342
343// -------------- Symm1D --------------
344
346{
347 _init(0);
348}
349
350void Symm1D::eval(size_t jg, double* xg, double* rg, integer* diagg,
351 double rdt)
352{
353 if (jg != npos && (jg + 2< firstPoint() || jg > lastPoint() + 2)) {
354 return;
355 }
356
357 // start of local part of global arrays
358 double* x = xg + loc();
359 double* r = rg + loc();
360 integer* diag = diagg + loc();
361
362 if (m_flow_right) {
363 size_t nc = m_flow_right->nComponents();
364 double* xb = x;
365 double* rb = r;
366 int* db = diag;
367 db[c_offset_V] = 0;
368 db[c_offset_T] = 0;
369 rb[c_offset_V] = xb[c_offset_V] - xb[c_offset_V + nc]; // zero dV/dz
370 if (m_flow_right->doEnergy(0)) {
371 rb[c_offset_T] = xb[c_offset_T] - xb[c_offset_T + nc]; // zero dT/dz
372 }
373 }
374
375 if (m_flow_left) {
376 size_t nc = m_flow_left->nComponents();
377 double* xb = x - nc;
378 double* rb = r - nc;
379 int* db = diag - nc;
380 db[c_offset_V] = 0;
381 db[c_offset_T] = 0;
382 rb[c_offset_V] = xb[c_offset_V] - xb[c_offset_V - nc]; // zero dV/dz
384 rb[c_offset_T] = xb[c_offset_T] - xb[c_offset_T - nc]; // zero dT/dz
385 }
386 }
387}
388
389shared_ptr<SolutionArray> Symm1D::toArray(bool normalize)
390{
392 return SolutionArray::create(m_solution, 0, meta);
393}
394
395// -------- Outlet1D --------
396
398{
399}
400
401OutletRes1D::OutletRes1D(shared_ptr<Solution> phase, const string& id)
402 : OutletRes1D()
403{
405 m_solution->thermo()->addSpeciesLock();
406 m_id = id;
407}
408
410{
411 _init(0);
412
413 if (m_flow_right) {
414 throw CanteraError("Outlet1D::init",
415 "Left outlets with right-to-left flow are not supported.");
416 }
417 if (m_flow_left) {
419 } else {
420 throw CanteraError("Outlet1D::init", "Outlet1D is not connected.");
421 }
422}
423
424void Outlet1D::eval(size_t jg, double* xg, double* rg, integer* diagg,
425 double rdt)
426{
427 if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) {
428 return;
429 }
430
431 // start of local part of global arrays
432 double* x = xg + loc();
433 double* r = rg + loc();
434 integer* diag = diagg + loc();
435
436 // flow is left-to-right
437 size_t nc = m_flow_left->nComponents();
438 double* xb = x - nc;
439 double* rb = r - nc;
440 int* db = diag - nc;
441
442 size_t last = m_flow_left->nPoints() - 1;
443 if (m_flow_left->doEnergy(last)) {
444 rb[c_offset_T] = xb[c_offset_T] - xb[c_offset_T - nc]; // zero T gradient
445 } else {
446 rb[c_offset_T] = xb[c_offset_T] - m_flow_left->T_fixed(last);
447 }
448 size_t kSkip = c_offset_Y + m_flow_left->rightExcessSpecies();
449 for (size_t k = c_offset_Y; k < nc; k++) {
450 if (k != kSkip) {
451 rb[k] = xb[k] - xb[k - nc]; // zero mass fraction gradient
452 db[k] = 0;
453 }
454 }
455}
456
457shared_ptr<SolutionArray> Outlet1D::toArray(bool normalize)
458{
460 return SolutionArray::create(m_solution, 0, meta);
461}
462
463// -------- OutletRes1D --------
464
465void OutletRes1D::setMoleFractions(const string& xres)
466{
467 m_xstr = xres;
468 if (m_flow) {
472 }
473}
474
475void OutletRes1D::setMoleFractions(const double* xres)
476{
477 if (m_flow) {
481 }
482}
483
485{
486 _init(0);
487
488 if (m_flow_right) {
489 throw CanteraError("OutletRes1D::init",
490 "Left outlets with right-to-left flow are not supported.");
491 }
492 if (m_flow_left) {
494 } else {
495 throw CanteraError("OutletRes1D::init", "no flow!");
496 }
497
498 m_nsp = m_flow->phase().nSpecies();
499 m_yres.resize(m_nsp, 0.0);
500 if (m_xstr != "") {
502 } else {
503 m_yres[0] = 1.0;
504 }
505}
506
507void OutletRes1D::eval(size_t jg, double* xg, double* rg,
508 integer* diagg, double rdt)
509{
510 if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) {
511 return;
512 }
513
514 // start of local part of global arrays
515 double* x = xg + loc();
516 double* r = rg + loc();
517 integer* diag = diagg + loc();
518
519 size_t nc = m_flow_left->nComponents();
520 double* xb = x - nc;
521 double* rb = r - nc;
522 int* db = diag - nc;
523
524 size_t last = m_flow_left->nPoints() - 1;
525 if (m_flow_left->doEnergy(last)) {
526 rb[c_offset_T] = xb[c_offset_T] - xb[c_offset_T - nc]; // zero T gradient
527 } else {
528 rb[c_offset_T] = xb[c_offset_T] - m_flow_left->T_fixed(last);
529 }
530 size_t kSkip = m_flow_left->rightExcessSpecies();
531 for (size_t k = c_offset_Y; k < nc; k++) {
532 if (k != kSkip) {
533 rb[k] = xb[k] - m_yres[k-c_offset_Y]; // fixed Y
534 db[k] = 0;
535 }
536 }
537}
538
539shared_ptr<SolutionArray> OutletRes1D::toArray(bool normalize)
540{
542 meta["temperature"] = m_temp;
543 auto arr = SolutionArray::create(m_solution, 1, meta);
544
545 // set gas state (using pressure from adjacent domain)
546 double pressure = m_flow->phase().pressure();
547 auto thermo = m_solution->thermo();
548 thermo->setState_TPY(m_temp, pressure, &m_yres[0]);
549 vector<double> data(thermo->stateSize());
550 thermo->saveState(data);
551
552 arr->setState(0, data);
553 if (normalize) {
554 arr->normalize();
555 }
556 return arr;
557}
558
559void OutletRes1D::fromArray(const shared_ptr<SolutionArray>& arr)
560{
561 Boundary1D::setMeta(arr->meta());
562 arr->setLoc(0);
563 auto thermo = arr->thermo();
564 m_temp = thermo->temperature();
565 auto Y = thermo->massFractions();
566 std::copy(Y, Y + m_nsp, &m_yres[0]);
567}
568
569// -------- Surf1D --------
570
572{
573 _init(0);
574}
575
576void Surf1D::eval(size_t jg, double* xg, double* rg,
577 integer* diagg, double rdt)
578{
579 if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) {
580 return;
581 }
582
583 // start of local part of global arrays
584 double* x = xg + loc();
585 double* r = rg + loc();
586
587 if (m_flow_right) {
588 double* rb = r;
589 double* xb = x;
590 rb[c_offset_T] = xb[c_offset_T] - m_temp; // specified T
591 }
592
593 if (m_flow_left) {
594 size_t nc = m_flow_left->nComponents();
595 double* rb = r - nc;
596 double* xb = x - nc;
597 rb[c_offset_T] = xb[c_offset_T] - m_temp; // specified T
598 }
599}
600
601shared_ptr<SolutionArray> Surf1D::toArray(bool normalize)
602{
604 meta["temperature"] = m_temp;
605 return SolutionArray::create(m_solution, 0, meta);
606}
607
608void Surf1D::fromArray(const shared_ptr<SolutionArray>& arr)
609{
610 auto meta = arr->meta();
611 m_temp = meta["temperature"].asDouble();
612 meta.erase("temperature");
614}
615
616void Surf1D::show(const double* x)
617{
618 writelog(" Temperature: {:10.4g} K \n\n", m_temp);
619}
620
621// -------- ReactingSurf1D --------
622
624 : m_kin(0)
625 , m_nsp(0)
626{
627}
628
629ReactingSurf1D::ReactingSurf1D(shared_ptr<Solution> phase, const string& id)
630{
631 auto thermo = std::dynamic_pointer_cast<SurfPhase>(phase->thermo());
632 if (!thermo) {
633 throw CanteraError("ReactingSurf1D::ReactingSurf1D",
634 "Detected incompatible ThermoPhase type '{}'", phase->thermo()->type());
635 }
636 auto kin = std::dynamic_pointer_cast<InterfaceKinetics>(phase->kinetics());
637 if (!kin) {
638 throw CanteraError("ReactingSurf1D::ReactingSurf1D",
639 "Detected incompatible kinetics type '{}'",
640 phase->kinetics()->kineticsType());
641 }
643 m_solution->thermo()->addSpeciesLock();
644 m_id = id;
645 m_kin = kin.get();
646 m_sphase = thermo.get();
648 m_enabled = true;
649}
650
651void ReactingSurf1D::setKinetics(shared_ptr<Kinetics> kin)
652{
653 warn_deprecated("ReactingSurf1D::setKinetics",
654 "After Cantera 3.2, a change of domain contents after instantiation "
655 "will be disabled.");
656 auto sol = Solution::create();
657 sol->setThermo(kin->reactionPhase());
658 sol->setKinetics(kin);
659 sol->setTransportModel("none");
660 m_solution = sol;
661 m_solution->thermo()->addSpeciesLock();
662 m_kin = dynamic_pointer_cast<InterfaceKinetics>(kin).get();
663 m_sphase = dynamic_pointer_cast<SurfPhase>(kin->reactionPhase()).get();
665 m_enabled = true;
666}
667
668string ReactingSurf1D::componentName(size_t n) const
669{
670 if (n < m_nsp) {
671 return m_sphase->speciesName(n);
672 }
673 throw IndexError("ReactingSurf1D::componentName", "component", n, m_nsp);
674}
675
676size_t ReactingSurf1D::componentIndex(const string& name, bool checkAlias) const
677{
678 return m_sphase->speciesIndex(name, true);
679}
680
682{
683 m_nv = m_nsp;
684 _init(m_nsp);
685
686 m_fixed_cov.resize(m_nsp, 0.0);
687 m_fixed_cov[0] = 1.0;
688 m_work.resize(m_kin->nTotalSpecies(), 0.0);
689
690 for (size_t n = 0; n < m_nsp; n++) {
691 setBounds(n, -1.0e-5, 2.0);
692 }
693}
694
696 double* x = xg + loc();
699}
700
701void ReactingSurf1D::eval(size_t jg, double* xg, double* rg,
702 integer* diagg, double rdt)
703{
704 if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) {
705 return;
706 }
707
708 // start of local part of global arrays
709 double* x = xg + loc();
710 double* r = rg + loc();
711 integer* diag = diagg + loc();
712
713 // set the coverages
714 double sum = 0.0;
715 for (size_t k = 0; k < m_nsp; k++) {
716 m_work[k] = x[k];
717 sum += x[k];
718 }
721
722 // set the left gas state to the adjacent point
723
724 size_t leftloc = 0, rightloc = 0;
725 size_t pnt = 0;
726
727 if (m_flow_left) {
728 leftloc = m_flow_left->loc();
729 pnt = m_flow_left->nPoints() - 1;
730 m_flow_left->setGas(xg + leftloc, pnt);
731 }
732
733 if (m_flow_right) {
734 rightloc = m_flow_right->loc();
735 m_flow_right->setGas(xg + rightloc, 0);
736 }
737
739 double rs0 = 1.0/m_sphase->siteDensity();
740
741 if (m_enabled) {
742 for (size_t k = 0; k < m_nsp; k++) {
743 r[k] = m_work[k] * m_sphase->size(k) * rs0;
744 r[k] -= rdt*(x[k] - prevSoln(k,0));
745 diag[k] = 1;
746 }
747 r[0] = 1.0 - sum;
748 diag[0] = 0;
749 } else {
750 for (size_t k = 0; k < m_nsp; k++) {
751 r[k] = x[k] - m_fixed_cov[k];
752 diag[k] = 0;
753 }
754 }
755
756 if (m_flow_right) {
757 double* rb = r + m_nsp;
758 double* xb = x + m_nsp;
759 rb[c_offset_T] = xb[c_offset_T] - m_temp; // specified T
760 }
761 if (m_flow_left) {
762 size_t nc = m_flow_left->nComponents();
763 const vector<double>& mwleft = m_phase_left->molecularWeights();
764 double* rb = r - nc;
765 double* xb = x - nc;
766 rb[c_offset_T] = xb[c_offset_T] - m_temp; // specified T
767 size_t nSkip = m_flow_left->rightExcessSpecies();
768 size_t l_offset = 0;
769 ThermoPhase* left_thermo = &m_flow_left->phase();
770 for (size_t nth = 0; nth < m_kin->nPhases(); nth++) {
771 if (&m_kin->thermo(nth) == left_thermo) {
772 l_offset = m_kin->kineticsSpeciesIndex(0, nth);
773 break;
774 }
775 }
776 for (size_t nl = 0; nl < m_left_nsp; nl++) {
777 if (nl != nSkip) {
778 rb[c_offset_Y+nl] += m_work[nl + l_offset]*mwleft[nl];
779 }
780 }
781 }
782}
783
784double ReactingSurf1D::value(const string& component) const
785{
786 if (!m_state) {
787 throw CanteraError("ReactingSurf1D::value",
788 "Domain needs to be installed in a container.");
789 }
790 auto i = componentIndex(component);
791 const double* soln = m_state->data() + m_iloc;
792 return soln[index(i, 0)];
793}
794
795shared_ptr<SolutionArray> ReactingSurf1D::toArray(bool normalize)
796{
797 if (!m_state) {
798 throw CanteraError("ReactingSurf1D::toArray",
799 "Domain needs to be installed in a container before calling toArray.");
800 }
801 double* soln = m_state->data() + m_iloc;
803 meta["temperature"] = m_temp;
804 meta["phase"]["name"] = m_sphase->name();
805 AnyValue source = m_sphase->input().getMetadata("filename");
806 meta["phase"]["source"] = source.empty() ? "<unknown>" : source.asString();
807
808 // set state of surface phase
810 m_sphase->setCoverages(soln);
811 vector<double> data(m_sphase->stateSize());
812 m_sphase->saveState(data.size(), &data[0]);
813
814 auto arr = SolutionArray::create(m_solution, 1, meta);
815 arr->setState(0, data);
816 if (normalize) {
817 arr->normalize();
818 }
819 return arr;
820}
821
822void ReactingSurf1D::fromArray(const shared_ptr<SolutionArray>& arr)
823{
824 if (!m_state) {
825 throw CanteraError("Domain1D::fromArray",
826 "Domain needs to be installed in a container before calling fromArray.");
827 }
828 resize(nComponents(), arr->size());
830 double* soln = m_state->data() + m_iloc;
831
832 Boundary1D::setMeta(arr->meta());
833 arr->setLoc(0);
834 auto surf = std::dynamic_pointer_cast<SurfPhase>(arr->thermo());
835 if (!surf) {
836 throw CanteraError("ReactingSurf1D::fromArray",
837 "Restoring of coverages requires surface phase");
838 }
839 m_temp = surf->temperature();
840 surf->getCoverages(soln);
841 _finalize(soln);
842}
843
844void ReactingSurf1D::show(const double* x)
845{
846 writelog(" Temperature: {:10.4g} K \n", m_temp);
847 writelog(" Coverages: \n");
848 for (size_t k = 0; k < m_nsp; k++) {
849 writelog(" {:>20s} {:10.4g} \n", m_sphase->speciesName(k), x[k]);
850 }
851 writelog("\n");
852}
853}
Boundary objects for one-dimensional simulations.
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
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 empty() const
Return boolean indicating whether AnyValue is empty.
Definition AnyMap.cpp:690
ThermoPhase * m_phase_left
Thermo object used by left flow domain.
Definition Boundary1D.h:125
double m_mdot
Mass flow rate at the boundary.
Definition Boundary1D.h:131
double m_temp
Temperature of the boundary.
Definition Boundary1D.h:129
void _init(size_t n)
Initialize member variables based on the adjacent domains.
Flow1D * m_flow_left
Flow domain to the left of this boundary.
Definition Boundary1D.h:119
ThermoPhase * m_phase_right
Thermo object used by right flow domain.
Definition Boundary1D.h:126
void fromArray(const shared_ptr< SolutionArray > &arr) override
Restore the solution for this domain from a SolutionArray.
size_t m_right_nsp
Number of species in right flow domain.
Definition Boundary1D.h:124
virtual void setTemperature(double t)
Set the temperature.
Definition Boundary1D.h:61
size_t m_left_nsp
Number of species in left flow domain.
Definition Boundary1D.h:123
Boundary1D()
Default constructor.
size_t m_right_nv
Number of state vector components in right flow domain.
Definition Boundary1D.h:122
size_t m_left_nv
Flow domain to the right of this boundary.
Definition Boundary1D.h:121
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:667
size_t m_iloc
Starting location within the solution vector for unknowns that correspond to this domain.
Definition Domain1D.h:847
shared_ptr< Solution > m_solution
Composite thermo/kinetics/transport handler.
Definition Domain1D.h:864
OneDim * m_container
Parent OneDim simulation containing this and adjacent domains.
Definition Domain1D.h:838
size_t nComponents() const
Number of components at each grid point.
Definition Domain1D.h:174
virtual bool isConnector()
True if the domain is a connector domain.
Definition Domain1D.h:59
virtual void setMeta(const AnyMap &meta)
Retrieve meta data.
Definition Domain1D.cpp:171
size_t m_index
Left-to-right location of this domain.
Definition Domain1D.h:840
string id() const
Returns the identifying tag for this domain.
Definition Domain1D.h:718
shared_ptr< Solution > phase() const
Return thermo/kinetics/transport manager used in the domain.
Definition Domain1D.h:641
size_t m_nv
Number of solution components.
Definition Domain1D.h:826
size_t nPoints() const
Number of grid points in this domain.
Definition Domain1D.h:202
double lowerBound(size_t n) const
Lower bound on the nth component.
Definition Domain1D.h:329
shared_ptr< vector< double > > m_state
data pointer shared from OneDim
Definition Domain1D.h:823
virtual void resize(size_t nv, size_t np)
Resize the domain to have nv components and np grid points.
Definition Domain1D.cpp:52
double upperBound(size_t n) const
Upper bound on the nth component.
Definition Domain1D.h:324
double m_press
pressure [Pa]
Definition Domain1D.h:821
const OneDim & container() const
The container holding this domain.
Definition Domain1D.h:112
string m_id
Identity tag for the domain.
Definition Domain1D.h:857
string type() const
String indicating the domain implemented.
Definition Domain1D.h:51
void setBounds(size_t n, double lower, double upper)
Set the upper and lower bounds for a solution component, n.
Definition Domain1D.h:268
double prevSoln(size_t n, size_t j) const
Value of component n at point j in the previous solution.
Definition Domain1D.h:708
size_t firstPoint() const
The index of the first (that is, left-most) grid point belonging to this domain.
Definition Domain1D.h:662
void needJacUpdate()
Set this if something has changed in the governing equations (for example, the value of a constant ha...
Definition Domain1D.cpp:135
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:408
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:657
virtual AnyMap getMeta() const
Retrieve meta data.
Definition Domain1D.cpp:143
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
void init() override
Initialize.
This class represents 1D flow domains that satisfy the one-dimensional similarity solution for chemic...
Definition Flow1D.h:47
double density(size_t j) const
Get the density [kg/m³] at point j
Definition Flow1D.h:425
bool doEnergy(size_t j)
true if the energy equation is solved at point j or false if a fixed temperature condition is imposed...
Definition Flow1D.h:410
ThermoPhase & phase()
Access the phase object used to compute thermodynamic properties for points in this domain.
Definition Flow1D.h:93
bool twoPointControlEnabled() const
Returns the status of the two-point control.
Definition Flow1D.h:403
size_t rightExcessSpecies() const
Index of the species on the right boundary with the largest mass fraction.
Definition Flow1D.h:484
double pressure() const
The current pressure [Pa].
Definition Flow1D.h:160
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:289
void setViscosityFlag(bool dovisc)
Specify if the viscosity term should be included in the momentum equation.
Definition Flow1D.h:451
size_t leftExcessSpecies() const
Index of the species on the left boundary with the largest mass fraction.
Definition Flow1D.h:479
bool isFree() const
Retrieve flag indicating whether flow is freely propagating.
Definition Flow1D.h:435
bool isStrained() const
Retrieve flag indicating whether flow uses radial momentum.
Definition Flow1D.h:446
double T_fixed(size_t j) const
The fixed temperature value at point j.
Definition Flow1D.h:193
An array index is out of range.
void setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
vector< double > m_yin
inlet mass fractions
Definition Boundary1D.h:189
int m_ilr
A marker that indicates whether this is a left inlet or a right inlet.
Definition Boundary1D.h:183
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
string m_xstr
inlet mass fractions.
Definition Boundary1D.h:190
size_t nSpecies() override
Get the number of species.
Definition Boundary1D.h:165
void fromArray(const shared_ptr< SolutionArray > &arr) override
Restore the solution for this domain from a SolutionArray.
void updateState(size_t loc) override
Update state at given location to state of associated Solution object.
void setTemperature(double T) override
Set the temperature.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
size_t m_nsp
Number of species in the adjacent flow domain.
Definition Boundary1D.h:188
void init() override
Initialize.
Flow1D * m_flow
the adjacent flow domain
Definition Boundary1D.h:191
void setSpreadRate(double V0) override
set spreading rate
void show(const double *x) override
Print the solution.
double m_V0
The spread rate of the inlet [1/s].
Definition Boundary1D.h:186
Inlet1D()
Default constructor.
ThermoPhase & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism.
Definition Kinetics.h:270
size_t nPhases() const
The number of phases participating in the reaction mechanism.
Definition Kinetics.h:201
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
Definition Kinetics.h:304
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
Definition Kinetics.h:282
virtual void getNetProductionRates(double *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Definition Kinetics.cpp:489
void resize() override
Call to set the size of internal data structures after first defining the system or if the problem si...
Definition OneDim.cpp:189
Domain1D & domain(size_t i) const
Return a reference to domain i.
Definition OneDim.h:78
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
void init() override
Initialize.
An outlet with specified composition.
Definition Boundary1D.h:294
void setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
OutletRes1D()
Default constructor.
string m_xstr
Mole fractions in the reservoir.
Definition Boundary1D.h:328
vector< double > m_yres
Mass fractions in the reservoir.
Definition Boundary1D.h:327
void fromArray(const shared_ptr< SolutionArray > &arr) override
Restore the solution for this domain from a SolutionArray.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
size_t m_nsp
Number of species in the adjacent flow domain.
Definition Boundary1D.h:326
void init() override
Initialize.
Flow1D * m_flow
The adjacent flow domain.
Definition Boundary1D.h:329
virtual void setMoleFractions(const double *const x)
Set the mole fractions to the specified values.
Definition Phase.cpp:347
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:270
void saveState(vector< double > &state) const
Save the current internal state of the phase.
Definition Phase.cpp:303
string speciesName(size_t k) const
Name of the species with index k.
Definition Phase.cpp:174
virtual size_t stateSize() const
Return size of vector defining internal state of the phase.
Definition Phase.cpp:295
void setMoleFractionsByName(const Composition &xMap)
Set the species mole fractions by name.
Definition Phase.cpp:388
const vector< double > & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition Phase.cpp:460
size_t speciesIndex(const string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition Phase.cpp:147
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
Definition Phase.h:690
void getMassFractions(double *const y) const
Get the species mass fractions.
Definition Phase.cpp:536
virtual double pressure() const
Return the thermodynamic pressure (Pa).
Definition Phase.h:647
string name() const
Return the name of the phase.
Definition Phase.cpp:20
SurfPhase * m_sphase
phase representing the surface species
Definition Boundary1D.h:420
void setKinetics(shared_ptr< Kinetics > kin) override
Set the kinetics manager.
void resetBadValues(double *xg) override
When called, this function should reset "bad" values in the state vector such as negative species con...
size_t componentIndex(const string &name, bool checkAlias=true) const override
Index of component with name name.
InterfaceKinetics * m_kin
surface kinetics mechanism
Definition Boundary1D.h:419
bool m_enabled
True if coverage equations are being solved.
Definition Boundary1D.h:422
vector< double > m_fixed_cov
Fixed values of the coverages used when coverage equations are not being solved.
Definition Boundary1D.h:430
ReactingSurf1D()
Default constructor.
vector< double > m_work
temporary vector used to store coverages and production rates.
Definition Boundary1D.h:426
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
double value(const string &component) const override
Set a single component value at a boundary.
void fromArray(const shared_ptr< SolutionArray > &arr) override
Restore the solution for this domain from a SolutionArray.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
void _finalize(const double *x) override
In some cases, a domain may need to set parameters that depend on the initial solution estimate.
Definition Boundary1D.h:412
size_t m_nsp
the number of surface phase species
Definition Boundary1D.h:421
string componentName(size_t n) const override
Name of component n. May be overloaded.
void init() override
Initialize.
void show(const double *x) override
Print the solution.
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
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
void fromArray(const shared_ptr< SolutionArray > &arr) override
Restore the solution for this domain from a SolutionArray.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
void init() override
Initialize.
void show(const double *x) override
Print the solution.
double pressure() const override
Return the thermodynamic pressure (Pa).
Definition SurfPhase.h:254
double size(size_t k) const
Returns the number of sites occupied by one molecule of species k.
Definition SurfPhase.h:237
void setCoverages(const double *theta)
Set the surface site fractions to a specified state.
double siteDensity() const
Returns the site density.
Definition SurfPhase.h:232
void setCoveragesNoNorm(const double *theta)
Set the surface site fractions to a specified state.
void getCoverages(double *theta) const
Return a vector of surface coverages.
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
void init() override
Initialize.
Base class for a phase with thermodynamic properties.
virtual void setState_TP(double t, double p)
Set the temperature (K) and pressure (Pa)
const AnyMap & input() const
Access input data associated with the phase description.
void writelog(const string &fmt, const Args &... args)
Write a formatted message to the screen.
Definition global.h:176
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 int LeftInlet
Unique identifier for the left inlet.
Definition Boundary1D.h:22
const int RightInlet
Unique identifier for the right inlet.
Definition Boundary1D.h:25
@ c_offset_U
axial velocity [m/s]
Definition Flow1D.h:26
@ c_offset_L
(1/r)dP/dr
Definition Flow1D.h:29
@ c_offset_V
strain rate
Definition Flow1D.h:27
@ c_offset_Y
mass fractions
Definition Flow1D.h:32
@ c_offset_Uo
oxidizer axial velocity [m/s]
Definition Flow1D.h:31
@ c_offset_T
temperature [kelvin]
Definition Flow1D.h:28
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.
Definition AnyMap.cpp:1997