10#include "cantera/oneD/refine.h"
33 if (!sol || !(sol->thermo())) {
35 "Missing or incomplete Solution object.");
38 "After Cantera 3.2, a change of domain contents after instantiation "
49 return toArray()->info(keys, rows, width);
81 return fmt::format(
"component {}", n);
89 for (
size_t n = 0; n <
m_nv; n++) {
95 "Component '{}' not found", name);
100 for (
size_t n = 0; n <
m_nv; n++) {
106 "Component '{}' not found", name);
112 for (n = 0; n <
m_nv; n++) {
125 for (n = 0; n <
m_nv; n++) {
145 auto wrap_tols = [
this](
const vector<double>& tols) {
148 set<double> unique_tols(tols.begin(), tols.end());
149 if (unique_tols.size() == 1) {
153 for (
size_t i = 0; i < tols.size(); i++) {
160 state[
"type"] =
type();
161 state[
"points"] =
static_cast<long int>(
nPoints());
163 state[
"tolerances"][
"transient-abstol"] = wrap_tols(
m_atol_ts);
164 state[
"tolerances"][
"steady-abstol"] = wrap_tols(
m_atol_ss);
165 state[
"tolerances"][
"transient-reltol"] = wrap_tols(
m_rtol_ts);
166 state[
"tolerances"][
"steady-reltol"] = wrap_tols(
m_rtol_ss);
173 auto set_tols = [&](
const AnyValue& tols,
const string& which, vector<double>& out)
175 if (!tols.
hasKey(which)) {
178 const auto& tol = tols[which];
179 if (tol.isScalar()) {
184 if (tol.hasKey(name)) {
185 out[i] = tol[name].asDouble();
187 warn_user(
"Domain1D::setMeta",
"No {} found for component '{}'",
194 if (meta.
hasKey(
"tolerances")) {
195 const auto& tols = meta[
"tolerances"];
196 set_tols(tols,
"transient-abstol",
m_atol_ts);
197 set_tols(tols,
"transient-reltol",
m_rtol_ts);
198 set_tols(tols,
"steady-abstol",
m_atol_ss);
199 set_tols(tols,
"steady-reltol",
m_rtol_ss);
232 for (
size_t j = 0; j <
m_points; j++) {
240 vector<double>
grid(points);
241 double dz = length /
static_cast<double>(points - 1);
242 for (
size_t iz = 0; iz < points; iz++) {
243 grid[iz] = start + iz * dz;
251 for (
size_t i = 0; i < nn; i++) {
252 writeline(
'-', 79,
false,
true);
254 for (
size_t n = 0; n < 5; n++) {
257 writeline(
'-', 79,
false,
true);
258 for (
size_t j = 0; j <
m_points; j++) {
260 for (
size_t n = 0; n < 5; n++) {
266 size_t nrem =
m_nv - 5*nn;
267 writeline(
'-', 79,
false,
true);
269 for (
size_t n = 0; n < nrem; n++) {
272 writeline(
'-', 79,
false,
true);
273 for (
size_t j = 0; j <
m_points; j++) {
275 for (
size_t n = 0; n < nrem; n++) {
285 "Domain1D::setProfile",
"To be removed after Cantera 3.2. Replaceable by "
286 "version using vector arguments.");
287 for (
size_t n = 0; n <
m_nv; n++) {
289 for (
size_t j = 0; j <
m_points; j++) {
295 throw CanteraError(
"Domain1D::setProfile",
"unknown component: "+name);
300 m_refiner->setCriteria(ratio, slope, curve, prune);
310 for (
size_t j = 0; j <
m_points; j++) {
311 for (
size_t n = 0; n <
m_nv; n++) {
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 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.
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.
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.
size_t size() const
Return the size of the solution vector (the product of m_nv and m_points).
vector< double > m_atol_ts
Absolute tolerances for transient mode.
virtual void setMeta(const AnyMap &meta)
Retrieve meta data.
void setupGrid(const vector< double > &grid)
Set up initial grid.
vector< 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.
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.
vector< double > values(const string &component) const
Retrieve component values.
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 show(const double *x)
Print the solution.
vector< double > m_rtol_ss
Relative tolerances for steady mode.
vector< double > m_slast
Solution vector at the last time step.
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.
void setSolution(shared_ptr< Solution > sol)
Set the solution manager.
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.
string type() const
String indicating the domain implemented.
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 void setProfile(const string &component, const vector< double > &pos, const vector< double > &values)
Specify a profile for a component.
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...
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.
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.
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 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.
void saveStats()
Save statistics on function and Jacobian evaluation, and reset the counters.
shared_ptr< SystemJacobian > linearSolver() const
Get the the linear solver being used to hold the Jacobian matrix and solve linear systems as part of ...
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.