Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion include/cantera/base/SolutionArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ class SolutionArray
/**
* Check whether SolutionArray contains a component.
* A component is a property defining state or auxiliary variable.
* @param name name of component
* @param checkAlias if `true` (default), check alias mapping
*/
bool hasComponent(const string& name) const;
bool hasComponent(const string& name, bool checkAlias=true) const;

/**
* Retrieve a component of the SolutionArray by name.
Expand Down Expand Up @@ -404,6 +406,9 @@ class SolutionArray
vector<int> m_active; //!< Vector of locations referencing active entries
};

//! Return mapping of component alias names to standardized component names.
const map<string, string>& _componentAliasMap();

}

#endif
24 changes: 12 additions & 12 deletions include/cantera/oneD/Boundary1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class Boundary1D : public Domain1D

void setupGrid(size_t n, const double* z) override {}

void fromArray(SolutionArray& arr, double* soln) override;
void fromArray(const shared_ptr<SolutionArray>& arr) override;

protected:
//! Initialize member variables based on the adjacent domains.
Expand Down Expand Up @@ -173,8 +173,8 @@ class Inlet1D : public Boundary1D
}
void init() override;
void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
shared_ptr<SolutionArray> asArray(const double* soln) const override;
void fromArray(SolutionArray& arr, double* soln) override;
shared_ptr<SolutionArray> toArray(bool normalize=false) const override;
void fromArray(const shared_ptr<SolutionArray>& arr) override;

protected:
//! A marker that indicates whether this is a left inlet or a right inlet.
Expand Down Expand Up @@ -216,7 +216,7 @@ class Empty1D : public Boundary1D

void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;

shared_ptr<SolutionArray> asArray(const double* soln) const override;
shared_ptr<SolutionArray> toArray(bool normalize=false) const override;
};

/**
Expand Down Expand Up @@ -245,7 +245,7 @@ class Symm1D : public Boundary1D

void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;

shared_ptr<SolutionArray> asArray(const double* soln) const override;
shared_ptr<SolutionArray> toArray(bool normalize=false) const override;
};


Expand Down Expand Up @@ -275,7 +275,7 @@ class Outlet1D : public Boundary1D

void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;

shared_ptr<SolutionArray> asArray(const double* soln) const override;
shared_ptr<SolutionArray> toArray(bool normalize=false) const override;
};


Expand Down Expand Up @@ -312,8 +312,8 @@ class OutletRes1D : public Boundary1D

void init() override;
void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
shared_ptr<SolutionArray> asArray(const double* soln) const override;
void fromArray(SolutionArray& arr, double* soln) override;
shared_ptr<SolutionArray> toArray(bool normalize=false) const override;
void fromArray(const shared_ptr<SolutionArray>& arr) override;

protected:
size_t m_nsp = 0; //!< Number of species in the adjacent flow domain
Expand Down Expand Up @@ -347,8 +347,8 @@ class Surf1D : public Boundary1D

void init() override;
void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;
shared_ptr<SolutionArray> asArray(const double* soln) const override;
void fromArray(SolutionArray& arr, double* soln) override;
shared_ptr<SolutionArray> toArray(bool normalize=false) const override;
void fromArray(const shared_ptr<SolutionArray>& arr) override;
void show(const double* x) override;
};

Expand Down Expand Up @@ -390,8 +390,8 @@ class ReactingSurf1D : public Boundary1D

void eval(size_t jg, double* xg, double* rg, integer* diagg, double rdt) override;

shared_ptr<SolutionArray> asArray(const double* soln) const override;
void fromArray(SolutionArray& arr, double* soln) override;
shared_ptr<SolutionArray> toArray(bool normalize=false) const override;
void fromArray(const shared_ptr<SolutionArray>& arr) override;

void _getInitialSoln(double* x) override {
m_sphase->getCoverages(x);
Expand Down
101 changes: 93 additions & 8 deletions include/cantera/oneD/Domain1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,23 @@ class Domain1D
m_name[n] = name;
}

//! index of component with name `name`.
virtual size_t componentIndex(const string& name) const;
/**
* Index of component with name `name`.
* @param name name of component
* @param checkAlias if `true` (default), check alias mapping
*
* @since New in %Cantera 3.2.
*/
virtual size_t componentIndex(const string& name, bool checkAlias=true) const;

/**
* Check whether the Domain contains a component.
* @param name name of component
* @param checkAlias if `true` (default), check alias mapping
*
* @since New in %Cantera 3.2.
*/
virtual bool hasComponent(const string& name, bool checkAlias=true) const;

/**
* Set the upper and lower bounds for a solution component, n.
Expand Down Expand Up @@ -348,16 +363,73 @@ class Domain1D
return x[index(n,j)];
}

/**
* Retrieve component values.
* @param component Name of the component.
* @param[out] values Vector of length nPoints() containing values at grid points.
*
* @since New in %Cantera 3.2.
*/
virtual void getValues(const string& component, vector<double>& values) const {
throw NotImplementedError("Domain1D::getValues", "Needs to be overloaded.");
}

/**
* Specify component values.
* @param component Name of the component.
* @param[in] values Vector of length nPoints() containing values at grid points.
*
* @since New in %Cantera 3.2.
*/
virtual void setValues(const string& component, const vector<double>& values) {
throw NotImplementedError("Domain1D::setValues", "Needs to be overloaded.");
}

/**
* Specify a profile for a component.
* @param component Name of the component.
* @param[in] pos A vector of relative positions, beginning with 0.0 at the
* left of the domain, and ending with 1.0 at the right of the domain.
* @param[in] values A vector of values corresponding to the relative position
* locations.
*
* Note that the vector pos and values can have lengths different than the
* number of grid points, but their lengths must be equal. The values at
* the grid points will be linearly interpolated based on the (pos,
* values) specification.
*
* @since New in %Cantera 3.2.
*/
virtual void setProfile(const string& component,
const vector<double>& pos, const vector<double>& values) {
throw NotImplementedError("Domain1D::setProfile", "Needs to be overloaded.");
}

/**
* Specify a flat profile for a component.
* @param component Name of the component.
* @param value Constant value.
*
* @since New in %Cantera 3.2.
*/
virtual void setFlatProfile(const string& component, double v) {
throw NotImplementedError(
"Domain1D::setFlatProfile", "Needs to be overloaded.");
}

//! Save the state of this domain as a SolutionArray.
/*!
* @param soln local solution vector for this domain
* @todo Despite the method's name, data are copied; the intent is to access data
* directly in future revisions, where a non-const version will be implemented.
*
* @since New in %Cantera 3.0.
* @deprecated To be removed after %Cantera 3.2. Replaceable by toArray().
*/
virtual shared_ptr<SolutionArray> asArray(const double* soln) const {
throw NotImplementedError("Domain1D::asArray", "Needs to be overloaded.");
shared_ptr<SolutionArray> asArray(const double* soln) const {
warn_deprecated("Domain1D::asArray",
"To be removed after Cantera 3.2. Replaceable by 'toArray'.");
return toArray();
}

//! Save the state of this domain to a SolutionArray.
Expand All @@ -368,17 +440,26 @@ class Domain1D
*
* @since New in %Cantera 3.0.
*/
shared_ptr<SolutionArray> toArray(bool normalize=false) const;
virtual shared_ptr<SolutionArray> toArray(bool normalize=false) const {
throw NotImplementedError("Domain1D::toArray", "Needs to be overloaded.");
}

//! Restore the solution for this domain from a SolutionArray
/*!
* @param[in] arr SolutionArray defining the state of this domain
* @param[out] soln Value of the solution vector, local to this domain
*
* @since New in %Cantera 3.0.
* @deprecated To be removed after %Cantera 3.2.
* Replaceable by version that does not require solution vector.
*/
virtual void fromArray(SolutionArray& arr, double* soln) {
throw NotImplementedError("Domain1D::fromArray", "Needs to be overloaded.");
void fromArray(SolutionArray& arr, double* soln) {
warn_deprecated("Domain1D::fromArray",
"To be removed after Cantera 3.2. Replaceable by version that does not "
"require solution vector.");
// create a shared_ptr that skips deletion of the held pointer
shared_ptr<SolutionArray> arr_ptr(&arr, [](SolutionArray*){});
fromArray(arr_ptr);
}

//! Restore the solution for this domain from a SolutionArray.
Expand All @@ -387,7 +468,9 @@ class Domain1D
* @param arr SolutionArray defining the state of this domain
* @since New in %Cantera 3.0.
*/
void fromArray(const shared_ptr<SolutionArray>& arr);
virtual void fromArray(const shared_ptr<SolutionArray>& arr) {
throw NotImplementedError("Domain1D::fromArray", "Needs to be overloaded.");
}

//! Return thermo/kinetics/transport manager used in the domain
//! @since New in %Cantera 3.0.
Expand Down Expand Up @@ -499,6 +582,8 @@ class Domain1D
//! @param name Name of the component
//! @param values Array of length nPoints() containing the initial values
//! @param soln Pointer to the local portion of the system state vector
//! @deprecated To be removed after %Cantera 3.2.
//! Replaceable by version using vectors arguments.
void setProfile(const string& name, double* values, double* soln);

//! Access the array of grid coordinates [m]
Expand Down
32 changes: 23 additions & 9 deletions include/cantera/oneD/Flow1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define CT_FLOW1D_H

#include "Domain1D.h"
#include "OneDim.h"
#include "cantera/base/Array.h"
#include "cantera/base/Solution.h"
#include "cantera/thermo/ThermoPhase.h"
Expand Down Expand Up @@ -175,15 +176,23 @@ class Flow1D : public Domain1D

string componentName(size_t n) const override;

size_t componentIndex(const string& name) const override;
size_t componentIndex(const string& name, bool checkAlias=true) const override;

bool hasComponent(const string& name, bool checkAlias=true) const override;

//! Returns true if the specified component is an active part of the solver state
virtual bool componentActive(size_t n) const;

void show(const double* x) override;

shared_ptr<SolutionArray> asArray(const double* soln) const override;
void fromArray(SolutionArray& arr, double* soln) override;
void getValues(const string& component, vector<double>& values) const override;
void setValues(const string& component, const vector<double>& values) override;
void setProfile(const string& component,
const vector<double>& pos, const vector<double>& values) override;
void setFlatProfile(const string& component, double v) override;

shared_ptr<SolutionArray> toArray(bool normalize=false) const override;
void fromArray(const shared_ptr<SolutionArray>& arr) override;

//! Set flow configuration for freely-propagating flames, using an internal point
//! with a fixed temperature as the condition to determine the inlet mass flux.
Expand Down Expand Up @@ -548,15 +557,15 @@ class Flow1D : public Domain1D
double rdt, size_t jmin, size_t jmax);

/**
* Evaluate the lambda equation residual.
* Evaluate the radial pressure gradient equation residual.
*
* @f[
* \frac{d\Lambda}{dz} = 0
* @f]
*
* The lambda equation serves as an eigenvalue that allows the momentum
* equation and continuity equations to be simultaneously satisfied in
* axisymmetric flows. The lambda equation propagates information from
* The radial pressure gradient @f$ \Lambda @f$ serves as an eigenvalue that allows
* the momentum and continuity equations to be simultaneously satisfied in
* axisymmetric flows. This equation propagates information from
* left-to-right. The default boundary condition is @f$ \Lambda = 0 @f$
* at the left boundary. The equation is first order and so only one
* boundary condition is needed.
Expand All @@ -571,7 +580,7 @@ class Flow1D : public Domain1D
*
* @f[
* \rho c_p u \frac{dT}{dz} =
* \frac{d}{dz}\left( \lambda \frac{dT}{dz} \right)
* \frac{d}{dz}\left( \Lambda \frac{dT}{dz} \right)
* - \sum_k h_kW_k\dot{\omega}_k
* - \sum_k j_k \frac{dh_k}{dz}
* @f]
Expand Down Expand Up @@ -674,7 +683,12 @@ class Flow1D : public Domain1D

//! Get the radial pressure gradient [N/m⁴] at point `j` from the local state vector
//! `x`
double lambda(const double* x, size_t j) const {
//! @deprecated To be removed after %Cantera 3.2. Renamed to Lambda().
double lambda(const double* x, size_t j) const;

//! Get the radial pressure gradient [N/m⁴] at point `j` from the local state vector
//! `x`
double Lambda(const double* x, size_t j) const {
return x[index(c_offset_L, j)];
}

Expand Down
2 changes: 1 addition & 1 deletion include/cantera/oneD/OneDim.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class OneDim : public SteadyStateSystem
}

//! Get the index of the domain named `name`.
size_t domainIndex(const string& name);
size_t domainIndex(const string& name) const;

//! Check that the specified domain index is in range.
//! Throws an exception if n is greater than nDomains()-1
Expand Down
8 changes: 8 additions & 0 deletions include/cantera/oneD/Sim1D.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class Sim1D : public OneDim
* left of the domain, and ending with 1.0 at the right of the domain.
* @param vals A vector of values corresponding to the relative position
* locations.
*
* @deprecated To be removed after %Cantera 3.2.
* Replaceable by Domain1D::setProfile.
*/
void setInitialGuess(const string& component, vector<double>& locs,
vector<double>& vals);
Expand Down Expand Up @@ -92,11 +95,16 @@ class Sim1D : public OneDim
* number of grid points, but their lengths must be equal. The values at
* the grid points will be linearly interpolated based on the (pos,
* values) specification.
*
* @deprecated To be removed after %Cantera 3.2.
* Replaceable by Domain1D::setProfile.
*/
void setProfile(size_t dom, size_t comp, const vector<double>& pos,
const vector<double>& values);

//! Set component 'comp' of domain 'dom' to value 'v' at all points.
//! @deprecated To be removed after %Cantera 3.2.
//! Replaceable by Domain1D::setProfile.
void setFlatProfile(size_t dom, size_t comp, double v);

//! @}
Expand Down
11 changes: 8 additions & 3 deletions interfaces/cython/cantera/_onedim.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ cdef extern from "cantera/oneD/Domain1D.h":
size_t nComponents()
size_t nPoints()
string componentName(size_t) except +translate_exception
size_t componentIndex(string) except +translate_exception
size_t componentIndex(string&) except +translate_exception
cbool hasComponent(string&) except +translate_exception
vector[double] grid() except +translate_exception
void setupGrid(vector[double]&) except +translate_exception
void getValues(string&, vector[double]&) except +translate_exception
void setValues(string&, vector[double]&) except +translate_exception
void setProfile(string&, vector[double]&, vector[double]&) except +translate_exception
void setFlatProfile(string&, double) except +translate_exception
void setBounds(size_t, double, double)
double upperBound(size_t)
double lowerBound(size_t)
Expand All @@ -37,8 +44,6 @@ cdef extern from "cantera/oneD/Domain1D.h":
double steady_atol(size_t)
double transient_rtol(size_t)
double transient_atol(size_t)
double z(size_t)
void setupGrid(size_t, double*) except +translate_exception
void setID(string)
string& id()
string domainType "type"()
Expand Down
Loading
Loading