16 Boundary1D::Boundary1D() : Domain1D(1, 1, 0.0)
20 void Boundary1D::_init(
size_t n)
22 if (m_index ==
npos) {
23 throw CanteraError(
"Boundary1D::_init",
24 "install in container before calling init.");
35 Domain1D& r = container().domain(m_index-1);
36 if (!r.isConnector()) {
37 m_left_nv = r.nComponents();
43 m_left_loc = container().start(m_index-1);
44 m_left_points = r.nPoints();
45 m_flow_left =
dynamic_cast<StFlow*
>(&r);
46 if (m_flow_left !=
nullptr) {
47 m_phase_left = &m_flow_left->phase();
50 throw CanteraError(
"Boundary1D::_init",
51 "Boundary domains can only be connected on the left to flow "
52 "domains, not '{}' domains.", r.type());
57 if (m_index + 1 < container().nDomains()) {
58 Domain1D& r = container().domain(m_index+1);
59 if (!r.isConnector()) {
60 m_right_nv = r.nComponents();
66 m_right_loc = container().start(m_index+1);
67 m_flow_right =
dynamic_cast<StFlow*
>(&r);
68 if (m_flow_right !=
nullptr) {
69 m_phase_right = &m_flow_right->phase();
72 throw CanteraError(
"Boundary1D::_init",
73 "Boundary domains can only be connected on the right to flow "
74 "domains, not '{}' domains.", r.type());
90 Inlet1D::Inlet1D(shared_ptr<Solution> solution,
const string&
id)
108 writelog(
" Mass Flux: {:10.4g} kg/m^2/s \n", m_mdot);
109 writelog(
" Temperature: {:10.4g} K \n", m_temp);
112 for (
size_t k = 0; k < m_flow->phase().nSpecies(); k++) {
113 if (m_yin[k] != 0.0) {
148 if (m_flow_left && !m_flow_right) {
151 "Right inlets with right-to-left flow are only supported for "
152 "strained flow configurations.");
155 m_flow = m_flow_left;
156 }
else if (m_flow_right) {
158 m_flow = m_flow_right;
160 throw CanteraError(
"Inlet1D::init",
"Inlet1D is not properly connected.");
165 m_yin.resize(m_nsp, 0.0);
174 integer* diagg,
double rdt)
180 if (m_ilr == LeftInlet) {
182 double* xb = xg + m_flow->
loc();
183 double* rb = rg + m_flow->
loc();
189 if (m_flow->doEnergy(0)) {
216 for (
size_t k = 0; k < m_nsp; k++) {
227 if (m_flow->doEnergy(m_flow->
nPoints() - 1)) {
233 for (
size_t k = 0; k < m_nsp; k++) {
244 meta[
"mass-flux"] = m_mdot;
248 double pressure = m_flow->phase().
pressure();
250 phase->setState_TPY(m_temp, pressure, m_yin.data());
251 vector<double> data(phase->stateSize());
252 phase->saveState(data);
254 arr->setState(0, data);
262 auto phase = arr.
thermo();
263 auto meta = arr.
meta();
264 m_temp = phase->temperature();
265 if (meta.hasKey(
"mass-flux")) {
266 m_mdot = meta.at(
"mass-flux").asDouble();
270 m_mdot = phase->density() * aux.at(
"velocity").as<
double>();
272 phase->getMassFractions(m_yin.data());
283 integer* diagg,
double rdt)
308 double* x = xg +
loc();
309 double* r = rg +
loc();
310 integer* diag = diagg +
loc();
320 if (m_flow_right->doEnergy(0)) {
333 if (m_flow_left->doEnergy(m_flow_left->
nPoints() - 1)) {
347 OutletRes1D::OutletRes1D()
351 OutletRes1D::OutletRes1D(shared_ptr<Solution> solution,
const string&
id)
364 "Left outlets with right-to-left flow are not supported.");
367 m_flow_left->setViscosityFlag(
false);
369 throw CanteraError(
"Outlet1D::init",
"Outlet1D is not connected.");
381 double* x = xg +
loc();
382 double* r = rg +
loc();
383 integer* diag = diagg +
loc();
391 size_t last = m_flow_left->
nPoints() - 1;
392 if (m_flow_left->doEnergy(last)) {
400 rb[k] = xb[k] - xb[k - nc];
439 "Left outlets with right-to-left flow are not supported.");
442 m_flow = m_flow_left;
448 m_yres.resize(m_nsp, 0.0);
457 integer* diagg,
double rdt)
464 double* x = xg +
loc();
465 double* r = rg +
loc();
466 integer* diag = diagg +
loc();
473 size_t last = m_flow_left->
nPoints() - 1;
474 if (m_flow_left->doEnergy(last)) {
491 meta[
"temperature"] = m_temp;
495 double pressure = m_flow->phase().
pressure();
497 phase->setState_TPY(m_temp, pressure, &m_yres[0]);
498 vector<double> data(phase->stateSize());
499 phase->saveState(data);
501 arr->setState(0, data);
509 auto phase = arr.
thermo();
510 m_temp = phase->temperature();
511 auto Y = phase->massFractions();
512 std::copy(Y, Y + m_nsp, &m_yres[0]);
523 integer* diagg,
double rdt)
530 double* x = xg +
loc();
531 double* r = rg +
loc();
550 meta[
"temperature"] = m_temp;
556 auto meta = arr.
meta();
557 m_temp = meta[
"temperature"].asDouble();
558 meta.erase(
"temperature");
564 s <<
"------------------- Surface " <<
domainIndex() <<
" ------------------- " << std::endl;
565 s <<
" temperature: " << m_temp <<
" K" << std::endl;
570 writelog(
" Temperature: {:10.4g} K \n\n", m_temp);
575 ReactingSurf1D::ReactingSurf1D()
581 ReactingSurf1D::ReactingSurf1D(shared_ptr<Solution> solution,
const string&
id)
583 auto phase = std::dynamic_pointer_cast<SurfPhase>(
solution->thermo());
585 throw CanteraError(
"ReactingSurf1D::ReactingSurf1D",
586 "Detected incompatible ThermoPhase type '{}'",
solution->thermo()->type());
588 auto kin = std::dynamic_pointer_cast<InterfaceKinetics>(
solution->kinetics());
590 throw CanteraError(
"ReactingSurf1D::ReactingSurf1D",
591 "Detected incompatible kinetics type '{}'",
592 solution->kinetics()->kineticsType());
597 m_sphase = phase.get();
608 m_kin = dynamic_pointer_cast<InterfaceKinetics>(kin).get();
609 m_sphase = dynamic_pointer_cast<SurfPhase>(kin->reactionPhase()).get();
628 m_fixed_cov.resize(m_nsp, 0.0);
629 m_fixed_cov[0] = 1.0;
632 for (
size_t n = 0; n < m_nsp; n++) {
633 setBounds(n, -1.0e-5, 2.0);
638 double* x = xg +
loc();
644 integer* diagg,
double rdt)
651 double* x = xg +
loc();
652 double* r = rg +
loc();
653 integer* diag = diagg +
loc();
657 for (
size_t k = 0; k < m_nsp; k++) {
666 size_t leftloc = 0, rightloc = 0;
670 leftloc = m_flow_left->
loc();
671 pnt = m_flow_left->
nPoints() - 1;
672 m_flow_left->
setGas(xg + leftloc, pnt);
676 rightloc = m_flow_right->
loc();
677 m_flow_right->
setGas(xg + rightloc, 0);
684 for (
size_t k = 0; k < m_nsp; k++) {
685 r[k] = m_work[k] * m_sphase->
size(k) * rs0;
692 for (
size_t k = 0; k < m_nsp; k++) {
693 r[k] = x[k] - m_fixed_cov[k];
699 double* rb = r + m_nsp;
700 double* xb = x + m_nsp;
712 for (
size_t nth = 0; nth < m_kin->
nPhases(); nth++) {
713 if (&m_kin->
thermo(nth) == left_thermo) {
718 for (
size_t nl = 0; nl < m_left_nsp; nl++) {
720 rb[
c_offset_Y+nl] += m_work[nl + l_offset]*mwleft[nl];
729 meta[
"temperature"] = m_temp;
730 meta[
"phase"][
"name"] = m_sphase->
name();
732 meta[
"phase"][
"source"] = source.
empty() ?
"<unknown>" : source.
asString();
737 vector<double> data(m_sphase->
stateSize());
738 m_sphase->
saveState(data.size(), &data[0]);
741 arr->setState(0, data);
749 auto surf = std::dynamic_pointer_cast<SurfPhase>(arr.
thermo());
752 "Restoring of coverages requires surface phase");
754 m_temp = surf->temperature();
755 surf->getCoverages(soln);
760 writelog(
" Temperature: {:10.4g} K \n", m_temp);
762 for (
size_t k = 0; k < m_nsp; k++) {
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.
A map of string keys to values whose type can vary at runtime.
A wrapper for a variable whose type is determined at runtime.
const string & asString() const
Return the held value, if it is a string.
bool empty() const
Return boolean indicating whether AnyValue is empty.
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.
size_t domainIndex()
The left-to-right location of this domain.
shared_ptr< Solution > m_solution
Composite thermo/kinetics/transport handler.
size_t nComponents() const
Number of components at each grid point.
virtual void setMeta(const AnyMap &meta)
Retrieve meta data.
size_t nPoints() const
Number of grid points in this domain.
shared_ptr< Solution > solution() const
Return thermo/kinetics/transport manager used in the domain.
string m_id
Identity tag for the domain.
double prevSoln(size_t n, size_t j) const
Value of component n at point j in the previous solution.
size_t firstPoint() const
The index of the first (that is, left-most) grid point belonging to this domain.
void needJacUpdate()
Set this if something has changed in the governing equations (for example, the value of a constant ha...
virtual size_t loc(size_t j=0) const
Location of the start of the local solution vector in the global solution vector,.
virtual AnyMap getMeta() const
Retrieve meta data.
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.
void setSpreadRate(double V0) override
set spreading rate
void show(const double *x) override
Print the solution.
size_t nPhases() const
The number of phases participating in the reaction mechanism.
size_t kineticsSpeciesIndex(size_t k, size_t n) const
The location of species k of phase n in species arrays.
size_t nTotalSpecies() const
The total number of species in all phases participating in the kinetics mechanism.
virtual void getNetProductionRates(double *wdot)
Species net production rates [kmol/m^3/s or kmol/m^2/s].
ThermoPhase & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism.
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.
size_t nSpecies() const
Returns the number of species in the phase.
void saveState(vector< double > &state) const
Save the current internal state of the phase.
string speciesName(size_t k) const
Name of the species with index k.
virtual size_t stateSize() const
Return size of vector defining internal state of the phase.
void setMoleFractionsByName(const Composition &xMap)
Set the species mole fractions by name.
const vector< double > & molecularWeights() const
Return a const reference to the internal vector of molecular weights.
virtual void setTemperature(double temp)
Set the internally stored temperature of the phase (K).
void getMassFractions(double *const y) const
Get the species mass fractions.
virtual double pressure() const
Return the thermodynamic pressure (Pa).
string name() const
Return the name of the phase.
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.
static shared_ptr< SolutionArray > create(const shared_ptr< Solution > &sol, int size=0, const AnyMap &meta={})
Instantiate a new SolutionArray reference.
AnyMap & meta()
SolutionArray meta data.
shared_ptr< ThermoPhase > thermo()
Retrieve associated ThermoPhase object.
static shared_ptr< Solution > create()
Create an empty Solution object.
size_t rightExcessSpecies() const
Index of the species on the right boundary with the largest mass fraction.
void setGas(const double *x, size_t j)
Set the gas object state to be consistent with the solution at point j.
size_t leftExcessSpecies() const
Index of the species on the left boundary with the largest mass fraction.
bool isFree() const
Retrieve flag indicating whether flow is freely propagating.
bool isStrained() const
Retrieve flag indicating whether flow uses radial momentum.
double T_fixed(size_t j) const
The fixed temperature value at point j.
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).
double size(size_t k) const
Returns the number of sites occupied by one molecule of species k.
void setCoverages(const double *theta)
Set the surface site fractions to a specified state.
double siteDensity() const
Returns the site density.
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.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
@ c_offset_U
axial velocity
@ c_offset_Y
mass fractions