OGS
OGSMesh.cpp
Go to the documentation of this file.
1
13#include "OGSMesh.h"
14
15#include <algorithm>
16#include <pybind11/eigen.h>
17#include <pybind11/pybind11.h>
18#include <pybind11/stl.h>
19#include <spdlog/spdlog.h>
20
21#include <numeric>
22#include <range/v3/algorithm/copy.hpp>
23#include <range/v3/numeric.hpp>
24#include <range/v3/range/conversion.hpp>
25#include <range/v3/view/enumerate.hpp>
26#include <range/v3/view/indirect.hpp>
27#include <range/v3/view/join.hpp>
28#include <range/v3/view/map.hpp>
29#include <range/v3/view/transform.hpp>
30#include <span>
31#include <vector>
32
34#include "BaseLib/Logging.h"
35#include "InfoLib/GitInfo.h"
37#include "MeshLib/Mesh.h"
38#include "MeshLib/Node.h"
40#include "MeshLib/VtkOGSEnum.h"
41
42OGSMesh::OGSMesh(MeshLib::Mesh& mesh) : _mesh(mesh) {}
43
44std::vector<double> OGSMesh::getPointCoordinates() const
45{
46 return ranges::to<std::vector>(_mesh.getNodes() | MeshLib::views::coords |
47 ranges::views::join);
48}
49
50std::pair<std::vector<int>, std::vector<int>> OGSMesh::getCells() const
51{
52 auto const& elements = _mesh.getElements();
53 std::vector<int> cells;
54 std::vector<int> cell_types;
55 for (auto const* element : elements)
56 {
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{
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{
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{
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{
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:46
std::vector< double > getPointCoordinates() const
Definition OGSMesh.cpp:44
OGSMesh(MeshLib::Mesh &mesh)
Definition OGSMesh.cpp:42
std::pair< std::vector< int >, std::vector< int > > getCells() const
Definition OGSMesh.cpp:50
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
PropertyVector< T > * getOrCreateMeshProperty(Mesh &mesh, std::string const &property_name, MeshItemType const item_type, int const number_of_components)