6#include "cantera/oneD/refine.h"
17 m_nv = m_domain->nComponents();
18 m_active.resize(m_nv,
true);
25 "'ratio' must be greater than 2.0 ({} was specified).", ratio);
26 }
else if (slope < 0.0 || slope > 1.0) {
28 "'slope' must be between 0.0 and 1.0 ({} was specified).", slope);
29 }
else if (curve < 0.0 || curve > 1.0) {
31 "'curve' must be between 0.0 and 1.0 ({} was specified).", curve);
34 "'prune' must be less than 'curve' and 'slope' ({} was specified).",
55 throw CanteraError(
"Refiner::analyze",
"number of grid points provided does not match domain size.");
70 vector<double> val(n);
71 vector<double> slope(n-1);
73 vector<double> dz(n-1);
74 for (
size_t j = 0; j < n-1; j++) {
75 dz[j] = z[j+1] - z[j];
78 for (
size_t i = 0; i <
m_nv; i++) {
80 string name =
m_domain->componentName(i);
82 for (
size_t j = 0; j < n; j++) {
83 val[j] =
value(x, i, j);
87 for (
size_t j = 0; j < n-1; j++) {
88 slope[j] = (val[j+1] - val[j]) / dz[j];
92 double valMin = *min_element(val.begin(), val.end());
93 double valMax = *max_element(val.begin(), val.end());
94 double slopeMin = *min_element(slope.begin(), slope.end());
95 double slopeMax = *max_element(slope.begin(), slope.end());
98 double valMagnitude = std::max(fabs(valMax), fabs(valMin));
99 double slopeMagnitude = std::max(fabs(slopeMax), fabs(slopeMin));
107 double max_change =
m_slope*(valMax - valMin);
108 for (
size_t j = 0; j < n-1; j++) {
109 double ratio = fabs(val[j+1] - val[j]) / (max_change +
m_thresh);
110 if (ratio > 1.0 && dz[j] >= 2 *
m_gridmin) {
117 }
else if (
m_keep[j] == UNSET) {
127 if (slopeMax - slopeMin >
m_min_range*slopeMagnitude) {
129 double max_change =
m_curve*(slopeMax - slopeMin);
130 for (
size_t j = 0; j < n-2; j++) {
134 double ratio = fabs(slope[j+1] - slope[j]) / (max_change +
m_thresh/dz[j]);
142 }
else if (
m_keep[j+1] == UNSET) {
151 for (
size_t j = 1; j < n-1; j++) {
175 if (j > 1 && z[j+1]-z[j-1] >
m_ratio * dz[j-2]) {
181 if (j < n-2 && z[j+1]-z[j-1] >
m_ratio * dz[j+1]) {
202 for (
size_t j = 2; j < n-1; j++) {
220 writelog(
string(
"Refining grid in ") +
222 +
" New points inserted after grid points ");
233 }
else if (
m_domain->nPoints() > 1) {
Base class for exceptions thrown by Cantera classes.
Base class for one-dimensional domains.
This class represents 1D flow domains that satisfy the one-dimensional similarity solution for chemic...
bool twoPointControlEnabled() const
Returns the status of the two-point control.
double m_zfixed
Location of the point where temperature is fixed.
double leftControlPointCoordinate() const
Returns the z-coordinate of the left control point.
bool isFree() const
Retrieve flag indicating whether flow is freely propagating.
double rightControlPointCoordinate() const
Returns the z-coordinate of the right control point.
double value(const double *x, size_t n, size_t j)
Returns the value of the solution component, n, at grid point j.
set< string > m_componentNames
Names of components that require the addition of new grid points.
double m_thresh
Absolute tolerance threshold for solution components in the domain.
double m_ratio
grid spacing refinement criteria
void show()
Displays the results of the grid refinement analysis.
size_t m_nv
Number of components in the domain.
double m_prune
pruning refinement criteria
double m_min_range
Threshold for ignoring small changes around a constant during refinement.
set< size_t > m_insertPts
Indices of grid points that need new grid points added after them.
void setCriteria(double ratio=10.0, double slope=0.8, double curve=0.8, double prune=-0.1)
Set grid refinement criteria.
double m_curve
function slope refinement criteria
vector< bool > m_active
Flags for whether each component should be considered for grid refinement.
size_t m_npmax
Maximum number of grid points.
int analyze(size_t n, const double *z, const double *x)
Determine locations in the grid that need additional grid points and update the internal state of the...
double m_slope
function change refinement criteria
double prune()
Returns the threshold for removing unnecessary grid points.
double m_gridmin
minimum grid spacing [m]
map< size_t, GridPointStatus > m_keep
Status of whether each grid point should be kept or removed.
Domain1D * m_domain
Pointer to the domain to be refined.
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
void writelog(const string &fmt, const Args &... args)
Write a formatted message to the screen.
Namespace for the Cantera kernel.