Skip to content

Commit f668de1

Browse files
committed
Have a common FritionSpec block for choosing the Friction method
Move to Types
1 parent 34ba0e3 commit f668de1

7 files changed

Lines changed: 85 additions & 54 deletions

File tree

OpenHPL/Data.mo

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ record Data "Provides a data set of most common used settings"
33
extends Modelica.Icons.Record;
44
parameter Boolean showElevation=true "Display elevation of connectors"
55
annotation(Dialog(group = "Icon"),
6-
choices(checkBox = true));
6+
choices(checkBox = true));
77
parameter SI.Acceleration g = Modelica.Constants.g_n "Gravity constant"
88
annotation (Dialog(enable=false, group = "Constants"));
99
parameter Real gamma_air = 1.4 "Ratio of heat capacities at constant pressure (C_p) to constant volume (C_v) for air at STP"
@@ -16,8 +16,24 @@ record Data "Provides a data set of most common used settings"
1616
annotation (Dialog(group = "Waterway properties"));
1717
parameter SI.DynamicViscosity mu = 1.3076e-3 "Dynamic viscosity of water at T_0"
1818
annotation (Dialog(group = "Waterway properties"));
19-
parameter SI.Height p_eps = 0 "Pipe roughness height (default is smooth pipe)"
20-
annotation (Dialog(group = "Waterway properties"));
19+
parameter Types.FrictionMethod FrictionMethod = Types.FrictionMethod.PipeRoughness "Default friction specification method"
20+
annotation (Dialog(group = "Friction"));
21+
parameter SI.Height p_eps_input = 0 "Pipe roughness height (for PipeRoughness method)"
22+
annotation (Dialog(group = "Friction", enable = FrictionMethod == Types.FrictionMethod.PipeRoughness));
23+
parameter Real f_moody(min=0) = 0.02 "Moody friction factor (used when FrictionMethod = MoodyFriction)"
24+
annotation (Dialog(group = "Friction", enable = FrictionMethod == Types.FrictionMethod.MoodyFriction));
25+
parameter Real m_manning(unit="m(1/3)/s", min=0) = 40 "Manning M (Strickler) coefficient (used when FrictionMethod = ManningFriction)"
26+
annotation (Dialog(group = "Friction", enable = FrictionMethod == Types.FrictionMethod.ManningFriction and not use_n));
27+
parameter Boolean use_n = false "If true, use Manning's n instead of M"
28+
annotation (Dialog(group = "Friction", enable = FrictionMethod == Types.FrictionMethod.ManningFriction), choices(checkBox=true));
29+
parameter Real n_manning(unit="s/m(1/3)", min=0) = 0.025 "Manning's n coefficient (used when FrictionMethod = ManningFriction and use_n)"
30+
annotation (Dialog(group = "Friction", enable = FrictionMethod == Types.FrictionMethod.ManningFriction and use_n));
31+
parameter SI.Diameter D_h = 1.0 "Reference hydraulic diameter for friction conversion (used for Moody/Manning)"
32+
annotation (Dialog(group = "Friction", enable = FrictionMethod <> Types.FrictionMethod.PipeRoughness));
33+
final parameter Real n_eff_ = if use_n then n_manning else 1/m_manning "Effective Manning's n coefficient";
34+
final parameter SI.Height p_eps = if FrictionMethod == Types.FrictionMethod.PipeRoughness then p_eps_input
35+
elseif FrictionMethod == Types.FrictionMethod.MoodyFriction then 3.7 * D_h * 10^(-1/(2*sqrt(f_moody)))
36+
else D_h * 3.0971 * exp(-0.118/n_eff_) "Computed equivalent pipe roughness height";
2137
parameter SI.Compressibility beta = 4.5e-10 "Water compressibility"
2238
annotation (Dialog(group = "Waterway properties"));
2339
parameter SI.Compressibility beta_total = 1 / (rho*1000^2) "Total compressibility"

OpenHPL/Types/FrictionSpec.mo

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
within OpenHPL.Types;
2+
partial model FrictionSpec "Reusable friction specification with multiple input methods"
3+
outer Data data "Using standard data set";
4+
5+
parameter Types.FrictionMethod FrictionMethod = data.FrictionMethod "Method for specifying pipe friction" annotation (
6+
Dialog(group = "Friction"));
7+
parameter SI.Height p_eps_input = data.p_eps "Pipe roughness height (absolute)" annotation (
8+
Dialog(group = "Friction", enable = FrictionMethod == Types.FrictionMethod.PipeRoughness));
9+
parameter Real f_moody(min=0) = data.f_moody "Moody friction factor (dimensionless, typically 0.01-0.05)" annotation (
10+
Dialog(group = "Friction", enable = FrictionMethod == Types.FrictionMethod.MoodyFriction));
11+
parameter Real m_manning(unit="m(1/3)/s", min=0) = data.m_manning "Manning M (Strickler) coefficient M=1/n (typically 60-110 for steel, 30-60 for rock tunnels)" annotation (
12+
Dialog(group = "Friction", enable = FrictionMethod == Types.FrictionMethod.ManningFriction and not use_n));
13+
parameter Boolean use_n = data.use_n "If true, use Mannings coefficient n (=1/M) instead of Manning's M (Strickler)" annotation (
14+
Dialog(group = "Friction", enable = FrictionMethod == Types.FrictionMethod.ManningFriction), choices(checkBox=true));
15+
parameter Real n_manning(unit="s/m(1/3)", min=0) = data.n_manning "Manning's n coefficient (typically 0.009-0.017 for steel/concrete, 0.017-0.030 for rock tunnels)" annotation (
16+
Dialog(group = "Friction", enable = FrictionMethod == Types.FrictionMethod.ManningFriction and use_n));
17+
18+
parameter SI.Diameter D_h "Hydraulic diameter used for friction conversion" annotation (
19+
Dialog(group = "Friction"));
20+
21+
protected
22+
parameter Real n_eff = if use_n then n_manning else 1/m_manning "Effective Manning's n coefficient";
23+
parameter SI.Height p_eps = if FrictionMethod == Types.FrictionMethod.PipeRoughness then p_eps_input
24+
elseif FrictionMethod == Types.FrictionMethod.MoodyFriction then 3.7 * D_h * 10^(-1/(2*sqrt(f_moody)))
25+
else D_h * 3.0971 * exp(-0.118/n_eff) "Equivalent pipe roughness height";
26+
27+
annotation (preferredView="info",
28+
Documentation(info="<html>
29+
<h4>Friction Specification</h4>
30+
<p>Partial model providing a reusable friction parameter set. Extending models must supply
31+
the hydraulic diameter <code>D_h</code> used for converting Moody and Manning coefficients
32+
to equivalent pipe roughness height <code>p_eps</code>.</p>
33+
34+
<p>Three friction specification methods are supported via the <code>FrictionMethod</code> parameter:</p>
35+
<ul>
36+
<li><strong>Pipe Roughness (p_eps)</strong>: Direct specification of absolute pipe roughness height (m).
37+
Typical values: 0.0001&ndash;0.001 m for steel pipes, 0.001&ndash;0.003 m for concrete.</li>
38+
<li><strong>Moody Friction Factor (f)</strong>: Dimensionless friction factor from Moody diagram.
39+
Typical values: 0.01&ndash;0.05. Converted to equivalent roughness using fully turbulent flow approximation:
40+
p_eps = 3.7&middot;D&middot;10<sup>-1/(2&radic;f)</sup></li>
41+
<li><strong>Manning Coefficient</strong>: Two notations are supported:
42+
<ul>
43+
<li><strong>Manning's M coefficient (Strickler)</strong> [m<sup>1/3</sup>/s]: M = 1/n, typical values 60&ndash;110 for steel,
44+
30&ndash;60 for rock tunnels.</li>
45+
<li><strong>Manning's n coefficient</strong> [s/m<sup>1/3</sup>]: Typical values 0.009&ndash;0.013 for smooth steel,
46+
0.012&ndash;0.017 for concrete, 0.017&ndash;0.030 for rock tunnels. Use checkbox <code>use_n</code> to enable.</li>
47+
</ul>
48+
Converted using: p_eps = D_h&middot;3.097&middot;e<sup>(-0.118/n)</sup> empirically derived from the Karman-Prandtl equation.</li>
49+
</ul>
50+
</html>"));
51+
end FrictionSpec;

OpenHPL/Types/package.order

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ DraftTube
22
Efficiency
33
Fitting
44
FrictionMethod
5+
FrictionSpec
56
Lambda
67
SurgeTank

OpenHPL/Waterway/DraftTube.mo

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
within OpenHPL.Waterway;
1+
within OpenHPL.Waterway;
22
model DraftTube "Model of a draft tube for reaction turbines"
33
outer Data data "Using standard data set";
44
extends OpenHPL.Icons.DraftTube;
5+
extends Types.FrictionSpec( final D_h = 0.5 * (D_i + D_o));
56
import Modelica.Constants.pi;
67
parameter Types.DraftTube DraftTubeType = OpenHPL.Types.DraftTube.ConicalDiffuser "Types of draft tube" annotation (
78
Dialog(group = "Draft tube types"));
@@ -29,8 +30,6 @@ model DraftTube "Model of a draft tube for reaction turbines"
2930
choice = 45 "45°",
3031
choice = 60 "60°",
3132
choice = 90 "90°"));
32-
parameter SI.Height p_eps = data.p_eps "Pipe roughness height" annotation (
33-
Dialog(group = "Geometry"));
3433
parameter Boolean SteadyState=data.SteadyState "If true, starts in steady state" annotation (Dialog(group="Initialization"));
3534
parameter SI.VolumeFlowRate Vdot_0=data.Vdot_0 "Initial volume flow rate" annotation (Dialog(group="Initialization"));
3635

OpenHPL/Waterway/PenstockKP.mo

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
within OpenHPL.Waterway;
1+
within OpenHPL.Waterway;
22
model PenstockKP "Detailed model of the pipe. Could have elastic walls and compressible water. KP scheme"
33
outer OpenHPL.Data data "Using standard data set";
44
extends OpenHPL.Icons.Pipe( vertical=true);
5+
extends Types.FrictionSpec( final D_h = (D_i + D_o) / 2);
56
import Modelica.Constants.pi;
67
// geometrical parameters of the pipe
78
parameter SI.Height H = 420 "Height difference from the inlet to the outlet of the pipe" annotation (
@@ -12,8 +13,6 @@ model PenstockKP "Detailed model of the pipe. Could have elastic walls and compr
1213
Dialog(group = "Geometry"));
1314
parameter SI.Diameter D_o = D_i "Diametr from the outlet side of the pipe" annotation (
1415
Dialog(group = "Geometry"));
15-
parameter SI.Height p_eps = data.p_eps "Pipe roughness height" annotation (
16-
Dialog(group = "Geometry"));
1716
// condition of steady state
1817
parameter Boolean SteadyState=data.SteadyState "If true, starts in steady state" annotation (Dialog(group="Initialization"));
1918
// staedy state values for flow rate in all segments of the pipe

OpenHPL/Waterway/Pipe.mo

Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
within OpenHPL.Waterway;
1+
within OpenHPL.Waterway;
22
model Pipe "Model of a pipe"
33
outer Data data "Using standard data set";
44
extends OpenHPL.Icons.Pipe;
55
extends OpenHPL.Interfaces.TwoContacts;
6+
extends Types.FrictionSpec( final D_h = (D_i + D_o) / 2);
67

78
// Geometrical parameters of the pipe:
89
parameter SI.Length H = 0 "Height difference from the inlet to the outlet" annotation (
@@ -14,21 +15,6 @@ model Pipe "Model of a pipe"
1415
parameter SI.Diameter D_o = D_i "Diameter of the outlet side" annotation (
1516
Dialog(group = "Geometry"));
1617

17-
// Friction specification:
18-
parameter Types.FrictionMethod friction_method = Types.FrictionMethod.PipeRoughness "Method for specifying pipe friction" annotation (
19-
Dialog(group = "Friction"));
20-
parameter SI.Height p_eps_input = data.p_eps "Pipe roughness height (absolute)" annotation (
21-
Dialog(group = "Friction", enable = friction_method == Types.FrictionMethod.PipeRoughness));
22-
parameter Real f_moody(min=0) = 0.02 "Moody friction factor (dimensionless, typically 0.01-0.05)" annotation (
23-
Dialog(group = "Friction", enable = friction_method == Types.FrictionMethod.MoodyFriction));
24-
parameter Real m_manning(unit="m(1/3)/s", min=0) = 40 "Manning M (Strickler) coefficient M=1/n (typically 60-110 for steel, 30-60 for rock tunnels)" annotation (
25-
Dialog(group = "Friction", enable = friction_method == Types.FrictionMethod.ManningFriction and not use_n));
26-
parameter Boolean use_n = false "If true, use Mannings coefficient n (=1/M) instead of Manning's M (Strickler)" annotation (
27-
Dialog(group = "Friction", enable = friction_method == Types.FrictionMethod.ManningFriction), choices(checkBox=true));
28-
parameter Real n_manning(unit="s/m(1/3)", min=0) = 0.025 "Manning's n coefficient (typically 0.009-0.017 for steel/concrete, 0.017-0.030 for rock tunnels)" annotation (
29-
Dialog(group = "Friction", enable = friction_method == Types.FrictionMethod.ManningFriction and use_n));
30-
31-
3218
// Steady state:
3319
parameter Boolean SteadyState=data.SteadyState "If true, starts in steady state" annotation (Dialog(group="Initialization"));
3420
parameter SI.VolumeFlowRate Vdot_0=data.Vdot_0 "Initial flow rate of the pipe" annotation (Dialog(group="Initialization"));
@@ -44,10 +30,6 @@ model Pipe "Model of a pipe"
4430
SI.VolumeFlowRate Vdot "Volume flow rate";
4531

4632
protected
47-
parameter Real n_eff = if use_n then n_manning else 1/m_manning "Effective Manning's n coefficient";
48-
parameter SI.Height p_eps = if friction_method == Types.FrictionMethod.PipeRoughness then p_eps_input
49-
elseif friction_method == Types.FrictionMethod.MoodyFriction then 3.7 * D_ * 10^(-1/(2*sqrt(f_moody)))
50-
else D_*3.0971 *exp(-0.118/n_eff) "Equivalent pipe roughness height";
5133
parameter SI.Diameter D_ = ( D_i + D_o) / 2 "Average diameter";
5234
parameter SI.Area A_i = D_i ^ 2 * C.pi / 4 "Inlet cross-sectional area";
5335
parameter SI.Area A_o = D_o ^ 2 * C.pi / 4 "Outlet cross-sectional area";
@@ -119,24 +101,8 @@ slopes (positive or negative height difference).</p>
119101
taper geometry: 0.05–0.15 for gentle cones, up to 0.6 for sharp contractions.</p>
120102
121103
<h5>Friction Specification</h5>
122-
<p>The pipe friction can be specified using one of three methods via the <code>friction_method</code> parameter:</p>
123-
<ul>
124-
<li><strong>Pipe Roughness (p_eps)</strong>: Direct specification of absolute pipe roughness height (m).
125-
Typical values: 0.0001-0.001 m for steel pipes, 0.001-0.003 m for concrete.</li>
126-
<li><strong>Moody Friction Factor (f)</strong>: Dimensionless friction factor from Moody diagram.
127-
Typical values: 0.01-0.05. Converted to equivalent roughness using fully turbulent flow approximation:
128-
p_eps = 3.7·D·10<sup>-1/(2√f)</sup></li>
129-
<li><strong>Manning Coefficient</strong>: Two notations are supported:
130-
<ul>
131-
<li><strong>Manning's M coefficient (Strickler)</strong> [m<sup>1/3</sup>/s]: M = 1/n, typical values 60-110 for steel,
132-
30-60 for rock tunnels.</li>
133-
<li><strong>Manning's n coefficient</strong> [s/m<sup>1/3</sup>]: Typical values 0.009-0.013 for smooth steel,
134-
0.012-0.017 for concrete, 0.017-0.030 for rock tunnels. Use checkbox <code>use_n</code> to enable this notation.</li>
135-
</ul>
136-
These are then converted using: p_eps = D_h·3.097·e<sup>(-0.118/n)</sup> empirically derived from the&nbsp;Karman-Prandtl equation.</li>
137-
</ul>
138-
<p>The conversions are simplified for hydropower applications assuming fully turbulent flow,
139-
so they depend only on fixed pipe dimensions and the chosen friction coefficient.</p>
104+
<p>Friction is specified via the inherited <a href=\"modelica://OpenHPL.Waterway.BaseClasses.FrictionSpec\">FrictionSpec</a>
105+
base class, which supports pipe roughness, Moody friction factor, and Manning coefficient methods.</p>
140106
141107
<h5>Initialization</h5>
142108
<p>By default, the pipe provides an initial equation for the flow rate: either <code>der(mdot) = 0</code>

OpenHPL/Waterway/SurgeTank.mo

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
within OpenHPL.Waterway;
1+
within OpenHPL.Waterway;
22
model SurgeTank "Model of the surge tank/shaft"
33
outer Data data "Using standard data set";
44
extends OpenHPL.Icons.Surge(lds=l, Lds=L);
55
extends OpenHPL.Interfaces.TwoContacts;
6+
extends Types.FrictionSpec( final D_h = D);
67

78
parameter Types.SurgeTank SurgeTankType = OpenHPL.Types.SurgeTank.STSimple "Types of surge tank"
89
annotation (Dialog(group = "Surge tank types"));
@@ -16,8 +17,6 @@ model SurgeTank "Model of the surge tank/shaft"
1617
annotation (Dialog(group = "Geometry"));
1718

1819

19-
parameter SI.Height p_eps = data.p_eps "Pipe roughness height" annotation (
20-
Dialog(group = "Geometry"));
2120
parameter SI.Diameter D_so = D "If Sharp orifice type: Diameter of sharp orifice" annotation (
2221
Dialog(group = "Geometry",enable=SurgeTankType == OpenHPL.Types.SurgeTank.STSharpOrifice));
2322
parameter SI.Diameter D_t = D "If Throttle value type: Diameter of throat" annotation (
@@ -113,9 +112,9 @@ equation
113112
F_f = Functions.DarcyFriction.Friction(v, D, l, data.rho, data.mu, p_eps) + A * phiSO * 0.5 * data.rho * abs(v) * v;
114113
F_p = (p_b - p_t) * A;
115114
if v >= 0 then
116-
phiSO = Functions.Fitting.FittingPhi(v, D, D_so, L, 90, data.rho, data.mu, data.p_eps, OpenHPL.Types.Fitting.SharpOrifice);
115+
phiSO = Functions.Fitting.FittingPhi(v, D, D_so, L, 90, data.rho, data.mu, p_eps, OpenHPL.Types.Fitting.SharpOrifice);
117116
else
118-
phiSO = Functions.Fitting.FittingPhi(v, D_so, D, L, 90, data.rho, data.mu, data.p_eps, OpenHPL.Types.Fitting.SharpOrifice);
117+
phiSO = Functions.Fitting.FittingPhi(v, D_so, D, L, 90, data.rho, data.mu, p_eps, OpenHPL.Types.Fitting.SharpOrifice);
119118
end if;
120119
elseif SurgeTankType == OpenHPL.Types.SurgeTank.STThrottleValve then
121120
if l <= L_t then
@@ -131,10 +130,10 @@ equation
131130
M = m * v;
132131
if v > 0 then
133132
F_f = Functions.DarcyFriction.Friction(Vdot/A_t, D_t, L_t, data.rho, data.mu, p_eps) + Functions.DarcyFriction.Friction(Vdot/A, D, l - L_t, data.rho, data.mu, p_eps) + A_t * phiSO * 0.5 * data.rho * abs(Vdot/A_t) * Vdot/A_t;
134-
phiSO = Functions.Fitting.FittingPhi(Vdot/A_t, D_t, D, L, 90, data.rho, data.mu, data.p_eps, OpenHPL.Types.Fitting.Square);
133+
phiSO = Functions.Fitting.FittingPhi(Vdot/A_t, D_t, D, L, 90, data.rho, data.mu, p_eps, OpenHPL.Types.Fitting.Square);
135134
elseif v < 0 then
136135
F_f = Functions.DarcyFriction.Friction(Vdot/A_t, D_t, L_t, data.rho, data.mu, p_eps) + Functions.DarcyFriction.Friction(Vdot/A, D, l - L_t, data.rho, data.mu, p_eps) + A * phiSO * 0.5 * data.rho * abs(Vdot/A) * Vdot/A;
137-
phiSO = Functions.Fitting.FittingPhi(Vdot/A, D, D_t, L, 90, data.rho, data.mu, data.p_eps, OpenHPL.Types.Fitting.Square);
136+
phiSO = Functions.Fitting.FittingPhi(Vdot/A, D, D_t, L, 90, data.rho, data.mu, p_eps, OpenHPL.Types.Fitting.Square);
138137
else
139138
F_f = 0;
140139
phiSO = 0;

0 commit comments

Comments
 (0)