diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bf2c0b..39dbcb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -152,6 +152,33 @@ All notable changes to CableDyn are recorded in this file. The format follows and checkpoint state; `Tf` 0 or no row leaves runs unchanged to the bit. A VIV FRAME row now needs LINE TYPES `Cl > 0` or a WAKE OSCILLATOR row; the Python deck reader and builder follow. +- A long-run check of the VIV synchronisation model (`viv_long_run`, 400 cycles). With every node + of a finite-EI cable moved across the flow, the shedding phase follows the closed-form solution + of its equation (Adler's) with an error that grows linearly in time and falls fourfold per + halving of the step: 0.017 rad after 400 cycles at 100 steps per cycle; inside the + synchronisation band the phase lag holds to 3e-5 rad. On a taut line locked in, finite-EI and + `EI = 0`, the load powers close the line's energy balance to 2e-4 of the VIV work at second + order, and the response amplitude, VIV power and lock-in frequency of the run's two halves agree + within 0.18 %. + +### Changed + +- `run_study` (and `cabledyn-study`) with `jobs > 1` runs every case with `OMP_NUM_THREADS=1` + unless the environment sets it, and `study.json` records the value (`omp_num_threads`). Many + processes that each start an OpenMP team oversubscribed the cores: 24 lazy-wave runs at 24 jobs + took 19.1 s with the OpenMP default and 16.7 s with one thread each. The Python manual gives the + measured batch scaling (13.3 times faster at 24 jobs on a 24-core workstation, 15.1 at 48). +- The load power channels (`VIVPow`, `DragPow`, `DampPow` and their per-length forms) of a line + evaluate its node powers once per output row instead of once per channel, on finite-EI cables, + `EI = 0` lines and line systems. Outputs are unchanged to the bit; with the three line totals + the VIV examples run about 11 % faster (`viv_taut_cable_inline.dat` 2.39 s to 2.14 s; the same + line with 200 elements at 100 steps per cycle 18.1 s to 16.1 s). +- The bending damping of a finite-EI cable (`EI|Bb`, `EI|-zeta|f`) evaluates the second + derivatives of the curvature only where the position Jacobian needs them, not in every residual + evaluation. Results are unchanged to the bit; the Delta Flume case 9 deck of + `validation/experiments/delta_flume` (64 elements, 80 000 steps) runs in 58.6 s instead of + 73.2 s. + ### Fixed - The statics of a finite-EI line through the free surface could fail at isolated currents: diff --git a/CMakeLists.txt b/CMakeLists.txt index 4d853fd..f07b54b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1430,6 +1430,15 @@ target_link_libraries(test_hermite_load_power PRIVATE cabledyn_core) add_test(NAME hermite_load_power COMMAND test_hermite_load_power) set_tests_properties(hermite_load_power PROPERTIES LABELS "fortran;dynamic;viv") +# Long VIV runs (400 cycles at 100 and 200 steps per cycle): the shedding phase under prescribed +# motion against Adler's closed form (linear error growth, second order), and a locked-in taut +# line of both kinds (energy closure of the load powers, stationary statistics and frequency). +# About 26 s in Release and 160 s in Debug locally. +add_executable(test_viv_long_run tests/test_viv_long_run.f90) +target_link_libraries(test_viv_long_run PRIVATE cabledyn_core) +add_test(NAME viv_long_run COMMAND test_viv_long_run) +set_tests_properties(viv_long_run PROPERTIES LABELS "fortran;dynamic;viv;slow" TIMEOUT 1200) + add_executable(test_load_power_deck tests/test_load_power_deck.f90) target_link_libraries(test_load_power_deck PRIVATE cabledyn_core) add_test(NAME load_power_deck COMMAND test_load_power_deck WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) diff --git a/VALIDATION.md b/VALIDATION.md index 3b523da..4f68327 100644 --- a/VALIDATION.md +++ b/VALIDATION.md @@ -65,6 +65,7 @@ article's methods, are compared in | **L2-VIV** | Cross-flow VIV lock-in of a taut 100 m line, U = 0.06–0.42 m/s | MoorDyn-C v2.7.2 (RK2, `dtM` 5e-4 s) and MoorDyn-F (OpenFAST v5 `moordyn_driver`, `dtM` 5e-4 s) | over 150–300 s, mode-1 lock-in at U 0.09–0.18 m/s: mid-span A/D within 0.2% of MoorDyn-F (0.017 against 0.018 at 0.06 m/s, below lock-in); mode 3 at 0.39–0.42 m/s within 1.4%; at 0.36 m/s MoorDyn-F settles in mode 2 and CableDyn in mode 3; frequency within one spectral bin wherever the modes agree; same response at `dtM` 5e-4 and 1e-2 s. At 0.21–0.33 m/s two branches coexist (a run ramped up from 0.18 m/s stays in mode 1, one ramped down from 0.30 m/s stays in mode 2): from rest CableDyn and MoorDyn-C settle in mode 2 (U 0.24 m/s: A/D 0.575 against 0.574 at x/L 0.24, same frequency); MoorDyn-F, whose phases start at zero (it does not carry its seed into its state), in mode 1, which `zero VIVphaseSeed` reproduces (0.699 against 0.699) | A/D <3%, frequency within one spectral bin; band: 3% (MoorDyn-C), 1% (MoorDyn-F) (`viv_lockin`) | Pass | | **L2-VIV-riser** | Catenary riser of Thorsen et al. in a uniform 0.2 m/s current (MoorDyn-C's VIV test: D 0.024 m, EI 10.5 N m², 100 segments, `Cl` 0.7), deck written anchor first | measured cross-flow frequency 1.04 Hz; MoorDyn-C v2.7.2 (RK4, `dtM` 1e-4 s) | over 20–40 s at `dtM` 1e-3 s: mean fairlead tension 69.92 N against 69.93 N, range 3.73 N against 3.72 N, tension period 0.4853 s against the measured 0.4808 s and MoorDyn-C's 0.4811 s (0.4843 / 0.4829 s at `dtM` 5e-4 / 2.5e-4 s) | mean 0.2%, range 10%, period 1.5% (`viv_riser`) | Pass | | **L2-VIV-EI** | Cross-flow VIV of a finite-EI cable: the L2-VIV line with EI = 1 N m², and a bending-stiff line (EA 5e9 N, EI 5e7 N m², β = π²EI/(TL²) ≈ 1, neutrally buoyant) against the EI = 0 string of equal first-mode frequency, U = 0.10–0.36 m/s | CableDyn `EI = 0` line (verification) | EI = 1: mid/quarter A/D 0.661/0.420 against 0.661/0.420, same frequency, at `dtM` 5e-4 to 1e-2 s; stiff line: mode-1 lock-in A/D within 2.5% of the string's at the same frequency for U ≤ 0.24 m/s; for U ≥ 0.27 m/s the string jumps to mode 2 while the stiff line stays in mode 1 (bending raises f₂/f₁ to 3.15) | EI = 1: A/D within 1% at `dtM` 0.01 and 0.002 s (5e-4 s run once over 200 s); stiff line at U 0.21 m/s: A/D within 3%; frequency within one spectral bin; at U 0.30 m/s stiff line A/D > 0.6, string < 0.15 (`viv_lockin`, `hermite_viv`) | Pass | +| **L2-VIV-long** | Long VIV runs, 400 cycles: (a) every node of a finite-EI cable moved across a 0.3 m/s flow at 5.5 rad/s (outside the synchronisation band) and inside it; (b) a taut 20 m line locked in, finite-EI and `EI = 0`, ρ∞ = 1, at 100 and 200 steps per cycle | (a) Adler's equation in closed form, `tan(ψ/2) = (b + s tan(θ/2))/a`; (b) the load powers against the change of the line's energy; a 2× finer step | (a) phase error 0.017 rad after 400 cycles at 100 steps per cycle, growing linearly (T/(T/2) 1.99) and second order (4.01 from 50 to 100 steps); inside the band the lag stays within 3.0e-5 rad of ψ*; (b) energy mismatch 2.0e-4 / 1.8e-4 of the VIV work, second order (3.98 / 3.67), A/D and VIV power of the run's two halves within 7.3e-4 and 1.8e-3, lock-in frequency within 1.9e-4 | (a) growth ratio 1.8–2.2, order 3.6–4.4, ≤0.05 rad; locked ≤1e-4 rad; (b) ≤3e-4, ratio 3–5; halves 2e-3 / 1e-2 / 2e-3 (`viv_long_run`) | Pass | | **L3-1** | WD0050 static | OrcaFlex | 0.15 / 0.85% | <2% | Pass | | **L3-2** | Regular-wave dynamic | OrcaFlex (pinned, dt-converged) | mean 0.30%, swing 8.4% | <2% / <15% | Pass | | **L3-3** | Current-deflected static | OrcaFlex | 0.07–0.67% | <2% | Pass | diff --git a/doc/cli.rst b/doc/cli.rst index 675af90..eb826da 100644 --- a/doc/cli.rst +++ b/doc/cli.rst @@ -1125,7 +1125,9 @@ remaining cases. * - ``--jobs`` - int - ``1`` - - Number of native processes run concurrently; must be positive. + - Number of native processes run concurrently; must be positive. Above 1, each process + runs with ``OMP_NUM_THREADS=1`` unless the environment sets it (measured batch scaling + and thread settings: :doc:`python`, Batch execution and study records). * - ``--timeout`` - float, s - none diff --git a/doc/python.rst b/doc/python.rst index 8517c5f..dd740ae 100644 --- a/doc/python.rst +++ b/doc/python.rst @@ -714,6 +714,71 @@ cases may run as separate native processes with ``jobs > 1``. Results are always written in the original manifest order, not completion order. This is process-level concurrency; it does not change CableDyn's numerical settings or make one solver instance multithreaded. +With ``jobs > 1`` and no ``OMP_NUM_THREADS`` in the environment, every case runs with +``OMP_NUM_THREADS=1``, and ``study.json`` records the value the cases ran with +(``omp_num_threads``; ``null`` when the environment was passed on without one). A set +``OMP_NUM_THREADS`` is passed on unchanged. The OpenMP regions of a GNU build (the tangent kernels +of a finite-EI cable of 32 elements or more, up to four threads, and the lines of a multi-line +system) pay off in a single run only, and many processes that each start a team oversubscribe the +cores. Measured on a 24-core, 48-thread workstation (gfortran Release build; the static Windows +release has no OpenMP): + +.. list-table:: Batch wall time, 96 finite-EI VIV cases (100 elements, 2000 steps, 1.8 s each) + :header-rows: 1 + + * - ``jobs`` + - wall, ``OMP_NUM_THREADS=1`` + - speed-up + - mean case time + - wall, OpenMP default + * - 1 + - 177.4 s + - 1.0 + - 1.84 s + - 181.2 s + * - 2 + - 91.2 s + - 1.9 + - 1.89 s + - 91.5 s + * - 4 + - 48.2 s + - 3.7 + - 1.97 s + - 49.4 s + * - 8 + - 27.1 s + - 6.5 + - 2.18 s + - 28.7 s + * - 16 + - 16.7 s + - 10.6 + - 2.62 s + - 16.9 s + * - 24 + - 13.4 s + - 13.3 + - 3.15 s + - 14.1 s + * - 48 + - 11.8 s + - 15.1 + - 5.45 s + - 11.9 s + +A case slows down as more run beside it (1.84 s alone, 3.15 s beside 23 others: shared memory +bandwidth and a lower all-core clock), so the batch gains less than ``jobs``; the second hardware +thread of each core adds 13 %. The VIV cases spend almost no time in OpenMP regions (a single run +takes 1.79 s with one thread and 1.76 s with the default), so the default costs them at most 5 %. +On a deck that uses them, the 1024-element lazy-wave cable of +``examples/lazy_wave_vessel_rao.dat``, a single run takes 11.4 s with one thread, 10.6 s with four +and 12.5 s with the default, and a batch of 24 such runs with ``jobs=24`` takes 16.7 s with one +thread per process, 17.9 s with four and 19.1 s with the default. Set ``jobs`` to the number of +physical cores (24 here), or to the number of hardware threads for the last 10-15 %, and leave +``OMP_NUM_THREADS`` unset for a batch; for a single long run of a large finite-EI cable, +``OMP_NUM_THREADS=4`` is the fastest setting. + One failed case does not cancel the remaining cases. The final status distinguishes: * ``completed`` — native exit zero, which the driver reserves for a converged analysis; diff --git a/python/cabledyn/study.py b/python/cabledyn/study.py index 6c721f2..0fb54c4 100644 --- a/python/cabledyn/study.py +++ b/python/cabledyn/study.py @@ -314,6 +314,19 @@ def _case_dict(case: StudyCaseResult) -> dict[str, object]: return result +def _case_environment(job_count: int) -> dict[str, str] | None: + """The environment entries of every case process: one OpenMP thread each when several run at + once and the caller's environment does not choose a count, otherwise none. + + Several CableDyn processes that each start an OpenMP team oversubscribe the cores; on a 24-core + workstation a batch of 24 finite-EI lazy-wave runs took 14 % longer with OpenMP left at its + default than with one thread per process. + """ + if job_count <= 1 or os.environ.get("OMP_NUM_THREADS", "").strip(): + return None + return {"OMP_NUM_THREADS": "1"} + + def run_study( case_manifest: str | os.PathLike[str], *, @@ -354,7 +367,10 @@ def run_study( Per-case time limit, in seconds; ``None`` for no limit. jobs : int Number of independent native processes run at once (not solver - threads within a process). + threads within a process). With ``jobs > 1`` and no + ``OMP_NUM_THREADS`` in the environment, each process runs with + ``OMP_NUM_THREADS=1``: the processes then share the cores without + oversubscribing them. A set ``OMP_NUM_THREADS`` is passed on unchanged. overwrite : bool Allow a non-empty output directory and replace existing case outputs. @@ -446,6 +462,7 @@ def run_study( solver_version = native.version() destination.mkdir(parents=True, exist_ok=True) + case_env = _case_environment(job_count) started = datetime.now(timezone.utc).isoformat() summaries: dict[str, list[dict[str, object]]] = {} summaries_lock = threading.Lock() @@ -464,9 +481,14 @@ def execute(case: _Case) -> StudyCaseResult: main_output: Path | None = None static_output: Path | None = None try: - native_result = native.run( - case.deck, output_root, timeout=timeout_value, overwrite=overwrite - ) + if case_env is None: + native_result = native.run( + case.deck, output_root, timeout=timeout_value, overwrite=overwrite + ) + else: + native_result = native.run( + case.deck, output_root, timeout=timeout_value, overwrite=overwrite, env=case_env + ) stdout, stderr = native_result.stdout, native_result.stderr returncode = native_result.returncode main_output = native_result.main_output @@ -600,6 +622,11 @@ def execute(case: _Case) -> StudyCaseResult: "started_at": started, "finished_at": finished, "jobs": job_count, + "omp_num_threads": ( + case_env["OMP_NUM_THREADS"] + if case_env is not None + else os.environ.get("OMP_NUM_THREADS") + ), "timeout": timeout_value, "period": {"start": start_value, "stop": stop_value}, "channels": list(selected) if selected is not None else None, diff --git a/python/tests/test_study.py b/python/tests/test_study.py index 61cdeb7..1bba809 100644 --- a/python/tests/test_study.py +++ b/python/tests/test_study.py @@ -315,3 +315,39 @@ def test_study_argument_validation(tmp_path, kwargs, message): output_directory=tmp_path / "results", **kwargs, ) + + +@pytest.mark.parametrize( + ("jobs", "omp", "passed", "recorded"), + [ + (2, None, "1", "1"), # parallel cases default to one OpenMP thread each + (2, "", "1", "1"), # an empty value counts as unset + (2, "3", None, "3"), # the caller's count is passed on unchanged + (1, None, None, None), # one case at a time keeps the environment + ], +) +def test_study_gives_parallel_cases_one_openmp_thread( + tmp_path, monkeypatch, jobs, omp, passed, recorded +): + if omp is None: + monkeypatch.delenv("OMP_NUM_THREADS", raising=False) + else: + monkeypatch.setenv("OMP_NUM_THREADS", omp) + manifest = _case_manifest(tmp_path) + driver = _driver(tmp_path) + original_run = driver.run + seen: list[object] = [] + lock = threading.Lock() + + def recording_run(*args, **kwargs): + with lock: + seen.append(kwargs.get("env")) + return original_run(*args, **kwargs) + + driver.run = recording_run # type: ignore[method-assign] + result = run_study(manifest, driver=driver, output_directory=tmp_path / "results", jobs=jobs) + assert result.passed + expected = None if passed is None else {"OMP_NUM_THREADS": passed} + assert seen == [expected, expected] + payload = json.loads(result.study_manifest.read_text(encoding="utf-8")) + assert payload["omp_num_threads"] == recorded diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index ec8a5e2..f03d875 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -909,6 +909,19 @@ MODULE CableDyn_DeckDriver ! Range graphs and touchdown channels of the run (sized by range_setup_planned; every ! row samples the lines that need it before the channels are evaluated). TYPE(CD_RangeSet) :: rset + ! The node load powers of each line (VIVPow, DragPow, DampPow and their per-length + ! channels), evaluated once per row by the row's first load power channel of that line + ! (lp_row stamps, lp_off offsets into the node arrays). + INTEGER, ALLOCATABLE :: lp_off(:), lp_row(:) + REAL(wp), ALLOCATABLE :: line_pv(:), line_pd(:), line_pm(:) + END TYPE + + TYPE :: LoadPowerRow + !! The node load powers of one finite-EI cable at the committed state of one output row + !! (CD_HermiteCable_Dyn_Load_Power): the row's first load power channel of the cable + !! evaluates them and its other load power channels reuse them. + LOGICAL :: valid = .FALSE. + REAL(wp), ALLOCATABLE :: pv(:), pd(:), pm(:) END TYPE TYPE :: LineStepWorkspace @@ -34147,6 +34160,8 @@ SUBROUTINE write_hermite_model_row(unit, time, channels, lines, points, cables, REAL(wp) :: val, f(3), fl(3) CHARACTER(NAMELEN) :: lo CHARACTER(1024) :: em + ! the cables' load powers at this row's state, shared by their load power channels + TYPE(LoadPowerRow) :: powers(SIZE(cables)) ErrStat = CD_DECKDRV_OK; ErrMsg = '' IF (PRESENT(ranges)) THEN DO li = 1, SIZE(lines) @@ -34233,7 +34248,7 @@ SUBROUTINE write_hermite_model_row(unit, time, channels, lines, points, cables, CALL parse_line_node_channel(channels(i), line_id, pidx, pp, comp) END IF li = find_line(lines, line_id) - CALL eval_cable_channel(cables(li), channels(i), val, ErrStat, ErrMsg) + CALL eval_cable_channel(cables(li), channels(i), val, ErrStat, ErrMsg, power=powers(li)) IF (ErrStat /= CD_DECKDRV_OK) RETURN END IF IF (.NOT. IEEE_IS_FINITE(val)) THEN @@ -35586,7 +35601,7 @@ SUBROUTINE write_planned_row(unit, time, channels, lines, points, work, label, E INTEGER, PARAMETER :: CH_LEGACY = 0, CH_FAIRTEN = 1, CH_ANCHTEN = 2, CH_ANGLE = 3, CH_NODE_TEN = 4, & CH_NODE_STATE = 5, CH_POINT_MOTION = 6, CH_POINT_FIXED = 7, CH_POINT_LINE = 8, & - CH_SYS_POINT = 9, CH_TDP = 10 + CH_SYS_POINT = 9, CH_TDP = 10, CH_LOAD_POWER = 11 INTEGER :: i, k, n, li, off, nd, ne, nnode, stride, es LOGICAL :: has_motion, ok REAL(wp) :: val, q_point(3), v_point(3), a_point(3) @@ -35664,6 +35679,22 @@ SUBROUTINE write_planned_row(unit, time, channels, lines, points, work, label, E val = points(work%ch_aux(i))%pos(work%ch_comp(i)) CASE (CH_TDP) val = work%rset%lines(li)%tdp(work%ch_comp(i)) + CASE (CH_LOAD_POWER) + CALL fetch_power(li, ok) + IF (.NOT. ok) THEN + CALL legacy_value(i, val) + ELSE + off = work%lp_off(li) + nnode = work%line_ndof(li)/stride + IF (PRESENT(models)) THEN + val = load_power_value(work%ch_aux(i), work%ch_node(i), work%line_pv(off + 1:off + nnode), & + work%line_pd(off + 1:off + nnode), work%line_pm(off + 1:off + nnode), models(li)%l0) + ELSE + val = load_power_value(work%ch_aux(i), work%ch_node(i), work%line_pv(off + 1:off + nnode), & + work%line_pd(off + 1:off + nnode), work%line_pm(off + 1:off + nnode), & + system%lines(li)%l0) + END IF + END IF CASE (CH_SYS_POINT) CALL CD_Get_System_Point_State(system, work%ch_aux(i), q_point, v_point, a_point, es, em) IF (es /= CD_SYSTEM_OK) THEN @@ -35760,6 +35791,28 @@ SUBROUTINE fetch_state(il, fetched) IF (fetched) work%state_row(il) = work%row END SUBROUTINE fetch_state + SUBROUTINE fetch_power(il, fetched) + !! Evaluate line `il`'s node load powers into the row cache once per row. + INTEGER, INTENT(IN) :: il + LOGICAL, INTENT(OUT) :: fetched + INTEGER :: o, m, es + CHARACTER(1024) :: msg + fetched = work%lp_row(il) == work%row + IF (fetched) RETURN + o = work%lp_off(il) + m = work%line_ndof(il)/stride + IF (PRESENT(models)) THEN + CALL CD_Get_Model_Load_Power(models(il), work%line_pv(o + 1:o + m), work%line_pd(o + 1:o + m), & + work%line_pm(o + 1:o + m), es, msg) + fetched = es == CD_MODEL_OK + ELSE + CALL CD_Get_System_Line_Load_Power(system, il, work%line_pv(o + 1:o + m), work%line_pd(o + 1:o + m), & + work%line_pm(o + 1:o + m), es, msg) + fetched = es == CD_SYSTEM_OK + END IF + IF (fetched) work%lp_row(il) = work%row + END SUBROUTINE fetch_power + SUBROUTINE end_tension_override(il, inode, nel, v) !! EI=0 model/system lines: an end node reports the force the line exerts on its end !! point (end element tension + the end node's lumped loads) instead of the element @@ -35843,6 +35896,8 @@ SUBROUTINE build_plan() IF (ALLOCATED(work%line_ndof)) DEALLOCATE (work%line_ndof, work%line_ne, work%state_off, work%ten_off, & work%state_row, work%ten_row) IF (ALLOCATED(work%line_q)) DEALLOCATE (work%line_q, work%line_v, work%line_a, work%line_ten) + IF (ALLOCATED(work%lp_off)) DEALLOCATE (work%lp_off, work%lp_row) + IF (ALLOCATED(work%line_pv)) DEALLOCATE (work%line_pv, work%line_pd, work%line_pm) ALLOCATE (work%ch_kind(n), work%ch_line(n), work%ch_node(n), work%ch_comp(n), work%ch_aux(n), work%ch_val(n)) ALLOCATE (work%line_ndof(nl), work%line_ne(nl), work%state_off(nl + 1), work%ten_off(nl + 1), & work%state_row(nl), work%ten_row(nl)) @@ -35857,6 +35912,8 @@ SUBROUTINE build_plan() work%state_row = 0 work%ten_row = 0 work%row = 0 + ALLOCATE (work%lp_off(nl + 1), work%lp_row(nl)) + work%lp_row = 0 DO j = 1, n lo = to_lower(channels(j)) @@ -35925,13 +35982,18 @@ SUBROUTINE build_plan() ELSE CALL parse_line_node_channel(channels(j), il, node, kind, comp) ! from the line model, channel-at-a-time (CH_LEGACY) - IF (is_load_power_kind(kind) .OR. kind == 21) CYCLE + IF (kind == 21) CYCLE il = find_line(lines, il) IF (il < 1) CYCLE CALL line_sizes(il, sized, tension_sized) IF (.NOT. sized) CYCLE IF (node < 1 .OR. node > work%line_ndof(il)/stride) CYCLE - IF (kind == 3) THEN + IF (is_load_power_kind(kind)) THEN + ! the line's node load powers, evaluated once per row for all its power channels + work%ch_kind(j) = CH_LOAD_POWER + work%ch_node(j) = deck_to_internal_node(node, work%line_ndof(il)/stride - 1) + work%ch_aux(j) = kind + ELSE IF (kind == 3) THEN IF (.NOT. tension_sized) CYCLE work%ch_kind(j) = CH_NODE_TEN work%ch_node(j) = deck_to_internal_node(node, work%line_ne(il)) @@ -35947,12 +36009,16 @@ SUBROUTINE build_plan() work%state_off(1) = 0 work%ten_off(1) = 0 + work%lp_off(1) = 0 DO il = 1, nl work%state_off(il + 1) = work%state_off(il) + work%line_ndof(il) work%ten_off(il + 1) = work%ten_off(il) + MAX(0, work%line_ne(il)) + work%lp_off(il + 1) = work%lp_off(il) + work%line_ndof(il)/stride END DO ALLOCATE (work%line_q(work%state_off(nl + 1)), work%line_v(work%state_off(nl + 1)), & work%line_a(work%state_off(nl + 1)), work%line_ten(work%ten_off(nl + 1))) + ALLOCATE (work%line_pv(work%lp_off(nl + 1)), work%line_pd(work%lp_off(nl + 1)), & + work%line_pm(work%lp_off(nl + 1))) work%plan_ready = .TRUE. work%plan_motion = has_motion END SUBROUTINE build_plan @@ -40176,7 +40242,7 @@ SUBROUTINE sys_solvefail(ch, em, ErrStat, ErrMsg) ErrMsg = 'CableDyn_DeckDriver: OUTPUT "'//TRIM(ch)//'": '//TRIM(em) END SUBROUTINE sys_solvefail - SUBROUTINE eval_cable_channel(cable, ch, val, ErrStat, ErrMsg, mesh_node) + SUBROUTINE eval_cable_channel(cable, ch, val, ErrStat, ErrMsg, mesh_node, power) !! Evaluate one channel for a finite-EI Hermite power cable (CD_HFMF). Reads the cable's !! committed state directly from the CD_HFMF !! line (stride-6 DOFs: r at 6*(n-1)+1..3, tangent m at +4..6) and recovers the @@ -40187,13 +40253,16 @@ SUBROUTINE eval_cable_channel(cable, ch, val, ErrStat, ErrMsg, mesh_node) !! names a deck node (1 + the total NumSegs of the line's sections, End A first), read at its !! node of the final mesh on a refined line (cable%deck_node); mesh_node = .TRUE. reads the !! token's node as a node of the final mesh instead (the static profile and the C API line - !! arrays list every mesh node). + !! arrays list every mesh node). power (optional), the cable's load powers at its present + !! state: a load power channel takes them when they are valid and stores them otherwise, so + !! the load power channels of one output row evaluate them once. TYPE(CD_HFMF_ModuleType), INTENT(INOUT) :: cable CHARACTER(*), INTENT(IN) :: ch REAL(wp), INTENT(OUT) :: val INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg LOGICAL, INTENT(IN), OPTIONAL :: mesh_node + TYPE(LoadPowerRow), INTENT(INOUT), OPTIONAL :: power CHARACTER(NAMELEN) :: lo INTEGER :: line_id, node, kind, comp, nnode, nelem, inode, es @@ -40279,6 +40348,13 @@ SUBROUTINE eval_cable_channel(cable, ch, val, ErrStat, ErrMsg, mesh_node) inode = deck_to_internal_node(node, nelem) SELECT CASE (kind) CASE (15:20) ! load power: the line total, or per unit length about the node + IF (PRESENT(power)) THEN + IF (power%valid) THEN + ! the row's earlier load power channel of this cable evaluated them at this state + val = load_power_value(kind, inode, power%pv, power%pd, power%pm, cable%line%l0) + RETURN + END IF + END IF BLOCK REAL(wp) :: pv(nnode), pd(nnode), pm(nnode) CALL CD_HermiteCable_Dyn_Load_Power(cable%line, pv, pd, pm, es, em) @@ -40287,6 +40363,12 @@ SUBROUTINE eval_cable_channel(cable, ch, val, ErrStat, ErrMsg, mesh_node) TRIM(em)); RETURN END IF val = load_power_value(kind, inode, pv, pd, pm, cable%line%l0) + IF (PRESENT(power)) THEN + power%pv = pv + power%pd = pd + power%pm = pm + power%valid = .TRUE. + END IF END BLOCK CASE (21) ! the smoothed VIV amplitude estimate of the node (VIV AMPLITUDE) BLOCK diff --git a/src/CableDyn_HermiteCable.f90 b/src/CableDyn_HermiteCable.f90 index f3b32c6..45e3690 100644 --- a/src/CableDyn_HermiteCable.f90 +++ b/src/CableDyn_HermiteCable.f90 @@ -494,49 +494,53 @@ SUBROUTINE CD_HermiteCable_Bending_Damping(qr, vr, L, Bb, fdamp, Kq, Kv, ErrStat DO jj = 1, 6 J(:, jj) = Dcr(:, jj)*g + cr*Dg(jj) END DO - ! second derivatives of kappa = cr g: T(i,j,k) = d2 kappa_i / dx_j dx_k, x = (a, b) - DO k = 1, 6 - DO jj = 1, 6 - DO i = 1, 3 - acc = Dcr(i, jj)*Dg(k) + Dcr(i, k)*Dg(jj) - IF (jj <= 3 .AND. k >= 4) acc = acc + levi(i, jj, k - 3)*g - IF (jj >= 4 .AND. k <= 3) acc = acc + levi(i, k, jj - 3)*g - IF (jj <= 3 .AND. k <= 3) THEN - acc = acc + cr(i)*gaa2*a6(jj)*a6(k) - IF (jj == k) acc = acc + cr(i)*ga - END IF - T(i, jj, k) = acc - END DO - END DO - END DO - ! projector P = I - t t^T and dP(i,m,k) = d P_im / d a_k (zero for b) + ! projector P = I - t t^T DO m = 1, 3 DO i = 1, 3 Pm(i, m) = -tv(i)*tv(m) END DO Pm(m, m) = Pm(m, m) + CD_ONE END DO - DO k = 1, 3 - DO m = 1, 3 - DO i = 1, 3 - dik = CD_ZERO; IF (i == k) dik = CD_ONE - dmk = CD_ZERO; IF (m == k) dmk = CD_ONE - dP(i, m, k) = -(((dik - tv(i)*tv(k))/sp)*tv(m) + tv(i)*((dmk - tv(m)*tv(k))/sp)) - END DO - END DO - END DO Km = MATMUL(Pm, J) kr = MATMUL(Km, xd) - ! dK(i,j,k) = d K_ij / d x_k = sum_m dP(i,m,k) J(m,j) + sum_m P(i,m) T(m,j,k) - DO k = 1, 6 - DO jj = 1, 6 - DO i = 1, 3 - acc = SUM(Pm(i, :)*T(:, jj, k)) - IF (k <= 3) acc = acc + SUM(dP(i, :, k)*J(:, jj)) - dK(i, jj, k) = acc + IF (PRESENT(Kq)) THEN + ! the second derivatives the position Jacobian alone takes (the force does not) + ! second derivatives of kappa = cr g: T(i,j,k) = d2 kappa_i / dx_j dx_k, x = (a, b) + DO k = 1, 6 + DO jj = 1, 6 + DO i = 1, 3 + acc = Dcr(i, jj)*Dg(k) + Dcr(i, k)*Dg(jj) + IF (jj <= 3 .AND. k >= 4) acc = acc + levi(i, jj, k - 3)*g + IF (jj >= 4 .AND. k <= 3) acc = acc + levi(i, k, jj - 3)*g + IF (jj <= 3 .AND. k <= 3) THEN + acc = acc + cr(i)*gaa2*a6(jj)*a6(k) + IF (jj == k) acc = acc + cr(i)*ga + END IF + T(i, jj, k) = acc + END DO END DO END DO - END DO + ! dP(i,m,k) = d P_im / d a_k (zero for b) + DO k = 1, 3 + DO m = 1, 3 + DO i = 1, 3 + dik = CD_ZERO; IF (i == k) dik = CD_ONE + dmk = CD_ZERO; IF (m == k) dmk = CD_ONE + dP(i, m, k) = -(((dik - tv(i)*tv(k))/sp)*tv(m) + tv(i)*((dmk - tv(m)*tv(k))/sp)) + END DO + END DO + END DO + ! dK(i,j,k) = d K_ij / d x_k = sum_m dP(i,m,k) J(m,j) + sum_m P(i,m) T(m,j,k) + DO k = 1, 6 + DO jj = 1, 6 + DO i = 1, 3 + acc = SUM(Pm(i, :)*T(:, jj, k)) + IF (k <= 3) acc = acc + SUM(dP(i, :, k)*J(:, jj)) + dK(i, jj, k) = acc + END DO + END DO + END DO + END IF g6 = Bb*MATMUL(TRANSPOSE(Km), kr) IF (PRESENT(Kv) .OR. (PRESENT(Kq) .AND. has_rate)) V6 = Bb*MATMUL(TRANSPOSE(Km), Km) IF (PRESENT(Kq)) THEN diff --git a/tests/test_load_power_deck.f90 b/tests/test_load_power_deck.f90 index b98930d..bd2ff57 100644 --- a/tests/test_load_power_deck.f90 +++ b/tests/test_load_power_deck.f90 @@ -16,7 +16,11 @@ PROGRAM test_load_power_deck !! the cable's VIV power within 2 %; !! P4 the EI = 0 line split at a free point into two lines (the multi-line system) balances !! within 1 % over both lines; - !! P5 malformed channels, an unknown line, node 0 and a node past the end are refused. + !! P5 malformed channels, an unknown line, node 0 and a node past the end are refused; + !! P6 a row evaluates a line's node powers once for all its load power channels: a channel + !! read alone (DampPow1 of the cable, DragPow1 of the EI = 0 line, DampPow2 of the system) + !! takes the same values, to the printed digits, as among the line's other power channels + !! (P1, P3, P4), and they change from row to row. USE CableDyn_Precision, ONLY: wp USE CableDyn_DeckDriver, ONLY: CD_Run_Deck_Driver, CD_DECKDRV_OK IMPLICIT NONE @@ -29,6 +33,9 @@ PROGRAM test_load_power_deck CALL check_ei0() CALL check_system() CALL check_refusals() + CALL check_shared('P6 finite-EI cable', 'lpd_cab', '1.0', 'DampPow1', .FALSE., 4, 4) + CALL check_shared('P6 EI = 0 line', 'lpd_ei0', '0.0', 'DragPow1', .FALSE., 3, 3) + CALL check_shared('P6 system', 'lpd_sys', '0.0', 'DampPow2', .TRUE., 6, 7) IF (nfail > 0) THEN WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed' ERROR STOP 1 @@ -272,6 +279,29 @@ SUBROUTINE check_system() CALL balance('P4 two EI = 0 lines and a free point', tab, n, 2, pv) END SUBROUTINE check_system + SUBROUTINE check_shared(label, root, ei, channel, split, ncol, col) + !! Channel `channel` read alone against column `col` of the earlier run `root` (ncol channels), + !! which evaluated it among the line's other load power channels, over the rows from 50 s. + CHARACTER(*), INTENT(IN) :: label, root, ei, channel + LOGICAL, INTENT(IN) :: split + INTEGER, INTENT(IN) :: ncol, col + REAL(wp), ALLOCATABLE :: tab(:, :), one(:, :) + INTEGER :: n, n1 + LOGICAL :: ok + CHARACTER(1024) :: msg + CALL write_deck('lpd_one.dat', ei, channel, split, 52.0_wp) + CALL run('lpd_one.dat', 'lpd_one', ok, msg) + CALL require(ok, label//': the one-channel deck runs: '//TRIM(msg)) + IF (.NOT. ok) RETURN + CALL read_out('lpd_one.out', 1, one, n1) + CALL read_out(root//'.out', ncol, tab, n) + CALL require(n1 > 100 .AND. n >= n1, label//': the runs wrote their rows') + IF (.NOT. (n1 > 100 .AND. n >= n1)) RETURN + CALL require(ALL(one(1, 1:n1) == tab(1, 1:n1)) .AND. ALL(one(2, 1:n1) == tab(col, 1:n1)), & + label//': the channel alone equals the channel among the line''s power channels') + CALL require(ANY(one(2, 2:n1) /= one(2, 1)), label//': the channel changes from row to row') + END SUBROUTINE check_shared + SUBROUTINE check_refusals() CALL refused('VIVPow0', 'bad load power channel', 'line 0') CALL refused('DragPow7', 'bad load power channel', 'an unknown line') diff --git a/tests/test_viv_long_run.f90 b/tests/test_viv_long_run.f90 new file mode 100644 index 0000000..232f62a --- /dev/null +++ b/tests/test_viv_long_run.f90 @@ -0,0 +1,471 @@ +! File: tests/test_viv_long_run.f90 +! SPDX-License-Identifier: Apache-2.0 +! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +PROGRAM test_viv_long_run + !! Long runs of the cross-flow VIV synchronisation model (CableDyn_VIV): hundreds of cycles, as a + !! VIV study runs them, at 100 steps per cycle. The shedding phase advances by Heun's rule + !! (viv_step_begin / viv_step_end of both line kinds), so its error must grow linearly in time + !! and fall with dt^2; the load powers must close the energy balance over the whole run; and a + !! locked-in response must be stationary. Every tolerance below comes from a dt sweep (25, 50, + !! 100, 200, 400 steps per cycle, gfortran Release) and is stated with the measured value. + !! + !! P Prescribed motion, the finite-EI cable (10 elements, 20 m, every node's position held and + !! moved): all nodes move across a uniform flow U = 0.3 m/s (along y) as a rigid body, + !! z = z0 - A cos(om t), A = 1e-6 m (the phase does not depend on A; a small A keeps the + !! relative flow and so U and the cross-flow axis fixed to (A om/U)^2 ~ 1e-10). The running + !! mean squares start at those of the motion and average over 1000 s, so the motion phase is + !! phi_y = om t - pi/2 to the averaging ripple (about 1e-4 rad), and psi = phi_y - phi obeys + !! Adler's equation d psi/dt = a - b sin(psi), a = om - Om cF, b = Om dF, Om = 2 pi U/D, + !! whose solution is closed form: tan(psi/2) = (b + s tan(theta/2))/a, theta = theta0 + s t, + !! s = sqrt(a^2 - b^2) outside the band (a > b), and psi -> asin(a/b) inside it. + !! P1 outside the band (om 5.5 rad/s, slip period 2 pi/s = 4.3 s), 400 motion cycles: the + !! largest phase error over the 11 nodes against the closed form grows linearly: error(T)/ + !! error(T/2) in [1.8, 2.2] (linear 2, quadratic 4; measured 2.014 and 1.988 at 50 and 100 + !! steps per cycle); + !! P2 it is second order: error at 50 over error at 100 steps per cycle in [3.6, 4.4] + !! (measured 4.01), and at 100 steps per cycle at most 0.05 rad after 400 cycles (measured + !! 0.0167, i.e. 4e-5 rad per cycle); + !! P3 inside the band (om = Om (cF + dF/2), psi* = pi/6), 50 steps per cycle: the phase lag + !! stays within 1e-4 rad of psi* at T/2 and T (measured 2.9e-5 at 25, 50 and 100 steps per + !! cycle: the averaging-ripple floor, not the step) and does not grow (error(T) <= + !! 1.1 error(T/2), measured 1.0004), and the mean shedding rate over the second half is om + !! within 1e-8 (measured 5.8e-12). + !! + !! C Lock-in, both line kinds: a weightless taut line (20 m, 10 elements, D 0.1 m, 8.1 kg/m, + !! EA 5e7 N, 3.8 kN, the finite-EI cable EI 1e3 N m^2, no added mass so that the structural + !! energy is the whole stored energy), pinned at both ends in the 0.3 m/s cross current, Cl + !! 0.8, cF 0.18, dF 0.08, Cd 1.2, running RMS window 0.25 s (the examples' value), rho_inf = 1 + !! (no numerical damping, so that the load powers are the whole energy change). It locks in at + !! about 0.63 Hz with a mid-span A/D of 0.56-0.57. 400 cycles of the nominal shedding period + !! D/(cF U) = 1.85 s (740 s) at 100 and at 200 steps per cycle. + !! C1 energy: E(t) - E(0) = int (P_viv + P_drag + P_damp) dt (trapezoidal), the mismatch at + !! most 3e-4 of the VIV work at 100 steps per cycle (measured 2.0e-4 finite EI, 1.8e-4 + !! EI = 0: the lift takes the phase predicted from the previous step's mid-point rate, half + !! a step behind the step's own, a second-order lag), second order (the ratio from 100 to + !! 200 steps per cycle in [3, 5], measured 3.98 and 3.67), and it accumulates with the work + !! and not faster: the mismatch fraction at T within 1.25 times that at T/2 (measured 1.00 + !! and 1.00); + !! C2 statistics over the last three quarters of the run, its two halves: the mid-span RMS + !! A/D within 2e-3 and the mean VIV power within 1e-2 of each other (measured 7.3e-4 and + !! 1.8e-3 finite EI, 4.1e-4 and 9.0e-4 EI = 0), the same bounds as the change of the + !! second half's values from 100 to 200 steps per cycle must meet (measured A/D 7.9e-5 and + !! 6.0e-4, power 1.1e-3 and 3.3e-4), so a drift between the halves stays below the + !! discretisation error of the statistic; + !! C3 phase: the mean shedding rate (the lock-in frequency) of the mid-span node over the two + !! halves agrees within 2e-3 (measured 7.4e-5 finite EI, 1.9e-4 EI = 0), so the phase error + !! against a finer step grows linearly (a frequency offset) and not quadratically, and the + !! second half's rate changes by at most 5e-3 from 100 to 200 steps per cycle (measured + !! 1.6e-4 finite EI, 1.9e-4 EI = 0). The coupled lock-in frequency converges at second + !! order (test viv_step_order). + USE CableDyn_Precision, ONLY: wp + USE CableDyn_VIV, ONLY: CD_VIV_TWO_PI + USE CableDyn_HermiteCableDynamic, ONLY: CD_HermiteCableDynType, CD_HermiteCable_Dyn_Init, & + CD_HermiteCable_Dyn_Set_Drag, CD_HermiteCable_Dyn_Set_VIV, & + CD_HermiteCable_Dyn_Step, CD_HermiteCable_Dyn_Recompute_Acceleration, & + CD_HermiteCable_Dyn_Energy, CD_HermiteCable_Dyn_Load_Power, & + CD_HermiteCable_Dyn_End, CD_HCDYN_OK + USE CableDyn_Dynamic, ONLY: GenAlphaConfig + USE CableDyn_Model, ONLY: CD_ModelType, CD_Init_Model, CD_Set_Model_VIV, CD_Step_Model, CD_End_Model, & + CD_Recompute_Model_Acceleration, CD_Get_Model_Load_Power, CD_MODEL_OK + IMPLICIT NONE + + REAL(wp), PARAMETER :: PI = 3.14159265358979323846_wp + REAL(wp), PARAMETER :: RHOW = 1025.0_wp, D = 0.1_wp, CF = 0.18_wp, DF = 0.08_wp, U = 0.3_wp + REAL(wp), PARAMETER :: OMS = CD_VIV_TWO_PI*U/D + INTEGER, PARAMETER :: NCYC = 400 + + !> The results of one lock-in run (C): the energy mismatch over the VIV work at T/2 and T, the + !> mid-span RMS A/D and mean VIV power over the two halves of the last three quarters, and the + !> mean shedding rate of the mid-span node over the same halves. + TYPE :: lockin_result + LOGICAL :: ok = .FALSE. + REAL(wp) :: closure(2) = 0.0_wp, ad(2) = 0.0_wp, pviv(2) = 0.0_wp, rate(2) = 0.0_wp + END TYPE lockin_result + + INTEGER :: nfail = 0 + + CALL check_prescribed() + CALL check_lockin(.TRUE., 'finite-EI cable') + CALL check_lockin(.FALSE., 'EI = 0 line') + IF (nfail > 0) THEN + WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed' + ERROR STOP 1 + END IF + WRITE (*, '(A)') 'PASS: long-run VIV phase, energy and statistics' + +CONTAINS + + SUBROUTINE require(cond, label) + LOGICAL, INTENT(IN) :: cond + CHARACTER(*), INTENT(IN) :: label + IF (cond) RETURN + nfail = nfail + 1 + WRITE (*, '(A)') 'FAIL: '//TRIM(label) + END SUBROUTINE require + + PURE REAL(wp) FUNCTION wrap_pi(x) RESULT(y) + !! x mapped to [-pi, pi]. + REAL(wp), INTENT(IN) :: x + y = x - CD_VIV_TWO_PI*ANINT(x/CD_VIV_TWO_PI) + END FUNCTION wrap_pi + + PURE REAL(wp) FUNCTION rel(x, y) RESULT(r) + !! The relative difference of two statistics. + REAL(wp), INTENT(IN) :: x, y + r = ABS(x - y)/MAX(ABS(x), ABS(y), TINY(1.0_wp)) + END FUNCTION rel + + PURE REAL(wp) FUNCTION adler_psi(t, psi0, a, b) RESULT(psi) + !! The continuous solution of d psi/dt = a - b sin(psi), a > b > 0, from psi(0) = psi0 in + !! (-pi, pi): tan(psi/2) = (b + s tan(theta/2))/a, theta = theta0 + s t, s = sqrt(a^2 - b^2), + !! continued over the turns of theta. + REAL(wp), INTENT(IN) :: t, psi0, a, b + REAL(wp) :: s, th, thr, k + s = SQRT(a*a - b*b) + th = 2.0_wp*ATAN((a*TAN(0.5_wp*psi0) - b)/s) + s*t + k = ANINT(th/CD_VIV_TWO_PI) + thr = th - CD_VIV_TWO_PI*k + psi = CD_VIV_TWO_PI*k + 2.0_wp*ATAN((b + s*TAN(0.5_wp*thr))/a) + END FUNCTION adler_psi + + SUBROUTINE check_prescribed() + REAL(wp) :: e50(2), e100(2), el(2), rate_err + LOGICAL :: ok + CALL prescribed(5.5_wp, 50, e50, rate_err, ok) + IF (.NOT. ok) RETURN + CALL prescribed(5.5_wp, 100, e100, rate_err, ok) + IF (.NOT. ok) RETURN + WRITE (*, '(A,2ES11.3,A,2ES11.3)') ' P1/P2 outside the band, phase error at T/2, T: 50 steps ', e50, & + ', 100 steps ', e100 + WRITE (*, '(A,3F8.4)') ' P1/P2 growth T/(T/2) at 50, 100 steps, order 50/100: ', e50(2)/e50(1), e100(2)/e100(1), & + e50(2)/e100(2) + CALL require(e50(2) >= 1.8_wp*e50(1) .AND. e50(2) <= 2.2_wp*e50(1) .AND. & + e100(2) >= 1.8_wp*e100(1) .AND. e100(2) <= 2.2_wp*e100(1), & + 'P1: the phase error grows linearly in time') + CALL require(e50(2) >= 3.6_wp*e100(2) .AND. e50(2) <= 4.4_wp*e100(2), 'P2: the phase error is second order') + CALL require(e100(2) <= 0.05_wp, 'P2: at most 0.05 rad after 400 cycles at 100 steps per cycle') + CALL prescribed(OMS*(CF + 0.5_wp*DF), 50, el, rate_err, ok) + IF (.NOT. ok) RETURN + WRITE (*, '(A,2ES11.3,A,ES11.3)') ' P3 inside the band, phase-lag error at T/2, T: ', el, & + ', mean rate error ', rate_err + CALL require(MAXVAL(el) <= 1.0e-4_wp .AND. el(2) <= 1.1_wp*el(1), 'P3: the locked phase lag holds') + CALL require(rate_err <= 1.0e-8_wp, 'P3: the locked shedding rate is the motion frequency') + END SUBROUTINE check_prescribed + + SUBROUTINE prescribed(om, nper, err, rate_err, ok) + !! Every node of the straight cable moved across the flow as a rigid body at om, nper steps per + !! motion cycle over NCYC cycles: err the largest phase error over the nodes at T/2 and T + !! (outside the band against the closed form, inside it the phase lag against psi*), rate_err + !! the relative error of the mean shedding rate over the second half inside the band. + REAL(wp), INTENT(IN) :: om + INTEGER, INTENT(IN) :: nper + REAL(wp), INTENT(OUT) :: err(2), rate_err + LOGICAL, INTENT(OUT) :: ok + INTEGER, PARAMETER :: NE = 10, NN = NE + 1 + REAL(wp), PARAMETER :: SPAN = 20.0_wp, AMP = 1.0e-6_wp, Z0 = -50.0_wp, TW = 1.0e3_wp + TYPE(CD_HermiteCableDynType) :: m + REAL(wp) :: seed(6*NN), l0(NE), eav(NE), eiv(NE), rhoa(NE), wv(NE), hd(NE), hn(NE), ht(NE) + REAL(wp) :: cl(NE), cfv(NE), dfv(NE), pq(3*NN), pv(3*NN), pa(3*NN), dt, t, a, b, phi0(NN), psi0(NN) + REAL(wp) :: phu(NN), phold(NN), ex, e, ph_half(NN), psi_star + INTEGER :: pdofs(3*NN), i, n, nstep, es + CHARACTER(1024) :: em + LOGICAL :: locked + err = 0.0_wp; rate_err = 0.0_wp + seed = 0.0_wp + DO i = 1, NN + seed(6*(i - 1) + 1) = SPAN*REAL(i - 1, wp)/REAL(NE, wp) + seed(6*(i - 1) + 3) = Z0 - AMP + seed(6*(i - 1) + 4) = 1.0_wp + pdofs(3*i - 2:3*i) = [6*(i - 1) + 1, 6*(i - 1) + 2, 6*(i - 1) + 3] + END DO + ! a stiff, unstretched cable: the slopes (free) barely turn under the tiny lift and the drag + l0 = SPAN/REAL(NE, wp); eav = 5.0e7_wp; eiv = 1.0e6_wp; rhoa = 8.1_wp; wv = 0.0_wp + CALL CD_HermiteCable_Dyn_Init(m, l0, eav, eiv, rhoa, wv, seed, pdofs, -1.0e4_wp, 0.0_wp, 1.0_wp, es, em) + ok = es == CD_HCDYN_OK + CALL require(ok, 'P: init: '//TRIM(em)) + IF (.NOT. ok) RETURN + hd = D; hn = 1.2_wp; ht = 0.0_wp + CALL CD_HermiteCable_Dyn_Set_Drag(m, RHOW, hd, hn, ht, 0.0_wp, [0.0_wp, U, 0.0_wp], es, em) + ok = es == CD_HCDYN_OK + CALL require(ok, 'P: drag: '//TRIM(em)) + IF (.NOT. ok) RETURN + cl = 1.0e-3_wp; cfv = CF; dfv = DF + CALL CD_HermiteCable_Dyn_Set_VIV(m, cl, cfv, dfv, TW, es, em) + ok = es == CD_HCDYN_OK + CALL require(ok, 'P: VIV: '//TRIM(em)) + IF (.NOT. ok) RETURN + CALL kin(0.0_wp, om, seed, AMP, Z0, NN, pq, pv, pa) + CALL CD_HermiteCable_Dyn_Recompute_Acceleration(m, es, em, pres_dofs=pdofs, pres_a=pa) + ok = es == CD_HCDYN_OK + CALL require(ok, 'P: start acceleration: '//TRIM(em)) + IF (.NOT. ok) RETURN + ! the running mean squares start at those of the motion, y' = A om sin(om t) + m%viv_ms(1, :) = 0.5_wp*(AMP*om)**2 + m%viv_ms(2, :) = 0.5_wp*(AMP*om*om)**2 + a = om - OMS*CF + b = OMS*DF + locked = ABS(a) < b + psi_star = ASIN(MAX(-1.0_wp, MIN(1.0_wp, a/b))) + phi0 = m%viv_phi + phu = phi0 + phold = phi0 + DO i = 1, NN + psi0(i) = wrap_pi(-0.5_wp*PI - phi0(i)) + END DO + dt = CD_VIV_TWO_PI/om/REAL(nper, wp) + nstep = nper*NCYC + DO n = 1, nstep + t = REAL(n, wp)*dt + CALL kin(t, om, seed, AMP, Z0, NN, pq, pv, pa) + CALL CD_HermiteCable_Dyn_Step(m, dt, 50, 1.0e-10_wp, es, em, pres_dofs=pdofs, pres_q=pq, pres_v=pv, pres_a=pa) + ok = es == CD_HCDYN_OK + CALL require(ok, 'P: step: '//TRIM(em)) + IF (.NOT. ok) EXIT + DO i = 1, NN + phu(i) = phu(i) + wrap_pi(m%viv_phi(i) - phold(i)) + phold(i) = m%viv_phi(i) + END DO + IF (n /= nstep/2 .AND. n /= nstep) CYCLE + e = 0.0_wp + DO i = 1, NN + IF (locked) THEN + ex = wrap_pi(phu(i) - (om*t - 0.5_wp*PI - psi_star)) + ELSE + ex = phu(i) - (phi0(i) + om*t - (adler_psi(t, psi0(i), a, b) - psi0(i))) + END IF + e = MAX(e, ABS(ex)) + END DO + IF (n == nstep/2) THEN + err(1) = e + ph_half = phu + ELSE + err(2) = e + END IF + END DO + IF (ok .AND. locked) rate_err = ABS(SUM(phu - ph_half)/REAL(NN, wp)/(0.5_wp*REAL(nstep, wp)*dt) - om)/om + CALL CD_HermiteCable_Dyn_End(m) + END SUBROUTINE prescribed + + SUBROUTINE kin(tt, om, seed, amp, z0, nn, pq, pv, pa) + !! The prescribed rigid-body motion of every node at time tt. + REAL(wp), INTENT(IN) :: tt, om, seed(:), amp, z0 + INTEGER, INTENT(IN) :: nn + REAL(wp), INTENT(OUT) :: pq(:), pv(:), pa(:) + INTEGER :: j + DO j = 1, nn + pq(3*j - 2:3*j) = [seed(6*(j - 1) + 1), 0.0_wp, z0 - amp*COS(om*tt)] + pv(3*j - 2:3*j) = [0.0_wp, 0.0_wp, amp*om*SIN(om*tt)] + pa(3*j - 2:3*j) = [0.0_wp, 0.0_wp, amp*om*om*COS(om*tt)] + END DO + END SUBROUTINE kin + + SUBROUTINE check_lockin(finite_ei, label) + LOGICAL, INTENT(IN) :: finite_ei + CHARACTER(*), INTENT(IN) :: label + TYPE(lockin_result) :: r1, r2 + CALL lockin(finite_ei, 100, r1) + IF (.NOT. r1%ok) RETURN + CALL lockin(finite_ei, 200, r2) + IF (.NOT. r2%ok) RETURN + WRITE (*, '(3A,2ES11.3,A,2ES11.3)') ' C1 ', label, ': energy mismatch / VIV work at T/2, T, 100 steps ', & + r1%closure, ', 200 steps ', r2%closure + WRITE (*, '(3A,4F11.6)') ' C2 ', label, ': RMS A/D and VIV power [W] over the halves ', r1%ad/D, r1%pviv + WRITE (*, '(3A,2F12.8,A,F12.8)') ' C3 ', label, ': mean shedding rate [rad/s] over the halves ', r1%rate, & + ', at 200 steps ', r2%rate(2) + WRITE (*, '(3A,5ES10.2)') ' ', label, ': halves A/D, power, rate; 100 to 200 steps A/D, power ', & + rel(r1%ad(1), r1%ad(2)), rel(r1%pviv(1), r1%pviv(2)), rel(r1%rate(1), r1%rate(2)), & + rel(r1%ad(2), r2%ad(2)), rel(r1%pviv(2), r2%pviv(2)) + CALL require(ABS(r1%closure(2)) <= 3.0e-4_wp, 'C1 '//label//': the load powers close the energy balance') + CALL require(ABS(r1%closure(2)) >= 3.0_wp*ABS(r2%closure(2)) .AND. & + ABS(r1%closure(2)) <= 5.0_wp*ABS(r2%closure(2)), 'C1 '//label//': the mismatch is second order') + CALL require(ABS(r1%closure(2)) <= 1.25_wp*ABS(r1%closure(1)), & + 'C1 '//label//': the mismatch grows no faster than the work') + CALL require(rel(r1%ad(1), r1%ad(2)) <= 2.0e-3_wp .AND. rel(r1%pviv(1), r1%pviv(2)) <= 1.0e-2_wp, & + 'C2 '//label//': the response is stationary') + CALL require(rel(r1%ad(2), r2%ad(2)) <= 2.0e-3_wp .AND. rel(r1%pviv(2), r2%pviv(2)) <= 1.0e-2_wp, & + 'C2 '//label//': the statistics are converged in the step') + CALL require(rel(r1%rate(1), r1%rate(2)) <= 2.0e-3_wp, 'C3 '//label//': the lock-in frequency does not drift') + CALL require(rel(r1%rate(2), r2%rate(2)) <= 5.0e-3_wp, 'C3 '//label//': the lock-in frequency is converged') + END SUBROUTINE check_lockin + + SUBROUTINE lockin(finite_ei, nper, res) + !! The taut line locked in over NCYC nominal cycles at nper steps per cycle. + LOGICAL, INTENT(IN) :: finite_ei + INTEGER, INTENT(IN) :: nper + TYPE(lockin_result), INTENT(OUT) :: res + INTEGER, PARAMETER :: NE = 10, NN = NE + 1, MIDN = NE/2 + 1 + REAL(wp), PARAMETER :: SPAN = 20.0_wp, Z0 = -50.0_wp, EA = 5.0e7_wp, MLIN = 8.1_wp, TENS = 3.8e3_wp + REAL(wp), PARAMETER :: TW = 0.25_wp + TYPE(CD_HermiteCableDynType) :: hm + TYPE(CD_ModelType) :: em0 + TYPE(GenAlphaConfig) :: cfg + REAL(wp) :: seed(6*NN), l0(NE), eav(NE), eiv(NE), rhoa(NE), wv(NE), hd(NE), hn(NE), ht(NE) + REAL(wp) :: cl(NE), cfv(NE), dfv(NE), dt, tv, e0, e_now, p_prev(3), p_now(3), work(3) + REAL(wp) :: q0(3*NN), v0(3*NN), fext(3*NN), fluid(3, NN), wl(NN), z, ph, phold, phu, s2(2), sp(2), cnt(2) + REAL(wp) :: ph_mark(3) + INTEGER :: conn(2, NE), i, n, nstep, es, n_iter, n0, n1, h + CHARACTER(1024) :: em + LOGICAL :: conv, stalled, ok + tv = D/(CF*U) + dt = tv/REAL(nper, wp) + nstep = nper*NCYC + ! the statistics window: the last three quarters, in two halves (n0, n1] and (n1, nstep] + n0 = nper*(NCYC/4) + n1 = nper*(NCYC/4 + (NCYC - NCYC/4)/2) + cl = 0.8_wp; cfv = CF; dfv = DF + l0 = SPAN/REAL(NE, wp)/(1.0_wp + TENS/EA) + eav = EA; rhoa = MLIN + IF (finite_ei) THEN + seed = 0.0_wp + DO i = 1, NN + seed(6*(i - 1) + 1) = SPAN*REAL(i - 1, wp)/REAL(NE, wp) + seed(6*(i - 1) + 3) = Z0 + seed(6*(i - 1) + 4) = 1.0_wp + END DO + eiv = 1.0e3_wp; wv = 0.0_wp + CALL CD_HermiteCable_Dyn_Init(hm, l0, eav, eiv, rhoa, wv, seed, [1, 2, 3, 6*NE + 1, 6*NE + 2, 6*NE + 3], & + -1.0e4_wp, 0.0_wp, 1.0_wp, es, em) + ok = es == CD_HCDYN_OK + IF (ok) THEN + hd = D; hn = 1.2_wp; ht = 0.0_wp + CALL CD_HermiteCable_Dyn_Set_Drag(hm, RHOW, hd, hn, ht, 0.0_wp, [0.0_wp, U, 0.0_wp], es, em) + ok = es == CD_HCDYN_OK + END IF + IF (ok) THEN + CALL CD_HermiteCable_Dyn_Set_VIV(hm, cl, cfv, dfv, TW, es, em) + ok = es == CD_HCDYN_OK + END IF + CALL require(ok, 'C: the finite-EI cable sets up: '//TRIM(em)) + IF (.NOT. ok) RETURN + phold = hm%viv_phi(MIDN) + ELSE + DO i = 1, NE + conn(:, i) = [i, i + 1] + END DO + q0 = 0.0_wp + DO i = 1, NN + q0(3*i - 2) = SPAN*REAL(i - 1, wp)/REAL(NE, wp) + q0(3*i) = Z0 + END DO + v0 = 0.0_wp; fext = 0.0_wp + fluid = 0.0_wp; fluid(2, :) = U; wl = 0.0_wp + cfg%rho_inf = 1.0_wp + CALL CD_Init_Model(em0, q0, v0, conn, l0, eav, rhoa, .TRUE., fext, [1, 2, 3, 3*NN - 2, 3*NN - 1, 3*NN], cfg, & + es, em, fluid_velocity=fluid, drag_waterline_z=wl, drag_rho=RHOW, drag_diameter=D, & + drag_cdn=1.2_wp, drag_cdt=0.0_wp) + ok = es == CD_MODEL_OK + IF (ok) THEN + hd = D + CALL CD_Set_Model_VIV(em0, RHOW, cl, hd, cfv, dfv, TW, es, em) + ok = es == CD_MODEL_OK + END IF + IF (ok) THEN + CALL CD_Recompute_Model_Acceleration(em0, es, em) + ok = es == CD_MODEL_OK + END IF + CALL require(ok, 'C: the EI = 0 line sets up: '//TRIM(em)) + IF (.NOT. ok) RETURN + phold = em0%viv_phi(MIDN) + END IF + phu = phold + CALL energy(finite_ei, hm, em0, l0, EA, MLIN, e0) + CALL powers(finite_ei, hm, em0, NN, p_prev) + work = 0.0_wp + s2 = 0.0_wp; sp = 0.0_wp; cnt = 0.0_wp + ph_mark = 0.0_wp + DO n = 1, nstep + IF (finite_ei) THEN + CALL CD_HermiteCable_Dyn_Step(hm, dt, 50, 1.0e-8_wp, es, em) + ok = es == CD_HCDYN_OK + ph = hm%viv_phi(MIDN) + z = hm%q(6*(MIDN - 1) + 3) - Z0 + ELSE + CALL CD_Step_Model(em0, dt, conv, stalled, n_iter, es, em) + ok = es == CD_MODEL_OK .AND. conv + ph = em0%viv_phi(MIDN) + z = em0%q(3*MIDN) - Z0 + END IF + CALL require(ok, 'C: step: '//TRIM(em)) + IF (.NOT. ok) EXIT + phu = phu + wrap_pi(ph - phold) + phold = ph + CALL powers(finite_ei, hm, em0, NN, p_now) + work = work + 0.5_wp*dt*(p_prev + p_now) + p_prev = p_now + IF (n == n0) ph_mark(1) = phu + IF (n == n1) ph_mark(2) = phu + IF (n > n0) THEN + h = MERGE(1, 2, n <= n1) + s2(h) = s2(h) + z*z + sp(h) = sp(h) + p_now(1) + cnt(h) = cnt(h) + 1.0_wp + END IF + IF (n == nstep/2 .OR. n == nstep) THEN + CALL energy(finite_ei, hm, em0, l0, EA, MLIN, e_now) + res%closure(MERGE(1, 2, n == nstep/2)) = (e_now - e0 - SUM(work))/work(1) + END IF + END DO + ph_mark(3) = phu + IF (ok) THEN + res%ok = .TRUE. + res%ad = SQRT(2.0_wp*s2/cnt) + res%pviv = sp/cnt + res%rate(1) = (ph_mark(2) - ph_mark(1))/(REAL(n1 - n0, wp)*dt) + res%rate(2) = (ph_mark(3) - ph_mark(2))/(REAL(nstep - n1, wp)*dt) + END IF + IF (finite_ei) THEN + CALL CD_HermiteCable_Dyn_End(hm) + ELSE + CALL CD_End_Model(em0, es, em) + END IF + END SUBROUTINE lockin + + SUBROUTINE energy(finite_ei, hm, em0, l0, ea, mlin, e) + !! The line's kinetic plus elastic energy: the finite-EI cable's own (consistent mass), or for + !! the EI = 0 line the consistent translational mass (rho_a l0/6 [[2, 1], [1, 2]]) and the + !! tension-only axial strain energy EA (l - l0)^2/(2 l0). + LOGICAL, INTENT(IN) :: finite_ei + TYPE(CD_HermiteCableDynType), INTENT(IN) :: hm + TYPE(CD_ModelType), INTENT(IN) :: em0 + REAL(wp), INTENT(IN) :: l0(:), ea, mlin + REAL(wp), INTENT(OUT) :: e + INTEGER :: k, ia, ib, ess + REAL(wp) :: l, kin_, str_ + CHARACTER(256) :: emm + IF (finite_ei) THEN + CALL CD_HermiteCable_Dyn_Energy(hm, kin_, str_, ess, emm) + CALL require(ess == CD_HCDYN_OK, 'C: energy: '//TRIM(emm)) + e = kin_ + str_ + ELSE + e = 0.0_wp + DO k = 1, SIZE(l0) + ia = 3*k - 2; ib = 3*k + 1 + e = e + mlin*l0(k)/6.0_wp*(DOT_PRODUCT(em0%v(ia:ia + 2), em0%v(ia:ia + 2)) + & + DOT_PRODUCT(em0%v(ia:ia + 2), em0%v(ib:ib + 2)) + & + DOT_PRODUCT(em0%v(ib:ib + 2), em0%v(ib:ib + 2))) + l = NORM2(em0%q(ib:ib + 2) - em0%q(ia:ia + 2)) + IF (l > l0(k)) e = e + 0.5_wp*ea*(l - l0(k))**2/l0(k) + END DO + END IF + END SUBROUTINE energy + + SUBROUTINE powers(finite_ei, hm, em0, nn, p) + !! The line totals of the VIV, drag and damping powers. + LOGICAL, INTENT(IN) :: finite_ei + TYPE(CD_HermiteCableDynType), INTENT(IN) :: hm + TYPE(CD_ModelType), INTENT(IN) :: em0 + INTEGER, INTENT(IN) :: nn + REAL(wp), INTENT(OUT) :: p(3) + REAL(wp) :: pv(nn), pd(nn), pm(nn) + INTEGER :: ess + CHARACTER(256) :: emm + IF (finite_ei) THEN + CALL CD_HermiteCable_Dyn_Load_Power(hm, pv, pd, pm, ess, emm) + ELSE + CALL CD_Get_Model_Load_Power(em0, pv, pd, pm, ess, emm) + END IF + CALL require(ess == 0, 'C: load power: '//TRIM(emm)) + p = [SUM(pv), SUM(pd), SUM(pm)] + END SUBROUTINE powers + +END PROGRAM test_viv_long_run