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 putch(unsigned char x) { unsigned char i=0; for(i=0;i<5;i++) { disp1(font[x-32][i]); _delay_us(FONT_DELAY); } disp1(0); _delay_us(FONT_DELAY); }
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"); }
void CTriangleObj::DrawPickingObjectLine(const int objid) { Vector3i* m_pTriangle = (Vector3i*)m_pPolygon; int i, name = objid; SETUP_PICKING_GLENV(); //draw the triangles first; glPushName(-1); glBegin(GL_TRIANGLES); for (i=0; i<m_nPolygonCount; i++){ for (int t=0; t<3; t++){ const int p = m_pTriangle[i][t]; glVertex3dv(&m_pVertex[p].x); } } glEnd(); glPopName(); //then, draw the lines if (this->m_pPolyNorm==NULL) this->ComputePolygonNormals(); const float offset = this->GetHiddenLineOffset(); glLineWidth(2); for (i=0; i<m_nPolygonCount; i++, name+=3){ Vector3f &norm = m_pPolyNorm[i]; Vector3f disp = norm * offset; Vector3d disp1(disp.x, disp.y, disp.z); Vector3I & tri = m_pTriangle[i]; DrawPickinigTrianleEdge(m_pVertex, disp1, tri.x, tri.y, tri.z, name); } }
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; }
//***********main**************************** void main( void ) { DDRC=0xFF; DDRB=0x3F; DDRD=0xF0; //USART_Init ( MYUBRR ); //Konfig10bitADC(); //InitTIMER(); InitINT(); RTCInit(); sei(); disp1(128); _delay_ms(500); _delay_ms(500); _delay_ms(500); _delay_ms(500); while(1); while(0) { /* //_delay_ms(100); // LCDWriteIntXY(0,0,temp100,4); LCDWriteIntXY(0,0,aaa,2); LCDWriteStringXY(2,0,":"); LCDWriteIntXY(3,0,min,2); LCDWriteStringXY(5,0,":"); LCDWriteIntXY(6,0,sec,2); LCDWriteIntXY(10,0,temp100/100,3); LCDData(0b11011111); LCDWriteStringXY(14,0,"C"); _delay_ms(100); if(sec==60){sec=0; min++;} if(min==60){min=0; hour++;} if(hour==24){hour=0;} */ } }
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); }
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; }
// 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(); }
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; }
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); }
/*************************************** * * * _Machine * * * ***************************************/ static int _Machine(V_INSTR **value) { int machineOps = 0; while (PC->instr != MChalt) { switch (PC->instr) { case MChalt: disp("MChalt\n"); break; case MCret: disp("MCret\n"); D_assert(D1->instr == DPcont); PC = D1->info.code; popD1(); break; case MCgoto: disp("MCgoto\n"); PC = PC->info.code; break; case MCsave: disp("MCsave\n"); pushD4(DPpr0); D4->info.pr0 = V; PC++; break; case MCswap: disp("MCswap\n") D_assert(D4->instr == DPpr0); R0 = D4->info.pr0; D_set(D4->instr = DPpr1); D4->info.pr1 = V; V = R0; PC++; break; case MCpair: disp("MCpair\n"); D_assert(D4->instr == DPpr0 || D4->instr == DPpr1); allocH2(1, R0); V_set(R0->instr = MCpair); R0->info.pair.v0 = V; R0->info.pair.v1 = D4->info.pr1; V = R0; popD4(); PC++; break; case MCp0: disp("P0\n"); V_assert(V->instr == MCpair); V = V->info.pair.v0; PC++; break; case MCp1: disp("P1\n"); V_assert(V->instr == MCpair); V = V->info.pair.v1; PC++; break; case MCmap_prod: disp("map_prod\n"); V_assert(V->instr == MCpair); allocH2(1, R0); V_set(R0->instr = MCpair); R0->info.pair.v1 = V->info.pair.v1; /* <_, v2> */ R1 = V->info.pair.v0; /* <v0, v1> */ V_assert(R1->instr == MCpair); R0->info.pair.v0 = R1->info.pair.v0; /* build <v0, v2> */ pushD4(DPpr0); D4->info.pr0 = R0; allocH2(1, R0); V_set(R0->instr = MCpair); /* build <v1, v2> */ R1 = V->info.pair.v0; /* <v0, v1> */ R0->info.pair.v0 = R1->info.pair.v1; /* <v1, _> */ R0->info.pair.v1 = V->info.pair.v1; /* <v1, v2> */ V = R0; /* set V to point to <v1, v2> */ PC++; break; case MCpr: disp("pr\n"); V_assert(V->instr == MCpair); pushD4(DPpr1); D4->info.pr1 = V->info.pair.v1; /* pr1(v1, c) */ PC++; break; case MCfunc: disp("FUNC\n"); pushD1(DPcont); D1->info.code = PC + 1; PC = PC->info.funcCode; break; case MCparm: disp1("`%d\n",PC->info.macroParm); pushD1(DPcont); D1->info.code = PC + 1; pushD3(DPreload); D3->info.reload = A; V_assert(A->info.macroFrame.arg); PC = A->info.macroFrame.arg[PC->info.macroParm]; A = A->info.macroFrame.prev; break; case MCldparm: disp("MCldparm\n"); V_assert(PC->info.macroList); allocH1(1, R0); V_set(R0->instr = MCldparm); R0->info.macroFrame.prev = A; R0->info.macroFrame.arg = PC->info.macroList; A = R0; PC++; break; case MCreload: disp("MCreload\n"); D_assert(D3->instr == DPreload); A = D3->info.reload; popD3(); PC++; break; case MCunload: disp("MCunload\n"); A = A->info.macroFrame.prev; PC++; break; case MCbang: disp("!\n"); V = _BANG; PC++; break; case MCcons: /* Build the cons structure in the Heap */ disp1("cons{%d}\n", PC->info.structorPosn); allocH1(1, R0); V_set(R0->instr = PC->instr); R0->info.structor.posn = PC->info.structorPosn; R0->info.structor.next = V; V = R0; PC++; break; case MCjump: disp("jump\n"); pushD1(DPcont); D1->info.code = PC + 1; PC = PC->info.code; break; case MCjumpc: /* [#@] */ disp ("jump?..."); V_assert (V->instr == MCpair); if (V->info.pair.v0->info.at.next && /* AT TAG? */ V->info.pair.v0->info.at.posn == 0) { disp ("no\n"); /* YES---DON'T JUMP */ V = V->info.pair.v0->info.at.next; /* ...AND STRIP THE TAG */ PC++; } else { disp ("yes\n"); /* NO--- JUMP */ pushD1 (DPcont); D1->info.code = PC + 1; PC = PC->info.code; } break; case MCinduct: disp("induct\n"); pushD1(DPcont); D1->info.code = PC + 1; V_assert(V->instr == MCpair); allocH2(1, R0); R1 = V->info.pair.v0; V_assert(R1->instr == MCcons); V_set(R0->instr = MCpair); R0->info.pair.v1 = V->info.pair.v1; R0->info.pair.v0 = R1->info.structor.next; V = R0; PC = PC->info.inductCode; PC = PC + (R1->info.structor.posn - 1); /* [#@] */ break; case MCalloc: disp1("alloc{%d}\n", PC->info.allocNum); allocH1(PC->info.allocNum, R0); PC++; break; case MCldmacroframe: /* load the current macro frame into the record */ disp("ldmacroframe\n"); V_set(R0->instr = MCldmacroframe); R0->info.recMacroFrame.frame = A; R0->info.recMacroFrame.gcId = PC->info.numDestrs; R1 = V; V = R0; R0++; PC++; break; case MCbclosure: disp("bclosure\n"); V_set(R0->instr = MCbclosure); R0->info.closure.v = R1; R0->info.closure.c = PC->info.closureCode; PC++; break; case MCclosure: disp("closure\n"); R0++; V_set(R0->instr = MCclosure); R0->info.closure.v = R1; R0->info.closure.c = PC->info.closureCode; PC++; break; case MCdest: disp1("dest(%d)\n",PC->info.structorPosn); pushD3(DPreload); D3->info.reload = A; pushD1(DPcont); D1->info.code = PC + 1; V_assert(V->instr == MCldmacroframe); R1 = V; R0 = V + PC->info.structorPosn; V_assert((R0->instr == MCclosure) || (R0->instr == MCbclosure)); A = V->info.recMacroFrame.frame; V = R0->info.closure.v; PC = R0->info.closure.c; break; /* * [H-O] ADDED THIS CASE/INSTRUCTION FOR H-O DESTRUCTORS (IE. WE NOW CAN * DESTRUCT WITH INPUT): * */ case MCdestHO: disp1 ("destHO(%d)\n", PC->info.structorPosn); pushD3 (DPreload); D3->info.reload = A; pushD1 (DPcont); D1->info.code = PC + 1; V_assert (V->instr == MCpair); allocH2 (1, R0); V_set (R0->instr = MCpair); R0->info.pair.v0 = V->info.pair.v0; R1 = V->info.pair.v1; V = R0; V_assert (R1->instr == MCldmacroframe); A = R1->info.recMacroFrame.frame; R0 = R1 + PC->info.structorPosn; V_assert ( (R0->instr == MCclosure) || (R0->instr == MCbclosure)); V->info.pair.v1 = R0->info.closure.v; PC = R0->info.closure.c; break; case MCmkupdate: disp("mkupdate\n"); V_assert((R1[1].instr == MCclosure) || (R1[1].instr == MCbclosure)); pushD2(DPupdate); D2->info.update = R1; PC++; break; case MCupdate: disp("update\n"); D_assert(D2->instr == DPupdate); if (D2->info.update) { /* see if we need to do the update */ R0 = D2->info.update + PC->info.updateClo; V_assert((R0->instr == MCclosure) || (R0->instr == MCbclosure)); R0->info.closure.v = V; R0->info.closure.c = &_RET; } popD2(); D_assert(D1->instr == DPcont); PC = D1->info.code; popD1(); break; case MCint: /* [BI] BUILTIN INTEGERS */ disp1 ("int{%d}\n", PC->info.i); allocH1 (1, V); V_set (V->instr = PC->instr); V->info.integer.i = PC->info.i; V->info.integer.gcId = GC_BUILTIN; PC++; break; case MCchar: /* [BI] BUILTIN CHARACTERS */ disp1 ("char{%d}\n", (int)PC->info.c); allocH1 (1, V); V_set (V->instr = PC->instr); V->info.character.c = (int)PC->info.c; V->info.character.gcId = GC_BUILTIN; PC++; break; case MCadd: /* [BI] BUILTIN ADDITION */ disp ("add\n"); allocH1 (1, R0); V_set (R0->instr = MCint); R0->info.integer.i = V->info.pair.v0->info.integer.i + V->info.pair.v1->info.integer.i; R0->info.integer.gcId = GC_BUILTIN; V = R0; PC++; break; case MCsub: /* [BI] BUILTIN SUBTRACTION */ disp ("sub\n"); allocH1 (1, R0); V_set (R0->instr = MCint); R0->info.integer.i = V->info.pair.v0->info.integer.i - V->info.pair.v1->info.integer.i; R0->info.integer.gcId = GC_BUILTIN; V = R0; PC++; break; case MCmul: /* [BI] BUILTIN MULTIPLICATION */ disp ("mul\n"); allocH1 (1, R0); V_set (R0->instr = MCint); R0->info.integer.i = V->info.pair.v0->info.integer.i * V->info.pair.v1->info.integer.i; R0->info.integer.gcId = GC_BUILTIN; V = R0; PC++; break; case MCdiv: /* [BI] BUILTIN DIVISION */ disp ("div\n"); allocH1 (1, R0); V_set (R0->instr = MCint); R0->info.integer.i = V->info.pair.v0->info.integer.i / V->info.pair.v1->info.integer.i; R0->info.integer.gcId = GC_BUILTIN; V = R0; PC++; break; case MCmod: /* [BI] BUILTIN MODULUS OPERATION (INTEGER DIVISION REMAINDER) */ disp ("mod\n"); allocH1 (1, R0); V_set (R0->instr = MCint); R0->info.integer.i = V->info.pair.v0->info.integer.i % V->info.pair.v1->info.integer.i; R0->info.integer.gcId = GC_BUILTIN; V = R0; PC++; break; case MClt_int: /* [BI] [#@] BUILTIN LESS-THAN FOR INTEGERS */ disp ("lt_int\n"); allocH1 (1, R0); V_set (R0->instr = MCcons); R0->info.structor.posn = (V->info.pair.v0->info.integer.i < V->info.pair.v1->info.integer.i) + 1; R0->info.structor.next = NULL; V = R0; PC++; break; case MCle_int: /* [BI] [#@] BUILTIN LESS-THAN-EQUAL-TO FOR INTEGERS */ disp ("le_int\n"); allocH1 (1, R0); V_set (R0->instr = MCcons); R0->info.structor.posn = (V->info.pair.v0->info.integer.i <= V->info.pair.v1->info.integer.i) + 1; R0->info.structor.next = NULL; V = R0; PC++; break; case MCgt_int: /* [BI] [#@] BUILTIN GREATER-THAN FOR INTEGERS */ disp ("gt_int\n"); allocH1 (1, R0); V_set (R0->instr = MCcons); R0->info.structor.posn = (V->info.pair.v0->info.integer.i > V->info.pair.v1->info.integer.i) + 1; R0->info.structor.next = NULL; V = R0; PC++; break; case MCge_int: /* [BI] [#@] BUILTIN GREATER-THAN-EQUAL-TO FOR INTEGERS */ disp ("ge_int\n"); allocH1 (1, R0); V_set (R0->instr = MCcons); R0->info.structor.posn = (V->info.pair.v0->info.integer.i >= V->info.pair.v1->info.integer.i) + 1; R0->info.structor.next = NULL; V = R0; PC++; break; case MCeq_int: /* [BI] [#@] BUILTIN EQUALITY FOR INTEGERS */ disp ("eq_int\n"); allocH1 (1, R0); V_set (R0->instr = MCcons); R0->info.structor.posn = (V->info.pair.v0->info.integer.i == V->info.pair.v1->info.integer.i) + 1; R0->info.structor.next = NULL; V = R0; PC++; break; case MClt_char: /* [BI] [#@] BUILTIN LESS-THAN FOR CHARACTERS */ disp ("lt_char\n"); allocH1 (1, R0); V_set (R0->instr = MCcons); R0->info.structor.posn = (V->info.pair.v0->info.character.c < V->info.pair.v1->info.character.c) + 1; R0->info.structor.next = NULL; V = R0; PC++; break; case MCle_char: /* [BI] [#@] BUILTIN LESS-THAN-EQUAL-TO FOR CHARACTERS */ disp ("le_char\n"); allocH1 (1, R0); V_set (R0->instr = MCcons); R0->info.structor.posn = (V->info.pair.v0->info.character.c <= V->info.pair.v1->info.character.c) + 1; R0->info.structor.next = NULL; V = R0; PC++; break; case MCgt_char: /* [BI] [#@] BUILTIN GREATER-THAN FOR CHARACTERS */ disp ("gt_char\n"); allocH1 (1, R0); V_set (R0->instr = MCcons); R0->info.structor.posn = (V->info.pair.v0->info.character.c > V->info.pair.v1->info.character.c) + 1; R0->info.structor.next = NULL; V = R0; PC++; break; case MCge_char: /* [BI] [#@] BUILTIN GREATER-THAN-EQUAL-TO FOR CHARACTERS */ disp ("ge_char\n"); allocH1 (1, R0); V_set (R0->instr = MCcons); R0->info.structor.posn = (V->info.pair.v0->info.character.c >= V->info.pair.v1->info.character.c) + 1; R0->info.structor.next = NULL; V = R0; PC++; break; case MCeq_char: /* [BI] [#@] BUILTIN EQUALITY FOR CHARACTERS */ disp ("eq_char\n"); allocH1 (1, R0); V_set (R0->instr = MCcons); R0->info.structor.posn = (V->info.pair.v0->info.character.c == V->info.pair.v1->info.character.c) + 1; R0->info.structor.next = NULL; V = R0; PC++; break; case MCcode: /* [BI] BUILTIN CHARACTER-TO-ASCII-CODE CONVERSION */ disp ("code\n"); allocH1 (1, R0); V_set (R0->instr = MCint); R0->info.integer.i = (int)V->info.character.c; R0->info.integer.gcId = GC_BUILTIN; V = R0; PC++; break; case MCdecode: /* [BI] BUILTIN ASCII-CODE-TO-CHARACTER CONVERSION */ disp ("decode\n"); allocH1 (1, R0); V_set (R0->instr = MCchar); R0->info.character.c = (char)V->info.integer.i; R0->info.character.gcId = GC_BUILTIN; V = R0; PC++; break; case MCat: /* [#@] */ disp ("@\n"); allocH1 (1, R0); V_set (R0->instr = PC->instr); R0->info.at.next = V; R0->info.at.posn = 0; V = R0; PC++; break; case MCinvalid: printMsg(FATAL_MSG, "invalid instruction in machine."); break; default: printMsg(FATAL_MSG, "invalid machine instruction."); break; } } *value = V; return(machineOps); }
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; }
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 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 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 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; }