24 "install in container before calling init.");
49 "Boundary domains can only be connected on the left to flow "
64 m_flow_right =
dynamic_cast<Flow1D*
>(&r);
65 if (m_flow_right !=
nullptr) {
70 "Boundary domains can only be connected on the right to flow "
93 auto thermo =
phase->thermo();
94 m_temp = thermo->temperature();
96 m_nsp = thermo->nSpecies();
98 thermo->getMassFractions(
m_yin);
124 if (
m_yin[k] != 0.0) {
137 thermo->setMoleFractionsByName(xin);
138 thermo->getMassFractions(
m_yin);
149 thermo->setMoleFractions(xin);
150 thermo->getMassFractions(
m_yin);
173 "Right inlets with right-to-left flow are only supported for "
174 "strained flow configurations.");
178 }
else if (m_flow_right) {
182 throw CanteraError(
"Inlet1D::init",
"Inlet1D is not properly connected.");
201 span<int> diagg,
double rdt)
209 span<const double> xb = xg.subspan(
m_flow->loc());
210 span<double> rb = rg.subspan(
m_flow->loc());
216 if (
m_flow->doEnergy(0)) {
228 }
else if (
m_flow->isStrained()) {
229 if (
m_flow->twoPointControlEnabled()) {
251 for (
size_t k = 0; k <
m_nsp; k++) {
252 if (k != m_flow_right->leftExcessSpecies()) {
260 span<double> rb = rg.subspan(
loc() -
m_flow->nComponents());
261 span<const double> xb = xg.subspan(
loc() -
m_flow->nComponents());
262 size_t last_index =
m_flow->nPoints() - 1;
271 if (
m_flow->twoPointControlEnabled()) {
280 for (
size_t k = 0; k <
m_nsp; k++) {
291 meta[
"mass-flux"] =
m_mdot;
295 double pressure =
m_flow->phase().pressure();
298 vector<double> data(thermo->stateSize());
299 thermo->saveState(data);
301 arr->setState(0, data);
312 auto thermo = arr->thermo();
313 auto meta = arr->meta();
314 m_temp = thermo->temperature();
315 if (meta.hasKey(
"mass-flux")) {
316 m_mdot = meta.at(
"mass-flux").asDouble();
319 auto aux = arr->getAuxiliary(0);
320 m_mdot = thermo->density() * aux.at(
"velocity").as<
double>();
322 thermo->getMassFractions(
m_yin);
333 span<int> diagg,
double rdt)
351 span<int> diagg,
double rdt)
358 size_t nc = m_flow_right->nComponents();
359 span<const double> xb = xg.subspan(
loc(), nc);
360 span<double> rb = rg.subspan(
loc(), nc);
361 span<int> db = diagg.subspan(
loc(), nc);
365 if (m_flow_right->doEnergy(0)) {
372 span<const double> xb = xg.subspan(
loc() - nc, nc);
373 span<const double> xb2 = xg.subspan(
loc() - 2*nc, nc);
374 span<double> rb = rg.subspan(
loc() - nc, nc);
375 span<int> db = diagg.subspan(
loc() - nc, nc);
411 "Left outlets with right-to-left flow are not supported.");
416 throw CanteraError(
"Outlet1D::init",
"Outlet1D is not connected.");
421 span<int> diagg,
double rdt)
429 span<const double> xb = xg.subspan(
loc() - nc, nc);
430 span<const double> xb2 = xg.subspan(
loc() - 2*nc, nc);
431 span<double> rb = rg.subspan(
loc() - nc, nc);
432 span<int> db = diagg.subspan(
loc() - nc, nc);
443 rb[k] = xb[k] - xb2[k];
461 m_flow->phase().setMoleFractionsByName(xres);
470 m_flow->phase().setMoleFractions(xres);
482 "Left outlets with right-to-left flow are not supported.");
500 span<int> diagg,
double rdt)
508 span<const double> xb = xg.subspan(
loc() - nc, nc);
509 span<const double> xb2 = xg.subspan(
loc() - 2*nc, nc);
510 span<double> rb = rg.subspan(
loc() - nc, nc);
511 span<int> db = diagg.subspan(
loc() - nc, nc);
531 meta[
"temperature"] =
m_temp;
535 double pressure =
m_flow->phase().pressure();
538 vector<double> data(thermo->stateSize());
539 thermo->saveState(data);
541 arr->setState(0, data);
552 auto thermo = arr->thermo();
553 m_temp = thermo->temperature();
554 auto Y = thermo->massFractions();
555 m_yres.assign(Y.begin(), Y.end());
566 span<int> diagg,
double rdt)
573 span<double> rb = rg.subspan(
loc(), m_flow_right->nComponents());
574 span<const double> xb = xg.subspan(
loc(), m_flow_right->nComponents());
580 span<double> rb = rg.subspan(
loc() - nc, nc);
581 span<const double> xb = xg.subspan(
loc() - nc, nc);
589 meta[
"temperature"] =
m_temp;
595 auto meta = arr->meta();
596 m_temp = meta[
"temperature"].asDouble();
597 meta.erase(
"temperature");
616 auto thermo = std::dynamic_pointer_cast<SurfPhase>(
phase->thermo());
619 "Detected incompatible ThermoPhase type '{}'",
phase->thermo()->type());
621 auto kin = std::dynamic_pointer_cast<InterfaceKinetics>(
phase->kinetics());
624 "Detected incompatible kinetics type '{}'",
625 phase->kinetics()->kineticsType());
641 throw IndexError(
"ReactingSurf1D::componentName",
"component", n,
m_nsp);
646 return m_sphase->speciesIndex(name,
true);
658 for (
size_t n = 0; n <
m_nsp; n++) {
664 span<double> x = xg.subspan(
loc(),
m_nsp);
670 span<int> diagg,
double rdt)
677 span<const double> x = xg.subspan(
loc(),
m_nsp);
678 span<double> r = rg.subspan(
loc(),
m_nsp);
679 span<int> diag = diagg.subspan(
loc(),
m_nsp);
683 for (
size_t k = 0; k <
m_nsp; k++) {
692 size_t leftloc = 0, rightloc = 0;
702 rightloc = m_flow_right->loc();
703 m_flow_right->setGas(xg.subspan(rightloc, m_flow_right->size()), 0);
707 double rs0 = 1.0/
m_sphase->siteDensity();
710 for (
size_t k = 0; k <
m_nsp; k++) {
718 for (
size_t k = 0; k <
m_nsp; k++) {
725 span<double> rb = r.subspan(
m_nsp, m_flow_right->nComponents());
726 span<const double> xb = x.subspan(
m_nsp, m_flow_right->nComponents());
732 span<double> rb = rg.subspan(
loc() - nc, nc);
733 span<const double> xb = xg.subspan(
loc() - nc, nc);
738 for (
size_t nth = 0; nth <
m_kin->nPhases(); nth++) {
739 if (&
m_kin->thermo(nth) == left_thermo) {
740 l_offset =
m_kin->kineticsSpeciesIndex(0, nth);
756 "Domain needs to be installed in a container.");
760 return soln[
index(i, 0)];
767 "Domain needs to be installed in a container before calling toArray.");
771 meta[
"temperature"] =
m_temp;
772 meta[
"phase"][
"name"] =
m_sphase->name();
774 meta[
"phase"][
"source"] = source.
empty() ?
"<unknown>" : source.
asString();
779 vector<double> data(
m_sphase->stateSize());
783 arr->setState(0, data);
794 "Domain needs to be installed in a container before calling fromArray.");
802 auto surf = std::dynamic_pointer_cast<SurfPhase>(arr->thermo());
805 "Restoring of coverages requires surface phase");
807 m_temp = surf->temperature();
808 surf->getCoverages(soln);
816 for (
size_t k = 0; k <
m_nsp; k++) {
Boundary objects for one-dimensional simulations.
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.
ThermoPhase * m_phase_left
Thermo object used by left flow domain.
double m_mdot
Mass flow rate at the boundary.
double m_temp
Temperature of the boundary.
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.
ThermoPhase * m_phase_right
Thermo object used by right flow domain.
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.
virtual void setTemperature(double t)
Set the temperature.
size_t m_left_nsp
Number of species in left flow domain.
Boundary1D()
Default constructor.
size_t m_right_nv
Number of state vector components in right flow domain.
size_t m_left_nv
Flow domain to the right of this boundary.
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 m_iloc
Starting location within the solution vector for unknowns that correspond to this domain.
shared_ptr< Solution > m_solution
Composite thermo/kinetics/transport handler.
OneDim * m_container
Parent OneDim simulation containing this and adjacent domains.
size_t nComponents() const
Number of components at each grid point.
virtual bool isConnector()
True if the domain is a connector domain.
virtual void setMeta(const AnyMap &meta)
Retrieve meta data.
size_t m_index
Left-to-right location of this domain.
string id() const
Returns the identifying tag for this domain.
shared_ptr< Solution > phase() const
Return thermo/kinetics/transport manager used in the domain.
size_t m_nv
Number of solution components.
virtual string domainType() const
Domain type flag.
shared_ptr< vector< double > > m_state
data pointer shared from OneDim
virtual void resize(size_t nv, size_t np)
Resize the domain to have nv components and np grid points.
double m_press
pressure [Pa]
const OneDim & container() const
The container holding this domain.
string m_id
Identity tag for the domain.
void setBounds(size_t n, double lower, double upper)
Set the upper and lower bounds for a solution component, n.
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...
Domain1D(size_t nv=1, size_t points=1, double time=0.0)
Constructor.
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.
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 > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
void eval(size_t jg, span< const double > xg, span< double > rg, span< int > 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...
An array index is out of range.
void setMoleFractions(const string &xin) override
Set the mole fractions by specifying a string.
vector< double > m_yin
inlet mass fractions
int m_ilr
A marker that indicates whether this is a left inlet or a right inlet.
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
string m_xstr
inlet mass fractions.
size_t nSpecies() override
Get the number of species.
void fromArray(const shared_ptr< SolutionArray > &arr) override
Restore the solution for this domain from a SolutionArray.
void updateState(size_t loc) override
Update state at given location to state of associated Solution object.
void setTemperature(double T) override
Set the temperature.
void eval(size_t jg, span< const double > xg, span< double > rg, span< int > diagg, double rdt) override
Evaluate the residual function at point j.
void show(span< const double > x) override
Print the solution.
size_t m_nsp
Number of species in the adjacent flow domain.
void init() override
Initialize.
Flow1D * m_flow
the adjacent flow domain
void setSpreadRate(double V0) override
set spreading rate
double m_V0
The spread rate of the inlet [1/s].
Inlet1D()
Default constructor.
Domain1D & domain(size_t i) const
Return a reference to domain i.
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
void eval(size_t jg, span< const double > xg, span< double > rg, span< int > 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 > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
OutletRes1D()
Default constructor.
string m_xstr
Mole fractions in the reservoir.
vector< double > m_yres
Mass fractions in the reservoir.
void fromArray(const shared_ptr< SolutionArray > &arr) override
Restore the solution for this domain from a SolutionArray.
void eval(size_t jg, span< const double > xg, span< double > rg, span< int > diagg, double rdt) override
Evaluate the residual function at point j.
size_t m_nsp
Number of species in the adjacent flow domain.
void init() override
Initialize.
Flow1D * m_flow
The adjacent flow domain.
SurfPhase * m_sphase
phase representing the surface species
size_t componentIndex(const string &name, bool checkAlias=true) const override
Index of component with name name.
InterfaceKinetics * m_kin
surface kinetics mechanism
bool m_enabled
True if coverage equations are being solved.
vector< double > m_fixed_cov
Fixed values of the coverages used when coverage equations are not being solved.
ReactingSurf1D()
Default constructor.
vector< double > m_work
temporary vector used to store coverages and production rates.
shared_ptr< SolutionArray > toArray(bool normalize=false) 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, span< const double > xg, span< double > rg, span< int > diagg, double rdt) override
Evaluate the residual function at point j.
void show(span< const double > x) override
Print the solution.
size_t m_nsp
the number of surface phase species
void _finalize(span< const double > x) override
In some cases, a domain may need to set parameters that depend on the initial solution estimate.
void resetBadValues(span< double > xg) override
When called, this function should reset "bad" values in the state vector such as negative species con...
string componentName(size_t n) const override
Name of component n. May be overloaded.
void init() override
Initialize.
static shared_ptr< SolutionArray > create(const shared_ptr< Solution > &sol, int size=0, const AnyMap &meta={})
Instantiate a new SolutionArray reference.
shared_ptr< SolutionArray > toArray(bool normalize=false) 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, span< const double > xg, span< double > rg, span< int > diagg, double rdt) override
Evaluate the residual function at point j.
void show(span< const double > x) override
Print the solution.
void init() override
Initialize.
shared_ptr< SolutionArray > toArray(bool normalize=false) override
Save the state of this domain to a SolutionArray.
void eval(size_t jg, span< const double > xg, span< double > rg, span< int > diagg, double rdt) override
Evaluate the residual function at point j.
void init() override
Initialize.
Base class for a phase with thermodynamic properties.
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"
const int LeftInlet
Unique identifier for the left inlet.
const int RightInlet
Unique identifier for the right inlet.
@ 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]