https://mooseframework.inl.gov
Enumerations | Functions | Variables
MathUtils Namespace Reference

Enumerations

enum  ComputeType { ComputeType::value, ComputeType::derivative }
 

Functions

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. More...
 
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. More...
 
Point circumcenter2D (const Point &p0, const Point &p1, const Point &p2)
 Evaluate circumcenter of a triangle given three arbitrary points. More...
 
Point circumcenter3D (const Point &p0, const Point &p1, const Point &p2, const Point &p3)
 Evaluate circumcenter of a tetrahedrom given four arbitrary points. More...
 
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 (T x, Real smoothing_length)
 
template<typename T >
regularizedHeavysideDerivative (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. More...
 
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. More...
 
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. More...
 
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. More...
 
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. More...
 
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 More...
 
template<typename T >
gradName (const T &base_prop_name)
 automatic prefixing for naming material properties based on gradients of coupled variables/functors More...
 
template<typename T >
timeDerivName (const T &base_prop_name)
 automatic prefixing for naming material properties based on time derivatives of coupled variables/functors More...
 
void kron (RealEigenMatrix &product, const RealEigenMatrix &mat_A, const RealEigenMatrix &mat_B)
 Computes the Kronecker product of two matrices. More...
 
template<>
void mooseSetToZero< RankFourTensor > (RankFourTensor &v)
 Helper function template specialization to set an object to zero. More...
 
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. More...
 
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. More...
 
template<>
void mooseSetToZero< ADRankTwoTensor > (ADRankTwoTensor &v)
 Helper function template specialization to set an object to zero. More...
 
template<>
void mooseSetToZero< SymmetricRankFourTensor > (SymmetricRankFourTensor &v)
 Helper function template specialization to set an object to zero. More...
 
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. More...
 
template<>
void mooseSetToZero< ADSymmetricRankTwoTensor > (ADSymmetricRankTwoTensor &v)
 Helper function template specialization to set an object to zero. More...
 
Real plainLog (Real x, unsigned int derivative_order)
 
 FactorizedRankTwoTensorOperatorMapUnary (log, std::log(eigval))
 
 FactorizedRankTwoTensorOperatorMapDerivativeUnary (dlog, std::log(eigval), 1/eigval)
 
 FactorizedRankTwoTensorOperatorMapUnary (exp, std::exp(eigval))
 
 FactorizedRankTwoTensorOperatorMapDerivativeUnary (dexp, std::exp(eigval), std::exp(eigval))
 
 FactorizedRankTwoTensorOperatorMapUnary (sqrt, std::sqrt(eigval))
 
 FactorizedRankTwoTensorOperatorMapDerivativeUnary (dsqrt, std::sqrt(eigval), std::pow(eigval, -1./2.)/2.)
 
 FactorizedRankTwoTensorOperatorMapUnary (cbrt, std::cbrt(eigval))
 
 FactorizedRankTwoTensorOperatorMapDerivativeUnary (dcbrt, std::cbrt(eigval), std::pow(eigval, -2./3.)/3.)
 
 FactorizedRankTwoTensorOperatorMapBinary (pow, std::pow(eigval, arg))
 
 FactorizedRankTwoTensorOperatorMapDerivativeBinary (dpow, std::pow(eigval, arg), arg *std::pow(eigval, arg - 1))
 

Variables

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

Enumeration Type Documentation

◆ ComputeType

Enumerator
value 
derivative 

Definition at line 338 of file MathUtils.h.

339 {
340  value,
341  derivative
342 };
Real value(unsigned n, unsigned alpha, unsigned beta, Real x)

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 170 of file MathUtils.h.

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

171 {
172  result += a * b;
173 }

◆ 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 180 of file MathUtils.h.

183 {
184  result.add(scalar, numeric_vector);
185 }
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.

Referenced by circumcenter2D().

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 }
bool isZero(const T &value, const Real tolerance=TOLERANCE *TOLERANCE *TOLERANCE)
Definition: MooseUtils.h:691

◆ 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.

Referenced by circumcenter3D().

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 }
bool isZero(const T &value, const Real tolerance=TOLERANCE *TOLERANCE *TOLERANCE)
Definition: MooseUtils.h:691

◆ 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 }
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
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:333
bool isZero(const T &value, const Real tolerance=TOLERANCE *TOLERANCE *TOLERANCE)
Definition: MooseUtils.h:691
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
auto norm_sq(const T &a) -> decltype(std::norm(a))

◆ 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 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:333
bool isZero(const T &value, const Real tolerance=TOLERANCE *TOLERANCE *TOLERANCE)
Definition: MooseUtils.h:691
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
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
auto norm_sq(const T &a) -> decltype(std::norm(a))

◆ clamp()

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

Definition at line 309 of file MathUtils.h.

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

◆ 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 198 of file MathUtils.h.

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

199 {
200  return a * b;
201 }

◆ 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 434 of file MathUtils.h.

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

◆ FactorizedRankTwoTensorOperatorMapBinary()

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

◆ FactorizedRankTwoTensorOperatorMapDerivativeBinary()

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

◆ FactorizedRankTwoTensorOperatorMapDerivativeUnary() [1/4]

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

◆ FactorizedRankTwoTensorOperatorMapDerivativeUnary() [2/4]

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

◆ FactorizedRankTwoTensorOperatorMapDerivativeUnary() [3/4]

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

◆ FactorizedRankTwoTensorOperatorMapDerivativeUnary() [4/4]

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

◆ FactorizedRankTwoTensorOperatorMapUnary() [1/4]

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

◆ FactorizedRankTwoTensorOperatorMapUnary() [2/4]

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

◆ FactorizedRankTwoTensorOperatorMapUnary() [3/4]

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

◆ FactorizedRankTwoTensorOperatorMapUnary() [4/4]

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

◆ 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 445 of file MathUtils.h.

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

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

◆ 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 417 of file MathUtils.h.

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

◆ mooseSetToZero() [1/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 372 of file MathUtils.h.

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

373 {
379  v = 0;
380 }

◆ mooseSetToZero() [2/3]

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

Definition at line 383 of file MathUtils.h.

384 {
385  mooseError("mooseSetToZero does not accept pointers");
386 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:333

◆ mooseSetToZero() [3/3]

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

Definition at line 390 of file MathUtils.h.

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

◆ mooseSetToZero< ADRankFourTensor >()

Definition at line 25 of file RankFourTensor.C.

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

◆ mooseSetToZero< ADRankThreeTensor >()

Definition at line 26 of file RankThreeTensor.C.

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

◆ mooseSetToZero< ADRankTwoTensor >()

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 26 of file RankTwoTensor.C.

27 {
28  v.zero();
29 }

◆ mooseSetToZero< ADSymmetricRankFourTensor >()

Definition at line 25 of file SymmetricRankFourTensor.C.

26 {
27  v.zero();
28 }

◆ mooseSetToZero< ADSymmetricRankTwoTensor >()

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 26 of file SymmetricRankTwoTensor.C.

27 {
28  v.zero();
29 }
void zero()
Set all components to zero.

◆ mooseSetToZero< RankFourTensor >()

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 19 of file RankFourTensor.C.

20 {
21  v.zero();
22 }
void zero()
Zeros out the tensor.

◆ mooseSetToZero< RankFourTensorTempl< ADReal > >()

◆ mooseSetToZero< RankFourTensorTempl< Real > >()

◆ mooseSetToZero< RankThreeTensor >()

Definition at line 19 of file RankThreeTensor.C.

20 {
21  v.zero();
22 }
void zero()
Zeros out the tensor.

◆ mooseSetToZero< RankThreeTensorTempl< ADReal > >()

◆ mooseSetToZero< RankThreeTensorTempl< Real > >()

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

◆ mooseSetToZero< RankTwoTensor >()

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 19 of file RankTwoTensor.C.

20 {
21  v.zero();
22 }

◆ mooseSetToZero< SymmetricRankFourTensor >()

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 19 of file SymmetricRankFourTensor.C.

20 {
21  v.zero();
22 }

◆ mooseSetToZero< SymmetricRankFourTensorTempl< ADReal > >()

◆ mooseSetToZero< SymmetricRankFourTensorTempl< Real > >()

◆ mooseSetToZero< SymmetricRankTwoTensor >()

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 19 of file SymmetricRankTwoTensor.C.

20 {
21  v.zero();
22 }
void zero()
Set all components to zero.

◆ 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 }
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:159
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 157 of file MathUtils.h.

158 {
159  return x < 0.0 ? x : 0.0;
160 }

◆ plainLog()

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

Definition at line 28 of file MathUtils.C.

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

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 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:333
auto log(const T &)

◆ 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 237 of file MathUtils.h.

Referenced by MortarSegmentHelper::isDisjoint().

238 {
239  const auto size = c.size();
240  if (size == 0)
241  return 0.0;
242 
243  R value = c[0];
244  if (derivative)
245  {
246  value *= size - 1;
247  for (std::size_t i = 1; i < size - 1; ++i)
248  value = value * x + c[i] * (size - i - 1);
249  }
250  else
251  {
252  for (std::size_t i = 1; i < size; ++i)
253  value = value * x + c[i];
254  }
255 
256  return value;
257 }
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 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:333
Real plainLog(Real x, unsigned int derivative_order)
Definition: MathUtils.C:28
auto log(const T &)

◆ 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 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:333
Real plainLog(Real x, unsigned int derivative_order)
Definition: MathUtils.C:28
auto log(const T &)

◆ 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 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:333
Real plainLog(Real x, unsigned int derivative_order)
Definition: MathUtils.C:28
auto log(const T &)

◆ 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 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:333
Real plainLog(Real x, unsigned int derivative_order)
Definition: MathUtils.C:28
auto log(const T &)
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template pow< 2 >(tan(_arg))+1.0) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(sqrt

◆ 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 272 of file MathUtils.h.

Referenced by NodalPatchRecovery::computePVector(), NodalPatchRecoveryBase::evaluateBasisFunctions(), and ProjectedStatefulMaterialNodalPatchRecoveryTempl< T, is_ad >::evaluateBasisFunctions().

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

◆ 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 293 of file MathUtils.h.

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

◆ positivePart()

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

Definition at line 150 of file MathUtils.h.

151 {
152  return x > 0.0 ? x : 0.0;
153 }

◆ pow()

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

Definition at line 91 of file MathUtils.h.

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

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 }

◆ regularizedHeavyside()

template<typename T >
T MathUtils::regularizedHeavyside ( 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  return 0.5 * (1 + std::sin(libMesh::pi * x / 2 / smoothing_length));
133  else
134  return 1.0;
135 }
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template * sin(_arg) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(tan
const Real pi

◆ regularizedHeavysideDerivative()

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

Definition at line 139 of file MathUtils.h.

140 {
141  if (x < smoothing_length && x > -smoothing_length)
142  return 0.25 * libMesh::pi / smoothing_length *
143  (std::cos(libMesh::pi * x / 2 / smoothing_length));
144  else
145  return 0.0;
146 }
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template cos(_arg) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(cos
const Real pi

◆ round()

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

◆ sign()

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

◆ smootherStep() [1/2]

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

Definition at line 320 of file MathUtils.h.

321 {
322  mooseAssert("start < end", "Start value must be lower than end value for smootherStep");
323  if (x <= start)
324  return 0.0;
325  else if (x >= end)
326  {
327  if (derivative)
328  return 0.0;
329  else
330  return 1.0;
331  }
332  x = (x - start) / (end - start);
333  if (derivative)
334  return 30.0 * libMesh::Utility::pow<2>(x) * (x * (x - 2.0) + 1.0) / (end - start);
335  return libMesh::Utility::pow<3>(x) * (x * (x * 6.0 - 15.0) + 10.0);
336 }
CTSub CT_OPERATOR_BINARY CTMul CTCompareLess CTCompareGreater CTCompareEqual _arg template pow< 2 >(tan(_arg))+1.0) *_arg.template D< dtag >()) CT_SIMPLE_UNARY_FUNCTION(sqrt

◆ smootherStep() [2/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 346 of file MathUtils.h.

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

◆ 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 }
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
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 456 of file MathUtils.h.

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

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

Variable Documentation

◆ sqrt2

constexpr Real MathUtils::sqrt2 = 1.4142135623730951
static