17#include <range/v3/action/push_back.hpp>
18#include <range/v3/view/transform.hpp>
92 std::pair<std::string, PropertyVectorBase*>
const& property_pair,
93 unsigned int const n_files,
unsigned int const chunk_size_bytes)
97 std::size_t num_of_tuples = 0;
98 void const* data_ptr = 0;
103 auto f = [&data_type, &num_of_tuples, &data_ptr,
104 &property_pair](
auto basic_type) ->
bool
106 auto const property_base = property_pair.second;
107 auto const typed_property =
110 if (typed_property ==
nullptr)
116 data_ptr = typed_property->data();
118 if constexpr (std::is_same_v<double,
decltype(basic_type)>)
123 static_assert((std::numeric_limits<double>::digits == 53),
124 "Double has 52 bits fractional part");
127 else if constexpr (std::is_same_v<float,
decltype(basic_type)>)
132 static_assert((std::numeric_limits<float>::digits == 24),
133 "Float has 23 bits fractional part");
136 else if constexpr (std::is_same_v<int,
decltype(basic_type)>)
138 static_assert((std::numeric_limits<int>::digits == 31),
139 "Signed int has 32-1 bits");
157 else if constexpr (std::is_same_v<
unsigned int,
decltype(basic_type)>)
159 static_assert((std::numeric_limits<unsigned int>::digits == 32),
160 "Unsigned int has 32 bits");
163 else if constexpr (std::is_same_v<std::size_t,
decltype(basic_type)>)
165 static_assert((std::numeric_limits<std::size_t>::digits == 64),
166 "size_t has 64 bits");
169 else if constexpr (std::is_same_v<char,
decltype(basic_type)>)
173 else if constexpr (std::is_same_v<
unsigned char,
decltype(basic_type)>)
175 static_assert((std::numeric_limits<unsigned char>::digits == 8),
176 "Unsigned char has 8 bits");
186 f(
double{}) || f(
float{}) || f(
int{}) || f(
long{}) || f(
unsigned{}) ||
187 f(
long{}) || f(
static_cast<unsigned long>(0)) || f(std::size_t{}) ||
188 f(
char{}) || f(
static_cast<unsigned char>(0));
195 auto const& property_base = property_pair.second;
196 auto const& global_components =
197 property_base->getNumberOfGlobalComponents();
202 assert(global_components >= 0);
203 auto const ui_global_components =
204 static_cast<unsigned int>(global_components);
207 property_base->getMeshItemType();
209 std::string
const& name = property_base->getPropertyName();
211 HdfData hdf = {data_ptr, num_of_tuples, ui_global_components, name,
212 data_type, n_files, chunk_size_bytes};
214 XdmfData xdmf{num_of_tuples, ui_global_components, data_type,
215 name, mesh_item_type, 0,
216 n_files, std::nullopt};
218 return XdmfHdfData{std::move(hdf), std::move(xdmf)};
223 unsigned int const chunk_size_bytes)
229 std::vector<XdmfHdfData> attributes;
230 for (
auto const& [name, property_base] : properties)
237 if (!property_base->is_for_output)
244 std::pair(std::string(name), property_base), n_files,
248 attributes.push_back(attribute.value());
252 WARN(
"Could not create attribute meta of {:s}.", name);
260 std::vector<MeshLib::Node*>
const& nodes = mesh.
getNodes();
262 int const point_size = 3;
263 std::vector<double> values;
264 values.reserve(nodes.size() * point_size);
265 for (
auto const& n : nodes)
267 const double* x = n->data();
268 values.insert(values.cend(), x, x + point_size);
275 unsigned int const n_files,
276 unsigned int const chunk_size_bytes)
278 std::string
const name =
"geometry";
279 std::vector<MeshLib::Node*>
const& nodes = mesh.
getNodes();
281 int const point_size = 3;
282 auto const& partition_dim = nodes.size();
293 name, std::nullopt, 2,
294 n_files, std::nullopt};
296 return XdmfHdfData{std::move(hdf), std::move(xdmf)};
303 if (elements.empty())
307 auto const ogs_cell_type = elements[0]->getCellType();
309 if (std::any_of(elements.begin(), elements.end(),
310 [&](
auto const& cell)
311 { return cell->getCellType() != ogs_cell_type; }))
322 std::vector<MeshLib::Element*>
const& elements = mesh.
getElements();
323 std::vector<int> values;
325 auto const push_cellnode_ids_to_vector =
326 [&values, &offset](
auto const& cell)
328 values |= ranges::actions::push_back(
330 ranges::views::transform([&offset](
auto const node_id) ->
int
331 { return node_id + offset; }));
337 values.reserve(elements.size() * 2);
339 for (
auto const& cell : elements)
341 auto const ogs_cell_type = cell->getCellType();
344 push_cellnode_ids_to_vector(cell);
351 values.reserve(elements.size() * (elements[0]->getNumberOfNodes() + 1));
352 for (
auto const& cell : elements)
354 values.push_back(cell->getNumberOfNodes());
355 push_cellnode_ids_to_vector(cell);
360 values.reserve(elements.size() * elements[0]->getNumberOfNodes());
361 for (
auto const& cell : elements)
363 push_cellnode_ids_to_vector(cell);
367 return {values, topology_type};
372 unsigned int const n_files,
373 unsigned int const chunk_size_bytes)
375 std::string
const name =
"topology";
378 n_files, chunk_size_bytes};
388 return XdmfHdfData{std::move(hdf), std::move(xdmf)};
Definition of the Element class.
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition of mesh-related Enumerations.
Enum for all propertyVector data types and XDMF ParentDataTypes.
Definition of the Mesh class.
Definition of the Node class.
std::vector< Node * > const & getNodes() const
Get the nodes-vector for the mesh.
std::vector< Element * > const & getElements() const
Get the element-vector for the mesh.
Properties & getProperties()
Property manager on mesh items. Class Properties manages scalar, vector or matrix properties....
std::size_t getNumberOfTuples() const
constexpr auto to_underlying(E e) noexcept
Converts an enumeration to its underlying type.
const std::string OGS_VERSION
XdmfHdfData transformTopology(std::vector< int > const &values, ParentDataType const parent_data_type, unsigned int const n_files, unsigned int const chunk_size_bytes)
Create meta data for topology used for HDF5 and XDMF.
std::pair< std::vector< int >, ParentDataType > transformToXDMFTopology(MeshLib::Mesh const &mesh, std::size_t const offset)
Copies all cells into a new vector. Contiguous data used for writing. The topology is specific to xdm...
constexpr auto cellTypeOGS2XDMF(MeshLib::CellType const &cell_type)
ParentDataType getTopologyType(MeshLib::Mesh const &mesh)
std::optional< XdmfHdfData > transformAttribute(std::pair< std::string, PropertyVectorBase * > const &property_pair, unsigned int const n_files, unsigned int const chunk_size_bytes)
std::vector< double > transformToXDMFGeometry(MeshLib::Mesh const &mesh)
Copies all node points into a new vector. Contiguous data used for writing. Conform with XDMF standar...
XdmfHdfData transformGeometry(MeshLib::Mesh const &mesh, double const *data_ptr, unsigned int const n_files, unsigned int const chunk_size_bytes)
Create meta data for geometry used for hdf5 and xdmf.
static constexpr auto elemOGSTypeToXDMFType()
std::vector< XdmfHdfData > transformAttributes(MeshLib::Mesh const &mesh, unsigned int const n_files, unsigned int const chunk_size_bytes)
Create meta data for attributes used for hdf5 and xdmf.
constexpr auto elem_type_ogs2xdmf
constexpr ranges::views::view_closure ids
For an element of a range view return its id.
CellType
Types of mesh elements supported by OpenGeoSys.
Dispatches functions specific to execution platform (w/o MPI)
unsigned int number_of_nodes