Updated a few more files to make their code much cleaner and better.

这个提交包含在:
Sai Suraj
2023-04-18 19:53:46 +05:30
父节点 0363f176f8
当前提交 7457f8fec0
共有 3 个文件被更改,包括 31 次插入38 次删除

查看文件

@@ -88,24 +88,25 @@ class CylindricalSector(UserObjectGeometry):
try: try:
materialsrequested = self.kwargs['material_ids'] materialsrequested = self.kwargs['material_ids']
except KeyError: except KeyError:
logger.exception(self.__str__() + ' No materials have been specified') logger.exception(f'{self.__str__()} No materials have been specified')
raise raise
sectorstartangle = 2 * np.pi * (start / 360) sectorstartangle = 2 * np.pi * (start / 360)
sectorangle = 2 * np.pi * (end / 360) sectorangle = 2 * np.pi * (end / 360)
if normal != 'x' and normal != 'y' and normal != 'z': if normal not in ['x', 'y', 'z']:
logger.exception(self.__str__() + ' the normal direction must be either x, y or z.') logger.exception(f'{self.__str__()} the normal direction must be either ' +
f'x, y or z.')
raise ValueError raise ValueError
if r <= 0: 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: if sectorstartangle < 0 or sectorangle <= 0:
logger.exception(self.__str__() + ' the starting angle and sector ' + logger.exception(f'{self.__str__()} the starting angle and sector angle should be ' +
'angle should be a positive values.') f'a positive values.')
raise ValueError raise ValueError
if sectorstartangle >= 2 * np.pi or sectorangle >= 2 * np.pi: if sectorstartangle >= 2 * np.pi or sectorangle >= 2 * np.pi:
logger.exception(self.__str__() + ' the starting angle and sector ' + logger.exception(f'{self.__str__()} the starting angle and sector angle must be ' +
'angle must be less than 360 degrees.') f'less than 360 degrees.')
raise ValueError raise ValueError
# Look up requested materials in existing list of material instances # Look up requested materials in existing list of material instances
@@ -113,7 +114,7 @@ class CylindricalSector(UserObjectGeometry):
if len(materials) != len(materialsrequested): if len(materials) != len(materialsrequested):
notfound = [x for x in materialsrequested if x not in materials] 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 raise ValueError
if thickness > 0: if thickness > 0:
@@ -122,13 +123,12 @@ class CylindricalSector(UserObjectGeometry):
averaging = materials[0].averagable and averagecylindricalsector averaging = materials[0].averagable and averagecylindricalsector
numID = numIDx = numIDy = numIDz = materials[0].numID numID = numIDx = numIDy = numIDz = materials[0].numID
# Uniaxial anisotropic case
elif len(materials) == 3: elif len(materials) == 3:
averaging = False averaging = False
numIDx = materials[0].numID numIDx = materials[0].numID
numIDy = materials[1].numID numIDy = materials[1].numID
numIDz = materials[2].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] averagedmaterial = [x for x in grid.materials if x.ID == requiredID]
if averagedmaterial: if averagedmaterial:
numID = averagedmaterial.numID numID = averagedmaterial.numID

查看文件

@@ -62,15 +62,15 @@ class Edge(UserObjectGeometry):
p2 = self.kwargs['p2'] p2 = self.kwargs['p2']
material_id = self.kwargs['material_id'] material_id = self.kwargs['material_id']
except KeyError: except KeyError:
logger.exception(self.__str__() + ' requires exactly 3 parameters') logger.exception(f'{self.__str__()} requires exactly 3 parameters')
raise raise
if self.do_rotate: if self.do_rotate:
self._do_rotate() self._do_rotate()
p3 = uip.round_to_grid_static_point(p1) p3 = uip.round_to_grid_static_point(p1)
p4 = uip.round_to_grid_static_point(p2) p4 = uip.round_to_grid_static_point(p2)
p1, p2 = uip.check_box_points(p1, p2, self.__str__()) p1, p2 = uip.check_box_points(p1, p2, self.__str__())
xs, ys, zs = p1 xs, ys, zs = p1
xf, yf, zf = p2 xf, yf, zf = p2
@@ -83,31 +83,24 @@ class Edge(UserObjectGeometry):
# Check for valid orientations # Check for valid orientations
# x-orientated edge # x-orientated edge
if xs != xf: if (xs != xf
if ys != yf or zs != zf: and (ys != yf or zs != zf)
logger.exception(self.__str__() + ' the edge is not specified correctly') or xs == xf
raise ValueError and ys != yf
else: and zs != zf):
for i in range(xs, xf): logger.exception(f'{self.__str__()} the edge is not specified correctly')
build_edge_x(i, ys, zs, material.numID, grid.rigidE, grid.rigidH, grid.ID) 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: elif ys != yf:
if xs != xf or zs != zf: for j in range(ys, yf):
logger.exception(self.__str__() + ' the edge is not specified correctly') build_edge_y(xs, j, zs, material.numID, grid.rigidE, grid.rigidH, grid.ID)
raise ValueError
else:
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: elif zs != zf:
if xs != xf or ys != yf: for k in range(zs, zf):
logger.exception(self.__str__() + ' the edge is not specified correctly') build_edge_z(xs, ys, k, material.numID, grid.rigidE, grid.rigidH, grid.ID)
raise ValueError
else:
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(self.grid_name(grid) + f'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'{p3[2]:g}m, to {p4[0]:g}m, {p4[1]:g}m, {p4[2]:g}m of ' +

查看文件

@@ -53,7 +53,7 @@ class Ellipsoid(UserObjectGeometry):
zr = self.kwargs['zr'] zr = self.kwargs['zr']
except KeyError: 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 raise
# Check averaging # Check averaging
@@ -73,7 +73,7 @@ class Ellipsoid(UserObjectGeometry):
try: try:
materialsrequested = self.kwargs['material_ids'] materialsrequested = self.kwargs['material_ids']
except KeyError: except KeyError:
logger.exception(self.__str__() + ' no materials have been specified') logger.exception(f'{self.__str__()} no materials have been specified')
raise raise
# Centre of sphere # Centre of sphere
@@ -86,7 +86,7 @@ class Ellipsoid(UserObjectGeometry):
if len(materials) != len(materialsrequested): if len(materials) != len(materialsrequested):
notfound = [x for x in materialsrequested if x not in materials] 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 raise ValueError
# Isotropic case # Isotropic case