Cantera  2.1.2
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  //! Get a pointer to an array of length m_n for temporary work space.
79  doublereal* getWorkArray();
80 
81  //! Release a work array by pushing its pointer onto the stack of
82  //! available arrays.
83  void releaseWorkArray(doublereal* work);
84 
85  std::vector<doublereal*> m_workarrays;
86  int m_maxAge;
87  size_t m_nv, m_np, m_n;
88  doublereal m_elapsed;
89 
90 private:
91  char m_buf[100];
92 };
93 }
94 
95 #endif
Container class for multiple-domain 1D problems.
Definition: OneDim.h:22
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:26
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...
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.
void releaseWorkArray(doublereal *work)
Release a work array by pushing its pointer onto the stack of available arrays.
Newton iterator for multi-domain, one-dimensional problems.
Definition: MultiNewton.h:22
doublereal * getWorkArray()
Get a pointer to an array of length m_n for temporary work space.
void setOptions(int maxJacAge=5)
Set options.
Definition: MultiNewton.h:70