22 double dy2,dtavgInv,maxdy2,dtOut,safety,eps;
24 dtavgInv = 2.0/(dtn+dtnm1);
31 for (k=0; k < nPoints; k++)
33 dy2 = ypn[k]-ypnm1[k];
34 maxdy2 = fmax(maxdy2,fabs(dy2)*0.5/(1.0+fabs(yn[k])));
42 dtOut = sqrt(tau/(maxdy2+eps))*safety;
51 return (a < 0.0 ? -1.0 : 1.0);
55 double aa = fabs(a), bb = fabs(b);
56 if (a*b < 0.0)
return 0.0;
57 return aa <= bb ? a : b;
59 double musclmod(
double dU,
double dU1,
double dU2)
64 double minmod3(
double dU,
double dU1,
double dU2)
69 double mminmod2(
double dU,
double dU1,
double M,
int* tag)
85 A[0][0]*(A[1][1]*A[2][2]-A[2][1]*A[1][2])-
86 A[0][1]*(A[1][0]*A[2][2]-A[2][0]*A[1][2])+
87 A[0][2]*(A[1][0]*A[2][1]-A[2][0]*A[1][1]);
89 if (fabs(detA) <= 0.0)
91 printf(
"WARNING invertLocal3d detA= %g A= \n",detA);
95 printf(
"%g ",A[i][j]);
100 assert(fabs(detA) > 0.0);
102 AI[0][0] = detAinv*(A[1][1]*A[2][2]-A[1][2]*A[2][1]);
103 AI[0][1] = detAinv*(A[0][2]*A[2][1]-A[0][1]*A[2][2]);
104 AI[0][2] = detAinv*(A[0][1]*A[1][2]-A[0][2]*A[1][1]);
106 AI[1][0] = detAinv*(A[1][2]*A[2][0]-A[1][0]*A[2][2]);
107 AI[1][1] = detAinv*(A[0][0]*A[2][2]-A[0][2]*A[2][0]);
108 AI[1][2] = detAinv*(A[0][2]*A[1][0]-A[0][0]*A[1][2]);
110 AI[2][0] = detAinv*(A[1][0]*A[2][1]-A[1][1]*A[2][0]);
111 AI[2][1] = detAinv*(A[0][1]*A[2][0]-A[0][0]*A[2][1]);
112 AI[2][2] = detAinv*(A[0][0]*A[1][1]-A[0][1]*A[1][0]);
119 double u0,
double u1,
double * dU)
121 register double volume;
122 volume = fabs(x1[0]-x0[0]);
123 dN0[0]= -(x1[0]-x0[0]);
124 dN1[0]= -(x0[0]-x1[0]);
125 dU[0] = dN0[0]*u0 + dN1[0]*u1;
129 double * dN1,
double * dN2,
130 double u0,
double u1,
double u2,
double * dU)
132 double detJ,dx10[2],dx20[2],JinvT[2][2];
137 const double dN0h[2] = {-1.,-1.};
138 const double dN1h[2] = { 1., 0.};
139 const double dN2h[2] = { 0., 1.};
140 dx10[0] = x1[0]-x0[0]; dx10[1] = x1[1]-x0[1];
141 dx20[0] = x2[0]-x0[0]; dx20[1] = x2[1]-x0[1];
142 detJ = dx10[0]*dx20[1]-dx10[1]*dx20[0];
148 JinvT[0][0] = dx20[1]/detJ; JinvT[0][1] =-dx10[1]/detJ;
149 JinvT[1][0] =-dx20[0]/detJ; JinvT[1][1] = dx10[0]/detJ;
151 dN0[0] = JinvT[0][0]*dN0h[0]+JinvT[0][1]*dN0h[1];
152 dN0[1] = JinvT[1][0]*dN0h[0]+JinvT[1][1]*dN0h[1];
154 dN1[0] = JinvT[0][0]*dN1h[0]+JinvT[0][1]*dN1h[1];
155 dN1[1] = JinvT[1][0]*dN1h[0]+JinvT[1][1]*dN1h[1];
157 dN2[0] = JinvT[0][0]*dN2h[0]+JinvT[0][1]*dN2h[1];
158 dN2[1] = JinvT[1][0]*dN2h[0]+JinvT[1][1]*dN2h[1];
160 dU[0] = u0*dN0[0] + u1*dN1[0] + u2*dN2[0];
161 dU[1] = u0*dN0[1] + u1*dN1[1] + u2*dN2[1];
165 double * dN0,
double * dN1,
double * dN2,
double * dN3,
166 double u0,
double u1,
double u2,
double u3,
double * dU)
168 double dx[3][3],Jinv[3][3],JinvT[3][3];
169 int gradientFailed = 0;
174 const double dN0h[3] = {-1.,-1.,-1.};
175 const double dN1h[3] = { 1., 0.,0.};
176 const double dN2h[3] = { 0., 1.,0.};
177 const double dN3h[3] = { 0., 0.,1.};
178 dx[0][0] = x1[0]-x0[0]; dx[1][0] = x1[1]-x0[1]; dx[2][0] = x1[2]-x0[2];
179 dx[0][1] = x2[0]-x0[0]; dx[1][1] = x2[1]-x0[1]; dx[2][1] = x2[2]-x0[2];
180 dx[0][2] = x3[0]-x0[0]; dx[1][2] = x3[1]-x0[1]; dx[2][2] = x3[2]-x0[2];
184 if (gradientFailed != 0)
186 dU[0]=0.0; dU[1]=0.0; dU[2]=0.0;
188 JinvT[0][0] = Jinv[0][0]; JinvT[0][1] = Jinv[1][0]; JinvT[0][2] = Jinv[2][0];
189 JinvT[1][0] = Jinv[0][1]; JinvT[1][1] = Jinv[1][1]; JinvT[1][2] = Jinv[2][1];
190 JinvT[2][0] = Jinv[0][2]; JinvT[2][1] = Jinv[1][2]; JinvT[2][2] = Jinv[2][2];
194 dN0[0] = JinvT[0][0]*dN0h[0]+JinvT[0][1]*dN0h[1]+JinvT[0][2]*dN0h[2];
195 dN0[1] = JinvT[1][0]*dN0h[0]+JinvT[1][1]*dN0h[1]+JinvT[1][2]*dN0h[2];
196 dN0[2] = JinvT[2][0]*dN0h[0]+JinvT[2][1]*dN0h[1]+JinvT[2][2]*dN0h[2];
198 dN1[0] = JinvT[0][0]*dN1h[0]+JinvT[0][1]*dN1h[1]+JinvT[0][2]*dN1h[2];
199 dN1[1] = JinvT[1][0]*dN1h[0]+JinvT[1][1]*dN1h[1]+JinvT[1][2]*dN1h[2];
200 dN1[2] = JinvT[2][0]*dN1h[0]+JinvT[2][1]*dN1h[1]+JinvT[2][2]*dN1h[2];
202 dN2[0] = JinvT[0][0]*dN2h[0]+JinvT[0][1]*dN2h[1]+JinvT[0][2]*dN2h[2];
203 dN2[1] = JinvT[1][0]*dN2h[0]+JinvT[1][1]*dN2h[1]+JinvT[1][2]*dN2h[2];
204 dN2[2] = JinvT[2][0]*dN2h[0]+JinvT[2][1]*dN2h[1]+JinvT[2][2]*dN2h[2];
206 dN3[0] = JinvT[0][0]*dN3h[0]+JinvT[0][1]*dN3h[1]+JinvT[0][2]*dN3h[2];
207 dN3[1] = JinvT[1][0]*dN3h[0]+JinvT[1][1]*dN3h[1]+JinvT[1][2]*dN3h[2];
208 dN3[2] = JinvT[2][0]*dN3h[0]+JinvT[2][1]*dN3h[1]+JinvT[2][2]*dN3h[2];
210 dU[0] = u0*dN0[0] + u1*dN1[0] + u2*dN2[0] + u3*dN3[0];
211 dU[1] = u0*dN0[1] + u1*dN1[1] + u2*dN2[1] + u3*dN3[1];
212 dU[2] = u0*dN0[2] + u1*dN1[2] + u2*dN2[2] + u3*dN3[2];
215 int nElements_global,
217 int nElementBoundaries_element,
219 int * elementNodesArray,
220 int * elementNeighborsArray,
222 double * elementBarycentersArray,
257 int eN0,eN1,nN0,nN1,ndof0,ndof1;
259 double dUlim,dU,dU0,dU1,Ubar,Ubar0,Ubar1;
260 double xbar,xbar0,xbar1,dx;
262 for (eN=0; eN < nElements_global; eN++)
264 ndof0 = l2g[eN*nDOF_element + 0]; ndof1 = l2g[eN*nDOF_element + 1];
265 nN0 = elementNodesArray[eN*nNodes_element + 0];
266 nN1 = elementNodesArray[eN*nNodes_element + 1];
267 dx = nodeArray[nN1*3 + 0] - nodeArray[nN0*3 + 0];
268 xbar = elementBarycentersArray[eN*3 + 0];
270 dU = (Uin[ndof1]-Uin[ndof0])/dx;
271 Ubar = 0.5*(Uin[ndof1]+Uin[ndof0]);
275 xbar0 = nodeArray[nN1*3 + 0]; Ubar0 = Uin[ndof1];
276 eN0 = elementNeighborsArray[eN*nElementBoundaries_element + 0];
279 xbar0 = elementBarycentersArray[eN0*3 + 0];
280 Ubar0 = 0.5*(Uin[l2g[eN0*nDOF_element + 0]] + Uin[l2g[eN0*nDOF_element + 1]]);
282 dU0 = (Ubar0-Ubar)/(xbar0-xbar);
286 xbar1 = nodeArray[nN0*3 + 0]; Ubar1 = Uin[ndof0];
287 eN1 = elementNeighborsArray[eN*nElementBoundaries_element + 1];
290 xbar1 = elementBarycentersArray[eN1*3 + 0];
291 Ubar1 = 0.5*(Uin[l2g[eN1*nDOF_element + 0]] + Uin[l2g[eN1*nDOF_element + 1]]);
293 dU1 = (Ubar1-Ubar)/(xbar1-xbar);
295 if (limiterFlag == 2)
297 else if (limiterFlag == 1)
301 tag[eN] = fabs(dUlim-dU) < 1.0e-6;
304 Uout[ndof0] = Ubar + (nodeArray[nN0*3 + 0]-xbar)*dUlim;
305 Uout[ndof1] = Ubar + (nodeArray[nN1*3 + 0]-xbar)*dUlim;
312 int nElements_global,
314 int nElementBoundaries_element,
316 int * elementNodesArray,
317 int * elementNeighborsArray,
319 double * elementBarycentersArray,
354 int eN0,eN1,nN0,nN1,ndof0,ndof1;
356 double dUlim,dU,dU0,dU1,Ubar,Ubar0,Ubar1,Umin,UminA;
357 double xbar,xbar0,xbar1,dx;
359 for (eN=0; eN < nElements_global; eN++)
361 ndof0 = l2g[eN*nDOF_element + 0]; ndof1 = l2g[eN*nDOF_element + 1];
362 nN0 = elementNodesArray[eN*nNodes_element + 0];
363 nN1 = elementNodesArray[eN*nNodes_element + 1];
364 dx = nodeArray[nN1*3 + 0] - nodeArray[nN0*3 + 0];
365 xbar = elementBarycentersArray[eN*3 + 0];
367 dU = (Uin[ndof1]-Uin[ndof0])/dx;
368 Ubar = 0.5*(Uin[ndof1]+Uin[ndof0]);
369 Umin = fmin(Uin[ndof1],Uin[ndof0]);
370 UminA = fmin(fabs(Uin[ndof1]),fabs(Uin[ndof0]));
374 xbar0 = nodeArray[nN1*3 + 0]; Ubar0 = Uin[ndof1];
375 eN0 = elementNeighborsArray[eN*nElementBoundaries_element + 0];
378 xbar0 = elementBarycentersArray[eN0*3 + 0];
379 Ubar0 = 0.5*(Uin[l2g[eN0*nDOF_element + 0]] + Uin[l2g[eN0*nDOF_element + 1]]);
381 dU0 = (Ubar0-Ubar)/(xbar0-xbar);
385 xbar1 = nodeArray[nN0*3 + 0]; Ubar1 = Uin[ndof0];
386 eN1 = elementNeighborsArray[eN*nElementBoundaries_element + 1];
389 xbar1 = elementBarycentersArray[eN1*3 + 0];
390 Ubar1 = 0.5*(Uin[l2g[eN1*nDOF_element + 0]] + Uin[l2g[eN1*nDOF_element + 1]]);
392 dU1 = (Ubar1-Ubar)/(xbar1-xbar);
394 if (enforcePositivity && Umin < vacuumTol)
396 else if (UminA < vacuumTol)
400 tag[eN] = fabs(dUlim-dU) < 1.0e-6;
403 Uout[ndof0] = Ubar + (nodeArray[nN0*3 + 0]-xbar)*dUlim;
404 Uout[ndof1] = Ubar + (nodeArray[nN1*3 + 0]-xbar)*dUlim;
410 int nElementBoundaries_element,
412 const int * elementBoundariesArray,
413 const int * elementNeighborsArray,
414 double * elementBarycentersArray,
415 double * elementBoundaryBarycentersArray,
416 double * elementNeighborShapeGradients)
431 int eN,ebN,eN_opposite,ebN_global,ebNplus1, ebNplus2,I;
432 double u[4] = {1.0,1.0,1.0,1.0};
433 double dU[3]= {0.0,0.0,0.0};
435 double dN[4][3] = {{0.0,0.0,0.0},
440 double xn[5][3] = {{0.0,0.0,0.0},
447 for (eN = 0; eN < nElements_global; eN++)
449 xn[0][0] = elementBarycentersArray[eN*3 + 0];
450 xn[0][1] = elementBarycentersArray[eN*3 + 1];
451 xn[0][2] = elementBarycentersArray[eN*3 + 2];
454 for (ebN=0; ebN < nElementBoundaries_element; ebN++)
456 eN_opposite = elementNeighborsArray[eN*nElementBoundaries_element + ebN];
459 ebN_global = elementBoundariesArray[eN*nElementBoundaries_element + ebN];
460 xn[1][0] = elementBoundaryBarycentersArray[ebN_global*3 +0];
461 xn[1][1] = elementBoundaryBarycentersArray[ebN_global*3 +1];
462 xn[1][2] = elementBoundaryBarycentersArray[ebN_global*3 +2];
466 xn[1][0] = elementBarycentersArray[eN_opposite*3 +0];
467 xn[1][1] = elementBarycentersArray[eN_opposite*3 +1];
468 xn[1][2] = elementBarycentersArray[eN_opposite*3 +2];
472 elementNeighborShapeGradients[eN*nElementBoundaries_element*nElementBoundaries_element*nSpace +
473 ebN*nElementBoundaries_element*nSpace +
476 elementNeighborShapeGradients[eN*nElementBoundaries_element*nElementBoundaries_element*nSpace +
477 ebN*nElementBoundaries_element*nSpace +
483 else if (nSpace == 2)
485 for (eN = 0; eN < nElements_global; eN++)
487 xn[0][0] = elementBarycentersArray[eN*3 + 0];
488 xn[0][1] = elementBarycentersArray[eN*3 + 1];
489 xn[0][2] = elementBarycentersArray[eN*3 + 2];
492 for (ebN=0; ebN < nElementBoundaries_element; ebN++)
494 eN_opposite = elementNeighborsArray[eN*nElementBoundaries_element + ebN];
498 ebN_global = elementBoundariesArray[eN*nElementBoundaries_element + ebN];
499 xn[ebN+1][0] = elementBoundaryBarycentersArray[ebN_global*3 +0];
500 xn[ebN+1][1] = elementBoundaryBarycentersArray[ebN_global*3 +1];
501 xn[ebN+1][2] = elementBoundaryBarycentersArray[ebN_global*3 +2];
505 xn[ebN+1][0] = elementBarycentersArray[eN_opposite*3 +0];
506 xn[ebN+1][1] = elementBarycentersArray[eN_opposite*3 +1];
507 xn[ebN+1][2] = elementBarycentersArray[eN_opposite*3 +2];
515 for (ebN=0; ebN < nElementBoundaries_element; ebN++)
517 ebNplus1 = (ebN+1) % nElementBoundaries_element;
529 for (I = 0; I < nSpace; I++)
532 elementNeighborShapeGradients[eN*nElementBoundaries_element*nElementBoundaries_element*nSpace +
533 ebN*nElementBoundaries_element*nSpace +
537 elementNeighborShapeGradients[eN*nElementBoundaries_element*nElementBoundaries_element*nSpace +
538 ebN*nElementBoundaries_element*nSpace +
542 elementNeighborShapeGradients[eN*nElementBoundaries_element*nElementBoundaries_element*nSpace +
543 ebN*nElementBoundaries_element*nSpace +
553 for (eN = 0; eN < nElements_global; eN++)
555 xn[0][0] = elementBarycentersArray[eN*3 + 0];
556 xn[0][1] = elementBarycentersArray[eN*3 + 1];
557 xn[0][2] = elementBarycentersArray[eN*3 + 2];
560 for (ebN=0; ebN < nElementBoundaries_element; ebN++)
562 eN_opposite = elementNeighborsArray[eN*nElementBoundaries_element + ebN];
566 ebN_global = elementBoundariesArray[eN*nElementBoundaries_element + ebN];
567 xn[ebN+1][0] = elementBoundaryBarycentersArray[ebN_global*3 +0];
568 xn[ebN+1][1] = elementBoundaryBarycentersArray[ebN_global*3 +1];
569 xn[ebN+1][2] = elementBoundaryBarycentersArray[ebN_global*3 +2];
582 xn[ebN+1][0] = elementBarycentersArray[eN_opposite*3 +0];
583 xn[ebN+1][1] = elementBarycentersArray[eN_opposite*3 +1];
584 xn[ebN+1][2] = elementBarycentersArray[eN_opposite*3 +2];
601 for (ebN=0; ebN < nElementBoundaries_element; ebN++)
603 ebNplus1 = (ebN+1) % nElementBoundaries_element;
604 ebNplus2 = (ebN+2) % nElementBoundaries_element;
618 dN[0],dN[1],dN[2],dN[3],
619 u[0],
u[1],
u[2],
u[3],dU);
620 for (I = 0; I < nSpace; I++)
623 elementNeighborShapeGradients[eN*nElementBoundaries_element*nElementBoundaries_element*nSpace +
624 ebN*nElementBoundaries_element*nSpace +
628 elementNeighborShapeGradients[eN*nElementBoundaries_element*nElementBoundaries_element*nSpace +
629 ebN*nElementBoundaries_element*nSpace +
633 elementNeighborShapeGradients[eN*nElementBoundaries_element*nElementBoundaries_element*nSpace +
634 ebN*nElementBoundaries_element*nSpace +
638 elementNeighborShapeGradients[eN*nElementBoundaries_element*nElementBoundaries_element*nSpace +
639 ebN*nElementBoundaries_element*nSpace +
650 int nElementBoundaries_element,
652 const int * elementBoundariesArray,
653 const int * elementNeighborsArray,
654 const double * elementBarycentersArray,
655 const double * elementBoundaryBarycentersArray,
656 const double * elementNeighborShapeGradients,
658 int * alphaNeighbors)
660 int eN,ebN,ebN_global,ebN_I,ebN_Iplus1,eN_ebN_I,eN_ebN_Iplus1,lamn[2],
661 onBoundary,positiveFound;
664 for (eN=0; eN < nElements_global; eN++)
667 elementNeighborsArray[eN*nElementBoundaries_element + 0] < 0 ||
668 elementNeighborsArray[eN*nElementBoundaries_element + 1] < 0 ||
669 elementNeighborsArray[eN*nElementBoundaries_element + 2] < 0;
671 for (ebN=0; ebN < nElementBoundaries_element; ebN++)
673 ebN_global = elementBoundariesArray[eN*nElementBoundaries_element+ebN];
676 lam[0] = 0.0; lam[1] = 0.0;
677 lamn[0]=-1; lamn[1]=-1;
678 alphas[eN*nElementBoundaries_element*nSpace + ebN*nSpace + 0] = lam[0];
679 alphas[eN*nElementBoundaries_element*nSpace + ebN*nSpace + 1] = lam[1];
680 alphaNeighbors[eN*nElementBoundaries_element*nSpace + ebN*nSpace + 0] = lamn[0];
681 alphaNeighbors[eN*nElementBoundaries_element*nSpace + ebN*nSpace + 1] = lamn[1];
685 positiveFound = 0; ebN_I=0;
686 while (ebN_I < nElementBoundaries_element && positiveFound == 0)
688 lam[0] = 0.0; lam[1] = 0.0; lamn[0] = -1; lamn[1] = -1;
695 ebN_Iplus1 = (ebN_I + 1) % nElementBoundaries_element;
696 eN_ebN_I = elementNeighborsArray[eN*nElementBoundaries_element+ebN_I];
697 eN_ebN_Iplus1 = elementNeighborsArray[eN*nElementBoundaries_element+ebN_Iplus1];
698 lamn[0] = eN_ebN_I; lamn[1] = eN_ebN_Iplus1;
701 elementNeighborShapeGradients[eN*nElementBoundaries_element*nElementBoundaries_element*nSpace +
702 ebN_I*nElementBoundaries_element*nSpace +
704 *(elementBoundaryBarycentersArray[ebN_global*3 + 0] - elementBarycentersArray[eN_ebN_I*3 + 0])
706 elementNeighborShapeGradients[eN*nElementBoundaries_element*nElementBoundaries_element*nSpace +
707 ebN_I*nElementBoundaries_element*nSpace +
709 *(elementBoundaryBarycentersArray[ebN_global*3 + 1] - elementBarycentersArray[eN_ebN_I*3 + 1]);
711 elementNeighborShapeGradients[eN*nElementBoundaries_element*nElementBoundaries_element*nSpace +
712 ebN_I*nElementBoundaries_element*nSpace +
714 *(elementBoundaryBarycentersArray[ebN_global*3 + 0] - elementBarycentersArray[eN_ebN_Iplus1*3 + 0])
716 elementNeighborShapeGradients[eN*nElementBoundaries_element*nElementBoundaries_element*nSpace +
717 ebN_I*nElementBoundaries_element*nSpace +
719 *(elementBoundaryBarycentersArray[ebN_global*3 + 1] - elementBarycentersArray[eN_ebN_Iplus1*3 + 1]);
720 if (lam[0] >= -1.0e-10 && lam[1] >= -1.0e-10)
723 alphas[eN*nElementBoundaries_element*nSpace + ebN*nSpace + 0] = lam[0];
724 alphas[eN*nElementBoundaries_element*nSpace + ebN*nSpace + 1] = lam[1];
725 alphaNeighbors[eN*nElementBoundaries_element*nSpace + ebN*nSpace + 0] = lamn[0];
726 alphaNeighbors[eN*nElementBoundaries_element*nSpace + ebN*nSpace + 1] = lamn[1];
730 assert(positiveFound);
738 int nElements_global,
739 int nElementBoundaries_element,
742 int * elementNeighborsArray,
746 int * alphaNeighbors,
754 double dU,deltaU[3],tdeltaU[3],
pos[3],
neg[3],pos_eN,neg_eN,thp,thm,sumDU,
755 uM[3],uMlim[3],uBar,uBar_0,uBar_1;
756 int eN,ebN,ebNplus1,ebNplus2,eN_0,eN_1,onBoundary,tag_eN[3];
758 double uavgIn,uavgOut;
759 double oneThird=1.0/3.0;
761 for (eN = 0; eN < nElements_global; eN++)
763 uBar = (Uin[l2g[eN*nDOF_element+0]]+Uin[l2g[eN*nDOF_element+1]]+Uin[l2g[eN*nDOF_element+2]])*oneThird;
766 elementNeighborsArray[eN*nElementBoundaries_element + 0] < 0 ||
767 elementNeighborsArray[eN*nElementBoundaries_element + 1] < 0 ||
768 elementNeighborsArray[eN*nElementBoundaries_element + 2] < 0;
771 tdeltaU[0] = 0.0; tdeltaU[1] = 0.0; tdeltaU[2] = 0.0;
775 for (ebN=0; ebN < nElementBoundaries_element; ebN++)
777 ebNplus1 = (ebN+1) % nElementBoundaries_element;
778 ebNplus2 = (ebN+2) % nElementBoundaries_element;
784 uM[ebN] = 0.5*(Uin[l2g[eN*nDOF_element+ebNplus1]]+Uin[l2g[eN*nDOF_element+ebNplus2]]);
785 eN_0 = alphaNeighbors[eN*nElementBoundaries_element*nSpace + ebN*nSpace + 0];
786 eN_1 = alphaNeighbors[eN*nElementBoundaries_element*nSpace + ebN*nSpace + 1];
787 uBar_0 = (Uin[l2g[eN_0*nDOF_element+0]]+Uin[l2g[eN_0*nDOF_element+1]]+Uin[l2g[eN_0*nDOF_element+2]])*oneThird;
788 uBar_1 = (Uin[l2g[eN_1*nDOF_element+0]]+Uin[l2g[eN_1*nDOF_element+1]]+Uin[l2g[eN_1*nDOF_element+2]])*oneThird;
789 dU = alphas[eN*nElementBoundaries_element*nSpace + ebN*nSpace + 0]*(uBar_0-uBar)+
790 alphas[eN*nElementBoundaries_element*nSpace + ebN*nSpace + 1]*(uBar_1-uBar);
791 deltaU[ebN] =
mminmod2(uM[ebN]-uBar,nu*dU,Mh2,&tag_eN[ebN]);
792 tdeltaU[ebN]= deltaU[ebN];
795 sumDU = tdeltaU[0] + tdeltaU[1] + tdeltaU[2];
796 if (fabs(sumDU) > 1.0e-6)
799 pos_eN = 0.0; neg_eN = 0.0;
800 for (ebN=0; ebN < nElementBoundaries_element; ebN++)
802 pos[ebN] = ( deltaU[ebN] > 0.0) ? deltaU[ebN] : 0.0;
803 neg[ebN] = (-deltaU[ebN] > 0.0) ? -deltaU[ebN] : 0.0;
807 thp = (1.0 < neg_eN/pos_eN) ? 1.0 : neg_eN/pos_eN;
808 thm = (1.0 < pos_eN/neg_eN) ? 1.0 : pos_eN/neg_eN;
809 for (ebN=0; ebN < nElementBoundaries_element; ebN++)
811 tdeltaU[ebN] = thp*
pos[ebN] - thm*
neg[ebN];
819 uMlim[0] = uBar + tdeltaU[0];
820 uMlim[1] = uBar + tdeltaU[1];
821 uMlim[2] = uBar + tdeltaU[2];
824 Uout[l2g[eN*nDOF_element + 0]] = uMlim[1]+uMlim[2]-uMlim[0];
825 Uout[l2g[eN*nDOF_element + 1]] = uMlim[2]+uMlim[0]-uMlim[1];
826 Uout[l2g[eN*nDOF_element + 2]] = uMlim[0]+uMlim[1]-uMlim[2];
827 tag[eN] = tag_eN[0] + tag_eN[1] + tag_eN[2] == 3;
829 uavgOut = (Uout[l2g[eN*nDOF_element + 0]]+Uout[l2g[eN*nDOF_element + 1]]+Uout[l2g[eN*nDOF_element + 2]])*oneThird;
843 double * elementAverages)
846 const double denom = 1.0/nDOF_element;
847 for (eN = 0; eN < nElements_global; eN++)
849 elementAverages[eN] = 0.0;
850 for (i=0; i < nDOF_element; i++)
852 I = l2g[eN*nDOF_element+i];
853 elementAverages[eN] += Uin[I];
855 elementAverages[eN] *= denom;
864 register int i,j,itmp;
866 for (i=0; i < len; i++)
869 for (j = i+1; j < len; j++)
873 tmp = A[i]; A[i]= A[j]; A[j]= tmp;
874 itmp= order[i]; order[i] = order[j]; order[j] = itmp;
880 int allowMinWithUndershoot,
881 int nElements_global,
882 int nElementBoundaries_element,
886 const int * elementNeighborsArray,
887 const int * elementBoundariesArray,
888 const int * elementNodesArray,
889 const double * nodeArray,
890 const double * elementBarycentersArray,
891 const double * elementBoundaryBarycentersArray,
892 const double * elementNeighborShapeGradients,
894 const double * grad_v0,
895 double * elementAverages,
901 int eN,nN_global,ebN,ebN_global,ebN_1,eN_ebN,eN_ebN_1,onBoundary,isExtremum;
902 int dUdescendingOrder[4];
903 double normDU[4],dU[4][2],max_ebN,min_ebN,uM;
905 double normDUsave[4];
906 int maxFound,minFound,islot,i,itmp,okGradient;
907 int nElementBoundaries_element2 = nElementBoundaries_element*nElementBoundaries_element;
908 register int DOF0,DOF1,DOF2;
909 register double dUlim0,dUlim1;
910 register double uBar,uBar_ebN,uBar_ebN_1;
912 const double otol = 1.0e-5;
916 for (eN = 0; eN < nElements_global; eN++)
919 uBar = elementAverages[eN];
920 DOF0 = l2g[eN*nDOF_element+0]; DOF1 = l2g[eN*nDOF_element+1]; DOF2 = l2g[eN*nDOF_element+2];
922 elementNeighborsArray[eN*nElementBoundaries_element + 0] < 0 ||
923 elementNeighborsArray[eN*nElementBoundaries_element + 1] < 0 ||
924 elementNeighborsArray[eN*nElementBoundaries_element + 2] < 0;
927 dUlim0 = 0.0; dUlim1 = 0.0;
933 maxFound = 0; minFound = 0;
934 for (ebN = 0; ebN < nElementBoundaries_element; ebN++)
936 eN_ebN = elementNeighborsArray[eN*nElementBoundaries_element + ebN];
937 uBar_ebN = elementAverages[eN_ebN];
938 maxFound = uBar_ebN > uBar ? 1 : maxFound;
939 minFound = uBar_ebN < uBar ? 1 : minFound;
941 isExtremum = (maxFound*minFound == 0);
942 if (isExtremum && killExtrema > 0)
948 dUlim0 = 0.0; dUlim1 = 0.0;
954 dUlim0 = 0.0; dUlim1 = 0.0;
956 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 0*nSpace + 0]*Uin[DOF0]+
957 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 1*nSpace + 0]*Uin[DOF1]+
958 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 2*nSpace + 0]*Uin[DOF2];
960 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 0*nSpace + 1]*Uin[DOF0]+
961 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 1*nSpace + 1]*Uin[DOF1]+
962 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 2*nSpace + 1]*Uin[DOF2];
963 normDU[0] = sqrt(dU[0][0]*dU[0][0] + dU[0][1]*dU[0][1]);
964 normDU[1] = 0.0; normDU[2] = 0.0; normDU[3] = 0.0;
966 for (ebN = 0; ebN < nElementBoundaries_element; ebN++)
968 ebN_1 = (ebN+1) % nElementBoundaries_element;
975 eN_ebN = elementNeighborsArray[eN*nElementBoundaries_element + ebN];
976 eN_ebN_1 = elementNeighborsArray[eN*nElementBoundaries_element + ebN_1];
977 uBar_ebN = elementAverages[eN_ebN];
978 uBar_ebN_1= elementAverages[eN_ebN_1];
981 dU[ebN+1][0] = 0.0; dU[ebN+1][1] = 0.0;
983 uBar*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
984 ebN*nElementBoundaries_element*nSpace +
987 uBar_ebN*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
988 ebN*nElementBoundaries_element*nSpace +
991 uBar_ebN_1*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
992 ebN*nElementBoundaries_element*nSpace +
996 uBar*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
997 ebN*nElementBoundaries_element*nSpace +
1000 uBar_ebN*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1001 ebN*nElementBoundaries_element*nSpace +
1004 uBar_ebN_1*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1005 ebN*nElementBoundaries_element*nSpace +
1007 normDU[ebN+1] = sqrt(dU[ebN+1][0]*dU[ebN+1][0] + dU[ebN+1][1]*dU[ebN+1][1]);
1010 dUdescendingOrder[0] = 0; dUdescendingOrder[1] = 1; dUdescendingOrder[2]=2; dUdescendingOrder[3]=3;
1011 normDUsave[0] = normDU[0]; normDUsave[1]=normDU[1]; normDUsave[2]=normDU[2]; normDUsave[3]=normDU[3];
1041 okGradient = 0; islot = 0;
1043 while (okGradient == 0 && islot < nElementBoundaries_element)
1045 itmp = dUdescendingOrder[islot];
1048 for (ebN = 0; ebN < nElementBoundaries_element; ebN++)
1050 eN_ebN = elementNeighborsArray[eN*nElementBoundaries_element + ebN];
1051 uBar_ebN = elementAverages[eN_ebN];
1052 ebN_global = elementBoundariesArray[eN*nElementBoundaries_element + ebN];
1055 dU[itmp][0]*(elementBoundaryBarycentersArray[ebN_global*3 + 0]-
1056 elementBarycentersArray[eN*3 + 0])
1058 dU[itmp][1]*(elementBoundaryBarycentersArray[ebN_global*3 + 1]-
1059 elementBarycentersArray[eN*3 + 1]);
1060 max_ebN = uBar > uBar_ebN ? uBar : uBar_ebN;
1061 min_ebN = uBar < uBar_ebN ? uBar : uBar_ebN;
1063 okGradient = (okGradient > 0) && min_ebN <= uM -otol && uM <= max_ebN + otol;
1068 if (okGradient == 1)
1070 if (okGradient || allowMinWithUndershoot > 0)
1072 itmp = dUdescendingOrder[islot];
1073 dUlim0 = dU[itmp][0];
1074 dUlim1 = dU[itmp][1];
1075 tag[eN] = islot == 0 ? 1 : 0;
1085 nN_global = elementNodesArray[eN*nNodes_element+0];
1088 dUlim0*(nodeArray[nN_global*3 + 0] - elementBarycentersArray[eN*3 + 0])
1090 dUlim1*(nodeArray[nN_global*3 + 1] - elementBarycentersArray[eN*3 + 1]);
1091 nN_global = elementNodesArray[eN*nNodes_element+1];
1094 dUlim0*(nodeArray[nN_global*3 + 0] - elementBarycentersArray[eN*3 + 0])
1096 dUlim1*(nodeArray[nN_global*3 + 1] - elementBarycentersArray[eN*3 + 1]);
1097 nN_global = elementNodesArray[eN*nNodes_element+2];
1100 dUlim0*(nodeArray[nN_global*3 + 0] - elementBarycentersArray[eN*3 + 0])
1102 dUlim1*(nodeArray[nN_global*3 + 1] - elementBarycentersArray[eN*3 + 1]);
1108 int allowMinWithUndershoot,
1109 int nElements_global,
1110 int nElementBoundaries_element,
1114 const int * elementNeighborsArray,
1115 const int * elementBoundariesArray,
1116 const int * elementNodesArray,
1117 const double * nodeArray,
1118 const double * elementBarycentersArray,
1119 const double * elementBoundaryBarycentersArray,
1120 const double * elementNeighborShapeGradients,
1122 const double * grad_v0,
1123 double * elementAverages,
1129 int eN,nN_global,ebN,ebN_global,ebN_1,ebN_2,eN_ebN,eN_ebN_1,eN_ebN_2,onBoundary,isExtremum;
1130 int dUdescendingOrder[5];
1131 double normDU[5],dU[5][3],max_ebN,min_ebN,uM;
1133 double normDUsave[5];
1134 int maxFound,minFound,islot,i,itmp,okGradient;
1135 int nElementBoundaries_element2 = nElementBoundaries_element*nElementBoundaries_element;
1136 register int DOF0,DOF1,DOF2,DOF3;
1137 register double dUlim0,dUlim1,dUlim2;
1138 register double uBar,uBar_ebN,uBar_ebN_1,uBar_ebN_2;
1140 const double otol = 1.0e-5;
1143 for (eN = 0; eN < nElements_global; eN++)
1146 uBar = elementAverages[eN];
1147 DOF0 = l2g[eN*nDOF_element+0]; DOF1 = l2g[eN*nDOF_element+1];
1148 DOF2 = l2g[eN*nDOF_element+2]; DOF3 = l2g[eN*nDOF_element+3];
1150 elementNeighborsArray[eN*nElementBoundaries_element + 0] < 0 ||
1151 elementNeighborsArray[eN*nElementBoundaries_element + 1] < 0 ||
1152 elementNeighborsArray[eN*nElementBoundaries_element + 2] < 0 ||
1153 elementNeighborsArray[eN*nElementBoundaries_element + 3] < 0;
1156 dUlim0 = 0.0; dUlim1 = 0.0; dUlim2 = 0.0;
1162 maxFound = 0; minFound = 0;
1163 for (ebN = 0; ebN < nElementBoundaries_element; ebN++)
1165 eN_ebN = elementNeighborsArray[eN*nElementBoundaries_element + ebN];
1166 uBar_ebN = elementAverages[eN_ebN];
1167 maxFound = uBar_ebN > uBar ? 1 : maxFound;
1168 minFound = uBar_ebN < uBar ? 1 : minFound;
1170 isExtremum = (maxFound*minFound == 0);
1171 if (isExtremum && killExtrema > 0)
1177 dUlim0 = 0.0; dUlim1 = 0.0; dUlim2 = 0.0;
1183 dUlim0 = 0.0; dUlim1 = 0.0; dUlim2 = 0.0;
1185 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 0*nSpace + 0]*Uin[DOF0]+
1186 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 1*nSpace + 0]*Uin[DOF1]+
1187 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 2*nSpace + 0]*Uin[DOF2]+
1188 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 3*nSpace + 0]*Uin[DOF3];
1190 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 0*nSpace + 1]*Uin[DOF0]+
1191 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 1*nSpace + 1]*Uin[DOF1]+
1192 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 2*nSpace + 1]*Uin[DOF2]+
1193 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 3*nSpace + 1]*Uin[DOF3];
1195 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 0*nSpace + 2]*Uin[DOF0]+
1196 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 1*nSpace + 2]*Uin[DOF1]+
1197 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 2*nSpace + 2]*Uin[DOF2]+
1198 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 3*nSpace + 2]*Uin[DOF3];
1199 normDU[0] = sqrt(dU[0][0]*dU[0][0] + dU[0][1]*dU[0][1] + dU[0][2]*dU[0][2]);
1200 normDU[1] = 0.0; normDU[2] = 0.0; normDU[3] = 0.0; normDU[4] = 0.0;
1202 for (ebN = 0; ebN < nElementBoundaries_element; ebN++)
1204 ebN_1 = (ebN+1) % nElementBoundaries_element;
1205 ebN_2 = (ebN+2) % nElementBoundaries_element;
1213 eN_ebN = elementNeighborsArray[eN*nElementBoundaries_element + ebN];
1214 eN_ebN_1 = elementNeighborsArray[eN*nElementBoundaries_element + ebN_1];
1215 eN_ebN_2 = elementNeighborsArray[eN*nElementBoundaries_element + ebN_2];
1216 uBar_ebN = elementAverages[eN_ebN];
1217 uBar_ebN_1= elementAverages[eN_ebN_1];
1218 uBar_ebN_2= elementAverages[eN_ebN_2];
1221 dU[ebN+1][0] = 0.0; dU[ebN+1][1] = 0.0; dU[ebN+1][2] = 0.0;
1223 uBar*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1224 ebN*nElementBoundaries_element*nSpace +
1227 uBar_ebN*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1228 ebN*nElementBoundaries_element*nSpace +
1231 uBar_ebN_1*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1232 ebN*nElementBoundaries_element*nSpace +
1235 uBar_ebN_2*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1236 ebN*nElementBoundaries_element*nSpace +
1240 uBar*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1241 ebN*nElementBoundaries_element*nSpace +
1244 uBar_ebN*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1245 ebN*nElementBoundaries_element*nSpace +
1248 uBar_ebN_1*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1249 ebN*nElementBoundaries_element*nSpace +
1252 uBar_ebN_1*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1253 ebN*nElementBoundaries_element*nSpace +
1257 uBar*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1258 ebN*nElementBoundaries_element*nSpace +
1261 uBar_ebN*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1262 ebN*nElementBoundaries_element*nSpace +
1265 uBar_ebN_1*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1266 ebN*nElementBoundaries_element*nSpace +
1269 uBar_ebN_1*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1270 ebN*nElementBoundaries_element*nSpace +
1273 normDU[ebN+1] = sqrt(dU[ebN+1][0]*dU[ebN+1][0] + dU[ebN+1][1]*dU[ebN+1][1] + dU[ebN+1][2]*dU[ebN+1][2]);
1276 dUdescendingOrder[0] = 0; dUdescendingOrder[1] = 1; dUdescendingOrder[2]=2;
1277 dUdescendingOrder[3]=3; dUdescendingOrder[4] = 4;
1279 normDUsave[0] = normDU[0]; normDUsave[1]=normDU[1]; normDUsave[2]=normDU[2]; normDUsave[3]=normDU[3];
1280 normDUsave[4] = normDU[4];
1311 okGradient = 0; islot = 0;
1313 while (okGradient == 0 && islot < nElementBoundaries_element)
1315 itmp = dUdescendingOrder[islot];
1318 for (ebN = 0; ebN < nElementBoundaries_element; ebN++)
1320 eN_ebN = elementNeighborsArray[eN*nElementBoundaries_element + ebN];
1321 uBar_ebN = elementAverages[eN_ebN];
1322 ebN_global = elementBoundariesArray[eN*nElementBoundaries_element + ebN];
1325 dU[itmp][0]*(elementBoundaryBarycentersArray[ebN_global*3 + 0]-
1326 elementBarycentersArray[eN*3 + 0])
1328 dU[itmp][1]*(elementBoundaryBarycentersArray[ebN_global*3 + 1]-
1329 elementBarycentersArray[eN*3 + 1])
1331 dU[itmp][2]*(elementBoundaryBarycentersArray[ebN_global*3 + 2]-
1332 elementBarycentersArray[eN*3 + 2]);
1334 max_ebN = uBar > uBar_ebN ? uBar : uBar_ebN;
1335 min_ebN = uBar < uBar_ebN ? uBar : uBar_ebN;
1337 okGradient = (okGradient > 0) && min_ebN <= uM -otol && uM <= max_ebN + otol;
1342 if (okGradient == 1)
1344 if (okGradient || allowMinWithUndershoot > 0)
1346 itmp = dUdescendingOrder[islot];
1347 dUlim0 = dU[itmp][0];
1348 dUlim1 = dU[itmp][1];
1349 dUlim2 = dU[itmp][2];
1350 tag[eN] = islot == 0 ? 1 : 0;
1361 nN_global = elementNodesArray[eN*nNodes_element+0];
1364 dUlim0*(nodeArray[nN_global*3 + 0] - elementBarycentersArray[eN*3 + 0])
1366 dUlim1*(nodeArray[nN_global*3 + 1] - elementBarycentersArray[eN*3 + 1])
1368 dUlim2*(nodeArray[nN_global*3 + 2] - elementBarycentersArray[eN*3 + 2]);
1369 nN_global = elementNodesArray[eN*nNodes_element+1];
1372 dUlim0*(nodeArray[nN_global*3 + 0] - elementBarycentersArray[eN*3 + 0])
1374 dUlim1*(nodeArray[nN_global*3 + 1] - elementBarycentersArray[eN*3 + 1])
1376 dUlim2*(nodeArray[nN_global*3 + 2] - elementBarycentersArray[eN*3 + 2]);
1377 nN_global = elementNodesArray[eN*nNodes_element+2];
1380 dUlim0*(nodeArray[nN_global*3 + 0] - elementBarycentersArray[eN*3 + 0])
1382 dUlim1*(nodeArray[nN_global*3 + 1] - elementBarycentersArray[eN*3 + 1])
1384 dUlim2*(nodeArray[nN_global*3 + 2] - elementBarycentersArray[eN*3 + 2]);
1385 nN_global = elementNodesArray[eN*nNodes_element+3];
1388 dUlim0*(nodeArray[nN_global*3 + 0] - elementBarycentersArray[eN*3 + 0])
1390 dUlim1*(nodeArray[nN_global*3 + 1] - elementBarycentersArray[eN*3 + 1])
1392 dUlim2*(nodeArray[nN_global*3 + 2] - elementBarycentersArray[eN*3 + 2]);
1398 int allowMinWithUndershoot,
1399 int enforcePositivity,
1401 int nElements_global,
1402 int nElementBoundaries_element,
1406 const int * elementNeighborsArray,
1407 const int * elementBoundariesArray,
1408 const int * elementNodesArray,
1409 const double * nodeArray,
1410 const double * elementBarycentersArray,
1411 const double * elementBoundaryBarycentersArray,
1412 const double * elementNeighborShapeGradients,
1414 const double * grad_v0,
1415 double * elementAverages,
1421 int eN,nN_global,ebN,ebN_global,ebN_1,eN_ebN,eN_ebN_1,onBoundary,isExtremum;
1422 int dUdescendingOrder[4];
1423 double normDU[4],dU[4][2],max_ebN,min_ebN,uM;
1425 double normDUsave[4];
1426 int maxFound,minFound,islot,i,itmp,okGradient;
1427 int nElementBoundaries_element2 = nElementBoundaries_element*nElementBoundaries_element;
1428 register int DOF0,DOF1,DOF2;
1429 register double dUlim0,dUlim1;
1430 register double uBar,uBar_ebN,uBar_ebN_1;
1432 const double otol = 1.0e-5;
1436 for (eN = 0; eN < nElements_global; eN++)
1439 uBar = elementAverages[eN];
1440 DOF0 = l2g[eN*nDOF_element+0]; DOF1 = l2g[eN*nDOF_element+1]; DOF2 = l2g[eN*nDOF_element+2];
1442 elementNeighborsArray[eN*nElementBoundaries_element + 0] < 0 ||
1443 elementNeighborsArray[eN*nElementBoundaries_element + 1] < 0 ||
1444 elementNeighborsArray[eN*nElementBoundaries_element + 2] < 0;
1447 dUlim0 = 0.0; dUlim1 = 0.0;
1453 maxFound = 0; minFound = 0;
1454 for (ebN = 0; ebN < nElementBoundaries_element; ebN++)
1456 eN_ebN = elementNeighborsArray[eN*nElementBoundaries_element + ebN];
1457 uBar_ebN = elementAverages[eN_ebN];
1458 maxFound = uBar_ebN > uBar ? 1 : maxFound;
1459 minFound = uBar_ebN < uBar ? 1 : minFound;
1461 isExtremum = (maxFound*minFound == 0);
1462 if (isExtremum && killExtrema > 0)
1468 dUlim0 = 0.0; dUlim1 = 0.0;
1471 else if (fabs(uBar) < vacuumTol)
1473 dUlim0 = 0.0; dUlim1 = 0.0;
1476 else if (enforcePositivity && uBar < vacuumTol)
1478 dUlim0 = 0.0; dUlim1 = 0.0;
1484 dUlim0 = 0.0; dUlim1 = 0.0;
1486 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 0*nSpace + 0]*Uin[DOF0]+
1487 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 1*nSpace + 0]*Uin[DOF1]+
1488 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 2*nSpace + 0]*Uin[DOF2];
1490 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 0*nSpace + 1]*Uin[DOF0]+
1491 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 1*nSpace + 1]*Uin[DOF1]+
1492 grad_v0[eN*1*nDOF_element*nSpace + 0*nDOF_element*nSpace + 2*nSpace + 1]*Uin[DOF2];
1493 normDU[0] = sqrt(dU[0][0]*dU[0][0] + dU[0][1]*dU[0][1]);
1494 normDU[1] = 0.0; normDU[2] = 0.0; normDU[3] = 0.0;
1496 for (ebN = 0; ebN < nElementBoundaries_element; ebN++)
1498 ebN_1 = (ebN+1) % nElementBoundaries_element;
1505 eN_ebN = elementNeighborsArray[eN*nElementBoundaries_element + ebN];
1506 eN_ebN_1 = elementNeighborsArray[eN*nElementBoundaries_element + ebN_1];
1507 uBar_ebN = elementAverages[eN_ebN];
1508 uBar_ebN_1= elementAverages[eN_ebN_1];
1511 dU[ebN+1][0] = 0.0; dU[ebN+1][1] = 0.0;
1513 uBar*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1514 ebN*nElementBoundaries_element*nSpace +
1517 uBar_ebN*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1518 ebN*nElementBoundaries_element*nSpace +
1521 uBar_ebN_1*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1522 ebN*nElementBoundaries_element*nSpace +
1526 uBar*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1527 ebN*nElementBoundaries_element*nSpace +
1530 uBar_ebN*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1531 ebN*nElementBoundaries_element*nSpace +
1534 uBar_ebN_1*elementNeighborShapeGradients[eN*nElementBoundaries_element2*nSpace +
1535 ebN*nElementBoundaries_element*nSpace +
1537 normDU[ebN+1] = sqrt(dU[ebN+1][0]*dU[ebN+1][0] + dU[ebN+1][1]*dU[ebN+1][1]);
1540 dUdescendingOrder[0] = 0; dUdescendingOrder[1] = 1; dUdescendingOrder[2]=2; dUdescendingOrder[3]=3;
1541 normDUsave[0] = normDU[0]; normDUsave[1]=normDU[1]; normDUsave[2]=normDU[2]; normDUsave[3]=normDU[3];
1571 okGradient = 0; islot = 0;
1573 while (okGradient == 0 && islot < nElementBoundaries_element)
1575 itmp = dUdescendingOrder[islot];
1578 for (ebN = 0; ebN < nElementBoundaries_element; ebN++)
1580 eN_ebN = elementNeighborsArray[eN*nElementBoundaries_element + ebN];
1581 uBar_ebN = elementAverages[eN_ebN];
1582 ebN_global = elementBoundariesArray[eN*nElementBoundaries_element + ebN];
1585 dU[itmp][0]*(elementBoundaryBarycentersArray[ebN_global*3 + 0]-
1586 elementBarycentersArray[eN*3 + 0])
1588 dU[itmp][1]*(elementBoundaryBarycentersArray[ebN_global*3 + 1]-
1589 elementBarycentersArray[eN*3 + 1]);
1590 max_ebN = uBar > uBar_ebN ? uBar : uBar_ebN;
1591 min_ebN = uBar < uBar_ebN ? uBar : uBar_ebN;
1593 okGradient = (okGradient > 0) && min_ebN <= uM -otol && uM <= max_ebN + otol &&
1594 fabs(min_ebN) >= vacuumTol && fabs(max_ebN) >= vacuumTol;
1595 if (enforcePositivity)
1597 okGradient = (okGradient > 0) && min_ebN >= vacuumTol && max_ebN >= vacuumTol;
1603 if (okGradient == 1)
1605 if ((okGradient || allowMinWithUndershoot > 0) && uBar > vacuumTol)
1607 itmp = dUdescendingOrder[islot];
1608 dUlim0 = dU[itmp][0];
1609 dUlim1 = dU[itmp][1];
1610 tag[eN] = islot == 0 ? 1 : 0;
1620 nN_global = elementNodesArray[eN*nNodes_element+0];
1623 dUlim0*(nodeArray[nN_global*3 + 0] - elementBarycentersArray[eN*3 + 0])
1625 dUlim1*(nodeArray[nN_global*3 + 1] - elementBarycentersArray[eN*3 + 1]);
1626 nN_global = elementNodesArray[eN*nNodes_element+1];
1629 dUlim0*(nodeArray[nN_global*3 + 0] - elementBarycentersArray[eN*3 + 0])
1631 dUlim1*(nodeArray[nN_global*3 + 1] - elementBarycentersArray[eN*3 + 1]);
1632 nN_global = elementNodesArray[eN*nNodes_element+2];
1635 dUlim0*(nodeArray[nN_global*3 + 0] - elementBarycentersArray[eN*3 + 0])
1637 dUlim1*(nodeArray[nN_global*3 + 1] - elementBarycentersArray[eN*3 + 1]);