6 #include "cantera/oneD/refine.h"
14 Refiner::Refiner(Domain1D& domain) :
17 m_nv = m_domain->nComponents();
18 m_active.resize(m_nv,
true);
21 void Refiner::setCriteria(
double ratio,
double slope,
double curve,
double prune)
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);
32 }
else if (prune > curve || prune > slope) {
34 "'prune' must be less than 'curve' and 'slope' ({} was specified).",
43 int Refiner::analyze(
size_t n,
const double* z,
const double* x)
46 throw CanteraError(
"Refiner::analyze",
"max number of grid points reached ({}).", m_npmax);
49 if (m_domain->nPoints() <= 1) {
60 m_nv = m_domain->nComponents();
63 if (n != m_domain->nPoints()) {
64 throw CanteraError(
"Refiner::analyze",
"inconsistent");
68 vector<double> v(n), s(n-1);
70 vector<double> dz(n-1);
71 for (
size_t j = 0; j < n-1; j++) {
72 dz[j] = z[j+1] - z[j];
75 for (
size_t i = 0; i < m_nv; i++) {
77 string name = m_domain->componentName(i);
79 for (
size_t j = 0; j < n; j++) {
80 v[j] = value(x, i, j);
84 for (
size_t j = 0; j < n-1; j++) {
85 s[j] = (value(x, i, j+1) - value(x, i, j))/(z[j+1] - z[j]);
89 double vmin = *min_element(v.begin(), v.end());
90 double vmax = *max_element(v.begin(), v.end());
91 double smin = *min_element(s.begin(), s.end());
92 double smax = *max_element(s.begin(), s.end());
95 double aa = std::max(fabs(vmax), fabs(vmin));
96 double ss = std::max(fabs(smax), fabs(smin));
102 if ((vmax - vmin) > m_min_range*aa) {
105 double dmax = m_slope*(vmax - vmin) + m_thresh;
106 for (
size_t j = 0; j < n-1; j++) {
107 double r = fabs(v[j+1] - v[j])/dmax;
108 if (r > 1.0 && dz[j] >= 2 * m_gridmin) {
115 }
else if (m_keep[j] == 0) {
125 if ((smax - smin) > m_min_range*ss) {
128 double dmax = m_curve*(smax - smin);
129 for (
size_t j = 0; j < n-2; j++) {
130 double r = fabs(s[j+1] - s[j]) / (dmax + m_thresh/dz[j]);
131 if (r > 1.0 && dz[j] >= 2 * m_gridmin &&
132 dz[j+1] >= 2 * m_gridmin) {
139 }
else if (m_keep[j+1] == 0) {
147 StFlow* fflame =
dynamic_cast<StFlow*
>(m_domain);
150 for (
size_t j = 1; j < n-1; j++) {
152 if (dz[j] > m_ratio*dz[j-1]) {
154 m_c.insert(fmt::format(
"point {}", j));
162 if (dz[j] < dz[j-1]/m_ratio) {
164 m_c.insert(fmt::format(
"point {}", j-1));
173 if (j > 1 && z[j+1]-z[j-1] > m_ratio * dz[j-2]) {
179 if (j < n-2 && z[j+1]-z[j-1] > m_ratio * dz[j+1]) {
184 if (fflame && fflame->isFree() && z[j] == fflame->m_zfixed) {
191 for (
size_t j = 2; j < n-1; j++) {
192 if (m_keep[j] == -1 && m_keep[j-1] == -1) {
197 return int(m_loc.size());
200 double Refiner::value(
const double* x,
size_t i,
size_t j)
202 return x[m_domain->index(i,j)];
207 if (!m_loc.empty()) {
209 writelog(
string(
"Refining grid in ") +
211 +
" New points inserted after grid points ");
212 for (
const auto& loc : m_loc) {
217 for (
const auto& c : m_c) {
222 }
else if (m_domain->nPoints() > 1) {
223 writelog(
"no new points needed in "+m_domain->id()+
"\n");
227 int Refiner::getNewGrid(
int n,
const double* z,
int nn,
double* zn)
229 int nnew =
static_cast<int>(m_loc.size());
231 throw CanteraError(
"Refine::getNewGrid",
"array size too small.");
240 for (
int j = 0; j < n - 1; j++) {
243 if (m_loc.count(j)) {
244 zn[jn] = 0.5*(z[j] + z[j+1]);
Base class for exceptions thrown by Cantera classes.
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.