Skip to content

Commit 22331d8

Browse files
authored
Works on future
* plot parameters * typo correction in dir name * added cfl hint to test * test * fix test * New comment to fix issue 12 * test workflow * update pytest * update pytest * added uv * correction in stress formula * type hint and formatting * formatting again * black formatting * more work around blondel * error correction * minor correction * updated venv * added catenary model * updated example script with catenary * updated example script with catenary * formatting and namespace renaming * pyproject.toml * fix typos * formating * Pyntb version change and propagation * Auto formatting
1 parent 02ab85c commit 22331d8

21 files changed

Lines changed: 703 additions & 261 deletions

create_uvenv

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
3+
# -- dir for all envs
4+
ENV_DIR=/home/${USER}/ENV
5+
mkdir -p $ENV_DIR
6+
7+
# -- current env with link
8+
VENV=${ENV_DIR}/pallas-slenderpy-uv
9+
VLNK=.venv
10+
ln -sf $VENV $VLNK
11+
uv venv $VENV --python-preference=system # --python 3.11
12+
source $VENV/bin/activate
13+
# .venv\Scripts\activate
14+
15+
# -- upgrade pip
16+
uv pip install --upgrade pip
17+
18+
# -- install local package
19+
rm -rf build
20+
uv pip install .[examples,dev]
21+
22+
# -- end text
23+
echo "---"
24+
echo -e "\e[1mto start the environment, type :\e[0m"
25+
echo "source ${VENV}/bin/activate"
26+
echo ""
27+
echo -e "\e[1mto stop the environment, type :\e[0m"
28+
echo "deactivate"
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,22 @@
11
#!/bin/bash
22

3-
# Run this in slenderpy/examples directory !
4-
5-
63
# -- dir for all envs
74
ENV_DIR=/home/${USER}/ENV
85
mkdir -p $ENV_DIR
96

10-
117
# -- current env with link
12-
VENV=/home/${USER}/ENV/pallas-slenderpy
8+
VENV=${ENV_DIR}/pallas-slenderpy-virtualenv
139
VLNK=.venv
1410
ln -sf $VENV $VLNK
1511
python3 -m venv $VENV
1612
source $VENV/bin/activate
1713

18-
1914
# -- upgrade pip
2015
python3 -m pip install --upgrade pip
2116

22-
2317
# -- install local package
24-
cd ..
25-
pip install .[examples,test]
26-
18+
rm -rf build
19+
pip install .[examples,dev]
2720

2821
# -- end text
2922
echo "---"

doc/conf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
# -- Project information -----------------------------------------------------
1717

1818
project = "slenderpy"
19-
copyright = "2024, RTE & Eurobios Mews Labs"
20-
author = "Eurobios Mews Labs"
19+
copyright = "2025, RTE & Mews Labs"
20+
author = "Mews Labs"
2121

2222
# The full version, including alpha/beta/rc tags
23-
release = "2024.0.0"
23+
release = "2025.0.0"
2424

2525
# -- General configuration ---------------------------------------------------
2626

examples/cable_static.py

Lines changed: 83 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import matplotlib.pyplot as plt
22
import numpy as np
33

4+
from slenderpy.future._constant import _GRAVITY
5+
from slenderpy.future.cable.static import blondel
6+
from slenderpy.future.cable.static import catenary
47
from slenderpy.future.cable.static import nleq
58
from slenderpy.future.cable.static import parabolic
69

@@ -9,15 +12,16 @@ def _aster570():
912
linm = 1.571
1013
axs = 3.653e07
1114
rts = 1.853e05
12-
return linm, axs, rts
15+
alpha = 2.300e-05
16+
return linm, axs, rts, alpha
1317

1418

15-
def parabolic_vs_nleq():
19+
def parabolic_vs_catenary_vs_nleq():
1620
"""Check differences between parabolic and nleq models when everything
1721
except mechanical tension is set."""
1822

1923
# conductor properties
20-
linm, axs, rts = _aster570()
24+
linm, axs, rts, _ = _aster570()
2125

2226
# span properties
2327
lspan = 400
@@ -28,10 +32,14 @@ def parabolic_vs_nleq():
2832
xa1 = np.linspace(0, lspan * np.ones_like(tension), 401)
2933
ya1 = parabolic.shape(xa1, lspan, tension, sld, linm)
3034

35+
# position (catenary)
36+
xa2 = np.array(xa1)
37+
ya2 = catenary.shape(xa1, lspan, tension, sld, linm)
38+
3139
# position (nleq)
3240
lcab, lve = nleq.solve(lspan, tension, sld, linm, axs, rtol=1.0e-99, maxiter=2)
3341
s = np.linspace(0, lcab * np.ones_like(tension), 401)
34-
xa2, ya2 = nleq.shape(s, lspan, tension, sld, linm, axs, lcab=lcab, lve=lve)
42+
xa3, ya3 = nleq.shape(s, lspan, tension, sld, linm, axs, lcab=lcab, lve=lve)
3543

3644
# sag-to-length ratio
3745
ratio = nleq.sag(lspan, tension, sld, linm, axs) / np.sqrt(lspan**2 + sld**2)
@@ -44,7 +52,8 @@ def parabolic_vs_nleq():
4452
plt.plot(
4553
xa1[:, n], ya1[:, n], c=f"C{n}", ls="-", label=f"parabolic r={ratio[n]:.3f}"
4654
)
47-
plt.plot(xa2[:, n], ya2[:, n], c=f"C{n}", ls="--", label="nleq")
55+
plt.plot(xa2[:, n], ya2[:, n], c=f"C{n}", ls="--", label="catenary")
56+
plt.plot(xa3[:, n], ya3[:, n], c=f"C{n}", ls=":", lw=2, label="nleq")
4857
plt.grid(True)
4958
plt.xlabel("$x$ (m)")
5059
plt.ylabel("$y$ (m)")
@@ -56,13 +65,11 @@ def parabolic_vs_nleq():
5665
def compare_all(lspan=400.0, ratio=0.25, sld=0.0):
5766
"""Quick plot script to make visual check"""
5867

59-
# NB: we can see that the sag/argsag functions in cable are max chord and not sag ...
60-
6168
# lspan = 100.
6269
# ratio = 0.01
6370
# sld = 10.
6471

65-
linm, axs, rts = _aster570()
72+
linm, axs, rts, _ = _aster570()
6673
tension = ratio * rts
6774

6875
# [parabolic] compute cable stuff
@@ -97,32 +104,37 @@ def compare_all(lspan=400.0, ratio=0.25, sld=0.0):
97104
sx_ = np.max(nleq.stress(1001, lspan, tension, sld, linm, axs, lcab=lcab, lve=lve))
98105
sa_ = nleq.mean_stress(lspan, tension, sld, linm, axs, lcab=lcab, lve=lve)
99106

100-
# [old] [catenary]
101-
from slenderpy.future._constant import _GRAVITY
102-
import slenderpy.cable as sc
107+
# [catenary] compute cable stuff
103108

104109
# static shape
105-
s = np.linspace(0, 1, 101)
106-
a = tension / (linm * _GRAVITY)
107-
y = sc._alts(s, lspan, a, sld)
108-
110+
xc = np.linspace(0, 1, 101)
111+
yc = catenary.shape(xc, lspan, tension, sld, linm)
112+
# cable length
113+
lc = catenary.length(lspan, tension, sld, linm)
114+
# cable sag
115+
sagc = catenary.sag(lspan, tension, sld, linm)
109116
# sag points
110-
xc = sc.argsag(lspan, a, sld) * lspan
111-
yc = sc._alts(xc / lspan, lspan, a, sld)
117+
xu = catenary.argsag(lspan, tension, sld, linm)
118+
yu = catenary.shape(xu, lspan, tension, sld, linm)
119+
# stress
120+
nn = float("nan")
121+
# > not implemented yet
112122

113123
# [print]
114124
print(f"[all] flat length {lspan:.6f}")
115125
print(f"[all] 3dim length {np.sqrt(lspan**2 + sld**2):.6f}")
116126
print(f"[pbl] cable length {length:.6f}")
117-
print(f"[cat] cable length {sc.catenary_length(lspan, a, sld):.6f}")
127+
print(f"[cat] cable length {lc:.6f}")
118128
print(f"[nle] cable len 0 {lcab:.6f}")
119129
print(f"[nle] cable len 1 {length_:.6f}")
120130
print(f"[pbl] sag {sag:.6f}")
121-
print(f"[cat] sag {sc.sag(lspan, a, sld):.6f}")
131+
print(f"[cat] sag {sagc:.6f}")
122132
print(f"[nle] sag {sag_:.6f}")
123133
print(f"[pbl] max stress {sx:.6f}")
134+
print(f"[cat] max stress {nn:.6f}")
124135
print(f"[nle] max stress {sx_:.6f}")
125136
print(f"[pbl] avg stress {sa:.6f}")
137+
print(f"[cat] avg stress {nn:.6f}")
126138
print(f"[nle] avg stress {sa_:.6f}")
127139

128140
# [plot]
@@ -132,8 +144,8 @@ def compare_all(lspan=400.0, ratio=0.25, sld=0.0):
132144
plt.plot([xs, xs], [ys, xs * sld / lspan], ls="--", c="C0")
133145
plt.plot(xn, yn, label="NL eq.", c="C1")
134146
plt.plot([xt, xt], [yt, xt * sld / lspan], ls="--", c="C1")
135-
plt.plot(s * lspan, y, c="C2", label="catenary")
136-
plt.plot([xc, xc], [yc, xc * sld / lspan], ls="--", c="C2")
147+
plt.plot(xc, yc, c="C2", label="catenary")
148+
plt.plot([xu, xu], [yu, xu * sld / lspan], ls="--", c="C2")
137149
plt.legend()
138150
plt.xlabel("$x$")
139151
plt.ylabel("$y$")
@@ -147,13 +159,62 @@ def compare_all(lspan=400.0, ratio=0.25, sld=0.0):
147159
return
148160

149161

162+
def test_blondel():
163+
164+
# conductor properties
165+
linm, axs, rts, alpha = _aster570()
166+
167+
# span properties
168+
lspan = 400
169+
tensions = rts * np.array([0.02, 0.05, 0.1, 0.2])
170+
slds = np.array([0.0, 20.0, 50.0, 100.0])
171+
172+
# temperatures
173+
Tref = 15.0
174+
Tend = Tref + np.linspace(-20, +80, 101)
175+
dt = Tend - Tref
176+
177+
#
178+
fig, ax = plt.subplots(nrows=len(slds), ncols=len(tensions))
179+
for i in range(len(slds)):
180+
for j in range(len(tensions)):
181+
182+
sld = slds[i]
183+
tension = tensions[j]
184+
185+
# compute new tensions
186+
w = linm * _GRAVITY * lspan
187+
tb = blondel.tension(w, tension, Tref, Tend, axs, alpha)
188+
tp = parabolic.thermal_expansion_tension(
189+
lspan, tension, sld, Tref, Tend, linm, alpha
190+
)
191+
tn = nleq.thermal_expansion_tension(
192+
lspan, tension, sld, Tref, Tend, linm, axs, alpha
193+
)
194+
195+
ax[i, j].plot(dt, tb - tension, label="blondel")
196+
ax[i, j].plot(dt, tp - tension, label="parabolic")
197+
ax[i, j].plot(dt, tn - tension, label="nleq")
198+
ax[i, j].grid(True)
199+
ax[i, j].set_title(f"With H={tension/1000.} kN and h={sld} m")
200+
201+
ax[-1, -1].legend()
202+
for i in range(len(slds)):
203+
ax[i, 0].set_ylabel("Tension difference (N)")
204+
for j in range(len(tensions)):
205+
ax[-1, j].set_xlabel("Temperature difference (K)")
206+
207+
150208
if __name__ == "__main__":
151209
import matplotlib
152210

153211
matplotlib.use("TkAgg")
154212
plt.close("all")
155213

156-
parabolic_vs_nleq()
214+
parabolic_vs_catenary_vs_nleq()
215+
157216
compare_all(lspan=400.0, ratio=0.25, sld=10.0)
158217
print()
159218
compare_all(lspan=100.0, ratio=0.01, sld=15.0)
219+
#
220+
test_blondel()

pyproject.toml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[build-system]
22
requires = [
3-
"setuptools>=40.8.0",
3+
"setuptools>=68.0.0",
44
]
55
build-backend = "setuptools.build_meta"
66

@@ -22,8 +22,8 @@ dependencies = [
2222
"matplotlib >= 3.3.2",
2323
"numpy >= 1.19.0",
2424
"pandas >= 1.1.3",
25-
"pyntb > 2024.0.1",
26-
"scipy >= 1.5.2",
25+
"pyntb >= 2025.0.1",
26+
"scipy >= 1.7.0",
2727
"tqdm >= 4.58.0",
2828
"xarray >= 0.16.2",
2929
]
@@ -34,7 +34,15 @@ examples = [
3434
]
3535
test = [
3636
"pylint",
37-
"pytest",
37+
"pytest",
38+
]
39+
lint = [
40+
"black ~= 25.1.0",
41+
"mypy ~= 1.13.0",
42+
"ruff ~= 0.8.0"
43+
]
44+
dev = [
45+
"slenderpy[test,lint]",
3846
]
3947

4048
[project.urls]

src/slenderpy/_cable_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import scipy.interpolate
77
import scipy.sparse
88
from scipy.optimize import brenth
9+
910
from slenderpy import fdm_utils as fdmu
1011

1112

src/slenderpy/beam.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import numpy as np
66
import scipy as sp
77
from scipy.optimize import newton
8+
89
from slenderpy import _cable_utils as cbu
910
from slenderpy import _progress_bar as spb
1011
from slenderpy import fdm_utils as fdu

0 commit comments

Comments
 (0)