Skip to content

Commit a1f2a95

Browse files
committed
fix: apply ruff-formatting
1 parent 3328988 commit a1f2a95

16 files changed

Lines changed: 3866 additions & 696 deletions

src/weac/analysis/analyzer.py

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
logger = logging.getLogger(__name__)
2222

2323

24-
2524
def track_analyzer_call(func):
2625
"""Decorator to track call count and execution time of Analyzer methods."""
2726

@@ -163,7 +162,9 @@ def rasterize_solution(
163162
if not ki[i]:
164163
issupported[nic[i] : nic[i + 1]] = False
165164
# Compute segment solution
166-
zi = self.sm.z(xi, C[:, [i]], length, phi, theta, ki[i], is_loaded = gi[i], qs=qs)
165+
zi = self.sm.z(
166+
xi, C[:, [i]], length, phi, theta, ki[i], is_loaded=gi[i], qs=qs
167+
)
167168
# Assemble global solution matrix
168169
zs[:, nic[i] : nic[i + 1]] = zi
169170

@@ -586,7 +587,7 @@ def incremental_ERR(
586587
C_uncracked = self.sm.uncracked_unknown_constants
587588
C_cracked = self.sm.unknown_constants
588589
phi = self.sm.scenario.phi
589-
theta=self.sm.scenario.theta
590+
theta = self.sm.scenario.theta
590591
qs = self.sm.scenario.surface_load
591592

592593
# Reduce inputs to segments with crack advance
@@ -634,7 +635,6 @@ def incremental_ERR(
634635
self._integrand_GII, z_uncracked=z_uncracked, z_cracked=z_cracked
635636
)
636637

637-
638638
# Segment contributions to total crack opening integral
639639
Ginc1 += quad(intGI, 0, length, epsabs=tolerance, epsrel=tolerance)[0] / (
640640
2 * da
@@ -663,7 +663,7 @@ def differential_ERR(
663663
gi = self.sm.scenario.gi
664664
C = self.sm.unknown_constants
665665
phi = self.sm.scenario.phi
666-
theta= self.sm.scenario.theta
666+
theta = self.sm.scenario.theta
667667
qs = self.sm.scenario.surface_load
668668

669669
# Get number and indices of segment transitions
@@ -681,31 +681,75 @@ def differential_ERR(
681681

682682
# Compute energy relase rate of all crack tips
683683
for j, idx in enumerate(ict):
684-
685684
# Solution at crack tip
686685

687686
# Solution at unpertrubed side
688687

689688
# Mode I, II and III differential energy release rates
690689
if not self.sm.is_generalized:
691690
z = self.sm.z(
692-
li[idx], C[:, [idx]], li[idx], phi=phi, theta=theta,has_foundation=ki[idx],is_loaded=gi[idx], qs=qs if gi[idx] else 0
691+
li[idx],
692+
C[:, [idx]],
693+
li[idx],
694+
phi=phi,
695+
theta=theta,
696+
has_foundation=ki[idx],
697+
is_loaded=gi[idx],
698+
qs=qs if gi[idx] else 0,
693699
)
694700
Gdif[1:3, j] = np.concatenate(
695701
(self.sm.fq.Gi(z, unit=unit), self.sm.fq.Gii(z, unit=unit))
696702
)
697703
else:
698704
if ki[idx]:
699-
z_ct = self.sm.z(li[idx], C[:,[idx]], li[idx], phi=phi, theta=theta, has_foundation=ki[idx], is_loaded=gi[idx], qs=qs)
700-
z_ub = self.sm.z(li[idx], C[:,[idx]], li[idx], phi=phi, theta=theta, has_foundation=ki[idx], is_loaded=gi[idx], qs=qs)
705+
z_ct = self.sm.z(
706+
li[idx],
707+
C[:, [idx]],
708+
li[idx],
709+
phi=phi,
710+
theta=theta,
711+
has_foundation=ki[idx],
712+
is_loaded=gi[idx],
713+
qs=qs,
714+
)
715+
z_ub = self.sm.z(
716+
li[idx],
717+
C[:, [idx]],
718+
li[idx],
719+
phi=phi,
720+
theta=theta,
721+
has_foundation=ki[idx],
722+
is_loaded=gi[idx],
723+
qs=qs,
724+
)
701725
else:
702-
z_ct = self.sm.z(li[idx], C[:,[idx]], li[idx], phi=phi, theta=theta, has_foundation=ki[idx], is_loaded=gi[idx], qs=qs)
703-
z_ub = self.sm.z(li[idx], C[:,[idx]], li[idx], phi=phi, theta=theta, has_foundation=ki[idx], is_loaded=gi[idx], qs=qs)
704-
Gdif[1:,j] = np.concatenate(
705-
(self.sm.fq.Gi(z_ct,z_ub, phi=phi, theta=theta, unit=unit),
706-
self.sm.fq.Gii(z_ct,z_ub, phi=phi, theta=theta, unit=unit),
707-
self.sm.fq.Giii(z_ct,z_ub, phi, theta, unit=unit),)
726+
z_ct = self.sm.z(
727+
li[idx],
728+
C[:, [idx]],
729+
li[idx],
730+
phi=phi,
731+
theta=theta,
732+
has_foundation=ki[idx],
733+
is_loaded=gi[idx],
734+
qs=qs,
735+
)
736+
z_ub = self.sm.z(
737+
li[idx],
738+
C[:, [idx]],
739+
li[idx],
740+
phi=phi,
741+
theta=theta,
742+
has_foundation=ki[idx],
743+
is_loaded=gi[idx],
744+
qs=qs,
708745
)
746+
Gdif[1:, j] = np.concatenate(
747+
(
748+
self.sm.fq.Gi(z_ct, z_ub, phi=phi, theta=theta, unit=unit),
749+
self.sm.fq.Gii(z_ct, z_ub, phi=phi, theta=theta, unit=unit),
750+
self.sm.fq.Giii(z_ct, z_ub, phi, theta, unit=unit),
751+
)
752+
)
709753
# Sum mode I and II contributions
710754
Gdif[0, :] = Gdif[1, :] + Gdif[2, :] + Gdif[3, :]
711755

src/weac/analysis/criteria_evaluator.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ def evaluate_SteadyState(
746746
system_copy.set_forced_touchdown_mode(mode)
747747
touchdown_distance = system_copy.slab_touchdown.touchdown_distance
748748
analyzer = Analyzer(system_copy, printing_enabled=print_call_stats)
749-
energy_release_rate, _, _, _ = analyzer.differential_ERR(unit="J/m^2")
749+
energy_release_rate, _, _, _ = analyzer.differential_ERR(unit="J/m^2")
750750
maximal_stress_result = self._calculate_maximal_stresses(
751751
system_copy, print_call_stats=print_call_stats
752752
)
@@ -1129,7 +1129,13 @@ def _calculate_sigma_tau_at_x(
11291129
is_loaded = system.scenario.gi[segment_index]
11301130
# Calculate the displacement field
11311131
Z = system.z(
1132-
coordinate_in_segment, C, li_segment, phi, theta, has_foundation=has_foundation, is_loaded=is_loaded
1132+
coordinate_in_segment,
1133+
C,
1134+
li_segment,
1135+
phi,
1136+
theta,
1137+
has_foundation=has_foundation,
1138+
is_loaded=is_loaded,
11331139
)
11341140

11351141
# Calculate the stresses

src/weac/analysis/plotter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,15 +2062,15 @@ def plot_displacements(
20622062
[x / 10, analyzer.sm.fq.u(z, unit="mm"), r"$u_0\ (\mathrm{mm})$"],
20632063
[x / 10, -analyzer.sm.fq.w(z, unit="mm"), r"$-w\ (\mathrm{mm})$"],
20642064
[x / 10, analyzer.sm.fq.psi(z, unit="deg"), r"$\psi\ (^\circ)$ "],
2065-
]
2065+
]
20662066
else:
20672067
data = [
20682068
[x / 10, analyzer.sm.fq.u(z, unit="mm"), r"$u_0\ (\mathrm{mm})$"],
20692069
[x / 10, analyzer.sm.fq.v(z, unit="mm"), r"$v_0\ (\mathrm{mm})$"],
20702070
[x / 10, -analyzer.sm.fq.w(z, unit="mm"), r"$-w\ (\mathrm{mm})$"],
20712071
[x / 10, analyzer.sm.fq.psiy(z, unit="deg"), r"$\psi_y\ (^\circ)$ "],
20722072
[x / 10, analyzer.sm.fq.psiz(z, unit="deg"), r"$\psi_z\ (^\circ)$ "],
2073-
]
2073+
]
20742074
self._plot_data(
20752075
scenario=analyzer.sm.scenario,
20762076
ax1label=r"Displacements",

src/weac/components/layer.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ class WeakLayer(BaseModel):
254254

255255
rho: float = Field(default=125, gt=0, description="Density of the Slab [kg m⁻³]")
256256
h: float = Field(default=20, gt=0, description="Height/Thickness of the slab [mm]")
257-
f: float | None = Field(default=None, description="Weight density of the weak layer [N/mm^3]")
257+
f: float | None = Field(
258+
default=None, description="Weight density of the weak layer [N/mm^3]"
259+
)
258260
collapse_height: float = Field(
259261
default=0.0, ge=0, description="Collapse height [mm]"
260262
)
@@ -284,7 +286,10 @@ class WeakLayer(BaseModel):
284286
default="bergfeld",
285287
description="Method to calculate the Young's modulus",
286288
)
287-
constitutive_model: Literal["PlaneStrain", "PlaneStress","Uniaxial"] = Field(default = "PlaneStrain", description="Marks how interlinked the weak layer is in out-of-plane direction.")
289+
constitutive_model: Literal["PlaneStrain", "PlaneStress", "Uniaxial"] = Field(
290+
default="PlaneStrain",
291+
description="Marks how interlinked the weak layer is in out-of-plane direction.",
292+
)
288293
grain_type: GrainType | None = Field(default=None, description="Grain type")
289294
grain_size: float | None = Field(default=None, description="Grain size [mm]")
290295
hand_hardness: HandHardness | None = Field(
@@ -308,7 +313,6 @@ def model_post_init(self, _ctx): # pylint: disable=arguments-differ
308313
object.__setattr__(
309314
self, "collapse_height", self.collapse_height or _collapse_height(self.h)
310315
)
311-
312316

313317
# Validate that collapse height is smaller than layer height
314318
if self.collapse_height >= self.h:
@@ -318,14 +322,13 @@ def model_post_init(self, _ctx): # pylint: disable=arguments-differ
318322
f"increasing layer thickness."
319323
)
320324

321-
322-
if self.constitutive_model =='PlaneStrain':
325+
if self.constitutive_model == "PlaneStrain":
323326
nu_eff = self.nu
324327
E_eff = self.E
325-
elif self.constitutive_model == 'PlaneStress':
326-
nu_eff = self.nu/(1+self.nu)
327-
E_eff = self.E*(1+2*self.nu)/((1+self.nu)**2)
328-
elif self.constitutive_model == 'Uniaxial':
328+
elif self.constitutive_model == "PlaneStress":
329+
nu_eff = self.nu / (1 + self.nu)
330+
E_eff = self.E * (1 + 2 * self.nu) / ((1 + self.nu) ** 2)
331+
elif self.constitutive_model == "Uniaxial":
329332
nu_eff = 0
330333
E_eff = self.E
331334
object.__setattr__(self, "nu", nu_eff)
@@ -334,7 +337,9 @@ def model_post_init(self, _ctx): # pylint: disable=arguments-differ
334337
E_plane = self.E / (1 - self.nu**2) # plane-strain Young
335338
object.__setattr__(self, "kn", self.kn or E_plane / self.h)
336339
object.__setattr__(self, "kt", self.kt or self.G / self.h)
337-
object.__setattr__(self, "f", self.f if self.f is not None else self.rho*1e-12*G_MM_S2)
340+
object.__setattr__(
341+
self, "f", self.f if self.f is not None else self.rho * 1e-12 * G_MM_S2
342+
)
338343

339344
@model_validator(mode="after")
340345
def validate_positive_E_G(self):

src/weac/components/scenario_config.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44

55
from typing import Literal, Any, Annotated
66

7-
from pydantic import BaseModel, Field, field_validator, ConfigDict, PlainSerializer, WithJsonSchema
7+
from pydantic import (
8+
BaseModel,
9+
Field,
10+
field_validator,
11+
ConfigDict,
12+
PlainSerializer,
13+
WithJsonSchema,
14+
)
815
import numpy as np
916

1017

@@ -16,7 +23,9 @@ def _serialize_ndarray(arr: np.ndarray) -> list:
1623
NumpyArray = Annotated[
1724
np.ndarray,
1825
PlainSerializer(_serialize_ndarray, return_type=list),
19-
WithJsonSchema({"type": "array", "items": {"type": "array", "items": {"type": "number"}}}),
26+
WithJsonSchema(
27+
{"type": "array", "items": {"type": "array", "items": {"type": "number"}}}
28+
),
2029
]
2130

2231
SystemType = Literal[
@@ -83,7 +92,7 @@ class ScenarioConfig(BaseModel):
8392
description="Rotation angle in degrees (counterclockwise positive)",
8493
)
8594
b: float = Field(
86-
default = 300, ge=1, description= "Out-of-plane width of the model in [mm]"
95+
default=300, ge=1, description="Out-of-plane width of the model in [mm]"
8796
)
8897
cut_length: float = Field(
8998
default=0.0, ge=0, description="Cut length of performed PST or VPST [mm]"
@@ -100,14 +109,14 @@ class ScenarioConfig(BaseModel):
100109
"Adam et al. (2024)",
101110
)
102111
load_vector_left: NumpyArray = Field(
103-
default_factory = lambda: np.zeros((6,1)),
104-
description="Load vector on the left side of the configuration to model external loading in mode III experiments.")
105-
112+
default_factory=lambda: np.zeros((6, 1)),
113+
description="Load vector on the left side of the configuration to model external loading in mode III experiments.",
114+
)
106115

107116
load_vector_right: NumpyArray = Field(
108-
default_factory = lambda: np.zeros((6,1)),
109-
description="Load vector on the right side of the configuration to model external loading in mode III experiments.")
110-
117+
default_factory=lambda: np.zeros((6, 1)),
118+
description="Load vector on the right side of the configuration to model external loading in mode III experiments.",
119+
)
111120

112121
@field_validator("load_vector_left", "load_vector_right", mode="after")
113122
@classmethod
@@ -119,5 +128,7 @@ def check_load_vector_shape(cls, value: Any) -> Any:
119128
# Try to reshape if possible
120129
arr = arr.reshape(-1, 1)
121130
if arr.shape[0] != 6:
122-
raise ValueError(f"load vectors must have shape (6, 1), got {arr.shape}")
131+
raise ValueError(
132+
f"load vectors must have shape (6, 1), got {arr.shape}"
133+
)
123134
return arr

src/weac/components/segment.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ def _serialize_ndarray(arr: np.ndarray) -> list:
1818
NumpyArray = Annotated[
1919
np.ndarray,
2020
PlainSerializer(_serialize_ndarray, return_type=list),
21-
WithJsonSchema({"type": "array", "items": {"type": "array", "items": {"type": "number"}}}),
21+
WithJsonSchema(
22+
{"type": "array", "items": {"type": "array", "items": {"type": "number"}}}
23+
),
2224
]
2325

26+
2427
class Segment(BaseModel):
2528
"""
2629
Defines a snow-slab segment: its length, foundation support, and applied loads.
@@ -37,6 +40,7 @@ class Segment(BaseModel):
3740
m: float
3841
Skier mass at the segment's right edge [kg].
3942
"""
43+
4044
model_config = ConfigDict(arbitrary_types_allowed=True)
4145
length: float = Field(default=5e3, ge=0, description="Segment length in [mm]")
4246
has_foundation: bool = Field(
@@ -45,14 +49,15 @@ class Segment(BaseModel):
4549
"cracked/free-hanging (no foundation)",
4650
)
4751
is_loaded: bool = Field(
48-
default=True, description="Whether additional loading is applied at the segment's top side"
52+
default=True,
53+
description="Whether additional loading is applied at the segment's top side",
4954
)
5055
m: float = Field(
5156
default=0, ge=0, description="Skier mass at the segment's right edge in [kg]"
5257
)
5358

5459
f: NumpyArray = Field(
55-
default_factory=lambda: np.zeros((6,1), dtype=float),
60+
default_factory=lambda: np.zeros((6, 1), dtype=float),
5661
description=(
5762
"Load vector acting on the right side of the segment. "
5863
"Includes the six section forces [Nx, Vy, Vz, Mx, My, Mz]."

src/weac/core/eigensystem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def zp(
297297
Particular integral vector (6x1) at position x.
298298
"""
299299
# Get weight and surface loads
300-
qw_t, _, qw_n = decompose_to_xyz(f=self.slab.qw, phi=phi)
300+
qw_t, _, qw_n = decompose_to_xyz(f=self.slab.qw, phi=phi)
301301
qs_t, _, qs_n = decompose_to_xyz(f=qs, phi=phi)
302302

303303
# Weak Layer properties

src/weac/core/field_quantities.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ def Gi(self, Ztip: np.ndarray, unit: EnergyUnit = "kJ/m^2") -> float | np.ndarra
139139
Desired output unit. Default is kJ/m^2.
140140
"""
141141
return (
142-
self._unit_factor(unit) *
143-
self.es.weak_layer.kn / 2 * self.w(Ztip)**2
144-
#self.sig(Ztip) ** 2 / (2 * self.es.weak_layer.kn)
142+
self._unit_factor(unit) * self.es.weak_layer.kn / 2 * self.w(Ztip) ** 2
143+
# self.sig(Ztip) ** 2 / (2 * self.es.weak_layer.kn)
145144
)
146145

147146
def Gii(self, Ztip: np.ndarray, unit: EnergyUnit = "kJ/m^2") -> float | np.ndarray:

0 commit comments

Comments
 (0)