OGS
OGSMesh.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 "OGSMesh.h"
5
6#include <pybind11/eigen.h>
7#include <pybind11/pybind11.h>
8#include <pybind11/stl.h>
9#include <spdlog/spdlog.h>
10
11#include <range/v3/view/join.hpp>
12#include <vector>
13
15#include "BaseLib/Logging.h"
16#include "InfoLib/GitInfo.h"
18#include "MeshLib/Node.h"
19#include "MeshLib/VtkOGSEnum.h"
20
22
23std::vector<double> OGSMesh::getPointCoordinates() const
24{
25 return ranges::to<std::vector>(_mesh.getNodes() | MeshLib::views::coords |
26 ranges::views::join);
27}
28
29std::pair<std::vector<int>, std::vector<int>> OGSMesh::getCells() const
30{
31 auto const& elements = _mesh.getElements();
32 std::vector<int> cells;
33 std::vector<int> cell_types;
34 for (auto const* element : elements)
35 {
36 ranges::copy(element->nodes() | MeshLib::views::ids,
37 std::back_inserter(cells));
38 cell_types.push_back(OGSToVtkCellType(element->getCellType()));
39 }
40 return {cells, cell_types};
41}
42
43std::vector<std::string> OGSMesh::getDataArrayNames() const
44{
45 return _mesh.getProperties().getPropertyVectorNames();
46}
47
48MeshLib::MeshItemType OGSMesh::meshItemType(std::string_view const name) const
49{
50 auto const& properties = _mesh.getProperties();
51
52 auto const& found = BaseLib::findElementOrError(
53 properties,
54 [&name](auto const& p) { return p.first == name; },
55 [&name]()
56 {
57 OGS_FATAL("A property with the name '{}' doesn't exist in the mesh",
58 name);
59 });
60 return found.second->getMeshItemType();
61}
#define OGS_FATAL(...)
Definition Error.h:19
int OGSToVtkCellType(MeshLib::CellType ogs)
MeshLib::MeshItemType meshItemType(std::string_view const name) const
Definition OGSMesh.cpp:48
MeshLib::Mesh & _mesh
Definition OGSMesh.h:141
std::vector< double > getPointCoordinates() const
Definition OGSMesh.cpp:23
std::vector< std::string > getDataArrayNames() const
Definition OGSMesh.cpp:43
OGSMesh(MeshLib::Mesh &mesh)
Definition OGSMesh.cpp:21
std::pair< std::vector< int >, std::vector< int > > getCells() const
Definition OGSMesh.cpp:29
ranges::range_reference_t< Range > findElementOrError(Range &range, std::predicate< ranges::range_reference_t< Range > > auto &&predicate, std::invocable auto error_callback)
Definition Algorithm.h:74
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition Mesh.h:216
constexpr ranges::views::view_closure coords
Definition Mesh.h:223