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 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 toward your MMG5_pMesh (that store your mesh)
77 * MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
78 * &mmgSol: pointer toward your MMG5_pSol (that store 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,...)
void MMG3D_Set_handGivenMesh(MMG5_pMesh mesh)
int MMG3D_Chk_meshData(MMG5_pMesh mesh, MMG5_pSol met)
int MMG3D_Free_all(const int starter,...)
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)
int MMG3D_Set_solSize(MMG5_pMesh mesh, MMG5_pSol sol, int typEntity, MMG5_int np, int typSol)
int ier
program main
Example for using mmglib (basic use)
Definition main.F90:6
int MMG3D_saveMesh(MMG5_pMesh mesh, const char *filename)
Definition inout_3d.c:1259
int MMG3D_saveSol(MMG5_pMesh mesh, MMG5_pSol met, const char *filename)
Definition inout_3d.c:2300
int MMG3D_mmg3dlib(MMG5_pMesh mesh, MMG5_pSol met)
Definition libmmg3d.c:975
#define MMG5_ARG_ppMesh
Definition libmmgtypes.h:96
#define MMG5_ARG_end
#define MMG5_STRONGFAILURE
Definition libmmgtypes.h:59
#define MMG5_LOWFAILURE
Definition libmmgtypes.h:51
@ MMG5_Scalar
#define MMG5_ARG_start
Definition libmmgtypes.h:87
@ MMG5_Vertex
#define MMG5_ARG_ppMet
MMG mesh structure.
MMG5_pPoint point
MMG5_pTetra tetra
double c[3]
MMG5_int ref
double * m
MMG5_int v[4]
MMG5_int ref