10#include "cantera/oneD/refine.h"
29 "To be changed after Cantera 3.0; for new behavior, see 'type'.");
37 if (nv != m_nv || !m_refiner) {
39 m_refiner = make_unique<Refiner>(*
this);
42 m_name.resize(m_nv,
"");
43 m_max.resize(m_nv, 0.0);
44 m_min.resize(m_nv, 0.0);
46 m_rtol_ss.resize(m_nv, 1.0e-4);
47 m_atol_ss.resize(m_nv, 1.0e-9);
48 m_rtol_ts.resize(m_nv, 1.0e-4);
49 m_atol_ts.resize(m_nv, 1.0e-11);
52 m_slast.resize(m_nv *
m_points, 0.0);
58 if (m_name[n] !=
"") {
61 return fmt::format(
"component {}", n);
73 "no component named "+name);
79 for (n = 0; n < m_nv; n++) {
92 for (n = 0; n < m_nv; n++) {
112 auto wrap_tols = [
this](
const vector<double>& tols) {
115 set<double> unique_tols(tols.begin(), tols.end());
116 if (unique_tols.size() == 1) {
120 for (
size_t i = 0; i < tols.size(); i++) {
127 state[
"type"] =
type();
128 state[
"points"] =
static_cast<long int>(
nPoints());
130 state[
"tolerances"][
"transient-abstol"] = wrap_tols(m_atol_ts);
131 state[
"tolerances"][
"steady-abstol"] = wrap_tols(m_atol_ss);
132 state[
"tolerances"][
"transient-reltol"] = wrap_tols(m_rtol_ts);
133 state[
"tolerances"][
"steady-reltol"] = wrap_tols(m_rtol_ss);
141 "To be removed after Cantera 3.0; superseded by asArray.");
144 arr->writeEntry(out,
"",
"");
151 "Domain needs to be installed in a container before calling asArray.");
164 "Domain needs to be installed in a container before calling fromArray.");
174 auto set_tols = [&](
const AnyValue& tols,
const string& which, vector<double>& out)
176 if (!tols.
hasKey(which)) {
179 const auto& tol = tols[which];
180 if (tol.isScalar()) {
185 if (tol.hasKey(name)) {
186 out[i] = tol[name].asDouble();
188 warn_user(
"Domain1D::setMeta",
"No {} found for component '{}'",
195 if (meta.
hasKey(
"tolerances")) {
196 const auto& tols = meta[
"tolerances"];
197 set_tols(tols,
"transient-abstol", m_atol_ts);
198 set_tols(tols,
"transient-reltol", m_rtol_ts);
199 set_tols(tols,
"steady-abstol", m_atol_ss);
200 set_tols(tols,
"steady-reltol", m_rtol_ss);
207 "To be removed after Cantera 3.0; restore from SolutionArray instead.");
209 arr->readEntry(state,
"",
"");
237 for (
size_t j = 0; j <
m_points; j++) {
246 "To be removed after Cantera 3.0; replaced by 'show'.");
253 "To be removed after Cantera 3.0; replaced by 'show'.");
260 for (
size_t i = 0; i < nn; i++) {
261 writeline(
'-', 79,
false,
true);
263 for (
size_t n = 0; n < 5; n++) {
266 writeline(
'-', 79,
false,
true);
267 for (
size_t j = 0; j <
m_points; j++) {
269 for (
size_t n = 0; n < 5; n++) {
270 double v = value(x, i*5+n, j);
276 size_t nrem = m_nv - 5*nn;
277 writeline(
'-', 79,
false,
true);
279 for (
size_t n = 0; n < nrem; n++) {
282 writeline(
'-', 79,
false,
true);
283 for (
size_t j = 0; j <
m_points; j++) {
285 for (
size_t n = 0; n < nrem; n++) {
286 double v = value(x, nn*5+n, j);
293void Domain1D::setProfile(
const string& name,
double* values,
double* soln)
295 for (
size_t n = 0; n < m_nv; n++) {
297 for (
size_t j = 0; j <
m_points; j++) {
298 soln[index(n, j) +
m_iloc] = values[j];
303 throw CanteraError(
"Domain1D::setProfile",
"unknown component: "+name);
308 for (
size_t j = 0; j <
m_points; j++) {
309 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 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 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.
void setTransientTolerances(double rtol, double atol, size_t n=npos)
Set tolerances for time-stepping mode.
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.
double rtol(size_t n)
Relative tolerance of the nth component.
AnyMap serialize(const double *soln) const
Save the state of this domain as an AnyMap.
shared_ptr< Solution > solution() const
Return thermo/kinetics/transport manager used in the domain.
virtual void setMeta(const AnyMap &meta)
Retrieve meta data.
virtual void _finalize(const double *x)
In some cases, a domain may need to set parameters that depend on the initial solution estimate.
virtual string type() const
String indicating the domain implemented.
size_t nPoints() const
Number of grid points in this domain.
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.
void setSteadyTolerances(double rtol, double atol, size_t n=npos)
Set tolerances for steady-state mode.
virtual shared_ptr< SolutionArray > asArray(const double *soln) const
Save the state of this domain as a SolutionArray.
virtual string componentName(size_t n) const
Name of the nth component. May be overloaded.
double atol(size_t n)
Absolute tolerance of the nth component.
void restore(const AnyMap &state, double *soln, int loglevel)
Restore the solution for this domain from an AnyMap.
shared_ptr< SolutionArray > toArray(bool normalize=false) const
Save the state of this domain to a SolutionArray.
size_t m_points
Number of grid points.
virtual void showSolution(const double *x)
Print the solution.
int domainType()
Domain type flag.
virtual double initialValue(size_t n, size_t j)
Initial value of solution component n at grid point j.
virtual size_t componentIndex(const string &name) const
index of component with name name.
virtual void fromArray(SolutionArray &arr, double *soln)
Restore the solution for this domain from a SolutionArray.
virtual void showSolution_s(std::ostream &s, const double *x)
void needJacUpdate()
Set this if something has changed in the governing equations (for example, the value of a constant ha...
virtual void _getInitialSoln(double *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 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...
virtual AnyMap getMeta() const
Retrieve meta data.
virtual void show(std::ostream &s, const double *x)
Print the solution.
virtual void setupGrid(size_t n, const double *z)
called to set up initial grid, and after grid refinement
void setAge(int age)
Set the Jacobian age.
An error indicating that an unimplemented function has been called.
virtual void resize()
Call after one or more grids has changed size, for example after being refined.
void saveStats()
Save statistics on function and Jacobian evaluation, and reset the counters.
static shared_ptr< SolutionArray > create(const shared_ptr< Solution > &sol, int size=0, const AnyMap &meta={})
Instantiate a new SolutionArray reference.
MultiJac & jacobian()
Return a reference to the Jacobian evaluator of an OneDim object.
void writelog(const string &fmt, const Args &... args)
Write a formatted message to the screen.
void warn_user(const string &method, const string &msg, const Args &... args)
Print a user warning raised from method as CanteraWarning.
Namespace for the Cantera kernel.
const size_t npos
index returned by functions to indicate "no position"
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.