MED fichier: Fichier source de UsesCase_MEDmesh_8.c

MED fichier

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

UsesCase_MEDmesh_8.c
Aller à la documentation de ce fichier.
1 /* This file is part of MED.
2 *
3 * COPYRIGHT (C) 1999 - 2017 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 8 : read a 2D unstructured mesh with coordinates nodes
20 * modifications (generic approach)
21 */
22
23 #include <med.h>
24 #define MESGERR 1
25 #include <med_utils.h>
26
27 #include <string.h>
28
29 int main (int argc, char **argv) {
30 med_idt fid;
31 med_int nmesh;
32 char meshname[MED_NAME_SIZE+1]="";
33 char meshdescription[MED_COMMENT_SIZE+1]="";
34 med_int meshdim;
35 med_int spacedim;
36 med_sorting_type sortingtype;
37 med_int nstep;
38 med_mesh_type meshtype;
39 med_axis_type axistype;
40 char *axisname;
41 char *unitname;
42 char dtunit[MED_SNAME_SIZE+1]="";
43 med_float *coordinates = NULL;
44 med_int ngeo = 0;
45 med_int nnodes = 0;
46 med_int *connectivity = NULL;
47 med_bool coordinatechangement;
48 med_bool geotransformation;
49 int i, it, j;
50 med_int profilesize;
51 char profilename[MED_NAME_SIZE+1]="";
52 med_int numdt, numit;
53 med_float dt;
54 med_geometry_type geotype;
55 med_geometry_type *geotypes = MED_GET_CELL_GEOMETRY_TYPE;
56 int ret=-1;
57
58 /* open MED file with READ ONLY access mode */
59 fid = MEDfileOpen("UsesCase_MEDmesh_6.med",MED_ACC_RDONLY);
60 if (fid < 0) {
61 MESSAGE("ERROR : open file in READ ONLY ACCESS mode ...");
62 goto ERROR;
63 }
64
65
66 /* read how many mesh in the file */
67 if ((nmesh = MEDnMesh(fid)) < 0) {
68 MESSAGE("ERROR : read how many mesh ...");
69 goto ERROR;
70 }
71
72 for (i=0;i<nmesh;i++) {
73
74 /* read computation space dimension */
75 if ((spacedim = MEDmeshnAxis(fid, i+1)) < 0) {
76 MESSAGE("ERROR : read computation space dimension ...");
77 goto ERROR;
78 }
79
80 /* memory allocation */
81 if ((axisname = (char*) malloc(MED_SNAME_SIZE*spacedim+1)) == NULL) {
82 MESSAGE("ERROR : memory allocation ...");
83 goto ERROR;
84 }
85 if ((unitname = (char*) malloc(MED_SNAME_SIZE*spacedim+1)) == NULL) {
86 MESSAGE("ERROR : memory allocation ...");
87 goto ERROR;
88 }
89
90 /* read mesh informations : meshname, mesh dimension, mesh type ... */
91 if (MEDmeshInfo(fid, i+1, meshname, &spacedim, &meshdim, &meshtype, meshdescription,
92 dtunit, &sortingtype, &nstep,
93 &axistype, axisname, unitname) < 0) {
94 MESSAGE("ERROR : mesh info ...")
95 free(axisname);
96 free(unitname);
97 goto ERROR;
98 }
99 free(axisname);
100 free(unitname);
101
102
103 /* read how many nodes in the mesh */
104 if ((nnodes = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NONE,
105 MED_COORDINATE, MED_NO_CMODE,&coordinatechangement,
106 &geotransformation)) < 0) {
107 MESSAGE("ERROR : number of nodes ...");
108 goto ERROR;
109 }
110
111 /* read mesh nodes coordinates */
112 if ((coordinates = (med_float*) malloc(sizeof(med_float)*nnodes*spacedim)) == NULL) {
113 MESSAGE("ERROR : memory allocation ...");
114 goto ERROR;
115 }
116
117 if (MEDmeshNodeCoordinateRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE,
118 coordinates) < 0) {
119 MESSAGE("ERROR : nodes coordinates ...");
120 free(coordinates);
121 goto ERROR;
122 }
123
124
125 /* read all MED geometry cell types */
126 for (it=1; it<=MED_N_CELL_FIXED_GEO; it++) {
127
128 geotype = geotypes[it];
129
130 if ((ngeo = MEDmeshnEntity(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL,geotype,
131 MED_CONNECTIVITY, MED_NODAL, &coordinatechangement,
132 &geotransformation)) < 0) {
133 MESSAGE("ERROR : number of cell ...");
134 ISCRUTE(geotype);
135 goto ERROR;
136 }
137
138 if (ngeo) {
139 /* read cells connectivity in the mesh */
140 if ((connectivity = (med_int *) malloc(sizeof(med_int)*ngeo*(geotype%100))) == NULL) {
141 MESSAGE("ERROR : memory allocation ...");
142 goto ERROR;
143 }
144
145 if (MEDmeshElementConnectivityRd(fid, meshname, MED_NO_DT, MED_NO_IT, MED_CELL,
146 geotype, MED_NODAL, MED_FULL_INTERLACE, connectivity) < 0) {
147 MESSAGE("ERROR : cellconnectivity ...");
148 ISCRUTE(geotype);
149 free(connectivity);
150 goto ERROR;
151 }
152
153 /* memory deallocation */
154 free(connectivity);
155 connectivity = NULL;
156 }
157 }
158
159
160 /* read nodes coordinates changements step by step */
161 for (it=1;it<nstep;it++) {
162
163 if (MEDmeshComputationStepInfo(fid, meshname, it+1,
164 &numdt, &numit, &dt) < 0) {
165 MESSAGE("ERROR : Computing step info ...");
166 SSCRUTE(meshname);
167 goto ERROR;
168 }
169
170 /* test changement : for nodes coordinates */
171 if ((nnodes = MEDmeshnEntityWithProfile(fid, meshname, numdt, numit,
172 MED_NODE, MED_NONE,
173 MED_COORDINATE, MED_NO_CMODE,
174 MED_GLOBAL_STMODE, profilename, &profilesize,
175 &coordinatechangement, &geotransformation)) < 0) {
176 MESSAGE("ERROR : number of nodes ...");
177 goto ERROR;
178 }
179
180 /* if only coordinates have changed, then read the new coordinates */
181 /* to verify if there is a matrix transformation => UsesCase_MEDmesh12. */
182 if (coordinatechangement && geotransformation) {
183 if (MEDmeshNodeCoordinateWithProfileRd(fid, meshname, numdt, numit,
184 MED_GLOBAL_STMODE,profilename,
185 MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,
186 coordinates) < 0) {
187 MESSAGE("ERROR : nodes coordinates ...");
188 free(coordinates);
189 goto ERROR;
190 }
191 }
192
193 }
194 }
195
196 free(coordinates);
197
198 ret=0;
199 ERROR:
200
201 /* close MED file */
202 if (MEDfileClose(fid) < 0) {
203 MESSAGE("ERROR : close file");
204 ret=-1;
205 }
206
207
208 return ret;
209 }
210
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MED_NODE
Definition: med.h:139
MED_FULL_INTERLACE
Definition: med.h:92
MED_NO_IT
#define MED_NO_IT
Definition: med.h:314
MED_COORDINATE
Definition: med.h:145
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:316
MED_N_CELL_FIXED_GEO
#define MED_N_CELL_FIXED_GEO
Definition: med.h:234
MED_GET_CELL_GEOMETRY_TYPE
med_geometry_type MED_GET_CELL_GEOMETRY_TYPE[MED_N_CELL_FIXED_GEO+2]
Definition: MEDiterators.c:44
MEDmeshInfo
MEDC_EXPORT med_err MEDmeshInfo(const med_idt fid, const int meshit, char *const meshname, med_int *const spacedim, med_int *const meshdim, med_mesh_type *const meshtype, char *const description, char *const dtunit, med_sorting_type *const sortingtype, med_int *const nstep, med_axis_type *const axistype, char *const axisname, char *const axisunit)
Cette routine permet de lire les informations relatives à un maillage dans un fichier.
Definition: MEDmeshInfo.c:43
MEDmeshComputationStepInfo
MEDC_EXPORT med_err MEDmeshComputationStepInfo(const med_idt fid, const char *const meshname, const int csit, med_int *const numdt, med_int *const numit, med_float *const dt)
Cette routine permet de lire les informations relatives à une séquence de calcul d'un maillage...
Definition: MEDmeshComputationStepInfo.c:38
MEDnMesh
MEDC_EXPORT med_int MEDnMesh(const med_idt fid)
Cette routine permet de lire le nombre de maillages dans un fichier.
Definition: MEDnMesh.c:34
med_float
double med_float
Definition: med.h:329
med_mesh_type
med_mesh_type
Definition: med.h:127
MED_ACC_RDONLY
Definition: med.h:116
MED_ALL_CONSTITUENT
#define MED_ALL_CONSTITUENT
Definition: med.h:294
MED_GLOBAL_STMODE
Definition: med.h:105
MED_CELL
Definition: med.h:139
med_sorting_type
med_sorting_type
Definition: med.h:304
med.h
MED_NO_CMODE
Definition: med.h:250
MED_NODAL
Definition: med.h:250
MEDmeshnAxis
MEDC_EXPORT med_int MEDmeshnAxis(const med_idt fid, const int meshit)
Cette routine permet de lire dans un maillage le nombre d'axes du repère des coordonnées des noeuds...
Definition: MEDmeshnAxis.c:35
MED_NONE
#define MED_NONE
Definition: med.h:226
med_axis_type
med_axis_type
Definition: med.h:253
med_int
int med_int
Definition: med.h:335
MEDmeshnEntityWithProfile
MEDC_EXPORT med_int MEDmeshnEntityWithProfile(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_data_type datatype, const med_connectivity_mode cmode, const med_storage_mode storagemode, char *const profilename, med_int *const profilesize, med_bool *const changement, med_bool *const transformation)
Cette routine permet de lire le nombre d'entités dans un maillage pour une séquence de calcul et un p...
Definition: MEDmeshnEntityWithProfile.c:47
MEDmeshNodeCoordinateWithProfileRd
MEDC_EXPORT med_err MEDmeshNodeCoordinateWithProfileRd(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_storage_mode storagemode, const char *const profilename, const med_switch_mode switchmode, const med_int dimselect, med_float *const coordinates)
Cette routine permet de lire dans un maillage le tableau des coordonnées des noeuds, selon une séquence de calcul donnée et un profil donnés.
Definition: MEDmeshNodeCoordinateWithProfileRd.c:40
main
int main(int argc, char **argv)
Definition: UsesCase_MEDmesh_8.c:29
MED_COMMENT_SIZE
#define MED_COMMENT_SIZE
Definition: med.h:75
MEDmeshElementConnectivityRd
MEDC_EXPORT med_err MEDmeshElementConnectivityRd(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_connectivity_mode cmode, const med_switch_mode switchmode, med_int *const connectivity)
Cette routine permet de lire dans un maillage le tableau des connectivités pour un type géométrique d...
Definition: MEDmeshElementConnectivityRd.c:40
ISCRUTE
#define ISCRUTE(entier)
Definition: med_utils.h:306
MED_CONNECTIVITY
Definition: med.h:145
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition: MEDfileOpen.c:41
med_idt
hid_t med_idt
Definition: med.h:324
MEDmeshnEntity
MEDC_EXPORT med_int MEDmeshnEntity(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_data_type datatype, const med_connectivity_mode cmode, med_bool *const changement, med_bool *const transformation)
Cette routine permet de lire le nombre d'entités dans un maillage pour une séquence de calcul donnée...
Definition: MEDmeshnEntity.c:44
MEDmeshNodeCoordinateRd
MEDC_EXPORT med_err MEDmeshNodeCoordinateRd(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_switch_mode switchmode, med_float *const coordinates)
Cette routine permet de lire dans un maillage le tableau des coordonnées des noeuds, selon une séquence de calcul donnée.
Definition: MEDmeshNodeCoordinateRd.c:37
MED_NO_DT
#define MED_NO_DT
Definition: med.h:313
MED_NAME_SIZE
#define MED_NAME_SIZE
Definition: med.h:77
med_utils.h
MED_SNAME_SIZE
#define MED_SNAME_SIZE
Definition: med.h:78
med_bool
med_bool
Definition: med.h:255
med_geometry_type
int med_geometry_type
Definition: med.h:189
SSCRUTE
#define SSCRUTE(chaine)
Definition: med_utils.h:315