Merge pull request #365 from Sai-Suraj-27/optimizing

Removed un-necessary string concatenations and Refactored few functions.
这个提交包含在:
Craig Warren
2023-08-17 17:05:30 +01:00
提交者 GitHub
当前提交 ce47ff6005
共有 27 个文件被更改,包括 253 次插入326 次删除

查看文件

@@ -98,11 +98,11 @@ class AddGrass(UserObjectGeometry):
xf, yf, zf = p2
if frac_dim < 0:
logger.exception(f"{self.__str__()} requires a positive value for " + "the fractal dimension")
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(
f"{self.__str__()} requires a positive value for " + "the minimum and maximum heights for grass blades"
f"{self.__str__()} requires a positive value for the minimum and maximum heights for grass blades"
)
raise ValueError
@@ -118,7 +118,7 @@ class AddGrass(UserObjectGeometry):
# xminus surface
if xs == volume.xs:
logger.exception(
f"{self.__str__()} grass can only be specified " + "on surfaces in the positive axis direction"
f"{self.__str__()} grass can only be specified on surfaces in the positive axis direction"
)
raise ValueError
# xplus surface
@@ -126,8 +126,8 @@ class AddGrass(UserObjectGeometry):
if fractalrange[1] > grid.nx:
logger.exception(
f"{self.__str__()} cannot apply grass to "
+ "fractal box as it would exceed the domain "
+ "size in the x direction"
"fractal box as it would exceed the domain "
"size in the x direction"
)
raise ValueError
requestedsurface = "xplus"
@@ -143,7 +143,7 @@ class AddGrass(UserObjectGeometry):
# yminus surface
if ys == volume.ys:
logger.exception(
f"{self.__str__()} grass can only be specified " + "on surfaces in the positive axis direction"
f"{self.__str__()} grass can only be specified on surfaces in the positive axis direction"
)
raise ValueError
# yplus surface
@@ -151,8 +151,8 @@ class AddGrass(UserObjectGeometry):
if fractalrange[1] > grid.ny:
logger.exception(
f"{self.__str__()} cannot apply grass to "
+ "fractal box as it would exceed the domain "
+ "size in the y direction"
"fractal box as it would exceed the domain "
"size in the y direction"
)
raise ValueError
requestedsurface = "yplus"
@@ -165,7 +165,7 @@ class AddGrass(UserObjectGeometry):
# zminus surface
if zs == volume.zs:
logger.exception(
f"{self.__str__()} grass can only be specified " + "on surfaces in the positive axis direction"
f"{self.__str__()} grass can only be specified on surfaces in the positive axis direction"
)
raise ValueError
# zplus surface
@@ -173,8 +173,8 @@ class AddGrass(UserObjectGeometry):
if fractalrange[1] > grid.nz:
logger.exception(
f"{self.__str__()} cannot apply grass to "
+ "fractal box as it would exceed the domain "
+ "size in the z direction"
"fractal box as it would exceed the domain "
"size in the z direction"
)
raise ValueError
requestedsurface = "zplus"
@@ -195,7 +195,7 @@ class AddGrass(UserObjectGeometry):
if n_blades > surface.fractalsurface.shape[0] * surface.fractalsurface.shape[1]:
logger.exception(
f"{self.__str__()} the specified surface is not large "
+ "enough for the number of grass blades/roots specified"
"enough for the number of grass blades/roots specified"
)
raise ValueError
@@ -244,7 +244,7 @@ class AddGrass(UserObjectGeometry):
if testgrass:
logger.exception(
f"{self.__str__()} requires the time step for the "
+ "model to be less than the relaxation time required to model grass."
"model to be less than the relaxation time required to model grass."
)
raise ValueError
@@ -252,9 +252,9 @@ class AddGrass(UserObjectGeometry):
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 "
+ f"{surface.seed}, and range {limits[0]:g}m to {limits[1]:g}m, "
+ f"added to {surface.operatingonID}."
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 "
f"{surface.seed}, and range {limits[0]:g}m to {limits[1]:g}m, "
f"added to {surface.operatingonID}."
)

查看文件

@@ -82,8 +82,8 @@ class AddSurfaceRoughness(UserObjectGeometry):
except KeyError:
logger.warning(
f"{self.__str__()} no value for seed detected. This "
+ "means you will get a different fractal distribution "
+ "every time the model runs."
"means you will get a different fractal distribution "
"every time the model runs."
)
seed = None
@@ -108,13 +108,13 @@ class AddSurfaceRoughness(UserObjectGeometry):
if weighting[0] < 0:
logger.exception(
f"{self.__str__()} requires a positive value for the "
+ "fractal weighting in the first direction of the surface"
"fractal weighting in the first direction of the surface"
)
raise ValueError
if weighting[1] < 0:
logger.exception(
f"{self.__str__()} requires a positive value for the "
+ "fractal weighting in the second direction of the surface"
"fractal weighting in the second direction of the surface"
)
raise ValueError
@@ -124,7 +124,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
logger.exception(f"{self.__str__()} dimensions are not specified correctly")
raise ValueError
if xs not in [volume.xs, volume.xf]:
logger.exception(f"{self.__str__()} can only be used on the external " + "surfaces of a fractal box")
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), round_value(limits[1] / grid.dx))
# xminus surface
@@ -132,9 +132,9 @@ class AddSurfaceRoughness(UserObjectGeometry):
if fractalrange[0] < 0 or fractalrange[1] > volume.xf:
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"
"to fractal box as it would exceed either the "
"upper coordinates of the fractal box or the "
"domain in the x direction"
)
raise ValueError
requestedsurface = "xminus"
@@ -143,9 +143,9 @@ class AddSurfaceRoughness(UserObjectGeometry):
if fractalrange[0] < volume.xs or fractalrange[1] > grid.nx:
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"
"to fractal box as it would exceed either the "
"lower coordinates of the fractal box or the "
"domain in the x direction"
)
raise ValueError
requestedsurface = "xplus"
@@ -163,9 +163,9 @@ class AddSurfaceRoughness(UserObjectGeometry):
if fractalrange[0] < 0 or fractalrange[1] > volume.yf:
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"
"to fractal box as it would exceed either the "
"upper coordinates of the fractal box or the "
"domain in the y direction"
)
raise ValueError
requestedsurface = "yminus"
@@ -174,9 +174,9 @@ class AddSurfaceRoughness(UserObjectGeometry):
if fractalrange[0] < volume.ys or fractalrange[1] > grid.ny:
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"
"to fractal box as it would exceed either the "
"lower coordinates of the fractal box or the "
"domain in the y direction"
)
raise ValueError
requestedsurface = "yplus"
@@ -191,9 +191,9 @@ class AddSurfaceRoughness(UserObjectGeometry):
if fractalrange[0] < 0 or fractalrange[1] > volume.zf:
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"
"to fractal box as it would exceed either the "
"upper coordinates of the fractal box or the "
"domain in the x direction"
)
raise ValueError
requestedsurface = "zminus"
@@ -202,9 +202,9 @@ class AddSurfaceRoughness(UserObjectGeometry):
if fractalrange[0] < volume.zs or fractalrange[1] > grid.nz:
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"
"to fractal box as it would exceed either the "
"lower coordinates of the fractal box or the "
"domain in the z direction"
)
raise ValueError
requestedsurface = "zplus"
@@ -226,7 +226,7 @@ class AddSurfaceRoughness(UserObjectGeometry):
# List of existing surfaces IDs
existingsurfaceIDs = [x.surfaceID for x in volume.fractalsurfaces]
if surface.surfaceID in existingsurfaceIDs:
logger.exception(f"{self.__str__()} has already been used on the " + f"{surface.surfaceID} surface")
logger.exception(f"{self.__str__()} has already been used on the {surface.surfaceID} surface")
raise ValueError
surface.generate_fractal_surface()
@@ -234,10 +234,10 @@ class AddSurfaceRoughness(UserObjectGeometry):
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}, "
+ f"{surface.weighting[1]:g}, fractal seeding {surface.seed}, "
+ f"and range {limits[0]:g}m to {limits[1]:g}m, added to "
+ f"{surface.operatingonID}."
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}, "
f"{surface.weighting[1]:g}, fractal seeding {surface.seed}, "
f"and range {limits[0]:g}m to {limits[1]:g}m, added to "
f"{surface.operatingonID}."
)

查看文件

@@ -85,7 +85,7 @@ class AddSurfaceWater(UserObjectGeometry):
xf, yf, zf = p2
if depth <= 0:
logger.exception(f"{self.__str__()} requires a positive value for the " + f"depth of water")
logger.exception(f"{self.__str__()} requires a positive value for the depth of water")
raise ValueError
# Check for valid orientations
@@ -94,7 +94,7 @@ class AddSurfaceWater(UserObjectGeometry):
logger.exception(f"{self.__str__()} dimensions are not specified correctly")
raise ValueError
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")
logger.exception(f"{self.__str__()} can only be used on the external surfaces of a fractal box")
raise ValueError
# xminus surface
if xs == volume.xs:
@@ -110,7 +110,7 @@ class AddSurfaceWater(UserObjectGeometry):
logger.exception(f"{self.__str__()} dimensions are not specified correctly")
raise ValueError
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")
logger.exception(f"{self.__str__()} can only be used on the external surfaces of a fractal box")
raise ValueError
# yminus surface
if ys == volume.ys:
@@ -123,7 +123,7 @@ class AddSurfaceWater(UserObjectGeometry):
elif zs == zf:
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")
logger.exception(f"{self.__str__()} can only be used on the external surfaces of a fractal box")
raise ValueError
# zminus surface
if zs == volume.zs:
@@ -141,7 +141,7 @@ class AddSurfaceWater(UserObjectGeometry):
surface = next((x for x in volume.fractalsurfaces if x.surfaceID == requestedsurface), None)
if not surface:
logger.exception(
f"{self.__str__()} specified surface {requestedsurface} " + f"does not have a rough surface applied"
f"{self.__str__()} specified surface {requestedsurface} does not have a rough surface applied"
)
raise ValueError
@@ -151,7 +151,7 @@ class AddSurfaceWater(UserObjectGeometry):
if surface.filldepth < surface.fractalrange[0] or surface.filldepth > surface.fractalrange[1]:
logger.exception(
f"{self.__str__()} requires a value for the depth of water that lies with the "
+ f"range of the requested surface roughness"
f"range of the requested surface roughness"
)
raise ValueError
@@ -170,7 +170,7 @@ class AddSurfaceWater(UserObjectGeometry):
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}."
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}."
)

查看文件

@@ -157,7 +157,7 @@ class Box(UserObjectGeometry):
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}."
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}."
)

查看文件

@@ -85,11 +85,11 @@ class Cone(UserObjectGeometry):
x2, y2, z2 = uip.round_to_grid(p2)
if r1 < 0:
logger.exception(f"{self.__str__()} the radius of the first face " + f"{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(f"{self.__str__()} the radius of the second face " + f"{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:
@@ -158,7 +158,7 @@ class Cone(UserObjectGeometry):
dielectricsmoothing = "on" if averaging else "off"
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}."
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}."
)

查看文件

@@ -146,7 +146,7 @@ class Cylinder(UserObjectGeometry):
dielectricsmoothing = "on" if averaging else "off"
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}."
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}."
)

查看文件

@@ -94,17 +94,15 @@ class CylindricalSector(UserObjectGeometry):
sectorangle = 2 * np.pi * (end / 360)
if normal not in ["x", "y", "z"]:
logger.exception(f"{self.__str__()} the normal direction must be either " + f"x, y or z.")
logger.exception(f"{self.__str__()} the normal direction must be either x, y or z.")
raise ValueError
if r <= 0:
logger.exception(f"{self.__str__()} the radius {r:g} should be a positive value.")
if sectorstartangle < 0 or sectorangle <= 0:
logger.exception(f"{self.__str__()} the starting angle and sector angle should be " + f"a positive values.")
logger.exception(f"{self.__str__()} the starting angle and sector angle should be a positive values.")
raise ValueError
if sectorstartangle >= 2 * np.pi or sectorangle >= 2 * np.pi:
logger.exception(
f"{self.__str__()} the starting angle and sector angle must be " + f"less than 360 degrees."
)
logger.exception(f"{self.__str__()} the starting angle and sector angle must be less than 360 degrees.")
raise ValueError
# Look up requested materials in existing list of material instances
@@ -195,18 +193,18 @@ class CylindricalSector(UserObjectGeometry):
dielectricsmoothing = "on" if averaging else "off"
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}."
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(
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} "
+ f"degrees, of material(s) {', '.join(materialsrequested)} "
+ f"created."
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} "
f"degrees, of material(s) {', '.join(materialsrequested)} "
f"created."
)

查看文件

@@ -103,6 +103,6 @@ class Edge(UserObjectGeometry):
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."
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(f"{self.__str__()} please specify a point and " + f"the three semiaxes.")
logger.exception(f"{self.__str__()} please specify a point and the three semiaxes.")
raise
# Check averaging
@@ -140,8 +140,8 @@ class Ellipsoid(UserObjectGeometry):
dielectricsmoothing = "on" if averaging else "off"
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, "
+ f"y-semiaxis {yr:g}m and z-semiaxis {zr:g}m of material(s) "
+ f"{', '.join(materialsrequested)} created, dielectric "
+ f"smoothing is {dielectricsmoothing}."
f"{p2[1]:g}m, {p2[2]:g}m, x-semiaxis {xr:g}m, "
f"y-semiaxis {yr:g}m and z-semiaxis {zr:g}m of material(s) "
f"{', '.join(materialsrequested)} created, dielectric "
f"smoothing is {dielectricsmoothing}."
)

查看文件

@@ -87,8 +87,8 @@ class FractalBox(UserObjectGeometry):
except KeyError:
logger.warning(
f"{self.__str__()} no value for seed detected. This "
+ "means you will get a different fractal distribution "
+ "every time the model runs."
"means you will get a different fractal distribution "
"every time the model runs."
)
seed = None
@@ -112,24 +112,18 @@ class FractalBox(UserObjectGeometry):
xf, yf, zf = p2
if frac_dim < 0:
logger.exception(f"{self.__str__()} requires a positive value for the " + "fractal dimension")
logger.exception(f"{self.__str__()} requires a positive value for the fractal dimension")
raise ValueError
if weighting[0] < 0:
logger.exception(
f"{self.__str__()} requires a positive value for the " + "fractal weighting in the x direction"
)
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(
f"{self.__str__()} requires a positive value for the " + "fractal weighting in the y direction"
)
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(
f"{self.__str__()} requires a positive value for the " + "fractal weighting in the z direction"
)
logger.exception(f"{self.__str__()} requires a positive value for the fractal weighting in the z direction")
if n_materials < 0:
logger.exception(f"{self.__str__()} requires a positive value for the " + "number of bins")
logger.exception(f"{self.__str__()} requires a positive value for the number of bins")
raise ValueError
# Find materials to use to build fractal volume, either from mixing
@@ -140,15 +134,11 @@ class FractalBox(UserObjectGeometry):
if mixingmodel:
if nbins == 1:
logger.exception(
f"{self.__str__()} must be used with more than " + "one material from the mixing model."
)
logger.exception(f"{self.__str__()} must be used with more than one material from the mixing model.")
raise ValueError
if isinstance(mixingmodel, ListMaterial) and nbins > len(mixingmodel.mat):
logger.exception(
f"{self.__str__()} too many materials/bins "
+ "requested compared to materials in "
+ "mixing model."
f"{self.__str__()} too many materials/bins " "requested compared to materials in " "mixing model."
)
raise ValueError
# Create materials from mixing model as number of bins now known
@@ -173,13 +163,13 @@ class FractalBox(UserObjectGeometry):
dielectricsmoothing = "on" if volume.averaging else "off"
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 "
+ f"{volume.weighting[0]:g}, {volume.weighting[1]:g}, "
+ f"{volume.weighting[2]:g}, fractal seeding {volume.seed}, "
+ f"with {volume.nbins} material(s) created, dielectric smoothing "
+ f"is {dielectricsmoothing}."
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 "
f"{volume.weighting[0]:g}, {volume.weighting[1]:g}, "
f"{volume.weighting[2]:g}, fractal seeding {volume.seed}, "
f"with {volume.nbins} material(s) created, dielectric smoothing "
f"is {dielectricsmoothing}."
)
grid.fractalvolumes.append(volume)

查看文件

@@ -388,8 +388,8 @@ class FractalBoxBuilder(UserObjectGeometry):
if volume.nbins == 1:
logger.exception(
f"{self.__str__()} is being used with a "
+ "single material and no modifications, "
+ "therefore please use a #box command instead."
"single material and no modifications, "
"therefore please use a #box command instead."
)
raise ValueError
else:

查看文件

@@ -108,8 +108,8 @@ class GeometryObjectsRead(UserObjectGeometry):
):
logger.exception(
f"{self.__str__()} requires the spatial resolution "
+ "of the geometry objects file to match the spatial "
+ "resolution of the model"
"of the geometry objects file to match the spatial "
"resolution of the model"
)
raise ValueError
@@ -134,9 +134,9 @@ class GeometryObjectsRead(UserObjectGeometry):
grid.ID[:, xs : xs + ID.shape[1], ys : ys + ID.shape[2], zs : zs + ID.shape[3]] = ID + numexistmaterials
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}."
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}."
)
except KeyError:
averaging = False
@@ -155,7 +155,7 @@ class GeometryObjectsRead(UserObjectGeometry):
)
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}."
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}."
)

查看文件

@@ -148,6 +148,6 @@ class Plate(UserObjectGeometry):
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."
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."
)

查看文件

@@ -133,7 +133,7 @@ class Sphere(UserObjectGeometry):
dielectricsmoothing = "on" if averaging else "off"
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}."
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}."
)

查看文件

@@ -205,15 +205,15 @@ class Triangle(UserObjectGeometry):
dielectricsmoothing = "on" if averaging else "off"
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}."
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(
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."
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."
)

查看文件

@@ -113,12 +113,12 @@ class Waveform(UserObjectMulti):
wavetype = self.kwargs["wave_type"].lower()
except KeyError:
logger.exception(
f"{self.params_str()} must have one of the " + f"following types {','.join(WaveformUser.types)}."
f"{self.params_str()} must have one of the following types {','.join(WaveformUser.types)}."
)
raise
if wavetype not in WaveformUser.types:
logger.exception(
f"{self.params_str()} must have one of the " + f"following types {','.join(WaveformUser.types)}."
f"{self.params_str()} must have one of the following types {','.join(WaveformUser.types)}."
)
raise ValueError
@@ -267,7 +267,7 @@ class VoltageSource(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 with " "the identifier " f"{waveform_id}."))
logger.exception(self.params_str() + (" there is no waveform with " "the identifier {waveform_id}."))
raise ValueError
v = VoltageSourceUser()
@@ -296,7 +296,7 @@ class VoltageSource(UserObjectMulti):
raise ValueError
v.start = start
v.stop = min(stop, grid.timewindow)
startstop = f" start time {v.start:g} secs, finish time " f"{v.stop:g} secs "
startstop = f" start time {v.start:g} secs, finish time {v.stop:g} secs "
except KeyError:
v.start = 0
v.stop = grid.timewindow
@@ -386,7 +386,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(f"{self.params_str()} there is no waveform " + f"with the identifier {waveform_id}.")
logger.exception(f"{self.params_str()} there is no waveform with the identifier {waveform_id}.")
raise ValueError
h = HertzianDipoleUser()
@@ -415,18 +415,18 @@ class HertzianDipole(UserObjectMulti):
stop = self.kwargs["stop"]
if start < 0:
logger.exception(
f"{self.params_str()} delay of the initiation of the " + f"source should not be less than zero."
f"{self.params_str()} delay of the initiation of the source should not be less than zero."
)
raise ValueError
if stop < 0:
logger.exception(f"{self.params_str()} time to remove the source " + f"should not be less than zero.")
logger.exception(f"{self.params_str()} time to remove the source should not be less than zero.")
raise ValueError
if stop - start <= 0:
logger.exception(f"{self.params_str()} duration of the source should not be zero or less.")
raise ValueError
h.start = start
h.stop = min(stop, grid.timewindow)
startstop = f" start time {h.start:g} secs, finish time " f"{h.stop:g} secs "
startstop = f" start time {h.start:g} secs, finish time {h.stop:g} secs "
except KeyError:
h.start = 0
h.stop = grid.timewindow
@@ -527,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(f"{self.params_str()} there is no waveform " + f"with the identifier {waveform_id}.")
logger.exception(f"{self.params_str()} there is no waveform with the identifier {waveform_id}.")
raise ValueError
m = MagneticDipoleUser()
@@ -558,7 +558,7 @@ class MagneticDipole(UserObjectMulti):
raise ValueError
m.start = start
m.stop = min(stop, grid.timewindow)
startstop = f" start time {m.start:g} secs, " f"finish time {m.stop:g} secs "
startstop = f" start time {m.start:g} secs, finish time {m.stop:g} secs "
except KeyError:
m.start = 0
m.stop = grid.timewindow
@@ -568,7 +568,7 @@ class MagneticDipole(UserObjectMulti):
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,"
f"{m.polarisation} at {p2[0]:g}m, {p2[1]:g}m, {p2[2]:g}m,"
+ startstop
+ f"using waveform {m.waveformID} created."
)
@@ -627,8 +627,8 @@ class TransmissionLine(UserObjectMulti):
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."
"with the CUDA or OpenCL-based solver. Consider "
"using a #voltage_source instead."
)
raise ValueError
@@ -661,14 +661,14 @@ class TransmissionLine(UserObjectMulti):
if resistance <= 0 or resistance >= config.sim_config.em_consts["z0"]:
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."
"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(f"{self.params_str()} there is no waveform " + f"with the identifier {waveform_id}.")
logger.exception(f"{self.params_str()} there is no waveform with the identifier {waveform_id}.")
raise ValueError
t = TransmissionLineUser(grid)
@@ -697,7 +697,7 @@ class TransmissionLine(UserObjectMulti):
raise ValueError
t.start = start
t.stop = min(stop, grid.timewindow)
startstop = f" start time {t.start:g} secs, finish time " + f"{t.stop:g} secs "
startstop = f" start time {t.start:g} secs, finish time {t.stop:g} secs "
except KeyError:
t.start = 0
t.stop = grid.timewindow
@@ -846,19 +846,17 @@ class RxArray(UserObjectMulti):
dx, dy, dz = uip.discretise_point(dl)
if xs > xf or ys > yf or zs > zf:
logger.exception(
f"{self.params_str()} the lower coordinates " + "should be less than the upper 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(f"{self.params_str()} the step size should not " + "be less than zero.")
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(
f"{self.params_str()} the step size should " + "not be less than the spatial discretisation."
f"{self.params_str()} the step size should not be less than the spatial discretisation."
)
raise ValueError
if dy < 1:
@@ -866,7 +864,7 @@ class RxArray(UserObjectMulti):
dy = 1
else:
logger.exception(
f"{self.params_str()} the step size should " + "not be less than the spatial discretisation."
f"{self.params_str()} the step size should not be less than the spatial discretisation."
)
raise ValueError
if dz < 1:
@@ -874,7 +872,7 @@ class RxArray(UserObjectMulti):
dz = 1
else:
logger.exception(
f"{self.params_str()} the step size should " + "not be less than the spatial discretisation."
f"{self.params_str()} the step size should not be less than the spatial discretisation."
)
raise ValueError
@@ -974,7 +972,7 @@ class Snapshot(UserObjectMulti):
if time > 0:
iterations = round_value((time / grid.dt)) + 1
else:
logger.exception(f"{self.params_str()} time value must be " + "greater than zero.")
logger.exception(f"{self.params_str()} time value must be greater than zero.")
raise ValueError
try:
@@ -1009,12 +1007,10 @@ class Snapshot(UserObjectMulti):
outputs = dict.fromkeys(SnapshotUser.allowableoutputs, True)
if dx < 0 or dy < 0 or dz < 0:
logger.exception(f"{self.params_str()} the step size should not " + "be less than zero.")
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(
f"{self.params_str()} the step size should not " + "be less than the spatial discretisation."
)
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:
logger.exception(f"{self.params_str()} time value is not valid.")
@@ -1064,26 +1060,26 @@ class Material(UserObjectMulti):
if er < 1:
logger.exception(
f"{self.params_str()} requires a positive value of " + f"one or greater for static (DC) permittivity."
f"{self.params_str()} requires a positive value of 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 " + f"value for electric conductivity.")
logger.exception(f"{self.params_str()} requires a positive value for electric conductivity.")
raise ValueError
else:
se = float("inf")
if mr < 1:
logger.exception(
f"{self.params_str()} requires a positive value of " + f"one or greater for magnetic permeability."
f"{self.params_str()} requires a positive value of one or greater for magnetic permeability."
)
raise ValueError
if sm < 0:
logger.exception(f"{self.params_str()} requires a positive value " + f"for magnetic loss.")
logger.exception(f"{self.params_str()} requires a positive value 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} " + f"already exists")
logger.exception(f"{self.params_str()} with ID {material_id} already exists")
raise ValueError
# Create a new instance of the Material class material
@@ -1137,7 +1133,7 @@ class AddDebyeDispersion(UserObjectMulti):
raise
if poles < 0:
logger.exception(f"{self.params_str()} requires a positive value " + "for number of poles.")
logger.exception(f"{self.params_str()} requires a positive value for number of poles.")
raise ValueError
# Look up requested materials in existing list of material instances
@@ -1163,9 +1159,7 @@ class AddDebyeDispersion(UserObjectMulti):
disp_material.deltaer.append(er_delta[i])
disp_material.tau.append(tau[i])
else:
logger.exception(
f"{self.params_str()} requires positive " + "values for the permittivity difference."
)
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"]:
config.get_model_config().materials["maxpoles"] = disp_material.poles
@@ -1212,7 +1206,7 @@ class AddLorentzDispersion(UserObjectMulti):
raise
if poles < 0:
logger.exception(f"{self.params_str()} requires a positive value " + "for number of poles.")
logger.exception(f"{self.params_str()} requires a positive value for number of poles.")
raise ValueError
# Look up requested materials in existing list of material instances
@@ -1254,9 +1248,9 @@ class AddLorentzDispersion(UserObjectMulti):
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"and gamma={', '.join('%4.3e' % delta for delta in disp_material.alpha)} created."
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."
)
@@ -1284,11 +1278,11 @@ class AddDrudeDispersion(UserObjectMulti):
alpha = self.kwargs["alpha"]
material_ids = self.kwargs["material_ids"]
except KeyError:
logger.exception(f"{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(f"{self.params_str()} requires a positive value " + "for number of poles.")
logger.exception(f"{self.params_str()} requires a positive value for number of poles.")
raise ValueError
# Look up requested materials in existing list of material instances
@@ -1364,30 +1358,30 @@ class SoilPeplinski(UserObjectMulti):
water_fraction_upper = self.kwargs["water_fraction_upper"]
ID = self.kwargs["id"]
except KeyError:
logger.exception(f"{self.params_str()} requires at exactly seven " + "parameters.")
logger.exception(f"{self.params_str()} requires at exactly seven parameters.")
raise
if sand_fraction < 0:
logger.exception(f"{self.params_str()} requires a positive value " + "for the sand fraction.")
logger.exception(f"{self.params_str()} requires a positive value for the sand fraction.")
raise ValueError
if clay_fraction < 0:
logger.exception(f"{self.params_str()} requires a positive value " + "for the clay fraction.")
logger.exception(f"{self.params_str()} requires a positive value for the clay fraction.")
raise ValueError
if bulk_density < 0:
logger.exception(f"{self.params_str()} requires a positive value " + "for the bulk density.")
logger.exception(f"{self.params_str()} requires a positive value for the bulk density.")
raise ValueError
if sand_density < 0:
logger.exception(f"{self.params_str()} requires a positive value " + "for the sand particle density.")
logger.exception(f"{self.params_str()} requires a positive value for the sand particle density.")
raise ValueError
if water_fraction_lower < 0:
logger.exception(
f"{self.params_str()} requires a positive value " + "for the lower limit of the water volumetric "
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(
f"{self.params_str()} requires a positive value " + "for the upper limit of the water volumetric "
f"{self.params_str()} requires a positive value for the upper limit of the water volumetric "
"fraction."
)
raise ValueError
@@ -1403,10 +1397,10 @@ class SoilPeplinski(UserObjectMulti):
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."
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)
@@ -1444,46 +1438,44 @@ class MaterialRange(UserObjectMulti):
ro_upper = self.kwargs["ro_upper"]
ID = self.kwargs["id"]
except KeyError:
logger.exception(f"{self.params_str()} requires at exactly nine " + "parameters.")
logger.exception(f"{self.params_str()} requires at exactly nine parameters.")
raise
if er_lower < 1:
logger.exception(
f"{self.params_str()} requires a value greater or equal to 1 "
+ "for the lower range of relative permittivity."
"for the lower range of relative permittivity."
)
raise ValueError
if mr_lower < 1:
logger.exception(
f"{self.params_str()} requires a value greater or equal to 1 "
+ "for the lower range of relative magnetic permeability."
"for the lower range of relative magnetic permeability."
)
raise ValueError
if sigma_lower < 0:
logger.exception(f"{self.params_str()} requires a positive value " + "for the lower limit of conductivity.")
logger.exception(f"{self.params_str()} requires a positive value for the lower limit of conductivity.")
raise ValueError
if ro_lower < 0:
logger.exception(f"{self.params_str()} requires a positive value " + "for the lower range magnetic loss.")
logger.exception(f"{self.params_str()} requires a positive value for the lower range magnetic loss.")
raise ValueError
if er_upper < 1:
logger.exception(
f"{self.params_str()} requires a value greater or equal to 1"
+ "for the upper range of relative permittivity."
"for the upper range of relative permittivity."
)
raise ValueError
if mr_upper < 1:
logger.exception(
f"{self.params_str()} requires a value greater or equal to 1"
+ "for the upper range of relative magnetic permeability"
"for the upper range of relative magnetic permeability"
)
raise ValueError
if sigma_upper < 0:
logger.exception(f"{self.params_str()} requires a positive value " + "for the upper range of conductivity.")
logger.exception(f"{self.params_str()} requires a positive value for the upper range of conductivity.")
raise ValueError
if ro_upper < 0:
logger.exception(
f"{self.params_str()} requires a positive value " + "for the upper range of magnetic loss."
)
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(f"{self.params_str()} with ID {ID} already exists")
@@ -1495,9 +1487,9 @@ class MaterialRange(UserObjectMulti):
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"
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)
@@ -1521,7 +1513,7 @@ class MaterialList(UserObjectMulti):
list_of_materials = self.kwargs["list_of_materials"]
ID = self.kwargs["id"]
except KeyError:
logger.exception(f"{self.params_str()} requires at at least 2 " + "parameters.")
logger.exception(f"{self.params_str()} requires at at least 2 parameters.")
raise
if any(x.ID == ID for x in grid.mixingmodels):
@@ -1530,9 +1522,7 @@ class MaterialList(UserObjectMulti):
s = ListMaterialUser(ID, list_of_materials)
logger.info(
f"{self.grid_name(grid)}A list of materials used to " + f"create {s.ID} that includes {s.mat}, created"
)
logger.info(f"{self.grid_name(grid)}A list of materials used to create {s.ID} that includes {s.mat}, created")
grid.mixingmodels.append(s)
@@ -1579,7 +1569,7 @@ class GeometryView(UserObjectMulti):
output_type = self.kwargs["output_type"].lower()
filename = self.kwargs["filename"]
except KeyError:
logger.exception(f"{self.params_str()} requires exactly eleven " + "parameters.")
logger.exception(f"{self.params_str()} requires exactly eleven parameters.")
raise
GeometryViewUser = self.geometry_view_constructor(grid, output_type)
@@ -1597,25 +1587,23 @@ class GeometryView(UserObjectMulti):
dx, dy, dz = uip.discretise_static_point(dl)
if dx < 0 or dy < 0 or dz < 0:
logger.exception(f"{self.params_str()} the step size should not be " + "less than zero.")
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(f"{self.params_str()} the step size should be " + "less than the domain size.")
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(
f"{self.params_str()} the step size should not " + "be less than the spatial discretisation."
)
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(f"{self.params_str()} requires type to be either " + "n (normal) or f (fine).")
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(
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)"
"discretisation for the geometry view to be the "
"same as the model for geometry view of "
"type f (fine)"
)
raise ValueError
@@ -1623,10 +1611,10 @@ class GeometryView(UserObjectMulti):
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."
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)
@@ -1656,7 +1644,7 @@ class GeometryObjectsWrite(UserObjectMulti):
p2 = self.kwargs["p2"]
basefilename = self.kwargs["filename"]
except KeyError:
logger.exception(f"{self.params_str()} requires exactly seven " + "parameters.")
logger.exception(f"{self.params_str()} requires exactly seven parameters.")
raise
p1, p2 = uip.check_box_points(p1, p2, self.params_str())
@@ -1721,7 +1709,7 @@ class PMLCFS(UserObjectMulti):
sigmamin = self.kwargs["sigmamin"]
sigmamax = self.kwargs["sigmamax"]
except KeyError:
logger.exception(f"{self.params_str()} requires exactly twelve " + "parameters.")
logger.exception(f"{self.params_str()} requires exactly twelve parameters.")
raise
if (
@@ -1730,7 +1718,7 @@ class PMLCFS(UserObjectMulti):
or sigmascalingprofile not in CFSParameter.scalingprofiles.keys()
):
logger.exception(
f"{self.params_str()} must have scaling type " + f"{','.join(CFSParameter.scalingprofiles.keys())}"
f"{self.params_str()} must have scaling type {','.join(CFSParameter.scalingprofiles.keys())}"
)
raise ValueError
if (
@@ -1738,9 +1726,7 @@ class PMLCFS(UserObjectMulti):
or kappascalingdirection not in CFSParameter.scalingdirections
or sigmascalingdirection not in CFSParameter.scalingdirections
):
logger.exception(
f"{self.params_str()} must have scaling type " + f"{','.join(CFSParameter.scalingdirections)}"
)
logger.exception(f"{self.params_str()} must have scaling type {','.join(CFSParameter.scalingdirections)}")
raise ValueError
if (
float(alphamin) < 0
@@ -1749,7 +1735,7 @@ class PMLCFS(UserObjectMulti):
or float(kappamax) < 0
or float(sigmamin) < 0
):
logger.exception(f"{self.params_str()} minimum and maximum scaling " + "values must be greater than zero.")
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:
@@ -1795,7 +1781,7 @@ class PMLCFS(UserObjectMulti):
grid.pmls["cfs"].append(cfs)
if len(grid.pmls["cfs"]) > 2:
logger.exception(f"{self.params_str()} can only be used up to two " + "times, for up to a 2nd order PML.")
logger.exception(f"{self.params_str()} can only be used up to two times, for up to a 2nd order PML.")
raise ValueError

查看文件

@@ -348,8 +348,8 @@ class SrcSteps(UserObjectSingle):
logger.info(
f"Simple sources will step {G.srcsteps[0] * G.dx:g}m, "
+ f"{G.srcsteps[1] * G.dy:g}m, {G.srcsteps[2] * G.dz:g}m "
+ "for each model run."
f"{G.srcsteps[1] * G.dy:g}m, {G.srcsteps[2] * G.dz:g}m "
"for each model run."
)
@@ -373,8 +373,8 @@ class RxSteps(UserObjectSingle):
logger.info(
f"All receivers will step {G.rxsteps[0] * G.dx:g}m, "
+ f"{G.rxsteps[1] * G.dy:g}m, {G.rxsteps[2] * G.dz:g}m "
+ "for each model run."
f"{G.rxsteps[1] * G.dy:g}m, {G.rxsteps[2] * G.dz:g}m "
"for each model run."
)
@@ -418,8 +418,7 @@ class ExcitationFile(UserObjectSingle):
logger.info(f"Excitation file: {excitationfile}")
# Get waveform names
with open(excitationfile, "r") as f:
waveformIDs = f.readline().split()
waveformIDs = np.loadtxt(excitationfile, max_rows=1, dtype=str)
# Read all waveform values into an array
waveformvalues = np.loadtxt(excitationfile, skiprows=1, dtype=config.sim_config.dtypes["float_or_double"])
@@ -434,12 +433,12 @@ class ExcitationFile(UserObjectSingle):
waveformtime = np.arange(0, G.timewindow + G.dt, G.dt)
timestr = "simulation time array"
for waveform in range(len(waveformIDs)):
if any(x.ID == waveformIDs[waveform] for x in G.waveforms):
logger.exception(f"Waveform with ID {waveformIDs[waveform]} already exists")
for waveformID in waveformIDs:
if any(x.ID == waveformID for x in G.waveforms):
logger.exception(f"Waveform with ID {waveformID} already exists")
raise ValueError
w = Waveform()
w.ID = waveformIDs[waveform]
w.ID = waveformID
w.type = "user"
# Select correct column of waveform values depending on array shape
@@ -462,8 +461,8 @@ class ExcitationFile(UserObjectSingle):
logger.info(
f"User waveform {w.ID} created using {timestr} and, if "
+ f"required, interpolation parameters (kind: {kwargs['kind']}, "
+ f"fill value: {kwargs['fill_value']})."
f"required, interpolation parameters (kind: {kwargs['kind']}, "
f"fill value: {kwargs['fill_value']})."
)
G.waveforms.append(w)

查看文件

@@ -96,7 +96,7 @@ class Context:
"""Prints the total simulation time based on context."""
s = (
f"\n=== Simulation completed in "
+ f"{humanize.precisedelta(datetime.timedelta(seconds=self.tsimend - self.tsimstart), format='%0.4f')}"
f"{humanize.precisedelta(datetime.timedelta(seconds=self.tsimend - self.tsimstart), format='%0.4f')}"
)
logger.basic(f"{s} {'=' * (get_terminal_width() - 1 - len(s))}\n")

查看文件

@@ -427,19 +427,11 @@ def dispersion_analysis(G):
results["error"] = "user waveform detected."
else:
# User-defined waveform
if waveform.type == "user":
iterations = G.iterations
# Built-in waveform
else:
# Time to analyse waveform - 4*pulse_width as using entire
# time window can result in demanding FFT
waveform.calculate_coefficients()
iterations = round_value(4 * waveform.chi / G.dt)
if iterations > G.iterations:
iterations = G.iterations
# Time to analyse waveform - 4*pulse_width as using entire
# time window can result in demanding FFT
waveform.calculate_coefficients()
iterations = round_value(4 * waveform.chi / G.dt)
iterations = min(iterations, G.iterations)
waveformvalues = np.zeros(G.iterations)
for iteration in range(G.iterations):
waveformvalues[iteration] = waveform.calculate_value(iteration * G.dt, G.dt)

查看文件

@@ -185,8 +185,7 @@ def write_processed_file(processedlines):
f.write(f"{item}")
logger.info(
f"Written input commands, after processing any Python "
+ f"code and include commands, to file: {processedfile}\n"
f"Written input commands, after processing any Python code and include commands, to file: {processedfile}\n"
)

查看文件

@@ -64,9 +64,7 @@ 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(
f"{cmd} requires exactly one parameter to specify " + f"the number of CPU OpenMP threads to use"
)
logger.exception(f"{cmd} requires exactly one parameter to specify the number of CPU OpenMP threads to use")
raise ValueError
omp_threads = OMPThreads(n=tmp[0])
@@ -106,7 +104,7 @@ def process_singlecmds(singlecmds):
if len(tmp) != 1:
logger.exception(
f"{cmd} requires exactly one parameter to specify the "
+ f"time window. Either in seconds or number of iterations."
f"time window. Either in seconds or number of iterations."
)
raise ValueError
tmp = tmp[0].lower()

查看文件

@@ -317,9 +317,8 @@ class PeplinskiSoil:
# Check to see if the material already exists before creating a new one
requiredID = "|{:.4f}|".format(float(muiter[0]))
material = next((x for x in G.materials if x.ID == requiredID), None)
if muiter.index == 0:
if material:
self.matID.append(material.numID)
if muiter.index == 0 and material:
self.matID.append(material.numID)
if not material:
m = DispersiveMaterial(len(G.materials), requiredID)
m.type = "debye"
@@ -412,9 +411,8 @@ class RangeMaterial:
# Check to see if the material already exists before creating a new one
requiredID = f"|{float(er):.4f}+{float(se):.4f}+{float(mr):.4f}+{float(sm):.4f}|"
material = next((x for x in G.materials if x.ID == requiredID), None)
if iter == 0:
if material:
self.matID.append(material.numID)
if iter == 0 and material:
self.matID.append(material.numID)
if not material:
m = Material(len(G.materials), requiredID)
m.type = ""

查看文件

@@ -208,22 +208,7 @@ class Snapshot:
G: FDTDGrid class describing a grid in a model.
"""
celldata = {}
for k, v in self.outputs.items():
if v:
if k == "Ex":
celldata[k] = self.snapfields["Ex"]
if k == "Ey":
celldata[k] = self.snapfields["Ey"]
if k == "Ez":
celldata[k] = self.snapfields["Ez"]
if k == "Hx":
celldata[k] = self.snapfields["Hx"]
if k == "Hy":
celldata[k] = self.snapfields["Hy"]
if k == "Hz":
celldata[k] = self.snapfields["Hz"]
celldata = {k: self.snapfields[k] for k in ["Ex", "Ey", "Ez", "Hx", "Hy", "Hz"] if self.outputs.get(k)}
imageToVTK(
str(self.filename.with_suffix("")),
@@ -255,24 +240,10 @@ class Snapshot:
f.attrs["dx_dy_dz"] = (self.dx * G.dx, self.dy * G.dy, self.dz * G.dz)
f.attrs["time"] = self.time * G.dt
if self.outputs["Ex"]:
f["Ex"] = self.snapfields["Ex"]
pbar.update(n=self.snapfields["Ex"].nbytes)
if self.outputs["Ey"]:
f["Ey"] = self.snapfields["Ey"]
pbar.update(n=self.snapfields["Ey"].nbytes)
if self.outputs["Ez"]:
f["Ez"] = self.snapfields["Ez"]
pbar.update(n=self.snapfields["Ez"].nbytes)
if self.outputs["Hx"]:
f["Hx"] = self.snapfields["Hx"]
pbar.update(n=self.snapfields["Hx"].nbytes)
if self.outputs["Hy"]:
f["Hy"] = self.snapfields["Hy"]
pbar.update(n=self.snapfields["Hy"].nbytes)
if self.outputs["Hz"]:
f["Hz"] = self.snapfields["Hz"]
pbar.update(n=self.snapfields["Hz"].nbytes)
for key in ["Ex", "Ey", "Ez", "Hx", "Hy", "Hz"]:
if self.outputs[key]:
f[key] = self.snapfields[key]
pbar.update(n=self.snapfields[key].nbytes)
f.close()

查看文件

@@ -70,9 +70,9 @@ class UserInput:
# Incorrect index
i = p[v.index(err.args[0])]
if name:
s = f"\n'{cmd_str}' {err.args[0]} {name}-coordinate {i * dl:g} " + "is not within the model domain"
s = f"\n'{cmd_str}' {err.args[0]} {name}-coordinate {i * dl:g} is not within the model domain"
else:
s = f"\n'{cmd_str}' {err.args[0]}-coordinate {i * dl:g} is not " + "within the model domain"
s = f"\n'{cmd_str}' {err.args[0]}-coordinate {i * dl:g} is not within the model domain"
logger.exception(s)
raise
@@ -108,7 +108,7 @@ class MainGridUserInput(UserInput):
p = self.check_point(p, cmd_str, name)
if self.grid.within_pml(p):
logger.warning(f"'{cmd_str}' sources and receivers should not " + "normally be positioned within the PML.")
logger.warning(f"'{cmd_str}' sources and receivers should not normally be positioned within the PML.")
return p
@@ -117,7 +117,7 @@ class MainGridUserInput(UserInput):
p2 = self.check_point(p2, cmd_str, name="upper")
if np.greater(p1, p2).any():
logger.exception(f"'{cmd_str}' the lower coordinates should be less " + "than the upper coordinates.")
logger.exception(f"'{cmd_str}' the lower coordinates should be less than the upper coordinates.")
raise ValueError
return p1, p2
@@ -186,7 +186,7 @@ class SubgridUserInput(MainGridUserInput):
# Provide user within a warning if they have placed objects within
# the OS non-working region.
if np.less(p_t, self.inner_bound).any() or np.greater(p_t, self.outer_bound).any():
logger.warning(f"'{cmd_str}' this object traverses the Outer " + "Surface. This is an advanced feature.")
logger.warning(f"'{cmd_str}' this object traverses the Outer Surface. This is an advanced feature.")
return p_t
def discretise_static_point(self, p):

查看文件

@@ -137,8 +137,8 @@ for i, model in enumerate(testmodels):
if filetest[path + outputstest[0]].dtype != fileref[path + outputsref[0]].dtype:
logger.warning(
f"Type of floating point number in test model "
+ f"({filetest[path + outputstest[0]].dtype}) does not "
+ f"match type in reference solution ({fileref[path + outputsref[0]].dtype})\n"
f"({filetest[path + outputstest[0]].dtype}) does not "
f"match type in reference solution ({fileref[path + outputsref[0]].dtype})\n"
)
float_or_doubleref = fileref[path + outputsref[0]].dtype
float_or_doubletest = filetest[path + outputstest[0]].dtype
@@ -271,11 +271,11 @@ for name, data in sorted(testresults.items()):
if "analytical" in name:
logger.info(
f"Test '{name}.in' using v.{data['Test version']} compared "
+ f"to analytical solution. Max difference {data['Max diff']:.2f}dB."
f"to analytical solution. Max difference {data['Max diff']:.2f}dB."
)
else:
logger.info(
f"Test '{name}.in' using v.{data['Test version']} compared to "
+ f"reference solution using v.{data['Ref version']}. Max difference "
+ f"{data['Max diff']:.2f}dB."
f"reference solution using v.{data['Ref version']}. Max difference "
f"{data['Max diff']:.2f}dB."
)

查看文件

@@ -169,10 +169,10 @@ if __name__ == "__main__":
# Check waveform parameters
if args.type.lower() not in Waveform.types:
logging.exception(f"The waveform must have one of the following types " + f"{', '.join(Waveform.types)}")
logging.exception(f"The waveform must have one of the following types {', '.join(Waveform.types)}")
raise ValueError
if args.freq <= 0:
logging.exception("The waveform requires an excitation frequency value of " + "greater than zero")
logging.exception("The waveform requires an excitation frequency value of greater than zero")
raise ValueError
# Create waveform instance

查看文件

@@ -55,11 +55,7 @@ class Cursor(object):
) # Convert pixel values from float (0-1) to integer (0-255)
match = pixel_match(materials, pixel)
if match is False:
logger.info(
"x, y: {} {} px; RGB: {}; material ID: {}".format(
int(x), int(y), pixel[:-1], len(self.materials)
)
)
logger.info(f"x, y: {int(x)} {int(y)} px; RGB: {pixel[:-1]}; material ID: {len(self.materials)}")
materials.append(pixel)
@@ -103,7 +99,7 @@ if __name__ == "__main__":
imdata = np.rot90(im, k=3) # Rotate 90CW
imdata = np.floor(imdata * 255).astype(np.int16) # Convert pixel values from float (0-1) to integer (0-255)
logger.info("Reading PNG image file: {}".format(os.path.split(args.imagefile)[1]))
logger.info(f"Reading PNG image file: {os.path.split(args.imagefile)[1]}")
logger.info(
" 1. Select discrete material colours by clicking on parts of the image.\n 2. When all materials have been selected close the image."
)
@@ -122,7 +118,7 @@ if __name__ == "__main__":
dx_dy_dz = (args.dxdydz[0][0], args.dxdydz[0][1], args.dxdydz[0][2])
# Filename for geometry (HDF5) file
hdf5file = os.path.splitext(args.imagefile)[0] + ".h5"
hdf5file = f"{os.path.splitext(args.imagefile)[0]}.h5"
# Array to store geometry data (initialised as background, i.e. -1)
data = np.ones((imdata.shape[0], imdata.shape[1], args.zcells), dtype=np.int16) * -1
@@ -140,4 +136,4 @@ if __name__ == "__main__":
# Write data to file
fout.create_dataset("data", data=data)
logger.info("Written HDF5 file: {}".format(os.path.split(hdf5file)[1]))
logger.info(f"Written HDF5 file: {os.path.split(hdf5file)[1]}")