OGS
OGSMesh.cpp
Go to the documentation of this file.
1
13#include "OGSMesh.h"
14
15#include <pybind11/eigen.h>
16#include <pybind11/pybind11.h>
17#include <pybind11/stl.h>
18#include <spdlog/spdlog.h>
19
20#include <numeric>
21#include <range/v3/algorithm/copy.hpp>
22#include <range/v3/numeric.hpp>
23#include <range/v3/range/conversion.hpp>
24#include <range/v3/view/enumerate.hpp>
25#include <range/v3/view/indirect.hpp>
26#include <range/v3/view/join.hpp>
27#include <range/v3/view/map.hpp>
28#include <range/v3/view/transform.hpp>
29#include <span>
30#include <vector>
31
33#include "BaseLib/Logging.h"
34#include "InfoLib/GitInfo.h"
36#include "MeshLib/Mesh.h"
37#include "MeshLib/Node.h"
39#include "MeshLib/VtkOGSEnum.h"
40
41OGSMesh::OGSMesh(MeshLib::Mesh& mesh) : _mesh(mesh) {}
42
43std::vector<double> OGSMesh::getPointCoordinates() const
44{
45 return ranges::to<std::vector>(_mesh.getNodes() | MeshLib::views::coords |
46 ranges::views::join);
47}
48
49std::pair<std::vector<int>, std::vector<int>> OGSMesh::getCells() const
50{
51 auto const& elements = _mesh.getElements();
52 std::vector<int> cells;
53 std::vector<int> cell_types;
54 for (auto const* element : elements)
55 {
56 cells.push_back(static_cast<int>(element->getNumberOfNodes()));
57 ranges::copy(element->nodes() | MeshLib::views::ids,
58 std::back_inserter(cells));
59 cell_types.push_back(OGSToVtkCellType(element->getCellType()));
60 }
61 return {cells, cell_types};
62}
63
64void OGSMesh::setPointDataArray(std::string const& name,
65 std::vector<double> const& values,
66 std::size_t const number_of_components)
67{
68 auto* pv = MeshLib::getOrCreateMeshProperty<double>(
69 _mesh, name, MeshLib::MeshItemType::Node, number_of_components);
70 if (pv == nullptr)
71 {
72 OGS_FATAL("Couldn't access cell/element property '{}'.", name);
73 }
74 if (pv->size() != values.size())
75 {
77 "OGSMesh::setPointDataArray: size mismatch: property vector has "
78 "size '{}', while the number of values is '{}'.",
79 pv->size(), values.size());
80 }
81 std::copy(values.begin(), values.end(), pv->data());
82}
83
84std::vector<double> OGSMesh::getPointDataArray(
85 std::string const& name, std::size_t const number_of_components) const
86{
87 auto const* pv = MeshLib::getOrCreateMeshProperty<double>(
88 _mesh, name, MeshLib::MeshItemType::Node, number_of_components);
89 if (pv == nullptr)
90 {
91 OGS_FATAL("Couldn't access point/node property '{}'.", name);
92 }
93 return ranges::to<std::vector>(std::span(pv->data(), pv->size()));
94}
95
96void OGSMesh::setCellDataArray(std::string const& name,
97 std::vector<double> const& values,
98 std::size_t const number_of_components)
99{
100 auto* pv = MeshLib::getOrCreateMeshProperty<double>(
101 _mesh, name, MeshLib::MeshItemType::Cell, number_of_components);
102 if (pv == nullptr)
103 {
104 OGS_FATAL("Couldn't access cell/element property '{}'.", name);
105 }
106 if (pv->size() != values.size())
107 {
108 OGS_FATAL(
109 "OGSMesh::setCellDataArray: size mismatch: property vector has "
110 "size '{}', while the number of values is '{}'.",
111 pv->size(), values.size());
112 }
113 std::copy(values.begin(), values.end(), pv->data());
114}
115
116std::vector<double> OGSMesh::getCellDataArray(
117 std::string const& name, std::size_t const number_of_components) const
118{
119 auto const* pv = MeshLib::getOrCreateMeshProperty<double>(
120 _mesh, name, MeshLib::MeshItemType::Cell, number_of_components);
121 if (pv == nullptr)
122 {
123 OGS_FATAL("Couldn't access cell/element property '{}'.", name);
124 }
125 return ranges::to<std::vector>(std::span(pv->data(), pv->size()));
126}
Definition of the Element class.
#define OGS_FATAL(...)
Definition Error.h:26
Git information.
Definition of the Mesh class.
Definition of the Node class.
int OGSToVtkCellType(MeshLib::CellType ogs)
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
Definition Mesh.h:106
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Definition Mesh.h:109
void setPointDataArray(std::string const &name, std::vector< double > const &values, std::size_t const number_of_components)
Definition OGSMesh.cpp:64
std::vector< double > getPointDataArray(std::string const &name, std::size_t const number_of_components=1) const
Definition OGSMesh.cpp:84
void setCellDataArray(std::string const &name, std::vector< double > const &values, std::size_t const number_of_components)
Definition OGSMesh.cpp:96
MeshLib::Mesh & _mesh
Definition OGSMesh.h:45
std::vector< double > getPointCoordinates() const
Definition OGSMesh.cpp:43
OGSMesh(MeshLib::Mesh &mesh)
Definition OGSMesh.cpp:41
std::pair< std::vector< int >, std::vector< int > > getCells() const
Definition OGSMesh.cpp:49
std::vector< double > getCellDataArray(std::string const &name, std::size_t const number_of_components) const
Definition OGSMesh.cpp:116
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
Definition Mesh.h:225
constexpr ranges::views::view_closure coords
Definition Mesh.h:232