|
| 1 | +/* |
| 2 | + * Copyright (c) 2022 Jose Luis Cercos-Pita <jlc@core-marine.com> |
| 3 | + * |
| 4 | + * Redistribution and use in source and binary forms, with or without |
| 5 | + * modification, are permitted provided that the following conditions are met: |
| 6 | + * |
| 7 | + * 1. Redistributions of source code must retain the above copyright notice, |
| 8 | + * this list of conditions and the following disclaimer. |
| 9 | + * |
| 10 | + * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | + * this list of conditions and the following disclaimer in the documentation |
| 12 | + * and/or other materials provided with the distribution. |
| 13 | + * |
| 14 | + * 3. Neither the name of the copyright holder nor the names of its |
| 15 | + * contributors may be used to endorse or promote products derived from |
| 16 | + * this software without specific prior written permission. |
| 17 | + * |
| 18 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | + * POSSIBILITY OF SUCH DAMAGE. |
| 29 | + */ |
| 30 | + |
| 31 | +/** @file minimal.cpp |
| 32 | + * Minimal tests that only checks the library is correctly initialized, |
| 33 | + * running and closing |
| 34 | + */ |
| 35 | + |
| 36 | +#include "MoorDyn2.h" |
| 37 | +#include <algorithm> |
| 38 | +#include <cmath> |
| 39 | +#include <catch2/catch_test_macros.hpp> |
| 40 | + |
| 41 | +// #define SAVE_VTK |
| 42 | + |
| 43 | +using namespace std; |
| 44 | + |
| 45 | +TEST_CASE("Breaker") |
| 46 | +{ |
| 47 | + MoorDyn system = MoorDyn_Create("Mooring/lines.txt"); |
| 48 | + REQUIRE(system); |
| 49 | + |
| 50 | + unsigned int n_dof; |
| 51 | + REQUIRE(MoorDyn_NCoupledDOF(system, &n_dof) == MOORDYN_SUCCESS); |
| 52 | + REQUIRE(n_dof == 9); |
| 53 | + |
| 54 | + int err; |
| 55 | + double x[9], dx[9]; |
| 56 | + // Get the initial positions from the config file |
| 57 | + for (unsigned int i = 0; i < 3; i++) { |
| 58 | + // 4 = first fairlead id |
| 59 | + auto point = MoorDyn_GetPoint(system, i + 4); |
| 60 | + REQUIRE(point); |
| 61 | + REQUIRE(MoorDyn_GetPointPos(point, x + 3 * i) == MOORDYN_SUCCESS); |
| 62 | + } |
| 63 | + |
| 64 | + auto point = MoorDyn_GetPoint(system, 4); |
| 65 | + REQUIRE(point); |
| 66 | + auto line = MoorDyn_GetLine(system, 1); |
| 67 | + REQUIRE(line); |
| 68 | + |
| 69 | + std::fill(dx, dx + 9, 0.0); |
| 70 | + REQUIRE(MoorDyn_Init(system, x, dx) == MOORDYN_SUCCESS); |
| 71 | +#ifdef SAVE_VTK |
| 72 | + REQUIRE(MoorDyn_SaveVTK(system, "line_break.000.vtm") == MOORDYN_SUCCESS); |
| 73 | +#endif |
| 74 | + // Let's move the system at a 10.0m/s speed during 0.5 seconds |
| 75 | + double f[9]; |
| 76 | + dx[0] = 10.0; |
| 77 | + double t = 0.0, dt = 0.5; |
| 78 | + REQUIRE(MoorDyn_Step(system, x, dx, f, &t, &dt) == MOORDYN_SUCCESS); |
| 79 | +#ifdef SAVE_VTK |
| 80 | + REQUIRE(MoorDyn_SaveVTK(system, "line_break.001.vtm") == MOORDYN_SUCCESS); |
| 81 | +#endif |
| 82 | + x[0] += dx[0] * dt; |
| 83 | + |
| 84 | + // Break a line and repeat 3 times |
| 85 | + REQUIRE(MoorDyn_BreakLine(system, point, line) == MOORDYN_SUCCESS); |
| 86 | + REQUIRE(MoorDyn_Step(system, x, dx, f, &t, &dt) == MOORDYN_SUCCESS); |
| 87 | +#ifdef SAVE_VTK |
| 88 | + REQUIRE(MoorDyn_SaveVTK(system, "line_break.002.vtm") == MOORDYN_SUCCESS); |
| 89 | +#endif |
| 90 | + x[0] += dx[0] * dt; |
| 91 | + REQUIRE(MoorDyn_Step(system, x, dx, f, &t, &dt) == MOORDYN_SUCCESS); |
| 92 | +#ifdef SAVE_VTK |
| 93 | + REQUIRE(MoorDyn_SaveVTK(system, "line_break.003.vtm") == MOORDYN_SUCCESS); |
| 94 | +#endif |
| 95 | + x[0] += dx[0] * dt; |
| 96 | + REQUIRE(MoorDyn_Step(system, x, dx, f, &t, &dt) == MOORDYN_SUCCESS); |
| 97 | +#ifdef SAVE_VTK |
| 98 | + REQUIRE(MoorDyn_SaveVTK(system, "line_break.004.vtm") == MOORDYN_SUCCESS); |
| 99 | +#endif |
| 100 | + x[0] += dx[0] * dt; |
| 101 | + |
| 102 | + REQUIRE(MoorDyn_Close(system) == MOORDYN_SUCCESS); |
| 103 | +} |
0 commit comments