Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
main_optim.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
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 "libmmg2d.h"
47// if the header file is in "include/mmg/mmg2d"
48#include "mmg/mmg2d/libmmg2d.h"
49
50int main(int argc,char *argv[]) {
51 MMG5_pMesh mmgMesh;
52 MMG5_pSol mmgLs,mmgMet;
53 int ier;
54 char *inname,*lsname,*outname;
55
56 fprintf(stdout," -- TEST MMG2DLS \n");
57
58 if ( argc != 4 ) {
59 printf(" Usage: %s meshfile lsfile meshout\n",argv[0]);
60 return(1);
61 }
62
63 /* Name and path of the mesh files */
64 inname = (char *) calloc(strlen(argv[1]) + 1, sizeof(char));
65 if ( inname == NULL ) {
66 perror(" ## Memory problem: calloc");
67 exit(EXIT_FAILURE);
68 }
69 strcpy(inname,argv[1]);
70
71 lsname = (char *) calloc(strlen(argv[2]) + 1, sizeof(char));
72 if ( lsname == NULL ) {
73 perror(" ## Memory problem: calloc");
74 exit(EXIT_FAILURE);
75 }
76 strcpy(lsname,argv[2]);
77
78
79 outname = (char *) calloc(strlen(argv[3]) + 1, sizeof(char));
80 if ( outname == NULL ) {
81 perror(" ## Memory problem: calloc");
82 exit(EXIT_FAILURE);
83 }
84 strcpy(outname,argv[3]);
85
87 /* args of InitMesh:
88 * MMG5_ARG_start: we start to give the args of a variadic func
89 * MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
90 * &mmgMesh: pointer toward your MMG5_pMesh (that store your mesh)
91 * MMG5_ARG_ppLs: next arg will be a pointer over a MMG5_pSol storing a level-set
92 * &mmgLs: pointer toward your MMG5_pSol (that store your level-set)
93 */
94 mmgMesh = NULL;
95 mmgLs = NULL;
96 mmgMet = NULL;
98 MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppLs,&mmgLs,
99 MMG5_ARG_ppMet,&mmgMet,
101
103 /* Ask for level set discretization: note that it is important to do this step
104 * here because in iso mode, some filters are applied at mesh loading */
105 if ( MMG2D_Set_iparameter(mmgMesh,NULL,MMG2D_IPARAM_iso, 1) != 1 )
106 exit(EXIT_FAILURE);
107
108 /* Ask for optim mode: compute the mean of input edge lengths */
109 if ( MMG2D_Set_iparameter(mmgMesh,NULL,MMG2D_IPARAM_optim, 1) != 1 )
110 exit(EXIT_FAILURE);
111
112 /* Ask to do this with anisotropic metric. */
113 if ( MMG2D_Set_iparameter(mmgMesh,NULL,MMG2D_IPARAM_anisosize, 1) != 1 )
114 exit(EXIT_FAILURE);
115
121 if ( MMG2D_loadMesh(mmgMesh,inname) != 1 ) exit(EXIT_FAILURE);
122
127 if ( MMG2D_loadSol(mmgMesh,mmgLs,lsname) != 1 )
128 exit(EXIT_FAILURE);
129
131 if ( MMG2D_Chk_meshData(mmgMesh,mmgLs) != 1 ) exit(EXIT_FAILURE);
132
142 ier = MMG2D_mmg2dls(mmgMesh,mmgLs,mmgMet);
143
144 if ( ier == MMG5_STRONGFAILURE ) {
145 fprintf(stdout,"BAD ENDING OF MMG2DLS: UNABLE TO SAVE MESH\n");
146 return(ier);
147 } else if ( ier == MMG5_LOWFAILURE )
148 fprintf(stdout,"BAD ENDING OF MMG2DLS\n");
149
150 /* (Not mandatory) Automatically save the mesh */
151 if ( MMG2D_saveMesh(mmgMesh,outname) != 1 )
152 exit(EXIT_FAILURE);
153
154 /* (Not mandatory) Automatically save the output metric */
155 if ( MMG2D_saveSol(mmgMesh,mmgMet,outname) != 1 )
156 exit(EXIT_FAILURE);
157
158 /* 9) free the MMG2D5 structures */
160 MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppLs,&mmgLs,
161 MMG5_ARG_ppMet,&mmgMet,
163
164 free(inname);
165 inname = NULL;
166
167 free(outname);
168 outname = NULL;
169
170 free(lsname);
171 outname = NULL;
172
173 return(ier);
174}
int MMG2D_Init_mesh(const int starter,...)
Initialize a mesh structure and optionally the associated solution and metric structures.
int MMG2D_Set_iparameter(MMG5_pMesh mesh, MMG5_pSol sol, int iparam, MMG5_int val)
Set integer parameter iparam to value val.
int MMG2D_Chk_meshData(MMG5_pMesh mesh, MMG5_pSol met)
Check if the number of given entities match with mesh and sol size.
int MMG2D_Free_all(const int starter,...)
Deallocations before return.
int ier
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 MMG2D_mmg2dls(MMG5_pMesh mesh, MMG5_pSol sol, MMG5_pSol umet)
Main "program" for the level-set discretization library.
Definition: libmmg2d.c:524
@ MMG2D_IPARAM_iso
Definition: libmmg2d.h:116
@ MMG2D_IPARAM_optim
Definition: libmmg2d.h:121
@ MMG2D_IPARAM_anisosize
Definition: libmmg2d.h:132
#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
#define MMG5_ARG_start
Definition: libmmgtypes.h:93
#define MMG5_ARG_ppMet
Definition: libmmgtypes.h:122
MMG mesh structure.
Definition: libmmgtypes.h:613