14#include "arcane/utils/Collection.h"
15#include "arcane/utils/Enumerator.h"
16#include "arcane/utils/HashTableMap.h"
17#include "arcane/utils/IOException.h"
18#include "arcane/utils/ITraceMng.h"
19#include "arcane/utils/Iostream.h"
20#include "arcane/utils/OStringStream.h"
21#include "arcane/utils/ScopedPtr.h"
22#include "arcane/utils/StdHeader.h"
23#include "arcane/utils/String.h"
24#include "arcane/utils/ValueConvert.h"
25#include "arcane/utils/Real3.h"
26#include "arcane/utils/CheckedConvert.h"
28#include "arcane/core/BasicService.h"
29#include "arcane/core/FactoryService.h"
30#include "arcane/core/ICaseMeshReader.h"
31#include "arcane/core/IItemFamily.h"
32#include "arcane/core/IPrimaryMesh.h"
33#include "arcane/core/IMeshBuilder.h"
34#include "arcane/core/IMeshReader.h"
35#include "arcane/core/IMeshUtilities.h"
36#include "arcane/core/IMeshWriter.h"
37#include "arcane/core/IParallelMng.h"
38#include "arcane/core/IVariableAccessor.h"
39#include "arcane/core/IXmlDocumentHolder.h"
40#include "arcane/core/Item.h"
42#include "arcane/core/IVariableMng.h"
43#include "arcane/core/VariableTypes.h"
44#include "arcane/core/XmlNode.h"
45#include "arcane/core/XmlNodeList.h"
46#include "arcane/core/UnstructuredMeshAllocateBuildInfo.h"
48#include "arcane/core/internal/IVariableMngInternal.h"
49#include "arcane/core/internal/VtkCellTypes.h"
61using namespace Arcane::VtkUtils;
102class VtkMeshIOService
120 VTK_MT_StructuredGrid,
121 VTK_MT_UnstructuredGrid
160 const String& dir_name,
bool use_internal_partition);
173 static const int BUFSIZE = 10000;
177 explicit VtkFile(std::istream* stream)
192 const String& expected_value1,
193 const String& expected_value2);
298 bool is_comment =
true;
301 for (
int i = 0; i < BUFSIZE &&
m_buf[i] !=
'\0'; ++i) {
302 if (!isspace(
m_buf[i]) &&
m_buf[i] !=
'#' && is_comment) {
305 if (
m_buf[i] ==
'#') {
314 for (
int i = 0; i < BUFSIZE &&
m_buf[i] !=
'\0'; ++i) {
315 if (
m_buf[i] ==
'\r') {
369 bool is_comment =
true;
377 for (
int i = 0; i < BUFSIZE &&
m_buf[i] !=
'\0'; ++i) {
378 if (!isspace(
m_buf[i]) &&
m_buf[i] !=
'#' && is_comment) {
381 if (
m_buf[i] ==
'#') {
390 for (
int i = 0; i < BUFSIZE &&
m_buf[i] !=
'\0'; ++i) {
391 if (
m_buf[i] ==
'\r') {
418 (*m_stream) >> ws >> v;
442 (*m_stream) >> ws >> v;
466 (*m_stream) >> ws >> v;
486 constexpr size_t sizeofT =
sizeof(T);
489 Byte big_endian[sizeofT];
490 Byte little_endian[sizeofT];
493 m_stream->read((
char*)big_endian, sizeofT);
496 for (
size_t i = 0; i < sizeofT; i++) {
497 little_endian[sizeofT - 1 - i] = big_endian[i];
501 T* conv =
new (little_endian) T;
521 String expected_value_low = expected_value.
lower();
523 if (current_value_low != expected_value_low) {
525 expected_value, current_value);
545 String expected_value1_low = expected_value1.
lower();
546 String expected_value2_low = expected_value2.
lower();
548 if (current_value_low != expected_value1_low && current_value_low != expected_value2_low) {
550 expected_value1, expected_value2, current_value);
569 String expected_value_low = expected_value.
lower();
570 return (current_value_low == expected_value_low);
588 std::ifstream ifile(file_name.
localstr(), std::ifstream::binary);
591 error() <<
"Unable to read file '" << file_name <<
"'";
604 info() <<
"Titre du fichier VTK : " << title.
localstr();
612 vtk_file.setIsBinaryFile(
true);
615 eMeshType mesh_type = VTK_MT_Unknown;
623 std::istringstream mesh_type_line(buf);
624 std::string dataset_str;
625 std::string mesh_type_str;
627 mesh_type_line >> ws >> dataset_str >> ws >> mesh_type_str;
632 mesh_type = VTK_MT_StructuredGrid;
636 mesh_type = VTK_MT_UnstructuredGrid;
639 if (mesh_type == VTK_MT_Unknown) {
640 error() <<
"Support exists only for 'STRUCTURED_GRID' and 'UNSTRUCTURED_GRID' formats (format=" << mesh_type_str <<
"')";
644 debug() <<
"Lecture en-tête OK";
648 case VTK_MT_StructuredGrid:
652 case VTK_MT_UnstructuredGrid:
654 debug() <<
"Lecture _readUnstructuredGrid OK";
658 debug() <<
"Lecture _readFacesMesh OK";
688 const char* buf =
nullptr;
694 std::istringstream iline(buf);
695 std::string dimension_str;
696 iline >> ws >> dimension_str >> ws >> nb_node_x >> ws >> nb_node_y >> ws >> nb_node_z;
699 error() <<
"Syntax error while reading grid dimensions";
704 if (nb_node_x <= 1 || nb_node_y <= 1 || nb_node_z <= 1) {
705 error() <<
"Invalid dimensions: x=" << nb_node_x <<
" y=" << nb_node_y <<
" z=" << nb_node_z;
709 info() <<
" Infos: " << nb_node_x <<
" " << nb_node_y <<
" " << nb_node_z;
710 Integer nb_node = nb_node_x * nb_node_y * nb_node_z;
713 std::string float_str;
716 std::istringstream iline(buf);
717 std::string points_str;
719 iline >> ws >> points_str >> ws >> nb_node_read >> ws >> float_str;
721 error() <<
"Syntax error while reading grid dimensions";
725 if (nb_node_read != nb_node) {
726 error() <<
"Number of invalid nodes: expected=" << nb_node <<
" found=" << nb_node_read;
731 Int32 rank =
mesh->parallelMng()->commRank();
733 Integer nb_cell_x = nb_node_x - 1;
734 Integer nb_cell_y = nb_node_y - 1;
735 Integer nb_cell_z = nb_node_z - 1;
737 if (use_internal_partition && rank != 0) {
746 const Integer nb_node_yz = nb_node_y * nb_node_z;
747 const Integer nb_node_xy = nb_node_x * nb_node_y;
749 Integer nb_cell = nb_cell_x * nb_cell_y * nb_cell_z;
756 info() <<
" NODE YZ = " << nb_node_yz;
761 for (
Integer x = 0; x < nb_node_x; ++x) {
762 for (
Integer z = 0; z < nb_node_z; ++z) {
763 for (
Integer y = 0; y < nb_node_y; ++y) {
765 Integer node_unique_id = y + (z)*nb_node_y + x * nb_node_y * nb_node_z;
767 nodes_unique_id[node_local_id] = node_unique_id;
795 for (
Integer z = 0; z < nb_cell_z; ++z) {
796 for (
Integer y = 0; y < nb_cell_y; ++y) {
797 for (
Integer x = 0; x < nb_cell_x; ++x) {
798 Integer current_cell_nb_node = 8;
801 Int64 cell_unique_id = x + y * nb_cell_x + z * nb_cell_x * nb_cell_y;
803 cells_infos[cells_infos_index] = IT_Hexaedron8;
806 cells_infos[cells_infos_index] = cell_unique_id;
810 Integer base_id = x + y * nb_node_x + z * nb_node_xy;
811 cells_infos[cells_infos_index + 0] = nodes_unique_id[base_id];
812 cells_infos[cells_infos_index + 1] = nodes_unique_id[base_id + 1];
813 cells_infos[cells_infos_index + 2] = nodes_unique_id[base_id + nb_node_x + 1];
814 cells_infos[cells_infos_index + 3] = nodes_unique_id[base_id + nb_node_x + 0];
815 cells_infos[cells_infos_index + 4] = nodes_unique_id[base_id + nb_node_xy];
816 cells_infos[cells_infos_index + 5] = nodes_unique_id[base_id + nb_node_xy + 1];
817 cells_infos[cells_infos_index + 6] = nodes_unique_id[base_id + nb_node_xy + nb_node_x + 1];
818 cells_infos[cells_infos_index + 7] = nodes_unique_id[base_id + nb_node_xy + nb_node_x + 0];
819 cells_infos_index += current_cell_nb_node;
820 cells_local_id[cell_local_id] = cell_local_id;
827 mesh->setDimension(3);
828 mesh->allocateCells(nb_cell, cells_infos,
false);
836 for (
Integer z = 0; z < nb_node_z; ++z) {
837 for (
Integer y = 0; y < nb_node_y; ++y) {
838 for (
Integer x = 0; x < nb_node_x; ++x) {
842 Integer node_unique_id = x + y * nb_node_x + z * nb_node_xy;
843 coords[node_unique_id] =
Real3(nx, ny, nz);
849 for (
Integer z = 0; z < nb_node_z; ++z) {
850 for (
Integer y = 0; y < nb_node_y; ++y) {
851 for (
Integer x = 0; x < nb_node_x; ++x) {
855 Integer node_unique_id = x + y * nb_node_x + z * nb_node_xy;
856 coords[node_unique_id] =
Real3(nx, ny, nz);
862 for (
Integer z = 0; z < nb_node_z; ++z) {
863 for (
Integer y = 0; y < nb_node_y; ++y) {
864 for (
Integer x = 0; x < nb_node_x; ++x) {
868 Integer node_unique_id = x + y * nb_node_x + z * nb_node_xy;
869 coords[node_unique_id] =
Real3(nx, ny, nz);
881 nodes_coord_var[inode] = coords[node.
uniqueId().asInt32()];
905 Int64 node_unique_id = node.uniqueId().asInt64();
906 Int64 node_z = node_unique_id / nb_node_xy;
907 Int64 node_y = (node_unique_id - node_z * nb_node_xy) / nb_node_x;
908 Int64 node_x = node_unique_id - node_z * nb_node_xy - node_y * nb_node_x;
911 if (node_x != (nb_node_x - 1))
915 if (node_y != (nb_node_y - 1))
919 if (node_z != (nb_node_z - 1))
923 xmin_surface_lid.
add(face_local_id);
925 xmax_surface_lid.
add(face_local_id);
927 ymin_surface_lid.
add(face_local_id);
929 ymax_surface_lid.
add(face_local_id);
931 zmin_surface_lid.
add(face_local_id);
933 zmax_surface_lid.
add(face_local_id);
969 std::istringstream iline(buf);
970 std::string points_str;
971 std::string data_type_str;
974 iline >> ws >> points_str >> ws >> nb_node >> ws >> data_type_str;
984 info() <<
"VTK file : number of nodes = " << nb_node;
987 node_coords.
resize(nb_node);
990 for (
Integer i = 0; i < nb_node; ++i) {
994 node_coords[i] =
Real3(nx, ny, nz);
998 for (
Integer i = 0; i < nb_node; ++i) {
1002 node_coords[i] =
Real3(nx, ny, nz);
1006 for (
Integer i = 0; i < nb_node; ++i) {
1010 node_coords[i] =
Real3(nx, ny, nz);
1040 ARCANE_UNUSED(
mesh);
1044 std::istringstream iline(buf);
1045 std::string cells_str;
1046 Int32 i64_nb_cell = 0;
1047 Int32 i64_nb_cell_node = 0;
1049 iline >> ws >> cells_str >> ws >> i64_nb_cell >> ws >> i64_nb_cell_node;
1056 info() <<
"VTK file : nb_cell = " << i64_nb_cell <<
" nb_cell_node=" << i64_nb_cell_node;
1058 if (i64_nb_cell < 0 || i64_nb_cell_node < 0) {
1060 i64_nb_cell, i64_nb_cell_node);
1063 Int32 nb_cell = CheckedConvert::toInt32(i64_nb_cell);
1064 Int32 nb_cell_node = CheckedConvert::toInt32(i64_nb_cell_node);
1066 cells_nb_node.
resize(nb_cell);
1067 cells_type.
resize(nb_cell);
1068 cells_connectivity.
resize(nb_cell_node);
1071 Integer connectivity_index = 0;
1072 for (
Integer i = 0; i < nb_cell; ++i) {
1074 cells_nb_node[i] = n;
1075 for (
Integer j = 0; j < n; ++j) {
1077 cells_connectivity[connectivity_index] = id;
1078 ++connectivity_index;
1088 std::istringstream iline(buf);
1089 std::string cell_types_str;
1091 iline >> ws >> cell_types_str >> ws >> nb_cell_type;
1097 vtk_file.
checkString(cell_types_str,
"CELL_TYPES");
1098 if (nb_cell_type != nb_cell) {
1100 nb_cell_type, nb_cell);
1104 for (
Integer i = 0; i < nb_cell; ++i) {
1106 Int16 it = vtkToArcaneCellType(vtk_ct, cells_nb_node[i]);
1125 ARCANE_UNUSED(
mesh);
1129 if (vtk_file.isEof())
1136 vtk_file.reReadSameLine();
1236 Int32 sid =
mesh->parallelMng()->commRank();
1241 bool need_read =
true;
1243 if (use_internal_partition)
1244 need_read = (sid == 0);
1246 std::array<Int64, 4> nb_cell_by_dimension = {};
1247 Int32 mesh_dimension = -1;
1254 debug() <<
"Lecture _readNodesUnstructuredGrid OK";
1255 nb_node = node_coords.
size();
1263 debug() <<
"Reading _readCellsUnstructuredGrid OK";
1265 nb_cell = cells_nb_node.
size();
1266 nb_cell_node = cells_connectivity.
size();
1267 cells_local_id.
resize(nb_cell);
1270 mesh_build_info.
preAllocate(nb_cell, nb_cell_node);
1273 Int32 connectivity_index = 0;
1274 for (
Integer i = 0; i < nb_cell; ++i) {
1275 Int32 current_cell_nb_node = cells_nb_node[i];
1276 Int64 cell_unique_id = i;
1278 cells_local_id[i] = i;
1281 if (cell_dim >= 0 && cell_dim <= 3)
1282 ++nb_cell_by_dimension[cell_dim];
1284 auto cell_nodes = cells_connectivity.
subView(connectivity_index, current_cell_nb_node);
1285 mesh_build_info.
addCell(cells_type[i], cell_unique_id, cell_nodes);
1286 connectivity_index += current_cell_nb_node;
1290 Int32 nb_different_dim = 0;
1291 for (
Int32 i = 0; i < 4; ++i)
1292 if (nb_cell_by_dimension[i] != 0) {
1296 if (nb_different_dim > 1)
1297 ARCANE_FATAL(
"The mesh contains cells of different dimension. nb0={0} nb1={1} nb2={2} nb3={3}",
1298 nb_cell_by_dimension[0], nb_cell_by_dimension[1], nb_cell_by_dimension[2], nb_cell_by_dimension[3]);
1303 Integer wanted_dimension = mesh_dimension;
1316 nodes_coord_var[inode] = node_coords[node.
uniqueId().asInt32()];
1322 debug() <<
"Reading _readData OK";
1340 bool use_internal_partition)
1342 ARCANE_UNUSED(dir_name);
1344 std::ifstream ifile(file_name.
localstr(), std::ifstream::binary);
1346 info() <<
"No face descriptor file found '" << file_name <<
"'";
1351 const char* buf = 0;
1355 info() <<
"Reading VTK file '" << file_name <<
"'";
1356 info() <<
"Title of VTK file: " << title;
1360 vtk_file.setIsBinaryFile(
true);
1363 eMeshType mesh_type = VTK_MT_Unknown;
1369 std::istringstream mesh_type_line(buf);
1370 std::string dataset_str;
1371 std::string mesh_type_str;
1372 mesh_type_line >> ws >> dataset_str >> ws >> mesh_type_str;
1376 mesh_type = VTK_MT_UnstructuredGrid;
1379 if (mesh_type == VTK_MT_Unknown) {
1380 error() <<
"Face descriptor file type must be 'UNSTRUCTURED_GRID' (format=" << mesh_type_str <<
"')";
1393 bool need_read =
true;
1394 if (use_internal_partition)
1395 need_read = (sid == 0);
1412 nb_face = faces_nb_node.
size();
1416 faces_local_id.
resize(nb_face);
1459 if ((sid == 0) && vtk_file.isEof())
1463 pm->broadcast(bb, 0);
1470 created_infos_str() <<
"<?xml version='1.0' ?>\n";
1471 created_infos_str() <<
"<infos>";
1474 const char* buf = 0;
1477 bool reading_node =
false;
1478 bool reading_cell =
false;
1479 while (((buf = vtk_file.
getNextLine()) != 0) && !vtk_file.isEof()) {
1480 debug() <<
"Read line";
1481 std::istringstream iline(buf);
1482 std::string data_str;
1488 iline >> ws >> nb_item;
1489 reading_node =
false;
1490 reading_cell =
true;
1491 if (nb_item != nb_cell_kind)
1492 error() <<
"Size expected = " << nb_cell_kind <<
" found = " << nb_item;
1498 iline >> ws >> nb_item;
1499 reading_node =
true;
1500 reading_cell =
false;
1501 if (nb_item != nb_node)
1502 error() <<
"Size expected = " << nb_node <<
" found = " << nb_item;
1507 std::string name_str;
1510 iline >> ws >> name_str >> ws >> nb_fields;
1513 std::string type_str;
1514 std::string s_name_str;
1515 int nb_component = 1;
1516 bool is_group =
false;
1518 for (
Integer i = 0; i < nb_fields; i++) {
1520 std::istringstream iline(buf);
1521 iline >> ws >> s_name_str >> ws >> nb_component >> ws >> nb_item >> ws >> type_str;
1523 if (nb_item != nb_cell_kind && reading_cell && !reading_node)
1524 error() <<
"Size expected = " << nb_cell_kind <<
" found = " << nb_item;
1526 if (nb_item != nb_node && !reading_cell && reading_node)
1527 error() <<
"Size expected = " << nb_node <<
" found = " << nb_item;
1529 String name_str = s_name_str;
1532 if (cstr ==
"GROUP_") {
1535 debug() <<
"** ** ** GROUP ! name=" << new_name;
1536 name_str = new_name;
1541 error() <<
"Group type must be 'int', found=" << type_str;
1546 created_infos_str() <<
"<node-group name='" << name_str <<
"'/>";
1551 created_infos_str() <<
"<cell-group name='" << name_str <<
"'/>";
1559 error() <<
"Expecting 'float' or 'double' data type, found=" << type_str;
1564 fatal() <<
"Unable to read POINT_DATA: feature not implemented";
1567 created_infos_str() <<
"<cell-variable name='" << name_str <<
"'/>";
1570 throw IOException(
"Unable to read face variables: feature not supported");
1580 if (reading_node || reading_cell) {
1581 std::string type_str;
1582 std::string s_name_str;
1584 bool is_group =
false;
1585 int nb_component = 1;
1587 iline >> ws >> s_name_str >> ws >> type_str >> ws >> nb_component;
1588 debug() <<
"** ** ** READNAME: name=" << s_name_str <<
" type=" << type_str;
1590 String name_str = s_name_str;
1593 if (cstr ==
"GROUP_") {
1596 info() <<
"** ** ** GROUP ! name=" << new_name;
1597 name_str = new_name;
1601 error() <<
"Expecting 'SCALARS' data type, found=" << data_str;
1607 error() <<
"Group type must be 'int', found=" << type_str;
1615 created_infos_str() <<
"<node-group name='" << name_str <<
"'/>";
1620 created_infos_str() <<
"<cell-group name='" << name_str <<
"'/>";
1626 error() <<
"Expecting 'float' or 'double' data type, found=" << type_str;
1633 fatal() <<
"Unable to read POINT_DATA: feature not implemented";
1636 created_infos_str() <<
"<cell-variable name='" << name_str <<
"'/>";
1639 throw IOException(
"Unable to read face variables: feature not supported");
1646 error() <<
"Expecting value CELL_DATA or POINT_DATA, found='" << data_str <<
"'";
1652 created_infos_str() <<
"</infos>";
1653 if (use_internal_partition) {
1656 String str = created_infos_str.str();
1659 bytes.resize(len + 1);
1666 String str = String::fromUtf8(bytes);
1667 info() <<
"FOUND STR=" << bytes.size() <<
" " << str;
1669 XmlNode doc_node = doc->documentNode();
1675 String name = xnode.attrValue(
"name");
1676 info() <<
"Building variable: " << name;
1686 String name = xnode.attrValue(
"name");
1687 info() <<
"Building group: " << name;
1697 String name = xnode.attrValue(
"name");
1698 info() <<
"Create node group: " << name;
1721 info() <<
"Building face group '" << name <<
"'"
1722 <<
" size=" << faces_lid.
size();
1724 mesh->faceFamily()->createGroup(name, faces_lid);
1742 info() <<
"Reading values for variable: " << var_name <<
" n=" << nb_cell;
1744 mesh->variableMng()->_internalApi()->addAutoDestroyVariable(var);
1746 for (
Integer i = 0; i < nb_cell; ++i) {
1751 info() <<
"Variable build finished: " << vtk_file.isEof();
1772 info() <<
"Reading group info for group: " << name;
1775 for (
Integer i = 0; i < nb_item; ++i) {
1778 ids.
add(local_id[i]);
1780 info() <<
"Building group: " << name <<
" nb_element=" << ids.
size();
1802 info() <<
"Reading node group info for group: " << name;
1805 for (
Integer i = 0; i < nb_item; ++i) {
1810 info() <<
"Creating group: " << name <<
" nb_element=" << ids.
size();
1823class VtkLegacyMeshWriter
1824:
public BasicService
1844 void _saveGroups(
IItemFamily* family, std::ostream& ofile);
1872 String fname = file_name;
1875 fname = fname +
".vtk";
1893 std::ofstream ofile(file_name.
localstr());
1896 throw IOException(
"VtkMeshIOService::writeMeshToFile(): Unable to open file");
1897 ofile <<
"# vtk DataFile Version 2.0\n";
1898 ofile <<
"Maillage Arcane\n";
1900 ofile <<
"DATASET UNSTRUCTURED_GRID\n";
1902 nodes_local_id_to_current.
fill(NULL_ITEM_ID);
1910 ofile <<
"POINTS " << nb_node <<
" double\n";
1915 nodes_local_id_to_current[node.
localId()] = node_index;
1916 Real3 xyz = coords[inode];
1917 ofile << xyz.
x <<
' ' << xyz.
y <<
' ' << xyz.
z <<
'\n';
1924 Integer nb_node_cell_kind = nb_cell_kind;
1925 ENUMERATE_ITEMWITHNODES(iitem, cell_kind_family->
allItems())
1927 nb_node_cell_kind += (*iitem).nbNode();
1929 ofile <<
"CELLS " << nb_cell_kind <<
' ' << nb_node_cell_kind <<
"\n";
1930 ENUMERATE_ITEMWITHNODES(iitem, cell_kind_family->
allItems())
1934 ofile << item_nb_node;
1935 for (NodeLocalId node_id : item.
nodes()) {
1936 ofile <<
' ' << nodes_local_id_to_current[node_id];
1941 ofile <<
"CELL_TYPES " << nb_cell_kind <<
"\n";
1945 int type = VTK_BAD_ARCANE_TYPE;
1949 type = arcaneToVtkCellType(iti);
1950 ofile << type <<
'\n';
1956 ofile <<
"POINT_DATA " << nb_node <<
"\n";
1961 ofile <<
"CELL_DATA " << nb_cell_kind <<
"\n";
1962 _saveGroups(
mesh->itemFamily(cell_kind), ofile);
1968void VtkLegacyMeshWriter::
1969_saveGroups(
IItemFamily* family, std::ostream& ofile)
1971 info() <<
"Saving groups for family name=" << family->
name();
1979 if (group.
name() ==
"OuterFaces")
1981 ofile <<
"SCALARS GROUP_" << group.
name() <<
" int 1\n";
1982 ofile <<
"LOOKUP_TABLE default\n";
1983 in_group_list.fill(
'0');
1985 in_group_list[(*iitem).localId()] =
'1';
1988 ofile << in_group_list[(*iitem).localId()] <<
'\n';
2013 const String& dir_name,
bool use_internal_partition)
override
2016 ARCANE_UNUSED(mesh_node);
2018 bool ret = vtk_service.
readMesh(
mesh, file_name, dir_name, use_internal_partition);
2041class VtkLegacyCaseMeshReader
2054 , m_read_info(read_info)
2061 ARCANE_UNUSED(build_info);
2066 String fname = m_read_info.fileName();
2067 m_trace_mng->info() <<
"VtkLegacy Reader (ICaseMeshReader) file_name=" << fname;
2068 bool ret = vtk_service.
readMesh(pm, fname, m_read_info.directoryName(), m_read_info.isParallelRead());
2090 if (read_info.format() ==
"vtk")
#define ARCANE_THROW(exception_class,...)
Macro for throwing an exception with formatting.
#define ARCANE_FATAL(...)
Macro throwing a FatalErrorException.
#define ARCANE_REGISTER_SUB_DOMAIN_FACTORY(aclass, ainterface, aname)
Registers a factory service for the class aclass.
#define ARCANE_SERVICE_INTERFACE(ainterface)
Macro to declare an interface when registering a service.
Integer size() const
Number of elements in the vector.
AbstractService(const ServiceBuildInfo &)
Constructor from a ServiceBuildInfo.
Base class for 1D data vectors.
void fill(ConstReferenceType value)
Fills the array with the value value.
void resize(Int64 s)
Changes the number of elements in the array to s.
void add(ConstReferenceType val)
Adds element val to the end of the array.
ArrayView< T > subView(Int64 abegin, Integer asize)
Sub-view starting from element abegin and containing asize elements.
Necessary information for reading a mesh file.
EnumeratorT< ItemGroup > Enumerator
Constant view of an array of type T.
constexpr Integer size() const noexcept
Number of elements in the array.
Information about the floating-point type.
Interface for the mesh reading service from the dataset.
Interface of an entity family.
virtual ItemGroupCollection groups() const =0
Collection of groups in this family.
virtual ItemGroup allItems() const =0
Group of all entities.
virtual ItemGroup createGroup(const String &name, Int32ConstArrayView local_ids, bool do_override=false)=0
Creates an entity group named name containing the entities local_ids.
virtual Int32 maxLocalId() const =0
virtual String name() const =0
Family name.
virtual Integer nbItem() const =0
Number of entities.
Interface of a mesh creation/reading service.
Interface of the service managing the reading of a mesh.
eReturnType
Types of return codes for a read or write operation.
@ RTError
Error during the operation.
@ RTOk
Operation successfully performed.
Interface of a class providing utility functions on meshes.
virtual void getFacesLocalIdFromConnectivity(ConstArrayView< ItemTypeId > items_type, ConstArrayView< Int64 > items_connectivity, ArrayView< Int32 > local_ids, bool allow_null=false)=0
Searches for the local IDs of faces based on their connectivity.
Interface of a mesh writing service.
Exception when an input/output error is detected.
Interface of the parallelism manager for a subdomain.
virtual Int32 commRank() const =0
Rank of this instance in the communicator.
virtual void broadcastMemoryBuffer(ByteArray &bytes, Int32 rank)=0
Performs a broadcast of a memory region.
virtual void addAutoDestroyVariable(VariableRef *var)=0
Adds the variable to the list of variables that are kept until the end of execution.
Variable manager interface.
virtual IVariableMngInternal * _internalApi()=0
Internal Arcane API.
static IXmlDocumentHolder * loadFromBuffer(Span< const Byte > buffer, const String &name, ITraceMng *tm)
Loads an XML document.
const String & name() const
Group name.
Type of an entity (Item).
Info on a mesh entity type.
Int16 dimension() const
Dimension of the element (<0 if unknown).
bool isPolygon() const
Indicates if the type is a polygon.
Mesh entity type manager.
ItemTypeInfo * typeFromId(Integer id) const
Type corresponding to the number id.
Mesh element based on nodes (Edge,Face,Cell).
NodeConnectedListViewType nodes() const
List of nodes of the entity.
Int32 nbNode() const
Number of nodes of the entity.
constexpr Int32 localId() const
Local identifier of the entity in the processor subdomain.
ItemUniqueId uniqueId() const
Unique identifier across all domains.
Parameters necessary for building a mesh.
Output stream linked to a String.
Class managing a 3-dimensional real vector.
Reference to an instance.
Encapsulation of an automatically destructing pointer.
Structure containing the information to create a service.
Service creation properties.
Unicode character string.
String lower() const
Transforms all characters in the string to lowercase.
const char * localstr() const
Returns the conversion of the instance into UTF-8 encoding.
ByteConstArrayView utf8() const
Returns the conversion of the instance into UTF-8 encoding.
bool endsWith(const String &s) const
Indicates if the string ends with the characters of s.
String substring(Int64 pos) const
Substring starting at position pos.
TraceAccessor(ITraceMng *m)
Constructs an accessor via the trace manager m.
TraceMessageDbg debug(Trace::eDebugLevel=Trace::Medium) const
Flow for a debug message.
TraceMessage fatal() const
Flow for a fatal error message.
TraceMessage info() const
Flow for an information message.
TraceMessage error() const
Flow for an error message.
ITraceMng * traceMng() const
Trace manager.
1D data vector with value semantics (STL style).
Information for allocating entities of an unstructured mesh.
void allocateMesh()
Allocates the mesh with the cells added during the call to addCell().
void setMeshDimension(Int32 v)
Sets the mesh dimension.
void preAllocate(Int32 nb_cell, Int64 nb_connectivity_node)
Pre-allocate the memory.
void addCell(ItemTypeId type_id, Int64 cell_uid, SmallSpan< const Int64 > nodes_uid)
Adds a cell to the mesh.
Parameters necessary for building a variable.
const char * getCurrentLine()
Allows returning the line present in the buffer.
bool isEmptyNextLine()
Allows checking if the next line is empty.
bool m_is_init
Has at least one line been read.
std::istream * m_stream
The stream.
static bool isEqualString(const String ¤t_value, const String &expected_value)
Allows checking if expected_value == current_value.
double getDouble()
Allows retrieving the next double.
bool m_is_eof
Is the end of the file reached.
char m_buf[BUFSIZE]
The buffer containing the read line.
void getBinary(T &type)
Allows retrieving the next binary number.
int getInt()
Allows retrieving the next integer.
void checkString(const String ¤t_value, const String &expected_value)
Allows checking if expected_value == current_value.
bool m_is_binary_file
Is this a file containing binary data.
bool m_need_reread_current_line
Should the same line be reread.
const char * getNextLine()
Allows retrieving the next line from the file.
float getFloat()
Allows retrieving the following float.
void allocateMeshItems(IPrimaryMesh *pm) override
Allocates the mesh entities managed by this service.
void fillMeshBuildInfo(MeshBuildInfo &build_info) override
Fills build_info with the necessary information to create the mesh.
Ref< IMeshBuilder > createBuilder(const CaseMeshReaderReadInfo &read_info) const override
Returns a builder to create and read the mesh whose information is specified in read_info.
bool writeMeshToFile(IMesh *mesh, const String &file_name) override
Writing the mesh to VTK.
void _writeMeshToFile(IMesh *mesh, const String &file_name, eItemKind cell_kind)
Writes the mesh in VTK format.
void build() override
Build-level construction of the service.
Mesh file reader for legacy VTK format.
void _createFaceGroup(IMesh *mesh, const String &name, Int32ConstArrayView faces_lid)
Allows creating a face group named "name" composed of faces having the IDs included in "faces_lid".
bool _readMetadata(IMesh *mesh, VtkFile &vtk_file)
Read metadata.
void _readCellVariable(IMesh *mesh, VtkFile &vtk_file, const String &name_str, Integer nb_cell)
Allows creating a cell variable from the information in the vtk file.
bool _readStructuredGrid(IPrimaryMesh *mesh, VtkFile &, bool use_internal_partition)
Allows reading a vtk file containing a STRUCTURED_GRID.
void _readNodesUnstructuredGrid(IMesh *mesh, VtkFile &vtk_file, Array< Real3 > &node_coords)
Read nodes and their coordinates.
void _readItemGroup(IMesh *mesh, VtkFile &vtk_file, const String &name_str, Integer nb_item, eItemKind ik, ConstArrayView< Int32 > local_id)
Allows creating an item group.
void _readCellsUnstructuredGrid(IMesh *mesh, VtkFile &vtk_file, Array< Int32 > &cells_nb_node, Array< ItemTypeId > &cells_type, Array< Int64 > &cells_connectivity)
Read cells and their connectivity.
void _readFacesMesh(IMesh *mesh, const String &file_name, const String &dir_name, bool use_internal_partition)
Allows reading the truc.vtkfaces.vtk file (if it exists).
bool _readData(IMesh *mesh, VtkFile &vtk_file, bool use_internal_partition, eItemKind cell_kind, Int32ConstArrayView local_id, Integer nb_node)
Allows reading supplementary data (POINT_DATA / CELL_DATA).
bool readMesh(IPrimaryMesh *mesh, const String &file_name, const String &dir_name, bool use_internal_partition)
Allows starting the reading of a vtk file.
void _readNodeGroup(IMesh *mesh, VtkFile &vtk_file, const String &name, Integer nb_item)
Allows creating a node group.
bool _readUnstructuredGrid(IPrimaryMesh *mesh, VtkFile &vtk_file, bool use_internal_partition)
Allows reading a vtk file containing an UNSTRUCTURED_GRID.
eReturnType readMeshFromFile(IPrimaryMesh *mesh, const XmlNode &mesh_node, const String &file_name, const String &dir_name, bool use_internal_partition) override
Reads a mesh from a file.
bool allowExtension(const String &str) override
Checks if the service supports files with the extension str.
List of nodes of a DOM tree.
XmlNode documentElement() const
Returns the document element.
XmlNodeList children(const String &name) const
Set of child nodes of this node having the name name.
#define ARCANE_REGISTER_SERVICE(aclass, a_service_property,...)
Macro for registering a service.
MeshVariableScalarRefT< Cell, Real > VariableCellReal
Real type quantity at cell center.
MeshVariableScalarRefT< Node, Real3 > VariableNodeReal3
Coordinate type quantity at node.
@ ReduceMax
Maximum of values.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
ArrayView< Byte > ByteArrayView
C equivalent of a 1D array of characters.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
@ ST_SubDomain
The service is used at the subdomain level.
UniqueArray< Byte > ByteUniqueArray
Dynamic 1D array of characters.
UniqueArray< Int32 > Int32UniqueArray
Dynamic 1D array of 32-bit integers.
eItemKind
Mesh entity type.
@ IK_Node
Node mesh entity.
@ IK_Cell
Cell mesh entity.
@ IK_Face
Face mesh entity.
std::int16_t Int16
Signed integer type of 16 bits.
double Real
Type representing a real number.
ConstArrayView< Byte > ByteConstArrayView
C equivalent of a 1D array of characters.
unsigned char Byte
Type of a byte.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Creates a reference on a pointer.
ArrayView< Real > RealArrayView
C equivalent of a 1D array of reals.
std::int32_t Int32
Signed integer type of 32 bits.
Real y
second component of the triplet
Real z
third component of the triplet
Real x
first component of the triplet