Skip to content

Conversation

@akeeste
Copy link
Contributor

@akeeste akeeste commented Apr 10, 2024

This PR addresses issue #1201 and the discussion in https://github.com/WEC-Sim/WEC-Sim_Team/discussions/89 by allowing users to define multiple hydrodynamic datasets and switch between them during simulation as the operational state of a device changes.

Major changes in this PR:

  • WECSim_Library_BodyElements.slx:
    • adds From flags that hold an index (body1_hydroForceIndex, etc) which the user can define in their switching logic.
    • creates a separate Variable Hydrodynamics block which controls importing body.hydroForce into Simulink. This is a variant subsystem so that in the case of 1 h5File (as was previously supported), the library behavior is simplified.
  • bodyClass.m
    • adds an index for the hydroForce dataset at equilibrium. body.hydroForceIndexInitial
    • Makes every instance of body.h5File a cell array of strings
    • Makes every instance of body.hydroData an array of structures, with each structure retaining the previous format
    • Makes every instance of body.hydroForce a structure containing the previous hydroForce structure format. This nested structure is required to import the entire dataset as a bus in Simulink.
  • initializeWecSim.m
    • whenever functions are called on body.hydroData, loop through the entire array of hydroData structs
    • create buses for each hydro body
    • create variable hydro variant subsystems for each hydro body
  • struct2bus.m
    • modified from answer on this thread
    • creates a bus from nested structures so that body.hydroForce can be loaded into Simulink in its entirety.
    • Called for each body as the format of body.hydroForce can vary with GBM, mean drift, etc

Minor changes in this PR:

  • responseClass.m and postProcessWecSim.m
    • saves the hydroForceIndex to the responseClass for visualization
  • addDefaultPlotVars.m
    • Minor bug fix
  • wecSimMCR.m and initializeWecSim.m
    • renames saved MCR hydroData to prevent conflicts

TODO list, roughly in suggested order

  • Allow variable hydrodynamics in bodyClass.m
  • Allow variable hydrodynamics in Body library
  • Add initial value for hydroForceIndex that does not change
  • Allow the hydroForceIndex to change in the library so that users can control switching
  • Update mask initialization to select the default hydroForce based on body.hydroForceIndexInitial
  • Allow different bodies to contain different numbers of h5Files
  • Allow variableHydro.option to be body dependent. This seems to be breaking due to the bus set-up
  • Allow displaced volume and centerBuoyancy to vary with hydroForce. These are copied to hydroForce and applied from there during the simulation
  • Allow quadratic drag and linear damping to vary with hydroForce?
  • Adding switching logic example
  • Fix added mass post-processing
  • Add global GoTo blocks for body forces, constraint forces, time
  • Evaluate the model instability when switching between different h5files --> see Variable hydro demonstrations WEC-Sim_Applications#65
  • Validate a case study (passive yaw can highlight benefits/drawbacks of VH vs another advanced feature) --> see Variable hydro demonstrations WEC-Sim_Applications#65
  • Add documentation

Future work:

  • Time varying mass and inertia
  • Enable variable hydro with the state space and FIR filter blocks --> TBD, this may not be possible. Requires setting a mask variable through a port.
  • Additional applications (large amplitude sphere, VG OSWEC)

@kmruehl
Copy link
Collaborator

kmruehl commented Apr 24, 2024

Based on @dav-og suggestion, consider including passive yaw as use case and deprecating the current passive yaw implementation

@akeeste
Copy link
Contributor Author

akeeste commented Apr 24, 2024

One follow-up on passive yaw-- A feature that passive yaw has that is not currently planned here is interpolation between data points. Passive yaw (I believe) will interpolate between directions if past the threshold. We were not planning that here since right now the user-defined switching parameter is not a dimension of each hydroForce array. That may be possible, but the implementation will definitely be more complicated. We were planning to force the user to include as much state discretization as is required ahead of time.

@dav-og
Copy link
Contributor

dav-og commented Apr 24, 2024

Thats correct, passive yaw interpolates hydrodynamic coefficients between headings - for a user-defined threshold. The results can change a lot depending on this threshold - but if you set it very low then the computation time explodes. User has to evaluate this speed-accuracy trade off.

For passive yaw, the hydrostatic stiffness matrix is rotated with the body in WEC-Sim

@akeeste
Copy link
Contributor Author

akeeste commented Jun 5, 2024

FYI I've been reading briefly on methods to accomplish this hydrodynamics variation. This post and this older post both describe pathways and limitations of how we can implement this feature with minimal changes.

The possible methods seems to be the following. Based on my initial research, I suggest the following order of preference based on what I've read:

  • Load the entire list of structures contained in body.hydroForce into the simulation. Then we may be able to treat it as a bus signal, then index and pull out the relevant signal based on the user defined hydroForceIndex
  • Use parameter writer to change the value of the constant blocks loading
  • Make the force coefficients a signal instead of a constant. This seems overkill and complicated since we only want to select the index of the hydroForce struct, not control the data within each hydroForce struct during simulation

@akeeste
Copy link
Contributor Author

akeeste commented Jun 6, 2024

I made some nice progress on this PR lately by turning the body.hydroForce structure into a bus signal. All data nested within body.hydroForce can be loaded once as a constant in the simulation. The data to use at a given time can be indexed using a signal defined by the user. Some progress left to go, but this is a big step in moving this PR forward.

test_v2.zip

@akeeste
Copy link
Contributor Author

akeeste commented Jun 6, 2024

Going the library I noticed that regular wave excitation (both with and without passive yaw ) does not handle directional spreading and probably should. It only takes the first directional component of the excitation force.

@akeeste
Copy link
Contributor Author

akeeste commented Jun 10, 2024

Excitingly, I got this feature working for a basic case now! I temporarily edited the RM3 example model and input files to run when importing the a set of 3 h5files into the same body. There a few more complex cases to test/implement next which I added to the TODO list above.

@akeeste
Copy link
Contributor Author

akeeste commented Jun 12, 2024

Comment from @MShabara - we may want to reference the buffered fourier spectral method to address unstable switching in this feature

@akeeste
Copy link
Contributor Author

akeeste commented Jul 26, 2024

Recording a few recent updates:

Right now the implementation mostly works but has a couple odd edge cases that should work but don't. I'm working through fixes for these edge cases.

Working scenarios:

  • all bodies use variable hydro (``body.variableHydro.option=1) and each has multiple h5Files.
  • no bodies use variable hydro

Breaking scenarios:

  • some but not all bodies use variable hydro
  • a body with variable hydro has only one h5 file

@akeeste
Copy link
Contributor Author

akeeste commented Jul 31, 2024

Summarizing a discussion that @salhus and I had on this feature:

An important but currently missing aspect of this PR is how to treat the CG, mass, and inertia if a body state changes. E.g if a device is flooded, its cg, mass, and inertia all change. Simscape may allow a time-varying inertia tensor through the general variable mass block

@kmruehl
Copy link
Collaborator

kmruehl commented Sep 5, 2024

@akeeste the merge conflicts are resolved, but do you know why the tests are failing?

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.

It looks like there is one file that should be removed from this PR

@kmruehl
Copy link
Collaborator

kmruehl commented Sep 5, 2024

@akeeste the merge conflicts are resolved, but do you know why the tests are failing?

@akeeste the tests are throwing a warning when the Simulink files are copied, and the MATLAB version doesn't match. This happens in C:\Users\kmruehl\Documents\GitHub\WEC-Sim\WEC-Sim\tests\runFromSimTest.m lines 34-37

            copyfile(fullfile(testCase.wsDir,'/examples/RM3FromSimulink/RM3FromSimulink.slx'),...
                fullfile(testCase.runFromSimDir,'fromSimInput.slx'));
            copyfile(fullfile(testCase.wsDir,'/examples/RM3FromSimulink/RM3FromSimulink.slx'),...
                fullfile(testCase.runFromSimDir,'fromSimCustom.slx'));   

However, the error is due the following:

    ---------
    Error ID:
    ---------
    'MATLAB:num2str:nonNumericInput'
    --------------
    Error Details:
    --------------
    Error using num2str (line 24)
    Input to num2str must be numeric.
    
    Error in writeBlocksFromInput (line 160)
            values{i,1} = num2str(maskVars.(names{i,1}));
    
    Error in loadInputFileCallback (line 40)
                writeBlocksFromInput(blockHandle,type,inputFilePath);
    
    Error in runFromSimTest/setupInputFiles (line 81)
                        loadInputFileCallback(grfBlockHandle);

maskVars.(names{i,1}) is not numeric

@akeeste
Copy link
Contributor Author

akeeste commented Sep 5, 2024

@kmruehl I saw these tests failures yesterday. In short, no I don't yet know why. I did not touch any WEC-Sim GUI or Run From Simulink functionality. I'm guessing there was a problem coming from library changes in main that were pulled into dev, and then into my branch

@akeeste
Copy link
Contributor Author

akeeste commented Sep 5, 2024

@kmruehl The WEC-Sim GUI issue should be resolved pending the test completion. I thought the bug was coming from a library merge that I messed up because a non-variable hydro case was failing. But the issue was on my development efforts--related to body.h5File becoming a cell which is not allowed in a mask

@kmruehl
Copy link
Collaborator

kmruehl commented Sep 5, 2024

@akeeste thanks for the update, looks like all tests are passing now. Thanks!

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 thanks again for your help resolving the tests. Everything looks good, but I'm going to go. I'm going to go through it myself one more time before merging.

@kmruehl kmruehl added Feature new feature request BEM/BEMIO related to BEMIO or BEM hydro data Body Class Body Class (bodyClass.m) labels Sep 5, 2024
@kmruehl kmruehl merged commit 2a98d34 into WEC-Sim:dev Sep 5, 2024
@akeeste akeeste deleted the variableHydro branch September 6, 2024 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BEM/BEMIO related to BEMIO or BEM hydro data Body Class Body Class (bodyClass.m) Feature new feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants