📄 quadhex.cpp
字号:
#include "quadhex.h"#include "linhex.h"#include "global.h"#include "globmat.h"#include "genfile.h"#include "node.h"#include "element.h"#include "loadcase.h"#include "intpoints.h"#include <stdlib.h>quadhex::quadhex (void){ long i,j; // number of nodes on element nne=20; // number of DOFs on element ndofe=60; // number of strain/stress components tncomp=6; // number of functions approximated napfun=3; // order of numerical integration of mass matrix intordmm=2; // number of edges on element ned=12; // number of nodes on one edge nned=3; // order of numerical integration on element edges (boundaries) intordb=3; // number of surfaces on element nsurf=6; // number of nodes on one surface nnsurf=8; // strain/stress state ssst=spacestress; // number of blocks (parts of geometric matrix) nb=1; // number of strain/stress components ncomp = new long [nb]; ncomp[0]=6; // 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]=27; // total number of integration points tnip=0; for (i=0;i<nb;i++){ for (j=0;j<nb;j++){ tnip+=nip[i][j]; } } intordsm[0][0]=3;}quadhex::~quadhex (void){ long i; for (i=0;i<nb;i++){ delete [] nip[i]; delete [] intordsm[i]; } delete [] nip; delete [] intordsm; delete [] cncomp; delete [] ncomp;}void quadhex::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 xi,eta,zeta - natural coordinates @param nodval - nodal values JK, 20.8.2001*/double quadhex::approx (double xi,double eta,double zeta,vector &nodval){ double f; vector bf(nne); bf_quad_hex_3d (bf.a,xi,eta,zeta); scprd (bf,nodval,f); return f;}/** function assembles %matrix of base functions @param n - %matrix of base functions @param xi,eta,zeta - coordinates JK, 16.8.2001*/void quadhex::bf_matrix (matrix &n,double xi,double eta,double zeta){ long i,j,k,l; vector bf(nne); fillm (0.0,n); bf_quad_hex_3d (bf.a,xi,eta,zeta); j=0; k=1; l=2; for (i=0;i<nne;i++){ n[0][j]=bf[i]; j+=3; n[1][k]=bf[i]; k+=3; n[2][l]=bf[i]; l+=3; }}/** function computes strain-displacement (geometric) %matrix @param gm - geometric %matrix @param x,y,z - vectors containing element node coordinates @param xi,eta,zeta - coordinates @param jac - Jacobian JK, 16.8.2001*/void quadhex::geom_matrix (matrix &gm,vector &x,vector &y,vector &z, double xi,double eta,double zeta,double &jac){ long i,j,k,l; vector dx(nne),dy(nne),dz(nne); dx_bf_quad_hex_3d (dx.a,xi,eta,zeta); dy_bf_quad_hex_3d (dy.a,xi,eta,zeta); dz_bf_quad_hex_3d (dz.a,xi,eta,zeta); derivatives_3d (dx,dy,dz,jac,x,y,z,xi,eta,zeta); fillm (0.0,gm); j=0; k=1; l=2; for (i=0;i<nne;i++){ gm[0][j]=dx[i]; gm[1][k]=dy[i]; gm[2][l]=dz[i]; gm[3][k]=dz[i]; gm[3][l]=dy[i]; gm[4][j]=dz[i]; gm[4][l]=dx[i]; gm[5][j]=dy[i]; gm[5][k]=dx[i]; j+=3; k+=3; l+=3; }}/** function assembles transformation %matrix from local nodal coordinate system to the global coordinate system x_g = T x_l @param nodes - nodes of element @param tmat - transformation %matrix JK*/void quadhex::transf_matrix (ivector &nodes,matrix &tmat){ long i,n,m; fillm (0.0,tmat); 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+0][i*3]=Mt->nodes[nodes[i]].e1[0]; tmat[i*3+1][i*3]=Mt->nodes[nodes[i]].e1[1]; tmat[i*3+2][i*3]=Mt->nodes[nodes[i]].e1[2]; tmat[i*3+0][i*3+1]=Mt->nodes[nodes[i]].e2[0]; tmat[i*3+1][i*3+1]=Mt->nodes[nodes[i]].e2[1]; tmat[i*3+2][i*3+1]=Mt->nodes[nodes[i]].e2[2]; tmat[i*3+0][i*3+2]=Mt->nodes[nodes[i]].e3[0]; tmat[i*3+1][i*3+2]=Mt->nodes[nodes[i]].e3[1]; tmat[i*3+2][i*3+2]=Mt->nodes[nodes[i]].e3[2]; } }}/** function computes stiffness %matrix of one element @param eid - number of element @param ri,ci - row and column indices @param sm - stiffness %matrix JK, 16.8.2001*/void quadhex::stiffness_matrix (long eid,long ri,long ci,matrix &sm){ long i,j,k,ipp; double xi,eta,zeta,jac; vector x(nne),y(nne),z(nne),w,gp; matrix gm(tncomp,ndofe),d(tncomp,tncomp); Mt->give_node_coord3d (x,y,z,eid); fillm (0.0,sm); allocv (intordsm[0][0],w); allocv (intordsm[0][0],gp); 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]; // geometric matrix geom_matrix (gm,x,y,z,xi,eta,zeta,jac); // stiffness matrix of the material Mm->matstiff (d,ipp); ipp++; jac*=w[i]*w[j]*w[k]; bdbjac (sm,gm,d,gm,jac); } } } destrv (gp); destrv (w); }/** function computes stiffness %matrix of one element @param eid - number of element @param sm - stiffness %matrix JK, 16.8.2001*/void quadhex::res_stiffness_matrix (long eid,matrix &sm){ long transf; ivector nodes (nne); stiffness_matrix (eid,0,0,sm); // transformation of stiffness matrix // (in the case of nodal coordinate systems) 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 mass %matrix @param eid - number of element @param mm - mass %matrix JK, 16.8.2001*/void quadhex::mass_matrix (long eid,matrix &mm){ long i,j,k; double jac,xi,eta,zeta,w1,w2,w3,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]; 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); rho = approx (xi,eta,zeta,dens); jac*=w1*w2*w3*rho; nnj (mm.a,n.a,jac,n.m,n.n); } } } }/** function computes mass %matrix @param eid - number of element @param mm - mass %matrix JK, 16.8.2001*/void quadhex::res_mass_matrix (long eid,matrix &mm){ long transf; ivector nodes(nne); mass_matrix (eid,mm); // transformation of mass matrix // (in the case of nodal coordinate systems) Mt->give_elemnodes (eid,nodes); transf = Mt->locsystems (nodes); if (transf>0){ matrix tmat (ndofe,ndofe); transf_matrix (nodes,tmat); glmatrixtransf (mm,tmat); }}/** function computes load %matrix @param eid - number of element @param lm - load %matrix JK, 16.8.2001*/void quadhex::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; nnj (lm.a,n.a,jac,n.m,n.n); } } } }/** function computes load %matrix @param eid - number of element @param lm - load %matrix JK, 16.8.2001*/void quadhex::res_load_matrix (long eid,matrix &lm){ long transf; ivector nodes(nne); load_matrix (eid,lm); // transformation of load matrix // (in the case of nodal coordinate systems) Mt->give_elemnodes (eid,nodes); transf = Mt->locsystems (nodes); if (transf>0){ matrix tmat (ndofe,ndofe); transf_matrix (nodes,tmat); glmatrixtransf (lm,tmat); }}/** function computes strains at integration points @param lcid - load case id @param eid - element id JK, modified 23.11.2006*/void quadhex::res_ip_strains (long lcid,long eid){ vector x(nne),y(nne),z(nne),r(ndofe),gp,w,eps,aux; ivector nodes(nne),cn(ndofe); matrix gm,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); lgvectortransf (aux,r,tmat); copyv (aux,r); destrv (aux); destrm (tmat); } ip_strains (lcid,eid,0,0,x,y,z,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 x,y,z - %vectors of nodal coordinates @param r - %vector of nodal displacements JK, 10.5.2002, modified 27.11.2006*/void quadhex::ip_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,aux; ivector nodes(nne),cn(ndofe); matrix gm,tmat; 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]; 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],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 JK, 27.9.2005*/void quadhex::nod_strains_ip (long lcid,long eid,long ri,long ci){ long i,j,ipp; ivector ipnum(nne),nod(nne); vector eps(tncomp); // numbers of integration points closest to nodes // (function is from the file GEFEL/ordering.cpp) ipp=Mt->elements[eid].ipp[ri][ci]; nodip_quadhex (ipp,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 in nodes of element @param lcid - load case id @param eid - element id @param stra - array for strain components stra[i][j] - the j-th strain component at the i-th node JK, 10.5.2002*/void quadhex::nod_strains_comp (long lcid,long eid,double **stra){ long i,j; double jac; vector x(nne),y(nne),z(nne),nxi(nne),neta(nne),nzeta(nne),eps(tncomp),r(ndofe),aux; ivector cn(ndofe),nodes(nne); matrix gm(tncomp,ndofe),tmat; // 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); lgvectortransf (aux,r,tmat); copyv (aux,r); destrv (aux); destrm (tmat); } // natural coordinates of element nodes // (function is from the file GEFEL/ordering.cpp) nodcoord_quadhex (nxi,neta,nzeta); // loop over nodes
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -