Skip to content

Commit

Permalink
🎨 Format Python code with psf/black (#74)
Browse files Browse the repository at this point in the history
Co-authored-by: ccaprani <[email protected]>
  • Loading branch information
github-actions[bot] and ccaprani authored Mar 31, 2024
1 parent 1d5adb9 commit 55ae8f3
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 63 deletions.
4 changes: 2 additions & 2 deletions src/pycba/beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def no_restraints(self):
The number of restraints in the beam
"""
return len(self._restraints)

@property
def no_fixed_restraints(self):
"""
Expand All @@ -230,7 +230,7 @@ def no_fixed_restraints(self):
no_fixed_restraints : int
The number of fixed restraints in the beam
"""
return len(np.where(np.array(self._restraints)==-1)[0])
return len(np.where(np.array(self._restraints) == -1)[0])

@property
def length(self):
Expand Down
44 changes: 25 additions & 19 deletions src/pycba/inf_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,63 +118,69 @@ def get_il(self, poi: float, load_effect: str) -> (np.ndarray, np.ndarray):
if not self.vResults:
self.create_ils()

x = self.vResults[0].results.x
x = self.vResults[0].results.x
npts = len(self.vResults)
eta = np.zeros(npts)

# Preparations for reaction ILs
#
# Get vector of the node locations
node_locations = np.cumsum(np.insert(self.ba.beam.mbr_lengths, 0, 0))
# Link the supported DOF to the index in the BeamAnalysis reactions vector
idx_mask = np.zeros_like(self.ba._beam.restraints)
idx_mask[np.where(np.array(self.ba._beam.restraints)==-1)] = np.arange(self.ba.beam.no_fixed_restraints)
idx_mask[np.where(np.array(self.ba._beam.restraints) == -1)] = np.arange(
self.ba.beam.no_fixed_restraints
)

# idx = np.abs(x - poi).argmin()

#idx = np.abs(x - poi).argmin()

if load_effect.upper() == "V":
dx = x[2] - x[1]
idx = np.where(np.abs(x - poi) <= dx * 1e-6)[0][0]
for i, res in enumerate(self.vResults):
eta[i] = res.results.V[idx]

elif load_effect.upper() == "R":
#
# Getting the correct reaction is tricky
#
# The indices of the supported DOFs wrt the node locations vector
vert_sups_dof_idx = np.where(np.array(self.ba._beam.restraints)[::2]==-1)[0]
vert_sups_dof_idx = np.where(np.array(self.ba._beam.restraints)[::2] == -1)[
0
]
# The locations then of these supports
vert_sups_locs = node_locations[vert_sups_dof_idx]
# The index of the closest support
closest_vert_sup_idx = np.abs(vert_sups_locs-poi).argmin()
closest_vert_sup_idx = np.abs(vert_sups_locs - poi).argmin()
# And its value
closest_vert_sup = vert_sups_locs[closest_vert_sup_idx]
# And now the index of this support in the node locations vector
vert_sup_node_idx = np.where(node_locations==closest_vert_sup)[0][0]
vert_sup_node_idx = np.where(node_locations == closest_vert_sup)[0][0]
# And hence its index in the overall DOFs vector
vert_sup_dof_idx = 2*vert_sup_node_idx
vert_sup_dof_idx = 2 * vert_sup_node_idx
# And finally the index of the support nearest the POI in the reactions vector
vert_sup_idx = idx_mask[vert_sup_dof_idx]
vert_sup_idx = idx_mask[vert_sup_dof_idx]

for i, res in enumerate(self.vResults):
eta[i] = res.R[vert_sup_idx]

elif load_effect.upper() == "MR":
#
# Follows the same logic for the vertical reaction
#
mt_sups_dof_idx = np.where(np.array(self.ba._beam.restraints)[1::2]==-1)[0]
mt_sups_dof_idx = np.where(np.array(self.ba._beam.restraints)[1::2] == -1)[
0
]
mt_sups_locs = node_locations[mt_sups_dof_idx]
closest_mt_sup_idx = np.abs(mt_sups_locs-poi).argmin()
closest_mt_sup_idx = np.abs(mt_sups_locs - poi).argmin()
closest_mt_sup = mt_sups_locs[closest_mt_sup_idx]
mt_sup_node_idx = np.where(node_locations==closest_mt_sup)[0][0]
mt_sup_dof_idx = 2*mt_sup_node_idx+1
mt_sup_node_idx = np.where(node_locations == closest_mt_sup)[0][0]
mt_sup_dof_idx = 2 * mt_sup_node_idx + 1
mt_sup_idx = idx_mask[mt_sup_dof_idx]

for i, res in enumerate(self.vResults):
eta[i] = res.R[mt_sup_idx]

else:
dx = x[2] - x[1]
idx = np.where(np.abs(x - poi) <= dx * 1e-6)[0][0]
Expand Down
11 changes: 5 additions & 6 deletions src/pycba/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,10 @@ def H(self, v: np.ndarray, value: float = 0.0) -> np.ndarray:
"""
return np.heaviside(v, value)


def get_ref(self, L: float, eType: int) -> LoadCNL:
"""
Returns the Released End Forces for a span of length L of element eType:
converts the Consistent Nodal Loads of the applied loading to the correct nodal
Returns the Released End Forces for a span of length L of element eType:
converts the Consistent Nodal Loads of the applied loading to the correct nodal
loading depending on the element type.
Parameters
Expand All @@ -232,7 +231,7 @@ def get_ref(self, L: float, eType: int) -> LoadCNL:
Returns
-------
LoadCNL
Released End Forces for this load type: the nodal loads to be applied in
Released End Forces for this load type: the nodal loads to be applied in
the analysis, consistent with the element type.
"""
cnl = self.get_cnl(L, eType)
Expand All @@ -250,9 +249,9 @@ def get_ref(self, L: float, eType: int) -> LoadCNL:
ref[2] = -fm * cnl.Ma
ref[3] = 0.5 * cnl.Ma
elif eType == 4: # keep only vertical, remove moments
ref[0] = -(cnl.Ma+cnl.Mb)/L
ref[0] = -(cnl.Ma + cnl.Mb) / L
ref[1] = 1.0 * cnl.Ma
ref[2] = (cnl.Ma+cnl.Mb)/L
ref[2] = (cnl.Ma + cnl.Mb) / L
ref[3] = 1.0 * cnl.Mb
else:
# no nothing if it is FF
Expand Down
18 changes: 9 additions & 9 deletions src/pycba/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def _member_values(
L = beam.mbr_lengths[i_span]
EI = beam.mbr_EIs[i_span]
etype = beam.mbr_eletype[i_span]

dx = L / self.npts
x = np.zeros(self.npts + 3)
x[1 : self.npts + 2] = dx * np.arange(0, self.npts + 1)
Expand All @@ -151,8 +151,8 @@ def _member_values(
res = MaMb.get_mbr_results(x, L)

# Now get the results for all the applied loads on a simple span
Ma=0
Mb=0
Ma = 0
Mb = 0
for load in beam._loads:
if load.i_span != i_span:
continue
Expand All @@ -161,19 +161,19 @@ def _member_values(
Ma += cnl.Ma
Mb += cnl.Mb

# Check element type for any released displacements
# Check element type for any released displacements
R0 = d[1]
theta = 0
phi_i = 0
# Account for end release if joint not already rotating
if etype != 1 and abs(R0) < 1e-6 :
theta = (d[2]-d[0])/L
phi_i = (L/(3*EI))*(-(f[1]-0.5*f[3])+(Ma-0.5*Mb))
if etype != 1 and abs(R0) < 1e-6:
theta = (d[2] - d[0]) / L
phi_i = (L / (3 * EI)) * (-(f[1] - 0.5 * f[3]) + (Ma - 0.5 * Mb))

R0 -= phi_i - theta

# And superimpose end displacements using Moment-Area
h = L / self.npts
h = L / self.npts

R = integrate.cumtrapz(res.M[1:-1], dx=h, initial=0) / EI + R0
D = integrate.cumtrapz(R, dx=h, initial=0) + d[0]
Expand Down
54 changes: 27 additions & 27 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_1span_ee():
L = 10 # m
EI = 30 * 600e7 * 1e-6 # kNm2
R = [-1, -1, -1, -1]
LM = [[1, 2, P, 0.5*L, 0]]
LM = [[1, 2, P, 0.5 * L, 0]]

beam_analysis = cba.BeamAnalysis([L], EI, R, LM)
out = beam_analysis.analyze()
Expand All @@ -26,9 +26,9 @@ def test_1span_ee():
Mb = beam_analysis.beam_results.results.M[-2]
Mc = beam_analysis.beam_results.results.M[51]

assert Ma == pytest.approx(-P*L/8)
assert Mb == pytest.approx(-P*L/8)
assert Mc == pytest.approx(P*L/8)
assert Ma == pytest.approx(-P * L / 8)
assert Mb == pytest.approx(-P * L / 8)
assert Mc == pytest.approx(P * L / 8)


def test_1span_ep():
Expand All @@ -40,7 +40,7 @@ def test_1span_ep():
L = 10 # m
EI = 30 * 600e7 * 1e-6 # kNm2
R = [-1, -1, -1, 0]
LM = [[1, 2, P, 0.5*L, 0]]
LM = [[1, 2, P, 0.5 * L, 0]]

beam_analysis = cba.BeamAnalysis([L], EI, R, LM)
out = beam_analysis.analyze()
Expand All @@ -50,9 +50,9 @@ def test_1span_ep():
Mb = beam_analysis.beam_results.results.M[-2]
Mc = beam_analysis.beam_results.results.M[51]

assert Ma == pytest.approx(-3*P*L/16)
assert Ma == pytest.approx(-3 * P * L / 16)
assert Mb == pytest.approx(0)
assert Mc == pytest.approx(5*P*L/32)
assert Mc == pytest.approx(5 * P * L / 32)


def test_1span_ep_eletype2():
Expand All @@ -64,7 +64,7 @@ def test_1span_ep_eletype2():
L = 10 # m
EI = 30 * 600e7 * 1e-6 # kNm2
R = [-1, -1, -1, -1] # Notice, fixed-fixed supports
LM = [[1, 2, P, 0.5*L, 0]]
LM = [[1, 2, P, 0.5 * L, 0]]

beam_analysis = cba.BeamAnalysis([L], EI, R, LM, eletype=[2])
out = beam_analysis.analyze()
Expand All @@ -74,9 +74,9 @@ def test_1span_ep_eletype2():
Mb = beam_analysis.beam_results.results.M[-2]
Mc = beam_analysis.beam_results.results.M[51]

assert Ma == pytest.approx(-3*P*L/16)
assert Ma == pytest.approx(-3 * P * L / 16)
assert Mb == pytest.approx(0)
assert Mc == pytest.approx(5*P*L/32)
assert Mc == pytest.approx(5 * P * L / 32)


def test_1span_pe():
Expand All @@ -88,7 +88,7 @@ def test_1span_pe():
L = 10 # m
EI = 30 * 600e7 * 1e-6 # kNm2
R = [-1, 0, -1, -1]
LM = [[1, 2, P, 0.5*L, 0]]
LM = [[1, 2, P, 0.5 * L, 0]]

beam_analysis = cba.BeamAnalysis([L], EI, R, LM)
out = beam_analysis.analyze()
Expand All @@ -99,8 +99,8 @@ def test_1span_pe():
Mc = beam_analysis.beam_results.results.M[51]

assert Ma == pytest.approx(0)
assert Mb == pytest.approx(-3*P*L/16)
assert Mc == pytest.approx(5*P*L/32)
assert Mb == pytest.approx(-3 * P * L / 16)
assert Mc == pytest.approx(5 * P * L / 32)


def test_1span_pe_eletype3():
Expand All @@ -112,7 +112,7 @@ def test_1span_pe_eletype3():
L = 10 # m
EI = 30 * 600e7 * 1e-6 # kNm2
R = [-1, -1, -1, -1] # Notice, fixed-fixed supports
LM = [[1, 2, P, 0.5*L, 0]]
LM = [[1, 2, P, 0.5 * L, 0]]

beam_analysis = cba.BeamAnalysis([L], EI, R, LM, eletype=[3])
out = beam_analysis.analyze()
Expand All @@ -123,8 +123,8 @@ def test_1span_pe_eletype3():
Mc = beam_analysis.beam_results.results.M[51]

assert Ma == pytest.approx(0)
assert Mb == pytest.approx(-3*P*L/16)
assert Mc == pytest.approx(5*P*L/32)
assert Mb == pytest.approx(-3 * P * L / 16)
assert Mc == pytest.approx(5 * P * L / 32)


def test_1span_pp():
Expand All @@ -136,7 +136,7 @@ def test_1span_pp():
L = 10 # m
EI = 30 * 600e7 * 1e-6 # kNm2
R = [-1, 0, -1, 0]
LM = [[1, 2, P, 0.5*L, 0]]
LM = [[1, 2, P, 0.5 * L, 0]]

beam_analysis = cba.BeamAnalysis([L], EI, R, LM)
out = beam_analysis.analyze()
Expand All @@ -148,7 +148,7 @@ def test_1span_pp():

assert Ma == pytest.approx(0)
assert Mb == pytest.approx(0)
assert Mc == pytest.approx(P*L/4)
assert Mc == pytest.approx(P * L / 4)


def test_1span_pp_eletype4():
Expand All @@ -160,7 +160,7 @@ def test_1span_pp_eletype4():
L = 10 # m
EI = 30 * 600e7 * 1e-6 # kNm2
R = [-1, -1, -1, -1] # Notice, fixed-fixed supports
LM = [[1, 2, P, 0.5*L, 0]]
LM = [[1, 2, P, 0.5 * L, 0]]

beam_analysis = cba.BeamAnalysis([L], EI, R, LM, eletype=[4])
out = beam_analysis.analyze()
Expand All @@ -172,13 +172,13 @@ def test_1span_pp_eletype4():

assert Ma == pytest.approx(0)
assert Mb == pytest.approx(0)
assert Mc == pytest.approx(P*L/4)
assert Mc == pytest.approx(P * L / 4)


def get_1span_beam_def(etype):
P = 10 # kN
L = 10 # m
a = 0.25*L
a = 0.25 * L
EI = 30 * 600e7 * 1e-6 # kNm2
R = [-1, -1, -1, -1] # Notice, fixed-fixed supports
LM = [[1, 2, P, a, 0]]
Expand All @@ -201,8 +201,8 @@ def test_1span_def_ff():

# a>b
b = aa
a = L-b
ymax = -(2*P*a**3*b**2)/(3*(3*a+b)**2*EI)
a = L - b
ymax = -(2 * P * a**3 * b**2) / (3 * (3 * a + b) ** 2 * EI)

assert dmax == pytest.approx(ymax, abs=1e-6)

Expand All @@ -214,8 +214,8 @@ def test_1span_def_fp():
P, L, EI, aa, dmax = get_1span_beam_def(etype=2)

a = aa
b = L-a
ymax = -(P*a**2*b)/(6*EI)*(b/(3*L-a))**0.5
b = L - a
ymax = -(P * a**2 * b) / (6 * EI) * (b / (3 * L - a)) ** 0.5

assert dmax == pytest.approx(ymax, abs=1e-6)

Expand All @@ -227,7 +227,7 @@ def test_1span_def_pf():
P, L, EI, aa, dmax = get_1span_beam_def(etype=3)

b = aa
ymax = -(P*b)/(3*EI)*(L**2-b**2)**3/(3*L**2-b**2)**2
ymax = -(P * b) / (3 * EI) * (L**2 - b**2) ** 3 / (3 * L**2 - b**2) ** 2

assert dmax == pytest.approx(ymax, abs=1e-6)

Expand All @@ -239,7 +239,7 @@ def test_1span_def_pp():
P, L, EI, aa, dmax = get_1span_beam_def(etype=4)

a = aa
ymax = -3**0.5*P*a*(L**2-a**2)**1.5/(27*EI*L)
ymax = -(3**0.5) * P * a * (L**2 - a**2) ** 1.5 / (27 * EI * L)

assert dmax == pytest.approx(ymax, abs=1e-6)

Expand Down

0 comments on commit 55ae8f3

Please sign in to comment.