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