10#include "cantera/oneD/refine.h"
32 m_force_full_update(false)
45 if (nv != m_nv || !m_refiner) {
47 m_refiner.reset(
new Refiner(*
this));
50 m_name.resize(m_nv,
"");
51 m_max.resize(m_nv, 0.0);
52 m_min.resize(m_nv, 0.0);
54 m_rtol_ss.resize(m_nv, 1.0e-4);
55 m_atol_ss.resize(m_nv, 1.0e-9);
56 m_rtol_ts.resize(m_nv, 1.0e-4);
57 m_atol_ts.resize(m_nv, 1.0e-11);
60 m_slast.resize(m_nv * m_points, 0.0);
66 if (m_name[n] !=
"") {
69 return fmt::format(
"component {}", n);
81 "no component named "+name);
87 for (n = 0; n < m_nv; n++) {
100 for (n = 0; n < m_nv; n++) {
134 vector<XML_Node*> nodes = dom.
getChildren(
"floatArray");
135 for (
size_t i = 0; i < nodes.size(); i++) {
136 string title = nodes[i]->attrib(
"title");
140 warn_user(
"Domain1D::restore",
"Received an array of length "
141 "{} when one of length {} was expected. Tolerances for "
142 "individual species may not be preserved.",
149 if (!values.empty()) {
150 values.resize(
nComponents(), values[values.size()-1]);
157 if (title ==
"abstol_transient") {
159 }
else if (title ==
"reltol_transient") {
161 }
else if (title ==
"abstol_steady") {
163 }
else if (title ==
"reltol_steady") {
167 "Got an unexpected array, '" + title +
"'");
174 auto wrap_tols = [
this](
const vector_fp& tols) {
177 std::set<double> unique_tols(tols.begin(), tols.end());
178 if (unique_tols.size() == 1) {
182 for (
size_t i = 0; i < tols.size(); i++) {
189 state[
"points"] =
static_cast<long int>(
nPoints());
191 state[
"tolerances"][
"transient-abstol"] = wrap_tols(m_atol_ts);
192 state[
"tolerances"][
"steady-abstol"] = wrap_tols(m_atol_ss);
193 state[
"tolerances"][
"transient-reltol"] = wrap_tols(m_rtol_ts);
194 state[
"tolerances"][
"steady-reltol"] = wrap_tols(m_rtol_ss);
203 if (!tols.
hasKey(which)) {
206 const auto& tol = tols[which];
207 if (tol.isScalar()) {
212 if (tol.hasKey(name)) {
213 out[i] = tol[name].asDouble();
214 }
else if (loglevel) {
215 warn_user(
"Domain1D::restore",
"No {} found for component '{}'",
222 if (state.
hasKey(
"tolerances")) {
223 const auto& tols = state[
"tolerances"];
224 set_tols(tols,
"transient-abstol", m_atol_ts);
225 set_tols(tols,
"transient-reltol", m_rtol_ts);
226 set_tols(tols,
"steady-abstol", m_atol_ss);
227 set_tols(tols,
"steady-reltol", m_rtol_ss);
255 for (
size_t j = 0; j < m_points; j++) {
264 for (
size_t i = 0; i < nn; i++) {
265 writeline(
'-', 79,
false,
true);
267 for (
size_t n = 0; n < 5; n++) {
270 writeline(
'-', 79,
false,
true);
271 for (
size_t j = 0; j < m_points; j++) {
273 for (
size_t n = 0; n < 5; n++) {
274 double v = value(x, i*5+n, j);
280 size_t nrem = m_nv - 5*nn;
281 writeline(
'-', 79,
false,
true);
283 for (
size_t n = 0; n < nrem; n++) {
286 writeline(
'-', 79,
false,
true);
287 for (
size_t j = 0; j < m_points; j++) {
289 for (
size_t n = 0; n < nrem; n++) {
290 double v = value(x, nn*5+n, j);
297void Domain1D::setProfile(
const std::string& name,
double* values,
double* soln)
299 for (
size_t n = 0; n < m_nv; n++) {
301 for (
size_t j = 0; j < m_points; j++) {
302 soln[index(n, j) +
m_iloc] = values[j];
307 throw CanteraError(
"Domain1D::setProfile",
"unknown component: "+name);
312 for (
size_t j = 0; j < m_points; j++) {
313 for (
size_t n = 0; n < m_nv; n++) {
A map of string keys to values whose type can vary at runtime.
bool hasKey(const std::string &key) const
Returns true if the map contains an item named key.
A wrapper for a variable whose type is determined at runtime.
bool hasKey(const std::string &key) const
Returns true if this AnyValue is an AnyMap and that map contains a key with the given name.
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.
size_t nComponents() const
Number of components at each grid point.
virtual doublereal initialValue(size_t n, size_t j)
Initial value of solution component n at grid point j.
virtual AnyMap serialize(const double *soln) const
Save the state of this domain as an AnyMap.
virtual void showSolution(const doublereal *x)
Print the solution.
doublereal atol(size_t n)
Absolute tolerance of the nth component.
size_t nPoints() const
Number of grid points in this domain.
virtual std::string componentName(size_t n) const
Name of the nth component. May be overloaded.
void setSteadyTolerances(doublereal rtol, doublereal atol, size_t n=npos)
Set tolerances for steady-state mode.
virtual XML_Node & save(XML_Node &o, const doublereal *const sol)
Save the current solution for this domain into an XML_Node.
virtual void resize(size_t nv, size_t np)
virtual void restore(const XML_Node &dom, doublereal *soln, int loglevel)
Restore the solution for this domain from an XML_Node.
virtual void _getInitialSoln(doublereal *x)
Writes some or all initial solution values into the global solution array, beginning at the location ...
Domain1D(size_t nv=1, size_t points=1, double time=0.0)
Constructor.
virtual void setupGrid(size_t n, const doublereal *z)
called to set up initial grid, and after grid refinement
doublereal rtol(size_t n)
Relative tolerance of the nth component.
virtual size_t componentIndex(const std::string &name) const
index of component with name name.
virtual size_t loc(size_t j=0) const
Location of the start of the local solution vector in the global solution vector,.
void locate()
Find the index of the first grid point in this domain, and the start of its variables in the global s...
void setTransientTolerances(doublereal rtol, doublereal atol, size_t n=npos)
Set tolerances for time-stepping mode.
void setAge(int age)
Set the Jacobian age.
An error indicating that an unimplemented function has been called.
void saveStats()
Save statistics on function and Jacobian evaluation, and reset the counters.
MultiJac & jacobian()
Return a reference to the Jacobian evaluator.
Refine Domain1D grids so that profiles satisfy adaptation tolerances.
Class XML_Node is a tree-based representation of the contents of an XML file.
void addAttribute(const std::string &attrib, const std::string &value)
Add or modify an attribute of the current node.
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...
CTML ("Cantera Markup Language") is the variant of XML that Cantera uses to store data.
void writelog(const std::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"
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
size_t getFloatArray(const XML_Node &node, vector_fp &v, const bool convert=true, const std::string &unitsString="", const std::string &nodeName="floatArray")
This function reads the current node or a child node of the current node with the default name,...
void warn_user(const std::string &method, const std::string &msg, const Args &... args)
Print a user warning raised from method as CanteraWarning.
void addFloatArray(XML_Node &node, const std::string &titleString, const size_t n, const doublereal *const values, const std::string &unitsString="", const std::string &typeString="", const doublereal minval=Undef, const doublereal maxval=Undef)
This function adds a child node with the name, "floatArray", with a value consisting of a comma separ...