Skip to content

Commit 6eb36dd

Browse files
committed
fix precision loss in complex number comversion in turbulence module
1 parent 2c258bb commit 6eb36dd

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

tests/turb/driving/driving-ref.dat

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
boxlen : 4.0000000000000000e+00
2-
density : -1.5970192481745945e+05
2+
density : -1.5970192503110823e+05
33
dx : 1.6384000000000000e+04
44
level : 1.5728640000000000e+06
55
ncells : 2.6214400000000000e+05
6-
pressure : -5.3599210383977520e+05
6+
pressure : -5.3599210405342397e+05
77
time : 2.5147260806143501e-01
88
unit_d : 1.5049295743500001e-20
99
unit_l : 3.0857000000000000e+18
1010
unit_t : 3.1556926000000000e+13
11-
velocity_x : 2.2878501962849146e+05
12-
velocity_y : 2.2205591221498317e+05
13-
velocity_z : 2.1700854779837615e+05
11+
velocity_x : 2.2878502213449072e+05
12+
velocity_y : 2.2205591253462457e+05
13+
velocity_z : 2.1700854906616427e+05
1414
x : 5.2428800000000000e+05
1515
y : 5.2428800000000000e+05
1616
z : 5.2428800000000000e+05

turb/init_turb.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ subroutine init_turb
144144
afield_next = afield_next * turb_norm * turb_rms
145145
else
146146
! Not a restart - set up initial field and perform FFT
147-
turb_next = cmplx(0.0_dp, 0.0_dp)
147+
turb_next = cmplx(0, 0, kind=cdp)
148148
call add_turbulence(turb_next, turb_dt)
149149

150150
! Fourier transform

turb/turb_force_utils.f90

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ subroutine gaussian_cmplx(G)
153153
call kiss64_double(ndim, kiss64_state, Rnd(1:ndim))
154154
arg = (Rnd(1:ndim) * 2.0 * PI) - 1.0
155155

156-
G = cmplx(mag * cos(arg), mag * sin(arg))
156+
G = cmplx(mag * cos(arg), mag * sin(arg), kind=cdp)
157157

158158
! Method 2: Gaussian real and imaginary components
159159
! do d=1,ndim
@@ -187,19 +187,21 @@ subroutine add_turbulence(turb_field, dt)
187187
! Wiener process
188188

189189
integer :: i, j, k ! Loop variables
190-
integer :: ii,jj,kk ! Hermitian pair
191190
integer :: halfway ! Half of grid size
192191

193192
#if defined(HERMITIAN_FIELD)
193+
integer :: ii,jj,kk ! Hermitian pair
194194
logical :: hermitian_pair ! Do we need to take conjugate?
195195
logical :: own_conjg ! Are we are own conjugate pair?
196196
#endif
197197

198-
real(kind=dp) :: unitk(1:NDIM) ! Unit vector parallel to k
199198
complex(kind=cdp) :: complex_vec(1:NDIM) ! Complex Fourier vector
199+
#if NDIM>1
200+
real(kind=dp) :: unitk(1:NDIM) ! Unit vector parallel to k
200201
complex(kind=cdp) :: unitk_cmplx(1:NDIM) ! Unit vector parallel to k
201202
complex(kind=cdp) :: comp_cmplx(1:NDIM) ! Compressive component
202203
complex(kind=cdp) :: sol_cmplx(1:NDIM) ! Solenoidal components
204+
#endif
203205

204206
halfway = TURB_GS / 2 ! integer division
205207

@@ -262,7 +264,7 @@ subroutine add_turbulence(turb_field, dt)
262264
#if NDIM>1
263265
! Helmholtz decomposition!
264266
call find_unitk(i, j, k, halfway, unitk)
265-
unitk_cmplx = cmplx(unitk)
267+
unitk_cmplx = cmplx(unitk, kind=cdp)
266268
comp_cmplx = unitk_cmplx * dot_product(unitk_cmplx,complex_vec)
267269
sol_cmplx = complex_vec - comp_cmplx
268270
complex_vec = comp_cmplx*comp_frac + sol_cmplx*sol_frac
@@ -490,7 +492,7 @@ subroutine power_rms_norm(power_in, P)
490492
integer :: d ! Dimension counter
491493

492494
do d=1,NDIM
493-
complex_field(d,:,:,:) = cmplx(power_in)
495+
complex_field(d,:,:,:) = cmplx(power_in, kind=cdp)
494496
end do
495497

496498
#if NDIM==1

0 commit comments

Comments
 (0)