52 double logh,logs,*ma,*mb,ux,uy,d1,d2,dd,rap,dh;
53 double tail,coef,ma1[3],mb1[3],m[3],dd1,dd2;
54 double SQRT3DIV2=0.8660254037844386;
56 MMG5_int ncor,nc,k,iadr,a,b;
58 static int8_t mmgWarn = 0;
60 if ( abs(
mesh->info.imprim) > 5 ||
mesh->info.ddebug ) {
61 fprintf(stdout,
" ** Grading mesh\n");
66 logh =
mesh->info.hgrad;
74 fprintf(stderr,
"\n ## Error: %s: unable to allocate hash table.\n",__func__);
79 for(k=1 ; k<=
mesh->nt ; k++) {
84 for(i=0 ; i<3 ; i++) {
89 if (
mesh->point[a].s ||
mesh->point[b].s ) {
96 fprintf(stderr,
"\n ## Warning: %s: unable to hash at least one edge"
104 for (k=1; k<=
mesh->np; k++)
105 (&
mesh->point[k])->tagdel =
mesh->base+1;
111 for (k=0; k<edgeTable.
siz; k++) {
112 pht = &edgeTable.
item[k];
115 if ( !pht->
a )
break;
118 p1 = &
mesh->point[a];
119 p2 = &
mesh->point[b];
126 pht = pht->
nxt ? &edgeTable.
item[pht->
nxt] : 0;
131 ux = p2->
c[0] - p1->
c[0];
132 uy = p2->
c[1] - p1->
c[1];
134 d1 = ma[0]*ux*ux + ma[2]*uy*uy + 2.0*ma[1]*ux*uy;
136 if ( d1 < 0.0 ) d1 = 0.0;
139 d2 = mb[0]*ux*ux + mb[2]*uy*uy+ 2.0*mb[1]*ux*uy;
141 if ( d2 < 0.0 ) d2 = 0.0;
146 p1 = &
mesh->point[b];
147 p2 = &
mesh->point[a];
159 tail = (dd1+dd2+4*sqrt(0.5*(d1+d2))) / 6.0;
160 coef = log(rap) / tail;
166 coef = exp(tail*logh);
171 coef = 1.0 / (coef*coef);
172 for (i=0; i<3; i++) {
173 ma1[i] = coef * ma[i];
174 mb1[i] = coef * mb[i];
178 for (i=0; i<3; i++) ma[i] = m[i];
181 for (i=0; i<3; i++) ma[i] = SQRT3DIV2 * (ma[i]+mb1[i]);
184 for (i=0; i<3; i++) mb[i] = m[i];
187 for (i=0; i<3; i++) mb[i] = SQRT3DIV2 * (mb[i]+ma1[i]);
193 pht = pht->
nxt ? &edgeTable.
item[pht->
nxt] : 0;
197 }
while ( nc && ++itour < maxtou );
200 if ( abs(
mesh->info.imprim) > 3 && ncor ) {
201 fprintf(stdout,
" gradation: %7" MMG5_PRId
" updated, %d iter.\n",ncor,itour);