MED fichier: Fichier source de UsesCase_MEDstructElement_1.c

MED fichier

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

UsesCase_MEDstructElement_1.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 * StructElement use case 1 : write struct elements model in a file
20 * STEP 1 : suppport mesh creation
21 * STEP 2 : struct element model creation
22 * STEP 3 : computation mesh creation
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 char elementname[MED_NAME_SIZE+1]="";
34 const char ballsupportname[MED_NAME_SIZE+1]="BALL_SUPPORT_MESH";
35 const char beamsupportname[MED_NAME_SIZE+1]="BEAM_SUPPORT_MESH";
36 const char computmeshname[MED_NAME_SIZE+1]="COMPUT_MESH";
37 const char beamsectionname[MED_NAME_SIZE+1]="BEAM_SECTION_MESH";
38 const med_int elementdim = 3;
39 med_int nnode;
40 med_geometry_type geotype=MED_NONE;
41 med_int ncomp;
42 const med_float ballmeshnodescoo[3] = {0.0, 0.0, 0.0 };
43 const med_float beammeshnodescoo[3*7] = {0.0,0.0,0.0,
44 0.0,0.0,2.0,
45 0.0,0.0,4.0,
46 0.0,0.0,5.0,
47 0.0,0.0,7.0,
48 0.0,0.0,10.0,
49 0.0,0.0,11.0 };
50 const med_float beamsectioncoo[9*3] = {-0.2,-0.2,0.0,
51 0.0,-0.2,0.0,
52 0.2,-0.2,0.0,
53 -0.2, 0.0,0.0,
54 0.0, 0.0,0.0,
55 0.2, 0.0,0.0,
56 -0.2, 0.2,0.0,
57 0.0, 0.2,0.0,
58 0.2, 0.2,0.0 };
59 const med_int seg2connectivity[2*6] = {1,2, 2,3, 3,4, 4,5, 5,6, 6,7};
60 med_int spacedim, meshdim,nseg2;
61 /* 123456789012345612345678901234561234567890123456 */
62 const char axisname[3*MED_SNAME_SIZE+1] = "x y z ";
63 const char unitname[3*MED_SNAME_SIZE+1] = "cm cm cm ";
64 const med_float attvalue[6] = {0.2,0.3,0.4,0.4,0.3,0.2};
65 /* 1234567890123456789012345678901234567890123456789012345678901234 */
66 const char attprovalue[2*MED_NAME_SIZE+1] = {"EXTREMITY_1_____________________________________________________" \
67 "EXTREMITY_2_____________________________________________________" };
68 const char profilename[MED_NAME_SIZE+1] = "EXTREMITY_PROFILE_NAME";
69 const med_int profilesize = 2;
70 const med_int profile[2] = {1,6};
71 const med_float meshcoo[3*12] = { 0.0, 0.0, 0.0,
72 1.1, 1.1, 1.1,
73 2.2, 2.2, 2.2,
74 10., 10., 10.,
75 12., 12., 12.,
76 60., 20., 20.,
77 70., 20., 20.,
78 80., 20., 20.,
79 90., 20., 20.,
80 100., 20., 20.,
81 110., 20., 20.,
82 120., 20., 20.
83 };
84 const med_int beamconnectivity[12] = { 6,7,
85 7,8,
86 8,9,
87 9,10,
88 10,11,
89 11,12 };
90 med_int nentity;
91 const med_int labels[3] = { 1, 2, 3 }; /* nodes numbers */
92 const med_int ballconnectivity[2] = { 4, 5 }; /* nodes numbers */
93 const med_float balldiameter[2] = { 2.0, 5.8 };
94 const med_int nquad4=4;
95 const med_int beamsectionconnectivity[4*4] = { 4,5,2,1,
96 5,6,3,2,
97 7,8,5,4,
98 8,9,6,5};
99 int ret=-1;
100
101 /* file creation */
102 fid = MEDfileOpen("UsesCase_MEDstructElement_1.med",MED_ACC_CREAT);
103 if (fid < 0) {
104 MESSAGE("ERROR : file creation");
105 goto ERROR;
106 }
107
108 /* STEP 1 : support meshes creation */
109 spacedim = 3;
110 meshdim = 3;
111
112 /* Mesh 1 : support mesh for ball model */
113 if (MEDsupportMeshCr(fid, ballsupportname, spacedim, meshdim, "Support mesh for a ball model",
114 MED_CARTESIAN, axisname, unitname) < 0) {
115 MESSAGE("ERROR : creating a support mesh ...");
116 goto ERROR;
117 }
118 /* 1 node and no cell in the mesh */
119 nnode = 1;
120 if (MEDmeshNodeCoordinateWr(fid, ballsupportname, MED_NO_DT, MED_NO_IT, 0.0,
121 MED_FULL_INTERLACE, nnode, ballmeshnodescoo) < 0) {
122 MESSAGE("ERROR : write nodes coordinates ...");
123 goto ERROR;
124 }
125
126 /* Mesh 2 :support mesh for beam model */
127 if (MEDsupportMeshCr(fid, beamsupportname, spacedim, meshdim, "Support mesh for a beam model",
128 MED_CARTESIAN, axisname, unitname) < 0) {
129 MESSAGE("ERROR : creating a support mesh ...");
130 goto ERROR;
131 }
132 /* 7 nodes and 6 MED_SEG2 */
133 nnode = 7;
134 if (MEDmeshNodeCoordinateWr(fid, beamsupportname, MED_NO_DT, MED_NO_IT, 0.0,
135 MED_FULL_INTERLACE, nnode, beammeshnodescoo) < 0) {
136 MESSAGE("ERROR : write nodes coordinates ...");
137 goto ERROR;
138 }
139 nseg2 = 6;
140 if (MEDmeshElementConnectivityWr(fid, beamsupportname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_SEG2,
141 MED_NODAL, MED_FULL_INTERLACE, nseg2, seg2connectivity) < 0) {
142 MESSAGE("ERROR : write cells connectivity ...");
143 goto ERROR;
144 }
145
146 /* Mesh 3 : support mesh to define a section for integration points of
147 a struct element */
148 if (MEDsupportMeshCr(fid, beamsectionname, spacedim, meshdim, "Support mesh for a section of the beam model",
149 MED_CARTESIAN, axisname, unitname) < 0) {
150 MESSAGE("ERROR : creating a support mesh ...");
151 goto ERROR;
152 }
153
154 nnode = 9;
155 if (MEDmeshNodeCoordinateWr(fid, beamsectionname, MED_NO_DT, MED_NO_IT, 0.0,
156 MED_FULL_INTERLACE, nnode, beamsectioncoo) < 0) {
157 MESSAGE("ERROR : write nodes coordinates ...");
158 goto ERROR;
159 }
160
161 if (MEDmeshElementConnectivityWr(fid, beamsectionname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_QUAD4,
162 MED_NODAL, MED_FULL_INTERLACE, nquad4, beamsectionconnectivity) < 0) {
163 MESSAGE("ERROR : write cells connectivity ...");
164 goto ERROR;
165 }
166
167 /* STEP 2 */
168 /* particle model creation : no support mesh */
169 strcpy(elementname,MED_PARTICLE_NAME);
170 if ((geotype = MEDstructElementCr(fid, elementname, elementdim, MED_NO_MESHNAME,
171 MED_NONE,MED_NONE)) < 0) {
172 MESSAGE("ERROR : creating struct element");
173 goto ERROR;
174 }
175 ncomp=1;
176 if (MEDstructElementVarAttCr(fid, elementname,
177 MED_PARTICLE_LABEL, MED_ATT_INT, ncomp) < 0) {
178 MESSAGE("ERROR : creating struct element");
179 goto ERROR;
180 }
181
182 /* ball model creation */
183 strcpy(elementname,MED_BALL_NAME);
184 if ((geotype = MEDstructElementCr(fid, elementname, elementdim, ballsupportname,
185 MED_NODE,MED_NONE)) < 0) {
186 MESSAGE("ERROR : creating struct element");
187 goto ERROR;
188 }
189 ncomp=1;
190 if (MEDstructElementVarAttCr(fid, elementname,
191 MED_BALL_DIAMETER, MED_ATT_FLOAT64, ncomp) < 0) {
192 MESSAGE("ERROR : creating struct element");
193 goto ERROR;
194 }
195
196
197 /* A beam */
198 strcpy(elementname,MED_BEAM_NAME);
199 if ((geotype = MEDstructElementCr(fid, elementname, elementdim, beamsupportname,
200 MED_CELL,MED_SEG2)) < 0) {
201 MESSAGE("ERROR : creating struct element");
202 goto ERROR;
203 }
204 ncomp=1;
205 /* a first constant attribute */
206 if (MEDstructElementConstAttWr(fid, elementname,
207 MED_BEAM_THICKNESS, MED_ATT_FLOAT64, ncomp,
208 MED_CELL,(void*) attvalue) < 0) {
209 MESSAGE("ERROR : creating struct element");
210 goto ERROR;
211 }
212 /* a second constant attribute defined with a profile for the first and the
213 last segment */
214 /* create the profile */
215 if (MEDprofileWr(fid, profilename, profilesize, profile ) < 0) {
216 MESSAGE("ERROR : create profile ...");
217 goto ERROR;
218 }
219 /* write the constant attribute */
220 if (MEDstructElementConstAttWithProfileWr(fid,
221 elementname,
222 "BEAM_EXTREMITIES_LABELS",
223 MED_ATT_NAME,
224 ncomp,
225 MED_CELL,
226 profilename,
227 (void*) attprovalue) < 0) {
228 MESSAGE("ERROR : creating struct element");
229 goto ERROR;
230 }
231
232 /* STEP 3 : Computation mesh creation */
233
234 /* mesh creation */
235 if (MEDmeshCr(fid, computmeshname, spacedim, meshdim, MED_UNSTRUCTURED_MESH,
236 "Computation mesh", "s", MED_SORT_DTIT,
237 MED_CARTESIAN, axisname, unitname) < 0) {
238 MESSAGE("ERROR : creating computation mesh ...");
239 goto ERROR;
240 }
241
242 /* mesh node creation */
243 nnode = 12;
244 if (MEDmeshNodeCoordinateWr(fid, computmeshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
245 MED_FULL_INTERLACE, nnode, meshcoo) < 0) {
246 MESSAGE("ERROR : writing nodes coordinates ...");
247 goto ERROR;
248 }
249
250 /* 1 beam */
251 nentity = 1;
252 SSCRUTE(elementname);
253 geotype = MEDstructElementGeotype(fid,elementname);
254 ISCRUTE(geotype);
255
256 if (MEDmeshElementConnectivityWr(fid,computmeshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
257 MED_STRUCT_ELEMENT, geotype, MED_NODAL,
258 MED_FULL_INTERLACE, nentity, beamconnectivity) < 0 ) {
259 MESSAGE("ERROR : beam connectivity ...");
260 goto ERROR;
261 }
262
263 /* Get the dynamic geometry type of each struct element model.
264 Then for each type, write the connectivity and variable(s) attribute(s) */
265
266 /* 3 particles in the mesh */
267 strcpy(elementname,MED_PARTICLE_NAME);
268 geotype = MEDstructElementGeotype(fid,elementname);
269 nentity = 3;
270 ISCRUTE(geotype);
271 if (MEDmeshElementConnectivityWr(fid, computmeshname, MED_NO_DT, MED_NO_IT, 0.0,
272 MED_STRUCT_ELEMENT, geotype , MED_NODAL, MED_FULL_INTERLACE,
273 nentity, 0) < 0) {
274 MESSAGE("ERROR : writing particles connectivity ...");
275 goto ERROR;
276 }
277
278 /* no support mesh => no connectivity, the particles are localized with an association between
279 the mesh nodes and the label attribute defined in the struct model */
280 if (MEDmeshStructElementVarAttWr(fid, computmeshname, MED_NO_DT, MED_NO_IT,
281 geotype, MED_PARTICLE_LABEL,
282 nentity, labels) < 0 ) {
283 MESSAGE("ERROR : writing variable attributes ...");
284 goto ERROR;
285 }
286
287
288 /* 2 balls */
289 strcpy(elementname,MED_BALL_NAME);
290 nentity = 2;
291 geotype = MEDstructElementGeotype(fid,elementname);
292 if (MEDmeshElementConnectivityWr(fid,computmeshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT,
293 MED_STRUCT_ELEMENT, geotype, MED_NODAL,
294 MED_FULL_INTERLACE, nentity, ballconnectivity) < 0 ) {
295 MESSAGE("ERROR : writing balls connectivity");
296 goto ERROR;
297 }
298
299 /* variable attribute : write ball diameter */
300 if (MEDmeshStructElementVarAttWr(fid, computmeshname, MED_NO_DT, MED_NO_IT,
301 geotype, MED_BALL_DIAMETER,
302 nentity, balldiameter) < 0 ) {
303 MESSAGE("ERROR : writing variable attributes ...");
304 goto ERROR;
305 }
306
307
308 ret=0;
309 ERROR:
310
311 /* close file */
312 if (MEDfileClose(fid) < 0) {
313 MESSAGE("ERROR : file closing");
314 ret=-1;
315 }
316
317 return ret;
318 }
319
MEDstructElementGeotype
MEDC_EXPORT med_geometry_type MEDstructElementGeotype(const med_idt fid, const char *const modelname)
Cette routine renvoie le type géométrique mgeotype associé au modèle d'éléments de structure de nom m...
Definition: MEDstructElementGeotype.c:38
MED_QUAD4
#define MED_QUAD4
Definition: med.h:201
MED_NO_IT
#define MED_NO_IT
Definition: med.h:316
MEDstructElementVarAttCr
MEDC_EXPORT med_err MEDstructElementVarAttCr(const med_idt fid, const char *const modelname, const char *const varattname, const med_attribute_type varatttype, const med_int ncomponent)
Cette routine déclare la présence d'un attribut caractéristique variable attaché aux éléments de type...
Definition: MEDstructElementVarAttCr.c:42
med_utils.h
MED_PARTICLE_NAME
#define MED_PARTICLE_NAME
Definition: med.h:434
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_NODAL
Definition: med.h:252
MED_FULL_INTERLACE
Definition: med.h:94
MED_ACC_CREAT
Definition: med.h:121
MED_SORT_DTIT
Definition: med.h:306
med_float
double med_float
Definition: med.h:331
MEDmeshElementConnectivityWr
MEDC_EXPORT med_err MEDmeshElementConnectivityWr(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_geometry_type geotype, const med_connectivity_mode cmode, const med_switch_mode switchmode, const med_int nentity, const med_int *const connectivity)
Cette routine permet d'écrire dans un maillage le tableau des connectivités pour un type géométrique ...
Definition: MEDmeshElementConnectivityWr.c:42
MED_STRUCT_ELEMENT
Definition: med.h:142
MED_SEG2
#define MED_SEG2
Definition: med.h:197
MEDprofileWr
MEDC_EXPORT med_err MEDprofileWr(const med_idt fid, const char *const profilename, const med_int profilesize, const med_int *const profilearray)
Cette routine permet d'écrire un profil dans un fichier MED.
Definition: MEDprofileWr.c:40
MED_ATT_INT
Definition: med.h:171
MED_UNDEF_DT
#define MED_UNDEF_DT
Definition: med.h:317
MEDsupportMeshCr
MEDC_EXPORT med_err MEDsupportMeshCr(const med_idt fid, const char *const supportmeshname, const med_int spacedim, const med_int meshdim, const char *const description, const med_axis_type axistype, const char *const axisname, const char *const axisunit)
Cette routine permet de créer un maillage support.
Definition: MEDsupportMeshCr.c:46
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:316
MEDstructElementCr
MEDC_EXPORT med_geometry_type MEDstructElementCr(const med_idt fid, const char *const modelname, const med_int modeldim, const char *const supportmeshname, const med_entity_type sentitytype, const med_geometry_type sgeotype)
Cette routine permet de créer un nouveau modèle d'éléments de structure dans un fichier MED...
Definition: MEDstructElementCr.c:50
MED_BALL_NAME
#define MED_BALL_NAME
Definition: med.h:435
MED_ATT_FLOAT64
Definition: med.h:170
MED_NODE
Definition: med.h:141
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MED_BEAM_THICKNESS
#define MED_BEAM_THICKNESS
Definition: med.h:441
MED_CELL
Definition: med.h:141
MED_UNSTRUCTURED_MESH
Definition: med.h:129
MED_NONE
#define MED_NONE
Definition: med.h:228
MED_NO_MESHNAME
#define MED_NO_MESHNAME
Definition: med.h:267
MED_BEAM_NAME
#define MED_BEAM_NAME
Definition: med.h:436
med_int
int med_int
Definition: med.h:337
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, selon une séquence de calcul donnée.
Definition: MEDmeshNodeCoordinateWr.c:45
MEDmeshStructElementVarAttWr
MEDC_EXPORT med_err MEDmeshStructElementVarAttWr(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_geometry_type mgeotype, const char *const varattname, const med_int nentity, const void *const value)
Cette routine écrit les valeurs d'un attribut caractéristique variable sur les éléments de structure ...
Definition: MEDmeshStructElementVarAttWr.c:42
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
ISCRUTE
#define ISCRUTE(entier)
Definition: med_utils.h:306
MEDstructElementConstAttWr
MEDC_EXPORT med_err MEDstructElementConstAttWr(const med_idt fid, const char *const modelname, const char *const constattname, const med_attribute_type constatttype, const med_int ncomponent, const med_entity_type sentitytype, const void *const value)
Cette routine définit un attribut caractéristique constant d'un modèle d'éléments de structure...
Definition: MEDstructElementConstAttWr.c:43
MEDstructElementConstAttWithProfileWr
MEDC_EXPORT med_err MEDstructElementConstAttWithProfileWr(const med_idt fid, const char *const modelname, const char *const constattname, const med_attribute_type constatttype, const med_int ncomponent, const med_entity_type sentitytype, const char *const profilename, const void *const value)
Cette routine définit un attribut caractéristique constant d'un modèle d'éléments de structure...
Definition: MEDstructElementConstAttWithProfileWr.c:44
main
int main(int argc, char **argv)
Definition: UsesCase_MEDstructElement_1.c:31
MED_PARTICLE_LABEL
#define MED_PARTICLE_LABEL
Definition: med.h:439
MED_CARTESIAN
Definition: med.h:255
MED_ATT_NAME
Definition: med.h:172
med_idt
hid_t med_idt
Definition: med.h:326
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_BALL_DIAMETER
#define MED_BALL_DIAMETER
Definition: med.h:440
med_geometry_type
int med_geometry_type
Definition: med.h:191
SSCRUTE
#define SSCRUTE(chaine)
Definition: med_utils.h:315