Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
main.c
Go to the documentation of this file.
1
10#include <assert.h>
11#include <stdio.h>
12#include <stdlib.h>
13#include <signal.h>
14#include <string.h>
15#include <ctype.h>
16#include <math.h>
17#include <float.h>
18
20// if the header file is in the "include" directory
21// #include "libmmg3d.h"
22// if the header file is in "include/mmg/mmg3d"
23#include "mmg/mmg3d/libmmg3d.h"
24
25int main(int argc,char *argv[]) {
26 MMG5_pMesh mmgMesh;
27 MMG5_pSol mmgSol,mmgMet,tmpSol;
28 int i,j,opt;
29
30 /* To manually recover the mesh */
31 MMG5_int np;
32 int nsol,typSol[MMG5_NSOLS_MAX];
33 double *sols;
34
35 /* Filenames */
36 char *filename, *fileout;
37
38 fprintf(stdout," -- TEST MMG3DLIB \n");
39
40 if ( argc != 4 ) {
41 printf(" Usage: %s filein fileout io_option\n",argv[0]);
42 printf(" io_option = 0 to Get/Set the solution field by field\n");
43 printf(" io_option = 1 to Get/Set the solution field by field"
44 " and vertex by vertex\n");
45 return(1);
46 }
47
48 /* Name and path of the mesh file */
49 filename = (char *) calloc(strlen(argv[1]) + 1, sizeof(char));
50 if ( filename == NULL ) {
51 perror(" ## Memory problem: calloc");
52 exit(EXIT_FAILURE);
53 }
54 strcpy(filename,argv[1]);
55
56 fileout = (char *) calloc(strlen(argv[2]) + 1, sizeof(char));
57 if ( fileout == NULL ) {
58 perror(" ## Memory problem: calloc");
59 exit(EXIT_FAILURE);
60 }
61 strcpy(fileout,argv[2]);
62
63 opt = atoi(argv[3]);
64
67 /* args of InitMesh:
68 * MMG5_ARG_start: we start to give the args of a variadic func
69 * MMG5_ARG_ppMesh: next arg will be a pointer over a MMG5_pMesh
70 * &mmgMesh: pointer to your MMG5_pMesh (that stores your mesh)
71 * MMG5_ARG_ppMet: next arg will be a pointer over a MMG5_pSol storing a metric
72 * &mmgSol: pointer to your MMG5_pSol (that stores your metric) */
73
74 mmgMesh = NULL;
75 mmgSol = NULL;
76 mmgMet = NULL;
77 tmpSol = NULL;
79 MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppMet,&mmgMet,
81
87 if ( MMG3D_loadMesh(mmgMesh,filename) != 1 ) exit(EXIT_FAILURE);
88
89 if ( MMG3D_loadAllSols(mmgMesh,&mmgSol,filename) != 1 )
90 exit(EXIT_FAILURE);
91
96 if ( MMG3D_Get_solsAtVerticesSize(mmgMesh,&mmgSol,&nsol,&np,typSol) != 1 )
97 exit(EXIT_FAILURE);
98
102 if ( MMG3D_Set_solsAtVerticesSize(mmgMesh,&tmpSol,nsol,np,typSol) != 1 )
103 exit(EXIT_FAILURE);
104
108 /* Get the entire field of a given solution */
109 for ( i=1; i<=nsol; ++i ) {
110 if ( !opt ) {
111 /* Get the ith solution array */
112 if ( typSol[i-1] == MMG5_Scalar )
113 sols = (double*) calloc(np, sizeof(double));
114 else if ( typSol[i-1] == MMG5_Vector )
115 sols = (double*) calloc(np*3, sizeof(double));
116 else if ( typSol[i-1] == MMG5_Tensor ) {
117 sols = (double*) calloc(np*6, sizeof(double));
118 }
119 else {
120 puts("Unexpected solution type.");
121 exit(EXIT_FAILURE);
122 }
123
124 if ( MMG3D_Get_ithSols_inSolsAtVertices(mmgSol,i,sols) !=1 ) exit(EXIT_FAILURE);
125
126 /* Set the ith solution in the new structure */
127 if ( MMG3D_Set_ithSols_inSolsAtVertices(tmpSol,i,sols) !=1 ) exit(EXIT_FAILURE);
128 }
129 else {
130 /* Get the ith solution array vertex by vertex */
131 if ( typSol[i-1] == MMG5_Scalar )
132 sols = (double*) calloc(1, sizeof(double));
133 else if ( typSol[i-1] == MMG5_Vector )
134 sols = (double*) calloc(3, sizeof(double));
135 else if ( typSol[i-1] == MMG5_Tensor ) {
136 sols = (double*) calloc(6, sizeof(double));
137 }
138 else {
139 puts("Unexpected solution type.");
140 exit(EXIT_FAILURE);
141 }
142
143 for ( j=1; j<=np; ++j ) {
144 if ( MMG3D_Get_ithSol_inSolsAtVertices(mmgSol,i,sols,j) !=1 ) exit(EXIT_FAILURE);
145
146 /* Set the ith solution vertex by vertex in the new structure */
147 if ( MMG3D_Set_ithSol_inSolsAtVertices(tmpSol,i,sols,j) !=1 ) exit(EXIT_FAILURE);
148 }
149 }
150
151 free(sols); sols = NULL;
152 }
153
154
158 /* save the mesh */
159 if ( MMG3D_saveMesh(mmgMesh,fileout) != 1 )
160 exit(EXIT_FAILURE);
161
162 /*s ave the solutions array */
163 if ( MMG3D_saveAllSols(mmgMesh,&tmpSol,fileout) != 1 )
164 exit(EXIT_FAILURE);
165
167 MMG3D_Free_allSols(mmgMesh,&mmgSol);
168
170 MMG5_ARG_ppMesh,&mmgMesh,MMG5_ARG_ppSols,&tmpSol,
172
173 free(filename);
174 filename = NULL;
175
176 free(fileout);
177 fileout = NULL;
178
179 return 0;
180}
int MMG3D_Init_mesh(const int starter,...)
Initialize a mesh structure and optionally the associated solution and metric structures.
int MMG3D_Set_ithSols_inSolsAtVertices(MMG5_pSol sol, int i, double *s)
Set all elements of one out of multiple solution fields that are defined on vertices.
int MMG3D_Get_ithSol_inSolsAtVertices(MMG5_pSol sol, int i, double *s, MMG5_int pos)
Get one out of several solutions at a specific vertex.
int MMG3D_Free_allSols(MMG5_pMesh mesh, MMG5_pSol *sol)
Deallocate an array of solution fields.
int MMG3D_Set_ithSol_inSolsAtVertices(MMG5_pSol sol, int i, double *s, MMG5_int pos)
Set a single element of one out of multiple solution fields that are defined on vertices.
int MMG3D_Set_solsAtVerticesSize(MMG5_pMesh mesh, MMG5_pSol *sol, int nsols, MMG5_int nentities, int *typSol)
Initialize an array of solution values defined at vertices.
int MMG3D_Get_ithSols_inSolsAtVertices(MMG5_pSol sol, int i, double *s)
Get one out of several solutions at all vertices in the mesh.
int MMG3D_Get_solsAtVerticesSize(MMG5_pMesh mesh, MMG5_pSol *sol, int *nsols, MMG5_int *np, int *typSol)
Get the number of elements, type, and dimensions of several solutions defined on vertices.
int MMG3D_Free_all(const int starter,...)
Deallocations before return.
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_loadMesh(MMG5_pMesh mesh, const char *filename)
Load a mesh (in .mesh/.mesb format) from file.
Definition: inout_3d.c:1049
int MMG3D_loadAllSols(MMG5_pMesh mesh, MMG5_pSol *sol, const char *filename)
Load one or more solutions in a solution file in medit file format.
Definition: inout_3d.c:2216
int MMG3D_saveAllSols(MMG5_pMesh mesh, MMG5_pSol *sol, const char *filename)
Save 1 or more solutions in medit solution file format.
Definition: inout_3d.c:2352
#define MMG5_ARG_ppMesh
Definition: libmmgtypes.h:102
#define MMG5_ARG_end
Definition: libmmgtypes.h:179
@ MMG5_Vector
Definition: libmmgtypes.h:220
@ MMG5_Tensor
Definition: libmmgtypes.h:221
@ MMG5_Scalar
Definition: libmmgtypes.h:219
#define MMG5_ARG_ppSols
Definition: libmmgtypes.h:142
#define MMG5_ARG_start
Definition: libmmgtypes.h:93
#define MMG5_NSOLS_MAX
Definition: libmmgtypes.h:187
#define MMG5_ARG_ppMet
Definition: libmmgtypes.h:122
MMG mesh structure.
Definition: libmmgtypes.h:613