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