Cantera  2.0
Sim1D.h
Go to the documentation of this file.
1 /**
2  * @file Sim1D.h
3  */
4 
5 #ifndef CT_SIM1D_H
6 #define CT_SIM1D_H
7 
8 #include "OneDim.h"
10 
11 namespace Cantera
12 {
13 
14 /**
15  * One-dimensional simulations. Class Sim1D extends class OneDim
16  * by storing the solution vector, and by adding a hybrid
17  * Newton/time-stepping solver.
18  */
19 class Sim1D : public OneDim
20 {
21 
22 public:
23 
24 
25  //! Default constructor.
26  /*!
27  * This constructor is provided to make
28  * the class default-constructible, but is not meant to be
29  * used in most applications. Use the next constructor
30  */
31  Sim1D();
32 
33 
34  /**
35  * Standard constructor.
36  * @param domains A vector of pointers to the domains to be linked together.
37  * The domain pointers must be entered in left-to-right order --- i.e.,
38  * the pointer to the leftmost domain is domain[0], the pointer to the
39  * domain to its right is domain[1], etc.
40  */
41  Sim1D(std::vector<Domain1D*>& domains);
42 
43  /// Destructor. Does nothing.
44  virtual ~Sim1D() {}
45 
46  /**
47  * @name Setting initial values
48  *
49  * These methods are used to set the initial values of
50  * solution components.
51  */
52  //@{
53 
54  /// Set initial guess based on equilibrium
55  void setInitialGuess(std::string component, vector_fp& locs, vector_fp& vals);
56 
57  /// Set one entry in the solution vector.
58  void setValue(size_t dom, size_t comp, size_t localPoint, doublereal value);
59 
60  /// Get one entry in the solution vector.
61  doublereal value(size_t dom, size_t comp, size_t localPoint) const;
62 
63  doublereal workValue(size_t dom, size_t comp, size_t localPoint) const;
64 
65  /// Specify a profile for one component of one domain.
66  void setProfile(size_t dom, size_t comp, const vector_fp& pos,
67  const vector_fp& values);
68 
69  /// Set component 'comp' of domain 'dom' to value 'v' at all points.
70  void setFlatProfile(size_t dom, size_t comp, doublereal v);
71 
72  //@}
73 
74  void save(std::string fname, std::string id, std::string desc);
75 
76  /// Print to stream s the current solution for all domains.
77  void showSolution(std::ostream& s);
78  void showSolution();
79 
80  const doublereal* solution() {
81  return DATA_PTR(m_x);
82  }
83 
84  void setTimeStep(doublereal stepsize, size_t n, integer* tsteps);
85 
86  //void setMaxTimeStep(doublereal tmax) { m_maxtimestep = tmax; }
87 
88  void solve(int loglevel = 0, bool refine_grid = true);
89 
90  void eval(doublereal rdt=-1.0, int count = 1) {
91  OneDim::eval(npos, DATA_PTR(m_x), DATA_PTR(m_xnew), rdt, count);
92  }
93 
94  /// Refine the grid in all domains.
95  int refine(int loglevel=0);
96 
97  int setFixedTemperature(doublereal t);
98  void setAdiabaticFlame(void);
99 
100  /// Set the criteria for grid refinement.
101  void setRefineCriteria(int dom = -1, doublereal ratio = 10.0,
102  doublereal slope = 0.8, doublereal curve = 0.8, doublereal prune = -0.1);
103  void setMaxGridPoints(int dom = -1, int npoints = 300);
104 
105  void restore(std::string fname, std::string id);
106  //! Set the minimum grid spacing in the specified domain(s).
107  /*!
108  * @param dom Domain index. If dom == -1, the specified spacing
109  is applied to all domains.
110  @param gridmin The minimum allowable grid spacing [m]
111  */
112  void setGridMin(int dom, double gridmin);
113 
114  void getInitialSoln();
115 
116  void setSolution(const doublereal* soln) {
117  std::copy(soln, soln + m_x.size(), DATA_PTR(m_x));
118  }
119 
120  const doublereal* solution() const {
121  return DATA_PTR(m_x);
122  }
123 
124  doublereal jacobian(int i, int j);
125 
126  void evalSSJacobian();
127 
128 protected:
129 
130  vector_fp m_x; // the solution vector
131  vector_fp m_xnew; // a work array used to hold the residual
132  // or the new solution
133  doublereal m_tstep; // timestep
134  vector_int m_steps; // array of number of steps to take before
135  // re-attempting the steady-state solution
136 
137 
138 private:
139 
140  /// Calls method _finalize in each domain.
141  void finalize();
142 
143  /*! Wrapper around the Newton solver.
144  * @return 0 if successful, -1 on failure
145  */
146  int newtonSolve(int loglevel);
147 
148 
149 };
150 
151 }
152 #endif
153 
154