- 1
%% Choose Solver, Boundary Conditions, Wave Speed method and Friction Type
- 2
% Choose solver:
- 3
% 1) 1D_SinglePhase
- 4
% 2) 1D_TwoPhase_DVCM
- 5
% 3) 1D_TwoPhase_DGCM
- 6
Solver = ’1D_TwoPhase_DGCM’;
- 7
- 8
% Choose upstream boundary condition:
- 9
% 1) Reservoir
- 10
Upstream_boundary = ’Reservoir’;
- 11
- 12
% Choose downstream boundary condition:
- 13
% 1) Valve_Instantaneous_Closure
- 14
% 2) Valve_Transient_Closure
- 15
Downstream_boundary = ’Valve_Transient_Closure’;
- 16
- 17
% Choose wave speed method: already known or need calculation:
- 18
% 1) WaveSpeed_Known
- 19
% 2) WaveSpeed_Calculate
- 20
WaveSpeed_Type = ’WaveSpeed_Calculate’;
- 21
- 22
% Choose friction type:
- 23
% 1) Prescribed_Steady_State_Friction (insert value in f_pre)
- 24
% 2) Steady_State_Friction
- 25
% 3) Quasi_Steady_Friction
- 26
% 4) Unsteady_Friction_Brunone
- 27
% 5) Unsteady_Friction_Zielke
- 28
% 6) Unsteady_Friction_VardyBrown
- 29
% 7) Unsteady_Friction_Zarzycki
- 30
Friction_Type = ’Unsteady_Friction_VardyBrown’;
- 31
- 32
%% Mesh
- 33
% Number of divisions of the pipe [−]
- 34
Reaches = 48;
- 35
% One oscillation is four times the traveling time of the pressure wave [−]
- 36
Oscillations = 20;
- 37
- 38
%% Universal Constants
- 39
% Gravitational acceleration [m/s^2]
- 40
g = 9.8;
- 41
- 42
%% Pipe Dimensions and Parameters
- 43
% Length of pipe [m]
- 44
L = 15.22;
- 45
% Diameter of pipe [m]
- 46
D = 0.02;
- 47
% Cross sectional area of pipe [m^2]
- 48
A = pi ∗ D^2/4;
- 49
% Thickness of pipe [m]
- 50
e = 0.001;
- 51
% Young’s modulus [Pa]
- 52
E = 120E9;
- 53
% Absolute roughness [m]
- 54
roughness = 0.0015E−3;
- 55
% Poisson’s ratio [−]
- 56
nu_p = 0.35;
- 57
% Angle of inclination [deg]
- 58
theta = 0;
- 59
- 60
%% Fluid Properties
- 61
% Density of water [kg/m^3]
- 62
rho = 998.2;
- 63
% Bulk modulus of water [Pa]
- 64
K = 2.2E9;
- 65
% Dynamic viscosity [kg/m∗s]
- 66
viscosity = 1.002E−3;
- 67
- 68
switch Solver
- 69
case ’1D_TwoPhase_DVCM’
- 70
% Vapour pressure in piezometric head [m]
- 71
H_vap = 0.10793;
- 72
% Barometric pressure head [m]
- 73
H_b = 101325/(rho∗g);
- 74
% Vapour pressure in gauge piezometric head [m]
- 75
H_v = H_vap − H_b;
- 76
case ’1D_TwoPhase_DGCM’
- 77
% Saturation pressure in piezometric head [m]
- 78
H_sat = 0.10793;
- 79
% Barometric pressure head [m]
- 80
H_b = 101325/(rho∗g);
- 81
% Saturation pressure in gauge piezometric head [m]
- 82
H_v = H_sat − H_b;
- 83
% Void fraction at reference pressure [−]
- 84
alpha_0 = 1e−7;
- 85
end
- 86
- 87
%% Weighting factor for DVCM and DGCM
- 88
% Weighting factor [−]
- 89
psi = 0.55;
- 90
- 91
%% Flow Inputs
- 92
% Initial flow velocity [m/s]
- 93
u_0 = 0.156e−3/A;
- 94
% Initial volumetric flow rate [m^3/s]
- 95
Q_0 = u_0∗A;
- 96
% Initial Reynolds number [−]
- 97
Re_0 = rho∗u_0∗D/viscosity;
- 98
- 99
%% Upstream reservoir / Initial head
- 100
% Height/pressure of the reservoir [m]
- 101
H_r = 46;
- 102
- 103
%% Downstream valve
- 104
% Closing time of valve [s]
- 105
t_c = 18/1000;
- 106
- 107
switch Downstream_boundary
- 108
case ’Valve_Instantaneous_Closure’
- 109
% Valve closure coefficient [−]
- 110
m = 0;
- 111
case ’Valve_Transient_Closure’
- 112
% Valve closure coefficient [−]
- 112
m = 5;
- 114
end
- 115
- 116
%% Wave speed − pure liquid
- 117
switch WaveSpeed_Type
- 118
case ’WaveSpeed_Calculate’
- 119
% Speed of the pressure wave [m/s]
- 120
a = WaveSpeed(e,D,K,rho,E,nu_p);
- 121
case ’WaveSpeed_Known’
- 122
% Speed of the pressure wave [m/s]
- 123
a = 1200;
- 124
end
- 125
- 126
%% Prescribed steady state friction coefficient (do not remove or hide)
- 127
% Prescribed steady state fricion coefficient [−]
- 128
f_pre = 0;
- 1
%% Initialize matrices to reduce calculation time
- 2
% Volumetric flow rate [m^3/s]
- 3
Q(1:n,1:n_t) = 0;
- 4
% Piezometric head [m]
- 5
H(1:n,1:n_t) = 0;
- 5
% Time [s]
- 7
t(1:n_t) = 0;
- 8
% Height from datum [m]
- 9
z(1:n) = 0;
- 10
% Volumetric flow rate acceleration [m^3/s^2]
- 11
dQ(n,n_t−2) = 0;
- 12
- 13
%% Calculating the offset of each node from the datum (reference height)
- 14
% i indicate node number [−]
- 15
for i = 1:n
- 16
% Height from datum [m]
- 17
z(i) = (i−1)∗dx∗sind(theta);
- 18
end
- 19
- 20
%% Steady State
- 21
[Q, H] = SteadyState(Q_0, H_r, rho, D, viscosity, a, A, roughness, g,...
- 22
dx, Q, H, n, theta, Friction_Type, f_pre);
- 23
- 24
%% Transient flow
- 25
% j indicate time step number [−]
- 26
for j = 2:n_t
- 27
% Time [s]
- 28
t(j) = t(j−1) + dt;
- 29
- 30
%% Interior Nodes
- 31
for i = 2:n−1
- 32
[Q(i,j), H(i,j)] = InteriorNodes_SinglePhase(a, g, A, rho, D,...
- 33
viscosity, roughness, dx, theta, Q(i−1,j−1), H(i−1,j−1),...
- 34
Q(i+1,j−1), H(i+1,j−1), Q, Re_0, i, j, dt, Friction_Type,...
- 35
Q_0, f_pre, W, dQ, n_t);
- 36
end
- 37
- 38
%% Upstream Boundary
- 39
switch Upstream_boundary
- 40
case ’Reservoir’
- 41
[Q(1,j), H(1,j)] = Reservoir_Upstream(a, g, A, rho, D, dx,...
- 42
viscosity, roughness, theta, Q(2,j−1), H(2,j−1), H_r,....
- 43
Q, Re_0, i, j, dt, Friction_Type, Q_0, f_pre, W, dQ, n_t);
- 44
end
- 45
- 46
%% Downstream Boundary
- 47
switch Downstream_boundary
- 48
case ’Valve_Instantaneous_Closure’
- 49
[Q(n,j), H(n,j)] = Valve_Closure(a, g, A, D, dx, roughness,...
- 50
rho, viscosity, t(j), t_c, m, theta, Q(n,1), H(n,1),...
- 51
Q(n−1,j−1), H(n−1,j−1), Q, Re_0, i, j, dt,...
- 52
Friction_Type, f_pre, W, dQ, n_t);
- 53
case ’Valve_Transient_Closure’
- 54
[Q(n,j), H(n,j)] = Valve_Closure(a, g, A, D, dx, roughness,...
- 55
rho, viscosity, t(j), t_c, m, theta, Q(n,1), H(n,1),...
- 56
Q(n−1,j−1), H(n−1,j−1), Q, Re_0, i, j, dt,...
- 57
Friction_Type, f_pre, W, dQ, n_t);
- 58
end
- 59
- 60
%% Calculating the change in volumetric flow rate for unsteady friction
- 61
switch Friction_Type
- 62
case ’Unsteady_Friction_Zielke’
- 63
if j<n_t
- 64
dQ(:,n_t−j+1) = Q(:,j)-Q(:,j−1);
- 62
end
- 66
case ’Unsteady_Friction_VardyBrown’
- 67
if j<n_t
- 68
dQ(:,n_t−j+1) = Q(:,j)-Q(:,j−1);
- 69
end
- 70
case ’Unsteady_Friction_Zarzycki’
- 71
if j<n_t
- 72
dQ(:,n_t−j+1) = Q(:,j)-Q(:,j−1);
- 73
end
- 74
end
- 75
end
- 1
%% Initialize matrices to reduce calculation time
- 2
% Volumetric flow rate [m^3/s]
- 3
Q_u(1:n,1:n_t) = 0;
- 4
% Volumetric flow rate [m^3/s]
- 5
Q(1:n,1:n_t) = 0;
- 6
% Piezometric head [m]
- 7
H(1:n,1:n_t) = 0;
- 8
% Time [s]
- 9
t(1:n_t) = 0;
- 10
% Height from datum [m]
- 11
z(1:n) = 0;
- 12
% Volumetric flow rate acceleration [m^3/s^2]
- 13
dQ(n,n_t−2) = 0;
- 14
% Vapour cavity volume [m^3]
- 15
V_cav(1:n,1:n_t) = 0;
- 16
- 17
%% Calculating the offset of each node from the datum (reference height)
- 18
% i indicate node number [−]
- 19
for i = 1:n
- 20
% Height from datum [m]
- 21
z(i) = (i−1)∗dx∗sind(theta);
- 22
end
- 23
- 24
%% Steady State
- 25
[Q, H] = SteadyState(Q_0, H_r, rho, D, viscosity, a, A, roughness, g,...
- 26
dx, Q, H, n, theta, Friction_Type, f_pre);
- 27
Q_u(:,1) = Q(:,1);
- 28
- 29
%% Transient
- 30
% j indicate time step number [−]
- 31
for j = 2:n_t
- 32
% Time [s]
- 33
t(j) = t(j−1) + dt;
- 34
- 35
%% Interior Nodes
- 36
% The different formulaton for j = 2 and j > 2 is because Equation 7.9
- 37
% requires a vapour cavity volume from two time steps back. However as
- 38
% there is no j = −1, the steady state values (j = 1) will be used for
- 39
% V_cav, Q, and Q_u in Equation 7.9.
- 40
if j == 2
- 41
for i = 2:n−1
- 42
[Q_u(i,j), Q(i,j), H(i,j), V_cav(i,j)] = InteriorNodes_DVCM(...
- 43
a, g, A, rho, D, viscosity, roughness, dx, theta,...
- 44
Q(i−1,j−1), H(i−1,j−1), Q_u(i+1,j−1), H(i+1,j−1), Q,...
- 45
Q_u, Re_0, i, j, dt, Friction_Type, Q_0, f_pre, W, dQ,...
- 46
n_t, V_cav(i,j−1), V_cav(i,j−1), Q(i,j−1), Q_u(i,j−1),...
- 47
psi, z(i), H_v);
- 48
end
- 49
else
- 50
for i = 2:n−1
- 51
[Q_u(i,j), Q(i,j), H(i,j), V_cav(i,j)] = InteriorNodes_DVCM(...
- 52
a, g, A, rho, D, viscosity, roughness, dx, theta,...
- 53
Q(i−1,j−1), H(i−1,j−1), Q_u(i+1,j−1), H(i+1,j−1), Q,...
- 54
Q_u, Re_0, i, j, dt, Friction_Type, Q_0, f_pre, W, dQ,...
- 55
n_t, V_cav(i,j−1), V_cav(i,j−2), Q(i,j−2), Q_u(i,j−2),...
- 56
psi, z(i), H_v);
- 57
end
- 58
end
- 59
- 60
%% Upstream Boundary
- 61
switch Upstream_boundary
- 62
case ’Reservoir’
- 63
[Q(1,j), H(1,j)] = Reservoir_Upstream(a, g, A, rho, D, dx,...
- 64
viscosity, roughness, theta, Q_u(2,j−1), H(2,j−1), H_r,...
- 65
Q_u, Re_0, 1, j, dt, Friction_Type, Q_0, f_pre, W, dQ, n_t);
- 66
end
- 67
Q_u(1,j) = Q(1,j);
- 68
- 69
%% Downstream Boundary
- 70
% Again, because there is no j = −1, the steady state values are used
- 71
% for V_cav, Q, and Q_u in Equation 7.9.
- 72
if j == 2
- 73
switch Downstream_boundary
- 74
case ’Valve_Instantaneous_Closure’
- 75
[Q_u(n,j), Q(n,j), H(n,j), V_cav(n,j)] = Valve_Closure_DVCM(...
- 76
a, g, A, D, dx, roughness, rho, viscosity,...
- 77
t(j), t_c, m, theta, Q(n,1), H(n,1), Q(n−1,j−1),...
- 78
H(n−1,j−1), Q, Re_0, n, j, dt, Friction_Type, f_pre,...
- 79
W, dQ, n_t, V_cav(n,j−1), V_cav(n,j−1), Q(n,j−1),...
- 80
Q_u(n,j−1), psi, z(n), H_v);
- 81
case ’Valve_Transient_Closure’
- 82
[Q_u(n,j), Q(n,j), H(n,j), V_cav(n,j)] = Valve_Closure_DVCM(...
- 83
a, g, A, D, dx, roughness, rho, viscosity,...
- 84
t(j), t_c, m, theta, Q(n,1), H(n,1), Q(n−1,j−1),...
- 85
H(n−1,j−1), Q, Re_0, n, j, dt, Friction_Type, f_pre,...
- 86
W, dQ, n_t, V_cav(n,j−1), V_cav(n,j−1), Q(n,j−1),...
- 87
Q_u(n,j−1), psi, z(n), H_v);
- 88
end
- 89
else
- 90
switch Downstream_boundary
- 91
case ’Valve_Instantaneous_Closure’
- 92
[Q_u(n,j), Q(n,j), H(n,j), V_cav(n,j)] = Valve_Closure_DVCM(...
- 93
a, g, A, D, dx, roughness, rho, viscosity,...
- 94
t(j), t_c, m, theta, Q(n,1), H(n,1), Q(n−1,j−1),...
- 95
H(n−1,j−1), Q, Re_0, n, j, dt, Friction_Type, f_pre,...
- 96
W, dQ, n_t, V_cav(n,j−1), V_cav(n,j−2), Q(n,j−2),...
- 97
Q_u(n,j−2), psi, z(n), H_v);
- 98
case ’Valve_Transient_Closure’
- 99
[Q_u(n,j), Q(n,j), H(n,j), V_cav(n,j)] = Valve_Closure_DVCM(...
- 100
a, g, A, D, dx, roughness, rho, viscosity,...
- 101
t(j), t_c, m, theta, Q(n,1), H(n,1), Q(n−1,j−1),...
- 102
H(n−1,j−1), Q, Re_0, n, j, dt, Friction_Type, f_pre,...
- 103
W, dQ, n_t, V_cav(n,j−1), V_cav(n,j−2), Q(n,j−2),...
- 104
Q_u(n,j−2), psi, z(n), H_v);
- 105
end
- 106
end
- 107
- 108
%% Calculating the change in volumetric flow rate for unsteady friction
- 109
switch Friction_Type
- 110
case ’Unsteady_Friction_Zielke’
- 111
if j<n_t
- 112
dQ(:,n_t−j+1) = Q(:,j)-Q(:,j−1);
- 113
end
- 114
case ’Unsteady_Friction_VardyBrown’
- 115
if j<n_t
- 116
dQ(:,n_t−j+1) = Q(:,j)-Q(:,j−1);
- 117
end
- 118
case ’Unsteady_Friction_Zarzycki’
- 119
if j<n_t
- 120
dQ(:,n_t−j+1) = Q(:,j)-Q(:,j−1);
- 121
end
- 122
end
- 123
end
- 124
- 125
%% Calculating the void fraction − used to warn for void fraction >10%
- 126
V_reach_boundary = dx/2 ∗ A;
- 127
V_reach_interior = dx ∗ A;
- 128
- 129
alpha(1,:) = V_cav(1,:)/V_reach_boundary;
- 130
alpha(2:n−1,:) = V_cav(2:end−1,:)/V_reach_interior;
- 131
alpha(n,:) = V_cav(end,:)/V_reach_boundary;
- 132
- 133
if max(max(alpha)) > 0.1
- 134
fprintf(2,’Warning: A void fraction above 0.1\n’)
- 135
fprintf(2,’has been calculated, and the solution\n’)
- 136
fprintf(2,’might not be accurate. Try using \n’)
- 137
fprintf(2,’DGCM instead, as it might produce\n’)
- 138
fprintf(2,’better results.\n’)
- 139
disp(’-------------------------------------’)
- 140
end
- 1
%% Initialize matrices to reduce calculation time
- 2
% Volumetric flow rate [m^3/s]
- 3
Q_u(1:n,1:n_t) = 0;
- 4
% Volumetric flow rate [m^3/s]
- 5
Q(1:n,1:n_t) = 0;
- 6
% Piezometric head [m]
- 7
H(1:n,1:n_t) = 0;
- 8
% Time [s]
- 9
t(1:n_t) = 0;
- 10
% Height from datum [m]
- 11
z(1:n) = 0;
- 12
% Volumetric flow rate acceleration [m^3/s^2]
- 13
dQ(n,n_t−2) = 0;
- 14
% Gas cavity volume [m^3]
- 15
V_g(1:n,1:n_t) = 0;
- 16
- 17
%% Calculating the offset of each node from the datum (reference height)
- 18
for i = 1:n
- 19
% Height from datum [m]
- 20
z(i) = (i−1)∗dx∗sind(theta);
- 21
end
- 22
- 23
%% Calculating the pipe volume associated to each node
- 24
% Volume associated to the node at the upstream boundary [m^3]
- 25
V_total(1,1) = A∗dx/2;
- 26
% Volume associated to the individual interior nodes [m^3]
- 27
V_total(2:n−1,1) = A∗dx;
- 28
% Volume associated to the node at the downstream boundary [m^3]
- 29
V_total(n,1) = A∗dx/2;
- 30
- 31
%% Steady State
- 32
[Q, H, V_g] = SteadyState_DGCM(Q_0, H_r, rho, D, viscosity, a, A,...
- 33
roughness, g, dx, Q, H, n, theta, Friction_Type, f_pre, alpha_0,...
- 34
V_total, V_g, z, H_v);
- 35
Q_u(:,1) = Q(:,1);
- 36
- 37
%% Transient
- 38
% j indicate time step number [−]
- 39
for j = 2:n_t
- 40
% Time [s]
- 41
t(j) = t(j−1) + dt;
- 42
- 43
%% Interior Nodes
- 44
% The different formulaton for j = 2 and j > 2 is because Equation 7.9
- 45
% requires a vapour cavity volume from two time steps back. However as
- 46
% there is no j = −1, the steady state values (j = 1) will be used for
- 47
% V_g, Q, and Q_u in Equation 7.9.
- 48
if j == 2
- 49
for i = 2:n−1
- 50
[Q_u(i,j), Q(i,j), H(i,j), V_g(i,j)] = InteriorNodes_DGCM(...
- 51
a, g, A, rho, D, viscosity, roughness, dx, theta,...
- 52
Q(i−1,j−1), H(i−1,j−1), Q_u(i+1,j−1), H(i+1,j−1), Q,...
- 53
Q_u, Re_0, i, j, dt, Friction_Type, Q_0, f_pre, W, dQ,...
- 54
n_t, H(i,1), alpha_0, V_total(i,1), V_g(i,j−1), Q(i,j−1),...
- 55
Q_u(i,j−1), psi, z(i), H_v);
- 56
end
- 57
else
- 58
for i = 2:n−1
- 59
[Q_u(i,j), Q(i,j), H(i,j), V_g(i,j)] = InteriorNodes_DGCM(...
- 60
a, g, A, rho, D, viscosity, roughness, dx, theta,...
- 61
Q(i−1,j−1), H(i−1,j−1), Q_u(i+1,j−1), H(i+1,j−1), Q,...
- 62
Q_u, Re_0, i, j, dt, Friction_Type, Q_0, f_pre, W, dQ,...
- 63
n_t, H(i,1), alpha_0, V_total(i,1), V_g(i,j−2), Q(i,j−2),...
- 64
Q_u(i,j−2), psi, z(i), H_v);
- 65
end
- 66
end
- 67
- 68
%% Upstream Boundary
- 69
switch Upstream_boundary
- 70
case ’Reservoir’
- 71
[Q_u(1,j), Q(1,j), H(1,j), V_g(1,j)] = Reservoir_Upstream_DGCM(...
- 72
a, g, A, rho, D, dx, viscosity, roughness, theta,...
- 73
Q_u(2,j−1), H(2,j−1), H_r, Q_u, Re_0, 1, j, dt,...
- 74
Friction_Type, Q_0, f_pre, W, dQ, n_t, H(1,1), alpha_0,...
- 75
V_total(1,1), z(1), H_v);
- 76
end
- 77
- 78
%% Downstream Boundary
- 79
% Again, because there is no j = −1, the steady state values are used
- 80
% for V_g, Q, and Q_u in Equation 7.9.
- 81
if j == 2
- 82
switch Downstream_boundary
- 83
case ’Valve_Instantaneous_Closure’
- 84
[Q_u(n,j), Q(n,j), H(n,j), V_g(n,j)] = Valve_Closure_DGCM(...
- 85
a, g, A, D, dx, roughness, rho, viscosity,...
- 86
t(j), t_c, m, theta, Q(n,1), H(n,1), Q(n−1,j−1),...
- 87
H(n−1,j−1), Q, Re_0, n, j, dt, Friction_Type, f_pre,...
- 88
W, dQ, n_t, alpha_0, V_total(n,1), V_g(n,j−1),...
- 89
Q(n,j−1), Q_u(n,j−1), psi, z(n), H_v);
- 90
case ’Valve_Transient_Closure’
- 91
[Q_u(n,j), Q(n,j), H(n,j), V_g(n,j)] = Valve_Closure_DGCM(...
- 92
a, g, A, D, dx, roughness, rho, viscosity,...
- 93
t(j), t_c, m, theta, Q(n,1), H(n,1), Q(n−1,j−1),...
- 94
H(n−1,j−1), Q, Re_0, n, j, dt, Friction_Type, f_pre,...
- 95
W, dQ, n_t, alpha_0, V_total(n,1), V_g(n,j−1),...
- 96
Q(n,j−1), Q_u(n,j−1), psi, z(n), H_v);
- 97
end
- 98
else
- 99
switch Downstream_boundary
- 100
case ’Valve_Instantaneous_Closure’
- 101
[Q_u(n,j), Q(n,j), H(n,j), V_g(n,j)] = Valve_Closure_DGCM(...
- 102
a, g, A, D, dx, roughness, rho, viscosity,...
- 103
t(j), t_c, m, theta, Q(n,1), H(n,1), Q(n−1,j−1),...
- 104
H(n−1,j−1), Q, Re_0, n, j, dt, Friction_Type, f_pre,...
- 105
W, dQ, n_t, alpha_0, V_total(n,1), V_g(n,j−2),...
- 106
Q(n,j−2), Q_u(n,j−2), psi, z(n), H_v);
- 107
case ’Valve_Transient_Closure’
- 108
[Q_u(n,j), Q(n,j), H(n,j), V_g(n,j)] = Valve_Closure_DGCM(...
- 109
a, g, A, D, dx, roughness, rho, viscosity,...
- 110
t(j), t_c, m, theta, Q(n,1), H(n,1), Q(n−1,j−1),...
- 111
H(n−1,j−1), Q, Re_0, n, j, dt, Friction_Type, f_pre,...
- 112
W, dQ, n_t, alpha_0, V_total(n,1), V_g(n,j−2),...
- 113
Q(n,j−2), Q_u(n,j−2), psi, z(n), H_v);
- 114
end
- 115
end
- 116
- 117
%% Calculating the change in volumetric flow rate for unsteady friction
- 118
switch Friction_Type
- 119
case ’Unsteady_Friction_Zielke’
- 120
if j<n_t
- 121
dQ(:,n_t−j+1) = Q(:,j)-Q(:,j−1);
- 122
end
- 123
case ’Unsteady_Friction_VardyBrown’
- 124
if j<n_t
- 125
dQ(:,n_t−j+1) = Q(:,j)-Q(:,j−1);
- 126
end
- 127
case ’Unsteady_Friction_Zarzycki’
- 128
if j<n_t
- 129
dQ(:,n_t−j+1) = Q(:,j)-Q(:,j−1);
- 130
end
- 131
end
- 132
end
- 1
function [Q_u_P, Q_P, H_P, V_cav_P] = InteriorNodes_DVCM(a, g, A, rho,...
- 2
D, viscosity, roughness, dx, theta, Q_A, H_A, Q_u_B, H_B, Q, Q_u,...
- 3
Re_0, i, j, dt, Friction_Type, Q_0, f_pre, W, dQ, n_t, V_cav_t,...
- 4
V_cav_P0, Q_P0, Q_u_P0, psi, z_P, H_v)
- 5
%% Interior nodes
- 6
% Pipe constant [s/m^2]
- 7
B = PipeConst(a, g, A);
- 8
% Positive characteristics equation [m]
- 9
C_p = Characteristic_Plus(a, g, A, D, dx, roughness, rho, viscosity,...
- 10
theta, Q_A, H_A, Q, Re_0, i, j, dt, Friction_Type, Q_0, f_pre, W,...
- 11
dQ, n_t);
- 12
% Negative characteristics equation [m]
- 13
C_m = Characteristic_Minus(a, g, A, D, dx, roughness, rho, viscosity,...
- 14
theta, Q_u_B, H_B, Q_u, Re_0, i, j, dt, Friction_Type, Q_0, f_pre,...
- 15
W, dQ, n_t);
- 16
- 17
% Checking if a vapour cavity was present at the previous time step.
- 18
if V_cav_t > 0
- 19
%% Vapour cavity was present at the previous time step.
- 20
% Piezometric head [m]
- 21
H_P = z_P + H_v;
- 22
% Volumetric flow rate [m^3/s]
- 23
Q_u_P = (C_p − H_P)/B;
- 24
% Volumetric flow rate [m^3/s]
- 25
Q_P = (H_P − C_m)/B;
- 26
% Vapour cavity volume [m^3]
- 27
V_cav_P = V_cav_P0 + 2∗dt∗(psi∗(Q_P − Q_u_P) + (1 − psi)∗(Q_P0 − Q_u_P0));
- 28
- 29
% Checking if the vapour cavity disappears.
- 30
if V_cav_P <= 0
- 31
%% Vapour cavity disappears because of a rise in head.
- 32
% Vapour cavity volume [m^3]
- 33
V_cav_P = 0;
- 34
% Piezometric head [m]
- 35
H_P = (C_p + C_m)/2;
- 36
- 37
if H_P < z_P + H_v
- 38
% Piezometric head [m]
- 39
H_P = z_P + H_v;
- 40
end
- 41
- 42
% Volumetric flow rate [m^3/s]
- 43
Q_u_P = (C_p − H_P)/B;
- 44
% Volumetric flow rate [m^3/s]
- 45
Q_P = Q_u_P;
- 46
- 47
end
- 48
else
- 49
%% No vapour cavity was present in the previous time step.
- 50
% Piezometric head [m]
- 51
H_P = (C_p + C_m)/2;
- 52
- 53
% Checking if the head falls below the level where vapour cavities are created.
- 54
if H_P <= z_P + H_v
- 55
%% Head fell below vapourization level.
- 56
% Piezometric head [m]
- 57
H_P = z_P + H_v;
- 58
% Volumetric flow rate [m^3/s]
- 59
Q_u_P = (C_p − H_P)/B;
- 60
% Volumetric flow rate [m^3/s]
- 61
Q_P = (H_P − C_m)/B;
- 62
% Vapour cavity volume [m^3]
- 63
V_cav_P = V_cav_P0 + 2∗dt∗(psi∗(Q_P − Q_u_P) + (1 − psi)∗(Q_P0 − Q_u_P0));
- 64
- 65
% Checking if a vapour cavity is created.
- 66
if V_cav_P <= 0
- 67
%% No vapour cavity is created.
- 68
% Vapour cavity volume [m^3]
- 69
V_cav_P = 0;
- 70
% Piezometric head [m]
- 71
H_P = (C_p + C_m)/2;
- 72
- 73
if H_P < z_P + H_v
- 74
% Piezometric head [m]
- 75
H_P = z_P + H_v;
- 76
end
- 77
- 78
% Volumetric flow rate [m^3/s]
- 79
Q_u_P = (C_p − H_P)/B;
- 80
% Volumetric flow rate [m^3/s]
- 81
Q_P = Q_u_P;
- 82
- 83
end
- 84
else
- 85
%% Head is above vapourization level.
- 86
% Vapour cavity volume [m^3]
- 87
V_cav_P = 0;
- 88
% Volumetric flow rate [m^3/s]
- 89
Q_u_P = (C_p − H_P)/B;
- 90
% Volumetric flow rate [m^3/s]
- 91
Q_P = Q_u_P;
- 92
end
- 93
end
- 94
- 95
end
- 1
function [Q_u_P, Q_P, H_P, V_g_P] = InteriorNodes_DGCM(a, g, A, rho, D,...
- 2
viscosity, roughness, dx, theta, Q_A, H_A, Q_u_B, H_B, Q, Q_u, Re_0,...
- 3
i, j, dt, Friction_Type, Q_0, f_pre, W, dQ, n_t, H_0, alpha_0,...
- 4
V_total, V_g_P0, Q_P0, Q_u_P0, psi, z_P, H_v)
- 5
%% Interior nodes
- 6
% Pipe constant [s/m^2]
- 7
B = PipeConst(a, g, A);
- 8
% Positive characteristics equation [m]
- 9
C_p = Characteristic_Plus(a, g, A, D, dx, roughness, rho, viscosity,...
- 10
theta, Q_A, H_A, Q, Re_0, i, j, dt, Friction_Type, Q_0, f_pre, W,...
- 11
dQ, n_t);
- 12
% Negative characteristics equation [m]
- 13
C_m = Characteristic_Minus(a, g, A, D, dx, roughness, rho, viscosity,...
- 14
theta, Q_u_B, H_B, Q_u, Re_0, i, j, dt, Friction_Type, Q_0, f_pre, W,...
- 15
dQ, n_t);
- 16
- 17
%% Calculation of head − Fluid Transients in Systems
- 18
% Pressure at steady state [Pa]
- 19
P_0 = rho∗g∗(H_0 − z_P − H_v);
- 20
% Constant [m^4]
- 21
C_3 = P_0∗alpha_0∗V_total/(rho∗g);
- 22
% Constant [−]
- 23
B_2 = 0.5/2;
- 24
% Constant [m^2]
- 25
C_4 = B_2∗B∗C_3/(psi∗dt);
- 26
% Constant [m^3/s]
- 27
B_v = (V_g_P0/(2∗dt) + (1 − psi)∗(Q_P0 − Q_u_P0))/psi;
- 28
- 29
if B_v <= 0
- 30
% Constant [m^3/s]
- 31
B_v = 0;
- 32
end
- 33
- 34
% Constant [m/s]
- 35
B_1 = -B_2∗(C_m + C_p) + B_2∗B∗B_v + (z_P + H_v)/2;
- 36
- 37
if B_1 == 0
- 38
% Piezometric head [m]
- 39
H_P = sqrt(C_4) + z_P + H_v;
- 40
else
- 41
% Constant [−]
- 42
B_B = C_4/B_1^2;
- 43
- 44
if B_1 < 0 && B_B > 0.001
- 45
% Piezometric head [m]
- 46
H_P = -B_1∗(1 + sqrt(1 + B_B)) + z_P + H_v;
- 47
elseif B_1 > 0 && B_B > 0.001
- 48
% Piezometric head [m]
- 49
H_P = -B_1∗(1 − sqrt(1 + B_B)) + z_P + H_v;
- 50
elseif B_1 < 0 && B_B < 0.001
- 51
% Piezometric head [m]
- 52
H_P = −2∗B_1 − C_4/(2∗B_1) + z_P + H_v;
- 53
elseif B_1 > 0 && B_B < 0.001
- 54
% Piezometric head [m]
- 55
H_P = C_4/(2∗B_1) + z_P + H_v;
- 56
end
- 57
end
- 58
- 59
if H_P < z_P + H_v
- 60
% Piezometric head [m]
- 61
H_P = z_P + H_v;
- 62
end
- 63
- 64
%% Calculation of flows and vapour sizes
- 65
% Volumetric flow rate [m^3/s]
- 66
Q_u_P = (C_p − H_P)/B;
- 67
% Volumetric flow rate [m^3/s]
- 68
Q_P = (H_P − C_m)/B;
- 69
% Gas cavity volume [m^3]
- 70
V_g_P = V_g_P0 + (psi∗(Q_P − Q_u_P) + (1−psi)∗(Q_P0 − Q_u_P0))∗2∗dt;
- 71
- 72
if V_g_P < 0
- 73
% Gas cavity volume [m^3]
- 74
V_g_P = C_3/(H_P − z_P − H_v);
- 75
end
- 76
- 77
end
- 1
function [Q_u_P, Q_P, H_P, V_cav_P] = Valve_Closure_DVCM(a, g, A, D, dx,...
- 2
roughness, rho, viscosity, t, t_c, m, theta, Q_0, H_0, Q_A, H_A, Q,...
- 3
Re_0, i, j, dt, Friction_Type, f_pre, W, dQ, n_t, V_cav_t, V_cav_P0,...
- 4
Q_P0, Q_u_P0, psi, z_P, H_v)
- 5
%% Calculating the dimensionless closure time for the valve
- 6
if t < t_c
- 7
% Dimensionless valve closure time [−]
- 8
tau_v = 1 − (t/t_c)^m;
- 9
else
- 10
% Dimensionless valve closure time [−]
- 11
tau_v = 0;
- 12
end
- 13
- 14
%% Calculating the volumetric flow rate at the valve
- 15
% Pipe constant [s/m^2]
- 16
B = PipeConst(a, g, A);
- 17
% Positive characteristics equation [m]
- 18
C_p = Characteristic_Plus(a, g, A, D, dx, roughness, rho, viscosity,...
- 19
theta, Q_A, H_A, Q, Re_0, i, j, dt, Friction_Type, Q_0, f_pre, W,...
- 20
dQ, n_t);
- 21
% Variable [m^5/s^2]
- 22
C_v = (Q_0∗tau_v)^2/(2∗H_0);
- 23
% Volumetric flow rate [m^3/s]
- 24
Q_P = − B∗C_v + sqrt((B∗C_v)^2 + 2∗C_v∗C_p);
- 25
- 26
%% Calculation of the head
- 27
% Checking if a vapour cavity was present at the previous time step.
- 28
if V_cav_t > 0
- 29
%% Vapour cavity was present at the previous time step.
- 30
% Piezometric head [m]
- 31
H_P = z_P + H_v;
- 32
% Volumetric flow rate [m^3/s]
- 33
Q_u_P = (C_p − H_P)/B;
- 34
% Vapour cavity volume [m^3]
- 35
V_cav_P = V_cav_P0 + 2∗dt∗(psi∗(Q_P − Q_u_P) + (1 − psi)∗(Q_P0 − Q_u_P0));
- 36
- 37
% Checking if the vapour cavity disappears.
- 38
if V_cav_P <= 0
- 39
%% Vapour cavity disappears because of a rise in head
- 40
% Vapour cavity volume [m^3]
- 41
V_cav_P = 0;
- 42
% Volumetric flow rate [m^3/s]
- 43
Q_u_P = Q_P;
- 44
% Piezometric head [m]
- 45
H_P = C_p − B∗Q_P;
- 46
- 47
if H_P < z_P + H_v
- 48
% Piezometric head [m]
- 49
H_P = z_P + H_v;
- 50
end
- 51
- 52
end
- 53
else
- 54
%% No vapour cavity was present in the previous time step
- 55
% Volumetric flow rate [m^3/s]
- 56
Q_u_P = Q_P;
- 57
% Piezometric head [m]
- 58
H_P = C_p − B∗Q_u_P;
- 59
- 60
% Checking if the head falls below the level where vapour cavities are created.
- 61
if H_P <= z_P + H_v
- 62
%% Head fell below vapourization level.
- 63
% Piezometric head [m]
- 64
H_P = z_P + H_v;
- 65
% Volumetric flow rate [m^3/s]
- 66
Q_u_P = (C_p − H_P)/B;
- 67
% Vapour cavity volume [m^3]
- 68
V_cav_P = V_cav_P0 + 2∗dt∗(psi∗(Q_P − Q_u_P) + (1 − psi)∗(Q_P0 − Q_u_P0));
- 69
- 70
% Checking if a vapour cavity is created.
- 71
if V_cav_P <= 0
- 72
%% No vapour cavity is created
- 73
% Vapour cavity volume [m^3]
- 74
V_cav_P = 0;
- 75
% Piezometric head [m]
- 76
H_P = C_p − B∗Q_P;
- 77
- 78
if H_P < z_P + H_v
- 79
% Piezometric head [m]
- 80
H_P = z_P + H_v;
- 81
end
- 82
- 86
% Volumetric flow rate [m^3/s]
- 84
Q_u_P = Q_P;
- 85
end
- 86
else
- 87
%% Head is above vapourization level
- 88
% Vapour cavity volume [m^3]
- 89
V_cav_P = 0;
- 90
end
- 91
end
- 92
- 93
end
- 1
function [Q_u_P, Q_P, H_P, V_g_P] = Valve_Closure_DGCM(a, g, A, D, dx,...
- 2
roughness, rho, viscosity, t, t_c, m, theta, Q_0, H_0, Q_A, H_A, Q,...
- 3
Re_0, n, j, dt, Friction_Type, f_pre, W, dQ, n_t, alpha_0, V_total,...
- 4
V_g_P0, Q_P0, Q_u_P0, psi, z_P, H_v)
- 5
%% Calculating the dimensionless closure time for the valve
- 6
if t < t_c
- 7
% Dimensionless valve closure time [−]
- 8
tau = 1 − (t/t_c)^m;
- 9
else
- 10
% Dimensionless valve closure time [−]
- 11
tau = 0;
- 12
end
- 13
- 14
%% Calculating the volumetric flow rate at the valve
- 15
% Pipe constant [s/m^2]
- 16
B = PipeConst(a, g, A);
- 17
% Positive characteristics equation [m]
- 18
C_p = Characteristic_Plus(a, g, A, D, dx, roughness, rho, viscosity,...
- 19
theta, Q_A, H_A, Q, Re_0, n, j, dt, Friction_Type, Q_0, f_pre, W,...
- 20
dQ, n_t);
- 21
% Variable [m^5/s^2]
- 22
C_v = (Q_0∗tau)^2/(2∗H_0);
- 23
% Volumetric flow rate [m^3/s]
- 24
Q_P = − B∗C_v + sqrt((B∗C_v)^2 + 2∗C_v∗C_p);
- 25
- 26
%% Calculation of the head
- 27
% Pressure at steady state [Pa]
- 28
P_0 = rho∗g∗(H_0 − z_P − H_v);
- 29
% Constant [m^4]
- 30
C_3 = P_0∗alpha_0∗V_total/(rho∗g);
- 31
% Constant [−]
- 32
B_2 = 1/2;
- 33
% Constant [m^2]
- 34
C_4 = B_2∗B∗C_3/(psi∗dt);
- 35
% Constant [m^3/s]
- 36
B_v = (V_g_P0/(2∗dt) + (1 − psi)∗(Q_P0 − Q_u_P0))/psi;
- 37
- 38
if B_v <= 0
- 39
% Constant [m^3/s]
- 40
B_v = 0;
- 41
end
- 42
- 43
% Constant [m/s]
- 44
B_1 = -B_2∗(C_p − B∗Q_P) + B_2∗B∗B_v + (z_P + H_v)/2;
- 45
- 46
if B_1 == 0
- 47
% Piezometric head [m]
- 48
H_P = sqrt(C_4) + z_P + H_v;
- 49
else
- 50
% Constant [−]
- 51
B_B = C_4/B_1^2;
- 52
if B_1 < 0 && B_B >= 0.001
- 53
% Piezometric head [m]
- 54
H_P = -B_1∗(1 + sqrt(1 + B_B)) + z_P + H_v;
- 55
elseif B_1 > 0 && B_B >= 0.001
- 56
% Piezometric head [m]
- 57
H_P = -B_1∗(1 − sqrt(1 + B_B)) + z_P + H_v;
- 58
elseif B_1 < 0 && B_B < 0.001
- 59
% Piezometric head [m]
- 60
H_P = −-2∗B_1 − C_4/(2∗B_1) + z_P + H_v;
- 61
elseif B_1 > 0 && B_B < 0.001
- 62
% Piezometric head [m]
- 63
H_P = C_4/(2∗B_1) + z_P + H_v;
- 64
end
- 65
end
- 66
- 67
if H_P < z_P + H_v
- 68
% Piezometric head [m]
- 69
H_P = z_P + H_v;
- 70
end
- 71
- 72
%% Calculation of flows and vapour sizes
- 73
% Volumetric flow rate [m^3/s]
- 74
Q_u_P = (C_p − H_P)/B;
- 75
% Gas cavity volume [m^3]
- 76
V_g_P = V_g_P0 + (psi∗(Q_P − Q_u_P) + (1−psi)∗(Q_P0 − Q_u_P0))∗2∗dt;
- 77
- 78
if V_g_P < 0
- 79
% Gas cavity volume [m^3]
- 80
V_g_P = C_3/(H_P − z_P − H_v);
- 81
end
- 82
- 83
end
- 1
function [J] = FrictionTerm(Friction_Type, D, roughness, rho, Re_0, Q_0,...
- 2
Q_point, Q, viscosity, A, i, j, dx, dt, Charact_Line, g, a, f_pre,...
- 3
W, dQ, n_t)
- 4
% The friction term is comprised of three parts, steady state friction ,J_s
- 5
% (only used by "Prescribed_Steady_State_Friction" and
- 6
% "Steady_State_Friction"), quasi-steady friction, J_q, and unsteady
- 7
% friction, J_u (for the unsteady friction models). Theses three are
- 8
% summarized after the calculation of each part.
- 9
switch Friction_Type
- 10
case ’Prescribed_Steady_State_Friction’
- 11
% Resistance coefficient [s^2/m^5]
- 12
R = f_pre∗dx/(2∗g∗D∗A^2);
- 13
J_s = R∗Q_point∗abs(Q_point);
- 14
J_q = 0;
- 15
J_u = 0;
- 16
case ’Steady_State_Friction’
- 17
% Darcy friction factor, determined for either laminar flow or via
- 18
% the Colebrook-White equation for turbulent flow [−]
- 19
f_s = FricFac(D, roughness, rho, Q_0, viscosity, A);
- 20
% Resistance coefficient [s^2/m^5]
- 21
R = f_s∗dx/(2∗g∗D∗A^2);
- 22
J_s = R∗Q_point∗abs(Q_point);
- 23
J_q = 0;
- 24
J_u = 0;
- 25
case ’Quasi_Steady_Friction’
- 26
% Darcy friction factor, determined for either laminar flow or via
- 27
% the Colebrook-White equation for turbulent flow [−]
- 28
f_q = FricFac(D, roughness, rho, Q_point, viscosity, A);
- 29
% Resistance coefficient [s^2/m^5]
- 30
R = f_q∗dx/(2∗g∗D∗A^2);
- 31
J_s = 0;
- 32
J_q = R∗Q_point∗abs(Q_point);
- 33
J_u = 0;
- 34
case ’Unsteady_Friction_Brunone’
- 35
% Darcy friction factor, determined for either laminar flow or via
- 36
% the Colebrook-White equation for turbulent flow [−]
- 37
f_q = FricFac(D, roughness, rho, Q_point, viscosity, A);
- 38
% Resistance coefficient [s^2/m^5]
- 39
R = f_q∗dx/(2∗g∗D∗A^2);
- 40
J_s = 0;
- 41
J_q = R∗Q_point∗abs(Q_point);
- 42
switch Charact_Line
- 43
case ’Plus’
- 44
J_u = BrunoneFricp(Q, Re_0, D, j, i, a, dt, dx,g,A);
- 45
case ’Minus’
- 46
J_u = BrunoneFricm(Q, Re_0, D, j, i, a, dt, dx,g,A);
- 47
end
- 48
case ’Unsteady_Friction_Zielke’
- 49
% Darcy friction factor, determined for either laminar flow or via
- 50
% the Colebrook-White equation for turbulent flow [−]
- 51
f_q = FricFac(D, roughness, rho, Q_point, viscosity, A);
- 52
% Resistance coefficient [s^2/m^5]
- 53
R = f_q∗dx/(2∗g∗D∗A^2);
- 54
J_s = 0;
- 55
J_q = R∗Q_point∗abs(Q_point);
- 56
switch Charact_Line
- 57
case ’Plus’
- 58
J_u = CBFricp(dt, j, i, D, rho, viscosity, g,A,a,W,dQ,n_t);
- 59
case ’Minus’
- 60
J_u = CBFricm(dt, j, i, D, rho, viscosity, g,A,a,W,dQ,n_t);
- 61
end
- 62
case ’Unsteady_Friction_VardyBrown’
- 63
% Darcy friction factor, determined for either laminar flow or via
- 64
% the Colebrook-White equation for turbulent flow [−]
- 65
f_q = FricFac(D, roughness, rho, Q_point, viscosity, A);
- 66
% Resistance coefficient [s^2/m^5]
- 67
R = f_q∗dx/(2∗g∗D∗A^2);
- 68
J_s = 0;
- 69
J_q = R∗Q_point∗abs(Q_point);
- 70
switch Charact_Line
- 71
case ’Plus’
- 72
J_u = CBFricp(dt, j, i, D, rho, viscosity, g,A,a,W,dQ,n_t);
- 73
case ’Minus’
- 74
J_u = CBFricm(dt, j, i, D, rho, viscosity, g,A,a,W,dQ,n_t);
- 75
end
- 76
case ’Unsteady_Friction_Zarzycki’
- 77
% Darcy friction factor, determined for either laminar flow or via
- 78
% the Colebrook-White equation for turbulent flow [−]
- 79
f_q = FricFac(D, roughness, rho, Q_point, viscosity, A);
- 80
% Resistance coefficient [s^2/m^5]
- 81
R = f_q∗dx/(2∗g∗D∗A^2);
- 82
J_s = 0;
- 83
J_q = R∗Q_point∗abs(Q_point);
- 84
switch Charact_Line
- 85
case ’Plus’
- 86
J_u = CBFricp(dt, j, i, D, rho, viscosity, g,A,a,W,dQ,n_t);
- 87
case ’Minus’
- 88
J_u = CBFricm(dt, j, i, D, rho, viscosity, g,A,a,W,dQ,n_t);
- 89
end
- 90
end
- 91
% Friction term [m]
- 92
J = J_s + J_q + J_u;
- 93
end