Skip to content

Conversation

@MShabara
Copy link
Contributor

This PR updates the optimalGainCalc files for the P and PI controllers to compute the gains and power using interpolated hydrodynamic coefficients instead of relying on the values at the nearest frequency.

Benefit:
Interpolating the hydrodynamic coefficients improves the accuracy of the computed gains and power, especially when the hydrodynamic data is available only at coarse frequency intervals.

Below are a comparison of the codes results before (-- orange) and after the modification (blue)
PI:
image

P:
image

@MShabara MShabara requested a review from jtgrasb July 30, 2025 02:34
Adds semicolon to one of the lines
@jtgrasb
Copy link
Contributor

jtgrasb commented Aug 7, 2025

@MShabara Thanks for these updates! They look good, just waiting on the latching and declutching cases.

@MShabara
Copy link
Contributor Author

MShabara commented Aug 9, 2025

@jtgrasb There appears to be a bug in optimalgainCalc.m for both the latching and declutching control applications.

When calculated manually, the device’s natural frequency is 1.2853 rad/s, but the functions in the latching and declutching cases compute it as 1.4500 rad/s. This discrepancy leads to incorrect latching and de clutching time values. The main reason for this difference is the definition of the added mass.

For the latching control: When manually setting the natural frequency in the functions to 1.2853 rad/s, the resulting times match the optimal values obtained from the parameter sweep using the MCR.

For declutching control: Correcting the natural freq does not solve the issue
image

Do you have an idea of what might be wrong?

@jtgrasb
Copy link
Contributor

jtgrasb commented Aug 14, 2025

@MShabara What do you mean by calculating the natural frequency manually? By running a free decay test?

@MShabara
Copy link
Contributor Author

@jtgrasb this is actually an interesting question, there are two ways to do that:

1- The first is using the SDOF natural freq equation for heave only motion
$\omega_n = \sqrt{\frac{k}{m+m_\infty}} = \sqrt{\frac{770389.11}{261724+204629.35}} = 1.2853$ rad/sec -> $T_n = 4.8886$ sec

2- Second using the decay test by applying
waves = waveClass('noWave');
waves.period = 9.6664;

image

$T_n = (9.76-4.91) = 4.85 sec$ -> $\omega_n = 1.2955 rad/sec$
Which is close enough to the analytical solution.

When trying to get the natural freq graphically using the waves = waveClass('noWaveCIC);
You endup with
image
$T_n = 4.34$ sec -> $\omega_n = 1.4477$ rad/sec

This value is close to the one the optimalControlGains.m produce as the added mass in that case is 130876.8, not 204629.35 as in the previous case.

@akeeste akeeste changed the base branch from dev to main August 25, 2025 18:13
@jtgrasb
Copy link
Contributor

jtgrasb commented Sep 10, 2025

@MShabara Thanks for explaining. I was also confused so did some digging:

  • There is a key difference here between natural frequency and resonant frequency. In all of the examples and documentation, I refer to the natural frequency, but what I really meant was the resonance frequency. Although a lot of papers I've seen use them somewhat interchangeably, there's a key difference that is at hand here. The natural frequency is generally more of a static value for a fixed system (like you are calculating above). For a WEC, its natural frequency would change based on the wave frequency. The resonant frequency on the other hand is the frequency at which maximum response occurs for a frequency dependent system. The resonant frequency can be found from the impedance which is what we're doing to find the optimal controls.
    • I've updated the gain calculation scripts and documentation to follow this convention in this PR and PR 1553.
  • I'm not exactly sure on the latching and declutching. I think taking the latching/declutching time as half the difference between the wave period and resonant period is more of an estimate. The fact that the system is moving at different velocities due to the latching/declutching means the dynamics are changed and the optimal time is not so simple. There may be better optimal time calculations such as from Babarit, Clement.

@MShabara
Copy link
Contributor Author

@jtgrasb

Thanks for this clarification, I think the explanation you mentioned in the first point should be added in the documentation as well in PR 1553

Correct me if I’m wrong, but my understanding of regular vs. regularCIC is as follows:

regularCIC simulates a single-frequency component extracted from a wave spectrum (with multiple frequencies), using a smooth ramp (CIC envelope) to study the body’s time-domain response to that frequency.
regular represents a single-frequency sinusoidal wave applied directly at full amplitude, typically for steady-state or RAO analysis.

If this is correct, it worth adding it to the PR too. The difference between them is not clearly documented in WEC-Sim.

Then when using regular, the natural frequency coincides with the resonant frequency. For regularCIC, however, they will not necessarily be the same. Therefore, in the optimalGainCalc function, we should modify the calculations to use $m_\infty$ instead of $m(\omega)$, since the example case corresponds to regularCIC.

@jtgrasb
Copy link
Contributor

jtgrasb commented Sep 11, 2025

@MShabara Yes, I believe your explanation is correct. A regular wave is a purely linear based on the velocity and radiation damping coefficient at a single frequency. A regularCIC wave uses the convolution integral (which takes into account the entire spectrum) and infinite frequency added mass. I think these are already described in the code structure section, but it could definitely be improved.

However, the impedance representation is still accurate for either wave type and the result in terms of resonance is still the same. To show this, I ran optimalGainCalc using regular (normal added mass) and regularCIC (infinite frequency added mass) and ran the gain sweep:
regular:
KpOpt = 883448.343745
image

regularCIC:
KpOpt = 931317.176371
image

When using the infinite frequency added mass, the predicted optimal gain is not accurate to the actual optimal gain.

@jtgrasb jtgrasb merged commit 2d75692 into WEC-Sim:main Sep 17, 2025
3 checks passed
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