📄 barelq3d.cpp
字号:
#include <math.h>#include "barelq3d.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"barelq3d::barelq3d (void){ long i; nne=3; ndofe=9; tncomp=1; napfun=1; 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;}barelq3d::~barelq3d (void){ long i; for (i=0;i<nb;i++){ delete [] nip[i]; delete [] intordsm[i]; } delete [] nip; delete [] intordsm; delete [] cncomp; delete [] ncomp;}void barelq3d::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,z - vectors of nodal coordinates JK, 28.9.2005*/void barelq3d::dirvect (vector &s,vector &x,vector &y,vector &z){ double d; s[0]=x[1]-x[0]; s[1]=y[1]-y[0]; s[2]=z[1]-z[0]; d=sqrt(s[0]*s[0]+s[1]*s[1]+s[2]*s[2]); 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; s[2]/=d;}/** function approximates function defined by nodal values @param xi,eta - coordinates on element @param nodval - nodal values JK, 28.9.2005*/double barelq3d::approx (double xi,vector &nodval){ double f; vector bf(nne); bf_quad_1d (bf.a,xi); scprd (bf,nodval,f); return f;}/** function returns strain-displacement (geometric) %matrix @param gm - strain-displacement (geometric) %matrix @param x - direction %vector @param s - direction %vector @param xi - natural coordinate @param jac - Jacobian JK, 28.9.2005*/void barelq3d::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[0]*s[2]; gm[0][3]= dx[1]*s[0]; gm[0][4]= dx[1]*s[1]; gm[0][5]= dx[1]*s[2]; gm[0][6]= dx[2]*s[0]; gm[0][7]= dx[2]*s[1]; gm[0][8]= dx[2]*s[2];}/** function computes local coordinates coordinates of nodes after transformatikon of the bar to the x axis @param x,y,z - vectors of nodal coordinates @param lx - %vector of the x coordinates after transformation JK, 28.9.2005*/void barelq3d::giveloccoord(vector &x,vector &y,vector &z,vector &lx){ double l; lx[0] = 0.0; l = sqrt((x[1]-x[0])*(x[1]-x[0]) + (y[1]-y[0])*(y[1]-y[0]) + (z[1]-z[0])*(z[1]-z[0])); lx[1] = l; l = sqrt((x[2]-x[0])*(x[2]-x[0]) + (y[2]-y[0])*(y[2]-y[0]) + (z[2]-z[0])*(z[2]-z[0])); lx[2] = l;}void barelq3d::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 barelq3d::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 barelq3d::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,ci - row and column indices @param sm - stiffness %matrix @param lx - %vector of x coodinates of nodes after bar transformation to the x axis @param s - direction %vector JK, 28.9.2005*/void barelq3d::stiffness_matrix (long eid,long ri,long ci,matrix &sm,vector &lx,vector &s){ long i,ipp; double a,xi,jac; vector w,gp,t(nne); matrix gm(tncomp,ndofe),d(tncomp,tncomp); // setting of stiffness matrix fillm (0.0,sm); // area of cross section Mc->give_area (eid,a); allocv (intordsm[0][0],w); allocv (intordsm[0][0],gp); gauss_points (gp.a,w.a,intordsm[0][0]); // integration point id ipp=Mt->elements[eid].ipp[ri][ci]; for (i=0;i<intordsm[0][0];i++){ xi=gp[i]; // strain-displacement matrix geom_matrix (gm,lx,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++; } }/** function computes stiffness %matrix of 3D bar element with quadratic shape functions @param eid - element id @param sm - stiffness %matrix JK, 28.9.2005*/void barelq3d::res_stiffness_matrix (long eid,matrix &sm){ long transf; ivector nodes(nne); vector gx(nne),gy(nne),gz(nne),x(nne),s(nne); matrix tmat (ndofe,ndofe); // nodal coordinates in global system Mt->give_node_coord3d (gx,gy,gz,eid); // computation of x coodinates in local system attached to the bar giveloccoord (gx,gy,gz,x); // computation of direction vector dirvect (s,gx,gy,gz); // stiffness matrix stiffness_matrix (eid,0,0,sm,x,s); // nodes on element Mt->give_elemnodes (eid,nodes); // transformation of stiffness matrix transf = Mt->locsystems (nodes); if (transf>0){ transf_matrix (nodes,tmat); glmatrixtransf (sm,tmat); }}void barelq3d::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 barelq3d::res_mainip_strains (long lcid,long eid){ vector aux,gx(nne),gy(nne),gz(nne),x(nne),s(3),r(ndofe); ivector cn(ndofe),nodes(nne); matrix tmat; // coordinates of nodes in global system Mt->give_node_coord3d (gx,gy,gz,eid); // coordinates of nodes in local system giveloccoord (gx,gy,gz,x); // direction vector dirvect (s,gx,gy,gz); // nodes of element Mt->give_elemnodes (eid,nodes); // code numbers 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); } // computation of strains mainip_strains (lcid,eid,0,0,x,s,r);}/** function computes strains at integration points of element @param lcid - load case id @param eid - element id @param ri - row index @param ci - column index @param lx - %vector of x-coordinates in local system @param s - direction %vector @param r - %vector of nodal displacements JK, 29.9.2005*/void barelq3d::mainip_strains (long lcid,long eid,long ri,long ci,vector &lx,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]); // integration point id ipp=Mt->elements[eid].ipp[ri+ii][ci+ii]; for (i=0;i<intordsm[ii][ii];i++){ xi=gp[i]; // strain-displacement matrix geom_matrix (gm,lx,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 at nodes of element @param lcid - load case id @param eid - element id @param ri,ci - row and column indices JK, 29.9.2005*/void barelq3d::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, 29.9.2005*/void barelq3d::nod_strains_comp (long lcid,long eid,double **stra){ long i,j; double jac; ivector cn(ndofe),nodes(nne); vector gx(nne),gy(nne),gz(nne),x(nne),s(3),nxi(nne),r(ndofe),eps(tncomp),aux; matrix tmat,gm(tncomp,ndofe); // node coordinates Mt->give_node_coord3d (gx,gy,gz,eid); // x-coordinates in local system giveloccoord (gx,gy,gz,x); // computation of direction vector dirvect (s,gx,gy,gz); // 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++){ // strain-displacement (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, 29.9.2005*/void barelq3d::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, 29.9.2005*/void barelq3d::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, 29.9.2005*/void barelq3d::strains (long lcid,long eid,long ri,long ci){ long i; 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 barelq3d::strains (file %s, line %d).\n",__FILE__,__LINE__); } } if (Mp->strainaver==0){ for (i=0;i<nne;i++){ delete [] stra[i]; } delete [] stra; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -