15#include <range/v3/action/push_back.hpp>
16#include <range/v3/view/transform.hpp>
90 std::pair<std::string, PropertyVectorBase*>
const& property_pair,
91 unsigned int const n_files,
unsigned int const chunk_size_bytes)
95 std::size_t num_of_tuples = 0;
96 void const* data_ptr = 0;
101 auto f = [&data_type, &num_of_tuples, &data_ptr,
102 &property_pair](
auto basic_type) ->
bool
104 auto const property_base = property_pair.second;
105 auto const typed_property =
108 if (typed_property ==
nullptr)
114 data_ptr = typed_property->data();
116 if constexpr (std::is_same_v<double,
decltype(basic_type)>)
121 static_assert((std::numeric_limits<double>::digits == 53),
122 "Double has 52 bits fractional part");
125 else if constexpr (std::is_same_v<float,
decltype(basic_type)>)
130 static_assert((std::numeric_limits<float>::digits == 24),
131 "Float has 23 bits fractional part");
134 else if constexpr (std::is_same_v<int32_t,
decltype(basic_type)>)
138 else if constexpr (std::is_same_v<uint32_t,
decltype(basic_type)>)
142 else if constexpr (std::is_same_v<int64_t,
decltype(basic_type)>)
146 else if constexpr (std::is_same_v<uint64_t,
decltype(basic_type)>)
150 else if constexpr (std::is_same_v<int8_t,
decltype(basic_type)>)
154 else if constexpr (std::is_same_v<uint8_t,
decltype(basic_type)>)
158 else if constexpr (std::is_same_v<char,
decltype(basic_type)>)
162 else if constexpr (std::is_same_v<
unsigned char,
decltype(basic_type)>)
164 static_assert((std::numeric_limits<unsigned char>::digits == 8),
165 "Unsigned char has 8 bits");
168 else if constexpr (std::is_same_v<
unsigned long,
decltype(basic_type)>)
170 if (
sizeof(
unsigned long) == 8 &&
171 std::numeric_limits<unsigned long>::digits == 64)
175 else if (
sizeof(
unsigned long) == 4 &&
176 std::numeric_limits<unsigned long>::digits == 32)
185 else if constexpr (std::is_same_v<std::size_t,
decltype(basic_type)>)
187 if (
sizeof(std::size_t) == 8 &&
188 std::numeric_limits<std::size_t>::digits == 64)
192 else if (
sizeof(std::size_t) == 4 &&
193 std::numeric_limits<std::size_t>::digits == 32)
209 f(
double{}) || f(
float{}) || f(
int{}) || f(
long{}) || f(
unsigned{}) ||
210 f(
long{}) || f(
static_cast<unsigned long>(0)) || f(std::size_t{}) ||
211 f(
char{}) || f(
static_cast<unsigned char>(0));
218 auto const& property_base = property_pair.second;
219 auto const& global_components =
220 property_base->getNumberOfGlobalComponents();
225 assert(global_components >= 0);
226 auto const ui_global_components =
227 static_cast<unsigned int>(global_components);
230 property_base->getMeshItemType();
232 std::string
const& name = property_base->getPropertyName();
234 HdfData hdf = {data_ptr, num_of_tuples, ui_global_components, name,
235 data_type, n_files, chunk_size_bytes};
237 XdmfData xdmf{num_of_tuples, ui_global_components, data_type,
238 name, mesh_item_type, 0,
239 n_files, std::nullopt};
241 return XdmfHdfData{std::move(hdf), std::move(xdmf)};
246 unsigned int const chunk_size_bytes)
252 std::vector<XdmfHdfData> attributes;
253 for (
auto const& [name, property_base] : properties)
260 if (!property_base->is_for_output)
267 std::pair(std::string(name), property_base), n_files,
271 attributes.push_back(attribute.value());
275 WARN(
"Could not create attribute meta of {:s}.", name);
283 std::vector<MeshLib::Node*>
const& nodes = mesh.
getNodes();
285 int const point_size = 3;
286 std::vector<double> values;
287 values.reserve(nodes.size() * point_size);
288 for (
auto const& n : nodes)
290 const double* x = n->data();
291 values.insert(values.cend(), x, x + point_size);
298 unsigned int const n_files,
299 unsigned int const chunk_size_bytes)
301 std::string
const name =
"geometry";
302 std::vector<MeshLib::Node*>
const& nodes = mesh.
getNodes();
304 int const point_size = 3;
305 auto const& partition_dim = nodes.size();
316 name, std::nullopt, 2,
317 n_files, std::nullopt};
319 return XdmfHdfData{std::move(hdf), std::move(xdmf)};
326 if (elements.empty())
330 auto const ogs_cell_type = elements[0]->getCellType();
332 if (std::any_of(elements.begin(), elements.end(),
333 [&](
auto const& cell)
334 { return cell->getCellType() != ogs_cell_type; }))
345 std::vector<MeshLib::Element*>
const& elements = mesh.
getElements();
346 std::vector<std::size_t> values;
348 auto const push_cellnode_ids_to_vector =
349 [&values, &offset](
auto const& cell)
351 values |= ranges::actions::push_back(
353 ranges::views::transform([&offset](
auto const node_id)
354 { return node_id + offset; }));
360 values.reserve(elements.size() * 2);
362 for (
auto const& cell : elements)
364 auto const ogs_cell_type = cell->getCellType();
367 push_cellnode_ids_to_vector(cell);
373 values.reserve(elements.size() * elements[0]->getNumberOfNodes());
374 for (
auto const& cell : elements)
376 push_cellnode_ids_to_vector(cell);
381 values.reserve(elements.size() * elements[0]->getNumberOfNodes());
382 for (
auto const& cell : elements)
384 push_cellnode_ids_to_vector(cell);
388 return {values, topology_type};
393 unsigned int const n_files,
394 unsigned int const chunk_size_bytes)
396 std::string
const name =
"topology";
398 HdfData const hdf = {values.data(),
399 values.size() / tuple_size,
405 XdmfData const xdmf{values.size() / tuple_size,
414 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.
std::pair< std::string, std::size_t > ParentDataType2String(ParentDataType p)
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
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::pair< std::vector< std::size_t >, 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...
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.
XdmfHdfData transformTopology(std::vector< std::size_t > 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.
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