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

📄 barel2d.cpp

📁 Finite element program for mechanical problem. It can solve various problem in solid problem
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include <math.h>#include "barel2d.h"#include "global.h"#include "globmat.h"#include "genfile.h"#include "element.h"#include "node.h"#include "intpoints.h"#include "loadcase.h"barel2d::barel2d (void){  long i;    //  number nodes on element  nne=2;  //  number of DOFs on element  ndofe=4;  //  number of strain/stress components  tncomp=1;  //  number of functions approximated  napfun=2;  ssst = bar;    //  number of blocks (parts of geometric matrix)  nb=1;    //  number of strain/stress components  ncomp = new long [nb];  ncomp[0]=1;    //  cumulative number of components approximated  cncomp = new long [nb];  cncomp[0]=0;    //  number of integration points  //  order of numerical integration of stiffness matrix  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]=1;  //  total number of integration points  tnip=0;  for (i=0;i<nb;i++){    tnip+=nip[i][i];  }    intordsm[0][0]=1;}barel2d::~barel2d (void){  long i;    for (i=0;i<nb;i++){    delete [] nip[i];    delete [] intordsm[i];  }  delete [] nip;  delete [] intordsm;  delete [] cncomp;  delete [] ncomp;}void barel2d::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 assembles strain-displacement (geometric) %matrix   geometric %matrix is in global coordinate system   @param gm - geometric %matrix   @param s,c - sin and cos   @param l - length of the bar      JK, 10.8.2001*/void barel2d::geom_matrix (matrix &gm,double s,double c,double l){  gm[0][0]=c/l*(-1.0);  gm[0][1]=s/l*(-1.0);  gm[0][2]=c/l;  gm[0][3]=s/l;}/**   function assembles strain-displacement (geometric) %matrix   geometric %matrix is in local element coordinate system      @param gm - geometric %matrix   @param x - node coordinates   @param jac - Jacobian      JK, 10.8.2001*/void barel2d::geom_matrix (matrix &gm,vector &x,double &jac){  double xi=0.0,n[2];  vector dx(2);    dx_bf_lin_1d (n);  derivatives_1d (dx,jac,x,xi);    gm[0][0]= dx[0];  gm[0][2]= dx[1];}/**   function approximates function defined by nodal values   @param xi - natural coordinate   @param nodval - nodal values      JK*/double barel2d::approx (double xi,vector &nodval){  double f;  vector bf(nne);  bf_lin_1d (bf.a,xi);  scprd (bf,nodval,f);  return f;}/**   function assembles transformation %matrix from local nodal coordinate   system to the global coordinate system x_g = T x_l      @param nodes - array containing node numbers   @param tmat - transformation %matrix      JK, 3.2.2002*/void barel2d::transf_matrix (ivector &nodes,matrix &tmat){  long i;  fillm (0.0,tmat);    for (i=0;i<tmat.m;i++){    tmat[i][i]=1.0;  }    for (i=0;i<nodes.n;i++){    if (Mt->nodes[nodes[i]].transf>0){      tmat[i*2+0][i*2]=Mt->nodes[nodes[i]].e1[0];   tmat[i*2+0][i*2+1]=Mt->nodes[nodes[i]].e2[0];      tmat[i*2+1][i*2]=Mt->nodes[nodes[i]].e1[1];   tmat[i*2+1][i*2+1]=Mt->nodes[nodes[i]].e2[1];    }  }}//void barel2d::bar_transf_matrix (vector &x, matrix &tmat,vector &gx,vector &gy)void barel2d::tran_mat (vector &x, matrix &tmat,vector &gx,vector &gy){  long i,j;  vector gv(2*gx.n),lv(2*gx.n);    j=0;  for (i=0;i<gx.n;i++){    gv[j]=gx[i];  j++;    gv[j]=gy[i];  j++;  }    //globloctransf (gv,lv,tmat);  glvectortransf (gv,lv,tmat);    for (i=0;i<gx.n;i++){    x[i]=lv[i*2];  }}/**   function computes stiffness %matrix of twodimensional bar element      @param eid - element id   @param ri,ci - row and column indices   @param sm - stiffness %matrix   JK, 10.8.2001*/void barel2d::stiffness_matrix (long eid,long ri,long ci,matrix &sm){  long ipid,transf;  double c,s,l,a,jac;  ivector nodes (nne);  vector x(nne),y(nne);  matrix gm(tncomp,ndofe),d(tncomp,tncomp),tmat (ndofe,ndofe);  fillm (0.0,sm);    //  node cooridnates  Mt->give_node_coord2d (x,y,eid);    //  length of the element  l=sqrt ((x[1]-x[0])*(x[1]-x[0])+(y[1]-y[0])*(y[1]-y[0]));  if (l<Mp->zero){    fprintf (stderr,"\n\n zero length of the %ld truss element",eid);    fprintf (stderr,"\n in function barel2d::stiffness_matrix (barel2d.cpp).\n");  }    s=(y[1]-y[0])/l;  c=(x[1]-x[0])/l;    //  geometric matrix  geom_matrix (gm,s,c,l);  //  number of first integration point on element  ipid=Mt->elements[eid].ipp[ri][ci];  //  stiffness matrix of material  Mm->matstiff (d,ipid);  //  area of bar cross-section  Mc->give_area (eid,a);  jac=a*l;  //  B^T D B  bdbj (sm.a,gm.a,d.a,jac,gm.m,gm.n);    //  transformation of stiffness matrix from global coordinate system  //  to the local nodal systems  Mt->give_elemnodes (eid,nodes);  transf = Mt->locsystems (nodes);  if (transf>0){    transf_matrix (nodes,tmat);    glmatrixtransf (sm,tmat);  }  }/**   function computes stiffness %matrix of twodimensional bar element      @param eid - element id   @param sm - stiffness %matrix      JK, 10.8.2001*/void barel2d::res_stiffness_matrix (long eid,matrix &sm){  stiffness_matrix (eid,0,0,sm);}/**   function computes mass %matrix of twodimensional bar element      @param eid - element id   @param mm - mass %matrix   JK, 10.8.2001*/void barel2d::mass_matrix (long eid,matrix &mm){  double l,a,rho;  vector x(nne),y(nne);    fillm (0.0,mm);  Mt->give_node_coord2d (x,y,eid);  //  length of the element  l=sqrt ((x[1]-x[0])*(x[1]-x[0])+(y[1]-y[0])*(y[1]-y[0]));  if (l<Mp->zero){    fprintf (stderr,"\n\n zero length of the %ld truss element",eid);    fprintf (stderr,"\n in function barel2d::mass_matrix (file %s, line %d).\n",__FILE__,__LINE__);  }    //  area of bar cross-section  Mc->give_area (eid,a);  //  density of the material  Mc->give_densitye (eid,rho);    mm[0][0]=a*rho*l*1.0/3.0;  mm[0][1]=0.0;  mm[0][2]=a*rho*l*1.0/6.0;  mm[0][3]=0.0;  mm[1][0]=0.0;  mm[1][1]=a*rho*l*1.0/3.0;  mm[1][2]=0.0;  mm[1][3]=a*rho*l*1.0/6.0;  mm[2][0]=a*rho*l*1.0/6.0;  mm[2][1]=0.0;  mm[2][2]=a*rho*l*1.0/3.0;  mm[2][3]=0.0;  mm[3][0]=0.0;  mm[3][1]=a*rho*l*1.0/6.0;  mm[3][2]=0.0;  mm[3][3]=a*rho*l*1.0/3.0;}void barel2d::giveloccoord(vector &x, vector &y,vector &lx){  double l;  lx[0] = 0.0;  l = sqr(x[1] - x[0]) + sqr(y[1] - y[0]);  l = sqrt(l);  lx[1] = l;}/**   function computes strain at integration points      @param lcid - load case id   @param eid - element id      JK*/void barel2d::res_ip_strains (long lcid,long eid){  long transf;  vector x(nne),r(ndofe),aux(ndofe);  ivector cn(ndofe),nodes(nne);  matrix tmat(ndofe,ndofe);    //  code numbers  Mt->give_code_numbers (eid,cn.a);  //  displacements at element nodes  eldispl (lcid,eid,r.a,cn.a,ndofe);    //  transformation of displacement vector  //  (in the case of nodal coordinate systems)  Mt->give_elemnodes (eid,nodes);  transf = Mt->locsystems (nodes);  if (transf>0){    transf_matrix (nodes,tmat);    lgvectortransf (aux,r,tmat);    copyv (aux,r);  }    ip_strains (lcid,eid,0,0,r);  }/**   function computes strains at integration point   @param lcid - load case id   @param eid - element id   @param ri - row index   @param ci - column index   @param r - nodal displacements      10.5.2002*/void barel2d::ip_strains (long lcid,long eid,long ri,long ci,vector &r){  long ipid;  double s,c,l;  vector x(nne),y(nne),eps(tncomp);  matrix gm(tncomp,ndofe);  //  node cooridnates  Mt->give_node_coord2d (x,y,eid);    //  length of the element  l=sqrt ((x[1]-x[0])*(x[1]-x[0])+(y[1]-y[0])*(y[1]-y[0]));  if (l<Mp->zero){    fprintf (stderr,"\n\n zero length of the %ld truss element",eid);    fprintf (stderr,"\n in function barel2d::ip_strains (barel2d.cpp).\n");  }    s=(y[1]-y[0])/l;  c=(x[1]-x[0])/l;  //  geometrix matrix  geom_matrix (gm,s,c,l);  //  strain computation  mxv (gm,r,eps);  //  strain storage  ipid=Mt->elements[eid].ipp[ri][ci];  Mm->storestrain (lcid,ipid,eps);}/**   function computes strains in nodes of element   @param lcid - load case id   @param eid - element id   @param ri,ci - row and column indices   10.5.2002*/void barel2d::nod_strains_ip (long lcid,long eid,long ri,long ci){  long i,j,ipid;  ivector ipnum(nne),nod(nne);  vector eps(tncomp);    //  numbers of integration points closest to nodes  //  (function is from the file GEFEL/ordering.cpp)  ipid=Mt->elements[eid].ipp[ri][ci];  nodip_bar (ipid,intordsm[0][0],ipnum);    //  node numbers of the element  Mt->give_elemnodes (eid,nod);    for (i=0;i<nne;i++){    //  strains at the closest integration point    Mm->givestrain (lcid,ipnum[i],eps);        //  storage of strains to the node    j=nod[i];    Mt->nodes[j].storestrain (lcid,0,eps);  }}/**   function computes strains at strain points      @param lcid - load case id   @param eid - element id   @param ri,ci - row and column indices      JK*/void barel2d::strains (long lcid,long eid,long ri,long ci){  long i,naep,ncp,sid;  vector coord,eps;  switch (Mm->stra.tape[eid]){  case nowhere:{    break;  }  case intpts:{    //allip_strains (lcid,eid,ri,ci);    break;  }  case enodes:{    nod_strains_ip (lcid,eid,ri,ci);    break;  }  case userdefined:{    //  number of auxiliary element points    naep = Mm->stra.give_naep (eid);    ncp = Mm->stra.give_ncomp (eid);    sid = Mm->stra.give_sid (eid);    allocv (ncp,eps);    allocv (1,coord);    for (i=0;i<naep;i++){      Mm->stra.give_aepcoord (sid,i,coord);      if (Mp->strainaver==0)	//appval (coord[0],0,ncp,eps,stra);      if (Mp->strainaver==1)	//appstrain (lcid,eid,coord[0],0,ncp,eps);      Mm->stra.storevalues(lcid,eid,i,eps);    }    destrv (eps);    destrv (coord);    break;  }  default:{    fprintf (stderr,"\n\n unknown strain point is required in function barelq2d::strains (file %s, line %d).\n",__FILE__,__LINE__);  }  }}

⌨️ 快捷键说明

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