Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 0 additions & 159 deletions MoorDyn.h

This file was deleted.

132 changes: 132 additions & 0 deletions MoorDyn2WS.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright (c) 2022, Matt Hall
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

/** @file Moordyn2.h
* C API for the moordyn::MoorDyn object, which is the main simulation handler
*/

#ifndef __MOORDYN2_H__
#define __MOORDYN2_H__

#include "MoorDynAPI.h"
/* #include "Waves.h"
#include "Seafloor.h"
#include "Point.h"
#include "Rod.h"
#include "Line.h"
#include "Body.h"
#include <stdlib.h>
#include <stdint.h>*/

#ifdef __cplusplus
extern "C"
{
#endif

#ifdef WIN32
#include <windows.h>
#endif

/** @defgroup new_c_api The C API
* @{
*/

/// A mooring system instance
typedef struct __MoorDyn* MoorDyn;

/** @brief Creates a MoorDyn instance
*
* At the time of creating a new MoorDyn instance, the input file is read
* and all the objects and structures are created. You must call afterwards
* MoorDyn_Init() to compute the initial conditions
*
* @param infilename The input file, if either NULL or "", then
* "Mooring/lines.txt" will be considered
* @return The mooring instance, NULL if errors happened
*/
MoorDyn DECLDIR
MoorDyn_Create(const char* infilename);

/** @brief Compute the initial condition of a MoorDyn system
*
* At the time of creating a new MoorDyn instance, the input file is read
* and all the objects and structures are created. You must call afterwards
* MoorDyn_Init() to compute the initial conditions
*
* @param system The Moordyn system
* @param x Position vector (6 components per coupled body or cantilevered
* rod and 3 components per pinned rod or coupled point)
* @param xd Velocity vector (6 components per coupled body or cantilevered
* rod and 3 components per pinned rod or coupled point)
* @return MOORDYN_SUCESS If the mooring system is correctly initialized,
* an error code otherwise (see @ref moordyn_errors)
* @note MoorDyn_NCoupledDOF() can be used to know the number of components
* required for \p x and \p xd
*/
int DECLDIR
MoorDyn_Init(MoorDyn system, const double* x, const double* xd);

/** @brief Runs a time step of the MoorDyn system
* @param system The Moordyn system
* @param x Position vector
* @param xd Velocity vector
* @param f Output forces
* @param t Simulation time
* @param dt Time step
* @return MOORDYN_SUCESS if the mooring system has correctly evolved, an
* error code otherwise (see @ref moordyn_errors)
* @note MoorDyn_NCoupledDOF() can be used to know the number of components
* required for \p x, \p xd and \p f
*/
int DECLDIR
MoorDyn_Step(MoorDyn system,
const double* x,
const double* xd,
double* f,
double* t,
double* dt);

/** @brief Releases MoorDyn allocated resources
* @param system The Moordyn system
* @return MOORDYN_SUCESS If the mooring system is correctly destroyed, an
* error code otherwise (see @ref moordyn_errors)
*/
int DECLDIR
MoorDyn_Close(MoorDyn system);

/**
* @}
*/

#ifdef __cplusplus
}
#endif

#endif
9 changes: 0 additions & 9 deletions MoorDyn_caller.m

This file was deleted.

9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ If the MoorDyn files on this repository are not functioning on your system,
you should compile the code from source following the steps in the
[documentation](https://moordyn.readthedocs.io/en/latest/). MoorDyn will
automatically build with the right architecture for your system. Once you have
your local MoorDyn library and source code, replace `MoorDyn.h`,
`MoorDynAPI.h`, and the library file(s) (e.g., `libmoordyn.dll`) from this repo
with your local copy.
your local MoorDyn library and source code, replace the library file(s)
(e.g., `libmoordyn.dll`) from this repo with your local copy.

--------------------- MoorDyn v2.4.0 -------------------------

Expand Down Expand Up @@ -68,7 +67,7 @@ data,î Ocean Engineering, vol. 104, pp. 590ñ603, Aug. 2015.

**Mac architecture issue:**

If WECSim on Mac gives architecture errors when running MoorDyn similar to:
If WEC-Sim on Mac gives architecture errors when running MoorDyn similar to:

Error using wecSim (line 46)
There was an error loading the library "WEC-Sim/source/functions/moorDyn/libmoordyn.dylib"
Expand All @@ -80,6 +79,6 @@ If WECSim on Mac gives architecture errors when running MoorDyn similar to:

then you have a mismatch between the MoorDyn compiled architecture and your system architecture. To resolve this, double check you copied and renamed the `.dylib` corrsponding to your system into the `WEC-Sim/source/functions/moorDyn` folder.

If that doesnt work, you should compile the code from source following the steps in the [documentation](https://moordyn.readthedocs.io/en/latest/). MoorDyn will automatically build with the right architecture for your system. Once you have your local MoorDyn library and source code, replace `MoorDyn.h`, `MoorDynAPI.h`, and `libmoordyn.dylib` from this repo with your local copy. The `.h` files can be found in `MoorDyn/source/`, and the library files can be found in `MoorDyn/build/source/`.
If that doesnt work, you should compile the code from source following the steps in the [documentation](https://moordyn.readthedocs.io/en/latest/). MoorDyn will automatically build with the right architecture for your system. Once you have your local MoorDyn library and source code, replace `MoorDyn2.h` (and other linked .h files), `MoorDynAPI.h`, and `libmoordyn.dylib` from this repo with your local copy. The `.h` files can be found in `MoorDyn/source/`, and the library files can be found in `MoorDyn/build/source/`.

Note: to force MoorDyn to compile for a different architecture, add the `-DCMAKE_OSX_ARCHITECTURES=<insert architecture>` to your cmake call.
10 changes: 10 additions & 0 deletions moordynCaller.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function lineForces = moordynCaller(disp,vel,time,dt)
% function calls MoorDyn library to calculate and return the mooring
% line forces at every time step.
mdStruct = evalin('base','mdStruct');
Copy link

Choose a reason for hiding this comment

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

Same comment about evalin and base workspaces as in WEC-Sim/WEC-Sim#1566

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mdStruct is a libpointer. These cannot be loaded into Simulink. The best alternative I found is to use evalin here to load it into the MATLAB function. A couple other options I found seem to be to declare it as a global variable or us an S-function in Simulink, which both seemed like worse options. We could also go back to v1 API and the MoorDyn team may be able to edit the source to avoid the graphics popup window.

lineForces = zeros(1,length(disp));
lineForcesPtr = libpointer('doublePtr',lineForces);
calllib('libmoordyn', 'MoorDyn_Step', mdStruct, disp, vel, lineForcesPtr, time, dt);
lineForces = lineForcesPtr.value;
clear lineForcesPtr
end