1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 creation d'une geometrie 3d : un cube [0,1]^3
25 maillé uniformement en hexahedres reguliers;
26 avec en plus une partie des faces (une partie
27 des faces de la frontiere) du maillage.
28 ATTENTION : 3 noeuds dans chaque direction
35 int main (int argc, char **argv)
39 char maa[MED_NAME_SIZE+1] = "CUBE_EN_HEXA8";
40 char maadesc[MED_COMMENT_SIZE+1] = "Example de maillage non structure 3D";
75 char nomcoo[3*MED_SNAME_SIZE+1] = "x y z ";
76 char unicoo[3*MED_SNAME_SIZE+1] = "cm cm cm ";
77 /* char nomnoe[19*MED_TAILLE_PNOM+1] = "nom1 nom2 nom3 nom4";*/
79 // med_int numnoe[27] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27};
80 med_int nufano[27] = {1,1,1,1,1,1,1,1,1,3,3,3,3,0,3,3,3,3,2,2,2,2,2,2,2,2,2};
86 4, 13, 14, 5, 1, 10, 11, 2,
87 5, 14, 15, 6, 2, 11, 12, 3,
88 7, 16, 17, 8, 4, 13, 14, 5,
89 8, 17, 18, 9, 5, 14, 15, 6,
90 13, 22, 23, 14, 10, 19, 20, 11,
91 14, 23, 24, 15, 11, 20, 21, 12,
92 16, 25, 26, 17, 13, 22, 23, 14,
93 17, 26, 27, 18, 14, 23, 24, 15
95 // char nomhexa8[MED_TAILLE_PNOM*8+1] = "hexa1 hexa2 hexa3 hexa4 hexa5 hexa6 hexa7 hexa8 ";
96 // med_int numhexa8[8] = {1,2,3,4,5,6,7,8};
97 med_int nufahexa8[8] = {-1,-1,-1,-1,-2,-2,-2,-2};
99 char nomfam[MED_NAME_SIZE+1];
101 //char attdesMED_TAILLE_DESC+1];
106 char gro[MED_LNAME_SIZE+1];
107 char dtunitp3[MED_LNAME_SIZE+1]="";
113 Some fields : 2 on nodes : one int and one double , one on cells : double
116 char champ1[MED_NAME_SIZE+1]="fieldnodeint" ;
117 char champ1_comp[MED_SNAME_SIZE+1]="comp1 " ;
118 char champ1_unit[MED_SNAME_SIZE+1]="M " ;
119 med_int fieldnodeint[27] = {1,1,3,2,2,3,4,4,5,1,1,3,2,2,3,4,4,5,1,1,3,2,2,3,4,4,5};
121 char champ2[MED_NAME_SIZE+1]="fieldnodedouble" ;
122 char champ2_comp[MED_SNAME_SIZE+1]="comp1 " ;
123 char champ2_unit[MED_SNAME_SIZE+1]="J " ;
124 med_float fieldnodedouble1[27] = {1.,3.,4.,1.,3.,4.,3.,2.,5.,1.,3.,4.,1.,3.,4.,3.,2.,5.,1.,3.,4.,1.,3.,4.,3.,2.,5.};
125 med_float fieldnodedouble2[27] = {1.,2.,2.,3.,3.,3.,4.,4.,5.,1.,2.,2.,3.,3.,3.,4.,4.,5.,1.,2.,2.,3.,3.,3.,4.,4.,5.};
127 char champ3[MED_NAME_SIZE+1]="fieldcelldouble" ;
128 char champ3_comp[MED_SNAME_SIZE*3+1]="comp1 comp2 comp3 " ;
129 char champ3_unit[MED_SNAME_SIZE*3+1]="M/S m/s m/s " ;
130 med_float fieldcelldouble[8*3] = {0.,1.,1.,1.,1.,2.,2.,3.,0.,1.,1.,1.,1.,2.,2.,3.,0.,1.,1.,1.,1.,2.,2.,3.};
132 /***************************************************************************/
133 fid = MEDfileOpen("cube_hexa8.med",MED_ACC_RDWR);
138 printf("MEDouvrir : %d\n",ret);
140 /***************************************************************************/
142 ret = MEDmeshCr(fid,maa,mdim,mdim,MED_UNSTRUCTURED_MESH,maadesc,dtunitp3,
143 MED_SORT_DTIT,MED_CARTESIAN,nomcoo,unicoo);
144 printf("MEDmaaCr : %d\n",ret);
146 ret = MEDunvCr(fid,maa);
147 printf("MEDunvCr : %d\n",ret);
149 /***************************************************************************/
151 ret = MEDmeshNodeCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,MED_FULL_INTERLACE,nnoe,coo);
152 MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,0,nnoe,nufano);
153 printf("MEDnoeudsEcr : %d\n",ret);
155 /* ecriture des mailles MED_HEXA8 :
158 - numeros (optionnel)
159 - numeros des familles */
161 ret = MEDmeshElementConnectivityWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,
162 MED_CELL,MED_HEXA8,MED_NODAL,MED_FULL_INTERLACE,
164 MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_HEXA8,nhexa8,nufahexa8);
165 printf("MEDelementsEcr : %d \n",ret);
167 /***************************************************************************/
168 /* ecriture des familles */
170 - toujours creer une famille de numero 0 ne comportant aucun attribut
171 ni groupe (famille de reference pour les noeuds ou les elements
172 qui ne sont rattaches a aucun groupe ni attribut)
173 - les numeros de familles de noeuds sont > 0
174 - les numeros de familles des elements sont < 0
175 - rien d'imposer sur les noms de familles
181 strcpy(nomfam,"FAMILLE_0");
183 ret = MEDfamilyCr(fid,maa,nomfam,numfam,0,gro);
188 - 2 familles d'elements (-1,-2) et
189 - 3 familles de noeuds (1,2,3)
195 for (i=0;i<nfame;i++)
199 strcpy(nomfam,"FAMILLE_ELEMENT_");
201 sprintf(nomfam,"%s%d",nomfam,-numfam);
205 //strcpy(attdes,"description attribut");
206 strcpy(gro,"groupe1");
209 /*printf("nomfam : %s - numfam : %d - attide : %d - attval : %d - ngro : %d \n",nomfam,numfam,attide,attval,ngro);*/
211 ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
212 printf("MEDfamCr : %d\n",ret);
220 for (i=0;i<nfamn;i++)
224 strcpy(nomfam,"FAMILLE_NOEUD_");
226 sprintf(nomfam,"%s%d",nomfam,numfam);
230 //strcpy(attdes,"description attribut");
231 strcpy(gro,"groupe2");
233 ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
234 printf("MEDfamCr : %d\n",ret);
239 /***************************************************************************/
245 ret = MEDfieldCr(fid,champ1,MED_INT32,1,champ1_comp,champ1_unit,dtunitp3,maa);
246 printf("MEDchampCr : %d \n",ret);
248 ret = MEDfieldValueWr(fid, champ1,MED_NO_DT,MED_NO_IT,0.,MED_NODE,0,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodeint);
250 printf("MEDchampEcr : %d \n",ret);
256 ret = MEDfieldCr(fid,champ2,MED_FLOAT64,1,champ2_comp,champ2_unit,dtunitp3,maa);
257 printf("MEDchampCr : %d \n",ret);
259 ret = MEDfieldValueWr(fid, champ2,1,MED_NO_IT,1.1 ,MED_NODE,0,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble1);
260 printf("MEDchampEcr1 : %d \n",ret);
261 ret = MEDfieldValueWr(fid, champ2,2,MED_NO_IT,1.2 ,MED_NODE,0,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble2);
262 printf("MEDchampEcr2 : %d \n",ret);
266 /* on met champ2 sans pas de temps pour pouvoir le lire aussi par defaut !*/
269 ret = MEDfieldValueWr(fid, champ2,MED_NO_DT,MED_NO_IT,0. ,MED_NODE,0,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble1);
270 printf("MEDchampEcr : %d \n",ret);
275 ret = MEDfieldCr(fid,champ3,MED_FLOAT64,3,champ3_comp,champ3_unit,dtunitp3,maa);
276 printf("MEDchampCr : %d \n",ret);
278 ret = MEDfieldValueWr(fid, champ3,MED_NO_DT,MED_NO_IT,0.,MED_CELL,MED_HEXA8,MED_FULL_INTERLACE,MED_ALL_CONSTITUENT,nhexa8, (unsigned char *)fieldcelldouble);
279 printf("MEDchampEcr : %d \n",ret);
283 /***************************************************************************/
285 ret = MEDfermer(fid);
288 if ( getenv("srcdir") )
289 /* we are in 'make check' */
290 remove( "cube_hexa8.med" );