Remove shifting zero frequency from fractal surfaces

这个提交包含在:
Nathan Mannall
2025-04-15 17:32:35 +01:00
父节点 2c8c14c73d
当前提交 493db241d7
共有 3 个文件被更改,包括 15 次插入12 次删除

查看文件

@@ -26,6 +26,10 @@ from gprMax.config cimport float_or_double_complex
cpdef void generate_fractal2D(
int nx,
int ny,
int ox,
int oy,
int gx,
int gy,
int nthreads,
float D,
np.float64_t[:] weighting,
@@ -50,12 +54,16 @@ cpdef void generate_fractal2D(
cdef Py_ssize_t i, j
cdef double v2x, v2y, rr, B
cdef int sx, sy
sx = gx // 2
sy = gy // 2
for i in prange(nx, nogil=True, schedule='static', num_threads=nthreads):
for j in range(ny):
# Positional vector for current position
v2x = weighting[0] * i
v2y = weighting[1] * j
v2x = weighting[0] * ((i + ox + sx) % gx)
v2y = weighting[1] * ((j + oy + sy) % gy)
# Calulate norm of v2 - v1
rr = ((v2x - v1[0])**2 + (v2y - v1[1])**2)**(1/2)

查看文件

@@ -108,11 +108,13 @@ class FractalSurface:
# 2D FFT
A = fftpack.fftn(A)
# Shift the zero frequency component to the centre of the array
A = fftpack.fftshift(A)
# Generate fractal
generate_fractal2D(
surfacedims[0],
surfacedims[1],
0,
0,
surfacedims[0],
surfacedims[1],
config.get_model_config().ompthreads,
@@ -122,8 +124,7 @@ class FractalSurface:
A,
self.fractalsurface,
)
# Shift the zero frequency component to start of the array
self.fractalsurface = fftpack.ifftshift(self.fractalsurface)
# Set DC component of FFT to zero
self.fractalsurface[0, 0] = 0
# Take the real part (numerical errors can give rise to an imaginary part)

查看文件

@@ -223,27 +223,21 @@ class FractalBox(RotatableMixin, GeometryUserObject):
for surface in self.volume.fractalsurfaces:
if surface.surfaceID == "xminus":
if surface.fractalrange[0] < self.volume.xs:
self.volume.nx += self.volume.xs - surface.fractalrange[0]
self.volume.xs = surface.fractalrange[0]
elif surface.surfaceID == "xplus":
if surface.fractalrange[1] > self.volume.xf:
self.volume.nx += surface.fractalrange[1] - self.volume.xf
self.volume.xf = surface.fractalrange[1]
elif surface.surfaceID == "yminus":
if surface.fractalrange[0] < self.volume.ys:
self.volume.ny += self.volume.ys - surface.fractalrange[0]
self.volume.ys = surface.fractalrange[0]
elif surface.surfaceID == "yplus":
if surface.fractalrange[1] > self.volume.yf:
self.volume.ny += surface.fractalrange[1] - self.volume.yf
self.volume.yf = surface.fractalrange[1]
elif surface.surfaceID == "zminus":
if surface.fractalrange[0] < self.volume.zs:
self.volume.nz += self.volume.zs - surface.fractalrange[0]
self.volume.zs = surface.fractalrange[0]
elif surface.surfaceID == "zplus":
if surface.fractalrange[1] > self.volume.zf:
self.volume.nz += surface.fractalrange[1] - self.volume.zf
self.volume.zf = surface.fractalrange[1]
# If there is only 1 bin then a normal material is being used,