⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 q4plate.cpp

📁 Finite element program for mechanical problem. It can solve various problem in solid problem
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include "q4plate.h"#include "global.h"#include "globmat.h"#include "genfile.h"#include "node.h"#include "element.h"#include "intpoints.h"#include <stdlib.h>#include <math.h>// w,fx,fyq4plate::q4plate (void){  long i,j;  nne=4;  ndofe=12;  tncomp=5;  napfun=2;  ned=4;  nned=2;  intordmm=3; intordb=2;  ssst=plate;    nb=2;  ncomp = new long [nb];  ncomp[0]=3;  ncomp[1]=2;  cncomp = new long [nb];  cncomp[0]=0;  cncomp[1]=3;  nip = new long* [nb];  intordsm = new long* [nb];  for (i=0;i<nb;i++){    nip[i] = new long [nb];    intordsm[i] = new long [nb];  }  nip[0][0]=9;  nip[0][1]=0;  nip[1][0]=0;  nip[1][1]=4;  tnip=0;  for (i=0;i<nb;i++){    for (j=0;j<nb;j++){      tnip+=nip[i][j];    }  }  intordsm[0][0]=3;  intordsm[0][1]=0;  intordsm[1][0]=0;  intordsm[1][1]=2;}q4plate::~q4plate (void){  long i;    for (i=0;i<nb;i++){    delete [] nip[i];    delete [] intordsm[i];  }  delete [] nip;  delete [] intordsm;  delete [] cncomp;  delete [] ncomp;}void q4plate::eleminit (long eid){  long ii,jj;  Mt->elements[eid].nb=nb;  Mt->elements[eid].intordsm = new long* [nb];  Mt->elements[eid].nip = new long* [nb];  for (ii=0;ii<nb;ii++){    Mt->elements[eid].intordsm[ii] = new long [nb];    Mt->elements[eid].nip[ii] = new long [nb];    for (jj=0;jj<nb;jj++){      Mt->elements[eid].intordsm[ii][jj]=intordsm[ii][jj];      Mt->elements[eid].nip[ii][jj]=nip[ii][jj];    }  }}/**   function approximates function defined by nodal values   @param xi,eta - coordinates on element   @param nodval - nodal values*/double q4plate::approx (double xi,double eta,vector &nodval){  double f;  vector bf(nne);    bf_lin_4_2d (bf.a,xi,eta);    scprd (bf,nodval,f);    return f;}/**   function assembles %matrix of transformation for Q4plate   %matrix reduces 16 DOFs to 12 DOFs      20.3.2002*/void q4plate::atd_matrix (matrix &atd,vector &x,vector &y,long eid){  double sx,sy;  matrix p(16,16),p1(16,16),ct(4,2);  vector dl(4);  long i,j,i1,i2,i3,i4,ii;  dl[0]=sqrt((x[1]-x[0])*(x[1]-x[0])+(y[1]-y[0])*(y[1]-y[0]));  dl[1]=sqrt((x[2]-x[1])*(x[2]-x[1])+(y[2]-y[1])*(y[2]-y[1]));  dl[2]=sqrt((x[3]-x[2])*(x[3]-x[2])+(y[3]-y[2])*(y[3]-y[2]));  dl[3]=sqrt((x[0]-x[3])*(x[0]-x[3])+(y[0]-y[3])*(y[0]-y[3]));  // matrix vector of sides {cos,sin}   ct[0][0]=(x[1]-x[0])/dl[0];  ct[0][1]=(y[1]-y[0])/dl[0];  ct[1][0]=(x[2]-x[1])/dl[1];  ct[1][1]=(y[2]-y[1])/dl[1];  ct[2][0]=(x[3]-x[2])/dl[2];  ct[2][1]=(y[3]-y[2])/dl[2];  ct[3][0]=(x[0]-x[3])/dl[3];  ct[3][1]=(y[0]-y[3])/dl[3];  fillm (0.0,p);  fillm (0.0,p1);  fillm (0.0,atd);  for (i=0;i<nne;i++){    i1=3*i;    i2=i1+1;    i3=i1+2;    i4=12+i;    p[i1][0]=1.;    p[i1][1]=x[i];    p[i1][2]=y[i];    p[i1][3]=x[i]*y[i];    p[i1][4]=x[i]*x[i];    p[i1][5]=y[i]*y[i];    p[i1][6]=x[i]*x[i]*y[i];    p[i1][7]=y[i]*y[i]*x[i];    p[i1][8]=x[i]*x[i]*x[i];    p[i1][9]=y[i]*y[i]*y[i];    p[i1][10]=x[i]*x[i]*x[i]*y[i];    p[i1][11]=y[i]*y[i]*y[i]*x[i];    p[i2][5]=y[i]*2.;    p[i2][6]=x[i]*x[i];    p[i2][7]=y[i]*x[i]*2.;    p[i2][9]=y[i]*y[i]*3.;    p[i2][10]=x[i]*x[i]*x[i];    p[i2][11]=y[i]*y[i]*x[i]*3.;    p[i2][14]=1.;    p[i2][15]=x[i];    p[i3][4]=-x[i]*2.;    p[i3][6]=-x[i]*y[i]*2.;    p[i3][7]=-y[i]*y[i];    p[i3][8]=-x[i]*x[i]*3.;    p[i3][10]=-x[i]*x[i]*y[i]*3.;    p[i3][11]=-y[i]*y[i]*y[i];    p[i3][12]=-1.;    p[i3][13]=-y[i];    ii=i+1;    if (ii > 3) ii=ii-4;        sy=(y[i]+y[ii])/2.;    sx=(x[i]+x[ii])/2.;    p[i4][1]= ct[i][0];    p[i4][2]= ct[i][1];    p[i4][3]= sy*ct[i][0]+sx*ct[i][1];    p[i4][12]=-ct[i][0];    p[i4][13]=-sy*ct[i][0];    p[i4][14]=-ct[i][1];    p[i4][15]=-sx*ct[i][1];  }  double *ee;  ee = new double [16*16];  for (i=0;i<16;i++){    for (j=0;j<16;j++){      ee[i*16+j]=0.0;    }    ee[i*16+i]=1.0;  }    gemp (p.a,p1.a,ee,16,16,10.e-5,1);//  invm (p,p1);  without move zerodiagonal  delete [] ee;/*    if(eid==122){    fprintf (Out,"\n\n p1");    for (i=0;i<16;i++){      fprintf (Out,"\n");      for (j=0;j<16;j++){      fprintf (Out," %le",p1[i][j]);	  }    }*/  for (i=0;i<p1.n;i++){    atd[i][0] =p1[i][0]  -p1[i][12]/dl[0]+p1[i][15]/dl[3];    atd[i][1] =p1[i][1]  -p1[i][12]*ct[0][1]/2.-p1[i][15]*ct[3][1]/2.;    atd[i][2] =p1[i][2]  +p1[i][12]*ct[0][0]/2.+p1[i][15]*ct[3][0]/2.;    atd[i][3] =p1[i][3]  -p1[i][13]/dl[1]+p1[i][12]/dl[0];    atd[i][4] =p1[i][4]  -p1[i][13]*ct[1][1]/2.-p1[i][12]*ct[0][1]/2.;    atd[i][5] =p1[i][5]  +p1[i][13]*ct[1][0]/2.+p1[i][12]*ct[0][0]/2.;    atd[i][6] =p1[i][6]  -p1[i][14]/dl[2]+p1[i][13]/dl[1];    atd[i][7] =p1[i][7]  -p1[i][14]*ct[2][1]/2.-p1[i][13]*ct[1][1]/2.;    atd[i][8] =p1[i][8]  +p1[i][14]*ct[2][0]/2.+p1[i][13]*ct[1][0]/2.;    atd[i][9] =p1[i][9]  -p1[i][15]/dl[3]+p1[i][14]/dl[2];    atd[i][10]=p1[i][10] -p1[i][15]*ct[3][1]/2.-p1[i][14]*ct[2][1]/2.;    atd[i][11]=p1[i][11] +p1[i][15]*ct[3][0]/2.+p1[i][14]*ct[2][0]/2.;  }  }/**  function assembles %matrix of base functions for w  (approximation of deflection)  20.3.2002*/void q4plate::bf_matrix (matrix &n,matrix &atd,vector &x,vector &y,vector &l){  double sx,sy;  int i;    // first point is in I Q  sx=(x[0]*(1+l[0])*(1+l[1])+x[1]*(1-l[0])*(1+l[1])+x[2]*(1-l[0])*(1-l[1])+x[3]*(1+l[0])*(1-l[1]))/4.;  sy=(y[0]*(1+l[0])*(1+l[1])+y[1]*(1-l[0])*(1+l[1])+y[2]*(1-l[0])*(1-l[1])+y[3]*(1+l[0])*(1-l[1]))/4.;  // base w  for (i=0;i<atd.n;i++){    n[0][i]=atd[0][i]+sx*atd[1][i]+sy*atd[2][i]+sx*sy*atd[3][i]+sx*sx*atd[4][i]      +sy*sy*atd[5][i]+sx*sx*sy*atd[6][i]+sy*sy*sx*atd[7][i]+sx*sx*sx*atd[8][i]      +sy*sy*sy*atd[9][i]+sx*sx*sx*sy*atd[10][i]+sx*sy*sy*sy*atd[11][i];  }  }/**   function assembles bending part of the geometrical %matrix of base functions Q4plate   20.3.2002*/void q4plate::geom_matrix_bending (matrix &gm,matrix &atd,vector &x,vector &y,vector &l){  double sx,sy;  int i;  // first point is in I Q  sx=(x[0]*(1+l[0])*(1+l[1])+x[1]*(1-l[0])*(1+l[1])+x[2]*(1-l[0])*(1-l[1])+x[3]*(1+l[0])*(1-l[1]))/4.;  sy=(y[0]*(1+l[0])*(1+l[1])+y[1]*(1-l[0])*(1+l[1])+y[2]*(1-l[0])*(1-l[1])+y[3]*(1+l[0])*(1-l[1]))/4.;  // original gm matrix, which would have to multiply by matrix atd  //  gm[0][4]=-2.;  gm[0][6]=-y*2.;  gm[0][8]=-x*6.;  gm[0][10]=-x*y*6.;  //  gm[1][5]=-2.;  gm[1][7]=-x*2.;  gm[1][9]=-y*6.;  gm[1][11]=-x*y*6.;  //  gm[2][6]=-x*4.; gm[2][7]=-y*4.; gm[2][10]=-x*x*6.; gm[2][11]=-y*y*6.; gm[2][13]=-1.; gm[2][15]=-1.;    for (i=0;i<atd.n;i++){    gm[0][i]=-2.*atd[4][i]-2.*sy*atd[6][i]-6.*sx*atd[8][i]-6.*sx*sy*atd[10][i];    gm[1][i]=-2.*atd[5][i]-2.*sx*atd[7][i]-6.*sy*atd[9][i]-6.*sx*sy*atd[11][i];    gm[2][i]=-4.*sx*atd[6][i]-4.*sy*atd[7][i]-6.*sx*sx*atd[10][i]-6.*sy*sy*atd[11][i]-atd[13][i]-atd[15][i];  }  }/**   function assembles shear part of the geometrical %matrix of base functions Q4plate   20.3.2002*/void q4plate::geom_matrix_shear (matrix &gm,matrix &atd,vector &x,vector &y,vector &l){  long i;  double sx,sy;    // first point is in I Q  sx=(x[0]*(1+l[0])*(1+l[1])+x[1]*(1-l[0])*(1+l[1])+x[2]*(1-l[0])*(1-l[1])+x[3]*(1+l[0])*(1-l[1]))/4.;  sy=(y[0]*(1+l[0])*(1+l[1])+y[1]*(1-l[0])*(1+l[1])+y[2]*(1-l[0])*(1-l[1])+y[3]*(1+l[0])*(1-l[1]))/4.;    for (i=0;i<atd.n;i++){    gm[0][i]=atd[1][i]+sy*atd[3][i]-atd[12][i]-sy*atd[13][i];    gm[1][i]=atd[2][i]+sx*atd[3][i]-atd[14][i]-sx*atd[15][i];  }}/**   function assembles stiffness matrices for bending and shear   function extracts components of the bending   part of stiffness %matrix of the material to the matrix db   20.3.2002*/void q4plate::dmatblock (matrix &dd,matrix &d,long ri, long ci, double t){  double c;    fillm (0.0,dd);  if (ri==0 && ci==0){  c=t*t*t;  dd[0][0] = c*d[0][0];  dd[0][1] = c*d[0][1];  dd[0][2] = c*d[0][2];  dd[1][0] = c*d[1][0];  dd[1][1] = c*d[1][1];  dd[1][2] = c*d[1][2];  dd[2][0] = c*d[2][0];  dd[2][1] = c*d[2][1];  dd[2][2] = c*d[2][2];  }  if (ri==1 && ci==1){    dd[0][0] = t*d[3][3]*5.0/6.0;  dd[0][1] = 0.0;    dd[1][0] = 0.0;                dd[1][1] = t*d[4][4]*5.0/6.0;  }}/**   function assembles transformation %matrix from local nodal coordinate   system to the global coordinate system x_g = T x_l      base vectors e1 and e2 have to contain 2 components   the components are in the midplane      @param nodes - element nodes   @param tmat - transformation %matrix      JK,*/void q4plate::transfmat (ivector &nodes,matrix &tmat){  long i,n,m;  n=nodes.n;  m=tmat.m;  for (i=0;i<m;i++){    tmat[i][i]=1.0;  }    for (i=0;i<n;i++){    if (Mt->nodes[nodes[i]].transf>0){      tmat[i*3+1][i*3+1]=Mt->nodes[nodes[i]].e1[0];  tmat[i*3+1][i*3+2]=Mt->nodes[nodes[i]].e2[0];      tmat[i*3+2][i*3+1]=Mt->nodes[nodes[i]].e1[1];  tmat[i*3+2][i*3+2]=Mt->nodes[nodes[i]].e2[1];    }  }}/**   function computes stiffness %matrix of Q4plate element      this function is used in plate elements (function is called   by function res_stiffness_matrix) and shell elements      @param eid - element id   @param ri,ci - row and column indeces   @param sm - stiffness %matrix   @param x,y - nodal coordinates      20.3.2002*/void q4plate::stiffness_matrix (long eid,long ri, long ci, matrix &sm,vector &x, vector &y){  long i,j,ii,jj,ipp;  double jac,a,a0,a1,thick;  ivector nodes(nne);  vector w,gp,l(2),t(nne);  matrix gm,dd,atd(16,12),d(5,5);  Mt->give_elemnodes (eid,nodes);  Mc->give_thickness (eid,nodes,t);  // translation to center it is necesary for w which in local coord. and no in relation  a=(x[0]+x[1]+x[2]+x[3])/4.;  x[0]=x[0]-a;  x[1]=x[1]-a;  x[2]=x[2]-a;  x[3]=x[3]-a;  a=(y[0]+y[1]+y[2]+y[3])/4.;  y[0]=y[0]-a;  y[1]=y[1]-a;  y[2]=y[2]-a;  y[3]=y[3]-a;  //     jakobian  a = (x[2]-x[0])*(y[3]-y[1])-(y[2]-y[0])*(x[3]-x[1]);  a0=-(x[3]-x[2])*(y[1]-y[0])+(y[3]-y[2])*(x[1]-x[0]);  a1=-(x[2]-x[1])*(y[3]-y[0])+(y[2]-y[1])*(x[3]-x[0]);  atd_matrix (atd,x,y,eid);  fillm (0.0,sm);//  ii=Mt->elements[eid].ipp[sip][0];  for (ii=0;ii<nb;ii++){    for (jj=0;jj<nb;jj++){      if (intordsm[ii][jj]==0)  continue;      allocv (intordsm[ii][jj],w); allocv (intordsm[ii][jj],gp);      allocm (ncomp[jj],ndofe,gm);      allocm (ncomp[ii],ncomp[jj],dd);      ipp=Mt->elements[eid].ipp[ri+ii][ci+jj];      gauss_points (gp.a,w.a,intordsm[ii][jj]);	  for (i=0;i<intordsm[ii][jj];i++){		 l[0]=gp[i];  		for (j=0;j<intordsm[ii][jj];j++){		  l[1]=gp[j];		  jac=(a+a0*l[0]+a1*l[1])/8.*w[i]*w[j];		  if(ii==0) geom_matrix_bending (gm,atd,x,y,l);		  else if(ii==1) geom_matrix_shear (gm,atd,x,y,l);		  Mm->matstiff (d,ipp);	      thick=approx (l[0],l[1],t);          dmatblock (dd, d,ii,jj,thick);          bdbjac (sm,gm,dd,gm,jac);		  ipp++;		}	  }      destrm (dd);  destrm (gm);  destrv (gp);  destrv (w);	}  }/*  fprintf (Out,"\n\n kontrola matice tuhosti");  for (i=0;i<ndofe;i++){    fprintf (Out,"\n");    for (j=0;j<ndofe;j++){fprintf (Out," %le",sm[i][j]);}  }  if(eid<3)  {    fprintf (Out,"\n\n diagonalni prvky desky, %ld,\n",eid);    for (i=0;i<ndofe;i++){fprintf (Out," %le",sm[i][i]);}  }*/  }/**   function assembles stiffness %matrix of plane stress rectangular   finite element with biquadratic approximation functions      @param eid - element id   @param sm - stiffness %matrix   */void q4plate::res_stiffness_matrix (long eid,matrix &sm){  long transf;  ivector nodes(nne);  vector x(nne),y(nne);  Mt->give_node_coord2d (x,y,eid);  Mt->give_elemnodes (eid,nodes);    stiffness_matrix (eid,0,0,sm,x,y);  //  transformation of stiffness matrix  transf = Mt->locsystems (nodes);  if (transf>0){    matrix tmat (ndofe,ndofe);    transfmat (nodes,tmat);    glmatrixtransf (sm,tmat);  }}/**   function computes initial stress stiffness %matrix of Q4 element      @param eid - element id   @param ri,ci - row and column indices   @param ism - i-s matrix      15.11.2003*/void q4plate::initstr_matrix (long eid,long ri,long ci,matrix &ism){  long i,i1,i2,j,j1,j2,k,ii,jj;  double jac,a,a0,a1,thick,xx,yy;  ivector nodes(nne);  vector w,gp,l(2),x(nne),y(nne),z(nne),sig(3),sx(3),sy(3),t(nne),dwx(12),dwy(12);  matrix tran(3,3),atd(16,12);// sig....... Axial stress  Mt->give_elemnodes (eid,nodes);  Mc->give_thickness (eid,nodes,t);// translation to center it is necesary for w which in local coord. and no in relation  a=(x[0]+x[1]+x[2]+x[3])/4.;  x[0]=x[0]-a;  x[1]=x[1]-a;  x[2]=x[2]-a;  x[3]=x[3]-a;  a=(y[0]+y[1]+y[2]+y[3])/4.;  y[0]=y[0]-a;  y[1]=y[1]-a;  y[2]=y[2]-a;  y[3]=y[3]-a;    //     jakobian  a = (x[2]-x[0])*(y[3]-y[1])-(y[2]-y[0])*(x[3]-x[1]);  a0=-(x[3]-x[2])*(y[1]-y[0])+(y[3]-y[2])*(x[1]-x[0]);  a1=-(x[2]-x[1])*(y[3]-y[0])+(y[2]-y[1])*(x[3]-x[0]);  atd_matrix (atd,x,y,eid);  fillm (0.0,ism);//  ii=Mt->elements[eid].ipp[sip][0];  for (ii=0;ii<nb;ii++){    for (jj=0;jj<nb;jj++){      if (intordsm[ii][jj]==0)  continue;      allocv (intordsm[ii][jj],w); allocv (intordsm[ii][jj],gp);	  for (i=0;i<intordsm[ii][jj];i++){		 l[0]=gp[i];  		for (j=0;j<intordsm[ii][jj];j++){		  l[1]=gp[j];  	      xx=(x[1]*(1-l[0])*(1+l[1])+x[2]*(1-l[0])*(1-l[1])+x[3]*(1+l[0])*(1-l[1]))/4.;	      yy=(y[1]*(1-l[0])*(1+l[1])+y[2]*(1-l[0])*(1-l[1])+y[3]*(1+l[0])*(1-l[1]))/4.;          for (k=0;k<dwx.n;k++){           dwx[i]=atd[1][k]+yy*atd[3][k]+2.*xx*atd[4][k]+2.*xx*yy*atd[6][k]+                  yy*yy*atd[7][k]+3.*xx*xx*atd[8][k]+3.*xx*xx*yy*atd[10][k]+yy*yy*yy*atd[11][k];           dwy[i]=atd[2][k]+xx*atd[3][k]+2.*yy*atd[5][k]+xx*xx*atd[6][k]+2.*yy*xx*                       atd[7][k]+3.*yy*yy*atd[9][k]+xx*xx*xx*atd[10][k]+3.*xx*yy*yy*atd[11][k];		  }    	      thick=approx (l[0],l[1],t);		  jac=(a+a0*l[0]+a1*l[1])/8.*w[i]*w[j]*thick/24.;          for (i2=0;i2<sig.n;i2++){            i1=3*i2-3;            for (j2=0;j2<nne;j2++){             j1=3*j2-3;             ism[i1][j1]=ism[i1][j1]+( dwx[i]*dwx[j]*sig[0]                +(dwx[i]*dwy[j]+dwx[j]*dwy[i])*sig[2]+dwy[i]*dwy[j]*sig[1] )*jac;			}		  }		}	  }      destrv (gp);  destrv (w);	}  }       		}/**   function computes load %matrix of the plate rectangular finite element   load vector is obtained after premultiplying load %matrix   by nodal load values      @param eid - number of element   @param lm - load %matrix      JK, 3.10.2006*/void q4plate::load_matrix (long eid,matrix &lm){  long i,j;  double jac,xi,eta,w1,w2,a,a0,a1,thick;  ivector nodes(nne);  vector x(nne),y(nne),w(intordmm),gp(intordmm),t(nne),l(2);  matrix atd(16,12),n(napfun,ndofe);    Mt->give_elemnodes (eid,nodes);  Mc->give_thickness (eid,nodes,t);    Mt->give_node_coord2d (x,y,eid);  gauss_points (gp.a,w.a,intordmm);  a=(x[0]+x[1]+x[2]+x[3])/4.;  x[0]=x[0]-a;  x[1]=x[1]-a;  x[2]=x[2]-a;  x[3]=x[3]-a;  a=(y[0]+y[1]+y[2]+y[3])/4.;  y[0]=y[0]-a;  y[1]=y[1]-a;  y[2]=y[2]-a;  y[3]=y[3]-a;  a = (x[2]-x[0])*(y[3]-y[1])-(y[2]-y[0])*(x[3]-x[1]);  a0=-(x[3]-x[2])*(y[1]-y[0])+(y[3]-y[2])*(x[1]-x[0]);  a1=-(x[2]-x[1])*(y[3]-y[0])+(y[2]-y[1])*(x[3]-x[0]);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -