16 Bdry1D::Bdry1D() : Domain1D(1, 1, 0.0),
17 m_flow_left(0), m_flow_right(0),
18 m_ilr(0), m_left_nv(0), m_right_nv(0),
19 m_left_loc(0), m_right_loc(0),
21 m_left_nsp(0), m_right_nsp(0),
22 m_sp_left(0), m_sp_right(0),
23 m_start_left(0), m_start_right(0),
24 m_phase_left(0), m_phase_right(0), m_temp(0.0), m_mdot(0.0)
26 m_type = cConnectorType;
29 void Bdry1D::_init(
size_t n)
31 if (m_index ==
npos) {
32 throw CanteraError(
"Bdry1D::_init",
33 "install in container before calling init.");
44 Domain1D& r = container().domain(m_index-1);
45 if (r.domainType() == cFlowType) {
46 m_flow_left = (StFlow*)&r;
47 m_left_nv = m_flow_left->nComponents();
48 m_left_points = m_flow_left->nPoints();
49 m_left_loc = container().start(m_index-1);
50 m_left_nsp = m_left_nv - c_offset_Y;
51 m_phase_left = &m_flow_left->phase();
53 throw CanteraError(
"Bdry1D::_init",
54 "Boundary domains can only be connected on the left to flow " 55 "domains, not type {} domains.", r.domainType());
60 if (m_index + 1 < container().nDomains()) {
61 Domain1D& r = container().domain(m_index+1);
62 if (r.domainType() == cFlowType) {
63 m_flow_right = (StFlow*)&r;
64 m_right_nv = m_flow_right->nComponents();
65 m_right_loc = container().start(m_index+1);
66 m_right_nsp = m_right_nv - c_offset_Y;
67 m_phase_right = &m_flow_right->phase();
69 throw CanteraError(
"Bdry1D::_init",
70 "Boundary domains can only be connected on the right to flow " 71 "domains, not type {} domains.", r.domainType());
87 void Inlet1D::showSolution(
const double* x)
89 writelog(
" Mass Flux: {:10.4g} kg/m^2/s \n", m_mdot);
90 writelog(
" Temperature: {:10.4g} K \n", m_temp);
93 for (
size_t k = 0; k < m_flow->phase().nSpecies(); k++) {
94 if (m_yin[k] != 0.0) {
96 m_flow->phase().speciesName(k), m_yin[k]);
103 void Inlet1D::setMoleFractions(
const std::string& xin)
107 m_flow->phase().setMoleFractionsByName(xin);
108 m_flow->phase().getMassFractions(m_yin.data());
113 void Inlet1D::setMoleFractions(
const doublereal* xin)
116 m_flow->phase().setMoleFractions(xin);
117 m_flow->phase().getMassFractions(m_yin.data());
131 m_flow = m_flow_left;
132 }
else if (m_flow_right) {
134 m_flow = m_flow_right;
140 m_nsp = m_flow->nComponents() - c_offset_Y;
141 m_yin.resize(m_nsp, 0.0);
143 setMoleFractions(m_xstr);
149 void Inlet1D::eval(
size_t jg, doublereal* xg, doublereal* rg,
150 integer* diagg, doublereal rdt)
152 if (jg !=
npos && (jg + 2 < firstPoint() || jg > lastPoint() + 2)) {
156 if (m_ilr == LeftInlet) {
158 double* xb = xg + m_flow->loc();
159 double* rb = rg + m_flow->loc();
173 if (m_flow->fixed_mdot()) {
180 m_mdot = m_flow->density(0)*xb[0];
185 for (
size_t k = 0; k < m_nsp; k++) {
186 if (k != m_flow_right->leftExcessSpecies()) {
187 rb[c_offset_Y+k] += m_mdot*m_yin[k];
194 double* rb = rg + loc() - m_flow->nComponents();
198 for (
size_t k = 0; k < m_nsp; k++) {
199 if (k != m_flow_left->rightExcessSpecies()) {
200 rb[c_offset_Y+k] += m_mdot * m_yin[k];
208 XML_Node& inlt = Domain1D::save(o, soln);
210 addFloat(inlt,
"temperature", m_temp);
212 for (
size_t k=0; k < m_nsp; k++) {
213 addFloat(inlt,
"massFraction", m_yin[k],
"",
214 m_flow->phase().speciesName(k));
219 void Inlet1D::restore(
const XML_Node& dom, doublereal* soln,
int loglevel)
221 Domain1D::restore(dom, soln, loglevel);
223 m_temp =
getFloat(dom,
"temperature");
225 m_yin.assign(m_nsp, 0.0);
227 for (
size_t i = 0; i < dom.
nChildren(); i++) {
229 if (node.
name() ==
"massFraction") {
230 size_t k = m_flow->phase().speciesIndex(node.
attrib(
"type"));
246 void Empty1D::eval(
size_t jg, doublereal* xg, doublereal* rg,
247 integer* diagg, doublereal rdt)
253 XML_Node& symm = Domain1D::save(o, soln);
258 void Empty1D::restore(
const XML_Node& dom, doublereal* soln,
int loglevel)
260 Domain1D::restore(dom, soln, loglevel);
271 void Symm1D::eval(
size_t jg, doublereal* xg, doublereal* rg, integer* diagg,
274 if (jg !=
npos && (jg + 2< firstPoint() || jg > lastPoint() + 2)) {
279 doublereal* x = xg + loc();
280 doublereal* r = rg + loc();
281 integer* diag = diagg + loc();
284 size_t nc = m_flow_right->nComponents();
290 rb[1] = xb[1] - xb[1 + nc];
291 rb[2] = xb[2] - xb[2 + nc];
295 size_t nc = m_flow_left->nComponents();
301 rb[1] = xb[1] - xb[1 - nc];
302 rb[2] = xb[2] - xb[2 - nc];
308 XML_Node& symm = Domain1D::save(o, soln);
313 void Symm1D::restore(
const XML_Node& dom, doublereal* soln,
int loglevel)
315 Domain1D::restore(dom, soln, loglevel);
321 OutletRes1D::OutletRes1D()
325 m_type = cOutletResType;
334 m_flow_right->setViscosityFlag(
false);
337 m_flow_left->setViscosityFlag(
false);
349 doublereal* x = xg +
loc();
350 doublereal* r = rg +
loc();
351 integer* diag = diagg +
loc();
358 rb[2] = xb[2] - xb[2 + nc];
359 for (
size_t k = c_offset_Y; k < nc; k++) {
360 rb[k] = xb[k] - xb[k + nc];
371 if (m_flow_left->fixed_mdot()) {
375 rb[2] = xb[2] - xb[2 - nc];
377 for (
size_t k = c_offset_Y; k < nc; k++) {
379 rb[k] = xb[k] - xb[k - nc];
425 m_flow = m_flow_left;
426 }
else if (m_flow_right) {
427 m_flow = m_flow_right;
433 m_yres.resize(m_nsp, 0.0);
442 integer* diagg, doublereal rdt)
449 doublereal* x = xg +
loc();
450 doublereal* r = rg +
loc();
451 integer* diag = diagg +
loc();
463 rb[2] = xb[2] - xb[2 + nc];
466 for (
size_t k = c_offset_Y; k < nc; k++) {
467 rb[k] = xb[k] - m_yres[k-c_offset_Y];
477 if (!m_flow_left->fixed_mdot()) {
482 rb[2] = xb[2] - m_temp;
484 for (
size_t k = c_offset_Y; k < nc; k++) {
486 rb[k] = xb[k] - m_yres[k-c_offset_Y];
497 addFloat(outlt,
"temperature", m_temp,
"K");
498 for (
size_t k=0; k < m_nsp; k++) {
499 addFloat(outlt,
"massFraction", m_yres[k],
"",
508 m_temp =
getFloat(dom,
"temperature");
510 m_yres.assign(m_nsp, 0.0);
511 for (
size_t i = 0; i < dom.
nChildren(); i++) {
513 if (node.
name() ==
"massFraction") {
532 integer* diagg, doublereal rdt)
539 doublereal* x = xg +
loc();
540 doublereal* r = rg +
loc();
545 rb[2] = xb[2] - m_temp;
552 rb[2] = xb[2] - m_temp;
560 addFloat(inlt,
"temperature", m_temp);
567 m_temp =
getFloat(dom,
"temperature");
571 void Surf1D::showSolution_s(std::ostream& s,
const double* x)
573 s <<
"------------------- Surface " <<
domainIndex() <<
" ------------------- " << std::endl;
574 s <<
" temperature: " << m_temp <<
" K" << std::endl;
579 ReactingSurf1D::ReactingSurf1D()
587 void ReactingSurf1D::setKineticsMgr(InterfaceKinetics* kin)
590 m_surfindex = kin->surfacePhaseIndex();
591 m_sphase = (SurfPhase*)&kin->thermo(m_surfindex);
609 m_fixed_cov.resize(m_nsp, 0.0);
610 m_fixed_cov[0] = 1.0;
613 for (
size_t n = 0; n < m_nsp; n++) {
614 setBounds(n, -1.0e-5, 2.0);
619 double* x = xg +
loc();
625 integer* diagg, doublereal rdt)
632 doublereal* x = xg +
loc();
633 doublereal* r = rg +
loc();
634 integer* diag = diagg +
loc();
637 doublereal sum = 0.0;
638 for (
size_t k = 0; k < m_nsp; k++) {
647 size_t leftloc = 0, rightloc = 0;
651 leftloc = m_flow_left->
loc();
652 pnt = m_flow_left->
nPoints() - 1;
653 m_flow_left->
setGas(xg + leftloc, pnt);
657 rightloc = m_flow_right->
loc();
658 m_flow_right->
setGas(xg + rightloc, 0);
666 doublereal maxx = -1.0;
667 for (
size_t k = 0; k < m_nsp; k++) {
668 r[k] = m_work[k + ioffset] * m_sphase->
size(k) * rs0;
671 maxx = std::max(x[k], maxx);
676 for (
size_t k = 0; k < m_nsp; k++) {
677 r[k] = x[k] - m_fixed_cov[k];
683 double* rb = r + m_nsp;
684 double* xb = x + m_nsp;
685 rb[2] = xb[2] - m_temp;
692 rb[2] = xb[2] - m_temp;
694 for (
size_t nl = 0; nl < m_left_nsp; nl++) {
696 rb[c_offset_Y+nl] += m_work[nl]*mwleft[nl];
704 const doublereal* s = soln +
loc();
707 addFloat(dom,
"temperature", m_temp,
"K");
708 for (
size_t k=0; k < m_nsp; k++) {
718 m_temp =
getFloat(dom,
"temperature");
720 m_fixed_cov.assign(m_nsp, 0.0);
721 for (
size_t i = 0; i < dom.
nChildren(); i++) {
723 if (node.
name() ==
"coverage") {
726 m_fixed_cov[k] = soln[k] = node.
fp_value();
737 writelog(
" Temperature: {:10.4g} K \n", m_temp);
739 for (
size_t k = 0; k < m_nsp; k++) {
void setCoveragesNoNorm(const doublereal *theta)
Set the surface site fractions to a specified state.
const vector_fp & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
std::string name() const
Returns the name of the XML node.
void getMassFractions(doublereal *const y) const
Get the species mass fractions.
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
size_t speciesIndex(const std::string &name) const
Returns the index of a species named 'name' within the Phase object.
virtual void setMoleFractions(const std::string &xin)
Set the mole fractions by specifying a std::string.
virtual void eval(size_t jg, doublereal *xg, doublereal *rg, integer *diagg, doublereal rdt)
Evaluate the residual function at point j.
const size_t npos
index returned by functions to indicate "no position"
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
size_t firstPoint() const
The index of the first (i.e., left-most) grid point belonging to this domain.
void writelog(const std::string &fmt, const Args &... args)
Write a formatted message to the screen.
void setCoverages(const doublereal *theta)
Set the surface site fractions to a specified state.
Class XML_Node is a tree-based representation of the contents of an XML file.
size_t nSpecies() const
Returns the number of species in the phase.
virtual void eval(size_t jg, doublereal *xg, doublereal *rg, integer *diagg, doublereal rdt)
Evaluate the residual function at point j.
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
virtual void eval(size_t jg, doublereal *xg, doublereal *rg, integer *diagg, doublereal rdt)
Evaluate the residual function at point j.
virtual XML_Node & save(XML_Node &o, const doublereal *const soln)
Save the current solution for this domain into an XML_Node.
virtual XML_Node & save(XML_Node &o, const doublereal *const sol)
Save the current solution for this domain into an XML_Node.
virtual void getNetProductionRates(doublereal *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
virtual XML_Node & save(XML_Node &o, const doublereal *const soln)
Save the current solution for this domain into an XML_Node.
size_t lastPoint() const
The index of the last (i.e., right-most) grid point belonging to this domain.
virtual void eval(size_t jg, doublereal *xg, doublereal *rg, integer *diagg, doublereal rdt)
Evaluate the residual function at point j.
Boundary objects for one-dimensional simulations.
virtual void resize(size_t nv, size_t np)
virtual void showSolution(const doublereal *x)
Print the solution.
void getCoverages(doublereal *theta) const
Return a vector of surface coverages.
virtual XML_Node & save(XML_Node &o, const doublereal *const soln)
Save the current solution for this domain into an XML_Node.
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
std::string speciesName(size_t k) const
Name of the species with index k.
void setMoleFractionsByName(const compositionMap &xMap)
Set the species mole fractions by name.
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
Base class for exceptions thrown by Cantera classes.
virtual void setMoleFractions(const doublereal *const x)
Set the mole fractions to the specified values.
virtual XML_Node & save(XML_Node &o, const doublereal *const soln)
Save the current solution for this domain into an XML_Node.
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
size_t domainIndex()
The left-to-right location of this domain.
double prevSoln(size_t n, size_t j) const
Value of component n at point j in the previous solution.
XML_Node & child(const size_t n) const
Return a changeable reference to the n'th child of the current node.
void setGas(const doublereal *x, size_t j)
Set the gas object state to be consistent with the solution at point j.
void addFloat(XML_Node &node, const std::string &title, const doublereal val, const std::string &units, const std::string &type, const doublereal minval, const doublereal maxval)
This function adds a child node with the name, "float", with a value consisting of a single floating ...
size_t nComponents() const
Number of components at each grid point.
std::string attrib(const std::string &attr) const
Function returns the value of an attribute.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
virtual void setTemperature(const doublereal temp)
Set the internally stored temperature of the phase (K).
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
doublereal getFloat(const XML_Node &parent, const std::string &name, const std::string &type)
Get a floating-point value from a child element.
doublereal size(size_t k) const
This routine returns the size of species k.
size_t rightExcessSpecies() const
Index of the species on the right boundary with the largest mass fraction.
virtual std::string componentName(size_t n) const
Name of the nth component. May be overloaded.
size_t nPoints() const
Number of grid points in this domain.
Namespace for the Cantera kernel.
doublereal fp_value() const
Return the value of an XML node as a single double.
size_t nChildren(bool discardComments=false) const
Return the number of children.
virtual size_t loc(size_t j=0) const
Location of the start of the local solution vector in the global solution vector,.
doublereal siteDensity()
Returns the site density.
virtual void resetBadValues(double *xg)