42    real(dp), 
allocatable :: psi(:, :)
 
   45    real(dp), 
allocatable :: phi_cav(:)
 
   48    real(dp), 
allocatable :: gradphi_cav(:, :)
 
   50    real(dp), 
allocatable :: phi_grid(:, :)
 
   52    real(dp), 
allocatable :: zeta(:)
 
   54    real(dp) :: force_time
 
   61    real(dp), 
allocatable :: phi(:, :)
 
   64    real(dp), 
allocatable :: xs(:, :)
 
   71    real(dp), 
allocatable :: xs_rel_diff(:)
 
   77    real(dp), 
allocatable :: sgrid(:, :)
 
   80    real(dp), 
allocatable :: s(:, :)
 
   87    real(dp), 
allocatable :: s_rel_diff(:)
 
   97    real(dp), 
allocatable :: phiinf(:, :)
 
  100    real(dp), 
allocatable :: phieps(:, :)
 
  103    integer :: phieps_niter
 
  107    real(dp), 
allocatable :: phieps_rel_diff(:)
 
  110    real(dp) :: phieps_time
 
  114    real(dp), 
allocatable :: g(:, :)
 
  117    real(dp), 
allocatable :: y(:, :)
 
  123    real(dp), 
allocatable :: y_rel_diff(:)
 
  128    real(dp), 
allocatable :: ygrid(:, :)
 
  132    real(dp), 
allocatable :: q(:, :)
 
  135    real(dp), 
allocatable :: qgrid(:, :)
 
  142    real(dp), 
allocatable :: rhs_lpb(:,:,:)
 
  145    real(dp), 
allocatable :: rhs_adj_lpb(:,:,:)
 
  148    real(dp), 
allocatable :: x_lpb(:,:,:)
 
  152    real(dp), 
allocatable :: x_adj_lpb(:,:,:)
 
  155    real(dp), 
allocatable :: g_lpb(:,:)
 
  158    real(dp), 
allocatable :: f_lpb(:,:)
 
  161    integer :: x_lpb_niter
 
  164    integer :: x_adj_lpb_niter
 
  167    real(dp) :: x_lpb_time
 
  170    real(dp) :: x_adj_lpb_time
 
  174    real(dp), 
allocatable :: x_lpb_rel_diff(:)
 
  178    real(dp), 
allocatable :: x_adj_lpb_rel_diff(:)
 
  181    real(dp), 
allocatable :: zeta_dip(:, :)
 
  182    real(dp), 
allocatable :: x_adj_re_grid(:, :)
 
  183    real(dp), 
allocatable :: x_adj_r_grid(:, :)
 
  184    real(dp), 
allocatable :: x_adj_e_grid(:, :)
 
  185    real(dp), 
allocatable :: phi_n(:, :)
 
  187    real(dp) :: hsp_adj_time
 
  197    real(dp), 
allocatable :: phi_cav(:)
 
  200    real(dp), 
allocatable :: e_cav(:, :)
 
  203    real(dp), 
allocatable :: g_cav(:, :, :)
 
  205    logical :: do_phi = .false.
 
  207    logical :: do_e = .false.
 
  209    logical :: do_g = .false.
 
  216    type(ddx_params_type) :: params
 
  217    type(ddx_constants_type) :: constants
 
  218    type(ddx_workspace_type) :: workspace
 
  258subroutine allocate_model(nsph, x, y, z, rvdw, model, lmax, ngrid, force, fmm, pm, &
 
  259        & pl, se, eta, eps, kappa, matvecmem, maxiter, jacobi_ndiis, nproc, &
 
  260        & output_filename, ddx_data, ddx_error)
 
  263    integer, 
intent(in) :: nsph, model, lmax, force, fmm, pm, pl, &
 
  264        & matvecmem, maxiter, jacobi_ndiis, &
 
  266    real(dp), 
intent(in):: x(nsph), y(nsph), z(nsph), &
 
  267        & rvdw(nsph), se, eta, eps, kappa
 
  268    character(len=255), 
intent(in) :: output_filename
 
  270    type(
ddx_type), 
target, 
intent(out) :: ddx_data
 
  271    type(ddx_error_type), 
intent(inout) :: ddx_error
 
  273    real(dp), 
allocatable :: csph(:, :)
 
  275    if (ddx_error % flag .ne. 0) 
then 
  276        call update_error(ddx_error, 
"allocate_model received input in error state, " // &
 
  281    allocate(csph(3, nsph), stat=istatus)
 
  282    if (istatus .ne. 0) 
then 
  283        call update_error(ddx_error, 
"Allocation failed in allocate_model")
 
  289    call params_init(model, force, eps, kappa, eta, se, lmax, ngrid, &
 
  290        & matvecmem, maxiter, jacobi_ndiis, fmm, pm, pl, nproc, nsph, &
 
  291        & csph, rvdw, output_filename, ddx_data % params, ddx_error)
 
  292    if (ddx_error % flag .ne. 0) 
then 
  293        call update_error(ddx_error, 
"params_init returned an error, exiting")
 
  296    call constants_init(ddx_data % params, ddx_data % constants, ddx_error)
 
  297    if (ddx_error % flag .ne. 0) 
then 
  298        call update_error(ddx_error, 
"constants_init returned an error, exiting")
 
  302        & ddx_data % workspace, ddx_error)
 
  303    if (ddx_error % flag .ne. 0) 
then 
  304        call update_error(ddx_error, 
"workspace_init returned an error, exiting")
 
  307    deallocate(csph, stat=istatus)
 
  308    if (istatus .ne. 0) 
then 
  309        call update_error(ddx_error, 
"Deallocation failed in allocate_model")
 
  323    type(
ddx_type), 
intent(inout) :: ddx_data
 
  324    type(ddx_error_type), 
intent(inout) :: ddx_error
 
  345    type(ddx_error_type), 
intent(inout) :: ddx_error
 
  351    if (params % model .eq. 3) 
then 
  352        if (params % force .eq. 1) 
then 
  353            electrostatics % do_phi = .true.
 
  354            electrostatics % do_e = .true.
 
  355            electrostatics % do_g = .true.
 
  357            electrostatics % do_phi = .true.
 
  358            electrostatics % do_e = .true.
 
  359            electrostatics % do_g = .false.
 
  362        if (params % force .eq. 1) 
then 
  363            electrostatics % do_phi = .true.
 
  364            electrostatics % do_e = .true.
 
  365            electrostatics % do_g = .false.
 
  367            electrostatics % do_phi = .true.
 
  368            electrostatics % do_e = .false.
 
  369            electrostatics % do_g = .false.
 
  374    if (electrostatics % do_phi) 
then 
  375        allocate(electrostatics % phi_cav(constants % ncav), stat=info)
 
  376        if (info .ne. 0) 
then 
  377            call update_error(ddx_error, &
 
  378                & 
"Allocation failed in allocate_electrostatics")
 
  382    if (electrostatics % do_e) 
then 
  383        allocate(electrostatics % e_cav(3, constants % ncav), stat=info)
 
  384        if (info .ne. 0) 
then 
  385            call update_error(ddx_error, &
 
  386                & 
"Allocation failed in allocate_electrostatics")
 
  390    if (electrostatics % do_g) 
then 
  391        allocate(electrostatics % g_cav(3, 3, constants % ncav), stat=info)
 
  392        if (info .ne. 0) 
then 
  393            call update_error(ddx_error, &
 
  394                & 
"Allocation failed in allocate_electrostatics")
 
  409    type(ddx_error_type), 
intent(inout) :: ddx_error
 
  415    if (
allocated(electrostatics % phi_cav)) 
then 
  416        deallocate(electrostatics % phi_cav, stat=info)
 
  417        if (info .ne. 0) 
then 
  418            call update_error(ddx_error, &
 
  419                & 
"Deallocation failed in deallocate_electrostatics")
 
  422    if (
allocated(electrostatics % e_cav)) 
then 
  423        deallocate(electrostatics % e_cav, stat=info)
 
  424        if (info .ne. 0) 
then 
  425            call update_error(ddx_error, &
 
  426                & 
"Deallocation failed in deallocate_electrostatics")
 
  429    if (
allocated(electrostatics % g_cav)) 
then 
  430        deallocate(electrostatics % g_cav, stat=info)
 
  431        if (info .ne. 0) 
then 
  432            call update_error(ddx_error, &
 
  433                & 
"Deallocation failed in deallocate_electrostatics")
 
  451    type(ddx_error_type), 
intent(inout) :: ddx_error
 
  454    allocate(state % psi(constants % nbasis, params % nsph), stat=istatus)
 
  455    if (istatus .ne. 0) 
then 
  456        call update_error(ddx_error, 
"allocate_state: `psi` allocation failed")
 
  459    allocate(state % phi_cav(constants % ncav), stat=istatus)
 
  460    if (istatus .ne. 0) 
then 
  461        call update_error(ddx_error, 
"allocate_state: `phi_cav` allocation failed")
 
  464    allocate(state % gradphi_cav(3, constants % ncav), stat=istatus)
 
  465    if (istatus .ne. 0) 
then 
  466        call update_error(ddx_error, &
 
  467            & 
"allocate_state: `gradphi_cav` allocation failed")
 
  470    allocate(state % q(constants % nbasis, &
 
  471        & params % nsph), stat=istatus)
 
  472    if (istatus .ne. 0) 
then 
  473        call update_error(ddx_error, 
"allocate_state: `q` " // &
 
  474            & 
"allocation failed")
 
  479    if (params % model .eq. 1) 
then 
  480        allocate(state % phi_grid(params % ngrid, &
 
  481            & params % nsph), stat=istatus)
 
  482        if (istatus .ne. 0) 
then 
  483            call update_error(ddx_error, 
"allocate_state: `phi_grid` " // &
 
  484                & 
"allocation failed")
 
  487        allocate(state % phi(constants % nbasis, &
 
  488            & params % nsph), stat=istatus)
 
  489        if (istatus .ne. 0) 
then 
  490            call update_error(ddx_error, 
"allocate_state: `phi` " // &
 
  491                & 
"allocation failed")
 
  494        allocate(state % xs(constants % nbasis, &
 
  495            & params % nsph), stat=istatus)
 
  496        if (istatus .ne. 0) 
then 
  497            call update_error(ddx_error, 
"allocate_state: `xs` " // &
 
  498                & 
"allocation failed")
 
  501        allocate(state % xs_rel_diff(params % maxiter), &
 
  503        if (istatus .ne. 0) 
then 
  504            call update_error(ddx_error, 
"allocate_state: `xs_rel_diff` " // &
 
  505                & 
"allocation failed")
 
  508        allocate(state % s(constants % nbasis, &
 
  509            & params % nsph), stat=istatus)
 
  510        if (istatus .ne. 0) 
then 
  511            call update_error(ddx_error, 
"allocate_state: `s` " // &
 
  512            & 
"allocation failed")
 
  515        allocate(state % s_rel_diff(params % maxiter), &
 
  517        if (istatus .ne. 0) 
then 
  518            call update_error(ddx_error, 
"allocate_state: `s_rel_diff` " // &
 
  519                & 
"allocation failed")
 
  522        allocate(state % sgrid(params % ngrid, &
 
  523            & params % nsph), stat=istatus)
 
  524        if (istatus .ne. 0) 
then 
  525            call update_error(ddx_error, 
"allocate_state: `sgrid` " // &
 
  526                & 
"allocation failed")
 
  529        allocate(state % zeta(constants % ncav), stat=istatus)
 
  530        if (istatus .ne. 0) 
then 
  531            call update_error(ddx_error, 
"allocate_state: `zeta` " // &
 
  532                & 
"allocation failed")
 
  536    else if (params % model .eq. 2) 
then 
  537        allocate(state % phi_grid(params % ngrid, &
 
  538            & params % nsph), stat=istatus)
 
  539        if (istatus .ne. 0) 
then 
  540            call update_error(ddx_error, 
"allocate_state: `phi_grid` " // &
 
  541                & 
"allocation failed")
 
  544        allocate(state % phi(constants % nbasis, &
 
  545            & params % nsph), stat=istatus)
 
  546        if (istatus .ne. 0) 
then 
  547            call update_error(ddx_error, 
"allocate_state: `phi` " // &
 
  548                & 
"allocation failed")
 
  551        allocate(state % phiinf(constants % nbasis, &
 
  552            & params % nsph), stat=istatus)
 
  553        if (istatus .ne. 0) 
then 
  554            call update_error(ddx_error, 
"allocate_state: `phiinf` " // &
 
  555                & 
"allocation failed")
 
  558        allocate(state % phieps(constants % nbasis, &
 
  559            & params % nsph), stat=istatus)
 
  560        if (istatus .ne. 0) 
then 
  561            call update_error(ddx_error, 
"allocate_state: `phieps` " // &
 
  562                & 
"allocation failed")
 
  565        allocate(state % phieps_rel_diff(params % maxiter), &
 
  567        if (istatus .ne. 0) 
then 
  568            call update_error(ddx_error, 
"allocate_state: `xs_rel_diff` " // &
 
  569                & 
"allocation failed")
 
  572        allocate(state % xs(constants % nbasis, &
 
  573            & params % nsph), stat=istatus)
 
  574        if (istatus .ne. 0) 
then 
  575            call update_error(ddx_error, 
"allocate_state: `xs` " // &
 
  576                & 
"allocation failed")
 
  579        allocate(state % xs_rel_diff(params % maxiter), &
 
  581        if (istatus .ne. 0) 
then 
  582            call update_error(ddx_error, 
"allocate_state: `xs_rel_diff` " // &
 
  583                & 
"allocation failed")
 
  586        allocate(state % s(constants % nbasis, &
 
  587            & params % nsph), stat=istatus)
 
  588        if (istatus .ne. 0) 
then 
  589            call update_error(ddx_error, 
"allocate_state: `s` " // &
 
  590                & 
"allocation failed")
 
  593        allocate(state % s_rel_diff(params % maxiter), &
 
  595        if (istatus .ne. 0) 
then 
  596            call update_error(ddx_error, 
"allocate_state: `xs_rel_diff` " // &
 
  597                & 
"allocation failed")
 
  600        allocate(state % sgrid(params % ngrid, &
 
  601            & params % nsph), stat=istatus)
 
  602        if (istatus .ne. 0) 
then 
  603            call update_error(ddx_error, 
"allocate_state: `sgrid` " // &
 
  604                & 
"allocation failed")
 
  607        allocate(state % y(constants % nbasis, &
 
  608            & params % nsph), stat=istatus)
 
  609        if (istatus .ne. 0) 
then 
  610            call update_error(ddx_error, 
"allocate_state: `y` " // &
 
  611                & 
"allocation failed")
 
  614        allocate(state % y_rel_diff(params % maxiter), &
 
  616        if (istatus .ne. 0) 
then 
  617            call update_error(ddx_error, 
"allocate_state: `y_rel_diff` " // &
 
  618                & 
"allocation failed")
 
  621        allocate(state % ygrid(params % ngrid, &
 
  622            & params % nsph), stat=istatus)
 
  623        if (istatus .ne. 0) 
then 
  624            call update_error(ddx_error, 
"allocate_state: `ygrid` " // &
 
  625                & 
"allocation failed")
 
  628        allocate(state % g(constants % nbasis, &
 
  629            & params % nsph), stat=istatus)
 
  630        if (istatus .ne. 0) 
then 
  631            call update_error(ddx_error, 
"allocate_state: `g` " // &
 
  632                & 
"allocation failed")
 
  635        allocate(state % qgrid(params % ngrid, &
 
  636            & params % nsph), stat=istatus)
 
  637        if (istatus .ne. 0) 
then 
  638            call update_error(ddx_error, 
"allocate_state: `qgrid` " // &
 
  639                & 
"allocation failed")
 
  642        allocate(state % zeta(constants % ncav), stat=istatus)
 
  643        if (istatus .ne. 0) 
then 
  644            call update_error(ddx_error, 
"allocate_state: `zeta` " // &
 
  645                & 
"allocation failed")
 
  649    else if (params % model .eq. 3) 
then 
  650        allocate(state % phi_grid(params % ngrid, &
 
  651            & params % nsph), stat=istatus)
 
  652        if (istatus .ne. 0) 
then 
  653            call update_error(ddx_error, 
"allocate_state: `phi_grid` " // &
 
  654                & 
"allocation failed")
 
  657        allocate(state % phi(constants % nbasis, &
 
  658            & params % nsph), stat=istatus)
 
  659        if (istatus .ne. 0) 
then 
  660            call update_error(ddx_error, 
"allocate_state: `phi` " // &
 
  661                & 
"allocation failed")
 
  664        allocate(state % zeta(constants % ncav), stat=istatus)
 
  665        if (istatus .ne. 0) 
then 
  666            call update_error(ddx_error, 
"allocate_state: `zeta` " // &
 
  667                & 
"allocation failed")
 
  671        allocate(state % x_lpb_rel_diff(params % maxiter), &
 
  673        if (istatus .ne. 0) 
then 
  674            call update_error(ddx_error, 
"allocate_state: `x_lpb_rel_diff` " // &
 
  675                & 
"allocation failed")
 
  678        allocate(state % rhs_lpb(constants % nbasis, &
 
  679            & params % nsph, 2), &
 
  681        if (istatus .ne. 0) 
then 
  682            call update_error(ddx_error, 
"allocate_state: `rhs_lpb` " // &
 
  683                & 
"allocation failed")
 
  686        allocate(state % rhs_adj_lpb(constants % nbasis, &
 
  687            & params % nsph, 2), &
 
  689        if (istatus .ne. 0) 
then 
  690            call update_error(ddx_error, 
"allocate_state: `rhs_adj_lpb` " // &
 
  691                & 
"allocation failed")
 
  694        allocate(state % x_lpb(constants % nbasis, &
 
  695            & params % nsph, 2), &
 
  697        if (istatus .ne. 0) 
then 
  698            call update_error(ddx_error, 
"allocate_state: `x_lpb` " // &
 
  699                & 
"allocation failed")
 
  702        allocate(state % x_adj_lpb(constants % nbasis, &
 
  703            & params % nsph, 2), stat=istatus)
 
  704        if (istatus .ne. 0) 
then 
  705            call update_error(ddx_error, 
"allocate_state: `x_adj_lpb` " // &
 
  706                & 
"allocation failed")
 
  709        allocate(state % x_adj_lpb_rel_diff(params % maxiter), &
 
  711        if (istatus .ne. 0) 
then 
  712            call update_error(ddx_error, &
 
  713                & 
"allocate_state: `x_adj_lpb_rel_diff` allocation failed")
 
  716        allocate(state % g_lpb(params % ngrid, &
 
  717            & params % nsph), stat=istatus)
 
  718        if (istatus .ne. 0) 
then 
  719            call update_error(ddx_error, 
"allocate_state: `g_lpb` " // &
 
  720                & 
"allocation failed")
 
  723        allocate(state % f_lpb(params % ngrid, &
 
  724            & params % nsph), stat=istatus)
 
  725        if (istatus .ne. 0) 
then 
  726            call update_error(ddx_error, 
"allocate_state: `f_lpb` " // &
 
  727                & 
"allocation failed")
 
  730        allocate(state % zeta_dip(3, constants % ncav), stat=istatus)
 
  731        if (istatus .ne. 0) 
then 
  732            call update_error(ddx_error, 
"allocate_state: `zeta_dip` " // &
 
  733                & 
"allocation failed")
 
  736        allocate(state % x_adj_re_grid(params % ngrid, params % nsph), &
 
  738        if (istatus .ne. 0) 
then 
  739            call update_error(ddx_error, 
"allocate_state: `x_adj_re_grid` " // &
 
  740                & 
"allocation failed")
 
  743        allocate(state % x_adj_r_grid(params % ngrid, params % nsph), &
 
  745        if (istatus .ne. 0) 
then 
  746            call update_error(ddx_error, 
"allocate_state: `x_adj_r_grid` " // &
 
  747                & 
"allocation failed")
 
  750        allocate(state % x_adj_e_grid(params % ngrid, params % nsph), &
 
  752        if (istatus .ne. 0) 
then 
  753            call update_error(ddx_error, 
"allocate_state: `x_adj_e_grid` " // &
 
  754                & 
"allocation failed")
 
  757        allocate(state % phi_n(params % ngrid, params % nsph), &
 
  759        if (istatus .ne. 0) 
then 
  760            call update_error(ddx_error, 
"allocate_state: `phi_n` " // &
 
  761                & 
"allocation failed")
 
  777    type(ddx_error_type), 
intent(inout) :: ddx_error
 
  780    if (
allocated(state % phi_cav)) 
then 
  781        deallocate(state % phi_cav, stat=istatus)
 
  782        if (istatus .ne. 0) 
then 
  783            call update_error(ddx_error, 
"`phi_cav` deallocation failed!")
 
  787    if (
allocated(state % gradphi_cav)) 
then 
  788        deallocate(state % gradphi_cav, stat=istatus)
 
  789        if (istatus .ne. 0) 
then 
  790            call update_error(ddx_error, 
"`gradphi_cav` deallocation failed!")
 
  794    if (
allocated(state % psi)) 
then 
  795        deallocate(state % psi, stat=istatus)
 
  796        if (istatus .ne. 0) 
then 
  797            call update_error(ddx_error, 
"`psi` deallocation failed!")
 
  801    if (
allocated(state % phi_grid)) 
then 
  802        deallocate(state % phi_grid, stat=istatus)
 
  803        if (istatus .ne. 0) 
then 
  804            call update_error(ddx_error, 
"`phi_grid` deallocation failed!")
 
  808    if (
allocated(state % phi)) 
then 
  809        deallocate(state % phi, stat=istatus)
 
  810        if (istatus .ne. 0) 
then 
  811            call update_error(ddx_error, 
"`phi` deallocation failed!")
 
  814    if (
allocated(state % phiinf)) 
then 
  815        deallocate(state % phiinf, stat=istatus)
 
  816        if (istatus .ne. 0) 
then 
  817            call update_error(ddx_error, 
"`phiinf` deallocation failed!")
 
  820    if (
allocated(state % phieps)) 
then 
  821        deallocate(state % phieps, stat=istatus)
 
  822        if (istatus .ne. 0) 
then 
  823            call update_error(ddx_error, 
"`phieps` deallocation failed!")
 
  826    if (
allocated(state % phieps_rel_diff)) 
then 
  827        deallocate(state % phieps_rel_diff, stat=istatus)
 
  828        if (istatus .ne. 0) 
then 
  829            call update_error(ddx_error, 
"`phieps_rel_diff` deallocation failed!")
 
  832    if (
allocated(state % xs)) 
then 
  833        deallocate(state % xs, stat=istatus)
 
  834        if (istatus .ne. 0) 
then 
  835            call update_error(ddx_error, 
"`xs` deallocation failed!")
 
  838    if (
allocated(state % xs_rel_diff)) 
then 
  839        deallocate(state % xs_rel_diff, stat=istatus)
 
  840        if (istatus .ne. 0) 
then 
  841            call update_error(ddx_error, 
"`xs_rel_diff` deallocation failed!")
 
  844    if (
allocated(state % s)) 
then 
  845        deallocate(state % s, stat=istatus)
 
  846        if (istatus .ne. 0) 
then 
  847            call update_error(ddx_error, 
"`s` deallocation failed!")
 
  850    if (
allocated(state % s_rel_diff)) 
then 
  851        deallocate(state % s_rel_diff, stat=istatus)
 
  852        if (istatus .ne. 0) 
then 
  853            call update_error(ddx_error, 
"`s_rel_diff` deallocation failed!")
 
  856    if (
allocated(state % sgrid)) 
then 
  857        deallocate(state % sgrid, stat=istatus)
 
  858        if (istatus .ne. 0) 
then 
  859            call update_error(ddx_error, 
"`sgrid` deallocation failed!")
 
  862    if (
allocated(state % y)) 
then 
  863        deallocate(state % y, stat=istatus)
 
  864        if (istatus .ne. 0) 
then 
  865            call update_error(ddx_error, 
"`y` deallocation failed!")
 
  868    if (
allocated(state % y_rel_diff)) 
then 
  869        deallocate(state % y_rel_diff, stat=istatus)
 
  870        if (istatus .ne. 0) 
then 
  871            call update_error(ddx_error, 
"`y_rel_diff` deallocation failed!")
 
  874    if (
allocated(state % ygrid)) 
then 
  875        deallocate(state % ygrid, stat=istatus)
 
  876        if (istatus .ne. 0) 
then 
  877            call update_error(ddx_error, 
"`ygrid` deallocation failed!")
 
  880    if (
allocated(state % g)) 
then 
  881        deallocate(state % g, stat=istatus)
 
  882        if (istatus .ne. 0) 
then 
  883            call update_error(ddx_error, 
"`g` deallocation failed!")
 
  886    if (
allocated(state % q)) 
then 
  887        deallocate(state % q, stat=istatus)
 
  888        if (istatus .ne. 0) 
then 
  889            call update_error(ddx_error, 
"`q` deallocation failed!")
 
  892    if (
allocated(state % qgrid)) 
then 
  893        deallocate(state % qgrid, stat=istatus)
 
  894        if (istatus .ne. 0) 
then 
  895            call update_error(ddx_error, 
"`qgrid` deallocation failed!")
 
  898    if (
allocated(state % zeta)) 
then 
  899        deallocate(state % zeta, stat=istatus)
 
  900        if (istatus .ne. 0) 
then 
  901            call update_error(ddx_error, 
"`zeta` deallocation failed!")
 
  904    if (
allocated(state % x_lpb)) 
then 
  905        deallocate(state % x_lpb, stat=istatus)
 
  906        if (istatus .ne. 0) 
then 
  907            call update_error(ddx_error, 
"`x_lpb` deallocation failed!")
 
  910    if (
allocated(state % x_lpb_rel_diff)) 
then 
  911        deallocate(state % x_lpb_rel_diff, stat=istatus)
 
  912        if (istatus .ne. 0) 
then 
  913            call update_error(ddx_error, 
"`x_lpb_rel_diff` deallocation failed!")
 
  916    if (
allocated(state % x_adj_lpb)) 
then 
  917        deallocate(state % x_adj_lpb, stat=istatus)
 
  918        if (istatus .ne. 0) 
then 
  919            call update_error(ddx_error, 
"x_adj_lpb deallocation failed!")
 
  922    if (
allocated(state % x_adj_lpb_rel_diff)) 
then 
  923        deallocate(state % x_adj_lpb_rel_diff, stat=istatus)
 
  924        if (istatus .ne. 0) 
then 
  925            call update_error(ddx_error, 
"`x_adj_lpb_rel_diff` deallocation failed!")
 
  928    if (
allocated(state % g_lpb)) 
then 
  929        deallocate(state % g_lpb, stat=istatus)
 
  930        if (istatus .ne. 0) 
then 
  931            call update_error(ddx_error, 
"`g_lpb` deallocation failed!")
 
  934    if (
allocated(state % f_lpb)) 
then 
  935        deallocate(state % f_lpb, stat=istatus)
 
  936        if (istatus .ne. 0) 
then 
  937            call update_error(ddx_error, 
"`f_lpb` deallocation failed!")
 
  940    if (
allocated(state % rhs_lpb)) 
then 
  941        deallocate(state % rhs_lpb, stat=istatus)
 
  942        if (istatus .ne. 0) 
then 
  943            call update_error(ddx_error, 
"`rhs_lpb` deallocation failed!")
 
  946    if (
allocated(state % rhs_adj_lpb)) 
then 
  947        deallocate(state % rhs_adj_lpb, stat=istatus)
 
  948        if (istatus .ne. 0) 
then 
  949            call update_error(ddx_error, 
"`rhs_adj_lpb` deallocation failed!")
 
  952    if (
allocated(state % zeta_dip)) 
then 
  953        deallocate(state % zeta_dip, stat=istatus)
 
  954        if (istatus .ne. 0) 
then 
  955            call update_error(ddx_error, 
"`zeta_dip` deallocation failed!")
 
  958    if (
allocated(state % x_adj_re_grid)) 
then 
  959        deallocate(state % x_adj_re_grid, stat=istatus)
 
  960        if (istatus .ne. 0) 
then 
  961            call update_error(ddx_error, 
"`x_adj_re_grid` deallocation failed!")
 
  964    if (
allocated(state % x_adj_r_grid)) 
then 
  965        deallocate(state % x_adj_r_grid, stat=istatus)
 
  966        if (istatus .ne. 0) 
then 
  967            call update_error(ddx_error, 
"`x_adj_r_grid` deallocation failed!")
 
  970    if (
allocated(state % x_adj_e_grid)) 
then 
  971        deallocate(state % x_adj_e_grid, stat=istatus)
 
  972        if (istatus .ne. 0) 
then 
  973            call update_error(ddx_error, 
"`x_adj_e_grid` deallocation failed!")
 
  976    if (
allocated(state % phi_n)) 
then 
  977        deallocate(state % phi_n, stat=istatus)
 
  978        if (istatus .ne. 0) 
then 
  979            call update_error(ddx_error, 
"`phi_n` deallocation failed!")
 
  999    character (len=*), 
intent(in) :: label
 
 1000    integer, 
intent(in) :: nbasis, lmax, ncol, icol, iunit
 
 1001    real(dp), 
intent(in) :: x(nbasis, ncol)
 
 1003    integer :: l, m, ind, noff, nprt, ic, j
 
 1005    if (ncol .eq. 1) 
then 
 1006        write (iunit,
'(3x,a,1x,a,i4,a)') label, 
"(column ", icol, 
")" 
 1008        write (iunit,
'(3x,a)') label
 
 1011    if (ncol .eq. 1) 
then 
 1015                write(iunit,1000) l, m, x(ind+m, 1)
 
 1020        nprt = max(ncol-noff, 0)
 
 1022            write(iunit,1010) (j, j = ic, ic+4)
 
 1026                    write(iunit,1020) l, m, x(ind+m, ic:ic+4)
 
 1030        write (iunit,1010) (j, j = nprt+1, nprt+noff)
 
 1034                write(iunit,1020) l, m, x(ind+m, nprt+1:nprt+noff)
 
 1038    1000 
format(1x,i3,i4,f14.8)
 
 1039    1010 
format(8x,5i14)
 
 1040    1020 
format(1x,i3,i4,5f14.8)
 
 1056    character (len=*), 
intent(in) :: label
 
 1057    integer, 
intent(in) :: ngrid, ncol, icol, iunit
 
 1058    real(dp), 
intent(in) :: x(ngrid, ncol)
 
 1060    integer :: ig, noff, nprt, ic, j
 
 1062    if (ncol .eq. 1) 
then 
 1063        write (iunit,
'(3x,a,1x,a,i4,a)') label, 
"(column ", icol, 
")" 
 1065        write (iunit,
'(3x,a)') label
 
 1068    if (ncol .eq. 1) 
then 
 1070            write(iunit,1000) ig, x(ig, 1)
 
 1074        nprt = max(ncol-noff, 0)
 
 1076            write(iunit,1010) (j, j = ic, ic+4)
 
 1078                write(iunit,1020) ig, x(ig, ic:ic+4)
 
 1081        write (iunit,1010) (j, j = nprt+1, nprt+noff)
 
 1083            write(iunit,1020) ig, x(ig, nprt+1:nprt+noff)
 
 1087    1000 
format(1x,i5,f14.8)
 
 1088    1010 
format(6x,5i14)
 
 1089    1020 
format(1x,i5,5f14.8)
 
 1102    type(
ddx_type), 
intent(in)  :: ddx_data
 
 1103    character(len=*) :: label
 
 1104    real(dp) :: vector(ddx_data % constants % nbasis, ddx_data % params % nsph)
 
 1108    do isph = 1, ddx_data % params % nsph
 
 1109      do lm = 1, ddx_data % constants % nbasis
 
 1110        write(6,
'(F15.8)') vector(lm,isph)
 
 1132subroutine ddintegrate(nsph, nbasis, ngrid, vwgrid, ldvwgrid, x_grid, x_lm)
 
 1135    integer, 
intent(in) :: nsph, nbasis, ngrid, ldvwgrid
 
 1136    real(dp), 
intent(in) :: vwgrid(ldvwgrid, ngrid)
 
 1137    real(dp), 
intent(in) :: x_grid(ngrid, nsph)
 
 1139    real(dp), 
intent(out) :: x_lm(nbasis, nsph)
 
 1141    call dgemm(
'N', 
'N', nbasis, nsph, ngrid, one, vwgrid, ldvwgrid, x_grid, &
 
 1142        & ngrid, zero, x_lm, nbasis)
 
 1160subroutine dbasis(params, constants, x, basloc, dbsloc, vplm, vcos, vsin)
 
 1164    real(dp), 
dimension(3),        
intent(in)    :: x
 
 1165    real(dp), 
dimension(constants % nbasis),   
intent(inout) :: basloc, vplm
 
 1166    real(dp), 
dimension(3, constants % nbasis), 
intent(inout) :: dbsloc
 
 1167    real(dp), 
dimension(params % lmax+1),   
intent(inout) :: vcos, vsin
 
 1168    integer :: l, m, ind
 
 1169    real(dp)  :: cthe, sthe, cphi, sphi, plm, fln, pp1, pm1, pp, VC, VS
 
 1170    real(dp)  :: et(3), ep(3)
 
 1175    sthe = sqrt(one - cthe*cthe)
 
 1177    if ( sthe.ne.zero ) 
then 
 1190    if( sthe.ne.zero ) 
then 
 1204    call polleg_work( cthe, sthe, params % lmax, vplm, vcos )
 
 1211    if ( sthe.ne.zero ) 
then 
 1212        call trgev( cphi, sphi, params % lmax, vcos, vsin )
 
 1223    do l = 0, params % lmax
 
 1226        fln = constants % vscales(ind)   
 
 1227        basloc(ind) = fln*vplm(ind)
 
 1229            dbsloc(:,ind) = fln*vplm(ind+1)*et(:)
 
 1231            dbsloc(:,ind) = zero
 
 1234            fln = constants % vscales(ind+m)
 
 1235            plm = fln*vplm(ind+m)   
 
 1237            if (m.lt.l) pp1 = -pt5*vplm(ind+m+1)
 
 1238            pm1 = pt5*(dble(l+m)*dble(l-m+1)*vplm(ind+m-1))
 
 1244            basloc(ind+m) = plm*vcos(m+1)
 
 1247            if ( sthe.ne.zero ) 
then 
 1249                dbsloc(:,ind+m) = -fln*pp*vcos(m+1)*et(:) - dble(m)*plm*vsin(m+1)*ep(:)
 
 1255                dbsloc(:,ind+m) = -fln*pp*vcos(m+1)*et(:) - fln*pp*ep(:)*vc
 
 1263            basloc(ind-m) = plm*vsin(m+1)
 
 1266            if ( sthe.ne.zero ) 
then 
 1268                dbsloc(:,ind-m) = -fln*pp*vsin(m+1)*et(:) + dble(m)*plm*vcos(m+1)*ep(:)
 
 1273                dbsloc(:,ind-m) = -fln*pp*vsin(m+1)*et(:) - fln*pp*ep(:)*vs
 
 1291real(dp) function intmlp(params, constants, t, sigma, basloc )
 
 1296      real(dp), 
intent(in) :: t
 
 1297      real(dp), 
dimension(constants % nbasis), 
intent(in) :: sigma, basloc
 
 1300      real(dp)  :: tt, ss, fac
 
 1311      do l = 0, params % lmax
 
 1316        fac = tt / constants % vscales(ind)**2
 
 1319        ss = ss + fac * dot_product( basloc(ind-l:ind+l), &
 
 1320                                     sigma( ind-l:ind+l)   )
 
 1337subroutine wghpot(ncav, phi_cav, nsph, ngrid, ui, phi_grid, g)
 
 1340    integer, 
intent(in) :: ncav, nsph, ngrid
 
 1341    real(dp), 
intent(in) :: phi_cav(ncav), ui(ngrid, nsph)
 
 1343    real(dp), 
intent(out) :: g(ngrid, nsph), phi_grid(ngrid, nsph)
 
 1345    integer isph, igrid, icav
 
 1356            if (ui(igrid, isph) .ne. zero) 
then 
 1359                phi_grid(igrid, isph) = phi_cav(icav)
 
 1361                g(igrid, isph) = -ui(igrid, isph) * phi_cav(icav)
 
 1370    integer, 
intent(in) :: lmax, nbasis
 
 1371    real(dp), 
dimension(nbasis), 
intent(in) :: u
 
 1372    real(dp), 
intent(inout) :: unorm
 
 1373    integer :: l, m, ind
 
 1379        fac = one/(one + dble(l))
 
 1381            unorm = unorm + fac*u(ind+m)*u(ind+m)
 
 1389real(dp) function hnorm(lmax, nbasis, nsph, x)
 
 1391    integer, 
intent(in) :: lmax, nbasis, nsph
 
 1392    real(dp),  
dimension(nbasis, nsph), 
intent(in) :: x
 
 1394    real(dp) :: vrms, fac
 
 1400        call hsnorm(lmax, nbasis, x(:,isph), fac)
 
 1401        vrms = vrms + fac*fac
 
 1403    hnorm = sqrt(vrms/dble(nsph))
 
 1406real(dp) function rmsnorm(lmax, nbasis, nsph, x)
 
 1409    integer, 
intent(in) :: lmax, nbasis, nsph
 
 1410    real(dp),  
dimension(nbasis, nsph), 
intent(in) :: x
 
 1412    real(dp) :: vrms, vmax
 
 1414    if (lmax.eq.0) 
continue 
 1416    call rmsvec(n,x,vrms,vmax)
 
 1423    integer, 
intent(in) :: n
 
 1424    real(dp), 
dimension(n), 
intent(in) :: v
 
 1425    real(dp), 
intent(inout) :: vrms, vmax
 
 1431      vmax = max(vmax,abs(v(i)))
 
 1432      vrms = vrms + v(i)*v(i)
 
 1435    vrms = sqrt(vrms/dble(n))
 
 1438subroutine adjrhs(params, constants, isph, xi, vlm, work)
 
 1442    integer, 
intent(in) :: isph
 
 1443    real(dp), 
dimension(params % ngrid, params % nsph), 
intent(in) :: xi
 
 1444    real(dp), 
dimension(constants % nbasis), 
intent(inout) :: vlm
 
 1445    real(dp), 
dimension(params % lmax+1), 
intent(inout) :: work
 
 1447    integer :: ij, jsph, ig
 
 1448    real(dp)  :: vji(3), vvji, tji, xji, oji, fac
 
 1450    do ij = constants % inl(isph), constants % inl(isph+1)-1
 
 1451      jsph = constants % nl(ij)
 
 1452      do ig = 1, params % ngrid
 
 1453        vji  = params % csph(:,jsph) + params % rsph(jsph)* &
 
 1454            & constants % cgrid(:,ig) - params % csph(:,isph)
 
 1455        vvji = sqrt(dot_product(vji,vji))
 
 1456        tji  = vvji/params % rsph(isph)
 
 1457        if ( tji.lt.( one + (params % se+one)/two*params % eta ) ) 
then 
 1458          xji = 
fsw( tji, params % se, params % eta )
 
 1459          if ( constants % fi(ig,jsph).gt.one ) 
then 
 1460            oji = xji/ constants % fi(ig,jsph)
 
 1464          fac = constants % wgrid(ig) * xi(ig,jsph) * oji
 
 1466              & params % lmax, constants % vscales_rel, one, vlm, work)
 
 1470end subroutine adjrhs
 
 1472subroutine calcv(params, constants, isph, pot, sigma, work)
 
 1476    integer, 
intent(in) :: isph
 
 1477    real(dp), 
dimension(constants % nbasis, params % nsph), 
intent(in) :: sigma
 
 1478    real(dp), 
dimension(params % ngrid), 
intent(inout) :: pot
 
 1479    real(dp), 
dimension(params % lmax+1), 
intent(inout) :: work
 
 1481    integer :: its, ij, jsph
 
 1483    real(dp) :: vvij, tij, xij, oij, thigh
 
 1485    thigh = one + pt5*(params % se + one)*params % eta
 
 1488    do its = 1, params % ngrid
 
 1490        if (constants % ui(its,isph).lt.one) 
then 
 1492            do ij = constants % inl(isph), constants % inl(isph+1)-1
 
 1493                jsph = constants % nl(ij)
 
 1495                vij  = params % csph(:,isph) + params % rsph(isph)* &
 
 1496                    & constants % cgrid(:,its) - params % csph(:,jsph)
 
 1497                vvij = sqrt( dot_product( vij, vij ) )
 
 1498                tij  = vvij / params % rsph(jsph)
 
 1500                if (tij.lt.thigh) 
then 
 1501                    xij = 
fsw(tij, params % se, params % eta)
 
 1502                    if (constants % fi(its,isph).gt.one) 
then 
 1503                        oij = xij / constants % fi(its,isph)
 
 1507                    call fmm_l2p_work(vij, params % rsph(jsph), params % lmax, &
 
 1508                        & constants % vscales_rel, oij, sigma(:, jsph), one, &
 
 1524    real(dp), 
intent(in) :: alpha, x_sph(constants % nbasis, params % nsph), &
 
 1527    real(dp), 
intent(inout) :: x_grid(params % ngrid, params % nsph)
 
 1530        & constants % vgrid, constants % vgrid_nbasis, alpha, x_sph, beta, &
 
 1538        & x_sph, beta, x_grid)
 
 1541    integer, 
intent(in) :: nbasis, ngrid, nsph, ldvgrid
 
 1542    real(dp), 
intent(in) :: vgrid(ldvgrid, ngrid), alpha, &
 
 1543        & x_sph(nbasis, nsph), beta
 
 1545    real(dp), 
intent(inout) :: x_grid(ngrid, nsph)
 
 1549    call dgemm(
'T', 
'N', ngrid, nsph, nbasis, alpha, vgrid, ldvgrid, x_sph, &
 
 1550        & nbasis, beta, x_grid, ngrid)
 
 1559    real(dp), 
intent(in) :: alpha, x_grid(params % ngrid, params % nsph), &
 
 1562    real(dp), 
intent(inout) :: x_sph(constants % nbasis, params % nsph)
 
 1565        & params % nsph, constants % vwgrid, constants % vgrid_nbasis, alpha, &
 
 1566        & x_grid, beta, x_sph)
 
 1571        & x_grid, beta, x_sph)
 
 1574    integer, 
intent(in) :: nbasis, ngrid, nsph, ldvwgrid
 
 1575    real(dp), 
intent(in) :: vwgrid(ldvwgrid, ngrid), alpha, &
 
 1576        & x_grid(ngrid, nsph), beta
 
 1578    real(dp), 
intent(inout) :: x_sph(nbasis, nsph)
 
 1581    call dgemm(
'N', 
'N', nbasis, nsph, ngrid, alpha, vwgrid, ldvwgrid, &
 
 1582        & x_grid, ngrid, beta, x_sph, nbasis)
 
 1593    real(dp), 
intent(in) :: x_cav(constants % ncav)
 
 1595    real(dp), 
intent(inout) :: x_grid(params % ngrid, params % nsph)
 
 1598        & constants % icav_ia, constants % icav_ja, x_cav, x_grid)
 
 1608    integer, 
intent(in) :: ngrid, nsph, ncav
 
 1609    integer, 
intent(in) :: icav_ia(nsph+1), icav_ja(ncav)
 
 1610    real(dp), 
intent(in) :: x_cav(ncav)
 
 1612    real(dp), 
intent(out) :: x_grid(ngrid, nsph)
 
 1614    integer :: isph, icav, igrid, igrid_old
 
 1619        do icav = icav_ia(isph), icav_ia(isph+1)-1
 
 1620            igrid = icav_ja(icav)
 
 1621            x_grid(igrid_old+1:igrid-1, isph) = zero
 
 1622            x_grid(igrid, isph) = x_cav(icav)
 
 1625        x_grid(igrid+1:ngrid, isph) = zero
 
 1637    real(dp), 
intent(in)  :: s(constants%nbasis, params%nsph)
 
 1638    real(dp), 
intent(out) :: xi(constants%ncav)
 
 1639    integer :: its, isph, ii
 
 1641    do isph = 1, params%nsph
 
 1642        do its = 1, params%ngrid
 
 1643            if (constants%ui(its, isph) .gt. zero) 
then 
 1645                xi(ii) = constants%ui(its, isph)*dot_product( &
 
 1646                    & constants%vwgrid(:constants % nbasis, its), s(:, isph))
 
 1661    real(dp), 
intent(inout) :: node_m((params % pm+1)**2, constants % nclusters)
 
 1663    real(dp) :: work(6*params % pm**2 + 19*params % pm + 8)
 
 1677    real(dp), 
intent(inout) :: node_m((params % pm+1)**2, constants % nclusters)
 
 1679    real(dp), 
intent(out) :: work(6*params % pm**2 + 19*params % pm + 8)
 
 1682    real(dp) :: c1(3), c(3), r1, r
 
 1686    do i = constants % nclusters, 1, -1
 
 1688        if (constants % children(1, i) == 0) cycle
 
 1689        c = constants % cnode(:, i)
 
 1690        r = constants % rnode(i)
 
 1692        j = constants % children(1, i)
 
 1693        c1 = constants % cnode(:, j)
 
 1694        r1 = constants % rnode(j)
 
 1698            & constants % vscales, &
 
 1699            & constants % vcnk, one, &
 
 1700            & node_m(:, j), zero, node_m(:, i), work)
 
 1702        do j = constants % children(1, i)+1, constants % children(2, i)
 
 1703            c1 = constants % cnode(:, j)
 
 1704            r1 = constants % rnode(j)
 
 1707                & constants % vscales, constants % vcnk, one, &
 
 1708                & node_m(:, j), one, node_m(:, i), work)
 
 1722    real(dp), 
intent(inout) :: node_m((params % pm+1)**2, constants % nclusters)
 
 1739    real(dp), 
intent(inout) :: node_m((params % pm+1)**2, constants % nclusters)
 
 1741    real(dp) :: work(6*params % pm**2 + 19*params % pm + 8)
 
 1742    complex(dp) :: work_complex(2*params % pm+1)
 
 1745    real(dp) :: c1(3), c(3), r1, r
 
 1747    do i = constants % nclusters, 1, -1
 
 1749        if (constants % children(1, i) == 0) cycle
 
 1750        c = constants % cnode(:, i)
 
 1751        r = constants % rnode(i)
 
 1753        j = constants % children(1, i)
 
 1754        c1 = constants % cnode(:, j)
 
 1755        r1 = constants % rnode(j)
 
 1756        c1 = params % kappa*(c1 - c)
 
 1758            & constants % SK_rnode(:, j), constants % SK_rnode(:, i), &
 
 1759            & params % pm, constants % vscales, one, node_m(:, j), zero, &
 
 1760            & node_m(:, i), work, work_complex)
 
 1762        do j = constants % children(1, i)+1, constants % children(2, i)
 
 1763            c1 = constants % cnode(:, j)
 
 1764            r1 = constants % rnode(j)
 
 1765            c1 = params % kappa*(c1 - c)
 
 1767                & constants % SK_rnode(:, j), constants % SK_rnode(:, i), &
 
 1768                & params % pm, constants % vscales, one, node_m(:, j), one, &
 
 1769                & node_m(:, i), work, work_complex)
 
 1783    real(dp), 
intent(inout) :: node_m((params % pm+1)**2, constants % nclusters)
 
 1785    real(dp) :: work(6*params % pm**2 + 19*params % pm + 8)
 
 1799    real(dp), 
intent(inout) :: node_m((params % pm+1)**2, constants % nclusters)
 
 1801    real(dp), 
intent(out) :: work(6*params % pm**2 + 19*params % pm + 8)
 
 1804    real(dp) :: c1(3), c(3), r1, r
 
 1806    do i = 2, constants % nclusters
 
 1807        j = constants % parent(i)
 
 1808        c = constants % cnode(:, j)
 
 1809        r = constants % rnode(j)
 
 1810        c1 = constants % cnode(:, i)
 
 1811        r1 = constants % rnode(i)
 
 1814            & constants % vscales, constants % vcnk, one, node_m(:, j), one, &
 
 1815            & node_m(:, i), work)
 
 1827    real(dp), 
intent(inout) :: node_m((params % pm+1)**2, constants % nclusters)
 
 1842    real(dp), 
intent(inout) :: node_m((params % pm+1)**2, constants % nclusters)
 
 1844    real(dp) :: work(6*params % pm**2 + 19*params % pm + 8)
 
 1845    complex(dp) :: work_complex(2*params % pm+1)
 
 1848    real(dp) :: c1(3), c(3)
 
 1850    do i = 2, constants % nclusters
 
 1851        j = constants % parent(i)
 
 1852        c = constants % cnode(:, j)
 
 1853        c1 = constants % cnode(:, i)
 
 1854        c1 = params % kappa*(c1 - c)
 
 1857            & constants % SK_rnode(:, j), params % pm, constants % vscales, &
 
 1858            & one, node_m(:, j), one, node_m(:, i), work, work_complex)
 
 1871    real(dp), 
intent(inout) :: node_l((params % pl+1)**2, constants % nclusters)
 
 1873    real(dp) :: work(6*params % pl**2 + 19*params % pl + 8)
 
 1887    real(dp), 
intent(inout) :: node_l((params % pl+1)**2, constants % nclusters)
 
 1889    real(dp), 
intent(out) :: work(6*params % pl**2 + 19*params % pl + 8)
 
 1892    real(dp) :: c1(3), c(3), r1, r
 
 1896    do i = 2, constants % nclusters
 
 1897        j = constants % parent(i)
 
 1898        c = constants % cnode(:, j)
 
 1899        r = constants % rnode(j)
 
 1900        c1 = constants % cnode(:, i)
 
 1901        r1 = constants % rnode(i)
 
 1904            & constants % vscales, constants % vfact, one, &
 
 1905            & node_l(:, j), one, node_l(:, i), work)
 
 1918    real(dp), 
intent(inout) :: node_l((params % pl+1)**2, constants % nclusters)
 
 1935    real(dp), 
intent(inout) :: node_l((params % pl+1)**2, constants % nclusters)
 
 1937    real(dp) :: work(6*params % pl**2 + 19*params % pl + 8)
 
 1938    complex(dp) :: work_complex(2*params % pl+1)
 
 1941    real(dp) :: c_child(3), c_parent(3), c_diff(3)
 
 1943    do i = 2, constants % nclusters
 
 1944        j = constants % parent(i)
 
 1945        c_child = constants % cnode(:, j)
 
 1946        c_parent = constants % cnode(:, i)
 
 1947        c_diff = params % kappa*(c_child - c_parent)
 
 1949            & constants % si_rnode(:, j), constants % si_rnode(:, i), &
 
 1950            & params % pl, constants % vscales, one, &
 
 1951            & node_l(:, j), one, node_l(:, i), work, work_complex)
 
 1964    real(dp), 
intent(inout) :: node_l((params % pl+1)**2, constants % nclusters)
 
 1966    real(dp) :: work(6*params % pl**2 + 19*params % pl + 8)
 
 1980    real(dp), 
intent(inout) :: node_l((params % pl+1)**2, constants % nclusters)
 
 1982    real(dp), 
intent(out) :: work(6*params % pl**2 + 19*params % pl + 8)
 
 1985    real(dp) :: c1(3), c(3), r1, r
 
 1987    do i = constants % nclusters, 1, -1
 
 1989        if (constants % children(1, i) == 0) cycle
 
 1990        c = constants % cnode(:, i)
 
 1991        r = constants % rnode(i)
 
 1993        j = constants % children(1, i)
 
 1994        c1 = constants % cnode(:, j)
 
 1995        r1 = constants % rnode(j)
 
 1998            & constants % vscales, constants % vfact, one, &
 
 1999            & node_l(:, j), zero, node_l(:, i), work)
 
 2001        do j = constants % children(1, i)+1, constants % children(2, i)
 
 2002            c1 = constants % cnode(:, j)
 
 2003            r1 = constants % rnode(j)
 
 2006                & constants % vscales, constants % vfact, one, &
 
 2007                & node_l(:, j), one, node_l(:, i), work)
 
 2021    real(dp), 
intent(inout) :: node_l((params % pl+1)**2, constants % nclusters)
 
 2023    real(dp) :: work(6*params % pl**2 + 19*params % pl + 8)
 
 2024    complex(dp) :: work_complex(2*params % pl+1)
 
 2027    real(dp) :: c_parent(3), c_child(3), c_diff(3)
 
 2029    do i = constants % nclusters, 1, -1
 
 2030        c_child = constants % cnode(:, i)
 
 2031        j = constants % parent(i)
 
 2033        c_parent = constants % cnode(:, j)
 
 2034        c_diff = params % kappa*(c_parent - c_child)
 
 2036            & constants % si_rnode(:, i), constants % si_rnode(:, j), &
 
 2037            & params % pl, constants % vscales, one, &
 
 2038            & node_l(:, i), one, node_l(:, j), work, work_complex)
 
 2050    real(dp), 
intent(in) :: node_m((params % pm+1)**2, constants % nclusters)
 
 2052    real(dp), 
intent(out) :: node_l((params % pl+1)**2, constants % nclusters)
 
 2054    real(dp) :: work(6*max(params % pm, params % pl)**2 + &
 
 2055        & 19*max(params % pm, params % pl) + 8)
 
 2058    real(dp) :: c1(3), c(3), r1, r
 
 2062    do i = 1, constants % nclusters
 
 2064        if (constants % nfar(i) .eq. 0) 
then 
 2068        c = constants % cnode(:, i)
 
 2069        r = constants % rnode(i)
 
 2071        k = constants % far(constants % sfar(i))
 
 2072        c1 = constants % cnode(:, k)
 
 2073        r1 = constants % rnode(k)
 
 2076            & constants % vscales, constants % m2l_ztranslate_coef, one, &
 
 2077            & node_m(:, k), zero, node_l(:, i), work)
 
 2078        do j = constants % sfar(i)+1, constants % sfar(i+1)-1
 
 2079            k = constants % far(j)
 
 2080            c1 = constants % cnode(:, k)
 
 2081            r1 = constants % rnode(k)
 
 2084                & params % pl, constants % vscales, &
 
 2085                & constants % m2l_ztranslate_coef, one, node_m(:, k), one, &
 
 2086                & node_l(:, i), work)
 
 2100    real(dp), 
intent(in) :: node_m((params % pm+1)**2, constants % nclusters)
 
 2102    real(dp), 
intent(out) :: node_l((params % pl+1)**2, constants % nclusters)
 
 2104    real(dp) :: work(6*params % pm**2 + 19*params % pm + 8)
 
 2105    complex(dp) :: work_complex(2*params % pm+1)
 
 2108    real(dp) :: c1(3), c(3), r1, r
 
 2112    do i = 1, constants % nclusters
 
 2114        if (constants % nfar(i) .eq. 0) 
then 
 2118        c = constants % cnode(:, i)
 
 2119        r = constants % rnode(i)
 
 2121        k = constants % far(constants % sfar(i))
 
 2122        c1 = constants % cnode(:, k)
 
 2123        r1 = constants % rnode(k)
 
 2124        c1 = params % kappa*(c1 - c)
 
 2126            & constants % SK_rnode(:, k), constants % SI_rnode(:, i), &
 
 2128            & constants % vscales, one, &
 
 2129            & node_m(:, k), zero, node_l(:, i), work, work_complex)
 
 2130        do j = constants % sfar(i)+1, constants % sfar(i+1)-1
 
 2131            k = constants % far(j)
 
 2132            c1 = constants % cnode(:, k)
 
 2133            r1 = constants % rnode(k)
 
 2134            c1 = params % kappa*(c1 - c)
 
 2136                & constants % SI_rnode(:, i), params % pm, &
 
 2137                & constants % vscales, one, &
 
 2138                & node_m(:, k), one, node_l(:, i), work, work_complex)
 
 2150    real(dp), 
intent(in) :: node_l((params % pl+1)**2, constants % nclusters)
 
 2152    real(dp), 
intent(inout) :: node_m((params % pm+1)**2, constants % nclusters)
 
 2166    real(dp), 
intent(in) :: node_l((params % pl+1)**2, constants % nclusters)
 
 2168    real(dp), 
intent(out) :: node_m((params % pm+1)**2, constants % nclusters)
 
 2170    real(dp) :: work(6*params % pm**2 + 19*params % pm + 8)
 
 2171    complex(dp) :: work_complex(2*params % pm+1)
 
 2174    real(dp) :: c1(3), c(3), r
 
 2178    do i = 1, constants % nclusters
 
 2180        if (constants % nfar(i) .eq. 0) 
then 
 2183        c = constants % cnode(:, i)
 
 2184        r = constants % rnode(i)
 
 2186        k = constants % far(constants % sfar(i))
 
 2187        c1 = constants % cnode(:, k)
 
 2188        c1 = params % kappa*(c - c1)
 
 2190            & constants % SK_rnode(:, i), params % pm, constants % vscales, &
 
 2191            & one, node_l(:, k), one, node_m(:, i), work, work_complex)
 
 2192        do j = constants % sfar(i)+1, constants % sfar(i+1)-1
 
 2193            k = constants % far(j)
 
 2194            c1 = constants % cnode(:, k)
 
 2195            c1 = params % kappa*(c - c1)
 
 2197                & constants % SI_rnode(:, k), constants % SK_rnode(:, i), &
 
 2198                & params % pm, constants % vscales, one, node_l(:, k), &
 
 2199                & one, node_m(:, i), work, work_complex)
 
 2212    real(dp), 
intent(in) :: node_l((params % pl+1)**2, constants % nclusters)
 
 2214    real(dp), 
intent(out) :: node_m((params % pm+1)**2, constants % nclusters)
 
 2217    real(dp) :: c1(3), c(3), r1, r
 
 2221    do i = 1, constants % nclusters
 
 2223        if (constants % nfar(i) .eq. 0) 
then 
 2226        c = constants % cnode(:, i)
 
 2227        r = constants % rnode(i)
 
 2229        k = constants % far(constants % sfar(i))
 
 2230        c1 = constants % cnode(:, k)
 
 2231        r1 = constants % rnode(k)
 
 2234            & constants % vscales, constants % m2l_ztranslate_adj_coef, one, &
 
 2235            & node_l(:, k), one, node_m(:, i))
 
 2236        do j = constants % sfar(i)+1, constants % sfar(i+1)-1
 
 2237            k = constants % far(j)
 
 2238            c1 = constants % cnode(:, k)
 
 2239            r1 = constants % rnode(k)
 
 2242                & constants % vscales, constants % m2l_ztranslate_adj_coef, one, &
 
 2243                & node_l(:, k), one, node_m(:, i))
 
 2251subroutine tree_l2p(params, constants, alpha, node_l, beta, grid_v, sph_l)
 
 2256    real(dp), 
intent(in) :: node_l((params % pl+1)**2, constants % nclusters), &
 
 2259    real(dp), 
intent(inout) :: grid_v(params % ngrid, params % nsph)
 
 2261    real(dp), 
intent(out) :: sph_l((params % pl+1)**2, params % nsph)
 
 2268    if (beta .eq. zero) 
then 
 2271        grid_v = beta * grid_v
 
 2276    do isph = 1, params % nsph
 
 2277        sph_l(:, isph) = node_l(:, constants % snode(isph))
 
 2280    call dgemm(
'T', 
'N', params % ngrid, params % nsph, &
 
 2281        & (params % pl+1)**2, alpha, constants % vgrid2, &
 
 2282        & constants % vgrid_nbasis, sph_l, (params % pl+1)**2, beta, grid_v, &
 
 2295    real(dp), 
intent(in) :: node_l((params % pl+1)**2, constants % nclusters), &
 
 2298    real(dp), 
intent(inout) :: grid_v(params % ngrid, params % nsph)
 
 2300    real(dp) :: sph_l((params % pl+1)**2, params % nsph)
 
 2304    if (beta .eq. zero) 
then 
 2307        grid_v = beta * grid_v
 
 2312    do isph = 1, params % nsph
 
 2313        sph_l(:, isph) = node_l(:, constants % snode(isph))
 
 2316    call dgemm(
'T', 
'N', params % ngrid, params % nsph, &
 
 2317        & (params % pl+1)**2, alpha, constants % vgrid, &
 
 2318        & constants % vgrid_nbasis, sph_l, (params % pl+1)**2, beta, grid_v, &
 
 2325subroutine tree_l2p_adj(params, constants, alpha, grid_v, beta, node_l, sph_l)
 
 2330    real(dp), 
intent(in) :: grid_v(params % ngrid, params % nsph), alpha, &
 
 2333    real(dp), 
intent(inout) :: node_l((params % pl+1)**2, &
 
 2334        & constants % nclusters)
 
 2336    real(dp), 
intent(out) :: sph_l((params % pl+1)**2, params % nsph)
 
 2338    integer :: isph, inode
 
 2341    if (beta .eq. zero) 
then 
 2344        node_l = beta * node_l
 
 2347    call dgemm(
'N', 
'N', (params % pl+1)**2, params % nsph, &
 
 2348        & params % ngrid, one, constants % vgrid2, constants % vgrid_nbasis, &
 
 2349        & grid_v, params % ngrid, zero, sph_l, &
 
 2350        & (params % pl+1)**2)
 
 2354    do isph = 1, params % nsph
 
 2355        inode = constants % snode(isph)
 
 2356        node_l(:, inode) = node_l(:, inode) + alpha*sph_l(:, isph)
 
 2368    real(dp), 
intent(in) :: grid_v(params % ngrid, params % nsph), alpha, &
 
 2371    real(dp), 
intent(inout) :: node_l((params % pl+1)**2, &
 
 2372        & constants % nclusters)
 
 2374    real(dp) :: sph_l((params % pl+1)**2, params % nsph)
 
 2375    integer :: isph, inode
 
 2378    if (beta .eq. zero) 
then 
 2381        node_l = beta * node_l
 
 2384    call dgemm(
'N', 
'N', (params % pl+1)**2, params % nsph, &
 
 2385        & params % ngrid, one, constants % vgrid, constants % vgrid_nbasis, &
 
 2386        & grid_v, params % ngrid, zero, sph_l, &
 
 2387        & (params % pl+1)**2)
 
 2391    do isph = 1, params % nsph
 
 2392        inode = constants % snode(isph)
 
 2393        node_l(:, inode) = node_l(:, inode) + alpha*sph_l(:, isph)
 
 2400subroutine tree_m2p(params, constants, p, alpha, sph_m, beta, grid_v)
 
 2405    integer, 
intent(in) :: p
 
 2406    real(dp), 
intent(in) :: sph_m((p+1)**2, params % nsph), alpha, beta
 
 2408    real(dp), 
intent(inout) :: grid_v(params % ngrid, params % nsph)
 
 2410    integer :: isph, inode, jnear, jnode, jsph, igrid
 
 2413    real(dp) :: work(p+1)
 
 2415    if (beta .eq. zero) 
then 
 2418        grid_v = beta * grid_v
 
 2424    do isph = 1, params % nsph
 
 2426        inode = constants % snode(isph)
 
 2427        do jnear = constants % snear(inode), constants % snear(inode+1)-1
 
 2430            jnode = constants % near(jnear)
 
 2431            jsph = constants % order(constants % cluster(1, jnode))
 
 2433            if(isph .eq. jsph) cycle
 
 2435            do igrid = 1, params % ngrid
 
 2436                if(constants % ui(igrid, isph) .eq. zero) cycle
 
 2437                c = constants % cgrid(:, igrid)*params % rsph(isph) - &
 
 2438                    & params % csph(:, jsph) + params % csph(:, isph)
 
 2440                    & constants % vscales_rel, alpha, sph_m(:, jsph), one, &
 
 2441                    & grid_v(igrid, isph), work)
 
 2455    integer, 
intent(in) :: p, sph_p
 
 2456    real(dp), 
intent(in) :: sph_m((sph_p+1)**2, params % nsph), alpha, beta
 
 2458    real(dp), 
intent(inout) :: grid_v(params % ngrid, params % nsph)
 
 2460    integer :: isph, inode, jnear, jnode, jsph, igrid
 
 2463    real(dp) :: work(p+1)
 
 2464    complex(dp) :: work_complex(p+1)
 
 2466    if (beta .eq. zero) 
then 
 2469        grid_v = beta * grid_v
 
 2475    do isph = 1, params % nsph
 
 2477        inode = constants % snode(isph)
 
 2478        do jnear = constants % snear(inode), constants % snear(inode+1)-1
 
 2481            jnode = constants % near(jnear)
 
 2482            jsph = constants % order(constants % cluster(1, jnode))
 
 2486            do igrid = 1, params % ngrid
 
 2487                if(constants % ui(igrid, isph) .eq. zero) cycle
 
 2488                c = constants % cgrid(:, igrid)*params % rsph(isph) - &
 
 2489                    & params % csph(:, jsph) + params % csph(:, isph)
 
 2490                c = c * params % kappa
 
 2492                    & constants % SK_ri(:, jsph), alpha, sph_m(:, jsph), one, &
 
 2493                    & grid_v(igrid, isph), work_complex, work)
 
 2507    integer, 
intent(in) :: p
 
 2508    real(dp), 
intent(in) :: grid_v(params % ngrid, params % nsph), alpha, &
 
 2511    real(dp), 
intent(inout) :: sph_m((p+1)**2, params % nsph)
 
 2513    real(dp) :: work(p+1)
 
 2515    integer :: isph, inode, jnear, jnode, jsph, igrid
 
 2518    if (beta .eq. zero) 
then 
 2521        sph_m = beta * sph_m
 
 2527    do isph = 1, params % nsph
 
 2529        inode = constants % snode(isph)
 
 2530        do jnear = constants % snear(inode), constants % snear(inode+1)-1
 
 2533            jnode = constants % near(jnear)
 
 2534            jsph = constants % order(constants % cluster(1, jnode))
 
 2536            if(isph .eq. jsph) cycle
 
 2538            do igrid = 1, params % ngrid
 
 2539                if(constants % ui(igrid, jsph) .eq. zero) cycle
 
 2540                c = constants % cgrid(:, igrid)*params % rsph(jsph) - &
 
 2541                    & params % csph(:, isph) + params % csph(:, jsph)
 
 2543                    & params % rsph(isph), p, constants % vscales_rel, one, &
 
 2544                    & sph_m(:, isph), work)
 
 2559    integer, 
intent(in) :: p, sph_p
 
 2560    real(dp), 
intent(in) :: grid_v(params % ngrid, params % nsph), alpha, &
 
 2563    real(dp), 
intent(inout) :: sph_m((sph_p+1)**2, params % nsph)
 
 2566    integer :: isph, inode, jnear, jnode, jsph, igrid
 
 2569    if (beta .eq. zero) 
then 
 2572        sph_m = beta * sph_m
 
 2578    do isph = 1, params % nsph
 
 2580        inode = constants % snode(isph)
 
 2581        do jnear = constants % snear(inode), constants % snear(inode+1)-1
 
 2584            jnode = constants % near(jnear)
 
 2585            jsph = constants % order(constants % cluster(1, jnode))
 
 2587            do igrid = 1, params % ngrid
 
 2588                if(constants % ui(igrid, jsph) .eq. zero) cycle
 
 2589                c = constants % cgrid(:, igrid)*params % rsph(jsph) - &
 
 2590                    & params % csph(:, isph) + params % csph(:, jsph)
 
 2592                    & params % rsph(isph), params % kappa, p, &
 
 2593                    & constants % vscales, one, sph_m(:, isph))
 
 2608    integer, 
intent(in) :: p, sph_p
 
 2609    real(dp), 
intent(in) :: grid_v(params % ngrid, params % nsph), alpha, &
 
 2612    real(dp), 
intent(inout) :: sph_m((sph_p+1)**2, params % nsph)
 
 2614    integer :: isph, inode, jnear, jnode, jsph, igrid
 
 2617    if (beta .eq. zero) 
then 
 2620        sph_m = beta * sph_m
 
 2623    do isph = 1, params % nsph
 
 2625        inode = constants % snode(isph)
 
 2626        do jnear = constants % snear(inode), constants % snear(inode+1)-1
 
 2629            jnode = constants % near(jnear)
 
 2630            jsph = constants % order(constants % cluster(1, jnode))
 
 2632            if(isph .eq. jsph) cycle
 
 2634            do igrid = 1, params % ngrid
 
 2635                if(constants % ui(igrid, isph) .eq. zero) cycle
 
 2636                c = constants % cgrid(:, igrid)*params % rsph(isph) - &
 
 2637                    & params % csph(:, jsph) + params % csph(:, isph)
 
 2639                    & params % rsph(jsph), params % kappa, p, constants % vscales, one, &
 
 2654    real(dp), 
intent(in) :: sph_m(constants % nbasis, params % nsph)
 
 2656    real(dp), 
intent(inout) :: sph_m_grad((params % lmax+2)**2, 3, &
 
 2659    real(dp), 
intent(inout) :: work((params % lmax+2)**2, params % nsph)
 
 2661    integer :: isph, l, indi, indj, m
 
 2662    real(dp) :: tmp1, tmp2
 
 2663    real(dp), 
dimension(3, 3) :: zx_coord_transform, zy_coord_transform
 
 2665    zx_coord_transform = zero
 
 2666    zx_coord_transform(3, 2) = one
 
 2667    zx_coord_transform(2, 3) = one
 
 2668    zx_coord_transform(1, 1) = one
 
 2669    zy_coord_transform = zero
 
 2670    zy_coord_transform(1, 2) = one
 
 2671    zy_coord_transform(2, 1) = one
 
 2672    zy_coord_transform(3, 3) = one
 
 2674    sph_m_grad(1:constants % nbasis, 3, :) = sph_m
 
 2675    do isph = 1, params % nsph
 
 2677            & sph_m(:, isph), zero, sph_m_grad(1:constants % nbasis, 1, isph))
 
 2679            & sph_m(:, isph), zero, sph_m_grad(1:constants % nbasis, 2, isph))
 
 2685    do l = params % lmax+1, 1, -1
 
 2688        tmp1 = sqrt(dble(2*l+1)) / sqrt(dble(2*l-1))
 
 2690            tmp2 = sqrt(dble(l*l-m*m)) * tmp1
 
 2691            sph_m_grad(indi+m, :, :) = tmp2 * sph_m_grad(indj+m, :, :)
 
 2693        sph_m_grad(indi+l, :, :) = zero
 
 2694        sph_m_grad(indi-l, :, :) = zero
 
 2696    sph_m_grad(1, :, :) = zero
 
 2699    do isph = 1, params % nsph
 
 2700        sph_m_grad(:, 3, isph) = sph_m_grad(:, 3, isph) / params % rsph(isph)
 
 2701        work(:, isph) = sph_m_grad(:, 1, isph) / params % rsph(isph)
 
 2703            & work(:, isph), zero, sph_m_grad(:, 1, isph))
 
 2704        work(:, isph) = sph_m_grad(:, 2, isph) / params % rsph(isph)
 
 2706            & work(:, isph), zero, sph_m_grad(:, 2, isph))
 
 2718    real(dp), 
intent(in) :: node_l((params % pl+1)**2, constants % nclusters)
 
 2720    real(dp), 
intent(out) :: sph_l_grad((params % pl+1)**2, 3, params % nsph)
 
 2722    real(dp), 
intent(out) :: work((params % pl+1)**2, params % nsph)
 
 2724    integer :: isph, inode, l, indi, indj, m
 
 2725    real(dp) :: tmp1, tmp2
 
 2726    real(dp), 
dimension(3, 3) :: zx_coord_transform, zy_coord_transform
 
 2729    if (params % pl .le. 0) 
return 
 2731    zx_coord_transform = zero
 
 2732    zx_coord_transform(3, 2) = one
 
 2733    zx_coord_transform(2, 3) = one
 
 2734    zx_coord_transform(1, 1) = one
 
 2735    zy_coord_transform = zero
 
 2736    zy_coord_transform(1, 2) = one
 
 2737    zy_coord_transform(2, 1) = one
 
 2738    zy_coord_transform(3, 3) = one
 
 2740    do isph = 1, params % nsph
 
 2741        inode = constants % snode(isph)
 
 2742        sph_l_grad(:, 3, isph) = node_l(:, inode)
 
 2744            & node_l(:, inode), zero, sph_l_grad(:, 1, isph))
 
 2746            & node_l(:, inode), zero, sph_l_grad(:, 2, isph))
 
 2752    do l = 1, params % pl
 
 2755        tmp1 = -sqrt(dble(2*l-1)) / sqrt(dble(2*l+1))
 
 2757            tmp2 = sqrt(dble(l*l-m*m)) * tmp1
 
 2758            sph_l_grad(indj+m, :, :) = tmp2 * sph_l_grad(indi+m, :, :)
 
 2763    do isph = 1, params % nsph
 
 2764        sph_l_grad(1:params % pl**2, 3, isph) = &
 
 2765            & sph_l_grad(1:params % pl**2, 3, isph) / params % rsph(isph)
 
 2766        work(1:params % pl**2, isph) = &
 
 2767            & sph_l_grad(1:params % pl**2, 1, isph) / params % rsph(isph)
 
 2769            & work(1:params % pl**2, isph), zero, &
 
 2770            & sph_l_grad(1:params % pl**2, 1, isph))
 
 2771        work(1:params % pl**2, isph) = &
 
 2772            & sph_l_grad(1:params % pl**2, 2, isph) / params % rsph(isph)
 
 2774            & work(1:params % pl**2, isph), zero, &
 
 2775            & sph_l_grad(1:params % pl**2, 2, isph))
 
 2780    sph_l_grad(indi-l:indi+l, :, :) = zero
 
 2790    character (len=2047), 
intent(out) :: string
 
 2791    character (len=10) :: vstr
 
 2792    write(vstr, *) 
"0.6.8" 
 2794        & 
" +----------------------------------------------------------------+", &
 
 2798        & 
"  |                        888      888 Y8b    d8Y                 |", &
 
 2800        & 
"  |                        888      888  Y8b  d8Y                  |", &
 
 2802        & 
"  |                        888      888   Y8888Y                   |", &
 
 2804        & 
"  |                    .d88888  .d88888    Y88Y                    |", &
 
 2806        & 
"  |                   d88  888 d88  888    d88b                    |", &
 
 2808        & 
"  |                   888  888 888  888   d8888b                   |", &
 
 2810        & 
"  |                   Y88b 888 Y88b 888  d8Y  Y8b                  |", &
 
 2812        & 
"  |                     Y88888   Y88888 d8Y    Y8b                 |", &
 
 2816        & 
"  |                 https://ddsolvation.github.io/ddX/             |", &
 
 2818        & 
"  |                         Version:", vstr, 
"                     |", &
 
 2822        & 
"  +----------------------------------------------------------------+" 
 2842    real(dp), 
intent(in) :: property_cav(constants % ncav)
 
 2843    real(dp), 
intent(out) :: property_sph(constants % nbasis, params % nsph)
 
 2846    workspace % tmp_cav = property_cav * constants % ui_cav
 
 2850        & constants % icav_ia, constants % icav_ja, workspace % tmp_cav, &
 
 2851        & workspace % tmp_grid)
 
 2854    call ddintegrate(params % nsph, constants % nbasis, &
 
 2855        & params % ngrid, constants % vwgrid, constants % vgrid_nbasis, &
 
 2856        & workspace % tmp_grid, property_sph)
 
subroutine allocate_electrostatics(params, constants, electrostatics, ddx_error)
Given the chosen model, find the required electrostatic properties, and allocate the arrays for them ...
 
subroutine deallocate_electrostatics(electrostatics, ddx_error)
Deallocate the electrostatic properties.
 
subroutine allocate_state(params, constants, state, ddx_error)
Initialize the ddx_state object.
 
subroutine deallocate_state(state, ddx_error)
Deallocate the ddx_state object.
 
subroutine get_banner(string)
Print the ddX logo.
 
subroutine constants_init(params, constants, ddx_error)
Compute all necessary constants.
 
subroutine constants_free(constants, ddx_error)
Deallocate the constants.
 
real(dp) function fsw(t, se, eta)
Switching function.
 
Core routines and parameters of the ddX software.
 
subroutine tree_l2l_rotation_adj_work(params, constants, node_l, work)
Adjoint transfer local coefficients over a tree.
 
subroutine deallocate_model(ddx_data, ddx_error)
Deallocate object with corresponding data.
 
subroutine tree_grad_l2l(params, constants, node_l, sph_l_grad, work)
TODO.
 
subroutine tree_l2p_bessel(params, constants, alpha, node_l, beta, grid_v)
TODO.
 
subroutine tree_l2p_bessel_adj(params, constants, alpha, grid_v, beta, node_l)
TODO.
 
subroutine tree_l2l_rotation(params, constants, node_l)
Transfer local coefficients over a tree.
 
subroutine tree_m2m_rotation(params, constants, node_m)
Transfer multipole coefficients over a tree.
 
subroutine tree_l2p(params, constants, alpha, node_l, beta, grid_v, sph_l)
TODO.
 
subroutine wghpot(ncav, phi_cav, nsph, ngrid, ui, phi_grid, g)
Weigh potential at cavity points by characteristic function TODO use cavity points in CSR format.
 
real(dp) function hnorm(lmax, nbasis, nsph, x)
Compute the global Sobolev H^(-1/2)-norm of x.
 
subroutine tree_l2p_adj(params, constants, alpha, grid_v, beta, node_l, sph_l)
TODO.
 
subroutine cav_to_spherical(params, constants, workspace, property_cav, property_sph)
Transform a function defined at the exposed cavity points (cav) to a spherical harmonics expansion....
 
subroutine tree_l2l_rotation_work(params, constants, node_l, work)
Transfer local coefficients over a tree.
 
subroutine tree_m2l_bessel_rotation(params, constants, node_m, node_l)
Transfer multipole local coefficients into local over a tree.
 
subroutine tree_m2m_bessel_rotation_adj(params, constants, node_m)
Adjoint transfer multipole coefficients over a tree.
 
subroutine rmsvec(n, v, vrms, vmax)
compute root-mean-square and max norm
 
subroutine print_nodes(iunit, label, ngrid, ncol, icol, x)
Print array of quadrature points.
 
subroutine tree_m2m_bessel_rotation_work(params, constants, node_m)
Transfer multipole coefficients over a tree.
 
subroutine ddeval_grid_work(nbasis, ngrid, nsph, vgrid, ldvgrid, alpha, x_sph, beta, x_grid)
Evaluate values of spherical harmonics at Lebedev grid points.
 
subroutine tree_m2l_rotation(params, constants, node_m, node_l)
Transfer multipole local coefficients into local over a tree.
 
subroutine ddintegrate_sph(params, constants, alpha, x_grid, beta, x_sph)
Integrate values at grid points into spherical harmonics.
 
subroutine tree_m2p(params, constants, p, alpha, sph_m, beta, grid_v)
TODO.
 
subroutine ddintegrate_sph_work(nbasis, ngrid, nsph, vwgrid, ldvwgrid, alpha, x_grid, beta, x_sph)
Integrate values at grid points into spherical harmonics.
 
subroutine tree_m2p_bessel(params, constants, p, alpha, sph_p, sph_m, beta, grid_v)
TODO.
 
subroutine tree_l2l_bessel_rotation_adj(params, constants, node_l)
Adjoint transfer local coefficients over a tree.
 
subroutine ddintegrate(nsph, nbasis, ngrid, vwgrid, ldvwgrid, x_grid, x_lm)
Integrate against spherical harmonics.
 
subroutine tree_l2l_bessel_rotation(params, constants, node_l)
Transfer local coefficients over a tree.
 
subroutine print_ddvector(ddx_data, label, vector)
Print dd Solution vector.
 
subroutine tree_l2l_bessel_rotation_work(params, constants, node_l)
Transfer local coefficients over a tree.
 
subroutine tree_m2p_bessel_nodiag_adj(params, constants, p, alpha, grid_v, beta, sph_p, sph_m)
TODO.
 
subroutine tree_m2l_bessel_rotation_adj(params, constants, node_l, node_m)
Adjoint transfer multipole local coefficients into local over a tree.
 
subroutine tree_m2m_rotation_work(params, constants, node_m, work)
Transfer multipole coefficients over a tree.
 
subroutine tree_grad_m2m(params, constants, sph_m, sph_m_grad, work)
TODO.
 
subroutine tree_m2p_adj(params, constants, p, alpha, grid_v, beta, sph_m)
TODO.
 
subroutine tree_m2p_bessel_adj(params, constants, p, alpha, grid_v, beta, sph_p, sph_m)
TODO.
 
subroutine hsnorm(lmax, nbasis, u, unorm)
Compute the local Sobolev H^(-1/2)-norm on one sphere of u.
 
subroutine tree_m2l_bessel_rotation_adj_work(params, constants, node_l, node_m)
Adjoint transfer multipole local coefficients into local over a tree.
 
subroutine tree_m2l_rotation_adj(params, constants, node_l, node_m)
Adjoint transfer multipole local coefficients into local over a tree.
 
subroutine tree_l2l_rotation_adj(params, constants, node_l)
Adjoint transfer local coefficients over a tree.
 
subroutine tree_m2m_rotation_adj(params, constants, node_m)
Adjoint transfer multipole coefficients over a tree.
 
subroutine ddproject_cav(params, constants, s, xi)
Integrate by a characteristic function at Lebedev grid points \xi(n,i) = sum w_n U_n^i Y_l^m(s_n) [S_...
 
subroutine ddeval_grid(params, constants, alpha, x_sph, beta, x_grid)
Evaluate values of spherical harmonics at Lebedev grid points.
 
subroutine ddcav_to_grid_work(ngrid, nsph, ncav, icav_ia, icav_ja, x_cav, x_grid)
Unwrap values at cavity points into values at all grid points.
 
subroutine tree_m2m_bessel_rotation(params, constants, node_m)
Transfer multipole coefficients over a tree.
 
subroutine tree_m2m_bessel_rotation_adj_work(params, constants, node_m)
Adjoint transfer multipole coefficients over a tree.
 
subroutine ddcav_to_grid(params, constants, x_cav, x_grid)
Unwrap values at cavity points into values at all grid points.
 
subroutine allocate_model(nsph, x, y, z, rvdw, model, lmax, ngrid, force, fmm, pm, pl, se, eta, eps, kappa, matvecmem, maxiter, jacobi_ndiis, nproc, output_filename, ddx_data, ddx_error)
Initialize ddX input with a full set of parameters.
 
subroutine tree_m2m_rotation_adj_work(params, constants, node_m, work)
Adjoint transfer multipole coefficients over a tree.
 
subroutine dbasis(params, constants, x, basloc, dbsloc, vplm, vcos, vsin)
Compute first derivatives of spherical harmonics.
 
subroutine print_spherical(iunit, label, nbasis, lmax, ncol, icol, x)
Print array of spherical harmonics.
 
real(dp) function intmlp(params, constants, t, sigma, basloc)
TODO.
 
Harmonics-related core routines.
 
subroutine fmm_l2p_adj_work(c, src_q, dst_r, p, vscales_rel, beta, dst_l, work)
Adjoint L2P.
 
subroutine fmm_m2m_bessel_rotation_adj_work(c, src_sk, dst_sk, p, vscales, alpha, src_m, beta, dst_m, work, work_complex)
Direct M2M translation by 4 rotations and 1 translation.
 
subroutine fmm_m2p_bessel_adj(c, src_q, dst_r, kappa, p, vscales, beta, dst_m)
Adjoint M2P operation.
 
subroutine polleg_work(ctheta, stheta, p, vplm, work)
Compute associated Legendre polynomials.
 
subroutine trgev(cphi, sphi, p, vcos, vsin)
Compute arrays of  and .
 
subroutine fmm_m2p_adj_work(c, src_q, dst_r, p, vscales_rel, beta, dst_m, work)
Adjoint M2P operation.
 
subroutine fmm_l2l_bessel_rotation_adj_work(c, src_si, dst_si, p, vscales, alpha, src_l, beta, dst_l, work, work_complex)
Direct L2L translation by 4 rotations and 1 translation.
 
subroutine fmm_m2m_bessel_rotation_work(c, src_sk, dst_sk, p, vscales, alpha, src_m, beta, dst_m, work, work_complex)
Direct M2M translation by 4 rotations and 1 translation.
 
subroutine fmm_l2l_rotation_work(c, src_r, dst_r, p, vscales, vfact, alpha, src_l, beta, dst_l, work)
Direct L2L translation by 4 rotations and 1 translation.
 
subroutine fmm_m2p_work(c, src_r, p, vscales_rel, alpha, src_m, beta, dst_v, work)
Accumulate potential, induced by multipole spherical harmonics.
 
subroutine fmm_m2l_rotation_adj(c, src_r, dst_r, pl, pm, vscales, m2l_ztranslate_adj_coef, alpha, src_l, beta, dst_m)
Adjoint M2L translation by 4 rotations and 1 translation.
 
subroutine fmm_m2m_rotation_work(c, src_r, dst_r, p, vscales, vcnk, alpha, src_m, beta, dst_m, work)
Direct M2M translation by 4 rotations and 1 translation.
 
subroutine fmm_sph_transform(p, r1, alpha, src, beta, dst)
Transform coefficients of spherical harmonics to a new cartesion system.
 
subroutine fmm_m2l_rotation_work(c, src_r, dst_r, pm, pl, vscales, m2l_ztranslate_coef, alpha, src_m, beta, dst_l, work)
Direct M2L translation by 4 rotations and 1 translation.
 
subroutine fmm_l2l_rotation_adj_work(c, src_r, dst_r, p, vscales, vfact, alpha, src_l, beta, dst_l, work)
Adjoint L2L translation by 4 rotations and 1 translation.
 
subroutine fmm_m2l_bessel_rotation_work(c, src_sk, dst_si, p, vscales, alpha, src_m, beta, dst_l, work, work_complex)
Direct M2M translation by 4 rotations and 1 translation.
 
subroutine fmm_l2l_bessel_rotation_work(c, src_si, dst_si, p, vscales, alpha, src_l, beta, dst_l, work, work_complex)
Direct L2L translation by 4 rotations and 1 translation.
 
subroutine fmm_m2l_bessel_rotation_adj_work(c, src_sk, dst_si, p, vscales, alpha, src_m, beta, dst_l, work, work_complex)
Direct M2M translation by 4 rotations and 1 translation.
 
subroutine fmm_m2m_rotation_adj_work(c, src_r, dst_r, p, vscales, vcnk, alpha, src_m, beta, dst_m, work)
Adjoint M2M translation by 4 rotations and 1 translation.
 
subroutine fmm_m2p_bessel_work(c, p, vscales, SK_ri, alpha, src_m, beta, dst_v, work_complex, work)
Accumulate Bessel potential, induced by multipole spherical harmonics.
 
subroutine fmm_l2p_work(c, src_r, p, vscales_rel, alpha, src_l, beta, dst_v, work)
Accumulate potential, induced by local spherical harmonics.
 
Module to treat properly user input parameters.
 
subroutine params_free(params, ddx_error)
Deallocate the parameter object.
 
subroutine params_init(model, force, eps, kappa, eta, se, lmax, ngrid, matvecmem, maxiter, jacobi_ndiis, fmm, pm, pl, nproc, nsph, csph, rsph, output_filename, params, ddx_error)
Initialize and check input parameters.
 
Workspace for temporary buffers.
 
subroutine workspace_init(params, constants, workspace, ddx_error)
Initialize and allocate the temporary workspaces.
 
subroutine workspace_free(workspace, ddx_error)
Deallocate the temporary workspaces.
 
Container for precomputed constants.
 
Container for the electrostatic properties. Since different methods require different electrostatic p...
 
This defined type contains the primal and adjoint RHSs, the solution of the primal and adjoint linear...
 
Main ddX type that stores all the required information. Container for the params, contants and worksp...
 
Type to check and store user input parameters.
 
Container for temporary arrays.