Skip to content

Commit eddcfd2

Browse files
authored
Fix wave current velocity (WEC-Sim#1540)
* correct current velocity in noWave case * correct current velocity in regular case * correct current velocity in irregular case
1 parent 2723da1 commit eddcfd2

3 files changed

Lines changed: 67 additions & 29 deletions

File tree

source/functions/simulink/model/irregWaveMorison.m

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
curramp = currentSpeedDepth;
4747
end
4848
%Vel should be a column vector
49-
Vel2 = [Vel(1),Vel(2),Vel(3)] + wxr + [curramp*cosd(currentDirection),curramp*sind(currentDirection),0];
49+
Vel2 = [Vel(1),Vel(2),Vel(3)] + wxr;
5050
% Update translational and rotational acceleration
5151
% dotw refers to \dot{\omega} = rotational acceleration
5252
Accelt = [Accel(4),Accel(5),Accel(6)];
@@ -58,7 +58,7 @@
5858
%% Calculate Directionality
5959
for aa = 1:length(direction)
6060

61-
%% Calculate Orbital Velocity
61+
%% Calculate Fluid Velocity and Acceleration
6262
for jj = 1:ff
6363
waveDirRad = direction(aa)*pi/180;
6464
phaseArg = w(jj,1)*Time - k(jj,1)*(ShiftCg(1)*cos(waveDirRad) + ShiftCg(2)*sin(waveDirRad)) + randPhase(jj,1);
@@ -92,8 +92,9 @@
9292

9393
% Sum the wave components to obtain the x, y, z orbital velocities
9494
uV = sum(uVt); uA = sum(uAt); vV = sum(vVt); vA = sum(vAt); wV = sum(wVt); wA = sum(wAt);
95-
fluidV = [uV, vV, wV];
96-
fluidA = [uA, vA, wA];
95+
% Total fluid velocity and acceleration
96+
fluidV = [uV, vV, wV] + [curramp*cosd(currentDirection) curramp*sind(currentDirection) 0];
97+
fluidA = [uA, vA, wA];
9798
if bodyMorison == 2
9899
%% Decompose Fluid Velocity
99100
% Tangential Velocity
@@ -133,22 +134,30 @@
133134
areaRot = abs(mtimes(Area(ii,:),RotMax));
134135
CdRot = mtimes(abs(Cd(ii,:)),RotMax);
135136
CaRot = abs(mtimes(Ca(ii,:),RotMax));
137+
% Fluid velocity relative to the body
138+
uVdiff = fluidV(1) - Vel2(1);
139+
vVdiff = fluidV(2) - Vel2(2);
140+
wVdiff = fluidV(3) - Vel2(3);
141+
% Fluid acceleration relative to the body
142+
uAdiff = fluidA(1) - Accel2(1);
143+
vAdiff = fluidA(2) - Accel2(2);
144+
wAdiff = fluidA(3) - Accel2(3);
136145
% Forces from velocity drag
137-
uVdiff = uV - Vel2(1); FxuV = (1/2)*abs(uVdiff)*uVdiff*rho*CdRot(1)*areaRot(1);
138-
vVdiff = vV - Vel2(2); FxvV = (1/2)*abs(vVdiff)*vVdiff*rho*CdRot(2)*areaRot(2);
139-
wVdiff = wV - Vel2(3); FxwV = (1/2)*abs(wVdiff)*wVdiff*rho*CdRot(3)*areaRot(3);
146+
FxuV = (1/2)*abs(uVdiff)*uVdiff*rho*CdRot(1)*areaRot(1);
147+
FxvV = (1/2)*abs(vVdiff)*vVdiff*rho*CdRot(2)*areaRot(2);
148+
FxwV = (1/2)*abs(wVdiff)*wVdiff*rho*CdRot(3)*areaRot(3);
140149
% Forces from body acceleration inertia
141-
uAdiff = uA - Accel2(1); FxuA = uAdiff*rho*Vol(ii,:)*CaRot(1);
142-
vAdiff = vA - Accel2(2); FxvA = vAdiff*rho*Vol(ii,:)*CaRot(2);
143-
wAdiff = wA - Accel2(3); FxwA = wAdiff*rho*Vol(ii,:)*CaRot(3);
150+
FxuA = uAdiff*rho*Vol(ii,:)*CaRot(1);
151+
FxvA = vAdiff*rho*Vol(ii,:)*CaRot(2);
152+
FxwA = wAdiff*rho*Vol(ii,:)*CaRot(3);
144153
% Forces from fluid acceleration inertia
145154
FxuAf = uA*Vol(ii,:)*rho;
146155
FxvAf = vA*Vol(ii,:)*rho;
147156
FxwAf = wA*Vol(ii,:)*rho;
148157
% Total Force from the Morison Element
149158
F = [FxuV + FxuA + FxuAf,...
150-
FxvV + FxvA + FxvAf,...
151-
FxwV + FxwA + FxwAf];
159+
FxvV + FxvA + FxvAf,...
160+
FxwV + FxwA + FxwAf];
152161
end
153162

154163
FMd(aa,:) = F;

source/functions/simulink/model/noWaveMorison.m

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,25 @@
4242
curramp = currentSpeedDepth;
4343
end
4444
%Vel should be a column vector
45-
Vel2 = [Vel(1),Vel(2),Vel(3)] + wxr + [curramp*cosd(currentDirection),curramp*sind(currentDirection),0];
45+
Vel2 = [Vel(1),Vel(2),Vel(3)] + wxr;
4646
% Update translational and rotational acceleration
4747
% dotw refers to \dot{\omega} = rotational acceleration
4848
Accelt = [Accel(4),Accel(5),Accel(6)];
4949
dotwxr = cross(Accelt,r(ii,:));
5050
wxwxr = cross(Velt,wxr);
5151
Accel2 = [Accel(1),Accel(2),Accel(3)] + dotwxr + wxwxr;
52+
%% Calculate Fluid Velocity and Acceleration
53+
% Orbital Velocity
54+
uV = 0;
55+
vV = 0;
56+
wV = 0;
57+
% Orbital Acceleration
58+
uA = 0;
59+
vA = 0;
60+
wA = 0;
61+
% Total fluid velocity and acceleration
62+
fluidV = [uV, vV, wV] + [curramp*cosd(currentDirection) curramp*sind(currentDirection) 0];
63+
fluidA = [uA, vA, wA];
5264
if bodyMorison == 2
5365
%% Decompose Body Velocity
5466
% Tangential Velocity
@@ -74,14 +86,22 @@
7486
areaRot = abs(mtimes(Area(ii,:),RotMax));
7587
CdRot = mtimes(abs(Cd(ii,:)),RotMax);
7688
CaRot = abs(mtimes(Ca(ii,:),RotMax));
77-
% Forces from body velocity drag
78-
FxuV = (1/2)*abs(-1*Vel2(1))*-1*Vel2(1)*rho*CdRot(1)*areaRot(1);
79-
FxvV = (1/2)*abs(-1*Vel2(2))*-1*Vel2(2)*rho*CdRot(2)*areaRot(2);
80-
FxwV = (1/2)*abs(-1*Vel2(3))*-1*Vel2(3)*rho*CdRot(3)*areaRot(3);
89+
% Fluid velocity relative to the body
90+
uVdiff = fluidV(1) - Vel2(1);
91+
vVdiff = fluidV(2) - Vel2(2);
92+
wVdiff = fluidV(3) - Vel2(3);
93+
% Fluid acceleration relative to the body
94+
uAdiff = fluidA(1) - Accel2(1);
95+
vAdiff = fluidA(2) - Accel2(2);
96+
wAdiff = fluidA(3) - Accel2(3);
97+
% Forces from velocity drag
98+
FxuV = (1/2)*abs(uVdiff)*uVdiff*rho*CdRot(1)*areaRot(1);
99+
FxvV = (1/2)*abs(vVdiff)*vVdiff*rho*CdRot(2)*areaRot(2);
100+
FxwV = (1/2)*abs(wVdiff)*wVdiff*rho*CdRot(3)*areaRot(3);
81101
% Forces from body acceleration inertia
82-
FxuA = rho*Vol(ii,:)*CaRot(1)*-1*Accel2(1);
83-
FxvA = rho*Vol(ii,:)*CaRot(2)*-1*Accel2(2);
84-
FxwA = rho*Vol(ii,:)*CaRot(3)*-1*Accel2(3);
102+
FxuA = uAdiff*rho*Vol(ii,:)*CaRot(1);
103+
FxvA = vAdiff*rho*Vol(ii,:)*CaRot(2);
104+
FxwA = wAdiff*rho*Vol(ii,:)*CaRot(3);
85105
% Sum the force contributions
86106
F = [FxuV + FxuA,FxvV + FxvA,FxwV + FxwA];
87107
end

source/functions/simulink/model/regWaveMorison.m

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@
4343
curramp = currentSpeedDepth;
4444
end
4545
%Vel should be a column vector
46-
Vel2 = [Vel(1),Vel(2),Vel(3)] + wxr + [curramp*cosd(currentDirection),curramp*sind(currentDirection),0];
46+
Vel2 = [Vel(1),Vel(2),Vel(3)] + wxr;
4747
% Update translational and rotational acceleration
4848
% dotw refers to \dot{\omega} = rotational acceleration
4949
Accelt = [Accel(4),Accel(5),Accel(6)];
5050
dotwxr = cross(Accelt,r(ii,:));
5151
wxwxr = cross(Velt,wxr);
5252
Accel2 = [Accel(1),Accel(2),Accel(3)] + dotwxr + wxwxr;
53-
%% Calculate Orbital Velocity
53+
%% Calculate Fluid Velocity and Acceleration
5454
waveDirRad = direction*pi/180;
5555
phaseArg = w*Time - k*(ShiftCg(1)*cos(waveDirRad) + ShiftCg(2)*sin(waveDirRad));
5656
% Vertical Variation
@@ -73,11 +73,12 @@
7373
uV = ramp*coeffHorz*cos(phaseArg)*g*k*(1/w)*cos(waveDirRad);
7474
vV = ramp*coeffHorz*cos(phaseArg)*g*k*(1/w)*sin(waveDirRad);
7575
wV = -ramp*coeffVert*sin(phaseArg)*g*k*(1/w);
76-
fluidV = [uV, vV, wV];
7776
% Orbital Acceleration
7877
uA = -ramp*coeffHorz*sin(phaseArg)*g*k*cos(waveDirRad);
7978
vA = -ramp*coeffHorz*sin(phaseArg)*g*k*sin(waveDirRad);
8079
wA = -ramp*coeffVert*cos(phaseArg)*g*k;
80+
% Total fluid velocity and acceleration
81+
fluidV = [uV, vV, wV] + [curramp*cosd(currentDirection) curramp*sind(currentDirection) 0];
8182
fluidA = [uA, vA, wA];
8283
if bodyMorison == 2
8384
%% Decompose Fluid Velocity
@@ -118,14 +119,22 @@
118119
areaRot = abs(mtimes(Area(ii,:),RotMax));
119120
CdRot = mtimes(abs(Cd(ii,:)),RotMax);
120121
CaRot = abs(mtimes(Ca(ii,:),RotMax));
122+
% Fluid velocity relative to the body
123+
uVdiff = fluidV(1) - Vel2(1);
124+
vVdiff = fluidV(2) - Vel2(2);
125+
wVdiff = fluidV(3) - Vel2(3);
126+
% Fluid acceleration relative to the body
127+
uAdiff = fluidA(1) - Accel2(1);
128+
vAdiff = fluidA(2) - Accel2(2);
129+
wAdiff = fluidA(3) - Accel2(3);
121130
% Forces from velocity drag
122-
uVdiff = uV - Vel2(1); FxuV = (1/2)*abs(uVdiff)*uVdiff*rho*CdRot(1)*areaRot(1);
123-
vVdiff = vV - Vel2(2); FxvV = (1/2)*abs(vVdiff)*vVdiff*rho*CdRot(2)*areaRot(2);
124-
wVdiff = wV - Vel2(3); FxwV = (1/2)*abs(wVdiff)*wVdiff*rho*CdRot(3)*areaRot(3);
131+
FxuV = (1/2)*abs(uVdiff)*uVdiff*rho*CdRot(1)*areaRot(1);
132+
FxvV = (1/2)*abs(vVdiff)*vVdiff*rho*CdRot(2)*areaRot(2);
133+
FxwV = (1/2)*abs(wVdiff)*wVdiff*rho*CdRot(3)*areaRot(3);
125134
% Forces from body acceleration inertia
126-
uAdiff = uA - Accel2(1); FxuA = uAdiff*rho*Vol(ii,:)*CaRot(1);
127-
vAdiff = vA - Accel2(2); FxvA = vAdiff*rho*Vol(ii,:)*CaRot(2);
128-
wAdiff = wA - Accel2(3); FxwA = wAdiff*rho*Vol(ii,:)*CaRot(3);
135+
FxuA = uAdiff*rho*Vol(ii,:)*CaRot(1);
136+
FxvA = vAdiff*rho*Vol(ii,:)*CaRot(2);
137+
FxwA = wAdiff*rho*Vol(ii,:)*CaRot(3);
129138
% Forces from fluid acceleration inertia
130139
FxuAf = uA*Vol(ii,:)*rho;
131140
FxvAf = vA*Vol(ii,:)*rho;

0 commit comments

Comments
 (0)