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