OGS
GetSpaceDimension.cpp
Go to the documentation of this file.
1
12#include "GetSpaceDimension.h"
13
14#include <Eigen/Core>
15#include <algorithm>
16#include <limits>
17
18#include "BaseLib/Error.h"
19#include "MeshLib/Node.h"
20
21namespace MeshLib
22{
23int getSpaceDimension(std::vector<Node*> const& nodes)
24{
25 Eigen::Vector3d x_magnitude = Eigen::Vector3d::Zero();
26 auto const x_ref = nodes[0]->asEigenVector3d();
27
28 for (auto const& node : nodes)
29 {
30 auto const x = node->asEigenVector3d();
31 x_magnitude += (x - x_ref).cwiseAbs();
32 }
33
34 // Z coordinate norm is not zero whichever 1D, 2D or 3D mesh:
35 if (x_magnitude[2] > 0)
36 {
37 return 3;
38 }
39
40 const auto computed_dimension = std::count_if(
41 x_magnitude.begin(), x_magnitude.end(),
42 [](const double x_i_magnitude)
43 { return x_i_magnitude > std::numeric_limits<double>::epsilon(); });
44
45 // 1D mesh in y direction:
46 if (computed_dimension == 1 && x_magnitude[1] > 0)
47 {
48 return 2;
49 }
50
51 return static_cast<int>(computed_dimension);
52}
53}; // namespace MeshLib
Definition of the Node class.
int getSpaceDimension(std::vector< Node * > const &nodes)
Computes dimension of the embedding space containing the set of given points.