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