| Cantera 3.0.0

Loading...
Searching...
No Matches
AdaptivePreconditioner.h
Go to the documentation of this file.
1/**
2 * @file AdaptivePreconditioner.h Declarations for the class
3 * AdaptivePreconditioner which is a child class of PreconditionerBase
4 * for preconditioners used by sundials
5 */
6
7// This file is part of Cantera. See License.txt in the top-level directory or
8// at https://cantera.org/license.txt for license and copyright information.
9
10#ifndef ADAPTIVEPRECONDITIONER_H
11#define ADAPTIVEPRECONDITIONER_H
12
13#include "cantera/numerics/PreconditionerBase.h"
14#include "cantera/numerics/eigen_sparse.h"
15#include "cantera/base/global.h"
16#include <iostream>
17
18 namespace Cantera
19{
20
21//! AdaptivePreconditioner a preconditioner designed for use with large
22//! mechanisms that leverages sparse solvers. It does this by pruning
23//! the preconditioner by a threshold value. It also neglects pressure
24//! dependence and third body contributions in its formation and has a
25//! finite difference approximation for temperature.
26 class AdaptivePreconditioner : public PreconditionerBase
27{
28 public:
29 AdaptivePreconditioner();
30
31 void initialize(size_t networkSize) override;
32
33 void reset() override {
34 m_precon_matrix.setZero();
35 m_jac_trips.clear();
36 };
37
38 void setup() override;
39
40 void solve(const size_t stateSize, double* rhs_vector, double* output) override;
41
42 void setValue(size_t row, size_t col, double value) override;
43
44 void stateAdjustment(vector<double>& state) override;
45
46 void updatePreconditioner() override;
47
48 //! Prune preconditioner elements
49 void prunePreconditioner();
50
51 //! Return semi-analytical Jacobian of an AdaptivePreconditioner object.
52 //! @ingroup derivGroup
53 Eigen::SparseMatrix<double> jacobian() {
54 Eigen::SparseMatrix<double> jacobian_mat(m_dim, m_dim);
55 jacobian_mat.setFromTriplets(m_jac_trips.begin(), m_jac_trips.end());
56 return jacobian_mat;
57 }
58
59 //! Return the internal preconditioner matrix
60 Eigen::SparseMatrix<double> matrix() {
61 updatePreconditioner();
62 return m_precon_matrix;
63 }
64
65 //! Get the threshold value for setting elements
66 double threshold() { return m_threshold; }
67
68 //! Get ILUT fill factor
69 double ilutFillFactor() { return m_fill_factor; }
70
71 //! Get ILUT drop tolerance
72 double ilutDropTol() { return m_drop_tol; }
73
74 //! Set the threshold value to compare elements against
75 //! @param threshold double value used in setting by threshold
76 void setThreshold(double threshold) {
77 m_threshold = threshold;
78 m_prune_precon = (threshold <= 0) ? false : true;
79 }
80
81 //! Set drop tolerance for ILUT
82 //! @param droptol double value used in setting solver drop tolerance
83 void setIlutDropTol(double droptol) {
84 m_drop_tol = droptol;
85 m_solver.setDroptol(droptol);
86 }
87
88 //! Set the fill factor for ILUT solver
89 //! @param fillFactor fill in factor for ILUT solver
90 void setIlutFillFactor(int fillFactor) {
91 m_fill_factor = fillFactor;
92 m_solver.setFillfactor(fillFactor);
93 }
94
95 //! Print preconditioner contents
96 void printPreconditioner() override;
97
98 //! Print jacobian contents
99 void printJacobian();
100
101 protected:
102 //! ILUT fill factor
103 double m_fill_factor = 0;
104
105 //! ILUT drop tolerance
106 double m_drop_tol = 0;
107
108 //! Vector of triples representing the jacobian used in preconditioning
109 vector<Eigen::Triplet<double>> m_jac_trips;
110
111 //! Storage of appropriately sized identity matrix for making the preconditioner
112 Eigen::SparseMatrix<double> m_identity;
113
114 //! Container that is the sparse preconditioner
115 Eigen::SparseMatrix<double> m_precon_matrix;
116
117 //! Solver used in solving the linear system
118 Eigen::IncompleteLUT<double> m_solver;
119
120 //! Minimum value a non-diagonal element must be to be included in
121 //! the preconditioner
122 double m_threshold = 0.0;
123
124 //! Bool set whether to prune the matrix or not
125 double m_prune_precon = true;
126};
127
128}
129
130#endif
PreconditionerBase.h
Declarations for the class PreconditionerBase which is a virtual base class for preconditioning syste...
Cantera::AdaptivePreconditioner
AdaptivePreconditioner a preconditioner designed for use with large mechanisms that leverages sparse ...
Definition AdaptivePreconditioner.h:27
Cantera::AdaptivePreconditioner::threshold
double threshold()
Get the threshold value for setting elements.
Definition AdaptivePreconditioner.h:66
Cantera::AdaptivePreconditioner::m_solver
Eigen::IncompleteLUT< double > m_solver
Solver used in solving the linear system.
Definition AdaptivePreconditioner.h:118
Cantera::AdaptivePreconditioner::ilutDropTol
double ilutDropTol()
Get ILUT drop tolerance.
Definition AdaptivePreconditioner.h:72
Cantera::AdaptivePreconditioner::matrix
Eigen::SparseMatrix< double > matrix()
Return the internal preconditioner matrix.
Definition AdaptivePreconditioner.h:60
Cantera::AdaptivePreconditioner::m_fill_factor
double m_fill_factor
ILUT fill factor.
Definition AdaptivePreconditioner.h:103
Cantera::AdaptivePreconditioner::setIlutDropTol
void setIlutDropTol(double droptol)
Set drop tolerance for ILUT.
Definition AdaptivePreconditioner.h:83
Cantera::AdaptivePreconditioner::m_drop_tol
double m_drop_tol
ILUT drop tolerance.
Definition AdaptivePreconditioner.h:106
Cantera::AdaptivePreconditioner::solve
void solve(const size_t stateSize, double *rhs_vector, double *output) override
Solve a linear system Ax=b where A is the preconditioner.
Definition AdaptivePreconditioner.cpp:96
Cantera::AdaptivePreconditioner::setValue
void setValue(size_t row, size_t col, double value) override
Set a value at the specified row and column of the jacobian triplet vector.
Definition AdaptivePreconditioner.cpp:17
Cantera::AdaptivePreconditioner::m_prune_precon
double m_prune_precon
Bool set whether to prune the matrix or not.
Definition AdaptivePreconditioner.h:125
Cantera::AdaptivePreconditioner::m_threshold
double m_threshold
Minimum value a non-diagonal element must be to be included in the preconditioner.
Definition AdaptivePreconditioner.h:122
Cantera::AdaptivePreconditioner::initialize
void initialize(size_t networkSize) override
Called during setup for any processes that need to be completed prior to setup functions used in sund...
Definition AdaptivePreconditioner.cpp:29
Cantera::AdaptivePreconditioner::m_jac_trips
vector< Eigen::Triplet< double > > m_jac_trips
Vector of triples representing the jacobian used in preconditioning.
Definition AdaptivePreconditioner.h:109
Cantera::AdaptivePreconditioner::setIlutFillFactor
void setIlutFillFactor(int fillFactor)
Set the fill factor for ILUT solver.
Definition AdaptivePreconditioner.h:90
Cantera::AdaptivePreconditioner::m_identity
Eigen::SparseMatrix< double > m_identity
Storage of appropriately sized identity matrix for making the preconditioner.
Definition AdaptivePreconditioner.h:112
Cantera::AdaptivePreconditioner::printPreconditioner
void printPreconditioner() override
Print preconditioner contents.
Definition AdaptivePreconditioner.cpp:110
Cantera::AdaptivePreconditioner::setup
void setup() override
Perform preconditioner specific post-reactor setup operations such as factorize.
Definition AdaptivePreconditioner.cpp:57
Cantera::AdaptivePreconditioner::stateAdjustment
void stateAdjustment(vector< double > &state) override
Adjust the state vector based on the preconditioner, e.g., Adaptive preconditioning uses a strictly p...
Definition AdaptivePreconditioner.cpp:22
Cantera::AdaptivePreconditioner::updatePreconditioner
void updatePreconditioner() override
Transform Jacobian vector and write into preconditioner, P = (I - gamma * J)
Definition AdaptivePreconditioner.cpp:72
Cantera::AdaptivePreconditioner::prunePreconditioner
void prunePreconditioner()
Prune preconditioner elements.
Definition AdaptivePreconditioner.cpp:84
Cantera::AdaptivePreconditioner::printJacobian
void printJacobian()
Print jacobian contents.
Definition AdaptivePreconditioner.cpp:117
Cantera::AdaptivePreconditioner::m_precon_matrix
Eigen::SparseMatrix< double > m_precon_matrix
Container that is the sparse preconditioner.
Definition AdaptivePreconditioner.h:115
Cantera::AdaptivePreconditioner::setThreshold
void setThreshold(double threshold)
Set the threshold value to compare elements against.
Definition AdaptivePreconditioner.h:76
Cantera::AdaptivePreconditioner::reset
void reset() override
Reset preconditioner parameters as needed.
Definition AdaptivePreconditioner.h:33
Cantera::AdaptivePreconditioner::ilutFillFactor
double ilutFillFactor()
Get ILUT fill factor.
Definition AdaptivePreconditioner.h:69
Cantera::PreconditionerBase
PreconditionerBase serves as an abstract type to extend different preconditioners.
Definition PreconditionerBase.h:31
Cantera::PreconditionerBase::m_dim
size_t m_dim
Dimension of the preconditioner.
Definition PreconditionerBase.h:117
global.h
This file contains definitions for utility functions and text for modules, inputfiles and logging,...
Cantera::AdaptivePreconditioner::jacobian
Eigen::SparseMatrix< double > jacobian()
Return semi-analytical Jacobian of an AdaptivePreconditioner object.
Definition AdaptivePreconditioner.h:53
Cantera
Namespace for the Cantera kernel.
Definition AnyMap.cpp:564