Skip to content

Conversation

@akeeste
Copy link
Contributor

@akeeste akeeste commented Oct 29, 2020

This is a fix and cleanup of the convolution integral function. There is a version bug between MATLAB R2020a and R2020b in the bsxfun() function.

This closes #437 .

Note it does not pass all tests, 8 fail. 6 test have minor differences close to the tolerance limit, and two in the passive yaw irregular case fail with larger errors.
Pos_diff = 2.5e-4
Force_diff = 7.9e+3

@akeeste akeeste added the Bug bug in WEC-Sim source, high priority label Oct 29, 2020
@akeeste akeeste linked an issue Oct 29, 2020 that may be closed by this pull request
@kmruehl kmruehl requested review from jleonqu and nathanmtom October 30, 2020 17:09
@kmruehl kmruehl added the Version MATLAB version issue, aka related to version compatibility label Oct 30, 2020
@kmruehl
Copy link
Collaborator

kmruehl commented Oct 30, 2020

@nathanmtom and @jleonqu can you review this and run it in 2020b?

@akeeste akeeste marked this pull request as draft October 30, 2020 17:20
@akeeste
Copy link
Contributor Author

akeeste commented Oct 30, 2020

Aside from a few small typos in the bodyClass, all changes are in one function in the Simulink library:
WECSim_Lib/Body Elements/Rigid Body/Hydrodynamic Body/Wave Radiation Forces Calculation/SS CI and Constant-Damping-CoeVariant Subsystem/Convolution Integral Calculation/ConvolutionIntegral_interp

Block location:
ci_location

Original CI function:
original_ci_function

New CI function:
new_ci_function

@jleonqu
Copy link
Contributor

jleonqu commented Oct 30, 2020

I was able to check this pull request locally in my computer. I run the case using Matlab 2020b and it works.

@akeeste
Copy link
Contributor Author

akeeste commented Nov 9, 2020

I have discussed this issue with Mathworks support. They confirmed that R2020a contained a bug allowing Simulink to compile without an error message. This allowed bsxfun() to function incorrectly and did not give the intended results. The bug was fixed in R2020b.

My update permutes the velocity and IRKB dimensions within the convolution integral function so that the dimensions match correctly for multiplication. 8/25 continuous integration tests still fail, because of the previous version's inaccurate bug.

@nathanmtom When you have time, can you please review the updated convolution integral function and check that it is calculating the integral correctly according to the theory documentation?

@akeeste akeeste marked this pull request as ready for review November 9, 2020 15:27
@kmruehl kmruehl added the high label Nov 18, 2020
@akeeste
Copy link
Contributor Author

akeeste commented Nov 19, 2020

Mathworks support also confirmed to me that this bug first appeared in R2017b (released September 2017). In 2017b, the requirements for dimension expansion were relaxed. It became possible for MATLAB to miss a runtime error for incompatible dimension operations, such as bsxfun().

I checked releases v2.2 and v3.0 which were before/after R2017b released. The convolution integration function does change between these versions, but I have not confirmed if v2.2 should have had this same error. It is likely the error in the changed function was missed because it overlapped with the simulink bug release which allowed it.

I am currently testing the accuracy of this change using the B2B application. This app compares regular wave, regular+B2B, regularCIC, regularCIC+B2B, regularCIC+SS, regularCIC+B2B+SS cases. The new CI update should match the state space response very closely. However there are some significant differences now between the CI and SS cases as shown in the radiation damping force plots:

Radiation damping in Surge:
surge

Radiation damping in Heave:
heave

Radiation damping in Pitch:
pitch

@akeeste
Copy link
Contributor Author

akeeste commented Nov 23, 2020

I solved the last problems with this bug. In addition to the permutations in the CI block, there was an issue with the selector block that chose the velocity values to pass into the CI function. I have solved both issues and the function now works correctly. All continuous integration tests are passing.

The below figures show that the CI calculations (black lines) are now more closely aligned with the state space calculations (light blue) and likely more accurate than previously.

Surge:
surge

Heave:
heave

Pitch:
pitch

@akeeste akeeste merged commit 0214db5 into WEC-Sim:dev Dec 2, 2020
@akeeste akeeste deleted the ci_b2b_bug branch December 2, 2020 14:27
@kmruehl kmruehl added MATLAB/Simulink MATLAB or Simulink related issues and removed High labels Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug bug in WEC-Sim source, high priority MATLAB/Simulink MATLAB or Simulink related issues Version MATLAB version issue, aka related to version compatibility

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug when using B2B and CI calculation together

3 participants