Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
main.c
Go to the documentation of this file.
1
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 mmgMetric, mmgDisp;
54 int ier;
55 char *inname, *outname;
56
57 fprintf(stdout, " -- TEST MMG3DMOV \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 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 outname = (char *) calloc(strlen(argv[2]) + 1, sizeof(char));
73 if ( outname == NULL ) {
74 perror(" ## Memory problem: calloc");
75 exit(EXIT_FAILURE);
76 }
77 strcpy(outname,argv[2]);
78
80 /* args of InitMesh:
81 * MMG5_ARG_start: we start to give the args of a variadic function
82 * MMG5_ARG_ppMesh: next arg will be a pointer to an MMG5_pMesh
83 * &mmgMesh: pointer to your MMG5_pMesh (that stores your mesh)
84 * MMG5_ARG_ppMet: next arg will be a pointer to MMG5_pSol storing a metric
85 * &mmgMetric: pointer to an MMG5_pSol that stores your metric field
86 * MMG5_ARG_ppDisp: next arg will be a pointer to MMG5_pSol storing a displacement
87 * &mmgDisp: pointer to an MMG5_pSol that stores your displacement field
88 * In this example the metric field is not used but it must be provided
89 * to MMG3D_mmg3dmov() and therefore it must be initialized; it cannot
90 * remain a NULL pointer. */
91 mmgMesh = NULL;
92 mmgMetric = NULL;
93 mmgDisp = NULL;
95 MMG5_ARG_ppMesh, &mmgMesh,
96 MMG5_ARG_ppMet, &mmgMetric,
97 MMG5_ARG_ppDisp, &mmgDisp,
99
105 if ( MMG3D_loadMesh(mmgMesh, inname) != 1 ) exit(EXIT_FAILURE);
106
112 /* Ask for lagrangian motion (mode 1) */
113 if ( MMG3D_Set_iparameter(mmgMesh, mmgDisp, MMG3D_IPARAM_lag, 1) != 1 )
114 exit(EXIT_FAILURE);
115
117 if ( MMG3D_loadSol(mmgMesh, mmgDisp, inname) != 1 )
118 exit(EXIT_FAILURE);
119
121 if ( MMG3D_Chk_meshData(mmgMesh, mmgDisp) != 1 ) exit(EXIT_FAILURE);
122
130 /* debug mode ON (default value = OFF) */
131 if ( MMG3D_Set_iparameter(mmgMesh, mmgDisp, MMG3D_IPARAM_debug, 1) != 1 )
132 exit(EXIT_FAILURE);
133
135 ier = MMG3D_mmg3dmov(mmgMesh, mmgMetric, mmgDisp);
136
137 if ( ier == MMG5_STRONGFAILURE ) {
138 fprintf(stdout,"BAD ENDING OF MMG3DMOV: UNABLE TO SAVE MESH\n");
139 return(ier);
140 } else if ( ier == MMG5_LOWFAILURE )
141 fprintf(stdout,"BAD ENDING OF MMG3DMOV\n");
142
143 /* (Not mandatory) Automatically save the mesh */
144 if ( MMG3D_saveMesh(mmgMesh, outname) != 1 )
145 exit(EXIT_FAILURE);
146
147 /* 9) free the MMG3D5 structures */
149 MMG5_ARG_ppMesh, &mmgMesh,
150 MMG5_ARG_ppMet, &mmgMetric,
151 MMG5_ARG_ppDisp, &mmgDisp,
153 free(inname);
154 inname = NULL;
155
156 free(outname);
157 outname = NULL;
158
159 return(ier);
160}
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 MMG3D_Set_iparameter(MMG5_pMesh mesh, MMG5_pSol sol, int iparam, MMG5_int val)
set an integer parameter of the remesher
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_mmg3dmov(MMG5_pMesh mesh, MMG5_pSol met, MMG5_pSol disp)
Main program for the rigid-body movement library.
Definition: libmmg3d.c:1475
@ MMG3D_IPARAM_debug
Definition: libmmg3d.h:146
@ MMG3D_IPARAM_lag
Definition: libmmg3d.h:152
#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_ppDisp
Definition: libmmgtypes.h:132
#define MMG5_ARG_start
Definition: libmmgtypes.h:93
#define MMG5_ARG_ppMet
Definition: libmmgtypes.h:122
MMG mesh structure.
Definition: libmmgtypes.h:613