Skip to content

Conversation

@akeeste
Copy link
Contributor

@akeeste akeeste commented Mar 26, 2021

This PR expands upon @jhbates work (PR #512) and allows WEC-Sim to run from Simulink.

There are now five ways to run WEC-Sim (two additional):

  1. 'wecSim' in command line. Uses standard wecSimInputFile.m
  2. 'wecSimInitFunction' in command line + running in Simulink using custom parameters (no input file)
  3. 'wecSimInitFunction' in command line + running in Simulink and loading an input file
  4. 'wecSimMCR' in command line
  5. 'wecSimPCT' in command line

If starting in Simulink (2,3 above), the user must run the new WEC-Sim pre-processing command 'wecSimInitFunction' prior to running every simulation. This extra step avoids a previously mentioned bug in R2020b. MCR and PCT can be used with the command line, but currently not when running WEC-Sim from Simulink. Regardless of the run method used, the WEC-Sim post-processing is run as the Global Reference Frame's stop function callback in Simulink.

Custom parameters may be set inside of the Simulink file using the mask for each WEC-Sim block. The masks currently contain most (but not every) options available in the text-based input. Whether the Simulink model runs an input file or uses custom parameters is determined by a single Global Reference Frame mask setting. This currently defaults to using an input file. Additionally, if custom parameters are used and WEC-Sim is run from Simulink then the mask parameters are written to a 'wecSimInputFile_simulinkCustomParameters.m' which is used for that simulation. To make initializing custom mask parameters easy, there is a button in the Global Reference Frame that prepopulates mask values using a previous input file.

New files

  • wecSimInitFunction - contains all wecSim.m pre-processing (before former wecSim.m line with sim(simulinkModel)...)
  • wecSimStopFunction - contains all wecSim.m post-processing (after former wecSim.m line with sim(simulinkModel)...)
  • SimulinkModelFunctions directory - contains all mask callback functions

This PR passes all continuous integration tests and also works with the various application case tests in PR #508. It should have the same backwards compatibility as the current dev branch does.

@yuyihsiang Can you test this PR with wecSimPCT? I have tested with MCR but do not have the parallel computing toolbox installed.
@jleonqu I believe you looked at this work a bit previously. Can you take a look at this PR generally and let me know your suggestions?

jhbates and others added 30 commits January 20, 2021 15:51
These functions are used as the Init and Stop functions of the Simulink file as well as all callbacks in the masked subsystem Parameters.
The system was designed to allow for the simulation to be ran from the Simulink file itself. This Simulink file contains a masked subsystem used to load input parameters for the simulation. There are two options for creating the parameters, load from input file or custom parameters.
Update allowing simulations ran from Simulink file #503
Merge my updates into the new feature branch
Copy link
Contributor

@jleonqu jleonqu left a comment

Choose a reason for hiding this comment

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

I liked the way you implemented this feature in Simulink, it is very convenient, easy to use, easy to understand, and very useful. Regarding MCR, I think it's not a big deal if you have to run the simulation with the command line, actually I prefer that way when I am running multiple simulations with the same model because for me it is easy to adjust the multiple runs using a Matlab script.

Just as a comment, the changes worked when I used Matlab 2020b, but they didn't work with Matlab 2021a (I had the same issue described in #546 ), which I think make sense, since #553 has not been merge into master.

@kmruehl kmruehl self-requested a review May 21, 2021 21:08
@kmruehl kmruehl removed the request for review from yuyihsiang June 4, 2021 20:24
Copy link
Collaborator

@kmruehl kmruehl left a comment

Choose a reason for hiding this comment

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

@akeeste this should be ready for your final review. Here are my notes:

  • updated docs to add Running from Simulink to advanced features and simplified workflow/examples
  • changed wecSimInitFunction to wecSimInitialize
  • added to .gitignore
  • added brief section on wecSimFcn related to #598

@akeeste To Do:

  • add custom WEC-Sim error if run from Simulink by hitting play and haven't executed wecSimInitialize
  • open issue or project to see if we can run from Simulink by hitting play (and run executing wecSimInitialize)

@kmruehl kmruehl linked an issue Jun 4, 2021 that may be closed by this pull request
@akeeste
Copy link
Contributor Author

akeeste commented Jun 4, 2021

@kmruehl I am ready to merge. I added a few small fixes and created project board cards for the last two items:
https://github.com/WEC-Sim/WEC-Sim/projects/53#card-62514170
https://github.com/WEC-Sim/WEC-Sim/projects/53#card-62514133

@kmruehl
Copy link
Collaborator

kmruehl commented Jun 7, 2021

@akeeste thank you! I made a minor revision and now I'm merging into dev

@kmruehl kmruehl merged commit 70453e2 into dev Jun 7, 2021
@kmruehl kmruehl deleted the feature_simulink_run branch June 7, 2021 16:29
@kmruehl kmruehl mentioned this pull request Jun 8, 2021
2 tasks
@kmruehl kmruehl linked an issue Jun 8, 2021 that may be closed by this pull request
2 tasks
@akeeste akeeste removed a link to an issue Jun 8, 2021
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature new feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Theory or Implementation]

5 participants