!
!     CalculiX - A 3-dimensional finite element program
!              Copyright (C) 1998-2005 Guido Dhondt
!
!     This program is free software; you can redistribute it and/or
!     modify it under the terms of the GNU General Public License as
!     published by the Free Software Foundation(version 2);
!     
!
!     This program is distributed in the hope that it will be useful,
!     but WITHOUT ANY WARRANTY; without even the implied warranty of 
!     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
!     GNU General Public License for more details.
!
!     You should have received a copy of the GNU General Public License
!     along with this program; if not, write to the Free Software
!     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
!
      subroutine linel(ithermal,mattyp,beta,al,um,am1,eth,elas,
     &  icmdl,exx,eyy,ezz,exy,exz,eyz,stre)
!
!     calculates stresses for linear elastic materials
!
!     icmdl=2: stress corresponding to thermal strain =
!             stress at total strain - stress at mechanical strain
!     icmdl=3: stress at mechanical strain
!
      implicit none
!
      integer ithermal,mattyp,icmdl
!
      real*8 beta(6),al,um,am1,eth(6),elas(21),exx,eyy,ezz,
     &  exy,exz,eyz,stre(6),fxx,fyy,fzz,fxy,fxz,fyz
!
      if(icmdl.eq.2) then
         if((ithermal.eq.1).or.(ithermal.eq.3)) then
            if(mattyp.eq.1) then
               beta(1)=((3.d0*al+2.d0*um)*eth(1))+
     &              beta(1)
               beta(2)=((3.d0*al+2.d0*um)*eth(1))+
     &              beta(2)
               beta(3)=((3.d0*al+2.d0*um)*eth(1))+
     &              beta(3)
            elseif(mattyp.eq.2) then
               beta(1)=(elas(1)*eth(1)+
     &              elas(2)*eth(2)+
     &              elas(4)*eth(3))+beta(1)
               beta(2)=(elas(2)*eth(1)+
     &              elas(3)*eth(2)+
     &              elas(5)*eth(3))+beta(2)
               beta(3)=(elas(4)*eth(1)+
     &              elas(5)*eth(2)+
     &              elas(6)*eth(3))+beta(3)
            elseif(mattyp.eq.3) then
               beta(1)=elas(1)*eth(1)+
     &              elas(2)*eth(2)+
     &              elas(4)*eth(3)+
     &              elas(7)*eth(4)+
     &              elas(11)*eth(5)+
     &              elas(16)*eth(6)+beta(1)
               beta(2)=elas(2)*eth(1)+
     &              elas(3)*eth(2)+
     &              elas(5)*eth(3)+
     &              elas(8)*eth(4)+
     &              elas(12)*eth(5)+
     &              elas(17)*eth(6)+beta(2)
               beta(3)=elas(4)*eth(1)+
     &              elas(5)*eth(2)+
     &              elas(6)*eth(3)+
     &              elas(9)*eth(4)+
     &              elas(13)*eth(5)+
     &              elas(18)*eth(6)+beta(3)
               beta(4)=elas(7)*eth(1)+
     &              elas(8)*eth(2)+
     &              elas(9)*eth(3)+
     &              2.d0*(elas(10)*eth(4)+
     &              elas(14)*eth(5)+
     &              elas(19)*eth(6))+beta(4)
               beta(5)=elas(11)*eth(1)+
     &              elas(12)*eth(2)+
     &              elas(13)*eth(3)+
     &              2.d0*(elas(14)*eth(4)+
     &              elas(15)*eth(5)+
     &              elas(20)*eth(6))+beta(5)
               beta(6)=elas(16)*eth(1)+
     &              elas(17)*eth(2)+
     &              elas(18)*eth(3)+
     &              2.d0*(elas(19)*eth(4)+
     &              elas(20)*eth(5)+
     &              elas(21)*eth(6))+beta(6)
            endif
         endif
!   
!     calculating the stress from the mechanical strain
!
      elseif(icmdl.eq.3) then
         if((ithermal.eq.1).or.(ithermal.eq.3)) then
            fxx=exx-eth(1)
            fyy=eyy-eth(2)
            fzz=ezz-eth(3)
            fxy=exy-2.d0*eth(4)
            fxz=exz-2.d0*eth(5)
            fyz=eyz-2.d0*eth(6)
         else
            fxx=exx
            fyy=eyy
            fzz=ezz
            fxy=exy
            fxz=exz
            fyz=eyz
         endif
         if(mattyp.eq.1) then
            stre(1)=am1*fxx+al*(fyy+fzz)-beta(1)
            stre(2)=am1*fyy+al*(fxx+fzz)-beta(2)
            stre(3)=am1*fzz+al*(fxx+fyy)-beta(3)
            stre(4)=um*fxy-beta(4)
            stre(5)=um*fxz-beta(5)
            stre(6)=um*fyz-beta(6)
         elseif(mattyp.eq.2) then
            stre(1)=elas(1)*fxx+elas(2)*fyy+
     &           elas(4)*fzz-beta(1)
            stre(2)=elas(2)*fxx+elas(3)*fyy+
     &           elas(5)*fzz-beta(2)
            stre(3)=elas(4)*fxx+elas(5)*fyy+
     &           elas(6)*fzz-beta(3)
            stre(4)=elas(7)*fxy-beta(4)
            stre(5)=elas(8)*fxz-beta(5)
            stre(6)=elas(9)*fyz-beta(6)
         elseif(mattyp.eq.3) then
            stre(1)=elas(1)*fxx+
     &           elas(2)*fyy+
     &           elas(4)*fzz+
     &           elas(7)*fxy+
     &           elas(11)*fxz+
     &           elas(16)*fyz-beta(1)
            stre(2)=elas(2)*fxx+
     &           elas(3)*fyy+
     &           elas(5)*fzz+
     &           elas(8)*fxy+
     &           elas(12)*fxz+
     &           elas(17)*fyz-beta(2)
            stre(3)=elas(4)*fxx+
     &           elas(5)*fyy+
     &           elas(6)*fzz+
     &           elas(9)*fxy+
     &           elas(13)*fxz+
     &           elas(18)*fyz-beta(3)
            stre(4)=elas(7)*fxx+
     &           elas(8)*fyy+
     &           elas(9)*fzz+
     &           elas(10)*fxy+
     &           elas(14)*fxz+
     &           elas(19)*fyz-beta(4)
            stre(5)=elas(11)*fxx+
     &           elas(12)*fyy+
     &           elas(13)*fzz+
     &           elas(14)*fxy+
     &           elas(15)*fxz+
     &           elas(20)*fyz-beta(5)
            stre(6)=elas(16)*fxx+
     &           elas(17)*fyy+
     &           elas(18)*fzz+
     &           elas(19)*fxy+
     &           elas(20)*fxz+
     &           elas(21)*fyz-beta(6)
!
         endif
      endif
!
      return
      end
