/** * \param mesh pointer toward the mesh structure. * \param np number of vertices. * \param nt number of triangles. * \param na number of edges. * \return 0 if failed, 1 otherwise. * * Set the number of vertices, triangles and edges of the * mesh and allocate the associated tables. If call twice, reset the * whole mesh to realloc it at the new size * */ int MMGS_Set_meshSize(MMG5_pMesh mesh, int np, int nt, int na) { int k; if ( ( (mesh->info.imprim > 5) || mesh->info.ddebug ) && ( mesh->point || mesh->tria || mesh->edge) ) fprintf(stdout," ## Warning: new mesh\n"); mesh->np = np; mesh->nt = nt; mesh->na = na; mesh->npi = mesh->np; mesh->nti = mesh->nt; mesh->nai = mesh->na; if ( mesh->point ) _MMG5_DEL_MEM(mesh,mesh->point,(mesh->npmax+1)*sizeof(MMG5_Point)); if ( mesh->tria ) _MMG5_DEL_MEM(mesh,mesh->tria,(mesh->nt+1)*sizeof(MMG5_Tria)); if ( mesh->edge ) _MMG5_DEL_MEM(mesh,mesh->edge,(mesh->na+1)*sizeof(MMG5_Edge)); /*tester si -m defini : renvoie 0 si pas ok et met la taille min dans info.mem */ if( mesh->info.mem > 0) { if ( mesh->npmax < mesh->np || mesh->ntmax < mesh->nt) { _MMGS_memOption(mesh); // printf("pas de pbs ? %d %d %d %d %d %d -- %d\n",mesh->npmax,mesh->np, // mesh->ntmax,mesh->nt,mesh->nemax,mesh->ne,mesh->info.mem); if ( mesh->npmax < mesh->np || mesh->ntmax < mesh->nt) { fprintf(stdout,"not enough memory: np : %d %d nt : %d %d \n" ,mesh->npmax,mesh->np, mesh->ntmax,mesh->nt); return(0); } } else if(mesh->info.mem < 39) { printf("not enough memory %d\n",mesh->info.mem); return(0); } } else { mesh->npmax = MG_MAX(1.5*mesh->np,_MMG5_NPMAX); mesh->ntmax = MG_MAX(1.5*mesh->nt,_MMG5_NTMAX); } _MMG5_ADD_MEM(mesh,(mesh->npmax+1)*sizeof(MMG5_Point),"initial vertices", printf(" Exit program.\n"); exit(EXIT_FAILURE)); _MMG5_SAFE_CALLOC(mesh->point,mesh->npmax+1,MMG5_Point); _MMG5_ADD_MEM(mesh,(mesh->ntmax+1)*sizeof(MMG5_Tria),"initial triangles",return(0)); _MMG5_SAFE_CALLOC(mesh->tria,mesh->ntmax+1,MMG5_Tria); mesh->namax = mesh->na; if ( mesh->na ) { _MMG5_ADD_MEM(mesh,(mesh->na+1)*sizeof(MMG5_Edge),"initial edges",return(0)); _MMG5_SAFE_CALLOC(mesh->edge,(mesh->na+1),MMG5_Edge); }
/** * \param mesh pointer toward the mesh structure. * \param sol pointer toward the sol structure. * \param typEntity type of solutions entities (vertices, triangles...). * \param np number of solutions. * \param typSol type of solution (scalar, vectorial...). * \return 0 if failed, 1 otherwise. * * Set the solution number, dimension and type. * */ int MMGS_Set_solSize(MMG5_pMesh mesh, MMG5_pSol sol, int typEntity, int np, int typSol) { if ( ( (mesh->info.imprim > 5) || mesh->info.ddebug ) && sol->m ) fprintf(stdout," ## Warning: new solution\n"); if ( typEntity != MMG5_Vertex ) { fprintf(stdout," ## Error: MMG3D5 need a solution imposed on vertices\n"); return(0); } if ( typSol == MMG5_Scalar ) { sol->size = 1; } else if ( typSol == MMG5_Vector ) { sol->size = 3; } else if ( typSol == MMG5_Tensor ) { sol->size = 6; } else { fprintf(stdout," ## Error: type of solution not yet implemented\n"); return(0); } sol->dim = 3; if ( np ) { sol->np = np; sol->npi = np; if ( sol->m ) _MMG5_DEL_MEM(mesh,sol->m,(sol->size*(sol->npmax+1))*sizeof(double)); sol->npmax = mesh->npmax; _MMG5_ADD_MEM(mesh,(sol->size*(sol->npmax+1))*sizeof(double),"initial solution", printf(" Exit program.\n"); exit(EXIT_FAILURE)); _MMG5_SAFE_CALLOC(sol->m,(sol->size*(sol->npmax+1)),double); } return(1); }
/** * \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); }