Skip to content

Commit 1b93e13

Browse files
committed
Add MoorDyn submodule and improve build robustness
1 parent 1f4c829 commit 1b93e13

8 files changed

Lines changed: 129 additions & 49 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ doc/user/_verification/demos/sphere_decay/*.png
4242
doc/user/_verification/demos/sphere_decay/*.hires.png
4343
_build/
4444

45+
# MoorDyn workaround (copied at configure time, see CMakeLists.txt)
46+
/cmake/MoorDynConfig.cmake
47+
/LICENSE.txt
48+
4549
# General
4650
build/
4751
demos/F3OF/f3of/

CMakeLists.txt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,20 @@ else()
220220
message(STATUS "Set C++ standard to: ${HC_CXX_STANDARD}")
221221
endif()
222222

223+
# Detect whether Chrono has the newer ChLoadHydrodynamics API.
224+
# If not, fall back to HydroChrono's legacy added-mass implementation.
225+
set(CHRONO_HAS_LOAD_HYDRODYNAMICS FALSE)
226+
get_target_property(_chrono_inc_dirs Chrono::Chrono_core INTERFACE_INCLUDE_DIRECTORIES)
227+
foreach(_dir ${_chrono_inc_dirs})
228+
if(EXISTS "${_dir}/chrono/physics/ChLoadHydrodynamics.h")
229+
set(CHRONO_HAS_LOAD_HYDRODYNAMICS TRUE)
230+
break()
231+
endif()
232+
endforeach()
233+
if(NOT CHRONO_HAS_LOAD_HYDRODYNAMICS)
234+
message(STATUS "ChLoadHydrodynamics not found in Chrono -- using legacy added-mass implementation")
235+
endif()
236+
223237
# Enable Irrlicht support if requested and available
224238
if(HYDROCHRONO_ENABLE_IRRLICHT AND NOT TARGET Chrono::Chrono_irrlicht)
225239
message(FATAL_ERROR "HYDROCHRONO_ENABLE_IRRLICHT is ON but Chrono::Chrono_irrlicht target not found. Ensure Chrono was built with Irrlicht support.")
@@ -265,6 +279,23 @@ endif()
265279
# -- MoorDyn mooring library (optional) --
266280
if(HYDROCHRONO_ENABLE_MOORDYN)
267281
message(STATUS "\n---- MoorDyn mooring library")
282+
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/extern/MoorDyn/CMakeLists.txt")
283+
message(FATAL_ERROR
284+
"MoorDyn submodule not found at extern/MoorDyn.\n"
285+
"Run: git submodule update --init extern/MoorDyn")
286+
endif()
287+
# MoorDyn's CMakeLists.txt uses CMAKE_SOURCE_DIR (which resolves to
288+
# HydroChrono's root) for its config template and CPack license.
289+
# Copy the files it expects so the configure step succeeds.
290+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/cmake/MoorDynConfig.cmake")
291+
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/extern/MoorDyn/cmake/MoorDynConfig.cmake"
292+
DESTINATION "${CMAKE_SOURCE_DIR}/cmake/")
293+
endif()
294+
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/LICENSE.txt")
295+
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/extern/MoorDyn/LICENSE.txt"
296+
DESTINATION "${CMAKE_SOURCE_DIR}/")
297+
endif()
298+
268299
set(EXTERNAL_EIGEN OFF CACHE BOOL "Use MoorDyn bundled Eigen" FORCE)
269300
set(PYTHON_WRAPPER OFF CACHE BOOL "Disable MoorDyn Python wrapper" FORCE)
270301
set(FORTRAN_WRAPPER OFF CACHE BOOL "Disable MoorDyn Fortran wrapper" FORCE)
@@ -485,6 +516,7 @@ target_compile_definitions(HydroChrono
485516
PUBLIC
486517
"HYDROCHRONO_VERSION=\"${PROJECT_VERSION}\""
487518
"HYDROCHRONO_BUILD_TYPE=\"$<IF:$<CONFIG:Debug>,Debug,$<IF:$<CONFIG:Release>,Release,$<IF:$<CONFIG:RelWithDebInfo>,RelWithDebInfo,$<IF:$<CONFIG:MinSizeRel>,MinSizeRel,Unknown>>>>\""
519+
$<$<NOT:$<BOOL:${CHRONO_HAS_LOAD_HYDRODYNAMICS}>>:HYDROCHRONO_USE_LEGACY_ADDED_MASS>
488520
PRIVATE
489521
$<$<BOOL:${HYDROCHRONO_ENABLE_LOGGING}>:HYDROCHRONO_ENABLE_LOGGING="1">
490522
)

build.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ if ($Help) {
6363
Write-Host " -Package Create distributable ZIP after building"
6464
Write-Host " -NoIrrlicht Disable Irrlicht (enabled by default if Chrono has it)"
6565
Write-Host " -NoVSG Disable VSG (enabled by default if Chrono has it)"
66-
Write-Host " -MoorDyn Enable MoorDyn mooring coupling (requires extern/MoorDyn)"
66+
Write-Host " -MoorDyn Enable MoorDyn mooring coupling"
67+
Write-Host " Requires: git submodule update --init extern/MoorDyn"
6768
Write-Host " -NoDemos Skip demo executables"
6869
Write-Host " -NoTests Skip test targets"
6970
Write-Host " -ConfigPath <path> Custom config file (default: build-config.json)`n"
@@ -80,6 +81,8 @@ if ($Help) {
8081
Write-Host "CONFIG FILE:" -ForegroundColor Yellow
8182
Write-Host ' { "ChronoDir": "C:/path/to/chrono/build/cmake" }' -ForegroundColor Gray
8283
Write-Host ""
84+
Write-Host "DOCS:" -ForegroundColor Yellow
85+
Write-Host " Full setup guide: docs/_main_pages/developer_docs/build_instructions.md`n"
8386
exit 0
8487
}
8588

@@ -188,6 +191,13 @@ try {
188191
exit 1
189192
}
190193

194+
# MoorDyn submodule check
195+
if ($MoorDyn -and -not (Test-Path ".\extern\MoorDyn\CMakeLists.txt")) {
196+
Write-Fail "MoorDyn submodule not found at extern/MoorDyn"
197+
Write-Host " Run: git submodule update --init extern/MoorDyn" -ForegroundColor Yellow
198+
exit 1
199+
}
200+
191201
# =============================================================================
192202
# Clean
193203
# =============================================================================

docs/_main_pages/developer_docs/build_instructions.md

Lines changed: 58 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,37 @@ parent_section: Developer Documentation
88

99
A PowerShell script (`build.ps1`) is provided to build HydroChrono from the command line. The steps to configure, build, and test with this script are outlined below. Alternatively, you can use the CMake GUI with Visual Studio; those instructions appear later on this page.
1010

11-
## Prerequisites (download/install these)
11+
## Prerequisites
12+
13+
**Required:**
1214

1315
- Visual Studio 2022 (Desktop development with C++)
1416
- CMake ≥ 3.18
15-
- Project Chrono (built from source; enable Parsers and Irrlicht modules)
16-
- HDF5 1.10.8 (CMake package)
17-
- Eigen 3.4 (headers)
18-
- Irrlicht 1.8.4 (if GUI)
19-
- Python 3.12 (only for tests/docs)
17+
- Project Chrono (built from source; enable the Parsers module at minimum)
18+
- HDF5 (C++ libraries, any recent version with CMake config support)
19+
20+
**Auto-detected from Chrono** (you do not need to install these separately):
21+
22+
- Eigen (header-only linear algebra library, bundled or referenced by Chrono)
23+
- Irrlicht / VSG (visualization backends, detected if Chrono was built with them)
24+
25+
**Optional:**
26+
27+
- Python 3.x (only needed for regression tests and building documentation)
28+
- MoorDyn (mooring dynamics library, included as a git submodule -- see [MoorDyn setup](#moordyn-mooring-library) below)
2029

2130
## Quick build with build.ps1 (recommended)
2231

2332
1) Copy `build-config-example.json` to `build-config.json` and set paths:
2433
```json
2534
{
2635
"ChronoDir": "C:/path/to/chrono/build/cmake",
27-
"Hdf5Dir": "C:/path/to/hdf5/share/cmake",
28-
"EigenDir": "C:/path/to/eigen-3.4.0",
29-
"IrrlichtDir": "C:/path/to/irrlicht-1.8.4",
3036
"PythonRoot": "C:/path/to/python/env"
3137
}
3238
```
3339

40+
`ChronoDir` is the only required key. Eigen, HDF5, and visualization library paths are auto-detected from Chrono's build configuration. `PythonRoot` is optional and only needed if Python isn't on your PATH.
41+
3442
2) From the repo root, run (first build) - use `-Verbose` for a more detailed output:
3543
```powershell
3644
./build.ps1 -Verbose
@@ -41,18 +49,22 @@ A PowerShell script (`build.ps1`) is provided to build HydroChrono from the comm
4149
./build.ps1 -Verbose -Package
4250
```
4351

44-
### Useful switches
52+
### Switches
4553

46-
- `-BuildType Release|Debug|RelWithDebInfo|MinSizeRel` (default: Release)
47-
- `-YamlRunner ON|OFF` to include/exclude the YAML runner target (default: ON)
48-
- `-Clean` remove existing `build/` before configuring
49-
- `-Package` run `cmake --install` and `cpack` (ZIP)
50-
- `-ConfigPath <file>` use a different JSON config
54+
| Switch | Description |
55+
|---|---|
56+
| `-BuildType <type>` | `Release` (default), `Debug`, `RelWithDebInfo`, or `MinSizeRel` |
57+
| `-Clean` | Remove existing `build/` before configuring |
58+
| `-Verbose` | Show full CMake and MSBuild output |
59+
| `-Package` | Run `cmake --install` and `cpack` to create a ZIP |
60+
| `-NoIrrlicht` | Disable Irrlicht visualization (auto-enabled if Chrono has it) |
61+
| `-NoVSG` | Disable VSG visualization (auto-enabled if Chrono has it) |
62+
| `-MoorDyn` | Enable MoorDyn mooring coupling (requires submodule, see [below](#moordyn-mooring-library)) |
63+
| `-NoDemos` | Skip building demo executables |
64+
| `-NoTests` | Skip building test targets |
65+
| `-ConfigPath <file>` | Use a different JSON config (default: `build-config.json`) |
5166

52-
What it does:
53-
- Passes your dependency paths to CMake
54-
- Builds with VS/MSBuild
55-
- For `-Package`: stages a flat install tree and creates a ZIP
67+
Run `.\build.ps1 -Help` for the full reference.
5668

5769
Install tree layout:
5870
```
@@ -62,16 +74,34 @@ install/
6274
tests/ # public regression suite (run_hydrochrono)
6375
```
6476

77+
## MoorDyn mooring library
78+
79+
[MoorDyn](https://github.com/FloatingArrayDesign/MoorDyn) is an optional mooring dynamics library included as a git submodule. To enable it:
80+
81+
1) Initialize the submodule (one-time setup, clones MoorDyn into `extern/MoorDyn`):
82+
```powershell
83+
git submodule update --init extern/MoorDyn
84+
```
85+
86+
2) Build with the `-MoorDyn` flag:
87+
```powershell
88+
./build.ps1 -MoorDyn -Verbose
89+
```
90+
91+
The submodule pins a specific MoorDyn version tested with HydroChrono. Running `git submodule update` after pulling new commits will keep it in sync.
92+
6593
## Alternative: CMake GUI + Visual Studio
6694

6795
1. Open CMake (GUI)
6896
- Source: HydroChrono repo root
6997
- Build: `<repo>/build`
7098

7199
2. Configure:
72-
- Set `Chrono_DIR` to `<chrono>/build/cmake`
73-
- Set `HDF5_DIR`, `Irrlicht_ROOT`, `Python3_ROOT_DIR`, `EIGEN3_INCLUDE_DIR`
74-
- Ensure your HydroChrono `CMAKE_MSVC_RUNTIME_LIBRARY` matches Chrono
100+
- Set `Chrono_DIR` to `<chrono>/build/cmake` (required)
101+
- Eigen, Irrlicht, and VSG paths are auto-detected from Chrono's build
102+
- `HDF5_DIR` may need to be set if CMake doesn't find it automatically
103+
- Set `HYDROCHRONO_ENABLE_MOORDYN` to `ON` if using MoorDyn (requires submodule, see [above](#moordyn-mooring-library))
104+
- Ensure your `CMAKE_MSVC_RUNTIME_LIBRARY` matches the one used to build Chrono
75105

76106
3. Generate → Open in Visual Studio → Build `run_hydrochrono` (choose the matching config, e.g., Release)
77107

@@ -85,24 +115,24 @@ After a local build, you have two regression test suites - **Option A** uses CTe
85115

86116
**Option A** - CTest:
87117
```powershell
88-
ctest -C Release -L regression
118+
ctest -C Release -L regression --test-dir build
89119
```
90120

91121
- Common CTest options/examples:
92122

93123
```powershell
94124
# Show failing test output
95-
ctest -C Release -L regression --output-on-failure
125+
ctest -C Release -L regression --test-dir build --output-on-failure
96126
97127
# Extra verbose output
98-
ctest -C Release -L regression -VV
128+
ctest -C Release -L regression --test-dir build -VV
99129
100130
# Only run specific tests
101-
ctest -C Release -R f3of -L regression
102-
ctest -C Release -R rm3 -L regression
131+
ctest -C Release -R f3of -L regression --test-dir build
132+
ctest -C Release -R rm3 -L regression --test-dir build
103133
104134
# Run in parallel
105-
ctest -C Release -j 6 -L regression
135+
ctest -C Release -j 6 -L regression --test-dir build
106136
```
107137

108138
**Option B** — Python-based YAML tests for the main executable:

docs/_main_pages/developer_docs/cmake_build_structure.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Banner comments separate sections so it’s easy to navigate and reason about ch
4141
- Project `HydroChrono` (C++)
4242
- Default build type: Release (Debug/MinSizeRel/RelWithDebInfo supported)
4343
- `cmake/` added to `CMAKE_MODULE_PATH` (local modules)
44-
- Generates `version.h` under `build/generated/`
44+
- Generates `version.h` under `build/hydroc/`
4545

4646
---
4747

@@ -52,6 +52,7 @@ Banner comments separate sections so it’s easy to navigate and reason about ch
5252
- `HYDROCHRONO_ENABLE_VSG` - Enable VSG visualization
5353
- `HYDROCHRONO_ENABLE_DEMOS` - Enable demo executables
5454
- `HYDROCHRONO_ENABLE_YAML_RUNNER` - Enable YAML-based CLI runner
55+
- `HYDROCHRONO_ENABLE_MOORDYN` - Enable MoorDyn mooring coupling (requires `extern/MoorDyn` submodule)
5556

5657
Enable lean builds (e.g., CI) or developer variants.
5758

@@ -61,14 +62,14 @@ Enable lean builds (e.g., CI) or developer variants.
6162

6263
### Chrono
6364

64-
- `find_package(Chrono CONFIG REQUIRED)`
65-
- If Irrlicht is enabled, find `Irrlicht` first so `Chrono::Chrono_irrlicht` exists
66-
- Extend `CMAKE_MODULE_PATH` with `Chrono_DIR` when needed
65+
- `find_package(Chrono CONFIG REQUIRED COMPONENTS Parsers)`
66+
- Irrlicht and VSG targets are checked if the corresponding `HYDROCHRONO_ENABLE_*` option is ON
67+
- HDF5 targets are pre-loaded before Chrono to avoid conflicts with `hdf5_tools` shim targets
6768

6869
### HDF5 & Eigen
6970

70-
- HDF5 required: `find_package(HDF5 REQUIRED COMPONENTS CXX)`; link static to avoid DLL issues
71-
- Eigen via config or module mode
71+
- HDF5: first tries config mode (`find_package(HDF5 CONFIG QUIET)`), falls back to module mode (`find_package(HDF5 REQUIRED COMPONENTS CXX)`). Prefers static libraries when available.
72+
- Eigen: auto-detected from Chrono's build configuration
7273

7374
### Platform notes
7475

@@ -80,15 +81,15 @@ Enable lean builds (e.g., CI) or developer variants.
8081

8182
Libraries:
8283

83-
- `HydroChrono` — core hydrodynamics (HDF5 I/O, YAML, utilities)
84-
- `HydroChronoGUI` — GUI helpers when Irrlicht is enabled
84+
- `HydroChrono` — core hydrodynamics (HDF5 I/O, YAML, radiation, waves, utilities)
85+
- `HydroChronoGUI` — GUI helpers for Irrlicht and/or VSG visualization
8586

86-
`configure_hydro_target(<tgt>)` centralizes: C++ standard, PIC, include dirs, Chrono links.
87+
Each target is configured directly with C++ standard, PIC, include dirs, and Chrono links.
8788

8889
Key links:
8990

90-
- `HydroChrono``Chrono::Chrono_core` (+ HDF5)
91-
- `HydroChronoGUI` → Chrono (+ `Chrono::Chrono_irrlicht` when enabled)
91+
- `HydroChrono``Chrono::Chrono_core`, OpenMP, HDF5 (+ MoorDyn when enabled)
92+
- `HydroChronoGUI``Chrono::Chrono_core` (+ `Chrono::Chrono_irrlicht` and/or `Chrono::Chrono_vsg` when enabled)
9293

9394

9495
---
@@ -109,8 +110,8 @@ Key links:
109110
110111
### Tests & Demos
111112

112-
- If enabled, tests are added via `add_subdirectory(tests)` and `add_subdirectory(tests/regression)`
113-
- A helper `configure_test_environment()` assembles PATH on Windows so Chrono/Irrlicht DLLs are found when tests run from the build tree
113+
- If enabled, tests are added via `add_subdirectory(tests/regression)` and `add_subdirectory(tests/unit)`
114+
- A helper `configure_test_environment()` assembles PATH on Windows so Chrono, HDF5, Irrlicht, VSG, and MoorDyn DLLs are found when tests run from the build tree
114115
- Demos can be included behind `HYDROCHRONO_ENABLE_DEMOS`
115116

116117
Runtime concerns that affect tests:

extern/MoorDyn

Submodule MoorDyn added at 405dd8c

include/hydroc/hydro_system.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,10 @@
2020
// ─────────────────────────────────────────────────────────────────────────────
2121
// Added Mass Implementation Toggle
2222
// ─────────────────────────────────────────────────────────────────────────────
23-
// By default, HydroChrono uses Chrono's built-in ChLoadHydrodynamics for
24-
// infinite-frequency added mass. To switch to HydroChrono's legacy
25-
// ChLoadAddedMass (ChLoadCustomMultiple-based) implementation, uncomment:
26-
//
27-
// #define HYDROCHRONO_USE_LEGACY_ADDED_MASS
28-
//
23+
// HYDROCHRONO_USE_LEGACY_ADDED_MASS is auto-detected at configure time based
24+
// on whether Chrono provides ChLoadHydrodynamics. When defined (legacy mode),
25+
// HydroChrono uses its own ChLoadAddedMass (ChLoadCustomMultiple-based)
26+
// implementation instead of Chrono's built-in ChLoadHydrodynamics.
2927

3028
// Include hydro_types.h FIRST to ensure BodyForces and GeneralizedForce are available
3129
// before any other includes that might conflict (e.g., config/hydro_config.h)

tests/unit/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ endfunction()
3131

3232
# --- Register unit tests ---
3333
message(STATUS "Add HydroChrono unit tests")
34-
build_unit_test(test_added_mass_determinism)
34+
if(CHRONO_HAS_LOAD_HYDRODYNAMICS)
35+
build_unit_test(test_added_mass_determinism)
36+
else()
37+
message(STATUS " Skipping test_added_mass_determinism (requires ChLoadHydrodynamics)")
38+
endif()
3539
build_unit_test(test_radiation_ss_model)
3640
build_unit_test(test_radiation_ss_fitter)

0 commit comments

Comments
 (0)