int main(int argc, char **argv) { COORD cord[3]; float a,b; scanf("%f %f %f %f %f %f %f", &cord[0].x, &cord[0].y, &cord[0].z, &cord[1].x, &cord[1].y, &cord[1].z, &a); printf("\nv1 = ( %f , %f , %f)", cord[0].x, cord[0].y, cord[0].z); printf("\nv2 = ( %f , %f , %f)", cord[1].x, cord[1].y, cord[1].z); printf("\na = %f ", a); cord[2] = v_sum(&cord[0],&cord[1]); printf("\nv1+v2 = ( %f , %f , %f )", cord[2].x, cord[2].y, cord[2].z); cord[2] = v_dif(&cord[0],&cord[1]); printf("\nv1-v2 = ( %f , %f , %f )", cord[2].x, cord[2].y, cord[2].z); b = v_dot(&cord[0],&cord[1]); printf("\nv1.v2 = %f ", b); cord[2] = v_prod(&a,&cord[0]); printf("\na v1 = ( %f , %f , %f )", cord[2].x, cord[2].y, cord[2].z); cord[2] = v_cross(&cord[0],&cord[1]); printf("\nv1 x v2 = ( %f , %f , %f )", cord[2].x, cord[2].y, cord[2].z); b = v_mod_2(&cord[0]); printf("\nv1^2 = %f ", b); b = v_mod(&cord[0]); printf("\n|v1| = %f ", b); printf("\n\n"); return(0); }
/* This routine performs ITMAX=5 Gauss-Seidel iterations to compute an approximation to (P-inverse)*z, where P = I - gamma*Jd, and Jd represents the diffusion contributions to the Jacobian. The answer is stored in z on return, and x is a temporary vector. The dimensions below assume a global constant NS >= ns. Some inner loops of length ns are implemented with the small vector kernels v_sum_prods, v_prod, v_inc_by_prod. */ static void GSIter(realtype gamma, N_Vector z, N_Vector x, WebData wdata) { int jx, jy, mx, my, x_loc, y_loc; int ns, mxns, i, iyoff, ic, iter; realtype beta[NS], beta2[NS], cof1[NS], gam[NS], gam2[NS]; realtype temp, *cox, *coy, *xd, *zd; xd = NV_DATA_S(x); zd = NV_DATA_S(z); ns = wdata->ns; mx = wdata->mx; my = wdata->my; mxns = wdata->mxns; cox = wdata->cox; coy = wdata->coy; /* Write matrix as P = D - L - U. Load local arrays beta, beta2, gam, gam2, and cof1. */ for (i = 0; i < ns; i++) { temp = ONE/(ONE + RCONST(2.0)*gamma*(cox[i] + coy[i])); beta[i] = gamma*cox[i]*temp; beta2[i] = RCONST(2.0)*beta[i]; gam[i] = gamma*coy[i]*temp; gam2[i] = RCONST(2.0)*gam[i]; cof1[i] = temp; } /* Begin iteration loop. Load vector x with (D-inverse)*z for first iteration. */ for (jy = 0; jy < my; jy++) { iyoff = mxns*jy; for (jx = 0; jx < mx; jx++) { ic = iyoff + ns*jx; v_prod(xd+ic, cof1, zd+ic, ns); /* x[ic+i] = cof1[i]z[ic+i] */ } } N_VConst(ZERO, z); /* Looping point for iterations. */ for (iter=1; iter <= ITMAX; iter++) { /* Calculate (D-inverse)*U*x if not the first iteration. */ if (iter > 1) { for (jy=0; jy < my; jy++) { iyoff = mxns*jy; for (jx=0; jx < mx; jx++) { /* order of loops matters */ ic = iyoff + ns*jx; x_loc = (jx == 0) ? 0 : ((jx == mx-1) ? 2 : 1); y_loc = (jy == 0) ? 0 : ((jy == my-1) ? 2 : 1); switch (3*y_loc+x_loc) { case 0 : /* jx == 0, jy == 0 */ /* x[ic+i] = beta2[i]x[ic+ns+i] + gam2[i]x[ic+mxns+i] */ v_sum_prods(xd+ic, beta2, xd+ic+ns, gam2, xd+ic+mxns, ns); break; case 1 : /* 1 <= jx <= mx-2, jy == 0 */ /* x[ic+i] = beta[i]x[ic+ns+i] + gam2[i]x[ic+mxns+i] */ v_sum_prods(xd+ic, beta, xd+ic+ns, gam2, xd+ic+mxns, ns); break; case 2 : /* jx == mx-1, jy == 0 */ /* x[ic+i] = gam2[i]x[ic+mxns+i] */ v_prod(xd+ic, gam2, xd+ic+mxns, ns); break; case 3 : /* jx == 0, 1 <= jy <= my-2 */ /* x[ic+i] = beta2[i]x[ic+ns+i] + gam[i]x[ic+mxns+i] */ v_sum_prods(xd+ic, beta2, xd+ic+ns, gam, xd+ic+mxns, ns); break; case 4 : /* 1 <= jx <= mx-2, 1 <= jy <= my-2 */ /* x[ic+i] = beta[i]x[ic+ns+i] + gam[i]x[ic+mxns+i] */ v_sum_prods(xd+ic, beta, xd+ic+ns, gam, xd+ic+mxns, ns); break; case 5 : /* jx == mx-1, 1 <= jy <= my-2 */ /* x[ic+i] = gam[i]x[ic+mxns+i] */ v_prod(xd+ic, gam, xd+ic+mxns, ns); break; case 6 : /* jx == 0, jy == my-1 */ /* x[ic+i] = beta2[i]x[ic+ns+i] */ v_prod(xd+ic, beta2, xd+ic+ns, ns); break; case 7 : /* 1 <= jx <= mx-2, jy == my-1 */ /* x[ic+i] = beta[i]x[ic+ns+i] */ v_prod(xd+ic, beta, xd+ic+ns, ns); break; case 8 : /* jx == mx-1, jy == my-1 */ /* x[ic+i] = 0.0 */ v_zero(xd+ic, ns); break; } } } } /* end if (iter > 1) */ /* Overwrite x with [(I - (D-inverse)*L)-inverse]*x. */ for (jy=0; jy < my; jy++) { iyoff = mxns*jy; for (jx=0; jx < mx; jx++) { /* order of loops matters */ ic = iyoff + ns*jx; x_loc = (jx == 0) ? 0 : ((jx == mx-1) ? 2 : 1); y_loc = (jy == 0) ? 0 : ((jy == my-1) ? 2 : 1); switch (3*y_loc+x_loc) { case 0 : /* jx == 0, jy == 0 */ break; case 1 : /* 1 <= jx <= mx-2, jy == 0 */ /* x[ic+i] += beta[i]x[ic-ns+i] */ v_inc_by_prod(xd+ic, beta, xd+ic-ns, ns); break; case 2 : /* jx == mx-1, jy == 0 */ /* x[ic+i] += beta2[i]x[ic-ns+i] */ v_inc_by_prod(xd+ic, beta2, xd+ic-ns, ns); break; case 3 : /* jx == 0, 1 <= jy <= my-2 */ /* x[ic+i] += gam[i]x[ic-mxns+i] */ v_inc_by_prod(xd+ic, gam, xd+ic-mxns, ns); break; case 4 : /* 1 <= jx <= mx-2, 1 <= jy <= my-2 */ /* x[ic+i] += beta[i]x[ic-ns+i] + gam[i]x[ic-mxns+i] */ v_inc_by_prod(xd+ic, beta, xd+ic-ns, ns); v_inc_by_prod(xd+ic, gam, xd+ic-mxns, ns); break; case 5 : /* jx == mx-1, 1 <= jy <= my-2 */ /* x[ic+i] += beta2[i]x[ic-ns+i] + gam[i]x[ic-mxns+i] */ v_inc_by_prod(xd+ic, beta2, xd+ic-ns, ns); v_inc_by_prod(xd+ic, gam, xd+ic-mxns, ns); break; case 6 : /* jx == 0, jy == my-1 */ /* x[ic+i] += gam2[i]x[ic-mxns+i] */ v_inc_by_prod(xd+ic, gam2, xd+ic-mxns, ns); break; case 7 : /* 1 <= jx <= mx-2, jy == my-1 */ /* x[ic+i] += beta[i]x[ic-ns+i] + gam2[i]x[ic-mxns+i] */ v_inc_by_prod(xd+ic, beta, xd+ic-ns, ns); v_inc_by_prod(xd+ic, gam2, xd+ic-mxns, ns); break; case 8 : /* jx == mx-1, jy == my-1 */ /* x[ic+i] += beta2[i]x[ic-ns+i] + gam2[i]x[ic-mxns+i] */ v_inc_by_prod(xd+ic, beta2, xd+ic-ns, ns); v_inc_by_prod(xd+ic, gam2, xd+ic-mxns, ns); break; } } } /* Add increment x to z : z <- z+x */ N_VLinearSum(ONE, z, ONE, x, z); } }
int splitElementsToTets(Summen *anz, Nodes *node, Elements *elem, Tetraeder **ptet) { int i,j,k,e,t=0; //int hextet[]= {0,2,5,7, 0,5,2,1, 2,7,0,3, 0,7,5,4, 2,5,7,6 }; // inside out int hextet[]= {7,2,5,0, 1,5,2,0, 3,7,0,2, 4,7,5,0, 6,5,7,2 }; /* 8 *4 */ int tet10tet[]={4,1,5,8, 5,2,6,9, 6,0,4,7, 7,8,9,3, 4,5,6,7, 4,5,7,8, 6,7,5,9, 8,9,5,7 }; int hex20tet[]={8,16,18,4, 8,18,10,3, 4,8,3,18, 4,12,3,8, 12,11,3,8, 12,0,11,8, 4,3,15,18, 4,15,19,18, 19,15,7,18, 10,18,16,6, 10,16,8,1, 6,10,1,16, 6,14,1,10, 14,9,1,10, 14,2,9,10, 6,1,13,16, 6,13,17,16, 17,13,5,16 }; int petet[]= {0,1,2,4, 5,3,0,4, 0,4,2,5 }; /* 15 *4 */ int pe15tet[]= { 6,1,7,10, 13,4,12,10, 13,12,6,10, 6,7,13,10, 9,8,6,0, 7,8,11,2, 14,13,11,5, 9,12,14,3, 9,13,14,12, 9,13,11,14, 7,6,9,8, 9,13,7,11, 13,12,9,7, 12,6,9,7, 9,8,11,2 }; /* 44 incl. midside nodes */ /* int hex20tet[]={22,24,20,23, 20,25,22,23, 20,24,22,21, 22,25,20,21, 24,20,23,11, 24,23,22,11, 20,24,21,9, 24,22,21,9, 23,20,25,19, 23,25,22,19, 21,25,20,17, 21,22,25,17, 23,12,0,20, 23,3,15,22, 1,13,21,20, 21,14,2,22, 4,12,23,20, 7,23,15,22, 13,5,21,20, 14,21,6,22, 0,11,23,20, 11,3,23,22, 1,9,21,20, 2,9,21,22, 19,4,23,20, 19,23,7,22, 17,5,21,20, 6,21,17,22, 0,24,11,20, 11,24,3,22, 24,1,9,20, 24,9,2,22, 25,19,4,20, 25,7,19,22, 17,5,25,20, 17,25,6,22, 8,20,24,0, 24,10,22,3, 20,8,24,1, 22,24,10,2, 16,20,25,4, 18,25,22,7, 16,20,25,5, 18,25,22,6 }; */ /* 8*4*4=64 incl midside and midvolume nodes */ /* int hex20hex[]={0,8,24,11, 12,20,26,23, 11,24,10,3, 23,26,22,15, 8,1,9,24, 20,13,21,26, 24,9,2,10, 26,21,14,22, 12,20,26,23, 4,16,25,19, 23,26,22,15, 19,25,18,7, 20,13,21,26, 16,5,17,25, 26,21,14,22, 25,176,18 }; */ Tetraeder *tet=NULL; double v12[3], v13[3], v14[3], vn[3]; for (e=0; e<anz->e; e++) { switch(elem[e].type) { case 1: if ( (tet = (Tetraeder *)realloc((Tetraeder *)tet, (t+5) * sizeof(Tetraeder))) == NULL ) printf(" ERROR: realloc in elemToTet()\n\n") ; for (j=0; j<5; j++) { for (k=0; k<3; k++) tet[t].cg[k]=0.; for (k=0; k<4; k++) { tet[t].n[k] = elem[e].nod[hextet[4*j+k]]; /* simple cg = sum of coordinates */ tet[t].cg[0]+= node[tet[t].n[k]].nx; tet[t].cg[1]+= node[tet[t].n[k]].ny; tet[t].cg[2]+= node[tet[t].n[k]].nz; } for (k=0; k<3; k++) tet[t].cg[k]/=4.; t++; } break; case 2: if ( (tet = (Tetraeder *)realloc((Tetraeder *)tet, (t+3) * sizeof(Tetraeder))) == NULL ) printf(" ERROR: realloc in elemToTet()\n\n") ; for (j=0; j<3; j++) { for (k=0; k<3; k++) tet[t].cg[k]=0.; for (k=0; k<4; k++) { tet[t].n[k] = elem[e].nod[petet[4*j+k]]; /* simple cg = sum of coordinates */ tet[t].cg[0]+= node[tet[t].n[k]].nx; tet[t].cg[1]+= node[tet[t].n[k]].ny; tet[t].cg[2]+= node[tet[t].n[k]].nz; } for (k=0; k<3; k++) tet[t].cg[k]/=4.; t++; } break; case 3: if ( (tet = (Tetraeder *)realloc((Tetraeder *)tet, (t+1) * sizeof(Tetraeder))) == NULL ) printf(" ERROR: realloc in elemToTet()\n\n") ; for (k=0; k<3; k++) tet[t].cg[k]=0.; for (k=0; k<4; k++) { tet[t].n[k] = elem[e].nod[k]; /* simple cg = sum of coordinates */ tet[t].cg[0]+= node[tet[t].n[k]].nx; tet[t].cg[1]+= node[tet[t].n[k]].ny; tet[t].cg[2]+= node[tet[t].n[k]].nz; } for (k=0; k<3; k++) tet[t].cg[k]/=4.; t++; break; case 4: if ( (tet = (Tetraeder *)realloc((Tetraeder *)tet, (t+18) * sizeof(Tetraeder))) == NULL ) printf(" ERROR: realloc in elemToTet()\n\n") ; for (j=0; j<18; j++) { for (k=0; k<3; k++) tet[t].cg[k]=0.; for (k=0; k<4; k++) { tet[t].n[k] = elem[e].nod[hex20tet[4*j+k]]; tet[t].cg[0]+= node[tet[t].n[k]].nx; tet[t].cg[1]+= node[tet[t].n[k]].ny; tet[t].cg[2]+= node[tet[t].n[k]].nz; } for (k=0; k<3; k++) tet[t].cg[k]/=4.; t++; } break; case 5: if ( (tet = (Tetraeder *)realloc((Tetraeder *)tet, (t+15) * sizeof(Tetraeder))) == NULL ) printf(" ERROR: realloc in elemToTet()\n\n") ; for (j=0; j<15; j++) { for (k=0; k<3; k++) tet[t].cg[k]=0.; for (k=0; k<4; k++) { tet[t].n[k] = elem[e].nod[pe15tet[4*j+k]]; tet[t].cg[0]+= node[tet[t].n[k]].nx; tet[t].cg[1]+= node[tet[t].n[k]].ny; tet[t].cg[2]+= node[tet[t].n[k]].nz; } for (k=0; k<3; k++) tet[t].cg[k]/=4.; t++; } break; case 6: if ( (tet = (Tetraeder *)realloc((Tetraeder *)tet, (t+8) * sizeof(Tetraeder))) == NULL ) printf(" ERROR: realloc in elemToTet()\n\n") ; for (j=0; j<8; j++) { for (k=0; k<3; k++) tet[t].cg[k]=0.; for (k=0; k<4; k++) { tet[t].n[k] = elem[e].nod[tet10tet[4*j+k]]; /* simple cg = sum of coordinates */ tet[t].cg[0]+= node[tet[t].n[k]].nx; tet[t].cg[1]+= node[tet[t].n[k]].ny; tet[t].cg[2]+= node[tet[t].n[k]].nz; } for (k=0; k<3; k++) tet[t].cg[k]/=4.; t++; } break; printf(" ERROR: Elem type:%d not supported\n", elem[e].type); } } /* volu = 1/6 * a x b * c */ for (i=0; i<t; i++) { v_result( &node[tet[i].n[0]].nx, &node[tet[i].n[1]].nx, v12); v_result( &node[tet[i].n[0]].nx, &node[tet[i].n[2]].nx, v13); v_result( &node[tet[i].n[0]].nx, &node[tet[i].n[3]].nx, v14); v_prod(v12,v13,vn); tet[i].v=v_sprod(vn,v14)/6.; if(tet[i].v<0.) { tet[i].v=-tet[i].v; k=tet[i].n[1]; tet[i].n[1]=tet[i].n[2]; tet[i].n[2]=k; } //printf("%d vol:%e vprod:%e %e %e sprod:%e\n", i, tet[i].v, vn[0],vn[1],vn[2], v_sprod(vn,v14) ); } *ptet=tet; return(t); }
int getGeoDataTria( double *p1, double *p2, double *p3, double *Ix, double *Iy, double *Ixy, double *A, double *pcg) /* p3 */ /* Tri_2 /|\ Tri_1 */ /* p1_p2 */ /* (p4) */ { int i; static double vx[]={1.,0.,0.}; double p4[3], v12[3], v13[3], v23[3], v14[3], v43[3], vnorm[3], vbuf[3], vbuf2[3]; double p_puf[3][3], vb; /* pktnr,xyz */ double l12, l13, l23, b1, b2, b_ges, h, A1, A2; double Ix1_p4, Iy1_p4, Ixy1_p4; double Ix2_p4, Iy2_p4, Ixy2_p4; double Ix_p4, Iy_p4, Ixy_p4; double spx_p4, spy_p4, sp1x_p4, sp2x_p4; double Ix_sp, Iy_sp, Ixy_sp; double alfa_z, a, b, c; /* v12 muss den groeste Laenge haben, sonst umsortieren und checken ob es ein dreieck ist v12xv13 != 0. */ v_result(p1, p2, v12); l12=v_betrag(v12); v_result(p1, p3, v13); v_prod(v12,v13,vbuf); if((int)(1.e20*v_betrag(vbuf))==0) return(0); l13=v_betrag(v13); v_result(p2, p3, v23); l23=v_betrag(v23); vb=l12; if (l13 > vb) { vb=l13; for (i=0; i<3; i++) p_puf[0][i]= p3[i]; for (i=0; i<3; i++) p_puf[1][i]= p1[i]; for (i=0; i<3; i++) p_puf[2][i]= p2[i]; for (i=0; i<3; i++) p1[i]=p_puf[0][i]; for (i=0; i<3; i++) p2[i]=p_puf[1][i]; for (i=0; i<3; i++) p3[i]=p_puf[2][i]; } if (l23 > vb) { vb=l23; for (i=0; i<3; i++) p_puf[0][i]= p2[i]; for (i=0; i<3; i++) p_puf[1][i]= p3[i]; for (i=0; i<3; i++) p_puf[2][i]= p1[i]; for (i=0; i<3; i++) p1[i]=p_puf[0][i]; for (i=0; i<3; i++) p2[i]=p_puf[1][i]; for (i=0; i<3; i++) p3[i]=p_puf[2][i]; } /* berechnung der Geometiegroessen (2D-Elementsys.) aus 3D Punktkoordinaten*/ v_result(p1, p3, v13); v_result(p1, p2, v12); b_ges=v_betrag(v12); b2=v_sprod( v13, v12); b2=b2/b_ges; b1=b_ges-b2; v_norm( v12, vnorm); v_scal( &b2, vnorm, v14); v_add( p1, v14, p4); v_result(p4, p3, v43); h=v_betrag(v43); A1= b1*h/2.; *A= b_ges*h/2.; A2= *A-A1; /* Schwerpunkte (sp) bezogen auf p4 IM LOKALEN SYSTEM */ sp1x_p4= b1/3.; sp2x_p4= -b2/3.; spx_p4 = (A1*sp1x_p4 + A2*sp2x_p4) / *A; spy_p4 = h/3.; /* Traegheitsmomente bezogen auf p4 IM LOKALEN SYSTEM */ Ix1_p4= b1*h*h*h/12.; Iy1_p4= h*b1*b1*b1/12.; Ixy1_p4= b1*b1*h*h/24.; Ix2_p4= b2*h*h*h/12.; Iy2_p4= h*b2*b2*b2/12.; Ixy2_p4= b2*b2*h*h/24.; Ix_p4= Ix1_p4 + Ix2_p4; Iy_p4= Iy1_p4 + Iy2_p4; Ixy_p4= Ixy1_p4 - Ixy2_p4; /* printf ("\nA:%lf b1:%lf b2:%lf h:%lf \n", *A, b1, b2, h); printf ("Tri1_P4 Ix:%lf Iy:%lf Ixy:%lf \n", Ix1_p4, Iy1_p4, Ixy1_p4); printf ("Tri2_P4 Ix:%lf Iy:%lf Ixy:%lf \n", Ix2_p4, Iy2_p4, Ixy2_p4); printf ("Tri _P4 Ix:%lf Iy:%lf Ixy:%lf \n", Ix_p4, Iy_p4, Ixy_p4); */ /* Traegheitsmomente bezogen auf Schwp. (nach Steiner) */ Ix_sp = Ix_p4 - spy_p4*spy_p4 * *A; Iy_sp = Iy_p4 - spx_p4*spx_p4 * *A; Ixy_sp = Ixy_p4 - spx_p4*spy_p4 * *A; /* printf ("\nA:%lf b1:%lf b2:%lf h:%lf \n", *A, b1, b2, h); printf ("sp_p4 spx:%lf spy:%lf \n", spx_p4, spy_p4); printf ("Tri _sp Ix:%lf Iy:%lf Ixy:%lf \n", Ix_sp, Iy_sp, Ixy_sp); */ /* umrechnen aufs Gloabale System (2D Elementsystem -> 3D Globalsystem) */ v_norm( v12, vnorm); v_scal( &spx_p4, vnorm, vbuf); v_add( p4, vbuf, vbuf2); v_norm( v43, vnorm); v_scal( &spy_p4, vnorm, vbuf); v_add( vbuf2, vbuf, pcg); /* ACHTUNG: z. Z. wird nur in der xy-ebene gedreht! */ v12[2] = 0.; alfa_z= acos( v_sprod(v12,vx) / v_betrag(v12) / v_betrag(vx) ) * (-1.); a = (Ix_sp+Iy_sp)/2.; b = (Ix_sp-Iy_sp)/2. * cos(2.*alfa_z); c = Ixy_sp * sin(2.*alfa_z); *Ix= a+b-c; *Iy= a-b+c; *Ixy= a * sin(2.*alfa_z) + Ixy_sp * cos(2.*alfa_z); /* Traegheitsmomente bezogen auf Globalsystem (nach Steiner) */ *Ix= *Ix + pcg[1]*pcg[1] * *A; *Iy= *Iy + pcg[0]*pcg[0] * *A; *Ixy= *Ixy + pcg[0]*pcg[1] * *A; return(1); }
int calcPrinc( double *s, double *p, double *a0, double *a1, double *a2, int flag ) /* *************************************************************************** */ /* berechnet aus dem Spannungstensor die Hauptspannungen und deren Raumwinkel */ /* s: spannungstensor, p: Principals, a0: alfa_p1, a1: alfa_p2, a2: alfa_p3 */ /* */ /* */ /* wenn flag=0 x[0] > x[1] > x[2] */ /* wenn flag=1 |x[0]| > |x[1]| > |x[2]| */ /* wenn flag=2 wie 1 aber ohne winkelberechnung */ /* *************************************************************************** */ { register int i; long double a, b, c, mean; long double sd[6]; double maxs=0.; double y[3], p_[3]; double p1[3]; double alfa[9]; for (i=0; i<6; i++) { maxs=dmax(maxs,dabs(s[i])); } if(!maxs) { p[0]=0.; p[1]=0.; p[2]=0.; a0[0]=0.; a0[1]=0.; a0[2]=1.; a1[0]=0.; a1[1]=1.; a1[2]=0.; a2[0]=-1.; a2[1]=0.; a2[2]=0.; return (1); } for (i=0; i<6; i++) { sd[i]=s[i]/maxs; } mean=0; for(i=0; i<3; i++) mean+=sd[i]; mean*=0.33333333; a= -(sd[0]+sd[1]+sd[2]); b= (sd[0] * sd[1]) + (sd[1] * sd[2]) + (sd[2] * sd[0]) - (sd[3] * sd[3]) - (sd[4] * sd[4]) - (sd[5] * sd[5] ); c= -( sd[0]*sd[1]*sd[2] + 2* sd[3]*sd[4]*sd[5] - sd[0]*sd[4]*sd[4] - sd[1]*sd[5]*sd[5] - sd[2]*sd[3]*sd[3] ); #if TEST1 printf ("xx:%.12f yy:%.12f zz:%.12f xy:%.12f yz:%.12f zx:%.12f max:%e\n", (double)s[0], (double)s[1], (double)s[2], (double)s[3], (double)s[4], (double)s[5], maxs); printf ("xx:%.12f yy:%.12f zz:%.12f xy:%.12f yz:%.12f zx:%.12f\n", (double)sd[0], (double)sd[1], (double)sd[2], (double)sd[3], (double)sd[4], (double)sd[5]); printf ("a :%e b :%e c :%e\n" , (double)a,(double)b,(double)c ); #endif /* if all principals 0 */ if ( ( abs(a)<= MIN )&&( abs(b)<= MIN )&&( abs(c)<= MIN ) ) { p[0]=0.; p[1]=0.; p[2]=0.; a0[0]=0.; a0[1]=0.; a0[2]=1.; a1[0]=0.; a1[1]=1.; a1[2]=0.; a2[0]=-1.; a2[1]=0.; a2[2]=0.; return (1); } /* if just one principal is != 0 */ else if ( ( abs(b)<MIN )&&( abs(c)<MIN ) ) { p_[0]=0.; p_[1]=0.; p_[2]=0.; if (flag) { p_[0]=-a; } else { if(-a<0) p_[2]=-a; else p_[0]=-a; } } /* wenn die Zugspannungen gleich sind, dann haben wir einen hydrostatischen Spannungszustand */ else if(( abs((sd[0]-sd[1])/mean)<MIN3) && (abs((sd[0]-sd[2])/mean)<MIN3) ) { /* die Schubspannungen muessen praktisch 0 sein verglichen mit den Zugspannungen */ if( (abs(sd[3]/mean)<MIN3) && (abs(sd[4]/mean)<MIN3) && (abs(sd[5]/mean)<MIN3) ) { a=0; for(i=0; i<6; i++) a+=sd[i]; a*=0.33333333; p[0]=a; p[1]=a; p[2]=a; a0[0]=0.; a0[1]=0.; a0[2]=1.; a1[0]=0.; a1[1]=1.; a1[2]=0.; a2[0]=-1.; a2[1]=0.; a2[2]=0.; return (1); } if ( gl3grades( a, b, c, p_ ) < 0 ) return (-2); } else if ( gl3grades( a, b, c, p_ ) < 0 ) return (-2); for (i=0; i<3; i++) p_[i]*=maxs; if (flag > 0) { y[0]=abs(p_[0]); y[1]=abs(p_[1]); y[2]=abs(p_[2]); } else { y[0]=p_[0]; y[1]=p_[1]; y[2]=p_[2]; } if ( (y[0]>=y[1]) && (y[0]>=y[2]) ) /* 1st greatest */ { p[0]=p_[0]; if (y[1]>y[2]) { p[1]=p_[1]; p[2]=p_[2]; } else { p[1]=p_[2]; p[2]=p_[1]; } } else if ( (y[1]>=y[0]) && (y[1]>=y[2]) ) /* 2nt greatest */ { p[0]=p_[1]; if (y[0]>y[2]) { p[1]=p_[0]; p[2]=p_[2]; } else { p[1]=p_[2]; p[2]=p_[0]; } } else if ( (y[2]>=y[0]) && (y[2]>=y[1]) ) /* 3rd greatest */ { p[0]=p_[2]; if (y[0]>y[1]) { p[1]=p_[0]; p[2]=p_[1]; } else { p[1]=p_[1]; p[2]=p_[0]; } } else { printf("ERROR in calcPrinc P:%lf %lf %lf\n",y[0],y[1],y[2] ); p[0]=0.; p[1]=0.; p[2]=0.; /* a0[0]=0.; a0[1]=0.; a0[2]=1.; a1[0]=0.; a1[1]=1.; a1[2]=0.; a2[0]=-1.; a2[1]=0.; a2[2]=0.; return (-2); */ } /* no angles if flag == 2 (fast method) */ if (flag == 2) return(1); calcPvector( s, p, alfa ); a0[0]=alfa[0]; a0[1]=alfa[1]; a0[2]=alfa[2]; a1[0]=alfa[3]; a1[1]=alfa[4]; a1[2]=alfa[5]; a2[0]=alfa[6]; a2[1]=alfa[7]; a2[2]=alfa[8]; /* kontrolle des letzten vektors mit Vektorprod. */ v_prod( a0, a1, p1); if(( (p1[0]*p1[0]-a2[0]*a2[0]) > MIN2 )|| ( (p1[1]*p1[1]-a2[1]*a2[1]) > MIN2 )|| ( (p1[2]*p1[2]-a2[2]*a2[2]) > MIN2 )) { #if TEST printf(" WARNING: in calcPrinc, some directions of maxPrinc in error \n"); printf(" p1: %lf p2: %lf p3: %lf \n", p[0], p[1], p[2] ); printf(" v1x: %lf v2x: %lf v3x: %lf v1xv2_x: %lf \n", a0[0], a1[0], a2[0], p1[0] ); printf(" v1y: %lf v2y: %lf v3y: %lf v1xv2_y: %lf \n", a0[1], a1[1], a2[1], p1[1] ); printf(" v1z: %lf v2z: %lf v3z: %lf v1xv2_z: %lf \n", a0[2], a1[2], a2[2], p1[2] ); printf(" v1r: %lf v2r: %lf v3r: %lf v1xv2_r: %lf \n", sqrt(a0[0]*a0[0]+a0[1]*a0[1]+a0[2]*a0[2]) , sqrt(a1[0]*a1[0]+a1[1]*a1[1]+a1[2]*a1[2]), sqrt(a2[0]*a2[0]+a2[1]*a2[1]+a2[2]*a2[2]) , sqrt(p1[0]*p1[0]+p1[1]*p1[1]+p1[2]*p1[2]) ); #endif return (-1); } return(1); }
int calcPvector( long double *s, long double *p, double *a ) { long double D[3]; long double max, maxD=-1.; double al, v1[3],v2[3],v3[3]; int i,j, max_indx, iflag=0, maxDi=-1; for(i=0; i<3; i++) { /* berechnung der drei determinanten fuer die faelle x=1, y=1, z=1 */ D[0]=((s[1]-p[i])*(s[2]-p[i]))-(s[4]*s[4]); D[1]=((s[0]-p[i])*(s[2]-p[i]))-(s[5]*s[5]); D[2]=((s[0]-p[i])*(s[1]-p[i]))-(s[3]*s[3]); /* bestimme die maximale determinante und den index */ max=0.; max_indx=-1; for (j=0; j<3; j++) if(D[j]*D[j]>max) { max=D[j]*D[j]; max_indx=j; } /* bestimme den index der maximalen determinante aller Richtungen */ if(max>maxD) { maxD=max; maxDi=i; } /* printf(" maxD:%e maxDi:%d D: %e %e %e max:%e indx:%d \n" ,(double)maxD, maxDi, (double)D[0], (double)D[1],(double)D[2], (double)max,max_indx); */ if(max<MIN) { iflag=1; } else if(max_indx==0) { a[0+(i*3)]=1.; a[1+(i*3)]=( (-s[3]*(s[2]-p[i])) - (-s[5]*s[4]) ) / D[max_indx]; a[2+(i*3)]=( ((s[1]-p[i])*-s[5]) - (s[4]*(-s[3])) ) / D[max_indx]; } else if(max_indx==1) { a[0+(i*3)]=( (-s[3]*(s[2]-p[i])) - (-s[4]*s[5]) ) / D[max_indx]; a[1+(i*3)]=1.; a[2+(i*3)]=( ((s[0]-p[i])*-s[4]) - (s[5]*(-s[3])) ) / D[max_indx]; } else if(max_indx==2) { a[0+(i*3)]=( (-s[5]*(s[1]-p[i])) - (-s[4]*s[3]) ) / D[max_indx]; a[1+(i*3)]=( ((s[0]-p[i])*-s[4]) - (s[3]*(-s[5])) ) / D[max_indx]; a[2+(i*3)]=1.; } } /* vectoren normieren */ for (i=0; i<3; i++) { al=sqrt(a[0+(i*3)]*a[0+(i*3)]+a[1+(i*3)]*a[1+(i*3)]+a[2+(i*3)]*a[2+(i*3)]); a[0+(i*3)]/=al; a[1+(i*3)]/=al; a[2+(i*3)]/=al; /* printf (" calcPvector max_indx:%d p[%d]=%e a:%e %e %e %e \n" ,max_indx,i, (double)p[i],(double)a[0+(i*3)],(double)a[1+(i*3)],(double)a[2+(i*3)], (double)al); */ } /* kontrolle ob richtungen nicht bestimmt wurden */ if (iflag) { if(maxDi==0) { v1[0]=a[0]; v1[1]=a[1]; v1[2]=a[2]; v2[0]=a[1]; v2[1]=a[2]; v2[2]=a[0]; v_prod(v1,v2,v3); v_prod(v1,v3,v2); a[3]=v2[0]; a[4]=v2[1]; a[5]=v2[2]; a[6]=v3[0]; a[7]=v3[1]; a[8]=v3[2]; } if(maxDi==1) { v1[0]=a[3]; v1[1]=a[4]; v1[2]=a[5]; v2[0]=a[4]; v2[1]=a[5]; v2[2]=a[3]; v_prod(v1,v2,v3); v_prod(v1,v3,v2); a[0]=v2[0]; a[1]=v2[1]; a[2]=v2[2]; a[6]=v3[0]; a[7]=v3[1]; a[8]=v3[2]; } if(maxDi==2) { v1[0]=a[6]; v1[1]=a[7]; v1[2]=a[8]; v2[0]=a[7]; v2[1]=a[8]; v2[2]=a[6]; v_prod(v1,v2,v3); v_prod(v1,v3,v2); a[0]=v2[0]; a[1]=v2[1]; a[2]=v2[2]; a[3]=v3[0]; a[4]=v3[1]; a[5]=v3[2]; } /* vectoren nochmal normieren */ for (i=0; i<3; i++) { al=sqrt(a[0+(i*3)]*a[0+(i*3)]+a[1+(i*3)]*a[1+(i*3)]+a[2+(i*3)]*a[2+(i*3)]); a[0+(i*3)]/=al; a[1+(i*3)]/=al; a[2+(i*3)]/=al; /* printf (" calcPvector max_indx:%d p[%d]=%lf a:%lf %lf %lf \n" ,max_indx,i,p[i],a[0+(i*3)],a[1+(i*3)],a[2+(i*3)]); */ } } return (1); }
ITG elemChecker(ITG sum_e, Nodes *node, Elements *elem) { ITG i, j; double v12[3], v13[3], v15[3], v15n[3], vn[3]; double bv15, bvn, bv15n, bgrenz; ITG epuf[27]; ITG e_korr=0; for (i=0; i<sum_e; i++) { if( (elem[i].type == 1)||(elem[i].type == 4) ) /* HEXA */ { v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[1]].nx, v12); v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[3]].nx, v13); v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[4]].nx, v15); v_prod(v12,v13,vn); v_result(v15,vn,v15n); bvn=v_betrag(vn); bv15=v_betrag(v15); bgrenz=sqrt(bvn*bvn+bv15*bv15); bv15n=v_betrag(v15n); /* printf ("elemcheck:%" ITGFORMAT " vn x=%e y=%e z=%e\n",elem[i].nr,vn[0],vn[1],vn[2]); */ if (bv15n > bgrenz) { /* printf ("elem %" ITGFORMAT " wrong defined, v15n=%e vgrenz=%e\n", elem[i].nr,bv15n,bgrenz); */ for (j=0; j<8; j++) { epuf[j] = elem[i].nod[j]; } elem[i].nod[0] = epuf[4]; elem[i].nod[1] = epuf[5]; elem[i].nod[2] = epuf[6]; elem[i].nod[3] = epuf[7]; elem[i].nod[4] = epuf[0]; elem[i].nod[5] = epuf[1]; elem[i].nod[6] = epuf[2]; elem[i].nod[7] = epuf[3]; e_korr++; if (elem[i].type == 4) { for (j=0; j<4; j++) { epuf[j] = elem[i].nod[j+8]; epuf[j+4] = elem[i].nod[j+16]; } elem[i].nod[8] = epuf[4]; elem[i].nod[9] = epuf[5]; elem[i].nod[10] = epuf[6]; elem[i].nod[11] = epuf[7]; elem[i].nod[16] = epuf[0]; elem[i].nod[17] = epuf[1]; elem[i].nod[18] = epuf[2]; elem[i].nod[19] = epuf[3]; } } } else if( (elem[i].type == 2)||(elem[i].type == 5) ) /* PENTA */ { v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[1]].nx, v12); v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[2]].nx, v13); v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[3]].nx, v15); v_prod(v12,v13,vn); v_result(v15,vn,v15n); bvn=v_betrag(vn); bv15=v_betrag(v15); bgrenz=sqrt(bvn*bvn+bv15*bv15); bv15n=v_betrag(v15n); /* printf ("elemcheck:%" ITGFORMAT " vn x=%e y=%e z=%e\n",elem[i].nr,vn[0],vn[1],vn[2]); */ if (bv15n > bgrenz) { /* printf ("elem %" ITGFORMAT " wrong defined, v15n=%e vgrenz=%e\n", elem[i].nr,bv15n,bgrenz); */ for (j=0; j<6; j++) { epuf[j] = elem[i].nod[j]; } elem[i].nod[0] = epuf[3]; elem[i].nod[1] = epuf[4]; elem[i].nod[2] = epuf[5]; elem[i].nod[3] = epuf[0]; elem[i].nod[4] = epuf[1]; elem[i].nod[5] = epuf[2]; e_korr++; if (elem[i].type == 5) { for (j=0; j<3; j++) { epuf[j] = elem[i].nod[j+6]; epuf[j+3] = elem[i].nod[j+12]; } elem[i].nod[6] = epuf[3]; elem[i].nod[7] = epuf[4]; elem[i].nod[8] = epuf[5]; elem[i].nod[12] = epuf[0]; elem[i].nod[13] = epuf[1]; elem[i].nod[14] = epuf[2]; } } } else if( (elem[i].type == 3)||(elem[i].type == 6) ) /* TET */ { v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[1]].nx, v12); v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[2]].nx, v13); v_result( &node[elem[i].nod[0]].nx, &node[elem[i].nod[3]].nx, v15); v_prod(v12,v13,vn); v_result(v15,vn,v15n); bvn=v_betrag(vn); bv15=v_betrag(v15); bgrenz=sqrt(bvn*bvn+bv15*bv15); bv15n=v_betrag(v15n); /* printf ("elemcheck:%" ITGFORMAT " vn x=%e y=%e z=%e\n",elem[i].nr,vn[0],vn[1],vn[2]); */ if (bv15n > bgrenz) { /* printf ("elem %" ITGFORMAT " wrong defined, v15n=%e vgrenz=%e\n", elem[i].nr,bv15n,bgrenz); */ for (j=0; j<4; j++) epuf[j] = elem[i].nod[j]; elem[i].nod[0] = epuf[1]; elem[i].nod[1] = epuf[2]; elem[i].nod[2] = epuf[3]; elem[i].nod[3] = epuf[0]; e_korr++; if (elem[i].type == 6) { for (j=4; j<10; j++) epuf[j] = elem[i].nod[j]; elem[i].nod[4] = epuf[5]; elem[i].nod[5] = epuf[9]; elem[i].nod[6] = epuf[8]; elem[i].nod[7] = epuf[4]; elem[i].nod[8] = epuf[6]; elem[i].nod[9] = epuf[7]; } } } } return (e_korr); }