Cantera  2.3.0
refine.h
1 // This file is part of Cantera. See License.txt in the top-level directory or
2 // at http://www.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 
22  //! Set grid refinement criteria
23  /*!
24  * @param ratio Maximum ratio between grid spacing at adjacent intervals.
25  * E.g. `(x[j+1] - x[j]) / (x[j] - x[j-1]) < ratio`
26  * @param slope Maximum fractional change in the value of each solution
27  * component between adjacent grid points
28  * @param curve Maximum fractional change in the derivative of each
29  * solution component between adjacent grid points.
30  * @param prune Threshold for removing unnecessary grid points. `prune`
31  * should be smaller than both `slope` and `curve`. Set `prune <= 0`
32  * to disable pruning.
33  */
34  void setCriteria(doublereal ratio = 10.0,
35  doublereal slope = 0.8,
36  doublereal curve = 0.8,
37  doublereal prune = -0.1);
38 
39  void setActive(int comp, bool state = true) {
40  m_active[comp] = state;
41  }
42 
43  //! Set the maximum number of points allowed in the domain
44  void setMaxPoints(int npmax) {
45  m_npmax = npmax;
46  }
47 
48  //! Returns the maximum number of points allowed in the domain
49  size_t maxPoints() const {
50  return m_npmax;
51  }
52 
53  //! Set the minimum allowable spacing between adjacent grid points [m].
54  void setGridMin(double gridmin) {
55  m_gridmin = gridmin;
56  }
57 
58  //! Returns the the minimum allowable spacing between adjacent
59  //! grid points [m].
60  double gridMin() const {
61  return m_gridmin;
62  }
63 
64  int analyze(size_t n, const doublereal* z, const doublereal* x);
65  int getNewGrid(int n, const doublereal* z, int nn, doublereal* znew);
66  int nNewPoints() {
67  return static_cast<int>(m_loc.size());
68  }
69  void show();
70  bool newPointNeeded(size_t j) {
71  return m_loc.find(j) != m_loc.end();
72  }
73  bool keepPoint(size_t j) {
74  return (m_keep[j] != -1);
75  }
76  double value(const double* x, size_t i, size_t j);
77 
78  double maxRatio() {
79  return m_ratio;
80  }
81  double maxDelta() {
82  return m_slope;
83  }
84  double maxSlope() {
85  return m_curve;
86  }
87  double prune() {
88  return m_prune;
89  }
90 
91 protected:
92  std::map<size_t, int> m_loc;
93  std::map<size_t, int> m_keep;
94  std::map<std::string, int> m_c;
95  std::vector<bool> m_active;
96  doublereal m_ratio, m_slope, m_curve, m_prune;
97  doublereal m_min_range;
98  Domain1D* m_domain;
99  size_t m_nv, m_npmax;
100  doublereal m_thresh;
101  doublereal m_gridmin; //!< minimum grid spacing [m]
102 };
103 
104 }
105 
106 #endif
This file contains definitions of terms that are used in internal routines and are unlikely to need m...
doublereal m_gridmin
minimum grid spacing [m]
Definition: refine.h:101
size_t maxPoints() const
Returns the maximum number of points allowed in the domain.
Definition: refine.h:49
Base class for one-dimensional domains.
Definition: Domain1D.h:36
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 setMaxPoints(int npmax)
Set the maximum number of points allowed in the domain.
Definition: refine.h:44
double gridMin() const
Returns the the minimum allowable spacing between adjacent grid points [m].
Definition: refine.h:60
void setGridMin(double gridmin)
Set the minimum allowable spacing between adjacent grid points [m].
Definition: refine.h:54
Refine Domain1D grids so that profiles satisfy adaptation tolerances.
Definition: refine.h:16
Namespace for the Cantera kernel.
Definition: application.cpp:29