import numpy as np
from gprMax.fields_update import update_ex
def main():
nthreads = 4
nx = 100
ny = 100
nz = 100
iterations = 1000
ID = np.ones((6, nx + 1, ny + 1, nz + 1), dtype=np.uint32)
Ex = np.zeros((nx, ny + 1, nz + 1), dtype=np.float64)
Hy = np.zeros((nx, ny + 1, nz), dtype=np.float64)
Hz = np.zeros((nx, ny, nz + 1), dtype=np.float64)
updatecoeffsE = np.zeros((10, 5), dtype=np.float64)
for timestep in range(iterations):
update_ex(nx, ny, nz, nthreads, updatecoeffsE, ID, Ex, Hy, Hz)
cpdef update_ex(int nx, int ny, int nz, int nthreads, np.float64_t[:, :] updatecoeffsE, np.uint32_t[:, :, :, :] ID, np.float64_t[:, :, :] Ex, np.float64_t[:, :, :] Hy, np.float64_t[:, :, :] Hz):
"""This function updates the Ex field components.
Args:
nx, ny, nz (int): Grid size in cells
nthreads (int): Number of threads to use
updatecoeffs, ID, E, H (memoryviews): Access to update coeffients, ID and field component arrays
"""
cdef int i, j, k, listIndex
for i in prange(0, nx, nogil=True, schedule='static', chunksize=1, num_threads=nthreads):
for j in range(1, ny):
for k in range(1, nz):
listIndex = ID[0, i, j, k]
Ex[i, j, k] = updatecoeffsE[listIndex, 0] * Ex[i, j, k] + updatecoeffsE[listIndex, 2] * (Hz[i, j, k] - Hz[i, j - 1, k]) - updatecoeffsE[listIndex, 3] * (Hy[i, j, k] - Hy[i, j, k - 1])