OGS
Is2DMeshOnRotatedVerticalPlane.cpp
Go to the documentation of this file.
1
13
14#include <algorithm>
15#include <limits>
16
17#include "BaseLib/Error.h"
19#include "MeshLib/Mesh.h"
20#include "MeshLib/Node.h"
21
22namespace MeshLib
23{
25{
26 auto const mesh_dimension = mesh.getDimension();
27 if (mesh_dimension != 2)
28 {
30 "A 2D mesh is required for this computation but the provided mesh, "
31 "mesh {:s}, has {:d}D elements.",
32 mesh.getName(), mesh_dimension);
33 }
34
35 auto const& elements = mesh.getElements();
36
37 bool const has_inclined_element =
38 std::any_of(elements.begin(), elements.end(),
39 [&mesh_dimension](auto const& element)
40 { return element->space_dimension_ != mesh_dimension; });
41
42 if (!has_inclined_element)
43 {
44 return false;
45 }
46
47 const bool is_rotated_around_y_axis = std::all_of(
48 elements.cbegin(), elements.cend(),
49 [](auto const& element)
50 {
51 // 3 nodes are enough to make up a plane.
52 auto const x1 = element->getNode(0)->data();
53 auto const x2 = element->getNode(1)->data();
54 auto const x3 = element->getNode(2)->data();
55
56 double const a0 = x2[0] - x1[0];
57 double const a2 = x2[2] - x1[2];
58
59 double const b0 = x3[0] - x1[0];
60 double const b2 = x3[2] - x1[2];
61
62 double const e_n_1 = -a0 * b2 + a2 * b0;
63 return std::fabs(e_n_1) < std::numeric_limits<double>::epsilon();
64 });
65
66 const bool is_rotated_around_z_axis = std::all_of(
67 elements.cbegin(), elements.cend(),
68 [](auto const& element)
69 {
70 // 3 nodes are enough to make up a plane.
71 auto const x1 = element->getNode(0)->data();
72 auto const x2 = element->getNode(1)->data();
73 auto const x3 = element->getNode(2)->data();
74
75 double const a0 = x2[0] - x1[0];
76 double const a1 = x2[1] - x1[1];
77
78 double const b0 = x3[0] - x1[0];
79 double const b1 = x3[1] - x1[1];
80
81 double const e_n_2 = a0 * b1 - a1 * b0;
82 return std::fabs(e_n_2) < std::numeric_limits<double>::epsilon();
83 });
84
85 if (!(is_rotated_around_y_axis || is_rotated_around_z_axis))
86 {
88 "2D Mesh {:s} is on an inclined plane, which is neither a vertical "
89 "nor horizontal plane that is required for the present "
90 "computation.",
91 mesh.getName());
92 }
93
94 return true;
95}
96}; // namespace MeshLib
Definition of the Element class.
#define OGS_FATAL(...)
Definition Error.h:26
Definition of the Mesh class.
Definition of the Node class.
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:109
unsigned getDimension() const
Returns the dimension of the mesh (determined by the maximum dimension over all elements).
Definition Mesh.h:88
const std::string getName() const
Get name of the mesh.
Definition Mesh.h:103
bool is2DMeshOnRotatedVerticalPlane(Mesh const &mesh)