Skip to content

Commit

Permalink
Update to fractal behaviour. Fixes int/float bug & D now used directly.
Browse files Browse the repository at this point in the history
  • Loading branch information
craig-warren committed Jan 3, 2024
1 parent 0848c13 commit 368e7c1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
8 changes: 3 additions & 5 deletions gprMax/fractals.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ def __init__(self, xs, xf, ys, yf, zs, zf, dimension, seed):
self.ny = yf - ys
self.nz = zf - zs
self.seed = seed
self.dimension = dimension
# Constant related to fractal dimension from: http://dx.doi.org/10.1017/CBO9781139174695
self.b = -(2 * self.dimension - 7) / 2
self.dimension = dimension # Fractal dimension from: http://dx.doi.org/10.1017/CBO9781139174695
self.weighting = np.array([1, 1], dtype=np.float64)
self.fractalrange = (0, 0)
self.filldepth = 0
Expand Down Expand Up @@ -90,7 +88,7 @@ def generate_fractal_surface(self, G):
A = fftpack.fftshift(A)

# Generate fractal
generate_fractal2D(surfacedims[0], surfacedims[1], G.nthreads, self.b, self.weighting, v1, A, self.fractalsurface)
generate_fractal2D(surfacedims[0], surfacedims[1], G.nthreads, self.dimension, self.weighting, v1, A, self.fractalsurface)

# Shift the zero frequency component to start of the array
self.fractalsurface = fftpack.ifftshift(self.fractalsurface)
Expand Down Expand Up @@ -178,7 +176,7 @@ def generate_fractal_volume(self, G):
A = fftpack.fftshift(A)

# Generate fractal
generate_fractal3D(self.nx, self.ny, self.nz, G.nthreads, self.b, self.weighting, v1, A, self.fractalvolume)
generate_fractal3D(self.nx, self.ny, self.nz, G.nthreads, self.dimension, self.weighting, v1, A, self.fractalvolume)

# Shift the zero frequency component to the start of the array
self.fractalvolume = fftpack.ifftshift(self.fractalvolume)
Expand Down
12 changes: 6 additions & 6 deletions gprMax/fractals_generate_ext.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ cimport numpy as np
from cython.parallel import prange


cpdef void generate_fractal2D(int nx, int ny, int nthreads, int b, np.float64_t[:] weighting, np.float64_t[:] v1, np.complex128_t[:, ::1] A, np.complex128_t[:, ::1] fractalsurface):
cpdef void generate_fractal2D(int nx, int ny, int nthreads, float D, np.float64_t[:] weighting, np.float64_t[:] v1, np.complex128_t[:, ::1] A, np.complex128_t[:, ::1] fractalsurface):
"""This function generates a fractal surface for a 2D array.
Args:
nx, ny (int): Fractal surface size in cells
nthreads (int): Number of threads to use
b (int): Constant related to fractal dimension
D (float): Fractal dimension
weighting (memoryview): Access to weighting vector
v1 (memoryview): Access to positional vector at centre of array, scaled by weighting
A (memoryview): Access to array containing random numbers (to be convolved with fractal function)
Expand All @@ -46,20 +46,20 @@ cpdef void generate_fractal2D(int nx, int ny, int nthreads, int b, np.float64_t[
# Calulate norm of v2 - v1
rr = ((v2x - v1[0])**2 + (v2y - v1[1])**2)**(1/2)

B = rr**b
B = rr**D
if B == 0:
B = 0.9

fractalsurface[i, j] = A[i, j] / B


cpdef void generate_fractal3D(int nx, int ny, int nz, int nthreads, int b, np.float64_t[:] weighting, np.float64_t[:] v1, np.complex128_t[:, :, ::1] A, np.complex128_t[:, :, ::1] fractalvolume):
cpdef void generate_fractal3D(int nx, int ny, int nz, int nthreads, float D, np.float64_t[:] weighting, np.float64_t[:] v1, np.complex128_t[:, :, ::1] A, np.complex128_t[:, :, ::1] fractalvolume):
"""This function generates a fractal volume for a 3D array.
Args:
nx, ny, nz (int): Fractal volume size in cells
nthreads (int): Number of threads to use
b (int): Constant related to fractal dimension
D (float): Fractal dimension
weighting (memoryview): Access to weighting vector
v1 (memoryview): Access to positional vector at centre of array, scaled by weighting
A (memoryview): Access to array containing random numbers (to be convolved with fractal function)
Expand All @@ -79,7 +79,7 @@ cpdef void generate_fractal3D(int nx, int ny, int nz, int nthreads, int b, np.fl

# Calulate norm of v2 - v1
rr = ((v2x - v1[0])**2 + (v2y - v1[1])**2 + (v2z - v1[2])**2)**(1/2)
B = rr**b
B = rr**D
if B == 0:
B = 0.9

Expand Down

0 comments on commit 368e7c1

Please sign in to comment.