Skip to content

Commit 54e974a

Browse files
MShabaraakeeste
andauthored
Fix for the elevation plot when multiple wave classes are defined (WEC-Sim#1526)
* fix for the elevation plot when multiple wave classes are defined * converts the types of waves to char * Update source/functions/initializeWecSim.m * update waves.plotSpectra() for multiple waves --------- Co-authored-by: Adam Keester <72414466+akeeste@users.noreply.github.com> Co-authored-by: akeeste <akeeste@sandia.gov>
1 parent d8a113f commit 54e974a

2 files changed

Lines changed: 24 additions & 15 deletions

File tree

source/functions/initializeWecSim.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@
321321

322322
% Check for all waves(#) are of the same type
323323
for iW = 2:length(waves)
324-
if strcmp(waves(iW).type, waves(1).type) ~=1
324+
if ~isequal(waves(iW).type, waves(1).type)
325325
error('All Wave-Spectra should be the same type as waves(1)')
326326
end
327327
end; clear iW

source/objects/waveClass.m

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -550,12 +550,16 @@ function plotElevation(obj,rampTime)
550550
rampTime double {mustBeReal, mustBeNonNan, mustBeFinite} = 0
551551
end
552552

553+
waveElevationSum = zeros(size(obj(1).waveAmpTime(:,2)));
554+
for i = 1:numel(obj)
555+
waveElevationSum = waveElevationSum + obj(i).waveAmpTime(:,2);
556+
end
553557
figure
554-
plot(obj.waveAmpTime(:,1),obj.waveAmpTime(:,2))
558+
plot(obj(1).waveAmpTime(:,1),waveElevationSum)
555559
title('Wave Surfave Elevation')
556560
if nargin==2
557561
hold on
558-
line([rampTime,rampTime],[1.5*min(obj.waveAmpTime(:,2)),1.5*max(obj.waveAmpTime(:,2))],'Color','k')
562+
line([rampTime,rampTime],[1.5*min(obj(1).waveAmpTime(:,2)),1.5*max(obj(1).waveAmpTime(:,2))],'Color','k')
559563
title(['Wave Surface Elevation, Ramp Time ' num2str(rampTime) ' (s)'])
560564
end
561565
xlabel('Time (s)')
@@ -570,23 +574,28 @@ function plotSpectrum(obj)
570574
% figure : fig
571575
% Plot of wave spectrum versus wave frequency
572576
%
573-
m0 = trapz(obj.omega,obj.spectrum);
574-
HsTest = 4*sqrt(m0);
575-
[~,I] = max(abs(obj.spectrum));
576-
wp = obj.omega(I);
577-
TpTest = 2*pi/wp;
577+
for i = 1:length(obj)
578+
m0 = trapz(obj(i).omega,obj(i).spectrum);
579+
Hs(i) = 4*sqrt(m0);
580+
[sMax(i),I] = max(abs(obj(i).spectrum));
581+
wp(i) = obj(i).omega(I);
582+
Tp(i) = 2*pi/wp(i);
583+
end
578584

579585
figure
580-
plot(obj.omega,obj.spectrum,'s-')
586+
legendStrings = {};
581587
hold on
582-
line([wp,wp],[0,max(obj.spectrum)],'Color','k')
583-
xlim([0 max(obj.omega)])
584-
title([obj.spectrumType, ' Spectrum, T_p= ' num2str(TpTest) ' [s], ' 'H_m_0= ' num2str(HsTest), ' [m]'])
585-
if strcmp(obj.spectrumType,'JS') == 1
586-
title([obj.spectrumType, ' Spectrum, T_p= ' num2str(TpTest) ' [s], H_m_0= ' num2str(HsTest), ' [m], gamma = ' num2str(obj.gamma)])
587-
end
588+
for i = 1:length(obj)
589+
plot(obj(i).omega, obj(i).spectrum, 's-', ...
590+
[wp(i), wp(i)], [0, sMax(i)], '--');
591+
legendStrings{end+1} = ['waves(' num2str(i) ') spectrum'];
592+
legendStrings{end+1} = ['waves(' num2str(i) ') peak period'];
593+
end
594+
legend(legendStrings);
595+
xlim([0 max(obj(1).omega)])
588596
xlabel('Frequency (rad/s)')
589597
ylabel('Spectrum (m^2-s/rad)');
598+
title('Wave Spectra');
590599
end
591600

592601
end

0 commit comments

Comments
 (0)