Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
variadic_s.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/CNRS/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
40#include "libmmgs_private.h"
41#include "libmmgs.h"
42#include "mmgsexterns_private.h"
43
54static inline
56
57 /* mesh allocation */
58 if ( *mesh ) MMG5_SAFE_FREE(*mesh);
59 MMG5_SAFE_CALLOC(*mesh,1,MMG5_Mesh,return 0);
60
61 /* metric allocation */
62 if ( met ) {
63 if ( *met ) MMG5_DEL_MEM(*mesh,*met);
64 MMG5_SAFE_CALLOC(*met,1,MMG5_Sol,return 0);
65 }
66
67 /* level-set allocation in ls mode */
68 if ( ls ) {
69 if ( *ls )
70 MMG5_DEL_MEM(*mesh,*ls);
71 MMG5_SAFE_CALLOC(*ls,1,MMG5_Sol,return 0);
72 }
73
74 return 1;
75}
85static inline
87
89
90 (mesh)->dim = 3;
91 (mesh)->ver = 2;
92 (mesh)->nsols = 0;
93
94 if ( met && *met ) {
95 (*met)->dim = 3;
96 (*met)->ver = 2;
97 (*met)->size = 1;
98 (*met)->type = 1;
99 }
100
101 if ( ls && *ls ) {
102 (*ls)->dim = 3;
103 (*ls)->ver = 2;
104 (*ls)->size = 1;
105 (*ls)->type = 1;
106 }
107
108 /* Default parameters values */
110
111 /* Default vaules for file names */
112 if ( met ) {
114 }
115 else {
117 }
118
119 if ( ls && *ls ) {
122 }
123
124 return;
125}
126
151 MMG5_pSol *sol,*ls;
152 int typArg;
153 int meshCount;
154
155 meshCount = 0;
156 mesh = NULL;
157 sol = ls = NULL;
158
159
160 while ( (typArg = va_arg(argptr,int)) != MMG5_ARG_end )
161 {
162 switch ( typArg )
163 {
164 case(MMG5_ARG_ppMesh):
165 mesh = va_arg(argptr,MMG5_pMesh*);
166 ++meshCount;
167 break;
168 case MMG5_ARG_ppMet:
169 sol = va_arg(argptr,MMG5_pSol*);
170 break;
171 case(MMG5_ARG_ppLs):
172 ls = va_arg(argptr,MMG5_pSol*);
173 break;
174 default:
175 fprintf(stderr,"\n ## Error: %s: MMGS_Init_mesh:\n"
176 " unexpected argument type: %d\n",__func__,typArg);
177 fprintf(stderr," Argument type must be one of the following"
178 " preprocessor variable: MMG5_ARG_ppMesh, MMG5_ARG_ppMet,"
179 " MMG5_ARG_ppLs.\n");
180 return 0;
181 }
182 }
183
184 if ( meshCount !=1 ) {
185 fprintf(stderr,"\n ## Error: %s: MMGS_Init_mesh:\n"
186 " you need to initialize the mesh structure that"
187 " will contain your mesh.\n",__func__);
188 return 0;
189 }
190
191 /* allocations */
192 if ( !MMGS_Alloc_mesh(mesh,sol,ls) ) return 0;
193
194 /* initialisations */
196
197 return 1;
198}
199
226{
227
229 MMG5_pSol *sol,*sols,*ls;
230 int typArg;
231 int meshCount,metCount,lsCount,fieldsCount;
232
233 meshCount = metCount = lsCount = fieldsCount = 0;
234 sol = sols = ls = NULL;
235
236 while ( (typArg = va_arg(argptr,int)) != MMG5_ARG_end )
237 {
238 switch ( typArg )
239 {
240 case(MMG5_ARG_ppMesh):
241 mesh = va_arg(argptr,MMG5_pMesh*);
242 ++meshCount;
243 break;
244 case(MMG5_ARG_ppMet):
245 ++metCount;
246 sol = va_arg(argptr,MMG5_pSol*);
247 break;
248 case(MMG5_ARG_ppLs):
249 ++lsCount;
250 ls = va_arg(argptr,MMG5_pSol*);
251 break;
252 case(MMG5_ARG_ppSols):
253 ++fieldsCount;
254 sols = va_arg(argptr,MMG5_pSol*);
255 break;
256 default:
257 fprintf(stderr,"\n ## Error: %s: MMGS_Free_all:\n"
258 " unexpected argument type: %d\n",__func__,typArg);
259 fprintf(stderr," Argument type must be one of the following"
260 " preprocessor variable: MMG5_ARG_ppMesh, MMG5_ARG_ppMet or "
261 "MMG5_ARG_ppLs.\n");
262 return 0;
263 }
264 }
265
266 if ( meshCount !=1 ) {
267 fprintf(stderr,"\n ## Error: %s: MMGS_Free_all:\n"
268 " you need to provide your mesh structure"
269 " to allow to free the associated memory.\n",__func__);
270 return 0;
271 }
272
273 if ( metCount > 1 || lsCount > 1 || fieldsCount > 1 ) {
274 fprintf(stdout,"\n ## Warning: %s: MMGS_Free_all:\n"
275 " This function can free only one structure of each type.\n"
276 " Probable memory leak.\n",
277 __func__);
278 }
279
283 MMG5_ARG_end) )
284 return 0;
285
286 if ( sol )
288
289 if ( sols ) {
290 MMG5_DEL_MEM(*mesh,*sols);
291 }
292
294
295 return 1;
296}
297
325{
326
328 MMG5_pSol *sol,*ls,*sols;
329 int typArg,i;
330 int meshCount;
331
332 meshCount = 0;
333 sol = ls = sols = NULL;
334
335 while ( (typArg = va_arg(argptr,int)) != MMG5_ARG_end )
336 {
337 switch ( typArg )
338 {
339 case(MMG5_ARG_ppMesh):
340 mesh = va_arg(argptr,MMG5_pMesh*);
341 ++meshCount;
342 break;
343 case(MMG5_ARG_ppMet):
344 sol = va_arg(argptr,MMG5_pSol*);
345 break;
346 case(MMG5_ARG_ppLs):
347 ls = va_arg(argptr,MMG5_pSol*);
348 break;
349 case(MMG5_ARG_ppSols):
350 sols = va_arg(argptr,MMG5_pSol*);
351 break;
352 default:
353 fprintf(stderr,"\n ## Error: %s: MMGS_Free_structures:\n"
354 " unexpected argument type: %d\n",__func__,typArg);
355 fprintf(stderr," Argument type must be one of the following"
356 " preprocessor variable: MMG5_ARG_ppMesh, MMG5_ARG_ppMet or"
357 " MMG5_ARG_ppLs.\n");
358 return 0;
359 }
360 }
361
362 if ( meshCount !=1 ) {
363 fprintf(stderr,"\n ## Error: %s: MMGS_Free_structures:\n"
364 " you need to provide your mesh structure"
365 " to allow to free the associated memory.\n",__func__);
366 return 0;
367 }
368
373
374 /* mesh */
375 assert(mesh && *mesh);
376
377 /* ls */
378 if ( ls && (*ls) && (*ls)->m ) {
379 MMG5_DEL_MEM((*mesh),(*ls)->m);
380 }
381
382 /* met */
383 if ( sol && (*sol) && (*sol)->m ) {
384 MMG5_DEL_MEM((*mesh),(*sol)->m);
385 }
386
387 /* field */
388 if ( sols && (*mesh)->nsols ) {
389 for ( i=0; i<(*mesh)->nsols; ++i ) {
390 MMG5_DEL_MEM((*mesh),(*sols)[i].m);
391 }
392 }
393
395
396 return 1;
397}
398
427{
428
430 MMG5_pSol psl,*sol,*ls,*sols;
431 int typArg,i;
432 int meshCount;
433
434 meshCount = 0;
435 sol = ls = sols = NULL;
436
437 while ( (typArg = va_arg(argptr,int)) != MMG5_ARG_end )
438 {
439 switch ( typArg )
440 {
441 case(MMG5_ARG_ppMesh):
442 mesh = va_arg(argptr,MMG5_pMesh*);
443 ++meshCount;
444 break;
445 case(MMG5_ARG_ppMet):
446 sol = va_arg(argptr,MMG5_pSol*);
447 break;
448 case(MMG5_ARG_ppLs):
449 ls = va_arg(argptr,MMG5_pSol*);
450 break;
451 case(MMG5_ARG_ppSols):
452 sols = va_arg(argptr,MMG5_pSol*);
453 break;
454 default:
455 fprintf(stderr,"\n ## Error: %s: MMGS_Free_names:\n"
456 " unexpected argument type: %d\n",__func__,typArg);
457 fprintf(stderr," Argument type must be one of the following"
458 " preprocessor variable: MMG5_ARG_ppMesh, MMG5_ARG_ppMet "
459 " or MMG5_ARG_ppLs\n");
460 return 0;
461 }
462 }
463
464 if ( meshCount !=1 ) {
465 fprintf(stderr,"\n ## Error: %s: MMGS_Free_names:\n"
466 " you need to provide your mesh structure"
467 " to allow to free the associated memory.\n",__func__);
468 return 0;
469 }
470
471 /* mesh & met */
472 assert(mesh && *mesh );
473
474 if ( sol ) {
476 }
477 else {
479 }
480 /* ls */
481 if ( ls && *ls ) {
482 if ( (*ls)->namein ) {
483 MMG5_DEL_MEM(*mesh,(*ls)->namein);
484 }
485
486 if ( (*ls)->nameout ) {
487 MMG5_DEL_MEM(*mesh,(*ls)->nameout);
488 }
489 }
490 /* Fields */
491 if ( sols ) {
492 for ( i=0; i<(*mesh)->nsols; ++i ) {
493 psl = (*sols) + i;
494 if ( psl->namein ) {
495 MMG5_DEL_MEM(*mesh,psl->namein);
496 }
497 if ( psl->nameout ) {
499 }
500 }
501 }
502
503
504 return 1;
505}
void MMG5_mmgFree_names(MMG5_pMesh mesh, MMG5_pSol met)
void MMG5_Free_structures(MMG5_pMesh mesh, MMG5_pSol sol)
int MMGS_Free_structures(const int starter,...)
void MMGS_Init_parameters(MMG5_pMesh mesh)
int MMGS_Set_inputSolName(MMG5_pMesh mesh, MMG5_pSol sol, const char *solin)
void MMGS_Init_fileNames(MMG5_pMesh mesh, MMG5_pSol sol)
int MMGS_Free_names(const int starter,...)
int MMGS_Set_outputSolName(MMG5_pMesh mesh, MMG5_pSol sol, const char *solout)
MMG5_pMesh MMG5_pSol * sol
MMG5_pMesh * mesh
const int va_list argptr
void MMGS_Set_commonFunc(void)
Definition: libmmgs.c:732
API headers for the mmgs library.
#define MMG5_ARG_ppMesh
Definition: libmmgtypes.h:96
#define MMG5_ARG_end
Definition: libmmgtypes.h:173
#define MMG5_ARG_ppLs
Definition: libmmgtypes.h:106
#define MMG5_ARG_ppSols
Definition: libmmgtypes.h:136
#define MMG5_ARG_start
Definition: libmmgtypes.h:87
#define MMG5_ARG_ppMet
Definition: libmmgtypes.h:116
#define MMG5_SAFE_CALLOC(ptr, size, type, law)
#define MMG5_SAFE_FREE(ptr)
#define MMG5_DEL_MEM(mesh, ptr)
MMG mesh structure.
Definition: libmmgtypes.h:605
char * nameout
Definition: libmmgtypes.h:653
char * namein
Definition: libmmgtypes.h:652
char * nameout
Definition: libmmgtypes.h:674
char * namein
Definition: libmmgtypes.h:673
double * m
Definition: libmmgtypes.h:671
static int MMGS_Alloc_mesh(MMG5_pMesh *mesh, MMG5_pSol *met, MMG5_pSol *ls)
Definition: variadic_s.c:55
int MMGS_Init_mesh_var(va_list argptr)
Definition: variadic_s.c:149
int MMGS_Free_all_var(va_list argptr)
Definition: variadic_s.c:225
static void MMGS_Init_woalloc_mesh(MMG5_pMesh mesh, MMG5_pSol *met, MMG5_pSol *ls)
Definition: variadic_s.c:86
int MMGS_Free_names_var(va_list argptr)
Definition: variadic_s.c:426
int MMGS_Free_structures_var(va_list argptr)
Definition: variadic_s.c:324