Skip to content

Commit ea18e5f

Browse files
ccapranigithub-actions[bot]
authored andcommitted
🎨 Format Python code with psf/black
1 parent c7c98dc commit ea18e5f

File tree

5 files changed

+146
-68
lines changed

5 files changed

+146
-68
lines changed

src/ospgrillage/osp_grillage.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2273,9 +2273,7 @@ def _embed_geometry(self, ds):
22732273
# --- node coordinates DataArray ---
22742274
node_spec = self.Mesh_obj.node_spec
22752275
node_tags = sorted(node_spec.keys())
2276-
coord_data = np.array(
2277-
[node_spec[n]["coordinate"] for n in node_tags]
2278-
)
2276+
coord_data = np.array([node_spec[n]["coordinate"] for n in node_tags])
22792277
ds["node_coordinates"] = xr.DataArray(
22802278
coord_data,
22812279
dims=("Node", "Axis"),
@@ -3123,7 +3121,8 @@ def extract_analysis(
31233121
for ele_num, stresses in analysis_obj.ele_stresses.items():
31243122
ele_stress_dict[ele_num] = stresses
31253123
self.basic_load_case_record_stresses.setdefault(
3126-
analysis_obj.analysis_name, ele_stress_dict,
3124+
analysis_obj.analysis_name,
3125+
ele_stress_dict,
31273126
)
31283127

31293128
# if moving load, input is a list of analysis obj
@@ -3419,10 +3418,11 @@ def compile_data_array(self, local_force_option=True, main_ele_tags=None):
34193418
if self.basic_load_case_record_stresses:
34203419
stress_list = []
34213420
for lc_name in basic_load_case_coord:
3422-
lc_stresses = self.basic_load_case_record_stresses.get(lc_name, {})
3421+
lc_stresses = self.basic_load_case_record_stresses.get(
3422+
lc_name, {}
3423+
)
34233424
lc_row = [
3424-
lc_stresses.get(tag, [0.0] * 32)
3425-
for tag in ele_tag_shell
3425+
lc_stresses.get(tag, [0.0] * 32) for tag in ele_tag_shell
34263426
]
34273427
stress_list.append(lc_row)
34283428
stress_array = np.array(stress_list)

src/ospgrillage/ospgui.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,25 @@ def __init__(self):
753753
self.contour_group = QGroupBox("Shell Contour")
754754
contour_layout = QFormLayout()
755755
self.contour_component_combo = QComboBox()
756-
for comp in ("Mx", "My", "Mz", "Vx", "Vy", "Vz", "Dx", "Dy", "Dz",
757-
"N11", "N22", "N12", "M11", "M22", "M12", "Q13", "Q23"):
756+
for comp in (
757+
"Mx",
758+
"My",
759+
"Mz",
760+
"Vx",
761+
"Vy",
762+
"Vz",
763+
"Dx",
764+
"Dy",
765+
"Dz",
766+
"N11",
767+
"N22",
768+
"N12",
769+
"M11",
770+
"M22",
771+
"M12",
772+
"Q13",
773+
"Q23",
774+
):
758775
self.contour_component_combo.addItem(comp)
759776
contour_layout.addRow("Component:", self.contour_component_combo)
760777
self.contour_colorscale_combo = QComboBox()
@@ -973,10 +990,10 @@ def __init__(self):
973990
self.generated_code = ""
974991

975992
# Results viewer state
976-
self._mode = "wizard" # "wizard" or "results"
977-
self._model_proxy = None # _ModelProxy from loaded results
978-
self._results = None # xarray Dataset
979-
self._stale_tabs = set() # result tab names needing re-render
993+
self._mode = "wizard" # "wizard" or "results"
994+
self._model_proxy = None # _ModelProxy from loaded results
995+
self._results = None # xarray Dataset
996+
self._stale_tabs = set() # result tab names needing re-render
980997

981998
# Create UI components
982999
self.create_menu_bar()
@@ -1641,9 +1658,7 @@ def _open_results_file(self):
16411658
)
16421659
return
16431660
except Exception as e:
1644-
QMessageBox.critical(
1645-
self, "Error", f"Could not load results file:\n{e}"
1646-
)
1661+
QMessageBox.critical(self, "Error", f"Could not load results file:\n{e}")
16471662
return
16481663

16491664
self._model_proxy = proxy
@@ -1791,7 +1806,10 @@ def _refresh_current_result_tab(self):
17911806
from PyQt6.QtCore import QUrl
17921807

17931808
tmp = tempfile.NamedTemporaryFile(
1794-
suffix=".html", delete=False, mode="w", encoding="utf-8",
1809+
suffix=".html",
1810+
delete=False,
1811+
mode="w",
1812+
encoding="utf-8",
17951813
)
17961814
tmp.write(fig.to_html(include_plotlyjs=True))
17971815
tmp.close()

src/ospgrillage/postprocessing.py

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,7 @@ def get(self):
331331
# ``forces_shell`` aligned with the ``ele_nodes_shell`` Nodes dimension.
332332
_SHELL_COMPONENTS = ("Vx", "Vy", "Vz", "Mx", "My", "Mz")
333333
_SHELL_COMP_COLUMNS = {
334-
comp: [f"{comp}_{s}" for s in ("i", "j", "k", "l")]
335-
for comp in _SHELL_COMPONENTS
334+
comp: [f"{comp}_{s}" for s in ("i", "j", "k", "l")] for comp in _SHELL_COMPONENTS
336335
}
337336

338337
# Displacement components for shell contour. User-facing names map to
@@ -349,9 +348,7 @@ def get(self):
349348

350349
# All components accepted by plot_srf
351350
_SRF_COMPONENTS = (
352-
_SHELL_COMPONENTS
353-
+ tuple(_DISP_COMPONENTS.keys())
354-
+ _STRESS_RESULTANTS
351+
_SHELL_COMPONENTS + tuple(_DISP_COMPONENTS.keys()) + _STRESS_RESULTANTS
355352
)
356353

357354

@@ -527,7 +524,9 @@ def _extract_def_data(
527524
# ---------------------------------------------------------------------------
528525
# Shell contour data extraction
529526
# ---------------------------------------------------------------------------
530-
def _extract_shell_contour_data(result_obj, component, loadcase=None, *, averaging="nodal"):
527+
def _extract_shell_contour_data(
528+
result_obj, component, loadcase=None, *, averaging="nodal"
529+
):
531530
"""Extract per-node contour values for a shell stress resultant.
532531
533532
Parameters
@@ -736,9 +735,9 @@ def _triangulate_shell_mesh(node_coords, element_quads):
736735
vx, vy, vz = [], [], []
737736
for tag in ordered_tags:
738737
c = node_coords[tag]
739-
vx.append(c[0]) # model x -> plotly x
740-
vy.append(c[2]) # model z -> plotly y
741-
vz.append(-c[1]) # model y -> plotly z (negated)
738+
vx.append(c[0]) # model x -> plotly x
739+
vy.append(c[2]) # model z -> plotly y
740+
vz.append(-c[1]) # model y -> plotly z (negated)
742741

743742
# Triangle indices (each quad -> 2 triangles)
744743
i_idx, j_idx, k_idx = [], [], []
@@ -1281,15 +1280,22 @@ def _plotly_3d_shell_contour(
12811280
# Extract data — dispatch to force or displacement extraction
12821281
if component in _DISP_COMPONENTS:
12831282
node_values, element_quads = _extract_shell_disp_data(
1284-
result_obj, component, loadcase,
1283+
result_obj,
1284+
component,
1285+
loadcase,
12851286
)
12861287
elif component in _STRESS_RESULTANTS:
12871288
node_values, element_quads = _extract_shell_stress_data(
1288-
result_obj, component, loadcase,
1289+
result_obj,
1290+
component,
1291+
loadcase,
12891292
)
12901293
else:
12911294
node_values, element_quads = _extract_shell_contour_data(
1292-
result_obj, component, loadcase, averaging=averaging,
1295+
result_obj,
1296+
component,
1297+
loadcase,
1298+
averaging=averaging,
12931299
)
12941300

12951301
# Build node coordinate dict from Dataset
@@ -1300,7 +1306,8 @@ def _plotly_3d_shell_contour(
13001306

13011307
# Triangulate
13021308
vx, vy, vz, i_idx, j_idx, k_idx, tag_to_vidx = _triangulate_shell_mesh(
1303-
node_coords, element_quads,
1309+
node_coords,
1310+
element_quads,
13041311
)
13051312

13061313
# Build intensity array aligned with vertex order
@@ -1318,12 +1325,17 @@ def _plotly_3d_shell_contour(
13181325
k=k_idx,
13191326
intensity=intensity,
13201327
colorscale=colorscale,
1321-
colorbar=dict(title=component, x=-0.05, xanchor="right") if show_colorbar else None,
1328+
colorbar=dict(title=component, x=-0.05, xanchor="right")
1329+
if show_colorbar
1330+
else None,
13221331
showscale=show_colorbar,
13231332
opacity=opacity,
13241333
flatshading=True,
13251334
lighting=dict(
1326-
ambient=1.0, diffuse=0.0, specular=0.0, fresnel=0.0,
1335+
ambient=1.0,
1336+
diffuse=0.0,
1337+
specular=0.0,
1338+
fresnel=0.0,
13271339
),
13281340
name=f"shell_{component}",
13291341
hovertemplate=f"{component}: %{{intensity:.3g}}<extra></extra>",
@@ -1394,15 +1406,22 @@ def _plot_shell_contour_mpl(
13941406

13951407
if component in _DISP_COMPONENTS:
13961408
node_values, element_quads = _extract_shell_disp_data(
1397-
result_obj, component, loadcase,
1409+
result_obj,
1410+
component,
1411+
loadcase,
13981412
)
13991413
elif component in _STRESS_RESULTANTS:
14001414
node_values, element_quads = _extract_shell_stress_data(
1401-
result_obj, component, loadcase,
1415+
result_obj,
1416+
component,
1417+
loadcase,
14021418
)
14031419
else:
14041420
node_values, element_quads = _extract_shell_contour_data(
1405-
result_obj, component, loadcase, averaging=averaging,
1421+
result_obj,
1422+
component,
1423+
loadcase,
1424+
averaging=averaging,
14061425
)
14071426

14081427
# Build node coordinate dict
@@ -2205,8 +2224,7 @@ def plot_srf(
22052224
"""
22062225
if component not in _SRF_COMPONENTS:
22072226
raise ValueError(
2208-
f"Unknown component {component!r}. "
2209-
f"Expected one of {_SRF_COMPONENTS}."
2227+
f"Unknown component {component!r}. " f"Expected one of {_SRF_COMPONENTS}."
22102228
)
22112229
if "ele_nodes_shell" not in result_obj:
22122230
raise ValueError(

tests/generate_test_results.py

Lines changed: 70 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,44 @@
3333

3434

3535
# -- Materials & sections --------------------------------------------------
36-
concrete = og.create_material(
37-
material="concrete", code="AS5100-2017", grade="65MPa"
38-
)
36+
concrete = og.create_material(material="concrete", code="AS5100-2017", grade="65MPa")
3937
concrete_shell = og.create_material(
4038
material="concrete", code="AS5100-2017", grade="50MPa", rho=2400
4139
)
4240

4341
long_sec = og.create_section(
44-
A=0.034 * m2, J=2.08e-3 * m3, Iz=6.77e-3 * m4,
45-
Iy=2.04e-3 * m4, Az=6.10e-3 * m2, Ay=3.99e-3 * m2,
42+
A=0.034 * m2,
43+
J=2.08e-3 * m3,
44+
Iz=6.77e-3 * m4,
45+
Iy=2.04e-3 * m4,
46+
Az=6.10e-3 * m2,
47+
Ay=3.99e-3 * m2,
4648
)
4749
edge_sec = og.create_section(
48-
A=0.034 * m2, J=2.08e-3 * m3, Iz=6.77e-3 * m4,
49-
Iy=2.04e-3 * m4, Az=6.10e-3 * m2, Ay=3.99e-3 * m2,
50+
A=0.034 * m2,
51+
J=2.08e-3 * m3,
52+
Iz=6.77e-3 * m4,
53+
Iy=2.04e-3 * m4,
54+
Az=6.10e-3 * m2,
55+
Ay=3.99e-3 * m2,
5056
)
5157
trans_sec = og.create_section(
52-
A=0.504 * m2, J=5.22303e-3 * m3, Iy=0.32928 * m4,
53-
Iz=1.3608e-3 * m4, Ay=0.42 * m2, Az=0.42 * m2, unit_width=True,
58+
A=0.504 * m2,
59+
J=5.22303e-3 * m3,
60+
Iy=0.32928 * m4,
61+
Iz=1.3608e-3 * m4,
62+
Ay=0.42 * m2,
63+
Az=0.42 * m2,
64+
unit_width=True,
5465
)
5566
end_sec = og.create_section(
56-
A=0.504 / 2 * m2, J=2.5e-3 * m3, Iy=2.73e-2 * m4,
57-
Iz=6.8e-4 * m4, Ay=0.21 * m2, Az=0.21 * m2, unit_width=True,
67+
A=0.504 / 2 * m2,
68+
J=2.5e-3 * m3,
69+
Iy=2.73e-2 * m4,
70+
Iz=6.8e-4 * m4,
71+
Ay=0.21 * m2,
72+
Az=0.21 * m2,
73+
unit_width=True,
5874
)
5975
shell_sec = og.create_section(h=0.2)
6076

@@ -90,9 +106,7 @@ def _add_loads(model):
90106
for z_pos in model.Mesh_obj.noz[1:-1]:
91107
p1 = og.create_load_vertex(x=0, z=z_pos, p=22.4 * kN / m)
92108
p2 = og.create_load_vertex(x=L, z=z_pos, p=22.4 * kN / m)
93-
DL.add_load(
94-
og.create_load(loadtype="line", point1=p1, point2=p2, name="SW")
95-
)
109+
DL.add_load(og.create_load(loadtype="line", point1=p1, point2=p2, name="SW"))
96110
model.add_load_case(DL)
97111

98112
overlay = og.create_load(
@@ -115,17 +129,27 @@ def _add_loads(model):
115129
(
116130
"test_beam_oblique.nc",
117131
dict(
118-
bridge_name="Beam Oblique (skew 20)", long_dim=L, width=w, skew=20,
119-
num_long_grid=7, num_trans_grid=11, edge_beam_dist=1.0 * m,
132+
bridge_name="Beam Oblique (skew 20)",
133+
long_dim=L,
134+
width=w,
135+
skew=20,
136+
num_long_grid=7,
137+
num_trans_grid=11,
138+
edge_beam_dist=1.0 * m,
120139
mesh_type="Oblique",
121140
),
122141
_assign_beam_members,
123142
),
124143
(
125144
"test_beam_ortho.nc",
126145
dict(
127-
bridge_name="Beam Ortho (skew 15)", long_dim=L, width=w, skew=15,
128-
num_long_grid=7, num_trans_grid=11, edge_beam_dist=1.0 * m,
146+
bridge_name="Beam Ortho (skew 15)",
147+
long_dim=L,
148+
width=w,
149+
skew=15,
150+
num_long_grid=7,
151+
num_trans_grid=11,
152+
edge_beam_dist=1.0 * m,
129153
mesh_type="Ortho",
130154
),
131155
_assign_beam_members,
@@ -134,22 +158,38 @@ def _add_loads(model):
134158
(
135159
"test_beam_link.nc",
136160
dict(
137-
bridge_name="Beam Link", long_dim=L, width=w, skew=-12,
138-
num_long_grid=7, num_trans_grid=5, edge_beam_dist=1.0 * m,
139-
mesh_type="Ortho", model_type="beam_link",
140-
beam_width=1.0, web_thick=0.02, centroid_dist_y=0.499,
161+
bridge_name="Beam Link",
162+
long_dim=L,
163+
width=w,
164+
skew=-12,
165+
num_long_grid=7,
166+
num_trans_grid=5,
167+
edge_beam_dist=1.0 * m,
168+
mesh_type="Ortho",
169+
model_type="beam_link",
170+
beam_width=1.0,
171+
web_thick=0.02,
172+
centroid_dist_y=0.499,
141173
),
142174
_assign_beam_members,
143175
),
144176
# Shell-beam hybrid model
145177
(
146178
"test_shell_beam.nc",
147179
dict(
148-
bridge_name="Shell Beam", long_dim=L, width=w, skew=0,
149-
num_long_grid=7, num_trans_grid=11, edge_beam_dist=1.0 * m,
150-
mesh_type="Orth", model_type="shell_beam",
151-
max_mesh_size_z=1.0, max_mesh_size_x=1.0,
152-
offset_beam_y_dist=0.499, beam_width=0.89,
180+
bridge_name="Shell Beam",
181+
long_dim=L,
182+
width=w,
183+
skew=0,
184+
num_long_grid=7,
185+
num_trans_grid=11,
186+
edge_beam_dist=1.0 * m,
187+
mesh_type="Orth",
188+
model_type="shell_beam",
189+
max_mesh_size_z=1.0,
190+
max_mesh_size_x=1.0,
191+
offset_beam_y_dist=0.499,
192+
beam_width=0.89,
153193
),
154194
_assign_shell_members,
155195
),
@@ -161,7 +201,9 @@ def main():
161201
model_type = kwargs.get("model_type", "beam")
162202
mesh_type = kwargs.get("mesh_type", "?")
163203
skew = kwargs.get("skew", 0)
164-
print(f"Generating {filename} (type={model_type}, mesh={mesh_type}, skew={skew})...")
204+
print(
205+
f"Generating {filename} (type={model_type}, mesh={mesh_type}, skew={skew})..."
206+
)
165207
model = og.create_grillage(**kwargs)
166208
assign_fn(model)
167209
model.create_osp_model(pyfile=False)

0 commit comments

Comments
 (0)