你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-07 15:10:13 +08:00
refactored domain coordinates logic
这个提交包含在:
@@ -20,6 +20,7 @@ import numpy as np
|
||||
|
||||
from gprMax.constants import c, floattype, complextype
|
||||
from gprMax.materials import Material
|
||||
from gprMax.utilities import round_value
|
||||
|
||||
|
||||
class Grid(object):
|
||||
@@ -29,6 +30,9 @@ class Grid(object):
|
||||
self.nx = grid.shape[0]
|
||||
self.ny = grid.shape[1]
|
||||
self.nz = grid.shape[2]
|
||||
self.dx = 1
|
||||
self.dy = 1
|
||||
self.dz = 1
|
||||
self.i_max = self.nx - 1
|
||||
self.j_max = self.ny - 1
|
||||
self.k_max = self.nz - 1
|
||||
@@ -50,6 +54,14 @@ class Grid(object):
|
||||
def get(self, i, j, k):
|
||||
return self.grid[i, j, k]
|
||||
|
||||
def within_bounds(self, **kwargs):
|
||||
for co, val in kwargs.items():
|
||||
if val < 0 or val > getattr(self, 'n' + co):
|
||||
raise ValueError(co)
|
||||
|
||||
def calculate_coord(self, coord, val):
|
||||
co = round_value(float(val) / getattr(self, 'd' + coord))
|
||||
return co
|
||||
|
||||
class FDTDGrid(Grid):
|
||||
"""Holds attributes associated with the entire grid. A convenient way for accessing regularly used parameters."""
|
||||
|
@@ -36,6 +36,14 @@ def process_multicmds(multicmds, G):
|
||||
G (class): Grid class instance - holds essential parameters describing the model.
|
||||
"""
|
||||
|
||||
# Check if coordinates are within the bounds of the grid
|
||||
def check_coordinates(x, y, z, name=''):
|
||||
try:
|
||||
G.within_bounds(x=x, y=y, z=z)
|
||||
except ValueError as err:
|
||||
s = "'{}: {} ' {} {}-coordinate is not within the model domain".format(cmdname, ' '.join(tmp), name, err.args[0])
|
||||
raise CmdInputError(s)
|
||||
|
||||
# Waveform definitions
|
||||
cmdname = '#waveform'
|
||||
if multicmds[cmdname] != 'None':
|
||||
@@ -73,16 +81,11 @@ def process_multicmds(multicmds, G):
|
||||
# Check polarity & position parameters
|
||||
if tmp[0].lower() not in ('x', 'y', 'z'):
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be x, y, or z')
|
||||
xcoord = round_value(float(tmp[1])/G.dx)
|
||||
ycoord = round_value(float(tmp[2])/G.dy)
|
||||
zcoord = round_value(float(tmp[3])/G.dz)
|
||||
xcoord = G.calculate_coord('x', tmp[1])
|
||||
ycoord = G.calculate_coord('y', tmp[2])
|
||||
zcoord = G.calculate_coord('z', tmp[3])
|
||||
resistance = float(tmp[4])
|
||||
if xcoord < 0 or xcoord >= G.nx:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' x-coordinate is not within the model domain')
|
||||
if ycoord < 0 or ycoord >= G.ny:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' y-coordinate is not within the model domain')
|
||||
if zcoord < 0 or zcoord >= G.nz:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' z-coordinate is not within the model domain')
|
||||
check_coordinates(xcoord, ycoord, zcoord)
|
||||
if xcoord < G.pmlthickness[0] or xcoord > G.nx - G.pmlthickness[3] or ycoord < G.pmlthickness[1] or ycoord > G.ny - G.pmlthickness[4] or zcoord < G.pmlthickness[2] or zcoord > G.nz - G.pmlthickness[5]:
|
||||
print("WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n')
|
||||
if resistance < 0:
|
||||
@@ -139,15 +142,10 @@ def process_multicmds(multicmds, G):
|
||||
# Check polarity & position parameters
|
||||
if tmp[0].lower() not in ('x', 'y', 'z'):
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be x, y, or z')
|
||||
xcoord = round_value(float(tmp[1])/G.dx)
|
||||
ycoord = round_value(float(tmp[2])/G.dy)
|
||||
zcoord = round_value(float(tmp[3])/G.dz)
|
||||
if xcoord < 0 or xcoord >= G.nx:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' x-coordinate is not within the model domain')
|
||||
if ycoord < 0 or ycoord >= G.ny:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' y-coordinate is not within the model domain')
|
||||
if zcoord < 0 or zcoord >= G.nz:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' z-coordinate is not within the model domain')
|
||||
xcoord = G.calculate_coord('x', tmp[1])
|
||||
ycoord = G.calculate_coord('y', tmp[2])
|
||||
zcoord = G.calculate_coord('z', tmp[3])
|
||||
check_coordinates(xcoord, ycoord, zcoord)
|
||||
if xcoord < G.pmlthickness[0] or xcoord > G.nx - G.pmlthickness[3] or ycoord < G.pmlthickness[1] or ycoord > G.ny - G.pmlthickness[4] or zcoord < G.pmlthickness[2] or zcoord > G.nz - G.pmlthickness[5]:
|
||||
print("WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n')
|
||||
|
||||
@@ -204,15 +202,10 @@ def process_multicmds(multicmds, G):
|
||||
# Check polarity & position parameters
|
||||
if tmp[0].lower() not in ('x', 'y', 'z'):
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be x, y, or z')
|
||||
xcoord = round_value(float(tmp[1])/G.dx)
|
||||
ycoord = round_value(float(tmp[2])/G.dy)
|
||||
zcoord = round_value(float(tmp[3])/G.dz)
|
||||
if xcoord < 0 or xcoord >= G.nx:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' x-coordinate is not within the model domain')
|
||||
if ycoord < 0 or ycoord >= G.ny:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' y-coordinate is not within the model domain')
|
||||
if zcoord < 0 or zcoord >= G.nz:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' z-coordinate is not within the model domain')
|
||||
xcoord = G.calculate_coord('x', tmp[1])
|
||||
ycoord = G.calculate_coord('y', tmp[2])
|
||||
zcoord = G.calculate_coord('z', tmp[3])
|
||||
check_coordinates(xcoord, ycoord, zcoord)
|
||||
if xcoord < G.pmlthickness[0] or xcoord > G.nx - G.pmlthickness[3] or ycoord < G.pmlthickness[1] or ycoord > G.ny - G.pmlthickness[4] or zcoord < G.pmlthickness[2] or zcoord > G.nz - G.pmlthickness[5]:
|
||||
print("WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n')
|
||||
|
||||
@@ -257,7 +250,6 @@ def process_multicmds(multicmds, G):
|
||||
|
||||
G.magneticdipoles.append(m)
|
||||
|
||||
|
||||
# Transmission line
|
||||
cmdname = '#transmission_line'
|
||||
if multicmds[cmdname] != 'None':
|
||||
@@ -269,16 +261,14 @@ def process_multicmds(multicmds, G):
|
||||
# Check polarity & position parameters
|
||||
if tmp[0].lower() not in ('x', 'y', 'z'):
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' polarisation must be x, y, or z')
|
||||
xcoord = round_value(float(tmp[1])/G.dx)
|
||||
ycoord = round_value(float(tmp[2])/G.dy)
|
||||
zcoord = round_value(float(tmp[3])/G.dz)
|
||||
|
||||
xcoord = G.calculate_coord('x', tmp[1])
|
||||
ycoord = G.calculate_coord('y', tmp[2])
|
||||
zcoord = G.calculate_coord('z', tmp[3])
|
||||
resistance = float(tmp[4])
|
||||
if xcoord < 0 or xcoord >= G.nx:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' x-coordinate is not within the model domain')
|
||||
if ycoord < 0 or ycoord >= G.ny:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' y-coordinate is not within the model domain')
|
||||
if zcoord < 0 or zcoord >= G.nz:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' z-coordinate is not within the model domain')
|
||||
|
||||
check_coordinates(xcoord, ycoord, zcoord)
|
||||
|
||||
if xcoord < G.pmlthickness[0] or xcoord > G.nx - G.pmlthickness[3] or ycoord < G.pmlthickness[1] or ycoord > G.ny - G.pmlthickness[4] or zcoord < G.pmlthickness[2] or zcoord > G.nz - G.pmlthickness[5]:
|
||||
print("WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n')
|
||||
if resistance <= 0 or resistance > z0:
|
||||
@@ -324,7 +314,6 @@ def process_multicmds(multicmds, G):
|
||||
|
||||
G.transmissionlines.append(t)
|
||||
|
||||
|
||||
# Receiver
|
||||
cmdname = '#rx'
|
||||
if multicmds[cmdname] != 'None':
|
||||
@@ -337,12 +326,7 @@ def process_multicmds(multicmds, G):
|
||||
xcoord = round_value(float(tmp[0])/G.dx)
|
||||
ycoord = round_value(float(tmp[1])/G.dy)
|
||||
zcoord = round_value(float(tmp[2])/G.dz)
|
||||
if xcoord < 0 or xcoord >= G.nx:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' x-coordinate is not within the model domain')
|
||||
if ycoord < 0 or ycoord >= G.ny:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' y-coordinate is not within the model domain')
|
||||
if zcoord < 0 or zcoord >= G.nz:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' z-coordinate is not within the model domain')
|
||||
check_coordinates(xcoord, ycoord, zcoord)
|
||||
if xcoord < G.pmlthickness[0] or xcoord > G.nx - G.pmlthickness[3] or ycoord < G.pmlthickness[1] or ycoord > G.ny - G.pmlthickness[4] or zcoord < G.pmlthickness[2] or zcoord > G.nz - G.pmlthickness[5]:
|
||||
print("WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n')
|
||||
|
||||
@@ -381,28 +365,21 @@ def process_multicmds(multicmds, G):
|
||||
if len(tmp) != 9:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires exactly nine parameters')
|
||||
|
||||
xs = round_value(float(tmp[0])/G.dx)
|
||||
xf = round_value(float(tmp[3])/G.dx)
|
||||
ys = round_value(float(tmp[1])/G.dy)
|
||||
yf = round_value(float(tmp[4])/G.dy)
|
||||
zs = round_value(float(tmp[2])/G.dz)
|
||||
zf = round_value(float(tmp[5])/G.dz)
|
||||
dx = round_value(float(tmp[6])/G.dx)
|
||||
dy = round_value(float(tmp[7])/G.dy)
|
||||
dz = round_value(float(tmp[8])/G.dz)
|
||||
xs = G.calculate_coord('x', tmp[0])
|
||||
ys = G.calculate_coord('y', tmp[1])
|
||||
zs = G.calculate_coord('z', tmp[2])
|
||||
|
||||
xf = G.calculate_coord('x', tmp[3])
|
||||
yf = G.calculate_coord('y', tmp[4])
|
||||
zf = G.calculate_coord('z', tmp[5])
|
||||
|
||||
dx = G.calculate_coord('x', tmp[6])
|
||||
dy = G.calculate_coord('y', tmp[7])
|
||||
dz = G.calculate_coord('z', tmp[8])
|
||||
|
||||
check_coordinates(xs, ys, zs, name='lower')
|
||||
check_coordinates(xf, yf, zf, name='upper')
|
||||
|
||||
if xs < 0 or xs >= G.nx:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the lower x-coordinate {:g}m is not within the model domain'.format(xs))
|
||||
if xf < 0 or xf >= G.nx:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the upper x-coordinate {:g}m is not within the model domain'.format(xf))
|
||||
if ys < 0 or ys >= G.ny:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the lower y-coordinate {:g}m is not within the model domain'.format(ys))
|
||||
if yf < 0 or yf >= G.ny:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the upper y-coordinate {:g}m is not within the model domain'.format(yf))
|
||||
if zs < 0 or zs >= G.nz:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the lower z-coordinate {:g}m is not within the model domain'.format(zs))
|
||||
if zf < 0 or zf >= G.nz:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the upper z-coordinate {:g}m is not within the model domain'.format(zf))
|
||||
if xcoord < G.pmlthickness[0] or xcoord > G.nx - G.pmlthickness[3] or ycoord < G.pmlthickness[1] or ycoord > G.ny - G.pmlthickness[4] or zcoord < G.pmlthickness[2] or zcoord > G.nz - G.pmlthickness[5]:
|
||||
print("WARNING: '" + cmdname + ': ' + ' '.join(tmp) + "'" + ' sources and receivers should not normally be positioned within the PML.\n')
|
||||
if xs >= xf or ys >= yf or zs >= zf:
|
||||
@@ -437,15 +414,17 @@ def process_multicmds(multicmds, G):
|
||||
if len(tmp) != 11:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires exactly eleven parameters')
|
||||
|
||||
xs = round_value(float(tmp[0])/G.dx)
|
||||
xf = round_value(float(tmp[3])/G.dx)
|
||||
ys = round_value(float(tmp[1])/G.dy)
|
||||
yf = round_value(float(tmp[4])/G.dy)
|
||||
zs = round_value(float(tmp[2])/G.dz)
|
||||
zf = round_value(float(tmp[5])/G.dz)
|
||||
dx = round_value(float(tmp[6])/G.dx)
|
||||
dy = round_value(float(tmp[7])/G.dy)
|
||||
dz = round_value(float(tmp[8])/G.dz)
|
||||
xs = G.calculate_coord('x', tmp[0])
|
||||
ys = G.calculate_coord('y', tmp[1])
|
||||
zs = G.calculate_coord('z', tmp[2])
|
||||
|
||||
xf = G.calculate_coord('x', tmp[3])
|
||||
yf = G.calculate_coord('y', tmp[4])
|
||||
zf = G.calculate_coord('z', tmp[5])
|
||||
|
||||
dx = G.calculate_coord('x', tmp[6])
|
||||
dy = G.calculate_coord('y', tmp[7])
|
||||
dz = G.calculate_coord('z', tmp[8])
|
||||
|
||||
# If number of iterations given
|
||||
try:
|
||||
@@ -458,18 +437,9 @@ def process_multicmds(multicmds, G):
|
||||
else:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' time value must be greater than zero')
|
||||
|
||||
if xs < 0 or xs > G.nx:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the lower x-coordinate {:g}m is not within the model domain'.format(xs * G.dx))
|
||||
if xf < 0 or xf > G.nx:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the upper x-coordinate {:g}m is not within the model domain'.format(xf * G.dx))
|
||||
if ys < 0 or ys > G.ny:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the lower y-coordinate {:g}m is not within the model domain'.format(ys * G.dy))
|
||||
if yf < 0 or yf > G.ny:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the upper y-coordinate {:g}m is not within the model domain'.format(yf * G.dy))
|
||||
if zs < 0 or zs > G.nz:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the lower z-coordinate {:g}m is not within the model domain'.format(zs * G.dz))
|
||||
if zf < 0 or zf > G.nz:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the upper z-coordinate {:g}m is not within the model domain'.format(zf * G.dz))
|
||||
check_coordinates(xs, ys, zs, name='lower')
|
||||
check_coordinates(xf, yf, zf, name='upper')
|
||||
|
||||
if xs >= xf or ys >= yf or zs >= zf:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the lower coordinates should be less than the upper coordinates')
|
||||
if dx < 0 or dy < 0 or dz < 0:
|
||||
@@ -486,7 +456,6 @@ def process_multicmds(multicmds, G):
|
||||
|
||||
G.snapshots.append(s)
|
||||
|
||||
|
||||
# Materials
|
||||
cmdname = '#material'
|
||||
if multicmds[cmdname] != 'None':
|
||||
@@ -666,28 +635,21 @@ def process_multicmds(multicmds, G):
|
||||
if len(tmp) != 11:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' requires exactly eleven parameters')
|
||||
|
||||
xs = round_value(float(tmp[0])/G.dx)
|
||||
xf = round_value(float(tmp[3])/G.dx)
|
||||
ys = round_value(float(tmp[1])/G.dy)
|
||||
yf = round_value(float(tmp[4])/G.dy)
|
||||
zs = round_value(float(tmp[2])/G.dz)
|
||||
zf = round_value(float(tmp[5])/G.dz)
|
||||
dx = round_value(float(tmp[6])/G.dx)
|
||||
dy = round_value(float(tmp[7])/G.dy)
|
||||
dz = round_value(float(tmp[8])/G.dz)
|
||||
xs = G.calculate_coord('x', tmp[0])
|
||||
ys = G.calculate_coord('y', tmp[1])
|
||||
zs = G.calculate_coord('z', tmp[2])
|
||||
|
||||
xf = G.calculate_coord('x', tmp[3])
|
||||
yf = G.calculate_coord('y', tmp[4])
|
||||
zf = G.calculate_coord('z', tmp[5])
|
||||
|
||||
dx = G.calculate_coord('x', tmp[6])
|
||||
dy = G.calculate_coord('y', tmp[7])
|
||||
dz = G.calculate_coord('z', tmp[8])
|
||||
|
||||
check_coordinates(xs, ys, zs, name='lower')
|
||||
check_coordinates(xf, yf, zf, name='upper')
|
||||
|
||||
if xs < 0 or xs > G.nx:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the lower x-coordinate {:g}m is not within the model domain'.format(xs * G.dx))
|
||||
if xf < 0 or xf > G.nx:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the upper x-coordinate {:g}m is not within the model domain'.format(xf * G.dx))
|
||||
if ys < 0 or ys > G.ny:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the lower y-coordinate {:g}m is not within the model domain'.format(ys * G.dy))
|
||||
if yf < 0 or yf > G.ny:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the upper y-coordinate {:g}m is not within the model domain'.format(yf * G.dy))
|
||||
if zs < 0 or zs > G.nz:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the lower z-coordinate {:g}m is not within the model domain'.format(zs * G.dz))
|
||||
if zf < 0 or zf > G.nz:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the upper z-coordinate {:g}m is not within the model domain'.format(zf * G.dz))
|
||||
if xs >= xf or ys >= yf or zs >= zf:
|
||||
raise CmdInputError("'" + cmdname + ': ' + ' '.join(tmp) + "'" + ' the lower coordinates should be less than the upper coordinates')
|
||||
if dx < 0 or dy < 0 or dz < 0:
|
||||
|
在新工单中引用
屏蔽一个用户