	SUBROUTINE UEL(RHS,AMATRX,SVARS,ENERGY,NDOFEL,NRHS,NSVARS,
     1     PROPS,NPROPS,COORDS,MCRD,NNODE,U,DU,V,A,JTYPE,TIME,
     2     DTIME,KSTEP,KINC,JELEM,PARAMS,NDLOAD,JDLTYP,ADLMAG,
     3     PREDEF,NPREDF,LFLAGS,MLVARX,DDLMAG,MDLOAD,PNEWDT,
     4     JPROPS,NJPROP,PERIOD)
C     
      INCLUDE 'ABA_PARAM.INC'
      PARAMETER ( ZERO = 0.D0, HALF = 0.5D0, ONE = 1.D0 )
C
      DIMENSION RHS(MLVARX,*),AMATRX(NDOFEL,NDOFEL),
     1     SVARS(NSVARS),ENERGY(8),PROPS(*),COORDS(MCRD,NNODE),
     2     U(NDOFEL),DU(MLVARX,*),V(NDOFEL),A(NDOFEL),TIME(2),
     3     PARAMS(3),JDLTYP(MDLOAD,*),ADLMAG(MDLOAD,*),
     4     DDLMAG(MDLOAD,*),PREDEF(2,NPREDF,NNODE),LFLAGS(*),
     5     JPROPS(*)

      AREA = PROPS(1)
      E    = PROPS(2)
	PERM = PROPS(3)
C
	SITA=1.0
C     
      ALEN = SQRT((COORDS(1,2)-COORDS(1,1))**2+
     @(COORDS(2,2)-COORDS(2,1))**2+(COORDS(3,2)-COORDS(3,1))**2)

	 COSLX=(COORDS(1,2)-COORDS(1,1))/ALEN
	 COSLY=(COORDS(2,2)-COORDS(2,1))/ALEN
	 COSLZ=(COORDS(3,2)-COORDS(3,1))/ALEN

      AE   = AREA*E/ALEN
	AK = AREA*PERM/ALEN
C
      DO K1 = 1, NDOFEL                      
        DO K2 = 1, NDOFEL
          AMATRX(K2,K1) = ZERO
        END DO
      END DO
C  
	IF (LFLAGS(1).EQ.61.OR.LFLAGS(1).EQ.64.OR.LFLAGS(1).EQ.65) THEN
    
		AMATRX(1,1) =  AE*COSLX*COSLX  
          AMATRX(2,1) =  AE*COSLX*COSLY  
          AMATRX(3,1) =  AE*COSLX*COSLZ  
          AMATRX(5,1) = -AE*COSLX*COSLX  
          AMATRX(6,1) = -AE*COSLX*COSLY  
          AMATRX(7,1) = -AE*COSLX*COSLZ 
		
          AMATRX(1,2) = AMATRX(2,1)
          AMATRX(1,3) = AMATRX(3,1)
          AMATRX(1,5) = AMATRX(5,1)
          AMATRX(1,6) = AMATRX(6,1)
          AMATRX(1,7) = AMATRX(7,1)


          AMATRX(2,2) =  AE*COSLY*COSLY  
          AMATRX(3,2) =  AE*COSLY*COSLZ  
          AMATRX(5,2) = -AE*COSLY*COSLX
          AMATRX(6,2) = -AE*COSLY*COSLY  
          AMATRX(7,2) = -AE*COSLY*COSLZ  

          AMATRX(2,3) =  AMATRX(3,2)  
          AMATRX(2,5) =  AMATRX(5,2)  
          AMATRX(2,6) =  AMATRX(6,2)  
          AMATRX(2,7) =  AMATRX(7,2)  

          AMATRX(3,3) =  AE*COSLZ*COSLZ  
          AMATRX(5,3) = -AE*COSLZ*COSLX  
          AMATRX(6,3) = -AE*COSLZ*COSLY  
          AMATRX(7,3) = -AE*COSLZ*COSLZ  

          AMATRX(3,5) =  AMATRX(5,3)  
          AMATRX(3,6) =  AMATRX(6,3)  
          AMATRX(3,7) =  AMATRX(7,3)  

          AMATRX(4,4) = -SITA*AK*DTIME
          AMATRX(8,4) =  SITA*AK*DTIME
 
          AMATRX(4,8) =  AMATRX(8,4)  

          AMATRX(4,8) =  AMATRX(8,4)  

          AMATRX(5,5) =  AE*COSLX*COSLX
          AMATRX(6,5) =  AE*COSLX*COSLY  
          AMATRX(7,5) =  AE*COSLX*COSLZ  

          AMATRX(5,6) =  AMATRX(6,5)  
          AMATRX(5,7) =  AMATRX(7,5)  

          AMATRX(6,6) =  AE*COSLY*COSLY  
          AMATRX(7,6) =  AE*COSLY*COSLX

          AMATRX(6,7) =  AMATRX(7,6)  
		
          AMATRX(7,7) =  AE*COSLZ*COSLZ

          AMATRX(8,8) = -SITA*AK*DTIME
  	RHS(4,1) =RHS(4,1)+AK*SITA*U(4)*DTIME-AK*SITA*U(8)*DTIME
	RHS(8,1) =RHS(8,1)-AK*SITA*U(4)*DTIME+AK*SITA*U(8)*DTIME
	END IF
	RETURN
      END       
