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