MoorDyn
MoorDyn copied to clipboard
Compile Moordyn And use it with Matlab
Hello,
I would like to use moorDyn and Map++ separately (don't include it in the OpenFAST code). I would like to plotted the anchor lines. However I can't generate the DLL file. Usually I use visual studio 2017 and the nmake command. Could you share the process to be able to use these codes with matlab or python?
Best Regards,
Hi, in Windows I usually use MinGW and its "minGW32-make", with the makefiles that are included in the MoorDyn repo. Interacting with the DLL from Python or Matlab is the same as interacting with any other DLL from those languages.
I still need to get proper Matlab and Python examples into the documentation but here are examples that arose from the issues discussion: Matlab: https://github.com/mattEhall/MoorDyn/issues/9 Python: https://github.com/mattEhall/MoorDyn/issues/5
The v2 candidate has a Matlab wrapper, based on mex files, which is blazzing. Unfortunately, it is totally impossible to build that wrapper automatically in a github action, so no binaries will be provided. That means you have to compile MoorDyn by yourself to get Matllab support. The process is documented here
An example of a Matlab script can be found here
P.S. You are welcome to support this v2 candidate in the same PR link:
So it will be merged ASAP. You can also leave your feedback
Hi,I have a problem about v2 candidate. When I configure moordyn, it shows that the source directory "C:/MoorDyn/MoorDyn" does not appear to contain CMakeLists.txt. So,I want to know where to find the CMakeLists.txt.
CMakeLists.txt is in the root folder of MoorDyn. I suspect you have not cloned/downloaded the v2 candidate:
https://github.com/mattEhall/MoorDyn/tree/v2
But the v1:
https://github.com/mattEhall/MoorDyn
Can you check that? (They have radically different folders and files)
I do used the v1 files, thank you so much. And now I have a new question, when I generate moordyn, it shows that target "moordyn" requires the language dialect "CXX17" (with compiler extensions). But the current compiler "GNU" does not support this, or CMake does not know the flags to enable it. Maybe you know how to solve it?
MinGW absolutely supports -std=c++17. Can you tell me which version do you have? How did you install it?
Can you also paste here the exact output of cmake?
I reinstalled the MinGW (from githup ,version :x86_64-12.2.0-release-win32-seh-rt_v10-rev1.7z)and added the path.
Then it worked, thank you again. But when I use a cmd with administrative rights , it produces errors. How should I solve this?
First, do not crop the output, it makes way harder to analyze the problem. On top of that, text is better than image.
MoorDyn is compiling just fine. Apparently it is failing while building the Python wrapper. So I suggest you to just disable it (PYTHON_WRAPPER=OFF in CMake)
I got it, thank you very much.
Can we close this?
@sanguinariojoe
Hi, I want to call the Moordyn program on windows using matlab. I was following this tutorial[1], and there was a problem compiling the MoorDyn input mingw32-make
in cmd as Administrator. The output was:
In file included from E:/MATLAB/R2021a/extern/include/mexAdapter.hpp:18,
from D:\Desktop\MoorDyn\MoorDyn\wrappers\matlab\MoorDynM_Close.cpp:32:
E:/MATLAB/R2021a/extern/include/cppmex/detail/mexApiAdapterImpl.hpp: In function 'void {anonymous}::set_eval_promise_data(void*)':
E:/MATLAB/R2021a/extern/include/cppmex/detail/mexApiAdapterImpl.hpp:429:13: error: invalid use of incomplete type 'class std::promise<void>'
429 | prom->set_value();
In file included from E:/MATLAB/R2021a/extern/include/cppmex/mexFuture.hpp:9,
from E:/MATLAB/R2021a/extern/include/cppmex/mexMatlabEngine.hpp:13,
from E:/MATLAB/R2021a/extern/include/mex.hpp:80,
from D:\Desktop\MoorDyn\MoorDyn\wrappers\matlab\MoorDynM_Close.cpp:31:
E:/mingw64/lib/gcc/x86_64-w64-mingw32/12.2.0/include/c++/future:134:11: note: declaration of 'class std::promise<void>'
134 | class promise;
...
...
mingw32-make[2]: *** [wrappers\matlab\CMakeFiles\MoorDynM_Close.dir\build.make:76: wrappers/matlab/CMakeFiles/MoorDynM_Close.dir/MoorDynM_Close.cpp.obj] Error 1
mingw32-make[1]: *** [CMakeFiles\Makefile2:1089: wrappers/matlab/CMakeFiles/MoorDynM_Close.dir/all] Error 2
mingw32-make: *** [Makefile:165: all] Error 2
Line 76 of MoorDynM_Close.dir\build.make
is :
cd /d D:\Desktop\MoorDyn\MoorDyn.build\wrappers\matlab && E:\mingw64\bin\c++.exe $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -MD -MT wrappers/matlab/CMakeFiles/MoorDynM_Close.dir/MoorDynM_Close.cpp.obj -MF CMakeFiles\MoorDynM_Close.dir\MoorDynM_Close.cpp.obj.d -o CMakeFiles\MoorDynM_Close.dir\MoorDynM_Close.cpp.obj -c D:\Desktop\MoorDyn\MoorDyn\wrappers\matlab\MoorDynM_Close.cpp
Thanks very much for your help.
[1] https://github.com/sanguinariojoe/MoorDyn/blob/v2/docs/starting.rst#compile-and-install-moordyn
Hey @xdd1997 !
This is not a problem on MoorDyn, but on Matlab (or eventually on MinGW). I will anyway give it a shot as soon as I can find a windows machine with Matlab
I have Matlab R2021b:
On MSYS I have installed mingw-w64-x86_64-toolchain as well as the suggested packages mingw-w64-x86_64-python-setuptools
and mingw-w64-x86_64-python-pip
Then I ran the CMake with the following options:
Then on the cmd I navigated to the building folder and typed mingw32-wmake
:
I'll wait anyway till the compilation finish, because I actually implemented many functions to the wrapper that I could not check.
@xdd1997 I uploaded a couple of fixes to https://github.com/sanguinariojoe/MoorDyn/tree/v2, but the compilation is working to me with the steps discussed above
Thank you for your help. I have successfully compiled many *.mexw64
files, and copied these *.mexw64
files and libmoordyn.dll
file to the project path. The demo can run smoothly now.
I suggest you to modify this part of the tutorial[1] as my error started from this point:
I was unable to obtain the mimgw32-make.exe
program with the above command, so I obtained the mingw64 program through the link[2] However, the error I mentioned earlier occurred.
I finally managed to compile it by typing pacman -S mingw-w64-x86_64-toolchain
in MSYS2 MINGW64.
Anyway, thank you again for your help.
[1] https://github.com/sanguinariojoe/MoorDyn/blob/v2/docs/starting.rst#compile-and-install-moordyn [2] https://www.mingw-w64.org/downloads/#mingw-builds.