Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions pycufsm/pre/cutwp.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,26 +266,28 @@ def prop2(coord: np.ndarray, ends: np.ndarray) -> Sect_Props:
x_shearcentre = np.float64(0.0)
if np.abs(y_shearcentre / np.sqrt(area)) < 1e-12:
y_shearcentre = np.float64(0.0)
# Compute unit warping
# Compute unit warping about the shear centre. As in the original CUTWP,
# this walk uses its own visited-node table (wo_vals), separate from
# the one used above for the centroid-based warping (w_vals).
for _ in range(n_elements):
i = 0
while i < len(ends) - 1 and (
(np.any(w_vals[:, 0] == ends[i, 0]) and np.any(w_vals[:, 0] == ends[i, 1]))
or (not (np.any(w_vals[:, 0] == ends[i, 0])) and (not np.any(w_vals[:, 0] == ends[i, 1])))
(np.any(wo_vals[:, 0] == ends[i, 0]) and np.any(wo_vals[:, 0] == ends[i, 1]))
or (not (np.any(wo_vals[:, 0] == ends[i, 0])) and (not np.any(wo_vals[:, 0] == ends[i, 1])))
):
i = i + 1
start_node = int(ends[i, 0]) - 1
end_node = int(ends[i, 0]) - 1
end_node = int(ends[i, 1]) - 1
po_vals = (
(coord[start_node, 0] - x_shearcentre) * (coord[end_node, 1] - y_shearcentre)
- (coord[end_node, 0] - x_shearcentre) * (coord[start_node, 1] - y_shearcentre)
) / lengths[i]
if w_vals[start_node, 0] == 0:
w_vals[start_node, 0] = start_node + 1
w_vals[start_node, 1] = w_vals[end_node, 1] - po_vals * lengths[i]
elif w_vals[end_node, 0] == 0:
w_vals[end_node, 0] = end_node + 1
w_vals[end_node, 1] = w_vals[start_node, 1] + po_vals * lengths[i]
if wo_vals[start_node, 0] == 0:
wo_vals[start_node, 0] = start_node + 1
wo_vals[start_node, 1] = wo_vals[end_node, 1] - po_vals * lengths[i]
elif wo_vals[end_node, 0] == 0:
wo_vals[end_node, 0] = end_node + 1
wo_vals[end_node, 1] = wo_vals[start_node, 1] + po_vals * lengths[i]
w_no = w_no + 1 / (2 * area) * (wo_vals[start_node, 1] + wo_vals[end_node, 1]) * thicknesses[i] * lengths[i]
wn_vals: Optional[np.ndarray] = np.zeros((len(wo_vals), 2))
wn_vals = w_no - wo_vals[:, 1]
Expand Down
62 changes: 62 additions & 0 deletions tests/test_cutwp.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,65 @@ def it_is_zero_for_a_section_symmetric_about_x():
ends = np.array([[0, 1, 0.1], [2, 3, 0.1], [0, 2, 0.1]], dtype=float)
sect = cutwp.prop2(coord.copy(), ends.copy())
assert sect["Ixy"] == approx(0.0)

def context_warping_constant():
# Centreline dimensions shared by the closed-form checks below
depth, width, thick = 10.0, 4.0, 0.1

def _channel():
coord = np.array([[width, 0.0], [0.0, 0.0], [0.0, depth], [width, depth]])
ends = np.array([[0, 1, thick], [1, 2, thick], [2, 3, thick]], dtype=float)
return coord, ends

def _subdivided(coord: np.ndarray, ends: np.ndarray, parts: int) -> tuple[np.ndarray, np.ndarray]:
# Split each element into ``parts`` collinear elements
new_coord = [coord[int(ends[0, 0])]]
new_ends = []
for start, end, t in ends:
for k in range(1, parts + 1):
new_coord.append(coord[int(start)] + (coord[int(end)] - coord[int(start)]) * k / parts)
new_ends.append([len(new_coord) - 2, len(new_coord) - 1, t])
return np.array(new_coord), np.array(new_ends, dtype=float)

def it_matches_the_closed_form_value_for_a_plain_channel():
# Cw = t b^3 h^2 (3b + 2h) / (12 (6b + h))
coord, ends = _channel()
sect = cutwp.prop2(coord.copy(), ends.copy())
expected = thick * width**3 * depth**2 * (3 * width + 2 * depth) / (12 * (6 * width + depth))
assert sect["Cw"] == approx(expected)
# the shear centre, computed before Cw, is unaffected: e = 3b^2 / (h + 6b)
assert sect["x0"] == approx(-3 * width**2 / (depth + 6 * width))

def it_matches_the_closed_form_value_for_a_zed():
# Point-symmetric section with a non-zero product of inertia:
# Cw = t b^3 h^2 (b + 2h) / (12 (2b + h))
coord = np.array([[width, 0.0], [0.0, 0.0], [0.0, depth], [-width, depth]])
ends = np.array([[0, 1, thick], [1, 2, thick], [2, 3, thick]], dtype=float)
sect = cutwp.prop2(coord.copy(), ends.copy())
expected = thick * width**3 * depth**2 * (width + 2 * depth) / (12 * (2 * width + depth))
assert sect["Cw"] == approx(expected)

def it_does_not_depend_on_the_element_discretisation():
coord, ends = _channel()
reference = cutwp.prop2(coord.copy(), ends.copy())["Cw"]
fine_coord, fine_ends = _subdivided(coord, ends, parts=5)
assert cutwp.prop2(fine_coord.copy(), fine_ends.copy())["Cw"] == approx(reference)

def it_does_not_depend_on_the_element_order():
coord, ends = _channel()
reference = cutwp.prop2(coord.copy(), ends.copy())["Cw"]
reversed_ends = ends[::-1].copy()
assert cutwp.prop2(coord.copy(), reversed_ends)["Cw"] == approx(reference)

def it_returns_a_normalised_unit_warping():
# The normalised unit warping integrates to zero over the section
coord, ends = _channel()
sect = cutwp.prop2(coord.copy(), ends.copy())
wn_vals = sect["wn"]
assert wn_vals is not None
integral = sum(
(wn_vals[int(s)] + wn_vals[int(e)]) / 2 * t * np.hypot(*(coord[int(e)] - coord[int(s)]))
for s, e, t in ends
)
assert integral == approx(0.0, abs=1e-9)
assert np.max(np.abs(wn_vals)) > 0
Loading