Added a pre-commit config file and reformatted all the files accordingly by using it.

这个提交包含在:
Sai-Suraj-27
2023-06-26 16:09:39 +05:30
父节点 c71e87e34f
当前提交 f9dd7f2420
共有 155 个文件被更改,包括 11383 次插入8802 次删除

查看文件

@@ -32,13 +32,13 @@ class Cone(UserObjectGeometry):
can have different radii and one of them can be zero.
Attributes:
p1: list of the coordinates (x,y,z) of the centre of the first face
p1: list of the coordinates (x,y,z) of the centre of the first face
of the cone.
p2: list of the coordinates (x,y,z) of the centre of the second face
p2: list of the coordinates (x,y,z) of the centre of the second face
of the cone.
r1: float of the radius of the first face of the cone.
r2: float of the radius of the second face of the cone.
material_id: string for the material identifier that must correspond
material_id: string for the material identifier that must correspond
to material that has already been defined.
material_ids: list of material identifiers in the x, y, z directions.
averaging: string (y or n) used to switch on and off dielectric smoothing.
@@ -46,22 +46,22 @@ class Cone(UserObjectGeometry):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.hash = '#cone'
self.hash = "#cone"
def create(self, grid, uip):
try:
p1 = self.kwargs['p1']
p2 = self.kwargs['p2']
r1 = self.kwargs['r1']
r2 = self.kwargs['r2']
p1 = self.kwargs["p1"]
p2 = self.kwargs["p2"]
r1 = self.kwargs["r1"]
r2 = self.kwargs["r2"]
except KeyError:
logger.exception(f'{self.__str__()} please specify two points and two radii')
logger.exception(f"{self.__str__()} please specify two points and two radii")
raise
# Check averaging
try:
# Try user-specified averaging
averagecylinder = self.kwargs['averaging']
averagecylinder = self.kwargs["averaging"]
except KeyError:
# Otherwise go with the grid default
averagecylinder = grid.averagevolumeobjects
@@ -69,13 +69,13 @@ class Cone(UserObjectGeometry):
# Check materials have been specified
# Isotropic case
try:
materialsrequested = [self.kwargs['material_id']]
materialsrequested = [self.kwargs["material_id"]]
except KeyError:
# Anisotropic case
try:
materialsrequested = self.kwargs['material_ids']
materialsrequested = self.kwargs["material_ids"]
except KeyError:
logger.exception(f'{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,17 +85,15 @@ 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 " + f"{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 " + f"{r2:g} should be a positive value.")
raise ValueError
if r1 == 0 and r2 == 0:
logger.exception(f'{self.__str__()} both radii cannot be zero.')
logger.exception(f"{self.__str__()} both radii cannot be zero.")
raise ValueError
# Look up requested materials in existing list of material instances
@@ -103,7 +101,7 @@ class Cone(UserObjectGeometry):
if len(materials) != len(materialsrequested):
notfound = [x for x in materialsrequested if x not in materials]
logger.exception(f'{self.__str__()} material(s) {notfound} do not exist')
logger.exception(f"{self.__str__()} material(s) {notfound} do not exist")
raise ValueError
# Isotropic case
@@ -117,33 +115,50 @@ class Cone(UserObjectGeometry):
numIDx = materials[0].numID
numIDy = materials[1].numID
numIDz = materials[2].numID
requiredID = materials[0].ID + '+' + materials[1].ID + '+' + materials[2].ID
requiredID = 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
else:
numID = len(grid.materials)
m = Material(numID, requiredID)
m.type = 'dielectric-smoothed'
m.type = "dielectric-smoothed"
# Create dielectric-smoothed constituents for material
m.er = np.mean((materials[0].er, materials[1].er,
materials[2].er), axis=0)
m.se = np.mean((materials[0].se, materials[1].se,
materials[2].se), axis=0)
m.mr = np.mean((materials[0].mr, materials[1].mr,
materials[2].mr), axis=0)
m.sm = np.mean((materials[0].sm, materials[1].sm,
materials[2].sm), axis=0)
m.er = np.mean((materials[0].er, materials[1].er, materials[2].er), axis=0)
m.se = np.mean((materials[0].se, materials[1].se, materials[2].se), axis=0)
m.mr = np.mean((materials[0].mr, materials[1].mr, materials[2].mr), axis=0)
m.sm = np.mean((materials[0].sm, materials[1].sm, materials[2].sm), axis=0)
# Append the new material object to the materials list
grid.materials.append(m)
build_cone(x1, y1, z1, x2, y2, z2, r1, r2, grid.dx, grid.dy, grid.dz,
numID, numIDx, numIDy, numIDz, averaging, grid.solid,
grid.rigidE, grid.rigidH, grid.ID)
build_cone(
x1,
y1,
z1,
x2,
y2,
z2,
r1,
r2,
grid.dx,
grid.dy,
grid.dz,
numID,
numIDx,
numIDy,
numIDz,
averaging,
grid.solid,
grid.rigidE,
grid.rigidH,
grid.ID,
)
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}.")
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}."
)