diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cd9946e..d1b295a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -168,6 +168,21 @@ All notable changes to CableDyn are recorded in this file. The format follows moorings, and quote their results for the enlarged grid. With the `MD_Shared` grid, the line-1 fairlead tension standard deviation of the tutorial was 18 % too high. See the manual's OpenFAST page (SeaState grid). +- Active tensioning of finite-EI cables in OpenFAST (`CompMooring = 5`). A `CONTROL` row may + now name a finite-EI (cubic-Hermite) cable, alone or in a deck with `EI = 0` lines. Before + each mooring step, ServoDyn's `CableDeltaL` and `CableDeltaLdot` scale every cable element of + the line's fairlead-side deck segment by (S + `DeltaL`)/S, with the matching rate, so the + segment becomes S + `DeltaL` long. The cable's mass, attachment masses, tributary lengths and + seabed contact coefficients follow the new lengths, and the axial damping acts on the rate of + the strain the elastic force uses, so a segment paid out at constant strain carries no damping + force. The force-blended generalised-α step takes its committed force at the lengths of the + preceding step, so a pay-out ramp follows the quasi-static tension at any `rhoInf`; a deck + that controls a finite-EI cable under `False alpha_force_blend` fails at initialisation with + a message that names the line, as that blend has no such treatment. A command outside + MoorDyn-F's bounds stops the run as for `EI = 0` lines (see Changed), and FAST.Farm decks + still reject `CONTROL`. A zero command, with a `DeltaLdot` of either sign, leaves the run + bit-identical to an uncontrolled one, and a checkpoint restart continues bit-identically. See + the manual's deck format page (CONTROL). ### Changed @@ -318,6 +333,16 @@ All notable changes to CableDyn are recorded in this file. The format follows 0.63 m against 0.64 m converged, where the linear interpolation gave 0.23 m. On the `EI = 0` chain of `examples/chain_range_tdp.dat` the largest step falls from 2.59 m to 1.33 m. The TDP now lies on the contact-onset height, and `TDPGrd` uses the same location. +- Active tensioning (`CONTROL`) of an `EI = 0` line now stops the run when a command leaves + MoorDyn-F's bounds, as MoorDyn-F does: with `UnstrLen` the line's unstretched length and N its + number of segments, a `DeltaL` above `UnstrLen`/N or below −0.5 `UnstrLen`/N, the comparisons + MoorDyn-F makes, so a command MoorDyn-F accepts is accepted (on a line of one section + `UnstrLen`/N is the controlled segment's initial length). The message names the channel, the + line, the command and the bound. A command beyond these bounds had printed a one-time warning + and been applied. A command within the bounds that would make the controlled segment of a + line of several sections non-positive also stops the run. Finite-EI cables take the same + bounds. Every row is checked before any line changes, and a row that still fails takes back + the lines the command had already changed, so a refused command changes nothing. - Faster wave kinematics of directional and multi-train seas (`wavetrain` rows, spectral `waves` rows, `WaveSpreading`). Each component's phase cosine is now computed once for the surface elevation and the kinematics, and its depth profile with one exponential instead of @@ -520,6 +545,54 @@ All notable changes to CableDyn are recorded in this file. The format follows than a factor four, as the manual states; it had kept the first tangent for the whole step, which a slow linear contraction could exhaust (30 iterations at the start of the 5 m heave cells of the L2-2 parity test with the force blend). +- Active tensioning (`CONTROL`) of an `EI = 0` line now changes the segment at the line's + fairlead-side end, the end on a host-driven point (`Coupled`, `Vessel`, `Turbine`, + `Body` or a `Coupled`/`Vessel` rod end), and the segment at the `NodeB` written in the + deck when both or neither ends are host-driven, as MoorDyn-F does for a deck in its own order. + It had always changed the segment at CableDyn's End A, the `NodeA` of a line that the + automatic anchor-first swap leaves in deck order. Two kinds of line change: a line kept in + deck order whose only host-driven end is its `NodeB`, such as a stock-order + `Connect`-to-`Vessel` clump leg or a line from a `Fixed` anchor to a coupled rod end, now + controls the segment at the host-driven end instead of the one at its `NodeA`; and a line + with both or no host-driven ends that the swap leaves in deck order, such as a + `Connect`-to-`Fixed` or `Connect`-to-`Connect` line, a `Fixed` hang-off above a + `Free`/`Connect` point, or a line between two vessel points, now controls the segment at its + `NodeB`. Lines from a `Fixed` anchor to a `Coupled`, `Vessel` or `Body` point, + written in either order, and lines written fairlead first from a host-driven `NodeA` control + the same segment as before. +- Active tensioning (`CONTROL`) of `EI = 0` lines no longer lags behind the commanded length + on a pay-out or haul-in ramp. A length update had re-derived the committed acceleration + under the new length, and the next generalised-α step evaluated its blended configuration + with the new length only, so the force of each length change entered the committed side of + the blend. The committed state now keeps its acceleration and the lengths and rates it was + reached with, and each share of the step after a change takes the lengths of its own time + level. With the force-blended step (the default), the step-start force is evaluated at the + committed lengths and rates: the internal force, every dynamic load, every step-start + quantity of the release cap (stretch, tension, secant and law stiffness, dashpot tension, and + the one-step dissipation budget of a dashpot slack at the step start), + and the distributed external load and seabed coefficients those lengths give; the cap's + end-state quantities take the new lengths; the end-of-step force takes the new lengths, and the inertia (the + structural and added mass, which the force blend keeps at the α level) the blended ones. + Under `False alpha_force_blend` the step blends the old and new lengths with the + configuration. An acceleration re-derived between a command and the next step, as a host + state update does, is solved at the committed lengths, as the step evaluates its committed + side, and leaves them committed. On a taut line paid out at a tension change of 1 N per step, + the tension follows the closed form to 1.8 mN at `rhoInf` 0.4 and 0 alike (the start-up + transient), where a step-start force at the new lengths lags by 2.6 N. In + the coupled OpenFAST comparison with stock MoorDyn (`validation/scripts/activetension/`), the + controlled fairlead tensions had run up to 97 kN (4.1 %) above MoorDyn during the pay-out and + 148 kN (6.3 %) below it during the haul-in, at `rhoInf` 0.4 and still 58 kN and 89 kN at + `rhoInf` 0; they now stay within 3 kN (0.13 %). The hold tensions, which the published + comparison scores, move by less than 0.01 %, and the scorer now also gates the ramps. + This change leaves runs without `CONTROL`, and a zero command, bit-identical. A checkpoint restart + re-applies the restored command as the committed state's, so a restart during a ramp + continues bit-identically. A step that `ei0_substeps auto` solves in sub-steps spreads the + length change over them: the committed lengths are part of the state each pass starts from, + each sub-step ends at the lengths and rates interpolated linearly in time (the last at the + new ones), and the trigger takes the step-start tensions at the committed lengths. On a line + turning by 2.3° per step and paid out at 0.05 m/s, the sub-stepped march equals one taken as + given at a quarter of the step to 3e-8 N; applying the whole change in the first sub-step + departs from it by 22 N. - The development environment (`environment.yml`) excludes OpenBLAS 0.3.34, which caused the access violation in the modal analysis tests listed under Known issues for 0.1.1. On AMD Zen 4 and Zen 5 CPUs that expose AVX-512, OpenBLAS 0.3.34 enlarges the GEMM blocking, diff --git a/CMakeLists.txt b/CMakeLists.txt index b57cb64e..20a5e70a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -653,6 +653,14 @@ target_link_libraries(test_hermite_axial_damping PRIVATE cabledyn_core) add_test(NAME hermite_axial_damping COMMAND test_hermite_axial_damping) set_tests_properties(hermite_axial_damping PROPERTIES LABELS "fortran;unit;dynamic;damping") +# Active line control of a finite-EI cable: the length update rebuilds the caches a fresh +# build carries (bit for bit), is atomic and rewinds exactly; hanging, taut and paid-out +# vertical cables meet their closed forms; a slow ramp ends at the static equilibrium. +add_executable(test_hermite_cable_control tests/test_hermite_cable_control.f90) +target_link_libraries(test_hermite_cable_control PRIVATE cabledyn_core) +add_test(NAME hermite_cable_control COMMAND test_hermite_cable_control) +set_tests_properties(hermite_cable_control PROPERTIES LABELS "fortran;unit;dynamic;hermite") + add_executable(test_hermite_added_mass tests/test_hermite_added_mass.f90) target_link_libraries(test_hermite_added_mass PRIVATE cabledyn_core) add_test(NAME hermite_added_mass COMMAND test_hermite_added_mass) @@ -2347,6 +2355,7 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") test_hermite_cable test_hermite_drag_dynamics test_hermite_axial_damping + test_hermite_cable_control test_endconn_spring) target_compile_options(${_cabledyn_exact_real_test} PRIVATE -Wno-compare-reals) endforeach() @@ -2355,6 +2364,7 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") -Wno-uninitialized -Wno-maybe-uninitialized) target_compile_options(test_torsion_deck PRIVATE -Wno-uninitialized -Wno-maybe-uninitialized) + target_compile_options(test_hermite_cable_control PRIVATE -Wno-uninitialized -Wno-maybe-uninitialized) endif() if(CABLEDYN_ENABLE_COVERAGE) @@ -2403,6 +2413,7 @@ if(CABLEDYN_ENABLE_COVERAGE) test_hermite_cable_dynamic test_hermite_drag_dynamics test_hermite_axial_damping + test_hermite_cable_control test_hermite_added_mass test_hermite_wave_forcing test_lazywave_dynamics diff --git a/VALIDATION.md b/VALIDATION.md index 3626f377..78cee30d 100644 --- a/VALIDATION.md +++ b/VALIDATION.md @@ -757,7 +757,8 @@ stop with a named error. | Farm + restart / Farm + linearisation | Not applicable | FAST.Farm has no restart and does not call module linearisation; the same applies to stock MoorDyn | | Line failures (`FAILURE` table) | Pass verified | MoorDyn semantics on both paths (reserve-point pre-allocation, time or tension trigger, detach onto a massless Free point); standalone (point systems and free Rigid6 bodies), coupled, and checkpoint-replay tests | | Viscoelastic stiffness (`ElasticMod > 1`; [Hall et al., 2023](https://cabledyn.readthedocs.io/en/latest/references.html#ref-hall2023)) | Pass verified | both MoorDyn forms as per-element two-branch series-Kelvin laws eliminated implicitly in the generalised-α step; the standard linear solid is recovered only when the fast-branch dashpot `BA_D` is zero; `md_viscoelastic` r-test 0.007–0.97% at 5× dt; the coupled module carries `dl_1` in the checkpoint state | -| 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)) | +| 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); during the pay-out and haul-in ramps the tensions differ by at most 0.13% (controlled fairleads) / 0.39% (anchors) of the baseline tension, with the force-blended step evaluating its step-start force at the committed lengths (the fairleads had differed by up to 4.1% and 6.3% before the length update kept the committed lengths in the generalised-alpha step; the holds were unaffected) ([`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)) | +| Active tension of finite-EI cables (no MoorDyn-F counterpart) | Pass scoped | coupled A/B with the active-tension model above, line 1 a finite-EI cable of small bending stiffness (EI = 1e5 N m², 50 elements) against stock MoorDyn's chain: during the ramps its tensions differ by at most 0.21% (fairlead) / 0.86% (anchor) of the baseline at `rhoInf` 0.4, and its hold responses by 1.9–2.3% (against the `EI = 0` twin of the same deck this hold difference falls from about 2% at 50 to 0.3% at 100 segments); a restart mid-ramp and `NumCrctn = 1` are bit-identical. Aggregate and model tests: closed forms on axial vertical cables (top reaction w(L + ΔL) to 2e-7, taut top tension EA(H − L′)/L′ + wL′/2 to 1e-12, Kelvin–Voigt pay-out lag BA·H·L̇/L′² to 1e-5 of the lag), slow-ramp end state equal to the static solve of the edited lengths to 2e-6 of the displacement, damping Jacobian with the length rate against finite differences, caches equal to a fresh build and snapshot/restore bit for bit, bit-identical zero command and checkpoint restart (`test_hermite_cable_control`, `test_hermite_axial_damping`, `case_aggregate_cable_control`, `case_restart_cable_control`) | | 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 | diff --git a/doc/capabilities.rst b/doc/capabilities.rst index df3a5864..e6fcac78 100644 --- a/doc/capabilities.rst +++ b/doc/capabilities.rst @@ -192,11 +192,10 @@ OpenFAST coverage The ``CompMooring = 5`` shell covers normal coupled time-domain stepping with its own ``dtM``, nonzero ``PtfmInit``, correction iterations, SeaState fields, checkpoint/restart, scoped -quasi-static ``dYdu`` linearisation, line failures, active-tension control for ``EI = 0`` lines, -and FAST.Farm shared moorings. Restart and linearisation do not arise under FAST.Farm, which -does not call those module operations. Active ServoDyn control of a finite-EI cable -remains rejected. See :doc:`openfast` for setup and :doc:`coupling_boundary` for the interface -contract. +quasi-static ``dYdu`` linearisation, line failures, active-tension control of ``EI = 0`` lines +and finite-EI cables, and FAST.Farm shared moorings. Restart and linearisation do not arise under +FAST.Farm, which does not call those module operations, and active-tension control is rejected +there. See :doc:`openfast` for setup and :doc:`coupling_boundary` for the interface contract. How to interpret this page -------------------------- diff --git a/doc/coupling.rst b/doc/coupling.rst index 12c84ab4..d66c8d64 100644 --- a/doc/coupling.rst +++ b/doc/coupling.rst @@ -48,8 +48,10 @@ solve is mathematically incorrect; changing ``NumCrctn`` does not change that de Outside that surface the module fails closed — a clear fatal error, never a silent wrong answer — on: - - active ServoDyn control (``CableDeltaL``) of a finite-EI cable, or any ``CONTROL`` section - in FAST.Farm (``EI = 0`` line control is supported in a single-turbine model), + - any ``CONTROL`` section in FAST.Farm (active ServoDyn control, ``CableDeltaL``, of + ``EI = 0`` lines and finite-EI cables is supported in a single-turbine model), a + command outside MoorDyn-F's bounds or one that would make a controlled segment + non-positive, and ``CONTROL`` of a finite-EI cable under ``False alpha_force_blend``, - coupled ``Rigid6`` bodies and rods in a FAST.Farm deck, - deck ``waves``/``wavetrain`` OPTIONS (the host SeaState supplies the waves), and a deck ``current`` except as a steady current on a single-turbine, pure ``EI = 0`` deck without diff --git a/doc/coupling_boundary.md b/doc/coupling_boundary.md index 15205cb8..5f4e36e4 100644 --- a/doc/coupling_boundary.md +++ b/doc/coupling_boundary.md @@ -128,7 +128,7 @@ point mesh. It supports: stored in the OpenFAST state record; - quasi-static linearisation; - FAST.Farm shared moorings; -- line failures and active tension control of `EI = 0` lines; +- line failures, and active tension control of `EI = 0` lines and finite-EI cables; - WaterKin files with independent selection of host wave and host current. SeaState's standard steady current is reconstructed on the same vertical nodes and weights SeaState uses, so it can be removed or kept exactly; a host field that cannot be separated is rejected. diff --git a/doc/driver_format.md b/doc/driver_format.md index 83c23521..e5240eef 100644 --- a/doc/driver_format.md +++ b/doc/driver_format.md @@ -386,7 +386,8 @@ row. On this route: field; - a finite-EI cable cannot share a coupled deck with Rigid6 bodies, rods, or `Connect`/`Free` points; -- CONTROL and FAILURE rows are rejected on decks that contain finite-EI cables; +- FAILURE rows are rejected on decks that contain finite-EI cables; CONTROL rows may name + finite-EI cables (see [CONTROL](#control-optional-openfast-line-control)); - `Coupled`/`Vessel` rods are platform-borne and need no `motionFile`: each is a node of the OpenFAST mesh at its End A, turns rigidly with the platform orientation (its deck coordinates, like those of `Coupled` points, are given at the undisplaced platform and moved by @@ -980,17 +981,53 @@ ChannelID Line(s) | `Line(s)` | one line id or a comma list without spaces (`1,2`) | Each line belongs to at most one channel. Before every advance, the channel's `DeltaL` sets the -unstretched length of each assigned line's **last (fairlead-side) segment** to its initial length -plus `DeltaL`; `DeltaLdot` supplies the matching rate. Axial damping on that segment acts on the -strain rate, as in MoorDyn-F, so a segment paid out at constant strain carries no damping tension. -A command that makes that segment length -zero or negative is rejected. A command above one initial segment length, or below minus half of -it, prints a one-time warning and is applied unclamped. The host input arrays are sized to the -highest channel id. - -CONTROL is supported only on the OpenFAST `CompMooring = 5` route, for pure `EI = 0`, -non-FAST.Farm decks, without OpenFAST linearisation. The standalone driver rejects a CONTROL -section, as does a coupled deck containing a finite-EI cable. +unstretched length of each assigned line's **fairlead-side segment** to its initial length plus +`DeltaL`; `DeltaLdot` supplies the matching rate. The fairlead-side segment is the one at the +line's end on a host-driven point: `Coupled`, `Vessel`, `Turbine`, `Body`, or an end of a +`Coupled` or `Vessel` rod. When both ends or neither end are on such points, it is the segment at +the `NodeB` written in the deck. A line written in the stock MoorDyn order, with its host-driven +end at `NodeB`, is therefore controlled where MoorDyn-F controls it, at its last segment N at +`AttachB`; so is a line with both or no host-driven ends. A line written fairlead first, with its +only host-driven end at `NodeA`, is controlled at that end. The length is held over the advance. +Axial damping on that segment acts on the strain rate, as in MoorDyn-F, so a segment paid out at +constant strain carries no damping tension. + +A command outside MoorDyn-F's bounds stops the run with a message that names the channel, the +line, the command and the bound, as MoorDyn-F stops there. With `UnstrLen` the line's unstretched +length and N its number of segments, both summed over its `SECTIONS` rows, MoorDyn-F refuses +`DeltaL` > `UnstrLen`/N and `DeltaL` < −0.5 `UnstrLen`/N; CableDyn makes the same comparisons, so +a command MoorDyn-F accepts is accepted. On a line of one section `UnstrLen`/N is the controlled +segment's initial length S, and the bounds read −S/2 ≤ `DeltaL` ≤ S. On a line of several +sections the controlled segment can be shorter or longer than `UnstrLen`/N; a command within the +bounds that would make it zero or negative (possible when it is shorter than half of +`UnstrLen`/N) also stops the run, with a message that names the line. + +- On an `EI = 0` line the segment is the end element on that side, of initial length S. The + step evaluates the committed side of its generalised-α blend at the lengths of the previous + advance (with the force blend, the default, the step-start force; under + `False alpha_force_blend`, lengths blended with the configuration), so a length ramp is + followed without lag at any `rhoInf`. +- On a finite-EI cable, which runs from a `Fixed` anchor to a host-driven fairlead, the segment + is the fairlead segment of the deck mesh (the length of the `SECTIONS` row at the fairlead over + its `NumSegs`). Where the static initialisation refined the mesh, it is the cable elements that + make up that segment. Each of them scales by (S + `DeltaL`)/S, S being the segment's initial + length, with rate `DeltaLdot` l/S for an element of initial length l, so the segment becomes + S + `DeltaL` long. The structural and attachment mass, the seabed contact coefficients and the + tributary lengths follow the new lengths; `BA` keeps its initial resolution. The step blends + the force of the committed state, taken at the lengths of the previous advance, with the force + at the new lengths, so a length ramp is followed without lag at any `rhoInf`. This needs the + force-blended generalised-α, the default: a deck that controls a finite-EI cable under + `False alpha_force_blend` fails at initialisation with a message that names the line. Within + the bounds above, a cable of one section scales each element within [0.5, 2] of its initial + length; on a cable of several sections the scaling can leave that range, beyond the + resolution its static mesh was built for, so keep large commands on a fairlead section whose + segments are at least `UnstrLen`/N long. A cable restrained in torsion cannot be controlled + (the coupled route rejects torsion stiffness in END CONNECTIONS). + +The host input arrays are sized to the highest channel id. + +CONTROL is supported only on the OpenFAST `CompMooring = 5` route, for non-FAST.Farm decks, +without OpenFAST linearisation. The standalone driver rejects a CONTROL section. ### OPTIONS (`value keyword` order, case-insensitive keyword) diff --git a/doc/migrating.rst b/doc/migrating.rst index e4723966..04748725 100644 --- a/doc/migrating.rst +++ b/doc/migrating.rst @@ -115,9 +115,13 @@ Keyword map * - ``WaterKin`` file (``CurrentMod 1``, ``WaveKinMod 1``) - same file; ``WaveKinMod 2`` and ``SEASTATE`` only when coupled to OpenFAST * - ``FAILURE``, ``CONTROL`` sections - - ``FAILURE`` on ``EI = 0`` decks, standalone and in OpenFAST; ``CONTROL`` on ``EI = 0`` - decks in OpenFAST (the standalone driver rejects it). A deck with a finite-EI cable - rejects both + - ``FAILURE`` on ``EI = 0`` decks, standalone and in OpenFAST (a deck with a finite-EI + cable rejects it); ``CONTROL`` on ``EI = 0`` lines and finite-EI cables in OpenFAST, not + in FAST.Farm (the standalone driver rejects it). The command changes the segment at the + line's host-driven end, or at the ``NodeB`` written in the deck when both or neither ends + are host-driven; a stock-order deck is controlled where MoorDyn-F controls it. A + command outside MoorDyn-F's bounds (−S/2 ≤ ``DeltaL`` ≤ S with S = ``UnstrLen``/N, the + same comparison) stops the run, as it stops MoorDyn-F * - ``FairTen``, ``AnchTen``, point/node channels - same names; tensions in N (:doc:`outputs`). On a line with no ``Fixed`` end the two end channels name the opposite ends from MoorDyn's (see above) diff --git a/doc/openfast.rst b/doc/openfast.rst index 941f7a94..09e82172 100644 --- a/doc/openfast.rst +++ b/doc/openfast.rst @@ -335,8 +335,16 @@ without an auxiliary process: turbines, otherwise initialisation fails. * **Line failures** detach a line end on a time or tension trigger and replay correctly after a restart. Verify the trigger and the post-failure topology in a dedicated case first. -* **Active tensioning** maps ServoDyn ``CableDeltaL`` control onto ``EI = 0`` lines; finite-EI - lines reject it. +* **Active tensioning** maps ServoDyn ``CableDeltaL``/``CableDeltaLdot`` control onto the + fairlead-side segment of ``EI = 0`` lines and finite-EI cables, the segment at the line's end + on a host-driven point, or at the ``NodeB`` written in the deck when both or neither ends are + (:doc:`driver_format`, CONTROL). On a finite-EI cable the command scales every cable element + of that segment, and needs the force-blended generalised-α (the default). On both kinds a + command outside MoorDyn-F's bounds, from minus half to plus one ``UnstrLen``/N of the line + (the controlled segment's initial length on a line of one section), stops the run with a + message that names the line, as it stops MoorDyn-F; so does a command that would make the + controlled segment of a line of several sections non-positive. FAST.Farm decks reject + CONTROL. * **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, free rods and pinned rods start at their static equilibrium with the platform diff --git a/doc/theory.rst b/doc/theory.rst index eb199e87..5f9d41e8 100644 --- a/doc/theory.rst +++ b/doc/theory.rst @@ -1439,7 +1439,9 @@ dynamic load: axial damping, the viscoelastic and Syrope laws, seabed contact, d friction, Morison drag, Froude–Krylov and buoyancy loads. Added mass stays at :math:`(\mathbf{q}_\alpha, \mathbf{a}_{\alpha_m})`. :math:`\mathbf{r}_n` is evaluated afresh at the committed state of every step, with the viscoelastic and Syrope elements at their committed -internal state, so the scheme carries no extra state and a restart is exact; a re-solve of the +internal state (and, after a length change by active line control, at the lengths the committed +state was reached with; see Active line control), so the scheme carries no extra state and a +restart is exact; a re-solve of the same step from the same state (the junction coupling) reuses it. The fluid fields of an ``EI = 0`` line (current, wave velocity and acceleration, and the waterline) are held over the step: before the step the host (the standalone driver, or the coupling host) samples them for @@ -2239,11 +2241,115 @@ pre-allocated reserve free point that then moves with the attached line ends. On the bodies keep their staggered step with the remaining lines, and the reserve point is integrated on its line-end loads within the same line step. -**Active line control.** A ``CONTROL`` row assigns a control channel to an ``EI = 0`` line. The -commanded :math:`\Delta L` and :math:`\Delta\dot L` change the unstretched length and its rate -of the End-A element, :math:`L_0 = L_{0,\text{base}} + \Delta L`; the structural mass and the -point mass shares are updated consistently, while ``BA`` keeps its initial resolution. -Commands that would make the element length non-positive are rejected. +**Active line control.** A ``CONTROL`` row assigns a control channel to a line. The command +acts on the segment at the line's fairlead-side end, the end on a host-driven point (coupled, +vessel, turbine or body point, or an end of a coupled or vessel rod); when both or neither ends +are host-driven, it acts on the segment at the ``NodeB`` written in the deck (MoorDyn-F's +segment :math:`N` at ``AttachB``). On an ``EI = 0`` line the commanded :math:`\Delta L` and +:math:`\Delta\dot L` change the unstretched length and its rate of that end element, +:math:`L_0 = L_{0,\text{base}} + \Delta L`; the structural mass and the point mass shares are +updated consistently, while ``BA`` keeps its initial resolution. Commands outside MoorDyn-F's +bounds, :math:`-\bar L/2 \le \Delta L \le \bar L` with :math:`\bar L` the line's unstretched +length over its number of segments (``UnstrLen``/N, the base length of the controlled segment +on a line of one section), are rejected with the same comparisons MoorDyn-F makes, on both line +kinds; so is a command that would make the controlled segment non-positive, which only a line +of several sections allows. + +On an ``EI = 0`` line the length is applied before a step and held over it, and the +committed state keeps the lengths and rates it was reached with, :math:`L_{0,c}` and +:math:`\dot L_{0,c}`, together with its acceleration. Each share of the generalised-:math:`\alpha` +residual takes the lengths of its own time level, and the step commits the new lengths with the +new state. With the force blend (the default) the step-start force +:math:`\mathbf{r}(\mathbf{q}_n, \mathbf{v}_n)` is the committed state's: its internal force, axial +damping, viscoelastic and Syrope laws, seabed contact, damping and friction, Morison drag, +Froude–Krylov and buoyancy loads are evaluated with :math:`L_{0,c}` and :math:`\dot L_{0,c}`, with +the distributed external load and the nodal seabed coefficients those lengths give, and so is +every step-start quantity of the release cap: the stretch :math:`e_n = l_n - L_{0,c}`, the +tension :math:`T_n` (the elastic one, or that of the viscoelastic or Syrope law at the committed +state), :math:`W_n`, the secant :math:`T_n/e_n`, the law stiffness :math:`k_n` (:math:`EA_D/L_{0,c}`, +:math:`K_1/L_{0,c}`) and the dashpot tension :math:`T_{d,n}` (with :math:`\dot L_{0,c}`). +:math:`\mathbf{r}(\mathbf{q}_{n+1}, \mathbf{v}_{n+1})` and the cap's end-state quantities take the new +lengths and rates: the stretch :math:`e_{n+1} = l_{n+1} - L_0`, the estimate +:math:`\hat T_{n+1} = \min(T_n/e_n, k_n)\,e_{n+1}` and :math:`T_{d,n+1}`; the projections :math:`p` and +:math:`p_{n+1}` are geometric. The dashpot weight :math:`\phi` measures the end stretch against the new +length, so its band runs from :math:`L_0` to :math:`L_0 + c\,e_n`, the width set by the step-start +stretch as without a change. For an elastic element the secant estimate then differs from its end +tension :math:`EA\,e_{n+1}/L_0` by the factor :math:`L_0/L_{0,c}`, that is by the relative length change +of the step. A haul-in can make :math:`p_{n+1}` more negative than without a change; the +capped force is then bounded below by zero, and the cap's quick inactivity test uses the bound +:math:`N \ge W_n - (1-\alpha_f)\,T_n (l_n - L_0)^2/(4 e_n)`. The external load of the step, +constant over it, is :math:`(1-\alpha_f)\,\mathbf{f}_\text{ext}(L_0) + \alpha_f\,\mathbf{f}_\text{ext}(L_{0,c})`. +The inertia, which the force blend keeps at the :math:`\alpha` level (the structural mass applied +to :math:`\mathbf{a}_{n+1-\alpha_m}` and the added mass at :math:`\mathbf{q}_\alpha`), takes the +blended lengths :math:`(1-\alpha_f) L_0 + \alpha_f L_{0,c}` of the changed elements, as +:math:`\mathbf{q}_\alpha` blends the configuration. With the configuration blend +(``False alpha_force_blend``) the residual evaluates the internal force, the damping and the +hydrodynamic loads at the blended configuration :math:`\mathbf{q}_{n+1-\alpha_f}`; for an element +whose length changed it also blends the lengths, :math:`(1-\alpha_f) L_0 + \alpha_f L_{0,c}` (and +the rates likewise, the structural and added mass included), so that the configuration and the +lengths are blended consistently and the new length belongs to :math:`t_{n+1}`; the external load +and the seabed coefficients are then the new lengths'. Evaluating the committed side with the +new lengths (the step-start force, or a configuration blended without its lengths), or +re-deriving the committed acceleration under the new length, would add the force of the length +change to the committed side of the blend, weighted by :math:`\alpha_m` and :math:`\alpha_f`; on a +pay-out or haul-in ramp the tension would then lag the quasi-static value by a fixed fraction of +its change per step, at any :math:`\rho_\infty` (on a taut line paid out at a tension change of +1 N per step, 2.6 N with the step-start force at the new lengths, against 1.8 mN, the start-up +transient that :math:`\rho_\infty = 0` shows as well). An acceleration re-derived between the +command and the step (a host state update or a boundary commit) belongs to the committed state, +so it is solved with :math:`L_{0,c}` and :math:`\dot L_{0,c}`, which stay the committed lengths and +rates, and evaluated as the step evaluates its committed side: with the force blend at the +external load and seabed coefficients of :math:`L_{0,c}` as well, with the configuration blend at +the present ones. + +A step that the rotation- and snap-resolved sub-steps (``ei0_substeps auto``, above) solve +again spreads a pending length change over its sub-steps. The committed lengths and rates are +part of the state each pass starts from; sub-step :math:`k` of :math:`n` ends at the lengths and +rates interpolated linearly in time between :math:`L_{0,c}` and :math:`L_0` at :math:`k/n`, with +the external load and seabed coefficients rebuilt at them, and the last on the new ones bit for +bit. Each sub-step treats its start and end lengths as the step above treats :math:`L_{0,c}` and +:math:`L_0`, so the first starts at :math:`L_{0,c}`, and the trigger takes the step-start +tensions at :math:`L_{0,c}`. A constant command rate makes the interpolated lengths those the +rate integrates to: on a line turning by 2.3° per step whose end segment is paid out at +0.05 m/s, every step solved in four sub-steps, the march equals one taken as given at a quarter +of the step to 3e-8 N, where applying the whole change in the first sub-step departs from it by +22 N (2.2 times the tension change per step). A step recovered after a stall and the halves of a +line-system step halved after a failure, which take their sub-steps as given, apply the whole +change in their first part. + +On a finite-EI cable, whose fairlead is End A, the command acts on the cable elements that make +up the End-A segment of the deck mesh, of initial length :math:`S`. Each element scales by +:math:`\lambda = (S + \Delta L)/S`, :math:`L_{0,e} = \lambda L_{0,e,\text{base}}`, with rate +:math:`\dot L_{0,e} = \Delta\dot L\, L_{0,e,\text{base}}/S`. The length is applied before a +step and held over it. The +consistent mass, the attachment masses, the tributary lengths and the nodal seabed coefficients +are rebuilt from the new lengths in the order initialisation used, so the model is the one a +build with those lengths would give; the mass of the new lengths acts over the step and its rate +term :math:`\dot{\mathbf{M}}\mathbf{v}` is not modelled (as in MoorDyn), and the committed +acceleration is kept as the history of the preceding step. The committed state keeps the lengths +and rates it was reached with: in the force-blended residual the committed force +:math:`\mathbf{F}_n = \mathbf{R}(\mathbf{q}_n, \mathbf{v}_n, t_n)` is the force at those +lengths, and only :math:`\mathbf{R}(\mathbf{q}_{n+1}, \mathbf{v}_{n+1}, t_{n+1})` takes the new +ones; an acceleration re-derived between the command and the step (a boundary commit) is solved +at those lengths too, since it belongs to the committed state. The configuration-blended form +(``False alpha_force_blend``) has no such treatment and is refused for a controlled cable. Evaluating :math:`\mathbf{F}_n` at the new lengths would add the force of the length change +to the committed state, which the blend weighs by :math:`\alpha_f`; on a pay-out ramp the +tension would then lag the quasi-static value by a fixed fraction of its change per step. A step +that follows a change starts its Newton iteration from the Newmark predictor, not from the +constant-acceleration one, since the change is a step in the load. The axial damping acts on +the rate of the strain :math:`\varepsilon = |\mathbf{r}_{,\xi}|/L_0 - 1` along the motion and +the length change. The tangent terms of :math:`\mathbf{r}_{,\xi}` carry the +factor :math:`L_0` and cancel, so with :math:`\mathbf{p} = H'_1 \mathbf{r}_1 + H'_3 \mathbf{r}_2` +the end-position part, + +.. math:: + + \dot\varepsilon = \frac{\mathbf{t}\cdot\left(\mathbf{v}_{,\xi} + - (\dot L_0/L_0)\,\mathbf{p}\right)}{L_0}, + +and a segment paid out at constant strain carries no damping force. The position Jacobian of the +damping force gains :math:`-BA\, H'_a H'_b\, (\dot L_0/L_0^2)\, \mathbf{t}\mathbf{t}^\mathsf{T}` on +the end-position columns. Tension and coupled loads ------------------------- diff --git a/doc/troubleshooting.rst b/doc/troubleshooting.rst index bbe679ab..b7e0c42b 100644 --- a/doc/troubleshooting.rst +++ b/doc/troubleshooting.rst @@ -402,10 +402,25 @@ FAILURE and CONTROL sections bodies and their lines only; model a clump or buoy on the line as part of a body. * - ``this entry point does not support the CONTROL section`` - the standalone driver does not consume CONTROL. Line control is an OpenFAST - ``CompMooring = 5`` feature for ``EI = 0`` decks; remove the section for a standalone run. + ``CompMooring = 5`` feature; remove the section for a standalone run. * - ``CONTROL row has trailing content`` / ``line L is assigned to more than one CONTROL channel`` - write ``ChannelID Lines`` with a comma list without spaces, and assign each line once. + * - ``control channel C commands DeltaL = ... m on EI = 0 line L, outside MoorDyn-F's + bounds -S/2 <= DeltaL <= S (S = UnstrLen/N = ... m)`` (or ``on finite-EI line L``) + - the command lengthens the line's fairlead-side segment by more than ``UnstrLen``/N (the + line's unstretched length over its number of segments) or shortens it by more than half + of that, where MoorDyn-F also stops. Keep ``CableDeltaL`` within the bounds, or mesh the + line with fewer, longer segments so the command is a smaller fraction of one. + * - ``control channel C commands DeltaL = ... m on ... line L, which would make its controlled + segment (... m long) non-positive`` + - on a line of several sections the controlled segment is shorter than half of + ``UnstrLen``/N, so a haul-in within MoorDyn-F's bounds would consume it. Keep the + haul-in shorter than the segment, or make the fairlead-side section's segments longer. + * - ``CONTROL line L: active line control of a finite-EI line needs the force-blended + generalised-alpha (OPTION alpha_force_blend True)`` + - the configuration blend has no committed-length treatment, so a ramp would lag; remove + ``False alpha_force_blend`` from a deck that controls a finite-EI cable. .. _non-convergence: @@ -682,9 +697,10 @@ aborts with a CableDyn fatal error, check whether the deck uses one of these com * - Not supported on the coupled route - Use instead - * - active ServoDyn control (``CONTROL``) on a deck with a **finite-EI** cable, or in FAST.Farm - - ``EI = 0`` line control **is** supported in a single-turbine model; for a controlled cable, - use stock MoorDyn (``CompMooring = 3``) in the same binary + * - active ServoDyn control (``CONTROL``) in FAST.Farm + - line control of ``EI = 0`` lines and finite-EI cables **is** supported in a single-turbine + model; for controlled lines in a farm, use stock MoorDyn (``CompMooring = 3``) in the same + binary * - deck ``waves``/``wavetrain`` OPTIONS, and a deck ``current`` on a deck with finite-EI cables, Rigid6 bodies or rods, in FAST.Farm, or with a SeaState that carries waves or current diff --git a/python/tests/test_deck_file.py b/python/tests/test_deck_file.py index c8c783b6..62a65f6c 100644 --- a/python/tests/test_deck_file.py +++ b/python/tests/test_deck_file.py @@ -3437,6 +3437,19 @@ def test_control_rows_fail_closed(rows, message): DeckFile.from_text(_with_section(_STATIC, "CONTROL", "Channel Lines", *rows)) +def test_control_rows_may_name_finite_ei_cables_on_the_coupled_route(): + # native CD_Init_Deck_Aggregate controls the fairlead-side segment of a finite-EI cable + # too, alone or on one channel with EI = 0 lines (line 4 is the mixed deck's cable) + marker = "--------------------------- OPTIONS" + block = ( + "--------------------------- CONTROL -------------------------------------------\n" + "ChannelID Lines\n(-) (-)\n1 4\n2 1,3\n" + ) + text = (ROOT / "examples/iea15mw_umaine_mixed_cabledyn.dat").read_text(encoding="utf-8") + deck = DeckFile.from_text(text.replace(marker, block + marker, 1), caller_driven=True) + assert [row.tokens for row in deck._rows("CONTROL")] == [("1", "4"), ("2", "1,3")] + + # --------------------------------------------------------------------------- # Editing API error contract # --------------------------------------------------------------------------- diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index 497f5ffd..ed9ed449 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -103,6 +103,7 @@ MODULE CableDyn_DeckDriver CD_HermiteCable_Dyn_Set_ForceBlend, CD_HC_FORCE_BLEND_DEFAULT, & CD_HermiteCable_Dyn_Set_Friction_Anchors, & CD_HermiteCable_Dyn_Set_Friction_Axial, & + CD_HermiteCable_Dyn_Set_Control_Seabed, & CD_HermiteCable_Dyn_Max_Step_Rotation, CD_HermiteCable_Dyn_Energy, & CD_HermiteCable_Attachment_Drag, CD_HermiteCable_Dyn_Torsion_State USE CableDyn_HermiteTorsion, ONLY: CD_HermiteTorsionType, CD_HermiteTorsion_Compliance, CD_HTORS_MAX_STEP, & @@ -247,6 +248,8 @@ MODULE CableDyn_DeckDriver 'route, which supports torsion); set TorsStiffness Free in every END CONNECTIONS row' CHARACTER(*), PARAMETER :: TORSION_NEEDS_FORCE_BLEND = 'torsion in a dynamic run needs the force-blended '// & 'generalised-alpha (OPTION alpha_force_blend True)' + CHARACTER(*), PARAMETER :: CONTROL_NEEDS_FORCE_BLEND = 'active line control of a finite-EI line needs the '// & + 'force-blended generalised-alpha (OPTION alpha_force_blend True)' REAL(wp), PARAMETER :: QUARTER_PI = 0.785398163397448309616_wp ! pi/4 (displaced-area factor) ! rhoInf above which a dynamic run notes the missing numerical dissipation (run_deck_driver) REAL(wp), PARAMETER :: RHO_INF_NOTE = 0.95_wp @@ -436,6 +439,10 @@ MODULE CableDyn_DeckDriver REAL(wp) :: tors_nx(3, 2) = CD_ZERO REAL(wp) :: tors_pretwist(2) = CD_ZERO INTEGER :: deck_line = 0 ! deck file line of the row, for error messages + ! True when the anchor-first swap (normalize_stock_endpoint_order) exchanged the two ends: + ! the deck's written NodeB (MoorDyn's AttachB) is then End A, otherwise End B. Active line + ! control reads it for a line with no single host-driven end. + LOGICAL :: ends_swapped = .FALSE. ! ATTACHMENTS (finite-EI lines): one column per discrete attachment -- arc length from ! End A [m], mass [kg], displaced volume [m^3], drag area CdA [m^2], added-mass Ca [-], ! axial drag area CdAx [m^2] (rows 1-6). @@ -469,8 +476,9 @@ MODULE CableDyn_DeckDriver TYPE :: DeckControl !! One CONTROL row (MoorDyn cable control): ChannelID LineID[,LineID...]. - !! The host's DeltaL/DeltaLdot input for this channel modulates the LAST - !! (fairlead-side) segment's unstretched length of every listed line. + !! The host's DeltaL/DeltaLdot input for this channel modulates the unstretched length of + !! the fairlead-side segment of every listed line: the one at its end on a host-driven + !! point, or, when both or neither ends are, at the written NodeB (MoorDyn's AttachB). INTEGER :: channel = 0 INTEGER, ALLOCATABLE :: line_ids(:) END TYPE @@ -1013,13 +1021,31 @@ MODULE CableDyn_DeckDriver TYPE(DeckLine), ALLOCATABLE :: fail_lines(:) TYPE(DeckPoint), ALLOCATABLE :: fail_points(:) ! Active line control (CONTROL section), flattened per controlled line: the - ! host channel, the system line index, the LAST (fairlead-side) element, and - ! its base unstretched length -- l(N) = base + DeltaL(chan) each advance. + ! host channel and the deck line id. The controlled segment is the deck segment at + ! the line's fairlead-side end: the end on a host-driven point (Coupled, Vessel, + ! Turbine, Body, a Coupled/Vessel rod end), or, when both or neither ends are, + ! the written NodeB (MoorDyn's AttachB, its segment N); on a finite-EI line that is its + ! host-driven End A. + ! An EI = 0 row (ctrl_is_cable false) holds the system line index, that element and + ! its base unstretched length -- l = base + DeltaL(chan) each advance. A finite-EI row + ! holds the cable index, the first of the ctrl_nelem cable elements that make up that + ! segment, and the segment's base length S; their base lengths sit at + ! ctrl_span_l0(ctrl_span_off + 1:) and each scales by (S + DeltaL)/S. + ! ctrl_unstr_len and ctrl_nsegs are the deck line's unstretched length and segment + ! count (summed over its sections), MoorDyn-F's UnstrLen and N: its command bounds + ! -0.5 UnstrLen/N <= DeltaL <= UnstrLen/N. INTEGER :: n_ctrl_chans = 0 INTEGER, ALLOCATABLE :: ctrl_chan(:) INTEGER, ALLOCATABLE :: ctrl_line(:) INTEGER, ALLOCATABLE :: ctrl_elem(:) + INTEGER, ALLOCATABLE :: ctrl_nelem(:) REAL(wp), ALLOCATABLE :: ctrl_base_l0(:) + REAL(wp), ALLOCATABLE :: ctrl_unstr_len(:) + INTEGER, ALLOCATABLE :: ctrl_nsegs(:) + LOGICAL, ALLOCATABLE :: ctrl_is_cable(:) + INTEGER, ALLOCATABLE :: ctrl_line_id(:) + INTEGER, ALLOCATABLE :: ctrl_span_off(:) + REAL(wp), ALLOCATABLE :: ctrl_span_l0(:) ! Coupled Rigid6 bodies (pure EI=0 deck): the opaque runtime the facade marches over ! `sys` each mooring step. Populated only when the deck declares Rigid6 BODYs ! (has_rigid6); the facade MOVEs it onto its persistent module state. @@ -2928,6 +2954,12 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, IF (es /= CD_HFMF_OK) THEN CALL fail(ErrStat, ErrMsg, 'finite-EI Hermite contact wiring failed: '//TRIM(em)); RETURN END IF + ! The same kBot, diameters and cBot/kBot let active line control rebuild the nodal + ! coefficients when an unstretched length changes (the EI = 0 seabed recompute inputs). + CALL CD_HermiteCable_Dyn_Set_Control_Seabed(cable%line, opts%kbot, diam, opts%cbot/opts%kbot, es, em) + IF (es /= CD_HCDYN_OK) THEN + CALL fail(ErrStat, ErrMsg, 'finite-EI Hermite seabed recompute wiring failed: '//TRIM(em)); RETURN + END IF ! The static friction force of every node becomes the initial force of its ! elastic-plastic spring, so the march starts in the static equilibrium. IF (static_friction) THEN @@ -6040,7 +6072,7 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi TYPE(DeckFailure), ALLOCATABLE :: fails(:) TYPE(DeckControl), ALLOCATABLE :: ctrls(:) LOGICAL, ALLOCATABLE :: is_fin(:) - INTEGER :: i, c, n_fin, n_ei0, cn, es, j, k, nctrl_lines, ne_line + INTEGER :: i, c, n_fin, n_ei0, cn, es, j INTEGER :: n_rigid6, n_point3, n_rod, n_host_rod, n_host_body REAL(wp) :: fairlead_dcm(3, 3), host_dcm(3, 3) ! Preserve the complete multi-hierarchy finite-EI initialization diagnostic. @@ -6450,17 +6482,13 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi END IF END IF - ! CONTROL scope in the coupled aggregate: pure EI=0, non-farm decks (the - ! system wrapper drives the segment update; finite-EI cable control and farm - ! mode are not supported). + ! CONTROL scope in the coupled aggregate: non-farm decks. The system wrapper + ! drives the EI = 0 segment update and each finite-EI cable takes its own + ! (CD_HFMF_Set_SegmentLength); farm mode is not supported for either. IF (SIZE(ctrls) > 0) THEN IF (nturb > 0) THEN CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_Aggregate: CONTROL on a FAST.Farm deck is not supported'); RETURN END IF - IF (n_fin > 0) THEN - CALL fail(ErrStat, ErrMsg, 'CD_Init_Deck_Aggregate: CONTROL on a deck with finite-EI cables is '// & - 'not supported'); RETURN - END IF END IF ! FAILURE scope in the coupled aggregate: pure EI=0, non-farm, frictionless @@ -6569,65 +6597,6 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi agg%fail_lines = lines agg%fail_points = points END IF - ! CONTROL runtime table: flatten channel -> (system line, last element, base - ! length). The scope above guarantees a pure EI=0 deck, so deck line ids - ! resolve to system line indices by array position. - IF (SIZE(ctrls) > 0) THEN - nctrl_lines = 0 - DO i = 1, SIZE(ctrls) - nctrl_lines = nctrl_lines + SIZE(ctrls(i)%line_ids) - agg%n_ctrl_chans = MAX(agg%n_ctrl_chans, ctrls(i)%channel) - END DO - ALLOCATE (agg%ctrl_chan(nctrl_lines), agg%ctrl_line(nctrl_lines), agg%ctrl_elem(nctrl_lines), & - agg%ctrl_base_l0(nctrl_lines)) - c = 0 - DO i = 1, SIZE(ctrls) - DO k = 1, SIZE(ctrls(i)%line_ids) - c = c + 1 - agg%ctrl_chan(c) = ctrls(i)%channel - agg%ctrl_line(c) = 0 - DO j = 1, SIZE(lines) - IF (lines(j)%id == ctrls(i)%line_ids(k)) agg%ctrl_line(c) = j - END DO - IF (agg%ctrl_line(c) < 1) THEN - CALL fail(ErrStat, ErrMsg, 'CONTROL references a line the aggregate did not initialize') - CALL CD_End_Deck_Aggregate(agg); RETURN - END IF - ! Fairlead element + base length from the BUILT model, never re-derived - ! from the deck sections: the mesh builder reverses element order for - ! anchor_is_end_b lines, so on a composite line a sections-scan picks the - ! ANCHOR-side segment and a zero command would rewrite the fairlead - ! segment to the wrong length. The built l0 is the single truth. - ne_line = SIZE(agg%sys%lines(agg%ctrl_line(c))%l0) - IF (ne_line < 1) THEN - CALL fail(ErrStat, ErrMsg, 'CONTROL line has no elements') - CALL CD_End_Deck_Aggregate(agg); RETURN - END IF - agg%ctrl_elem(c) = ne_line - agg%ctrl_base_l0(c) = agg%sys%lines(agg%ctrl_line(c))%l0(ne_line) - ! Update capability is an INIT-time property: verify it here so the apply - ! loop can never fail for input reasons after its prevalidation (a mid-loop - ! failure would leave mixed lengths). The deck path always supplies the - ! seabed recompute inputs; this protects any future builder that does not. - IF (agg%sys%lines(agg%ctrl_line(c))%has_seabed .AND. & - .NOT. agg%sys%lines(agg%ctrl_line(c))%has_seabed_recompute) THEN - CALL fail(ErrStat, ErrMsg, 'CONTROL line was built without the seabed recompute inputs') - CALL CD_End_Deck_Aggregate(agg); RETURN - END IF - IF (agg%sys%lines(agg%ctrl_line(c))%has_viscoelastic) THEN - IF (agg%sys%lines(agg%ctrl_line(c))%ve_mode(ne_line) /= 0) THEN - ! same INIT-time rule: the runtime length update fails closed on a - ! viscoelastic element (the dl_1 state has no rescaling law), so a - ! deck composing CONTROL with a viscoelastic fairlead segment must - ! not start at all - CALL fail(ErrStat, ErrMsg, 'CONTROL targets a viscoelastic (ElasticMod 2) fairlead '// & - 'segment; active line control is not supported on the viscoelastic model') - CALL CD_End_Deck_Aggregate(agg); RETURN - END IF - END IF - END DO - END DO - END IF ! Build one coupled Hermite cable per finite-EI line (the production bending path). Each ! cable owns its own static-seeded dynamic model and its coupled fairlead node. @@ -6676,6 +6645,15 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi IF (opts%has_bathymetry_file) CALL CD_End_Bathymetry(bathymetry) END IF + ! CONTROL runtime table, from the built system lines and cables. + IF (SIZE(ctrls) > 0) THEN + CALL build_aggregate_control_table(ctrls, lines, points, rods, sections, types, is_fin, agg, & + ErrStat, ErrMsg) + IF (ErrStat /= CD_DECKDRV_OK) THEN + CALL CD_End_Deck_Aggregate(agg); RETURN + END IF + END IF + ! Retain the deck OUTPUTS channels and always build the deck-line-id -> object map. The ! map is also the authoritative line inventory for the coupled static profile, which is ! written even when the deck intentionally declares no time-history OUTPUTS channels. @@ -6748,6 +6726,213 @@ SUBROUTINE CD_Init_Deck_Aggregate(deck_path, dt, agg, ErrStat, ErrMsg, env_gravi END BLOCK END SUBROUTINE CD_Init_Deck_Aggregate + SUBROUTINE build_aggregate_control_table(ctrls, lines, points, rods, sections, types, is_fin, agg, ErrStat, ErrMsg) + !! CONTROL runtime table of the coupled aggregate: one row per controlled line, read + !! from the BUILT models, never re-derived from the deck sections (both mesh builders + !! reverse the deck's End A -> End B order). A deck line resolves to its object by its + !! rank among the lines of its kind in deck order -- the order in which the EI = 0 + !! system and the cables are built (build_line_object_map) -- so a deck mixing both + !! kinds addresses the right object. + !! The controlled segment is the one at the line's fairlead-side end: the end on a + !! host-driven point (Coupled, Vessel, Turbine, Body, or an end of a Coupled or + !! Vessel rod). When both ends or neither end are host-driven, it is the segment at + !! the NodeB the deck wrote (MoorDyn's AttachB, its segment N). The built models run + !! End B (node 1) -> End A (last node); the written NodeB is End A when the + !! anchor-first swap exchanged the ends and End B otherwise. + !! EI = 0 row: that end element of the system line and its base length. + !! Finite-EI row: the cable elements that make up the deck segment at that end, with + !! their base length S. The coupled cable builder runs a finite-EI line from its Fixed + !! anchor at End B to its Coupled/Vessel fairlead at End A, so the rule gives End A; a + !! finite-EI line whose End A is not its only host-driven end fails closed by name. + !! When the static solve refined the deck mesh, the span is the elements whose + !! reference-arc midpoint lies in that segment (the rule the property remap uses). + !! Each row also keeps the deck line's unstretched length and segment count (MoorDyn-F's + !! UnstrLen and N, summed over the line's sections), from which the apply takes + !! MoorDyn-F's command bounds. Every capability check runs here (a finite-EI line also + !! needs the force-blended generalised-alpha), so the apply loop cannot fail for input + !! reasons after its prevalidation. + TYPE(DeckControl), INTENT(IN) :: ctrls(:) + TYPE(DeckLine), INTENT(IN) :: lines(:) + TYPE(DeckPoint), INTENT(IN) :: points(:) + TYPE(DeckRod), INTENT(IN) :: rods(:) + TYPE(DeckSection), INTENT(IN) :: sections(:) + TYPE(DeckLineType), INTENT(IN) :: types(:) + LOGICAL, INTENT(IN) :: is_fin(:) + TYPE(CD_DeckAggregateType), INTENT(INOUT) :: agg + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + + INTEGER :: i, j, k, c, nrow, jline, obj, ne_line, first, e, es, parent_end + LOGICAL :: host_a, host_b + INTEGER, ALLOCATABLE :: conn(:, :), parent(:) + REAL(wp), ALLOCATABLE :: l0_deck(:), ea(:), mpl(:), diam(:), ei(:), gas(:), gj(:), i_rt(:), i_rn(:) + REAL(wp) :: span + CHARACTER(24) :: lid + CHARACTER(512) :: em + + ErrStat = CD_DECKDRV_OK + ErrMsg = '' + nrow = 0 + DO i = 1, SIZE(ctrls) + nrow = nrow + SIZE(ctrls(i)%line_ids) + agg%n_ctrl_chans = MAX(agg%n_ctrl_chans, ctrls(i)%channel) + END DO + ALLOCATE (agg%ctrl_chan(nrow), agg%ctrl_line(nrow), agg%ctrl_elem(nrow), agg%ctrl_nelem(nrow), & + agg%ctrl_base_l0(nrow), agg%ctrl_is_cable(nrow), agg%ctrl_line_id(nrow), agg%ctrl_span_off(nrow), & + agg%ctrl_span_l0(0), agg%ctrl_unstr_len(nrow), agg%ctrl_nsegs(nrow)) + c = 0 + DO i = 1, SIZE(ctrls) + DO k = 1, SIZE(ctrls(i)%line_ids) + c = c + 1 + agg%ctrl_chan(c) = ctrls(i)%channel + jline = 0 + DO j = 1, SIZE(lines) + IF (lines(j)%id == ctrls(i)%line_ids(k)) jline = j + END DO + IF (jline < 1) THEN + CALL fail(ErrStat, ErrMsg, 'CONTROL references a line the aggregate did not initialize'); RETURN + END IF + lid = int_to_str(lines(jline)%id) + obj = COUNT(is_fin(1:jline) .EQV. is_fin(jline)) + agg%ctrl_line(c) = obj + agg%ctrl_line_id(c) = lines(jline)%id + agg%ctrl_is_cable(c) = is_fin(jline) + agg%ctrl_span_off(c) = SIZE(agg%ctrl_span_l0) + agg%ctrl_nelem(c) = 1 + ! MoorDyn-F's UnstrLen and N of the line (the bounds of its command) + agg%ctrl_unstr_len(c) = CD_ZERO + agg%ctrl_nsegs(c) = 0 + DO j = 1, SIZE(sections) + IF (sections(j)%line_id /= lines(jline)%id) CYCLE + agg%ctrl_unstr_len(c) = agg%ctrl_unstr_len(c) + sections(j)%length + agg%ctrl_nsegs(c) = agg%ctrl_nsegs(c) + sections(j)%nsegs + END DO + IF (.NOT. (agg%ctrl_nsegs(c) > 0 .AND. agg%ctrl_unstr_len(c) > CD_ZERO)) THEN + CALL fail(ErrStat, ErrMsg, 'CONTROL line '//TRIM(lid)//' has no unstretched length and segment count'); RETURN + END IF + ! the fairlead-side end: the host-driven one, else the written NodeB + host_a = host_driven_point(lines(jline)%nodeA) + host_b = host_driven_point(lines(jline)%nodeB) + IF (.NOT. is_fin(jline)) THEN + IF (.NOT. agg%has_sys) THEN + CALL fail(ErrStat, ErrMsg, 'CONTROL line '//TRIM(lid)//' has no EI = 0 system line'); RETURN + END IF + IF (obj > SIZE(agg%sys%lines)) THEN + CALL fail(ErrStat, ErrMsg, 'CONTROL line '//TRIM(lid)//' has no EI = 0 system line'); RETURN + END IF + ne_line = SIZE(agg%sys%lines(obj)%l0) + IF (ne_line < 1) THEN + CALL fail(ErrStat, ErrMsg, 'CONTROL line has no elements'); RETURN + END IF + ! the fairlead-side element (End A is the last element, End B the first) + IF (host_a .NEQV. host_b) THEN + e = MERGE(ne_line, 1, host_a) + ELSE + e = MERGE(ne_line, 1, lines(jline)%ends_swapped) + END IF + agg%ctrl_elem(c) = e + agg%ctrl_base_l0(c) = agg%sys%lines(obj)%l0(e) + ! The deck path always supplies the seabed recompute inputs; this protects any + ! future builder that does not. + IF (agg%sys%lines(obj)%has_seabed .AND. .NOT. agg%sys%lines(obj)%has_seabed_recompute) THEN + CALL fail(ErrStat, ErrMsg, 'CONTROL line was built without the seabed recompute inputs'); RETURN + END IF + IF (agg%sys%lines(obj)%has_viscoelastic) THEN + IF (agg%sys%lines(obj)%ve_mode(e) /= 0) THEN + ! the runtime length update fails closed on a viscoelastic element (the + ! dl_1 state has no rescaling law), so a deck composing CONTROL with a + ! viscoelastic controlled segment must not start at all + CALL fail(ErrStat, ErrMsg, 'CONTROL targets a viscoelastic (ElasticMod 2) '// & + 'segment; active line control is not supported on the viscoelastic model'); RETURN + END IF + END IF + IF (agg%sys%lines(obj)%has_syrope) THEN + IF (agg%sys%lines(obj)%syrope_is(e)) THEN + ! the same rule for the Syrope working-curve states + CALL fail(ErrStat, ErrMsg, 'CONTROL line '//TRIM(lid)//' targets a Syrope segment; active '// & + 'line control is not supported on the Syrope model'); RETURN + END IF + END IF + ELSE + ! the coupled cable builder makes End A the host-driven fairlead and End B the + ! Fixed anchor; any other arrangement would control a segment that is not the + ! fairlead-side one, so it fails closed + IF (.NOT. (host_a .AND. .NOT. host_b)) THEN + CALL fail(ErrStat, ErrMsg, 'CONTROL line '//TRIM(lid)//': active line control of a finite-EI '// & + 'line needs its End A, the fairlead, to be its only host-driven end'); RETURN + END IF + IF (.NOT. ALLOCATED(agg%cables)) THEN + CALL fail(ErrStat, ErrMsg, 'CONTROL line '//TRIM(lid)//' has no finite-EI cable'); RETURN + END IF + IF (obj > SIZE(agg%cables)) THEN + CALL fail(ErrStat, ErrMsg, 'CONTROL line '//TRIM(lid)//' has no finite-EI cable'); RETURN + END IF + ASSOCIATE (cab => agg%cables(obj)%line) + IF (cab%torsion%active) THEN + CALL fail(ErrStat, ErrMsg, 'CONTROL line '//TRIM(lid)//': active line control of a finite-EI '// & + 'line restrained in torsion is not supported'); RETURN + END IF + IF (cab%has_contact .AND. .NOT. cab%has_seabed_recompute) THEN + CALL fail(ErrStat, ErrMsg, 'CONTROL line '//TRIM(lid)//' was built without the seabed '// & + 'recompute inputs'); RETURN + END IF + IF (.NOT. cab%force_blend) THEN + CALL fail(ErrStat, ErrMsg, 'CONTROL line '//TRIM(lid)//': '//CONTROL_NEEDS_FORCE_BLEND); RETURN + END IF + CALL build_finite_section_mesh(lines(jline), sections, types, conn, l0_deck, ea, mpl, diam, ei, & + gas, gj, i_rt, i_rn, es, em) + IF (es /= CD_DECKDRV_OK) THEN + CALL fail(ErrStat, ErrMsg, 'CONTROL line '//TRIM(lid)//': '//TRIM(em)); RETURN + END IF + CALL reference_arc_parents(l0_deck, cab%l0, parent) + ! the deck's End A segment (deck element SIZE(l0_deck)): the trailing span of + ! cable elements whose parent it is + parent_end = SIZE(l0_deck) + first = cab%ne + 1 + DO e = cab%ne, 1, -1 + IF (parent(e) /= parent_end) EXIT + first = e + END DO + span = CD_ZERO + DO e = first, cab%ne + span = span + cab%l0(e) + END DO + IF (first > cab%ne .OR. & + ABS(span - l0_deck(parent_end)) > 1.0e-9_wp*MAX(CD_ONE, l0_deck(parent_end))) THEN + CALL fail(ErrStat, ErrMsg, 'CONTROL line '//TRIM(lid)//': the controlled segment is not '// & + 'made up of whole cable elements'); RETURN + END IF + agg%ctrl_elem(c) = first + agg%ctrl_nelem(c) = cab%ne - first + 1 + agg%ctrl_base_l0(c) = span + agg%ctrl_span_l0 = [agg%ctrl_span_l0, cab%l0(first:cab%ne)] + END ASSOCIATE + END IF + END DO + END DO + + CONTAINS + + LOGICAL FUNCTION host_driven_point(id) RESULT(host) + !! True for a point the host drives: Coupled or Vessel (Turbine points are already + !! Coupled here), Body, or an end of a Coupled or Vessel rod. + INTEGER, INTENT(IN) :: id + INTEGER :: ip, ir, rod_id, end_id + host = .FALSE. + ip = find_point(points, id) + IF (ip < 1) RETURN + host = TRIM(points(ip)%ptype) == 'coupled' .OR. TRIM(points(ip)%ptype) == 'vessel' .OR. & + starts_with(TRIM(points(ip)%ptype), 'body') .OR. points(ip)%turbine_id > 0 + IF (host) RETURN + CALL parse_rod_point_type(points(ip)%ptype, rod_id, end_id) + IF (rod_id < 1 .OR. (end_id /= 1 .AND. end_id /= 2)) RETURN + DO ir = 1, SIZE(rods) + IF (rods(ir)%id == rod_id) host = TRIM(rods(ir)%rod_type) == 'coupled' .OR. & + TRIM(rods(ir)%rod_type) == 'vessel' + END DO + END FUNCTION host_driven_point + END SUBROUTINE build_aggregate_control_table + SUBROUTINE validate_aggregate_point_channels(channels, points, lines, is_fin, ErrStat, ErrMsg) CHARACTER(*), INTENT(IN) :: channels(:) TYPE(DeckPoint), INTENT(IN) :: points(:) @@ -7062,7 +7247,14 @@ SUBROUTINE CD_End_Deck_Aggregate(agg) IF (ALLOCATED(agg%ctrl_chan)) DEALLOCATE (agg%ctrl_chan) IF (ALLOCATED(agg%ctrl_line)) DEALLOCATE (agg%ctrl_line) IF (ALLOCATED(agg%ctrl_elem)) DEALLOCATE (agg%ctrl_elem) + IF (ALLOCATED(agg%ctrl_nelem)) DEALLOCATE (agg%ctrl_nelem) IF (ALLOCATED(agg%ctrl_base_l0)) DEALLOCATE (agg%ctrl_base_l0) + IF (ALLOCATED(agg%ctrl_unstr_len)) DEALLOCATE (agg%ctrl_unstr_len) + IF (ALLOCATED(agg%ctrl_nsegs)) DEALLOCATE (agg%ctrl_nsegs) + IF (ALLOCATED(agg%ctrl_is_cable)) DEALLOCATE (agg%ctrl_is_cable) + IF (ALLOCATED(agg%ctrl_line_id)) DEALLOCATE (agg%ctrl_line_id) + IF (ALLOCATED(agg%ctrl_span_off)) DEALLOCATE (agg%ctrl_span_off) + IF (ALLOCATED(agg%ctrl_span_l0)) DEALLOCATE (agg%ctrl_span_l0) ! Release the Rigid6 runtime and clear the flag: without this a REUSED bundle (or a ! failed re-init that routes through here) would keep a stale has_rigid6 = .TRUE. and the ! previous deck's body allocatables, so a later non-Rigid6 deck could march a stale body. @@ -8442,26 +8634,42 @@ SUBROUTINE remap_elem_by_reference_arc(a, l0_parent, l0_child) REAL(wp), ALLOCATABLE, INTENT(INOUT) :: a(:) REAL(wp), INTENT(IN) :: l0_parent(:), l0_child(:) REAL(wp), ALLOCATABLE :: b(:) - REAL(wp) :: s_mid, s_child, s_parent_end, tol_arc - INTEGER :: j, parent + INTEGER, ALLOCATABLE :: parent(:) IF (SIZE(l0_child) == SIZE(l0_parent)) RETURN - ALLOCATE (b(SIZE(l0_child))) - parent = 1 + CALL reference_arc_parents(l0_parent, l0_child, parent) + b = a(parent) + CALL MOVE_ALLOC(b, a) + END SUBROUTINE remap_elem_by_reference_arc + + SUBROUTINE reference_arc_parents(l0_parent, l0_child, parent) + !! The parent element of every child element of a nested child mesh: the parent whose + !! reference arc contains the child's midpoint (the rule of remap_elem_by_reference_arc). + !! Meshes of equal size map element to element. + REAL(wp), INTENT(IN) :: l0_parent(:), l0_child(:) + INTEGER, ALLOCATABLE, INTENT(OUT) :: parent(:) + REAL(wp) :: s_mid, s_child, s_parent_end, tol_arc + INTEGER :: j, p + + ALLOCATE (parent(SIZE(l0_child))) + IF (SIZE(l0_child) == SIZE(l0_parent)) THEN + parent = [(j, j=1, SIZE(l0_child))] + RETURN + END IF + p = 1 s_child = CD_ZERO s_parent_end = l0_parent(1) tol_arc = 64.0_wp*EPSILON(CD_ONE)*MAX(CD_ONE, SUM(l0_parent)) DO j = 1, SIZE(l0_child) s_mid = s_child + 0.5_wp*l0_child(j) - DO WHILE (parent < SIZE(l0_parent) .AND. s_mid > s_parent_end + tol_arc) - parent = parent + 1 - s_parent_end = s_parent_end + l0_parent(parent) + DO WHILE (p < SIZE(l0_parent) .AND. s_mid > s_parent_end + tol_arc) + p = p + 1 + s_parent_end = s_parent_end + l0_parent(p) END DO - b(j) = a(parent) + parent(j) = p s_child = s_child + l0_child(j) END DO - CALL MOVE_ALLOC(b, a) - END SUBROUTINE remap_elem_by_reference_arc + END SUBROUTINE reference_arc_parents SUBROUTINE deck_node_mesh_map(l0_deck, l0_mesh, map) !! The public node (End A = 1) of a finite-EI line's final mesh at each deck node, matched on @@ -13689,6 +13897,7 @@ SUBROUTINE normalize_stock_endpoint_order(points, lines, sections) tmp = lines(i)%nodeA lines(i)%nodeA = lines(i)%nodeB lines(i)%nodeB = tmp + lines(i)%ends_swapped = .TRUE. mode_tmp = lines(i)%endconn_mode(1) lines(i)%endconn_mode(1) = lines(i)%endconn_mode(2) lines(i)%endconn_mode(2) = mode_tmp @@ -32601,8 +32810,14 @@ REAL(wp) FUNCTION cable_axial_tension(cable, e, xi) RESULT(t) IF (cable%line%has_axial_damping) THEN vr(1:6) = cable%line%v(6*(e - 1) + 1:6*(e - 1) + 6) vr(7:12) = cable%line%v(6*e + 1:6*e + 6) - CALL CD_HermiteCable_Axial_Damping_Resultant(qr, vr, l0, cable%line%BA(e), xi, & - viscous, es, em) + IF (cable%line%has_ctrl) THEN + ! active line control: the strain rate includes the unstretched-length rate + CALL CD_HermiteCable_Axial_Damping_Resultant(qr, vr, l0, cable%line%BA(e), xi, & + viscous, es, em, l0_dot=cable%line%l0_dot(e)) + ELSE + CALL CD_HermiteCable_Axial_Damping_Resultant(qr, vr, l0, cable%line%BA(e), xi, & + viscous, es, em) + END IF IF (es /= 0) THEN t = CD_ZERO ELSE diff --git a/src/CableDyn_Dynamic.f90 b/src/CableDyn_Dynamic.f90 index 06274e55..03df8de5 100644 --- a/src/CableDyn_Dynamic.f90 +++ b/src/CableDyn_Dynamic.f90 @@ -627,7 +627,7 @@ SUBROUTINE CD_Cable_Gen_Alpha_Step(q, v, a, elem_conn, l0, ea, rho_a, tension_on load_band_proc, prescribed_q, prescribed_v, prescribed_a, structural_mass, & workspace, added_mass_band_proc, start_load, start_tension, & probe_q, probe_R, probe_K, start_stiffness, axial_damping, & - axial_l0_rate) + axial_l0_rate, start_l0, mass_l0, start_l0_rate) !! One generalized-alpha step: the constant load f_ext plus the optional load, !! banded-load, force-only and added-mass callbacks (hydrodynamics, damping, contact). !! On a singular effective tangent returns CD_DYN_SINGULAR; on a line-search @@ -708,6 +708,18 @@ SUBROUTINE CD_Cable_Gen_Alpha_Step(q, v, a, elem_conn, l0, ea, rho_a, tension_on !! are passed together; the state outputs are the t_n state, converged = .FALSE. REAL(wp), INTENT(IN), OPTIONAL :: probe_q(:) REAL(wp), INTENT(OUT), OPTIONAL :: probe_R(:), probe_K(:, :) + !! Unstretched lengths changed between t_n and t_{n+1} (active line control; n_elem each, + !! finite and positive). l0 is then the length at t_{n+1}, which r(q_{n+1}, v_{n+1}) and + !! the release cap's end stretch use. start_l0 (force blend only, ignored without it): the + !! lengths the step-start state was reached with, which the step-start internal force + !! r(q_n) and the release cap's step-start quantities use: e_n, T_n, W_n and the + !! step-start dashpot tension T_d,n (start_load, start_tension and start_stiffness must + !! then be those of these lengths). mass_l0: the lengths of the structural consistent mass + !! (ignored with structural_mass). Absent: l0. start_l0_rate (force blend with + !! axial_damping only): the unstretched-length rates the step-start state was reached + !! with, for T_d,n; axial_l0_rate stays the rate at t_{n+1}, for T_d,n+1. Absent: + !! axial_l0_rate. + REAL(wp), INTENT(IN), OPTIONAL :: start_l0(:), mass_l0(:), start_l0_rate(:) INTEGER :: n_dof, n_elem, n_free, bt, kl, ku, ldab INTEGER, POINTER :: free(:), fixed(:), ipiv(:) @@ -844,6 +856,36 @@ SUBROUTINE CD_Cable_Gen_Alpha_Step(q, v, a, elem_conn, l0, ea, rho_a, tension_on CALL check_config(cfg, ErrStat, ErrMsg) IF (ErrStat /= 0) RETURN n_elem = SIZE(elem_conn, 2) + IF (PRESENT(start_l0)) THEN + IF (SIZE(start_l0) /= n_elem) THEN + CALL fail(ErrStat, ErrMsg, 'start_l0 must have shape (n_elem)') + RETURN + END IF + IF (.NOT. CD_All_Finite(start_l0) .OR. ANY(start_l0 <= CD_ZERO)) THEN + CALL fail(ErrStat, ErrMsg, 'start_l0 must be finite and positive') + RETURN + END IF + END IF + IF (PRESENT(mass_l0)) THEN + IF (SIZE(mass_l0) /= n_elem) THEN + CALL fail(ErrStat, ErrMsg, 'mass_l0 must have shape (n_elem)') + RETURN + END IF + IF (.NOT. CD_All_Finite(mass_l0) .OR. ANY(mass_l0 <= CD_ZERO)) THEN + CALL fail(ErrStat, ErrMsg, 'mass_l0 must be finite and positive') + RETURN + END IF + END IF + IF (PRESENT(start_l0_rate)) THEN + IF (SIZE(start_l0_rate) /= n_elem) THEN + CALL fail(ErrStat, ErrMsg, 'start_l0_rate must have shape (n_elem)') + RETURN + END IF + IF (.NOT. CD_All_Finite(start_l0_rate)) THEN + CALL fail(ErrStat, ErrMsg, 'start_l0_rate must be finite') + RETURN + END IF + END IF IF (PRESENT(workspace)) THEN work => workspace ELSE @@ -907,7 +949,11 @@ SUBROUTINE CD_Cable_Gen_Alpha_Step(q, v, a, elem_conn, l0, ea, rho_a, tension_on END IF M = structural_mass ELSE IF (.NOT. use_element_mass_band) THEN - CALL CD_Assemble_Cable_Mass(elem_conn, l0, rho_a, M, es, em) + IF (PRESENT(mass_l0)) THEN + CALL CD_Assemble_Cable_Mass(elem_conn, mass_l0, rho_a, M, es, em) + ELSE + CALL CD_Assemble_Cable_Mass(elem_conn, l0, rho_a, M, es, em) + END IF IF (es /= 0) THEN CALL fail(ErrStat, ErrMsg, 'mass assembly failed: '//TRIM(em)) RETURN @@ -1050,16 +1096,26 @@ SUBROUTINE CD_Cable_Gen_Alpha_Step(q, v, a, elem_conn, l0, ea, rho_a, tension_on IF (use_element_mass_band) THEN ! The element mass band depends only on the connectivity, the free list, l0 and ! rho_a: a step with the inputs of the remembered band (bw_hit: same connectivity and - ! free list) reuses it, which is the band the assembly would build again. + ! free list) reuses it, which is the band the assembly would build again. Its lengths + ! are mass_l0 when present. mb_hit = .FALSE. - IF (bw_hit) mb_hit = mass_band_matches(work, l0, rho_a) - IF (.NOT. mb_hit) THEN - work%mb_valid = .FALSE. - CALL assemble_mass_band_free(elem_conn, l0, rho_a, work%dof_marker(1:n_dof), kl, ku, M_band, es, em) - IF (es == 0 .AND. work%bw_valid) CALL remember_mass_band(work, l0, rho_a) - ELSE IF (work%mb_hits < HUGE(work%mb_hits)) THEN - work%mb_hits = work%mb_hits + 1 + IF (PRESENT(mass_l0)) THEN + IF (bw_hit) mb_hit = mass_band_matches(work, mass_l0, rho_a) + IF (.NOT. mb_hit) THEN + work%mb_valid = .FALSE. + CALL assemble_mass_band_free(elem_conn, mass_l0, rho_a, work%dof_marker(1:n_dof), kl, ku, M_band, & + es, em) + IF (es == 0 .AND. work%bw_valid) CALL remember_mass_band(work, mass_l0, rho_a) + END IF + ELSE + IF (bw_hit) mb_hit = mass_band_matches(work, l0, rho_a) + IF (.NOT. mb_hit) THEN + work%mb_valid = .FALSE. + CALL assemble_mass_band_free(elem_conn, l0, rho_a, work%dof_marker(1:n_dof), kl, ku, M_band, es, em) + IF (es == 0 .AND. work%bw_valid) CALL remember_mass_band(work, l0, rho_a) + END IF END IF + IF (mb_hit .AND. work%mb_hits < HUGE(work%mb_hits)) work%mb_hits = work%mb_hits + 1 ELSE work%mb_valid = .FALSE. CALL pack_dense_free_band(M, free, kl, ku, CD_ONE, M_band, es, em) @@ -1508,14 +1564,21 @@ END SUBROUTINE end_junction_data SUBROUTINE start_forces(es_s, em_s) !! fint_n = f_int(q_n) and load_n = the dynamic load at (q_n, v_n): start_load when the - !! caller supplies it, else the force-only callback (or load_proc) evaluated there. + !! caller supplies it, else the force-only callback (or load_proc) evaluated there. The + !! internal force and the release-cap data take the lengths the step-start state was + !! reached with (start_l0 when present). INTEGER, INTENT(OUT) :: es_s CHARACTER(*), INTENT(OUT) :: em_s INTEGER :: i es_s = 0 em_s = '' - CALL CD_Assemble_Cable_Internal_Force(q_n_nodes, elem_conn, l0, ea, tension_only, fint_n, es_s, em_s, & - topology_validated=topo_ok) + IF (PRESENT(start_l0)) THEN + CALL CD_Assemble_Cable_Internal_Force(q_n_nodes, elem_conn, start_l0, ea, tension_only, fint_n, es_s, & + em_s, topology_validated=topo_ok) + ELSE + CALL CD_Assemble_Cable_Internal_Force(q_n_nodes, elem_conn, l0, ea, tension_only, fint_n, es_s, em_s, & + topology_validated=topo_ok) + END IF IF (es_s /= 0) THEN es_s = CD_DYN_BADINPUT em_s = 'step-start internal-force assembly failed: '//TRIM(em_s) @@ -1577,11 +1640,13 @@ SUBROUTINE start_forces(es_s, em_s) IF (release_cap) THEN DO i = 1, n_elem BLOCK - REAL(wp) :: d(3), ell + REAL(wp) :: d(3), ell, l0s d = q_n_nodes(:, elem_conn(2, i)) - q_n_nodes(:, elem_conn(1, i)) ell = NORM2(d) + l0s = l0(i) + IF (PRESENT(start_l0)) l0s = start_l0(i) chord_n(:, i) = d/ell - stretch_n(i) = ell - l0(i) + stretch_n(i) = ell - l0s tension_n(i) = CD_ZERO stiff_n(i) = HUGE(CD_ONE) dcoef_n(i) = CD_ZERO @@ -1589,16 +1654,34 @@ SUBROUTINE start_forces(es_s, em_s) damp_n(i) = CD_ZERO IF (ea(i) > CD_ZERO .AND. PRESENT(axial_damping)) THEN IF (axial_damping(i) > CD_ZERO) THEN - ! the dashpot tension the start load carries, as the callback evaluates it + ! the dashpot coefficient and payout rate of the end share (lengths at t_{n+1}) dcoef_n(i) = axial_damping(i)/l0(i) IF (PRESENT(axial_l0_rate)) rl0dot_n(i) = axial_l0_rate(i)/l0(i) - damp_n(i) = dcoef_n(i)*(DOT_PRODUCT(chord_n(:, i), v_n(3*elem_conn(2, i) - 2:3*elem_conn(2, i)) - & - v_n(3*elem_conn(1, i) - 2:3*elem_conn(1, i))) - ell*rl0dot_n(i)) + IF (PRESENT(start_l0) .OR. PRESENT(start_l0_rate)) THEN + ! after a length change the start load's dashpot has the step-start lengths + ! and rates + BLOCK + REAL(wp) :: dcs, rrs + dcs = axial_damping(i)/l0s + rrs = CD_ZERO + IF (PRESENT(start_l0_rate)) THEN + rrs = start_l0_rate(i)/l0s + ELSE IF (PRESENT(axial_l0_rate)) THEN + rrs = axial_l0_rate(i)/l0s + END IF + damp_n(i) = dcs*(DOT_PRODUCT(chord_n(:, i), v_n(3*elem_conn(2, i) - 2:3*elem_conn(2, i)) - & + v_n(3*elem_conn(1, i) - 2:3*elem_conn(1, i))) - ell*rrs) + END BLOCK + ELSE + ! the dashpot tension the start load carries, as the callback evaluates it + damp_n(i) = dcoef_n(i)*(DOT_PRODUCT(chord_n(:, i), v_n(3*elem_conn(2, i) - 2:3*elem_conn(2, i)) - & + v_n(3*elem_conn(1, i) - 2:3*elem_conn(1, i))) - ell*rl0dot_n(i)) + END IF END IF END IF IF (stretch_n(i) > CD_ZERO) THEN IF (ea(i) > CD_ZERO) THEN - tension_n(i) = ea(i)*(ell/l0(i) - CD_ONE) + tension_n(i) = ea(i)*(ell/l0s - CD_ONE) ELSE IF (PRESENT(start_tension)) THEN tension_n(i) = MAX(start_tension(i), CD_ZERO) IF (PRESENT(start_stiffness)) stiff_n(i) = start_stiffness(i) @@ -2026,13 +2109,13 @@ SUBROUTINE eval_dynamic(q_eval, Rout, es_e, em_e, effout, effbandout) ! (= structural_mass when supplied). Recomputing from elem_conn/l0/rho_a here ! would ignore a supplied structural_mass while the Jacobian honored it. IF (use_element_mass_band) THEN - CALL consistent_mass_matvec(elem_conn, l0, rho_a, a_alpha, Rout) + CALL structural_inertia(Rout) ELSE Rout = MATMUL(M, a_alpha) END IF Rout = Rout + M_add_a_eval + fint_eval - f_ext - load_eval ELSE IF (use_element_mass_band) THEN - CALL consistent_mass_matvec(elem_conn, l0, rho_a, a_alpha, Rout) + CALL structural_inertia(Rout) Rout = Rout + fint_eval - f_ext - load_eval ELSE Rout = MATMUL(M, a_alpha) + fint_eval - f_ext - load_eval @@ -2068,6 +2151,17 @@ SUBROUTINE eval_dynamic(q_eval, Rout, es_e, em_e, effout, effbandout) END IF END SUBROUTINE eval_dynamic + SUBROUTINE structural_inertia(Rout) + !! Rout = M a_alpha with the element consistent mass (of mass_l0 when present, the lengths + !! the mass band was built from). + REAL(wp), INTENT(OUT) :: Rout(:) + IF (PRESENT(mass_l0)) THEN + CALL consistent_mass_matvec(elem_conn, mass_l0, rho_a, a_alpha, Rout) + ELSE + CALL consistent_mass_matvec(elem_conn, l0, rho_a, a_alpha, Rout) + END IF + END SUBROUTINE structural_inertia + SUBROUTINE apply_release_cap(q_eval, Rout, effout, effbandout) !! Release cap of the force blend. A tension-only element taut at t_n (tension T_0, !! stretch e_0 = l_n - l0 > 0, chord d_0 = l_n t_0) carries alpha_f T_0 along its @@ -2133,12 +2227,24 @@ SUBROUTINE apply_release_cap(q_eval, Rout, effout, effbandout) !! T_d,0 |ldot_0| dt plus the end share's credit. The capped force grows without bound as !! p -> 0 (W_d > 0), so the force is continuous there; alpha_f |p| <= |ldot_0| dt is a !! sufficient test of an inactive cap. The same law covers a compressive T_d,0 (p < 0). + !! After a length change W_d and ldot_0 take the step-start lengths and rates (BA/l0_c, + !! l_n l0_dot_c/l0_c), as T_d,0 does, and the end share's T_d,1 the new ones. + !! After a length change (start_l0) every step-start quantity takes the lengths and rates + !! the step-start state was reached with: e_0 = l_n - l0_c, T_0, W_0, the secant T_0/e_0, + !! the law stiffness k_n and the dashpot tension T_d,0 (start_l0_rate); the end-state + !! quantities take those at t_{n+1}: e_1 = |d_1| - l0, T^_1 = k e_1, T_d,1 and the + !! dashpot weight phi, whose band runs from l0 to l0 + c e_0 (the end stretch against the + !! new length, the band width set by the step-start stretch, as without a change). p and + !! p_1 are the geometric projections above (l_n = l0_c + e_0). A haul-in (l0 < l0_c) can + !! make p_1 more negative, so N is bounded below by zero there too, and the inactive-cap + !! test uses the bound N >= W_0 - (1 - alpha_f) T_0 (l_n - l0)^2/(4 e_0), which is W_0/2 + !! without a change. REAL(wp), INTENT(IN) :: q_eval(:) REAL(wp), INTENT(INOUT) :: Rout(:) REAL(wp), INTENT(INOUT), OPTIONAL :: effout(:, :), effbandout(:, :) INTEGER :: e, na, nb, i, j, gi(6), fi, fj REAL(wp) :: d1(3), l1, e1, e0, t0, p, p1, num, ln, k0, ten1, cosang, dg, delta, t1(3), g(3), blk(3, 3), sgn - REAL(wp) :: band, phi, dphi, td1, dv(3), dp1(3), dtd1(3), kc, credit + REAL(wp) :: band, phi, dphi, td1, dv(3), dp1(3), dtd1(3), kc, credit, ls, nlb, dcs LOGICAL :: taut_end, damped, slack band = alpha_f/(CD_ONE - alpha_f) DO e = 1, n_elem @@ -2152,9 +2258,12 @@ SUBROUTINE apply_release_cap(q_eval, Rout, effout, effbandout) nb = elem_conn(2, e) d1 = q_eval(3*nb - 2:3*nb) - q_eval(3*na - 2:3*na) e0 = stretch_n(e) - ! projected shortening p = l_n - t_0 . d_1 (l_n = l0 + e_0); the common case, an element + ! the rest length of the step-start state (the committed one after a length change) + ls = l0(e) + IF (PRESENT(start_l0)) ls = start_l0(e) + ! projected shortening p = l_n - t_0 . d_1 (l_n = ls + e_0); the common case, an element ! that does not release, is decided here without a root - p = e0 + (l0(e) - (chord_n(1, e)*d1(1) + chord_n(2, e)*d1(2) + chord_n(3, e)*d1(3))) + p = e0 + (ls - (chord_n(1, e)*d1(1) + chord_n(2, e)*d1(2) + chord_n(3, e)*d1(3))) ! a damped element taut at t_n whose end state lies below the band edge l0 + band e_0 damped = .FALSE. IF (.NOT. slack) THEN @@ -2163,12 +2272,15 @@ SUBROUTINE apply_release_cap(q_eval, Rout, effout, effbandout) END IF IF (slack) THEN ! the kept dashpot share alpha_f T_d,0 returns work only when T_d,0 p > 0, and stays - ! within W_d = T_d,0^2 dt/(BA/l0) while alpha_f |p| <= |ldot_0| dt + ! within W_d = T_d,0^2 dt/(BA/l0) while alpha_f |p| <= |ldot_0| dt (BA/l0_c after a + ! length change: the dashpot coefficient T_d,0 was evaluated with) IF (.NOT. damp_n(e)*p > CD_ZERO) CYCLE - IF (alpha_f*ABS(p)*dcoef_n(e) <= ABS(damp_n(e))*dt) CYCLE + dcs = dcoef_n(e) + IF (PRESENT(start_l0)) dcs = axial_damping(e)/ls + IF (alpha_f*ABS(p)*dcs <= ABS(damp_n(e))*dt) CYCLE l1 = NORM2(d1) IF (.NOT. l1 > CD_ZERO) CYCLE - ln = l0(e) + e0 + ln = ls + e0 t1 = d1/l1 cosang = t1(1)*chord_n(1, e) + t1(2)*chord_n(2, e) + t1(3)*chord_n(3, e) p1 = (l1 - ln) + 0.5_wp*ln*((t1(1) - chord_n(1, e))**2 + (t1(2) - chord_n(2, e))**2 + & @@ -2176,7 +2288,7 @@ SUBROUTINE apply_release_cap(q_eval, Rout, effout, effbandout) dv = v_eval(3*nb - 2:3*nb) - v_eval(3*na - 2:3*na) td1 = dcoef_n(e)*(DOT_PRODUCT(t1, dv) - l1*rl0dot_n(e)) credit = (CD_ONE - alpha_f)*td1*p1 - num = damp_n(e)*damp_n(e)*dt/dcoef_n(e) + MAX(credit, CD_ZERO) + num = damp_n(e)*damp_n(e)*dt/dcs + MAX(credit, CD_ZERO) dg = num/p IF (ABS(dg) >= alpha_f*ABS(damp_n(e))) CYCLE delta = dg - alpha_f*damp_n(e) @@ -2196,11 +2308,13 @@ SUBROUTINE apply_release_cap(q_eval, Rout, effout, effbandout) l1 = NORM2(d1) IF (.NOT. l1 > CD_ZERO) CYCLE e1 = l1 - l0(e) - ln = l0(e) + e0 + ln = ls + e0 t1 = d1/l1 cosang = t1(1)*chord_n(1, e) + t1(2)*chord_n(2, e) + t1(3)*chord_n(3, e) p1 = (e1 - e0) + 0.5_wp*ln*((t1(1) - chord_n(1, e))**2 + (t1(2) - chord_n(2, e))**2 + & (t1(3) - chord_n(3, e))**2) + ! |d_1| - l_n = (e_1 - e_0) + (l0 - ls) after a length change + IF (PRESENT(start_l0)) p1 = p1 + (l0(e) - ls) k0 = MIN(t0/e0, stiff_n(e)) ten1 = k0*MAX(e1, CD_ZERO) ! the dashpot weight and its slope along t_1 (zero at and below l0) @@ -2233,7 +2347,14 @@ SUBROUTINE apply_release_cap(q_eval, Rout, effout, effbandout) IF (e1 > CD_ZERO) g = g + ((CD_ONE - alpha_f)/p)*k0*p1*t1 END IF ELSE - IF (.NOT. 4.0_wp*alpha_f*p > e0) CYCLE + IF (PRESENT(start_l0)) THEN + ! N >= W_0 - (1 - alpha_f) T_0 (l_n - l0)^2/(4 e_0), l_n - l0 = e_0 + ls - l0 + nlb = 0.5_wp*t0*e0 - (CD_ONE - alpha_f)*t0*MAX(e0 + (ls - l0(e)), CD_ZERO)**2/(4.0_wp*e0) + ! (p > 0 as well: the bound can be negative after a haul-in) + IF (.NOT. (p > CD_ZERO .AND. alpha_f*t0*p > nlb)) CYCLE + ELSE + IF (.NOT. 4.0_wp*alpha_f*p > e0) CYCLE + END IF num = 0.5_wp*t0*e0 taut_end = d1(1)*d1(1) + d1(2)*d1(2) + d1(3)*d1(3) > l0(e)*l0(e) l1 = CD_ZERO @@ -2247,7 +2368,7 @@ SUBROUTINE apply_release_cap(q_eval, Rout, effout, effbandout) taut_end = e1 > CD_ZERO END IF IF (taut_end) THEN - ln = l0(e) + e0 + ln = ls + e0 ! the secant stiffness, bounded for a law element by its step-start axial stiffness k0 = MIN(t0/e0, stiff_n(e)) ten1 = k0*e1 @@ -2255,9 +2376,11 @@ SUBROUTINE apply_release_cap(q_eval, Rout, effout, effbandout) cosang = t1(1)*chord_n(1, e) + t1(2)*chord_n(2, e) + t1(3)*chord_n(3, e) p1 = (e1 - e0) + 0.5_wp*ln*((t1(1) - chord_n(1, e))**2 + (t1(2) - chord_n(2, e))**2 + & (t1(3) - chord_n(3, e))**2) + IF (PRESENT(start_l0)) p1 = p1 + (l0(e) - ls) num = num + (CD_ONE - alpha_f)*ten1*p1 END IF - dg = num/p + ! num >= W_0/2 > 0 without a length change; a haul-in can drive it below zero + dg = MAX(num, CD_ZERO)/p IF (dg >= alpha_f*t0) CYCLE delta = dg - alpha_f*t0 Rout(3*na - 2:3*na) = Rout(3*na - 2:3*na) - delta*chord_n(:, e) @@ -2265,9 +2388,12 @@ SUBROUTINE apply_release_cap(q_eval, Rout, effout, effbandout) IF (.NOT. (PRESENT(effout) .OR. PRESENT(effbandout))) CYCLE ! d(delta)/d(x_b) = g, d(delta)/d(x_a) = -g, with dp/dd_1 = -t_0, ! dT_1/dd_1 = k0 t_1 and dp_1/dd_1 = t_1 - (l_n/|d_1|)(t_0 - (t_1 . t_0) t_1) - g = (num/(p*p))*chord_n(:, e) - IF (taut_end) g = g + ((CD_ONE - alpha_f)/p)*((k0*p1 + ten1)*t1 - & - ten1*(ln/l1)*(chord_n(:, e) - cosang*t1)) + g = CD_ZERO + IF (num > CD_ZERO) THEN + g = (num/(p*p))*chord_n(:, e) + IF (taut_end) g = g + ((CD_ONE - alpha_f)/p)*((k0*p1 + ten1)*t1 - & + ten1*(ln/l1)*(chord_n(:, e) - cosang*t1)) + END IF END IF DO j = 1, 3 DO i = 1, 3 diff --git a/src/CableDyn_HermiteCableDynamic.f90 b/src/CableDyn_HermiteCableDynamic.f90 index 43d8195d..02a635a3 100644 --- a/src/CableDyn_HermiteCableDynamic.f90 +++ b/src/CableDyn_HermiteCableDynamic.f90 @@ -72,6 +72,7 @@ MODULE CableDyn_HermiteCableDynamic USE CableDyn_Bathymetry, ONLY: CD_BathymetryType, CD_Bathymetry_Is_Initialized, & CD_Bathymetry_Floor_Gradient, CD_End_Bathymetry, CD_BATHY_OK, & CD_Bathymetry_Rotate_Curvature + USE CableDyn_Line, ONLY: CD_Nodal_Seabed_Stiffness, CD_LINE_OK USE CableDyn_HermiteTorsion, ONLY: CD_HermiteTorsionType, CD_HermiteTorsion_Line, CD_HermiteTorsion_Unwrap, & CD_HermiteTorsion_Compliance, CD_HermiteTorsion_Validate, CD_HTORS_OK, & CD_HTORS_MAX_STEP, CD_HermiteTorsionWorkType, CD_HermiteTorsion_Work_Init, & @@ -105,6 +106,9 @@ MODULE CableDyn_HermiteCableDynamic PUBLIC :: CD_HermiteCable_Dyn_Set_Attachments PUBLIC :: CD_HermiteCable_Attachment_Drag PUBLIC :: CD_HermiteCable_Dyn_Recompute_Acceleration + PUBLIC :: CD_HermiteCable_Dyn_Set_SegmentLength + PUBLIC :: CD_HermiteCableControlSaveType, CD_HermiteCable_Dyn_Save_Control, CD_HermiteCable_Dyn_Restore_Control + PUBLIC :: CD_HermiteCable_Dyn_Set_Control_Seabed PUBLIC :: CD_HermiteCable_Dyn_Set_Irregular_Waves PUBLIC :: CD_HermiteCable_Drag_Element PUBLIC :: CD_HermiteCable_Axial_Damping_Element @@ -192,6 +196,26 @@ MODULE CableDyn_HermiteCableDynamic ! axial quadrature as the elastic resultant. Off by default. LOGICAL :: has_axial_damping = .FALSE. REAL(wp), ALLOCATABLE :: BA(:) + ! Active line control (CD_HermiteCable_Dyn_Set_SegmentLength): a host changes the + ! unstretched lengths l0 of chosen elements between steps. has_ctrl is set by the first + ! change; from then on l0_dot(ne) holds the unstretched-length rate of every element + ! (zero outside the controlled span), which the axial damping subtracts from the strain + ! rate. A model that is never controlled leaves has_ctrl false and l0_dot unallocated, so + ! every evaluation is unchanged. BA keeps its initial resolution. + LOGICAL :: has_ctrl = .FALSE. + REAL(wp), ALLOCATABLE :: l0_dot(:) + ! The lengths and rates the committed state was reached with (allocated with l0_dot, set + ! at each commit): the force-blended committed force F_n = R(q_n, v_n, t_n) belongs to + ! them, so the first step after a length change blends F_n at these lengths with + ! R(q_{n+1}) at the new ones. ws_recovery_l0_c/ws_recovery_l0_dot_c are the step-start + ! copies of the recovering step. + REAL(wp), ALLOCATABLE :: l0_c(:), l0_dot_c(:), ws_recovery_l0_c(:), ws_recovery_l0_dot_c(:) + ! Seabed recompute inputs of a controlled contact model (CD_HermiteCable_Dyn_Set_Control_Seabed): + ! the per-area penalty kBot, the per-element contact diameter and cBot/kBot, so a length + ! change rebuilds contact_kn/contact_cn with the helper the deck used at initialisation. + LOGICAL :: has_seabed_recompute = .FALSE. + REAL(wp) :: seabed_kbot = CD_ZERO, seabed_cn_over_kn = CD_ZERO + REAL(wp), ALLOCATABLE :: seabed_diameter_elem(:) REAL(wp) :: seabed_z = CD_ZERO, kn = CD_ZERO REAL(wp), ALLOCATABLE :: trib(:) ! nodal tributary length ! Production standalone contact. contact_kn/contact_cn are nodal coefficients [N/m] @@ -311,6 +335,9 @@ MODULE CableDyn_HermiteCableDynamic LOGICAL :: a_restored = .FALSE. INTEGER, ALLOCATABLE :: att_node(:) REAL(wp), ALLOCATABLE :: att_w(:), att_b(:), att_fk(:), att_cda(:), att_cdax(:) + ! The two nodal mass terms each attachment adds to Mgb, the dry mass m and the added mass + ! Ca rho V, kept so that a length change rebuilds Mgb in the order initialisation used. + REAL(wp), ALLOCATABLE :: att_mass(:), att_madd(:) REAL(wp) :: att_rho = CD_ZERO ! Rollback copies of CD_HermiteCable_Dyn_Set_Held_Fluid, kept so a per-step field update ! allocates nothing: a (ndof), hf_u/hf_ud (3, nn), hf_wl (nn). @@ -324,6 +351,10 @@ MODULE CableDyn_HermiteCableDynamic ! leave partially advanced state. Buffers allocate on first Snapshot (amortised zero; ! never touched by Step itself). REAL(wp), ALLOCATABLE :: snap_q(:), snap_v(:), snap_a(:) + ! The unstretched lengths and their rates join the snapshot (active line control): a + ! restore that changes l0 rebuilds the length-dependent caches from the restored lengths. + REAL(wp), ALLOCATABLE :: snap_l0(:), snap_l0_dot(:), snap_l0_c(:), snap_l0_dot_c(:) + LOGICAL :: snap_has_ctrl = .FALSE. REAL(wp) :: snap_t = CD_ZERO REAL(wp) :: snap_endconn_d0(3, 2) = CD_ZERO ! Condensed torsion (CD_HermiteCable_Dyn_Set_Torsion): end frames, GJ, imposed twist Phi and @@ -439,6 +470,21 @@ MODULE CableDyn_HermiteCableDynamic LOGICAL :: initialized = .FALSE. END TYPE CD_HermiteCableDynType + TYPE :: CD_HermiteCableControlSaveType + !! What CD_HermiteCable_Dyn_Set_SegmentLength writes, as CD_HermiteCable_Dyn_Save_Control + !! found it (the length caches are rebuilt from the lengths on a restore). + LOGICAL :: valid = .FALSE., has_ctrl = .FALSE., tr_valid = .FALSE., rates = .FALSE. + REAL(wp), ALLOCATABLE :: l0(:), l0_dot(:), l0_c(:), l0_dot_c(:) + END TYPE CD_HermiteCableControlSaveType + + TYPE :: committed_lengths_aside + !! The present lengths, rates and length caches of a controlled model, set aside while + !! one evaluation of the committed state runs with the lengths and rates that state was + !! reached with (enter_committed_lengths / leave_committed_lengths). + LOGICAL :: lengths = .FALSE., rates = .FALSE. + REAL(wp), ALLOCATABLE :: l0(:), rate(:), mgb(:, :), trib(:), kn(:), cn(:), frk(:) + END TYPE committed_lengths_aside + CONTAINS LOGICAL FUNCTION CD_HermiteCable_Dyn_Profile_Enabled() RESULT(enabled) @@ -784,6 +830,8 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_Contact(model, kn_node, cn_node, mu, ErrStat, model%a = old_a CALL fail_contact('initial acceleration refresh failed: '//TRIM(em)); RETURN END IF + ! New nodal coefficients supersede any seabed recompute inputs given for the old ones. + model%has_seabed_recompute = .FALSE. CONTAINS SUBROUTINE fail_contact(msg) @@ -950,7 +998,7 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_Attachments(model, node, mass, volume, cda, c a_old = model%a mgb_old = model%Mgb ALLOCATE (model%att_node(n), model%att_w(n), model%att_b(n), model%att_fk(n), model%att_cda(n), & - model%att_cdax(n)) + model%att_cdax(n), model%att_mass(n), model%att_madd(n)) model%att_node = node model%att_w = (mass - rho_w*volume)*gravity model%att_b = rho_w*gravity*volume @@ -958,16 +1006,19 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_Attachments(model, node, mass, volume, cda, c model%att_cda = cda model%att_cdax = cdax model%att_rho = rho_w + model%att_mass = mass + model%att_madd = ca*rho_w*volume DO k = 1, n DO d = 1, 3 dof = 6*(node(k) - 1) + d - model%Mgb(KL_D + KU_D + 1, dof) = model%Mgb(KL_D + KU_D + 1, dof) + mass(k) + ca(k)*rho_w*volume(k) + model%Mgb(KL_D + KU_D + 1, dof) = model%Mgb(KL_D + KU_D + 1, dof) + model%att_mass(k) + model%att_madd(k) END DO END DO model%has_attach = .TRUE. CALL solve_consistent_acceleration(model, es, em) IF (es /= CD_HCDYN_OK) THEN - DEALLOCATE (model%att_node, model%att_w, model%att_b, model%att_fk, model%att_cda, model%att_cdax) + DEALLOCATE (model%att_node, model%att_w, model%att_b, model%att_fk, model%att_cda, model%att_cdax, & + model%att_mass, model%att_madd) model%has_attach = .FALSE. model%Mgb = mgb_old model%a = a_old @@ -1090,7 +1141,11 @@ SUBROUTINE CD_HermiteCable_Dyn_Recompute_Acceleration(model, ErrStat, ErrMsg, pr !! free-DOF acceleration from the complete installed load set at the model's current !! q/v/t. Optional prescribed fixed-DOF accelerations enter the consistent-mass RHS, !! including their off-diagonal coupling to free DOFs. Failure is atomic with respect - !! to the previously committed acceleration. + !! to the previously committed acceleration. Under active line control the acceleration + !! is the committed state's: between a length change (CD_HermiteCable_Dyn_Set_SegmentLength) + !! and the next step it is solved with the lengths and rates that state was reached with + !! (l0_c, l0_dot_c), which stay the committed ones, so the step still blends the old and new + !! lengths. TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg @@ -1105,13 +1160,13 @@ SUBROUTINE CD_HermiteCable_Dyn_Recompute_Acceleration(model, ErrStat, ErrMsg, pr END IF a_old = model%a IF (PRESENT(pres_dofs) .AND. PRESENT(pres_a)) THEN - CALL solve_consistent_acceleration(model, ErrStat, ErrMsg, pres_dofs=pres_dofs, pres_a=pres_a) + CALL solve_committed_acceleration(model, ErrStat, ErrMsg, pres_dofs=pres_dofs, pres_a=pres_a) ELSE IF (PRESENT(pres_dofs) .OR. PRESENT(pres_a)) THEN ErrStat = CD_HCDYN_BADINPUT ErrMsg = 'CD_HermiteCable_Dyn_Recompute_Acceleration: pres_dofs and pres_a must be supplied together' RETURN ELSE - CALL solve_consistent_acceleration(model, ErrStat, ErrMsg) + CALL solve_committed_acceleration(model, ErrStat, ErrMsg) END IF IF (ErrStat /= CD_HCDYN_OK) THEN model%a = a_old @@ -1119,6 +1174,437 @@ SUBROUTINE CD_HermiteCable_Dyn_Recompute_Acceleration(model, ErrStat, ErrMsg, pr END IF END SUBROUTINE CD_HermiteCable_Dyn_Recompute_Acceleration + SUBROUTINE CD_HermiteCable_Dyn_Set_SegmentLength(model, elems, l0_new, l0_dot, ErrStat, ErrMsg, restored) + !! Active line control (the OpenFAST cable-control channel): set the unstretched length + !! and its rate of the listed elements, applied before a step and held over it. Every + !! term that reads l0 when it is evaluated (elastic force, weight, drag, Froude-Krylov + !! load, added mass, dry-part buoyancy, the tensile audit and the residual scale) follows + !! at once. The cached terms are rebuilt from the new lengths in the order initialisation + !! used, so the model carries what one built with them would: the constant mass Mgb with + !! the attachment masses, the nodal tributary lengths and, on a contact model, the nodal + !! seabed coefficients and the friction spring stiffness. The rate enters the axial + !! damping (CD_HermiteCable_Axial_Damping_Element). The step uses the mass of the new + !! lengths and leaves out the rate term dM/dt v, as MoorDyn does; the committed + !! acceleration is kept as the history of the preceding step, and BA keeps its initial + !! resolution. The committed state keeps the lengths it was reached with (l0_c, + !! l0_dot_c): the force-blended committed force F_n stays the force at those lengths + !! (cached or, after a cache loss, evaluated with them), and only the step's new force + !! R(q_{n+1}) takes the new ones, so a length ramp is not lagged by alpha_f times the + !! length change. The carried step factor is discarded, and the step after a change starts + !! from the Newmark predictor (the change is a load step). + !! A call that changes no length and no rate (bit for bit, a rate of -0 counting as +0) + !! returns at once, so a zero command of either sign on an uncontrolled model leaves it + !! untouched. The update is atomic: every check and rebuild runs before the model is + !! written. A line restrained in torsion is refused (its condensed torsional compliance + !! has no length-control law here), as is a contact model without the seabed recompute + !! inputs and a model on the configuration-blended generalised-alpha (force blend off, + !! CD_HermiteCable_Dyn_Set_ForceBlend), whose blended state has no committed-length + !! treatment, so a ramp would lag by alpha_f times the length change. restored = .TRUE. (a checkpoint + !! restart re-applying the command the committed state was reached with) makes the + !! lengths and rates the committed ones at once; a committed force reloaded with the + !! state belongs to them and stays valid. + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + INTEGER, INTENT(IN) :: elems(:) + REAL(wp), INTENT(IN) :: l0_new(:), l0_dot(:) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + LOGICAL, INTENT(IN), OPTIONAL :: restored + INTEGER :: k, n, istat + LOGICAL :: lengths_changed, rates_changed + REAL(wp) :: rate_now + REAL(wp), ALLOCATABLE :: l0_trial(:), rate_new(:) + + ErrStat = CD_HCDYN_OK; ErrMsg = '' + IF (.NOT. model%initialized) THEN + CALL fail('model not initialised'); RETURN + END IF + n = SIZE(elems) + IF (n < 1 .OR. SIZE(l0_new) /= n .OR. SIZE(l0_dot) /= n) THEN + CALL fail('elems, l0_new and l0_dot must share one length >= 1'); RETURN + END IF + IF (ANY(elems < 1) .OR. ANY(elems > model%ne)) THEN + CALL fail('element index out of range'); RETURN + END IF + DO k = 2, n + IF (elems(k) <= elems(k - 1)) THEN + CALL fail('element indices must be strictly increasing'); RETURN + END IF + END DO + IF (.NOT. (CD_All_Finite(l0_new) .AND. CD_All_Finite(l0_dot))) THEN + CALL fail('l0 and l0_dot must be finite'); RETURN + END IF + IF (ANY(l0_new <= CD_ZERO)) THEN + CALL fail('l0 must be positive'); RETURN + END IF + IF (model%torsion%active) THEN + CALL fail('a line restrained in torsion is not supported (the condensed torsional compliance '// & + 'has no length-control law)'); RETURN + END IF + IF (model%has_contact .AND. .NOT. model%has_seabed_recompute) THEN + CALL fail('a seabed-contact model needs the seabed recompute inputs '// & + '(CD_HermiteCable_Dyn_Set_Control_Seabed)'); RETURN + END IF + IF (.NOT. model%force_blend) THEN + CALL fail('the configuration-blended generalised-alpha (force blend off) is not supported: '// & + 'enable the force blend (CD_HermiteCable_Dyn_Set_ForceBlend)'); RETURN + END IF + ! a rate of -0 is stored as +0, so a zero command of either sign is inert + rate_new = positive_zero(l0_dot) + lengths_changed = .FALSE. + rates_changed = .FALSE. + DO k = 1, n + IF (.NOT. bits_equal(model%l0(elems(k)), l0_new(k))) lengths_changed = .TRUE. + rate_now = CD_ZERO + IF (model%has_ctrl) rate_now = model%l0_dot(elems(k)) + IF (.NOT. bits_equal(rate_now, rate_new(k))) rates_changed = .TRUE. + END DO + IF (.NOT. (lengths_changed .OR. rates_changed)) THEN + CALL commit_restored() + RETURN + END IF + IF (.NOT. ALLOCATED(model%l0_dot)) THEN + ALLOCATE (model%l0_dot(model%ne), model%l0_c(model%ne), model%l0_dot_c(model%ne), & + model%ws_recovery_l0_c(model%ne), model%ws_recovery_l0_dot_c(model%ne), STAT=istat) + IF (istat /= 0) THEN + CALL fail('rate storage allocation failed'); RETURN + END IF + model%l0_dot = CD_ZERO + END IF + ! the first change: the committed state was reached with the present lengths, at rest + IF (.NOT. model%has_ctrl) THEN + model%l0_c = model%l0 + model%l0_dot_c = CD_ZERO + END IF + IF (lengths_changed) THEN + ALLOCATE (l0_trial(model%ne), STAT=istat) + IF (istat /= 0) THEN + CALL fail('length storage allocation failed'); RETURN + END IF + l0_trial = model%l0 + l0_trial(elems) = l0_new + CALL rebuild_length_caches(model, l0_trial, ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) THEN + ErrMsg = 'CD_HermiteCable_Dyn_Set_SegmentLength: '//TRIM(ErrMsg); RETURN + END IF + END IF + IF (.NOT. model%has_ctrl) model%l0_dot = CD_ZERO + model%has_ctrl = .TRUE. + model%l0_dot(elems) = rate_new + ! the cached committed force stays valid (it is the force at l0_c); the carried factor + ! holds the tangent of the old lengths + model%tr_valid = .FALSE. + CALL commit_restored() + + CONTAINS + SUBROUTINE fail(msg) + CHARACTER(*), INTENT(IN) :: msg + ErrStat = CD_HCDYN_BADINPUT + ErrMsg = 'CD_HermiteCable_Dyn_Set_SegmentLength: '//msg + END SUBROUTINE fail + + SUBROUTINE commit_restored() + !! restored: the present lengths and rates are the committed state's. + IF (.NOT. PRESENT(restored)) RETURN + IF (.NOT. (restored .AND. model%has_ctrl)) RETURN + model%l0_c = model%l0 + model%l0_dot_c = model%l0_dot + END SUBROUTINE commit_restored + END SUBROUTINE CD_HermiteCable_Dyn_Set_SegmentLength + + SUBROUTINE CD_HermiteCable_Dyn_Save_Control(model, saved) + !! Save what CD_HermiteCable_Dyn_Set_SegmentLength writes (the lengths, rates, committed + !! lengths and rates, the control flag and the carried-factor flag), so that a caller + !! applying one command to several models can take back the ones it already changed + !! when a later one fails (CD_HermiteCable_Dyn_Restore_Control). + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + TYPE(CD_HermiteCableControlSaveType), INTENT(INOUT) :: saved + saved%valid = model%initialized + IF (.NOT. saved%valid) RETURN + saved%has_ctrl = model%has_ctrl + saved%tr_valid = model%tr_valid + saved%l0 = model%l0 + saved%rates = ALLOCATED(model%l0_dot) + IF (saved%rates) THEN + saved%l0_dot = model%l0_dot + saved%l0_c = model%l0_c + saved%l0_dot_c = model%l0_dot_c + END IF + END SUBROUTINE CD_HermiteCable_Dyn_Save_Control + + SUBROUTINE CD_HermiteCable_Dyn_Restore_Control(model, saved, ErrStat, ErrMsg) + !! Take the model back to what CD_HermiteCable_Dyn_Save_Control saved. Lengths changed + !! since get the caches built from the saved lengths, as CD_HermiteCable_Dyn_Restore + !! rebuilds them: the caches are a function of the lengths (built in the order + !! initialisation used), so the model is the saved one bit for bit. Fails closed, writing + !! nothing, when the save does not belong to the model or the rebuild fails. + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + TYPE(CD_HermiteCableControlSaveType), INTENT(IN) :: saved + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), ALLOCATABLE :: l0_back(:) + + ErrStat = CD_HCDYN_OK; ErrMsg = '' + IF (.NOT. (model%initialized .AND. saved%valid)) THEN + ErrStat = CD_HCDYN_BADINPUT + ErrMsg = 'CD_HermiteCable_Dyn_Restore_Control: no saved control state'; RETURN + END IF + IF (SIZE(saved%l0) /= model%ne) THEN + ErrStat = CD_HCDYN_BADINPUT + ErrMsg = 'CD_HermiteCable_Dyn_Restore_Control: the saved state belongs to another model'; RETURN + END IF + IF (.NOT. ALL(bits_equal(model%l0, saved%l0))) THEN + l0_back = saved%l0 + CALL rebuild_length_caches(model, l0_back, ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) THEN + ErrMsg = 'CD_HermiteCable_Dyn_Restore_Control: '//TRIM(ErrMsg); RETURN + END IF + END IF + IF (saved%rates) THEN + model%l0_dot = saved%l0_dot + model%l0_c = saved%l0_c + model%l0_dot_c = saved%l0_dot_c + IF (.NOT. ALLOCATED(model%ws_recovery_l0_c)) & + ALLOCATE (model%ws_recovery_l0_c(model%ne), model%ws_recovery_l0_dot_c(model%ne)) + ELSE IF (ALLOCATED(model%l0_dot)) THEN + DEALLOCATE (model%l0_dot, model%l0_c, model%l0_dot_c, model%ws_recovery_l0_c, model%ws_recovery_l0_dot_c) + END IF + model%has_ctrl = saved%has_ctrl + model%tr_valid = saved%tr_valid + END SUBROUTINE CD_HermiteCable_Dyn_Restore_Control + + SUBROUTINE CD_HermiteCable_Dyn_Set_Control_Seabed(model, kbot, diameter_elem, cn_over_kn, ErrStat, ErrMsg) + !! Store the seabed recompute inputs of a contact model for active line control: the + !! per-area penalty kbot [N/m^3], the per-element contact diameter [m] and the ratio + !! cn/kn, the inputs from which the deck built the installed nodal coefficients with + !! CD_Nodal_Seabed_Stiffness. Call after CD_HermiteCable_Dyn_Set_Contact. The inputs + !! must reproduce the installed contact_kn and contact_cn bit for bit at the present + !! lengths, so a length change rebuilds exactly the coefficients a model built with the + !! new lengths would carry; otherwise the call fails and changes nothing. + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + REAL(wp), INTENT(IN) :: kbot, diameter_elem(:), cn_over_kn + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), ALLOCATABLE :: kn_check(:) + INTEGER :: es + CHARACTER(200) :: em + + ErrStat = CD_HCDYN_OK; ErrMsg = '' + IF (.NOT. model%initialized) THEN + CALL fail('model not initialised'); RETURN + END IF + IF (.NOT. (model%has_contact .AND. ALLOCATED(model%contact_kn) .AND. ALLOCATED(model%contact_cn))) THEN + CALL fail('seabed contact (CD_HermiteCable_Dyn_Set_Contact) is required'); RETURN + END IF + IF (SIZE(diameter_elem) /= model%ne) THEN + CALL fail('diameter_elem must have one entry per element'); RETURN + END IF + IF (.NOT. (CD_Is_Finite(cn_over_kn) .AND. cn_over_kn >= CD_ZERO)) THEN + CALL fail('cn_over_kn must be finite and non-negative'); RETURN + END IF + CALL CD_Nodal_Seabed_Stiffness(kbot, diameter_elem, model%l0, kn_check, es, em) + IF (es /= CD_LINE_OK) THEN + CALL fail(TRIM(em)); RETURN + END IF + IF (.NOT. ALL(bits_equal(kn_check, model%contact_kn))) THEN + CALL fail('the inputs do not reproduce the installed nodal contact stiffness'); RETURN + END IF + IF (.NOT. ALL(bits_equal(kn_check*cn_over_kn, model%contact_cn))) THEN + CALL fail('the inputs do not reproduce the installed nodal contact damping'); RETURN + END IF + model%seabed_kbot = kbot + model%seabed_diameter_elem = diameter_elem + model%seabed_cn_over_kn = cn_over_kn + model%has_seabed_recompute = .TRUE. + + CONTAINS + SUBROUTINE fail(msg) + CHARACTER(*), INTENT(IN) :: msg + ErrStat = CD_HCDYN_BADINPUT + ErrMsg = 'CD_HermiteCable_Dyn_Set_Control_Seabed: '//msg + END SUBROUTINE fail + END SUBROUTINE CD_HermiteCable_Dyn_Set_Control_Seabed + + SUBROUTINE rebuild_length_caches(model, l0_new, ErrStat, ErrMsg) + !! Install the unstretched lengths l0_new with every cache built from them, in the order + !! initialisation used, so the model matches one built with these lengths bit for bit: + !! the constant mass Mgb (element by element, then the attachment masses), the nodal + !! tributary lengths and, on a contact model, the nodal seabed coefficients + !! (CD_Nodal_Seabed_Stiffness, as the deck builds them) with the friction spring + !! stiffness that follows them. Everything is built first; the model is written only + !! when every build succeeded. + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + REAL(wp), INTENT(IN) :: l0_new(:) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), ALLOCATABLE :: mgb_new(:, :), trib_new(:), kn_new(:), cn_new(:) + REAL(wp) :: Me(12, 12) + INTEGER :: e, k, d, dof, es, istat + CHARACTER(200) :: em + + ErrStat = CD_HCDYN_OK; ErrMsg = '' + IF (SIZE(l0_new) /= model%ne) THEN + ErrStat = CD_HCDYN_BADINPUT; ErrMsg = 'length rebuild: l0 must have one entry per element'; RETURN + END IF + ALLOCATE (mgb_new(LDAB_D, model%ndof), trib_new(model%nn), STAT=istat) + IF (istat /= 0) THEN + ErrStat = CD_HCDYN_BADINPUT; ErrMsg = 'length rebuild: workspace allocation failed'; RETURN + END IF + mgb_new = CD_ZERO + DO e = 1, model%ne + CALL CD_HermiteCable_Mass(model%rho_a(e), l0_new(e), Me, es, em) + IF (es /= CD_HCABLE_OK) THEN + ErrStat = CD_HCDYN_BADINPUT; ErrMsg = 'length rebuild: mass assembly: '//TRIM(em); RETURN + END IF + CALL scatter12_band(mgb_new, Me, e) + END DO + IF (model%has_attach) THEN + DO k = 1, SIZE(model%att_node) + DO d = 1, 3 + dof = 6*(model%att_node(k) - 1) + d + mgb_new(KL_D + KU_D + 1, dof) = mgb_new(KL_D + KU_D + 1, dof) + model%att_mass(k) + model%att_madd(k) + END DO + END DO + END IF + trib_new = CD_ZERO + DO e = 1, model%ne + trib_new(e) = trib_new(e) + 0.5_wp*l0_new(e) + trib_new(e + 1) = trib_new(e + 1) + 0.5_wp*l0_new(e) + END DO + IF (model%has_contact) THEN + IF (.NOT. model%has_seabed_recompute) THEN + ErrStat = CD_HCDYN_BADINPUT + ErrMsg = 'length rebuild: the seabed-contact model has no seabed recompute inputs'; RETURN + END IF + CALL CD_Nodal_Seabed_Stiffness(model%seabed_kbot, model%seabed_diameter_elem, l0_new, kn_new, es, em) + IF (es /= CD_LINE_OK) THEN + ErrStat = CD_HCDYN_BADINPUT; ErrMsg = 'length rebuild: seabed stiffness: '//TRIM(em); RETURN + END IF + cn_new = kn_new*model%seabed_cn_over_kn + END IF + model%l0 = l0_new + CALL MOVE_ALLOC(mgb_new, model%Mgb) + CALL MOVE_ALLOC(trib_new, model%trib) + IF (model%has_contact) THEN + CALL MOVE_ALLOC(kn_new, model%contact_kn) + CALL MOVE_ALLOC(cn_new, model%contact_cn) + IF (model%fr_active) model%fr_k = model%contact_kn + END IF + END SUBROUTINE rebuild_length_caches + + SUBROUTINE enter_committed_lengths(model, aside, ErrStat, ErrMsg) + !! Install the lengths and rates the committed state was reached with (l0_c, l0_dot_c) for + !! one evaluation of the committed state, setting the present ones aside: after a length + !! change the length-dependent caches are rebuilt from l0_c, and leave_committed_lengths + !! moves the present ones back bit for bit. A model that is not under active line control, + !! or whose lengths and rates are the committed ones, is left as it is. On failure nothing + !! is written. + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + TYPE(committed_lengths_aside), INTENT(INOUT) :: aside + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), ALLOCATABLE :: l0_old(:) + + ErrStat = CD_HCDYN_OK; ErrMsg = '' + aside%lengths = .FALSE. + aside%rates = .FALSE. + IF (.NOT. model%has_ctrl) RETURN + IF (ALL(bits_equal(model%l0, model%l0_c)) .AND. ALL(bits_equal(model%l0_dot, model%l0_dot_c))) RETURN + IF (.NOT. ALL(bits_equal(model%l0, model%l0_c))) THEN + aside%l0 = model%l0 + aside%mgb = model%Mgb + aside%trib = model%trib + IF (model%has_contact) THEN + aside%kn = model%contact_kn + aside%cn = model%contact_cn + IF (model%fr_active) aside%frk = model%fr_k + END IF + ! a copy, so no subobject of model is associated with a second dummy + l0_old = model%l0_c + CALL rebuild_length_caches(model, l0_old, ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) RETURN + aside%lengths = .TRUE. + END IF + aside%rate = model%l0_dot + model%l0_dot = model%l0_dot_c + aside%rates = .TRUE. + END SUBROUTINE enter_committed_lengths + + SUBROUTINE leave_committed_lengths(model, aside) + !! Move back the present lengths, rates and caches enter_committed_lengths set aside. + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + TYPE(committed_lengths_aside), INTENT(INOUT) :: aside + IF (aside%lengths) THEN + model%l0 = aside%l0 + CALL MOVE_ALLOC(aside%mgb, model%Mgb) + CALL MOVE_ALLOC(aside%trib, model%trib) + IF (model%has_contact) THEN + CALL MOVE_ALLOC(aside%kn, model%contact_kn) + CALL MOVE_ALLOC(aside%cn, model%contact_cn) + IF (model%fr_active) CALL MOVE_ALLOC(aside%frk, model%fr_k) + END IF + END IF + IF (aside%rates) model%l0_dot = aside%rate + aside%lengths = .FALSE. + aside%rates = .FALSE. + END SUBROUTINE leave_committed_lengths + + SUBROUTINE assemble_committed_force(model, ErrStat, ErrMsg) + !! The committed force F_n = R(q_n, v_n, t_n) into ws_R, with the lengths and rates the + !! committed state was reached with (l0_c, l0_dot_c; enter_committed_lengths); without a + !! pending length or rate change this is the plain evaluation. + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + TYPE(committed_lengths_aside) :: aside + INTEGER :: es + CHARACTER(200) :: em + + CALL enter_committed_lengths(model, aside, es, em) + IF (es /= CD_HCDYN_OK) THEN + ErrStat = es; ErrMsg = 'committed force: '//TRIM(em); RETURN + END IF + CALL assemble_residual(model, model%q, model%v, model%t, .TRUE., .FALSE., ErrStat, ErrMsg) + CALL leave_committed_lengths(model, aside) + END SUBROUTINE assemble_committed_force + + SUBROUTINE solve_committed_acceleration(model, ErrStat, ErrMsg, pres_dofs, pres_a) + !! solve_consistent_acceleration for the committed state: the acceleration is the + !! committed state's, so under active line control it is solved with the lengths and rates + !! that state was reached with (l0_c, l0_dot_c; enter_committed_lengths), which stay the + !! committed ones. Without a pending length or rate change this is the plain solve. + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER, INTENT(IN), OPTIONAL :: pres_dofs(:) + REAL(wp), INTENT(IN), OPTIONAL :: pres_a(:) + TYPE(committed_lengths_aside) :: aside + INTEGER :: es + CHARACTER(200) :: em + + CALL enter_committed_lengths(model, aside, es, em) + IF (es /= CD_HCDYN_OK) THEN + ErrStat = es; ErrMsg = 'committed acceleration: '//TRIM(em); RETURN + END IF + CALL solve_consistent_acceleration(model, ErrStat, ErrMsg, pres_dofs=pres_dofs, pres_a=pres_a) + CALL leave_committed_lengths(model, aside) + END SUBROUTINE solve_committed_acceleration + + ELEMENTAL LOGICAL FUNCTION bits_equal(a, b) RESULT(same) + !! Bitwise equality of two reals (so +0 and -0 differ). + REAL(wp), INTENT(IN) :: a, b + same = TRANSFER(a, 0_INT64) == TRANSFER(b, 0_INT64) + END FUNCTION bits_equal + + ELEMENTAL REAL(wp) FUNCTION positive_zero(x) RESULT(y) + !! x with a negative zero replaced by +0, on the bits (so no floating-point mode can keep + !! the sign); every other value is returned unchanged. + REAL(wp), INTENT(IN) :: x + INTEGER(INT64) :: bits + bits = TRANSFER(x, 0_INT64) + IF (bits == -HUGE(0_INT64) - 1_INT64) bits = 0_INT64 + y = TRANSFER(bits, y) + END FUNCTION positive_zero + SUBROUTINE CD_HermiteCable_Dyn_Set_ForceBlend(model, enabled, ErrStat, ErrMsg) !! Select the generalised-alpha blend. enabled = .TRUE. (the default): the residual !! blends the forces, G = M a_am + (1-af) r(q_{n+1}, v_{n+1}, t_{n+1}) + af r(q_n, v_n, t_n), @@ -1136,6 +1622,12 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_ForceBlend(model, enabled, ErrStat, ErrMsg) ErrMsg = 'CD_HermiteCable_Dyn_Set_ForceBlend: model not initialised' RETURN END IF + IF (model%has_ctrl .AND. .NOT. enabled) THEN + ! active line control needs the committed-length treatment of the force blend + ErrStat = CD_HCDYN_BADINPUT + ErrMsg = 'CD_HermiteCable_Dyn_Set_ForceBlend: a model under active line control needs the force blend' + RETURN + END IF model%force_blend = enabled model%fc_valid = .FALSE. model%tr_valid = .FALSE. @@ -2333,14 +2825,15 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_Held_Fluid(model, fluid_velocity, fluid_accel model%hf_wl = waterline_z model%has_held_field = .TRUE. IF (.NOT. had_field .AND. .NOT. model%a_restored) THEN - CALL solve_consistent_acceleration(model, ErrStat, ErrMsg) + CALL solve_committed_acceleration(model, ErrStat, ErrMsg) ELSE - CALL assemble_residual(model, model%q, model%v, model%t, .TRUE., .FALSE., es, em) + CALL assemble_committed_force(model, es, em) ErrStat = es ErrMsg = em IF (es == CD_HCDYN_OK .AND. model%force_blend) THEN ! This validation is the next step's committed force F_n = R(q_n, v_n, t_n) under the - ! new field, the evaluation the step would otherwise repeat: cache it, keyed as usual. + ! new field (at the committed lengths), the evaluation the step would otherwise repeat: + ! cache it, keyed as usual. model%fc_R = model%ws_R model%fc_q = model%q model%fc_v = model%v @@ -2767,9 +3260,10 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r model%ws_an(pres_dofs(ip)) = model%a(pres_dofs(ip)) END DO END IF - ! Committed force F_n = R(q_n, v_n, t_n) with the current load configuration: reused - ! from the previous step's converged evaluation when its key matches the committed - ! state exactly, evaluated here otherwise (one residual assembly). + ! Committed force F_n = R(q_n, v_n, t_n) with the current load configuration and the + ! lengths the committed state was reached with (active line control: l0_c): reused from + ! the previous step's converged evaluation when its key matches the committed state + ! exactly, evaluated here otherwise (one residual assembly). fc_hit = .FALSE. IF (model%force_blend) fc_hit = force_cache_matches() ! Cross-step factor reuse needs the step to continue bitwise from the state the carried @@ -2781,7 +3275,7 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r factor_ok = xs_active model%tr_valid = .FALSE. IF (model%force_blend .AND. .NOT. fc_hit) THEN - CALL assemble_residual(model, model%q, model%v, model%t, .TRUE., .FALSE., es, em2) + CALL assemble_committed_force(model, es, em2) IF (es /= CD_HCDYN_OK) THEN ErrStat = es; ErrMsg = 'CD_HermiteCable_Dyn_Step: '//TRIM(em2); RETURN END IF @@ -2823,6 +3317,11 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r e_ma = e_ma + model%ws_inert(iv)**2 END DO use_ca = e_ma > CD_ZERO .AND. e_bal <= PRED_BALANCE**2*e_ma + ! Active line control: after a length or rate change the step's force departs from the + ! committed balance by the force of the change, a load step the constant-acceleration + ! guess does not anticipate; the step starts from the Newmark guess, which damps what + ! the change excites. + IF (use_ca .AND. model%has_ctrl) use_ca = lengths_committed() END IF ! The carried factor is used under the same smoothness test: through a transient it ! stops each step just inside the tolerance, and those states can lead the start-up of a @@ -3433,6 +3932,11 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r model%fc_d0 = model%endconn_d0 model%fc_valid = .TRUE. END IF + ! The committed state was reached with the present lengths and rates. + IF (model%has_ctrl) THEN + model%l0_c = model%l0 + model%l0_dot_c = model%l0_dot + END IF ! Largest nodal tangent turn of the step (the time-step diagnostic). DO i = 1, model%nn model%max_step_rotation = MAX(model%max_step_rotation, & @@ -3482,6 +3986,19 @@ SUBROUTINE window_mean(slot, esx) win_done(slot) = .TRUE. END SUBROUTINE window_mean + LOGICAL FUNCTION lengths_committed() RESULT(ok) + !! The lengths and rates are those the committed state was reached with. + INTEGER :: ie + ok = .TRUE. + DO ie = 1, model%ne + IF (.NOT. (bits_equal(model%l0(ie), model%l0_c(ie)) .AND. & + bits_equal(model%l0_dot(ie), model%l0_dot_c(ie)))) THEN + ok = .FALSE. + RETURN + END IF + END DO + END FUNCTION lengths_committed + LOGICAL FUNCTION force_cache_matches() RESULT(ok) !! The cached F_n was evaluated at exactly the committed state and configuration. INTEGER :: ii @@ -3946,6 +4463,10 @@ SUBROUTINE CD_HermiteCable_Dyn_Step_Recovering(model, dt, max_iter, tol, ErrStat model%ws_recovery_v0 = model%v model%ws_recovery_a0 = model%a IF (model%fr_active) model%ws_recovery_fr = model%fr_anchor + IF (model%has_ctrl) THEN + model%ws_recovery_l0_c = model%l0_c + model%ws_recovery_l0_dot_c = model%l0_dot_c + END IF t_save = model%t na_steps_save = model%na_steps_done; na_sum_save = model%na_iter_sum; na_mn_save = model%na_mn_active tensile_events_save = model%tensile_event_count @@ -4033,6 +4554,8 @@ SUBROUTINE CD_HermiteCable_Dyn_Step_Recovering(model, dt, max_iter, tol, ErrStat model%q = q_save; model%v = v_save; model%a = a_save; model%t = t_save model%endconn_d0 = d0_save IF (model%fr_active) model%fr_anchor = model%ws_recovery_fr + IF (model%has_ctrl) model%l0_c = model%ws_recovery_l0_c + IF (model%has_ctrl) model%l0_dot_c = model%ws_recovery_l0_dot_c model%na_steps_done = na_steps_save; model%na_iter_sum = na_sum_save; model%na_mn_active = na_mn_save model%tensile_event_count = tensile_events_save model%tensile_worst_element = tensile_element_save @@ -4107,6 +4630,8 @@ SUBROUTINE CD_HermiteCable_Dyn_Step_Recovering(model, dt, max_iter, tol, ErrStat model%q = q_save; model%v = v_save; model%a = a_save; model%t = t_save model%endconn_d0 = d0_save IF (model%fr_active) model%fr_anchor = model%ws_recovery_fr + IF (model%has_ctrl) model%l0_c = model%ws_recovery_l0_c + IF (model%has_ctrl) model%l0_dot_c = model%ws_recovery_l0_dot_c model%na_steps_done = na_steps_save model%na_iter_sum = na_sum_save model%na_mn_active = na_mn_save @@ -4149,6 +4674,8 @@ SUBROUTINE CD_HermiteCable_Dyn_Step_Recovering(model, dt, max_iter, tol, ErrStat model%q = q_save; model%v = v_save; model%a = a_save; model%t = t_save model%endconn_d0 = d0_save IF (model%fr_active) model%fr_anchor = model%ws_recovery_fr + IF (model%has_ctrl) model%l0_c = model%ws_recovery_l0_c + IF (model%has_ctrl) model%l0_dot_c = model%ws_recovery_l0_dot_c model%na_steps_done = na_steps_save; model%na_iter_sum = na_sum_save; model%na_mn_active = na_mn_save model%tensile_event_count = tensile_events_save model%tensile_worst_element = tensile_element_save @@ -4617,8 +5144,14 @@ SUBROUTINE CD_HermiteCable_Dyn_End_Force(model, node, force, ErrStat, ErrMsg) END IF r3 = fe(i0 + 1:i0 + 3) IF (model%has_axial_damping) THEN - CALL CD_HermiteCable_Axial_Damping_Element(qe, ve, model%l0(e), model%BA(e), fdamp, ErrStat=es, ErrMsg=em2, & - quadrature_order=model%axial_quadrature_order) + IF (model%has_ctrl) THEN + CALL CD_HermiteCable_Axial_Damping_Element(qe, ve, model%l0(e), model%BA(e), fdamp, ErrStat=es, ErrMsg=em2, & + quadrature_order=model%axial_quadrature_order, & + l0_dot=model%l0_dot(e)) + ELSE + CALL CD_HermiteCable_Axial_Damping_Element(qe, ve, model%l0(e), model%BA(e), fdamp, ErrStat=es, ErrMsg=em2, & + quadrature_order=model%axial_quadrature_order) + END IF IF (es /= CD_HCDYN_OK) THEN ErrStat = CD_HCDYN_NOCONVERGE; ErrMsg = 'CD_HermiteCable_Dyn_End_Force: '//TRIM(em2); RETURN END IF @@ -5608,9 +6141,9 @@ SUBROUTINE torsion_cache_fill(model, ErrStat, ErrMsg) END SUBROUTINE torsion_cache_fill SUBROUTINE CD_HermiteCable_Dyn_Snapshot(model, ErrStat, ErrMsg) - !! Capture the committed step state (q, v, a, t) into the model-owned snapshot - !! buffers (see the type note: the aggregate stage-then-commit contract). Buffers - !! allocate on first use and are reused thereafter. + !! Capture the committed step state (q, v, a, t) and the unstretched lengths with their + !! rates into the model-owned snapshot buffers (see the type note: the aggregate + !! stage-then-commit contract). Buffers allocate on first use and are reused thereafter. TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg @@ -5622,11 +6155,24 @@ SUBROUTINE CD_HermiteCable_Dyn_Snapshot(model, ErrStat, ErrMsg) RETURN END IF IF (.NOT. ALLOCATED(model%snap_q)) THEN - ALLOCATE (model%snap_q(model%ndof), model%snap_v(model%ndof), model%snap_a(model%ndof)) + ALLOCATE (model%snap_q(model%ndof), model%snap_v(model%ndof), model%snap_a(model%ndof), & + model%snap_l0(model%ne), model%snap_l0_dot(model%ne), model%snap_l0_c(model%ne), & + model%snap_l0_dot_c(model%ne)) END IF model%snap_q = model%q model%snap_v = model%v model%snap_a = model%a + model%snap_l0 = model%l0 + model%snap_has_ctrl = model%has_ctrl + IF (model%has_ctrl) THEN + model%snap_l0_dot = model%l0_dot + model%snap_l0_c = model%l0_c + model%snap_l0_dot_c = model%l0_dot_c + ELSE + model%snap_l0_dot = CD_ZERO + model%snap_l0_c = model%l0 + model%snap_l0_dot_c = CD_ZERO + END IF model%snap_t = model%t model%snap_endconn_d0 = model%endconn_d0 model%snap_torsion_theta = model%torsion%theta @@ -5650,10 +6196,13 @@ END SUBROUTINE CD_HermiteCable_Dyn_Snapshot SUBROUTINE CD_HermiteCable_Dyn_Restore(model, ErrStat, ErrMsg) !! Restore the committed step state from the last Snapshot. Fails closed if no valid - !! snapshot exists (a restore must never silently run on stale or absent state). + !! snapshot exists (a restore must never silently run on stale or absent state). Lengths + !! changed by active line control since the snapshot come back with the caches built + !! from them, so no command need be re-applied. TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), ALLOCATABLE :: l0_restore(:) ErrStat = CD_HCDYN_OK ErrMsg = '' IF (.NOT. model%initialized) THEN @@ -5666,6 +6215,24 @@ SUBROUTINE CD_HermiteCable_Dyn_Restore(model, ErrStat, ErrMsg) ErrMsg = 'CD_HermiteCable_Dyn_Restore: no valid snapshot' RETURN END IF + ! Lengths first (active line control): when they moved since the snapshot, the + ! length-dependent caches are rebuilt from the snapshot lengths before any state is + ! written, so a failed rebuild leaves the model unchanged. + IF (.NOT. ALL(bits_equal(model%l0, model%snap_l0))) THEN + ! a copy, so no subobject of model is associated with a second dummy + l0_restore = model%snap_l0 + CALL rebuild_length_caches(model, l0_restore, ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) THEN + ErrMsg = 'CD_HermiteCable_Dyn_Restore: '//TRIM(ErrMsg) + RETURN + END IF + END IF + model%has_ctrl = model%snap_has_ctrl + IF (model%has_ctrl) THEN + model%l0_dot = model%snap_l0_dot + model%l0_c = model%snap_l0_c + model%l0_dot_c = model%snap_l0_dot_c + END IF model%q = model%snap_q model%v = model%snap_v model%a = model%snap_a @@ -5700,7 +6267,17 @@ SUBROUTINE CD_HermiteCable_Dyn_End(model) TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model IF (ALLOCATED(model%att_node)) DEALLOCATE (model%att_node, model%att_w, model%att_b, model%att_fk, & model%att_cda, model%att_cdax) + IF (ALLOCATED(model%att_mass)) DEALLOCATE (model%att_mass, model%att_madd) model%has_attach = .FALSE. + IF (ALLOCATED(model%l0_dot)) DEALLOCATE (model%l0_dot, model%l0_c, model%l0_dot_c, model%ws_recovery_l0_c, & + model%ws_recovery_l0_dot_c) + model%has_ctrl = .FALSE. + IF (ALLOCATED(model%seabed_diameter_elem)) DEALLOCATE (model%seabed_diameter_elem) + model%has_seabed_recompute = .FALSE. + model%seabed_kbot = CD_ZERO + model%seabed_cn_over_kn = CD_ZERO + IF (ALLOCATED(model%snap_l0)) DEALLOCATE (model%snap_l0, model%snap_l0_dot, model%snap_l0_c, model%snap_l0_dot_c) + model%snap_has_ctrl = .FALSE. IF (ALLOCATED(model%l0)) DEALLOCATE (model%l0) IF (ALLOCATED(model%EA)) DEALLOCATE (model%EA) IF (ALLOCATED(model%EI)) DEALLOCATE (model%EI) @@ -6035,10 +6612,19 @@ SUBROUTINE assemble_residual(model, q_cfg, v_cfg, t_eval, want_residual, want_ta qe(7:9) = q_cfg(6*e + 1:6*e + 3); qe(10:12) = q_cfg(6*e + 4:6*e + 6) ve(1:3) = v_cfg(6*(e - 1) + 1:6*(e - 1) + 3); ve(4:6) = v_cfg(6*(e - 1) + 4:6*(e - 1) + 6) ve(7:9) = v_cfg(6*e + 1:6*e + 3); ve(10:12) = v_cfg(6*e + 4:6*e + 6) - IF (want_tangent) THEN + IF (want_tangent .AND. model%has_ctrl) THEN + CALL CD_HermiteCable_Axial_Damping_Element(qe, ve, model%l0(e), model%BA(e), & + fdamp, kdq, kdv, es, em2, & + model%axial_quadrature_order, model%l0_dot(e)) + ELSE IF (want_tangent) THEN CALL CD_HermiteCable_Axial_Damping_Element(qe, ve, model%l0(e), model%BA(e), & fdamp, kdq, kdv, es, em2, & model%axial_quadrature_order) + ELSE IF (model%has_ctrl) THEN + CALL CD_HermiteCable_Axial_Damping_Element(qe, ve, model%l0(e), model%BA(e), & + fdamp, ErrStat=es, ErrMsg=em2, & + quadrature_order=model%axial_quadrature_order, & + l0_dot=model%l0_dot(e)) ELSE CALL CD_HermiteCable_Axial_Damping_Element(qe, ve, model%l0(e), model%BA(e), & fdamp, ErrStat=es, ErrMsg=em2, & @@ -6678,9 +7264,15 @@ SUBROUTINE evaluate_tangent_element(model, e, q_cfg, v_cfg, t_eval, Kstruct, Kdr END IF IF (model%has_axial_damping) THEN - CALL CD_HermiteCable_Axial_Damping_Element(qe, ve, model%l0(e), model%BA(e), & - fload, djq, djv, es, em, & - model%axial_quadrature_order) + IF (model%has_ctrl) THEN + CALL CD_HermiteCable_Axial_Damping_Element(qe, ve, model%l0(e), model%BA(e), & + fload, djq, djv, es, em, & + model%axial_quadrature_order, model%l0_dot(e)) + ELSE + CALL CD_HermiteCable_Axial_Damping_Element(qe, ve, model%l0(e), model%BA(e), & + fload, djq, djv, es, em, & + model%axial_quadrature_order) + END IF IF (es /= CD_HCDYN_OK) THEN ErrStat = CD_HCDYN_NOCONVERGE; ErrMsg = TRIM(em); RETURN END IF @@ -6756,13 +7348,15 @@ SUBROUTINE evaluate_tangent_element(model, e, q_cfg, v_cfg, t_eval, Kstruct, Kdr END IF END SUBROUTINE evaluate_tangent_element - SUBROUTINE CD_HermiteCable_Axial_Damping_Resultant(qe, ve, l0, BA, xi, resultant, ErrStat, ErrMsg) + SUBROUTINE CD_HermiteCable_Axial_Damping_Resultant(qe, ve, l0, BA, xi, resultant, ErrStat, ErrMsg, l0_dot) !! Signed viscous axial resultant N_v = BA*strain_rate at one material point. !! This is the damping share added to the elastic resultant for tension outputs. + !! l0_dot: the unstretched-length rate of a controlled element (see the element routine). REAL(wp), INTENT(IN) :: qe(12), ve(12), l0, BA, xi REAL(wp), INTENT(OUT) :: resultant INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), INTENT(IN), OPTIONAL :: l0_dot REAL(wp) :: H(4), dH(4), r_xi(3), v_xi(3), speed INTEGER :: s @@ -6777,6 +7371,11 @@ SUBROUTINE CD_HermiteCable_Axial_Damping_Resultant(qe, ve, l0, BA, xi, resultant IF (.NOT. CD_All_Finite(qe) .OR. .NOT. CD_All_Finite(ve)) THEN CALL fail('qe and ve must be finite'); RETURN END IF + IF (PRESENT(l0_dot)) THEN + IF (.NOT. CD_Is_Finite(l0_dot)) THEN + CALL fail('l0_dot must be finite'); RETURN + END IF + END IF IF (.NOT. (BA > CD_ZERO)) RETURN CALL CD_HermiteCable_Shapes(xi, l0, H, dH) r_xi = CD_ZERO @@ -6789,6 +7388,7 @@ SUBROUTINE CD_HermiteCable_Axial_Damping_Resultant(qe, ve, l0, BA, xi, resultant IF (.NOT. CD_Is_Finite(speed) .OR. speed <= 1.0e-12_wp*MAX(CD_ONE, l0)) THEN CALL fail('collapsed or non-finite element tangent'); RETURN END IF + IF (PRESENT(l0_dot)) v_xi = v_xi - (l0_dot/l0)*(dH(1)*qe(1:3) + dH(3)*qe(7:9)) resultant = BA*DOT_PRODUCT(r_xi/speed, v_xi)/l0 IF (.NOT. CD_Is_Finite(resultant)) CALL fail('non-finite damping resultant') @@ -6802,7 +7402,7 @@ END SUBROUTINE fail END SUBROUTINE CD_HermiteCable_Axial_Damping_Resultant SUBROUTINE CD_HermiteCable_Axial_Damping_Element(qe, ve, l0, BA, fdamp, Kq, Kv, ErrStat, ErrMsg, & - quadrature_order) + quadrature_order, l0_dot) !! Consistent axial Kelvin-Voigt contribution for one cubic-Hermite element. !! The material coordinate is reference arc length s0 = l0*xi. With !! r_xi = dr/dxi, t = r_xi/|r_xi| and v_xi = dv/dxi, @@ -6812,16 +7412,30 @@ SUBROUTINE CD_HermiteCable_Axial_Damping_Element(qe, ve, l0, BA, fdamp, Kq, Kv, !! !! fdamp is an INTERNAL generalized force, so v dot fdamp is non-negative. !! Kq = d(fdamp)/dq and Kv = d(fdamp)/dv are exact analytical Jacobians. + !! + !! l0_dot (optional): the unstretched-length rate of an element under active line + !! control. The strain |r_xi|/l0 - 1 then also changes with l0: the material-tangent + !! terms of r_xi carry the factor l0 and cancel, so only the end-position part + !! p = dH_1 r_1 + dH_3 r_2 contributes, and the strain rate becomes + !! + !! strain_rate = t dot (v_xi - (l0_dot/l0) p) / l0, + !! + !! the rate of the strain the elastic resultant uses, so a segment paid out at constant + !! strain carries no damping force (the MoorDyn-F convention ldot - (l/L0) L0dot of the + !! EI = 0 lines, taken pointwise). Kq gains -BA dH_a dH_b (l0_dot/l0**2) t t^T on the + !! end-position columns b, and the transverse part of v_xi becomes that of the same + !! combination; Kv is unchanged. REAL(wp), INTENT(IN) :: qe(12), ve(12), l0, BA REAL(wp), INTENT(OUT) :: fdamp(12) REAL(wp), INTENT(OUT), OPTIONAL :: Kq(12, 12), Kv(12, 12) INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg INTEGER, INTENT(IN), OPTIONAL :: quadrature_order + REAL(wp), INTENT(IN), OPTIONAL :: l0_dot REAL(wp) :: gp(6), gw(6), H(4), dH(4) REAL(wp) :: r_xi(3), v_xi(3), tangent(3), pperp(3), projector(3, 3) - REAL(wp) :: speed, strain_rate, scale_q, scale_v + REAL(wp) :: speed, strain_rate, scale_q, scale_v, rate_ratio INTEGER :: order, ig, s, sp, c, cp, ia, ib ErrStat = CD_HCDYN_OK @@ -6841,6 +7455,13 @@ SUBROUTINE CD_HermiteCable_Axial_Damping_Element(qe, ve, l0, BA, fdamp, Kq, Kv, IF (order < 1 .OR. order > 6) THEN CALL fail('quadrature_order must lie in [1,6]'); RETURN END IF + rate_ratio = CD_ZERO + IF (PRESENT(l0_dot)) THEN + IF (.NOT. CD_Is_Finite(l0_dot)) THEN + CALL fail('l0_dot must be finite'); RETURN + END IF + rate_ratio = l0_dot/l0 + END IF IF (.NOT. (BA > CD_ZERO)) RETURN CALL CD_HermiteCable_Gauss_Rule(order, gp, gw) @@ -6857,6 +7478,8 @@ SUBROUTINE CD_HermiteCable_Axial_Damping_Element(qe, ve, l0, BA, fdamp, Kq, Kv, CALL fail('collapsed or non-finite element tangent at a quadrature point'); RETURN END IF tangent = r_xi/speed + ! controlled element: the rate of the end-position part of r_xi at fixed q + IF (PRESENT(l0_dot)) v_xi = v_xi - rate_ratio*(dH(1)*qe(1:3) + dH(3)*qe(7:9)) strain_rate = DOT_PRODUCT(tangent, v_xi)/l0 projector = CD_ZERO DO c = 1, 3 @@ -6884,6 +7507,9 @@ SUBROUTINE CD_HermiteCable_Axial_Damping_Element(qe, ve, l0, BA, fdamp, Kq, Kv, scale_q = gw(ig)*BA*dH(s)*dH(sp)/speed Kq(ia, ib) = Kq(ia, ib) + scale_q*(strain_rate*projector(c, cp) + & tangent(c)*pperp(cp)/l0) + ! the length-rate term depends on the end positions (sp = 1, 3) only + IF (PRESENT(l0_dot) .AND. MOD(sp, 2) == 1) & + Kq(ia, ib) = Kq(ia, ib) - gw(ig)*BA*dH(s)*dH(sp)*(rate_ratio/l0)*tangent(c)*tangent(cp) END IF END DO END DO diff --git a/src/CableDyn_Model.f90 b/src/CableDyn_Model.f90 index a3198b82..631fc344 100644 --- a/src/CableDyn_Model.f90 +++ b/src/CableDyn_Model.f90 @@ -62,6 +62,7 @@ MODULE CableDyn_Model USE CableDyn_Linalg, ONLY: CD_Solve_Dense_As_Banded, CD_Solve_Dense_As_Banded_Multiple, CD_Factor_Banded, & CD_Solve_Factored_Banded_Multiple USE CableDyn_Profile, ONLY: CD_Profile_Count_Line_Step + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: INT64 IMPLICIT NONE PRIVATE @@ -97,6 +98,7 @@ MODULE CableDyn_Model PUBLIC :: CD_Set_Model_EndQuery PUBLIC :: CD_Get_Model_EndQuery PUBLIC :: CD_Update_Model_SegmentLength + PUBLIC :: CD_ModelControlSaveType, CD_Save_Model_Control, CD_Restore_Model_Control PUBLIC :: CD_Calc_Model_CoupledLoads PUBLIC :: CD_Calc_Model_CoupledKinematicDerivatives PUBLIC :: CD_Calc_Model_CoupledAccelDerivative, CD_Update_Model_CoupledAccelDerivative @@ -140,7 +142,7 @@ MODULE CableDyn_Model ! slots. commit_state_copy holds the one list of that state. TYPE :: CD_ModelCommitSlot REAL(wp), ALLOCATABLE :: q(:), v(:), a(:), ve_dl_1(:), syrope_slow(:), syrope_tmax(:) - REAL(wp), ALLOCATABLE :: fr_anchor(:, :) + REAL(wp), ALLOCATABLE :: fr_anchor(:, :), l0_c(:), l0_dot_c(:) END TYPE CD_ModelCommitSlot ! Diagnostics of the rotation- and snap-resolved sub-stepping (CD_Step_Model): calls counts @@ -155,6 +157,20 @@ MODULE CableDyn_Model INTEGER :: max_used = 1 END TYPE CD_SubstepStats + TYPE :: CD_ModelControlSaveType + !! What CD_Update_Model_SegmentLength writes, as CD_Save_Model_Control found it. + LOGICAL :: valid = .FALSE. + REAL(wp), ALLOCATABLE :: l0(:), l0_dot(:), l0_c(:), l0_dot_c(:), f_ext(:), seabed_kn(:), seabed_cn(:) + END TYPE CD_ModelControlSaveType + + TYPE :: model_lengths_aside + !! The present lengths and rates, and the external load and seabed coefficients that follow + !! the lengths, that enter_committed_lengths set aside (leave_committed_lengths moves them + !! back). + LOGICAL :: active = .FALSE. + REAL(wp), ALLOCATABLE :: l0(:), l0_dot(:), f_ext(:), kn(:), cn(:) + END TYPE model_lengths_aside + TYPE :: CD_ModelType !! Persistent positions-only EI=0 model state and immutable mesh/properties. LOGICAL :: initialized = .FALSE. @@ -170,6 +186,17 @@ MODULE CableDyn_Model ! until CD_Update_Model_SegmentLength sets it). Feeds the axial-damping ! effective stretch rate. REAL(wp), ALLOCATABLE :: l0_dot(:) + ! The unstretched lengths and rates the committed state was reached with (active line + ! control), so the committed state keeps its own lengths in the generalised-alpha blend of + ! the step that follows a length change (CD_Step_Model). With the force blend the step-start + ! force takes l0_c and l0_dot_c (with the external load and seabed coefficients of l0_c), + ! the end-of-step force the present lengths and rates, and only the inertia the blended + ! lengths (1 - alpha_f) l0 + alpha_f l0_c; under False alpha_force_blend every alpha-level + ! term takes the blended lengths and rates. Each successful step makes the present lengths + ! the committed ones. l0_c_rollback / recovery_l0_c are the copies of the system + ! stage-then-commit and of the recovering step. + REAL(wp), ALLOCATABLE :: l0_c(:), l0_dot_c(:) + REAL(wp), ALLOCATABLE :: l0_c_rollback(:), l0_dot_c_rollback(:), recovery_l0_c(:), recovery_l0_dot_c(:) ! Per-element distributed load per unit LENGTH (3, n_elem) plus the ! NON-distributed remainder of the init f_ext, stored when the caller supplies ! the per-length load: a segment-length update REASSEMBLES the distributed part @@ -362,13 +389,16 @@ MODULE CableDyn_Model ! parameter of the line, copied with the model). The other sub_* arrays are scratch: ! sub_slot(1) the committed state at the step start, sub_slot(2) the state the plain step ! reached, sub_t0 and sub_t1 the segment tensions at the step start and end, and - ! sub_pq/pv/pa the sub-step boundary motion. + ! sub_pq/pv/pa the sub-step boundary motion, sub_target the lengths, rates, external load + ! and seabed coefficients a pending length change (active line control) sets for the end of + ! the step (CD_Save_Model_Control). TYPE(CD_SubstepStats) :: sub_stats, sub_stats_rollback REAL(wp) :: sub_t_init = CD_ZERO ! audit_hmax at the last save of the system-rollback state (CableDyn_System) REAL(wp) :: audit_hmax_rollback = CD_ZERO TYPE(CD_ModelCommitSlot) :: sub_slot(2) REAL(wp), ALLOCATABLE :: sub_t0(:), sub_t1(:), sub_pq(:), sub_pv(:), sub_pa(:) + TYPE(CD_ModelControlSaveType) :: sub_target ! TEST-ONLY hooks of the sub-stepping, never set by a production caller: sub_test_fail > 0 ! makes sub-step number sub_test_fail of every sub-stepped pass report a failure, and ! sub_test_repeat solves the first sub-stepped pass twice (the second from the restored @@ -911,6 +941,8 @@ SUBROUTINE CD_Init_Model(model, q0, v0, elem_conn, l0, ea, rho_a, tension_only, model%cfg = cfg ALLOCATE (model%elem_conn(2, n_elem), model%fixed_dofs(SIZE(fixed_dofs)), & model%l0(n_elem), model%ea(n_elem), model%ea_dyn(n_elem), model%rho_a(n_elem), model%l0_dot(n_elem), & + model%l0_c(n_elem), model%l0_dot_c(n_elem), model%l0_c_rollback(n_elem), & + model%l0_dot_c_rollback(n_elem), model%recovery_l0_c(n_elem), model%recovery_l0_dot_c(n_elem), & model%f_ext(n_dof), & model%q(n_dof), model%v(n_dof), model%a(n_dof), & model%q_step(n_dof), model%v_step(n_dof), model%a_step(n_dof), & @@ -926,6 +958,12 @@ SUBROUTINE CD_Init_Model(model, q0, v0, elem_conn, l0, ea, rho_a, tension_only, model%fixed_dofs = fixed_dofs model%l0 = l0 model%l0_dot = CD_ZERO + model%l0_c = l0 + model%l0_dot_c = CD_ZERO + model%l0_c_rollback = l0 + model%l0_dot_c_rollback = CD_ZERO + model%recovery_l0_c = l0 + model%recovery_l0_dot_c = CD_ZERO model%ea = ea model%ea_dyn = ea model%rho_a = rho_a @@ -1948,6 +1986,19 @@ SUBROUTINE CD_Step_Model(model, dt, converged, stalled, n_iter, ErrStat, ErrMsg, !! needs the end reaction and tangent of the nominal step. as_given = .TRUE. takes the step !! as given as well: the stall recoveries of CD_Step_Model_Recovering and CD_Step_System, !! whose sub-steps are themselves part of a recovery, pass it. + !! + !! A pending length change (active line control: CD_Update_Model_SegmentLength set lengths + !! or rates that differ from those the committed state was reached with, l0_c and l0_dot_c) + !! is spread over the sub-steps. The committed lengths are part of the state each pass + !! starts from (commit_state_copy). Sub-step k of n ends at the lengths and rates + !! interpolated linearly in time between the committed ones and the new ones at k/n, with + !! the external load and seabed coefficients rebuilt at those lengths as + !! CD_Update_Model_SegmentLength builds them, and the last sub-step ends at the new lengths, + !! rates, external load and seabed coefficients bit for bit. Each sub-step treats its own + !! start and end lengths as the plain step treats the committed and new ones, so the first + !! starts at the committed lengths. (A constant pay-out rate, the usual command, makes the + !! interpolated lengths those its rate integrates to.) The trigger takes the step-start + !! tensions and slack classification at the committed lengths. TYPE(CD_ModelType), INTENT(INOUT) :: model REAL(wp), INTENT(IN) :: dt LOGICAL, INTENT(OUT) :: converged, stalled @@ -1956,9 +2007,10 @@ SUBROUTINE CD_Step_Model(model, dt, converged, stalled, n_iter, ErrStat, ErrMsg, REAL(wp), INTENT(IN), OPTIONAL :: prescribed_q(:), prescribed_v(:), prescribed_a(:) LOGICAL, INTENT(IN), OPTIONAL :: as_given INTEGER :: nsub, nsub2, iter_trial - LOGICAL :: has_pres, resolve, capped, capped2, ok + LOGICAL :: has_pres, resolve, capped, capped2, ok, pending has_pres = PRESENT(prescribed_q) .AND. PRESENT(prescribed_v) .AND. PRESENT(prescribed_a) + pending = .FALSE. resolve = model%initialized .AND. model%cfg%ei0_substeps == CD_EI0_SUBSTEPS_AUTO .AND. & .NOT. model%dynamic_workspace%end_request IF (resolve .AND. PRESENT(as_given)) resolve = .NOT. as_given @@ -1969,8 +2021,23 @@ SUBROUTINE CD_Step_Model(model, dt, converged, stalled, n_iter, ErrStat, ErrMsg, resolve = sub_alloc(model, has_pres) IF (resolve) THEN CALL sub_store(model, 1) - ! the segment tensions at the step start, for the trigger (sub_count) - CALL sub_tensions_scratch(model, 0) + ! the segment tensions at the step start, for the trigger (sub_count), at the lengths + ! the committed state was reached with + pending = .NOT. model_lengths_committed(model) + IF (pending) THEN + CALL CD_Save_Model_Control(model, model%sub_target) + BLOCK + TYPE(model_lengths_aside) :: aside + INTEGER :: es_c + CHARACTER(160) :: em_c + ! without the loads nothing is rebuilt, so this cannot fail + CALL enter_committed_lengths(model, aside, .FALSE., es_c, em_c) + CALL sub_tensions_scratch(model, 0) + CALL leave_committed_lengths(model, aside) + END BLOCK + ELSE + CALL sub_tensions_scratch(model, 0) + END IF END IF END IF IF (.NOT. resolve) THEN @@ -2029,6 +2096,7 @@ SUBROUTINE CD_Step_Model(model, dt, converged, stalled, n_iter, ErrStat, ErrMsg, END IF ! a sub-step failed: return the plain step's own (converged) result CALL sub_load(model, 2) + IF (pending) CALL sub_lengths_target(model) converged = .TRUE. stalled = .FALSE. n_iter = iter_trial @@ -2052,6 +2120,19 @@ SUBROUTINE run_substeps(n, ok_run) h = dt/REAL(n, wp) ok_run = .TRUE. DO k = 1, n + ! a pending length change: the lengths at the sub-step end (the new ones at the last) + IF (pending) THEN + IF (k == n) THEN + CALL sub_lengths_target(model) + ELSE + CALL sub_lengths_at(model, REAL(k, wp)/REAL(n, wp), es_k) + IF (es_k /= CD_MODEL_OK) THEN + CALL sub_lengths_target(model) + ok_run = .FALSE. + RETURN + END IF + END IF + END IF IF (has_pres) THEN IF (k == n) THEN model%sub_pq = prescribed_q @@ -2069,6 +2150,7 @@ SUBROUTINE run_substeps(n, ok_run) END IF IF (k == model%sub_test_fail) conv_k = .FALSE. IF (es_k /= CD_MODEL_OK .OR. .NOT. conv_k) THEN + IF (pending) CALL sub_lengths_target(model) ok_run = .FALSE. RETURN END IF @@ -2093,6 +2175,11 @@ LOGICAL FUNCTION sub_alloc(model, has_pres) RESULT(ok) ALLOCATE (s%q(model%n_dof), s%v(model%n_dof), s%a(model%n_dof), STAT=istat) IF (istat /= 0) RETURN END IF + IF (.NOT. sized(s%l0_c, model%n_elem)) THEN + IF (ALLOCATED(s%l0_c)) DEALLOCATE (s%l0_c, s%l0_dot_c) + ALLOCATE (s%l0_c(model%n_elem), s%l0_dot_c(model%n_elem), STAT=istat) + IF (istat /= 0) RETURN + END IF IF (model%has_viscoelastic) THEN IF (.NOT. sized(s%ve_dl_1, SIZE(model%ve_dl_1))) THEN IF (ALLOCATED(s%ve_dl_1)) DEALLOCATE (s%ve_dl_1) @@ -2146,14 +2233,16 @@ LOGICAL FUNCTION sized(x, n) RESULT(yes) END FUNCTION sized END FUNCTION sub_alloc - SUBROUTINE commit_state_copy(model, to_model, q, v, a, ve_dl_1, syrope_slow, syrope_tmax, fr_anchor) + SUBROUTINE commit_state_copy(model, to_model, q, v, a, ve_dl_1, syrope_slow, syrope_tmax, fr_anchor, & + l0_c, l0_dot_c) !! The one list of the state a line step commits: the kinematics, the viscoelastic dl_1, the - !! Syrope slow strain and running maximum tension, and the friction anchors. to_model = + !! Syrope slow strain and running maximum tension, the friction anchors, and the unstretched + !! lengths and rates the committed state was reached with (l0_c, l0_dot_c, active line + !! control). to_model = !! .FALSE. saves the model's state into the arrays given, .TRUE. returns the model to them. !! Every snapshot of the committed state in this module goes through here (the sub-step !! slots of CD_Step_Model, save_recovery_state and restore_recovery_state). A state a step - !! comes to commit (such as the segment length of a line under active tension control) is - !! added here, as an optional array its snapshots pass; the rollback of the line system + !! comes to commit is added here, as an optional array its snapshots pass; the rollback of the line system !! (CableDyn_System: save_line_states, restore_line_states, CD_System_Snapshot and the !! frame snapshot of CD_Step_System) lists the same state and must follow. An optional array !! is passed as an allocatable that is allocated with the state it holds, so it is absent @@ -2162,6 +2251,7 @@ SUBROUTINE commit_state_copy(model, to_model, q, v, a, ve_dl_1, syrope_slow, syr LOGICAL, INTENT(IN) :: to_model REAL(wp), INTENT(INOUT) :: q(:), v(:), a(:) REAL(wp), INTENT(INOUT), OPTIONAL :: ve_dl_1(:), syrope_slow(:), syrope_tmax(:), fr_anchor(:, :) + REAL(wp), INTENT(INOUT), OPTIONAL :: l0_c(:), l0_dot_c(:) IF (to_model) THEN model%q = q model%v = v @@ -2172,6 +2262,10 @@ SUBROUTINE commit_state_copy(model, to_model, q, v, a, ve_dl_1, syrope_slow, syr model%syrope_tmax = syrope_tmax END IF IF (model%has_seabed_friction .AND. PRESENT(fr_anchor)) model%fr_anchor = fr_anchor + IF (PRESENT(l0_c) .AND. PRESENT(l0_dot_c)) THEN + model%l0_c = l0_c + model%l0_dot_c = l0_dot_c + END IF ELSE q = model%q v = model%v @@ -2182,6 +2276,10 @@ SUBROUTINE commit_state_copy(model, to_model, q, v, a, ve_dl_1, syrope_slow, syr syrope_tmax = model%syrope_tmax END IF IF (model%has_seabed_friction .AND. PRESENT(fr_anchor)) fr_anchor = model%fr_anchor + IF (PRESENT(l0_c) .AND. PRESENT(l0_dot_c)) THEN + l0_c = model%l0_c + l0_dot_c = model%l0_dot_c + END IF END IF END SUBROUTINE commit_state_copy @@ -2191,7 +2289,8 @@ SUBROUTINE sub_store(model, slot) INTEGER, INTENT(IN) :: slot CALL commit_state_copy(model, .FALSE., model%sub_slot(slot)%q, model%sub_slot(slot)%v, model%sub_slot(slot)%a, & model%sub_slot(slot)%ve_dl_1, model%sub_slot(slot)%syrope_slow, & - model%sub_slot(slot)%syrope_tmax, model%sub_slot(slot)%fr_anchor) + model%sub_slot(slot)%syrope_tmax, model%sub_slot(slot)%fr_anchor, & + model%sub_slot(slot)%l0_c, model%sub_slot(slot)%l0_dot_c) END SUBROUTINE sub_store SUBROUTINE sub_load(model, slot) @@ -2200,9 +2299,83 @@ SUBROUTINE sub_load(model, slot) INTEGER, INTENT(IN) :: slot CALL commit_state_copy(model, .TRUE., model%sub_slot(slot)%q, model%sub_slot(slot)%v, model%sub_slot(slot)%a, & model%sub_slot(slot)%ve_dl_1, model%sub_slot(slot)%syrope_slow, & - model%sub_slot(slot)%syrope_tmax, model%sub_slot(slot)%fr_anchor) + model%sub_slot(slot)%syrope_tmax, model%sub_slot(slot)%fr_anchor, & + model%sub_slot(slot)%l0_c, model%sub_slot(slot)%l0_dot_c) END SUBROUTINE sub_load + SUBROUTINE sub_lengths_target(model) + !! Put back the lengths, rates, external load and seabed coefficients a pending length + !! change set for the end of the step (sub_target, saved by CD_Step_Model), bit for bit; the + !! committed lengths are left as they are. + TYPE(CD_ModelType), INTENT(INOUT) :: model + model%l0 = model%sub_target%l0 + model%l0_dot = model%sub_target%l0_dot + model%f_ext = model%sub_target%f_ext + IF (ALLOCATED(model%sub_target%seabed_kn)) model%seabed_kn = model%sub_target%seabed_kn + IF (ALLOCATED(model%sub_target%seabed_cn)) model%seabed_cn = model%sub_target%seabed_cn + END SUBROUTINE sub_lengths_target + + SUBROUTINE sub_lengths_at(model, frac, ErrStat) + !! The lengths and rates at the fraction frac of a sub-stepped interval with a pending length + !! change: interpolated linearly in time between those of the committed state at the + !! interval start (sub_slot(1)) and the new ones (sub_target), an element whose length or + !! rate does not change keeping it bit for bit; the external load and the seabed + !! coefficients that follow the lengths are rebuilt at them with the helpers + !! CD_Update_Model_SegmentLength uses (those of the new lengths when no length changes). + !! On failure the model is left as it was. + TYPE(CD_ModelType), INTENT(INOUT) :: model + REAL(wp), INTENT(IN) :: frac + INTEGER, INTENT(OUT) :: ErrStat + REAL(wp) :: l0_k(model%n_elem), l0_dot_k(model%n_elem), f_dist(model%n_dof) + REAL(wp), ALLOCATABLE :: kn_k(:) + REAL(wp) :: a, b + INTEGER :: e, es + LOGICAL :: moved + CHARACTER(160) :: em + ErrStat = CD_MODEL_OK + moved = .FALSE. + DO e = 1, model%n_elem + a = model%sub_slot(1)%l0_c(e) + b = model%sub_target%l0(e) + l0_k(e) = b + IF (.NOT. bits_equal(a, b)) THEN + l0_k(e) = a + frac*(b - a) + moved = .TRUE. + END IF + a = model%sub_slot(1)%l0_dot_c(e) + b = model%sub_target%l0_dot(e) + l0_dot_k(e) = b + IF (.NOT. bits_equal(a, b)) l0_dot_k(e) = positive_zero(a + frac*(b - a)) + END DO + IF (moved .AND. ALLOCATED(model%dist_load)) THEN + CALL CD_Assemble_Distributed_Load(model%elem_conn, l0_k, model%dist_load, f_dist, es, em) + IF (es /= 0) THEN + ErrStat = CD_MODEL_BADINPUT + RETURN + END IF + f_dist = model%f_ext_dist_base + f_dist + IF (.NOT. CD_All_Finite(f_dist)) THEN + ErrStat = CD_MODEL_BADINPUT + RETURN + END IF + END IF + IF (moved .AND. model%has_seabed .AND. model%has_seabed_recompute) THEN + CALL CD_Nodal_Seabed_Stiffness(model%seabed_kbot, model%seabed_diameter_elem, l0_k, kn_k, es, em) + IF (es /= 0) THEN + ErrStat = CD_MODEL_BADINPUT + RETURN + END IF + END IF + CALL sub_lengths_target(model) + model%l0 = l0_k + model%l0_dot = l0_dot_k + IF (moved .AND. ALLOCATED(model%dist_load)) model%f_ext = f_dist + IF (ALLOCATED(kn_k)) THEN + CALL MOVE_ALLOC(kn_k, model%seabed_kn) + IF (ALLOCATED(model%seabed_cn)) model%seabed_cn = model%seabed_kn*model%seabed_cn_over_kn + END IF + END SUBROUTINE sub_lengths_at + SUBROUTINE sub_tensions(model, tension) !! The segment tensions at the model's committed state as the run audit takes them !! (CD_Audit_Model_Step): the dynamic EA times the strain of an elastic segment, the law's @@ -2291,9 +2464,9 @@ SUBROUTINE sub_count(model, dt, nsub, capped) !! scale (the largest step-start tension, at least SUB_TAUT_FRACTION of sub_t_init); at least !! SUB_SNAP_STEPS when a segment slack at the start ends above SUB_SNAP_FRACTION of the scale !! and its axial wave crosses it more than once in dt. The tensions are those of - !! sub_tensions. The strains use model%l0, the lengths the step itself uses - !! (CD_Update_Model_SegmentLength sets them before the step); a length that changes within - !! the step would need its step-start value for the start state here. + !! sub_tensions. The end state takes the present lengths model%l0, the start state the + !! lengths it was reached with (slot 1's l0_c; the same bits unless a length change is + !! pending, see CD_Step_Model). TYPE(CD_ModelType), INTENT(INOUT) :: model REAL(wp), INTENT(IN) :: dt INTEGER, INTENT(OUT) :: nsub @@ -2318,7 +2491,7 @@ SUBROUTINE sub_count(model, dt, nsub, capped) te = model%sub_t1(e) d0 = model%sub_slot(1)%q(3*nb - 2:3*nb) - model%sub_slot(1)%q(3*na - 2:3*na) l_s = NORM2(d0) - IF (.NOT. snap .AND. l_s <= model%l0(e) .AND. te > SUB_SNAP_FRACTION*scale) THEN + IF (.NOT. snap .AND. l_s <= model%sub_slot(1)%l0_c(e) .AND. te > SUB_SNAP_FRACTION*scale) THEN courant = dt*SQRT(segment_wave_stiffness(model, e, te)/model%rho_a(e))/model%l0(e) IF (courant > CD_ONE) snap = .TRUE. END IF @@ -2366,9 +2539,13 @@ SUBROUTINE step_model_plain(model, dt, converged, stalled, n_iter, ErrStat, ErrM CHARACTER(*), INTENT(OUT) :: ErrMsg REAL(wp), INTENT(IN), OPTIONAL :: prescribed_q(:), prescribed_v(:), prescribed_a(:) - INTEGER :: es + INTEGER :: es, e CHARACTER(160) :: em - LOGICAL :: has_load + LOGICAL :: has_load, blend, force_lengths + REAL(wp) :: af + REAL(wp), ALLOCATABLE :: l0_new(:), l0_dot_new(:), l0_start(:), l0_mass(:), f_ext_new(:), f_ext_c(:) + REAL(wp), ALLOCATABLE :: l0_dot_start(:) + TYPE(model_lengths_aside) :: aside converged = .FALSE. stalled = .FALSE. @@ -2405,70 +2582,70 @@ SUBROUTINE step_model_plain(model, dt, converged, stalled, n_iter, ErrStat, ErrM ! whose tension (tension_start_work) the release cap of the step bounds like the elastic ! tension. A warm re-solve of the same step (the junction coupling re-steps the line from ! the same committed state with moved ends) reuses the load of the previous call. - IF (.NOT. (has_load .AND. model%cfg%force_blend)) THEN - model%load_start_valid = .FALSE. - ELSE IF (.NOT. (model%dynamic_workspace%guess_armed .AND. model%load_start_valid)) THEN - model%load_start_valid = .FALSE. - IF (ALLOCATED(model%load_start_work)) THEN - IF (SIZE(model%load_start_work) /= model%n_dof) DEALLOCATE (model%load_start_work) - END IF - IF (.NOT. ALLOCATED(model%load_start_work)) THEN - ALLOCATE (model%load_start_work(model%n_dof), STAT=es) - IF (es /= 0) THEN - ErrStat = CD_MODEL_ALLOCFAIL - ErrMsg = 'CableDyn_Model: step-start load workspace allocation failed' - RETURN - END IF - END IF - ! tension_start_work stays unallocated without a viscoelastic or Syrope element, and the - ! step then sees start_tension absent - IF (ALLOCATED(model%tension_start_work)) THEN - IF (SIZE(model%tension_start_work) /= model%n_elem .OR. & - .NOT. (model%has_viscoelastic .OR. model%has_syrope)) DEALLOCATE (model%tension_start_work) - END IF - IF ((model%has_viscoelastic .OR. model%has_syrope) .AND. .NOT. ALLOCATED(model%tension_start_work)) THEN - ALLOCATE (model%tension_start_work(model%n_elem), STAT=es) - IF (es /= 0) THEN - ErrStat = CD_MODEL_ALLOCFAIL - ErrMsg = 'CableDyn_Model: step-start tension workspace allocation failed' - RETURN - END IF - END IF - IF (ALLOCATED(model%stiffness_start_work)) THEN - IF (.NOT. ALLOCATED(model%tension_start_work)) THEN - DEALLOCATE (model%stiffness_start_work) - ELSE IF (SIZE(model%stiffness_start_work) /= model%n_elem) THEN - DEALLOCATE (model%stiffness_start_work) - END IF - END IF - IF (ALLOCATED(model%tension_start_work) .AND. .NOT. ALLOCATED(model%stiffness_start_work)) THEN - ALLOCATE (model%stiffness_start_work(model%n_elem), STAT=es) - IF (es /= 0) THEN - ErrStat = CD_MODEL_ALLOCFAIL - ErrMsg = 'CableDyn_Model: step-start stiffness workspace allocation failed' - RETURN - END IF - END IF - model%ve_dt = CD_ZERO - IF (ALLOCATED(model%tension_start_work)) THEN - CALL model_contributor_force(model, model%q, model%v, model%load_start_work, es, em, & - law_tension=model%tension_start_work, & - law_stiffness=model%stiffness_start_work) - ELSE - CALL model_contributor_force(model, model%q, model%v, model%load_start_work, es, em) - END IF + ! + ! Active line control: after a length or rate change the committed state keeps the lengths + ! and rates it was reached with (l0_c, l0_dot_c), and the step that follows treats them as + ! the generalised-alpha form requires. With the force blend, r(q_{n+1}, v_{n+1}) takes the + ! present lengths, rates, external load and seabed coefficients, and r(q_n, v_n) those of + ! the committed state: its load (here) and its internal force and release-cap data (the + ! step's start_l0) are evaluated at l0_c and l0_dot_c, with the distributed load and the + ! recomputed seabed coefficients rebuilt at l0_c (enter_committed_lengths), and the + ! constant external load of the step blends the two, (1 - alpha_f) f_ext + alpha_f f_ext_c. + ! The inertia, which the force blend keeps at the alpha level (M a_alpha, the added mass + ! at q_alpha), takes the blended lengths (1 - alpha_f) l0 + alpha_f l0_c. Under + ! False alpha_force_blend every alpha-level term (internal force, damping, hydrodynamic + ! loads, the structural and added mass) takes the blended lengths and rates, with the + ! present external load and seabed coefficients. Either way the lengths are blended element + ! by element and only where they differ, the new lengths come back with the state at + ! t_{n+1}, and an unchanged model takes the plain path. + blend = .NOT. model_lengths_committed(model) + force_lengths = blend .AND. model%cfg%force_blend + af = model%cfg%rho_inf/(model%cfg%rho_inf + CD_ONE) + IF (force_lengths) THEN + CALL enter_committed_lengths(model, aside, .TRUE., es, em) IF (es /= CD_MODEL_OK) THEN ErrStat = es - ErrMsg = 'CableDyn_Model: step-start load failed: '//TRIM(em) + ErrMsg = 'CableDyn_Model: step-start lengths: '//TRIM(em) RETURN END IF - model%load_start_valid = .TRUE. + IF (ALLOCATED(aside%f_ext)) f_ext_c = model%f_ext END IF + CALL step_start_load(ErrStat, ErrMsg) + IF (force_lengths) CALL leave_committed_lengths(model, aside) + IF (ErrStat /= CD_MODEL_OK) RETURN ! arm the viscoelastic contributors with the step size: in-step load ! evaluations use the backward-Euler-eliminated dl_1(q, v); it is reset to ! the instantaneous limit (0) on EVERY exit below so committed-state queries ! (coupled loads, tension) never see a stale step size model%ve_dt = dt + IF (force_lengths) THEN + ! the release cap's step-start dashpot takes the committed rates (start_l0_rate) + l0_dot_start = model%l0_dot_c + IF (.NOT. ALL(bits_equal(model%l0, model%l0_c))) THEN + l0_start = model%l0_c + l0_mass = model%l0 + DO e = 1, model%n_elem + IF (.NOT. bits_equal(model%l0(e), model%l0_c(e))) & + l0_mass(e) = (CD_ONE - af)*model%l0(e) + af*model%l0_c(e) + END DO + END IF + IF (ALLOCATED(f_ext_c)) THEN + f_ext_new = model%f_ext + DO e = 1, model%n_dof + IF (.NOT. bits_equal(f_ext_new(e), f_ext_c(e))) & + model%f_ext(e) = (CD_ONE - af)*f_ext_new(e) + af*f_ext_c(e) + END DO + END IF + ELSE IF (blend) THEN + l0_new = model%l0 + l0_dot_new = model%l0_dot + DO e = 1, model%n_elem + IF (.NOT. bits_equal(l0_new(e), model%l0_c(e))) & + model%l0(e) = (CD_ONE - af)*l0_new(e) + af*model%l0_c(e) + IF (.NOT. bits_equal(l0_dot_new(e), model%l0_dot_c(e))) & + model%l0_dot(e) = (CD_ONE - af)*l0_dot_new(e) + af*model%l0_dot_c(e) + END DO + END IF IF (PRESENT(prescribed_q) .AND. has_load .AND. model%has_added_mass) THEN CALL CD_Cable_Gen_Alpha_Step(model%q, model%v, model%a, model%elem_conn, model%l0, model%ea_dyn, & model%rho_a, model%tension_only, model%f_ext, model%fixed_dofs, & @@ -2480,7 +2657,8 @@ SUBROUTINE step_model_plain(model, dt, converged, stalled, n_iter, ErrStat, ErrM workspace=model%dynamic_workspace, start_load=model%load_start_work, & start_tension=model%tension_start_work, & start_stiffness=model%stiffness_start_work, & - axial_damping=model%ba_dyn, axial_l0_rate=model%l0_dot) + axial_damping=model%ba_dyn, axial_l0_rate=model%l0_dot, & + start_l0=l0_start, mass_l0=l0_mass, start_l0_rate=l0_dot_start) ELSE IF (PRESENT(prescribed_q) .AND. has_load) THEN CALL CD_Cable_Gen_Alpha_Step(model%q, model%v, model%a, model%elem_conn, model%l0, model%ea_dyn, & model%rho_a, model%tension_only, model%f_ext, model%fixed_dofs, & @@ -2491,7 +2669,8 @@ SUBROUTINE step_model_plain(model, dt, converged, stalled, n_iter, ErrStat, ErrM prescribed_a=prescribed_a, workspace=model%dynamic_workspace, & start_load=model%load_start_work, start_tension=model%tension_start_work, & start_stiffness=model%stiffness_start_work, & - axial_damping=model%ba_dyn, axial_l0_rate=model%l0_dot) + axial_damping=model%ba_dyn, axial_l0_rate=model%l0_dot, & + start_l0=l0_start, mass_l0=l0_mass, start_l0_rate=l0_dot_start) ELSE IF (PRESENT(prescribed_q) .AND. model%has_added_mass) THEN CALL CD_Cable_Gen_Alpha_Step(model%q, model%v, model%a, model%elem_conn, model%l0, model%ea_dyn, & model%rho_a, model%tension_only, model%f_ext, model%fixed_dofs, & @@ -2499,14 +2678,16 @@ SUBROUTINE step_model_plain(model, dt, converged, stalled, n_iter, ErrStat, ErrM n_iter, & es, em, added_mass_band_proc=model_added_mass_band, prescribed_q=prescribed_q, & prescribed_v=prescribed_v, prescribed_a=prescribed_a, & - workspace=model%dynamic_workspace) + workspace=model%dynamic_workspace, & + start_l0=l0_start, mass_l0=l0_mass) ELSE IF (PRESENT(prescribed_q)) THEN CALL CD_Cable_Gen_Alpha_Step(model%q, model%v, model%a, model%elem_conn, model%l0, model%ea_dyn, & model%rho_a, model%tension_only, model%f_ext, model%fixed_dofs, & dt, model%cfg, model%q_step, model%v_step, model%a_step, converged, stalled, & n_iter, & es, em, prescribed_q=prescribed_q, prescribed_v=prescribed_v, & - prescribed_a=prescribed_a, workspace=model%dynamic_workspace) + prescribed_a=prescribed_a, workspace=model%dynamic_workspace, & + start_l0=l0_start, mass_l0=l0_mass) ELSE IF (has_load .AND. model%has_added_mass) THEN CALL CD_Cable_Gen_Alpha_Step(model%q, model%v, model%a, model%elem_conn, model%l0, model%ea_dyn, & model%rho_a, model%tension_only, model%f_ext, model%fixed_dofs, & @@ -2516,7 +2697,8 @@ SUBROUTINE step_model_plain(model, dt, converged, stalled, n_iter, ErrStat, ErrM added_mass_band_proc=model_added_mass_band, workspace=model%dynamic_workspace, & start_load=model%load_start_work, start_tension=model%tension_start_work, & start_stiffness=model%stiffness_start_work, & - axial_damping=model%ba_dyn, axial_l0_rate=model%l0_dot) + axial_damping=model%ba_dyn, axial_l0_rate=model%l0_dot, & + start_l0=l0_start, mass_l0=l0_mass, start_l0_rate=l0_dot_start) ELSE IF (has_load) THEN CALL CD_Cable_Gen_Alpha_Step(model%q, model%v, model%a, model%elem_conn, model%l0, model%ea_dyn, & model%rho_a, model%tension_only, model%f_ext, model%fixed_dofs, & @@ -2526,19 +2708,25 @@ SUBROUTINE step_model_plain(model, dt, converged, stalled, n_iter, ErrStat, ErrM workspace=model%dynamic_workspace, start_load=model%load_start_work, & start_tension=model%tension_start_work, & start_stiffness=model%stiffness_start_work, & - axial_damping=model%ba_dyn, axial_l0_rate=model%l0_dot) + axial_damping=model%ba_dyn, axial_l0_rate=model%l0_dot, & + start_l0=l0_start, mass_l0=l0_mass, start_l0_rate=l0_dot_start) ELSE IF (model%has_added_mass) THEN CALL CD_Cable_Gen_Alpha_Step(model%q, model%v, model%a, model%elem_conn, model%l0, model%ea_dyn, & model%rho_a, model%tension_only, model%f_ext, model%fixed_dofs, & dt, model%cfg, model%q_step, model%v_step, model%a_step, converged, stalled, & n_iter, es, em, & - added_mass_band_proc=model_added_mass_band, workspace=model%dynamic_workspace) + added_mass_band_proc=model_added_mass_band, workspace=model%dynamic_workspace, & + start_l0=l0_start, mass_l0=l0_mass) ELSE CALL CD_Cable_Gen_Alpha_Step(model%q, model%v, model%a, model%elem_conn, model%l0, model%ea_dyn, & model%rho_a, model%tension_only, model%f_ext, model%fixed_dofs, & dt, model%cfg, model%q_step, model%v_step, model%a_step, converged, stalled, & - n_iter, es, em, workspace=model%dynamic_workspace) + n_iter, es, em, workspace=model%dynamic_workspace, & + start_l0=l0_start, mass_l0=l0_mass) END IF + IF (ALLOCATED(l0_new)) model%l0 = l0_new + IF (ALLOCATED(l0_dot_new)) model%l0_dot = l0_dot_new + IF (ALLOCATED(f_ext_new)) model%f_ext = f_ext_new model%ve_dt = CD_ZERO CALL CD_Profile_Count_Line_Step(n_iter) IF (es /= CD_DYN_OK) THEN @@ -2665,12 +2853,90 @@ SUBROUTINE step_model_plain(model, dt, converged, stalled, n_iter, ErrStat, ErrM model%q = model%q_step model%v = model%v_step model%a = model%a_step + ! the committed state is now the one of the present lengths and rates + IF (blend) THEN + model%l0_c = model%l0 + model%l0_dot_c = model%l0_dot + END IF ! The mapping repeats the queries validated above, so it cannot fail here. IF (model%has_seabed_friction) & CALL mapped_friction_anchors(model, model%q, model%v, .TRUE., ErrStat, ErrMsg) CONTAINS + SUBROUTINE step_start_load(es_s, em_s) + !! The force blend's load at the committed state (q_n, v_n) into load_start_work (with the + !! law tensions and axial stiffnesses of the viscoelastic and Syrope elements in + !! tension_start_work and stiffness_start_work), unless a + !! warm re-solve of the same step reuses the previous call's; without the force blend or a + !! load contributor there is none. Evaluated with the model as the caller left it (the + !! committed lengths entered after a length change). + INTEGER, INTENT(OUT) :: es_s + CHARACTER(*), INTENT(OUT) :: em_s + CHARACTER(160) :: em_c + es_s = CD_MODEL_OK + em_s = '' + IF (.NOT. (has_load .AND. model%cfg%force_blend)) THEN + model%load_start_valid = .FALSE. + RETURN + END IF + IF (model%dynamic_workspace%guess_armed .AND. model%load_start_valid) RETURN + model%load_start_valid = .FALSE. + IF (ALLOCATED(model%load_start_work)) THEN + IF (SIZE(model%load_start_work) /= model%n_dof) DEALLOCATE (model%load_start_work) + END IF + IF (.NOT. ALLOCATED(model%load_start_work)) THEN + ALLOCATE (model%load_start_work(model%n_dof), STAT=es_s) + IF (es_s /= 0) THEN + es_s = CD_MODEL_ALLOCFAIL + em_s = 'CableDyn_Model: step-start load workspace allocation failed' + RETURN + END IF + END IF + ! tension_start_work stays unallocated without a viscoelastic or Syrope element, and the + ! step then sees start_tension absent + IF (ALLOCATED(model%tension_start_work)) THEN + IF (SIZE(model%tension_start_work) /= model%n_elem .OR. & + .NOT. (model%has_viscoelastic .OR. model%has_syrope)) DEALLOCATE (model%tension_start_work) + END IF + IF ((model%has_viscoelastic .OR. model%has_syrope) .AND. .NOT. ALLOCATED(model%tension_start_work)) THEN + ALLOCATE (model%tension_start_work(model%n_elem), STAT=es_s) + IF (es_s /= 0) THEN + es_s = CD_MODEL_ALLOCFAIL + em_s = 'CableDyn_Model: step-start tension workspace allocation failed' + RETURN + END IF + END IF + IF (ALLOCATED(model%stiffness_start_work)) THEN + IF (.NOT. ALLOCATED(model%tension_start_work)) THEN + DEALLOCATE (model%stiffness_start_work) + ELSE IF (SIZE(model%stiffness_start_work) /= model%n_elem) THEN + DEALLOCATE (model%stiffness_start_work) + END IF + END IF + IF (ALLOCATED(model%tension_start_work) .AND. .NOT. ALLOCATED(model%stiffness_start_work)) THEN + ALLOCATE (model%stiffness_start_work(model%n_elem), STAT=es_s) + IF (es_s /= 0) THEN + es_s = CD_MODEL_ALLOCFAIL + em_s = 'CableDyn_Model: step-start stiffness workspace allocation failed' + RETURN + END IF + END IF + model%ve_dt = CD_ZERO + IF (ALLOCATED(model%tension_start_work)) THEN + CALL model_contributor_force(model, model%q, model%v, model%load_start_work, es_s, em_c, & + law_tension=model%tension_start_work, & + law_stiffness=model%stiffness_start_work) + ELSE + CALL model_contributor_force(model, model%q, model%v, model%load_start_work, es_s, em_c) + END IF + IF (es_s /= CD_MODEL_OK) THEN + em_s = 'CableDyn_Model: step-start load failed: '//TRIM(em_c) + RETURN + END IF + model%load_start_valid = .TRUE. + END SUBROUTINE step_start_load + SUBROUTINE model_force(q, v, force, ErrStat, ErrMsg) REAL(wp), INTENT(IN) :: q(:), v(:) REAL(wp), INTENT(OUT) :: force(:) @@ -2692,6 +2958,8 @@ END SUBROUTINE model_load_band SUBROUTINE model_added_mass_band(q, accel, free, kl, ku, M_add_a, M_add_band, dMa_a_dq_band, ErrStat, ErrMsg, & need_tangent) + !! The added mass at q_alpha; after a length change under the force blend with the + !! blended lengths of the inertia (l0_mass, unallocated and so absent otherwise). REAL(wp), INTENT(IN) :: q(:), accel(:) INTEGER, INTENT(IN) :: free(:), kl, ku REAL(wp), INTENT(OUT) :: M_add_a(:), M_add_band(:, :), dMa_a_dq_band(:, :) @@ -2699,7 +2967,7 @@ SUBROUTINE model_added_mass_band(q, accel, free, kl, ku, M_add_a, M_add_band, dM CHARACTER(*), INTENT(OUT) :: ErrMsg LOGICAL, INTENT(IN), OPTIONAL :: need_tangent CALL model_added_mass_banded(model, q, accel, free, kl, ku, M_add_a, M_add_band, dMa_a_dq_band, & - ErrStat, ErrMsg, need_tangent=need_tangent) + ErrStat, ErrMsg, need_tangent=need_tangent, l0_elem=l0_mass) ErrStat = as_dyn_callback_status(ErrStat) END SUBROUTINE model_added_mass_band END SUBROUTINE step_model_plain @@ -2879,12 +3147,123 @@ SUBROUTINE CD_Step_Model_Recovering(model, dt, converged, stalled, n_iter, ErrSt END BLOCK END SUBROUTINE CD_Step_Model_Recovering + LOGICAL FUNCTION model_lengths_committed(model) RESULT(same) + !! The unstretched lengths and rates are those the committed state was reached with (bit + !! for bit). A model without the committed copies counts as committed. + TYPE(CD_ModelType), INTENT(IN) :: model + INTEGER :: e + same = .TRUE. + IF (.NOT. (ALLOCATED(model%l0_c) .AND. ALLOCATED(model%l0_dot_c))) RETURN + DO e = 1, SIZE(model%l0) + IF (.NOT. (bits_equal(model%l0(e), model%l0_c(e)) .AND. bits_equal(model%l0_dot(e), model%l0_dot_c(e)))) THEN + same = .FALSE. + RETURN + END IF + END DO + END FUNCTION model_lengths_committed + + ELEMENTAL LOGICAL FUNCTION bits_equal(x, y) RESULT(same) + !! Bitwise equality of two reals (so +0 and -0 differ). + REAL(wp), INTENT(IN) :: x, y + same = TRANSFER(x, 0_INT64) == TRANSFER(y, 0_INT64) + END FUNCTION bits_equal + + ELEMENTAL REAL(wp) FUNCTION positive_zero(x) RESULT(y) + !! x with a negative zero replaced by +0, on the bits (so no floating-point mode can keep + !! the sign); every other value is returned unchanged. + REAL(wp), INTENT(IN) :: x + INTEGER(INT64) :: bits + bits = TRANSFER(x, 0_INT64) + IF (bits == -HUGE(0_INT64) - 1_INT64) bits = 0_INT64 + y = TRANSFER(bits, y) + END FUNCTION positive_zero + + SUBROUTINE enter_committed_lengths(model, aside, loads, ErrStat, ErrMsg) + !! Install the lengths and rates the committed state was reached with (l0_c, l0_dot_c) for + !! an evaluation of the committed state, setting the present ones aside; + !! leave_committed_lengths moves them back bit for bit. With loads, the external load and + !! the seabed coefficients that follow the lengths (the distributed load, and the seabed + !! stiffness and damping of a model that recomputes them) are rebuilt at l0_c as well, with + !! the helpers and in the order CD_Update_Model_SegmentLength uses, so they are those of the + !! committed lengths; they are rebuilt only when a length differs (a rate change alone + !! leaves them as they are). A model whose lengths and rates are the committed ones is left + !! as it is. On failure nothing is written. + TYPE(CD_ModelType), INTENT(INOUT) :: model + TYPE(model_lengths_aside), INTENT(INOUT) :: aside + LOGICAL, INTENT(IN) :: loads + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), ALLOCATABLE :: f_c(:), kn_c(:) + LOGICAL :: rebuild + INTEGER :: es + CHARACTER(160) :: em + + ErrStat = CD_MODEL_OK + ErrMsg = '' + aside%active = .FALSE. + IF (.NOT. model%initialized) RETURN + IF (model_lengths_committed(model)) RETURN + rebuild = loads + IF (rebuild) rebuild = .NOT. ALL(bits_equal(model%l0, model%l0_c)) + IF (rebuild .AND. ALLOCATED(model%dist_load)) THEN + ALLOCATE (f_c(SIZE(model%f_ext)), STAT=es) + IF (es /= 0) THEN + ErrStat = CD_MODEL_ALLOCFAIL + ErrMsg = 'committed lengths: external-load workspace allocation failed' + RETURN + END IF + CALL CD_Assemble_Distributed_Load(model%elem_conn, model%l0_c, model%dist_load, f_c, es, em) + IF (es /= 0) THEN + CALL fail(ErrStat, ErrMsg, 'committed lengths: distributed-load assembly failed: '//TRIM(em)) + RETURN + END IF + f_c = model%f_ext_dist_base + f_c + END IF + IF (rebuild .AND. model%has_seabed .AND. model%has_seabed_recompute) THEN + CALL CD_Nodal_Seabed_Stiffness(model%seabed_kbot, model%seabed_diameter_elem, model%l0_c, kn_c, es, em) + IF (es /= 0) THEN + CALL fail(ErrStat, ErrMsg, 'committed lengths: seabed stiffness recompute failed: '//TRIM(em)) + RETURN + END IF + END IF + aside%l0 = model%l0 + aside%l0_dot = model%l0_dot + model%l0 = model%l0_c + model%l0_dot = model%l0_dot_c + IF (ALLOCATED(f_c)) THEN + CALL MOVE_ALLOC(model%f_ext, aside%f_ext) + CALL MOVE_ALLOC(f_c, model%f_ext) + END IF + IF (ALLOCATED(kn_c)) THEN + CALL MOVE_ALLOC(model%seabed_kn, aside%kn) + CALL MOVE_ALLOC(kn_c, model%seabed_kn) + IF (ALLOCATED(model%seabed_cn)) THEN + CALL MOVE_ALLOC(model%seabed_cn, aside%cn) + model%seabed_cn = model%seabed_kn*model%seabed_cn_over_kn + END IF + END IF + aside%active = .TRUE. + END SUBROUTINE enter_committed_lengths + + SUBROUTINE leave_committed_lengths(model, aside) + !! Move back what enter_committed_lengths set aside. + TYPE(CD_ModelType), INTENT(INOUT) :: model + TYPE(model_lengths_aside), INTENT(INOUT) :: aside + IF (.NOT. aside%active) RETURN + model%l0 = aside%l0 + model%l0_dot = aside%l0_dot + IF (ALLOCATED(aside%f_ext)) CALL MOVE_ALLOC(aside%f_ext, model%f_ext) + IF (ALLOCATED(aside%kn)) CALL MOVE_ALLOC(aside%kn, model%seabed_kn) + IF (ALLOCATED(aside%cn)) CALL MOVE_ALLOC(aside%cn, model%seabed_cn) + aside%active = .FALSE. + END SUBROUTINE leave_committed_lengths + SUBROUTINE save_recovery_state(model) !! Save the committed state into the recovery snapshot (commit_state_copy). TYPE(CD_ModelType), INTENT(INOUT) :: model CALL commit_state_copy(model, .FALSE., model%recovery_q0, model%recovery_v0, model%recovery_a0, & model%recovery_ve_dl_1, model%recovery_syrope_slow, model%recovery_syrope_tmax, & - model%recovery_fr_anchor) + model%recovery_fr_anchor, model%recovery_l0_c, model%recovery_l0_dot_c) END SUBROUTINE save_recovery_state SUBROUTINE restore_recovery_state(model) @@ -2892,7 +3271,7 @@ SUBROUTINE restore_recovery_state(model) TYPE(CD_ModelType), INTENT(INOUT) :: model CALL commit_state_copy(model, .TRUE., model%recovery_q0, model%recovery_v0, model%recovery_a0, & model%recovery_ve_dl_1, model%recovery_syrope_slow, model%recovery_syrope_tmax, & - model%recovery_fr_anchor) + model%recovery_fr_anchor, model%recovery_l0_c, model%recovery_l0_dot_c) model%ve_dt = CD_ZERO END SUBROUTINE restore_recovery_state @@ -4049,7 +4428,7 @@ SUBROUTINE CD_Calc_Model_CoupledEndMass(model, m_cc, ErrStat, ErrMsg) END DO END SUBROUTINE CD_Calc_Model_CoupledEndMass - SUBROUTINE CD_Update_Model_SegmentLength(model, elem, l0_new, l0_dot, ErrStat, ErrMsg) + SUBROUTINE CD_Update_Model_SegmentLength(model, elem, l0_new, l0_dot, ErrStat, ErrMsg, restored) !! Active line control (the MoorDyn CtrlChan mechanism): set one element's !! unstretched length and its rate. The elastic tension and the per-step mass !! assembly read model%l0 directly, so the dynamics track the new length from @@ -4058,15 +4437,27 @@ SUBROUTINE CD_Update_Model_SegmentLength(model, elem, l0_new, l0_dot, ErrStat, E !! frozen at its init resolution (MoorDyn's convention -- BA derives from the !! INITIAL UnstrLen). Callers owning point bindings (the system) must recompute !! any end-node mass-diagonal shares after this call. + !! The committed state keeps its acceleration and the lengths it was reached with + !! (l0_c, l0_dot_c). With the force blend the next step (CD_Step_Model) evaluates its + !! step-start force at l0_c and l0_dot_c, its end-of-step force at the new lengths and + !! rates, and only its inertia at the blended lengths (1 - alpha_f) l0 + alpha_f l0_c; + !! under False alpha_force_blend it blends the lengths and rates into every alpha-level + !! term. restored = .TRUE. (a checkpoint restart re-applying the command of + !! the committed state) makes the new length and rate the committed ones as well. A rate + !! of -0 is stored as +0, so a zero command of either sign leaves an uncontrolled model + !! bit-identical (the committed-length test compares bits). TYPE(CD_ModelType), INTENT(INOUT) :: model INTEGER, INTENT(IN) :: elem REAL(wp), INTENT(IN) :: l0_new, l0_dot INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg + LOGICAL, INTENT(IN), OPTIONAL :: restored INTEGER :: es + REAL(wp) :: rate CHARACTER(160) :: em ErrStat = CD_MODEL_OK ErrMsg = '' + rate = positive_zero(l0_dot) IF (.NOT. model%initialized) THEN ErrStat = CD_MODEL_NOT_INITIALIZED ErrMsg = 'CableDyn_Model: model is not initialized' @@ -4107,11 +4498,10 @@ SUBROUTINE CD_Update_Model_SegmentLength(model, elem, l0_new, l0_dot, ErrStat, E END IF ! The update is atomic: every length-dependent quantity is built from a trial ! length vector first, and the committed fields are mutated only once all builds - ! succeeded. A failed acceleration recompute restores the entry state whole. + ! succeeded. BLOCK - REAL(wp) :: l0_trial(SIZE(model%l0)), f_dist(SIZE(model%f_ext)), f_ext_entry(SIZE(model%f_ext)) - REAL(wp) :: l0_entry, l0_dot_entry - REAL(wp), ALLOCATABLE :: kn_new(:), kn_entry(:), cn_entry(:) + REAL(wp) :: l0_trial(SIZE(model%l0)), f_dist(SIZE(model%f_ext)) + REAL(wp), ALLOCATABLE :: kn_new(:) l0_trial = model%l0 l0_trial(elem) = l0_new ! Distributed external load tracks the length: REASSEMBLE the distributed part @@ -4124,6 +4514,12 @@ SUBROUTINE CD_Update_Model_SegmentLength(model, elem, l0_new, l0_dot, ErrStat, E CALL fail(ErrStat, ErrMsg, 'segment-length update: distributed-load reassembly failed: '//TRIM(em)) RETURN END IF + ! the external load the new length gives must be finite (an overflowing length + ! fails here, before anything is written) + IF (.NOT. CD_All_Finite(model%f_ext_dist_base + f_dist)) THEN + CALL fail(ErrStat, ErrMsg, 'segment-length update: the external load at the new length is not finite') + RETURN + END IF END IF ! Seabed nodal coefficients track the tributary lengths: rebuild through the ! SAME helper the deck used, so a fresh build at the new length matches @@ -4135,44 +4531,86 @@ SUBROUTINE CD_Update_Model_SegmentLength(model, elem, l0_new, l0_dot, ErrStat, E CALL fail(ErrStat, ErrMsg, 'segment-length update: seabed stiffness recompute failed: '//TRIM(em)) RETURN END IF + IF (.NOT. CD_All_Finite(kn_new*model%seabed_cn_over_kn)) THEN + CALL fail(ErrStat, ErrMsg, 'segment-length update: the seabed coefficients at the new length are not finite') + RETURN + END IF END IF ! Commit. The consistent mass follows l0 implicitly (it is applied element by - ! element from the committed lengths, and the step rebuilds its mass band when they change). - l0_entry = model%l0(elem) - l0_dot_entry = model%l0_dot(elem) - f_ext_entry = model%f_ext + ! element from the present lengths, and the step rebuilds its mass band when they change). model%l0(elem) = l0_new - model%l0_dot(elem) = l0_dot + model%l0_dot(elem) = rate IF (ALLOCATED(model%dist_load)) model%f_ext = model%f_ext_dist_base + f_dist IF (model%has_seabed .AND. model%has_seabed_recompute) THEN - CALL MOVE_ALLOC(model%seabed_kn, kn_entry) CALL MOVE_ALLOC(kn_new, model%seabed_kn) - IF (ALLOCATED(model%seabed_cn)) THEN - cn_entry = model%seabed_cn - model%seabed_cn = model%seabed_kn*model%seabed_cn_over_kn - END IF - END IF - ! The committed acceleration satisfied the OLD length's equation of motion; - ! recompute it at the current q/v under the new length so the model is - ! indistinguishable from one built with it (load exchanges and the next - ! gen-alpha step start from a consistent state). A FULLY COUPLED model (no - ! free DOFs -- every line in a point-connected system) carries only - ! caller-prescribed accelerations, so there is nothing to recompute. - IF (SIZE(model%fixed_dofs) < model%n_dof) THEN - CALL CD_Recompute_Model_Acceleration(model, es, em) - IF (es /= CD_MODEL_OK) THEN - ! The recompute restored the acceleration; restore every other field. - model%l0(elem) = l0_entry - model%l0_dot(elem) = l0_dot_entry - model%f_ext = f_ext_entry - IF (ALLOCATED(kn_entry)) CALL MOVE_ALLOC(kn_entry, model%seabed_kn) - IF (ALLOCATED(cn_entry)) model%seabed_cn = cn_entry - CALL fail(ErrStat, ErrMsg, 'segment-length update: acceleration recompute failed: '//TRIM(em)) + IF (ALLOCATED(model%seabed_cn)) model%seabed_cn = model%seabed_kn*model%seabed_cn_over_kn + END IF + ! The committed acceleration is kept: it is the history of the step that reached the + ! committed state, at the lengths of that step (re-deriving it under the new length + ! would carry the force of the length change into the next step's alpha_m blend). + IF (PRESENT(restored)) THEN + IF (restored) THEN + model%l0_c(elem) = l0_new + model%l0_dot_c(elem) = rate END IF END IF END BLOCK END SUBROUTINE CD_Update_Model_SegmentLength + SUBROUTINE CD_Save_Model_Control(model, saved) + !! Save what CD_Update_Model_SegmentLength writes (the lengths and rates, the committed + !! lengths and rates, the external load and the seabed coefficients), so that a caller + !! applying one command to several lines can take back the ones it already changed when + !! a later one fails (CD_Restore_Model_Control). + TYPE(CD_ModelType), INTENT(IN) :: model + TYPE(CD_ModelControlSaveType), INTENT(INOUT) :: saved + saved%valid = model%initialized + IF (.NOT. saved%valid) RETURN + saved%l0 = model%l0 + saved%l0_dot = model%l0_dot + saved%l0_c = model%l0_c + saved%l0_dot_c = model%l0_dot_c + saved%f_ext = model%f_ext + IF (ALLOCATED(model%seabed_kn)) THEN + saved%seabed_kn = model%seabed_kn + ELSE IF (ALLOCATED(saved%seabed_kn)) THEN + DEALLOCATE (saved%seabed_kn) + END IF + IF (ALLOCATED(model%seabed_cn)) THEN + saved%seabed_cn = model%seabed_cn + ELSE IF (ALLOCATED(saved%seabed_cn)) THEN + DEALLOCATE (saved%seabed_cn) + END IF + END SUBROUTINE CD_Save_Model_Control + + SUBROUTINE CD_Restore_Model_Control(model, saved, ErrStat, ErrMsg) + !! Put back, bit for bit, what CD_Save_Model_Control saved. Fails closed, writing nothing, + !! when the save does not belong to the model. + TYPE(CD_ModelType), INTENT(INOUT) :: model + TYPE(CD_ModelControlSaveType), INTENT(IN) :: saved + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + ErrStat = CD_MODEL_OK + ErrMsg = '' + IF (.NOT. (model%initialized .AND. saved%valid)) THEN + CALL fail(ErrStat, ErrMsg, 'control restore: no saved control state') + RETURN + END IF + IF (SIZE(saved%l0) /= SIZE(model%l0) .OR. SIZE(saved%f_ext) /= SIZE(model%f_ext) .OR. & + (ALLOCATED(saved%seabed_kn) .NEQV. ALLOCATED(model%seabed_kn)) .OR. & + (ALLOCATED(saved%seabed_cn) .NEQV. ALLOCATED(model%seabed_cn))) THEN + CALL fail(ErrStat, ErrMsg, 'control restore: the saved state belongs to another model') + RETURN + END IF + model%l0 = saved%l0 + model%l0_dot = saved%l0_dot + model%l0_c = saved%l0_c + model%l0_dot_c = saved%l0_dot_c + model%f_ext = saved%f_ext + IF (ALLOCATED(saved%seabed_kn)) model%seabed_kn = saved%seabed_kn + IF (ALLOCATED(saved%seabed_cn)) model%seabed_cn = saved%seabed_cn + END SUBROUTINE CD_Restore_Model_Control + SUBROUTINE CD_Get_Model_EndNodeMassDiag(model, coupled_slot, mass_diag, ErrStat, ErrMsg) !! The coupled end node's OWN diagonal share of the consistent structural mass: !! sum over elements attached to that node of rho_a*l0/3 (the 2m/6 block diagonal @@ -4892,35 +5330,37 @@ SUBROUTINE CD_Update_Model_External_Loads(model, f_ext, ErrStat, ErrMsg) CALL fail(ErrStat, ErrMsg, 'external-load update requires initialized rollback workspace') RETURN END IF - model%f_ext_rollback = model%f_ext - model%a_rollback = model%a - model%f_ext = f_ext - CALL CD_Recompute_Model_Acceleration(model, ErrStat, ErrMsg) - IF (ErrStat /= CD_MODEL_OK) THEN - model%f_ext = model%f_ext_rollback - model%a = model%a_rollback - RETURN - END IF - ! Maintain the distributed-load invariant f_ext = remainder + assemble(dist, l0): - ! a later segment-length update RECONSTRUCTS f_ext from the remainder, so a - ! runtime external-load update that skipped this would be silently WIPED by the - ! next control command. Recomputed only on success (the rollback path above - ! restores the committed pair untouched). - IF (ALLOCATED(model%dist_load)) THEN - BLOCK - REAL(wp) :: f_dist(SIZE(model%f_ext)) - INTEGER :: es2 - CHARACTER(160) :: em2 + ! Maintain the distributed-load invariant f_ext = remainder + assemble(dist, l0): a later + ! segment-length update RECONSTRUCTS f_ext from the remainder, so a runtime external-load + ! update that skipped this would be silently WIPED by the next control command. The + ! remainder is stored BEFORE the acceleration recompute, which under the force blend after + ! a pending length change rebuilds the committed external load from it + ! (enter_committed_lengths); a failed recompute restores f_ext, the remainder and a. + BLOCK + REAL(wp) :: f_dist(SIZE(model%f_ext)) + REAL(wp), ALLOCATABLE :: base_entry(:) + INTEGER :: es2 + CHARACTER(160) :: em2 + IF (ALLOCATED(model%dist_load)) THEN CALL CD_Assemble_Distributed_Load(model%elem_conn, model%l0, model%dist_load, f_dist, es2, em2) IF (es2 /= 0) THEN - model%f_ext = model%f_ext_rollback - model%a = model%a_rollback CALL fail(ErrStat, ErrMsg, 'external-load update: distributed-load remainder failed: '//TRIM(em2)) RETURN END IF - model%f_ext_dist_base = model%f_ext - f_dist - END BLOCK - END IF + base_entry = model%f_ext_dist_base + END IF + model%f_ext_rollback = model%f_ext + model%a_rollback = model%a + model%f_ext = f_ext + IF (ALLOCATED(model%dist_load)) model%f_ext_dist_base = model%f_ext - f_dist + CALL CD_Recompute_Model_Acceleration(model, ErrStat, ErrMsg) + IF (ErrStat /= CD_MODEL_OK) THEN + model%f_ext = model%f_ext_rollback + model%a = model%a_rollback + IF (ALLOCATED(base_entry)) model%f_ext_dist_base = base_entry + RETURN + END IF + END BLOCK END SUBROUTINE CD_Update_Model_External_Loads SUBROUTINE CD_Update_Model_CoupledMotion(model, q_coupled, v_coupled, a_coupled, ErrStat, ErrMsg) @@ -5018,6 +5458,32 @@ SUBROUTINE CD_Recompute_Model_Acceleration(model, ErrStat, ErrMsg) !! external loads, environmental loads, added mass, and fixed/coupled DOF map. !! Use this after runtime updates when the caller needs a consistent !! acceleration before a load exchange or diagnostic query. + !! Under active line control the acceleration is the committed state's: between a length + !! change (CD_Update_Model_SegmentLength) and the next step it is solved with the lengths + !! and rates that state was reached with (l0_c, l0_dot_c), which stay the committed ones, + !! so the step still treats the old and new lengths as it should. The state is evaluated as + !! the step evaluates its committed side: with the force blend (the step-start force r_n) + !! the external load and the seabed coefficients that follow the lengths are rebuilt at + !! the committed lengths too (enter_committed_lengths); under False alpha_force_blend, as + !! in that step's blend, only the element lengths and rates take the committed values and + !! the external load and the seabed coefficients are the present ones. The present values + !! are put back bit for bit on every exit. + TYPE(CD_ModelType), INTENT(INOUT) :: model + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + TYPE(model_lengths_aside) :: aside + + CALL enter_committed_lengths(model, aside, model%cfg%force_blend, ErrStat, ErrMsg) + IF (ErrStat /= CD_MODEL_OK) THEN + ErrMsg = 'CableDyn_Model: acceleration recompute: '//TRIM(ErrMsg) + RETURN + END IF + CALL recompute_model_acceleration_now(model, ErrStat, ErrMsg) + CALL leave_committed_lengths(model, aside) + END SUBROUTINE CD_Recompute_Model_Acceleration + + SUBROUTINE recompute_model_acceleration_now(model, ErrStat, ErrMsg) + !! CD_Recompute_Model_Acceleration with the lengths and rates in place. TYPE(CD_ModelType), INTENT(INOUT) :: model INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg @@ -5289,7 +5755,7 @@ SUBROUTINE model_added_mass_band(q, accel, free, kl, ku, M_add_a, M_add_band, dM ErrStat, ErrMsg, need_tangent=need_tangent) ErrStat = as_dyn_callback_status(ErrStat) END SUBROUTINE model_added_mass_band - END SUBROUTINE CD_Recompute_Model_Acceleration + END SUBROUTINE recompute_model_acceleration_now SUBROUTINE CD_Audit_Model_Step(model, time, dt, new_spike) !! Audit one committed host step of an EI=0 line (called by the standalone driver on the @@ -5484,6 +5950,12 @@ SUBROUTINE CD_End_Model(model, ErrStat, ErrMsg) IF (ALLOCATED(model%rho_a)) DEALLOCATE (model%rho_a) IF (ALLOCATED(model%f_ext)) DEALLOCATE (model%f_ext) IF (ALLOCATED(model%l0_dot)) DEALLOCATE (model%l0_dot) + IF (ALLOCATED(model%l0_c)) DEALLOCATE (model%l0_c) + IF (ALLOCATED(model%l0_dot_c)) DEALLOCATE (model%l0_dot_c) + IF (ALLOCATED(model%l0_c_rollback)) DEALLOCATE (model%l0_c_rollback) + IF (ALLOCATED(model%l0_dot_c_rollback)) DEALLOCATE (model%l0_dot_c_rollback) + IF (ALLOCATED(model%recovery_l0_c)) DEALLOCATE (model%recovery_l0_c) + IF (ALLOCATED(model%recovery_l0_dot_c)) DEALLOCATE (model%recovery_l0_dot_c) IF (ALLOCATED(model%dist_load)) DEALLOCATE (model%dist_load) IF (ALLOCATED(model%f_ext_dist_base)) DEALLOCATE (model%f_ext_dist_base) IF (ALLOCATED(model%seabed_diameter_elem)) DEALLOCATE (model%seabed_diameter_elem) @@ -5508,6 +5980,7 @@ SUBROUTINE CD_End_Model(model, ErrStat, ErrMsg) IF (ALLOCATED(model%recovery_q0)) DEALLOCATE (model%recovery_q0) model%sub_slot(1) = CD_ModelCommitSlot() model%sub_slot(2) = CD_ModelCommitSlot() + model%sub_target = CD_ModelControlSaveType() IF (ALLOCATED(model%sub_t0)) DEALLOCATE (model%sub_t0) IF (ALLOCATED(model%sub_t1)) DEALLOCATE (model%sub_t1) IF (ALLOCATED(model%sub_pq)) DEALLOCATE (model%sub_pq) @@ -5681,6 +6154,18 @@ SUBROUTINE CD_Copy_Model(src, dst, ErrStat, ErrMsg) IF (ErrStat /= CD_MODEL_OK) RETURN CALL copy_real1(src%l0_dot, work%l0_dot, 'l0_dot', ErrStat, ErrMsg) IF (ErrStat /= CD_MODEL_OK) RETURN + CALL copy_real1(src%l0_c, work%l0_c, 'l0_c', ErrStat, ErrMsg) + IF (ErrStat /= CD_MODEL_OK) RETURN + CALL copy_real1(src%l0_dot_c, work%l0_dot_c, 'l0_dot_c', ErrStat, ErrMsg) + IF (ErrStat /= CD_MODEL_OK) RETURN + CALL copy_real1(src%l0_c_rollback, work%l0_c_rollback, 'l0_c_rollback', ErrStat, ErrMsg) + IF (ErrStat /= CD_MODEL_OK) RETURN + CALL copy_real1(src%l0_dot_c_rollback, work%l0_dot_c_rollback, 'l0_dot_c_rollback', ErrStat, ErrMsg) + IF (ErrStat /= CD_MODEL_OK) RETURN + CALL copy_real1(src%recovery_l0_c, work%recovery_l0_c, 'recovery_l0_c', ErrStat, ErrMsg) + IF (ErrStat /= CD_MODEL_OK) RETURN + CALL copy_real1(src%recovery_l0_dot_c, work%recovery_l0_dot_c, 'recovery_l0_dot_c', ErrStat, ErrMsg) + IF (ErrStat /= CD_MODEL_OK) RETURN CALL copy_real2(src%dist_load, work%dist_load, 'dist_load', ErrStat, ErrMsg) IF (ErrStat /= CD_MODEL_OK) RETURN CALL copy_real1(src%f_ext_dist_base, work%f_ext_dist_base, 'f_ext_dist_base', ErrStat, ErrMsg) @@ -5889,6 +6374,12 @@ SUBROUTINE commit_model_copy(from, to) CALL MOVE_ALLOC(from%ea, to%ea) CALL MOVE_ALLOC(from%rho_a, to%rho_a) CALL MOVE_ALLOC(from%l0_dot, to%l0_dot) + CALL MOVE_ALLOC(from%l0_c, to%l0_c) + CALL MOVE_ALLOC(from%l0_dot_c, to%l0_dot_c) + CALL MOVE_ALLOC(from%l0_c_rollback, to%l0_c_rollback) + CALL MOVE_ALLOC(from%l0_dot_c_rollback, to%l0_dot_c_rollback) + CALL MOVE_ALLOC(from%recovery_l0_c, to%recovery_l0_c) + CALL MOVE_ALLOC(from%recovery_l0_dot_c, to%recovery_l0_dot_c) CALL MOVE_ALLOC(from%dist_load, to%dist_load) CALL MOVE_ALLOC(from%f_ext_dist_base, to%f_ext_dist_base) CALL MOVE_ALLOC(from%f_ext, to%f_ext) @@ -7628,7 +8119,9 @@ SUBROUTINE model_added_mass_full(model, q, accel, M_add, dMa_a_dq, ErrStat, ErrM END SUBROUTINE model_added_mass_full SUBROUTINE model_added_mass_banded(model, q, accel, free, kl, ku, M_add_a, M_add_band, dMa_a_dq_band, & - ErrStat, ErrMsg, need_tangent) + ErrStat, ErrMsg, need_tangent, l0_elem) + !! l0_elem (n_elem, finite and positive): the element lengths to use instead of model%l0 + !! (the blended lengths of a step after a length change). TYPE(CD_ModelType), INTENT(INOUT) :: model REAL(wp), INTENT(IN) :: q(:), accel(:) INTEGER, INTENT(IN) :: free(:), kl, ku @@ -7636,9 +8129,10 @@ SUBROUTINE model_added_mass_banded(model, q, accel, free, kl, ku, M_add_a, M_add INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg LOGICAL, INTENT(IN), OPTIONAL :: need_tangent + REAL(wp), INTENT(IN), OPTIONAL :: l0_elem(:) INTEGER :: e, i, n, ldab, idx(6) - REAL(wp) :: q2(6), a2(6), wl2(2), m2(6, 6), dm2(6, 6), ma2(6) + REAL(wp) :: q2(6), a2(6), wl2(2), m2(6, 6), dm2(6, 6), ma2(6), le LOGICAL :: want_tangent, zero_accel, free_map_ready ErrStat = CD_MODEL_OK @@ -7673,6 +8167,16 @@ SUBROUTINE model_added_mass_banded(model, q, accel, free, kl, ku, M_add_a, M_add CALL fail(ErrStat, ErrMsg, 'banded added mass q/accel must be finite') RETURN END IF + IF (PRESENT(l0_elem)) THEN + IF (SIZE(l0_elem) /= model%n_elem) THEN + CALL fail(ErrStat, ErrMsg, 'banded added mass lengths must have shape (n_elem)') + RETURN + END IF + IF (.NOT. CD_All_Finite(l0_elem) .OR. ANY(l0_elem <= CD_ZERO)) THEN + CALL fail(ErrStat, ErrMsg, 'banded added mass lengths must be finite and positive') + RETURN + END IF + END IF IF (want_tangent) THEN model%free_map_work(1:n) = 0 @@ -7693,16 +8197,18 @@ SUBROUTINE model_added_mass_banded(model, q, accel, free, kl, ku, M_add_a, M_add DO e = 1, model%n_elem CALL extract_element_state(model, e, q, accel, idx, q2, a2) CALL extract_nodal_scalar(model%added_mass_waterline_z, model, e, wl2) + le = model%l0(e) + IF (PRESENT(l0_elem)) le = l0_elem(e) IF (want_tangent) THEN IF (zero_accel) THEN - CALL CD_Added_Mass_Element_Matrix(q2(1:3), q2(4:6), model%l0(e), wl2(1), wl2(2), & + CALL CD_Added_Mass_Element_Matrix(q2(1:3), q2(4:6), le, wl2(1), wl2(2), & model%added_mass_rho, model%added_mass_diameter_elem(e), & model%added_mass_can_elem(e), model%added_mass_cat_elem(e), & m2, ErrStat, ErrMsg, inputs_validated=.TRUE.) IF (ErrStat /= 0) RETURN ma2 = CD_ZERO ELSE - CALL CD_Added_Mass_Element(q2(1:3), q2(4:6), a2(1:3), a2(4:6), model%l0(e), wl2(1), wl2(2), & + CALL CD_Added_Mass_Element(q2(1:3), q2(4:6), a2(1:3), a2(4:6), le, wl2(1), wl2(2), & model%added_mass_rho, model%added_mass_diameter_elem(e), & model%added_mass_can_elem(e), model%added_mass_cat_elem(e), & m2, dm2, ErrStat, ErrMsg, inputs_validated=.TRUE.) @@ -7710,7 +8216,7 @@ SUBROUTINE model_added_mass_banded(model, q, accel, free, kl, ku, M_add_a, M_add ma2 = MATMUL(m2, a2) END IF ELSE - CALL CD_Added_Mass_Element_Force(q2(1:3), q2(4:6), a2(1:3), a2(4:6), model%l0(e), wl2(1), wl2(2), & + CALL CD_Added_Mass_Element_Force(q2(1:3), q2(4:6), a2(1:3), a2(4:6), le, wl2(1), wl2(2), & model%added_mass_rho, model%added_mass_diameter_elem(e), & model%added_mass_can_elem(e), model%added_mass_cat_elem(e), & ma2, ErrStat, ErrMsg, inputs_validated=.TRUE.) diff --git a/src/CableDyn_OpenFAST_Aggregate.f90 b/src/CableDyn_OpenFAST_Aggregate.f90 index 2abb1d4f..1b06e130 100644 --- a/src/CableDyn_OpenFAST_Aggregate.f90 +++ b/src/CableDyn_OpenFAST_Aggregate.f90 @@ -53,8 +53,12 @@ MODULE CableDyn_OpenFAST_Aggregate CD_HFMF_SetCoupledKinematics, CD_HFMF_GetCoupledKinematics, & CD_HFMF_End, CD_HFMF_OK, CD_HFMF_BADINPUT, & CD_HFMF_Snapshot, CD_HFMF_Restore, & - CD_HFMF_Set_Held_Fluid, CD_HFMF_NNodes, CD_HFMF_GetNodePositions - USE CableDyn_HermiteCableDynamic, ONLY: CD_HermiteCable_Dyn_Profile_Enabled + CD_HFMF_Set_Held_Fluid, CD_HFMF_NNodes, CD_HFMF_GetNodePositions, & + CD_HFMF_Set_SegmentLength + USE CableDyn_HermiteCableDynamic, ONLY: CD_HermiteCable_Dyn_Profile_Enabled, CD_HermiteCableControlSaveType, & + CD_HermiteCable_Dyn_Save_Control, CD_HermiteCable_Dyn_Restore_Control, & + CD_HCDYN_OK + USE CableDyn_Model, ONLY: CD_ModelControlSaveType USE CableDyn_DeckDriver, ONLY: CD_DeckAggregateType, CD_Init_Deck_Aggregate, CD_End_Deck_Aggregate, & CD_DECKDRV_OK, CD_DECKDRV_BADINPUT, CD_Eval_Aggregate_Channel, & CD_Cable_Deck_Node, & @@ -78,7 +82,8 @@ MODULE CableDyn_OpenFAST_Aggregate USE CableDyn_RangeOutput, ONLY: CD_RangeSet, CD_Range_End USE CableDyn_System, ONLY: CD_Get_System_Substep_Counts, CD_System_NLines, CD_System_Line_NDOF, & CD_Get_System_Line_State, & - CD_Update_System_Line_SegmentLength, & + CD_Update_System_Line_SegmentLength, CD_Save_System_Line_Control, & + CD_Restore_System_Line_Control, & CD_Update_System_Line_Hydro_Fields, CD_SYSTEM_OK, & CD_System_NHydroPoints, CD_Get_System_HydroPoint_Positions, & CD_Set_System_HydroPoint_Fluid @@ -190,13 +195,23 @@ MODULE CableDyn_OpenFAST_Aggregate TYPE(DeckLine), ALLOCATABLE :: fail_lines(:) TYPE(DeckPoint), ALLOCATABLE :: fail_points(:) TYPE(DeckFailure), ALLOCATABLE :: snap_failures(:) - ! Active line control (CONTROL section): flattened channel -> (line, last - ! element, base length) table; ctrl_warned suppresses the MoorDyn bound - ! warnings after the first exceedance per row. + ! Active line control (CONTROL section): flattened channel -> (line, controlled + ! element, base length) table. The controlled segment is the deck segment at the line's + ! fairlead-side end (see CD_DeckAggregateType). A finite-EI row (ctrl_is_cable) holds + ! the cable index, the first of the ctrl_nelem cable elements of that segment and its + ! base length S; their base lengths sit at ctrl_span_l0(ctrl_span_off + 1:). INTEGER :: n_ctrl_chans = 0 - INTEGER, ALLOCATABLE :: ctrl_chan(:), ctrl_line(:), ctrl_elem(:) + INTEGER, ALLOCATABLE :: ctrl_chan(:), ctrl_line(:), ctrl_elem(:), ctrl_nelem(:) REAL(wp), ALLOCATABLE :: ctrl_base_l0(:) - LOGICAL, ALLOCATABLE :: ctrl_warned(:) + ! the deck line's unstretched length and segment count, MoorDyn-F's UnstrLen and N + REAL(wp), ALLOCATABLE :: ctrl_unstr_len(:) + INTEGER, ALLOCATABLE :: ctrl_nsegs(:) + ! per row, the object it changes as it was before the change (CD_AGG_Apply_LineControl) + TYPE(CD_HermiteCableControlSaveType), ALLOCATABLE :: ctrl_cable_saved(:) + TYPE(CD_ModelControlSaveType), ALLOCATABLE :: ctrl_line_saved(:) + LOGICAL, ALLOCATABLE :: ctrl_is_cable(:) + INTEGER, ALLOCATABLE :: ctrl_line_id(:), ctrl_span_off(:) + REAL(wp), ALLOCATABLE :: ctrl_span_l0(:) ! Coupled Rigid6 bodies (pure EI=0 deck): the opaque runtime the facade marches over the ! EI=0 system each mooring step, in place of the plain moving step. has_rigid6 selects the ! body-march branch; the runtime's own snapshot buffer joins the aggregate snapshot/restore. @@ -345,9 +360,14 @@ SUBROUTINE CD_AGG_Init_From_Deck(self, deck_path, dt, ErrStat, ErrMsg, env_gravi CALL MOVE_ALLOC(parts%ctrl_chan, candidate%ctrl_chan) CALL MOVE_ALLOC(parts%ctrl_line, candidate%ctrl_line) CALL MOVE_ALLOC(parts%ctrl_elem, candidate%ctrl_elem) + CALL MOVE_ALLOC(parts%ctrl_nelem, candidate%ctrl_nelem) CALL MOVE_ALLOC(parts%ctrl_base_l0, candidate%ctrl_base_l0) - ALLOCATE (candidate%ctrl_warned(SIZE(candidate%ctrl_chan))) - candidate%ctrl_warned = .FALSE. + CALL MOVE_ALLOC(parts%ctrl_unstr_len, candidate%ctrl_unstr_len) + CALL MOVE_ALLOC(parts%ctrl_nsegs, candidate%ctrl_nsegs) + CALL MOVE_ALLOC(parts%ctrl_is_cable, candidate%ctrl_is_cable) + CALL MOVE_ALLOC(parts%ctrl_line_id, candidate%ctrl_line_id) + CALL MOVE_ALLOC(parts%ctrl_span_off, candidate%ctrl_span_off) + CALL MOVE_ALLOC(parts%ctrl_span_l0, candidate%ctrl_span_l0) END IF ! Coupled Rigid6 decks: take over the opaque body runtime (deep-copied by the intrinsic ! assignment; the deck bundle is released in CD_End_Deck_Aggregate below). @@ -1700,30 +1720,45 @@ INTEGER FUNCTION CD_AGG_NCtrlChans(self) RESULT(n) n = self%n_ctrl_chans END FUNCTION CD_AGG_NCtrlChans - SUBROUTINE CD_AGG_Apply_LineControl(self, delta_l, delta_l_dot, ErrStat, ErrMsg) - !! Apply the host's cable-control command BEFORE an advance: for every - !! controlled line, the LAST (fairlead-side) segment's unstretched length - !! becomes base + delta_l(chan) with rate delta_l_dot(chan) -- the MoorDyn - !! convention, applied unclamped with the MoorDyn warning bounds (an increase - !! beyond one base segment length or a reduction past half of it warns once - !! per row and proceeds). + SUBROUTINE CD_AGG_Apply_LineControl(self, delta_l, delta_l_dot, ErrStat, ErrMsg, restored) + !! Apply the host's cable-control command BEFORE an advance to the deck segment at the + !! fairlead-side end of each controlled line: the end on a host-driven point, else the + !! written NodeB (MoorDyn's AttachB, its segment N). On an EI = 0 line that element's + !! unstretched length becomes base + delta_l(chan) with rate delta_l_dot(chan) -- the + !! MoorDyn convention. On a finite-EI cable every cable element of that segment (base + !! length S) scales by (S + delta_l)/S, with rate delta_l_dot*l_e/S, so the segment takes + !! the same length and rate. + !! A command outside MoorDyn-F's bounds fails closed by channel and line, as MoorDyn-F + !! stops the run there (ErrID_Fatal): with UnstrLen and N the deck line's unstretched + !! length and segment count (summed over its sections), MoorDyn-F refuses + !! DeltaL > UnstrLen/N and DeltaL < -0.5*UnstrLen/N (MoorDyn.f90, the active-tension + !! bounds check), the same comparisons in the same precision, so a command MoorDyn-F + !! accepts is accepted here. On a uniform line UnstrLen/N is the controlled segment's + !! base length S. On a line of several sections the controlled segment can be shorter + !! than UnstrLen/N/2, so a command within the bounds can still make it non-positive; + !! that fails closed as well. + !! Every row is checked before any line changes, and the objects the loop already + !! changed are put back, bit for bit, if a later row fails after all (a capability the + !! initialisation could not verify, an allocation): a refused command writes nothing. + !! On both kinds the committed state keeps the lengths it was reached with until the + !! next advance commits the new ones. restored = .TRUE. is the checkpoint-restart + !! re-application of the command the committed state was reached with: the lengths + !! become the committed ones at once. TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: self REAL(wp), INTENT(IN) :: delta_l(:), delta_l_dot(:) INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg + LOGICAL, INTENT(IN), OPTIONAL :: restored - INTEGER :: c, ch, es + INTEGER :: c, ch, es, nspan, k, nrow + REAL(wp) :: lambda, mean_seg CHARACTER(512) :: em + CHARACTER(16) :: line_kind ErrStat = CD_AGG_OK ErrMsg = '' IF (.NOT. require_initialized(self, ErrStat, ErrMsg)) RETURN IF (.NOT. ALLOCATED(self%ctrl_chan)) RETURN - IF (.NOT. self%has_sys) THEN - ErrStat = CD_AGG_BADINPUT - ErrMsg = 'CableDyn_OpenFAST_Aggregate: line control requires the EI=0 system' - RETURN - END IF IF (SIZE(delta_l) < self%n_ctrl_chans .OR. SIZE(delta_l_dot) < self%n_ctrl_chans) THEN ErrStat = CD_AGG_BADINPUT ErrMsg = 'CableDyn_OpenFAST_Aggregate: the control command must cover every declared channel' @@ -1734,33 +1769,114 @@ SUBROUTINE CD_AGG_Apply_LineControl(self, delta_l, delta_l_dot, ErrStat, ErrMsg) ErrMsg = 'CableDyn_OpenFAST_Aggregate: the control command must be finite' RETURN END IF - ! PREVALIDATE every row before mutating any line: a bad later row must not - ! leave the aggregate at mixed lengths (the caller may treat BADINPUT as - ! recoverable). - DO c = 1, SIZE(self%ctrl_chan) - IF (delta_l(self%ctrl_chan(c)) <= -self%ctrl_base_l0(c)) THEN + nrow = SIZE(self%ctrl_chan) + ! PREVALIDATE every row before mutating any line + DO c = 1, nrow + ch = self%ctrl_chan(c) + IF (self%ctrl_is_cable(c)) THEN + line_kind = 'finite-EI' + IF (self%ctrl_line(c) < 1 .OR. self%ctrl_line(c) > self%ncable) THEN + ErrStat = CD_AGG_BADINPUT + ErrMsg = 'CableDyn_OpenFAST_Aggregate: line control addresses a cable the aggregate does not own' + RETURN + END IF + ELSE + line_kind = 'EI = 0' + IF (.NOT. self%has_sys) THEN + ErrStat = CD_AGG_BADINPUT + ErrMsg = 'CableDyn_OpenFAST_Aggregate: line control requires the EI=0 system' + RETURN + END IF + END IF + ! MoorDyn-F's bounds, written as MoorDyn-F evaluates them + mean_seg = self%ctrl_unstr_len(c)/REAL(self%ctrl_nsegs(c), wp) + IF (delta_l(ch) > self%ctrl_unstr_len(c)/REAL(self%ctrl_nsegs(c), wp) .OR. & + delta_l(ch) < -0.5_wp*self%ctrl_unstr_len(c)/REAL(self%ctrl_nsegs(c), wp)) THEN + ErrStat = CD_AGG_BADINPUT + WRITE (em, '(A,I0,A,ES12.5,A,I0,A,ES12.5,A)') 'CableDyn_OpenFAST_Aggregate: control channel ', ch, & + ' commands DeltaL = ', delta_l(ch), ' m on '//TRIM(line_kind)//' line ', self%ctrl_line_id(c), & + ', outside MoorDyn-F''s bounds -S/2 <= DeltaL <= S (S = UnstrLen/N = ', mean_seg, ' m)' + ErrMsg = TRIM(em) + RETURN + END IF + IF (.NOT. (self%ctrl_base_l0(c) + delta_l(ch) > CD_ZERO)) THEN ErrStat = CD_AGG_BADINPUT - ErrMsg = 'CableDyn_OpenFAST_Aggregate: DeltaL reduces a controlled segment to a non-positive length' + WRITE (em, '(A,I0,A,ES12.5,A,I0,A,ES12.5,A)') 'CableDyn_OpenFAST_Aggregate: control channel ', ch, & + ' commands DeltaL = ', delta_l(ch), ' m on '//TRIM(line_kind)//' line ', self%ctrl_line_id(c), & + ', which would make its controlled segment (', self%ctrl_base_l0(c), ' m long) non-positive' + ErrMsg = TRIM(em) RETURN END IF END DO - DO c = 1, SIZE(self%ctrl_chan) + ! The objects each row changes, as they are before its change (kept from step to step, + ! so the saves allocate once) + IF (ALLOCATED(self%ctrl_cable_saved)) THEN + IF (SIZE(self%ctrl_cable_saved) /= nrow) DEALLOCATE (self%ctrl_cable_saved, self%ctrl_line_saved) + END IF + IF (.NOT. ALLOCATED(self%ctrl_cable_saved)) ALLOCATE (self%ctrl_cable_saved(nrow), self%ctrl_line_saved(nrow)) + DO c = 1, nrow ch = self%ctrl_chan(c) - IF (.NOT. self%ctrl_warned(c)) THEN - IF (delta_l(ch) > self%ctrl_base_l0(c) .OR. delta_l(ch) < -0.5_wp*self%ctrl_base_l0(c)) THEN - WRITE (*, '(A,I0,A)') 'CableDyn: WARNING -- control channel ', ch, & - ' DeltaL exceeds the MoorDyn advisory bounds (+1/-0.5 segment lengths); applying unclamped' - self%ctrl_warned(c) = .TRUE. + IF (self%ctrl_is_cable(c)) THEN + CALL CD_HermiteCable_Dyn_Save_Control(self%cables(self%ctrl_line(c))%line, self%ctrl_cable_saved(c)) + nspan = self%ctrl_nelem(c) + BLOCK + INTEGER :: elems(nspan) + REAL(wp) :: l0_new(nspan), l0_rate(nspan), base + lambda = (self%ctrl_base_l0(c) + delta_l(ch))/self%ctrl_base_l0(c) + DO k = 1, nspan + base = self%ctrl_span_l0(self%ctrl_span_off(c) + k) + elems(k) = self%ctrl_elem(c) + k - 1 + l0_new(k) = base*lambda + l0_rate(k) = delta_l_dot(ch)*base/self%ctrl_base_l0(c) + END DO + CALL CD_HFMF_Set_SegmentLength(self%cables(self%ctrl_line(c)), elems, l0_new, l0_rate, es, em, & + restored=restored) + END BLOCK + IF (es /= CD_HFMF_OK) THEN + CALL take_back(c - 1, 'CableDyn_OpenFAST_Aggregate: line-control update failed: '//TRIM(em)) + RETURN + END IF + ELSE + CALL CD_Save_System_Line_Control(self%sys%fast%system, self%ctrl_line(c), self%ctrl_line_saved(c), es, em) + IF (es == CD_SYSTEM_OK) & + CALL CD_Update_System_Line_SegmentLength(self%sys%fast%system, self%ctrl_line(c), self%ctrl_elem(c), & + self%ctrl_base_l0(c) + delta_l(ch), delta_l_dot(ch), es, em, & + restored=restored) + IF (es /= CD_SYSTEM_OK) THEN + CALL take_back(c - 1, 'CableDyn_OpenFAST_Aggregate: line-control update failed: '//TRIM(em)) + RETURN END IF - END IF - CALL CD_Update_System_Line_SegmentLength(self%sys%fast%system, self%ctrl_line(c), self%ctrl_elem(c), & - self%ctrl_base_l0(c) + delta_l(ch), delta_l_dot(ch), es, em) - IF (es /= CD_SYSTEM_OK) THEN - ErrStat = CD_AGG_BADINPUT - ErrMsg = 'CableDyn_OpenFAST_Aggregate: line-control update failed: '//TRIM(em) - RETURN END IF END DO + + CONTAINS + + SUBROUTINE take_back(last, msg) + !! A row failed after the rows 1..last were applied: put their objects back, the latest + !! first (a line named in two rows ends at its state before the first), and report msg. + INTEGER, INTENT(IN) :: last + CHARACTER(*), INTENT(IN) :: msg + INTEGER :: r, es2 + CHARACTER(512) :: em2, em_undo + em_undo = '' + DO r = last, 1, -1 + IF (self%ctrl_is_cable(r)) THEN + CALL CD_HermiteCable_Dyn_Restore_Control(self%cables(self%ctrl_line(r))%line, self%ctrl_cable_saved(r), & + es2, em2) + IF (es2 /= CD_HCDYN_OK) em_undo = em2 + ELSE + CALL CD_Restore_System_Line_Control(self%sys%fast%system, self%ctrl_line(r), self%ctrl_line_saved(r), & + es2, em2) + IF (es2 /= CD_SYSTEM_OK) em_undo = em2 + END IF + END DO + ErrStat = CD_AGG_BADINPUT + IF (LEN_TRIM(em_undo) == 0) THEN + ErrMsg = msg + ELSE + ErrMsg = msg//'; the lines it had already changed could not all be put back: '//TRIM(em_undo) + END IF + END SUBROUTINE take_back END SUBROUTINE CD_AGG_Apply_LineControl INTEGER FUNCTION CD_AGG_NFailures(self) RESULT(n) @@ -1851,8 +1967,16 @@ SUBROUTINE CD_AGG_End(self, ErrStat, ErrMsg) IF (ALLOCATED(self%ctrl_chan)) DEALLOCATE (self%ctrl_chan) IF (ALLOCATED(self%ctrl_line)) DEALLOCATE (self%ctrl_line) IF (ALLOCATED(self%ctrl_elem)) DEALLOCATE (self%ctrl_elem) + IF (ALLOCATED(self%ctrl_nelem)) DEALLOCATE (self%ctrl_nelem) IF (ALLOCATED(self%ctrl_base_l0)) DEALLOCATE (self%ctrl_base_l0) - IF (ALLOCATED(self%ctrl_warned)) DEALLOCATE (self%ctrl_warned) + IF (ALLOCATED(self%ctrl_unstr_len)) DEALLOCATE (self%ctrl_unstr_len) + IF (ALLOCATED(self%ctrl_nsegs)) DEALLOCATE (self%ctrl_nsegs) + IF (ALLOCATED(self%ctrl_cable_saved)) DEALLOCATE (self%ctrl_cable_saved) + IF (ALLOCATED(self%ctrl_line_saved)) DEALLOCATE (self%ctrl_line_saved) + IF (ALLOCATED(self%ctrl_is_cable)) DEALLOCATE (self%ctrl_is_cable) + IF (ALLOCATED(self%ctrl_line_id)) DEALLOCATE (self%ctrl_line_id) + IF (ALLOCATED(self%ctrl_span_off)) DEALLOCATE (self%ctrl_span_off) + IF (ALLOCATED(self%ctrl_span_l0)) DEALLOCATE (self%ctrl_span_l0) CALL CD_Rigid6_End(self%rigid6) self%has_rigid6 = .FALSE. CALL CD_Rod_End(self%rod) diff --git a/src/CableDyn_OpenFAST_HermiteFMF.f90 b/src/CableDyn_OpenFAST_HermiteFMF.f90 index 66f14b96..01853ea9 100644 --- a/src/CableDyn_OpenFAST_HermiteFMF.f90 +++ b/src/CableDyn_OpenFAST_HermiteFMF.f90 @@ -41,7 +41,8 @@ MODULE CableDyn_OpenFAST_HermiteFMF CD_HermiteCable_Dyn_Snapshot, CD_HermiteCable_Dyn_Restore, & CD_HermiteCable_Dyn_End, CD_HCDYN_OK, & CD_HermiteCable_Dyn_Set_Torsion, CD_HermiteCable_Dyn_Set_Torsion_Drive, & - CD_HermiteCable_Dyn_Set_Torsion_Frames + CD_HermiteCable_Dyn_Set_Torsion_Frames, & + CD_HermiteCable_Dyn_Set_SegmentLength USE CableDyn_HermiteTorsion, ONLY: CD_HermiteTorsionType, CD_HermiteTorsion_Compliance, CD_HermiteTorsion_Line, & CD_HermiteTorsion_Unwrap, CD_HTORS_OK, CD_HTORS_MAX_STEP USE CableDyn_HermiteCable, ONLY: CD_HermiteCable_Shapes @@ -65,6 +66,7 @@ MODULE CableDyn_OpenFAST_HermiteFMF PUBLIC :: CD_HFMF_Set_Waves PUBLIC :: CD_HFMF_Set_Held_Fluid PUBLIC :: CD_HFMF_Set_Contact + PUBLIC :: CD_HFMF_Set_SegmentLength PUBLIC :: CD_HFMF_Set_Attachments PUBLIC :: CD_HFMF_Set_EndConnection PUBLIC :: CD_HFMF_Set_Torsion @@ -1194,6 +1196,29 @@ SUBROUTINE CD_HFMF_Set_Contact(self, kn_node, cn_node, mu, ErrStat, ErrMsg, bath END IF END SUBROUTINE CD_HFMF_Set_Contact + SUBROUTINE CD_HFMF_Set_SegmentLength(self, elems, l0_new, l0_dot, ErrStat, ErrMsg, restored) + !! Active line control through the FMF owner: set the unstretched lengths and their rates + !! of the listed elements before the next UpdateStates (CD_HermiteCable_Dyn_Set_SegmentLength). + !! Lengths do not depend on the frame, so the cable heading plays no part. + TYPE(CD_HFMF_ModuleType), INTENT(INOUT) :: self + INTEGER, INTENT(IN) :: elems(:) + REAL(wp), INTENT(IN) :: l0_new(:), l0_dot(:) + LOGICAL, INTENT(IN), OPTIONAL :: restored + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER :: es + CHARACTER(300) :: em + + ErrStat = CD_HFMF_OK; ErrMsg = '' + IF (.NOT. self%initialized) THEN + ErrStat = CD_HFMF_BADINPUT; ErrMsg = 'CD_HFMF_Set_SegmentLength: module not initialised'; RETURN + END IF + CALL CD_HermiteCable_Dyn_Set_SegmentLength(self%line, elems, l0_new, l0_dot, es, em, restored=restored) + IF (es /= CD_HCDYN_OK) THEN + ErrStat = CD_HFMF_BADINPUT; ErrMsg = 'CD_HFMF_Set_SegmentLength: '//TRIM(em) + END IF + END SUBROUTINE CD_HFMF_Set_SegmentLength + SUBROUTINE CD_HFMF_Refresh_Acceleration(self, ErrStat, ErrMsg) !! Recompute free-node acceleration after a direct-feedthrough boundary commit. !! The caller-prescribed coupled acceleration participates in the consistent-mass @@ -1660,6 +1685,13 @@ SUBROUTINE CD_HFMF_UnpackMirror(self, buf, t, ErrStat, ErrMsg) ! The reloaded acceleration is committed history: a first held fluid field after the ! reload (the host re-sampling its field on the restored state) must keep it. self%line%a_restored = .TRUE. + ! Active line control: the reloaded state is committed with the lengths and rates in + ! place now, so the caller re-applies the command of the checkpointed step BEFORE the + ! reload (the committed force F_n belongs to those lengths). + IF (self%line%has_ctrl) THEN + self%line%l0_c = self%line%l0 + self%line%l0_dot_c = self%line%l0_dot + END IF ! the force-blend committed force reloads with the state it was evaluated at self%line%fc_valid = .FALSE. IF (self%line%force_blend) THEN diff --git a/src/CableDyn_System.f90 b/src/CableDyn_System.f90 index 34dcc24a..bf5b025f 100644 --- a/src/CableDyn_System.f90 +++ b/src/CableDyn_System.f90 @@ -20,7 +20,8 @@ MODULE CableDyn_System CD_Model_Has_Friction, CD_Get_Model_Friction_Anchors, CD_Set_Model_Friction_Anchors, & CD_Get_Model_EndNodeMassDiag, CD_Get_Model_EndNodeAddedMass, & CD_Get_Model_EndNodeTangent, CD_Set_Model_EndQuery, CD_Get_Model_EndQuery, & - CD_Update_Model_SegmentLength, & + CD_Update_Model_SegmentLength, CD_ModelControlSaveType, CD_Save_Model_Control, & + CD_Restore_Model_Control, & CD_Update_Model_CoupledMotion, CD_Update_Model_Interior_State, CD_Step_Model, & CD_Get_Model_Substep_Counts, CD_SubstepStats, & CD_Calc_Model_CoupledLoads, CD_Recompute_Model_Acceleration, & @@ -98,6 +99,7 @@ MODULE CableDyn_System PUBLIC :: CD_System_Point_Environment PUBLIC :: CD_Detach_System_LineEnds PUBLIC :: CD_Update_System_Line_SegmentLength + PUBLIC :: CD_Save_System_Line_Control, CD_Restore_System_Line_Control PUBLIC :: CD_System_Is_Initialized PUBLIC :: CD_System_Has_DynamicPoints @@ -210,7 +212,7 @@ MODULE CableDyn_System ! init helpers (bitwise-deterministic), and the distributed-load remainder ! restores with f_ext -- the documented bit-identical restore must hold ! WITHOUT the caller re-applying its command. - REAL(wp), ALLOCATABLE :: snap_l0(:), snap_l0_dot(:), snap_fbase(:) + REAL(wp), ALLOCATABLE :: snap_l0(:), snap_l0_dot(:), snap_fbase(:), snap_l0_c(:), snap_l0_dot_c(:) ! Viscoelastic dl_1 joins the snapshot (per-element, concatenated like ! snap_l0): the state advances with every committed line step, so the ! aggregate stage-then-commit restore must rewind it with q/v/a. @@ -455,6 +457,7 @@ SUBROUTINE CD_End_System(system, ErrStat, ErrMsg) IF (ALLOCATED(system%snap_bindings)) DEALLOCATE (system%snap_bindings) IF (ALLOCATED(system%snap_map)) DEALLOCATE (system%snap_map) IF (ALLOCATED(system%snap_l0)) DEALLOCATE (system%snap_l0, system%snap_l0_dot) + IF (ALLOCATED(system%snap_l0_c)) DEALLOCATE (system%snap_l0_c, system%snap_l0_dot_c) IF (ALLOCATED(system%snap_fbase)) DEALLOCATE (system%snap_fbase) IF (ALLOCATED(system%snap_ve_dl_1)) DEALLOCATE (system%snap_ve_dl_1) IF (ALLOCATED(system%snap_syrope_slow)) DEALLOCATE (system%snap_syrope_slow, system%snap_syrope_tmax) @@ -1254,11 +1257,11 @@ RECURSIVE SUBROUTINE CD_Step_System(system, dt, q_coupled, v_coupled, a_coupled, INTEGER, PARAMETER :: MAX_SUBDIV = 6 ! floor dt/64: resolves any benign line-search stall INTEGER :: i, j, lo, hi, nc, es, line_dof, sys_dof, depth, iter2, ntot, nve, nsy, lo_ve, lo_sy, ne, nfr, lo_fr - INTEGER :: n_team + INTEGER :: n_team, nel, lo_el LOGICAL :: conv2, stall2 CHARACTER(160) :: em REAL(wp), ALLOCATABLE :: q0(:), v0(:), a0(:), qm(:), vm(:), am(:), qs(:), vs(:), as(:) - REAL(wp), ALLOCATABLE :: dl1s(:), slows(:), tmaxs(:), frs(:, :), hmaxs(:) + REAL(wp), ALLOCATABLE :: dl1s(:), slows(:), tmaxs(:), frs(:, :), hmaxs(:), l0cs(:), l0dcs(:) TYPE(CD_SubstepStats), ALLOCATABLE :: subs(:) converged = .FALSE. @@ -1380,24 +1383,29 @@ RECURSIVE SUBROUTINE CD_Step_System(system, dt, q_coupled, v_coupled, a_coupled, lo = lo + nc END DO CALL restore_line_states(system) - ! The frame snapshot covers every state a line step commits: the kinematics and the - ! viscoelastic / Syrope history variables. + ! The frame snapshot covers every state a line step commits: the kinematics, the + ! viscoelastic / Syrope history variables and the lengths and rates the committed state + ! was reached with (active line control: a converged first half commits the new + ! lengths, so a restore without them would re-run the full step unblended). ntot = 0 nve = 0 nsy = 0 nfr = 0 + nel = 0 DO i = 1, system%n_lines ntot = ntot + SIZE(system%lines(i)%q) + nel = nel + SIZE(system%lines(i)%l0_c) IF (system%lines(i)%has_viscoelastic) nve = nve + SIZE(system%lines(i)%ve_dl_1) IF (system%lines(i)%has_syrope) nsy = nsy + SIZE(system%lines(i)%syrope_slow) IF (CD_Model_Has_Friction(system%lines(i))) nfr = nfr + SIZE(system%lines(i)%fr_anchor, 2) END DO ALLOCATE (qs(ntot), vs(ntot), as(ntot), dl1s(nve), slows(nsy), tmaxs(nsy), frs(2, nfr), & - hmaxs(system%n_lines), subs(system%n_lines)) + hmaxs(system%n_lines), subs(system%n_lines), l0cs(nel), l0dcs(nel)) lo = 1 lo_ve = 1 lo_sy = 1 lo_fr = 1 + lo_el = 1 DO i = 1, system%n_lines hi = lo + SIZE(system%lines(i)%q) - 1 qs(lo:hi) = system%lines(i)%q @@ -1408,6 +1416,10 @@ RECURSIVE SUBROUTINE CD_Step_System(system, dt, q_coupled, v_coupled, a_coupled, hmaxs(i) = system%lines(i)%audit_hmax subs(i) = system%lines(i)%sub_stats lo = hi + 1 + ne = SIZE(system%lines(i)%l0_c) + l0cs(lo_el:lo_el + ne - 1) = system%lines(i)%l0_c + l0dcs(lo_el:lo_el + ne - 1) = system%lines(i)%l0_dot_c + lo_el = lo_el + ne IF (CD_Model_Has_Friction(system%lines(i))) THEN ne = SIZE(system%lines(i)%fr_anchor, 2) frs(:, lo_fr:lo_fr + ne - 1) = system%lines(i)%fr_anchor @@ -1444,6 +1456,7 @@ RECURSIVE SUBROUTINE CD_Step_System(system, dt, q_coupled, v_coupled, a_coupled, lo_ve = 1 lo_sy = 1 lo_fr = 1 + lo_el = 1 DO i = 1, system%n_lines hi = lo + SIZE(system%lines(i)%q) - 1 system%lines(i)%q = qs(lo:hi) @@ -1452,6 +1465,10 @@ RECURSIVE SUBROUTINE CD_Step_System(system, dt, q_coupled, v_coupled, a_coupled, system%lines(i)%audit_hmax = hmaxs(i) system%lines(i)%sub_stats = subs(i) lo = hi + 1 + ne = SIZE(system%lines(i)%l0_c) + system%lines(i)%l0_c = l0cs(lo_el:lo_el + ne - 1) + system%lines(i)%l0_dot_c = l0dcs(lo_el:lo_el + ne - 1) + lo_el = lo_el + ne IF (CD_Model_Has_Friction(system%lines(i))) THEN ne = SIZE(system%lines(i)%fr_anchor, 2) system%lines(i)%fr_anchor = frs(:, lo_fr:lo_fr + ne - 1) @@ -1893,18 +1910,21 @@ PURE SUBROUTINE solve_spd3(A, b, x, ok) IF (.NOT. ok) x = CD_ZERO END SUBROUTINE solve_spd3 - SUBROUTINE CD_Update_System_Line_SegmentLength(system, line_index, elem, l0_new, l0_dot, ErrStat, ErrMsg) + SUBROUTINE CD_Update_System_Line_SegmentLength(system, line_index, elem, l0_new, l0_dot, ErrStat, ErrMsg, & + restored) !! Active line control at the system level: update one element's unstretched !! length/rate on a contained line (CD_Update_Model_SegmentLength does the model !! work) and RECOMPUTE the end-node consistent-mass diagonal shares of every !! point bound to that line -- the implicit share a Free/Connect point carries !! (see the massless-point step) reads rho_a*l0/3, so a length change on an end - !! element moves it. + !! element moves it. restored = .TRUE. marks the length and rate as the committed + !! state's (a checkpoint restart re-applying the restored command). TYPE(CD_SystemType), INTENT(INOUT) :: system INTEGER, INTENT(IN) :: line_index, elem REAL(wp), INTENT(IN) :: l0_new, l0_dot INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg + LOGICAL, INTENT(IN), OPTIONAL :: restored INTEGER :: k, i, kb, es REAL(wp) :: md @@ -1934,7 +1954,7 @@ SUBROUTINE CD_Update_System_Line_SegmentLength(system, line_index, elem, l0_new, END DO END DO END IF - CALL CD_Update_Model_SegmentLength(system%lines(line_index), elem, l0_new, l0_dot, es, em) + CALL CD_Update_Model_SegmentLength(system%lines(line_index), elem, l0_new, l0_dot, es, em, restored=restored) IF (es /= CD_MODEL_OK) THEN CALL fail(ErrStat, ErrMsg, 'segment-length update failed: '//TRIM(em)) RETURN @@ -1951,6 +1971,49 @@ SUBROUTINE CD_Update_System_Line_SegmentLength(system, line_index, elem, l0_new, END DO END SUBROUTINE CD_Update_System_Line_SegmentLength + SUBROUTINE CD_Save_System_Line_Control(system, line_index, saved, ErrStat, ErrMsg) + !! Save what CD_Update_System_Line_SegmentLength writes on one contained line + !! (CD_Save_Model_Control), for CD_Restore_System_Line_Control. + TYPE(CD_SystemType), INTENT(IN) :: system + INTEGER, INTENT(IN) :: line_index + TYPE(CD_ModelControlSaveType), INTENT(INOUT) :: saved + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + CALL validate_line_index(system, line_index, ErrStat, ErrMsg) + IF (ErrStat /= CD_SYSTEM_OK) RETURN + CALL CD_Save_Model_Control(system%lines(line_index), saved) + END SUBROUTINE CD_Save_System_Line_Control + + SUBROUTINE CD_Restore_System_Line_Control(system, line_index, saved, ErrStat, ErrMsg) + !! Take one contained line back to what CD_Save_System_Line_Control saved, bit for bit, + !! and re-accumulate the end-node mass-diagonal shares of the Free/Connect points bound to + !! it from the restored lengths (the accumulation the update and initialisation perform). + TYPE(CD_SystemType), INTENT(INOUT) :: system + INTEGER, INTENT(IN) :: line_index + TYPE(CD_ModelControlSaveType), INTENT(IN) :: saved + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER :: k, i, es + CHARACTER(240) :: em + CALL validate_line_index(system, line_index, ErrStat, ErrMsg) + IF (ErrStat /= CD_SYSTEM_OK) RETURN + CALL CD_Restore_Model_Control(system%lines(line_index), saved, es, em) + IF (es /= CD_MODEL_OK) THEN + CALL fail(ErrStat, ErrMsg, TRIM(em)) + RETURN + END IF + IF (.NOT. (ALLOCATED(system%points) .AND. ALLOCATED(system%bindings))) RETURN + DO k = 1, SIZE(system%bindings) + IF (system%bindings(k)%line_index /= line_index) CYCLE + i = find_point_index(system%points, system%bindings(k)%point_id) + IF (i < 1) CYCLE + IF (system%points(i)%point_type /= CD_POINT_FREE .AND. & + system%points(i)%point_type /= CD_POINT_CONNECT) CYCLE + CALL recompute_point_line_mass_diag(system, i, ErrStat, ErrMsg) + IF (ErrStat /= CD_SYSTEM_OK) RETURN + END DO + END SUBROUTINE CD_Restore_System_Line_Control + SUBROUTINE recompute_point_line_mass_diag(system, point_index, ErrStat, ErrMsg) !! Re-accumulate one point's attached end-node consistent-mass diagonal share !! from its CURRENT bindings (the same accumulation init performs). @@ -2978,6 +3041,9 @@ SUBROUTINE save_line_states(system, ErrStat, ErrMsg) system%lines(i)%audit_hmax_rollback = system%lines(i)%audit_hmax ! the sub-stepping diagnostics likewise: a rolled-back step is not counted system%lines(i)%sub_stats_rollback = system%lines(i)%sub_stats + ! the committed lengths and rates (active line control) advance with a step too + system%lines(i)%l0_c_rollback = system%lines(i)%l0_c + system%lines(i)%l0_dot_c_rollback = system%lines(i)%l0_dot_c ! the viscoelastic dl_1 state advances with every committed line step, so ! it must roll back with q/v/a (a line that stepped can be rolled back ! when a sibling line or the coupled point solve fails) @@ -3007,6 +3073,8 @@ SUBROUTINE restore_line_states(system) system%lines(i)%a = system%lines(i)%a_rollback system%lines(i)%audit_hmax = system%lines(i)%audit_hmax_rollback system%lines(i)%sub_stats = system%lines(i)%sub_stats_rollback + system%lines(i)%l0_c = system%lines(i)%l0_c_rollback + system%lines(i)%l0_dot_c = system%lines(i)%l0_dot_c_rollback IF (system%lines(i)%has_viscoelastic) & system%lines(i)%ve_dl_1 = system%lines(i)%ve_dl_1_rollback IF (system%lines(i)%has_syrope) THEN @@ -3115,6 +3183,7 @@ SUBROUTINE CD_System_Snapshot(system, ErrStat, ErrMsg) netot = netot + SIZE(system%lines(i)%l0) END DO ALLOCATE (system%snap_l0(netot), system%snap_l0_dot(netot), system%snap_fbase(ntot), & + system%snap_l0_c(netot), system%snap_l0_dot_c(netot), & system%snap_ve_dl_1(netot), system%snap_syrope_slow(netot), & system%snap_syrope_tmax(netot), system%snap_fr_anchor(ntot)) END BLOCK @@ -3152,6 +3221,8 @@ SUBROUTINE CD_System_Snapshot(system, ErrStat, ErrMsg) he = le + ne_i - 1 system%snap_l0(le:he) = system%lines(i)%l0 system%snap_l0_dot(le:he) = system%lines(i)%l0_dot + system%snap_l0_c(le:he) = system%lines(i)%l0_c + system%snap_l0_dot_c(le:he) = system%lines(i)%l0_dot_c IF (system%lines(i)%has_viscoelastic) & system%snap_ve_dl_1(le:he) = system%lines(i)%ve_dl_1 IF (system%lines(i)%has_syrope) THEN @@ -3224,6 +3295,8 @@ SUBROUTINE CD_System_Restore(system, ErrStat, ErrMsg) he = le + ne_i - 1 hi = lo + SIZE(system%lines(i)%q) - 1 system%lines(i)%l0_dot = system%snap_l0_dot(le:he) + system%lines(i)%l0_c = system%snap_l0_c(le:he) + system%lines(i)%l0_dot_c = system%snap_l0_dot_c(le:he) IF (system%lines(i)%has_viscoelastic) & system%lines(i)%ve_dl_1 = system%snap_ve_dl_1(le:he) IF (system%lines(i)%has_syrope) THEN diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index f280770e..07a32f3d 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -1418,6 +1418,24 @@ SUBROUTINE rebuild_from_checkpoint( t, u1, p, x, other, m, ErrStat, ErrMsg ) ErrStat, ErrMsg, RoutineName ) RETURN END IF + ! Active line control: the rebuild re-initialized at the BASE segment lengths; + ! apply the restored command HERE, on the rebuild transition itself, so every + ! entry that can trigger a rebuild (UpdateStates -- including its supercycle + ! early-return substeps -- and CalcOutput) resumes at the checkpointed lengths. + ! The restored command is the one the committed state was reached with, so the + ! lengths are re-applied as committed (the next advance blends them into its + ! generalised-alpha terms exactly as the uninterrupted run does). It runs before the + ! line interiors and cable mirrors reload below, which bring back the committed state + ! of the uninterrupted run, a cable's committed force included. + IF (ALLOCATED(u1%DeltaL)) THEN + CALL CD_AGG_Apply_LineControl( Inst(id)%agg, REAL(u1%DeltaL, wp), REAL(u1%DeltaLdot, wp), es, em, & + restored=.TRUE. ) + IF (es /= CD_AGG_OK) THEN + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: line-control apply after the '// & + 'checkpoint rebuild failed: '//TRIM(em), ErrStat, ErrMsg, RoutineName ) + RETURN + END IF + END IF ! ...line interiors + cable free-DOF mirrors, exactly (committed accelerations ! reload from the mirror -- shared helper with the state-const CalcOutput) CALL reload_interiors_ary( Inst(id), m, x%states, REAL(t, wp), ErrStat2, ErrMsg2 ) @@ -1438,20 +1456,6 @@ SUBROUTINE rebuild_from_checkpoint( t, u1, p, x, other, m, ErrStat, ErrMsg ) RETURN END IF END IF - - ! Active line control: the rebuild re-initialized at the BASE segment lengths; - ! apply the restored command HERE, on the rebuild transition itself, so every - ! entry that can trigger a rebuild (UpdateStates -- including its supercycle - ! early-return substeps -- and CalcOutput) resumes at the checkpointed lengths. - IF (ALLOCATED(u1%DeltaL)) THEN - CALL CD_AGG_Apply_LineControl( Inst(id)%agg, REAL(u1%DeltaL, wp), REAL(u1%DeltaLdot, wp), es, em ) - IF (es /= CD_AGG_OK) THEN - CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: line-control apply after the '// & - 'checkpoint rebuild failed: '//TRIM(em), ErrStat, ErrMsg, RoutineName ) - CALL release_instance( id ) - RETURN - END IF - END IF ! A fresh-process restart first passes through CD_Init, whose provisional instance ! owns the output stream of the same root; the checkpointed m%CDInst need not be ! that slot. Find it so its stream is released and the slot freed with old_id. @@ -1637,7 +1641,8 @@ SUBROUTINE CD_UpdateStates( t, n, u, t_array, p, x, xd, z, other, m, ErrStat, Er IF (ErrStat >= AbortErrLev) RETURN END IF ! Active line control: apply the interpolated DeltaL/DeltaLdot command to - ! the controlled segments BEFORE the advance (the MoorDyn placement). + ! the controlled segments (EI=0 line segments and finite-EI cable spans) + ! BEFORE the advance (the MoorDyn placement). ! Runs AFTER the snapshot so a correction re-entry restores the ! step-start lengths and re-applies the corrected command. IF (ALLOCATED(Inst(id)%u_interp%DeltaL)) THEN diff --git a/tests/data/activetension_ab_reference.csv b/tests/data/activetension_ab_reference.csv index 487180db..29a366c2 100644 --- a/tests/data/activetension_ab_reference.csv +++ b/tests/data/activetension_ab_reference.csv @@ -3,20 +3,20 @@ # Tensions in N; hold windows have DeltaLdot=0. Reproduce: validation/scripts/activetension/ + validation/scripts/openfast_activetension_ab.py. channel,hold,cabledyn_N,moordyn_N,pct FairTen1,baseline,2.353e+06,2.35299e+06,+0.000 -FairTen1,payout_hold,2.272e+06,2.27203e+06,-0.046 -FairTen1,haulin_hold,2.39815e+06,2.39819e+06,-0.112 +FairTen1,payout_hold,2.27203e+06,2.27203e+06,-0.013 +FairTen1,haulin_hold,2.39818e+06,2.39819e+06,-0.040 FairTen2,baseline,2.429e+06,2.42922e+06,-0.009 -FairTen2,payout_hold,2.339e+06,2.33916e+06,+0.080 -FairTen2,haulin_hold,2.47692e+06,2.47691e+06,+0.508 +FairTen2,payout_hold,2.33901e+06,2.33916e+06,+0.084 +FairTen2,haulin_hold,2.4769e+06,2.47691e+06,+0.461 FairTen3,baseline,2.429e+06,2.42922e+06,-0.009 -FairTen3,payout_hold,2.339e+06,2.33916e+06,+0.080 -FairTen3,haulin_hold,2.47692e+06,2.47691e+06,+0.508 +FairTen3,payout_hold,2.33901e+06,2.33916e+06,+0.084 +FairTen3,haulin_hold,2.4769e+06,2.47691e+06,+0.461 AnchTen1,baseline,1.274e+06,1.27428e+06,-0.022 -AnchTen1,payout_hold,1.19297e+06,1.19292e+06,+0.396 -AnchTen1,haulin_hold,1.31936e+06,1.31935e+06,+0.632 +AnchTen1,payout_hold,1.19295e+06,1.19292e+06,+0.367 +AnchTen1,haulin_hold,1.31937e+06,1.31935e+06,+0.665 AnchTen2,baseline,1.35e+06,1.35005e+06,-0.004 -AnchTen2,payout_hold,1.2601e+06,1.26032e+06,-0.190 -AnchTen2,haulin_hold,1.39775e+06,1.39772e+06,+0.169 +AnchTen2,payout_hold,1.26017e+06,1.26032e+06,-0.107 +AnchTen2,haulin_hold,1.39774e+06,1.39772e+06,+0.145 AnchTen3,baseline,1.35e+06,1.35005e+06,-0.004 -AnchTen3,payout_hold,1.2601e+06,1.26032e+06,-0.190 -AnchTen3,haulin_hold,1.39775e+06,1.39772e+06,+0.169 +AnchTen3,payout_hold,1.26017e+06,1.26032e+06,-0.107 +AnchTen3,haulin_hold,1.39774e+06,1.39772e+06,+0.145 diff --git a/tests/test_core_release_regressions.f90 b/tests/test_core_release_regressions.f90 index a692c8f1..9193d831 100644 --- a/tests/test_core_release_regressions.f90 +++ b/tests/test_core_release_regressions.f90 @@ -5,7 +5,12 @@ PROGRAM test_core_release_regressions !! Failure-path contracts of the numerical core: !! 1. The system subdivision fallback restores the complete committed line state !! (kinematics AND viscoelastic / Syrope history) when it cannot complete an - !! interval, so its best-effort result equals one plain full-dt step. + !! interval, so its best-effort result equals one plain full-dt step; after an + !! active-line-control length change that includes the committed lengths. + !! 1b. A re-derived acceleration between a length change and the next step (the + !! model's recompute, and the system update the OpenFAST shell performs) belongs to + !! the committed state: it is solved at the committed lengths, which stay committed, so + !! the step still blends the old and new lengths. !! 2. A segment-length update whose acceleration recompute fails leaves the model !! exactly as it was (lengths, rates, loads, mass, acceleration). !! 3. An ElasticMod 3 rope whose alphaMBL does not exceed the static EA fails at @@ -23,11 +28,13 @@ PROGRAM test_core_release_regressions USE CableDyn_Model, ONLY: CD_ModelType, CD_Init_Model, CD_Step_Model, CD_Step_Model_Recovering, & CD_End_Model, CD_Get_Model_State, CD_Get_Model_VE_Dl1, & CD_Get_Model_Syrope_State, CD_Update_Model_SegmentLength, & - CD_MODEL_OK, CD_MODEL_BADINPUT + CD_Recompute_Model_Acceleration, CD_MODEL_OK, CD_MODEL_BADINPUT USE CableDyn_System, ONLY: CD_SystemType, CD_Init_System_From_Models, CD_End_System, CD_Step_System, & CD_Get_System_CoupledMotion, CD_System_NCoupledDOF, CD_Get_System_Line_State, & CD_Get_System_Line_VE_Dl1, CD_Get_System_Line_Syrope_State, & - CD_System_Fallback_Count, CD_System_Fallback_Reset, CD_SYSTEM_OK + CD_System_Fallback_Count, CD_System_Fallback_Reset, CD_SYSTEM_OK, & + CD_Update_System_Line_SegmentLength, CD_Update_System_CoupledMotion, & + CD_Recompute_System_Acceleration USE CableDyn_Hydro, ONLY: CD_Airy_Wave_Kinematics_Precomputed, CD_HYDRO_OK, CD_HYDRO_BADINPUT USE CableDyn_HermiteCableStatic, ONLY: CD_HermiteCable_Static_Solve, CD_HermiteCable_Static_Solve_AutoMesh, & CD_HermiteCable_Trivial_Seed, CD_HermiteResolutionType, & @@ -58,6 +65,8 @@ PROGRAM test_core_release_regressions nfail = 0 CALL case_fallback_restores_constitutive_state() + CALL case_fallback_restores_committed_lengths() + CALL case_recompute_keeps_committed_lengths() CALL case_segment_length_update_is_atomic() CALL case_mode3_premise_over_slack_range() CALL case_short_error_buffers() @@ -209,6 +218,157 @@ SUBROUTINE case_fallback_restores_constitutive_state() CALL CD_Syrope_End(td) END SUBROUTINE case_fallback_restores_constitutive_state + SUBROUTINE case_fallback_restores_committed_lengths() + !! Active line control: a length and rate change, then a step that stalls at every + !! subdivision level. The first half-step commits the new lengths as those of the + !! committed state, so the fallback's restore must bring back the committed lengths of + !! the entry state as well: the plain full-dt re-run then blends the old and new lengths + !! and equals one plain step of the same line bit for bit. + REAL(wp), PARAMETER :: DT = 0.02_wp + TYPE(CD_ModelType) :: models(1), ref + TYPE(CD_SystemType) :: system + TYPE(GenAlphaConfig) :: cfg + INTEGER :: conn(2, 2), fixed(6), es, n_iter, nc, j + REAL(wp) :: l0(2), q0(9), v0(9), f_ext(9), eav(2), rho_a(2) + REAL(wp), ALLOCATABLE :: qc(:), vc(:), ac(:) + REAL(wp) :: qs(9), vs(9), as(9), qr(9), vr(9), ar(9), pq(9), pv(9), pa(9) + LOGICAL :: conv, stalled + CHARACTER(240) :: em + + cfg%max_iter = 1 + cfg%rel_tol = 1.0e-15_wp + cfg%abs_tol = 1.0e-300_wp + v0 = 0.0_wp + f_ext = 0.0_wp + f_ext(6) = -2.0e3_wp + rho_a = 22.42_wp + eav = 1.0e8_wp + CALL two_element_chain(1.01_wp, conn, l0, q0, fixed) + CALL CD_Init_Model(models(1), q0, v0, conn, l0, eav, rho_a, .FALSE., f_ext, fixed, cfg, es, em) + CALL require(es == CD_MODEL_OK, 'fallback-lengths:init '//TRIM(em)) + CALL CD_Init_Model(ref, q0, v0, conn, l0, eav, rho_a, .FALSE., f_ext, fixed, cfg, es, em) + CALL require(es == CD_MODEL_OK, 'fallback-lengths:reference-init '//TRIM(em)) + CALL CD_Init_System_From_Models(system, models, es, em) + CALL require(es == CD_SYSTEM_OK, 'fallback-lengths:system-init '//TRIM(em)) + ! pay out the second element: a new length and rate the committed state was not reached with + CALL CD_Update_System_Line_SegmentLength(system, 1, 2, 1.004_wp, 0.2_wp, es, em) + CALL require(es == CD_SYSTEM_OK, 'fallback-lengths:system-update '//TRIM(em)) + CALL CD_Update_Model_SegmentLength(ref, 2, 1.004_wp, 0.2_wp, es, em) + CALL require(es == CD_MODEL_OK, 'fallback-lengths:reference-update '//TRIM(em)) + nc = CD_System_NCoupledDOF(system, es, em) + CALL require(es == CD_SYSTEM_OK .AND. nc == 6, 'fallback-lengths:coupled-dof-count') + ALLOCATE (qc(nc), vc(nc), ac(nc)) + CALL CD_Get_System_CoupledMotion(system, qc, vc, ac, es, em) + CALL require(es == CD_SYSTEM_OK, 'fallback-lengths:coupled-motion') + qc(4) = qc(4) + 0.004_wp + vc(4) = 0.2_wp + ac = 0.0_wp + + CALL CD_System_Fallback_Reset() + CALL CD_Step_System(system, DT, qc, vc, ac, conv, stalled, n_iter, es, em) + CALL require(es == CD_SYSTEM_OK, 'fallback-lengths:system-step '//TRIM(em)) + CALL require(.NOT. conv, 'fallback-lengths:step-stalls-at-every-depth') + CALL require(CD_System_Fallback_Count() > 0, 'fallback-lengths:subdivision-entered') + CALL CD_System_Fallback_Reset() + + CALL CD_Get_Model_State(ref, pq, pv, pa, es, em) + DO j = 1, 6 + pq(fixed(j)) = qc(j) + pv(fixed(j)) = vc(j) + pa(fixed(j)) = ac(j) + END DO + CALL CD_Step_Model(ref, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + CALL require(es == CD_MODEL_OK, 'fallback-lengths:reference-step') + CALL CD_Get_System_Line_State(system, 1, qs, vs, as, es, em) + CALL CD_Get_Model_State(ref, qr, vr, ar, es, em) + CALL require(same(qs, qr) .AND. same(vs, vr) .AND. same(as, ar), & + 'fallback-lengths:kinematics-equal-one-blended-plain-step') + CALL require(same(system%lines(1)%l0_c, ref%l0_c) .AND. same(system%lines(1)%l0_dot_c, ref%l0_dot_c), & + 'fallback-lengths:committed-lengths-advanced-once') + + CALL CD_End_System(system, es, em) + CALL CD_End_Model(models(1), es, em) + CALL CD_End_Model(ref, es, em) + END SUBROUTINE case_fallback_restores_committed_lengths + + SUBROUTINE case_recompute_keeps_committed_lengths() + !! Active line control on an EI = 0 line: after a length and rate change, re-deriving the + !! acceleration (a boundary commit, or the OpenFAST shell's state update) solves it at the + !! lengths and rates the committed state was reached with. It equals the acceleration of + !! a line that was never commanded, the committed lengths stay, the new ones stay in + !! place, and the step that follows is the blended step of a model whose acceleration was + !! not re-derived. The same holds through the system update (coupled motion + recompute). + REAL(wp), PARAMETER :: DT = 0.02_wp + TYPE(CD_ModelType) :: a, b, twin, lines(1) + TYPE(CD_SystemType) :: system + TYPE(GenAlphaConfig) :: cfg + INTEGER :: conn(2, 2), fixed(6), es, n_iter, nc, j + REAL(wp) :: l0(2), q0(9), v0(9), f_ext(9), eav(2), rho_a(2), pq(9), pv(9), pa(9) + REAL(wp) :: qs(9), vs(9), as(9) + REAL(wp), ALLOCATABLE :: qc(:), vc(:), ac(:) + LOGICAL :: conv, stalled + CHARACTER(240) :: em + + v0 = 0.0_wp + f_ext = 0.0_wp + f_ext(6) = -2.0e3_wp + rho_a = 22.42_wp + eav = 1.0e8_wp + CALL two_element_chain(1.01_wp, conn, l0, q0, fixed) + CALL CD_Init_Model(a, q0, v0, conn, l0, eav, rho_a, .FALSE., f_ext, fixed, cfg, es, em) + CALL require(es == CD_MODEL_OK, 'recompute-lengths:init '//TRIM(em)) + CALL CD_Init_Model(twin, q0, v0, conn, l0, eav, rho_a, .FALSE., f_ext, fixed, cfg, es, em) + CALL require(es == CD_MODEL_OK, 'recompute-lengths:twin-init '//TRIM(em)) + lines(1) = a + CALL CD_Update_Model_SegmentLength(a, 2, 1.004_wp, 0.2_wp, es, em) + CALL require(es == CD_MODEL_OK, 'recompute-lengths:update '//TRIM(em)) + b = a + CALL CD_Recompute_Model_Acceleration(a, es, em) + CALL require(es == CD_MODEL_OK, 'recompute-lengths:recompute '//TRIM(em)) + CALL CD_Recompute_Model_Acceleration(twin, es, em) + CALL require(es == CD_MODEL_OK, 'recompute-lengths:twin-recompute '//TRIM(em)) + CALL require(same(a%a, twin%a), 'recompute-lengths:acceleration-of-the-committed-lengths') + CALL require(same(a%l0_c, l0) .AND. same(a%l0_dot_c, [0.0_wp, 0.0_wp]) .AND. & + a%l0(2) == 1.004_wp .AND. a%l0_dot(2) == 0.2_wp .AND. same(a%l0, b%l0) .AND. & + same(a%l0_dot, b%l0_dot), 'recompute-lengths:committed-and-present-lengths-kept') + ! the step after it is the blended step (of a model with the same acceleration) + b%a = a%a + CALL CD_Get_Model_State(a, pq, pv, pa, es, em) + pq(7) = pq(7) + 0.004_wp + pv(7) = 0.2_wp + CALL CD_Step_Model(a, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + CALL require(es == CD_MODEL_OK .AND. conv, 'recompute-lengths:step '//TRIM(em)) + CALL CD_Step_Model(b, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + CALL require(es == CD_MODEL_OK .AND. conv, 'recompute-lengths:reference-step '//TRIM(em)) + CALL require(same(a%q, b%q) .AND. same(a%v, b%v) .AND. same(a%a, b%a) .AND. same(a%l0_c, a%l0), & + 'recompute-lengths:the-step-still-blends-the-lengths') + + ! the system update the OpenFAST shell performs between the command and the step + CALL CD_Init_System_From_Models(system, lines, es, em) + CALL require(es == CD_SYSTEM_OK, 'recompute-lengths:system-init '//TRIM(em)) + CALL CD_Update_System_Line_SegmentLength(system, 1, 2, 1.004_wp, 0.2_wp, es, em) + CALL require(es == CD_SYSTEM_OK, 'recompute-lengths:system-update '//TRIM(em)) + nc = CD_System_NCoupledDOF(system, es, em) + ALLOCATE (qc(nc), vc(nc), ac(nc)) + CALL CD_Get_System_CoupledMotion(system, qc, vc, ac, es, em) + CALL CD_Update_System_CoupledMotion(system, qc, vc, ac, es, em) + CALL require(es == CD_SYSTEM_OK, 'recompute-lengths:system-motion '//TRIM(em)) + CALL CD_Recompute_System_Acceleration(system, es, em) + CALL require(es == CD_SYSTEM_OK, 'recompute-lengths:system-recompute '//TRIM(em)) + CALL CD_Get_System_Line_State(system, 1, qs, vs, as, es, em) + CALL require(same(as, twin%a) .AND. same(system%lines(1)%l0_c, l0) .AND. system%lines(1)%l0(2) == 1.004_wp, & + 'recompute-lengths:the-system-update-keeps-the-committed-lengths') + DO j = 1, 2 + CALL require(system%lines(1)%l0_dot_c(j) == 0.0_wp, 'recompute-lengths:system-committed-rates') + END DO + + CALL CD_End_System(system, es, em) + CALL CD_End_Model(a, es, em) + CALL CD_End_Model(b, es, em) + CALL CD_End_Model(twin, es, em) + CALL CD_End_Model(lines(1), es, em) + END SUBROUTINE case_recompute_keeps_committed_lengths + SUBROUTINE case_segment_length_update_is_atomic() !! A length so large that the reassembled distributed load overflows makes the !! acceleration recompute fail after the length-dependent fields were rebuilt. diff --git a/tests/test_ei0_slack_dynamics.f90 b/tests/test_ei0_slack_dynamics.f90 index 195ef517..5cefc951 100644 --- a/tests/test_ei0_slack_dynamics.f90 +++ b/tests/test_ei0_slack_dynamics.f90 @@ -63,6 +63,14 @@ PROGRAM test_ei0_slack_dynamics !! share's credit (it returned many times that before the cap covered slack starts), a !! slack segment with no step-start dashpot force keeps the plain blend, and the tangent !! of a capped row matches the finite difference on the banded and the dense path. + !! 11. A length change over the step (active line control) on the chain of case 5: the + !! step-start force and the release cap's step-start data at the lengths the step-start + !! state was reached with (start_l0), the inertia at the blended lengths (mass_l0); the + !! residual against the closed form and the tangent against the finite difference, also + !! for turning releases (the projected cap) and a haul-in whose end share alone returns more + !! than W_n; and, on the chain with a callback load, the dashpot share and the law bound of + !! the cap and the kept dashpot share of a segment slack at the step-start length (case 10) + !! under a length and rate change, against their closed forms. USE CableDyn_Precision, ONLY: wp USE CableDyn_DeckDriver, ONLY: CD_Run_Deck_Driver, CD_DECKDRV_OK USE CableDyn_Dynamic, ONLY: GenAlphaConfig, CD_CableGenAlphaWorkspace, CD_Cable_Gen_Alpha_Step, CD_DYN_OK @@ -85,6 +93,8 @@ PROGRAM test_ei0_slack_dynamics ! a two-sided axial dashpot (BA cb_ba_dash, force cb_ba_dash (dl/dt)/l0 along the chord, as the ! line model's axial damping) on segment cb_dash_elem (0: none) of rest length cb_l0_dash REAL(wp) :: cb_ba_dash = 0.0_wp, cb_l0_dash = 1.0_wp + ! the dashpot's unstretched-length rate (its force is then (BA/l0) (t . w - (l/l0) l0_dot) t) + REAL(wp) :: cb_l0dot_dash = 0.0_wp INTEGER :: cb_dash_elem = 0 REAL(wp) :: cb_q0(12) = 0.0_wp INTEGER :: cb_law_elem = 0 @@ -94,6 +104,8 @@ PROGRAM test_ei0_slack_dynamics IF (COMMAND_ARGUMENT_COUNT() >= 1) CALL GET_COMMAND_ARGUMENT(1, driver) CALL case_tangent_consistency() CALL case_release_energy() + CALL case_length_change_step() + CALL case_length_change_cap_terms() CALL case_law_release_cap() CALL case_law_damped_release() CALL case_damped_elastic_release() @@ -379,41 +391,54 @@ SUBROUTINE chain_nodes(dirs, strain, l0, q) END DO END SUBROUTINE chain_nodes - SUBROUTINE blended_force(qn, q1, l0, ea, alpha_f, capped, f) + SUBROUTINE blended_force(qn, q1, l0, ea, alpha_f, capped, f, l0s) !! Closed form of the blended internal force (1 - alpha_f) f(q1) + alpha_f f(qn) of the !! tension-only chain, with the release cap (capped) or without it: the retained share !! alpha_f T_n along the step-start chord t_n is at most - !! (W_n + (1 - alpha_f) T_1 p_1)/p, W_n = T_n e_n/2, with the projected shortening - !! p = |d_n| - t_n . d_1 and p_1 = |d_1| - t_1 . d_n, so that the blend returns at most W_n. + !! (W_n + (1 - alpha_f) T^_1 p_1)/p, W_n = T_n e_n/2, with the projected shortening + !! p = |d_n| - t_n . d_1 and p_1 = |d_1| - t_1 . d_n, so that the blend returns at most W_n + !! (T^_1 = T_1 without a length change). l0s: the lengths of the step-start state (f(qn), + !! T_n and e_n) when they differ from the lengths l0 at t_{n+1}; the cap's end-tension + !! estimate is then the step-start secant times the end stretch, T^_1 = (T_n/e_n) e_1, + !! and N is bounded below by zero. REAL(wp), INTENT(IN) :: qn(12), q1(12), l0(3), ea(3), alpha_f LOGICAL, INTENT(IN) :: capped REAL(wp), INTENT(OUT) :: f(12) + REAL(wp), INTENT(IN), OPTIONAL :: l0s(3) INTEGER :: e - REAL(wp) :: dn(3), d1(3), ln, l1, t0, t1, e0, dg, p, p1, share(3) + REAL(wp) :: dn(3), d1(3), ln, l1, t0, t1, t1h, e0, e1, dg, p, p1, share(3), ls(3) + ls = l0 + IF (PRESENT(l0s)) ls = l0s f = 0.0_wp DO e = 1, 3 dn = qn(3*e + 1:3*e + 3) - qn(3*e - 2:3*e) d1 = q1(3*e + 1:3*e + 3) - q1(3*e - 2:3*e) ln = NORM2(dn) l1 = NORM2(d1) - t0 = MAX(0.0_wp, ea(e)*(ln/l0(e) - 1.0_wp)) + t0 = MAX(0.0_wp, ea(e)*(ln/ls(e) - 1.0_wp)) t1 = MAX(0.0_wp, ea(e)*(l1/l0(e) - 1.0_wp)) - e0 = ln - l0(e) + e0 = ln - ls(e) + e1 = l1 - l0(e) dg = alpha_f*t0 p = ln - DOT_PRODUCT(dn/ln, d1) p1 = l1 - DOT_PRODUCT(d1/l1, dn) - IF (capped .AND. t0 > 0.0_wp .AND. p > 0.0_wp) dg = MIN(dg, (0.5_wp*t0*e0 + (1.0_wp - alpha_f)*t1*p1)/p) + t1h = t1 + IF (PRESENT(l0s) .AND. e0 > 0.0_wp) t1h = t0/e0*MAX(e1, 0.0_wp) + IF (capped .AND. t0 > 0.0_wp .AND. p > 0.0_wp) & + dg = MIN(dg, MAX(0.5_wp*t0*e0 + (1.0_wp - alpha_f)*t1h*p1, 0.0_wp)/p) share = (1.0_wp - alpha_f)*t1*d1/l1 + dg*dn/ln f(3*e - 2:3*e) = f(3*e - 2:3*e) - share f(3*e + 1:3*e + 3) = f(3*e + 1:3*e + 3) + share END DO END SUBROUTINE blended_force - SUBROUTINE probe_step(qn, vn, an, q1, l0, ea, rho_a, dense, R, K) - !! Residual and effective tangent of the force-blended step at q1 (the probe_q hook). + SUBROUTINE probe_step(qn, vn, an, q1, l0, ea, rho_a, dense, R, K, start_l0, mass_l0) + !! Residual and effective tangent of the force-blended step at q1 (the probe_q hook); + !! start_l0 and mass_l0 are passed on to the step (a length change over the step). REAL(wp), INTENT(IN) :: qn(12), vn(12), an(12), q1(12), l0(3), ea(3), rho_a(3) LOGICAL, INTENT(IN) :: dense REAL(wp), INTENT(OUT) :: R(12), K(9, 9) + REAL(wp), INTENT(IN), OPTIONAL :: start_l0(3), mass_l0(3) INTEGER :: conn(2, 3), n_iter, es REAL(wp) :: qo(12), vo(12), ao(12) LOGICAL :: converged, stalled @@ -425,11 +450,13 @@ SUBROUTINE probe_step(qn, vn, an, q1, l0, ea, rho_a, dense, R, K) IF (dense) THEN CALL CD_Cable_Gen_Alpha_Step(qn, vn, an, conn, l0, ea, rho_a, .TRUE., 0.0_wp*qn, [1, 2, 3], 0.05_wp, cfg, & qo, vo, ao, converged, stalled, n_iter, es, em, load_proc=zero_load, & - workspace=work, probe_q=q1, probe_R=R, probe_K=K) + workspace=work, probe_q=q1, probe_R=R, probe_K=K, start_l0=start_l0, & + mass_l0=mass_l0) ELSE CALL CD_Cable_Gen_Alpha_Step(qn, vn, an, conn, l0, ea, rho_a, .TRUE., 0.0_wp*qn, [1, 2, 3], 0.05_wp, cfg, & qo, vo, ao, converged, stalled, n_iter, es, em, & - workspace=work, probe_q=q1, probe_R=R, probe_K=K) + workspace=work, probe_q=q1, probe_R=R, probe_K=K, start_l0=start_l0, & + mass_l0=mass_l0) END IF IF (es /= CD_DYN_OK) THEN WRITE (*, '(A)') 'MISMATCH [tangent:probe '//TRIM(em)//']' @@ -588,6 +615,113 @@ SUBROUTINE case_release_energy() CALL require(ratio < 1.0e-6_wp, 'release-energy:continuous-at-rest-length') END SUBROUTINE case_release_energy + SUBROUTINE case_length_change_step() + !! A length change over the step (active line control): segment 1 paid out (0.97 to 1.0 m), + !! segment 3 hauled in (0.83 to 0.8 m). The step-start force and the release cap's + !! step-start tension and stretch take the lengths the step-start state was reached with + !! (start_l0), the force at t_{n+1} and the cap's end stretch the new ones (l0), and the + !! structural inertia the blended ones (mass_l0): residual against the closed form (force + !! and inertia) and tangent against the central difference of the residual, with all + !! segments taut, segment 1 released deeply (cap active), segment 1 turning by 45 degrees + !! as it ends just slack (projected cap), the hauled-in segment 3 turning by about 50 + !! degrees and ending taut (capped with the end share at the secant estimate + !! T^_1 = (T_n/e_n) e_1), and segment 3 shortening along its chord while it stretches + !! against its new length (the end share alone returns more than W_n: kept force zero), on + !! both paths. + REAL(wp), PARAMETER :: L0(3) = [1.0_wp, 1.2_wp, 0.8_wp], L0S(3) = [0.97_wp, 1.2_wp, 0.83_wp] + REAL(wp), PARAMETER :: EA(3) = [1.0e6_wp, 1.5e6_wp, 0.8e6_wp], RHO_A(3) = [2.0_wp, 3.0_wp, 1.5_wp] + REAL(wp), PARAMETER :: DIRS_N(3, 3) = RESHAPE([1.0_wp, 0.2_wp, 0.1_wp, 0.3_wp, 1.0_wp, -0.2_wp, & + -0.2_wp, 0.4_wp, 1.0_wp], [3, 3]) + REAL(wp), PARAMETER :: DIRS_1(3, 3) = RESHAPE([1.0_wp, 0.27_wp, 0.04_wp, 0.36_wp, 1.0_wp, -0.12_wp, & + -0.12_wp, 0.46_wp, 1.0_wp], [3, 3]) + REAL(wp), PARAMETER :: H = 1.0e-6_wp, RHO = 0.4_wp, DT = 0.05_wp + REAL(wp), PARAMETER :: ALPHA_F = RHO/(RHO + 1.0_wp), ALPHA_M = (2.0_wp*RHO - 1.0_wp)/(RHO + 1.0_wp) + REAL(wp), PARAMETER :: BETA = 0.25_wp*(1.0_wp - ALPHA_M + ALPHA_F)**2 + REAL(wp), PARAMETER :: DIRS_T1(3, 3) = RESHAPE([0.6_wp, 0.9_wp, 0.1_wp, 0.36_wp, 1.0_wp, -0.12_wp, & + -0.12_wp, 0.46_wp, 1.0_wp], [3, 3]) + REAL(wp), PARAMETER :: DIRS_T3(3, 3) = RESHAPE([1.0_wp, 0.27_wp, 0.04_wp, 0.36_wp, 1.0_wp, -0.12_wp, & + 0.6_wp, 1.2_wp, 0.4_wp], [3, 3]) + REAL(wp) :: dirs(3, 3, 5), strain_1(3, 5), qn(12), vn(12), an(12), q1(12), qp(12), lm(3), R(12), Rp(12), Rm(12) + REAL(wp) :: K(9, 9), Kfd(9, 9), Kdump(9, 9), f_cap(12), f_new(12), f_raw(12), acc(12), inertia(12), m + REAL(wp) :: scale, err + INTEGER :: c, p, j, i, e, free(9) + LOGICAL :: dense + CHARACTER(16) :: label + free = [(i + 3, i=1, 9)] + lm = L0 + lm(1) = (1.0_wp - ALPHA_F)*L0(1) + ALPHA_F*L0S(1) + lm(3) = (1.0_wp - ALPHA_F)*L0(3) + ALPHA_F*L0S(3) + strain_1(:, 1) = [0.020_wp, 0.015_wp, 0.020_wp] + strain_1(:, 2) = [-0.050_wp, 0.015_wp, 0.020_wp] + strain_1(:, 3) = [-0.0005_wp, 0.015_wp, 0.020_wp] + strain_1(:, 4) = [0.020_wp, 0.015_wp, 0.0002_wp] + strain_1(:, 5) = [0.020_wp, 0.015_wp, 0.025_wp] + dirs(:, :, 1) = DIRS_1 + dirs(:, :, 2) = DIRS_1 + dirs(:, :, 3) = DIRS_T1 + dirs(:, :, 4) = DIRS_T3 + dirs(:, :, 5) = DIRS_N + vn = 0.0_wp + an = 0.0_wp + DO i = 4, 12 + vn(i) = 0.01_wp*SIN(1.7_wp*REAL(i, wp)) + an(i) = 0.02_wp*COS(2.3_wp*REAL(i, wp)) + END DO + CALL chain_nodes(DIRS_N, [0.010_wp, 0.020_wp, 0.010_wp], L0S, qn) + DO c = 1, 5 + SELECT CASE (c) + CASE (1) + label = 'taut-taut' + CASE (2) + label = 'release-cap' + CASE (3) + label = 'turning-release' + CASE (4) + label = 'haul-in-turning' + CASE DEFAULT + label = 'haul-in-negative' + END SELECT + CALL chain_nodes(dirs(:, :, c), strain_1(:, c), L0, q1) + CALL blended_force(qn, q1, L0, EA, ALPHA_F, .TRUE., f_cap, l0s=L0S) + CALL blended_force(qn, q1, L0, EA, ALPHA_F, .FALSE., f_raw, l0s=L0S) + ! the same with the step-start force at the new lengths: what start_l0 must avoid + CALL blended_force(qn, q1, L0, EA, ALPHA_F, .TRUE., f_new) + scale = MAXVAL(ABS(f_raw)) + CALL require(MAXVAL(ABS(f_new - f_cap)) > 1.0e-2_wp*scale, 'lengths:'//TRIM(label)//':start-lengths-matter') + IF (c >= 2) CALL require(MAXVAL(ABS(f_cap - f_raw)) > 1.0e-3_wp*scale, 'lengths:'//TRIM(label)//':cap-active') + ! inertia M(mass_l0) a_alpha of the generalised-alpha relations, the fixed node held + acc = 0.0_wp + DO i = 4, 12 + acc(i) = (1.0_wp - ALPHA_M)*(q1(i) - qn(i) - DT*vn(i) - DT*DT*(0.5_wp - BETA)*an(i))/(BETA*DT*DT) + & + ALPHA_M*an(i) + END DO + inertia = 0.0_wp + DO e = 1, 3 + m = RHO_A(e)*lm(e)/6.0_wp + inertia(3*e - 2:3*e) = inertia(3*e - 2:3*e) + m*(2.0_wp*acc(3*e - 2:3*e) + acc(3*e + 1:3*e + 3)) + inertia(3*e + 1:3*e + 3) = inertia(3*e + 1:3*e + 3) + m*(acc(3*e - 2:3*e) + 2.0_wp*acc(3*e + 1:3*e + 3)) + END DO + DO p = 1, 2 + dense = p == 2 + CALL probe_step(qn, vn, an, q1, L0, EA, RHO_A, dense, R, K, start_l0=L0S, mass_l0=lm) + err = MAXVAL(ABS(R(4:12) - f_cap(4:12) - inertia(4:12)))/MAX(scale, MAXVAL(ABS(inertia))) + WRITE (*, '(A,A,A,L1,A,ES9.2)') ' lengths ', TRIM(label), ' dense=', dense, ': residual vs closed form ', err + CALL require(err < 1.0e-9_wp, 'lengths:'//TRIM(label)//TRIM(MERGE(':dense ', ':banded', dense))//':residual') + DO j = 1, 9 + qp = q1 + qp(free(j)) = q1(free(j)) + H + CALL probe_step(qn, vn, an, qp, L0, EA, RHO_A, dense, Rp, Kdump, start_l0=L0S, mass_l0=lm) + qp(free(j)) = q1(free(j)) - H + CALL probe_step(qn, vn, an, qp, L0, EA, RHO_A, dense, Rm, Kdump, start_l0=L0S, mass_l0=lm) + Kfd(:, j) = (Rp(4:12) - Rm(4:12))/(2.0_wp*H) + END DO + err = MAXVAL(ABS(K - Kfd))/MAXVAL(ABS(K)) + WRITE (*, '(A,A,A,L1,A,ES9.2)') ' lengths ', TRIM(label), ' dense=', dense, ': max |K - K_fd|/max|K| = ', err + CALL require(err < 1.0e-6_wp, 'lengths:'//TRIM(label)//TRIM(MERGE(':dense ', ':banded', dense))//':fd-tangent') + END DO + END DO + END SUBROUTINE case_length_change_step + SUBROUTINE case_light_cable_coarse_step() LOGICAL :: conv INTEGER :: es @@ -791,10 +925,11 @@ SUBROUTINE chain_load(q, v, force, jac_q, jac_v) ell = NORM2(c) t = c/ell w = v(3*b - 2:3*b) - v(3*a - 2:3*a) - ten = cb_ba_dash*DOT_PRODUCT(t, w)/cb_l0_dash + ten = cb_ba_dash*(DOT_PRODUCT(t, w) - ell*cb_l0dot_dash/cb_l0_dash)/cb_l0_dash force(3*a - 2:3*a) = force(3*a - 2:3*a) + ten*t force(3*b - 2:3*b) = force(3*b - 2:3*b) - ten*t - kb = ten*(eye - outer3(t, t))/ell + (cb_ba_dash/cb_l0_dash)*outer3(t, MATMUL(eye - outer3(t, t), w)/ell) + kb = ten*(eye - outer3(t, t))/ell + (cb_ba_dash/cb_l0_dash)*outer3(t, MATMUL(eye - outer3(t, t), w)/ell) - & + (cb_ba_dash*cb_l0dot_dash/cb_l0_dash**2)*outer3(t, t) kv = (cb_ba_dash/cb_l0_dash)*outer3(t, t) jac_q(3*a - 2:3*a, 3*a - 2:3*a) = jac_q(3*a - 2:3*a, 3*a - 2:3*a) + kb jac_q(3*a - 2:3*a, 3*b - 2:3*b) = jac_q(3*a - 2:3*a, 3*b - 2:3*b) - kb @@ -871,7 +1006,7 @@ SUBROUTINE cb_added_mass(q, accel, M_add, dMa_a_dq, ErrStat, ErrMsg) END SUBROUTINE cb_added_mass SUBROUTINE probe_chain(qn, vn, an, q1, l0, ea, rho_a, banded, R, K, start_tension, start_stiffness, & - axial_damping) + axial_damping, start_load, start_l0, axial_l0_rate, start_l0_rate) !! Residual and effective tangent at q1 of the force-blended step of the chain with the !! callback load: banded (load_band_proc + load_force_proc) or dense (load_proc, with the !! added mass when cb_madd > 0). @@ -879,6 +1014,9 @@ SUBROUTINE probe_chain(qn, vn, an, q1, l0, ea, rho_a, banded, R, K, start_tensio LOGICAL, INTENT(IN) :: banded REAL(wp), INTENT(OUT) :: R(12), K(9, 9) REAL(wp), INTENT(IN), OPTIONAL :: start_tension(:), start_stiffness(:), axial_damping(:) + !! a length change over the step: the step-start load, lengths and rates, and the rates at + !! t_{n+1} (passed on to the step) + REAL(wp), INTENT(IN), OPTIONAL :: start_load(:), start_l0(:), axial_l0_rate(:), start_l0_rate(:) INTEGER :: conn(2, 3), n_iter, es REAL(wp) :: qo(12), vo(12), ao(12) LOGICAL :: converged, stalled @@ -892,19 +1030,22 @@ SUBROUTINE probe_chain(qn, vn, an, q1, l0, ea, rho_a, banded, R, K, start_tensio qo, vo, ao, converged, stalled, n_iter, es, em, load_band_proc=cb_load_band, & load_force_proc=cb_force, workspace=work, start_tension=start_tension, & start_stiffness=start_stiffness, axial_damping=axial_damping, & - probe_q=q1, probe_R=R, probe_K=K) + start_load=start_load, start_l0=start_l0, axial_l0_rate=axial_l0_rate, & + start_l0_rate=start_l0_rate, probe_q=q1, probe_R=R, probe_K=K) ELSE IF (cb_madd > 0.0_wp) THEN CALL CD_Cable_Gen_Alpha_Step(qn, vn, an, conn, l0, ea, rho_a, .TRUE., 0.0_wp*qn, [1, 2, 3], 0.05_wp, cfg, & qo, vo, ao, converged, stalled, n_iter, es, em, load_proc=cb_load, & added_mass_proc=cb_added_mass, workspace=work, start_tension=start_tension, & start_stiffness=start_stiffness, axial_damping=axial_damping, & - probe_q=q1, probe_R=R, probe_K=K) + start_load=start_load, start_l0=start_l0, axial_l0_rate=axial_l0_rate, & + start_l0_rate=start_l0_rate, probe_q=q1, probe_R=R, probe_K=K) ELSE CALL CD_Cable_Gen_Alpha_Step(qn, vn, an, conn, l0, ea, rho_a, .TRUE., 0.0_wp*qn, [1, 2, 3], 0.05_wp, cfg, & qo, vo, ao, converged, stalled, n_iter, es, em, load_proc=cb_load, & workspace=work, start_tension=start_tension, & start_stiffness=start_stiffness, axial_damping=axial_damping, & - probe_q=q1, probe_R=R, probe_K=K) + start_load=start_load, start_l0=start_l0, axial_l0_rate=axial_l0_rate, & + start_l0_rate=start_l0_rate, probe_q=q1, probe_R=R, probe_K=K) END IF IF (es /= CD_DYN_OK) THEN WRITE (*, '(A)') 'MISMATCH [chain:probe '//TRIM(em)//']' @@ -915,24 +1056,26 @@ SUBROUTINE probe_chain(qn, vn, an, q1, l0, ea, rho_a, banded, R, K, start_tensio END SUBROUTINE probe_chain SUBROUTINE fd_tangent_check(label, qn, vn, an, q1, l0, ea, rho_a, banded, start_tension, start_stiffness, & - axial_damping) + axial_damping, start_load, start_l0, axial_l0_rate, start_l0_rate) !! The step's tangent against the central difference of its residual. CHARACTER(*), INTENT(IN) :: label REAL(wp), INTENT(IN) :: qn(12), vn(12), an(12), q1(12), l0(3), ea(3), rho_a(3) LOGICAL, INTENT(IN) :: banded REAL(wp), INTENT(IN), OPTIONAL :: start_tension(:), start_stiffness(:), axial_damping(:) + REAL(wp), INTENT(IN), OPTIONAL :: start_load(:), start_l0(:), axial_l0_rate(:), start_l0_rate(:) REAL(wp), PARAMETER :: H = 1.0e-6_wp INTEGER :: j REAL(wp) :: qp(12), R(12), Rp(12), Rm(12), K(9, 9), Kfd(9, 9), Kdump(9, 9), err - CALL probe_chain(qn, vn, an, q1, l0, ea, rho_a, banded, R, K, start_tension, start_stiffness, axial_damping) + CALL probe_chain(qn, vn, an, q1, l0, ea, rho_a, banded, R, K, start_tension, start_stiffness, axial_damping, & + start_load, start_l0, axial_l0_rate, start_l0_rate) DO j = 1, 9 qp = q1 qp(3 + j) = q1(3 + j) + H CALL probe_chain(qn, vn, an, qp, l0, ea, rho_a, banded, Rp, Kdump, start_tension, start_stiffness, & - axial_damping) + axial_damping, start_load, start_l0, axial_l0_rate, start_l0_rate) qp(3 + j) = q1(3 + j) - H CALL probe_chain(qn, vn, an, qp, l0, ea, rho_a, banded, Rm, Kdump, start_tension, start_stiffness, & - axial_damping) + axial_damping, start_load, start_l0, axial_l0_rate, start_l0_rate) Kfd(:, j) = (Rp(4:12) - Rm(4:12))/(2.0_wp*H) END DO err = MAXVAL(ABS(K - Kfd))/MAXVAL(ABS(K)) @@ -976,6 +1119,7 @@ SUBROUTINE reset_chain_load() cb_ba_law = 0.0_wp cb_ba_dash = 0.0_wp cb_l0_dash = 1.0_wp + cb_l0dot_dash = 0.0_wp cb_dash_elem = 0 END SUBROUTINE reset_chain_load @@ -1199,6 +1343,252 @@ SUBROUTINE case_damped_elastic_release() CALL reset_chain_load() END SUBROUTINE case_damped_elastic_release + SUBROUTINE case_length_change_cap_terms() + !! The release cap under a length change of the end segment (active line control), hauled + !! in (0.82 to 0.8 m) and paid out (0.78 to 0.8 m), its rate changing too. Its step-start + !! quantities take the step-start length and rate (start_l0, start_l0_rate): e_n, T_n, W_n, + !! the secant T_n/e_n, the law stiffness k_n and the dashpot tension T_d,n; its end-state + !! quantities the new ones: e_{n+1}, T^_{n+1} = min(T_n/e_n, k_n) e_{n+1}, T_d,n+1 and the + !! dashpot weight phi (band l0 to l0 + c e_n). (a) An elastic segment with a two-sided + !! dashpot turning by 5 and 45 degrees and ending slack, in the band or above it: the change + !! the dashpot share makes to the cap against the closed form. (b) A damped law segment + !! (ea = 0) with a damping-dominated start: the cap against the closed form with the + !! bounded secant. (c) The elastic segment with a dashpot slack at the step-start length + !! (e_n = -2 mm against l0_c; on the haul-in pass taut against the new length), extending at + !! 0.5 m/s and turning by 5 to 135 degrees: the kept dashpot share against the closed form + !! (W_d + N_d)/p, W_d = T_d,n^2 dt l0_c/BA with T_d,n at l0_c and l0_dot_c, N_d from + !! T_d,n+1 at the new length and rate. The tangent against the finite difference on both + !! paths. + REAL(wp), PARAMETER :: L0(3) = [1.0_wp, 1.2_wp, 0.8_wp], EA(3) = [1.0e6_wp, 1.5e6_wp, 0.8e6_wp] + REAL(wp), PARAMETER :: DIRS(3, 3) = RESHAPE([1.0_wp, 0.2_wp, 0.1_wp, 0.3_wp, 1.0_wp, -0.2_wp, & + -0.2_wp, 0.4_wp, 1.0_wp], [3, 3]) + REAL(wp), PARAMETER :: THETA(2) = [5.0_wp, 45.0_wp] + REAL(wp), PARAMETER :: S1(6) = [-1.0e-3_wp, -1.0e-5_wp, 2.0e-4_wp, 6.0e-4_wp, 1.5e-3_wp, 3.0e-3_wp] + REAL(wp), PARAMETER :: DT = 0.05_wp, RHO = 0.4_wp, BA = 2.0e4_wp, EA_LAW = 0.8e6_wp, BA_LAW = 2.0e5_wp + REAL(wp), PARAMETER :: RHO_TINY(3) = [1.0e-12_wp, 1.0e-12_wp, 1.0e-12_wp] + REAL(wp) :: ls3, rs, rn, ls(3), qn(12), vn(12), z(12), q1(12), v1(12), sl(12), jq(12, 12), jv(12, 12) + REAL(wp) :: Ra(12), Rb(12), K(9, 9), tn(3), u(3), dir(3), d0(3), d1(3), t1(3), ln, l1, e0, e1, t0, w0 + REAL(wp) :: p, p1, k0, that, td0, td1, phi, kc, num, dg, du, dd, am, af, beta, gamma, band, err, worst + REAL(wp) :: kn, wd, nd, best, qbest(12) + REAL(wp), PARAMETER :: THETA_S(4) = [5.0_wp, 45.0_wp, 90.0_wp, 135.0_wp] + REAL(wp), PARAMETER :: OFS_S(7) = [-0.02_wp, -0.003_wp, 0.0_wp, 0.003_wp, 0.02_wp, 0.1_wp, 0.3_wp] + INTEGER :: ip, i, j, nact + LOGICAL :: damped + am = (2.0_wp*RHO - 1.0_wp)/(RHO + 1.0_wp) + af = RHO/(RHO + 1.0_wp) + beta = 0.25_wp*(1.0_wp - am + af)**2 + gamma = 0.5_wp - am + af + band = af/(1.0_wp - af) + z = 0.0_wp + DO ip = 1, 2 + ! pass 1 hauls in, pass 2 pays out + ls3 = MERGE(0.82_wp, 0.78_wp, ip == 1) + rs = MERGE(-0.02_wp, 0.02_wp, ip == 1) + rn = MERGE(-0.03_wp, 0.03_wp, ip == 1) + ls = [L0(1), L0(2), ls3] + ! (a) the elastic segment with a dashpot + CALL reset_chain_load() + cb_dash_elem = 3 + cb_ba_dash = BA + CALL chain_nodes(DIRS, [0.010_wp, 0.020_wp, 0.001_wp], ls, qn) + d0 = qn(10:12) - qn(7:9) + ln = NORM2(d0) + tn = d0/ln + u = [tn(2), -tn(1), 0.0_wp] + u = u/NORM2(u) + vn = 0.0_wp + vn(10:12) = 0.5_wp*tn + ! the step-start load at the step-start length and rate, then the dashpot at the new ones + cb_l0_dash = ls3 + cb_l0dot_dash = rs + CALL chain_load(qn, vn, sl, jq, jv) + cb_l0_dash = L0(3) + cb_l0dot_dash = rn + e0 = ln - ls3 + t0 = EA(3)*(ln/ls3 - 1.0_wp) + w0 = 0.5_wp*t0*e0 + td0 = BA*(DOT_PRODUCT(tn, vn(10:12) - vn(7:9)) - ln*rs/ls3)/ls3 + worst = 0.0_wp + nact = 0 + DO i = 1, SIZE(THETA) + DO j = 1, SIZE(S1) + dir = COS(THETA(i)*PI/180.0_wp)*tn + SIN(THETA(i)*PI/180.0_wp)*u + q1 = qn + q1(10:12) = qn(7:9) + L0(3)*(1.0_wp + S1(j))*dir + CALL probe_chain(qn, vn, z, q1, L0, EA, RHO_TINY, .TRUE., Ra, K, axial_damping=[0.0_wp, 0.0_wp, BA], & + start_load=sl, start_l0=ls, axial_l0_rate=[0.0_wp, 0.0_wp, rn], & + start_l0_rate=[0.0_wp, 0.0_wp, rs]) + CALL probe_chain(qn, vn, z, q1, L0, EA, RHO_TINY, .TRUE., Rb, K, start_load=sl, start_l0=ls) + ! the closed form of the two caps on the end segment + v1 = gamma/(beta*DT)*(q1 - qn) + (1.0_wp - gamma/beta)*vn + v1(1:3) = 0.0_wp + d1 = q1(10:12) - q1(7:9) + l1 = NORM2(d1) + t1 = d1/l1 + e1 = l1 - L0(3) + p = ln - DOT_PRODUCT(tn, d1) + p1 = l1 - DOT_PRODUCT(t1, d0) + k0 = t0/e0 + that = k0*MAX(e1, 0.0_wp) + du = 0.0_wp + IF (p > 0.0_wp) du = MIN(MAX(w0 + (1.0_wp - af)*that*p1, 0.0_wp)/p - af*t0, 0.0_wp) + dd = du + damped = l1 < L0(3) + band*e0 + IF (damped) THEN + dd = 0.0_wp + IF (p > 0.0_wp) THEN + phi = MIN(1.0_wp, MAX(0.0_wp, 1.0_wp - e1/(band*e0))) + td1 = BA*(DOT_PRODUCT(t1, v1(10:12) - v1(7:9)) - l1*rn/L0(3))/L0(3) + num = w0 + (1.0_wp - af)*(that + phi*td1)*p1 + kc = t0 + phi*td0 + dg = MAX(num, 0.0_wp)/p + dd = MIN(dg - af*kc, 0.0_wp) + END IF + END IF + IF (ABS(dd - du) > 1.0e-6_wp*t0) nact = nact + 1 + err = MAX(MAXVAL(ABS(Ra(10:12) - Rb(10:12) - (dd - du)*tn)), MAXVAL(ABS(Ra(7:9) - Rb(7:9) + (dd - du)*tn))) + worst = MAX(worst, err/(t0 + ABS(td0))) + END DO + END DO + WRITE (*, '(A,I0,A,I0,A,ES10.3)') ' length change, pass ', ip, ': dashpot share of the cap active at ', nact, & + ' states; largest deviation from the closed form / (T_n + |T_d,n|) ', worst + CALL require(nact >= 2, 'lengths-cap:dashpot-share-active') + CALL require(worst < 1.0e-9_wp, 'lengths-cap:dashpot-closed-form') + dir = COS(THETA(1)*PI/180.0_wp)*tn + SIN(THETA(1)*PI/180.0_wp)*u + q1 = qn + q1(10:12) = qn(7:9) + L0(3)*(1.0_wp + 2.0e-4_wp)*dir + DO i = 1, 2 + CALL fd_tangent_check('lengths-cap-dashpot', qn, vn, z, q1, L0, EA, [2.0_wp, 3.0_wp, 1.5_wp], i == 1, & + axial_damping=[0.0_wp, 0.0_wp, BA], start_load=sl, start_l0=ls, & + axial_l0_rate=[0.0_wp, 0.0_wp, rn], start_l0_rate=[0.0_wp, 0.0_wp, rs]) + END DO + ! (c) the dashpot segment slack at the step-start length + CALL reset_chain_load() + cb_dash_elem = 3 + cb_ba_dash = BA + CALL chain_nodes(DIRS, [0.010_wp, 0.020_wp, -2.0e-3_wp/ls3], ls, qn) + d0 = qn(10:12) - qn(7:9) + ln = NORM2(d0) + tn = d0/ln + u = [tn(2), -tn(1), 0.0_wp] + u = u/NORM2(u) + vn = 0.0_wp + vn(10:12) = 0.5_wp*tn + cb_l0_dash = ls3 + cb_l0dot_dash = rs + CALL chain_load(qn, vn, sl, jq, jv) + cb_l0_dash = L0(3) + cb_l0dot_dash = rn + CALL require(ln < ls3, 'lengths-cap:slack-start') + td0 = BA*(DOT_PRODUCT(tn, vn(10:12) - vn(7:9)) - ln*rs/ls3)/ls3 + wd = td0*td0*DT*ls3/BA + worst = 0.0_wp + nact = 0 + best = 0.0_wp + qbest = qn + DO i = 1, SIZE(THETA_S) + DO j = 1, SIZE(OFS_S) + dir = COS(THETA_S(i)*PI/180.0_wp)*tn + SIN(THETA_S(i)*PI/180.0_wp)*u + q1 = qn + q1(10:12) = qn(7:9) + MAX(ln*COS(THETA_S(i)*PI/180.0_wp) + OFS_S(j), 0.05_wp*L0(3))*dir + CALL probe_chain(qn, vn, z, q1, L0, EA, RHO_TINY, .TRUE., Ra, K, axial_damping=[0.0_wp, 0.0_wp, BA], & + start_load=sl, start_l0=ls, axial_l0_rate=[0.0_wp, 0.0_wp, rn], & + start_l0_rate=[0.0_wp, 0.0_wp, rs]) + CALL probe_chain(qn, vn, z, q1, L0, EA, RHO_TINY, .TRUE., Rb, K, start_load=sl, start_l0=ls) + v1 = gamma/(beta*DT)*(q1 - qn) + (1.0_wp - gamma/beta)*vn + v1(1:3) = 0.0_wp + d1 = q1(10:12) - q1(7:9) + l1 = NORM2(d1) + t1 = d1/l1 + p = ln - DOT_PRODUCT(tn, d1) + p1 = l1 - DOT_PRODUCT(t1, d0) + td1 = BA*(DOT_PRODUCT(t1, v1(10:12) - v1(7:9)) - l1*rn/L0(3))/L0(3) + nd = MAX((1.0_wp - af)*td1*p1, 0.0_wp) + dd = 0.0_wp + dg = 0.0_wp + IF (td0*p > 0.0_wp) THEN + dg = (wd + nd)/p + IF (ABS(dg) < af*ABS(td0)) dd = dg - af*td0 + END IF + IF (ABS(dd) > 1.0e-6_wp*ABS(td0)) nact = nact + 1 + IF (ABS(dd) > best .AND. ABS(dg) < 0.5_wp*af*ABS(td0) .AND. & + ABS((1.0_wp - af)*td1*p1) > 0.1_wp*wd) THEN + best = ABS(dd) + qbest = q1 + END IF + err = MAX(MAXVAL(ABS(Ra(10:12) - Rb(10:12) - dd*tn)), MAXVAL(ABS(Ra(7:9) - Rb(7:9) + dd*tn))) + worst = MAX(worst, err/ABS(td0)) + END DO + END DO + WRITE (*, '(A,I0,A,I0,A,I0,A,ES10.3)') ' length change, pass ', ip, ': slack-start dashpot cap active at ', & + nact, ' of ', SIZE(THETA_S)*SIZE(OFS_S), ' states; largest deviation from the closed form / |T_d,n| ', worst + CALL require(nact >= 4 .AND. best > 0.0_wp, 'lengths-cap:slack-dashpot-active') + CALL require(worst < 1.0e-9_wp, 'lengths-cap:slack-dashpot-closed-form') + DO i = 1, 2 + CALL fd_tangent_check('lengths-cap-slack-dashpot', qn, vn, z, qbest, L0, EA, [2.0_wp, 3.0_wp, 1.5_wp], & + i == 1, axial_damping=[0.0_wp, 0.0_wp, BA], start_load=sl, start_l0=ls, & + axial_l0_rate=[0.0_wp, 0.0_wp, rn], start_l0_rate=[0.0_wp, 0.0_wp, rs]) + END DO + ! (b) the damped law segment (ea = 0): T_n mostly damping at e_n = 1 um + CALL reset_chain_load() + cb_law_elem = 3 + cb_ea_law = EA_LAW + cb_ba_law = BA_LAW + CALL chain_nodes(DIRS, [0.010_wp, 0.020_wp, 1.0e-6_wp/ls3], ls, qn) + d0 = qn(10:12) - qn(7:9) + ln = NORM2(d0) + tn = d0/ln + u = [tn(2), -tn(1), 0.0_wp] + u = u/NORM2(u) + vn = 0.0_wp + vn(10:12) = 0.05_wp*tn + cb_l0_law = ls3 + CALL chain_load(qn, vn, sl, jq, jv) + cb_l0_law = L0(3) + t0 = DOT_PRODUCT(sl(7:9), tn) + e0 = ln - ls3 + w0 = 0.5_wp*t0*e0 + kn = EA_LAW/ls3 + k0 = MIN(t0/e0, kn) + CALL require(t0/e0 > 1.0e3_wp*kn, 'lengths-cap:law-damping-dominated-start') + worst = 0.0_wp + nact = 0 + dir = COS(PI/4.0_wp)*tn + SIN(PI/4.0_wp)*u + DO j = 1, SIZE(S1) + q1 = qn + q1(10:12) = qn(7:9) + L0(3)*(1.0_wp + S1(j))*dir + CALL probe_chain(qn, vn, z, q1, L0, [EA(1), EA(2), 0.0_wp], RHO_TINY, .TRUE., Ra, K, & + start_tension=[0.0_wp, 0.0_wp, t0], start_stiffness=[0.0_wp, 0.0_wp, kn], start_load=sl, & + start_l0=ls) + CALL probe_chain(qn, vn, z, q1, L0, [EA(1), EA(2), 0.0_wp], RHO_TINY, .TRUE., Rb, K, start_load=sl, start_l0=ls) + d1 = q1(10:12) - q1(7:9) + l1 = NORM2(d1) + t1 = d1/l1 + e1 = l1 - L0(3) + p = ln - DOT_PRODUCT(tn, d1) + p1 = l1 - DOT_PRODUCT(t1, d0) + that = k0*MAX(e1, 0.0_wp) + dd = 0.0_wp + IF (p > 0.0_wp) dd = MIN(MAX(w0 + (1.0_wp - af)*that*p1, 0.0_wp)/p - af*t0, 0.0_wp) + IF (ABS(dd) > 1.0e-6_wp*t0) nact = nact + 1 + err = MAX(MAXVAL(ABS(Ra(10:12) - Rb(10:12) - dd*tn)), MAXVAL(ABS(Ra(7:9) - Rb(7:9) + dd*tn))) + worst = MAX(worst, err/t0) + END DO + WRITE (*, '(A,I0,A,I0,A,ES10.3)') ' length change, pass ', ip, ': law cap active at ', nact, & + ' states; largest deviation from the closed form / T_n ', worst + CALL require(nact >= 4, 'lengths-cap:law-active') + CALL require(worst < 1.0e-9_wp, 'lengths-cap:law-closed-form') + q1 = qn + q1(10:12) = qn(7:9) + L0(3)*(1.0_wp + 6.0e-4_wp)*dir + DO i = 1, 2 + CALL fd_tangent_check('lengths-cap-law', qn, vn, z, q1, L0, [EA(1), EA(2), 0.0_wp], [2.0_wp, 3.0_wp, 1.5_wp], & + i == 1, start_tension=[0.0_wp, 0.0_wp, t0], start_stiffness=[0.0_wp, 0.0_wp, kn], & + start_load=sl, start_l0=ls) + END DO + END DO + CALL reset_chain_load() + END SUBROUTINE case_length_change_cap_terms + SUBROUTINE damped_tangent_case(label, qn, vn, q1, l0, ea, ad, t0) !! The damped chain of case_damped_elastic_release at one trial state where the cap acts: !! the cap is active, and the tangent matches the finite difference on both paths. diff --git a/tests/test_hermite_axial_damping.f90 b/tests/test_hermite_axial_damping.f90 index e78e4fce..fc33ca19 100644 --- a/tests/test_hermite_axial_damping.f90 +++ b/tests/test_hermite_axial_damping.f90 @@ -4,8 +4,10 @@ PROGRAM test_hermite_axial_damping !! Axial Kelvin-Voigt damping on the finite-EI Hermite cable. The gates cover the !! analytical straight-element limit, rigid-body invariance, positive dissipation, - !! exact position/velocity Jacobians, and the transactional model setter. + !! exact position/velocity Jacobians, the unstretched-length rate of active line + !! control, and the transactional model setter. USE CableDyn_Precision, ONLY: wp + USE CableDyn_HermiteCable, ONLY: CD_HermiteCable_Axial_Resultant USE CableDyn_HermiteCableDynamic, ONLY: CD_HermiteCableDynType, CD_HermiteCable_Dyn_End_Force, & CD_HermiteCable_Axial_Damping_Element, & CD_HermiteCable_Axial_Damping_Resultant, & @@ -23,6 +25,7 @@ PROGRAM test_hermite_axial_damping nfail = 0 CALL check_straight_limit() CALL check_jacobians_and_dissipation() + CALL check_length_rate() CALL check_setter_lifecycle() IF (nfail > 0) THEN WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed' @@ -120,6 +123,95 @@ SUBROUTINE check_jacobians_and_dissipation() 'velocity Jacobian is symmetric') END SUBROUTINE check_jacobians_and_dissipation + SUBROUTINE check_length_rate() + !! Active line control: with an unstretched-length rate l0_dot the damped strain rate is + !! the time derivative of the strain |r_xi|/l0 - 1 the elastic resultant uses, along + !! q + v t and l0 + l0_dot t. Gates: a straight element paid out at constant strain + !! carries no damping force; the viscous resultant matches the central difference of that + !! strain; a zero rate reproduces the uncontrolled element; and the position and velocity + !! Jacobians with a rate match central differences. + REAL(wp), PARAMETER :: l0 = 2.2_wp, ba = 3.7e4_wp, ldot = 0.37_wp, stretch = 1.004_wp + REAL(wp), PARAMETER :: xs(3) = [0.0_wp, 0.31_wp, 0.83_wp] + REAL(wp) :: qe(12), ve(12), qp(12), qm(12), vp(12), vm(12) + REAL(wp) :: f(12), f0(12), fp(12), fm(12), kq(12, 12), kv(12, 12), kq0(12, 12), kv0(12, 12) + REAL(wp) :: kqfd(12, 12), kvfd(12, 12) + REAL(wp) :: td, sp, sm, h, errq, errv, scaleq, scalev, rate_fd + INTEGER :: es, j, k + CHARACTER(300) :: em + + ! (a) constant-strain pay-out: r_2 moves with the growing reference at the element's + ! stretch and the tangents keep it, so the strain does not change anywhere + qe = [0.0_wp, 0.0_wp, 0.0_wp, stretch, 0.0_wp, 0.0_wp, & + stretch*l0, 0.0_wp, 0.0_wp, stretch, 0.0_wp, 0.0_wp] + ve = 0.0_wp + ve(7) = stretch*ldot + CALL CD_HermiteCable_Axial_Damping_Element(qe, ve, l0, ba, f, kq, kv, es, em, l0_dot=ldot) + CALL require(es == CD_HCDYN_OK, 'pay-out element accepted: '//TRIM(em)) + CALL require(nan_max_abs(f) <= 1.0e-12_wp*ba*ldot/l0, & + 'a straight element paid out at constant strain carries no damping force') + DO k = 1, SIZE(xs) + CALL CD_HermiteCable_Axial_Damping_Resultant(qe, ve, l0, ba, xs(k), td, es, em, l0_dot=ldot) + CALL require(es == CD_HCDYN_OK .AND. ABS(td) <= 1.0e-12_wp*ba*ldot/l0, & + 'constant-strain pay-out has no viscous resultant') + END DO + ! without the rate the end velocity reads as stretch: strain rate dH_3 stretch ldot/l0, + ! so f_r2 = BA stretch ldot/l0 times the integral of dH_3**2 = 36 x**2 (1 - x)**2, 6/5 + CALL CD_HermiteCable_Axial_Damping_Element(qe, ve, l0, ba, f, ErrStat=es, ErrMsg=em) + CALL require(ABS(f(7) - 1.2_wp*ba*stretch*ldot/l0) <= 1.0e-12_wp*ba*ldot/l0, & + 'without the rate the same motion reads as a stretching dashpot') + + ! (b) the resultant is BA times the time derivative of the strain along the motion + qe = [0.10_wp, -0.20_wp, 0.30_wp, 0.90_wp, 0.20_wp, 0.15_wp, & + 2.30_wp, 0.50_wp, 0.80_wp, 0.70_wp, -0.10_wp, 0.25_wp] + ve = [0.12_wp, -0.04_wp, 0.03_wp, 0.02_wp, 0.01_wp, -0.03_wp, & + -0.06_wp, 0.08_wp, 0.05_wp, -0.01_wp, 0.04_wp, 0.02_wp] + h = 1.0e-6_wp + DO k = 1, SIZE(xs) + CALL CD_HermiteCable_Axial_Resultant(qe + h*ve, l0 + h*ldot, 1.0_wp, xs(k), sp, es, em) + CALL CD_HermiteCable_Axial_Resultant(qe - h*ve, l0 - h*ldot, 1.0_wp, xs(k), sm, es, em) + rate_fd = (sp - sm)/(2.0_wp*h) + CALL CD_HermiteCable_Axial_Damping_Resultant(qe, ve, l0, ba, xs(k), td, es, em, l0_dot=ldot) + CALL require(es == CD_HCDYN_OK .AND. ABS(td - ba*rate_fd) <= 1.0e-7_wp*ba*MAX(ABS(rate_fd), 1.0e-3_wp), & + 'the controlled viscous resultant is BA times the strain rate along q(t), l0(t)') + END DO + + ! (c) a zero rate is the uncontrolled element + CALL CD_HermiteCable_Axial_Damping_Element(qe, ve, l0, ba, f0, kq0, kv0, es, em, 6) + CALL CD_HermiteCable_Axial_Damping_Element(qe, ve, l0, ba, f, kq, kv, es, em, 6, 0.0_wp) + CALL require(nan_max_abs(f - f0) <= 0.0_wp .AND. nan_max_abs(kq - kq0) <= 0.0_wp .AND. & + nan_max_abs(kv - kv0) <= 0.0_wp, 'a zero length rate reproduces the uncontrolled element') + + ! (d) Jacobians with a rate against central differences + CALL CD_HermiteCable_Axial_Damping_Element(qe, ve, l0, ba, f, kq, kv, es, em, 6, ldot) + CALL require(es == CD_HCDYN_OK, 'controlled curved element accepted: '//TRIM(em)) + CALL require(nan_max_abs(kq - kq0) > 1.0e-3_wp*nan_max_abs(kq0), 'the length rate enters the position Jacobian') + DO j = 1, 12 + h = 2.0e-7_wp*MAX(1.0_wp, ABS(qe(j))) + qp = qe; qm = qe + qp(j) = qp(j) + h; qm(j) = qm(j) - h + CALL CD_HermiteCable_Axial_Damping_Element(qp, ve, l0, ba, fp, ErrStat=es, ErrMsg=em, & + quadrature_order=6, l0_dot=ldot) + CALL CD_HermiteCable_Axial_Damping_Element(qm, ve, l0, ba, fm, ErrStat=es, ErrMsg=em, & + quadrature_order=6, l0_dot=ldot) + kqfd(:, j) = (fp - fm)/(2.0_wp*h) + h = 2.0e-7_wp*MAX(1.0_wp, ABS(ve(j))) + vp = ve; vm = ve + vp(j) = vp(j) + h; vm(j) = vm(j) - h + CALL CD_HermiteCable_Axial_Damping_Element(qe, vp, l0, ba, fp, ErrStat=es, ErrMsg=em, & + quadrature_order=6, l0_dot=ldot) + CALL CD_HermiteCable_Axial_Damping_Element(qe, vm, l0, ba, fm, ErrStat=es, ErrMsg=em, & + quadrature_order=6, l0_dot=ldot) + kvfd(:, j) = (fp - fm)/(2.0_wp*h) + END DO + scaleq = MAX(1.0_wp, nan_max_abs(kqfd)) + scalev = MAX(1.0_wp, nan_max_abs(kvfd)) + errq = nan_max_abs(kq - kqfd)/scaleq + errv = nan_max_abs(kv - kvfd)/scalev + WRITE (*, '(A,ES10.3,A,ES10.3)') ' controlled damping Jacobian relative errors: q=', errq, ' v=', errv + CALL require(errq < 2.0e-7_wp, 'controlled position Jacobian matches central differences') + CALL require(errv < 2.0e-8_wp, 'controlled velocity Jacobian matches central differences') + END SUBROUTINE check_length_rate + SUBROUTINE check_setter_lifecycle() TYPE(CD_HermiteCableDynType) :: model TYPE(CD_HFMF_ModuleType), ALLOCATABLE :: cables(:) diff --git a/tests/test_hermite_cable_control.f90 b/tests/test_hermite_cable_control.f90 new file mode 100644 index 00000000..8de7669a --- /dev/null +++ b/tests/test_hermite_cable_control.f90 @@ -0,0 +1,688 @@ +! File: tests/test_hermite_cable_control.f90 +! SPDX-License-Identifier: Apache-2.0 +! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +PROGRAM test_hermite_cable_control + !! Active line control of a finite-EI (cubic-Hermite) cable, + !! CD_HermiteCable_Dyn_Set_SegmentLength: + !! A the update is inert when nothing changes (a rate of -0 included), rebuilds every + !! length-dependent cache to what a model built with the new lengths carries (bit for + !! bit), leaves the committed lengths to a re-derived acceleration, is atomic on + !! failure, refuses a torsion line, a contact line without the seabed recompute inputs + !! and the configuration blend, is taken back exactly by a saved control state, and + !! joins the snapshot/restore contract exactly; + !! B a hanging vertical cable whose top span is paid out settles to the top reaction + !! w (L + DeltaL) and the stretched length L' + w L'**2/(2 EA); + !! C a taut vertical cable whose top span is hauled in settles to the top tension + !! EA (H - L')/L' + w L'/2; + !! D a weightless taut cable paid out at a constant rate Ldot carries the Kelvin-Voigt + !! tension EA (H/L' - 1) - BA H Ldot/L'**2 (without the length rate it does not); + !! E a slack cable whose top span is ramped slowly ends at the static equilibrium of the + !! edited lengths; + !! F the cable of D paid out at a constant rate under the force-blended generalised-alpha + !! with alpha_f > 0 carries the same tension as with alpha_f = 0, the closed form of D, + !! also when the committed force is evaluated afresh each step rather than reused: the + !! committed force of each step belongs to the lengths it was reached with. + !! The axial cases B-D and F hold every transverse DOF, so the closed forms are exact for the + !! cubic-Hermite element (linear tension, quadratic displacement); the transient is damped + !! by BA. A, D and E run at rho_inf = 0; B and C at rho_inf = 0 and 0.4, C also comparing the + !! two through the ramp (the lag check of a line with weight). + USE CableDyn_Precision, ONLY: wp + USE CableDyn_HermiteCableDynamic, ONLY: CD_HermiteCableDynType, CD_HermiteCable_Dyn_Init, & + CD_HermiteCable_Dyn_Step, CD_HermiteCable_Dyn_Reaction, & + CD_HermiteCable_Dyn_Set_SegmentLength, & + CD_HermiteCable_Dyn_Set_Control_Seabed, & + CD_HermiteCable_Dyn_Set_Contact, CD_HermiteCable_Dyn_Set_Attachments, & + CD_HermiteCable_Dyn_Set_Axial_Damping, CD_HermiteCable_Dyn_Set_Drag, & + CD_HermiteCable_Dyn_Recompute_Acceleration, & + CD_HermiteCable_Dyn_Snapshot, CD_HermiteCable_Dyn_Restore, & + CD_HermiteCable_Dyn_Set_ForceBlend, CD_HermiteCableControlSaveType, & + CD_HermiteCable_Dyn_Save_Control, CD_HermiteCable_Dyn_Restore_Control, & + CD_HermiteCable_Dyn_End, CD_HCDYN_OK + USE CableDyn_HermiteCableStatic, ONLY: CD_HermiteCable_Static_Solve, CD_HCSTAT_OK + USE CableDyn_Line, ONLY: CD_Nodal_Seabed_Stiffness, CD_LINE_OK + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: INT64 + IMPLICIT NONE + + REAL(wp), PARAMETER :: PI = 3.14159265358979323846_wp + INTEGER :: nfail + + nfail = 0 + CALL check_model_contract() + CALL check_hanging_payout() + CALL check_taut_haul_in() + CALL check_payout_rate_lag() + CALL check_slow_ramp_static() + CALL check_payout_alpha_f() + IF (nfail > 0) THEN + WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed' + ERROR STOP 1 + END IF + WRITE (*, '(A)') 'PASS: finite-EI active line control (caches, rewind, closed forms, static end state)' + +CONTAINS + + INCLUDE 'nan_max_abs.inc' + + ! ------------------------------------------------------------------------------------------ + SUBROUTINE check_model_contract() + !! A: a seabed cable with friction, attachments and axial damping. + INTEGER, PARAMETER :: NE = 8, NN = NE + 1, NDOF = 6*NN + REAL(wp), PARAMETER :: L = 1.5_wp, KBOT = 1.0e5_wp, CBOT = 1.0e4_wp, ZBED = -20.0_wp, DT = 0.01_wp + TYPE(CD_HermiteCableDynType) :: a, b, ref, twin + REAL(wp) :: l0(NE), l0b(NE), q(NDOF), diam(NE), lam + INTEGER, PARAMETER :: SPAN(2) = [7, 8] + INTEGER :: i, es, k + CHARACTER(300) :: em + + l0 = L + diam = 0.1_wp + q = 0.0_wp + DO i = 1, NN + q(6*(i - 1) + 1) = REAL(i - 1, wp)*L + q(6*(i - 1) + 3) = ZBED + q(6*(i - 1) + 4) = 1.0_wp + END DO + CALL build_bed_model(a, l0, q, diam, KBOT, CBOT, ZBED, es, em) + CALL require(es == CD_HCDYN_OK, 'A: seabed model: '//TRIM(em)) + IF (es /= CD_HCDYN_OK) RETURN + + ! inert: a command that changes nothing leaves the model untouched and uncontrolled + twin = a + CALL CD_HermiteCable_Dyn_Set_SegmentLength(a, SPAN, a%l0(SPAN), [0.0_wp, 0.0_wp], es, em) + CALL require(es == CD_HCDYN_OK .AND. .NOT. a%has_ctrl .AND. .NOT. ALLOCATED(a%l0_dot), & + 'A: an unchanged length and zero rate leave the model uncontrolled') + CALL require(same_bits2(a%Mgb, twin%Mgb) .AND. same_bits(a%l0, twin%l0) .AND. & + (a%fc_valid .EQV. twin%fc_valid), 'A: the inert call writes nothing') + DO k = 1, 3 + CALL CD_HermiteCable_Dyn_Step(a, DT, 50, 1.0e-10_wp, es, em) + CALL require(es == CD_HCDYN_OK, 'A: inert step: '//TRIM(em)) + CALL CD_HermiteCable_Dyn_Step(twin, DT, 50, 1.0e-10_wp, es, em) + END DO + CALL require(same_bits(a%q, twin%q) .AND. same_bits(a%v, twin%v) .AND. same_bits(a%a, twin%a), & + 'A: steps after the inert call are bit-identical to a never-controlled twin') + ! a rate of -0 (a host's negated zero) counts as +0: still inert + CALL CD_HermiteCable_Dyn_Set_SegmentLength(a, SPAN, a%l0(SPAN), [SIGN(0.0_wp, -1.0_wp), SIGN(0.0_wp, -1.0_wp)], & + es, em) + CALL require(es == CD_HCDYN_OK .AND. .NOT. a%has_ctrl .AND. .NOT. ALLOCATED(a%l0_dot), & + 'A: a rate of -0 leaves the model uncontrolled') + ! the configuration blend has no committed-length treatment: refused by name + CALL CD_HermiteCable_Dyn_Set_ForceBlend(twin, .FALSE., es, em) + CALL require(es == CD_HCDYN_OK, 'A: twin on the configuration blend') + CALL CD_HermiteCable_Dyn_Set_SegmentLength(twin, SPAN, 1.1_wp*twin%l0(SPAN), [0.0_wp, 0.0_wp], es, em) + CALL require(es /= CD_HCDYN_OK .AND. INDEX(em, 'force blend') > 0 .AND. .NOT. twin%has_ctrl, & + 'A: the configuration blend fails closed by name') + CALL CD_HermiteCable_Dyn_End(twin) + + ! rebuild = fresh init: lengthen the trailing span, then build a model with those lengths + CALL CD_HermiteCable_Dyn_End(a) + CALL build_bed_model(a, l0, q, diam, KBOT, CBOT, ZBED, es, em) + lam = 1.3_wp + CALL CD_HermiteCable_Dyn_Set_SegmentLength(a, SPAN, lam*l0(SPAN), [0.0_wp, 0.0_wp], es, em) + CALL require(es == CD_HCDYN_OK .AND. a%has_ctrl, 'A: span lengthened: '//TRIM(em)) + CALL require(.NOT. a%tr_valid .AND. same_bits(a%l0_c, l0) .AND. ALL(a%l0_dot_c == 0.0_wp), & + 'A: a length change drops the carried factor; the committed state keeps its lengths') + l0b = l0 + l0b(SPAN) = lam*l0(SPAN) + CALL build_bed_model(b, l0b, q, diam, KBOT, CBOT, ZBED, es, em) + CALL require(es == CD_HCDYN_OK, 'A: fresh model at the new lengths: '//TRIM(em)) + CALL require(same_bits(a%l0, b%l0), 'A: lengths equal a fresh build') + CALL require(same_bits2(a%Mgb, b%Mgb), 'A: constant mass with attachments equals a fresh build bit for bit') + CALL require(same_bits(a%trib, b%trib), 'A: tributary lengths equal a fresh build bit for bit') + CALL require(same_bits(a%contact_kn, b%contact_kn) .AND. same_bits(a%contact_cn, b%contact_cn), & + 'A: nodal seabed coefficients equal a fresh build bit for bit') + CALL require(same_bits(a%fr_k, b%fr_k), 'A: friction spring stiffness equals a fresh build bit for bit') + ! a non-stepping re-derivation of the committed acceleration between the command and the + ! step belongs to the committed state: it is solved at the lengths that state was reached + ! with, which stay the committed ones, so it equals the acceleration of a model that was + ! never commanded, the committed force cache survives, and the new lengths stay in place + twin = a + CALL build_bed_model(ref, l0, q, diam, KBOT, CBOT, ZBED, es, em) + CALL CD_HermiteCable_Dyn_Recompute_Acceleration(ref, es, em) + CALL CD_HermiteCable_Dyn_Recompute_Acceleration(a, es, em) + CALL require(es == CD_HCDYN_OK .AND. same_bits(a%a, ref%a) .AND. same_bits(a%l0_c, l0) .AND. & + ALL(a%l0_dot_c == 0.0_wp) .AND. (a%fc_valid .EQV. twin%fc_valid) .AND. unchanged(a, twin), & + 'A: a re-derived acceleration belongs to the committed lengths, which stay committed') + CALL CD_HermiteCable_Dyn_End(ref) + CALL CD_HermiteCable_Dyn_End(twin) + ! once the new lengths are committed (restored = .TRUE., as a checkpoint restart does), + ! the re-derived acceleration is the fresh model's and the two models step identically + CALL CD_HermiteCable_Dyn_Set_SegmentLength(a, SPAN, lam*l0(SPAN), [0.0_wp, 0.0_wp], es, em, restored=.TRUE.) + CALL require(es == CD_HCDYN_OK .AND. same_bits(a%l0_c, a%l0), 'A: restored = .TRUE. commits the lengths') + CALL CD_HermiteCable_Dyn_Recompute_Acceleration(a, es, em) + CALL require(es == CD_HCDYN_OK .AND. nan_max_abs(a%a - b%a) <= 0.0_wp, & + 'A: at committed new lengths the re-derived acceleration equals the fresh model''s') + DO k = 1, 3 + CALL CD_HermiteCable_Dyn_Step(a, DT, 50, 1.0e-10_wp, es, em) + CALL require(es == CD_HCDYN_OK, 'A: controlled step: '//TRIM(em)) + CALL CD_HermiteCable_Dyn_Step(b, DT, 50, 1.0e-10_wp, es, em) + CALL require(es == CD_HCDYN_OK, 'A: fresh-model step: '//TRIM(em)) + END DO + CALL require(nan_max_abs(a%q - b%q) <= 0.0_wp .AND. nan_max_abs(a%v - b%v) <= 0.0_wp, & + 'A: the controlled model marches exactly as one built with the new lengths') + CALL CD_HermiteCable_Dyn_End(b) + + ! a rate-only change rebuilds nothing and keeps the committed force (it belongs to the + ! committed rates, which stay) + ref = a + CALL CD_HermiteCable_Dyn_Set_SegmentLength(a, SPAN, a%l0(SPAN), [0.05_wp, 0.05_wp], es, em) + CALL require(es == CD_HCDYN_OK .AND. same_bits2(a%Mgb, ref%Mgb) .AND. same_bits(a%l0, ref%l0) .AND. & + a%fc_valid .AND. same_bits(a%fc_R, ref%fc_R) .AND. ALL(a%l0_dot_c == 0.0_wp) .AND. & + ALL(a%l0_dot(SPAN) == 0.05_wp) .AND. ALL(a%l0_dot(1:6) == 0.0_wp), & + 'A: a rate-only change keeps the caches and records the rate on the span') + + ! a controlled model keeps the force blend + CALL CD_HermiteCable_Dyn_Set_ForceBlend(a, .FALSE., es, em) + CALL require(es /= CD_HCDYN_OK .AND. a%force_blend, 'A: the force blend of a controlled model stays on') + + ! a saved control state takes a command back bit for bit, the carried-factor flag included + BLOCK + TYPE(CD_HermiteCableControlSaveType) :: saved + LOGICAL :: tr_before + ref = a + tr_before = a%tr_valid + CALL CD_HermiteCable_Dyn_Save_Control(a, saved) + CALL CD_HermiteCable_Dyn_Set_SegmentLength(a, SPAN, 0.7_wp*a%l0(SPAN), [-0.3_wp, -0.3_wp], es, em, & + restored=.TRUE.) + CALL require(es == CD_HCDYN_OK .AND. .NOT. unchanged(a, ref), 'A: a command to take back') + CALL CD_HermiteCable_Dyn_Restore_Control(a, saved, es, em) + CALL require(es == CD_HCDYN_OK .AND. unchanged(a, ref) .AND. same_bits(a%l0_c, ref%l0_c) .AND. & + same_bits(a%l0_dot_c, ref%l0_dot_c) .AND. (a%tr_valid .EQV. tr_before), & + 'A: the saved control state takes the command back bit for bit') + ! on a model that was never controlled, the restore drops the control storage again + CALL build_bed_model(twin, l0, q, diam, KBOT, CBOT, ZBED, es, em) + ref = twin + CALL CD_HermiteCable_Dyn_Save_Control(twin, saved) + CALL CD_HermiteCable_Dyn_Set_SegmentLength(twin, SPAN, 1.2_wp*l0(SPAN), [0.1_wp, 0.1_wp], es, em) + CALL CD_HermiteCable_Dyn_Restore_Control(twin, saved, es, em) + CALL require(es == CD_HCDYN_OK .AND. unchanged(twin, ref) .AND. .NOT. ALLOCATED(twin%l0_dot), & + 'A: taking back the first command restores the uncontrolled model') + CALL CD_HermiteCable_Dyn_End(twin) + CALL CD_HermiteCable_Dyn_End(ref) + END BLOCK + + ! atomic failure: nothing is written + ref = a + CALL CD_HermiteCable_Dyn_Set_SegmentLength(a, [7, 9], [1.0_wp, 1.0_wp], [0.0_wp, 0.0_wp], es, em) + CALL require(es /= CD_HCDYN_OK .AND. unchanged(a, ref), 'A: an out-of-range element fails and writes nothing') + CALL CD_HermiteCable_Dyn_Set_SegmentLength(a, [8, 7], [1.0_wp, 1.0_wp], [0.0_wp, 0.0_wp], es, em) + CALL require(es /= CD_HCDYN_OK .AND. unchanged(a, ref), 'A: unordered elements fail and write nothing') + CALL CD_HermiteCable_Dyn_Set_SegmentLength(a, SPAN, [1.0_wp, -1.0_wp], [0.0_wp, 0.0_wp], es, em) + CALL require(es /= CD_HCDYN_OK .AND. unchanged(a, ref), 'A: a non-positive length fails and writes nothing') + twin = a + twin%torsion%active = .TRUE. + CALL CD_HermiteCable_Dyn_Set_SegmentLength(twin, SPAN, [1.0_wp, 1.0_wp], [0.0_wp, 0.0_wp], es, em) + CALL require(es /= CD_HCDYN_OK .AND. INDEX(em, 'torsion') > 0, 'A: a line restrained in torsion fails closed') + twin%torsion%active = .FALSE. + twin%has_seabed_recompute = .FALSE. + CALL CD_HermiteCable_Dyn_Set_SegmentLength(twin, SPAN, [1.0_wp, 1.0_wp], [0.0_wp, 0.0_wp], es, em) + CALL require(es /= CD_HCDYN_OK .AND. INDEX(em, 'seabed recompute') > 0, & + 'A: a contact line without the seabed recompute inputs fails closed') + CALL CD_HermiteCable_Dyn_End(twin) + CALL CD_HermiteCable_Dyn_Set_Control_Seabed(a, 2.0_wp*KBOT, diam, CBOT/KBOT, es, em) + CALL require(es /= CD_HCDYN_OK .AND. INDEX(em, 'do not reproduce') > 0 .AND. a%seabed_kbot == KBOT, & + 'A: seabed recompute inputs that do not reproduce the installed coefficients fail') + + ! snapshot/restore: a later command and step roll back exactly, caches included + ref = a + CALL CD_HermiteCable_Dyn_Snapshot(a, es, em) + CALL require(es == CD_HCDYN_OK, 'A: snapshot: '//TRIM(em)) + CALL CD_HermiteCable_Dyn_Set_SegmentLength(a, SPAN, 0.8_wp*a%l0(SPAN), [-0.1_wp, -0.1_wp], es, em) + CALL require(es == CD_HCDYN_OK, 'A: command after the snapshot: '//TRIM(em)) + CALL CD_HermiteCable_Dyn_Step(a, DT, 50, 1.0e-10_wp, es, em) + CALL require(es == CD_HCDYN_OK, 'A: step after the command: '//TRIM(em)) + CALL CD_HermiteCable_Dyn_Restore(a, es, em) + CALL require(es == CD_HCDYN_OK, 'A: restore: '//TRIM(em)) + CALL require(unchanged(a, ref) .AND. same_bits(a%l0_dot, ref%l0_dot) .AND. same_bits(a%q, ref%q) .AND. & + same_bits(a%v, ref%v) .AND. same_bits(a%a, ref%a) .AND. same_bits2(a%fr_anchor, ref%fr_anchor), & + 'A: restore brings back the lengths, rates, caches and state bit for bit') + DO k = 1, 3 + CALL CD_HermiteCable_Dyn_Step(a, DT, 50, 1.0e-10_wp, es, em) + CALL CD_HermiteCable_Dyn_Step(ref, DT, 50, 1.0e-10_wp, es, em) + END DO + CALL require(es == CD_HCDYN_OK .AND. same_bits(a%q, ref%q) .AND. same_bits(a%v, ref%v), & + 'A: the restored model marches bit-identically to an untouched copy') + CALL CD_HermiteCable_Dyn_End(ref) + CALL CD_HermiteCable_Dyn_End(a) + + ! a snapshot taken before any command restores the uncontrolled model + CALL build_bed_model(a, l0, q, diam, KBOT, CBOT, ZBED, es, em) + ref = a + CALL CD_HermiteCable_Dyn_Snapshot(a, es, em) + CALL CD_HermiteCable_Dyn_Set_SegmentLength(a, SPAN, 1.5_wp*l0(SPAN), [0.2_wp, 0.2_wp], es, em) + CALL CD_HermiteCable_Dyn_Restore(a, es, em) + CALL require(es == CD_HCDYN_OK .AND. .NOT. a%has_ctrl .AND. unchanged(a, ref), & + 'A: restoring a pre-control snapshot gives back the uncontrolled model') + CALL CD_HermiteCable_Dyn_End(ref) + CALL CD_HermiteCable_Dyn_End(a) + END SUBROUTINE check_model_contract + + SUBROUTINE build_bed_model(model, l0, q, diam, kbot, cbot, zbed, ErrStat, ErrMsg) + !! A cable laid on a flat bed: nodal contact with friction, axial damping and two + !! attachments, set up in the order of the deck builder. + TYPE(CD_HermiteCableDynType), INTENT(OUT) :: model + REAL(wp), INTENT(IN) :: l0(:), q(:), diam(:), kbot, cbot, zbed + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), ALLOCATABLE :: kn(:), cn(:) + INTEGER :: ne, ndof, k + ne = SIZE(l0) + ndof = 6*(ne + 1) + CALL CD_HermiteCable_Dyn_Init(model, l0, [(1.0e6_wp, k=1, ne)], [(100.0_wp, k=1, ne)], [(5.0_wp, k=1, ne)], & + [(30.0_wp, k=1, ne)], q, [1, 2, 3, ndof - 5, ndof - 4, ndof - 3], zbed, 0.0_wp, & + 0.5_wp, ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) RETURN + CALL CD_HermiteCable_Dyn_Set_Axial_Damping(model, [(2.0e4_wp, k=1, ne)], ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) RETURN + CALL CD_Nodal_Seabed_Stiffness(kbot, diam, l0, kn, ErrStat, ErrMsg) + IF (ErrStat /= CD_LINE_OK) RETURN + cn = kn*(cbot/kbot) + CALL CD_HermiteCable_Dyn_Set_Contact(model, kn, cn, 0.3_wp, ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) RETURN + CALL CD_HermiteCable_Dyn_Set_Control_Seabed(model, kbot, diam, cbot/kbot, ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) RETURN + CALL CD_HermiteCable_Dyn_Set_Attachments(model, [3, ne], [50.0_wp, 20.0_wp], [0.01_wp, 0.02_wp], & + [0.1_wp, 0.0_wp], [0.05_wp, 0.0_wp], [1.0_wp, 0.5_wp], & + 1025.0_wp, 9.80665_wp, ErrStat, ErrMsg) + END SUBROUTINE build_bed_model + + LOGICAL FUNCTION unchanged(m, r) RESULT(same) + !! Every length-dependent field of m equals that of r bit for bit. + TYPE(CD_HermiteCableDynType), INTENT(IN) :: m, r + same = same_bits(m%l0, r%l0) .AND. same_bits2(m%Mgb, r%Mgb) .AND. same_bits(m%trib, r%trib) .AND. & + same_bits(m%contact_kn, r%contact_kn) .AND. same_bits(m%contact_cn, r%contact_cn) .AND. & + same_bits(m%fr_k, r%fr_k) .AND. (m%has_ctrl .EQV. r%has_ctrl) + IF (same .AND. m%has_ctrl) same = same_bits(m%l0_dot, r%l0_dot) + END FUNCTION unchanged + + ! ------------------------------------------------------------------------------------------ + SUBROUTINE check_hanging_payout() + !! B: a vertical cable hangs from a fixed top node; its two top elements (S = 2 m) are paid + !! out by 0.5 m on a smooth ramp. At rest the top carries the whole submerged weight + !! w (L + DeltaL), and the free end hangs L' + w L'**2/(2 EA) below the top. Marched at + !! rho_inf = 0 (alpha_f = 0) and rho_inf = 0.4 (alpha_f = 2/7, where the committed force + !! carries weight in the blend): both reach the closed form. (The free end rings axially + !! through the ramp, and the two spectral radii damp that differently by more than a lag + !! would shift the tension, so the lag is checked on the taut lines of C and F.) + INTEGER, PARAMETER :: NE = 10 + REAL(wp), PARAMETER :: L = 10.0_wp, EA = 1.0e5_wp, W = 50.0_wp, RHOA = 10.0_wp, BA = 2000.0_wp + REAL(wp), PARAMETER :: DL = 0.5_wp, TR = 2.0_wp, TEND = 8.0_wp, DT = 0.01_wp + TYPE(CD_HermiteCableDynType) :: m + REAL(wp) :: s, z(NE + 1), mz(NE + 1), t_top, lp, z_end, expect + INTEGER :: i, es, pass + CHARACTER(300) :: em + + DO pass = 1, 2 + DO i = 1, NE + 1 + s = REAL(i - 1, wp)*L/REAL(NE, wp) + z(i) = -(L - s) - W*(L*L - s*s)/(2.0_wp*EA) + mz(i) = 1.0_wp + W*s/EA + END DO + CALL vertical_model(m, L/REAL(NE, wp), EA, W, RHOA, BA, z, mz, .FALSE., es, em, & + rho_inf=MERGE(0.0_wp, 0.4_wp, pass == 1)) + CALL require(es == CD_HCDYN_OK, 'B: init: '//TRIM(em)) + IF (es /= CD_HCDYN_OK) RETURN + t_top = top_tension(m) + CALL require(ABS(t_top - W*L) <= 1.0e-9_wp*W*L, 'B: the seed carries the weight w L') + CALL march_ramp(m, [NE - 1, NE], DL, 0.0_wp, TR, TEND, DT, .TRUE., es, em) + CALL require(es == CD_HCDYN_OK, 'B: march: '//TRIM(em)) + IF (es /= CD_HCDYN_OK) RETURN + lp = L + DL + expect = W*lp + t_top = top_tension(m) + z_end = m%q(3) + WRITE (*, '(A,I0,A,ES12.5,A,ES12.5)') ' B (pass ', pass, '): top reaction rel. error ', & + ABS(t_top - expect)/expect, ' free-end position error [m] ', ABS(z_end + lp + W*lp*lp/(2.0_wp*EA)) + CALL require(ABS(t_top - expect) <= 1.0e-6_wp*expect, 'B: top reaction is w (L + DeltaL)') + CALL require(ABS(z_end + lp + W*lp*lp/(2.0_wp*EA)) <= 1.0e-6_wp, & + 'B: the free end hangs L'' + w L''**2/(2 EA) below the top') + CALL require(ALL(ABS(m%l0(NE - 1:NE) - 1.25_wp) <= 2.0_wp*EPSILON(1.0_wp)), & + 'B: the span elements scaled by (S + DeltaL)/S') + CALL CD_HermiteCable_Dyn_End(m) + END DO + END SUBROUTINE check_hanging_payout + + SUBROUTINE check_taut_haul_in() + !! C: a vertical cable between fixed ends H = 10.1 m apart; its two top elements are + !! hauled in by 0.2 m. At rest the top tension is EA (H - L')/L' + w L'/2. Marched at + !! rho_inf = 0 and 0.4, as B: both reach the closed form, and through the ramp the top + !! tension of the two follows the same path, to a few per cent of the per-step tension + !! change (a committed force taken at the new lengths would lag the alpha_f > 0 run by + !! alpha_f = 2/7 of it). + INTEGER, PARAMETER :: NE = 10 + REAL(wp), PARAMETER :: L = 10.0_wp, H = 10.1_wp, EA = 1.0e5_wp, W = 50.0_wp, RHOA = 10.0_wp + REAL(wp), PARAMETER :: BA = 2000.0_wp, DL = -0.2_wp, TR = 2.0_wp, TEND = 8.0_wp, DT = 0.01_wp + TYPE(CD_HermiteCableDynType) :: m + REAL(wp) :: s, z(NE + 1), mz(NE + 1), tb, t_top, lp, expect, hist(NINT(TEND/DT), 2), d_step, diff + INTEGER :: i, es, pass + CHARACTER(300) :: em + + DO pass = 1, 2 + tb = EA*(H - L)/L - W*L/2.0_wp + DO i = 1, NE + 1 + s = REAL(i - 1, wp)*L/REAL(NE, wp) + z(i) = s + (tb*s + W*s*s/2.0_wp)/EA + mz(i) = 1.0_wp + (tb + W*s)/EA + END DO + CALL vertical_model(m, L/REAL(NE, wp), EA, W, RHOA, BA, z, mz, .TRUE., es, em, & + rho_inf=MERGE(0.0_wp, 0.4_wp, pass == 1)) + CALL require(es == CD_HCDYN_OK, 'C: init: '//TRIM(em)) + IF (es /= CD_HCDYN_OK) RETURN + t_top = top_tension(m) + expect = EA*(H - L)/L + W*L/2.0_wp + CALL require(ABS(t_top - expect) <= 1.0e-9_wp*expect, 'C: the seed carries EA (H - L)/L + w L/2') + CALL march_ramp(m, [NE - 1, NE], DL, 0.0_wp, TR, TEND, DT, .TRUE., es, em, hist(:, pass)) + CALL require(es == CD_HCDYN_OK, 'C: march: '//TRIM(em)) + IF (es /= CD_HCDYN_OK) RETURN + lp = L + DL + expect = EA*(H - lp)/lp + W*lp/2.0_wp + t_top = top_tension(m) + WRITE (*, '(A,I0,A,ES12.5)') ' C (pass ', pass, '): top tension rel. error ', ABS(t_top - expect)/expect + CALL require(ABS(t_top - expect) <= 1.0e-6_wp*expect, 'C: top tension is EA (H - L'')/L'' + w L''/2') + CALL CD_HermiteCable_Dyn_End(m) + END DO + ! the largest per-step change of the quasi-static tension EA H/L'(t), at the shortest L' + lp = L + DL + d_step = EA*H*ABS(DL)*0.5_wp*(PI/TR)*DT/(lp*lp) + diff = MAXVAL(ABS(hist(:, 2) - hist(:, 1))) + WRITE (*, '(A,ES10.3,A,ES12.5)') ' C: per-step tension change ', d_step, & + ' N; max difference between rho_inf = 0.4 and 0 ', diff + CALL require(diff <= 5.0e-2_wp*d_step, 'C: the alpha_f > 0 ramp follows the alpha_f = 0 one (no lag)') + END SUBROUTINE check_taut_haul_in + + SUBROUTINE check_payout_rate_lag() + !! D: a weightless cable between fixed ends H = 10.1 m apart (initial strain 1 %); its two + !! top elements are paid out at Ldot = 0.01 m/s from t = 0. The strain stays uniform, + !! eps = H/L' - 1, so the Kelvin-Voigt tension is EA eps + BA d(eps)/dt + !! = EA (H/L' - 1) - BA H Ldot/L'**2: the damping lag. Withholding the length rate puts a + !! spurious stretch rate on the span and misses it. + INTEGER, PARAMETER :: NE = 10 + REAL(wp), PARAMETER :: L = 10.0_wp, H = 10.1_wp, EA = 1.0e5_wp, RHOA = 1.0_wp, BA = 1.0e5_wp + REAL(wp), PARAMETER :: LDOT = 0.01_wp, TEND = 4.0_wp, DT = 0.01_wp + TYPE(CD_HermiteCableDynType) :: m + REAL(wp) :: s, z(NE + 1), mz(NE + 1), err_rate, err_norate, lag + INTEGER :: i, es, pass + CHARACTER(300) :: em + + lag = BA*H*LDOT/(L + LDOT*TEND)**2 + DO pass = 1, 2 + DO i = 1, NE + 1 + s = REAL(i - 1, wp)*L/REAL(NE, wp) + z(i) = s*H/L + mz(i) = H/L + END DO + CALL vertical_model(m, L/REAL(NE, wp), EA, 0.0_wp, RHOA, BA, z, mz, .TRUE., es, em) + CALL require(es == CD_HCDYN_OK, 'D: init: '//TRIM(em)) + IF (es /= CD_HCDYN_OK) RETURN + IF (pass == 1) THEN + CALL march_rate(m, [NE - 1, NE], LDOT, .TRUE., TEND, DT, H, EA, BA, err_rate, es, em) + CALL require(es == CD_HCDYN_OK, 'D: march: '//TRIM(em)) + ELSE + CALL march_rate(m, [NE - 1, NE], LDOT, .FALSE., TEND, DT, H, EA, BA, err_norate, es, em) + CALL require(es == CD_HCDYN_OK, 'D: march without the rate: '//TRIM(em)) + END IF + CALL CD_HermiteCable_Dyn_End(m) + END DO + WRITE (*, '(A,ES10.3,A,ES12.5,A,ES12.5)') ' D: damping lag ', lag, ' N; max tension error with the rate ', & + err_rate, ' N, without ', err_norate + CALL require(err_rate <= 1.0e-2_wp*lag, 'D: tension follows EA (H/L'' - 1) - BA H Ldot/L''**2') + CALL require(err_norate > 0.2_wp*lag, 'D: without the length rate the damping tension is wrong') + END SUBROUTINE check_payout_rate_lag + + SUBROUTINE check_slow_ramp_static() + !! E: a slack planar cable (10.4 m between ends 10 m apart, EI > 0) sagging under its + !! weight; its three top elements are hauled in by 0.2 m on a slow ramp and the line + !! settles. The end state is the static equilibrium of the edited lengths + !! (CD_HermiteCable_Static_Solve, seeded from the initial equilibrium). + INTEGER, PARAMETER :: NE = 12, NN = NE + 1, NDOF = 6*NN + REAL(wp), PARAMETER :: LTOT = 10.4_wp, EA = 1.0e6_wp, EI = 50.0_wp, W = 20.0_wp, RHOA = 2.0_wp + REAL(wp), PARAMETER :: BA = 1.0e4_wp, SAG = 1.3_wp, DL = -0.2_wp, TR = 10.0_wp, TEND = 60.0_wp, DT = 0.05_wp + TYPE(CD_HermiteCableDynType) :: m + REAL(wp) :: l0(NE), seed(NDOF), q_static(NDOF), q_edit(NDOF), curv(NN), res, t, dx(3), dist, err + INTEGER, ALLOCATABLE :: fixed(:) + INTEGER :: i, es, iters, k + CHARACTER(300) :: em + + l0 = LTOT/REAL(NE, wp) + ! end translations, then the out-of-plane DOFs (m_y everywhere, r_y in the interior) + fixed = [1, 2, 3, NDOF - 5, NDOF - 4, NDOF - 3, (6*(i - 1) + 5, i=1, NN), (6*(i - 1) + 2, i=2, NN - 1)] + ! parabolic sag below the chord from (0, 0, 0) to (8, 0, 6) + DO i = 1, NN + t = REAL(i - 1, wp)/REAL(NE, wp) + seed(6*(i - 1) + 1:6*(i - 1) + 3) = [8.0_wp*t, 0.0_wp, 6.0_wp*t - 4.0_wp*SAG*t*(1.0_wp - t)] + dx = [8.0_wp, 0.0_wp, 6.0_wp - 4.0_wp*SAG*(1.0_wp - 2.0_wp*t)] + seed(6*(i - 1) + 4:6*(i - 1) + 6) = dx/NORM2(dx) + END DO + CALL CD_HermiteCable_Static_Solve(l0, [(EA, k=1, NE)], [(EI, k=1, NE)], [(W, k=1, NE)], seed, fixed, & + -1.0e3_wp, 0.0_wp, 4, 200, 1.0e-10_wp, 1.0_wp, q_static, curv, res, iters, & + es, em) + CALL require(es == CD_HCSTAT_OK, 'E: initial static solve: '//TRIM(em)) + IF (es /= CD_HCSTAT_OK) RETURN + CALL require(q_static(6*(NE/2) + 3) < 3.0_wp - 0.5_wp, 'E: the initial equilibrium sags below the chord') + CALL CD_HermiteCable_Dyn_Init(m, l0, [(EA, k=1, NE)], [(EI, k=1, NE)], [(RHOA, k=1, NE)], [(W, k=1, NE)], & + q_static, fixed, -1.0e3_wp, 0.0_wp, 0.0_wp, es, em) + CALL require(es == CD_HCDYN_OK, 'E: init: '//TRIM(em)) + IF (es /= CD_HCDYN_OK) RETURN + CALL CD_HermiteCable_Dyn_Set_Axial_Damping(m, [(BA, k=1, NE)], es, em) + CALL CD_HermiteCable_Dyn_Set_Drag(m, 1025.0_wp, [(0.2_wp, k=1, NE)], [(2.0_wp, k=1, NE)], & + [(0.5_wp, k=1, NE)], 100.0_wp, [0.0_wp, 0.0_wp, 0.0_wp], es, em) + CALL require(es == CD_HCDYN_OK, 'E: drag: '//TRIM(em)) + CALL march_ramp(m, [NE - 2, NE - 1, NE], DL, 0.0_wp, TR, TEND, DT, .TRUE., es, em) + CALL require(es == CD_HCDYN_OK, 'E: march: '//TRIM(em)) + IF (es /= CD_HCDYN_OK) RETURN + l0(NE - 2:NE) = l0(NE - 2:NE)*((3.0_wp*l0(NE) + DL)/(3.0_wp*l0(NE))) + CALL CD_HermiteCable_Static_Solve(l0, [(EA, k=1, NE)], [(EI, k=1, NE)], [(W, k=1, NE)], q_static, fixed, & + -1.0e3_wp, 0.0_wp, 1, 200, 1.0e-10_wp, 1.0_wp, q_edit, curv, res, iters, & + es, em) + CALL require(es == CD_HCSTAT_OK, 'E: static solve at the edited lengths: '//TRIM(em)) + IF (es /= CD_HCSTAT_OK) RETURN + err = 0.0_wp + dist = 0.0_wp + DO i = 1, NN + err = MAX(err, NORM2(m%q(6*(i - 1) + 1:6*(i - 1) + 3) - q_edit(6*(i - 1) + 1:6*(i - 1) + 3))) + dist = MAX(dist, NORM2(q_static(6*(i - 1) + 1:6*(i - 1) + 3) - q_edit(6*(i - 1) + 1:6*(i - 1) + 3))) + END DO + WRITE (*, '(A,ES12.5,A,ES12.5,A)') ' E: end state vs static solve ', err, ' m (the haul-in moves nodes up to ', & + dist, ' m)' + CALL require(dist > 0.1_wp, 'E: the haul-in moves the line') + CALL require(err <= 1.0e-5_wp*dist, 'E: the settled end state is the static equilibrium of the edited lengths') + CALL CD_HermiteCable_Dyn_End(m) + END SUBROUTINE check_slow_ramp_static + + SUBROUTINE check_payout_alpha_f() + !! F: the cable of D paid out at Ldot = 0.01 m/s, marched with rho_inf = 0.4 + !! (alpha_f = 2/7) and with rho_inf = 0 (alpha_f = 0). The force-blended residual weighs + !! the committed force F_n by alpha_f; F_n is the force at the lengths of the step that + !! reached the committed state, so the blend tracks the quasi-static tension + !! EA (H/L' - 1) - BA H Ldot/L'**2 at either alpha_f. Evaluating F_n with the new lengths + !! instead lags the tension by a fixed fraction of the per-step change + !! dT = EA H Ldot dt/L'**2 (the pay-out ramp artifact this check guards against). + INTEGER, PARAMETER :: NE = 10 + REAL(wp), PARAMETER :: L = 10.0_wp, H = 10.1_wp, EA = 1.0e5_wp, RHOA = 1.0_wp, BA = 1.0e5_wp + REAL(wp), PARAMETER :: LDOT = 0.01_wp, TEND = 4.0_wp, DT = 0.01_wp + TYPE(CD_HermiteCableDynType) :: m + REAL(wp) :: s, z(NE + 1), mz(NE + 1), err(3), t_hist(NINT(TEND/DT), 3), d_step, diff + INTEGER :: i, es, pass + CHARACTER(300) :: em + + d_step = EA*H*LDOT*DT/(L + LDOT*TEND)**2 + DO pass = 1, 3 + DO i = 1, NE + 1 + s = REAL(i - 1, wp)*L/REAL(NE, wp) + z(i) = s*H/L + mz(i) = H/L + END DO + CALL vertical_model(m, L/REAL(NE, wp), EA, 0.0_wp, RHOA, BA, z, mz, .TRUE., es, em, & + rho_inf=MERGE(0.0_wp, 0.4_wp, pass == 2)) + CALL require(es == CD_HCDYN_OK, 'F: init: '//TRIM(em)) + IF (es /= CD_HCDYN_OK) RETURN + ! pass 3 drops the committed force reused from the preceding step before every step, so + ! each step evaluates it afresh at the committed lengths + CALL march_rate(m, [NE - 1, NE], LDOT, .TRUE., TEND, DT, H, EA, BA, err(pass), es, em, t_hist(:, pass), & + fresh_force=pass == 3) + CALL require(es == CD_HCDYN_OK, 'F: march: '//TRIM(em)) + CALL CD_HermiteCable_Dyn_End(m) + IF (es /= CD_HCDYN_OK) RETURN + END DO + diff = MAXVAL(ABS(t_hist(NINT(1.0_wp/DT):, 1) - t_hist(NINT(1.0_wp/DT):, 2))) + WRITE (*, '(A,ES10.3,A,ES12.5,A,ES12.5,A,ES12.5)') ' F: per-step tension change ', d_step, & + ' N; max error vs the closed form at alpha_f = 2/7 ', err(1), ' N, at alpha_f = 0 ', err(2), & + ' N; max difference ', diff + CALL require(err(1) <= 2.0e-2_wp*d_step, 'F: at alpha_f > 0 the tension follows the quasi-static closed form') + CALL require(err(2) <= 2.0e-2_wp*d_step, 'F: at alpha_f = 0 the tension follows the quasi-static closed form') + WRITE (*, '(A,ES12.5,A)') ' F: with the committed force evaluated afresh each step, max error ', err(3), ' N' + CALL require(err(3) <= 2.0e-2_wp*d_step, & + 'F: a committed force evaluated afresh (not reused) is taken at the committed lengths') + CALL require(diff <= 2.0e-2_wp*d_step, 'F: the tension at alpha_f > 0 equals the one at alpha_f = 0') + END SUBROUTINE check_payout_alpha_f + + ! ------------------------------------------------------------------------------------------ + SUBROUTINE vertical_model(model, l, ea, w, rhoa, ba, z, mz, fix_bottom, ErrStat, ErrMsg, rho_inf) + !! A vertical cable along z (node 1 at the bottom, the last node at the fixed top) held in + !! every transverse DOF, so only r_z and m_z move: an axial bar under weight w. rho_inf + !! (default 0) is the generalised-alpha spectral radius. + TYPE(CD_HermiteCableDynType), INTENT(OUT) :: model + REAL(wp), INTENT(IN) :: l, ea, w, rhoa, ba, z(:), mz(:) + LOGICAL, INTENT(IN) :: fix_bottom + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), INTENT(IN), OPTIONAL :: rho_inf + REAL(wp), ALLOCATABLE :: q(:) + INTEGER, ALLOCATABLE :: fixed(:) + INTEGER :: nn, ne, i, k + REAL(wp) :: rho + nn = SIZE(z) + ne = nn - 1 + ALLOCATE (q(6*nn)) + q = 0.0_wp + fixed = [INTEGER ::] + DO i = 1, nn + q(6*(i - 1) + 3) = z(i) + q(6*(i - 1) + 6) = mz(i) + fixed = [fixed, 6*(i - 1) + 1, 6*(i - 1) + 2, 6*(i - 1) + 4, 6*(i - 1) + 5] + END DO + fixed = [fixed, 6*nn - 3] + IF (fix_bottom) fixed = [fixed, 3] + rho = 0.0_wp + IF (PRESENT(rho_inf)) rho = rho_inf + CALL CD_HermiteCable_Dyn_Init(model, [(l, k=1, ne)], [(ea, k=1, ne)], [(1.0_wp, k=1, ne)], & + [(rhoa, k=1, ne)], [(w, k=1, ne)], q, fixed, -1.0e3_wp, 0.0_wp, rho, & + ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) RETURN + CALL CD_HermiteCable_Dyn_Set_Axial_Damping(model, [(ba, k=1, ne)], ErrStat, ErrMsg) + END SUBROUTINE vertical_model + + SUBROUTINE march_ramp(model, span, dl_final, dl_start, tr, tend, dt, with_rate, ErrStat, ErrMsg, tension) + !! March to tend, changing the span's total length from its base S by + !! dl(t) = dl_start + (dl_final - dl_start) (1 - cos(pi t/tr))/2 over [0, tr] and holding it + !! after; each element scales by (S + dl)/S, with rate dl_dot l_e/S, before each step + !! (and, optionally, return the top tension after every step). + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + INTEGER, INTENT(IN) :: span(:) + REAL(wp), INTENT(IN) :: dl_final, dl_start, tr, tend, dt + LOGICAL, INTENT(IN) :: with_rate + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), INTENT(OUT), OPTIONAL :: tension(:) + REAL(wp) :: base(SIZE(span)), s_base, t, dl, dldot + INTEGER :: n, k + base = model%l0(span) + s_base = SUM(base) + n = NINT(tend/dt) + DO k = 1, n + t = REAL(k, wp)*dt + IF (t < tr) THEN + dl = dl_start + (dl_final - dl_start)*0.5_wp*(1.0_wp - COS(PI*t/tr)) + dldot = (dl_final - dl_start)*0.5_wp*(PI/tr)*SIN(PI*t/tr) + ELSE + dl = dl_final + dldot = 0.0_wp + END IF + IF (.NOT. with_rate) dldot = 0.0_wp + CALL CD_HermiteCable_Dyn_Set_SegmentLength(model, span, base*((s_base + dl)/s_base), dldot*base/s_base, & + ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) RETURN + CALL CD_HermiteCable_Dyn_Step(model, dt, 50, 1.0e-10_wp, ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) RETURN + IF (PRESENT(tension)) tension(k) = top_tension(model) + END DO + END SUBROUTINE march_ramp + + SUBROUTINE march_rate(model, span, ldot, with_rate, tend, dt, h, ea, ba, err_max, ErrStat, ErrMsg, tension, & + fresh_force) + !! March a constant pay-out of the span (rate passed when with_rate) and return the largest + !! deviation of the top tension from EA (H/L' - 1) - BA H Ldot/L'**2 after the first second + !! (and, optionally, the top tension after every step). fresh_force drops the committed + !! force cached by the preceding step before each step (re-selecting the force blend does). + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + INTEGER, INTENT(IN) :: span(:) + REAL(wp), INTENT(IN) :: ldot, tend, dt, h, ea, ba + LOGICAL, INTENT(IN) :: with_rate + REAL(wp), INTENT(OUT) :: err_max + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), INTENT(OUT), OPTIONAL :: tension(:) + LOGICAL, INTENT(IN), OPTIONAL :: fresh_force + REAL(wp) :: base(SIZE(span)), s_base, l_total, t, lp, rate, expect + INTEGER :: n, k + LOGICAL :: fresh + fresh = .FALSE. + IF (PRESENT(fresh_force)) fresh = fresh_force + base = model%l0(span) + s_base = SUM(base) + l_total = SUM(model%l0) + err_max = 0.0_wp + rate = 0.0_wp + IF (with_rate) rate = ldot + n = NINT(tend/dt) + DO k = 1, n + t = REAL(k, wp)*dt + CALL CD_HermiteCable_Dyn_Set_SegmentLength(model, span, base*((s_base + ldot*t)/s_base), rate*base/s_base, & + ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) RETURN + IF (fresh) THEN + CALL CD_HermiteCable_Dyn_Set_ForceBlend(model, .TRUE., ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) RETURN + END IF + CALL CD_HermiteCable_Dyn_Step(model, dt, 50, 1.0e-6_wp, ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) RETURN + IF (PRESENT(tension)) tension(k) = top_tension(model) + IF (t < 1.0_wp) CYCLE + lp = l_total + ldot*t + expect = ea*(h/lp - 1.0_wp) - ba*h*ldot/(lp*lp) + err_max = MAX(err_max, ABS(top_tension(model) - expect)) + END DO + END SUBROUTINE march_rate + + REAL(wp) FUNCTION top_tension(model) RESULT(t) + !! Axial pull of the line on its fixed top node (the last node). + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + REAL(wp) :: f(3) + INTEGER :: es + CHARACTER(200) :: em + CALL CD_HermiteCable_Dyn_Reaction(model, model%nn, f, es, em) + t = -f(3) + IF (es /= CD_HCDYN_OK) t = HUGE(1.0_wp) + END FUNCTION top_tension + + LOGICAL FUNCTION same_bits(x, y) RESULT(same) + REAL(wp), INTENT(IN) :: x(:), y(:) + same = SIZE(x) == SIZE(y) + IF (same) same = ALL(TRANSFER(x, 0_INT64, SIZE(x)) == TRANSFER(y, 0_INT64, SIZE(y))) + END FUNCTION same_bits + + LOGICAL FUNCTION same_bits2(x, y) RESULT(same) + REAL(wp), INTENT(IN) :: x(:, :), y(:, :) + same = SIZE(x, 1) == SIZE(y, 1) .AND. SIZE(x, 2) == SIZE(y, 2) + IF (same) same = same_bits(RESHAPE(x, [SIZE(x)]), RESHAPE(y, [SIZE(y)])) + END FUNCTION same_bits2 + + SUBROUTINE require(condition, message) + LOGICAL, INTENT(IN) :: condition + CHARACTER(*), INTENT(IN) :: message + IF (.NOT. condition) THEN + nfail = nfail + 1 + WRITE (*, '(A)') 'MISMATCH: '//TRIM(message) + END IF + END SUBROUTINE require + +END PROGRAM test_hermite_cable_control diff --git a/tests/test_model.f90 b/tests/test_model.f90 index b8063fcd..b7fd128d 100644 --- a/tests/test_model.f90 +++ b/tests/test_model.f90 @@ -43,6 +43,9 @@ PROGRAM test_model CALL case_lifecycle_static_step() CALL case_segment_length_update() + CALL case_segment_payout_ramp() + CALL case_segment_payout_substeps() + CALL case_segment_force_blend_committed_side() CALL case_copy_model_preserves_state() CALL case_prescribed_step_updates_state() CALL case_recovery_common_path() @@ -163,10 +166,14 @@ END SUBROUTINE case_lifecycle_static_step SUBROUTINE case_segment_length_update() !! Active line control (the CtrlChan mechanism): CD_Update_Model_SegmentLength - !! must leave the model INDISTINGUISHABLE from one BUILT with the new length -- - !! the stale-cache killer (any l0-derived quantity cached at init and not - !! refreshed breaks the bitwise step equivalence). Also: paying out a taut - !! segment drops its tension (sign), and the validation battery fails closed. + !! keeps the committed acceleration and the lengths the committed state was reached + !! with (a re-derived acceleration keeps them too); once the new length is committed + !! (restored = .TRUE., the checkpoint-restart re-application) and the acceleration + !! re-derived (CD_Recompute_Model_Acceleration) the model must be INDISTINGUISHABLE from one + !! BUILT with the new length -- the stale-cache killer (any l0-derived quantity + !! cached at init and not refreshed breaks the bitwise step equivalence). Also: + !! paying out a taut segment drops its tension (sign), and the validation battery + !! fails closed. INTEGER, PARAMETER :: NE = 4, NN = NE + 1, NDOF = 3*NN TYPE(CD_ModelType) :: ma, mb TYPE(GenAlphaConfig) :: cfg @@ -194,16 +201,25 @@ SUBROUTINE case_segment_length_update() ! sign: paying out the taut end segment drops its tension, others unchanged CALL CD_Get_Model_Tension(ma, ten0, es, em) CALL require(es == CD_MODEL_OK, 'seglen:tension-0') + aa = ma%a CALL CD_Update_Model_SegmentLength(ma, NE, l0b(NE), 0.0_wp, es, em) CALL require(es == CD_MODEL_OK, 'seglen:update: '//TRIM(em)) + CALL require(nan_max_abs(ma%a - aa) <= 0.0_wp .AND. nan_max_abs(ma%l0_c - l0) <= 0.0_wp, & + 'seglen:update-keeps-the-committed-acceleration-and-lengths') CALL CD_Get_Model_Tension(ma, ten1, es, em) CALL require(es == CD_MODEL_OK, 'seglen:tension-1') CALL require(ten1(NE) < ten0(NE), 'seglen:payout-drops-end-tension') CALL require(nan_max_abs(ten1(1:NE - 1) - ten0(1:NE - 1)) <= 0.0_wp, 'seglen:other-segments-untouched') - ! equivalence: the updated model matches the fresh-built twin bitwise -- - ! tensions, coupled loads (the re-assembled mass cache), and a full dynamic - ! step under the same trajectory + ! equivalence: committed at the new length, the updated model matches the fresh-built + ! twin bitwise -- tensions, coupled loads (the re-assembled mass cache), and a full + ! dynamic step under the same trajectory + CALL CD_Recompute_Model_Acceleration(ma, es, em) + CALL require(es == CD_MODEL_OK .AND. nan_max_abs(ma%l0_c - l0) <= 0.0_wp .AND. nan_max_abs(ma%a - aa) <= 0.0_wp, & + 'seglen:recompute-keeps-the-committed-lengths') + CALL CD_Update_Model_SegmentLength(ma, NE, l0b(NE), 0.0_wp, es, em, restored=.TRUE.) + CALL CD_Recompute_Model_Acceleration(ma, es, em) + CALL require(es == CD_MODEL_OK .AND. nan_max_abs(ma%l0_c - l0b) <= 0.0_wp, 'seglen:commit-at-new-length') CALL CD_Get_Model_Tension(mb, tenb, es, em) CALL require(nan_max_abs(ten1 - tenb) <= 0.0_wp, 'seglen:tension-equals-fresh-build') CALL CD_Calc_Model_CoupledLoads(ma, loads_a, es, em) @@ -243,8 +259,10 @@ SUBROUTINE case_segment_length_update() CALL CD_Init_Model(mw1, q0, v0, conn, l0b, ea, rho_a, .FALSE., fw1, fixed, cfg, es, em, & dist_load_per_length=wpl) CALL require(es == CD_MODEL_OK, 'seglen:init-weighted-fresh') - CALL CD_Update_Model_SegmentLength(mw0, NE, l0b(NE), 0.0_wp, es, em) + CALL CD_Update_Model_SegmentLength(mw0, NE, l0b(NE), 0.0_wp, es, em, restored=.TRUE.) CALL require(es == CD_MODEL_OK, 'seglen:weighted-update: '//TRIM(em)) + CALL CD_Recompute_Model_Acceleration(mw0, es, em) + CALL require(es == CD_MODEL_OK, 'seglen:weighted-commit: '//TRIM(em)) CALL require(nan_max_abs(mw0%f_ext - mw1%f_ext) <= 0.0_wp, 'seglen:weighted-fext-bitwise') CALL require(nan_max_abs(mw0%l0 - mw1%l0) <= 0.0_wp, 'seglen:weighted-l0-bitwise') CALL require(nan_max_abs(mw0%a - mw1%a) <= 0.0_wp, 'seglen:weighted-accel-bitwise') @@ -282,8 +300,10 @@ SUBROUTINE case_segment_length_update() fx0(3*2 - 1) = fx0(3*2 - 1) + 3.0_wp CALL CD_Update_Model_External_Loads(mx0, fx0, es, em) CALL require(es == CD_MODEL_OK, 'seglen:extload-update: '//TRIM(em)) - CALL CD_Update_Model_SegmentLength(mx0, NE, l0b(NE), 0.0_wp, es, em) + CALL CD_Update_Model_SegmentLength(mx0, NE, l0b(NE), 0.0_wp, es, em, restored=.TRUE.) CALL require(es == CD_MODEL_OK, 'seglen:extload-control: '//TRIM(em)) + CALL CD_Recompute_Model_Acceleration(mx0, es, em) + CALL require(es == CD_MODEL_OK, 'seglen:extload-commit: '//TRIM(em)) ! fresh twin: assembled at the NEW length plus the same bump CALL CD_Assemble_Distributed_Load(conn, l0b, wplx, fx1, es, em) CALL require(es == 0, 'seglen:extload-assemble-fresh') @@ -382,6 +402,300 @@ SUBROUTINE case_segment_length_update() CALL require(es /= CD_MODEL_OK, 'seglen:uninitialized-fails') END SUBROUTINE case_segment_length_update + SUBROUTINE case_segment_payout_ramp() + !! A weightless EI = 0 line between fixed ends H = 10.1 m apart (initial strain 1 %), + !! its end element paid out at Ldot = 0.01 m/s from t = 0, marched with rho_inf = 0.4 + !! and rho_inf = 0. The strain stays uniform, eps = H/L' - 1, so the reported tension + !! (elastic plus Kelvin-Voigt) is EA (H/L' - 1) - BA H Ldot/L'**2. The committed state + !! keeps the lengths it was reached with: re-deriving the committed acceleration under + !! the new length, or evaluating the step-start force of the force blend (the default; + !! under False alpha_force_blend the blended configuration) with the new length, lags the + !! tension by a fixed fraction of its change per step, dT = EA H Ldot dt/L'**2 (the + !! pay-out ramp artifact this check guards against). + INTEGER, PARAMETER :: NE = 10, NN = NE + 1, NDOF = 3*NN + REAL(wp), PARAMETER :: L = 10.0_wp, H = 10.1_wp, EAV = 1.0e5_wp, RHOA = 1.0_wp, BAV = 1.0e5_wp + REAL(wp), PARAMETER :: LDOT = 0.01_wp, TEND = 4.0_wp, DT = 0.01_wp + TYPE(CD_ModelType) :: m + TYPE(GenAlphaConfig) :: cfg + INTEGER :: conn(2, NE), fixed(6), es, n_iter, i, k, pass + REAL(wp) :: l0(NE), ea(NE), rho_a(NE), ba(NE), q0(NDOF), v0(NDOF), f_ext(NDOF), ten(NE) + REAL(wp) :: t, lp, expect, err(3), d_step, hist(NINT(TEND/DT), 3), diff, diff_cfg + LOGICAL :: conv, stalled + CHARACTER(200) :: em + + DO i = 1, NE + conn(:, i) = [i, i + 1] + END DO + l0 = L/REAL(NE, wp) + ea = EAV + rho_a = RHOA + ba = BAV + DO i = 1, NN + q0(3*i - 2:3*i) = [REAL(i - 1, wp)*H/REAL(NE, wp), 0.0_wp, 0.0_wp] + END DO + fixed = [1, 2, 3, NDOF - 2, NDOF - 1, NDOF] + v0 = 0.0_wp + f_ext = 0.0_wp + d_step = EAV*H*LDOT*DT/(L + LDOT*TEND)**2 + err = 0.0_wp + ! pass 1: rho_inf 0.4, 2: rho_inf 0, 3: rho_inf 0.4 with the configuration blend + DO pass = 1, 3 + cfg%rho_inf = MERGE(0.0_wp, 0.4_wp, pass == 2) + cfg%force_blend = pass /= 3 + cfg%rel_tol = 1.0e-10_wp + CALL CD_Init_Model(m, q0, v0, conn, l0, ea, rho_a, .FALSE., f_ext, fixed, cfg, es, em, ba=ba) + CALL require(es == CD_MODEL_OK, 'payout:init: '//TRIM(em)) + IF (es /= CD_MODEL_OK) RETURN + DO k = 1, NINT(TEND/DT) + t = REAL(k, wp)*DT + CALL CD_Update_Model_SegmentLength(m, NE, l0(NE) + LDOT*t, LDOT, es, em) + CALL require(es == CD_MODEL_OK, 'payout:update: '//TRIM(em)) + CALL CD_Step_Model(m, DT, conv, stalled, n_iter, es, em) + CALL require(es == CD_MODEL_OK .AND. conv, 'payout:step: '//TRIM(em)) + IF (es /= CD_MODEL_OK) EXIT + CALL CD_Get_Model_Tension(m, ten, es, em) + hist(k, pass) = ten(1) + IF (t < 1.0_wp) CYCLE + lp = L + LDOT*t + expect = EAV*(H/lp - 1.0_wp) - BAV*H*LDOT/(lp*lp) + err(pass) = MAX(err(pass), ABS(ten(1) - expect), ABS(ten(NE) - expect)) + END DO + CALL CD_End_Model(m, es, em) + END DO + diff = MAXVAL(ABS(hist(NINT(1.0_wp/DT):, 1) - hist(NINT(1.0_wp/DT):, 2))) + diff_cfg = MAXVAL(ABS(hist(NINT(1.0_wp/DT):, 3) - hist(NINT(1.0_wp/DT):, 2))) + WRITE (*, '(A,ES10.3,A,ES12.5,A,ES12.5,A,ES12.5)') ' payout ramp: per-step tension change ', d_step, & + ' N; max error vs the closed form at rho_inf = 0.4 ', err(1), ' N, at 0 ', err(2), ' N; difference ', diff + WRITE (*, '(A,ES12.5,A,ES12.5)') ' payout ramp, False alpha_force_blend at rho_inf = 0.4: max error ', err(3), & + ' N; difference to rho_inf = 0 ', diff_cfg + ! the error is the start-up transient (1.8e-3 d_step at either rho_inf); a step-start force at + ! blended or new lengths under the force blend leaves 7e-3 and 2.6 d_step, and a difference + ! between the two rho_inf of 9e-4 d_step and more + CALL require(err(1) <= 5.0e-3_wp*d_step, 'payout:rho_inf-0.4-follows-the-closed-form') + CALL require(err(2) <= 5.0e-3_wp*d_step, 'payout:rho_inf-0-follows-the-closed-form') + CALL require(diff <= 1.0e-4_wp*d_step, 'payout:rho_inf-0.4-equals-rho_inf-0') + CALL require(err(3) <= 5.0e-3_wp*d_step .AND. diff_cfg <= 1.0e-4_wp*d_step, 'payout:configuration-blend') + END SUBROUTINE case_segment_payout_ramp + + SUBROUTINE case_segment_payout_substeps() + !! A pay-out on a turning EI = 0 line, solved in sub-steps. A 10-segment line, End A fixed + !! at the origin and End B on a circle of radius H = 10.1 m at OMEGA = 2 rad/s (starting in + !! rigid rotation), turns its segments by 2.3 deg per 0.02 s step, so with ei0_substeps auto + !! (the default angle of 1 deg, at most 4 sub-steps) every step is solved again in four + !! sub-steps; its end element is paid out at LDOT = 0.05 m/s with a Kelvin-Voigt dashpot. + !! The sub-steps take the committed lengths at their start and the lengths interpolated in + !! time at their end, so the march equals a march with ei0_substeps off at dt/4 that sets + !! the length at every fine step, to the quintic of the end motion inside a step (3e-8 N + !! against the per-step tension change d_step = 9.9 N). Taking the whole length change in + !! the first sub-step departs from it by 22 N (2.2 d_step) and 5e-3 m. + INTEGER, PARAMETER :: NE = 10, NN = NE + 1, NDOF = 3*NN, NSUB = 4 + REAL(wp), PARAMETER :: L = 10.0_wp, H = 10.1_wp, EAV = 1.0e5_wp, RHOA = 1.0_wp, BAV = 1.0e3_wp + REAL(wp), PARAMETER :: LDOT = 0.05_wp, OMEGA = 2.0_wp, TEND = 2.0_wp, DT = 0.02_wp + TYPE(CD_ModelType) :: sub_m, fine_m + TYPE(GenAlphaConfig) :: cfg + INTEGER :: conn(2, NE), fixed(6), es, n_iter, i, k, j + REAL(wp) :: l0(NE), ea(NE), rho_a(NE), ba(NE), q0(NDOF), v0(NDOF), f_ext(NDOF) + REAL(wp) :: pq(NDOF), pv(NDOF), pa(NDOF), ten_s(NE), ten_f(NE), t, d_step, err_t, err_q + LOGICAL :: conv, stalled, all_conv + CHARACTER(200) :: em + + DO i = 1, NE + conn(:, i) = [i, i + 1] + END DO + l0 = L/REAL(NE, wp) + ea = EAV + rho_a = RHOA + ba = BAV + DO i = 1, NN + q0(3*i - 2:3*i) = [REAL(i - 1, wp)*H/REAL(NE, wp), 0.0_wp, 0.0_wp] + v0(3*i - 2:3*i) = [0.0_wp, OMEGA*q0(3*i - 2), 0.0_wp] + END DO + fixed = [1, 2, 3, NDOF - 2, NDOF - 1, NDOF] + f_ext = 0.0_wp + cfg%rel_tol = 1.0e-10_wp + cfg%ei0_substep_max = NSUB + CALL CD_Init_Model(sub_m, q0, v0, conn, l0, ea, rho_a, .FALSE., f_ext, fixed, cfg, es, em, ba=ba) + CALL require(es == CD_MODEL_OK, 'payout-substeps:init: '//TRIM(em)) + IF (es /= CD_MODEL_OK) RETURN + ! the pay-out rate is the committed one from the start (a constant command) + CALL CD_Update_Model_SegmentLength(sub_m, NE, l0(NE), LDOT, es, em, restored=.TRUE.) + CALL require(es == CD_MODEL_OK, 'payout-substeps:rate: '//TRIM(em)) + ! End B starts with its centripetal acceleration, so the quintic of the end motion inside a + ! step (the sub-step boundaries) follows the circle to (OMEGA DT)**6 + CALL payout_end_on_circle(H, OMEGA, 0.0_wp, pq, pv, pa) + sub_m%a(NDOF - 2:NDOF) = pa(NDOF - 2:NDOF) + CALL CD_Copy_Model(sub_m, fine_m, es, em) + CALL require(es == CD_MODEL_OK, 'payout-substeps:copy: '//TRIM(em)) + fine_m%cfg%ei0_substeps = CD_EI0_SUBSTEPS_OFF + d_step = EAV*H*LDOT*DT/(L + LDOT*TEND)**2 + all_conv = .TRUE. + err_t = 0.0_wp + err_q = 0.0_wp + DO k = 1, NINT(TEND/DT) + t = REAL(k, wp)*DT + CALL CD_Update_Model_SegmentLength(sub_m, NE, l0(NE) + LDOT*t, LDOT, es, em) + all_conv = all_conv .AND. es == CD_MODEL_OK + CALL payout_end_on_circle(H, OMEGA, t, pq, pv, pa) + CALL CD_Step_Model(sub_m, DT, conv, stalled, n_iter, es, em, prescribed_q=pq, prescribed_v=pv, prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + DO j = 1, NSUB + t = (REAL(k - 1, wp) + REAL(j, wp)/REAL(NSUB, wp))*DT + CALL CD_Update_Model_SegmentLength(fine_m, NE, l0(NE) + LDOT*t, LDOT, es, em) + all_conv = all_conv .AND. es == CD_MODEL_OK + CALL payout_end_on_circle(H, OMEGA, t, pq, pv, pa) + CALL CD_Step_Model(fine_m, DT/REAL(NSUB, wp), conv, stalled, n_iter, es, em, prescribed_q=pq, & + prescribed_v=pv, prescribed_a=pa) + all_conv = all_conv .AND. es == CD_MODEL_OK .AND. conv + END DO + IF (.NOT. all_conv) EXIT + CALL CD_Get_Model_Tension(sub_m, ten_s, es, em) + CALL CD_Get_Model_Tension(fine_m, ten_f, es, em) + err_t = MAX(err_t, MAXVAL(ABS(ten_s - ten_f))) + err_q = MAX(err_q, MAXVAL(ABS(sub_m%q - fine_m%q))) + END DO + CALL require(all_conv, 'payout-substeps:march: '//TRIM(em)) + WRITE (*, '(A,I0,A,I0,A,I0,A,ES10.3,A,ES10.3,A,ES10.3,A)') ' payout sub-steps: ', sub_m%sub_stats%events, & + ' of ', sub_m%sub_stats%calls, ' steps in ', sub_m%sub_stats%max_used, ' sub-steps; tension against dt/4 ', & + err_t, ' N (d_step ', d_step, ' N), position ', err_q, ' m' + CALL require(sub_m%sub_stats%events == NINT(TEND/DT) .AND. sub_m%sub_stats%max_used == NSUB .AND. & + sub_m%sub_stats%fallbacks == 0, 'payout-substeps:every-step-sub-stepped') + CALL require(ALL(sub_m%l0 == fine_m%l0) .AND. ALL(sub_m%l0_c == sub_m%l0), 'payout-substeps:lengths') + CALL require(err_t <= 1.0e-4_wp*d_step .AND. err_q <= 1.0e-9_wp, 'payout-substeps:equals-the-dt/4-march') + CALL CD_End_Model(sub_m, es, em) + CALL CD_End_Model(fine_m, es, em) + END SUBROUTINE case_segment_payout_substeps + + SUBROUTINE payout_end_on_circle(h, omega, tt, pq, pv, pa) + !! End B (the last node) on a circle of radius h about the origin at angular speed omega, + !! at time tt, as full prescribed vectors (End A at the origin). + REAL(wp), INTENT(IN) :: h, omega, tt + REAL(wp), INTENT(OUT) :: pq(:), pv(:), pa(:) + INTEGER :: n + n = SIZE(pq) + pq = 0.0_wp + pv = 0.0_wp + pa = 0.0_wp + pq(n - 2:n) = h*[COS(omega*tt), SIN(omega*tt), 0.0_wp] + pv(n - 2:n) = h*omega*[-SIN(omega*tt), COS(omega*tt), 0.0_wp] + pa(n - 2:n) = -h*omega**2*[COS(omega*tt), SIN(omega*tt), 0.0_wp] + END SUBROUTINE payout_end_on_circle + + SUBROUTINE case_segment_force_blend_committed_side() + !! Under the force blend (the default) the committed side of the first step after a length + !! and rate command is the committed state's own: a weighted, damped, grounded tension-only + !! line paid out at its end element gives, bit for bit, the acceleration recompute, the + !! step-start load (damping at the committed rate, seabed contact with the committed + !! tributary lengths), the step-start internal force and the release-cap data of its + !! uncommanded twin, while the force at t_{n+1}, the present external load and seabed + !! coefficients are the new lengths' and the inertia takes the blended lengths. + INTEGER, PARAMETER :: NE = 4, NN = NE + 1, NDOF = 3*NN + REAL(wp), PARAMETER :: KBOT = 1.0e5_wp, CN_RATIO = 0.05_wp, DL = 0.02_wp, LDOT = 0.3_wp + TYPE(CD_ModelType) :: a, b + TYPE(GenAlphaConfig) :: cfg + INTEGER :: conn(2, NE), fixed(6), es, n_iter, i + REAL(wp) :: l0(NE), l1(NE), ea(NE), rho_a(NE), ba(NE), diam(NE), q0(NDOF), v0(NDOF), wpl(3, NE) + REAL(wp) :: fw(NDOF), fw1(NDOF), lm(NE), af + REAL(wp), ALLOCATABLE :: kn(:), kn1(:) + LOGICAL :: conv, stalled + CHARACTER(200) :: em + + CALL straight_cable(NE, conn, l0, ea, rho_a, q0, fixed) + v0 = 0.0_wp + DO i = 4, NDOF - 3 + v0(i) = 0.05_wp*SIN(1.3_wp*REAL(i, wp)) + END DO + wpl = 0.0_wp + wpl(3, :) = -7.5_wp + ba = 50.0_wp + diam = 0.1_wp + l1 = l0 + l1(NE) = l0(NE) + DL + CALL CD_Assemble_Distributed_Load(conn, l0, wpl, fw, es, em) + CALL CD_Assemble_Distributed_Load(conn, l1, wpl, fw1, es, em) + CALL CD_Nodal_Seabed_Stiffness(KBOT, diam, l0, kn, es, em) + CALL CD_Nodal_Seabed_Stiffness(KBOT, diam, l1, kn1, es, em) + CALL require(es == 0, 'committed-side:seabed-helper') + af = cfg%rho_inf/(cfg%rho_inf + 1.0_wp) + lm = l0 + lm(NE) = (1.0_wp - af)*l1(NE) + af*l0(NE) + CALL CD_Init_Model(a, q0, v0, conn, l0, ea, rho_a, .TRUE., fw, fixed, cfg, es, em, ba=ba, & + dist_load_per_length=wpl, seabed_z_floor=1.0e-3_wp, seabed_kn=kn, seabed_cn=CN_RATIO*kn, & + seabed_kbot=KBOT, seabed_contact_diameter=diam, seabed_cn_over_kn=CN_RATIO) + CALL require(es == CD_MODEL_OK, 'committed-side:init-a: '//TRIM(em)) + CALL CD_Init_Model(b, q0, v0, conn, l0, ea, rho_a, .TRUE., fw, fixed, cfg, es, em, ba=ba, & + dist_load_per_length=wpl, seabed_z_floor=1.0e-3_wp, seabed_kn=kn, seabed_cn=CN_RATIO*kn, & + seabed_kbot=KBOT, seabed_contact_diameter=diam, seabed_cn_over_kn=CN_RATIO) + CALL require(es == CD_MODEL_OK, 'committed-side:init-b: '//TRIM(em)) + IF (es /= CD_MODEL_OK) RETURN + CALL CD_Update_Model_SegmentLength(a, NE, l1(NE), LDOT, es, em) + CALL require(es == CD_MODEL_OK, 'committed-side:update: '//TRIM(em)) + CALL require(nan_max_abs(a%f_ext - fw1) <= 0.0_wp .AND. nan_max_abs(a%seabed_kn - kn1) <= 0.0_wp, & + 'committed-side:present-load-is-the-new-lengths') + ! the committed acceleration, re-derived, is the twin's + CALL CD_Recompute_Model_Acceleration(a, es, em) + CALL require(es == CD_MODEL_OK, 'committed-side:recompute-a: '//TRIM(em)) + CALL CD_Recompute_Model_Acceleration(b, es, em) + CALL require(es == CD_MODEL_OK, 'committed-side:recompute-b: '//TRIM(em)) + CALL require(nan_max_abs(a%a - b%a) <= 0.0_wp, 'committed-side:recompute-equals-twin') + CALL require(nan_max_abs(a%f_ext - fw1) <= 0.0_wp .AND. nan_max_abs(a%seabed_kn - kn1) <= 0.0_wp .AND. & + nan_max_abs(a%seabed_cn - CN_RATIO*kn1) <= 0.0_wp .AND. nan_max_abs(a%l0 - l1) <= 0.0_wp .AND. & + a%l0_dot(NE) == LDOT .AND. nan_max_abs(a%l0_c - l0) <= 0.0_wp, 'committed-side:recompute-restores') + ! the step: the committed side bit for bit the twin's + CALL CD_Step_Model(a, 0.02_wp, conv, stalled, n_iter, es, em) + CALL require(es == CD_MODEL_OK .AND. conv, 'committed-side:step-a: '//TRIM(em)) + CALL CD_Step_Model(b, 0.02_wp, conv, stalled, n_iter, es, em) + CALL require(es == CD_MODEL_OK .AND. conv, 'committed-side:step-b: '//TRIM(em)) + IF (.NOT. (ALLOCATED(a%load_start_work) .AND. ALLOCATED(b%load_start_work))) THEN + CALL require(.FALSE., 'committed-side:start-load-allocated') + RETURN + END IF + CALL require(nan_max_abs(a%load_start_work - b%load_start_work) <= 0.0_wp, 'committed-side:start-load-equals-twin') + CALL require(nan_max_abs(a%dynamic_workspace%fint_n - b%dynamic_workspace%fint_n) <= 0.0_wp .AND. & + nan_max_abs(a%dynamic_workspace%tension_n - b%dynamic_workspace%tension_n) <= 0.0_wp .AND. & + nan_max_abs(a%dynamic_workspace%stretch_n - b%dynamic_workspace%stretch_n) <= 0.0_wp .AND. & + nan_max_abs(a%dynamic_workspace%damp_n - b%dynamic_workspace%damp_n) <= 0.0_wp, & + 'committed-side:start-force-and-cap-data-equal-twin') + CALL require(MAXVAL(ABS(b%dynamic_workspace%damp_n)) > 0.0_wp, 'committed-side:start-dashpot-nonzero') + CALL require(MAXVAL(ABS(b%load_start_work)) > 0.0_wp .AND. MAXVAL(b%dynamic_workspace%tension_n) > 0.0_wp, & + 'committed-side:start-data-nonzero') + CALL require(nan_max_abs(a%dynamic_workspace%mb_l0 - lm) <= 0.0_wp, 'committed-side:inertia-at-blended-lengths') + CALL require(nan_max_abs(a%q - b%q) > 0.0_wp, 'committed-side:command-moves-the-line') + CALL require(nan_max_abs(a%f_ext - fw1) <= 0.0_wp .AND. nan_max_abs(a%l0 - l1) <= 0.0_wp .AND. & + nan_max_abs(a%l0_c - l1) <= 0.0_wp .AND. a%l0_dot_c(NE) == LDOT, 'committed-side:step-commits') + CALL CD_End_Model(a, es, em) + CALL CD_End_Model(b, es, em) + + ! An external-load update between the command and the step: the committed acceleration it + ! re-derives carries the new load (the distributed-load remainder is refreshed before the + ! committed external load is rebuilt from it), as the uncommanded twin given the same load. + BLOCK + REAL(wp) :: bump(NDOF), scale_a + bump = 0.0_wp + bump(3*2 - 1) = 3.0_wp + bump(3*3) = -4.0_wp + CALL CD_Init_Model(a, q0, v0, conn, l0, ea, rho_a, .TRUE., fw, fixed, cfg, es, em, ba=ba, & + dist_load_per_length=wpl, seabed_z_floor=1.0e-3_wp, seabed_kn=kn, seabed_cn=CN_RATIO*kn, & + seabed_kbot=KBOT, seabed_contact_diameter=diam, seabed_cn_over_kn=CN_RATIO) + CALL CD_Init_Model(b, q0, v0, conn, l0, ea, rho_a, .TRUE., fw, fixed, cfg, es, em, ba=ba, & + dist_load_per_length=wpl, seabed_z_floor=1.0e-3_wp, seabed_kn=kn, seabed_cn=CN_RATIO*kn, & + seabed_kbot=KBOT, seabed_contact_diameter=diam, seabed_cn_over_kn=CN_RATIO) + CALL require(es == CD_MODEL_OK, 'committed-side:extload-init: '//TRIM(em)) + CALL CD_Update_Model_SegmentLength(a, NE, l1(NE), LDOT, es, em) + CALL require(es == CD_MODEL_OK, 'committed-side:extload-command: '//TRIM(em)) + CALL CD_Update_Model_External_Loads(a, fw1 + bump, es, em) + CALL require(es == CD_MODEL_OK, 'committed-side:extload-update-a: '//TRIM(em)) + CALL CD_Update_Model_External_Loads(b, fw + bump, es, em) + CALL require(es == CD_MODEL_OK, 'committed-side:extload-update-b: '//TRIM(em)) + scale_a = MAXVAL(ABS(b%a)) + CALL require(scale_a > 0.0_wp .AND. nan_max_abs(a%a - b%a) <= 1.0e-12_wp*scale_a, & + 'committed-side:extload-recompute-equals-twin') + CALL require(nan_max_abs(a%f_ext - (fw1 + bump)) <= 0.0_wp .AND. nan_max_abs(a%l0_c - l0) <= 0.0_wp, & + 'committed-side:extload-keeps-present-load-and-committed-lengths') + CALL CD_End_Model(a, es, em) + CALL CD_End_Model(b, es, em) + END BLOCK + END SUBROUTINE case_segment_force_blend_committed_side + SUBROUTINE case_copy_model_preserves_state() !! Checked model copies preserve persistent state and leave transient solver !! workspaces independent of the source object. diff --git a/tests/test_openfast_aggregate.f90 b/tests/test_openfast_aggregate.f90 index c3a2a6da..67e5db9a 100644 --- a/tests/test_openfast_aggregate.f90 +++ b/tests/test_openfast_aggregate.f90 @@ -20,6 +20,8 @@ PROGRAM test_openfast_aggregate !! 7) ptfm_init_equivalence -- the ptfm_init option == a pre-displaced deck, bit-for-bit, !! against an independent transcription of the NWTC ZYX transform; zero == absent; !! non-finite fails closed. + !! 8) line control -- CONTROL on EI=0 lines and finite-EI cables (alone and mixed), its + !! fail-closed bounds, rewind and bit-identical checkpoint restart (--line-control-only). USE CableDyn_Precision, ONLY: wp USE CableDyn_DeckDriver, ONLY: CD_Deck_Query_dtM, CD_DECKDRV_OK USE CableDyn_OpenFAST_Aggregate, ONLY: CD_AGG_ModuleType, CD_AGG_Init_From_Deck, CD_AGG_NMovingPoints, & @@ -60,7 +62,8 @@ PROGRAM test_openfast_aggregate CD_SystemType, CD_End_System, CD_System_Line_Has_Friction, & CD_Get_System_Line_Friction_Anchors, CD_Set_System_Line_Friction_Anchors USE CableDyn_DeckDriver, ONLY: CD_Init_Deck_System - USE CableDyn_OpenFAST_HermiteFMF, ONLY: CD_HFMF_FrictionMirrorSize + USE CableDyn_OpenFAST_HermiteFMF, ONLY: CD_HFMF_FrictionMirrorSize, CD_HFMF_ModuleType, CD_HFMF_End + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: INT64 USE, INTRINSIC :: IEEE_ARITHMETIC, ONLY: IEEE_IS_FINITE, IEEE_VALUE, IEEE_QUIET_NAN USE, INTRINSIC :: IEEE_EXCEPTIONS, ONLY: IEEE_USUAL, IEEE_GET_HALTING_MODE, IEEE_SET_HALTING_MODE, IEEE_SET_FLAG IMPLICIT NONE @@ -111,6 +114,17 @@ PROGRAM test_openfast_aggregate WRITE (*, '(A)') 'PASS: displaced semitaut mooring initialisation' STOP END IF + IF (TRIM(test_filter) == '--line-control-only') THEN + CALL case_aggregate_line_control() + CALL case_aggregate_cable_control() + CALL case_restart_cable_control() + IF (nfail > 0) THEN + WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' line-control assertion(s) failed' + ERROR STOP 1 + END IF + WRITE (*, '(A)') 'PASS: coupled active line control' + STOP + END IF END IF CALL case_pure_mooring_equals_fmf() CALL case_mixed_deck_composition() @@ -151,6 +165,9 @@ PROGRAM test_openfast_aggregate CALL case_farm_shared_anchor() CALL case_aggregate_failures() CALL case_aggregate_line_control() + CALL case_aggregate_cable_control() + CALL case_restart_cable_control() + CALL case_restart_line_control() CALL case_restart_equivalence() CALL case_restart_friction() IF (nfail > 0) THEN @@ -3134,9 +3151,12 @@ SUBROUTINE case_aggregate_line_control() CALL require(es == CD_AGG_OK, 'aggctrl: control init: '//TRIM(em)) CALL require(CD_AGG_NCtrlChans(aggc) == 1 .AND. CD_AGG_NCtrlChans(agg) == 0, 'aggctrl: channel counts') - ! (a) zero command == never applied, bit-identical loads after one step - CALL CD_AGG_Apply_LineControl(aggc, [0.0_wp], [0.0_wp], es, em) + ! (a) zero command == never applied, bit-identical loads after one step; the rate is -0 + ! (a host's negated zero), which must count as +0 + CALL CD_AGG_Apply_LineControl(aggc, [0.0_wp], [SIGN(0.0_wp, -1.0_wp)], es, em) CALL require(es == CD_AGG_OK, 'aggctrl: zero apply: '//TRIM(em)) + CALL require(TRANSFER(aggc%sys%fast%system%lines(aggc%ctrl_line(1))%l0_dot(aggc%ctrl_elem(1)), 0_INT64) == & + 0_INT64, 'aggctrl: a rate of -0 is stored as +0') CALL CD_AGG_GetMovingPointMesh(agg, q0, v0, a0, lf, es, em) v0 = 0.0_wp a0 = 0.0_wp @@ -3206,9 +3226,10 @@ SUBROUTINE case_aggregate_line_control() CALL CD_AGG_End(aggd, es, em) END BLOCK - ! (b3) ATOMIC command validation: with one channel driving BOTH lines - ! (bases 0.98 and 0.48 on the composite deck), a command invalid only for the - ! SECOND row must leave the FIRST line untouched -- pre-fix the loop had + ! (b3) ATOMIC command validation: with one channel driving BOTH lines (line 1 of + ! 0.98 m in one segment, line 2 of 0.50 + 0.48 m in two, MoorDyn-F's UnstrLen/N 0.98 and + ! 0.49 m), a command invalid only for the SECOND row (-0.3 m is within half of 0.98 m + ! but not of 0.49 m) must leave the FIRST line untouched -- pre-fix the loop had ! already updated it before hitting the bad row. BLOCK TYPE(CD_AGG_ModuleType) :: agga @@ -3220,14 +3241,42 @@ SUBROUTINE case_aggregate_line_control() ne1 = CD_System_Line_NElem(agga%sys%fast%system, 1, es, em) ALLOCATE (t1b(ne1), t1a(ne1)) CALL CD_Get_System_Line_Tension(agga%sys%fast%system, 1, t1b, es, em) - CALL CD_AGG_Apply_LineControl(agga, [-0.6_wp], [0.0_wp], es, em) - CALL require(es /= CD_AGG_OK, 'aggctrl: atomic bad-row command fails closed') + CALL CD_AGG_Apply_LineControl(agga, [-0.3_wp], [0.0_wp], es, em) + CALL require(es /= CD_AGG_OK .AND. INDEX(em, 'EI = 0 line 2') > 0, & + 'aggctrl: atomic bad-row command fails closed by the second line') CALL CD_Get_System_Line_Tension(agga%sys%fast%system, 1, t1a, es, em) CALL require(nan_max_abs(t1a - t1b) <= 0.0_wp, & 'aggctrl: a rejected command leaves every line bit-identical (no partial apply)') + ! MoorDyn-F bounds the command by UnstrLen/N of the whole line, not by the controlled + ! segment: on line 2 (controlled segment 0.48 m, UnstrLen/N = 0.49 m) a pay-out of + ! 0.49 m is accepted, as MoorDyn-F accepts it + CALL require(agga%ctrl_nsegs(2) == 2 .AND. ABS(agga%ctrl_unstr_len(2) - 0.98_wp) <= 1.0e-15_wp .AND. & + ABS(agga%ctrl_base_l0(2) - 0.48_wp) <= 1.0e-15_wp, 'aggctrl: line 2 is 0.98 m in two segments') + CALL CD_AGG_Apply_LineControl(agga, [agga%ctrl_unstr_len(2)/REAL(agga%ctrl_nsegs(2), wp)], [0.0_wp], es, em) + CALL require(es == CD_AGG_OK, 'aggctrl: a pay-out of UnstrLen/N > S is accepted, as in MoorDyn-F: '//TRIM(em)) CALL CD_AGG_End(agga, es, em) END BLOCK + ! (b3') a controlled segment shorter than half of UnstrLen/N: a haul-in within MoorDyn-F's + ! bounds that would make it non-positive fails closed by name and writes nothing + BLOCK + TYPE(CD_AGG_ModuleType) :: aggn + REAL(wp), ALLOCATABLE :: keep(:) + CALL write_agg_failure_deck('agg_ctrl_short.dat', control_row='1 2', composite_line2=.TRUE., & + short_tail2=.TRUE.) + CALL CD_AGG_Init_From_Deck(aggn, 'agg_ctrl_short.dat', DT, es, em) + CALL require(es == CD_AGG_OK, 'aggctrl: short-segment deck init: '//TRIM(em)) + IF (es == CD_AGG_OK) THEN + keep = aggn%sys%fast%system%lines(2)%l0 + CALL require(ABS(aggn%ctrl_base_l0(1) - 0.08_wp) <= 1.0e-15_wp, 'aggctrl: the controlled segment is 0.08 m') + CALL CD_AGG_Apply_LineControl(aggn, [-0.2_wp], [0.0_wp], es, em) + CALL require(es /= CD_AGG_OK .AND. INDEX(em, 'EI = 0 line 2') > 0 .AND. INDEX(em, 'non-positive') > 0, & + 'aggctrl: a haul-in that would make the segment non-positive fails closed by name') + CALL require(ALL(aggn%sys%fast%system%lines(2)%l0 == keep), 'aggctrl: the refused haul-in writes nothing') + END IF + CALL CD_AGG_End(aggn, es, em) + END BLOCK + ! (b4) REWIND: a command applied after a snapshot must roll back WITH the ! states -- l0, mass, seabed coefficients, and the distributed-load remainder ! all restore, so the tensions return bit-identically without any re-apply. @@ -3264,26 +3313,612 @@ SUBROUTINE case_aggregate_line_control() 'aggctrl: FAILURE trailing token fails closed') END BLOCK + ! (b6) the controlled segment is the one at the line's fairlead-side end: the end on a + ! host-driven point, else the written NodeB (MoorDyn's AttachB, its segment N). Line 1 + ! is Connect -> Vessel kept in deck order (the vessel is End B of the built model): the + ! vessel-side element is controlled, not the one at the Connect. Line 2 (Connect and + ! Fixed, no host-driven end) controls the element at its written NodeB: the anchor + ! when written Connect -> Fixed (End B); written Fixed -> Connect it is swapped (the + ! Connect is End A) and controls the End-A element. + BLOCK + TYPE(CD_AGG_ModuleType) :: aggv, aggs + REAL(wp) :: qn(9), vn(9), an(9), l1(2), l2(2) + CALL write_agg_failure_deck('agg_ctrl_attachb.dat', control_row='1 1,2', composite_line1=.TRUE., & + composite_line2=.TRUE.) + CALL CD_AGG_Init_From_Deck(aggv, 'agg_ctrl_attachb.dat', DT, es, em) + CALL require(es == CD_AGG_OK, 'aggctrl: AttachB deck init: '//TRIM(em)) + IF (es == CD_AGG_OK) THEN + l1 = aggv%sys%fast%system%lines(1)%l0 + l2 = aggv%sys%fast%system%lines(2)%l0 + CALL require(ALL(aggv%ctrl_elem == [1, 1]), 'aggctrl: lines kept in deck order control their End-B element') + CALL CD_AGG_Apply_LineControl(aggv, [0.05_wp], [0.0_wp], es, em) + CALL require(es == CD_AGG_OK, 'aggctrl: AttachB apply: '//TRIM(em)) + CALL CD_Get_System_Line_State(aggv%sys%fast%system, 1, qn, vn, an, es, em) + CALL require(nan_max_abs(qn(1:3)) <= 1.0e-12_wp .AND. & + aggv%sys%fast%system%lines(1)%l0(1) == l1(1) + 0.05_wp .AND. & + aggv%sys%fast%system%lines(1)%l0(2) == l1(2), & + 'aggctrl: a Connect -> Vessel line in stock order controls the vessel-end segment') + CALL CD_Get_System_Line_State(aggv%sys%fast%system, 2, qn, vn, an, es, em) + CALL require(nan_max_abs(qn(1:3) - [2.0_wp, 0.0_wp, 0.0_wp]) <= 1.0e-12_wp .AND. & + aggv%sys%fast%system%lines(2)%l0(1) == l2(1) + 0.05_wp .AND. & + aggv%sys%fast%system%lines(2)%l0(2) == l2(2), & + 'aggctrl: a line without a host-driven end controls its written-NodeB segment') + END IF + CALL write_agg_failure_deck('agg_ctrl_stock.dat', control_row='1 2', composite_line2=.TRUE., & + stock_line2=.TRUE.) + CALL CD_AGG_Init_From_Deck(aggs, 'agg_ctrl_stock.dat', DT, es, em) + CALL require(es == CD_AGG_OK, 'aggctrl: stock-order deck init: '//TRIM(em)) + IF (es == CD_AGG_OK) THEN + CALL require(ALL(aggs%sys%fast%system%lines(2)%l0 == l2) .AND. aggs%ctrl_elem(1) == 2, & + 'aggctrl: a swapped line builds the same model and controls its End-A element') + CALL CD_AGG_Apply_LineControl(aggs, [0.05_wp], [0.0_wp], es, em) + CALL require(es == CD_AGG_OK .AND. aggs%sys%fast%system%lines(2)%l0(2) == l2(2) + 0.05_wp .AND. & + aggs%sys%fast%system%lines(2)%l0(1) == l2(1), & + 'aggctrl: the swapped line controls its written-NodeB (Connect) segment') + END IF + CALL CD_AGG_End(aggv, es, em) + CALL CD_AGG_End(aggs, es, em) + END BLOCK + + ! (b7) a coupled rod end is host-driven: a line written anchor first to a Coupled rod's + ! End B is kept in deck order (the swap only matches points) and controls its End-B + ! element, the rod end; the same line to a Coupled point at that position is swapped and + ! controls its End-A element, the same physical end. Written fairlead first from the rod + ! end it controls its End-A element. + BLOCK + TYPE(CD_AGG_ModuleType) :: aggr, aggp + INTEGER :: ner + CALL write_host_rod_deck('agg_ctrl_rod.dat', .FALSE., control_row='1 1', stock_line1=.TRUE.) + CALL CD_AGG_Init_From_Deck(aggr, 'agg_ctrl_rod.dat', DT, es, em) + CALL require(es == CD_AGG_OK, 'aggctrl: rod deck init: '//TRIM(em)) + CALL write_host_rod_deck('agg_ctrl_rod_pts.dat', .TRUE., control_row='1 1', stock_line1=.TRUE.) + CALL CD_AGG_Init_From_Deck(aggp, 'agg_ctrl_rod_pts.dat', DT, es, em) + CALL require(es == CD_AGG_OK, 'aggctrl: rod-as-points deck init: '//TRIM(em)) + IF (CD_AGG_IsInitialized(aggr) .AND. CD_AGG_IsInitialized(aggp)) THEN + ner = SIZE(aggr%sys%fast%system%lines(1)%l0) + CALL require(aggr%ctrl_elem(1) == 1 .AND. aggp%ctrl_elem(1) == ner, & + 'aggctrl: a line to a coupled rod end controls the segment at the rod end') + END IF + CALL CD_AGG_End(aggr, es, em) + CALL CD_AGG_End(aggp, es, em) + CALL write_host_rod_deck('agg_ctrl_rod_ff.dat', .FALSE., control_row='1 1') + CALL CD_AGG_Init_From_Deck(aggr, 'agg_ctrl_rod_ff.dat', DT, es, em) + CALL require(es == CD_AGG_OK, 'aggctrl: fairlead-first rod deck init: '//TRIM(em)) + IF (es == CD_AGG_OK) THEN + CALL require(aggr%ctrl_elem(1) == SIZE(aggr%sys%fast%system%lines(1)%l0), & + 'aggctrl: a line written fairlead first from a coupled rod end controls its End-A element') + END IF + CALL CD_AGG_End(aggr, es, em) + END BLOCK + ! (c) fail-closed battery CALL CD_AGG_Apply_LineControl(aggc, [REAL(wp) ::], [REAL(wp) ::], es, em) CALL require(es /= CD_AGG_OK, 'aggctrl: short command vector fails closed') CALL CD_AGG_Apply_LineControl(aggc, [-1.0_wp], [0.0_wp], es, em) CALL require(es /= CD_AGG_OK, 'aggctrl: non-positive segment length fails closed') + ! (d) MoorDyn-F's bounds (MoorDyn.f90, ErrID_Fatal): an increase of more than UnstrLen/N + ! or a reduction of more than half of it stops the run by line, command and bound, and + ! writes nothing; the bounds themselves are allowed, as in MoorDyn-F. + BLOCK + REAL(wp) :: s_base, l_keep + INTEGER :: il, ie + il = aggc%ctrl_line(1) + ie = aggc%ctrl_elem(1) + s_base = aggc%ctrl_unstr_len(1)/REAL(aggc%ctrl_nsegs(1), wp) + CALL require(s_base == aggc%ctrl_base_l0(1), 'aggctrl: on a uniform line UnstrLen/N is the segment length') + CALL CD_AGG_Apply_LineControl(aggc, [s_base], [0.0_wp], es, em) + CALL require(es == CD_AGG_OK, 'aggctrl: a pay-out of one segment length is within the bounds: '//TRIM(em)) + CALL CD_AGG_Apply_LineControl(aggc, [-0.5_wp*aggc%ctrl_unstr_len(1)/REAL(aggc%ctrl_nsegs(1), wp)], [0.0_wp], & + es, em) + CALL require(es == CD_AGG_OK, 'aggctrl: a haul-in of half a segment length is within the bounds: '//TRIM(em)) + l_keep = aggc%sys%fast%system%lines(il)%l0(ie) + CALL CD_AGG_Apply_LineControl(aggc, [1.01_wp*s_base], [0.0_wp], es, em) + CALL require(es /= CD_AGG_OK .AND. INDEX(em, 'EI = 0 line 2') > 0 .AND. INDEX(em, 'MoorDyn-F') > 0 .AND. & + INDEX(em, '-S/2 <= DeltaL <= S') > 0 .AND. INDEX(em, 'UnstrLen/N') > 0, & + 'aggctrl: a pay-out beyond one segment length stops by line and bound') + CALL require(aggc%sys%fast%system%lines(il)%l0(ie) == l_keep, 'aggctrl: a refused pay-out writes nothing') + CALL CD_AGG_Apply_LineControl(aggc, [-0.51_wp*s_base], [0.0_wp], es, em) + CALL require(es /= CD_AGG_OK .AND. INDEX(em, 'EI = 0 line 2') > 0, & + 'aggctrl: a haul-in beyond half a segment length stops by line') + CALL require(aggc%sys%fast%system%lines(il)%l0(ie) == l_keep, 'aggctrl: a refused haul-in writes nothing') + END BLOCK + CALL CD_AGG_End(agg, es, em) CALL CD_AGG_End(aggc, es, em) END SUBROUTINE case_aggregate_line_control - SUBROUTINE write_agg_failure_deck(path, failure_row, control_row, composite_line2) + SUBROUTINE case_aggregate_cable_control() + !! Active line control of finite-EI cables on the coupled aggregate: + !! (a) a cable-only deck controls the trailing span of cable elements that makes up the + !! deck's fairlead-side segment (40/13 m), whether the line is written anchor first + !! (MoorDyn order) or fairlead first; a zero command is bit-identical to no control + !! over a driven march; + !! (b) a pay-out scales every span element by (S + DeltaL)/S, leaves the rest, and the + !! next step converges; + !! (c) a command outside MoorDyn-F's bounds -UnstrLen/N/2 <= DeltaL <= UnstrLen/N (145 m + !! in 47 segments; the controlled segment is 40/13 m) fails closed, naming the line, + !! and writes nothing; the bounds themselves are accepted, as in MoorDyn-F, even + !! where they scale the segment by more than 2; + !! (d) an aggregate snapshot rewinds a command with the cable's caches; + !! (e) MIXED deck (cable = deck line 1, chain = deck line 2): the chain resolves to EI = 0 + !! system line 1 -- its rank among the EI = 0 lines, not its deck position -- and one + !! channel drives both kinds; + !! (f) CONTROL with a finite-EI cable in FAST.Farm fails closed by name; + !! (g) on a mesh the static initialisation refined (adaptive_mesh), the span is the + !! children of the fairlead-side segment, and the command scales all of them. + TYPE(CD_AGG_ModuleType) :: agg, aggc + REAL(wp), PARAMETER :: DT = 0.05_wp + REAL(wp) :: r0(3, 1), v0(3, 1), a0(3, 1), tgt(3, 1), lf(3, 1), lc(3, 1), pf(3, 1), vf(3, 1), af(3, 1) + REAL(wp), ALLOCATABLE :: l0_base(:), l0_keep(:), mgb_keep(:, :) + REAL(wp) :: s_span, lam, t + INTEGER :: es, ni, k, ne, first + LOGICAL :: cv, st, bit_same + CHARACTER(512) :: em + + CALL write_cable_only_deck('agg_cable_plain.dat', stock_order=.TRUE.) + CALL write_cable_only_deck('agg_cable_ctrl.dat', control_row='1 1', stock_order=.TRUE.) + CALL CD_AGG_Init_From_Deck(agg, 'agg_cable_plain.dat', DT, es, em) + CALL require(es == CD_AGG_OK, 'cablectrl: plain init: '//TRIM(em)) + CALL CD_AGG_Init_From_Deck(aggc, 'agg_cable_ctrl.dat', DT, es, em) + CALL require(es == CD_AGG_OK, 'cablectrl: a finite-EI cable with CONTROL initialises: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + CALL require(CD_AGG_NCtrlChans(aggc) == 1 .AND. SIZE(aggc%ctrl_chan) == 1, 'cablectrl: one channel, one row') + CALL require(aggc%ctrl_is_cable(1) .AND. aggc%ctrl_line(1) == 1 .AND. aggc%ctrl_line_id(1) == 1, & + 'cablectrl: the row addresses cable 1, deck line 1') + ne = aggc%cables(1)%line%ne + first = aggc%ctrl_elem(1) + s_span = SUM(aggc%cables(1)%line%l0(first:ne)) + CALL require(first >= 1 .AND. first <= ne .AND. ABS(s_span - 40.0_wp/13.0_wp) <= 1.0e-12_wp*s_span .AND. & + ABS(aggc%ctrl_base_l0(1) - s_span) <= 0.0_wp, & + 'cablectrl: the span is the trailing elements of the 40/13 m fairlead-side segment') + IF (first > 1) CALL require(SUM(aggc%cables(1)%line%l0(first - 1:ne)) > 40.0_wp/13.0_wp + 1.0e-9_wp, & + 'cablectrl: the span stops at the segment boundary') + l0_base = aggc%cables(1)%line%l0 + ! the same cable written fairlead first builds the same model and controls the same + ! fairlead-side span + BLOCK + TYPE(CD_AGG_ModuleType) :: aggf + INTEGER :: nf + CALL write_cable_only_deck('agg_cable_ctrl_ff.dat', control_row='1 1') + CALL CD_AGG_Init_From_Deck(aggf, 'agg_cable_ctrl_ff.dat', DT, es, em) + CALL require(es == CD_AGG_OK, 'cablectrl: fairlead-first deck init: '//TRIM(em)) + IF (es == CD_AGG_OK) THEN + nf = aggf%ctrl_nelem(1) + CALL require(aggf%ctrl_elem(1) == first .AND. nf == ne - first + 1 .AND. & + aggf%ctrl_base_l0(1) == aggc%ctrl_base_l0(1) .AND. ALL(aggf%cables(1)%line%l0 == l0_base), & + 'cablectrl: a cable written fairlead first controls the same fairlead-side span') + END IF + CALL CD_AGG_End(aggf, es, em) + END BLOCK + + ! (a) zero command == never controlled, bit for bit, under a driven fairlead + CALL CD_AGG_GetMovingPointMesh(agg, r0, v0, a0, lf, es, em) + tgt = r0 + v0 = 0.0_wp + a0 = 0.0_wp + bit_same = .TRUE. + DO k = 1, 4 + t = REAL(k, wp)*DT + tgt(1, 1) = r0(1, 1) + 0.2_wp*(1.0_wp - COS(2.0_wp*PI*t/2.0_wp)) + v0(1, 1) = 0.2_wp*(2.0_wp*PI/2.0_wp)*SIN(2.0_wp*PI*t/2.0_wp) + ! the rate alternates between +0 and -0 (a host's negated zero): both are inert + CALL CD_AGG_Apply_LineControl(aggc, [0.0_wp], [SIGN(0.0_wp, REAL(1 - 2*MOD(k, 2), wp))], es, em) + CALL require(es == CD_AGG_OK, 'cablectrl: zero apply: '//TRIM(em)) + CALL CD_AGG_Step_Moving(agg, DT, tgt, v0, a0, cv, st, ni, es, em) + CALL require(es == CD_AGG_OK .AND. cv, 'cablectrl: plain step: '//TRIM(em)) + CALL CD_AGG_Step_Moving(aggc, DT, tgt, v0, a0, cv, st, ni, es, em) + CALL require(es == CD_AGG_OK .AND. cv, 'cablectrl: controlled step: '//TRIM(em)) + CALL CD_AGG_CalcOutput(agg, es, em) + CALL CD_AGG_CalcOutput(aggc, es, em) + CALL CD_AGG_GetMovingPointMesh(agg, pf, vf, af, lf, es, em) + CALL CD_AGG_GetMovingPointMesh(aggc, pf, vf, af, lc, es, em) + bit_same = bit_same .AND. nan_max_abs(lc - lf) <= 0.0_wp .AND. & + nan_max_abs(aggc%cables(1)%line%q - agg%cables(1)%line%q) <= 0.0_wp + END DO + CALL require(bit_same .AND. .NOT. aggc%cables(1)%line%has_ctrl, & + 'cablectrl: a zero command is bit-identical to an uncontrolled cable') + + ! (b) pay-out: every span element scales by (S + DeltaL)/S, the rest is untouched + lam = (s_span + 0.4_wp)/s_span + CALL CD_AGG_Apply_LineControl(aggc, [0.4_wp], [0.1_wp], es, em) + CALL require(es == CD_AGG_OK, 'cablectrl: pay-out apply: '//TRIM(em)) + CALL require(ALL(aggc%cables(1)%line%l0(first:ne) == l0_base(first:ne)*lam) .AND. & + ALL(aggc%cables(1)%line%l0(1:first - 1) == l0_base(1:first - 1)), & + 'cablectrl: the span scales by (S + DeltaL)/S and nothing else moves') + CALL require(ABS(SUM(aggc%cables(1)%line%l0(first:ne)) - (s_span + 0.4_wp)) <= 1.0e-12_wp*s_span, & + 'cablectrl: the controlled segment is S + DeltaL long') + CALL require(ALL(ABS(aggc%cables(1)%line%l0_dot(first:ne) - 0.1_wp*l0_base(first:ne)/s_span) <= & + 1.0e-15_wp) .AND. ALL(aggc%cables(1)%line%l0_dot(1:first - 1) == 0.0_wp), & + 'cablectrl: each span element carries DeltaLdot l_e/S') + CALL CD_AGG_Step_Moving(aggc, DT, tgt, v0, a0, cv, st, ni, es, em) + CALL require(es == CD_AGG_OK .AND. cv, 'cablectrl: the step after a pay-out converges: '//TRIM(em)) + + ! (c) MoorDyn-F's bounds: refused outside, writing nothing; accepted on them + BLOCK + REAL(wp) :: bound + CALL require(aggc%ctrl_nsegs(1) == 47 .AND. ABS(aggc%ctrl_unstr_len(1) - 145.0_wp) <= 1.0e-12_wp, & + 'cablectrl: UnstrLen and N of the line') + bound = aggc%ctrl_unstr_len(1)/REAL(aggc%ctrl_nsegs(1), wp) + l0_keep = aggc%cables(1)%line%l0 + CALL CD_AGG_Apply_LineControl(aggc, [-0.51_wp*bound], [0.0_wp], es, em) + CALL require(es /= CD_AGG_OK .AND. INDEX(em, 'finite-EI line 1') > 0 .AND. INDEX(em, 'MoorDyn-F') > 0, & + 'cablectrl: a haul-in beyond half of UnstrLen/N fails closed by line') + CALL CD_AGG_Apply_LineControl(aggc, [1.01_wp*bound], [0.0_wp], es, em) + CALL require(es /= CD_AGG_OK .AND. INDEX(em, 'finite-EI line 1') > 0, & + 'cablectrl: a pay-out beyond UnstrLen/N fails closed by line') + CALL require(ALL(aggc%cables(1)%line%l0 == l0_keep), 'cablectrl: a refused command writes nothing') + CALL CD_AGG_Apply_LineControl(aggc, [bound], [0.0_wp], es, em) + CALL require(es == CD_AGG_OK .AND. bound > s_span, & + 'cablectrl: a pay-out of UnstrLen/N (> S) is accepted, as in MoorDyn-F: '//TRIM(em)) + CALL CD_AGG_Apply_LineControl(aggc, [-0.5_wp*aggc%ctrl_unstr_len(1)/REAL(aggc%ctrl_nsegs(1), wp)], [0.0_wp], & + es, em) + CALL require(es == CD_AGG_OK, 'cablectrl: a haul-in of half of UnstrLen/N is accepted: '//TRIM(em)) + ! back to the pay-out of (b), which (d) restores to + CALL CD_AGG_Apply_LineControl(aggc, [0.4_wp], [0.1_wp], es, em) + CALL require(es == CD_AGG_OK .AND. ALL(aggc%cables(1)%line%l0 == l0_keep), 'cablectrl: back to the pay-out') + END BLOCK + + ! (d) an aggregate snapshot rewinds a command, caches included + l0_keep = aggc%cables(1)%line%l0 + mgb_keep = aggc%cables(1)%line%Mgb + CALL CD_AGG_Snapshot(aggc, es, em) + CALL CD_AGG_Apply_LineControl(aggc, [-0.3_wp], [-0.2_wp], es, em) + CALL require(es == CD_AGG_OK .AND. ANY(aggc%cables(1)%line%Mgb /= mgb_keep), 'cablectrl: rewind apply') + CALL CD_AGG_Restore(aggc, es, em) + CALL require(es == CD_AGG_OK .AND. ALL(aggc%cables(1)%line%l0 == l0_keep) .AND. & + ALL(aggc%cables(1)%line%Mgb == mgb_keep) .AND. & + ALL(aggc%cables(1)%line%l0_dot(first:ne) == 0.1_wp*l0_base(first:ne)/s_span), & + 'cablectrl: the restore brings back the lengths, rates and mass bit for bit') + CALL CD_AGG_End(agg, es, em) + CALL CD_AGG_End(aggc, es, em) + + ! (e) MIXED deck: the chain is deck line 2 but system line 1 + BLOCK + TYPE(CD_AGG_ModuleType) :: aggm + REAL(wp), ALLOCATABLE :: tb(:), ta(:) + INTEGER :: nec + CALL write_mixed_deck('agg_mixed_ctrl.dat', control_row='1 2') + CALL CD_AGG_Init_From_Deck(aggm, 'agg_mixed_ctrl.dat', DT, es, em) + CALL require(es == CD_AGG_OK, 'cablectrl: mixed deck with a controlled chain: '//TRIM(em)) + IF (es == CD_AGG_OK) THEN + CALL require(.NOT. aggm%ctrl_is_cable(1) .AND. aggm%ctrl_line(1) == 1 .AND. aggm%ctrl_line_id(1) == 2, & + 'cablectrl: deck line 2 resolves to EI = 0 system line 1 (its rank, not its position)') + nec = CD_System_Line_NElem(aggm%sys%fast%system, 1, es, em) + ALLOCATE (tb(nec), ta(nec)) + CALL CD_Get_System_Line_Tension(aggm%sys%fast%system, 1, tb, es, em) + ! the chain is written fairlead first (Vessel NodeA, Fixed NodeB): its vessel end is + ! the fairlead side, End A of the built line (its last element) + CALL CD_AGG_Apply_LineControl(aggm, [0.5_wp], [0.0_wp], es, em) + CALL require(es == CD_AGG_OK .AND. aggm%ctrl_elem(1) == nec .AND. & + aggm%sys%fast%system%lines(1)%l0(nec) == aggm%ctrl_base_l0(1) + 0.5_wp, & + 'cablectrl: the chain''s fairlead segment is base + DeltaL: '//TRIM(em)) + CALL CD_Get_System_Line_Tension(aggm%sys%fast%system, 1, ta, es, em) + CALL require(ta(nec) < tb(nec), 'cablectrl: paying the chain out drops its fairlead tension') + CALL require(.NOT. aggm%cables(1)%line%has_ctrl, 'cablectrl: the cable is not touched') + END IF + CALL CD_AGG_End(aggm, es, em) + CALL write_mixed_deck('agg_mixed_ctrl2.dat', control_row='1 1,2') + CALL CD_AGG_Init_From_Deck(aggm, 'agg_mixed_ctrl2.dat', DT, es, em) + CALL require(es == CD_AGG_OK, 'cablectrl: mixed deck, one channel on both kinds: '//TRIM(em)) + IF (es == CD_AGG_OK) THEN + CALL require(aggm%ctrl_is_cable(1) .AND. .NOT. aggm%ctrl_is_cable(2) .AND. aggm%ctrl_line(2) == 1, & + 'cablectrl: rows for the cable and the chain') + CALL CD_AGG_Apply_LineControl(aggm, [0.3_wp], [0.0_wp], es, em) + nec = SIZE(aggm%sys%fast%system%lines(1)%l0) + CALL require(es == CD_AGG_OK .AND. aggm%cables(1)%line%has_ctrl .AND. & + aggm%sys%fast%system%lines(1)%l0(nec) == aggm%ctrl_base_l0(2) + 0.3_wp, & + 'cablectrl: one channel drives the cable span and the chain segment') + END IF + CALL CD_AGG_End(aggm, es, em) + ! a row that fails after the earlier rows changed their lines (a fault injected into the + ! table, past the prevalidation) takes those lines back bit for bit: the cable row first + ! (rows cable, chain), then the chain row first (rows chain, cable) + BLOCK + TYPE(CD_HFMF_ModuleType) :: cab_keep + REAL(wp), ALLOCATABLE :: l0c(:), ldc(:), fc(:), tc(:), tc2(:) + INTEGER :: keep_elem + CALL CD_AGG_Init_From_Deck(aggm, 'agg_mixed_ctrl2.dat', DT, es, em) + CALL require(es == CD_AGG_OK, 'cablectrl: injected-fault deck init: '//TRIM(em)) + IF (es == CD_AGG_OK) THEN + cab_keep = aggm%cables(1) + keep_elem = aggm%ctrl_elem(2) + aggm%ctrl_elem(2) = 0 + CALL CD_AGG_Apply_LineControl(aggm, [0.3_wp], [0.1_wp], es, em) + aggm%ctrl_elem(2) = keep_elem + CALL require(es /= CD_AGG_OK .AND. INDEX(em, 'line-control update failed') > 0, & + 'cablectrl: the injected chain-row fault fails the command') + CALL require(.NOT. aggm%cables(1)%line%has_ctrl .AND. .NOT. ALLOCATED(aggm%cables(1)%line%l0_dot) .AND. & + ALL(aggm%cables(1)%line%l0 == cab_keep%line%l0) .AND. & + ALL(aggm%cables(1)%line%Mgb == cab_keep%line%Mgb) .AND. & + ALL(aggm%cables(1)%line%trib == cab_keep%line%trib) .AND. & + (aggm%cables(1)%line%tr_valid .EQV. cab_keep%line%tr_valid), & + 'cablectrl: the cable the failed command had changed is taken back bit for bit') + CALL CD_HFMF_End(cab_keep) + END IF + CALL CD_AGG_End(aggm, es, em) + CALL write_mixed_deck('agg_mixed_ctrl3.dat', control_row='1 2,1') + CALL CD_AGG_Init_From_Deck(aggm, 'agg_mixed_ctrl3.dat', DT, es, em) + CALL require(es == CD_AGG_OK, 'cablectrl: chain-first deck init: '//TRIM(em)) + IF (es == CD_AGG_OK) THEN + CALL require(.NOT. aggm%ctrl_is_cable(1) .AND. aggm%ctrl_is_cable(2), 'cablectrl: rows chain, cable') + ! one command to give the chain a committed rate and length to come back to + CALL CD_AGG_Apply_LineControl(aggm, [0.2_wp], [0.05_wp], es, em, restored=.TRUE.) + CALL require(es == CD_AGG_OK, 'cablectrl: chain-first first command: '//TRIM(em)) + ASSOCIATE (chain => aggm%sys%fast%system%lines(1)) + l0c = chain%l0 + ldc = chain%l0_dot + fc = chain%f_ext + nec = SIZE(chain%l0) + ALLOCATE (tc(nec), tc2(nec)) + CALL CD_Get_System_Line_Tension(aggm%sys%fast%system, 1, tc, es, em) + keep_elem = aggm%ctrl_elem(2) + aggm%ctrl_elem(2) = 0 + CALL CD_AGG_Apply_LineControl(aggm, [0.4_wp], [0.1_wp], es, em) + aggm%ctrl_elem(2) = keep_elem + CALL require(es /= CD_AGG_OK .AND. INDEX(em, 'line-control update failed') > 0, & + 'cablectrl: the injected cable-row fault fails the command') + CALL CD_Get_System_Line_Tension(aggm%sys%fast%system, 1, tc2, es, em) + CALL require(ALL(chain%l0 == l0c) .AND. & + ALL(TRANSFER(chain%l0_dot, 0_INT64, nec) == TRANSFER(ldc, 0_INT64, nec)) .AND. & + ALL(chain%l0_c == l0c) .AND. ALL(chain%f_ext == fc) .AND. ALL(tc2 == tc), & + 'cablectrl: the chain the failed command had changed is taken back bit for bit') + END ASSOCIATE + END IF + CALL CD_AGG_End(aggm, es, em) + END BLOCK + END BLOCK + + ! a finite-EI line on the configuration-blended generalised-alpha cannot be controlled + BLOCK + TYPE(CD_AGG_ModuleType) :: aggb + CALL write_cable_only_deck('agg_cable_ctrl_cfgblend.dat', control_row='1 1', config_blend=.TRUE.) + CALL CD_AGG_Init_From_Deck(aggb, 'agg_cable_ctrl_cfgblend.dat', DT, es, em) + CALL require(es /= CD_AGG_OK .AND. INDEX(em, 'CONTROL line 1') > 0 .AND. INDEX(em, 'force-blended') > 0, & + 'cablectrl: CONTROL of a finite-EI line under the configuration blend fails closed by name') + CALL CD_AGG_End(aggb, es, em) + END BLOCK + + ! (g) a mesh the static initialisation refined: the fairlead-side deck segment is now + ! several cable elements, and the command scales all of them + BLOCK + TYPE(CD_AGG_ModuleType) :: aggr + REAL(wp), ALLOCATABLE :: base(:) + INTEGER :: ner, fr + CALL write_cable_only_deck('agg_cable_ctrl_refined.dat', control_row='1 1', adaptive_mesh=.TRUE., & + stock_order=.TRUE.) + CALL CD_AGG_Init_From_Deck(aggr, 'agg_cable_ctrl_refined.dat', DT, es, em) + CALL require(es == CD_AGG_OK, 'cablectrl: refined cable with CONTROL: '//TRIM(em)) + IF (es == CD_AGG_OK) THEN + ner = aggr%cables(1)%line%ne + fr = aggr%ctrl_elem(1) + WRITE (*, '(A,I0,A,I0,A)') ' cable control span on the refined mesh: ', ner - fr + 1, ' of ', ner, & + ' elements' + CALL require(ner > 47 .AND. MOD(ner, 47) == 0 .AND. ner - fr + 1 == ner/47, & + 'cablectrl: the span is the children of the refined fairlead-side segment') + CALL require(ABS(SUM(aggr%cables(1)%line%l0(fr:ner)) - 40.0_wp/13.0_wp) <= 1.0e-12_wp*40.0_wp, & + 'cablectrl: the refined span is the 40/13 m segment') + base = aggr%cables(1)%line%l0 + CALL CD_AGG_Apply_LineControl(aggr, [0.3_wp], [0.0_wp], es, em) + CALL require(es == CD_AGG_OK .AND. & + ALL(aggr%cables(1)%line%l0(fr:ner) == base(fr:ner)*((aggr%ctrl_base_l0(1) + 0.3_wp)/ & + aggr%ctrl_base_l0(1))) .AND. & + ALL(aggr%cables(1)%line%l0(1:fr - 1) == base(1:fr - 1)), & + 'cablectrl: the command scales every child of the segment and nothing else') + END IF + CALL CD_AGG_End(aggr, es, em) + END BLOCK + + ! (f) FAST.Farm: CONTROL on a deck with a finite-EI cable fails closed by name + BLOCK + INTEGER :: u, ios + OPEN (NEWUNIT=u, FILE='agg_farm_cable_ctrl.dat', STATUS='REPLACE', ACTION='WRITE', IOSTAT=ios) + WRITE (u, '(A)') 'farm deck with one finite-EI cable and a CONTROL row' + 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)') 'bare 0.16 36.70 4.69e8 0.0 1.99e4 1.2 0.1 1.0 0.0' + WRITE (u, '(A)') '--- POINTS ---' + WRITE (u, '(A)') 'ID Type X Y Z' + WRITE (u, '(A)') '(-) (-) (m) (m) (m)' + WRITE (u, '(A)') '1 Fixed 0.0 0.0 -56.0' + WRITE (u, '(A)') '2 Turbine1 90.0 0.0 -14.0' + WRITE (u, '(A)') '--- LINES ---' + WRITE (u, '(A)') 'ID NodeA NodeB Outputs' + WRITE (u, '(A)') '(-) (-) (-) (-)' + WRITE (u, '(A)') '1 2 1 -' + WRITE (u, '(A)') '--- SECTIONS ---' + WRITE (u, '(A)') 'LineID LineType Length NumSegs' + WRITE (u, '(A)') '(-) (-) (m) (-)' + WRITE (u, '(A)') '1 bare 145.0 47' + CALL write_control_section(u, '1 1') + WRITE (u, '(A)') '--- OPTIONS ---' + WRITE (u, '(A)') '9.80665 g' + WRITE (u, '(A)') '1025.0 rhoW' + WRITE (u, '(A)') '--- need this line ---' + CLOSE (u) + CALL CD_AGG_Init_From_Deck(aggc, 'agg_farm_cable_ctrl.dat', DT, es, em, n_turbines=1, & + turbine_ref_pos=RESHAPE([0.0_wp, 0.0_wp, 0.0_wp], [3, 1])) + CALL require(es /= CD_AGG_OK .AND. INDEX(em, 'CONTROL on a FAST.Farm deck') > 0, & + 'cablectrl: CONTROL of a finite-EI cable in FAST.Farm fails closed by name') + CALL CD_AGG_End(aggc, es, em) + END BLOCK + END SUBROUTINE case_aggregate_cable_control + + SUBROUTINE case_restart_cable_control() + !! CHECKPOINT-RESTART of a controlled finite-EI cable, bit for bit (the shell rebuild's + !! recipe): instance A marches under a pay-out ramp and a hold; a fresh instance B is built + !! at the base lengths, takes A's coupled kinematics, re-applies the last command (the + !! shell re-applies the restored DeltaL) and then reloads A's cable mirror; both continue + !! under the same drive and commands. The re-applied lengths rebuild B's mass, tributary + !! lengths and seabed coefficients exactly as A's were rebuilt; the mirror reload that + !! follows brings back the committed force A carries into its next step and takes the + !! lengths in place as those the committed state was reached with (A's l0_c), so the + !! trajectories stay bit-identical, on a suspended cable and on a grounded cable with + !! stick-slip friction. The checkpoint falls in the hold and in the ramp. Deck 4 holds a + !! host fluid field (external_fluid) sampled before each command, as the shell does, and + !! re-sampled after the reload: each sample re-evaluates the committed force, at the + !! committed lengths, so the restart is bit-identical only if the reload took the + !! re-applied lengths as committed (the command goes on before the reload). + TYPE(CD_AGG_ModuleType) :: agg_a, agg_b + REAL(wp), PARAMETER :: DT = 0.05_wp + INTEGER, PARAMETER :: NPOST = 6 + REAL(wp), ALLOCATABLE :: r0(:, :), vel(:, :), acc(:, :), tgt(:, :), pa(:, :), la(:, :), pb(:, :), lb(:, :) + REAL(wp), ALLOCATABLE :: v2(:, :), a2(:, :), cbuf(:), fv(:, :), fa(:, :), wl(:) + REAL(wp) :: dl, dldot + INTEGER :: es, ni, s, npt, deck, npre, nfl + LOGICAL :: cv, st, same, fluid + CHARACTER(512) :: em + CHARACTER(64) :: path + + DO deck = 1, 4 + fluid = deck == 4 + SELECT CASE (deck) + CASE (1) + path = 'agg_restart_cable_ctrl.dat' + CALL write_cable_only_deck(path, control_row='1 1') + npre = 8 + CASE (2, 4) + path = 'agg_restart_cable_ctrl.dat' + npre = 4 + CASE DEFAULT + path = 'agg_restart_ground_ctrl.dat' + CALL write_cable_grounded_deck(path, control_row='1 1') + npre = 8 + END SELECT + CALL CD_AGG_Init_From_Deck(agg_a, TRIM(path), DT, es, em, external_fluid=fluid) + CALL require(es == CD_AGG_OK, 'ctrl-restart:A-init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + IF (fluid) THEN + nfl = CD_AGG_NFluidNodes(agg_a, es, em) + IF (ALLOCATED(fv)) DEALLOCATE (fv, fa, wl) + ALLOCATE (fv(3, nfl), fa(3, nfl), wl(nfl)) + fv = 0.0_wp + fa = 0.0_wp + wl = 0.0_wp + END IF + npt = CD_AGG_NMovingPoints(agg_a, es, em) + IF (ALLOCATED(r0)) DEALLOCATE (r0, vel, acc, tgt, pa, la, pb, lb, v2, a2) + ALLOCATE (r0(3, npt), vel(3, npt), acc(3, npt), tgt(3, npt), pa(3, npt), la(3, npt), pb(3, npt), & + lb(3, npt), v2(3, npt), a2(3, npt)) + CALL CD_AGG_GetMovingPointMesh(agg_a, r0, vel, acc, la, es, em) + tgt = r0 + vel = 0.0_wp + acc = 0.0_wp + DO s = 1, npre + CALL control_drive(s, DT, r0, tgt, vel, dl, dldot) + IF (fluid) CALL fluid_sample(agg_a, s, fv, fa, wl) + CALL CD_AGG_Apply_LineControl(agg_a, [dl], [dldot], es, em) + CALL CD_AGG_Step_Moving(agg_a, DT, tgt, vel, acc, cv, st, ni, es, em) + CALL require(es == CD_AGG_OK .AND. cv, 'ctrl-restart:A-march: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + END DO + ! the checkpoint: fresh B at the base lengths, A's kinematics and mirror, the last command + CALL CD_AGG_Init_From_Deck(agg_b, TRIM(path), DT, es, em, external_fluid=fluid) + CALL require(es == CD_AGG_OK, 'ctrl-restart:B-init: '//TRIM(em)) + CALL CD_AGG_GetMovingPointMesh(agg_a, pa, v2, a2, la, es, em) + CALL CD_AGG_UpdateStates_Moving(agg_b, pa, v2, a2, es, em) + ! the restored command goes on as the committed state's before the mirror reload (the + ! shell rebuild order), as its lengths are in the uninterrupted run; the reload brings + ! back the committed force + CALL control_drive(npre, DT, r0, tgt, vel, dl, dldot) + CALL CD_AGG_Apply_LineControl(agg_b, [dl], [dldot], es, em, restored=.TRUE.) + CALL require(es == CD_AGG_OK, 'ctrl-restart:B-reapply: '//TRIM(em)) + ALLOCATE (cbuf(CD_HFMF_MirrorSize(agg_a%cables(1)))) + CALL CD_HFMF_PackMirror(agg_a%cables(1), cbuf, es, em) + CALL CD_HFMF_UnpackMirror(agg_b%cables(1), cbuf, agg_a%cables(1)%line%t, es, em) + CALL require(es == CD_HFMF_OK, 'ctrl-restart:cable-unpack: '//TRIM(em)) + DEALLOCATE (cbuf) + ! the shell re-samples the host field on the restored state + IF (fluid) CALL fluid_sample(agg_b, npre, fv, fa, wl) + CALL require(ALL(agg_b%cables(1)%line%l0 == agg_a%cables(1)%line%l0) .AND. & + ALL(agg_b%cables(1)%line%Mgb == agg_a%cables(1)%line%Mgb) .AND. & + ALL(agg_b%cables(1)%line%trib == agg_a%cables(1)%line%trib), & + 'ctrl-restart:re-applied lengths and caches equal the uninterrupted run''s') + IF (agg_a%cables(1)%line%has_contact) & + CALL require(ALL(agg_b%cables(1)%line%contact_kn == agg_a%cables(1)%line%contact_kn) .AND. & + ALL(agg_b%cables(1)%line%fr_k == agg_a%cables(1)%line%fr_k), & + 'ctrl-restart:re-applied seabed coefficients equal the uninterrupted run''s') + same = .TRUE. + DO s = npre + 1, npre + NPOST + CALL control_drive(s, DT, r0, tgt, vel, dl, dldot) + IF (fluid) CALL fluid_sample(agg_a, s, fv, fa, wl) + IF (fluid) CALL fluid_sample(agg_b, s, fv, fa, wl) + CALL CD_AGG_Apply_LineControl(agg_a, [dl], [dldot], es, em) + CALL CD_AGG_Apply_LineControl(agg_b, [dl], [dldot], es, em) + CALL CD_AGG_Step_Moving(agg_a, DT, tgt, vel, acc, cv, st, ni, es, em) + CALL require(es == CD_AGG_OK .AND. cv, 'ctrl-restart:A-continue: '//TRIM(em)) + CALL CD_AGG_Step_Moving(agg_b, DT, tgt, vel, acc, cv, st, ni, es, em) + CALL require(es == CD_AGG_OK .AND. cv, 'ctrl-restart:B-continue: '//TRIM(em)) + CALL CD_AGG_CalcOutput(agg_a, es, em) + CALL CD_AGG_CalcOutput(agg_b, es, em) + CALL CD_AGG_GetMovingPointMesh(agg_a, pa, v2, a2, la, es, em) + CALL CD_AGG_GetMovingPointMesh(agg_b, pb, v2, a2, lb, es, em) + same = same .AND. nan_max_abs(la - lb) <= 0.0_wp .AND. & + nan_max_abs(agg_a%cables(1)%line%q - agg_b%cables(1)%line%q) <= 0.0_wp .AND. & + nan_max_abs(agg_a%cables(1)%line%a - agg_b%cables(1)%line%a) <= 0.0_wp + END DO + WRITE (*, '(A,I0,A,ES10.3)') ' ctrl-restart deck ', deck, ': max load difference ', nan_max_abs(la - lb) + CALL require(same, 'ctrl-restart:the restarted run continues bit-identically') + CALL CD_AGG_End(agg_a, es, em) + CALL CD_AGG_End(agg_b, es, em) + END DO + END SUBROUTINE case_restart_cable_control + + SUBROUTINE fluid_sample(agg, step, fv, fa, wl) + !! A host fluid field for the coming step of case_restart_cable_control: a uniform + !! current that grows with the step count (fa and wl as given). + TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: agg + INTEGER, INTENT(IN) :: step + REAL(wp), INTENT(INOUT) :: fv(:, :) + REAL(wp), INTENT(IN) :: fa(:, :), wl(:) + INTEGER :: esf + CHARACTER(512) :: emf + fv(1, :) = 0.02_wp*REAL(step, wp) + CALL CD_AGG_SetFluidFields(agg, fv, fa, wl, esf, emf) + CALL require(esf == CD_AGG_OK, 'ctrl-restart:fluid field: '//TRIM(emf)) + END SUBROUTINE fluid_sample + + SUBROUTINE control_drive(step, dt, r0, tgt, vel, dl, dldot) + !! Surge drive of every coupled point and the control command at t = step*dt: a 0.3 m + !! pay-out on a half-cosine ramp over 0.3 s, then held. + INTEGER, INTENT(IN) :: step + REAL(wp), INTENT(IN) :: dt, r0(:, :) + REAL(wp), INTENT(INOUT) :: tgt(:, :), vel(:, :) + REAL(wp), INTENT(OUT) :: dl, dldot + REAL(wp), PARAMETER :: TR = 0.3_wp + REAL(wp) :: t + t = REAL(step, wp)*dt + tgt(1, :) = r0(1, :) + 0.2_wp*(1.0_wp - COS(2.0_wp*PI*t/2.0_wp)) + vel(1, :) = 0.2_wp*(2.0_wp*PI/2.0_wp)*SIN(2.0_wp*PI*t/2.0_wp) + IF (t < TR) THEN + dl = 0.3_wp*0.5_wp*(1.0_wp - COS(PI*t/TR)) + dldot = 0.3_wp*0.5_wp*(PI/TR)*SIN(PI*t/TR) + ELSE + dl = 0.3_wp + dldot = 0.0_wp + END IF + END SUBROUTINE control_drive + + SUBROUTINE write_agg_failure_deck(path, failure_row, control_row, composite_line2, composite_line1, stock_line2, & + short_tail2) !! Vessel fairlead + massy Connect junction + Fixed anchor, two 0.98 m lines -- !! the connect rig behind the coupled facade, with optional FAILURE/CONTROL rows. !! composite_line2 splits line 2 into two sections with DIFFERENT segment - !! lengths (0.50 then 0.48) -- the control-base composite regression. + !! lengths (0.50 then 0.48) -- the control-base composite regression; composite_line1 + !! splits line 1 (Connect -> Vessel, kept in deck order) the same way. stock_line2 + !! writes line 2 anchor first (Fixed NodeA, sections reversed), which the anchor-first + !! swap turns into the same line. short_tail2 (with composite_line2) makes line 2's + !! sections 0.90 and 0.08 m, a controlled segment shorter than half of UnstrLen/N. CHARACTER(*), INTENT(IN) :: path CHARACTER(*), INTENT(IN), OPTIONAL :: failure_row, control_row - LOGICAL, INTENT(IN), OPTIONAL :: composite_line2 - LOGICAL :: comp2 + LOGICAL, INTENT(IN), OPTIONAL :: composite_line2, composite_line1, stock_line2, short_tail2 + LOGICAL :: comp2, comp1, stock2, short2 INTEGER :: u, ios + comp1 = .FALSE. + IF (PRESENT(composite_line1)) comp1 = composite_line1 + stock2 = .FALSE. + IF (PRESENT(stock_line2)) stock2 = stock_line2 OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE', IOSTAT=ios) WRITE (u, '(A)') 'Coupled connect rig with optional FAILURE' WRITE (u, '(A)') '--- LINE TYPES ---' @@ -3300,14 +3935,31 @@ SUBROUTINE write_agg_failure_deck(path, failure_row, control_row, composite_line WRITE (u, '(A)') 'ID NodeA NodeB Outputs' WRITE (u, '(A)') '(-) (-) (-) (-)' WRITE (u, '(A)') '1 2 1 -' - WRITE (u, '(A)') '2 2 3 -' + IF (stock2) THEN + WRITE (u, '(A)') '2 3 2 -' + ELSE + WRITE (u, '(A)') '2 2 3 -' + END IF WRITE (u, '(A)') '--- SECTIONS ---' WRITE (u, '(A)') 'LineID LineType Length NumSegs' WRITE (u, '(A)') '(-) (-) (m) (-)' - WRITE (u, '(A)') '1 line 0.98 1' + IF (comp1) THEN + WRITE (u, '(A)') '1 line 0.50 1' + WRITE (u, '(A)') '1 line 0.48 1' + ELSE + WRITE (u, '(A)') '1 line 0.98 1' + END IF comp2 = .FALSE. IF (PRESENT(composite_line2)) comp2 = composite_line2 - IF (comp2) THEN + short2 = .FALSE. + IF (PRESENT(short_tail2)) short2 = short_tail2 + IF (comp2 .AND. short2) THEN + WRITE (u, '(A)') '2 line 0.90 1' + WRITE (u, '(A)') '2 line 0.08 1' + ELSE IF (comp2 .AND. stock2) THEN + WRITE (u, '(A)') '2 line 0.48 1' + WRITE (u, '(A)') '2 line 0.50 1' + ELSE IF (comp2) THEN WRITE (u, '(A)') '2 line 0.50 1' WRITE (u, '(A)') '2 line 0.48 1' ELSE @@ -3853,6 +4505,113 @@ SUBROUTINE case_external_fluid_cable() CALL CD_AGG_End(agg_p, es, em) END SUBROUTINE case_external_fluid_cable + SUBROUTINE case_restart_line_control() + !! CHECKPOINT-RESTART of a controlled EI = 0 deck, bit for bit (the shell rebuild's + !! recipe): instance A marches the three VolturnUS chains under a surge drive while + !! channel 1 pays their fairlead segments out on a ramp and then holds; a fresh + !! instance B takes A's coupled kinematics and line interiors [v; q; a], then re-applies + !! the last command as the committed state's (restored = .TRUE.); both continue under the + !! same drive and commands. A step after a length change blends the committed lengths + !! into its generalised-alpha terms, so B must carry A's committed lengths for the + !! trajectories to stay bit-identical. The checkpoint falls in the ramp and in the hold. + TYPE(CD_AGG_ModuleType) :: agg_a, agg_b + REAL(wp), PARAMETER :: DT = 0.05_wp + INTEGER, PARAMETER :: NPOST = 8 + REAL(wp) :: r0(3, 3), vel(3, 3), acc(3, 3), tgt(3, 3), pa(3, 3), la(3, 3), pb(3, 3), lb(3, 3) + REAL(wp) :: v2(3, 3), a2(3, 3), dl, dldot + REAL(wp), ALLOCATABLE :: qL(:), vL(:), aL(:) + INTEGER :: es, ni, s, nl, il, ndof, npre, pass + LOGICAL :: cv, st, same + CHARACTER(512) :: em + + CALL write_volturnus_deck('agg_restart_ctrl.dat', control_row='1 1,2,3') + DO pass = 1, 2 + npre = MERGE(8, 30, pass == 1) + CALL CD_AGG_Init_From_Deck(agg_a, 'agg_restart_ctrl.dat', DT, es, em) + CALL require(es == CD_AGG_OK, 'ctrl-restart:A-init: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + CALL CD_AGG_GetMovingPointMesh(agg_a, r0, vel, acc, la, es, em) + tgt = r0 + vel = 0.0_wp + acc = 0.0_wp + DO s = 1, npre + CALL ctrl_ramp_drive(s, DT, r0, tgt, vel, dl, dldot) + CALL CD_AGG_Apply_LineControl(agg_a, [dl], [dldot], es, em) + CALL CD_AGG_Step_Moving(agg_a, DT, tgt, vel, acc, cv, st, ni, es, em) + CALL require(es == CD_AGG_OK .AND. cv, 'ctrl-restart:A-march: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + END DO + CALL CD_AGG_Init_From_Deck(agg_b, 'agg_restart_ctrl.dat', DT, es, em) + CALL require(es == CD_AGG_OK, 'ctrl-restart:B-init: '//TRIM(em)) + CALL CD_AGG_GetMovingPointMesh(agg_a, pa, v2, a2, la, es, em) + CALL CD_AGG_UpdateStates_Moving(agg_b, pa, v2, a2, es, em) + nl = CD_System_NLines(agg_a%sys%fast%system, es, em) + DO il = 1, nl + ndof = CD_System_Line_NDOF(agg_a%sys%fast%system, il, es, em) + IF (ALLOCATED(qL)) DEALLOCATE (qL, vL, aL) + ALLOCATE (qL(ndof), vL(ndof), aL(ndof)) + CALL CD_Get_System_Line_State(agg_a%sys%fast%system, il, qL, vL, aL, es, em) + CALL CD_Update_System_Line_Interior_State(agg_b%sys%fast%system, il, qL(4:ndof - 3), vL(4:ndof - 3), & + es, em, a_interior=aL(4:ndof - 3)) + CALL require(es == CD_SYSTEM_OK, 'ctrl-restart:B-interior: '//TRIM(em)) + END DO + ! the restored command is the one A's committed state was reached with + CALL ctrl_ramp_drive(npre, DT, r0, tgt, vel, dl, dldot) + CALL CD_AGG_Apply_LineControl(agg_b, [dl], [dldot], es, em, restored=.TRUE.) + CALL require(es == CD_AGG_OK, 'ctrl-restart:B-reapply: '//TRIM(em)) + same = .TRUE. + DO il = 1, nl + same = same .AND. ALL(agg_b%sys%fast%system%lines(il)%l0 == agg_a%sys%fast%system%lines(il)%l0) .AND. & + ALL(agg_b%sys%fast%system%lines(il)%l0_c == agg_a%sys%fast%system%lines(il)%l0_c) + END DO + CALL require(same, 'ctrl-restart:B carries the lengths and the committed lengths of A') + DO s = npre + 1, npre + NPOST + CALL ctrl_ramp_drive(s, DT, r0, tgt, vel, dl, dldot) + CALL CD_AGG_Apply_LineControl(agg_a, [dl], [dldot], es, em) + CALL CD_AGG_Apply_LineControl(agg_b, [dl], [dldot], es, em) + CALL CD_AGG_Step_Moving(agg_a, DT, tgt, vel, acc, cv, st, ni, es, em) + CALL require(es == CD_AGG_OK .AND. cv, 'ctrl-restart:A-continue: '//TRIM(em)) + CALL CD_AGG_Step_Moving(agg_b, DT, tgt, vel, acc, cv, st, ni, es, em) + CALL require(es == CD_AGG_OK .AND. cv, 'ctrl-restart:B-continue: '//TRIM(em)) + CALL CD_AGG_CalcOutput(agg_a, es, em) + CALL CD_AGG_CalcOutput(agg_b, es, em) + CALL CD_AGG_GetMovingPointMesh(agg_a, pa, v2, a2, la, es, em) + CALL CD_AGG_GetMovingPointMesh(agg_b, pb, v2, a2, lb, es, em) + same = same .AND. nan_max_abs(la - lb) <= 0.0_wp + DO il = 1, nl + same = same .AND. nan_max_abs(agg_a%sys%fast%system%lines(il)%q - agg_b%sys%fast%system%lines(il)%q) & + <= 0.0_wp + END DO + END DO + WRITE (*, '(A,I0,A,ES10.3)') ' ctrl-restart (EI = 0) after step ', npre, ': max load difference ', & + nan_max_abs(la - lb) + CALL require(same, 'ctrl-restart:the restarted EI = 0 run continues bit-identically') + CALL CD_AGG_End(agg_a, es, em) + CALL CD_AGG_End(agg_b, es, em) + END DO + END SUBROUTINE case_restart_line_control + + SUBROUTINE ctrl_ramp_drive(step, dt, r0, tgt, vel, dl, dldot) + !! Surge drive of every coupled point and the control command at t = step*dt: a 2 m + !! pay-out on a half-cosine ramp over 1 s, then held (case_restart_line_control). + INTEGER, INTENT(IN) :: step + REAL(wp), INTENT(IN) :: dt, r0(:, :) + REAL(wp), INTENT(INOUT) :: tgt(:, :), vel(:, :) + REAL(wp), INTENT(OUT) :: dl, dldot + REAL(wp), PARAMETER :: TR = 1.0_wp + REAL(wp) :: t + t = REAL(step, wp)*dt + tgt(1, :) = r0(1, :) + 0.5_wp*(1.0_wp - COS(2.0_wp*PI*t/4.0_wp)) + vel(1, :) = 0.5_wp*(2.0_wp*PI/4.0_wp)*SIN(2.0_wp*PI*t/4.0_wp) + IF (t < TR) THEN + dl = 2.0_wp*0.5_wp*(1.0_wp - COS(PI*t/TR)) + dldot = 2.0_wp*0.5_wp*(PI/TR)*SIN(PI*t/TR) + ELSE + dl = 2.0_wp + dldot = 0.0_wp + END IF + END SUBROUTINE ctrl_ramp_drive + SUBROUTINE case_restart_equivalence() !! CHECKPOINT-RESTART semantics at the aggregate level (the shell rebuild's exact !! recipe): march instance A mid-flight, capture what a checkpoint carries -- the @@ -4191,7 +4950,7 @@ END SUBROUTINE write_current_deck ! deck writers ! --------------------------------------------------------------------------------------- - SUBROUTINE write_volturnus_deck(path, fairleads, extra_option, extra_option2, extra_option3) + SUBROUTINE write_volturnus_deck(path, fairleads, extra_option, extra_option2, extra_option3, control_row) !! IEA-15MW VolturnUS-S three-chain mooring (End A = Vessel fairlead, End B = Fixed !! anchor), 20 segments per line -- a pure EI=0 deck (all sections chain, EI = 0). !! fairleads (optional, 3x3): override the three Vessel coordinates, written @@ -4200,9 +4959,10 @@ SUBROUTINE write_volturnus_deck(path, fairleads, extra_option, extra_option2, ex !! bit-for-bit -- the ptfm_init equivalence case keys on that. !! extra_option[23] (optional): verbatim OPTIONS lines appended before the terminator !! (deck current/waves/dtM/TMax variants for the external-fluid cases). + !! control_row (optional): a CONTROL section with this row. CHARACTER(*), INTENT(IN) :: path REAL(wp), INTENT(IN), OPTIONAL :: fairleads(3, 3) - CHARACTER(*), INTENT(IN), OPTIONAL :: extra_option, extra_option2, extra_option3 + CHARACTER(*), INTENT(IN), OPTIONAL :: extra_option, extra_option2, extra_option3, control_row REAL(wp) :: fl(3, 3) INTEGER :: u, ios fl(:, 1) = [-58.0_wp, 0.0_wp, -14.0_wp] @@ -4236,6 +4996,12 @@ SUBROUTINE write_volturnus_deck(path, fairleads, extra_option, extra_option2, ex WRITE (u, '(A)') '1 main 850.0 20' WRITE (u, '(A)') '2 main 850.0 20' WRITE (u, '(A)') '3 main 850.0 20' + IF (PRESENT(control_row)) THEN + WRITE (u, '(A)') '--- CONTROL ---' + WRITE (u, '(A)') 'ChannelID Lines' + WRITE (u, '(A)') '(-) (-)' + WRITE (u, '(A)') TRIM(control_row) + END IF WRITE (u, '(A)') '--- OPTIONS ---' WRITE (u, '(A)') '9.80665 g' WRITE (u, '(A)') '1025.0 rhoW' @@ -4416,13 +5182,15 @@ SUBROUTINE write_touchdown_cable_deck(path, outputs_row) CLOSE (u) END SUBROUTINE write_touchdown_cable_deck - SUBROUTINE write_mixed_deck(path, finite_end_connection, rigid_end_connection) + SUBROUTINE write_mixed_deck(path, finite_end_connection, rigid_end_connection, control_row) !! MIXED deck: one EI=0 catenary chain (mooring) + one finite-EI lazy-wave power cable. !! Cable endpoints (Fixed anchor + Coupled fairlead) sit well above the -200 m seabed, so !! the suspended pinned-span cable ignores WtrDpth while the mooring uses it (touchdown). + !! control_row adds a CONTROL section (cable = deck line 1, chain = deck line 2). CHARACTER(*), INTENT(IN) :: path LOGICAL, INTENT(IN), OPTIONAL :: finite_end_connection LOGICAL, INTENT(IN), OPTIONAL :: rigid_end_connection + CHARACTER(*), INTENT(IN), OPTIONAL :: control_row INTEGER :: u, ios OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE', IOSTAT=ios) WRITE (u, '(A)') 'MIXED deck: EI=0 chain mooring + finite-EI lazy-wave cable' @@ -4470,6 +5238,7 @@ SUBROUTINE write_mixed_deck(path, finite_end_connection, rigid_end_connection) WRITE (u, '(A)') '1 A Rigid -0.24716 0 -0.968975' END IF END IF + IF (PRESENT(control_row)) CALL write_control_section(u, control_row) WRITE (u, '(A)') '--- OPTIONS ---' WRITE (u, '(A)') '9.80665 g' WRITE (u, '(A)') '1025.0 rhoW' @@ -4481,6 +5250,26 @@ SUBROUTINE write_mixed_deck(path, finite_end_connection, rigid_end_connection) CLOSE (u) END SUBROUTINE write_mixed_deck + SUBROUTINE write_control_section(u, rows) + !! A CONTROL section; rows holds one or more rows separated by ';'. + INTEGER, INTENT(IN) :: u + CHARACTER(*), INTENT(IN) :: rows + INTEGER :: lo, hi + WRITE (u, '(A)') '--- CONTROL ---' + WRITE (u, '(A)') 'ChannelID Lines' + WRITE (u, '(A)') '(-) (-)' + lo = 1 + DO + hi = INDEX(rows(lo:), ';') + IF (hi == 0) THEN + WRITE (u, '(A)') TRIM(rows(lo:)) + EXIT + END IF + WRITE (u, '(A)') TRIM(rows(lo:lo + hi - 2)) + lo = lo + hi + END DO + END SUBROUTINE write_control_section + SUBROUTINE write_mixed_channels_deck(path, point_channel_id, outputs_row) !! The write_mixed_deck geometry (cable = line 1, mooring chain = line 2) plus an OUTPUTS !! section exercising both objects and multiple channel kinds: FairTen/AnchTen on the mooring, @@ -4578,18 +5367,28 @@ SUBROUTINE write_mooring_channels_deck(path) CLOSE (u) END SUBROUTINE write_mooring_channels_deck - SUBROUTINE write_cable_only_deck(path, modified_newton, cable_load_feedback) + SUBROUTINE write_cable_only_deck(path, modified_newton, cable_load_feedback, control_row, adaptive_mesh, & + stock_order, config_blend) !! A finite-EI lazy-wave power cable, coupled at the fairlead -- no EI=0 line. Bare + !! buoyancy-module properties from the Humboldt / GoMex 15 MW reference (the l3_lazywave !! and deck_hermite_cable convention). Purely SUSPENDED (no WtrDpth). modified_newton - !! adds the OPTIONS row (the tangent-reuse plumbing gate's twin-deck knob). + !! adds the OPTIONS row (the tangent-reuse plumbing gate's twin-deck knob); control_row + !! a CONTROL section; adaptive_mesh the OPTIONS row that lets the static solve refine + !! the 47 deck segments; stock_order writes the line anchor first (MoorDyn order, Fixed + !! NodeA, sections reversed), which the anchor-first swap turns into the same cable; + !! config_blend the OPTIONS row that selects the configuration-blended generalised-alpha. CHARACTER(*), INTENT(IN) :: path - LOGICAL, INTENT(IN), OPTIONAL :: modified_newton + LOGICAL, INTENT(IN), OPTIONAL :: modified_newton, config_blend LOGICAL, INTENT(IN), OPTIONAL :: cable_load_feedback + CHARACTER(*), INTENT(IN), OPTIONAL :: control_row + LOGICAL, INTENT(IN), OPTIONAL :: adaptive_mesh + LOGICAL, INTENT(IN), OPTIONAL :: stock_order INTEGER :: u, ios - LOGICAL :: mn + LOGICAL :: mn, stock mn = .FALSE. IF (PRESENT(modified_newton)) mn = modified_newton + stock = .FALSE. + IF (PRESENT(stock_order)) stock = stock_order OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE', IOSTAT=ios) WRITE (u, '(A)') 'finite-EI lazy-wave power cable, coupled at the fairlead (no EI=0 line)' WRITE (u, '(A)') '--- LINE TYPES ---' @@ -4605,18 +5404,35 @@ SUBROUTINE write_cable_only_deck(path, modified_newton, cable_load_feedback) WRITE (u, '(A)') '--- LINES ---' WRITE (u, '(A)') 'ID NodeA NodeB Outputs' WRITE (u, '(A)') '(-) (-) (-) (-)' - WRITE (u, '(A)') '1 2 1 -' + IF (stock) THEN + WRITE (u, '(A)') '1 1 2 -' + ELSE + WRITE (u, '(A)') '1 2 1 -' + END IF WRITE (u, '(A)') '--- SECTIONS ---' WRITE (u, '(A)') 'LineID LineType Length NumSegs' WRITE (u, '(A)') '(-) (-) (m) (-)' - WRITE (u, '(A)') '1 bare 40.0 13' - WRITE (u, '(A)') '1 buoy 50.0 16' - WRITE (u, '(A)') '1 bare 55.0 18' + IF (stock) THEN + WRITE (u, '(A)') '1 bare 55.0 18' + WRITE (u, '(A)') '1 buoy 50.0 16' + WRITE (u, '(A)') '1 bare 40.0 13' + ELSE + WRITE (u, '(A)') '1 bare 40.0 13' + WRITE (u, '(A)') '1 buoy 50.0 16' + WRITE (u, '(A)') '1 bare 55.0 18' + END IF + IF (PRESENT(control_row)) CALL write_control_section(u, control_row) WRITE (u, '(A)') '--- OPTIONS ---' WRITE (u, '(A)') '9.80665 g' WRITE (u, '(A)') '1025.0 rhoW' WRITE (u, '(A)') '0.5 rhoInf' IF (mn) WRITE (u, '(A)') 'true modified_newton' + IF (PRESENT(config_blend)) THEN + IF (config_blend) WRITE (u, '(A)') 'false alpha_force_blend' + END IF + IF (PRESENT(adaptive_mesh)) THEN + IF (adaptive_mesh) WRITE (u, '(A)') 'true adaptive_mesh' + END IF IF (PRESENT(cable_load_feedback)) THEN IF (cable_load_feedback) THEN WRITE (u, '(A)') 'true cable_load_feedback' @@ -4628,15 +5444,16 @@ SUBROUTINE write_cable_only_deck(path, modified_newton, cable_load_feedback) CLOSE (u) END SUBROUTINE write_cable_only_deck - SUBROUTINE write_cable_grounded_deck(path, bathy_path, refined, extra_option) + SUBROUTINE write_cable_grounded_deck(path, bathy_path, refined, extra_option, control_row) !! Coupled finite-EI touchdown cable. The 115 m span between endpoints 96.9 m apart !! develops a grounded run on the -50 m bed without exceeding the 126 m planar !! L-shape capacity (longer fixtures necessarily wad on a frictionless bed). - !! Optional bathymetry_path replaces flat WtrDpth. + !! Optional bathymetry_path replaces flat WtrDpth; control_row adds a CONTROL section. CHARACTER(*), INTENT(IN) :: path CHARACTER(*), INTENT(IN), OPTIONAL :: bathy_path LOGICAL, INTENT(IN), OPTIONAL :: refined CHARACTER(*), INTENT(IN), OPTIONAL :: extra_option + CHARACTER(*), INTENT(IN), OPTIONAL :: control_row INTEGER :: u, ios LOGICAL :: fine_mesh fine_mesh = .FALSE. @@ -4669,6 +5486,7 @@ SUBROUTINE write_cable_grounded_deck(path, bathy_path, refined, extra_option) WRITE (u, '(A)') '1 buoy 40.0 17' WRITE (u, '(A)') '1 bare 45.0 20' END IF + IF (PRESENT(control_row)) CALL write_control_section(u, control_row) WRITE (u, '(A)') '--- OPTIONS ---' WRITE (u, '(A)') '9.80665 g' WRITE (u, '(A)') '1025.0 rhoW' @@ -4762,14 +5580,20 @@ SUBROUTINE write_mixed_free_deck(path) CLOSE (u) END SUBROUTINE write_mixed_free_deck - SUBROUTINE write_host_rod_deck(path, rod_as_points) + SUBROUTINE write_host_rod_deck(path, rod_as_points, control_row, stock_line1) !! A Coupled (platform-borne) vertical rod, End A at z = -1 and End B at z = -3, moored at both !! ends to its own anchor, plus an independent Coupled fairlead with its own line. With !! rod_as_points the rod is replaced by two Coupled points at its end positions (the same - !! lines, the same statics): the reference for the rod's line-end loads. + !! lines, the same statics): the reference for the rod's line-end loads. control_row adds a + !! CONTROL section; stock_line1 writes line 1 anchor first (Fixed NodeA). CHARACTER(*), INTENT(IN) :: path LOGICAL, INTENT(IN) :: rod_as_points + CHARACTER(*), INTENT(IN), OPTIONAL :: control_row + LOGICAL, INTENT(IN), OPTIONAL :: stock_line1 INTEGER :: u + LOGICAL :: stock1 + stock1 = .FALSE. + IF (PRESENT(stock_line1)) stock1 = stock_line1 OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') WRITE (u, '(A)') 'coupled host rod deck' WRITE (u, '(A)') '--- LINE TYPES ---' @@ -4803,7 +5627,11 @@ SUBROUTINE write_host_rod_deck(path, rod_as_points) WRITE (u, '(A)') '--- LINES ---' WRITE (u, '(A)') 'ID NodeA NodeB Outputs' WRITE (u, '(A)') '(-) (-) (-) (-)' - WRITE (u, '(A)') '1 3 1 -' + IF (stock1) THEN + WRITE (u, '(A)') '1 1 3 -' + ELSE + WRITE (u, '(A)') '1 3 1 -' + END IF WRITE (u, '(A)') '2 4 5 -' WRITE (u, '(A)') '3 2 6 -' WRITE (u, '(A)') '--- SECTIONS ---' @@ -4812,6 +5640,7 @@ SUBROUTINE write_host_rod_deck(path, rod_as_points) WRITE (u, '(A)') '1 line 8.0 6' WRITE (u, '(A)') '2 line 9.5 6' WRITE (u, '(A)') '3 line 9.5 6' + IF (PRESENT(control_row)) CALL write_control_section(u, control_row) WRITE (u, '(A)') '--- OPTIONS ---' WRITE (u, '(A)') '9.80665 g' WRITE (u, '(A)') '1025.0 rhoW' diff --git a/validation/scripts/activetension/README.md b/validation/scripts/activetension/README.md index b2056b23..5aaa2db4 100644 --- a/validation/scripts/activetension/README.md +++ b/validation/scripts/activetension/README.md @@ -74,7 +74,9 @@ At the holds, where `DeltaLdot = 0`, the tensions of CableDyn and stock MoorDyn 0.03 %. The tension changes from the baseline, which are the active-tension response, agree to within **0.6 %** on the controlled fairleads and **0.7 %** on the anchors. Both codes report the line-end force, and CableDyn's Newton static equilibrium and MoorDyn's dynamic relaxation give -the same baseline tension to within 0.03 %. During the pay-out -and haul-in ramps, axial damping driven by the commanded rate (`BA·ℓ̇`) produces a transient -that the two element formulations represent slightly differently; it is reported for context -and not scored. +the same baseline tension to within 0.03 %. During the pay-out and haul-in ramps the tensions +differ by at most **0.13 %** of the baseline tension on the controlled fairleads and **0.39 %** +on the anchors; the scorer gates this at 1 %. Before CableDyn kept the committed lengths in the +generalised-α step after a length change, the controlled fairleads had run up to 97 kN (4.1 %) +above MoorDyn during the pay-out and 148 kN (6.3 %) below it during the haul-in, while the holds +agreed as they do now. diff --git a/validation/scripts/openfast_activetension_ab.py b/validation/scripts/openfast_activetension_ab.py index 173c4797..95623770 100644 --- a/validation/scripts/openfast_activetension_ab.py +++ b/validation/scripts/openfast_activetension_ab.py @@ -17,16 +17,18 @@ cancels the codes' small static-tension offset) isolates how each solver renders the commanded length modulation into tension. -The fast pay-out/haul-in RAMPS carry a rate-dependent axial-damping transient (BA*ldot from the -commanded DeltaLdot) that the two element formulations render differently; that is reported as -context but not gated -- the winch setpoint is the controlled quantity, not the slew transient. +The pay-out and haul-in RAMPS are scored too: over each ramp and its settling into the next hold, +the largest difference between the two codes' tensions must stay within GATE_RAMP_PCT of the +MoorDyn baseline tension of that line. The commanded length changes every step there, so this +checks that the length update enters the time integration the way MoorDyn's does. Usage: python validation/scripts/openfast_activetension_ab.py [t_base_lo t_base_hi t_payout_lo t_payout_hi t_haulin_lo t_haulin_hi] Defaults match the DLL schedule (pay out over 40-100 s, hold to 160 s, haul in over 160-220 s, -hold to 260 s): baseline [10,38], pay-out hold [110,158], haul-in hold [228,258]. +hold to 260 s): baseline [10,38], pay-out hold [110,158], haul-in hold [228,258]; the ramps are +scored over [38,110] and [158,228] (from the end of one hold window to the start of the next). Channel names are matched case-insensitively (MoorDyn-F emits UPPERCASE). """ @@ -54,6 +56,9 @@ # a real response -- each controlled hold must change the tension by at least this fraction of # baseline in each code -- so the A/B cannot pass vacuously on a dead cable-control path. GATE_MIN_RESPONSE_PCT = 1.0 # |dT| / baseline, per code, per controlled hold +# Ramp agreement: max |T(=5) - T(=3)| over each ramp, as a percentage of the line's MoorDyn +# baseline tension (controlled fairleads and anchors). +GATE_RAMP_PCT = 1.0 # Note: within a steady hold (DeltaLdot=0) the tension is essentially flat, so the =5-vs-=3 # correlation of the hold window is noise-vs-noise and is reported for context only, NOT gated. # The gated quantity is the tension CHANGE from baseline -- the winch setpoint response. @@ -221,6 +226,36 @@ def report( ANCHORS, "anchor (far-end) tensions -- steady agreement", GATE_ANCHOR_PCT, False ) + # Ramps: the largest tension difference between the codes while the length changes. + ramps = {"pay-out ramp": (bh, pl), "haul-in ramp": (ph, hl)} + print("--- ramps -- largest tension difference while the length changes ---") + for ch in CONTROLLED + ANCHORS: + base3 = window(h3, r3, ch, bl, bh) + c5, c3 = col(h5, ch), col(h3, ch) + if not base3 or c5 < 0 or c3 < 0: + print(f"{ch:10} MISSING") + fails.append(ch) + continue + b3 = mean(base3) + parts = [] + flag = " ok" + for name, (lo, hi) in ramps.items(): + d = max( + ( + abs(x5[c5] - x3[c3]) + for x5, x3 in zip(r5, r3) + if lo <= x5[t5] <= hi and abs(x5[t5] - x3[t3]) <= 0.5 * dt_est + ), + default=math.nan, + ) + parts.append(f"{name} {d / 1e3:7.1f} kN ({pct(d, b3):5.2f}%)") + if not (math.isfinite(d) and pct(d, b3) <= GATE_RAMP_PCT): + flag = " <-- GATE FAIL" + if flag != " ok": + fails.append(ch) + print(f"{ch:10} " + " ".join(parts) + flag) + print() + if fails: print(f"RESULT: FAIL -- {', '.join(dict.fromkeys(fails))}") return 1 @@ -228,7 +263,8 @@ def report( f"RESULT: PASS -- both codes show a real active-tension response " f"(>= {GATE_MIN_RESPONSE_PCT:.0f}% of baseline), the commanded pay-out/haul-in tension " f"response on the controlled lines agrees within {GATE_RESPONSE_PCT:.0f}%, and the anchor " - f"tensions within {GATE_ANCHOR_PCT:.0f}% between CableDyn and stock MoorDyn, end to end " + f"tensions within {GATE_ANCHOR_PCT:.0f}% between CableDyn and stock MoorDyn, and during the " + f"ramps the tensions differ by at most {GATE_RAMP_PCT:.0f}% of the baseline, end to end " "through the OpenFAST ServoDyn cable-control path." ) return 0