Reaktoro
A unified framework for modeling chemically reactive systems
Utils.hpp
1 // Reaktoro is a unified framework for modeling chemically reactive systems.
2 //
3 // Copyright (C) 2014-2018 Allan Leal
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library. If not, see <http://www.gnu.org/licenses/>.
17 
18 #pragma once
19 
20 // C++ includes
21 #include <functional>
22 
23 // Reaktoro includes
24 #include <Reaktoro/Math/Matrix.hpp>
25 
26 namespace Reaktoro {
27 
33 auto largestStep(VectorConstRef p, VectorConstRef dp) -> double;
34 
40 auto fractionToTheBoundary(VectorConstRef p, VectorConstRef dp, double tau) -> double;
41 
48 auto fractionToTheBoundary(VectorConstRef p, VectorConstRef dp, double tau, Index& ilimiting) -> double;
49 
57 auto fractionToTheBoundary(VectorConstRef p, VectorConstRef dp, MatrixConstRef C, VectorConstRef r, double tau) -> double;
58 
65 auto fractionToTheLowerBoundary(VectorConstRef p, VectorConstRef dp, VectorConstRef lower, double tau) -> double;
66 
76 auto lessThan(double a, double b, double baseval) -> bool;
77 
87 auto greaterThan(double a, double b, double baseval) -> bool;
88 
90 auto infinity() -> double;
91 
93 auto bfgs() -> std::function<Matrix(VectorConstRef, VectorConstRef)>;
94 
96 auto minimizeGoldenSectionSearch(const std::function<double(double)>& f, double a, double b, double tol = 1e-5) -> double;
97 
99 auto minimizeBrent(const std::function<double(double)>& f, double min, double max, double tolerance = 1e-5, unsigned maxiters = 100) -> double;
100 
101 } // namespace Reaktoro
auto infinity() -> double
Return the floating-point representation of positive infinity.
Definition: Utils.cpp:105
auto minimizeBrent(const std::function< double(double)> &f, double min, double max, double tolerance, unsigned maxiters) -> double
Calculate the minimum of a single variable function using the Brent algorithm.
Definition: Utils.cpp:201
The namespace containing all components of the Reaktoro library.
Definition: ChemicalScalar.hpp:24
auto lessThan(double lhs, double rhs, double baseval) -> bool
Compute the fraction-to-the-boundary step length given by:
Definition: Utils.cpp:93
auto greaterThan(double lhs, double rhs, double baseval) -> bool
Check if a float number is greater than another by a base value.
Definition: Utils.cpp:99
auto largestStep(VectorConstRef p, VectorConstRef dp) -> double
Compute the largest step length such that is on the lower bound .
Definition: Utils.cpp:25
std::size_t Index
Define a type that represents an index.
Definition: Index.hpp:26
Eigen::MatrixXd Matrix
Alias to Eigen type MatrixXd.
Definition: Matrix.hpp:42
auto bfgs() -> std::function< Matrix(VectorConstRef, VectorConstRef)>
Return an inverse Hessian function based on the BFGS Hessian approximation.
Definition: Utils.cpp:110
Eigen::Ref< const Eigen::MatrixXd > MatrixConstRef
Alias to Eigen type Ref<const MatrixXd>.
Definition: Matrix.hpp:44
Eigen::Ref< const Eigen::VectorXd > VectorConstRef
< Alias to Eigen type Ref<VectorXd>.
Definition: Matrix.hpp:31