Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
9 
10 namespace Cantera
11 {
12 
13 /**
14  * One-dimensional simulations. Class Sim1D extends class OneDim by storing
15  * the solution vector, and by adding a hybrid Newton/time-stepping solver.
16  * @ingroup onedim
17  */
18 class Sim1D : public OneDim
19 {
20 public:
21 
22  //! Default constructor.
23  /*!
24  * This constructor is provided to make the class default-constructible,
25  * but is not meant to be used in most applications. Use the next
26  * constructor
27  */
28  Sim1D() {}
29 
30  /**
31  * Standard constructor.
32  * @param domains A vector of pointers to the domains to be linked together.
33  * The domain pointers must be entered in left-to-right order --- i.e.,
34  * the pointer to the leftmost domain is domain[0], the pointer to the
35  * domain to its right is domain[1], etc.
36  */
37  Sim1D(std::vector<Domain1D*>& domains);
38 
39  /**
40  * @name Setting initial values
41  *
42  * These methods are used to set the initial values of
43  * solution components.
44  */
45  //@{
46 
47  /// Set initial guess based on equilibrium
48  void setInitialGuess(const std::string& component, vector_fp& locs,
49  vector_fp& vals);
50 
51  /**
52  * Set a single value in the solution vector.
53  * @param dom domain number, beginning with 0 for the leftmost domain.
54  * @param comp component number
55  * @param localPoint grid point within the domain, beginning with 0 for
56  * the leftmost grid point in the domain.
57  * @param value the value.
58  */
59  void setValue(size_t dom, size_t comp, size_t localPoint, doublereal value);
60 
61  /**
62  * Get one entry in the solution vector.
63  * @param dom domain number, beginning with 0 for the leftmost domain.
64  * @param comp component number
65  * @param localPoint grid point within the domain, beginning with 0 for
66  * the leftmost grid point in the domain.
67  */
68  doublereal value(size_t dom, size_t comp, size_t localPoint) const;
69 
70  doublereal workValue(size_t dom, size_t comp, size_t localPoint) const;
71 
72  /**
73  * Specify a profile for one component of one domain.
74  * @param dom domain number, beginning with 0 for the leftmost domain.
75  * @param comp component number
76  * @param pos A vector of relative positions, beginning with 0.0 at the
77  * left of the domain, and ending with 1.0 at the right of the domain.
78  * @param values A vector of values corresponding to the relative position
79  * locations.
80  *
81  * Note that the vector pos and values can have lengths different than the
82  * number of grid points, but their lengths must be equal. The values at
83  * the grid points will be linearly interpolated based on the (pos,
84  * values) specification.
85  */
86  void setProfile(size_t dom, size_t comp, const vector_fp& pos,
87  const vector_fp& values);
88 
89  /// Set component 'comp' of domain 'dom' to value 'v' at all points.
90  void setFlatProfile(size_t dom, size_t comp, doublereal v);
91 
92  //@}
93 
94  void save(const std::string& fname, const std::string& id,
95  const std::string& desc, int loglevel=1);
96 
97  void saveResidual(const std::string& fname, const std::string& id,
98  const std::string& desc, int loglevel=1);
99 
100  /// Print to stream s the current solution for all domains.
101  void showSolution(std::ostream& s);
102  void showSolution();
103 
104  const doublereal* solution() {
105  return DATA_PTR(m_x);
106  }
107 
108  void setTimeStep(doublereal stepsize, size_t n, integer* tsteps);
109 
110  //void setMaxTimeStep(doublereal tmax) { m_maxtimestep = tmax; }
111 
112  void solve(int loglevel = 0, bool refine_grid = true);
113 
114  void eval(doublereal rdt=-1.0, int count = 1) {
116  }
117 
118  /// Refine the grid in all domains.
119  int refine(int loglevel=0);
120 
121  //! Add node for fixed temperature point of freely propagating flame
122  int setFixedTemperature(doublereal t);
123 
124  /**
125  * Set grid refinement criteria. If dom >= 0, then the settings
126  * apply only to the specified domain. If dom < 0, the settings
127  * are applied to each domain. @see Refiner::setCriteria.
128  */
129  void setRefineCriteria(int dom = -1, doublereal ratio = 10.0,
130  doublereal slope = 0.8, doublereal curve = 0.8, doublereal prune = -0.1);
131  void setMaxGridPoints(int dom = -1, int npoints = 300);
132 
133  //! Set the minimum grid spacing in the specified domain(s).
134  /*!
135  * @param dom Domain index. If dom == -1, the specified spacing
136  is applied to all domains.
137  @param gridmin The minimum allowable grid spacing [m]
138  */
139  void setGridMin(int dom, double gridmin);
140 
141  //! Initialize the solution with a previously-saved solution.
142  void restore(const std::string& fname, const std::string& id, int loglevel=2);
143 
144  void getInitialSoln();
145 
146  void setSolution(const doublereal* soln) {
147  std::copy(soln, soln + m_x.size(), DATA_PTR(m_x));
148  }
149 
150  const doublereal* solution() const {
151  return DATA_PTR(m_x);
152  }
153 
154  doublereal jacobian(int i, int j);
155 
156  void evalSSJacobian();
157 
158 protected:
159  //! the solution vector
161 
162  //! a work array used to hold the residual or the new solution
164 
165  //! timestep
166  doublereal m_tstep;
167 
168  //! array of number of steps to take before re-attempting the steady-state
169  //! solution
171 
172 private:
173  /// Calls method _finalize in each domain.
174  void finalize();
175 
176  /*! Wrapper around the Newton solver.
177  * @return 0 if successful, -1 on failure
178  */
179  int newtonSolve(int loglevel);
180 };
181 
182 }
183 #endif
Container class for multiple-domain 1D problems.
Definition: OneDim.h:21
void restore(const std::string &fname, const std::string &id, int loglevel=2)
Initialize the solution with a previously-saved solution.
Definition: Sim1D.cpp:108
vector_fp m_x
the solution vector
Definition: Sim1D.h:160
doublereal value(size_t dom, size_t comp, size_t localPoint) const
Get one entry in the solution vector.
Definition: Sim1D.cpp:60
void eval(size_t j, double *x, double *r, doublereal rdt=-1.0, int count=1)
Evaluate the multi-domain residual function.
Definition: OneDim.cpp:232
MultiJac & jacobian()
Return a reference to the Jacobian evaluator.
Definition: OneDim.cpp:86
const size_t npos
index returned by functions to indicate "no position"
Definition: ct_defs.h:165
void setValue(size_t dom, size_t comp, size_t localPoint, doublereal value)
Set a single value in the solution vector.
Definition: Sim1D.cpp:51
void setRefineCriteria(int dom=-1, doublereal ratio=10.0, doublereal slope=0.8, doublereal curve=0.8, doublereal prune=-0.1)
Set grid refinement criteria.
Definition: Sim1D.cpp:514
void setInitialGuess(const std::string &component, vector_fp &locs, vector_fp &vals)
Set initial guess based on equilibrium.
Definition: Sim1D.cpp:38
vector_int m_steps
array of number of steps to take before re-attempting the steady-state solution
Definition: Sim1D.h:170
int newtonSolve(int loglevel)
Definition: Sim1D.cpp:201
doublereal rdt() const
Reciprocal of the time step.
Definition: OneDim.h:134
std::vector< int > vector_int
Vector of ints.
Definition: ct_defs.h:159
int setFixedTemperature(doublereal t)
Add node for fixed temperature point of freely propagating flame.
Definition: Sim1D.cpp:414
One-dimensional simulations.
Definition: Sim1D.h:18
void finalize()
Calls method _finalize in each domain.
Definition: Sim1D.cpp:185
doublereal m_tstep
timestep
Definition: Sim1D.h:166
void setFlatProfile(size_t dom, size_t comp, doublereal v)
Set component 'comp' of domain 'dom' to value 'v' at all points.
Definition: Sim1D.cpp:149
Sim1D()
Default constructor.
Definition: Sim1D.h:28
vector_fp m_xnew
a work array used to hold the residual or the new solution
Definition: Sim1D.h:163
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:157
int refine(int loglevel=0)
Refine the grid in all domains.
Definition: Sim1D.cpp:325
void setProfile(size_t dom, size_t comp, const vector_fp &pos, const vector_fp &values)
Specify a profile for one component of one domain.
Definition: Sim1D.cpp:78
#define DATA_PTR(vec)
Creates a pointer to the start of the raw data for a vector.
Definition: ct_defs.h:36
void setGridMin(int dom, double gridmin)
Set the minimum grid spacing in the specified domain(s).
Definition: Sim1D.cpp:528