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

📄 linhex_nb1.cpp

📁 Finite element program for mechanical problem. It can solve various problem in solid problem
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  double xi,eta,zeta,jac;  vector x(nne),y(nne),z(nne),w,gp;  matrix gm,d(tncomp,tncomp);    Mt->give_node_coord3d (x,y,z,eid);    fillm (0.0,sm);  for (ii=0;ii<nb;ii++){    allocm (ncomp[ii],ndofe,gm);    for (jj=0;jj<nb;jj++){      if (intordsm[ii][jj]==0)  continue;      allocv (intordsm[ii][jj],w);      allocv (intordsm[ii][jj],gp);            gauss_points (gp.a,w.a,intordsm[ii][jj]);            ipp=Mt->elements[eid].ipp[ri+ii][ci+jj];            for (i=0;i<intordsm[ii][jj];i++){	xi=gp[i];	for (j=0;j<intordsm[ii][jj];j++){	  eta=gp[j];	  for (k=0;k<intordsm[ii][jj];k++){	    zeta=gp[k];	    	    //  geometric matrices	    geom_matrix (gm,x,y,z,xi,eta,zeta,jac);	    	    Mm->matstiff (d,ipp);  ipp++;	    	    jac*=w[i]*w[j]*w[k];	    	    //  contribution to the stiffness matrix of the element	    bdbjac (sm,gm,d,gm,jac);	    	  }	}      }      destrv (gp);  destrv (w);    }    destrm (gm);  }    //  transformation of stiffness matrix  ivector nodes (nne);  Mt->give_elemnodes (eid,nodes);  transf = Mt->locsystems (nodes);  if (transf>0){    matrix tmat (ndofe,ndofe);    transf_matrix (nodes,tmat);    glmatrixtransf (sm,tmat);  }  }/**   function computes stiffness %matrix of quadrilateral finite element      function computes stiffness %matrix for geometrically nonlinear problems      @param lcid - load case id   @param eid - element id   @param ri,ci - row and column indices   @param sm - stiffness %matrix   @param x,y - vectors of nodal coordinates      JK, 21.9.2005*/void linhex::gnl_stiffness_matrix (long lcid,long eid,long ri,long ci,matrix &sm){  long i,j,k,ipp;  double xi,eta,zeta,jac,jac2;  ivector cn(ndofe);  vector w,gp,sig(tncomp),r(ndofe),x(nne),y(nne),z(nne);  matrix gm(tncomp,ndofe),grm(9,ndofe),d(tncomp,tncomp),s(9,9);    //  node coordinates  Mt->give_node_coord3d (x,y,z,eid);  //  code numbers of element  Mt->give_code_numbers (eid,cn.a);  //  nodal displacements  eldispl (lcid,eid,r.a,cn.a,ndofe);    //  component setting to zero  fillm (0.0,sm);    //  array for weights of integration points  allocv (intordsm[0][0],w);  //  array for coordinates of integration points  allocv (intordsm[0][0],gp);    //  coordinates and weights of integration points  gauss_points (gp.a,w.a,intordsm[0][0]);    //  number of the first integration point on element  ipp=Mt->elements[eid].ipp[ri][ci];      for (i=0;i<intordsm[0][0];i++){    xi=gp[i];    for (j=0;j<intordsm[0][0];j++){      eta=gp[j];      for (k=0;k<intordsm[0][0];k++){	zeta=gp[k];		//	//  linear stiffness matrix and inital deformation matrix	//		//  strain-displacement matrix	gngeom_matrix (gm,r,x,y,z,xi,eta,zeta,jac);		//  stiffness matrix of the material	Mm->matstiff (d,ipp);		jac*=w[i]*w[j]*w[k];		//  contribution to the stiffness matrix of the element	bdbjac (sm,gm,d,gm,jac);			//	//  initial stress matrix	//		//  gradient matrix	gnl_grmatrix (grm,x,y,z,xi,eta,zeta,jac2);		//  stresses	Mm->givestress (lcid,ipp,sig);		s[0][0]=sig[0];  s[0][1]=sig[5];  s[0][2]=sig[4];	s[1][0]=sig[5];  s[1][1]=sig[1];  s[1][2]=sig[3];	s[2][0]=sig[4];  s[2][1]=sig[3];  s[2][2]=sig[2];		s[3][3]=sig[0];  s[3][4]=sig[5];  s[3][5]=sig[4];	s[4][3]=sig[5];  s[4][4]=sig[1];  s[4][5]=sig[3];	s[5][3]=sig[4];  s[5][4]=sig[3];  s[5][5]=sig[2];		s[6][6]=sig[0];  s[6][7]=sig[5];  s[6][8]=sig[4];	s[7][6]=sig[5];  s[7][7]=sig[1];  s[7][8]=sig[3];	s[8][6]=sig[4];  s[8][7]=sig[3];  s[8][8]=sig[2];				//  contribution to the stiffness matrix of the element	bdbjac (sm,grm,s,grm,jac);		ipp++;      }    }  }    destrv (gp);  destrv (w);  }/**   function assembles resulting stiffness matrix of the element      @param lcid - load case id   @param eid - element id   @param sm - stiffness matrix      JK, 9.5.2002*/void linhex::res_stiffness_matrix (long lcid,long eid,matrix &sm){  gl_stiffness_matrix (eid,0,0,sm);  //gnl_stiffness_matrix (lcid,eid,0,0,sm);}/**   function computes mass matrix   @param eid - number of element   @param mm - mass matrix   19.7.2001*/void linhex::mass_matrix (long eid,matrix &mm){  long i,j,k;  double jac,xi,eta,zeta,rho;  ivector nodes (nne);  vector x(nne),y(nne),z(nne),w(intordmm),gp(intordmm),dens(nne);  matrix n(napfun,ndofe);    Mt->give_elemnodes (eid,nodes);  Mc->give_density (eid,nodes,dens);  Mt->give_node_coord3d (x,y,z,eid);  gauss_points (gp.a,w.a,intordmm);    fillm (0.0,mm);    for (i=0;i<intordmm;i++){    xi=gp[i];    for (j=0;j<intordmm;j++){      eta=gp[j];      for (k=0;k<intordmm;k++){	zeta=gp[k];		jac_3d (jac,x,y,z,xi,eta,zeta);		jac=fabs(jac);	bf_matrix (n,xi,eta,zeta);	rho = approx (xi,eta,zeta,dens);		jac*=w[i]*w[j]*w[k]*rho;		nnj (mm.a,n.a,jac,n.m,n.n);      }    }  }  }/**   function computes load matrix   @param eid - number of element   @param lm - load matrix      25.7.2001*/void linhex::load_matrix (long eid,matrix &lm){  long i,j,k;  double jac,xi,eta,zeta,w1,w2,w3;  ivector nodes (nne);  vector x(nne),y(nne),z(nne),w(intordmm),gp(intordmm);  matrix n(napfun,ndofe);    Mt->give_elemnodes (eid,nodes);  Mt->give_node_coord3d (x,y,z,eid);  gauss_points (gp.a,w.a,intordmm);    fillm (0.0,lm);    for (i=0;i<intordmm;i++){    xi=gp[i];  w1=w[i];    for (j=0;j<intordmm;j++){      eta=gp[j];  w2=w[j];      for (k=0;k<intordmm;k++){	zeta=gp[k];  w3=w[k];		jac_3d (jac,x,y,z,xi,eta,zeta);	bf_matrix (n,xi,eta,zeta);	jac*=w1*w2*w3;		//jac=fabs(jac);	//if (jac<0.0)  fprintf (stderr,"\n zaporny jakobian ve funkci load_matrix");	nnj (lm.a,n.a,jac,n.m,n.n);      }    }  }  }/**   function computes strains at integration points      @param lcid - load case id   @param eid - element id      JK*/void linhex::res_mainip_strains (long lcid,long eid){  long i;  ivector nodes(nne),cn(ndofe);  vector x(nne),y(nne),z(nne),r(ndofe),aux;  matrix tmat;    Mt->give_elemnodes (eid,nodes);  Mt->give_node_coord3d (x,y,z,eid);  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);    copyv (aux,r);    destrv (aux);    destrm (tmat);  }    gl_mainip_strains (lcid,eid,0,0,x,y,z,r);  //gnl_mainip_strains (lcid,eid,0,0,x,y,z,r);  }/**   function computes block of strains at integration points of element      @param lcid - load case id   @param eid - element id   @param ri - row index   @param ci - column index   @param x,y,z - %vectors of nodal coordinates   @param r - %vector of nodal displacements      10.5.2002*/void linhex::gl_mainip_strains (long lcid,long eid,long ri,long ci,vector &x,vector &y,vector &z,vector &r){  long i,j,k,ii,ipp;  double xi,eta,zeta,jac;  vector gp,w,eps;  matrix gm;    for (ii=0;ii<nb;ii++){        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];      for (j=0;j<intordsm[ii][ii];j++){	eta=gp[j];	for (k=0;k<intordsm[ii][ii];k++){	  zeta=gp[k];	  	  geom_matrix (gm,x,y,z,xi,eta,zeta,jac);	  	  mxv (gm,r,eps);	  	  Mm->storestrain (lcid,ipp,cncomp[ii],eps);	  	  ipp++;	}      }    }        destrm (gm);  destrv (w);  destrv (gp);    destrv (eps);  }}/**   function computes strains at integration points of element   function is used in geometrically linear problems      @param lcid - load case id   @param eid - element id   @param ri,ci - row and column indices   @param ii - number of block   @param x,y,z - arrays with node coordinates   @param r - %vector of nodal displacements      JK, 24.9.2005*/void linhex::gnl_mainip_strains (long lcid,long eid,long ri,long ci,vector &x,vector &y,vector &z,vector &r){  long i,j,k,ipp;  double xi,eta,zeta,jac,b11r,b12r,b13r,b21r,b22r,b23r,b31r,b32r,b33r;  vector gp,w,eps;  vector b11(ndofe),b12(ndofe),b13(ndofe),b21(ndofe),b22(ndofe),b23(ndofe),b31(ndofe),b32(ndofe),b33(ndofe);    allocv (intordsm[0][0],gp);  allocv (intordsm[0][0],w);  allocv (tncomp,eps);    gauss_points (gp.a,w.a,intordsm[0][0]);    ipp=Mt->elements[eid].ipp[ri][ci];  for (i=0;i<intordsm[0][0];i++){    xi=gp[i];    for (j=0;j<intordsm[0][0];j++){      eta=gp[j];      for (k=0;k<intordsm[0][0];k++){	zeta=gp[k];		bvectors (x,y,z,xi,eta,zeta,jac,b11,b12,b13,b21,b22,b23,b31,b32,b33);		scprd (b11,r,b11r);	scprd (b12,r,b12r);	scprd (b13,r,b13r);	scprd (b21,r,b21r);	scprd (b22,r,b22r);	scprd (b23,r,b23r);	scprd (b31,r,b31r);	scprd (b32,r,b32r);	scprd (b33,r,b33r);		eps[0] = b11r + 0.5*b11r*b11r + 0.5*b21r*b21r + 0.5*b31r*b31r;	eps[1] = b22r + 0.5*b12r*b12r + 0.5*b22r*b22r + 0.5*b32r*b32r;	eps[2] = b33r + 0.5*b13r*b13r + 0.5*b23r*b23r + 0.5*b33r*b33r;	eps[3] = b23r+b32r + b12r*b13r + b22r*b23r + b32r*b33r;	eps[4] = b31r+b13r + b13r*b11r + b23r*b21r + b33r*b31r;	eps[5] = b12r+b21r + b11r*b12r + b21r*b22r + b31r*b32r;			Mm->storestrain (lcid,ipp,eps);	ipp++;      }    }  }    destrv (eps);  destrv (w);  destrv (gp);  }/**   function computes strains in nodes of element      @param lcid - load case id   @param eid - element id      10.5.2002*/void linhex::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, 26.9.2004*/void linhex::nod_strains_comp (long lcid,long eid,double **stra){  long i,j;  double jac;  ivector cn(ndofe),nodes(nne);  vector x(nne),y(nne),z(nne),nxi(nne),neta(nne),nzeta(nne),r(ndofe),eps(tncomp),aux;  matrix tmat,gm(tncomp,ndofe);    //  node coordinates  Mt->give_node_coord3d (x,y,z,eid);  //  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);    copyv (aux,r);    destrv (aux);    destrm (tmat);  }    //  natural coordinates of element nodes  nodecoord (nxi,neta,nzeta);    //  loop over nodes  for (i=0;i<nne;i++){    //  geometric matrix    geom_matrix (gm,x,y,z,nxi[i],neta[i],nzeta[i],jac);    //  strain computation    mxv (gm,r,eps);        for (j=0;j<eps.n;j++){      stra[i][j]=eps[j];    }  }}/**   function computes strains on element      @param val - array containing strains on element   @param lcid - load case id   @param eid - element id      19.9.2002*//*  zruseno 26.9.2004void linhex::elem_strains (double **stra,long lcid,long eid,long ri,long ci){  long i,j,k,ii,ipp;  double xi,eta,zeta,*lsm,*lhs,*rhs;  vector nxi(nne),neta(nne),nzeta(nne),gp,w,eps,natcoord(3);  lsm = new double [16];  nodecoord (nxi,neta,nzeta);    for (ii=0;ii<nb;ii++){    allocv (intordsm[ii][ii],gp);    allocv (intordsm[ii][ii],w);    allocv (ncomp[ii],eps);    lhs = new double [ncomp[ii]*4];    rhs = new double [ncomp[ii]*4];    gauss_points (gp.a,w.a,intordsm[ii][ii]);        nullv (lsm,16);    nullv (rhs,ncomp[ii]*4);        ipp=Mt->elements[eid].ipp[ri+ii][ci+ii];    for (i=0;i<intordsm[ii][ii];i++){      xi=gp[i];      for (j=0;j<intordsm[ii][ii];j++){	eta=gp[j];	for (k=0;k<intordsm[ii][ii];k++){	  zeta=gp[k];	  	  Mm->givestrain (lcid,ipp,cncomp[ii],ncomp[ii],eps);	  	  natcoord[0]=xi;  natcoord[1]=eta;  natcoord[2]=zeta;	  matassem_lsm (lsm,natcoord);	  rhsassem_lsm (rhs,natcoord,eps);	  	  ipp++;	}      }    }            solve_lsm (lsm,lhs,rhs,Mp->zero,4,ncomp[ii]);    nodal_values (stra,nxi,neta,nzeta,lhs,3,cncomp[ii],ncomp[ii]);    delete [] lhs;  delete [] rhs;    destrv (eps);  destrv (w);  destrv (gp);  }    delete [] lsm;}*//**   function computes strains in arbitrary point on element      @param lcid - load case id   @param eid - element id   @param xi, eta, zeta - natural coordinates of the point   @param fi - first index   @param ncomp - number of components   @param eps - array containing strains      11.5.2002*/void linhex::appstrain (long lcid,long eid,double xi,double eta,double zeta,long fi,long ncomp,vector &eps){  long i,j,k;  ivector nod(nne);  vector nodval(nne);    if (ncomp != eps.n){    fprintf (stderr,"\n\n wrong interval of indices in function strain (%s, line %d).\n",__FILE__,__LINE__);    abort ();  }  Mt->give_elemnodes (eid,nod);  k=0;  for (i=fi;i<fi+ncomp;i++){    for (j=0;j<nne;j++){      nodval[j]=Mt->nodes[nod[j]].strain[lcid*tncomp+i];    }    eps[k]=approx (xi,eta,zeta,nodval);    k++;  }}/**

⌨️ 快捷键说明

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