Giter VIP home page Giter VIP logo

fostwin's People

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

fostwin's Issues

Excitation force calculation based on spectrum

@bretbosma The code that calculates the excitation force time series for SID, based on S(w), seems a little convoluted and may contain some errors (not entirely sure yet).

FOSTWIN/SIDWaveGenerator.m

Lines 57 to 160 in d2ed56b

% generate complex spectrum with random phases
phi = 2*pi*rand(size(S)); % random phases
A = sqrt(2*S*df).*exp(1i*phi); % complex A
% figure
% subplot(211)
% plot(w,abs(A))
% ylabel('Amplitude (m)')
% grid on
%
% subplot(212)
% plot(w,angle(A))
% ylabel('Angle (rad)')
% xlabel('\omega (rad/sec)')
%
%
% sgtitle('JONSWAP amplitude spectrum with random phases')
% grid on
% interpolate wamit results to fit spectral frequency
wamitExAft = interp1(wamit.w,wamit.FexAftPitch,w,'spline','extrap');
wamitExBow = interp1(wamit.w,wamit.FexBowPitch,w,'spline','extrap');
% multiply JONSWAP amplitude spectrum and wamit excitation spectrum
FexAft_w = A .* wamitExAft;
FexBow_w = A .* wamitExBow;
argAft = [0, FexAft_w(2:Nf-1), 2*real(FexAft_w(Nf)), conj(FexAft_w(Nf-1:-1:2))];
argBow = [0, FexBow_w(2:Nf-1), 2*real(FexBow_w(Nf)), conj(FexBow_w(Nf-1:-1:2))];
FexAft(1:N) = real(N/2*ifft(argAft)); % generate timeseries
FexBow(1:N) = real(N/2*ifft(argBow)); % generate timeseries
% TsTwin = TsTwin * 10;
tnew = 0:TsTwin:duration; % around 100 hz for tsTwin
FexAftnew = interp1(t,FexAft,tnew,'spline','extrap');
FexBownew = interp1(t,FexBow,tnew,'spline','extrap');
% figure
% plot(t,FexAft)
% hold on
% plot(t,FexBow)
% plot(tnew,FexAftnew,'--')
% plot(tnew,FexBownew,'--')
% legend('Aft','Bow','Aft New','Bow New')
t = tnew;
FexAft = FexAftnew;
FexBow = FexBownew;
% tukey window on the first and last 20 seconds
r = 40/duration;
r_win = tukeywin(length(t),r).';
FexAft = FexAft .* r_win;
FexBow = FexBow .* r_win;
% plot WAMIT excitation spectrum
% figure
% subplot(211)
% plot(wamit.w,abs(wamit.FexAftPitch))
% hold on
% plot(wamit.w,abs(wamit.FexBowPitch))
% legend('Aft','Bow')
% ylabel('Excitation (Nm/m)')
%
% subplot(212)
% plot(wamit.w,angle(wamit.FexAftPitch))
% hold on
% plot(wamit.w,angle(wamit.FexBowPitch))
% xlabel('\omega (rad/s)')
% ylabel('angle (rad)')
% sgtitle('Normalized Excitation Spectrum (WAMIT)')
%
% % plot magnitude with interpolated
% figure
% plot(wamit.w,abs(wamit.FexAftPitch),'-')
% hold on
% plot(w,abs(wamitExAft),'*')
% xlabel('\omega(rad/s)')
% ylabel('Excitation spectrum magnitude')
% legend('WAMIT','Interpolated')
FexcAft = timeseries(FexAft,t);
FexcBow = timeseries(FexBow,t);
Fexc.Aft = timeseries(FexAft,t);
Fexc.Bow = timeseries(FexBow,t);
busInfo = Simulink.Bus.createObject(Fexc);
% generate time series of Excitation Force for bow and aft
% figure
% plot(t,FexAft)
% hold on
% plot(t,FexBow)
% legend('Aft','Bow')
% grid on
% xlabel('time (s)')
% ylabel('Fex (Nm)')
% title('Excitation force input time series')
Fexin = Simulink.SimulationData.Dataset;
Fexin = Fexin.addElement(Fexc.Aft,'FexAft');
Fexin = Fexin.addElement(Fexc.Bow,'FexBow');

A potentially simpler version that should yield the same result is this (to be checked)

  % generate spectrum with random phases
    phi = 2*pi*rand(size(S)); % random phases
    A = sqrt(2*S*df); %NOT complex A - phase is dealt with further below .*exp(1i*phi); % complex A
    
    % interpolate wamit results to fit spectral frequency
    wamitExAft = interp1(wamit.w,wamit.FexAftPitch,w,'spline','extrap');
    wamitExBow = interp1(wamit.w,wamit.FexBowPitch,w,'spline','extrap');
    
    % multiply JONSWAP amplitude spectrum and wamit excitation spectrum
    FexAft_w = A .* wamitExAft;
    FexBow_w = A .* wamitExBow;

    t = 0:TsTwin:duration; % around 100 hz for tsTwin

    % Note: WecSim uses Re*cos(x) - Im*sin(x), which corresponds to
    % real(A*exp(-ix))
    FexAft = zeros(size(t));
    FexBow = zeros(size(t));
    for n=1:length(w)
        arg = -1i*(w(n)*t + phi(n));
        FexAft = FexAft + real(FexAft_w(n)*exp(arg));  
        FexBow = FexBow + real(FexBow_w(n)*exp(arg));  
    end

Stop Target Timeouts

When running the simulation in realtime, there are often issues when running the pTg.stop line to stop the simulation on the speedgoat.

Symptoms:

  • run pTg.stop or stoptarget (when coming from the UI)
  • Get Cannot stop application on target 'EGIBaseline2' : Timed-out waiting for application to stop
  • Simulation is no longer transmitting data - also the current step time stops increasing if looking at the speedgoat screen/ using the UI - no data coming in anymore
  • About 30 seconds later, the speedgoat ends up in the "DONE" state and the logsout variable is transferred to the host machine

Adding Simulink.sdi.setRecordData(false); didn't seem to fix the issue

WAMIT excitation force phasing

@bretbosma I believe I found a first issue as to why SID and wecSim give different results. There are likely more differences, but this particular issue should probably be resolved first.

I compared the excitation force from the "excitationWAMIT.mat" file with that from the h5 file used in wecSim. The Matlab code used for the comparison is pasted at the end of this issue. This code will need wecSim on the path for the readBEMIOH5 function.

The results:

image

image

image

Observations:

  • the comparison looks good for the abs
  • for the real and imag, it seems the phase is "scrambled" (for lack of a better word) for the aft flap for the SID case. The behavior of this excitation force does not look physical. I suspect something went wrong when the "excitationWAMIT.mat" file was created

Possible actions:

  • Replace the "excitationWAMIT.mat" file with a corrected version (if found to be incorrect)
  • Remove the "excitationWAMIT.mat" file, and read from the h5 file as in the code below. If going this route, we should extract the required h5 read code from the wecSim example, and have a little helper function in our repo (to avoid needing a wecSim install on the path for the SID option).

@bretbosma - any views?

% check excitation force between WAMIT mat file for SID and h5 file for
% WecSim

clearvars; close all; clc;

% SID excitation force from WAMIT
sid = load('excitationWAMIT.mat');

dofPitch = 5;
rho = 1020;
g = 9.81;

% use wecSim script to read H5 file
hydroWecSimFlapBow = readBEMIOH5('hydroData/foswec.h5',1,0); % bow flap is body 1
hydroWecSimFlapAft = readBEMIOH5('hydroData/foswec.h5',3,0); % aft flap is body 3

wecSimFexBowPitch =  rho*g* (squeeze(hydroWecSimFlapBow.hydro_coeffs.excitation.re(dofPitch,1,:)) ...
                        + 1i*squeeze(hydroWecSimFlapBow.hydro_coeffs.excitation.im(dofPitch,1,:)));

wecSimFexAftPitch =  rho*g* (squeeze(hydroWecSimFlapAft.hydro_coeffs.excitation.re(dofPitch,1,:)) ...
                        + 1i*squeeze(hydroWecSimFlapAft.hydro_coeffs.excitation.im(dofPitch,1,:)));

figure
subplot(2,1,1)
plot(sid.w, abs(sid.FexBowPitch))
hold on
plot(hydroWecSimFlapBow.simulation_parameters.w, abs(wecSimFexBowPitch))
ylabel('Fex Pitch Bow (Nm/m)')
xlabel('t (s)')
title('Abs')
legend('SID','wecSim')

subplot(2,1,2)
title('Abs')
plot(sid.w, abs(sid.FexAftPitch))
hold on
plot(hydroWecSimFlapAft.simulation_parameters.w, abs(wecSimFexAftPitch))
ylabel('Fex Pitch Aft (Nm/m)')
xlabel('t (s)')
legend('SID','wecSim')

figure
subplot(2,1,1)
plot(sid.w, real(sid.FexBowPitch))
hold on
plot(hydroWecSimFlapBow.simulation_parameters.w, real(wecSimFexBowPitch))
ylabel('Fex Pitch Bow (Nm/m)')
xlabel('t (s)')
title('Real')
legend('SID','wecSim')

subplot(2,1,2)
plot(sid.w, real(sid.FexAftPitch))
hold on
plot(hydroWecSimFlapAft.simulation_parameters.w, real(wecSimFexAftPitch))
ylabel('Fex Pitch Aft (Nm/m)')
xlabel('t (s)')
legend('SID','wecSim')

figure
subplot(2,1,1)
plot(sid.w, imag(sid.FexBowPitch))
hold on
plot(hydroWecSimFlapBow.simulation_parameters.w, imag(wecSimFexBowPitch))
ylabel('Fex Pitch Bow (Nm/m)')
xlabel('t (s)')
title('Imag')
legend('SID','wecSim')

subplot(2,1,2)
plot(sid.w, imag(sid.FexAftPitch))
hold on
plot(hydroWecSimFlapAft.simulation_parameters.w, imag(wecSimFexAftPitch))
ylabel('Fex Pitch Aft (Nm/m)')
xlabel('t (s)')
legend('SID','wecSim')

SID excitation force: JONSWAP scaling factor

@bretbosma The JONSWAP spectrum is calculated here:

S = 5/16*Hm0^2*fp^4./f.^5.*exp(-1.25*(f/fp).^(-4)); % Pierson-Moskowitz
S(1)=0;
sigma = ones(size(f)) * 0.07; % sigma = 0.07 (f<=fp) or 0.09 (f>fp)
sigma(f>fp) = 0.09;
S = S .* gamma.^exp(-(f/fp - 1).^2 ./ (2*sigma.^2)); % JONSWAP

This appears to be missing a scaling factor that adjusts the overall spectrum energy to account for gamma. Based on IEC TC114 -2 this factor should be of the form:

image

For gamma = 3.3 this introduces ~25 error in the forcing / surface elevation.

Frequency response in the journal paper

Hello @johannes-spinneken, I'm a PhD student working on this competition and I have a question about the frequency response in your paper (Fig. 7).

FOSWEC paper_frequency response

I'm not sure what is the input and the output here, I guess this is based on the flap frame, and shows the frequency response from flap torque to flap velocity, is that correct? I tried to compare this to the bode plot I got from your SystemID model. The result shows that the two systems are totally different. Are we supposed to get the same system in this competition?

Besides, I tried to find out the frequency response of your wecSim model, and this seems to be different from the SystemID model (but somewhat similar). So I am also wondering how much difference is expected between the two models.

Thank you for your time and response.

Number of failed/ unstable controller attempts not reset when restarting simulation

Not sure if this is the behavior we want, but when restarting a simulation through the UI, where the model isn't re-compiled, the number of faults/ unstable states that the controller is allowed to into before landing in the fault state isn't re-set.

Might become an issue if someone is using the realtime system to test optimizing parameters, where some of the tests land the controller in an unstable state.

Triggers for state machine

From today's information session: What do you use to detect instability and trigger the state machine?

JONSWAP gamma

@bretbosma The way the FOSWTIN code is currently setup, gamma is set to 3.3 for SID, and not set explicitly for the WecSim simulations.

WecSim will calculate gamma based on Tp and Hs using IEC TC114 -2:

image

For the standard case (Hs = 0.136m and Tp=2.61s), WecSim will use gamma of 1.0, whereas gamma = 3.3 (hard coded) for SID. This means WecSim and SID may often use different gamma and results are difficult to compare.

Solutions:

  • Could bring gamma into the main init script, and then explicitly set gamma for both SID and WecSim
  • Could calculate gamma in the SID wave generator script, based on the same equations as WecSim

SID vs. WecSim comparision: Case A

The purpose of this issue is to track comparisons between the FOSTWIN SID and WecSim results. This issue covers Case A: Hs=0.136m and Tp = 2.61m

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.