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*/
24
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;
55 char *filename, *fileout;
56
57 fprintf(stdout," -- TEST MMG3DLIB \n");
58
59 if ( argc != 3 ) {
60 printf(" Usage: %s filein fileout \n",argv[0]);
61 return(1);
62 }
63
64 /* Name and path of the mesh file */
65 filename = (char *) calloc(strlen(argv[1]) + 1, sizeof(char));
66 if ( filename == NULL ) {
67 perror(" ## Memory problem: calloc");
68 exit(EXIT_FAILURE);
69 }
70 strcpy(filename,argv[1]);
71
72 fileout = (char *) calloc(strlen(argv[2]) + 1, sizeof(char));
73 if ( fileout == NULL ) {
74 perror(" ## Memory problem: calloc");
75 exit(EXIT_FAILURE);
76 }
77 strcpy(fileout,argv[2]);
78
81 /* args of InitMesh:
82 * MMG5_ARG_start: we start to give the args of a variadic func
83 * MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
84 * &mmgMesh: pointer toward your MMG5_pMesh (that store your mesh)
85 * MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
86 * &mmgSol: pointer toward your MMG5_pSol (that store your metric) */
87
88 mmgMesh = NULL;
89 mmgSol = NULL;
90
92 MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppMet,&mmgSol,
94
100 if ( MMG3D_loadMesh(mmgMesh,filename) != 1 ) exit(EXIT_FAILURE);
101
107 if ( MMG3D_loadSol(mmgMesh,mmgSol,filename) != 1 )
108 exit(EXIT_FAILURE);
109
111 if ( MMG3D_Chk_meshData(mmgMesh,mmgSol) != 1 ) exit(EXIT_FAILURE);
112
115 ier = MMG3D_mmg3dlib(mmgMesh,mmgSol);
116
117
118
119 if ( ier == MMG5_STRONGFAILURE ) {
120 fprintf(stdout,"BAD ENDING OF MMG3DLIB: UNABLE TO SAVE MESH\n");
121 return(ier);
122 } else if ( ier == MMG5_LOWFAILURE )
123 fprintf(stdout,"BAD ENDING OF MMG3DLIB\n");
124
132 if ( MMG3D_saveMesh(mmgMesh,fileout) != 1 ) {
133 fprintf(stdout,"UNABLE TO SAVE MESH\n");
134 return(MMG5_STRONGFAILURE);
135 }
136
138 if ( MMG3D_saveSol(mmgMesh,mmgSol,fileout) != 1 ) {
139 fprintf(stdout,"UNABLE TO SAVE SOL\n");
140 return(MMG5_LOWFAILURE);
141 }
142
145 MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppMet,&mmgSol,
147
148 free(filename);
149 filename = NULL;
150
151 free(fileout);
152 fileout = NULL;
153
154 return(ier);
155}
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_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 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_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
#define MMG5_ARG_start
Definition: libmmgtypes.h:93
#define MMG5_ARG_ppMet
Definition: libmmgtypes.h:122
MMG mesh structure.
Definition: libmmgtypes.h:613