15#include <range/v3/action/push_back.hpp>
16#include <range/v3/view/transform.hpp>
93 std::pair<std::string, PropertyVectorBase*>
const& property_pair,
94 unsigned int const n_files,
unsigned int const chunk_size_bytes)
98 std::size_t num_of_tuples = 0;
99 void const* data_ptr = 0;
104 auto f = [&data_type, &num_of_tuples, &data_ptr,
105 &property_pair](
auto basic_type) ->
bool
107 auto const property_base = property_pair.second;
108 auto const typed_property =
111 if (typed_property ==
nullptr)
117 data_ptr = typed_property->data();
119 if constexpr (std::is_same_v<double,
decltype(basic_type)>)
124 static_assert((std::numeric_limits<double>::digits == 53),
125 "Double has 52 bits fractional part");
128 else if constexpr (std::is_same_v<float,
decltype(basic_type)>)
133 static_assert((std::numeric_limits<float>::digits == 24),
134 "Float has 23 bits fractional part");
137 else if constexpr (std::is_same_v<int32_t,
decltype(basic_type)>)
141 else if constexpr (std::is_same_v<uint32_t,
decltype(basic_type)>)
145 else if constexpr (std::is_same_v<int64_t,
decltype(basic_type)>)
149 else if constexpr (std::is_same_v<uint64_t,
decltype(basic_type)>)
153 else if constexpr (std::is_same_v<int8_t,
decltype(basic_type)>)
157 else if constexpr (std::is_same_v<uint8_t,
decltype(basic_type)>)
161 else if constexpr (std::is_same_v<char,
decltype(basic_type)>)
165 else if constexpr (std::is_same_v<
unsigned char,
decltype(basic_type)>)
167 static_assert((std::numeric_limits<unsigned char>::digits == 8),
168 "Unsigned char has 8 bits");
171 else if constexpr (std::is_same_v<
unsigned long,
decltype(basic_type)>)
173 if (
sizeof(
unsigned long) == 8 &&
174 std::numeric_limits<unsigned long>::digits == 64)
178 else if (
sizeof(
unsigned long) == 4 &&
179 std::numeric_limits<unsigned long>::digits == 32)
188 else if constexpr (std::is_same_v<std::size_t,
decltype(basic_type)>)
190 if (
sizeof(std::size_t) == 8 &&
191 std::numeric_limits<std::size_t>::digits == 64)
195 else if (
sizeof(std::size_t) == 4 &&
196 std::numeric_limits<std::size_t>::digits == 32)
212 f(
double{}) || f(
float{}) || f(
int{}) || f(
long{}) || f(
unsigned{}) ||
213 f(
long{}) || f(
static_cast<unsigned long>(0)) || f(std::size_t{}) ||
214 f(
char{}) || f(
static_cast<unsigned char>(0));
221 auto const& property_base = property_pair.second;
222 auto const& global_components =
223 property_base->getNumberOfGlobalComponents();
228 assert(global_components >= 0);
229 auto const ui_global_components =
230 static_cast<unsigned int>(global_components);
233 property_base->getMeshItemType();
235 std::string
const& name = property_base->getPropertyName();
237 HdfData hdf = {data_ptr, num_of_tuples, ui_global_components, name,
238 data_type, n_files, chunk_size_bytes};
240 XdmfData xdmf{num_of_tuples, ui_global_components, data_type,
241 name, mesh_item_type, 0,
242 n_files, std::nullopt};
244 return XdmfHdfData{std::move(hdf), std::move(xdmf)};
249 unsigned int const chunk_size_bytes)
255 std::vector<XdmfHdfData> attributes;
256 for (
auto const& [name, property_base] : properties)
263 if (!property_base->is_for_output)
270 std::pair(std::string(name), property_base), n_files,
274 attributes.push_back(attribute.value());
278 WARN(
"Could not create attribute meta of {:s}.", name);
286 std::vector<MeshLib::Node*>
const& nodes = mesh.
getNodes();
288 int const point_size = 3;
289 std::vector<double> values;
290 values.reserve(nodes.size() * point_size);
291 for (
auto const& n : nodes)
293 const double* x = n->data();
294 values.insert(values.cend(), x, x + point_size);
301 unsigned int const n_files,
302 unsigned int const chunk_size_bytes)
304 std::string
const name =
"geometry";
305 std::vector<MeshLib::Node*>
const& nodes = mesh.
getNodes();
307 int const point_size = 3;
308 auto const& partition_dim = nodes.size();
319 name, std::nullopt, 2,
320 n_files, std::nullopt};
322 return XdmfHdfData{std::move(hdf), std::move(xdmf)};
329 if (elements.empty())
333 auto const ogs_cell_type = elements[0]->getCellType();
335 if (std::any_of(elements.begin(), elements.end(),
336 [&](
auto const& cell)
337 { return cell->getCellType() != ogs_cell_type; }))
345#if !defined(USE_PETSC)
357 std::vector<int>
const topology_types =
360 auto const common_topology_type =
361 std::all_of(topology_types.begin(), topology_types.end(),
362 [&local_topology_type](
int other)
363 { return other == static_cast<int>(local_topology_type); })
364 ? local_topology_type
366 return common_topology_type;
373 std::vector<MeshLib::Element*>
const& elements = mesh.
getElements();
374 std::vector<std::size_t> values;
376 auto const push_cellnode_ids_to_vector =
377 [&values, &offset](
auto const& cell)
379 values |= ranges::actions::push_back(
381 ranges::views::transform([&offset](
auto const node_id)
382 { return node_id + offset; }));
388 values.reserve(elements.size() * 2);
390 for (
auto const& cell : elements)
392 auto const ogs_cell_type = cell->getCellType();
400 push_cellnode_ids_to_vector(cell);
405 values.reserve(elements.size() * elements[0]->getNumberOfNodes());
406 for (
auto const& cell : elements)
408 push_cellnode_ids_to_vector(cell);
412 return {values, topology_type};
417 unsigned int const n_files,
418 unsigned int const chunk_size_bytes)
420 std::string
const name =
"topology";
422 HdfData const hdf = {values.data(),
423 values.size() / tuple_size,
429 XdmfData const xdmf{values.size() / tuple_size,
438 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
static std::vector< T > allgather(T const &value, Mpi const &mpi)
constexpr auto to_underlying(E e) noexcept
Converts an enumeration to its underlying type.
const std::string OGS_VERSION
ParentDataType getLocalTopologyType(MeshLib::Mesh const &mesh)
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