OGS
MathLib::CubicSolver Class Reference

Detailed Description

Definition at line 25 of file CubicRoots.h.

#include <CubicRoots.h>

Public Member Functions

 CubicSolver (const double a, const double b, const double c, const double d)
 
std::vector< double > solve ()
 
double smallestPositiveRealRoot ()
 

Private Attributes

double a_
 
double b_
 
double c_
 
double d_
 

Constructor & Destructor Documentation

◆ CubicSolver()

MathLib::CubicSolver::CubicSolver ( const double a,
const double b,
const double c,
const double d )
inline

Definition at line 28 of file CubicRoots.h.

29 : a_(a), b_(b), c_(c), d_(d)
30 {
31 if (std::abs(a_) < 1e-9)
32 {
33 OGS_FATAL("'a' must be non-zero for a cubic equation.");
34 }
35 }
#define OGS_FATAL(...)
Definition Error.h:26

References a_, and OGS_FATAL.

Member Function Documentation

◆ smallestPositiveRealRoot()

double MathLib::CubicSolver::smallestPositiveRealRoot ( )
inline

Definition at line 55 of file CubicRoots.h.

56 {
57 std::vector<double> const roots = solve();
58
59 auto positive_roots =
60 roots | ranges::views::filter([](double root) { return root > 0; });
61
62 // If no positive root exists, return NaN
63 if (ranges::empty(positive_roots))
64 {
65 return std::numeric_limits<double>::quiet_NaN();
66 }
67
68 return ranges::min(positive_roots);
69 }
std::vector< double > solve()
Definition CubicRoots.h:38

References solve().

Referenced by MaterialPropertyLib::PengRobinson::value().

◆ solve()

std::vector< double > MathLib::CubicSolver::solve ( )
inline

Definition at line 38 of file CubicRoots.h.

39 {
40 // Solve using Boost's cubic_roots
41 std::array<double, 3> const roots =
42 boost::math::tools::cubic_roots<double>(a_, b_, c_, d_);
43
44 std::vector<double> filtered_roots =
45 ranges::views::ref(roots) |
46 ranges::views::filter([](double const root)
47 { return !std::isnan(root); }) |
48 ranges::to<std::vector>();
49 ranges::sort(filtered_roots);
50
51 return filtered_roots;
52 }

References a_, b_, c_, and d_.

Referenced by smallestPositiveRealRoot().

Member Data Documentation

◆ a_

double MathLib::CubicSolver::a_
private

Definition at line 72 of file CubicRoots.h.

Referenced by CubicSolver(), and solve().

◆ b_

double MathLib::CubicSolver::b_
private

Definition at line 72 of file CubicRoots.h.

Referenced by solve().

◆ c_

double MathLib::CubicSolver::c_
private

Definition at line 72 of file CubicRoots.h.

Referenced by solve().

◆ d_

double MathLib::CubicSolver::d_
private

Definition at line 72 of file CubicRoots.h.

Referenced by solve().


The documentation for this class was generated from the following file: