17 setTolerances(
size_t nr,
const doublereal* rtol,
18 size_t na,
const doublereal* atol,
int ts)
21 "Use setTransientTolerances or setSteadyTolerances.");
22 if (nr < m_nv || na < m_nv)
24 "wrong array size for solution error tolerances. "
25 "Size should be at least "+
int2str(m_nv));
27 copy(rtol, rtol + m_nv, m_rtol_ss.begin());
28 copy(atol, atol + m_nv, m_atol_ss.begin());
31 copy(rtol, rtol + m_nv, m_rtol_ts.begin());
32 copy(atol, atol + m_nv, m_atol_ts.begin());
37 setTolerances(
size_t n, doublereal rtol, doublereal atol,
int ts)
40 "Use setTransientTolerances or setSteadyTolerances.");
52 setTolerances(doublereal rtol, doublereal atol,
int ts)
55 "Use setTransientTolerances or setSteadyTolerances.");
56 for (
size_t n = 0; n < m_nv; n++) {
68 void Domain1D::setTransientTolerances(doublereal rtol, doublereal atol,
size_t n)
71 for (n = 0; n < m_nv; n++) {
81 void Domain1D::setTolerancesTS(doublereal rtol, doublereal atol,
size_t n)
84 "Use setTransientTolerances");
85 setTransientTolerances(rtol, atol, n);
88 void Domain1D::setSteadyTolerances(doublereal rtol, doublereal atol,
size_t n)
91 for (n = 0; n < m_nv; n++) {
101 void Domain1D::setTolerancesSS(doublereal rtol, doublereal atol,
size_t n)
104 "Use setSteadyTolerances");
105 setSteadyTolerances(rtol, atol, n);
109 eval(
size_t jg, doublereal* xg, doublereal* rg,
110 integer* mask, doublereal rdt)
113 if (jg !=
npos && (jg + 1 < firstPoint() || jg > lastPoint() + 1)) {
123 doublereal* x = xg + loc();
124 doublereal* rsd = rg + loc();
125 integer* diag = mask + loc();
127 size_t jmin, jmax, jpt, j, i;
128 jpt = jg - firstPoint();
134 jmin = std::max<size_t>(jpt, 1) - 1;
135 jmax = std::min(jpt+1,m_points-1);
138 for (j = jmin; j <= jmax; j++) {
139 if (j == 0 || j == m_points - 1) {
140 for (i = 0; i < m_nv; i++) {
141 rsd[index(i,j)] = residual(x,i,j);
142 diag[index(i,j)] = 0;
145 for (i = 0; i < m_nv; i++) {
146 rsd[index(i,j)] = residual(x,i,j)
147 - timeDerivativeFlag(i)*rdt*(value(x,i,j) - prevSoln(i,j));
148 diag[index(i,j)] = timeDerivativeFlag(i);
160 addFloatArray(d,
"abstol_transient", nComponents(), &m_atol_ts[0]);
161 addFloatArray(d,
"reltol_transient", nComponents(), &m_rtol_ts[0]);
162 addFloatArray(d,
"abstol_steady", nComponents(), &m_atol_ss[0]);
163 addFloatArray(d,
"reltol_steady", nComponents(), &m_rtol_ss[0]);
167 void Domain1D::restore(
const XML_Node& dom, doublereal* soln,
int loglevel)
170 vector<XML_Node*> nodes;
172 for (
size_t i = 0; i < nodes.size(); i++) {
173 string title = nodes[i]->attrib(
"title");
175 if (values.size() != nComponents()) {
177 writelog(
"Warning: Domain1D::restore: Got an array of length " +
178 int2str(values.size()) +
" when one of length " +
179 int2str(nComponents()) +
" was expected. " +
180 "Tolerances for individual species may not be preserved.\n");
186 if (!values.empty()) {
187 values.resize(nComponents(), values[values.size()-1]);
194 if (title ==
"abstol_transient") {
196 }
else if (title ==
"reltol_transient") {
198 }
else if (title ==
"abstol_steady") {
200 }
else if (title ==
"reltol_steady") {
204 "Got an unexpected array, '" + title +
"'");
209 void Domain1D::setupGrid(
size_t n,
const doublereal* z)
213 for (
size_t j = 0; j < m_points; j++) {
221 writelog(
"\n-------------------------------------"
222 "------------------------------------------");
225 void Domain1D::showSolution(
const doublereal* x)
232 for (i = 0; i < nn; i++) {
234 sprintf(buf,
"\n z ");
236 for (n = 0; n < 5; n++) {
237 sprintf(buf,
" %10s ",componentName(i*5 + n).c_str());
241 for (j = 0; j < m_points; j++) {
242 sprintf(buf,
"\n %10.4g ",m_z[j]);
244 for (n = 0; n < 5; n++) {
245 v = value(x, i*5+n, j);
246 sprintf(buf,
" %10.4g ",v);
252 size_t nrem = m_nv - 5*nn;
254 sprintf(buf,
"\n z ");
256 for (n = 0; n < nrem; n++) {
257 sprintf(buf,
" %10s ", componentName(nn*5 + n).c_str());
261 for (j = 0; j < m_points; j++) {
262 sprintf(buf,
"\n %10.4g ",m_z[j]);
264 for (n = 0; n < nrem; n++) {
265 v = value(x, nn*5+n, j);
266 sprintf(buf,
" %10.4g ", v);
273 void Domain1D::_getInitialSoln(doublereal* x)
275 for (
size_t j = 0; j < m_points; j++) {
276 for (
size_t n = 0; n < m_nv; n++) {
277 x[index(n,j)] = initialValue(n,j);
282 doublereal Domain1D::initialValue(
size_t n,
size_t j)
285 "base class method called!");
std::string int2str(const int n, const std::string &fmt)
Convert an int to a string using a format converter.
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data...
const size_t npos
index returned by functions to indicate "no position"
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.
void addFloatArray(Cantera::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...
Base class for exceptions thrown by Cantera classes.
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
void writelog(const std::string &msg)
Write a message to the screen.
size_t getFloatArray(const Cantera::XML_Node &node, std::vector< doublereal > &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...
void getChildren(const std::string &name, std::vector< XML_Node * > &children) const
Get a vector of pointers to XML_Node containing all of the children of the current node which matches...