|
| 1 | +%% Read OSWEC hydro data |
| 2 | +hydro = struct(); |
| 3 | +hydro = readWAMIT(hydro,'../../../_Common_Input_Files/OSWEC/hydroData/oswec.out',[]); |
| 4 | +hydro = radiationIRF(hydro,40,[],[],[],[]); |
| 5 | +hydro = excitationIRF(hydro,40,[],[],[],[]); |
| 6 | +hydro.plotDirections = [36 1 2 3]; |
| 7 | +hydro.plotDofs = [6 6]; |
| 8 | +hydro.plotBodies = 1; |
| 9 | +% plotBEMIO(hydro) |
| 10 | +% hydro = writeBEMIOH5(hydro); |
| 11 | + |
| 12 | +%% Split hydro into multiple hydro structures by wave direction |
| 13 | +iDirs = [32 33 34 35 36 1 2 3 4 5 6]; % select direction indices to use |
| 14 | +for i = 1:length(iDirs) |
| 15 | + iDir = iDirs(i); |
| 16 | + |
| 17 | + temp_hydro = hydro; |
| 18 | + vars = {'ex_K','ex_ma', 'ex_ph', 'ex_re', 'ex_im', ... |
| 19 | + 'sc_ma', 'sc_ph', 'sc_re', 'sc_im', ... |
| 20 | + 'fk_ma', 'fk_ph', 'fk_re', 'fk_im'}; % directionally dependent variables |
| 21 | + |
| 22 | + for iVar = 1:length(vars) |
| 23 | + temp_hydro.(vars{iVar}) = hydro.(vars{iVar})(:,iDir,:); |
| 24 | + end |
| 25 | + temp_hydro.Nh = 1; |
| 26 | + % temp_hydro.file = [hydro.file '_' num2str(temp_hydro.theta)]; |
| 27 | + temp_hydro.file = [hydro.file '_' num2str(hydro.theta(iDir))]; |
| 28 | + temp_hydro.theta = 10; |
| 29 | + |
| 30 | + % theta(i) = temp_hydro.theta; |
| 31 | + theta(i) = hydro.theta(iDir); |
| 32 | + |
| 33 | + % Assign split data to a new structure array |
| 34 | + hydro_split(i) = temp_hydro; |
| 35 | +end |
| 36 | + |
| 37 | +%% interpolate BEM data to greater directional fidelity |
| 38 | +theta = wrapTo180(theta); |
| 39 | +nTheta0 = length(theta); |
| 40 | +thetaInds = 1:nTheta0; |
| 41 | + |
| 42 | +newDirs = -40:0.05:40; |
| 43 | +newDirs = setdiff(newDirs,theta); % remove values repeated in theta |
| 44 | + |
| 45 | +% Append the interpolated direction and hydro structue to theta and |
| 46 | +% hydro_split respectively. |
| 47 | +theta(end+1:end+length(newDirs)) = newDirs; |
| 48 | +for i = nTheta0 + 1 : length(theta) |
| 49 | + ind1 = thetaInds(theta(i) > theta(1:nTheta0)); |
| 50 | + ind1 = ind1(end); |
| 51 | + |
| 52 | + ind2 = thetaInds(theta(i) < theta(1:nTheta0)); |
| 53 | + ind2 = ind2(1); |
| 54 | + |
| 55 | + hydro_split(i) = hydro_split(1); |
| 56 | + hydro_split(i).theta = 10; % this has to be the same as the wave direction so that the BEM data processes correctly. |
| 57 | + hydro_split(i).file = [hydro.file '_' num2str(wrapTo360(theta(i)))]; |
| 58 | + |
| 59 | + dTheta = (theta(i) - theta(ind1)) / (theta(ind2) - theta(ind1)); |
| 60 | + for iVar = 2:length(vars) % start at 2 to skip theta |
| 61 | + hydro_split(i).(vars{iVar}) = hydro_split(ind1).(vars{iVar}) * (1-dTheta) +... |
| 62 | + hydro_split(ind2).(vars{iVar}) * dTheta; |
| 63 | + end |
| 64 | +end |
| 65 | + |
| 66 | +% Sort theta and hydro_split into the correct order based on frequency |
| 67 | +[thetaSorted,iSorted] = sort(theta); |
| 68 | +theta = wrapTo360(theta); |
| 69 | +thetaSorted = wrapTo360(thetaSorted); |
| 70 | +hydro_sorted = hydro_split(iSorted); |
| 71 | + |
| 72 | +%% Write all data to h5 files |
| 73 | +for i = 1:length(hydro_sorted) |
| 74 | + % Skip files that have already been written because writeBEMIOH5 is slow |
| 75 | + if ~isfile([hydro_sorted(i).file '.h5']) |
| 76 | + writeBEMIOH5(hydro_sorted(i)); |
| 77 | + end |
| 78 | +end |
0 commit comments