Skip to content

Conversation

@salhus
Copy link
Contributor

@salhus salhus commented May 24, 2023

@nathanmtom

As mentioned in the last comment for #1063 the fix needs to be done to readWAMIT and writeBEMIOh5.
Here is an illustration.
I modified an .out file to have $(4,6)$ and $(5,6)$ terms.
modOut

Here is how readWAMIT would read it to MATLAB workspace,

readWAMITout

I then fixed the readWAMIT to have zeros in the $6^{th}$ row. The readWAMIT function then read the .out file correctly to the MATLAB workspace but the writeBEMIOh5 still automatically does a transpose (perhaps the writing indices are switched in the writing function),

Here is how readWAMIT read the .out file,
after_readWAMIT_fix

While after the writeBEMIOh5 is done the h5 file is written like this,
h5File_readWAMIT_fix

After having the trasnpose done in the writeBEMIOh5 as well, it can be seen that readWAMIT reads the matrix correctly to the workspace, and the writeBEMIOh5 writes the h5 file correctly,

here is readWAMIT reading the matrix correctly to the workspace,
after_readWAMIT_and_writeBEMIOh5_fix

and here is the h5 file correctly written,
h5_after_readWAMIT_and_writeBEMIOh5_fix

@nathanmtom
Copy link

@salhus Thanks for double checking the implementation here. As I'm reviewing this PR one quick request is that in 'readBEMIOH5.m' to delete line 56 where you originally zeroed the 6 row of the hydrostatic matrix. I'll follow-up with comments directly on the files you've changed so far.

this commit removes the line 56 that zeros the last row of the hydrostatics matrix.
@salhus
Copy link
Contributor Author

salhus commented May 31, 2023

@nathanmtom Thanks for pointing that. I just made a commit that removes the line 56.

tmp = textscan(raw{n+3}(find(raw{n+3}==':')+1:end),'%f');
hydro(F).Khs(5,5:6,hydro(F).Nb) = tmp{1};
hydro(F).Khs(5:6,5,hydro(F).Nb) = tmp{1};
hydro(F).Khs(6,:) = 0*hydro(F).Khs(6,:); % 6th row must be zeros

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Sal, so putting line 96 in does work, but wondering if rather than writing cells then overwriting with 0 it would be better to update how we import and assign the hydrostatic coefficients. If we change the following lines we should get the same result but adjust the code to better infer what coefficients should be transposed across the diagonal.

Replace line 92 with:
hydro(F).Khs(4:5,4,hydro(F).Nb) = tmp{1}(1:2);
Delete lines 95 and lines 96

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. That would remove the 6th row being written in the first place. I made a commit to that effect

clear tmp;
else
writeH5Parameter(filename,['/body' num2str(i) '/hydro_coeffs/linear_restoring_stiffness'],hydro.Khs(:,:,i),'Hydrostatic stiffness matrix','');
writeH5Parameter(filename,['/body' num2str(i) '/hydro_coeffs/linear_restoring_stiffness'],hydro.Khs(:,:,i)','Hydrostatic stiffness matrix','');
Copy link

@nathanmtom nathanmtom Jun 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@salhus I do not have an .h5 viewer, but you mention that this flip is to make the viewer have the right matrix format; however, we then use the reverseDimensionOrder in the readBEMIOH5 to get it back in the original form for WEC-Sim. Therefore, we are flipping it forward and flipping it backward. I tried running without the transpose and then removing the reverseDimensionOrder and the WAMIT and AQWA matrices were in the right format for WEC-Sim.

Therefore, my question is if we can clean up this implementation to not have unnecessary flipping if it is only for the .h5 viewer. As mentioned above the results come out as we want, just seeing if the implementation can be modified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nathanmtom,
I see your point that it is redundant. However, I think having the h5 file represent the coefficients is also important.
The h5 files are useful in their own right because it can be a standardised way of expressing the bemio processed results regardless of BEM software being used. This is helpful when comparing hydrodynamic coefficients, or importing it to optimizers etc.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@salhus I understand and agree with that point. But now wondering why the .h5 viewer does a flip when importing into its own data format. Did you have the opportunity to verify if other .h5 viewers provided the same result? As perhaps if there is an import issue with the one .h5 viewer you are testing while others do not have this issue then perhaps we eliminate this redundancy and note one .h5 viewer is perhaps importing incorrectly. This might be a non-issue just do not personal use .h5 viewers at this time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nathanmtom
Yes, I did check with another h5viewer, and observed the same dimension order.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, then no further discussion on this point needed and will keep it as is.

salhus added 2 commits May 31, 2023 18:29
only_write_what_you_need
-forgot adding (1,2) in the last commit
tmp = textscan(raw{n+3}(find(raw{n+3}==':')+1:end),'%f');
hydro(F).Khs(5,5:6,hydro(F).Nb) = tmp{1};
hydro(F).Khs(5:6,5,hydro(F).Nb) = tmp{1};
% 6th row must be zeros

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@salhus Minor comment, can we delete this line. Without more context a user might not understand why and we do not provide greater description in our documentation. Therefore, requesting to either delete, or reference the AQWA or WAMIT manuals.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I just made that commit.

remove comment for cleaner code
@nathanmtom nathanmtom merged commit db83778 into WEC-Sim:dev Jun 2, 2023
@nathanmtom
Copy link

Thanks for bearing with me and answering my questions on a fairly straightforward PR, but still nice to have documentation of the decisions made if we need to revisit in the future. Merge coming shortly.

@salhus
Copy link
Contributor Author

salhus commented Jun 2, 2023

Thanks @nathanmtom ! I appreciate it.
Yes, it will be good to be able to point out to this discussion if some one has questions in the future.

@salhus salhus deleted the hydrostatics_readWAMIT_writeBEMIOh5 branch October 4, 2023 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants