14#include "arcane/utils/Collection.h"
15#include "arcane/utils/Enumerator.h"
16#include "arcane/utils/Iostream.h"
17#include "arcane/utils/StringBuilder.h"
18#include "arcane/utils/IOException.h"
19#include "arcane/utils/FixedArray.h"
20#include "arcane/utils/MemoryView.h"
22#include "arcane/core/PostProcessorWriterBase.h"
23#include "arcane/core/Directory.h"
24#include "arcane/core/FactoryService.h"
25#include "arcane/core/IDataWriter.h"
26#include "arcane/core/IData.h"
27#include "arcane/core/IItemFamily.h"
28#include "arcane/core/VariableCollection.h"
29#include "arcane/core/IParallelMng.h"
30#include "arcane/core/IMesh.h"
31#include "arcane/core/internal/VtkCellTypes.h"
33#include "arcane/core/materials/IMeshMaterialMng.h"
34#include "arcane/core/materials/IMeshEnvironment.h"
36#include "arcane/hdf5/Hdf5Utils.h"
37#include "arcane/hdf5/VtkHdfV2PostProcessor_axl.h"
77 asConstSpan(
const T* v)
86class VtkHdfV2DataWriter
98 struct DatasetGroupAndName
102 DatasetGroupAndName(
HGroup& group_,
const String& name_)
126 DatasetInfo() =
default;
127 explicit DatasetInfo(
const String& name)
134 bool isNull()
const {
return m_name.null(); }
136 HGroup* group()
const {
return m_group; }
137 const String& name()
const {
return m_name; }
140 void setOffset(
Int64 v) { m_offset = v; }
141 friend bool operator<(
const DatasetInfo& s1,
const DatasetInfo& s2)
143 return (s1.m_name < s2.m_name);
148 HGroup* m_group =
nullptr;
158 void setTotalSize(
Int64 v) { m_total_size = v; }
159 void setSize(
Int64 v) { m_size = v; }
160 void setOffset(
Int64 v) { m_offset = v; }
162 Int64 totalSize()
const {
return m_total_size; }
163 Int64 size()
const {
return m_size; }
164 Int64 offset()
const {
return m_offset; }
169 Int64 m_total_size = 0;
177 struct ItemGroupCollectiveInfo
181 explicit ItemGroupCollectiveInfo(
const ItemGroup& g)
207 , m_dataset_info(dataset_info)
213 , m_dataset_info(dataset_info)
214 , m_group_info(group_info)
220 DatasetInfo datasetInfo()
const {
return m_dataset_info; }
236 void endWrite()
override;
243 void setDirectoryName(
const String& dir_name) { m_directory_name = dir_name; }
244 void setMaxWriteSize(Int64 v) { m_max_write_size = v; }
249 IMesh* m_mesh =
nullptr;
252 IMeshMaterialMng* m_material_mng =
nullptr;
258 UniqueArray<Real> m_times;
261 String m_full_filename;
264 String m_directory_name;
270 HGroup m_cell_data_group;
271 HGroup m_node_data_group;
273 HGroup m_steps_group;
274 HGroup m_point_data_offsets_group;
275 HGroup m_cell_data_offsets_group;
276 HGroup m_field_data_offsets_group;
278 bool m_is_parallel =
false;
279 bool m_is_master_io =
false;
280 bool m_is_collective_io =
false;
281 bool m_is_first_call =
false;
282 bool m_is_writer =
false;
290 std::map<DatasetInfo, Int64> m_offset_info_list;
292 StandardTypes m_standard_types{
false };
296 UniqueArray<Ref<ItemGroupCollectiveInfo>> m_materials_groups;
304 Int64 m_max_write_size = 0;
308 void _addInt64ArrayAttribute(Hid& hid,
const char* name, Span<const Int64> values);
309 void _addStringAttribute(Hid& hid,
const char* name,
const String& value);
311 template <
typename DataType>
void
312 _writeDataSet1D(
const DataInfo& data_info, Span<const DataType> values);
313 template <
typename DataType>
void
314 _writeDataSet1DUsingCollectiveIO(
const DataInfo& data_info, Span<const DataType> values);
315 template <
typename DataType>
void
316 _writeDataSet1DCollective(
const DataInfo& data_info, Span<const DataType> values);
317 template <
typename DataType>
void
318 _writeDataSet2D(
const DataInfo& data_info, Span2<const DataType> values);
319 template <
typename DataType>
void
320 _writeDataSet2DUsingCollectiveIO(
const DataInfo& data_info, Span2<const DataType> values);
321 template <
typename DataType>
void
322 _writeDataSet2DCollective(
const DataInfo& data_info, Span2<const DataType> values);
323 template <
typename DataType>
void
324 _writeBasicTypeDataset(
const DataInfo& data_info, IData* data);
325 void _writeReal3Dataset(
const DataInfo& data_info, IData* data);
326 void _writeReal2Dataset(
const DataInfo& data_info, IData* data);
328 String _getFileName()
330 StringBuilder sb(m_mesh->name());
332 return sb.toString();
334 template <
typename DataType>
void
335 _writeDataSetGeneric(
const DataInfo& data_info,
Int32 nb_dim,
336 Int64 dim1_size,
Int64 dim2_size,
const DataType* values_data,
338 void _writeDataSetGeneric(
const DataInfo& data_info,
Int32 nb_dim,
339 Int64 dim1_size,
Int64 dim2_size, ConstMemoryView values_data,
340 const hid_t hdf_datatype_type,
bool is_collective);
341 void _addInt64Attribute(Hid& hid,
const char* name,
Int64 value);
342 Int64 _readInt64Attribute(Hid& hid,
const char* name);
343 void _openOrCreateGroups();
346 void _initializeOffsets();
349 void _writeConstituentsGroups();
360, m_is_collective_io(is_collective_io)
361, m_all_cells_info(mesh->allCells())
362, m_all_nodes_info(mesh->allNodes())
369void VtkHdfV2DataWriter::
370beginWrite(
const VariableCollection& vars)
377 IParallelMng* pm = m_mesh->parallelMng();
378 const Int32 nb_rank = pm->commSize();
379 m_is_parallel = nb_rank > 1;
380 m_is_master_io = pm->isMasterIO();
382 Int32 time_index = m_times.size();
383 const bool is_first_call = (time_index < 2);
384 m_is_first_call = is_first_call;
386 info() <<
"WARNING: L'implémentation au format 'VtkHdfV2' est expérimentale";
388 String filename = _getFileName();
390 Directory dir(m_directory_name);
392 m_full_filename = dir.file(filename);
393 info(4) <<
"VtkHdfV2DataWriter::beginWrite() file=" << m_full_filename;
402 if (pm->isHybridImplementation() || pm->isThreadImplementation())
403 m_is_collective_io =
false;
406 info() <<
"VtkHdfV2DataWriter: using collective MPI/IO ?=" << m_is_collective_io;
407 info() <<
"VtkHdfV2DataWriter: max_write_size (kB) =" << m_max_write_size;
408 info() <<
"VtkHdfV2DataWriter: has_material?=" << (m_material_mng !=
nullptr);
415 m_is_writer = m_is_master_io || m_is_collective_io;
419 if (m_is_collective_io)
420 plist_id.createFilePropertyMPIIO(pm);
422 if (is_first_call && m_is_master_io)
423 dir.createDirectory();
425 if (m_is_collective_io)
429 m_standard_types.initialize();
432 m_file_id.openTruncate(m_full_filename, plist_id.id());
434 m_file_id.openAppend(m_full_filename, plist_id.id());
436 _openOrCreateGroups();
439 std::array<Int64, 2> version = { 2, 0 };
440 _addInt64ArrayAttribute(m_top_group,
"Version", version);
441 _addStringAttribute(m_top_group,
"Type",
"UnstructuredGrid");
446 _initializeItemGroupCollectiveInfos(m_all_cells_info);
447 _initializeItemGroupCollectiveInfos(m_all_nodes_info);
449 CellGroup all_cells = m_mesh->allCells();
450 NodeGroup all_nodes = m_mesh->allNodes();
453 const Int32 nb_node = all_nodes.size();
455 Int32 total_nb_connected_node = 0;
458 total_nb_connected_node += cell.nodeIds().size();
463 UniqueArray<Int64> cells_connectivity(total_nb_connected_node);
464 UniqueArray<Int64> cells_offset(nb_cell + 1);
465 UniqueArray<unsigned char> cells_ghost_type(nb_cell);
466 UniqueArray<unsigned char> cells_type(nb_cell);
467 UniqueArray<Int64> cells_uid(nb_cell);
470 Int32 connected_node_index = 0;
472 Int32 index = icell.index();
475 cells_uid[index] = cell.uniqueId();
478 bool is_ghost = !cell.isOwn();
480 ghost_type = VtkUtils::CellGhostTypes::DUPLICATECELL;
481 cells_ghost_type[index] = ghost_type;
483 unsigned char vtk_type = VtkUtils::arcaneToVtkCellType(cell.type());
484 cells_type[index] = vtk_type;
485 for (NodeLocalId node : cell.nodeIds()) {
486 cells_connectivity[connected_node_index] = node;
487 ++connected_node_index;
489 cells_offset[index + 1] = connected_node_index;
493 _initializeOffsets();
496 _writeDataSet1DCollective<Int64>({ { m_top_group,
"Offsets" }, m_offset_for_cell_offset_info }, cells_offset);
498 _writeDataSet1DCollective<Int64>({ { m_top_group,
"Connectivity" }, m_connectivity_offset_info },
500 _writeDataSet1DCollective<unsigned char>({ { m_top_group,
"Types" }, m_cell_offset_info }, cells_type);
503 Int64 nb_cell_int64 = nb_cell;
504 _writeDataSet1DCollective<Int64>({ { m_top_group,
"NumberOfCells" }, m_part_offset_info },
505 asConstSpan(&nb_cell_int64));
506 Int64 nb_node_int64 = nb_node;
507 _writeDataSet1DCollective<Int64>({ { m_top_group,
"NumberOfPoints" }, m_part_offset_info },
508 asConstSpan(&nb_node_int64));
509 Int64 number_of_connectivity_ids = cells_connectivity.size();
510 _writeDataSet1DCollective<Int64>({ { m_top_group,
"NumberOfConnectivityIds" }, m_part_offset_info },
511 asConstSpan(&number_of_connectivity_ids));
516 UniqueArray<Int64> nodes_uid(nb_node);
517 UniqueArray<unsigned char> nodes_ghost_type(nb_node);
519 UniqueArray2<Real> points;
520 points.resize(nb_node, 3);
522 Int32 index = inode.index();
525 nodes_uid[index] = node.uniqueId();
528 bool is_ghost = !node.isOwn();
530 ghost_type = VtkUtils::PointGhostTypes::DUPLICATEPOINT;
531 nodes_ghost_type[index] = ghost_type;
533 Real3 pos = nodes_coordinates[inode];
534 points[index][0] = pos.x;
535 points[index][1] = pos.y;
536 points[index][2] = pos.z;
540 _writeDataSet1DCollective<Int64>({ { m_node_data_group,
"GlobalNodeId" }, m_cell_offset_info }, nodes_uid);
543 _writeDataSet1DCollective<unsigned char>({ { m_node_data_group,
"vtkGhostType" }, m_cell_offset_info }, nodes_ghost_type);
546 _writeDataSet2DCollective<Real>({ { m_top_group,
"Points" }, m_point_offset_info }, points);
550 _writeDataSet1DCollective<unsigned char>({ { m_cell_data_group,
"vtkGhostType" }, m_cell_offset_info }, cells_ghost_type);
554 _writeDataSet1DCollective<Int64>({ { m_cell_data_group,
"GlobalCellId" }, m_cell_offset_info }, cells_uid);
558 Real current_time = m_times[time_index - 1];
559 _writeDataSet1D<Real>({ { m_steps_group,
"Values" }, m_time_offset_info }, asConstSpan(¤t_time));
562 Int64 comm_size = pm->commSize();
563 Int64 part_offset = (time_index - 1) * comm_size;
564 _writeDataSet1D<Int64>({ { m_steps_group,
"PartOffsets" }, m_time_offset_info }, asConstSpan(&part_offset));
567 _addInt64Attribute(m_steps_group,
"NSteps", time_index);
570 _writeConstituentsGroups();
576void VtkHdfV2DataWriter::
577_writeConstituentsGroups()
584 for (IMeshEnvironment* env : m_material_mng->environments()) {
587 m_materials_groups.add(group_info_ref);
589 _initializeItemGroupCollectiveInfos(group_info);
590 ConstArrayView<Int32> groups_ids = cells.view().localIds();
591 DatasetGroupAndName dataset_group_name(m_top_group, String(
"Constituent_") + cells.name());
593 info() <<
"Writing infos for group '" << cells.name() <<
"'";
594 _writeDataSet1DCollective<Int32>({ dataset_group_name, m_cell_offset_info }, groups_ids);
603VtkHdfV2DataWriter::WritePartInfo VtkHdfV2DataWriter::
604_computeWritePartInfo(
Int64 local_size)
607 IParallelMng* pm = m_mesh->parallelMng();
608 Int32 nb_rank = pm->commSize();
609 Int32 my_rank = pm->commRank();
611 UniqueArray<Int64> ranks_size(nb_rank);
612 ArrayView<Int64> all_sizes(ranks_size);
613 Int64 dim1_size = local_size;
614 pm->allGather(ConstArrayView<Int64>(1, &dim1_size), all_sizes);
616 Int64 total_size = 0;
617 for (
Integer i = 0; i < nb_rank; ++i)
618 total_size += all_sizes[i];
621 for (
Integer i = 0; i < my_rank; ++i)
622 my_index += all_sizes[i];
625 part_info.setTotalSize(total_size);
626 part_info.setSize(local_size);
627 part_info.setOffset(my_index);
634void VtkHdfV2DataWriter::
637 Int64 dim1_size = group_info.m_item_group.size();
638 group_info.setWritePartInfo(_computeWritePartInfo(dim1_size));
643 std::pair<Int64, Int64> _getInterval(
Int64 index,
Int64 nb_interval,
Int64 total_size)
645 Int64 n = total_size;
646 Int64 isize = n / nb_interval;
647 Int64 ibegin = index * isize;
649 if ((index + 1) == nb_interval)
651 return { ibegin, isize };
663void VtkHdfV2DataWriter::
666 ConstMemoryView values_data,
667 const hid_t hdf_type,
bool is_collective)
672 HGroup& group = data_info.dataset.group;
673 const String& name = data_info.dataset.name;
677 Int64 wanted_offset = data_info.datasetInfo().offset();
679 static constexpr int MAX_DIM = 2;
688 FixedArray<hsize_t, MAX_DIM> local_dims;
689 local_dims[0] = dim1_size;
690 local_dims[1] = dim2_size;
693 FixedArray<hsize_t, MAX_DIM> global_dims;
697 FixedArray<hsize_t, MAX_DIM> max_dims;
698 max_dims[0] = H5S_UNLIMITED;
699 max_dims[1] = dim2_size;
702 Int64 write_offset = 0;
705 Int64 global_dim1_size = dim1_size;
706 Int32 nb_participating_rank = 1;
709 nb_participating_rank = m_mesh->parallelMng()->commSize();
711 if (data_info.m_group_info) {
714 part_info = data_info.m_group_info->writePartInfo();
717 part_info = _computeWritePartInfo(dim1_size);
719 global_dim1_size = part_info.totalSize();
720 my_index = part_info.offset();
723 HProperty write_plist_id;
725 write_plist_id.createDatasetTransfertCollectiveMPIIO();
728 FixedArray<hsize_t, MAX_DIM> hyperslab_offsets;
730 if (m_is_first_call) {
732 FixedArray<hsize_t, MAX_DIM> chunk_dims;
733 global_dims[0] = global_dim1_size;
734 global_dims[1] = dim2_size;
736 Int64 chunk_size = global_dim1_size / nb_participating_rank;
737 if (chunk_size < 1024)
739 const Int64 max_chunk_size = 1024 * 1024 * 10;
740 chunk_size =
math::min(chunk_size, max_chunk_size);
741 chunk_dims[0] = chunk_size;
742 chunk_dims[1] = dim2_size;
743 info() <<
"CHUNK nb_dim=" << nb_dim
744 <<
" global_dim1_size=" << global_dim1_size
745 <<
" chunk0=" << chunk_dims[0]
746 <<
" chunk1=" << chunk_dims[1]
748 file_space.createSimple(nb_dim, global_dims.data(), max_dims.data());
750 plist_id.create(H5P_DATASET_CREATE);
751 H5Pset_chunk(plist_id.id(), nb_dim, chunk_dims.data());
752 dataset.create(group, name.localstr(), hdf_type, file_space, HProperty{}, plist_id, HProperty{});
755 hyperslab_offsets[0] = my_index;
756 hyperslab_offsets[1] = 0;
762 dataset.open(group, name.localstr());
763 file_space = dataset.getSpace();
764 int nb_dimension = file_space.nbDimension();
765 if (nb_dimension != nb_dim)
766 ARCANE_THROW(IOException,
"Bad dimension '{0}' for dataset '{1}' (should be 1)",
769 FixedArray<hsize_t, MAX_DIM> original_dims;
770 file_space.getDimensions(original_dims.data(),
nullptr);
771 hsize_t offset0 = original_dims[0];
774 if (wanted_offset >= 0) {
775 offset0 = wanted_offset;
776 info() <<
"Forcing offset to " << wanted_offset;
778 global_dims[0] = offset0 + global_dim1_size;
779 global_dims[1] = dim2_size;
780 write_offset = offset0;
783 if ((herror = dataset.setExtent(global_dims.data())) < 0)
784 ARCANE_THROW(IOException,
"Can not extent dataset '{0}' (err={1})", name, herror);
785 file_space = dataset.getSpace();
787 hyperslab_offsets[0] = offset0 + my_index;
788 hyperslab_offsets[1] = 0;
789 info(4) <<
"APPEND nb_dim=" << nb_dim
790 <<
" dim0=" << global_dims[0]
791 <<
" count0=" << local_dims[0]
792 <<
" offsets0=" << hyperslab_offsets[0] <<
" name=" << name;
795 Int64 nb_write_byte = global_dim1_size * dim2_size * values_data.datatypeSize();
799 Int64 nb_interval = 1;
800 if (is_collective && m_max_write_size > 0) {
801 nb_interval = 1 + nb_write_byte / (m_max_write_size * 1024);
803 info(4) <<
"WRITE global_size=" << nb_write_byte <<
" max_size=" << m_max_write_size <<
" nb_interval=" << nb_interval;
805 for (
Int64 i = 0; i < nb_interval; ++i) {
806 auto [index, nb_element] = _getInterval(i, nb_interval, dim1_size);
808 FixedArray<hsize_t, 2> dims;
809 dims[0] = nb_element;
811 FixedArray<hsize_t, 2> offsets;
812 offsets[0] = hyperslab_offsets[0] + index;
814 if ((herror = H5Sselect_hyperslab(file_space.id(), H5S_SELECT_SET, offsets.data(),
nullptr, dims.data(),
nullptr)) < 0)
815 ARCANE_THROW(IOException,
"Can not select hyperslab '{0}' (err={1})", name, herror);
818 memory_space.createSimple(nb_dim, dims.data());
819 Int64 data_offset = index * values_data.datatypeSize() * dim2_size;
821 if ((herror = dataset.write(hdf_type, values_data.data() + data_offset, memory_space, file_space, write_plist_id)) < 0)
822 ARCANE_THROW(IOException,
"Can not write dataset '{0}' (err={1})", name, herror);
825 ARCANE_THROW(IOException,
"Can not write dataset '{0}'", name);
828 if (!data_info.datasetInfo().isNull())
829 m_offset_info_list.insert(std::make_pair(data_info.datasetInfo(), write_offset));
835template <
typename DataType>
void VtkHdfV2DataWriter::
837 Int64 dim1_size,
Int64 dim2_size,
const DataType* values_data,
840 const hid_t hdf_type = m_standard_types.nativeType(DataType{});
841 ConstMemoryView mem_view =
makeConstMemoryView(values_data,
sizeof(DataType), dim1_size * dim2_size);
842 _writeDataSetGeneric(data_info, nb_dim, dim1_size, dim2_size, mem_view, hdf_type, is_collective);
848template <
typename DataType>
void VtkHdfV2DataWriter::
849_writeDataSet1D(
const DataInfo& data_info, Span<const DataType> values)
851 _writeDataSetGeneric(data_info, 1, values.size(), 1, values.data(),
false);
857template <
typename DataType>
void VtkHdfV2DataWriter::
858_writeDataSet1DUsingCollectiveIO(
const DataInfo& data_info, Span<const DataType> values)
860 _writeDataSetGeneric(data_info, 1, values.size(), 1, values.data(),
true);
866template <
typename DataType>
void VtkHdfV2DataWriter::
867_writeDataSet1DCollective(
const DataInfo& data_info, Span<const DataType> values)
870 return _writeDataSet1D(data_info, values);
871 if (m_is_collective_io)
872 return _writeDataSet1DUsingCollectiveIO(data_info, values);
873 UniqueArray<DataType> all_values;
874 IParallelMng* pm = m_mesh->parallelMng();
875 pm->gatherVariable(values.smallView(), all_values, pm->masterIORank());
877 _writeDataSet1D<DataType>(data_info, all_values);
883template <
typename DataType>
void VtkHdfV2DataWriter::
884_writeDataSet2D(
const DataInfo& data_info, Span2<const DataType> values)
886 _writeDataSetGeneric(data_info, 2, values.dim1Size(), values.dim2Size(), values.data(),
false);
892template <
typename DataType>
void VtkHdfV2DataWriter::
893_writeDataSet2DUsingCollectiveIO(
const DataInfo& data_info, Span2<const DataType> values)
895 _writeDataSetGeneric(data_info, 2, values.dim1Size(), values.dim2Size(), values.data(),
true);
901template <
typename DataType>
void VtkHdfV2DataWriter::
902_writeDataSet2DCollective(
const DataInfo& data_info, Span2<const DataType> values)
905 return _writeDataSet2D(data_info, values);
906 if (m_is_collective_io)
907 return _writeDataSet2DUsingCollectiveIO(data_info, values);
909 Int64 dim2_size = values.dim2Size();
910 UniqueArray<DataType> all_values;
911 IParallelMng* pm = m_mesh->parallelMng();
912 Span<const DataType> values_1d(values.data(), values.totalNbElement());
913 pm->gatherVariable(values_1d.smallView(), all_values, pm->masterIORank());
914 if (m_is_master_io) {
915 Int64 dim1_size = all_values.size();
917 dim1_size = dim1_size / dim2_size;
918 Span2<const DataType> span2(all_values.data(), dim1_size, dim2_size);
919 return _writeDataSet2D<DataType>(data_info, span2);
926void VtkHdfV2DataWriter::
927_addInt64ArrayAttribute(Hid& hid,
const char* name, Span<const Int64> values)
929 hsize_t
len = values.size();
930 hid_t aid = H5Screate_simple(1, &len,
nullptr);
931 hid_t attr = H5Acreate2(hid.id(), name, H5T_NATIVE_INT64, aid, H5P_DEFAULT, H5P_DEFAULT);
934 int ret = H5Awrite(attr, H5T_NATIVE_INT64, values.data());
944void VtkHdfV2DataWriter::
945_addInt64Attribute(Hid& hid,
const char* name,
Int64 value)
947 HSpace aid(H5Screate(H5S_SCALAR));
950 attr.create(hid, name, H5T_NATIVE_INT64, aid);
952 attr.open(hid, name);
955 herr_t ret = attr.write(H5T_NATIVE_INT64, &value);
963Int64 VtkHdfV2DataWriter::
964_readInt64Attribute(Hid& hid,
const char* name)
967 attr.open(hid, name);
971 herr_t ret = attr.read(H5T_NATIVE_INT64, &value);
980void VtkHdfV2DataWriter::
981_addStringAttribute(Hid& hid,
const char* name,
const String& value)
983 hid_t aid = H5Screate(H5S_SCALAR);
984 hid_t attr_type = H5Tcopy(H5T_C_S1);
985 H5Tset_size(attr_type, value.length());
986 hid_t attr = H5Acreate2(hid.id(), name, attr_type, aid, H5P_DEFAULT, H5P_DEFAULT);
989 int ret = H5Awrite(attr, attr_type, value.localstr());
990 ret = H5Tclose(attr_type);
1000void VtkHdfV2DataWriter::
1006 for (
const auto& i : m_offset_info_list) {
1007 Int64 offset = i.second;
1009 HGroup* hdf_group = offset_info.group();
1012 _writeDataSet1D<Int64>({ { *hdf_group, offset_info.name() }, m_time_offset_info }, asConstSpan(&offset));
1022void VtkHdfV2DataWriter::
1023_openOrCreateGroups()
1026 m_top_group.openOrCreate(m_file_id,
"VTKHDF");
1027 m_cell_data_group.openOrCreate(m_top_group,
"CellData");
1028 m_node_data_group.openOrCreate(m_top_group,
"PointData");
1029 m_steps_group.openOrCreate(m_top_group,
"Steps");
1030 m_point_data_offsets_group.openOrCreate(m_steps_group,
"PointDataOffsets");
1031 m_cell_data_offsets_group.openOrCreate(m_steps_group,
"CellDataOffsets");
1032 m_field_data_offsets_group.openOrCreate(m_steps_group,
"FieldDataOffsets");
1038void VtkHdfV2DataWriter::
1041 m_cell_data_group.close();
1042 m_node_data_group.close();
1043 m_point_data_offsets_group.close();
1044 m_cell_data_offsets_group.close();
1045 m_field_data_offsets_group.close();
1046 m_steps_group.close();
1047 m_top_group.close();
1056 ARCANE_UNUSED(meta_data);
1065 info(4) <<
"Write VtkHdfV2 var=" << var->
name();
1070 ARCANE_FATAL(
"Only export of scalar item variable is implemented (name={0})", var->
name());
1072 ARCANE_FATAL(
"Export of partial variable is not implemented");
1077 switch (item_kind) {
1079 group = &m_cell_data_group;
1080 offset_info = m_cell_offset_info;
1081 group_info = &m_all_cells_info;
1084 group = &m_node_data_group;
1085 offset_info = m_point_offset_info;
1086 group_info = &m_all_nodes_info;
1089 ARCANE_FATAL(
"Only export of 'Cell' or 'Node' variable is implemented (name={0})", var->
name());
1096 switch (data_type) {
1098 _writeBasicTypeDataset<Real>(data_info, data);
1101 _writeBasicTypeDataset<Int64>(data_info, data);
1104 _writeBasicTypeDataset<Int32>(data_info, data);
1107 _writeReal3Dataset(data_info, data);
1110 _writeReal2Dataset(data_info, data);
1113 warning() << String::format(
"Export for datatype '{0}' is not supported (var_name={1})", data_type, var->
name());
1120template <
typename DataType>
void VtkHdfV2DataWriter::
1121_writeBasicTypeDataset(
const DataInfo& data_info,
IData* data)
1131void VtkHdfV2DataWriter::
1132_writeReal3Dataset(
const DataInfo& data_info, IData* data)
1134 auto* true_data =
dynamic_cast<IArrayDataT<Real3>*
>(data);
1136 SmallSpan<const Real3> values(true_data->view());
1137 Int32 nb_value = values.size();
1139 UniqueArray2<Real> scalar_values;
1140 scalar_values.resize(nb_value, 3);
1141 for (Int32 i = 0; i < nb_value; ++i) {
1142 Real3 v = values[i];
1143 scalar_values[i][0] = v.x;
1144 scalar_values[i][1] = v.y;
1145 scalar_values[i][2] = v.z;
1147 _writeDataSet2DCollective<Real>(data_info, scalar_values);
1153void VtkHdfV2DataWriter::
1154_writeReal2Dataset(
const DataInfo& data_info, IData* data)
1157 auto* true_data =
dynamic_cast<IArrayDataT<Real2>*
>(data);
1159 SmallSpan<const Real2> values(true_data->view());
1160 Int32 nb_value = values.size();
1161 UniqueArray2<Real> scalar_values;
1162 scalar_values.resize(nb_value, 3);
1163 for (
Int32 i = 0; i < nb_value; ++i) {
1164 Real2 v = values[i];
1165 scalar_values[i][0] = v.x;
1166 scalar_values[i][1] = v.y;
1167 scalar_values[i][2] = 0.0;
1169 _writeDataSet2DCollective<Real>(data_info, scalar_values);
1175void VtkHdfV2DataWriter::
1178 HGroup* hgroup = offset_info.group();
1180 StandardArrayT<Int64> a(hgroup->id(), offset_info.name());
1181 UniqueArray<Int64> values;
1182 a.directRead(m_standard_types, values);
1183 Int64 offset_value = values[wanted_step];
1184 offset_info.setOffset(offset_value);
1185 info() <<
"VALUES name=" << offset_info.name() <<
" values=" << values
1186 <<
" wanted_step=" << wanted_step <<
" v=" << offset_value;
1192void VtkHdfV2DataWriter::
1213 m_cell_offset_info =
DatasetInfo(m_steps_group,
"CellOffsets");
1214 m_point_offset_info =
DatasetInfo(m_steps_group,
"PointOffsets");
1215 m_connectivity_offset_info =
DatasetInfo(m_steps_group,
"ConnectivityIdOffsets");
1217 m_offset_for_cell_offset_info =
DatasetInfo(
"_OffsetForCellOffsetInfo");
1218 m_part_offset_info =
DatasetInfo(
"_PartOffsetInfo");
1219 m_time_offset_info =
DatasetInfo(
"_TimeOffsetInfo");
1224 if (m_is_writer && !m_is_first_call) {
1225 IParallelMng* pm = m_mesh->parallelMng();
1226 const Int32 nb_rank = pm->commSize();
1227 Int64 nb_current_step = _readInt64Attribute(m_steps_group,
"NSteps");
1228 Int32 time_index = m_times.size();
1229 info(4) <<
"NB_STEP=" << nb_current_step <<
" time_index=" << time_index
1230 <<
" current_time=" << m_times.back();
1231 const bool debug_times =
false;
1233 StandardArrayT<Real> a1(m_steps_group.id(),
"Values");
1234 UniqueArray<Real> times;
1235 a1.directRead(m_standard_types, times);
1236 info() <<
"TIMES=" << times;
1238 if ((nb_current_step + 1) != time_index) {
1239 info() <<
"[VtkHdf] go_backward detected";
1240 Int32 wanted_step = time_index - 1;
1243 _readAndSetOffset(m_cell_offset_info, wanted_step);
1244 _readAndSetOffset(m_point_offset_info, wanted_step);
1245 _readAndSetOffset(m_connectivity_offset_info, wanted_step);
1246 m_part_offset_info.setOffset(wanted_step * nb_rank);
1247 m_time_offset_info.setOffset(wanted_step);
1248 m_offset_for_cell_offset_info.setOffset(m_cell_offset_info.offset() + wanted_step * nb_rank);
1261class VtkHdfV2PostProcessor
1262:
public ArcaneVtkHdfV2PostProcessorObject
1267 : ArcaneVtkHdfV2PostProcessorObject(sbi)
1271 IDataWriter* dataWriter()
override {
return m_writer.get(); }
1272 void notifyBeginWrite()
override
1274 bool use_collective_io =
true;
1275 Int64 max_write_size = 0;
1277 use_collective_io = options()->useCollectiveWrite();
1278 max_write_size = options()->maxWriteSize();
1280 auto w = std::make_unique<VtkHdfV2DataWriter>(mesh(), groups(), use_collective_io);
1281 w->setMaxWriteSize(max_write_size);
1282 w->setTimes(times());
1284 w->setDirectoryName(dir.
file(
"vtkhdfv2"));
1285 m_writer = std::move(w);
1287 void notifyEndWrite()
override
1291 void close()
override {}
1295 std::unique_ptr<IDataWriter> m_writer;
#define ARCANE_CHECK_POINTER(ptr)
Macro retournant le pointeur ptr s'il est non nul ou lancant une exception s'il est nul.
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Classe gérant un répertoire.
String file(const String &file_name) const override
Retourne le chemin complet du fichier file_name dans le répertoire.
Encapsule un hid_t pour un groupe.
static void useMutex(bool is_active, IParallelMng *pm)
Fonction permettant d'activer ou de désactiver les verrous à chaque appel à HDF5.
static bool hasParallelHdf5()
Vrai HDF5 est compilé avec le support de MPI.
Interface d'écriture des données d'une variable.
Interface d'une variable.
virtual eDataType dataType() const =0
Type de la donnée gérée par la variable (Real, Integer, ...)
virtual eItemKind itemKind() const =0
Genre des entités du maillage sur lequel repose la variable.
virtual bool isPartial() const =0
Indique si la variable est partielle.
virtual Integer dimension() const =0
Dimension de la variable.
virtual String name() const =0
Nom de la variable.
Groupe d'entités de maillage.
Integer size() const
Nombre d'éléments du groupe.
static IMeshMaterialMng * getReference(const MeshHandleOrMesh &mesh_handle, bool create=true)
Récupère ou créé la référence associée à mesh.
Structure contenant les informations pour créer un service.
Vue d'un tableau d'éléments de type T.
Chaîne de caractères unicode.
Classe d'accès aux traces.
TraceAccessor(ITraceMng *m)
Construit un accesseur via le gestionnaire de trace m.
TraceMessage info() const
Flot pour un message d'information.
TraceMessage warning() const
Flot pour un message d'avertissement.
void write(IVariable *var, IData *data) override
Ecrit les données data de la variable var.
void setMetaData(const String &meta_data) override
Positionne les infos des méta-données.
Post-traitement au format VtkHdf V2.
__host__ __device__ Real2 min(Real2 a, Real2 b)
Retourne le minimum de deux Real2.
ItemGroupT< Cell > CellGroup
Groupe de mailles.
ItemGroupT< Node > NodeGroup
Groupe de noeuds.
MeshVariableScalarRefT< Node, Real3 > VariableNodeReal3
Grandeur au noeud de type coordonnées.
Integer len(const char *s)
Retourne la longueur de la chaîne s.
Fonctions utilitaires pour Hdf5.
Active toujours les traces dans les parties Arcane concernant les matériaux.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Ref< TrueType > createRef(Args &&... args)
Créé une instance de type TrueType avec les arguments Args et retourne une référence dessus.
Collection< ItemGroup > ItemGroupCollection
Collection de groupes d'éléments du maillage.
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
bool operator<(const Item &item1, const Item &item2)
Compare deux entités.
ConstMemoryView makeConstMemoryView(const void *ptr, Int32 datatype_size, Int64 nb_element)
Créé une vue mémoire en lecture seule.
eItemKind
Genre d'entité de maillage.
@ IK_Node
Entité de maillage de genre noeud.
@ IK_Cell
Entité de maillage de genre maille.
double Real
Type représentant un réel.
unsigned char Byte
Type d'un octet.
eDataType
Type d'une donnée.
@ DT_Int32
Donnée de type entier 32 bits.
@ DT_Real3
Donnée de type vecteur 3.
@ DT_Int64
Donnée de type entier 64 bits.
@ DT_Real2
Donnée de type vecteur 2.
@ DT_Real
Donnée de type réel.
@ Cell
Le maillage est AMR par maille.
std::int32_t Int32
Type entier signé sur 32 bits.
ConstArrayView< Real > RealConstArrayView
Equivalent C d'un tableau à une dimension de réels.
Conserve les infos sur les données à sauver et l'offset associé.
Classe pour conserver un couple (hdf_group,nom_du_dataset).
Classe pour conserver les information d'un offset.
Int64 offset() const
Valeur de l'offset. (-1) si on écrit à la fin du tableau.
Informations collectives sur un ItemGroup;.
WritePartInfo m_write_part_info
Informations sur l'écriture.
ItemGroup m_item_group
Groupe associé
Informations sur l'offset de la partie à écrire associée à un rang.