Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
main.c
Go to the documentation of this file.
1
36#include <assert.h>
37#include <stdio.h>
38#include <stdlib.h>
39#include <signal.h>
40#include <string.h>
41#include <ctype.h>
42#include <math.h>
43#include <float.h>
44
46// if the header file is in the "include" directory
47// #include "libmmg3d.h"
48// if the header file is in "include/mmg/mmg3d"
49#include "mmg/mmg3d/libmmg3d.h"
50
51int main(int argc,char *argv[]) {
52 MMG5_pMesh mmgMesh;
53 MMG5_pSol mmgSol;
54 int ier,k;
55 char *outname;
56
57 fprintf(stdout," -- TEST MMG3DLIB \n");
58 if ( argc != 2 ) {
59 printf(" Usage: %s fileout \n",argv[0]);
60 return(1);
61 }
62
63 /* Name and path of the mesh files */
64 outname = (char *) calloc(strlen(argv[1]) + 1, sizeof(char));
65 if ( outname == NULL ) {
66 perror(" ## Memory problem: calloc");
67 exit(EXIT_FAILURE);
68 }
69 strcpy(outname,argv[1]);
70
73 /* args of InitMesh:
74 * MMG5_ARG_start: we start to give the args of a variadic func
75 * MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
76 * &mmgMesh: pointer to your MMG5_pMesh (that stores your mesh)
77 * MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
78 * &mmgSol: pointer to your MMG5_pSol (that stores your metric) */
79
80 mmgMesh = NULL;
81 mmgSol = NULL;
82
84 MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppMet,&mmgSol,
86
94 if ( MMG3D_Set_meshSize(mmgMesh,12,12,0,20,0,0) != 1 ) exit(EXIT_FAILURE);
95
98 mmgMesh->point[1].c[0] = 0.; mmgMesh->point[1].c[1] = 0.; mmgMesh->point[1].c[2] = 0.; mmgMesh->point[1].ref = 0;
99 /* or with the api function :
100 if ( MMG3D_Set_vertex(mmgMesh,0 ,0 ,0 ,0, 1) != 1 ) exit(EXIT_FAILURE); */
101 mmgMesh->point[2].c[0] = 0.5; mmgMesh->point[2].c[1] = 0; mmgMesh->point[2].c[2] = 0; mmgMesh->point[2].ref = 0;
102 mmgMesh->point[3].c[0] = 0.5; mmgMesh->point[3].c[1] = 0; mmgMesh->point[3].c[2] = 1; mmgMesh->point[3].ref = 0;
103 mmgMesh->point[4].c[0] = 0; mmgMesh->point[4].c[1] = 0; mmgMesh->point[4].c[2] = 1; mmgMesh->point[4].ref = 0;
104 mmgMesh->point[5].c[0] = 0; mmgMesh->point[5].c[1] = 1; mmgMesh->point[5].c[2] = 0; mmgMesh->point[5].ref = 0;
105 mmgMesh->point[6].c[0] = 0.5; mmgMesh->point[6].c[1] = 1; mmgMesh->point[6].c[2] = 0; mmgMesh->point[6].ref = 0;
106 mmgMesh->point[7].c[0] = 0.5; mmgMesh->point[7].c[1] = 1; mmgMesh->point[7].c[2] = 1; mmgMesh->point[7].ref = 0;
107 mmgMesh->point[8].c[0] = 0; mmgMesh->point[8].c[1] = 1; mmgMesh->point[8].c[2] = 1; mmgMesh->point[8].ref = 0;
108 mmgMesh->point[9].c[0] = 1; mmgMesh->point[9].c[1] = 0; mmgMesh->point[9].c[2] = 0; mmgMesh->point[9].ref = 0;
109 mmgMesh->point[10].c[0] = 1; mmgMesh->point[10].c[1] = 1; mmgMesh->point[10].c[2] = 0; mmgMesh->point[10].ref = 0;
110 mmgMesh->point[11].c[0] = 1; mmgMesh->point[11].c[1] = 0; mmgMesh->point[11].c[2] = 1; mmgMesh->point[11].ref = 0;
111 mmgMesh->point[12].c[0] = 1; mmgMesh->point[12].c[1] = 1; mmgMesh->point[12].c[2] = 1; mmgMesh->point[12].ref = 0;
112
113 /*tetra*/
114 mmgMesh->tetra[1].v[0] = 1; mmgMesh->tetra[1].v[1] = 2; mmgMesh->tetra[1].v[2] = 4; mmgMesh->tetra[1].v[3] = 8; mmgMesh->tetra[1].ref = 1;
115 /* or with the api function :
116 if ( MMG3D_Set_tetrahedra(mmgMesh,1 ,2 ,4 ,8, 1) != 1 ) exit(EXIT_FAILURE); */
117 mmgMesh->tetra[2].v[0] = 8; mmgMesh->tetra[2].v[1] = 3; mmgMesh->tetra[2].v[2] = 2; mmgMesh->tetra[2].v[3] = 7; mmgMesh->tetra[2].ref = 1;
118 mmgMesh->tetra[3].v[0] = 2; mmgMesh->tetra[3].v[1] = 5; mmgMesh->tetra[3].v[2] = 6; mmgMesh->tetra[3].v[3] = 8; mmgMesh->tetra[3].ref = 1;
119 mmgMesh->tetra[4].v[0] = 8; mmgMesh->tetra[4].v[1] = 5; mmgMesh->tetra[4].v[2] = 1; mmgMesh->tetra[4].v[3] = 2; mmgMesh->tetra[4].ref = 1;
120 mmgMesh->tetra[5].v[0] = 2; mmgMesh->tetra[5].v[1] = 7; mmgMesh->tetra[5].v[2] = 8; mmgMesh->tetra[5].v[3] = 6; mmgMesh->tetra[5].ref = 1;
121 mmgMesh->tetra[6].v[0] = 2; mmgMesh->tetra[6].v[1] = 4; mmgMesh->tetra[6].v[2] = 3; mmgMesh->tetra[6].v[3] = 8; mmgMesh->tetra[6].ref = 1;
122 mmgMesh->tetra[7].v[0] = 2; mmgMesh->tetra[7].v[1] = 9; mmgMesh->tetra[7].v[2] = 3; mmgMesh->tetra[7].v[3] = 7; mmgMesh->tetra[7].ref = 2;
123 mmgMesh->tetra[8].v[0] = 7; mmgMesh->tetra[8].v[1] = 11; mmgMesh->tetra[8].v[2] = 9; mmgMesh->tetra[8].v[3] = 12; mmgMesh->tetra[8].ref = 2;
124 mmgMesh->tetra[9].v[0] = 9; mmgMesh->tetra[9].v[1] = 6; mmgMesh->tetra[9].v[2] = 10; mmgMesh->tetra[9].v[3] = 7; mmgMesh->tetra[9].ref = 2;
125 mmgMesh->tetra[10].v[0] = 7; mmgMesh->tetra[10].v[1] = 6; mmgMesh->tetra[10].v[2] = 2; mmgMesh->tetra[10].v[3] = 9; mmgMesh->tetra[10].ref = 2;
126 mmgMesh->tetra[11].v[0] = 9; mmgMesh->tetra[11].v[1] = 12; mmgMesh->tetra[11].v[2] = 7; mmgMesh->tetra[11].v[3] = 10; mmgMesh->tetra[11].ref = 2;
127 mmgMesh->tetra[12].v[0] = 9; mmgMesh->tetra[12].v[1] = 3; mmgMesh->tetra[12].v[2] = 11; mmgMesh->tetra[12].v[3] = 7; mmgMesh->tetra[12].ref = 2;
128
136 if ( MMG3D_Set_solSize(mmgMesh,mmgSol,MMG5_Vertex,12,MMG5_Scalar) != 1 )
137 exit(EXIT_FAILURE);
138
140 for(k=1 ; k<=12 ; k++) {
141 mmgSol->m[k] = 0.5;
142 /* or with the api function :
143 if ( MMG3D_Set_scalarSol(mmgSol,0.5,k) != 1 ) exit(EXIT_FAILURE); */
144 }
149
151 if ( MMG3D_Chk_meshData(mmgMesh,mmgSol) != 1 ) exit(EXIT_FAILURE);
152
155 // WARNING: the MMG3D_mmg3dlib function returns 1 if success, 0 if fail.
156 // The MMG3D4 library was working opposite.
157 ier = MMG3D_mmg3dlib(mmgMesh,mmgSol);
158
159 if ( ier == MMG5_STRONGFAILURE ) {
160 fprintf(stdout,"BAD ENDING OF MMG3DLIB: UNABLE TO SAVE MESH\n");
161 return(ier);
162 } else if ( ier == MMG5_LOWFAILURE )
163 fprintf(stdout,"BAD ENDING OF MMG3DLIB\n");
164
165
173 if ( MMG3D_saveMesh(mmgMesh,outname) != 1 ) exit(EXIT_FAILURE);
174
176 if ( MMG3D_saveSol(mmgMesh,mmgSol,outname) !=1 ) exit(EXIT_FAILURE);
177
180 MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppMet,&mmgSol,
182 free(outname);
183 outname = NULL;
184
185 return(ier);
186}
int MMG3D_Init_mesh(const int starter,...)
Initialize a mesh structure and optionally the associated solution and metric structures.
void MMG3D_Set_handGivenMesh(MMG5_pMesh mesh)
Finish providing mesh data without using the API functions.
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_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.
int ier
program main
Example for using mmglib (basic use)
Definition: main.F90:6
int MMG3D_saveMesh(MMG5_pMesh mesh, const char *filename)
Save a mesh in .mesh/.meshb format.
Definition: inout_3d.c:1273
int MMG3D_saveSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
Write isotropic or anisotropic metric.
Definition: inout_3d.c:2314
int MMG3D_mmg3dlib(MMG5_pMesh mesh, MMG5_pSol met)
Main "program" for the mesh adaptation library.
Definition: libmmg3d.c:975
#define MMG5_ARG_ppMesh
Definition: libmmgtypes.h:102
#define MMG5_ARG_end
Definition: libmmgtypes.h:179
#define MMG5_STRONGFAILURE
Definition: libmmgtypes.h:65
#define MMG5_LOWFAILURE
Definition: libmmgtypes.h:57
@ MMG5_Scalar
Definition: libmmgtypes.h:219
#define MMG5_ARG_start
Definition: libmmgtypes.h:93
@ MMG5_Vertex
Definition: libmmgtypes.h:230
#define MMG5_ARG_ppMet
Definition: libmmgtypes.h:122
MMG mesh structure.
Definition: libmmgtypes.h:613
MMG5_pPoint point
Definition: libmmgtypes.h:649
MMG5_pTetra tetra
Definition: libmmgtypes.h:651
double c[3]
Definition: libmmgtypes.h:277
MMG5_int ref
Definition: libmmgtypes.h:284
double * m
Definition: libmmgtypes.h:680
MMG5_int v[4]
Definition: libmmgtypes.h:409
MMG5_int ref
Definition: libmmgtypes.h:410