Cantera 2.6.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 https://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 */
19 class MultiNewton
20{
21 public:
22 MultiNewton(int sz);
23 virtual ~MultiNewton() {};
24 MultiNewton(const MultiNewton&) = delete;
25 MultiNewton& operator=(const MultiNewton&) = delete;
26
27 size_t size() {
28 return m_n;
29 }
30
31 //! Compute the undamped Newton step. The residual function is evaluated
32 //! at `x`, but the Jacobian is not recomputed.
33 void step(doublereal* x, doublereal* step,
34 OneDim& r, MultiJac& jac, int loglevel);
35
36 /**
37 * Return the factor by which the undamped Newton step 'step0'
38 * must be multiplied in order to keep all solution components in
39 * all domains between their specified lower and upper bounds.
40 */
41 doublereal boundStep(const doublereal* x0, const doublereal* step0,
42 const OneDim& r, int loglevel);
43
44 /**
45 * On entry, step0 must contain an undamped Newton step for the solution x0.
46 * This method attempts to find a damping coefficient such that the next
47 * undamped step would have a norm smaller than that of step0. If
48 * successful, the new solution after taking the damped step is returned in
49 * x1, and the undamped step at x1 is returned in step1.
50 */
51 int dampStep(const doublereal* x0, const doublereal* step0,
52 doublereal* x1, doublereal* step1, doublereal& s1,
53 OneDim& r, MultiJac& jac, int loglevel, bool writetitle);
54
55 //! Compute the weighted 2-norm of `step`.
56 doublereal norm2(const doublereal* x, const doublereal* step,
57 OneDim& r) const;
58
59 /**
60 * Find the solution to F(X) = 0 by damped Newton iteration. On entry, x0
61 * contains an initial estimate of the solution. On successful return, x1
62 * contains the converged solution.
63 */
64 int solve(doublereal* x0, doublereal* x1, OneDim& r, MultiJac& jac,
65 int loglevel);
66
67 /// Set options.
68 void setOptions(int maxJacAge = 5) {
69 m_maxAge = maxJacAge;
70 }
71
72 /// Change the problem size.
73 void resize(size_t points);
74
75 protected:
76 //! Work arrays of size #m_n used in solve().
77 vector_fp m_x, m_stp, m_stp1;
78
79 int m_maxAge;
80
81 //! number of variables
82 size_t m_n;
83
84 doublereal m_elapsed;
85};
86}
87
88#endif
MultiJac.h
Cantera::MultiJac
Class MultiJac evaluates the Jacobian of a system of equations defined by a residual function supplie...
Definition: MultiJac.h:23
Cantera::MultiNewton
Newton iterator for multi-domain, one-dimensional problems.
Definition: MultiNewton.h:20
Cantera::MultiNewton::resize
void resize(size_t points)
Change the problem size.
Definition: MultiNewton.cpp:141
Cantera::MultiNewton::m_x
vector_fp m_x
Work arrays of size m_n used in solve().
Definition: MultiNewton.h:77
Cantera::MultiNewton::boundStep
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...
Definition: MultiNewton.cpp:196
Cantera::MultiNewton::dampStep
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.
Definition: MultiNewton.cpp:208
Cantera::MultiNewton::setOptions
void setOptions(int maxJacAge=5)
Set options.
Definition: MultiNewton.h:68
Cantera::MultiNewton::m_n
size_t m_n
number of variables
Definition: MultiNewton.h:82
Cantera::MultiNewton::solve
int solve(doublereal *x0, doublereal *x1, OneDim &r, MultiJac &jac, int loglevel)
Find the solution to F(X) = 0 by damped Newton iteration.
Definition: MultiNewton.cpp:289
Cantera::MultiNewton::norm2
doublereal norm2(const doublereal *x, const doublereal *step, OneDim &r) const
Compute the weighted 2-norm of step.
Definition: MultiNewton.cpp:149
Cantera::MultiNewton::step
void step(doublereal *x, doublereal *step, OneDim &r, MultiJac &jac, int loglevel)
Compute the undamped Newton step.
Definition: MultiNewton.cpp:162
Cantera::OneDim
Container class for multiple-domain 1D problems.
Definition: OneDim.h:27
Cantera
Namespace for the Cantera kernel.
Definition: AnyMap.cpp:557
Cantera::vector_fp
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:184