11#include "cantera/oneD/refine.h"
34 return toArray()->info(keys, rows, width);
66 return fmt::format(
"component {}", n);
74 for (
size_t n = 0; n <
m_nv; n++) {
80 "Component '{}' not found", name);
85 for (
size_t n = 0; n <
m_nv; n++) {
91 "Component '{}' not found", name);
97 for (n = 0; n <
m_nv; n++) {
110 for (n = 0; n <
m_nv; n++) {
130 auto wrap_tols = [
this](
const vector<double>& tols) {
133 set<double> unique_tols(tols.begin(), tols.end());
134 if (unique_tols.size() == 1) {
138 for (
size_t i = 0; i < tols.size(); i++) {
146 state[
"points"] =
static_cast<long int>(
nPoints());
148 state[
"tolerances"][
"transient-abstol"] = wrap_tols(
m_atol_ts);
149 state[
"tolerances"][
"steady-abstol"] = wrap_tols(
m_atol_ss);
150 state[
"tolerances"][
"transient-reltol"] = wrap_tols(
m_rtol_ts);
151 state[
"tolerances"][
"steady-reltol"] = wrap_tols(
m_rtol_ss);
158 auto set_tols = [&](
const AnyValue& tols,
const string& which, vector<double>& out)
160 if (!tols.
hasKey(which)) {
163 const auto& tol = tols[which];
164 if (tol.isScalar()) {
169 if (tol.hasKey(name)) {
170 out[i] = tol[name].asDouble();
172 warn_user(
"Domain1D::setMeta",
"No {} found for component '{}'",
179 if (meta.
hasKey(
"tolerances")) {
180 const auto& tols = meta[
"tolerances"];
181 set_tols(tols,
"transient-abstol",
m_atol_ts);
182 set_tols(tols,
"transient-reltol",
m_rtol_ts);
183 set_tols(tols,
"steady-abstol",
m_atol_ss);
184 set_tols(tols,
"steady-reltol",
m_rtol_ss);
210 m_z.assign(
z.begin(),
z.end());
217 vector<double>
grid(points);
218 double dz = length /
static_cast<double>(points - 1);
219 for (
size_t iz = 0; iz < points; iz++) {
220 grid[iz] = start + iz * dz;
228 for (
size_t i = 0; i < nn; i++) {
229 writeline(
'-', 79,
false,
true);
231 for (
size_t n = 0; n < 5; n++) {
234 writeline(
'-', 79,
false,
true);
235 for (
size_t j = 0; j <
m_points; j++) {
237 for (
size_t n = 0; n < 5; n++) {
243 size_t nrem =
m_nv - 5*nn;
244 writeline(
'-', 79,
false,
true);
246 for (
size_t n = 0; n < nrem; n++) {
249 writeline(
'-', 79,
false,
true);
250 for (
size_t j = 0; j <
m_points; j++) {
252 for (
size_t n = 0; n < nrem; n++) {
261 m_refiner->setCriteria(ratio, slope, curve, prune);
271 for (
size_t j = 0; j <
m_points; j++) {
272 for (
size_t n = 0; n <
m_nv; n++) {
286 if (arr.
size() == 0) {
292 vector<double> data(
nPoints());
293 for (
size_t j = 0; j <
nPoints(); j++) {
294 data[j] = res[
index(i, j)];
Header file for class ThermoPhase, the base class for phases with thermodynamic properties,...
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 m_iloc
Starting location within the solution vector for unknowns that correspond to this domain.
virtual void _getInitialSoln(span< double > x)
Writes some or all initial solution values into the global solution array, beginning at the location ...
shared_ptr< Solution > m_solution
Composite thermo/kinetics/transport handler.
Domain1D * m_left
Pointer to the domain to the left.
OneDim * m_container
Parent OneDim simulation containing this and adjacent domains.
virtual void setupGrid(span< const double > z)
Set up initial grid.
size_t nComponents() const
Number of components at each grid point.
double rtol(size_t n)
Relative tolerance of the nth component.
vector< double > m_atol_ss
Absolute tolerances for steady mode.
void setupUniformGrid(size_t points, double length, double start=0.)
Set up uniform grid.
vector< double > m_rtol_ts
Relative tolerances for transient mode.
vector< double > m_atol_ts
Absolute tolerances for transient mode.
virtual void setMeta(const AnyMap &meta)
Retrieve meta data.
span< double > grid()
Access the array of grid coordinates [m].
size_t m_jstart
Index of the first point in this domain in the global point list.
size_t m_nv
Number of solution components.
size_t nPoints() const
Number of grid points in this domain.
vector< string > m_name
Names of solution components.
virtual string domainType() const
Domain type flag.
string info(const vector< string > &keys, int rows=10, int width=80)
Return a concise summary of a Domain.
virtual size_t componentIndex(const string &name, bool checkAlias=true) const
Index of component with name name.
virtual void resize(size_t nv, size_t np)
Resize the domain to have nv components and np grid points.
double z(size_t jlocal) const
Get the coordinate [m] of the point with local index jlocal.
virtual void appendResiduals(SolutionArray &arr, span< const double > res) const
Append residual data to a SolutionArray as extra components.
vector< double > m_rtol_ss
Relative tolerances for steady mode.
vector< double > m_slast
Solution vector at the last time step.
virtual double value(const string &component) const
Set a single component value at a boundary.
Domain1D * m_right
Pointer to the domain to the right.
void setSteadyTolerances(double rtol, double atol, size_t n=npos)
Set tolerances for steady-state mode.
virtual string componentName(size_t n) const
Name of component n. May be overloaded.
double atol(size_t n)
Absolute tolerance of the nth component.
vector< double > m_z
1D spatial grid coordinates
size_t m_points
Number of grid points.
virtual void show(span< const double > x)
Print the solution.
vector< double > m_max
Upper bounds on solution components.
unique_ptr< Refiner > m_refiner
Refiner object used for placing grid points.
vector< double > m_min
Lower bounds on solution components.
virtual double initialValue(size_t n, size_t j)
Initial value of solution component n at grid point j.
virtual shared_ptr< SolutionArray > toArray(bool normalize=false)
Save the state of this domain to a SolutionArray.
void needJacUpdate()
Set this if something has changed in the governing equations (for example, the value of a constant ha...
Domain1D(size_t nv=1, size_t points=1, double time=0.0)
Constructor.
size_t index(size_t n, size_t j) const
Returns the index of the solution vector, which corresponds to component n at grid point j.
vector< double > getRefineCriteria()
Get the grid refinement criteria.
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 bool hasComponent(const string &name, bool checkAlias=true) const
Check whether the Domain contains a component.
void setRefineCriteria(double ratio=10.0, double slope=0.8, double curve=0.8, double prune=-0.1)
Set grid refinement criteria.
An array index is out of range.
An error indicating that an unimplemented function has been called.
A container class holding arrays of state information.
void setComponent(const string &name, const AnyValue &data)
Set a component of the SolutionArray by name.
void addExtra(const string &name, bool back=true)
Add auxiliary component to SolutionArray.
int size() const
Size of SolutionArray (number of entries).
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"