OGS
ElementCoordinatesMappingLocal.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) OpenGeoSys Community (opengeosys.org)
2// SPDX-License-Identifier: BSD-3-Clause
3
5
6#include <cassert>
7#include <limits>
8
10#include "MathLib/MathTools.h"
11#include "MathLib/Point3d.h"
13#include "MeshLib/Node.h"
14
15namespace detail
16{
19 std::vector<MathLib::Point3d>& points)
20{
21 std::transform(points.begin(), points.end(), points.begin(),
22 [&matR2local](auto const& pnt) { return matR2local * pnt; });
23}
24
29 const unsigned element_dimension,
30 const unsigned global_dim,
31 const std::vector<MathLib::Point3d>& points)
32{
33 Eigen::Matrix3d matR;
34 // compute R in x=R*x' where x are original coordinates and x' are local
35 // coordinates
36 if (element_dimension == 1)
37 {
38 Eigen::Vector3d const xx =
39 (points[1].asEigenVector3d() - points[0].asEigenVector3d())
40 .normalized();
41 if (global_dim == 2)
42 {
44 }
45 else
46 {
48 }
49 matR.transposeInPlace();
50 }
51 else if (global_dim == 3 && element_dimension == 2)
52 {
53 // get plane normal
54 auto const [plane_normal, d] = GeoLib::getNewellPlane(points);
55 // compute a rotation matrix to XY
56 matR = GeoLib::computeRotationMatrixToXY(plane_normal);
57 // set a transposed matrix
58 matR.transposeInPlace();
59 }
60 return matR;
61}
62} // namespace detail
63
64namespace MeshLib
65{
67 const Element& e, const unsigned global_dim)
68 : _global_dim(global_dim), _matR2global(Eigen::Matrix3d::Identity())
69{
70 unsigned const space_dim = std::max(e.space_dimension_, _global_dim);
71 assert(e.getDimension() <= space_dim);
72 _points.reserve(e.getNumberOfNodes());
73 for (unsigned i = 0; i < e.getNumberOfNodes(); i++)
74 {
75 _points.emplace_back(*(e.getNode(i)));
76 }
77
78 auto const element_dim = e.getDimension();
79
80 if (element_dim != space_dim)
81 {
83 detail::getRotationMatrixToGlobal(element_dim, space_dim, _points);
85 }
86}
87
88} // namespace MeshLib
ElementCoordinatesMappingLocal(const Element &e, const unsigned global_dim)
virtual unsigned getNumberOfNodes() const =0
virtual const Node * getNode(unsigned idx) 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:181
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)