2 SUBROUTINE neowes(eq, coreprof, neoclassic, coreimpurity)
 
    4 SUBROUTINE neowes(eq, coreprof, neoclassic)
 
   14   USE deallocate_structures
 
   18   TYPE (type_equilibrium
), 
pointer :: 
eq(:)
 
   19   TYPE (type_coreprof
), 
pointer :: coreprof(:)
 
   21   TYPE (type_coreimpur
), 
pointer :: coreimpurity(:)
 
   23   TYPE (type_neoclassic
), 
pointer :: neoclassic(:)
 
   25   INTEGER(ITM_I4) :: ion=0,imp=0,icharge=0,iz=0,inucl=0
 
   26   INTEGER(ITM_I4) :: nrho_prof,nion_prof,nrho_eq
 
   27   INTEGER(ITM_I4) :: nrho_imp = 0
 
   28   INTEGER(ITM_I4), 
SAVE :: &
 
   29        nrho = 0, nion = 0, nimp = 0, ncharge = 0, nspecies = 0
 
   30   REAL(R8) :: a00,b00,r00,rho_tor_max
 
   31   REAL(R8) :: mass,charge
 
   32   INTEGER(ITM_I4), 
DIMENSION(:), 
POINTER :: ncharges
 
   33   REAL(R8), 
DIMENSION(:), 
POINTER :: &
 
   34        nne,tte,nni,tti,tavg,rlne,rlte,rlni,rlti,qq,zeff,zee, &
 
   35        rhoi,v_i,rnue,rnui,eps12,eps32,mneo
 
   36   REAL(R8), 
DIMENSION(:), 
POINTER :: &
 
   37        rho,diffe,diff,chi,vconv,
flux,gradn,gradp,eer,sum1,sum2
 
   38   REAL(R8), 
DIMENSION(:,:), 
POINTER :: nneo,tneo,zneo
 
   42   REAL(R8) :: cc=1.0_r8, lcoul=14.0_r8
 
   46   character(len = 132), 
target :: codename(1) = 
'NEOWES' 
   47   character(len = 132), 
target :: codeversion(1) = 
'CC_Cyprus12' 
   51   nrho_prof=
SIZE(coreprof(1)%rho_tor)
 
   52   nion_prof=
SIZE(coreprof(1)%ni%value, dim=2)
 
   53   nrho_eq=
SIZE(
eq(1)%profiles_1d%rho_tor)
 
   55   IF (
ASSOCIATED(coreimpurity)) 
THEN 
   56      IF (
SIZE(coreimpurity) > 0) 
THEN 
   57         nrho_imp=
SIZE(coreimpurity(1)%rho_tor)
 
   58         IF (nrho_imp > 0) 
THEN 
   59            nimp=
SIZE(coreimpurity(1)%impurity)
 
   77      ALLOCATE(ncharges(nimp))
 
   80         ncharges(imp) = 
SIZE(coreimpurity(1)%impurity(imp)%nz, 2)
 
   81         DO icharge=1,ncharges(imp)
 
   94   IF (.NOT. 
ASSOCIATED(neoclassic)) 
THEN 
   95      ALLOCATE(neoclassic(1))
 
   96      ALLOCATE(neoclassic(1)%codeparam%codename(1))
 
   97      ALLOCATE(neoclassic(1)%codeparam%codeversion(1))
 
   98      neoclassic(1)%codeparam%codename = codename
 
   99      neoclassic(1)%codeparam%codeversion = codeversion
 
  101   ALLOCATE(neoclassic(1)%rho_tor_norm(nrho))
 
  102   ALLOCATE(neoclassic(1)%rho_tor(nrho))
 
  103   ALLOCATE(neoclassic(1)%sigma(nrho))
 
  104   ALLOCATE(neoclassic(1)%jboot(nrho))
 
  105   ALLOCATE(neoclassic(1)%er(nrho))
 
  108   ALLOCATE(neoclassic(1)%ne_neo%flux(nrho))
 
  109   ALLOCATE(neoclassic(1)%ni_neo%flux(nrho,nion))
 
  110   ALLOCATE(neoclassic(1)%te_neo%flux(nrho))
 
  111   ALLOCATE(neoclassic(1)%ti_neo%flux(nrho,nion))
 
  112   ALLOCATE(neoclassic(1)%ne_neo%diff_eff(nrho))
 
  113   ALLOCATE(neoclassic(1)%ni_neo%diff_eff(nrho,nion))
 
  114   ALLOCATE(neoclassic(1)%te_neo%diff_eff(nrho))
 
  115   ALLOCATE(neoclassic(1)%ti_neo%diff_eff(nrho,nion))
 
  116   ALLOCATE(neoclassic(1)%ne_neo%vconv_eff(nrho))
 
  117   ALLOCATE(neoclassic(1)%ni_neo%vconv_eff(nrho,nion))
 
  118   ALLOCATE(neoclassic(1)%te_neo%vconv_eff(nrho))
 
  119   ALLOCATE(neoclassic(1)%ti_neo%vconv_eff(nrho,nion))
 
  120   ALLOCATE(neoclassic(1)%ti_neo%exchange(nrho,nion))
 
  121   ALLOCATE(neoclassic(1)%ti_neo%qgi(nrho,nion))
 
  123   ALLOCATE(neoclassic(1)%vpol(nrho,nion))
 
  124   ALLOCATE(neoclassic(1)%mtor_neo%flux(nrho))
 
  125   ALLOCATE(neoclassic(1)%mtor_neo%diff_eff(nrho))
 
  126   ALLOCATE(neoclassic(1)%mtor_neo%vconv_eff(nrho))
 
  128   neoclassic(1)%ne_neo%flux=0._r8
 
  129   neoclassic(1)%ni_neo%flux=0._r8
 
  130   neoclassic(1)%te_neo%flux=0._r8
 
  131   neoclassic(1)%ti_neo%flux=0._r8
 
  132   neoclassic(1)%ne_neo%diff_eff=0._r8
 
  133   neoclassic(1)%ni_neo%diff_eff=0._r8
 
  134   neoclassic(1)%te_neo%diff_eff=0._r8
 
  135   neoclassic(1)%ti_neo%diff_eff=0._r8
 
  136   neoclassic(1)%ne_neo%vconv_eff=0._r8
 
  137   neoclassic(1)%ni_neo%vconv_eff=0._r8
 
  138   neoclassic(1)%te_neo%vconv_eff=0._r8
 
  139   neoclassic(1)%ti_neo%vconv_eff=0._r8
 
  140   neoclassic(1)%ti_neo%exchange=0._r8
 
  141   neoclassic(1)%ti_neo%qgi=0._r8
 
  143   neoclassic(1)%vpol=0._r8
 
  144   neoclassic(1)%mtor_neo%flux=0._r8
 
  145   neoclassic(1)%mtor_neo%diff_eff=0._r8
 
  146   neoclassic(1)%mtor_neo%vconv_eff=0._r8
 
  150      ALLOCATE(neoclassic(1)%nz_neo(nimp))
 
  151      ALLOCATE(neoclassic(1)%tz_neo(nimp))
 
  153         ncharge=ncharges(imp)
 
  154         ALLOCATE(neoclassic(1)%nz_neo(imp)%flux(nrho,ncharge))
 
  155         ALLOCATE(neoclassic(1)%nz_neo(imp)%diff_eff(nrho,ncharge))
 
  156         ALLOCATE(neoclassic(1)%nz_neo(imp)%vconv_eff(nrho,ncharge))
 
  157         neoclassic(1)%nz_neo(imp)%flux=0._r8
 
  158         neoclassic(1)%nz_neo(imp)%diff_eff=0._r8
 
  159         neoclassic(1)%nz_neo(imp)%vconv_eff=0._r8
 
  160         ALLOCATE(neoclassic(1)%tz_neo(imp)%flux(nrho,ncharge))
 
  161         ALLOCATE(neoclassic(1)%tz_neo(imp)%diff_eff(nrho,ncharge))
 
  162         ALLOCATE(neoclassic(1)%tz_neo(imp)%vconv_eff(nrho,ncharge))
 
  163         ALLOCATE(neoclassic(1)%tz_neo(imp)%exchange(nrho,ncharge))
 
  164         neoclassic(1)%tz_neo(imp)%flux=0._r8
 
  165         neoclassic(1)%tz_neo(imp)%diff_eff=0._r8
 
  166         neoclassic(1)%tz_neo(imp)%vconv_eff=0._r8
 
  167         neoclassic(1)%tz_neo(imp)%exchange=0._r8
 
  178   call deallocate_cpo(neoclassic(1)%composition)
 
  179   call copy_cpo(coreprof(1)%composition,neoclassic(1)%composition)
 
  180   call deallocate_cpo(neoclassic(1)%compositions)
 
  181   call copy_cpo(coreprof(1)%compositions,neoclassic(1)%compositions)
 
  185   a00=
eq(1)%eqgeometry%a_minor
 
  186   b00=
eq(1)%global_param%toroid_field%b0
 
  187   r00=
eq(1)%global_param%toroid_field%r0
 
  191   rho_tor_max=maxval(
eq(1)%profiles_1d%rho_tor)
 
  195   neoclassic(1)%rho_tor=coreprof(1)%rho_tor
 
  196   neoclassic(1)%rho_tor_norm=neoclassic(1)%rho_tor/rho_tor_max
 
  200   rho => neoclassic(1)%rho_tor
 
  218   ALLOCATE(eps12(nrho))
 
  219   ALLOCATE(eps32(nrho))
 
  221   ALLOCATE(nneo(nrho,0:nspecies))
 
  222   ALLOCATE(tneo(nrho,0:nspecies))
 
  223   ALLOCATE(zneo(nrho,0:nspecies))
 
  224   ALLOCATE(mneo(0:nspecies))
 
  226   CALL 
l3interp(coreprof(1)%profiles1d%zeff%value, &
 
  227        coreprof(1)%rho_tor,nrho_prof, zeff,rho,nrho)
 
  228   CALL 
l3interp(
eq(1)%profiles_1d%q,
eq(1)%profiles_1d%rho_tor, &
 
  229        nrho_eq, qq,rho,nrho)
 
  233   CALL 
l3interp(coreprof(1)%ne%value,coreprof(1)%rho_tor, &
 
  234        nrho_prof, nneo(1,0),rho,nrho)
 
  235   CALL 
l3interp(coreprof(1)%te%value,coreprof(1)%rho_tor, &
 
  236        nrho_prof, tneo(1,0),rho,nrho)
 
  241      inucl = coreprof(1)%compositions%ions(ion)%nucindex
 
  242      mass = coreprof(1)%compositions%nuclei(inucl)%amn * itm_amu
 
  243      charge = ee*coreprof(1)%compositions%ions(ion)%zion
 
  245      CALL 
l3interp(coreprof(1)%ni%value(1,ion),coreprof(1)%rho_tor, &
 
  246           nrho_prof, nneo(1,ion),rho,nrho)
 
  247      CALL 
l3interp(coreprof(1)%ti%value(1,ion),coreprof(1)%rho_tor, &
 
  248           nrho_prof, tneo(1,ion),rho,nrho)
 
  254   tavg=sum(nneo(:,1:nion)*tneo(:,1:nion), dim=2)/sum(nneo(:,1:nion), dim=2)
 
  260      ncharge=ncharges(imp)
 
  262      inucl = coreimpurity(1)%compositions%impurities(imp)%nucindex
 
  263      mass = coreimpurity(1)%compositions%nuclei(inucl)%amn * itm_amu
 
  267         CALL 
l3interp(coreimpurity(1)%impurity(imp)%nz(1,icharge), &
 
  268              coreimpurity(1)%rho_tor,nrho_imp, &
 
  270         CALL 
l3interp(coreimpurity(1)%impurity(imp)%z(1,icharge), &
 
  271              coreimpurity(1)%rho_tor,nrho_imp, &
 
  273         zneo(:,iz)=ee*zneo(:,iz)
 
  291         DO icharge=1,ncharges(imp)
 
  308      CALL 
l3deriv(nni,rho,nrho,rlni,rho,nrho)
 
  309      CALL 
l3deriv(tti,rho,nrho,rlti,rho,nrho)
 
  317         rnui=(lcoul/2.09e13_r8)*nni*(zee*zee/(ee*ee))/(tti**1.5)
 
  319         rnui=(lcoul/2.09e13_r8)* &
 
  320              max( nni*(zee*zee/(ee*ee)), nne )/(tti**1.5)
 
  328         rnue=(lcoul/3.44e11_r8)*zeff*nne/(tte**1.5)
 
  334      rhoi=sqrt(cc*cc*mass*kb*tti/(zee*zee*b00*b00))
 
  335      v_i=sqrt(kb*tti/mass)
 
  342         diff => neoclassic(1)%ne_neo%diff_eff
 
  343         gradn => neoclassic(1)%ne_neo%vconv_eff
 
  344         gradp => neoclassic(1)%ne_neo%flux
 
  345         chi => neoclassic(1)%te_neo%diff_eff
 
  346         flux => neoclassic(1)%te_neo%flux
 
  348         sum1 => neoclassic(1)%er
 
  349         sum2 => neoclassic(1)%te_neo%vconv_eff
 
  353         neoclassic(1)%sigma = ((1.-eps12)**2.)*nne*ee*ee/(0.51*rnue*itm_me)
 
  354         neoclassic(1)%jboot = nne*kb*tte*(2.44*rlne+0.69*rlte)
 
  355      ELSE IF (iz <= nion) 
THEN 
  356         diff => neoclassic(1)%ni_neo%diff_eff(:,iz)
 
  357         gradn => neoclassic(1)%ni_neo%vconv_eff(:,iz)
 
  358         gradp => neoclassic(1)%ni_neo%flux(:,iz)
 
  359         chi => neoclassic(1)%ti_neo%diff_eff(:,iz)
 
  360         flux => neoclassic(1)%ti_neo%flux(:,iz)
 
  362         neoclassic(1)%ti_neo%exchange(:,iz) = &
 
  363              3.*(itm_me/mass)*nne*kb*rnue*(tti-tte)
 
  364         neoclassic(1)%jboot = neoclassic(1)%jboot &
 
  365              + nni*kb*tti*(2.44*rlne-0.42*rlti)
 
  368         diff => neoclassic(1)%nz_neo(imp)%diff_eff(:,icharge)
 
  369         gradn => neoclassic(1)%nz_neo(imp)%vconv_eff(:,icharge)
 
  370         gradp => neoclassic(1)%nz_neo(imp)%flux(:,icharge)
 
  371         chi => neoclassic(1)%tz_neo(imp)%diff_eff(:,icharge)
 
  372         flux => neoclassic(1)%tz_neo(imp)%flux(:,icharge)
 
  377      gradp = nni*kb*tti*(rlni+rlti)
 
  385      eps32=max(rho,rhoi)/r00
 
  387      diff=rhoi*rhoi*rnui*2._r8*qq*qq
 
  388      diff=max(diff, rhoi*rhoi*(v_i/abs(qq*r00))*qq*qq)
 
  389      diff=min(diff, rhoi*rhoi*rnui*qq*qq/eps32)
 
  396      flux=nni*kb*tti*(-chi)*rlti
 
  400      sum1 = sum1 + zee*diff*gradp/(kb*tti)
 
  401      sum2 = sum2 + nni*zee*zee*diff/(kb*tti)
 
  407   eer => neoclassic(1)%er 
 
  410   neoclassic(1)%jboot = - eps12*(qq*r00/((rho+1e-10)*b00))*neoclassic(1)%jboot
 
  418   diffe => neoclassic(1)%ne_neo%diff_eff
 
  420   diff => neoclassic(1)%ne_neo%diff_eff
 
  421   vconv => neoclassic(1)%ne_neo%vconv_eff
 
  422   flux => neoclassic(1)%ne_neo%flux
 
  423   gradn => neoclassic(1)%ne_neo%vconv_eff
 
  424   gradp => neoclassic(1)%ne_neo%flux
 
  428   flux = -(diff/(kb*tte))*(gradp - nne*zee*eer)
 
  429   vconv = (
flux + diff*gradn)/nne
 
  432      diff => neoclassic(1)%ni_neo%diff_eff(:,ion)
 
  433      vconv => neoclassic(1)%ni_neo%vconv_eff(:,ion)
 
  434      flux => neoclassic(1)%ni_neo%flux(:,ion)
 
  435      gradn => neoclassic(1)%ni_neo%vconv_eff(:,ion)
 
  436      gradp => neoclassic(1)%ni_neo%flux(:,ion)
 
  442      neoclassic(1)%vpol(:,ion) = (gradp/(nni*zee) - eer)*cc/b00
 
  444      flux = -(diff/(kb*tti))*(gradp - nni*zee*eer)
 
  446      vconv = (
flux + diff*gradn)/nni
 
  454      DO icharge=1,ncharges(imp)
 
  457         diff => neoclassic(1)%nz_neo(imp)%diff_eff(:,icharge)
 
  458         vconv => neoclassic(1)%nz_neo(imp)%vconv_eff(:,icharge)
 
  459         flux => neoclassic(1)%nz_neo(imp)%flux(:,icharge)
 
  460         gradn => neoclassic(1)%nz_neo(imp)%vconv_eff(:,icharge)
 
  461         gradp => neoclassic(1)%nz_neo(imp)%flux(:,icharge)
 
  467         flux = -(diff/(kb*tti))*(gradp - nni*zee*eer)
 
  469         vconv = (
flux + diff*gradn)/nni
 
  476   neoclassic(1)%time=coreprof(1)%time
 
  480     if(
associated(ncharges)) 
deallocate(ncharges)
 
  483   if(
associated(nne)) 
deallocate(nne)
 
  484   if(
associated(tte)) 
deallocate(tte)
 
  485   if(
associated(nni)) 
deallocate(nni)
 
  486   if(
associated(tti)) 
deallocate(tti)
 
  487   if(
associated(tavg)) 
deallocate(tavg)
 
  488   if(
associated(rlne)) 
deallocate(rlne)
 
  489   if(
associated(rlte)) 
deallocate(rlte)
 
  490   if(
associated(rlni)) 
deallocate(rlni)
 
  491   if(
associated(rlti)) 
deallocate(rlti)
 
  492   if(
associated(qq)) 
deallocate(qq)
 
  493   if(
associated(zeff)) 
deallocate(zeff)
 
  494   if(
associated(zee)) 
deallocate(zee)
 
  495   if(
associated(rhoi)) 
deallocate(rhoi)
 
  496   if(
associated(v_i)) 
deallocate(v_i)
 
  497   if(
associated(rnue)) 
deallocate(rnue)
 
  498   if(
associated(rnui)) 
deallocate(rnui)
 
  499   if(
associated(eps12)) 
deallocate(eps12)
 
  500   if(
associated(eps32)) 
deallocate(eps32)
 
  501   if(
associated(nneo)) 
deallocate(nneo)
 
  502   if(
associated(tneo)) 
deallocate(tneo)
 
  503   if(
associated(zneo)) 
deallocate(zneo)
 
  504   if(
associated(mneo)) 
deallocate(mneo)
 
subroutine l3deriv(y_in, x_in, nr_in, dydx_out, x_out, nr_out)
subroutine eq(pcequi, psicon, ncequi, nstep, ngrid,
subroutine flux(psitok, rk, zk, nk)
subroutine l3interp(y_in, x_in, nr_in, y_out, x_out, nr_out)
subroutine neowes(eq, coreprof, neoclassic)