MED fichier: Fichier source de UsesCase_MEDmesh_9.c

MED fichier

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

UsesCase_MEDmesh_9.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 * How to create an unstructured mesh
20 *
21 * Use case 9 : a 2D unstructured mesh with moving grid
22 * transformation
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 unstructured 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 const med_float initial_coordinates[30] = { 2.,1., 7.,1., 12.,1., 17.,1., 22.,1.,
39 2.,6., 7.,6., 12.,6., 17.,6., 22.,6.,
40 2.,11., 7.,11., 12.,11., 17.,11., 22.,11.};
41 const med_int nnodes = 15;
42 const med_int triaconnectivity[24] = { 1,7,6, 2,7,1, 3,7,2, 8,7,3,
43 13,7,8, 12,7,13, 11,7,12, 6,7,11 };
44 const med_int ntria3 = 8;
45 const med_int quadconnectivity[16] = {3,4,9,8, 4,5,10,9,
46 15,14,9,10, 13,8,9,14};
47 const med_int nquad4 = 4;
48 /* matrix transformation (step 1) : rotation about the Y-axis : 45 degrees */
49 const med_float tansfMatrix_step1 [7] = { 0.0, 0.0, 0.0, 0.92388, 0.0, 0.38268, 0.0 };
50 /* matrix transformation (step 2) : rotation about the Y-axis : 90 degrees */
51 const med_float tansfMatrix_step2 [7] = { 0.0, 0.0, 0.0, 0.707, 0.0, 0.707, 0.0 };
52 int ret=-1;
53
54 /* open MED file */
55 fid = MEDfileOpen("UsesCase_MEDmesh_9.med",MED_ACC_CREAT);
56 if (fid < 0) {
57 MESSAGE("ERROR : file creation ...");
58 goto ERROR;
59 }
60
61 /* write a comment in the file */
62 if (MEDfileCommentWr(fid,"A 2D unstructured mesh : 15 nodes, 12 cells") < 0) {
63 MESSAGE("ERROR : write file description ...");
64 goto ERROR;
65 }
66
67 /* mesh creation : a 2D unstructured mesh */
68 if (MEDmeshCr(fid, meshname, spacedim, meshdim, MED_UNSTRUCTURED_MESH,
69 "A 2D structured mesh","",MED_SORT_DTIT,MED_CARTESIAN, axisname, unitname) < 0) {
70 MESSAGE("ERROR : mesh creation ...");
71 goto ERROR;
72 }
73
74 /* nodes coordinates in a cartesian axis in full interlace mode
75 (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step
76 */
77 if (MEDmeshNodeCoordinateWithProfileWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0,
78 MED_COMPACT_STMODE, MED_NO_PROFILE,
79 MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
80 nnodes, initial_coordinates) < 0) {
81 MESSAGE("ERROR : nodes coordinates ...");
82 goto ERROR;
83 }
84
85 /* cells connectiviy is defined in nodal mode */
86 if (MEDmeshElementConnectivityWithProfileWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0,
87 MED_CELL, MED_TRIA3, MED_NODAL,
88 MED_COMPACT_STMODE, MED_NO_PROFILE,
89 MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
90 ntria3, triaconnectivity) < 0) {
91 MESSAGE("ERROR : triangular cells connectivity ...");
92 goto ERROR;
93 }
94
95 if (MEDmeshElementConnectivityWithProfileWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0,
96 MED_CELL, MED_QUAD4, MED_NODAL,
97 MED_COMPACT_STMODE, MED_NO_PROFILE,
98 MED_FULL_INTERLACE, MED_ALL_CONSTITUENT,
99 nquad4, quadconnectivity) < 0) {
100 MESSAGE("ERROR : quadrangular cells connectivity ...");
101 goto ERROR;
102 }
103
104 /*
105 * Mesh deformation (nodes coordinates) in 2 steps
106 * A rotation by step for each node
107 */
108 /* STEP 1 : dt1 = 5.5, it = 1*/
109 if ( MEDmeshNodeCoordinateTrsfWr(fid, meshname, 1, 1, 5.5, tansfMatrix_step1) < 0) {
110 MESSAGE("Erreur a l'ecriture de la transformation géométrique n°1");
111 goto ERROR;
112 }
113
114 /* STEP 2 : dt2 = 8.9, it = 1*/
115 if ( MEDmeshNodeCoordinateTrsfWr(fid, meshname, 2, 2, 8.9, tansfMatrix_step2 ) < 0) {
116 MESSAGE("Erreur a l'ecriture de la transformation géométrique n°1");
117 goto ERROR;
118 }
119
120 /* create family 0 : by default, all mesh entities family number is 0 */
121 if (MEDfamilyCr(fid, meshname,MED_NO_NAME, 0, 0, MED_NO_GROUP) < 0) {
122 MESSAGE("ERROR : create family ...");
123 goto ERROR;
124 }
125
126 ret=0;
127 ERROR:
128
129 /* close MED file */
130 if (MEDfileClose(fid) < 0) {
131 MESSAGE("ERROR : close file ...");
132 ret=-1;
133 }
134
135 return ret;
136 }
MED_QUAD4
#define MED_QUAD4
Definition: med.h:199
MEDfileClose
MEDC_EXPORT med_err MEDfileClose(med_idt fid)
Fermeture d'un fichier MED.
Definition: MEDfileClose.c:30
MED_TRIA3
#define MED_TRIA3
Definition: med.h:198
MED_CARTESIAN
Definition: med.h:253
MED_FULL_INTERLACE
Definition: med.h:92
MED_NO_IT
#define MED_NO_IT
Definition: med.h:314
MEDmeshNodeCoordinateTrsfWr
MEDC_EXPORT med_err MEDmeshNodeCoordinateTrsfWr(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_float dt, const med_float *const coordinatetrsf)
Cette routine définit les paramètres de translation rotation à appliquer aux noeuds de la séquence de...
Definition: MEDmeshNodeCoordinateTrsfWr.c:41
MED_SORT_DTIT
Definition: med.h:304
MESSAGE
#define MESSAGE(chaine)
Definition: med_utils.h:316
MED_NO_GROUP
#define MED_NO_GROUP
Definition: med.h:284
med_float
double med_float
Definition: med.h:329
MED_COMPACT_STMODE
Definition: med.h:106
MED_ALL_CONSTITUENT
#define MED_ALL_CONSTITUENT
Definition: med.h:294
MED_CELL
Definition: med.h:139
MED_UNSTRUCTURED_MESH
Definition: med.h:127
med.h
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_NODAL
Definition: med.h:250
med_int
int med_int
Definition: med.h:335
MED_NO_NAME
#define MED_NO_NAME
Definition: med.h:263
MEDmeshNodeCoordinateWithProfileWr
MEDC_EXPORT med_err MEDmeshNodeCoordinateWithProfileWr(const med_idt fid, const char *const meshname, const med_int numdt, const med_int numit, const med_float dt, const med_storage_mode storagemode, const char *const profilename, const med_switch_mode switchmode, const med_int dimselect, 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 et un profil donnés.
Definition: MEDmeshNodeCoordinateWithProfileWr.c:46
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_PROFILE
#define MED_NO_PROFILE
Definition: med.h:276
main
int main(int argc, char **argv)
Definition: UsesCase_MEDmesh_9.c:31
MEDfileOpen
MEDC_EXPORT med_idt MEDfileOpen(const char *const filename, const med_access_mode accessmode)
Ouverture d'un fichier MED.
Definition: MEDfileOpen.c:41
MEDmeshElementConnectivityWithProfileWr
MEDC_EXPORT med_err MEDmeshElementConnectivityWithProfileWr(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_storage_mode storagemode, const char *const profilename, const med_switch_mode switchmode, const med_int dimselect, 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: MEDmeshElementConnectivityWithProfileWr.c:45
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
med_idt
hid_t med_idt
Definition: med.h:324
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_ACC_CREAT
Definition: med.h:119