Cantera  2.2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MultiNewton.h
Go to the documentation of this file.
1 /**
2  * @file MultiNewton.h
3  */
4 
5 /*
6  * Copyright 2002 California Institute of Technology
7  */
8 
9 #ifndef CT_MULTINEWTON_H
10 #define CT_MULTINEWTON_H
11 
12 #include "MultiJac.h"
13 
14 namespace Cantera
15 {
16 
17 /**
18  * Newton iterator for multi-domain, one-dimensional problems.
19  * Used by class OneDim.
20  * @ingroup onedim
21  */
23 {
24 public:
25  MultiNewton(int sz);
26  virtual ~MultiNewton() {};
27 
28  size_t size() {
29  return m_n;
30  }
31 
32  //! Compute the undamped Newton step. The residual function is evaluated
33  //! at `x`, but the Jacobian is not recomputed.
34  void step(doublereal* x, doublereal* step,
35  OneDim& r, MultiJac& jac, int loglevel);
36 
37  /**
38  * Return the factor by which the undamped Newton step 'step0'
39  * must be multiplied in order to keep all solution components in
40  * all domains between their specified lower and upper bounds.
41  */
42  doublereal boundStep(const doublereal* x0, const doublereal* step0,
43  const OneDim& r, int loglevel);
44 
45  /**
46  * On entry, step0 must contain an undamped Newton step for the
47  * solution x0. This method attempts to find a damping coefficient
48  * such that the next undamped step would have a norm smaller than
49  * that of step0. If successful, the new solution after taking the
50  * damped step is returned in x1, and the undamped step at x1 is
51  * returned in step1.
52  */
53  int dampStep(const doublereal* x0, const doublereal* step0,
54  doublereal* x1, doublereal* step1, doublereal& s1,
55  OneDim& r, MultiJac& jac, int loglevel, bool writetitle);
56 
57  //! Compute the weighted 2-norm of `step`.
58  doublereal norm2(const doublereal* x, const doublereal* step,
59  OneDim& r) const;
60 
61  /**
62  * Find the solution to F(X) = 0 by damped Newton iteration. On
63  * entry, x0 contains an initial estimate of the solution. On
64  * successful return, x1 contains the converged solution.
65  */
66  int solve(doublereal* x0, doublereal* x1, OneDim& r, MultiJac& jac,
67  int loglevel);
68 
69  /// Set options.
70  void setOptions(int maxJacAge = 5) {
71  m_maxAge = maxJacAge;
72  }
73 
74  /// Change the problem size.
75  void resize(size_t points);
76 
77 protected:
78  //! Work arrays of size #m_n used in solve().
79  vector_fp m_x, m_stp, m_stp1;
80 
81  int m_maxAge;
82 
83  //! number of variables
84  size_t m_n;
85 
86  doublereal m_elapsed;
87 
88 private:
89  char m_buf[100];
90 };
91 }
92 
93 #endif
Container class for multiple-domain 1D problems.
Definition: OneDim.h:21
size_t m_n
number of variables
Definition: MultiNewton.h:84
void step(doublereal *x, doublereal *step, OneDim &r, MultiJac &jac, int loglevel)
Compute the undamped Newton step.
int solve(doublereal *x0, doublereal *x1, OneDim &r, MultiJac &jac, int loglevel)
Find the solution to F(X) = 0 by damped Newton iteration.
doublereal norm2(const doublereal *x, const doublereal *step, OneDim &r) const
Compute the weighted 2-norm of step.
void resize(size_t points)
Change the problem size.
Class MultiJac evaluates the Jacobian of a system of equations defined by a residual function supplie...
Definition: MultiJac.h:25
doublereal boundStep(const doublereal *x0, const doublereal *step0, const OneDim &r, int loglevel)
Return the factor by which the undamped Newton step 'step0' must be multiplied in order to keep all s...
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 dampStep(const doublereal *x0, const doublereal *step0, doublereal *x1, doublereal *step1, doublereal &s1, OneDim &r, MultiJac &jac, int loglevel, bool writetitle)
On entry, step0 must contain an undamped Newton step for the solution x0.
Newton iterator for multi-domain, one-dimensional problems.
Definition: MultiNewton.h:22
vector_fp m_x
Work arrays of size m_n used in solve().
Definition: MultiNewton.h:79
void setOptions(int maxJacAge=5)
Set options.
Definition: MultiNewton.h:70