Skip to content

Commit bba14d1

Browse files
committed
Updates
1 parent cb05855 commit bba14d1

16 files changed

Lines changed: 1320 additions & 67 deletions
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
"""3-D Unsteady Pulsatile Flow through an Axisymmetric AAA — Time-Marching TL.
2+
3+
Run directly or via the CLI:
4+
5+
python examples/AAA/AAA_pulsatile_transfer.py
6+
python examples/AAA/AAA_pulsatile_transfer.py myconfig.yaml
7+
python -m underPINN run examples/AAA/AAA_pulsatile_transfer.yaml
8+
9+
Same time-marching transfer-learning framework as ``pipe_flow_pulsatile_transfer``
10+
but in the **AAA (bulge)** geometry, Newtonian rheology. The inlet imposes a
11+
pulsatile parabolic profile
12+
13+
u_inlet(r, t) = (V_max + V_amp · sin(2π t / T_period)) · (1 − r²/R_vessel²)
14+
15+
with no-slip on the curved wall and p = 0 at the outlet. The steady
16+
Poiseuille profile is used as the initial condition at t = 0. Overlapping
17+
windows are supported via ``time_marching.stride < dT``.
18+
19+
Network: (x, y, z, t) → (u, v, w, p)
20+
"""
21+
from __future__ import annotations
22+
23+
import os
24+
os.environ.setdefault("XLA_PYTHON_CLIENT_PREALLOCATE", "false")
25+
26+
from underPINN.config.loader import cfg_get
27+
from underPINN.pde.navier_stokes_3d import UnsteadyNS3DPDE
28+
from underPINN.geometry.aaa import BulgeGeometry
29+
from underPINN.utils.pulsatile_time_march import (
30+
cosine_squared_inlet_factory,
31+
make_model_from_cfg,
32+
parabolic_steady_uvw_factory,
33+
run_pulsatile_time_march,
34+
)
35+
36+
37+
def run_AAA_pulsatile_transfer(cfg) -> dict:
38+
ph = cfg.physics
39+
Re = float(cfg_get(ph, "Re", default=40.0))
40+
R_vessel = float(cfg_get(ph, "R_vessel", default=0.5))
41+
R_AAA = float(cfg_get(ph, "R_AAA", default=1.0))
42+
L = float(cfg_get(ph, "L", default=7.0))
43+
x_lo = float(cfg_get(ph, "x_lo", default=-3.5))
44+
x0 = float(cfg_get(ph, "x0", default=-2.0))
45+
L_AAA = float(cfg_get(ph, "L_AAA", default=1.5))
46+
V_max = float(cfg_get(ph, "V_max", default=2.0))
47+
V_amp = float(cfg_get(ph, "V_amp", default=1.0))
48+
T_period = float(cfg_get(ph, "T_period", default=1.0))
49+
x_hi = x_lo + L
50+
x_mid = 0.5 * (x_lo + x_hi)
51+
52+
print(f"AAA pulsatile (3-D unsteady): Re={Re}, R_vessel={R_vessel}, "
53+
f"R_AAA={R_AAA}, x∈[{x_lo}, {x_hi}], x0={x0}, L_AAA={L_AAA}")
54+
print(f" Inlet peak(t) = {V_max} + {V_amp}·sin(2π t/{T_period}) "
55+
f"(parabolic profile)")
56+
57+
geom = BulgeGeometry(R_vessel=R_vessel, R_AAA=R_AAA, L=L,
58+
x_lo=x_lo, x0=x0, L_AAA=L_AAA)
59+
model, _ = make_model_from_cfg(cfg)
60+
pde = UnsteadyNS3DPDE(model, Re=Re)
61+
62+
return run_pulsatile_time_march(
63+
cfg,
64+
problem_spec=dict(
65+
problem="AAA_pulsatile_transfer",
66+
label="AAA pulsatile flow (Newtonian)",
67+
geom=geom, pde=pde,
68+
inlet_target_fn=cosine_squared_inlet_factory(
69+
R_vessel, V_max, V_amp, T_period),
70+
steady_uvw_fn=parabolic_steady_uvw_factory(R_vessel, V_max),
71+
physics_dict={"Re": Re, "R_vessel": R_vessel, "R_AAA": R_AAA,
72+
"L": L, "x_lo": x_lo, "x0": x0, "L_AAA": L_AAA,
73+
"V_max": V_max, "V_amp": V_amp, "T_period": T_period},
74+
plot_extent=(x_lo, x_hi, x_mid),
75+
),
76+
out_dir_default="outputs/AAA_pulsatile_transfer",
77+
)
78+
79+
80+
if __name__ == "__main__":
81+
import sys
82+
import pathlib
83+
_HERE = pathlib.Path(__file__).parent
84+
cfg_path = str(
85+
pathlib.Path(sys.argv[1]) if len(sys.argv) > 1
86+
else _HERE / "AAA_pulsatile_transfer.yaml"
87+
)
88+
from underPINN.config.loader import load_config
89+
run_AAA_pulsatile_transfer(load_config(cfg_path))
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
problem: AAA_pulsatile_transfer
2+
# Run via:
3+
# python examples/AAA/AAA_pulsatile_transfer.py
4+
# python -m underPINN run examples/AAA/AAA_pulsatile_transfer.yaml
5+
#
6+
# Same domain and Reynolds number as the steady AAA case
7+
# (examples/AAA/config.yaml). Pulsatile inlet:
8+
# u_inlet(r,t) = (V_max + V_amp·sin(2πt/T_period))·(1 − r²/R_vessel²)
9+
# Long-time integration via time-marching transfer learning, optionally with
10+
# OVERLAPPING windows (set stride < dT).
11+
12+
network:
13+
type : gated_mlp # 'mlp' or 'gated_mlp'
14+
layers: [4, 128, 128, 128, 128, 4] # (x, y, z, t) → (u, v, w, p)
15+
16+
physics:
17+
Re : 40.0
18+
R_vessel : 0.5 # straight-vessel radius
19+
R_AAA : 1.0 # peak bulge radius
20+
L : 7.0 # total domain length
21+
x_lo : -3.5 # inlet x
22+
x0 : -2.0 # bulge centre
23+
L_AAA : 1.5 # axial bulge width
24+
V_max : 2.0 # mean centreline peak
25+
V_amp : 1.0 # pulsation amplitude
26+
T_period : 1.0 # pulse period
27+
28+
# ── Time-marching transfer learning ──────────────────────────────────────────
29+
time_marching:
30+
T_total : 4.0 # 4 pulse cycles
31+
dT : 0.5 # window length
32+
stride : 0.5 # set < dT for overlapping windows
33+
n_first_epochs : 12000
34+
n_warm_epochs : 4000
35+
n_cold_epochs : 12000
36+
compare_no_transfer: true
37+
restart : true
38+
first_lr : 1.0e-3
39+
warm_lr : 5.0e-4
40+
cold_lr : 1.0e-3
41+
lr_alpha : 0.01
42+
43+
# ── Collocation data (per window) ────────────────────────────────────────────
44+
data:
45+
n_interior: 30000
46+
n_wall : 6000
47+
n_inlet : 1200
48+
n_outlet : 1200
49+
n_ic : 2500
50+
batch_r : 2048
51+
batch_bc : 512
52+
53+
loss:
54+
w_pde : 1.0
55+
w_wall : 100.0
56+
w_inlet : 50.0
57+
w_outlet: 20.0
58+
w_ic : 100.0
59+
60+
output:
61+
dir: outputs/AAA_pulsatile_transfer
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"""3-D Unsteady Pulsatile Flow through an Axisymmetric AAA with Carreau Blood.
2+
3+
Time-marching transfer learning combining the AAA bulge geometry with the
4+
Carreau (shear-thinning blood) constitutive law:
5+
6+
μ*(γ̇*) = 1 + (β − 1)[1 + (Cu γ̇*)²]^((n−1)/2)
7+
blood: β = 16, n = 0.3568.
8+
9+
Domain and Reynolds number are identical to the steady AAA-rheology case
10+
(``examples/AAA_rheology/config.yaml``). Inlet imposes the developed Carreau
11+
radial profile modulated in time:
12+
13+
u_inlet(r, t) = (V_max + V_amp · sin(2π t / T_period)) · u*_carr(r/R_vessel)
14+
15+
Network: (x, y, z, t) → (u, v, w, p)
16+
"""
17+
from __future__ import annotations
18+
19+
import os
20+
os.environ.setdefault("XLA_PYTHON_CLIENT_PREALLOCATE", "false")
21+
22+
from underPINN.config.loader import cfg_get
23+
from underPINN.pde.carreau_ns_3d import UnsteadyCarreauNS3DPDE
24+
from underPINN.geometry.aaa import BulgeGeometry
25+
from underPINN.utils.pulsatile_time_march import (
26+
carreau_inlet_factory,
27+
carreau_steady_uvw_factory,
28+
make_model_from_cfg,
29+
run_pulsatile_time_march,
30+
)
31+
32+
33+
def run_AAA_rheology_pulsatile(cfg) -> dict:
34+
ph = cfg.physics
35+
Re = float(cfg_get(ph, "Re", default=40.0))
36+
R_vessel = float(cfg_get(ph, "R_vessel", default=0.5))
37+
R_AAA = float(cfg_get(ph, "R_AAA", default=1.0))
38+
L = float(cfg_get(ph, "L", default=7.0))
39+
x_lo = float(cfg_get(ph, "x_lo", default=-3.5))
40+
x0 = float(cfg_get(ph, "x0", default=-2.0))
41+
L_AAA = float(cfg_get(ph, "L_AAA", default=1.5))
42+
V_max = float(cfg_get(ph, "V_max", default=2.0))
43+
V_amp = float(cfg_get(ph, "V_amp", default=1.0))
44+
T_period = float(cfg_get(ph, "T_period", default=1.0))
45+
beta = float(cfg_get(ph, "beta", default=16.0))
46+
Cu = float(cfg_get(ph, "Cu", default=10.0))
47+
n = float(cfg_get(ph, "n", default=0.3568))
48+
x_hi = x_lo + L
49+
x_mid = 0.5 * (x_lo + x_hi)
50+
51+
print(f"Carreau pulsatile AAA (3-D unsteady): Re={Re}, R_vessel={R_vessel}, "
52+
f"R_AAA={R_AAA}, x∈[{x_lo}, {x_hi}], x0={x0}, L_AAA={L_AAA}")
53+
print(f" Carreau: β={beta}, Cu={Cu}, n={n}")
54+
print(f" Inlet peak(t) = {V_max} + {V_amp}·sin(2π t/{T_period}) "
55+
f"(Carreau-developed profile)")
56+
57+
geom = BulgeGeometry(R_vessel=R_vessel, R_AAA=R_AAA, L=L,
58+
x_lo=x_lo, x0=x0, L_AAA=L_AAA)
59+
model, _ = make_model_from_cfg(cfg)
60+
pde = UnsteadyCarreauNS3DPDE(model, Re=Re, beta=beta, Cu=Cu, n=n)
61+
62+
return run_pulsatile_time_march(
63+
cfg,
64+
problem_spec=dict(
65+
problem="AAA_rheology_pulsatile",
66+
label="Carreau pulsatile AAA",
67+
geom=geom, pde=pde,
68+
inlet_target_fn=carreau_inlet_factory(
69+
R_vessel, V_max, V_amp, T_period, beta, Cu, n),
70+
steady_uvw_fn=carreau_steady_uvw_factory(
71+
R_vessel, V_max, beta, Cu, n),
72+
physics_dict={"Re": Re, "R_vessel": R_vessel, "R_AAA": R_AAA,
73+
"L": L, "x_lo": x_lo, "x0": x0, "L_AAA": L_AAA,
74+
"V_max": V_max, "V_amp": V_amp, "T_period": T_period,
75+
"beta": beta, "Cu": Cu, "n": n},
76+
plot_extent=(x_lo, x_hi, x_mid),
77+
),
78+
out_dir_default="outputs/AAA_rheology_pulsatile",
79+
)
80+
81+
82+
if __name__ == "__main__":
83+
import sys
84+
import pathlib
85+
_HERE = pathlib.Path(__file__).parent
86+
cfg_path = str(
87+
pathlib.Path(sys.argv[1]) if len(sys.argv) > 1
88+
else _HERE / "AAA_rheology_pulsatile.yaml"
89+
)
90+
from underPINN.config.loader import load_config
91+
run_AAA_rheology_pulsatile(load_config(cfg_path))
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
problem: AAA_rheology_pulsatile
2+
# Run via:
3+
# python examples/AAA_rheology/AAA_rheology_pulsatile.py
4+
# python -m underPINN run examples/AAA_rheology/AAA_rheology_pulsatile.yaml
5+
#
6+
# Same domain/Re as the steady AAA-rheology case
7+
# (examples/AAA_rheology/config.yaml). Carreau blood rheology in the AAA bulge,
8+
# pulsatile inlet.
9+
10+
network:
11+
type : gated_mlp
12+
layers: [4, 128, 128, 128, 128, 128, 4] # (x, y, z, t) → (u, v, w, p)
13+
14+
physics:
15+
Re : 40.0
16+
R_vessel : 0.5
17+
R_AAA : 1.0
18+
L : 7.0
19+
x_lo : -3.5
20+
x0 : -2.0
21+
L_AAA : 1.5
22+
V_max : 2.0
23+
V_amp : 1.0
24+
T_period : 1.0
25+
# Carreau rheology — blood values (Nagargoje et al. 2021, Table II):
26+
# λ = 3.131 s, n = 0.3568, μ0/μ∞ = 16
27+
# Diameter-based non-dim: D = 2·R_vessel = 1.0, U_mean = V_max/2 = 1.0
28+
# Re = ρ U_mean D / μ∞ = 40, Cu = λ U_mean / D = 3.131
29+
beta : 16.0
30+
Cu : 3.131 # = λ U_mean / D
31+
n : 0.3568
32+
33+
time_marching:
34+
T_total : 4.0
35+
dT : 0.5
36+
stride : 0.5
37+
n_first_epochs : 12000
38+
n_warm_epochs : 4000
39+
n_cold_epochs : 12000
40+
compare_no_transfer: true
41+
restart : true
42+
first_lr : 1.0e-3
43+
warm_lr : 5.0e-4
44+
cold_lr : 1.0e-3
45+
lr_alpha : 0.01
46+
47+
data:
48+
n_interior: 40000
49+
n_wall : 8000
50+
n_inlet : 1500
51+
n_outlet : 1500
52+
n_ic : 3000
53+
batch_r : 2048
54+
batch_bc : 512
55+
56+
loss:
57+
w_pde : 1.0
58+
w_wall : 100.0
59+
w_inlet : 50.0
60+
w_outlet: 20.0
61+
w_ic : 100.0
62+
63+
output:
64+
dir: outputs/AAA_rheology_pulsatile

examples/AAA_rheology/config.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ physics:
2828
x0 : -2.0 # axial centre of the bulge
2929
L_AAA : 1.5 # full axial width of the bulge region
3030
V_max : 2.0 # inlet centreline velocity (matches Newtonian V_max)
31-
# Carreau rheology (blood values from the paper)
31+
# Carreau rheology (Nagargoje, Mishra & Gupta 2021, Table II — blood):
32+
# λ = 3.131 s, n = 0.3568, μ0/μ∞ = 16
33+
# Non-dim groups in this sim are diameter/mean-velocity based:
34+
# D = 2·R_vessel = 1.0, U_mean = V_max/2 = 1.0 (parabolic)
35+
# Re = ρ U_mean D / μ∞ = 40
36+
# Cu = λ U_mean / D = 3.131
3237
beta : 16.0 # viscosity ratio μ0/μ∞ (1 = Newtonian)
33-
Cu : 10.0 # Carreau number (shear-thinning strength)
38+
Cu : 3.131 # = λ·U_mean/D
3439
n : 0.3568 # power-law index
3540

3641
data:

0 commit comments

Comments
 (0)