double Quad4FiberOverlay::computeCurrentStrain() { // determine the current strain given trial displacements at nodes u.Zero(); const Vector &disp1 = theNodes[0]->getTrialDisp(); const Vector &disp2 = theNodes[1]->getTrialDisp(); const Vector &disp3 = theNodes[2]->getTrialDisp(); const Vector &disp4 = theNodes[3]->getTrialDisp(); u[0] = disp1(0); u[1] = disp1(1); u[2] = disp2(0); u[3] = disp2(1); u[4] = disp3(0); u[5] = disp3(1); u[6] = disp4(0); u[7] = disp4(1); // Loop over the integration points strain = 0; for(int ip = 0; ip < 2; ip++) { //This llop calculates twice the strain, since it is adding the strain at two GP... this->getEltBb(pts[ip][0],pts[ip][1]); for (int i = 0; i < SL_NUM_DOF; i++) { strain += Bb(i)*u(i); } } strain = strain/2.0; //Since it was calculated twice. this function should be redeveloped return strain; }
void main() { int a[M]={1,2,3,4,5,6,7,8,9,10}; int b[M]={1,1,1,1,1,1,1,1,1,1}; int c1[N][N],c2[N][N]; madd(a,b,c1); mult(a,b,c2); printf("a¾ØÕó:\n");disp1(a); printf("b¾ØÕó:\n");disp1(b); printf("a+b:\n");disp2(c1); printf("a¡Áb:\n");disp2(c2); printf("\n"); }
int FourNodeQuad3d::update() { const Vector &disp1 = theNodes[0]->getTrialDisp(); const Vector &disp2 = theNodes[1]->getTrialDisp(); const Vector &disp3 = theNodes[2]->getTrialDisp(); const Vector &disp4 = theNodes[3]->getTrialDisp(); static double u[2][4]; u[0][0] = disp1(dirn[0]); u[1][0] = disp1(dirn[1]); u[0][1] = disp2(dirn[0]); u[1][1] = disp2(dirn[1]); u[0][2] = disp3(dirn[0]); u[1][2] = disp3(dirn[1]); u[0][3] = disp4(dirn[0]); u[1][3] = disp4(dirn[1]); static Vector eps(3); int ret = 0; // Loop over the integration points for (int i = 0; i < 4; i++) { // Determine Jacobian for this integration point this->shapeFunction(pts[i][0], pts[i][1]); // Interpolate strains //eps = B*u; //eps.addMatrixVector(0.0, B, u, 1.0); eps.Zero(); for (int beta = 0; beta < 4; beta++) { eps(0) += shp[0][beta]*u[0][beta]; eps(1) += shp[1][beta]*u[1][beta]; eps(2) += shp[0][beta]*u[1][beta] + shp[1][beta]*u[0][beta]; } // Set the material strain ret += theMaterial[i]->setTrialStrain(eps); } return ret; }
//! @brief Update the values of the state variables. int XC::FourNodeQuad::update(void) { const Vector &disp1 = theNodes[0]->getTrialDisp(); const Vector &disp2 = theNodes[1]->getTrialDisp(); const Vector &disp3 = theNodes[2]->getTrialDisp(); const Vector &disp4 = theNodes[3]->getTrialDisp(); static double u[2][4]; u[0][0] = disp1(0); u[1][0] = disp1(1); u[0][1] = disp2(0); u[1][1] = disp2(1); u[0][2] = disp3(0); u[1][2] = disp3(1); u[0][3] = disp4(0); u[1][3] = disp4(1); static XC::Vector eps(3); int ret = 0; // Loop over the integration points for(size_t i= 0;i<physicalProperties.size();i++) { //Determine Jacobian for this integration point const GaussPoint &gp= getGaussModel().getGaussPoints()[i]; this->shapeFunction(gp); // Interpolate strains //eps = B*u; //eps.addMatrixVector(0.0, B, u, 1.0); eps.Zero(); for(int beta= 0;beta<4;beta++) { eps(0)+= shp[0][beta]*u[0][beta]; eps(1)+= shp[1][beta]*u[1][beta]; eps(2)+= shp[0][beta]*u[1][beta] + shp[1][beta]*u[0][beta]; } // Set the material strain ret += physicalProperties[i]->setTrialStrain(eps); } return ret; }
double TrussSection::computeCurrentStrain(void) const { // NOTE method will not be called if L == 0 // determine the strain const Vector &disp1 = theNodes[0]->getTrialDisp(); const Vector &disp2 = theNodes[1]->getTrialDisp(); double dLength = 0.0; if (initialDisp == 0) for (int i = 0; i < dimension; i++) dLength += (disp2(i)-disp1(i))*cosX[i]; else for (int i = 0; i < dimension; i++) dLength += (disp2(i)-disp1(i)-initialDisp[i])*cosX[i]; // this method should never be called with L == 0 return dLength/L; }
const Vector & PDeltaCrdTransf2d::getBasicTrialDisp(void) { // determine global displacements const Vector &disp1 = nodeIPtr->getTrialDisp(); const Vector &disp2 = nodeJPtr->getTrialDisp(); static double ug[6]; for (int i = 0; i < 3; i++) { ug[i] = disp1(i); ug[i+3] = disp2(i); } if (nodeIInitialDisp != 0) { for (int j=0; j<3; j++) ug[j] -= nodeIInitialDisp[j]; } if (nodeJInitialDisp != 0) { for (int j=0; j<3; j++) ug[j+3] -= nodeJInitialDisp[j]; } static Vector ub(3); double oneOverL = 1.0/L; double sl = sinTheta*oneOverL; double cl = cosTheta*oneOverL; ub(0) = -cosTheta*ug[0] - sinTheta*ug[1] + cosTheta*ug[3] + sinTheta*ug[4]; ub(1) = -sl*ug[0] + cl*ug[1] + ug[2] + sl*ug[3] - cl*ug[4]; if (nodeIOffset != 0) { double t02 = -cosTheta*nodeIOffset[1] + sinTheta*nodeIOffset[0]; double t12 = sinTheta*nodeIOffset[1] + cosTheta*nodeIOffset[0]; ub(0) -= t02*ug[2]; ub(1) += oneOverL*t12*ug[2]; } if (nodeJOffset != 0) { double t35 = -cosTheta*nodeJOffset[1] + sinTheta*nodeJOffset[0]; double t45 = sinTheta*nodeJOffset[1] + cosTheta*nodeJOffset[0]; ub(0) += t35*ug[5]; ub(1) -= oneOverL*t45*ug[5]; } ub(2) = ub(1) + ug[5] - ug[2]; return ub; }
int TPB1D::update(void) { // get trial displacements and take difference const Vector& disp1 = theNodes[0]->getTrialDisp(); const Vector& disp2 = theNodes[1]->getTrialDisp(); double d = disp2(direction)-disp1(direction); if (d0 != 0) d -= (*d0)(direction); return theMaterial->setTrialStrain(d); }
// 11.1 ver1.1.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" /* int _tmain(int argc, _TCHAR* argv[]) { return 0; } */ /****************************************************/ /* pas.c */ /* 高级语言到四元式 */ /****************************************************/ #include "stdio.h" #include "string.h" #include "time.h" #include "conio.h" #include "stdlib.h" void my_delay(unsigned long ms) { double start_time = (double)clock() / CLOCKS_PER_SEC * 1000; while ( (double)clock() / CLOCKS_PER_SEC * 1000 - start_time < ms ) ; } #define ACC -2 /****************************************/ #define sy_if 0 #define sy_then 1 #define sy_else 2 #define sy_while 3 #define sy_begin 4 #define sy_do 5 #define sy_end 6 #define a 7 #define semicolon 8 #define e 9 #define jinghao 10 #define S 11 #define L 12 #define tempsy 15 #define EA 18 /*E and*/ #define EO 19 /*E or*/ #define plus 34 #define minus 35 //添加 减号的关键字 #define times 36 #define division 37 //添加 除号的关键字 #define becomes 38 #define op_and 39 #define op_or 40 #define op_not 41 #define rop 42 #define lparent 48 #define rparent 49 #define ident 56 #define intconst 57 /******************************************/ char ch = '\0'; /*当前字符*/ int count = 0; static char spelling[10] = {""}; /*存放识别的字*/ static char line[81] = {""}; /*一行字符缓冲区*/ char *pline;/*字符缓冲区指针*/ char ch_exit; static char ntab1[100][10]; struct ntab { int tc; int fc; } ntab2[200]; int label = 0; /*存放临时变量的表的定义 */ struct rwords { char sp[10]; int sy; }; /*存放文件的结构*/ struct rwords reswords[10] = {{"if", sy_if}, {"do", sy_do}, {"else", sy_else}, {"while", sy_while}, {"then", sy_then}, {"begin", sy_begin}, {"end", sy_end}, {"and", op_and}, {"or", op_or}, {"not", op_not} }; struct aa { int sy1; int pos; } buf[1000], /*词法分析结果缓冲区*/ n,/*当前字符*/ n1,/*当前表达式中的字符*/ E,/*非终结符*/ sstack[100],/*符号栈*/ ibuf[100], stack[1000]; struct aa oth; struct fourexp { char op[10]; struct aa arg1; struct aa arg2; int result; } fexp[200]; /*四元式的结构*/ int ssp = 0; /*指向sstack[100]*/ struct aa *pbuf = buf; /*指向词法分析缓冲区*/ int nlength = 0; int lnum = 0; /*源程序长度*/ int tt1 = 0; FILE *cfile; FILE *mfile; /*********************************************************/ int newt = 0; /*临时变量*/ int nxq = 100; /*nxq指向下一个形成的四元式的地址*/ int lr; int lr1; int sp = 0; /* 状态栈定义*/ int stack1[100]; int sp1 = 0; /*状态栈1的定义*/ int num = 0; struct ll { int nxq1; int tc1; int fc1; } labelmark[10]; int labeltemp[10]; int pointmark = -1, pointtemp = -1; int sign = 0; /*sign=1,表达式为赋值语句;sign=2,表达式为布尔表达式。*/ /***********************************************/ static int action[19][13] = /*0*/ {{2, -1, -1, 3, 4, -1, -1, 5, -1, -1, 10, 1, -1}, /*1*/ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, ACC, -1, -1}, /*2*/ { -1, -1, -1, -1, -1, -1, -1, -1, -1, 6, -1, -1, -1}, /*3*/ { -1, -1, -1, -1, -1, -1, -1, -1, -1, 7, -1, -1, -1}, /*4*/ {2, -1, -1, 3, 4, -1, -1, 5, -1, -1, -1, 9, 8}, /*5*/ { -1, -1, 104, -1, -1, -1, 104, -1, 104, -1, 104, -1, -1}, /*6*/ { -1, 10, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, /*7*/ { -1, -1, -1, -1, -1, 11, -1, -1, -1, -1, -1, -1, -1}, /*8*/ { -1, -1, -1, -1, -1, -1, 12, -1, -1, -1, -1, -1, -1}, /*9*/ { -1, -1, -1, -1, -1, -1, 105, -1, 13, -1, -1, -1, -1}, /*10*/ {2, -1, -1, 3, 4, -1, -1, 5, -1, -1, -1, 14, -1}, /*11*/ {2, -1, -1, 3, 4, -1, -1, 5, -1, -1, -1, 15, -1}, /*12*/ { -1, -1, 103, -1, -1, -1, 103, -1, 103, -1, 103, -1, -1}, /*13*/ {2, -1, -1, 3, 4, -1, -1, 5, -1, -1, -1, 9, 16}, /*14*/ { -1, -1, 17, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, /*15*/ { -1, -1, 102, -1, -1, -1, 102, -1, 102, -1, 102, -1, -1}, /*16*/ { -1, -1, -1, -1, -1, -1, 106, -1, -1, -1, -1, -1, -1}, /*17*/ {2, -1, -1, 3, 4, -1, -1, 5, -1, -1, -1, 18, -1}, /*18*/ { -1, -1, 101, -1, -1, -1, 101, -1, 101, -1, 101, -1, -1} }; //下面的是添加了减法和除法的算术表达式SLR矩阵 static int action1[14][9] = /*0*/ {{3, -1, -1, -1, -1, 2, -1, -1, 1}, /*1*/ { -1, 4, 5, 6, 7, -1, -1, ACC, -1}, /*2*/ {3, -1, -1, -1, -1, 2, -1, -1, 8}, /*3*/ { -1, 106, 106, 106, 106, -1, 106, 106, -1}, /*4*/ {3, -1, -1, -1, -1, 2, -1, -1, 9}, /*5*/ {3, -1, -1, -1, -1, 2, -1, -1, 10}, /*6*/ {3, -1, -1, -1, -1, 2, -1, -1, 11}, /*7*/ {3, -1, -1, -1, -1, 2, -1, -1, 12}, /*8*/ { -1, 4, 5, 6, 7, -1, 13, -1, -1}, /*9*/ { -1, 101, 5, 101, 7, -1, 101, 101, -1}, /*10*/ { -1, 102, 102, 102, 102, -1, 102, 102, -1}, /*11*/ { -1, 103, 5, 103, 7, -1, 103, 103, -1}, /*12*/ { -1, 104, 104, 104, 104, -1, 104, 104, -1}, /*13*/ { -1, 105, 105, 105, 105, -1, 105, 105, -1} }; static int action2[16][11] = /*0*/ {{1, -1, 4, -1, 5, -1, -1, -1, 13, 7, 8}, /*1*/ { -1, 2, -1, 101, -1, 101, 101, 101, -1, -1, -1}, /*2*/ {3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}, /*3*/ { -1, -1, -1, 102, -1, 102, 102, 102, -1, -1, -1}, /*4*/ {1, -1, 4, -1, 5, -1, -1, -1, 11, 7, 8}, /*5*/ {1, -1, 4, -1, 5, -1, -1, -1, 6, 7, 8}, /*6*/ { -1, -1, -1, 104, -1, 9, 10, 104, -1, -1, -1}, /*7*/ {1, -1, 4, -1, 5, -1, -1, -1, 14, 7, 8}, /*8*/ {1, -1, 4, -1, 5, -1, -1, -1, 15, 7, 8}, /*9*/ {105, -1, 105, -1, 105, -1, -1, 105, -1, -1, -1}, /*10*/ {107, -1, 107, -1, 107, -1, -1, 107, -1, -1, -1}, /*11*/ { -1, -1, -1, 12, -1, 9, 10, -1, -1, -1, -1}, /*12*/ { -1, 103, -1, 103, -1, 103, 103, 103, -1, -1, -1}, /*13*/ { -1, -1, -1, -1, -1, 9, 10, ACC, -1, -1, -1}, /*14*/ { -1, -1, -1, 106, -1, 9, 10, 106, -1, -1, -1}, /*15*/ { -1, -1, -1, 108, -1, 9, 10, 108, -1, -1, -1} }; /****************从文件读一行到缓冲区***********************************/ void readline() { char ch1; pline = line; ch1 = getc(cfile); while (ch1 != '\n') { //////////////////////////////////////////////////////////////////////////// my_delay(50); printf("%c", ch1); /////////////////////////////////////////////////////////////////////////////// *pline = ch1; pline++; ch1 = getc(cfile); //取下一个字符 } *pline = '\0'; pline = line; printf("\n"); } /*********************************从缓冲区读一个字符************************/ void readch() { if (ch == '\0') { readline(); lnum++; } ch = *pline; pline++; } /****************标志符和关键字的识别************************************/ find(char spel[]) { int ss1 = 0; int ii = 0; while ((ss1 == 0) && (ii < nlength)) { if (!strcmp(spel, ntab1[ii])) ss1 = 1; ii++; } if (ss1 == 1) return ii - 1; else return -1; } void identifier() { int iii = 0, j, k; int ss = 0; k = 0; do { spelling[k] = ch; k++; readch(); } while (((ch >= 'a') && (ch <= 'z')) || ((ch >= '0') && (ch <= '9'))); pline--; spelling[k] = '\0'; while ((ss == 0) && (iii < 10)) { if (!strcmp(spelling, reswords[iii].sp)) ss = 1; iii++; } /*关键字匹配*/ if (ss == 1) { buf[count].sy1 = reswords[iii - 1].sy; } else { buf[count].sy1 = ident; j = find(spelling); if (j == -1) { buf[count].pos = tt1; strcpy(ntab1[tt1], spelling); tt1++; nlength++; } else buf[count].pos = j; } count++; for (k = 0; k < 10; k++) spelling[k] = '\0'; } /*****************数字的识别***********************************/ void number() { int ivalue = 0; int digit; do { digit = ch - '0'; ivalue = ivalue * 10 + digit; readch(); } while ((ch >= '0') && (ch <= '9')); buf[count].sy1 = intconst; buf[count].pos = ivalue; count++; pline--; } /**************扫描主函数*************************************/ void scan() { int i; while (ch != '~') { switch (ch) { case ' ': break; case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': identifier(); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': number(); break; case '<': readch(); if (ch == '=') { buf[count].pos = 0; } else { if (ch == '>') buf[count].pos = 4; else { buf[count].pos = 1; pline--; } } buf[count].sy1 = rop; count++; break; case '>': readch(); if (ch == '=') { buf[count].pos = 2; } else { buf[count].pos = 3; pline--; } buf[count].sy1 = rop; count++; break; case '(': buf[count].sy1 = lparent; count++; break; case ')': buf[count].sy1 = rparent; count++; break; case '#': buf[count].sy1 = jinghao; count++; break; case '+': buf[count].sy1 = plus; count++; break; case '-': //ex buf[count].sy1 = minus; count++; break; case '/': //ex buf[count].sy1 = division; count++; break; case '*': buf[count].sy1 = times; count++; break; case ':': readch(); if (ch == '=') buf[count].sy1 = becomes; count++; break; case '=': buf[count].sy1 = rop; buf[count].pos = 5; count++; break; case ';': buf[count].sy1 = semicolon; count++; break; } readch(); } buf[count].sy1 = -1; } /******************************************************************/ void readnu() { if (pbuf->sy1 >= 0) { n.sy1 = pbuf->sy1; n.pos = pbuf->pos; pbuf++; } } /******************中间变量的生成**************************/ newtemp() { newt++; return newt; } /**************************生成四元式****************/ gen(char op1[], struct aa arg11, struct aa arg22, int result1) { strcpy(fexp[nxq].op, op1); fexp[nxq].arg1.sy1 = arg11.sy1; fexp[nxq].arg1.pos = arg11.pos; fexp[nxq].arg2.sy1 = arg22.sy1; fexp[nxq].arg2.pos = arg22.pos; fexp[nxq].result = result1; nxq++; return nxq - 1; } /**********布尔表达式的匹配****************/ merg(int p1, int p2) { int p; if (p2 == 0) return p1; else { p = p2; while (fexp[p].result != 0) p = fexp[p].result; fexp[p].result = p1; return p2; } } void backpatch(int p, int t) { int tempq; int q; q = p; while (q != 0) { tempq = fexp[q].result; fexp[q].result = t; q = tempq; } } /*******************************************/ change1(int chan) { switch (chan) { case ident: case intconst: return 0; case plus: return 1; case times: return 2; case minus: //返回减号在 算术表达式SLR表中的 列号 return 3; case division: ///返回除号在 算术表达式SLR表中的 列号 return 4; case lparent: return 5; case rparent: return 6; case jinghao: return 7; case tempsy: return 8; } } change2(int chan) { switch (chan) { case ident: case intconst: return 0; case rop: return 1; case lparent: return 2; case rparent: return 3; case op_not: return 4; case op_and: return 5; case op_or: return 6; case jinghao: return 7; case tempsy: return 8; case EA: return 9; case EO: return 10; } } /************赋值语句的的分析***************************/ void lrparse1(int num) { lr1 = action1[stack1[sp1]][change1(n1.sy1)]; if (lr1 == -1) { printf("\n算术表达式或赋值语句出错!\n"); getch(); exit(0); } if (ibuf[0].sy1 != ident) //对赋值表达式的检查 { printf("\n赋值语句出错!赋值号的左边不是变量名\n"); getch(); exit(0); } if ((lr1 < 14) && (lr1 >= 0)) //14 ――标记算术表达式SLR表中的状态数 { sp1++; stack1[sp1] = lr1; if (n1.sy1 != tempsy) { ssp++; num++; sstack[ssp].sy1 = n1.sy1; sstack[ssp].pos = n1.pos; } n1.sy1 = ibuf[num].sy1; n1.pos = ibuf[num].pos; lrparse1(num); } if ((lr1 >= 100) && (lr1 < 107)) { switch (lr1) { case 100: break; case 101: printf("\nE->E+E 归约\n"); E.pos = newtemp(); gen("+", sstack[ssp - 2], sstack[ssp], E.pos + 100); ssp = ssp - 2; sstack[ssp].sy1 = tempsy; sstack[ssp].pos = E.pos; sp1 = sp1 - 3; break; /*E->E+E*/ case 102: printf("\nE->E*E 归约\n"); E.pos = newtemp(); gen("*", sstack[ssp - 2], sstack[ssp], E.pos + 100); ssp = ssp - 2; sstack[ssp].sy1 = tempsy; sstack[ssp].pos = E.pos; sp1 = sp1 - 3; break; /*E->E*E*/ case 103: //添加的 对减法归约的语义代码 printf("\nE->E-E 归约\n"); E.pos = newtemp(); gen("-", sstack[ssp - 2], sstack[ssp], E.pos + 100); ssp = ssp - 2; sstack[ssp].sy1 = tempsy; sstack[ssp].pos = E.pos; sp1 = sp1 - 3; break; /*E->E-E*/ case 104: //添加的 对除法归约的语义代码 printf("\nE->E/E 归约\n"); E.pos = newtemp(); gen("/", sstack[ssp - 2], sstack[ssp], E.pos + 100); ssp = ssp - 2; sstack[ssp].sy1 = tempsy; sstack[ssp].pos = E.pos; sp1 = sp1 - 3; break; /*E->E/E*/ case 105: printf("\nE->(E) 归约\n"); E.pos = sstack[ssp - 1].pos; ssp = ssp - 2; sstack[ssp].sy1 = tempsy; sstack[ssp].pos = E.pos; sp1 = sp1 - 3; break; /*E->(E)*/ case 106: printf("\nE->i 归约\n"); E.pos = sstack[ssp].pos; sp1--; break; /*E->i*/ } n1.sy1 = tempsy; /*规约后为非终结符*/ n1.pos = E.pos; lrparse1(num); } if ((lr1 == ACC) && (stack1[sp1] == 1)) { /*归约A->i:=E*/ printf("\nA->i:=E 归约\n"); gen(":=", sstack[ssp], oth, ibuf[0].pos); ssp = ssp - 3; sp1 = sp1 - 3; } } /*********************布尔表达式的分析**************************/ lrparse2(int num) { int templabel; lr1 = action2[stack1[sp1]][change2(n1.sy1)]; if (lr1 == -1) { if (sign == 2) printf("\nwhile语句出错!\n"); if (sign == 3) printf("\nif语句出错!\n"); getch(); exit(0); } if ((lr1 < 16) && (lr1 >= 0)) { sp1++; stack1[sp1] = lr1; ssp++; sstack[ssp].sy1 = n1.sy1; sstack[ssp].pos = n1.pos; if ((n1.sy1 != tempsy) && (n1.sy1 != EA) && (n1.sy1 != EO)) num++; n1.sy1 = ibuf[num].sy1; n1.pos = ibuf[num].pos; lrparse2(num); } if ((lr1 >= 100) && (lr1 < 109)) { switch (lr1) { case 100: break; case 101: ntab2[label].tc = nxq; ntab2[label].fc = nxq + 1; gen("jnz", sstack[ssp], oth, 0); gen("j", oth, oth, 0); sp1--; ssp--; label++; n1.sy1 = tempsy; break; /*E->i*/ case 102: ntab2[label].tc = nxq; ntab2[label].fc = nxq + 1; switch (sstack[ssp - 1].pos) { case 0: gen("j<=", sstack[ssp - 2], sstack[ssp], 0); break; case 1: gen("j<", sstack[ssp - 2], sstack[ssp], 0); break; case 2: gen("j>=", sstack[ssp - 2], sstack[ssp], 0); break; case 3: gen("j>", sstack[ssp - 2], sstack[ssp], 0); break; case 4: gen("j<>", sstack[ssp - 2], sstack[ssp], 0); break; case 5: gen("j=", sstack[ssp - 2], sstack[ssp], 0); break; } gen("j", oth, oth, 0); ssp = ssp - 3; sp1 = sp1 - 3; label++; n1.sy1 = tempsy; break; /*E->i rop i*/ case 103: label = label - 1; ssp = ssp - 3; sp1 = sp1 - 3; label++; n1.sy1 = tempsy; break; /*E->(E)*/ case 104: label = label - 1; templabel = ntab2[label].tc; ntab2[label].tc = ntab2[label].fc; ntab2[label].fc = templabel; ssp = ssp - 2; sp1 = sp1 - 2; label++; n1.sy1 = tempsy; break; /*E->not E*/ case 105: backpatch(ntab2[label - 1].tc, nxq); label = label - 1; ssp = ssp - 2; sp1 = sp1 - 2; label++; n1.sy1 = EA; break; /*EA->E(1)and*/ case 106: label = label - 2; ntab2[label].tc = ntab2[label + 1].tc; ntab2[label].fc = merg(ntab2[label].fc, ntab2[label + 1].fc); ssp = ssp - 2; sp1 = sp1 - 2; label++; n1.sy1 = tempsy; break; /*E->EA E(2)*/ case 107: backpatch(ntab2[label - 1].fc, nxq); label = label - 1; ssp = ssp - 2; sp1 = sp1 - 2; label++; n1.sy1 = EO; break; case 108: label = label - 2; ntab2[label].fc = ntab2[label + 1].fc; ntab2[label].tc = merg(ntab2[label].tc, ntab2[label + 1].tc); ssp = ssp - 2; sp1 = sp1 - 2; label++; n1.sy1 = tempsy; break; } lrparse2(num); } if (lr1 == ACC) return 1; } /***************测试字符是否为表达式中的值(不包括";")**************/ test(int value) { switch (value) { case intconst: case ident: case plus: case times: case minus: //减号 是否是表达式中的符号 case division: //除号 是否是表达式中的符号 case becomes: case lparent: case rparent: case rop: case op_and: case op_or: case op_not: return 1; default: return 0; } } /*******************************************/ int lrparse() { int i1 = 0; int num = 0; /*指向表达式缓冲区*/ if (test(n.sy1)) { if (stack[sp].sy1 == sy_while) sign = 2; else { if (stack[sp].sy1 == sy_if) sign = 3; else sign = 1; } do { ibuf[i1].sy1 = n.sy1; ibuf[i1].pos = n.pos; readnu(); i1++; } while (test(n.sy1)); /*把表达式放入缓冲区*/ ibuf[i1].sy1 = jinghao; pbuf--; /*指针后退1,需要吗?*/ sstack[0].sy1 = jinghao; ssp = 0; /*符号栈底的初始化*/ if (sign == 1) { sp1 = 0; stack1[sp1] = 0; /*状态栈1的栈底初始化*/ num = 2; /*指向:=*/ n1.sy1 = ibuf[num].sy1; n1.pos = ibuf[num].pos; lrparse1(num); /*处理赋值语句*/ n.sy1 = a; /*当前文法符号置为a(赋值语句)*/ } if ((sign == 2) || (sign == 3)) { pointmark++; labelmark[pointmark].nxq1 = nxq; sp1 = 0; stack1[sp1] = 0; num = 0; n1.sy1 = ibuf[num].sy1; n1.pos = ibuf[num].pos; lrparse2(num); labelmark[pointmark].tc1 = ntab2[label - 1].tc; labelmark[pointmark].fc1 = ntab2[label - 1].fc; /*处理布尔语句*/ /*在处理完E,要回填真值链*/ backpatch(labelmark[pointmark].tc1, nxq); n.sy1 = e; /*当前文法符号置为e(赋值语句)*/ } } lr = action[stack[sp].pos][n.sy1]; printf("stack[%d]=%d\t\tn=%d\t\tlr=%d\n", sp, stack[sp].pos, n.sy1, lr); if ((lr < 19) && (lr >= 0)) { sp++; stack[sp].pos = lr; stack[sp].sy1 = n.sy1; readnu(); lrparse(); } if ((lr <= 106) && (lr >= 100)) { switch (lr) { case 100: break; /*S'->S*/ case 101: printf("S->if e then S else S 归约\n"); sp = sp - 6; n.sy1 = S; /*归约完if后,填then后面的无条件转移语句*/ fexp[labeltemp[pointtemp]].result = nxq; pointtemp--; if (stack[sp].sy1 == sy_then) { gen("j", oth, oth, 0); backpatch(labelmark[pointmark].fc1, nxq); pointtemp++; labeltemp[pointtemp] = nxq - 1; } pointmark--; if (stack[sp].sy1 == sy_do) { gen("j", oth, oth, labelmark[pointmark].nxq1); backpatch(labelmark[pointmark].fc1, nxq); } break; /*S->if e then S then S else S*/ case 102: printf("S->while e do S 归约\n"); sp = sp - 4; n.sy1 = S; pointmark--; if (stack[sp].sy1 == sy_do) { gen("j", oth, oth, labelmark[pointmark].nxq1); backpatch(labelmark[pointmark].fc1, nxq); } if (stack[sp].sy1 == sy_then) { gen("j", oth, oth, 0); fexp[labelmark[pointmark].fc1].result = nxq; pointtemp++; labeltemp[pointtemp] = nxq - 1; } break; /*S->while e do S*/ case 103: printf("S->begin L end 归约\n"); sp = sp - 3; n.sy1 = S; if (stack[sp].sy1 == sy_then) { gen("j", oth, oth, 0); backpatch(labelmark[pointmark].fc1, nxq); pointtemp++; labeltemp[pointtemp] = nxq - 1; } if (stack[sp].sy1 == sy_do) { gen("j", oth, oth, labelmark[pointmark].nxq1); backpatch(labelmark[pointmark].fc1, nxq); } getch(); break; /*S->begin L end*/ case 104: printf("S->a 归约\n"); sp = sp - 1; n.sy1 = S; if (stack[sp].sy1 == sy_then) { gen("j", oth, oth, 0); backpatch(labelmark[pointmark].fc1, nxq); pointtemp++; labeltemp[pointtemp] = nxq - 1; } if (stack[sp].sy1 == sy_do) { gen("j", oth, oth, labelmark[pointmark].nxq1); backpatch(labelmark[pointmark].fc1, nxq); } break; /*S->a*/ case 105: printf("L->S 归约\n"); sp = sp - 1; n.sy1 = L; break; /*L->S*/ case 106: printf("L->S;L 归约\n"); sp = sp - 3; n.sy1 = L; break; /*L->S;L*/ } getch(); pbuf--; lrparse(); } if (lr == ACC) { printf("分析成功!文法正确!\n"); lr = -100; //添加的语句 可能导致错误产生!!!! return ACC; } else if (lr == -1) { printf("分析失败!文法错误!\n"); lr = -200; //添加的语句 可能导致错误产生!!!! } } /*****************************disp1*************************/ void disp1() { int temp1 = 0; printf("\n********************词法分析结果***********************\n"); for (temp1 = 0; temp1 < count; temp1++) { printf("%d\t%d\n", buf[temp1].sy1, buf[temp1].pos); if (temp1 == 20) { printf("Press any key to continue......\n"); getch(); } } getch(); } /******************************************************/ void disp2() { int temp1 = 100; printf("\n********************四元式分析结果***********************\n"); for (temp1 = 100; temp1 < nxq; temp1++) { if (temp1 > 100) fprintf(mfile, "\n"); fprintf(mfile, "%d\t", temp1); fprintf(mfile, "(%s\t,", fexp[temp1].op); if (fexp[temp1].arg1.sy1 == ident) fprintf(mfile, "%s\t,", ntab1[fexp[temp1].arg1.pos]); else { if (fexp[temp1].arg1.sy1 == tempsy) fprintf(mfile, "T%d\t,", fexp[temp1].arg1.pos); else { if (fexp[temp1].arg1.sy1 == intconst) fprintf(mfile, "%d\t,", fexp[temp1].arg1.pos); else fprintf(mfile, "\t,"); } } if (fexp[temp1].arg2.sy1 == ident) fprintf(mfile, "%s\t,", ntab1[fexp[temp1].arg2.pos]); else { if (fexp[temp1].arg2.sy1 == tempsy) fprintf(mfile, "T%d\t,", fexp[temp1].arg2.pos); else { if (fexp[temp1].arg2.sy1 == intconst) fprintf(mfile, "%d\t,", fexp[temp1].arg2.pos); else fprintf(mfile, "\t,"); } } if (fexp[temp1].op[0] != 'j') { if (fexp[temp1].result >= 100) fprintf(mfile, "T%d\t)", fexp[temp1].result - 100); else fprintf(mfile, "%s\t)", ntab1[fexp[temp1].result]); } else fprintf(mfile, "%d\t)", fexp[temp1].result); if (temp1 == 20) { printf("\nPress any key to continue......\n"); getch(); } } getch(); } void disp3() { int tttt; printf("\n\n程序总 %d 共行,产生了 %d 个二元式!\n", lnum, count); getch(); printf("\n*******************变量表*******************\n"); for (tttt = 0; tttt < tt1; tttt++) printf("%d\t%s\n", tttt, ntab1[tttt]); getch(); } /*****************主程序**********************/ void main() { printf("\nStart to read pas.c"); cfile = fopen("pas.dat", "r"); if ((cfile = fopen("pas.dat", "r")) == NULL) { printf("\n can't open file!"); printf("\n press any key to quit!"); scanf("%c", &ch_exit); exit(0); } else printf("\n reading...! \n"); mfile = fopen("pas.med", "w"); /*打开c语言源文件*/ readch(); /*从源文件读一个字符*/ scan(); /*词法分析*/ disp1(); disp3(); stack[sp].pos = 0; stack[sp].sy1 = -1; /*初始化状态栈栈底*/ stack1[sp1] = 0; /*初始化状态栈栈底*/ oth.sy1 = -1; printf("\n*********状态栈变化过程及规约顺序************\n"); readnu(); /*从二元式读一个字符*/ lrparse(); getch(); /*四元式的分析*/ disp2(); printf("\n程序结束。谢谢使用!\n"); printf("COPYRIGHT BY Z.Y.P 2001.6.7"); getch(); }
int EETruss::update() { int rValue = 0; // get current time Domain *theDomain = this->getDomain(); (*t)(0) = theDomain->getCurrentTime(); // determine dsp, vel and acc in basic system const Vector &disp1 = theNodes[0]->getTrialDisp(); const Vector &disp2 = theNodes[1]->getTrialDisp(); const Vector &vel1 = theNodes[0]->getTrialVel(); const Vector &vel2 = theNodes[1]->getTrialVel(); const Vector &accel1 = theNodes[0]->getTrialAccel(); const Vector &accel2 = theNodes[1]->getTrialAccel(); const Vector &dispIncr1 = theNodes[0]->getIncrDeltaDisp(); const Vector &dispIncr2 = theNodes[1]->getIncrDeltaDisp(); (*db)(0) = (*vb)(0) = (*ab)(0) = 0.0; double dbDelta = 0.0; for (int i=0; i<numDIM; i++) { (*db)(0) += (disp2(i)-disp1(i))*cosX[i]; (*vb)(0) += (vel2(i)-vel1(i))*cosX[i]; (*ab)(0) += (accel2(i)-accel1(i))*cosX[i]; dbDelta += (dispIncr2(i)-dispIncr1(i))*cosX[i]; } // do not check time for right now because of transformation constraint // handler calling update at beginning of new step when applying load // if (fabs(dbDelta) > DBL_EPSILON || (*t)(0) > tLast) { if (fabs(dbDelta) > DBL_EPSILON) { // set the trial response at the site if (theSite != 0) { theSite->setTrialResponse(db, vb, ab, (Vector*)0, t); } else { sData[0] = OF_RemoteTest_setTrialResponse; rValue += theChannel->sendVector(0, 0, *sendData, 0); } } // save the last time tLast = (*t)(0); return rValue; }
const Vector & PDeltaCrdTransf2d::getBasicIncrDeltaDisp(void) { // determine global displacements const Vector &disp1 = nodeIPtr->getIncrDeltaDisp(); const Vector &disp2 = nodeJPtr->getIncrDeltaDisp(); static double Dug[6]; for (int i = 0; i < 3; i++) { Dug[i] = disp1(i); Dug[i+3] = disp2(i); } static Vector Dub(3); double oneOverL = 1.0/L; double sl = sinTheta*oneOverL; double cl = cosTheta*oneOverL; Dub(0) = -cosTheta*Dug[0] - sinTheta*Dug[1] + cosTheta*Dug[3] + sinTheta*Dug[4]; Dub(1) = -sl*Dug[0] + cl*Dug[1] + Dug[2] + sl*Dug[3] - cl*Dug[4]; if (nodeIOffset != 0) { double t02 = -cosTheta*nodeIOffset[1] + sinTheta*nodeIOffset[0]; double t12 = sinTheta*nodeIOffset[1] + cosTheta*nodeIOffset[0]; Dub(0) -= t02*Dug[2]; Dub(1) += oneOverL*t12*Dug[2]; } if (nodeJOffset != 0) { double t35 = -cosTheta*nodeJOffset[1] + sinTheta*nodeJOffset[0]; double t45 = sinTheta*nodeJOffset[1] + cosTheta*nodeJOffset[0]; Dub(0) += t35*Dug[5]; Dub(1) -= oneOverL*t45*Dug[5]; } Dub(2) = Dub(1) + Dug[5] - Dug[2]; return Dub; }
double Truss2::computeCurrentNormalStrain(void) const { // normal vector = (-cosX[1], cosX[0]) if (otherLength == 0) { return 0; } // determine the strain const Vector &disp1 = theOtherNodes[0]->getTrialDisp(); const Vector &disp2 = theOtherNodes[1]->getTrialDisp(); double dLength = 0.0; for (int i = 0; i < dimension; i++) dLength += (disp2(i)-disp1(i))*otherCosX[i]; // this method should never be called with L == 0 // double et = projFactor*dLength/otherLength; double et = dLength/otherLength; return et; }
int FourNodeQuadUP::update() { const Vector &disp1 = nd1Ptr->getTrialDisp(); const Vector &disp2 = nd2Ptr->getTrialDisp(); const Vector &disp3 = nd3Ptr->getTrialDisp(); const Vector &disp4 = nd4Ptr->getTrialDisp(); static double u[2][4]; if (end1InitDisp == 0) { u[0][0] = disp1(0); u[1][0] = disp1(1); } else { u[0][0] = disp1(0) - end1InitDisp[0]; u[1][0] = disp1(1) - end1InitDisp[1]; } if (end2InitDisp == 0) { u[0][1] = disp2(0); u[1][1] = disp2(1); } else { u[0][1] = disp2(0) - end2InitDisp[0]; u[1][1] = disp2(1) - end2InitDisp[1]; } if (end3InitDisp == 0) { u[0][2] = disp3(0); u[1][2] = disp3(1); } else { u[0][2] = disp3(0) - end3InitDisp[0]; u[1][2] = disp3(1) - end3InitDisp[1]; } if (end3InitDisp == 0) { u[0][3] = disp4(0); u[1][3] = disp4(1); } else { u[0][3] = disp4(0) - end4InitDisp[0]; u[1][3] = disp4(1) - end4InitDisp[1];; } static Vector eps(3); int ret = 0; // Determine Jacobian for this integration point this->shapeFunction(); // Loop over the integration points for (int i = 0; i < 4; i++) { // Interpolate strains //eps = B*u; //eps.addMatrixVector(0.0, B, u, 1.0); eps.Zero(); for (int beta = 0; beta < 4; beta++) { eps(0) += shp[0][beta][i]*u[0][beta]; eps(1) += shp[1][beta][i]*u[1][beta]; eps(2) += shp[0][beta][i]*u[1][beta] + shp[1][beta][i]*u[0][beta]; } // Set the material strain ret += theMaterial[i]->setTrialStrain(eps); } return ret; }
int PY_Macro2D::update(void) { Domain *theDomain=this->getDomain(); Tt = theDomain->getCurrentTime(); double dt = Tt - Ct; // determine the strain const Vector &disp1 = theNodes[0]->getTrialDisp(); const Vector &disp2 = theNodes[1]->getTrialDisp(); double Ru = disp1(1); // pore water pressure // Use displacements to find the total strain in the element TU = 0.0; for (int i=0; i<2; i++) { TU -= (disp2(i)-disp1(i)) * trans(0,i); } // Find the change in strain double dU = TU - CU; // Declare the other variables required double dz, f, f_, Tzold, Tznew; dz = K/py*(1-(tanh(a*abs(Cz))/tanh(a))*(b+g*signum(dU*Cz)))*dU; Tz = Cz+dz; // Pore Pressure Generation Model Tforce = py*Tz*CS; Ttangent = K*(1-(tanh(a*fabs(Tz))/tanh(a))*(b+g*signum(dU*Tz)))*TS; TW = CW; double dSb = 0.0; if (fabs(Tz) <= 0.67*m2/m1) { TW = CW+fabs(Tforce*dU)/py/(py/K); dSb = exp(-1*pow(TW/w1,1.4))*1.4*pow(TW/w1,0.4)*fabs(Tforce*dU)/py/(py/K)/w1; } double Sff = 1-Ru; double dSd = beta/(0.01+0.99*fabs(Sff-CS0))*pow(CS,p1) *dt/(1+beta/(0.01+0.99*fabs(Sff-CS0))*pow(CS,p1) *dt)*(Sff-CS); TS0 = CS0 - dSb + dSd; if (fabs(Tz) <= 0.67*m2/m1) { TS = TS0; } else { double alp = 0.67*m2/m1; TS = TS0*(1+alp*alp)/(fabs(Tz)*alp+pow((Tz*alp)*(Tz*alp)+(1-Tz*Tz)*(1+alp*alp),0.5)); } // Compute force and tangent // Tforce = py*Tz*TS; // Ttangent = K*(1-(tanh(a*fabs(Tz))/tanh(a))*(b+g*signum(dU*Tz)))*TS; return 0; }
void BeamColumnJoint3d::getGlobalDispls(Vector &dg) { // local variables that will be used in this method int converge = 0; int linesearch = 0; int totalCount = 0; int dtConverge = 0; int incCount = 0; int count = 0; int maxTotalCount = 1000; int maxCount = 20; double loadStep = 0.0; double dLoadStep = 1.0; double stepSize; Vector uExtOld(24); uExtOld.Zero(); Vector uExt(12); uExt.Zero(); Vector duExt(12); duExt.Zero(); Vector uIntOld(4); uIntOld.Zero(); Vector uInt(4); uInt.Zero(); Vector duInt(4); duInt.Zero(); Vector duIntTemp(4); duIntTemp.Zero(); Vector intEq(4); intEq.Zero(); Vector intEqLast(4); intEqLast.Zero(); Vector Uepr(24); Uepr.Zero(); Vector UeprInt(4); UeprInt.Zero(); Vector Ut(24); Ut.Zero(); Vector duExtTemp(24); duExtTemp.Zero(); Vector disp1 = nodePtr[0]->getTrialDisp(); Vector disp2 = nodePtr[1]->getTrialDisp(); Vector disp3 = nodePtr[2]->getTrialDisp(); Vector disp4 = nodePtr[3]->getTrialDisp(); for (int i = 0; i < 6; i++) { Ut(i) = disp1(i); Ut(i+6) = disp2(i); Ut(i+12) = disp3(i); Ut(i+18) = disp4(i); } Uepr = Uecommit; UeprInt = UeIntcommit; uExtOld = Uepr; duExtTemp = Ut - Uepr; duExt.addMatrixVector(0.0,Transf,duExtTemp,1.0); uExt.addMatrixVector(0.0,Transf,uExtOld,1.0); uIntOld = UeprInt; uInt = uIntOld; double tol = 1e-12; double tolIntEq = tol; double toluInt = (tol>tol*uInt.Norm())? tol:tol*uInt.Norm(); double tolIntEqdU = tol; double ctolIntEqdU = tol; double ctolIntEq = tol; double normDuInt = toluInt; double normIntEq = tolIntEq; double normIntEqdU = tolIntEqdU; Vector u(16); u.Zero(); double engrLast = 0.0; double engr = 0.0; Vector fSpring(13); fSpring.Zero(); Vector kSpring(13); kSpring.Zero(); Matrix dintEq_du(4,4); dintEq_du.Zero(); Matrix df_dDef(13,13); df_dDef.Zero(); Matrix tempintEq_du (4,13); tempintEq_du.Zero(); while ((loadStep < 1.0) && (totalCount < maxTotalCount)) { count = 0; converge = 0; dtConverge = 0; while ((!converge) && (count < maxCount)) { if (dLoadStep <= 1e-3) { dLoadStep = dLoadStep; } totalCount ++; count ++; for (int ic = 0; ic < 12; ic++ ) { u(ic) = uExt(ic) + duExt(ic); } u(12) = uInt(0); u(13) = uInt(1); u(14) = uInt(2); u(15) = uInt(3); getMatResponse(u,fSpring,kSpring); // performs internal equilibrium intEq(0) = -fSpring(2)-fSpring(3)+fSpring(9)-fSpring(12)/elemHeight; intEq(1) = fSpring(1)-fSpring(5)-fSpring(7)+fSpring(12)/elemWidth; intEq(2) = -fSpring(4)-fSpring(8)+fSpring(10)+fSpring(12)/elemHeight; intEq(3) = fSpring(0)-fSpring(6)-fSpring(11)-fSpring(12)/elemWidth; matDiag(kSpring, df_dDef); //////////////////////// dintEq_du = dg_df*df_dDef*dDef_du tempintEq_du.addMatrixProduct(0.0,dg_df,df_dDef,1.0); dintEq_du.addMatrixProduct(0.0,tempintEq_du,dDef_du,1.0); normIntEq = intEq.Norm(); normIntEqdU = 0.0; for (int jc = 0; jc<4 ; jc++) { normIntEqdU += intEq(jc)*duInt(jc); } normIntEqdU = fabs(normIntEqdU); if (totalCount == 1) { tolIntEq = (tol>tol*normIntEq) ? tol:tol*normIntEq; tolIntEqdU = tol; } else if (totalCount == 2) { tolIntEqdU = (tol>tol*normIntEqdU) ? tol:tol*normIntEqdU; } ctolIntEqdU = (tolIntEqdU*dLoadStep > tol) ? tolIntEqdU*dLoadStep:tol; ctolIntEq = (tolIntEq*dLoadStep > tol) ? tolIntEq*dLoadStep:tol; // check for convergence starts if ((normIntEq < tol) || ((normIntEqdU < tol) && (count >1)) || (normDuInt < toluInt) || (dLoadStep < 1e-3)) { if ((normIntEq > ctolIntEq) || (normIntEqdU > tolIntEqdU) || (normDuInt > toluInt)) { dtConverge = 1; } else { dtConverge = 0; } converge = 1; loadStep = loadStep + dLoadStep; if (fabs(1.0 - loadStep) < tol) { loadStep = 1.0; } } else { ////////////// duInt = -dintEq_du/intEq dintEq_du.Solve(intEq,duInt); duInt *= -1; normDuInt = duInt.Norm(); if (!linesearch) { uInt = uInt + duInt; } else { engrLast = 0.0; engr = 0.0; for (int jd = 0; jd<4 ; jd++) { engrLast += duInt(jd)*intEqLast(jd); engr += duInt(jd)*intEq(jd); } if (fabs(engr) > tol*engrLast) { duIntTemp = duInt; duIntTemp *= -1; // lineSearch algorithm requirement stepSize = getStepSize(engrLast,engr,uExt,duExt,uInt,duIntTemp,tol); if (fabs(stepSize) > 0.001) { uInt = uInt + stepSize*duInt; } else { uInt = uInt + duInt; } } else { uInt = uInt + duInt; } intEqLast = intEq; } } } if (!converge && loadStep < 1.0) { incCount = 0; maxCount = 25; if (!linesearch) { linesearch = 1; uInt = uIntOld; duInt.Zero(); } else { opserr << "WARNING : BeamColumnJoint::getGlobalDispls() - convergence problem in state determination" << endln; uInt = uIntOld; duInt.Zero(); duExt = duExt*0.1; dLoadStep = dLoadStep*0.1; } } else if (loadStep < 1.0) { maxCount = 10; incCount ++; normDuInt = toluInt; if ((incCount < maxCount) || dtConverge) { uExt = uExt + duExt; if (loadStep + dLoadStep > 1.0) { duExt = duExt*(1.0 - loadStep)/dLoadStep; dLoadStep = 1.0 - loadStep; incCount = 9; } } else { incCount = 0; uExt = uExt + duExt; dLoadStep = dLoadStep*10; if (loadStep + dLoadStep > 1.0) { uExt = uExt + duExt*(1.0 - loadStep)/dLoadStep; dLoadStep = 1.0 - loadStep; incCount = 9; } } } } // determination of stiffness matrix and the residual force vector for the element formR(fSpring); formK(kSpring); for (int ig = 0; ig < 25; ig++ ) { if (ig<24) { dg(ig) = Ut(ig); } } dg(24) = uInt(0); dg(25) = uInt(1); dg(26) = uInt(2); dg(27) = uInt(3); }
void TractsToVectorImageFilter< PixelType >::GenerateData() { mitk::BaseGeometry::Pointer geometry = m_FiberBundle->GetGeometry(); // calculate new image parameters itk::Vector<double> spacing; itk::Point<double> origin; itk::Matrix<double, 3, 3> direction; ImageRegion<3> imageRegion; if (!m_MaskImage.IsNull()) { spacing = m_MaskImage->GetSpacing(); imageRegion = m_MaskImage->GetLargestPossibleRegion(); origin = m_MaskImage->GetOrigin(); direction = m_MaskImage->GetDirection(); } else { spacing = geometry->GetSpacing(); origin = geometry->GetOrigin(); mitk::BaseGeometry::BoundsArrayType bounds = geometry->GetBounds(); origin[0] += bounds.GetElement(0); origin[1] += bounds.GetElement(2); origin[2] += bounds.GetElement(4); for (int i=0; i<3; i++) for (int j=0; j<3; j++) direction[j][i] = geometry->GetMatrixColumn(i)[j]; imageRegion.SetSize(0, geometry->GetExtent(0)); imageRegion.SetSize(1, geometry->GetExtent(1)); imageRegion.SetSize(2, geometry->GetExtent(2)); m_MaskImage = ItkUcharImgType::New(); m_MaskImage->SetSpacing( spacing ); m_MaskImage->SetOrigin( origin ); m_MaskImage->SetDirection( direction ); m_MaskImage->SetRegions( imageRegion ); m_MaskImage->Allocate(); m_MaskImage->FillBuffer(1); } OutputImageType::RegionType::SizeType outImageSize = imageRegion.GetSize(); m_OutImageSpacing = m_MaskImage->GetSpacing(); m_ClusteredDirectionsContainer = ContainerType::New(); // initialize num directions image m_NumDirectionsImage = ItkUcharImgType::New(); m_NumDirectionsImage->SetSpacing( spacing ); m_NumDirectionsImage->SetOrigin( origin ); m_NumDirectionsImage->SetDirection( direction ); m_NumDirectionsImage->SetRegions( imageRegion ); m_NumDirectionsImage->Allocate(); m_NumDirectionsImage->FillBuffer(0); // initialize direction images m_DirectionImageContainer = DirectionImageContainerType::New(); // resample fiber bundle double minSpacing = 1; if(m_OutImageSpacing[0]<m_OutImageSpacing[1] && m_OutImageSpacing[0]<m_OutImageSpacing[2]) minSpacing = m_OutImageSpacing[0]; else if (m_OutImageSpacing[1] < m_OutImageSpacing[2]) minSpacing = m_OutImageSpacing[1]; else minSpacing = m_OutImageSpacing[2]; if (m_UseWorkingCopy) m_FiberBundle = m_FiberBundle->GetDeepCopy(); // resample fiber bundle for sufficient voxel coverage m_FiberBundle->ResampleSpline(minSpacing/10); // iterate over all fibers vtkSmartPointer<vtkPolyData> fiberPolyData = m_FiberBundle->GetFiberPolyData(); int numFibers = m_FiberBundle->GetNumFibers(); m_DirectionsContainer = ContainerType::New(); VectorContainer< unsigned int, std::vector< double > >::Pointer peakLengths = VectorContainer< unsigned int, std::vector< double > >::New(); MITK_INFO << "Generating directions from tractogram"; boost::progress_display disp(numFibers); for( int i=0; i<numFibers; i++ ) { ++disp; vtkCell* cell = fiberPolyData->GetCell(i); int numPoints = cell->GetNumberOfPoints(); vtkPoints* points = cell->GetPoints(); if (numPoints<2) continue; vnl_vector_fixed<double, 3> dir; itk::Point<double, 3> worldPos; vnl_vector<double> v; float fiberWeight = m_FiberBundle->GetFiberWeight(i); for( int j=0; j<numPoints-1; j++) { // get current position along fiber in world coordinates double* temp = points->GetPoint(j); worldPos = GetItkPoint(temp); itk::Index<3> index; m_MaskImage->TransformPhysicalPointToIndex(worldPos, index); if (!m_MaskImage->GetLargestPossibleRegion().IsInside(index) || m_MaskImage->GetPixel(index)==0) continue; // get fiber tangent direction at this position v = GetVnlVector(temp); dir = GetVnlVector(points->GetPoint(j+1))-v; if (dir.is_zero()) continue; dir.normalize(); // add direction to container unsigned int idx = index[0] + outImageSize[0]*(index[1] + outImageSize[1]*index[2]); DirectionContainerType::Pointer dirCont; if (m_DirectionsContainer->IndexExists(idx)) { peakLengths->ElementAt(idx).push_back(fiberWeight); dirCont = m_DirectionsContainer->GetElement(idx); if (dirCont.IsNull()) { dirCont = DirectionContainerType::New(); dirCont->push_back(dir); m_DirectionsContainer->InsertElement(idx, dirCont); } else dirCont->push_back(dir); } else { dirCont = DirectionContainerType::New(); dirCont->push_back(dir); m_DirectionsContainer->InsertElement(idx, dirCont); std::vector< double > lengths; lengths.push_back(fiberWeight); peakLengths->InsertElement(idx, lengths); } } } vtkSmartPointer<vtkCellArray> m_VtkCellArray = vtkSmartPointer<vtkCellArray>::New(); vtkSmartPointer<vtkPoints> m_VtkPoints = vtkSmartPointer<vtkPoints>::New(); itk::ImageRegionIterator<ItkUcharImgType> dirIt(m_NumDirectionsImage, m_NumDirectionsImage->GetLargestPossibleRegion()); MITK_INFO << "Clustering directions"; boost::progress_display disp2(outImageSize[0]*outImageSize[1]*outImageSize[2]); while(!dirIt.IsAtEnd()) { ++disp2; OutputImageType::IndexType index = dirIt.GetIndex(); int idx = index[0]+(index[1]+index[2]*outImageSize[1])*outImageSize[0]; if (!m_DirectionsContainer->IndexExists(idx)) { ++dirIt; continue; } DirectionContainerType::Pointer dirCont = m_DirectionsContainer->GetElement(idx); if (dirCont.IsNull() || dirCont->empty()) { ++dirIt; continue; } // std::vector< double > lengths; lengths.resize(dirCont->size(), 1); // all peaks have size 1 DirectionContainerType::Pointer directions; if (m_MaxNumDirections>0) { directions = FastClustering(dirCont, peakLengths->GetElement(idx)); std::sort( directions->begin(), directions->end(), CompareVectorLengths ); } else directions = dirCont; unsigned int numDir = directions->size(); if (m_MaxNumDirections>0 && numDir>m_MaxNumDirections) numDir = m_MaxNumDirections; int count = 0; for (unsigned int i=0; i<numDir; i++) { vtkSmartPointer<vtkPolyLine> container = vtkSmartPointer<vtkPolyLine>::New(); itk::ContinuousIndex<double, 3> center; center[0] = index[0]; center[1] = index[1]; center[2] = index[2]; itk::Point<double> worldCenter; m_MaskImage->TransformContinuousIndexToPhysicalPoint( center, worldCenter ); DirectionType dir = directions->at(i); if (dir.magnitude()<m_SizeThreshold) continue; if (m_NormalizeVectors) dir.normalize(); count++; if (m_CreateDirectionImages && i<10) { if (i==m_DirectionImageContainer->size()) { ItkDirectionImageType::Pointer directionImage = ItkDirectionImageType::New(); directionImage->SetSpacing( spacing ); directionImage->SetOrigin( origin ); directionImage->SetDirection( direction ); directionImage->SetRegions( imageRegion ); directionImage->Allocate(); Vector< float, 3 > nullVec; nullVec.Fill(0.0); directionImage->FillBuffer(nullVec); m_DirectionImageContainer->InsertElement(i, directionImage); } // set direction image pixel ItkDirectionImageType::Pointer directionImage = m_DirectionImageContainer->GetElement(i); Vector< float, 3 > pixel; pixel.SetElement(0, dir[0]); pixel.SetElement(1, dir[1]); pixel.SetElement(2, dir[2]); directionImage->SetPixel(index, pixel); } // add direction to vector field (with spacing compensation) itk::Point<double> worldStart; worldStart[0] = worldCenter[0]-dir[0]/2*minSpacing; worldStart[1] = worldCenter[1]-dir[1]/2*minSpacing; worldStart[2] = worldCenter[2]-dir[2]/2*minSpacing; vtkIdType id = m_VtkPoints->InsertNextPoint(worldStart.GetDataPointer()); container->GetPointIds()->InsertNextId(id); itk::Point<double> worldEnd; worldEnd[0] = worldCenter[0]+dir[0]/2*minSpacing; worldEnd[1] = worldCenter[1]+dir[1]/2*minSpacing; worldEnd[2] = worldCenter[2]+dir[2]/2*minSpacing; id = m_VtkPoints->InsertNextPoint(worldEnd.GetDataPointer()); container->GetPointIds()->InsertNextId(id); m_VtkCellArray->InsertNextCell(container); } dirIt.Set(count); ++dirIt; } vtkSmartPointer<vtkPolyData> directionsPolyData = vtkSmartPointer<vtkPolyData>::New(); directionsPolyData->SetPoints(m_VtkPoints); directionsPolyData->SetLines(m_VtkCellArray); m_OutputFiberBundle = mitk::FiberBundle::New(directionsPolyData); }
int Truss2::commitSensitivity(int gradNumber, int numGrads) { // Initial declarations int i; double strainSensitivity, temp1, temp2; // Displacement difference between the two ends double strain = this->computeCurrentStrain(); double dLength = strain*L; // Displacement sensitivity difference between the two ends double sens1; double sens2; double dSensitivity = 0.0; for (i=0; i<dimension; i++){ sens1 = theNodes[0]->getDispSensitivity(i+1, gradNumber); sens2 = theNodes[1]->getDispSensitivity(i+1, gradNumber); dSensitivity += (sens2-sens1)*cosX[i]; } strainSensitivity = dSensitivity/L; // Check if a nodal coordinate is random int nodeParameterID0 = theNodes[0]->getCrdsSensitivity(); int nodeParameterID1 = theNodes[1]->getCrdsSensitivity(); if (nodeParameterID0 != 0 || nodeParameterID1 != 0) { double dx = L*cosX[0]; double dy = L*cosX[1]; //double dz = L*cosX[2]; // Compute derivative of transformation matrix (assume 4 dofs) double dcosXdh[3]; if (nodeParameterID0 == 1) { // here x1 is random temp1 = (-L+dx*dx/L)/(L*L); temp2 = dx*dy/(L*L*L); //dtdh(0) = -temp1; //dtdh(1) = -temp2; //dtdh(2) = temp1; //dtdh(3) = temp2; dcosXdh[0] = temp1; dcosXdh[1] = temp2; dcosXdh[2] = 0.0; } if (nodeParameterID0 == 2) { // here y1 is random temp1 = (-L+dy*dy/L)/(L*L); temp2 = dx*dy/(L*L*L); //dtdh(0) = -temp2; //dtdh(1) = -temp1; //dtdh(2) = temp2; //dtdh(3) = temp1; dcosXdh[0] = temp2; dcosXdh[1] = temp1; dcosXdh[2] = 0.0; } if (nodeParameterID1 == 1) { // here x2 is random temp1 = (L-dx*dx/L)/(L*L); temp2 = -dx*dy/(L*L*L); //dtdh(0) = -temp1; //dtdh(1) = -temp2; //dtdh(2) = temp1; //dtdh(3) = temp2; dcosXdh[0] = temp1; dcosXdh[1] = temp2; dcosXdh[2] = 0.0; } if (nodeParameterID1 == 2) { // here y2 is random temp1 = (L-dy*dy/L)/(L*L); temp2 = -dx*dy/(L*L*L); //dtdh(0) = -temp2; //dtdh(1) = -temp1; //dtdh(2) = temp2; //dtdh(3) = temp1; dcosXdh[0] = temp2; dcosXdh[1] = temp1; dcosXdh[2] = 0.0; } const Vector &disp1 = theNodes[0]->getTrialDisp(); const Vector &disp2 = theNodes[1]->getTrialDisp(); double dLengthDerivative = 0.0; for (i = 0; i < dimension; i++){ dLengthDerivative += (disp2(i)-disp1(i))*dcosXdh[i]; } strainSensitivity += dLengthDerivative/L; if (nodeParameterID0 == 1) { // here x1 is random strainSensitivity += dLength/(L*L*L)*dx; } if (nodeParameterID0 == 2) { // here y1 is random strainSensitivity += dLength/(L*L*L)*dy; } if (nodeParameterID1 == 1) { // here x2 is random strainSensitivity -= dLength/(L*L*L)*dx; } if (nodeParameterID1 == 2) { // here y2 is random strainSensitivity -= dLength/(L*L*L)*dy; } } // Pass it down to the material theMaterial->commitSensitivity(strainSensitivity, gradNumber, numGrads); return 0; }
const Vector & Truss2::getResistingForceSensitivity(int gradNumber) { theVector->Zero(); // Initial declarations int i; double stressSensitivity, temp1, temp2; // Make sure the material is up to date double strain = this->computeCurrentStrain(); double rate = this->computeCurrentStrainRate(); theMaterial->setTrialStrain(strain,rate); // Contribution from material stressSensitivity = theMaterial->getStressSensitivity(gradNumber,true); // Check if a nodal coordinate is random double dcosXdh[3]; dcosXdh[0] = 0.0; dcosXdh[1] = 0.0; dcosXdh[2] = 0.0; int nodeParameterID0 = theNodes[0]->getCrdsSensitivity(); int nodeParameterID1 = theNodes[1]->getCrdsSensitivity(); if (nodeParameterID0 != 0 || nodeParameterID1 != 0) { double dx = L*cosX[0]; double dy = L*cosX[1]; //double dz = L*cosX[2]; // Compute derivative of transformation matrix (assume 4 dofs) if (nodeParameterID0 == 1) { // here x1 is random temp1 = (-L+dx*dx/L)/(L*L); temp2 = dx*dy/(L*L*L); //dtdh(0) = -temp1; //dtdh(1) = -temp2; //dtdh(2) = temp1; //dtdh(3) = temp2; dcosXdh[0] = temp1; dcosXdh[1] = temp2; dcosXdh[2] = 0.0; } if (nodeParameterID0 == 2) { // here y1 is random temp1 = (-L+dy*dy/L)/(L*L); temp2 = dx*dy/(L*L*L); //dtdh(0) = -temp2; //dtdh(1) = -temp1; //dtdh(2) = temp2; //dtdh(3) = temp1; dcosXdh[0] = temp2; dcosXdh[1] = temp1; dcosXdh[2] = 0.0; } if (nodeParameterID1 == 1) { // here x2 is random temp1 = (L-dx*dx/L)/(L*L); temp2 = -dx*dy/(L*L*L); //dtdh(0) = -temp1; //dtdh(1) = -temp2; //dtdh(2) = temp1; //dtdh(3) = temp2; dcosXdh[0] = temp1; dcosXdh[1] = temp2; dcosXdh[2] = 0.0; } if (nodeParameterID1 == 2) { // here y2 is random temp1 = (L-dy*dy/L)/(L*L); temp2 = -dx*dy/(L*L*L); //dtdh(0) = -temp2; //dtdh(1) = -temp1; //dtdh(2) = temp2; //dtdh(3) = temp1; dcosXdh[0] = temp2; dcosXdh[1] = temp1; dcosXdh[2] = 0.0; } const Vector &disp1 = theNodes[0]->getTrialDisp(); const Vector &disp2 = theNodes[1]->getTrialDisp(); double dLengthDerivative = 0.0; for (i = 0; i < dimension; i++) { dLengthDerivative += (disp2(i)-disp1(i))*dcosXdh[i]; } double materialTangent = theMaterial->getTangent(); double strainSensitivity = 0.0; if (nodeParameterID0 == 1) { // here x1 is random strainSensitivity = (dLengthDerivative*L+strain*dx)/(L*L); } if (nodeParameterID0 == 2) { // here y1 is random strainSensitivity = (dLengthDerivative*L+strain*dy)/(L*L); } if (nodeParameterID1 == 1) { // here x2 is random strainSensitivity = (dLengthDerivative*L-strain*dx)/(L*L); } if (nodeParameterID1 == 2) { // here y2 is random strainSensitivity = (dLengthDerivative*L-strain*dy)/(L*L); } stressSensitivity += materialTangent * strainSensitivity; } // Compute sensitivity depending on 'parameter' double stress = theMaterial->getStress(); int numDOF2 = numDOF/2; double temp; if (parameterID == 1) { // Cross-sectional area for (i = 0; i < dimension; i++) { temp = (stress + A*stressSensitivity)*cosX[i]; (*theVector)(i) = -temp; (*theVector)(i+numDOF2) = temp; } } else { // Density, material parameter or nodal coordinate for (i = 0; i < dimension; i++) { temp = A*(stressSensitivity*cosX[i] + stress*dcosXdh[i]); (*theVector)(i) = -temp; (*theVector)(i+numDOF2) = temp; } } // subtract external load sensitivity if (theLoadSens == 0) { theLoadSens = new Vector(numDOF); } (*theVector) -= *theLoadSens; return *theVector; }
void TractsToVectorImageFilter< PixelType >::GenerateData() { mitk::BaseGeometry::Pointer geometry = m_FiberBundle->GetGeometry(); // calculate new image parameters itk::Vector<double> spacing3; itk::Point<double> origin3; itk::Matrix<double, 3, 3> direction3; ImageRegion<3> imageRegion3; if (!m_MaskImage.IsNull()) { spacing3 = m_MaskImage->GetSpacing(); imageRegion3 = m_MaskImage->GetLargestPossibleRegion(); origin3 = m_MaskImage->GetOrigin(); direction3 = m_MaskImage->GetDirection(); } else { spacing3 = geometry->GetSpacing(); origin3 = geometry->GetOrigin(); mitk::BaseGeometry::BoundsArrayType bounds = geometry->GetBounds(); origin3[0] += bounds.GetElement(0); origin3[1] += bounds.GetElement(2); origin3[2] += bounds.GetElement(4); for (int i=0; i<3; i++) for (int j=0; j<3; j++) direction3[j][i] = geometry->GetMatrixColumn(i)[j]; imageRegion3.SetSize(0, geometry->GetExtent(0)+1); imageRegion3.SetSize(1, geometry->GetExtent(1)+1); imageRegion3.SetSize(2, geometry->GetExtent(2)+1); m_MaskImage = ItkUcharImgType::New(); m_MaskImage->SetSpacing( spacing3 ); m_MaskImage->SetOrigin( origin3 ); m_MaskImage->SetDirection( direction3 ); m_MaskImage->SetRegions( imageRegion3 ); m_MaskImage->Allocate(); m_MaskImage->FillBuffer(1); } OutputImageType::RegionType::SizeType outImageSize = imageRegion3.GetSize(); m_OutImageSpacing = m_MaskImage->GetSpacing(); m_ClusteredDirectionsContainer = ContainerType::New(); // initialize num directions image m_NumDirectionsImage = ItkUcharImgType::New(); m_NumDirectionsImage->SetSpacing( spacing3 ); m_NumDirectionsImage->SetOrigin( origin3 ); m_NumDirectionsImage->SetDirection( direction3 ); m_NumDirectionsImage->SetRegions( imageRegion3 ); m_NumDirectionsImage->Allocate(); m_NumDirectionsImage->FillBuffer(0); itk::Vector<double, 4> spacing4; itk::Point<float, 4> origin4; itk::Matrix<double, 4, 4> direction4; itk::ImageRegion<4> imageRegion4; spacing4[0] = spacing3[0]; spacing4[1] = spacing3[1]; spacing4[2] = spacing3[2]; spacing4[3] = 1; origin4[0] = origin3[0]; origin4[1] = origin3[1]; origin4[2] = origin3[2]; origin3[3] = 0; for (int r=0; r<3; r++) for (int c=0; c<3; c++) direction4[r][c] = direction3[r][c]; direction4[3][3] = 1; imageRegion4.SetSize(0, imageRegion3.GetSize()[0]); imageRegion4.SetSize(1, imageRegion3.GetSize()[1]); imageRegion4.SetSize(2, imageRegion3.GetSize()[2]); imageRegion4.SetSize(3, m_MaxNumDirections*3); m_DirectionImage = ItkDirectionImageType::New(); m_DirectionImage->SetSpacing( spacing4 ); m_DirectionImage->SetOrigin( origin4 ); m_DirectionImage->SetDirection( direction4 ); m_DirectionImage->SetRegions( imageRegion4 ); m_DirectionImage->Allocate(); m_DirectionImage->FillBuffer(0.0); // iterate over all fibers vtkSmartPointer<vtkPolyData> fiberPolyData = m_FiberBundle->GetFiberPolyData(); int numFibers = m_FiberBundle->GetNumFibers(); m_DirectionsContainer = ContainerType::New(); VectorContainer< unsigned int, std::vector< double > >::Pointer peakLengths = VectorContainer< unsigned int, std::vector< double > >::New(); MITK_INFO << "Generating directions from tractogram"; boost::progress_display disp(numFibers); for( int i=0; i<numFibers; i++ ) { ++disp; vtkCell* cell = fiberPolyData->GetCell(i); int numPoints = cell->GetNumberOfPoints(); vtkPoints* points = cell->GetPoints(); if (numPoints<2) continue; vnl_vector_fixed<double, 3> dir; vnl_vector<double> v; float fiberWeight = m_FiberBundle->GetFiberWeight(i); for( int j=0; j<numPoints-1; j++) { itk::Point<float, 3> startVertex = mitk::imv::GetItkPoint(points->GetPoint(j)); itk::Index<3> startIndex; itk::ContinuousIndex<float, 3> startIndexCont; m_MaskImage->TransformPhysicalPointToIndex(startVertex, startIndex); m_MaskImage->TransformPhysicalPointToContinuousIndex(startVertex, startIndexCont); itk::Point<float, 3> endVertex = mitk::imv::GetItkPoint(points->GetPoint(j + 1)); itk::Index<3> endIndex; itk::ContinuousIndex<float, 3> endIndexCont; m_MaskImage->TransformPhysicalPointToIndex(endVertex, endIndex); m_MaskImage->TransformPhysicalPointToContinuousIndex(endVertex, endIndexCont); dir[0] = endVertex[0]-startVertex[0]; dir[1] = endVertex[1]-startVertex[1]; dir[2] = endVertex[2]-startVertex[2]; if (dir.is_zero()) continue; dir.normalize(); std::vector< std::pair< itk::Index<3>, double > > segments = mitk::imv::IntersectImage(spacing3, startIndex, endIndex, startIndexCont, endIndexCont); for (std::pair< itk::Index<3>, double > segment : segments) { if (!m_MaskImage->GetLargestPossibleRegion().IsInside(segment.first) || (!m_OnlyUseMaskGeometry && m_MaskImage->GetPixel(segment.first)==0)) continue; // add direction to container unsigned int idx = segment.first[0] + outImageSize[0]*(segment.first[1] + outImageSize[1]*segment.first[2]); DirectionContainerType::Pointer dirCont; if (m_DirectionsContainer->IndexExists(idx)) { peakLengths->ElementAt(idx).push_back(fiberWeight*segment.second); dirCont = m_DirectionsContainer->GetElement(idx); if (dirCont.IsNull()) { dirCont = DirectionContainerType::New(); dirCont->push_back(dir); m_DirectionsContainer->InsertElement(idx, dirCont); } else dirCont->push_back(dir); } else { dirCont = DirectionContainerType::New(); dirCont->push_back(dir); m_DirectionsContainer->InsertElement(idx, dirCont); std::vector< double > lengths; lengths.push_back(fiberWeight*segment.second); peakLengths->InsertElement(idx, lengths); } } } } itk::ImageRegionIterator<ItkUcharImgType> dirIt(m_NumDirectionsImage, m_NumDirectionsImage->GetLargestPossibleRegion()); MITK_INFO << "Clustering directions"; float max_dir_mag = 0; boost::progress_display disp2(outImageSize[0]*outImageSize[1]*outImageSize[2]); while(!dirIt.IsAtEnd()) { ++disp2; OutputImageType::IndexType idx3 = dirIt.GetIndex(); int idx_lin = idx3[0]+(idx3[1]+idx3[2]*outImageSize[1])*outImageSize[0]; itk::Index<4> idx4; idx4[0] = idx3[0]; idx4[1] = idx3[1]; idx4[2] = idx3[2]; if (!m_DirectionsContainer->IndexExists(idx_lin)) { ++dirIt; continue; } DirectionContainerType::Pointer dirCont = m_DirectionsContainer->GetElement(idx_lin); if (dirCont.IsNull() || dirCont->empty()) { ++dirIt; continue; } DirectionContainerType::Pointer directions; if (m_MaxNumDirections>0) { directions = FastClustering(dirCont, peakLengths->GetElement(idx_lin)); std::sort( directions->begin(), directions->end(), CompareVectorLengths ); } else directions = dirCont; unsigned int numDir = directions->size(); if (m_MaxNumDirections>0 && numDir>m_MaxNumDirections) numDir = m_MaxNumDirections; float voxel_max_mag = 0; for (unsigned int i=0; i<numDir; i++) { DirectionType dir = directions->at(i); float mag = dir.magnitude(); if (mag>voxel_max_mag) voxel_max_mag = mag; if (mag>max_dir_mag) max_dir_mag = mag; } int count = 0; for (unsigned int i=0; i<numDir; i++) { DirectionType dir = directions->at(i); count++; float mag = dir.magnitude(); if (m_NormalizationMethod==MAX_VEC_NORM && voxel_max_mag>mitk::eps) dir /= voxel_max_mag; else if (m_NormalizationMethod==SINGLE_VEC_NORM && mag>mitk::eps) dir.normalize(); for (unsigned int j = 0; j<3; j++) { idx4[3] = i*3 + j; m_DirectionImage->SetPixel(idx4, dir[j]); } } dirIt.Set(count); ++dirIt; } if (m_NormalizationMethod==GLOBAL_MAX && max_dir_mag>0) { itk::ImageRegionIterator<ItkDirectionImageType> dirImgIt(m_DirectionImage, m_DirectionImage->GetLargestPossibleRegion()); while(!dirImgIt.IsAtEnd()) { dirImgIt.Set(dirImgIt.Get()/max_dir_mag); ++dirImgIt; } } }
void FourNodeQuadUP::setDomain(Domain *theDomain) { // Check Domain is not null - invoked when object removed from a domain if (theDomain == 0) { nd1Ptr = 0; nd2Ptr = 0; nd3Ptr = 0; nd4Ptr = 0; return; } int Nd1 = connectedExternalNodes(0); int Nd2 = connectedExternalNodes(1); int Nd3 = connectedExternalNodes(2); int Nd4 = connectedExternalNodes(3); nd1Ptr = theDomain->getNode(Nd1); nd2Ptr = theDomain->getNode(Nd2); nd3Ptr = theDomain->getNode(Nd3); nd4Ptr = theDomain->getNode(Nd4); if (nd1Ptr == 0 || nd2Ptr == 0 || nd3Ptr == 0 || nd4Ptr == 0) { //opserr << "FATAL ERROR FourNodeQuadUP (tag: %d), node not found in domain", // this->getTag()); return; } int dofNd1 = nd1Ptr->getNumberDOF(); int dofNd2 = nd2Ptr->getNumberDOF(); int dofNd3 = nd3Ptr->getNumberDOF(); int dofNd4 = nd4Ptr->getNumberDOF(); if (dofNd1 != 3 || dofNd2 != 3 || dofNd3 != 3 || dofNd4 != 3) { //opserr << "FATAL ERROR FourNodeQuadUP (tag: %d), has differing number of DOFs at its nodes", // this->getTag()); return; } this->DomainComponent::setDomain(theDomain); // Compute consistent nodal loads due to pressure this->setPressureLoadAtNodes(); const Vector &disp1 = nd1Ptr->getDisp(); if (disp1.Norm() != 0.0) { end1InitDisp = new double[2]; for (int i=0; i<2; i++) { end1InitDisp[0] = disp1(i); } } const Vector &disp2 = nd2Ptr->getDisp(); if (disp2.Norm() != 0.0) { end2InitDisp = new double[2]; for (int i=0; i<2; i++) { end2InitDisp[0] = disp2(i); } } const Vector &disp3 = nd3Ptr->getDisp(); if (disp3.Norm() != 0.0) { end3InitDisp = new double[2]; for (int i=0; i<2; i++) { end3InitDisp[0] = disp3(i); } } const Vector &disp4 = nd4Ptr->getDisp(); if (disp4.Norm() != 0.0) { end4InitDisp = new double[2]; for (int i=0; i<2; i++) { end4InitDisp[0] = disp4(i); } } }
int EETrussCorot::update() { int rValue = 0; // get current time Domain *theDomain = this->getDomain(); (*t)(0) = theDomain->getCurrentTime(); // determine dsp, vel and acc in basic system const Vector &disp1 = theNodes[0]->getTrialDisp(); const Vector &disp2 = theNodes[1]->getTrialDisp(); const Vector &vel1 = theNodes[0]->getTrialVel(); const Vector &vel2 = theNodes[1]->getTrialVel(); const Vector &accel1 = theNodes[0]->getTrialAccel(); const Vector &accel2 = theNodes[1]->getTrialAccel(); const Vector &dispIncr1 = theNodes[0]->getIncrDeltaDisp(); const Vector &dispIncr2 = theNodes[1]->getIncrDeltaDisp(); // initial offsets double d21Last[3]; d21[0] = L; d21[1] = d21[2] = 0.0; v21[0] = v21[1] = v21[2] = 0.0; a21[0] = a21[1] = a21[2] = 0.0; d21Last[0] = L; d21Last[1] = d21Last[2] = 0.0; // update offsets in basic system for (int i=0; i<numDIM; i++) { double deltaDisp = disp2(i) - disp1(i); d21[0] += deltaDisp*R(0,i); d21[1] += deltaDisp*R(1,i); d21[2] += deltaDisp*R(2,i); double deltaVel = vel2(i) - vel1(i); v21[0] += deltaVel*R(0,i); v21[1] += deltaVel*R(1,i); v21[2] += deltaVel*R(2,i); double deltaAccel = accel2(i) - accel1(i); a21[0] += deltaAccel*R(0,i); a21[1] += deltaAccel*R(1,i); a21[2] += deltaAccel*R(2,i); double deltaDispLast = (disp2(i)-dispIncr2(i)) - (disp1(i)-dispIncr1(i)); d21Last[0] += deltaDispLast*R(0,i); d21Last[1] += deltaDispLast*R(1,i); d21Last[2] += deltaDispLast*R(2,i); } // compute new length and deformation Ln = sqrt(d21[0]*d21[0] + d21[1]*d21[1] + d21[2]*d21[2]); double c1 = d21[0]*v21[0] + d21[1]*v21[1] + d21[2]*v21[2]; double c2 = v21[0]*v21[0] + v21[1]*v21[1] + v21[2]*v21[2] + d21[0]*a21[0] + d21[1]*a21[1] + d21[2]*a21[2]; (*db)(0) = Ln - L; (*vb)(0) = c1/Ln; (*ab)(0) = c2/Ln - (c1*c1)/(Ln*Ln*Ln); double LnLast = sqrt(d21Last[0]*d21Last[0] + d21Last[1]*d21Last[1] + d21Last[2]*d21Last[2]); double dbDelta = (Ln - L) - (LnLast - L); // do not check time for right now because of transformation constraint // handler calling update at beginning of new step when applying load // if (fabs(dbDelta) > DBL_EPSILON || (*t)(0) > tLast) { if (fabs(dbDelta) > DBL_EPSILON) { // set the trial response at the site if (theSite != 0) { theSite->setTrialResponse(db, vb, ab, (Vector*)0, t); } else { sData[0] = OF_RemoteTest_setTrialResponse; rValue += theChannel->sendVector(0, 0, *sendData, 0); } } // save the last time tLast = (*t)(0); return rValue; }
const Vector & PDeltaCrdTransf2d::getPointGlobalDisplFromBasic(double xi, const Vector &uxb) { // determine global displacements const Vector &disp1 = nodeIPtr->getTrialDisp(); const Vector &disp2 = nodeJPtr->getTrialDisp(); static Vector ug(6); for (int i = 0; i < 3; i++) { ug(i) = disp1(i); ug(i+3) = disp2(i); } if (nodeIInitialDisp != 0) { for (int j=0; j<3; j++) ug[j] -= nodeIInitialDisp[j]; } if (nodeJInitialDisp != 0) { for (int j=0; j<3; j++) ug[j+3] -= nodeJInitialDisp[j]; } // transform global end displacements to local coordinates static Vector ul(6); // total displacements ul(0) = cosTheta*ug(0) + sinTheta*ug(1); ul(1) = -sinTheta*ug(0) + cosTheta*ug(1); ul(2) = ug(2); ul(3) = cosTheta*ug(3) + sinTheta*ug(4); ul(4) = -sinTheta*ug(3) + cosTheta*ug(4); ul(5) = ug(5); if (nodeIOffset != 0) { double t02 = -cosTheta*nodeIOffset[1] + sinTheta*nodeIOffset[0]; double t12 = sinTheta*nodeIOffset[1] + cosTheta*nodeIOffset[0]; ul(0) += t02*ug(2); ul(1) += t12*ug(2); } if (nodeJOffset != 0) { double t35 = -cosTheta*nodeJOffset[1] + sinTheta*nodeJOffset[0]; double t45 = sinTheta*nodeJOffset[1] + cosTheta*nodeJOffset[0]; ul(3) += t35*ug(5); ul(4) += t45*ug(5); } // compute displacements at point xi, in local coordinates static Vector uxl(2), uxg(2); uxl(0) = uxb(0) + ul(0); uxl(1) = uxb(1) + (1-xi)*ul(1) + xi*ul(4); // rotate displacements to global coordinates // uxg = RljT*uxl uxg(0) = cosTheta*uxl(0) - sinTheta*uxl(1); uxg(1) = sinTheta*uxl(0) + cosTheta*uxl(1); return uxg; }