16Boundary1D::Boundary1D() : Domain1D(1, 1, 0.0)
18 m_type = cConnectorType;
21void Boundary1D::_init(
size_t n)
23 if (m_index == npos) {
24 throw CanteraError(
"Boundary1D::_init",
25 "install in container before calling init.");
36 Domain1D& r = container().domain(m_index-1);
37 if (!r.isConnector()) {
38 m_left_nv = r.nComponents();
39 if (m_left_nv > c_offset_Y) {
44 m_left_loc = container().start(m_index-1);
45 m_left_points = r.nPoints();
46 m_flow_left =
dynamic_cast<StFlow*
>(&r);
47 if (m_flow_left !=
nullptr) {
48 m_phase_left = &m_flow_left->phase();
51 throw CanteraError(
"Boundary1D::_init",
52 "Boundary domains can only be connected on the left to flow "
53 "domains, not '{}' domains.", r.type());
58 if (m_index + 1 < container().nDomains()) {
59 Domain1D& r = container().domain(m_index+1);
60 if (!r.isConnector()) {
61 m_right_nv = r.nComponents();
62 if (m_right_nv > c_offset_Y) {
67 m_right_loc = container().start(m_index+1);
68 m_flow_right =
dynamic_cast<StFlow*
>(&r);
69 if (m_flow_right !=
nullptr) {
70 m_phase_right = &m_flow_right->phase();
73 throw CanteraError(
"Boundary1D::_init",
74 "Boundary domains can only be connected on the right to flow "
75 "domains, not '{}' domains.", r.type());
92Inlet1D::Inlet1D(shared_ptr<Solution> solution,
const string&
id)
110 writelog(
" Mass Flux: {:10.4g} kg/m^2/s \n", m_mdot);
111 writelog(
" Temperature: {:10.4g} K \n", m_temp);
114 for (
size_t k = 0; k < m_flow->phase().nSpecies(); k++) {
115 if (m_yin[k] != 0.0) {
150 if (m_flow_left && !m_flow_right) {
153 "Right inlets with right-to-left flow are only supported for "
154 "strained flow configurations.");
157 m_flow = m_flow_left;
158 }
else if (m_flow_right) {
160 m_flow = m_flow_right;
162 throw CanteraError(
"Inlet1D::init",
"Inlet1D is not properly connected.");
167 m_yin.resize(m_nsp, 0.0);
176 integer* diagg,
double rdt)
182 if (m_ilr == LeftInlet) {
184 double* xb = xg + m_flow->
loc();
185 double* rb = rg + m_flow->
loc();
191 if (m_flow->doEnergy(0)) {
218 for (
size_t k = 0; k < m_nsp; k++) {
229 if (m_flow->doEnergy(m_flow->
nPoints() - 1)) {
235 for (
size_t k = 0; k < m_nsp; k++) {
246 meta[
"mass-flux"] = m_mdot;
250 double pressure = m_flow->phase().
pressure();
252 phase->setState_TPY(m_temp, pressure, m_yin.data());
253 vector<double> data(phase->stateSize());
254 phase->saveState(data);
256 arr->setState(0, data);
264 auto phase = arr.
thermo();
265 auto meta = arr.
meta();
266 m_temp = phase->temperature();
267 if (meta.hasKey(
"mass-flux")) {
268 m_mdot = meta.at(
"mass-flux").asDouble();
272 m_mdot = phase->density() * aux.at(
"velocity").as<
double>();
274 phase->getMassFractions(m_yin.data());
285 integer* diagg,
double rdt)
310 double* x = xg +
loc();
311 double* r = rg +
loc();
312 integer* diag = diagg +
loc();
322 if (m_flow_right->doEnergy(0)) {
335 if (m_flow_left->doEnergy(m_flow_left->
nPoints() - 1)) {
349OutletRes1D::OutletRes1D()
354OutletRes1D::OutletRes1D(shared_ptr<Solution> solution,
const string&
id)
367 "Left outlets with right-to-left flow are not supported.");
370 m_flow_left->setViscosityFlag(
false);
372 throw CanteraError(
"Outlet1D::init",
"Outlet1D is not connected.");
384 double* x = xg +
loc();
385 double* r = rg +
loc();
386 integer* diag = diagg +
loc();
394 size_t last = m_flow_left->
nPoints() - 1;
395 if (m_flow_left->doEnergy(last)) {
403 rb[k] = xb[k] - xb[k - nc];
442 "Left outlets with right-to-left flow are not supported.");
445 m_flow = m_flow_left;
451 m_yres.resize(m_nsp, 0.0);
460 integer* diagg,
double rdt)
467 double* x = xg +
loc();
468 double* r = rg +
loc();
469 integer* diag = diagg +
loc();
476 size_t last = m_flow_left->
nPoints() - 1;
477 if (m_flow_left->doEnergy(last)) {
494 meta[
"temperature"] = m_temp;
498 double pressure = m_flow->phase().
pressure();
500 phase->setState_TPY(m_temp, pressure, &m_yres[0]);
501 vector<double> data(phase->stateSize());
502 phase->saveState(data);
504 arr->setState(0, data);
512 auto phase = arr.
thermo();
513 m_temp = phase->temperature();
514 auto Y = phase->massFractions();
515 std::copy(Y, Y + m_nsp, &m_yres[0]);
526 integer* diagg,
double rdt)
533 double* x = xg +
loc();
534 double* r = rg +
loc();
553 meta[
"temperature"] = m_temp;
559 auto meta = arr.
meta();
560 m_temp = meta[
"temperature"].asDouble();
561 meta.erase(
"temperature");
567 s <<
"------------------- Surface " <<
domainIndex() <<
" ------------------- " << std::endl;
568 s <<
" temperature: " << m_temp <<
" K" << std::endl;
573 writelog(
" Temperature: {:10.4g} K \n\n", m_temp);
578ReactingSurf1D::ReactingSurf1D()
586ReactingSurf1D::ReactingSurf1D(shared_ptr<Solution> solution,
const string&
id)
588 auto phase = std::dynamic_pointer_cast<SurfPhase>(
solution->thermo());
590 throw CanteraError(
"ReactingSurf1D::ReactingSurf1D",
591 "Detected incompatible ThermoPhase type '{}'",
solution->thermo()->type());
593 auto kin = std::dynamic_pointer_cast<InterfaceKinetics>(
solution->kinetics());
595 throw CanteraError(
"ReactingSurf1D::ReactingSurf1D",
596 "Detected incompatible kinetics type '{}'",
597 solution->kinetics()->kineticsType());
602 m_sphase = phase.get();
615 m_kin = dynamic_pointer_cast<InterfaceKinetics>(kin).get();
616 m_surfindex = kin->reactionPhaseIndex();
617 m_sphase = dynamic_pointer_cast<SurfPhase>(kin->reactionPhase()).get();
625 "To be removed after Cantera 3.0. Replaced by Domain1D::setKinetics.");
647 m_fixed_cov.resize(m_nsp, 0.0);
648 m_fixed_cov[0] = 1.0;
651 for (
size_t n = 0; n < m_nsp; n++) {
652 setBounds(n, -1.0e-5, 2.0);
657 double* x = xg +
loc();
663 integer* diagg,
double rdt)
670 double* x = xg +
loc();
671 double* r = rg +
loc();
672 integer* diag = diagg +
loc();
676 for (
size_t k = 0; k < m_nsp; k++) {
685 size_t leftloc = 0, rightloc = 0;
689 leftloc = m_flow_left->
loc();
690 pnt = m_flow_left->
nPoints() - 1;
691 m_flow_left->
setGas(xg + leftloc, pnt);
695 rightloc = m_flow_right->
loc();
696 m_flow_right->
setGas(xg + rightloc, 0);
704 for (
size_t k = 0; k < m_nsp; k++) {
705 r[k] = m_work[k + ioffset] * m_sphase->
size(k) * rs0;
712 for (
size_t k = 0; k < m_nsp; k++) {
713 r[k] = x[k] - m_fixed_cov[k];
719 double* rb = r + m_nsp;
720 double* xb = x + m_nsp;
732 for (
size_t nth = 0; nth < m_kin->
nPhases(); nth++) {
733 if (&m_kin->
thermo(nth) == left_thermo) {
738 for (
size_t nl = 0; nl < m_left_nsp; nl++) {
740 rb[
c_offset_Y+nl] += m_work[nl + l_offset]*mwleft[nl];
749 meta[
"temperature"] = m_temp;
750 meta[
"phase"][
"name"] = m_sphase->
name();
752 meta[
"phase"][
"source"] = source.
empty() ?
"<unknown>" : source.
asString();
757 vector<double> data(m_sphase->
stateSize());
758 m_sphase->
saveState(data.size(), &data[0]);
761 arr->setState(0, data);
769 auto surf = std::dynamic_pointer_cast<SurfPhase>(arr.
thermo());
772 "Restoring of coverages requires surface phase");
774 m_temp = surf->temperature();
775 surf->getCoverages(soln);
780 writelog(
" Temperature: {:10.4g} K \n", m_temp);
782 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.
shared_ptr< Solution > solution() const
Return thermo/kinetics/transport manager used in the domain.
virtual void setMeta(const AnyMap &meta)
Retrieve meta data.
size_t nPoints() const
Number of grid points in this 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.
A kinetics manager for heterogeneous reaction mechanisms.
size_t reactionPhaseIndex() const
Phase where the reactions occur.
ThermoPhase & thermo(size_t n=0)
This method returns a reference to the nth ThermoPhase object defined in this kinetics mechanism.
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].
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 setKineticsMgr(InterfaceKinetics *kin)
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.
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.
A simple thermodynamic model for a surface phase, assuming an ideal solution model.
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
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.