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

📄 cct.cpp

📁 Finite element program for mechanical problem. It can solve various problem in solid problem
💻 CPP
📖 第 1 页 / 共 3 页
字号:
#include "global.h"#include "cct.h"#include "gadaptivity.h"#include "globmat.h"#include "genfile.h"#include "element.h"#include "node.h"#include "intpoints.h"#include <stdlib.h>#include <math.h>cctelem::cctelem (void){  long i,j;  nne=3;  ndofe=9;  tncomp=5;  napfun=3;  ned=3;  nned=2;  intordmm=3;  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]=1;  nip[0][1]=0;  nip[1][0]=0;  nip[1][1]=1;    tnip=0;  for (i=0;i<nb;i++){    for (j=0;j<nb;j++){      tnip+=nip[i][j];    }  }    intordsm[0][0]=1;  intordsm[0][1]=0;  intordsm[1][0]=0;  intordsm[1][1]=1;}cctelem::~cctelem (void){  long i;    for (i=0;i<nb;i++){    delete [] intordsm[i];    delete [] nip[i];  }  delete [] intordsm;  delete [] nip;  delete [] cncomp;  delete [] ncomp;}void cctelem::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 areacoord - vector containing area coordinates   @param nodval - nodal values   28.3.2002*/double cctelem::approx (vector &areacoord,vector &nodval){  double f;  scprd (areacoord,nodval,f);  return f;}/**   function approximates function defined by nodal values   @param xi,eta - natural coordinates   @param nodval - nodal values*/double cctelem::approx_nat (double xi,double eta,vector &nodval){  double f;  vector areacoord(3);  areacoord[0]=xi;  areacoord[1]=eta;  areacoord[2]=1.0-areacoord[0]-areacoord[1];  scprd (areacoord,nodval,f);  return f;}/**   function assembles %matrix of approximation functions      @param n - %matrix of approximation functions   @param x,y - array containing node coordinates   @param areacoord - array of area coordinates      JK, 19.7.2001*/void cctelem::bf_matrix (matrix &n,vector &x,vector &y,vector &areacoord){  vector bf(9),sx(3),sy(3);    sx[0]=x[1]-x[0];  sx[1]=x[2]-x[1];  sx[2]=x[0]-x[2];  sy[0]=y[1]-y[0];  sy[1]=y[2]-y[1];  sy[2]=y[0]-y[2];    bf_cct (bf.a,areacoord.a,sx.a,sy.a);    fillm (0.0,n);    n[0][0]=bf[0];  n[0][1]=bf[1];  n[0][2]=bf[2];  n[0][3]=bf[3];  n[0][4]=bf[4];  n[0][5]=bf[5];  n[0][6]=bf[6];  n[0][7]=bf[7];  n[0][8]=bf[8];    n[1][1]=bf[0];  n[1][4]=bf[3];  n[1][7]=bf[6];  n[2][2]=bf[0];  n[2][5]=bf[3];  n[2][8]=bf[6];}/**   function assembles part of geometric %matrix      @param gm - geometric %matrix   @param x,y - array containing node coordinates   @param areacoord - area coordinates      JK, 19.7.2001*/void cctelem::geom_matrix_block (matrix &gm,long bi,vector &x,vector &y,vector &areacoord){  double det;  vector sx(3),sy(3),b(3),c(3),bf(9),dx(9),dy(9);  sx[0]=x[1]-x[0];  sx[1]=x[2]-x[1];  sx[2]=x[0]-x[2];  sy[0]=y[1]-y[0];  sy[1]=y[2]-y[1];  sy[2]=y[0]-y[2];    //  det is equal to double area of the element  det = (x[1]-x[0])*(y[2]-y[0])-(x[2]-x[0])*(y[1]-y[0]);      plsb (b.a,y.a,det);  plsc (c.a,x.a,det);    bf_cct (bf.a,areacoord.a,sx.a,sy.a);  dx_cct (dx.a,areacoord.a,b.a,sx.a,sy.a);  dy_cct (dy.a,areacoord.a,c.a,sx.a,sy.a);    fillm (0.0,gm);    if (bi==0){    gm[0][2]=dx[0];    gm[0][5]=dx[3];    gm[0][8]=dx[6];        gm[1][1]=0.0-dy[0];    gm[1][4]=0.0-dy[3];    gm[1][7]=0.0-dy[6];        gm[2][1]=0.0-dx[0];    gm[2][2]=dy[0];    gm[2][4]=0.0-dx[3];    gm[2][5]=dy[3];    gm[2][7]=0.0-dx[6];    gm[2][8]=dy[6];  }  if (bi==1){    gm[0][0]=dy[0];    gm[0][1]=dy[1]-bf[0];    gm[0][2]=dy[2];    gm[0][3]=dy[3];    gm[0][4]=dy[4]-bf[3];    gm[0][5]=dy[5];    gm[0][6]=dy[6];    gm[0][7]=dy[7]-bf[6];    gm[0][8]=dy[8];        gm[1][0]=dx[0];    gm[1][1]=dx[1];    gm[1][2]=dx[2]+bf[0];    gm[1][3]=dx[3];    gm[1][4]=dx[4];    gm[1][5]=dx[5]+bf[3];    gm[1][6]=dx[6];    gm[1][7]=dx[7];    gm[1][8]=dx[8]+bf[6];  }  }/**   function assembles geometric %matrix of the cct element      @param gm - geometric %matrix   @param x,y - array of node coordinates   @param areacoord - area coordinates      JK, 19.7.2001*/void cctelem::geom_matrix (matrix &gm,vector &x,vector &y,vector &areacoord){  double det;  vector sx(3),sy(3),b(3),c(3),bf(9),dx(9),dy(9);    sx[0]=x[1]-x[0];  sx[1]=x[2]-x[1];  sx[2]=x[0]-x[2];  sy[0]=y[1]-y[0];  sy[1]=y[2]-y[1];  sy[2]=y[0]-y[2];  //  det is equal to double area of the element  det = (x[1]-x[0])*(y[2]-y[0])-(x[2]-x[0])*(y[1]-y[0]);    plsb (b.a,y.a,det);  plsc (c.a,x.a,det);    bf_cct (bf.a,areacoord.a,sx.a,sy.a);  dx_cct (dx.a,areacoord.a,b.a,sx.a,sy.a);  dy_cct (dy.a,areacoord.a,c.a,sx.a,sy.a);  fillm (0.0,gm);    gm[0][2]=dx[0];  gm[0][5]=dx[3];  gm[0][8]=dx[6];    gm[1][1]=0.0-dy[0];  gm[1][4]=0.0-dy[3];  gm[1][7]=0.0-dy[6];    gm[2][1]=0.0-dx[0];  gm[2][2]=dy[0];  gm[2][4]=0.0-dx[3];  gm[2][5]=dy[3];  gm[2][7]=0.0-dx[6];  gm[2][8]=dy[6];    gm[3][0]=dy[0];  gm[3][1]=dy[1]-bf[0];  gm[3][2]=dy[2];  gm[3][3]=dy[3];  gm[3][4]=dy[4]-bf[3];  gm[3][5]=dy[5];  gm[3][6]=dy[6];  gm[3][7]=dy[7]-bf[6];  gm[3][8]=dy[8];    gm[4][0]=dx[0];  gm[4][1]=dx[1];  gm[4][2]=dx[2]+bf[0];  gm[4][3]=dx[3];  gm[4][4]=dx[4];  gm[4][5]=dx[5]+bf[3];  gm[4][6]=dx[6];  gm[4][7]=dx[7];  gm[4][8]=dx[8]+bf[6];}/**   function extracts blocks from stiffness %matrix of the material      @param ri,ci - row and column indices   @param d - stiffness %matrix of the material   @param dd - required block from stiffness %matrix of material   @param t - thickness of plate      JK, 19.7.2001*/void cctelem::dmatblock (long ri,long ci,matrix &d,matrix &dd,double t){  double c;    c=t*t*t;  fillm (0.0,dd);    if (ri==0 && ci==0){    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;  }}void cctelem::dmat (matrix &d,double t){  double c;    c=t*t*t;    d[0][0] = c*d[0][0];  d[0][1] = c*d[0][1];  d[0][2] = c*d[0][2];  d[1][0] = c*d[1][0];  d[1][1] = c*d[1][1];  d[1][2] = c*d[1][2];  d[2][0] = c*d[2][0];  d[2][1] = c*d[2][1];  d[2][2] = c*d[2][2];    d[3][3] = t*d[3][3]*5.0/6.0;  d[4][4] = t*d[4][4]*5.0/6.0;}/**   nutna kontrola   function assembles transformation %matrix */void cctelem::transf_matrix (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 cct element      @param eid - element id   @param ri,ci - row and column indices   @param sm - stiffness %matrix      JK, 19.7.2001*/void cctelem::stiffness_matrix (long eid,long ri,long ci,matrix &sm,vector &x,vector &y){  long i,ii,jj,ipp;  double jac,det,thick;  ivector nodes(nne);  vector l(3),t(nne),gp1,gp2,w,areacoord(3);  matrix gmr,gmc,dd,d(tncomp,tncomp);    Mt->give_elemnodes (eid,nodes);  Mc->give_thickness (eid,nodes,t);  //  det is equal to double area of the element  det = (x[1]-x[0])*(y[2]-y[0])-(x[2]-x[0])*(y[1]-y[0]);    fillm (0.0,sm);    for (ii=0;ii<nb;ii++){    allocm (ncomp[ii],ndofe,gmr);    for (jj=0;jj<nb;jj++){      if (intordsm[ii][jj]==0)  continue;      allocv (intordsm[ii][jj],w);      allocv (intordsm[ii][jj],gp1);      allocv (intordsm[ii][jj],gp2);            allocm (ncomp[jj],ndofe,gmc);      allocm (ncomp[ii],ncomp[jj],dd);            gauss_points_tr (gp1.a,gp2.a,w.a,intordsm[ii][jj]);            ipp=Mt->elements[eid].ipp[ri+ii][ci+jj];            for (i=0;i<intordsm[ii][jj];i++){	areacoord[0]=gp1[i];	areacoord[1]=gp2[i];	areacoord[2]=1.0-areacoord[0]-areacoord[1];		thick = approx (areacoord,t);	//  geometric matrix	geom_matrix_block (gmr,ii,x,y,areacoord);	geom_matrix_block (gmc,jj,x,y,areacoord);		//  matrix of stiffness of the material	Mm->matstiff (d,ipp);	dmatblock (ii,jj,d,dd,thick);		jac=w[i]*det;		//  contribution to the stiffness matrix of the element	bdbjac (sm,gmr,dd,gmc,jac);		ipp++;      }      destrm (dd);  destrm (gmc);  destrv (gp2);  destrv (gp1);  destrv (w);    }    destrm (gmr);  }}/**   function assembles resulting stiffness %matrix of the element      @param eid - element id   @param sm - stiffness %matrix      JK, 9.5.2002*/void cctelem::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);    transf_matrix (nodes,tmat);    glmatrixtransf (sm,tmat);  }}/**   function computes mass %matrix of the cct element      @param eid - element id   @param mm - mass %matrix      JK, 19.7.2001*/void cctelem::mass_matrix (long eid,matrix &mm,vector &x,vector &y){  long i;  double det,ww,thick,rho;  ivector nodes(nne);  vector l(3),gp1(intordmm),gp2(intordmm),w(intordmm),t(nne),dens(nne);  matrix n(3,ndofe);  Mt->give_elemnodes (eid,nodes);  Mc->give_thickness (eid,nodes,t);

⌨️ 快捷键说明

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