17 Domain1D::Domain1D(
size_t nv,
size_t points,
double time) :
29 m_force_full_update(false)
38 if (nv != m_nv || !m_refiner) {
40 m_refiner.reset(
new Refiner(*
this));
44 m_name.resize(m_nv,
"");
45 m_max.resize(m_nv, 0.0);
46 m_min.resize(m_nv, 0.0);
48 m_rtol_ss.resize(m_nv, 1.0e-4);
49 m_atol_ss.resize(m_nv, 1.0e-9);
50 m_rtol_ts.resize(m_nv, 1.0e-4);
51 m_atol_ts.resize(m_nv, 1.0e-11);
54 m_slast.resize(m_nv * m_points, 0.0);
60 if (m_name[n] !=
"") {
63 return fmt::format(
"component {}", n);
75 "no component named "+name);
81 for (n = 0; n < m_nv; n++) {
94 for (n = 0; n < m_nv; n++) {
113 integer* mask, doublereal rdt)
116 "Derived classes should implement eval directly. The 'residual' method" 117 " will be removed after Cantera 2.3.");
129 doublereal* x = xg +
loc();
130 doublereal* rsd = rg +
loc();
131 integer* diag = mask +
loc();
140 jmin = std::max<size_t>(jpt, 1) - 1;
141 jmax = std::min(jpt+1,m_points-1);
144 for (
size_t j = jmin; j <= jmax; j++) {
145 if (j == 0 || j == m_points - 1) {
146 for (
size_t i = 0; i < m_nv; i++) {
148 diag[index(i,j)] = 0;
151 for (
size_t i = 0; i < m_nv; i++) {
176 vector<XML_Node*> nodes = dom.
getChildren(
"floatArray");
177 for (
size_t i = 0; i < nodes.size(); i++) {
178 string title = nodes[i]->attrib(
"title");
182 writelog(
"Warning: Domain1D::restore: Got an array of length {}" 183 " when one of length {} was expected. " 184 "Tolerances for individual species may not be preserved.\n",
191 if (!values.empty()) {
192 values.resize(
nComponents(), values[values.size()-1]);
199 if (title ==
"abstol_transient") {
201 }
else if (title ==
"reltol_transient") {
203 }
else if (title ==
"abstol_steady") {
205 }
else if (title ==
"reltol_steady") {
209 "Got an unexpected array, '" + title +
"'");
238 for (
size_t j = 0; j < m_points; j++) {
247 for (
size_t i = 0; i < nn; i++) {
248 writeline(
'-', 79,
false,
true);
250 for (
size_t n = 0; n < 5; n++) {
253 writeline(
'-', 79,
false,
true);
254 for (
size_t j = 0; j < m_points; j++) {
256 for (
size_t n = 0; n < 5; n++) {
257 double v = value(x, i*5+n, j);
263 size_t nrem = m_nv - 5*nn;
264 writeline(
'-', 79,
false,
true);
266 for (
size_t n = 0; n < nrem; n++) {
269 writeline(
'-', 79,
false,
true);
270 for (
size_t j = 0; j < m_points; j++) {
272 for (
size_t n = 0; n < nrem; n++) {
273 double v = value(x, nn*5+n, j);
280 void Domain1D::setProfile(
const std::string& name,
double* values,
double* soln)
282 for (
size_t n = 0; n < m_nv; n++) {
284 for (
size_t j = 0; j < m_points; j++) {
285 soln[index(n, j) +
m_iloc] = values[j];
290 throw CanteraError(
"Domain1D::setProfile",
"unknown component: "+name);
295 for (
size_t j = 0; j < m_points; j++) {
296 for (
size_t n = 0; n < m_nv; n++) {
305 "base class method called!");
void addFloatArray(XML_Node &node, const std::string &title, const size_t n, const doublereal *const vals, const std::string &units, const std::string &type, const doublereal minval, const doublereal maxval)
This function adds a child node with the name, "floatArray", with a value consisting of a comma separ...
std::vector< XML_Node * > getChildren(const std::string &name) const
Get a vector of pointers to XML_Node containing all of the children of the current node which match t...
size_t getFloatArray(const XML_Node &node, vector_fp &v, const bool convert, const std::string &unitsString, const std::string &nodeName)
This function reads the current node or a child node of the current node with the default name...
virtual void _getInitialSoln(doublereal *x)
Writes some or all initial solution values into the global solution array, beginning at the location ...
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
void locate()
Find the index of the first grid point in this domain, and the start of its variables in the global s...
MultiJac & jacobian()
Return a reference to the Jacobian evaluator.
size_t m_iloc
Starting location within the solution vector for unknowns that correspond to this domain...
const size_t npos
index returned by functions to indicate "no position"
size_t firstPoint() const
The index of the first (i.e., left-most) grid point belonging to this domain.
void writelog(const std::string &fmt, const Args &... args)
Write a formatted message to the screen.
virtual doublereal residual(doublereal *x, size_t n, size_t j)
Class XML_Node is a tree-based representation of the contents of an XML file.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
virtual XML_Node & save(XML_Node &o, const doublereal *const sol)
Save the current solution for this domain into an XML_Node.
void setAge(int age)
Set the Jacobian age.
size_t lastPoint() const
The index of the last (i.e., right-most) grid point belonging to this domain.
virtual void resize(size_t nv, size_t np)
virtual void showSolution(const doublereal *x)
Print the solution.
Base class for exceptions thrown by Cantera classes.
void saveStats()
Save statistics on function and Jacobian evaluation, and reset the counters.
virtual std::string componentName(size_t n) const
Name of the nth component. May be overloaded.
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
size_t componentIndex(const std::string &name) const
index of component with name name.
double prevSoln(size_t n, size_t j) const
Value of component n at point j in the previous solution.
size_t nComponents() const
Number of components at each grid point.
void setSteadyTolerances(doublereal rtol, doublereal atol, size_t n=npos)
Set tolerances for steady-state mode.
virtual void eval(size_t j, doublereal *x, doublereal *r, integer *mask, doublereal rdt=0.0)
Evaluate the residual function at point j.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
int timeDerivativeFlag(size_t n)
doublereal atol(size_t n)
Absolute tolerance of the nth component.
Refine Domain1D grids so that profiles satisfy adaptation tolerances.
doublereal rtol(size_t n)
Relative tolerance of the nth component.
size_t nPoints() const
Number of grid points in this domain.
Namespace for the Cantera kernel.
void setTransientTolerances(doublereal rtol, doublereal atol, size_t n=npos)
Set tolerances for time-stepping mode.
virtual void setupGrid(size_t n, const doublereal *z)
called to set up initial grid, and after grid refinement
virtual size_t loc(size_t j=0) const
Location of the start of the local solution vector in the global solution vector,.
virtual doublereal initialValue(size_t n, size_t j)
Initial value of solution component n at grid point j.