14#include "arcane/utils/ITraceMng.h"
16#include "arcane/IMeshReader.h"
17#include "arcane/BasicService.h"
18#include "arcane/ServiceFactory.h"
19#include "arcane/IPrimaryMesh.h"
20#include "arcane/ICaseMeshReader.h"
21#include "arcane/IMeshBuilder.h"
22#include "arcane/IParallelMng.h"
23#include "arcane/MeshPartInfo.h"
55 struct MEDToArcaneItemInfo
59 MEDToArcaneItemInfo(
int dimension,
int nb_node, med_int med_type,
61 : m_dimension(dimension)
63 , m_med_type(med_type)
64 , m_arcane_type(arcane_type)
65 , m_indirection(indirection)
70 int dimension()
const {
return m_dimension; }
71 int nbNode()
const {
return m_nb_node; }
72 med_int medType()
const {
return m_med_type; }
73 Integer arcaneType()
const {
return m_arcane_type; }
74 const Int32* indirection()
const {
return m_indirection; }
82 const Int32* m_indirection;
90 _initMEDToArcaneTypes();
107 AutoCloseMED(med_idt
id)
124 void _initMEDToArcaneTypes();
125 void _addTypeInfo(
int dimension,
int nb_node, med_int med_type,
Integer arcane_type)
128 m_med_to_arcane_types.add(t);
130 void _addTypeInfo(
int dimension,
int nb_node, med_int med_type,
Integer arcane_type,
131 const Int32* indirection)
133 MEDToArcaneItemInfo t(dimension, nb_node, med_type, arcane_type, indirection);
134 m_med_to_arcane_types.
add(t);
136 void _readAndAllocateCells(IPrimaryMesh* mesh, Int32 mesh_dimension, med_idt fid,
const char* meshname);
139 _readNodesCoordinates(IPrimaryMesh* mesh, Int64 nb_node, Int32 spacedim,
140 med_idt fid,
const char* meshname);
148 const Int32 Hexaedron8_indirection[] = { 1, 0, 3, 2, 5, 4, 7, 6 };
149 const Int32 Hexaedron20_indirection[] = { 1, 8, 10, 3, 9, 2, 0, 11, 5, 14, 18, 7, 6, 4, 16, 15, 13, 12, 17, 19 };
150 const Int32 Pyramid5_indirection[] = { 1, 0, 3, 2, 4 };
151 const Int32 Quad4_indirection[] = { 1, 0, 3, 2 };
152 const Int32 Triangle3_indirection[] = { 1, 0, 2 };
154 const Int32 Tetraedron4_indirection[] = { 1, 0, 2, 3 };
158_initMEDToArcaneTypes()
160 m_med_to_arcane_types.clear();
165 _addTypeInfo(1, 2, MED_SEG2, IT_Line2);
166 _addTypeInfo(1, 3, MED_SEG3, IT_Line3);
167 _addTypeInfo(1, 4, MED_SEG4, IT_NullType);
170 _addTypeInfo(2, 3, MED_TRIA3, IT_Triangle3, Triangle3_indirection);
171 _addTypeInfo(2, 4, MED_QUAD4, IT_Quad4, Quad4_indirection);
172 _addTypeInfo(2, 6, MED_TRIA6, IT_NullType);
173 _addTypeInfo(2, 7, MED_TRIA7, IT_NullType);
174 _addTypeInfo(2, 8, MED_QUAD8, IT_Quad8);
175 _addTypeInfo(2, 9, MED_QUAD9, IT_NullType);
178 _addTypeInfo(3, 4, MED_TETRA4, IT_Tetraedron4);
179 _addTypeInfo(3, 5, MED_PYRA5, IT_Pyramid5, Pyramid5_indirection);
180 _addTypeInfo(3, 6, MED_PENTA6, IT_Pentaedron6);
181 _addTypeInfo(3, 8, MED_HEXA8, IT_Hexaedron8, Hexaedron8_indirection);
182 _addTypeInfo(3, 10, MED_TETRA10, IT_Tetraedron10);
183 _addTypeInfo(3, 12, MED_OCTA12, IT_Octaedron12);
184 _addTypeInfo(3, 13, MED_PYRA13, IT_NullType);
185 _addTypeInfo(3, 15, MED_PENTA15, IT_NullType);
186 _addTypeInfo(3, 18, MED_PENTA18, IT_NullType);
187 _addTypeInfo(3, 20, MED_HEXA20, IT_Hexaedron20, Hexaedron20_indirection);
188 _addTypeInfo(3, 27, MED_HEXA27, IT_NullType);
196 _addTypeInfo(2, 0, MED_POLYGON, IT_NullType);
197 _addTypeInfo(2, 0, MED_POLYGON2, IT_NullType);
198 _addTypeInfo(3, 0, MED_POLYHEDRON, IT_NullType);
212 info() <<
"Trying to read MED File name=" << file_name;
213 return _readMesh(mesh, file_name);
222 const med_idt fid = MEDfileOpen(filename.localstr(), MED_ACC_RDONLY);
224 MESSAGE(
"ERROR: can not open MED file ");
225 error() <<
"ERROR: can not open MED file '" << filename <<
"'";
231 int nb_mesh = MEDnMesh(fid);
233 error() <<
"Error reading number of meshes";
236 info() <<
"MED: nb_mesh=" << nb_mesh;
238 error() <<
"No mesh is present";
246 int nb_axis = MEDmeshnAxis(fid, mesh_index);
248 error() <<
"Can not read number of axis (MEDmeshnAxis)";
251 info() <<
"MED: nb_axis=" << nb_axis;
253 UniqueArray<char> axisname(MED_SNAME_SIZE * nb_axis + 1,
'\0');
254 UniqueArray<char> unitname(MED_SNAME_SIZE * nb_axis + 1,
'\0');
256 char meshname[MED_NAME_SIZE + 1];
258 char meshdescription[MED_COMMENT_SIZE + 1];
259 meshdescription[0] =
'\0';
260 char dtunit[MED_SNAME_SIZE + 1];
262 med_int spacedim = 0;
264 med_mesh_type meshtype = MED_UNDEF_MESH_TYPE;
265 med_sorting_type sortingtype = MED_SORT_UNDEF;
267 med_axis_type axistype = MED_UNDEF_AXIS_TYPE;
269 err = MEDmeshInfo(fid, mesh_index, meshname, &spacedim, &meshdim, &meshtype, meshdescription,
270 dtunit, &sortingtype, &nstep, &axistype, axisname.data(), unitname.data());
272 error() <<
"Can not read mesh info (MEDmeshInfo) r=" << err;
275 if (meshtype != MED_UNSTRUCTURED_MESH) {
276 error() <<
"Arcane handle only MED unstructured mesh (MED_UNSTRUCTURED_MESH) type=" << meshtype;
279 Integer mesh_dimension = meshdim;
280 if (mesh_dimension != 2 && mesh_dimension != 3)
281 ARCANE_FATAL(
"MED reader handles only 2D or 3D meshes");
283 info() <<
"MED: name=" << meshname;
284 info() <<
"MED: description=" << meshdescription;
285 info() <<
"MED: spacedim=" << spacedim;
286 info() <<
"MED: meshdim=" << meshdim;
287 info() <<
"MED: dtunit=" << dtunit;
288 info() <<
"MED: meshtype=" << meshtype;
289 info() <<
"MED: sortingtype=" << sortingtype;
290 info() <<
"MED: axistype=" << axistype;
291 info() <<
"MED: nstep=" << nstep;
296 med_bool coordinatechangement;
297 med_bool geotransformation;
300 med_int med_nb_node = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NO_GEOTYPE,
301 MED_COORDINATE, MED_NO_CMODE, &coordinatechangement,
303 if (med_nb_node < 0) {
304 error() <<
"Can not read number of nodes (MEDmeshnEntity) err=" << med_nb_node;
307 nb_node = med_nb_node;
309 info() <<
"MED: nb_node=" << nb_node;
311 mesh->setDimension(mesh_dimension);
313 IParallelMng* pm = mesh->parallelMng();
314 bool is_parallel = pm->isParallel();
315 Int32 rank = mesh->meshPartInfo().partRank();
317 bool is_read_items = !(is_parallel && rank != 0);
319 _readAndAllocateCells(mesh, mesh_dimension, fid, meshname);
321 return _readNodesCoordinates(mesh, nb_node, spacedim, fid, meshname);
325 mesh->allocateCells(0, {},
true);
336 Int64 cell_unique_id = 0;
338 for (
const auto& iinfo : m_med_to_arcane_types) {
339 Integer item_dimension = iinfo.dimension();
341 if (item_dimension != mesh_dimension)
343 UniqueArray<med_int> med_connectivity;
344 Int32 nb_item = _readItems(fid, meshname, iinfo, med_connectivity);
347 Integer arcane_type = iinfo.arcaneType();
348 Integer nb_item_node = iinfo.nbNode();
349 if (arcane_type == IT_NullType) {
351 ARCANE_FATAL(
"MED type '{0}' is not supported by Arcane", iinfo.medType());
353 Int64 cells_infos_index = 0;
354 Int64 med_connectivity_index = 0;
355 UniqueArray<Int64> cells_infos((2 + nb_item_node) * nb_item);
356 info() <<
"CELL_INFOS size=" << cells_infos.size() <<
" nb_item=" << nb_item
357 <<
" type=" << arcane_type;
358 const Int32* indirection = iinfo.indirection();
359 for (
Int32 i = 0; i < nb_item; ++i) {
360 cells_infos[cells_infos_index] = arcane_type;
362 cells_infos[cells_infos_index] = cell_unique_id;
367 Span<Int64> cinfo_span(cells_infos.span().subspan(cells_infos_index, nb_item_node));
368 Span<med_int> med_cinfo_span(med_connectivity.span().subspan(med_connectivity_index, nb_item_node));
370 for (
Integer k = 0; k < nb_item_node; ++k) {
371 cinfo_span[k] = med_cinfo_span[indirection[k]] - 1;
375 for (
Integer k = 0; k < nb_item_node; ++k)
376 cinfo_span[k] = med_cinfo_span[k] - 1;
378 med_connectivity_index += nb_item_node;
379 cells_infos_index += nb_item_node;
382 mesh->allocateCells(nb_item, cells_infos,
false);
391 med_idt fid,
const char* meshname)
393 const bool do_verbose =
false;
395 UniqueArray<Real3> nodes_coordinates(nb_node);
397 UniqueArray<med_float> coordinates(nb_node * spacedim);
398 int err = MEDmeshNodeCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE,
401 error() <<
"Can not read nodes coordinates err=" << err;
406 for (
Int64 i = 0; i < nb_node; ++i) {
407 Real3 xyz(coordinates[i * 3], coordinates[(i * 3) + 1], coordinates[(i * 3) + 2]);
409 info() <<
"I=" << i <<
" XYZ=" << xyz;
410 nodes_coordinates[i] = xyz;
413 else if (spacedim == 2) {
414 for (
Int64 i = 0; i < nb_node; ++i) {
415 Real3 xyz(coordinates[i * 2], coordinates[(i * 2) + 1], 0.0);
417 info() <<
"I=" << i <<
" XYZ=" << xyz;
418 nodes_coordinates[i] = xyz;
422 ARCANE_THROW(NotImplementedException,
"spacedim!=2 && spacedim!=3");
430 nodes_coord_var[inode] = nodes_coordinates[node.uniqueId()];
440_readItems(med_idt fid,
const char* meshname,
const MEDToArcaneItemInfo& iinfo,
443 int med_item_type = iinfo.medType();
444 med_bool coordinatechangement;
445 med_bool geotransformation;
446 med_int nb_med_item = ::MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL, med_item_type,
447 MED_CONNECTIVITY, MED_NODAL, &coordinatechangement,
449 if (nb_med_item < 0) {
450 ARCANE_FATAL(
"Can not read MED med_item_type '{0}' error={1}", med_item_type, nb_med_item);
452 info() <<
"MED: type=" << med_item_type <<
" nb_item=" << nb_med_item;
453 if (nb_med_item == 0)
455 Int64 nb_node = iinfo.nbNode();
458 ARCANE_THROW(NotImplementedException,
"Reading items with MED type '{0}'", med_item_type);
460 connectivity.resize(nb_node * nb_med_item);
461 int err = MEDmeshElementConnectivityRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL,
462 med_item_type, MED_NODAL, MED_FULL_INTERLACE,
463 connectivity.data());
465 ARCANE_FATAL(
"Can not read connectivity MED med_item_type '{0}' error={1}",
468 info() <<
"CON: " << connectivity;
475class MEDMeshReaderService
496 bool use_internal_partition)
override
498 ARCANE_UNUSED(mesh_element);
499 ARCANE_UNUSED(dir_name);
500 ARCANE_UNUSED(use_internal_partition);
502 return reader.readMesh(
mesh, file_name);
516class MEDCaseMeshReader
529 , m_read_info(read_info)
536 ARCANE_UNUSED(build_info);
541 String fname = m_read_info.fileName();
542 m_trace_mng->info() <<
"MED Reader (ICaseMeshReader) file_name=" << fname;
565 if (read_info.format() ==
"med")
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
#define ARCANE_SERVICE_INTERFACE(ainterface)
Macro pour déclarer une interface lors de l'enregistrement d'un service.
Classe de base d'un service.
AbstractService(const ServiceBuildInfo &)
Constructeur à partir d'un ServiceBuildInfo.
Tableau d'items de types quelconques.
void add(ConstReferenceType val)
Ajoute l'élément val à la fin du tableau.
Informations nécessaires pour la lecture d'un fichier de maillage.
Interface du service de lecture du maillage à partir du jeu de données.
Interface d'un service de création/lecture du maillage.
Interface du service gérant la lecture d'un maillage.
eReturnType
Types des codes de retour d'une lecture ou écriture.
@ RTError
Erreur lors de l'opération.
@ RTOk
Opération effectuée avec succès.
Interface du gestionnaire de traces.
void allocateMeshItems(IPrimaryMesh *pm) override
Alloue les entités du maillage géré par ce service.
void fillMeshBuildInfo(MeshBuildInfo &build_info) override
Remplit build_info avec les informations nécessaires pour créer le maillage.
Ref< IMeshBuilder > createBuilder(const CaseMeshReaderReadInfo &read_info) const override
Retourne un builder pour créer et lire le maillage dont les informations sont spécifiées dans read_in...
bool allowExtension(const String &str) override
Vérifie si le service supporte les fichiers avec l'extension str.
void build() override
Construction de niveau build du service.
eReturnType readMeshFromFile(IPrimaryMesh *mesh, const XmlNode &mesh_element, const String &file_name, const String &dir_name, bool use_internal_partition) override
Lit un maillage à partir d'un fichier.
Lecteur de maillages au format MED.
Paramètres nécessaires à la construction d'un maillage.
Référence à une instance.
Structure contenant les informations pour créer un service.
Chaîne de caractères unicode.
TraceAccessor(ITraceMng *m)
Construit un accesseur via le gestionnaire de trace m.
TraceMessage info() const
Flot pour un message d'information.
TraceMessage error() const
Flot pour un message d'erreur.
ITraceMng * traceMng() const
Gestionnaire de trace.
Vecteur 1D de données avec sémantique par valeur (style STL).
#define ARCANE_REGISTER_SERVICE(aclass, a_service_property,...)
Macro pour enregistrer un service.
MeshVariableScalarRefT< Node, Real3 > VariableNodeReal3
Grandeur au noeud de type coordonnées.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
@ ST_SubDomain
Le service s'utilise au niveau du sous-domaine.
auto makeRef(InstanceType *t) -> Ref< InstanceType >
Créé une référence sur un pointeur.
std::int32_t Int32
Type entier signé sur 32 bits.
Informations pour passer des types MED aux types Arcane pour les entités.