-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: error creating wave if nfreq=1
#308
Comments
I forgot to mention that my current workaround is just to reshape in phases_float = degrees_to_radians(phases, False)
phases = np.reshape(phases_float,phases.shape)
assert phases.shape == (nfreq, ndirections, nrealizations) |
I think the reshape should be done for the input to We should add a test that uses a single frequency (not just for waves, for a whole problem). This used to work and then broke without us realizing it. |
By this do you mean the assert statement should be done before calling I'll start working on a test case as well. |
I think the issue was, it returns a float when the input was not a float, it was an ndarray of size (1,1,1). |
After looking into it more, I'm not sure that setting nfreq = 1 will give a reasonable answer. When nfreq = 1, the derivative matrix is [[0, 0] [0, 0]], which means the velocity (and therefore power) is always equal to zero. |
For optimizing power there is no optimal solution (always zero) but I guess you could have a different objective function that depends on position or acceleration instead. I think we should fix the size issue, but not do anything else since all our examples use power for the objective. |
Could you explain why velocity and power are always zero? If nfreq=1 corresponds to a regular wave where everything is linear and there is only one frequency present in all signals, it would seem to me that velocity and power could be well-defined signals at that frequency, the optimum would exist, and could be verified analytically since it's all linear. |
Oh I see, I think this was also partially the source of my confusion in #307. I originally assumed the conversion from freq domain to time domain would work like this:
But it seems like instead of a discrete sampling of the continuous inverse fourier transform, the PS method uses the discrete inverse fourier transform directly ( If I want to simulate (for the purpose of validating against analytical) a linear system where I know there will be nonzero harmonic content at only one frequency f, is it correct that the freq vector must consist of f and 2f, not just f, so that there are sample points at the right places in time to pick up the derivative? And if I want to simulate a system with a constraint, where I expect the solution to have odd harmonics of Is there a benefit of using the ifft, which appears to require frequency doubles to get accurate derivatives, compared to the way I misunderstood it to work, which would not? My experience in signals has been almost all continuous time, so sorry if I'm misunderstanding some nuance of discrete time. |
You would still need to sample the same number of points, else the problem would be over/under determined. So the number of frequency determines the number of collocation points. The only difference would be that you would not be limited to equally spaced points in time (cannot use the DFT). I am sure there are theoretical reasons why equally-spaced frequency and time steps & DFT are the best choice for some predetermined finite number of samples... but I don't have a good explanation. The derivative components of the highest frequency are always zero, so your last frequency needs to be larger than the largest frequency you want to use for the derivative (not just the main signal: position). I don't believe you need to include double the frequency of each harmonic you are interested in. |
Ok, I think that makes sense now. My reasoning for the factor of two thing was this:
|
I don't think that's right. You don't need points at the troughs/peaks for every frequency (see n=3 in image above). And for all frequencies (except the largest) you have more than just two points per period. The "issue" with the Nyquist frequency is that there are only two points per period and they fall at the peak/trough, so the derivative is zero at all the collocation points for that frequency. This is the true value, and is not an issue, except if you try to use only one frequency and have an objective that depends on the derivative. In general you just need your final frequency to be larger than the largest frequency you want to use for the derivative. |
Describe the bug
Attribute error when creating waves with
nfreq=1
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Runs without error.
Observed behavior
WecOptTool 2.6.0: runs without error
newest commit: attribute error
System:
Additional information
Seems like this was introduced when the assert statement was added in #297
The root cause seems to be that
degrees_to_radians
outputs a float instead of a np array when the input size is (1,1,1) as it is here.Relevant source code in
waves.py
:The text was updated successfully, but these errors were encountered: