50#include "mmg/mmg3d/libmmg3d.h"
52int main(
int argc,
char *argv[]) {
57 char *fileout_generic,*fileout_medit,*filein;
60 fprintf(stdout,
" -- TEST LOAD AND GET MESH DATA \n");
63 printf(
" Usage: %s filein fileout silent_mode\n",argv[0]);
68 filein = (
char *) calloc(strlen(argv[1]) + 1,
sizeof(char));
69 if ( filein == NULL ) {
70 perror(
" ## Memory problem: calloc");
73 strcpy(filein,argv[1]);
75 fileout_generic = (
char *) calloc(strlen(argv[2])+1,
sizeof(char));
76 if ( fileout_generic == NULL ) {
77 perror(
" ## Memory problem: calloc");
80 strcpy(fileout_generic,argv[2]);
82 fileout_medit = (
char *) calloc(strlen(argv[2]) + 6,
sizeof(char));
83 if ( fileout_medit == NULL ) {
84 perror(
" ## Memory problem: calloc");
87 strcpy(fileout_medit,argv[2]);
88 strcat(fileout_medit,
".mesh");
90 silent = atoi(argv[3]);
112 fprintf(stderr,
" ** %s NOT FOUND.\n",filein);
113 fprintf(stderr,
" ** UNABLE TO OPEN INPUT FILE.\n");
117 assert (
ier == -1 );
118 fprintf(stderr,
" ** UNABLE TO READ INPUT FILE.\n");
127 MMG5_int np, ne, nt, na;
129 fprintf(stderr,
" ERROR: Unable to get mesh size.\n");
138 points = (
double *)malloc(3*np*
sizeof(
double));
140 ref = (MMG5_int *)malloc(np*
sizeof(MMG5_int));
145 fprintf(stderr,
" ERROR: Unable to get mesh vertices.\n");
151 MMG5_int *tetref=NULL, *tetra=NULL;
153 tetra = (MMG5_int *)malloc(4*ne*
sizeof(MMG5_int));
155 tetref = (MMG5_int *)malloc(ne*
sizeof(MMG5_int));
160 fprintf(stderr,
" ERROR: Unable to get mesh tetra.\n");
169 if( !(inm = fopen(fileout_medit,
"w")) ) {
170 fprintf(stderr,
" ** UNABLE TO OPEN OUTPUT MESH FILE.\n");
174 fprintf(inm,
"MeshVersionFormatted 2\n");
175 fprintf(inm,
"\nDimension 3\n");
178 fprintf(inm,
"\nVertices\n%"MMG5_PRId
"\n",np);
179 for(k=1; k<=np; k++) {
180 MMG5_int address = 3*(k-1);
181 fprintf(inm,
"%.15lg %.15lg %.15lg %"MMG5_PRId
" \n",
182 points[address],points[address+1],points[address+2],ref[k-1]);
186 fprintf(inm,
"\nTetrahedra\n%"MMG5_PRId
"\n",ne);
187 for(k=1; k<=ne; k++) {
188 MMG5_int address = 4*(k-1);
189 fprintf(inm,
"%"MMG5_PRId
" %"MMG5_PRId
" %"MMG5_PRId
" %"MMG5_PRId
" %"
190 MMG5_PRId
" \n",tetra[address],tetra[address+1],
191 tetra[address+2],tetra[address+3],tetref[k-1]);
194 fprintf(inm,
"\nEnd\n");
198 free(points); free(ref);
199 free(tetra); free(tetref);
201 fileout_medit = NULL;
204 for ( k=1; k<=ne; ++k ) {
208 fprintf(stderr,
" ERROR: Unable to get adjacents of tetra %"MMG5_PRId
".\n",k);
213 fprintf(stdout,
"Tetra %"MMG5_PRId
" is adjacent to tetras %"MMG5_PRId
" %"
214 MMG5_PRId
" %"MMG5_PRId
" %"MMG5_PRId
"\n",
215 k,adja[0],adja[1],adja[2],adja[3]);
224 fprintf(stderr,
" ** %s NOT FOUND.\n",fileout_generic);
225 fprintf(stderr,
" ** UNABLE TO OPEN INPUT FILE.\n");
229 free(fileout_generic);
230 fileout_generic = NULL;
237 return(EXIT_SUCCESS);
int MMG3D_Init_mesh(const int starter,...)
Initialize a mesh structure and optionally the associated solution and metric structures.
int MMG3D_Get_vertices(MMG5_pMesh mesh, double *vertices, MMG5_int *refs, int *areCorners, int *areRequired)
Get the coordinates and references of all vertices in the mesh.
int MMG3D_Get_tetrahedra(MMG5_pMesh mesh, MMG5_int *tetra, MMG5_int *refs, int *areRequired)
Get the vertices and reference of all tetrahedra in the mesh.
int MMG3D_Get_meshSize(MMG5_pMesh mesh, MMG5_int *np, MMG5_int *ne, MMG5_int *nprism, MMG5_int *nt, MMG5_int *nquad, MMG5_int *na)
Get the number of vertices, tetrahedra, prisms, triangles, quadrilaterals and edges of the mesh.
int MMG3D_Free_all(const int starter,...)
Deallocations before return.
program main
Example for using mmglib (basic use)
int MMG3D_saveGenericMesh(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Save mesh data in a file whose format depends on the filename extension.
int MMG3D_loadGenericMesh(MMG5_pMesh mesh, MMG5_pSol met, MMG5_pSol sol, const char *filename)
Read mesh data in a format determined by the filename extension.
LIBMMG3D_EXPORT int MMG3D_Get_adjaTet(MMG5_pMesh mesh, MMG5_int kel, MMG5_int listet[4])
Return adjacent elements of a tetrahedron.