int main(int argc,char *argv[]) { MMG5_pMesh mesh; MMG5_pSol met; int ier; char stim[32]; atexit(endcod); tminit(ctim,TIMEMAX); chrono(ON,&ctim[0]); /* assign default values */ mesh = NULL; met = NULL; MMG5_Init_mesh(&mesh,&met); /* reset default values for file names */ MMG5_Free_names(mesh,met); /* command line */ if ( !MMG5_parsar(argc,argv,mesh,met) ) return(1); /* load data */ fprintf(stdout,"\n -- INPUT DATA\n"); chrono(ON,&ctim[1]); /* read mesh file */ if ( !MMG5_loadMesh(mesh) ) { MMG5_Free_all(mesh,met ); return(MMG5_STRONGFAILURE); } if ( !MMG5_Set_solSize(mesh,met,MMG5_Vertex,0,MMG5_Scalar) ) { MMG5_Free_all(mesh,met); return(MMG5_STRONGFAILURE); } /* read metric if any */ ier = MMG5_loadMet(mesh,met); if ( !ier ) { MMG5_Free_all(mesh,met); return(MMG5_STRONGFAILURE); } if ( !MMG5_parsop(mesh,met) ) RETURN_AND_FREE(mesh,met,MMG5_LOWFAILURE); chrono(OFF,&ctim[1]); printim(ctim[1].gdif,stim); fprintf(stdout," -- DATA READING COMPLETED. %s\n",stim); ier = MMG5_mmg3dlib(mesh,met ); if ( ier != MMG5_STRONGFAILURE ) { chrono(ON,&ctim[1]); if ( mesh->info.imprim ) fprintf(stdout,"\n -- WRITING DATA FILE %s\n",mesh->nameout); if ( !MMG5_saveMesh(mesh) ) { MMG5_Free_all(mesh,met ); return(EXIT_FAILURE); } if ( !MMG5_saveMet(mesh,met) ) { MMG5_Free_all(mesh,met); return(EXIT_FAILURE); } chrono(OFF,&ctim[1]); if ( mesh->info.imprim ) fprintf(stdout," -- WRITING COMPLETED\n"); } /* free mem */ chrono(OFF,&ctim[0]); printim(ctim[0].gdif,stim); fprintf(stdout,"\n MMG3D: ELAPSED TIME %s\n",stim); MMG5_Free_all(mesh,met); return(ier); }
int main(int argc,char *argv[]) { MMG5_pMesh mmgMesh; MMG5_pSol mmgSol,mmgDisp; int k,ier; char *pwd,*inname,*outname; fprintf(stdout," -- TEST MMG3DLIB \n"); /* Name and path of the mesh files */ pwd = getenv("PWD"); inname = (char *) calloc(strlen(pwd) + 40, sizeof(char)); if ( inname == NULL ) { perror(" ## Memory problem: calloc"); exit(EXIT_FAILURE); } outname = (char *) calloc(strlen(pwd) + 49, sizeof(char)); if ( outname == NULL ) { perror(" ## Memory problem: calloc"); exit(EXIT_FAILURE); } sprintf(inname, "%s%s%s", pwd, "/../libexamples/mmg3d/example4/", "tinyBoxt"); /** 1) Initialisation of mesh and sol structures */ /* args of InitMesh: mesh=&mmgMesh, sol=&mmgSol */ mmgMesh = NULL; mmgSol = NULL; mmgDisp = NULL; //Useless here: just needed forthe lagrangian motion option MMG5_Init_mesh(&mmgMesh,&mmgSol,&mmgDisp); /** 2) Build mesh in MMG5 format */ /** Two solutions: just use the MMG5_loadMesh function that will read a .mesh(b) file formatted or manually set your mesh using the MMG5_Set* functions */ /** with MMG5_loadMesh function */ /** a) (not mandatory): give the mesh name (by default, the "mesh.mesh" file is oppened)*/ if ( !MMG5_Set_inputMeshName(mmgMesh,inname) ) exit(EXIT_FAILURE); /** b) function calling */ if ( !MMG5_loadMesh(mmgMesh) ) exit(EXIT_FAILURE); /** 3) Build displacement in MMG5 format */ /** Two solutions: just use the MMG5_loadMet function that will read a .sol(b) file formatted or manually set your sol using the MMG5_Set* functions */ /**------------------- Lagrangian motion option ----------------------------*/ /* Ask for lagrangian motion (mode 1) */ if ( !MMG5_Set_iparameter(mmgMesh,mmgDisp,MMG5_IPARAM_lag, 1) ) exit(EXIT_FAILURE); /** With MMG5_loadMet function */ /** a) (not mandatory): give the sol name (by default, the "mesh.sol" file is oppened)*/ if ( !MMG5_Set_inputSolName(mmgMesh,mmgDisp,inname) ) exit(EXIT_FAILURE); /** b) function calling */ if ( !MMG5_loadMet(mmgMesh,mmgDisp) ) exit(EXIT_FAILURE); /** 4) (not mandatory): check if the number of given entities match with mesh size */ if ( !MMG5_Chk_meshData(mmgMesh,mmgDisp) ) exit(EXIT_FAILURE); /** 5) (not mandatory): set your global parameters using the MMG5_Set_iparameter and MMG5_Set_dparameter function (resp. for integer parameters and double param)*/ /**------------------- Lagrangian motion computation ---------------------*/ /* debug mode ON (default value = OFF) */ if ( !MMG5_Set_iparameter(mmgMesh,mmgDisp,MMG5_IPARAM_debug, 1) ) exit(EXIT_FAILURE); /** library call */ ier = MMG5_mmg3dmov(mmgMesh,mmgSol,mmgDisp); if ( ier == MMG5_STRONGFAILURE ) { fprintf(stdout,"BAD ENDING OF MMG3DLIB: UNABLE TO SAVE MESH\n"); return(ier); } else if ( ier == MMG5_LOWFAILURE ) fprintf(stdout,"BAD ENDING OF MMG3DLIB\n"); /* (Not mandatory) Automatically save the mesh */ sprintf(outname, "%s%s%s", pwd, "/../libexamples/mmg3d/example4/", "tinyBoxt.o.mesh"); if ( !MMG5_Set_outputMeshName(mmgMesh,outname) ) exit(EXIT_FAILURE); MMG5_saveMesh(mmgMesh); /* (Not mandatory) Automatically save the solution */ if ( !MMG5_Set_outputSolName(mmgMesh,mmgSol,outname) ) exit(EXIT_FAILURE); MMG5_saveMet(mmgMesh,mmgSol); /* 9) free the MMG3D5 structures */ MMG5_Free_all(mmgMesh,mmgSol,mmgDisp); free(inname); inname = NULL; free(outname); outname = NULL; return(ier); }
/** * \param argc number of command line arguments. * \param argv command line arguments. * \return \ref MMG5_SUCCESS if success. * \return \ref MMG5_LOWFAILURE if failed but a conform mesh is saved. * \return \ref MMG5_STRONGFAILURE if failed and we can't save the mesh. * * Main program for MMG3D executable: perform mesh adaptation. * */ int main(int argc,char *argv[]) { MMG5_Mesh mesh; MMG5_Sol met; int ier; char stim[32]; fprintf(stdout," -- MMG3d, Release %s (%s) \n",MG_VER,MG_REL); fprintf(stdout," %s\n",MG_CPY); fprintf(stdout," %s %s\n",__DATE__,__TIME__); signal(SIGABRT,_MMG5_excfun); signal(SIGFPE,_MMG5_excfun); signal(SIGILL,_MMG5_excfun); signal(SIGSEGV,_MMG5_excfun); signal(SIGTERM,_MMG5_excfun); signal(SIGINT,_MMG5_excfun); atexit(_MMG5_endcod); tminit(MMG5_ctim,TIMEMAX); chrono(ON,&MMG5_ctim[0]); /* assign default values */ memset(&mesh,0,sizeof(MMG5_Mesh)); memset(&met,0,sizeof(MMG5_Sol)); MMG5_Init_parameters(&mesh); met.size = 1; /* command line */ if ( !MMG5_parsar(argc,argv,&mesh,&met) ) return(MMG5_STRONGFAILURE); #ifdef USE_SCOTCH _MMG5_warnScotch(&mesh); #endif /* load data */ fprintf(stdout,"\n -- INPUT DATA\n"); chrono(ON,&MMG5_ctim[1]); _MMG5_warnOrientation(&mesh); /* read mesh file */ if ( !MMG5_loadMesh(&mesh) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); /* read metric if any */ ier = MMG5_loadMet(&mesh,&met); if ( !ier ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); else if ( ier > 0 && met.np != mesh.np ) { fprintf(stdout," ## WARNING: WRONG SOLUTION NUMBER. IGNORED\n"); _MMG5_DEL_MEM(&mesh,met.m,(met.size*met.npmax+1)*sizeof(double)); met.np = 0; } else if ( met.size!=1 ) { fprintf(stdout," ## ERROR: ANISOTROPIC METRIC NOT IMPLEMENTED.\n"); _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); } if ( !MMG5_parsop(&mesh,&met) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_LOWFAILURE); chrono(OFF,&MMG5_ctim[1]); printim(MMG5_ctim[1].gdif,stim); fprintf(stdout," -- DATA READING COMPLETED. %s\n",stim); /* analysis */ chrono(ON,&MMG5_ctim[2]); _MMG5_setfunc(&mesh,&met); MMG5_Set_saveFunc(&mesh); if ( abs(mesh.info.imprim) > 0 ) _MMG5_outqua(&mesh,&met); fprintf(stdout,"\n %s\n MODULE MMG3D: IMB-LJLL : %s (%s)\n %s\n", MG_STR,MG_VER,MG_REL,MG_STR); if ( mesh.info.imprim ) fprintf(stdout,"\n -- PHASE 1 : ANALYSIS\n"); if ( !_MMG5_scaleMesh(&mesh,&met) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); if ( mesh.info.iso ) { if ( !met.np ) { fprintf(stdout,"\n ## ERROR: A VALID SOLUTION FILE IS NEEDED \n"); _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); } if ( !_MMG5_mmg3d2(&mesh,&met) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); } if ( !mesh.info.iso && !met.np && !_MMG5_DoSol(&mesh,&met) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_LOWFAILURE); if ( !_MMG5_analys(&mesh) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_LOWFAILURE); if ( mesh.info.imprim > 3 && !mesh.info.iso && met.m ) _MMG5_prilen(&mesh,&met); chrono(OFF,&MMG5_ctim[2]); printim(MMG5_ctim[2].gdif,stim); if ( mesh.info.imprim ) fprintf(stdout," -- PHASE 1 COMPLETED. %s\n",stim); /* mesh adaptation */ chrono(ON,&MMG5_ctim[3]); if ( mesh.info.imprim ) fprintf(stdout,"\n -- PHASE 2 : %s MESHING\n",met.size < 6 ? "ISOTROPIC" : "ANISOTROPIC"); /* renumerotation if available */ if ( !_MMG5_scotchCall(&mesh,&met) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); #ifdef PATTERN if ( !_MMG5_mmg3d1_pattern(&mesh,&met) ) { if ( !(mesh.adja) && !_MMG5_hashTetra(&mesh,1) ) { fprintf(stdout," ## Hashing problem. Unable to save mesh.\n"); _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); } if ( !_MMG5_unscaleMesh(&mesh,&met) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); if ( !MMG5_saveMesh(&mesh) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); if ( met.m && !MMG5_saveMet(&mesh,&met) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_LOWFAILURE); } #else /* Pattern in iso mode, delauney otherwise */ if ( !mesh.info.iso ) { if( !_MMG5_mmg3d1_delone(&mesh,&met) ) { if ( !(mesh.adja) && !_MMG5_hashTetra(&mesh,1) ) { fprintf(stdout," ## Hashing problem. Unable to save mesh.\n"); _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); } if ( !_MMG5_unscaleMesh(&mesh,&met) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); if ( !MMG5_saveMesh(&mesh) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); if ( met.m && !MMG5_saveMet(&mesh,&met) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_LOWFAILURE); } } else { if( !_MMG5_mmg3d1_pattern(&mesh,&met) ) { if ( !(mesh.adja) && !_MMG5_hashTetra(&mesh,1) ) { fprintf(stdout," ## Hashing problem. Unable to save mesh.\n"); _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); } if ( !_MMG5_unscaleMesh(&mesh,&met) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); if ( !MMG5_saveMesh(&mesh) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); if ( met.m && !MMG5_saveMet(&mesh,&met) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_LOWFAILURE); } } #endif chrono(OFF,&MMG5_ctim[3]); printim(MMG5_ctim[3].gdif,stim); if ( mesh.info.imprim ) fprintf(stdout," -- PHASE 2 COMPLETED. %s\n",stim); fprintf(stdout,"\n %s\n END OF MODULE MMG3d: IMB-LJLL \n %s\n",MG_STR,MG_STR); /* save file */ _MMG5_outqua(&mesh,&met); if ( mesh.info.imprim > 3 && !mesh.info.iso ) _MMG5_prilen(&mesh,&met); chrono(ON,&MMG5_ctim[1]); if ( mesh.info.imprim ) fprintf(stdout,"\n -- WRITING DATA FILE %s\n",mesh.nameout); if ( !_MMG5_unscaleMesh(&mesh,&met) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); if ( !MMG5_saveMesh(&mesh) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); if ( !MMG5_saveMet(&mesh,&met) ) _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_STRONGFAILURE); chrono(OFF,&MMG5_ctim[1]); if ( mesh.info.imprim ) fprintf(stdout," -- WRITING COMPLETED\n"); /* free mem */ _MMG5_RETURN_AND_FREE(&mesh,&met,MMG5_SUCCESS); }