! calculate L_i vectors needed in calculate_rhoq from information of impurity cluster etc.
! L_i = R_mu - R_cls - r^cls_i, here R_mu and R_cls are the positions in the host systems basis and r^cls_i is the position inside the impurity cluster
implicitnone
type(type_rhoq),intent(inout)::t_rhoq
! local
integer::mu_0,mu_cls,mu_orig! layer indices for probe position, cluster center and origin position, respectively
double precision::R_mu(3),R_cls(3)! position in host system according to mu_orig and mu_cls
double precision,allocatable::rcls_i(:,:)! size=(3,Nscoef), positions inside the impurity cluster
double precision,allocatable::rbasis(:,:)! size=(3,natyp), positions in host system
double precision,intent(in)::thetasnew(nrmaxd,nfund,ncelld)! shape functions in Chebychev mesh (new mesh)
double precision,parameter::c0ll=1.0d0/sqrt(16.0d0*datan(1.0d0))! Y_00 = 1/sqrt(4*pi) needed for theta_00 * Y_00 = 1, other spherical harmonics are in Gaunt coefficients cleb(:,:)
! local
integer::irmdnew,imt1,l1,m1,lm1,lm2,lm3,ir,ifun,j
! get indices of imt and irmd in new mesh -> boundaries for ir loops
irmdnew=npan_tot*(ncheb+1)
imt1=ipan_intervall(npan_log+npan_eq)+1
! first treat spherical block (diagonal in lm, lm' -> only lm'==lm)
dolm01=1,lmmaxso
! fill diagonal
doir=1,irmdnew
q_of_r(ir,lm01,lm01)=q_of_r(ir)+rll(ir,lm01,lm01)*rllleft(ir,lm01,lm01)! note: diagonal in lm01!!!
enddo! ir
! add shapefunction to points with r> R_MT
doir=imt1+1,irmdnew
q_of_r(ir)=q_of_r(ir)*thetasnew(ir,1)*c0ll! add shapefunction on diagonal for last points outside of MT radius