MED fichier: Fichier source de UsesCase_MEDmesh_4.c

MED fichier

- Documentation MED
- Guides d'utilisation
- Guides de référence

UsesCase_MEDmesh_4.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2019 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 /*
20 * How to create a structured mesh
21 *
22 * Use case 4 : write a 2D structured mesh (5x3 cartesian grid)
23 */
24
25 #include <med.h>
26 #define MESGERR 1
27 #include <med_utils.h>
28
29 #include <string.h>
30
31 int main (int argc, char **argv) {
32 med_idt fid;
33 const char meshname[MED_NAME_SIZE+1] = "2D structured mesh";
34 const med_int spacedim = 2;
35 const med_int meshdim = 2;
36 const char axisname[2*MED_SNAME_SIZE+1] = "x y ";
37 const char unitname[2*MED_SNAME_SIZE+1] = "cm cm ";
38 med_int axis, size ;
39 const med_float cooXaxis[5] = {1.,2.,3.,4.,5.};
40 const med_float cooYaxis[3] = {1.,2.,3.};
41 const med_int nquad4 = 8;
42 /* 12345678901234561234567890123456123456789012345612345678901234561234567890123456123456789012345612345678901234561234567890123456 */
43 const char cellsnames[8*MED_SNAME_SIZE+1] = "CELL_1 CELL_2 CELL_3 CELL_4 CELL_5 CELL_6 CELL_7 CELL_8 ";
44 const char familyname [MED_NAME_SIZE+1] = "CART_GRID_QUAD_FAMILY";
45 const char groupname [MED_LNAME_SIZE+1] = "CART_GRID_GROUP";
46 const med_int familynumbers[8] = { -1, -1, -1, -1, -1, -1, -1, -1 };
47 int ret=-1;
48
49 /* MED file creation */
50 fid = MEDfileOpen("UsesCase_MEDmesh_4.med",MED_ACC_CREAT);
51 if (fid < 0) {
52 MESSAGE("ERROR : file creation ...");
53 goto ERROR;
54 }
55
56 /* create the structured mesh in the MED file */
57 if (MEDmeshCr(fid, meshname, spacedim, meshdim, MED_STRUCTURED_MESH,
58 "A 2D structured mesh","",MED_SORT_DTIT,
59 MED_CARTESIAN, axisname, unitname) < 0) {
60 MESSAGE("ERROR : mesh creation ...");
61 goto ERROR;
62 }
63
64 /* specify the grid type : MED_CARTESIAN_GRID */
65 if (MEDmeshGridTypeWr(fid,meshname, MED_CARTESIAN_GRID) < 0) {
66 MESSAGE("ERROR : write grid type ...");
67 goto ERROR;
68 }
69
70 /* write axis "X" and "Y" coordinates */
71 axis = 1;
72 size = 5;
73 if (MEDmeshGridIndexCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT,0.0,
74 axis, size, cooXaxis) < 0) {
75 MESSAGE("ERROR : write of axis X coordinates ...");
76 goto ERROR;
77 }
78 axis++;
79 size = 3;
80 if (MEDmeshGridIndexCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT,0.0,
81 axis, size, cooYaxis) < 0) {
82 MESSAGE("ERROR : write of axis Y coordinates ...");
83 goto ERROR;
84 }
85
86 /* optionnal : names for nodes or elements */
87 /* In this case, a name is given to the cells of the mesh */
88 if (MEDmeshEntityNameWr(fid, meshname, MED_NO_DT, MED_NO_IT,
89 MED_CELL, MED_QUAD4, nquad4, cellsnames) < 0) {
90 MESSAGE("ERROR : cells names ...");
91 goto ERROR;
92 }
93
94 /* We have to create family 0 : by default, all mesh entities family number is 0 */
95 if (MEDfamilyCr(fid, meshname, MED_NO_NAME, 0, 0, MED_NO_GROUP) < 0) {
96 MESSAGE("ERROR : family 0 creation ...");
97 goto ERROR;
98 }
99
100 /* We decide to create a family for boundary quad4 :
101 by convention a nodes family number is > 0 and an element family number is < 0 */
102 if (MEDfamilyCr(fid, meshname,familyname, 1, -1, groupname) < 0) {
103 MESSAGE("ERROR : family creation ...");
104 goto ERROR;
105 }
106
107 /* Then we write family number for quad4 */
108 if (MEDmeshEntityFamilyNumberWr(fid, meshname, MED_NO_DT, MED_NO_IT,
109 MED_CELL, MED_QUAD4, nquad4, familynumbers) < 0) {
110 MESSAGE("ERROR : nodes family numbers ...");
111 goto ERROR;
112 }
113
114 ret = 0;
115 ERROR:
116
117 /* close MED file */
118 if (MEDfileClose(fid) < 0) {
119 MESSAGE("ERROR : close file ...");
120 ret = -1;
121 }
122
123 return ret;
124 }
125
MED_QUAD4
#define MED_QUAD4
Definition: med.h:201
MED_NO_IT
#define MED_NO_IT
Definition: med.h:316
med_utils.h
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition: MEDfileOpen.c:41
MEDmeshEntityNameWr
MEDC_EXPORT med_err MEDmeshEntityNameWr(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_entity_type entitype, const med_geometry_type geotype, const med_int nentity, const char *const name)
Cette routine permet d'écrire les noms d'un type d'entité d'un maillage.
Definition: MEDmeshEntityNameWr.c:39
MED_ACC_CREAT
Definition: med.h:121
MED_SORT_DTIT
Definition: med.h:306
med_float
double med_float
Definition: med.h:331
MED_NO_GROUP
#define MED_NO_GROUP
Definition: med.h:286
MEDmeshGridTypeWr
MEDC_EXPORT med_err MEDmeshGridTypeWr(const med_idt fid, const char *const meshname, const med_grid_type gridtype)
Cette routine permet de définir le type d'un maillage structuré (MED_STRUCTURED_MESH).
Definition: MEDmeshGridTypeWr.c:37
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:316
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MEDmeshGridIndexCoordinateWr
MEDC_EXPORT med_err MEDmeshGridIndexCoordinateWr(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_float dt, const med_int axis, const med_int indexsize, const med_float *const gridindex)
Cette routine permet l'écriture des coordonnées des noeuds d'un maillage structuré selon un axe du re...
Definition: MEDmeshGridIndexCoordinateWr.c:43
MED_LNAME_SIZE
#define MED_LNAME_SIZE
Definition: med.h:81
MED_CELL
Definition: med.h:141
med_int
int med_int
Definition: med.h:337
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
MED_NO_NAME
#define MED_NO_NAME
Definition: med.h:265
main
int main(int argc, char **argv)
Definition: UsesCase_MEDmesh_4.c:31
MED_CARTESIAN
Definition: med.h:255
MED_CARTESIAN_GRID
Definition: med.h:135
med_idt
hid_t med_idt
Definition: med.h:326
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_NO_DT
#define MED_NO_DT
Definition: med.h:315
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:79
MED_SNAME_SIZE
#define MED_SNAME_SIZE
Definition: med.h:80
med.h
MED_STRUCTURED_MESH
Definition: med.h:129
MEDmeshEntityFamilyNumberWr
MEDC_EXPORT med_err MEDmeshEntityFamilyNumberWr(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_entity_type entitype, const med_geometry_type geotype, const med_int nentity, const med_int *const number)
Cette routine permet l'écriture des numéros de famille d'un type d'entité d'un maillage.
Definition: MEDmeshEntityFamilyNumberWr.c:39