16Boundary1D::Boundary1D() : Domain1D(1, 1, 0.0)
20void 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();
38 if (m_left_nv > c_offset_Y) {
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();
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();
61 if (m_right_nv > c_offset_Y) {
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();
72 throw CanteraError(
"Boundary1D::_init",
73 "Boundary domains can only be connected on the right to flow "
74 "domains, not '{}' domains.", r.type());
90Inlet1D::Inlet1D(shared_ptr<Solution> solution,
const string&
id)
116 writelog(
" Mass Flux: {:10.4g} kg/m^2/s \n", m_mdot);
117 writelog(
" Temperature: {:10.4g} K \n", m_temp);
120 for (
size_t k = 0; k < m_flow->phase().nSpecies(); k++) {
121 if (m_yin[k] != 0.0) {
156 if (m_flow_left && !m_flow_right) {
159 "Right inlets with right-to-left flow are only supported for "
160 "strained flow configurations.");
163 m_flow = m_flow_left;
164 }
else if (m_flow_right) {
166 m_flow = m_flow_right;
168 throw CanteraError(
"Inlet1D::init",
"Inlet1D is not properly connected.");
173 m_yin.resize(m_nsp, 0.0);
183 integer* diagg,
double rdt)
189 if (m_ilr == LeftInlet) {
191 double* xb = xg + m_flow->
loc();
192 double* rb = rg + m_flow->
loc();
198 if (m_flow->doEnergy(0)) {
233 for (
size_t k = 0; k < m_nsp; k++) {
244 size_t last_index = m_flow->
nPoints() - 1;
247 if (m_flow->doEnergy(m_flow->
nPoints() - 1)) {
258 m_mdot = -m_flow->density(last_index) * xb[
c_offset_Uo];
262 for (
size_t k = 0; k < m_nsp; k++) {
273 meta[
"mass-flux"] = m_mdot;
277 double pressure = m_flow->phase().
pressure();
279 phase->setState_TPY(m_temp, pressure, m_yin.data());
280 vector<double> data(phase->stateSize());
281 phase->saveState(data);
283 arr->setState(0, data);
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();
299 m_mdot = phase->density() * aux.at(
"velocity").as<
double>();
301 phase->getMassFractions(m_yin.data());
312 integer* diagg,
double rdt)
337 double* x = xg +
loc();
338 double* r = rg +
loc();
339 integer* diag = diagg +
loc();
349 if (m_flow_right->doEnergy(0)) {
362 if (m_flow_left->doEnergy(m_flow_left->
nPoints() - 1)) {
376OutletRes1D::OutletRes1D()
380OutletRes1D::OutletRes1D(shared_ptr<Solution> solution,
const string&
id)
393 "Left outlets with right-to-left flow are not supported.");
396 m_flow_left->setViscosityFlag(
false);
398 throw CanteraError(
"Outlet1D::init",
"Outlet1D is not connected.");
410 double* x = xg +
loc();
411 double* r = rg +
loc();
412 integer* diag = diagg +
loc();
420 size_t last = m_flow_left->
nPoints() - 1;
421 if (m_flow_left->doEnergy(last)) {
429 rb[k] = xb[k] - xb[k - nc];
468 "Left outlets with right-to-left flow are not supported.");
471 m_flow = m_flow_left;
477 m_yres.resize(m_nsp, 0.0);
486 integer* diagg,
double rdt)
493 double* x = xg +
loc();
494 double* r = rg +
loc();
495 integer* diag = diagg +
loc();
502 size_t last = m_flow_left->
nPoints() - 1;
503 if (m_flow_left->doEnergy(last)) {
520 meta[
"temperature"] = m_temp;
524 double pressure = m_flow->phase().
pressure();
526 phase->setState_TPY(m_temp, pressure, &m_yres[0]);
527 vector<double> data(phase->stateSize());
528 phase->saveState(data);
530 arr->setState(0, data);
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]);
552 integer* diagg,
double rdt)
559 double* x = xg +
loc();
560 double* r = rg +
loc();
579 meta[
"temperature"] = m_temp;
585 auto meta = arr.
meta();
586 m_temp = meta[
"temperature"].asDouble();
587 meta.erase(
"temperature");
593 s <<
"------------------- Surface " <<
domainIndex() <<
" ------------------- " << std::endl;
594 s <<
" temperature: " << m_temp <<
" K" << std::endl;
599 writelog(
" Temperature: {:10.4g} K \n\n", m_temp);
604ReactingSurf1D::ReactingSurf1D()
610ReactingSurf1D::ReactingSurf1D(shared_ptr<Solution> solution,
const string&
id)
612 auto phase = std::dynamic_pointer_cast<SurfPhase>(
solution->thermo());
614 throw CanteraError(
"ReactingSurf1D::ReactingSurf1D",
615 "Detected incompatible ThermoPhase type '{}'",
solution->thermo()->type());
617 auto kin = std::dynamic_pointer_cast<InterfaceKinetics>(
solution->kinetics());
619 throw CanteraError(
"ReactingSurf1D::ReactingSurf1D",
620 "Detected incompatible kinetics type '{}'",
621 solution->kinetics()->kineticsType());
626 m_sphase = phase.get();
634 sol->setThermo(kin->reactionPhase());
635 sol->setKinetics(kin);
636 sol->setTransportModel(
"none");
638 m_kin = dynamic_pointer_cast<InterfaceKinetics>(kin).get();
639 m_sphase = dynamic_pointer_cast<SurfPhase>(kin->reactionPhase()).get();
658 m_fixed_cov.resize(m_nsp, 0.0);
659 m_fixed_cov[0] = 1.0;
662 for (
size_t n = 0; n < m_nsp; n++) {
663 setBounds(n, -1.0e-5, 2.0);
668 double* x = xg +
loc();
674 integer* diagg,
double rdt)
681 double* x = xg +
loc();
682 double* r = rg +
loc();
683 integer* diag = diagg +
loc();
687 for (
size_t k = 0; k < m_nsp; k++) {
696 size_t leftloc = 0, rightloc = 0;
700 leftloc = m_flow_left->
loc();
701 pnt = m_flow_left->
nPoints() - 1;
702 m_flow_left->
setGas(xg + leftloc, pnt);
706 rightloc = m_flow_right->
loc();
707 m_flow_right->
setGas(xg + rightloc, 0);
714 for (
size_t k = 0; k < m_nsp; k++) {
715 r[k] = m_work[k] * m_sphase->
size(k) * rs0;
722 for (
size_t k = 0; k < m_nsp; k++) {
723 r[k] = x[k] - m_fixed_cov[k];
729 double* rb = r + m_nsp;
730 double* xb = x + m_nsp;
742 for (
size_t nth = 0; nth < m_kin->
nPhases(); nth++) {
743 if (&m_kin->
thermo(nth) == left_thermo) {
748 for (
size_t nl = 0; nl < m_left_nsp; nl++) {
750 rb[
c_offset_Y+nl] += m_work[nl + l_offset]*mwleft[nl];
759 meta[
"temperature"] = m_temp;
760 meta[
"phase"][
"name"] = m_sphase->
name();
762 meta[
"phase"][
"source"] = source.
empty() ?
"<unknown>" : source.
asString();
767 vector<double> data(m_sphase->
stateSize());
768 m_sphase->
saveState(data.size(), &data[0]);
771 arr->setState(0, data);
779 auto surf = std::dynamic_pointer_cast<SurfPhase>(arr.
thermo());
782 "Restoring of coverages requires surface phase");
784 m_temp = surf->temperature();
785 surf->getCoverages(soln);
790 writelog(
" Temperature: {:10.4g} K \n", m_temp);
792 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.
virtual void setTemperature(double t)
Set the temperature.
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.
double lowerBound(size_t n) const
Lower bound on the nth component.
double upperBound(size_t n) const
Upper bound on the nth component.
void setSolution(shared_ptr< Solution > sol)
Set the solution manager.
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.
bool twoPointControlEnabled() const
Returns the status of the two-point control.
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.
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.
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 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.
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 [m/s]
@ c_offset_Y
mass fractions
@ c_offset_Uo
oxidizer axial velocity [m/s]
@ c_offset_T
temperature [kelvin]