cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
c     Calls Stuart's angle subroutine to get triangle dislocation results.

c     Comninou and Dundurs use a 1,2,3 = NED coordinate system.
c       Their simple angular dislocation is in the 1,3 plane
c       with its tip under the origin and its arm pointing toward +x1.

c---+-|--1----+----2----+----3----+----4----+----5----+----6----+----7--

      subroutine comdun ( nu, x1, x2, x3, a, beta, v, dv )

c     Programmed by Bill Stuart (1997) from
c       Comninou and Dundurs, 1975, "The angular dislocation in a half space",
c       Journal of Elasticity, v.5, n.3,4, p. 203-216.

c       nu             - Poisson ratio
c       x1,x2,x3       - obs pt: x1 +rt,  x2 out,  x3 dwn
c       a              - depth, >0, to ang disloc vertex
c       beta           - acute angle, rad, of disloc
c       b1,b2,b3       - burg. vecs. in x(i)
c       v(b,comp)      - obs. displ
c       dv(b,comp,dx)  - displ deriv

      IMPLICIT REAL*8 (A-H,O-Z)
      real*8 tol,y3,nu, x1, x2, x3, a, beta, v, dv

      dimension v(3,3),vc(3,3), dv(3,3,3),dvc(3,3,3)

      tol = 1e-4

      cb  = cos(beta)
      sb  = sin(beta)
      ctb = cb/sb

      y1  = x1
      y2  = x2
      y3  = x3 - a
      yb3 = y3 + 2.*a

      z1  = y1*cb - y3*sb
      z2  = y2
      z3  = y1*sb + y3*cb

      if(abs(cb).LT.tol.AND.abs(y3).LT.tol)then
        cb = tol
        y3 = tol
      end if

      zb1 =  y1*cb + yb3*sb
      zb3 = -y1*sb + yb3*cb

      r   = sqrt(y1**2 + y2**2 + y3**2)
      rb  = sqrt(y1*y1 + y2*y2 + yb3*yb3 )

      f   = -atan2 (y2,y1) + atan2 (y2,z1) +
     .      atan2 (y2*r*sb , (y1*z1 + y2**2*cb) )

      fb  = -atan2 (y2,y1) + atan2 (y2,zb1) +
     .       atan2 (y2*rb*sb , (y1*zb1 + y2**2*cb) )

c     derivs f, fb

      dfdy1 =
     .  y2*(1/(y1**2 + y2**2) - cb/(y2**2 + z1**2) +
     -    (sb*(cb*y1*(-r**2 + y2**2) + (-r**2 + y1**2)*z1))/
     -     (r*(r**2*sb**2*y2**2 + (cb*y2**2 + y1*z1)**2)))

      dfdy2 =
     .  -(y1/(y1**2 + y2**2)) + z1/(y2**2 + z1**2) +
     -  (sb*(cb*(-(r**2*y2**2) + y2**4) + y1*(r**2 + y2**2)*z1))/
     -   (r*(r**2*sb**2*y2**2 + (cb*y2**2 + y1*z1)**2))

      dfdy3 =
     .  sb*y2*(1/(y2**2 + z1**2) +
     -    (r**2*sb*y1 + cb*y2**2*y3 + y1*y3*z1)/
     -     (r*(r**2*sb**2*y2**2 + (cb*y2**2 + y1*z1)**2)))

      dfbdy1 =
     .  y2*(1/(y1**2 + y2**2) - cb/(y2**2 + zb1**2) +
     -    (sb*(cb*y1*(-rb**2 + y2**2) + (-rb**2 + y1**2)*zb1))/
     -     (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2)))

      dfbdy2 =
     .  -(y1/(y1**2 + y2**2)) + zb1/(y2**2 + zb1**2) +
     -  (sb*(cb*(-(rb**2*y2**2) + y2**4) + y1*(rb**2 + y2**2)*zb1))/
     -   (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2))

      dfbdy3 =
     .  sb*y2*(-(1/(y2**2 + zb1**2)) +
     -    (-(rb**2*sb*y1) + cb*y2**2*yb3 + y1*yb3*zb1)/
     -     (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2)))

c     v  displacements

      v(1,1) =
     .  -(y1*y2*(1/(r*(r - y3)) + 1/(rb*(rb + yb3)))) -
     -  cb*y2*((r*sb - y1)/(r*(r - z3)) +
     -     (rb*sb - y1)/(rb*(rb + zb3))) +
     -  2*(1 - nu)*(-2*atan2(y2,y1) + atan2(y2,z1) +
     -     atan2((r*sb*y2),(cb*y2**2 + y1*z1)) + atan2(y2,zb1) +
     -     atan2((rb*sb*y2),(cb*y2**2 + y1*zb1)))

      v(1,2) =
     .  -(y2**2*(1/(r*(r - y3)) + 1/(rb*(rb + yb3)) -
     -       cb*(1/(r*(r - z3)) + 1/(rb*(rb + zb3))))) +
     -  (1 - 2*nu)*(log(r - y3) + log(rb + yb3) -
     -     cb*(log(r - z3) + log(rb + zb3)))

      v(1,3) =
     .  y2*(1/r - 1/rb - cb*((cb*r - y3)/(r*(r - z3)) -
     -       (cb*rb + yb3)/(rb*(rb + zb3))))

      v(2,1) =
     .  y1**2*(1/(r*(r - y3)) + 1/(rb*(rb + yb3))) +
     -  ((r*sb - y1)*z1)/(r*(r - z3)) +
     -  ((rb*sb - y1)*zb1)/(rb*(rb + zb3)) +
     -  (-1 + 2*nu)*(log(r - y3) + log(rb + yb3) -
     -     cb*(log(r - z3) + log(rb + zb3)))

      v(2,2) =
     .  y1*y2*(1/(r*(r - y3)) + 1/(rb*(rb + yb3))) -
     -  y2*(z1/(r*(r - z3)) + zb1/(rb*(rb + zb3))) +
     -  2*(1 - nu)*(-2*atan2(y2,y1) + atan2(y2,z1) +
     -     atan2((r*sb*y2),(cb*y2**2 + y1*z1)) + atan2(y2,zb1) +
     -     atan2((rb*sb*y2),(cb*y2**2 + y1*zb1)))

      v(2,3) =
     .  -((1/r - 1/rb)*y1) + ((cb*r - y3)*z1)/(r*(r - z3)) -
     -  ((cb*rb + yb3)*zb1)/(rb*(rb + zb3)) +
     -  (-1 + 2*nu)*sb*(log(r - z3) - log(rb + zb3))

      v(3,1) =
     .sb*y2*((r*sb - y1)/(r*(r - z3)) +
     . (rb*sb - y1)/(rb*(rb + zb3)))

      v(3,2) =
     .  -(sb*y2**2*(1/(r*(r - z3)) + 1/(rb*(rb + zb3)))) +
     -  (1 - 2*nu)*sb*(log(r - z3) + log(rb + zb3))

      v(3,3) =
     .  sb*y2*((cb*r - y3)/(r*(r - z3)) -
     -     (cb*rb + yb3)/(rb*(rb + zb3))) +
     -  2*(1 - nu)*(atan2(y2,z1) +
     -     atan2((r*sb*y2),(cb*y2**2 + y1*z1)) - atan2(y2,zb1) -
     -     atan2((rb*sb*y2),(cb*y2**2 + y1*zb1)))

c     vc  displacements

      vc(1,1) =
     .  (a*ctb*y2*(-a + yb3))/rb**3 +
     -  ((1 - 2*nu)*y2*(ctb*(1 - 2*nu - a/rb) -
     -       ((nu + a/rb)*y1)/(rb + yb3)))/(rb + yb3) +
     -  (y2*(-a + yb3)*(-(ctb*(1 - 2*nu)) + (a*y1)/rb**2 +
     -       ((2*nu + a/rb)*y1)/(rb + yb3)))/(rb*(rb + yb3)) +
     -  (cb*ctb*(1 - 2*nu)*(cb + a/rb)*y2)/(rb + zb3) +
     -  (y2*(-a + yb3)*(-((a*cb*ctb*yb3)/rb**2) +
     -       (cb*(2*cb*(1 - nu)*(rb*sb - y1) +
     -            ctb*(cb*(1 - 2*nu) - a/rb)*(cb*rb + yb3)))/(rb + zb3))
     -     )/(rb*(rb + zb3)) -
     -  2*ctb**2*(1 - 2*nu)*(1 - nu)*
     -   (-atan2(y2,y1) + atan2(y2,zb1) +
     -     atan2((rb*sb*y2),(cb*y2**2 + y1*zb1)))

      vc(1,2) =
     .  -((a*ctb*y1*(-a + yb3))/rb**3) -
     -  ((1 - 2*nu)*(-a + ctb*(1 - 2*nu - a/rb)*y1 + nu*yb3 +
     -       ((nu + a/rb)*y2**2)/(rb + yb3)))/(rb + yb3) +
     -  ((-a + yb3)*(-2*nu + (-a + ctb*(1 - 2*nu)*y1)/rb +
     -       (a*y2**2)/rb**3 + ((2*nu + a/rb)*y2**2)/(rb*(rb + yb3))))/
     -   (rb + yb3) - (ctb*(1 - 2*nu)*(cb + a/rb)*zb1)/(rb + zb3) +
     -  ((-a + yb3)*(cb**2 + (a*ctb*yb3*zb1)/rb**3 -
     -       (a*cb + ctb*(1 - 2*nu)*zb1)/rb -
     -       (cb**2*y2**2 - (a*ctb*(cb*rb + yb3)*zb1)/rb)/
     -        (rb*(rb + zb3))))/(rb + zb3) +
     -  (1 - 2*nu)*((2*ctb**2*(1 - nu) - nu)*log(rb + yb3) -
     -     cb*(1 + 2*ctb**2*(1 - nu) - 2*nu)*log(rb + zb3))

      vc(1,3) =
     .  (y2*(-a + yb3)*(a/rb**2 + (2*nu)/(rb + yb3)))/rb +
     -  (cb*y2*(-a + yb3)*(1 - 2*nu - (a*yb3)/rb**2 -
     -       ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/(rb*(rb + zb3)) +
     -  2*(1 - nu)*(((2*nu + a/rb)*y2)/(rb + yb3) -
     -     (cb*(cb + a/rb)*y2)/(rb + zb3) +
     -     ctb*(1 - 2*nu)*(-atan2(y2,y1) + atan2(y2,zb1) +
     -        atan2((rb*sb*y2),(cb*y2**2 + y1*zb1))))

      vc(2,1) =
     .  -((a*ctb*y1*(-a + yb3))/rb**3) +
     -  ((1 - 2*nu)*(-a + ctb*(-1 + 2*nu)*y1 + (a*ctb*y1)/rb + nu*yb3 +
     -       ((nu + a/rb)*y1**2)/(rb + yb3)))/(rb + yb3) +
     -  ((-a + yb3)*(2*nu - (a*y1**2)/rb**3 +
     -       (a + ctb*(1 - 2*nu)*y1)/rb -
     -       ((2*nu + a/rb)*y1**2)/(rb*(rb + yb3))))/(rb + yb3) -
     -  (ctb*(1 - 2*nu)*(-((a*(rb*sb - y1))/(cb*rb)) + cb*zb1))/
     -   (rb + zb3) + (ctb*(-a + yb3)*
     -     (-(cb*sb) + (a*y1*yb3)/(cb*rb**3) +
     -       ((rb*sb - y1)*(2*cb*(1 - nu) -
     -            ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/rb))/
     -   (rb + zb3) + (1 - 2*nu)*
     -   ((2*ctb**2*(1 - nu) + nu)*log(rb + yb3) -
     -     cb*(1 + 2*ctb**2*(1 - nu))*log(rb + zb3))

      vc(2,2) =
     .  -((a*ctb*y2*(-a + yb3))/rb**3) +
     -  ((1 - 2*nu)*y2*(ctb*(-1 + 2*nu + a/rb) +
     -       ((nu + a/rb)*y1)/(rb + yb3)))/(rb + yb3) +
     -  (y2*(-a + yb3)*(ctb*(1 - 2*nu) - (2*nu*y1)/(rb + yb3) -
     -       (a*y1*(1/rb + 1/(rb + yb3)))/rb))/(rb*(rb + yb3)) -
     -  (ctb*(1 - 2*nu)*(1 + a/(cb*rb))*y2)/(rb + zb3) +
     -  (ctb*y2*(-a + yb3)*(-2*cb*(1 - nu) + (a*yb3)/(cb*rb**2) +
     -       ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/
     -   (rb*(rb + zb3)) + 2*ctb**2*(1 - 2*nu)*(1 - nu)*
     -   (-atan2(y2,y1) + atan2(y2,zb1) +
     -     atan2((rb*sb*y2),(cb*y2**2 + y1*zb1)))

      vc(2,3) =
     .  (-2*(1 - nu)*(2*nu + a/rb)*y1)/(rb + yb3) +
     -  ((-a + yb3)*(ctb*(1 - 2*nu) - (a*y1)/rb**2 -
     -       (2*nu*y1)/(rb + yb3)))/rb +
     -  (2*(1 - nu)*(cb + a/rb)*zb1)/(rb + zb3) -
     -  ((-a + yb3)*(cb*sb +
     -       (ctb*(cb*rb + yb3)*
     -          (2*cb*(1 - nu) - (cb*rb + yb3)/(rb + zb3)))/rb +
     -   (a*(sb - (yb3*zb1)/rb**2 -
     -   ((cb*rb + yb3)*zb1)/(rb*(rb + zb3))))/rb))/(rb + zb3)
     -   - 2*ctb*(1 - 2*nu)*(1 - nu)*(log(rb + yb3)
     .   - cb*log(rb + zb3))

      vc(3,1) =
     .  -((y2*(-a + yb3)*(a/rb**2 + 1/(rb + yb3)))/rb) +
     -  (1 - 2*nu)*(((1 + a/rb)*y2)/(rb + yb3) -
     -     (cb*(cb + a/rb)*y2)/(rb + zb3)) +
     -  (cb*y2*(-a + yb3)*((a*yb3)/rb**2 +
     -       ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/(rb*(rb + zb3))

      vc(3,2) =
     .  (y1*(-a + yb3)*(a/rb**2 + 1/(rb + yb3)))/rb -
     -  ((-a + yb3)*((cb - a/rb)*sb + ((1 + (a*yb3)/rb**2)*zb1)/rb -
     -       (cb*sb*y2**2 - (a*(cb*rb + yb3)*zb1)/rb)/(rb*(rb + zb3))))/
     -   (rb + zb3) + (1 - 2*nu)*
     -   (-(((1 + a/rb)*y1)/(rb + yb3)) +
     -     ((cb + a/rb)*zb1)/(rb + zb3) - sb*log(rb + zb3))

      vc(3,3) =
     .  (sb*y2*(-a + yb3)*(1 + (a*yb3)/rb**2 +
     -       ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/(rb*(rb + zb3)) +
     -  2*(1 - nu)*(((cb + a/rb)*sb*y2)/(rb + zb3) - atan2(y2,y1) +
     -     atan2(y2,zb1) + atan2((rb*sb*y2),(cb*y2**2 + y1*zb1)))

c     v   derivatives

      dv(1,1,1) =
     .  -(y2*(1/(r*(r - y3)) + 1/(rb*(rb + yb3)))) -
     -  y1*y2*(-(y1/(r**2*(r - y3)**2)) - y1/(r**3*(r - y3)) -
     -     y1/(rb**2*(rb + yb3)**2) - y1/(rb**3*(rb + yb3))) +
     -  2*(1 - nu)*(y2*(1/(y1**2 + y2**2) - cb/(y2**2 + z1**2) +
     -        (sb*(cb*y1*(-r**2 + y2**2) + (-r**2 + y1**2)*z1))/
     -         (r*(r**2*sb**2*y2**2 + (cb*y2**2 + y1*z1)**2))) +
     -     y2*(1/(y1**2 + y2**2) - cb/(y2**2 + zb1**2) +
     -        (sb*(cb*y1*(-rb**2 + y2**2) + (-rb**2 + y1**2)*zb1))/
     -         (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2)))) -
     -  cb*y2*(-(((r*sb - y1)*(-sb + y1/r))/(r*(r - z3)**2)) -
     -     ((r*sb - y1)*y1)/(r**3*(r - z3)) +
     -     (-1 + (sb*y1)/r)/(r*(r - z3)) -
     -     ((rb*sb - y1)*(-sb + y1/rb))/(rb*(rb + zb3)**2) -
     -     ((rb*sb - y1)*y1)/(rb**3*(rb + zb3)) +
     -     (-1 + (sb*y1)/rb)/(rb*(rb + zb3)))

      dv(1,1,2) =
     .  -(y1*(1/(r*(r - y3)) + 1/(rb*(rb + yb3)))) -
     -  y1*y2*(-(y2/(r**2*(r - y3)**2)) - y2/(r**3*(r - y3)) -
     -     y2/(rb**2*(rb + yb3)**2) - y2/(rb**3*(rb + yb3))) +
     -  2*(1 - nu)*((-2*y1)/(y1**2 + y2**2) + z1/(y2**2 + z1**2) +
     -     (sb*(cb*(-(r**2*y2**2) + y2**4) + y1*(r**2 + y2**2)*z1))/
     -      (r*(r**2*sb**2*y2**2 + (cb*y2**2 + y1*z1)**2)) +
     -     zb1/(y2**2 + zb1**2) +
     -     (sb*(cb*(-(rb**2*y2**2) + y2**4) + y1*(rb**2 + y2**2)*zb1))/
     -      (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2))) -
     -  cb*((r*sb - y1)/(r*(r - z3)) + (rb*sb - y1)/(rb*(rb + zb3))) -
     -  cb*y2*(-(((r*sb - y1)*y2)/(r**2*(r - z3)**2)) +
     -     (sb*y2)/(r**2*(r - z3)) - ((r*sb - y1)*y2)/(r**3*(r - z3)) -
     -     ((rb*sb - y1)*y2)/(rb**2*(rb + zb3)**2) +
     -     (sb*y2)/(rb**2*(rb + zb3)) -
     -     ((rb*sb - y1)*y2)/(rb**3*(rb + zb3)))

      dv(1,1,3) =
     . -(y1*y2*(-(y3/(r**3*(r - y3))) - (-1 + y3/r)/(r*(r - y3)**2) -
     - yb3/(rb**3*(rb + yb3)) - (1 + yb3/rb)/(rb*(rb + yb3)**2)))
     -   + 2*(1 - nu)*(sb*y2*
     -      (1/(y2**2 + z1**2) +
     -        (r**2*sb*y1 + cb*y2**2*y3 + y1*y3*z1)/
     -         (r*(r**2*sb**2*y2**2 + (cb*y2**2 + y1*z1)**2))) +
     -     sb*y2*(-(1/(y2**2 + zb1**2)) +
     -        (-(rb**2*sb*y1) + cb*y2**2*yb3 + y1*yb3*zb1)/
     -         (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2)))) -
     -  cb*y2*(-(((r*sb - y1)*(-cb + y3/r))/(r*(r - z3)**2)) +
     -  (sb*y3)/(r**2*(r - z3)) - ((r*sb - y1)*y3)/(r**3*(r - z3)) -
     -     ((rb*sb - y1)*(cb + yb3/rb))/(rb*(rb + zb3)**2) +
     -     (sb*yb3)/(rb**2*(rb + zb3)) -
     -     ((rb*sb - y1)*yb3)/(rb**3*(rb + zb3)))

      dv(1,2,1) =
     .  -(y2**2*(-(y1/(r**2*(r - y3)**2)) - y1/(r**3*(r - y3)) -
     -       y1/(rb**2*(rb + yb3)**2) - y1/(rb**3*(rb + yb3)) -
     -       cb*(-((-sb + y1/r)/(r*(r - z3)**2)) - y1/(r**3*(r - z3)) -
     -          (-sb + y1/rb)/(rb*(rb + zb3)**2) - y1/(rb**3*(rb + zb3))
     -          ))) + (1 - 2*nu)*
     -   (y1/(r*(r - y3)) + y1/(rb*(rb + yb3)) -
     -     cb*((-sb + y1/r)/(r - z3) + (-sb + y1/rb)/(rb + zb3)))

      dv(1,2,2) =
     .  -2*y2*(1/(r*(r - y3)) + 1/(rb*(rb + yb3)) -
     -     cb*(1/(r*(r - z3)) + 1/(rb*(rb + zb3)))) -
     -  y2**2*(-(y2/(r**2*(r - y3)**2)) - y2/(r**3*(r - y3)) -
     -     y2/(rb**2*(rb + yb3)**2) - y2/(rb**3*(rb + yb3)) -
     -     cb*(-(y2/(r**2*(r - z3)**2)) - y2/(r**3*(r - z3)) -
     -        y2/(rb**2*(rb + zb3)**2) - y2/(rb**3*(rb + zb3)))) +
     -  (1 - 2*nu)*(y2/(r*(r - y3)) + y2/(rb*(rb + yb3)) -
     -     cb*(y2/(r*(r - z3)) + y2/(rb*(rb + zb3))))

      dv(1,2,3) =
     .  -(y2**2*(-(y3/(r**3*(r - y3))) - (-1 + y3/r)/(r*(r - y3)**2) -
     -       yb3/(rb**3*(rb + yb3)) - (1 + yb3/rb)/(rb*(rb + yb3)**2) -
     -       cb*(-((-cb + y3/r)/(r*(r - z3)**2)) - y3/(r**3*(r - z3)) -
     -          (cb + yb3/rb)/(rb*(rb + zb3)**2) -
     -          yb3/(rb**3*(rb + zb3))))) +
     -  (1 - 2*nu)*((-1 + y3/r)/(r - y3) + (1 + yb3/rb)/(rb + yb3) -
     -     cb*((-cb + y3/r)/(r - z3) + (cb + yb3/rb)/(rb + zb3)))

      dv(1,3,1) =
     .  y2*(-(y1/r**3) + y1/rb**3 -
     -    cb*(-(((-sb + y1/r)*(cb*r - y3))/(r*(r - z3)**2)) +
     -       (cb*y1)/(r**2*(r - z3)) -
     -       (y1*(cb*r - y3))/(r**3*(r - z3)) +
     -       ((-sb + y1/rb)*(cb*rb + yb3))/(rb*(rb + zb3)**2) -
     -       (cb*y1)/(rb**2*(rb + zb3)) +
     -       (y1*(cb*rb + yb3))/(rb**3*(rb + zb3))))

      dv(1,3,2) =
     .  1/r - 1/rb - cb*((cb*r - y3)/(r*(r - z3)) -
     -     (cb*rb + yb3)/(rb*(rb + zb3))) +
     -  y2*(-(y2/r**3) + y2/rb**3 -
     -     cb*(-((y2*(cb*r - y3))/(r**2*(r - z3)**2)) +
     -        (cb*y2)/(r**2*(r - z3)) -
     -        (y2*(cb*r - y3))/(r**3*(r - z3)) +
     -        (y2*(cb*rb + yb3))/(rb**2*(rb + zb3)**2) -
     -        (cb*y2)/(rb**2*(rb + zb3)) +
     -        (y2*(cb*rb + yb3))/(rb**3*(rb + zb3))))

      dv(1,3,3) =
     .  y2*(-(y3/r**3) + yb3/rb**3 -
     -    cb*(-(((cb*r - y3)*(-cb + y3/r))/(r*(r - z3)**2)) -
     -       ((cb*r - y3)*y3)/(r**3*(r - z3)) +
     -       (-1 + (cb*y3)/r)/(r*(r - z3)) +
     -       ((cb*rb + yb3)*(cb + yb3/rb))/(rb*(rb + zb3)**2) +
     -       (yb3*(cb*rb + yb3))/(rb**3*(rb + zb3)) -
     -       (1 + (cb*yb3)/rb)/(rb*(rb + zb3))))

      dv(2,1,1) =
     .  2*y1*(1/(r*(r - y3)) + 1/(rb*(rb + yb3))) +
     -  y1**2*(-(y1/(r**2*(r - y3)**2)) - y1/(r**3*(r - y3)) -
     -     y1/(rb**2*(rb + yb3)**2) - y1/(rb**3*(rb + yb3))) -
     -  ((r*sb - y1)*(-sb + y1/r)*z1)/(r*(r - z3)**2) +
     -  (cb*(r*sb - y1))/(r*(r - z3)) -
     -  ((r*sb - y1)*y1*z1)/(r**3*(r - z3)) +
     -  ((-1 + (sb*y1)/r)*z1)/(r*(r - z3)) -
     -  ((rb*sb - y1)*(-sb + y1/rb)*zb1)/(rb*(rb + zb3)**2) +
     -  (cb*(rb*sb - y1))/(rb*(rb + zb3)) -
     -  ((rb*sb - y1)*y1*zb1)/(rb**3*(rb + zb3)) +
     -  ((-1 + (sb*y1)/rb)*zb1)/(rb*(rb + zb3)) +
     -  (-1 + 2*nu)*(y1/(r*(r - y3)) + y1/(rb*(rb + yb3)) -
     -     cb*((-sb + y1/r)/(r - z3) + (-sb + y1/rb)/(rb + zb3)))

      dv(2,1,2) =
     .  y1**2*(-(y2/(r**2*(r - y3)**2)) - y2/(r**3*(r - y3)) -
     -     y2/(rb**2*(rb + yb3)**2) - y2/(rb**3*(rb + yb3))) -
     -  ((r*sb - y1)*y2*z1)/(r**2*(r - z3)**2) +
     -  (sb*y2*z1)/(r**2*(r - z3)) -
     -  ((r*sb - y1)*y2*z1)/(r**3*(r - z3)) -
     -  ((rb*sb - y1)*y2*zb1)/(rb**2*(rb + zb3)**2) +
     -  (sb*y2*zb1)/(rb**2*(rb + zb3)) -
     -  ((rb*sb - y1)*y2*zb1)/(rb**3*(rb + zb3)) +
     -  (-1 + 2*nu)*(y2/(r*(r - y3)) + y2/(rb*(rb + yb3)) -
     -     cb*(y2/(r*(r - z3)) + y2/(rb*(rb + zb3))))

      dv(2,1,3) =
     .  y1**2*(-(y3/(r**3*(r - y3))) - (-1 + y3/r)/(r*(r - y3)**2) -
     -     yb3/(rb**3*(rb + yb3)) - (1 + yb3/rb)/(rb*(rb + yb3)**2)) -
     -  ((r*sb - y1)*(-cb + y3/r)*z1)/(r*(r - z3)**2) -
     -  (sb*(r*sb - y1))/(r*(r - z3)) + (sb*y3*z1)/(r**2*(r - z3)) -
     -  ((r*sb - y1)*y3*z1)/(r**3*(r - z3)) -
     -  ((rb*sb - y1)*(cb + yb3/rb)*zb1)/(rb*(rb + zb3)**2) +
     -  (sb*(rb*sb - y1))/(rb*(rb + zb3)) +
     -  (sb*yb3*zb1)/(rb**2*(rb + zb3)) -
     -  ((rb*sb - y1)*yb3*zb1)/(rb**3*(rb + zb3)) +
     -  (-1 + 2*nu)*((-1 + y3/r)/(r - y3) + (1 + yb3/rb)/(rb + yb3) -
     -     cb*((-cb + y3/r)/(r - z3) + (cb + yb3/rb)/(rb + zb3)))

      dv(2,2,1) =
     .  y2*(1/(r*(r - y3)) + 1/(rb*(rb + yb3))) +
     -  y1*y2*(-(y1/(r**2*(r - y3)**2)) - y1/(r**3*(r - y3)) -
     -     y1/(rb**2*(rb + yb3)**2) - y1/(rb**3*(rb + yb3))) +
     -  2*(1 - nu)*(y2*(1/(y1**2 + y2**2) - cb/(y2**2 + z1**2) +
     -        (sb*(cb*y1*(-r**2 + y2**2) + (-r**2 + y1**2)*z1))/
     -         (r*(r**2*sb**2*y2**2 + (cb*y2**2 + y1*z1)**2))) +
     -     y2*(1/(y1**2 + y2**2) - cb/(y2**2 + zb1**2) +
     -        (sb*(cb*y1*(-rb**2 + y2**2) + (-rb**2 + y1**2)*zb1))/
     -         (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2)))) -
     -  y2*(-(((-sb + y1/r)*z1)/(r*(r - z3)**2)) + cb/(r*(r - z3)) -
     -     (y1*z1)/(r**3*(r - z3)) -
     -     ((-sb + y1/rb)*zb1)/(rb*(rb + zb3)**2) +
     -     cb/(rb*(rb + zb3)) - (y1*zb1)/(rb**3*(rb + zb3)))

      dv(2,2,2) =
     .  y1*(1/(r*(r - y3)) + 1/(rb*(rb + yb3))) +
     -  y1*y2*(-(y2/(r**2*(r - y3)**2)) - y2/(r**3*(r - y3)) -
     -     y2/(rb**2*(rb + yb3)**2) - y2/(rb**3*(rb + yb3))) -
     -  z1/(r*(r - z3)) + 2*(1 - nu)*
     -   ((-2*y1)/(y1**2 + y2**2) + z1/(y2**2 + z1**2) +
     -     (sb*(cb*(-(r**2*y2**2) + y2**4) + y1*(r**2 + y2**2)*z1))/
     -      (r*(r**2*sb**2*y2**2 + (cb*y2**2 + y1*z1)**2)) +
     -     zb1/(y2**2 + zb1**2) +
     -     (sb*(cb*(-(rb**2*y2**2) + y2**4) + y1*(rb**2 + y2**2)*zb1))/
     -      (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2))) -
     -  zb1/(rb*(rb + zb3)) -
     -  y2*(-((y2*z1)/(r**2*(r - z3)**2)) - (y2*z1)/(r**3*(r - z3)) -
     -     (y2*zb1)/(rb**2*(rb + zb3)**2) - (y2*zb1)/(rb**3*(rb + zb3)))

      dv(2,2,3) =
     .  y1*y2*(-(y3/(r**3*(r - y3))) - (-1 + y3/r)/(r*(r - y3)**2) -
     -     yb3/(rb**3*(rb + yb3)) - (1 + yb3/rb)/(rb*(rb + yb3)**2)) +
     -  2*(1 - nu)*(sb*y2*(1/(y2**2 + z1**2) +
     -        (r**2*sb*y1 + cb*y2**2*y3 + y1*y3*z1)/
     -         (r*(r**2*sb**2*y2**2 + (cb*y2**2 + y1*z1)**2))) +
     -     sb*y2*(-(1/(y2**2 + zb1**2)) +
     -        (-(rb**2*sb*y1) + cb*y2**2*yb3 + y1*yb3*zb1)/
     -         (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2)))) -
     -  y2*(-(((-cb + y3/r)*z1)/(r*(r - z3)**2)) - sb/(r*(r - z3)) -
     -     (y3*z1)/(r**3*(r - z3)) -
     -     ((cb + yb3/rb)*zb1)/(rb*(rb + zb3)**2) +
     -     sb/(rb*(rb + zb3)) - (yb3*zb1)/(rb**3*(rb + zb3)))

      dv(2,3,1) =
     .  -(1/r) + 1/rb - y1*(-(y1/r**3) + y1/rb**3) -
     -  ((-sb + y1/r)*(cb*r - y3)*z1)/(r*(r - z3)**2) +
     -  (cb*(cb*r - y3))/(r*(r - z3)) + (cb*y1*z1)/(r**2*(r - z3)) -
     -  (y1*(cb*r - y3)*z1)/(r**3*(r - z3)) +
     -  ((-sb + y1/rb)*(cb*rb + yb3)*zb1)/(rb*(rb + zb3)**2) -
     -  (cb*(cb*rb + yb3))/(rb*(rb + zb3)) -
     -  (cb*y1*zb1)/(rb**2*(rb + zb3)) +
     -  (y1*(cb*rb + yb3)*zb1)/(rb**3*(rb + zb3)) +
     -  (-1 + 2*nu)*sb*((-sb + y1/r)/(r - z3) -
     -     (-sb + y1/rb)/(rb + zb3))

      dv(2,3,2) =
     .  -(y1*(-(y2/r**3) + y2/rb**3)) -
     -  (y2*(cb*r - y3)*z1)/(r**2*(r - z3)**2) +
     -  (cb*y2*z1)/(r**2*(r - z3)) -
     -  (y2*(cb*r - y3)*z1)/(r**3*(r - z3)) +
     -  (y2*(cb*rb + yb3)*zb1)/(rb**2*(rb + zb3)**2) -
     -  (cb*y2*zb1)/(rb**2*(rb + zb3)) +
     -  (y2*(cb*rb + yb3)*zb1)/(rb**3*(rb + zb3)) +
     -  (-1 + 2*nu)*sb*(y2/(r*(r - z3)) - y2/(rb*(rb + zb3)))

      dv(2,3,3) =
     .  -(y1*(-(y3/r**3) + yb3/rb**3)) -
     -  ((cb*r - y3)*(-cb + y3/r)*z1)/(r*(r - z3)**2) -
     -  (sb*(cb*r - y3))/(r*(r - z3)) -
     -  ((cb*r - y3)*y3*z1)/(r**3*(r - z3)) +
     -  ((-1 + (cb*y3)/r)*z1)/(r*(r - z3)) +
     -  ((cb*rb + yb3)*(cb + yb3/rb)*zb1)/(rb*(rb + zb3)**2) -
     -  (sb*(cb*rb + yb3))/(rb*(rb + zb3)) +
     -  (yb3*(cb*rb + yb3)*zb1)/(rb**3*(rb + zb3)) -
     -  ((1 + (cb*yb3)/rb)*zb1)/(rb*(rb + zb3)) +
     -  (-1 + 2*nu)*sb*((-cb + y3/r)/(r - z3) -
     -     (cb + yb3/rb)/(rb + zb3))

      dv(3,1,1) =
     .  sb*y2*(-(((r*sb - y1)*(-sb + y1/r))/(r*(r - z3)**2)) -
     -    ((r*sb - y1)*y1)/(r**3*(r - z3)) +
     -    (-1 + (sb*y1)/r)/(r*(r - z3)) -
     -    ((rb*sb - y1)*(-sb + y1/rb))/(rb*(rb + zb3)**2) -
     -    ((rb*sb - y1)*y1)/(rb**3*(rb + zb3)) +
     -    (-1 + (sb*y1)/rb)/(rb*(rb + zb3)))

      dv(3,1,2) =
     .  sb*((r*sb - y1)/(r*(r - z3)) + (rb*sb - y1)/(rb*(rb + zb3))) +
     -  sb*y2*(-(((r*sb - y1)*y2)/(r**2*(r - z3)**2)) +
     -     (sb*y2)/(r**2*(r - z3)) - ((r*sb - y1)*y2)/(r**3*(r - z3)) -
     -     ((rb*sb - y1)*y2)/(rb**2*(rb + zb3)**2) +
     -     (sb*y2)/(rb**2*(rb + zb3)) -
     -     ((rb*sb - y1)*y2)/(rb**3*(rb + zb3)))

      dv(3,1,3) =
     .  sb*y2*(-(((r*sb - y1)*(-cb + y3/r))/(r*(r - z3)**2)) +
     -    (sb*y3)/(r**2*(r - z3)) - ((r*sb - y1)*y3)/(r**3*(r - z3)) -
     -    ((rb*sb - y1)*(cb + yb3/rb))/(rb*(rb + zb3)**2) +
     -    (sb*yb3)/(rb**2*(rb + zb3)) -
     -    ((rb*sb - y1)*yb3)/(rb**3*(rb + zb3)))

      dv(3,2,1) =
     .  -(sb*y2**2*(-((-sb + y1/r)/(r*(r - z3)**2)) -
     -       y1/(r**3*(r - z3)) - (-sb + y1/rb)/(rb*(rb + zb3)**2) -
     -       y1/(rb**3*(rb + zb3)))) +
     -  (1 - 2*nu)*sb*((-sb + y1/r)/(r - z3) + (-sb + y1/rb)/(rb + zb3))

      dv(3,2,2) =
     .  -2*sb*y2*(1/(r*(r - z3)) + 1/(rb*(rb + zb3))) -
     -  sb*y2**2*(-(y2/(r**2*(r - z3)**2)) - y2/(r**3*(r - z3)) -
     -     y2/(rb**2*(rb + zb3)**2) - y2/(rb**3*(rb + zb3))) +
     -  (1 - 2*nu)*sb*(y2/(r*(r - z3)) + y2/(rb*(rb + zb3)))

      dv(3,2,3) =
     .  -(sb*y2**2*(-((-cb + y3/r)/(r*(r - z3)**2)) -
     -       y3/(r**3*(r - z3)) - (cb + yb3/rb)/(rb*(rb + zb3)**2) -
     -       yb3/(rb**3*(rb + zb3)))) +
     -  (1 - 2*nu)*sb*((-cb + y3/r)/(r - z3) + (cb + yb3/rb)/(rb + zb3))

      dv(3,3,1) =
     .  2*(1 - nu)*(y2*(1/(y1**2 + y2**2) - cb/(y2**2 + z1**2) +
     -        (sb*(cb*y1*(-r**2 + y2**2) + (-r**2 + y1**2)*z1))/
     -         (r*(r**2*sb**2*y2**2 + (cb*y2**2 + y1*z1)**2))) -
     -     y2*(1/(y1**2 + y2**2) - cb/(y2**2 + zb1**2) +
     -        (sb*(cb*y1*(-rb**2 + y2**2) + (-rb**2 + y1**2)*zb1))/
     -         (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2)))) +
     -  sb*y2*(-(((-sb + y1/r)*(cb*r - y3))/(r*(r - z3)**2)) +
     -     (cb*y1)/(r**2*(r - z3)) - (y1*(cb*r - y3))/(r**3*(r - z3)) +
     -     ((-sb + y1/rb)*(cb*rb + yb3))/(rb*(rb + zb3)**2) -
     -     (cb*y1)/(rb**2*(rb + zb3)) +
     -     (y1*(cb*rb + yb3))/(rb**3*(rb + zb3)))

      dv(3,3,2) =
     .  2*(1 - nu)*(z1/(y2**2 + z1**2) +
     -     (sb*(cb*(-(r**2*y2**2) + y2**4) + y1*(r**2 + y2**2)*z1))/
     -      (r*(r**2*sb**2*y2**2 + (cb*y2**2 + y1*z1)**2)) -
     -     zb1/(y2**2 + zb1**2) -
     -     (sb*(cb*(-(rb**2*y2**2) + y2**4) + y1*(rb**2 + y2**2)*zb1))/
     -      (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2))) +
     -  sb*((cb*r - y3)/(r*(r - z3)) - (cb*rb + yb3)/(rb*(rb + zb3))) +
     -  sb*y2*(-((y2*(cb*r - y3))/(r**2*(r - z3)**2)) +
     -     (cb*y2)/(r**2*(r - z3)) - (y2*(cb*r - y3))/(r**3*(r - z3)) +
     -     (y2*(cb*rb + yb3))/(rb**2*(rb + zb3)**2) -
     -     (cb*y2)/(rb**2*(rb + zb3)) +
     -     (y2*(cb*rb + yb3))/(rb**3*(rb + zb3)))

      dv(3,3,3) =
     .  2*(1 - nu)*(sb*y2*(1/(y2**2 + z1**2) +
     -        (r**2*sb*y1 + cb*y2**2*y3 + y1*y3*z1)/
     -         (r*(r**2*sb**2*y2**2 + (cb*y2**2 + y1*z1)**2))) -
     -     sb*y2*(-(1/(y2**2 + zb1**2)) +
     -        (-(rb**2*sb*y1) + cb*y2**2*yb3 + y1*yb3*zb1)/
     -         (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2)))) +
     -  sb*y2*(-(((cb*r - y3)*(-cb + y3/r))/(r*(r - z3)**2)) -
     -     ((cb*r - y3)*y3)/(r**3*(r - z3)) +
     -     (-1 + (cb*y3)/r)/(r*(r - z3)) +
     -     ((cb*rb + yb3)*(cb + yb3/rb))/(rb*(rb + zb3)**2) +
     -     (yb3*(cb*rb + yb3))/(rb**3*(rb + zb3)) -
     -     (1 + (cb*yb3)/rb)/(rb*(rb + zb3)))

c     vc   derivatives

      dvc(1,1,1) =
     .  (-3*a*ctb*y1*y2*(-a + yb3))/rb**5 -
     -  ((1 - 2*nu)*y1*y2*(ctb*(1 - 2*nu - a/rb) -
     -       ((nu + a/rb)*y1)/(rb + yb3)))/(rb*(rb + yb3)**2) -
     -  (y1*y2*(-a + yb3)*(-(ctb*(1 - 2*nu)) + (a*y1)/rb**2 +
     -       ((2*nu + a/rb)*y1)/(rb + yb3)))/(rb**2*(rb + yb3)**2) -
     -  (y1*y2*(-a + yb3)*(-(ctb*(1 - 2*nu)) + (a*y1)/rb**2 +
     -       ((2*nu + a/rb)*y1)/(rb + yb3)))/(rb**3*(rb + yb3)) +
     -  (y2*(-a + yb3)*(a/rb**2 - (2*a*y1**2)/rb**4 -
     -       ((2*nu + a/rb)*y1**2)/(rb*(rb + yb3)**2) +
     -       (2*nu + a/rb)/(rb + yb3) - (a*y1**2)/(rb**3*(rb + yb3))))/
     -   (rb*(rb + yb3)) + ((1 - 2*nu)*y2*
     -     ((a*ctb*y1)/rb**3 + ((nu + a/rb)*y1**2)/(rb*(rb + yb3)**2) -
     -       (nu + a/rb)/(rb + yb3) + (a*y1**2)/(rb**3*(rb + yb3))))/
     -   (rb + yb3) - 2*ctb**2*(1 - 2*nu)*(1 - nu)*y2*
     -   (1/(y1**2 + y2**2) - cb/(y2**2 + zb1**2) +
     -     (sb*(cb*y1*(-rb**2 + y2**2) + (-rb**2 + y1**2)*zb1))/
     -      (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2))) -
     -  (cb*ctb*(1 - 2*nu)*(cb + a/rb)*(-sb + y1/rb)*y2)/
     -   (rb + zb3)**2 - (a*cb*ctb*(1 - 2*nu)*y1*y2)/
     -   (rb**3*(rb + zb3)) -
     -  ((-sb + y1/rb)*y2*(-a + yb3)*
     -     (-((a*cb*ctb*yb3)/rb**2) +
     -       (cb*(2*cb*(1 - nu)*(rb*sb - y1) +
     -            ctb*(cb*(1 - 2*nu) - a/rb)*(cb*rb + yb3)))/(rb + zb3))
     -     )/(rb*(rb + zb3)**2) -
     -  (y1*y2*(-a + yb3)*(-((a*cb*ctb*yb3)/rb**2) +
     -       (cb*(2*cb*(1 - nu)*(rb*sb - y1) +
     -            ctb*(cb*(1 - 2*nu) - a/rb)*(cb*rb + yb3)))/(rb + zb3))
     -     )/(rb**3*(rb + zb3)) +
     -  (y2*(-a + yb3)*((2*a*cb*ctb*y1*yb3)/rb**4 -
     -       (cb*(-sb + y1/rb)*
     -          (2*cb*(1 - nu)*(rb*sb - y1) +
     -            ctb*(cb*(1 - 2*nu) - a/rb)*(cb*rb + yb3)))/
     -        (rb + zb3)**2 +
     -       (cb*((cb*ctb*(cb*(1 - 2*nu) - a/rb)*y1)/rb +
     -            2*cb*(1 - nu)*(-1 + (sb*y1)/rb) +
     -            (a*ctb*y1*(cb*rb + yb3))/rb**3))/(rb + zb3)))/
     -   (rb*(rb + zb3))

      dvc(1,1,2) =
     .  (a*ctb*(-a + yb3))/rb**3 - (3*a*ctb*y2**2*(-a + yb3))/rb**5 -
     -  ((1 - 2*nu)*y2**2*(ctb*(1 - 2*nu - a/rb) -
     -       ((nu + a/rb)*y1)/(rb + yb3)))/(rb*(rb + yb3)**2) +
     -  ((1 - 2*nu)*(ctb*(1 - 2*nu - a/rb) -
     -       ((nu + a/rb)*y1)/(rb + yb3)))/(rb + yb3) -
     -  (y2**2*(-a + yb3)*(-(ctb*(1 - 2*nu)) + (a*y1)/rb**2 +
     -       ((2*nu + a/rb)*y1)/(rb + yb3)))/(rb**2*(rb + yb3)**2) +
     -  ((-a + yb3)*(-(ctb*(1 - 2*nu)) + (a*y1)/rb**2 +
     -       ((2*nu + a/rb)*y1)/(rb + yb3)))/(rb*(rb + yb3)) -
     -  (y2**2*(-a + yb3)*(-(ctb*(1 - 2*nu)) + (a*y1)/rb**2 +
     -       ((2*nu + a/rb)*y1)/(rb + yb3)))/(rb**3*(rb + yb3)) +
     -  (y2*(-a + yb3)*((-2*a*y1*y2)/rb**4 -
     -       ((2*nu + a/rb)*y1*y2)/(rb*(rb + yb3)**2) -
     -       (a*y1*y2)/(rb**3*(rb + yb3))))/(rb*(rb + yb3)) +
     -  ((1 - 2*nu)*y2*((a*ctb*y2)/rb**3 +
     -       ((nu + a/rb)*y1*y2)/(rb*(rb + yb3)**2) +
     -       (a*y1*y2)/(rb**3*(rb + yb3))))/(rb + yb3) -
     -  2*ctb**2*(1 - 2*nu)*(1 - nu)*
     -   (-(y1/(y1**2 + y2**2)) + zb1/(y2**2 + zb1**2) +
     -     (sb*(cb*(-(rb**2*y2**2) + y2**4) + y1*(rb**2 + y2**2)*zb1))/
     -      (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2))) -
     -  (cb*ctb*(1 - 2*nu)*(cb + a/rb)*y2**2)/(rb*(rb + zb3)**2) +
     -  (cb*ctb*(1 - 2*nu)*(cb + a/rb))/(rb + zb3) -
     -  (a*cb*ctb*(1 - 2*nu)*y2**2)/(rb**3*(rb + zb3)) -
     -  (y2**2*(-a + yb3)*(-((a*cb*ctb*yb3)/rb**2) +
     -       (cb*(2*cb*(1 - nu)*(rb*sb - y1) +
     -            ctb*(cb*(1 - 2*nu) - a/rb)*(cb*rb + yb3)))/(rb + zb3))
     -     )/(rb**2*(rb + zb3)**2) +
     -  ((-a + yb3)*(-((a*cb*ctb*yb3)/rb**2) +
     -       (cb*(2*cb*(1 - nu)*(rb*sb - y1) +
     -            ctb*(cb*(1 - 2*nu) - a/rb)*(cb*rb + yb3)))/(rb + zb3))
     -     )/(rb*(rb + zb3)) -
     -  (y2**2*(-a + yb3)*(-((a*cb*ctb*yb3)/rb**2) +
     -       (cb*(2*cb*(1 - nu)*(rb*sb - y1) +
     -            ctb*(cb*(1 - 2*nu) - a/rb)*(cb*rb + yb3)))/(rb + zb3))
     -     )/(rb**3*(rb + zb3)) +
     -  (y2*(-a + yb3)*((2*a*cb*ctb*y2*yb3)/rb**4 -
     -       (cb*y2*(2*cb*(1 - nu)*(rb*sb - y1) +
     -            ctb*(cb*(1 - 2*nu) - a/rb)*(cb*rb + yb3)))/
     -        (rb*(rb + zb3)**2) +
     -       (cb*((cb*ctb*(cb*(1 - 2*nu) - a/rb)*y2)/rb +
     -            (2*cb*(1 - nu)*sb*y2)/rb +
     -            (a*ctb*y2*(cb*rb + yb3))/rb**3))/(rb + zb3)))/
     -   (rb*(rb + zb3))

      dvc(1,1,3) =
     .  (a*ctb*y2)/rb**3 - (3*a*ctb*y2*yb3*(-a + yb3))/rb**5 -
     -  ((1 - 2*nu)*y2*(1 + yb3/rb)*
     -     (ctb*(1 - 2*nu - a/rb) - ((nu + a/rb)*y1)/(rb + yb3)))/
     -   (rb + yb3)**2 + (y2*
     -     (-(ctb*(1 - 2*nu)) + (a*y1)/rb**2 +
     -       ((2*nu + a/rb)*y1)/(rb + yb3)))/(rb*(rb + yb3)) -
     -  (y2*yb3*(-a + yb3)*(-(ctb*(1 - 2*nu)) + (a*y1)/rb**2 +
     -       ((2*nu + a/rb)*y1)/(rb + yb3)))/(rb**3*(rb + yb3)) -
     -  (y2*(-a + yb3)*(1 + yb3/rb)*
     -     (-(ctb*(1 - 2*nu)) + (a*y1)/rb**2 +
     -       ((2*nu + a/rb)*y1)/(rb + yb3)))/(rb*(rb + yb3)**2) +
     -  ((1 - 2*nu)*y2*((a*ctb*yb3)/rb**3 +
     -       (a*y1*yb3)/(rb**3*(rb + yb3)) +
     -       ((nu + a/rb)*y1*(1 + yb3/rb))/(rb + yb3)**2))/(rb + yb3) +
     -  (y2*(-a + yb3)*((-2*a*y1*yb3)/rb**4 -
     -       (a*y1*yb3)/(rb**3*(rb + yb3)) -
     -       ((2*nu + a/rb)*y1*(1 + yb3/rb))/(rb + yb3)**2))/
     -   (rb*(rb + yb3)) - 2*ctb**2*(1 - 2*nu)*(1 - nu)*sb*y2*
     -   (-(1/(y2**2 + zb1**2)) +
     -     (-(rb**2*sb*y1) + cb*y2**2*yb3 + y1*yb3*zb1)/
     -      (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2))) -
     -  (cb*ctb*(1 - 2*nu)*(cb + a/rb)*y2*(cb + yb3/rb))/
     -   (rb + zb3)**2 - (a*cb*ctb*(1 - 2*nu)*y2*yb3)/
     -   (rb**3*(rb + zb3)) -
     -  (y2*(-a + yb3)*(cb + yb3/rb)*
     -     (-((a*cb*ctb*yb3)/rb**2) +
     -       (cb*(2*cb*(1 - nu)*(rb*sb - y1) +
     -            ctb*(cb*(1 - 2*nu) - a/rb)*(cb*rb + yb3)))/(rb + zb3))
     -     )/(rb*(rb + zb3)**2) +
     -  (y2*(-((a*cb*ctb*yb3)/rb**2) +
     -       (cb*(2*cb*(1 - nu)*(rb*sb - y1) +
     -            ctb*(cb*(1 - 2*nu) - a/rb)*(cb*rb + yb3)))/(rb + zb3))
     -     )/(rb*(rb + zb3)) -
     -  (y2*yb3*(-a + yb3)*(-((a*cb*ctb*yb3)/rb**2) +
     -       (cb*(2*cb*(1 - nu)*(rb*sb - y1) +
     -            ctb*(cb*(1 - 2*nu) - a/rb)*(cb*rb + yb3)))/(rb + zb3))
     -     )/(rb**3*(rb + zb3)) +
     -  (y2*(-a + yb3)*(-((a*cb*ctb)/rb**2) +
     -       (2*a*cb*ctb*yb3**2)/rb**4 -
     -       (cb*(cb + yb3/rb)*
     -          (2*cb*(1 - nu)*(rb*sb - y1) +
     -            ctb*(cb*(1 - 2*nu) - a/rb)*(cb*rb + yb3)))/
     -        (rb + zb3)**2 +
     -       (cb*((2*cb*(1 - nu)*sb*yb3)/rb +
     -            (a*ctb*yb3*(cb*rb + yb3))/rb**3 +
     -            ctb*(cb*(1 - 2*nu) - a/rb)*(1 + (cb*yb3)/rb)))/
     -        (rb + zb3)))/(rb*(rb + zb3))

      dvc(1,2,1) =
     .  -((a*ctb*(-a + yb3))/rb**3) +
     -  (3*a*ctb*y1**2*(-a + yb3))/rb**5 +
     -  ((1 - 2*nu)*y1*(-a + ctb*(1 - 2*nu - a/rb)*y1 + nu*yb3 +
     -       ((nu + a/rb)*y2**2)/(rb + yb3)))/(rb*(rb + yb3)**2) -
     -  (y1*(-a + yb3)*(-2*nu + (-a + ctb*(1 - 2*nu)*y1)/rb +
     -       (a*y2**2)/rb**3 + ((2*nu + a/rb)*y2**2)/(rb*(rb + yb3))))/
     -   (rb*(rb + yb3)**2) -
     -  ((1 - 2*nu)*(ctb*(1 - 2*nu - a/rb) + (a*ctb*y1**2)/rb**3 -
     -       ((nu + a/rb)*y1*y2**2)/(rb*(rb + yb3)**2) -
     -       (a*y1*y2**2)/(rb**3*(rb + yb3))))/(rb + yb3) +
     -  ((-a + yb3)*((ctb*(1 - 2*nu))/rb -
     -       (y1*(-a + ctb*(1 - 2*nu)*y1))/rb**3 -
     -       (3*a*y1*y2**2)/rb**5 -
     -       ((2*nu + a/rb)*y1*y2**2)/(rb**2*(rb + yb3)**2) -
     -       (a*y1*y2**2)/(rb**4*(rb + yb3)) -
     -       ((2*nu + a/rb)*y1*y2**2)/(rb**3*(rb + yb3))))/(rb + yb3) +
     -  (ctb*(1 - 2*nu)*(cb + a/rb)*(-sb + y1/rb)*zb1)/(rb + zb3)**2 -
     -  (cb*ctb*(1 - 2*nu)*(cb + a/rb))/(rb + zb3) +
     -  (a*ctb*(1 - 2*nu)*y1*zb1)/(rb**3*(rb + zb3)) +
     -  (1 - 2*nu)*(((2*ctb**2*(1 - nu) - nu)*y1)/(rb*(rb + yb3)) -
     -     (cb*(1 + 2*ctb**2*(1 - nu) - 2*nu)*(-sb + y1/rb))/(rb + zb3))
     -    - ((-sb + y1/rb)*(-a + yb3)*
     -     (cb**2 + (a*ctb*yb3*zb1)/rb**3 -
     -       (a*cb + ctb*(1 - 2*nu)*zb1)/rb -
     -       (cb**2*y2**2 - (a*ctb*(cb*rb + yb3)*zb1)/rb)/
     -        (rb*(rb + zb3))))/(rb + zb3)**2 +
     -  ((-a + yb3)*(-((cb*ctb*(1 - 2*nu))/rb) + (a*cb*ctb*yb3)/rb**3 -
     -       (3*a*ctb*y1*yb3*zb1)/rb**5 +
     -       (y1*(a*cb + ctb*(1 - 2*nu)*zb1))/rb**3 +
     -       ((-sb + y1/rb)*(cb**2*y2**2 -
     -            (a*ctb*(cb*rb + yb3)*zb1)/rb))/(rb*(rb + zb3)**2) +
     -       (y1*(cb**2*y2**2 - (a*ctb*(cb*rb + yb3)*zb1)/rb))/
     -        (rb**3*(rb + zb3)) -
     -       (-((a*cb*ctb*(cb*rb + yb3))/rb) -
     -          (a*cb*ctb*y1*zb1)/rb**2 +
     -          (a*ctb*y1*(cb*rb + yb3)*zb1)/rb**3)/(rb*(rb + zb3))))/
     -   (rb + zb3)

      dvc(1,2,2) =
     .  (3*a*ctb*y1*y2*(-a + yb3))/rb**5 +
     -  ((1 - 2*nu)*y2*(-a + ctb*(1 - 2*nu - a/rb)*y1 + nu*yb3 +
     -       ((nu + a/rb)*y2**2)/(rb + yb3)))/(rb*(rb + yb3)**2) -
     -  (y2*(-a + yb3)*(-2*nu + (-a + ctb*(1 - 2*nu)*y1)/rb +
     -       (a*y2**2)/rb**3 + ((2*nu + a/rb)*y2**2)/(rb*(rb + yb3))))/
     -   (rb*(rb + yb3)**2) -
     -  ((1 - 2*nu)*((a*ctb*y1*y2)/rb**3 -
     -       ((nu + a/rb)*y2**3)/(rb*(rb + yb3)**2) +
     -       (2*(nu + a/rb)*y2)/(rb + yb3) -
     -       (a*y2**3)/(rb**3*(rb + yb3))))/(rb + yb3) +
     -  ((-a + yb3)*((2*a*y2)/rb**3 -
     -       ((-a + ctb*(1 - 2*nu)*y1)*y2)/rb**3 - (3*a*y2**3)/rb**5 -
     -       ((2*nu + a/rb)*y2**3)/(rb**2*(rb + yb3)**2) +
     -       (2*(2*nu + a/rb)*y2)/(rb*(rb + yb3)) -
     -       (a*y2**3)/(rb**4*(rb + yb3)) -
     -       ((2*nu + a/rb)*y2**3)/(rb**3*(rb + yb3))))/(rb + yb3) +
     -  (ctb*(1 - 2*nu)*(cb + a/rb)*y2*zb1)/(rb*(rb + zb3)**2) +
     -  (a*ctb*(1 - 2*nu)*y2*zb1)/(rb**3*(rb + zb3)) +
     -  (1 - 2*nu)*(((2*ctb**2*(1 - nu) - nu)*y2)/(rb*(rb + yb3)) -
     -     (cb*(1 + 2*ctb**2*(1 - nu) - 2*nu)*y2)/(rb*(rb + zb3))) -
     -  (y2*(-a + yb3)*(cb**2 + (a*ctb*yb3*zb1)/rb**3 -
     -       (a*cb + ctb*(1 - 2*nu)*zb1)/rb -
     -       (cb**2*y2**2 - (a*ctb*(cb*rb + yb3)*zb1)/rb)/
     -        (rb*(rb + zb3))))/(rb*(rb + zb3)**2) +
     -  ((-a + yb3)*((-3*a*ctb*y2*yb3*zb1)/rb**5 +
     -       (y2*(a*cb + ctb*(1 - 2*nu)*zb1))/rb**3 +
     -       (y2*(cb**2*y2**2 - (a*ctb*(cb*rb + yb3)*zb1)/rb))/
     -        (rb**2*(rb + zb3)**2) +
     -       (y2*(cb**2*y2**2 - (a*ctb*(cb*rb + yb3)*zb1)/rb))/
     -        (rb**3*(rb + zb3)) -
     -       (2*cb**2*y2 - (a*cb*ctb*y2*zb1)/rb**2 +
     -          (a*ctb*y2*(cb*rb + yb3)*zb1)/rb**3)/(rb*(rb + zb3))))/
     -   (rb + zb3)

      dvc(1,2,3) =
     .  -((a*ctb*y1)/rb**3) + (3*a*ctb*y1*yb3*(-a + yb3))/rb**5 +
     -  ((1 - 2*nu)*(1 + yb3/rb)*
     -     (-a + ctb*(1 - 2*nu - a/rb)*y1 + nu*yb3 +
     -       ((nu + a/rb)*y2**2)/(rb + yb3)))/(rb + yb3)**2 +
     -  (-2*nu + (-a + ctb*(1 - 2*nu)*y1)/rb + (a*y2**2)/rb**3 +
     -     ((2*nu + a/rb)*y2**2)/(rb*(rb + yb3)))/(rb + yb3) -
     -  ((-a + yb3)*(1 + yb3/rb)*
     -     (-2*nu + (-a + ctb*(1 - 2*nu)*y1)/rb + (a*y2**2)/rb**3 +
     -       ((2*nu + a/rb)*y2**2)/(rb*(rb + yb3))))/(rb + yb3)**2 -
     -  ((1 - 2*nu)*(nu + (a*ctb*y1*yb3)/rb**3 -
     -       (a*y2**2*yb3)/(rb**3*(rb + yb3)) -
     -       ((nu + a/rb)*y2**2*(1 + yb3/rb))/(rb + yb3)**2))/(rb + yb3)
     -    + ((-a + yb3)*(-(((-a + ctb*(1 - 2*nu)*y1)*yb3)/rb**3) -
     -       (3*a*y2**2*yb3)/rb**5 - (a*y2**2*yb3)/(rb**4*(rb + yb3)) -
     -       ((2*nu + a/rb)*y2**2*yb3)/(rb**3*(rb + yb3)) -
     -       ((2*nu + a/rb)*y2**2*(1 + yb3/rb))/(rb*(rb + yb3)**2)))/
     -   (rb + yb3) + (ctb*(1 - 2*nu)*(cb + a/rb)*(cb + yb3/rb)*zb1)/
     -   (rb + zb3)**2 - (ctb*(1 - 2*nu)*(cb + a/rb)*sb)/(rb + zb3) +
     -  (a*ctb*(1 - 2*nu)*yb3*zb1)/(rb**3*(rb + zb3)) +
     -  (1 - 2*nu)*(((2*ctb**2*(1 - nu) - nu)*(1 + yb3/rb))/
     -      (rb + yb3) - (cb*(1 + 2*ctb**2*(1 - nu) - 2*nu)*
     -        (cb + yb3/rb))/(rb + zb3)) -
     -  ((-a + yb3)*(cb + yb3/rb)*
     -     (cb**2 + (a*ctb*yb3*zb1)/rb**3 -
     -       (a*cb + ctb*(1 - 2*nu)*zb1)/rb -
     -       (cb**2*y2**2 - (a*ctb*(cb*rb + yb3)*zb1)/rb)/
     -        (rb*(rb + zb3))))/(rb + zb3)**2 +
     -  (cb**2 + (a*ctb*yb3*zb1)/rb**3 -
     -     (a*cb + ctb*(1 - 2*nu)*zb1)/rb -
     -     (cb**2*y2**2 - (a*ctb*(cb*rb + yb3)*zb1)/rb)/(rb*(rb + zb3)))
     -    /(rb + zb3) + ((-a + yb3)*
     -     (-((ctb*(1 - 2*nu)*sb)/rb) + (a*ctb*sb*yb3)/rb**3 +
     -       (a*ctb*zb1)/rb**3 - (3*a*ctb*yb3**2*zb1)/rb**5 +
     -       (yb3*(a*cb + ctb*(1 - 2*nu)*zb1))/rb**3 +
     -       ((cb + yb3/rb)*(cb**2*y2**2 -
     -            (a*ctb*(cb*rb + yb3)*zb1)/rb))/(rb*(rb + zb3)**2) +
     -       (yb3*(cb**2*y2**2 - (a*ctb*(cb*rb + yb3)*zb1)/rb))/
     -        (rb**3*(rb + zb3)) -
     -       (-((a*ctb*sb*(cb*rb + yb3))/rb) +
     -          (a*ctb*yb3*(cb*rb + yb3)*zb1)/rb**3 -
     -          (a*ctb*(1 + (cb*yb3)/rb)*zb1)/rb)/(rb*(rb + zb3))))/
     -   (rb + zb3)

      dvc(1,3,1) =
     .  (y2*(-a + yb3)*((-2*a*y1)/rb**4 -
     -       (2*nu*y1)/(rb*(rb + yb3)**2)))/rb -
     -  (y1*y2*(-a + yb3)*(a/rb**2 + (2*nu)/(rb + yb3)))/rb**3 +
     -  2*(1 - nu)*(-(((2*nu + a/rb)*y1*y2)/(rb*(rb + yb3)**2)) -
     -     (a*y1*y2)/(rb**3*(rb + yb3)) +
     -     ctb*(1 - 2*nu)*y2*
     -      (1/(y1**2 + y2**2) - cb/(y2**2 + zb1**2) +
     -        (sb*(cb*y1*(-rb**2 + y2**2) + (-rb**2 + y1**2)*zb1))/
     -         (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2))) +
     -     (cb*(cb + a/rb)*(-sb + y1/rb)*y2)/(rb + zb3)**2 +
     -     (a*cb*y1*y2)/(rb**3*(rb + zb3))) -
     -  (cb*(-sb + y1/rb)*y2*(-a + yb3)*
     -     (1 - 2*nu - (a*yb3)/rb**2 -
     -       ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/(rb*(rb + zb3)**2)
     -    - (cb*y1*y2*(-a + yb3)*
     -     (1 - 2*nu - (a*yb3)/rb**2 -
     -       ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/(rb**3*(rb + zb3))
     -    + (cb*y2*(-a + yb3)*
     -     ((2*a*y1*yb3)/rb**4 +
     -       ((cb + a/rb)*(-sb + y1/rb)*(cb*rb + yb3))/(rb + zb3)**2 -
     -       (cb*(cb + a/rb)*y1)/(rb*(rb + zb3)) +
     -       (a*y1*(cb*rb + yb3))/(rb**3*(rb + zb3))))/(rb*(rb + zb3))

      dvc(1,3,2) =
     .  (y2*(-a + yb3)*((-2*a*y2)/rb**4 -
     -       (2*nu*y2)/(rb*(rb + yb3)**2)))/rb +
     -  ((-a + yb3)*(a/rb**2 + (2*nu)/(rb + yb3)))/rb -
     -  (y2**2*(-a + yb3)*(a/rb**2 + (2*nu)/(rb + yb3)))/rb**3 +
     -  2*(1 - nu)*(-(((2*nu + a/rb)*y2**2)/(rb*(rb + yb3)**2)) +
     -     (2*nu + a/rb)/(rb + yb3) - (a*y2**2)/(rb**3*(rb + yb3)) +
     -     ctb*(1 - 2*nu)*(-(y1/(y1**2 + y2**2)) +
     -        zb1/(y2**2 + zb1**2) +
     -        (sb*(cb*(-(rb**2*y2**2) + y2**4) +
     -             y1*(rb**2 + y2**2)*zb1))/
     -         (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2))) +
     -     (cb*(cb + a/rb)*y2**2)/(rb*(rb + zb3)**2) -
     -     (cb*(cb + a/rb))/(rb + zb3) + (a*cb*y2**2)/(rb**3*(rb + zb3))
     -     ) - (cb*y2**2*(-a + yb3)*
     -     (1 - 2*nu - (a*yb3)/rb**2 -
     -       ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/
     -   (rb**2*(rb + zb3)**2) +
     -  (cb*(-a + yb3)*(1 - 2*nu - (a*yb3)/rb**2 -
     -       ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/(rb*(rb + zb3)) -
     -  (cb*y2**2*(-a + yb3)*
     -     (1 - 2*nu - (a*yb3)/rb**2 -
     -       ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/(rb**3*(rb + zb3))
     -    + (cb*y2*(-a + yb3)*
     -     ((2*a*y2*yb3)/rb**4 +
     -       ((cb + a/rb)*y2*(cb*rb + yb3))/(rb*(rb + zb3)**2) -
     -       (cb*(cb + a/rb)*y2)/(rb*(rb + zb3)) +
     -       (a*y2*(cb*rb + yb3))/(rb**3*(rb + zb3))))/(rb*(rb + zb3))

      dvc(1,3,3) =
     .  (y2*(a/rb**2 + (2*nu)/(rb + yb3)))/rb -
     -  (y2*yb3*(-a + yb3)*(a/rb**2 + (2*nu)/(rb + yb3)))/rb**3 +
     -  (y2*(-a + yb3)*((-2*a*yb3)/rb**4 -
     -       (2*nu*(1 + yb3/rb))/(rb + yb3)**2))/rb +
     -  2*(1 - nu)*(-((a*y2*yb3)/(rb**3*(rb + yb3))) -
     -     ((2*nu + a/rb)*y2*(1 + yb3/rb))/(rb + yb3)**2 +
     -     ctb*(1 - 2*nu)*sb*y2*
     -      (-(1/(y2**2 + zb1**2)) +
     -        (-(rb**2*sb*y1) + cb*y2**2*yb3 + y1*yb3*zb1)/
     -         (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2))) +
     -     (cb*(cb + a/rb)*y2*(cb + yb3/rb))/(rb + zb3)**2 +
     -     (a*cb*y2*yb3)/(rb**3*(rb + zb3))) -
     -  (cb*y2*(-a + yb3)*(cb + yb3/rb)*
     -     (1 - 2*nu - (a*yb3)/rb**2 -
     -       ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/(rb*(rb + zb3)**2)
     -    + (cb*y2*(1 - 2*nu - (a*yb3)/rb**2 -
     -       ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/(rb*(rb + zb3)) -
     -  (cb*y2*yb3*(-a + yb3)*
     -     (1 - 2*nu - (a*yb3)/rb**2 -
     -       ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/(rb**3*(rb + zb3))
     -    + (cb*y2*(-a + yb3)*
     -     (-(a/rb**2) + (2*a*yb3**2)/rb**4 +
     -       ((cb + a/rb)*(cb*rb + yb3)*(cb + yb3/rb))/(rb + zb3)**2 +
     -       (a*yb3*(cb*rb + yb3))/(rb**3*(rb + zb3)) -
     -       ((cb + a/rb)*(1 + (cb*yb3)/rb))/(rb + zb3)))/
     -   (rb*(rb + zb3))

      dvc(2,1,1) =
     .  -((a*ctb*(-a + yb3))/rb**3) +
     -  (3*a*ctb*y1**2*(-a + yb3))/rb**5 -
     -  ((1 - 2*nu)*y1*(-a + ctb*(-1 + 2*nu)*y1 + (a*ctb*y1)/rb +
     -       nu*yb3 + ((nu + a/rb)*y1**2)/(rb + yb3)))/
     -   (rb*(rb + yb3)**2) -
     -  (y1*(-a + yb3)*(2*nu - (a*y1**2)/rb**3 +
     -       (a + ctb*(1 - 2*nu)*y1)/rb -
     -  ((2*nu + a/rb)*y1**2)/(rb*(rb + yb3))))/(rb*(rb + yb3)**2)
     -   + ((1 - 2*nu)*(ctb*(-1 + 2*nu) + (a*ctb)/rb -
     -       (a*ctb*y1**2)/rb**3 -
     -       ((nu + a/rb)*y1**3)/(rb*(rb + yb3)**2) +
     -       (2*(nu + a/rb)*y1)/(rb + yb3) -
     -       (a*y1**3)/(rb**3*(rb + yb3))))/(rb + yb3) +
     -  ((-a + yb3)*((ctb*(1 - 2*nu))/rb - (2*a*y1)/rb**3 +
     -       (3*a*y1**3)/rb**5 - (y1*(a + ctb*(1 - 2*nu)*y1))/rb**3 +
     -       ((2*nu + a/rb)*y1**3)/(rb**2*(rb + yb3)**2) -
     -       (2*(2*nu + a/rb)*y1)/(rb*(rb + yb3)) +
     -       (a*y1**3)/(rb**4*(rb + yb3)) +
     -       ((2*nu + a/rb)*y1**3)/(rb**3*(rb + yb3))))/(rb + yb3) +
     -  (ctb*(1 - 2*nu)*(-sb + y1/rb)*
     -     (-((a*(rb*sb - y1))/(cb*rb)) + cb*zb1))/(rb + zb3)**2 -
     -  (ctb*(1 - 2*nu)*(cb**2 + (a*(rb*sb - y1)*y1)/(cb*rb**3) -
     -       (a*(-1 + (sb*y1)/rb))/(cb*rb)))/(rb + zb3) +
     -  (1 - 2*nu)*(((2*ctb**2*(1 - nu) + nu)*y1)/(rb*(rb + yb3)) -
     -     (cb*(1 + 2*ctb**2*(1 - nu))*(-sb + y1/rb))/(rb + zb3)) -
     -  (ctb*(-sb + y1/rb)*(-a + yb3)*
     -     (-(cb*sb) + (a*y1*yb3)/(cb*rb**3) +
     -       ((rb*sb - y1)*(2*cb*(1 - nu) -
     -            ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/rb))/
     -   (rb + zb3)**2 + (ctb*(-a + yb3)*
     -     ((a*yb3)/(cb*rb**3) - (3*a*y1**2*yb3)/(cb*rb**5) -
     -       ((rb*sb - y1)*y1*
     -          (2*cb*(1 - nu) -
     -  ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/rb**3 +
     -       ((-1 + (sb*y1)/rb)*
     -          (2*cb*(1 - nu) -
     -            ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/rb +
     -       ((rb*sb - y1)*(((1 + a/(cb*rb))*(-sb + y1/rb)*
     -               (cb*rb + yb3))/(rb + zb3)**2 -
     -            (cb*(1 + a/(cb*rb))*y1)/(rb*(rb + zb3)) +
     -            (a*y1*(cb*rb + yb3))/(cb*rb**3*(rb + zb3))))/rb))/
     -   (rb + zb3)

      dvc(2,1,2) =
     .  (3*a*ctb*y1*y2*(-a + yb3))/rb**5 -
     -  ((1 - 2*nu)*y2*(-a + ctb*(-1 + 2*nu)*y1 + (a*ctb*y1)/rb +
     -       nu*yb3 + ((nu + a/rb)*y1**2)/(rb + yb3)))/
     -   (rb*(rb + yb3)**2) -
     -  (y2*(-a + yb3)*(2*nu - (a*y1**2)/rb**3 +
     -       (a + ctb*(1 - 2*nu)*y1)/rb -
     - ((2*nu + a/rb)*y1**2)/(rb*(rb + yb3))))/(rb*(rb + yb3)**2)
     -   + ((1 - 2*nu)*(-((a*ctb*y1*y2)/rb**3) -
     -       ((nu + a/rb)*y1**2*y2)/(rb*(rb + yb3)**2) -
     -       (a*y1**2*y2)/(rb**3*(rb + yb3))))/(rb + yb3) +
     -  ((-a + yb3)*((3*a*y1**2*y2)/rb**5 -
     -       ((a + ctb*(1 - 2*nu)*y1)*y2)/rb**3 +
     -       ((2*nu + a/rb)*y1**2*y2)/(rb**2*(rb + yb3)**2) +
     -       (a*y1**2*y2)/(rb**4*(rb + yb3)) +
     - ((2*nu + a/rb)*y1**2*y2)/(rb**3*(rb + yb3))))/(rb + yb3) +
     -  (ctb*(1 - 2*nu)*y2*(-((a*(rb*sb - y1))/(cb*rb)) + cb*zb1))/
     -   (rb*(rb + zb3)**2) -
     -  (ctb*(1 - 2*nu)*(-((a*sb*y2)/(cb*rb**2)) +
     -       (a*(rb*sb - y1)*y2)/(cb*rb**3)))/(rb + zb3) +
     -  (1 - 2*nu)*(((2*ctb**2*(1 - nu) + nu)*y2)/(rb*(rb + yb3)) -
     -     (cb*(1 + 2*ctb**2*(1 - nu))*y2)/(rb*(rb + zb3))) -
     -  (ctb*y2*(-a + yb3)*(-(cb*sb) + (a*y1*yb3)/(cb*rb**3) +
     -       ((rb*sb - y1)*(2*cb*(1 - nu) -
     -            ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/rb))/
     -   (rb*(rb + zb3)**2) +
     -  (ctb*(-a + yb3)*((-3*a*y1*y2*yb3)/(cb*rb**5) +
     -       (sb*y2*(2*cb*(1 - nu) -
     -            ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/rb**2 -
     -       ((rb*sb - y1)*y2*
     -          (2*cb*(1 - nu) -
     -            ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/rb**3 +
     -       ((rb*sb - y1)*(((1 + a/(cb*rb))*y2*(cb*rb + yb3))/
     -             (rb*(rb + zb3)**2) -
     -            (cb*(1 + a/(cb*rb))*y2)/(rb*(rb + zb3)) +
     -            (a*y2*(cb*rb + yb3))/(cb*rb**3*(rb + zb3))))/rb))/
     -   (rb + zb3)

      dvc(2,1,3) =
     .  -((a*ctb*y1)/rb**3) + (3*a*ctb*y1*yb3*(-a + yb3))/rb**5 -
     -  ((1 - 2*nu)*(1 + yb3/rb)*
     -     (-a + ctb*(-1 + 2*nu)*y1 + (a*ctb*y1)/rb + nu*yb3 +
     -       ((nu + a/rb)*y1**2)/(rb + yb3)))/(rb + yb3)**2 +
     -  (2*nu - (a*y1**2)/rb**3 + (a + ctb*(1 - 2*nu)*y1)/rb -
     -     ((2*nu + a/rb)*y1**2)/(rb*(rb + yb3)))/(rb + yb3) -
     -  ((-a + yb3)*(1 + yb3/rb)*
     -     (2*nu - (a*y1**2)/rb**3 + (a + ctb*(1 - 2*nu)*y1)/rb -
     -       ((2*nu + a/rb)*y1**2)/(rb*(rb + yb3))))/(rb + yb3)**2 +
     -  ((1 - 2*nu)*(nu - (a*ctb*y1*yb3)/rb**3 -
     -       (a*y1**2*yb3)/(rb**3*(rb + yb3)) -
     -       ((nu + a/rb)*y1**2*(1 + yb3/rb))/(rb + yb3)**2))/(rb + yb3)
     -    + ((-a + yb3)*((3*a*y1**2*yb3)/rb**5 -
     -       ((a + ctb*(1 - 2*nu)*y1)*yb3)/rb**3 +
     -       (a*y1**2*yb3)/(rb**4*(rb + yb3)) +
     -       ((2*nu + a/rb)*y1**2*yb3)/(rb**3*(rb + yb3)) +
     -       ((2*nu + a/rb)*y1**2*(1 + yb3/rb))/(rb*(rb + yb3)**2)))/
     -   (rb + yb3) + (ctb*(1 - 2*nu)*(cb + yb3/rb)*
     -     (-((a*(rb*sb - y1))/(cb*rb)) + cb*zb1))/(rb + zb3)**2 -
     -  (ctb*(1 - 2*nu)*(cb*sb - (a*sb*yb3)/(cb*rb**2) +
     -       (a*(rb*sb - y1)*yb3)/(cb*rb**3)))/(rb + zb3) +
     -  (1 - 2*nu)*(((2*ctb**2*(1 - nu) + nu)*(1 + yb3/rb))/
     -      (rb + yb3) - (cb*(1 + 2*ctb**2*(1 - nu))*(cb + yb3/rb))/
     -      (rb + zb3)) - (ctb*(-a + yb3)*(cb + yb3/rb)*
     -     (-(cb*sb) + (a*y1*yb3)/(cb*rb**3) +
     -       ((rb*sb - y1)*(2*cb*(1 - nu) -
     -            ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/rb))/
     -   (rb + zb3)**2 + (ctb*
     -     (-(cb*sb) + (a*y1*yb3)/(cb*rb**3) +
     -       ((rb*sb - y1)*(2*cb*(1 - nu) -
     -            ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/rb))/
     -   (rb + zb3) + (ctb*(-a + yb3)*
     -     ((a*y1)/(cb*rb**3) - (3*a*y1*yb3**2)/(cb*rb**5) +
     -       (sb*yb3*(2*cb*(1 - nu) -
     -            ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/rb**2 -
     -       ((rb*sb - y1)*yb3*
     -          (2*cb*(1 - nu) -
     -            ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/rb**3 +
     -       ((rb*sb - y1)*(((1 + a/(cb*rb))*(cb*rb + yb3)*
     -               (cb + yb3/rb))/(rb + zb3)**2 +
     -            (a*yb3*(cb*rb + yb3))/(cb*rb**3*(rb + zb3)) -
     -            ((1 + a/(cb*rb))*(1 + (cb*yb3)/rb))/(rb + zb3)))/rb))/
     -   (rb + zb3)

      dvc(2,2,1) =
     .  (3*a*ctb*y1*y2*(-a + yb3))/rb**5 -
     -  ((1 - 2*nu)*y1*y2*(ctb*(-1 + 2*nu + a/rb) +
     -       ((nu + a/rb)*y1)/(rb + yb3)))/(rb*(rb + yb3)**2) +
     -  ((1 - 2*nu)*y2*(-((a*ctb*y1)/rb**3) -
     -       ((nu + a/rb)*y1**2)/(rb*(rb + yb3)**2) +
     -       (nu + a/rb)/(rb + yb3) - (a*y1**2)/(rb**3*(rb + yb3))))/
     -   (rb + yb3) - (y1*y2*(-a + yb3)*
     -     (ctb*(1 - 2*nu) - (2*nu*y1)/(rb + yb3) -
     -       (a*y1*(1/rb + 1/(rb + yb3)))/rb))/(rb**2*(rb + yb3)**2) -
     -  (y1*y2*(-a + yb3)*(ctb*(1 - 2*nu) - (2*nu*y1)/(rb + yb3) -
     -       (a*y1*(1/rb + 1/(rb + yb3)))/rb))/(rb**3*(rb + yb3)) +
     -  (y2*(-a + yb3)*((2*nu*y1**2)/(rb*(rb + yb3)**2) -
     -       (2*nu)/(rb + yb3) -
     -       (a*y1*(-(y1/rb**3) - y1/(rb*(rb + yb3)**2)))/rb -
     -       (a*(1/rb + 1/(rb + yb3)))/rb +
     -       (a*y1**2*(1/rb + 1/(rb + yb3)))/rb**3))/(rb*(rb + yb3)) +
     -  2*ctb**2*(1 - 2*nu)*(1 - nu)*y2*
     -   (1/(y1**2 + y2**2) - cb/(y2**2 + zb1**2) +
     -     (sb*(cb*y1*(-rb**2 + y2**2) + (-rb**2 + y1**2)*zb1))/
     -      (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2))) +
     -  (ctb*(1 - 2*nu)*(1 + a/(cb*rb))*(-sb + y1/rb)*y2)/
     -   (rb + zb3)**2 + (a*ctb*(1 - 2*nu)*y1*y2)/
     -   (cb*rb**3*(rb + zb3)) -
     -  (ctb*(-sb + y1/rb)*y2*(-a + yb3)*
     -     (-2*cb*(1 - nu) + (a*yb3)/(cb*rb**2) +
     -       ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/
     -   (rb*(rb + zb3)**2) -
     -  (ctb*y1*y2*(-a + yb3)*
     -     (-2*cb*(1 - nu) + (a*yb3)/(cb*rb**2) +
     -       ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/
     -   (rb**3*(rb + zb3)) +
     -  (ctb*y2*(-a + yb3)*((-2*a*y1*yb3)/(cb*rb**4) -
     -       ((1 + a/(cb*rb))*(-sb + y1/rb)*(cb*rb + yb3))/
     -        (rb + zb3)**2 + (cb*(1 + a/(cb*rb))*y1)/(rb*(rb + zb3)) -
     -       (a*y1*(cb*rb + yb3))/(cb*rb**3*(rb + zb3))))/
     -   (rb*(rb + zb3))

      dvc(2,2,2) =
     .  -((a*ctb*(-a + yb3))/rb**3) +
     -  (3*a*ctb*y2**2*(-a + yb3))/rb**5 -
     -  ((1 - 2*nu)*y2**2*(ctb*(-1 + 2*nu + a/rb) +
     -       ((nu + a/rb)*y1)/(rb + yb3)))/(rb*(rb + yb3)**2) +
     -  ((1 - 2*nu)*(ctb*(-1 + 2*nu + a/rb) +
     -       ((nu + a/rb)*y1)/(rb + yb3)))/(rb + yb3) +
     -  ((1 - 2*nu)*y2*(-((a*ctb*y2)/rb**3) -
     -       ((nu + a/rb)*y1*y2)/(rb*(rb + yb3)**2) -
     -       (a*y1*y2)/(rb**3*(rb + yb3))))/(rb + yb3) -
     -  (y2**2*(-a + yb3)*(ctb*(1 - 2*nu) - (2*nu*y1)/(rb + yb3) -
     -       (a*y1*(1/rb + 1/(rb + yb3)))/rb))/(rb**2*(rb + yb3)**2) +
     -  ((-a + yb3)*(ctb*(1 - 2*nu) - (2*nu*y1)/(rb + yb3) -
     -       (a*y1*(1/rb + 1/(rb + yb3)))/rb))/(rb*(rb + yb3)) -
     -  (y2**2*(-a + yb3)*(ctb*(1 - 2*nu) - (2*nu*y1)/(rb + yb3) -
     -       (a*y1*(1/rb + 1/(rb + yb3)))/rb))/(rb**3*(rb + yb3)) +
     -  (y2*(-a + yb3)*((2*nu*y1*y2)/(rb*(rb + yb3)**2) -
     -       (a*y1*(-(y2/rb**3) - y2/(rb*(rb + yb3)**2)))/rb +
     -       (a*y1*y2*(1/rb + 1/(rb + yb3)))/rb**3))/(rb*(rb + yb3)) +
     -  2*ctb**2*(1 - 2*nu)*(1 - nu)*
     -   (-(y1/(y1**2 + y2**2)) + zb1/(y2**2 + zb1**2) +
     -     (sb*(cb*(-(rb**2*y2**2) + y2**4) + y1*(rb**2 + y2**2)*zb1))/
     -      (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2))) +
     -  (ctb*(1 - 2*nu)*(1 + a/(cb*rb))*y2**2)/(rb*(rb + zb3)**2) -
     -  (ctb*(1 - 2*nu)*(1 + a/(cb*rb)))/(rb + zb3) +
     -  (a*ctb*(1 - 2*nu)*y2**2)/(cb*rb**3*(rb + zb3)) -
     -  (ctb*y2**2*(-a + yb3)*
     -     (-2*cb*(1 - nu) + (a*yb3)/(cb*rb**2) +
     -       ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/
     -   (rb**2*(rb + zb3)**2) +
     -  (ctb*(-a + yb3)*(-2*cb*(1 - nu) + (a*yb3)/(cb*rb**2) +
     -       ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/
     -   (rb*(rb + zb3)) - (ctb*y2**2*(-a + yb3)*
     -     (-2*cb*(1 - nu) + (a*yb3)/(cb*rb**2) +
     -       ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/
     -   (rb**3*(rb + zb3)) +
     -  (ctb*y2*(-a + yb3)*((-2*a*y2*yb3)/(cb*rb**4) -
     -       ((1 + a/(cb*rb))*y2*(cb*rb + yb3))/(rb*(rb + zb3)**2) +
     -       (cb*(1 + a/(cb*rb))*y2)/(rb*(rb + zb3)) -
     -       (a*y2*(cb*rb + yb3))/(cb*rb**3*(rb + zb3))))/
     -   (rb*(rb + zb3))

      dvc(2,2,3) =
     .  -((a*ctb*y2)/rb**3) + (3*a*ctb*y2*yb3*(-a + yb3))/rb**5 -
     -  ((1 - 2*nu)*y2*(1 + yb3/rb)*
     -     (ctb*(-1 + 2*nu + a/rb) + ((nu + a/rb)*y1)/(rb + yb3)))/
     -   (rb + yb3)**2 + ((1 - 2*nu)*y2*
     -     (-((a*ctb*yb3)/rb**3) - (a*y1*yb3)/(rb**3*(rb + yb3)) -
     -       ((nu + a/rb)*y1*(1 + yb3/rb))/(rb + yb3)**2))/(rb + yb3) +
     -  (y2*(ctb*(1 - 2*nu) - (2*nu*y1)/(rb + yb3) -
     -       (a*y1*(1/rb + 1/(rb + yb3)))/rb))/(rb*(rb + yb3)) -
     -  (y2*yb3*(-a + yb3)*(ctb*(1 - 2*nu) - (2*nu*y1)/(rb + yb3) -
     -       (a*y1*(1/rb + 1/(rb + yb3)))/rb))/(rb**3*(rb + yb3)) -
     -  (y2*(-a + yb3)*(1 + yb3/rb)*
     -     (ctb*(1 - 2*nu) - (2*nu*y1)/(rb + yb3) -
     -       (a*y1*(1/rb + 1/(rb + yb3)))/rb))/(rb*(rb + yb3)**2) +
     -  (y2*(-a + yb3)*((2*nu*y1*(1 + yb3/rb))/(rb + yb3)**2 +
     -       (a*y1*yb3*(1/rb + 1/(rb + yb3)))/rb**3 -
     -       (a*y1*(-(yb3/rb**3) - (1 + yb3/rb)/(rb + yb3)**2))/rb))/
     -   (rb*(rb + yb3)) + 2*ctb**2*(1 - 2*nu)*(1 - nu)*sb*y2*
     -   (-(1/(y2**2 + zb1**2)) +
     -     (-(rb**2*sb*y1) + cb*y2**2*yb3 + y1*yb3*zb1)/
     -      (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2))) +
     -  (ctb*(1 - 2*nu)*(1 + a/(cb*rb))*y2*(cb + yb3/rb))/
     -   (rb + zb3)**2 + (a*ctb*(1 - 2*nu)*y2*yb3)/
     -   (cb*rb**3*(rb + zb3)) -
     -  (ctb*y2*(-a + yb3)*(cb + yb3/rb)*
     -     (-2*cb*(1 - nu) + (a*yb3)/(cb*rb**2) +
     -       ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/
     -   (rb*(rb + zb3)**2) +
     -  (ctb*y2*(-2*cb*(1 - nu) + (a*yb3)/(cb*rb**2) +
     -       ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/
     -   (rb*(rb + zb3)) - (ctb*y2*yb3*(-a + yb3)*
     -     (-2*cb*(1 - nu) + (a*yb3)/(cb*rb**2) +
     -       ((1 + a/(cb*rb))*(cb*rb + yb3))/(rb + zb3)))/
     -   (rb**3*(rb + zb3)) +
     -  (ctb*y2*(-a + yb3)*(a/(cb*rb**2) - (2*a*yb3**2)/(cb*rb**4) -
     -       ((1 + a/(cb*rb))*(cb*rb + yb3)*(cb + yb3/rb))/
     -        (rb + zb3)**2 -
     -       (a*yb3*(cb*rb + yb3))/(cb*rb**3*(rb + zb3)) +
     -       ((1 + a/(cb*rb))*(1 + (cb*yb3)/rb))/(rb + zb3)))/
     -   (rb*(rb + zb3))

      dvc(2,3,1) =
     .  (2*(1 - nu)*(2*nu + a/rb)*y1**2)/(rb*(rb + yb3)**2) -
     -  (2*(1 - nu)*(2*nu + a/rb))/(rb + yb3) +
     -  (2*a*(1 - nu)*y1**2)/(rb**3*(rb + yb3)) +
     -  ((-a + yb3)*(-(a/rb**2) + (2*a*y1**2)/rb**4 +
     -       (2*nu*y1**2)/(rb*(rb + yb3)**2) - (2*nu)/(rb + yb3)))/rb -
     -  (y1*(-a + yb3)*(ctb*(1 - 2*nu) - (a*y1)/rb**2 -
     -       (2*nu*y1)/(rb + yb3)))/rb**3 -
     -  (2*(1 - nu)*(cb + a/rb)*(-sb + y1/rb)*zb1)/(rb + zb3)**2 +
     -  (2*cb*(1 - nu)*(cb + a/rb))/(rb + zb3) -
     -  (2*a*(1 - nu)*y1*zb1)/(rb**3*(rb + zb3)) -
     -  2*ctb*(1 - 2*nu)*(1 - nu)*
     -   (y1/(rb*(rb + yb3)) - (cb*(-sb + y1/rb))/(rb + zb3)) +
     -  ((-sb + y1/rb)*(-a + yb3)*
     -     (cb*sb + (ctb*(cb*rb + yb3)*
     -          (2*cb*(1 - nu) - (cb*rb + yb3)/(rb + zb3)))/rb +
     -       (a*(sb - (yb3*zb1)/rb**2 -
     -            ((cb*rb + yb3)*zb1)/(rb*(rb + zb3))))/rb))/
     -   (rb + zb3)**2 - ((-a + yb3)*
     -     ((ctb*(cb*rb + yb3)*
     -          (((-sb + y1/rb)*(cb*rb + yb3))/(rb + zb3)**2 -
     -            (cb*y1)/(rb*(rb + zb3))))/rb +
     -       (cb*ctb*y1*(2*cb*(1 - nu) - (cb*rb + yb3)/(rb + zb3)))/
     -        rb**2 - (ctb*y1*(cb*rb + yb3)*
     -          (2*cb*(1 - nu) - (cb*rb + yb3)/(rb + zb3)))/rb**3 -
     -       (a*y1*(sb - (yb3*zb1)/rb**2 -
     -            ((cb*rb + yb3)*zb1)/(rb*(rb + zb3))))/rb**3 +
     -       (a*(-((cb*yb3)/rb**2) + (2*y1*yb3*zb1)/rb**4 +
     -            ((-sb + y1/rb)*(cb*rb + yb3)*zb1)/
     -             (rb*(rb + zb3)**2) -
     -            (cb*(cb*rb + yb3))/(rb*(rb + zb3)) -
     -            (cb*y1*zb1)/(rb**2*(rb + zb3)) +
     -            (y1*(cb*rb + yb3)*zb1)/(rb**3*(rb + zb3))))/rb))/
     -   (rb + zb3)

      dvc(2,3,2) =
     .  (2*(1 - nu)*(2*nu + a/rb)*y1*y2)/(rb*(rb + yb3)**2) +
     -  (2*a*(1 - nu)*y1*y2)/(rb**3*(rb + yb3)) +
     -  ((-a + yb3)*((2*a*y1*y2)/rb**4 +
     -       (2*nu*y1*y2)/(rb*(rb + yb3)**2)))/rb -
     -  (y2*(-a + yb3)*(ctb*(1 - 2*nu) - (a*y1)/rb**2 -
     -       (2*nu*y1)/(rb + yb3)))/rb**3 -
     -  (2*(1 - nu)*(cb + a/rb)*y2*zb1)/(rb*(rb + zb3)**2) -
     -  (2*a*(1 - nu)*y2*zb1)/(rb**3*(rb + zb3)) -
     -  2*ctb*(1 - 2*nu)*(1 - nu)*
     -   (y2/(rb*(rb + yb3)) - (cb*y2)/(rb*(rb + zb3))) +
     -  (y2*(-a + yb3)*(cb*sb +
     -       (ctb*(cb*rb + yb3)*
     -          (2*cb*(1 - nu) - (cb*rb + yb3)/(rb + zb3)))/rb +
     -       (a*(sb - (yb3*zb1)/rb**2 -
     -            ((cb*rb + yb3)*zb1)/(rb*(rb + zb3))))/rb))/
     -   (rb*(rb + zb3)**2) -
     -  ((-a + yb3)*((ctb*(cb*rb + yb3)*
     -          ((y2*(cb*rb + yb3))/(rb*(rb + zb3)**2) -
     -            (cb*y2)/(rb*(rb + zb3))))/rb +
     -       (cb*ctb*y2*(2*cb*(1 - nu) - (cb*rb + yb3)/(rb + zb3)))/
     -        rb**2 - (ctb*y2*(cb*rb + yb3)*
     -          (2*cb*(1 - nu) - (cb*rb + yb3)/(rb + zb3)))/rb**3 -
     -       (a*y2*(sb - (yb3*zb1)/rb**2 -
     -            ((cb*rb + yb3)*zb1)/(rb*(rb + zb3))))/rb**3 +
     -       (a*((2*y2*yb3*zb1)/rb**4 +
     -            (y2*(cb*rb + yb3)*zb1)/(rb**2*(rb + zb3)**2) -
     -            (cb*y2*zb1)/(rb**2*(rb + zb3)) +
     -            (y2*(cb*rb + yb3)*zb1)/(rb**3*(rb + zb3))))/rb))/
     -   (rb + zb3)

      dvc(2,3,3) =
     .  (2*a*(1 - nu)*y1*yb3)/(rb**3*(rb + yb3)) +
     -  (2*(1 - nu)*(2*nu + a/rb)*y1*(1 + yb3/rb))/(rb + yb3)**2 +
     -  (ctb*(1 - 2*nu) - (a*y1)/rb**2 - (2*nu*y1)/(rb + yb3))/rb -
     -  (yb3*(-a + yb3)*(ctb*(1 - 2*nu) - (a*y1)/rb**2 -
     -       (2*nu*y1)/(rb + yb3)))/rb**3 +
     -  ((-a + yb3)*((2*a*y1*yb3)/rb**4 +
     -       (2*nu*y1*(1 + yb3/rb))/(rb + yb3)**2))/rb -
     -  (2*(1 - nu)*(cb + a/rb)*(cb + yb3/rb)*zb1)/(rb + zb3)**2 +
     -  (2*(1 - nu)*(cb + a/rb)*sb)/(rb + zb3) -
     -  (2*a*(1 - nu)*yb3*zb1)/(rb**3*(rb + zb3)) -
     -  2*ctb*(1 - 2*nu)*(1 - nu)*
     -   ((1 + yb3/rb)/(rb + yb3) - (cb*(cb + yb3/rb))/(rb + zb3)) +
     -  ((-a + yb3)*(cb + yb3/rb)*
     -     (cb*sb + (ctb*(cb*rb + yb3)*
     -          (2*cb*(1 - nu) - (cb*rb + yb3)/(rb + zb3)))/rb +
     -       (a*(sb - (yb3*zb1)/rb**2 -
     -            ((cb*rb + yb3)*zb1)/(rb*(rb + zb3))))/rb))/
     -   (rb + zb3)**2 - (cb*sb +
     -     (ctb*(cb*rb + yb3)*
     -        (2*cb*(1 - nu) - (cb*rb + yb3)/(rb + zb3)))/rb +
     -     (a*(sb - (yb3*zb1)/rb**2 -
     -          ((cb*rb + yb3)*zb1)/(rb*(rb + zb3))))/rb)/(rb + zb3) -
     -  ((-a + yb3)*(-((ctb*yb3*(cb*rb + yb3)*
     -            (2*cb*(1 - nu) - (cb*rb + yb3)/(rb + zb3)))/rb**3) +
     -       (ctb*(1 + (cb*yb3)/rb)*
     -          (2*cb*(1 - nu) - (cb*rb + yb3)/(rb + zb3)))/rb +
     -       (ctb*(cb*rb + yb3)*
     -          (((cb*rb + yb3)*(cb + yb3/rb))/(rb + zb3)**2 -
     -            (1 + (cb*yb3)/rb)/(rb + zb3)))/rb -
     -       (a*yb3*(sb - (yb3*zb1)/rb**2 -
     -            ((cb*rb + yb3)*zb1)/(rb*(rb + zb3))))/rb**3 +
     -       (a*(-((sb*yb3)/rb**2) - zb1/rb**2 + (2*yb3**2*zb1)/rb**4 +
     -            ((cb*rb + yb3)*(cb + yb3/rb)*zb1)/
     -             (rb*(rb + zb3)**2) -
     -            (sb*(cb*rb + yb3))/(rb*(rb + zb3)) +
     -            (yb3*(cb*rb + yb3)*zb1)/(rb**3*(rb + zb3)) -
     -            ((1 + (cb*yb3)/rb)*zb1)/(rb*(rb + zb3))))/rb))/
     -   (rb + zb3)

      dvc(3,1,1) =
     .  -((y2*(-a + yb3)*((-2*a*y1)/rb**4 - y1/(rb*(rb + yb3)**2)))/
     -     rb) + (y1*y2*(-a + yb3)*(a/rb**2 + 1/(rb + yb3)))/rb**3 +
     -  (1 - 2*nu)*(-(((1 + a/rb)*y1*y2)/(rb*(rb + yb3)**2)) -
     -     (a*y1*y2)/(rb**3*(rb + yb3)) +
     -     (cb*(cb + a/rb)*(-sb + y1/rb)*y2)/(rb + zb3)**2 +
     -     (a*cb*y1*y2)/(rb**3*(rb + zb3))) -
     -  (cb*(-sb + y1/rb)*y2*(-a + yb3)*
     -     ((a*yb3)/rb**2 + ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/
     -   (rb*(rb + zb3)**2) -
     -  (cb*y1*y2*(-a + yb3)*
     -     ((a*yb3)/rb**2 + ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/
     -   (rb**3*(rb + zb3)) +
     -  (cb*y2*(-a + yb3)*((-2*a*y1*yb3)/rb**4 -
     -       ((cb + a/rb)*(-sb + y1/rb)*(cb*rb + yb3))/(rb + zb3)**2 +
     -       (cb*(cb + a/rb)*y1)/(rb*(rb + zb3)) -
     -       (a*y1*(cb*rb + yb3))/(rb**3*(rb + zb3))))/(rb*(rb + zb3))

      dvc(3,1,2) =
     .  -((y2*(-a + yb3)*((-2*a*y2)/rb**4 - y2/(rb*(rb + yb3)**2)))/
     -     rb) - ((-a + yb3)*(a/rb**2 + 1/(rb + yb3)))/rb +
     -  (y2**2*(-a + yb3)*(a/rb**2 + 1/(rb + yb3)))/rb**3 +
     -  (1 - 2*nu)*(-(((1 + a/rb)*y2**2)/(rb*(rb + yb3)**2)) +
     -     (1 + a/rb)/(rb + yb3) - (a*y2**2)/(rb**3*(rb + yb3)) +
     -     (cb*(cb + a/rb)*y2**2)/(rb*(rb + zb3)**2) -
     -     (cb*(cb + a/rb))/(rb + zb3) + (a*cb*y2**2)/(rb**3*(rb + zb3))
     -     ) - (cb*y2**2*(-a + yb3)*
     -     ((a*yb3)/rb**2 + ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/
     -   (rb**2*(rb + zb3)**2) +
     -  (cb*(-a + yb3)*((a*yb3)/rb**2 +
     -       ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/(rb*(rb + zb3)) -
     -  (cb*y2**2*(-a + yb3)*
     -     ((a*yb3)/rb**2 + ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/
     -   (rb**3*(rb + zb3)) +
     -  (cb*y2*(-a + yb3)*((-2*a*y2*yb3)/rb**4 -
     -       ((cb + a/rb)*y2*(cb*rb + yb3))/(rb*(rb + zb3)**2) +
     -       (cb*(cb + a/rb)*y2)/(rb*(rb + zb3)) -
     -       (a*y2*(cb*rb + yb3))/(rb**3*(rb + zb3))))/(rb*(rb + zb3))

      dvc(3,1,3) =
     .  -((y2*(a/rb**2 + 1/(rb + yb3)))/rb) +
     -  (y2*yb3*(-a + yb3)*(a/rb**2 + 1/(rb + yb3)))/rb**3 -
     -  (y2*(-a + yb3)*((-2*a*yb3)/rb**4 - (1 + yb3/rb)/(rb + yb3)**2))/
     -   rb + (1 - 2*nu)*(-((a*y2*yb3)/(rb**3*(rb + yb3))) -
     -     ((1 + a/rb)*y2*(1 + yb3/rb))/(rb + yb3)**2 +
     -     (cb*(cb + a/rb)*y2*(cb + yb3/rb))/(rb + zb3)**2 +
     -     (a*cb*y2*yb3)/(rb**3*(rb + zb3))) -
     -  (cb*y2*(-a + yb3)*(cb + yb3/rb)*
     -     ((a*yb3)/rb**2 + ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/
     -   (rb*(rb + zb3)**2) +
     -  (cb*y2*((a*yb3)/rb**2 +
     -       ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/(rb*(rb + zb3)) -
     -  (cb*y2*yb3*(-a + yb3)*
     -     ((a*yb3)/rb**2 + ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/
     -   (rb**3*(rb + zb3)) +
     -  (cb*y2*(-a + yb3)*(a/rb**2 - (2*a*yb3**2)/rb**4 -
     -       ((cb + a/rb)*(cb*rb + yb3)*(cb + yb3/rb))/(rb + zb3)**2 -
     -       (a*yb3*(cb*rb + yb3))/(rb**3*(rb + zb3)) +
     -       ((cb + a/rb)*(1 + (cb*yb3)/rb))/(rb + zb3)))/
     -   (rb*(rb + zb3))

      dvc(3,2,1) =
     .  (y1*(-a + yb3)*((-2*a*y1)/rb**4 - y1/(rb*(rb + yb3)**2)))/rb +
     -  ((-a + yb3)*(a/rb**2 + 1/(rb + yb3)))/rb -
     -  (y1**2*(-a + yb3)*(a/rb**2 + 1/(rb + yb3)))/rb**3 +
     -  (1 - 2*nu)*(((1 + a/rb)*y1**2)/(rb*(rb + yb3)**2) -
     -     (1 + a/rb)/(rb + yb3) + (a*y1**2)/(rb**3*(rb + yb3)) -
     -     ((cb + a/rb)*(-sb + y1/rb)*zb1)/(rb + zb3)**2 +
     -     (cb*(cb + a/rb))/(rb + zb3) -
     -     (sb*(-sb + y1/rb))/(rb + zb3) - (a*y1*zb1)/(rb**3*(rb + zb3))
     -     ) + ((-sb + y1/rb)*(-a + yb3)*
     -     ((cb - a/rb)*sb + ((1 + (a*yb3)/rb**2)*zb1)/rb -
     -       (cb*sb*y2**2 - (a*(cb*rb + yb3)*zb1)/rb)/(rb*(rb + zb3))))/
     -   (rb + zb3)**2 - ((-a + yb3)*
     -     ((a*sb*y1)/rb**3 + (cb*(1 + (a*yb3)/rb**2))/rb -
     -       (2*a*y1*yb3*zb1)/rb**5 -
     -       (y1*(1 + (a*yb3)/rb**2)*zb1)/rb**3 +
     -       ((-sb + y1/rb)*(cb*sb*y2**2 - (a*(cb*rb + yb3)*zb1)/rb))/
     -        (rb*(rb + zb3)**2) +
     -       (y1*(cb*sb*y2**2 - (a*(cb*rb + yb3)*zb1)/rb))/
     -        (rb**3*(rb + zb3)) -
     -       (-((a*cb*(cb*rb + yb3))/rb) - (a*cb*y1*zb1)/rb**2 +
     -          (a*y1*(cb*rb + yb3)*zb1)/rb**3)/(rb*(rb + zb3))))/
     -   (rb + zb3)

      dvc(3,2,2) =
     .  (y1*(-a + yb3)*((-2*a*y2)/rb**4 - y2/(rb*(rb + yb3)**2)))/rb -
     -  (y1*y2*(-a + yb3)*(a/rb**2 + 1/(rb + yb3)))/rb**3 +
     -  (1 - 2*nu)*(((1 + a/rb)*y1*y2)/(rb*(rb + yb3)**2) +
     -     (a*y1*y2)/(rb**3*(rb + yb3)) -
     -     ((cb + a/rb)*y2*zb1)/(rb*(rb + zb3)**2) -
     -     (sb*y2)/(rb*(rb + zb3)) - (a*y2*zb1)/(rb**3*(rb + zb3))) +
     -  (y2*(-a + yb3)*((cb - a/rb)*sb + ((1 + (a*yb3)/rb**2)*zb1)/rb -
     -       (cb*sb*y2**2 - (a*(cb*rb + yb3)*zb1)/rb)/(rb*(rb + zb3))))/
     -   (rb*(rb + zb3)**2) -
     -  ((-a + yb3)*((a*sb*y2)/rb**3 - (2*a*y2*yb3*zb1)/rb**5 -
     -       (y2*(1 + (a*yb3)/rb**2)*zb1)/rb**3 +
     -       (y2*(cb*sb*y2**2 - (a*(cb*rb + yb3)*zb1)/rb))/
     -        (rb**2*(rb + zb3)**2) +
     -       (y2*(cb*sb*y2**2 - (a*(cb*rb + yb3)*zb1)/rb))/
     -        (rb**3*(rb + zb3)) -
     -       (2*cb*sb*y2 - (a*cb*y2*zb1)/rb**2 +
     -          (a*y2*(cb*rb + yb3)*zb1)/rb**3)/(rb*(rb + zb3))))/
     -   (rb + zb3)

      dvc(3,2,3) =
     .  (y1*(a/rb**2 + 1/(rb + yb3)))/rb -
     -  (y1*yb3*(-a + yb3)*(a/rb**2 + 1/(rb + yb3)))/rb**3 +
     -  (y1*(-a + yb3)*((-2*a*yb3)/rb**4 - (1 + yb3/rb)/(rb + yb3)**2))/
     -   rb + (1 - 2*nu)*((a*y1*yb3)/(rb**3*(rb + yb3)) +
     -     ((1 + a/rb)*y1*(1 + yb3/rb))/(rb + yb3)**2 -
     -     ((cb + a/rb)*(cb + yb3/rb)*zb1)/(rb + zb3)**2 +
     -     ((cb + a/rb)*sb)/(rb + zb3) -
     -     (sb*(cb + yb3/rb))/(rb + zb3) -
     -     (a*yb3*zb1)/(rb**3*(rb + zb3))) +
     -  ((-a + yb3)*(cb + yb3/rb)*
     -     ((cb - a/rb)*sb + ((1 + (a*yb3)/rb**2)*zb1)/rb -
     -       (cb*sb*y2**2 - (a*(cb*rb + yb3)*zb1)/rb)/(rb*(rb + zb3))))/
     -   (rb + zb3)**2 - ((cb - a/rb)*sb +
     -     ((1 + (a*yb3)/rb**2)*zb1)/rb -
     -     (cb*sb*y2**2 - (a*(cb*rb + yb3)*zb1)/rb)/(rb*(rb + zb3)))/
     -   (rb + zb3) - ((-a + yb3)*
     -     ((a*sb*yb3)/rb**3 + (sb*(1 + (a*yb3)/rb**2))/rb -
     -       (yb3*(1 + (a*yb3)/rb**2)*zb1)/rb**3 +
     -       ((a/rb**2 - (2*a*yb3**2)/rb**4)*zb1)/rb +
     -       ((cb + yb3/rb)*(cb*sb*y2**2 - (a*(cb*rb + yb3)*zb1)/rb))/
     -        (rb*(rb + zb3)**2) +
     -       (yb3*(cb*sb*y2**2 - (a*(cb*rb + yb3)*zb1)/rb))/
     -        (rb**3*(rb + zb3)) -
     -       (-((a*sb*(cb*rb + yb3))/rb) +
     -          (a*yb3*(cb*rb + yb3)*zb1)/rb**3 -
     -          (a*(1 + (cb*yb3)/rb)*zb1)/rb)/(rb*(rb + zb3))))/
     -   (rb + zb3)

      dvc(3,3,1) =
     .  2*(1 - nu)*(y2*(1/(y1**2 + y2**2) - cb/(y2**2 + zb1**2) +
     -        (sb*(cb*y1*(-rb**2 + y2**2) + (-rb**2 + y1**2)*zb1))/
     -         (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2))) -
     -     ((cb + a/rb)*sb*(-sb + y1/rb)*y2)/(rb + zb3)**2 -
     -     (a*sb*y1*y2)/(rb**3*(rb + zb3))) -
     -  (sb*(-sb + y1/rb)*y2*(-a + yb3)*
     -     (1 + (a*yb3)/rb**2 + ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))
     -    /(rb*(rb + zb3)**2) -
     -  (sb*y1*y2*(-a + yb3)*
     -     (1 + (a*yb3)/rb**2 + ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))
     -    /(rb**3*(rb + zb3)) +
     -  (sb*y2*(-a + yb3)*((-2*a*y1*yb3)/rb**4 -
     -       ((cb + a/rb)*(-sb + y1/rb)*(cb*rb + yb3))/(rb + zb3)**2 +
     -       (cb*(cb + a/rb)*y1)/(rb*(rb + zb3)) -
     -       (a*y1*(cb*rb + yb3))/(rb**3*(rb + zb3))))/(rb*(rb + zb3))

      dvc(3,3,2) =
     .  2*(1 - nu)*(-(y1/(y1**2 + y2**2)) + zb1/(y2**2 + zb1**2) +
     -     (sb*(cb*(-(rb**2*y2**2) + y2**4) + y1*(rb**2 + y2**2)*zb1))/
     -      (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2)) -
     -     ((cb + a/rb)*sb*y2**2)/(rb*(rb + zb3)**2) +
     -     ((cb + a/rb)*sb)/(rb + zb3) - (a*sb*y2**2)/(rb**3*(rb + zb3))
     -     ) - (sb*y2**2*(-a + yb3)*
     -     (1 + (a*yb3)/rb**2 + ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))
     -    /(rb**2*(rb + zb3)**2) +
     -  (sb*(-a + yb3)*(1 + (a*yb3)/rb**2 +
     -       ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/(rb*(rb + zb3)) -
     -  (sb*y2**2*(-a + yb3)*
     -     (1 + (a*yb3)/rb**2 + ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))
     -    /(rb**3*(rb + zb3)) +
     -  (sb*y2*(-a + yb3)*((-2*a*y2*yb3)/rb**4 -
     -       ((cb + a/rb)*y2*(cb*rb + yb3))/(rb*(rb + zb3)**2) +
     -       (cb*(cb + a/rb)*y2)/(rb*(rb + zb3)) -
     -       (a*y2*(cb*rb + yb3))/(rb**3*(rb + zb3))))/(rb*(rb + zb3))

      dvc(3,3,3) =
     .  2*(1 - nu)*(sb*y2*(-(1/(y2**2 + zb1**2)) +
     -        (-(rb**2*sb*y1) + cb*y2**2*yb3 + y1*yb3*zb1)/
     -         (rb*(rb**2*sb**2*y2**2 + (cb*y2**2 + y1*zb1)**2))) -
     -     ((cb + a/rb)*sb*y2*(cb + yb3/rb))/(rb + zb3)**2 -
     -     (a*sb*y2*yb3)/(rb**3*(rb + zb3))) -
     -  (sb*y2*(-a + yb3)*(cb + yb3/rb)*
     -     (1 + (a*yb3)/rb**2 + ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))
     -    /(rb*(rb + zb3)**2) +
     -  (sb*y2*(1 + (a*yb3)/rb**2 +
     -       ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))/(rb*(rb + zb3)) -
     -  (sb*y2*yb3*(-a + yb3)*
     -     (1 + (a*yb3)/rb**2 + ((cb + a/rb)*(cb*rb + yb3))/(rb + zb3)))
     -    /(rb**3*(rb + zb3)) +
     -  (sb*y2*(-a + yb3)*(a/rb**2 - (2*a*yb3**2)/rb**4 -
     -       ((cb + a/rb)*(cb*rb + yb3)*(cb + yb3/rb))/(rb + zb3)**2 -
     -       (a*yb3*(cb*rb + yb3))/(rb**3*(rb + zb3)) +
     -       ((cb + a/rb)*(1 + (cb*yb3)/rb))/(rb + zb3)))/
     -   (rb*(rb + zb3))

      pi   = 4.d0*atan2(1.d0,1.d0)
      vfac = 1.d0/(8.d0*pi*(1.d0-nu))

      do 20  i=1,3
      do 20  j=1,3
      v(i,j)    = vfac*( v(i,j)    + 2.d0*vc(i,j))
      do 10 k=1,3
      dv(i,j,k) = vfac*( dv(i,j,k) + 2.d0*dvc(i,j,k))
   10 continue
   20 continue

      return
      end

c---+-|--1----+----2----+----3----+----4----+----5----+----6----+----7--
cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc


program test_crust_eos
    use constants_def, only: dp
    use constants_lib
	use nucchem_def
	use nucchem_lib
	use superfluid_def
	use superfluid_lib
	use dStar_eos_lib

	integer :: eos_handle,sf_handle,ierr
	integer, dimension(3) :: Z,A,N,chem_ids, charged_ids
	real(dp), dimension(3) :: Y, Yion
	real(dp), dimension(num_dStar_eos_results) :: res
	type(composition_info_type) :: ionic
	integer :: i, ncharged
	real(dp) :: Xsum
	type(crust_eos_component), dimension(num_crust_eos_components) :: eos_components
    logical, parameter :: dbg = .FALSE.

	! n/o16/fe56 composition
	Z = [0.0,8.0,26.0]; A = [1.0,16.0,56.0]
	N = A-Z

    call constants_init('',ierr)
	call nucchem_init('../../data',ierr)
	call sf_startup('../../data',ierr)
	call sf_load_gaps('ns','gc','t72',ierr)

	call dStar_eos_startup('../../data')
	eos_handle = alloc_dStar_eos_handle(ierr)

	! get indices
	chem_ids = [(get_nuclide_index_from_ZN(Z(i),N(i)),i=1,3)]

	! O-Fe mixture
	Y = [0.0,0.5,0.5]/real(A,dp)
	call compute_composition_moments(3,chem_ids,Y,ionic,Xsum,ncharged, charged_ids, Yion,  &
			& exclude_neutrons = .TRUE.)
	call write_headers
	call do_one(1.0e2_dp)
	call do_one(1.0e5_dp)
	call do_one(1.0e7_dp)
	call do_one(1.0e9_dp)
	call do_one(1.0e11_dp)

	! add neutrons
	Y = [0.5,0.0,0.5]/real(A,dp)
	call compute_composition_moments(3,chem_ids,Y,ionic,Xsum,ncharged, charged_ids, Yion,  &
		& exclude_neutrons=.TRUE.)
	call write_headers
	call do_one(1.0e11_dp)
	call do_one(1.0e13_dp)

	! extreme neutron-rich composition
	Y = [0.95,0.0,0.05]/real(A,dp)
	call compute_composition_moments(3,chem_ids,Y,ionic,Xsum,ncharged, charged_ids, Yion,  &
		& exclude_neutrons=.TRUE.)
	call write_headers
	call do_one(1.0e12_dp)
	call do_one(1.0e14_dp)

    ! make trouble
	! n/o16/fe56 composition
!     Z = [0.0,12.0,26.0]; A = [1.0,48.0,56.0]
!     N = A-Z
!     chem_ids = [(get_nuclide_index_from_ZN(Z(i),N(i)),i=1,3)]
!     Y = [0.8,0.2,0.0]/real(A,dp)
!     call compute_composition_moments(3,chem_ids,Y,ionic,Xsum,ncharged, charged_ids, Yion,  &
!         & exclude_neutrons=.TRUE.)
!     call write_headers
!     call do_one(1.0e12_dp)
!     call do_one(1.0e14_dp)

	call sf_shutdown
	call nucchem_shutdown

	contains
	subroutine write_headers()
		write (*,'(/,"<Z> =",f7.2,"; <A> =",f7.2)') ionic% Z, ionic% A
		write (*,'(2a8,3a12,10a8,/)') 'lg(rho)','lg(T)','Gamma','Theta','Cv/kb/Na','lg(E)','lg(P)','lg(S)', &
			& 'chi_Rho','chi_T','G1','G3-1','del_ad','mu_e','mu_n'
	end subroutine write_headers

	subroutine do_one(rho)
		use constants_def, only: ln10,avogadro,boltzmann
		real(dp), intent(in) :: rho
		real(dp) :: lgr, lgT, T, Tc(max_number_sf_types)
		real(dp) :: Gamma,TpT,f,u,p,s,cv,chi_rho,chi_T,chk
		real(dp) :: k,Tcs(max_number_sf_types),chi,kFn,kFp
		integer :: phase
		integer :: i

		chi = use_default_nuclear_size
		lgr = log10(rho)
		do i = 1, 11
			lgT = 7.5 + (i-1)/10.0
			T = 10.0**lgT

			chi = nuclear_volume_fraction(rho,ionic,default_nuclear_radius)
			kFn = neutron_wavenumber(rho,ionic,chi)
			kFp = 0.0_dp
			call sf_get_results(kFp,kFn,Tcs)
			call eval_crust_eos(eos_handle,rho,T,ionic,ncharged,charged_ids, &
			&	Yion, Tcs, res, phase, chi, eos_components)
			chk = exp(res(i_lnP)-res(i_lnE))/rho
			write (*,'(2f8.2,3es12.4,10f8.3)')  &
				& lgr,lgT,res(i_Gamma),res(i_Theta),res(i_Cv)/boltzmann/avogadro,res(i_lnE)/ln10,res(i_lnP)/ln10,res(i_lnS)/ln10, &
				& res(i_chiRho),res(i_chiT),res(i_Gamma1),res(i_Gamma3),  &
				& res(i_grad_ad), res(i_mu_e),res(i_mu_n)

                if (dbg) then
                    write (*,'(a11,7a12)') 'component: ','pressure','energy','entropy','free energy','Cv','chi_rho','chi_T'
                    write (*,'(a11,7es12.4)') 'electron: ',eos_components(icrust_eos_ep)
                    write (*,'(a11,7es12.4)') 'ion: ',eos_components(icrust_eos_ion)
                    write (*,'(a11,7es12.4)') 'neutron: ',eos_components(icrust_eos_neutron)
                    write (*,'(a11,7es12.4)') 'radiation: ',eos_components(icrust_eos_radiation)
                end if
		end do
	end subroutine do_one

end program test_crust_eos


*     TC04AD EXAMPLE PROGRAM TEXT
*     Copyright (c) 2002-2020 NICONET e.V.
*
*     .. Parameters ..
      INTEGER          NIN, NOUT
      PARAMETER        ( NIN = 5, NOUT = 6 )
      INTEGER          MMAX, PMAX, KPCMAX, NMAX
      PARAMETER        ( MMAX = 5, PMAX = 5, KPCMAX = 5, NMAX = 5 )
      INTEGER          MAXMP
      PARAMETER        ( MAXMP = MAX( MMAX, PMAX ) )
      INTEGER          LDPCO1, LDPCO2, LDQCO1, LDQCO2, LDA, LDB, LDC,
     $                 LDD
      PARAMETER        ( LDPCO1 = MAXMP, LDPCO2 = MAXMP,
     $                   LDQCO1 = MAXMP, LDQCO2 = MAXMP,
     $                   LDA = NMAX, LDB = NMAX, LDC = MAXMP,
     $                   LDD = MAXMP )
      INTEGER          LIWORK
      PARAMETER        ( LIWORK = 2*MAXMP )
      INTEGER          LDWORK
      PARAMETER        ( LDWORK = ( MAXMP )*( MAXMP+4 ) )
*     .. Local Scalars ..
      DOUBLE PRECISION RCOND
      INTEGER          I, INFO, J, K, KPCOEF, M, N, P, PORM, PORP
      CHARACTER*1      LERI
      LOGICAL          LLERI
*     .. Local Arrays ..
      DOUBLE PRECISION A(LDA,NMAX), B(LDB,MAXMP), C(LDC,NMAX),
     $                 D(LDD,MAXMP), PCOEFF(LDPCO1,LDPCO2,KPCMAX),
     $                 QCOEFF(LDQCO1,LDQCO2,KPCMAX), DWORK(LDWORK)
      INTEGER          INDEX(MAXMP), IWORK(LIWORK)
*     .. External Functions ..
      LOGICAL          LSAME
      EXTERNAL         LSAME
*     .. External Subroutines ..
      EXTERNAL         TC04AD
*     .. Intrinsic Functions ..
      INTRINSIC        MAX
*     .. Executable Statements ..
*
      WRITE ( NOUT, FMT = 99999 )
*     Skip the heading in the data file and read the data.
      READ ( NIN, FMT = '()' )
      READ ( NIN, FMT = * ) M, P, LERI
      LLERI = LSAME( LERI, 'L' )
      IF ( M.LE.0 .OR. M.GT.MMAX ) THEN
         WRITE ( NOUT, FMT = 99991 ) M
      ELSE IF ( P.LE.0 .OR. P.GT.PMAX ) THEN
         WRITE ( NOUT, FMT = 99990 ) P
      ELSE
         PORM = P
         IF ( .NOT.LLERI ) PORM = M
         READ ( NIN, FMT = * ) ( INDEX(I), I = 1,PORM )
         PORP = M
         IF ( .NOT.LLERI ) PORP = P
         KPCOEF = 0
         DO 20 I = 1, PORM
            KPCOEF = MAX( KPCOEF, INDEX(I) )
   20    CONTINUE
         KPCOEF = KPCOEF + 1
         IF ( KPCOEF.LE.0 .OR. KPCOEF.GT.KPCMAX ) THEN
            WRITE ( NOUT, FMT = 99989 ) KPCOEF
         ELSE
            READ ( NIN, FMT = * )
     $         ( ( ( PCOEFF(I,J,K), K = 1,KPCOEF ), J = 1,PORM ),
     $                              I = 1,PORM )
            READ ( NIN, FMT = * )
     $         ( ( ( QCOEFF(I,J,K), K = 1,KPCOEF ), J = 1,PORP ),
     $                              I = 1,PORM )
*           Find a ssr of the given left pmr.
            CALL TC04AD( LERI, M, P, INDEX, PCOEFF, LDPCO1, LDPCO2,
     $                   QCOEFF, LDQCO1, LDQCO2, N, RCOND, A, LDA, B,
     $                   LDB, C, LDC, D, LDD, IWORK, DWORK, LDWORK,
     $                   INFO )
*
            IF ( INFO.NE.0 ) THEN
               WRITE ( NOUT, FMT = 99998 ) INFO
            ELSE
               WRITE ( NOUT, FMT = 99997 ) N, RCOND
               WRITE ( NOUT, FMT = 99996 )
               DO 40 I = 1, N
                  WRITE ( NOUT, FMT = 99995 ) ( A(I,J), J = 1,N )
   40          CONTINUE
               WRITE ( NOUT, FMT = 99994 )
               DO 60 I = 1, N
                  WRITE ( NOUT, FMT = 99995 ) ( B(I,J), J = 1,M )
   60          CONTINUE
               WRITE ( NOUT, FMT = 99993 )
               DO 80 I = 1, P
                  WRITE ( NOUT, FMT = 99995 ) ( C(I,J), J = 1,N )
   80          CONTINUE
               WRITE ( NOUT, FMT = 99992 )
               DO 100 I = 1, P
                  WRITE ( NOUT, FMT = 99995 ) ( D(I,J), J = 1,M )
  100          CONTINUE
            END IF
         END IF
      END IF
      STOP
*
99999 FORMAT (' TC04AD EXAMPLE PROGRAM RESULTS',/1X)
99998 FORMAT (' INFO on exit from TC04AD = ',I2)
99997 FORMAT (' The order of the resulting state-space representation ',
     $       ' =  ',I2,//' RCOND = ',F4.2)
99996 FORMAT (/' The state dynamics matrix A is ')
99995 FORMAT (20(1X,F8.4))
99994 FORMAT (/' The input/state matrix B is ')
99993 FORMAT (/' The state/output matrix C is ')
99992 FORMAT (/' The direct transmission matrix D is ')
99991 FORMAT (/' M is out of range.',/' M = ',I5)
99990 FORMAT (/' P is out of range.',/' P = ',I5)
99989 FORMAT (/' KPCOEF is out of range.',/' KPCOEF = ',I5)
      END


 !
 ! This file is part of the ExaHyPE project.
 ! Copyright (c) 2016  http://exahype.eu
 ! All rights reserved.
 !
 ! The project has received funding from the European Union's Horizon
 ! 2020 research and innovation programme under grant agreement
 ! No 671698. For copyrights and licensing, please consult the webpage.
 !
 ! Released under the BSD 3 Open Source License.
 ! For the full license text, see LICENSE.txt
 !

SUBROUTINE ADERPicardLoopNonlinear(luh,dt,dx,lqh,lFh)
    USE typesDef
    USE, INTRINSIC :: ISO_C_BINDING
    IMPLICIT NONE
    ! Argument list
    DOUBLE PRECISION, INTENT(IN)  :: luh(nVar,nDOF(1),nDOF(2),nDOF(3))              ! spatial degrees of freedom
    DOUBLE PRECISION, INTENT(IN)  :: dt                                             !
    DOUBLE PRECISION, INTENT(IN)  :: dx(d)                                          !
    DOUBLE PRECISION, INTENT(OUT) :: lqh(nVar,nDOF(0),nDOF(1),nDOF(2),nDOF(3))      ! space-time degrees of freedom
    DOUBLE PRECISION, INTENT(OUT) :: lFh(nVar,d+1,nDOF(1),nDOF(2),nDOF(3),nDOF(0))    ! nonlinear flux tensor in each space-time DOF
    ! Local variables
    INTEGER :: i,j,k,l,iVar, iter
    DOUBLE PRECISION    :: rhs0(nVar,nDOF(1),nDOF(2),nDOF(3),nDOF(0))               ! contribution of the initial condition to the known right hand side
    DOUBLE PRECISION    :: rhs(nVar,nDOF(1),nDOF(2),nDOF(3),nDOF(0))                ! known right hand side
    DOUBLE PRECISION    :: aux(d)                                                   ! auxiliary variables
    DOUBLE PRECISION    :: lqhold(nVar,nDOF(0),nDOF(1),nDOF(2),nDOF(3))             ! old space-time degrees of freedom
    DOUBLE PRECISION    :: lqx(nVar,nDOF(1),nDOF(2),nDOF(3),nDOF(0))                ! spatial derivative qx of q
    DOUBLE PRECISION    :: lqy(nVar,nDOF(1),nDOF(2),nDOF(3),nDOF(0))                ! spatial derivative qy of q
    DOUBLE PRECISION    :: lqz(nVar,nDOF(1),nDOF(2),nDOF(3),nDOF(0))                ! spatial derivative qz of q
    DOUBLE PRECISION    :: lqt(nVar,nDOF(1),nDOF(2),nDOF(3),nDOF(0))                ! time derivative qt of q
    DOUBLE PRECISION    :: src(nVar), BgradQ(nVar), gradQ(nVar,d)
    DOUBLE PRECISION    :: res                                                      ! residual
    DOUBLE PRECISION, PARAMETER :: tol = 1e-7                                       ! tolerance
    !
    DO k = 1, nDOF(3)
     DO j = 1, nDOF(2)
      DO i = 1, nDOF(1)
        ! Trivial initial guess (can be significantly improved)
        DO iVar = 1, nVar
            lqh(iVar,:,i,j,k) = luh(iVar,i,j,k)
        ENDDO
        ! Compute the contribution of the initial condition uh to the time update. I prefer to compute it once
        ! and store it in rhs0, but if you think it is faster, you can also recompute this contribution
        ! inside the Picard loop (DO iter = 1, N+1)
        aux = (/ wGPN(i), wGPN(j), wGPN(k) /)

        DO iVar = 1, nVar
         rhs0(iVar,i,j,k,:) = PRODUCT(aux(1:nDim))*F0(:)*luh(iVar,i,j,k)
        ENDDO
        !
      ENDDO
     ENDDO
    ENDDO

    !
    ! Discrete Picard iterations. This set of nested loops should (theoretically) be a dream for vectorization, since they are rather independent...
    DO iter = 1, N+1
        ! save old space-time DOF
        !lqhold = lqh
        DO l = 1, nDOF(0) ! loop over DOF in time
         ! Compute the fluxes (once these fluxes are available, the subsequent operations are independent from each other)
         DO k = 1, nDOF(3)
          DO j = 1, nDOF(2)
           DO i = 1, nDOF(1)
                CALL PDEFlux(lFh(:,:,i,j,k,l),lqh(:,l,i,j,k))
           ENDDO
          ENDDO
         ENDDO

         ! Compute the "derivatives" (contributions of the stiffness matrix)
         ! x direction (independent from the y and z derivatives)
        DO k = 1, nDOF(3)
          DO j = 1, nDOF(2)
              aux = (/ wGPN(l), wGPN(j), wGPN(k) /)
              rhs(:,:,j,k,l) = rhs0(:,:,j,k,l) - PRODUCT(aux(1:nDim))*dt/dx(1)*MATMUL( lFh(:,1,:,j,k,l), Kxi )
              lqx(:,:,j,k,l) = 1.0/dx(1)*MATMUL( lqh(:,l,:,j,k), TRANSPOSE(dudx) )         ! currently used only for debugging purposes, to check if derivatives are correctly computed
          ENDDO
         ENDDO

         ! y direction (independent from the x and z derivatives) - should not be used for 1D
         IF(nDim>=2) THEN
             DO k = 1, nDOF(3)
              DO i = 1, nDOF(1)
                  aux = (/ wGPN(l), wGPN(i), wGPN(k) /)
                  rhs(:,i,:,k,l) = rhs(:,i,:,k,l) - PRODUCT(aux(1:nDim))*dt/dx(2)*MATMUL( lFh(:,2,i,:,k,l), Kxi )
                  lqy(:,i,:,k,l) = 1.0/dx(2)*MATMUL( lqh(:,l,i,:,k), TRANSPOSE(dudx) )     ! currently used only for debugging purposes, to check if derivatives are correctly computed
              ENDDO
             ENDDO
         ENDIF
         ! z direction (independent from the x and y derivatives) - should not be used for 1D and 2D
         IF(nDim>=3) THEN
             DO j = 1, nDOF(2)
              DO i = 1, nDOF(1)
                  aux = (/ wGPN(l), wGPN(i), wGPN(j) /)
                  rhs(:,i,j,:,l) = rhs(:,i,j,:,l) - PRODUCT(aux(1:nDim))*dt/dx(3)*MATMUL( lFh(:,3,i,j,:,l), Kxi )
                  lqz(:,i,j,:,l) = 1.0/dx(3)*MATMUL( lqh(:,l,i,j,:), TRANSPOSE(dudx) )     ! currently used only for debugging purposes, to check if derivatives are correctly computed
              ENDDO
             ENDDO
         ENDIF
         !
         DO k = 1, nDOF(3)
          DO j = 1, nDOF(2)
           DO i = 1, nDOF(1)
                aux = (/ wGPN(i), wGPN(j), wGPN(k) /)
                gradQ(:,1) = lqx(:,i,j,k,l)
                gradQ(:,2) = lqy(:,i,j,k,l)
                gradQ(:,3) = lqz(:,i,j,k,l)
                CALL PDESource(src,lqh(:,l,i,j,k))
                CALL PDENCP(BgradQ,lqh(:,l,i,j,k),gradQ)
                lFh(:,d+1,i,j,k,l) = src - BgradQ
                rhs(:,i,j,k,l) = rhs(:,i,j,k,l) + PRODUCT(aux(1:nDim))*wGPN(l)*dt*lFh(:,d+1,i,j,k,l)
           ENDDO
          ENDDO
         ENDDO
         !
        ENDDO ! end loop over time DOF
        !
        ! Multiply with (K1)^(-1) to get the discrete time integral of the discrete Picard iteration
        !
        DO k = 1, nDOF(3)
         DO j = 1, nDOF(2)
          DO i = 1, nDOF(1)
             aux = (/ wGPN(i), wGPN(j), wGPN(k) /)
             lqh(:,:,i,j,k) = 1./(PRODUCT(aux(1:nDim)))*MATMUL( rhs(:,i,j,k,:), TRANSPOSE(iK1) )
             !lqt(:,i,j,k,:) = 1.0/dt*MATMUL( lqh(:,:,i,j,k), TRANSPOSE(dudx) )         ! currently used only for debugging purposes, to check if derivatives are correctly computed
           ENDDO
         ENDDO
        ENDDO

        !
        ! We can stop the iterations if a certain tolerance has been reached. If you do not like this unpredictable feature (it depends on the solution of the PDE)
        ! simply comment the lines below, so each element will always do the same number of iterations in the predictor step, i.e. the same number of operations
        !
        res = SQRT(SUM((lqh-lqhold)**2))
        IF(res.LT.tol) THEN
           EXIT
        ENDIF
        !
    ENDDO

    !PRINT *, 'lQH=', lQH
END SUBROUTINE ADERPicardLoopNonlinear

SUBROUTINE ADERPredictorNonlinear(lqh,lFh,lqhi,lFhi_x,lFhi_y,lFhi_z,lShi)
    USE typesDef
    USE, INTRINSIC :: ISO_C_BINDING
    IMPLICIT NONE
    ! Argument list
    DOUBLE PRECISION, INTENT(IN)  :: lqh(nVar,nDOF(0),nDOF(1),nDOF(2),nDOF(3))      ! space-time degrees of freedom
    DOUBLE PRECISION, INTENT(IN)  :: lFh(nVar,d+1,nDOF(1),nDOF(2),nDOF(3),nDOF(0))    ! nonlinear flux tensor in each space-time DOF
    DOUBLE PRECISION, INTENT(OUT) :: lqhi(nVar,nDOF(1),nDOF(2),nDOF(3))             ! time-averaged space-time degrees of freedom
    DOUBLE PRECISION, INTENT(OUT) :: lFhi_x(nVar,nDOF(1),nDOF(2),nDOF(3))           ! time-averaged nonlinear flux tensor in each space-time DOF in x direction
    DOUBLE PRECISION, INTENT(OUT) :: lFhi_y(nVar,nDOF(2),nDOF(1),nDOF(3))           ! time-averaged nonlinear flux tensor in each space-time DOF in y direction
    DOUBLE PRECISION, INTENT(OUT) :: lFhi_z(nVar,nDOF(3),nDOF(1),nDOF(2))           ! time-averaged nonlinear flux tensor in each space-time DOF in z direction
    DOUBLE PRECISION, INTENT(OUT) :: lShi(nVar,nDOF(1),nDOF(2),nDOF(3))             ! time-averaged nonlinear source
    ! Local variables
    INTEGER :: i,j,k,iDim
    !
    !OPEN(UNIT=12, FILE="aoutput_lqh2.txt", ACTION="write", STATUS="replace")
    !WRITE(12, '(ES24.16,1x)') , lqh

    !OPEN(UNIT=12, FILE="aoutput_lFh.txt", ACTION="write", STATUS="replace")
    !WRITE(12, '(ES24.16,1x)') , lFh
    !
    ! Immediately compute the time-averaged space-time polynomials
    !
    DO k = 1, nDOF(3)
     DO j = 1, nDOF(2)
      DO i = 1, nDOF(1)
         lqhi(:,i,j,k) = MATMUL( lqh(:,:,i,j,k), wGPN )
         !DO iDim = 1, nDim
         !   lFhi(:,i,j,k,iDim) = MATMUL( lFh(:,iDim,i,j,k,:), wGPN )
         !ENDDO
         lFhi_x(:,i,j,k) = MATMUL( lFh(:,1,i,j,k,:), wGPN )
         lFhi_y(:,j,i,k) = MATMUL( lFh(:,2,i,j,k,:), wGPN )
         lFhi_z(:,k,i,j) = MATMUL( lFh(:,3,i,j,k,:), wGPN )
         lShi(:,i,j,k)   = MATMUL( lFh(:,4,i,j,k,:), wGPN )
      ENDDO
     ENDDO
    ENDDO

    !OPEN(UNIT=12, FILE="aoutput_lqhi.txt", ACTION="write", STATUS="replace")
    !WRITE(12, '(ES24.16,1x)') , lqhi

    !OPEN(UNIT=12, FILE="aoutput_lFhi_x.txt", ACTION="write", STATUS="replace")
    !WRITE(12, '(ES24.16,1x)') , lFhi_x

    !OPEN(UNIT=12, FILE="aoutput_lFhi_y.txt", ACTION="write", STATUS="replace")
    !WRITE(12, '(ES24.16,1x)') , lFhi_y

    !OPEN(UNIT=12, FILE="aoutput_lFhi_z.txt", ACTION="write", STATUS="replace")
    !WRITE(12, '(ES24.16,1x)') , lFhi_z

    !CALL EXIT

    !
END SUBROUTINE ADERPredictorNonlinear

SUBROUTINE ADERExtrapolatorNonlinear(lqhi,lFhi_x,lFhi_y,lFhi_z,lQbnd,lFbnd)
    USE typesDef
    USE, INTRINSIC :: ISO_C_BINDING
    IMPLICIT NONE
    ! Argument list
    DOUBLE PRECISION, INTENT(IN)  :: lqhi(nVar,nDOF(1),nDOF(2),nDOF(3))             ! time-averaged space-time degrees of freedom
    DOUBLE PRECISION, INTENT(IN)  :: lFhi_x(nVar,nDOF(1),nDOF(2),nDOF(3))           ! time-averaged nonlinear flux tensor in each space-time DOF in x direction
    DOUBLE PRECISION, INTENT(IN)  :: lFhi_y(nVar,nDOF(2),nDOF(1),nDOF(3))           ! time-averaged nonlinear flux tensor in each space-time DOF in y direction
    DOUBLE PRECISION, INTENT(IN)  :: lFhi_z(nVar,nDOF(3),nDOF(1),nDOF(2))           ! time-averaged nonlinear flux tensor in each space-time DOF in z direction
    DOUBLE PRECISION, INTENT(OUT) :: lQbnd(nVar,nDOF(2),nDOF(3),6)                  ! time-averaged space-time degrees of freedom
    DOUBLE PRECISION, INTENT(OUT) :: lFbnd(nVar,nDOF(2),nDOF(3),6)                  ! time-averaged nonlinear flux tensor in each space-time DOF
    ! Local variables
    INTEGER :: i,j,k
    !
    !
    ! Compute the bounday-extrapolated values for Q and F*n
    !
    lQbnd = 0.
    lFbnd = 0.
    ! x-direction: face 1 (left) and face 2 (right)
    DO k = 1, nDOF(3)
     DO j = 1, nDOF(2)
        lQbnd(:,j,k,1) = MATMUL( lqhi(:,:,j,k),   FLCoeff )   ! left
        lQbnd(:,j,k,2) = MATMUL( lqhi(:,:,j,k),   FRCoeff )   ! right
        lFbnd(:,j,k,1) = MATMUL( lFhi_x(:,:,j,k), FLCoeff )   ! left
        lFbnd(:,j,k,2) = MATMUL( lFhi_x(:,:,j,k), FRCoeff )   ! right
     ENDDO
    ENDDO
    ! y-direction: face 3 (left) and face 4 (right)
    IF(nDim>=2) THEN
        DO k = 1, nDOF(3)
         DO i = 1, nDOF(1)
            lQbnd(:,i,k,3) = MATMUL( lqhi(:,i,:,k),   FLCoeff )   ! left
            lQbnd(:,i,k,4) = MATMUL( lqhi(:,i,:,k),   FRCoeff )   ! right
            lFbnd(:,i,k,3) = MATMUL( lFhi_y(:,:,i,k), FLCoeff )   ! left
            lFbnd(:,i,k,4) = MATMUL( lFhi_y(:,:,i,k), FRCoeff )   ! right
         ENDDO
        ENDDO
    ENDIF
    ! z-direction: face 5 (left) and face 6 (right)
    IF(nDim>=3) THEN
        DO j = 1, nDOF(2)
         DO i = 1, nDOF(1)
            lQbnd(:,i,j,5) = MATMUL( lqhi(:,i,j,:),   FLCoeff )   ! left
            lQbnd(:,i,j,6) = MATMUL( lqhi(:,i,j,:),   FRCoeff )   ! right
            lFbnd(:,i,j,5) = MATMUL( lFhi_z(:,:,i,j), FLCoeff )   ! left
            lFbnd(:,i,j,6) = MATMUL( lFhi_z(:,:,i,j), FRCoeff )   ! right
         ENDDO
        ENDDO
    ENDIF
    !
    !OPEN(UNIT=12, FILE="aoutput_lFbnd.txt", ACTION="write", STATUS="replace")
    !WRITE(12, '(ES24.16,1x)') , lFbnd

    !OPEN(UNIT=12, FILE="aoutput_lQbnd.txt", ACTION="write", STATUS="replace")
    !WRITE(12, '(ES24.16,1x)') , lQbnd
    !CALL EXIT

END SUBROUTINE ADERExtrapolatorNonlinear


!***************************************************************************
!***************  MODUL ***************************************************
!***************************************************************************

module aleas
!del alea3d
integer, public                ::nvalo,nvaloq  !en el fons tenim nvalo**2
real*8 , public, allocatable   ::particions_esfera(:,:) !s'hauria de fer nomes de out
integer, public, parameter     ::tamstocas=100000   !es per fer la matriu de ran2
integer, public                ::nunualea,cotran !numero de numeros aleas k realment tenim
real*8 , public                ::stocas(tamstocas)

contains

!**************************************************************************
subroutine inialea3d(un)
  integer i,j,k
  real*8 a,b,c,e,x,y,z
  integer un
  nvalo=un
  nvaloq=un*un
  allocate(particions_esfera(nvaloq,3))
  e=2d0*3.141592/nvalo
  do i=1,nvalo
    do j=1,nvalo
      a=dcos(i*e)
      c=sqrt(1d0-a**2)
      x=c*dcos(j*e)
      y=c*dsin(j*e)
      z=a
      k=(i-1)*nvalo+j
      particions_esfera(k,1)=x
      particions_esfera(k,2)=y
      particions_esfera(k,3)=z
    end do
  end do
end subroutine inialea3d

!**************************************************************************
subroutine llaleat
    integer ui,i,ii,ios
    open(10,file='alea.dat',status='old',iostat=ios)
    if (ios/=0) then
      print *,"";      print *,"";      print *,"";
      print *,"there is no alea.dat file with aleatory numbers"
      print *,"";      print *,"";      print *,"";
      print *,"I can't tolerate that: f**ck you I'm quitting"
      print *,"";      print *,"";      print *,"";
      stop
    end if
    nunualea=0
    cotran=1
    do ui=1,tamstocas
      read (10,*,ERR=100,END=90) stocas(ui)
      nunualea=nunualea+1
    end do
    return
100 print *,"";      print *,"";      print *,"";
    print *,"error in the random file alea.dat"
    print *,"";      print *,"";      print *,"";
    print *," I can't tolerate that: f**ck you I'm quitting"
    print *,"";      print *,"";      print *,"";
    stop
90  close(10)
    open(10,file='alea.dat')
	print*,"end alea.dat"
	rewind(10)
	ii=int(a*1000)+1
print *,a,ii,"rew"
	do i=1,ii-1
          read(10,*)
	end do
end subroutine

end module


      DOUBLE PRECISION FUNCTION bcorr(a0,b0)
C-----------------------------------------------------------------------
C
C     EVALUATION OF  DEL(A0) + DEL(B0) - DEL(A0 + B0)  WHERE
C     LN(GAMMA(A)) = (A - 0.5)*LN(A) - A + 0.5*LN(2*PI) + DEL(A).
C     IT IS ASSUMED THAT A0 .GE. 8 AND B0 .GE. 8.
C
C-----------------------------------------------------------------------
C     .. Scalar Arguments ..
      DOUBLE PRECISION a0,b0
C     ..
C     .. Local Scalars ..
      DOUBLE PRECISION a,b,c,c0,c1,c2,c3,c4,c5,h,s11,s3,s5,s7,s9,t,w,x,
     +                 x2
C     ..
C     .. Intrinsic Functions ..
      INTRINSIC dmax1,dmin1
C     ..
C     .. Data statements ..
      DATA c0/.833333333333333D-01/,c1/-.277777777760991D-02/,
     +     c2/.793650666825390D-03/,c3/-.595202931351870D-03/,
     +     c4/.837308034031215D-03/,c5/-.165322962780713D-02/
C     ..
C     .. Executable Statements ..
C------------------------
      a = dmin1(a0,b0)
      b = dmax1(a0,b0)
C
      h = a/b
      c = h/ (1.0D0+h)
      x = 1.0D0/ (1.0D0+h)
      x2 = x*x
C
C                SET SN = (1 - X**N)/(1 - X)
C
      s3 = 1.0D0 + (x+x2)
      s5 = 1.0D0 + (x+x2*s3)
      s7 = 1.0D0 + (x+x2*s5)
      s9 = 1.0D0 + (x+x2*s7)
      s11 = 1.0D0 + (x+x2*s9)
C
C                SET W = DEL(B) - DEL(A + B)
C
      t = (1.0D0/b)**2
      w = ((((c5*s11*t+c4*s9)*t+c3*s7)*t+c2*s5)*t+c1*s3)*t + c0
      w = w* (c/b)
C
C                   COMPUTE  DEL(A) + W
C
      t = (1.0D0/a)**2
      bcorr = (((((c5*t+c4)*t+c3)*t+c2)*t+c1)*t+c0)/a + w
      RETURN

      END


!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
subroutine stepper(psi,N_traj,method,Nsteps,Nskip,Nwrite,eps,OPv)

  use matrix
  use rungekutta
  implicit none
  character(len=30),intent(in) :: method
  integer,intent(in) :: N_traj,Nskip,Nwrite,Nsteps
  real(kind=8),intent(in) :: eps
  complex(kind=8),intent(inout) :: psi(0:Nbasis,N_traj)
  external OPv

  integer :: cnt,ccnt,Nbp1,i,j
  real(kind=8) :: time,dT,dTdid,dTnext
  real(kind=8) :: err(N_traj)
  real(kind=8),parameter :: zero = 0d0
  complex(kind=8) :: dpsi(0:Nbasis,N_traj),psiNEW(0:Nbasis,N_traj)   ! state vectors
  Nbp1 = Nbasis+1

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
! write initial population
  dT = Tfinal/(Nsteps+1)
  time = zero
  ccnt = 0
  err(:) = zero
  call writePOP(time,ccnt,psi,err,N_traj,Nwrite)
  ccnt = ccnt + 1

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
! adaptive step-size Runge-Kutta Cash-Karp propagation
  if(trim(method) == 'adaptive') then

    cnt = 0
    timeloop: do
      if(time+dT > Tfinal) exit timeloop
! compute gradient
      call OPv(time,psi,dpsi,N_traj)
! non unitary evolution
      call adapt(Nbp1,psi,dpsi,psiNEW,N_traj,time,dT,eps,err,dTdid,dTnext,OPv)
! normalization
      call normalize(N_traj,psiNEW,psi)
! prepar for next step
      dT = dTnext
      if(modulo(cnt,Nskip)==0) then
          call writePOP(time,ccnt,psi,err,N_traj,Nwrite)
          ccnt = ccnt + 1
      endif
      cnt = cnt + 1
    enddo timeloop

! compute gradient and optimize field
    call OPv(time,psi,dpsi,N_traj)
! propagate last step
    dT = Tfinal - time
    call CashKarp_step(Nbp1,psi,dpsi,N_traj,time,dT,psiNEW,err,OPv)
! normalization
    call normalize(N_traj,psiNEW,psi)
    Time = Tfinal
    call writePOP(Tfinal,ccnt,psi,err,N_traj,Nwrite)

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
! simple Runge-Kutta Cash-Karp propagation
  elseif(trim(method) == 'rungekutta') then

    cnt = 0
    ckloop : do
      if(time + dT > Tfinal+eps) exit ckloop
! compute gradient
      call OPv(time,psi,dpsi,N_traj)
! non unitary evolution
      call CashKarp_step(Nbp1,psi,dpsi,N_traj,time,dT,psiNEW,err,OPv)
! normalization
      call normalize(N_traj,psiNEW,psi)
! prepare for next iteration
      time = time + dT
      if(modulo(cnt,Nskip)==0) then
          call writePOP(time,ccnt,psi,err,N_traj,Nwrite)
          ccnt = ccnt + 1
      endif
      cnt = cnt + 1
    enddo ckloop

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
  else
    write(1,*) 'Oups! No such propagator available.'
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
  endif

end subroutine stepper
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1