MED fichier
UsesCase_MEDmesh_15.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2  *
3  * COPYRIGHT (C) 1999 - 2021 EDF R&D, CEA/DEN
4  * MED is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * MED is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with MED. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 /*
19  * How to create an unstructured mesh with polyhedrons
20  *
21  * Use case 15 : a 3D unstructured mesh with 2 polyhedrons
22  */
23 
24 #include <med.h>
25 #define MESGERR 1
26 #include <med_utils.h>
27 
28 #include <string.h>
29 
30 int main (int argc, char **argv) {
31  med_idt fid;
32  const char meshname[MED_NAME_SIZE+1] = "3D Unstructured Mesh With 2 polyhedrons";
33  const med_int spacedim = 3;
34  const med_int meshdim = 3;
35  /* 12345678901234561234567890123456 */
36  const char axisname[3*MED_SNAME_SIZE+1] = "x y z ";
37  const char unitname[3*MED_SNAME_SIZE+1] = "cm cm cm ";
38 
39  const med_int nnodes = 16;
40  const med_float coordinates[3 * 16] = {
41 /* [ 1 ] */ -10.0, -10.0, +0.0,
42 /* [ 2 ] */ -10.0, -10.0, +10.,
43 /* [ 3 ] */ -10.0, +10.0, +10.,
44 /* [ 4 ] */ -10.0, +10.0, +0.0,
45 /* [ 5 ] */ +10.0, -10.0, +0.0,
46 /* [ 6 ] */ +10.0, -10.0, +10.,
47 /* [ 7 ] */ +10.0, +10.0, +10.,
48 /* [ 8 ] */ +10.0, +10.0, +0.0,
49 /* [ 9 ] */ -10.0, +0.0 , +10.0,
50 /* [ 10 ] */ -10.0, +0.0 , +0.0 ,
51 /* [ 11 ] */ +0.0 , -10.0 , +10.0,
52 /* [ 12 ] */ +0.0 , -10.0 , +0.0 ,
53 /* [ 13 ] */ +0.0 , +10.0 , +10.0,
54 /* [ 14 ] */ +10.0, +0.0 , +10.0,
55 /* [ 15 ] */ +0.0 , +10.0 , +0.0 ,
56 /* [ 16 ] */ +10.0, +0.0 , +0.0
57  };
58 
59  /*Il y a 58 numéros de noeuds dans le tableau de connextivité*/
60  const med_int connectivity[26+32] = {
61 /* - Poly 1 : */
62 /* - Face 1 : */ 1, 2 , 9 , 3 , 10,
63 /* - Face 2 : */ 1, 12 , 5 , 6 , 11, 2,
64 /* - Face 3 : */ 2, 11 , 6 , 3 , 9 ,
65 /* - Face 4 : */ 3, 6 , 5 ,
66 /* - Face 5 : */ 3, 5 , 10 ,
67 /* - Face 6 : */ 1, 10 , 5 , 12,
68 /* - Poly 2 : */
69 /* - Face 1 : */ 3, 13 , 7 , 8 , 15, 4,
70 /* - Face 2 : */ 3, 4 , 10 ,
71 /* - Face 3 : */ 4, 15 , 8 , 16 , 5, 10,
72 /* - Face 4 : */ 3, 6 , 14 , 7 , 13,
73 /* - Face 5 : */ 5, 16 , 8 , 7 , 14, 6,
74 /* - Face 6 : */ 3, 10 , 5 ,
75 /* - Face 7 : */ 3, 5 , 6
76  };
77 
78  /* Il y a deux polyèdres, le premier a 6 faces, le second 7 faces */
79  /* La face 7 du Poly 2 utilise 59-56=3 noeuds */
80  const med_int nodeindex[6+7+1] = { 1, 6, 12, 17, 20, 23,
81  27, 33, 36, 42, 47, 53, 56, 59};
82  /* Il y a un total de 13 faces */
83  /* NodeIndexSize == Nbre De Faces +1 */
84  const med_int nodeindexSize = 6+7+1;
85 
86  /* Il y a deux polyèdres, le premier a 6 faces, le second 7 faces */
87  /* Pn+1 == FaceIndex[n+1]== NodeIndexSize== Nbre De Faces +1 */
88  const med_int faceindex[3] = {1,7,14};
89  const med_int faceindexSize = 3;
90 
91 
92  /* open MED file */
93  fid = MEDfileOpen("UsesCase_MEDmesh_15.med",
95  if (fid < 0) {
96  MESSAGE("ERROR : file creation ...");
97  return -1;
98  }
99 
100  /* write a comment in the file */
101  if (MEDfileCommentWr(fid,
102  "A 3D unstructured mesh : 2 polyhedrons") < 0) {
103  MESSAGE("ERROR : write file description ...");
104  return -1;
105  }
106 
107  /* mesh creation : a 3D unstructured mesh */
108  if (MEDmeshCr(fid, meshname, spacedim, meshdim,
109  MED_UNSTRUCTURED_MESH, "A 3D mesh with 2 polyhedron",
110  "", MED_SORT_DTIT,
111  MED_CARTESIAN, axisname, unitname) < 0) {
112  MESSAGE("ERROR : mesh creation ...");
113  return -1;
114  }
115 
116  /* nodes coordinates in a cartesian axis in full interlace mode
117  (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step
118  */
119  if (MEDmeshNodeCoordinateWr(fid, meshname,
121  MED_FULL_INTERLACE, nnodes, coordinates) < 0) {
122  MESSAGE("ERROR : nodes coordinates ...");
123  return -1;
124  }
125 
126  /* cells connectiviy is defined in nodal mode */
127  if (MEDmeshPolyhedronWr(fid, meshname,
130  faceindexSize, faceindex,
131  nodeindexSize, nodeindex,
132  connectivity) < 0) {
133  MESSAGE("ERROR : polyhedron connectivity ...");
134  return -1;
135  }
136 
137  /* create family 0 : by default, all mesh entities family number is 0 */
138  if (MEDfamilyCr(fid, meshname, "", 0, 0, "") < 0) {
139  MESSAGE("ERROR : family 0 creation ...");
140  return -1;
141  }
142 
143  /* close MED file */
144  if (MEDfileClose(fid) < 0) {
145  MESSAGE("ERROR : close file ...");
146  return -1;
147  }
148 
149  return 0;
150 }
MED_CARTESIAN
Definition: med.h:258
MED_FULL_INTERLACE
Definition: med.h:96
MED_SORT_DTIT
Definition: med.h:309
MEDmeshPolyhedronWr
MEDC_EXPORT med_err MEDmeshPolyhedronWr(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_float dt, const med_entity_type entitype, const med_connectivity_mode cmode, const med_int faceindexsize, const med_int *const faceindex, const med_int nodeindexsize, const med_int *const nodeindex, const med_int *const connectivity)
Cette routine permet l'écriture dans un maillage des connectivités de polyèdres.
Definition: MEDmeshPolyhedronWr.c:47
MEDmeshCr
MEDC_EXPORT med_err MEDmeshCr(const med_idt fid, const char *const meshname, const med_int spacedim, const med_int meshdim, const med_mesh_type meshtype, const char *const description, const char *const dtunit, const med_sorting_type sortingtype, const med_axis_type axistype, const char *const axisname, const char *const axisunit)
Cette routine permet de créer un maillage dans un fichier.
Definition: MEDmeshCr.c:45
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition: MEDfileOpen.c:42
MED_SNAME_SIZE
#define MED_SNAME_SIZE
Definition: med.h:82
MED_NODAL
Definition: med.h:255
med_idt
hid_t med_idt
Definition: med.h:331
MED_CELL
Definition: med.h:143
MEDfileCommentWr
MEDC_EXPORT med_err MEDfileCommentWr(const med_idt fid, const char *const comment)
Ecriture d'un descripteur dans un fichier MED.
Definition: MEDfileCommentWr.c:34
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:324
med_int
int med_int
Definition: med.h:342
MEDfamilyCr
MEDC_EXPORT med_err MEDfamilyCr(const med_idt fid, const char *const meshname, const char *const familyname, const med_int familynumber, const med_int ngroup, const char *const groupname)
Cette routine permet la création d'une famille portant sur les entités d'un maillage.
Definition: MEDfamilyCr.c:40
med.h
med_float
double med_float
Definition: med.h:336
MED_NO_DT
#define MED_NO_DT
Definition: med.h:320
MEDmeshNodeCoordinateWr
MEDC_EXPORT med_err MEDmeshNodeCoordinateWr(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_float dt, const med_switch_mode switchmode, const med_int nentity, const med_float *const coordinates)
Cette routine permet d'écrire dans un maillage le tableau des coordonnées des noeuds,...
Definition: MEDmeshNodeCoordinateWr.c:45
MED_ACC_CREAT
Definition: med.h:123
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:81
MED_UNSTRUCTURED_MESH
Definition: med.h:131
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MED_UNDEF_DT
#define MED_UNDEF_DT
Definition: med.h:322
MED_NO_IT
#define MED_NO_IT
Definition: med.h:321
main
int main(int argc, char **argv)
Definition: UsesCase_MEDmesh_15.c:30
med_utils.h