你已经派生过 gprMax
镜像自地址
https://gitee.com/sunhf/gprMax.git
已同步 2025-08-07 15:10:13 +08:00
Merge pull request #342 from Sai-Suraj-27/beta_1
This PR updates a few more files which makes them much cleaner with better code.
这个提交包含在:
@@ -102,9 +102,11 @@ halfspace = gprMax.Box(p1=(0, 0, 0), p2=(x, y, antenna_p[2]), material_id='soil'
|
||||
scene.add(halfspace)
|
||||
|
||||
for i in range(1, 51):
|
||||
snap = gprMax.Snapshot(p1=(0, y / 2, 0), p2=(x, y / 2 + dl, z), dl=(dl, dl, dl),
|
||||
filename=Path(*parts[:-1], parts[-1] + '_' + str(i)).name,
|
||||
time=i * tw / 50)
|
||||
snap = gprMax.Snapshot(p1=(0, y / 2, 0),
|
||||
p2=(x, y / 2 + dl, z),
|
||||
dl=(dl, dl, dl),
|
||||
filename=Path(*parts[:-1], f'{parts[-1]}_{str(i)}').name,
|
||||
time=i * tw / 50,)
|
||||
scene.add(snap)
|
||||
|
||||
# create a geometry view of the main grid and the sub grid stitched together
|
||||
|
@@ -74,7 +74,7 @@ class AddGrass(UserObjectGeometry):
|
||||
limits = self.kwargs['limits']
|
||||
n_blades = self.kwargs['n_blades']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' requires at least eleven parameters')
|
||||
logger.exception(f'{self.__str__()} requires at least eleven parameters')
|
||||
raise
|
||||
|
||||
try:
|
||||
@@ -90,7 +90,7 @@ class AddGrass(UserObjectGeometry):
|
||||
try:
|
||||
volume = volumes[0]
|
||||
except NameError:
|
||||
logger.exception(self.__str__() + f' cannot find FractalBox {fractal_box_id}')
|
||||
logger.exception(f'{self.__str__()} cannot find FractalBox {fractal_box_id}')
|
||||
raise
|
||||
|
||||
p1, p2 = uip.check_box_points(p1, p2, self.__str__())
|
||||
@@ -98,32 +98,32 @@ class AddGrass(UserObjectGeometry):
|
||||
xf, yf, zf = p2
|
||||
|
||||
if frac_dim < 0:
|
||||
logger.exception(self.__str__() + ' requires a positive value for ' +
|
||||
logger.exception(f'{self.__str__()} requires a positive value for ' +
|
||||
'the fractal dimension')
|
||||
raise ValueError
|
||||
if limits[0] < 0 or limits[1] < 0:
|
||||
logger.exception(self.__str__() + ' requires a positive value for ' +
|
||||
logger.exception(f'{self.__str__()} requires a positive value for ' +
|
||||
'the minimum and maximum heights for grass blades')
|
||||
raise ValueError
|
||||
|
||||
# Check for valid orientations
|
||||
if xs == xf:
|
||||
if ys == yf or zs == zf:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
if xs != volume.xs and xs != volume.xf:
|
||||
logger.exception(self.__str__() + ' must specify external surfaces on a fractal box')
|
||||
logger.exception(f'{self.__str__()} must specify external surfaces on a fractal box')
|
||||
raise ValueError
|
||||
fractalrange = (round_value(limits[0] / grid.dx), round_value(limits[1] / grid.dx))
|
||||
# xminus surface
|
||||
if xs == volume.xs:
|
||||
logger.exception(self.__str__() + ' grass can only be specified ' +
|
||||
logger.exception(f'{self.__str__()} grass can only be specified ' +
|
||||
'on surfaces in the positive axis direction')
|
||||
raise ValueError
|
||||
# xplus surface
|
||||
elif xf == volume.xf:
|
||||
if fractalrange[1] > grid.nx:
|
||||
logger.exception(self.__str__() + ' cannot apply grass to ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply grass to ' +
|
||||
'fractal box as it would exceed the domain ' +
|
||||
'size in the x direction')
|
||||
raise ValueError
|
||||
@@ -131,21 +131,21 @@ class AddGrass(UserObjectGeometry):
|
||||
|
||||
elif ys == yf:
|
||||
if xs == xf or zs == zf:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
if ys != volume.ys and ys != volume.yf:
|
||||
logger.exception(self.__str__() + ' must specify external surfaces on a fractal box')
|
||||
logger.exception(f'{self.__str__()} must specify external surfaces on a fractal box')
|
||||
raise ValueError
|
||||
fractalrange = (round_value(limits[0] / grid.dy), round_value(limits[1] / grid.dy))
|
||||
# yminus surface
|
||||
if ys == volume.ys:
|
||||
logger.exception(self.__str__() + ' grass can only be specified ' +
|
||||
logger.exception(f'{self.__str__()} grass can only be specified ' +
|
||||
'on surfaces in the positive axis direction')
|
||||
raise ValueError
|
||||
# yplus surface
|
||||
elif yf == volume.yf:
|
||||
if fractalrange[1] > grid.ny:
|
||||
logger.exception(self.__str__() + ' cannot apply grass to ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply grass to ' +
|
||||
'fractal box as it would exceed the domain ' +
|
||||
'size in the y direction')
|
||||
raise ValueError
|
||||
@@ -153,28 +153,28 @@ class AddGrass(UserObjectGeometry):
|
||||
|
||||
elif zs == zf:
|
||||
if xs == xf or ys == yf:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
if zs != volume.zs and zs != volume.zf:
|
||||
logger.exception(self.__str__() + ' must specify external surfaces on a fractal box')
|
||||
logger.exception(f'{self.__str__()} must specify external surfaces on a fractal box')
|
||||
raise ValueError
|
||||
fractalrange = (round_value(limits[0] / grid.dz), round_value(limits[1] / grid.dz))
|
||||
# zminus surface
|
||||
if zs == volume.zs:
|
||||
logger.exception(self.__str__() + ' grass can only be specified ' +
|
||||
logger.exception(f'{self.__str__()} grass can only be specified ' +
|
||||
'on surfaces in the positive axis direction')
|
||||
raise ValueError
|
||||
# zplus surface
|
||||
elif zf == volume.zf:
|
||||
if fractalrange[1] > grid.nz:
|
||||
logger.exception(self.__str__() + ' cannot apply grass to ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply grass to ' +
|
||||
'fractal box as it would exceed the domain ' +
|
||||
'size in the z direction')
|
||||
raise ValueError
|
||||
requestedsurface = 'zplus'
|
||||
|
||||
else:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
|
||||
surface = FractalSurface(xs, xf, ys, yf, zs, zf, frac_dim)
|
||||
@@ -187,7 +187,7 @@ class AddGrass(UserObjectGeometry):
|
||||
surface.operatingonID = volume.ID
|
||||
surface.generate_fractal_surface()
|
||||
if n_blades > surface.fractalsurface.shape[0] * surface.fractalsurface.shape[1]:
|
||||
logger.exception(self.__str__() + ' the specified surface is not large ' +
|
||||
logger.exception(f'{self.__str__()} the specified surface is not large ' +
|
||||
'enough for the number of grass blades/roots specified')
|
||||
raise ValueError
|
||||
|
||||
@@ -234,13 +234,13 @@ class AddGrass(UserObjectGeometry):
|
||||
grass = next((x for x in grid.materials if x.ID == 'grass'))
|
||||
testgrass = next((x for x in grass.tau if x < grid.dt), None)
|
||||
if testgrass:
|
||||
logger.exception(self.__str__() + ' requires the time step for the ' +
|
||||
logger.exception(f'{self.__str__()} requires the time step for the ' +
|
||||
'model to be less than the relaxation time required to model grass.')
|
||||
raise ValueError
|
||||
|
||||
volume.fractalsurfaces.append(surface)
|
||||
|
||||
logger.info(self.grid_name(grid) + f'{n_blades} blades of grass on surface from ' +
|
||||
logger.info(f'{self.grid_name(grid)}{n_blades} blades of grass on surface from ' +
|
||||
f'{xs * grid.dx:g}m, {ys * grid.dy:g}m, {zs * grid.dz:g}m, ' +
|
||||
f'to {xf * grid.dx:g}m, {yf * grid.dy:g}m, {zf * grid.dz:g}m ' +
|
||||
f'with fractal dimension {surface.dimension:g}, fractal seeding ' +
|
||||
|
@@ -74,13 +74,13 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
limits = np.array(self.kwargs['limits'])
|
||||
fractal_box_id = self.kwargs['fractal_box_id']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' incorrect parameters')
|
||||
logger.exception(f'{self.__str__()} incorrect parameters')
|
||||
raise
|
||||
|
||||
try:
|
||||
seed = self.kwargs['seed']
|
||||
except KeyError:
|
||||
logger.warning(self.__str__() + ' no value for seed detected. This ' +
|
||||
logger.warning(f'{self.__str__()} no value for seed detected. This ' +
|
||||
'means you will get a different fractal distribution ' +
|
||||
'every time the model runs.')
|
||||
seed = None
|
||||
@@ -93,7 +93,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
if volumes:
|
||||
volume = volumes[0]
|
||||
else:
|
||||
logger.exception(self.__str__() + f' cannot find FractalBox {fractal_box_id}')
|
||||
logger.exception(f'{self.__str__()} cannot find FractalBox {fractal_box_id}')
|
||||
raise ValueError
|
||||
|
||||
p1, p2 = uip.check_box_points(p1, p2, self.__str__())
|
||||
@@ -101,25 +101,25 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
xf, yf, zf = p2
|
||||
|
||||
if frac_dim < 0:
|
||||
logger.exception(self.__str__() + ' requires a positive value for the ' +
|
||||
logger.exception(f'{self.__str__()} requires a positive value for the ' +
|
||||
'fractal dimension')
|
||||
raise ValueError
|
||||
if weighting[0] < 0:
|
||||
logger.exception(self.__str__() + ' requires a positive value for the ' +
|
||||
logger.exception(f'{self.__str__()} requires a positive value for the ' +
|
||||
'fractal weighting in the first direction of the surface')
|
||||
raise ValueError
|
||||
if weighting[1] < 0:
|
||||
logger.exception(self.__str__() + ' requires a positive value for the ' +
|
||||
logger.exception(f'{self.__str__()} requires a positive value for the ' +
|
||||
'fractal weighting in the second direction of the surface')
|
||||
raise ValueError
|
||||
|
||||
# Check for valid orientations
|
||||
if xs == xf:
|
||||
if ys == yf or zs == zf:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
if xs != volume.xs and xs != volume.xf:
|
||||
logger.exception(self.__str__() + ' can only be used on the external ' +
|
||||
logger.exception(f'{self.__str__()} can only be used on the external ' +
|
||||
'surfaces of a fractal box')
|
||||
raise ValueError
|
||||
fractalrange = (round_value(limits[0] / grid.dx),
|
||||
@@ -127,7 +127,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
# xminus surface
|
||||
if xs == volume.xs:
|
||||
if fractalrange[0] < 0 or fractalrange[1] > volume.xf:
|
||||
logger.exception(self.__str__() + ' cannot apply fractal surface ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply fractal surface ' +
|
||||
'to fractal box as it would exceed either the ' +
|
||||
'upper coordinates of the fractal box or the ' +
|
||||
'domain in the x direction')
|
||||
@@ -136,7 +136,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
# xplus surface
|
||||
elif xf == volume.xf:
|
||||
if fractalrange[0] < volume.xs or fractalrange[1] > grid.nx:
|
||||
logger.exception(self.__str__() + ' cannot apply fractal surface ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply fractal surface ' +
|
||||
'to fractal box as it would exceed either the ' +
|
||||
'lower coordinates of the fractal box or the ' +
|
||||
'domain in the x direction')
|
||||
@@ -145,10 +145,10 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
|
||||
elif ys == yf:
|
||||
if xs == xf or zs == zf:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
if ys != volume.ys and ys != volume.yf:
|
||||
logger.exception(self.__str__() + ' can only be used on the external ' +
|
||||
logger.exception(f'{self.__str__()} can only be used on the external ' +
|
||||
'surfaces of a fractal box')
|
||||
raise ValueError
|
||||
fractalrange = (round_value(limits[0] / grid.dy),
|
||||
@@ -156,7 +156,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
# yminus surface
|
||||
if ys == volume.ys:
|
||||
if fractalrange[0] < 0 or fractalrange[1] > volume.yf:
|
||||
logger.exception(self.__str__() + ' cannot apply fractal surface ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply fractal surface ' +
|
||||
'to fractal box as it would exceed either the ' +
|
||||
'upper coordinates of the fractal box or the ' +
|
||||
'domain in the y direction')
|
||||
@@ -165,7 +165,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
# yplus surface
|
||||
elif yf == volume.yf:
|
||||
if fractalrange[0] < volume.ys or fractalrange[1] > grid.ny:
|
||||
logger.exception(self.__str__() + ' cannot apply fractal surface ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply fractal surface ' +
|
||||
'to fractal box as it would exceed either the ' +
|
||||
'lower coordinates of the fractal box or the ' +
|
||||
'domain in the y direction')
|
||||
@@ -174,10 +174,10 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
|
||||
elif zs == zf:
|
||||
if xs == xf or ys == yf:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
if zs != volume.zs and zs != volume.zf:
|
||||
logger.exception(self.__str__() + ' can only be used on the external ' +
|
||||
logger.exception(f'{self.__str__()} can only be used on the external ' +
|
||||
'surfaces of a fractal box')
|
||||
raise ValueError
|
||||
fractalrange = (round_value(limits[0] / grid.dz),
|
||||
@@ -185,7 +185,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
# zminus surface
|
||||
if zs == volume.zs:
|
||||
if fractalrange[0] < 0 or fractalrange[1] > volume.zf:
|
||||
logger.exception(self.__str__() + ' cannot apply fractal surface ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply fractal surface ' +
|
||||
'to fractal box as it would exceed either the ' +
|
||||
'upper coordinates of the fractal box or the ' +
|
||||
'domain in the x direction')
|
||||
@@ -194,7 +194,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
# zplus surface
|
||||
elif zf == volume.zf:
|
||||
if fractalrange[0] < volume.zs or fractalrange[1] > grid.nz:
|
||||
logger.exception(self.__str__() + ' cannot apply fractal surface ' +
|
||||
logger.exception(f'{self.__str__()} cannot apply fractal surface ' +
|
||||
'to fractal box as it would exceed either the ' +
|
||||
'lower coordinates of the fractal box or the ' +
|
||||
'domain in the z direction')
|
||||
@@ -202,7 +202,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
requestedsurface = 'zplus'
|
||||
|
||||
else:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
|
||||
surface = FractalSurface(xs, xf, ys, yf, zs, zf, frac_dim)
|
||||
@@ -218,14 +218,14 @@ class AddSurfaceRoughness(UserObjectGeometry):
|
||||
# List of existing surfaces IDs
|
||||
existingsurfaceIDs = [x.surfaceID for x in volume.fractalsurfaces]
|
||||
if surface.surfaceID in existingsurfaceIDs:
|
||||
logger.exception(self.__str__() + f' has already been used on the ' +
|
||||
logger.exception(f'{self.__str__()} has already been used on the ' +
|
||||
f'{surface.surfaceID} surface')
|
||||
raise ValueError
|
||||
|
||||
surface.generate_fractal_surface()
|
||||
volume.fractalsurfaces.append(surface)
|
||||
|
||||
logger.info(self.grid_name(grid) + f'Fractal surface from {xs * grid.dx:g}m, ' +
|
||||
logger.info(f'{self.grid_name(grid)}Fractal surface from {xs * grid.dx:g}m, ' +
|
||||
f'{ys * grid.dy:g}m, {zs * grid.dz:g}m, to {xf * grid.dx:g}m, ' +
|
||||
f'{yf * grid.dy:g}m, {zf * grid.dz:g}m with fractal dimension ' +
|
||||
f'{surface.dimension:g}, fractal weightings {surface.weighting[0]:g}, ' +
|
||||
|
@@ -68,18 +68,16 @@ class AddSurfaceWater(UserObjectGeometry):
|
||||
fractal_box_id = self.kwargs['fractal_box_id']
|
||||
depth = self.kwargs['depth']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' requires exactly eight parameters')
|
||||
logger.exception(f'{self.__str__()} requires exactly eight parameters')
|
||||
raise
|
||||
|
||||
if self.do_rotate:
|
||||
self._do_rotate()
|
||||
|
||||
# Get the correct fractal volume
|
||||
volumes = [volume for volume in grid.fractalvolumes if volume.ID == fractal_box_id]
|
||||
if volumes:
|
||||
if volumes := [volume for volume in grid.fractalvolumes if volume.ID == fractal_box_id]:
|
||||
volume = volumes[0]
|
||||
else:
|
||||
logger.exception(self.__str__() + f' cannot find FractalBox {fractal_box_id}')
|
||||
logger.exception(f'{self.__str__()} cannot find FractalBox {fractal_box_id}')
|
||||
raise ValueError
|
||||
|
||||
p1, p2 = uip.check_box_points(p1, p2, self.__str__())
|
||||
@@ -87,18 +85,18 @@ class AddSurfaceWater(UserObjectGeometry):
|
||||
xf, yf, zf = p2
|
||||
|
||||
if depth <= 0:
|
||||
logger.exception(self.__str__() + ' requires a positive value for ' +
|
||||
'the depth of water')
|
||||
logger.exception(f'{self.__str__()} requires a positive value for the ' +
|
||||
f'depth of water')
|
||||
raise ValueError
|
||||
|
||||
# Check for valid orientations
|
||||
if xs == xf:
|
||||
if ys == yf or zs == zf:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
if xs != volume.xs and xs != volume.xf:
|
||||
logger.exception(self.__str__() + ' can only be used on the ' +
|
||||
'external surfaces of a fractal box')
|
||||
if xs not in [volume.xs, volume.xf]:
|
||||
logger.exception(f'{self.__str__()} can only be used on the external surfaces '
|
||||
f'of a fractal box')
|
||||
raise ValueError
|
||||
# xminus surface
|
||||
if xs == volume.xs:
|
||||
@@ -110,12 +108,12 @@ class AddSurfaceWater(UserObjectGeometry):
|
||||
filldepth = filldepthcells * grid.dx
|
||||
|
||||
elif ys == yf:
|
||||
if xs == xf or zs == zf:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
if zs == zf:
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
if ys != volume.ys and ys != volume.yf:
|
||||
logger.exception(self.__str__() + ' can only be used on the ' +
|
||||
'external surfaces of a fractal box')
|
||||
if ys not in [volume.ys, volume.yf]:
|
||||
logger.exception(f'{self.__str__()} can only be used on the external surfaces ' +
|
||||
f'of a fractal box')
|
||||
raise ValueError
|
||||
# yminus surface
|
||||
if ys == volume.ys:
|
||||
@@ -127,12 +125,9 @@ class AddSurfaceWater(UserObjectGeometry):
|
||||
filldepth = filldepthcells * grid.dy
|
||||
|
||||
elif zs == zf:
|
||||
if xs == xf or ys == yf:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
if zs != volume.zs and zs != volume.zf:
|
||||
logger.exception(self.__str__() + ' can only be used on the ' +
|
||||
'external surfaces of a fractal box')
|
||||
if zs not in [volume.zs, volume.zf]:
|
||||
logger.exception(f'{self.__str__()} can only be used on the external surfaces '
|
||||
f'of a fractal box')
|
||||
raise ValueError
|
||||
# zminus surface
|
||||
if zs == volume.zs:
|
||||
@@ -144,38 +139,35 @@ class AddSurfaceWater(UserObjectGeometry):
|
||||
filldepth = filldepthcells * grid.dz
|
||||
|
||||
else:
|
||||
logger.exception(self.__str__() + ' dimensions are not specified correctly')
|
||||
logger.exception(f'{self.__str__()} dimensions are not specified correctly')
|
||||
raise ValueError
|
||||
|
||||
surface = next((x for x in volume.fractalsurfaces if x.surfaceID == requestedsurface), None)
|
||||
if not surface:
|
||||
logger.exception(self.__str__() + f' specified surface {requestedsurface} ' +
|
||||
'does not have a rough surface applied')
|
||||
logger.exception(f'{self.__str__()} specified surface {requestedsurface} ' +
|
||||
f'does not have a rough surface applied')
|
||||
raise ValueError
|
||||
|
||||
surface.filldepth = filldepthcells
|
||||
|
||||
# Check that requested fill depth falls within range of surface roughness
|
||||
if surface.filldepth < surface.fractalrange[0] or surface.filldepth > surface.fractalrange[1]:
|
||||
logger.exception(self.__str__() + ' requires a value for the depth ' +
|
||||
'of water that lies with the range of the requested ' +
|
||||
'surface roughness')
|
||||
logger.exception(f'{self.__str__()} requires a value for the depth of water that lies with the ' +
|
||||
f'range of the requested surface roughness')
|
||||
raise ValueError
|
||||
|
||||
# Check to see if water has been already defined as a material
|
||||
if not any(x.ID == 'water' for x in grid.materials):
|
||||
if all(x.ID != 'water' for x in grid.materials):
|
||||
create_water(grid)
|
||||
|
||||
# Check if time step for model is suitable for using water
|
||||
water = next((x for x in grid.materials if x.ID == 'water'))
|
||||
testwater = next((x for x in water.tau if x < grid.dt), None)
|
||||
if testwater:
|
||||
logger.exception(self.__str__() + ' requires the time step for the ' +
|
||||
'model to be less than the relaxation time required ' +
|
||||
'to model water.')
|
||||
if testwater := next((x for x in water.tau if x < grid.dt), None):
|
||||
logger.exception(f'{self.__str__()} requires the time step for the model '
|
||||
f'to be less than the relaxation time required to model water.')
|
||||
raise ValueError
|
||||
|
||||
logger.info(self.grid_name(grid) + f'Water on surface from {xs * grid.dx:g}m, ' +
|
||||
logger.info(f'{self.grid_name(grid)}Water on surface from {xs * grid.dx:g}m, ' +
|
||||
f'{ys * grid.dy:g}m, {zs * grid.dz:g}m, to {xf * grid.dx:g}m, ' +
|
||||
f'{yf * grid.dy:g}m, {zf * grid.dz:g}m with depth {filldepth:g}m, ' +
|
||||
f'added to {surface.operatingonID}.')
|
||||
|
@@ -65,7 +65,7 @@ class Box(UserObjectGeometry):
|
||||
p1 = self.kwargs['p1']
|
||||
p2 = self.kwargs['p2']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' Please specify two points.')
|
||||
logger.exception(f'{self.__str__()} Please specify two points.')
|
||||
raise
|
||||
|
||||
if self.do_rotate:
|
||||
@@ -80,7 +80,7 @@ class Box(UserObjectGeometry):
|
||||
try:
|
||||
materialsrequested = self.kwargs['material_ids']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' No materials have been specified')
|
||||
logger.exception(f'{self.__str__()} No materials have been specified')
|
||||
raise
|
||||
|
||||
# Check averaging
|
||||
@@ -103,7 +103,7 @@ class Box(UserObjectGeometry):
|
||||
|
||||
if len(materials) != len(materialsrequested):
|
||||
notfound = [x for x in materialsrequested if x not in materials]
|
||||
logger.exception(self.__str__() + f' material(s) {notfound} do not exist')
|
||||
logger.exception(f'{self.__str__()} material(s) {notfound} do not exist')
|
||||
raise ValueError
|
||||
|
||||
# Isotropic case
|
||||
@@ -144,7 +144,7 @@ class Box(UserObjectGeometry):
|
||||
|
||||
dielectricsmoothing = 'on' if averaging else 'off'
|
||||
|
||||
logger.info(self.grid_name(grid) + f"Box from {p5[0]:g}m, {p5[1]:g}m, " +
|
||||
logger.info(f"{self.grid_name(grid)}Box from {p5[0]:g}m, {p5[1]:g}m, " +
|
||||
f"{p5[2]:g}m, to {p6[0]:g}m, {p6[1]:g}m, {p6[2]:g}m of " +
|
||||
f"material(s) {', '.join(materialsrequested)} created, " +
|
||||
f"dielectric smoothing is {dielectricsmoothing}.")
|
||||
|
@@ -66,6 +66,5 @@ r = template.render(
|
||||
}]
|
||||
)
|
||||
|
||||
f = open('cython/dispersive_updates_test.pyx', 'w')
|
||||
f.write(r)
|
||||
f.close()
|
||||
with open('cython/dispersive_updates_test.pyx', 'w') as f:
|
||||
f.write(r)
|
||||
|
@@ -38,9 +38,9 @@ class UserObjectGeometry:
|
||||
"""Readable string of parameters given to object."""
|
||||
s = ''
|
||||
for _, v in self.kwargs.items():
|
||||
if isinstance(v, tuple) or isinstance(v, list):
|
||||
if isinstance(v, (tuple, list)):
|
||||
v = ' '.join([str(el) for el in v])
|
||||
s += str(v) + ' '
|
||||
s += f'{str(v)} '
|
||||
|
||||
return f'{self.hash}: {s[:-1]}'
|
||||
|
||||
@@ -109,7 +109,7 @@ def rotate_2point_object(pts, axis, angle, origin=None):
|
||||
# Use origin at centre of object if not given
|
||||
if not origin:
|
||||
origin = pts[0,:] + (pts[1,:] - pts[0,:]) / 2
|
||||
|
||||
|
||||
# Check angle value is suitable
|
||||
angle = int(angle)
|
||||
if angle < 0 or angle > 360:
|
||||
@@ -120,7 +120,7 @@ def rotate_2point_object(pts, axis, angle, origin=None):
|
||||
raise ValueError
|
||||
|
||||
# Check axis is valid
|
||||
if axis != 'x' and axis != 'y' and axis != 'z':
|
||||
if axis not in ['x', 'y', 'z']:
|
||||
logger.exception('Axis of rotation must be x, y, or z')
|
||||
raise ValueError
|
||||
|
||||
|
@@ -55,7 +55,7 @@ class Cone(UserObjectGeometry):
|
||||
r1 = self.kwargs['r1']
|
||||
r2 = self.kwargs['r2']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' please specify 2 points and two radii')
|
||||
logger.exception(f'{self.__str__()} please specify 2 points and two radii')
|
||||
raise
|
||||
|
||||
# Check averaging
|
||||
@@ -75,7 +75,7 @@ class Cone(UserObjectGeometry):
|
||||
try:
|
||||
materialsrequested = self.kwargs['material_ids']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' no materials have been specified')
|
||||
logger.exception(f'{self.__str__()} no materials have been specified')
|
||||
raise
|
||||
|
||||
p3 = uip.round_to_grid_static_point(p1)
|
||||
@@ -85,15 +85,15 @@ class Cone(UserObjectGeometry):
|
||||
x2, y2, z2 = uip.round_to_grid(p2)
|
||||
|
||||
if r1 < 0:
|
||||
logger.exception(self.__str__() + f' the radius of the first face {r1:g} should be a positive value.')
|
||||
logger.exception(f'{self.__str__()} the radius of the first face {r1:g} should be a positive value.')
|
||||
raise ValueError
|
||||
|
||||
if r2 < 0:
|
||||
logger.exception(self.__str__() + f' the radius of the second face {r2:g} should be a positive value.')
|
||||
logger.exception(f'{self.__str__()} the radius of the second face {r2:g} should be a positive value.')
|
||||
raise ValueError
|
||||
|
||||
if r1 == 0 and r2 == 0:
|
||||
logger.exception(self.__str__() + f' not both radii can be zero.')
|
||||
logger.exception(f'{self.__str__()} not both radii can be zero.')
|
||||
raise ValueError
|
||||
|
||||
# Look up requested materials in existing list of material instances
|
||||
@@ -101,7 +101,7 @@ class Cone(UserObjectGeometry):
|
||||
|
||||
if len(materials) != len(materialsrequested):
|
||||
notfound = [x for x in materialsrequested if x not in materials]
|
||||
logger.exception(self.__str__() + f' material(s) {notfound} do not exist')
|
||||
logger.exception(f'{self.__str__()} material(s) {notfound} do not exist')
|
||||
raise ValueError
|
||||
|
||||
# Isotropic case
|
||||
@@ -141,7 +141,7 @@ class Cone(UserObjectGeometry):
|
||||
grid.rigidE, grid.rigidH, grid.ID)
|
||||
|
||||
dielectricsmoothing = 'on' if averaging else 'off'
|
||||
logger.info(self.grid_name(grid) + f"Cone with face centres {p3[0]:g}m, " +
|
||||
logger.info(f"{self.grid_name(grid)}Cone with face centres {p3[0]:g}m, " +
|
||||
f"{p3[1]:g}m, {p3[2]:g}m and {p4[0]:g}m, {p4[1]:g}m, {p4[2]:g}m, " +
|
||||
f"with radii {r1:g}m and {r2:g}, of material(s) {', '.join(materialsrequested)} " +
|
||||
f"created, dielectric smoothing is {dielectricsmoothing}.")
|
||||
|
@@ -52,7 +52,7 @@ class Cylinder(UserObjectGeometry):
|
||||
p2 = self.kwargs['p2']
|
||||
r = self.kwargs['r']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' please specify 2 points and a radius')
|
||||
logger.exception(f'{self.__str__()} please specify 2 points and a radius')
|
||||
raise
|
||||
|
||||
# Check averaging
|
||||
@@ -72,7 +72,7 @@ class Cylinder(UserObjectGeometry):
|
||||
try:
|
||||
materialsrequested = self.kwargs['material_ids']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' no materials have been specified')
|
||||
logger.exception(f'{self.__str__()} no materials have been specified')
|
||||
raise
|
||||
|
||||
p3 = uip.round_to_grid_static_point(p1)
|
||||
@@ -82,7 +82,7 @@ class Cylinder(UserObjectGeometry):
|
||||
x2, y2, z2 = uip.round_to_grid(p2)
|
||||
|
||||
if r <= 0:
|
||||
logger.exception(self.__str__() + f' the radius {r:g} should be a positive value.')
|
||||
logger.exception(f'{self.__str__()} the radius {r:g} should be a positive value.')
|
||||
raise ValueError
|
||||
|
||||
# Look up requested materials in existing list of material instances
|
||||
@@ -90,7 +90,7 @@ class Cylinder(UserObjectGeometry):
|
||||
|
||||
if len(materials) != len(materialsrequested):
|
||||
notfound = [x for x in materialsrequested if x not in materials]
|
||||
logger.exception(self.__str__() + f' material(s) {notfound} do not exist')
|
||||
logger.exception(f'{self.__str__()} material(s) {notfound} do not exist')
|
||||
raise ValueError
|
||||
|
||||
# Isotropic case
|
||||
@@ -130,7 +130,7 @@ class Cylinder(UserObjectGeometry):
|
||||
grid.rigidE, grid.rigidH, grid.ID)
|
||||
|
||||
dielectricsmoothing = 'on' if averaging else 'off'
|
||||
logger.info(self.grid_name(grid) + f"Cylinder with face centres {p3[0]:g}m, " +
|
||||
logger.info(f"{self.grid_name(grid)}Cylinder with face centres {p3[0]:g}m, " +
|
||||
f"{p3[1]:g}m, {p3[2]:g}m and {p4[0]:g}m, {p4[1]:g}m, {p4[2]:g}m, " +
|
||||
f"with radius {r:g}m, of material(s) {', '.join(materialsrequested)} " +
|
||||
f"created, dielectric smoothing is {dielectricsmoothing}.")
|
||||
|
@@ -88,24 +88,25 @@ class CylindricalSector(UserObjectGeometry):
|
||||
try:
|
||||
materialsrequested = self.kwargs['material_ids']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' No materials have been specified')
|
||||
logger.exception(f'{self.__str__()} No materials have been specified')
|
||||
raise
|
||||
|
||||
sectorstartangle = 2 * np.pi * (start / 360)
|
||||
sectorangle = 2 * np.pi * (end / 360)
|
||||
|
||||
if normal != 'x' and normal != 'y' and normal != 'z':
|
||||
logger.exception(self.__str__() + ' the normal direction must be either x, y or z.')
|
||||
if normal not in ['x', 'y', 'z']:
|
||||
logger.exception(f'{self.__str__()} the normal direction must be either ' +
|
||||
f'x, y or z.')
|
||||
raise ValueError
|
||||
if r <= 0:
|
||||
logger.exception(self.__str__() + f' the radius {r:g} should be a positive value.')
|
||||
logger.exception(f'{self.__str__()} the radius {r:g} should be a positive value.')
|
||||
if sectorstartangle < 0 or sectorangle <= 0:
|
||||
logger.exception(self.__str__() + ' the starting angle and sector ' +
|
||||
'angle should be a positive values.')
|
||||
logger.exception(f'{self.__str__()} the starting angle and sector angle should be ' +
|
||||
f'a positive values.')
|
||||
raise ValueError
|
||||
if sectorstartangle >= 2 * np.pi or sectorangle >= 2 * np.pi:
|
||||
logger.exception(self.__str__() + ' the starting angle and sector ' +
|
||||
'angle must be less than 360 degrees.')
|
||||
logger.exception(f'{self.__str__()} the starting angle and sector angle must be ' +
|
||||
f'less than 360 degrees.')
|
||||
raise ValueError
|
||||
|
||||
# Look up requested materials in existing list of material instances
|
||||
@@ -113,7 +114,7 @@ class CylindricalSector(UserObjectGeometry):
|
||||
|
||||
if len(materials) != len(materialsrequested):
|
||||
notfound = [x for x in materialsrequested if x not in materials]
|
||||
logger.exception(self.__str__() + f' material(s) {notfound} do not exist')
|
||||
logger.exception(f'{self.__str__()} material(s) {notfound} do not exist')
|
||||
raise ValueError
|
||||
|
||||
if thickness > 0:
|
||||
@@ -122,13 +123,12 @@ class CylindricalSector(UserObjectGeometry):
|
||||
averaging = materials[0].averagable and averagecylindricalsector
|
||||
numID = numIDx = numIDy = numIDz = materials[0].numID
|
||||
|
||||
# Uniaxial anisotropic case
|
||||
elif len(materials) == 3:
|
||||
averaging = False
|
||||
numIDx = materials[0].numID
|
||||
numIDy = materials[1].numID
|
||||
numIDz = materials[2].numID
|
||||
requiredID = materials[0].ID + '+' + materials[1].ID + '+' + materials[2].ID
|
||||
requiredID = f'{materials[0].ID}+{materials[1].ID}+{materials[2].ID}'
|
||||
averagedmaterial = [x for x in grid.materials if x.ID == requiredID]
|
||||
if averagedmaterial:
|
||||
numID = averagedmaterial.numID
|
||||
@@ -181,14 +181,14 @@ class CylindricalSector(UserObjectGeometry):
|
||||
|
||||
if thickness > 0:
|
||||
dielectricsmoothing = 'on' if averaging else 'off'
|
||||
logger.info(self.grid_name(grid) + f"Cylindrical sector with centre " +
|
||||
logger.info(f"{self.grid_name(grid)}Cylindrical sector with centre " +
|
||||
f"{ctr1:g}m, {ctr2:g}m, radius {r:g}m, starting angle " +
|
||||
f"{(sectorstartangle / (2 * np.pi)) * 360:.1f} degrees, " +
|
||||
f"sector angle {(sectorangle / (2 * np.pi)) * 360:.1f} degrees, " +
|
||||
f"thickness {thickness:g}m, of material(s) {', '.join(materialsrequested)} " +
|
||||
f"created, dielectric smoothing is {dielectricsmoothing}.")
|
||||
else:
|
||||
logger.info(self.grid_name(grid) + f"Cylindrical sector with centre " +
|
||||
logger.info(f"{self.grid_name(grid)}Cylindrical sector with centre " +
|
||||
f"{ctr1:g}m, {ctr2:g}m, radius {r:g}m, starting angle " +
|
||||
f"{(sectorstartangle / (2 * np.pi)) * 360:.1f} degrees, " +
|
||||
f"sector angle {(sectorangle / (2 * np.pi)) * 360:.1f} " +
|
||||
|
@@ -62,15 +62,15 @@ class Edge(UserObjectGeometry):
|
||||
p2 = self.kwargs['p2']
|
||||
material_id = self.kwargs['material_id']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' requires exactly 3 parameters')
|
||||
logger.exception(f'{self.__str__()} requires exactly 3 parameters')
|
||||
raise
|
||||
|
||||
if self.do_rotate:
|
||||
self._do_rotate()
|
||||
|
||||
|
||||
p3 = uip.round_to_grid_static_point(p1)
|
||||
p4 = uip.round_to_grid_static_point(p2)
|
||||
|
||||
|
||||
p1, p2 = uip.check_box_points(p1, p2, self.__str__())
|
||||
xs, ys, zs = p1
|
||||
xf, yf, zf = p2
|
||||
@@ -83,32 +83,23 @@ class Edge(UserObjectGeometry):
|
||||
|
||||
# Check for valid orientations
|
||||
# x-orientated edge
|
||||
if xs != xf:
|
||||
if ys != yf or zs != zf:
|
||||
logger.exception(self.__str__() + ' the edge is not specified correctly')
|
||||
raise ValueError
|
||||
else:
|
||||
for i in range(xs, xf):
|
||||
build_edge_x(i, ys, zs, material.numID, grid.rigidE, grid.rigidH, grid.ID)
|
||||
if ((xs != xf and (ys != yf or zs != zf))
|
||||
or (ys != yf and (xs != xf or zs != zf))
|
||||
or (zs != zf and (xs != xf or ys != yf))):
|
||||
logger.exception(f'{self.__str__()} the edge is not specified correctly')
|
||||
raise ValueError
|
||||
elif xs != xf:
|
||||
for i in range(xs, xf):
|
||||
build_edge_x(i, ys, zs, material.numID, grid.rigidE, grid.rigidH, grid.ID)
|
||||
|
||||
# y-orientated edge
|
||||
elif ys != yf:
|
||||
if xs != xf or zs != zf:
|
||||
logger.exception(self.__str__() + ' the edge is not specified correctly')
|
||||
raise ValueError
|
||||
else:
|
||||
for j in range(ys, yf):
|
||||
build_edge_y(xs, j, zs, material.numID, grid.rigidE, grid.rigidH, grid.ID)
|
||||
for j in range(ys, yf):
|
||||
build_edge_y(xs, j, zs, material.numID, grid.rigidE, grid.rigidH, grid.ID)
|
||||
|
||||
# z-orientated edge
|
||||
elif zs != zf:
|
||||
if xs != xf or ys != yf:
|
||||
logger.exception(self.__str__() + ' the edge is not specified correctly')
|
||||
raise ValueError
|
||||
else:
|
||||
for k in range(zs, zf):
|
||||
build_edge_z(xs, ys, k, material.numID, grid.rigidE, grid.rigidH, grid.ID)
|
||||
for k in range(zs, zf):
|
||||
build_edge_z(xs, ys, k, material.numID, grid.rigidE, grid.rigidH, grid.ID)
|
||||
|
||||
logger.info(self.grid_name(grid) + f'Edge from {p3[0]:g}m, {p3[1]:g}m, ' +
|
||||
logger.info(f'{self.grid_name(grid)}Edge from {p3[0]:g}m, {p3[1]:g}m, ' +
|
||||
f'{p3[2]:g}m, to {p4[0]:g}m, {p4[1]:g}m, {p4[2]:g}m of ' +
|
||||
f'material {material_id} created.')
|
||||
|
@@ -53,7 +53,7 @@ class Ellipsoid(UserObjectGeometry):
|
||||
zr = self.kwargs['zr']
|
||||
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' please specify a point and the three semiaxes.')
|
||||
logger.exception(f'{self.__str__()} please specify a point and the three semiaxes.')
|
||||
raise
|
||||
|
||||
# Check averaging
|
||||
@@ -73,7 +73,7 @@ class Ellipsoid(UserObjectGeometry):
|
||||
try:
|
||||
materialsrequested = self.kwargs['material_ids']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' no materials have been specified')
|
||||
logger.exception(f'{self.__str__()} no materials have been specified')
|
||||
raise
|
||||
|
||||
# Centre of sphere
|
||||
@@ -86,7 +86,7 @@ class Ellipsoid(UserObjectGeometry):
|
||||
|
||||
if len(materials) != len(materialsrequested):
|
||||
notfound = [x for x in materialsrequested if x not in materials]
|
||||
logger.exception(self.__str__() + f' material(s) {notfound} do not exist')
|
||||
logger.exception(f'{self.__str__()} material(s) {notfound} do not exist')
|
||||
raise ValueError
|
||||
|
||||
# Isotropic case
|
||||
@@ -126,7 +126,7 @@ class Ellipsoid(UserObjectGeometry):
|
||||
grid.rigidE, grid.rigidH, grid.ID)
|
||||
|
||||
dielectricsmoothing = 'on' if averaging else 'off'
|
||||
logger.info(self.grid_name(grid) + f"Ellipsoid with centre {p2[0]:g}m, " +
|
||||
logger.info(f"{self.grid_name(grid)}Ellipsoid with centre {p2[0]:g}m, " +
|
||||
f"{p2[1]:g}m, {p2[2]:g}m, x-semiaxis {xr:g}m, y-semiaxis {yr:g}m and z-semiaxis {zr:g}m of material(s) " +
|
||||
f"{', '.join(materialsrequested)} created, dielectric " +
|
||||
f"smoothing is {dielectricsmoothing}.")
|
||||
|
@@ -78,13 +78,13 @@ class FractalBox(UserObjectGeometry):
|
||||
mixing_model_id = self.kwargs['mixing_model_id']
|
||||
ID = self.kwargs['id']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' Incorrect parameters')
|
||||
logger.exception(f'{self.__str__()} Incorrect parameters')
|
||||
raise
|
||||
|
||||
try:
|
||||
seed = self.kwargs['seed']
|
||||
except KeyError:
|
||||
logger.warning(self.__str__() + ' no value for seed detected. This ' +
|
||||
logger.warning(f'{self.__str__()} no value for seed detected. This ' +
|
||||
'means you will get a different fractal distribution ' +
|
||||
'every time the model runs.')
|
||||
seed = None
|
||||
@@ -107,24 +107,24 @@ class FractalBox(UserObjectGeometry):
|
||||
p1, p2 = uip.check_box_points(p1, p2, self.__str__())
|
||||
xs, ys, zs = p1
|
||||
xf, yf, zf = p2
|
||||
|
||||
|
||||
if frac_dim < 0:
|
||||
logger.exception(self.__str__() + ' requires a positive value for the ' +
|
||||
logger.exception(f'{self.__str__()} requires a positive value for the ' +
|
||||
'fractal dimension')
|
||||
raise ValueError
|
||||
if weighting[0] < 0:
|
||||
logger.exception(self.__str__() + ' requires a positive value for the ' +
|
||||
logger.exception(f'{self.__str__()} requires a positive value for the ' +
|
||||
'fractal weighting in the x direction')
|
||||
raise ValueError
|
||||
if weighting[1] < 0:
|
||||
logger.exception(self.__str__() + ' requires a positive value for the ' +
|
||||
logger.exception(f'{self.__str__()} requires a positive value for the ' +
|
||||
'fractal weighting in the y direction')
|
||||
raise ValueError
|
||||
if weighting[2] < 0:
|
||||
logger.exception(self.__str__() + ' requires a positive value for the ' +
|
||||
logger.exception(f'{self.__str__()} requires a positive value for the ' +
|
||||
'fractal weighting in the z direction')
|
||||
if n_materials < 0:
|
||||
logger.exception(self.__str__() + ' requires a positive value for the ' +
|
||||
logger.exception(f'{self.__str__()} requires a positive value for the ' +
|
||||
'number of bins')
|
||||
raise ValueError
|
||||
|
||||
@@ -136,14 +136,14 @@ class FractalBox(UserObjectGeometry):
|
||||
|
||||
if mixingmodel:
|
||||
if nbins == 1:
|
||||
logger.exception(self.__str__() + ' must be used with more than ' +
|
||||
logger.exception(f'{self.__str__()} must be used with more than ' +
|
||||
'one material from the mixing model.')
|
||||
raise ValueError
|
||||
# Create materials from mixing model as number of bins now known
|
||||
# from fractal_box command.
|
||||
mixingmodel.calculate_properties(nbins, grid)
|
||||
elif not material:
|
||||
logger.exception(self.__str__() + f' mixing model or material with ' +
|
||||
logger.exception(f'{self.__str__()} mixing model or material with ' +
|
||||
'ID {mixing_model_id} does not exist')
|
||||
raise ValueError
|
||||
|
||||
@@ -160,7 +160,7 @@ class FractalBox(UserObjectGeometry):
|
||||
volume.mixingmodel = mixingmodel
|
||||
|
||||
dielectricsmoothing = 'on' if volume.averaging else 'off'
|
||||
logger.info(self.grid_name(grid) + f'Fractal box {volume.ID} from ' +
|
||||
logger.info(f'{self.grid_name(grid)}Fractal box {volume.ID} from ' +
|
||||
f'{p3[0]:g}m, {p3[1]:g}m, {p3[2]:g}m, to {p4[0]:g}m, ' +
|
||||
f'{p4[1]:g}m, {p4[2]:g}m with {volume.operatingonID}, ' +
|
||||
f'fractal dimension {volume.dimension:g}, fractal weightings ' +
|
||||
|
@@ -319,7 +319,7 @@ class FractalBoxBuilder(UserObjectGeometry):
|
||||
|
||||
else:
|
||||
if volume.nbins == 1:
|
||||
logger.exception(self.__str__() + ' is being used with a ' +
|
||||
logger.exception(f'{self.__str__()} is being used with a ' +
|
||||
'single material and no modifications, ' +
|
||||
'therefore please use a #box command instead.')
|
||||
raise ValueError
|
||||
|
@@ -46,7 +46,7 @@ class GeometryObjectsRead(UserObjectGeometry):
|
||||
geofile = self.kwargs['geofile']
|
||||
matfile = self.kwargs['matfile']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + 'requires exactly five parameters')
|
||||
logger.exception(f'{self.__str__()} requires exactly five parameters')
|
||||
raise
|
||||
|
||||
# Discretise the point using uip object. This has different behaviour
|
||||
@@ -100,7 +100,7 @@ class GeometryObjectsRead(UserObjectGeometry):
|
||||
if round_value((dx_dy_dz[0] / grid.dx) != 1 or
|
||||
round_value(dx_dy_dz[1] / grid.dy) != 1 or
|
||||
round_value(dx_dy_dz[2] / grid.dz) != 1):
|
||||
logger.exception(self.__str__() + ' requires the spatial resolution ' +
|
||||
logger.exception(f'{self.__str__()} requires the spatial resolution ' +
|
||||
'of the geometry objects file to match the spatial ' +
|
||||
'resolution of the model')
|
||||
raise ValueError
|
||||
@@ -122,7 +122,7 @@ class GeometryObjectsRead(UserObjectGeometry):
|
||||
grid.rigidE[:, xs:xs + rigidE.shape[1], ys:ys + rigidE.shape[2], zs:zs + rigidE.shape[3]] = rigidE
|
||||
grid.rigidH[:, xs:xs + rigidH.shape[1], ys:ys + rigidH.shape[2], zs:zs + rigidH.shape[3]] = rigidH
|
||||
grid.ID[:, xs:xs + ID.shape[1], ys:ys + ID.shape[2], zs:zs + ID.shape[3]] = ID + numexistmaterials
|
||||
logger.info(self.grid_name(grid) + f'Geometry objects from file {geofile} ' +
|
||||
logger.info(f'{self.grid_name(grid)}Geometry objects from file {geofile} ' +
|
||||
f'inserted at {xs * grid.dx:g}m, {ys * grid.dy:g}m, ' +
|
||||
f'{zs * grid.dz:g}m, with corresponding materials file ' +
|
||||
f'{matfile}.')
|
||||
@@ -131,7 +131,7 @@ class GeometryObjectsRead(UserObjectGeometry):
|
||||
build_voxels_from_array(xs, ys, zs, config.get_model_config().ompthreads,
|
||||
numexistmaterials, averaging, data,
|
||||
grid.solid, grid.rigidE, grid.rigidH, grid.ID)
|
||||
logger.info(self.grid_name(grid) + f'Geometry objects from file ' +
|
||||
logger.info(f'{self.grid_name(grid)}Geometry objects from file ' +
|
||||
f'(voxels only){geofile} inserted at {xs * grid.dx:g}m, ' +
|
||||
f'{ys * grid.dy:g}m, {zs * grid.dz:g}m, with corresponding ' +
|
||||
f'materials file {matfile}.')
|
||||
|
@@ -61,7 +61,7 @@ class Plate(UserObjectGeometry):
|
||||
p1 = self.kwargs['p1']
|
||||
p2 = self.kwargs['p2']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' 2 points must be specified')
|
||||
logger.exception(f'{self.__str__()} 2 points must be specified')
|
||||
raise
|
||||
|
||||
# isotropic
|
||||
@@ -72,7 +72,7 @@ class Plate(UserObjectGeometry):
|
||||
try:
|
||||
materialsrequested = self.kwargs['material_ids']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' No materials have been specified')
|
||||
logger.exception(f'{self.__str__()} No materials have been specified')
|
||||
raise
|
||||
|
||||
if self.do_rotate:
|
||||
@@ -86,23 +86,10 @@ class Plate(UserObjectGeometry):
|
||||
xf, yf, zf = p2
|
||||
|
||||
# Check for valid orientations
|
||||
if xs == xf:
|
||||
if ys == yf or zs == zf:
|
||||
logger.exception(self.__str__() + ' the plate is not specified correctly')
|
||||
raise ValueError
|
||||
|
||||
elif ys == yf:
|
||||
if xs == xf or zs == zf:
|
||||
logger.exception(self.__str__() + ' the plate is not specified correctly')
|
||||
raise ValueError
|
||||
|
||||
elif zs == zf:
|
||||
if xs == xf or ys == yf:
|
||||
logger.exception(self.__str__() + ' the plate is not specified correctly')
|
||||
raise ValueError
|
||||
|
||||
else:
|
||||
logger.exception(self.__str__() + ' the plate is not specified correctly')
|
||||
if ((xs == xf and (ys == yf or zs == zf))
|
||||
or (ys == yf and (xs == xf or zs == zf))
|
||||
or (zs == zf and (ys != yf and xs != xf))):
|
||||
logger.exception(f'{self.__str__()} the plate is not specified correctly')
|
||||
raise ValueError
|
||||
|
||||
# Look up requested materials in existing list of material instances
|
||||
@@ -110,7 +97,7 @@ class Plate(UserObjectGeometry):
|
||||
|
||||
if len(materials) != len(materialsrequested):
|
||||
notfound = [x for x in materialsrequested if x not in materials]
|
||||
logger.exception(self.__str__() + f' material(s) {notfound} do not exist')
|
||||
logger.exception(f'{self.__str__()} material(s) {notfound} do not exist')
|
||||
raise ValueError
|
||||
|
||||
# yz-plane plate
|
||||
@@ -161,6 +148,6 @@ class Plate(UserObjectGeometry):
|
||||
build_face_xy(i, j, zs, numIDx, numIDy, grid.rigidE,
|
||||
grid.rigidH, grid.ID)
|
||||
|
||||
logger.info(self.grid_name(grid) + f"Plate from {p3[0]:g}m, {p3[1]:g}m, " +
|
||||
logger.info(f"{self.grid_name(grid)}Plate from {p3[0]:g}m, {p3[1]:g}m, " +
|
||||
f"{p3[2]:g}m, to {p4[0]:g}m, {p4[1]:g}m, {p4[2]:g}m of " +
|
||||
f"material(s) {', '.join(materialsrequested)} created.")
|
||||
|
@@ -48,7 +48,7 @@ class Sphere(UserObjectGeometry):
|
||||
p1 = self.kwargs['p1']
|
||||
r = self.kwargs['r']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' please specify a point and a radius.')
|
||||
logger.exception(f'{self.__str__()} please specify a point and a radius.')
|
||||
raise
|
||||
|
||||
# Check averaging
|
||||
@@ -68,7 +68,7 @@ class Sphere(UserObjectGeometry):
|
||||
try:
|
||||
materialsrequested = self.kwargs['material_ids']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' no materials have been specified')
|
||||
logger.exception(f'{self.__str__()} no materials have been specified')
|
||||
raise
|
||||
|
||||
# Centre of sphere
|
||||
@@ -85,7 +85,7 @@ class Sphere(UserObjectGeometry):
|
||||
|
||||
if len(materials) != len(materialsrequested):
|
||||
notfound = [x for x in materialsrequested if x not in materials]
|
||||
logger.exception(self.__str__() + f' material(s) {notfound} do not exist')
|
||||
logger.exception(f'{self.__str__()} material(s) {notfound} do not exist')
|
||||
raise ValueError
|
||||
|
||||
# Isotropic case
|
||||
@@ -125,7 +125,7 @@ class Sphere(UserObjectGeometry):
|
||||
grid.rigidE, grid.rigidH, grid.ID)
|
||||
|
||||
dielectricsmoothing = 'on' if averaging else 'off'
|
||||
logger.info(self.grid_name(grid) + f"Sphere with centre {p2[0]:g}m, " +
|
||||
logger.info(f"{self.grid_name(grid)}Sphere with centre {p2[0]:g}m, " +
|
||||
f"{p2[1]:g}m, {p2[2]:g}m, radius {r:g}m, of material(s) " +
|
||||
f"{', '.join(materialsrequested)} created, dielectric " +
|
||||
f"smoothing is {dielectricsmoothing}.")
|
||||
|
@@ -70,7 +70,7 @@ class Triangle(UserObjectGeometry):
|
||||
up3 = self.kwargs['p3']
|
||||
thickness = self.kwargs['thickness']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' specify 3 points and a thickness')
|
||||
logger.exception(f'{self.__str__()} specify 3 points and a thickness')
|
||||
raise
|
||||
|
||||
if self.do_rotate:
|
||||
@@ -93,7 +93,7 @@ class Triangle(UserObjectGeometry):
|
||||
try:
|
||||
materialsrequested = self.kwargs['material_ids']
|
||||
except KeyError:
|
||||
logger.exception(self.__str__() + ' no materials have been specified')
|
||||
logger.exception(f'{self.__str__()} no materials have been specified')
|
||||
raise
|
||||
|
||||
p4 = uip.round_to_grid_static_point(up1)
|
||||
@@ -108,21 +108,21 @@ class Triangle(UserObjectGeometry):
|
||||
x3, y3, z3 = uip.round_to_grid(up3)
|
||||
|
||||
if thickness < 0:
|
||||
logger.exception(self.__str__() + ' requires a positive value for thickness')
|
||||
logger.exception(f'{self.__str__()} requires a positive value for thickness')
|
||||
raise ValueError
|
||||
|
||||
# Check for valid orientations
|
||||
# yz-plane triangle
|
||||
if x1 == x2 and x2 == x3:
|
||||
if x1 == x2 == x3:
|
||||
normal = 'x'
|
||||
# xz-plane triangle
|
||||
elif y1 == y2 and y2 == y3:
|
||||
elif y1 == y2 == y3:
|
||||
normal = 'y'
|
||||
# xy-plane triangle
|
||||
elif z1 == z2 and z2 == z3:
|
||||
elif z1 == z2 == z3:
|
||||
normal = 'z'
|
||||
else:
|
||||
logger.exception(self.__str__() + ' the triangle is not specified correctly')
|
||||
logger.exception(f'{self.__str__()} the triangle is not specified correctly')
|
||||
raise ValueError
|
||||
|
||||
# Look up requested materials in existing list of material instances
|
||||
@@ -130,7 +130,7 @@ class Triangle(UserObjectGeometry):
|
||||
|
||||
if len(materials) != len(materialsrequested):
|
||||
notfound = [x for x in materialsrequested if x not in materials]
|
||||
logger.exception(self.__str__() + f' material(s) {notfound} do not exist')
|
||||
logger.exception(f'{self.__str__()} material(s) {notfound} do not exist')
|
||||
raise ValueError
|
||||
|
||||
if thickness > 0:
|
||||
@@ -185,13 +185,13 @@ class Triangle(UserObjectGeometry):
|
||||
|
||||
if thickness > 0:
|
||||
dielectricsmoothing = 'on' if averaging else 'off'
|
||||
logger.info(self.grid_name(grid) + f"Triangle with coordinates " +
|
||||
logger.info(f"{self.grid_name(grid)}Triangle with coordinates " +
|
||||
f"{p4[0]:g}m {p4[1]:g}m {p4[2]:g}m, {p5[0]:g}m {p5[1]:g}m " +
|
||||
f"{p5[2]:g}m, {p6[0]:g}m {p6[1]:g}m {p6[2]:g}m and thickness " +
|
||||
f"{thickness:g}m of material(s) {', '.join(materialsrequested)} " +
|
||||
f"created, dielectric smoothing is {dielectricsmoothing}.")
|
||||
else:
|
||||
logger.info(self.grid_name(grid) + f"Triangle with coordinates " +
|
||||
logger.info(f"{self.grid_name(grid)}Triangle with coordinates " +
|
||||
f"{p4[0]:g}m {p4[1]:g}m {p4[2]:g}m, {p5[0]:g}m {p5[1]:g}m " +
|
||||
f"{p5[2]:g}m, {p6[0]:g}m {p6[1]:g}m {p6[2]:g}m of material(s) " +
|
||||
f"{', '.join(materialsrequested)} created.")
|
||||
|
@@ -243,18 +243,15 @@ class VoltageSource(UserObjectMulti):
|
||||
logger.exception(self.params_str() + (' polarisation must be '
|
||||
'x, y, or z.'))
|
||||
raise ValueError
|
||||
if ('2D TMx' in config.get_model_config().mode and
|
||||
(polarisation == 'y' or polarisation == 'z')):
|
||||
if '2D TMx' in config.get_model_config().mode and polarisation in ['y','z',]:
|
||||
logger.exception(self.params_str() + (' polarisation must be x in '
|
||||
'2D TMx mode.'))
|
||||
raise ValueError
|
||||
elif ('2D TMy' in config.get_model_config().mode and
|
||||
(polarisation == 'x' or polarisation == 'z')):
|
||||
elif '2D TMy' in config.get_model_config().mode and polarisation in ['x','z',]:
|
||||
logger.exception(self.params_str() + (' polarisation must be y in '
|
||||
'2D TMy mode.'))
|
||||
raise ValueError
|
||||
elif ('2D TMz' in config.get_model_config().mode and
|
||||
(polarisation == 'x' or polarisation == 'y')):
|
||||
elif '2D TMz' in config.get_model_config().mode and polarisation in ['x','y',]:
|
||||
logger.exception(self.params_str() + (' polarisation must be z in '
|
||||
'2D TMz mode.'))
|
||||
raise ValueError
|
||||
@@ -305,10 +302,7 @@ class VoltageSource(UserObjectMulti):
|
||||
'less.'))
|
||||
raise ValueError
|
||||
v.start = start
|
||||
if stop > grid.timewindow:
|
||||
v.stop = grid.timewindow
|
||||
else:
|
||||
v.stop = stop
|
||||
v.stop = min(stop, grid.timewindow)
|
||||
startstop = (f' start time {v.start:g} secs, finish time '
|
||||
f'{v.stop:g} secs ')
|
||||
except KeyError:
|
||||
@@ -318,7 +312,7 @@ class VoltageSource(UserObjectMulti):
|
||||
|
||||
v.calculate_waveform_values(grid)
|
||||
|
||||
logger.info(self.grid_name(grid) + f'Voltage source with polarity '
|
||||
logger.info(f'{self.grid_name(grid)}Voltage source with polarity '
|
||||
f'{v.polarisation} at {p2[0]:g}m, {p2[1]:g}m, {p2[2]:g}m, '
|
||||
f'resistance {v.resistance:.1f} Ohms,' + startstop +
|
||||
f'using waveform {v.waveformID} created.')
|
||||
@@ -367,8 +361,7 @@ class HertzianDipole(UserObjectMulti):
|
||||
p1 = self.kwargs['p1']
|
||||
waveform_id = self.kwargs['waveform_id']
|
||||
except KeyError:
|
||||
logger.exception(self.params_str() + ' requires at least 3 ' +
|
||||
'parameters.')
|
||||
logger.exception(f'{self.params_str()} requires at least 3 parameters.')
|
||||
raise
|
||||
|
||||
if self.do_rotate:
|
||||
@@ -379,18 +372,15 @@ class HertzianDipole(UserObjectMulti):
|
||||
logger.exception(self.params_str() + (' polarisation must be '
|
||||
'x, y, or z.'))
|
||||
raise ValueError
|
||||
if ('2D TMx' in config.get_model_config().mode and
|
||||
(polarisation == 'y' or polarisation == 'z')):
|
||||
if '2D TMx' in config.get_model_config().mode and polarisation in ['y','z',]:
|
||||
logger.exception(self.params_str() + (' polarisation must be x in '
|
||||
'2D TMx mode.'))
|
||||
raise ValueError
|
||||
elif ('2D TMy' in config.get_model_config().mode and
|
||||
(polarisation == 'x' or polarisation == 'z')):
|
||||
elif '2D TMy' in config.get_model_config().mode and polarisation in ['x','z',]:
|
||||
logger.exception(self.params_str() + (' polarisation must be y in '
|
||||
'2D TMy mode.'))
|
||||
raise ValueError
|
||||
elif ('2D TMz' in config.get_model_config().mode and
|
||||
(polarisation == 'x' or polarisation == 'y')):
|
||||
elif '2D TMz' in config.get_model_config().mode and polarisation in ['x','y',]:
|
||||
logger.exception(self.params_str() + (' polarisation must be z in '
|
||||
'2D TMz mode.'))
|
||||
raise ValueError
|
||||
@@ -401,7 +391,7 @@ class HertzianDipole(UserObjectMulti):
|
||||
|
||||
# Check if there is a waveformID in the waveforms list
|
||||
if not any(x.ID == waveform_id for x in grid.waveforms):
|
||||
logger.exception(self.params_str() + ' there is no waveform ' +
|
||||
logger.exception(f'{self.params_str()} there is no waveform ' +
|
||||
f'with the identifier {waveform_id}.')
|
||||
raise ValueError
|
||||
|
||||
@@ -422,8 +412,7 @@ class HertzianDipole(UserObjectMulti):
|
||||
h.xcoordorigin = xcoord
|
||||
h.ycoordorigin = ycoord
|
||||
h.zcoordorigin = zcoord
|
||||
h.ID = (h.__class__.__name__ + '(' + str(h.xcoord) + ',' +
|
||||
str(h.ycoord) + ',' + str(h.zcoord) + ')')
|
||||
h.ID = f'{h.__class__.__name__}({str(h.xcoord)},{str(h.ycoord)},{str(h.zcoord)})'
|
||||
h.waveformID = waveform_id
|
||||
|
||||
try:
|
||||
@@ -431,25 +420,19 @@ class HertzianDipole(UserObjectMulti):
|
||||
start = self.kwargs['start']
|
||||
stop = self.kwargs['stop']
|
||||
if start < 0:
|
||||
logger.exception(self.params_str() + (' delay of the initiation '
|
||||
'of the source should not '
|
||||
'be less than zero.'))
|
||||
logger.exception(f'{self.params_str()} delay of the initiation of the ' +
|
||||
f'source should not be less than zero.')
|
||||
raise ValueError
|
||||
if stop < 0:
|
||||
logger.exception(self.params_str() + (' time to remove the '
|
||||
'source should not be '
|
||||
'less than zero.'))
|
||||
logger.exception(f'{self.params_str()} time to remove the source ' +
|
||||
f'should not be less than zero.')
|
||||
raise ValueError
|
||||
if stop - start <= 0:
|
||||
logger.exception(self.params_str() + (' duration of the source '
|
||||
'should not be zero or '
|
||||
'less.'))
|
||||
logger.exception(
|
||||
f'{self.params_str()} duration of the source should not be zero or less.')
|
||||
raise ValueError
|
||||
h.start = start
|
||||
if stop > grid.timewindow:
|
||||
h.stop = grid.timewindow
|
||||
else:
|
||||
h.stop = stop
|
||||
h.stop = min(stop, grid.timewindow)
|
||||
startstop = (f' start time {h.start:g} secs, finish time '
|
||||
f'{h.stop:g} secs ')
|
||||
except KeyError:
|
||||
@@ -460,12 +443,12 @@ class HertzianDipole(UserObjectMulti):
|
||||
h.calculate_waveform_values(grid)
|
||||
|
||||
if config.get_model_config().mode == '2D':
|
||||
logger.info(self.grid_name(grid) + f'Hertzian dipole is a line ' +
|
||||
logger.info(f'{self.grid_name(grid)}Hertzian dipole is a line ' +
|
||||
f'source in 2D with polarity {h.polarisation} at ' +
|
||||
f'{p2[0]:g}m, {p2[1]:g}m, {p2[2]:g}m,' + startstop +
|
||||
f'using waveform {h.waveformID} created.')
|
||||
else:
|
||||
logger.info(self.grid_name(grid) + f'Hertzian dipole with ' +
|
||||
logger.info(f'{self.grid_name(grid)}Hertzian dipole with ' +
|
||||
f'polarity {h.polarisation} at {p2[0]:g}m, ' +
|
||||
f'{p2[1]:g}m, {p2[2]:g}m,' + startstop +
|
||||
f'using waveform {h.waveformID} created.')
|
||||
@@ -514,8 +497,7 @@ class MagneticDipole(UserObjectMulti):
|
||||
p1 = self.kwargs['p1']
|
||||
waveform_id = self.kwargs['waveform_id']
|
||||
except KeyError:
|
||||
logger.exception(self.params_str() + ' requires at least five '
|
||||
'parameters.')
|
||||
logger.exception(f'{self.params_str()} requires at least five parameters.')
|
||||
raise
|
||||
|
||||
if self.do_rotate:
|
||||
@@ -526,18 +508,15 @@ class MagneticDipole(UserObjectMulti):
|
||||
logger.exception(self.params_str() + (' polarisation must be '
|
||||
'x, y, or z.'))
|
||||
raise ValueError
|
||||
if ('2D TMx' in config.get_model_config().mode and
|
||||
(polarisation == 'y' or polarisation == 'z')):
|
||||
if '2D TMx' in config.get_model_config().mode and polarisation in ['y','z',]:
|
||||
logger.exception(self.params_str() + (' polarisation must be x in '
|
||||
'2D TMx mode.'))
|
||||
raise ValueError
|
||||
elif ('2D TMy' in config.get_model_config().mode and
|
||||
(polarisation == 'x' or polarisation == 'z')):
|
||||
elif '2D TMy' in config.get_model_config().mode and polarisation in ['x','z',]:
|
||||
logger.exception(self.params_str() + (' polarisation must be y in '
|
||||
'2D TMy mode.'))
|
||||
raise ValueError
|
||||
elif ('2D TMz' in config.get_model_config().mode and
|
||||
(polarisation == 'x' or polarisation == 'y')):
|
||||
elif '2D TMz' in config.get_model_config().mode and polarisation in ['x','y',]:
|
||||
logger.exception(self.params_str() + (' polarisation must be z in '
|
||||
'2D TMz mode.'))
|
||||
raise ValueError
|
||||
@@ -548,7 +527,7 @@ class MagneticDipole(UserObjectMulti):
|
||||
|
||||
# Check if there is a waveformID in the waveforms list
|
||||
if not any(x.ID == waveform_id for x in grid.waveforms):
|
||||
logger.exception(self.params_str() + ' there is no waveform ' +
|
||||
logger.exception(f'{self.params_str()} there is no waveform ' +
|
||||
f'with the identifier {waveform_id}.')
|
||||
raise ValueError
|
||||
|
||||
@@ -584,10 +563,7 @@ class MagneticDipole(UserObjectMulti):
|
||||
'less.'))
|
||||
raise ValueError
|
||||
m.start = start
|
||||
if stop > grid.timewindow:
|
||||
m.stop = grid.timewindow
|
||||
else:
|
||||
m.stop = stop
|
||||
m.stop = min(stop, grid.timewindow)
|
||||
startstop = (f' start time {m.start:g} secs, '
|
||||
f'finish time {m.stop:g} secs ')
|
||||
except KeyError:
|
||||
@@ -597,7 +573,7 @@ class MagneticDipole(UserObjectMulti):
|
||||
|
||||
m.calculate_waveform_values(grid)
|
||||
|
||||
logger.info(self.grid_name(grid) + f'Magnetic dipole with polarity ' +
|
||||
logger.info(f'{self.grid_name(grid)}Magnetic dipole with polarity ' +
|
||||
f'{m.polarisation} at {p2[0]:g}m, {p2[1]:g}m, {p2[2]:g}m,' +
|
||||
startstop + f'using waveform {m.waveformID} created.')
|
||||
|
||||
@@ -647,17 +623,15 @@ class TransmissionLine(UserObjectMulti):
|
||||
waveform_id = self.kwargs['waveform_id']
|
||||
resistance = self.kwargs['resistance']
|
||||
except KeyError:
|
||||
logger.exception(self.params_str() + ' requires at least six '
|
||||
'parameters.')
|
||||
logger.exception(f'{self.params_str()} requires at least six parameters.')
|
||||
raise
|
||||
|
||||
if self.do_rotate:
|
||||
self._do_rotate(grid)
|
||||
|
||||
# Warn about using a transmission line on GPU
|
||||
if (config.sim_config.general['solver'] == 'cuda' or
|
||||
config.sim_config.general['solver'] == 'opencl'):
|
||||
logger.exception(self.params_str() + ' cannot currently be used ' +
|
||||
if (config.sim_config.general['solver'] in ['cuda', 'opencl']):
|
||||
logger.exception(f'{self.params_str()} cannot currently be used ' +
|
||||
'with the CUDA or OpenCL-based solver. Consider ' +
|
||||
'using a #voltage_source instead.')
|
||||
raise ValueError
|
||||
@@ -667,18 +641,15 @@ class TransmissionLine(UserObjectMulti):
|
||||
logger.exception(self.params_str() + (' polarisation must be '
|
||||
'x, y, or z.'))
|
||||
raise ValueError
|
||||
if ('2D TMx' in config.get_model_config().mode and
|
||||
(polarisation == 'y' or polarisation == 'z')):
|
||||
if '2D TMx' in config.get_model_config().mode and polarisation in ['y','z',]:
|
||||
logger.exception(self.params_str() + (' polarisation must be x in '
|
||||
'2D TMx mode.'))
|
||||
raise ValueError
|
||||
elif ('2D TMy' in config.get_model_config().mode and
|
||||
(polarisation == 'x' or polarisation == 'z')):
|
||||
elif '2D TMy' in config.get_model_config().mode and polarisation in ['x','z',]:
|
||||
logger.exception(self.params_str() + (' polarisation must be y in '
|
||||
'2D TMy mode.'))
|
||||
raise ValueError
|
||||
elif ('2D TMz' in config.get_model_config().mode and
|
||||
(polarisation == 'x' or polarisation == 'y')):
|
||||
elif '2D TMz' in config.get_model_config().mode and polarisation in ['x','y',]:
|
||||
logger.exception(self.params_str() + (' polarisation must be z in '
|
||||
'2D TMz mode.'))
|
||||
raise ValueError
|
||||
@@ -688,14 +659,14 @@ class TransmissionLine(UserObjectMulti):
|
||||
|
||||
|
||||
if resistance <= 0 or resistance >= config.sim_config.em_consts['z0']:
|
||||
logger.exception(self.params_str() + ' requires a resistance ' +
|
||||
logger.exception(f'{self.params_str()} requires a resistance ' +
|
||||
'greater than zero and less than the impedance ' +
|
||||
'of free space, i.e. 376.73 Ohms.')
|
||||
raise ValueError
|
||||
|
||||
# Check if there is a waveformID in the waveforms list
|
||||
if not any(x.ID == waveform_id for x in grid.waveforms):
|
||||
logger.exception(self.params_str() + ' there is no waveform ' +
|
||||
logger.exception(f'{self.params_str()} there is no waveform ' +
|
||||
f'with the identifier {waveform_id}.')
|
||||
raise ValueError
|
||||
|
||||
@@ -729,11 +700,8 @@ class TransmissionLine(UserObjectMulti):
|
||||
'less.'))
|
||||
raise ValueError
|
||||
t.start = start
|
||||
if stop > grid.timewindow:
|
||||
t.stop = grid.timewindow
|
||||
else:
|
||||
t.stop = stop
|
||||
startstop = (f' start time {t.start:g} secs, finish time '
|
||||
t.stop = min(stop, grid.timewindow)
|
||||
startstop = (f' start time {t.start:g} secs, finish time ' +
|
||||
f'{t.stop:g} secs ')
|
||||
except KeyError:
|
||||
t.start = 0
|
||||
@@ -743,7 +711,7 @@ class TransmissionLine(UserObjectMulti):
|
||||
t.calculate_waveform_values(grid)
|
||||
t.calculate_incident_V_I(grid)
|
||||
|
||||
logger.info(self.grid_name(grid) + f'Transmission line with polarity ' +
|
||||
logger.info(f'{self.grid_name(grid)}Transmission line with polarity ' +
|
||||
f'{t.polarisation} at {p2[0]:g}m, {p2[1]:g}m, ' +
|
||||
f'{p2[2]:g}m, resistance {t.resistance:.1f} Ohms,' +
|
||||
startstop + f'using waveform {t.waveformID} created.')
|
||||
@@ -869,8 +837,7 @@ class RxArray(UserObjectMulti):
|
||||
p2 = self.kwargs['p2']
|
||||
dl = self.kwargs['dl']
|
||||
except KeyError:
|
||||
logger.exception(self.params_str() + ' requires exactly 9 '
|
||||
'parameters')
|
||||
logger.exception(f'{self.params_str()} requires exactly 9 parameters')
|
||||
raise
|
||||
|
||||
xs, ys, zs = uip.check_src_rx_point(p1, self.params_str(), 'lower')
|
||||
@@ -880,32 +847,32 @@ class RxArray(UserObjectMulti):
|
||||
dx, dy, dz = uip.discretise_point(dl)
|
||||
|
||||
if xs > xf or ys > yf or zs > zf:
|
||||
logger.exception(self.params_str() + ' the lower coordinates '
|
||||
logger.exception(f'{self.params_str()} the lower coordinates ' +
|
||||
'should be less than the upper coordinates.')
|
||||
raise ValueError
|
||||
if dx < 0 or dy < 0 or dz < 0:
|
||||
logger.exception(self.params_str() + ' the step size should not '
|
||||
logger.exception(f'{self.params_str()} the step size should not ' +
|
||||
'be less than zero.')
|
||||
raise ValueError
|
||||
if dx < 1:
|
||||
if dx == 0:
|
||||
dx = 1
|
||||
else:
|
||||
logger.exception(self.params_str() + ' the step size should '
|
||||
logger.exception(f'{self.params_str()} the step size should ' +
|
||||
'not be less than the spatial discretisation.')
|
||||
raise ValueError
|
||||
if dy < 1:
|
||||
if dy == 0:
|
||||
dy = 1
|
||||
else:
|
||||
logger.exception(self.params_str() + ' the step size should '
|
||||
logger.exception(f'{self.params_str()} the step size should ' +
|
||||
'not be less than the spatial discretisation.')
|
||||
raise ValueError
|
||||
if dz < 1:
|
||||
if dz == 0:
|
||||
dz = 1
|
||||
else:
|
||||
logger.exception(self.params_str() + ' the step size should '
|
||||
logger.exception(f'{self.params_str()} the step size should ' +
|
||||
'not be less than the spatial discretisation.')
|
||||
raise ValueError
|
||||
|
||||
@@ -965,8 +932,7 @@ class Snapshot(UserObjectMulti):
|
||||
|
||||
def create(self, grid, uip):
|
||||
if isinstance(grid, SubGridBaseGrid):
|
||||
logger.exception(self.params_str() + ' do not add snapshots to '
|
||||
'subgrids.')
|
||||
logger.exception(f'{self.params_str()} do not add snapshots to subgrids.')
|
||||
raise ValueError
|
||||
try:
|
||||
p1 = self.kwargs['p1']
|
||||
@@ -974,8 +940,7 @@ class Snapshot(UserObjectMulti):
|
||||
dl = self.kwargs['dl']
|
||||
filename = self.kwargs['filename']
|
||||
except KeyError:
|
||||
logger.exception(self.params_str() + ' requires exactly 11 '
|
||||
'parameters.')
|
||||
logger.exception(f'{self.params_str()} requires exactly 11 parameters.')
|
||||
raise
|
||||
|
||||
try:
|
||||
@@ -998,13 +963,12 @@ class Snapshot(UserObjectMulti):
|
||||
try:
|
||||
time = self.kwargs['time']
|
||||
except KeyError:
|
||||
logger.exception(self.params_str() + ' requires exactly 5 '
|
||||
'parameters.')
|
||||
logger.exception(f'{self.params_str()} requires exactly 5 parameters.')
|
||||
raise
|
||||
if time > 0:
|
||||
iterations = round_value((time / grid.dt)) + 1
|
||||
else:
|
||||
logger.exception(self.params_str() + ' time value must be '
|
||||
logger.exception(f'{self.params_str()} time value must be ' +
|
||||
'greater than zero.')
|
||||
raise ValueError
|
||||
|
||||
@@ -1036,11 +1000,11 @@ class Snapshot(UserObjectMulti):
|
||||
outputs = dict.fromkeys(SnapshotUser.allowableoutputs, True)
|
||||
|
||||
if dx < 0 or dy < 0 or dz < 0:
|
||||
logger.exception(self.params_str() + ' the step size should not '
|
||||
logger.exception(f'{self.params_str()} the step size should not ' +
|
||||
'be less than zero.')
|
||||
raise ValueError
|
||||
if dx < 1 or dy < 1 or dz < 1:
|
||||
logger.exception(self.params_str() + ' the step size should not '
|
||||
logger.exception(f'{self.params_str()} the step size should not ' +
|
||||
'be less than the spatial discretisation.')
|
||||
raise ValueError
|
||||
if iterations <= 0 or iterations > grid.iterations:
|
||||
@@ -1085,32 +1049,31 @@ class Material(UserObjectMulti):
|
||||
sm = self.kwargs['sm']
|
||||
material_id = self.kwargs['id']
|
||||
except KeyError:
|
||||
logger.exception(f'{self.params_str()} requires exactly five '
|
||||
f'parameters.')
|
||||
logger.exception(f'{self.params_str()} requires exactly five parameters.')
|
||||
raise
|
||||
|
||||
if er < 1:
|
||||
logger.exception(f'{self.params_str()} requires a positive value of '
|
||||
logger.exception(f'{self.params_str()} requires a positive value of ' +
|
||||
f'one or greater for static (DC) permittivity.')
|
||||
raise ValueError
|
||||
if se != 'inf':
|
||||
se = float(se)
|
||||
if se < 0:
|
||||
logger.exception(f'{self.params_str()} requires a positive '
|
||||
logger.exception(f'{self.params_str()} requires a positive ' +
|
||||
f'value for electric conductivity.')
|
||||
raise ValueError
|
||||
else:
|
||||
se = float('inf')
|
||||
if mr < 1:
|
||||
logger.exception(f'{self.params_str()} requires a positive value of '
|
||||
logger.exception(f'{self.params_str()} requires a positive value of ' +
|
||||
f'one or greater for magnetic permeability.')
|
||||
raise ValueError
|
||||
if sm < 0:
|
||||
logger.exception(f'{self.params_str()} requires a positive value '
|
||||
logger.exception(f'{self.params_str()} requires a positive value ' +
|
||||
f'for magnetic loss.')
|
||||
raise ValueError
|
||||
if any(x.ID == material_id for x in grid.materials):
|
||||
logger.exception(f'{self.params_str()} with ID {material_id} '
|
||||
logger.exception(f'{self.params_str()} with ID {material_id} ' +
|
||||
f'already exists')
|
||||
raise ValueError
|
||||
|
||||
@@ -1159,12 +1122,11 @@ class AddDebyeDispersion(UserObjectMulti):
|
||||
tau = self.kwargs['tau']
|
||||
material_ids = self.kwargs['material_ids']
|
||||
except KeyError:
|
||||
logger.exception(self.params_str() + ' requires at least four '
|
||||
'parameters.')
|
||||
logger.exception(f'{self.params_str()} requires at least four parameters.')
|
||||
raise
|
||||
|
||||
if poles < 0:
|
||||
logger.exception(self.params_str() + ' requires a positive value '
|
||||
logger.exception(f'{self.params_str()} requires a positive value ' +
|
||||
'for number of poles.')
|
||||
raise ValueError
|
||||
|
||||
@@ -1192,7 +1154,7 @@ class AddDebyeDispersion(UserObjectMulti):
|
||||
disp_material.deltaer.append(er_delta[i])
|
||||
disp_material.tau.append(tau[i])
|
||||
else:
|
||||
logger.exception(self.params_str() + ' requires positive '
|
||||
logger.exception(f'{self.params_str()} requires positive ' +
|
||||
'values for the permittivity difference.')
|
||||
raise ValueError
|
||||
if disp_material.poles > config.get_model_config().materials['maxpoles']:
|
||||
@@ -1234,12 +1196,11 @@ class AddLorentzDispersion(UserObjectMulti):
|
||||
delta = self.kwargs['delta']
|
||||
material_ids = self.kwargs['material_ids']
|
||||
except KeyError:
|
||||
logger.exception(self.params_str() + ' requires at least five '
|
||||
'parameters.')
|
||||
logger.exception(f'{self.params_str()} requires at least five parameters.')
|
||||
raise
|
||||
|
||||
if poles < 0:
|
||||
logger.exception(self.params_str() + ' requires a positive value '
|
||||
logger.exception(f'{self.params_str()} requires a positive value ' +
|
||||
'for number of poles.')
|
||||
raise ValueError
|
||||
|
||||
@@ -1266,7 +1227,7 @@ class AddLorentzDispersion(UserObjectMulti):
|
||||
disp_material.tau.append(omega[i])
|
||||
disp_material.alpha.append(delta[i])
|
||||
else:
|
||||
logger.exception(self.params_str() + ' requires positive '
|
||||
logger.exception(f'{self.params_str()} requires positive '
|
||||
'values for the permittivity difference '
|
||||
'and frequencies, and associated times '
|
||||
'that are greater than the time step for '
|
||||
@@ -1279,9 +1240,9 @@ class AddLorentzDispersion(UserObjectMulti):
|
||||
grid.materials = [disp_material if mat.numID==material.numID else mat for mat in grid.materials]
|
||||
|
||||
logger.info(
|
||||
f"{self.grid_name(grid)}Lorentz disperion added to {disp_material.ID} "
|
||||
f"with delta_eps_r={', '.join('%4.2f' % deltaer for deltaer in disp_material.deltaer)}, "
|
||||
f"omega={', '.join('%4.3e' % omega for omega in disp_material.tau)} secs, "
|
||||
f"{self.grid_name(grid)}Lorentz disperion added to {disp_material.ID} " +
|
||||
f"with delta_eps_r={', '.join('%4.2f' % deltaer for deltaer in disp_material.deltaer)}, " +
|
||||
f"omega={', '.join('%4.3e' % omega for omega in disp_material.tau)} secs, " +
|
||||
f"and gamma={', '.join('%4.3e' % delta for delta in disp_material.alpha)} created.")
|
||||
|
||||
|
||||
@@ -1309,12 +1270,12 @@ class AddDrudeDispersion(UserObjectMulti):
|
||||
alpha = self.kwargs['alpha']
|
||||
material_ids = self.kwargs['material_ids']
|
||||
except KeyError:
|
||||
logger.exception(self.params_str() + ' requires at least four '
|
||||
logger.exception(f'{self.params_str()} requires at least four ' +
|
||||
'parameters.')
|
||||
raise
|
||||
|
||||
if poles < 0:
|
||||
logger.exception(self.params_str() + ' requires a positive value '
|
||||
logger.exception(f'{self.params_str()} requires a positive value ' +
|
||||
'for number of poles.')
|
||||
raise ValueError
|
||||
|
||||
@@ -1340,9 +1301,9 @@ class AddDrudeDispersion(UserObjectMulti):
|
||||
disp_material.tau.append(omega[i])
|
||||
disp_material.alpha.append(alpha[i])
|
||||
else:
|
||||
logger.exception(self.params_str() + ' requires positive '
|
||||
'values for the frequencies, and '
|
||||
'associated times that are greater than '
|
||||
logger.exception(f'{self.params_str()} requires positive ' +
|
||||
'values for the frequencies, and ' +
|
||||
'associated times that are greater than ' +
|
||||
'the time step for the model.')
|
||||
raise ValueError
|
||||
if disp_material.poles > config.get_model_config().materials['maxpoles']:
|
||||
@@ -1388,33 +1349,33 @@ class SoilPeplinski(UserObjectMulti):
|
||||
water_fraction_upper = self.kwargs['water_fraction_upper']
|
||||
ID = self.kwargs['id']
|
||||
except KeyError:
|
||||
logger.exception(self.params_str() + ' requires at exactly seven '
|
||||
logger.exception(f'{self.params_str()} requires at exactly seven ' +
|
||||
'parameters.')
|
||||
raise
|
||||
|
||||
if sand_fraction < 0:
|
||||
logger.exception(self.params_str() + ' requires a positive value '
|
||||
logger.exception(f'{self.params_str()} requires a positive value ' +
|
||||
'for the sand fraction.')
|
||||
raise ValueError
|
||||
if clay_fraction < 0:
|
||||
logger.exception(self.params_str() + ' requires a positive value '
|
||||
logger.exception(f'{self.params_str()} requires a positive value ' +
|
||||
'for the clay fraction.')
|
||||
raise ValueError
|
||||
if bulk_density < 0:
|
||||
logger.exception(self.params_str() + ' requires a positive value '
|
||||
logger.exception(f'{self.params_str()} requires a positive value ' +
|
||||
'for the bulk density.')
|
||||
raise ValueError
|
||||
if sand_density < 0:
|
||||
logger.exception(self.params_str() + ' requires a positive value '
|
||||
logger.exception(f'{self.params_str()} requires a positive value ' +
|
||||
'for the sand particle density.')
|
||||
raise ValueError
|
||||
if water_fraction_lower < 0:
|
||||
logger.exception(self.params_str() + ' requires a positive value '
|
||||
logger.exception(f'{self.params_str()} requires a positive value ' +
|
||||
'for the lower limit of the water volumetric '
|
||||
'fraction.')
|
||||
raise ValueError
|
||||
if water_fraction_upper < 0:
|
||||
logger.exception(self.params_str() + ' requires a positive value '
|
||||
logger.exception(f'{self.params_str()} requires a positive value ' +
|
||||
'for the upper limit of the water volumetric '
|
||||
'fraction.')
|
||||
raise ValueError
|
||||
@@ -1427,10 +1388,10 @@ class SoilPeplinski(UserObjectMulti):
|
||||
s = PeplinskiSoilUser(ID, sand_fraction, clay_fraction, bulk_density,
|
||||
sand_density, (water_fraction_lower, water_fraction_upper))
|
||||
|
||||
logger.info(self.grid_name(grid) + 'Mixing model (Peplinski) used to '
|
||||
f'create {s.ID} with sand fraction {s.S:g}, clay fraction '
|
||||
f'{s.C:g}, bulk density {s.rb:g}g/cm3, sand particle '
|
||||
f'density {s.rs:g}g/cm3, and water volumetric fraction '
|
||||
logger.info(f'{self.grid_name(grid)}Mixing model (Peplinski) used to ' +
|
||||
f'create {s.ID} with sand fraction {s.S:g}, clay fraction ' +
|
||||
f'{s.C:g}, bulk density {s.rb:g}g/cm3, sand particle ' +
|
||||
f'density {s.rs:g}g/cm3, and water volumetric fraction ' +
|
||||
f'{s.mu[0]:g} to {s.mu[1]:g} created.')
|
||||
|
||||
grid.mixingmodels.append(s)
|
||||
@@ -1470,47 +1431,47 @@ class MaterialRange(UserObjectMulti):
|
||||
ro_upper = self.kwargs['ro_upper']
|
||||
ID = self.kwargs['id']
|
||||
except KeyError:
|
||||
logger.exception(self.params_str() + ' requires at exactly nine '
|
||||
logger.exception(f'{self.params_str()} requires at exactly nine ' +
|
||||
'parameters.')
|
||||
raise
|
||||
|
||||
if er_lower < 1:
|
||||
logger.exception(self.params_str() + ' requires a value greater or equal to 1 '
|
||||
logger.exception(f'{self.params_str()} requires a value greater or equal to 1 ' +
|
||||
'for the lower range of relative permittivity.')
|
||||
raise ValueError
|
||||
if mr_lower < 1:
|
||||
logger.exception(self.params_str() + ' requires a value greater or equal to 1 '
|
||||
logger.exception(f'{self.params_str()} requires a value greater or equal to 1 ' +
|
||||
'for the lower range of relative magnetic permeability.')
|
||||
raise ValueError
|
||||
if sigma_lower < 0:
|
||||
logger.exception(self.params_str() + ' requires a positive value '
|
||||
logger.exception(f'{self.params_str()} requires a positive value ' +
|
||||
'for the lower limit of conductivity.')
|
||||
raise ValueError
|
||||
if ro_lower < 0:
|
||||
logger.exception(self.params_str() + ' requires a positive value '
|
||||
logger.exception(f'{self.params_str()} requires a positive value ' +
|
||||
'for the lower range magnetic loss.')
|
||||
raise ValueError
|
||||
if er_upper < 1:
|
||||
logger.exception(self.params_str() + ' requires a value greater or equal to 1'
|
||||
logger.exception(f'{self.params_str()} requires a value greater or equal to 1' +
|
||||
'for the upper range of relative permittivity.')
|
||||
raise ValueError
|
||||
|
||||
|
||||
if mr_upper < 1:
|
||||
logger.exception(self.params_str() + ' requires a value greater or equal to 1'
|
||||
logger.exception(f'{self.params_str()} requires a value greater or equal to 1' +
|
||||
'for the upper range of relative magnetic permeability')
|
||||
raise ValueError
|
||||
|
||||
|
||||
if sigma_upper < 0:
|
||||
logger.exception(self.params_str() + ' requires a positive value '
|
||||
logger.exception(f'{self.params_str()} requires a positive value ' +
|
||||
'for the upper range of conductivity.')
|
||||
raise ValueError
|
||||
if ro_upper < 0:
|
||||
logger.exception(self.params_str() + ' requires a positive value '
|
||||
logger.exception(f'{self.params_str()} requires a positive value ' +
|
||||
'for the upper range of magnetic loss.')
|
||||
|
||||
|
||||
|
||||
if any(x.ID == ID for x in grid.mixingmodels):
|
||||
logger.exception(self.params_str() + f' with ID {ID} already exists')
|
||||
logger.exception(f'{self.params_str()} with ID {ID} already exists')
|
||||
raise ValueError
|
||||
|
||||
# Create a new instance of the Material class material
|
||||
@@ -1518,11 +1479,11 @@ class MaterialRange(UserObjectMulti):
|
||||
s = RangeMaterialUser(ID, (er_lower, er_upper), (sigma_lower, sigma_upper),
|
||||
(mr_lower, mr_upper), (ro_lower, ro_upper))
|
||||
|
||||
logger.info(self.grid_name(grid) + 'Material properties used to '
|
||||
f'create {s.ID} with range(s) {s.er[0]:g} to {s.er[1]:g}, relative permittivity '
|
||||
f'{s.sig[0]:g} to {s.sig[1]:g}, S/m conductivity, {s.mu[0]:g} to {s.mu[1]:g} relative magnetic permeability '
|
||||
logger.info(f'{self.grid_name(grid)}Material properties used to ' +
|
||||
f'create {s.ID} with range(s) {s.er[0]:g} to {s.er[1]:g}, relative permittivity ' +
|
||||
f'{s.sig[0]:g} to {s.sig[1]:g}, S/m conductivity, {s.mu[0]:g} to {s.mu[1]:g} relative magnetic permeability ' +
|
||||
f'{s.ro[0]:g} to {s.ro[1]:g} Ohm/m magnetic loss, created')
|
||||
|
||||
|
||||
|
||||
grid.mixingmodels.append(s)
|
||||
|
||||
@@ -1547,21 +1508,21 @@ class MaterialList(UserObjectMulti):
|
||||
list_of_materials = self.kwargs['list_of_materials']
|
||||
ID = self.kwargs['id']
|
||||
except KeyError:
|
||||
logger.exception(self.params_str() + ' requires at at least 2 '
|
||||
logger.exception(f'{self.params_str()} requires at at least 2 ' +
|
||||
'parameters.')
|
||||
raise
|
||||
|
||||
|
||||
if any(x.ID == ID for x in grid.mixingmodels):
|
||||
logger.exception(self.params_str() + f' with ID {ID} already exists')
|
||||
logger.exception(f'{self.params_str()} with ID {ID} already exists')
|
||||
raise ValueError
|
||||
|
||||
# Create a new instance of the Material class material
|
||||
# (start index after pec & free_space)
|
||||
s = ListMaterialUser(ID, list_of_materials)
|
||||
|
||||
logger.info(self.grid_name(grid) + 'A list of materials used to '
|
||||
logger.info(f'{self.grid_name(grid)}A list of materials used to ' +
|
||||
f'create {s.ID} that includes {s.mat}, created')
|
||||
|
||||
|
||||
|
||||
grid.mixingmodels.append(s)
|
||||
|
||||
@@ -1608,7 +1569,7 @@ class GeometryView(UserObjectMulti):
|
||||
output_type = self.kwargs['output_type'].lower()
|
||||
filename = self.kwargs['filename']
|
||||
except KeyError:
|
||||
logger.exception(self.params_str() + ' requires exactly eleven '
|
||||
logger.exception(f'{self.params_str()} requires exactly eleven ' +
|
||||
'parameters.')
|
||||
raise
|
||||
|
||||
@@ -1627,36 +1588,36 @@ class GeometryView(UserObjectMulti):
|
||||
dx, dy, dz = uip.discretise_static_point(dl)
|
||||
|
||||
if dx < 0 or dy < 0 or dz < 0:
|
||||
logger.exception(self.params_str() + ' the step size should not be '
|
||||
logger.exception(f'{self.params_str()} the step size should not be ' +
|
||||
'less than zero.')
|
||||
raise ValueError
|
||||
if dx > grid.nx or dy > grid.ny or dz > grid.nz:
|
||||
logger.exception(self.params_str() + ' the step size should be '
|
||||
logger.exception(f'{self.params_str()} the step size should be ' +
|
||||
'less than the domain size.')
|
||||
raise ValueError
|
||||
if dx < 1 or dy < 1 or dz < 1:
|
||||
logger.exception(self.params_str() + ' the step size should not '
|
||||
logger.exception(f'{self.params_str()} the step size should not ' +
|
||||
'be less than the spatial discretisation.')
|
||||
raise ValueError
|
||||
if output_type not in ['n', 'f']:
|
||||
logger.exception(self.params_str() + ' requires type to be either '
|
||||
logger.exception(f'{self.params_str()} requires type to be either ' +
|
||||
'n (normal) or f (fine).')
|
||||
raise ValueError
|
||||
if output_type == 'f' and (dx * grid.dx != grid.dx or
|
||||
dy * grid.dy != grid.dy or
|
||||
dz * grid.dz != grid.dz):
|
||||
logger.exception(self.params_str() + ' requires the spatial '
|
||||
'discretisation for the geometry view to be the '
|
||||
'same as the model for geometry view of '
|
||||
logger.exception(f'{self.params_str()} requires the spatial ' +
|
||||
'discretisation for the geometry view to be the ' +
|
||||
'same as the model for geometry view of ' +
|
||||
'type f (fine)')
|
||||
raise ValueError
|
||||
|
||||
g = GeometryViewUser(xs, ys, zs, xf, yf, zf, dx, dy, dz, filename, grid)
|
||||
|
||||
logger.info(self.grid_name(grid) + f'Geometry view from {p3[0]:g}m, '
|
||||
f'{p3[1]:g}m, {p3[2]:g}m, to {p4[0]:g}m, {p4[1]:g}m, '
|
||||
f'{p4[2]:g}m, discretisation {dx * grid.dx:g}m, '
|
||||
f'{dy * grid.dy:g}m, {dz * grid.dz:g}m, with filename '
|
||||
logger.info(f'{self.grid_name(grid)}Geometry view from {p3[0]:g}m, ' +
|
||||
f'{p3[1]:g}m, {p3[2]:g}m, to {p4[0]:g}m, {p4[1]:g}m, ' +
|
||||
f'{p4[2]:g}m, discretisation {dx * grid.dx:g}m, ' +
|
||||
f'{dy * grid.dy:g}m, {dz * grid.dz:g}m, with filename ' +
|
||||
f'base {g.filename} created.')
|
||||
|
||||
grid.geometryviews.append(g)
|
||||
@@ -1686,7 +1647,7 @@ class GeometryObjectsWrite(UserObjectMulti):
|
||||
p2 = self.kwargs['p2']
|
||||
basefilename = self.kwargs['filename']
|
||||
except KeyError:
|
||||
logger.exception(self.params_str() + ' requires exactly seven '
|
||||
logger.exception(f'{self.params_str()} requires exactly seven ' +
|
||||
'parameters.')
|
||||
raise
|
||||
|
||||
@@ -1750,30 +1711,30 @@ class PMLCFS(UserObjectMulti):
|
||||
sigmamin = self.kwargs['sigmamin']
|
||||
sigmamax = self.kwargs['sigmamax']
|
||||
except KeyError:
|
||||
logger.exception(self.params_str() + ' requires exactly twelve '
|
||||
logger.exception(f'{self.params_str()} requires exactly twelve ' +
|
||||
'parameters.')
|
||||
raise
|
||||
|
||||
if (alphascalingprofile not in CFSParameter.scalingprofiles.keys() or
|
||||
kappascalingprofile not in CFSParameter.scalingprofiles.keys() or
|
||||
sigmascalingprofile not in CFSParameter.scalingprofiles.keys()):
|
||||
logger.exception(self.params_str() + ' must have scaling type '
|
||||
logger.exception(f'{self.params_str()} must have scaling type ' +
|
||||
f"{','.join(CFSParameter.scalingprofiles.keys())}")
|
||||
raise ValueError
|
||||
if (alphascalingdirection not in CFSParameter.scalingdirections or
|
||||
kappascalingdirection not in CFSParameter.scalingdirections or
|
||||
sigmascalingdirection not in CFSParameter.scalingdirections):
|
||||
logger.exception(self.params_str() + ' must have scaling type '
|
||||
logger.exception(f'{self.params_str()} must have scaling type ' +
|
||||
f"{','.join(CFSParameter.scalingdirections)}")
|
||||
raise ValueError
|
||||
if (float(alphamin) < 0 or float(alphamax) < 0 or
|
||||
float(kappamin) < 0 or float(kappamax) < 0 or float(sigmamin) < 0):
|
||||
logger.exception(self.params_str() + ' minimum and maximum scaling '
|
||||
logger.exception(f'{self.params_str()} minimum and maximum scaling ' +
|
||||
'values must be greater than zero.')
|
||||
raise ValueError
|
||||
# TODO: Fix handling of kappa for 2nd order PMLs
|
||||
# if float(kappamin) < 1:
|
||||
# logger.exception(self.params_str() + ' minimum scaling value for '
|
||||
# logger.exception(f'{self.params_str()} minimum scaling value for '
|
||||
# 'kappa must be greater than or equal to one.')
|
||||
# raise ValueError
|
||||
|
||||
@@ -1813,7 +1774,7 @@ class PMLCFS(UserObjectMulti):
|
||||
grid.pmls['cfs'].append(cfs)
|
||||
|
||||
if len(grid.pmls['cfs']) > 2:
|
||||
logger.exception(self.params_str() + ' can only be used up to two '
|
||||
logger.exception(f'{self.params_str()} can only be used up to two ' +
|
||||
'times, for up to a 2nd order PML.')
|
||||
raise ValueError
|
||||
|
||||
|
@@ -92,7 +92,7 @@ class Context:
|
||||
|
||||
def print_logo_copyright(self):
|
||||
"""Prints gprMax logo, version, and copyright/licencing information."""
|
||||
logo_copyright = logo(__version__ + ' (' + codename + ')')
|
||||
logo_copyright = logo(f'{__version__} ({codename})')
|
||||
logger.basic(logo_copyright)
|
||||
|
||||
def print_sim_time_taken(self):
|
||||
@@ -164,19 +164,15 @@ class MPIContext(Context):
|
||||
executor = self.MPIExecutor(self._run_model, comm=self.comm)
|
||||
|
||||
# Check GPU resources versus number of MPI tasks
|
||||
if executor.is_master():
|
||||
if config.sim_config.general['solver'] == 'cuda':
|
||||
if executor.size - 1 > len(config.sim_config.devices['devs']):
|
||||
logger.exception('Not enough GPU resources for number of '
|
||||
'MPI tasks requested. Number of MPI tasks '
|
||||
'should be equal to number of GPUs + 1.')
|
||||
raise ValueError
|
||||
|
||||
# Create job list
|
||||
jobs = []
|
||||
for i in self.model_range:
|
||||
jobs.append({'i': i})
|
||||
if (executor.is_master() and
|
||||
config.sim_config.general['solver'] == 'cuda' and
|
||||
executor.size - 1 > len(config.sim_config.devices['devs'])):
|
||||
logger.exception('Not enough GPU resources for number of '
|
||||
'MPI tasks requested. Number of MPI tasks '
|
||||
'should be equal to number of GPUs + 1.')
|
||||
raise ValueError
|
||||
|
||||
jobs = [{'i': i} for i in self.model_range]
|
||||
# Send the workers to their work loop
|
||||
executor.start()
|
||||
if executor.is_master():
|
||||
|
@@ -76,7 +76,7 @@ def write_hdf5_outputfile(outputfile, G):
|
||||
# Write meta data and data for any subgrids
|
||||
if sg_rxs:
|
||||
for sg in G.subgrids:
|
||||
grp = f.create_group('/subgrids/' + sg.name)
|
||||
grp = f.create_group(f'/subgrids/{sg.name}')
|
||||
write_hd5_data(grp, sg, is_subgrid=True)
|
||||
|
||||
if G.rxs or sg_rxs:
|
||||
@@ -115,7 +115,7 @@ def write_hd5_data(basegrp, G, is_subgrid=False):
|
||||
# Create group for sources (except transmission lines); add type and positional data attributes
|
||||
srclist = G.voltagesources + G.hertziandipoles + G.magneticdipoles
|
||||
for srcindex, src in enumerate(srclist):
|
||||
grp = basegrp.create_group('srcs/src' + str(srcindex + 1))
|
||||
grp = basegrp.create_group(f'srcs/src{str(srcindex + 1)}')
|
||||
grp.attrs['Type'] = type(src).__name__
|
||||
grp.attrs['Position'] = (src.xcoord * G.dx, src.ycoord * G.dy, src.zcoord * G.dz)
|
||||
|
||||
|
@@ -371,8 +371,7 @@ class GeometryObjects:
|
||||
parts = config.sim_config.input_file_path.with_suffix('').parts
|
||||
self.filename_hdf5 = Path(*parts[:-1], self.basefilename)
|
||||
self.filename_hdf5 = self.filename_hdf5.with_suffix('.h5')
|
||||
self.filename_materials = Path(
|
||||
*parts[:-1], self.basefilename + '_materials')
|
||||
self.filename_materials = Path(*parts[:-1], f'{self.basefilename}_materials')
|
||||
self.filename_materials = self.filename_materials.with_suffix('.txt')
|
||||
|
||||
# Sizes of arrays to write necessary to update progress bar
|
||||
|
@@ -178,8 +178,8 @@ def write_processed_file(processedlines):
|
||||
for item in processedlines:
|
||||
f.write(f'{item}')
|
||||
|
||||
logger.info(f'Written input commands, after processing any Python code and '
|
||||
f'include commands, to file: {processedfile}\n')
|
||||
logger.info(f'Written input commands, after processing any Python ' +
|
||||
f'code and include commands, to file: {processedfile}\n')
|
||||
|
||||
|
||||
def check_cmd_names(processedlines, checkessential=True):
|
||||
|
@@ -55,8 +55,8 @@ def process_singlecmds(singlecmds):
|
||||
if singlecmds[cmd] is not None:
|
||||
tmp = tuple(int(x) for x in singlecmds[cmd].split())
|
||||
if len(tmp) != 1:
|
||||
logger.exception(cmd + ' requires exactly one parameter to specify ' +
|
||||
'the number of CPU OpenMP threads to use')
|
||||
logger.exception(f'{cmd} requires exactly one parameter to specify ' +
|
||||
f'the number of CPU OpenMP threads to use')
|
||||
raise ValueError
|
||||
|
||||
omp_threads = OMPThreads(n=tmp[0])
|
||||
@@ -66,7 +66,7 @@ def process_singlecmds(singlecmds):
|
||||
if singlecmds[cmd] is not None:
|
||||
tmp = [float(x) for x in singlecmds[cmd].split()]
|
||||
if len(tmp) != 3:
|
||||
logger.exception(cmd + ' requires exactly three parameters')
|
||||
logger.exception(f'{cmd} requires exactly three parameters')
|
||||
raise ValueError
|
||||
|
||||
dl = (tmp[0], tmp[1], tmp[2])
|
||||
@@ -77,7 +77,7 @@ def process_singlecmds(singlecmds):
|
||||
if singlecmds[cmd] is not None:
|
||||
tmp = [float(x) for x in singlecmds[cmd].split()]
|
||||
if len(tmp) != 3:
|
||||
logger.exception(cmd + ' requires exactly three parameters')
|
||||
logger.exception(f'{cmd} requires exactly three parameters')
|
||||
raise ValueError
|
||||
|
||||
p1 = (tmp[0], tmp[1], tmp[2])
|
||||
@@ -94,8 +94,8 @@ def process_singlecmds(singlecmds):
|
||||
if singlecmds[cmd] is not None:
|
||||
tmp = singlecmds[cmd].split()
|
||||
if len(tmp) != 1:
|
||||
logger.exception(cmd + ' requires exactly one parameter to specify ' +
|
||||
'the time window. Either in seconds or number of iterations.')
|
||||
logger.exception(f'{cmd} requires exactly one parameter to specify the ' +
|
||||
f'time window. Either in seconds or number of iterations.')
|
||||
raise ValueError
|
||||
tmp = tmp[0].lower()
|
||||
|
||||
@@ -113,8 +113,8 @@ def process_singlecmds(singlecmds):
|
||||
cmd = '#pml_cells'
|
||||
if singlecmds[cmd] is not None:
|
||||
tmp = singlecmds[cmd].split()
|
||||
if len(tmp) != 1 and len(tmp) != 6:
|
||||
logger.exception(cmd + ' requires either one or six parameter(s)')
|
||||
if len(tmp) not in [1, 6]:
|
||||
logger.exception(f'{cmd} requires either one or six parameter(s)')
|
||||
raise ValueError
|
||||
if len(tmp) == 1:
|
||||
pml_cells = PMLProps(thickness=int(tmp[0]))
|
||||
@@ -132,7 +132,7 @@ def process_singlecmds(singlecmds):
|
||||
if singlecmds[cmd] is not None:
|
||||
tmp = singlecmds[cmd].split()
|
||||
if len(tmp) != 3:
|
||||
logger.exception(cmd + ' requires exactly three parameters')
|
||||
logger.exception(f'{cmd} requires exactly three parameters')
|
||||
raise ValueError
|
||||
|
||||
p1 = (float(tmp[0]), float(tmp[1]), float(tmp[2]))
|
||||
@@ -143,7 +143,7 @@ def process_singlecmds(singlecmds):
|
||||
if singlecmds[cmd] is not None:
|
||||
tmp = singlecmds[cmd].split()
|
||||
if len(tmp) != 3:
|
||||
logger.exception(cmd + ' requires exactly three parameters')
|
||||
logger.exception(f'{cmd} requires exactly three parameters')
|
||||
raise ValueError
|
||||
|
||||
p1 = (float(tmp[0]), float(tmp[1]), float(tmp[2]))
|
||||
@@ -154,8 +154,8 @@ def process_singlecmds(singlecmds):
|
||||
cmd = '#excitation_file'
|
||||
if singlecmds[cmd] is not None:
|
||||
tmp = singlecmds[cmd].split()
|
||||
if len(tmp) != 1 and len(tmp) != 3:
|
||||
logger.exception(cmd + ' requires either one or three parameter(s)')
|
||||
if len(tmp) not in [1, 3]:
|
||||
logger.exception(f'{cmd} requires either one or three parameter(s)')
|
||||
raise ValueError
|
||||
|
||||
if len(tmp) > 1:
|
||||
|
@@ -73,7 +73,7 @@ class ModelBuildRun:
|
||||
self.p = psutil.Process()
|
||||
|
||||
# Normal model reading/building process; bypassed if geometry information to be reused
|
||||
self.build_geometry() if not config.get_model_config().reuse_geometry else self.reuse_geometry()
|
||||
self.reuse_geometry() if config.get_model_config().reuse_geometry else self.build_geometry()
|
||||
|
||||
logger.info(f'\nOutput directory: {config.get_model_config().output_file_path.parent.resolve()}')
|
||||
|
||||
@@ -109,11 +109,11 @@ class ModelBuildRun:
|
||||
|
||||
# Write files for any geometry views and geometry object outputs
|
||||
gvs = G.geometryviews + [gv for sg in G.subgrids for gv in sg.geometryviews]
|
||||
if not (gvs or G.geometryobjectswrite) and config.sim_config.args.geometry_only:
|
||||
if (not gvs and not G.geometryobjectswrite and config.sim_config.args.geometry_only):
|
||||
logger.exception('\nNo geometry views or geometry objects found.')
|
||||
raise ValueError
|
||||
save_geometry_views(gvs)
|
||||
|
||||
|
||||
if G.geometryobjectswrite:
|
||||
logger.info('')
|
||||
for i, go in enumerate(G.geometryobjectswrite):
|
||||
@@ -271,8 +271,7 @@ class ModelBuildRun:
|
||||
logger.warning(f"You have specified more threads ({config.get_model_config().ompthreads}) "
|
||||
f"than available physical CPU cores ({config.sim_config.hostinfo['physicalcores']}). "
|
||||
f"This may lead to degraded performance.")
|
||||
# Print information about any compute device, e.g. GPU, in use
|
||||
elif config.sim_config.general['solver'] == 'cuda' or config.sim_config.general['solver'] == 'opencl':
|
||||
elif config.sim_config.general['solver'] in ['cuda', 'opencl']:
|
||||
if config.sim_config.general['solver'] == 'opencl':
|
||||
solvername = 'OpenCL'
|
||||
platformname = ' on ' + ' '.join(config.get_model_config().device['dev'].platform.name.split())
|
||||
@@ -338,11 +337,11 @@ class GridBuilder:
|
||||
pbar.close()
|
||||
|
||||
def tm_grid_update(self):
|
||||
if '2D TMx' == config.get_model_config().mode:
|
||||
if config.get_model_config().mode == '2D TMx':
|
||||
self.grid.tmx()
|
||||
elif '2D TMy' == config.get_model_config().mode:
|
||||
elif config.get_model_config().mode == '2D TMy':
|
||||
self.grid.tmy()
|
||||
elif '2D TMz' == config.get_model_config().mode:
|
||||
elif config.get_model_config().mode == '2D TMz':
|
||||
self.grid.tmz()
|
||||
|
||||
def update_voltage_source_materials(self):
|
||||
|
@@ -220,26 +220,26 @@ class MPIExecutor(object):
|
||||
|
||||
def join(self):
|
||||
"""Joins the workers."""
|
||||
if self.is_master():
|
||||
if not self.is_master():
|
||||
return
|
||||
logger.debug(f'({self.comm.name}) - Terminating. Sending sentinel to all workers.')
|
||||
# Send sentinel to all workers
|
||||
for worker in self.workers:
|
||||
self.comm.send(None, dest=worker, tag=Tags.EXIT)
|
||||
|
||||
logger.debug(f'({self.comm.name}) - Terminating. Sending sentinel to all workers.')
|
||||
# Send sentinel to all workers
|
||||
for worker in self.workers:
|
||||
self.comm.send(None, dest=worker, tag=Tags.EXIT)
|
||||
logger.debug(f'({self.comm.name}) - Waiting for all workers to terminate.')
|
||||
|
||||
logger.debug(f'({self.comm.name}) - Waiting for all workers to terminate.')
|
||||
down = [False] * len(self.workers)
|
||||
while True:
|
||||
for i, worker in enumerate(self.workers):
|
||||
if self.comm.Iprobe(source=worker, tag=Tags.EXIT):
|
||||
self.comm.recv(source=worker, tag=Tags.EXIT)
|
||||
down[i] = True
|
||||
if all(down):
|
||||
break
|
||||
|
||||
down = [False] * len(self.workers)
|
||||
while True:
|
||||
for i, worker in enumerate(self.workers):
|
||||
if self.comm.Iprobe(source=worker, tag=Tags.EXIT):
|
||||
self.comm.recv(source=worker, tag=Tags.EXIT)
|
||||
down[i] = True
|
||||
if all(down):
|
||||
break
|
||||
|
||||
self._up = False
|
||||
logger.debug(f'({self.comm.name}) - All workers terminated.')
|
||||
self._up = False
|
||||
logger.debug(f'({self.comm.name}) - All workers terminated.')
|
||||
|
||||
def submit(self, jobs, sleep=0.0):
|
||||
"""Submits a list of jobs to the workers and returns the results.
|
||||
|
@@ -105,7 +105,7 @@ class Scene:
|
||||
|
||||
# Check essential commands and warn user if missing
|
||||
for cmd_type in self.essential_cmds:
|
||||
d = any([isinstance(cmd, cmd_type) for cmd in cmds_unique])
|
||||
d = any(isinstance(cmd, cmd_type) for cmd in cmds_unique)
|
||||
if not d:
|
||||
logger.exception('Your input file is missing essential commands ' +
|
||||
'required to run a model. Essential commands ' +
|
||||
|
@@ -96,7 +96,7 @@ class VoltageSource(Source):
|
||||
i = self.xcoord
|
||||
j = self.ycoord
|
||||
k = self.zcoord
|
||||
componentID = 'E' + self.polarisation
|
||||
componentID = f'E{self.polarisation}'
|
||||
|
||||
if self.polarisation == 'x':
|
||||
if self.resistance != 0:
|
||||
@@ -130,30 +130,31 @@ class VoltageSource(Source):
|
||||
G: FDTDGrid class describing a grid in a model.
|
||||
"""
|
||||
|
||||
if self.resistance != 0:
|
||||
i = self.xcoord
|
||||
j = self.ycoord
|
||||
k = self.zcoord
|
||||
if self.resistance == 0:
|
||||
return
|
||||
i = self.xcoord
|
||||
j = self.ycoord
|
||||
k = self.zcoord
|
||||
|
||||
componentID = 'E' + self.polarisation
|
||||
requirednumID = G.ID[G.IDlookup[componentID], i, j, k]
|
||||
material = next(x for x in G.materials if x.numID == requirednumID)
|
||||
newmaterial = deepcopy(material)
|
||||
newmaterial.ID = material.ID + '+' + self.ID
|
||||
newmaterial.numID = len(G.materials)
|
||||
newmaterial.averagable = False
|
||||
newmaterial.type += ',\nvoltage-source' if newmaterial.type else 'voltage-source'
|
||||
componentID = f'E{self.polarisation}'
|
||||
requirednumID = G.ID[G.IDlookup[componentID], i, j, k]
|
||||
material = next(x for x in G.materials if x.numID == requirednumID)
|
||||
newmaterial = deepcopy(material)
|
||||
newmaterial.ID = f'{material.ID}+{self.ID}'
|
||||
newmaterial.numID = len(G.materials)
|
||||
newmaterial.averagable = False
|
||||
newmaterial.type += ',\nvoltage-source' if newmaterial.type else 'voltage-source'
|
||||
|
||||
# Add conductivity of voltage source to underlying conductivity
|
||||
if self.polarisation == 'x':
|
||||
newmaterial.se += G.dx / (self.resistance * G.dy * G.dz)
|
||||
elif self.polarisation == 'y':
|
||||
newmaterial.se += G.dy / (self.resistance * G.dx * G.dz)
|
||||
elif self.polarisation == 'z':
|
||||
newmaterial.se += G.dz / (self.resistance * G.dx * G.dy)
|
||||
# Add conductivity of voltage source to underlying conductivity
|
||||
if self.polarisation == 'x':
|
||||
newmaterial.se += G.dx / (self.resistance * G.dy * G.dz)
|
||||
elif self.polarisation == 'y':
|
||||
newmaterial.se += G.dy / (self.resistance * G.dx * G.dz)
|
||||
elif self.polarisation == 'z':
|
||||
newmaterial.se += G.dz / (self.resistance * G.dx * G.dy)
|
||||
|
||||
G.ID[G.IDlookup[componentID], i, j, k] = newmaterial.numID
|
||||
G.materials.append(newmaterial)
|
||||
G.ID[G.IDlookup[componentID], i, j, k] = newmaterial.numID
|
||||
G.materials.append(newmaterial)
|
||||
|
||||
|
||||
class HertzianDipole(Source):
|
||||
@@ -180,7 +181,7 @@ class HertzianDipole(Source):
|
||||
i = self.xcoord
|
||||
j = self.ycoord
|
||||
k = self.zcoord
|
||||
componentID = 'E' + self.polarisation
|
||||
componentID = f'E{self.polarisation}'
|
||||
if self.polarisation == 'x':
|
||||
Ex[i, j, k] -= (updatecoeffsE[ID[G.IDlookup[componentID], i, j, k], 4] *
|
||||
self.waveformvalues_halfdt[iteration] * self.dl *
|
||||
@@ -217,7 +218,7 @@ class MagneticDipole(Source):
|
||||
i = self.xcoord
|
||||
j = self.ycoord
|
||||
k = self.zcoord
|
||||
componentID = 'H' + self.polarisation
|
||||
componentID = f'H{self.polarisation}'
|
||||
|
||||
if self.polarisation == 'x':
|
||||
Hx[i, j, k] -= (updatecoeffsH[ID[G.IDlookup[componentID], i, j, k], 4] *
|
||||
|
@@ -174,7 +174,7 @@ class PrecursorNodesBase:
|
||||
|
||||
for f in field_names:
|
||||
try:
|
||||
val = c1 * getattr(self, f + '_0') + c2 * getattr(self, f + '_1')
|
||||
val = c1 * getattr(self, f'{f}_0') + c2 * getattr(self, f'{f}_1')
|
||||
except ValueError:
|
||||
raise
|
||||
setattr(self, f, val)
|
||||
@@ -184,7 +184,7 @@ class PrecursorNodesBase:
|
||||
current main time step, i.e. ey_left = copy.ey_left_1
|
||||
"""
|
||||
for f in field_names:
|
||||
val = np.copy(getattr(self, f + '_1'))
|
||||
val = np.copy(getattr(self, f'{f}_1'))
|
||||
setattr(self, f, val)
|
||||
|
||||
def calc_exact_magnetic_in_time(self):
|
||||
@@ -218,9 +218,9 @@ class PrecursorNodesBase:
|
||||
|
||||
def update_previous_timestep_fields(self, field_names):
|
||||
for fn in field_names:
|
||||
val = getattr(self, fn + '_1')
|
||||
val = getattr(self, f'{fn}_1')
|
||||
val_c = np.copy(val)
|
||||
setattr(self, fn + '_0', val_c)
|
||||
setattr(self, f'{fn}_0', val_c)
|
||||
|
||||
def interpolate_to_sub_grid(self, field, coords):
|
||||
x, z, x_sg, z_sg = coords
|
||||
|
@@ -33,10 +33,10 @@ def create_updates(G):
|
||||
sg_type = type(sg)
|
||||
if sg_type == SubGridHSG and sg.filter:
|
||||
precursors = PrecursorNodesFiltered(G, sg)
|
||||
elif sg_type == SubGridHSG and not sg.filter:
|
||||
elif sg_type == SubGridHSG:
|
||||
precursors = PrecursorNodes(G, sg)
|
||||
else:
|
||||
logger.exception(str(sg) + ' is not a subgrid type')
|
||||
logger.exception(f'{str(sg)} is not a subgrid type')
|
||||
raise ValueError
|
||||
|
||||
sgu = SubgridUpdater(sg, precursors, G)
|
||||
|
@@ -45,7 +45,7 @@ class SubGridBase(UserObjectMulti):
|
||||
elif isinstance(node, UserObjectGeometry):
|
||||
self.children_geometry.append(node)
|
||||
else:
|
||||
logger.exception(str(node) + ' this Object can not be added to a sub grid')
|
||||
logger.exception(f'{str(node)} this Object can not be added to a sub grid')
|
||||
raise ValueError
|
||||
|
||||
def set_discretisation(self, sg, grid):
|
||||
@@ -128,7 +128,7 @@ class SubGridBase(UserObjectMulti):
|
||||
# Don't mix and match different subgrid types
|
||||
for sg_made in grid.subgrids:
|
||||
if type(sg) != type(sg_made):
|
||||
logger.exception(self.__str__() + ' please only use one type of subgrid')
|
||||
logger.exception(f'{self.__str__()} please only use one type of subgrid')
|
||||
raise ValueError
|
||||
|
||||
# Reference the subgrid under the main grid to which it belongs
|
||||
|
@@ -378,7 +378,7 @@ class CUDAUpdates:
|
||||
for pml in self.grid.pmls['slabs']:
|
||||
pml.htod_field_arrays()
|
||||
pml.set_blocks_per_grid()
|
||||
knl_name = 'order' + str(len(pml.CFS)) + '_' + pml.direction
|
||||
knl_name = f'order{len(pml.CFS)}_{pml.direction}'
|
||||
self.subs_name_args['FUNC'] = knl_name
|
||||
|
||||
knl_electric = getattr(knl_pml_updates_electric, knl_name)
|
||||
@@ -880,21 +880,21 @@ class OpenCLUpdates:
|
||||
for pml in self.grid.pmls['slabs']:
|
||||
pml.set_queue(self.queue)
|
||||
pml.htod_field_arrays()
|
||||
knl_name = 'order' + str(len(pml.CFS)) + '_' + pml.direction
|
||||
knl_name = f'order{len(pml.CFS)}_{pml.direction}'
|
||||
knl_electric_name = getattr(knl_pml_updates_electric, knl_name)
|
||||
knl_magnetic_name = getattr(knl_pml_updates_magnetic, knl_name)
|
||||
|
||||
pml.update_electric_dev = self.elwise(self.ctx,
|
||||
knl_electric_name['args_opencl'].substitute({'REAL': config.sim_config.dtypes['C_float_or_double']}),
|
||||
pml.update_electric_dev = self.elwise(self.ctx,
|
||||
knl_electric_name['args_opencl'].substitute({'REAL': config.sim_config.dtypes['C_float_or_double']}),
|
||||
knl_electric_name['func'].substitute(subs),
|
||||
'pml_updates_electric_' + knl_name,
|
||||
f'pml_updates_electric_{knl_name}',
|
||||
preamble=self.knl_common,
|
||||
options=config.sim_config.devices['compiler_opts'])
|
||||
|
||||
options=config.sim_config.devices['compiler_opts'],)
|
||||
|
||||
pml.update_magnetic_dev = self.elwise(self.ctx,
|
||||
knl_magnetic_name['args_opencl'].substitute({'REAL': config.sim_config.dtypes['C_float_or_double']}),
|
||||
knl_magnetic_name['func'].substitute(subs),
|
||||
'pml_updates_magnetic_' + knl_name,
|
||||
f'pml_updates_magnetic_{knl_name}',
|
||||
preamble=self.knl_common,
|
||||
options=config.sim_config.devices['compiler_opts'])
|
||||
|
||||
|
@@ -65,7 +65,7 @@ class UserInput:
|
||||
except ValueError as err:
|
||||
v = ['x', 'y', 'z']
|
||||
# Discretisation
|
||||
dl = getattr(self.grid, 'd' + err.args[0])
|
||||
dl = getattr(self.grid, f'd{err.args[0]}')
|
||||
# Incorrect index
|
||||
i = p[v.index(err.args[0])]
|
||||
if name:
|
||||
|
@@ -508,14 +508,14 @@ def print_opencl_info(devs):
|
||||
|
||||
import pyopencl as cl
|
||||
|
||||
logger.basic('|--->OpenCL:')
|
||||
logger.basic('|--->OpenCL:')
|
||||
logger.debug(f'PyOpenCL: {cl.VERSION_TEXT}')
|
||||
|
||||
for i, (ID, dev) in enumerate(devs.items()):
|
||||
if i == 0:
|
||||
platform = dev.platform.name
|
||||
logger.basic(f' |--->Platform: {platform}')
|
||||
if not platform == dev.platform.name:
|
||||
if platform != dev.platform.name:
|
||||
logger.basic(f' |--->Platform: {dev.platform.name}')
|
||||
types = cl.device_type.to_string(dev.type)
|
||||
if 'CPU' in types:
|
||||
|
@@ -91,7 +91,7 @@ def logo(version):
|
||||
v""" + version + '\n\n'
|
||||
|
||||
str = f"{description} {'=' * (get_terminal_width() - len(description) - 1)}\n\n"
|
||||
str += Fore.CYAN + f'{logo}'
|
||||
str += f'{Fore.CYAN}{logo}'
|
||||
str += Style.RESET_ALL + textwrap.fill(copyright,
|
||||
width=get_terminal_width() - 1,
|
||||
initial_indent=' ') + '\n'
|
||||
|
8
setup.py
8
setup.py
@@ -134,12 +134,12 @@ if 'cleanall' in sys.argv:
|
||||
for file in cythonfiles:
|
||||
filebase = os.path.splitext(file)[0]
|
||||
# Remove Cython C files
|
||||
if os.path.isfile(filebase + '.c'):
|
||||
if os.path.isfile(f'{filebase}.c'):
|
||||
try:
|
||||
os.remove(filebase + '.c')
|
||||
print(f'Removed: {filebase + ".c"}')
|
||||
os.remove(f'{filebase}.c')
|
||||
print(f'Removed: {filebase}.c')
|
||||
except OSError:
|
||||
print(f'Could not remove: {filebase + ".c"}')
|
||||
print(f'Could not remove: {filebase}.c')
|
||||
# Remove compiled Cython modules
|
||||
libfile = (glob.glob(os.path.join(os.getcwd(),
|
||||
os.path.splitext(file)[0]) + '*.pyd') +
|
||||
|
@@ -93,8 +93,8 @@ for x, model in enumerate(testmodels):
|
||||
# Diffs
|
||||
datadiffs = np.zeros(datatest.shape, dtype=np.float64)
|
||||
for i in range(len(outputstest)):
|
||||
max = np.amax(np.abs(dataref[:, i]))
|
||||
datadiffs[:, i] = np.divide(np.abs(datatest[:, i] - dataref[:, i]), max, out=np.zeros_like(dataref[:, i]), where=max != 0) # Replace any division by zero with zero
|
||||
maxi = np.amax(np.abs(dataref[:, i]))
|
||||
datadiffs[:, i] = np.divide(np.abs(datatest[:, i] - dataref[:, i]), maxi, out=np.zeros_like(dataref[:, i]), where=maxi != 0) # Replace any division by zero with zero
|
||||
|
||||
# Calculate power (ignore warning from taking a log of any zero values)
|
||||
with np.errstate(divide='ignore'):
|
||||
|
@@ -29,10 +29,16 @@ rx = gprMax.Rx(p1=(0.038, 0.114, 0.013))
|
||||
plate = gprMax.Plate(p1=(0.013, 0.013, 0.013),
|
||||
p2=(0.038, 0.113, 0.013), material_id='pec')
|
||||
|
||||
gv1 = gprMax.GeometryView(p1=(0, 0, 0), p2=(x, y, z), dl=(dl, dl, dl),
|
||||
filename=Path(*parts[:-1], parts[-1] + '_n'), output_type='n')
|
||||
gv2 = gprMax.GeometryView(p1=(0, 0, 0), p2=(x, y, z), dl=(dl, dl, dl),
|
||||
filename=Path(*parts[:-1], parts[-1] + '_f'), output_type='f')
|
||||
gv1 = gprMax.GeometryView(p1=(0, 0, 0),
|
||||
p2=(x, y, z),
|
||||
dl=(dl, dl, dl),
|
||||
filename=Path(*parts[:-1], f'{parts[-1]}_n'),
|
||||
output_type='n',)
|
||||
gv2 = gprMax.GeometryView(p1=(0, 0, 0),
|
||||
p2=(x, y, z),
|
||||
dl=(dl, dl, dl),
|
||||
filename=Path(*parts[:-1], f'{parts[-1]}_f'),
|
||||
output_type='f',)
|
||||
|
||||
pmls = {'CFS-PML': {'pml': gprMax.PMLProps(formulation='HORIPML', thickness=10),
|
||||
# Parameters from http://dx.doi.org/10.1109/TAP.2018.2823864
|
||||
|
@@ -29,10 +29,16 @@ rx = gprMax.Rx(p1=(0.113, 0.189, 0.088))
|
||||
plate = gprMax.Plate(p1=(0.088, 0.088, 0.088),
|
||||
p2=(0.113, 0.188, 0.088), material_id='pec')
|
||||
|
||||
gv1 = gprMax.GeometryView(p1=(0, 0, 0), p2=(x, y, z), dl=(dl, dl, dl),
|
||||
filename=Path(*parts[:-1], parts[-1] + '_n'), output_type='n')
|
||||
gv2 = gprMax.GeometryView(p1=(0, 0, 0), p2=(x, y, z), dl=(dl, dl, dl),
|
||||
filename=Path(*parts[:-1], parts[-1] + '_f'), output_type='f')
|
||||
gv1 = gprMax.GeometryView(p1=(0, 0, 0),
|
||||
p2=(x, y, z),
|
||||
dl=(dl, dl, dl),
|
||||
filename=Path(*parts[:-1], f'{parts[-1]}_n'),
|
||||
output_type='n',)
|
||||
gv2 = gprMax.GeometryView(p1=(0, 0, 0),
|
||||
p2=(x, y, z),
|
||||
dl=(dl, dl, dl),
|
||||
filename=Path(*parts[:-1], f'{parts[-1]}_f'),
|
||||
output_type='f',)
|
||||
|
||||
pml = gprMax.PMLProps(formulation='HORIPML', thickness=10)
|
||||
|
||||
|
@@ -81,8 +81,10 @@ realmax = np.where(np.abs(real[:, 1]) == 1)[0][0]
|
||||
difftime = - (timemodel[modelmax] - real[realmax, 0])
|
||||
|
||||
# Plot modelled and real data
|
||||
fig, ax = plt.subplots(num=modelfile.stem + '_vs_' + realfile.stem,
|
||||
figsize=(20, 10), facecolor='w', edgecolor='w')
|
||||
fig, ax = plt.subplots(num=f'{modelfile.stem}_vs_{realfile.stem}',
|
||||
figsize=(20, 10),
|
||||
facecolor='w',
|
||||
edgecolor='w',)
|
||||
ax.plot(timemodel + difftime, model, 'r', lw=2, label='Model')
|
||||
ax.plot(real[:, 0], real[:, 1], 'r', ls='--', lw=2, label='Experiment')
|
||||
ax.set_xlabel('Time [s]')
|
||||
@@ -93,7 +95,7 @@ ax.legend()
|
||||
ax.grid()
|
||||
|
||||
# Save a PDF/PNG of the figure
|
||||
savename = modelfile.stem + '_vs_' + realfile.stem
|
||||
savename = f'{modelfile.stem}_vs_{realfile.stem}'
|
||||
savename = modelfile.parent / savename
|
||||
# fig.savefig(savename.with_suffix('.pdf'), dpi=None, format='pdf',
|
||||
# bbox_inches='tight', pad_inches=0.1)
|
||||
|
@@ -112,11 +112,9 @@ for i, model in enumerate(testmodels):
|
||||
filetest.attrs['dt'],
|
||||
filetest.attrs['dx_dy_dz'], rxposrelative)
|
||||
|
||||
filetest.close()
|
||||
|
||||
else:
|
||||
# Get output for model and reference files
|
||||
fileref = file.stem + '_ref'
|
||||
fileref = f'{file.stem}_ref'
|
||||
fileref = file.parent / Path(fileref)
|
||||
fileref = h5py.File(fileref.with_suffix('.h5'), 'r')
|
||||
filetest = h5py.File(file.with_suffix('.h5'), 'r')
|
||||
@@ -159,15 +157,15 @@ for i, model in enumerate(testmodels):
|
||||
raise ValueError
|
||||
|
||||
fileref.close()
|
||||
filetest.close()
|
||||
filetest.close()
|
||||
|
||||
# Diffs
|
||||
datadiffs = np.zeros(datatest.shape, dtype=np.float64)
|
||||
for i in range(len(outputstest)):
|
||||
max = np.amax(np.abs(dataref[:, i]))
|
||||
datadiffs[:, i] = np.divide(np.abs(dataref[:, i] - datatest[:, i]), max,
|
||||
maxi = np.amax(np.abs(dataref[:, i]))
|
||||
datadiffs[:, i] = np.divide(np.abs(dataref[:, i] - datatest[:, i]), maxi,
|
||||
out=np.zeros_like(dataref[:, i]),
|
||||
where=max != 0) # Replace any division by zero with zero
|
||||
where=maxi != 0) # Replace any division by zero with zero
|
||||
|
||||
# Calculate power (ignore warning from taking a log of any zero values)
|
||||
with np.errstate(divide='ignore'):
|
||||
@@ -188,17 +186,17 @@ for i, model in enumerate(testmodels):
|
||||
facecolor='w',
|
||||
edgecolor='w')
|
||||
ex1.plot(timetest, datatest[:, 0], 'r', lw=2, label=model)
|
||||
ex1.plot(timeref, dataref[:, 0], 'g', lw=2, ls='--', label=model + '(Ref)')
|
||||
ex1.plot(timeref, dataref[:, 0], 'g', lw=2, ls='--', label=f'{model}(Ref)')
|
||||
ey1.plot(timetest, datatest[:, 1], 'r', lw=2, label=model)
|
||||
ey1.plot(timeref, dataref[:, 1], 'g', lw=2, ls='--', label=model + '(Ref)')
|
||||
ey1.plot(timeref, dataref[:, 1], 'g', lw=2, ls='--', label=f'{model}(Ref)')
|
||||
ez1.plot(timetest, datatest[:, 2], 'r', lw=2, label=model)
|
||||
ez1.plot(timeref, dataref[:, 2], 'g', lw=2, ls='--', label=model + '(Ref)')
|
||||
ez1.plot(timeref, dataref[:, 2], 'g', lw=2, ls='--', label=f'{model}(Ref)')
|
||||
hx1.plot(timetest, datatest[:, 3], 'r', lw=2, label=model)
|
||||
hx1.plot(timeref, dataref[:, 3], 'g', lw=2, ls='--', label=model + '(Ref)')
|
||||
hx1.plot(timeref, dataref[:, 3], 'g', lw=2, ls='--', label=f'{model}(Ref)')
|
||||
hy1.plot(timetest, datatest[:, 4], 'r', lw=2, label=model)
|
||||
hy1.plot(timeref, dataref[:, 4], 'g', lw=2, ls='--', label=model + '(Ref)')
|
||||
hy1.plot(timeref, dataref[:, 4], 'g', lw=2, ls='--', label=f'{model}(Ref)')
|
||||
hz1.plot(timetest, datatest[:, 5], 'r', lw=2, label=model)
|
||||
hz1.plot(timeref, dataref[:, 5], 'g', lw=2, ls='--', label=model + '(Ref)')
|
||||
hz1.plot(timeref, dataref[:, 5], 'g', lw=2, ls='--', label=f'{model}(Ref)')
|
||||
ylabels = ['$E_x$, field strength [V/m]', '$H_x$, field strength [A/m]',
|
||||
'$E_y$, field strength [V/m]', '$H_y$, field strength [A/m]',
|
||||
'$E_z$, field strength [V/m]', '$H_z$, field strength [A/m]']
|
||||
@@ -232,7 +230,7 @@ for i, model in enumerate(testmodels):
|
||||
ax.grid()
|
||||
|
||||
# Save a PDF/PNG of the figure
|
||||
filediffs = file.stem + '_diffs'
|
||||
filediffs = f'{file.stem}_diffs'
|
||||
filediffs = file.parent / Path(filediffs)
|
||||
# fig1.savefig(file.with_suffix('.pdf'), dpi=None, format='pdf',
|
||||
# bbox_inches='tight', pad_inches=0.1)
|
||||
|
在新工单中引用
屏蔽一个用户