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 2d :
25 maillé en 4 quadrangles reguliers
26 1 triangle et 1 polygone.
33 int main (int argc, char **argv)
37 char maa[MED_NAME_SIZE+1] = "poly2D";
38 char maadesc[MED_COMMENT_SIZE+1] = "Example de maillage non structure 2D avec 1 polygone";
57 char nomcoo[2*MED_SNAME_SIZE+1] = "x y ";
58 char unicoo[2*MED_SNAME_SIZE+1] = "cm cm ";
59 /* char nomnoe[19*MED_TAILLE_PNOM+1] = "nom1 nom2 nom3 nom4";*/
61 // med_int numnoe[11] = {1,2,3,4,5,6,7,8,9,10,11};
62 med_int nufano[11] = {0,0,0,0,0,0,0,0,0,0,0};
73 // char nomquad4[MED_TAILLE_PNOM*4+1] = "quad1 quad2 quad3 quad4 ";
74 // med_int numquad4[4] = {1,2,3,4};
75 med_int nufaquad4[4] = {-1,-1,0,0};
81 // char nomtria3[MED_TAILLE_PNOM+1] = "tria1 ";
82 // med_int numtria3[1] = {1};
83 med_int nufatria3[1] = {-2};
86 med_int nindexpoly = 2;
87 med_int indexpoly [2] = {
93 char nompoly[MED_TAILLE_PNOM+1] = "poly ";
94 // med_int numpoly[1] = {1};
95 med_int nufapoly[1] = {-3};
97 char nomfam[MED_NAME_SIZE+1];
99 //char attdesMED_TAILLE_DESC+1];
104 char gro[MED_LNAME_SIZE+1];
105 char dtunitp3[MED_LNAME_SIZE+1]="";
111 Some fields : 2 on nodes : one int and one double , one on cells : double
113 char champ1[MED_NAME_SIZE+1]="fieldnodeint" ;
114 char champ1_comp[MED_SNAME_SIZE+1]="comp1 " ;
115 char champ1_unit[MED_SNAME_SIZE+1]="M " ;
116 med_int fieldnodeint[9] = {1,1,3,2,2,3,4,4,5};
118 char champ2[MED_NAME_SIZE+1]="fieldnodedouble" ;
119 char champ2_comp[MED_SNAME_SIZE+1]="comp1 " ;
120 char champ2_unit[MED_SNAME_SIZE+1]="J " ;
121 med_float fieldnodedouble1[9] = {1.,3.,4.,1.,3.,4.,3.,2.,5.};
122 med_float fieldnodedouble2[9] = {1.,2.,2.,3.,3.,3.,4.,4.,5.};
124 char champ3[MED_NAME_SIZE+1]="fieldcelldouble" ;
125 char champ3_comp[MED_SNAME_SIZE*2+1]="comp1 comp2 " ;
126 char champ3_unit[MED_SNAME_SIZE*2+1]="M/S m/s " ;
127 med_float fieldcelldouble[4*2] = {0.,1.,1.,1.,1.,2.,2.,3.};
129 /***************************************************************************/
130 fid = MEDfileOpen("poly2D.med",MED_ACC_RDWR);
135 printf("MEDouvrir : %d\n",ret);
137 /***************************************************************************/
139 ret = MEDmeshCr(fid,maa,mdim,mdim,MED_UNSTRUCTURED_MESH,maadesc,dtunitp3,
140 MED_SORT_DTIT,MED_CARTESIAN,nomcoo,unicoo);
141 printf("MEDmaaCr : %d\n",ret);
143 ret = MEDunvCr(fid,maa);
144 printf("MEDunvCr : %d\n",ret);
146 /***************************************************************************/
148 ret = MEDmeshNodeCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,MED_FULL_INTERLACE,nnoe,coo);
149 MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,0,nnoe,nufano);
150 printf("MEDnoeudsEcr : %d\n",ret);
152 /* ecriture des mailles MED_QUAD4 :
155 - numeros (optionnel)
156 - numeros des familles */
158 ret = MEDmeshElementConnectivityWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,
159 MED_CELL,MED_QUAD4,MED_NODAL,MED_FULL_INTERLACE,
161 MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_QUAD4,nquad4,nufaquad4);
162 printf("MEDelementsEcr for quad : %d \n",ret);
164 /* ecriture des mailles MED_TRIA3 :
167 - numeros (optionnel)
168 - numeros des familles */
170 ret = MEDmeshElementConnectivityWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NO_DT,
171 MED_CELL,MED_TRIA3,MED_NODAL,MED_FULL_INTERLACE,
173 MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_CELL,MED_TRIA3,ntria3,nufatria3);
174 printf("MEDelementsEcr for tria : %d \n",ret);
176 /* ecriture des mailles MED_POLYGONE:
179 - numeros (optionnel)
180 - numeros des familles
181 Dans ce cas il n existe pas de routine globale (Warning !!)
185 ret = MEDpolygoneConnEcr(fid,maa,indexpoly,nindexpoly,poly,
187 printf("MEDpolygoneConnEcr: %d \n",ret);
190 MEDnomEcr(fid,maa,nompoly,npoly,MED_CELL,MED_POLYGONE);
191 printf("MEDnomEcr for poly : %d \n",ret);
194 MEDnumEcr(fid,maa,numpoly,npoly,MED_CELL,MED_POLYGONE);
195 printf("MEDnumEcr for poly : %d \n",ret);
198 MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT, MED_CELL,MED_POLYGONE, npoly,nufapoly);
199 printf("MEDfamEcr for poly : %d \n",ret);
202 /***************************************************************************/
203 /* ecriture des familles */
205 - toujours creer une famille de numero 0 ne comportant aucun attribut
206 ni groupe (famille de reference pour les noeuds ou les elements
207 qui ne sont rattaches a aucun groupe ni attribut)
208 - les numeros de familles de noeuds sont > 0
209 - les numeros de familles des elements sont < 0
210 - rien d'imposer sur les noms de familles
216 strcpy(nomfam,"FAMILLE_0");
218 ret = MEDfamilyCr(fid,maa,nomfam,numfam,0,gro);
220 printf("MEDfamCr : %d \n",ret);
223 - 2 familles d'elements de dimension (d)
224 en fait de face (-10)
229 strcpy(nomfam,"FAMILLE_CELL_");
230 sprintf(nomfam,"%s%d",nomfam,-numfam);
234 //strcpy(attdes,"description attribut");
235 strcpy(gro,"groupe0");
238 ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
239 printf("MEDfamCr : %d\n",ret);
242 strcpy(nomfam,"FAMILLE_CELL_");
243 sprintf(nomfam,"%s%d",nomfam,-numfam);
247 //strcpy(attdes,"description attribut");
248 strcpy(gro,"groupe0");
251 ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
252 printf("MEDfamCr : %d\n",ret);
255 strcpy(nomfam,"FAMILLE_CELL_");
256 sprintf(nomfam,"%s%d",nomfam,-numfam);
260 //strcpy(attdes,"description attribut");
261 strcpy(gro,"groupe0");
264 ret = MEDfamilyCr(fid,maa,nomfam,numfam,ngro,gro);
265 printf("MEDfamCr : %d\n",ret);
268 /***************************************************************************/
274 ret = MEDfieldCr(fid,champ1,MED_INT32,1,champ1_comp,champ1_unit,dtunitp3,maa);
275 printf("MEDchampCr : %d \n",ret);
277 ret = MEDfieldValueWr(fid, champ1,MED_NO_DT,MED_NO_IT,0.,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodeint);
279 printf("MEDchampEcr : %d \n",ret);
285 ret = MEDfieldCr(fid,champ2,MED_FLOAT64,1,champ2_comp,champ2_unit,dtunitp3,maa);
286 printf("MEDchampCr : %d \n",ret);
288 ret = MEDfieldValueWr(fid, champ2,1,MED_NO_IT,1.1 ,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble1);
289 printf("MEDchampEcr1 : %d \n",ret);
290 ret = MEDfieldValueWr(fid, champ2,2,MED_NO_IT,1.2 ,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble2);
291 printf("MEDchampEcr2 : %d \n",ret);
295 // on met champ2 sans pas de temps pour pouvoir le lire aussi par defaut !
298 ret = MEDfieldValueWr(fid, champ2,MED_NO_DT,MED_NO_IT,0. ,MED_NODE,0,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nnoe, (unsigned char *)fieldnodedouble1);
299 printf("MEDchampEcr : %d \n",ret);
304 ret = MEDfieldCr(fid,champ3,MED_FLOAT64,2,champ3_comp,champ3_unit,dtunitp3,maa);
305 printf("MEDchampCr : %d \n",ret);
307 ret = MEDfieldValueWr(fid, champ3,MED_NO_DT,MED_NO_IT,0.,MED_CELL,MED_QUAD4,MED_NO_INTERLACE,MED_ALL_CONSTITUENT,nquad4, (unsigned char *)fieldcelldouble);
308 printf("MEDchampEcr : %d \n",ret);
312 /***************************************************************************/
314 ret = MEDfermer(fid);
315 printf("MEDfermer : %d\n",ret);