Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
zaldy_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
36#include "libmmgs_private.h"
37
38/* get new point address */
39MMG5_int MMGS_newPt(MMG5_pMesh mesh,double c[3],double n[3]) {
40 MMG5_pPoint ppt;
41 MMG5_int curpt;
42
43 if ( !mesh->npnil ) return 0;
44
45 curpt = mesh->npnil;
46 if ( mesh->npnil > mesh->np ) mesh->np = mesh->npnil;
47 ppt = &mesh->point[curpt];
48 memcpy(ppt->c,c,3*sizeof(double));
49 if ( n )
50 memcpy(ppt->n,n,3*sizeof(double));
51 ppt->tag &= ~MG_NUL;
52 mesh->npnil = ppt->tmp;
53 ppt->tmp = 0;
54
55 return curpt;
56}
57
58void MMGS_delPt(MMG5_pMesh mesh,MMG5_int ip) {
59 MMG5_pPoint ppt;
60
61 ppt = &mesh->point[ip];
62 memset(ppt,0,sizeof(MMG5_Point));
63 ppt->tag = MG_NUL;
64 ppt->tmp = mesh->npnil;
65 mesh->npnil = ip;
66 if ( ip == mesh->np ) {
67 while ( !MG_VOK((&mesh->point[mesh->np])) ) mesh->np--;
68 }
69}
70
72 MMG5_int curiel;
73
74 if ( !mesh->nenil ) return 0;
75 curiel = mesh->nenil;
76
77 if ( mesh->nenil > mesh->nt ) mesh->nt = mesh->nenil;
78 mesh->nenil = mesh->tria[curiel].v[2];
79 mesh->tria[curiel].v[2] = 0;
80
81 return curiel;
82}
83
93int MMGS_delElt(MMG5_pMesh mesh,MMG5_int iel) {
94 MMG5_pTria pt;
95
96 pt = &mesh->tria[iel];
97 if ( !MG_EOK(pt) ) {
98 fprintf(stderr,"\n ## INVALID ELEMENT %" MMG5_PRId ".\n",iel);
99 return 0;
100 }
101 memset(pt,0,sizeof(MMG5_Tria));
102 pt->v[2] = mesh->nenil;
103 if ( mesh->adja )
104 memset(&mesh->adja[3*(iel-1)+1],0,3*sizeof(MMG5_int));
105 mesh->nenil = iel;
106 if ( iel == mesh->nt ) {
107 while ( !MG_EOK((&mesh->tria[mesh->nt])) ) mesh->nt--;
108 }
109 return 1;
110}
111
127static inline
129 size_t usedMem,avMem,reservedMem,npadd;
130 int bytes;
131
133
134 /* init allocation need MMG5_MEMMIN B */
135 reservedMem = MMG5_MEMMIN;
136
137 /* Compute the needed initial memory */
138 usedMem = reservedMem + (mesh->np+1)*sizeof(MMG5_Point)
139 + (mesh->nt+1)*sizeof(MMG5_Tria) + (3*mesh->nt+1)*sizeof(MMG5_int)
140 + (mesh->np+1)*sizeof(double);
141
142 if ( usedMem > mesh->memMax ) {
143 fprintf(stderr,"\n ## Error: %s: %zu MB of memory ",__func__,mesh->memMax/MMG5_MILLION);
144 fprintf(stderr,"is not enough to load mesh. You need to ask %zu MB minimum\n",
145 usedMem/MMG5_MILLION+1);
146 return 0;
147 }
148
149 /* point+xpoint+tria+adja+aniso sol */
150 bytes = sizeof(MMG5_Point) + sizeof(MMG5_xPoint) +
151 2*sizeof(MMG5_Tria) + 3*sizeof(MMG5_int) + 6*sizeof(double);
152
153 avMem = mesh->memMax-usedMem;
154
155 /* If npadd is exactly the maximum memory available, we will use all the
156 * memory and the analysis step will fail. As arrays may be reallocated, we
157 * can have smaller values for xpmax and ntmax (npadd/2). */
158 npadd = avMem/(2*bytes);
159 mesh->npmax = MG_MIN(mesh->npmax,mesh->np+npadd);
160 mesh->ntmax = MG_MIN(mesh->ntmax,2*npadd+mesh->nt);
161
162 if ( sizeof(MMG5_int) == sizeof(int32_t) ) {
164 /* maximal number of triangles, taking the
165 * computation of adjacency relationships into account */
166 int coef = 3;
167 int32_t int32_ntmax = (INT32_MAX-(coef+1))/coef;
168
169 if ( int32_ntmax < mesh->ntmax ) {
170 if ( int32_ntmax <= mesh->nt ) {
171 /* No possible allocation without int32 overflow */
172 fprintf(stderr,"\n ## Error: %s: with %" MMG5_PRId " triangles Mmg will overflow"
173 " the 32-bit integer.\n",__func__,mesh->nt);
174 fprintf(stderr,"Please, configure Mmg with MMG5_INT=int64_t argument.\n");
175 return 0;
176 }
177 else {
178 /* Correction of maximal number of triangles */
179 mesh->ntmax = int32_ntmax;
180 }
181 }
182 }
183
184 if ( abs(mesh->info.imprim) > 4 || mesh->info.ddebug ) {
185 fprintf(stdout," MAXIMUM MEMORY AUTHORIZED (MB) %zu\n",
187 }
188
189 if ( abs(mesh->info.imprim) > 5 || mesh->info.ddebug ) {
190 fprintf(stdout," MMG2D_NPMAX %" MMG5_PRId "\n",mesh->npmax);
191 fprintf(stdout," MMG2D_NTMAX %" MMG5_PRId "\n",mesh->ntmax);
192 }
193
194 return 1;
195}
196
206
208
211
213}
214
224 MMG5_int k;
225
226 MMG5_ADD_MEM(mesh,(mesh->npmax+1)*sizeof(MMG5_Point),"initial vertices",
227 fprintf(stderr," Exit program.\n");
228 return 0);
230 MMG5_ADD_MEM(mesh,(mesh->ntmax+1)*sizeof(MMG5_Tria),"initial triangles",
231 fprintf(stderr," Exit program.\n");
232 return 0);
234
235
236 mesh->namax = mesh->na;
237 if ( mesh->na ) {
238 MMG5_ADD_MEM(mesh,(mesh->na+1)*sizeof(MMG5_Edge),"initial edges",return 0);
239 MMG5_SAFE_CALLOC(mesh->edge,(mesh->na+1),MMG5_Edge,return 0);
240 }
241
242 /* keep track of empty links */
243 mesh->npnil = mesh->np + 1;
244 mesh->nenil = mesh->nt + 1;
245
246 for (k=mesh->npnil; k<mesh->npmax-1; k++)
247 mesh->point[k].tmp = k+1;
248
249 for (k=mesh->nenil; k<mesh->ntmax-1; k++)
250 mesh->tria[k].v[2] = k+1;
251
252 return 1;
253}
254
264
265 if ( !MMGS_memOption(mesh) ) return 0;
266
268}
MMG5_pMesh * mesh
#define MMGS_NPMAX
#define MMGS_NTMAX
#define MMG5_SAFE_CALLOC(ptr, size, type, law)
size_t MMG5_memSize(void)
Definition: tools.c:852
#define MG_EOK(pt)
void MMG5_memOption_memSet(MMG5_pMesh mesh)
Definition: tools.c:891
#define MG_NUL
#define MG_MIN(a, b)
#define MG_MAX(a, b)
#define MMG5_ADD_MEM(mesh, size, message, law)
#define MMG5_MILLION
#define MG_VOK(ppt)
#define MMG5_MEMMIN
Structure to store edges of a MMG mesh.
Definition: libmmgtypes.h:305
int8_t ddebug
Definition: libmmgtypes.h:532
MMG mesh structure.
Definition: libmmgtypes.h:605
MMG5_int ntmax
Definition: libmmgtypes.h:612
MMG5_Info info
Definition: libmmgtypes.h:651
MMG5_pPoint point
Definition: libmmgtypes.h:641
MMG5_int * adja
Definition: libmmgtypes.h:624
size_t memMax
Definition: libmmgtypes.h:606
MMG5_int npmax
Definition: libmmgtypes.h:612
MMG5_int nenil
Definition: libmmgtypes.h:622
MMG5_int namax
Definition: libmmgtypes.h:612
MMG5_int nt
Definition: libmmgtypes.h:612
MMG5_pTria tria
Definition: libmmgtypes.h:647
MMG5_int np
Definition: libmmgtypes.h:612
MMG5_pEdge edge
Definition: libmmgtypes.h:649
MMG5_int na
Definition: libmmgtypes.h:612
MMG5_int npnil
Definition: libmmgtypes.h:621
Structure to store points of a MMG mesh.
Definition: libmmgtypes.h:270
double n[3]
Definition: libmmgtypes.h:272
int16_t tag
Definition: libmmgtypes.h:284
MMG5_int tmp
Definition: libmmgtypes.h:280
double c[3]
Definition: libmmgtypes.h:271
MMG5_int v[3]
Definition: libmmgtypes.h:334
Structure to store surface points of a MMG mesh.
Definition: libmmgtypes.h:294
MMG5_int MMGS_newPt(MMG5_pMesh mesh, double c[3], double n[3])
Definition: zaldy_s.c:39
int MMGS_delElt(MMG5_pMesh mesh, MMG5_int iel)
Definition: zaldy_s.c:93
int MMGS_zaldy(MMG5_pMesh mesh)
Definition: zaldy_s.c:263
int MMGS_setMeshSize_alloc(MMG5_pMesh mesh)
Definition: zaldy_s.c:223
static int MMGS_memOption_memSet(MMG5_pMesh mesh)
Definition: zaldy_s.c:128
void MMGS_delPt(MMG5_pMesh mesh, MMG5_int ip)
Definition: zaldy_s.c:58
int MMGS_memOption(MMG5_pMesh mesh)
Definition: zaldy_s.c:205
MMG5_int MMGS_newElt(MMG5_pMesh mesh)
Definition: zaldy_s.c:71