Skip to content

Commit ae7ddd9

Browse files
Merge pull request #47 from Spectre5/style-updates
some linting cleanup
2 parents 6dd68d0 + 39bc217 commit ae7ddd9

File tree

12 files changed

+280
-284
lines changed

12 files changed

+280
-284
lines changed

docs/source/rst/api.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ Material Class
125125
:show-inheritance:
126126
:members:
127127

128-
GeometryCleaner Class
129-
"""""""""""""""""""""
128+
GeometryCleanerMixin Class
129+
""""""""""""""""""""""""""
130130

131-
.. autoclass:: sectionproperties.pre.pre.GeometryCleaner
131+
.. autoclass:: sectionproperties.pre.pre.GeometryCleanerMixin
132132
:show-inheritance:
133133
:members:
134134

docs/source/rst/examples.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -969,10 +969,10 @@ accuracy of the result compared with the time taken to obtain the solution::
969969
t_calc.append(t) # save the time
970970
j_calc.append(j) # save the torsion constant
971971
# print the result
972-
str = "Mesh Size: {0}; ".format(mesh_size)
973-
str += "Solution Time {0:.5f} s; ".format(t)
974-
str += "Torsion Constant: {0:.12e}".format(j)
975-
print(str)
972+
msg = "Mesh Size: {0}; ".format(mesh_size)
973+
msg += "Solution Time {0:.5f} s; ".format(t)
974+
msg += "Torsion Constant: {0:.12e}".format(j)
975+
print(msg)
976976

977977
correct_val = j_calc[0] # assume the finest mesh gives the 'correct' value
978978
j_np = np.array(j_calc) # convert results to a numpy array

sectionproperties/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.0.8"
1+
__version__ = "1.0.8"

sectionproperties/analysis/cross_section.py

Lines changed: 72 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,9 @@ def init():
121121
# if materials are specified, check that the right number of material properties are
122122
# specified and then populate material_groups list
123123
if materials is not None:
124-
str = "Number of materials ({0}), ".format(len(materials))
125-
str += "should match the number of regions ({0}).".format(
126-
max(attributes) + 1)
127-
assert(len(materials) == max(attributes) + 1), str
124+
msg = "Number of materials ({0}), ".format(len(materials))
125+
msg += "should match the number of regions ({0}).".format(max(attributes) + 1)
126+
assert(len(materials) == max(attributes) + 1), msg
128127

129128
# add a MaterialGroup object to the material_groups list for each uniquely
130129
# encountered material
@@ -783,10 +782,10 @@ def calc_plastic():
783782
# calculate plastic properties
784783
try:
785784
plastic_section.calculate_plastic_properties(self, verbose)
786-
except ValueError:
787-
str = "Plastic section properties calculation failed. Contact "
788-
str += "robbie.vanleeuwen@gmail.com with your analysis parameters."
789-
raise RuntimeError(str)
785+
except ValueError as exp:
786+
msg = "Plastic section properties calculation failed. Contact "
787+
msg += "robbie.vanleeuwen@gmail.com with your analysis parameters."
788+
raise RuntimeError(msg) from exp
790789

791790
if time_info:
792791
text = "--Calculating plastic properties..."
@@ -1043,7 +1042,7 @@ def plot_mesh(self, ax=None, pause=True, alpha=1, materials=False, mask=None):
10431042
if ax is None:
10441043
ax_supplied = False
10451044
(fig, ax) = plt.subplots()
1046-
post.setup_plot(ax, pause)
1045+
post.setup_plot(pause)
10471046
else:
10481047
ax_supplied = True
10491048

@@ -1081,10 +1080,14 @@ def plot_mesh(self, ax=None, pause=True, alpha=1, materials=False, mask=None):
10811080
# display the legend
10821081
ax.legend(loc='center left', bbox_to_anchor=(1, 0.5), handles=legend_list)
10831082

1084-
# if no axes object is supplied, finish the plot
1085-
if not ax_supplied:
1086-
post.finish_plot(ax, pause, title='Finite Element Mesh')
1087-
return (fig, ax)
1083+
if ax_supplied:
1084+
# if an axis is supplied, return None for figure and axes to indicate that it is not
1085+
# yet finished
1086+
return None, None
1087+
1088+
# if no axes object is supplied, finish the plot and return the figure and axes
1089+
post.finish_plot(ax, pause, title='Finite Element Mesh')
1090+
return (fig, ax)
10881091

10891092
def plot_centroids(self, pause=True):
10901093
"""Plots the elastic centroid, the shear centre, the plastic centroids and the principal
@@ -1143,7 +1146,7 @@ def plot_centroids(self, pause=True):
11431146

11441147
# create plot and setup the plot
11451148
(fig, ax) = plt.subplots()
1146-
post.setup_plot(ax, pause)
1149+
post.setup_plot(pause)
11471150

11481151
# plot the finite element mesh
11491152
self.plot_mesh(ax, pause, alpha=0.5)
@@ -1466,10 +1469,10 @@ def get_sc(self):
14661469

14671470
if self.section_props.x_se is None:
14681471
return (None, None)
1469-
else:
1470-
# add centroid location to move section back to original location
1471-
x_se = self.section_props.x_se + self.section_props.cx
1472-
y_se = self.section_props.y_se + self.section_props.cy
1472+
1473+
# add centroid location to move section back to original location
1474+
x_se = self.section_props.x_se + self.section_props.cx
1475+
y_se = self.section_props.y_se + self.section_props.cy
14731476

14741477
return (x_se, y_se)
14751478

@@ -1488,9 +1491,9 @@ def get_sc_p(self):
14881491

14891492
if self.section_props.x11_se is None:
14901493
return (None, None)
1491-
else:
1492-
x11_se = self.section_props.x11_se
1493-
y22_se = self.section_props.y22_se
1494+
1495+
x11_se = self.section_props.x11_se
1496+
y22_se = self.section_props.y22_se
14941497

14951498
return (x11_se, y22_se)
14961499

@@ -1509,10 +1512,10 @@ def get_sc_t(self):
15091512

15101513
if self.section_props.x_st is None:
15111514
return (None, None)
1512-
else:
1513-
# add centroid location to move section back to original location
1514-
x_st = self.section_props.x_st + self.section_props.cx
1515-
y_st = self.section_props.y_st + self.section_props.cy
1515+
1516+
# add centroid location to move section back to original location
1517+
x_st = self.section_props.x_st + self.section_props.cx
1518+
y_st = self.section_props.y_st + self.section_props.cy
15161519

15171520
return (x_st, y_st)
15181521

@@ -1617,10 +1620,10 @@ def get_pc(self):
16171620

16181621
if self.section_props.x_pc is None:
16191622
return (None, None)
1620-
else:
1621-
# add centroid location to move section back to original location
1622-
x_pc = self.section_props.x_pc + self.section_props.cx
1623-
y_pc = self.section_props.y_pc + self.section_props.cy
1623+
1624+
# add centroid location to move section back to original location
1625+
x_pc = self.section_props.x_pc + self.section_props.cx
1626+
y_pc = self.section_props.y_pc + self.section_props.cy
16241627

16251628
return (x_pc, y_pc)
16261629

@@ -1639,14 +1642,14 @@ def get_pc_p(self):
16391642

16401643
if self.section_props.x11_pc is None:
16411644
return (None, None)
1642-
else:
1643-
# determine the position of the plastic centroid in the global axis
1644-
(x_pc, y_pc) = fea.global_coordinate(
1645-
self.section_props.phi, self.section_props.x11_pc, self.section_props.y22_pc
1646-
)
16471645

1648-
# add centroid location to move section back to original location
1649-
return (x_pc + self.section_props.cx, y_pc + self.section_props.cy)
1646+
# determine the position of the plastic centroid in the global axis
1647+
(x_pc, y_pc) = fea.global_coordinate(
1648+
self.section_props.phi, self.section_props.x11_pc, self.section_props.y22_pc
1649+
)
1650+
1651+
# add centroid location to move section back to original location
1652+
return (x_pc + self.section_props.cx, y_pc + self.section_props.cy)
16501653

16511654
def get_s(self):
16521655
"""
@@ -1766,9 +1769,15 @@ def __init__(self, geometry, materials, debug):
17661769
self.materials = copy.deepcopy(materials)
17671770
self.debug = debug
17681771

1772+
# initialize variables to be defined later within calculate_plastic_force
1773+
self.c_top = [0.0, 0.0]
1774+
self.c_bot = [0.0, 0.0]
1775+
self.f_top = 0.0
1776+
self.f_bot = 0.0
1777+
17691778
if self.materials is not None:
17701779
# create dummy control point at the start of the list
1771-
(x_min, x_max, y_min, y_max) = geometry.calculate_extents()
1780+
(x_min, _, y_min, _) = geometry.calculate_extents()
17721781
self.geometry.control_points.insert(0, [x_min - 1, y_min - 1])
17731782

17741783
# create matching dummy material
@@ -1862,7 +1871,8 @@ def get_elements(self, mesh):
18621871

18631872
return (nodes, elements, element_list)
18641873

1865-
def calculate_centroid(self, elements):
1874+
@staticmethod
1875+
def calculate_centroid(elements):
18661876
"""Calculates the elastic centroid from a list of finite elements.
18671877
18681878
:param elements: A list of Tri6 finite elements.
@@ -1987,7 +1997,8 @@ def calculate_plastic_properties(self, cross_section, verbose):
19871997
cross_section.section_props.s22 / cross_section.section_props.z22_minus
19881998
)
19891999

1990-
def check_convergence(self, root_result, axis):
2000+
@staticmethod
2001+
def check_convergence(root_result, axis):
19912002
"""Checks that the function solver converged and if not, raises a helpful error.
19922003
19932004
:param root_result: Result object from the root finder
@@ -1997,13 +2008,14 @@ def check_convergence(self, root_result, axis):
19972008
"""
19982009

19992010
if not root_result.converged:
2000-
str = "Plastic centroid calculation about the {0}".format(axis)
2001-
str += " failed. Contact robbie.vanleeuwen@gmail.com with your"
2002-
str += " analysis parameters. Termination flag: {0}".format(root_result.flag)
2011+
msg = "Plastic centroid calculation about the {0}".format(axis)
2012+
msg += " failed. Contact robbie.vanleeuwen@gmail.com with your"
2013+
msg += " analysis parameters. Termination flag: {0}".format(root_result.flag)
20032014

2004-
raise RuntimeError(str)
2015+
raise RuntimeError(msg)
20052016

2006-
def print_verbose(self, d, root_result, axis):
2017+
@staticmethod
2018+
def print_verbose(d, root_result, axis):
20072019
"""Prints information related to the function solver convergence to the terminal.
20082020
20092021
:param float d: Location of the plastic centroid axis
@@ -2012,9 +2024,9 @@ def print_verbose(self, d, root_result, axis):
20122024
:param string axis: Axis being considered by the function solver
20132025
"""
20142026

2015-
str = "---{0} plastic centroid calculation converged at ".format(axis)
2016-
str += "{0:.5e} in {1} iterations.".format(d, root_result.iterations)
2017-
print(str)
2027+
msg = "---{0} plastic centroid calculation converged at ".format(axis)
2028+
msg += "{0:.5e} in {1} iterations.".format(d, root_result.iterations)
2029+
print(msg)
20182030

20192031
def calculate_extreme_fibres(self, angle):
20202032
"""Calculates the locations of the extreme fibres along and perpendicular to the axis
@@ -2168,6 +2180,7 @@ def calculate_plastic_force(self, elements, u, p):
21682180
self.c_top = [qy_top / ea_top, qx_top / ea_top]
21692181
self.c_bot = [qy_bot / ea_bot, qx_bot / ea_bot]
21702182
self.f_top = f_top
2183+
self.f_bot = f_bot
21712184

21722185
return (f_top, f_bot)
21732186

@@ -2191,11 +2204,9 @@ def create_plastic_mesh(self, new_line=None):
21912204
self.add_line(geom, new_line)
21922205

21932206
# fast clean the geometry after adding the line
2194-
clean = pre.GeometryCleaner(geom, verbose=False)
2195-
clean.zip_points()
2196-
clean.remove_zero_length_facets()
2197-
clean.remove_unused_points()
2198-
geom = clean.geometry
2207+
geom.zip_points()
2208+
geom.remove_zero_length_facets()
2209+
geom.remove_unused_points()
21992210

22002211
if self.debug:
22012212
if new_line is not None:
@@ -2258,7 +2269,7 @@ def add_line(self, geometry, line):
22582269

22592270
# if the line lies within q -> q + s and the point hasn't already been added
22602271
# (ignore t as it is infinitely long)
2261-
if (u >= 0 and u <= 1 and list(new_pt) not in [list(item) for item in int_pts]):
2272+
if (0 <= u <= 1 and list(new_pt) not in [list(item) for item in int_pts]):
22622273
int_pts.append(new_pt)
22632274
fct_idx.append(idx)
22642275

@@ -2301,7 +2312,8 @@ def add_line(self, geometry, line):
23012312
for idx in idx_to_remove:
23022313
geometry.facets.pop(idx)
23032314

2304-
def rebuild_parent_facet(self, geometry, fct_idx, pt_idx):
2315+
@staticmethod
2316+
def rebuild_parent_facet(geometry, fct_idx, pt_idx):
23052317
"""Splits and rebuilds a facet at a given point.
23062318
23072319
:param geometry: Cross-section geometry object used to generate the mesh
@@ -2357,12 +2369,13 @@ def point_within_element(self, pt):
23572369

23582370
return False
23592371

2360-
def plot_mesh(self, nodes, elements, element_list, materials):
2372+
@staticmethod
2373+
def plot_mesh(nodes, elements, element_list, materials):
23612374
"""Watered down implementation of the CrossSection method to plot the finite element mesh,
23622375
showing material properties."""
23632376

2364-
(fig, ax) = plt.subplots()
2365-
post.setup_plot(ax, True)
2377+
(_, ax) = plt.subplots()
2378+
post.setup_plot(True)
23662379

23672380
# plot the mesh
23682381
ax.triplot(nodes[:, 0], nodes[:, 1], elements[:, 0:3], lw=0.5,
@@ -2438,7 +2451,7 @@ def plot_stress_contour(self, sigs, title, pause):
24382451

24392452
# create plot and setup the plot
24402453
(fig, ax) = plt.subplots()
2441-
post.setup_plot(ax, pause)
2454+
post.setup_plot(pause)
24422455

24432456
# plot the finite element mesh
24442457
self.cross_section.plot_mesh(ax, pause, alpha=0.5)
@@ -2500,7 +2513,7 @@ def plot_stress_vector(self, sigxs, sigys, title, pause):
25002513

25012514
# create plot and setup the plot
25022515
(fig, ax) = plt.subplots()
2503-
post.setup_plot(ax, pause)
2516+
post.setup_plot(pause)
25042517

25052518
# plot the finite element mesh
25062519
self.cross_section.plot_mesh(ax, pause, alpha=0.5)

0 commit comments

Comments
 (0)