diff --git a/CHANGELOG.md b/CHANGELOG.md index 15818222..7bc9d957 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -128,6 +128,28 @@ All notable changes to CableDyn are recorded in this file. The format follows - `CD_HermiteCable_Dyn_Curvature_Exact` and `CD_HFMF_Curvature_Exact`: the exact geometric nodal curvature of the cubic-Hermite centreline, the larger one-sided trace at a node, which `CD_HermiteCable_Dyn_Curvature` and `CD_HFMF_Curvature` returned up to 0.1.1. +- `Pinned` and `CoupledPinned`/`VesselPinned` rods in coupled OpenFAST (`CompMooring = 5`) runs. + A `Pinned` rod turns about its fixed End A, which the coupled route previously refused. A + `CoupledPinned` rod (MoorDyn-F's coupled pinned rod) is a node of the coupling mesh at its + End A that takes the platform position only: the rod turns about it with its own rotation, + the pin acceleration loading that rotation through the rod's inertia, and the node returns + the rod's net force less its inertia with zero moment. The angular acceleration in that force + is solved for the node's current acceleration, so an output probe sees the rod's effective + inertia about the pin. `PtfmInit` moves the rod with the platform, the static initial + condition balances it about its pin (a pinned rod that carries no line keeps its deck + orientation), sub-cycled steps move the pin along the host path interpolated linearly as for + every other host node, the sub-step count resolves the rod's own swing about its pin under + its weight, buoyancy and pin acceleration (`|W d_g - B d_b|` and the pin-acceleration load + over the inertia about the pin) as well as its lines, so a short pinned rod that carries no + line stays stable at a coupling step beyond its explicit limit (a `CoupledPinned` rod takes + the stiffer of its step-start and end-of-step wetting, so a pin that crosses the free surface + within a step is covered), and checkpoint restarts and correction iterations reproduce the + run bit for bit with the existing rod state mirror. An end of a `Pinned` or `CoupledPinned` rod that + carries no line needs no `RodA`/`RodB` POINT row on the coupled route; other rods still + need one at both ends. The C API runs `Pinned` rods, as its manual page already stated. The + standalone driver and the C API refuse `CoupledPinned` rods by name; FAST.Farm decks still + refuse rods, OpenFAST linearisation still refuses rods, and `CoupledPinned` bodies remain + unsupported. See the manual's OpenFAST page (Lifecycle features). ### Changed @@ -251,6 +273,55 @@ All notable changes to CableDyn are recorded in this file. The format follows ### Fixed +- Seabed contact in the explicit object sub-step estimate. The staggered march of free and + pinned rods and Rigid6 bodies (the coupled OpenFAST and C API routes, standalone rod decks and + `bodyScheme staggered`) applies the seabed penalty springs explicitly, but sized its sub-steps + from the lines, hydrostatics and (pinned rods) the swing only, so a rod or body resting on a + stiff seabed at a large coupling step could exceed the central-difference limit and be thrown + off the bed. The estimate now adds the contact springs that can act within the step + (`kBot d dl` per rod contact station, `kBot` over 1 m² at a body's reference point), in + heave, roll and pitch about the reference point, or about the pin of a pinned rod at both pin + poses. A station counts from its complete rigid-body motion: its reach + `dt |v + w x s| + dt² (|a| + |alpha x s| + |w|² |s| + g)/2` bounds its travel in every + direction, and it counts when its height above the highest floor within that horizontal + distance (the depth on a flat seabed; on a `bathymetryFile` grid the highest node of the + overlapped cells, raised for the crease rounding by the new `CD_Bathymetry_Max_Floor`) is at + most the reach plus the rod radius, so a rod sliding or turning towards a shallower bed is + covered as well as one landing. The monolithic scheme, which carries the contact in its + Jacobian, is unchanged. No shipped example or existing test changes its sub-step count. +- Line-free explicit object marches without a sub-step estimate. A standalone deck without lines + marched its bodies and rods by the explicit central difference at `dtM` with no sub-steps, and + the `bodyScheme staggered` multibody march skipped the bodies (and rods) when no `EI = 0` line + was present (finite-EI cables only), so a short pinned rod or a body on a stiff seabed could + exceed the explicit limit there. Both now take the estimate from the objects' own terms + (hydrostatic restoring, seabed contact, a pinned rod's swing about its pin), and the staggered + multibody march sizes a pinned rod as the coupled route does: its line springs through their + arms from the pin on its inertia about the pin, plus its swing and contact about the pin. A 1 m + dry pinned rod at `dtM = 0.6 s` (`omega0 dt = 2.29`) now takes 6 sub-steps on both routes and + equals a `dtM = 0.1 s` run at every row, where it previously turned over. No shipped example + or existing test changes its sub-step count. +- Further terms of the explicit object sub-step estimate (coupled and C API routes, standalone + rod decks, decks without lines and `bodyScheme staggered`; the monolithic scheme is + unchanged): a rod near the free surface adds its waterplane stiffness (`rhoW g D dl` at each + station whose section can cross the surface within the step, `rhoW g pi D^2/4` where its axis + can cross it) and takes its dry inertia, for free and pinned rods and the rods fixed to a + Rigid6 body, so a floating rod (a 5 cm rod at `omega dt = 2.2`) no longer grows; a finite-EI + cable on a body or rod of the staggered march adds its attachment spring (`EA/L` along its end + force, `T/L` across), as the explicit cable end force needs; a rod pinned to a body takes the + body's pin acceleration and a reduced-mass lower bound of its inertia about the pin; a step + that would need more than the 256-sub-step cap is warned about once per run. Of the existing + tests, only the staggered pinned-cable deck of `clamped_cable_ends` changes (10 steps now + sub-cycled 2 to 5 times; printed results unchanged); no shipped example changes. +- Seabed friction of rods and Rigid6 bodies is applied implicitly. The regularised friction + `-mu N v/sqrt(v^2 + vreg^2)` (`vreg = 1e-3 m/s`) is a damper of up to `mu N/vreg`, far stiffer + than any practical step, and was evaluated explicitly, so a rod or body resting on a + frictional bed chattered (velocity and friction flipping every step). It now enters the + implicit velocity derivative of the step as its secant coefficient `mu N/sqrt(v^2 + vreg^2)`, + as the line nodes treat it implicitly: a rod held in a cross current holds still (creep at + `vreg F/(mu N)`) where it slid back and forth at a few mm/s. This changes the results of decks + with rods or bodies on a frictional seabed; none of the shipped examples or existing tests has + one. + - Tension spikes of tension-only (`EI = 0`) lines that go slack. The generalised-α step evaluated the axial force and the dynamic loads at the blended configuration `q_α = (1 − α_f) q_{n+1} + α_f q_n`. A segment that was slack at the start of a step and diff --git a/CMakeLists.txt b/CMakeLists.txt index 7c2e0b0f..fd3bdce1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1044,6 +1044,17 @@ set_tests_properties(openfast_aggregate_touchdown PROPERTIES set_tests_properties(openfast_aggregate openfast_aggregate_touchdown PROPERTIES RESOURCE_LOCK openfast_aggregate_files) +# Pinned and CoupledPinned rods on the coupled aggregate: the compound-pendulum period, a held +# host equal to a fixed pin, constant and harmonic pin accelerations against closed forms, +# sub-cycling, snapshot/restore, the output probe, restart, PtfmInit with the static start, a +# step without the staged rods, and rod ends without a line. +add_executable(test_openfast_pinned_rod tests/test_openfast_pinned_rod.f90) +target_link_libraries(test_openfast_pinned_rod PRIVATE cabledyn_core) +file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/openfast_pinned_rod) +add_test(NAME openfast_pinned_rod COMMAND test_openfast_pinned_rod + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/openfast_pinned_rod) +set_tests_properties(openfast_pinned_rod PROPERTIES LABELS "fortran;dynamic;openfast;validation") + # Maintained IEA-15 MW mixed deck: the finite-EI power cable has a genuine multi-node # grounded run and marches through the OpenFAST aggregate at 40 Hz with host current. add_executable(test_openfast_touchdown tests/test_openfast_touchdown.f90) @@ -2395,6 +2406,7 @@ if(CABLEDYN_ENABLE_COVERAGE) test_openfast_shell test_hermite_fmf test_openfast_aggregate + test_openfast_pinned_rod test_of_mooring_counters test_ei0_mesh_scaling_counters test_c_api diff --git a/VALIDATION.md b/VALIDATION.md index df910349..7d7ce2b9 100644 --- a/VALIDATION.md +++ b/VALIDATION.md @@ -740,6 +740,7 @@ stop with a named error. | Active tension (`CtrlChan`) | Pass verified | CONTROL parsing, last-segment length/rate modulation, and exact unit tests; coupled A/B in which a ServoDyn cable-control DLL drives the same pay-out/haul-in `DeltaL` schedule into `=5` (CableDyn) and `=3` (stock MoorDyn) in one binary: hold tensions agree to <0.03% and the tension responses to <0.6% (controlled fairleads) / <0.7% (anchors) ([`validation/scripts/activetension/`](https://github.com/SMI-Lab-Inha/CableDyn/tree/main/validation/scripts/activetension), [`validation/scripts/openfast_activetension_ab.py`](https://github.com/SMI-Lab-Inha/CableDyn/blob/main/validation/scripts/openfast_activetension_ab.py)) | | Coupled `Rigid6` bodies + `Point3` buoys | Pass verified | 6-DOF `Rigid6` motion with hydrostatic (`C33`/`C44`/`C55`) restoring, checkpoint state (bit-identical `openfast -restart` of a 13.9 MN-swinging tethered body), and SeaState drag / Froude–Krylov / added mass. `Point3` buoys take buoyancy and drag/added-mass/FK; a submerged volume-only buoy takes FK. Tests: `case_coupled_rigid6`/`_mirror`/`_fluid`, `case_coupled_point3_buoy`/`_fluid` | | Coupled rigid rods | Pass verified | host-driven `RodA/B` endpoints, correction rewind, bit-identical 24-scalar-per-rod checkpoint state, and two Gauss fluid nodes per rod with SeaState drag/Froude–Krylov/added mass; `case_coupled_rod`, `_mirror`, and `_fluid` pass, and the OpenFAST module compiles with rod decks enabled | +| Coupled pinned rods (`Pinned`, `CoupledPinned`/`VesselPinned`) | Pass verified | `openfast_pinned_rod` on the aggregate: a dry rod (10 m, 500 kg) released at 30° swings with the elliptic-integral compound-pendulum period to 1.6e-4 at `dt = T/100`, End A on the pin to 0 m; a held `CoupledPinned` node reproduces the `Pinned` rod to round-off (1e-12), returns zero moment, and its force equals the analytic pin reaction to 2.0e-13 of `mg`; a pin accelerating at 2 m/s² gives the mean angle `atan(a/g)` to 1e-6 rad and the period of `sqrt(g² + a²)` to 1.6e-4; a harmonic pin motion follows the linear base-excitation solution to 1.5e-3 / 3.7e-4 of the amplitude at `T0/100` / `T0/200` (ratio 4.03); a 0.1 s step sub-cycled 7 times reproduces a run at the sub-step size to 1e-14 rad and 4e-10 N for a drifting pin; a 1 m `Pinned` rod that carries no line (dry and hanging, or buoyant and upright under water) at a 0.6 s step (`omega0 dt` 2.29 / 3.42, beyond the explicit limit 2) sub-cycles it 6 / 9 times from its own swing stiffness `|W d_g - B d_b|`, equals the run at the sub-step size bit for bit, stays within its release angle and keeps the elliptic-integral period to 6.0e-3 / 5.9e-3 (taken whole, the step turns the rod over); a `CoupledPinned` pin crossing the free surface within one step at constant velocity (a 1 kg/m rod lifted from submerged to dry in 0.1 s, `omega dt` 2.13 wet; a 33 kg/m rod lowered from dry to submerged in 0.6 s, 2.29 dry) takes at least 6 sub-steps from its step-start wetting (more from the waterplane near the surface) and ends within 5e-5 / 3e-4 rad of a run at a sixtieth of the step, where the end-of-step wetting alone gives one sub-step and an angle error of 0.20 / 0.69 rad; on a stiff seabed (`kBot` 1e7 N/m³) a `Pinned` rod whose far end rests on the bed (0.1 s step) and a `Free` rod lying on it (0.05 s step) sub-cycle their contact mode (34–36 and 26 sub-steps), stay at rest on the bed over 5 s (angle change 3.8e-3 / 4e-15 rad, the undamped static settlement) and end within 1.9e-6 / 8e-8 of a run at a tenth of the step, where the sub-steps of the lines and swing alone (1 and 4) throw them off the bed (4.2 rad, 0.8 m); an output probe returns `-m (I_c/I_p) a_p` within 1e-10 of `mg` (not `-m a_p`), and its pin force moves by 2e-11 N when the held end acceleration of the attached tethers changes their end load by 8 N; snapshot/restore, probe restore and restart overlay are bit-identical, the restored state's loads before the next step included; a step without the staged rods (the step-start pin carried by the rod) is bit-identical to the staged one; a `Free` or `Coupled` rod with an end without a line is refused by name; with `PtfmInit` the static start leaves 1.4e-8 N·m about the pin. OpenFAST (IEA-15 UMaine, JONSWAP Hs 6 m, 60 s, `dtM = DT = 0.025 s`) with line 1 hung from a 4 m `CoupledPinned` rod at its fairlead: `openfast -restart` at 30 s reproduces every later OpenFAST output row bit for bit (`NumCrctn` 0 and 1), `NumCrctn = 1` equals `NumCrctn = 0` bit for bit, and surge/heave/pitch statistics stay within 0.2 % / 0.4 % / 1.7 % (mean) of the deck with line 1 on a `Coupled` point | | Coupled finite-EI touchdown/contact | Pass verified | flat `WtrDpth` and equivalent constant structured bathymetry initialise and step with matching loads; friction and checkpoint restore are tested. The IEA-15 mixed example (its power cable on 248 elements, each at most half the bending length) has 149 grounded nodes and completes a 20 s aggregate trajectory at `dtM=0.025 s` with 2 m surge, 1 m heave, and 0.5 m/s host current, without fallback or stall recovery, at most 12 Newton iterations. A full-turbine run of the same model (one hour after a 200 s transient; TurbSim normal turbulence, 10.6 m/s, 17 % TI; JONSWAP Hs 8 m, Tp 12 s, aligned with the wind and the cable; AeroDyn with the rotor held at 7.55 rpm, no controller, rigid blades and tower; SeaState grid covering the lines) completes without recoveries or non-finite values. The cable's hang-off tension is 11.5 ± 1.1 kN (static 11.9 kN, maximum 17.9 kN). The 149 nodes grounded at the static state stay grounded, joined by one more once the platform has drifted (the touchdown moves 2.5 m toward the platform). The peak curvature is 0.156 1/m at the sag bend, 72 m from the hang-off, and 0.109 1/m at the touchdown. On the former 87-element mesh (10 m elements along the laid section) the peak was 0.160 1/m and the touchdown curvature 0.075 1/m, under-resolved by about 30 %. These curvatures were recorded before the `Curv` channels took the curvature recovered from nodal equilibrium: they are the geometric curvature of the centreline (the larger one-sided trace at a node), which `OutputRecovery element` reproduces. The chain-only twin of the run matches stock MoorDyn over 1200 s to 0.3 % in platform motion and fairlead tension statistics. The anchor tension of the laid cable stays at its static 1.23 kN (maximum 1.24 kN): the seabed friction of the 370 m laid section holds the tension changes at the touchdown. On the former mesh it read 1.39 kN (median) with wave-frequency stick-slip peaks up to 4.1 kN lasting under 1 s, which the resolved mesh does not show, and before the anchor-end correction of this release it locked at about 2.75 kN for the whole run. The run takes 27.1 min of wall time (18.8 min on the former mesh) | | `WaterKin` from file | Pass verified | See [WaterKin and SeaState modes](#waterkin-and-seastate-modes) | | Syrope polyester (`SYROPE:` syntax; [Falkenberg et al., 2017](https://cabledyn.readthedocs.io/en/latest/references.html#ref-falkenberg2017)) | Pass verified | MoorDyn-F/C `BA_s|BA_d` rate and force equations; analytic position/velocity tangents with finite-difference checks; projected, bracketed backward-Euler slow-state update with a strong-unloading boundary test; OWC running maximum; `SYROPE IC` `Tmax0/Tmean0` history with range/order checks; both states carried through every lifecycle stage and the coupled checkpoint. `BA_s` is kept separate from line axial damping (`BA`) and tested against double counting. Composite, hydrodynamic, finite-EI, current, and wave combinations stop with a named error | diff --git a/doc/capabilities.rst b/doc/capabilities.rst index 398383c7..df3a5864 100644 --- a/doc/capabilities.rst +++ b/doc/capabilities.rst @@ -179,8 +179,11 @@ and ``RODS`` are MoorDyn-compatible deck records that the driver translates; the alternative discretisation of the line. Supported translations include fixed/coupled/vessel attachments, free or connecting masses and clumps, ``Point3`` buoys, ``Rigid6`` bodies, and coupled rigid rods. In OpenFAST, ``Coupled``/``Vessel`` bodies and rods are platform-borne 6-DOF nodes that -return a force and a moment; the C API and Python run free bodies and rods in still water. The -coupled body/rod routes carry checkpoint state and SeaState drag, Froude–Krylov, and added mass. +return a force and a moment, ``CoupledPinned``/``VesselPinned`` rods turn about a platform-borne +node that takes the platform position only and returns a force with zero moment, and ``Pinned`` +rods turn about a fixed End A; ``CoupledPinned`` bodies are not supported. The C API and Python +run free, fixed and pinned rods and free bodies in still water. The coupled body/rod routes carry +checkpoint state and SeaState drag, Froude–Krylov, and added mass. ``Rigid6`` also carries the documented hydrostatic restoring terms. Consult :doc:`driver_format` before using an imported object because unsupported fields fail closed. diff --git a/doc/capi.rst b/doc/capi.rst index aad269a4..8cd3272a 100644 --- a/doc/capi.rst +++ b/doc/capi.rst @@ -862,9 +862,9 @@ Newton settings are taken from the deck. The deck's ``OUTPUTS`` section is parse but the C ABI writes no output files. **Finite-EI lines, bodies and rods.** A deck with finite-EI (``EI > 0``) lines or with a -``BODIES`` or ``RODS`` table (``Point3`` buoys, free ``Rigid6`` bodies, free, fixed or pinned -rods, with their lines) runs on the same coupled aggregate as the OpenFAST module, with these -differences from the point-system decks: +``BODIES`` or ``RODS`` table (``Point3`` buoys, free ``Rigid6`` bodies, or free, fixed and +``Pinned`` rods, with their lines; a ``Pinned`` rod turns about its fixed End A) runs on the same +coupled aggregate as the OpenFAST module, with these differences from the point-system decks: * the coupled DOFs are the ``x, y, z`` of the deck's ``Coupled``/``Vessel`` points only, in the order of `Coupled DOF layout`_ (anchors are not part of the vector); the bodies and @@ -893,6 +893,8 @@ The deck is validated under the standalone-deck rules: - Where it is supported * - ``Coupled``/``Vessel`` bodies or rods (6-DOF host nodes) - the OpenFAST module; the standalone driver with a ``motionFile`` + * - ``CoupledPinned``/``VesselPinned`` rods (a pin the host moves) + - the OpenFAST module * - a ``motionFile`` option - the standalone driver (prescribe motion through ``CableDyn_Step`` instead) * - a ``FAILURE`` section (line failures) diff --git a/doc/coupling.rst b/doc/coupling.rst index 585a92d7..12c84ab4 100644 --- a/doc/coupling.rst +++ b/doc/coupling.rst @@ -32,7 +32,8 @@ checkpoint-restart, quasi-static linearisation (``dYdu``), FAST.Farm farm-level ``C33``/``C44``/``C55`` hydrostatic restoring, restart state, and SeaState drag / Froude-Krylov / added-mass), coupled ``Point3`` buoys (buoyancy and SeaState drag / Froude-Krylov / added-mass), and coupled rigid rods with host-driven endpoints, correction rewind, checkpoint state, and two-point -Gauss SeaState sampling. +Gauss SeaState sampling, including MoorDyn-F's coupled pinned rods (``CoupledPinned``, force only) +and rods pinned to a fixed point. The input/output Jacobian has two deliberately different contracts. During an ordinary nonlinear OpenFAST run, CableDyn returns the partial direct-feedthrough derivative at fixed committed internal diff --git a/doc/driver_format.md b/doc/driver_format.md index 105bf385..e934d6cb 100644 --- a/doc/driver_format.md +++ b/doc/driver_format.md @@ -392,8 +392,23 @@ row. On this route: like those of `Coupled` points, are given at the undisplaced platform and moved by `PtfmInit`), and returns to the platform the force and moment about End A of its attached lines, weight, buoyancy, Morison loads, seabed contact and its own and added-mass inertia - (MoorDyn-F's coupled rod). `CoupledPinned` and `VesselPinned` rods are rejected by name, and on the OpenFAST route - `Pinned` rods fail closed as well (the coupled rod march does not turn a rod about its pin); + (MoorDyn-F's coupled rod); +- `CoupledPinned`/`VesselPinned` rods are pinned to the platform: each is a node of the OpenFAST + mesh at its End A (moved by `PtfmInit` with the rod, like a `Coupled` rod) that takes the + platform position only. The rod turns about the node with its own three rotations, the node + orientation and angular rates are ignored, and the node returns a force and no moment: the + rod's lines, weight, buoyancy, Morison loads and seabed contact less its own and added-mass + inertia (MoorDyn-F's coupled pinned rod). The angular acceleration in that inertia is solved + for the node's current acceleration, so the rotation feels the platform acceleration and a + CalcOutput at an off-step acceleration returns the rod's effective inertia about the pin. + `Pinned` rods turn about their fixed End A. With `bodyIC static` both start balanced about + their pins; a pinned rod that carries no line is not part of the static solve and starts at + rest in its deck orientation, turned by `PtfmInit` for a `CoupledPinned` rod (a dry pendulum + given at an angle starts at that angle). An end + of a `Pinned` or `CoupledPinned` rod that carries no line needs no `RodA`/`RodB` POINT + row on this route; every other rod needs a line or a POINT row at both ends. Outside a + coupled host a `CoupledPinned` rod is rejected by name ("requires a coupled host"), + zero-length ones included; - `Coupled`/`Vessel` bodies are platform-borne the same way: a mesh node at the body reference point, the body frame turning with the platform, returning the force and moment about the reference point of its `Body` lines, weight, buoyancy and restoring, Morison and @@ -579,10 +594,10 @@ rod lying on the bed along its whole length. |--------|---------| | `ID` | unique rod id ≥ 1 | | `RodType` | a `ROD TYPES` key | -| `Type` | `Free`, `Fixed`, `Pinned`, `Coupled`, `Vessel`, `Body`, or `BodyPinned` (MoorDyn aliases `Anchor`/`Fix`, `Pin`, `Point`/`Con`, `Ves`, `Cpld`, `BodyPin`). `Coupled`/`Vessel` rods are prescribed by `motionFile` rows for both `RodA` and `RodB`, which must preserve the rod length; in OpenFAST (`CompMooring = 5`) they follow the platform instead (see the OpenFAST route below). `Free` rods are integrated dynamically and may coexist with prescribed rods. A `Pinned` rod turns about its End A, which stays fixed; it may carry lines. A `Body` rod is fixed to Rigid6 body N: its end coordinates are in the body frame from the body reference point, and its mass, inertia, hydrostatic, Morison, and seabed loads and added mass are lumped into the body about that point. A `BodyPinned` rod has its end coordinates in the body frame too, but only its End A is held, on the body: the rod has its own three rotations, its loads reach the body as the pin force (no moment), and it may carry lines. | +| `Type` | `Free`, `Fixed`, `Pinned`, `Coupled`, `Vessel`, `CoupledPinned`, `VesselPinned`, `Body`, or `BodyPinned` (MoorDyn aliases `Anchor`/`Fix`, `Pin`, `Point`/`Con`, `Ves`, `Cpld`, `CpldPin`, `VesPin`, `BodyPin`). `Coupled`/`Vessel` rods are prescribed by `motionFile` rows for both `RodA` and `RodB`, which must preserve the rod length; in OpenFAST (`CompMooring = 5`) they follow the platform instead (see the OpenFAST route above). `CoupledPinned`/`VesselPinned` rods run only in OpenFAST, pinned at End A to a node that follows the platform position. `Free` rods are integrated dynamically and may coexist with prescribed rods. A `Pinned` rod turns about its End A, which stays fixed; it may carry lines. A `Body` rod is fixed to Rigid6 body N: its end coordinates are in the body frame from the body reference point, and its mass, inertia, hydrostatic, Morison, and seabed loads and added mass are lumped into the body about that point. A `BodyPinned` rod has its end coordinates in the body frame too, but only its End A is held, on the body: the rod has its own three rotations, its loads reach the body as the pin force (no moment), and it may carry lines. | | `XA,YA,ZA` | rod End A coordinates [m] | | `XB,YB,ZB` | rod End B coordinates [m]; distinct from End A (ignored for a zero-length rod) | -| `NumSegs` | ≥ 1; hydrodynamic segments of the rod (loads integrated per segment); seabed contact uses max(20, `NumSegs`) segments. `0` declares a zero-length rod (MoorDyn): a point-like connector at End A with no mass, volume or side loads and, having no axis, no end loads either. It becomes one point that both of its ends resolve to: `Free` for a free rod, `Fixed` for a fixed or pinned rod, `Coupled` for a coupled rod, `Body` for a rod on body N. A free zero-length rod therefore moves with the end-node mass of its lines, as a `Mass = 0` `Free` point, and `Rod` output channels of it are rejected by name (use `Point

` channels) | +| `NumSegs` | ≥ 1; hydrodynamic segments of the rod (loads integrated per segment); seabed contact uses max(20, `NumSegs`) segments. `0` declares a zero-length rod (MoorDyn): a point-like connector at End A with no mass, volume or side loads and, having no axis, no end loads either. It becomes one point that both of its ends resolve to: `Free` for a free rod, `Fixed` for a fixed or pinned rod, `Coupled` for a coupled rod or, in OpenFAST, a `CoupledPinned` rod, `Body` for a rod on body N. A free zero-length rod therefore moves with the end-node mass of its lines, as a `Mass = 0` `Free` point, and `Rod` output channels of it are rejected by name (use `Point

` channels) | | `Outputs` | `-` or `p`; `p` writes the end positions as a time series to `.Rod.p.out`, End A first | ### POINTS diff --git a/doc/migrating.rst b/doc/migrating.rst index e987db21..e4723966 100644 --- a/doc/migrating.rst +++ b/doc/migrating.rst @@ -104,7 +104,10 @@ Keyword map - supported subset: ``Point3``/``Rigid6`` bodies and rigid rods, lines attached through ``Body`` points and at rod ends (``RA``/``RB`` in ``LINES``, or ``RodA``/``RodB`` points) (:doc:`tutorial_bodies`); ``ROD TYPES`` - ``Cd Ca CdEnd CaEnd`` as in MoorDyn, with optional axial side ``CdAx CaAx`` columns + ``Cd Ca CdEnd CaEnd`` as in MoorDyn, with optional axial side ``CdAx CaAx`` columns. + ``CoupledPinned``/``VesselPinned`` rods run in OpenFAST as in MoorDyn-F (End A follows + the platform position, the rod turns about it, a force is returned without moment); + ``CoupledPinned`` bodies are rejected * - ``dtM``, ``TMax`` (standalone), ``WtrDpth``, ``rhoW``/``WtrDnsty``, ``g`` - same * - ``kBot``, ``cBot``, seabed friction coefficient diff --git a/doc/openfast.rst b/doc/openfast.rst index c8cfbe3b..92f0c401 100644 --- a/doc/openfast.rst +++ b/doc/openfast.rst @@ -272,13 +272,23 @@ without an auxiliary process: lines reject it. * **Rigid6 bodies, Point3 bodies, and rigid rods** are translated at the deck boundary; their supported loads and restrictions in coupled runs are listed in :doc:`capabilities`. Free - Rigid6 bodies and rods start at their static equilibrium with the platform at ``PtfmInit`` - (``bodyIC static``, the default), as in standalone runs. ``Coupled``/``Vessel`` rods are - platform-borne: each is a node of the coupling mesh at its End A that follows the platform - position and orientation and returns a force and a moment (MoorDyn-F's coupled rod, including - the rod's own and added-mass inertia). ``Coupled``/``Vessel`` bodies are platform-borne the - same way, with the node at the body reference point, and may share a deck with ``Free`` - bodies. ``CoupledPinned`` rods and bodies, and ``Pinned`` rods, are not supported on this route. + Rigid6 bodies, free rods and pinned rods start at their static equilibrium with the platform + at ``PtfmInit`` (``bodyIC static``, the default), as in standalone runs; one that carries no + line is not part of that solve and starts at rest in its deck pose. ``Coupled``/``Vessel`` + rods are platform-borne: each is a node of the coupling mesh at its End A that follows the + platform position and orientation and returns a force and a moment (MoorDyn-F's coupled rod, + including the rod's own and added-mass inertia). ``CoupledPinned``/``VesselPinned`` rods are + pinned to the platform: the node at End A follows the platform position only, the rod turns + about it with its own rotation (the node orientation and angular rates are ignored), and the + node returns a force with zero moment (MoorDyn-F's coupled pinned rod). That force is the + rod's net load less its inertia, with the angular acceleration solved for the node's current + acceleration; a CalcOutput at an off-step acceleration therefore returns the rod's effective + inertia about the pin rather than its full mass (the rotation, the angular velocity and the + held fluid stay those of the committed step). ``PtfmInit`` moves and turns such a rod with + the platform before the static solve balances it about its pin. ``Pinned`` rods turn about a + fixed End A. ``Coupled``/``Vessel`` bodies are platform-borne the same way as ``Coupled`` rods, + with the node at the body reference point, and may share a deck with ``Free`` bodies. + ``CoupledPinned`` bodies are not supported on this route. Each is a separate qualification: a successful ordinary run does not qualify restart, linearisation, control, failure, or farm behaviour for a new model. diff --git a/doc/options.rst b/doc/options.rst index 27253d99..ca95a4af 100644 --- a/doc/options.rst +++ b/doc/options.rst @@ -234,8 +234,9 @@ Clock and initial condition ``Free``/``Connect`` points step in one implicit generalised-alpha step with their ``EI = 0`` lines (a Newton iteration on the object accelerations around the line steps); no sub-stepping is needed for stability. A deck without lines keeps its explicit - central-difference march unless it names ``monolithic bodyScheme``. ``staggered``: the - staggered predictor-corrector, sub-stepped for the stiffest body-mooring mode. Decks with + central-difference march, sub-stepped for the objects' own restoring, unless it names + ``monolithic bodyScheme``. ``staggered``: the staggered predictor-corrector, sub-stepped + for the stiffest body-mooring mode and the objects' own restoring. Decks with a ``motionFile`` or a ``FAILURE`` section, and coupled runs, use ``staggered`` whatever the value. See :doc:`theory` - standalone @@ -701,10 +702,10 @@ These names exist so a migrated MoorDyn deck fails less often at the syntax boun ``frictionMu``, ``frictionMuLateral`` and ``frictionMuAxial``, with no static-to-kinetic ratio or friction damping. Remove the row. -Other MoorDyn constructs that fail by name rather than as unknown input: ``CoupledPinned`` and -``VesselPinned`` rods, and ``CoupledPinned`` bodies. Line-node output channels start at node 1 -(``N0`` is rejected), and a number with a sign inside its mantissa (such as ``1+2``) is rejected -instead of being read up to the sign. +Other MoorDyn constructs that fail by name rather than as unknown input: ``CoupledPinned`` bodies, +and ``CoupledPinned``/``VesselPinned`` rods outside a coupled host (they run in OpenFAST, see +:doc:`openfast`). Line-node output channels start at node 1 (``N0`` is rejected), and a number +with a sign inside its mantissa (such as ``1+2``) is rejected instead of being read up to the sign. Water-kinematics sources ------------------------ diff --git a/doc/outputs.rst b/doc/outputs.rst index 9f06152e..e5a02415 100644 --- a/doc/outputs.rst +++ b/doc/outputs.rst @@ -730,8 +730,9 @@ Body and rod channels ~~~~~~~~~~~~~~~~~~~~~ The MoorDyn-F names, for Rigid6 bodies and for rods (free, fixed, pinned, prescribed, fixed or -pinned to a body), on every route that carries them, the OpenFAST ``CompMooring = 5`` route -included. Loads are evaluated at the committed state of the output time. +pinned to a body, and in OpenFAST pinned to the platform), on every route that carries them, the +OpenFAST ``CompMooring = 5`` route included. Loads are evaluated at the committed state of the +output time. .. list-table:: :header-rows: 1 diff --git a/doc/theory.rst b/doc/theory.rst index 20a6de90..2a61acce 100644 --- a/doc/theory.rst +++ b/doc/theory.rst @@ -1781,9 +1781,9 @@ Deck ``POINTS``, ``BODIES``, and ``RODS`` records follow the MoorDyn object mode and :math:`\mathbf{G}_{c,k}^T(\mathbf{M}_k\mathbf{X}_k - \mathbf{F}_k) = \mathbf{0}` for each pinned rod :math:`k`: the pin passes the rod's force to the body and no moment, and the rod's rotation feels the pin acceleration. (MoorDyn adds every body-attached rod, pinned or not, to the body's - equations with its full force, moment and mass, and its pinned-rod rotation does not include - the pin acceleration, so the two formulations can differ for a pinned rod on an accelerating - body.) + equations with its full force, moment and mass; its pinned-rod rotation includes the pin + acceleration, taken from the body acceleration the rod's kinematics were last set with, so the + two formulations can differ by that lag for a pinned rod on an accelerating body.) - A **zero-length rod** (``NumSegs`` 0) is a point-like connector: it has no mass, volume or side loads, and its end terms act along an axis it does not have, so it reduces to a massless point at End A (``Free``, ``Fixed``, ``Coupled`` or on a body). @@ -1793,7 +1793,10 @@ static equilibrium, solved jointly with the ``Free``/``Connect`` points. The unk body's position and a rotation-vector increment on SO(3) (for a free rod only the two rotations normal to its axis), each pinned rod's two rotations about its pin, and each point's position. A pinned rod's residual rows are its moment about the pin; its net force acts on its parent body -at the pin (a rod pinned to a fixed point has none). A deck with pinned rods takes the +at the pin (a rod pinned to a fixed point has none, and a ``CoupledPinned`` rod in OpenFAST is +balanced about its pin at the platform's initial pose). A free or pinned rod that no line +attaches to (nor, for a rod pinned to a body, any line of its body) is not an unknown: it keeps +its deck pose and starts at rest there. A deck with pinned rods takes the central-difference Jacobian of the full residual. A finite-EI line enters with its axial stiffness and weight only. The residual is the net force and moment of the loads the dynamic step applies at rest: weight, buoyancy and hydrostatic restoring, steady-current drag, @@ -1919,14 +1922,115 @@ update is explicit. Each coupled step is therefore divided into equal sub-steps body-mooring frequency. Each attached line acts as the directional spring :math:`k_a\mathbf{t}\mathbf{t}^T + (T/L)(\mathbf{I} - \mathbf{t}\mathbf{t}^T)` (:math:`\mathbf{t}` the chord direction, :math:`L` the chord length, :math:`k_a = 1/\sum l_0/EA`, :math:`T` the end -tension), carried to the reference point and added to the hydrostatic restoring; the inertia is -the structural plus added mass. The estimate omits the line-end inertia and the coupling between +tension), carried to the reference point and added to the hydrostatic restoring and to the +seabed contact; the inertia is the structural plus added mass. The contact springs are the +penalty springs of the seabed model (:math:`k_\text{Bot}\,d\,\mathrm{d}l` at each contact station +of a rod, :math:`k_\text{Bot}` over 1 m² at a body's reference point) that can act within the +coming step. A station at arm :math:`\mathbf{s}` from the rod centre moves with +:math:`\mathbf{v} + \boldsymbol{\omega}\times\mathbf{s}`, and its acceleration is bounded by +:math:`a_s = |\mathbf{a}| + |\boldsymbol{\alpha}\times\mathbf{s}| + |\boldsymbol{\omega}|^2|\mathbf{s}| + g` +(:math:`\mathbf{a}`, :math:`\boldsymbol{\alpha}` the committed accelerations, the free fall added +so that a first step without them counts); its reach +:math:`\rho = \Delta t\,|\mathbf{v} + \boldsymbol{\omega}\times\mathbf{s}| + \tfrac{1}{2}\Delta t^2 a_s` +bounds its travel in every direction, vertical and horizontal. The station counts when its height +above the highest floor within the horizontal distance :math:`\rho` (the depth on a flat seabed; +on a bathymetry grid the highest node of the cells the surrounding box overlaps, raised by +:math:`0.05` of their range for the crease rounding) is at most :math:`\rho` plus the rod radius. +An object about to land, sliding towards a shallower bed or turning a station onto it is thus +resolved as well as one at rest on the bed. A spring :math:`k` at arm :math:`\mathbf{a}` +adds :math:`k` in heave and :math:`k a_y^2`, :math:`k a_x^2` in roll and pitch. A rod near the +free surface adds its waterplane stiffness in the same way: :math:`\rho_w g\,d\,\mathrm{d}l` at each +station whose cross-section can cross the (held or wave) surface within the step, and +:math:`\rho_w g\,\pi d^2/4` between each pair of stations whose axis can cross it, which together +bound the elliptical waterplane of any crossing; its inertia is then the structural one, since +the added mass changes as it crosses. A finite-EI cable on a body or rod of the staggered march, +whose end force the march returns explicitly, adds the directional spring above with +:math:`k_a = 1/\sum l_0/EA` and its current end tension. The normal seabed damping and the +regularised friction (a damper :math:`\mu N/\sqrt{v^2 + v_\text{reg}^2}`, :math:`\mu N/v_\text{reg}` +at rest) are applied implicitly, the friction as that secant coefficient, so they set no limit; +the monolithic scheme carries the contact and the hydrostatics in its Jacobian, and its accuracy +sub-steps (above) leave them out. A step that would need more than 256 sub-steps is warned about +once per run. The estimate omits the line-end inertia and the coupling between the diagonal terms, so it can understate the coupled frequency by about a factor 1.6; stability alone (the central-difference bound :math:`\omega\,\Delta t < 2`) would allow a limit near 1. The limit of 0.4 is set by accuracy: a rod released out of balance at :math:`\Delta t = 0.1` s follows the fairlead-tension transient of a :math:`\Delta t = 0.005` s run within 1.5 %. +The objects' own terms (hydrostatic restoring, a rod's waterplane, seabed contact, and the +swing of a pinned rod below, about its pin on every route, with its parent body's pin +acceleration and the reduced mass :math:`m m_b/(m + m_b)` for a rod pinned to a body) enter +whether or not a line is attached: a deck without lines, which marches its +objects by the same explicit scheme, and a staggered deck whose only lines are finite-EI cables +are sub-stepped for them as well. Both schemes start from the instantaneous acceleration of the initial state. +On the coupled route a ``Pinned`` or ``CoupledPinned`` rod advances only its rotation in this +way; its centre then follows the pin at :math:`t_{n+1}` (fixed, or placed by the host), so End A +drives its lines with the pin motion exactly. The end-of-step angular acceleration solves the +reduced pinned-rod equation with +:math:`\mathbf{a} = \mathbf{a}_p + \boldsymbol{\alpha}\times\mathbf{r} + \boldsymbol{\omega}\times(\boldsymbol{\omega}\times\mathbf{r})`, +so the pin acceleration :math:`\mathbf{a}_p` loads the rotation through the rod's inertia, and +the implicit drag acts on the velocity change +:math:`\tfrac{1}{2}\Delta t(\boldsymbol{\alpha}_{n+1} - \boldsymbol{\alpha}_n)\times\mathbf{r}` of the +pinned centre. The sub-step estimate takes the line springs through their arms from the pin +against the rotational inertia about the pin, and adds the rod's own swing about the pin, so a +pinned rod that carries no line is still sub-stepped as the compound pendulum it is. Its weight +and buoyancy act vertically at points :math:`\mathbf{p}_i` from the pin; the first moment +:math:`\mathbf{P} = \sum_i f_i\,\mathbf{p}_i` of these loads turns with the rod, and its length +:math:`|\mathbf{P}| = |W d_g - B d_b|` (weight :math:`W` and buoyancy :math:`B` on the axis at +:math:`d_g` and :math:`d_b` from the pin) is the swing stiffness at the bottom of the swing, +whatever the current pose. The pin acceleration adds :math:`|\mathbf{a}_p|\,|\mathbf{G}|`, with +:math:`|\mathbf{G}|` the first moment of the rod's translational inertia (structural and added) +about the pin, :math:`m d_g` for a dry rod; for the hanging dry rod this is the effective gravity +bound :math:`g + |\mathbf{a}_p| \ge |\mathbf{g} - \mathbf{a}_p|`, taken with the larger of the +step-start and end-of-step pin accelerations. The swing stiffness over the smaller rotational +inertia about the pin across the rod axis, about :math:`3g/(2L)` for a dry uniform rod of length +:math:`L`, adds to the line estimate of :math:`\omega^2`. The buoyancy is that of the wet +length at the evaluated pose; the change of a surface-piercing rod's waterline with its tilt +(an articulated column) enters through the rod's waterplane stiffness about the pin (above). +The host places a ``CoupledPinned`` pin at :math:`t_{n+1}` before the estimate, so +the swing is evaluated with the rod at both its step-start and its end-of-step pin, taking the +larger stiffness and the smaller inertia. The sub-steps move the pin along a straight line; at +the rod's orientation and with the surface held over the step, every slice's clearance to the +surface then changes monotonically and in the same sense, so the wetting, the moment +:math:`W d_g - B d_b` and the added mass are bounded by their values at the two ends, and a step +whose pin crosses the free surface (a light rod lifted out of the water, or a heavy one lowered +into it) is sub-stepped for the stiffer of its wet states. The seabed contact adds its angular +stiffness about the pin, :math:`\sum k\,|\mathbf{a}\times\mathbf{e}_z|^2` over the contact +stations within reach (at both pin poses for a ``CoupledPinned`` rod), so a rod whose far end +rests on the bed is sub-stepped for its contact mode. In a sub-cycled step the host pin's +position, +velocity and acceleration are each interpolated linearly between their step-start values (the End +A motion of the committed rod) and the end-of-step host input, as the host fairleads of the lines +and the ``Coupled`` rods are, so points on one platform keep their relative positions under a +translation within the step. This is second order: between exact end values the interpolated +position departs from the host path by at most :math:`\Delta t^2 \max|\mathbf{a}_p|/8`, the +interpolated velocity is not the derivative of the interpolated position (they differ by +:math:`O(\Delta t\,|\mathbf{a}_p|)`), and a pin moving at constant velocity is reproduced exactly. +A first step without a committed angular acceleration (the aggregate and the C API) takes its +starting one with the pin at its step-start pose; under OpenFAST the rod state mirror reloaded +at the initial output call carries the committed accelerations of the initial condition, zero +for the static start, so a start out of equilibrium (``bodyIC deck``) begins its first step +from rest acceleration, an error of order :math:`\Delta t` in that step's velocity, as for a +free rod. + +The host receives the rod's net load less its inertia at the pin, and no moment. It is the +direct feedthrough of the pin acceleration at the rod's current state: the pin position, +velocity and acceleration are those the host last set (re-derived from the rod's End A motion, +so that a checkpoint restart reproduces the force between steps bit for bit), the rotation, the +angular velocity and the held fluid are the committed ones, and the angular acceleration is +solved again for the pin's current acceleration. A CalcOutput at an off-step pin acceleration +therefore returns the rod's effective inertia about the pin. The attached lines keep their +committed interior state, accelerations included, as in every output evaluation, and their end +loads are taken at the end accelerations of the re-solved rotation: the solve moves the end-node +inertia from the end accelerations the system holds with the lines' coupled mass block +:math:`\mathbf{M}_{cc}` (structural and added mass; the step's corrector instead lets the line +interior follow, :math:`\mathbf{M}_{cc} - \mathbf{M}_{cf}\mathbf{M}_{ff}^{-1}\mathbf{M}_{fc}`). At a +held interior the end loads are linear in the end accelerations, so the force does not depend on +the end accelerations the line loads were evaluated with. MoorDyn-F's coupled pinned rod keeps +the same pin acceleration term in its rotation equation and returns the same force: its output +call evaluates the rod's state derivative at the current input first (its lumped line mass has +no interior coupling). + **Mixed topologies.** One step marches every object of a deck together: bodies with their fixed and pinned rods, free and pinned rods, the ``EI = 0`` lines with their ``Free``/``Connect`` points, and the finite-EI cables. In the monolithic scheme the points are junctions of the diff --git a/python/cabledyn/deck_file.py b/python/cabledyn/deck_file.py index f7163bf1..ff1eeb09 100644 --- a/python/cabledyn/deck_file.py +++ b/python/cabledyn/deck_file.py @@ -325,6 +325,9 @@ "con": "free", "ves": "vessel", "cpld": "coupled", + "cpldpin": "coupledpinned", + "vesselpinned": "coupledpinned", + "vespin": "coupledpinned", } _RIGID_END_CONNECTIONS = frozenset({"rigid", "infinity", "inf"}) # TorsStiffness keywords of an end free to twist (a numeric 0 is free too) @@ -1866,7 +1869,8 @@ def _resolve_rod_ends( end points of a rod fixed to a body (RODS type ``Body``) into ``Body`` points. Native ``collapse_zero_length_rods`` first merges both ends of a zero-length rod (NumSegs 0) into one connector point typed after the rod: - Free, Fixed (fixed or pinned rod), Coupled, or ``Body``. ``point_types``, + Free, Fixed (fixed or pinned rod), Coupled (coupled or CoupledPinned rod), or + ``Body``. ``point_types``, ``point_ids`` and ``point_z`` are updated in place. """ merged: dict[str, str] = {} @@ -1904,7 +1908,9 @@ def _resolve_rod_ends( resolved = kind elif kind == "pinned": resolved = "fixed" - elif kind == "vessel": + elif kind in {"vessel", "coupledpinned"}: + # a zero-length CoupledPinned rod is a Coupled point on the coupled + # route (and refused elsewhere, see the RODS checks) resolved = "coupled" elif body is not None: resolved = f"body{_native_id_suffix(body.group(1))}" @@ -3230,10 +3236,13 @@ def end_key(token: str) -> str: f"{self._at(row)}: rod references missing rod type {row.tokens[1]}" ) rod_kind = _ROD_ATTACHMENT_ALIASES.get(row.tokens[2].lower(), row.tokens[2].lower()) - if rod_kind in {"coupledpinned", "cpldpin", "vesselpinned", "vespin"}: + # native finalize_checks: the host moves the pin of a CoupledPinned rod, so only the + # coupled route (a caller-driven deck) takes one, zero-length ones included + if rod_kind == "coupledpinned" and not self.caller_driven: raise DeckFormatError( - f"{self._at(row)}: CoupledPinned/VesselPinned RODS are not supported (use " - "Coupled, Vessel, Pinned or BodyPinned)" + f"{self._at(row)}: CoupledPinned/VesselPinned ROD requires a coupled host " + "(OpenFAST CompMooring = 5); in a standalone deck use Pinned, BodyPinned, " + "or a Coupled rod with a motionFile" ) # Body (fixed to the body) or BodyPinned / BodyPin (End A pinned to it) body_kind = re.fullmatch(r"body([0-9]+)(?:pin|pinned)?", rod_kind) @@ -3242,10 +3251,10 @@ def end_key(token: str) -> str: raise DeckFormatError( f"{self._at(row)}: ROD attachment must name a Rigid6 (Free) BODY" ) - elif rod_kind not in {"free", "fixed", "coupled", "vessel", "pinned"}: + elif rod_kind not in {"free", "fixed", "coupled", "vessel", "pinned", "coupledpinned"}: raise DeckFormatError( f"{self._at(row)}: ROD type must be Free, Fixed, Pinned, Coupled, Vessel, " - "Body, or BodyPinned" + "CoupledPinned, VesselPinned, Body, or BodyPinned" ) if ( not zero_length diff --git a/python/tests/test_deck_native_parity.py b/python/tests/test_deck_native_parity.py index 70afcd07..bc1f2d4c 100644 --- a/python/tests/test_deck_native_parity.py +++ b/python/tests/test_deck_native_parity.py @@ -298,6 +298,31 @@ def test_rod_channel_quantities_follow_the_native_vocabulary(): # --------------------------------------------------------------------------- rods +@pytest.mark.parametrize("kind", ["CoupledPinned", "CpldPin", "VesselPinned", "VesPin"]) +def test_coupled_pinned_rods_need_a_coupled_host(kind): + # native finalize_checks: the host moves the pin, so the standalone driver refuses the rod + # (zero-length ones too) and the coupled route takes it + pinned = _spar((_SPAR_ROD, _SPAR_ROD.replace("Free", kind))) + _rejects(pinned, "requires a coupled host") + zero_length = _spar( + (_SPAR_ROD, _SPAR_ROD.replace("Free", kind).replace("-20.0 1", "-20.0 0")) + ) + _rejects(zero_length, "requires a coupled host") + still = ("uniform 0.5 0.0 0.0 current", "none current") + DeckFile.from_text( + _spar((_SPAR_ROD, _SPAR_ROD.replace("Free", kind)), still), caller_driven=True + ) + # a zero-length one is a Coupled point at End A that its End B point merges into + DeckFile.from_text( + _spar( + (_SPAR_ROD, _SPAR_ROD.replace("Free", kind).replace("-20.0 1", "-20.0 0")), + still, + ('"Point2px"\n"Point2pz"', '"Point3px"\n"Point3pz"'), + ), + caller_driven=True, + ) + + def test_rod_endpoints_have_an_admissible_magnitude(): text = _spar((_SPAR_ROD, _SPAR_ROD.replace("0.0 0.0 -30.0", "2.0e6 0.0 -30.0"))) _rejects(text, "ROD endpoint coordinates must be at most 1e6 m") @@ -643,8 +668,6 @@ def test_named_rejections_of_moordyn_only_rows(): _rejects(_options(_HELD, "airy 2 8 0 waves regular"), "is a positional") _rejects(_options(_HELD, "200 WaveComponents", "600 WaveDirections"), "at most 100000") DeckFile.from_text(_options(_HELD, "200 WaveComponents", "500 WaveDirections")) - coupled_pinned = _SPAR_ROD.replace("Free", "CoupledPinned") - _rejects(_spar((_SPAR_ROD, coupled_pinned)), "CoupledPinned/VesselPinned RODS") _rejects(_edit(_HELD, ("0.252 390.0", "0.252 39+1")), "is not a plain number") turbine = _edit(_HELD, ("2 Coupled 0.0", "2 Turbine1 0.0")) _rejects(turbine, "Turbine points need a TURBINES section") diff --git a/src/CableDyn_Bathymetry.f90 b/src/CableDyn_Bathymetry.f90 index 6c5db76a..a040656f 100644 --- a/src/CableDyn_Bathymetry.f90 +++ b/src/CableDyn_Bathymetry.f90 @@ -28,6 +28,7 @@ MODULE CableDyn_Bathymetry PUBLIC :: CD_Bathymetry_Floor PUBLIC :: CD_Bathymetry_Floor_Gradient PUBLIC :: CD_Bathymetry_Grid_Floor + PUBLIC :: CD_Bathymetry_Max_Floor PUBLIC :: CD_Bathymetry_Rotate_Curvature PUBLIC :: CD_Bathymetry_Seabed_Load INTEGER, PARAMETER, PUBLIC :: CD_BATHY_OK = 0, CD_BATHY_BADINPUT = 1, CD_BATHY_ALLOCFAIL = 2 @@ -187,6 +188,42 @@ SUBROUTINE CD_Bathymetry_Grid_Floor(bathy, xq, yq, z_floor, ErrStat, ErrMsg) CALL floor_eval(bathy, xq, yq, z_floor, dfdx, dfdy, ErrStat, ErrMsg, rounded=.FALSE.) END SUBROUTINE CD_Bathymetry_Grid_Floor + SUBROUTINE CD_Bathymetry_Max_Floor(bathy, x_lo, x_hi, y_lo, y_hi, z_max, ErrStat, ErrMsg) + !! An upper bound of the seabed elevation (CD_Bathymetry_Floor) over the horizontal box + !! [x_lo, x_hi] x [y_lo, y_hi]: the highest grid node of the cells the box overlaps (the + !! bilinear surface of a cell lies within its node range, and outside the grid the floor + !! is clamped to its edge cells), raised by CD_BATHY_CREASE_FRACTION times the node range, + !! which bounds the crease rounding (it moves the surface by at most |J| delta/6 per + !! direction, below a thirtieth of the node range for both directions together). + TYPE(CD_BathymetryType), INTENT(IN) :: bathy + REAL(wp), INTENT(IN) :: x_lo, x_hi, y_lo, y_hi + REAL(wp), INTENT(OUT) :: z_max + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER :: i0, i1, j0, j1 + REAL(wp) :: t, z_min + LOGICAL :: clamped + + z_max = CD_ZERO + ErrStat = CD_BATHY_OK + ErrMsg = '' + IF (.NOT. CD_Bathymetry_Is_Initialized(bathy)) THEN + CALL fail(ErrStat, ErrMsg, 'bathymetry object is not initialized') + RETURN + END IF + IF (.NOT. (CD_All_Finite([x_lo, x_hi, y_lo, y_hi]) .AND. x_lo <= x_hi .AND. y_lo <= y_hi)) THEN + CALL fail(ErrStat, ErrMsg, 'bathymetry box bounds must be finite and ordered') + RETURN + END IF + CALL locate_axis(bathy%x, x_lo, i0, t, clamped) + CALL locate_axis(bathy%x, x_hi, i1, t, clamped) + CALL locate_axis(bathy%y, y_lo, j0, t, clamped) + CALL locate_axis(bathy%y, y_hi, j1, t, clamped) + z_max = -MINVAL(bathy%depth(i0:i1 + 1, j0:j1 + 1)) + z_min = -MAXVAL(bathy%depth(i0:i1 + 1, j0:j1 + 1)) + z_max = z_max + CD_BATHY_CREASE_FRACTION*(z_max - z_min) + END SUBROUTINE CD_Bathymetry_Max_Floor + SUBROUTINE CD_Bathymetry_Floor_Gradient(bathy, xq, yq, z_floor, dfdx, dfdy, ErrStat, ErrMsg, crease_curvature) !! Return seabed elevation and horizontal gradients dz_floor/dx, dz_floor/dy. !! crease_curvature (optional): the second derivatives (z_xx, z_xy, z_yy) of the crease diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index fd34c926..73328fbe 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -41,7 +41,8 @@ MODULE CableDyn_DeckDriver CD_STATIC_FRICTION_AS_LAID, CD_STATIC_FRICTION_NONE USE CableDyn_Bathymetry, ONLY: CD_BathymetryType, CD_Init_Bathymetry, CD_End_Bathymetry, & CD_Bathymetry_Is_Initialized, CD_Bathymetry_Floor, & - CD_Bathymetry_Floor_Gradient, CD_Bathymetry_Grid_Floor, CD_BATHY_OK + CD_Bathymetry_Floor_Gradient, CD_Bathymetry_Grid_Floor, CD_Bathymetry_Max_Floor, & + CD_BATHY_OK USE CableDyn_Line, ONLY: CD_LineType, CD_LineSection, CD_Build_Line_Mesh, & CD_Nodal_Seabed_Stiffness, CD_LINE_OK USE CableDyn_Catenary, ONLY: CD_Catenary_Seed, CD_CAT_OK, CD_CAT_NOSEED @@ -715,6 +716,18 @@ MODULE CableDyn_DeckDriver ! Pinned rod: End A held at pin, the rod turns about it (three rotational DOFs) LOGICAL :: is_pinned = .FALSE. REAL(wp) :: pin(3) = CD_ZERO + ! CoupledPinned/VesselPinned rod (coupled aggregate): a pinned rod whose pin is a host node; + ! the host prescribes pin, pin_v and pin_a (zero for a fixed pin), and the rod's rotation + ! about it stays its own degree of freedom + LOGICAL :: is_host_pinned = .FALSE. + REAL(wp) :: pin_v(3) = CD_ZERO, pin_a(3) = CD_ZERO + ! pin0, pin0_v, pin0_a (host-pinned rod): the pin kinematics at the start of the coming step, + ! i.e. the End A motion of the committed rod state (set_rod_pin_start). They are set where + ! the committed state is (Init, the end of every step, a mirror restore, a host transfer + ! that does not advance) and not by the transfer of the t + dt host kinematics before a + ! step, so the step's start-acceleration solve and its sub-steps have the step-start pin + ! without a staged copy of the rods. + REAL(wp) :: pin0(3) = CD_ZERO, pin0_v(3) = CD_ZERO, pin0_a(3) = CD_ZERO ! Rod pinned to a body (BodyPinned): the index of the parent body in the march's body ! states and the pin (End A) in the body frame; pin then follows the body INTEGER :: parent = 0 @@ -810,6 +823,9 @@ MODULE CableDyn_DeckDriver ! 2 rod end (cab_obj rod index, cab_off(1) = -1 End A, +1 End B), 0 held point INTEGER, ALLOCATABLE :: cab_kind(:), cab_obj(:), cable_points(:, :) REAL(wp), ALLOCATABLE :: cab_off(:, :), cab_force(:, :) + ! cab_kax, cab_len: a cable's static axial stiffness 1/sum(l0/EA) and unstretched length, for the + ! sub-step estimate of the staggered march (mb_cable_k6) + REAL(wp), ALLOCATABLE :: cab_kax(:), cab_len(:) ! cab_clamp: End A carries a Rigid or elastic END CONNECTION on its body or rod; its end ! tangent then follows the object orientation, the cable is re-stepped at every outer ! iteration of the monolithic step (implicit coupling, its end stiffness in the Jacobian) and @@ -5934,9 +5950,10 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi !! the cables are both built under the environment the host owns (host overrides deck). !! !! Scope: EI=0 lines with Fixed/Coupled/Vessel/Connect/Free points, Point3 buoys, Rigid6 - !! bodies and RODs (host-coupled or free), CONTROL, FAILURE and FAST.Farm turbines, plus - !! finite-EI cables. Fails closed with a clear message on: a motionFile (the host drives the - !! coupled boundary); deck waves (the host supplies wave kinematics); a deck current on + !! bodies and RODs (free, fixed, pinned, host-coupled or host-pinned), CONTROL, FAILURE and + !! FAST.Farm turbines, plus finite-EI cables. Fails closed with a clear message on: a + !! motionFile (the host drives the coupled boundary); deck waves (the host supplies wave + !! kinematics); a deck current on !! a deck with a finite-EI cable, a Rigid6 body or a rod, under a host fluid field, or in !! FAST.Farm mode; a deck with a finite-EI cable that also carries Free/Connect dynamic !! points. A deck current on any other deck is a steady field applied through the lines. @@ -6048,8 +6065,9 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi END IF IF (MAXVAL(ABS(ptfm_init)) > CD_ZERO) THEN CALL apply_ptfm_init(points, ptfm_init) - ! Coupled/Vessel RODS are platform-borne like Coupled points: their ends and their - ! RodA/B attachment points move rigidly with the initial platform displacement. + ! Coupled/Vessel and CoupledPinned RODS are platform-borne like Coupled points: their ends + ! and their RodA/B attachment points move rigidly with the initial platform + ! displacement (MoorDyn-F also turns a coupled pinned rod's axis with PtfmInit). CALL apply_ptfm_host_rods(rods, points, ptfm_init) CALL apply_ptfm_host_bodies(bodies, points, ptfm_init) host_dcm = ptfm_zyx_dcm(ptfm_init(4:6)) @@ -6264,7 +6282,8 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi ! below (n_rod block) and built into agg%rod. A rod deck mixed with Rigid6 bodies fails closed ! there (the aggregate marches one body/rod family per step). n_rod = SIZE(rods) - n_host_rod = COUNT(rods%rod_type == 'coupled' .OR. rods%rod_type == 'vessel') + n_host_rod = COUNT(rods%rod_type == 'coupled' .OR. rods%rod_type == 'vessel' .OR. & + rods%rod_type == 'coupledpinned') n_host_body = COUNT(bodies%host_coupled) IF (opts%has_motion_file) THEN CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_Aggregate: the coupled boundary is driven by the host, '// & @@ -6361,12 +6380,9 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_Aggregate: a coupled ROD with a finite-EI cable in the '// & 'same deck is not supported'); RETURN END IF - ! The aggregate rod march integrates Free rods and prescribes Coupled/Vessel ones; any other - ! rod would be held at its pose, so a Pinned rod (which must turn about its pin) is refused. - IF (ANY(rods%rod_type == 'pinned')) THEN - CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_Aggregate: a Pinned ROD is not supported on the coupled '// & - 'route (the coupled rod march does not turn rods about a pin); use the standalone driver'); RETURN - END IF + ! The aggregate rod march integrates Free rods, turns Pinned and CoupledPinned rods about + ! their pins (a fixed point, or a host node that moves the pin), prescribes Coupled/Vessel + ! rods and holds Fixed ones. IF (nturb > 0) THEN CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_Aggregate: coupled RODs in a FAST.Farm deck are not '// & 'supported'); RETURN @@ -6389,11 +6405,13 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_Aggregate: line FAILURE on a coupled ROD deck is not '// & 'supported (the failure trigger is not evaluated against the post-rod-march state)'); RETURN END IF - ! Coupled/Vessel rods become 6-DOF host nodes (End A position + platform orientation). The - ! linearization probe places translational moving points only, so it cannot carry them. + ! Coupled/Vessel rods become 6-DOF host nodes (End A position + platform orientation), + ! CoupledPinned ones translational host nodes with a rotation of their own. The + ! linearization probe places translational moving points only and holds every rod, so it + ! carries neither. IF (n_host_rod > 0 .AND. PRESENT(coupled_positions)) THEN CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_Aggregate: coupled_positions (the linearization probe) '// & - 'does not support Coupled/Vessel RODS'); RETURN + 'does not support Coupled/Vessel or CoupledPinned RODS'); RETURN END IF END IF @@ -11541,10 +11559,9 @@ SUBROUTINE append_rod(line, rods, nr, ErrStat, ErrMsg) r%rod_type = 'vessel' CASE ('cpld') r%rod_type = 'coupled' - CASE ('coupledpinned', 'cpldpin', 'vesselpinned', 'vespin') - ! rejected here, before a NumSegs 0 rod collapses to an unknown point type - CALL fail(ErrStat, ErrMsg, 'CoupledPinned/VesselPinned RODS are not supported (use Coupled, Vessel, '// & - 'Pinned or BodyPinned)'); RETURN + CASE ('cpldpin', 'vesselpinned', 'vespin') + ! MoorDyn-F treats the four spellings alike: End A pinned to a host node + r%rod_type = 'coupledpinned' CASE DEFAULT IF (starts_with(TRIM(r%rod_type), 'body') .AND. LEN_TRIM(r%rod_type) > 7) THEN IF (r%rod_type(LEN_TRIM(r%rod_type) - 2:LEN_TRIM(r%rod_type)) == 'pin' .AND. & @@ -11985,8 +12002,9 @@ SUBROUTINE collapse_zero_length_rods(rods, points, np, lines, opts) !! the rod axis, which a zero-length rod does not have (zero for lines without bending !! stiffness), so it carries no hydrodynamic load either. Each one becomes one POINT at End A !! that both of its ends (RA/RB tokens and RodA/B POINT rows) resolve to: Free for a - !! free rod, Fixed for a fixed or pinned rod, Coupled for a coupled rod and Body for a rod - !! fixed or pinned to body M. The rod leaves the rod list; opts%zl_rod/zl_point keep the map + !! free rod, Fixed for a fixed or pinned rod, Coupled for a coupled or (coupled host only) + !! CoupledPinned rod and Body for a rod fixed or pinned to body M. The rod leaves the rod + !! list; opts%zl_rod/zl_point keep the map !! so that a Rod output channel on it can be refused by name. TYPE(DeckRod), ALLOCATABLE, INTENT(INOUT) :: rods(:) TYPE(DeckPoint), ALLOCATABLE, INTENT(INOUT) :: points(:) @@ -12009,13 +12027,17 @@ SUBROUTINE collapse_zero_length_rods(rods, points, np, lines, opts) drop = .FALSE. DO i = 1, SIZE(rods) IF (rods(i)%nsegs /= 0) CYCLE + ! a CoupledPinned rod needs a coupled host; elsewhere it stays a rod and is refused by name + IF (TRIM(rods(i)%rod_type) == 'coupledpinned' .AND. .NOT. opts%host_coupled_objects) CYCLE keep(i) = .FALSE. SELECT CASE (TRIM(rods(i)%rod_type)) CASE ('free') ptype = 'free' CASE ('fixed', 'pinned') ptype = 'fixed' - CASE ('coupled', 'vessel') + CASE ('coupled', 'vessel', 'coupledpinned') + ! a point at End A has no rotation to pin: a zero-length CoupledPinned rod transmits the + ! force of its lines to the host, as a Coupled point does ptype = 'coupled' CASE DEFAULT bid = MAX(body_id_of_rod_type(rods(i)%rod_type), pinned_body_of_rod_type(rods(i)%rod_type)) @@ -14217,9 +14239,10 @@ SUBROUTINE finalize_checks(types, bodies, rod_types, rods, points, lines, sectio END IF ELSE IF (TRIM(rods(i)%rod_type) /= 'free' .AND. TRIM(rods(i)%rod_type) /= 'fixed' .AND. & TRIM(rods(i)%rod_type) /= 'coupled' .AND. TRIM(rods(i)%rod_type) /= 'vessel' .AND. & - TRIM(rods(i)%rod_type) /= 'pinned') THEN + TRIM(rods(i)%rod_type) /= 'pinned' .AND. TRIM(rods(i)%rod_type) /= 'coupledpinned') THEN CALL fail(ErrStat, ErrMsg, 'ROD type "'//TRIM(rods(i)%rod_type)// & - '" is not supported (supported: Free, Fixed, Pinned, Coupled, Vessel, Body, BodyPinned)') + '" is not supported (supported: Free, Fixed, Pinned, Coupled, Vessel, CoupledPinned, '// & + 'VesselPinned, Body, BodyPinned)') RETURN END IF IF ((TRIM(rods(i)%rod_type) == 'coupled' .OR. TRIM(rods(i)%rod_type) == 'vessel') .AND. & @@ -14227,6 +14250,14 @@ SUBROUTINE finalize_checks(types, bodies, rod_types, rods, points, lines, sectio CALL fail(ErrStat, ErrMsg, 'Coupled/Vessel ROD requires a motionFile (or a coupled host)') RETURN END IF + ! The host moves the pin of a CoupledPinned rod and takes its force; a motionFile cannot + ! stand in for it (it prescribes both rod ends), so the rod needs the coupled aggregate. + IF (TRIM(rods(i)%rod_type) == 'coupledpinned' .AND. .NOT. opts%host_coupled_objects) THEN + CALL fail(ErrStat, ErrMsg, 'CoupledPinned/VesselPinned ROD requires a coupled host (OpenFAST '// & + 'CompMooring = 5); in a standalone deck use Pinned, BodyPinned, or a Coupled rod with a '// & + 'motionFile') + RETURN + END IF IF (.NOT. valid_rod_output_flags(rods(i)%outputs)) THEN CALL fail(ErrStat, ErrMsg, 'ROD Outputs "'//TRIM(rods(i)%outputs)// & '": supported rod-output flag is p') @@ -16358,7 +16389,8 @@ SUBROUTINE init_rod_states(rod_types, rods, points, rod_state, ErrStat, ErrMsg, rod_state(i)%rod_id = rods(i)%id rod_state(i)%is_free = TRIM(rods(i)%rod_type) == 'free' rod_state(i)%is_prescribed = TRIM(rods(i)%rod_type) == 'coupled' .OR. TRIM(rods(i)%rod_type) == 'vessel' - rod_state(i)%is_pinned = TRIM(rods(i)%rod_type) == 'pinned' + rod_state(i)%is_host_pinned = TRIM(rods(i)%rod_type) == 'coupledpinned' + rod_state(i)%is_pinned = TRIM(rods(i)%rod_type) == 'pinned' .OR. rod_state(i)%is_host_pinned rod_state(i)%pin = rods(i)%end_a rod_state(i)%point_a_index = rod_point_index(points, rods(i)%id, 1) rod_state(i)%point_b_index = rod_point_index(points, rods(i)%id, 2) @@ -16387,9 +16419,31 @@ SUBROUTINE init_rod_states(rod_types, rods, points, rod_state, ErrStat, ErrMsg, rod_state(i)%inertia(1) = 0.5_wp*rod_state(i)%mass*radius*radius rod_state(i)%inertia(2) = rod_state(i)%mass*(3.0_wp*radius*radius + rod_state(i)%length**2)/12.0_wp rod_state(i)%inertia(3) = rod_state(i)%inertia(2) + ! a host-pinned rod starts its first step from its pin at rest in the deck pose + IF (rod_state(i)%is_host_pinned) CALL set_rod_pin_start(rod_state(i)) END DO END SUBROUTINE init_rod_states + SUBROUTINE rod_end_a_motion(rod, p, v, a) + !! Position, velocity and acceleration of a rod's End A from its rigid motion (centre, frame, + !! angular rates). + TYPE(RodState), INTENT(IN) :: rod + REAL(wp), INTENT(OUT) :: p(3), v(3), a(3) + REAL(wp) :: arm(3) + arm = MATMUL(rod%rot_mat, [-rod%half_length, CD_ZERO, CD_ZERO]) + p = rod%r + arm + v = rod%v + cross3(rod%omega, arm) + a = rod%a + cross3(rod%alpha, arm) + cross3(rod%omega, cross3(rod%omega, arm)) + END SUBROUTINE rod_end_a_motion + + SUBROUTINE set_rod_pin_start(rod) + !! Record the committed End A motion of a host-pinned rod as the pin kinematics its next step + !! starts from (RodState%pin0). Derived from the rod state, which the checkpoint mirror + !! carries, so a restored run takes the same values bit for bit. + TYPE(RodState), INTENT(INOUT) :: rod + CALL rod_end_a_motion(rod, rod%pin0, rod%pin0_v, rod%pin0_a) + END SUBROUTINE set_rod_pin_start + SUBROUTINE ensure_rod_step_workspace(work, ncoupled, nrod, npoint) TYPE(RodStepWorkspace), INTENT(INOUT) :: work INTEGER, INTENT(IN) :: ncoupled, nrod, npoint @@ -16461,7 +16515,7 @@ END SUBROUTINE ensure_square_workspace SUBROUTINE rigid_coupled_acceleration(dload_da, dt, a_points, bases, arms, mass_eff, added6, inertia_body, & rot_mat, omega, f_global, m_global, dv0, dfo_dv, acc, alpha, & - ErrStat, ErrMsg, pin_arm, m6_out, rhs_out) + ErrStat, ErrMsg, pin_arm, m6_out, rhs_out, pin_acc, pin_load) !! End-of-step rigid-body (rod or Rigid6) accelerations x = (acc, alpha) of the staggered !! central-difference corrector of step_rigid6_system / step_rod_system. The loads were !! evaluated at the predictor, whose position is the final position (Newmark beta = 0) and @@ -16500,13 +16554,18 @@ SUBROUTINE rigid_coupled_acceleration(dload_da, dt, a_points, bases, arms, mass_ REAL(wp), INTENT(OUT) :: acc(3), alpha(3) INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg - ! pin_arm: the reference point turns about a fixed pin at -pin_arm from it (a pinned rod): - ! with x = T y + b, T = [-[r]x; I], b = [w x (w x r); 0], the rotational acceleration y solves - ! T^T m6 T y = T^T (rhs - m6 b) - REAL(wp), INTENT(IN), OPTIONAL :: pin_arm(3) + ! pin_arm: the reference point turns about a pin at -pin_arm from it (a pinned rod): with + ! x = T y + b, T = [-[r]x; I], b = [a_p + w x (w x r); 0], the rotational acceleration y + ! solves T^T m6 T y = T^T (rhs - m6 b). a_p is pin_acc, the pin acceleration (zero when + ! absent: a fixed pin); a moving pin (a CoupledPinned rod) thus loads the rotation with the + ! inertia of its acceleration. + REAL(wp), INTENT(IN), OPTIONAL :: pin_arm(3), pin_acc(3) ! m6_out/rhs_out: return the assembled system m6 x = rhs instead of solving it (the pinned- ! child group solve of mb_group_solve); acc and alpha are then zero REAL(wp), INTENT(OUT), OPTIONAL :: m6_out(6, 6), rhs_out(6) + ! pin_load (with pin_arm): the force the body exerts on its pin, rhs(1:3) - m6(1:3, :) x, i.e. + ! its net load less its inertia (line-end inertia at the solved attachment accelerations) + REAL(wp), INTENT(OUT), OPTIONAL :: pin_load(3) INTEGER :: i, j, k, bi, bj REAL(wp) :: m6(6, 6), rhs(6), inertia_g(3, 3), s_i(3, 3), s_j(3, 3), d_ij(3, 3), g(3), c_j(3) @@ -16573,6 +16632,7 @@ SUBROUTINE rigid_coupled_acceleration(dload_da, dt, a_points, bases, arms, mass_ END DO b6 = CD_ZERO b6(1:3) = cross3(omega, cross3(omega, pin_arm)) + IF (PRESENT(pin_acc)) b6(1:3) = pin_acc + b6(1:3) CALL solve_sym3(MATMUL(TRANSPOSE(t63), MATMUL(m6, t63)), MATMUL(TRANSPOSE(t63), rhs - MATMUL(m6, b6)), y, ok) IF (.NOT. ok) THEN ErrStat = CD_DECKDRV_SOLVEFAIL @@ -16581,6 +16641,7 @@ SUBROUTINE rigid_coupled_acceleration(dload_da, dt, a_points, bases, arms, mass_ END IF alpha = y acc = MATMUL(t63(1:3, :), y) + b6(1:3) + IF (PRESENT(pin_load)) pin_load = rhs(1:3) - MATMUL(m6(1:3, 1:3), acc) - MATMUL(m6(1:3, 4:6), alpha) RETURN END IF CALL solve_rigid6x6(m6, rhs, ErrStat, ErrMsg) @@ -17215,7 +17276,8 @@ SUBROUTINE write_objects_dynamic_out(out_root, channels, bodies, rod_types, rods ErrStat, ErrMsg, bathymetry) !! March the bodies (with the rods fixed to them) and the free and pinned rods of a deck !! without lines: each object is advanced by the staggered central-difference scheme of the - !! line-coupled routes (Newmark gamma = 1/2, beta = 0, drag implicit), with no line loads. With + !! line-coupled routes (Newmark gamma = 1/2, beta = 0, drag implicit), with no line loads, + !! sub-cycled for the objects' own restoring (objects_substep_count). With !! bodyIC static a floating body starts at its hydrostatic equilibrium (float_body_equilibrium). CHARACTER(*), INTENT(IN) :: out_root CHARACTER(NAMELEN), INTENT(IN) :: channels(:) @@ -17232,8 +17294,8 @@ SUBROUTINE write_objects_dynamic_out(out_root, channels, bodies, rod_types, rods TYPE(RigidBodyState), ALLOCATABLE :: rigid(:), old_rigid(:) TYPE(RodState), ALLOCATABLE :: rst(:), old_rst(:) TYPE(DeckRod), ALLOCATABLE :: own(:) - INTEGER :: unit, ios, step, nstep, k, es - REAL(wp) :: t, acc(3), alpha(3), dv0(6) + INTEGER :: unit, ios, step, nstep, k, es, nsub, isub + REAL(wp) :: t, acc(3), alpha(3), dv0(6), dts, ts CHARACTER(160) :: em TYPE(DriverProgress) :: progress @@ -17288,53 +17350,62 @@ SUBROUTINE write_objects_dynamic_out(out_root, channels, bodies, rod_types, rods DO step = 1, nstep CALL CD_Profile_Enter(CD_PROF_SOLVE) t = REAL(step, wp)*opts%dtM - old_rigid = rigid - old_rst = rst - DO k = 1, SIZE(rigid) - CALL CD_Rigid_Advance_Newmark(rigid(k)%r, rigid(k)%v, rigid(k)%rot_mat, rigid(k)%omega, rigid(k)%a, & - rigid(k)%alpha, rigid(k)%a, rigid(k)%alpha, opts%dtM, CD_RIGID_NEWMARK_GAMMA, & - CD_RIGID_NEWMARK_BETA, es, em) - IF (es /= CD_RIGID_OK) CALL fail_solve(ErrStat, ErrMsg, 'body finite-rotation update failed: '//TRIM(em)) - IF (ErrStat /= CD_DECKDRV_OK) EXIT - dv0(1:3) = -CD_RIGID_NEWMARK_GAMMA*opts%dtM*old_rigid(k)%a - dv0(4:6) = -CD_RIGID_NEWMARK_GAMMA*opts%dtM*old_rigid(k)%alpha - CALL objects_acceleration(opts, t, opts%dtM, dv0, acc, alpha, ErrStat, ErrMsg, body=rigid(k), & - bathymetry=bathymetry) - IF (ErrStat /= CD_DECKDRV_OK) EXIT - rigid(k) = old_rigid(k) - CALL CD_Rigid_Advance_Newmark(rigid(k)%r, rigid(k)%v, rigid(k)%rot_mat, rigid(k)%omega, old_rigid(k)%a, & - old_rigid(k)%alpha, acc, alpha, opts%dtM, CD_RIGID_NEWMARK_GAMMA, & - CD_RIGID_NEWMARK_BETA, es, em) - IF (es /= CD_RIGID_OK) CALL fail_solve(ErrStat, ErrMsg, 'body finite-rotation update failed: '//TRIM(em)) - IF (ErrStat /= CD_DECKDRV_OK) EXIT - rigid(k)%a = acc - rigid(k)%alpha = alpha - END DO - IF (ErrStat == CD_DECKDRV_OK) THEN - DO k = 1, SIZE(rst) - IF (.NOT. (rst(k)%is_free .OR. rst(k)%is_pinned)) CYCLE - CALL CD_Rigid_Advance_Newmark(rst(k)%r, rst(k)%v, rst(k)%rot_mat, rst(k)%omega, rst(k)%a, rst(k)%alpha, & - rst(k)%a, rst(k)%alpha, opts%dtM, CD_RIGID_NEWMARK_GAMMA, & + ! sub-steps that resolve the objects' own restoring (objects_substep_count) + CALL objects_substep_count(rigid, rst, opts, t - opts%dtM, opts%dtM, nsub, ErrStat, ErrMsg, bathymetry) + IF (ErrStat /= CD_DECKDRV_OK) nsub = 0 + dts = opts%dtM/REAL(MAX(1, nsub), wp) + DO isub = 1, nsub + ts = t - opts%dtM + REAL(isub, wp)*dts + IF (isub == nsub) ts = t + old_rigid = rigid + old_rst = rst + DO k = 1, SIZE(rigid) + CALL CD_Rigid_Advance_Newmark(rigid(k)%r, rigid(k)%v, rigid(k)%rot_mat, rigid(k)%omega, rigid(k)%a, & + rigid(k)%alpha, rigid(k)%a, rigid(k)%alpha, dts, CD_RIGID_NEWMARK_GAMMA, & CD_RIGID_NEWMARK_BETA, es, em) - IF (es /= CD_RIGID_OK) CALL fail_solve(ErrStat, ErrMsg, 'rod finite-rotation update failed: '//TRIM(em)) + IF (es /= CD_RIGID_OK) CALL fail_solve(ErrStat, ErrMsg, 'body finite-rotation update failed: '//TRIM(em)) IF (ErrStat /= CD_DECKDRV_OK) EXIT - CALL pin_rod(rst(k)) - dv0(1:3) = -CD_RIGID_NEWMARK_GAMMA*opts%dtM*old_rst(k)%a - dv0(4:6) = -CD_RIGID_NEWMARK_GAMMA*opts%dtM*old_rst(k)%alpha - CALL objects_acceleration(opts, t, opts%dtM, dv0, acc, alpha, ErrStat, ErrMsg, rod=rst(k), & + dv0(1:3) = -CD_RIGID_NEWMARK_GAMMA*dts*old_rigid(k)%a + dv0(4:6) = -CD_RIGID_NEWMARK_GAMMA*dts*old_rigid(k)%alpha + CALL objects_acceleration(opts, ts, dts, dv0, acc, alpha, ErrStat, ErrMsg, body=rigid(k), & bathymetry=bathymetry) IF (ErrStat /= CD_DECKDRV_OK) EXIT - rst(k) = old_rst(k) - CALL CD_Rigid_Advance_Newmark(rst(k)%r, rst(k)%v, rst(k)%rot_mat, rst(k)%omega, old_rst(k)%a, & - old_rst(k)%alpha, acc, alpha, opts%dtM, CD_RIGID_NEWMARK_GAMMA, & + rigid(k) = old_rigid(k) + CALL CD_Rigid_Advance_Newmark(rigid(k)%r, rigid(k)%v, rigid(k)%rot_mat, rigid(k)%omega, old_rigid(k)%a, & + old_rigid(k)%alpha, acc, alpha, dts, CD_RIGID_NEWMARK_GAMMA, & CD_RIGID_NEWMARK_BETA, es, em) - IF (es /= CD_RIGID_OK) CALL fail_solve(ErrStat, ErrMsg, 'rod finite-rotation update failed: '//TRIM(em)) + IF (es /= CD_RIGID_OK) CALL fail_solve(ErrStat, ErrMsg, 'body finite-rotation update failed: '//TRIM(em)) IF (ErrStat /= CD_DECKDRV_OK) EXIT - rst(k)%a = acc - rst(k)%alpha = alpha - CALL pin_rod(rst(k)) + rigid(k)%a = acc + rigid(k)%alpha = alpha END DO - END IF + IF (ErrStat == CD_DECKDRV_OK) THEN + DO k = 1, SIZE(rst) + IF (.NOT. (rst(k)%is_free .OR. rst(k)%is_pinned)) CYCLE + CALL CD_Rigid_Advance_Newmark(rst(k)%r, rst(k)%v, rst(k)%rot_mat, rst(k)%omega, rst(k)%a, rst(k)%alpha, & + rst(k)%a, rst(k)%alpha, dts, CD_RIGID_NEWMARK_GAMMA, & + CD_RIGID_NEWMARK_BETA, es, em) + IF (es /= CD_RIGID_OK) CALL fail_solve(ErrStat, ErrMsg, 'rod finite-rotation update failed: '//TRIM(em)) + IF (ErrStat /= CD_DECKDRV_OK) EXIT + CALL pin_rod(rst(k)) + dv0(1:3) = -CD_RIGID_NEWMARK_GAMMA*dts*old_rst(k)%a + dv0(4:6) = -CD_RIGID_NEWMARK_GAMMA*dts*old_rst(k)%alpha + CALL objects_acceleration(opts, ts, dts, dv0, acc, alpha, ErrStat, ErrMsg, rod=rst(k), & + bathymetry=bathymetry) + IF (ErrStat /= CD_DECKDRV_OK) EXIT + rst(k) = old_rst(k) + CALL CD_Rigid_Advance_Newmark(rst(k)%r, rst(k)%v, rst(k)%rot_mat, rst(k)%omega, old_rst(k)%a, & + old_rst(k)%alpha, acc, alpha, dts, CD_RIGID_NEWMARK_GAMMA, & + CD_RIGID_NEWMARK_BETA, es, em) + IF (es /= CD_RIGID_OK) CALL fail_solve(ErrStat, ErrMsg, 'rod finite-rotation update failed: '//TRIM(em)) + IF (ErrStat /= CD_DECKDRV_OK) EXIT + rst(k)%a = acc + rst(k)%alpha = alpha + CALL pin_rod(rst(k)) + END DO + END IF + IF (ErrStat /= CD_DECKDRV_OK) EXIT + END DO IF (ErrStat == CD_DECKDRV_OK) THEN CALL CD_Profile_Step() CALL CD_Profile_Enter(CD_PROF_OUTPUT) @@ -17378,6 +17449,54 @@ SUBROUTINE write_row(time) END SUBROUTINE write_row END SUBROUTINE write_objects_dynamic_out + SUBROUTINE objects_substep_count(rigid, rst, opts, time, dt, nsub, ErrStat, ErrMsg, bathymetry) + !! Sub-steps of a step of length dt of the march of a deck without lines + !! (write_objects_dynamic_out), from the estimate of the line-coupled routes without its line + !! springs (rigid_substep_count): a body's hydrostatic restoring and seabed contact, with the + !! contact and waterplane of the rods fixed to it (rigid6_contact_stiffness), over its + !! structural mass and inertia plus the submerged translational added mass, as in + !! step_rigid6_system; a free or pinned rod's own terms (rod_estimate_terms), as in + !! step_rod_system. + TYPE(RigidBodyState), INTENT(IN) :: rigid(:) + TYPE(RodState), INTENT(IN) :: rst(:) + TYPE(DeckOptions), INTENT(IN) :: opts + REAL(wp), INTENT(IN) :: time, dt + INTEGER, INTENT(OUT) :: nsub + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + TYPE(CD_BathymetryType), INTENT(IN), OPTIONAL :: bathymetry + INTEGER :: k, j + REAL(wp) :: omega2, om2, mass6(6), k6(6), w2, shift(3) + + nsub = 1 + ErrStat = CD_DECKDRV_OK + ErrMsg = '' + omega2 = CD_ZERO + DO k = 1, SIZE(rigid) + IF (rigid(k)%is_prescribed) CYCLE + mass6(1:3) = rigid(k)%mass + IF (rigid(k)%r(3) < CD_ZERO) mass6(1:3) = mass6(1:3) + opts%rhoW*rigid(k)%vol*MAX(CD_ZERO, rigid(k)%ca) + mass6(4:6) = global_inertia_diag(rigid(k)%rot_mat, rigid(k)%inertia) + k6 = [CD_ZERO, CD_ZERO, rigid(k)%c33, rigid(k)%c44, rigid(k)%c55, CD_ZERO] + CALL rigid6_contact_stiffness(rigid(k), opts, time, dt, k6, ErrStat, ErrMsg, bathymetry) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + DO j = 1, 6 + IF (mass6(j) > CD_ZERO) omega2 = MAX(omega2, k6(j)/mass6(j)) + END DO + END DO + DO k = 1, SIZE(rst) + IF (.NOT. (rst(k)%is_free .OR. rst(k)%is_pinned)) CYCLE + CALL rod_estimate_terms(rst(k), opts, time, dt, mass6, k6, w2, shift, ErrStat, ErrMsg, bathymetry) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + om2 = CD_ZERO + DO j = 1, 6 + IF (mass6(j) > CD_ZERO) om2 = MAX(om2, k6(j)/mass6(j)) + END DO + omega2 = MAX(omega2, om2 + w2) + END DO + nsub = rigid_substep_count(omega2, dt) + END SUBROUTINE objects_substep_count + ! --------------------------------------------------------------------------- ! ! multibody march: Rigid6 bodies (with fixed and pinned rods), free, pinned ! ! and fixed rods, Free/Connect points, EI=0 lines and finite-EI cables ! @@ -17625,7 +17744,8 @@ SUBROUTINE write_multibody_dynamic_out(deck_path, out_root, channels, types, bod ALLOCATE (mb%cables(SIZE(cab_lines)), mb%cab_kind(SIZE(cab_lines)), mb%cab_obj(SIZE(cab_lines)), & mb%cab_off(3, SIZE(cab_lines)), mb%cab_force(3, SIZE(cab_lines)), & mb%cab_clamp(SIZE(cab_lines)), mb%cab_moment(3, SIZE(cab_lines)), mb%cab_fend(3, SIZE(cab_lines)), & - mb%cab_mend(3, SIZE(cab_lines)), mb%cab_f0(3, SIZE(cab_lines)), mb%cab_m0(3, SIZE(cab_lines))) + mb%cab_mend(3, SIZE(cab_lines)), mb%cab_f0(3, SIZE(cab_lines)), mb%cab_m0(3, SIZE(cab_lines)), & + mb%cab_kax(SIZE(cab_lines)), mb%cab_len(SIZE(cab_lines))) mb%cab_age = HUGE(1) mb%cab_kind = 0 mb%cab_obj = 0 @@ -17637,6 +17757,25 @@ SUBROUTINE write_multibody_dynamic_out(deck_path, out_root, channels, types, bod mb%cab_mend = CD_ZERO mb%cab_f0 = CD_ZERO mb%cab_m0 = CD_ZERO + ! static axial stiffness and length of each cable (its sections, the dynamic modulus when it + ! has one), for the sub-step estimate of the staggered march + DO c = 1, SIZE(cab_lines) + BLOCK + REAL(wp) :: compl, clen, ea_s + INTEGER :: js + compl = CD_ZERO + clen = CD_ZERO + DO js = 1, SIZE(sections) + IF (sections(js)%line_id /= cab_lines(c)%id .OR. sections(js)%ltype < 1) CYCLE + clen = clen + sections(js)%length + ea_s = MAX(types(sections(js)%ltype)%ea, types(sections(js)%ltype)%ea_d) + IF (ea_s > CD_ZERO) compl = compl + sections(js)%length/ea_s + END DO + mb%cab_len(c) = clen + mb%cab_kax(c) = CD_ZERO + IF (compl > CD_ZERO) mb%cab_kax(c) = CD_ONE/compl + END BLOCK + END DO DO c = 1, SIZE(cab_lines) pc = points pa = find_point(points, cab_lines(c)%nodeA) @@ -17944,14 +18083,17 @@ SUBROUTINE CD_Multibody_Probe_Get(rec) END SUBROUTINE CD_Multibody_Probe_Get SUBROUTINE mb_snap_pinned(rod, rigid) - !! A pinned rod keeps End A on its pin: a fixed point, or the pin point of its parent body. + !! A pinned rod keeps End A on its pin: a fixed point, a host node (a CoupledPinned rod on + !! the coupled aggregate, whose pin, pin_v and pin_a the host sets) or the pin point of its + !! parent body. !! Its centre, velocity and acceleration follow the pin motion and the rod's own rotation. TYPE(RodState), INTENT(INOUT) :: rod TYPE(RigidBodyState), INTENT(IN) :: rigid(:) REAL(wp) :: p(3), v_pin(3), a_pin(3), arm(3) IF (.NOT. rod%is_pinned) RETURN - v_pin = CD_ZERO - a_pin = CD_ZERO + ! zero for a fixed pin + v_pin = rod%pin_v + a_pin = rod%pin_a IF (rod%parent > 0) THEN ASSOCIATE (b => rigid(rod%parent)) p = MATMUL(b%rot_mat, rod%pin_body) @@ -18076,6 +18218,44 @@ SUBROUTINE mb_cable_arm(mb, c, arm) END SELECT END SUBROUTINE mb_cable_arm + SUBROUTINE mb_cable_k6(mb, kind, obj, shift, k6) + !! Add to k6 the diagonal stiffness of the finite-EI cables attached to object obj (cab_kind + !! kind) at their arms (mb_cable_arm, plus shift: from a pinned rod's centre to its pin): the + !! directional spring k_ax t t^T + (T/L)(I - t t^T) of line_attachment_stiffness, t along the + !! cable's current end force, T its magnitude, L its unstretched length and k_ax = 1/sum(l0/EA). + !! The staggered march returns the cable end force explicitly, so this spring bounds its step. + TYPE(MultibodyMarch), INTENT(IN) :: mb + INTEGER, INTENT(IN) :: kind, obj + REAL(wp), INTENT(IN) :: shift(3) + REAL(wp), INTENT(INOUT) :: k6(6) + INTEGER :: c, k + REAL(wp) :: arm(3), t(3), ten, katt(3, 3), s(3, 3), krot(3, 3), eye(3, 3) + IF (.NOT. ALLOCATED(mb%cables)) RETURN + eye = CD_ZERO + DO k = 1, 3 + eye(k, k) = CD_ONE + END DO + DO c = 1, SIZE(mb%cables) + IF (mb%cab_kind(c) /= kind .OR. mb%cab_obj(c) /= obj) CYCLE + CALL mb_cable_arm(mb, c, arm) + arm = arm + shift + ten = NORM2(mb%cab_force(:, c)) + IF (ten > CD_ZERO .AND. mb%cab_len(c) > CD_ZERO) THEN + t = mb%cab_force(:, c)/ten + katt = mb%cab_kax(c)*SPREAD(t, 2, 3)*SPREAD(t, 1, 3) + & + ten/mb%cab_len(c)*(eye - SPREAD(t, 2, 3)*SPREAD(t, 1, 3)) + ELSE + katt = mb%cab_kax(c)*eye + END IF + s = skew3(arm) + krot = -MATMUL(s, MATMUL(katt, s)) + DO k = 1, 3 + k6(k) = k6(k) + katt(k, k) + k6(3 + k) = k6(3 + k) + krot(k, k) + END DO + END DO + END SUBROUTINE mb_cable_k6 + SUBROUTINE mb_rod_bases(mb, points, rod, bases, arms) !! System coupled-DOF bases (-1: no EI=0 line) and arms of a rod's End A and End B points. TYPE(MultibodyMarch), INTENT(IN) :: mb @@ -18508,7 +18688,8 @@ END SUBROUTINE mb_line_loads SUBROUTINE mb_step(mb, points, opts, time, dt, converged, stalled, n_iter, ErrStat, ErrMsg, bathymetry) !! Advance the multibody march from time - dt to time, sub-cycled so that the explicit object - !! positions resolve the stiffest object-mooring mode of the EI=0 lines (rigid_substep_count). + !! positions resolve the stiffest object-mooring mode of the EI=0 lines and the objects' own + !! restoring, with or without lines (rigid_substep_count). TYPE(MultibodyMarch), INTENT(INOUT) :: mb TYPE(DeckPoint), INTENT(IN) :: points(:) TYPE(DeckOptions), INTENT(IN) :: opts @@ -18519,7 +18700,7 @@ SUBROUTINE mb_step(mb, points, opts, time, dt, converged, stalled, n_iter, ErrSt TYPE(CD_BathymetryType), INTENT(IN), OPTIONAL :: bathymetry INTEGER :: ib, ir, ip, nsub, isub, it, k, bases(2) LOGICAL :: conv_s, stall_s - REAL(wp) :: omega2, mass6(6), arms(3, 2), f_d(3), m_d(3), added6(6, 6), drag6(6, 6) + REAL(wp) :: omega2, mass6(6), arms(3, 2), f_d(3), m_d(3), added6(6, 6), drag6(6, 6), k6c(6), w2_pin, shift(3) converged = .TRUE. stalled = .FALSE. @@ -18552,45 +18733,73 @@ SUBROUTINE mb_step(mb, points, opts, time, dt, converged, stalled, n_iter, ErrSt END IF END IF omega2 = CD_ZERO - ! a body-only monolithic deck still resolves its hydrostatic restoring - IF (mb%has_sys .OR. mb%implicit) THEN - DO ib = 1, SIZE(mb%rigid) - BLOCK - INTEGER :: att_base(SIZE(mb%rigid(ib)%point_indices)) - REAL(wp) :: att_arm(3, SIZE(mb%rigid(ib)%point_indices)) - DO ip = 1, SIZE(mb%rigid(ib)%point_indices) - att_base(ip) = -1 - IF (mb%has_sys) att_base(ip) = system_point_base(mb%system, & - points(mb%rigid(ib)%point_indices(ip))%id) - att_arm(:, ip) = MATMUL(mb%rigid(ib)%rot_mat, points(mb%rigid(ib)%point_indices(ip))%body_offset) + ! the bodies' own restoring enters with or without lines (a body-only deck still resolves it) + DO ib = 1, SIZE(mb%rigid) + BLOCK + INTEGER :: att_base(SIZE(mb%rigid(ib)%point_indices)) + REAL(wp) :: att_arm(3, SIZE(mb%rigid(ib)%point_indices)) + DO ip = 1, SIZE(mb%rigid(ib)%point_indices) + att_base(ip) = -1 + IF (mb%has_sys) att_base(ip) = system_point_base(mb%system, & + points(mb%rigid(ib)%point_indices(ip))%id) + att_arm(:, ip) = MATMUL(mb%rigid(ib)%rot_mat, points(mb%rigid(ib)%point_indices(ip))%body_offset) + END DO + mass6(1:3) = mb%rigid(ib)%mass + IF (mb%rigid(ib)%r(3) < CD_ZERO) mass6(1:3) = mass6(1:3) + opts%rhoW*mb%rigid(ib)%vol* & + MAX(CD_ZERO, mb%rigid(ib)%ca) + mass6(4:6) = global_inertia_diag(mb%rigid(ib)%rot_mat, mb%rigid(ib)%inertia) + IF (ALLOCATED(mb%rigid(ib)%att_rods)) THEN + DO k = 1, SIZE(mb%rigid(ib)%att_rods) + mass6(1:3) = mass6(1:3) + mb%rigid(ib)%att_rods(k)%mass END DO - mass6(1:3) = mb%rigid(ib)%mass - IF (mb%rigid(ib)%r(3) < CD_ZERO) mass6(1:3) = mass6(1:3) + opts%rhoW*mb%rigid(ib)%vol* & - MAX(CD_ZERO, mb%rigid(ib)%ca) - mass6(4:6) = global_inertia_diag(mb%rigid(ib)%rot_mat, mb%rigid(ib)%inertia) - IF (ALLOCATED(mb%rigid(ib)%att_rods)) THEN - DO k = 1, SIZE(mb%rigid(ib)%att_rods) - mass6(1:3) = mass6(1:3) + mb%rigid(ib)%att_rods(k)%mass - END DO - END IF - omega2 = MAX(omega2, rigid_omega2_estimate(mb%system, att_base, att_arm, mass6, & - [CD_ZERO, CD_ZERO, mb%rigid(ib)%c33, mb%rigid(ib)%c44, & - mb%rigid(ib)%c55, CD_ZERO])) - END BLOCK - END DO - END IF - IF (mb%has_sys) THEN + END IF + ! hydrostatic restoring; the staggered scheme's explicit positions also meet the seabed + ! contact that acts within the step (the monolithic scheme carries it in its Jacobian) + k6c = [CD_ZERO, CD_ZERO, mb%rigid(ib)%c33, mb%rigid(ib)%c44, mb%rigid(ib)%c55, CD_ZERO] + IF (.NOT. mb%implicit) THEN + CALL rigid6_contact_stiffness(mb%rigid(ib), opts, time - dt, dt, k6c, ErrStat, ErrMsg, bathymetry) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + CALL mb_cable_k6(mb, 1, ib, [CD_ZERO, CD_ZERO, CD_ZERO], k6c) + END IF + omega2 = MAX(omega2, rigid_omega2_estimate(mb%system, att_base, att_arm, mass6, k6c)) + END BLOCK + END DO + ! the rods' own terms enter the staggered scheme with or without lines + IF (mb%has_sys .OR. .NOT. mb%implicit) THEN DO ir = 1, SIZE(mb%rods) IF (.NOT. (mb%rods(ir)%is_free .OR. mb%rods(ir)%is_pinned)) CYCLE CALL mb_rod_bases(mb, points, mb%rods(ir), bases, arms) - CALL rod_environment_force(mb%rods(ir), opts, time - dt, f_d, m_d, added6, drag6, ErrStat, ErrMsg) + IF (mb%implicit) THEN + ! monolithic accuracy sub-steps: the line springs over the structural plus added mass + CALL rod_environment_force(mb%rods(ir), opts, time - dt, f_d, m_d, added6, drag6, ErrStat, ErrMsg) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + mass6(1:3) = mb%rods(ir)%mass + mass6(4:6) = global_inertia_diag(mb%rods(ir)%rot_mat, mb%rods(ir)%inertia) + DO k = 1, 6 + mass6(k) = mass6(k) + MAX(CD_ZERO, added6(k, k)) + END DO + omega2 = MAX(omega2, rigid_omega2_estimate(mb%system, bases, arms, mass6)) + CYCLE + END IF + ! the staggered scheme's explicit positions also meet the rod's own terms + ! (rod_estimate_terms, as in step_rod_system: a pinned rod about its pin, with the pin + ! acceleration of its parent body) and its finite-EI cables (mb_cable_k6), whose end + ! forces it applies explicitly; the monolithic scheme carries the contact and the + ! hydrostatics in its Jacobian + IF (mb%rods(ir)%is_pinned .AND. mb%rods(ir)%parent > 0) THEN + CALL rod_estimate_terms(mb%rods(ir), opts, time - dt, dt, mass6, k6c, w2_pin, shift, ErrStat, ErrMsg, & + bathymetry, parent=mb%rigid(mb%rods(ir)%parent)) + ELSE + CALL rod_estimate_terms(mb%rods(ir), opts, time - dt, dt, mass6, k6c, w2_pin, shift, ErrStat, ErrMsg, & + bathymetry) + END IF IF (ErrStat /= CD_DECKDRV_OK) RETURN - mass6(1:3) = mb%rods(ir)%mass - mass6(4:6) = global_inertia_diag(mb%rods(ir)%rot_mat, mb%rods(ir)%inertia) - DO k = 1, 6 - mass6(k) = mass6(k) + MAX(CD_ZERO, added6(k, k)) - END DO - omega2 = MAX(omega2, rigid_omega2_estimate(mb%system, bases, arms, mass6)) + IF (mb%rods(ir)%is_pinned) THEN + arms(:, 1) = arms(:, 1) + shift + arms(:, 2) = arms(:, 2) + shift + END IF + CALL mb_cable_k6(mb, 2, ir, shift, k6c) + omega2 = MAX(omega2, rigid_omega2_estimate(mb%system, bases, arms, mass6, k6c) + w2_pin) END DO END IF IF (mb%implicit) THEN @@ -19922,7 +20131,7 @@ FUNCTION line_attachment_stiffness(system, dof) RESULT(katt) END DO END FUNCTION line_attachment_stiffness - PURE INTEGER FUNCTION rigid_substep_count(omega2, dt, omega_dt_max) RESULT(nsub) + INTEGER FUNCTION rigid_substep_count(omega2, dt, omega_dt_max) RESULT(nsub) !! Sub-steps per coupled step so that omega*dt_sub stays at or below RIGID_OMEGA_DT_MAX, !! capped at RIGID_MAX_SUBSTEPS. The explicit central-difference stability limit is !! omega*dt < 2, and omega from rigid_omega2_estimate (directional line stiffness, added @@ -19930,11 +20139,14 @@ PURE INTEGER FUNCTION rigid_substep_count(omega2, dt, omega_dt_max) RESULT(nsub) !! on short lines goes unstable at an estimated omega*dt of 1.27). The limit 0.4 is set by !! accuracy, not stability: a rod released out of equilibrium at dt 0.1 s keeps its !! fairlead-tension transient within 1.5% of a dt 0.005 s run. omega_dt_max replaces the - !! limit (bodySubstep accuracy of the monolithic scheme). + !! limit (bodySubstep accuracy of the monolithic scheme). A step that needs more than the + !! cap is warned about once per run (process): its sub-steps then exceed the limit, and + !! beyond omega*dt_sub = 2 the explicit step is unstable, so dtM must come down. REAL(wp), INTENT(IN) :: omega2, dt REAL(wp), INTENT(IN), OPTIONAL :: omega_dt_max REAL(wp), PARAMETER :: RIGID_OMEGA_DT_MAX = 0.4_wp INTEGER, PARAMETER :: RIGID_MAX_SUBSTEPS = 256 + LOGICAL, SAVE :: warned = .FALSE. REAL(wp) :: ratio, lim nsub = 1 IF (.NOT. (omega2 > CD_ZERO .AND. dt > CD_ZERO)) RETURN @@ -19943,6 +20155,14 @@ PURE INTEGER FUNCTION rigid_substep_count(omega2, dt, omega_dt_max) RESULT(nsub) ratio = SQRT(omega2)*dt/lim IF (.NOT. (ratio < REAL(RIGID_MAX_SUBSTEPS, wp))) THEN nsub = RIGID_MAX_SUBSTEPS + !$OMP CRITICAL (cd_substep_cap_warning) + IF (.NOT. warned) THEN + warned = .TRUE. + WRITE (output_unit, '(A,I0,A,ES10.3,A)') ' Warning: an object step needs more than ', RIGID_MAX_SUBSTEPS, & + ' sub-steps (estimated omega dt_sub at the cap ', SQRT(omega2)*dt/REAL(RIGID_MAX_SUBSTEPS, wp), & + '; the explicit step is unstable above 2): reduce dtM.' + END IF + !$OMP END CRITICAL (cd_substep_cap_warning) ELSE IF (ratio > CD_ONE) THEN nsub = CEILING(ratio) END IF @@ -19951,8 +20171,9 @@ END FUNCTION rigid_substep_count SUBROUTINE step_rod_system(system, points, opts, rod_state, time, dt, converged, stalled, n_iter, ErrStat, ErrMsg, & work, bathymetry, host_mask, host_q, host_v, host_a, host_start) !! Advance rods and lines from time - dt to time: step_rod_once, sub-cycled so that the - !! explicit central-difference rod position resolves the stiffest rod-mooring mode - !! (rigid_substep_count). converged is the AND and stalled the OR over the sub-steps. + !! explicit central-difference rod position resolves the stiffest rod-mooring mode and the + !! swing of a pinned rod about its pin (rigid_substep_count). converged is the AND and + !! stalled the OR over the sub-steps. TYPE(CD_SystemType), INTENT(INOUT) :: system TYPE(DeckPoint), INTENT(IN) :: points(:) TYPE(DeckOptions), INTENT(IN) :: opts @@ -19969,12 +20190,14 @@ SUBROUTINE step_rod_system(system, points, opts, rod_state, time, dt, converged, LOGICAL, INTENT(IN), OPTIONAL :: host_mask(:) REAL(wp), INTENT(IN), OPTIONAL :: host_q(:), host_v(:), host_a(:) - INTEGER :: ir, nsub, isub, it, base_a, base_b, k - ! host_start: step-start state of the host-driven rods (see step_rigid6_system) + INTEGER :: ir, nsub, isub, it, base_a, base_b + ! host_start: step-start state of the Coupled/Vessel rods (see step_rigid6_system); a + ! host-pinned rod carries its step-start pin itself (RodState%pin0) TYPE(RodState), INTENT(IN), OPTIONAL :: host_start(:) REAL(wp), ALLOCATABLE :: hk_end(:, :) - LOGICAL :: conv_s, stall_s - REAL(wp) :: omega2, arms(3, 2), mass6(6), added6(6, 6), drag6(6, 6), f_dummy(3), m_dummy(3) + LOGICAL :: conv_s, stall_s, host_pins + REAL(wp) :: omega2, arms(3, 2), mass6(6), k6c(6), w2_pin, shift(3) + TYPE(RodState) :: rod0 REAL(wp), ALLOCATABLE :: q0h(:), v0h(:), a0h(:) converged = .TRUE. @@ -19982,28 +20205,57 @@ SUBROUTINE step_rod_system(system, points, opts, rod_state, time, dt, converged, n_iter = 0 omega2 = CD_ZERO DO ir = 1, SIZE(rod_state) - IF (.NOT. rod_state(ir)%is_free) CYCLE + IF (.NOT. (rod_state(ir)%is_free .OR. rod_state(ir)%is_pinned)) CYCLE arms(:, 1) = MATMUL(rod_state(ir)%rot_mat, [-rod_state(ir)%half_length, CD_ZERO, CD_ZERO]) arms(:, 2) = -arms(:, 1) - base_a = system_point_base(system, points(rod_state(ir)%point_a_index)%id) - base_b = system_point_base(system, points(rod_state(ir)%point_b_index)%id) - ! structural inertia plus the rod's wet added mass (its 6x6 added-mass diagonal) - CALL rod_environment_force(rod_state(ir), opts, time - dt, f_dummy, m_dummy, added6, drag6, ErrStat, ErrMsg) + base_a = rod_end_base(system, points, rod_state(ir)%point_a_index) + base_b = rod_end_base(system, points, rod_state(ir)%point_b_index) + ! the rod's own terms (rod_estimate_terms): a free rod's structural plus added mass with its + ! seabed contact and waterplane stiffness; a pinned rod only turns about its pin, so its line + ! ends act through their arms from the pin on its rotational inertia about the pin (the + ! translational entries stay zero, so rigid_omega2_estimate skips them), and its weight, + ! buoyancy, pin acceleration, seabed contact and waterplane make it a compound pendulum even + ! without a line, whose squared frequency w2_pin adds to that of the lines + IF (rod_state(ir)%is_host_pinned) THEN + ! the host has already placed the pin at t + dt: the rod at its step-start pin (pin0) is + ! bounded with it, so that a step whose pin crosses the free surface keeps the restoring + ! of the wetting it starts from (and of its seabed contact) + rod0 = rod_state(ir) + rod0%r = rod0%r + (rod0%pin0 - rod0%pin) + rod0%pin = rod0%pin0 + CALL rod_estimate_terms(rod_state(ir), opts, time - dt, dt, mass6, k6c, w2_pin, shift, ErrStat, ErrMsg, & + bathymetry, rod_start=rod0) + ELSE + CALL rod_estimate_terms(rod_state(ir), opts, time - dt, dt, mass6, k6c, w2_pin, shift, ErrStat, ErrMsg, & + bathymetry) + END IF IF (ErrStat /= CD_DECKDRV_OK) RETURN - mass6(1:3) = rod_state(ir)%mass - mass6(4:6) = global_inertia_diag(rod_state(ir)%rot_mat, rod_state(ir)%inertia) - DO k = 1, 6 - mass6(k) = mass6(k) + MAX(CD_ZERO, added6(k, k)) - END DO - omega2 = MAX(omega2, rigid_omega2_estimate(system, [base_a, base_b], arms, mass6)) + IF (rod_state(ir)%is_pinned) THEN + arms(:, 1) = arms(:, 1) + shift + arms(:, 2) = arms(:, 2) + shift + END IF + omega2 = MAX(omega2, rigid_omega2_estimate(system, [base_a, base_b], arms, mass6, k6c) + w2_pin) END DO nsub = rigid_substep_count(omega2, dt) CALL host_substep_start(system, nsub, q0h, v0h, a0h, ErrStat, ErrMsg, host_mask) IF (ErrStat /= CD_DECKDRV_OK) RETURN + ! A host-pinned rod without a committed acceleration (the first step) takes its starting + ! acceleration with its pin at the step start: the host has already placed the pin at + ! t + dt, so the rods go back to their step-start pin (pin0, which the rod state carries; + ! no staged copy is needed) for it and return to t + dt after it. + host_pins = ANY(rod_state%is_host_pinned) + IF (ANY(rod_state%is_host_pinned .AND. .NOT. rod_state%accel_valid)) THEN + CALL save_host_end_rod(rod_state, hk_end) + CALL interp_host_pins(rod_state, hk_end, CD_ZERO) + CALL rod_start_accelerations(system, points, opts, rod_state, time - dt, work, ErrStat, ErrMsg, bathymetry) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + CALL interp_host_pins(rod_state, hk_end, CD_ONE) + END IF DO isub = 1, nsub - IF (nsub > 1 .AND. PRESENT(host_start)) THEN + IF (nsub > 1 .AND. (PRESENT(host_start) .OR. host_pins)) THEN IF (isub == 1) CALL save_host_end_rod(rod_state, hk_end) - CALL interp_host_rod(rod_state, host_start, hk_end, REAL(isub, wp)/REAL(nsub, wp)) + IF (PRESENT(host_start)) CALL interp_host_rod(rod_state, host_start, hk_end, REAL(isub, wp)/REAL(nsub, wp)) + IF (host_pins) CALL interp_host_pins(rod_state, hk_end, REAL(isub, wp)/REAL(nsub, wp)) END IF IF (.NOT. PRESENT(host_mask)) THEN CALL step_rod_once(system, points, opts, rod_state, time - dt + REAL(isub, wp)*dt/REAL(nsub, wp), & @@ -20024,6 +20276,10 @@ SUBROUTINE step_rod_system(system, points, opts, rod_state, time, dt, converged, n_iter = n_iter + it IF (ErrStat /= CD_DECKDRV_OK) RETURN END DO + ! the committed pin of a host-pinned rod starts its next step + DO ir = 1, SIZE(rod_state) + IF (rod_state(ir)%is_host_pinned) CALL set_rod_pin_start(rod_state(ir)) + END DO END SUBROUTINE step_rod_system SUBROUTINE save_host_end_rigid(rigid, hk) @@ -20073,20 +20329,22 @@ SUBROUTINE interp_host_rigid(rigid, start, hk, s) END SUBROUTINE interp_host_rigid SUBROUTINE save_host_end_rod(rods, hk) - !! Rod twin of save_host_end_rigid. + !! Rod twin of save_host_end_rigid; rows 25 to 33 hold the pin, pin velocity and pin + !! acceleration (the host kinematics of a host-pinned rod). TYPE(RodState), INTENT(IN) :: rods(:) REAL(wp), ALLOCATABLE, INTENT(INOUT) :: hk(:, :) INTEGER :: ir IF (ALLOCATED(hk)) DEALLOCATE (hk) - ALLOCATE (hk(24, SIZE(rods))) + ALLOCATE (hk(33, SIZE(rods))) DO ir = 1, SIZE(rods) hk(:, ir) = [rods(ir)%r, rods(ir)%v, rods(ir)%a, rods(ir)%omega, rods(ir)%alpha, & - RESHAPE(rods(ir)%rot_mat, [9])] + RESHAPE(rods(ir)%rot_mat, [9]), rods(ir)%pin, rods(ir)%pin_v, rods(ir)%pin_a] END DO END SUBROUTINE save_host_end_rod SUBROUTINE interp_host_rod(rods, start, hk, s) - !! Rod twin of interp_host_rigid (the rod centre and frame of each host-driven rod). + !! Rod twin of interp_host_rigid (the rod centre and frame of each Coupled/Vessel rod; a + !! host-pinned rod moves its pin in interp_host_pins). TYPE(RodState), INTENT(INOUT) :: rods(:) TYPE(RodState), INTENT(IN) :: start(:) REAL(wp), INTENT(IN) :: hk(:, :), s @@ -20114,10 +20372,43 @@ SUBROUTINE interp_host_rod(rods, start, hk, s) END DO END SUBROUTINE interp_host_rod + SUBROUTINE interp_host_pins(rods, hk, s) + !! Place the pin of every host-pinned rod at fraction s of its step and move the rod with it + !! (mb_snap_pinned); the rod keeps its own rotation. Position, velocity and acceleration are + !! each linear between the step-start pin (pin0, the End A motion of the committed rod state, + !! as the line ends see it) and the t + dt host values in hk (rows 25 to 33); s = 1 restores + !! the t + dt pin. This is the interpolation the sub-steps give every other host node (the + !! host fairleads of the lines and the Coupled rods), so points on one platform keep their + !! relative positions under a translation inside the step. It is second order: between exact + !! end values a linear position deviates from the host path by at most dt^2 max|a|/8, the + !! velocity by dt^2 max|da/dt|/8 and the acceleration by dt^2 max|d2a/dt2|/8, and the + !! interpolated velocity is not the derivative of the interpolated position (the two differ + !! by O(dt max|a|)). A constant-velocity pin is reproduced exactly. + TYPE(RodState), INTENT(INOUT) :: rods(:) + REAL(wp), INTENT(IN) :: hk(:, :), s + INTEGER :: ir + TYPE(RigidBodyState) :: no_parent(0) + DO ir = 1, SIZE(rods) + IF (.NOT. rods(ir)%is_host_pinned) CYCLE + IF (s >= CD_ONE) THEN + rods(ir)%pin = hk(25:27, ir) + rods(ir)%pin_v = hk(28:30, ir) + rods(ir)%pin_a = hk(31:33, ir) + ELSE + rods(ir)%pin = rods(ir)%pin0 + s*(hk(25:27, ir) - rods(ir)%pin0) + rods(ir)%pin_v = rods(ir)%pin0_v + s*(hk(28:30, ir) - rods(ir)%pin0_v) + rods(ir)%pin_a = rods(ir)%pin0_a + s*(hk(31:33, ir) - rods(ir)%pin0_a) + END IF + CALL mb_snap_pinned(rods(ir), no_parent) + END DO + END SUBROUTINE interp_host_pins + SUBROUTINE step_rod_once(system, points, opts, rod_state, time, dt, converged, stalled, n_iter, ErrStat, ErrMsg, & work, bathymetry, host_mask, host_q, host_v, host_a) - !! One staggered central-difference step of the free rods and their lines (the scheme of - !! step_rigid6_once; the rod adds its 6x6 added-mass matrix and distributed drag). + !! One staggered central-difference step of the free and pinned rods and their lines (the + !! scheme of step_rigid6_once; the rod adds its 6x6 added-mass matrix and distributed drag). + !! A pinned rod (fixed pin, or a host-pinned rod whose pin the host has placed at t + dt) + !! integrates its rotation about the pin only. TYPE(CD_SystemType), INTENT(INOUT) :: system TYPE(DeckPoint), INTENT(IN) :: points(:) TYPE(DeckOptions), INTENT(IN) :: opts @@ -20136,8 +20427,9 @@ SUBROUTINE step_rod_once(system, points, opts, rod_state, time, dt, converged, s REAL(wp), INTENT(IN), OPTIONAL :: host_q(:), host_v(:), host_a(:) INTEGER :: ir, es - REAL(wp) :: dv0(6), acc(3), alpha(3) + REAL(wp) :: dv0(6), acc(3), alpha(3), arm(3) CHARACTER(160) :: em + TYPE(RigidBodyState) :: no_parent(0) converged = .FALSE. stalled = .FALSE. @@ -20145,24 +20437,10 @@ SUBROUTINE step_rod_once(system, points, opts, rod_state, time, dt, converged, s ErrStat = CD_DECKDRV_OK ErrMsg = '' CALL ensure_rod_step_workspace(work, system%n_system_coupled_dof, SIZE(rod_state), SIZE(system%points)) - ! 0. a free rod without a committed acceleration (the first step) gets the instantaneous - ! one from the current line loads, so the predictor starts from the actual a_0 - IF (.NOT. ALL(rod_state%accel_valid .OR. .NOT. rod_state%is_free)) THEN - CALL rigid_start_loads(system, work%q(1:system%n_system_coupled_dof), work%v(1:system%n_system_coupled_dof), & - work%a(1:system%n_system_coupled_dof), work%loads(1:system%n_system_coupled_dof), & - work%dload_da, ErrStat, ErrMsg) - IF (ErrStat /= CD_DECKDRV_OK) RETURN - DO ir = 1, SIZE(rod_state) - IF (rod_state(ir)%accel_valid .OR. .NOT. rod_state(ir)%is_free) CYCLE - CALL rod_body_acceleration(system, points, opts, rod_state(ir), time - dt, CD_ZERO, & - [CD_ZERO, CD_ZERO, CD_ZERO, CD_ZERO, CD_ZERO, CD_ZERO], work, acc, alpha, & - ErrStat, ErrMsg, bathymetry) - IF (ErrStat /= CD_DECKDRV_OK) RETURN - rod_state(ir)%a = acc - rod_state(ir)%alpha = alpha - rod_state(ir)%accel_valid = .TRUE. - END DO - END IF + ! 0. a free or pinned rod without a committed acceleration (the first step) gets the + ! instantaneous one from the current line loads, so the predictor starts from the actual a_0 + CALL rod_start_accelerations(system, points, opts, rod_state, time - dt, work, ErrStat, ErrMsg, bathymetry) + IF (ErrStat /= CD_DECKDRV_OK) RETURN work%old_rods = rod_state work%old_points = system%points CALL CD_Get_System_CoupledMotion(system, work%q(1:system%n_system_coupled_dof), & @@ -20175,10 +20453,12 @@ SUBROUTINE step_rod_once(system, points, opts, rod_state, time, dt, converged, s END IF CALL overlay_host_motion(work%q(1:system%n_system_coupled_dof), work%v(1:system%n_system_coupled_dof), & work%a(1:system%n_system_coupled_dof), host_mask, host_q, host_v, host_a) - ! 1. predictor for the free rods (central difference; see step_rigid6_once for the - ! staggered predictor-corrector) and the line step to t + dt + ! 1. predictor for the free and pinned rods (central difference; see step_rigid6_once for + ! the staggered predictor-corrector) and the line step to t + dt. A pinned rod advances its + ! rotation only: its centre then follows the pin at t + dt (mb_snap_pinned), so End A + ! drives its lines with the pin motion exactly. DO ir = 1, SIZE(rod_state) - IF (.NOT. rod_state(ir)%is_free) THEN + IF (.NOT. (rod_state(ir)%is_free .OR. rod_state(ir)%is_pinned)) THEN IF (.NOT. rod_state(ir)%is_prescribed) THEN rod_state(ir)%v = CD_ZERO rod_state(ir)%a = CD_ZERO @@ -20196,6 +20476,7 @@ SUBROUTINE step_rod_once(system, points, opts, rod_state, time, dt, converged, s ErrMsg = 'CableDyn_DeckDriver: rod finite-rotation update failed: '//TRIM(em) RETURN END IF + CALL mb_snap_pinned(rod_state(ir), no_parent) END DO CALL scatter_rod_point_motion(system, points, rod_state, work%q(1:system%n_system_coupled_dof), & work%v(1:system%n_system_coupled_dof), & @@ -20220,7 +20501,7 @@ SUBROUTINE step_rod_once(system, points, opts, rod_state, time, dt, converged, s ErrMsg = 'CableDyn_DeckDriver: rod line-system step failed: '//TRIM(em) RETURN END IF - IF (.NOT. ANY(rod_state%is_free)) RETURN + IF (.NOT. ANY(rod_state%is_free .OR. rod_state%is_pinned)) RETURN ! 2. corrector from the end-of-step line loads at the predictor CALL CD_Calc_System_CoupledLoads(system, work%loads(1:system%n_system_coupled_dof), es, em) IF (es /= CD_SYSTEM_OK) THEN @@ -20240,9 +20521,18 @@ SUBROUTINE step_rod_once(system, points, opts, rod_state, time, dt, converged, s END IF DO ir = 1, SIZE(rod_state) - IF (.NOT. rod_state(ir)%is_free) CYCLE - dv0(1:3) = -CD_RIGID_NEWMARK_GAMMA*dt*work%old_rods(ir)%a + IF (.NOT. (rod_state(ir)%is_free .OR. rod_state(ir)%is_pinned)) CYCLE dv0(4:6) = -CD_RIGID_NEWMARK_GAMMA*dt*work%old_rods(ir)%alpha + IF (rod_state(ir)%is_pinned) THEN + ! The predictor centre velocity is the pin's plus w x r, so the final one differs from it + ! by gamma dt (alpha_{n+1} - alpha_n) x r only: with x = T y + b (rigid_coupled_acceleration) + ! that is dv0 + gamma dt x for dv0 = -gamma dt (alpha_n x r + b), b = a_p + w x (w x r). + arm = rod_state(ir)%r - rod_state(ir)%pin + dv0(1:3) = -CD_RIGID_NEWMARK_GAMMA*dt*(cross3(work%old_rods(ir)%alpha, arm) + rod_state(ir)%pin_a + & + cross3(rod_state(ir)%omega, cross3(rod_state(ir)%omega, arm))) + ELSE + dv0(1:3) = -CD_RIGID_NEWMARK_GAMMA*dt*work%old_rods(ir)%a + END IF CALL rod_body_acceleration(system, points, opts, rod_state(ir), time, dt, dv0, work, acc, alpha, & ErrStat, ErrMsg, bathymetry) IF (ErrStat /= CD_DECKDRV_OK) THEN @@ -20264,6 +20554,7 @@ SUBROUTINE step_rod_once(system, points, opts, rod_state, time, dt, converged, s END IF rod_state(ir)%a = acc rod_state(ir)%alpha = alpha + CALL mb_snap_pinned(rod_state(ir), no_parent) END DO ! the RodA/B point records follow the corrected rods CALL scatter_rod_point_motion(system, points, rod_state, work%q(1:system%n_system_coupled_dof), & @@ -20282,12 +20573,13 @@ SUBROUTINE step_rod_once(system, points, opts, rod_state, time, dt, converged, s END SUBROUTINE step_rod_once SUBROUTINE rod_body_acceleration(system, points, opts, rod, time, dt, dv0, work, acc, alpha, ErrStat, ErrMsg, & - bathymetry) - !! The acceleration of a free rod at its current state and time from its weight, the - !! distributed Morison / buoyancy loads (rod_environment_force), the seabed contact and the - !! line loads in work%loads (evaluated with the attachment accelerations work%a, end-node + bathymetry, pin_load) + !! The acceleration of a free or pinned rod at its current state and time from its weight, + !! the distributed Morison / buoyancy loads (rod_environment_force), the seabed contact and + !! the line loads in work%loads (evaluated with the attachment accelerations work%a, end-node !! inertia derivative work%dload_da): rigid_coupled_acceleration with the step dt and - !! velocity offset dv0 (dt = 0, dv0 = 0: the instantaneous acceleration). + !! velocity offset dv0 (dt = 0, dv0 = 0: the instantaneous acceleration). A pinned rod turns + !! about its pin, which moves with rod%pin_a (zero for a fixed pin). TYPE(CD_SystemType), INTENT(IN) :: system TYPE(DeckPoint), INTENT(IN) :: points(:) TYPE(DeckOptions), INTENT(IN) :: opts @@ -20298,6 +20590,8 @@ SUBROUTINE rod_body_acceleration(system, points, opts, rod, time, dt, dv0, work, INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg TYPE(CD_BathymetryType), INTENT(IN), OPTIONAL :: bathymetry + ! pin_load (a pinned rod): the force the rod exerts on its pin (rigid_coupled_acceleration) + REAL(wp), INTENT(OUT), OPTIONAL :: pin_load(3) INTEGER :: base_a, base_b REAL(wp) :: f_body(3), f_env(3), f_seabed(3), m_env(3), m_seabed(3), m_global(3) @@ -20307,8 +20601,8 @@ SUBROUTINE rod_body_acceleration(system, points, opts, rod, time, dt, dv0, work, alpha = CD_ZERO att_arm(:, 1) = MATMUL(rod%rot_mat, [-rod%half_length, CD_ZERO, CD_ZERO]) att_arm(:, 2) = -att_arm(:, 1) - base_a = system_point_base(system, points(rod%point_a_index)%id) - base_b = system_point_base(system, points(rod%point_b_index)%id) + base_a = rod_end_base(system, points, rod%point_a_index) + base_b = rod_end_base(system, points, rod%point_b_index) f_a = CD_ZERO f_b = CD_ZERO IF (base_a >= 0) f_a = work%loads(base_a + 1:base_a + 3) @@ -20323,11 +20617,158 @@ SUBROUTINE rod_body_acceleration(system, points, opts, rod, time, dt, dv0, work, IF (ErrStat /= CD_DECKDRV_OK) RETURN f_body = f_body + f_env + f_seabed m_global = m_global + m_env + m_seabed - CALL rigid_coupled_acceleration(work%dload_da, dt, work%a(1:system%n_system_coupled_dof), [base_a, base_b], & - att_arm, rod%mass, added6, rod%inertia, rod%rot_mat, rod%omega, f_body, & - m_global, dv0, drag6 + contact_dv, acc, alpha, ErrStat, ErrMsg) + IF (rod%is_pinned) THEN + CALL rigid_coupled_acceleration(work%dload_da, dt, work%a(1:system%n_system_coupled_dof), [base_a, base_b], & + att_arm, rod%mass, added6, rod%inertia, rod%rot_mat, rod%omega, f_body, & + m_global, dv0, drag6 + contact_dv, acc, alpha, ErrStat, ErrMsg, & + pin_arm=rod%r - rod%pin, pin_acc=rod%pin_a, pin_load=pin_load) + ELSE + CALL rigid_coupled_acceleration(work%dload_da, dt, work%a(1:system%n_system_coupled_dof), [base_a, base_b], & + att_arm, rod%mass, added6, rod%inertia, rod%rot_mat, rod%omega, f_body, & + m_global, dv0, drag6 + contact_dv, acc, alpha, ErrStat, ErrMsg) + END IF END SUBROUTINE rod_body_acceleration + SUBROUTINE rod_start_accelerations(system, points, opts, rod_state, time, work, ErrStat, ErrMsg, bathymetry) + !! The instantaneous acceleration of every free or pinned rod without a committed one (the + !! first step) from the current line loads at time, so the predictor starts from the + !! actual a_0 (rod_body_acceleration at dt = 0). + TYPE(CD_SystemType), INTENT(INOUT) :: system + TYPE(DeckPoint), INTENT(IN) :: points(:) + TYPE(DeckOptions), INTENT(IN) :: opts + TYPE(RodState), INTENT(INOUT) :: rod_state(:) + REAL(wp), INTENT(IN) :: time + TYPE(RodStepWorkspace), INTENT(INOUT) :: work + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + TYPE(CD_BathymetryType), INTENT(IN), OPTIONAL :: bathymetry + INTEGER :: ir + REAL(wp) :: acc(3), alpha(3) + TYPE(RigidBodyState) :: no_parent(0) + + ErrStat = CD_DECKDRV_OK + ErrMsg = '' + IF (ALL(rod_state%accel_valid .OR. .NOT. (rod_state%is_free .OR. rod_state%is_pinned))) RETURN + CALL ensure_rod_step_workspace(work, system%n_system_coupled_dof, SIZE(rod_state), SIZE(system%points)) + CALL rigid_start_loads(system, work%q(1:system%n_system_coupled_dof), work%v(1:system%n_system_coupled_dof), & + work%a(1:system%n_system_coupled_dof), work%loads(1:system%n_system_coupled_dof), & + work%dload_da, ErrStat, ErrMsg) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + DO ir = 1, SIZE(rod_state) + IF (rod_state(ir)%accel_valid .OR. .NOT. (rod_state(ir)%is_free .OR. rod_state(ir)%is_pinned)) CYCLE + CALL rod_body_acceleration(system, points, opts, rod_state(ir), time, CD_ZERO, & + [CD_ZERO, CD_ZERO, CD_ZERO, CD_ZERO, CD_ZERO, CD_ZERO], work, acc, alpha, & + ErrStat, ErrMsg, bathymetry) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + rod_state(ir)%a = acc + rod_state(ir)%alpha = alpha + rod_state(ir)%accel_valid = .TRUE. + CALL mb_snap_pinned(rod_state(ir), no_parent) + END DO + END SUBROUTINE rod_start_accelerations + + FUNCTION pinned_rotational_inertia(rod, added6) RESULT(mp) + !! The 3x3 rotational inertia of a pinned rod about its pin (global axes): the structural + !! and added mass about the centre, T^T M T with T = [-[r]x; I] and r from the pin to the + !! centre (the reduction of rigid_coupled_acceleration). + TYPE(RodState), INTENT(IN) :: rod + REAL(wp), INTENT(IN) :: added6(6, 6) + REAL(wp) :: mp(3, 3) + REAL(wp) :: m6(6, 6), t63(6, 3), ig(3, 3) + INTEGER :: k + ig = CD_ZERO + DO k = 1, 3 + ig(k, k) = rod%inertia(k) + END DO + m6 = added6 + DO k = 1, 3 + m6(k, k) = m6(k, k) + rod%mass + END DO + m6(4:6, 4:6) = m6(4:6, 4:6) + MATMUL(rod%rot_mat, MATMUL(ig, TRANSPOSE(rod%rot_mat))) + t63 = CD_ZERO + t63(1:3, :) = -skew3(rod%r - rod%pin) + DO k = 1, 3 + t63(3 + k, k) = CD_ONE + END DO + mp = MATMUL(TRANSPOSE(t63), MATMUL(m6, t63)) + END FUNCTION pinned_rotational_inertia + + FUNCTION pinned_swing_omega2(rod, opts, mp, added6, buoyancy, mp_start, added_start, buoy_start, k_extra) & + RESULT(omega2) + !! Squared frequency of a pinned rod swinging about its pin under its weight, its buoyancy + !! and the pin acceleration, for the sub-step estimate of step_rod_system (added there to + !! the line estimate). Vertical loads f_i at p_i from the pin turn with the rod; the moment + !! of the loads about the pin has the rotational stiffness -[e_z]x [P]x with P = sum f_i p_i, + !! whose length |P| does not depend on the pose for a fixed load distribution and is the + !! swing stiffness at the bottom of the compound pendulum: |W d_g - B d_b| for a weight W and + !! a buoyancy B on the axis at d_g and d_b from the pin (omega^2 about 3 g/(2 L) for a dry + !! uniform rod). The buoyancy is the wet distribution of the evaluated pose + !! (rod_environment_force); the change of a surface-piercing rod's wet length with its tilt + !! enters through k_extra (rod_hydrostatic_stiffness). The pin acceleration a_p loads the + !! rod with -M_t a_p, whose + !! stiffness is |a_p| |G|, G = [r]x M_tt + M_rt the first moment of the translational inertia + !! (structural and added) about the pin: c [q]x for a rod (c = m d_g when dry), so + !! |G| = ||G||_F/sqrt(2), and the hanging dry rod sees the effective gravity bound + !! g + |a_p| >= |g - a_p|. |a_p| is the larger of the step-start and end-of-step host pin + !! accelerations (zero for a fixed pin). The inertia is the smaller principal rotational + !! inertia about the pin across the rod axis (mp: structural and added mass). + !! + !! mp_start, added_start and buoy_start (a host-pinned rod) are the inertia, added mass and + !! buoyancy of the same rod at its step-start pin: the stiffness is then the larger and the + !! inertia the smaller of the two poses. The sub-steps move the pin along a straight line, so + !! at the rod's orientation, with the surface held over the step, every slice's clearance to + !! the surface changes monotonically and in the same sense: each slice's wet area, and with + !! it the net first moment W d_g - B d_b about the pin and the added mass, change + !! monotonically, and the two ends bound the path, a step whose pin crosses the free surface + !! included. k_extra adds a further angular stiffness about the pin (the seabed contact of + !! rod_contact_stiffness). + TYPE(RodState), INTENT(IN) :: rod + TYPE(DeckOptions), INTENT(IN) :: opts + REAL(wp), INTENT(IN) :: mp(3, 3), added6(6, 6), buoyancy(4) + REAL(wp), INTENT(IN), OPTIONAL :: mp_start(3, 3), added_start(6, 6), buoy_start(4), k_extra + REAL(wp) :: omega2 + REAL(wp) :: arm(3), a_pin, k_swing, i_min + + omega2 = CD_ZERO + arm = rod%r - rod%pin + a_pin = MAX(NORM2(rod%pin_a), NORM2(rod%pin0_a)) + k_swing = swing_stiffness(added6, buoyancy) + i_min = cross_inertia(mp) + IF (PRESENT(mp_start) .AND. PRESENT(added_start) .AND. PRESENT(buoy_start)) THEN + k_swing = MAX(k_swing, swing_stiffness(added_start, buoy_start)) + i_min = MIN(i_min, cross_inertia(mp_start)) + END IF + IF (PRESENT(k_extra)) k_swing = k_swing + k_extra + IF (i_min > CD_ZERO) omega2 = k_swing/i_min + + CONTAINS + + REAL(wp) FUNCTION swing_stiffness(added, buoy) RESULT(k) + !! |P| plus the pin-acceleration term for one pose's added mass and buoyancy. + REAL(wp), INTENT(IN) :: added(6, 6), buoy(4) + REAL(wp) :: p(3), g3(3, 3) + ! weight at the centre, buoyancy at its first moment about the centre + p = (buoy(1) - rod%mass*opts%g)*arm + buoy(2:4) + k = NORM2(p) + IF (a_pin > CD_ZERO) THEN + g3 = rod%mass*skew3(arm) + MATMUL(skew3(arm), added(1:3, 1:3)) + added(4:6, 1:3) + k = k + a_pin*NORM2(g3)/SQRT(2.0_wp) + END IF + END FUNCTION swing_stiffness + + REAL(wp) FUNCTION cross_inertia(m3) RESULT(i) + !! The smaller principal value of m3 in the plane across the rod axis. + REAL(wp), INTENT(IN) :: m3(3, 3) + REAL(wp) :: e1(3), e2(3), m11, m22, m12 + e1 = rod%rot_mat(:, 2) + e2 = rod%rot_mat(:, 3) + m11 = DOT_PRODUCT(e1, MATMUL(m3, e1)) + m22 = DOT_PRODUCT(e2, MATMUL(m3, e2)) + m12 = DOT_PRODUCT(e1, MATMUL(m3, e2)) + i = 0.5_wp*(m11 + m22) - SQRT(0.25_wp*(m11 - m22)**2 + m12**2) + END FUNCTION cross_inertia + END FUNCTION pinned_swing_omega2 + SUBROUTINE step_prescribed_rod_system(system, points, opts, motion, rod_state, time_index, time, dt, & converged, stalled, n_iter, ErrStat, ErrMsg, work, hydro_work, bathymetry) !! Impose the motionFile rows on prescribed rods, then march the free rods and lines. The @@ -20495,8 +20936,9 @@ SUBROUTINE rod_seabed_contact(rod, opts, force, moment, load_dv, ErrStat, ErrMsg !! force and a moment about the rod centre, so a rod lying on the bed is supported along !! its whole length with the distributed rotational stiffness. load_dv returns the 6x6 !! derivative of (force, moment) w.r.t. the rod (velocity, angular velocity) from the - !! active normal dampers, which the rigid-body step applies implicitly; the springs and the - !! regularized friction act at the evaluated position and velocity. + !! active normal dampers and the regularised friction (as a damper of its secant coefficient + !! mu N/sqrt(v^2 + vreg^2)), which the + !! rigid-body step applies implicitly; the springs act at the evaluated position. TYPE(RodState), INTENT(IN) :: rod TYPE(DeckOptions), INTENT(IN) :: opts REAL(wp), INTENT(OUT) :: force(3), moment(3), load_dv(6, 6) @@ -20541,6 +20983,14 @@ SUBROUTINE rod_seabed_contact(rod, opts, force, moment, load_dv, ErrStat, ErrMsg denom = SQRT(v_eval(1)**2 + v_eval(2)**2 + vreg**2) f_i(1) = -opts%friction_mu*normal*v_eval(1)/denom f_i(2) = -opts%friction_mu*normal*v_eval(2)/denom + ! the regularised friction is a damper c = mu N/sqrt(v^2 + vreg^2), mu N/vreg at rest, far + ! stiffer than the step allows explicitly: it enters the implicit velocity derivative as + ! that secant coefficient, f = -c v at the end-of-step velocity (exact at the evaluated + ! velocity; the tangent would vanish where the trapezoidal acceleration rings) + blk = CD_ZERO + blk(1, 1) = -opts%friction_mu*normal/denom + blk(2, 2) = blk(1, 1) + CALL add_arm_block6(load_dv, blk, arm) END IF f_i(3) = normal force = force + f_i @@ -20548,6 +20998,304 @@ SUBROUTINE rod_seabed_contact(rod, opts, force, moment, load_dv, ErrStat, ErrMsg END DO END SUBROUTINE rod_seabed_contact + SUBROUTINE rod_contact_stiffness(rod, opts, ref, dt, k6, ErrStat, ErrMsg, bathymetry) + !! Add to k6 the diagonal stiffness, about the point ref in global axes, of the seabed contact + !! springs of rod_seabed_contact (kBot d dl at each of its stations) that can act within the + !! coming step of length dt (contact_within_reach, with the station's rigid-body velocity + !! v + w x s, the bound |a| + |alpha x s| + |w|^2 |s| + g of its acceleration and the rod + !! radius), so a rod about to land, sliding towards a shallower bed or turning a station + !! onto it is covered as well as one already on the bed. A vertical spring k at arm a from + !! ref adds k to the heave entry and k a_y^2, k a_x^2 to the roll and pitch entries (the bound + !! k |a x e_z|^2 of its rotational stiffness about any axis is their sum). The normal damper + !! and the friction are left out: the step applies the damper implicitly, and the + !! regularised friction is bounded by mu times the normal load. + TYPE(RodState), INTENT(IN) :: rod + TYPE(DeckOptions), INTENT(IN) :: opts + REAL(wp), INTENT(IN) :: ref(3), dt + REAL(wp), INTENT(INOUT) :: k6(6) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + TYPE(CD_BathymetryType), INTENT(IN), OPTIONAL :: bathymetry + INTEGER :: i, ncontact + REAL(wp) :: s, dl, arm(3), r_eval(3), k, a_ref(3), a_rigid + LOGICAL :: within + + ErrStat = CD_DECKDRV_OK + ErrMsg = '' + IF (.NOT. (opts%kbot > CD_ZERO .AND. rod%diam > CD_ZERO)) RETURN + ncontact = MAX(20, rod%nsegs) + DO i = 0, ncontact + s = -rod%half_length + rod%length*REAL(i, wp)/REAL(ncontact, wp) + dl = rod%length/REAL(ncontact, wp) + IF (i == 0 .OR. i == ncontact) dl = 0.5_wp*dl + arm = MATMUL(rod%rot_mat, [s, CD_ZERO, CD_ZERO]) + r_eval = rod%r + arm + a_rigid = NORM2(rod%a) + NORM2(cross3(rod%alpha, arm)) + SUM(rod%omega**2)*ABS(s) + CALL contact_within_reach(r_eval, rod%v + cross3(rod%omega, arm), a_rigid, 0.5_wp*rod%diam, dt, opts, & + within, ErrStat, ErrMsg, bathymetry) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + IF (.NOT. within) CYCLE + k = opts%kbot*rod%diam*dl + a_ref = r_eval - ref + k6(3) = k6(3) + k + k6(4) = k6(4) + k*a_ref(2)**2 + k6(5) = k6(5) + k*a_ref(1)**2 + END DO + END SUBROUTINE rod_contact_stiffness + + SUBROUTINE contact_within_reach(x, v, a_rigid, radius, dt, opts, within, ErrStat, ErrMsg, bathymetry) + !! Whether a contact point at x (velocity v, acceleration bounded by a_rigid, the free fall + !! g added) of a body of the given radius about it can meet the seabed within a step dt: its + !! reach dt |v| + dt^2 (a_rigid + g)/2 bounds its travel in every direction, and it counts when + !! its height above the highest floor within that horizontal distance (the depth on a flat + !! seabed, CD_Bathymetry_Max_Floor over the box around the disk on a bathymetry grid) is at + !! most the reach plus the radius. + REAL(wp), INTENT(IN) :: x(3), v(3), a_rigid, radius, dt + TYPE(DeckOptions), INTENT(IN) :: opts + LOGICAL, INTENT(OUT) :: within + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + TYPE(CD_BathymetryType), INTENT(IN), OPTIONAL :: bathymetry + INTEGER :: es + REAL(wp) :: reach, z_max + LOGICAL :: bathy_ready + CHARACTER(160) :: em + + within = .FALSE. + ErrStat = CD_DECKDRV_OK + ErrMsg = '' + reach = dt*NORM2(v) + 0.5_wp*dt*dt*(a_rigid + opts%g) + ! see deck_seabed_floor_at: no short-circuit on the absent OPTIONAL bathymetry + bathy_ready = .FALSE. + IF (PRESENT(bathymetry)) bathy_ready = CD_Bathymetry_Is_Initialized(bathymetry) + IF (bathy_ready) THEN + CALL CD_Bathymetry_Max_Floor(bathymetry, x(1) - reach, x(1) + reach, x(2) - reach, x(2) + reach, z_max, es, em) + IF (es /= CD_BATHY_OK) THEN + CALL fail_solve(ErrStat, ErrMsg, 'deck bathymetry floor bound failed: '//TRIM(em)) + RETURN + END IF + ELSE IF (opts%has_wtrdpth) THEN + z_max = -opts%wtrdpth + ELSE + RETURN + END IF + within = x(3) - z_max <= reach + radius + END SUBROUTINE contact_within_reach + + SUBROUTINE rod_hydrostatic_stiffness(rod, opts, time, ref, dt, k6, near, ErrStat, ErrMsg) + !! Add to k6 a bound of the waterplane (hydrostatic) stiffness of a rod near the free surface + !! within the coming step, about ref in global axes, as rod_contact_stiffness adds its contact: + !! rhoW g D dl at each station (those of rod_contact_stiffness) whose cross-section can cross + !! the surface within the step (its height above the surface within r sin(phi) plus its reach, + !! phi the axis angle from the vertical), and rhoW g pi D^2/4 at each pair of neighbouring + !! stations between which the axis can cross it; together they bound the elliptical + !! waterplane pi r^2/cos(phi) of any crossing. The surface is the host-held or deck wave + !! elevation at the station, still water otherwise. near returns whether any term was added + !! (the rod's added mass then changes within the step and the estimate takes its dry inertia). + TYPE(RodState), INTENT(IN) :: rod + TYPE(DeckOptions), INTENT(IN) :: opts + REAL(wp), INTENT(IN) :: time, ref(3), dt + REAL(wp), INTENT(INOUT) :: k6(6) + LOGICAL, INTENT(OUT) :: near + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER :: i, ncontact, es, ih + REAL(wp) :: reach(0:MAX(20, rod%nsegs)), h(0:MAX(20, rod%nsegs)), xs(3, 0:MAX(20, rod%nsegs)) + REAL(wp) :: s, dl, arm(3), x(3), eta, u(3), du(3), tq, lseg, sphi, k, kpair, rmax + CHARACTER(160) :: em + + near = .FALSE. + ErrStat = CD_DECKDRV_OK + ErrMsg = '' + IF (.NOT. (rod%diam > CD_ZERO .AND. opts%rhoW > CD_ZERO)) RETURN + ncontact = MAX(20, rod%nsegs) + lseg = rod%length/REAL(MAX(1, rod%nsegs), wp) + sphi = SQRT(MAX(CD_ZERO, CD_ONE - rod%rot_mat(3, 1)**2)) + DO i = 0, ncontact + s = -rod%half_length + rod%length*REAL(i, wp)/REAL(ncontact, wp) + arm = MATMUL(rod%rot_mat, [s, CD_ZERO, CD_ZERO]) + x = rod%r + arm + eta = CD_ZERO + IF (rod%has_held) THEN + tq = (s + rod%half_length)/lseg + ih = MIN(MAX(1, rod%nsegs) - 1, MAX(0, INT(tq))) + tq = MIN(CD_ONE, MAX(CD_ZERO, tq - REAL(ih, wp))) + eta = (CD_ONE - tq)*rod%held_eta(ih) + tq*rod%held_eta(ih + 1) + ELSE IF (opts%has_wave) THEN + CALL deck_wave_kinematics(opts, x(1), x(2), x(3), time, eta, u, du, es, em) + IF (es /= CD_HYDRO_OK) THEN + CALL fail_solve(ErrStat, ErrMsg, 'rod waterplane estimate: wave kinematics failed: '//TRIM(em)) + RETURN + END IF + END IF + xs(:, i) = x + h(i) = x(3) - eta + reach(i) = dt*NORM2(rod%v + cross3(rod%omega, arm)) + 0.5_wp*dt*dt* & + (NORM2(rod%a) + NORM2(cross3(rod%alpha, arm)) + SUM(rod%omega**2)*ABS(s) + opts%g) + END DO + k = opts%rhoW*opts%g*rod%diam + kpair = opts%rhoW*opts%g*QUARTER_PI*rod%diam**2 + DO i = 0, ncontact + dl = rod%length/REAL(ncontact, wp) + IF (i == 0 .OR. i == ncontact) dl = 0.5_wp*dl + IF (ABS(h(i)) <= 0.5_wp*rod%diam*sphi + reach(i)) CALL add_spring(k*dl, xs(:, i)) + IF (i < ncontact) THEN + rmax = MAX(reach(i), reach(i + 1)) + IF (MIN(h(i), h(i + 1)) - rmax <= CD_ZERO .AND. MAX(h(i), h(i + 1)) + rmax >= CD_ZERO) & + CALL add_spring(kpair, 0.5_wp*(xs(:, i) + xs(:, i + 1))) + END IF + END DO + + CONTAINS + + SUBROUTINE add_spring(kv, xp) + REAL(wp), INTENT(IN) :: kv, xp(3) + REAL(wp) :: a(3) + a = xp - ref + k6(3) = k6(3) + kv + k6(4) = k6(4) + kv*a(2)**2 + k6(5) = k6(5) + kv*a(1)**2 + near = .TRUE. + END SUBROUTINE add_spring + END SUBROUTINE rod_hydrostatic_stiffness + + SUBROUTINE rod_estimate_terms(rod, opts, time, dt, mass6, k6, w2, shift, ErrStat, ErrMsg, bathymetry, & + rod_start, parent) + !! A free or pinned rod's own terms of the sub-step estimate, shared by step_rod_system, the + !! staggered multibody march and the deck without lines. A free rod: its seabed contact + !! (rod_contact_stiffness) and waterplane stiffness (rod_hydrostatic_stiffness) about its + !! centre in k6, over its structural plus added mass in mass6 (structural only near the + !! surface, whose crossing changes the added mass within the step). A pinned rod: its swing + !! about the pin (pinned_swing_omega2, with its contact and waterplane stiffness about the + !! pin) in w2, its rotational inertia about the pin in mass6(4:6) with mass6(1:3) = 0, and + !! shift = r - pin, which carries the arms of its line springs from its centre to its pin. + !! rod_start (a host-pinned rod) is the rod at its step-start pin, bounded together with it. + !! parent (a rod pinned to a body) gives the pin acceleration and, through the reduced mass + !! m m_b/(m + m_b) with the translational added mass left out, a lower bound of the inertia + !! about the pin when the body moves with the swing. + TYPE(RodState), INTENT(IN) :: rod + TYPE(DeckOptions), INTENT(IN) :: opts + REAL(wp), INTENT(IN) :: time, dt + REAL(wp), INTENT(OUT) :: mass6(6), k6(6), w2, shift(3) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + TYPE(CD_BathymetryType), INTENT(IN), OPTIONAL :: bathymetry + TYPE(RodState), INTENT(IN), OPTIONAL :: rod_start + TYPE(RigidBodyState), INTENT(IN), OPTIONAL :: parent + REAL(wp) :: f(3), m(3), added6(6, 6), drag6(6, 6), buoy(4), mp(3, 3), kh(6), kc, a6(6, 6) + REAL(wp) :: added0(6, 6), buoy0(4), a60(6, 6), p(3) + LOGICAL :: near, near0 + INTEGER :: k + TYPE(RodState) :: rc + + mass6 = CD_ZERO + k6 = CD_ZERO + w2 = CD_ZERO + shift = CD_ZERO + CALL rod_environment_force(rod, opts, time, f, m, added6, drag6, ErrStat, ErrMsg, buoyancy=buoy) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + IF (rod%is_pinned) THEN + rc = rod + a6 = added6 + IF (PRESENT(parent)) THEN + p = rod%pin - parent%r + rc%pin_a = parent%a + cross3(parent%alpha, p) + cross3(parent%omega, cross3(parent%omega, p)) + rc%pin0_a = rc%pin_a + IF (parent%mass > CD_ZERO) rc%mass = rod%mass*parent%mass/(rod%mass + parent%mass) + a6(1:3, :) = CD_ZERO + a6(:, 1:3) = CD_ZERO + END IF + kh = CD_ZERO + CALL rod_contact_stiffness(rod, opts, rod%pin, dt, kh, ErrStat, ErrMsg, bathymetry) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + CALL rod_hydrostatic_stiffness(rod, opts, time, rod%pin, dt, kh, near, ErrStat, ErrMsg) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + kc = kh(4) + kh(5) + IF (PRESENT(rod_start)) THEN + CALL rod_environment_force(rod_start, opts, time, f, m, added0, drag6, ErrStat, ErrMsg, buoyancy=buoy0) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + kh = CD_ZERO + CALL rod_contact_stiffness(rod_start, opts, rod_start%pin, dt, kh, ErrStat, ErrMsg, bathymetry) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + CALL rod_hydrostatic_stiffness(rod_start, opts, time, rod_start%pin, dt, kh, near0, ErrStat, ErrMsg) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + kc = MAX(kc, kh(4) + kh(5)) + near = near .OR. near0 + a60 = added0 + IF (near) THEN + a6 = CD_ZERO + a60 = CD_ZERO + END IF + mp = pinned_rotational_inertia(rc, a6) + w2 = pinned_swing_omega2(rc, opts, mp, added6, buoy, pinned_rotational_inertia(rod_start, a60), added0, & + buoy0, k_extra=kc) + ELSE + IF (near) a6 = CD_ZERO + mp = pinned_rotational_inertia(rc, a6) + w2 = pinned_swing_omega2(rc, opts, mp, added6, buoy, k_extra=kc) + END IF + DO k = 1, 3 + mass6(3 + k) = mp(k, k) + END DO + shift = rod%r - rod%pin + ELSE + CALL rod_contact_stiffness(rod, opts, rod%r, dt, k6, ErrStat, ErrMsg, bathymetry) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + CALL rod_hydrostatic_stiffness(rod, opts, time, rod%r, dt, k6, near, ErrStat, ErrMsg) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + mass6(1:3) = rod%mass + mass6(4:6) = global_inertia_diag(rod%rot_mat, rod%inertia) + IF (.NOT. near) THEN + DO k = 1, 6 + mass6(k) = mass6(k) + MAX(CD_ZERO, added6(k, k)) + END DO + END IF + END IF + END SUBROUTINE rod_estimate_terms + + SUBROUTINE rigid6_contact_stiffness(body, opts, time, dt, k6, ErrStat, ErrMsg, bathymetry) + !! Add to k6 the diagonal seabed contact stiffness of a Rigid6 body about its reference point + !! that can act within the coming step (contact_within_reach): the reference-point penalty of + !! rigid6_seabed_contact (kBot over 1 m^2, heave only) and the stations of the rods fixed to + !! the body, posed as rigid6_rod_loads poses them, with the body's rigid-body motion; and the + !! waterplane stiffness of those rods near the surface (rod_hydrostatic_stiffness). + TYPE(RigidBodyState), INTENT(IN) :: body + TYPE(DeckOptions), INTENT(IN) :: opts + REAL(wp), INTENT(IN) :: time, dt + REAL(wp), INTENT(INOUT) :: k6(6) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + TYPE(CD_BathymetryType), INTENT(IN), OPTIONAL :: bathymetry + INTEGER :: k + REAL(wp) :: r(3) + LOGICAL :: within, near + TYPE(RodState) :: rs + + ErrStat = CD_DECKDRV_OK + ErrMsg = '' + IF (opts%kbot > CD_ZERO) THEN + CALL contact_within_reach(body%r, body%v, NORM2(body%a), CD_ZERO, dt, opts, within, ErrStat, ErrMsg, bathymetry) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + IF (within) k6(3) = k6(3) + opts%kbot + END IF + IF (.NOT. ALLOCATED(body%att_rods)) RETURN + DO k = 1, SIZE(body%att_rods) + rs = body%att_rods(k) + r = MATMUL(body%rot_mat, body%att_c(:, k)) + rs%r = body%r + r + rs%rot_mat = MATMUL(body%rot_mat, body%att_rot(:, :, k)) + rs%v = body%v + cross3(body%omega, r) + rs%omega = body%omega + rs%a = body%a + cross3(body%alpha, r) + cross3(body%omega, cross3(body%omega, r)) + rs%alpha = body%alpha + rs%has_held = .FALSE. + CALL rod_contact_stiffness(rs, opts, body%r, dt, k6, ErrStat, ErrMsg, bathymetry) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + CALL rod_hydrostatic_stiffness(rs, opts, time, body%r, dt, k6, near, ErrStat, ErrMsg) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + END DO + END SUBROUTINE rigid6_contact_stiffness + PURE SUBROUTINE add_arm_block6(mat, blk, arm) !! Add T^T blk T to a 6x6 rigid-body matrix about the reference point, T = [I, -[arm]x] !! mapping (translation, rotation) of the reference point to the point at arm: the 3x3 @@ -20564,7 +21312,7 @@ PURE SUBROUTINE add_arm_block6(mat, blk, arm) mat(4:6, 4:6) = mat(4:6, 4:6) - MATMUL(s, b_s) END SUBROUTINE add_arm_block6 - SUBROUTINE rod_environment_force(rod, opts, time, force, moment, added_mass, drag_dv, ErrStat, ErrMsg) + SUBROUTINE rod_environment_force(rod, opts, time, force, moment, added_mass, drag_dv, ErrStat, ErrMsg, buoyancy) !! Distributed hydrostatic and Morison loads of a rigid rod about its centre, the rod's 6x6 !! hydrodynamic added-mass matrix about the same point (global frame) and the 6x6 derivative !! drag_dv of the drag force/moment w.r.t. the rod (velocity, angular velocity), which the @@ -20599,12 +21347,15 @@ SUBROUTINE rod_environment_force(rod, opts, time, force, moment, added_mass, dra !! and no host dynamic pressure the side keeps 1 + CaAx. Host-held fluid is sampled at the NumSegs + 1 !! segment stations and interpolated linearly along the rod; when the host also supplies the !! dynamic pressure the end caps carry it as with deck waves (side axial term CaAx only). + !! buoyancy (optional) returns the slice buoyancy alone: its upward total and its first + !! moment about the rod centre, the sum of rhoW g V_i (s_i q + c_i p) over the stations. TYPE(RodState), INTENT(IN) :: rod TYPE(DeckOptions), INTENT(IN) :: opts REAL(wp), INTENT(IN) :: time REAL(wp), INTENT(OUT) :: force(3), moment(3), added_mass(6, 6), drag_dv(6, 6) INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), INTENT(OUT), OPTIONAL :: buoyancy(4) REAL(wp), PARAMETER :: gp2(2) = [-0.57735026918962576451_wp, 0.57735026918962576451_wp] REAL(wp), PARAMETER :: gx10(10) = [-0.97390652851717174343_wp, -0.86506336668898453635_wp, & @@ -20624,6 +21375,7 @@ SUBROUTINE rod_environment_force(rod, opts, time, force, moment, added_mass, dra REAL(wp) :: r0, area, lseg, sphi, rs, eta_mean, ax_fk, s_a, h_a, h_b, dh, tlo, thi, tmp, th1, th2, th REAL(wp) :: f_end(2), eta_end(2), h_st(0:MAX(1, rod%nsegs)) REAL(wp) :: vol_end, kq, vq, u(3), du(3), eta, pd, x(3), v_end(3), arm(3), n_e(3), eta_star, f_c(3) + REAL(wp) :: buoy(4) ErrStat = CD_DECKDRV_OK ErrMsg = '' @@ -20631,6 +21383,8 @@ SUBROUTINE rod_environment_force(rod, opts, time, force, moment, added_mass, dra moment = CD_ZERO added_mass = CD_ZERO drag_dv = CD_ZERO + buoy = CD_ZERO + IF (PRESENT(buoyancy)) buoyancy = CD_ZERO nseg = MAX(1, rod%nsegs) axis = rod%rot_mat(:, 1) r0 = 0.5_wp*rod%diam @@ -20719,6 +21473,7 @@ SUBROUTINE rod_environment_force(rod, opts, time, force, moment, added_mass, dra END IF IF (ErrStat /= CD_DECKDRV_OK) RETURN END DO + IF (PRESENT(buoyancy)) buoyancy = buoy ! rodHydro moordyn: MoorDyn's waterplane moment (pi d^4/16) rho g sin(phi) cos(phi) with its ! end-cap moment, whose net exceeds the exact displaced-volume moment by (pi d^4/32) rho g @@ -20815,6 +21570,8 @@ SUBROUTINE station(s, w, f, c) fb = [CD_ZERO, CD_ZERO, opts%rhoW*vol*opts%g] force = force + fb moment = moment + cross3(arm_s + c*pvec, fb) + buoy(1) = buoy(1) + fb(3) + buoy(2:4) = buoy(2:4) + fb(3)*(arm_s + c*pvec) rel = us - vs acc_axial = DOT_PRODUCT(dus, axis)*axis rel_axial = DOT_PRODUCT(rel, axis)*axis @@ -21208,12 +21965,14 @@ SUBROUTINE solve_body_equilibrium_core(types, bodies, rod_types, rods, points, l okind(nobj) = OBJ_ROD idx(nobj) = i END DO - ! pinned rods (to a fixed pin or to a body) with a line, or on a moving body: two - ! rotations about the pin; the pin force acts on the parent body + ! pinned rods (to a fixed pin, to a body, or to a host node held at its initial pose: a + ! CoupledPinned rod) with a line, or on a moving body: two rotations about the pin; the + ! pin force acts on the parent body IF (.NOT. opts%has_motion_file) THEN DO i = 1, SIZE(rods) ibp = pinned_body_of_rod_type(rods(i)%rod_type) - IF (TRIM(rods(i)%rod_type) /= 'pinned' .AND. ibp < 1) CYCLE + IF (TRIM(rods(i)%rod_type) /= 'pinned' .AND. TRIM(rods(i)%rod_type) /= 'coupledpinned' .AND. & + ibp < 1) CYCLE k = rod_point_index(points, rods(i)%id, 1) j = rod_point_index(points, rods(i)%id, 2) ok = point_has_line(k) @@ -23136,10 +23895,11 @@ END SUBROUTINE CD_Rigid6_End SUBROUTINE CD_Init_Deck_Aggregate_Rod(rod_types, rods, points, opts, rt, ErrStat, ErrMsg, host_dcm) !! Populate the opaque rod runtime for the coupled aggregate: build the rod states and retain !! the deck options + points the per-step marcher needs (the aggregate keeps neither). The rod - !! twin of CD_Init_Deck_Aggregate_Rigid6. Coupled/Vessel rods become host nodes (one per rod, - !! in deck ROD order) at their End A; host_dcm is the host orientation at Init (the ZYX - !! global-to-platform DCM of PtfmInit, identity when absent), so the rod frame in platform - !! axes is host_dcm R0 and follows the host orientation afterwards. + !! twin of CD_Init_Deck_Aggregate_Rigid6. Coupled/Vessel and CoupledPinned/VesselPinned rods + !! become host nodes (one per rod, in deck ROD order) at their End A; host_dcm is the host + !! orientation at Init (the ZYX global-to-platform DCM of PtfmInit, identity when absent), so + !! the frame of a Coupled rod in platform axes is host_dcm R0 and follows the host orientation + !! afterwards. A CoupledPinned rod takes only the position of its node: it turns about it. TYPE(DeckRodType), INTENT(IN) :: rod_types(:) TYPE(DeckRod), INTENT(IN) :: rods(:) TYPE(DeckPoint), INTENT(IN) :: points(:) @@ -23150,8 +23910,21 @@ SUBROUTINE CD_Init_Deck_Aggregate_Rod(rod_types, rods, points, opts, rt, ErrStat REAL(wp), INTENT(IN), OPTIONAL :: host_dcm(3, 3) INTEGER :: ir, k, nh - CALL init_rod_states(rod_types, rods, points, rt%rods, ErrStat, ErrMsg) + ! An end of a Pinned or CoupledPinned rod that no line attaches to needs no RodA/B point + ! (a CoupledPinned rod often carries its line at End B only, and a pendulum none): its + ! pin holds the rod. Every other rod keeps the rule that both ends have a point. + CALL init_rod_states(rod_types, rods, points, rt%rods, ErrStat, ErrMsg, no_points=.TRUE.) IF (ErrStat /= CD_DECKDRV_OK) RETURN + DO ir = 1, SIZE(rt%rods) + IF (rt%rods(ir)%is_pinned) CYCLE + IF (rt%rods(ir)%point_a_index == 0 .OR. rt%rods(ir)%point_b_index == 0) THEN + CALL fail(ErrStat, ErrMsg, 'Rod state initialization requires RodA and RodB points: ROD '// & + TRIM(int_to_str(rt%rods(ir)%rod_id))//' ('//TRIM(rods(ir)%rod_type)//') has no line or Rod'// & + TRIM(int_to_str(rt%rods(ir)%rod_id))//MERGE('A', 'B', rt%rods(ir)%point_a_index == 0)// & + ' POINT at that end; on the coupled route only a Pinned or CoupledPinned rod may leave an end free') + RETURN + END IF + END DO rt%opts = opts rt%points = points rt%host_o0 = CD_ZERO @@ -23159,43 +23932,54 @@ SUBROUTINE CD_Init_Deck_Aggregate_Rod(rod_types, rods, points, opts, rt, ErrStat rt%host_o0(2, 2) = CD_ONE rt%host_o0(3, 3) = CD_ONE IF (PRESENT(host_dcm)) rt%host_o0 = host_dcm - nh = COUNT(rt%rods%is_prescribed) + nh = COUNT(rt%rods%is_prescribed .OR. rt%rods%is_host_pinned) ALLOCATE (rt%host_rod(nh), rt%host_rrel(3, 3, nh)) k = 0 DO ir = 1, SIZE(rt%rods) - IF (.NOT. rt%rods(ir)%is_prescribed) CYCLE + IF (.NOT. (rt%rods(ir)%is_prescribed .OR. rt%rods(ir)%is_host_pinned)) CYCLE k = k + 1 rt%host_rod(k) = ir rt%host_rrel(:, :, k) = MATMUL(rt%host_o0, rt%rods(ir)%rot_mat) - ! a host-driven rod starts at rest in the host's Init pose; its a/alpha are the host's - rt%rods(ir)%accel_valid = .TRUE. + ! a host-driven rod starts at rest in the host's Init pose; its a/alpha are the host's (a + ! host-pinned rod solves its own at the first step, like a free rod) + IF (rt%rods(ir)%is_prescribed) rt%rods(ir)%accel_valid = .TRUE. END DO rt%snap_rods = rt%rods rt%stage_rods = rt%rods END SUBROUTINE CD_Init_Deck_Aggregate_Rod PURE INTEGER FUNCTION CD_Rod_NHost(rt) RESULT(n) - !! Number of host-driven (Coupled/Vessel) rods, i.e. the rod host nodes (0 if unpopulated). + !! Number of host-driven (Coupled/Vessel and CoupledPinned/VesselPinned) rods, i.e. the rod + !! host nodes (0 if unpopulated). TYPE(CD_RodRuntimeType), INTENT(IN) :: rt n = 0 IF (ALLOCATED(rt%host_rod)) n = SIZE(rt%host_rod) END FUNCTION CD_Rod_NHost SUBROUTINE CD_Rod_SetHostKinematics(rt, position, velocity, acceleration, ErrStat, ErrMsg, orientation, & - angular_velocity, angular_acceleration) + angular_velocity, angular_acceleration, step_start) !! Impose the host node kinematics (End A position/velocity/acceleration, the host !! orientation and angular rates, all global; arrays shaped (3[,3], NHost)) on every !! Coupled/Vessel rod: R = O^T (O0 R0), centre = End A + (L/2) R e1 with the rigid !! velocity/acceleration transfer. Without an orientation the Init orientation is held; - !! without angular rates they are zero. Atomic: validates everything before any change. + !! without angular rates they are zero. A CoupledPinned rod takes the node translation as + !! its pin kinematics and ignores the orientation and angular rates: it keeps its own + !! rotation and follows the pin (mb_snap_pinned, with its committed angular acceleration). + !! Atomic: validates everything before any change. + !! + !! step_start: the kinematics are those of the committed time (a transfer that does not + !! advance, CD_AGG_UpdateStates_Moving), not the t + dt input of a coming step; the next step + !! of a CoupledPinned rod then starts from this pin (RodState%pin0). Default .FALSE. TYPE(CD_RodRuntimeType), INTENT(INOUT) :: rt REAL(wp), INTENT(IN) :: position(:, :), velocity(:, :), acceleration(:, :) INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg REAL(wp), INTENT(IN), OPTIONAL :: orientation(:, :, :) REAL(wp), INTENT(IN), OPTIONAL :: angular_velocity(:, :), angular_acceleration(:, :) + LOGICAL, INTENT(IN), OPTIONAL :: step_start INTEGER :: k, ir, nh REAL(wp) :: o(3, 3), rot(3, 3), arm(3), w(3), al(3) + TYPE(RigidBodyState) :: no_parent(0) ErrStat = CD_DECKDRV_OK ErrMsg = '' @@ -23221,6 +24005,16 @@ SUBROUTINE CD_Rod_SetHostKinematics(rt, position, velocity, acceleration, ErrSta END IF DO k = 1, nh ir = rt%host_rod(k) + IF (rt%rods(ir)%is_host_pinned) THEN + rt%rods(ir)%pin = position(:, k) + rt%rods(ir)%pin_v = velocity(:, k) + rt%rods(ir)%pin_a = acceleration(:, k) + CALL mb_snap_pinned(rt%rods(ir), no_parent) + IF (PRESENT(step_start)) THEN + IF (step_start) CALL set_rod_pin_start(rt%rods(ir)) + END IF + CYCLE + END IF o = rt%host_o0 IF (PRESENT(orientation)) o = orientation(:, :, k) w = CD_ZERO @@ -23245,6 +24039,8 @@ SUBROUTINE CD_Rod_GetHostKinematics(rt, k, position, velocity, acceleration, ori angular_acceleration) !! The committed kinematics of host node k (End A of the k-th Coupled/Vessel rod) and the !! host orientation O = (O0 R0) R^T it implies -- the inverse of CD_Rod_SetHostKinematics. + !! A CoupledPinned rod implies no host orientation or angular rates: its node reports the + !! Init orientation and zero rates, which CD_Rod_SetHostKinematics ignores for it. TYPE(CD_RodRuntimeType), INTENT(IN) :: rt INTEGER, INTENT(IN) :: k REAL(wp), INTENT(OUT) :: position(3), velocity(3), acceleration(3), orientation(3, 3) @@ -23270,15 +24066,19 @@ SUBROUTINE CD_Rod_GetHostKinematics(rt, k, position, velocity, acceleration, ori velocity = rt%rods(ir)%v - cross3(rt%rods(ir)%omega, arm) acceleration = rt%rods(ir)%a - cross3(rt%rods(ir)%alpha, arm) - & cross3(rt%rods(ir)%omega, cross3(rt%rods(ir)%omega, arm)) + IF (rt%rods(ir)%is_host_pinned) THEN + orientation = rt%host_o0 + RETURN + END IF orientation = MATMUL(rt%host_rrel(:, :, k), TRANSPOSE(rt%rods(ir)%rot_mat)) angular_velocity = rt%rods(ir)%omega angular_acceleration = rt%rods(ir)%alpha END SUBROUTINE CD_Rod_GetHostKinematics SUBROUTINE CD_Rod_ScatterHostPoints(system, rt, q, v, a) - !! Write the RodA/B attachment-point kinematics of every Coupled/Vessel rod into the - !! full coupled-block arrays (3, n_system_coupled_dof/3) of the EI=0 system; every other - !! block is left untouched. + !! Write the RodA/B attachment-point kinematics of every host-driven rod (Coupled/Vessel + !! and CoupledPinned) into the full coupled-block arrays (3, n_system_coupled_dof/3) of the + !! EI=0 system; every other block is left untouched. TYPE(CD_SystemType), INTENT(IN) :: system TYPE(CD_RodRuntimeType), INTENT(IN) :: rt REAL(wp), INTENT(INOUT) :: q(:, :), v(:, :), a(:, :) @@ -23295,7 +24095,7 @@ SUBROUTINE CD_Rod_ScatterHostPoints(system, rt, q, v, a) pidx = rt%rods(ir)%point_b_index arm = rt%rods(ir)%half_length*rt%rods(ir)%rot_mat(:, 1) END IF - base = system_point_base(system, rt%points(pidx)%id) + base = rod_end_base(system, rt%points, pidx) IF (base < 0 .OR. base/3 + 1 > SIZE(q, 2)) CYCLE q(:, base/3 + 1) = rt%rods(ir)%r + arm v(:, base/3 + 1) = rt%rods(ir)%v + cross3(rt%rods(ir)%omega, arm) @@ -23313,16 +24113,41 @@ SUBROUTINE CD_Rod_HostWrench(system, rt, loads, k, force, moment, ErrStat, ErrMs !! rod_environment_force (held host fluid when set), seabed contact, and the rigid-body and !! added-mass inertia -M a of the rod at its host-prescribed acceleration, including the !! gyroscopic term w x (I w). - TYPE(CD_SystemType), INTENT(IN) :: system - TYPE(CD_RodRuntimeType), INTENT(IN) :: rt + !! + !! A CoupledPinned rod returns a force and no moment (MoorDyn-F's coupled pinned rod): the + !! load it exerts on its pin, its net load less its inertia -M a. This is the direct + !! feedthrough of the pin acceleration, evaluated at the rod's current state: + !! * the pin position, velocity and acceleration are the End A motion of the rod state, + !! which CD_Rod_SetHostKinematics has moved with the host node (an output probe's + !! off-step kinematics included). They are re-derived from the rod state here (equal to + !! the host's values to round-off) so that the force depends on the checkpointed rod + !! state only: a restored run evaluates it bit for bit, also between steps; + !! * the rotation and the angular velocity are the rod's committed states (a probe moves + !! the pin, not the rotation), and the fluid is the step's held host fluid, as for every + !! other object a CalcOutput evaluates; + !! * the angular acceleration is solved again for the current pin acceleration + !! (rod_body_acceleration at dt = 0); the committed one is not used, so a probe sees the + !! rod's effective inertia about the pin; + !! * the attached lines keep their committed interior state, accelerations included (as + !! every output evaluation does), and their end loads are taken at the end accelerations + !! of the re-solved rotation: the loads come with the end accelerations the system holds + !! (the probe overlay places the RodA/B ends with the probe pin and the committed + !! angular acceleration), and the solve moves their end-node inertia to the re-solved + !! ones with the lines' coupled mass block, D = -M_cc (frozen_interior; the step's + !! corrector instead lets the interior follow). The coupled loads are linear in the end + !! accelerations at a held interior, so this is exact: the force does not depend on + !! which end accelerations the line loads were evaluated with. + TYPE(CD_SystemType), INTENT(INOUT) :: system + TYPE(CD_RodRuntimeType), INTENT(INOUT) :: rt REAL(wp), INTENT(IN) :: loads(:, :) INTEGER, INTENT(IN) :: k REAL(wp), INTENT(OUT) :: force(3), moment(3) INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg - INTEGER :: ir, base, j + INTEGER :: ir, base, j, n, es REAL(wp) :: arm(3), f_end(3, 2), f_env(3), m_env(3), f_sb(3), m_sb(3), added6(6, 6), drag6(6, 6) - REAL(wp) :: dv(6, 6), acc6(6), ig(3, 3), mc(3) + REAL(wp) :: dv(6, 6), acc6(6), ig(3, 3), mc(3), acc(3), alpha(3), pin_host(9) + CHARACTER(160) :: em force = CD_ZERO moment = CD_ZERO @@ -23332,13 +24157,41 @@ SUBROUTINE CD_Rod_HostWrench(system, rt, loads, k, force, moment, ErrStat, ErrMs CALL fail(ErrStat, ErrMsg, 'CD_Rod_HostWrench: host node index out of range'); RETURN END IF ir = rt%host_rod(k) + IF (rt%rods(ir)%is_host_pinned) THEN + n = system%n_system_coupled_dof + IF (3*SIZE(loads, 2) /= n .OR. SIZE(loads, 1) /= 3) THEN + CALL fail(ErrStat, ErrMsg, 'CD_Rod_HostWrench: load array does not cover the coupled points'); RETURN + END IF + ! the step workspace serves as scratch between steps (a step refills it before use) + CALL ensure_rod_step_workspace(rt%work, n, SIZE(rt%rods), SIZE(system%points)) + rt%work%loads(1:n) = RESHAPE(loads, [n]) + CALL CD_Get_System_CoupledMotion(system, rt%work%q(1:n), rt%work%v(1:n), rt%work%a(1:n), es, em) + ! the end-node inertia moves with the line interior held (an output evaluation keeps the + ! committed interior state, accelerations included) + IF (es == CD_SYSTEM_OK) CALL CD_Calc_System_CoupledAccelDerivative(system, rt%work%dload_da, es, em, & + frozen_interior=.TRUE.) + IF (es /= CD_SYSTEM_OK) THEN + CALL fail_solve(ErrStat, ErrMsg, 'CD_Rod_HostWrench: pinned-rod line query failed: '//TRIM(em)); RETURN + END IF + ! evaluate with the pin re-derived from the rod state, then put the host's values back + ! (state-const) + pin_host = [rt%rods(ir)%pin, rt%rods(ir)%pin_v, rt%rods(ir)%pin_a] + CALL rod_end_a_motion(rt%rods(ir), rt%rods(ir)%pin, rt%rods(ir)%pin_v, rt%rods(ir)%pin_a) + CALL rod_body_acceleration(system, rt%points, rt%opts, rt%rods(ir), CD_ZERO, CD_ZERO, & + [CD_ZERO, CD_ZERO, CD_ZERO, CD_ZERO, CD_ZERO, CD_ZERO], rt%work, acc, alpha, & + ErrStat, ErrMsg, pin_load=force) + rt%rods(ir)%pin = pin_host(1:3) + rt%rods(ir)%pin_v = pin_host(4:6) + rt%rods(ir)%pin_a = pin_host(7:9) + RETURN + END IF arm = rt%rods(ir)%half_length*rt%rods(ir)%rot_mat(:, 1) f_end = CD_ZERO DO j = 1, 2 IF (j == 1) THEN - base = system_point_base(system, rt%points(rt%rods(ir)%point_a_index)%id) + base = rod_end_base(system, rt%points, rt%rods(ir)%point_a_index) ELSE - base = system_point_base(system, rt%points(rt%rods(ir)%point_b_index)%id) + base = rod_end_base(system, rt%points, rt%rods(ir)%point_b_index) END IF IF (base < 0) CYCLE IF (base/3 + 1 > SIZE(loads, 2)) THEN @@ -23760,6 +24613,15 @@ SUBROUTINE CD_Rod_Set_States(rt, states, ErrStat, ErrMsg) rt%rods(ir)%alpha = states(k + 13:k + 15) rt%rods(ir)%rot_mat = RESHAPE(states(k + 16:k + 24), [3, 3]) rt%rods(ir)%accel_valid = .TRUE. + ! A CoupledPinned rod's pin is its End A: its kinematics follow from the restored state + ! (the End A motion the line ends carry), so the mirror needs no pin entries. The + ! continuing run derives its step-start pin from the same committed state with the same + ! arithmetic (set_rod_pin_start), so the restored pin0 is bit-identical to it; pin, pin_v + ! and pin_a are replaced by the host transfer before the next step or output evaluation. + IF (rt%rods(ir)%is_host_pinned) THEN + CALL rod_end_a_motion(rt%rods(ir), rt%rods(ir)%pin, rt%rods(ir)%pin_v, rt%rods(ir)%pin_a) + CALL set_rod_pin_start(rt%rods(ir)) + END IF END DO END SUBROUTINE CD_Rod_Set_States @@ -23873,7 +24735,7 @@ SUBROUTINE step_rigid6_system(system, points, opts, rigid, time, dt, converged, INTEGER :: ib, ip, nsub, isub, it REAL(wp), ALLOCATABLE :: hk_end(:, :) LOGICAL :: conv_s, stall_s - REAL(wp) :: omega2, mass6(6) + REAL(wp) :: omega2, mass6(6), k6c(6) converged = .TRUE. stalled = .FALSE. @@ -23892,9 +24754,11 @@ SUBROUTINE step_rigid6_system(system, points, opts, rigid, time, dt, converged, mass6(1:3) = rigid(ib)%mass IF (rigid(ib)%r(3) < CD_ZERO) mass6(1:3) = mass6(1:3) + opts%rhoW*rigid(ib)%vol*MAX(CD_ZERO, rigid(ib)%ca) mass6(4:6) = global_inertia_diag(rigid(ib)%rot_mat, rigid(ib)%inertia) - omega2 = MAX(omega2, rigid_omega2_estimate(system, att_base, att_arm, mass6, & - [CD_ZERO, CD_ZERO, rigid(ib)%c33, rigid(ib)%c44, & - rigid(ib)%c55, CD_ZERO])) + ! hydrostatic restoring plus the seabed contact that acts within the step + k6c = [CD_ZERO, CD_ZERO, rigid(ib)%c33, rigid(ib)%c44, rigid(ib)%c55, CD_ZERO] + CALL rigid6_contact_stiffness(rigid(ib), opts, time - dt, dt, k6c, ErrStat, ErrMsg, bathymetry) + IF (ErrStat /= CD_DECKDRV_OK) RETURN + omega2 = MAX(omega2, rigid_omega2_estimate(system, att_base, att_arm, mass6, k6c)) END BLOCK END DO nsub = rigid_substep_count(omega2, dt) @@ -24612,9 +25476,9 @@ SUBROUTINE rigid6_seabed_contact(body, opts, force, moment, load_dv, ErrStat, Er !! kBot/cBot (N/m^3, N.s/m^3) act over a fixed reference contact area !! RIGID6_CONTACT_AREA = 1 m^2: k = kBot*1 m^2 [N/m], c = cBot*1 m^2 [N.s/m]. This is a !! penalty that keeps the reference point out of the bed, not a footprint model. - !! load_dv returns the 6x6 derivative of the normal damping force w.r.t. the body - !! (velocity, angular velocity), which the rigid-body step applies implicitly; the spring - !! and the regularized friction act at the evaluated position and velocity. + !! load_dv returns the 6x6 derivative of the normal damping force and the friction damper (its + !! secant coefficient, see rod_seabed_contact) w.r.t. the body velocity, which the rigid-body + !! step applies implicitly; the spring acts at the evaluated position. TYPE(RigidBodyState), INTENT(IN) :: body TYPE(DeckOptions), INTENT(IN) :: opts REAL(wp), INTENT(OUT) :: force(3), moment(3), load_dv(6, 6) @@ -24645,6 +25509,9 @@ SUBROUTINE rigid6_seabed_contact(body, opts, force, moment, load_dv, ErrStat, Er denom = SQRT(body%v(1)**2 + body%v(2)**2 + vreg**2) force(1) = -opts%friction_mu*normal*body%v(1)/denom force(2) = -opts%friction_mu*normal*body%v(2)/denom + ! the friction damper as its secant coefficient, applied implicitly (rod_seabed_contact) + load_dv(1, 1) = -opts%friction_mu*normal/denom + load_dv(2, 2) = load_dv(1, 1) END IF force(3) = normal END SUBROUTINE rigid6_seabed_contact @@ -32124,8 +32991,8 @@ SUBROUTINE apply_ptfm_host_bodies(bodies, points, ptfm_init) END SUBROUTINE apply_ptfm_host_bodies SUBROUTINE apply_ptfm_host_rods(rods, points, ptfm_init) - !! Rigid-transform every Coupled/Vessel ROD (its End A/B and its RodA/B attachment - !! points) by the initial platform displacement, p' = r + M^T p (apply_ptfm_init). + !! Rigid-transform every Coupled/Vessel and CoupledPinned ROD (its End A/B and its RodA/B + !! attachment points) by the initial platform displacement, p' = r + M^T p (apply_ptfm_init). TYPE(DeckRod), INTENT(INOUT) :: rods(:) TYPE(DeckPoint), INTENT(INOUT) :: points(:) REAL(wp), INTENT(IN) :: ptfm_init(6) @@ -32133,7 +33000,8 @@ SUBROUTINE apply_ptfm_host_rods(rods, points, ptfm_init) INTEGER :: i, j, k dcm = ptfm_zyx_dcm(ptfm_init(4:6)) DO i = 1, SIZE(rods) - IF (TRIM(rods(i)%rod_type) /= 'coupled' .AND. TRIM(rods(i)%rod_type) /= 'vessel') CYCLE + IF (TRIM(rods(i)%rod_type) /= 'coupled' .AND. TRIM(rods(i)%rod_type) /= 'vessel' .AND. & + TRIM(rods(i)%rod_type) /= 'coupledpinned') CYCLE rods(i)%end_a = ptfm_init(1:3) + MATMUL(TRANSPOSE(dcm), rods(i)%end_a) rods(i)%end_b = ptfm_init(1:3) + MATMUL(TRANSPOSE(dcm), rods(i)%end_b) DO j = 1, 2 @@ -32649,7 +33517,7 @@ SUBROUTINE scatter_rod_point_motion(system, points, rod_state, q, v, a) REAL(wp) :: arm(3) DO ir = 1, SIZE(rod_state) - base = system_point_base(system, points(rod_state(ir)%point_a_index)%id) + base = rod_end_base(system, points, rod_state(ir)%point_a_index) IF (base >= 0) THEN arm = MATMUL(rod_state(ir)%rot_mat, [-rod_state(ir)%half_length, CD_ZERO, CD_ZERO]) q(base + 1:base + 3) = rod_state(ir)%r + arm @@ -32657,7 +33525,7 @@ SUBROUTINE scatter_rod_point_motion(system, points, rod_state, q, v, a) a(base + 1:base + 3) = rod_state(ir)%a + cross3(rod_state(ir)%alpha, arm) + & cross3(rod_state(ir)%omega, cross3(rod_state(ir)%omega, arm)) END IF - base = system_point_base(system, points(rod_state(ir)%point_b_index)%id) + base = rod_end_base(system, points, rod_state(ir)%point_b_index) IF (base >= 0) THEN arm = MATMUL(rod_state(ir)%rot_mat, [rod_state(ir)%half_length, CD_ZERO, CD_ZERO]) q(base + 1:base + 3) = rod_state(ir)%r + arm @@ -32792,6 +33660,16 @@ INTEGER FUNCTION system_point_base(system, point_id) RESULT(base) END DO END FUNCTION system_point_base + INTEGER FUNCTION rod_end_base(system, points, pidx) RESULT(base) + !! system_point_base of a rod end point; -1 for a rod end without a point (pidx = 0: no line + !! attaches there, a coupled-aggregate rod). + TYPE(CD_SystemType), INTENT(IN) :: system + TYPE(DeckPoint), INTENT(IN) :: points(:) + INTEGER, INTENT(IN) :: pidx + base = -1 + IF (pidx > 0) base = system_point_base(system, points(pidx)%id) + END FUNCTION rod_end_base + PURE FUNCTION cross3(a, b) RESULT(c) REAL(wp), INTENT(IN) :: a(3), b(3) REAL(wp) :: c(3) diff --git a/src/CableDyn_Model.f90 b/src/CableDyn_Model.f90 index ffa0736a..9e3971ad 100644 --- a/src/CableDyn_Model.f90 +++ b/src/CableDyn_Model.f90 @@ -96,6 +96,7 @@ MODULE CableDyn_Model PUBLIC :: CD_Calc_Model_CoupledLoads PUBLIC :: CD_Calc_Model_CoupledKinematicDerivatives PUBLIC :: CD_Calc_Model_CoupledAccelDerivative, CD_Update_Model_CoupledAccelDerivative + PUBLIC :: CD_Calc_Model_CoupledEndMass PUBLIC :: CD_Update_Model_Hydro_Fields PUBLIC :: CD_Update_Model_External_Loads PUBLIC :: CD_Update_Model_CoupledMotion @@ -3492,6 +3493,51 @@ SUBROUTINE CD_Calc_Model_CoupledAccelDerivative(model, dload_da, ErrStat, ErrMsg IF (ErrStat == CD_MODEL_OK) dload_da = model%dynamic_workspace%ad_result END SUBROUTINE CD_Calc_Model_CoupledAccelDerivative + SUBROUTINE CD_Calc_Model_CoupledEndMass(model, m_cc, ErrStat, ErrMsg) + !! The coupled-coupled block M_cc of the line mass (the consistent structural mass plus the + !! added mass at the current positions, exactly as CD_Update_Model_CoupledAccelDerivative + !! assembles it), n_coupled_dof square in the compact coupled ordering. -M_cc is the + !! derivative of CD_Calc_Model_CoupledLoads with respect to the prescribed coupled + !! accelerations at fixed free-DOF accelerations: the response of the coupled loads when + !! only the coupled motion changes and the line interior keeps its state (an output probe), + !! whereas CD_Calc_Model_CoupledAccelDerivative lets the free accelerations follow. + TYPE(CD_ModelType), INTENT(INOUT) :: model + REAL(wp), INTENT(OUT) :: m_cc(:, :) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER :: nc, bwf, e, i, j, r, c + + ErrStat = CD_MODEL_OK + ErrMsg = '' + m_cc = CD_ZERO + IF (.NOT. model%initialized) THEN + ErrStat = CD_MODEL_NOT_INITIALIZED + ErrMsg = 'CableDyn_Model: model is not initialized' + RETURN + END IF + nc = SIZE(model%fixed_dofs) + IF (SIZE(m_cc, 1) /= nc .OR. SIZE(m_cc, 2) /= nc) THEN + CALL fail(ErrStat, ErrMsg, 'm_cc output must have shape (n_coupled_dof, n_coupled_dof)') + RETURN + END IF + IF (nc == 0) RETURN + ! brings the banded full mass ad_full up to date (or confirms its cache) + CALL CD_Update_Model_CoupledAccelDerivative(model, ErrStat, ErrMsg) + IF (ErrStat /= CD_MODEL_OK) RETURN + ! the half-bandwidth ad_full was stored with (CD_Update_Model_CoupledAccelDerivative) + bwf = 2 + DO e = 1, model%n_elem + bwf = MAX(bwf, 3*ABS(model%elem_conn(1, e) - model%elem_conn(2, e)) + 2) + END DO + DO j = 1, nc + c = model%fixed_dofs(j) + DO i = 1, nc + r = model%fixed_dofs(i) + IF (ABS(r - c) <= bwf) m_cc(i, j) = model%dynamic_workspace%ad_full(bwf + 1 + r - c, c) + END DO + END DO + END SUBROUTINE CD_Calc_Model_CoupledEndMass + SUBROUTINE CD_Update_Model_SegmentLength(model, elem, l0_new, l0_dot, ErrStat, ErrMsg) !! Active line control (the MoorDyn CtrlChan mechanism): set one element's !! unstretched length and its rate. The elastic tension and the per-step mass diff --git a/src/CableDyn_OpenFAST_Aggregate.f90 b/src/CableDyn_OpenFAST_Aggregate.f90 index 3eb67ebc..991c352e 100644 --- a/src/CableDyn_OpenFAST_Aggregate.f90 +++ b/src/CableDyn_OpenFAST_Aggregate.f90 @@ -16,7 +16,9 @@ MODULE CableDyn_OpenFAST_Aggregate !! i in ncp_sys+1 .. ncp_sys+ncable -> cable (i - ncp_sys)'s single coupled fairlead, !! next nhost_rod columns -> the k-th Coupled/Vessel ROD's End A (a 6-DOF host !! node: orientation and angular rates in, force and - !! moment about End A out), + !! moment about End A out) or CoupledPinned ROD's pin + !! (translation in, force out, zero moment; the rod + !! turns about it on its own), !! last nhost_body columns -> the k-th Coupled/Vessel BODY's reference point !! (6-DOF host node, force and moment about it), !! with ncp_total = ncp_sys + ncable + nhost_rod + nhost_body. All facade arrays are shaped @@ -204,8 +206,9 @@ MODULE CableDyn_OpenFAST_Aggregate ! channels, keyed by deck line id. The references are fixed at the converged initial ! state (a checkpoint rebuild re-derives the same state), so they carry no step state. TYPE(CD_RangeSet) :: ranges - ! Coupled/Vessel rods: the trailing host nodes of the moving surface, and the full EI=0 - ! coupled-block scratch (3, n_system_coupled_dof/3) their RodA/B points are overlaid on. + ! Coupled/Vessel and CoupledPinned rods: the trailing host nodes of the moving surface, and + ! the full EI=0 coupled-block scratch (3, n_system_coupled_dof/3) their RodA/B points are + ! overlaid on. INTEGER :: nhost_rod = 0 INTEGER :: nhost_body = 0 ! Coupled/Vessel bodies: the trailing host nodes after the rods ! Body/rod marches: the host fairleads' t + dt motion as a flat coupled-DOF overlay @@ -649,7 +652,8 @@ SUBROUTINE CD_AGG_GetMovingPointMesh(self, position, velocity, acceleration, loa END IF END DO ! Host rod nodes: End A kinematics of each Coupled/Vessel rod and the wrench about End A - ! from the system's current coupled-point loads (the CD_AGG_CalcOutput evaluation). + ! from the system's current coupled-point loads (the CD_AGG_CalcOutput evaluation); the pin + ! of a CoupledPinned rod and its force, with zero moment. IF (self%nhost_rod > 0) THEN CALL CD_FMF_GetPointMesh(self%sys, self%hb_pos, self%hb_vel, self%hb_acc, self%hb_load, es, em) IF (es /= CD_FMF_OK) THEN @@ -813,12 +817,14 @@ SUBROUTINE CD_AGG_UpdateStates_Moving(self, position, velocity, acceleration, Er END IF END IF IF (self%nhost_rod + self%nhost_body > 0) THEN + ! a transfer without advancing: the host kinematics of the committed time, from which the + ! next step of a CoupledPinned rod starts (an output probe is restored by its caller) IF (PRESENT(orientation)) THEN CALL set_host_objects(self, position, velocity, acceleration, ErrStat, ErrMsg, orientation=orientation, & - angular_velocity=self%mv_omega, angular_acceleration=self%mv_alpha) + angular_velocity=self%mv_omega, angular_acceleration=self%mv_alpha, step_start=.TRUE.) ELSE CALL set_host_objects(self, position, velocity, acceleration, ErrStat, ErrMsg, & - angular_velocity=self%mv_omega, angular_acceleration=self%mv_alpha) + angular_velocity=self%mv_omega, angular_acceleration=self%mv_alpha, step_start=.TRUE.) END IF IF (ErrStat /= CD_AGG_OK) RETURN CALL overlay_host_objects(self, is_output_probe, ErrStat, ErrMsg) @@ -2224,18 +2230,24 @@ SUBROUTINE overlay_host_objects(self, output_probe, ErrStat, ErrMsg) END SUBROUTINE overlay_host_objects SUBROUTINE set_host_objects(self, position, velocity, acceleration, ErrStat, ErrMsg, orientation, & - angular_velocity, angular_acceleration) + angular_velocity, angular_acceleration, step_start) !! Impose the host-rod columns (the trailing nhost_rod moving columns) on the rod runtime. + !! step_start: a transfer that does not advance (CD_AGG_UpdateStates_Moving), whose host + !! kinematics the next step of a CoupledPinned rod starts from (CD_Rod_SetHostKinematics). TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: self REAL(wp), INTENT(IN) :: position(:, :), velocity(:, :), acceleration(:, :) INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg REAL(wp), INTENT(IN), OPTIONAL :: orientation(:, :, :) REAL(wp), INTENT(IN), OPTIONAL :: angular_velocity(:, :), angular_acceleration(:, :) + LOGICAL, INTENT(IN), OPTIONAL :: step_start INTEGER :: c0, c1, es + LOGICAL :: at_start CHARACTER(512) :: em ErrStat = CD_AGG_OK ErrMsg = '' + at_start = .FALSE. + IF (PRESENT(step_start)) at_start = step_start IF (self%nhost_body > 0) THEN c0 = self%ncp_sys + self%ncable + self%nhost_rod + 1 c1 = ncp_all(self) @@ -2261,19 +2273,19 @@ SUBROUTINE set_host_objects(self, position, velocity, acceleration, ErrStat, Err IF (PRESENT(angular_velocity)) THEN CALL CD_Rod_SetHostKinematics(self%rod, position(:, c0:c1), velocity(:, c0:c1), acceleration(:, c0:c1), & es, em, orientation(:, :, c0:c1), angular_velocity(:, c0:c1), & - angular_acceleration(:, c0:c1)) + angular_acceleration(:, c0:c1), step_start=at_start) ELSE CALL CD_Rod_SetHostKinematics(self%rod, position(:, c0:c1), velocity(:, c0:c1), acceleration(:, c0:c1), & - es, em, orientation(:, :, c0:c1)) + es, em, orientation(:, :, c0:c1), step_start=at_start) END IF ELSE IF (PRESENT(angular_velocity)) THEN CALL CD_Rod_SetHostKinematics(self%rod, position(:, c0:c1), velocity(:, c0:c1), acceleration(:, c0:c1), & es, em, angular_velocity=angular_velocity(:, c0:c1), & - angular_acceleration=angular_acceleration(:, c0:c1)) + angular_acceleration=angular_acceleration(:, c0:c1), step_start=at_start) ELSE CALL CD_Rod_SetHostKinematics(self%rod, position(:, c0:c1), velocity(:, c0:c1), acceleration(:, c0:c1), & - es, em) + es, em, step_start=at_start) END IF END IF IF (es /= CD_DECKDRV_OK) CALL map_deck_status(es, em, ErrStat, ErrMsg) diff --git a/src/CableDyn_System.f90 b/src/CableDyn_System.f90 index aceed8f4..64ef1782 100644 --- a/src/CableDyn_System.f90 +++ b/src/CableDyn_System.f90 @@ -24,6 +24,7 @@ MODULE CableDyn_System CD_Calc_Model_CoupledLoads, CD_Recompute_Model_Acceleration, & CD_Calc_Model_CoupledKinematicDerivatives, & CD_Calc_Model_CoupledAccelDerivative, CD_Update_Model_CoupledAccelDerivative, & + CD_Calc_Model_CoupledEndMass, & CD_Update_Model_External_Loads, CD_Update_Model_Hydro_Fields, & CD_MODEL_OK, CD_MODEL_BADINPUT, & CD_MODEL_SOLVEFAIL, CD_MODEL_NOT_INITIALIZED, CD_MODEL_ALLOCFAIL, CD_Copy_Model @@ -2183,20 +2184,28 @@ SUBROUTINE CD_Calc_System_CoupledKinematicDerivatives(system, dload_dq, dload_dv END DO END SUBROUTINE CD_Calc_System_CoupledKinematicDerivatives - SUBROUTINE CD_Calc_System_CoupledAccelDerivative(system, dload_da, ErrStat, ErrMsg) + SUBROUTINE CD_Calc_System_CoupledAccelDerivative(system, dload_da, ErrStat, ErrMsg, frozen_interior) !! Return the aggregate analytic coupled-load derivative with respect to - !! compact prescribed coupled accelerations. + !! compact prescribed coupled accelerations. By default the line interiors' + !! accelerations follow the coupled ones (the condensed derivative of a step); + !! frozen_interior = .TRUE. holds them (-M_cc of every line, + !! CD_Calc_Model_CoupledEndMass): the response of CD_Calc_System_CoupledLoads when + !! only the coupled motion changes, as in an output probe. TYPE(CD_SystemType), INTENT(INOUT) :: system REAL(wp), INTENT(OUT) :: dload_da(:, :) INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg + LOGICAL, INTENT(IN), OPTIONAL :: frozen_interior INTEGER :: i, j, k, lo, hi, nc, es, row, col + LOGICAL :: frozen CHARACTER(160) :: em ErrStat = CD_SYSTEM_OK ErrMsg = '' dload_da = CD_ZERO + frozen = .FALSE. + IF (PRESENT(frozen_interior)) frozen = frozen_interior IF (.NOT. system%initialized) THEN ErrStat = CD_SYSTEM_NOT_INITIALIZED ErrMsg = 'CableDyn_System: system is not initialized' @@ -2216,8 +2225,25 @@ SUBROUTINE CD_Calc_System_CoupledAccelDerivative(system, dload_da, ErrStat, ErrM RETURN END IF hi = lo + nc - 1 - ! the line's derivative stays in its own workspace (ad_result) and is summed from there - IF (nc > 0) THEN + IF (nc > 0 .AND. frozen) THEN + BLOCK + REAL(wp) :: m_cc(nc, nc) + CALL CD_Calc_Model_CoupledEndMass(system%lines(i), m_cc, es, em) + IF (es /= CD_MODEL_OK) THEN + ErrStat = CD_SYSTEM_SOLVEFAIL + ErrMsg = 'CableDyn_System: line coupled end mass failed: '//TRIM(em) + RETURN + END IF + DO j = 1, nc + row = system%coupled_dof_map(lo + j - 1) + DO k = 1, nc + col = system%coupled_dof_map(lo + k - 1) + dload_da(row, col) = dload_da(row, col) - m_cc(j, k) + END DO + END DO + END BLOCK + ELSE IF (nc > 0) THEN + ! the line's derivative stays in its own workspace (ad_result) and is summed from there CALL CD_Update_Model_CoupledAccelDerivative(system%lines(i), es, em) IF (es /= CD_MODEL_OK) THEN ErrStat = CD_SYSTEM_SOLVEFAIL diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index 432f98f9..854f534c 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -40,8 +40,9 @@ MODULE CableDyn !! construct is routed into the corresponding CableDyn feature (bodies and rods, !! viscoelastic and Syrope ropes, line failures, active tension through the CONTROL !! section, SeaState water kinematics), or, where CableDyn has no counterpart (for - !! example a CoupledPinned body or a Pinned rod on a line deck), fails closed with a - !! named error. + !! example a CoupledPinned body), fails closed with a named error. A CoupledPinned rod + !! is a coupling-mesh node like a Coupled rod but takes only the translation of its + !! node and returns force with zero moment: it turns about the node on its own. !! !! Supported coupled surface (each verified against stock MoorDyn or a named gate): !! Fixed/Coupled(Vessel) points, EI=0 mooring lines (BA damping + the Morison set), diff --git a/tests/test_bodies_rods.f90 b/tests/test_bodies_rods.f90 index a4a9548f..2063f9fc 100644 --- a/tests/test_bodies_rods.f90 +++ b/tests/test_bodies_rods.f90 @@ -10,7 +10,11 @@ PROGRAM test_bodies_rods !! rhoW A draft = m_total and heaves with 2 pi sqrt(m_total/(rhoW g A)) (CaEnd = 0); !! 3. the same spar on a light vertical tether: the tether carries the net buoyancy, and the !! Body/Rod channels report the body and rod on the line-coupled route; - !! 4. a LINES row written with R1A/R1B equals the same deck with Rod1A/Rod1B POINT rows. + !! 4. a LINES row written with R1A/R1B equals the same deck with Rod1A/Rod1B POINT rows; + !! 5. a short pinned rod at a step beyond its explicit swing limit sub-cycles it on a deck + !! without lines and on the staggered multibody march without an EI=0 line; + !! 6. a pinned rod held by a stiff finite-EI cable on the staggered march sub-cycles the cable + !! spring, whose end force the march applies explicitly. USE CableDyn_Precision, ONLY: wp USE CableDyn_DeckDriver, ONLY: CD_Run_Deck_Driver, CD_DECKDRV_OK USE, INTRINSIC :: IEEE_ARITHMETIC, ONLY: IEEE_IS_FINITE @@ -31,6 +35,8 @@ PROGRAM test_bodies_rods CALL check_pinned_rod_with_line() CALL check_zero_length_rod() CALL check_mixed_rest() + CALL check_lineless_substep() + CALL check_cable_rod_substep() IF (nfail > 0) THEN WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' body/rod topology check(s) failed' ERROR STOP 1 @@ -440,9 +446,10 @@ END SUBROUTINE write_rod_deck SUBROUTINE check_rod_end_tokens() REAL(wp), ALLOCATABLE :: a(:, :), b(:, :) LOGICAL :: ok1, ok2 - ! MoorDyn CoupledPinned/VesselPinned rods fail closed by name + ! MoorDyn CoupledPinned/VesselPinned rods need a coupled host: the standalone driver refuses + ! them by name CALL write_rod_deck('bodrod_cpldpin.dat', .TRUE., 'CoupledPinned') - CALL expect_reject('bodrod_cpldpin.dat', 'CoupledPinned/VesselPinned RODS are not supported', & + CALL expect_reject('bodrod_cpldpin.dat', 'CoupledPinned/VesselPinned ROD requires a coupled host', & 'a CoupledPinned rod') CALL write_rod_deck('bodrod_tokens.dat', .TRUE.) CALL write_rod_deck('bodrod_points.dat', .FALSE.) @@ -702,4 +709,158 @@ SUBROUTINE check_mixed_rest() 'cable anchor Point

F equals AnchTen') CALL require(ABS(dat(14, 1) - dat(15, 1)) <= 1.0e-9_wp*dat(15, 1), 'Rod2TenB is the tether''s FairTen') END SUBROUTINE check_mixed_rest + + SUBROUTINE write_short_pendulum(path, dt, with_cable) + !! A dry 1 m rod (50 kg/m) pinned at End A at (0, 0, 20) and released at 30 degrees, on a deck + !! without lines, or (with_cable) on the staggered multibody march beside an independent + !! finite-EI cable hung from a Fixed rod to an anchor (no EI=0 line, so no line spring reaches + !! the pinned rod). + CHARACTER(*), INTENT(IN) :: path + REAL(wp), INTENT(IN) :: dt + LOGICAL, INTENT(IN) :: with_cable + INTEGER :: u + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'Short dry rod pendulum pinned at End A' + IF (with_cable) THEN + WRITE (u, '(A)') '--- LINE TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass EA BA EI Cdn Cdt Can Cat' + WRITE (u, '(A)') '(-) (m) (kg/m) (N) (-) (Nm2) (-) (-) (-) (-)' + WRITE (u, '(A)') 'cable 0.15 30 5.0e8 -0.8 1.0e4 1.2 0.01 1.0 0' + END IF + WRITE (u, '(A)') '--- ROD TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass Cd Ca CdEnd CaEnd' + WRITE (u, '(A)') '(-) (m) (kg/m) (-) (-) (-) (-)' + WRITE (u, '(A)') 'pend 0.2 50 0 0 0 0' + WRITE (u, '(A)') '--- RODS ---' + WRITE (u, '(A)') 'ID RodType Attachment XA YA ZA XB YB ZB NumSegs Outputs' + WRITE (u, '(A)') '(-) (-) (-) (m) (m) (m) (m) (m) (m) (-) (-)' + WRITE (u, '(A,ES22.14,A,ES22.14,A)') '1 pend Pinned 0 0 20 ', 0.5_wp, ' 0 ', 20.0_wp - SQRT(0.75_wp), ' 4 -' + IF (with_cable) WRITE (u, '(A)') '2 pend Fixed 10 0 -55 10 0 -57 2 -' + IF (with_cable) THEN + WRITE (u, '(A)') '--- POINTS ---' + WRITE (u, '(A)') 'ID Type X Y Z Mass Vol CdA Ca' + WRITE (u, '(A)') '(-) (-) (m) (m) (m) (kg) (m3) (m2) (-)' + WRITE (u, '(A)') '1 Fixed 40 0 -60 0 0 0 0' + WRITE (u, '(A)') '--- LINES ---' + WRITE (u, '(A)') 'ID LineType AttachA AttachB UnstrLen NumSegs Outputs' + WRITE (u, '(A)') '(-) (-) (-) (-) (m) (-) (-)' + WRITE (u, '(A)') '1 cable R2B 1 35 10 -' + END IF + WRITE (u, '(A)') '--- OPTIONS ---' + WRITE (u, '(A)') '70 WtrDpth' + WRITE (u, '(A)') 'deck bodyIC' + IF (with_cable) WRITE (u, '(A)') 'staggered bodyScheme' + WRITE (u, '(ES22.14,A)') dt, ' dtM' + WRITE (u, '(A)') '18 TMax' + WRITE (u, '(A)') '--- OUTPUTS ---' + WRITE (u, '(A)') 'Rod1N4Px Rod1N4Pz' + WRITE (u, '(A)') '--- end ---' + CLOSE (u) + END SUBROUTINE write_short_pendulum + + SUBROUTINE check_lineless_substep() + !! A 1 m dry pinned rod swings with omega0^2 = m g (L/2)/I_A, about 14.6 rad^2/s^2, so a 0.6 s + !! step (omega0 dt = 2.29) is beyond the explicit limit of 2 for any line-free march: the deck + !! without lines, and the staggered multibody march whose only line is a finite-EI cable, + !! must take 6 sub-steps (omega0 dt/0.4 = 5.73) from the rod's own swing. Each run must + !! reproduce a run at the sub-step size at every 0.6 s output row (to the printed digits), + !! stay within its release angle and keep the elliptic-integral period to the accuracy of + !! omega0 dt_sub of about 0.38 (near (omega dt)^2/24 = 0.6 %). + REAL(wp), PARAMETER :: TH0 = 30.0_wp + REAL(wp), ALLOCATABLE :: dc(:, :), df(:, :) + REAL(wp) :: ia, t_ref, got, err, amp + INTEGER :: kase, i, nc + LOGICAL :: ok + CHARACTER(16) :: tag + + ia = 50.0_wp*(1.0_wp/3.0_wp + 0.2_wp**2/16.0_wp) + t_ref = 4.0_wp*SQRT(ia/(50.0_wp*GRAV*0.5_wp))*ellip_k(SIN(0.5_wp*TH0*PI/180.0_wp)) + DO kase = 1, 2 + tag = MERGE('no lines ', 'staggered, cable', kase == 1) + CALL write_short_pendulum('bodrod_short_c.dat', 0.6_wp, kase == 2) + CALL run('bodrod_short_c.dat', 'bodrod_short_c', 3, dc, ok) + IF (.NOT. ok) RETURN + CALL write_short_pendulum('bodrod_short_f.dat', 0.1_wp, kase == 2) + CALL run('bodrod_short_f.dat', 'bodrod_short_f', 3, df, ok) + IF (.NOT. ok) RETURN + nc = SIZE(dc, 2) + err = 0.0_wp + DO i = 1, nc + err = MAX(err, nan_max_abs(dc(2:3, i) - df(2:3, 6*(i - 1) + 1))) + END DO + amp = MAX(nan_max_abs(dc(2, :)), nan_max_abs(df(2, :))) + got = crossing_period(df(1, :), df(2, :)) + WRITE (*, '(A,A,A,ES10.3,A,F8.5,A,2F10.6)') 'short pinned rod at a 0.6 s step (', TRIM(tag), & + '): vs 0.1 s run ', err, ' m; max End B x/release ', amp/0.5_wp, '; period got/analytic [s] ', got, t_ref + CALL require(nc == 31 .AND. SIZE(df, 2) == 181, 'short pendulum: output rows ('//TRIM(tag)//')') + CALL require(err <= 1.0e-6_wp, 'short pendulum: 0.6 s step equals its 0.1 s sub-step run ('//TRIM(tag)//')') + CALL require(amp <= 1.02_wp*0.5_wp, 'short pendulum: the swing stays within its release ('//TRIM(tag)//')') + CALL require(ABS(got - t_ref) <= 1.5e-2_wp*t_ref, 'short pendulum: period ('//TRIM(tag)//')') + END DO + END SUBROUTINE check_lineless_substep + + SUBROUTINE write_cable_rod(path, dt) + !! A heavy 1 m rod (D = 0.3 m, 500 kg/m) hanging from a pin at (0, 0, -20), its End B held by + !! a 20 m neutrally buoyant finite-EI cable (EA 1e7 N, EI 10 N m^2) to an anchor along x at + !! 100 N of pretension, on the staggered multibody march (no EI=0 line). + CHARACTER(*), INTENT(IN) :: path + REAL(wp), INTENT(IN) :: dt + INTEGER :: u + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'Pinned rod held by a stiff finite-EI cable' + WRITE (u, '(A)') '--- LINE TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass EA BA EI Cdn Cdt Can Cat' + WRITE (u, '(A)') '(-) (m) (kg/m) (N) (-) (Nm2) (-) (-) (-) (-)' + WRITE (u, '(A,ES24.16,A)') 'tcable 0.05 ', RHO_W*0.25_wp*PI*0.05_wp**2, ' 1.0e7 -0.8 10.0 1.2 0.01 1.0 0' + WRITE (u, '(A)') '--- ROD TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass Cd Ca CdEnd CaEnd' + WRITE (u, '(A)') '(-) (m) (kg/m) (-) (-) (-) (-)' + WRITE (u, '(A)') 'heavy 0.3 500 0 0 0 0' + WRITE (u, '(A)') '--- RODS ---' + WRITE (u, '(A)') 'ID RodType Attachment XA YA ZA XB YB ZB NumSegs Outputs' + WRITE (u, '(A)') '(-) (-) (-) (m) (m) (m) (m) (m) (m) (-) (-)' + WRITE (u, '(A)') '1 heavy Pinned 0 0 -20 0 0 -21 4 -' + WRITE (u, '(A)') '--- POINTS ---' + WRITE (u, '(A)') 'ID Type X Y Z Mass Vol CdA Ca' + WRITE (u, '(A)') '(-) (-) (m) (m) (m) (kg) (m3) (m2) (-)' + WRITE (u, '(A)') '1 Fixed 20 0 -21 0 0 0 0' + WRITE (u, '(A)') '--- LINES ---' + WRITE (u, '(A)') 'ID LineType AttachA AttachB UnstrLen NumSegs Outputs' + WRITE (u, '(A)') '(-) (-) (-) (-) (m) (-) (-)' + WRITE (u, '(A,ES24.16,A)') '1 tcable R1B 1 ', 20.0_wp*(1.0_wp - 1.0e-5_wp), ' 10 -' + WRITE (u, '(A)') '--- OPTIONS ---' + WRITE (u, '(A)') '70 WtrDpth' + WRITE (u, '(A)') 'deck bodyIC' + WRITE (u, '(A)') 'staggered bodyScheme' + WRITE (u, '(ES22.14,A)') dt, ' dtM' + WRITE (u, '(A)') '2 TMax' + WRITE (u, '(A)') '--- OUTPUTS ---' + WRITE (u, '(A)') 'Rod1N4Px Rod1N4Pz' + WRITE (u, '(A)') '--- end ---' + CLOSE (u) + END SUBROUTINE write_cable_rod + + SUBROUTINE check_cable_rod_substep() + !! The cable's axial stiffness EA/L = 5e5 N/m acts at the 1 m arm against the rod's inertia + !! about its pin (about 170 kg m^2): omega^2 about 3e3 rad^2/s^2, against about 14 from the + !! rod's net weight, so a 0.05 s step (omega dt = 2.7) needs sub-steps that only the cable + !! spring of the estimate asks for (the staggered march returns the cable end force + !! explicitly). The rod must stay near its pose (End B within 0.1 m) and end within 1 cm of + !! a run at dtM = 0.005 s. + REAL(wp), ALLOCATABLE :: dc(:, :), df(:, :) + REAL(wp) :: dev, err + LOGICAL :: ok + CALL write_cable_rod('bodrod_cable_c.dat', 0.05_wp) + CALL run('bodrod_cable_c.dat', 'bodrod_cable_c', 3, dc, ok) + IF (.NOT. ok) RETURN + CALL write_cable_rod('bodrod_cable_f.dat', 0.005_wp) + CALL run('bodrod_cable_f.dat', 'bodrod_cable_f', 3, df, ok) + IF (.NOT. ok) RETURN + dev = nan_max_abs(dc(2, :)) + err = nan_max_abs(dc(2:3, SIZE(dc, 2)) - df(2:3, SIZE(df, 2))) + WRITE (*, '(A,ES10.3,A,ES10.3)') 'pinned rod on a stiff cable at a 0.05 s step: max |End B x| ', dev, & + ' m; end vs dtM/10 ', err + CALL require(dev <= 0.1_wp, 'cable rod: End B stays near its pose (cable spring sub-steps)') + CALL require(err <= 1.0e-2_wp, 'cable rod: ends as the dtM/10 run') + END SUBROUTINE check_cable_rod_substep END PROGRAM test_bodies_rods diff --git a/tests/test_body_rod_physics.f90 b/tests/test_body_rod_physics.f90 index 2e039c0b..95525e5e 100644 --- a/tests/test_body_rod_physics.f90 +++ b/tests/test_body_rod_physics.f90 @@ -25,6 +25,10 @@ PROGRAM test_body_rod_physics !! buoy on an overstretched line, bodies and rods displaced and turned) reach the same !! stable equilibrium, never an unstable one. The rigs of 1-4 !! release a body from its deck pose (bodyIC deck). + !! 7. a rod carried horizontally (drifting, or turning about its pin) onto a bathymetry step + !! up is sub-stepped for the contact it reaches within a step. + !! 8. a floating rod is sub-stepped for its waterplane stiffness, and a rod held by seabed + !! friction holds still at a coarse step (the friction damper is implicit). USE CableDyn_Precision, ONLY: wp USE CableDyn_DeckDriver, ONLY: CD_Run_Deck_Driver, CD_Deck_Equilibrium_Jacobian_Check, CD_DECKDRV_OK USE, INTRINSIC :: IEEE_ARITHMETIC, ONLY: IEEE_IS_FINITE @@ -49,6 +53,9 @@ PROGRAM test_body_rod_physics CALL check_equilibrium_jacobian() CALL check_equilibrium_seed_robustness() CALL check_static_body_start() + CALL check_bathymetry_reach_substep() + CALL check_floating_rod_substep() + CALL check_rod_friction_hold() IF (nfail > 0) THEN WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' body/rod physics check(s) failed' ERROR STOP 1 @@ -1442,4 +1449,221 @@ SUBROUTINE write_connect_deck(path) CLOSE (u) END SUBROUTINE write_connect_deck + ! ------------------------------------------------------------------------------------------ + ! 7. Contact reach over a bathymetry step + ! ------------------------------------------------------------------------------------------ + + REAL(wp) FUNCTION step_floor(x) RESULT(z) + !! The seabed of write_step_bathy: z = -10 m up to x = X0, a linear ramp to -9.2 m at + !! x = X0 + 0.8 (a 45 degree slope), and -9.2 m beyond. + REAL(wp), INTENT(IN) :: x + REAL(wp), PARAMETER :: X0 = 0.3_wp + z = -10.0_wp + 0.8_wp*MIN(1.0_wp, MAX(0.0_wp, (x - X0)/0.8_wp)) + END FUNCTION step_floor + + SUBROUTINE write_step_bathy(path) + CHARACTER(*), INTENT(IN) :: path + INTEGER :: u + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') '-20.0 -20.0 10.0' + WRITE (u, '(A)') '0.3 -20.0 10.0' + WRITE (u, '(A)') '1.1 -20.0 9.2' + WRITE (u, '(A)') '20.0 -20.0 9.2' + WRITE (u, '(A)') '-20.0 20.0 10.0' + WRITE (u, '(A)') '0.3 20.0 10.0' + WRITE (u, '(A)') '1.1 20.0 9.2' + WRITE (u, '(A)') '20.0 20.0 9.2' + CLOSE (u) + END SUBROUTINE write_step_bathy + + SUBROUTINE write_reach_deck(path, rod_type, x_a, dt) + !! A neutrally buoyant 2 m rod (D = 0.2 m, Cd = 1.2, Ca = 1) along y with its axis 0.5 m above + !! the 10 m bed of write_step_bathy, on a deck without lines, carried towards the 0.8 m step + !! up by a 2 m/s current along x: a Free rod at x = x_a drifts over it; a Pinned rod + !! (End A at the origin) weathervanes about its pin and sweeps its stations into it. + CHARACTER(*), INTENT(IN) :: path, rod_type + REAL(wp), INTENT(IN) :: x_a, dt + INTEGER :: u + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'Rod carried over a bathymetry step by a current' + WRITE (u, '(A)') '--- ROD TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass Cd Ca CdEnd CaEnd' + WRITE (u, '(A)') '(-) (m) (kg/m) (-) (-) (-) (-)' + WRITE (u, '(A,ES24.16,A)') 'float 0.2 ', RHO_W*0.25_wp*PI*0.2_wp**2, ' 1.2 1.0 0 0' + WRITE (u, '(A)') '--- RODS ---' + WRITE (u, '(A)') 'ID RodType Attachment XA YA ZA XB YB ZB NumSegs Outputs' + WRITE (u, '(A)') '(-) (-) (-) (m) (m) (m) (m) (m) (m) (-) (-)' + WRITE (u, '(A,A,A,ES24.16,A,ES24.16,A)') '1 float ', rod_type, ' ', x_a, ' 0 -9.5 ', x_a, ' 2 -9.5 4 -' + WRITE (u, '(A)') '--- OPTIONS ---' + WRITE (u, '(A)') '9.80665 g' + WRITE (u, '(A)') '1025.0 rhoW' + WRITE (u, '(A)') 'reach_step.xyz bathymetryFile' + WRITE (u, '(A)') '1.0e7 kBot' + WRITE (u, '(A)') 'uniform 2.0 0 0 current' + WRITE (u, '(A)') 'deck bodyIC' + WRITE (u, '(ES22.14,A)') dt, ' dtM' + WRITE (u, '(A)') '4.0 TMax' + WRITE (u, '(A)') '--- OUTPUTS ---' + WRITE (u, '(A)') 'Rod1N0Px Rod1N0Pz Rod1N2Px Rod1N2Pz Rod1N4Px Rod1N4Pz' + WRITE (u, '(A)') '--- end ---' + CLOSE (u) + END SUBROUTINE write_reach_deck + + SUBROUTINE check_bathymetry_reach_substep() + !! The contact reach must look along the station's whole path over the step. A neutrally + !! buoyant rod 0.5 m above a 10 m bed, carried by a 2 m/s current towards an 0.8 m step up (a + !! 45 degree ramp), meets the higher bed only by moving horizontally: (1) a Free rod drifting + !! over the step, (2) a Pinned rod turning about its pin (its stations move horizontally, + !! with no vertical velocity and an acceleration towards the pin). At dtM = 0.2 s the bed + !! below each station is out of vertical reach (0.5 m against g dt^2/2 = 0.2 m plus the + !! radius), so only the horizontal reach dt |v + w x s| + dt^2 (|a| + |alpha x s| + + !! |w|^2 |s| + g)/2 and the highest floor within it bring the contact springs (kBot 1e7) + !! into the sub-step estimate before a station is driven into the ramp. The run must stay + !! finite, keep every output node out of the bed (at most 8 cm below the floor under it, the + !! penalty set against the drag that presses the rod onto the slope) + !! and below z = -8 m, and end within 0.2 m of a run at dtM = 0.05 s (the rod meets a 45 + !! degree slope at about 2 m/s). With the vertical reach and the floor under each station + !! alone, the Free rod ends 3 m from the dtM = 0.05 s run and the Pinned rod sinks 14 cm into + !! the slope and is thrown up to z = -7.7 m. + REAL(wp), ALLOCATABLE :: dc(:, :), df(:, :) + REAL(wp) :: worst, zmax, err + INTEGER :: kase, i, j + LOGICAL :: ok + CHARACTER(8) :: kind + + CALL write_step_bathy('reach_step.xyz') + DO kase = 1, 2 + IF (kase == 1) THEN + kind = 'Free' + CALL write_reach_deck('reach_c.dat', 'Free', -3.0_wp, 0.2_wp) + CALL write_reach_deck('reach_f.dat', 'Free', -3.0_wp, 0.05_wp) + ELSE + kind = 'Pinned' + CALL write_reach_deck('reach_c.dat', 'Pinned', 0.0_wp, 0.2_wp) + CALL write_reach_deck('reach_f.dat', 'Pinned', 0.0_wp, 0.05_wp) + END IF + CALL run_deck('reach_c.dat', 'reach_c', ok) + IF (.NOT. ok) CYCLE + CALL read_out('reach_c.out', 7, dc, ok) + IF (.NOT. ok) CYCLE + CALL run_deck('reach_f.dat', 'reach_f', ok) + IF (.NOT. ok) CYCLE + CALL read_out('reach_f.out', 7, df, ok) + IF (.NOT. ok) CYCLE + worst = HUGE(1.0_wp) + zmax = -HUGE(1.0_wp) + DO i = 1, SIZE(dc, 2) + DO j = 2, 6, 2 + worst = MIN(worst, dc(j + 1, i) - step_floor(dc(j, i))) + zmax = MAX(zmax, dc(j + 1, i)) + END DO + END DO + err = nan_max_abs(dc(2:7, SIZE(dc, 2)) - df(2:7, SIZE(df, 2))) + WRITE (*, '(A,A,A,F8.4,A,F8.4,A,F8.4,A,ES10.3)') 'rod over a bathymetry step (', TRIM(kind), & + '): end x ', dc(6, SIZE(dc, 2)), ' m; least clearance ', worst, ' m; highest node ', zmax, & + ' m; end vs dtM/4 ', err + CALL require(ALL(IEEE_IS_FINITE(dc)), 'reach: '//TRIM(kind)//' run finite') + CALL require(dc(6, SIZE(dc, 2)) > 0.6_wp, 'reach: '//TRIM(kind)//' rod carried over the step') + CALL require(worst >= -0.08_wp .AND. zmax <= -8.0_wp, 'reach: '//TRIM(kind)//' rod kept out of the bed') + CALL require(err <= 0.2_wp, 'reach: '//TRIM(kind)//' ends as the dtM/4 run') + END DO + END SUBROUTINE check_bathymetry_reach_substep + + ! ------------------------------------------------------------------------------------------ + ! 8. A floating rod and a rod held by seabed friction at a coarse step + ! ------------------------------------------------------------------------------------------ + + SUBROUTINE check_floating_rod_substep() + !! A horizontal 1 m rod (D = 0.05 m, no drag or added mass) floating half submerged on a deck + !! without lines, released 5 mm below its waterline: its waterplane rhoW g D L against its + !! mass rhoW pi D^2 L/8 gives omega^2 = 8 g/(pi D), about 500 rad^2/s^2, so a 0.1 s step + !! (omega dt = 2.2) is beyond the explicit limit. The waterplane stiffness of the sub-step + !! estimate must keep the undamped heave within its release amplitude over 3 s. + REAL(wp), ALLOCATABLE :: dat(:, :) + REAL(wp) :: amp + INTEGER :: u + LOGICAL :: ok + OPEN (NEWUNIT=u, FILE='float_rod.dat', STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'Floating horizontal rod released below its waterline' + WRITE (u, '(A)') '--- ROD TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass Cd Ca CdEnd CaEnd' + WRITE (u, '(A)') '(-) (m) (kg/m) (-) (-) (-) (-)' + WRITE (u, '(A,ES24.16,A)') 'stick 0.05 ', RHO_W*PI*0.05_wp**2/8.0_wp, ' 0 0 0 0' + WRITE (u, '(A)') '--- RODS ---' + WRITE (u, '(A)') 'ID RodType Attachment XA YA ZA XB YB ZB NumSegs Outputs' + WRITE (u, '(A)') '(-) (-) (-) (m) (m) (m) (m) (m) (m) (-) (-)' + WRITE (u, '(A)') '1 stick Free 0 0 -0.005 1 0 -0.005 4 -' + WRITE (u, '(A)') '--- OPTIONS ---' + WRITE (u, '(A)') '9.80665 g' + WRITE (u, '(A)') '1025.0 rhoW' + WRITE (u, '(A)') '50 WtrDpth' + WRITE (u, '(A)') 'deck bodyIC' + WRITE (u, '(A)') '0.1 dtM' + WRITE (u, '(A)') '3.0 TMax' + WRITE (u, '(A)') '--- OUTPUTS ---' + WRITE (u, '(A)') 'Rod1N2Pz' + WRITE (u, '(A)') '--- end ---' + CLOSE (u) + CALL run_deck('float_rod.dat', 'float_rod', ok) + IF (.NOT. ok) RETURN + CALL read_out('float_rod.out', 2, dat, ok) + IF (.NOT. ok) RETURN + amp = nan_max_abs(dat(2, :)) + WRITE (*, '(A,ES10.3,A)') 'floating rod at a 0.1 s step: max |heave| ', amp, ' m (released at 5.0e-3 m)' + CALL require(amp <= 5.5e-3_wp, 'floating rod: the heave stays within its release (waterplane sub-steps)') + END SUBROUTINE check_floating_rod_substep + + SUBROUTINE check_rod_friction_hold() + !! A heavy rod (D = 0.2 m, 50 kg/m) lying on a frictional bed (mu = 0.5, kBot 1e5) in a + !! 0.3 m/s cross current, on a deck without lines at dtM = 0.1 s: the drag (about 11 N/m) + !! is far below mu N (about 87 N/m), so the rod holds. The regularised friction is a damper + !! mu N/vreg (vreg = 1e-3 m/s); applied explicitly it would flip the friction by mu N each + !! step. Implicit, the rod must hold still after the first second (|End A velocity| below + !! 5e-3 m/s) and its net cross load (drag less friction, Rod1Fy) stay below 5 % of mu N L. + REAL(wp), ALLOCATABLE :: dat(:, :) + REAL(wp) :: vmax, fmax, mun + INTEGER :: u, i + LOGICAL :: ok + OPEN (NEWUNIT=u, FILE='fric_rod.dat', STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'Heavy rod held by seabed friction in a cross current' + WRITE (u, '(A)') '--- ROD TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass Cd Ca CdEnd CaEnd' + WRITE (u, '(A)') '(-) (m) (kg/m) (-) (-) (-) (-)' + WRITE (u, '(A)') 'bar 0.2 50 1.2 1.0 0 0' + WRITE (u, '(A)') '--- RODS ---' + WRITE (u, '(A)') 'ID RodType Attachment XA YA ZA XB YB ZB NumSegs Outputs' + WRITE (u, '(A)') '(-) (-) (-) (m) (m) (m) (m) (m) (m) (-) (-)' + WRITE (u, '(A)') '1 bar Free 0 0 -20 1 0 -20 4 -' + WRITE (u, '(A)') '--- OPTIONS ---' + WRITE (u, '(A)') '9.80665 g' + WRITE (u, '(A)') '1025.0 rhoW' + WRITE (u, '(A)') '20 WtrDpth' + WRITE (u, '(A)') '1.0e5 kBot' + WRITE (u, '(A)') '0.5 frictionMu' + WRITE (u, '(A)') 'uniform 0 0.3 0 current' + WRITE (u, '(A)') 'deck bodyIC' + WRITE (u, '(A)') '0.1 dtM' + WRITE (u, '(A)') '4.0 TMax' + WRITE (u, '(A)') '--- OUTPUTS ---' + WRITE (u, '(A)') 'Rod1Vy Rod1Fy' + WRITE (u, '(A)') '--- end ---' + CLOSE (u) + CALL run_deck('fric_rod.dat', 'fric_rod', ok) + IF (.NOT. ok) RETURN + CALL read_out('fric_rod.out', 3, dat, ok) + IF (.NOT. ok) RETURN + mun = 0.5_wp*(50.0_wp - RHO_W*0.25_wp*PI*0.2_wp**2)*GRAV + vmax = 0.0_wp + fmax = 0.0_wp + DO i = 1, SIZE(dat, 2) + IF (dat(1, i) < 1.0_wp) CYCLE + vmax = MAX(vmax, ABS(dat(2, i))) + fmax = MAX(fmax, ABS(dat(3, i))) + END DO + WRITE (*, '(A,ES10.3,A,ES10.3,A,ES10.3,A)') 'rod held by friction at a 0.1 s step: max |v| ', vmax, & + ' m/s; max |net cross load| ', fmax, ' N against mu N L ', mun, ' N' + CALL require(vmax <= 5.0e-3_wp, 'friction: the rod holds still (implicit friction damper)') + CALL require(fmax <= 0.05_wp*mun, 'friction: the net cross load stays balanced') + END SUBROUTINE check_rod_friction_hold + END PROGRAM test_body_rod_physics diff --git a/tests/test_c_api.f90 b/tests/test_c_api.f90 index ea8aa269..92e78e42 100644 --- a/tests/test_c_api.f90 +++ b/tests/test_c_api.f90 @@ -538,14 +538,16 @@ SUBROUTINE case_stale_double_close_copied_handle() END SUBROUTINE case_stale_double_close_copied_handle SUBROUTINE case_deck_bodies_rods() - !! A deck with a free rod (and one with a free Rigid6 body) initializes through the aggregate: - !! the coupled DOFs are its Coupled points, the step is the deck dtM, and 20 driven steps - !! reproduce CD_AGG driven directly bit-for-bit (loads and coupled motion), also across a - !! SaveState / three trial steps / RestoreState rewind half way. A mismatched dt, - !! load derivatives and point fluid fields fail closed by name; a Coupled rod (a 6-DOF host - !! node) is rejected by the standalone deck rules. + !! A deck with a free rod (and one with a free Rigid6 body, and one with a Pinned rod) + !! initializes through the aggregate: the coupled DOFs are its Coupled points, the step is the + !! deck dtM, and 20 driven steps reproduce CD_AGG driven directly bit-for-bit (loads and + !! coupled motion), also across a SaveState / three trial steps / RestoreState rewind half + !! way. A mismatched dt, load derivatives and point fluid fields fail closed by name; a + !! Coupled rod (a 6-DOF host node) and a CoupledPinned rod (a host-driven pin) are rejected + !! by the standalone deck rules. CHARACTER(*), PARAMETER :: ROD_DECK = 'capi_rod_deck.dat', BODY_DECK = 'capi_body_deck.dat', & - HOST_DECK = 'capi_hostrod_deck.dat' + HOST_DECK = 'capi_hostrod_deck.dat', PIN_DECK = 'capi_pinrod_deck.dat', & + HOST_PIN_DECK = 'capi_hostpin_deck.dat' CHARACTER(KIND=C_CHAR), TARGET :: c_path(64) CHARACTER(KIND=C_CHAR), TARGET :: msg(300) TYPE(C_PTR) :: handle @@ -562,12 +564,17 @@ SUBROUTINE case_deck_bodies_rods() CALL write_capi_object_deck(ROD_DECK, 1) CALL write_capi_object_deck(BODY_DECK, 2) CALL write_capi_object_deck(HOST_DECK, 3) - DO ideck = 1, 2 - IF (ideck == 1) THEN + CALL write_capi_object_deck(PIN_DECK, 4) + CALL write_capi_object_deck(HOST_PIN_DECK, 5) + DO ideck = 1, 3 + SELECT CASE (ideck) + CASE (1) path = ROD_DECK - ELSE + CASE (2) path = BODY_DECK - END IF + CASE DEFAULT + path = PIN_DECK + END SELECT c_path = C_NULL_CHAR DO i = 1, LEN_TRIM(path) c_path(i) = path(i:i) @@ -651,11 +658,24 @@ SUBROUTINE case_deck_bodies_rods() CALL CableDyn_GetLastError(handle, C_LOC(msg), INT(SIZE(msg), C_INT)) CALL require(es == 3_C_INT .AND. INDEX(c_text(msg), 'Coupled/Vessel ROD') > 0, 'c-api-objects:host-rod-rejected') CALL CableDyn_Close(handle, es) + ! so is a CoupledPinned rod, whose pin a coupled host moves + path = HOST_PIN_DECK + c_path = C_NULL_CHAR + DO i = 1, LEN_TRIM(path) + c_path(i) = path(i:i) + END DO + CALL CableDyn_Create(handle, es) + CALL CableDyn_InitDeck(handle, C_LOC(c_path), INT(LEN_TRIM(path), C_INT), es) + CALL CableDyn_GetLastError(handle, C_LOC(msg), INT(SIZE(msg), C_INT)) + CALL require(es == 3_C_INT .AND. INDEX(c_text(msg), 'requires a coupled host') > 0, & + 'c-api-objects:host-pinned-rod-rejected') + CALL CableDyn_Close(handle, es) END SUBROUTINE case_deck_bodies_rods SUBROUTINE write_capi_object_deck(path, kind) !! kind 1: a submerged free rod between a Fixed anchor and a Coupled fairlead; kind 2: the same - !! with a free Rigid6 body; kind 3: a Coupled rod (a 6-DOF host node). + !! with a free Rigid6 body; kind 3: a Coupled rod (a 6-DOF host node); kind 4: a Pinned rod + !! (End A on a fixed pin); kind 5: a CoupledPinned rod (its pin a host node). CHARACTER(*), INTENT(IN) :: path INTEGER, INTENT(IN) :: kind INTEGER :: u @@ -679,11 +699,16 @@ SUBROUTINE write_capi_object_deck(path, kind) WRITE (u, '(A)') '--- RODS ---' WRITE (u, '(A)') 'ID RodType Type XA YA ZA XB YB ZB NumSegs Outputs' WRITE (u, '(A)') '(-) (-) (-) (m) (m) (m) (m) (m) (m) (-) (-)' - IF (kind == 1) THEN + SELECT CASE (kind) + CASE (1) WRITE (u, '(A)') '1 rodmat Free 0.0 0.0 -4.0 0.0 0.0 -2.0 2 -' - ELSE + CASE (3) WRITE (u, '(A)') '1 rodmat Coupled 0.0 0.0 -4.0 0.0 0.0 -2.0 2 -' - END IF + CASE (4) + WRITE (u, '(A)') '1 rodmat Pinned 0.0 0.0 -4.0 0.0 0.0 -2.0 2 -' + CASE DEFAULT + WRITE (u, '(A)') '1 rodmat CoupledPinned 0.0 0.0 -4.0 0.0 0.0 -2.0 2 -' + END SELECT END IF WRITE (u, '(A)') '--- POINTS ---' WRITE (u, '(A)') 'ID Type X Y Z Mass Vol CdA Ca' @@ -723,6 +748,8 @@ SUBROUTINE write_capi_object_deck(path, kind) WRITE (u, '(A)') '1.0e5 kBot' WRITE (u, '(A)') '0.005 dtM' WRITE (u, '(A)') '1.0 TMax' + ! the rod pinned at its lower end has no stable static balance: start from the deck pose + IF (kind == 4) WRITE (u, '(A)') 'deck bodyIC' WRITE (u, '(A)') '--- end ---' CLOSE (u) END SUBROUTINE write_capi_object_deck diff --git a/tests/test_openfast_aggregate.f90 b/tests/test_openfast_aggregate.f90 index 56f52f54..c2a04914 100644 --- a/tests/test_openfast_aggregate.f90 +++ b/tests/test_openfast_aggregate.f90 @@ -1821,13 +1821,14 @@ SUBROUTINE case_coupled_rigid6_mirror() DEALLOCATE (s1, s2, s3, sbad) END SUBROUTINE case_coupled_rigid6_mirror - SUBROUTINE write_coupled_rod_deck(path, add_current, rod_type) + SUBROUTINE write_coupled_rod_deck(path, add_current, rod_type, extra_option) !! A submerged Free rod tethered between a Fixed anchor and a Coupled fairlead by two chain !! lines (still water). add_current appends a deck current OPTION to exercise the still-water scope. - !! rod_type replaces the rod's Free type (the other rod routes). + !! rod_type replaces the rod's Free type (the other rod routes); extra_option is one more + !! OPTIONS row. CHARACTER(*), INTENT(IN) :: path LOGICAL, INTENT(IN) :: add_current - CHARACTER(*), INTENT(IN), OPTIONAL :: rod_type + CHARACTER(*), INTENT(IN), OPTIONAL :: rod_type, extra_option INTEGER :: u, ios CHARACTER(16) :: rt rt = 'Free' @@ -1872,6 +1873,7 @@ SUBROUTINE write_coupled_rod_deck(path, add_current, rod_type) WRITE (u, '(A)') '10.0 WtrDpth' WRITE (u, '(A)') '1.0e5 kBot' IF (add_current) WRITE (u, '(A)') 'profile -2.0 0.0 0.0 0.0 0.0 2.0 0.0 0.0 current' + IF (PRESENT(extra_option)) WRITE (u, '(A)') extra_option WRITE (u, '(A)') '--- OUTPUTS ---' WRITE (u, '(A)') 'FairTen2' WRITE (u, '(A)') '--- end ---' @@ -2037,10 +2039,35 @@ SUBROUTINE case_coupled_rod_fluid() CALL require(x_flow - x_still > 1.0e-4_wp, 'rod-fluid:host-current-drives-rod-downstream') CALL CD_AGG_End(flow, es, em) CALL CD_AGG_End(still, es, em) - ! the coupled rod march turns no rod about a pin: a Pinned rod is refused by name + ! the coupled rod march turns a Pinned rod about its fixed End A. Pinned at its lower end the + ! rod (heavier than water, its slack upper line pulling End B down) has no stable balance, so + ! the static start refuses it by name; from the deck pose a sideways fairlead drift turns it. CALL write_coupled_rod_deck('agg_rod_pinned.dat', .FALSE., 'Pinned') CALL CD_AGG_Init_From_Deck(still, 'agg_rod_pinned.dat', DT, es, em) - CALL require(es /= CD_AGG_OK .AND. INDEX(em, 'Pinned ROD') > 0, 'rod:pinned-fails-closed-by-name: '//TRIM(em)) + CALL require(es /= CD_AGG_OK .AND. INDEX(em, 'unstable') > 0, 'rod:pinned-unstable-static-start: '//TRIM(em)) + CALL write_coupled_rod_deck('agg_rod_pinned.dat', .FALSE., 'Pinned', 'deck bodyIC') + CALL CD_AGG_Init_From_Deck(still, 'agg_rod_pinned.dat', DT, es, em) + CALL require(es == CD_AGG_OK, 'rod:pinned-accepted: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + CALL CD_AGG_GetMovingPointMesh(still, r0, v0, a0, load, es, em) + v0 = 0.0_wp + a0 = 0.0_wp + v0(1, 1) = 0.2_wp + x_still = 0.0_wp + DO s = 1, 40 + r0(1, 1) = r0(1, 1) + 0.2_wp*DT + CALL CD_AGG_Step_Moving(still, DT, r0, v0, a0, cv, st, ia, es, em, t_committed=REAL(s, wp)*DT) + CALL require(es == CD_AGG_OK .AND. cv, 'rod:pinned-step: '//TRIM(em)) + IF (es /= CD_AGG_OK) EXIT + CALL CD_AGG_Get_Rod_States(still, ss, es, em) + ! End A = centre - (L/2) e1 stays on the pin at (0, 0, -4) + x_still = MAX(x_still, nan_max_abs(ss(1:3) - ss(16:18) - [0.0_wp, 0.0_wp, -4.0_wp])) + END DO + WRITE (*, '(A,ES10.3,A,ES10.3)') 'coupled Pinned rod: max |End A - pin| = ', x_still, & + ' m; |omega| after 40 steps = ', nan_max_abs(ss(10:12)) + CALL require(x_still <= 1.0e-12_wp, 'rod:pinned-end-A-stays-at-pin') + CALL require(nan_max_abs(ss(10:12)) > 0.0_wp, 'rod:pinned-turns-about-pin') + CALL CD_AGG_End(still, es, em) END SUBROUTINE case_coupled_rod_fluid SUBROUTINE case_rejected_static_branch_status() diff --git a/tests/test_openfast_pinned_rod.f90 b/tests/test_openfast_pinned_rod.f90 new file mode 100644 index 00000000..530d4ae5 --- /dev/null +++ b/tests/test_openfast_pinned_rod.f90 @@ -0,0 +1,1471 @@ +! File: tests/test_openfast_pinned_rod.f90 +! SPDX-License-Identifier: Apache-2.0 +! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +PROGRAM test_openfast_pinned_rod + !! Pinned and CoupledPinned rods on the OpenFAST CompMooring = 5 aggregate (the coupled rod + !! march turning a rod about a fixed pin or about a pin the host moves). Gates: + !! 1) a dry Pinned rod released at 30 degrees swings with the compound-pendulum period of + !! the complete elliptic integral (1e-3 at dt = T/100) and End A stays at the pin; + !! 2) a CoupledPinned rod whose host node is held reproduces the Pinned rod (1e-12), returns + !! zero moment, and its host force is the analytic pin reaction of the swinging rod; + !! 3) under a constant host acceleration a the rod swings about the mean angle atan(a/g) + !! with the period of the effective gravity sqrt(g^2 + a^2); + !! 4) a harmonic pin motion reproduces the linear base-excitation solution, converging at + !! second order in dt; + !! 5) a rod held by stiff tethers sub-cycles a coarse coupling step it could not take + !! explicitly and matches a run at the sub-step size; the host orientation and angular + !! rates are ignored; + !! 6) snapshot / step / restore / step is bit-identical; + !! 7) an output probe returns -M_eff a_p for a pin acceleration a_p (the re-solved rotation), + !! does not depend on the end acceleration the attached lines' loads were evaluated with, + !! and leaves the state bit-identical once restored; + !! 8) a fresh instance overlaid with the checkpoint state (host kinematics, line interiors, + !! rod states, committed line-end motion) returns the same loads before the next step and + !! continues bit-identically; + !! 9) PtfmInit moves the pin with the platform and the static initial condition balances the + !! rod about it; + !! 10) a CoupledPinned rod outside a coupled host is refused by name; + !! 11) the rod march needs no staged copy of the step-start rods (the rod carries its + !! step-start pin): a step without one is bit-identical; + !! 12) only a Pinned or CoupledPinned rod may leave an end without a line or POINT row; + !! 13) a short Pinned rod without a line (dry and hanging, or buoyant and upright) sub-cycles + !! a coupling step beyond the explicit limit of its own swing and keeps its period; + !! 14) a CoupledPinned rod whose pin crosses the free surface within one coupling step + !! (submerged to dry, or dry to submerged) sub-cycles it for the stiffer of its wet states; + !! 15) a Pinned rod whose far end rests on a stiff seabed, and a Free rod lying on it, sub-cycle + !! the contact mode of a large coupling step and stay at rest on the bed. + USE CableDyn_Precision, ONLY: wp + USE CableDyn_DeckDriver, ONLY: CD_Run_Deck_Driver, CD_DECKDRV_OK, CD_Rod_SetHostKinematics, CD_Step_Aggregate_Rod + USE CableDyn_OpenFAST_Aggregate, ONLY: CD_AGG_ModuleType, CD_AGG_Init_From_Deck, CD_AGG_NMovingPoints, & + CD_AGG_GetMovingPointMesh, CD_AGG_UpdateStates_Moving, & + CD_AGG_Step_Moving, CD_AGG_CalcOutput, CD_AGG_Snapshot, CD_AGG_Restore, & + CD_AGG_End, CD_AGG_OK, CD_AGG_EvalChannel, CD_AGG_NumChannels, & + CD_AGG_Rod_MirrorSize, CD_AGG_Get_Rod_States, CD_AGG_Set_Rod_States, & + CD_AGG_HasRod + USE CableDyn_System, ONLY: CD_System_NLines, CD_System_Line_NDOF, CD_Get_System_Line_State, & + CD_Update_System_Line_Interior_State, CD_SYSTEM_OK, CD_System_NSystemCoupledDOF, & + CD_Get_System_CoupledMotion, CD_Update_System_CoupledMotion, CD_Calc_System_CoupledLoads + USE, INTRINSIC :: IEEE_ARITHMETIC, ONLY: IEEE_IS_FINITE + IMPLICIT NONE + REAL(wp), PARAMETER :: PI = 3.141592653589793_wp, G = 9.80665_wp + ! the dry pendulum: L = 10 m, D = 0.2 m, 50 kg/m, pinned at z = 20 m (above the water) + REAL(wp), PARAMETER :: LP = 10.0_wp, DP = 0.2_wp, MP = 500.0_wp, ZPIN = 20.0_wp + INTEGER :: nfail + + nfail = 0 + CALL case_pendulum_and_held_host() + CALL case_constant_acceleration() + CALL case_harmonic_base_excitation() + CALL case_substep_and_state() + CALL case_probe() + CALL case_ptfm_static() + CALL case_standalone_refusal() + CALL case_unstaged_step() + CALL case_bare_rod_ends() + CALL case_lineless_swing_substep() + CALL case_surface_crossing_pin() + CALL case_seabed_contact_substep() + IF (nfail > 0) THEN + WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed' + ERROR STOP 1 + END IF + WRITE (*, '(A)') 'PASS: Pinned and CoupledPinned rods on the coupled aggregate' + +CONTAINS + + INCLUDE 'nan_max_abs.inc' + + SUBROUTINE require(cond, msg) + LOGICAL, INTENT(IN) :: cond + CHARACTER(*), INTENT(IN) :: msg + IF (.NOT. cond) THEN + WRITE (*, '(A)') 'MISMATCH: '//msg + nfail = nfail + 1 + END IF + END SUBROUTINE require + + ! --------------------------------------------------------------------------------------------- ! + ! decks ! + ! --------------------------------------------------------------------------------------------- ! + + SUBROUTINE write_pendulum_deck(path, rod_type, theta_deg, standalone, nsegs) + !! A dry rod (no drag, no added mass) pinned at End A at (0, 0, 20), above the water, released + !! at theta_deg from the vertical in the x-z plane, deck pose (bodyIC deck); no line touches + !! it. An independent Coupled fairlead with its own line keeps a mooring system in the deck. + !! standalone adds the dtM/TMax clock of a standalone run; nsegs replaces NumSegs 4. + CHARACTER(*), INTENT(IN) :: path, rod_type + REAL(wp), INTENT(IN) :: theta_deg + LOGICAL, INTENT(IN), OPTIONAL :: standalone + INTEGER, INTENT(IN), OPTIONAL :: nsegs + REAL(wp) :: th, xb, zb + INTEGER :: u, ns + ns = 4 + IF (PRESENT(nsegs)) ns = nsegs + th = theta_deg*PI/180.0_wp + xb = LP*SIN(th) + zb = ZPIN - LP*COS(th) + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'pinned rod pendulum on the coupled aggregate' + WRITE (u, '(A)') '--- LINE TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass EA BA EI Cdn Cdt Can Cat' + WRITE (u, '(A)') '(-) (m) (kg/m) (N) (-) (Nm2) (-) (-) (-) (-)' + WRITE (u, '(A)') 'line 0.10 80.0 1.0e6 0.0 0.0 1.0 0.0 1.0 0.0' + WRITE (u, '(A)') '--- ROD TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass Cd Ca CdEnd CaEnd' + WRITE (u, '(A)') '(-) (m) (kg/m) (-) (-) (-) (-)' + WRITE (u, '(A)') 'pend 0.2 50 0 0 0 0' + WRITE (u, '(A)') '--- RODS ---' + WRITE (u, '(A)') 'ID RodType Type XA YA ZA XB YB ZB NumSegs Outputs' + WRITE (u, '(A)') '(-) (-) (-) (m) (m) (m) (m) (m) (m) (-) (-)' + WRITE (u, '(A,A,A,ES24.16,A,ES24.16,A,I0,A)') '1 pend ', rod_type, ' 0 0 20 ', xb, ' 0 ', zb, ' ', ns, ' -' + WRITE (u, '(A)') '--- POINTS ---' + WRITE (u, '(A)') 'ID Type X Y Z Mass Vol CdA Ca' + WRITE (u, '(A)') '(-) (-) (m) (m) (m) (kg) (m3) (m2) (-)' + WRITE (u, '(A)') '1 Coupled 0.0 30.0 -1.0 0 0 0 0' + WRITE (u, '(A)') '2 Fixed 6.0 30.0 -8.0 0 0 0 0' + WRITE (u, '(A)') '--- LINES ---' + WRITE (u, '(A)') 'ID NodeA NodeB Outputs' + WRITE (u, '(A)') '(-) (-) (-) (-)' + WRITE (u, '(A)') '1 1 2 -' + WRITE (u, '(A)') '--- SECTIONS ---' + WRITE (u, '(A)') 'LineID LineType Length NumSegs' + WRITE (u, '(A)') '(-) (-) (m) (-)' + WRITE (u, '(A)') '1 line 9.5 6' + WRITE (u, '(A)') '--- OPTIONS ---' + WRITE (u, '(A)') '9.80665 g' + WRITE (u, '(A)') '1025.0 rhoW' + WRITE (u, '(A)') '10.0 WtrDpth' + WRITE (u, '(A)') '1.0e5 kBot' + WRITE (u, '(A)') 'deck bodyIC' + IF (PRESENT(standalone)) THEN + IF (standalone) THEN + WRITE (u, '(A)') '0.01 dtM' + WRITE (u, '(A)') '0.1 TMax' + END IF + END IF + WRITE (u, '(A)') '--- end ---' + CLOSE (u) + END SUBROUTINE write_pendulum_deck + + SUBROUTINE write_short_pendulum_deck(path, mass_pm, zpin, upright, theta_deg, rod_type) + !! A 1 m Pinned rod (rod_type replaces Pinned; D = 0.2 m, mass_pm kg/m, no drag or added + !! mass) pinned at End A at (0, 0, zpin) and released at theta_deg in the x-z plane from the + !! downward vertical (from the upward one with upright), deck pose; no line touches it. The + !! fairlead line of write_pendulum_deck keeps a mooring system in the deck. + CHARACTER(*), INTENT(IN) :: path + REAL(wp), INTENT(IN) :: mass_pm, zpin, theta_deg + LOGICAL, INTENT(IN) :: upright + CHARACTER(*), INTENT(IN), OPTIONAL :: rod_type + CHARACTER(16) :: rt + REAL(wp) :: th, xb, zb + INTEGER :: u + rt = 'Pinned' + IF (PRESENT(rod_type)) rt = rod_type + th = theta_deg*PI/180.0_wp + xb = SIN(th) + zb = zpin - COS(th) + IF (upright) zb = zpin + COS(th) + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'short pinned rod pendulum on the coupled aggregate' + WRITE (u, '(A)') '--- LINE TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass EA BA EI Cdn Cdt Can Cat' + WRITE (u, '(A)') '(-) (m) (kg/m) (N) (-) (Nm2) (-) (-) (-) (-)' + WRITE (u, '(A)') 'line 0.10 80.0 1.0e6 0.0 0.0 1.0 0.0 1.0 0.0' + WRITE (u, '(A)') '--- ROD TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass Cd Ca CdEnd CaEnd' + WRITE (u, '(A)') '(-) (m) (kg/m) (-) (-) (-) (-)' + WRITE (u, '(A,ES24.16,A)') 'pend 0.2 ', mass_pm, ' 0 0 0 0' + WRITE (u, '(A)') '--- RODS ---' + WRITE (u, '(A)') 'ID RodType Type XA YA ZA XB YB ZB NumSegs Outputs' + WRITE (u, '(A)') '(-) (-) (-) (m) (m) (m) (m) (m) (m) (-) (-)' + WRITE (u, '(A,ES24.16,A,ES24.16,A,ES24.16,A)') '1 pend '//TRIM(rt)//' 0 0 ', zpin, ' ', xb, ' 0 ', zb, ' 4 -' + WRITE (u, '(A)') '--- POINTS ---' + WRITE (u, '(A)') 'ID Type X Y Z Mass Vol CdA Ca' + WRITE (u, '(A)') '(-) (-) (m) (m) (m) (kg) (m3) (m2) (-)' + WRITE (u, '(A)') '1 Coupled 0.0 30.0 -1.0 0 0 0 0' + WRITE (u, '(A)') '2 Fixed 6.0 30.0 -8.0 0 0 0 0' + WRITE (u, '(A)') '--- LINES ---' + WRITE (u, '(A)') 'ID NodeA NodeB Outputs' + WRITE (u, '(A)') '(-) (-) (-) (-)' + WRITE (u, '(A)') '1 1 2 -' + WRITE (u, '(A)') '--- SECTIONS ---' + WRITE (u, '(A)') 'LineID LineType Length NumSegs' + WRITE (u, '(A)') '(-) (-) (m) (-)' + WRITE (u, '(A)') '1 line 9.5 6' + WRITE (u, '(A)') '--- OPTIONS ---' + WRITE (u, '(A)') '9.80665 g' + WRITE (u, '(A)') '1025.0 rhoW' + WRITE (u, '(A)') '30.0 WtrDpth' + WRITE (u, '(A)') '1.0e5 kBot' + WRITE (u, '(A)') 'deck bodyIC' + WRITE (u, '(A)') '--- end ---' + CLOSE (u) + END SUBROUTINE write_short_pendulum_deck + + SUBROUTINE write_tethered_deck(path, rod_type, body_ic) + !! A submerged rod (2 m, 0.2 m diameter, Cd = Ca = 1) hanging from End A at (0, 0, -10), held + !! at End B by two horizontal tethers to anchors at x = +/-10 m (EA 2e5 N, 0.5 % pretension): + !! the rotation about y meets their axial stiffness, a stiff mode of about 27 rad/s. End A + !! carries no line and has no Rod1A POINT row, which the coupled route does not need. An + !! independent Coupled fairlead with its own line comes first in the moving surface. The + !! deck asks for the rod's net load about End A (Rod1F/Rod1M). + CHARACTER(*), INTENT(IN) :: path, rod_type, body_ic + INTEGER :: u + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'tethered pinned rod on the coupled aggregate' + WRITE (u, '(A)') '--- LINE TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass EA BA EI Cdn Cdt Can Cat' + WRITE (u, '(A)') '(-) (m) (kg/m) (N) (-) (Nm2) (-) (-) (-) (-)' + WRITE (u, '(A)') 'line 0.10 80.0 1.0e6 0.0 0.0 1.0 0.0 1.0 0.0' + WRITE (u, '(A)') 'tether 0.05 4.0 2.0e5 0.0 0.0 1.0 0.0 1.0 0.0' + WRITE (u, '(A)') '--- ROD TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass Cd Ca CdEnd CaEnd' + WRITE (u, '(A)') '(-) (m) (kg/m) (-) (-) (-) (-)' + WRITE (u, '(A)') 'arm 0.2 50 1.0 1.0 0.0 0.0' + WRITE (u, '(A)') '--- RODS ---' + WRITE (u, '(A)') 'ID RodType Type XA YA ZA XB YB ZB NumSegs Outputs' + WRITE (u, '(A)') '(-) (-) (-) (m) (m) (m) (m) (m) (m) (-) (-)' + WRITE (u, '(A)') '1 arm '//rod_type//' 0 0 -10 0 0 -12 4 -' + WRITE (u, '(A)') '--- POINTS ---' + WRITE (u, '(A)') 'ID Type X Y Z Mass Vol CdA Ca' + WRITE (u, '(A)') '(-) (-) (m) (m) (m) (kg) (m3) (m2) (-)' + WRITE (u, '(A)') '1 Coupled 0.0 30.0 -1.0 0 0 0 0' + WRITE (u, '(A)') '2 Fixed 6.0 30.0 -8.0 0 0 0 0' + WRITE (u, '(A)') '3 Fixed 10.0 0 -12 0 0 0 0' + WRITE (u, '(A)') '4 Fixed -10.0 0 -12 0 0 0 0' + WRITE (u, '(A)') '--- LINES ---' + WRITE (u, '(A)') 'ID NodeA NodeB Outputs' + WRITE (u, '(A)') '(-) (-) (-) (-)' + WRITE (u, '(A)') '1 1 2 -' + WRITE (u, '(A)') '2 R1B 3 -' + WRITE (u, '(A)') '3 R1B 4 -' + WRITE (u, '(A)') '--- SECTIONS ---' + WRITE (u, '(A)') 'LineID LineType Length NumSegs' + WRITE (u, '(A)') '(-) (-) (m) (-)' + WRITE (u, '(A)') '1 line 9.5 6' + WRITE (u, '(A)') '2 tether 9.95 10' + WRITE (u, '(A)') '3 tether 9.95 10' + WRITE (u, '(A)') '--- OPTIONS ---' + WRITE (u, '(A)') '9.80665 g' + WRITE (u, '(A)') '1025.0 rhoW' + WRITE (u, '(A)') '20.0 WtrDpth' + WRITE (u, '(A)') '1.0e5 kBot' + WRITE (u, '(A)') body_ic//' bodyIC' + WRITE (u, '(A)') '--- OUTPUTS ---' + WRITE (u, '(A)') 'Rod1Fx' + WRITE (u, '(A)') 'Rod1Fy' + WRITE (u, '(A)') 'Rod1Fz' + WRITE (u, '(A)') 'Rod1Mx' + WRITE (u, '(A)') 'Rod1My' + WRITE (u, '(A)') 'Rod1Mz' + WRITE (u, '(A)') '--- end ---' + CLOSE (u) + END SUBROUTINE write_tethered_deck + + ! --------------------------------------------------------------------------------------------- ! + ! helpers ! + ! --------------------------------------------------------------------------------------------- ! + + REAL(wp) FUNCTION rod_angle(s) RESULT(th) + !! Angle of the rod axis (End A -> End B) from the downward vertical, positive towards +x. + REAL(wp), INTENT(IN) :: s(:) + th = ATAN2(s(16), -s(18)) + END FUNCTION rod_angle + + REAL(wp) FUNCTION ellip_k(k) RESULT(kk) + !! Complete elliptic integral of the first kind by the arithmetic-geometric mean. + REAL(wp), INTENT(IN) :: k + REAL(wp) :: a, b, c + INTEGER :: i + a = 1.0_wp + b = SQRT(1.0_wp - k*k) + DO i = 1, 30 + c = 0.5_wp*(a + b) + b = SQRT(a*b) + a = c + END DO + kk = PI/(2.0_wp*a) + END FUNCTION ellip_k + + SUBROUTINE crossings(t, x, xm, period, mean) + !! Mean period between the up-crossings of x through xm and the mean of x over those whole + !! periods (trapezoidal); period = -1 with fewer than three crossings. + REAL(wp), INTENT(IN) :: t(:), x(:), xm + REAL(wp), INTENT(OUT) :: period, mean + REAL(wp) :: tc, t0, t1, area + INTEGER :: i, n, i0, i1 + n = 0 + t0 = 0.0_wp + t1 = 0.0_wp + i0 = 0 + i1 = 0 + DO i = 1, SIZE(x) - 1 + IF (x(i) - xm < 0.0_wp .AND. x(i + 1) - xm >= 0.0_wp) THEN + tc = t(i) + (xm - x(i))*(t(i + 1) - t(i))/(x(i + 1) - x(i)) + IF (n == 0) THEN + t0 = tc + i0 = i + END IF + t1 = tc + i1 = i + n = n + 1 + END IF + END DO + period = -1.0_wp + mean = 0.0_wp + IF (n < 3) RETURN + period = (t1 - t0)/REAL(n - 1, wp) + ! the crossing value xm closes both ends of the window + area = 0.5_wp*(xm + x(i0 + 1))*(t(i0 + 1) - t0) + 0.5_wp*(x(i1) + xm)*(t1 - t(i1)) + DO i = i0 + 1, i1 - 1 + area = area + 0.5_wp*(x(i) + x(i + 1))*(t(i + 1) - t(i)) + END DO + mean = area/(t1 - t0) + END SUBROUTINE crossings + + FUNCTION pin_inertia(s) RESULT(ip) + !! Inertia tensor of the dry pendulum rod about its pin (End A), global axes. + REAL(wp), INTENT(IN) :: s(:) + REAL(wp) :: ip(3, 3), rot(3, 3), ib(3, 3), arm(3) + INTEGER :: k + rot = RESHAPE(s(16:24), [3, 3]) + ib = 0.0_wp + ib(1, 1) = 0.5_wp*MP*(0.5_wp*DP)**2 + ib(2, 2) = MP*(3.0_wp*(0.5_wp*DP)**2 + LP*LP)/12.0_wp + ib(3, 3) = ib(2, 2) + arm = 0.5_wp*LP*rot(:, 1) + ip = MATMUL(rot, MATMUL(ib, TRANSPOSE(rot))) + DO k = 1, 3 + ip(k, k) = ip(k, k) + MP*DOT_PRODUCT(arm, arm) + END DO + ip = ip - MP*SPREAD(arm, 2, 3)*SPREAD(arm, 1, 3) + END FUNCTION pin_inertia + + FUNCTION solve3(a, b) RESULT(x) + !! x = a^-1 b by Cramer's rule (a 3x3, well conditioned here). + REAL(wp), INTENT(IN) :: a(3, 3), b(3) + REAL(wp) :: x(3), d, c(3, 3) + INTEGER :: k + d = det3(a) + DO k = 1, 3 + c = a + c(:, k) = b + x(k) = det3(c)/d + END DO + END FUNCTION solve3 + + PURE REAL(wp) FUNCTION det3(m) RESULT(d) + REAL(wp), INTENT(IN) :: m(3, 3) + d = m(1, 1)*(m(2, 2)*m(3, 3) - m(2, 3)*m(3, 2)) - m(1, 2)*(m(2, 1)*m(3, 3) - m(2, 3)*m(3, 1)) + & + m(1, 3)*(m(2, 1)*m(3, 2) - m(2, 2)*m(3, 1)) + END FUNCTION det3 + + PURE FUNCTION cross(x, y) RESULT(z) + REAL(wp), INTENT(IN) :: x(3), y(3) + REAL(wp) :: z(3) + z = [x(2)*y(3) - x(3)*y(2), x(3)*y(1) - x(1)*y(3), x(1)*y(2) - x(2)*y(1)] + END FUNCTION cross + + FUNCTION pin_reaction(s, a_pin) RESULT(f) + !! The force a dry rod exerts on its pin at state s (rod mirror) for a pin acceleration + !! a_pin: Euler's equation about the pin, I_p alpha + w x (I_p w) = r x m (g - a_pin), then + !! f = m g - m (a_pin + alpha x r + w x (w x r)), g = (0, 0, -9.80665). + REAL(wp), INTENT(IN) :: s(:), a_pin(3) + REAL(wp) :: f(3), ip(3, 3), arm(3), w(3), alpha(3), gv(3) + ip = pin_inertia(s) + arm = 0.5_wp*LP*s(16:18) + w = s(10:12) + gv = [0.0_wp, 0.0_wp, -G] + alpha = solve3(ip, cross(arm, MP*(gv - a_pin)) - cross(w, MATMUL(ip, w))) + f = MP*gv - MP*(a_pin + cross(alpha, arm) + cross(w, cross(w, arm))) + END FUNCTION pin_reaction + + SUBROUTINE march(agg, dt, nstep, host, ang, t, ok, s_end, force) + !! March nstep coupling steps, the last moving column (the rod's pin when present) driven by + !! host(t) = [position, velocity, acceleration] and every other column held at its initial + !! position; ang(0:nstep) the rod angle, t the times. Before the first step the host + !! kinematics at t = 0 are transferred (the start of the run, as the coupled shell does). + TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: agg + REAL(wp), INTENT(IN) :: dt + INTEGER, INTENT(IN) :: nstep + INTERFACE + FUNCTION host(time) RESULT(k) + IMPORT :: wp + REAL(wp), INTENT(IN) :: time + REAL(wp) :: k(9) + END FUNCTION host + END INTERFACE + REAL(wp), INTENT(OUT) :: ang(0:nstep), t(0:nstep) + LOGICAL, INTENT(OUT) :: ok + REAL(wp), INTENT(OUT), OPTIONAL :: s_end(24), force(3, 0:nstep) + REAL(wp), ALLOCATABLE :: p(:, :), v(:, :), a(:, :), f(:, :), p0(:, :), s(:) + REAL(wp) :: k(9) + INTEGER :: n, es, it, step + LOGICAL :: cv, st + CHARACTER(512) :: em + + ok = .FALSE. + n = CD_AGG_NMovingPoints(agg, es, em) + ALLOCATE (p(3, n), v(3, n), a(3, n), f(3, n), p0(3, n), s(CD_AGG_Rod_MirrorSize(agg))) + CALL CD_AGG_GetMovingPointMesh(agg, p0, v, a, f, es, em) + v = 0.0_wp + a = 0.0_wp + p = p0 + k = host(0.0_wp) + p(:, n) = p0(:, n) + k(1:3) + v(:, n) = k(4:6) + a(:, n) = k(7:9) + CALL CD_AGG_UpdateStates_Moving(agg, p, v, a, es, em) + CALL require(es == CD_AGG_OK, 'march:start-transfer: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + CALL CD_AGG_Get_Rod_States(agg, s, es, em) + ang(0) = rod_angle(s) + t(0) = 0.0_wp + IF (PRESENT(force)) THEN + CALL CD_AGG_CalcOutput(agg, es, em) + CALL CD_AGG_GetMovingPointMesh(agg, p, v, a, f, es, em) + force(:, 0) = f(:, n) + END IF + DO step = 1, nstep + t(step) = REAL(step, wp)*dt + k = host(t(step)) + p = p0 + v = 0.0_wp + a = 0.0_wp + p(:, n) = p0(:, n) + k(1:3) + v(:, n) = k(4:6) + a(:, n) = k(7:9) + CALL CD_AGG_Step_Moving(agg, dt, p, v, a, cv, st, it, es, em, t_committed=t(step)) + CALL require(es == CD_AGG_OK .AND. cv, 'march:step: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + CALL CD_AGG_Get_Rod_States(agg, s, es, em) + ang(step) = rod_angle(s) + IF (PRESENT(force)) THEN + CALL CD_AGG_CalcOutput(agg, es, em) + CALL CD_AGG_GetMovingPointMesh(agg, p, v, a, f, es, em) + force(:, step) = f(:, n) + END IF + END DO + IF (PRESENT(s_end)) s_end = s + ok = ALL(IEEE_IS_FINITE(ang)) + END SUBROUTINE march + + ! --------------------------------------------------------------------------------------------- ! + ! 1-2: the fixed-pin pendulum and the held host ! + ! --------------------------------------------------------------------------------------------- ! + + SUBROUTINE case_pendulum_and_held_host() + TYPE(CD_AGG_ModuleType) :: pinned, held + REAL(wp), PARAMETER :: TH0 = 30.0_wp + REAL(wp), ALLOCATABLE :: p(:, :), v(:, :), a(:, :), f(:, :), mo(:, :), p0(:, :) + REAL(wp), ALLOCATABLE :: ang(:), t(:) + REAL(wp) :: s1(24), s2(24), ia, t_ref, dt, period, mean, err_state, err_pin, err_force, fref(3), pin(3) + INTEGER :: es, n, nstep, step, it + LOGICAL :: cv, st + CHARACTER(512) :: em + + ia = MP*(LP*LP/3.0_wp + DP*DP/16.0_wp) + t_ref = 4.0_wp*SQRT(ia/(MP*G*0.5_wp*LP))*ellip_k(SIN(0.5_wp*TH0*PI/180.0_wp)) + dt = t_ref/100.0_wp + nstep = 500 + CALL write_pendulum_deck('pinrod_pendulum.dat', 'Pinned', TH0) + CALL write_pendulum_deck('pinrod_pendulum_held.dat', 'CoupledPinned', TH0) + CALL CD_AGG_Init_From_Deck(pinned, 'pinrod_pendulum.dat', dt, es, em) + CALL require(es == CD_AGG_OK, 'pendulum:init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + CALL CD_AGG_Init_From_Deck(held, 'pinrod_pendulum_held.dat', dt, es, em) + CALL require(es == CD_AGG_OK, 'held:init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + CALL require(CD_AGG_HasRod(pinned) .AND. CD_AGG_NMovingPoints(pinned, es, em) == 1, & + 'pendulum:a Pinned rod adds no host node') + n = CD_AGG_NMovingPoints(held, es, em) + CALL require(n == 2, 'held:one host node for the CoupledPinned rod after the fairlead') + IF (n /= 2) RETURN + ALLOCATE (p(3, 2), v(3, 2), a(3, 2), f(3, 2), mo(3, 2), p0(3, 2), ang(0:nstep), t(0:nstep)) + CALL CD_AGG_GetMovingPointMesh(held, p0, v, a, f, es, em) + CALL require(nan_max_abs(p0(:, 2) - [0.0_wp, 0.0_wp, ZPIN]) <= 1.0e-13_wp, 'held:host node at End A') + p = p0 + v = 0.0_wp + a = 0.0_wp + CALL CD_AGG_Get_Rod_States(pinned, s1, es, em) + ang(0) = rod_angle(s1) + t(0) = 0.0_wp + err_state = 0.0_wp + err_pin = 0.0_wp + err_force = 0.0_wp + pin = [0.0_wp, 0.0_wp, ZPIN] + DO step = 0, nstep + IF (step > 0) THEN + CALL CD_AGG_Step_Moving(pinned, dt, p(:, 1:1), v(:, 1:1), a(:, 1:1), cv, st, it, es, em, & + t_committed=REAL(step, wp)*dt) + CALL require(es == CD_AGG_OK .AND. cv, 'pendulum:step: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + CALL CD_AGG_Step_Moving(held, dt, p, v, a, cv, st, it, es, em, t_committed=REAL(step, wp)*dt) + CALL require(es == CD_AGG_OK .AND. cv, 'held:step: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + END IF + CALL CD_AGG_Get_Rod_States(pinned, s1, es, em) + CALL CD_AGG_Get_Rod_States(held, s2, es, em) + t(step) = REAL(step, wp)*dt + ang(step) = rod_angle(s1) + err_pin = MAX(err_pin, nan_max_abs(s1(1:3) - 0.5_wp*LP*s1(16:18) - pin)) + err_state = MAX(err_state, nan_max_abs(s2 - s1)/MAX(1.0_wp, nan_max_abs(s1))) + CALL CD_AGG_CalcOutput(held, es, em) + CALL CD_AGG_GetMovingPointMesh(held, p, v, a, f, es, em, moment=mo) + CALL require(es == CD_AGG_OK, 'held:mesh: '//TRIM(em)) + CALL require(nan_max_abs(mo(:, 2)) <= 0.0_wp, 'held:host moment is zero') + fref = pin_reaction(s2, [0.0_wp, 0.0_wp, 0.0_wp]) + err_force = MAX(err_force, nan_max_abs(f(:, 2) - fref)/(MP*G)) + p = p0 + v = 0.0_wp + a = 0.0_wp + END DO + CALL crossings(t, ang, 0.0_wp, period, mean) + WRITE (*, '(A,2F12.6,A,ES10.3)') 'coupled Pinned pendulum period got/analytic [s]: ', period, t_ref, & + '; rel. error ', ABS(period - t_ref)/t_ref + WRITE (*, '(A,ES10.3,A,ES10.3,A,ES10.3)') 'max |End A - pin| [m] ', err_pin, & + '; held CoupledPinned vs Pinned state ', err_state, '; host force vs pin reaction / mg ', err_force + CALL require(ABS(period - t_ref) <= 1.0e-3_wp*t_ref, 'pendulum:period (elliptic integral)') + CALL require(err_pin <= 1.0e-12_wp, 'pendulum:End A stays at the pin') + CALL require(err_state <= 1.0e-12_wp, 'held:CoupledPinned with the host held equals Pinned') + CALL require(err_force <= 1.0e-10_wp, 'held:host force is the analytic pin reaction') + CALL CD_AGG_End(pinned, es, em) + CALL CD_AGG_End(held, es, em) + END SUBROUTINE case_pendulum_and_held_host + + ! --------------------------------------------------------------------------------------------- ! + ! 3: constant host acceleration ! + ! --------------------------------------------------------------------------------------------- ! + + FUNCTION host_const(time) RESULT(k) + !! The pin accelerating uniformly along +x from rest: a = 2 m/s^2. + REAL(wp), INTENT(IN) :: time + REAL(wp) :: k(9) + REAL(wp), PARAMETER :: AX = 2.0_wp + k = 0.0_wp + k(1) = 0.5_wp*AX*time*time + k(4) = AX*time + k(7) = AX + END FUNCTION host_const + + SUBROUTINE case_constant_acceleration() + !! In the frame of a pin accelerating at a along x the rod is a pendulum in the effective + !! gravity (-a, 0, -g): it swings about theta_eq = -atan(a/g) (trailing) with the period + !! 4 sqrt(I_p/(m h g_eff)) K(sin(delta/2)), g_eff = sqrt(g^2 + a^2), for an amplitude delta. + TYPE(CD_AGG_ModuleType) :: agg + REAL(wp), PARAMETER :: AX = 2.0_wp, DELTA = 5.0_wp + REAL(wp), ALLOCATABLE :: ang(:), t(:) + REAL(wp) :: ia, th_eq, geff, t_ref, dt, period, mean + INTEGER :: es, nstep + LOGICAL :: ok + CHARACTER(512) :: em + + th_eq = -ATAN(AX/G) + geff = SQRT(G*G + AX*AX) + ia = MP*(LP*LP/3.0_wp + DP*DP/16.0_wp) + t_ref = 4.0_wp*SQRT(ia/(MP*geff*0.5_wp*LP))*ellip_k(SIN(0.5_wp*DELTA*PI/180.0_wp)) + dt = t_ref/100.0_wp + nstep = 500 + CALL write_pendulum_deck('pinrod_accel.dat', 'CoupledPinned', th_eq*180.0_wp/PI + DELTA) + CALL CD_AGG_Init_From_Deck(agg, 'pinrod_accel.dat', dt, es, em) + CALL require(es == CD_AGG_OK, 'accel:init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + ALLOCATE (ang(0:nstep), t(0:nstep)) + CALL march(agg, dt, nstep, host_const, ang, t, ok) + CALL require(ok, 'accel:march finite') + IF (.NOT. ok) RETURN + CALL crossings(t, ang, th_eq, period, mean) + WRITE (*, '(A,2F12.6,A,2F10.6)') 'constant pin acceleration: period got/analytic [s] ', period, t_ref, & + '; mean angle got/atan(a/g) [rad] ', mean, th_eq + CALL require(ABS(period - t_ref) <= 1.0e-3_wp*t_ref, 'accel:period with g_eff') + CALL require(ABS(mean - th_eq) <= 1.0e-4_wp, 'accel:mean angle -atan(a/g)') + CALL CD_AGG_End(agg, es, em) + END SUBROUTINE case_constant_acceleration + + ! --------------------------------------------------------------------------------------------- ! + ! 4: harmonic base excitation ! + ! --------------------------------------------------------------------------------------------- ! + + FUNCTION host_harm(time) RESULT(k) + !! x_p = X (1 - cos W t): the pin starts at rest, X = 0.05 m, W = 0.6 w0. + REAL(wp), INTENT(IN) :: time + REAL(wp) :: k(9), w + REAL(wp), PARAMETER :: X = 0.05_wp + w = 0.6_wp*omega0() + k = 0.0_wp + k(1) = X*(1.0_wp - COS(w*time)) + k(4) = X*w*SIN(w*time) + k(7) = X*w*w*COS(w*time) + END FUNCTION host_harm + + REAL(wp) FUNCTION omega0() RESULT(w0) + !! Small-amplitude natural frequency of the dry pendulum about its pin. + w0 = SQRT(MP*G*0.5_wp*LP/(MP*(LP*LP/3.0_wp + DP*DP/16.0_wp))) + END FUNCTION omega0 + + SUBROUTINE case_harmonic_base_excitation() + !! Linear base excitation of the pendulum from rest, theta'' + w0^2 theta = -(m h/I_p) a_p(t): + !! theta = -(m h/I_p) X W^2 (cos W t - cos w0 t)/(w0^2 - W^2). The amplitude is about 0.01 + !! rad, so the neglected sin/cos terms stay near 1e-4 of it; three natural periods at + !! dt = T0/100 and T0/200 must converge at second order to below 2e-3 of the amplitude. + TYPE(CD_AGG_ModuleType) :: agg + REAL(wp), ALLOCATABLE :: ang(:), t(:), ref(:) + REAL(wp) :: w0, w, kap, dt, err(2), amp + INTEGER :: es, nstep, ires, i + LOGICAL :: ok + CHARACTER(512) :: em + + w0 = omega0() + w = 0.6_wp*w0 + kap = MP*0.5_wp*LP/(MP*(LP*LP/3.0_wp + DP*DP/16.0_wp)) + CALL write_pendulum_deck('pinrod_harm.dat', 'CoupledPinned', 0.0_wp) + DO ires = 1, 2 + nstep = 300*ires + dt = 2.0_wp*PI/w0/REAL(100*ires, wp) + CALL CD_AGG_Init_From_Deck(agg, 'pinrod_harm.dat', dt, es, em) + CALL require(es == CD_AGG_OK, 'harm:init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + ALLOCATE (ang(0:nstep), t(0:nstep), ref(0:nstep)) + CALL march(agg, dt, nstep, host_harm, ang, t, ok) + CALL require(ok, 'harm:march finite') + IF (.NOT. ok) RETURN + DO i = 0, nstep + ref(i) = -kap*0.05_wp*w*w*(COS(w*t(i)) - COS(w0*t(i)))/(w0*w0 - w*w) + END DO + amp = nan_max_abs(ref) + err(ires) = nan_max_abs(ang - ref)/amp + DEALLOCATE (ang, t, ref) + CALL CD_AGG_End(agg, es, em) + END DO + WRITE (*, '(A,ES10.3,A,2ES10.3,A,F6.2)') 'harmonic pin motion: amplitude ', amp, & + ' rad; rel. error dt = T0/100, T0/200: ', err, '; ratio ', err(1)/err(2) + CALL require(err(2) <= 2.0e-3_wp, 'harm:linear base-excitation solution') + CALL require(err(1)/err(2) > 3.0_wp, 'harm:second-order convergence') + END SUBROUTINE case_harmonic_base_excitation + + ! --------------------------------------------------------------------------------------------- ! + ! 5-6, 8: sub-stepping, snapshot / restore, restart overlay ! + ! --------------------------------------------------------------------------------------------- ! + + FUNCTION host_surge(time) RESULT(k) + !! x_p = X (1 - cos W t), X = 0.2 m, a 5 s period. + REAL(wp), INTENT(IN) :: time + REAL(wp) :: k(9), w + REAL(wp), PARAMETER :: X = 0.2_wp + w = 2.0_wp*PI/5.0_wp + k = 0.0_wp + k(1) = X*(1.0_wp - COS(w*time)) + k(4) = X*w*SIN(w*time) + k(7) = X*w*w*COS(w*time) + END FUNCTION host_surge + + FUNCTION host_drift(time) RESULT(k) + !! The pin drifting along +x at a constant 0.05 m/s from t = 0. + REAL(wp), INTENT(IN) :: time + REAL(wp) :: k(9) + k = 0.0_wp + k(1) = 0.05_wp*time + k(4) = 0.05_wp + END FUNCTION host_drift + + SUBROUTINE case_substep_and_state() + !! The tethered rod's stiff mode (about 27 rad/s) makes omega dt about 2.7 at a 0.1 s + !! coupling step, beyond the explicit limit of 2: the march must sub-cycle it (7 sub-steps). + !! Against a run at the sub-step size: a pin drifting at constant velocity, which the linear + !! interpolation of the host motion inside a step represents exactly, gives the same rod + !! motion and pin force; a harmonic surge gives the same rod motion within 1 % (the + !! interpolated pin path deviates by a dt^2 a/8 that the stiff tethers turn into a few N). + !! On the coarse run: host orientation and angular rates are ignored for the pin node; + !! snapshot/step/restore/step and the restart overlay are bit-identical. + TYPE(CD_AGG_ModuleType) :: coarse, fine, turned, agg_b + REAL(wp), PARAMETER :: DTC = 0.1_wp + INTEGER, PARAMETER :: NSUB = 7, NC = 60 + REAL(wp), ALLOCATABLE :: angc(:), tc(:), angf(:), tf(:), fc(:, :), ff(:, :) + REAL(wp), ALLOCATABLE :: p(:, :), v(:, :), a(:, :), f(:, :), fb(:, :), mo(:, :), mb(:, :), p0(:, :) + REAL(wp), ALLOCATABLE :: orr(:, :, :), w(:, :), al(:, :), lq(:), lv(:), la(:), rs(:), rs2(:) + REAL(wp), ALLOCATABLE :: cq(:), cvv(:), ca(:) + REAL(wp) :: err_ang, err_f, amp, famp, k(9), th, err + INTEGER :: es, i, n, step, it, nl, il, ndof, kind, ncd + LOGICAL :: ok, cv, st + CHARACTER(512) :: em + + CALL write_tethered_deck('pinrod_tether.dat', 'CoupledPinned', 'deck') + ALLOCATE (angc(0:NC), tc(0:NC), angf(0:NC*NSUB), tf(0:NC*NSUB), fc(3, 0:NC), ff(3, 0:NC*NSUB)) + DO kind = 1, 2 + CALL CD_AGG_Init_From_Deck(coarse, 'pinrod_tether.dat', DTC, es, em) + CALL require(es == CD_AGG_OK, 'substep:coarse-init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + CALL CD_AGG_Init_From_Deck(fine, 'pinrod_tether.dat', DTC/REAL(NSUB, wp), es, em) + CALL require(es == CD_AGG_OK, 'substep:fine-init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + IF (kind == 1) THEN + CALL march(coarse, DTC, NC, host_drift, angc, tc, ok, force=fc) + CALL require(ok, 'substep:coarse march finite (the stiff mode is sub-cycled)') + CALL march(fine, DTC/REAL(NSUB, wp), NC*NSUB, host_drift, angf, tf, ok, force=ff) + ELSE + CALL march(coarse, DTC, NC, host_surge, angc, tc, ok, force=fc) + CALL require(ok, 'substep:coarse march finite (the stiff mode is sub-cycled)') + CALL march(fine, DTC/REAL(NSUB, wp), NC*NSUB, host_surge, angf, tf, ok, force=ff) + END IF + CALL require(ok, 'substep:fine march finite') + IF (.NOT. ok) RETURN + err_ang = 0.0_wp + err_f = 0.0_wp + DO i = 0, NC + err_ang = MAX(err_ang, ABS(angc(i) - angf(NSUB*i))) + err_f = MAX(err_f, nan_max_abs(fc(:, i) - ff(:, NSUB*i))) + END DO + amp = nan_max_abs(angf) + famp = nan_max_abs(ff) + WRITE (*, '(A,I0,A,ES10.3,A,ES10.3,A,ES10.3,A,ES10.3)') 'sub-cycled coarse step vs sub-step run (', kind, & + '): angle ', err_ang, ' of ', amp, ' rad; pin force ', err_f, ' of ', famp + CALL require(amp > 0.05_wp, 'substep:the pin motion turns the rod') + IF (kind == 1) THEN + CALL require(err_ang <= 1.0e-8_wp*amp .AND. err_f <= 1.0e-8_wp*famp, & + 'substep:drifting pin: coarse equals fine') + CALL CD_AGG_End(coarse, es, em) + ELSE + CALL require(err_ang <= 1.0e-2_wp*amp, 'substep:surge: coarse equals fine (angle)') + END IF + CALL CD_AGG_End(fine, es, em) + END DO + + ! the host orientation and angular rates do not reach a CoupledPinned rod + n = CD_AGG_NMovingPoints(coarse, es, em) + ALLOCATE (p(3, n), v(3, n), a(3, n), f(3, n), fb(3, n), mo(3, n), mb(3, n), p0(3, n)) + ALLOCATE (orr(3, 3, n), w(3, n), al(3, n), rs(CD_AGG_Rod_MirrorSize(coarse)), rs2(CD_AGG_Rod_MirrorSize(coarse))) + CALL CD_AGG_Init_From_Deck(turned, 'pinrod_tether.dat', DTC, es, em) + CALL CD_AGG_GetMovingPointMesh(turned, p0, v, a, f, es, em) + CALL CD_AGG_Init_From_Deck(fine, 'pinrod_tether.dat', DTC, es, em) + err = 0.0_wp + DO step = 0, 20 + k = host_surge(REAL(step, wp)*DTC) + p = p0 + v = 0.0_wp + a = 0.0_wp + p(:, n) = p0(:, n) + k(1:3) + v(:, n) = k(4:6) + a(:, n) = k(7:9) + th = 0.3_wp*SIN(REAL(step, wp)) + orr = 0.0_wp + DO i = 1, n + orr(1, 1, i) = 1.0_wp + orr(2, 2, i) = 1.0_wp + orr(3, 3, i) = 1.0_wp + END DO + orr(1, 1, n) = COS(th) + orr(1, 3, n) = -SIN(th) + orr(3, 1, n) = SIN(th) + orr(3, 3, n) = COS(th) + w = 0.0_wp + al = 0.0_wp + w(2, n) = 0.3_wp*COS(REAL(step, wp)) + al(2, n) = -0.3_wp*SIN(REAL(step, wp)) + IF (step == 0) THEN + CALL CD_AGG_UpdateStates_Moving(turned, p, v, a, es, em, orientation=orr, angular_velocity=w, & + angular_acceleration=al) + CALL CD_AGG_UpdateStates_Moving(fine, p, v, a, es, em) + ELSE + CALL CD_AGG_Step_Moving(turned, DTC, p, v, a, cv, st, it, es, em, t_committed=REAL(step, wp)*DTC, & + orientation=orr, angular_velocity=w, angular_acceleration=al) + CALL require(es == CD_AGG_OK, 'orient:turned step: '//TRIM(em)) + CALL CD_AGG_Step_Moving(fine, DTC, p, v, a, cv, st, it, es, em, t_committed=REAL(step, wp)*DTC) + END IF + CALL CD_AGG_Get_Rod_States(turned, rs, es, em) + CALL CD_AGG_Get_Rod_States(fine, rs2, es, em) + err = MAX(err, nan_max_abs(rs - rs2)) + END DO + CALL require(err <= 0.0_wp, 'orient:host orientation and rates ignored by the pinned rod') + CALL CD_AGG_End(turned, es, em) + CALL CD_AGG_End(fine, es, em) + + ! snapshot -> step A -> restore -> step B reproduces step A + k = host_surge(REAL(NC + 1, wp)*DTC) + p = p0 + v = 0.0_wp + a = 0.0_wp + p(:, n) = p0(:, n) + k(1:3) + v(:, n) = k(4:6) + a(:, n) = k(7:9) + CALL CD_AGG_Snapshot(coarse, es, em) + CALL CD_AGG_Step_Moving(coarse, DTC, p, v, a, cv, st, it, es, em, t_committed=REAL(NC + 1, wp)*DTC) + CALL CD_AGG_CalcOutput(coarse, es, em) + CALL CD_AGG_GetMovingPointMesh(coarse, p, v, a, fb, es, em, moment=mb) + CALL CD_AGG_Get_Rod_States(coarse, rs, es, em) + CALL CD_AGG_Restore(coarse, es, em) + p = p0 + v = 0.0_wp + a = 0.0_wp + p(:, n) = p0(:, n) + k(1:3) + v(:, n) = k(4:6) + a(:, n) = k(7:9) + CALL CD_AGG_Step_Moving(coarse, DTC, p, v, a, cv, st, it, es, em, t_committed=REAL(NC + 1, wp)*DTC) + CALL CD_AGG_CalcOutput(coarse, es, em) + CALL CD_AGG_GetMovingPointMesh(coarse, p, v, a, f, es, em, moment=mo) + CALL CD_AGG_Get_Rod_States(coarse, rs2, es, em) + CALL require(nan_max_abs(f - fb) <= 0.0_wp .AND. nan_max_abs(mo - mb) <= 0.0_wp .AND. & + nan_max_abs(rs - rs2) <= 0.0_wp, 'state:snapshot-step-restore-step bit-identical') + CALL require(nan_max_abs(mo(:, n)) <= 0.0_wp .AND. nan_max_abs(f(:, n)) > 0.0_wp, 'state:force only at the pin node') + + ! restart: a fresh instance takes the host kinematics, the line interiors and the rod states + CALL CD_AGG_Init_From_Deck(agg_b, 'pinrod_tether.dat', DTC, es, em) + CALL require(es == CD_AGG_OK, 'restart:init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + CALL CD_AGG_UpdateStates_Moving(agg_b, p, v, a, es, em) + CALL require(es == CD_AGG_OK, 'restart:host: '//TRIM(em)) + nl = CD_System_NLines(coarse%sys%fast%system, es, em) + DO il = 1, nl + ndof = CD_System_Line_NDOF(coarse%sys%fast%system, il, es, em) + ALLOCATE (lq(ndof), lv(ndof), la(ndof)) + CALL CD_Get_System_Line_State(coarse%sys%fast%system, il, lq, lv, la, es, em) + CALL CD_Update_System_Line_Interior_State(agg_b%sys%fast%system, il, lq(4:ndof - 3), lv(4:ndof - 3), es, em, & + a_interior=la(4:ndof - 3)) + CALL require(es == CD_SYSTEM_OK, 'restart:interior: '//TRIM(em)) + DEALLOCATE (lq, lv, la) + END DO + CALL CD_AGG_Get_Rod_States(coarse, rs, es, em) + CALL CD_AGG_Set_Rod_States(agg_b, rs, es, em) + CALL require(es == CD_AGG_OK, 'restart:rod states: '//TRIM(em)) + ! the committed line-end motion closes the mirror (the shell restores it last) + ncd = CD_System_NSystemCoupledDOF(coarse%sys%fast%system) + ALLOCATE (cq(ncd), cvv(ncd), ca(ncd)) + CALL CD_Get_System_CoupledMotion(coarse%sys%fast%system, cq, cvv, ca, es, em) + CALL CD_Update_System_CoupledMotion(agg_b%sys%fast%system, cq, cvv, ca, es, em) + CALL require(es == CD_SYSTEM_OK, 'restart:coupled motion: '//TRIM(em)) + ! between steps (a supercycled host evaluates the restored state before the next step) the + ! pin force depends on the mirrored rod state only, not on the host pin it was stepped with + CALL CD_AGG_CalcOutput(coarse, es, em) + CALL CD_AGG_GetMovingPointMesh(coarse, p, v, a, f, es, em, moment=mo) + CALL CD_AGG_CalcOutput(agg_b, es, em) + CALL CD_AGG_GetMovingPointMesh(agg_b, p, v, a, fb, es, em, moment=mb) + WRITE (*, '(A,ES10.3)') 'CoupledPinned restart overlay: |pin force difference| before the next step = ', & + nan_max_abs(f - fb) + CALL require(nan_max_abs(f - fb) <= 0.0_wp .AND. nan_max_abs(mo - mb) <= 0.0_wp, & + 'restart:bit-identical loads of the restored state before the next step') + err = 0.0_wp + DO step = NC + 2, NC + 30 + k = host_surge(REAL(step, wp)*DTC) + p = p0 + v = 0.0_wp + a = 0.0_wp + p(:, n) = p0(:, n) + k(1:3) + v(:, n) = k(4:6) + a(:, n) = k(7:9) + CALL CD_AGG_Step_Moving(coarse, DTC, p, v, a, cv, st, it, es, em, t_committed=REAL(step, wp)*DTC) + CALL CD_AGG_Step_Moving(agg_b, DTC, p, v, a, cv, st, it, es, em, t_committed=REAL(step, wp)*DTC) + CALL require(es == CD_AGG_OK, 'restart:march: '//TRIM(em)) + CALL CD_AGG_CalcOutput(coarse, es, em) + CALL CD_AGG_GetMovingPointMesh(coarse, p, v, a, f, es, em, moment=mo) + CALL CD_AGG_CalcOutput(agg_b, es, em) + CALL CD_AGG_GetMovingPointMesh(agg_b, p, v, a, fb, es, em, moment=mb) + err = MAX(err, nan_max_abs(f - fb), nan_max_abs(mo - mb)) + END DO + CALL CD_AGG_Get_Rod_States(coarse, rs, es, em) + CALL CD_AGG_Get_Rod_States(agg_b, rs2, es, em) + WRITE (*, '(A,ES10.3)') 'CoupledPinned restart overlay: max |load difference| over 29 steps = ', err + CALL require(err <= 0.0_wp .AND. nan_max_abs(rs - rs2) <= 0.0_wp, 'restart:bit-identical continuation') + CALL CD_AGG_End(agg_b, es, em) + CALL CD_AGG_End(coarse, es, em) + END SUBROUTINE case_substep_and_state + + ! --------------------------------------------------------------------------------------------- ! + ! 7: the output probe ! + ! --------------------------------------------------------------------------------------------- ! + + SUBROUTINE case_probe() + !! On the hanging dry pendulum at rest, a probe pin acceleration a_p along x returns the + !! rest force plus -M_eff a_p with M_eff = m I_c/I_p (the rotation re-solved at a_p; the + !! committed angular acceleration would give -m a_p). On the tethered rod mid-swing, a + !! probe (pin moved, accelerated) restored as the coupled shell restores it (saved host + !! kinematics, line interiors, rod states, committed line-end motion) leaves the + !! continuation bit-identical to a twin that was never probed. + TYPE(CD_AGG_ModuleType) :: agg, twin + REAL(wp), ALLOCATABLE :: p(:, :), v(:, :), a(:, :), f(:, :), f0(:, :), mo(:, :), p0(:, :) + REAL(wp), ALLOCATABLE :: sp(:, :), sv(:, :), sa(:, :), so(:, :, :), sw(:, :), sal(:, :) + REAL(wp), ALLOCATABLE :: lq(:, :), lv(:, :), la(:, :), rs(:), rs2(:), fb(:, :), mb(:, :) + REAL(wp), ALLOCATABLE :: cq(:), cvv(:), ca(:), q2(:), v2(:), a2(:), l1(:), l2(:) + REAL(wp) :: ic, ip, ap, k(9), err, endb(3) + INTEGER :: es, n, step, it, nl, il, ndof, maxdof, ncd, ib + LOGICAL :: cv, st + CHARACTER(512) :: em + + CALL write_pendulum_deck('pinrod_probe.dat', 'CoupledPinned', 0.0_wp) + CALL CD_AGG_Init_From_Deck(agg, 'pinrod_probe.dat', 0.01_wp, es, em) + CALL require(es == CD_AGG_OK, 'probe:init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + n = CD_AGG_NMovingPoints(agg, es, em) + ALLOCATE (p(3, n), v(3, n), a(3, n), f(3, n), f0(3, n), mo(3, n), p0(3, n)) + CALL CD_AGG_CalcOutput(agg, es, em) + CALL CD_AGG_GetMovingPointMesh(agg, p0, v, a, f0, es, em) + ap = 1.5_wp + p = p0 + v = 0.0_wp + a = 0.0_wp + a(1, n) = ap + CALL CD_AGG_UpdateStates_Moving(agg, p, v, a, es, em, output_probe=.TRUE.) + CALL CD_AGG_CalcOutput(agg, es, em) + CALL CD_AGG_GetMovingPointMesh(agg, p, v, a, f, es, em, moment=mo) + ic = MP*(3.0_wp*(0.5_wp*DP)**2 + LP*LP)/12.0_wp + ip = ic + MP*(0.5_wp*LP)**2 + WRITE (*, '(A,F10.4,A,F10.4,A,F10.4)') 'probe pin acceleration: dF_x got ', f(1, n) - f0(1, n), & + ' N; -m (I_c/I_p) a_p ', -MP*ic/ip*ap, ' N; -m a_p ', -MP*ap + CALL require(ABS(f(1, n) - f0(1, n) + MP*ic/ip*ap) <= 1.0e-10_wp*MP*G, 'probe:-M_eff a_p (re-solved rotation)') + CALL require(nan_max_abs(f(2:3, n) - f0(2:3, n)) <= 1.0e-10_wp*MP*G .AND. nan_max_abs(mo(:, n)) <= 0.0_wp, & + 'probe:no other force change, zero moment') + CALL CD_AGG_End(agg, es, em) + + ! state-const probe on the tethered rod + CALL write_tethered_deck('pinrod_probe_tether.dat', 'CoupledPinned', 'deck') + CALL CD_AGG_Init_From_Deck(agg, 'pinrod_probe_tether.dat', 0.02_wp, es, em) + CALL CD_AGG_Init_From_Deck(twin, 'pinrod_probe_tether.dat', 0.02_wp, es, em) + CALL require(es == CD_AGG_OK, 'probe:tether init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + DEALLOCATE (p, v, a, f, mo, p0) + n = CD_AGG_NMovingPoints(agg, es, em) + ALLOCATE (p(3, n), v(3, n), a(3, n), f(3, n), mo(3, n), p0(3, n), fb(3, n), mb(3, n)) + ALLOCATE (sp(3, n), sv(3, n), sa(3, n), so(3, 3, n), sw(3, n), sal(3, n)) + ALLOCATE (rs(CD_AGG_Rod_MirrorSize(agg)), rs2(CD_AGG_Rod_MirrorSize(agg))) + CALL CD_AGG_GetMovingPointMesh(agg, p0, v, a, f, es, em) + err = 0.0_wp + DO step = 1, 40 + k = host_surge(REAL(step, wp)*0.02_wp) + p = p0 + v = 0.0_wp + a = 0.0_wp + p(:, n) = p0(:, n) + k(1:3) + v(:, n) = k(4:6) + a(:, n) = k(7:9) + CALL CD_AGG_Step_Moving(agg, 0.02_wp, p, v, a, cv, st, it, es, em, t_committed=REAL(step, wp)*0.02_wp) + CALL CD_AGG_Step_Moving(twin, 0.02_wp, p, v, a, cv, st, it, es, em, t_committed=REAL(step, wp)*0.02_wp) + CALL require(es == CD_AGG_OK, 'probe:march: '//TRIM(em)) + IF (step /= 20) CYCLE + ! the shell's probe: save the committed host kinematics and the state mirror, overlay, evaluate + CALL CD_AGG_GetMovingPointMesh(agg, sp, sv, sa, f, es, em, orientation=so, angular_velocity=sw, & + angular_acceleration=sal) + CALL CD_AGG_Get_Rod_States(agg, rs, es, em) + nl = CD_System_NLines(agg%sys%fast%system, es, em) + maxdof = 0 + DO il = 1, nl + maxdof = MAX(maxdof, CD_System_Line_NDOF(agg%sys%fast%system, il, es, em)) + END DO + ALLOCATE (lq(maxdof, nl), lv(maxdof, nl), la(maxdof, nl)) + DO il = 1, nl + ndof = CD_System_Line_NDOF(agg%sys%fast%system, il, es, em) + CALL CD_Get_System_Line_State(agg%sys%fast%system, il, lq(1:ndof, il), lv(1:ndof, il), la(1:ndof, il), es, em) + END DO + ncd = CD_System_NSystemCoupledDOF(agg%sys%fast%system) + ALLOCATE (cq(ncd), cvv(ncd), ca(ncd)) + CALL CD_Get_System_CoupledMotion(agg%sys%fast%system, cq, cvv, ca, es, em) + p(1, n) = p(1, n) + 0.3_wp + a(1, n) = a(1, n) + 4.0_wp + v(1, n) = v(1, n) - 0.5_wp + CALL CD_AGG_UpdateStates_Moving(agg, p, v, a, es, em, output_probe=.TRUE.) + CALL require(es == CD_AGG_OK, 'probe:overlay: '//TRIM(em)) + CALL CD_AGG_CalcOutput(agg, es, em) + CALL CD_AGG_GetMovingPointMesh(agg, p, v, a, f, es, em, moment=mo) + CALL require(ALL(IEEE_IS_FINITE(f)) .AND. nan_max_abs(mo(:, n)) <= 0.0_wp, 'probe:finite force, zero moment') + ! The tethers load End B with their end-node inertia at the end acceleration the system + ! holds (the probe pin with the committed rotation). Give that end another acceleration: + ! its line load changes, the pin force does not (the inertia is moved to the re-solved + ! rotation exactly). + CALL CD_AGG_Get_Rod_States(agg, rs2, es, em) + endb = rs2(1:3) + rs2(16:18) + ALLOCATE (q2(ncd), v2(ncd), a2(ncd), l1(ncd), l2(ncd)) + CALL CD_Get_System_CoupledMotion(agg%sys%fast%system, q2, v2, a2, es, em) + ib = 0 + DO il = 1, ncd/3 + IF (nan_max_abs(q2(3*il - 2:3*il) - endb) <= 1.0e-9_wp) ib = il + END DO + CALL require(ib > 0, 'probe:End B is a coupled point of the line system') + IF (ib > 0) THEN + CALL CD_Calc_System_CoupledLoads(agg%sys%fast%system, l1, es, em) + a2(3*ib - 2:3*ib) = a2(3*ib - 2:3*ib) + [3.0_wp, -2.0_wp, 1.0_wp] + CALL CD_Update_System_CoupledMotion(agg%sys%fast%system, q2, v2, a2, es, em) + CALL require(es == CD_SYSTEM_OK, 'probe:end acceleration: '//TRIM(em)) + CALL CD_Calc_System_CoupledLoads(agg%sys%fast%system, l2, es, em) + CALL CD_AGG_CalcOutput(agg, es, em) + CALL CD_AGG_GetMovingPointMesh(agg, p, v, a, fb, es, em, moment=mb) + WRITE (*, '(A,ES10.3,A,ES10.3,A)') 'probe with another End B acceleration: line load change ', & + nan_max_abs(l2(3*ib - 2:3*ib) - l1(3*ib - 2:3*ib)), ' N, pin force change ', & + nan_max_abs(fb(:, n) - f(:, n)), ' N' + CALL require(nan_max_abs(l2(3*ib - 2:3*ib) - l1(3*ib - 2:3*ib)) > 1.0_wp, & + 'probe:the End B line load carries the end acceleration') + CALL require(nan_max_abs(fb(:, n) - f(:, n)) <= 1.0e-9_wp*nan_max_abs(f(:, n)) .AND. & + nan_max_abs(mb(:, n)) <= 0.0_wp, 'probe:pin force independent of the held end acceleration') + END IF + DEALLOCATE (q2, v2, a2, l1, l2) + CALL CD_AGG_UpdateStates_Moving(agg, sp, sv, sa, es, em, output_probe=.TRUE., orientation=so, & + angular_velocity=sw, angular_acceleration=sal) + DO il = 1, nl + ndof = CD_System_Line_NDOF(agg%sys%fast%system, il, es, em) + CALL CD_Update_System_Line_Interior_State(agg%sys%fast%system, il, lq(4:ndof - 3, il), lv(4:ndof - 3, il), & + es, em, a_interior=la(4:ndof - 3, il)) + END DO + CALL CD_AGG_Set_Rod_States(agg, rs, es, em) + CALL require(es == CD_AGG_OK, 'probe:restore: '//TRIM(em)) + CALL CD_Update_System_CoupledMotion(agg%sys%fast%system, cq, cvv, ca, es, em) + CALL require(es == CD_SYSTEM_OK, 'probe:coupled motion: '//TRIM(em)) + CALL CD_AGG_Get_Rod_States(agg, rs2, es, em) + CALL require(nan_max_abs(rs2 - rs) <= 0.0_wp, 'probe:rod state restored bit-identically') + END DO + ! continuation after the probe: compare the steps 21-40 (already marched) at the end state + CALL CD_AGG_CalcOutput(agg, es, em) + CALL CD_AGG_GetMovingPointMesh(agg, p, v, a, f, es, em, moment=mo) + CALL CD_AGG_CalcOutput(twin, es, em) + CALL CD_AGG_GetMovingPointMesh(twin, p, v, a, fb, es, em, moment=mb) + CALL CD_AGG_Get_Rod_States(agg, rs, es, em) + CALL CD_AGG_Get_Rod_States(twin, rs2, es, em) + CALL require(nan_max_abs(f - fb) <= 0.0_wp .AND. nan_max_abs(mo - mb) <= 0.0_wp .AND. & + nan_max_abs(rs - rs2) <= 0.0_wp, 'probe:state-const (probed run equals the twin bit for bit)') + CALL CD_AGG_End(agg, es, em) + CALL CD_AGG_End(twin, es, em) + END SUBROUTINE case_probe + + ! --------------------------------------------------------------------------------------------- ! + ! 9: PtfmInit and the static initial condition ! + ! --------------------------------------------------------------------------------------------- ! + + SUBROUTINE case_ptfm_static() + !! PtfmInit (surge 1 m, sway 0.5 m, yaw 10 deg) moves the pin and the rod rigidly with the + !! platform before the static solve, which then turns the rod about its pin against the + !! now unequal tethers: the pin is the displaced End A, the rod's net moment about it + !! vanishes, the host node carries the rod's net force and no moment, and the rod starts + !! at rest. + TYPE(CD_AGG_ModuleType) :: agg + REAL(wp), ALLOCATABLE :: p(:, :), v(:, :), a(:, :), f(:, :), mo(:, :) + REAL(wp) :: ptfm(6), dcm(3, 3), pin(3), s(24), ch(6), cz, sz, tilt, fsc + INTEGER :: es, n, i + CHARACTER(512) :: em + + CALL write_tethered_deck('pinrod_ptfm.dat', 'CoupledPinned', 'static') + ptfm = [1.0_wp, 0.5_wp, 0.0_wp, 0.0_wp, 0.0_wp, 10.0_wp*PI/180.0_wp] + CALL CD_AGG_Init_From_Deck(agg, 'pinrod_ptfm.dat', 0.02_wp, es, em, ptfm_init=ptfm) + CALL require(es == CD_AGG_OK, 'ptfm:init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + n = CD_AGG_NMovingPoints(agg, es, em) + ALLOCATE (p(3, n), v(3, n), a(3, n), f(3, n), mo(3, n)) + cz = COS(ptfm(6)) + sz = SIN(ptfm(6)) + dcm = 0.0_wp + dcm(1, 1) = cz + dcm(1, 2) = sz + dcm(2, 1) = -sz + dcm(2, 2) = cz + dcm(3, 3) = 1.0_wp + pin = ptfm(1:3) + MATMUL(TRANSPOSE(dcm), [0.0_wp, 0.0_wp, -10.0_wp]) + CALL CD_AGG_CalcOutput(agg, es, em) + CALL CD_AGG_GetMovingPointMesh(agg, p, v, a, f, es, em, moment=mo) + CALL CD_AGG_Get_Rod_States(agg, s, es, em) + DO i = 1, 6 + CALL CD_AGG_EvalChannel(agg, i, ch(i), es, em) + END DO + tilt = ACOS(MIN(1.0_wp, -s(18))) + fsc = nan_max_abs(ch(1:3)) + WRITE (*, '(A,ES10.3,A,F8.4,A,ES10.3,A,ES10.3)') 'PtfmInit + static IC: |pin - displaced End A| ', & + nan_max_abs(p(:, n) - pin), '; rod tilt ', tilt, ' rad; |Rod1M| ', nan_max_abs(ch(4:6)), & + ' N m; |host force - Rod1F| ', nan_max_abs(f(:, n) - ch(1:3)) + CALL require(nan_max_abs(p(:, n) - pin) <= 1.0e-12_wp, 'ptfm:pin at the displaced End A') + CALL require(nan_max_abs(s(1:3) - 1.0_wp*s(16:18) - pin) <= 1.0e-12_wp, 'ptfm:rod End A on the pin') + CALL require(tilt > 1.0e-3_wp, 'ptfm:the static solve turned the rod') + CALL require(nan_max_abs(ch(4:6)) <= 1.0e-6_wp*fsc*2.0_wp, 'ptfm:net moment about the pin vanishes') + CALL require(nan_max_abs(f(:, n) - ch(1:3)) <= 1.0e-8_wp*fsc .AND. nan_max_abs(mo(:, n)) <= 0.0_wp, & + 'ptfm:host force is the net rod load, no moment') + CALL CD_AGG_End(agg, es, em) + END SUBROUTINE case_ptfm_static + + ! --------------------------------------------------------------------------------------------- ! + ! 11-12: a step without the staged rods, and rod ends without a point ! + ! --------------------------------------------------------------------------------------------- ! + + SUBROUTINE case_unstaged_step() + !! The rod march of a CoupledPinned rod needs no staged copy of the step-start rods: the rod + !! state carries its step-start pin. One instance marches through CD_AGG_Step_Moving (which + !! stages the rods and passes them on); its twin takes the t + dt pin through + !! CD_Rod_SetHostKinematics and steps with CD_Step_Aggregate_Rod alone (no staged rods, no + !! host overlay: the independent fairlead stays where the start transfer put it). Over the + !! first step (the start-acceleration solve with the pin at its step-start pose) and the + !! sub-cycled steps after it (the pin interpolated from its step start), the two are + !! bit-identical under a harmonic pin surge, whose acceleration differs between step start + !! and end. + TYPE(CD_AGG_ModuleType) :: staged, bare + REAL(wp), PARAMETER :: DTC = 0.1_wp + REAL(wp), ALLOCATABLE :: p(:, :), v(:, :), a(:, :), f(:, :), p0(:, :), rs(:), rs2(:) + REAL(wp), ALLOCATABLE :: cq(:), cvv(:), ca(:), cq2(:), cvv2(:), ca2(:) + REAL(wp) :: k(9), err, t + INTEGER :: es, n, step, it, ncd + LOGICAL :: cv, st + CHARACTER(512) :: em + + CALL write_tethered_deck('pinrod_unstaged.dat', 'CoupledPinned', 'deck') + CALL CD_AGG_Init_From_Deck(staged, 'pinrod_unstaged.dat', DTC, es, em) + CALL require(es == CD_AGG_OK, 'unstaged:init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + CALL CD_AGG_Init_From_Deck(bare, 'pinrod_unstaged.dat', DTC, es, em) + n = CD_AGG_NMovingPoints(staged, es, em) + ALLOCATE (p(3, n), v(3, n), a(3, n), f(3, n), p0(3, n)) + ALLOCATE (rs(CD_AGG_Rod_MirrorSize(staged)), rs2(CD_AGG_Rod_MirrorSize(staged))) + ncd = CD_System_NSystemCoupledDOF(staged%sys%fast%system) + ALLOCATE (cq(ncd), cvv(ncd), ca(ncd), cq2(ncd), cvv2(ncd), ca2(ncd)) + CALL CD_AGG_GetMovingPointMesh(staged, p0, v, a, f, es, em) + err = 0.0_wp + DO step = 0, 20 + t = REAL(step, wp)*DTC + k = host_surge(t) + p = p0 + v = 0.0_wp + a = 0.0_wp + p(:, n) = p0(:, n) + k(1:3) + v(:, n) = k(4:6) + a(:, n) = k(7:9) + IF (step == 0) THEN + CALL CD_AGG_UpdateStates_Moving(staged, p, v, a, es, em) + CALL CD_AGG_UpdateStates_Moving(bare, p, v, a, es, em) + CALL require(es == CD_AGG_OK, 'unstaged:start transfer: '//TRIM(em)) + CYCLE + END IF + CALL CD_AGG_Step_Moving(staged, DTC, p, v, a, cv, st, it, es, em, t_committed=t) + CALL require(es == CD_AGG_OK, 'unstaged:staged step: '//TRIM(em)) + CALL CD_Rod_SetHostKinematics(bare%rod, p(:, n:n), v(:, n:n), a(:, n:n), es, em) + CALL require(es == CD_DECKDRV_OK, 'unstaged:pin transfer: '//TRIM(em)) + CALL CD_Step_Aggregate_Rod(bare%sys%fast%system, bare%rod, t - DTC, DTC, cv, st, it, es, em) + CALL require(es == CD_DECKDRV_OK, 'unstaged:bare step: '//TRIM(em)) + IF (es /= CD_DECKDRV_OK) EXIT + CALL CD_AGG_Get_Rod_States(staged, rs, es, em) + CALL CD_AGG_Get_Rod_States(bare, rs2, es, em) + CALL CD_Get_System_CoupledMotion(staged%sys%fast%system, cq, cvv, ca, es, em) + CALL CD_Get_System_CoupledMotion(bare%sys%fast%system, cq2, cvv2, ca2, es, em) + err = MAX(err, nan_max_abs(rs - rs2), nan_max_abs(cq - cq2), nan_max_abs(cvv - cvv2), nan_max_abs(ca - ca2)) + END DO + WRITE (*, '(A,ES10.3,A,ES10.3,A)') 'CoupledPinned step without staged rods: max |state difference| = ', err, & + ' (rod turned ', ABS(rod_angle(rs)), ' rad)' + CALL require(err <= 0.0_wp, 'unstaged:the step-start pin needs no staged rods (bit-identical)') + CALL require(ABS(rod_angle(rs)) > 1.0e-3_wp, 'unstaged:the pin motion turns the rod') + CALL CD_AGG_End(staged, es, em) + CALL CD_AGG_End(bare, es, em) + END SUBROUTINE case_unstaged_step + + ! --------------------------------------------------------------------------------------------- ! + ! 13: a pinned rod without a line sub-cycles its own swing ! + ! --------------------------------------------------------------------------------------------- ! + + FUNCTION host_rest(time) RESULT(k) + !! A host node held at its initial position. + REAL(wp), INTENT(IN) :: time + REAL(wp) :: k(9) + k = 0.0_wp*time + END FUNCTION host_rest + + SUBROUTINE case_lineless_swing_substep() + !! A 1 m Pinned rod that carries no line, released at 30 degrees: (1) dry, hanging from a pin + !! above the water, omega0^2 = m g (L/2)/I_p, about 14.6 rad^2/s^2; (2) submerged and buoyant + !! (10 kg/m against 32.2 kg/m of displaced water), standing up from a pin at z = -15 m (out of + !! the surface's reach), + !! omega0^2 = (B - W)(L/2)/I_p, about 32.4 rad^2/s^2. At a 0.6 s coupling step omega0 dt is + !! 2.29 and 3.42, beyond the explicit limit of 2, and the sub-step estimate (the swing + !! stiffness |W d_g - B d_b| over the inertia about the pin) asks for 6 and 9 sub-steps + !! (omega0 dt/0.4 = 5.73 and 8.54). The coarse run must equal a run at that sub-step size at + !! every coupling step (so it took those sub-steps; taking each step whole, it departs by + !! radians and turns over), stay within its release angle, and swing + !! with the elliptic-integral period of the compound pendulum to the accuracy of + !! omega0 dt_sub, about 0.38 (a central-difference period error near (omega dt)^2/24 = 0.6 %). + TYPE(CD_AGG_ModuleType) :: coarse, fine + REAL(wp), PARAMETER :: DTC = 0.6_wp, TH0 = 30.0_wp, ZW = -15.0_wp + INTEGER, PARAMETER :: NC = 30, NSUBS(2) = [6, 9] + REAL(wp), ALLOCATABLE :: angc(:), tc(:), angf(:), tf(:) + REAL(wp) :: mpm, ip, kswing, t_ref, period, mean, err_ang, amp, rel + INTEGER :: es, i, kase, nsub + LOGICAL :: ok + CHARACTER(512) :: em + + DO kase = 1, 2 + nsub = NSUBS(kase) + IF (kase == 1) THEN + mpm = 50.0_wp + CALL write_short_pendulum_deck('pinrod_short.dat', mpm, ZPIN, .FALSE., TH0) + kswing = mpm*G*0.5_wp + ELSE + mpm = 10.0_wp + CALL write_short_pendulum_deck('pinrod_short.dat', mpm, ZW, .TRUE., TH0) + kswing = (1025.0_wp*0.25_wp*PI*DP*DP - mpm)*G*0.5_wp + END IF + ip = mpm*(1.0_wp/3.0_wp + DP*DP/16.0_wp) + t_ref = 4.0_wp*SQRT(ip/kswing)*ellip_k(SIN(0.5_wp*TH0*PI/180.0_wp)) + CALL CD_AGG_Init_From_Deck(coarse, 'pinrod_short.dat', DTC, es, em) + CALL require(es == CD_AGG_OK, 'lineless:coarse-init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + CALL CD_AGG_Init_From_Deck(fine, 'pinrod_short.dat', DTC/REAL(nsub, wp), es, em) + CALL require(es == CD_AGG_OK, 'lineless:fine-init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + ALLOCATE (angc(0:NC), tc(0:NC), angf(0:NC*nsub), tf(0:NC*nsub)) + CALL march(coarse, DTC, NC, host_rest, angc, tc, ok) + CALL require(ok, 'lineless:coarse march finite (the swing is sub-cycled)') + CALL march(fine, DTC/REAL(nsub, wp), NC*nsub, host_rest, angf, tf, ok) + CALL require(ok, 'lineless:fine march finite') + IF (.NOT. ok) RETURN + ! rod_angle is measured from the downward vertical: the upright rod's angle from the + ! upward one is pi - rod_angle, wrapped to (-pi, pi] + IF (kase == 2) THEN + angc = MODULO(2.0_wp*PI - angc, 2.0_wp*PI) - PI + angf = MODULO(2.0_wp*PI - angf, 2.0_wp*PI) - PI + END IF + err_ang = 0.0_wp + DO i = 0, NC + err_ang = MAX(err_ang, ABS(angc(i) - angf(nsub*i))) + END DO + amp = MAX(nan_max_abs(angc), nan_max_abs(angf)) + CALL crossings(tf, angf, 0.0_wp, period, mean) + rel = ABS(period - t_ref)/t_ref + WRITE (*, '(A,I0,A,ES10.3,A,F8.5,A,2F10.6,A,ES10.3)') 'lineless pinned swing (', kase, & + '): coarse vs sub-step run ', err_ang, ' rad; max angle/release ', amp/(TH0*PI/180.0_wp), & + '; period got/analytic [s] ', period, t_ref, '; rel. error ', rel + CALL require(err_ang <= 1.0e-8_wp*amp, 'lineless:coarse step equals its sub-step run') + CALL require(amp <= 1.02_wp*TH0*PI/180.0_wp, 'lineless:the swing stays within its release angle') + CALL require(rel <= 1.5e-2_wp, 'lineless:period (elliptic integral)') + DEALLOCATE (angc, tc, angf, tf) + CALL CD_AGG_End(coarse, es, em) + CALL CD_AGG_End(fine, es, em) + END DO + END SUBROUTINE case_lineless_swing_substep + + ! --------------------------------------------------------------------------------------------- ! + ! 14: a host pin crossing the free surface within one coupling step ! + ! --------------------------------------------------------------------------------------------- ! + + FUNCTION host_rise(time) RESULT(k) + !! The pin rising at a constant 12 m/s from t = 0. + REAL(wp), INTENT(IN) :: time + REAL(wp) :: k(9) + k = 0.0_wp + k(3) = 12.0_wp*time + k(6) = 12.0_wp + END FUNCTION host_rise + + FUNCTION host_sink(time) RESULT(k) + !! The pin sinking at a constant 2 m/s from t = 0. + REAL(wp), INTENT(IN) :: time + REAL(wp) :: k(9) + k = 0.0_wp + k(3) = -2.0_wp*time + k(6) = -2.0_wp + END FUNCTION host_sink + + SUBROUTINE case_surface_crossing_pin() + !! A 1 m CoupledPinned rod without a line whose host pin crosses the free surface in one + !! coupling step at constant velocity, which the linear interpolation of the pin inside the + !! step represents exactly. The march sizes its sub-steps after the host has placed the pin at + !! the end of the step, so the swing estimate must also take the step-start wetting: + !! (1) a light rod (1 kg/m against 32.2 kg/m of displaced water) standing up from a pin at + !! z = -1.1 m that rises at 12 m/s, fully submerged at the start of a 0.1 s step and dry + !! at its end: omega^2 = (B - W)(L/2)/I_p = 456 rad^2/s^2 at the start (omega dt = 2.13, + !! beyond the explicit limit of 2) but 14.6 at the end, which alone asks for one + !! sub-step; the start wetting asks for 6 (omega dt/0.4 = 5.34); + !! (2) a rod just heavier than water (33 kg/m) hanging from a pin at z = 1 m that sinks at + !! 2 m/s, dry at the start of a 0.6 s step and submerged at its end: 14.6 rad^2/s^2 at the + !! start (omega dt = 2.29) against 0.354 at the end; the start asks for 6 (5.73). + !! The crossing step must stay within 5e-3 rad and 1 % of the rod state of a run at a sixtieth + !! of the step (the wetting along the step is bounded by its two ends; near the surface the + !! waterplane term of the estimate adds sub-steps beyond these). + TYPE(CD_AGG_ModuleType) :: coarse, fine + INTEGER, PARAMETER :: NSUB = 60 + REAL(wp) :: angc(0:1), tc(0:1), angf(0:NSUB), tf(0:NSUB), sc(24), sf(24), dtc, err_ang, err_s + INTEGER :: es, kase + LOGICAL :: ok + CHARACTER(512) :: em + + DO kase = 1, 2 + IF (kase == 1) THEN + dtc = 0.1_wp + CALL write_short_pendulum_deck('pinrod_cross.dat', 1.0_wp, -1.1_wp, .TRUE., 10.0_wp, 'CoupledPinned') + ELSE + dtc = 0.6_wp + CALL write_short_pendulum_deck('pinrod_cross.dat', 33.0_wp, 1.0_wp, .FALSE., 30.0_wp, 'CoupledPinned') + END IF + CALL CD_AGG_Init_From_Deck(coarse, 'pinrod_cross.dat', dtc, es, em) + CALL require(es == CD_AGG_OK, 'cross:coarse-init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + CALL CD_AGG_Init_From_Deck(fine, 'pinrod_cross.dat', dtc/REAL(NSUB, wp), es, em) + CALL require(es == CD_AGG_OK, 'cross:fine-init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + IF (kase == 1) THEN + CALL march(coarse, dtc, 1, host_rise, angc, tc, ok, s_end=sc) + CALL require(ok, 'cross:coarse march finite') + CALL march(fine, dtc/REAL(NSUB, wp), NSUB, host_rise, angf, tf, ok, s_end=sf) + ELSE + CALL march(coarse, dtc, 1, host_sink, angc, tc, ok, s_end=sc) + CALL require(ok, 'cross:coarse march finite') + CALL march(fine, dtc/REAL(NSUB, wp), NSUB, host_sink, angf, tf, ok, s_end=sf) + END IF + CALL require(ok, 'cross:fine march finite') + IF (.NOT. ok) RETURN + err_ang = ABS(angc(1) - angf(NSUB)) + err_s = nan_max_abs(sc - sf)/MAX(1.0_wp, nan_max_abs(sf)) + WRITE (*, '(A,I0,A,ES10.3,A,F9.5,A,ES10.3)') 'surface-crossing pin (', kase, & + '): crossing step vs dt/60 run: angle ', err_ang, ' of ', angf(NSUB), ' rad; rod state ', err_s + CALL require(err_ang <= 5.0e-3_wp .AND. err_s <= 1.0e-2_wp, 'cross:crossing step follows the fine run') + CALL CD_AGG_End(coarse, es, em) + CALL CD_AGG_End(fine, es, em) + END DO + END SUBROUTINE case_surface_crossing_pin + + ! --------------------------------------------------------------------------------------------- ! + ! 15: seabed contact at a large coupling step ! + ! --------------------------------------------------------------------------------------------- ! + + SUBROUTINE write_seabed_rod_deck(path, rod_type) + !! A rod (D = 0.2 m, 50 kg/m, no drag or added mass) on a stiff seabed at z = -10 m (kBot + !! 1e7 N/m^3): a 1 m Pinned rod from a pin at (0, 0, -9.5) whose End B rests on the bed at + !! 30 degrees below the horizontal, or a 2 m Free rod lying on the bed from x = 0 to 2, held + !! by two lightly taut tethers to anchors 1 m above the bed. The fairlead line of + !! write_pendulum_deck keeps a mooring system in the deck. + CHARACTER(*), INTENT(IN) :: path, rod_type + INTEGER :: u + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'rod on a stiff seabed on the coupled aggregate' + WRITE (u, '(A)') '--- LINE TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass EA BA EI Cdn Cdt Can Cat' + WRITE (u, '(A)') '(-) (m) (kg/m) (N) (-) (Nm2) (-) (-) (-) (-)' + WRITE (u, '(A)') 'line 0.10 80.0 1.0e6 0.0 0.0 1.0 0.0 1.0 0.0' + WRITE (u, '(A)') 'tether 0.05 4.0 2.0e5 0.0 0.0 1.0 0.0 1.0 0.0' + WRITE (u, '(A)') '--- ROD TYPES ---' + WRITE (u, '(A)') 'Name Diam Mass Cd Ca CdEnd CaEnd' + WRITE (u, '(A)') '(-) (m) (kg/m) (-) (-) (-) (-)' + WRITE (u, '(A)') 'bar 0.2 50 0 0 0 0' + WRITE (u, '(A)') '--- RODS ---' + WRITE (u, '(A)') 'ID RodType Type XA YA ZA XB YB ZB NumSegs Outputs' + WRITE (u, '(A)') '(-) (-) (-) (m) (m) (m) (m) (m) (m) (-) (-)' + IF (rod_type == 'Free') THEN + WRITE (u, '(A)') '1 bar Free 0 0 -10 2 0 -10 4 -' + ELSE + WRITE (u, '(A,ES24.16,A)') '1 bar Pinned 0 0 -9.5 ', SQRT(0.75_wp), ' 0 -10 4 -' + END IF + WRITE (u, '(A)') '--- POINTS ---' + WRITE (u, '(A)') 'ID Type X Y Z Mass Vol CdA Ca' + WRITE (u, '(A)') '(-) (-) (m) (m) (m) (kg) (m3) (m2) (-)' + WRITE (u, '(A)') '1 Coupled 0.0 30.0 -1.0 0 0 0 0' + WRITE (u, '(A)') '2 Fixed 6.0 30.0 -8.0 0 0 0 0' + IF (rod_type == 'Free') THEN + WRITE (u, '(A)') '3 Fixed -5.0 0 -9 0 0 0 0' + WRITE (u, '(A)') '4 Fixed 7.0 0 -9 0 0 0 0' + END IF + WRITE (u, '(A)') '--- LINES ---' + WRITE (u, '(A)') 'ID NodeA NodeB Outputs' + WRITE (u, '(A)') '(-) (-) (-) (-)' + WRITE (u, '(A)') '1 1 2 -' + IF (rod_type == 'Free') THEN + WRITE (u, '(A)') '2 R1A 3 -' + WRITE (u, '(A)') '3 R1B 4 -' + END IF + WRITE (u, '(A)') '--- SECTIONS ---' + WRITE (u, '(A)') 'LineID LineType Length NumSegs' + WRITE (u, '(A)') '(-) (-) (m) (-)' + WRITE (u, '(A)') '1 line 9.5 6' + IF (rod_type == 'Free') THEN + WRITE (u, '(A)') '2 tether 5.09 10' + WRITE (u, '(A)') '3 tether 5.09 10' + END IF + WRITE (u, '(A)') '--- OPTIONS ---' + WRITE (u, '(A)') '9.80665 g' + WRITE (u, '(A)') '1025.0 rhoW' + WRITE (u, '(A)') '10.0 WtrDpth' + WRITE (u, '(A)') '1.0e7 kBot' + WRITE (u, '(A)') 'deck bodyIC' + WRITE (u, '(A)') '--- end ---' + CLOSE (u) + END SUBROUTINE write_seabed_rod_deck + + SUBROUTINE case_seabed_contact_substep() + !! The contact springs kBot d dl of the rod stations on the bed are far stiffer than the rod's + !! other restoring: (1) the Pinned rod's End B station alone, 5e4 N/m at 0.87 m horizontally + !! from the pin, gives omega^2 about 2e3 rad^2/s^2 about the pin (omega dt about 4.7 at a + !! 0.1 s step; the stations within reach of the bed over the step ask for 34 to 36 + !! sub-steps) against 5 from its submerged weight; (2) the Free rod's 21 stations, 4e6 N/m in + !! all on 100 kg, give omega^2 about 4e4 in heave (omega dt about 10 at a 0.05 s step, 26 + !! sub-steps) against about 800 from its tethers (4 sub-steps). The march must sub-cycle the + !! contact mode: over 5 s each rod stays at rest on the bed (its static settlement is below + !! 2 mm) and ends where a run at a tenth of the step ends; with the sub-steps of its other + !! restoring alone it is thrown off the bed. + TYPE(CD_AGG_ModuleType) :: coarse, fine + REAL(wp), ALLOCATABLE :: angc(:), tc(:), angf(:), tf(:) + REAL(wp) :: sc(24), sf(24), dtc, dev, err_end + INTEGER :: es, kase, nc + LOGICAL :: ok + CHARACTER(512) :: em + CHARACTER(8) :: kind + + DO kase = 1, 2 + IF (kase == 1) THEN + kind = 'Pinned' + dtc = 0.1_wp + ELSE + kind = 'Free' + dtc = 0.05_wp + END IF + nc = NINT(5.0_wp/dtc) + CALL write_seabed_rod_deck('pinrod_seabed.dat', TRIM(kind)) + CALL CD_AGG_Init_From_Deck(coarse, 'pinrod_seabed.dat', dtc, es, em) + CALL require(es == CD_AGG_OK, 'seabed:coarse-init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + CALL CD_AGG_Init_From_Deck(fine, 'pinrod_seabed.dat', 0.1_wp*dtc, es, em) + CALL require(es == CD_AGG_OK, 'seabed:fine-init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + ALLOCATE (angc(0:nc), tc(0:nc), angf(0:10*nc), tf(0:10*nc)) + CALL march(coarse, dtc, nc, host_rest, angc, tc, ok, s_end=sc) + CALL require(ok, 'seabed:'//TRIM(kind)//' coarse march finite (the contact mode is sub-cycled)') + IF (.NOT. ok) RETURN + CALL march(fine, 0.1_wp*dtc, 10*nc, host_rest, angf, tf, ok, s_end=sf) + CALL require(ok, 'seabed:'//TRIM(kind)//' fine march finite') + IF (.NOT. ok) RETURN + dev = nan_max_abs(angc - angc(0)) + err_end = MAX(ABS(angc(nc) - angf(10*nc)), nan_max_abs(sc(1:3) - sf(1:3))) + WRITE (*, '(A,A,A,ES10.3,A,ES10.3,A,ES10.3)') 'rod on a stiff seabed (', TRIM(kind), & + '): max angle change ', dev, ' rad; centre depth ', sc(3), '; end state vs dt/10 ', err_end + CALL require(dev <= 1.0e-2_wp .AND. ABS(sc(3) - MERGE(-9.75_wp, -10.0_wp, kase == 1)) <= 1.0e-2_wp, & + 'seabed:'//TRIM(kind)//' rod stays at rest on the bed') + CALL require(err_end <= 1.0e-4_wp, 'seabed:'//TRIM(kind)//' ends as the dt/10 run') + DEALLOCATE (angc, tc, angf, tf) + CALL CD_AGG_End(coarse, es, em) + CALL CD_AGG_End(fine, es, em) + END DO + END SUBROUTINE case_seabed_contact_substep + + SUBROUTINE case_bare_rod_ends() + !! On the coupled route only a Pinned or CoupledPinned rod may leave an end without a line or + !! RodA/B POINT row (its pin holds it): the tethered deck, whose rod carries no line at End + !! A, initialises with a Pinned or CoupledPinned rod and is refused with a Free or Coupled + !! one, as before this release. + TYPE(CD_AGG_ModuleType) :: agg + CHARACTER(16), PARAMETER :: KINDS(4) = [CHARACTER(16) :: 'Pinned', 'CoupledPinned', 'Free', 'Coupled'] + INTEGER :: es, i + CHARACTER(512) :: em + DO i = 1, 4 + CALL write_tethered_deck('pinrod_bare.dat', TRIM(KINDS(i)), 'deck') + CALL CD_AGG_Init_From_Deck(agg, 'pinrod_bare.dat', 0.02_wp, es, em) + IF (i <= 2) THEN + CALL require(es == CD_AGG_OK, 'bare-end:'//TRIM(KINDS(i))//' rod accepted: '//TRIM(em)) + ELSE + CALL require(es /= CD_AGG_OK .AND. INDEX(em, 'requires RodA and RodB points') > 0 .AND. & + INDEX(em, 'Rod1A') > 0, 'bare-end:'//TRIM(KINDS(i))//' rod refused: '//TRIM(em)) + END IF + CALL CD_AGG_End(agg, es, em) + END DO + END SUBROUTINE case_bare_rod_ends + + ! --------------------------------------------------------------------------------------------- ! + ! 10: no coupled host ! + ! --------------------------------------------------------------------------------------------- ! + + SUBROUTINE case_standalone_refusal() + !! The standalone driver has no host to move the pin: a CoupledPinned (or VesselPinned) rod + !! is refused by name, including a zero-length one. + LOGICAL :: conv + INTEGER :: es, ns + CHARACTER(512) :: em + DO ns = 0, 4, 4 + CALL write_pendulum_deck('pinrod_standalone.dat', 'VesselPinned', 10.0_wp, standalone=.TRUE., nsegs=ns) + CALL CD_Run_Deck_Driver('pinrod_standalone.dat', 'pinrod_standalone', conv, es, em) + CALL require(es /= CD_DECKDRV_OK .AND. INDEX(em, 'requires a coupled host') > 0, & + 'standalone:CoupledPinned refused by name: '//TRIM(em)) + END DO + END SUBROUTINE case_standalone_refusal + +END PROGRAM test_openfast_pinned_rod