OGS
ElementCoordinatesMappingLocal.cpp
Go to the documentation of this file.
1 
11 
12 #include <cassert>
13 #include <limits>
14 
16 #include "MathLib/MathTools.h"
17 #include "MathLib/Point3d.h"
19 #include "MeshLib/Node.h"
20 
21 namespace detail
22 {
24 void rotateToLocal(const MeshLib::RotationMatrix& matR2local,
25  std::vector<MathLib::Point3d>& points)
26 {
27  std::transform(points.begin(), points.end(), points.begin(),
28  [&matR2local](auto const& pnt) { return matR2local * pnt; });
29 }
30 
35  const unsigned element_dimension,
36  const unsigned global_dim,
37  const std::vector<MathLib::Point3d>& points)
38 {
39  Eigen::Matrix3d matR;
40  // compute R in x=R*x' where x are original coordinates and x' are local
41  // coordinates
42  if (element_dimension == 1)
43  {
44  Eigen::Vector3d const xx =
45  (Eigen::Map<Eigen::Vector3d const>(points[1].getCoords()) -
46  Eigen::Map<Eigen::Vector3d const>(points[0].getCoords()))
47  .normalized();
48  if (global_dim == 2)
49  {
51  }
52  else
53  {
55  }
56  matR.transposeInPlace();
57  }
58  else if (global_dim == 3 && element_dimension == 2)
59  {
60  // get plane normal
61  auto const [plane_normal, d] = GeoLib::getNewellPlane(points);
62  // compute a rotation matrix to XY
63  matR = GeoLib::computeRotationMatrixToXY(plane_normal);
64  // set a transposed matrix
65  matR.transposeInPlace();
66  }
67  return matR;
68 }
69 } // namespace detail
70 
71 namespace MeshLib
72 {
74  const Element& e, const unsigned global_dim)
75  : _global_dim(global_dim), _matR2global(Eigen::Matrix3d::Identity())
76 {
77  unsigned const space_dim = std::max(e.space_dimension_, _global_dim);
78  assert(e.getDimension() <= space_dim);
79  _points.reserve(e.getNumberOfNodes());
80  for (unsigned i = 0; i < e.getNumberOfNodes(); i++)
81  {
82  _points.emplace_back(*(e.getNode(i)));
83  }
84 
85  auto const element_dim = e.getDimension();
86 
87  if (element_dim != space_dim)
88  {
89  _matR2global =
90  detail::getRotationMatrixToGlobal(element_dim, space_dim, _points);
92  }
93 }
94 
95 } // namespace MeshLib
Definition of analytical geometry functions.
Definition of the Element class.
Definition of the Node class.
Definition of the Point3d class.
ElementCoordinatesMappingLocal(const Element &e, const unsigned global_dim)
virtual const Node * getNode(unsigned idx) const =0
virtual unsigned getNumberOfNodes() const =0
virtual constexpr unsigned getDimension() const =0
Get dimension of the mesh element.
unsigned space_dimension_
Dimension of the space, where the element exists.
Definition: Element.h:185
Eigen::Matrix3d compute3DRotationMatrixToX(Eigen::Vector3d const &v)
Eigen::Matrix3d computeRotationMatrixToXY(Eigen::Vector3d const &n)
std::pair< Eigen::Vector3d, double > getNewellPlane(InputIterator pnts_begin, InputIterator pnts_end)
Eigen::Matrix3d compute2DRotationMatrixToX(Eigen::Vector3d const &v)
Eigen::Matrix< double, 3u, 3u, Eigen::RowMajor > RotationMatrix
void rotateToLocal(const MeshLib::RotationMatrix &matR2local, std::vector< MathLib::Point3d > &points)
rotate points to local coordinates
MeshLib::RotationMatrix getRotationMatrixToGlobal(const unsigned element_dimension, const unsigned global_dim, const std::vector< MathLib::Point3d > &points)