Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
main.c
Go to the documentation of this file.
1/* =============================================================================
2** This file is part of the mmg software package for the tetrahedral
3** mesh modification.
4** Copyright (c) Bx INP/Inria/UBordeaux/UPMC, 2004- .
5**
6** mmg is free software: you can redistribute it and/or modify it
7** under the terms of the GNU Lesser General Public License as published
8** by the Free Software Foundation, either version 3 of the License, or
9** (at your option) any later version.
10**
11** mmg is distributed in the hope that it will be useful, but WITHOUT
12** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13** FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14** License for more details.
15**
16** You should have received a copy of the GNU Lesser General Public
17** License and of the GNU General Public License along with mmg (in
18** files COPYING.LESSER and COPYING). If not, see
19** <http://www.gnu.org/licenses/>. Please read their terms carefully and
20** use this copy of the mmg distribution only if you accept them.
21** =============================================================================
22*/
23
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 "include/mmg" dir is in your include path
47//#include "libmmg.h"
48// if your include path do not contain the "mmg" subdirectories
49#include "mmg/libmmg.h"
50
51int main(int argc,char *argv[]) {
52 MMG5_pMesh mmgMesh;
53 MMG5_pSol mmgSol;
54 int ier;
55 char *filename,*filename_o2d,*filename_os,*filename_o3d,*ptr;
56
57 fprintf(stdout," -- TEST MMGLIB \n");
58
59 if ( argc != 4 ) {
60 printf(" Usage: %s 2d_filein 3d_filein fileout\n",argv[0]);
61 return(1);
62 }
63
66 /* Name and path of the mesh file */
67 filename = (char *) calloc(strlen(argv[1]) + 1, sizeof(char));
68 if ( filename == NULL ) {
69 perror(" ## Memory problem: calloc");
70 exit(EXIT_FAILURE);
71 }
72 strcpy(filename,argv[1]);
73
74 /* Name and path of the mesh file */
75
78 /* args of InitMesh:
79 * MMG5_ARG_start: we start to give the args of a variadic func
80 * MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
81 * &mmgMesh: pointer toward your MMG5_pMesh (that store your mesh)
82 * MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
83 * &mmgSol: pointer toward your MMG5_pSol (that store your metric) */
84 mmgMesh = NULL;
85 mmgSol = NULL;
87 MMG5_ARG_ppMesh,&mmgMesh, MMG5_ARG_ppMet,&mmgSol,
89
95 if ( MMG2D_loadMesh(mmgMesh,filename) != 1 ) exit(EXIT_FAILURE);
99 if ( MMG2D_loadSol(mmgMesh,mmgSol,filename) != 1 ) exit(EXIT_FAILURE);
100
103 ier = MMG2D_mmg2dlib(mmgMesh,mmgSol);
104
105 if ( ier == MMG5_STRONGFAILURE ) {
106 fprintf(stdout,"BAD ENDING OF MMG2DLIB: UNABLE TO SAVE MESH\n");
107 return(ier);
108 } else if ( ier == MMG5_LOWFAILURE )
109 fprintf(stdout,"BAD ENDING OF MMG2DLIB\n");
110
118 /*save result*/
119 filename_o2d = (char *) calloc(strlen(argv[3]) + 4, sizeof(char));
120 if ( filename_o2d == NULL ) {
121 perror(" ## Memory problem: calloc");
122 exit(EXIT_FAILURE);
123 }
124 strcpy(filename_o2d,argv[3]);
125 ptr = strstr(filename_o2d,".mesh");
126 if ( !ptr ) ptr = strstr(filename_o2d,".msh");
127 if ( ptr ) *ptr = '\0';
128 strcat(filename_o2d,".2d");
129
130 if ( MMG2D_saveMesh(mmgMesh,filename_o2d) != 1 ) exit(EXIT_FAILURE);
131 /*save metric*/
132 if ( MMG2D_saveSol(mmgMesh,mmgSol,filename_o2d) != 1 ) exit(EXIT_FAILURE);
133
136 MMG5_ARG_ppMesh,&mmgMesh, MMG5_ARG_ppMet,&mmgSol,
138
139 free(filename);
140 filename = NULL;
143 /* Name and path of the mesh file */
144 filename = (char *) calloc(strlen(argv[2]) + 1, sizeof(char));
145 if ( filename == NULL ) {
146 perror(" ## Memory problem: calloc");
147 exit(EXIT_FAILURE);
148 }
149 strcpy(filename,argv[2]);
150
151 filename_os = (char *) calloc(strlen(argv[3]) + 3, sizeof(char));
152 if ( filename_os == NULL ) {
153 perror(" ## Memory problem: calloc");
154 exit(EXIT_FAILURE);
155 }
156 strcpy(filename_os,argv[3]);
157 ptr = strstr(filename_os,".mesh");
158 if ( !ptr ) ptr = strstr(filename_os,".msh");
159 if ( ptr ) *ptr = '\0';
160 strcat(filename_os,".s");
161
164 /* args of InitMesh
165 * MMG5_ARG_start: we start to give the args of a variadic func
166 * MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
167 * &mmgMesh: pointer toward your MMG5_pMesh (that store your mesh)
168 * MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
169 * &mmgSol: pointer toward your MMG5_pSol (that store your metric) */
170
171 mmgMesh = NULL;
172 mmgSol = NULL;
174 MMG5_ARG_ppMesh,&mmgMesh, MMG5_ARG_ppMet,&mmgSol,
176
183 if ( MMGS_loadMesh(mmgMesh,filename) != 1 ) exit(EXIT_FAILURE);
189 if ( MMGS_loadSol(mmgMesh,mmgSol,filename) != 1 ) exit(EXIT_FAILURE);
190
193 ier = MMGS_mmgslib(mmgMesh,mmgSol);
194
195 if ( ier == MMG5_STRONGFAILURE ) {
196 fprintf(stdout,"BAD ENDING OF MMGSLIB: UNABLE TO SAVE MESH\n");
197 return(ier);
198 } else if ( ier == MMG5_LOWFAILURE )
199 fprintf(stdout,"BAD ENDING OF MMGSLIB\n");
200
208 if ( MMGS_saveMesh(mmgMesh,filename_os) != 1 ) exit(EXIT_FAILURE);
209
211 if ( MMGS_saveSol(mmgMesh,mmgSol,filename_os) != 1 ) exit(EXIT_FAILURE);
212
215 MMG5_ARG_ppMesh,&mmgMesh, MMG5_ARG_ppMet,&mmgSol,
217
219 filename_o3d = (char *) calloc(strlen(argv[3]) + 4, sizeof(char));
220 if ( filename_o3d == NULL ) {
221 perror(" ## Memory problem: calloc");
222 exit(EXIT_FAILURE);
223 }
224 strcpy(filename_o3d,argv[3]);
225 ptr = strstr(filename_o3d,".mesh");
226 if ( !ptr ) ptr = strstr(filename_o3d,".msh");
227 if ( ptr ) *ptr = '\0';
228 strcat(filename_o3d,".3d");
229
232 /* args of InitMesh:
233 * MMG5_ARG_start: we start to give the args of a variadic func
234 * MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
235 * &mmgMesh: pointer toward your MMG5_pMesh (that store your mesh)
236 * MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
237 * &mmgSol: pointer toward your MMG5_pSol (that store your metric) */
238 mmgMesh = NULL;
239 mmgSol = NULL;
241 MMG5_ARG_ppMesh,&mmgMesh, MMG5_ARG_ppMet,&mmgSol,
243
249 if ( MMG3D_loadMesh(mmgMesh,filename) != 1 ) exit(EXIT_FAILURE);
250
256 if ( MMG3D_loadSol(mmgMesh,mmgSol,filename) != 1 ) exit(EXIT_FAILURE);
257
260 ier = MMG3D_mmg3dlib(mmgMesh,mmgSol);
261
262 if ( ier == MMG5_STRONGFAILURE ) {
263 fprintf(stdout,"BAD ENDING OF MMG3DLIB: UNABLE TO SAVE MESH\n");
264 return(ier);
265 } else if ( ier == MMG5_LOWFAILURE )
266 fprintf(stdout,"BAD ENDING OF MMG3DLIB\n");
267
275 if ( MMG3D_saveMesh(mmgMesh,filename_o3d) != 1 ) exit(EXIT_FAILURE);
276
278 if ( MMG3D_saveSol(mmgMesh,mmgSol,filename_o3d) != 1 ) exit(EXIT_FAILURE);
279
282 MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppMet,&mmgSol,
284
285 free(filename);
286 free(filename_o2d);
287 free(filename_os);
288 free(filename_o3d);
289
290 return(0);
291}
int MMG2D_Init_mesh(const int starter,...)
Initialize a mesh structure and optionally the associated solution and metric structures.
int MMG2D_Free_all(const int starter,...)
Deallocations before return.
int MMG3D_Init_mesh(const int starter,...)
Initialize a mesh structure and optionally the associated solution and metric structures.
int MMG3D_Free_all(const int starter,...)
Deallocations before return.
int MMGS_Init_mesh(const int starter,...)
Initialize a mesh structure and optionally the associated solution and metric structures.
int MMGS_Free_all(const int starter,...)
Deallocations before return.
int ier
MMG5_pMesh char * filename
program main
Example for using mmglib (basic use)
Definition: main.F90:6
int MMG2D_saveMesh(MMG5_pMesh mesh, const char *filename)
Save a mesh in .mesh/.meshb format.
Definition: inout_2d.c:1101
int MMG2D_saveSol(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Save metric field in medit solution file format.
Definition: inout_2d.c:1617
int MMG2D_loadMesh(MMG5_pMesh mesh, const char *filename)
Load a mesh (in .mesh/.mesb format) from file.
Definition: inout_2d.c:28
int MMG2D_loadSol(MMG5_pMesh mesh, MMG5_pSol sol, const char *filename)
Load a metric field (or other solution) in medit's .sol format.
Definition: inout_2d.c:905
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 MMGS_loadSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
Load a metric field (or other solution) in medit's .sol format.
Definition: inout_s.c:1312
int MMGS_saveMesh(MMG5_pMesh mesh, const char *filename)
Save a mesh in .mesh or .meshb format.
Definition: inout_s.c:842
int MMGS_saveSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
Write an isotropic or anisotropic metric in medit file format.
Definition: inout_s.c:1483
int MMGS_loadMesh(MMG5_pMesh mesh, const char *filename)
Load a mesh (in .mesh/.mesb format) from file.
Definition: inout_s.c:41
int MMG2D_mmg2dlib(MMG5_pMesh mesh, MMG5_pSol met)
Main "program" for the mesh adaptation library.
Definition: libmmg2d.c:63
int MMG3D_mmg3dlib(MMG5_pMesh mesh, MMG5_pSol met)
Main "program" for the mesh adaptation library.
Definition: libmmg3d.c:975
int MMGS_mmgslib(MMG5_pMesh mesh, MMG5_pSol met)
Main "program" for mesh adaptation.
Definition: libmmgs.c:545
#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
#define MMG5_ARG_start
Definition: libmmgtypes.h:93
#define MMG5_ARG_ppMet
Definition: libmmgtypes.h:122
MMG mesh structure.
Definition: libmmgtypes.h:613