int main (int argc, char **argv) { med_err _ret=0; med_idt _fid=0; med_geometry_type _geotype=MED_NONE; const char _elementname1[]="MED_BILLE"; /* med_int _elementdim1=3; */ /* const char _supportmeshname1[]="MED_BILLE_SUPPORT"; */ /* med_entity_type _entitytype1=MED_NODE; */ /* med_int _nnode1=1; */ /* med_int _ncell1=0; */ /* med_int _geocelltype1=MED_NONE; */ const char _varattname1_1[MED_NAME_SIZE+1]="MED_VFOO_ATR1_1"; /* const med_attribute_type _varatttype1_1=MED_ATT_INT; */ /* const med_int _ncomponent1_1=1; */ const med_int _varatrvalue1_1[3]={ 22 , 24, 25 }; /* const char _varattname1_2[MED_NAME_SIZE+1]="MED_VFOO_ATR1_2"; */ /* const med_attribute_type _varatttype1_2=MED_ATT_FLOAT64; */ /* const med_int _ncomponent1_2=2; */ const char _varattname1_3[MED_NAME_SIZE+1]="MED_VFOO_ATR1_3"; const med_attribute_type _varatttype1_3=MED_ATT_NAME; const med_int _ncomponent1_3=1; /*Ce qui suit est une seule chaine */ const char _varatrvalue1_3[3*MED_NAME_SIZE+1]= { "*--------------------------------1-----------------------------*" "*--------------------------------2-----------------------------*" "*--------------------------------3-----------------------------*" }; const char _meshname[]="maa1"; char _axisname[3*MED_SNAME_SIZE+1]=""; char _axisunit[3*MED_SNAME_SIZE+1]=""; strcat(_axisname,"x "); strcat(_axisname,"y "); strcat(_axisname,"z "); strcat(_axisunit,"cm "); strcat(_axisunit,"cm "); strcat(_axisunit,"cm "); const med_int _nentity = 3; const med_int _con[3]={ 2, 4 ,5}; /* (3 billes dont les centres sont les noeuds 2, 4 et 5 du maillage maa1 )*/ /* Ouverture en mode lecture du fichier Test_MEDstructuElement.med */ _fid = MEDfileOpen("current.med",MODE_ACCES); if (_fid < 0) { MESSAGE("Erreur à l'ouverture du fichier current.med"); return -1; } /* Creation du maillage "maa1" de type MED_UNSTRUCTURED_MESH et de dimension 3 */ if (MEDmeshCr(_fid,_meshname,3,3,MED_UNSTRUCTURED_MESH, "un premier maillage","s",MED_SORT_DTIT, MED_CARTESIAN,_axisname,_axisunit) < 0) { MESSAGE("Erreur a la creation du maillage maa1"); return -1; } _geotype = MEDstructElementGeotype(_fid,_elementname1); /* ecriture des connectivites des segments */ if ( MEDmeshElementConnectivityWr(_fid,_meshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT, MED_STRUCT_ELEMENT, _geotype, MED_NODAL, MED_FULL_INTERLACE, _nentity, _con) < 0 ) { MESSAGE("Impossible d'ecrire la connectivité des billes: "); return -1; } if (MEDmeshStructElementVarAttWr(_fid, _meshname, MED_NO_DT, MED_NO_IT, _geotype, _varattname1_1, _nentity, _varatrvalue1_1 ) < 0 ) { return -1; } if (MEDmeshStructElementVarAttWr(_fid, _meshname, MED_NO_DT, MED_NO_IT, _geotype, _varattname1_3, _nentity, _varatrvalue1_3 ) < 0 ) { return -1; } if ( MEDmeshComputationStepCr(_fid,_meshname,MED_NO_DT,MED_NO_IT, 1,MED_NO_IT,0.5) < 0) { fprintf(stderr,"Erreur a la creation du pas de temps du maillage %s\n",_meshname); return -1; } return _ret; }
int main (int argc, char **argv) { med_idt fid; const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh"; const med_int spacedim = 2; const med_int meshdim = 2; /* 12345678901234561234567890123456 */ const char axisname[2*MED_SNAME_SIZE+1] = "x y "; const char unitname[2*MED_SNAME_SIZE+1] = "cm cm "; const med_float coordinates[30] = { 2.,1., 7.,1., 12.,1., 17.,1., 22.,1., 2.,6., 7.,6., 12.,6., 17.,6., 22.,6., 2.,11., 7.,11., 12.,11., 17.,11., 22.,11.}; const med_int nnodes = 15; const med_int triaconnectivity[24] = { 1,7,6, 2,7,1, 3,7,2, 8,7,3, 13,7,8, 12,7,13, 11,7,12, 6,7,11 }; const med_int ntria3 = 8; const med_int quadconnectivity[16] = {3,4,9,8, 4,5,10,9, 15,14,9,10, 13,8,9,14}; const med_int nquad4 = 4; med_err ret=-1; /* open MED file */ fid = MEDfileOpen("UsesCase_MEDmesh_1.med",MED_ACC_CREAT); if (fid < 0) { MESSAGE("ERROR : file creation ..."); goto ERROR; } /* write a comment in the file */ if (MEDfileCommentWr(fid,"A 2D unstructured mesh : 15 nodes, 12 cells") < 0) { MESSAGE("ERROR : write file description ..."); goto ERROR; } /* mesh creation : a 2D unstructured mesh */ if (MEDmeshCr(fid, meshname, spacedim, meshdim, MED_UNSTRUCTURED_MESH, "A 2D unstructured mesh","",MED_SORT_DTIT,MED_CARTESIAN, axisname, unitname) < 0) { MESSAGE("ERROR : mesh creation ..."); goto ERROR; } /* nodes coordinates in a cartesian axis in full interlace mode (X1,Y1, X2,Y2, X3,Y3, ...) with no iteration and computation step */ if (MEDmeshNodeCoordinateWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0, MED_FULL_INTERLACE, nnodes, coordinates) < 0) { MESSAGE("ERROR : nodes coordinates ..."); goto ERROR; } /* cells connectiviy is defined in nodal mode with no iteration and computation step */ if (MEDmeshElementConnectivityWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_TRIA3, MED_NODAL, MED_FULL_INTERLACE, ntria3, triaconnectivity) < 0) { MESSAGE("ERROR : triangular cells connectivity ..."); goto ERROR; } if (MEDmeshElementConnectivityWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_QUAD4, MED_NODAL, MED_FULL_INTERLACE, nquad4, quadconnectivity) < 0) { MESSAGE("ERROR : quadrangular cells connectivity ..."); goto ERROR; } /* create family 0 : by default, all mesh entities family number is 0 */ if (MEDfamilyCr(fid, meshname,MED_NO_NAME, 0, 0, MED_NO_GROUP) < 0) { MESSAGE("ERROR : family 0 creation ..."); goto ERROR; } ret = 0; ERROR : /* close MED file */ if (MEDfileClose(fid) < 0) { MESSAGE("ERROR : close file ..."); return -1; } return ret; }
int main (int argc, char **argv) { int _i = 0; int _j = 0; med_idt _fid = 0; med_int _meshdim = 3; med_int _rmeshdim = 0; med_int _rspacedim = 0; med_int _n = 0; med_int _rnnoe = 0; med_int _rnse2 = 0; med_int _rnaxis = 0; const med_int _nnoe = 5; /* table des coordonnees (dimension * nombre de noeuds) */ med_float coo[5*3] = {0.0, 0.0, 0.0, 0.1 , 0.0, 0.0, 1.0, 0.0, 0.0, 1.1 , 0.0, 0.0, 2.0, 0.0, 0.0 }; med_float * _rcoo=NULL; med_int nse2 = 4; med_int se2[10] = {1,2, 2,3, 3,4, 4,5}; med_int * _rse2=NULL; const char _supportmeshname[]="SUPPORT_POUTRE"; char _axisname[3*MED_SNAME_SIZE+1]=""; char _axisunit[3*MED_SNAME_SIZE+1]=""; char _rsupportmeshname[MED_NAME_SIZE+1]=""; char _raxisname[3*MED_SNAME_SIZE+1]=""; char _raxisunit[3*MED_SNAME_SIZE+1]=""; char _rdescription[MED_COMMENT_SIZE+1]=""; med_axis_type _raxistype; med_bool _chgt=MED_FALSE,_trsf=MED_FALSE; strcat(_axisname,"x "); strcat(_axisname,"y "); strcat(_axisname,"z "); strcat(_axisunit,"cm "); strcat(_axisunit,"cm "); strcat(_axisunit,"cm "); /* ouverture du fichier */ if ((_fid = MEDfileOpen("current.med",MODE_ACCES)) < 0) { MESSAGE("Impossible de creer le fichier current.med"); return -1; } if (MEDsupportMeshCr( _fid, _supportmeshname, _meshdim, _meshdim,"Maillage support ED de type poutre", MED_CARTESIAN,_axisname, _axisname) < 0) { MESSAGE("Erreur a la creation du maillage support : "); SSCRUTE(_supportmeshname); return -1; } /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ if (MEDmeshNodeCoordinateWr(_fid,_supportmeshname,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, MED_FULL_INTERLACE, _nnoe, coo) < 0) { MESSAGE("Erreur a l'écriture des coordonnees des noeuds du maillage support"); return -1; } /* ecriture des connectivites des segments */ if ( MEDmeshElementConnectivityWr(_fid,_supportmeshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT, MED_CELL, MED_SEG2, MED_NODAL, MED_FULL_INTERLACE, nse2, se2) < 0 ) { MESSAGE("Impossible d'ecrire la connectivité des segments du maillage support : "); return -1; } if (MEDsupportMeshCr( _fid, "MED_BILLE_SUPPORT", _meshdim, _meshdim,"Maillage support ED de type bille", MED_CARTESIAN,_axisname, _axisname) < 0) { MESSAGE("Erreur a la creation du maillage support : "); SSCRUTE(_supportmeshname); return -1; } /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ if (MEDmeshNodeCoordinateWr(_fid,"MED_BILLE_SUPPORT",MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, MED_FULL_INTERLACE, 1, coo) < 0) { MESSAGE("Erreur a l'écriture des coordonnees des noeuds du maillage support : MED_BILLE_SUPPORT."); return -1; } if ( (_n =MEDnSupportMesh(_fid)) < 0 ) { MESSAGE("Erreur à la lecture du nombre de maillages supports : "); return -1; } for (_i=1; _i <= _n; ++_i) { if ( (_rnaxis = MEDsupportMeshnAxis(_fid, _i)) < 0) { MESSAGE("Erreur à la lecture du nombre d'axe du repère d'un maillage support : "); return -1; } printf("\t -Dimension de l'espace : %d\n",_rnaxis); if ( MEDsupportMeshInfo(_fid, _i , _rsupportmeshname, &_rspacedim, &_rmeshdim, _rdescription, &_raxistype, _raxisname, _raxisunit) < 0 ) { MESSAGE("Erreur à la lecture des informations sur le maillage support : "); SSCRUTE(_supportmeshname); return -1; } printf("Maillage support de nom : |%s| , de dimension : %d.\n",_rsupportmeshname, _rmeshdim); printf("\t -Dimension de l'espace : %d\n",_rspacedim); printf("\t -Description du maillage : %s\n",_rdescription); printf("\t -Noms des axes : %s\n",_raxisname); printf("\t -Unités des axes : %s\n",_raxisunit); /* Combien de noeuds a lire ? */ _rnnoe = MEDmeshnEntity(_fid,_rsupportmeshname,MED_NO_DT,MED_NO_IT, MED_NODE,MED_NONE,MED_COORDINATE,MED_NO_CMODE, &_chgt,&_trsf); if (_rnnoe < 0) { MESSAGE("Erreur a la lecture du nombre de noeuds. "); return -1; } else printf("Nombre de noeuds du maillage support: "IFORMAT" \n",_rnnoe); /* Allocations memoires */ if (_rnnoe > 0) { /* table des coordonnees (dimension * nombre de noeuds ) */ _rcoo = (med_float*) calloc(_rnnoe*_rspacedim,sizeof(med_float)); if ( MEDmeshNodeCoordinateRd(_fid, _rsupportmeshname, MED_NO_DT, MED_NO_IT,MED_FULL_INTERLACE, _rcoo) < 0 ) { MESSAGE("Erreur a la lecture des coordonnees des noeuds"); return -1; } else { printf("Valeur de _rcoo : "); for (_j=0;_j<_rnnoe*_rspacedim;_j++) printf("%4.2f ",_rcoo[_j]); printf("\n"); } free(_rcoo); } /* Combien de segments à lire ? */ _rnse2 = MEDmeshnEntity(_fid,_rsupportmeshname,MED_NO_DT,MED_NO_IT, MED_CELL,MED_SEG2,MED_CONNECTIVITY,MED_NODAL, &_chgt,&_trsf); if (_rnse2 < 0) { MESSAGE("Erreur a la lecture du nombre de segments."); return -1; } else printf("Nombre de segments du maillage support: "IFORMAT" \n",_rnse2); if (_rnse2 > 0) { /* table des connectivités (_rnse2 * nombre de noeuds ds un MED_SE2) */ _rse2 = (med_int*) calloc(_rnse2*2,sizeof(med_int)); if ( MEDmeshElementConnectivityRd(_fid, _rsupportmeshname, MED_NO_DT, MED_NO_IT, MED_CELL,MED_SEG2,MED_NODAL,MED_FULL_INTERLACE, _rse2) < 0 ) { MESSAGE("Erreur a la lecture des connectivités des segments"); return -1; } else { printf("Valeur de _rse2 : "); for (_j=0;_j<_rnse2*2;_j++) printf("%d ",_rse2[_j]); printf("\n"); } free(_rse2); } } return 0; }