https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Enumerations | Functions | Variables
MathUtils Namespace Reference

Enumerations

enum class  ComputeType { value , derivative }
 

Functions

 FactorizedRankTwoTensorOperatorMapUnary (log, log(eigval))
 
 FactorizedRankTwoTensorOperatorMapDerivativeUnary (dlog, log(eigval), 1/eigval)
 
 FactorizedRankTwoTensorOperatorMapUnary (exp, exp(eigval))
 
 FactorizedRankTwoTensorOperatorMapDerivativeUnary (dexp, exp(eigval), exp(eigval))
 
 FactorizedRankTwoTensorOperatorMapUnary (sqrt, sqrt(eigval))
 
 FactorizedRankTwoTensorOperatorMapDerivativeUnary (dsqrt, sqrt(eigval), pow(eigval, -1./2.)/2.)
 
 FactorizedRankTwoTensorOperatorMapUnary (cbrt, cbrt(eigval))
 
 FactorizedRankTwoTensorOperatorMapDerivativeUnary (dcbrt, cbrt(eigval), pow(eigval, -2./3.)/3.)
 
 FactorizedRankTwoTensorOperatorMapBinary (pow, pow(eigval, arg))
 
 FactorizedRankTwoTensorOperatorMapDerivativeBinary (dpow, pow(eigval, arg), arg *pow(eigval, arg - 1))
 
Real poly1Log (Real x, Real tol, unsigned int derivative_order)
 
Real poly2Log (Real x, Real tol, unsigned int derivative_order)
 
Real poly3Log (Real x, Real tol, unsigned int derivative_order)
 
Real poly4Log (Real x, Real tol, unsigned int derivative_order)
 
Real taylorLog (Real x)
 
Point barycentricToCartesian2D (const Point &p0, const Point &p1, const Point &p2, const Real b0, const Real b1, const Real b2)
 Evaluate Cartesian coordinates of any center point of a triangle given Barycentric coordinates of center point and Cartesian coordinates of triangle's vertices.
 
Point barycentricToCartesian3D (const Point &p0, const Point &p1, const Point &p2, const Point &p3, const Real b0, const Real b1, const Real b2, const Real b3)
 Evaluate Cartesian coordinates of any center point of a tetrahedron given Barycentric coordinates of center point and Cartesian coordinates of tetrahedon's vertices.
 
Point circumcenter2D (const Point &p0, const Point &p1, const Point &p2)
 Evaluate circumcenter of a triangle given three arbitrary points.
 
Point circumcenter3D (const Point &p0, const Point &p1, const Point &p2, const Point &p3)
 Evaluate circumcenter of a tetrahedrom given four arbitrary points.
 
template<typename T >
round (T x)
 
template<typename T >
sign (T x)
 
template<typename T >
pow (T x, int e)
 
template<typename T >
heavyside (T x)
 
template<typename T >
regularizedHeavyside (const T &x, Real smoothing_length)
 
template<typename T >
regularizedHeavysideDerivative (const T &x, Real smoothing_length)
 
template<typename T >
positivePart (T x)
 
template<typename T >
negativePart (T x)
 
template<typename T , typename T2 , typename T3 , typename std::enable_if< libMesh::ScalarTraits< T >::value &&libMesh::ScalarTraits< T2 >::value &&libMesh::ScalarTraits< T3 >::value, int >::type = 0>
void addScaled (const T &a, const T2 &b, T3 &result)
 
template<typename T , typename T2 , typename T3 , typename std::enable_if< libMesh::ScalarTraits< T >::value, int >::type = 0>
void addScaled (const T &scalar, const libMesh::NumericVector< T2 > &numeric_vector, libMesh::NumericVector< T3 > &result)
 
template<typename T , typename T2 , template< typename > class W, template< typename > class W2, typename std::enable_if< std::is_same< typename W< T >::index_type, unsigned int >::value &&std::is_same< typename W2< T2 >::index_type, unsigned int >::value, int >::type = 0>
libMesh::CompareTypes< T, T2 >::supertype dotProduct (const W< T > &a, const W2< T2 > &b)
 
template<typename C , typename T , typename R = typename libMesh::CompareTypes<typename C::value_type, T>::supertype>
poly (const C &c, const T x, const bool derivative=false)
 Evaluate a polynomial with the coefficients c at x.
 
template<typename C , typename T , typename R = typename libMesh::CompareTypes<typename C::value_type, T>::supertype>
polynomial (const C &c, const T x)
 Evaluate a polynomial with the coefficients c at x.
 
template<typename C , typename T , typename R = typename libMesh::CompareTypes<typename C::value_type, T>::supertype>
polynomialDerivative (const C &c, const T x)
 Returns the derivative of polynomial(c, x) with respect to x.
 
template<typename T , typename T2 >
clamp (const T &x, T2 lowerlimit, T2 upperlimit)
 
template<typename T , typename T2 >
smootherStep (T x, T2 start, T2 end, bool derivative=false)
 
template<ComputeType compute_type, typename X , typename S , typename E >
auto smootherStep (const X &x, const S &start, const E &end)
 
template<typename T >
void mooseSetToZero (T &v)
 Helper function templates to set a variable to zero.
 
template<typename T >
void mooseSetToZero (T *&)
 
template<>
void mooseSetToZero (std::vector< Real > &vec)
 
std::vector< std::vector< unsigned int > > multiIndex (unsigned int dim, unsigned int order)
 generate a complete multi index table for given dimension and order i.e.
 
template<ComputeType compute_type, typename X , typename X1 , typename X2 , typename Y1 , typename Y2 >
auto linearInterpolation (const X &x, const X1 &x1, const X2 &x2, const Y1 &y1, const Y2 &y2)
 
template<typename T1 , typename T2 >
std::size_t euclideanMod (T1 dividend, T2 divisor)
 perform modulo operator for Euclidean division that ensures a non-negative result
 
template<typename T >
gradName (const T &base_prop_name)
 automatic prefixing for naming material properties based on gradients of coupled variables/functors
 
template<typename T >
timeDerivName (const T &base_prop_name)
 automatic prefixing for naming material properties based on time derivatives of coupled variables/functors
 
void kron (RealEigenMatrix &product, const RealEigenMatrix &mat_A, const RealEigenMatrix &mat_B)
 Computes the Kronecker product of two matrices.
 
template<>
void mooseSetToZero< RankFourTensor > (RankFourTensor &v)
 Helper function template specialization to set an object to zero.
 
template<>
void mooseSetToZero< ADRankFourTensor > (ADRankFourTensor &v)
 
template<>
void mooseSetToZero< RankFourTensorTempl< Real > > (RankFourTensorTempl< Real > &v)
 
template<>
void mooseSetToZero< RankFourTensorTempl< ADReal > > (RankFourTensorTempl< ADReal > &v)
 
template<>
void mooseSetToZero< RankThreeTensorTempl< Real > > (RankThreeTensorTempl< Real > &v)
 Helper function template specialization to set an object to zero.
 
template<>
void mooseSetToZero< RankThreeTensorTempl< ADReal > > (RankThreeTensorTempl< ADReal > &v)
 
template<>
void mooseSetToZero< RankThreeTensor > (RankThreeTensor &v)
 
template<>
void mooseSetToZero< ADRankThreeTensor > (ADRankThreeTensor &v)
 
template<>
void mooseSetToZero< RankTwoTensor > (RankTwoTensor &v)
 Helper function template specialization to set an object to zero.
 
template<>
void mooseSetToZero< ADRankTwoTensor > (ADRankTwoTensor &v)
 Helper function template specialization to set an object to zero.
 
template<>
void mooseSetToZero< RankTwoTensor > (RankTwoTensor &v)
 Helper function template specialization to set an object to zero.
 
template<>
void mooseSetToZero< ADRankTwoTensor > (ADRankTwoTensor &v)
 Helper function template specialization to set an object to zero.
 
template<>
void mooseSetToZero< SymmetricRankFourTensor > (SymmetricRankFourTensor &v)
 Helper function template specialization to set an object to zero.
 
template<>
void mooseSetToZero< ADSymmetricRankFourTensor > (ADSymmetricRankFourTensor &v)
 
template<>
void mooseSetToZero< SymmetricRankFourTensorTempl< Real > > (SymmetricRankFourTensorTempl< Real > &v)
 
template<>
void mooseSetToZero< SymmetricRankFourTensorTempl< ADReal > > (SymmetricRankFourTensorTempl< ADReal > &v)
 
template<>
void mooseSetToZero< SymmetricRankTwoTensor > (SymmetricRankTwoTensor &v)
 Helper function template specialization to set an object to zero.
 
template<>
void mooseSetToZero< ADSymmetricRankTwoTensor > (ADSymmetricRankTwoTensor &v)
 Helper function template specialization to set an object to zero.
 
template<>
void mooseSetToZero< SymmetricRankTwoTensor > (SymmetricRankTwoTensor &v)
 Helper function template specialization to set an object to zero.
 
template<>
void mooseSetToZero< ADSymmetricRankTwoTensor > (ADSymmetricRankTwoTensor &v)
 Helper function template specialization to set an object to zero.
 
Real plainLog (Real x, unsigned int derivative_order)
 
template<>
void mooseSetToZero< RankFourTensor > (RankFourTensor &v)
 Helper function template specialization to set an object to zero.
 
template<>
void mooseSetToZero< ADRankFourTensor > (ADRankFourTensor &v)
 
template<>
void mooseSetToZero< RankThreeTensor > (RankThreeTensor &v)
 
template<>
void mooseSetToZero< ADRankThreeTensor > (ADRankThreeTensor &v)
 
template<>
void mooseSetToZero< RankTwoTensor > (RankTwoTensor &v)
 Helper function template specialization to set an object to zero.
 
template<>
void mooseSetToZero< ADRankTwoTensor > (ADRankTwoTensor &v)
 Helper function template specialization to set an object to zero.
 
template<>
void mooseSetToZero< SymmetricRankFourTensor > (SymmetricRankFourTensor &v)
 Helper function template specialization to set an object to zero.
 
template<>
void mooseSetToZero< ADSymmetricRankFourTensor > (ADSymmetricRankFourTensor &v)
 
template<>
void mooseSetToZero< SymmetricRankTwoTensor > (SymmetricRankTwoTensor &v)
 Helper function template specialization to set an object to zero.
 
template<>
void mooseSetToZero< ADSymmetricRankTwoTensor > (ADSymmetricRankTwoTensor &v)
 Helper function template specialization to set an object to zero.
 

Variables

static constexpr Real sqrt2 = 1.4142135623730951
 std::sqrt is not constexpr, so we add sqrt(2) as a constant (used in Mandel notation)
 

Enumeration Type Documentation

◆ ComputeType

enum class MathUtils::ComputeType
strong
Enumerator
value 
derivative 

Definition at line 339 of file MathUtils.h.

340{
341 value,
343};

Function Documentation

◆ addScaled() [1/2]

template<typename T , typename T2 , typename T3 , typename std::enable_if< libMesh::ScalarTraits< T >::value &&libMesh::ScalarTraits< T2 >::value &&libMesh::ScalarTraits< T3 >::value, int >::type = 0>
void MathUtils::addScaled ( const T &  a,
const T2 &  b,
T3 &  result 
)

Definition at line 175 of file MathUtils.h.

176{
177 result += a * b;
178}

Referenced by BDF2::computeTimeDerivativeHelper(), and NewmarkBeta::computeTimeDerivativeHelper().

◆ addScaled() [2/2]

template<typename T , typename T2 , typename T3 , typename std::enable_if< libMesh::ScalarTraits< T >::value, int >::type = 0>
void MathUtils::addScaled ( const T &  scalar,
const libMesh::NumericVector< T2 > &  numeric_vector,
libMesh::NumericVector< T3 > &  result 
)

Definition at line 185 of file MathUtils.h.

188{
189 result.add(scalar, numeric_vector);
190}
virtual void add(const numeric_index_type i, const T value)=0

◆ barycentricToCartesian2D()

Point MathUtils::barycentricToCartesian2D ( const Point &  p0,
const Point &  p1,
const Point &  p2,
const Real  b0,
const Real  b1,
const Real  b2 
)

Evaluate Cartesian coordinates of any center point of a triangle given Barycentric coordinates of center point and Cartesian coordinates of triangle's vertices.

Parameters
p0,p1,p2are the three non-collinear vertices in Cartesian coordinates
b0,b1,b2is the center point in barycentric coordinates with b0+b1+b2=1, e.g. (1/3,1/3,1/3) for a centroid
Returns
the center point of triangle in Cartesian coordinates

Definition at line 217 of file MathUtils.C.

223{
224 mooseAssert(!MooseUtils::isZero(b0 + b1 + b2 - 1.0), "Barycentric coordinates must sum to one!");
225
226 Point center;
227
228 for (unsigned int d = 0; d < 2; ++d)
229 center(d) = p0(d) * b0 + p1(d) * b1 + p2(d) * b2;
230 // p0, p1, p2 are vertices of triangle
231 // b0, b1, b2 are Barycentric coordinates of the triangle center
232
233 return center;
234}
Point center
Definition MortarUtils.C:58

Referenced by circumcenter2D().

◆ barycentricToCartesian3D()

Point MathUtils::barycentricToCartesian3D ( const Point &  p0,
const Point &  p1,
const Point &  p2,
const Point &  p3,
const Real  b0,
const Real  b1,
const Real  b2,
const Real  b3 
)

Evaluate Cartesian coordinates of any center point of a tetrahedron given Barycentric coordinates of center point and Cartesian coordinates of tetrahedon's vertices.

Parameters
p0,p1,p2,p3are the three non-coplanar vertices in Cartesian coordinates
b0,b1,b2,b3is the center point in barycentric coordinates with b0+b1+b2+b3=1, e.g. (1/4,1/4,1/4,1/4) for a centroid.
Returns
the center point of tetrahedron in Cartesian coordinates

Definition at line 237 of file MathUtils.C.

245{
246 mooseAssert(!MooseUtils::isZero(b0 + b1 + b2 + b3 - 1.0),
247 "Barycentric coordinates must sum to one!");
248
249 Point center;
250
251 for (unsigned int d = 0; d < 3; ++d)
252 center(d) = p0(d) * b0 + p1(d) * b1 + p2(d) * b2 + p3(d) * b3;
253 // p0, p1, p2, p3 are vertices of tetrahedron
254 // b0, b1, b2, b3 are Barycentric coordinates of the tetrahedron center
255
256 return center;
257}

Referenced by circumcenter3D().

◆ circumcenter2D()

Point MathUtils::circumcenter2D ( const Point &  p0,
const Point &  p1,
const Point &  p2 
)

Evaluate circumcenter of a triangle given three arbitrary points.

Parameters
p0,p1,p2are the three non-collinear vertices in Cartesian coordinates
Returns
the circumcenter in Cartesian coordinates

Definition at line 260 of file MathUtils.C.

261{
262 // Square of triangle edge lengths
263 Real edge01 = (p0 - p1).norm_sq();
264 Real edge02 = (p0 - p2).norm_sq();
265 Real edge12 = (p1 - p2).norm_sq();
266
267 // Barycentric weights for circumcenter
268 Real weight0 = edge12 * (edge01 + edge02 - edge12);
269 Real weight1 = edge02 * (edge01 + edge12 - edge02);
270 Real weight2 = edge01 * (edge02 + edge12 - edge01);
271
272 Real sum_weights = weight0 + weight1 + weight2;
273
274 // Check to make sure vertices are not collinear
275 if (MooseUtils::isZero(sum_weights))
276 mooseError("Cannot evaluate circumcenter. Points should be non-collinear.");
277
278 Real inv_sum_weights = 1.0 / sum_weights;
279
280 // Barycentric coordinates
281 Real b0 = weight0 * inv_sum_weights;
282 Real b1 = weight1 * inv_sum_weights;
283 Real b2 = weight2 * inv_sum_weights;
284
285 return MathUtils::barycentricToCartesian2D(p0, p1, p2, b0, b1, b2);
286}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
Point barycentricToCartesian2D(const Point &p0, const Point &p1, const Point &p2, const Real b0, const Real b1, const Real b2)
Evaluate Cartesian coordinates of any center point of a triangle given Barycentric coordinates of cen...
Definition MathUtils.C:217

◆ circumcenter3D()

Point MathUtils::circumcenter3D ( const Point &  p0,
const Point &  p1,
const Point &  p2,
const Point &  p3 
)

Evaluate circumcenter of a tetrahedrom given four arbitrary points.

Parameters
p0,p1,p2,p3are the four non-coplanar vertices in Cartesian coordinates
Returns
the circumcenter in Cartesian coordinates

Definition at line 289 of file MathUtils.C.

290{
291 // Square of tetrahedron edge lengths
292 Real edge01 = (p0 - p1).norm_sq();
293 Real edge02 = (p0 - p2).norm_sq();
294 Real edge03 = (p0 - p3).norm_sq();
295 Real edge12 = (p1 - p2).norm_sq();
296 Real edge13 = (p1 - p3).norm_sq();
297 Real edge23 = (p2 - p3).norm_sq();
298
299 // Barycentric weights for circumcenter
300 Real weight0 = -2 * edge12 * edge13 * edge23 + edge01 * edge23 * (edge13 + edge12 - edge23) +
301 edge02 * edge13 * (edge12 + edge23 - edge13) +
302 edge03 * edge12 * (edge13 + edge23 - edge12);
303 Real weight1 = -2 * edge02 * edge03 * edge23 + edge01 * edge23 * (edge02 + edge03 - edge23) +
304 edge13 * edge02 * (edge03 + edge23 - edge02) +
305 edge12 * edge03 * (edge02 + edge23 - edge03);
306 Real weight2 = -2 * edge01 * edge03 * edge13 + edge02 * edge13 * (edge01 + edge03 - edge13) +
307 edge23 * edge01 * (edge03 + edge13 - edge01) +
308 edge12 * edge03 * (edge01 + edge13 - edge03);
309 Real weight3 = -2 * edge01 * edge02 * edge12 + edge03 * edge12 * (edge01 + edge02 - edge12) +
310 edge23 * edge01 * (edge02 + edge12 - edge01) +
311 edge13 * edge02 * (edge01 + edge12 - edge02);
312
313 Real sum_weights = weight0 + weight1 + weight2 + weight3;
314
315 // Check to make sure vertices are not coplanar
316 if (MooseUtils::isZero(sum_weights))
317 mooseError("Cannot evaluate circumcenter. Points should be non-coplanar.");
318
319 Real inv_sum_weights = 1.0 / sum_weights;
320
321 // Barycentric coordinates
322 Real b0 = weight0 * inv_sum_weights;
323 Real b1 = weight1 * inv_sum_weights;
324 Real b2 = weight2 * inv_sum_weights;
325 Real b3 = weight3 * inv_sum_weights;
326
327 return MathUtils::barycentricToCartesian3D(p0, p1, p2, p3, b0, b1, b2, b3);
328}
Point barycentricToCartesian3D(const Point &p0, const Point &p1, const Point &p2, const Point &p3, const Real b0, const Real b1, const Real b2, const Real b3)
Evaluate Cartesian coordinates of any center point of a tetrahedron given Barycentric coordinates of ...
Definition MathUtils.C:237

◆ clamp()

template<typename T , typename T2 >
T MathUtils::clamp ( const T &  x,
T2  lowerlimit,
T2  upperlimit 
)

Definition at line 310 of file MathUtils.h.

311{
312 if (x < lowerlimit)
313 return lowerlimit;
314 if (x > upperlimit)
315 return upperlimit;
316 return x;
317}

◆ dotProduct()

template<typename T , typename T2 , template< typename > class W, template< typename > class W2, typename std::enable_if< std::is_same< typename W< T >::index_type, unsigned int >::value &&std::is_same< typename W2< T2 >::index_type, unsigned int >::value, int >::type = 0>
libMesh::CompareTypes< T, T2 >::supertype MathUtils::dotProduct ( const W< T > &  a,
const W2< T2 > &  b 
)

Definition at line 201 of file MathUtils.h.

202{
203 return a * b;
204}

Referenced by ADKernelGradTempl< T >::computeResidual(), and ADKernelGradTempl< T >::computeResidualsForJacobian().

◆ euclideanMod()

template<typename T1 , typename T2 >
std::size_t MathUtils::euclideanMod ( T1  dividend,
T2  divisor 
)

perform modulo operator for Euclidean division that ensures a non-negative result

Parameters
dividenddividend of the modulo operation
divisordivisor of the modulo operation
Returns
the non-negative remainder when the dividend is divided by the divisor

Definition at line 435 of file MathUtils.h.

436{
437 return (dividend % divisor + divisor) % divisor;
438}

Referenced by MooseMeshElementConversionUtils::convertPyramid5Elem(), MooseMeshElementConversionUtils::createUnitTet4FromHex8(), and MooseMeshElementConversionUtils::createUnitTet4FromPrism6().

◆ FactorizedRankTwoTensorOperatorMapBinary()

MathUtils::FactorizedRankTwoTensorOperatorMapBinary ( pow  ,
pow(eigval, arg)   
)
private

◆ FactorizedRankTwoTensorOperatorMapDerivativeBinary()

MathUtils::FactorizedRankTwoTensorOperatorMapDerivativeBinary ( dpow  ,
pow(eigval, arg)  ,
arg *  poweigval, arg - 1 
)
private

◆ FactorizedRankTwoTensorOperatorMapDerivativeUnary() [1/4]

MathUtils::FactorizedRankTwoTensorOperatorMapDerivativeUnary ( dcbrt  ,
cbrt(eigval)  ,
pow(eigval, -2./3.)/  3. 
)
private

◆ FactorizedRankTwoTensorOperatorMapDerivativeUnary() [2/4]

MathUtils::FactorizedRankTwoTensorOperatorMapDerivativeUnary ( dexp  ,
exp(eigval)  ,
exp(eigval)   
)
private

◆ FactorizedRankTwoTensorOperatorMapDerivativeUnary() [3/4]

MathUtils::FactorizedRankTwoTensorOperatorMapDerivativeUnary ( dlog  ,
log(eigval)  ,
1/  eigval 
)
private

◆ FactorizedRankTwoTensorOperatorMapDerivativeUnary() [4/4]

MathUtils::FactorizedRankTwoTensorOperatorMapDerivativeUnary ( dsqrt  ,
sqrt(eigval)  ,
pow(eigval, -1./2.)/  2. 
)
private

◆ FactorizedRankTwoTensorOperatorMapUnary() [1/4]

MathUtils::FactorizedRankTwoTensorOperatorMapUnary ( cbrt  ,
cbrt(eigval)   
)
private

◆ FactorizedRankTwoTensorOperatorMapUnary() [2/4]

MathUtils::FactorizedRankTwoTensorOperatorMapUnary ( exp  ,
exp(eigval)   
)
private

◆ FactorizedRankTwoTensorOperatorMapUnary() [3/4]

MathUtils::FactorizedRankTwoTensorOperatorMapUnary ( log  ,
log(eigval)   
)
private

◆ FactorizedRankTwoTensorOperatorMapUnary() [4/4]

MathUtils::FactorizedRankTwoTensorOperatorMapUnary ( sqrt  ,
sqrt(eigval)   
)
private

◆ gradName()

template<typename T >
T MathUtils::gradName ( const T &  base_prop_name)

automatic prefixing for naming material properties based on gradients of coupled variables/functors

Definition at line 446 of file MathUtils.h.

447{
448 return "grad_" + base_prop_name;
449}

Referenced by GenericFunctorMaterialTempl< is_ad >::GenericFunctorMaterialTempl().

◆ heavyside()

template<typename T >
T MathUtils::heavyside ( x)

Definition at line 120 of file MathUtils.h.

121{
122 return x < 0.0 ? 0.0 : 1.0;
123}

◆ kron()

void MathUtils::kron ( RealEigenMatrix &  product,
const RealEigenMatrix &  mat_A,
const RealEigenMatrix &  mat_B 
)

Computes the Kronecker product of two matrices.

Parameters
productReference to the product matrix
mat_AReference to the first matrix
mat_BReference to the other matrix

Definition at line 17 of file MathUtils.C.

18{
19 product.resize(mat_A.rows() * mat_B.rows(), mat_A.cols() * mat_B.cols());
20 for (unsigned int i = 0; i < mat_A.rows(); i++)
21 for (unsigned int j = 0; j < mat_A.cols(); j++)
22 for (unsigned int k = 0; k < mat_B.rows(); k++)
23 for (unsigned int l = 0; l < mat_B.cols(); l++)
24 product(((i * mat_B.rows()) + k), ((j * mat_B.cols()) + l)) = mat_A(i, j) * mat_B(k, l);
25}

◆ linearInterpolation()

template<ComputeType compute_type, typename X , typename X1 , typename X2 , typename Y1 , typename Y2 >
auto MathUtils::linearInterpolation ( const X &  x,
const X1 &  x1,
const X2 &  x2,
const Y1 &  y1,
const Y2 &  y2 
)

Definition at line 418 of file MathUtils.h.

419{
420 const auto m = (y2 - y1) / (x2 - x1);
421 if constexpr (compute_type == ComputeType::derivative)
422 return m;
423 if constexpr (compute_type == ComputeType::value)
424 return m * (x - x1) + y1;
425}

◆ mooseSetToZero() [1/3]

template<>
void MathUtils::mooseSetToZero ( std::vector< Real > &  vec)
inline

Definition at line 391 of file MathUtils.h.

392{
393 for (auto & v : vec)
394 v = 0.;
395}

◆ mooseSetToZero() [2/3]

template<typename T >
void MathUtils::mooseSetToZero ( T &  v)
inline

Helper function templates to set a variable to zero.

Specializations may have to be implemented (for examples see RankTwoTensor, RankFourTensor).

The default for non-pointer types is to assign zero. This should either do something sensible, or throw a compiler error. Otherwise the T type is designed badly.

Definition at line 373 of file MathUtils.h.

374{
380 v = 0;
381}

Referenced by MaterialBase::getGenericZeroMaterialProperty(), MaterialPropertyInterface::getGenericZeroMaterialProperty(), and MaterialBase::getGenericZeroMaterialPropertyByName().

◆ mooseSetToZero() [3/3]

template<typename T >
void MathUtils::mooseSetToZero ( T *&  )
inline

Definition at line 384 of file MathUtils.h.

385{
386 mooseError("mooseSetToZero does not accept pointers");
387}

◆ mooseSetToZero< ADRankFourTensor >() [1/2]

Definition at line 24 of file RankFourTensor.C.

26{
27 v.zero();
28}
void zero()
Zeros out the tensor.

◆ mooseSetToZero< ADRankFourTensor >() [2/2]

Definition at line 24 of file RankFourTensor.C.

26{
27 v.zero();
28}

◆ mooseSetToZero< ADRankThreeTensor >() [1/2]

Definition at line 25 of file RankThreeTensor.C.

27{
28 v.zero();
29}
void zero()
Zeros out the tensor.

◆ mooseSetToZero< ADRankThreeTensor >() [2/2]

Definition at line 25 of file RankThreeTensor.C.

27{
28 v.zero();
29}

◆ mooseSetToZero< ADRankTwoTensor >() [1/3]

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 25 of file RankTwoTensor.C.

27{
28 v.zero();
29}

◆ mooseSetToZero< ADRankTwoTensor >() [2/3]

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 25 of file RankTwoTensor.C.

27{
28 v.zero();
29}

◆ mooseSetToZero< ADRankTwoTensor >() [3/3]

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 25 of file RankTwoTensor.C.

27{
28 v.zero();
29}

◆ mooseSetToZero< ADSymmetricRankFourTensor >() [1/2]

Definition at line 24 of file SymmetricRankFourTensor.C.

26{
27 v.zero();
28}

◆ mooseSetToZero< ADSymmetricRankFourTensor >() [2/2]

Definition at line 24 of file SymmetricRankFourTensor.C.

26{
27 v.zero();
28}

◆ mooseSetToZero< ADSymmetricRankTwoTensor >() [1/3]

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 25 of file SymmetricRankTwoTensor.C.

27{
28 v.zero();
29}

◆ mooseSetToZero< ADSymmetricRankTwoTensor >() [2/3]

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 25 of file SymmetricRankTwoTensor.C.

27{
28 v.zero();
29}

◆ mooseSetToZero< ADSymmetricRankTwoTensor >() [3/3]

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 25 of file SymmetricRankTwoTensor.C.

27{
28 v.zero();
29}

◆ mooseSetToZero< RankFourTensor >() [1/2]

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 18 of file RankFourTensor.C.

20{
21 v.zero();
22}

◆ mooseSetToZero< RankFourTensor >() [2/2]

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 18 of file RankFourTensor.C.

20{
21 v.zero();
22}

◆ mooseSetToZero< RankFourTensorTempl< ADReal > >()

◆ mooseSetToZero< RankFourTensorTempl< Real > >()

template<>
void MathUtils::mooseSetToZero< RankFourTensorTempl< Real > > ( RankFourTensorTempl< Real > &  v)

◆ mooseSetToZero< RankThreeTensor >() [1/2]

Definition at line 18 of file RankThreeTensor.C.

20{
21 v.zero();
22}

◆ mooseSetToZero< RankThreeTensor >() [2/2]

Definition at line 18 of file RankThreeTensor.C.

20{
21 v.zero();
22}

◆ mooseSetToZero< RankThreeTensorTempl< ADReal > >()

◆ mooseSetToZero< RankThreeTensorTempl< Real > >()

template<>
void MathUtils::mooseSetToZero< RankThreeTensorTempl< Real > > ( RankThreeTensorTempl< Real > &  v)

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

◆ mooseSetToZero< RankTwoTensor >() [1/3]

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 18 of file RankTwoTensor.C.

20{
21 v.zero();
22}

◆ mooseSetToZero< RankTwoTensor >() [2/3]

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 18 of file RankTwoTensor.C.

20{
21 v.zero();
22}

◆ mooseSetToZero< RankTwoTensor >() [3/3]

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 18 of file RankTwoTensor.C.

20{
21 v.zero();
22}

◆ mooseSetToZero< SymmetricRankFourTensor >() [1/2]

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 18 of file SymmetricRankFourTensor.C.

20{
21 v.zero();
22}

◆ mooseSetToZero< SymmetricRankFourTensor >() [2/2]

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 18 of file SymmetricRankFourTensor.C.

20{
21 v.zero();
22}

◆ mooseSetToZero< SymmetricRankFourTensorTempl< ADReal > >()

◆ mooseSetToZero< SymmetricRankFourTensorTempl< Real > >()

◆ mooseSetToZero< SymmetricRankTwoTensor >() [1/3]

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 18 of file SymmetricRankTwoTensor.C.

20{
21 v.zero();
22}

◆ mooseSetToZero< SymmetricRankTwoTensor >() [2/3]

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 18 of file SymmetricRankTwoTensor.C.

20{
21 v.zero();
22}

◆ mooseSetToZero< SymmetricRankTwoTensor >() [3/3]

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 18 of file SymmetricRankTwoTensor.C.

20{
21 v.zero();
22}

◆ multiIndex()

std::vector< std::vector< unsigned int > > MathUtils::multiIndex ( unsigned int  dim,
unsigned int  order 
)

generate a complete multi index table for given dimension and order i.e.

given dim = 2, order = 2, generated table will have the following content 0 0 1 0 0 1 2 0 1 1 0 2 The first number in each entry represents the order of the first variable, i.e. x; The second number in each entry represents the order of the second variable, i.e. y. Multiplication is implied between numbers in each entry, i.e. 1 1 represents x^1 * y^1

Parameters
dimdimension of the multi-index, here dim = mesh dimension
ordergenerate the multi-index up to certain order
Returns
a data structure holding entries representing the complete multi index

Definition at line 186 of file MathUtils.C.

187{
188 // first row all zero
189 std::vector<std::vector<unsigned int>> multi_index;
190 std::vector<std::vector<unsigned int>> n_choose_k;
191 std::vector<unsigned int> row(dim, 0);
192 multi_index.push_back(row);
193
194 if (dim == 1)
195 for (unsigned int q = 1; q <= order; q++)
196 {
197 row[0] = q;
198 multi_index.push_back(row);
199 }
200 else
201 for (unsigned int q = 1; q <= order; q++)
202 {
203 n_choose_k = multiIndexHelper(dim + q - 1, dim - 1);
204 for (unsigned int r = 0; r < n_choose_k.size(); r++)
205 {
206 row.clear();
207 for (unsigned int c = 1; c < n_choose_k[0].size(); c++)
208 row.push_back(n_choose_k[r][c] - n_choose_k[r][c - 1] - 1);
209 multi_index.push_back(row);
210 }
211 }
212
213 return multi_index;
214}
std::vector< std::vector< unsigned int > > multiIndexHelper(unsigned int N, unsigned int K)
A helper function for MathUtils::multiIndex.
Definition MathUtils.C:333

◆ negativePart()

template<typename T >
T MathUtils::negativePart ( x)

Definition at line 162 of file MathUtils.h.

163{
164 return x < 0.0 ? x : 0.0;
165}

◆ plainLog()

Real MathUtils::plainLog ( Real  x,
unsigned int  derivative_order 
)

Definition at line 28 of file MathUtils.C.

29{
30 switch (derivative_order)
31 {
32 case 0:
33 return std::log(x);
34
35 case 1:
36 return 1.0 / x;
37
38 case 2:
39 return -1.0 / (x * x);
40
41 case 3:
42 return 2.0 / (x * x * x);
43 }
44
45 mooseError("Unsupported derivative order ", derivative_order);
46}

Referenced by poly1Log(), poly2Log(), poly3Log(), and poly4Log().

◆ poly()

template<typename C , typename T , typename R = typename libMesh::CompareTypes<typename C::value_type, T>::supertype>
R MathUtils::poly ( const C &  c,
const T  x,
const bool  derivative = false 
)

Evaluate a polynomial with the coefficients c at x.

Note that the Polynomial form is c[0]*x^s + c[1]*x^(s-1) + c[2]*x^(s-2) + ... + c[s-2]*x^2 + c[s-1]*x + c[s] where s = c.size()-1 , which is counter intuitive!

This function will be DEPRECATED soon (10/22/2020)

The coefficient container type can be any container that provides an index operator [] and a .size() method (e.g. std::vector, std::array). The return type is the supertype of the container value type and the argument x. The supertype is the type that can represent both number types.

Definition at line 238 of file MathUtils.h.

239{
240 const auto size = c.size();
241 if (size == 0)
242 return 0.0;
243
244 R value = c[0];
245 if (derivative)
246 {
247 value *= size - 1;
248 for (std::size_t i = 1; i < size - 1; ++i)
249 value = value * x + c[i] * (size - i - 1);
250 }
251 else
252 {
253 for (std::size_t i = 1; i < size; ++i)
254 value = value * x + c[i];
255 }
256
257 return value;
258}
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

◆ poly1Log()

Real MathUtils::poly1Log ( Real  x,
Real  tol,
unsigned int  derivative_order 
)

Definition at line 49 of file MathUtils.C.

50{
51 if (x >= tol)
52 return plainLog(x, derivative_order);
53
54 const auto c1 = [&]() { return 1.0 / tol; };
55 const auto c2 = [&]() { return std::log(tol) - 1.0; };
56
57 switch (derivative_order)
58 {
59 case 0:
60 return c1() * x + c2();
61
62 case 1:
63 return c1();
64
65 case 2:
66 return 0.0;
67
68 case 3:
69 return 0.0;
70 }
71
72 mooseError("Unsupported derivative order ", derivative_order);
73}
Real plainLog(Real x, unsigned int derivative_order)
Definition MathUtils.C:28

◆ poly2Log()

Real MathUtils::poly2Log ( Real  x,
Real  tol,
unsigned int  derivative_order 
)

Definition at line 76 of file MathUtils.C.

77{
78 if (x >= tol)
79 return plainLog(x, derivative_order);
80
81 const auto c1 = [&]() { return -0.5 / (tol * tol); };
82 const auto c2 = [&]() { return 2.0 / tol; };
83 const auto c3 = [&]() { return std::log(tol) - 3.0 / 2.0; };
84
85 switch (derivative_order)
86 {
87 case 0:
88 return c1() * x * x + c2() * x + c3();
89
90 case 1:
91 return 2.0 * c1() * x + c2();
92
93 case 2:
94 return 2.0 * c1();
95
96 case 3:
97 return 0.0;
98 }
99
100 mooseError("Unsupported derivative order ", derivative_order);
101}

◆ poly3Log()

Real MathUtils::poly3Log ( Real  x,
Real  tol,
unsigned int  derivative_order 
)

Definition at line 104 of file MathUtils.C.

105{
106 if (x >= tol)
107 return plainLog(x, derivative_order);
108
109 const auto c1 = [&]() { return 1.0 / (3.0 * tol * tol * tol); };
110 const auto c2 = [&]() { return -3.0 / (2.0 * tol * tol); };
111 const auto c3 = [&]() { return 3.0 / tol; };
112 const auto c4 = [&]() { return std::log(tol) - 11.0 / 6.0; };
113
114 switch (derivative_order)
115 {
116 case 0:
117 return c1() * x * x * x + c2() * x * x + c3() * x + c4();
118
119 case 1:
120 return 3.0 * c1() * x * x + 2.0 * c2() * x + c3();
121
122 case 2:
123 return 6.0 * c1() * x + 2.0 * c2();
124
125 case 3:
126 return 6.0 * c1();
127 }
128
129 mooseError("Unsupported derivative order ", derivative_order);
130}

◆ poly4Log()

Real MathUtils::poly4Log ( Real  x,
Real  tol,
unsigned int  derivative_order 
)

Definition at line 133 of file MathUtils.C.

134{
135 if (x >= tol)
136 return plainLog(x, derivative_order);
137
138 switch (derivative_order)
139 {
140 case 0:
141 return std::log(tol) + (x - tol) / tol -
142 Utility::pow<2>(x - tol) / (2.0 * Utility::pow<2>(tol)) +
143 Utility::pow<3>(x - tol) / (3.0 * Utility::pow<3>(tol)) -
144 Utility::pow<4>(x - tol) / (4.0 * Utility::pow<4>(tol)) +
145 Utility::pow<5>(x - tol) / (5.0 * Utility::pow<5>(tol)) -
146 Utility::pow<6>(x - tol) / (6.0 * Utility::pow<6>(tol));
147
148 case 1:
149 return 1.0 / tol - (x - tol) / Utility::pow<2>(tol) +
150 Utility::pow<2>(x - tol) / Utility::pow<3>(tol) -
151 Utility::pow<3>(x - tol) / Utility::pow<4>(tol) +
152 Utility::pow<4>(x - tol) / Utility::pow<5>(tol) -
153 Utility::pow<5>(x - tol) / Utility::pow<6>(tol);
154
155 case 2:
156 return -1.0 / Utility::pow<2>(tol) + 2.0 * (x - tol) / Utility::pow<3>(tol) -
157 3.0 * Utility::pow<2>(x - tol) / Utility::pow<4>(tol) +
158 4.0 * Utility::pow<3>(x - tol) / Utility::pow<5>(tol) -
159 5.0 * Utility::pow<4>(x - tol) / Utility::pow<6>(tol);
160
161 case 3:
162 return 2.0 / Utility::pow<3>(tol) - 6.0 * (x - tol) / Utility::pow<4>(tol) +
163 12.0 * Utility::pow<2>(x - tol) / Utility::pow<5>(tol) -
164 20.0 * Utility::pow<3>(x - tol) / Utility::pow<6>(tol);
165 }
166
167 mooseError("Unsupported derivative order ", derivative_order);
168}

◆ polynomial()

template<typename C , typename T , typename R = typename libMesh::CompareTypes<typename C::value_type, T>::supertype>
R MathUtils::polynomial ( const C &  c,
const T  x 
)

Evaluate a polynomial with the coefficients c at x.

Note that the Polynomial form is c[0] + c[1] * x + c[2] * x^2 + ... The coefficient container type can be any container that provides an index operator [] and a .size() method (e.g. std::vector, std::array). The return type is the supertype of the container value type and the argument x. The supertype is the type that can represent both number types.

Definition at line 273 of file MathUtils.h.

274{
275 auto size = c.size();
276 if (size == 0)
277 return 0.0;
278
279 size--;
280 R value = c[size];
281 for (std::size_t i = 1; i <= size; ++i)
282 value = value * x + c[size - i];
283
284 return value;
285}

◆ polynomialDerivative()

template<typename C , typename T , typename R = typename libMesh::CompareTypes<typename C::value_type, T>::supertype>
R MathUtils::polynomialDerivative ( const C &  c,
const T  x 
)

Returns the derivative of polynomial(c, x) with respect to x.

Definition at line 294 of file MathUtils.h.

295{
296 auto size = c.size();
297 if (size <= 1)
298 return 0.0;
299
300 size--;
301 R value = c[size] * size;
302 for (std::size_t i = 1; i < size; ++i)
303 value = value * x + c[size - i] * (size - i);
304
305 return value;
306}

◆ positivePart()

template<typename T >
T MathUtils::positivePart ( x)

Definition at line 155 of file MathUtils.h.

156{
157 return x > 0.0 ? x : 0.0;
158}

◆ pow()

template<typename T >
T MathUtils::pow ( x,
int  e 
)

Definition at line 91 of file MathUtils.h.

92{
93 bool neg = false;
94 T result = 1.0;
95
96 if (e < 0)
97 {
98 neg = true;
99 e = -e;
100 }
101
102 while (e)
103 {
104 // if bit 0 is set multiply the current power of two factor of the exponent
105 if (e & 1)
106 result *= x;
107
108 // x is incrementally set to consecutive powers of powers of two
109 x *= x;
110
111 // bit shift the exponent down
112 e >>= 1;
113 }
114
115 return neg ? 1.0 / result : result;
116}

Referenced by SurfaceMeshGeneratorBase::elementSatisfiesRequirements(), ProjectedStatefulMaterialNodalPatchRecoveryTempl< T, is_ad >::evaluateBasisFunctions(), PolynomialFit::fillMatrix(), AdvancedExtruderGenerator::radialExpansionRatio(), BicubicInterpolation::sample2ndDerivative(), BicubicInterpolation::sampleDerivative(), BicubicInterpolation::sampleInternal(), BicubicInterpolation::sampleValueAndDerivativesInternal(), and PseudoTimestep::timestepEXP().

◆ regularizedHeavyside()

template<typename T >
T MathUtils::regularizedHeavyside ( const T &  x,
Real  smoothing_length 
)

Definition at line 127 of file MathUtils.h.

128{
129 if (x <= -smoothing_length)
130 return 0.0;
131 else if (x < smoothing_length)
132 {
133 using std::sin;
134 return 0.5 * (1 + sin(libMesh::pi * x / 2 / smoothing_length));
135 }
136 else
137 return 1.0;
138}
const Real pi

◆ regularizedHeavysideDerivative()

template<typename T >
T MathUtils::regularizedHeavysideDerivative ( const T &  x,
Real  smoothing_length 
)

Definition at line 142 of file MathUtils.h.

143{
144 if (x < smoothing_length && x > -smoothing_length)
145 {
146 using std::cos;
147 return 0.25 * libMesh::pi / smoothing_length * (cos(libMesh::pi * x / 2 / smoothing_length));
148 }
149 else
150 return 0.0;
151}

◆ round()

template<typename T >
T MathUtils::round ( x)

Definition at line 77 of file MathUtils.h.

78{
79 return ::round(x); // use round from math.h
80}

◆ sign()

template<typename T >
T MathUtils::sign ( x)

Definition at line 84 of file MathUtils.h.

85{
86 return x >= 0.0 ? 1.0 : -1.0;
87}

Referenced by PiecewiseConstant::value().

◆ smootherStep() [1/2]

template<ComputeType compute_type, typename X , typename S , typename E >
auto MathUtils::smootherStep ( const X &  x,
const S &  start,
const E &  end 
)

Definition at line 347 of file MathUtils.h.

348{
349 mooseAssert("start < end", "Start value must be lower than end value for smootherStep");
350 if (x <= start)
351 return 0.0;
352 else if (x >= end)
353 {
354 if constexpr (compute_type == ComputeType::derivative)
355 return 0.0;
356 if constexpr (compute_type == ComputeType::value)
357 return 1.0;
358 }
359 const auto u = (x - start) / (end - start);
360 if constexpr (compute_type == ComputeType::derivative)
361 return 30.0 * libMesh::Utility::pow<2>(u) * (u * (u - 2.0) + 1.0) / (end - start);
362 if constexpr (compute_type == ComputeType::value)
363 return libMesh::Utility::pow<3>(u) * (u * (u * 6.0 - 15.0) + 10.0);
364}

◆ smootherStep() [2/2]

template<typename T , typename T2 >
T MathUtils::smootherStep ( x,
T2  start,
T2  end,
bool  derivative = false 
)

Definition at line 321 of file MathUtils.h.

322{
323 mooseAssert("start < end", "Start value must be lower than end value for smootherStep");
324 if (x <= start)
325 return 0.0;
326 else if (x >= end)
327 {
328 if (derivative)
329 return 0.0;
330 else
331 return 1.0;
332 }
333 x = (x - start) / (end - start);
334 if (derivative)
335 return 30.0 * libMesh::Utility::pow<2>(x) * (x * (x - 2.0) + 1.0) / (end - start);
336 return libMesh::Utility::pow<3>(x) * (x * (x * 6.0 - 15.0) + 10.0);
337}

◆ taylorLog()

Real MathUtils::taylorLog ( Real  x)
Todo:
This can be done without std::pow!

Definition at line 172 of file MathUtils.C.

173{
174 Real y = (x - 1.0) / (x + 1.0);
175 Real val = 1.0;
176 for (unsigned int i = 0; i < 5; ++i)
177 {
178 Real exponent = i + 2.0;
179 val += 1.0 / (2.0 * (i + 1.0) + 1.0) * std::pow(y, exponent);
180 }
181
182 return val * 2.0 * y;
183}
MooseUnits pow(const MooseUnits &, int)
Definition Units.C:537

◆ timeDerivName()

template<typename T >
T MathUtils::timeDerivName ( const T &  base_prop_name)

automatic prefixing for naming material properties based on time derivatives of coupled variables/functors

Definition at line 457 of file MathUtils.h.

458{
459 return "d" + base_prop_name + "_dt";
460}

Referenced by GenericFunctorMaterialTempl< is_ad >::GenericFunctorMaterialTempl(), and GenericVectorFunctorMaterialTempl< is_ad >::GenericVectorFunctorMaterialTempl().

Variable Documentation

◆ sqrt2

constexpr Real MathUtils::sqrt2 = 1.4142135623730951
staticconstexpr