Cantera  3.1.0a1
refine.h
1 // This file is part of Cantera. See License.txt in the top-level directory or
2 // at https://cantera.org/license.txt for license and copyright information.
3 
4 #ifndef CT_REFINE_H
5 #define CT_REFINE_H
6 
7 #include "cantera/base/ct_defs.h"
8 
9 namespace Cantera
10 {
11 
12 class Domain1D;
13 
14 //! Refine Domain1D grids so that profiles satisfy adaptation tolerances
15 //! @ingroup onedUtilsGroup
16  class Refiner
17 {
18 public:
19  Refiner(Domain1D& domain);
20  virtual ~Refiner() {}
21  Refiner(const Refiner&) = delete;
22  Refiner& operator=(const Refiner&) = delete;
23 
24  //! Set grid refinement criteria
25  /*!
26  * @param ratio Maximum ratio between grid spacing at adjacent intervals.
27  * That is, `(x[j+1] - x[j]) / (x[j] - x[j-1]) < ratio`
28  * @param slope Maximum fractional change in the value of each solution
29  * component between adjacent grid points
30  * @param curve Maximum fractional change in the derivative of each
31  * solution component between adjacent grid points.
32  * @param prune Threshold for removing unnecessary grid points. `prune`
33  * should be smaller than both `slope` and `curve`. Set `prune <= 0`
34  * to disable pruning.
35  */
36  void setCriteria(double ratio = 10.0,
37  double slope = 0.8,
38  double curve = 0.8,
39  double prune = -0.1);
40 
41  //! Get the grid refinement criteria. @see Refiner::setCriteria
42  vector<double> getCriteria()
43  {
44  return {m_ratio, m_slope, m_curve, m_prune};
45  }
46 
47  void setActive(int comp, bool state = true) {
48  m_active[comp] = state;
49  }
50 
51  //! Set the maximum number of points allowed in the domain
52  void setMaxPoints(int npmax) {
53  m_npmax = npmax;
54  }
55 
56  //! Returns the maximum number of points allowed in the domain
57  size_t maxPoints() const {
58  return m_npmax;
59  }
60 
61  //! Set the minimum allowable spacing between adjacent grid points [m].
62  void setGridMin(double gridmin) {
63  m_gridmin = gridmin;
64  }
65 
66  //! Returns the the minimum allowable spacing between adjacent
67  //! grid points [m].
68  double gridMin() const {
69  return m_gridmin;
70  }
71 
72  int analyze(size_t n, const double* z, const double* x);
73  int getNewGrid(int n, const double* z, int nn, double* znew);
74  int nNewPoints() {
75  return static_cast<int>(m_loc.size());
76  }
77  void show();
78  bool newPointNeeded(size_t j) {
79  return m_loc.find(j) != m_loc.end();
80  }
81  bool keepPoint(size_t j) {
82  return (m_keep[j] != -1);
83  }
84  double value(const double* x, size_t i, size_t j);
85 
86  double maxRatio() {
87  return m_ratio;
88  }
89  double maxDelta() {
90  return m_slope;
91  }
92  double maxSlope() {
93  return m_curve;
94  }
95  double prune() {
96  return m_prune;
97  }
98 
99 protected:
100  //! Indices of grid points that need new grid points added after them
101  set<size_t> m_loc;
102  map<size_t, int> m_keep;
103  //! Names of components that require the addition of new grid points
104  set<string> m_c;
105  vector<bool> m_active;
106  double m_ratio = 10.0;
107  double m_slope = 0.8;
108  double m_curve = 0.8;
109  double m_prune = -0.001;
110  double m_min_range = 0.01;
111  Domain1D* m_domain;
112  size_t m_nv;
113  size_t m_npmax = 1000;
114  double m_thresh = std::sqrt(std::numeric_limits<double>::epsilon());
115  double m_gridmin = 1e-10; //!< minimum grid spacing [m]
116 };
117 
118 }
119 
120 #endif
Base class for one-dimensional domains.
Definition: Domain1D.h:28
Refine Domain1D grids so that profiles satisfy adaptation tolerances.
Definition: refine.h:17
size_t maxPoints() const
Returns the maximum number of points allowed in the domain.
Definition: refine.h:57
set< string > m_c
Names of components that require the addition of new grid points.
Definition: refine.h:104
set< size_t > m_loc
Indices of grid points that need new grid points added after them.
Definition: refine.h:101
void setMaxPoints(int npmax)
Set the maximum number of points allowed in the domain.
Definition: refine.h:52
void setCriteria(double ratio=10.0, double slope=0.8, double curve=0.8, double prune=-0.1)
Set grid refinement criteria.
Definition: refine.cpp:21
double gridMin() const
Returns the the minimum allowable spacing between adjacent grid points [m].
Definition: refine.h:68
vector< double > getCriteria()
Get the grid refinement criteria.
Definition: refine.h:42
double m_gridmin
minimum grid spacing [m]
Definition: refine.h:115
void setGridMin(double gridmin)
Set the minimum allowable spacing between adjacent grid points [m].
Definition: refine.h:62
This file contains definitions of constants, types and terms that are used in internal routines and a...
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:564