48#include "mmg/mmg3d/libmmg3d.h"
50#define MAX0(a,b) (((a) > (b)) ? (a) : (b))
51#define MAX4(a,b,c,d) (((MAX0(a,b)) > (MAX0(c,d))) ? (MAX0(a,b)) : (MAX0(c,d)))
53int main(
int argc,
char *argv[]) {
60 MMG5_int k,np,ne,nt,na,nc,nr,nreq,ref,Tetra[4],Tria[3],Edge[2];
62 int typEntity, typSol,iface[2];
63 int *corner, *required, *ridge;
65 char *fileout, *solout;
67 fprintf(stdout,
" -- TEST MMG3DLIB \n");
70 printf(
" Usage: %s fileout\n",argv[0]);
75 fileout = (
char *) calloc(strlen(argv[1]) + 6,
sizeof(char));
76 if ( fileout == NULL ) {
77 perror(
" ## Memory problem: calloc");
80 strcpy(fileout,argv[1]);
81 strcat(fileout,
".mesh");
83 solout = (
char *) calloc(strlen(argv[1]) + 5,
sizeof(char));
84 if ( solout == NULL ) {
85 perror(
" ## Memory problem: calloc");
88 strcpy(solout,argv[1]);
89 strcat(solout,
".sol");
182 for(k=1 ; k<=12 ; k++) {
194 fprintf(stdout,
"BAD ENDING OF MMG3DLIB: UNABLE TO SAVE MESH\n");
197 fprintf(stdout,
"BAD ENDING OF MMG3DLIB\n");
207 if( !(inm = fopen(fileout,
"w")) ) {
208 fprintf(stderr,
" ** UNABLE TO OPEN OUTPUT MESH FILE.\n");
211 fprintf(inm,
"MeshVersionFormatted 2\n");
212 fprintf(inm,
"\nDimension 3\n");
218 corner = (
int*)calloc(np+1,
sizeof(
int));
220 perror(
" ## Memory problem: calloc");
224 required = (
int*)calloc(
MAX4(np,ne,nt,na)+1 ,
sizeof(int));
226 perror(
" ## Memory problem: calloc");
230 ridge = (
int*)calloc(na+1 ,
sizeof(
int));
232 perror(
" ## Memory problem: calloc");
237 fprintf(inm,
"\nVertices\n%"MMG5_PRId
"\n",np);
238 for(k=1; k<=np; k++) {
241 &ref,&(corner[k]),&(required[k])) != 1 )
243 fprintf(inm,
"%.15lg %.15lg %.15lg %"MMG5_PRId
" \n",Point[0],Point[1],Point[2],ref);
244 if ( corner[k] ) nc++;
245 if ( required[k] ) nreq++;
247 fprintf(inm,
"\nCorners\n%"MMG5_PRId
"\n",nc);
248 for(k=1; k<=np; k++) {
249 if ( corner[k] ) fprintf(inm,
"%"MMG5_PRId
" \n",k);
251 fprintf(inm,
"\nRequiredVertices\n%"MMG5_PRId
"\n",nreq);
252 for(k=1; k<=np; k++) {
253 if ( required[k] ) fprintf(inm,
"%"MMG5_PRId
" \n",k);
259 fprintf(inm,
"\nTriangles\n%"MMG5_PRId
"\n",nt);
260 for(k=1; k<=nt; k++) {
263 &ref,&(required[k])) != 1 )
265 fprintf(inm,
"%"MMG5_PRId
" %"MMG5_PRId
" %"MMG5_PRId
" %"MMG5_PRId
" \n",Tria[0],Tria[1],Tria[2],ref);
266 if ( required[k] ) nreq++;
268 fprintf(inm,
"\nRequiredTriangles\n%"MMG5_PRId
"\n",nreq);
269 for(k=1; k<=nt; k++) {
270 if ( required[k] ) fprintf(inm,
"%"MMG5_PRId
" \n",k);
275 for(k=1; k<=nt; k++) {
276 ktet[0] = ktet[1] = 0;
277 iface[0] = iface[1] = 0;
280 printf(
"Get tet from tria fail.\n");
283 printf(
"Tria %"MMG5_PRId
" is connected with tet %"MMG5_PRId
" "
284 "(face %d) and %"MMG5_PRId
" (face %d) \n",
285 k,ktet[0],iface[0],ktet[1],iface[1]);
289 fprintf(inm,
"\nEdges\n%"MMG5_PRId
"\n",na);
290 for(k=1; k<=na; k++) {
293 &(ridge[k]),&(required[k])) != 1 ) exit(EXIT_FAILURE);
294 fprintf(inm,
"%"MMG5_PRId
" %"MMG5_PRId
" %"MMG5_PRId
" \n",Edge[0],Edge[1],ref);
295 if ( ridge[k] ) nr++;
296 if ( required[k] ) nreq++;
298 fprintf(inm,
"\nRequiredEdges\n%"MMG5_PRId
"\n",nreq);
299 for(k=1; k<=na; k++) {
300 if ( required[k] ) fprintf(inm,
"%"MMG5_PRId
" \n",k);
302 fprintf(inm,
"\nRidges\n%"MMG5_PRId
"\n",nr);
303 for(k=1; k<=na; k++) {
304 if ( ridge[k] ) fprintf(inm,
"%"MMG5_PRId
" \n",k);
308 fprintf(inm,
"\nTetrahedra\n%"MMG5_PRId
"\n",ne);
309 for(k=1; k<=ne; k++) {
312 &ref,&(required[k])) != 1 ) exit(EXIT_FAILURE);
313 fprintf(inm,
"%"MMG5_PRId
" %"MMG5_PRId
" %"MMG5_PRId
" %"MMG5_PRId
" %"MMG5_PRId
" \n",
314 Tetra[0],Tetra[1],Tetra[2],Tetra[3],ref);
315 if ( required[k] ) nreq++;
317 fprintf(inm,
"\nRequiredTetrahedra\n%"MMG5_PRId
"\n",nreq);
318 for(k=1; k<=ne; k++) {
319 if ( required[k] ) fprintf(inm,
"%"MMG5_PRId
" \n",k);
322 fprintf(inm,
"\nEnd\n");
331 if( !(inm = fopen(solout,
"w")) ) {
332 fprintf(stderr,
" ** UNABLE TO OPEN OUTPUT FILE.\n");
335 fprintf(inm,
"MeshVersionFormatted 2\n");
336 fprintf(inm,
"\nDimension 3\n");
346 fprintf(inm,
"\nSolAtVertices\n%"MMG5_PRId
"\n",np);
347 fprintf(inm,
"1 1 \n\n");
348 for(k=1; k<=np; k++) {
351 fprintf(inm,
"%.15lg \n",Sol);
353 fprintf(inm,
"\nEnd\n");
int MMG3D_Init_mesh(const int starter,...)
Initialize a mesh structure and optionally the associated solution and metric structures.
int MMG3D_Get_edge(MMG5_pMesh mesh, MMG5_int *e0, MMG5_int *e1, MMG5_int *ref, int *isRidge, int *isRequired)
Get the vertices and reference of the next edge in the mesh.
int MMG3D_Get_triangle(MMG5_pMesh mesh, MMG5_int *v0, MMG5_int *v1, MMG5_int *v2, MMG5_int *ref, int *isRequired)
Get the vertices and reference of the next triangle in the mesh.
int MMG3D_Set_tetrahedron(MMG5_pMesh mesh, MMG5_int v0, MMG5_int v1, MMG5_int v2, MMG5_int v3, MMG5_int ref, MMG5_int pos)
set a single tetrahedron's vertices
int MMG3D_Set_triangle(MMG5_pMesh mesh, MMG5_int v0, MMG5_int v1, MMG5_int v2, MMG5_int ref, MMG5_int pos)
Set the vertices and reference of a single triangle in a mesh.
int MMG3D_Get_tetrahedron(MMG5_pMesh mesh, MMG5_int *v0, MMG5_int *v1, MMG5_int *v2, MMG5_int *v3, MMG5_int *ref, int *isRequired)
Get the vertices and reference of the next tetrahedron in the mesh.
int MMG3D_Get_solSize(MMG5_pMesh mesh, MMG5_pSol sol, int *typEntity, MMG5_int *np, int *typSol)
Get the number of elements, dimension, and type of a solution structure.
int MMG3D_Set_scalarSol(MMG5_pSol met, double s, MMG5_int pos)
Set a single element of a scalar solution structure.
int MMG3D_Get_vertex(MMG5_pMesh mesh, double *c0, double *c1, double *c2, MMG5_int *ref, int *isCorner, int *isRequired)
Get the coordinates c0, c1,c2 and reference ref of the next vertex of mesh.
int MMG3D_Chk_meshData(MMG5_pMesh mesh, MMG5_pSol met)
Check if the number of given entities match with mesh and sol size.
int MMG3D_Set_vertex(MMG5_pMesh mesh, double c0, double c1, double c2, MMG5_int ref, MMG5_int pos)
Set the coordinates of a single vertex.
int MMG3D_Get_scalarSol(MMG5_pSol met, double *s)
Get the next element of a scalar solution structure defined at vertices.
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.
int MMG3D_Set_meshSize(MMG5_pMesh mesh, MMG5_int np, MMG5_int ne, MMG5_int nprism, MMG5_int nt, MMG5_int nquad, MMG5_int na)
Set the number of vertices, tetrahedra, prisms, triangles, quadrilaterals, and edges of a mesh.
int MMG3D_Set_solSize(MMG5_pMesh mesh, MMG5_pSol sol, int typEntity, MMG5_int np, int typSol)
Initialize a solution field.
program main
Example for using mmglib (basic use)
int MMG3D_mmg3dlib(MMG5_pMesh mesh, MMG5_pSol met)
Main "program" for the mesh adaptation library.
LIBMMG3D_EXPORT int MMG3D_Get_tetFromTria(MMG5_pMesh mesh, MMG5_int ktri, MMG5_int *ktet, int *iface)
Get a tetrahedron given one of its triangles and the index by which it refers to this triangle (DEPRE...
#define MMG5_STRONGFAILURE