Cantera  3.1.0a2
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
16Boundary1D::Boundary1D() : Domain1D(1, 1, 0.0)
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) {
35 Domain1D& r = container().domain(m_index-1);
36 if (!r.isConnector()) { // multi-point domain
37 m_left_nv = r.nComponents();
38 if (m_left_nv > c_offset_Y) {
39 m_left_nsp = m_left_nv - c_offset_Y;
40 } else {
41 m_left_nsp = 0;
42 }
43 m_left_loc = container().start(m_index-1);
44 m_left_points = r.nPoints();
45 m_flow_left = dynamic_cast<Flow1D*>(&r);
46 if (m_flow_left != nullptr) {
47 m_phase_left = &m_flow_left->phase();
48 }
49 } else {
50 throw CanteraError("Boundary1D::_init",
51 "Boundary domains can only be connected on the left to flow "
52 "domains, not '{}' domains.", r.type());
53 }
54 }
55
56 // if this is not the last domain, see what is connected on the right
57 if (m_index + 1 < container().nDomains()) {
58 Domain1D& r = container().domain(m_index+1);
59 if (!r.isConnector()) { // multi-point domain
60 m_right_nv = r.nComponents();
61 if (m_right_nv > c_offset_Y) {
62 m_right_nsp = m_right_nv - c_offset_Y;
63 } else {
64 m_right_nsp = 0;
65 }
66 m_right_loc = container().start(m_index+1);
67 m_flow_right = dynamic_cast<Flow1D*>(&r);
68 if (m_flow_right != nullptr) {
69 m_phase_right = &m_flow_right->phase();
70 }
71 } else {
72 throw CanteraError("Boundary1D::_init",
73 "Boundary domains can only be connected on the right to flow "
74 "domains, not '{}' domains.", r.type());
75 }
76 }
77}
78
79void Boundary1D::fromArray(SolutionArray& arr, double* soln)
80{
81 setMeta(arr.meta());
82}
83
84// ---------------- Inlet1D methods ----------------
85
86Inlet1D::Inlet1D()
87{
88}
89
90Inlet1D::Inlet1D(shared_ptr<Solution> solution, const string& id)
91 : Inlet1D()
92{
94 m_id = id;
95}
96
97
98//! set spreading rate
100{
101 m_V0 = V0;
103}
104
106{
108 // Adjust flow domain temperature bounds based on inlet temperature
109 if (m_flow != nullptr && m_flow->lowerBound(c_offset_T) >= m_temp) {
110 m_flow->setBounds(c_offset_T, m_temp - 5.0, m_flow->upperBound(c_offset_T));
111 }
112}
113
114void Inlet1D::show(const double* x)
115{
116 writelog(" Mass Flux: {:10.4g} kg/m^2/s \n", m_mdot);
117 writelog(" Temperature: {:10.4g} K \n", m_temp);
118 if (m_flow) {
119 writelog(" Mass Fractions: \n");
120 for (size_t k = 0; k < m_flow->phase().nSpecies(); k++) {
121 if (m_yin[k] != 0.0) {
122 writelog(" {:>16s} {:10.4g} \n",
123 m_flow->phase().speciesName(k), m_yin[k]);
124 }
125 }
126 }
127 writelog("\n");
128}
129
130void Inlet1D::setMoleFractions(const string& xin)
131{
132 m_xstr = xin;
133 if (m_flow) {
134 m_flow->phase().setMoleFractionsByName(xin);
135 m_flow->phase().getMassFractions(m_yin.data());
137 }
138}
139
140void Inlet1D::setMoleFractions(const double* xin)
141{
142 if (m_flow) {
143 m_flow->phase().setMoleFractions(xin);
144 m_flow->phase().getMassFractions(m_yin.data());
146 }
147}
148
150{
151 _init(0);
152
153 // if a flow domain is present on the left, then this must be a right inlet.
154 // Note that an inlet object can only be a terminal object - it cannot have
155 // flows on both the left and right
156 if (m_flow_left && !m_flow_right) {
157 if (!m_flow_left->isStrained()) {
158 throw CanteraError("Inlet1D::init",
159 "Right inlets with right-to-left flow are only supported for "
160 "strained flow configurations.");
161 }
162 m_ilr = RightInlet;
163 m_flow = m_flow_left;
164 } else if (m_flow_right) {
165 m_ilr = LeftInlet;
166 m_flow = m_flow_right;
167 } else {
168 throw CanteraError("Inlet1D::init", "Inlet1D is not properly connected.");
169 }
170
171 // components = u, V, T, lambda, + mass fractions
172 m_nsp = m_flow->phase().nSpecies();
173 m_yin.resize(m_nsp, 0.0);
174 if (m_xstr != "") {
175 setMoleFractions(m_xstr);
176 } else {
177 m_yin[0] = 1.0;
178 }
179
180}
181
182void Inlet1D::eval(size_t jg, double* xg, double* rg,
183 integer* diagg, double rdt)
184{
185 if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) {
186 return;
187 }
188
189 if (m_ilr == LeftInlet) {
190 // Array elements corresponding to the first point of the flow domain
191 double* xb = xg + m_flow->loc();
192 double* rb = rg + m_flow->loc();
193
194 // The first flow residual is for u. This, however, is not modified by
195 // the inlet, since this is set within the flow domain from the
196 // continuity equation.
197
198 if (m_flow->doEnergy(0)) {
199 // The third flow residual is for T, where it is set to T(0). Subtract
200 // the local temperature to hold the flow T to the inlet T.
201 rb[c_offset_T] -= m_temp;
202 } else {
203 rb[c_offset_T] -= m_flow->T_fixed(0);
204 }
205
206 if (m_flow->isFree()) {
207 // if the flow is a freely-propagating flame, mdot is not specified.
208 // Set mdot equal to rho*u, and also set lambda to zero.
209 m_mdot = m_flow->density(0) * xb[c_offset_U];
210 } else if (m_flow->isStrained()) { // axisymmetric flow
211 if (m_flow->twoPointControlEnabled()) {
212 // When using two-point control, the mass flow rate at the left inlet is
213 // not specified. Instead, the mass flow rate is dictated by the
214 // velocity at the left inlet, which comes from the U variable. The
215 // default boundary condition specified in the Flow1D.cpp file already
216 // handles this case. We only need to update the stored value of m_mdot
217 // so that other equations that use the quantity are consistent.
218 m_mdot = m_flow->density(0)*xb[c_offset_U];
219 } else {
220 // The flow domain sets this to -rho*u. Add mdot to specify the mass
221 // flow rate
222 rb[c_offset_L] += m_mdot;
223 }
224
225 // spreading rate. The flow domain sets this to V(0),
226 // so for finite spreading rate subtract m_V0.
227 rb[c_offset_V] -= m_V0;
228 } else { // unstrained flow
229 rb[c_offset_U] = m_flow->density(0) * xb[c_offset_U] - m_mdot;
230 }
231
232 // add the convective term to the species residual equations
233 for (size_t k = 0; k < m_nsp; k++) {
234 if (k != m_flow_right->leftExcessSpecies()) {
235 rb[c_offset_Y+k] += m_mdot*m_yin[k];
236 }
237 }
238
239 } else {
240 // right inlet (should only be used for counter-flow flames)
241 // Array elements corresponding to the last point in the flow domain
242 double* rb = rg + loc() - m_flow->nComponents();
243 double* xb = xg + loc() - m_flow->nComponents();
244 size_t last_index = m_flow->nPoints() - 1;
245
246 rb[c_offset_V] -= m_V0;
247 if (m_flow->doEnergy(m_flow->nPoints() - 1)) {
248 rb[c_offset_T] -= m_temp; // T
249 } else {
250 rb[c_offset_T] -= m_flow->T_fixed(m_flow->nPoints() - 1);
251 }
252
253 if (m_flow->twoPointControlEnabled()) { // For point control adjustments
254 // At the right boundary, the mdot is dictated by the velocity at the right
255 // boundary, which comes from the Uo variable. The variable Uo is the
256 // left-moving velocity and has a negative value, so the mass flow has to be
257 // negated to give a positive value when using Uo.
258 m_mdot = -m_flow->density(last_index) * xb[c_offset_Uo];
259 }
260 rb[c_offset_U] += m_mdot;
261
262 for (size_t k = 0; k < m_nsp; k++) {
263 if (k != m_flow_left->rightExcessSpecies()) {
264 rb[c_offset_Y+k] += m_mdot * m_yin[k];
265 }
266 }
267 }
268}
269
270shared_ptr<SolutionArray> Inlet1D::asArray(const double* soln) const
271{
273 meta["mass-flux"] = m_mdot;
274 auto arr = SolutionArray::create(m_solution, 1, meta);
275
276 // set gas state (using pressure from adjacent domain)
277 double pressure = m_flow->phase().pressure();
278 auto phase = m_solution->thermo();
279 phase->setState_TPY(m_temp, pressure, m_yin.data());
280 vector<double> data(phase->stateSize());
281 phase->saveState(data);
282
283 arr->setState(0, data);
284 return arr;
285}
286
287void Inlet1D::fromArray(SolutionArray& arr, double* soln)
288{
290 arr.setLoc(0);
291 auto phase = arr.thermo();
292 auto meta = arr.meta();
293 m_temp = phase->temperature();
294 if (meta.hasKey("mass-flux")) {
295 m_mdot = meta.at("mass-flux").asDouble();
296 } else {
297 // convert data format used by Python h5py export (Cantera < 3.0)
298 auto aux = arr.getAuxiliary(0);
299 m_mdot = phase->density() * aux.at("velocity").as<double>();
300 }
301 phase->getMassFractions(m_yin.data());
302}
303
304// ------------- Empty1D -------------
305
307{
308 _init(0);
309}
310
311void Empty1D::eval(size_t jg, double* xg, double* rg,
312 integer* diagg, double rdt)
313{
314}
315
316shared_ptr<SolutionArray> Empty1D::asArray(const double* soln) const
317{
319 return SolutionArray::create(m_solution, 0, meta);
320}
321
322// -------------- Symm1D --------------
323
325{
326 _init(0);
327}
328
329void Symm1D::eval(size_t jg, double* xg, double* rg, integer* diagg,
330 double rdt)
331{
332 if (jg != npos && (jg + 2< firstPoint() || jg > lastPoint() + 2)) {
333 return;
334 }
335
336 // start of local part of global arrays
337 double* x = xg + loc();
338 double* r = rg + loc();
339 integer* diag = diagg + loc();
340
341 if (m_flow_right) {
342 size_t nc = m_flow_right->nComponents();
343 double* xb = x;
344 double* rb = r;
345 int* db = diag;
346 db[c_offset_V] = 0;
347 db[c_offset_T] = 0;
348 rb[c_offset_V] = xb[c_offset_V] - xb[c_offset_V + nc]; // zero dV/dz
349 if (m_flow_right->doEnergy(0)) {
350 rb[c_offset_T] = xb[c_offset_T] - xb[c_offset_T + nc]; // zero dT/dz
351 }
352 }
353
354 if (m_flow_left) {
355 size_t nc = m_flow_left->nComponents();
356 double* xb = x - nc;
357 double* rb = r - nc;
358 int* db = diag - nc;
359 db[c_offset_V] = 0;
360 db[c_offset_T] = 0;
361 rb[c_offset_V] = xb[c_offset_V] - xb[c_offset_V - nc]; // zero dV/dz
362 if (m_flow_left->doEnergy(m_flow_left->nPoints() - 1)) {
363 rb[c_offset_T] = xb[c_offset_T] - xb[c_offset_T - nc]; // zero dT/dz
364 }
365 }
366}
367
368shared_ptr<SolutionArray> Symm1D::asArray(const double* soln) const
369{
371 return SolutionArray::create(m_solution, 0, meta);
372}
373
374// -------- Outlet1D --------
375
376OutletRes1D::OutletRes1D()
377{
378}
379
380OutletRes1D::OutletRes1D(shared_ptr<Solution> solution, const string& id)
381 : OutletRes1D()
382{
384 m_id = id;
385}
386
388{
389 _init(0);
390
391 if (m_flow_right) {
392 throw CanteraError("Outlet1D::init",
393 "Left outlets with right-to-left flow are not supported.");
394 }
395 if (m_flow_left) {
396 m_flow_left->setViscosityFlag(false);
397 } else {
398 throw CanteraError("Outlet1D::init", "Outlet1D is not connected.");
399 }
400}
401
402void Outlet1D::eval(size_t jg, double* xg, double* rg, integer* diagg,
403 double rdt)
404{
405 if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) {
406 return;
407 }
408
409 // start of local part of global arrays
410 double* x = xg + loc();
411 double* r = rg + loc();
412 integer* diag = diagg + loc();
413
414 // flow is left-to-right
415 size_t nc = m_flow_left->nComponents();
416 double* xb = x - nc;
417 double* rb = r - nc;
418 int* db = diag - nc;
419
420 size_t last = m_flow_left->nPoints() - 1;
421 if (m_flow_left->doEnergy(last)) {
422 rb[c_offset_T] = xb[c_offset_T] - xb[c_offset_T - nc]; // zero T gradient
423 } else {
424 rb[c_offset_T] = xb[c_offset_T] - m_flow_left->T_fixed(last);
425 }
426 size_t kSkip = c_offset_Y + m_flow_left->rightExcessSpecies();
427 for (size_t k = c_offset_Y; k < nc; k++) {
428 if (k != kSkip) {
429 rb[k] = xb[k] - xb[k - nc]; // zero mass fraction gradient
430 db[k] = 0;
431 }
432 }
433}
434
435shared_ptr<SolutionArray> Outlet1D::asArray(const double* soln) const
436{
438 return SolutionArray::create(m_solution, 0, meta);
439}
440
441// -------- OutletRes1D --------
442
443void OutletRes1D::setMoleFractions(const string& xres)
444{
445 m_xstr = xres;
446 if (m_flow) {
447 m_flow->phase().setMoleFractionsByName(xres);
448 m_flow->phase().getMassFractions(m_yres.data());
450 }
451}
452
453void OutletRes1D::setMoleFractions(const double* xres)
454{
455 if (m_flow) {
456 m_flow->phase().setMoleFractions(xres);
457 m_flow->phase().getMassFractions(m_yres.data());
459 }
460}
461
463{
464 _init(0);
465
466 if (m_flow_right) {
467 throw CanteraError("OutletRes1D::init",
468 "Left outlets with right-to-left flow are not supported.");
469 }
470 if (m_flow_left) {
471 m_flow = m_flow_left;
472 } else {
473 throw CanteraError("OutletRes1D::init", "no flow!");
474 }
475
476 m_nsp = m_flow->phase().nSpecies();
477 m_yres.resize(m_nsp, 0.0);
478 if (m_xstr != "") {
479 setMoleFractions(m_xstr);
480 } else {
481 m_yres[0] = 1.0;
482 }
483}
484
485void OutletRes1D::eval(size_t jg, double* xg, double* rg,
486 integer* diagg, double rdt)
487{
488 if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) {
489 return;
490 }
491
492 // start of local part of global arrays
493 double* x = xg + loc();
494 double* r = rg + loc();
495 integer* diag = diagg + loc();
496
497 size_t nc = m_flow_left->nComponents();
498 double* xb = x - nc;
499 double* rb = r - nc;
500 int* db = diag - nc;
501
502 size_t last = m_flow_left->nPoints() - 1;
503 if (m_flow_left->doEnergy(last)) {
504 rb[c_offset_T] = xb[c_offset_T] - xb[c_offset_T - nc]; // zero T gradient
505 } else {
506 rb[c_offset_T] = xb[c_offset_T] - m_flow_left->T_fixed(last);
507 }
508 size_t kSkip = m_flow_left->rightExcessSpecies();
509 for (size_t k = c_offset_Y; k < nc; k++) {
510 if (k != kSkip) {
511 rb[k] = xb[k] - m_yres[k-c_offset_Y]; // fixed Y
512 db[k] = 0;
513 }
514 }
515}
516
517shared_ptr<SolutionArray> OutletRes1D::asArray(const double* soln) const
518{
520 meta["temperature"] = m_temp;
521 auto arr = SolutionArray::create(m_solution, 1, meta);
522
523 // set gas state (using pressure from adjacent domain)
524 double pressure = m_flow->phase().pressure();
525 auto phase = m_solution->thermo();
526 phase->setState_TPY(m_temp, pressure, &m_yres[0]);
527 vector<double> data(phase->stateSize());
528 phase->saveState(data);
529
530 arr->setState(0, data);
531 return arr;
532}
533
534void OutletRes1D::fromArray(SolutionArray& arr, double* soln)
535{
537 arr.setLoc(0);
538 auto phase = arr.thermo();
539 m_temp = phase->temperature();
540 auto Y = phase->massFractions();
541 std::copy(Y, Y + m_nsp, &m_yres[0]);
542}
543
544// -------- Surf1D --------
545
547{
548 _init(0);
549}
550
551void Surf1D::eval(size_t jg, double* xg, double* rg,
552 integer* diagg, double rdt)
553{
554 if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) {
555 return;
556 }
557
558 // start of local part of global arrays
559 double* x = xg + loc();
560 double* r = rg + loc();
561
562 if (m_flow_right) {
563 double* rb = r;
564 double* xb = x;
565 rb[c_offset_T] = xb[c_offset_T] - m_temp; // specified T
566 }
567
568 if (m_flow_left) {
569 size_t nc = m_flow_left->nComponents();
570 double* rb = r - nc;
571 double* xb = x - nc;
572 rb[c_offset_T] = xb[c_offset_T] - m_temp; // specified T
573 }
574}
575
576shared_ptr<SolutionArray> Surf1D::asArray(const double* soln) const
577{
579 meta["temperature"] = m_temp;
580 return SolutionArray::create(m_solution, 0, meta);
581}
582
583void Surf1D::fromArray(SolutionArray& arr, double* soln)
584{
585 auto meta = arr.meta();
586 m_temp = meta["temperature"].asDouble();
587 meta.erase("temperature");
589}
590
591void Surf1D::show(std::ostream& s, const double* x)
592{
593 s << "------------------- Surface " << domainIndex() << " ------------------- " << std::endl;
594 s << " temperature: " << m_temp << " K" << std::endl;
595}
596
597void Surf1D::show(const double* x)
598{
599 writelog(" Temperature: {:10.4g} K \n\n", m_temp);
600}
601
602// -------- ReactingSurf1D --------
603
604ReactingSurf1D::ReactingSurf1D()
605 : m_kin(0)
606 , m_nsp(0)
607{
608}
609
610ReactingSurf1D::ReactingSurf1D(shared_ptr<Solution> solution, const string& id)
611{
612 auto phase = std::dynamic_pointer_cast<SurfPhase>(solution->thermo());
613 if (!phase) {
614 throw CanteraError("ReactingSurf1D::ReactingSurf1D",
615 "Detected incompatible ThermoPhase type '{}'", solution->thermo()->type());
616 }
617 auto kin = std::dynamic_pointer_cast<InterfaceKinetics>(solution->kinetics());
618 if (!kin) {
619 throw CanteraError("ReactingSurf1D::ReactingSurf1D",
620 "Detected incompatible kinetics type '{}'",
621 solution->kinetics()->kineticsType());
622 }
624 m_id = id;
625 m_kin = kin.get();
626 m_sphase = phase.get();
627 m_nsp = m_sphase->nSpecies();
628 m_enabled = true;
629}
630
631void ReactingSurf1D::setKinetics(shared_ptr<Kinetics> kin)
632{
633 auto sol = Solution::create();
634 sol->setThermo(kin->reactionPhase());
635 sol->setKinetics(kin);
636 sol->setTransportModel("none");
637 setSolution(sol);
638 m_kin = dynamic_pointer_cast<InterfaceKinetics>(kin).get();
639 m_sphase = dynamic_pointer_cast<SurfPhase>(kin->reactionPhase()).get();
640 m_nsp = m_sphase->nSpecies();
641 m_enabled = true;
642}
643
644string ReactingSurf1D::componentName(size_t n) const
645{
646 if (n < m_nsp) {
647 return m_sphase->speciesName(n);
648 } else {
649 return "<unknown>";
650 }
651}
652
654{
655 m_nv = m_nsp;
656 _init(m_nsp);
657
658 m_fixed_cov.resize(m_nsp, 0.0);
659 m_fixed_cov[0] = 1.0;
660 m_work.resize(m_kin->nTotalSpecies(), 0.0);
661
662 for (size_t n = 0; n < m_nsp; n++) {
663 setBounds(n, -1.0e-5, 2.0);
664 }
665}
666
668 double* x = xg + loc();
669 m_sphase->setCoverages(x);
670 m_sphase->getCoverages(x);
671}
672
673void ReactingSurf1D::eval(size_t jg, double* xg, double* rg,
674 integer* diagg, double rdt)
675{
676 if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) {
677 return;
678 }
679
680 // start of local part of global arrays
681 double* x = xg + loc();
682 double* r = rg + loc();
683 integer* diag = diagg + loc();
684
685 // set the coverages
686 double sum = 0.0;
687 for (size_t k = 0; k < m_nsp; k++) {
688 m_work[k] = x[k];
689 sum += x[k];
690 }
691 m_sphase->setTemperature(m_temp);
692 m_sphase->setCoveragesNoNorm(m_work.data());
693
694 // set the left gas state to the adjacent point
695
696 size_t leftloc = 0, rightloc = 0;
697 size_t pnt = 0;
698
699 if (m_flow_left) {
700 leftloc = m_flow_left->loc();
701 pnt = m_flow_left->nPoints() - 1;
702 m_flow_left->setGas(xg + leftloc, pnt);
703 }
704
705 if (m_flow_right) {
706 rightloc = m_flow_right->loc();
707 m_flow_right->setGas(xg + rightloc, 0);
708 }
709
710 m_kin->getNetProductionRates(m_work.data());
711 double rs0 = 1.0/m_sphase->siteDensity();
712
713 if (m_enabled) {
714 for (size_t k = 0; k < m_nsp; k++) {
715 r[k] = m_work[k] * m_sphase->size(k) * rs0;
716 r[k] -= rdt*(x[k] - prevSoln(k,0));
717 diag[k] = 1;
718 }
719 r[0] = 1.0 - sum;
720 diag[0] = 0;
721 } else {
722 for (size_t k = 0; k < m_nsp; k++) {
723 r[k] = x[k] - m_fixed_cov[k];
724 diag[k] = 0;
725 }
726 }
727
728 if (m_flow_right) {
729 double* rb = r + m_nsp;
730 double* xb = x + m_nsp;
731 rb[c_offset_T] = xb[c_offset_T] - m_temp; // specified T
732 }
733 if (m_flow_left) {
734 size_t nc = m_flow_left->nComponents();
735 const vector<double>& mwleft = m_phase_left->molecularWeights();
736 double* rb = r - nc;
737 double* xb = x - nc;
738 rb[c_offset_T] = xb[c_offset_T] - m_temp; // specified T
739 size_t nSkip = m_flow_left->rightExcessSpecies();
740 size_t l_offset = 0;
741 ThermoPhase* left_thermo = &m_flow_left->phase();
742 for (size_t nth = 0; nth < m_kin->nPhases(); nth++) {
743 if (&m_kin->thermo(nth) == left_thermo) {
744 l_offset = m_kin->kineticsSpeciesIndex(0, nth);
745 break;
746 }
747 }
748 for (size_t nl = 0; nl < m_left_nsp; nl++) {
749 if (nl != nSkip) {
750 rb[c_offset_Y+nl] += m_work[nl + l_offset]*mwleft[nl];
751 }
752 }
753 }
754}
755
756shared_ptr<SolutionArray> ReactingSurf1D::asArray(const double* soln) const
757{
759 meta["temperature"] = m_temp;
760 meta["phase"]["name"] = m_sphase->name();
761 AnyValue source = m_sphase->input().getMetadata("filename");
762 meta["phase"]["source"] = source.empty() ? "<unknown>" : source.asString();
763
764 // set state of surface phase
765 m_sphase->setState_TP(m_temp, m_sphase->pressure());
766 m_sphase->setCoverages(soln);
767 vector<double> data(m_sphase->stateSize());
768 m_sphase->saveState(data.size(), &data[0]);
769
770 auto arr = SolutionArray::create(m_solution, 1, meta);
771 arr->setState(0, data);
772 return arr;
773}
774
776{
778 arr.setLoc(0);
779 auto surf = std::dynamic_pointer_cast<SurfPhase>(arr.thermo());
780 if (!surf) {
781 throw CanteraError("ReactingSurf1D::fromArray",
782 "Restoring of coverages requires surface phase");
783 }
784 m_temp = surf->temperature();
785 surf->getCoverages(soln);
786}
787
788void ReactingSurf1D::show(const double* x)
789{
790 writelog(" Temperature: {:10.4g} K \n", m_temp);
791 writelog(" Coverages: \n");
792 for (size_t k = 0; k < m_nsp; k++) {
793 writelog(" {:>20s} {:10.4g} \n", m_sphase->speciesName(k), x[k]);
794 }
795 writelog("\n");
796}
797}
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:580
A map of string keys to values whose type can vary at runtime.
Definition AnyMap.h:427
A wrapper for a variable whose type is determined at runtime.
Definition AnyMap.h:86
const string & asString() const
Return the held value, if it is a string.
Definition AnyMap.cpp:739
bool empty() const
Return boolean indicating whether AnyValue is empty.
Definition AnyMap.cpp:647
virtual void setTemperature(double t)
Set the temperature.
Definition Boundary1D.h:57
Base class for exceptions thrown by Cantera classes.
size_t lastPoint() const
The index of the last (that is, right-most) grid point belonging to this domain.
Definition Domain1D.h:398
size_t domainIndex()
The left-to-right location of this domain.
Definition Domain1D.h:52
shared_ptr< Solution > m_solution
Composite thermo/kinetics/transport handler.
Definition Domain1D.h:565
size_t nComponents() const
Number of components at each grid point.
Definition Domain1D.h:143
shared_ptr< Solution > solution() const
Return thermo/kinetics/transport manager used in the domain.
Definition Domain1D.h:364
virtual void setMeta(const AnyMap &meta)
Retrieve meta data.
Definition Domain1D.cpp:173
size_t nPoints() const
Number of grid points in this domain.
Definition Domain1D.h:165
double lowerBound(size_t n) const
Lower bound on the nth component.
Definition Domain1D.h:257
double upperBound(size_t n) const
Upper bound on the nth component.
Definition Domain1D.h:252
void setSolution(shared_ptr< Solution > sol)
Set the solution manager.
Definition Domain1D.cpp:31
string m_id
Identity tag for the domain.
Definition Domain1D.h:558
double prevSoln(size_t n, size_t j) const
Value of component n at point j in the previous solution.
Definition Domain1D.h:439
size_t firstPoint() const
The index of the first (that is, left-most) grid point belonging to this domain.
Definition Domain1D.h:390
void needJacUpdate()
Set this if something has changed in the governing equations (for example, the value of a constant ha...
Definition Domain1D.cpp:113
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:382
virtual AnyMap getMeta() const
Retrieve meta data.
Definition Domain1D.cpp:121
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as 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.
bool twoPointControlEnabled() const
Returns the status of the two-point control.
Definition Flow1D.h:313
size_t rightExcessSpecies() const
Index of the species on the right boundary with the largest mass fraction.
Definition Flow1D.h:390
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:241
size_t leftExcessSpecies() const
Index of the species on the left boundary with the largest mass fraction.
Definition Flow1D.h:385
bool isFree() const
Retrieve flag indicating whether flow is freely propagating.
Definition Flow1D.h:342
bool isStrained() const
Retrieve flag indicating whether flow uses radial momentum.
Definition Flow1D.h:353
double T_fixed(size_t j) const
The fixed temperature value at point j.
Definition Flow1D.h:162
void setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
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.
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
void init() override
Initialize.
void setSpreadRate(double V0) override
set spreading rate
void show(const double *x) override
Print the solution.
ThermoPhase & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism.
Definition Kinetics.h:242
size_t nPhases() const
The number of phases participating in the reaction mechanism.
Definition Kinetics.h:184
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
Definition Kinetics.h:276
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
Definition Kinetics.h:254
virtual void getNetProductionRates(double *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Definition Kinetics.cpp:363
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as 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 setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
void init() override
Initialize.
virtual void setMoleFractions(const double *const x)
Set the mole fractions to the specified values.
Definition Phase.cpp:289
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:231
void saveState(vector< double > &state) const
Save the current internal state of the phase.
Definition Phase.cpp:236
string speciesName(size_t k) const
Name of the species with index k.
Definition Phase.cpp:142
virtual size_t stateSize() const
Return size of vector defining internal state of the phase.
Definition Phase.cpp:228
void setMoleFractionsByName(const Composition &xMap)
Set the species mole fractions by name.
Definition Phase.cpp:330
const vector< double > & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition Phase.cpp:395
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
Definition Phase.h:623
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
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...
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
string componentName(size_t n) const override
Name of the nth component. May be overloaded.
void init() override
Initialize.
void show(const double *x) override
Print the solution.
A container class holding arrays of state information.
void setLoc(int loc, bool restore=true)
Update the buffered location used to access SolutionArray entries.
AnyMap getAuxiliary(int loc)
Retrieve auxiliary data for a given location.
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
shared_ptr< SolutionArray > asArray(const double *soln) const override
Save the state of this domain as a SolutionArray.
void eval(size_t jg, double *xg, double *rg, integer *diagg, double rdt) override
Evaluate the residual function at point j.
void fromArray(SolutionArray &arr, double *soln) override
Restore the solution for this domain from a SolutionArray.
void init() override
Initialize.
void show(std::ostream &s, const double *x) override
Print the solution.
double pressure() const override
Return the thermodynamic pressure (Pa).
Definition SurfPhase.h:238
double size(size_t k) const
Returns the number of sites occupied by one molecule of species k.
Definition SurfPhase.h:221
void setCoverages(const double *theta)
Set the surface site fractions to a specified state.
double siteDensity() const
Returns the site density.
Definition SurfPhase.h:216
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 > asArray(const double *soln) const override
Save the state of this domain as 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:175
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564
const size_t npos
index returned by functions to indicate "no position"
Definition ct_defs.h:180
@ 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_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