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; const char axisname[2*MED_SNAME_SIZE+1] = "x y "; const char unitname[2*MED_SNAME_SIZE+1] = "cm cm "; const med_float initial_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; /* matrix transformation (step 1) : rotation about the Y-axis : 45 degrees */ const med_float tansfMatrix_step1 [7] = { 0.0, 0.0, 0.0, 0.92388, 0.0, 0.38268, 0.0 }; /* matrix transformation (step 2) : rotation about the Y-axis : 90 degrees */ const med_float tansfMatrix_step2 [7] = { 0.0, 0.0, 0.0, 0.707, 0.0, 0.707, 0.0 }; int ret=-1; /* open MED file */ fid = MEDfileOpen("UsesCase_MEDmesh_9.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 structured 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 (MEDmeshNodeCoordinateWithProfileWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0, MED_COMPACT_STMODE, MED_NO_PROFILE, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, nnodes, initial_coordinates) < 0) { MESSAGE("ERROR : nodes coordinates ..."); goto ERROR; } /* cells connectiviy is defined in nodal mode */ if (MEDmeshElementConnectivityWithProfileWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_TRIA3, MED_NODAL, MED_COMPACT_STMODE, MED_NO_PROFILE, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, ntria3, triaconnectivity) < 0) { MESSAGE("ERROR : triangular cells connectivity ..."); goto ERROR; } if (MEDmeshElementConnectivityWithProfileWr(fid, meshname, MED_NO_DT, MED_NO_IT, 0.0, MED_CELL, MED_QUAD4, MED_NODAL, MED_COMPACT_STMODE, MED_NO_PROFILE, MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, nquad4, quadconnectivity) < 0) { MESSAGE("ERROR : quadrangular cells connectivity ..."); goto ERROR; } /* * Mesh deformation (nodes coordinates) in 2 steps * A rotation by step for each node */ /* STEP 1 : dt1 = 5.5, it = 1*/ if ( MEDmeshNodeCoordinateTrsfWr(fid, meshname, 1, 1, 5.5, tansfMatrix_step1) < 0) { MESSAGE("Erreur a l'ecriture de la transformation géométrique n°1"); goto ERROR; } /* STEP 2 : dt2 = 8.9, it = 1*/ if ( MEDmeshNodeCoordinateTrsfWr(fid, meshname, 2, 2, 8.9, tansfMatrix_step2 ) < 0) { MESSAGE("Erreur a l'ecriture de la transformation géométrique n°1"); 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 : create family ..."); goto ERROR; } ret=0; ERROR: /* close MED file */ if (MEDfileClose(fid) < 0) { MESSAGE("ERROR : close file ..."); ret=-1; } return ret; }
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; }
med_err generateFieldFile( const med_size nentities, const med_size nvaluesperentity, const med_size nconstituentpervalue, const med_switch_mode constituentmode,GetBlocksOfEntitiesType getBlockOfEntities, const med_int nbblocksperproc, GenerateDataType generateDatas, const med_storage_mode storagemode, const med_size profilearraysize, const char * const fieldnameprefix, COM_info * const cominfo ) { /* static int _fileno=0; */ med_err _ret=-1; char _filename [255]=""; char _meshname[MED_NAME_SIZE+1]="Empty mesh"; med_int _meshdim=3; char _meshcomponentname[3*MED_SNAME_SIZE+1] = "x y z "; char _meshcomponentunit[3*MED_SNAME_SIZE+1] = "cm cm cm "; char _fieldname [MED_NAME_SIZE+1]=""; char *componentname,*componentunit; char _profilename[MED_NAME_SIZE+1]=MED_NO_PROFILE; med_int *_profilearray=0; int _i=0,_j=0,_k=0, _lastusedrank=0; med_size _blocksize=0,_lastblocksize=0,_count=0,_stride=0,_start=0,_index=0; med_float *_arrayvalues; med_filter filter = MED_FILTER_INIT; med_size _nusedentities = nentities; med_size _io_count = nbblocksperproc; med_idt _fidseq,_fid; MPI_Info info = cominfo->info; MPI_Comm comm = cominfo->comm; int mpi_size = cominfo->mpi_size; int mpi_rank = cominfo->mpi_rank; char *_MED_MODE_SWITCH_MSG[3]={"MED_FULL_INTERLACE", "MED_NO_INTERLACE","MED_UNDEF_INTERLACE",}; char *_MED_STORAGE_MODE_MSG[3]={"MED_NO_STMODE","MED_GLOBAL_STMODE", "MED_COMPACT_STMODE"}; med_geometry_type _geotype = MED_TRIA6; med_int _geodim = _geotype/100; med_int _geonnodes = _geotype%100; char _ipointname[MED_NAME_SIZE+1]; med_float* _ipointrefcoo = 0; med_int _ipoint = nvaluesperentity; med_float* _ipointcoo = 0; med_float* _ipointwg = 0; sprintf(_filename,"%s_CPU-%03d_@_%s_%s.med",fieldnameprefix,mpi_size,_MED_MODE_SWITCH_MSG[constituentmode],_MED_STORAGE_MODE_MSG[storagemode]); /* SSCRUTE(_filename); */ /* Ouverture du fichier en mode parallel */ if ((_fid = MEDparFileOpen(_filename, MODE_ACCES ,comm, info)) < 0){ MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,_filename); goto ERROR; } /* SSCRUTE(_meshname); */ if (MEDmeshCr( _fid,_meshname,_meshdim,_meshdim, MED_UNSTRUCTURED_MESH, "Un maillage pour le test parallel","s", MED_SORT_DTIT, MED_CARTESIAN, _meshcomponentname, _meshcomponentunit) < 0) { MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_MESH,_meshname); goto ERROR; }; componentname = (char*) malloc((nconstituentpervalue*MED_SNAME_SIZE+1)*sizeof(char)); componentunit = (char*) malloc((nconstituentpervalue*MED_SNAME_SIZE+1)*sizeof(char)); /*TODO : Compléter le nom */ strcpy(componentname,""); strcpy(componentunit,""); strcpy(_fieldname,fieldnameprefix); if ( MEDfieldCr(_fid,_fieldname,MED_FLOAT64,nconstituentpervalue,componentname,componentunit,"s",_meshname ) < 0) { MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FIELD,_fieldname); goto ERROR; }; free(componentname); free(componentunit); if ( _ipoint > 1 ) { MESSAGE("Creating a localization of integration points..."); strcpy(_ipointname,_fieldname); strcat(_ipointname,"_loc"); /*Attention ancienne spec*/ _ipointrefcoo = (med_float *) calloc(_geodim*_geonnodes,sizeof(med_float)); _ipointcoo = (med_float *) calloc(_ipoint*_geodim,sizeof(med_float)); _ipointwg = (med_float *) calloc(_ipoint,sizeof(med_float)); if (MEDlocalizationWr(_fid, _ipointname, _geotype, _geotype/100, _ipointrefcoo, constituentmode, _ipoint, _ipointcoo, _ipointwg, MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT ) < 0) { MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_LOCALIZATION,_ipointname); ISCRUTE_int(constituentmode); goto ERROR; } free(_ipointrefcoo ); free(_ipointcoo ); free(_ipointwg ); } else { strcpy(_ipointname,MED_NO_LOCALIZATION); } if (profilearraysize) { MESSAGE("Creating a profile..."); strcpy(_profilename,_fieldname);strcat(_profilename,"_profile"); _profilearray = (med_int*) calloc(profilearraysize,sizeof(med_int)); for (_i=0; _i < profilearraysize; ++_i) _profilearray[_i]=_i; if ( MEDprofileWr(_fid,_profilename,profilearraysize,_profilearray) < 0) { MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_PROFILE,_profilename); goto ERROR; }; _nusedentities = profilearraysize; } else { strcpy(_profilename,MED_NO_PROFILE); } MESSAGE("Generating partition..."); getBlockOfEntities ( mpi_rank , mpi_size, _nusedentities, &_start, &_stride, &_io_count, &_blocksize, &_lastusedrank, &_lastblocksize); _count=_io_count; MESSAGE("Generating filter..."); if ( MEDfilterBlockOfEntityCr(_fid, nentities, nvaluesperentity, nconstituentpervalue, MED_ALL_CONSTITUENT, constituentmode, storagemode, _profilename, _start,_stride,_count,_blocksize,_lastblocksize, &filter) < 0 ) { MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,""); goto ERROR; } MESSAGE("Generating datas..."); generateDatas(mpi_rank, _lastusedrank, sizeof(med_float), storagemode, profilearraysize, _profilearray, _start, _stride, _count, _blocksize, _lastblocksize, nentities, nvaluesperentity, nconstituentpervalue, &_arrayvalues ); MESSAGE("Writing field..."); if ( MEDfieldValueAdvancedWr(_fid,_fieldname,MED_NO_DT,MED_NO_IT,0.0, MED_CELL, _geotype, _ipointname, &filter, (unsigned char*)_arrayvalues ) < 0) { MED_ERR_(_ret,MED_ERR_WRITE,MED_ERR_FIELD,_fieldname); ISCRUTE(mpi_rank); goto ERROR; } /* Test de lecture du même fichier avec filtre simple par un seul processeur */ /* TODO : Créer MEDflush */ H5Fflush(_fid, H5F_SCOPE_GLOBAL ); /*Le flush suffit pas besoin de synchroniser les processus : MPI_Barrier(MPI_COMM_WORLD); */ if (mpi_rank == 0 ) { MESSAGE("Reading field..."); med_int _nentitiesarrayvalues=0; med_float *_filteredarrayvalues=NULL; med_filter filter2=MED_FILTER_INIT; int _ind=0; FILE * _asciifile; char _asciifilename[255]=""; if ((_fidseq = MEDfileOpen(_filename, MED_ACC_RDONLY )) < 0){ MED_ERR_(_ret,MED_ERR_OPEN,MED_ERR_FILE,_filename); goto ERROR; } sprintf(_asciifilename,"%s_CPU-%03d_@_%s_%s.ascii",fieldnameprefix,mpi_size,_MED_MODE_SWITCH_MSG[constituentmode],_MED_STORAGE_MODE_MSG[storagemode]); _asciifile=fopen(_asciifilename, "w"); /*Génère un filtre de selection simple s'il n'a pas déjà été généré lors d'un précédent appel */ /*TODO : Déplacer cette appel dans le main après avoir externaliser la génération du profile */ if (!(cominfo->filterarray)) if ( generateFilterArray( nentities, nvaluesperentity, nconstituentpervalue, profilearraysize, _profilearray, &(cominfo->nentitiesfiltered), &(cominfo->filterarray) ) < 0 ) { goto ERROR; } ISCRUTE(cominfo->nentitiesfiltered); /*Stocke le filtre utilisé dans le fichier .ascii*/ for (_i=0; _i < cominfo->nentitiesfiltered; ++_i ) { /* ISCRUTE(cominfo->filterarray[_i]); */ fprintf(_asciifile,"%d ",cominfo->filterarray[_i]) ; } fprintf(_asciifile,"\n") ; /*Pas de profile possible (profilearraysize == 0) en MED_GLOBAL_STMODE sur un fichier géré en parallel */ if ( profilearraysize ) { _nentitiesarrayvalues = profilearraysize; } else { _nentitiesarrayvalues = nentities; } /*Attention allocation mémoire potentiellement grosse car réalisée uniquement par le processus 0 qui rassemble les données.*/ /* C'est une taille maxi qui ne prend pas en compte le COMPACT+filter */ /* TODO : Ajuster la taille au storage_mode*/ _filteredarrayvalues = (med_float*) malloc(_nentitiesarrayvalues* nvaluesperentity* nconstituentpervalue*sizeof(med_float)); /* Permet de vérifier une erreur d'indiçage après la lecture */ for (_i=0;_i<_nentitiesarrayvalues*nvaluesperentity*nconstituentpervalue; ++_i) _filteredarrayvalues[_i]=-_i; /*Création d'un filtre de sélection simple, pour une lecture séquentielle par le processys 0*/ if ( MEDfilterEntityCr(_fidseq, nentities, nvaluesperentity, nconstituentpervalue, MED_ALL_CONSTITUENT, constituentmode, storagemode, _profilename, cominfo->nentitiesfiltered,cominfo->filterarray, &filter2) < 0 ) { MED_ERR_(_ret,MED_ERR_CREATE,MED_ERR_FILTER,""); goto ERROR; } if ( MEDfieldValueAdvancedRd(_fidseq,_fieldname,MED_NO_DT,MED_NO_IT, MED_CELL, _geotype, &filter2, (unsigned char*)_filteredarrayvalues ) < 0) { MED_ERR_(_ret,MED_ERR_READ,MED_ERR_FIELD,_fieldname); ISCRUTE(mpi_rank); goto ERROR; } /*AFFICHAGE TOUJOURS EN FULL INTERLACE QUELQUES SOIENT LES COMBINAISONS*/ /*TODO : Externaliser l'affichage*/ if ( storagemode == MED_GLOBAL_STMODE ) { switch (constituentmode) { case MED_FULL_INTERLACE: for (_i=0; _i < cominfo->nentitiesfiltered; ++_i) for (_j=0; _j < nvaluesperentity; ++_j) for (_k=0; _k < nconstituentpervalue; ++_k) { _ind = (cominfo->filterarray[_i]-1)*nvaluesperentity*nconstituentpervalue+ _j*nconstituentpervalue+_k; /* fprintf(stdout,"%s%3d%s = %f\n","_filteredarrayvaluesFULLGLB[",_ind,"]",_filteredarrayvalues[_ind]) ; */ fprintf(_asciifile,"%f\n",_filteredarrayvalues[_ind]) ; } break; case MED_NO_INTERLACE: for (_j=0; _j < cominfo->nentitiesfiltered; ++_j) for (_k=0; _k < nvaluesperentity; ++_k) for (_i=0; _i < nconstituentpervalue; ++_i) { _ind =_i*nentities*nvaluesperentity+ (cominfo->filterarray[_j]-1)*nvaluesperentity +_k; /* fprintf(stdout,"%s%3d%s = %f\n","_filteredarrayvaluesNOGLB[",_ind,"]",_filteredarrayvalues[_ind]); */ fprintf(_asciifile,"%f\n",_filteredarrayvalues[_ind]); } break; } } else switch (constituentmode) { case MED_FULL_INTERLACE: for (_i=0; _i < cominfo->nentitiesfiltered; ++_i ) for (_j=0; _j < nvaluesperentity; ++_j) for (_k=0; _k < nconstituentpervalue; ++_k) { _ind = _i*nvaluesperentity*nconstituentpervalue+_j*nconstituentpervalue+_k; /* fprintf(stdout,"%s%3d%s = %f\n","_filteredarrayvaluesFULLCP[",_ind,"]",_filteredarrayvalues[_ind]) ; */ fprintf(_asciifile,"%f\n",_filteredarrayvalues[_ind]) ; } break; case MED_NO_INTERLACE: for (_j=0; _j < cominfo->nentitiesfiltered; ++_j) for (_k=0; _k < nvaluesperentity; ++_k) for (_i=0; _i < nconstituentpervalue; ++_i) { _ind =_i*cominfo->nentitiesfiltered*nvaluesperentity+ _j*nvaluesperentity +_k; /* _ind =_i*_nentitiesarrayvalues*nvaluesperentity+ (_filterarray[_j]-1)*nvaluesperentity +_k; */ /* fprintf(stdout,"%s%3d%s = %f\n","_filteredarrayvaluesNOCP[",_ind,"]",_filteredarrayvalues[_ind]); */ fprintf(_asciifile,"%f\n",_filteredarrayvalues[_ind]); } break; } free(_filteredarrayvalues); fclose(_asciifile); if ( MEDfilterClose(&filter2) < 0 ) { MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,""); goto ERROR; } } /*fin if (mpi_rank == 0) */ if ( MEDfilterClose(&filter) < 0 ) { MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILTER,""); goto ERROR; } _ret=0; ERROR: if (_arrayvalues) free(_arrayvalues); if (profilearraysize) free(_profilearray); if ( MEDfileClose(_fid) < 0) { MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILE,""); _ret = -1; } if (mpi_rank == 0 ) { if ( MEDfileClose(_fidseq) < 0) { MED_ERR_(_ret,MED_ERR_CLOSE,MED_ERR_FILE,""); _ret = -1; } } return _ret; }
int main (int argc, char **argv) { med_err ret = 0; med_idt fid; /* la dimension du maillage */ med_int mdim = 2; /* nom du maillage de longueur maxi MED_NAME_SIZE */ char maa[MED_NAME_SIZE+1] = "maa1"; /* le nombre de noeuds */ med_int nnoe = 4; /* table des coordonnees (dimension * nombre de noeuds) */ med_float coo[8] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}; med_float coo_2[8] = {0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0}; /* tables des noms et des unites des coordonnees (dimension*MED_SNAME_SIZE+1) */ /* 12345678901234561234567890123456*/ char nomcoo[2*MED_SNAME_SIZE+1] = "x y "; char unicoo[2*MED_SNAME_SIZE+1] = "cm cm "; /* tables des noms, numeros, numeros de familles des noeuds autant d'elements que de noeuds - les noms ont pout longueur MED_SNAME_SIZE */ /* 1234567890123456123456789012345612345678901234561234567890123456*/ char nomnoe[4*MED_SNAME_SIZE+1] = "nom1 nom2 nom3 nom4 "; med_int numnoe[4] = {1,2,3,4}; med_int nufano[4] = {0,1,2,2}; const med_float phi1=0; const med_float phi2=M_PI_4; const med_float phi3=M_PI_2; med_float trsf1[7]= {0,0,0, cos(phi1/2), 0, sin(phi1/2), 0 }; med_float trsf2[7]= {0,0,0, cos(phi2/2), 0, sin(phi2/2), 0 }; med_float trsf3[7]= {0,0,0, cos(phi3/2), 0, sin(phi3/2), 0 }; /* ouverture du fichier */ if ((fid = MEDfileOpen("Test_MEDmeshNodeCoordinateTrsfWr.med",MODE_ACCES)) < 0){ MESSAGE("Erreur à l'ouverture du fichier : "); return -1; } /* Creation du maillage "maa" de type MED_NON_STRUCURE et de dimension 2 */ if (MEDmeshCr( fid, maa, mdim, mdim, MED_UNSTRUCTURED_MESH, "un maillage pour Test_MEDmeshNodeCoordinateTrsfWr","s", MED_SORT_DTIT, MED_CARTESIAN, nomcoo, unicoo) < 0) { MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa); ret = -1; } /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ if (MEDmeshNodeCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, MED_FULL_INTERLACE,nnoe, coo) < 0) { MESSAGE("Erreur a l'ecriture des coordonnees des noeuds"); ret = -1; } /* Ecriture des noms des noeuds (optionnel dans un maillage MED) */ if (MEDmeshEntityNameWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,nomnoe) < 0) { MESSAGE("Erreur a l'ecriture des noms des noeuds"); ret = -1; } /* Ecriture des numeros des noeuds (optionnel dans un maillage MED) */ if (MEDmeshEntityNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,numnoe) < 0) { MESSAGE("Erreur a l'ecriture des numeros des noeuds"); ret = -1; } /* Ecriture des numeros de famille des noeuds */ if (MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,nufano) < 0) { MESSAGE("Erreur a l'ecriture des numeros de familles des noeuds"); ret = -1; } /* Transformation des coordonnees des noeuds coo_1 : */ fprintf(stdout,"Un message d'erreur est attendu: \n"); if ( MEDmeshNodeCoordinateTrsfWr(fid,maa,MED_NO_DT,MED_NO_IT,0.4,trsf1) >= 0) { MESSAGE("Erreur a l'ecriture de la transformation géométrique n°1"); MESSAGE("Aucune transformation géométrique à la séquence de calcul MED_NO_DT,MED_NO_IT n'est possible."); } fprintf(stdout,"Fin du message d'erreur attendu\n :"); /* Transformation des coordonnees des noeuds coo_1 : */ if ( MEDmeshNodeCoordinateTrsfWr(fid,maa,1,1,0.4,trsf1) < 0) { MESSAGE("Erreur a l'ecriture de la transformation géométrique n°1"); ret = -1; } /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ fprintf(stdout,"Un message d'erreur est attendu : \n"); if (MEDmeshNodeCoordinateWr(fid,maa,1,1, 0.5, MED_FULL_INTERLACE,nnoe, coo_2) >= 0) { MESSAGE("Erreur a l'ecriture des coordonnees des noeuds"); MESSAGE("Aucune ecriture des coordonnees des noeuds n'est possible sur une séquence de calcul comportant "\ "une transformation géométrique."); } fprintf(stdout,"Fin du message d'erreur attendu :\n"); /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ if (MEDmeshNodeCoordinateWr(fid,maa,2,1, 0.5, MED_FULL_INTERLACE,nnoe, coo_2) < 0) { MESSAGE("Erreur a l'ecriture des coordonnees des noeuds"); ret = -1; } /* Transformation des coordonnees des noeuds coo_2 : */ fprintf(stdout,"Un message d'erreur est attendu\n :"); if ( MEDmeshNodeCoordinateTrsfWr(fid,maa,2,1,0.5,trsf2) >= 0) { MESSAGE("Erreur a l'ecriture de la transformation géométrique n°2"); MESSAGE("Aucune transformation géométrique à une séquence de calcul comportant de nouvelles coordonnées n'est possible."); } fprintf(stdout,"Fin du message d'erreur attendu\n :"); /* Transformation des coordonnees des noeuds coo_2 : */ if ( MEDmeshNodeCoordinateTrsfWr(fid,maa,2,2,0.6,trsf2) < 0) { MESSAGE("Erreur a l'ecriture de la transformation géométrique n°2"); ret = -1; } /* Transformation des coordonnees des noeuds coo_3 : */ if ( MEDmeshNodeCoordinateTrsfWr(fid,maa,3,2,0.7,trsf3) < 0) { MESSAGE("Erreur a l'ecriture de la transformation géométrique n°3"); ret = -1; } if ( MEDmeshComputationStepCr(fid,maa, 3,2, 3,3, 3.3) < 0) { MESSAGE("Erreur a la creation d'un pas de temps du maillage maa"); } /* Modification des numeros des noeuds (optionnel dans un maillage MED) */ numnoe[2]=200; if (MEDmeshEntityNumberWr(fid,maa,3,3,MED_NODE,MED_NONE,nnoe,numnoe) < 0) { MESSAGE("Erreur a l'ecriture des numeros des noeuds"); ret = -1; } if ( MEDmeshComputationStepCr(fid,maa, 3,3, 3,4, 3.4) < 0) { MESSAGE("Erreur a la creation d'un pas de temps du maillage maa"); } /*TODO : Ecrire un test de comparaison interne next prev et ordre de découverte itératif */ /* Fermeture du fichier */ if (MEDfileClose(fid) < 0) { MESSAGE("Erreur a la fermeture du fichier test4.med"); return -1; } return ret; }
void ecs_post_med__ajoute_maillage(const char *nom_maillage, const ecs_int_t dim_m, ecs_med_t *cas_med) { int ind; ecs_int_t lng_nom_maillage; ecs_med_maillage_t *maillage_med; char desc_maillage_med[MED_COMMENT_SIZE + 1] = ""; char dtunit[MED_LNAME_SIZE + 1] = "s"; char axisname[MED_SNAME_SIZE*3 + 1]; char axisunit[MED_SNAME_SIZE*3 + 1]; med_err ret_med = 0; /*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/ if (cas_med == NULL) return; /* Create MED file if not done yet */ if (cas_med->fid == 0) { cas_med->fid = MEDfileOpen(cas_med->nom_fic, MED_ACC_CREAT); if (cas_med->fid < 0) ecs_error(__FILE__, __LINE__, 0, _("MED: error opening file \"%s\"."), cas_med->nom_fic); printf(" %s %s\n", _("Creating file:"), cas_med->nom_fic); } /* Initialize strings */ for (ind = 0; ind < MED_COMMENT_SIZE; ind++) desc_maillage_med[ind] = ' '; desc_maillage_med[MED_COMMENT_SIZE] = '\0'; for (ind = 0; ind < MED_SNAME_SIZE*3; ind++) { axisname[ind] = ' '; axisunit[ind] = ' '; } axisname[0] = 'x'; axisname[MED_SNAME_SIZE] = 'y'; axisname[MED_SNAME_SIZE*2] = 'z'; axisname[MED_SNAME_SIZE*3] = '\0'; for (ind = 0; ind < 3; ind++) axisunit[ind * MED_SNAME_SIZE] = 'm'; axisunit[MED_SNAME_SIZE*3] = '\0'; /* Vérification que le maillage n'a pas déjà été défini */ for (ind = 0; ind < cas_med->nbr_maillages; ind++) { maillage_med = cas_med->tab_maillages[ind]; if (strcmp(nom_maillage, maillage_med->nom_maillage) == 0) ecs_error(__FILE__, __LINE__, 0, _("A mesh named: %s\n" "is already defined in MED case: %s\n"), nom_maillage, cas_med->nom_cas); } ECS_MALLOC(maillage_med, 1, ecs_med_maillage_t); lng_nom_maillage = strlen(nom_maillage); ECS_MALLOC(maillage_med->nom_maillage, lng_nom_maillage + 1, char); strcpy(maillage_med->nom_maillage, nom_maillage); strncpy(maillage_med->nom_maillage_med, nom_maillage, MED_NAME_SIZE); for (ind = 0; ind < lng_nom_maillage; ind++) { if (maillage_med->nom_maillage_med[ind] == ' ') maillage_med->nom_maillage_med[ind] = '_'; else maillage_med->nom_maillage_med[ind] = tolower(maillage_med->nom_maillage_med[ind]); } for (ind = lng_nom_maillage; ind < MED_NAME_SIZE; ind++) maillage_med->nom_maillage_med[ind] = '\0'; maillage_med->nom_maillage_med[MED_NAME_SIZE] = '\0'; cas_med->nbr_maillages += 1; ECS_REALLOC(cas_med->tab_maillages, cas_med->nbr_maillages, ecs_med_maillage_t *); cas_med->tab_maillages[cas_med->nbr_maillages - 1] = maillage_med; /* Initialisation du maillage */ ret_med = MEDmeshCr(cas_med->fid, maillage_med->nom_maillage_med, (med_int)3, (med_int)(dim_m), MED_UNSTRUCTURED_MESH, desc_maillage_med, dtunit, MED_SORT_DTIT, MED_CARTESIAN, axisname, axisunit); if (ret_med != 0) ecs_error(__FILE__, __LINE__, 0, _("MED: error writing file \"%s\".\n" "Name of mesh to create: \"%s\"\n"), cas_med->nom_fic, maillage_med->nom_maillage_med, (int)3); if (ret_med != 0) ecs_error(__FILE__, __LINE__, 0, _("MED: error writing file \"%s\".\n" "Mesh name: \"%s\"\n" "mesh dimension: \"%d\", space dimension: \"%d\""), cas_med->nom_fic, maillage_med->nom_maillage_med, (int)dim_m, 3); }
int GModel::readMED(const std::string &name) { med_idt fid = MEDouvrir((char*)name.c_str(), MED_LECTURE); if(fid < 0) { Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } med_int v[3], vf[3]; MEDversionDonner(&v[0], &v[1], &v[2]); MEDversionLire(fid, &vf[0], &vf[1], &vf[2]); Msg::Info("Reading MED file V%d.%d.%d using MED library V%d.%d.%d", vf[0], vf[1], vf[2], v[0], v[1], v[2]); if(vf[0] < 2 || (vf[0] == 2 && vf[1] < 2)){ Msg::Error("Cannot read MED file older than V2.2"); return 0; } std::vector<std::string> meshNames; for(int i = 0; i < MEDnMaa(fid); i++){ char meshName[MED_TAILLE_NOM + 1], meshDesc[MED_TAILLE_DESC + 1]; med_int spaceDim; med_maillage meshType; #if (MED_MAJOR_NUM == 3) med_int meshDim, nStep; char dtUnit[MED_SNAME_SIZE + 1]; char axisName[3 * MED_SNAME_SIZE + 1], axisUnit[3 * MED_SNAME_SIZE + 1]; med_sorting_type sortingType; med_axis_type axisType; if(MEDmeshInfo(fid, i + 1, meshName, &spaceDim, &meshDim, &meshType, meshDesc, dtUnit, &sortingType, &nStep, &axisType, axisName, axisUnit) < 0){ #else if(MEDmaaInfo(fid, i + 1, meshName, &spaceDim, &meshType, meshDesc) < 0){ #endif Msg::Error("Unable to read mesh information"); return 0; } meshNames.push_back(meshName); } if(MEDfermer(fid) < 0){ Msg::Error("Unable to close file '%s'", (char*)name.c_str()); return 0; } int ret = 1; for(unsigned int i = 0; i < meshNames.size(); i++){ // we use the filename as a kind of "partition" indicator, allowing to // complete a model part by part (used e.g. in DDM, since MED does not store // a partition index) GModel *m = findByName(meshNames[i], name); if(!m) m = new GModel(meshNames[i]); ret = m->readMED(name, i); if(!ret) return 0; } return ret; } int GModel::readMED(const std::string &name, int meshIndex) { med_idt fid = MEDouvrir((char*)name.c_str(), MED_LECTURE); if(fid < 0){ Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } int numMeshes = MEDnMaa(fid); if(meshIndex >= numMeshes){ Msg::Info("Could not find mesh %d in MED file", meshIndex); return 0; } checkPointMaxNumbers(); GModel::setCurrent(this); // make sure we increment max nums in this model // read mesh info char meshName[MED_TAILLE_NOM + 1], meshDesc[MED_TAILLE_DESC + 1]; med_int spaceDim, nStep = 1; med_maillage meshType; #if (MED_MAJOR_NUM == 3) med_int meshDim; char dtUnit[MED_SNAME_SIZE + 1]; char axisName[3 * MED_SNAME_SIZE + 1], axisUnit[3 * MED_SNAME_SIZE + 1]; med_sorting_type sortingType; med_axis_type axisType; if(MEDmeshInfo(fid, meshIndex + 1, meshName, &spaceDim, &meshDim, &meshType, meshDesc, dtUnit, &sortingType, &nStep, &axisType, axisName, axisUnit) < 0){ #else if(MEDmaaInfo(fid, meshIndex + 1, meshName, &spaceDim, &meshType, meshDesc) < 0){ #endif Msg::Error("Unable to read mesh information"); return 0; } // FIXME: we should support multi-step MED3 meshes (probably by // storing each mesh as a separate model, with a naming convention // e.g. meshName_step%d). This way we could also handle multi-mesh // time sequences in MED3. if(nStep > 1) Msg::Warning("Discarding %d last meshes in multi-step MED mesh", nStep - 1); setName(meshName); setFileName(name); if(meshType == MED_NON_STRUCTURE){ Msg::Info("Reading %d-D unstructured mesh <<%s>>", spaceDim, meshName); } else{ Msg::Error("Reading structured MED meshes is not supported"); return 0; } med_int vf[3]; MEDversionLire(fid, &vf[0], &vf[1], &vf[2]); // read nodes #if (MED_MAJOR_NUM == 3) med_bool changeOfCoord, geoTransform; med_int numNodes = MEDmeshnEntity(fid, meshName, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NO_GEOTYPE, MED_COORDINATE, MED_NO_CMODE, &changeOfCoord, &geoTransform); #else med_int numNodes = MEDnEntMaa(fid, meshName, MED_COOR, MED_NOEUD, MED_NONE, MED_NOD); #endif if(numNodes < 0){ Msg::Error("Could not read number of MED nodes"); return 0; } if(numNodes == 0){ Msg::Error("No nodes in MED mesh"); return 0; } std::vector<MVertex*> verts(numNodes); std::vector<med_float> coord(spaceDim * numNodes); #if (MED_MAJOR_NUM == 3) if(MEDmeshNodeCoordinateRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_FULL_INTERLACE, &coord[0]) < 0){ #else std::vector<char> coordName(spaceDim * MED_TAILLE_PNOM + 1); std::vector<char> coordUnit(spaceDim * MED_TAILLE_PNOM + 1); med_repere rep; if(MEDcoordLire(fid, meshName, spaceDim, &coord[0], MED_FULL_INTERLACE, MED_ALL, 0, 0, &rep, &coordName[0], &coordUnit[0]) < 0){ #endif Msg::Error("Could not read MED node coordinates"); return 0; } std::vector<med_int> nodeTags(numNodes); #if (MED_MAJOR_NUM == 3) if(MEDmeshEntityNumberRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_NODE, MED_NO_GEOTYPE, &nodeTags[0]) < 0) #else if(MEDnumLire(fid, meshName, &nodeTags[0], numNodes, MED_NOEUD, MED_NONE) < 0) #endif nodeTags.clear(); for(int i = 0; i < numNodes; i++) verts[i] = new MVertex(coord[spaceDim * i], (spaceDim > 1) ? coord[spaceDim * i + 1] : 0., (spaceDim > 2) ? coord[spaceDim * i + 2] : 0., 0, nodeTags.empty() ? 0 : nodeTags[i]); // read elements (loop over all possible MSH element types) for(int mshType = 0; mshType < MSH_NUM_TYPE; mshType++){ med_geometrie_element type = msh2medElementType(mshType); if(type == MED_NONE) continue; #if (MED_MAJOR_NUM == 3) med_bool changeOfCoord; med_bool geoTransform; med_int numEle = MEDmeshnEntity(fid, meshName, MED_NO_DT, MED_NO_IT, MED_CELL, type, MED_CONNECTIVITY, MED_NODAL, &changeOfCoord, &geoTransform); #else med_int numEle = MEDnEntMaa(fid, meshName, MED_CONN, MED_MAILLE, type, MED_NOD); #endif if(numEle <= 0) continue; int numNodPerEle = type % 100; std::vector<med_int> conn(numEle * numNodPerEle); #if (MED_MAJOR_NUM == 3) if(MEDmeshElementConnectivityRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_CELL, type, MED_NODAL, MED_FULL_INTERLACE, &conn[0]) < 0){ #else if(MEDconnLire(fid, meshName, spaceDim, &conn[0], MED_FULL_INTERLACE, 0, MED_ALL, MED_MAILLE, type, MED_NOD) < 0){ #endif Msg::Error("Could not read MED elements"); return 0; } std::vector<med_int> fam(numEle, 0); #if (MED_MAJOR_NUM == 3) if(MEDmeshEntityFamilyNumberRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_CELL, type, &fam[0]) < 0){ #else if(MEDfamLire(fid, meshName, &fam[0], numEle, MED_MAILLE, type) < 0){ #endif Msg::Info("No family number for elements: using 0 as default family number"); } std::vector<med_int> eleTags(numEle); #if (MED_MAJOR_NUM == 3) if(MEDmeshEntityNumberRd(fid, meshName, MED_NO_DT, MED_NO_IT, MED_CELL, type, &eleTags[0]) < 0) #else if(MEDnumLire(fid, meshName, &eleTags[0], numEle, MED_MAILLE, type) < 0) #endif eleTags.clear(); std::map<int, std::vector<MElement*> > elements; MElementFactory factory; for(int j = 0; j < numEle; j++){ std::vector<MVertex*> v(numNodPerEle); for(int k = 0; k < numNodPerEle; k++) v[k] = verts[conn[numNodPerEle * j + med2mshNodeIndex(type, k)] - 1]; MElement *e = factory.create(mshType, v, eleTags.empty() ? 0 : eleTags[j]); if(e) elements[-fam[j]].push_back(e); } _storeElementsInEntities(elements); } _associateEntityWithMeshVertices(); _storeVerticesInEntities(verts); // read family info med_int numFamilies = MEDnFam(fid, meshName); if(numFamilies < 0){ Msg::Error("Could not read MED families"); return 0; } for(int i = 0; i < numFamilies; i++){ #if (MED_MAJOR_NUM == 3) med_int numAttrib = (vf[0] == 2) ? MEDnFamily23Attribute(fid, meshName, i + 1) : 0; med_int numGroups = MEDnFamilyGroup(fid, meshName, i + 1); #else med_int numAttrib = MEDnAttribut(fid, meshName, i + 1); med_int numGroups = MEDnGroupe(fid, meshName, i + 1); #endif if(numAttrib < 0 || numGroups < 0){ Msg::Error("Could not read MED groups or attributes"); return 0; } std::vector<med_int> attribId(numAttrib + 1); std::vector<med_int> attribVal(numAttrib + 1); std::vector<char> attribDes(MED_TAILLE_DESC * numAttrib + 1); std::vector<char> groupNames(MED_TAILLE_LNOM * numGroups + 1); char familyName[MED_TAILLE_NOM + 1]; med_int familyNum; #if (MED_MAJOR_NUM == 3) if(vf[0] == 2){ // MED2 file if(MEDfamily23Info(fid, meshName, i + 1, familyName, &attribId[0], &attribVal[0], &attribDes[0], &familyNum, &groupNames[0]) < 0){ Msg::Error("Could not read info for MED2 family %d", i + 1); continue; } } else{ if(MEDfamilyInfo(fid, meshName, i + 1, familyName, &familyNum, &groupNames[0]) < 0){ Msg::Error("Could not read info for MED3 family %d", i + 1); continue; } } #else if(MEDfamInfo(fid, meshName, i + 1, familyName, &familyNum, &attribId[0], &attribVal[0], &attribDes[0], &numAttrib, &groupNames[0], &numGroups) < 0){ Msg::Error("Could not read info for MED family %d", i + 1); continue; } #endif // family tags are unique (for all dimensions) GEntity *ge; if((ge = getRegionByTag(-familyNum))){} else if((ge = getFaceByTag(-familyNum))){} else if((ge = getEdgeByTag(-familyNum))){} else ge = getVertexByTag(-familyNum); if(ge){ elementaryNames[std::pair<int, int>(ge->dim(), -familyNum)] = familyName; if(numGroups > 0){ for(int j = 0; j < numGroups; j++){ char tmp[MED_TAILLE_LNOM + 1]; strncpy(tmp, &groupNames[j * MED_TAILLE_LNOM], MED_TAILLE_LNOM); tmp[MED_TAILLE_LNOM] = '\0'; // don't use same physical number across dimensions, as e.g. getdp // does not support this int pnum = setPhysicalName(tmp, ge->dim(), getMaxPhysicalNumber(-1) + 1); if(std::find(ge->physicals.begin(), ge->physicals.end(), pnum) == ge->physicals.end()) ge->physicals.push_back(pnum); } } } } // check if we need to read some post-processing data later #if (MED_MAJOR_NUM == 3) bool postpro = (MEDnField(fid) > 0) ? true : false; #else bool postpro = (MEDnChamp(fid, 0) > 0) ? true : false; #endif if(MEDfermer(fid) < 0){ Msg::Error("Unable to close file '%s'", (char*)name.c_str()); return 0; } return postpro ? 2 : 1; } template<class T> static void fillElementsMED(med_int family, std::vector<T*> &elements, std::vector<med_int> &conn, std::vector<med_int> &fam, med_geometrie_element &type) { if(elements.empty()) return; type = msh2medElementType(elements[0]->getTypeForMSH()); if(type == MED_NONE){ Msg::Warning("Unsupported element type in MED format"); return; } for(unsigned int i = 0; i < elements.size(); i++){ elements[i]->setVolumePositive(); for(int j = 0; j < elements[i]->getNumVertices(); j++) conn.push_back(elements[i]->getVertex(med2mshNodeIndex(type, j))->getIndex()); fam.push_back(family); } } static void writeElementsMED(med_idt &fid, char *meshName, std::vector<med_int> &conn, std::vector<med_int> &fam, med_geometrie_element type) { if(fam.empty()) return; #if (MED_MAJOR_NUM == 3) if(MEDmeshElementWr(fid, meshName, MED_NO_DT, MED_NO_IT, 0., MED_CELL, type, MED_NODAL, MED_FULL_INTERLACE, (med_int)fam.size(), &conn[0], MED_FALSE, 0, MED_FALSE, 0, MED_TRUE, &fam[0]) < 0) #else if(MEDelementsEcr(fid, meshName, (med_int)3, &conn[0], MED_FULL_INTERLACE, 0, MED_FAUX, 0, MED_FAUX, &fam[0], (med_int)fam.size(), MED_MAILLE, type, MED_NOD) < 0) #endif Msg::Error("Could not write MED elements"); } int GModel::writeMED(const std::string &name, bool saveAll, double scalingFactor) { med_idt fid = MEDouvrir((char*)name.c_str(), MED_CREATION); if(fid < 0){ Msg::Error("Unable to open file '%s'", name.c_str()); return 0; } // write header if(MEDfichDesEcr(fid, (char*)"MED file generated by Gmsh") < 0){ Msg::Error("Unable to write MED descriptor"); return 0; } char *meshName = (char*)getName().c_str(); // Gmsh always writes 3D unstructured meshes #if (MED_MAJOR_NUM == 3) char dtUnit[MED_SNAME_SIZE + 1] = ""; char axisName[3 * MED_SNAME_SIZE + 1] = ""; char axisUnit[3 * MED_SNAME_SIZE + 1] = ""; if(MEDmeshCr(fid, meshName, 3, 3, MED_UNSTRUCTURED_MESH, "Mesh created with Gmsh", dtUnit, MED_SORT_DTIT, MED_CARTESIAN, axisName, axisUnit) < 0){ #else if(MEDmaaCr(fid, meshName, 3, MED_NON_STRUCTURE, (char*)"Mesh created with Gmsh") < 0){ #endif Msg::Error("Could not create MED mesh"); return 0; } // if there are no physicals we save all the elements if(noPhysicalGroups()) saveAll = true; // index the vertices we save in a continuous sequence (MED // connectivity is given in terms of vertex indices) indexMeshVertices(saveAll); // get a vector containing all the geometrical entities in the // model (the ordering of the entities must be the same as the one // used during the indexing of the vertices) std::vector<GEntity*> entities; getEntities(entities); std::map<GEntity*, int> families; // write the families { // always create a "0" family, with no groups or attributes #if (MED_MAJOR_NUM == 3) if(MEDfamilyCr(fid, meshName, "F_0", 0, 0, "") < 0) #else if(MEDfamCr(fid, meshName, (char*)"F_0", 0, 0, 0, 0, 0, 0, 0) < 0) #endif Msg::Error("Could not create MED family 0"); // create one family per elementary entity, with one group per // physical entity and no attributes for(unsigned int i = 0; i < entities.size(); i++){ if(saveAll || entities[i]->physicals.size()){ int num = - ((int)families.size() + 1); families[entities[i]] = num; std::ostringstream fs; fs << entities[i]->dim() << "D_" << entities[i]->tag(); std::string familyName = "F_" + fs.str(); std::string groupName; for(unsigned j = 0; j < entities[i]->physicals.size(); j++){ std::string tmp = getPhysicalName (entities[i]->dim(), entities[i]->physicals[j]); if(tmp.empty()){ // create unique name std::ostringstream gs; gs << entities[i]->dim() << "D_" << entities[i]->physicals[j]; groupName += "G_" + gs.str(); } else groupName += tmp; groupName.resize((j + 1) * MED_TAILLE_LNOM, ' '); } #if (MED_MAJOR_NUM == 3) if(MEDfamilyCr(fid, meshName, familyName.c_str(), (med_int)num, (med_int)entities[i]->physicals.size(), groupName.c_str()) < 0) #else if(MEDfamCr(fid, meshName, (char*)familyName.c_str(), (med_int)num, 0, 0, 0, 0, (char*)groupName.c_str(), (med_int)entities[i]->physicals.size()) < 0) #endif Msg::Error("Could not create MED family %d", num); } } } // write the nodes { std::vector<med_float> coord; std::vector<med_int> fam; for(unsigned int i = 0; i < entities.size(); i++){ for(unsigned int j = 0; j < entities[i]->mesh_vertices.size(); j++){ MVertex *v = entities[i]->mesh_vertices[j]; if(v->getIndex() >= 0){ coord.push_back(v->x() * scalingFactor); coord.push_back(v->y() * scalingFactor); coord.push_back(v->z() * scalingFactor); fam.push_back(0); // we never create node families } } } if(fam.empty()){ Msg::Error("No nodes to write in MED mesh"); return 0; } #if (MED_MAJOR_NUM == 3) if(MEDmeshNodeWr(fid, meshName, MED_NO_DT, MED_NO_IT, 0., MED_FULL_INTERLACE, (med_int)fam.size(), &coord[0], MED_FALSE, "", MED_FALSE, 0, MED_TRUE, &fam[0]) < 0) #else char coordName[3 * MED_TAILLE_PNOM + 1] = "x y z "; char coordUnit[3 * MED_TAILLE_PNOM + 1] = "unknown unknown unknown "; if(MEDnoeudsEcr(fid, meshName, (med_int)3, &coord[0], MED_FULL_INTERLACE, MED_CART, coordName, coordUnit, 0, MED_FAUX, 0, MED_FAUX, &fam[0], (med_int)fam.size()) < 0) #endif Msg::Error("Could not write nodes"); } // write the elements { { // points med_geometrie_element typ = MED_NONE; std::vector<med_int> conn, fam; for(viter it = firstVertex(); it != lastVertex(); it++) if(saveAll || (*it)->physicals.size()) fillElementsMED(families[*it], (*it)->points, conn, fam, typ); writeElementsMED(fid, meshName, conn, fam, typ); } { // lines med_geometrie_element typ = MED_NONE; std::vector<med_int> conn, fam; for(eiter it = firstEdge(); it != lastEdge(); it++) if(saveAll || (*it)->physicals.size()) fillElementsMED(families[*it], (*it)->lines, conn, fam, typ); writeElementsMED(fid, meshName, conn, fam, typ); } { // triangles med_geometrie_element typ = MED_NONE; std::vector<med_int> conn, fam; for(fiter it = firstFace(); it != lastFace(); it++) if(saveAll || (*it)->physicals.size()) fillElementsMED(families[*it], (*it)->triangles, conn, fam, typ); writeElementsMED(fid, meshName, conn, fam, typ); } { // quads med_geometrie_element typ = MED_NONE; std::vector<med_int> conn, fam; for(fiter it = firstFace(); it != lastFace(); it++) if(saveAll || (*it)->physicals.size()) fillElementsMED(families[*it], (*it)->quadrangles, conn, fam, typ); writeElementsMED(fid, meshName, conn, fam, typ); } { // tets med_geometrie_element typ = MED_NONE; std::vector<med_int> conn, fam; for(riter it = firstRegion(); it != lastRegion(); it++) if(saveAll || (*it)->physicals.size()) fillElementsMED(families[*it], (*it)->tetrahedra, conn, fam, typ); writeElementsMED(fid, meshName, conn, fam, typ); } { // hexas med_geometrie_element typ = MED_NONE; std::vector<med_int> conn, fam; for(riter it = firstRegion(); it != lastRegion(); it++) if(saveAll || (*it)->physicals.size()) fillElementsMED(families[*it], (*it)->hexahedra, conn, fam, typ); writeElementsMED(fid, meshName, conn, fam, typ); } { // prisms med_geometrie_element typ = MED_NONE; std::vector<med_int> conn, fam; for(riter it = firstRegion(); it != lastRegion(); it++) if(saveAll || (*it)->physicals.size()) fillElementsMED(families[*it], (*it)->prisms, conn, fam, typ); writeElementsMED(fid, meshName, conn, fam, typ); } { // pyramids med_geometrie_element typ = MED_NONE; std::vector<med_int> conn, fam; for(riter it = firstRegion(); it != lastRegion(); it++) if(saveAll || (*it)->physicals.size()) fillElementsMED(families[*it], (*it)->pyramids, conn, fam, typ); writeElementsMED(fid, meshName, conn, fam, typ); } } if(MEDfermer(fid) < 0){ Msg::Error("Unable to close file '%s'", (char*)name.c_str()); return 0; } return 1; } #else int GModel::readMED(const std::string &name) { Msg::Error("Gmsh must be compiled with MED support to read '%s'", name.c_str()); return 0; }
int main (int argc, char **argv) /*TODO : Tester l'écriture des attributs famille,numéros optionnels, noms optionnels*/ { med_idt fid=0; med_int mdim=2,axe=0,nind=0; med_float indiceX[4] = {1.0,1.1,1.2,1.3}; med_float indiceY[4] = {2.0,2.1,2.2,2.3}; med_float coo[8] = {0.0,0.0,1.0,0.0,0.0,1.0,1.0,1.0}; med_int nnoeuds = 4; med_int structure_grille[2] = {2,2}; char maa [MED_NAME_SIZE+1]= "grille_cartesian"; char maa2[MED_NAME_SIZE+1]= "grille_curvilinear"; /* composantes et unites */ /* 12345678901234561234567890123456 */ char comp[2*MED_SNAME_SIZE+1] = "X Y "; char unit[2*MED_SNAME_SIZE+1] = "cm cm "; /* Creation du fichier test27.med */ fid = MEDfileOpen("test27.med",MODE_ACCES); if (fid < 0) { MESSAGE("Erreur a la creation du fichier test27.med"); return -1; } printf("Creation du fichier test27.med \n"); /* Creation du maillage "maa" de type MED_NON_STRUCURE et de dimension 2 */ if (MEDmeshCr( fid, "maillage vide",2, 2, MED_UNSTRUCTURED_MESH, "un maillage vide","s", MED_SORT_DTIT, MED_CARTESIAN, comp, unit) < 0) { MESSAGE("Erreur a la creation du maillage MED_UNSTRUCTURED_MESH : "); SSCRUTE(maa); return -1; } /* creation d'une grille cartesienne de dimension 2 */ /* on commence par definir un maillage MED_STRUCTURED_MESH de dimension 2 */ if (MEDmeshCr( fid, maa,mdim, mdim, MED_STRUCTURED_MESH, "un exemple de grille cartesienne","s", MED_SORT_DTIT, MED_CARTESIAN, comp, unit) < 0) { MESSAGE("Erreur a la creation de la grille"); return -1; } printf("Creation d'un maillage structure MED_STRUCTURED_MESH \n"); /* On specifie la nature du maillage structure : MED_GRILLE_CARTESIENNE */ if (MEDmeshGridTypeWr(fid,maa, MED_CARTESIAN_GRID) < 0) { MESSAGE("Erreur a l'ecriture de la nature de la grille"); return -1; } printf("On definit la nature du maillage structure : MED_GRILLE_CARTESIENNE \n"); /* on definit les indices des coordonnees de la grille selon chaque dimension */ /* axe des "X" */ nind = 4; axe = 1; if (MEDmeshGridIndexCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, axe,nind,indiceX) < 0) { MESSAGE("Erreur a l'ecriture de l'axe X"); return -1; } printf("Ecriture des indices des coordonnees selon l'axe des X \n"); /* axe des "Y" */ nind = 4; axe = 2; if (MEDmeshGridIndexCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, axe,nind,indiceY) < 0) { MESSAGE("Erreur a l'ecriture de l'axe Y"); return -1; } printf("Ecriture des indices des coordonnees selon l'axe des Y \n"); /* Creation d'une grille MED_CURVILINEAR_GRID de dimension 2 */ /* on commence par definir un maillage MED_STRUCTURED_MESH de dimension 2 */ if (MEDmeshCr( fid, maa2,mdim, mdim, MED_STRUCTURED_MESH, "un exemple de grille standard","s", MED_SORT_DTIT, MED_CARTESIAN, comp, unit) < 0) { MESSAGE("Erreur a la creation de la 2e grille"); return -1; } printf("Creation d'un maillage structure MED_STRUCTURED_MESH \n"); /* On specifie la nature du maillage structure : MED_CURVILINEAR_GRID */ if (MEDmeshGridTypeWr(fid,maa2, MED_CURVILINEAR_GRID) < 0) { MESSAGE("Erreur a l'ecriture de la nature de la grille"); return -1; } printf("On definit la nature du maillage structure : MED_CURVILINEAR_GRID \n"); if (MEDmeshNodeCoordinateWr(fid,maa2,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, MED_FULL_INTERLACE,nnoeuds, coo) < 0) { MESSAGE("Erreur a l'ecriture des noeuds de la grille MED_CURVILINEAR_GRID"); return -1; } printf("Ecriture des coordonnees des noeuds \n"); /* On definit la structure de la grille */ if ( MEDmeshGridStructWr(fid,maa2,MED_NO_DT,MED_NO_IT, MED_UNDEF_DT, structure_grille ) < 0) { MESSAGE("Erreur a l'ecriture de la structure de la grille"); return -1; } printf("Ecriture de la structure de la grille : / 2,2 / \n"); /* On ferme le fichier */ if (MEDfileClose(fid) < 0) { MESSAGE("Erreur a la fermeture du fichier"); return -1; } printf("Fermeture du fichier \n"); return 0; }
int main (int argc, char **argv) { med_err ret = 0; med_idt fid; /* la dimension du maillage */ med_int mdim = 2; /* nom du maillage de longueur maxi MED_NAME_SIZE */ char maa[MED_NAME_SIZE+1] = "maa1"; /* le nombre de noeuds */ med_int nnoe = 4; /* table des coordonnees (dimension * nombre de noeuds) */ med_float coo[8] = {0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0}; med_float coo_2[8] = {0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0}; /* tables des noms et des unites des coordonnees (dimension*MED_SNAME_SIZE+1) */ /* 12345678901234561234567890123456*/ char nomcoo[2*MED_SNAME_SIZE+1] = "x y "; char unicoo[2*MED_SNAME_SIZE+1] = "cm cm "; /* tables des noms, numeros, numeros de familles des noeuds autant d'elements que de noeuds - les noms ont pout longueur MED_SNAME_SIZE */ /* 1234567890123456123456789012345612345678901234561234567890123456*/ char nomnoe[4*MED_SNAME_SIZE+1] = "nom1 nom2 nom3 nom4 "; med_int numnoe[4] = {1,2,3,4}; med_int nufano[4] = {0,1,2,2}; /* Creation du fichier "test4.med" */ /* ouverture du fichier */ if ((fid = MEDfileOpen("test4.med",MODE_ACCES)) < 0){ MESSAGE("Erreur à l'ouverture du fichier : "); return -1; } /* Creation du maillage "maa" de type MED_NON_STRUCURE et de dimension 2 */ if (MEDmeshCr( fid, maa, mdim, mdim, MED_UNSTRUCTURED_MESH, "un maillage pour test4","s", MED_SORT_DTIT, MED_CARTESIAN, nomcoo, unicoo) < 0) { MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa); ret = -1; } /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ if (MEDmeshNodeCoordinateWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, MED_FULL_INTERLACE,nnoe, coo) < 0) { MESSAGE("Erreur a l'ecriture des coordonnees des noeuds"); ret = -1; } /* Ecriture des attributs des noeuds du maillage */ if (MEDmeshAttributeWr(fid,maa, 0, nnoe, 0) < 0 ) { MESSAGE("Erreur a l'ecriture des attributs des noeuds du maillage"); ret = -1; } /* Ecriture des noms des noeuds (optionnel dans un maillage MED) */ if (MEDmeshEntityNameWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,nomnoe) < 0) { MESSAGE("Erreur a l'ecriture des noms des noeuds"); ret = -1; } /* Ecriture des numeros des noeuds (optionnel dans un maillage MED) */ if (MEDmeshEntityNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,numnoe) < 0) { MESSAGE("Erreur a l'ecriture des numeros des noeuds"); ret = -1; } /* Ecriture des numeros de famille des noeuds */ if (MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_NODE,MED_NONE,nnoe,nufano) < 0) { MESSAGE("Erreur a l'ecriture des numeros de familles des noeuds"); ret = -1; } /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ if (MEDmeshNodeCoordinateWr(fid,maa,0,5,0.5, MED_FULL_INTERLACE,nnoe, coo_2) < 0) { MESSAGE("Erreur a l'ecriture des coordonnees des noeuds"); ret = -1; } /* Ecriture des coordonnees des noeuds en mode MED_FULL_INTERLACE : (X1,Y1, X2,Y2, X3,Y3, ...) dans un repere cartesien */ if (MEDmeshNodeCoordinateWr(fid,maa,2,0,2.0, MED_FULL_INTERLACE,nnoe, coo) < 0) { MESSAGE("Erreur a l'ecriture des coordonnees des noeuds"); ret = -1; } /*TODO : Ecrire un test de comparaison next prev et ordre de découverte itératif */ MEDmeshComputationStepCr(fid,maa,-1,-1,0,2,0.25); MEDmeshComputationStepCr(fid,maa,0,2,0,3,0.35); /* Fermeture du fichier */ if (MEDfileClose(fid) < 0) { MESSAGE("Erreur a la fermeture du fichier test4.med"); return -1; } return ret; }
int main (int argc, char **argv) { med_idt fid; const char meshname[MED_NAME_SIZE+1] = "3D Unstructured Mesh With 2 polyhedrons"; const med_int spacedim = 3; const med_int meshdim = 3; /* 12345678901234561234567890123456 */ const char axisname[3*MED_SNAME_SIZE+1] = "x y z "; const char unitname[3*MED_SNAME_SIZE+1] = "cm cm cm "; const med_int nnodes = 16; const med_float coordinates[3 * 16] = { /* [ 1 ] */ -10.0, -10.0, +0.0, /* [ 2 ] */ -10.0, -10.0, +10., /* [ 3 ] */ -10.0, +10.0, +10., /* [ 4 ] */ -10.0, +10.0, +0.0, /* [ 5 ] */ +10.0, -10.0, +0.0, /* [ 6 ] */ +10.0, -10.0, +10., /* [ 7 ] */ +10.0, +10.0, +10., /* [ 8 ] */ +10.0, +10.0, +0.0, /* [ 9 ] */ -10.0, +0.0 , +10.0, /* [ 10 ] */ -10.0, +0.0 , +0.0 , /* [ 11 ] */ +0.0 , -10.0 , +10.0, /* [ 12 ] */ +0.0 , -10.0 , +0.0 , /* [ 13 ] */ +0.0 , +10.0 , +10.0, /* [ 14 ] */ +10.0, +0.0 , +10.0, /* [ 15 ] */ +0.0 , +10.0 , +0.0 , /* [ 16 ] */ +10.0, +0.0 , +0.0 }; /*Il y a 58 numéros de noeuds dans le tableau de connextivité*/ const med_int connectivity[26+32] = { /* - Poly 1 : */ /* - Face 1 : */ 1, 2 , 9 , 3 , 10, /* - Face 2 : */ 1, 12 , 5 , 6 , 11, 2, /* - Face 3 : */ 2, 11 , 6 , 3 , 9 , /* - Face 4 : */ 3, 6 , 5 , /* - Face 5 : */ 3, 5 , 10 , /* - Face 6 : */ 1, 10 , 5 , 12, /* - Poly 2 : */ /* - Face 1 : */ 3, 13 , 7 , 8 , 15, 4, /* - Face 2 : */ 3, 4 , 10 , /* - Face 3 : */ 4, 15 , 8 , 16 , 5, 10, /* - Face 4 : */ 3, 6 , 14 , 7 , 13, /* - Face 5 : */ 5, 16 , 8 , 7 , 14, 6, /* - Face 6 : */ 3, 10 , 5 , /* - Face 7 : */ 3, 5 , 6 }; /* Il y a deux polyèdres, le premier a 6 faces, le second 7 faces */ /* La face 7 du Poly 2 utilise 59-56=3 noeuds */ const med_int nodeindex[6+7+1] = { 1, 6, 12, 17, 20, 23, 27, 33, 36, 42, 47, 53, 56, 59}; /* Il y a un total de 13 faces */ /* NodeIndexSize == Nbre De Faces +1 */ const med_int nodeindexSize = 6+7+1; /* Il y a deux polyèdres, le premier a 6 faces, le second 7 faces */ /* Pn+1 == FaceIndex[n+1]== NodeIndexSize== Nbre De Faces +1 */ const med_int faceindex[3] = {1,7,14}; const med_int faceindexSize = 3; /* open MED file */ fid = MEDfileOpen("UsesCase_MEDmesh_15.med", MED_ACC_CREAT); if (fid < 0) { MESSAGE("ERROR : file creation ..."); return -1; } /* write a comment in the file */ if (MEDfileCommentWr(fid, "A 3D unstructured mesh : 2 polyhedrons") < 0) { MESSAGE("ERROR : write file description ..."); return -1; } /* mesh creation : a 3D unstructured mesh */ if (MEDmeshCr(fid, meshname, spacedim, meshdim, MED_UNSTRUCTURED_MESH, "A 3D mesh with 2 polyhedron", "", MED_SORT_DTIT, MED_CARTESIAN, axisname, unitname) < 0) { MESSAGE("ERROR : mesh creation ..."); return -1; } /* 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, MED_UNDEF_DT, MED_FULL_INTERLACE, nnodes, coordinates) < 0) { MESSAGE("ERROR : nodes coordinates ..."); return -1; } /* cells connectiviy is defined in nodal mode */ if (MEDmeshPolyhedronWr(fid, meshname, MED_NO_DT, MED_NO_IT, MED_UNDEF_DT, MED_CELL, MED_NODAL, faceindexSize, faceindex, nodeindexSize, nodeindex, connectivity) < 0) { MESSAGE("ERROR : polyhedron connectivity ..."); return -1; } /* create family 0 : by default, all mesh entities family number is 0 */ if (MEDfamilyCr(fid, meshname, "", 0, 0, "") < 0) { MESSAGE("ERROR : quadrangular cells connectivity ..."); return -1; } /* close MED file */ if (MEDfileClose(fid) < 0) { MESSAGE("ERROR : close file ..."); return -1; } return 0; }
int main (int argc, char **argv) { med_err _ret=-1; med_idt _fid=0; char _meshname1[MED_NAME_SIZE+1] = "meshname1"; char _axisname[3*MED_SNAME_SIZE+1] = "x y z "; char _unitname[3*MED_SNAME_SIZE+1] = "cm cm cm "; char _fieldname1[MED_NAME_SIZE+1] = "champ reel"; char _componentname1[2*MED_SNAME_SIZE+1] = "comp1 comp2 "; /*12345678901234561234567890123456*/ char _unitname1[2*MED_SNAME_SIZE+1] = "unit1 unit2 "; char _dtunit[MED_SNAME_SIZE+1] = "s"; med_int _ncomponentname1 = 2; /*Exemple 1 : - Elément de référence de type géométrique MED_TRIA3 - Point X(X1,X2) quelconque dans le plan de l'élément de référence - Fonctions de base : P1(X)=1-X1-X2 ; P2(X)=X1; P3(X)=X2; (issu du choix de la base polynomiale (1,X1,X2) et des trois noeuds de la maille de référence pour construire l'interpolation) */ const char _interpname1[] ="interpname1"; med_geometry_type _geotype1 =MED_TRIA3; /* Ouverture en mode creation du fichier "current.med" */ _fid = MEDfileOpen("current.med",MODE_ACCES); if (_fid < 0) { MESSAGE("Erreur a la creation du fichier current.med"); return -1; } /* Creation de _meshname1 de dimension 2 dans un espace de dimension 3*/ if (MEDmeshCr( _fid, _meshname1, 3, 2, MED_UNSTRUCTURED_MESH, "Maillage vide","s", MED_SORT_DTIT, MED_CARTESIAN, _axisname, _unitname) < 0) { MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(_meshname1); goto ERROR; } /* Creation du champ réel n°1 */ if ( MEDfieldCr(_fid,_fieldname1,MED_FLOAT64, _ncomponentname1,_componentname1,_unitname1,_dtunit,_meshname1 ) < 0) { MESSAGE("Erreur à la création du champ : ");SSCRUTE(_fieldname1); goto ERROR; }; if ( (_ret = MEDfieldInterpWr(_fid, _fieldname1, _interpname1) <0) ) { MESSAGE("Erreur à l'écriture de la fonction d'interpolation n°1 sur le champ : ");SSCRUTE(_fieldname1); } ERROR: if (MEDfileClose(_fid) < 0) { MESSAGE("ERROR : file closing"); return -1; } return _ret; }
int main (int argc, char **argv) { med_idt fid; char maa[MED_NAME_SIZE+1] = "maa1"; med_int mdim = 3; med_int n=2; /* connectivite nodale */ med_int indexf[3] = {1,5,9}; med_int nf = 3; med_int indexn[9] = {1,4,7,10,13,16,19,22,25}; med_int nn = 9; med_int conn[24] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19, 20,21,22,23,24}; /* connectivite descendante */ med_int indexf2[3] = {1,5,9}; med_int nf2 = 3; med_int conn2[8] = {1,2,3,4,5,6,7,8}; med_int indexn2[8] = {MED_TRIA3,MED_TRIA3,MED_TRIA3,MED_TRIA3, MED_TRIA3,MED_TRIA3,MED_TRIA3,MED_TRIA3}; med_int nn2=8; /* 12345678901234561234567890123456*/ char nom[MED_SNAME_SIZE*2+1]="polyedre1 polyedre2 "; med_int num[2] = {1,2}; med_int fam[2] = {0,-1}; char nomcoo[3*MED_SNAME_SIZE+1] = "x y z "; char unicoo[3*MED_SNAME_SIZE+1] = "cm cm cm "; /* Creation du fichier test25.med */ if ((fid = MEDfileOpen("test25.med",MODE_ACCES)) < 0) { MESSAGE("Erreur a la creation du fichier test25.med"); return -1; } printf("Creation du fichier test25.med \n"); /* Creation du maillage */ if (MEDmeshCr( fid, maa, mdim, mdim, MED_UNSTRUCTURED_MESH, "un maillage pour test25","s", MED_SORT_DTIT, MED_CARTESIAN, nomcoo, unicoo) < 0) { MESSAGE("Erreur a la creation du maillage"); return -1; } printf("Creation du maillage \n"); /* Ecriture de la connectivite des mailles polyedres en mode nodal */ if (MEDmeshPolyhedronWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT,MED_CELL,MED_NODAL, nf,indexf,nn,indexn,conn) < 0) { MESSAGE("Erreur a l'ecriture de la connectivite des mailles MED_POLYGONE"); return -1; } printf("Ecriture des connectivites de mailles de type MED_POLYEDRE en mode nodal \n"); /* Ecriture des connectivites des mailles polyedres en mode descendant */ if (MEDmeshPolyhedronWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT,MED_CELL,MED_DESCENDING, nf2,indexf2,nn2,indexn2,conn2) < 0) { MESSAGE("Erreur a l'ecriture des connectivites des mailles MED_POLYEDRE en mode descendant"); return -1; } printf("Ecriture des connectivites de mailles de type MED_POLYEDRE en mode descendant \n"); /* Ecriture des noms des polyedres */ /* ecriture (optionnelle) des noms des polyedres */ if (MEDmeshEntityNameWr(fid,maa,MED_NO_DT,MED_NO_IT, MED_CELL,MED_POLYHEDRON,n,nom) < 0) { MESSAGE("Erreur a l'ecriture des noms des polyedres"); return -1; } printf("Ecriture des noms des polyedres \n"); /* ecriture (optionnelle) des numeros des polyedres */ if (MEDmeshEntityNumberWr(fid,maa,MED_NO_DT,MED_NO_IT, MED_CELL,MED_POLYHEDRON,n,num) < 0) { MESSAGE("Erreur a l'ecriture des numeros des polyedres"); return -1; } printf("Ecriture des numeros des polyedres \n"); /* ecriture des numeros des familles des polyedres */ if (MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT, MED_CELL,MED_POLYHEDRON,n,fam) < 0) { MESSAGE("Erreur a l'ecriture des numeros de familles des polyedres"); return -1; } printf("Ecriture des numeros des familles des polyedres \n"); /* Fermeture du fichier */ if (MEDfileClose(fid) < 0) { MESSAGE("Erreur a la fermeture du fichier"); return -1; } printf("Fermeture du fichier test25.med \n"); return 0; }
int main (int argc, char **argv) { med_idt fid; char maa[MED_NAME_SIZE+1] = "maa1"; med_int mdim = 3; med_int index[4] = {1,6,12,17}; med_int con[16] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}; med_int n=3,ni = 4; /* 123456789012345612345678901234561234567890123456 */ char nom[MED_SNAME_SIZE*3+1]="poly1 poly2 poly3 "; med_int num[3] = {1,2,3}; med_int fam[3] = {0,-1,-2}; char nomcoo[3*MED_SNAME_SIZE+1] = "x y z "; char unicoo[3*MED_SNAME_SIZE+1] = "cm cm cm "; /* Creation du fichier test23.med */ fid = MEDfileOpen("test23.med",MODE_ACCES); if (fid == -1) { MESSAGE("Erreur a la creation du fichier test23.med"); return -1; } printf("Creation du fichier test23.med \n"); /* Creation du maillage */ if (MEDmeshCr( fid, maa, mdim, mdim, MED_UNSTRUCTURED_MESH, "un maillage pour test23","s", MED_SORT_DTIT, MED_CARTESIAN, nomcoo, unicoo) < 0) { MESSAGE("Erreur a la creation du maillage"); return -1; } printf("Creation du maillage \n"); /* Ecriture de la connectivite des mailles polygones en mode nodal */ if (MEDmeshPolygonWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT,MED_CELL,MED_NODAL, ni,index,con) < 0) { MESSAGE("Erreur a l'ecriture de la connectivite des mailles MED_POLYGONE"); return -1; } printf("Ecriture des connectivites de mailles de type MED_POLYGONE en mode nodal \n"); /* Ecriture des noms des polygones */ /* ecriture (optionnelle) des noms des polygones */ if (MEDmeshEntityNameWr(fid,maa,MED_NO_DT,MED_NO_IT, MED_CELL,MED_POLYGON,n,nom) < 0) { MESSAGE("Erreur a l'ecriture des noms des polygones"); return -1; } printf("Ecriture des noms des polygones \n"); /* ecriture (optionnelle) des numeros des polygones */ if (MEDmeshEntityNumberWr(fid,maa,MED_NO_DT,MED_NO_IT, MED_CELL,MED_POLYGON,n,num) < 0) { MESSAGE("Erreur a l'ecriture des numeros des polygones"); return -1; } printf("Ecriture des numeros des polygones \n"); /* ecriture des numeros des familles des polygones */ if (MEDmeshEntityFamilyNumberWr(fid,maa,MED_NO_DT,MED_NO_IT, MED_CELL,MED_POLYGON,n,fam) < 0) { MESSAGE("Erreur a l'ecriture des numeros de familles des polygones"); return -1; } printf("Ecriture des numeros des familles des polygones \n"); /* Fermeture du fichier */ if (MEDfileClose(fid) < 0) { MESSAGE("Erreur a la fermeture du fichier"); return -1; } printf("Fermeture du fichier test23.med \n"); return 0; }
int main (int argc, char **argv) { med_idt fid; /* la dimension du maillage */ med_int mdim = 2; /* nom du maillage de longueur maxi MED_NAME_SIZE */ char maa[MED_NAME_SIZE+1] = "maa1"; /* le nombre de noeuds */ med_int nnoe = 4; /* table des coordonnees profil : (dimension * nombre de noeuds) */ med_float coo[8] = {0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0}; /* tables des noms et des unites des coordonnees profil : (dimension*MED_SNAME_SIZE+1) */ /* 12345678901234561234567890123456 */ char nomcoo[2*MED_SNAME_SIZE+1] = "x y "; char unicoo[2*MED_SNAME_SIZE+1] = "cm cm "; /* tables des noms, numeros, numeros de familles des noeuds autant d'elements que de noeuds - les noms ont pout longueur MED_SNAME_SIZE */ /* 1234567890123456123456789012345612345678901234561234567890123456 */ char nomnoe[4*MED_SNAME_SIZE+1] = "nom1 nom2 nom3 nom4 "; med_int numnoe[4] = {1,2,3,4}; med_int nufano[4] = {0,1,2,2}; /* Creation du fichier test14.med */ if ((fid = MEDfileOpen("test14.med",MODE_ACCES)) < 0) { MESSAGE("Erreur a la creation du fichier test14.med"); return -1; } /* Creation du maillage */ if (MEDmeshCr( fid, maa, mdim, mdim, MED_UNSTRUCTURED_MESH, "un maillage pour test14","s", MED_SORT_DTIT, MED_CARTESIAN, nomcoo, unicoo) < 0) { MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa); return -1; } /* Ecriture des noeuds d'un maillage MED : - Des cooordonnees en mode MED_FULL_INTERLACE : (X1,Y1,X2,Y2,X3,Y3,...) dans un repere cartesien - Des noms (optionnel dans un fichier MED) - Des numeros (optionnel dans un fichier MED) - Des numeros de familles des noeuds */ if (MEDmeshNodeWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT,MED_FULL_INTERLACE, nnoe,coo,MED_TRUE,nomnoe,MED_TRUE,numnoe,MED_TRUE, nufano) < 0) { MESSAGE("Erreur a l'ecriture des noeuds du maillage"); return -1; } /* Fermeture du fichier */ if (MEDfileClose(fid) < 0) { MESSAGE("Erreur a la fermeture du fichier"); return -1; } return 0; }
int main (int argc, char **argv) { med_idt fid = 0; med_int nse2 = 5; med_int se2[10] = {1,2,1,3,2,4,3,4,2,3}; /* 12345678901234561234567890123456123456789012345612345678901234561234567890123456 */ char nomse2[MED_SNAME_SIZE*5+1]="se1 se2 se3 se4 se5 "; med_int numse2[5] = {1,2,3,4,5}; med_int nufase2[5] = {-1,-1,0,-2,-3}; med_int ntr3 = 2; med_int tr3[6] = {1,2,-5,-5,3,-4}; /* 1234567890123456123456789012345612345678901234561234567890123456 */ char nomtr3[MED_SNAME_SIZE*2+1] = "tr1 tr2 "; med_int numtr3[2] = {4,5}; med_int nufatr3[2] = {0,-1}; char maa[MED_NAME_SIZE+1] = "maa1"; med_int mdim = 2; /* 12345678901234561234567890123456 */ char nomcoo[2*MED_SNAME_SIZE+1] = "x y "; char unicoo[2*MED_SNAME_SIZE+1] = "cm cm "; /* Creation du fichier test16.med */ if ((fid = MEDfileOpen("test16.med",MODE_ACCES)) < 0) { MESSAGE("Erreur a la creation du fichier test16.med"); return -1; } /* Creation du maillage */ if (MEDmeshCr( fid, maa, mdim, mdim, MED_UNSTRUCTURED_MESH, "un maillage pour test16","s", MED_SORT_DTIT, MED_CARTESIAN, nomcoo, unicoo) < 0) { MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa); return -1; } /* Ecriture des aretes segments MED_SEG2 : - connectivite - noms (optionnel) - numeros (optionnel) - numeros des familles */ if ( MEDmeshElementWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, MED_DESCENDING_EDGE,MED_SEG2,MED_DESCENDING,MED_NO_INTERLACE, nse2,se2,MED_TRUE,nomse2,MED_TRUE,numse2,MED_TRUE,nufase2)< 0 ) { MESSAGE("Impossible d'ecrire la connectivit� des aretes : "); return -1; } /* Ecriture des mailles MED_TRIA3 : - Connectivite - Noms (optionnel) - Numeros (optionnel) - Numeros des familles */ if ( MEDmeshElementWr(fid,maa,MED_NO_DT,MED_NO_IT,MED_UNDEF_DT, MED_CELL,MED_TRIA3,MED_DESCENDING,MED_NO_INTERLACE, ntr3,tr3,MED_TRUE,nomtr3,MED_TRUE,numtr3,MED_TRUE,nufatr3)< 0 ) { MESSAGE("Impossible d'ecrire les �l�ments triangles : "); return -1; } /* Fermeture du fichier */ if ( MEDfileClose(fid) < 0) { MESSAGE("Impossible de fermerle fichier : "); return -1; } return 0; }
int main (int argc, char **argv) { med_err ret=0; med_idt fid; /* Maillage support aux champs*/ /* Ces maillages sont vides*/ char maa1[MED_NAME_SIZE+1]= "maa1"; char maa2[MED_NAME_SIZE+1]= "maa2"; char * lien_maa2 = "./testfoo.med"; char maa3[MED_NAME_SIZE+1]= "maa3"; /* Caractéristiques du champ n° 1 sur TRIA6 */ char nomcha1[MED_NAME_SIZE+1] = "champ reel"; char comp1[2*MED_SNAME_SIZE+1] = "comp1 comp2 "; /*12345678901234561234567890123456*/ char unit1[2*MED_SNAME_SIZE+1] = "unit1 unit2 "; med_int ncomp1 = 2; /* Caractéristiques du model n° 1 de localisation des points de gauss pour le champ n° 1*/ med_int ngauss1_1 = 6; char gauss1_1[MED_NAME_SIZE+1] = "Model n1"; med_float refcoo1[12] = { -1.0,1.0, -1.0,-1.0, 1.0,-1.0, -1.0,0.0, 0.0,-1.0, 0.0,0.0 }; /* Constantes */ med_float gscoo1_1[12] = { 2*_b-1, 1-4*_b, 2*_b-1, 2*_b-1, 1-4*_b, 2*_b-1, 1-4*_a, 2*_a-1, 2*_a-1, 1-4*_a, 2*_a-1, 2*_a-1 }; med_float wg1_1[6] = { 4*_p2, 4*_p2, 4*_p2, 4*_p1, 4*_p1, 4*_p1 }; med_int nval1_1= 1*6; /*1 valeurs et 6 points de gauss par valeur */ med_int _nent1_1= 1; /*1 valeurs et 6 points de gauss par valeur */ med_float valr1_1[1*6*2] = {0.0,1.0, 2.0,3.0, 10.0,11.0, 12.0,13.0, 20.0,21.0, 22.0,23.0}; /* 2 composantes*/ /* Caractéristiques du model n° 2 de localisation des points de gauss pour le champ n° 1*/ med_int ngauss1_2 = 3; char gauss1_2[MED_NAME_SIZE+1] = "Model n2"; med_float gscoo1_2[6] = { -2.0/3,1.0/3, -2.0/3,-2.0/3, 1.0/3,-2.0/3 }; med_float wg1_2[3] = { 2.0/3, 2.0/3, 2.0/3 }; med_int nval1_2= 2*3; /*2 valeurs et 3 points de gauss par valeur */ med_int _nent1_2= 2; /*2 valeurs et 3 points de gauss par valeur */ med_float valr1_2[2*3*2] = {0.0,1.0, 2.0,3.0, 10.0,11.0, 12.0,13.0, 20.0,21.0, 22.0,23.0}; /* 2 composantes*/ med_float valr1_2p[2*3*2] = { 12.0,13.0, 20.0,21.0, 22.0,23.0}; /* 2 composantes*/ /* Caractéristiques du model n° 3 sans points de gauss pour le champ n° 1*/ med_int nval1_3= 6; /*6 valeurs et pas de points de gauss */ med_int _nent1_3= 6; /*6 valeurs et pas de points de gauss */ med_float valr1_3[2*3*2] = {0.0,1.0, 2.0,3.0, 10.0,11.0, 12.0,13.0, 20.0,21.0, 22.0,23.0}; /* 2 composantes*/ med_float valr1_3p[2*2*2] = { 2.0,3.0, 10.0,11.0 }; /* 2 composantes profil1 */ /* Caractéristiques du champ n° 2 */ char nomcha2[MED_NAME_SIZE+1] = "champ entier"; char comp2[3*MED_SNAME_SIZE+1] = "comp1 comp2 comp3 "; /*123456789012345612345678901234561234567890123456*/ char unit2[3*MED_SNAME_SIZE+1] = "unit1 unit2 unit3 "; med_int ncomp2 = 3; med_int nval2 = 5; /*5 valeurs */ med_int valr2[5*3 ] = {0,1,2, 10,11,12, 20,21,22, 30,31,32, 40,41,42}; /* 3 composantes*/ med_int valr2p[3*3 ] = {0,1,2, 20,21,22, 40,41,42}; /* 3 composantes*/ /* Profils utilisés */ char nomprofil1[MED_NAME_SIZE+1] = "PROFIL(champ(1))"; char nomprofil1b[MED_NAME_SIZE+1] = "PROFIL(champ(1b))"; char nomprofil2[MED_NAME_SIZE+1] = "PROFIL(champ2)"; med_int profil1[2] = { 2, 3 }; med_int profil2[3] = { 1, 3, 5 }; /* Caractéristiques du champ n° 3 */ char nomcha3[MED_NAME_SIZE+1] = "champ entier 3"; char comp3[3*MED_SNAME_SIZE+1] = "comp1 comp2 "; /*123456789012345612345678901234561234567890123456*/ char unit3[3*MED_SNAME_SIZE+1] = "unit1 unit2 "; char dtunit[MED_SNAME_SIZE+1] = "s"; med_int ncomp3 = 2; med_int nval3 = 5*4; /*5 valeurs et 4 noeuds par element*/ med_int _nent3 = 5; /*5 valeurs et 4 noeuds par element*/ med_int valr3[5*4*2] = {0,1, 10,11, 20,21, 30,31, 40,41, 50,51, 60,61, 70,71, 80,81, 90,91, 100,101, 110,111, 120,121, 130,131, 140,141, 150,151, 160,161, 170,171, 180,181, 190,191}; /* 2 composantes*/ med_int valr3p[3*4*2] = {0,1, 10,11, 20,21, 30,31, 80,81, 90,91, 100,101, 110,111, 160,161, 170,171, 180,181, 190,191}; /* 2 composantes*/ char nomcoo[3*MED_SNAME_SIZE+1] = "x y z "; char unicoo[3*MED_SNAME_SIZE+1] = "cm cm cm "; char _maa[MED_NAME_SIZE+1]=""; char _desc[MED_COMMENT_SIZE+1]=""; char _dtunit[MED_SNAME_SIZE+1]=""; char _nomcoo[3*MED_SNAME_SIZE+1]=""; char _unicoo[3*MED_SNAME_SIZE+1]=""; med_int _nstep=0; med_axis_type _rep; med_mesh_type _type; med_sorting_type _sort; char __dtunit [MED_SNAME_SIZE+1]=""; med_int _mdim=0,_sdim=0; med_int ncha=0; med_access_mode _accessmode; /* Il n'est pas necessaire de pré-allouer la mémoire. med-fichier s'occupe d'allouer la mémoire au fil de l'utilsation de l'API.*/ /* Attention la structure doit être initialisée à MED_MEMFILE_INIT avant toute première utilisation.*/ med_memfile memfile[1] = MED_MEMFILE_INIT; /* On décide de pré-allouer suffisement de mémoire : 10MB */ /* med-fichier utilisera l'espace réservé sans réallocation.*/ /* memfile[0].app_image_size = 10*1024*1024; */ /* memfile[0].app_image_ptr = calloc(memfile[0].app_image_size,sizeof(char)); */ /* On décide de pré-allouer insuffisement de mémoire : 1KB */ /* med-fichier utilisera l'espace réservé puis effectuera une réallocation.*/ /* memfile[0].app_image_size = 1024; */ /* memfile[0].app_image_ptr = calloc(memfile[0].app_image_size,sizeof(char)); */ AFF_MEMFILE; /* Ouverture du fichier */ /* mode RDWR uniquement si le fichier test10.med a préalablement été généré par test10 ou par le sync de test10_mem (en CREATE). Si test10.med n'existe pas et demande le mode RDWR -> erreur car nous n'avons pas initialisé une image mémoire valide ! */ _accessmode = MED_ACC_CREAT; if ((fid = MEDmemFileOpen("test10.med",memfile,MED_TRUE,_accessmode) ) < 0){ MESSAGE("Erreur à l'ouverture du fichier : "); return -1; } /* Ouverture du fichier */ /* Si l'on ne veut pas créer de fichier sur disque, sync=MED_FALSE */ /* if ((fid = MEDmemFileOpen("test10.med",memfile,MED_FALSE,MED_ACC_CREAT) ) < 0){ */ /* MESSAGE("Erreur à l'ouverture du fichier : "); */ /* return -1; */ /* } */ AFF_MEMFILE; /* combien de champs dans le fichier (pour tester le fichier mémoire)*/ if ((ncha = MEDnField(fid)) < 0) { MESSAGE("Impossible de lire le nombre de champs : ");ISCRUTE(ncha); } printf("Nombre de champs : "IFORMAT" \n",ncha); if (ncha == 3 ) { /*Un quatrième champ est crée seulement si un fichier test10.med existait et mode RDWR + sync */ /* creation du champ réel n° 1 */ if ( MEDfieldCr(fid,"Ajout Complémentaire",MED_FLOAT64,ncomp1,comp1,unit1,dtunit,maa1 ) < 0) { MESSAGE("Erreur à la création du champ : ");SSCRUTE("Ajout Complémentaire"); ret = -1; }; } /* creation de maa1 de dimension 3*/ if (MEDmeshCr( fid, maa1, 3, 3, MED_UNSTRUCTURED_MESH, "Maillage vide","s", MED_SORT_DTIT, MED_CARTESIAN, nomcoo, unicoo) < 0) { MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa1); ret = -1; } /* creation de maa3 de dimension 3*/ if (MEDmeshCr( fid, maa3, 3, 3, MED_UNSTRUCTURED_MESH, "Maillage vide","s", MED_SORT_DTIT, MED_CARTESIAN, nomcoo, unicoo) < 0) { MESSAGE("Erreur a la creation du maillage : "); SSCRUTE(maa3); ret = -1; } /* creation du champ réel n° 1 */ if ( MEDfieldCr(fid,nomcha1,MED_FLOAT64,ncomp1,comp1,unit1,dtunit,maa1 ) < 0) { MESSAGE("Erreur à la création du champ : ");SSCRUTE(nomcha1); ret = -1; }; /* creation du champ entier n° 2 */ if ( MEDfieldCr(fid,nomcha2,MED_INT32,ncomp2,comp2,unit2,dtunit,maa2 ) < 0) { MESSAGE("Erreur à la création du champ : ");SSCRUTE(nomcha2); ret = -1; }; /* creation du lien au fichier distant contenant maa2 */ if (MEDlinkWr(fid,maa2,lien_maa2) < 0) { MESSAGE("Erreur à la création du lien : ");SSCRUTE(lien_maa2); ret = -1; }; /* creation de la localisation des points de Gauss modèle n° 1 */ if (MEDlocalizationWr(fid, gauss1_1, MED_TRIA6, MED_TRIA6/100, refcoo1, USER_INTERLACE, ngauss1_1, gscoo1_1, wg1_1, MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT ) < 0) { MESSAGE("Erreur à la création du modèle n° 1 : ");SSCRUTE(gauss1_1); ret = -1; }; /* creation de la localisation des points de Gauss modèle n° 2 */ if (MEDlocalizationWr(fid, gauss1_2, MED_TRIA6, MED_TRIA6/100, refcoo1, USER_INTERLACE, ngauss1_2, gscoo1_2, wg1_2, MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT) < 0) { MESSAGE("Erreur à la création du modèle n° 1 : ");SSCRUTE(gauss1_2); ret = -1; }; /* ecriture du champ n° 1*/ /* enregistre uniquement les composantes n° 2 de valr1_1, et n'utilise ni pas de temps ni n° d'ordre*/ if ( MEDfieldValueWithProfileWr(fid, nomcha1,MED_NO_DT,MED_NO_IT,0.0,MED_CELL,MED_TRIA6,USER_MODE,MED_ALLENTITIES_PROFILE, gauss1_1,USER_INTERLACE, 2, _nent1_1, (unsigned char*)valr1_1 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* enregistre uniquement les composantes n° 1 de valr1_1, et n'utilise ni pas de temps ni n° d'ordre */ if ( MEDfieldValueWithProfileWr(fid, nomcha1,MED_NO_DT,MED_NO_IT,0.0,MED_CELL,MED_TRIA6,USER_MODE,MED_ALLENTITIES_PROFILE, gauss1_1,USER_INTERLACE, 1, _nent1_1, (unsigned char*)valr1_1 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* enregistre uniquement les composantes n° 1 de valr1_2, au pas de temps n° 1(5.5), n'utilise pas de n° d'ordre*/ /* ce champ repose sur le maillage maa2 qui est distant */ if ( MEDfieldValueWithProfileWr(fid, nomcha1,1,MED_NO_IT,5.5,MED_CELL,MED_TRIA6,USER_MODE,MED_ALLENTITIES_PROFILE, gauss1_2,USER_INTERLACE, 1, _nent1_2, (unsigned char*)valr1_2 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* Le test initial utilisait un deuxième maillage epour un même champ et une même séquence de calcul, ceci n'existe plus en 3.0*/ /* enregistre uniquement les composantes n° 2 de valr1_2, au pas de temps n° 1(5.5), n'utilise pas de n° d'ordre*/ /* ce champ repose sur le maillage maa1 qui est local */ if ( MEDfieldValueWithProfileWr(fid, nomcha1,1,1,5.5,MED_CELL,MED_TRIA6,USER_MODE,MED_ALLENTITIES_PROFILE, gauss1_1,USER_INTERLACE, 2, _nent1_1, (unsigned char*)valr1_1 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* enregistre uniquement les composantes n° 1 de valr1_1, au pas de temps n° 1(5.5), et n° d'itération n° 2*/ /* ce champ repose sur le maillage maa3 qui est local */ if ( MEDfieldValueWithProfileWr(fid, nomcha1,1,2,5.5,MED_CELL,MED_TRIA6,USER_MODE,MED_ALLENTITIES_PROFILE, gauss1_2,USER_INTERLACE, 1, _nent1_2, (unsigned char*)valr1_2 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* Creation d'un profil (selection du deuxieme élément de valr1_1) */ /* On n'utilise que la première valeur (2) du profil */ if ( MEDprofileWr(fid,nomprofil1,1,profil1) < 0) { MESSAGE("Erreur à l'écriture du profil : "); SSCRUTE(nomprofil1); ret = -1; }; if ( MEDprofileWr(fid,nomprofil1b,1,profil1) < 0) { MESSAGE("Erreur à l'écriture du profil : "); SSCRUTE(nomprofil1b); ret = -1; }; /* enregistre toutes les composantes du deuxième élément de valr1_1 (premier élément en stockage compact de valr1p), au pas de temps n° 2(5.6), et n° d'itération n° 2*/ if ( MEDfieldValueWithProfileWr(fid, nomcha1,2,2,5.6,MED_CELL,MED_TRIA6,USER_MODE,nomprofil1, MED_NO_LOCALIZATION,USER_INTERLACE, MED_ALL_CONSTITUENT, nval1_3, (unsigned char*)valr1_3p ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* enregistre toutes les composantes du deuxième élément de valr1_1 (premier élément en stockage compact de valr1p), au pas de temps n° 2(5.6), et n° d'itération n° 2 */ if ( MEDfieldValueWithProfileWr(fid, nomcha1,2,2,5.6,MED_CELL,MED_TRIA6,USER_MODE,nomprofil1b, gauss1_2,USER_INTERLACE, MED_ALL_CONSTITUENT, _nent1_2, (unsigned char*)valr1_2p ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; if ( MEDfieldValueWithProfileWr(fid, nomcha1,3,2,5.7,MED_CELL,MED_TRIA6,USER_MODE,nomprofil1, MED_NO_LOCALIZATION,USER_INTERLACE, 2, _nent1_3, (unsigned char*)valr1_3p ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* Ecriture du champ n° 2 */ if ( MEDfieldValueWr(fid, nomcha2,MED_NO_DT,MED_NO_IT,0, MED_DESCENDING_EDGE,MED_SEG2, USER_INTERLACE, 1, nval2, (unsigned char*)valr2 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; if ( MEDfieldValueWr(fid, nomcha2,MED_NO_DT,MED_NO_IT,0,MED_NODE,MED_NONE, USER_INTERLACE, 2, nval2, (unsigned char*)valr2 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; if ( MEDfieldValueWr(fid, nomcha2,MED_NO_DT,MED_NO_IT,0,MED_DESCENDING_FACE,MED_TRIA6, USER_INTERLACE, 3, nval2, (unsigned char*)valr2 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* Creation d'un profil (selection des éléments 1,3,5 de valr2) */ /* On utilise les trois valeurs du profil */ if ( MEDprofileWr(fid,nomprofil2,3,profil2) < 0) { MESSAGE("Erreur à l'écriture du profil : "); SSCRUTE(nomprofil2); ret = -1; }; if ( MEDfieldValueWithProfileWr(fid, nomcha2,MED_NO_DT,MED_NO_IT,0,MED_CELL,MED_TRIA6,USER_MODE,nomprofil2, MED_NO_LOCALIZATION,USER_INTERLACE, 3, nval2, (unsigned char*)valr2p ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; /* creation du champ entier n° 3 */ if ( MEDfieldCr(fid,nomcha3,MED_INT32,ncomp3,comp3,unit3,dtunit,maa1) < 0) { MESSAGE("Erreur à la création du champ : ");SSCRUTE(nomcha3); ret = -1; }; /* Ecriture du champ n° 3 */ if ( MEDfieldValueWr(fid, nomcha3,MED_NO_DT,MED_NO_IT,0,MED_CELL,MED_QUAD4, USER_INTERLACE, 1, nval3, (unsigned char*)valr3 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; if ( MEDfieldValueWr(fid, nomcha3,MED_NO_DT,MED_NO_IT,0,MED_NODE_ELEMENT,MED_QUAD4, USER_INTERLACE, MED_ALL_CONSTITUENT, _nent3, (unsigned char*)valr3 ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; if ( MEDfieldValueWithProfileWr(fid, nomcha3,MED_NO_DT,MED_NO_IT,0,MED_NODE_ELEMENT,MED_QUAD4,USER_MODE,nomprofil2, MED_NO_LOCALIZATION,USER_INTERLACE, MED_ALL_CONSTITUENT, _nent3, (unsigned char*)valr3p ) < 0) { MESSAGE("Erreur à l'écriture du champ : "); SSCRUTE(nomcha1);ISCRUTE_int(MED_NO_DT);ISCRUTE_int(MED_NO_IT);SSCRUTE(MED_NO_PROFILE); SSCRUTE(maa1); ret = -1; }; AFF_MEMFILE; /* fermeture du fichier */ if ( MEDfileClose(fid) < 0 ) { ret=-1; MESSAGE("Erreur à la fermeture du fichier "); } AFF_MEMFILE; /* H5Fflush(fid, H5F_SCOPE_GLOBAL ); */ _accessmode = MED_ACC_RDWR; /*ATTENTION : Il faut au moins une écriture/création dans le fichier pour que le sync se fasse en mode RW*/ if ((fid = MEDmemFileOpen("test10_mem.med",memfile,MED_TRUE,_accessmode) ) < 0){ MESSAGE("Erreur à l'ouverture du fichier : "); return -1; } AFF_MEMFILE; /* combien de champs dans le fichier (pour tester le fichier mémoire)*/ if ((ncha = MEDnField(fid)) < 0) { MESSAGE("Impossible de lire le nombre de champs : ");ISCRUTE(ncha); } printf("Nombre de champs : "IFORMAT" \n",ncha); /*Il faut une écriture pour que le sync se fasse en mode RW*/ if ( (ncha == 3) || (_accessmode == MED_ACC_RDWR) ) /* creation du champ complémentaire n° 2 */ if ( MEDfieldCr(fid,"Ajout Complémentaire 2",MED_FLOAT64,ncomp1,comp1,unit1,dtunit,maa1 ) < 0) { MESSAGE("Erreur à la création du champ : Complémentaire 2"); ret = -1; }; AFF_MEMFILE; /* Lecture des infos concernant le premier maillage */ if ( MEDmeshInfo( fid, 1, _maa, &_sdim, &_mdim, &_type, _desc, __dtunit, &_sort, &_nstep, &_rep, _nomcoo,_unicoo) < 0 ) { MESSAGE("Erreur a la lecture des informations sur le maillage : ");SSCRUTE(_maa); return -1; } else { printf("Maillage de nom : |%s| , de dimension : "IFORMAT" , et de type %d\n",_maa,_mdim,_type); printf("\t -Dimension de l'espace : "IFORMAT"\n",_sdim); printf("\t -Description du maillage : %s\n",_desc); printf("\t -Noms des axes : |%s|\n",_nomcoo); printf("\t -Unités des axes : |%s|\n",_unicoo); printf("\t -Type de repère : %d\n",_rep); printf("\t -Nombre d'étapes de calcul : "IFORMAT"\n",_nstep); printf("\t -Unité des dates : |%s|\n",__dtunit); } /* combien de champs dans le fichier (pour tester le fichier mémoire)*/ if ((ncha = MEDnField(fid)) < 0) { MESSAGE("Impossible de lire le nombre de champs : ");ISCRUTE(ncha); } printf("Nombre de champs : "IFORMAT" \n",ncha); if ( MEDfileClose(fid) < 0 ) { ret=-1; MESSAGE("Erreur à la fermeture du fichier "); } AFF_MEMFILE; free(memfile[0].app_image_ptr); memfile->app_image_size =0; return ret; }