### 4.2. APDL codes for TEG simulation

ANSYS Parametric Design Language (APDL) is widely used for programed simulation. The following APDL codes have taken temperature variation of materials properties, thermal contact and thermal radiation (although its influence is very weak) into consideration. According to the practical requirements, the readers could use the code more concisely by neglecting certain physical effects. The unit referring to length is meter and the temperature unit is Celsius.

*! defining the TEG cell dimensions*

*ln=1.6e-3 ! n-type thermoelement thickness*

*lp=1.6e-3 ! p-type thermoelement thickness*

*wn=1.4e-3 ! p-type thermoelement width*

*wp=1.4e-3 ! p-type thermoelement width*

*d=1.0e-3 ! Distance between the thermoelements*

*hs=0.2e-3 ! copper strap thickness*

*hc=1e-3 !substrate thickness*

*! definition of several physical parameters*

*rsvx=1.8e-8 ! copper electrical resistivity*

*kx=200 ! copper thermal conductivity*

*kxs=24 !substrate thermal conductivity*

*T1=250 ! temperature of heat source*

*T0=30 ! temperature of heat sink*

*Toffst=273 ! temperature offset*

*! defining TEG output parameters and the load*

**dim,P0,array,1 ! defining P0 as the output power*

**dim,R0,array,1 ! defining R0 as the load*

**dim,Qh,array,1 ! defining Qh as the heat flow into the TEG cell*

**dim,I,array,1 ! defining I as the current*

**dim,enta,array,1 ! defining enta as the energy efficiency*

**vfill,R0(1),ramp,0.025 ! setting the load (Ohm)*

*! pre-processing before calculation, defining element type, building the structure and meshing*

*/PREP7*

*toffst,Toffst ! set temperature offset*

*et,1,226,110 ! 20-node thermoelectric brick element*

*et,2,shell57 ! shell57 element for radiation simulation*

*et,3,conta174 ! conta174 element for contact simulation*

*et,4,targe170 ! target170 element for contact simulation*

*keyopt,3,1,4 ! taking temperature and voltage as the degree of freedom*

*keyopt,3,9,0*

*keyopt,3,10,1*

*keyopt,4,2,0*

*keyopt,4,3,0*

*! Temperature data points*

*mptemp,1,25,50,75,100,125,150*

*mptemp,7,175,200,225,250,275,300*

*mptemp,13,325,350*

*! Seebeck coefficient of the n-type material (V·K−1)*

*mpdata,sbkx,1,1,-160e-6,-168e-6,-174e-6,-180e-6,-184e-6,-187e-6*

*mpdata,sbkx,1,7,-189e-6,-190e-6,-189e-6,-186.5e-6,-183e-6,-177e-6*

*mpdata,sbkx,1,13,-169e-6,-160e-6*

*! electrical resistivity of the n-type material (Ohm*m)*

*mpdata,rsvx,1,1,1.03e-5,1.06e-5,1.1e-5,1.15e-5,1.2e-5,1.28e-5*

*mpdata,rsvx,1,7,1.37e-5,1.49e-5,1.59e-5,1.67e-5,1.74e-5,1.78e-5*

*mpdata,rsvx,1,13,1.8e-5,1.78e-5*

*! thermal conductivity of the n-type material (m* K−1)*

*mpdata,kxx,1,1,1.183,1.22,1.245,1.265,1.265,1.25*

*mpdata,kxx,1,7,1.22,1.19,1.16,1.14,1.115,1.09*

*mpdata,kxx,1,13,1.06,1.03*

*! Seebeck coefficient of the p-type material (V·K−1)*

*mpdata,sbkx,2,1,200e-6,202e-6,208e-6,214e-6,220e-6,223e-6*

*mpdata,sbkx,2,7,218e-6,200e-6,180e-6,156e-6,140e-6,120e-6*

*mpdata,sbkx,2,13,101e-6,90e-6*

*! electrical resistivity of the p-type material (Ohm*m)*

*mpdata,rsvx,2,1,1.0e-5,1.08e-5,1.18e-5,1.35e-5,1.51e-5,1.7e-5*

*mpdata,rsvx,2,7,1.85e-5,1.98e-5,2.07e-5,2.143e-5,2.15e-5,2.1e-5*

*mpdata,rsvx,2,13,2.05e-5,2.0e-5*

*! thermal conductivity of the p-type material (m* K−1)*

*mpdata,kxx,2,1,1.08,1.135,1.2,1.25,1.257,1.22*

*mpdata,kxx,2,7,1.116,1.135,1.13,1.09,1.12,1.25*

*mpdata,kxx,2,13,1.5,2.025*

*! material property for cooper strap*

*mp,rsvx,3,rsvx*

*mp,kxx,3,kx*

*! material property for the substrate*

*mp,kxx,4,kxs*

*!radiation property for the p-n materials*

*mp,emis,5*

*! contact friction coefficient*

*mp,mu,6,0*

*! build the TEG cell structure*

*block,d/2,wn+d/2,-ln,0,,t*

*block,-(wp+d/2),-d/2,-lp,0,,t*

*block,d/2,wn+d/2,,hs,,t*

*block,-(wp+d/2),-d/2,,hs,,t*

*block,-d/2,d/2,,hs,,t*

*block,-(wp+d/2),-d/2,-lp,-(lp+hs),,t*

*block,d/2,wn+d/2,-ln,-(ln+hs),,t*

*block,-(wp+d/2),wn+d/2,hs,hs+hc,,t*

*block,-(wp+d/2),wn+d/2,-(lp+hs),-(lp+hs+hc),,t*

*! glue the copper strap and the substrate*

*vsel,s,loc,y,0,hs*

*vsel,a,loc,y,hs,hc+hs*

*vglue,all*

*allsel*

*vsel,s,loc,y,-lp-hs,-lp*

*vsel,a,loc,y,-lp-hs-hc,-lp-hs*

*vglue,all*

*allsel*

*! meshing the TEG cell structure*

*numcmp,all*

*mshape,0,3d*

*mshkey,1*

*type,1*

*mat,3*

*lsel,s,loc,x,-d/2,d/2*

*lsel,r,loc,y,0*

*lsel,r,loc,z,t*

*lesize,all,d/3*

*vsel,s,loc,x,-d/2,d/2*

*vsel,r,loc,y,0,hs*

*vsweep,all*

*allsel*

*esize,ww/3*

*type,1*

*mat,3*

*vsel,s,loc,y,0,hs*

*vsel,u,loc,x,-d/2,d/2*

*vsweep,all*

*vsel,s,loc,y,-lp-hs,-lp*

*vsweep,all*

*type,1*

*mat,1*

*vsel,s,loc,x,d/2,d/2+wn*

*vsel,r,loc,y,-ln,0*

*vmesh,all*

*mat,2*

*vsel,s,loc,x,-(wp+d/2),-d/2*

*vsel,r,loc,y,-lp,0*

*vmesh,all*

*type,1*

*mat,4*

*vsel,s,loc,y,hs,hs+hc*

*vsel,a,loc,y,-lp-hs-hc,-lp-hs*

*vsweep,all*

*allsel*

*! defining the contact parameters*

*r,5 ! selecting the thermal contact conductivity and resistivity*

*RMORE,*

*rmore,,7e5 ! setting the thermal contact conductivity*

*rmore,0.67e8,0.5 ! setting the thermal contact resistivity*

*! defining the contact layer between p-leg and upper copper strap*

*vsel,s,loc,y,0,hs*

*asel,s,ext*

*asel,r,loc,y,0*

*nsla,s,1*

*nsel,r,loc,x,-(wp+d/2),-d/2*

*type,3*

*mat,6*

*real,5*

*esurf*

*allsel*

*! defining the target layer between p-leg and upper copper strap*

*vsel,s,mat,,2*

*asel,s,ext*

*asel,r,loc,y,0*

*nsla,s,1*

*type,4*

*mat,6*

*esurf*

*allsel*

*! defining the contact layer between n-leg and upper copper strap*

*vsel,s,loc,y,0,hs*

*asel,s,ext*

*asel,r,loc,y,0*

*nsla,s,1*

*nsel,r,loc,x,d/2,d/2+wn*

*type,3*

*mat,6*

*real,5*

*esurf*

*allsel*

*! defining the target layer between n-leg and upper copper strap*

*vsel,s,mat,,1*

*asel,s,ext*

*asel,r,loc,y,0*

*nsla,s,1*

*type,4*

*mat,6*

*esurf*

*allsel*

*! defining the contact layer between p-leg and bottom copper strap*

*vsel,s,loc,y,-hs-lp,-lp*

*vsel,r,loc,x,-wp-d/2,-d/2*

*asel,s,ext*

*asel,r,loc,y,-lp*

*nsla,s,1*

*type,3*

*mat,6*

*real,5*

*esurf*

*allsel*

*! defining the target layer between p-leg and bottom copper strap*

*vsel,s,mat,,2*

*asel,s,ext*

*asel,r,loc,y,-lp*

*nsla,s,1*

*type,4*

*mat,6*

*esurf*

*allsel*

*! defining the contact layer between n-leg and bottom copper strap*

*vsel,s,loc,y,-hs-ln,-ln*

*vsel,r,loc,x,d/2,d/2+wn*

*asel,s,ext*

*asel,r,loc,y,-ln*

*nsla,s,1*

*type,3*

*mat,6*

*real,5*

*esurf*

*allsel*

*! defining the target layer between n-leg and bottom copper strap*

*vsel,s,mat,,1*

*asel,s,ext*

*asel,r,loc,y,-ln*

*nsla,s,1*

*type,4*

*mat,6*

*esurf*

*allsel*

*! defining the shell element for radiation simulation, outputting radiation matrix*

*! defining the shell element for copper strap*

*type,2*

*aatt,3,,2*

*asel,s,loc,x,-(wp+d/2),wn+d/2*

*asel,r,loc,y,0,hs*

*asel,u,loc,y,0*

*asel,u,loc,y,hs*

*amesh,all*

*allsel*

*asel,s,loc,x,-d/2,d/2*

*asel,r,loc,y,0*

*amesh,all*

*allsel*

*aatt,3,,2*

*asel,s,loc,x,-(wp+d/2),wn+d/2*

*asel,r,loc,y,-lp-hs,-lp*

*asel,u,loc,y,-lp*

*asel,u,loc,y,-lp-hs*

*amesh,all*

*allsel*

*aatt,4,,2*

*asel,s,loc,x,-d/2,d/2*

*asel,r,loc,y,-lp-hs*

*amesh,all*

*! defining the shell element for p-n thermoelements*

*allsel*

*aatt,5,,2*

*asel,s,loc,x,-(wp+d/2),wn+d/2*

*asel,r,loc,y,-lp,0*

*asel,u,loc,y,-lp*

*asel,u,loc,y,0*

*amesh,all*

*! defining the space node for radiation simulation*

*n,10000,0,0,3e-3*

*fini*

*! using radiation matrix method*

*/aux12*

*emis,3,1 ! setting the emissivity*

*emis,4,1*

*emis,5,1*

*allsel*

*geom,0*

*stef,5.68e-8 ! setting the Stefan-Boltzmann constant*

*vtype,hidden*

*space,10000*

*write,teg,sub ! outputting the radiation super element*

*fini*

*/prep7*

*! deleting the shell elements and the corresponding mesh*

*allsel*

*asel,s,type,,2*

*aclear,al*

*etdele,2*

*allsel*

*et,5,matrix50,1 ! defining radiation matrix element*

*! defining boundary conditions and the load*

*nsel,s,loc,y,hs+hc ! TEG cell hot side*

*cp,1,temp,all ! coupling of temperature degree of freedom*

*nh=ndnext(0) ! getting the master node*

*d,nh,temp,Th ! setting the temperature constraint to the hot side*

*nsel,all*

*nsel,s,loc,y,-(ln+hs+hc) ! selecting the TEG cell cold side*

*d,all,temp,Tc ! setting the temperature constraint to the cold side*

*nsel,s,loc,y,-(ln+hs),-ln*

*nsel,r,loc,x,d/2+wn*

*cp,3,volt,all ! electrical coupling*

*nn=ndnext(0) ! getting the master node*

*d,nn,volt,0 ! setting the ground connection node*

*nsel,all*

*nsel,s,loc,y,-(lp+hs),-lp*

*nsel,r,loc,x,-(wp+d/2)*

*cp,4,volt,all ! ! electrical coupling*

*np=ndnext(0) ! getting the master node*

*nsel,all*

*type,5*

*allsel*

*d,10000,temp,300 ! setting the temperature of the space node*

*se,teg,sub ! reading the radiation super element*

*et,6,CIRCU124,0 ! setting the load resistor element*

*fini*

*/prep7*

*! setting the load value and property*

*r,1,R0(1)*

*type,6*

*real,1*

*numcmp,all*

*e,np,nn*

*esel,s,type,,6*

*circu_num=elnext(0) !getting circuit element number*

*allsel*

*fini*

*! starting the calculation*

*/SOLU*

*antype,static ! solution type*

*cnvtol,heat,1,1.e-3 ! setting the converging value for heat condition*

*cnvtol,amps,1,1.e-3 ! setting the converging value for the current*

*neqit,50 ! calculation iteration step*

*solve ! starting solving*

*fini*

**get,P0(1),elem,circu_num,nmisc,1 ! getting the output power of the TEG cell*

**get,Qh(1),node,nh,rf,heat ! getting the heat flow into the TEG cell*

**get,I(1),elem,circu_num,smisc,2 ! getting the current*

**voper,enta,P0,div,Qh ! calculating the energy efficiency of the TEG cell*