15 #include "../Exceptions/exceptions.h"
16 #include "../MemOps/MemOps.h"
20 int TripleMultiply(
IssmDouble* a,
int nrowa,
int ncola,
int itrna,
IssmDouble* b,
int nrowb,
int ncolb,
int itrnb,
IssmDouble* c,
int nrowc,
int ncolc,
int itrnc,
IssmDouble* d,
int iaddd){
23 int idima,idimb,idimc,idimd;
40 if (nrowb != idimb)
_error_(
"Matrix A and B inner vectors not equal size.");
44 if (ncolb != idimb)
_error_(
"Matrix A and B inner vectors not equal size.");
49 if (nrowc != idimc)
_error_(
"Matrix B and C inner vectors not equal size.");
53 if (ncolc != idimc)
_error_(
"Matrix B and C inner vectors not equal size.");
59 dtemp_dynamic = xNew<IssmDouble>(idima*idimc);
60 dtemp = dtemp_dynamic;
63 dtemp = &dtemp_static[0];
73 if (idima*idimc*(idimb+idimd) <= idimb*idimd*(idima+idimc)) {
85 xDelete<IssmDouble>(dtemp_dynamic);
91 int i,j,k,ipta,iptb,iptc;
92 int nrowc,ncolc,iinca,jinca,iincb,jincb,ntrma,ntrmb,nterm;
124 if (ntrma != ntrmb)
_error_(
"Matrix A and B inner vectors not equal size");
129 if (!iaddc)
for (i=0;i<nrowc*ncolc;i++) c[i]=0.;
133 for (i=0; i<nrowc; i++){
134 for (j=0; j<ncolc; j++){
138 for (k=0; k<nterm; k++){
139 c[iptc]+=a[ipta]*b[iptb];
161 int i,j,k,ipt,jpt,irow,icol,ipiv,ncol;
162 int *pivrc1,*pivrc2,*pindx;
166 _error_(
"No right-hand side for nvec=" << nvec <<
".");
179 pivrc1 =xNew<int>(nrow);
180 pivrc2 =xNew<int>(nrow);
181 pindx =xNew<int>(nrow);
185 for (i=0; i<nrow; i++) {
191 for (j=0; j<nrow; j++)
193 for (k=0; k<ncol; k++)
195 if (fabs(a[j*ndim+k]) > fabs(pivot)) {
201 if (fabs(pivot) < DBL_EPSILON) {
202 xDelete<int>(pivrc1);
203 xDelete<int>(pivrc2);
205 _error_(
"Pivot " << pivot <<
" less than machine epsilon");
226 for (k=0; k<ncol; k++) {
234 for (k=0; k<nvec; k++) {
248 a[ipiv*ndim+ipiv]=1.;
251 for (k=0; k<ncol; k++)
255 for (k=0; k<nvec; k++)
266 for (j=0; j<nrow; j++) {
267 if (j == ipiv)
continue;
269 dtemp=a[j*ndim+ipiv];
272 if (fabs(dtemp) > DBL_EPSILON) {
275 for (k=0; k<ncol; k++)
276 a[ipt+k]-=dtemp*a[jpt+k];
280 for (k=0; k<nvec; k++)
281 b[ipt+k]-=dtemp*b[jpt+k];
296 for (i=0; i<nrow; i++) {
299 if (pivrc1[j] != pivrc2[j]) {
306 for (k=0; k<nrow; k++) {
308 a[ipt+irow]=a[ipt+icol];
316 xDelete<int>(pivrc1);
317 xDelete<int>(pivrc2);
326 *Adet= A[0]*A[3]-A[2]*A[1];
336 if (fabs(
det) < DBL_EPSILON)
_error_(
"Determinant smaller than machine epsilon");
339 det_reciprocal = 1./
det;
342 Ainv[0]= A[3]*det_reciprocal;
343 Ainv[1]= - A[1]*det_reciprocal;
344 Ainv[2]= - A[2]*det_reciprocal;
345 Ainv[3]= A[0]*det_reciprocal;
378 else if (delta < 1.e-5*normM){
387 lambda1 = (-b-delta)/2.;
388 lambda2 = (-b+delta)/2.;
408 IssmDouble norm1 = (a11-lambda1)*(a11-lambda1) + a21*a21;
409 IssmDouble norm2 = a21*a21 + (a22-lambda1)*(a22-lambda1);
414 vy = (a11-lambda1)/norm1;
418 vx = - (a22-lambda1)/norm2;
435 *Adet= A[0]*A[4]*A[8]-A[0]*A[5]*A[7]-A[3]*A[1]*A[8]+A[3]*A[2]*A[7]+A[6]*A[1]*A[5]-A[6]*A[2]*A[4];
445 return a1*b2*c3-a1*b3*c2-b1*a2*c3+b1*a3*c2+c1*a2*b3-c1*a3*b2;
455 if (fabs(
det) < DBL_EPSILON)
_error_(
"Determinant smaller than machine epsilon");
458 det_reciprocal = 1./
det;
461 Ainv[0]=(A[4]*A[8]-A[5]*A[7])*det_reciprocal;
462 Ainv[1]=(A[2]*A[7]-A[1]*A[8])*det_reciprocal;
463 Ainv[2]=(A[1]*A[5]-A[2]*A[4])*det_reciprocal;
464 Ainv[3]=(A[5]*A[6]-A[3]*A[8])*det_reciprocal;
465 Ainv[4]=(A[0]*A[8]-A[2]*A[6])*det_reciprocal;
466 Ainv[5]=(A[2]*A[3]-A[0]*A[5])*det_reciprocal;
467 Ainv[6]=(A[3]*A[7]-A[4]*A[6])*det_reciprocal;
468 Ainv[7]=(A[1]*A[6]-A[0]*A[7])*det_reciprocal;
469 Ainv[8]=(A[0]*A[4]-A[1]*A[3])*det_reciprocal;
476 for(
int i=0;i<3;i++) X[i]=Ainv[i][0]*B[0] + Ainv[i][1]*B[1] + Ainv[i][2]*B[2];
559 if(fabs(
det) < DBL_EPSILON)
_error_(
"Determinant smaller than machine epsilon");
562 det_reciprocal = 1./
det;
568 for(
int i=0;i<4*4;i++) Ainv[i] = Ainv[i]*det_reciprocal;
574 for(
int i=0;i<4;i++) X[i]=Ainv[i][0]*B[0] + Ainv[i][1]*B[1] + Ainv[i][2]*B[2] + Ainv[i][3]*B[3];
586 dummy=xNew<IssmDouble>(m+1);
591 for(
int i=0;i<m;i++)dummy[i+1]=cell[i];
595 for(
int i=0;i<m;i++)dummy[i]=cell[i];
599 xDelete<IssmDouble>(cell); cell=dummy;
608 for(
int i=0;i<m;i++)sum+=cell[i];
620 for(
int i=0;i<nind;i++){
625 xDelete<IssmDouble>(cell);
638 for(
int j=0;j<i;j++)
newcell[j]=cell[j];
641 for(
int j=i+2;j<m+1;j++)
newcell[j]=cell[j-1];
644 xDelete<IssmDouble>(cell);
655 celllist=xNew<IssmDouble*>(numcells);
657 va_start(arguments,m);
659 for (
int x = 0; x < numcells; x++ ){
660 celllist[x]= va_arg ( arguments,
IssmDouble*);
662 va_end ( arguments );
665 for(
int i=0;i<m;i++){
667 for (
int j=0;j<numcells;j++)
_printf_(setprecision(10) << celllist[j][i] <<
" ");
672 xDelete<IssmDouble*>(celllist);