OGS 6.1.0-1721-g6382411ad
MathLib Namespace Reference

Detailed Description

Contains all mathematical functionality used in OpenGeoSys, from defining a vector or calculating a norm to integration schemes and matrix preconditioners.

See also
detail
Author
Norihiro Watanabe
Date
2013-08-13
Author
Wenqing Wang

Namespaces

 detail
 
 details
 
 KelvinVector
 
 LinAlg
 
 Nonlinear
 
 ODE
 

Classes

class  ConstantFunction
 
class  DenseMatrix
 
class  EigenLinearSolver
 
class  EigenLinearSolverBase
 
class  EigenLisLinearSolver
 
class  EigenMatrix
 
struct  EigenOption
 Option for Eigen sparse solver. More...
 
class  EigenVector
 Global vector based on Eigen vector. More...
 
struct  GaussLegendre
 
struct  GaussLegendrePyramid
 
struct  GaussLegendrePyramid< 2 >
 
struct  GaussLegendrePyramid< 3 >
 
struct  GaussLegendreTet
 
struct  GaussLegendreTet< 2 >
 
struct  GaussLegendreTet< 3 >
 
struct  GaussLegendreTri
 
struct  GaussLegendreTri< 2 >
 
struct  GaussLegendreTri< 3 >
 
class  LinearFunction
 
class  LinearIntervalInterpolation
 Class (template) LinearIntervalInterpolation is a functional object performing an interval mapping $f: [a,b] \to [c,d]$. More...
 
class  LisLinearSolver
 Linear solver using Lis (http://www.ssisc.org/lis/) More...
 
class  LisMatrix
 LisMatrix is a wrapper class for matrix types of the linear iterative solvers library. More...
 
struct  LisOption
 
class  LisVector
 Lis vector wrapper class. More...
 
struct  MatrixSpecifications
 
struct  MatrixVectorTraits
 
class  PETScLinearSolver
 
class  PETScMatrix
 Wrapper class for PETSc matrix routines for matrix. More...
 
struct  PETScMatrixOption
 This a struct data containing the configuration information to create a PETSc type matrix. More...
 
class  PETScVector
 Wrapper class for PETSc vector. More...
 
class  PiecewiseLinearInterpolation
 
class  PiecewiseLinearMonotonicCurve
 Class for strong monotonic curves. More...
 
class  Point3dWithID
 
struct  RowColumnIndices
 
struct  SetMatrixSparsity
 
struct  SetMatrixSparsity< EigenMatrix, SPARSITY_PATTERN >
 Sets the sparsity pattern of the underlying EigenMatrix. More...
 
struct  SetMatrixSparsity< LisMatrix, SPARSITY_PATTERN >
 Sets the sparsity pattern of the underlying LisMatrix. More...
 
class  TemplatePoint
 class-template for points can be instantiated by a numeric type. More...
 
class  TemplateVector3
 
class  TemplateWeightedPoint
 
struct  WeightedSum
 

Typedefs

using Point3d = MathLib::TemplatePoint< double, 3 >
 
template<typename IndexType >
using SparsityPattern = std::vector< IndexType >
 A vector telling how many nonzeros there are in each global matrix row. More...
 
using WeightedPoint1D = TemplateWeightedPoint< double, double, 1 >
 
using WeightedPoint2D = TemplateWeightedPoint< double, double, 2 >
 
using WeightedPoint3D = TemplateWeightedPoint< double, double, 3 >
 
using Vector3 = TemplateVector3< double >
 

Enumerations

enum  TriangleTest { GAUSS, BARYCENTRIC }
 
enum  VecNormType { VecNormType::NORM1, VecNormType::NORM2, VecNormType::INFINITY_N, VecNormType::INVALID }
 Norm type. Not declared as class type in order to use the members as integers. More...
 

Functions

template<typename CurveType >
std::unique_ptr< CurveType > createPiecewiseLinearCurve (BaseLib::ConfigTree const &config)
 
double orientation3d (MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c)
 
double calcTetrahedronVolume (MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c, MathLib::Point3d const &d)
 
double calcTriangleArea (MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c)
 
bool isPointInTetrahedron (MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c, MathLib::Point3d const &d, double eps)
 
bool isPointInTriangle (MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c, double eps_pnt_out_of_plane, double eps_pnt_out_of_tri, MathLib::TriangleTest algorithm)
 
bool gaussPointInTriangle (MathLib::Point3d const &q, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c, double eps_pnt_out_of_plane, double eps_pnt_out_of_tri)
 
bool barycentricPointInTriangle (MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c, double eps_pnt_out_of_plane, double eps_pnt_out_of_tri)
 
bool isPointInTriangleXY (MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c)
 
bool dividedByPlane (const MathLib::Point3d &a, const MathLib::Point3d &b, const MathLib::Point3d &c, const MathLib::Point3d &d)
 
bool isCoplanar (const MathLib::Point3d &a, const MathLib::Point3d &b, const MathLib::Point3d &c, const MathLib::Point3d &d)
 Checks if the four given points are located on a plane. More...
 
static std::array< std::array< double, 3 >, GaussLegendreTet< 3 >::NPoints > initGLTet3X ()
 
template<typename FP_TYPE , typename IDX_TYPE >
FP_TYPE sqrFrobNrm (const DenseMatrix< FP_TYPE, IDX_TYPE > &mat)
 
template<typename FP_TYPE , typename IDX_TYPE >
std::ostream & operator<< (std::ostream &os, const DenseMatrix< FP_TYPE, IDX_TYPE > &mat)
 
template<typename Matrix >
Eigen::Map< Matrix > createZeroedMatrix (std::vector< double > &data, Eigen::MatrixXd::Index rows, Eigen::MatrixXd::Index cols)
 
template<typename Matrix >
Eigen::Map< const Matrix > toMatrix (std::vector< double > const &data, Eigen::MatrixXd::Index rows, Eigen::MatrixXd::Index cols)
 
template<typename Matrix >
Eigen::Map< Matrix > toMatrix (std::vector< double > &data, Eigen::MatrixXd::Index rows, Eigen::MatrixXd::Index cols)
 
template<typename Vector >
Eigen::Map< Vector > createZeroedVector (std::vector< double > &data, Eigen::VectorXd::Index size)
 
template<typename Vector >
Eigen::Map< const Vector > toVector (std::vector< double > const &data, Eigen::VectorXd::Index size)
 Creates an Eigen mapped vector from the given data vector. More...
 
template<typename Vector >
Eigen::Map< Vector > toVector (std::vector< double > &data, Eigen::VectorXd::Index size)
 Creates an Eigen mapped vector from the given data vector. More...
 
Eigen::Map< const Eigen::VectorXd > toVector (std::vector< double > const &data)
 
Eigen::Map< Eigen::VectorXd > toVector (std::vector< double > &data)
 
void applyKnownSolution (EigenMatrix &A_, EigenVector &b_, EigenVector &, const std::vector< EigenMatrix::IndexType > &vec_knownX_id, const std::vector< double > &vec_knownX_x, double)
 
void applyKnownSolution (Eigen::MatrixXd &A, Eigen::VectorXd &b, Eigen::VectorXd &, const std::vector< Eigen::MatrixXd::Index > &_vec_knownX_id, const std::vector< double > &_vec_knownX_x, double penalty_scaling=1e+10)
 
template<typename MAT_T >
bool finalizeMatrixAssembly (MAT_T &)
 
template<typename VEC_T >
void finalizeVectorAssembly (VEC_T &)
 General function to finalize the vector assembly. More...
 
std::string convertVecNormTypeToString (VecNormType normType)
 convert VecNormType to string More...
 
VecNormType convertStringToVecNormType (const std::string &str)
 convert string to VecNormType More...
 
void ignoreOtherLinearSolvers (const BaseLib::ConfigTree &config, const std::string &solver_name)
 
bool checkLisError (int err)
 
bool finalizeMatrixAssembly (LisMatrix &mat)
 finish assembly to make this matrix be ready for use More...
 
bool finalizeMatrixAssembly (PETScMatrix &mat, const MatAssemblyType asm_type=MAT_FINAL_ASSEMBLY)
 General interface for the matrix assembly. More...
 
void applyKnownSolution (PETScMatrix &A, PETScVector &b, PETScVector &x, const std::vector< PetscInt > &vec_knownX_id, const std::vector< PetscScalar > &vec_knownX_x)
 apply known solutions to a system of linear equations More...
 
void finalizeVectorAssembly (PETScVector &vec)
 Function to finalize the vector assembly. More...
 
template<typename MATRIX , typename SPARSITY_PATTERN >
void setMatrixSparsity (MATRIX &matrix, SPARSITY_PATTERN const &sparsity_pattern)
 
double calcProjPntToLineAndDists (const double p[3], const double a[3], const double b[3], double &lambda, double &d0)
 
double getAngle (const double p0[3], const double p1[3], const double p2[3])
 
template<typename T , int N>
scalarProduct (T const *const v0, T const *const v1)
 
template<>
double scalarProduct< double, 3 > (double const *const v0, double const *const v1)
 
template<typename T >
scalarProduct (T const *const v0, T const *const v1, int const n)
 
double sqrDist (const double *p0, const double *p1)
 
double to_radians (double degrees)
 converts the given degrees to radians More...
 
template<typename Type >
Type limitValueInInterval (const Type variable, const Type lower_bound, const Type upper_bound)
 
template<typename MATRIX >
MathLib::Point3d operator* (MATRIX const &mat, MathLib::Point3d const &p)
 
double sqrDist (MathLib::Point3d const &p0, MathLib::Point3d const &p1)
 
double sqrDist2d (MathLib::Point3d const &p0, MathLib::Point3d const &p1)
 
template<typename T , std::size_t DIM>
bool operator== (TemplatePoint< T, DIM > const &a, TemplatePoint< T, DIM > const &b)
 
template<typename T , std::size_t DIM>
bool operator< (TemplatePoint< T, DIM > const &a, TemplatePoint< T, DIM > const &b)
 
template<typename T , std::size_t DIM>
bool lessEq (TemplatePoint< T, DIM > const &a, TemplatePoint< T, DIM > const &b, double eps=std::numeric_limits< double >::epsilon())
 
template<typename T >
maxNormDist (const MathLib::TemplatePoint< T > *p0, const MathLib::TemplatePoint< T > *p1)
 
template<typename T , std::size_t DIM>
std::ostream & operator<< (std::ostream &os, const TemplatePoint< T, DIM > &p)
 
template<typename T , std::size_t DIM>
std::istream & operator>> (std::istream &is, TemplatePoint< T, DIM > &p)
 
double scalarTriple (MathLib::Vector3 const &u, MathLib::Vector3 const &v, MathLib::Vector3 const &w)
 Calculates the scalar triple (u x v) . w. More...
 
template<typename T >
scalarProduct (TemplateVector3< T > const &v, TemplateVector3< T > const &w)
 
template<typename T1 >
TemplateVector3< T1 > crossProduct (TemplateVector3< T1 > const &v, TemplateVector3< T1 > const &w)
 
template<typename T1 >
TemplateVector3< T1 > operator* (TemplateVector3< T1 > const &v, double s)
 
template<typename T1 >
TemplateVector3< T1 > operator* (double s, TemplateVector3< T1 > const &v)
 

Variables

static const double p = 0.1126879257180162 / 6.
 
static const double q = 0.0734930431163619 / 6.
 
static const double r = 0.0425460207770812 / 6.
 
const Point3d ORIGIN { {{0.0, 0.0, 0.0}} }
 

Typedef Documentation

◆ Point3d

Definition at line 20 of file GeometricBasics.h.

◆ SparsityPattern

template<typename IndexType >
using MathLib::SparsityPattern = typedef std::vector<IndexType>

A vector telling how many nonzeros there are in each global matrix row.

Definition at line 18 of file SparsityPattern.h.

◆ Vector3

using MathLib::Vector3 = typedef TemplateVector3<double>

Definition at line 188 of file Vector3.h.

◆ WeightedPoint1D

using MathLib::WeightedPoint1D = typedef TemplateWeightedPoint<double, double, 1>

Definition at line 37 of file TemplateWeightedPoint.h.

◆ WeightedPoint2D

using MathLib::WeightedPoint2D = typedef TemplateWeightedPoint<double, double, 2>

Definition at line 38 of file TemplateWeightedPoint.h.

◆ WeightedPoint3D

using MathLib::WeightedPoint3D = typedef TemplateWeightedPoint<double, double, 3>

Definition at line 39 of file TemplateWeightedPoint.h.

Enumeration Type Documentation

◆ TriangleTest

Enumerator
GAUSS 
BARYCENTRIC 

Definition at line 22 of file GeometricBasics.h.

◆ VecNormType

enum MathLib::VecNormType
strong

Norm type. Not declared as class type in order to use the members as integers.

Enumerator
NORM1 

$\sum_i |x_i|$

NORM2 

$\sqrt(\sum_i (x_i)^2)$

INFINITY_N 

$\mathrm{max}_i |x_i|$

INVALID 

Definition at line 20 of file LinAlgEnums.h.

Function Documentation

◆ applyKnownSolution() [1/3]

void MathLib::applyKnownSolution ( EigenMatrix A,
EigenVector b,
EigenVector ,
const std::vector< EigenMatrix::IndexType > &  _vec_knownX_id,
const std::vector< double > &  _vec_knownX_x,
double  penalty_scaling = 1e+10 
)

apply known solutions to a system of linear equations

Parameters
ACoefficient matrix
bRHS vector
_vec_knownX_ida vector of known solution entry IDs
_vec_knownX_xa vector of known solutions
penalty_scalingvalue for scaling some matrix and right hand side entries to enforce some conditions

Definition at line 19 of file EigenTools.cpp.

References anonymous_namespace{Density100MPa.cpp}::c, MathLib::EigenMatrix::getRawMatrix(), and MathLib::EigenVector::getRawVector().

Referenced by NumLib::TimeDiscretizedODESystem< ODESystemTag::FirstOrderImplicitQuasilinear, NonlinearSolverTag::Newton >::applyKnownSolutionsNewton(), and NumLib::TimeDiscretizedODESystem< ODESystemTag::FirstOrderImplicitQuasilinear, NonlinearSolverTag::Picard >::applyKnownSolutionsPicard().

22 {
23  using SpMat = EigenMatrix::RawMatrixType;
24  static_assert(SpMat::IsRowMajor, "matrix is assumed to be row major!");
25 
26  auto &A = A_.getRawMatrix();
27  auto &b = b_.getRawVector();
28 
29  // A(k, j) = 0.
30  // set row to zero
31  for (auto row_id : vec_knownX_id)
32  for (SpMat::InnerIterator it(A,row_id); it; ++it) {
33  if (it.col() != decltype(it.col())(row_id)) it.valueRef() = 0.0;
34  }
35 
36  SpMat AT = A.transpose();
37 
38  for (std::size_t ix=0; ix<vec_knownX_id.size(); ix++)
39  {
40  SpMat::Index const row_id = vec_knownX_id[ix];
41  auto const x = vec_knownX_x[ix];
42 
43  // b_i -= A(i,k)*val, i!=k
44  // set column to zero, subtract from rhs
45  for (SpMat::InnerIterator it(AT, row_id); it; ++it)
46  {
47  if (it.col() == row_id) continue;
48 
49  b[it.col()] -= it.value()*x;
50  it.valueRef() = 0.0;
51  }
52 
53  auto& c = AT.coeffRef(row_id, row_id);
54  if (c != 0.0) {
55  b[row_id] = x * c;
56  } else {
57  b[row_id] = x;
58  c = 1.0;
59  }
60  }
61 
62  A = AT.transpose();
63 }

◆ applyKnownSolution() [2/3]

void MathLib::applyKnownSolution ( PETScMatrix A,
PETScVector b,
PETScVector x,
const std::vector< PetscInt > &  vec_knownX_id,
const std::vector< PetscScalar > &  vec_knownX_x 
)

apply known solutions to a system of linear equations

Parameters
ACoefficient matrix
bRHS vector
xSolution vector
vec_knownX_idA vector of known solution entry IDs
vec_knownX_xA vector of known solutions

Definition at line 21 of file PETScTools.cpp.

References MathLib::PETScMatrix::finalizeAssembly(), MathLib::PETScVector::finalizeAssembly(), MathLib::PETScVector::set(), and MathLib::PETScMatrix::setRowsColumnsZero().

24 {
25  A.finalizeAssembly();
26 
27  A.setRowsColumnsZero(vec_knownX_id);
28  A.finalizeAssembly();
29 
30  x.finalizeAssembly();
31  b.finalizeAssembly();
32  if (vec_knownX_id.size() > 0)
33  {
34  x.set(vec_knownX_id, vec_knownX_x);
35  b.set(vec_knownX_id, vec_knownX_x);
36  }
37 
38  x.finalizeAssembly();
39  b.finalizeAssembly();
40 }

◆ applyKnownSolution() [3/3]

void MathLib::applyKnownSolution ( Eigen::MatrixXd &  A,
Eigen::VectorXd &  b,
Eigen::VectorXd &  ,
const std::vector< Eigen::MatrixXd::Index > &  _vec_knownX_id,
const std::vector< double > &  _vec_knownX_x,
double  penalty_scaling = 1e+10 
)
inline

Definition at line 37 of file EigenTools.h.

References OGS_FATAL.

40 {
41  (void) A; (void) b; (void) _vec_knownX_id; (void) _vec_knownX_x;
42  (void) penalty_scaling;
43 
44  OGS_FATAL("Method not implemented."); // TODO implement
45 }
#define OGS_FATAL(fmt,...)
Definition: Error.h:71

◆ barycentricPointInTriangle()

bool MathLib::barycentricPointInTriangle ( MathLib::Point3d const &  p,
MathLib::Point3d const &  a,
MathLib::Point3d const &  b,
MathLib::Point3d const &  c,
double  eps_pnt_out_of_plane = std::numeric_limits< float >::epsilon(),
double  eps_pnt_out_of_tri = std::numeric_limits< float >::epsilon() 
)

Tests if the given point p is within the triangle, defined by its edge nodes a, b and c. Using two eps-values it is possible to test an 'epsilon' neighbourhood around the triangle as well as an 'epsilon' outside the triangles plane. Algorithm based on "Fundamentals of Computer Graphics" by Peter Shirley.

Parameters
ptest point
aedge node of triangle
bedge node of triangle
cedge node of triangle
eps_pnt_out_of_planeeps allowing for p to be slightly off the plane spanned by abc
eps_pnt_out_of_trieps allowing for p to be slightly off outside of abc
Returns
true if the test point p is within the 'epsilon'-neighbourhood of the triangle

Definition at line 142 of file GeometricBasics.cpp.

References calcTriangleArea(), crossProduct(), and orientation3d().

Referenced by isPointInTriangle().

148 {
149  if (std::abs(MathLib::orientation3d(p, a, b, c)) > eps_pnt_out_of_plane)
150  return false;
151 
152  MathLib::Vector3 const pa(p, a);
153  MathLib::Vector3 const pb(p, b);
154  MathLib::Vector3 const pc(p, c);
155  double const area_x_2(calcTriangleArea(a, b, c) * 2);
156 
157  double const alpha((MathLib::crossProduct(pb, pc).getLength()) / area_x_2);
158  if (alpha < -eps_pnt_out_of_tri || alpha > 1 + eps_pnt_out_of_tri)
159  return false;
160  double const beta((MathLib::crossProduct(pc, pa).getLength()) / area_x_2);
161  if (beta < -eps_pnt_out_of_tri || beta > 1 + eps_pnt_out_of_tri)
162  return false;
163  double const gamma(1 - alpha - beta);
164  return !(gamma < -eps_pnt_out_of_tri || gamma > 1 + eps_pnt_out_of_tri);
165 }
TemplateVector3< T1 > crossProduct(TemplateVector3< T1 > const &v, TemplateVector3< T1 > const &w)
Definition: Vector3.h:164
double orientation3d(MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c)
static const double p
double calcTriangleArea(MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c)

◆ calcProjPntToLineAndDists()

double MathLib::calcProjPntToLineAndDists ( const double  p[3],
const double  a[3],
const double  b[3],
double &  lambda,
double &  d0 
)

calcProjPntToLineAndDists computes the orthogonal projection of a point p to the line described by the points a and b, $g(\lambda) = a + \lambda (b - a)$, the distance between p and the projected point and the distances between the projected point and the end points a, b of the line

Parameters
pthe (mesh) point
afirst point of line
bsecond point of line
lambdathe projected point described by the line equation above
d0distance to the line point a
Returns
the distance between p and the orthogonal projection of p

Definition at line 18 of file MathTools.cpp.

References scalarProduct< double, 3 >(), sqrDist(), and MaterialPropertyLib::u.

Referenced by GeoLib::Polyline::getDistanceAlongPolyline(), MeshLib::LineRule2::isPntInElement(), and scalarProduct().

20 {
21  // g (lambda) = a + lambda v, v = b-a
22  double v[3] = {b[0] - a[0], b[1] - a[1], b[2] - a[2]};
23  // orthogonal projection: (g(lambda)-p) * v = 0 => in order to compute lambda we define a help vector u
24  double u[3] = {p[0] - a[0], p[1] - a[1], p[2] - a[2]};
25  lambda = scalarProduct<double,3> (u, v) / scalarProduct<double,3> (v, v);
26 
27  // compute projected point
28  double proj_pnt[3];
29  for (std::size_t k(0); k < 3; k++)
30  proj_pnt[k] = a[k] + lambda * v[k];
31 
32  d0 = std::sqrt (sqrDist (proj_pnt, a));
33 
34  return std::sqrt (sqrDist (p, proj_pnt));
35 }
double sqrDist(const double *p0, const double *p1)
Definition: MathTools.h:77
double scalarProduct< double, 3 >(double const *const v0, double const *const v1)
Definition: MathTools.h:39
static const double p

◆ calcTetrahedronVolume()

double MathLib::calcTetrahedronVolume ( MathLib::Point3d const &  x1,
MathLib::Point3d const &  x2,
MathLib::Point3d const &  x3,
MathLib::Point3d const &  x4 
)

Calculates the volume of a tetrahedron. The formula is V=1/6*|a(b x c)| with a=x1->x2, b=x1->x3 and c=x1->x4.

Definition at line 33 of file GeometricBasics.cpp.

References scalarTriple().

Referenced by MeshLib::TetRule4::computeVolume(), MeshLib::HexRule8::computeVolume(), MeshLib::PyramidRule5::computeVolume(), and MeshLib::PrismRule6::computeVolume().

37 {
38  const MathLib::Vector3 ab(a, b);
39  const MathLib::Vector3 ac(a, c);
40  const MathLib::Vector3 ad(a, d);
41  return std::abs(MathLib::scalarTriple(ac, ad, ab)) / 6.0;
42 }
double scalarTriple(MathLib::Vector3 const &u, MathLib::Vector3 const &v, MathLib::Vector3 const &w)
Calculates the scalar triple (u x v) . w.
Definition: Vector3.cpp:16

◆ calcTriangleArea()

double MathLib::calcTriangleArea ( MathLib::Point3d const &  a,
MathLib::Point3d const &  b,
MathLib::Point3d const &  c 
)

Calculates the area of the triangle defined by its edge nodes a, b and c. The formula is $A= \frac{1}{2} \cdot |u \times v|$, i.e. half of the area of the parallelogram specified by the vectors $u=b-a$ and $v=c-a$.

Definition at line 44 of file GeometricBasics.cpp.

References crossProduct(), MathLib::TemplateVector3< T >::getLength(), and MaterialPropertyLib::u.

Referenced by barycentricPointInTriangle(), MeshLib::QuadRule4::computeVolume(), MeshLib::TriRule3::computeVolume(), NumLib::LinearInterpolationOnSurface::interpolateInTri(), and GeoLib::IO::TINInterface::readTIN().

46 {
47  MathLib::Vector3 const u(a, c);
48  MathLib::Vector3 const v(a, b);
50  return 0.5 * w.getLength();
51 }
TemplateVector3< T1 > crossProduct(TemplateVector3< T1 > const &v, TemplateVector3< T1 > const &w)
Definition: Vector3.h:164

◆ checkLisError()

bool MathLib::checkLisError ( int  err)
inline

check Lis error codes

Parameters
errLis error code
Returns
success or not

Definition at line 30 of file LisCheck.h.

Referenced by finalizeMatrixAssembly(), MathLib::LisMatrix::getMaxDiagCoeff(), MathLib::LisMatrix::LisMatrix(), MathLib::SetMatrixSparsity< LisMatrix, SPARSITY_PATTERN >::operator()(), MathLib::LisMatrix::setZero(), MathLib::LisVector::size(), MathLib::LisLinearSolver::solve(), and MathLib::LisMatrix::~LisMatrix().

31 {
32  bool ok = (err == LIS_SUCCESS);
33  if (!ok) {
34  ERR("***ERROR: Lis error code = %d", err);
35  }
36  return ok;
37 }

◆ convertStringToVecNormType()

VecNormType MathLib::convertStringToVecNormType ( const std::string &  str)

convert string to VecNormType

Definition at line 28 of file LinAlgEnums.cpp.

References INFINITY_N, INVALID, NORM1, and NORM2.

Referenced by NumLib::createConvergenceCriterionDeltaX(), NumLib::createConvergenceCriterionPerComponentDeltaX(), NumLib::createConvergenceCriterionPerComponentResidual(), and NumLib::createConvergenceCriterionResidual().

29 {
30  if (str == "NORM1") return VecNormType::NORM1;
31  if (str == "NORM2") return VecNormType::NORM2;
32  if (str == "INFINITY_N") return VecNormType::INFINITY_N;
33  return VecNormType::INVALID;
34 }

◆ convertVecNormTypeToString()

std::string MathLib::convertVecNormTypeToString ( VecNormType  normType)

convert VecNormType to string

Definition at line 17 of file LinAlgEnums.cpp.

References INFINITY_N, NORM1, and NORM2.

18 {
19  switch (normType)
20  {
21  case VecNormType::NORM1: return "NORM1";
22  case VecNormType::NORM2: return "NORM2";
23  case VecNormType::INFINITY_N: return "INFINITY_N";
24  default: return "INVALID";
25  }
26 }

◆ createPiecewiseLinearCurve()

template<typename CurveType >
std::unique_ptr< CurveType > MathLib::createPiecewiseLinearCurve ( BaseLib::ConfigTree const &  config)

Create a curve

Parameters
configConfigTree object has a tag of <curve>
Input File Parameter:
curve__coords
Input File Parameter:
curve__values

Definition at line 21 of file CreatePiecewiseLinearCurve-impl.h.

References BaseLib::ConfigTree::getConfigParameter(), and OGS_FATAL.

Referenced by MaterialLib::PorousMedium::createCapillaryPressureModel(), MaterialLib::PorousMedium::createRelativePermeabilityModel(), and ProjectData::parseCurves().

23 {
24  auto x =
26  config.getConfigParameter<std::vector<double>>("coords");
27  auto y =
29  config.getConfigParameter<std::vector<double>>("values");
30 
31  if (x.empty() || y.empty())
32  {
33  OGS_FATAL("The given coordinates or values vector is empty.");
34  }
35  if (x.size() != y.size())
36  {
37  OGS_FATAL(
38  "The given coordinates and values vector sizes are "
39  "different.");
40  }
41  return std::make_unique<CurveType>(std::move(x), std::move(y));
42 }
#define OGS_FATAL(fmt,...)
Definition: Error.h:71

◆ createZeroedMatrix()

template<typename Matrix >
Eigen::Map< Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > > MathLib::createZeroedMatrix ( std::vector< double > &  data,
Eigen::MatrixXd::Index  rows,
Eigen::MatrixXd::Index  cols 
)
inline

Creates an Eigen mapped matrix having its entries stored in the given data vector.

Returns
An Eigen mapped matrix of the given size. All values of the matrix are set to zero.
Precondition
The passed data vector must have zero size.
Postcondition
The data has size rows * cols.
Note
The data vector will have the same storage order (row or column major) as the requested matrix type.

Creates an Eigen mapped matrix having its entries stored in the given data vector.

This is a convienence method which makes the specification of dynamically allocated Eigen matrices as return type easier.

Definition at line 31 of file EigenMapTools.h.

Referenced by ProcessLib::RichardsMechanics::RichardsMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::assemble(), ProcessLib::CentralDifferencesJacobianAssembler::assembleWithJacobian(), ProcessLib::RichardsMechanics::RichardsMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::assembleWithJacobian(), ProcessLib::HydroMechanics::HydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::assembleWithJacobian(), ProcessLib::ThermoMechanicalPhaseField::ThermoMechanicalPhaseFieldLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::assembleWithJacobianForDeformationEquations(), ProcessLib::HydroMechanics::HydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::assembleWithJacobianForDeformationEquations(), ProcessLib::ThermoMechanicalPhaseField::ThermoMechanicalPhaseFieldLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::assembleWithJacobianForHeatConductionEquations(), ProcessLib::ThermoMechanicalPhaseField::ThermoMechanicalPhaseFieldLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::assembleWithJacobianForPhaseFieldEquations(), ProcessLib::HydroMechanics::HydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::assembleWithJacobianForPressureEquations(), ProcessLib::ThermoMechanics::ThermoMechanicsLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getEpsilon(), ProcessLib::ThermoMechanics::ThermoMechanicsLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getEpsilonMechanical(), ProcessLib::RichardsComponentTransport::LocalAssemblerData< ShapeFunction, IntegrationMethod, GlobalDim >::getIntPtDarcyVelocity(), ProcessLib::RichardsMechanics::RichardsMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::getIntPtDarcyVelocity(), ProcessLib::TES::TESLocalAssembler< ShapeFunction_, IntegrationMethod_, GlobalDim >::getIntPtDarcyVelocity(), ProcessLib::LiquidFlow::LiquidFlowLocalAssembler< ShapeFunction, IntegrationMethod, GlobalDim >::getIntPtDarcyVelocity(), ProcessLib::GroundwaterFlow::LocalAssemblerData< ShapeFunction, IntegrationMethod, GlobalDim >::getIntPtDarcyVelocity(), ProcessLib::RichardsFlow::LocalAssemblerData< ShapeFunction, IntegrationMethod, GlobalDim >::getIntPtDarcyVelocity(), ProcessLib::HydroMechanics::HydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::getIntPtDarcyVelocity(), ProcessLib::ComponentTransport::LocalAssemblerData< ShapeFunction, IntegrationMethod, GlobalDim >::getIntPtDarcyVelocity(), ProcessLib::HT::HTFEM< ShapeFunction, IntegrationMethod, GlobalDim >::getIntPtDarcyVelocityLocal(), ProcessLib::RichardsMechanics::RichardsMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::getIntPtEpsilon(), ProcessLib::ThermoMechanicalPhaseField::ThermoMechanicalPhaseFieldLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getIntPtEpsilon(), ProcessLib::PhaseField::PhaseFieldLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getIntPtEpsilon(), ProcessLib::SmallDeformation::SmallDeformationLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getIntPtEpsilon(), ProcessLib::ThermoMechanics::ThermoMechanicsLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getIntPtEpsilon(), ProcessLib::SmallDeformationNonlocal::SmallDeformationNonlocalLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getIntPtEpsilon(), ProcessLib::ThermoMechanicalPhaseField::ThermoMechanicalPhaseFieldLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getIntPtHeatFlux(), ProcessLib::RichardsMechanics::RichardsMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::getIntPtSaturation(), ProcessLib::RichardsMechanics::RichardsMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::getIntPtSigma(), ProcessLib::ThermoMechanicalPhaseField::ThermoMechanicalPhaseFieldLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getIntPtSigma(), ProcessLib::PhaseField::PhaseFieldLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getIntPtSigma(), ProcessLib::SmallDeformation::SmallDeformationLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getIntPtSigma(), ProcessLib::ThermoMechanics::ThermoMechanicsLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getIntPtSigma(), ProcessLib::SmallDeformationNonlocal::SmallDeformationNonlocalLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getIntPtSigma(), ProcessLib::SmallDeformation::SmallDeformationLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getSigma(), ProcessLib::ThermoMechanics::ThermoMechanicsLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getSigma(), ProcessLib::SmallDeformationNonlocal::SmallDeformationNonlocalLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getSigma(), and ProcessLib::SmallDeformation::SmallDeformationProcess< DisplacementDim >::initializeConcreteProcess().

34 {
35  static_assert(Matrix::IsRowMajor || Matrix::IsVectorAtCompileTime,
36  "The default storage order in OGS is row major storage for "
37  "dense matrices.");
38  assert(Matrix::RowsAtCompileTime == Eigen::Dynamic ||
39  Matrix::RowsAtCompileTime == rows);
40  assert(Matrix::ColsAtCompileTime == Eigen::Dynamic ||
41  Matrix::ColsAtCompileTime == cols);
42  assert(data.empty()); // in order that resize fills the vector with zeros.
43 
44  data.resize(rows * cols);
45  return {data.data(), rows, cols};
46 }

◆ createZeroedVector()

template<typename Vector >
Eigen::Map<Vector> MathLib::createZeroedVector ( std::vector< double > &  data,
Eigen::VectorXd::Index  size 
)

Creates an Eigen mapped vector having its entries stored in the given data vector.

Returns
An Eigen mapped vector of the given size. All values of the vector are set to zero.
Precondition
The passed data vector must have zero size.
Postcondition
The data has size size.

Definition at line 152 of file EigenMapTools.h.

Referenced by ProcessLib::RichardsMechanics::RichardsMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::assemble(), ProcessLib::RichardsMechanics::RichardsMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::assembleWithJacobian(), ProcessLib::HydroMechanics::HydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::assembleWithJacobian(), ProcessLib::ThermoMechanicalPhaseField::ThermoMechanicalPhaseFieldLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::assembleWithJacobianForDeformationEquations(), ProcessLib::HydroMechanics::HydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::assembleWithJacobianForDeformationEquations(), ProcessLib::ThermoMechanicalPhaseField::ThermoMechanicalPhaseFieldLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::assembleWithJacobianForHeatConductionEquations(), ProcessLib::ThermoMechanicalPhaseField::ThermoMechanicalPhaseFieldLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::assembleWithJacobianForPhaseFieldEquations(), and ProcessLib::HydroMechanics::HydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::assembleWithJacobianForPressureEquations().

154 {
155  static_assert(Vector::IsVectorAtCompileTime, "A vector type is required.");
156  assert(Vector::SizeAtCompileTime == Eigen::Dynamic ||
157  Vector::SizeAtCompileTime == size);
158  assert(data.empty()); // in order that resize fills the vector with zeros.
159 
160  data.resize(size);
161  return {data.data(), size};
162 }

◆ crossProduct()

template<typename T1 >
TemplateVector3<T1> MathLib::crossProduct ( TemplateVector3< T1 > const &  v,
TemplateVector3< T1 > const &  w 
)

crossProduct: implementation of cross product, sometimes called outer product.

Definition at line 164 of file Vector3.h.

References MathLib::TemplatePoint< T >::_x.

Referenced by barycentricPointInTriangle(), calcTriangleArea(), MeshLib::calculateNormalizedSurfaceNormal(), GeoLib::compute3DRotationMatrixToX(), MeshLib::FaceRule::getSurfaceNormal(), isCoplanar(), GeoLib::MinimalBoundingSphere::MinimalBoundingSphere(), and scalarTriple().

167 {
168  return TemplateVector3<T1>(
169  v._x[1] * w._x[2] - v._x[2] * w._x[1],
170  v._x[2] * w._x[0] - v._x[0] * w._x[2],
171  v._x[0] * w._x[1] - v._x[1] * w._x[0]);
172 }

◆ dividedByPlane()

bool MathLib::dividedByPlane ( const MathLib::Point3d a,
const MathLib::Point3d b,
const MathLib::Point3d c,
const MathLib::Point3d d 
)

Checks if a and b can be placed on a plane such that c and d lie on different sides of said plane. (In 2D space this checks if c and d are on different sides of a line through a and b.)

Parameters
afirst point on plane
bsecond point on plane
cfirst point to test
dsecond point to test
Returns
true, if such a plane can be found, false otherwise

Definition at line 187 of file GeometricBasics.cpp.

Referenced by MeshLib::QuadRule4::validate().

189 {
190  for (unsigned x = 0; x < 3; ++x)
191  {
192  const unsigned y = (x + 1) % 3;
193  const double abc =
194  (b[x] - a[x]) * (c[y] - a[y]) - (b[y] - a[y]) * (c[x] - a[x]);
195  const double abd =
196  (b[x] - a[x]) * (d[y] - a[y]) - (b[y] - a[y]) * (d[x] - a[x]);
197 
198  if ((abc > 0 && abd < 0) || (abc < 0 && abd > 0))
199  return true;
200  }
201  return false;
202 }

◆ finalizeMatrixAssembly() [1/3]

template<typename MAT_T >
bool MathLib::finalizeMatrixAssembly ( MAT_T &  )

Definition at line 20 of file FinalizeMatrixAssembly.h.

Referenced by MathLib::LisLinearSolver::solve().

21 {
22  return true;
23 }

◆ finalizeMatrixAssembly() [2/3]

bool MathLib::finalizeMatrixAssembly ( LisMatrix mat)

finish assembly to make this matrix be ready for use

Definition at line 136 of file LisMatrix.cpp.

References MathLib::LisMatrix::_is_assembled, checkLisError(), MathLib::LisMatrix::getMatrixType(), MathLib::LisMatrix::getRawMatrix(), and MathLib::LisMatrix::isAssembled().

137 {
138  LIS_MATRIX &A = mat.getRawMatrix();
139 
140  if (!mat.isAssembled()) {
141  int ierr = lis_matrix_set_type(A, static_cast<int>(mat.getMatrixType()));
142  checkLisError(ierr);
143  ierr = lis_matrix_assemble(A);
144  checkLisError(ierr);
145  mat._is_assembled = true;
146  }
147  return true;
148 }
bool checkLisError(int err)
Definition: LisCheck.h:30

◆ finalizeMatrixAssembly() [3/3]

bool MathLib::finalizeMatrixAssembly ( PETScMatrix mat,
const MatAssemblyType  asm_type = MAT_FINAL_ASSEMBLY 
)

General interface for the matrix assembly.

Parameters
matThe matrix to be finalized.
asm_typeAssmebly type, either MAT_FLUSH_ASSEMBLY or MAT_FINAL_ASSEMBLY.

Definition at line 152 of file PETScMatrix.cpp.

References MathLib::PETScMatrix::finalizeAssembly().

153 {
154  mat.finalizeAssembly(asm_type);
155  return true;
156 }

◆ finalizeVectorAssembly() [1/2]

template<typename VEC_T >
void MathLib::finalizeVectorAssembly ( VEC_T &  )

General function to finalize the vector assembly.

Definition at line 20 of file FinalizeVectorAssembly.h.

Referenced by ProcessLib::GlobalVectorFromNamedFunction::call().

21 {
22 }

◆ finalizeVectorAssembly() [2/2]

void MathLib::finalizeVectorAssembly ( PETScVector vec)

Function to finalize the vector assembly.

Definition at line 312 of file PETScVector.cpp.

References MathLib::PETScVector::finalizeAssembly().

313 {
314  vec.finalizeAssembly();
315 }

◆ gaussPointInTriangle()

bool MathLib::gaussPointInTriangle ( MathLib::Point3d const &  p,
MathLib::Point3d const &  a,
MathLib::Point3d const &  b,
MathLib::Point3d const &  c,
double  eps_pnt_out_of_plane = std::numeric_limits< float >::epsilon(),
double  eps_pnt_out_of_tri = std::numeric_limits< float >::epsilon() 
)

Tests if the given point p is within the triangle, defined by its edge nodes a, b and c. Using two eps-values it is possible to test an 'epsilon' neighbourhood around the triangle as well as an 'epsilon' outside the triangles plane.

Parameters
ptest point
aedge node of triangle
bedge node of triangle
cedge node of triangle
eps_pnt_out_of_planeeps allowing for p to be slightly off the plane spanned by abc ((orthogonal distance to the plane spaned by triangle)
eps_pnt_out_of_trieps allowing for p to be slightly off outside of abc
Returns
true if the test point p is within the 'epsilon'-neighbourhood of the triangle

Definition at line 105 of file GeometricBasics.cpp.

References MathLib::TemplateVector3< T >::getSqrLength(), and sqrDist().

Referenced by isPointInTriangle().

111 {
112  MathLib::Vector3 const v(a, b);
113  MathLib::Vector3 const w(a, c);
114 
115  Eigen::Matrix2d mat;
116  mat(0, 0) = v.getSqrLength();
117  mat(0, 1) = v[0] * w[0] + v[1] * w[1] + v[2] * w[2];
118  mat(1, 0) = mat(0, 1);
119  mat(1, 1) = w.getSqrLength();
120  Eigen::Vector2d y;
121  y << v[0] * (q[0] - a[0]) + v[1] * (q[1] - a[1]) + v[2] * (q[2] - a[2]),
122  w[0] * (q[0] - a[0]) + w[1] * (q[1] - a[1]) + w[2] * (q[2] - a[2]);
123 
124  y = mat.partialPivLu().solve(y);
125 
126  const double lower(eps_pnt_out_of_tri);
127  const double upper(1 + lower);
128 
129  if (-lower <= y[0] && y[0] <= upper && -lower <= y[1] && y[1] <= upper &&
130  y[0] + y[1] <= upper)
131  {
132  MathLib::Point3d const q_projected(std::array<double, 3>{
133  {a[0] + y[0] * v[0] + y[1] * w[0], a[1] + y[0] * v[1] + y[1] * w[1],
134  a[2] + y[0] * v[2] + y[1] * w[2]}});
135  if (MathLib::sqrDist(q, q_projected) <= eps_pnt_out_of_plane)
136  return true;
137  }
138 
139  return false;
140 }
double sqrDist(const double *p0, const double *p1)
Definition: MathTools.h:77
static const double q

◆ getAngle()

double MathLib::getAngle ( const double  p0[3],
const double  p1[3],
const double  p2[3] 
)

Let $p_0, p_1, p_2 \in R^3$. The function getAngle computes the angle between the edges $(p_0,p_1)$ and $(p_1,p_2)$

Parameters
p0start point of edge 0
p1end point of edge 0 and start point of edge 1
p2end point of edge 1
Returns
the angle between the edges

Definition at line 37 of file MathTools.cpp.

References scalarProduct< double, 3 >().

Referenced by MeshLib::AngleSkewMetric::getMinMaxAngleFromQuad(), MeshLib::AngleSkewMetric::getMinMaxAngleFromTriangle(), and sqrDist().

38 {
39  const double v0[3] = {p0[0]-p1[0], p0[1]-p1[1], p0[2]-p1[2]};
40  const double v1[3] = {p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2]};
41 
42  // apply Cauchy Schwarz inequality
43  return std::acos (scalarProduct<double,3> (v0,v1) / (std::sqrt(scalarProduct<double,3>(v0,v0)) * sqrt(scalarProduct<double,3>(v1,v1))));
44 }
double scalarProduct< double, 3 >(double const *const v0, double const *const v1)
Definition: MathTools.h:39

◆ ignoreOtherLinearSolvers()

void MathLib::ignoreOtherLinearSolvers ( BaseLib::ConfigTree const &  config,
std::string const &  solver_name 
)

Ignore linear solver settings not needed for the selected one.

The project files support specifying linear solver options for all known solver libraries (currently PETSC, LIS, Eigen) even though for a specific build only one of those settings is used. That clearly conflicts with the requirement of the config tree that each setting present in the project file must be read exactly once.

The purpose of this function is to explicitly ignore all the settings that are not relevant for the currently used linear solver

Parameters
configThe config tree snippet for the linear solver.
solver_nameThe tag under which the relevant configuration is found. All other configurations will be ignored.

This function is currently used in the option parsing code of our EigenLinearSolver, LisOption and PETScLinearSolver

Definition at line 17 of file LinearSolverOptions.cpp.

References BaseLib::ConfigTree::ignoreConfigParameter(), and known_linear_solvers.

Referenced by MathLib::LisOption::LisOption(), MathLib::PETScLinearSolver::PETScLinearSolver(), and MathLib::EigenLinearSolver::setOption().

19 {
20  for (auto const& s : known_linear_solvers) {
21  if (s!=solver_name) config.ignoreConfigParameter(s);
22  }
23 }
static std::set< std::string > known_linear_solvers
void ignoreConfigParameter(std::string const &param) const
Definition: ConfigTree.cpp:182

◆ initGLTet3X()

static std::array<std::array<double, 3>, GaussLegendreTet<3>::NPoints> MathLib::initGLTet3X ( )
static

Definition at line 29 of file GaussLegendreTet.cpp.

References anonymous_namespace{Density100MPa.cpp}::c.

30 {
31  // Cf. Gellert, M., Harbord, R., 1991. Moderate degree cubature formulas for
32  // 3-D tetrahedral finite-element approximations. Communications in Applied
33  // Numerical Methods 7, 487-495. doi:10.1002/cnm.1630070609
34  const double a = 0.0673422422100983;
35  const double b = 0.3108859192633005;
36  const double c = 0.7217942490673264;
37  const double d = 0.0927352503108912;
38  const double e = 0.4544962958743506;
39  const double f = 0.045503704125649;
40 
41  return {{{{a, b, b}},
42  {{b, a, b}},
43  {{b, b, a}},
44  {{b, b, b}},
45  {{c, d, d}},
46  {{d, c, d}},
47  {{d, d, c}},
48  {{d, d, d}},
49  {{e, e, f}},
50  {{e, f, e}},
51  {{e, f, f}},
52  {{f, e, e}},
53  {{f, e, f}},
54  {{f, f, e}}}};
55 }

◆ isCoplanar()

bool MathLib::isCoplanar ( const MathLib::Point3d a,
const MathLib::Point3d b,
const MathLib::Point3d c,
const MathLib::Point3d d 
)

Checks if the four given points are located on a plane.

Definition at line 204 of file GeometricBasics.cpp.

References crossProduct(), MathLib::TemplateVector3< T >::getSqrLength(), and scalarProduct().

Referenced by MeshLib::MeshRevision::constructFourNodeElement(), GeoLib::Polyline::getGeoType(), GeoLib::Polyline::isCoplanar(), GeoLib::lineSegmentIntersect(), GeoLib::MinimalBoundingSphere::MinimalBoundingSphere(), MeshLib::MeshRevision::reducePrism(), and MeshLib::QuadRule4::validate().

206 {
207  const MathLib::Vector3 ab(a, b);
208  const MathLib::Vector3 ac(a, c);
209  const MathLib::Vector3 ad(a, d);
210 
211  if (ab.getSqrLength() < pow(std::numeric_limits<double>::epsilon(), 2) ||
212  ac.getSqrLength() < pow(std::numeric_limits<double>::epsilon(), 2) ||
213  ad.getSqrLength() < pow(std::numeric_limits<double>::epsilon(), 2))
214  {
215  return true;
216  }
217 
218  // In exact arithmetic <ac*ad^T, ab> should be zero
219  // if all four points are coplanar.
220  const double sqr_scalar_triple(
221  pow(MathLib::scalarProduct(MathLib::crossProduct(ac, ad), ab), 2));
222  // Due to evaluating the above numerically some cancellation or rounding
223  // can occur. For this reason a normalisation factor is introduced.
224  const double normalisation_factor =
225  (ab.getSqrLength() * ac.getSqrLength() * ad.getSqrLength());
226 
227  // tolerance 1e-11 is choosen such that
228  // a = (0,0,0), b=(1,0,0), c=(0,1,0) and d=(1,1,1e-6) are considered as
229  // coplanar
230  // a = (0,0,0), b=(1,0,0), c=(0,1,0) and d=(1,1,1e-5) are considered as not
231  // coplanar
232  return (sqr_scalar_triple / normalisation_factor < 1e-11);
233 }
TemplateVector3< T1 > crossProduct(TemplateVector3< T1 > const &v, TemplateVector3< T1 > const &w)
Definition: Vector3.h:164
T scalarProduct(T const *const v0, T const *const v1)
Definition: MathTools.h:28

◆ isPointInTetrahedron()

bool MathLib::isPointInTetrahedron ( MathLib::Point3d const &  p,
MathLib::Point3d const &  a,
MathLib::Point3d const &  b,
MathLib::Point3d const &  c,
MathLib::Point3d const &  d,
double  eps = std::numeric_limits< double >::epsilon() 
)

Tests if the given point p is located within a tetrahedron spanned by points a, b, c, d. If the tet specified by a, b, c, d is degenerated (i.e. all points are coplanar) the function will return false because there is no meaningful concept of "inside" for such elements.

Parameters
ptest point
aedge node of tetrahedron
bedge node of tetrahedron
cedge node of tetrahedron
dedge node of tetrahedron
epsAccounts for numerical inaccuracies by allowing a point to be slightly outside of the element and still be regarded as inside.
Returns
true if the test point p is not located outside of abcd (i.e. inside or on a plane/edge).

Definition at line 53 of file GeometricBasics.cpp.

References orientation3d().

Referenced by MeshLib::TetRule4::isPntInElement(), MeshLib::HexRule8::isPntInElement(), MeshLib::PyramidRule5::isPntInElement(), and MeshLib::PrismRule6::isPntInElement().

56 {
57  double const d0 (MathLib::orientation3d(d,a,b,c));
58  // if tetrahedron is not coplanar
59  if (std::abs(d0) > std::numeric_limits<double>::epsilon())
60  {
61  bool const d0_sign (d0>0);
62  // if p is on the same side of bcd as a
63  double const d1 (MathLib::orientation3d(d, p, b, c));
64  if (!(d0_sign == (d1>=0) || std::abs(d1) < eps))
65  return false;
66  // if p is on the same side of acd as b
67  double const d2 (MathLib::orientation3d(d, a, p, c));
68  if (!(d0_sign == (d2>=0) || std::abs(d2) < eps))
69  return false;
70  // if p is on the same side of abd as c
71  double const d3 (MathLib::orientation3d(d, a, b, p));
72  if (!(d0_sign == (d3>=0) || std::abs(d3) < eps))
73  return false;
74  // if p is on the same side of abc as d
75  double const d4 (MathLib::orientation3d(p, a, b, c));
76  return d0_sign == (d4 >= 0) || std::abs(d4) < eps;
77  }
78  return false;
79 }
double orientation3d(MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c)
static const double p

◆ isPointInTriangle()

bool MathLib::isPointInTriangle ( MathLib::Point3d const &  p,
MathLib::Point3d const &  a,
MathLib::Point3d const &  b,
MathLib::Point3d const &  c,
double  eps_pnt_out_of_plane = std::numeric_limits< float >::epsilon(),
double  eps_pnt_out_of_tri = std::numeric_limits< float >::epsilon(),
MathLib::TriangleTest  algorithm = MathLib::GAUSS 
)

Tests if the given point p is within the triangle, defined by its edge nodes a, b and c.Using two eps-values it is possible to test an 'epsilon' neighbourhood around the triangle as well as an 'epsilon' outside the triangles plane.

Parameters
ptest point
aedge node of triangle
bedge node of triangle
cedge node of triangle
eps_pnt_out_of_planeeps allowing for p to be slightly off the plane spanned by abc
eps_pnt_out_of_trieps allowing for p to be slightly off outside of abc
algorithmdefines the method to use
Returns
true if the test point p is within the 'epsilon'-neighbourhood of the triangle

Definition at line 81 of file GeometricBasics.cpp.

References BARYCENTRIC, barycentricPointInTriangle(), GAUSS, and gaussPointInTriangle().

Referenced by GeoLib::Triangle::containsPoint(), MeshLib::QuadRule4::isPntInElement(), and MeshLib::TriRule3::isPntInElement().

88 {
89  switch (algorithm)
90  {
91  case MathLib::GAUSS:
92  return gaussPointInTriangle(p, a, b, c, eps_pnt_out_of_plane,
93  eps_pnt_out_of_tri);
95  return barycentricPointInTriangle(p, a, b, c, eps_pnt_out_of_plane,
96  eps_pnt_out_of_tri);
97  default:
98  ERR("Selected algorithm for point in triangle testing not found, "
99  "falling back on default.");
100  }
101  return gaussPointInTriangle(p, a, b, c, eps_pnt_out_of_plane,
102  eps_pnt_out_of_tri);
103 }
bool gaussPointInTriangle(MathLib::Point3d const &q, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c, double eps_pnt_out_of_plane, double eps_pnt_out_of_tri)
static const double p
bool barycentricPointInTriangle(MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c, double eps_pnt_out_of_plane, double eps_pnt_out_of_tri)

◆ isPointInTriangleXY()

bool MathLib::isPointInTriangleXY ( MathLib::Point3d const &  p,
MathLib::Point3d const &  a,
MathLib::Point3d const &  b,
MathLib::Point3d const &  c 
)

Checks if the point $p'$ is in the triangle defined by the points $a', b', c'$, where the $p', a', b', c' $ are the orthogonal projections to the $x$- $y$ plane of the points $p, a, b, c$, respectively.

Definition at line 167 of file GeometricBasics.cpp.

Referenced by MeshLib::isPointInElementXY().

171 {
172  // criterion: p-a = u0 * (b-a) + u1 * (c-a); 0 <= u0, u1 <= 1, u0+u1 <= 1
173  Eigen::Matrix2d mat;
174  mat(0, 0) = b[0] - a[0];
175  mat(0, 1) = c[0] - a[0];
176  mat(1, 0) = b[1] - a[1];
177  mat(1, 1) = c[1] - a[1];
178  Eigen::Vector2d y;
179  y << p[0] - a[0], p[1] - a[1];
180 
181  y = mat.partialPivLu().solve(y);
182 
183  // check if u0 and u1 fulfills the condition
184  return 0 <= y[0] && y[0] <= 1 && 0 <= y[1] && y[1] <= 1 && y[0] + y[1] <= 1;
185 }
static const double p

◆ lessEq()

template<typename T , std::size_t DIM>
bool MathLib::lessEq ( TemplatePoint< T, DIM > const &  a,
TemplatePoint< T, DIM > const &  b,
double  eps = std::numeric_limits<double>::epsilon() 
)

Lexicographic comparison of points taking an epsilon into account.

Parameters
afirst input point.
bsecond input point.
epstolerance used in comparison of coordinates.
Returns
true, if a is smaller then or equal to b according to the following test $ |a_i - b_i| > \epsilon \cdot \min (|a_i|, |b_i|) $ and $ |a_i - b_i| > \epsilon $ for all coordinates $ 0 \le i < \textrm{DIM} $.

Definition at line 151 of file TemplatePoint.h.

References MaterialPropertyLib::u.

153 {
154  auto coordinateIsLargerEps = [&eps](T const u, T const v) -> bool
155  {
156  return std::fabs(u - v) > eps * std::min(std::fabs(v), std::fabs(u)) &&
157  std::fabs(u - v) > eps;
158  };
159 
160  for (std::size_t i = 0; i < DIM; ++i)
161  {
162  // test a relative and an absolute criterion
163  if (coordinateIsLargerEps(a[i], b[i]))
164  {
165  return static_cast<bool>(a[i] <= b[i]);
166  }
167  // a[i] ~= b[i] up to an epsilon. Compare next dimension.
168  }
169 
170  // all coordinates are equal up to an epsilon.
171  return true;
172 }

◆ limitValueInInterval()

template<typename Type >
Type MathLib::limitValueInInterval ( const Type  variable,
const Type  lower_bound,
const Type  upper_bound 
)

Definition at line 98 of file MathTools.h.

Referenced by MaterialLib::PorousMedium::CapillaryPressureSaturationCurve::getCapillaryPressure(), MaterialLib::PorousMedium::BrooksCoreyCapillaryPressureSaturation::getCapillaryPressure(), MaterialLib::PorousMedium::VanGenuchtenCapillaryPressureSaturation::getCapillaryPressure(), MaterialLib::PorousMedium::VanGenuchtenCapillaryPressureSaturation::getd2PcdS2(), MaterialLib::PorousMedium::CapillaryPressureSaturationCurve::getdPcdS(), MaterialLib::PorousMedium::BrooksCoreyCapillaryPressureSaturation::getdPcdS(), MaterialLib::PorousMedium::VanGenuchtenCapillaryPressureSaturation::getdPcdS(), MaterialLib::PorousMedium::RelativePermeabilityCurve::getdValue(), MaterialLib::PorousMedium::WettingPhaseBrooksCoreyOilGas::getdValue(), MaterialLib::PorousMedium::WettingPhaseVanGenuchten::getdValue(), MaterialLib::PorousMedium::NonWettingPhaseBrooksCoreyOilGas::getdValue(), MaterialLib::PorousMedium::NonWettingPhaseVanGenuchten::getdValue(), MaterialLib::PorousMedium::CapillaryPressureSaturationCurve::getSaturation(), MaterialLib::PorousMedium::BrooksCoreyCapillaryPressureSaturation::getSaturation(), MaterialLib::PorousMedium::VanGenuchtenCapillaryPressureSaturation::getSaturation(), MaterialLib::PorousMedium::RelativePermeabilityCurve::getValue(), MaterialLib::PorousMedium::WettingPhaseBrooksCoreyOilGas::getValue(), MaterialLib::PorousMedium::WettingPhaseVanGenuchten::getValue(), MaterialLib::PorousMedium::NonWettingPhaseBrooksCoreyOilGas::getValue(), and MaterialLib::PorousMedium::NonWettingPhaseVanGenuchten::getValue().

101 {
102  if (variable < lower_bound)
103  return lower_bound;
104  if (variable > upper_bound)
105  return upper_bound;
106  return variable;
107 }

◆ maxNormDist()

template<typename T >
T MathLib::maxNormDist ( const MathLib::TemplatePoint< T > *  p0,
const MathLib::TemplatePoint< T > *  p1 
)

Distance between points p0 and p1 in the maximum norm.

Definition at line 176 of file TemplatePoint.h.

177 {
178  const T x = fabs((*p1)[0] - (*p0)[0]);
179  const T y = fabs((*p1)[1] - (*p0)[1]);
180  const T z = fabs((*p1)[2] - (*p0)[2]);
181 
182  return std::max(x, std::max(y, z));
183 }

◆ operator*() [1/3]

template<typename MATRIX >
MathLib::Point3d MathLib::operator* ( MATRIX const &  mat,
MathLib::Point3d const &  p 
)
inline

rotation of points

Parameters
mata rotation matrix
pa point to be transformed
Returns
a rotated point

Definition at line 35 of file Point3d.h.

Referenced by MathLib::DenseMatrix< double >::operator*().

36 {
37  MathLib::Point3d new_p;
38  for (std::size_t i(0); i<3; ++i) {
39  for (std::size_t j(0); j<3; ++j) {
40  new_p[i] += mat(i,j)*p[j];
41  }
42  }
43  return new_p;
44 }
static const double p

◆ operator*() [2/3]

template<typename T1 >
TemplateVector3<T1> MathLib::operator* ( TemplateVector3< T1 > const &  v,
double  s 
)

multiplication with a scalar s

Definition at line 174 of file Vector3.h.

177 {
178  return TemplateVector3<T1>(v[0] * s, v[1] * s, v[2] * s);
179 }

◆ operator*() [3/3]

template<typename T1 >
TemplateVector3<T1> MathLib::operator* ( double  s,
TemplateVector3< T1 > const &  v 
)

Definition at line 181 of file Vector3.h.

184 {
185  return v * s;
186 }

◆ operator<()

template<typename T , std::size_t DIM>
bool MathLib::operator< ( TemplatePoint< T, DIM > const &  a,
TemplatePoint< T, DIM > const &  b 
)

Definition at line 120 of file TemplatePoint.h.

121 {
122  for (std::size_t i = 0; i < DIM; ++i)
123  {
124  if (a[i] > b[i]) {
125  return false;
126  }
127  if (a[i] < b[i])
128  {
129  return true;
130  }
131 
132  // continue with next dimension, because a[0] == b[0]
133  }
134 
135  // The values in all dimenisions are equal.
136  return false;
137 }

◆ operator<<() [1/2]

template<typename FP_TYPE , typename IDX_TYPE >
std::ostream& MathLib::operator<< ( std::ostream &  os,
const DenseMatrix< FP_TYPE, IDX_TYPE > &  mat 
)

overload the output operator for class DenseMatrix

Definition at line 182 of file DenseMatrix.h.

183 {
184  mat.write (os);
185  return os;
186 }

◆ operator<<() [2/2]

template<typename T , std::size_t DIM>
std::ostream& MathLib::operator<< ( std::ostream &  os,
const TemplatePoint< T, DIM > &  p 
)

overload the output operator for class Point

Definition at line 187 of file TemplatePoint.h.

References p.

188 {
189  p.write (os);
190  return os;
191 }
static const double p

◆ operator==()

template<typename T , std::size_t DIM>
bool MathLib::operator== ( TemplatePoint< T, DIM > const &  a,
TemplatePoint< T, DIM > const &  b 
)

Equality of TemplatePoint's up to an epsilon.

Definition at line 112 of file TemplatePoint.h.

References sqrDist().

113 {
114  T const sqr_dist(sqrDist(a,b));
115  auto const eps = std::numeric_limits<T>::epsilon();
116  return (sqr_dist < eps*eps);
117 }
double sqrDist(const double *p0, const double *p1)
Definition: MathTools.h:77

◆ operator>>()

template<typename T , std::size_t DIM>
std::istream& MathLib::operator>> ( std::istream &  is,
TemplatePoint< T, DIM > &  p 
)

overload the input operator for class Point

Definition at line 195 of file TemplatePoint.h.

196 {
197  p.read (is);
198  return is;
199 }
static const double p

◆ orientation3d()

double MathLib::orientation3d ( MathLib::Point3d const &  p,
MathLib::Point3d const &  a,
MathLib::Point3d const &  b,
MathLib::Point3d const &  c 
)

Checks if a point p is on the left or right side of a plane spanned by three points a, b, c.

Parameters
ppoint to test
afirst point on plane
bsecond point on plane
cthird point on plane
Returns
If the triangle abc is ordered counterclockwise when viewed from p, the method will return a negative value, otherwise it will return a positive value. If p is coplanar with abc, the function will return 0.

Definition at line 22 of file GeometricBasics.cpp.

References scalarTriple().

Referenced by barycentricPointInTriangle(), and isPointInTetrahedron().

26 {
27  MathLib::Vector3 const ap (a, p);
28  MathLib::Vector3 const bp (b, p);
29  MathLib::Vector3 const cp (c, p);
30  return MathLib::scalarTriple(bp,cp,ap);
31 }
double scalarTriple(MathLib::Vector3 const &u, MathLib::Vector3 const &v, MathLib::Vector3 const &w)
Calculates the scalar triple (u x v) . w.
Definition: Vector3.cpp:16
static const double p

◆ scalarProduct() [1/3]

template<typename T , int N>
T MathLib::scalarProduct ( T const *const  v0,
T const *const  v1 
)
inline

standard inner product in R^N

Parameters
v0array of type T representing the vector
v1array of type T representing the vector

Definition at line 28 of file MathTools.h.

Referenced by MeshLib::MeshSurfaceExtraction::get2DSurfaceElements(), GeoLib::getNewellPlane(), isCoplanar(), GeoLib::lineSegmentIntersect(), MeshGeoToolsLib::mapPointOnSurfaceElement(), GeoLib::MinimalBoundingSphere::MinimalBoundingSphere(), MeshLib::projectMeshOntoPlane(), scalarTriple(), and MeshLib::CellRule::testElementNodeOrder().

29 {
30  T res (v0[0] * v1[0]);
31 
32 #pragma omp parallel for reduction (+:res)
33  for (int k = 1; k < N; k++)
34  res += v0[k] * v1[k];
35  return res;
36 }

◆ scalarProduct() [2/3]

template<typename T >
T MathLib::scalarProduct ( T const *const  v0,
T const *const  v1,
int const  n 
)
inline

Definition at line 48 of file MathTools.h.

References calcProjPntToLineAndDists(), and p.

49 {
50  T res (v0[0] * v1[0]);
51 
52 #pragma omp parallel for reduction (+:res)
53  for (int k = 1; k < n; k++)
54  res += v0[k] * v1[k];
55  return res;
56 }

◆ scalarProduct() [3/3]

template<typename T >
T MathLib::scalarProduct ( TemplateVector3< T > const &  v,
TemplateVector3< T > const &  w 
)

Definition at line 158 of file Vector3.h.

References MathLib::TemplatePoint< T >::_x.

159 {
160  return v._x[0] * w._x[0] + v._x[1] * w._x[1] + v._x[2] * w._x[2];
161 }

◆ scalarProduct< double, 3 >()

template<>
double MathLib::scalarProduct< double, 3 > ( double const *const  v0,
double const *const  v1 
)
inline

Definition at line 39 of file MathTools.h.

Referenced by calcProjPntToLineAndDists(), getAngle(), and sqrDist().

40 {
41  double res (v0[0] * v1[0]);
42  for (std::size_t k(1); k < 3; k++)
43  res += v0[k] * v1[k];
44  return res;
45 }

◆ scalarTriple()

double MathLib::scalarTriple ( MathLib::Vector3 const &  u,
MathLib::Vector3 const &  v,
MathLib::Vector3 const &  w 
)

Calculates the scalar triple (u x v) . w.

Definition at line 16 of file Vector3.cpp.

References crossProduct(), and scalarProduct().

Referenced by calcTetrahedronVolume(), GeoLib::MinimalBoundingSphere::MinimalBoundingSphere(), orientation3d(), and GeoLib::triangleLineIntersection().

18 {
19  MathLib::Vector3 const cross(MathLib::crossProduct(u, v));
20  return MathLib::scalarProduct(cross,w);
21 }
TemplateVector3< T1 > crossProduct(TemplateVector3< T1 > const &v, TemplateVector3< T1 > const &w)
Definition: Vector3.h:164
T scalarProduct(T const *const v0, T const *const v1)
Definition: MathTools.h:28

◆ setMatrixSparsity()

template<typename MATRIX , typename SPARSITY_PATTERN >
void MathLib::setMatrixSparsity ( MATRIX &  matrix,
SPARSITY_PATTERN const &  sparsity_pattern 
)

Sets the sparsity pattern of the underlying matrix. To allow partial specialization a SetMatrixSparsity template is instantiated, to which the matrix and the sparsity_pattern are passed.

Definition at line 28 of file SetMatrixSparsity.h.

29 {
30  SetMatrixSparsity<MATRIX, SPARSITY_PATTERN> set_sparsity;
31  set_sparsity(matrix, sparsity_pattern);
32 }

◆ sqrDist() [1/2]

double MathLib::sqrDist ( MathLib::Point3d const &  p0,
MathLib::Point3d const &  p1 
)
inline

Computes the squared dist between the two points p0 and p1.

Definition at line 49 of file Point3d.h.

References scalarProduct< double, 3 >().

50 {
51  const double v[3] = {p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]};
53 }
double scalarProduct< double, 3 >(double const *const v0, double const *const v1)
Definition: MathTools.h:39

◆ sqrDist() [2/2]

double MathLib::sqrDist ( const double *  p0,
const double *  p1 
)
inline

squared dist between double arrays p0 and p1 (size of arrays is 3)

Definition at line 77 of file MathTools.h.

References getAngle(), and scalarProduct< double, 3 >().

Referenced by GeoLib::OctTree< POINT, MAX_POINTS >::addPoint(), GeoLib::Polyline::addPoint(), GeoLib::Grid< MeshLib::Node >::calcNearestPointInGridCell(), calcProjPntToLineAndDists(), MeshLib::EdgeRatioMetric::checkHexahedron(), MeshLib::EdgeRatioMetric::checkPrism(), MeshLib::EdgeRatioMetric::checkPyramid(), MeshLib::EdgeRatioMetric::checkQuad(), MeshLib::EdgeRatioMetric::checkTetrahedron(), MeshLib::EdgeRatioMetric::checkTriangle(), MeshLib::MeshRevision::collapseNodeIndices(), MeshLib::Element::computeSqrEdgeLengthRange(), MeshLib::Element::computeSqrNodeDistanceRange(), MeshLib::LineRule2::computeVolume(), GeoLib::Polygon::containsSegment(), MeshGeoToolsLib::createSubSegmentsForElement(), MeshLib::findElementsWithinRadius(), gaussPointInTriangle(), GeoLib::Polyline::getLocationOfPoint(), GeoLib::Grid< MeshLib::Node >::getNearestPoint(), GeoLib::Grid< MeshLib::Node >::getPointsInEpsilonEnvironment(), GeoLib::Polyline::insertPoint(), MeshLib::PointRule1::isPntInElement(), GeoLib::lineSegmentIntersect(), MeshGeoToolsLib::mapLineSegment(), GeoLib::operator==(), operator==(), GeoLib::MinimalBoundingSphere::pointDistanceSquared(), GeoLib::pointsAreIdentical(), GeoLib::Polyline::removePoint(), GeoLib::PointVec::resetInternalDataStructures(), and GeoLib::sortSegments().

78 {
79  const double v[3] = {p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]};
80  return scalarProduct<double,3>(v,v);
81 }
double scalarProduct< double, 3 >(double const *const v0, double const *const v1)
Definition: MathTools.h:39

◆ sqrDist2d()

double MathLib::sqrDist2d ( MathLib::Point3d const &  p0,
MathLib::Point3d const &  p1 
)
inline

Computes the squared distance between the orthogonal projection of the two points p0 and p1 onto the $xy$-plane.

Definition at line 58 of file Point3d.h.

Referenced by MeshLib::isPointInElementXY(), GeoLib::lineSegmentIntersect2d(), and MeshGeoToolsLib::snapPointToElementNode().

59 {
60  return (p0[0]-p1[0])*(p0[0]-p1[0]) + (p0[1]-p1[1])*(p0[1]-p1[1]);
61 }

◆ sqrFrobNrm()

template<typename FP_TYPE , typename IDX_TYPE >
FP_TYPE MathLib::sqrFrobNrm ( const DenseMatrix< FP_TYPE, IDX_TYPE > &  mat)

Definition at line 337 of file DenseMatrix-impl.h.

References MathLib::DenseMatrix< FP_TYPE, IDX_TYPE >::getNumberOfColumns(), and MathLib::DenseMatrix< FP_TYPE, IDX_TYPE >::getNumberOfRows().

338 {
339  FP_TYPE nrm(static_cast<FP_TYPE>(0));
340  IDX_TYPE i, j;
341  for (j = 0; j < mat.getNumberOfColumns(); j++)
342  for (i = 0; i < mat.getNumberOfRows(); i++)
343  nrm += mat(i, j) * mat(i, j);
344 
345  return nrm;
346 }

◆ to_radians()

double MathLib::to_radians ( double  degrees)
inline

converts the given degrees to radians

Definition at line 94 of file MathTools.h.

Referenced by MaterialLib::Fracture::anonymous_namespace{MohrCoulomb.cpp}::MaterialPropertyValues::MaterialPropertyValues().

94  {
95  return degrees*boost::math::constants::pi<double>()/180.;
96 }

◆ toMatrix() [1/2]

template<typename Matrix >
Eigen::Map< const Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > > MathLib::toMatrix ( std::vector< double > const &  data,
Eigen::MatrixXd::Index  rows,
Eigen::MatrixXd::Index  cols 
)
inline

Creates an Eigen mapped matrix from the given data vector.

Attention
The data vector must have the same storage order (row or column major) as the requested matrix type.

Creates an Eigen mapped matrix from the given data vector.

This is a convienence method which makes the specification of dynamically allocated Eigen matrices as return type easier.

Definition at line 71 of file EigenMapTools.h.

Referenced by ProcessLib::VectorMatrixAssembler::assemble(), ProcessLib::CentralDifferencesJacobianAssembler::assembleWithJacobian(), ProcessLib::CompareJacobiansJacobianAssembler::assembleWithJacobian(), ProcessLib::VectorMatrixAssembler::assembleWithJacobian(), NumLib::LocalLinearLeastSquaresExtrapolator::calculateResidualElement(), NumLib::LocalLinearLeastSquaresExtrapolator::extrapolateElement(), ProcessLib::TES::TESLocalAssembler< ShapeFunction_, IntegrationMethod_, GlobalDim >::getIntPtDarcyVelocity(), and toMatrix().

74 {
75  static_assert(Matrix::IsRowMajor || Matrix::IsVectorAtCompileTime,
76  "The default storage order in OGS is row major storage for "
77  "dense matrices.");
78  assert(Matrix::RowsAtCompileTime == Eigen::Dynamic ||
79  Matrix::RowsAtCompileTime == rows);
80  assert(Matrix::ColsAtCompileTime == Eigen::Dynamic ||
81  Matrix::ColsAtCompileTime == cols);
82  assert(static_cast<Eigen::MatrixXd::Index>(data.size()) == rows * cols);
83 
84  return {data.data(), rows, cols};
85 }

◆ toMatrix() [2/2]

template<typename Matrix >
Eigen::Map< Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > > MathLib::toMatrix ( std::vector< double > &  data,
Eigen::MatrixXd::Index  rows,
Eigen::MatrixXd::Index  cols 
)
inline

Creates an Eigen mapped matrix from the given data vector.

Attention
The data vector must have the same storage order (row or column major) as the requested matrix type.

Creates an Eigen mapped matrix from the given data vector.

This is a convienence method which makes the specification of dynamically allocated Eigen matrices as return type easier.

Definition at line 110 of file EigenMapTools.h.

References toMatrix().

113 {
114  static_assert(Matrix::IsRowMajor || Matrix::IsVectorAtCompileTime,
115  "The default storage order in OGS is row major storage for "
116  "dense matrices.");
117  assert(Matrix::RowsAtCompileTime == Eigen::Dynamic ||
118  Matrix::RowsAtCompileTime == rows);
119  assert(Matrix::ColsAtCompileTime == Eigen::Dynamic ||
120  Matrix::ColsAtCompileTime == cols);
121  assert(static_cast<Eigen::MatrixXd::Index>(data.size()) == rows * cols);
122 
123  return {data.data(), rows, cols};
124 }

◆ toVector() [1/4]

template<typename Vector >
Eigen::Map<const Vector> MathLib::toVector ( std::vector< double > const &  data,
Eigen::VectorXd::Index  size 
)

◆ toVector() [2/4]

template<typename Vector >
Eigen::Map<Vector> MathLib::toVector ( std::vector< double > &  data,
Eigen::VectorXd::Index  size 
)

Creates an Eigen mapped vector from the given data vector.

Definition at line 179 of file EigenMapTools.h.

181 {
182  static_assert(Vector::IsVectorAtCompileTime, "A vector type is required.");
183  assert(Vector::SizeAtCompileTime == Eigen::Dynamic ||
184  Vector::SizeAtCompileTime == size);
185  assert(static_cast<Eigen::VectorXd::Index>(data.size()) == size);
186 
187  return {data.data(), size};
188 }

◆ toVector() [3/4]

Eigen::Map<const Eigen::VectorXd> MathLib::toVector ( std::vector< double > const &  data)
inline

Creates an Eigen mapped vector from the given data vector.

This is a convienence method which makes the specification of dynamically allocated Eigen vectors as return type easier.

Definition at line 195 of file EigenMapTools.h.

197 {
198  return {data.data(), static_cast<Eigen::VectorXd::Index>(data.size())};
199 }

◆ toVector() [4/4]

Eigen::Map<Eigen::VectorXd> MathLib::toVector ( std::vector< double > &  data)
inline

Creates an Eigen mapped vector from the given data vector.

This is a convienence method which makes the specification of dynamically allocated Eigen vectors as return type easier.

Definition at line 206 of file EigenMapTools.h.

208 {
209  return {data.data(), static_cast<Eigen::VectorXd::Index>(data.size())};
210 }

Variable Documentation

◆ ORIGIN

MATHLIB_EXPORT const Point3d MathLib::ORIGIN { {{0.0, 0.0, 0.0}} }

Definition at line 27 of file Point3d.h.

Referenced by MeshLib::getBulkElementPoint().

◆ p

◆ q

◆ r

const double MathLib::r = 0.0425460207770812 / 6.
static

Definition at line 62 of file GaussLegendreTet.cpp.

Referenced by Adsorption::alphaTWaterDean(), ProcessLib::TES::TESLocalAssemblerInner< ProcessLib::detail::LocalAssemblerTraitsFixed >::assembleIntegrationPoint(), ModelTest::checkChildren(), NumLib::ShapeQuad8::computeGradShapeFunction(), NumLib::ShapeHex20::computeGradShapeFunction(), NumLib::ShapePyra13::computeGradShapeFunction(), NumLib::ShapePyra5::computeGradShapeFunction(), NumLib::TemplateIsoparametric< ShapeFunctionType_, ShapeMatrixTypes_ >::computeIntegralMeasure(), NumLib::ShapeHex20::computeShapeFunction(), NumLib::ShapePyra13::computeShapeFunction(), NumLib::ShapePyra5::computeShapeFunction(), DataHolderLib::createColor(), anonymous_namespace{ShapeHex20-impl.h}::dShapeFunctionHexHQ_Middle(), anonymous_namespace{CompareJacobiansJacobianAssembler.cpp}::dump_py(), GeoLib::Raster::getRasterFromSurface(), FileIO::Gocad::Layer::hasRegion(), ProcessLib::TES::TESFEMReactionAdaptorAdsorption::initReaction_slowDownUndershootStrategy(), MaterialLib::Solids::Creep::CreepBGRa< DisplacementDim >::integrateStress(), VtkImageDataToPointCloudFilter::interpolate(), NumLib::TemplateIsoparametric< ShapeFunctionType_, ShapeMatrixTypes_ >::interpolateZerothCoordinate(), anonymous_namespace{MFront.cpp}::MFrontToOGS(), anonymous_namespace{TESLocalAssembler-impl.h}::ogs5OutMat(), anonymous_namespace{TESLocalAssembler-impl.h}::ogs5OutVec(), anonymous_namespace{MFront.cpp}::OGSToMFront(), FileIO::Gocad::Region::operator==(), FileIO::Gocad::parseLayer(), FileIO::Gocad::parseRegion(), FileIO::XmlLutReader::readFromFile(), anonymous_namespace{ShapeHex20-impl.h}::ShapeFunctionHexHQ_Middle(), and VtkRaster::uint32toRGBA().