-
Notifications
You must be signed in to change notification settings - Fork 8
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
Default sprectral weighting #137
Conversation
also remove now unnecessary warning toggle
I think this is a good idea, as it looks a bit shonky having an example that triggers our own warning. Before I review this, though, I would like to suggest a couple of things to add value to the PR:
I'm not totally sold on the second suggestion, but I think the first one would be a useful improvement from this PR, beyond tidying up the example. |
I completed 2 with cf7747c and a version of 1 with 705da40. "version of 1:" I moved the checking for Additionally, I added some unit tests for this functionality to |
I'll try and get the review of this done before our meeting tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so there is an issue that checkSpectrum doesn't return the fixed spectrum, so when you run the example with a WAFO generated spectra it bugs out:
Running study...
Reference to non-existent field 'mu'.
Error in WecOptLib.models.DeviceModelTemplate/getPower (line 155)
mus(iSS) = S.mu;
Error in WecOptTool.run/obj (line 69)
pow = -1 * RM3Device.getPower(study.studyDir, ...
Error in fmincon (line 562)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in WecOptTool.run (line 93)
[sol,fval,exitflag,output] = fmincon(@obj, ...
Error in example (line 62)
WecOptTool.run(study, options);
Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.
The name checkSpectrum has also become a bit weird in that it fixes the spectra as well as checks them. My personal preference would be to have checkWeightingsPresent
as standalone function rather than rolling it into checkSpectrum and change its name to be clearer that it's going to change the input.
@@ -21,9 +21,12 @@ | |||
function SS = example8Spectra | |||
%EXAMPLE8SPECTRA Example Bretschneider spectrum with varying HHm0s, Tps, | |||
% Nbins, and range | |||
|
|||
% load data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a superfluous comment. Remove or edit the docstring, if necessary.
inds = 1:length(S); | ||
|
||
% check if there are no weightings, if necessary populate and warn | ||
S = checkWeightingsPresent(S); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this to be useful S must be returned by checkSpectrum
% S.S column vector of spectral density in [m^2 rad/ s] | ||
% | ||
% Outputs | ||
% (none) (will throw error if not valid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would need changed if S is returned
% WecOptTool is distributed in the hope that it will be useful, | ||
% but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
% GNU General Public License for more details. | ||
% | ||
% | ||
% You should have received a copy of the GNU General Public License | ||
% along with WecOptTool. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
function [] = checkSpectrum(S) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if checkSpectrum is the correct name for this now if it does two jobs, checking and fixing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, but I actually do prefer that its just one function call to do both
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I am going to push you on this, but not just because it's nasty to have one function with two purposes (ick). I'm most worried that, as we change to the new structure, there is a risk that this function ends up back inside the optimisation loop without the spectra being corrected first, rendering the original purpose of stopping the warning showing up in every iteration moot.
If we have an explicit function that fixes the mu prior to use in any optimisation that the user creates, then checkSpectrum can simply generate an error if it's not set (for more than one spectrum), which is its typical behaviour, allowing it to be safely used anywhere in the code. Does that make sense?
end | ||
end | ||
|
||
function [S] = checkWeightingsPresent(S) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making this a standalone function, then checkSpectrum doesn't need to return S and it's purpose remains clear. I think the name could be changed as well, to something like "fixWeightings", just to show that it changes the input.
.mat files added to #161 |
Description
I found the toggling of warnings in the example file particularly offensive for some reason :), so I made changes to set the equal weighting of the example spectra. This relates to #108, although does not close it.
Fixes (none)
test_results.pdf
Checklist:
example.m
has been modified, the content / line numbers indocs\user\example.rst
are still valid or have been fixed