14#include "arcane/utils/ArcanePrecomp.h"
16#include "arcane/utils/Iostream.h"
17#include "arcane/utils/StdHeader.h"
18#include "arcane/utils/HashTableMap.h"
19#include "arcane/utils/ValueConvert.h"
20#include "arcane/utils/ScopedPtr.h"
21#include "arcane/utils/ITraceMng.h"
22#include "arcane/utils/String.h"
23#include "arcane/utils/IOException.h"
24#include "arcane/utils/Collection.h"
25#include "arcane/utils/Enumerator.h"
27#include "arcane/utils/Real3.h"
29#include "arcane/core/FactoryService.h"
30#include "arcane/core/IMeshReader.h"
31#include "arcane/core/ISubDomain.h"
32#include "arcane/core/IMeshSubMeshTransition.h"
33#include "arcane/core/IItemFamily.h"
34#include "arcane/core/Item.h"
36#include "arcane/core/VariableTypes.h"
37#include "arcane/core/IVariableAccessor.h"
38#include "arcane/core/IParallelMng.h"
39#include "arcane/core/IIOMng.h"
40#include "arcane/core/IMeshUtilities.h"
41#include "arcane/core/IMeshWriter.h"
42#include "arcane/core/BasicService.h"
43#include "arcane/core/XmlNode.h"
70class VoronoiMeshIOService
78 ~VoronoiMeshIOService();
94 const String& dir_name,
bool use_internal_partition);
96 virtual bool hasCutInfos()
const {
return false; }
97 virtual ConstArrayView<Integer> communicatingSubDomains()
const {
return ConstArrayView<Integer>(); }
101 bool _readMesh(IPrimaryMesh* mesh,
const String& file_name,
const String& dir_name,
bool use_internal_partition);
102 bool _readHybridGrid(IPrimaryMesh* mesh, VoronoiFile& voronoi_file,
bool use_internal_partition);
103 void _readCellVariable(IMesh* mesh, VoronoiFile& voronoi_file,
const String& name_str,
Integer nb_cell);
104 void _readItemGroup(IMesh* mesh, VoronoiFile& voronoi_file,
const String& name_str,
Integer nb_item,
105 eItemKind ik, ConstArrayView<Integer> local_ids);
106 void _createFaceGroup(IMesh* mesh,
const String& name, ConstArrayView<Integer> faces_lid);
107 bool _readData(IMesh* mesh, VoronoiFile& voronoi_file,
bool use_internal_partition,
eItemKind cell_kind,
108 ConstArrayView<Integer> local_ids);
111 Array<Integer>& cells_nb_node,
112 Array<Integer>& cells_type,
113 Array<Int64>& cells_connectivity,
115 void _readFacesMesh(IMesh* mesh,
const String& file_name,
116 const String& dir_name,
bool use_internal_partition);
131 static const int BUFSIZE = 10000;
135 VoronoiFile(std::istream* stream)
138 const char* getNextLine();
144 return m_stream->eof();
149 std::istream* m_stream;
156const char* VoronoiFile::
159 while (m_stream->good()) {
160 m_stream->getline(m_buf,
sizeof(m_buf) - 1);
163 bool is_comment =
true;
164 if (m_buf[0] ==
'\n' || m_buf[0] ==
'\r')
167 for (
int i = 0; i < BUFSIZE && m_buf[i] !=
'\0'; ++i) {
168 if (!isspace(m_buf[i])) {
169 is_comment = (m_buf[i] ==
'#');
176 for (
int i = 0; i < BUFSIZE && m_buf[i] !=
'\0'; ++i) {
178 if (m_buf[i] ==
'\n' || m_buf[i] ==
'\r') {
186 throw IOException(
"VoronoiFile::getNexLine()",
"Unexpected EndOfFile");
196 (*m_stream) >> ws >> v;
197 if (m_stream->good())
199 throw IOException(
"VoronoiFile::getReal()",
"Bad Real");
209 (*m_stream) >> ws >> v;
210 if (m_stream->good())
212 throw IOException(
"VoronoiFile::getInteger()",
"Bad Integer");
223VoronoiMeshIOService::
232VoronoiMeshIOService::
233~VoronoiMeshIOService()
236 for (
Integer i = 0; i < size; ++i) {
251 bool use_internal_partition)
253 ARCANE_UNUSED(mesh_node);
254 ARCANE_UNUSED(use_internal_partition);
256 bool ret = _readMesh(
mesh, filename, dir_name, use_internal_partition);
266bool VoronoiMeshIOService::
268 bool use_internal_partition)
270 ARCANE_UNUSED(dir_name);
272 std::ifstream ifile(file_name.
localstr());
274 error() <<
"Unable to read file '" << file_name <<
"'";
277 VoronoiFile voronoi_file(&ifile);
284 ret = _readHybridGrid(mesh, voronoi_file, use_internal_partition);
299 const char* func_name =
"VoronoiMeshIOService::_readNodesHybridGrid()";
300 const char* buf = voronoi_file.getNextLine();
301 std::istringstream iline(buf);
302 std::string points_str;
303 std::string data_type_str;
305 iline >> ws >> nb_node;
307 throw IOException(func_name,
"Syntax error while reading number of nodes");
309 String msg =
String(
"Invalid number of nodes: n=") + nb_node;
313 info() <<
" Info: " << nb_node;
316 node_coords.
resize(nb_node);
318 for (
Integer i = 0; i < nb_node; ++i) {
319 Real nx = voronoi_file.getReal();
320 Real ny = voronoi_file.getReal();
321 Real nz = voronoi_file.getReal();
322 node_coords[i] =
Real3(nx, ny, nz);
344 const char* func_name =
"VoronoiMeshIOService::_readCellsHybridGrid()";
345 const char* buf = voronoi_file.getNextLine();
346 std::istringstream iline(buf);
347 std::string cells_str;
350 iline >> ws >> nb_cell >> ws >> nb_cell_node;
352 throw IOException(func_name,
"Syntax error while reading cells");
353 if (nb_cell < 0 || nb_cell_node < 0) {
354 throw IOException(func_name, String::format(
"Invalid dimensions: nb_cell={0} nb_cell_node={1}", nb_cell, nb_cell_node));
360 bool is_mesh_2d =
true;
362 cells_nb_node.
resize(nb_cell);
363 cells_type.
resize(nb_cell);
364 cells_connectivity.
resize(nb_cell_node);
366 Integer connectivity_index = 0;
367 for (
Integer i = 0; i < nb_cell; ++i) {
368 const Integer user_cell_type = voronoi_file.getInteger();
370 cells_type[i] = internal_cell_type;
372 fatal() <<
"Bad item type " << user_cell_type;
373 voronoi_file.getInteger();
378 cells_nb_node[i] = n;
379 for (
Integer j = 0; j < n; ++j) {
380 const Integer node_id = voronoi_file.getInteger();
381 cells_connectivity[connectivity_index] = node_id;
382 ++connectivity_index;
393bool VoronoiMeshIOService::
406 bool need_read =
true;
408 if (use_internal_partition)
409 need_read = (sid == 0);
421 nb_cell = cells_nb_node.
size();
422 nb_cell_node = cells_connectivity.
size();
423 cells_local_id.
resize(nb_cell);
430 cells_infos.
resize(nb_cell * 2 + nb_cell_node);
433 Integer connectivity_index = 0;
434 for (
Integer i = 0; i < nb_cell; ++i) {
435 Integer current_cell_nb_node = cells_nb_node[i];
438 cells_local_id[i] = i;
440 cells_infos[cells_infos_index] = cells_type[i];
443 cells_infos[cells_infos_index] = cell_unique_id;
446 for (
Integer z = 0; z < current_cell_nb_node; ++z) {
447 cells_infos[cells_infos_index + z] = cells_connectivity[connectivity_index + z];
449 cells_infos_index += current_cell_nb_node;
450 connectivity_index += current_cell_nb_node;
456 mesh->setDimension(dimension);
457 mesh->allocateCells(nb_cell, cells_infos,
false);
465 Int32 node_uid = node.uniqueId().asInt32();
466 nodes_coord_var[inode] = node_coords[node_uid];
471 bool r = _readData(mesh, voronoi_file, use_internal_partition,
IK_Cell, cells_local_id);
481bool VoronoiMeshIOService::
485 ARCANE_UNUSED(use_internal_partition);
486 ARCANE_UNUSED(local_ids);
490 Integer sid = subDomain()->subDomainId();
491 Integer nb_cell_kind = mesh->nbItem(cell_kind);
493 _readCellVariable(mesh, voronoi_file,
"CellCenter", nb_cell_kind);
506void VoronoiMeshIOService::
511 info() <<
"Reading values for variable: " << var_name <<
" n=" << nb_cell;
515 for (
Integer i = 0; i < nb_cell; ++i) {
516 cx = voronoi_file.getReal();
517 cy = voronoi_file.getReal();
518 cz = voronoi_file.getReal();
519 values[i] = Real3(cx, cy, cz);
521 info() <<
"Variable build done: " << voronoi_file.isEnd();
527void VoronoiMeshIOService::
531 IItemFamily* item_family = mesh->itemFamily(ik);
532 info() <<
"Reading group info for group: " << name;
535 for (
Integer i = 0; i < nb_item; ++i) {
536 Integer v = voronoi_file.getInteger();
538 ids.add(local_ids[i]);
540 info() <<
"Building group: " << name <<
" nb_element=" << ids.size();
542 item_family->createGroup(name, ids);
#define ARCANE_REGISTER_SUB_DOMAIN_FACTORY(aclass, ainterface, aname)
Registers a factory service for the class aclass.
Integer size() const
Number of elements in the vector.
Base class for 1D data vectors.
void resize(Int64 s)
Changes the number of elements in the array to s.
Base class of a service linked to a subdomain.
Constant view of an array of type T.
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.
Exception when an input/output error is detected.
virtual Int32 subDomainId() const =0
Subdomain ID associated with this manager.
Info on a mesh entity type.
Integer nbLocalEdge() const
Number of edges of the entity.
Integer nbLocalNode() const
Number of nodes of the entity.
Integer nbLocalFace() const
Number of faces of the entity.
Mesh entity type manager.
static Integer nbBasicItemType()
number of available types
ItemTypeInfo * typeFromId(Integer id) const
Type corresponding to the number id.
static Integer nbBuiltInItemType()
number of built-in types (excluding additional types)
Class managing a 3-dimensional real vector.
Structure containing the information to create a service.
Unicode character string.
const char * localstr() const
Returns the conversion of the instance into UTF-8 encoding.
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.
1D data vector with value semantics (STL style).
Reader for IFP internal Voronoi mesh files.
virtual void build()
Build-level construction of the service.
virtual eReturnType readMeshFromFile(IPrimaryMesh *mesh, const XmlNode &mesh_node, const String &file_name, const String &dir_name, bool use_internal_partition)
UniqueArray< VariableCellReal3 * > m_variables
Table of variables created locally by reading the mesh.
void _readCellsHybridGrid(IMesh *mesh, VoronoiFile &voronoi_file, Array< Integer > &cells_nb_node, Array< Integer > &cells_type, Array< Int64 > &cells_connectivity, Integer &mesh_dimension)
Reading of cells and their connectivity.
void _readNodesHybridGrid(IMesh *mesh, VoronoiFile &voronoi_file, Array< Real3 > &node_coords)
Reading of nodes and their coordinates.
virtual bool allowExtension(const String &str)
Checks if the service supports files with the extension str.
MeshVariableScalarRefT< Cell, Real3 > VariableCellReal3
Coordinate 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< Real3 > Real3ArrayView
C equivalent of a 1D array of Real3.
Int32 Integer
Type representing an integer.
eItemKind
Mesh entity type.
@ IK_Cell
Cell mesh entity.
double Real
Type representing a real number.
UniqueArray< Integer > IntegerUniqueArray
Dynamic 1D array of integers.
std::int32_t Int32
Signed integer type of 32 bits.