00001 subroutine poisson_solver_At_homosol_lesq(pot_bc,pot_nb,pot_surf,char_sym)
00002 use phys_constant, only : long
00003 use grid_parameter, only : nrg, ntg, npg, nlg
00004 use coordinate_grav_r, only : rg, hrg
00005 use coordinate_grav_theta, only : thg, hthg
00006 use coordinate_grav_phi, only : phig, hphig
00007 use trigonometry_grav_theta, only : hcosecthg
00008 use trigonometry_grav_phi, only : cosmpg, sinmpg, hsinmpg, hcosmpg
00009 use legendre_fn_grav, only : yplmg, hyplmg, hdtyplmg
00010 use def_matter, only : rs
00011 use make_array_1d
00012 use make_array_2d
00013 use interface_interpo_lag4th_2Dsurf
00014 use interface_minv
00015 implicit none
00016 real(long), pointer :: pot_bc(:,:), pot_nb(:,:), pot_surf(:,:,:)
00017 real(long), pointer :: alm(:,:), blm(:,:), pot_bcmnb(:,:)
00018 real(long), pointer :: fnc(:,:), hrs(:,:)
00019 real(long), pointer :: sgg(:), gg(:,:)
00020 real(long) :: hrsc, flm, fllmm, surf, val, tv, pv
00021 integer :: ir, it, ip, nbou, imm, ivec, im, ill, il, ieqs
00022 integer :: m_max, mm_max
00023 integer :: ii, jj
00024 character(len=6) :: char_sym
00025
00026
00027
00028
00029
00030
00031 call alloc_array2d(alm,0,nlg,0,nlg)
00032 call alloc_array2d(blm,0,nlg,0,nlg)
00033 call alloc_array2d(pot_bcmnb,1,ntg,1,npg)
00034 call alloc_array2d(fnc,0,ntg,0,npg)
00035 call alloc_array2d(hrs,0,ntg,0,npg)
00036 nbou = (nlg+1)*(nlg+1)
00037 if (char_sym.eq.'axisym') nbou = 5*nlg-1
00038 call alloc_array1d(sgg,1,nbou+1)
00039 call alloc_array2d(gg,1,nbou+1,1,nbou+1)
00040
00041 sgg(1:nbou+1) = 0.0d0
00042 gg(1:nbou+1,1:nbou+1) = 0.0d0
00043 alm(0:nlg,0:nlg) = 0.0d0
00044 blm(0:nlg,0:nlg) = 0.0d0
00045
00046 fnc(0:ntg,0:npg) = pot_bc(0:ntg,0:npg) - pot_nb(0:ntg,0:npg)
00047 do ip = 1, npg
00048 do it = 1, ntg
00049 tv = hthg(it)
00050 pv = hphig(ip)
00051 call interpo_lag4th_2Dsurf(val,fnc,tv,pv)
00052 pot_bcmnb(it,ip) = val
00053 call interpo_lag4th_2Dsurf(val,rs,tv,pv)
00054 hrs(it,ip) = val
00055 end do
00056 end do
00057
00058
00059
00060 ieqs = 0
00061 do il = 0, nlg
00062 m_max = il
00063 if (char_sym.eq.'axisym') m_max = min0(2,il)
00064 do im = 0, m_max
00065 ieqs = ieqs + 1
00066
00067 do ip = 1, npg
00068 do it = 1, ntg
00069
00070 hrsc = hrs(it,ip)
00071 flm = hrsc**(-il-1)*hyplmg(il,im,it)*hcosmpg(im,ip)
00072 sgg(ieqs) = sgg(ieqs) + pot_bcmnb(it,ip)*flm
00073
00074 ivec = 0
00075 do ill = 0, nlg
00076 mm_max = ill
00077 if (char_sym.eq.'axisym') mm_max = min0(2,ill)
00078 do imm = 0, mm_max
00079 ivec = ivec + 1
00080 fllmm = hrsc**(-ill-1)*hyplmg(ill,imm,it)*hcosmpg(imm,ip)
00081 gg(ieqs,ivec) = gg(ieqs,ivec) + fllmm*flm
00082 end do
00083 end do
00084 do ill = 1, nlg
00085 mm_max = ill
00086 if (char_sym.eq.'axisym') mm_max = min0(2,ill)
00087 do imm = 1, mm_max
00088 ivec = ivec + 1
00089 fllmm = hrsc**(-ill-1)*hyplmg(ill,imm,it)*hsinmpg(imm,ip)
00090 gg(ieqs,ivec) = gg(ieqs,ivec) + fllmm*flm
00091 end do
00092 end do
00093
00094 end do
00095 end do
00096
00097 end do
00098 end do
00099
00100 do il = 1, nlg
00101 m_max = il
00102 if (char_sym.eq.'axisym') m_max = min0(2,il)
00103 do im = 1, m_max
00104 ieqs = ieqs + 1
00105
00106 do ip = 1, npg
00107 do it = 1, ntg
00108
00109 hrsc = hrs(it,ip)
00110 flm = hrsc**(-il-1)*hyplmg(il,im,it)*hsinmpg(im,ip)
00111 sgg(ieqs) = sgg(ieqs) + pot_bcmnb(it,ip)*flm
00112
00113 ivec = 0
00114 do ill = 0, nlg
00115 mm_max = ill
00116 if (char_sym.eq.'axisym') mm_max = min0(2,ill)
00117 do imm = 0, mm_max
00118 ivec = ivec + 1
00119 fllmm = hrsc**(-ill-1)*hyplmg(ill,imm,it)*hcosmpg(imm,ip)
00120 gg(ieqs,ivec) = gg(ieqs,ivec) + fllmm*flm
00121 end do
00122 end do
00123 do ill = 1, nlg
00124 mm_max = ill
00125 if (char_sym.eq.'axisym') mm_max = min0(2,ill)
00126 do imm = 1, mm_max
00127 ivec = ivec + 1
00128 fllmm = hrsc**(-ill-1)*hyplmg(ill,imm,it)*hsinmpg(imm,ip)
00129 gg(ieqs,ivec) = gg(ieqs,ivec) + fllmm*flm
00130 end do
00131 end do
00132
00133 end do
00134 end do
00135
00136 end do
00137 end do
00138
00139 if(ivec.ne.nbou) write(6,*) ' harmonic ivec wrong ', ivec, nbou
00140 if(ieqs.ne.nbou) write(6,*) ' harmonic ieqs wrong ', ieqs, nbou
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 call minv(gg,sgg,nbou,nbou+1)
00154
00155
00156
00157
00158
00159 ieqs = 0
00160 do il = 0, nlg
00161 m_max = il
00162 if (char_sym.eq.'axisym') m_max = min0(2,il)
00163 do im = 0, m_max
00164 ieqs = ieqs + 1
00165 alm(il,im) = sgg(ieqs)
00166 end do
00167 end do
00168 do il = 1, nlg
00169 m_max = il
00170 if (char_sym.eq.'axisym') m_max = min0(2,il)
00171 do im = 1, m_max
00172 ieqs = ieqs + 1
00173 blm(il,im) = sgg(ieqs)
00174 end do
00175 end do
00176 if(ieqs.ne.nbou) write(6,*) ' harmonic alm blm wrong ', ieqs, nbou
00177
00178
00179
00180
00181 pot_surf(0:nrg,0:ntg,0:npg) = 0.0d0
00182 blm(0:nlg,0) = 0.0d0
00183 do ip = 0, npg
00184 do it = 0, ntg
00185 do ir = 1, nrg
00186
00187 surf = 0.0d0
00188 do il = 0, nlg
00189 m_max = il
00190 if (char_sym.eq.'axisym') m_max = min0(2,il)
00191 do im = 0, m_max
00192 surf = surf + alm(il,im)*rg(ir)**(-il-1)* &
00193 & yplmg(il,im,it)*cosmpg(im,ip) &
00194 & + blm(il,im)*rg(ir)**(-il-1)* &
00195 & yplmg(il,im,it)*sinmpg(im,ip)
00196 end do
00197 end do
00198
00199 pot_surf(ir,it,ip) = surf
00200 if (rg(ir).lt.rs(it,ip)) pot_surf(ir,it,ip) = 0.0d0
00201
00202 end do
00203 end do
00204 end do
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 deallocate(alm)
00215 deallocate(blm)
00216 deallocate(pot_bcmnb)
00217 deallocate(fnc)
00218 deallocate(hrs)
00219 deallocate(sgg)
00220 deallocate(gg)
00221
00222 end subroutine poisson_solver_At_homosol_lesq