Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
main.c
Go to the documentation of this file.
1
35#include <assert.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <signal.h>
39#include <string.h>
40#include <ctype.h>
41#include <math.h>
42#include <float.h>
43
45// if the header file is in the "include" directory
46// #include "libmmg3d.h"
47// if the header file is in "include/mmg/mmg3d"
48#include "mmg/mmg3d/libmmg3d.h"
49
50int main(int argc,char *argv[]) {
51 MMG5_pMesh mmgMesh;
52 MMG5_pSol mmgLs,mmgMet;
53 MMG5_int np,k;
54 int ier;
55 char *inname,*outname,*lsname;
56
57 fprintf(stdout," -- TEST MMG3DLS \n");
58
59 if ( argc != 4 ) {
60 printf(" Usage: %s meshfile lsfile fileout\n",argv[0]);
61 return(1);
62 }
63
64 /* Name and path of the mesh files */
65 inname = (char *) calloc(strlen(argv[1]) + 1, sizeof(char));
66 if ( inname == NULL ) {
67 perror(" ## Memory problem: calloc");
68 exit(EXIT_FAILURE);
69 }
70 strcpy(inname,argv[1]);
71
72
73 lsname = (char *) calloc(strlen(argv[2]) + 1, sizeof(char));
74 if ( lsname == NULL ) {
75 perror(" ## Memory problem: calloc");
76 exit(EXIT_FAILURE);
77 }
78 strcpy(lsname,argv[2]);
79
80 outname = (char *) calloc(strlen(argv[3]) + 1, sizeof(char));
81 if ( outname == NULL ) {
82 perror(" ## Memory problem: calloc");
83 exit(EXIT_FAILURE);
84 }
85 strcpy(outname,argv[3]);
86
88 /* args of InitMesh:
89 * MMG5_ARG_start: we start to give the args of a variadic func
90 * MMG5_ARG_ppMesh: next arg will be a pointer to an MMG5_pMesh
91 * &mmgMesh: pointer to your MMG5_pMesh (that stores your mesh)
92 * MMG5_ARG_ppLs: next arg will be a pointer to an MMG5_pSol storing a level-set
93 * &mmgLs: pointer to your MMG5_pSol (that stores your level-set)
94 * MMG5_ARG_ppMet: next arg will be a pointer to an MMG5_pSol that will
95 * store the input metric
96 * &mmgMet: pointer to your MMG5_pSol (that will store the input metric) */
97 mmgMesh = NULL;
98 mmgLs = NULL;
99 mmgMet = NULL;
101 MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppLs,&mmgLs,
102 MMG5_ARG_ppMet,&mmgMet,
104
106 /* Ask for level set discretization: note that it is important to do this step
107 * here because in iso mode, some filters are applied at mesh loading */
108 if ( MMG3D_Set_iparameter(mmgMesh,mmgLs,MMG3D_IPARAM_iso, 1) != 1 )
109 exit(EXIT_FAILURE);
110
116 if ( MMG3D_loadMesh(mmgMesh,inname) != 1 ) exit(EXIT_FAILURE);
117
123 if ( MMG3D_loadSol(mmgMesh,mmgLs,lsname) != 1 )
124 exit(EXIT_FAILURE);
125
127 /* Manually for example */
131 if ( MMG3D_Get_meshSize(mmgMesh,&np,NULL,NULL,NULL,NULL,NULL) !=1 ) exit(EXIT_FAILURE);
132
133 if ( MMG3D_Set_solSize(mmgMesh,mmgMet,MMG5_Vertex,np,MMG5_Tensor) != 1 )
134 exit(EXIT_FAILURE);
135
137 for(k=1 ; k<=np ; k++) {
138 /* the Metric is constant over the mesh and follows the canonical
139 * directions: it is given by the tensor (10000,0,100) */
140 if ( MMG3D_Set_tensorSol(mmgMet,10,0,0,1,0,1,k) != 1 ) exit(EXIT_FAILURE);
141 }
142
143
145 if ( MMG3D_Chk_meshData(mmgMesh,mmgLs) != 1 ) exit(EXIT_FAILURE);
146
152 ier = MMG3D_mmg3dls(mmgMesh,mmgLs,mmgMet);
153
154 if ( ier == MMG5_STRONGFAILURE ) {
155 fprintf(stdout,"BAD ENDING OF MMG3DLS: UNABLE TO SAVE MESH\n");
156 return(ier);
157 } else if ( ier == MMG5_LOWFAILURE )
158 fprintf(stdout,"BAD ENDING OF MMG3DLS\n");
159
160 /* (Not mandatory) Automatically save the mesh */
161 if ( MMG3D_saveMesh(mmgMesh,outname) != 1 )
162 exit(EXIT_FAILURE);
163
164 /* (Not mandatory) Automatically save the output metric */
165 if ( MMG3D_saveSol(mmgMesh,mmgMet,outname) != 1 )
166 exit(EXIT_FAILURE);
167
168 /* 9) free the MMG3D5 structures */
170 MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppLs,&mmgLs,
171 MMG5_ARG_ppMet,&mmgMet,
173
174 free(inname);
175 inname = NULL;
176
177 free(outname);
178 outname = NULL;
179
180 free(lsname);
181 lsname = NULL;
182
183 return(ier);
184}
int MMG3D_Init_mesh(const int starter,...)
Initialize a mesh structure and optionally the associated solution and metric structures.
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_tensorSol(MMG5_pSol met, double m11, double m12, double m13, double m22, double m23, double m33, MMG5_int pos)
Set a single element of a tensor solution structure.
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_iparameter(MMG5_pMesh mesh, MMG5_pSol sol, int iparam, MMG5_int val)
set an integer parameter of the remesher
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_loadSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
Load a metric field (or other solution).
Definition: inout_3d.c:2143
int MMG3D_loadMesh(MMG5_pMesh mesh, const char *filename)
Load a mesh (in .mesh/.mesb format) from file.
Definition: inout_3d.c:1049
int MMG3D_saveSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
Write isotropic or anisotropic metric.
Definition: inout_3d.c:2314
int MMG3D_mmg3dls(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_pSol umet)
Main "program" for the level-set discretization library.
Definition: libmmg3d.c:1192
@ MMG3D_IPARAM_iso
Definition: libmmg3d.h:148
#define MMG5_ARG_ppMesh
Definition: libmmgtypes.h:102
#define MMG5_ARG_end
Definition: libmmgtypes.h:179
#define MMG5_ARG_ppLs
Definition: libmmgtypes.h:112
#define MMG5_STRONGFAILURE
Definition: libmmgtypes.h:65
#define MMG5_LOWFAILURE
Definition: libmmgtypes.h:57
@ MMG5_Tensor
Definition: libmmgtypes.h:221
#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