Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
variadic_2d.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 "libmmg2d_private.h"
41#include "libmmg2d.h"
43
55static inline
57 MMG5_pSol *disp) {
58
59 /* mesh allocation */
60 if ( *mesh ) MMG5_SAFE_FREE(*mesh);
61 MMG5_SAFE_CALLOC(*mesh,1,MMG5_Mesh,return 0);
62
63 /* metric allocation */
64 if ( met ) {
65 if ( *met ) MMG5_DEL_MEM(*mesh,*met);
66 MMG5_SAFE_CALLOC(*met,1,MMG5_Sol,return 0);
67 }
68
69 /* level-set allocation in ls mode */
70 if ( ls ) {
71 if ( *ls )
72 MMG5_DEL_MEM(*mesh,*ls);
73 MMG5_SAFE_CALLOC(*ls,1,MMG5_Sol,return 0);
74 }
75
76 /* Displacement allocation */
77 if ( disp ) {
78 if ( *disp )
79 MMG5_DEL_MEM(*mesh,*disp);
80 MMG5_SAFE_CALLOC(*disp,1,MMG5_Sol,return 0);
81 }
82
83 return 1;
84}
95static inline
97
99
100 assert(mesh);
101 (*mesh)->dim = 2;
102 (*mesh)->ver = 2;
103 (*mesh)->nsols = 0;
104
105 if ( met && *met ) {
106 (*met)->dim = 2;
107 (*met)->ver = 2;
108 (*met)->size = 1;
109 (*met)->type = 1;
110 }
111
112 if ( ls && *ls ) {
113 (*ls)->dim = 2;
114 (*ls)->ver = 2;
115 (*ls)->size = 1;
116 (*ls)->type = 1;
117 }
118
119 if ( disp && *disp ) {
120 (*disp)->dim = 2;
121 (*disp)->ver = 2;
122 (*disp)->size = 2;
123 (*disp)->type = 2;
124 }
125
126 /* Default parameters values */
128
129 /* Default vaules for file names */
130 if ( met ) {
132 }
133 else {
135 }
136
137 if ( ls && *ls ) {
140 }
141
142 if ( disp && *disp ) {
143 MMG2D_Set_inputSolName(*mesh,*disp,"");
144 MMG2D_Set_outputSolName(*mesh,*disp,"");
145 }
146
147 return;
148}
149
178 MMG5_pSol *sol,*disp,*ls;
179 int typArg;
180 int meshCount;
181
182 meshCount = 0;
183 mesh = NULL;
184 disp = sol = ls = NULL;
185
186
187 while ( (typArg = va_arg(argptr,int )) != MMG5_ARG_end )
188 {
189 switch ( typArg )
190 {
191 case(MMG5_ARG_ppMesh):
192 mesh = va_arg(argptr,MMG5_pMesh*);
193 ++meshCount;
194 break;
195 case(MMG5_ARG_ppMet):
196 sol = va_arg(argptr,MMG5_pSol*);
197 break;
198 case(MMG5_ARG_ppLs):
199 ls = va_arg(argptr,MMG5_pSol*);
200 break;
201 case(MMG5_ARG_ppDisp):
202 disp = va_arg(argptr,MMG5_pSol*);
203 break;
204 default:
205 fprintf(stderr,"\n ## Error: %s: MMG2D_Init_mesh:\n"
206 " unexpected argument type: %d\n",__func__,typArg);
207 fprintf(stderr," Argument type must be one of the following"
208 " preprocessor variable: MMG5_ARG_ppMesh, MMG5_ARG_ppMet,"
209 " MMG5_ARG_ppLs, MMG5_ARG_ppDisp\n");
210 return 0;
211 }
212 }
213
214 if ( meshCount !=1 ) {
215 fprintf(stderr,"\n ## Error: %s: MMG2D_Init_mesh:\n"
216 " you need to initialize the mesh structure that"
217 " will contain your mesh.\n",__func__);
218 return 0;
219 }
220
221 /* allocations */
222 if ( !MMG2D_Alloc_mesh(mesh,sol,ls,disp) ) return 0;
223
224 /* initialisations */
226
227 return 1;
228}
229
260{
261
263 MMG5_pSol *sol,*disp,*ls,*sols;
264 int typArg;
265 int meshCount,metCount,lsCount,dispCount,fieldsCount;
266 int ier;
267
268 meshCount = metCount = lsCount = dispCount = fieldsCount = 0;
269 disp = sol = sols = ls = NULL;
270
271 while ( (typArg = va_arg(argptr,int )) != MMG5_ARG_end )
272 {
273 switch ( typArg )
274 {
275 case(MMG5_ARG_ppMesh):
276 mesh = va_arg(argptr,MMG5_pMesh*);
277 ++meshCount;
278 break;
279 case(MMG5_ARG_ppMet):
280 ++metCount;
281 sol = va_arg(argptr,MMG5_pSol*);
282 break;
283 case(MMG5_ARG_ppLs):
284 ++lsCount;
285 ls = va_arg(argptr,MMG5_pSol*);
286 break;
287 case(MMG5_ARG_ppDisp):
288 ++dispCount;
289 disp = va_arg(argptr,MMG5_pSol*);
290 break;
291 case(MMG5_ARG_ppSols):
292 ++fieldsCount;
293 sols = va_arg(argptr,MMG5_pSol*);
294 break;
295 default:
296 fprintf(stderr,"\n ## Error: %s: MMG2D_Free_all:\n"
297 " unexpected argument type: %d\n",__func__,typArg);
298 fprintf(stderr," Argument type must be one of the following"
299 " preprocessor variable: MMG5_ARG_ppMesh or MMG5_ARG_ppMet\n");
300 return 0;
301 }
302 }
303
304 if ( meshCount !=1 ) {
305 fprintf(stderr,"\n ## Error: %s: MMG2D_Free_all:\n"
306 " you need to provide your mesh structure"
307 " to allow to free the associated memory.\n",__func__);
308 return 0;
309 }
310
311 if ( metCount > 1 || lsCount > 1 || dispCount > 1 || fieldsCount > 1 ) {
312 fprintf(stdout,"\n ## Warning: %s: MMG2D_Free_all:\n"
313 " This function can free only one structure of each type.\n"
314 " Probable memory leak.\n",
315 __func__);
316 }
317
321 MMG5_ARG_ppSols, sols,
323
324 if ( sol )
326
327 if ( disp )
328 MMG5_SAFE_FREE(*disp);
329
330 if ( ls )
331 MMG5_SAFE_FREE(*ls);
332
333 if ( sols ) {
334 MMG5_DEL_MEM(*mesh,*sols);
335 }
336
338
339 return ier;
340}
341
369{
370
372 MMG5_pSol *sol,*disp,*ls,*sols;
373 int typArg,i;
374 int meshCount;
375
376 meshCount = 0;
377 mesh = NULL;
378 disp = sol = ls = sols = NULL;
379
380 while ( (typArg = va_arg(argptr,int )) != MMG5_ARG_end )
381 {
382 switch ( typArg )
383 {
384 case(MMG5_ARG_ppMesh):
385 mesh = va_arg(argptr,MMG5_pMesh*);
386 ++meshCount;
387 break;
388 case(MMG5_ARG_ppMet):
389 sol = va_arg(argptr,MMG5_pSol*);
390 break;
391 case(MMG5_ARG_ppLs):
392 ls = va_arg(argptr,MMG5_pSol*);
393 break;
394 case(MMG5_ARG_ppDisp):
395 disp = va_arg(argptr,MMG5_pSol*);
396 break;
397 case(MMG5_ARG_ppSols):
398 sols = va_arg(argptr,MMG5_pSol*);
399 break;
400 default:
401 fprintf(stderr,"\n ## Error: %s: MMG2D_Free_structures:\n"
402 " unexpected argument type: %d\n",__func__,typArg);
403 fprintf(stderr," Argument type must be one of the following"
404 " preprocessor variable: MMG5_ARG_ppMesh or MMG5_ARG_ppMet\n");
405 return 0;
406 }
407 }
408
409 if ( meshCount !=1 ) {
410 fprintf(stderr,"\n ## Error: %s: MMG2D_Free_structures:\n"
411 " you need to provide your mesh structure"
412 " to allow to free the associated memory.\n",__func__);
413 return 0;
414 }
415
419 MMG5_ARG_ppSols, sols,
420 MMG5_ARG_end) )
421 return 0;
422
423 /* mesh */
424 assert(mesh && *mesh);
425
426 if ( (*mesh)->edge )
427 MMG5_DEL_MEM((*mesh),(*mesh)->edge);
428
429 if ( (*mesh)->adja )
430 MMG5_DEL_MEM((*mesh),(*mesh)->adja);
431
432 if ( (*mesh)->adjq )
433 MMG5_DEL_MEM((*mesh),(*mesh)->adjq);
434
435 if ( (*mesh)->tria )
436 MMG5_DEL_MEM((*mesh),(*mesh)->tria);
437
438 if ( (*mesh)->quadra )
439 MMG5_DEL_MEM((*mesh),(*mesh)->quadra);
440
441 /* disp */
442 if ( disp && (*disp) && (*disp)->m )
443 MMG5_DEL_MEM((*mesh),(*disp)->m);
444
445 /* ls */
446 if ( ls && (*ls) && (*ls)->m )
447 MMG5_DEL_MEM((*mesh),(*ls)->m);
448
449 /* met */
450 if ( sol && (*sol) && (*sol)->m )
451 MMG5_DEL_MEM((*mesh),(*sol)->m);
452
453 /* field */
454 if ( sols && (*mesh)->nsols ) {
455 for ( i=0; i<(*mesh)->nsols; ++i ) {
456 MMG5_DEL_MEM((*mesh),(*sols)[i].m);
457 }
458 }
459
461
462 return 1;
463}
464
484{
485
487 MMG5_pSol psl,*sol,*disp,*ls,*sols;
488 int typArg,i;
489 int meshCount;
490
491 meshCount = 0;
492 disp = sol = ls = sols = NULL;
493
494 while ( (typArg = va_arg(argptr,int )) != MMG5_ARG_end )
495 {
496 switch ( typArg )
497 {
498 case(MMG5_ARG_ppMesh):
499 mesh = va_arg(argptr,MMG5_pMesh*);
500 ++meshCount;
501 break;
502 case(MMG5_ARG_ppMet):
503 sol = va_arg(argptr,MMG5_pSol*);
504 break;
505 case(MMG5_ARG_ppLs):
506 ls = va_arg(argptr,MMG5_pSol*);
507 break;
508 case(MMG5_ARG_ppDisp):
509 disp = va_arg(argptr,MMG5_pSol*);
510 break;
511 case(MMG5_ARG_ppSols):
512 sols = va_arg(argptr,MMG5_pSol*);
513 break;
514 default:
515 fprintf(stderr,"\n ## Error: %s: MMG2D_Free_names:\n"
516 " unexpected argument type: %d\n",__func__,typArg);
517 fprintf(stderr," Argument type must be one of the following"
518 " preprocessor variable: MMG5_ARG_ppMesh or MMG5_ARG_ppMet\n");
519 return 0;
520 }
521 }
522
523 if ( meshCount !=1 ) {
524 fprintf(stderr,"\n ## Error: %s: MMG2D_Free_names:\n"
525 " you need to provide your mesh structure"
526 " to allow to free the associated memory.\n",__func__);
527 return 0;
528 }
529
530 /* mesh & met */
531 if ( sol ) {
533 }
534 else {
536 }
537
538 /* disp */
539 if ( disp && *disp ) {
540 if ( (*disp)->namein ) {
541 MMG5_DEL_MEM(*mesh,(*disp)->namein);
542 }
543
544 if ( (*disp)->nameout ) {
545 MMG5_DEL_MEM(*mesh,(*disp)->nameout);
546 }
547 }
548
549 /* ls */
550 if ( ls && *ls ) {
551 if ( (*ls)->namein ) {
552 MMG5_DEL_MEM(*mesh,(*ls)->namein);
553 }
554
555 if ( (*ls)->nameout ) {
556 MMG5_DEL_MEM(*mesh,(*ls)->nameout);
557 }
558 }
559
560 /* Fields */
561 if ( sols ) {
562 for ( i=0; i<(*mesh)->nsols; ++i ) {
563 psl = (*sols) + i;
564 if ( psl->namein ) {
565 MMG5_DEL_MEM(*mesh,psl->namein);
566 }
567 if ( psl->nameout ) {
569 }
570 }
571 }
572
573 return 1;
574}
void MMG5_mmgFree_names(MMG5_pMesh mesh, MMG5_pSol met)
void MMG5_Free_structures(MMG5_pMesh mesh, MMG5_pSol sol)
void MMG2D_Init_parameters(MMG5_pMesh mesh)
void MMG2D_Init_fileNames(MMG5_pMesh mesh, MMG5_pSol sol)
int MMG2D_Free_structures(const int starter,...)
int MMG2D_Set_inputSolName(MMG5_pMesh mesh, MMG5_pSol sol, const char *solin)
int MMG2D_Free_names(const int starter,...)
int MMG2D_Set_outputSolName(MMG5_pMesh mesh, MMG5_pSol sol, const char *solout)
int ier
MMG5_pMesh MMG5_pSol * sol
MMG5_pMesh * mesh
const int va_list argptr
void MMG2D_Set_commonFunc(void)
Definition: libmmg2d.c:52
API headers for the mmg2d 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
char * nameout
Definition: libmmgtypes.h:674
char * namein
Definition: libmmgtypes.h:673
double * m
Definition: libmmgtypes.h:671
static int MMG2D_Alloc_mesh(MMG5_pMesh *mesh, MMG5_pSol *met, MMG5_pSol *ls, MMG5_pSol *disp)
Definition: variadic_2d.c:56
int MMG2D_Free_all_var(va_list argptr)
Definition: variadic_2d.c:259
int MMG2D_Free_structures_var(va_list argptr)
Definition: variadic_2d.c:368
int MMG2D_Free_names_var(va_list argptr)
Definition: variadic_2d.c:483
int MMG2D_Init_mesh_var(va_list argptr)
Definition: variadic_2d.c:176
static void MMG2D_Init_woalloc_mesh(MMG5_pMesh *mesh, MMG5_pSol *met, MMG5_pSol *ls, MMG5_pSol *disp)
Definition: variadic_2d.c:96