Cantera  3.2.0a4
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> solution, const string& id)
88 : Inlet1D()
89{
91 m_id = id;
92}
93
94
95//! set spreading rate
97{
98 m_V0 = V0;
100}
101
103{
105 // Adjust flow domain temperature bounds based on inlet temperature
106 if (m_flow != nullptr && m_flow->lowerBound(c_offset_T) >= m_temp) {
108 }
109}
110
111void Inlet1D::show(const double* x)
112{
113 writelog(" Mass Flux: {:10.4g} kg/m^2/s \n", m_mdot);
114 writelog(" Temperature: {:10.4g} K \n", m_temp);
115 if (m_flow) {
116 writelog(" Mass Fractions: \n");
117 for (size_t k = 0; k < m_flow->phase().nSpecies(); k++) {
118 if (m_yin[k] != 0.0) {
119 writelog(" {:>16s} {:10.4g} \n",
120 m_flow->phase().speciesName(k), m_yin[k]);
121 }
122 }
123 }
124 writelog("\n");
125}
126
127void Inlet1D::setMoleFractions(const string& xin)
128{
129 m_xstr = xin;
130 if (m_flow) {
134 }
135}
136
137void Inlet1D::setMoleFractions(const double* xin)
138{
139 if (m_flow) {
143 }
144}
145
147{
148 _init(0);
149
150 // if a flow domain is present on the left, then this must be a right inlet.
151 // Note that an inlet object can only be a terminal object - it cannot have
152 // flows on both the left and right
153 if (m_flow_left && !m_flow_right) {
154 if (!m_flow_left->isStrained()) {
155 throw CanteraError("Inlet1D::init",
156 "Right inlets with right-to-left flow are only supported for "
157 "strained flow configurations.");
158 }
161 } else if (m_flow_right) {
163 m_flow = m_flow_right;
164 } else {
165 throw CanteraError("Inlet1D::init", "Inlet1D is not properly connected.");
166 }
167
168 // components = u, V, T, Lambda, + mass fractions
169 m_nsp = m_flow->phase().nSpecies();
170 m_yin.resize(m_nsp, 0.0);
171 if (m_xstr != "") {
173 } else {
174 m_yin[0] = 1.0;
175 }
176
177}
178
179void Inlet1D::eval(size_t jg, double* xg, double* rg,
180 integer* diagg, double rdt)
181{
182 if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) {
183 return;
184 }
185
186 if (m_ilr == LeftInlet) {
187 // Array elements corresponding to the first point of the flow domain
188 double* xb = xg + m_flow->loc();
189 double* rb = rg + m_flow->loc();
190
191 // The first flow residual is for u. This, however, is not modified by
192 // the inlet, since this is set within the flow domain from the
193 // continuity equation.
194
195 if (m_flow->doEnergy(0)) {
196 // The third flow residual is for T, where it is set to T(0). Subtract
197 // the local temperature to hold the flow T to the inlet T.
198 rb[c_offset_T] -= m_temp;
199 } else {
200 rb[c_offset_T] -= m_flow->T_fixed(0);
201 }
202
203 if (m_flow->isFree()) {
204 // if the flow is a freely-propagating flame, mdot is not specified.
205 // Set mdot equal to rho*u.
206 m_mdot = m_flow->density(0) * xb[c_offset_U];
207 } else if (m_flow->isStrained()) { // axisymmetric flow
209 // When using two-point control, the mass flow rate at the left inlet is
210 // not specified. Instead, the mass flow rate is dictated by the
211 // velocity at the left inlet, which comes from the U variable. The
212 // default boundary condition specified in the Flow1D.cpp file already
213 // handles this case. We only need to update the stored value of m_mdot
214 // so that other equations that use the quantity are consistent.
216 } else {
217 // The flow domain sets this to -rho*u. Add mdot to specify the mass
218 // flow rate
219 rb[c_offset_L] += m_mdot;
220 }
221
222 // spreading rate. The flow domain sets this to V(0),
223 // so for finite spreading rate subtract m_V0.
224 rb[c_offset_V] -= m_V0;
225 } else { // unstrained flow
226 rb[c_offset_U] = m_flow->density(0) * xb[c_offset_U] - m_mdot;
227 }
228
229 // add the convective term to the species residual equations
230 for (size_t k = 0; k < m_nsp; k++) {
231 if (k != m_flow_right->leftExcessSpecies()) {
232 rb[c_offset_Y+k] += m_mdot*m_yin[k];
233 }
234 }
235
236 } else {
237 // right inlet (should only be used for counter-flow flames)
238 // Array elements corresponding to the last point in the flow domain
239 double* rb = rg + loc() - m_flow->nComponents();
240 double* xb = xg + loc() - m_flow->nComponents();
241 size_t last_index = m_flow->nPoints() - 1;
242
243 rb[c_offset_V] -= m_V0;
244 if (m_flow->doEnergy(m_flow->nPoints() - 1)) {
245 rb[c_offset_T] -= m_temp; // T
246 } else {
247 rb[c_offset_T] -= m_flow->T_fixed(m_flow->nPoints() - 1);
248 }
249
250 if (m_flow->twoPointControlEnabled()) { // For point control adjustments
251 // At the right boundary, the mdot is dictated by the velocity at the right
252 // boundary, which comes from the Uo variable. The variable Uo is the
253 // left-moving velocity and has a negative value, so the mass flow has to be
254 // negated to give a positive value when using Uo.
255 m_mdot = -m_flow->density(last_index) * xb[c_offset_Uo];
256 }
257 rb[c_offset_U] += m_mdot;
258
259 for (size_t k = 0; k < m_nsp; k++) {
260 if (k != m_flow_left->rightExcessSpecies()) {
261 rb[c_offset_Y+k] += m_mdot * m_yin[k];
262 }
263 }
264 }
265}
266
267shared_ptr<SolutionArray> Inlet1D::toArray(bool normalize) const
268{
270 meta["mass-flux"] = m_mdot;
271 auto arr = SolutionArray::create(m_solution, 1, meta);
272
273 // set gas state (using pressure from adjacent domain)
274 double pressure = m_flow->phase().pressure();
275 auto phase = m_solution->thermo();
276 phase->setState_TPY(m_temp, pressure, m_yin.data());
277 vector<double> data(phase->stateSize());
278 phase->saveState(data);
279
280 arr->setState(0, data);
281 if (normalize) {
282 arr->normalize();
283 }
284 return arr;
285}
286
287void Inlet1D::fromArray(const shared_ptr<SolutionArray>& arr)
288{
289 Boundary1D::setMeta(arr->meta());
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::toArray(bool normalize) 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
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::toArray(bool normalize) const
369{
371 return SolutionArray::create(m_solution, 0, meta);
372}
373
374// -------- Outlet1D --------
375
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) {
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::toArray(bool normalize) 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) {
450 }
451}
452
453void OutletRes1D::setMoleFractions(const double* xres)
454{
455 if (m_flow) {
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) {
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 != "") {
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::toArray(bool normalize) 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 if (normalize) {
532 arr->normalize();
533 }
534 return arr;
535}
536
537void OutletRes1D::fromArray(const shared_ptr<SolutionArray>& arr)
538{
539 Boundary1D::setMeta(arr->meta());
540 arr->setLoc(0);
541 auto phase = arr->thermo();
542 m_temp = phase->temperature();
543 auto Y = phase->massFractions();
544 std::copy(Y, Y + m_nsp, &m_yres[0]);
545}
546
547// -------- Surf1D --------
548
550{
551 _init(0);
552}
553
554void Surf1D::eval(size_t jg, double* xg, double* rg,
555 integer* diagg, double rdt)
556{
557 if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) {
558 return;
559 }
560
561 // start of local part of global arrays
562 double* x = xg + loc();
563 double* r = rg + loc();
564
565 if (m_flow_right) {
566 double* rb = r;
567 double* xb = x;
568 rb[c_offset_T] = xb[c_offset_T] - m_temp; // specified T
569 }
570
571 if (m_flow_left) {
572 size_t nc = m_flow_left->nComponents();
573 double* rb = r - nc;
574 double* xb = x - nc;
575 rb[c_offset_T] = xb[c_offset_T] - m_temp; // specified T
576 }
577}
578
579shared_ptr<SolutionArray> Surf1D::toArray(bool normalize) const
580{
582 meta["temperature"] = m_temp;
583 return SolutionArray::create(m_solution, 0, meta);
584}
585
586void Surf1D::fromArray(const shared_ptr<SolutionArray>& arr)
587{
588 auto meta = arr->meta();
589 m_temp = meta["temperature"].asDouble();
590 meta.erase("temperature");
592}
593
594void Surf1D::show(const double* x)
595{
596 writelog(" Temperature: {:10.4g} K \n\n", m_temp);
597}
598
599// -------- ReactingSurf1D --------
600
602 : m_kin(0)
603 , m_nsp(0)
604{
605}
606
607ReactingSurf1D::ReactingSurf1D(shared_ptr<Solution> solution, const string& id)
608{
609 auto phase = std::dynamic_pointer_cast<SurfPhase>(solution->thermo());
610 if (!phase) {
611 throw CanteraError("ReactingSurf1D::ReactingSurf1D",
612 "Detected incompatible ThermoPhase type '{}'", solution->thermo()->type());
613 }
614 auto kin = std::dynamic_pointer_cast<InterfaceKinetics>(solution->kinetics());
615 if (!kin) {
616 throw CanteraError("ReactingSurf1D::ReactingSurf1D",
617 "Detected incompatible kinetics type '{}'",
618 solution->kinetics()->kineticsType());
619 }
621 m_id = id;
622 m_kin = kin.get();
623 m_sphase = phase.get();
625 m_enabled = true;
626}
627
628void ReactingSurf1D::setKinetics(shared_ptr<Kinetics> kin)
629{
630 auto sol = Solution::create();
631 sol->setThermo(kin->reactionPhase());
632 sol->setKinetics(kin);
633 sol->setTransportModel("none");
634 setSolution(sol);
635 m_kin = dynamic_pointer_cast<InterfaceKinetics>(kin).get();
636 m_sphase = dynamic_pointer_cast<SurfPhase>(kin->reactionPhase()).get();
638 m_enabled = true;
639}
640
641string ReactingSurf1D::componentName(size_t n) const
642{
643 if (n < m_nsp) {
644 return m_sphase->speciesName(n);
645 } else {
646 return "<unknown>";
647 }
648}
649
650size_t ReactingSurf1D::componentIndex(const string& name, bool checkAlias) const
651{
652 return m_sphase->speciesIndex(name);
653}
654
656{
657 m_nv = m_nsp;
658 _init(m_nsp);
659
660 m_fixed_cov.resize(m_nsp, 0.0);
661 m_fixed_cov[0] = 1.0;
662 m_work.resize(m_kin->nTotalSpecies(), 0.0);
663
664 for (size_t n = 0; n < m_nsp; n++) {
665 setBounds(n, -1.0e-5, 2.0);
666 }
667}
668
670 double* x = xg + loc();
673}
674
675void ReactingSurf1D::eval(size_t jg, double* xg, double* rg,
676 integer* diagg, double rdt)
677{
678 if (jg != npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) {
679 return;
680 }
681
682 // start of local part of global arrays
683 double* x = xg + loc();
684 double* r = rg + loc();
685 integer* diag = diagg + loc();
686
687 // set the coverages
688 double sum = 0.0;
689 for (size_t k = 0; k < m_nsp; k++) {
690 m_work[k] = x[k];
691 sum += x[k];
692 }
695
696 // set the left gas state to the adjacent point
697
698 size_t leftloc = 0, rightloc = 0;
699 size_t pnt = 0;
700
701 if (m_flow_left) {
702 leftloc = m_flow_left->loc();
703 pnt = m_flow_left->nPoints() - 1;
704 m_flow_left->setGas(xg + leftloc, pnt);
705 }
706
707 if (m_flow_right) {
708 rightloc = m_flow_right->loc();
709 m_flow_right->setGas(xg + rightloc, 0);
710 }
711
713 double rs0 = 1.0/m_sphase->siteDensity();
714
715 if (m_enabled) {
716 for (size_t k = 0; k < m_nsp; k++) {
717 r[k] = m_work[k] * m_sphase->size(k) * rs0;
718 r[k] -= rdt*(x[k] - prevSoln(k,0));
719 diag[k] = 1;
720 }
721 r[0] = 1.0 - sum;
722 diag[0] = 0;
723 } else {
724 for (size_t k = 0; k < m_nsp; k++) {
725 r[k] = x[k] - m_fixed_cov[k];
726 diag[k] = 0;
727 }
728 }
729
730 if (m_flow_right) {
731 double* rb = r + m_nsp;
732 double* xb = x + m_nsp;
733 rb[c_offset_T] = xb[c_offset_T] - m_temp; // specified T
734 }
735 if (m_flow_left) {
736 size_t nc = m_flow_left->nComponents();
737 const vector<double>& mwleft = m_phase_left->molecularWeights();
738 double* rb = r - nc;
739 double* xb = x - nc;
740 rb[c_offset_T] = xb[c_offset_T] - m_temp; // specified T
741 size_t nSkip = m_flow_left->rightExcessSpecies();
742 size_t l_offset = 0;
743 ThermoPhase* left_thermo = &m_flow_left->phase();
744 for (size_t nth = 0; nth < m_kin->nPhases(); nth++) {
745 if (&m_kin->thermo(nth) == left_thermo) {
746 l_offset = m_kin->kineticsSpeciesIndex(0, nth);
747 break;
748 }
749 }
750 for (size_t nl = 0; nl < m_left_nsp; nl++) {
751 if (nl != nSkip) {
752 rb[c_offset_Y+nl] += m_work[nl + l_offset]*mwleft[nl];
753 }
754 }
755 }
756}
757
758double ReactingSurf1D::value(const string& component) const
759{
760 if (!m_state) {
761 throw CanteraError("ReactingSurf1D::value",
762 "Domain needs to be installed in a container.");
763 }
764 auto i = componentIndex(component);
765 const double* soln = m_state->data() + m_iloc;
766 return soln[index(i, 0)];
767}
768
769shared_ptr<SolutionArray> ReactingSurf1D::toArray(bool normalize) const
770{
771 if (!m_state) {
772 throw CanteraError("ReactingSurf1D::toArray",
773 "Domain needs to be installed in a container before calling toArray.");
774 }
775 double* soln = m_state->data() + m_iloc;
777 meta["temperature"] = m_temp;
778 meta["phase"]["name"] = m_sphase->name();
779 AnyValue source = m_sphase->input().getMetadata("filename");
780 meta["phase"]["source"] = source.empty() ? "<unknown>" : source.asString();
781
782 // set state of surface phase
784 m_sphase->setCoverages(soln);
785 vector<double> data(m_sphase->stateSize());
786 m_sphase->saveState(data.size(), &data[0]);
787
788 auto arr = SolutionArray::create(m_solution, 1, meta);
789 arr->setState(0, data);
790 if (normalize) {
791 arr->normalize();
792 }
793 return arr;
794}
795
796void ReactingSurf1D::fromArray(const shared_ptr<SolutionArray>& arr)
797{
798 if (!m_state) {
799 throw CanteraError("Domain1D::fromArray",
800 "Domain needs to be installed in a container before calling fromArray.");
801 }
802 resize(nComponents(), arr->size());
804 double* soln = m_state->data() + m_iloc;
805
806 Boundary1D::setMeta(arr->meta());
807 arr->setLoc(0);
808 auto surf = std::dynamic_pointer_cast<SurfPhase>(arr->thermo());
809 if (!surf) {
810 throw CanteraError("ReactingSurf1D::fromArray",
811 "Restoring of coverages requires surface phase");
812 }
813 m_temp = surf->temperature();
814 surf->getCoverages(soln);
815 _finalize(soln);
816}
817
818void ReactingSurf1D::show(const double* x)
819{
820 writelog(" Temperature: {:10.4g} K \n", m_temp);
821 writelog(" Coverages: \n");
822 for (size_t k = 0; k < m_nsp; k++) {
823 writelog(" {:>20s} {:10.4g} \n", m_sphase->speciesName(k), x[k]);
824 }
825 writelog("\n");
826}
827}
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:595
size_t m_iloc
Starting location within the solution vector for unknowns that correspond to this domain.
Definition Domain1D.h:773
shared_ptr< Solution > m_solution
Composite thermo/kinetics/transport handler.
Definition Domain1D.h:790
OneDim * m_container
Parent OneDim simulation containing this and adjacent domains.
Definition Domain1D.h:764
size_t nComponents() const
Number of components at each grid point.
Definition Domain1D.h:148
shared_ptr< Solution > solution() const
Return thermo/kinetics/transport manager used in the domain.
Definition Domain1D.h:569
virtual bool isConnector()
True if the domain is a connector domain.
Definition Domain1D.h:58
virtual void setMeta(const AnyMap &meta)
Retrieve meta data.
Definition Domain1D.cpp:160
size_t m_index
Left-to-right location of this domain.
Definition Domain1D.h:766
string id() const
Returns the identifying tag for this domain.
Definition Domain1D.h:646
size_t m_nv
Number of solution components.
Definition Domain1D.h:752
size_t nPoints() const
Number of grid points in this domain.
Definition Domain1D.h:176
double lowerBound(size_t n) const
Lower bound on the nth component.
Definition Domain1D.h:303
shared_ptr< vector< double > > m_state
data pointer shared from OneDim
Definition Domain1D.h:749
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 upperBound(size_t n) const
Upper bound on the nth component.
Definition Domain1D.h:298
void setSolution(shared_ptr< Solution > sol)
Set the solution manager.
Definition Domain1D.cpp:31
const OneDim & container() const
The container holding this domain.
Definition Domain1D.h:86
string m_id
Identity tag for the domain.
Definition Domain1D.h:783
string type() const
String indicating the domain implemented.
Definition Domain1D.h:50
void setBounds(size_t n, double lower, double upper)
Set the upper and lower bounds for a solution component, n.
Definition Domain1D.h:242
double prevSoln(size_t n, size_t j) const
Value of component n at point j in the previous solution.
Definition Domain1D.h:636
size_t firstPoint() const
The index of the first (that is, left-most) grid point belonging to this domain.
Definition Domain1D.h:590
void needJacUpdate()
Set this if something has changed in the governing equations (for example, the value of a constant ha...
Definition Domain1D.cpp:124
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:368
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:585
virtual AnyMap getMeta() const
Retrieve meta data.
Definition Domain1D.cpp:132
shared_ptr< SolutionArray > toArray(bool normalize=false) const 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:369
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:354
ThermoPhase & phase()
Access the phase object used to compute thermodynamic properties for points in this domain.
Definition Flow1D.h:83
bool twoPointControlEnabled() const
Returns the status of the two-point control.
Definition Flow1D.h:347
size_t rightExcessSpecies() const
Index of the species on the right boundary with the largest mass fraction.
Definition Flow1D.h:428
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:262
void setViscosityFlag(bool dovisc)
Specify if the viscosity term should be included in the momentum equation.
Definition Flow1D.h:395
size_t leftExcessSpecies() const
Index of the species on the left boundary with the largest mass fraction.
Definition Flow1D.h:423
bool isFree() const
Retrieve flag indicating whether flow is freely propagating.
Definition Flow1D.h:379
bool isStrained() const
Retrieve flag indicating whether flow uses radial momentum.
Definition Flow1D.h:390
double T_fixed(size_t j) const
The fixed temperature value at point j.
Definition Flow1D.h:171
void setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
vector< double > m_yin
inlet mass fractions
Definition Boundary1D.h:187
int m_ilr
A marker that indicates whether this is a left inlet or a right inlet.
Definition Boundary1D.h:181
string m_xstr
inlet mass fractions.
Definition Boundary1D.h:188
shared_ptr< SolutionArray > toArray(bool normalize=false) const override
Save the state of this domain to a SolutionArray.
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 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:186
void init() override
Initialize.
Flow1D * m_flow
the adjacent flow domain
Definition Boundary1D.h:189
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:184
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:248
size_t nPhases() const
The number of phases participating in the reaction mechanism.
Definition Kinetics.h:193
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
Definition Kinetics.h:282
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
Definition Kinetics.h:260
virtual void getNetProductionRates(double *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
Definition Kinetics.cpp:428
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:186
Domain1D & domain(size_t i) const
Return a reference to domain i.
Definition OneDim.h:78
shared_ptr< SolutionArray > toArray(bool normalize=false) const 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:287
void setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
OutletRes1D()
Default constructor.
string m_xstr
Mole fractions in the reservoir.
Definition Boundary1D.h:321
shared_ptr< SolutionArray > toArray(bool normalize=false) const override
Save the state of this domain to a SolutionArray.
vector< double > m_yres
Mass fractions in the reservoir.
Definition Boundary1D.h:320
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:319
void init() override
Initialize.
Flow1D * m_flow
The adjacent flow domain.
Definition Boundary1D.h:322
virtual void setMoleFractions(const double *const x)
Set the mole fractions to the specified values.
Definition Phase.cpp:310
size_t nSpecies() const
Returns the number of species in the phase.
Definition Phase.h:232
void saveState(vector< double > &state) const
Save the current internal state of the phase.
Definition Phase.cpp:266
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:258
void setMoleFractionsByName(const Composition &xMap)
Set the species mole fractions by name.
Definition Phase.cpp:351
const vector< double > & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
Definition Phase.cpp:423
size_t speciesIndex(const string &name) const
Returns the index of a species named 'name' within the Phase object.
Definition Phase.cpp:129
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
Definition Phase.h:648
void getMassFractions(double *const y) const
Get the species mass fractions.
Definition Phase.cpp:499
virtual double pressure() const
Return the thermodynamic pressure (Pa).
Definition Phase.h:605
string name() const
Return the name of the phase.
Definition Phase.cpp:20
SurfPhase * m_sphase
phase representing the surface species
Definition Boundary1D.h:410
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:409
bool m_enabled
True if coverage equations are being solved.
Definition Boundary1D.h:412
vector< double > m_fixed_cov
Fixed values of the coverages used when coverage equations are not being solved.
Definition Boundary1D.h:420
ReactingSurf1D()
Default constructor.
vector< double > m_work
temporary vector used to store coverages and production rates.
Definition Boundary1D.h:416
shared_ptr< SolutionArray > toArray(bool normalize=false) const 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:402
size_t m_nsp
the number of surface phase species
Definition Boundary1D.h:411
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) const 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: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 > toArray(bool normalize=false) const 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