www.mooseframework.org
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< ScalarTraits< T >::value &&ScalarTraits< T2 >::value &&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< ScalarTraits< T >::value, int >::type = 0>
void addScaled (const T &scalar, const NumericVector< T2 > &numeric_vector, 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...
 
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< DualReal > > (RankFourTensorTempl< DualReal > &v)
 
template<>
void mooseSetToZero< RankThreeTensorTempl< Real > > (RankThreeTensorTempl< Real > &v)
 Helper function template specialization to set an object to zero. More...
 
template<>
void mooseSetToZero< RankThreeTensorTempl< DualReal > > (RankThreeTensorTempl< DualReal > &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< DualReal > > (SymmetricRankFourTensorTempl< DualReal > &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 334 of file MathUtils.h.

335 {
336  value,
337  derivative
338 };
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< ScalarTraits< T >::value &&ScalarTraits< T2 >::value &&ScalarTraits< T3 >::value, int >::type = 0>
void MathUtils::addScaled ( const T &  a,
const T2 &  b,
T3 &  result 
)

Definition at line 168 of file MathUtils.h.

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

169 {
170  result += a * b;
171 }

◆ addScaled() [2/2]

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

Definition at line 178 of file MathUtils.h.

179 {
180  result.add(scalar, numeric_vector);
181 }

◆ 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 206 of file MathUtils.C.

Referenced by circumcenter2D().

212 {
213  mooseAssert(!MooseUtils::isZero(b0 + b1 + b2 - 1.0), "Barycentric coordinates must sum to one!");
214 
215  Point center;
216 
217  for (unsigned int d = 0; d < 2; ++d)
218  center(d) = p0(d) * b0 + p1(d) * b1 + p2(d) * b2;
219  // p0, p1, p2 are vertices of triangle
220  // b0, b1, b2 are Barycentric coordinates of the triangle center
221 
222  return center;
223 }
bool isZero(const T &value, const Real tolerance=TOLERANCE *TOLERANCE *TOLERANCE)
Definition: MooseUtils.h:628

◆ 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 226 of file MathUtils.C.

Referenced by circumcenter3D().

234 {
235  mooseAssert(!MooseUtils::isZero(b0 + b1 + b2 + b3 - 1.0),
236  "Barycentric coordinates must sum to one!");
237 
238  Point center;
239 
240  for (unsigned int d = 0; d < 3; ++d)
241  center(d) = p0(d) * b0 + p1(d) * b1 + p2(d) * b2 + p3(d) * b3;
242  // p0, p1, p2, p3 are vertices of tetrahedron
243  // b0, b1, b2, b3 are Barycentric coordinates of the tetrahedron center
244 
245  return center;
246 }
bool isZero(const T &value, const Real tolerance=TOLERANCE *TOLERANCE *TOLERANCE)
Definition: MooseUtils.h:628

◆ 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 249 of file MathUtils.C.

250 {
251  // Square of triangle edge lengths
252  Real edge01 = (p0 - p1).norm_sq();
253  Real edge02 = (p0 - p2).norm_sq();
254  Real edge12 = (p1 - p2).norm_sq();
255 
256  // Barycentric weights for circumcenter
257  Real weight0 = edge12 * (edge01 + edge02 - edge12);
258  Real weight1 = edge02 * (edge01 + edge12 - edge02);
259  Real weight2 = edge01 * (edge02 + edge12 - edge01);
260 
261  Real sum_weights = weight0 + weight1 + weight2;
262 
263  // Check to make sure vertices are not collinear
264  if (MooseUtils::isZero(sum_weights))
265  mooseError("Cannot evaluate circumcenter. Points should be non-collinear.");
266 
267  Real inv_sum_weights = 1.0 / sum_weights;
268 
269  // Barycentric coordinates
270  Real b0 = weight0 * inv_sum_weights;
271  Real b1 = weight1 * inv_sum_weights;
272  Real b2 = weight2 * inv_sum_weights;
273 
274  return MathUtils::barycentricToCartesian2D(p0, p1, p2, b0, b1, b2);
275 }
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:206
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
bool isZero(const T &value, const Real tolerance=TOLERANCE *TOLERANCE *TOLERANCE)
Definition: MooseUtils.h:628
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 278 of file MathUtils.C.

279 {
280  // Square of tetrahedron edge lengths
281  Real edge01 = (p0 - p1).norm_sq();
282  Real edge02 = (p0 - p2).norm_sq();
283  Real edge03 = (p0 - p3).norm_sq();
284  Real edge12 = (p1 - p2).norm_sq();
285  Real edge13 = (p1 - p3).norm_sq();
286  Real edge23 = (p2 - p3).norm_sq();
287 
288  // Barycentric weights for circumcenter
289  Real weight0 = -2 * edge12 * edge13 * edge23 + edge01 * edge23 * (edge13 + edge12 - edge23) +
290  edge02 * edge13 * (edge12 + edge23 - edge13) +
291  edge03 * edge12 * (edge13 + edge23 - edge12);
292  Real weight1 = -2 * edge02 * edge03 * edge23 + edge01 * edge23 * (edge02 + edge03 - edge23) +
293  edge13 * edge02 * (edge03 + edge23 - edge02) +
294  edge12 * edge03 * (edge02 + edge23 - edge03);
295  Real weight2 = -2 * edge01 * edge03 * edge13 + edge02 * edge13 * (edge01 + edge03 - edge13) +
296  edge23 * edge01 * (edge03 + edge13 - edge01) +
297  edge12 * edge03 * (edge01 + edge13 - edge03);
298  Real weight3 = -2 * edge01 * edge02 * edge12 + edge03 * edge12 * (edge01 + edge02 - edge12) +
299  edge23 * edge01 * (edge02 + edge12 - edge01) +
300  edge13 * edge02 * (edge01 + edge12 - edge02);
301 
302  Real sum_weights = weight0 + weight1 + weight2 + weight3;
303 
304  // Check to make sure vertices are not coplanar
305  if (MooseUtils::isZero(sum_weights))
306  mooseError("Cannot evaluate circumcenter. Points should be non-coplanar.");
307 
308  Real inv_sum_weights = 1.0 / sum_weights;
309 
310  // Barycentric coordinates
311  Real b0 = weight0 * inv_sum_weights;
312  Real b1 = weight1 * inv_sum_weights;
313  Real b2 = weight2 * inv_sum_weights;
314  Real b3 = weight3 * inv_sum_weights;
315 
316  return MathUtils::barycentricToCartesian3D(p0, p1, p2, p3, b0, b1, b2, b3);
317 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
bool isZero(const T &value, const Real tolerance=TOLERANCE *TOLERANCE *TOLERANCE)
Definition: MooseUtils.h:628
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:226
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 305 of file MathUtils.h.

306 {
307  if (x < lowerlimit)
308  return lowerlimit;
309  if (x > upperlimit)
310  return upperlimit;
311  return x;
312 }

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

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

195 {
196  return a * b;
197 }

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

431 {
432  return (dividend % divisor + divisor) % divisor;
433 }

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

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

442 {
443  return "grad_" + base_prop_name;
444 }

◆ heavyside()

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

Definition at line 119 of file MathUtils.h.

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

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

414 {
415  const auto m = (y2 - y1) / (x2 - x1);
416  if constexpr (compute_type == ComputeType::derivative)
417  return m;
418  if constexpr (compute_type == ComputeType::value)
419  return m * (x - x1) + y1;
420 }

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

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

369 {
375  v = 0;
376 }

◆ mooseSetToZero() [2/3]

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

Definition at line 379 of file MathUtils.h.

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

◆ mooseSetToZero() [3/3]

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

Definition at line 386 of file MathUtils.h.

387 {
388  for (auto & v : vec)
389  v = 0.;
390 }

◆ mooseSetToZero< ADRankFourTensor >()

Definition at line 26 of file RankFourTensor.C.

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

◆ mooseSetToZero< ADRankThreeTensor >()

Definition at line 27 of file RankThreeTensor.C.

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

◆ mooseSetToZero< ADRankTwoTensor >()

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 27 of file RankTwoTensor.C.

28 {
29  v.zero();
30 }

◆ mooseSetToZero< ADSymmetricRankFourTensor >()

Definition at line 26 of file SymmetricRankFourTensor.C.

27 {
28  v.zero();
29 }

◆ mooseSetToZero< ADSymmetricRankTwoTensor >()

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 27 of file SymmetricRankTwoTensor.C.

28 {
29  v.zero();
30 }
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 20 of file RankFourTensor.C.

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

◆ mooseSetToZero< RankFourTensorTempl< DualReal > >()

◆ mooseSetToZero< RankFourTensorTempl< Real > >()

◆ mooseSetToZero< RankThreeTensor >()

Definition at line 20 of file RankThreeTensor.C.

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

◆ mooseSetToZero< RankThreeTensorTempl< DualReal > >()

◆ 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 20 of file RankTwoTensor.C.

21 {
22  v.zero();
23 }

◆ mooseSetToZero< SymmetricRankFourTensor >()

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 20 of file SymmetricRankFourTensor.C.

21 {
22  v.zero();
23 }

◆ mooseSetToZero< SymmetricRankFourTensorTempl< DualReal > >()

◆ mooseSetToZero< SymmetricRankFourTensorTempl< Real > >()

◆ mooseSetToZero< SymmetricRankTwoTensor >()

Helper function template specialization to set an object to zero.

Needed by DerivativeMaterialInterface

Definition at line 20 of file SymmetricRankTwoTensor.C.

21 {
22  v.zero();
23 }
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 175 of file MathUtils.C.

176 {
177  // first row all zero
178  std::vector<std::vector<unsigned int>> multi_index;
179  std::vector<std::vector<unsigned int>> n_choose_k;
180  std::vector<unsigned int> row(dim, 0);
181  multi_index.push_back(row);
182 
183  if (dim == 1)
184  for (unsigned int q = 1; q <= order; q++)
185  {
186  row[0] = q;
187  multi_index.push_back(row);
188  }
189  else
190  for (unsigned int q = 1; q <= order; q++)
191  {
192  n_choose_k = multiIndexHelper(dim + q - 1, dim - 1);
193  for (unsigned int r = 0; r < n_choose_k.size(); r++)
194  {
195  row.clear();
196  for (unsigned int c = 1; c < n_choose_k[0].size(); c++)
197  row.push_back(n_choose_k[r][c] - n_choose_k[r][c - 1] - 1);
198  multi_index.push_back(row);
199  }
200  }
201 
202  return multi_index;
203 }
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:148
std::vector< std::vector< unsigned int > > multiIndexHelper(unsigned int N, unsigned int K)
A helper function for MathUtils::multiIndex.
Definition: MathUtils.C:322

◆ negativePart()

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

Definition at line 156 of file MathUtils.h.

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

◆ plainLog()

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

Definition at line 17 of file MathUtils.C.

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

18 {
19  switch (derivative_order)
20  {
21  case 0:
22  return std::log(x);
23 
24  case 1:
25  return 1.0 / x;
26 
27  case 2:
28  return -1.0 / (x * x);
29 
30  case 3:
31  return 2.0 / (x * x * x);
32  }
33 
34  mooseError("Unsupported derivative order ", derivative_order);
35 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
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 233 of file MathUtils.h.

Referenced by MortarSegmentHelper::isDisjoint().

234 {
235  const auto size = c.size();
236  if (size == 0)
237  return 0.0;
238 
239  R value = c[0];
240  if (derivative)
241  {
242  value *= size - 1;
243  for (std::size_t i = 1; i < size - 1; ++i)
244  value = value * x + c[i] * (size - i - 1);
245  }
246  else
247  {
248  for (std::size_t i = 1; i < size; ++i)
249  value = value * x + c[i];
250  }
251 
252  return value;
253 }
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 38 of file MathUtils.C.

39 {
40  if (x >= tol)
41  return plainLog(x, derivative_order);
42 
43  const auto c1 = [&]() { return 1.0 / tol; };
44  const auto c2 = [&]() { return std::log(tol) - 1.0; };
45 
46  switch (derivative_order)
47  {
48  case 0:
49  return c1() * x + c2();
50 
51  case 1:
52  return c1();
53 
54  case 2:
55  return 0.0;
56 
57  case 3:
58  return 0.0;
59  }
60 
61  mooseError("Unsupported derivative order ", derivative_order);
62 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
Real plainLog(Real x, unsigned int derivative_order)
Definition: MathUtils.C:17
auto log(const T &)

◆ poly2Log()

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

Definition at line 65 of file MathUtils.C.

66 {
67  if (x >= tol)
68  return plainLog(x, derivative_order);
69 
70  const auto c1 = [&]() { return -0.5 / (tol * tol); };
71  const auto c2 = [&]() { return 2.0 / tol; };
72  const auto c3 = [&]() { return std::log(tol) - 3.0 / 2.0; };
73 
74  switch (derivative_order)
75  {
76  case 0:
77  return c1() * x * x + c2() * x + c3();
78 
79  case 1:
80  return 2.0 * c1() * x + c2();
81 
82  case 2:
83  return 2.0 * c1();
84 
85  case 3:
86  return 0.0;
87  }
88 
89  mooseError("Unsupported derivative order ", derivative_order);
90 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
Real plainLog(Real x, unsigned int derivative_order)
Definition: MathUtils.C:17
auto log(const T &)

◆ poly3Log()

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

Definition at line 93 of file MathUtils.C.

94 {
95  if (x >= tol)
96  return plainLog(x, derivative_order);
97 
98  const auto c1 = [&]() { return 1.0 / (3.0 * tol * tol * tol); };
99  const auto c2 = [&]() { return -3.0 / (2.0 * tol * tol); };
100  const auto c3 = [&]() { return 3.0 / tol; };
101  const auto c4 = [&]() { return std::log(tol) - 11.0 / 6.0; };
102 
103  switch (derivative_order)
104  {
105  case 0:
106  return c1() * x * x * x + c2() * x * x + c3() * x + c4();
107 
108  case 1:
109  return 3.0 * c1() * x * x + 2.0 * c2() * x + c3();
110 
111  case 2:
112  return 6.0 * c1() * x + 2.0 * c2();
113 
114  case 3:
115  return 6.0 * c1();
116  }
117 
118  mooseError("Unsupported derivative order ", derivative_order);
119 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
Real plainLog(Real x, unsigned int derivative_order)
Definition: MathUtils.C:17
auto log(const T &)

◆ poly4Log()

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

Definition at line 122 of file MathUtils.C.

123 {
124  if (x >= tol)
125  return plainLog(x, derivative_order);
126 
127  switch (derivative_order)
128  {
129  case 0:
130  return std::log(tol) + (x - tol) / tol -
131  Utility::pow<2>(x - tol) / (2.0 * Utility::pow<2>(tol)) +
132  Utility::pow<3>(x - tol) / (3.0 * Utility::pow<3>(tol)) -
133  Utility::pow<4>(x - tol) / (4.0 * Utility::pow<4>(tol)) +
134  Utility::pow<5>(x - tol) / (5.0 * Utility::pow<5>(tol)) -
135  Utility::pow<6>(x - tol) / (6.0 * Utility::pow<6>(tol));
136 
137  case 1:
138  return 1.0 / tol - (x - tol) / Utility::pow<2>(tol) +
139  Utility::pow<2>(x - tol) / Utility::pow<3>(tol) -
140  Utility::pow<3>(x - tol) / Utility::pow<4>(tol) +
141  Utility::pow<4>(x - tol) / Utility::pow<5>(tol) -
142  Utility::pow<5>(x - tol) / Utility::pow<6>(tol);
143 
144  case 2:
145  return -1.0 / Utility::pow<2>(tol) + 2.0 * (x - tol) / Utility::pow<3>(tol) -
146  3.0 * Utility::pow<2>(x - tol) / Utility::pow<4>(tol) +
147  4.0 * Utility::pow<3>(x - tol) / Utility::pow<5>(tol) -
148  5.0 * Utility::pow<4>(x - tol) / Utility::pow<6>(tol);
149 
150  case 3:
151  return 2.0 / Utility::pow<3>(tol) - 6.0 * (x - tol) / Utility::pow<4>(tol) +
152  12.0 * Utility::pow<2>(x - tol) / Utility::pow<5>(tol) -
153  20.0 * Utility::pow<3>(x - tol) / Utility::pow<6>(tol);
154  }
155 
156  mooseError("Unsupported derivative order ", derivative_order);
157 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:284
Real plainLog(Real x, unsigned int derivative_order)
Definition: MathUtils.C:17
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 268 of file MathUtils.h.

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

269 {
270  auto size = c.size();
271  if (size == 0)
272  return 0.0;
273 
274  size--;
275  R value = c[size];
276  for (std::size_t i = 1; i <= size; ++i)
277  value = value * x + c[size - i];
278 
279  return value;
280 }
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 289 of file MathUtils.h.

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

◆ positivePart()

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

Definition at line 149 of file MathUtils.h.

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

◆ pow()

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

Definition at line 90 of file MathUtils.h.

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

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

◆ regularizedHeavyside()

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

Definition at line 126 of file MathUtils.h.

127 {
128  if (x <= -smoothing_length)
129  return 0.0;
130  else if (x < smoothing_length)
131  return 0.5 * (1 + std::sin(libMesh::pi * x / 2 / smoothing_length));
132  else
133  return 1.0;
134 }
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 138 of file MathUtils.h.

139 {
140  if (x < smoothing_length && x > -smoothing_length)
141  return 0.25 * libMesh::pi / smoothing_length *
142  (std::cos(libMesh::pi * x / 2 / smoothing_length));
143  else
144  return 0.0;
145 }
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 316 of file MathUtils.h.

317 {
318  mooseAssert("start < end", "Start value must be lower than end value for smootherStep");
319  if (x <= start)
320  return 0.0;
321  else if (x >= end)
322  {
323  if (derivative)
324  return 0.0;
325  else
326  return 1.0;
327  }
328  x = (x - start) / (end - start);
329  if (derivative)
330  return 30.0 * Utility::pow<2>(x) * (x * (x - 2.0) + 1.0) / (end - start);
331  return Utility::pow<3>(x) * (x * (x * 6.0 - 15.0) + 10.0);
332 }
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 342 of file MathUtils.h.

343 {
344  mooseAssert("start < end", "Start value must be lower than end value for smootherStep");
345  if (x <= start)
346  return 0.0;
347  else if (x >= end)
348  {
349  if constexpr (compute_type == ComputeType::derivative)
350  return 0.0;
351  if constexpr (compute_type == ComputeType::value)
352  return 1.0;
353  }
354  const auto u = (x - start) / (end - start);
355  if constexpr (compute_type == ComputeType::derivative)
356  return 30.0 * Utility::pow<2>(u) * (u * (u - 2.0) + 1.0) / (end - start);
357  if constexpr (compute_type == ComputeType::value)
358  return Utility::pow<3>(u) * (u * (u * 6.0 - 15.0) + 10.0);
359 }
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)

Definition at line 161 of file MathUtils.C.

162 {
163  Real y = (x - 1.0) / (x + 1.0);
164  Real val = 1.0;
165  for (unsigned int i = 0; i < 5; ++i)
166  {
167  Real exponent = i + 2.0;
168  val += 1.0 / (2.0 * (i + 1.0) + 1.0) * std::pow(y, exponent);
169  }
170 
171  return val * 2.0 * y;
172 }
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 452 of file MathUtils.h.

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

453 {
454  return "d" + base_prop_name + "_dt";
455 }

Variable Documentation

◆ sqrt2

constexpr Real MathUtils::sqrt2 = 1.4142135623730951
static