Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Helmholtz/hfmm3d.f
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ subroutine hfmm3d(nd,eps,zk,nsource,source,ifcharge,
c
c Set rescaling parameters
c
b0 = boxsize(0)
c round b0 up to a power of 2 so that rescaling is exact
b0 = scale(1.0d0, exponent(boxsize(0)))
b0inv = 1.0d0/b0
b0inv2 = b0inv**2

Expand Down
3 changes: 2 additions & 1 deletion src/Helmholtz/hfmm3d_memest.f
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ subroutine hfmm3d_memest(nd,eps,zk,nsource,source,ifcharge,
c
c Set rescaling parameters
c
b0 = boxsize(0)
c round b0 up to a power of 2 so that rescaling is exact
b0 = scale(1.0d0, exponent(boxsize(0)))
b0inv = 1.0d0/b0
b0inv2 = b0inv**2

Expand Down
3 changes: 2 additions & 1 deletion src/Helmholtz/hfmm3d_ndiv.f
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ subroutine hfmm3d_ndiv(nd,eps,zk,nsource,source,ifcharge,
c
c Set rescaling parameters
c
b0 = boxsize(0)
c round b0 up to a power of 2 so that rescaling is exact
b0 = scale(1.0d0, exponent(boxsize(0)))
b0inv = 1.0d0/b0
b0inv2 = b0inv**2

Expand Down
3 changes: 2 additions & 1 deletion src/Laplace/lfmm3d.f
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ subroutine lfmm3d(nd,eps,nsource,source,ifcharge,
c
c Set rescaling parameters
c
b0 = boxsize(0)
c round b0 up to a power of 2 so that rescaling is exact
b0 = scale(1.0d0, exponent(boxsize(0)))
b0inv = 1.0d0/b0
b0inv2 = b0inv**2
b0inv3 = b0inv2*b0inv
Expand Down
3 changes: 2 additions & 1 deletion src/Laplace/lfmm3d_ndiv.f
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,8 @@ subroutine lfmm3d_ndiv(nd,eps,nsource,source,ifcharge,
c
c Set rescaling parameters
c
b0 = boxsize(0)
c round b0 up to a power of 2 so that rescaling is exact
b0 = scale(1.0d0, exponent(boxsize(0)))
b0inv = 1.0d0/b0
b0inv2 = b0inv**2
b0inv3 = b0inv2*b0inv
Expand Down
84 changes: 81 additions & 3 deletions test/Helmholtz/test_hfmm3d_scale.f
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
implicit real *8 (a-h,o-z)
complex *16 z1,z2,zk,ima
integer *8 i1,i2,i3,i4,i5,i6
integer *8 i1,i2,i3,i4,i5,i6,i7
data ima/(0.0d0,1.0d0)/

done = 1
pi = atan(done)*4

ntest = 6
ntest = 7

z1 = 8 + ima*0.2d0

Expand Down Expand Up @@ -35,8 +35,11 @@
rsc = 1.0d-9
zk = z1*2*pi/rsc
call test_hfmm3d_scale(rsc,zk,i6)

zk = 1.1d0
call test_hfmm3d_near(zk,i7)

nsuccess = i1+i2+i3+i4+i5+i6
nsuccess = i1+i2+i3+i4+i5+i6+i7
open(unit=33,file='print_testres.txt',access='append')
write(*,'(a,i2,a,i2,a)') 'Successfully completed ', nsuccess,
1 ' out of ', ntest, ' in hfmm3d scale testing suite'
Expand Down Expand Up @@ -171,3 +174,78 @@ subroutine test_hfmm3d_scale(rsc,zk,isuccess)
end
c----------------------------------------------------------
c


subroutine test_hfmm3d_near(zk,isuccess)
c
c Targets at distance 1e-10 from sources, in a root box whose
c size is not a power of 2. Checks that rescaling the points to
c the unit box does not perturb near interactions.
c
implicit none
integer *8 ns,i,j,ier,isuccess,ione
double precision, allocatable :: source(:,:),targ(:,:)
double precision, allocatable :: dnorm(:,:)
complex *16, allocatable :: charge(:),dipvec(:,:)
complex *16, allocatable :: pot(:),potex(:)
complex *16, allocatable :: grad(:,:),gradex(:,:)
complex *16 zk
double precision eps,d,r,thresh,erra,ra,hkrand

ns = 2000
ione = 1
allocate(source(3,ns),targ(3,ns),dnorm(3,ns))
allocate(charge(ns),dipvec(3,ns))
allocate(pot(ns),grad(3,ns),potex(ns),gradex(3,ns))

eps = 0.51d-9
d = 1.0d-10

do i=1,ns
do j=1,3
dnorm(j,i) = 2*hkrand(0)-1
enddo
r = sqrt(dnorm(1,i)**2+dnorm(2,i)**2+dnorm(3,i)**2)
do j=1,3
dnorm(j,i) = dnorm(j,i)/r
dipvec(j,i) = dnorm(j,i)
enddo
source(1,i) = 0.37d0 + 1.3d0*dnorm(1,i)
source(2,i) = 0.21d0 + 1.3d0*dnorm(2,i)
source(3,i) = -0.11d0 + 1.3d0*dnorm(3,i)
do j=1,3
targ(j,i) = source(j,i) + d*dnorm(j,i)
enddo
charge(i) = hkrand(0)-0.5d0
potex(i) = 0
do j=1,3
gradex(j,i) = 0
enddo
enddo

call hfmm3d_t_cd_g(eps,zk,ns,source,charge,dipvec,ns,targ,
1 pot,grad,ier)

thresh = 1.0d-300
call h3ddirectcdg(ione,zk,source,charge,dipvec,ns,targ,ns,
1 potex,gradex,thresh)

erra = 0
ra = 0
do i=1,ns
erra = erra + abs(potex(i)-pot(i))**2
ra = ra + abs(potex(i))**2
do j=1,3
erra = erra + abs(gradex(j,i)-grad(j,i))**2
ra = ra + abs(gradex(j,i))**2
enddo
enddo
erra = sqrt(erra/ra)

call prin2('near-field l2 rel err=*',erra,1)

isuccess = 0
if(erra.lt.5*eps) isuccess = 1

return
end
79 changes: 76 additions & 3 deletions test/Laplace/test_lfmm3d_scale.f
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
implicit real *8 (a-h,o-z)
integer *8 i1,i2
integer *8 i1,i2,i3

done = 1
pi = atan(done)*4

ntest = 2
ntest = 3


rsc = 1.0d10
Expand All @@ -13,7 +13,9 @@
rsc = 1.0d-9
call test_lfmm3d_scale(rsc,i2)

nsuccess = i1+i2
call test_lfmm3d_near(i3)

nsuccess = i1+i2+i3
open(unit=33,file='print_testres.txt',access='append')
write(33,'(a,i1,a,i1,a)') 'Successfully completed ', nsuccess,
1 ' out of ', ntest, ' in lfmm3d scale testing suite'
Expand Down Expand Up @@ -141,3 +143,74 @@ subroutine test_lfmm3d_scale(rsc,isuccess)
end
c----------------------------------------------------------
c


subroutine test_lfmm3d_near(isuccess)
c
c Targets at distance 1e-10 from sources, in a root box whose
c size is not a power of 2. Checks that rescaling the points to
c the unit box does not perturb near interactions.
c
implicit none
integer *8 ns,i,j,ier,isuccess,ione
double precision, allocatable :: source(:,:),targ(:,:)
double precision, allocatable :: charge(:),dipvec(:,:)
double precision, allocatable :: pot(:),potex(:)
double precision, allocatable :: grad(:,:),gradex(:,:)
double precision eps,d,r,thresh,erra,ra,hkrand

ns = 2000
ione = 1
allocate(source(3,ns),targ(3,ns),charge(ns),dipvec(3,ns))
allocate(pot(ns),grad(3,ns),potex(ns),gradex(3,ns))

eps = 0.51d-9
d = 1.0d-10

do i=1,ns
do j=1,3
dipvec(j,i) = 2*hkrand(0)-1
enddo
r = sqrt(dipvec(1,i)**2+dipvec(2,i)**2+dipvec(3,i)**2)
do j=1,3
dipvec(j,i) = dipvec(j,i)/r
enddo
source(1,i) = 0.37d0 + 1.3d0*dipvec(1,i)
source(2,i) = 0.21d0 + 1.3d0*dipvec(2,i)
source(3,i) = -0.11d0 + 1.3d0*dipvec(3,i)
do j=1,3
targ(j,i) = source(j,i) + d*dipvec(j,i)
enddo
charge(i) = hkrand(0)-0.5d0
potex(i) = 0
do j=1,3
gradex(j,i) = 0
enddo
enddo

call lfmm3d_t_cd_g(eps,ns,source,charge,dipvec,ns,targ,
1 pot,grad,ier)

thresh = 1.0d-300
call l3ddirectcdg(ione,source,charge,dipvec,ns,targ,ns,
1 potex,gradex,thresh)

erra = 0
ra = 0
do i=1,ns
erra = erra + abs(potex(i)-pot(i))**2
ra = ra + abs(potex(i))**2
do j=1,3
erra = erra + abs(gradex(j,i)-grad(j,i))**2
ra = ra + abs(gradex(j,i))**2
enddo
enddo
erra = sqrt(erra/ra)

call prin2('near-field l2 rel err=*',erra,1)

isuccess = 0
if(erra.lt.5*eps) isuccess = 1

return
end
Loading