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

📄 barelq2d.cpp

📁 Finite element program for mechanical problem. It can solve various problem in solid problem
💻 CPP
📖 第 1 页 / 共 2 页
字号:
#include <math.h>#include "barelq2d.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"barelq2d::barelq2d (void){  long i;  nne=3;  ndofe=6;  tncomp=1;  napfun=2;  tnip=3;  ssst = bar;  nb=1;  ncomp = new long [nb];  ncomp[0]=1;  cncomp = new long [nb];  cncomp[0]=0;  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]=3;  intordsm[0][0]=3;  zero=Mp->zero;}barelq2d::~barelq2d (void){  long i;  for (i=0;i<nb;i++){    delete [] nip[i];    delete [] intordsm[i];  }  delete [] nip;  delete [] intordsm;  delete [] cncomp;  delete [] ncomp;  delete [] nip;}void barelq2d::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 computes direction %vector      @param s - direction %vector   @param x,y - vectors of nodal coordinates      TKR podle JK, 31.10.2006*/void barelq2d::dirvect (vector &s,vector &x,vector &y){  double d;    s[0]=x[1]-x[0];  s[1]=y[1]-y[0];    d=sqrt(s[0]*s[0]+s[1]*s[1]);    if (d<zero){    fprintf (stderr,"\n\n zero norm of direction vector in function dirvect (file %s, line %d).\n",__FILE__,__LINE__);  }    s[0]/=d;  s[1]/=d;}/**   function approximates function defined by nodal values   @param xi,eta - coordinates on element   @param nodval - nodal values*/double barelq2d::approx (double xi,vector &nodval){  double f;  vector bf(nne);  bf_quad_1d (bf.a,xi);  scprd (bf,nodval,f);  return f;}/**   function returns geometric matrix   @param gm - geometric matrix   @param s,c - sin and cos   @param l - length of the bar   10.8.2001*/void barelq2d::geom_matrix (matrix &gm, vector &x,vector &s,double xi,double &jac){  vector dx(nne);    dx_bf_quad_1d (dx.a,xi);  derivatives_1d (dx, jac, x, xi);    fillm(0.0, gm);    gm[0][0]= dx[0]*s[0];  gm[0][1]= dx[0]*s[1];  gm[0][2]= dx[1]*s[0];  gm[0][3]= dx[1]*s[1];  gm[0][4]= dx[2]*s[0];  gm[0][5]= dx[2]*s[1];}void barelq2d::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;  l = sqr(x[2] - x[0]) + sqr(y[2] - y[0]);  l = sqrt(l);  lx[2] = l;}void barelq2d::give_glob_loc_tmat(vector &x, vector &y, matrix &tmat){  double c, s, l;  fillm(0.0, tmat);  l = sqrt(sqr(x[1]-x[0]) + sqr(y[1]-y[0]));  c = (x[1] - x[0]) / l;  s = (y[1] - y[0]) / l;  tmat[0][0] = tmat[2][2] = tmat[4][4] =  c;  tmat[0][1] = tmat[2][3] = tmat[4][5] =  s;  tmat[1][0] = tmat[3][2] = tmat[5][4] = -s;  tmat[1][1] = tmat[3][3] = tmat[5][5] =  c;}void barelq2d::give_loc_glob_tmat(vector &x, vector &y, matrix &tmat){  double c, s, l;  fillm(0.0, tmat);  l = sqrt(sqr(x[1]-x[0]) + sqr(y[1]-y[0]));  c = (x[1] - x[0]) / l;  s = (y[1] - y[0]) / l;  tmat[0][0] = tmat[2][2] = tmat[4][4] =  c;  tmat[0][1] = tmat[2][3] = tmat[4][5] = -s;  tmat[1][0] = tmat[3][2] = tmat[5][4] =  s;  tmat[1][1] = tmat[3][3] = tmat[5][5] =  c;}/**   transformation matrix x_g = T x_l*/void barelq2d::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][i*2]=Mt->nodes[nodes[i]].e1[0];    tmat[i*2][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];    }  }}/**   function computes stiffness matrix of one element   @param eid - element id   @param ri - row index   @param sm - stiffness matrix   10.8.2001*/void barelq2d::stiffness_matrix (long eid,long ri,long ci,matrix &sm,vector &x,vector &s){  long i,ipp;  double a,xi,jac;  ivector nodes (nne);  vector w,gp,t(nne);  matrix gm,d(tncomp,tncomp);  fillm (0.0,sm);  Mt->give_elemnodes (eid,nodes);  Mc->give_area (eid,a);  allocv (intordsm[0][0],w);  allocv (intordsm[0][0],gp);  gauss_points (gp.a,w.a,intordsm[0][0]);    allocm (ncomp[0],ndofe,gm);  ipp=Mt->elements[eid].ipp[ri][ci];    for (i=0;i<intordsm[0][0];i++){    xi=gp[i];    geom_matrix (gm, x, s, xi, jac);    //  matrix of stiffness of the material    Mm->matstiff (d,ipp);    jac*=a*w[i];    //  contribution to the stiffness matrix of the element    bdbjac (sm,gm,d,gm,jac);    ipp++;  }  }void barelq2d::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 (%s, line %d).\n",__FILE__,__LINE__);  }  Mc->give_area (eid,a);  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 barelq2d::res_mainip_strains (long lcid,long eid){  vector aux,gx(nne),gy(nne),x(nne),s(2),r(ndofe);  ivector cn(ndofe),nodes(nne);  matrix tmat;  Mt->give_node_coord2d (gx,gy,eid);  giveloccoord (gx,gy,x);  //  direction vector  dirvect (s,gx,gy);  Mt->give_elemnodes (eid,nodes);  Mt->give_code_numbers (eid,cn.a);  eldispl (lcid,eid,r.a,cn.a,ndofe);  //  transformation of displacement vector  long transf = Mt->locsystems (nodes);  if (transf>0){    allocv (ndofe,aux);    allocm (ndofe,ndofe,tmat);    transf_matrix (nodes,tmat);    //locglobtransf (aux,r,tmat);    lgvectortransf (aux,r,tmat);    copyv (aux,r);    destrv (aux);    destrm (tmat);  }    mainip_strains (lcid,eid,0,0,x,s,r);}/**   function computes strains in integration points of element   @param lcid - load case id   @param eid - element id   @param ri - row index   @param ci - column index   10.5.2002*/void barelq2d::mainip_strains (long lcid,long eid,long ri,long ci,vector &x,vector &s,vector &r){  long i,ii,ipp;  double xi,jac;  vector gp,w,eps;  matrix gm;  for (ii=0;ii<nb;ii++){    if (intordsm[ii][ii]==0)  continue;    allocv (intordsm[ii][ii],gp);    allocv (intordsm[ii][ii],w);    allocv (ncomp[ii],eps);    allocm (ncomp[ii],ndofe,gm);    gauss_points (gp.a,w.a,intordsm[ii][ii]);    ipp=Mt->elements[eid].ipp[ri+ii][ci+ii];    for (i=0;i<intordsm[ii][ii];i++){      xi=gp[i];      geom_matrix (gm,x,s,xi,jac);      mxv (gm,r,eps);      Mm->storestrain (lcid,ipp,cncomp[ii],ncomp[ii],eps);      ipp++;    }    destrm (gm);  destrv (eps);  destrv (w);  destrv (gp);  }}/**   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 barelq2d::nod_strains_ip (long lcid,long eid,long ri,long ci){  long i,j;  ivector ipnum(nne),nod(nne);  vector eps(tncomp);    //  numbers of integration points closest to nodes  nodipnum (eid,ri,ci,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 nodal strains directly      @param lcid - load case id   @param eid - element id   @param stra - array for strain components      JK, 25.9.2004*/void barelq2d::nod_strains_comp (long lcid,long eid,double **stra){  long i,j;  double jac;  ivector cn(ndofe),nodes(nne);  vector gx(nne),gy(nne),x(nne),s(2),nxi(nne),r(ndofe),eps(tncomp),aux;  matrix tmat,gm(tncomp,ndofe);    //  node coordinates  Mt->give_node_coord2d (gx,gy,eid);  giveloccoord (gx,gy,x);  //  computation of direction vector  dirvect (s,gx,gy);  //  node numbers  Mt->give_elemnodes (eid,nodes);  //  code numbers of the element  Mt->give_code_numbers (eid,cn.a);  //  nodal displacements  eldispl (lcid,eid,r.a,cn.a,ndofe);    //  transformation of displacement vector  long transf = Mt->locsystems (nodes);  if (transf>0){    allocv (ndofe,aux);    allocm (ndofe,ndofe,tmat);    transf_matrix (nodes,tmat);    //locglobtransf (aux,r,tmat);    lgvectortransf (aux,r,tmat);    copyv (aux,r);    destrv (aux);    destrm (tmat);  }    //  natural coordinates of element nodes  nodecoord (nxi);    //  loop over nodes  for (i=0;i<nne;i++){    //  geometric matrix    geom_matrix (gm,x,s,nxi[i],jac);    //  strain computation    mxv (gm,r,eps);        for (j=0;j<eps.n;j++){      stra[i][j]=eps[j];    }  }}/**   function computes all strain components at all integration points      @param lcid - load case id   @param eid - element id      JK, 26.9.2004*/void barelq2d::res_allip_strains (long lcid,long eid){  //  all strain components at all integration points  allip_strains (lcid,eid,0,0);}/**   function assembles all values at all integration points      @param lcid - load case id   @param eid - element id   @param ri,ci - row and column indices      JK, 25.9.2004*/void barelq2d::allip_strains (long lcid,long eid,long ri,long ci){  //  blocks of strain components at integration points  res_mainip_strains (lcid,eid);}/**   function computes strains at strain points      @param lcid - load case id   @param eid - element id   @param ri,ci - row and column indices      JK*/void barelq2d::strains (long lcid,long eid,long ri,long ci){  long i,naep,ncp,sid;  double **stra;  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__);  }  }  if (Mp->strainaver==0){    for (i=0;i<nne;i++){      delete [] stra[i];    }    delete [] stra;  }}/**   function assembles natural coordinates of nodes of element   @param xi - array containing natural coordinates xi   10.5.2002*/void barelq2d::nodecoord (vector &xi){  xi[0] = -1.0;  xi[1] =  1.0;  xi[2] =  0.0;}/**   function returns numbers of integration point closest to element nodes      @param eid - element id   @param ri,ci - row and column indices   @param ipnum - array of numbers      JK, 25.9.2004*/void barelq2d::nodipnum (long eid,long ri,long ci,ivector &ipnum){  long i;    i=Mt->elements[eid].ipp[ri][ci];  ipnum[0]=i;  ipnum[1]=i+2;  ipnum[2]=i+1;}/**   function computes stresses at integration points      @param lcid - load case id   @param eid - element id      JK

⌨️ 快捷键说明

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