WEC-Sim Library

The WEC-Sim Library is in the $WECSIM/source/lib directory, and includes the following files:

Simulink Library

File name

WEC-Sim Library

WECSim_Lib.slx

Frames Sublibrary

WECSim_Lib_Frames.slx

Body Elements Sublibrary

WECSim_Lib_Body_Elements.slx

Constraints Sublibrary

WECSim_Lib_Constraints.slx

PTOs Sublibrary

WECSim_Lib_PTOs.slx

Cables Sublibrary

WECSim_Lib_Cables.slx

Moorings Sublibrary

WECSim_Lib_Moorings.slx

GitHub tracks when a change is made to a binary file (e.g. *.slx), but not the specific revisions made. This makes tracking revisions to the WEC-Sim Library more challenging than revisions to text files (e.g. *.m). The WEC-Sim Library is saved as a Custom Simulink Library with sublibaries. To ensure backwards compatibility, a Forwarding Table is used.

Formatting

Please format the color of library blocks according to their function:

Library Function

Color

Input

Green

Output

Red

From Workspace

Yellow

Simulink Function

Orange

Subsystem

Gray

Linked Block

Light Blue

../_images/library_format.png

WEC-Sim Library blocks with color formatting

Library Development

When masks are modified, Simulink executes the mask initialization code. If Simulink does not have access to the WEC-Sim objects in the Simulink workspace, Simulink will throw an error message and would not allow any changes.

In order to modify blocks masks the variable being modified must be accesible to Simulink’s workspace. This can be acheived by running any wecSimInputFile.m script without executing WEC-Sim. Running the wecSimInputFile.m script populates the MATLAB worskpace with the pertinent data objects using WEC-Sim’s class definitions. This enables the block masks to have access to the properties and methods for the pertinent class (e.g., bodyClass, waveClass etc.).

Simulink then executes each block mask’s initialization code before accepting any changes. Some of the WEC-Sim library blocks auto-generate additional blocks based on the wecSimInputFile.m script. To ensure that the library block auto-generates such blocks only when WEC-Sim is run, make sure to delete the auto-generated blocks before saving the modified block to the WEC-Sim library.

Note

This is especially important for the Wave Markers and for B2B

MATLAB Merge Tool

It is recommended that developers use the MATLAB Merge Tool to compare library versions when there are merge conflicts. The MATLAB Merge Tool allows users to compare changes directly in Simulink. The merge tool will open a special Simulink GUI that allows users to compare code versions both textually and within the block diagram. To use the tool, merge both branches locally and resolve any conflicts using the merge tool.

For example, take the branches <dev> and <new_feature> that each contain new WEC-Sim features. In the Git for Windows command line, these changes can be merged using:

# Checkout the <dev> branch and pull the latest
git checkout <dev>
git pull <remote>/<dev>

# Merge <new_feature> branch into <dev> branch
git merge <new_feature>

# Resolve library conflicts using the MATLAB merge tool
git mergetool -t mlMerge source/lib/WEC-Sim/<library_file>.slx

# Save desired revisions, then add and commit changes
git add source/lib/WEC-Sim/<library_file>.slx
git commit -m 'merge <dev> with <new_feature>'