### Fortran API: Initialize and Get Point Information Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/drivers.rst Fortran example showing system creation, checking degrees of freedom, and retrieving point information. Uses intrinsic modules for ISO_FORTRAN_ENV and ISO_C_BINDING. ```fortran program main use, intrinsic :: iso_fortran_env, only: real64 use, intrinsic :: iso_c_binding, only: c_ptr, c_associated use moordyn character(len=28) :: infile real(real64), allocatable, target :: x(:) real(real64), allocatable, target :: xd(:) real(real64), allocatable, target :: f(:) real(real64), allocatable, target :: r(:) real(real64) :: t, dt integer :: err, n_dof, n_points, i_point, n_lines, i_line, n_nodes, i_node type(c_ptr) :: system, point, line infile = 'Mooring/lines.txt' system = MD_Create(infile) if ( .not.c_associated(system) ) then stop 1 end if err = MD_NCoupledDOF( system, n_dof ) if ( err /= MD_SUCESS ) then stop 1 elseif ( n_dof /= 9 ) then print *, "3x3 = 9 DOFs were expected, not ", n_dof end if allocate ( x(0:8) ) allocate ( xd(0:8) ) allocate ( f(0:8) ) allocate ( r(0:2) ) xd = 0.0 f = 0.0 ! Get the positions from the points err = MD_GetNumberPoints( system, n_points ) if ( err /= MD_SUCESS ) then stop 1 elseif ( n_points /= 6 ) then print *, "6 points were expected, not ", n_points end if do i_point = 1, 3 point = MD_GetPoint( system, i_point + 3 ) ``` -------------------------------- ### Install Catch2 from Git Repository Source: https://github.com/floatingarraydesign/moordyn/blob/master/extern/Catch2/docs/cmake-integration.md Use these commands to clone the Catch2 repository, configure the build with CMake, and install it. Set BUILD_TESTING to OFF to exclude tests from the installation. ```bash $ git clone https://github.com/catchorg/Catch2.git $ cd Catch2 $ cmake -Bbuild -H. -DBUILD_TESTING=OFF $ sudo cmake --build build/ --target install ``` -------------------------------- ### MoorDyn V2 Input File Structure Example Source: https://context7.com/floatingarraydesign/moordyn/llms.txt A complete working example of a MoorDyn V2 input file. Sections are defined by dash-surrounded keywords, and comments start with '#'. ```text --------------------- MoorDyn Input File ------------------------------------ Three-line catenary mooring system, 150 m depth ---------------------- LINE TYPES ----------------------------------------------- TypeName Diam Mass/m EA BA/-zeta EI Cd Ca CdAx CaAx (name) (m) (kg/m) (N) (N-s/-) (N-m^2) (-) (-) (-) (-) Chain 0.1 150.0 1e8 -1 0 2.3 1.0 1.0 0.5 ---------------------- BODIES --------------------------------------------------- ID Attachment X0 Y0 Z0 r0 p0 y0 Mass CG I Volume CdA Ca (#) (word) (m) (m) (m) (d) (d) (d) (kg) (m)(kg-m^2)(m^3)(m^2)(-) 1 coupled 0 0 0 0 0 0 0 0 0 0 0 0 ---------------------- POINTS --------------------------------------------------- ID Attachment X Y Z Mass Volume CdA Ca (#) (word/ID) (m) (m) (m) (kg) (m^3) (m^2) (-) 1 Fixed -500 0 -150 0 0 0 0 2 Fixed 250 433 -150 0 0 0 0 3 Fixed 250 -433 -150 0 0 0 0 4 Body1 20 0 -10 0 0 0 0 5 Body1 -10 17 -10 0 0 0 0 6 Body1 -10 -17 -10 0 0 0 0 ---------------------- LINES ---------------------------------------------------- ID LineType AttachA AttachB UnstrLen NumSegs LineOutputs (#) (name) (ID) (ID) (m) (-) (-) 1 Chain 1 4 500 30 p 2 Chain 2 5 500 30 p 3 Chain 3 6 500 30 p ---------------------- OPTIONS -------------------------------------------------- writeLog 1 # write log file dtM 0.002 # internal time step (s) CFL 0.5 # Courant number limit tScheme RK2 # time integration scheme WtrDpth 150.0 # water depth (m) kBot 3.0e6 # seabed stiffness (Pa/m) cBot 3.0e5 # seabed damping (Pa-s/m) TmaxIC 120.0 # max IC generation time (s) threshIC 0.001 # IC convergence threshold dtIC 1.0 # IC convergence check interval (s) ---------------------- OUTPUTS -------------------------------------------------- FAIRTEN1 FAIRTEN2 FAIRTEN3 ANCHTEN1 ANCHTEN2 ANCHTEN3 BODY1PX BODY1PY BODY1PZ END ``` -------------------------------- ### Install Catch2 using vcpkg Source: https://github.com/floatingarraydesign/moordyn/blob/master/extern/Catch2/docs/cmake-integration.md Follow these steps to install Catch2 using the vcpkg dependency manager. This includes bootstrapping vcpkg, integrating it with your system, and then installing the catch2 package. ```bash git clone https://github.com/Microsoft/vcpkg.git cd vcpkg ./bootstrap-vcpkg.sh ./vcpkg integrate install ./vcpkg install catch2 ``` -------------------------------- ### Example Steady Currents Grid Input Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/waterkinematics.rst An example of a current_profile.txt file demonstrating a depth-dependent current profile. ```text 0 0.0 0.0 0.0 10 0.1 0.0 0.0 20 0.2 0.0 0.0 30 0.3 0.0 0.0 ``` -------------------------------- ### Install Python Build Tools Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/compiling.rst Use this command to install the necessary Python build tools. ```bash /python.exe -m pip install --upgrade build ``` -------------------------------- ### C MoorDyn Simulation Step Example Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/drivers.rst Provides a comprehensive example of initializing and stepping a MoorDyn simulation in C. This includes setting initial conditions and advancing the simulation. ```c #include #include #include #include int main(int, char**) { int err; MoorDyn system = MoorDyn_Create("Mooring/lines.txt"); if (!system) return 1; // 3 coupled points x 3 components per point = 9 DoF double x[9], xd[9]; memset(xd, 0.0, sizeof(double)); // Get the initial positions from the system itself for (unsigned int i = 0; i < 3; i++) { // 4 = first fairlead id MoorDynPoint point = MoorDyn_GetPoint(system, i + 4); err = MoorDyn_GetPointPos(point, x + 3 * i); if (err != MOORDYN_SUCCESS) { MoorDyn_Close(system); return 1; } } // Setup the initial condition err = MoorDyn_Init(system, x, xd); if (err != MOORDYN_SUCCESS) { MoorDyn_Close(system); return 1; } // Make the points move at 0.5 m/s to the positive x direction for (unsigned int i = 0; i < 3; i++) xd[3 * i] = 0.5; double t = 0.0, dt = 0.5; double f[9]; err = MoorDyn_Step(system, x, xd, f, &t, &dt); if (err != MOORDYN_SUCCESS) { MoorDyn_Close(system); return 1; } // Print the position and tension of the line nodes unsigned int n_lines; err = MoorDyn_GetNumberLines(system, &n_lines); if (err != MOORDYN_SUCCESS) { MoorDyn_Close(system); return 1; } for (unsigned int i = 0; i < n_lines; i++) { const unsigned int line_id = i + 1; printf("Line %u\n", line_id); printf("=======\n"); MoorDynLine line = MoorDyn_GetLine(system, line_id); if (!line) { MoorDyn_Close(system); return 1; } unsigned int n_nodes; ``` -------------------------------- ### Install MoorDyn Python Wrapper Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/compiling.rst After compiling MoorDyn, navigate to the root directory and run 'pip install ./'. This command installs the Python wrapper for MoorDyn. ```bash pip install ./ ``` -------------------------------- ### MoorDyn Initial Positions Example Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/inputs.rst Example of initial positions for coupled objects in OpenFAST mode. Non-zero values are incorporated into the initial states. ```none ---------------------- Initial Positions -------------------------------------- ref_X ref_Y surge_init sway_init heave_init roll_init pitch_init yaw_init (m) (m) (m) (m) (m) (rad) (rad) (rad) 0 0 10.0 0.0 0.0 0.0 20.0 0.0 ``` -------------------------------- ### Build and Install Eigen (Windows) Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/compiling.rst Compile and install Eigen using MinGW Makefiles after configuring with CMake. Ensure you run this in an administrator command prompt. ```bash cd C:\MoorDyn\eigen.build mingw32-make mingw32-make install ``` -------------------------------- ### Compile and Install MoorDyn (Linux/Mac) Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/compiling.rst Build and install MoorDyn using make. The -j flag enables parallel compilation for faster build times. This installs headers, libraries, and Python wrappers. ```bash make -j make install ``` -------------------------------- ### Install necessary tools for MoorDyn CMake compilation on Windows Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/compiling.rst Install essential development tools including Python setuptools, pip, make, GCC, GDB, and CMake using pacman within an MSYS2 environment. ```bash pacman -S mingw-w64-x86_64-python-setuptools mingw-w64-x86_64-python-pip mingw64/mingw-w64-x86_64-make mingw-w64-x86_64-gcc mingw-w64-x86_64-gdb mingw-w64-x86_64-cmake ``` -------------------------------- ### Wave FFT Grid Example Frequencies Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/waterkinematics.rst An example of a wave_frequencies.txt file with specific frequency components and amplitudes. This is used to illustrate potential issues with linear interpolation in the Wave FFT Grid method. ```text 0.0 0.0 0.0 0.2 1.0 0.0 0.4 0.0 3.0 0.6 0.0 0.0 ``` -------------------------------- ### Generate Windows Installer for MoorDyn using CMake Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/compiling.rst To generate a Windows installer, disable the PYTHON_WRAPPER option in CMake, then navigate to the build directory and run 'mingw32-make' followed by 'cpack -C Release'. ```bash cd C:\MoorDyn\MoorDyn.build cpack -C Release ``` -------------------------------- ### Configure MoorDyn Build (Linux/Mac) Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/compiling.rst Use CMake to configure the build environment for MoorDyn. Specify installation prefix and build type. If Eigen is not installed, use -DEXTERNAL_EIGEN=OFF. ```bash mkdir build cd build CMake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release ../ ``` -------------------------------- ### MoorDyn Input File Front Matter Example Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/inputs.rst The initial lines of the input file before any section heading are for free-form user input, such as labels and notes. ```none MoorDyn input file... MoorDyn v1 sample input file True Echo echo the input file data (flag) ``` -------------------------------- ### Import MoorDyn and Supporting Libraries Source: https://github.com/floatingarraydesign/moordyn/blob/master/example/MoorDyn_standalone_demo.ipynb Import the necessary MoorDyn library, moorpy for visualization, and numpy for numerical operations. Ensure these libraries are installed before running. ```python import moordyn import moorpy # a nice tool for visualizing moordyn import numpy as np ``` -------------------------------- ### Python C API Example Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/drivers.rst Demonstrates calling MoorDyn functions from Python using the ctypes library. Ensure MoorDyn is compiled as a shared library. ```python t = ctypes.pointer(ctypes.c_double(time[i])) MDStep((x[i,:]).ctypes.data_as(ctypes.POINTER(ctypes.c_double*vector_size)), (xd[i,:]).ctypes.data_as(ctypes.POINTER(ctypes.c_double*vector_size)), t, dtC) print("Succesffuly simulated for {} seconds - now closing MoorDyn...".format(tMax)) # close MoorDyn simulation (clean up the internal memory, hopefully) when finished MDClose() ``` -------------------------------- ### Example Event Listener Implementation Source: https://github.com/floatingarraydesign/moordyn/blob/master/extern/Catch2/docs/event-listeners.md Demonstrates how to create a custom event listener by deriving from `Catch::EventListenerBase` and overriding `testRunStarting` to perform initialization. Remember not to use assertion macros within listeners. ```cpp #include #include class testRunListener : public Catch::EventListenerBase { public: using Catch::EventListenerBase::EventListenerBase; void testRunStarting(Catch::TestRunInfo const&) override { lib_foo_init(); } }; CATCH_REGISTER_LISTENER(testRunListener) ``` -------------------------------- ### Run MoorDyn-C with Python Script Source: https://github.com/floatingarraydesign/moordyn/blob/master/example/README.md This is the simplest example for running MoorDyn-C using a Python script. It serves as a basic starting point for standalone MoorDyn-C execution. ```python import moordyn # Example usage of MoorDyn-C with a Python script # (Actual code would be here, this is a placeholder) ``` -------------------------------- ### Create and Close MoorDyn System Instance Source: https://context7.com/floatingarraydesign/moordyn/llms.txt Demonstrates how to create a MoorDyn system instance from an input file and subsequently close it to free resources. Ensure the input file path is correct or NULL for default. Verbosity and logging can be configured before initialization. ```c #include #include int main(void) { // Create system from input file (NULL defaults to "Mooring/lines.txt") MoorDyn system = MoorDyn_Create("Mooring/lines.txt"); if (!system) { fprintf(stderr, "ERROR: could not create MoorDyn system\n"); return 1; } // Configure verbosity before Init MoorDyn_SetVerbosity(system, MOORDYN_MSG_LEVEL); MoorDyn_SetLogFile(system, "Mooring/lines.log"); MoorDyn_SetLogLevel(system, MOORDYN_MSG_LEVEL); // ... use the system ... int err = MoorDyn_Close(system); if (err != MOORDYN_SUCCESS) { fprintf(stderr, "ERROR closing system: %d\n", err); return 1; } return 0; } // Expected: creates system from input file, writes log to lines.log ``` -------------------------------- ### Catch2 Test Case with Sections Source: https://github.com/floatingarraydesign/moordyn/blob/master/extern/Catch2/docs/tutorial.md Demonstrates using sections within a Catch2 TEST_CASE to share setup and teardown code. Each section is executed from the start of the TEST_CASE, ensuring a fresh state for each section's assertions. ```cpp TEST_CASE( "vectors can be sized and resized", "[vector]" ) { std::vector v( 5 ); REQUIRE( v.size() == 5 ); REQUIRE( v.capacity() >= 5 ); SECTION( "resizing bigger changes size and capacity" ) { v.resize( 10 ); REQUIRE( v.size() == 10 ); REQUIRE( v.capacity() >= 10 ); } SECTION( "resizing smaller changes size but not capacity" ) { v.resize( 0 ); REQUIRE( v.size() == 0 ); REQUIRE( v.capacity() >= 5 ); } SECTION( "reserving bigger changes capacity but not size" ) { v.reserve( 10 ); REQUIRE( v.size() == 5 ); REQUIRE( v.capacity() >= 10 ); } SECTION( "reserving smaller does not change size or capacity" ) { v.reserve( 0 ); REQUIRE( v.size() == 5 ); REQUIRE( v.capacity() >= 5 ); } } ``` -------------------------------- ### Install MATLAB MEX Targets Source: https://github.com/floatingarraydesign/moordyn/blob/master/wrappers/matlab/CMakeLists.txt Installs the compiled MATLAB MEX targets (libraries, archives, executables) to their respective destinations within the installation directory. This makes the compiled functions available after installation. ```cmake install(TARGETS ${MOORDYNM_TARGETS} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin INCLUDES DESTINATION include ) ``` -------------------------------- ### Example: Running a top-level section Source: https://github.com/floatingarraydesign/moordyn/blob/master/extern/Catch2/docs/command-line.md Demonstrates how to use the --section argument to run a specific top-level section ('sd') within a test case ('Test'). ```bash ./MyExe Test -c sd ``` -------------------------------- ### Configure MoorDyn with CMake for Custom Installation Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/troubleshooting.rst This CMake command configures MoorDyn for installation in a custom path, specifically addressing issues where the MoorDyn library is not found by the Python wrapper. It sets the installation prefix and build type, and enables user-specific installations for the Python wrapper. ```none cmake -DCMAKE_INSTALL_PREFIX="/usr/local/" -DCMAKE_BUILD_TYPE=Release DPYTHON_WRAPPER_USERINSTALL=ON ../ ``` -------------------------------- ### Print Help Message Source: https://github.com/floatingarraydesign/moordyn/blob/master/extern/Catch2/docs/command-line.md Displays the command-line arguments and their descriptions to standard output. ```bash -h, -?, --help ``` -------------------------------- ### Install Library and Export Targets Source: https://github.com/floatingarraydesign/moordyn/blob/master/wrappers/fortran/CMakeLists.txt Installs the 'moordynf' library and exports targets for use by other CMake projects. ```cmake install(TARGETS moordynf EXPORT MoorDynTargets LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin INCLUDES DESTINATION include ) ``` -------------------------------- ### Initialize and Plot with MoorPy Source: https://github.com/floatingarraydesign/moordyn/blob/master/example/MoorDyn_standalone_demo.ipynb Creates a MoorPy system by loading MoorDyn output files and plots the mooring system at a specific time. Ensure the input file and directory are correctly specified. ```python ms = moorpy.System(file="body.txt", dirname="./", rootname="body", qs = 0, Fortran = False) # qs tells MoorPy it is loading a MoorDyn system, Fortran = False tells it to use the MoorDyn-C output format ms.plot(color="red", time = 0) ``` -------------------------------- ### MoorDyn Input File Header Example Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/inputs.rst The initial lines of the input file are for free-form user input, such as labeling the file or adding notes. There is no limit to the number of lines allowed in this section. ```none --------------------- MoorDyn Input File ------------------------------------ MoorDyn v2 sample input file ``` -------------------------------- ### Install Fortran Module File Source: https://github.com/floatingarraydesign/moordyn/blob/master/wrappers/fortran/CMakeLists.txt Installs the Fortran module file ('moordyn.mod'), with conditional paths for Visual Studio builds. ```cmake if (CMAKE_GENERATOR MATCHES "Visual Studio") install( FILES ${CMAKE_CURRENT_BINARY_DIR}/$<$:Debug>$<$:Release>/moordyn.mod DESTINATION include/moordyn COMPONENT Devel ) else() install( FILES ${CMAKE_CURRENT_BINARY_DIR}/moordyn.mod DESTINATION include/moordyn ) endif() ``` -------------------------------- ### Basic MoorDyn Python Integration Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/drivers.rst Demonstrates creating a MoorDyn system, initializing its state, stepping through time, and retrieving node positions and tensions. Ensure MoorDyn is installed via pip. ```python import moordyn system = moordyn.Create("Mooring/lines.txt") # 3 coupled points x 3 components per point = 9 DoF xd = [0] * 9 # Get the initial positions from the system itself x = [] for i in range(3): # 4 = first fairlead id point = moordyn.GetPoint(system, i + 4) x = x + list(moordyn.GetPointPos(point)) # Setup the initial condition moordyn.Init(system, x, xd) # Make the points move at 0.5 m/s to the positive x direction for i in range(3): xd[3 * i] = 0.5 t, dt = 0.0, 0.5 f = moordyn.Step(system, x, xd, t, dt) # Print the position and tension of the line nodes n_lines = moordyn.GetNumberLines(system) for line_id in range(1, n_lines + 1): print("Line {}".format(line_id)) print("=======") line = moordyn.GetLine(system, line_id) n_segs = moordyn.GetLineN(line) for node_id in range(n_segs+1): print(" node {}:".format(node_id)) pos = moordyn.GetLineNodePos(line, node_id) print(" pos = {}".format(pos)) ten = moordyn.GetLineNodeTen(line, node_id) print(" ten = {}".format(ten)) # Alright, time to finish! moordyn.Close(system) ``` -------------------------------- ### Example: Running all sub-sections of a section Source: https://github.com/floatingarraydesign/moordyn/blob/master/extern/Catch2/docs/command-line.md Demonstrates how to use the --section argument to run a specific section ('sa') and all of its nested sub-sections ('sb', 'sc') within a test case ('Test'). ```bash ./MyExe Test -c sa ``` -------------------------------- ### Install MoorDyn via AUR (Arch Linux) Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/compiling.rst On Arch Linux and its derivatives, MoorDyn can be easily installed using the AUR helper 'yay'. ```bash yay -S moordyn ``` -------------------------------- ### Stationary Solver Initialization Options Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/initialization.rst Configure Moordyn for initialization using the stationary solver. Adjust threshIC and TmaxIC for convergence. ```none -------------------------- SOLVER OPTIONS--------------------------------------------------- 1e-6 threshIC - threshold for IC convergence 100.0 TmaxIC - threshold for IC convergence --------------------------- need this line ------------------------------------------------- ``` -------------------------------- ### Custom Streaming Reporter Example Source: https://github.com/floatingarraydesign/moordyn/blob/master/extern/Catch2/docs/reporters.md Example of a custom reporter inheriting from StreamingReporterBase. It responds to testCasePartialStarting and testCasePartialEnded events and registers itself as the 'partial' reporter. ```cpp #include #include #include #include class PartialReporter : public Catch::StreamingReporterBase { public: using StreamingReporterBase::StreamingReporterBase; static std::string getDescription() { return "Reporter for testing TestCasePartialStarting/Ended events"; } void testCasePartialStarting(Catch::TestCaseInfo const& testInfo, uint64_t partNumber) override { std::cout << "TestCaseStartingPartial: " << testInfo.name << '#' << partNumber << '\n'; } void testCasePartialEnded(Catch::TestCaseStats const& testCaseStats, uint64_t partNumber) override { std::cout << "TestCasePartialEnded: " << testCaseStats.testInfo->name << '#' << partNumber << '\n'; } }; CATCH_REGISTER_REPORTER("partial", PartialReporter) ``` -------------------------------- ### Install MoorDyn as Python Module (PyPI) Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/compiling.rst Installs the MoorDyn Python module from the Python Package Index (PyPI). Pip handles all necessary steps. ```bash python -m pip install moordyn ``` -------------------------------- ### Upscaled-Drag Dynamics Initialization Configuration Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/initialization.rst Configuration file for the upscaled-drag dynamics solver to achieve a good enough IC quickly. This method is faster than the stationary solver for IC generation but may require more computational resources. ```none riser_ic2.txt: The upscaled-drag to fast converge to a good enough IC -------------------------- SOLVER OPTIONS--------------------------------------------------- 0.25 cfl - Courant-Friedich-Lewy factor 1 ICgenDynamic - 0 for stationary solver, 1 for upscaled drag legacy solver 4.0 ICDfac - factor by which to scale drag coefficients during dynamic relaxation IC gen 1e-3 threshIC - threshold for IC convergence 0.5 dtIC - Time lapse between convergence tests (s) 5.0 TmaxIC - threshold for IC convergence riser.ic fileIC - Load a quasistatic solution before the IC solver (-) --------------------------- need this line ------------------------------------------------- ``` -------------------------------- ### Compile and Install MoorDyn using CMake on Windows Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/compiling.rst After configuring MoorDyn with CMake, navigate to the build directory and use 'mingw32-make' to compile and install the libraries. ```bash cd C:\MoorDyn\MoorDyn.build mingw32-make mingw32-make install ``` -------------------------------- ### C++ Standard Version Example (Polyfilling) Source: https://github.com/floatingarraydesign/moordyn/blob/master/extern/Catch2/docs/contributing.md Illustrates the use of polyfilled C++ features, such as `conjunction`, where a custom implementation is provided for older standards while leveraging standard library versions when available. ```cpp if available we use `std::conjunction` and otherwise provide our own implementation. ``` -------------------------------- ### Initialize MoorDyn System Without Initial Conditions Source: https://context7.com/floatingarraydesign/moordyn/llms.txt Provides an example of initializing the MoorDyn system with zero initial positions and velocities for the coupled DOFs. This function is suitable when a saved state file is to be loaded immediately after. It prints a success message upon completion. ```c #include #include int main(void) { MoorDyn system = MoorDyn_Create("Mooring/lines.txt"); unsigned int ndof; MoorDyn_NCoupledDOF(system, &ndof); // Platform at rest at origin double x[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; // surge,sway,heave,roll,pitch,yaw double xd[6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; int err = MoorDyn_Init(system, x, xd); if (err != MOORDYN_SUCCESS) { fprintf(stderr, "Init failed: %d\n", err); MoorDyn_Close(system); return 1; } printf("Initialization succeeded\n"); MoorDyn_Close(system); return 0; } // Expected: runs the IC solver (up to TmaxIC seconds), then prints "Initialization succeeded" ``` -------------------------------- ### Stationary Solver Initialization Configuration Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/initialization.rst Configuration file for the stationary solver to generate an initial system state. Use this when a quick, albeit potentially less accurate, initial guess is sufficient. ```none riser_ic1.txt: The system boot up with the stationary solver -------------------------- SOLVER OPTIONS--------------------------------------------------- 0.25 cfl - Courant-Friedich-Lewy factor 0 ICgenDynamic - 0 for stationary solver, 1 for upscaled drag legacy solver 4.0 ICDfac - factor by which to scale drag coefficients during dynamic relaxation IC gen 1e-3 threshIC - threshold for IC convergence 0.5 dtIC - Time lapse between convergence tests (s) 2.0 TmaxIC - threshold for IC convergence --------------------------- need this line ------------------------------------------------- ``` -------------------------------- ### MoorDyn 4D Current Grid Example File Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/waterkinematics.rst An example of a 4D current file, demonstrating the grid definition and data point format for specifying currents on a 4D grid. ```text 2 2 2 2 -1 1 -2 2 -3 0 0 15 -1 -2 -3 0 0.0 0.0 0.0 -1 -2 0 0 0.0 0.0 0.0 -1 2 -3 0 0.0 0.0 0.0 -1 2 0 0 0.0 0.0 0.0 1 -2 -3 0 0.0 0.0 0.0 1 -2 0 0 0.0 0.0 0.0 1 2 -3 0 0.0 0.0 0.0 1 2 0 0 0.0 0.0 0.0 -1 -2 -3 15 -0.5 -0.5 0.0 ``` -------------------------------- ### Upgrade or Install Build Tools using pip Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/compiling.rst If necessary, upgrade or install build tools using pip. This command may be required in certain proxy environments or if build tools are outdated. ```bash pip install --upgrade setuptools ``` -------------------------------- ### Example: Running a specific nested section Source: https://github.com/floatingarraydesign/moordyn/blob/master/extern/Catch2/docs/command-line.md Demonstrates how to use the --section argument to run a specific nested section ('sb') within a test case ('Test'). ```bash ./MyExe Test -c sa -c sb ``` -------------------------------- ### External Wave Kinematics Initialization and Usage in C Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/waterkinematics.rst Demonstrates how to initialize and use external wave kinematics by providing custom water velocity and acceleration data to MoorDyn during the simulation loop. This is useful when fluid dynamics are computed by an external program or custom code. ```c #include #include using namespace std; void get_water_kinematics(double t, const double* r, double* u, double* du) { // this function could call an external program, do its own computation, // lookup a precalculated value, etc u[0] = 1.0; // x velocity u[1] = 0.0; // y velocity u[2] = 0.0; // z velocity du[0] = 0.0; // x acceleration du[1] = 0.0; // y acceleration du[2] = 0.0; // z acceleration } bool main() { int err; MoorDyn system = MoorDyn_Create("Mooring/lines.txt"); if (!system) { cerr << "Failure Creating the Mooring system" << endl; return false; } // If you're dealing with coupled DOF's that could happen here // If not you can just pass in NULL err = MoorDyn_Init(system, NULL, NULL); if (err != MOORDYN_SUCCESS) { MoorDyn_Close(system); cerr << "Failure during the mooring initialization: " << err << endl; return false; } // Initialize the External Wave Kin, nwp gets set to the number of // points MoorDyn will want wave kinematics for. unsigned int nwp; err = MoorDyn_ExternalWaveKinInit(system, &nwp); if (err != MOORDYN_SUCCESS) { MoorDyn_Close(system); cerr << "Failure during the wave kinematics initialization: " << err << endl; return false; } // Allocate wave kinematics arrays double* r = new double[3 * nwp]; double* u = new double[3 * nwp]; double* du = new double[3 * nwp]; if (!r || !u || !du) { MoorDyn_Close(system); cerr << "Failure allocating " << 3 * 3 * nwp * sizeof(double) << " bytes" << endl; return false; } // Integrate in time const double t_max = 30.0; double t = 0.0, dt = 0.1; double f[3]; while (t < t_max) { // MoorDyn fills r with the (x, y, z) locations of nodes err = MoorDyn_ExternalWaveKinGetCoordinates(system, r); if (err != MOORDYN_SUCCESS) { MoorDyn_Close(system); cerr << "Failure getting the wave kinematics nodes: " << err << endl; return false; } // Loop through all the node coordinates and put their kinematics in u and du for (unsigned int i = 0; i < nwp; i++) { get_water_kinematics(t, r + 3 * i, u + 3 * i, du + 3 * i); } // Give MoorDyn our computed water kinematics (t says that these are // the kinematics for this moment in time) err = MoorDyn_ExternalWaveKinSet(system, u, du, t); if (err != MOORDYN_SUCCESS) { MoorDyn_Close(system); cerr << "Failure setting the wave kinematics: " << err << endl; return false; } err = MoorDyn_Step(system, NULL, NULL, NULL, &t, &dt); if (err != MOORDYN_SUCCESS) { MoorDyn_Close(system); cerr << "Failure during the mooring step: " << err << endl; return false; } } // Clean up our wave kinematics arrays delete[] r; delete[] u; delete[] du; err = MoorDyn_Close(system); if (err != MOORDYN_SUCCESS) { cerr << "Failure closing Moordyn: " << err << endl; return false; } } ``` -------------------------------- ### Nested Catch2 Sections Source: https://github.com/floatingarraydesign/moordyn/blob/master/extern/Catch2/docs/tutorial.md Illustrates nested sections within a Catch2 TEST_CASE. Nested sections allow for more granular control over setup and teardown, useful when multiple tests share parts of the setup. ```cpp SECTION( "reserving bigger changes capacity but not size" ) { v.reserve( 10 ); REQUIRE( v.size() == 5 ); REQUIRE( v.capacity() >= 10 ); SECTION( "reserving down unused capacity does not change capacity" ) { v.reserve( 7 ); REQUIRE( v.size() == 5 ); REQUIRE( v.capacity() >= 10 ); } } ``` -------------------------------- ### MATLAB MoorDyn Simulation Example Source: https://github.com/floatingarraydesign/moordyn/blob/master/docs/drivers.rst This MATLAB code demonstrates how to use MoorDyn for simulations. It covers creating the system, setting initial conditions, performing a time step, and retrieving node positions and tensions. Ensure the MoorDyn wrapper directory is added to the MATLAB path. ```matlab system = MoorDynM_Create('Mooring/lines.txt'); %% 3 coupled points x 3 components per point = 9 DoF x = zeros(9,1); xd = zeros(9,1); %% Get the initial positions from the system itself for i=1:3 %% 4 = first fairlead id point = MoorDynM_GetPoint(system, i + 3); x(1 + 3 * (i - 1):3 * i) = MoorDynM_GetPointPos(point); end %% Setup the initial condition MoorDynM_Init(system, x, xd); %% Make the points move at 0.5 m/s to the positive x direction for i=1:3 xd(1 + 3 * (i - 1)) = 0.5; end t = 0.0; dt = 0.5; [t, f] = MoorDynM_Step(system, x, xd, t, dt); %% Print the position and tension of the line nodes n_lines = MoorDynM_GetNumberLines(system); for line_id=1:n_lines line_id line = MoorDynM_GetLine(system, line_id); n_nodes = MoorDynM_GetLineNumberNodes(line); for node_id=1:n_nodes node_id pos = MoorDynM_GetLineNodePos(line, node_id - 1); pos ten = MoorDynM_GetLineNodeTen(line, node_id - 1); ten end end %% Alright, time to finish! MoorDynM_Close(system); ```