Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
variadic_3d.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
41#include "libmmg3d_private.h"
42#include "libmmg3d.h"
44
56static inline
58 ) {
59
60 /* mesh allocation */
61 if ( *mesh ) MMG5_SAFE_FREE(*mesh);
62 MMG5_SAFE_CALLOC(*mesh,1,MMG5_Mesh,return 0);
63
64 /* metric allocation */
65 if ( met ) {
66 if ( *met ) MMG5_DEL_MEM(*mesh,*met);
67 MMG5_SAFE_CALLOC(*met,1,MMG5_Sol,return 0);
68 }
69
70 /* level-set allocation in ls mode */
71 if ( ls ) {
72 if ( *ls )
73 MMG5_DEL_MEM(*mesh,*ls);
74 MMG5_SAFE_CALLOC(*ls,1,MMG5_Sol,return 0);
75 }
76
77 /* Displacement allocation */
78 if ( disp ) {
79 if ( *disp )
80 MMG5_DEL_MEM(*mesh,*disp);
81 MMG5_SAFE_CALLOC(*disp,1,MMG5_Sol,return 0);
82 }
83
84 return 1;
85}
96static inline
98 ) {
99
101
102 (mesh)->dim = 3;
103 (mesh)->ver = 2;
104 (mesh)->nsols = 0;
105
106 if ( met && *met ) {
107 (*met)->dim = 3;
108 (*met)->ver = 2;
109 (*met)->size = 1;
110 (*met)->type = 1;
111 }
112
113 if ( ls && *ls ) {
114 (*ls)->dim = 3;
115 (*ls)->ver = 2;
116 (*ls)->size = 1;
117 (*ls)->type = 1;
118 }
119
120 if ( disp && *disp ) {
121 (*disp)->dim = 3;
122 (*disp)->ver = 2;
123 (*disp)->size = 2;
124 (*disp)->type = 2;
125 }
126
127 /* Default parameters values */
129
130 /* Default vaules for file names */
131 if ( met ) {
133 }
134 else {
136 }
137
138 if ( ls && *ls ) {
141 }
142
143 if ( disp && *disp ) {
146 }
147
148 return;
149}
150
179 MMG5_pSol *sol,*disp,*ls;
180 int typArg;
181 int meshCount;
182
183 meshCount = 0;
184 mesh = NULL;
185 disp = sol = ls = NULL;
186
187
188 while ( (typArg = va_arg(argptr,int)) != MMG5_ARG_end )
189 {
190 switch ( typArg )
191 {
192 case(MMG5_ARG_ppMesh):
193 mesh = va_arg(argptr,MMG5_pMesh*);
194 ++meshCount;
195 break;
196 case(MMG5_ARG_ppMet):
197 sol = va_arg(argptr,MMG5_pSol*);
198 break;
199 case(MMG5_ARG_ppLs):
200 ls = va_arg(argptr,MMG5_pSol*);
201 break;
202 case(MMG5_ARG_ppDisp):
203 disp = va_arg(argptr,MMG5_pSol*);
204 break;
205 default:
206 fprintf(stderr,"\n ## Error: %s: MMG3D_Init_mesh:\n"
207 " unexpected argument type: %d\n",__func__,typArg);
208 fprintf(stderr," Argument type must be one"
209 " of the MMG5_ARG* preprocessor variable:"
210 " MMG5_ARG_ppMesh, MMG5_ARG_ppMet,"
211 " MMG5_ARG_ppLs, MMG5_ARG_ppDisp\n");
212 return 0;
213 }
214 }
215
216 if ( meshCount !=1 ) {
217 fprintf(stderr,"\n ## Error: %s: MMG3D_Init_mesh:\n"
218 " you need to initialize the mesh structure that"
219 " will contain your mesh.\n",__func__);
220 return 0;
221 }
222
223 /* allocations */
224 if ( !MMG3D_Alloc_mesh(mesh,sol,ls,disp) ) return 0;
225
226 /* initialisations */
228
229 return 1;
230}
231
262{
263
265 MMG5_pSol *sol,*disp,*sols,*ls;
266 int typArg;
267 int meshCount,metCount,lsCount,dispCount,fieldsCount;
268
269 meshCount = metCount = lsCount = dispCount = fieldsCount = 0;
270 mesh = NULL;
271 disp = sol = sols = ls = NULL;
272
273 while ( (typArg = va_arg(argptr,int)) != MMG5_ARG_end )
274 {
275 switch ( typArg )
276 {
277 case(MMG5_ARG_ppMesh):
278 mesh = va_arg(argptr,MMG5_pMesh*);
279 ++meshCount;
280 break;
281 case(MMG5_ARG_ppMet):
282 ++metCount;
283 sol = va_arg(argptr,MMG5_pSol*);
284 break;
285 case(MMG5_ARG_ppLs):
286 ++lsCount;
287 ls = va_arg(argptr,MMG5_pSol*);
288 break;
289 case(MMG5_ARG_ppDisp):
290 ++dispCount;
291 disp = va_arg(argptr,MMG5_pSol*);
292 break;
293 case(MMG5_ARG_ppSols):
294 ++fieldsCount;
295 sols = va_arg(argptr,MMG5_pSol*);
296 break;
297 default:
298 fprintf(stderr,"\n ## Error: %s: MMG3D_Free_all:\n"
299 " unexpected argument type: %d\n",__func__,typArg);
300 fprintf(stderr," Argument type must be one of the following preprocessor"
301 " variable:"
302 " MMG5_ARG_ppMesh, MMG5_ARG_ppMet,"
303 " MMG5_ARG_ppLs, MMG5_ARG_ppDisp\n");
304 return 0;
305 }
306 }
307
308 if ( meshCount !=1 ) {
309 fprintf(stderr,"\n ## Error: %s: MMG3D_Free_all:\n"
310 " you need to provide your mesh structure"
311 " to allow to free the associated memory.\n",__func__);
312 return 0;
313 }
314
315 if ( metCount > 1 || lsCount > 1 || dispCount > 1 || fieldsCount > 1 ) {
316 fprintf(stdout,"\n ## Warning: %s: MMG3D_Free_all:\n"
317 " This function can free only one structure of each type.\n"
318 " Probable memory leak.\n",
319 __func__);
320 }
321
325 MMG5_ARG_ppSols, sols,
326 MMG5_ARG_end) ) {
327 return 0;
328 }
329
330 if ( sol ) {
332 }
333
334 if ( disp ) {
335 MMG5_SAFE_FREE(*disp);
336 }
337
338 if ( ls ) {
339 MMG5_SAFE_FREE(*ls);
340 }
341
342 if ( sols ) {
343 MMG5_DEL_MEM(*mesh,*sols);
344 }
345
347
348 return 1;
349}
350
360 MMG5_pSol *disp,MMG5_pSol *field){
361 int i;
362 if ( (*mesh)->tetra )
363 MMG5_DEL_MEM((*mesh),(*mesh)->tetra);
364
365 if ( (*mesh)->prism )
366 MMG5_DEL_MEM((*mesh),(*mesh)->prism);
367
368 if ( (*mesh)->edge )
369 MMG5_DEL_MEM((*mesh),(*mesh)->edge);
370
371 if ( (*mesh)->adjt )
372 MMG5_DEL_MEM(*mesh,(*mesh)->adjt);
373
374 if ( (*mesh)->adja )
375 MMG5_DEL_MEM((*mesh),(*mesh)->adja);
376
377 if ( (*mesh)->adjapr )
378 MMG5_DEL_MEM((*mesh),(*mesh)->adjapr);
379
380 if ( (*mesh)->htab.geom )
381 MMG5_DEL_MEM((*mesh),(*mesh)->htab.geom);
382
383 if ( (*mesh)->tria )
384 MMG5_DEL_MEM((*mesh),(*mesh)->tria);
385
386 if ( (*mesh)->quadra )
387 MMG5_DEL_MEM((*mesh),(*mesh)->quadra);
388
389 if ( (*mesh)->xtetra )
390 MMG5_DEL_MEM((*mesh),(*mesh)->xtetra);
391
392 if ( (*mesh)->xprism )
393 MMG5_DEL_MEM((*mesh),(*mesh)->xprism);
394
395 /* disp */
396 if ( disp && (*disp) && (*disp)->m )
397 MMG5_DEL_MEM((*mesh),(*disp)->m);
398
399 /* ls */
400 if ( ls && (*ls) && (*ls)->m )
401 MMG5_DEL_MEM((*mesh),(*ls)->m);
402
403 /* field */
404 if ( field && (*mesh)->nsols ) {
405 for ( i=0; i<(*mesh)->nsols; ++i ) {
406 MMG5_DEL_MEM((*mesh),(*field)[i].m);
407 }
408 }
409
410 if ( sol ) {
412 }
413 else {
415 }
416 return;
417}
418
450{
451
453 MMG5_pSol *sol,*ls,*disp,*sols;
454 int typArg;
455 int meshCount;
456
457 meshCount = 0;
458 mesh = NULL;
459 disp = sol = ls = sols = NULL;
460
461 while ( (typArg = va_arg(argptr,int)) != MMG5_ARG_end )
462 {
463 switch ( typArg )
464 {
465 case(MMG5_ARG_ppMesh):
466 mesh = va_arg(argptr,MMG5_pMesh*);
467 ++meshCount;
468 break;
469 case(MMG5_ARG_ppMet):
470 sol = va_arg(argptr,MMG5_pSol*);
471 break;
472 case(MMG5_ARG_ppLs):
473 ls = va_arg(argptr,MMG5_pSol*);
474 break;
475 case(MMG5_ARG_ppDisp):
476 disp = va_arg(argptr,MMG5_pSol*);
477 break;
478 case(MMG5_ARG_ppSols):
479 sols = va_arg(argptr,MMG5_pSol*);
480 break;
481 default:
482 fprintf(stderr,"\n ## Error: %s: MMG3D_Free_structures:\n"
483 " unexpected argument type: %d\n",__func__,typArg);
484 fprintf(stderr," Argument type must be one of the following preprocessor"
485 " variable:"
486 " MMG5_ARG_ppMesh, MMG5_ARG_ppMet,"
487 " MMG5_ARG_ppLs, MMG5_ARG_ppDisp\n");
488 return 0;
489 }
490 }
491
492 if ( meshCount !=1 ) {
493 fprintf(stderr,"\n ## Error: %s: MMG3D_Free_structures:\n"
494 " you need to provide your mesh structure"
495 " to allow to free the associated memory.\n",__func__);
496 return 0;
497 }
498
501 MMG5_ARG_ppLs, ls,
502 MMG5_ARG_ppDisp, disp,
503 MMG5_ARG_ppSols, sols,
504 MMG5_ARG_end) ) {
505 return 0;
506 }
507
508 /* mesh */
509 assert(mesh && *mesh);
510
511
512 MMG3D_Free_arrays(mesh,sol,ls,disp,sols);
513
514 return 1;
515}
516
548{
549
551 MMG5_pSol psl,*sol,*disp,*ls,*sols;
552 int typArg,i;
553 int meshCount;
554
555 meshCount = 0;
556 disp = sol = ls = sols = NULL;
557
558 while ( (typArg = va_arg(argptr,int)) != MMG5_ARG_end )
559 {
560 switch ( typArg )
561 {
562 case(MMG5_ARG_ppMesh):
563 mesh = va_arg(argptr,MMG5_pMesh*);
564 ++meshCount;
565 break;
566 case(MMG5_ARG_ppMet):
567 sol = va_arg(argptr,MMG5_pSol*);
568 break;
569 case(MMG5_ARG_ppLs):
570 ls = va_arg(argptr,MMG5_pSol*);
571 break;
572 case(MMG5_ARG_ppDisp):
573 disp = va_arg(argptr,MMG5_pSol*);
574 break;
575 case(MMG5_ARG_ppSols):
576 sols = va_arg(argptr,MMG5_pSol*);
577 break;
578 default:
579 fprintf(stderr,"\n ## Error: %s: MMG3D_Free_names:\n"
580 " unexpected argument type: %d\n",__func__,typArg);
581 fprintf(stderr," Argument type must be one of the following preprocessor"
582 " variable:"
583 " MMG5_ARG_ppMesh, MMG5_ARG_ppMet,"
584 " MMG5_ARG_ppLs, MMG5_ARG_ppDisp\n");
585 return 0;
586 }
587 }
588
589 if ( meshCount !=1 ) {
590 fprintf(stderr,"\n ## Error: %s: MMG3D_Free_names:\n"
591 " you need to provide your mesh structure"
592 " to allow to free the associated memory.\n",__func__);
593 return 0;
594 }
595
596 /* mesh & met */
597 if (!sol)
599 else
601
602 /* disp */
603 if ( disp && *disp ) {
604 if ( (*disp)->namein ) {
605 MMG5_DEL_MEM(*mesh,(*disp)->namein);
606 }
607
608 if ( (*disp)->nameout ) {
609 MMG5_DEL_MEM(*mesh,(*disp)->nameout);
610 }
611 }
612
613 /* ls */
614 if ( ls && *ls ) {
615 if ( (*ls)->namein ) {
616 MMG5_DEL_MEM(*mesh,(*ls)->namein);
617 }
618
619 if ( (*ls)->nameout ) {
620 MMG5_DEL_MEM(*mesh,(*ls)->nameout);
621 }
622 }
623
624 /* Fields */
625 if ( sols ) {
626 for ( i=0; i<(*mesh)->nsols; ++i ) {
627 psl = (*sols) + i;
628 if ( psl->namein ) {
629 MMG5_DEL_MEM(*mesh,psl->namein);
630 }
631 if ( psl->nameout ) {
633 }
634 }
635 }
636
637 return 1;
638}
void MMG5_mmgFree_names(MMG5_pMesh mesh, MMG5_pSol met)
void MMG5_Free_structures(MMG5_pMesh mesh, MMG5_pSol sol)
void MMG3D_Init_fileNames(MMG5_pMesh mesh, MMG5_pSol sol)
int MMG3D_Set_inputSolName(MMG5_pMesh mesh, MMG5_pSol sol, const char *solin)
int MMG3D_Free_structures(const int starter,...)
int MMG3D_Free_names(const int starter,...)
int MMG3D_Set_outputSolName(MMG5_pMesh mesh, MMG5_pSol sol, const char *solout)
void MMG3D_Init_parameters(MMG5_pMesh mesh)
MMG5_pMesh MMG5_pSol * sol
MMG5_pMesh * mesh
const int va_list argptr
void MMG3D_Set_commonFunc(void)
Definition: libmmg3d.c:1745
API headers for the mmg3d 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_ppDisp
Definition: libmmgtypes.h:126
#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
MMG5_int * adjt
Definition: libmmgtypes.h:628
char * nameout
Definition: libmmgtypes.h:674
char * namein
Definition: libmmgtypes.h:673
double * m
Definition: libmmgtypes.h:671
static void MMG3D_Init_woalloc_mesh(MMG5_pMesh mesh, MMG5_pSol *met, MMG5_pSol *ls, MMG5_pSol *disp)
Definition: variadic_3d.c:97
int MMG3D_Free_all_var(va_list argptr)
Definition: variadic_3d.c:261
int MMG3D_Free_structures_var(va_list argptr)
Definition: variadic_3d.c:449
static int MMG3D_Alloc_mesh(MMG5_pMesh *mesh, MMG5_pSol *met, MMG5_pSol *ls, MMG5_pSol *disp)
Definition: variadic_3d.c:57
int MMG3D_Free_names_var(va_list argptr)
Definition: variadic_3d.c:547
void MMG3D_Free_arrays(MMG5_pMesh *mesh, MMG5_pSol *sol, MMG5_pSol *ls, MMG5_pSol *disp, MMG5_pSol *field)
Definition: variadic_3d.c:359
int MMG3D_Init_mesh_var(va_list argptr)
Definition: variadic_3d.c:177