Cantera  2.5.1
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 onedim
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  * E.g. `(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(doublereal ratio = 10.0,
37  doublereal slope = 0.8,
38  doublereal curve = 0.8,
39  doublereal prune = -0.1);
40 
41  //! Get the grid refinement criteria. @see Refiner::setCriteria
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 doublereal* z, const doublereal* x);
73  int getNewGrid(int n, const doublereal* z, int nn, doublereal* 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  std::map<size_t, int> m_loc;
101  std::map<size_t, int> m_keep;
102  std::map<std::string, int> m_c;
103  std::vector<bool> m_active;
104  doublereal m_ratio, m_slope, m_curve, m_prune;
105  doublereal m_min_range;
106  Domain1D* m_domain;
107  size_t m_nv, m_npmax;
108  doublereal m_thresh;
109  doublereal m_gridmin; //!< minimum grid spacing [m]
110 };
111 
112 }
113 
114 #endif
Base class for one-dimensional domains.
Definition: Domain1D.h:39
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
vector_fp getCriteria()
Get the grid refinement criteria.
Definition: refine.h:42
void setMaxPoints(int npmax)
Set the maximum number of points allowed in the domain.
Definition: refine.h:52
doublereal m_gridmin
minimum grid spacing [m]
Definition: refine.h:109
double gridMin() const
Returns the the minimum allowable spacing between adjacent grid points [m].
Definition: refine.h:68
void setCriteria(doublereal ratio=10.0, doublereal slope=0.8, doublereal curve=0.8, doublereal prune=-0.1)
Set grid refinement criteria.
Definition: refine.cpp:23
void setGridMin(double gridmin)
Set the minimum allowable spacing between adjacent grid points [m].
Definition: refine.h:62
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
std::vector< double > vector_fp
Turn on the use of stl vectors for the basic array type within cantera Vector of doubles.
Definition: ct_defs.h:180
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:264