Loading...
Searching...
No Matches
cubicEqn Class Reference

Container to encapsulate various operations for cubic equation of the forms with real coefficients: More...

#include <cubicEqn.H>

Inheritance diagram for cubicEqn:
Collaboration diagram for cubicEqn:

Public Types

enum  components { A , B , C , D }
 Component labeling enumeration. More...
Public Types inherited from VectorSpace< cubicEqn, scalar, 4 >
typedef VectorSpace< cubicEqn, scalar, Ncmpts > vsType
 VectorSpace type.
typedef scalar cmptType
 Component type.
typedef scalar magType
 Magnitude type.
typedef direction size_type
 The type to represent the size of a VectorSpace.
typedef scalar * iterator
 Random access iterator for traversing VectorSpace.
typedef const scalar * const_iterator
 Random access iterator for traversing VectorSpace.

Public Member Functions

 cubicEqn ()=default
 Default construct.
 cubicEqn (const Foam::zero)
 Construct initialized to zero.
 cubicEqn (const scalar a, const scalar b, const scalar c, const scalar d)
 Construct from components.
scalar a () const noexcept
scalar b () const noexcept
scalar c () const noexcept
scalar d () const noexcept
scalar & a () noexcept
scalar & b () noexcept
scalar & c () noexcept
scalar & d () noexcept
scalar value (const scalar x) const
 Evaluate the cubic equation at x.
scalar derivative (const scalar x) const
 Evaluate the derivative of the cubic equation at x.
scalar error (const scalar x) const
 Estimate the error of evaluation of the cubic equation at x.
Roots< 3 > roots () const
 Return the roots of the cubic equation with no particular order.
Public Member Functions inherited from VectorSpace< cubicEqn, scalar, 4 >
const Foam::VectorSpace< cubicEqn, scalar, Ncmpts >::template ConstBlock< SubVector, BStart > block () const
 VectorSpace ()=default
 Default construct.
const scalar & component (const direction) const
void replace (const direction, const scalar &)
const scalar * cdata () const noexcept
 Return const pointer to the first data element.
scalar * data () noexcept
 Return pointer to the first data element.
void fill (const scalar &s)
 Assign all components to given value.
const scalar & operator[] (const direction) const
void operator= (const VectorSpace< cubicEqn, scalar, Ncmpts > &)
void operator+= (const VectorSpace< cubicEqn, scalar, Ncmpts > &)
void operator-= (const VectorSpace< cubicEqn, scalar, Ncmpts > &)
void operator*= (const scalar)
void operator/= (const scalar)
iterator begin () noexcept
 Return an iterator (pointer) to begin of VectorSpace.
const_iterator cbegin () const noexcept
 Return const_iterator (const pointer) to begin of VectorSpace.
iterator end () noexcept
 Return an iterator (pointer) to end of VectorSpace.
const_iterator cend () const noexcept
 Return const_iterator (const pointer) to end of VectorSpace.

Additional Inherited Members

Static Public Member Functions inherited from VectorSpace< cubicEqn, scalar, 4 >
static constexpr direction size () noexcept
 The number of elements in the VectorSpace = Ncmpts.
static cubicEqn uniform (const scalar &s)
 Return a VectorSpace with all elements = s.
Public Attributes inherited from VectorSpace< cubicEqn, scalar, 4 >
scalar v_ [Ncmpts]
 The components of this vector space.
Static Public Attributes inherited from VectorSpace< cubicEqn, scalar, 4 >
static constexpr direction dim
 Dimensionality of space.
static constexpr direction nComponents
 Number of components in this vector space.
static constexpr direction mRows
static constexpr direction nCols
static const char *const typeName
static const char *const componentNames []
static const cubicEqn zero
static const cubicEqn one
static const cubicEqn max
static const cubicEqn min
static const cubicEqn rootMax
static const cubicEqn rootMin

Detailed Description

Container to encapsulate various operations for cubic equation of the forms with real coefficients:

\‍[    a*x^3 + b*x^2 + c*x + d = 0
      x^3 + B*x^2 + C*x + D = 0
\‍]

The following two substitutions into the above forms are used:

\‍[    x = t - B/3
    t = w - P/3/w
\‍]

This reduces the problem to a quadratic in w^3:

\‍[    w^6 + Q*w^3 - P = 0
\‍]

where Q and P are given in the code.

The properties of the cubic can be related to the properties of this quadratic in w^3.

If the quadratic eqn has two identical real roots at zero, three identical real roots exist in the cubic eqn.

If the quadratic eqn has two identical real roots at non-zero, two identical and one distinct real roots exist in the cubic eqn.

If the quadratic eqn has two complex roots (a complex conjugate pair), three distinct real roots exist in the cubic eqn.

If the quadratic eqn has two distinct real roots, one real root and two complex roots (a complex conjugate pair) exist in the cubic eqn.

The quadratic eqn is solved for the most numerically accurate value of w^3. See the quadraticEqn.H for details on how to pick a value. This single value of w^3 can yield up to three cube roots for w, which relate to the three solutions for x.

Only a single root, or pair of conjugate roots, is directly evaluated; the one, or ones with the lowest relative numerical error. Root identities are then used to recover the remaining roots, possibly utilising a quadratic and/or linear solution. This seems to be a good way of maintaining the accuracy of roots at very different magnitudes.

Reference:

    Kahan's algo. to compute 'p' using fused multiply-adds (tag:JML):
        Jeannerod, C. P., Louvet, N., & Muller, J. M. (2013).
        Further analysis of Kahan's algorithm for the accurate
        computation of 2× 2 determinants.
        Mathematics of Computation, 82(284), 2245-2264.
        DOI:10.1090/S0025-5718-2013-02679-8
See also
Test-cubicEqn.C
Source files

Definition at line 108 of file cubicEqn.H.

Member Enumeration Documentation

◆ components

enum components

Component labeling enumeration.

Enumerator

Definition at line 117 of file cubicEqn.H.

Constructor & Destructor Documentation

◆ cubicEqn() [1/3]

cubicEqn ( )
default

Default construct.

References a(), b(), c(), and d().

Referenced by cubicEqn().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cubicEqn() [2/3]

cubicEqn ( const Foam::zero )
inline

Construct initialized to zero.

Definition at line 23 of file cubicEqnI.H.

References cubicEqn(), VectorSpace< cubicEqn, scalar, 4 >::VectorSpace(), and VectorSpace< cubicEqn, scalar, 4 >::zero.

Here is the call graph for this function:

◆ cubicEqn() [3/3]

cubicEqn ( const scalar a,
const scalar b,
const scalar c,
const scalar d )
inline

Construct from components.

Definition at line 29 of file cubicEqnI.H.

References A, a(), B, b(), C, c(), D, d(), and VectorSpace< cubicEqn, scalar, 4 >::v_.

Here is the call graph for this function:

Member Function Documentation

◆ a() [1/2]

scalar a ( ) const
inlinenoexcept

Definition at line 148 of file cubicEqn.H.

References A, Foam::noexcept, and VectorSpace< cubicEqn, scalar, 4 >::v_.

Referenced by cubicEqn(), cubicEqn(), derivative(), error(), roots(), and value().

Here is the caller graph for this function:

◆ b() [1/2]

scalar b ( ) const
inlinenoexcept

Definition at line 149 of file cubicEqn.H.

References B, Foam::noexcept, and VectorSpace< cubicEqn, scalar, 4 >::v_.

Referenced by cubicEqn(), cubicEqn(), and roots().

Here is the caller graph for this function:

◆ c() [1/2]

scalar c ( ) const
inlinenoexcept

Definition at line 150 of file cubicEqn.H.

References C, Foam::noexcept, and VectorSpace< cubicEqn, scalar, 4 >::v_.

Referenced by cubicEqn(), cubicEqn(), derivative(), error(), roots(), and value().

Here is the caller graph for this function:

◆ d() [1/2]

scalar d ( ) const
inlinenoexcept

Definition at line 151 of file cubicEqn.H.

References D, Foam::noexcept, and VectorSpace< cubicEqn, scalar, 4 >::v_.

Referenced by cubicEqn(), cubicEqn(), error(), roots(), and value().

Here is the caller graph for this function:

◆ a() [2/2]

scalar & a ( )
inlinenoexcept

Definition at line 153 of file cubicEqn.H.

References A, Foam::noexcept, and VectorSpace< cubicEqn, scalar, 4 >::v_.

◆ b() [2/2]

scalar & b ( )
inlinenoexcept

Definition at line 154 of file cubicEqn.H.

References B, Foam::noexcept, and VectorSpace< cubicEqn, scalar, 4 >::v_.

◆ c() [2/2]

scalar & c ( )
inlinenoexcept

Definition at line 155 of file cubicEqn.H.

References C, Foam::noexcept, and VectorSpace< cubicEqn, scalar, 4 >::v_.

◆ d() [2/2]

scalar & d ( )
inlinenoexcept

Definition at line 156 of file cubicEqn.H.

References D, Foam::noexcept, and VectorSpace< cubicEqn, scalar, 4 >::v_.

◆ value()

Foam::scalar value ( const scalar x) const
inline

Evaluate the cubic equation at x.

Definition at line 46 of file cubicEqnI.H.

References a(), b, c(), d(), and x.

Referenced by particle< Type >::trackToMovingTri().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ derivative()

Foam::scalar derivative ( const scalar x) const
inline

Evaluate the derivative of the cubic equation at x.

Definition at line 52 of file cubicEqnI.H.

References a(), b, c(), and x.

Here is the call graph for this function:

◆ error()

Foam::scalar error ( const scalar x) const
inline

Estimate the error of evaluation of the cubic equation at x.

Definition at line 58 of file cubicEqnI.H.

References a(), b, c(), d(), Foam::mag(), Foam::magSqr(), and x.

Here is the call graph for this function:

◆ roots()

Foam::Roots< 3 > roots ( ) const

Return the roots of the cubic equation with no particular order.

if discriminant > 0: return three distinct real roots if discriminant < 0: return one real root and one complex root (one member of the complex conjugate pair) if discriminant = 0: return two identical roots, and one distinct real root if identical zero Hessian: return three identical real roots where the discriminant = - 4p^3 - 27q^2.

Definition at line 28 of file cubicEqn.C.

References a(), Foam::atan2(), b(), c(), Foam::cbrt(), Foam::roots::complex, Foam::cos(), d(), Foam::endl(), Foam::hypot(), Foam::Info, Foam::mag(), Foam::roots::nan, Foam::nl, p, Foam::roots::real, roots(), Foam::sign(), Foam::sin(), Foam::sqrt(), Foam::tab, Roots< N >::type(), and x.

Referenced by roots().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files:
  • src/OpenFOAM/primitives/polynomialEqns/cubicEqn/cubicEqn.H
  • src/OpenFOAM/primitives/polynomialEqns/cubicEqn/cubicEqn.C
  • src/OpenFOAM/primitives/polynomialEqns/cubicEqn/cubicEqnI.H