OGS
Utils.h
Go to the documentation of this file.
1 
11 #pragma once
12 
13 #include <algorithm>
14 #include <vector>
15 
16 #include "BaseLib/Algorithm.h"
17 #include "MeshLib/Node.h"
18 
19 #include "Element.h"
20 #include "FaceRule.h"
21 
22 namespace MeshLib
23 {
26 inline std::vector<Node*> getBaseNodes(std::vector<Element*> const& elements)
27 {
28  std::vector<Node*> base_nodes;
29  base_nodes.reserve(elements.size() * 2); // Save some of the realloctions.
30 
31  for (auto* const e : elements)
32  {
33  std::copy(e->getNodes(), e->getNodes() + e->getNumberOfBaseNodes(),
34  std::back_inserter(base_nodes));
35  }
36 
37  BaseLib::makeVectorUnique(base_nodes, [](Node const* a, Node* b) {
38  return a->getID() < b->getID();
39  });
40 
41  return base_nodes;
42 }
43 
44 inline Eigen::Vector3d calculateNormalizedSurfaceNormal(
45  MeshLib::Element const& surface_element,
46  MeshLib::Element const& bulk_element)
47 {
48  Eigen::Vector3d surface_element_normal;
49  if (surface_element.getDimension() < 2)
50  {
51  auto const bulk_element_normal =
53  auto const v0 = Eigen::Map<Eigen::Vector3d const>(
54  surface_element.getNode(0)->getCoords());
55  auto const v1 = Eigen::Map<Eigen::Vector3d const>(
56  surface_element.getNode(1)->getCoords());
57  Eigen::Vector3d const edge_vector = v1 - v0;
58  surface_element_normal = bulk_element_normal.cross(edge_vector);
59  }
60  else
61  {
62  surface_element_normal =
63  MeshLib::FaceRule::getSurfaceNormal(surface_element);
64  }
65 
66  surface_element_normal.normalize();
67  // At the moment (2018-04-26) the surface normal is not oriented
68  // according to the right hand rule
69  // for correct results it is necessary to multiply the normal with
70  // -1
71  surface_element_normal *= -1;
72 
73  return surface_element_normal;
74 }
75 
76 } // namespace MeshLib
Definition of the Element class.
Definition of the Node class.
std::size_t getID() const
Definition: Point3dWithID.h:62
const T * getCoords() const
Definition: TemplatePoint.h:75
virtual const Node * getNode(unsigned idx) const =0
virtual constexpr unsigned getDimension() const =0
Get dimension of the mesh element.
static Eigen::Vector3d getSurfaceNormal(Element const &e)
Returns the surface normal of a 2D element.
Definition: FaceRule.cpp:40
void makeVectorUnique(std::vector< T > &v)
Definition: Algorithm.h:209
void copy(PETScVector const &x, PETScVector &y)
Definition: LinAlg.cpp:37
Eigen::Vector3d calculateNormalizedSurfaceNormal(MeshLib::Element const &surface_element, MeshLib::Element const &bulk_element)
Definition: Utils.h:44
std::vector< Node * > getBaseNodes(std::vector< Element * > const &elements)
Definition: Utils.h:26