OGS 6.2.2-87-g988ee9c30.dirty.20200123122242
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

Namespaces

 detail
 
 details
 
 KelvinVector
 
 LinAlg
 
 Nonlinear
 
 ODE
 

Classes

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  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)
 
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 19 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 19 of file SparsityPattern.h.

◆ Vector3

using MathLib::Vector3 = typedef TemplateVector3<double>

Definition at line 197 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 21 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 21 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 20 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().

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

◆ 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 38 of file EigenTools.h.

References OGS_FATAL.

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

◆ 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 149 of file GeometricBasics.cpp.

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

Referenced by isPointInTriangle().

155 {
156  if (std::abs(MathLib::orientation3d(p, a, b, c)) > eps_pnt_out_of_plane)
157  {
158  return false;
159  }
160 
161  MathLib::Vector3 const pa(p, a);
162  MathLib::Vector3 const pb(p, b);
163  MathLib::Vector3 const pc(p, c);
164  double const area_x_2(calcTriangleArea(a, b, c) * 2);
165 
166  double const alpha((MathLib::crossProduct(pb, pc).getLength()) / area_x_2);
167  if (alpha < -eps_pnt_out_of_tri || alpha > 1 + eps_pnt_out_of_tri)
168  {
169  return false;
170  }
171  double const beta((MathLib::crossProduct(pc, pa).getLength()) / area_x_2);
172  if (beta < -eps_pnt_out_of_tri || beta > 1 + eps_pnt_out_of_tri)
173  {
174  return false;
175  }
176  double const gamma(1 - alpha - beta);
177  return !(gamma < -eps_pnt_out_of_tri || gamma > 1 + eps_pnt_out_of_tri);
178 }
TemplateVector3< T1 > crossProduct(TemplateVector3< T1 > const &v, TemplateVector3< T1 > const &w)
Definition: Vector3.h:173
double orientation3d(MathLib::Point3d const &p, MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &c)
static std::vector< std::size_t > getLength(NcVar const &var, bool const is_time_dep)
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 17 of file MathTools.cpp.

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

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

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

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 32 of file GeometricBasics.cpp.

References scalarTriple().

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

36 {
37  const MathLib::Vector3 ab(a, b);
38  const MathLib::Vector3 ac(a, c);
39  const MathLib::Vector3 ad(a, d);
40  return std::abs(MathLib::scalarTriple(ac, ad, ab)) / 6.0;
41 }
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:15

◆ 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 43 of file GeometricBasics.cpp.

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

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

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

◆ 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::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 29 of file LinAlgEnums.cpp.

References INFINITY_N, INVALID, NORM1, and NORM2.

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

30 {
31  if (str == "NORM1")
32  {
33  return VecNormType::NORM1;
34  }
35  if (str == "NORM2")
36  {
37  return VecNormType::NORM2;
38  }
39  if (str == "INFINITY_N")
40  {
41  return VecNormType::INFINITY_N;
42  }
43  return VecNormType::INVALID;
44 }

◆ convertVecNormTypeToString()

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

convert VecNormType to string

Definition at line 18 of file LinAlgEnums.cpp.

References INFINITY_N, NORM1, and NORM2.

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

◆ 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:64

◆ 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 32 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::ThermoHydroMechanics::ThermoHydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::assembleWithJacobian(), ProcessLib::HydroMechanics::HydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::assembleWithJacobian(), ProcessLib::ThermoMechanics::ThermoMechanicsLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::assembleWithJacobianForDeformationEquations(), ProcessLib::ThermoMechanicalPhaseField::ThermoMechanicalPhaseFieldLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::assembleWithJacobianForDeformationEquations(), ProcessLib::HydroMechanics::HydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::assembleWithJacobianForDeformationEquations(), ProcessLib::ThermoMechanics::ThermoMechanicsLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::assembleWithJacobianForHeatConductionEquations(), ProcessLib::ThermoMechanicalPhaseField::ThermoMechanicalPhaseFieldLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::assembleWithJacobianForHeatConductionEquations(), ProcessLib::ThermoMechanicalPhaseField::ThermoMechanicalPhaseFieldLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::assembleWithJacobianForPhaseFieldEquations(), ProcessLib::HydroMechanics::HydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::assembleWithJacobianForPressureEquations(), ProcessLib::ComponentTransport::LocalAssemblerData< ShapeFunction, IntegrationMethod, GlobalDim >::calculateIntPtDarcyVelocity(), ProcessLib::HydroMechanics::HydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::getEpsilon(), ProcessLib::ThermoMechanics::ThermoMechanicsLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getEpsilon(), ProcessLib::ThermoMechanics::ThermoMechanicsLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getEpsilonMechanical(), ProcessLib::RichardsComponentTransport::LocalAssemblerData< ShapeFunction, IntegrationMethod, GlobalDim >::getIntPtDarcyVelocity(), ProcessLib::TES::TESLocalAssembler< ShapeFunction_, IntegrationMethod_, GlobalDim >::getIntPtDarcyVelocity(), ProcessLib::ThermoHydroMechanics::ThermoHydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::getIntPtDarcyVelocity(), ProcessLib::LiquidFlow::LiquidFlowLocalAssembler< ShapeFunction, IntegrationMethod, GlobalDim >::getIntPtDarcyVelocity(), ProcessLib::RichardsMechanics::RichardsMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::getIntPtDarcyVelocity(), ProcessLib::GroundwaterFlow::LocalAssemblerData< ShapeFunction, IntegrationMethod, GlobalDim >::getIntPtDarcyVelocity(), ProcessLib::RichardsFlow::LocalAssemblerData< ShapeFunction, IntegrationMethod, GlobalDim >::getIntPtDarcyVelocity(), ProcessLib::HydroMechanics::HydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::getIntPtDarcyVelocity(), ProcessLib::HT::HTFEM< ShapeFunction, IntegrationMethod, GlobalDim >::getIntPtDarcyVelocityLocal(), ProcessLib::RichardsMechanics::RichardsMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::getIntPtEpsilon(), ProcessLib::ThermoHydroMechanics::ThermoHydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::getIntPtEpsilon(), ProcessLib::ThermoMechanics::ThermoMechanicsLocalAssembler< ShapeFunction, 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::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::ThermoHydroMechanics::ThermoHydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::getIntPtSigma(), ProcessLib::ThermoMechanicalPhaseField::ThermoMechanicalPhaseFieldLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getIntPtSigma(), ProcessLib::PhaseField::PhaseFieldLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getIntPtSigma(), ProcessLib::ThermoMechanics::ThermoMechanicsLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getIntPtSigma(), ProcessLib::SmallDeformation::SmallDeformationLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getIntPtSigma(), ProcessLib::SmallDeformationNonlocal::SmallDeformationNonlocalLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getIntPtSigma(), ProcessLib::ThermoHydroMechanics::ThermoHydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::getSigma(), ProcessLib::HydroMechanics::HydroMechanicsLocalAssembler< ShapeFunctionDisplacement, ShapeFunctionPressure, IntegrationMethod, DisplacementDim >::getSigma(), ProcessLib::ThermoMechanics::ThermoMechanicsLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getSigma(), ProcessLib::SmallDeformation::SmallDeformationLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getSigma(), ProcessLib::SmallDeformationNonlocal::SmallDeformationNonlocalLocalAssembler< ShapeFunction, IntegrationMethod, DisplacementDim >::getSigma(), and ProcessLib::Deformation::solidMaterialInternalToSecondaryVariables().

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

◆ 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 153 of file EigenMapTools.h.

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

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

◆ 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 173 of file Vector3.h.

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

Referenced by barycentricPointInTriangle(), calcTriangleArea(), MeshLib::calculateNormalizedSurfaceNormal(), GeoLib::compute3DRotationMatrixToX(), MeshLib::FaceRule::getSurfaceNormal(), ProcessLib::SurfaceFluxLocalAssembler< ShapeFunction, IntegrationMethod, GlobalDim >::integrate(), isCoplanar(), GeoLib::MinimalBoundingSphere::MinimalBoundingSphere(), and scalarTriple().

176 {
177  return TemplateVector3<T1>(
178  v._x[1] * w._x[2] - v._x[2] * w._x[1],
179  v._x[2] * w._x[0] - v._x[0] * w._x[2],
180  v._x[0] * w._x[1] - v._x[1] * w._x[0]);
181 }

◆ 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 200 of file GeometricBasics.cpp.

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

202 {
203  for (unsigned x = 0; x < 3; ++x)
204  {
205  const unsigned y = (x + 1) % 3;
206  const double abc =
207  (b[x] - a[x]) * (c[y] - a[y]) - (b[y] - a[y]) * (c[x] - a[x]);
208  const double abd =
209  (b[x] - a[x]) * (d[y] - a[y]) - (b[y] - a[y]) * (d[x] - a[x]);
210 
211  if ((abc > 0 && abd < 0) || (abc < 0 && abd > 0))
212  {
213  return true;
214  }
215  }
216  return false;
217 }

◆ finalizeMatrixAssembly() [1/3]

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

Definition at line 19 of file FinalizeMatrixAssembly.h.

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

20 {
21  return true;
22 }

◆ finalizeMatrixAssembly() [2/3]

bool MathLib::finalizeMatrixAssembly ( LisMatrix mat)

finish assembly to make this matrix be ready for use

Definition at line 121 of file LisMatrix.cpp.

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

122 {
123  LIS_MATRIX &A = mat.getRawMatrix();
124 
125  if (!mat.isAssembled()) {
126  int ierr = lis_matrix_set_type(A, static_cast<int>(mat.getMatrixType()));
127  checkLisError(ierr);
128  ierr = lis_matrix_assemble(A);
129  checkLisError(ierr);
130  mat._is_assembled = true;
131  }
132  return true;
133 }
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 19 of file FinalizeVectorAssembly.h.

20 {
21 }

◆ 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 &  q,
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 q 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
qtest 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 110 of file GeometricBasics.cpp.

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

Referenced by isPointInTriangle().

116 {
117  MathLib::Vector3 const v(a, b);
118  MathLib::Vector3 const w(a, c);
119 
120  Eigen::Matrix2d mat;
121  mat(0, 0) = v.getSqrLength();
122  mat(0, 1) = v[0] * w[0] + v[1] * w[1] + v[2] * w[2];
123  mat(1, 0) = mat(0, 1);
124  mat(1, 1) = w.getSqrLength();
125  Eigen::Vector2d y;
126  y << v[0] * (q[0] - a[0]) + v[1] * (q[1] - a[1]) + v[2] * (q[2] - a[2]),
127  w[0] * (q[0] - a[0]) + w[1] * (q[1] - a[1]) + w[2] * (q[2] - a[2]);
128 
129  y = mat.partialPivLu().solve(y);
130 
131  const double lower(eps_pnt_out_of_tri);
132  const double upper(1 + lower);
133 
134  if (-lower <= y[0] && y[0] <= upper && -lower <= y[1] && y[1] <= upper &&
135  y[0] + y[1] <= upper)
136  {
137  MathLib::Point3d const q_projected(std::array<double, 3>{
138  {a[0] + y[0] * v[0] + y[1] * w[0], a[1] + y[0] * v[1] + y[1] * w[1],
139  a[2] + y[0] * v[2] + y[1] * w[2]}});
140  if (MathLib::sqrDist(q, q_projected) <= eps_pnt_out_of_plane)
141  {
142  return true;
143  }
144  }
145 
146  return false;
147 }
double sqrDist(const double *p0, const double *p1)
Definition: MathTools.h:81
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 38 of file MathTools.cpp.

References scalarProduct< double, 3 >().

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

39 {
40  const double v0[3] = {p0[0]-p1[0], p0[1]-p1[1], p0[2]-p1[2]};
41  const double v1[3] = {p2[0]-p1[0], p2[1]-p1[1], p2[2]-p1[2]};
42 
43  // apply Cauchy Schwarz inequality
44  return std::acos (scalarProduct<double,3> (v0,v1) / (std::sqrt(scalarProduct<double,3>(v0,v0)) * sqrt(scalarProduct<double,3>(v1,v1))));
45 }
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)
22  {
23  config.ignoreConfigParameter(s);
24  }
25  }
26 }
static std::set< std::string > known_linear_solvers
void ignoreConfigParameter(std::string const &param) const
Definition: ConfigTree.cpp:187

◆ initGLTet3X()

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

Definition at line 30 of file GaussLegendreTet.cpp.

References anonymous_namespace{Density100MPa.cpp}::c.

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

◆ 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 219 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().

221 {
222  const MathLib::Vector3 ab(a, b);
223  const MathLib::Vector3 ac(a, c);
224  const MathLib::Vector3 ad(a, d);
225 
226  if (ab.getSqrLength() < pow(std::numeric_limits<double>::epsilon(), 2) ||
227  ac.getSqrLength() < pow(std::numeric_limits<double>::epsilon(), 2) ||
228  ad.getSqrLength() < pow(std::numeric_limits<double>::epsilon(), 2))
229  {
230  return true;
231  }
232 
233  // In exact arithmetic <ac*ad^T, ab> should be zero
234  // if all four points are coplanar.
235  const double sqr_scalar_triple(
236  pow(MathLib::scalarProduct(MathLib::crossProduct(ac, ad), ab), 2));
237  // Due to evaluating the above numerically some cancellation or rounding
238  // can occur. For this reason a normalisation factor is introduced.
239  const double normalisation_factor =
240  (ab.getSqrLength() * ac.getSqrLength() * ad.getSqrLength());
241 
242  // tolerance 1e-11 is choosen such that
243  // a = (0,0,0), b=(1,0,0), c=(0,1,0) and d=(1,1,1e-6) are considered as
244  // coplanar
245  // a = (0,0,0), b=(1,0,0), c=(0,1,0) and d=(1,1,1e-5) are considered as not
246  // coplanar
247  return (sqr_scalar_triple / normalisation_factor < 1e-11);
248 }
TemplateVector3< T1 > crossProduct(TemplateVector3< T1 > const &v, TemplateVector3< T1 > const &w)
Definition: Vector3.h:173
T scalarProduct(T const *const v0, T const *const v1)
Definition: MathTools.h:26

◆ 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 52 of file GeometricBasics.cpp.

References orientation3d().

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

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

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

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

93 {
94  switch (algorithm)
95  {
96  case MathLib::GAUSS:
97  return gaussPointInTriangle(p, a, b, c, eps_pnt_out_of_plane,
98  eps_pnt_out_of_tri);
100  return barycentricPointInTriangle(p, a, b, c, eps_pnt_out_of_plane,
101  eps_pnt_out_of_tri);
102  default:
103  ERR("Selected algorithm for point in triangle testing not found, "
104  "falling back on default.");
105  }
106  return gaussPointInTriangle(p, a, b, c, eps_pnt_out_of_plane,
107  eps_pnt_out_of_tri);
108 }
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 180 of file GeometricBasics.cpp.

Referenced by MeshLib::isPointInElementXY().

184 {
185  // criterion: p-a = u0 * (b-a) + u1 * (c-a); 0 <= u0, u1 <= 1, u0+u1 <= 1
186  Eigen::Matrix2d mat;
187  mat(0, 0) = b[0] - a[0];
188  mat(0, 1) = c[0] - a[0];
189  mat(1, 0) = b[1] - a[1];
190  mat(1, 1) = c[1] - a[1];
191  Eigen::Vector2d y;
192  y << p[0] - a[0], p[1] - a[1];
193 
194  y = mat.partialPivLu().solve(y);
195 
196  // check if u0 and u1 fulfills the condition
197  return 0 <= y[0] && y[0] <= 1 && 0 <= y[1] && y[1] <= 1 && y[0] + y[1] <= 1;
198 }
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.

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 }

◆ 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 34 of file Point3d.h.

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

35 {
36  MathLib::Point3d new_p;
37  for (std::size_t i(0); i<3; ++i) {
38  for (std::size_t j(0); j<3; ++j) {
39  new_p[i] += mat(i,j)*p[j];
40  }
41  }
42  return new_p;
43 }
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 183 of file Vector3.h.

186 {
187  return TemplateVector3<T1>(v[0] * s, v[1] * s, v[2] * s);
188 }

◆ operator*() [3/3]

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

Definition at line 190 of file Vector3.h.

193 {
194  return v * s;
195 }

◆ 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:81

◆ 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 21 of file GeometricBasics.cpp.

References scalarTriple().

Referenced by barycentricPointInTriangle(), and isPointInTetrahedron().

25 {
26  MathLib::Vector3 const ap (a, p);
27  MathLib::Vector3 const bp (b, p);
28  MathLib::Vector3 const cp (c, p);
29  return MathLib::scalarTriple(bp,cp,ap);
30 }
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:15
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 26 of file MathTools.h.

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

27 {
28  T res (v0[0] * v1[0]);
29 
30 #pragma omp parallel for reduction (+:res)
31  for (int k = 1; k < N; k++)
32  {
33  res += v0[k] * v1[k];
34  }
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 50 of file MathTools.h.

References calcProjPntToLineAndDists(), and p.

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

◆ scalarProduct() [3/3]

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

Definition at line 167 of file Vector3.h.

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

168 {
169  return v._x[0] * w._x[0] + v._x[1] * w._x[1] + v._x[2] * w._x[2];
170 }

◆ 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  {
44  res += v0[k] * v1[k];
45  }
46  return res;
47 }

◆ 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 15 of file Vector3.cpp.

References crossProduct(), and scalarProduct().

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

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

◆ 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 48 of file Point3d.h.

References scalarProduct< double, 3 >().

49 {
50  const double v[3] = {p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]};
52 }
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 81 of file MathTools.h.

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

Referenced by GeoLib::OctTree< POINT, MAX_POINTS >::addPoint(), GeoLib::Polyline::addPoint(), MeshGeoToolsLib::BoundaryElementsAtPoint::BoundaryElementsAtPoint(), 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(), MeshGeoToolsLib::MeshNodeSearcher::getMeshNodeIDs(), 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().

82 {
83  const double v[3] = {p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]};
84  return scalarProduct<double,3>(v,v);
85 }
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 57 of file Point3d.h.

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

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

◆ sqrFrobNrm()

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

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

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

366 {
367  FP_TYPE nrm(static_cast<FP_TYPE>(0));
368  IDX_TYPE i, j;
369  for (j = 0; j < mat.getNumberOfColumns(); j++)
370  {
371  for (i = 0; i < mat.getNumberOfRows(); i++)
372  {
373  nrm += mat(i, j) * mat(i, j);
374  }
375  }
376 
377  return nrm;
378 }

◆ 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 72 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().

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

◆ 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 111 of file EigenMapTools.h.

References toMatrix().

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

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

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

◆ 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 196 of file EigenMapTools.h.

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

◆ 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 207 of file EigenMapTools.h.

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

Variable Documentation

◆ ORIGIN

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

Definition at line 26 of file Point3d.h.

Referenced by MeshLib::getBulkElementPoint(), and getOrigin().

◆ p

◆ q

◆ r

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

Definition at line 63 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(), FileIO::Gocad::Layer::hasRegion(), ProcessLib::TES::TESFEMReactionAdaptorAdsorption::initReaction_slowDownUndershootStrategy(), MaterialLib::Solids::Creep::CreepBGRa< DisplacementDim >::integrateStress(), VtkImageDataToPointCloudFilter::interpolate(), NumLib::TemplateIsoparametric< ShapeFunctionType_, ShapeMatrixTypes_ >::interpolateZerothCoordinate(), main(), 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().