MED fichier

UsesCase_MEDmesh_13.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 * Use case 13 : a 2D unstructured mesh with 10 nodes and 2 polygons
20 * poly1 : 1,4,7,9,6,3
21 * poly2 : 2,5,8,10,7,4
22 * 9 10
23 *
24 * 6 7 8
25 *
26 * 3 4 5
27 *
28 * 1 2
29 *
30 */
31
32 #include <med.h>
33 #define MESGERR 1
34 #include <med_utils.h>
35
36 #include <string.h>
37
38 int main (int argc, char **argv) {
39 med_idt fid;
40 const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh";
41 const med_int spacedim = 2;
42 const med_int meshdim = 2;
43 /* 12345678901234561234567890123456 */
44 const char axisname[2*MED_SNAME_SIZE+1] = "x y ";
45 const char unitname[2*MED_SNAME_SIZE+1] = "cm cm ";
46 /* Dix noeuds dont deux communs aux deux polygones */
47 const med_float coordinates[2*10] = { 0.5, 0.,
48 1.5, 0.,
49 0., 0.5,
50 1., 0.5,
51 2., 0.5,
52 0., 1.,
53 1., 1.,
54 2., 1.,
55 0.5, 2.,
56 1.5, 2. };
57 const med_int nnodes = 10;
58 const med_int indexsize = 3;
59 const med_int index[3] = {1,7,13};
60 /* connectivity : 2 hexagons */
61 const med_int connectivity[12] = {1,4,7,9,6,3,
62 2,5,8,10,7,4};
63 int ret=-1;
64
65 /* open MED file */
66 fid = MEDfileOpen("UsesCase_MEDmesh_13.med", MED_ACC_CREAT);
67 if (fid < 0) {
68 MESSAGE("ERROR : file creation ...");
69 goto ERROR;
70 }
71
72 /* write a comment in the file */
73 if (MEDfileCommentWr(fid, "A 2D unstructured mesh : 12, 12 polygons") < 0)
74 { MESSAGE("ERROR : write file description ...");
75 goto ERROR;
76 }
77
78 /* mesh creation : a 2D unstructured mesh */
79 if (MEDmeshCr(fid, meshname, spacedim, meshdim,
80 MED_UNSTRUCTURED_MESH, "A 2D mesh with 2 polygons",
81 "", MED_SORT_DTIT, MED_CARTESIAN, axisname, unitname) < 0)
82 { MESSAGE("ERROR : mesh creation ...");
83 goto ERROR;
84 }
85
86 /* nodes coordinates in a cartesian axis in full interlace mode
87 (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step
88 */
89 if (MEDmeshNodeCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
90 MED_FULL_INTERLACE, nnodes, coordinates) < 0)
91 { MESSAGE("ERROR : nodes coordinates ...");
92 goto ERROR;
93 }
94
95 /* cells connectiviy is defined in nodal mode */
96 /* 2 polygons */
97 if (MEDmeshPolygonWr(fid, meshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
98 MED_CELL, MED_NODAL, indexsize, index, connectivity) < 0)
99 { MESSAGE("ERROR : polygon connectivity ...");
100 goto ERROR;
101 }
102
103
104 /* create family 0 : by default, all mesh entities family number is 0 */
105 if (MEDfamilyCr(fid, meshname, MED_NO_NAME, 0, 0, MED_NO_GROUP) < 0)
106 { MESSAGE("ERROR : family 0 creation ...");
107 goto ERROR;
108 }
109
110 ret=0;
111 ERROR:
112
113 /* close MED file */
114 if (MEDfileClose(fid) < 0) {
115 MESSAGE("ERROR : close file ...");
116 ret=-1;
117 }
118
119 return ret;
120 }
MED_CARTESIAN
Definition: med.h:258
MED_NO_GROUP
#define MED_NO_GROUP
Definition: med.h:289
MED_FULL_INTERLACE
Definition: med.h:96
MED_SORT_DTIT
Definition: med.h:309
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
MEDmeshPolygonWr
MEDC_EXPORT med_err MEDmeshPolygonWr(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 indexsize, const med_int *const polyindex, const med_int *const connectivity)
Cette routine permet l'écriture des connectivités de polygones.
Definition: MEDmeshPolygonWr.c:45
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
main
int main(int argc, char **argv)
Definition: UsesCase_MEDmesh_13.c:38
MED_NO_IT
#define MED_NO_IT
Definition: med.h:321
med_utils.h
MED_NO_NAME
#define MED_NO_NAME
Definition: med.h:268