From a3257f81eabaf99fddc99f182c1db9954aee74ad Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Thu, 29 Oct 2026 15:53:14 +0900 Subject: [PATCH 1/3] feat(openfast): linearise the line dynamics, as MoorDyn-F With Linearize = True the module now registers continuous states: the interior-node positions of every EI = 0 line (MoorDyn's names and order) and the free DOFs of every finite-EI cable (node positions and tangents), then their velocities. lin_eval loads a state and an input into the committed mirror, solves the accelerations without a time step and restores the committed state; CD_CalcContStateDeriv, CD_JacobianPContState and the input Jacobian central-difference it for A, B, C and D. This replaces the quasi-static linearisation without states. Positions, tangents and coupled-point displacements are stepped by 1 um: a millimetre step lifted a light cable's grounded nodes out of their 0.3 mm seabed penetration on one side of the difference, and the former 5 cm input step slackened a chain's last element, each halving a stiffness. Velocities take MoorDyn-F's 0.1 m/s, which gives the quadratic drag its equivalent linear damping. On the UMaine twin decks the reduction D - C A^-1 B matches MoorDyn-F's to 0.1 % per fairlead and on the platform 6x6, and the lowest nine line-mode frequencies to 0.3 %; both state matrices are stable. On the mixed deck with a lazy-wave power cable every coupled point matches central differences of the deck's own static solutions to 3.3e-4, also with a hang-off spring. openfast_lin_ab.py gates the frequencies, the stability and (with --cable-deck and --driver) the mixed deck, and solves an ill-conditioned A plainly instead of truncating it. A numeric-stiffness cable end connection now linearises. Free/Connect points and a Rigid cable end connection fail closed with named messages, as bodies, rods, Point3 buoys, torsion and CONTROL already did. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 10 + VALIDATION.md | 30 +- doc/openfast.rst | 44 +- doc/troubleshooting.rst | 14 +- src/CableDyn_System.f90 | 28 ++ src/openfast/CableDyn_OF.f90 | 552 ++++++++++++++++++++++++-- validation/scripts/openfast_lin_ab.py | 217 +++++++++- 7 files changed, 809 insertions(+), 86 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0404db5a..736ef117 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,16 @@ All notable changes to CableDyn are recorded in this file. The format follows ### Added +- OpenFAST linearisation with the line dynamics, as MoorDyn-F's: the continuous states are the + interior-node positions of every `EI = 0` line (MoorDyn's names and order) and the free + degrees of freedom of every finite-EI cable (node positions and tangents), then their + velocities, with `A`, `B`, `C` and `D` by central differences of the accelerations solved at the + perturbed state. On the UMaine chains the stiffness `D - C A^-1 B` matches MoorDyn-F's to 0.1 % + and the lowest nine line-mode frequencies to 0.3 %; with a lazy-wave power cable every coupled + point matches the deck's own static solutions to 3e-4, also with a hang-off spring. A cable + end connection with a numeric stiffness now linearises. Free/Connect points, a `Rigid` cable + end connection, bodies, rods, buoys, torsion and `CONTROL` fail closed with named messages. + This replaces the quasi-static linearisation without states. - Section-frame curvature channels `CurvXN` and `CurvYN` on finite-EI lines: the curvature vector on the cable's cross-section axes, for the fatigue of an armour wire or conductor at a fixed point of the section. The axes start at End A from the end connection diff --git a/VALIDATION.md b/VALIDATION.md index af80d954..89918c32 100644 --- a/VALIDATION.md +++ b/VALIDATION.md @@ -372,13 +372,25 @@ scripts, results, and source provenance are in ([`validation/scripts/openfast_lin_ab.py`](https://github.com/SMI-Lab-Inha/CableDyn/blob/main/validation/scripts/openfast_lin_ab.py)): the twin decks linearise once at t = 0. Each run has platform DOFs only, still water, and HydroDyn `ExctnMod = RdtnMod = 0`. MoorDyn's relaxation runs for `TmaxIC = 400 s`, and both `.lin` files are - written with `OutFmt = ES24.15E3`. CableDyn's quasi-static `dYdu` (no states) is compared with - MoorDyn's zero-frequency reduction `D − C A⁻¹ B` over 882 states. The per-fairlead stiffness agrees - to **0.07–0.10%** (line 1: 49 741 / 49 706 N/m in-plane horizontal) and the transverse `H/X` term - to 0.29%. The platform 6×6 diagonals agree to **≤0.10%** (surge 77 211 / 77 156 N/m, - roll 2.6473e8 / 2.6466e8 N·m/rad), and every entry to ≤1.0e-3 of √(KᵢᵢKⱼⱼ). Standalone CableDyn - static solves reproduce the block by finite differences to 1.5e-5, and its transverse term equals - the analytic `H/X`. Both 50-segment models sit 7–12% above the continuous elastic catenary + written with `OutFmt = ES24.15E3`. Both codes linearise the line dynamics over the same 882 states + (each interior node's position and velocity, in MoorDyn's layout and names), and their + zero-frequency reductions `D − C A⁻¹ B` are compared. The per-fairlead stiffness agrees to + **≤0.10%** (line 1: 49 741 / 49 706 N/m in-plane horizontal) and the transverse `H/X` term to 0.29%. + The platform 6×6 diagonals agree to **≤0.10%** (surge 77 211 / 77 156 N/m, roll 2.6473e8 / + 2.6466e8 N·m/rad), and every entry to ≤1.1e-3 of √(KᵢᵢKⱼⱼ). Standalone CableDyn static solves + reproduce the block by finite differences to 1e-5, and its transverse term equals the analytic + `H/X`. Both state matrices are stable, and the lowest nine line modes agree in frequency to + **0.04–0.30%** (CableDyn's consistent mass against MoorDyn's lumped mass). The damping ratios are + half MoorDyn's: both difference the quadratic drag over ±0.1 m/s, and CableDyn's drag, integrated + over the element, gives half the slope for a one-node perturbation. A mixed deck + (`examples/iea15mw_umaine_mixed_cabledyn.dat`, seabed friction off) adds 2976 states of the + lazy-wave power cable (positions and tangents of its free nodes, and their rates). Every coupled + point's linearised stiffness equals central differences of the deck's own static solutions to + ≤3.3e-4, the cable's 36.0 / 2.62 / 38.5 N/m included, and also with a 5e4 N·m/rad hang-off spring. + Two step sizes had to be small. A millimetre position step lifted the cable's grounded nodes out + of their 0.3 mm seabed penetration on one side of the difference, and a 5 cm coupled-point step + slackened the chain's last element. Each halved a stiffness (the cable's sway stiffness read 242 + instead of 2.6 N/m). States and inputs now take 1 µm. Both 50-segment models sit 7–12% above the continuous elastic catenary because of the touchdown discretisation; refining to 800 segments converges to it within 0.1%. MoorDyn's reduction needs the full-precision `OutFmt`. With the usual `ES10.3E2` (4 digits), `D ≈ 1e8 N/m` cancels to a ~1e4 N/m result and the block is 57% asymmetric with sign-flipped @@ -489,7 +501,7 @@ sizes, timing ranges, memory, Newton work, and the OrcaFlex mesh sweep are in remeshing), on the development workstation. Each binary output has exactly 144,001 rows from 600 s to 4200 s with 47 channels. The OpenFAST runtime Jacobian is the fixed-state direct-feedthrough derivative; formal linearisation - uses the re-equilibrated quasi-static stiffness. + differentiates the line dynamics with the line states registered. ### Numerical robustness @@ -780,7 +792,7 @@ stop with a named error. | Correction iterations (`NumCrctn > 0`) | Pass verified | bit-identical to own `NumCrctn = 0` run | | SeaState wave/current kinematics | Pass verified | wave A/B ≤0.16% of range | | Checkpoint-restart (incl. Free/Connect points) | Pass verified | restarted window = continuous run to 0.0; also with supercycling (`dtM` > `DT`, the held SeaState fields and the predictor loads checkpointed): IEA-15 VolturnUS-S, turbulent wind and JONSWAP sea, `openfast -restart` at 50 s reproduces every later OpenFAST and `.CD.out` row of the chain mooring at `dtM` = 4 `DT` (extrapolated and held loads) and `DT`, and of the chain + 248-element power-cable mooring at `dtM` = 2 `DT`. A finite-EI cable also checkpoints its committed boundary (held DOFs, end-connection directions, vessel frame): before, the rebuild took its fairlead from the restored input mesh, which differs in the last bits, and on the IEA-15 mixed deck restarted at 6 s the lazy-wave cable's `.CD.out` channels drifted by up to 9.4e-7 (relative) within 4 s; now all rows to 10 s match bit for bit at `dtM` = `DT` and 2 `DT`, `NumCrctn` 0 and 1, and with a rigid fairlead END CONNECTIONS row | -| Linearisation | Pass verified (quasi-static stiffness) | quasi-static `dYdu` compared entry by entry with stock MoorDyn's zero-frequency reduction `D − C A⁻¹ B` (full-precision `.lin` output): fairlead stiffness 0.07–0.10%, transverse `H/X` term 0.29%, platform 6×6 diagonals ≤0.10%; standalone static FD 1.5e-5; transverse term equals `H/X`. Velocity/acceleration columns are zero by design ([`openfast_lin_ab.py`](https://github.com/SMI-Lab-Inha/CableDyn/blob/main/validation/scripts/openfast_lin_ab.py)) | +| Linearisation | Pass verified (line dynamics) | line states as MoorDyn-F's (882 on the UMaine chains); zero-frequency reduction `D − C A⁻¹ B` compared entry by entry with stock MoorDyn's (full-precision `.lin` output): fairlead stiffness ≤0.10%, transverse `H/X` term 0.29%, platform 6×6 diagonals ≤0.10%; lowest nine line-mode frequencies 0.04–0.30%, both state matrices stable; a mixed deck with a lazy-wave power cable (2976 cable states) matches its own static solutions at every coupled point to ≤3.3e-4, also with a hang-off spring ([`openfast_lin_ab.py`](https://github.com/SMI-Lab-Inha/CableDyn/blob/main/validation/scripts/openfast_lin_ab.py)) | | FAST.Farm shared moorings + clumps + channel record | Pass verified | 600 s A/B of the r-test `MD_Shared` farm against stock MoorDyn (same deck, analysis from 100 s; [`fastfarm_shared_ab.py`](https://github.com/SMI-Lab-Inha/CableDyn/blob/main/validation/scripts/fastfarm_shared_ab.py)): tension means ≤0.02%, minima and maxima ≤0.25%, platform motions within millimetres and 0.001°; shared-line tension std 2.2–2.7% lower, 1.0% at half the mooring step (CableDyn's implicit step at the 0.05 s coupling step against MoorDyn's 1e-4 s explicit step). On the shared lines, which have no Fixed end, `FairTen`/`AnchTen` name the opposite ends from MoorDyn's (see the migration guide). MoorDyn's initial settling does not converge for the anchor legs 6 and 7 (2.4 m excess length at t = 0), a start-up transient over by 100 s that most likely set the 3% end of the earlier 60 s record | | Slack-line tension convention | Pass verified | tension-only dynamics; BA on slack lines matches `MoorDyn_Line.f90` | | Farm + restart / Farm + linearisation | Not applicable | FAST.Farm has no restart and does not call module linearisation; the same applies to stock MoorDyn | diff --git a/doc/openfast.rst b/doc/openfast.rst index 6ddf88dd..05bc6a89 100644 --- a/doc/openfast.rst +++ b/doc/openfast.rst @@ -326,8 +326,9 @@ hang-off the declared direction is given in platform axes and follows the OpenFA orientation; its angular velocity and acceleration enter the implicit residual and tangent, and the connection moment is returned to OpenFAST. Fixed-end directions are global. A rigid direction reversal of exactly 180° in one host update is rejected, because the shortest rotation -is not unique. Formal linearisation (``Linearize = True``) with a platform-relative end -connection fails during initialisation. Row grammar: :doc:`driver_format`. +is not unique. Formal linearisation (``Linearize = True``) supports pinned and numeric-stiffness +connections; a ``Rigid`` row fails during initialisation, because only the axial stretch of its +end tangent is a degree of freedom (see `Linearisation`_). Row grammar: :doc:`driver_format`. Line torsion ------------ @@ -413,15 +414,42 @@ without an auxiliary process: Each is a separate qualification: a successful ordinary run does not qualify restart, linearisation, control, failure, or farm behaviour for a new model. -Two different Jacobians -~~~~~~~~~~~~~~~~~~~~~~~ +Jacobians +~~~~~~~~~ During time marching, the OpenFAST input–output solver asks for the instantaneous output derivative with the cable state frozen; CableDyn evaluates it by symmetric perturbation of the -coupled input while preserving the committed state. In a ``Linearize = True`` run CableDyn -registers no dynamic states and reports the re-equilibrated quasi-static stiffness instead. -These are different derivatives and must not be interchanged. ``NumCrctn`` controls glue -correction passes; it does not change which derivative is used. +coupled input while preserving the committed state. A ``Linearize = True`` run differentiates the +line dynamics themselves (`Linearisation`_). ``NumCrctn`` controls glue correction passes; it does +not change which derivative is used. + +Linearisation +~~~~~~~~~~~~~ + +With ``Linearize = True`` CableDyn linearises the line dynamics, as MoorDyn-F does. The continuous +states are the positions of every ``EI = 0`` line's interior nodes and of every finite-EI cable's +free degrees of freedom (node positions and tangents ``m = dr/ds``), followed by their velocities. +``EI = 0`` states carry MoorDyn's names and order (``Line 1 node 1 Px, m`` … ``Vz, m/s``); a cable's +are named ``Cable 1 node 2 Px, m``, ``Cable 1 node 2 Tx, -`` (tangent) and ``Cable 1 node 2 dTx, +1/s`` (its rate), with node 1 at End A. The matrices ``A``, ``B``, ``C`` and ``D`` are central +differences: at each perturbed state or input, the accelerations are solved without a time step. +Positions, tangents and coupled-point displacements are stepped by 1 µm, which stays inside the +seabed penetration of a light cable and the stretch of every taut element. Velocities are stepped +by 0.1 m/s, MoorDyn-F's step. + +The zero-frequency reduction ``D − C A⁻¹ B`` is the static mooring stiffness. It agrees with +MoorDyn-F and with CableDyn's own static solutions (:doc:`validation`). Quadratic drag has no +slope at rest, so the 0.1 m/s step gives its equivalent linear damping at that velocity amplitude. +CableDyn integrates the drag over the element, and a one-node step then gives about half of +MoorDyn-F's lumped value. The internal states of viscoelastic, Syrope and VIV models and the +seabed-friction anchors are held at their operating-point values: the linearisation sees the rope's +instantaneous stiffness and a stuck laid run. Linearise from a settled operating point, such as the +still-water start at ``t = 0``. + +Initialisation fails with a named message for Free and Connect points, Point3 buoys, Rigid6 bodies +and rods, a line restrained in torsion, a ``CONTROL`` section, a cable with a ``Rigid`` end +connection, and FAST.Farm. These carry states that are not linearisation states. Time-domain runs +support all of them. Performance ----------- diff --git a/doc/troubleshooting.rst b/doc/troubleshooting.rst index 14cfbfc4..8842c028 100644 --- a/doc/troubleshooting.rst +++ b/doc/troubleshooting.rst @@ -403,8 +403,8 @@ Torsion FAST.Farm run, add a body (such a deck runs on the multibody route, which supports torsion), or set ``TorsStiffness Free`` in every ``END CONNECTIONS`` row. * - ``formal OpenFAST linearization of a line restrained in torsion is not supported`` - - linearise the model with ``TorsStiffness Free``; the torque's rotational stiffness is not - part of the quasi-static reduction. + - linearise the model with ``TorsStiffness Free``; the twist and the torque carry no + linearisation state. * - ``torsion: the twist would move more than pi/2 from its committed value`` - the host turned a fairlead by more than 90° about the line's end direction without a step (an output probe or a non-stepping input update). Keep the platform turn per @@ -846,10 +846,12 @@ aborts with a CableDyn fatal error, check whether the deck uses one of these com * - a finite-EI cable in the same deck as Rigid6 bodies, rods, or ``Connect``/``Free`` points - model the cable and the body/point system in separate decks or use the supported combinations in :doc:`capabilities` - * - OpenFAST linearisation with a platform-relative cable ``END CONNECTIONS`` row - (``formal OpenFAST linearization with a platform-relative cable end connection is not - supported``) or with a ``CONTROL`` section - - linearise a pinned-hang-off, uncontrolled variant of the deck; time-domain runs support both + * - OpenFAST linearisation of a cable with a ``Rigid`` ``END CONNECTIONS`` row (``formal + OpenFAST linearization of a cable with a rigid end connection is not supported``), of a deck + with ``Free`` or ``Connect`` points, or with a ``CONTROL`` section + - linearise a variant with a numeric rotational stiffness at the hang-off, the lines attached to + ``Fixed`` or ``Coupled`` points, and no ``CONTROL`` section; time-domain runs support all of + them * - a ``Rigid`` end-connection direction reversed by exactly 180 degrees in one host update - drive the platform through intermediate orientations * - VIV on a finite-EI line with two moving ends (``needs its End B fixed``) diff --git a/src/CableDyn_System.f90 b/src/CableDyn_System.f90 index cb3b130a..2c9e9b3b 100644 --- a/src/CableDyn_System.f90 +++ b/src/CableDyn_System.f90 @@ -85,6 +85,7 @@ MODULE CableDyn_System PUBLIC :: CD_Get_System_Point_State PUBLIC :: CD_Get_System_Line_State PUBLIC :: CD_Get_System_Line_Tension + PUBLIC :: CD_Get_System_Line_Stretch PUBLIC :: CD_Get_System_CoupledMotion PUBLIC :: CD_Update_System_CoupledMotion PUBLIC :: CD_Update_System_Point_States @@ -1149,6 +1150,33 @@ SUBROUTINE CD_Get_System_Line_Tension(system, line_index, tension, ErrStat, ErrM ErrMsg = '' END SUBROUTINE CD_Get_System_Line_Tension + SUBROUTINE CD_Get_System_Line_Stretch(system, line_index, stretch, ErrStat, ErrMsg) + !! Copy the element stretches of one contained line: each element's current chord length + !! minus its unstretched length (negative on a slack element). + TYPE(CD_SystemType), INTENT(IN) :: system + INTEGER, INTENT(IN) :: line_index + REAL(wp), INTENT(OUT) :: stretch(:) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + + INTEGER :: e, na, nb + + stretch = CD_ZERO + CALL validate_line_index(system, line_index, ErrStat, ErrMsg) + IF (ErrStat /= CD_SYSTEM_OK) RETURN + ASSOCIATE (ln => system%lines(line_index)) + IF (SIZE(stretch) /= ln%n_elem) THEN + CALL fail(ErrStat, ErrMsg, 'stretch output must have shape (n_elem)') + RETURN + END IF + DO e = 1, ln%n_elem + na = ln%elem_conn(1, e) + nb = ln%elem_conn(2, e) + stretch(e) = NORM2(ln%q(3*nb - 2:3*nb) - ln%q(3*na - 2:3*na)) - ln%l0(e) + END DO + END ASSOCIATE + END SUBROUTINE CD_Get_System_Line_Stretch + SUBROUTINE CD_Get_System_CoupledMotion(system, q_coupled, v_coupled, a_coupled, ErrStat, ErrMsg) !! Copy aggregate compact coupled motion, concatenated line by line. TYPE(CD_SystemType), INTENT(IN) :: system diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index 9c29dee5..36216744 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -52,9 +52,12 @@ MODULE CableDyn !! wave/current kinematics sampled at the line nodes (single-turbine only; see the !! farm scope at the use_extf guard), checkpoint restart (rebuild from the packed !! deck + state mirror, accepted on committed mooring-interval boundaries), - !! linearization (quasi-static dYdu only -- no dynamic state linearization; the - !! module registers zero continuous states and CD_CalcContStateDeriv stays fatal - !! by design), and FAST.Farm farm-level moorings (FarmSize > 0: Turbine decks, + !! linearization with the line dynamics (as MoorDyn-F: the continuous states are the + !! EI=0 lines' interior-node positions and the finite-EI cables' free DOFs, positions + !! and tangents, then their velocities; A, B, C and D by central differences of + !! lin_eval, the accelerations solved at the perturbed state; Free/Connect points, + !! bodies, rods, Point3 buoys, torsion, CONTROL and rigid cable ends fail closed), and + !! FAST.Farm farm-level moorings (FarmSize > 0: Turbine decks, !! per-turbine coupled meshes, shared lines; still-water hydro; farm restart and !! farm linearization fail closed with named messages). Checkpoint restart and !! linearization re-parse a temporary copy of the deck, written next to the @@ -94,7 +97,7 @@ MODULE CableDyn USE CableDyn_OpenFAST_HermiteFMF, ONLY: CD_HFMF_MirrorSize, CD_HFMF_PackMirror, CD_HFMF_UnpackMirror, & CD_HFMF_FrictionMirrorSize, CD_HFMF_BoundaryMirrorSize, & CD_HFMF_ForceMirrorSize, CD_HFMF_TorsionMirrorSize, CD_HFMF_VIVMirrorSize, & - CD_HFMF_OK + CD_HFMF_Refresh_Acceleration, CD_HFMF_OK USE CableDyn_HermiteCableDynamic, ONLY: CD_HermiteCable_Dyn_Reset_Profile, & CD_HermiteCable_Dyn_Disable_Profile, & CD_HermiteCable_Dyn_Get_Profile, & @@ -104,6 +107,8 @@ MODULE CableDyn USE CableDyn_LoadPredictor, ONLY: CD_Predictor_Ready, CD_Predictor_Fraction, CD_Predict_Loads USE CableDyn_Profile, ONLY: CD_Profile_Arm, CD_Profile_Disarm, CD_Profile_Kernels, CD_PROF_K_RESIDUAL, & CD_PROF_K_TANGENT, CD_PROF_K_FACTOR, CD_PROF_K_SOLVE, CD_PROF_NKERNEL + USE CableDyn_System, ONLY: CD_Get_System_Line_Stretch + USE CableDyn_EndConnection, ONLY: CD_ENDCONN_RIGID USE CableDyn_System, ONLY: CD_System_NLines, CD_System_Line_NDOF, CD_System_Line_NElem, & CD_Get_System_DynamicPoint_States, CD_Set_System_DynamicPoint_States, & CD_System_NSystemCoupledDOF, CD_Get_System_CoupledMotion, & @@ -192,6 +197,12 @@ END FUNCTION cd_cpu_guard_armed ! restored after (the boundary-only restore recomputes interior accelerations, ! which are gen-alpha COMMITTED values, not (q, v)-derivable) REAL(R8Ki), ALLOCATABLE :: ws_msave(:) + ! Linearization with the line dynamics (lin_state_map): for every state, its position, + ! velocity and acceleration slots in the x%states mirror, and the mirror save/work + ! buffers of lin_eval + LOGICAL :: lin_states = .FALSE. + INTEGER(IntKi), ALLOCATABLE :: lin_pos(:), lin_vel(:), lin_acc(:) + REAL(R8Ki), ALLOCATABLE :: ws_lsave(:), ws_lwork(:) ! FAST.Farm: turbine count (0 = plain single-turbine mode), the driving turbine ! per flat aggregate moving slot, that slot's node index within its turbine's ! mesh, the farm-layout reference offsets, and the per-turbine PtfmInit. @@ -779,46 +790,57 @@ SUBROUTINE CD_Init(InitInp, u, p, x, xd, z, other, y, m, DTcoupling, InitOut, Er CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: '//TRIM(em), ErrStat, ErrMsg, RoutineName ) RETURN END IF - ! Rigid6 bodies and rods carry their own degrees of freedom, but the quasi-static - ! linearization re-solves only the line and point equilibrium at each perturbed - ! boundary and holds them at their deck pose, so its dYdu would silently omit - ! their compliance. Fail closed until body-state linearization exists. + ! Rigid6 bodies and rods carry their own degrees of freedom, which are not linearization + ! states (the states are the line and cable DOFs): the linearization would hold them + ! where they are and omit their compliance. Fail closed until body-state linearization + ! exists. IF (InitInp%Linearize .AND. (CD_AGG_HasRigid6( Inst(id)%agg ) .OR. CD_AGG_HasRod( Inst(id)%agg ))) THEN CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: formal OpenFAST linearization '// & - 'with Rigid6 bodies or RODs is not supported; the quasi-static reduction '// & - 'holds them at their deck pose instead of re-solving their equilibrium '// & - '(linearize a deck without BODIES/RODS).', ErrStat, ErrMsg, RoutineName ) + 'with Rigid6 bodies or RODs is not supported; their states are not '// & + 'linearization states (linearize a deck without BODIES/RODS).', & + ErrStat, ErrMsg, RoutineName ) RETURN END IF - ! A Point3 buoy steps as a Free point, but the static solve holds it at its deck position: - ! each perturbed re-solve would leave it there and omit its compliance as well. + ! A Point3 buoy steps as a Free point with its own state, which is not a linearization + ! state either. IF (InitInp%Linearize .AND. CD_AGG_HasPoint3( Inst(id)%agg )) THEN CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: formal OpenFAST linearization '// & - 'with Point3 buoys is not supported; the quasi-static reduction holds a '// & - 'Point3 buoy at its deck position instead of re-solving its equilibrium '// & - '(model the buoy as a Free point to linearize).', ErrStat, ErrMsg, RoutineName ) + 'with Point3 buoys is not supported; their states are not linearization '// & + 'states.', ErrStat, ErrMsg, RoutineName ) + RETURN + END IF + ! A Free/Connect point steps with its own state through the implicit point-line coupling; + ! the linearization states are the line and cable DOFs only, so the point would be held + ! where it is and its compliance omitted. + IF (InitInp%Linearize .AND. CD_AGG_NDynamicPoints( Inst(id)%agg ) > 0) THEN + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: formal OpenFAST linearization '// & + 'with Free or Connect points is not supported; their states are not '// & + 'linearization states (attach the lines to Fixed or Coupled points to '// & + 'linearize).', ErrStat, ErrMsg, RoutineName ) RETURN END IF IF (InitInp%Linearize .AND. Inst(id)%agg%ncable > 0) THEN DO ic = 1, Inst(id)%agg%ncable + ! a rigid end connection holds the end tangent on the parent's direction, so only + ! its axial part is a degree of freedom, which the global-component states cannot + ! carry + IF (ANY(Inst(id)%agg%cables(ic)%line%endconn_mode == CD_ENDCONN_RIGID)) THEN + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: formal OpenFAST linearization '// & + 'of a cable with a rigid end connection is not supported (use a '// & + 'finite rotational stiffness in END CONNECTIONS to linearize).', & + ErrStat, ErrMsg, RoutineName ) + RETURN + END IF ! a line restrained in torsion returns a torque moment that turns with the platform ! even at a bending-pinned end: its rotational stiffness a a^T / C has no column in ! the translation-only reduction either IF (Inst(id)%agg%cables(ic)%line%torsion%active) THEN CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: formal OpenFAST linearization '// & - 'of a line restrained in torsion is not supported; the torque''s '// & - 'orientation and moment Jacobian columns are not part of the current '// & - 'quasi-static reduction (set TorsStiffness Free to linearize).', & + 'of a line restrained in torsion is not supported: its condensed torque '// & + 'carries no state of its own (set TorsStiffness Free to linearize).', & ErrStat, ErrMsg, RoutineName ) RETURN END IF - IF (.NOT. Inst(id)%agg%cables(ic)%has_parent_endconn) CYCLE - CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: formal OpenFAST linearization '// & - 'with a platform-relative cable end connection is not supported; '// & - 'the required orientation and connection-moment Jacobian columns '// & - 'are not part of the current quasi-static reduction.', & - ErrStat, ErrMsg, RoutineName ) - RETURN END DO END IF CALL CD_AGG_GetInitMetadata( Inst(id)%agg, nreportlines, npoints, nsections, nei0, nfinite, es, em ) @@ -1215,6 +1237,11 @@ SUBROUTINE CD_Init(InitInp, u, p, x, xd, z, other, y, m, DTcoupling, InitOut, Er CALL CD_InitVars( InitOut%Vars, u, p, x, y, m, Inst(id), InitInp%Linearize, ErrStat2, ErrMsg2 ) CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) IF (ErrStat >= AbortErrLev) RETURN + IF (InitInp%Linearize) THEN + CALL lin_state_map( Inst(id), m, ErrStat2, ErrMsg2 ) + CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + IF (ErrStat >= AbortErrLev) RETURN + END IF ! The time history contains the selected deck channels and is therefore opened only ! when nch > 0. The static profile, unconditional and covering every line node @@ -2645,16 +2672,241 @@ SUBROUTINE CD_CalcContStateDeriv( t, u, p, x, xd, z, other, m, dxdt, ErrStat, Er CHARACTER(*), INTENT( OUT) :: ErrMsg character(*), parameter :: RoutineName = 'CD_CalcContStateDeriv' + INTEGER(IntKi) :: ErrStat2 + CHARACTER(ErrMsgLen) :: ErrMsg2 ErrStat = ErrID_None ErrMsg = '' - ! Only the linearization/GetOP paths reach this routine (the module marches - ! implicitly through UpdateStates). CableDyn exposes no continuous states. - CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: continuous-state derivatives are part of '// & - 'the linearization surface; CableDyn exposes no continuous states to OpenFAST.', & - ErrStat, ErrMsg, RoutineName ) + ! Only the linearization/GetOP paths reach this routine (the module marches implicitly + ! through UpdateStates): dx/dt of the linearization states (lin_eval). + IF (.NOT. Inst(m%CDInst)%lin_states) THEN + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: continuous-state derivatives exist only '// & + 'for a linearization run (Linearize = True).', ErrStat, ErrMsg, RoutineName ) + RETURN + END IF + CALL lin_eval( m%CDInst, p, m, u, x, ErrStat2, ErrMsg2, dxdt=dxdt ) + CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) END SUBROUTINE CD_CalcContStateDeriv +!---------------------------------------------------------------------------------------------------------------------------------- + SUBROUTINE lin_state_map( inst_e, m, ErrStat, ErrMsg ) + !! The x%states mirror slots of the linearization states (CD_InitVars under Linearize): for + !! every interior DOF of an EI = 0 line and every free DOF of a finite-EI cable, the slot of + !! its position, of its velocity and of its acceleration (lin_pos, lin_vel, lin_acc), and the + !! mirror buffers of lin_eval. + TYPE(CD_OF_Instance), INTENT(INOUT) :: inst_e + TYPE(CD_MiscVarType), INTENT(IN) :: m + INTEGER(IntKi), INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER(IntKi) :: il, ic, ndofl, nin, nf, csz, koff, n, k, j, es + CHARACTER(ErrMsgLen) :: em + + ErrStat = ErrID_None + ErrMsg = '' + n = 0 + DO il = 1, inst_e%nlines + ndofl = CD_System_Line_NDOF( inst_e%agg%sys%fast%system, il, es, em ) + IF (es /= CD_SYSTEM_OK) THEN + CALL SetErrStat( ErrID_Fatal, TRIM(em), ErrStat, ErrMsg, 'lin_state_map' ); RETURN + END IF + n = n + ndofl - 6 + END DO + DO ic = 1, inst_e%agg%ncable + IF (CD_HFMF_MirrorSize( inst_e%agg%cables(ic) ) <= 0) CYCLE + n = n + COUNT(inst_e%agg%cables(ic)%line%freemask) + END DO + IF (ALLOCATED(inst_e%lin_pos)) DEALLOCATE (inst_e%lin_pos, inst_e%lin_vel, inst_e%lin_acc) + IF (ALLOCATED(inst_e%ws_lsave)) DEALLOCATE (inst_e%ws_lsave, inst_e%ws_lwork) + ALLOCATE (inst_e%lin_pos(n), inst_e%lin_vel(n), inst_e%lin_acc(n), inst_e%ws_lsave(m%Nx), & + inst_e%ws_lwork(m%Nx), STAT=es) + IF (es /= 0) THEN + CALL SetErrStat( ErrID_Fatal, 'Could not allocate the linearization state map.', ErrStat, ErrMsg, & + 'lin_state_map' ); RETURN + END IF + ! a mooring line's interior block is [v; r; a], 3 (N - 1) each, at LineStateIs1 + k = 0 + DO il = 1, inst_e%nlines + ndofl = CD_System_Line_NDOF( inst_e%agg%sys%fast%system, il, es, em ) + nin = ndofl - 6 + DO j = 0, nin - 1 + k = k + 1 + inst_e%lin_vel(k) = m%LineStateIs1(il) + j + inst_e%lin_pos(k) = m%LineStateIs1(il) + nin + j + inst_e%lin_acc(k) = m%LineStateIs1(il) + 2*nin + j + END DO + END DO + ! a cable's mirror starts [v_free; q_free; a_free], after the mooring block + koff = 0 + IF (inst_e%nlines > 0) koff = m%LineStateIsN(inst_e%nlines) + DO ic = 1, inst_e%agg%ncable + csz = CD_HFMF_MirrorSize( inst_e%agg%cables(ic) ) + IF (csz <= 0) CYCLE + nf = COUNT(inst_e%agg%cables(ic)%line%freemask) + DO j = 1, nf + k = k + 1 + inst_e%lin_vel(k) = koff + j + inst_e%lin_pos(k) = koff + nf + j + inst_e%lin_acc(k) = koff + 2*nf + j + END DO + koff = koff + csz + END DO + inst_e%lin_states = .TRUE. + END SUBROUTINE lin_state_map + + SUBROUTINE lin_disp_step( inst_, dx, ErrStat, ErrMsg ) + !! The coupled-point displacement step of the linearization, as MoorDyn-F's: half the + !! smallest positive element stretch of the EI = 0 lines, at most dx on entry. A larger + !! step would slacken a tension-only element on one side of the central difference (a + !! taut chain stretches about a centimetre per element) and halve its stiffness. + TYPE(CD_OF_Instance), INTENT(IN) :: inst_ + REAL(R8Ki), INTENT(INOUT) :: dx + INTEGER(IntKi), INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + + INTEGER(IntKi) :: il, ne, es + CHARACTER(ErrMsgLen) :: em + REAL(wp), ALLOCATABLE :: stretch(:) + + ErrStat = ErrID_None + ErrMsg = '' + DO il = 1, inst_%nlines + ne = CD_System_Line_NElem( inst_%agg%sys%fast%system, il, es, em ) + IF (es == CD_SYSTEM_OK) THEN + ALLOCATE (stretch(ne)) + CALL CD_Get_System_Line_Stretch( inst_%agg%sys%fast%system, il, stretch, es, em ) + END IF + IF (es /= CD_SYSTEM_OK) THEN + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: line '//TRIM(Num2LStr(il))//': '// & + TRIM(em), ErrStat, ErrMsg, 'CableDyn:lin_disp_step' ); RETURN + END IF + IF (ANY(stretch > 0.0_wp)) dx = MIN(dx, 0.5_R8Ki*REAL(MINVAL(stretch, MASK=stretch > 0.0_wp), R8Ki)) + DEALLOCATE (stretch) + END DO + END SUBROUTINE lin_disp_step + +!---------------------------------------------------------------------------------------------------------------------------------- + SUBROUTINE lin_eval( id, p, m, u, x_in, ErrStat, ErrMsg, dxdt, y_out ) + !! The linearization surface at the state x_in and input u: the line interiors and cable + !! free DOFs take x_in's positions and velocities, the coupled points u's kinematics, and the + !! accelerations are solved from them without a time step. dxdt gets dx/dt of the + !! linearization states (each position slot its velocity, each velocity slot its + !! acceleration; the other slots 0); y_out the loads on the coupled points and the deck + !! channels at that state. The committed state is restored on exit. + INTEGER(IntKi), INTENT(IN ) :: id + TYPE(CD_ParameterType), INTENT(IN ) :: p + TYPE(CD_MiscVarType), INTENT(INOUT) :: m + TYPE(CD_InputType), INTENT(IN ) :: u + TYPE(CD_ContinuousStateType), INTENT(IN ) :: x_in + INTEGER(IntKi), INTENT( OUT) :: ErrStat + CHARACTER(*), INTENT( OUT) :: ErrMsg + TYPE(CD_ContinuousStateType), INTENT(INOUT), OPTIONAL :: dxdt + TYPE(CD_OutputType), INTENT(INOUT), OPTIONAL :: y_out + + character(*), parameter :: RoutineName = 'CableDyn:lin_eval' + INTEGER(IntKi) :: ErrStat2, es, i, ic + CHARACTER(ErrMsgLen) :: ErrMsg2, em + REAL(wp) :: cval, t_clock + + ErrStat = ErrID_None + ErrMsg = '' + t_clock = REAL(MAX(Inst(id)%t_commit, 0.0_DbKi), wp) + ! the committed state: the coupled kinematics and the whole mirror + CALL CD_AGG_GetMovingPointMesh( Inst(id)%agg, Inst(id)%sv_pos, Inst(id)%sv_vel, Inst(id)%sv_acc, & + Inst(id)%ws_fld, es, em, orientation=Inst(id)%sv_orient, & + angular_velocity=Inst(id)%sv_omega, angular_acceleration=Inst(id)%sv_alpha, & + cable_loads=.FALSE. ) + IF (es /= CD_AGG_OK) THEN + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: '//TRIM(em), ErrStat, ErrMsg, RoutineName ); RETURN + END IF + CALL pack_state_mirror_ary( Inst(id), m, Inst(id)%ws_lsave, ErrStat2, ErrMsg2 ) + CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + IF (ErrStat >= AbortErrLev) RETURN + ! the state: x_in's positions and velocities in the committed mirror + Inst(id)%ws_lwork = Inst(id)%ws_lsave + Inst(id)%ws_lwork(Inst(id)%lin_pos) = x_in%states(Inst(id)%lin_pos) + Inst(id)%ws_lwork(Inst(id)%lin_vel) = x_in%states(Inst(id)%lin_vel) + CALL reload_interiors_ary( Inst(id), m, Inst(id)%ws_lwork, t_clock, ErrStat2, ErrMsg2 ) + CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + IF (ErrStat >= AbortErrLev) THEN + CALL restore; RETURN + END IF + ! the input: the coupled points move to u, and the accelerations follow (the EI = 0 lines + ! in the non-probe update, the cables by their refresh) + CALL mesh_to_arrays( u%CoupledKinematics(1), Inst(id)%ncp, Inst(id)%ws_pos, Inst(id)%ws_vel, & + Inst(id)%ws_acc, Inst(id)%ws_orient, Inst(id)%ws_omega, Inst(id)%ws_alpha, & + ErrStat2, ErrMsg2 ) + CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + IF (ErrStat >= AbortErrLev) THEN + CALL restore; RETURN + END IF + CALL CD_AGG_UpdateStates_Moving( Inst(id)%agg, Inst(id)%ws_pos, Inst(id)%ws_vel, Inst(id)%ws_acc, es, em, & + output_probe=.FALSE., orientation=Inst(id)%ws_orient, & + angular_velocity=Inst(id)%ws_omega, angular_acceleration=Inst(id)%ws_alpha ) + IF (es /= CD_AGG_OK) THEN + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: '//TRIM(em), ErrStat, ErrMsg, RoutineName ) + CALL restore; RETURN + END IF + DO ic = 1, Inst(id)%agg%ncable + CALL CD_HFMF_Refresh_Acceleration( Inst(id)%agg%cables(ic), es, em ) + IF (es /= CD_HFMF_OK) THEN + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: cable '//TRIM(Num2LStr(ic))// & + ' acceleration: '//TRIM(em), ErrStat, ErrMsg, RoutineName ) + CALL restore; RETURN + END IF + END DO + IF (PRESENT(dxdt)) THEN + CALL pack_state_mirror_ary( Inst(id), m, Inst(id)%ws_lwork, ErrStat2, ErrMsg2 ) + CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + IF (ErrStat >= AbortErrLev) THEN + CALL restore; RETURN + END IF + dxdt%states = 0.0_R8Ki + dxdt%states(Inst(id)%lin_pos) = Inst(id)%ws_lwork(Inst(id)%lin_vel) + dxdt%states(Inst(id)%lin_vel) = Inst(id)%ws_lwork(Inst(id)%lin_acc) + END IF + IF (PRESENT(y_out)) THEN + CALL CD_AGG_CalcOutput( Inst(id)%agg, es, em ) + IF (es == CD_AGG_OK) CALL CD_AGG_GetMovingPointMesh( Inst(id)%agg, Inst(id)%ws_pos, Inst(id)%ws_vel, & + Inst(id)%ws_acc, Inst(id)%ws_fld, es, em, & + orientation=Inst(id)%ws_orient, & + moment=Inst(id)%ws_moment, & + angular_velocity=Inst(id)%ws_omega, & + angular_acceleration=Inst(id)%ws_alpha ) + IF (es /= CD_AGG_OK) THEN + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: '//TRIM(em), ErrStat, ErrMsg, RoutineName ) + CALL restore; RETURN + END IF + DO i = 1, Inst(id)%ncp + y_out%CoupledLoads(1)%Force(:, i) = REAL(Inst(id)%ws_fld(:, i), ReKi) + y_out%CoupledLoads(1)%Moment(:, i) = REAL(Inst(id)%ws_moment(:, i), ReKi) + END DO + DO i = 1, p%NumOuts + CALL CD_AGG_EvalChannel( Inst(id)%agg, i, cval, es, em ) + IF (es /= CD_AGG_OK) THEN + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: output channel evaluation failed: '// & + TRIM(em), ErrStat, ErrMsg, RoutineName ) + CALL restore; RETURN + END IF + y_out%WriteOutput(i) = REAL(cval, ReKi) + END DO + END IF + CALL restore + + CONTAINS + + SUBROUTINE restore() + !! The committed coupled kinematics and mirror back; the held loads are re-evaluated. + CALL CD_AGG_UpdateStates_Moving( Inst(id)%agg, Inst(id)%sv_pos, Inst(id)%sv_vel, Inst(id)%sv_acc, es, em, & + output_probe=.TRUE., orientation=Inst(id)%sv_orient, & + angular_velocity=Inst(id)%sv_omega, angular_acceleration=Inst(id)%sv_alpha ) + IF (es /= CD_AGG_OK) CALL SetErrStat( ErrID_Fatal, 'CableDyn linearization restore failed: '//TRIM(em), & + ErrStat, ErrMsg, RoutineName ) + CALL reload_interiors_ary( Inst(id), m, Inst(id)%ws_lsave, t_clock, ErrStat2, ErrMsg2 ) + CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + Inst(id)%loads_cached = .FALSE. + END SUBROUTINE restore + END SUBROUTINE lin_eval + !---------------------------------------------------------------------------------------------------------------------------------- SUBROUTINE CD_End(u, p, x, xd, z, other, y, m, ErrStat , ErrMsg) USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: int64 @@ -2838,6 +3090,54 @@ SUBROUTINE CD_JacobianPInput(Vars, t, u, p, x, xd, z, OtherState, y, m, ErrStat, ! Get OP values here (the FD reference point) CALL CD_CalcOutput( t, u, p, x, xd, z, OtherState, y, m, ErrStat2, ErrMsg2 ); IF (Failed()) RETURN + ! Linearization with the line dynamics (the glue asks for dXdu with dYdu; the runtime + ! input/output solve asks for dYdu alone): the partial derivatives at the fixed state x, + ! by central differences of lin_eval, as MoorDyn-F's of its CalcOutput and + ! CalcContStateDeriv. + IF (Inst(m%CDInst)%lin_states .AND. PRESENT(dXdu)) THEN + IF (PRESENT(dYdu)) THEN + IF (.NOT. ALLOCATED(dYdu)) THEN + CALL AllocAry( dYdu, m%Jac%Ny, m%Jac%Nu, 'dYdu', ErrStat2, ErrMsg2 ); IF (Failed()) RETURN + END IF + dYdu = 0.0_R8Ki + END IF + IF (.NOT. ALLOCATED(dXdu)) THEN + CALL AllocAry( dXdu, m%Jac%Nx, m%Jac%Nu, 'dXdu', ErrStat2, ErrMsg2 ); IF (Failed()) RETURN + END IF + dXdu = 0.0_R8Ki + CALL CD_CopyInput( u, m%u_perturb, MESH_UPDATECOPY, ErrStat2, ErrMsg2 ); IF (Failed()) RETURN + CALL CD_VarsPackInput( Vars, u, m%Jac%u ) + DO i = 1, SIZE(Vars%u) + DO j = 1, Vars%u(i)%Num + iCol = Vars%u(i)%iLoc(1) + j - 1 + CALL MV_Perturb( Vars%u(i), j, 1, m%Jac%u, m%Jac%u_perturb ) + CALL CD_VarsUnpackInput( Vars, m%Jac%u_perturb, m%u_perturb ) + CALL lin_eval( m%CDInst, p, m, m%u_perturb, x, ErrStat2, ErrMsg2, dxdt=m%dxdt_lin, y_out=m%y_lin ) + IF (Failed()) RETURN + CALL CD_VarsPackOutput( Vars, m%y_lin, m%Jac%y_pos ) + CALL CD_VarsPackContStateDeriv( Vars, m%dxdt_lin, m%Jac%x_pos ) + CALL MV_Perturb( Vars%u(i), j, -1, m%Jac%u, m%Jac%u_perturb ) + CALL CD_VarsUnpackInput( Vars, m%Jac%u_perturb, m%u_perturb ) + CALL lin_eval( m%CDInst, p, m, m%u_perturb, x, ErrStat2, ErrMsg2, dxdt=m%dxdt_lin, y_out=m%y_lin ) + IF (Failed()) RETURN + CALL CD_VarsPackOutput( Vars, m%y_lin, m%Jac%y_neg ) + CALL CD_VarsPackContStateDeriv( Vars, m%dxdt_lin, m%Jac%x_neg ) + IF (PRESENT(dYdu)) CALL MV_ComputeCentralDiff( Vars%y, Vars%u(i)%Perturb, m%Jac%y_pos, m%Jac%y_neg, & + dYdu(:, iCol) ) + dXdu(:, iCol) = (m%Jac%x_pos - m%Jac%x_neg)/(2.0_R8Ki*Vars%u(i)%Perturb) + END DO + END DO + ! the outputs at the operating point again (the glue reads y after this call) + CALL CD_CalcOutput( t, u, p, x, xd, z, OtherState, y, m, ErrStat2, ErrMsg2 ); IF (Failed()) RETURN + IF (PRESENT(dXddu)) THEN + IF (ALLOCATED(dXddu)) DEALLOCATE (dXddu) + END IF + IF (PRESENT(dZdu)) THEN + IF (ALLOCATED(dZdu)) DEALLOCATE (dZdu) + END IF + RETURN + END IF + ! dY/du has TWO distinct contracts. During a normal nonlinear OpenFAST run the ! registered CableDyn states exist (Nx > 0), and the glue input/output solve needs ! the PARTIAL derivative g_u at fixed internal state. Re-equilibrating the line for @@ -3092,13 +3392,66 @@ SUBROUTINE CD_JacobianPContState(Vars, t, u, p, x, xd, z, OtherState, y, m, ErrS character(*), parameter :: RoutineName = 'CD_JacobianPContState' - INTEGER(IntKi) :: ErrStat2 + INTEGER(IntKi) :: ErrStat2, i, j, iCol CHARACTER(ErrMsgLen) :: ErrMsg2 ErrStat = ErrID_None ErrMsg = '' ErrStat2 = ErrID_None ErrMsg2 = '' + ! Linearization with the line dynamics: dYdx and dXdx by central differences of lin_eval + ! over the registered states, as MoorDyn-F's + IF (Inst(m%CDInst)%lin_states) THEN + IF (PRESENT(dYdx)) THEN + IF (.NOT. ALLOCATED(dYdx)) THEN + CALL AllocAry( dYdx, m%Jac%Ny, m%Jac%Nx, 'dYdx', ErrStat2, ErrMsg2 ) + CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + IF (ErrStat >= AbortErrLev) RETURN + END IF + dYdx = 0.0_R8Ki + END IF + IF (PRESENT(dXdx)) THEN + IF (.NOT. ALLOCATED(dXdx)) THEN + CALL AllocAry( dXdx, m%Jac%Nx, m%Jac%Nx, 'dXdx', ErrStat2, ErrMsg2 ) + CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + IF (ErrStat >= AbortErrLev) RETURN + END IF + dXdx = 0.0_R8Ki + END IF + CALL CD_CopyContState( x, m%x_perturb, MESH_UPDATECOPY, ErrStat2, ErrMsg2 ) + CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + IF (ErrStat >= AbortErrLev) RETURN + CALL CD_VarsPackContState( Vars, x, m%Jac%x ) + DO i = 1, SIZE(Vars%x) + DO j = 1, Vars%x(i)%Num + iCol = Vars%x(i)%iLoc(1) + j - 1 + CALL MV_Perturb( Vars%x(i), j, 1, m%Jac%x, m%Jac%x_perturb ) + CALL CD_VarsUnpackContState( Vars, m%Jac%x_perturb, m%x_perturb ) + CALL lin_eval( m%CDInst, p, m, u, m%x_perturb, ErrStat2, ErrMsg2, dxdt=m%dxdt_lin, y_out=m%y_lin ) + CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + IF (ErrStat >= AbortErrLev) RETURN + CALL CD_VarsPackOutput( Vars, m%y_lin, m%Jac%y_pos ) + CALL CD_VarsPackContStateDeriv( Vars, m%dxdt_lin, m%Jac%x_pos ) + CALL MV_Perturb( Vars%x(i), j, -1, m%Jac%x, m%Jac%x_perturb ) + CALL CD_VarsUnpackContState( Vars, m%Jac%x_perturb, m%x_perturb ) + CALL lin_eval( m%CDInst, p, m, u, m%x_perturb, ErrStat2, ErrMsg2, dxdt=m%dxdt_lin, y_out=m%y_lin ) + CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + IF (ErrStat >= AbortErrLev) RETURN + CALL CD_VarsPackOutput( Vars, m%y_lin, m%Jac%y_neg ) + CALL CD_VarsPackContStateDeriv( Vars, m%dxdt_lin, m%Jac%x_neg ) + IF (PRESENT(dYdx)) CALL MV_ComputeCentralDiff( Vars%y, Vars%x(i)%Perturb, m%Jac%y_pos, m%Jac%y_neg, & + dYdx(:, iCol) ) + IF (PRESENT(dXdx)) dXdx(:, iCol) = (m%Jac%x_pos - m%Jac%x_neg)/(2.0_R8Ki*Vars%x(i)%Perturb) + END DO + END DO + IF (PRESENT(dXddx)) THEN + IF (ALLOCATED(dXddx)) DEALLOCATE (dXddx) + END IF + IF (PRESENT(dZdx)) THEN + IF (ALLOCATED(dZdx)) DEALLOCATE (dZdx) + END IF + RETURN + END IF ! Under linearization the module registers ZERO state variables (the MAP-shaped ! dYdu-only reduction; see CD_InitVars), so every state Jacobian is an empty ! block. A state-registered instance (Nx > 0) has no x' = f(x, u) surface to @@ -3210,25 +3563,138 @@ SUBROUTINE CD_InitVars(Vars, u, p, x, y, m, inst_, Linearize, ErrStat, ErrMsg) CHARACTER(LinChanLen), ALLOCATABLE :: CblLinVel(:), CblLinPos(:), CblLinAcc(:) character(20), parameter :: TransDispSuffix(*) = [' Px, m', ' Py, m', ' Pz, m'] character(20), parameter :: TransVelSuffix(*) = [' Vx, m/s', ' Vy, m/s', ' Vz, m/s'] + ! a finite-EI cable node's tangent m = dr/ds and its rate (linearization states) + character(20), parameter :: TangentSuffix(*) = [' Tx, -', ' Ty, -', ' Tz, -'] + character(20), parameter :: TangentRateSuffix(*) = [' dTx, 1/s', ' dTy, 1/s', ' dTz, 1/s'] + ! central-difference steps of the linearization states. Positions, tangents and the + ! coupled-point displacements take 1 um (a tangent step moves an element by about its + ! length times the step): far inside the seabed penetration of a light cable (a few + ! tenths of a millimetre) and any element's slack, either of which a millimetre step + ! would cross on one side of the difference, and still some ten digits above round-off. + ! The velocity step is MoorDyn-F's 0.1 m/s: quadratic drag has no slope at rest, so the + ! difference over +-0.1 m/s is the drag's equivalent linear damping at that velocity + ! amplitude (a smaller step leaves the line modes all but undamped); a cable's tangent + ! rate takes the same amplitude over its mean element length. + REAL(R8Ki), PARAMETER :: LIN_DX = 1.0E-6_R8Ki, LIN_DV = 0.1_R8Ki + REAL(R8Ki), PARAMETER :: LIN_DT = 1.0E-6_R8Ki + INTEGER(IntKi) :: ipass, nnc, inode, ikind, i0, nrun, icomp, k + ! the position step of the line states and the coupled-point displacement step of the + ! inputs under linearization (lin_disp_step), and a cable's tangent-rate step + REAL(R8Ki) :: dx_pos, dx_u, dtr ErrStat = ErrID_None ErrMsg = '' + dx_u = 0.05_R8Ki + IF (Linearize) THEN + dx_u = LIN_DX + CALL lin_disp_step( inst_, dx_u, ErrStat2, ErrMsg2 ) + CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) + IF (ErrStat >= AbortErrLev) RETURN + END IF + dx_pos = dx_u IF (Linearize) THEN - ! Linearization presents the module in the MAP shape: ZERO continuous-state - ! variables. The module marches implicitly (generalised-alpha behind - ! UpdateStates), so there is no x' = f(x, u) surface to expose, and the glue - ! force-flags every registered x variable into the linearization set. With - ! Nx = 0 the linearized mooring is the direct-feedthrough impedance dYdu -- - ! stiffness from the displacement columns, damping from the velocity columns, - ! inertia from the acceleration columns: the quasi-static reduction MAP - ! exposes, and what a FOWT linearization consumes from a mooring. The - ! checkpoint and state-copy machinery is UNAFFECTED: pack_state_mirror and - ! the registry state copies use x%states directly, never Vars%x. + ! Linearization with the line dynamics, as MoorDyn-F: the continuous states are the + ! positions of every EI = 0 line's interior nodes and of every finite-EI cable's free + ! DOFs (node positions r and tangents m = dr/ds), then their velocities, held in the + ! x%states mirror slots (lin_state_map). The acceleration and the other mirror blocks + ! are not registered: the glue would take every registered x as a state. ALLOCATE (Vars%x(0), STAT=ErrStat2) IF (ErrStat2 /= 0) THEN CALL SetErrStat( ErrID_Fatal, 'Could not allocate Vars%x.', ErrStat, ErrMsg, RoutineName ); RETURN END IF + DO ipass = 1, 2 ! the positions, then the velocities + DO il = 1, inst_%nlines + ndofl = CD_System_Line_NDOF( inst_%agg%sys%fast%system, il, es, em ) + IF (es /= CD_SYSTEM_OK) THEN + CALL SetErrStat( ErrID_Fatal, TRIM(em), ErrStat, ErrMsg, RoutineName ); RETURN + END IF + N = ndofl/3 - 1 + DO i = 0, N - 2 + LinStr = 'Line '//TRIM(Num2LStr(il))//' node '//TRIM(Num2LStr(i + 1)) + IF (ipass == 1) THEN + CALL MV_AddVar( Vars%x, LinStr, FieldTransDisp, DatLoc(CD_x_states), & + iAry=m%LineStateIs1(il) + 3*(N - 1) + 3*i, Num=3, Flags=VF_DerivOrder2, & + Perturb=dx_pos, LinNames=[(TRIM(LinStr)//TransDispSuffix(j), j=1, 3)] ) + ELSE + CALL MV_AddVar( Vars%x, LinStr, FieldTransVel, DatLoc(CD_x_states), & + iAry=m%LineStateIs1(il) + 3*i, Num=3, Flags=VF_DerivOrder2, & + Perturb=LIN_DV, LinNames=[(TRIM(LinStr)//TransVelSuffix(j), j=1, 3)] ) + END IF + END DO + END DO + koff = 0 + IF (inst_%nlines > 0) koff = m%LineStateIsN(inst_%nlines) + DO ic = 1, inst_%agg%ncable + csz = CD_HFMF_MirrorSize( inst_%agg%cables(ic) ) + IF (csz <= 0) CYCLE + nf = COUNT(inst_%agg%cables(ic)%line%freemask) + ndofl = inst_%agg%cables(ic)%line%ndof + nnc = inst_%agg%cables(ic)%line%nn + dtr = LIN_DV*REAL(inst_%agg%cables(ic)%line%ne, R8Ki)/REAL(SUM(inst_%agg%cables(ic)%line%l0), R8Ki) + k = 0 + i = 1 + DO WHILE (i <= ndofl) + IF (.NOT. inst_%agg%cables(ic)%line%freemask(i)) THEN + i = i + 1 + CYCLE + END IF + ! a run of free DOFs of one node and one kind: the position r (DOFs 1-3 of the + ! node) or the tangent m (4-6); the node is named End A first, as the channels + inode = (i - 1)/6 + 1 + ikind = MERGE(1, 2, MOD(i - 1, 6) < 3) + i0 = i + DO WHILE (i <= ndofl) + IF (.NOT. inst_%agg%cables(ic)%line%freemask(i)) EXIT + IF ((i - 1)/6 + 1 /= inode .OR. MERGE(1, 2, MOD(i - 1, 6) < 3) /= ikind) EXIT + i = i + 1 + END DO + nrun = i - i0 + LinStr = 'Cable '//TRIM(Num2LStr(ic))//' node '//TRIM(Num2LStr(nnc + 1 - inode)) + ALLOCATE (CblLinPos(nrun), STAT=ErrStat2) + IF (ErrStat2 /= 0) THEN + CALL SetErrStat( ErrID_Fatal, 'Could not allocate cable lin-name work array.', & + ErrStat, ErrMsg, RoutineName ); RETURN + END IF + DO j = 1, nrun + icomp = MOD(i0 + j - 2, 3) + 1 + IF (ikind == 1 .AND. ipass == 1) THEN + CblLinPos(j) = TRIM(LinStr)//TransDispSuffix(icomp) + ELSE IF (ikind == 1) THEN + CblLinPos(j) = TRIM(LinStr)//TransVelSuffix(icomp) + ELSE IF (ipass == 1) THEN + CblLinPos(j) = TRIM(LinStr)//TangentSuffix(icomp) + ELSE + CblLinPos(j) = TRIM(LinStr)//TangentRateSuffix(icomp) + END IF + END DO + IF (ipass == 1) THEN + IF (ikind == 1 .AND. nrun == 3) THEN + CALL MV_AddVar( Vars%x, LinStr, FieldTransDisp, DatLoc(CD_x_states), & + iAry=koff + nf + k + 1, Num=nrun, Flags=VF_DerivOrder2, & + Perturb=dx_pos, LinNames=CblLinPos ) + ELSE + CALL MV_AddVar( Vars%x, LinStr, FieldScalar, DatLoc(CD_x_states), & + iAry=koff + nf + k + 1, Num=nrun, Flags=VF_DerivOrder2, DerivOrder=0, & + Perturb=MERGE(dx_pos, LIN_DT, ikind == 1), LinNames=CblLinPos ) + END IF + ELSE + IF (ikind == 1 .AND. nrun == 3) THEN + CALL MV_AddVar( Vars%x, LinStr, FieldTransVel, DatLoc(CD_x_states), & + iAry=koff + k + 1, Num=nrun, Flags=VF_DerivOrder2, & + Perturb=LIN_DV, LinNames=CblLinPos ) + ELSE + CALL MV_AddVar( Vars%x, LinStr, FieldScalar, DatLoc(CD_x_states), & + iAry=koff + k + 1, Num=nrun, Flags=VF_DerivOrder2, DerivOrder=1, & + Perturb=MERGE(LIN_DV, dtr, ikind == 1), LinNames=CblLinPos ) + END IF + END IF + DEALLOCATE (CblLinPos) + k = k + nrun + END DO + koff = koff + csz + END DO + END DO ELSE ! position states (interior line nodes; the mirror layout stores [rd, r] per @@ -3609,7 +4075,7 @@ SUBROUTINE CD_InitVars(Vars, u, p, x, y, m, inst_, Linearize, ErrStat, ErrMsg) CALL MV_AddMeshVar( Vars%u, "CoupledKinematics", MotionFields, & DatLoc(CD_u_CoupledKinematics, ivT), & Mesh=u%CoupledKinematics(ivT), & - Perturbs=[0.05_R8Ki, & ! FieldTransDisp + Perturbs=[dx_u, & ! FieldTransDisp 0.1_R8Ki, & ! FieldOrientation 0.1_R8Ki, & ! FieldTransVel 0.1_R8Ki, & ! FieldAngularVel diff --git a/validation/scripts/openfast_lin_ab.py b/validation/scripts/openfast_lin_ab.py index c8c72970..bb98b2e8 100644 --- a/validation/scripts/openfast_lin_ab.py +++ b/validation/scripts/openfast_lin_ab.py @@ -20,12 +20,15 @@ so the dynamic-relaxation initial state is settled, and no `SeaState WaterKin` row (no effect in still water). +Both modules linearize with the line dynamics: the continuous states are the +line nodes' positions and velocities (882 on this deck, in the same layout), and +the zero-frequency stiffness is the reduction K = D - C A^-1 B of each. + WHAT IS GATED 1. CableDyn invariants of a tangent mooring stiffness at equilibrium, on its - quasi-static dYdu (force rows vs translation-displacement columns, matched - by ROW/COLUMN LABELS): symmetry, negative (restoring) displacement - diagonals, and no net sway force under a collective surge of this - y-symmetric spread. + K (force rows vs translation-displacement columns, matched by ROW/COLUMN + LABELS): symmetry, negative (restoring) displacement diagonals, and no net + sway force under a collective surge of this y-symmetric spread. 2. The reference itself: MoorDyn's zero-frequency reduction K_md = D - C A^-1 B must be symmetric (<= 1e-3) and its .lin matrices must carry >= 10 significant digits; otherwise the comparison is refused @@ -39,9 +42,28 @@ operating-point fairlead loads): diagonals within --gate-pct, every entry within --gate-pct of sqrt(K_ii K_jj). Measured on this model (OutFmt ES24.15E3, TmaxIC 400 s, t = 0): the - dominant fairlead entries agree to 0.07-0.10 %, the small transverse - (H/X) entry to 0.29 %, the 6x6 diagonals to <= 0.10 % and every 6x6 - entry to 1.0e-3 of sqrt(K_ii K_jj) or better. + fairlead entries agree to 0.10 % (the small transverse entry to 0.29 %), + the 6x6 diagonals to <= 0.10 % and every 6x6 entry to 1.1e-3 of + sqrt(K_ii K_jj) or better. + 4. The dynamics: both state matrices stable (every eigenvalue in the left + half-plane), and the lowest --n-modes line-mode frequencies of CableDyn's + A within --freq-pct (default 1 %) of MoorDyn's. Measured: 0.04-0.07 % on + the first three modes, 0.3 % on the ninth (CableDyn's consistent mass + against MoorDyn's lumped mass). The damping ratios are printed, not gated: the + quadratic drag has no slope at rest, so both codes difference it over the + same +-0.1 m/s velocity step, and CableDyn's drag, integrated over the + element rather than lumped at the node, gives half the slope for a one-node + perturbation. + 5. With --cable-deck and --driver (optional): every coupled point of a mixed + deck (EI = 0 lines and finite-EI cables) against the deck's own static + solution. The deck is linearized in the same OpenFAST case (seabed + friction off: a stuck laid run is a different static problem), and the + standalone driver solves it at TMax = 0 with one coupled point moved + +-h (--cable-h, default 0.05 m) along each axis; -dF/dx of those solves is + the reference. Per-point 3x3 entries >= 10 % of the block's largest within + --cable-pct (default 1 %), every entry >= 1 % of it within twice that. + Measured on examples/iea15mw_umaine_mixed_cabledyn.dat: the lazy-wave + cable's 36.0 / 2.62 / 38.5 N/m within 3.3e-4, the chains within 7e-5. The 6x6 is the module-level stiffness. A full-system ElastoDyn linearization additionally contains a term of ElastoDyn/glue origin proportional to the @@ -66,6 +88,8 @@ [--ref-cd IEA-15-UMaine_CompMooring5_CableDyn.fst] [--ref-md IEA-15-UMaine_CompMooring3_MoorDyn.fst] [--t-lin 0.0] [--gate-pct 0.5] [--outfmt ES24.15E3] [--md-tmaxic 400] + [--n-modes 9] [--freq-pct 1.0] + [--cable-deck --driver [--cable-h 0.05] [--cable-pct 1.0]] [--skip-run] """ @@ -306,27 +330,147 @@ def op_values(labels: list[str], idx: list[int]) -> np.ndarray: def static_impedance(mod: dict) -> np.ndarray: """K = D - C A^+ B (reduces to D when the module carries no states). - A^+ is the pseudo-inverse when A is numerically singular: a lumped-mass - mooring on a FRICTIONLESS seabed can have neutral horizontal modes on its - grounded nodes (zero restoring force). The minimum-norm solution projects the - neutral modes out -- they stay put under a static boundary displacement, which - is exactly the quasi-static physics. On the settled UMaine deck with full - precision A is regular (the seabed penalty and line tension restrain every - node) and the plain solve is used.""" + A^+ is the pseudo-inverse only when A is singular to working precision (cond > + 1e14): a mooring on a FRICTIONLESS seabed can have neutral horizontal modes on + its grounded nodes (zero restoring force). The minimum-norm solution projects + the neutral modes out -- they stay put under a static boundary displacement, + which is exactly the quasi-static physics. A merely ill-conditioned A is solved + plainly: the soft lateral modes of a long laid cable are physical, and + truncating them corrupts every subsystem's reduction. On the settled UMaine + deck A is regular (the seabed penalty and line tension restrain every node).""" if mod["n_x"] == 0: return mod["D"] A = mod["A"] sv = np.linalg.svd(A, compute_uv=False) cond = sv[0] / max(sv[-1], 1e-300) - print(f"MD state matrix: {A.shape[0]} states, cond ~ {cond:.2e}") - if cond > 1e10: + print(f"state matrix: {A.shape[0]} states, cond ~ {cond:.2e}") + if cond > 1e14: print("note: neutral modes; using the pseudo-inverse zero-frequency reduction") - X = np.linalg.lstsq(A, mod["B"], rcond=1e-8)[0] + X = np.linalg.lstsq(A, mod["B"], rcond=1e-12)[0] else: X = np.linalg.solve(A, mod["B"]) return mod["D"] - mod["C"] @ X +def line_modes(A: np.ndarray) -> tuple[np.ndarray, np.ndarray, float]: + """Natural frequencies (Hz) and damping ratios of the oscillatory modes of a + state matrix, ascending in frequency, and its largest eigenvalue real part.""" + ev = np.linalg.eigvals(A) + osc = ev[ev.imag > 1e-9 * max(np.abs(ev).max(), 1.0)] + wn = np.abs(osc) + order = np.argsort(wn) + return wn[order] / (2.0 * np.pi), -osc.real[order] / wn[order], float(ev.real.max()) + + +def deck_points(deck: Path) -> list[tuple[int, str, list[float], int]]: + """(id, type, xyz, line index) of every row of a deck's POINTS section.""" + out = [] + in_points = False + for k, ln in enumerate(deck.read_text().splitlines()): + if ln.lstrip().startswith("-"): + in_points = "POINTS" in ln.upper() + continue + tok = ln.split() + if in_points and len(tok) >= 5 and tok[0].isdigit(): + out.append((int(tok[0]), tok[1].lower(), [float(v) for v in tok[2:5]], k)) + return out + + +def driver_point_loads(driver: Path, deck: Path, work: Path, pid: int, xyz: list[float], + coupled: list[int]) -> np.ndarray: + """The static loads Point

F{x,y,z} on every coupled point with point pid moved + to xyz: the deck solved by the standalone driver at TMax = 0.""" + lines = deck.read_text().splitlines() + row = {p[0]: p[3] for p in deck_points(deck)}[pid] + tok = lines[row].split() + lines[row] = " ".join(tok[:2] + [f"{v:.10f}" for v in xyz] + tok[5:]) + out: list[str] = [] + in_outputs = False + for ln in lines: + up = ln.strip().upper() + if ln.lstrip().startswith("-") and "OUTPUTS" in up: + in_outputs = True + out.append(ln) + out.extend(f'"Point{p}F{c}"' for p in coupled for c in "xyz") + continue + if in_outputs: + if up.startswith("END"): + in_outputs = False + out.append(ln) + continue + if re.match(r"^\s*\S+\s+TMax\b", ln): + ln = re.sub(r"^\s*\S+", "0.0", ln, count=1) + out.append(ln) + work.mkdir(parents=True, exist_ok=True) + (work / "trial.dat").write_text("\n".join(out) + "\n") + proc = subprocess.run([str(driver), "trial.dat", "trial"], cwd=work, capture_output=True, + text=True, timeout=3600) + if proc.returncode != 0: + tail = "\n".join((proc.stdout + proc.stderr).splitlines()[-15:]) + die(f"driver failed on {deck.name} with point {pid} at {xyz}:\n{tail}") + rows = [r for r in (work / "trial.out").read_text().splitlines() if r.strip() and not r.startswith("#")] + head = rows[0].split() + vals = [float(v) for v in rows[1].split()] + return np.array([[vals[head.index(f"Point{p}F{c}")] for c in "xyz"] for p in coupled]) + + +def cable_gate(args: argparse.Namespace, case: Path, cd_fst: Path) -> list[str]: + """Gate 5: a mixed deck's coupled-point stiffness against its static solution.""" + src = args.cable_deck.resolve() + if not src.is_file(): + die(f"cable deck not found: {src}") + if not args.driver.is_file(): + die(f"driver not found: {args.driver}") + deck = case / "CableDyn_cable_lin.dat" + text, n_mu = re.subn(r"^(\s*)\S+(\s+frictionMu\b)", r"\1none\2", src.read_text(), flags=re.M) + deck.write_text(text) + fst = case / "Main_lin_cable.fst" + fst_text = cd_fst.read_text() + name = file_entry(fst_text, "MooringFile", cd_fst.name) + fst.write_text(fst_text.replace(f'"{name}"', f'"{deck.name}"')) + if not args.skip_run: + print(f"running {fst.name} ...") + run_case(args.exe, fst) + mod = parse_module_lin(case / "Main_lin_cable.1.CD.lin") + kb, _ = block(mod, -static_impedance(mod), ["force"], ["translation displacement"], + "cable-deck stiffness") + pts = [p for p in deck_points(deck) if p[1] in ("coupled", "vessel", "cpld", "ves")] + ids = [p[0] for p in pts] + if kb.shape != (3 * len(ids), 3 * len(ids)): + die(f"cable-deck stiffness block {kb.shape} does not match {len(ids)} coupled points") + h = args.cable_h + tol = args.cable_pct / 100.0 + worst_dom = worst_all = 0.0 + print(f"cable deck {src.name} (frictionMu rows set to none: {n_mu}), coupled points {ids}, " + f"static reference from +-{h} m driver solves; K lin / K static / rel. diff (N/m):") + for ip, (pid, _, xyz, _) in enumerate(pts): + kref = np.zeros((3, 3)) + for k in range(3): + xp, xm = list(xyz), list(xyz) + xp[k] += h + xm[k] -= h + fp = driver_point_loads(args.driver, deck, case / "cable_lin_work", pid, xp, ids) + fm = driver_point_loads(args.driver, deck, case / "cable_lin_work", pid, xm, ids) + kref[:, k] = -(fp[ip] - fm[ip]) / (2.0 * h) + b = kb[3 * ip:3 * ip + 3, 3 * ip:3 * ip + 3] + big = np.abs(kref).max() + for i in range(3): + cells = [] + for j in range(3): + rel = (b[i, j] - kref[i, j]) / kref[i, j] if abs(kref[i, j]) > 1e-2 * big else 0.0 + if abs(kref[i, j]) >= 0.1 * big: + worst_dom = max(worst_dom, abs(rel)) + if abs(kref[i, j]) >= 1e-2 * big: + worst_all = max(worst_all, abs(rel)) + cells.append(f"{b[i, j]:11.5g} / {kref[i, j]:11.5g} / {rel:+.2e}") + print(f" point {pid} {'xyz'[i]}: " + " | ".join(cells)) + print(f"cable deck: dominant entries max rel. diff {worst_dom:.2e} (gate {tol:.1e}); " + f"all entries >= 1% of block max {worst_all:.2e} (gate {2 * tol:.1e})") + if worst_dom > tol or worst_all > 2 * tol: + return ["the cable deck's linearized point stiffness differs from its static solution"] + return [] + + def block(mod: dict, K: np.ndarray, row_must: list[str], col_must: list[str], what: str) -> tuple: rows = match_indices(mod["y_labels"], row_must) cols = match_indices(mod["u_labels"], col_must) @@ -372,8 +516,20 @@ def main() -> None: help="OutFmt written into both decks; the .lin matrices use it") ap.add_argument("--md-tmaxic", type=float, default=400.0, help="MoorDyn dynamic-relaxation time TmaxIC (s)") + ap.add_argument("--n-modes", type=int, default=9, + help="lowest line modes whose frequencies are gated") + ap.add_argument("--freq-pct", type=float, default=1.0, + help="CableDyn vs MoorDyn line-mode frequency tolerance in %%") + ap.add_argument("--cable-deck", type=Path, + help="a mixed EI = 0 + finite-EI deck for gate 5 (needs --driver)") + ap.add_argument("--driver", type=Path, help="the standalone CableDyn driver (gate 5)") + ap.add_argument("--cable-h", type=float, default=0.05, + help="coupled-point displacement of the gate-5 static solves (m)") + ap.add_argument("--cable-pct", type=float, default=1.0, help="gate-5 tolerance in %%") ap.add_argument("--skip-run", action="store_true") args = ap.parse_args() + if (args.cable_deck is None) != (args.driver is None): + die("--cable-deck and --driver go together") case = args.case_dir cd_fst = case / "Main_lin_cd5.fst" @@ -390,9 +546,9 @@ def main() -> None: md = parse_module_lin(case / "Main_lin_md3.1.MD.lin") print(f"CD: n_x={cd['n_x']} n_u={len(cd['u_labels'])} n_y={len(cd['y_labels'])}") print(f"MD: n_x={md['n_x']} n_u={len(md['u_labels'])} n_y={len(md['y_labels'])}") - if cd["n_x"] != 0: - die("CableDyn module reported continuous states under linearization " - "(the dYdu-only reduction must register Nx = 0)") + if cd["n_x"] == 0: + die("CableDyn module reported no continuous states under linearization " + "(the line positions and velocities must be states)") r_cd = coupled_points(cd_fst) r_md = coupled_points(md_fst) @@ -484,6 +640,27 @@ def main() -> None: if np.abs(rel_d).max() > tol or norm.max() > tol: failures.append("platform 6x6 stiffness differs from MoorDyn beyond the gate") + # 4. The dynamics: stability and the lowest line-mode frequencies. + f_cd, z_cd, re_cd = line_modes(cd["A"]) + f_md, z_md, re_md = line_modes(md["A"]) + nm = args.n_modes + if len(f_cd) < nm or len(f_md) < nm: + die(f"fewer than {nm} oscillatory modes (CD {len(f_cd)}, MD {len(f_md)})") + rel_f = f_cd[:nm] / f_md[:nm] - 1.0 + print(f"state matrices: max Re(lambda) CD {re_cd:.3e}, MD {re_md:.3e} (gate < 0)") + print(f"lowest {nm} line modes, f [Hz] CD / MD / rel. diff, damping ratio CD / MD (not gated):") + for i in range(nm): + print(f" {i + 1:2d} {f_cd[i]:.6f} / {f_md[i]:.6f} / {rel_f[i]:+.2e} {z_cd[i]:.4f} / {z_md[i]:.4f}") + print(f"line modes: max |rel. diff| {np.abs(rel_f).max():.2e} (gate {args.freq_pct / 100.0:.1e})") + if not (re_cd < 0.0 and re_md < 0.0): + failures.append("a state matrix has an eigenvalue in the right half-plane") + if np.abs(rel_f).max() > args.freq_pct / 100.0: + failures.append("the line-mode frequencies differ from MoorDyn beyond the gate") + + # 5. Optional: a mixed deck's coupled points against its own static solution. + if args.cable_deck is not None: + failures += cable_gate(args, case, cd_fst) + if failures: die("; ".join(failures)) print("PASS") From 3a7eb208d2b3ad7315030b31def9c0576f5cc622 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Thu, 29 Oct 2026 16:53:36 +0900 Subject: [PATCH 2/3] refactor(openfast): drop the quasi-static linearisation path Every Linearize call now takes the line-state branch of the input Jacobian, dXdu included only when the glue asks for it (a deck without line states has none), so quasistatic_dydu and its scratch-aggregate re-solves are unreachable and removed. Outside a linearisation run the input Jacobian is the runtime fixed-state derivative for any state count, and dXdu or a state Jacobian fails with a named message. The module comments no longer describe the zero-state reduction. Signed-off-by: Jae Hoon Seo --- src/openfast/CableDyn_OF.f90 | 293 +++++++---------------------------- 1 file changed, 57 insertions(+), 236 deletions(-) diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index 36216744..a9886605 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -59,8 +59,8 @@ MODULE CableDyn !! bodies, rods, Point3 buoys, torsion, CONTROL and rigid cable ends fail closed), and !! FAST.Farm farm-level moorings (FarmSize > 0: Turbine decks, !! per-turbine coupled meshes, shared lines; still-water hydro; farm restart and - !! farm linearization fail closed with named messages). Checkpoint restart and - !! linearization re-parse a temporary copy of the deck, written next to the + !! farm linearization fail closed with named messages). Checkpoint restart re-parses a + !! temporary copy of the deck, written next to the !! MooringFile (so its side files resolve as in the original run) and removed after !! use. !! @@ -573,16 +573,9 @@ SUBROUTINE CD_Init(InitInp, u, p, x, xd, z, other, y, m, DTcoupling, InitOut, Er 'not supported (linearize single-turbine cases).', ErrStat, ErrMsg, RoutineName ) RETURN END IF - ! Linearize is accepted for the established force-only boundary: the module presents - ! the MAP-shaped reduction -- ZERO - ! continuous-state variables (CD_InitVars) and a QUASI-STATIC dYdu whose - ! displacement columns come from scratch-aggregate static re-solves at the - ! perturbed boundary (each init IS a static solve), so the linearized mooring - ! is the re-equilibrated stiffness, not the frozen-interior response - ! (CD_JacobianPInput). Velocity/acceleration/orientation columns are zero: - ! frequency-dependent mooring damping is not representable without states. A - ! platform-relative cable end connection is rejected after deck construction below, - ! because it introduces orientation-dependent force and moment columns. + ! Linearize registers the line states (CD_InitVars, lin_state_map) and differentiates the + ! line dynamics (lin_eval); the objects whose states are not linearization states are + ! rejected after deck construction below. IF (.NOT. InitInp%UsePrimaryInputFile) THEN CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: passed-in primary input data is not '// & 'supported; provide the MoorDyn-format deck as a file.', ErrStat, ErrMsg, RoutineName ) @@ -3090,21 +3083,23 @@ SUBROUTINE CD_JacobianPInput(Vars, t, u, p, x, xd, z, OtherState, y, m, ErrStat, ! Get OP values here (the FD reference point) CALL CD_CalcOutput( t, u, p, x, xd, z, OtherState, y, m, ErrStat2, ErrMsg2 ); IF (Failed()) RETURN - ! Linearization with the line dynamics (the glue asks for dXdu with dYdu; the runtime - ! input/output solve asks for dYdu alone): the partial derivatives at the fixed state x, - ! by central differences of lin_eval, as MoorDyn-F's of its CalcOutput and - ! CalcContStateDeriv. - IF (Inst(m%CDInst)%lin_states .AND. PRESENT(dXdu)) THEN + ! Linearization with the line dynamics: the partial derivatives at the fixed state x, by + ! central differences of lin_eval, as MoorDyn-F's of its CalcOutput and + ! CalcContStateDeriv (dXdu only when the glue asks for it: a deck without line states + ! has none). + IF (Inst(m%CDInst)%lin_states) THEN IF (PRESENT(dYdu)) THEN IF (.NOT. ALLOCATED(dYdu)) THEN CALL AllocAry( dYdu, m%Jac%Ny, m%Jac%Nu, 'dYdu', ErrStat2, ErrMsg2 ); IF (Failed()) RETURN END IF dYdu = 0.0_R8Ki END IF - IF (.NOT. ALLOCATED(dXdu)) THEN - CALL AllocAry( dXdu, m%Jac%Nx, m%Jac%Nu, 'dXdu', ErrStat2, ErrMsg2 ); IF (Failed()) RETURN + IF (PRESENT(dXdu)) THEN + IF (.NOT. ALLOCATED(dXdu)) THEN + CALL AllocAry( dXdu, m%Jac%Nx, m%Jac%Nu, 'dXdu', ErrStat2, ErrMsg2 ); IF (Failed()) RETURN + END IF + dXdu = 0.0_R8Ki END IF - dXdu = 0.0_R8Ki CALL CD_CopyInput( u, m%u_perturb, MESH_UPDATECOPY, ErrStat2, ErrMsg2 ); IF (Failed()) RETURN CALL CD_VarsPackInput( Vars, u, m%Jac%u ) DO i = 1, SIZE(Vars%u) @@ -3124,7 +3119,7 @@ SUBROUTINE CD_JacobianPInput(Vars, t, u, p, x, xd, z, OtherState, y, m, ErrStat, CALL CD_VarsPackContStateDeriv( Vars, m%dxdt_lin, m%Jac%x_neg ) IF (PRESENT(dYdu)) CALL MV_ComputeCentralDiff( Vars%y, Vars%u(i)%Perturb, m%Jac%y_pos, m%Jac%y_neg, & dYdu(:, iCol) ) - dXdu(:, iCol) = (m%Jac%x_pos - m%Jac%x_neg)/(2.0_R8Ki*Vars%u(i)%Perturb) + IF (PRESENT(dXdu)) dXdu(:, iCol) = (m%Jac%x_pos - m%Jac%x_neg)/(2.0_R8Ki*Vars%u(i)%Perturb) END DO END DO ! the outputs at the operating point again (the glue reads y after this call) @@ -3138,73 +3133,52 @@ SUBROUTINE CD_JacobianPInput(Vars, t, u, p, x, xd, z, OtherState, y, m, ErrStat, RETURN END IF - ! dY/du has TWO distinct contracts. During a normal nonlinear OpenFAST run the - ! registered CableDyn states exist (Nx > 0), and the glue input/output solve needs - ! the PARTIAL derivative g_u at fixed internal state. Re-equilibrating the line for - ! those probes returns a total quasi-static derivative instead; inserting that into - ! the runtime algebraic loop can make its Jacobian rank deficient. For formal - ! linearization CableDyn deliberately registers no states (Nx = 0), so the useful - ! reduction is the re-equilibrated, zero-frequency stiffness. Keep those paths - ! explicit rather than using the linearization reduction in the runtime solve. + ! The runtime input/output solve of a nonlinear run: the PARTIAL derivative g_u at the + ! fixed internal state, as stock MoorDyn's runtime Jacobian. Perturb the current input, + ! evaluate CalcOutput with the same x/xd/z/other, and central-difference the packed + ! outputs; CD_CalcOutput's probe overlay restores the authoritative CableDyn state after + ! every evaluation. (Re-equilibrating the line for these probes would give a total + ! quasi-static derivative instead, which can make the runtime Jacobian rank deficient.) IF (PRESENT(dYdu)) THEN IF (.NOT. ALLOCATED(dYdu)) THEN CALL AllocAry( dYdu, m%Jac%Ny, m%Jac%Nu, 'dYdu', ErrStat2, ErrMsg2 ); IF (Failed()) RETURN END IF dYdu = 0.0_R8Ki - IF (m%Jac%Nx > 0) THEN - ! Match stock MoorDyn's runtime Jacobian contract: perturb the current input, - ! evaluate CalcOutput with the same x/xd/z/other, and central-difference the - ! packed outputs. CD_CalcOutput's probe overlay restores the authoritative - ! CableDyn state after every evaluation. - CALL CD_CopyInput( u, m%u_perturb, MESH_UPDATECOPY, ErrStat2, ErrMsg2 ); IF (Failed()) RETURN - CALL CD_VarsPackInput( Vars, u, m%Jac%u ) - DO i = 1, SIZE(Vars%u) - DO j = 1, Vars%u(i)%Num - iCol = Vars%u(i)%iLoc(1) + j - 1 - CALL MV_Perturb( Vars%u(i), j, 1, m%Jac%u, m%Jac%u_perturb ) - CALL CD_VarsUnpackInput( Vars, m%Jac%u_perturb, m%u_perturb ) - CALL CD_CalcOutput( t, m%u_perturb, p, x, xd, z, OtherState, m%y_lin, m, ErrStat2, ErrMsg2 ) - IF (Failed()) RETURN - CALL CD_VarsPackOutput( Vars, m%y_lin, m%Jac%y_pos ) - - CALL MV_Perturb( Vars%u(i), j, -1, m%Jac%u, m%Jac%u_perturb ) - CALL CD_VarsUnpackInput( Vars, m%Jac%u_perturb, m%u_perturb ) - CALL CD_CalcOutput( t, m%u_perturb, p, x, xd, z, OtherState, m%y_lin, m, ErrStat2, ErrMsg2 ) - IF (Failed()) RETURN - CALL CD_VarsPackOutput( Vars, m%y_lin, m%Jac%y_neg ) - - CALL MV_ComputeCentralDiff( Vars%y, Vars%u(i)%Perturb, m%Jac%y_pos, m%Jac%y_neg, & - dYdu(:, iCol) ) - END DO + CALL CD_CopyInput( u, m%u_perturb, MESH_UPDATECOPY, ErrStat2, ErrMsg2 ); IF (Failed()) RETURN + CALL CD_VarsPackInput( Vars, u, m%Jac%u ) + DO i = 1, SIZE(Vars%u) + DO j = 1, Vars%u(i)%Num + iCol = Vars%u(i)%iLoc(1) + j - 1 + CALL MV_Perturb( Vars%u(i), j, 1, m%Jac%u, m%Jac%u_perturb ) + CALL CD_VarsUnpackInput( Vars, m%Jac%u_perturb, m%u_perturb ) + CALL CD_CalcOutput( t, m%u_perturb, p, x, xd, z, OtherState, m%y_lin, m, ErrStat2, ErrMsg2 ) + IF (Failed()) RETURN + CALL CD_VarsPackOutput( Vars, m%y_lin, m%Jac%y_pos ) + + CALL MV_Perturb( Vars%u(i), j, -1, m%Jac%u, m%Jac%u_perturb ) + CALL CD_VarsUnpackInput( Vars, m%Jac%u_perturb, m%u_perturb ) + CALL CD_CalcOutput( t, m%u_perturb, p, x, xd, z, OtherState, m%y_lin, m, ErrStat2, ErrMsg2 ) + IF (Failed()) RETURN + CALL CD_VarsPackOutput( Vars, m%y_lin, m%Jac%y_neg ) + + CALL MV_ComputeCentralDiff( Vars%y, Vars%u(i)%Perturb, m%Jac%y_pos, m%Jac%y_neg, & + dYdu(:, iCol) ) END DO - ! The final negative probe leaves only output/cache workspaces at the - ! perturbed input (the authoritative structural state was already restored). - ! Re-evaluate the operating point so the callback is observationally neutral - ! to the next glue evaluation as well as state neutral. - CALL CD_CalcOutput( t, u, p, x, xd, z, OtherState, y, m, ErrStat2, ErrMsg2 ) - IF (Failed()) RETURN - ELSE - ! Zero-state formal linearization: each displacement probe re-solves static - ! equilibrium on a scratch aggregate, giving the reduced mooring stiffness. - CALL quasistatic_dydu( Vars, u, p, m, dYdu, ErrStat2, ErrMsg2 ); IF (Failed()) RETURN - END IF + END DO + ! The final negative probe leaves only output/cache workspaces at the perturbed + ! input (the authoritative structural state was already restored). Re-evaluate the + ! operating point so the callback is observationally neutral to the next glue + ! evaluation as well as state neutral. + CALL CD_CalcOutput( t, u, p, x, xd, z, OtherState, y, m, ErrStat2, ErrMsg2 ) + IF (Failed()) RETURN END IF - ! dX/du: the implicit march has no x' = f(x, u) surface. Under linearization the - ! module registers ZERO state variables (see CD_InitVars), so the honest dXdu is - ! the empty (0 x Nu) block; a caller holding a state-registered instance (Nx > 0) - ! is asking for a surface that does not exist -- fail loudly, never zero-fill. + ! dX/du of the implicit march exists only for a linearization run (the line-state + ! branch above): fail loudly, never zero-fill. IF (PRESENT(dXdu)) THEN - IF (m%Jac%Nx > 0) THEN - CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: dXdu is undefined for the implicit '// & - 'march with registered state variables; linearization must be requested at '// & - 'Init so the module presents its zero-state (dYdu-only) reduction.', & - ErrStat, ErrMsg, RoutineName ) - RETURN - END IF - IF (.NOT. ALLOCATED(dXdu)) THEN - CALL AllocAry( dXdu, m%Jac%Nx, m%Jac%Nu, 'dXdu', ErrStat2, ErrMsg2 ); IF (Failed()) RETURN - END IF + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: dXdu exists only for a linearization '// & + 'run (Linearize = True).', ErrStat, ErrMsg, RoutineName ) + RETURN END IF IF (PRESENT(dXddu)) THEN @@ -3221,155 +3195,6 @@ LOGICAL FUNCTION Failed() END FUNCTION Failed END SUBROUTINE CD_JacobianPInput -!---------------------------------------------------------------------------------------------------------------------------------- - SUBROUTINE quasistatic_dydu( Vars, u, p, m, dYdu, ErrStat, ErrMsg ) - !! The quasi-static dYdu displacement columns: for each coupled-mesh - !! FieldTransDisp perturbation, re-solve the mooring static equilibrium at the - !! perturbed boundary on a SCRATCH aggregate built from the deck copy (each - !! CD_AGG_Init_From_Deck IS a static solve; coupled_positions places the moving - !! points explicitly), read the loads and deck channels, and central-difference. - !! The live instance is never touched -- the probe cannot perturb committed - !! state by construction. All other input fields keep zero columns. - TYPE(ModVarsType), INTENT(IN ) :: Vars - TYPE(CD_InputType), INTENT(IN ) :: u - TYPE(CD_ParameterType), INTENT(IN ) :: p - TYPE(CD_MiscVarType), INTENT(INOUT) :: m - REAL(R8Ki), INTENT(INOUT) :: dYdu(:,:) - INTEGER(IntKi), INTENT( OUT) :: ErrStat - CHARACTER(*), INTENT( OUT) :: ErrMsg - - character(*), parameter :: RoutineName = 'quasistatic_dydu' - INTEGER(IntKi) :: ErrStat2, es, i, j, iCol, node, comp, ncp, k - CHARACTER(ErrMsgLen) :: ErrMsg2 - CHARACTER(2100) :: lin_deck - REAL(wp), ALLOCATABLE :: op_pos(:,:), prb_pos(:,:) - LOGICAL :: use_extf - REAL(wp), ALLOCATABLE :: static_cur(:,:) ! the host's steady current for the static probes - - ErrStat = ErrID_None - ErrMsg = '' - IF (p%DeckCopy%NumLines < 1) THEN - CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: the linearization probe needs the '// & - 'deck copy in the parameters.', ErrStat, ErrMsg, RoutineName ) - RETURN - END IF - ncp = u%CoupledKinematics(1)%Nnodes - ALLOCATE (op_pos(3, ncp), prb_pos(3, ncp), STAT=ErrStat2) - IF (ErrStat2 /= 0) THEN - CALL SetErrStat( ErrID_Fatal, 'Could not allocate the linearization probe positions.', & - ErrStat, ErrMsg, RoutineName ) - RETURN - END IF - ! the operating-point boundary: the committed mesh positions at the snapshot - DO i = 1, ncp - op_pos(:, i) = REAL(u%CoupledKinematics(1)%Position(:, i), wp) + & - REAL(u%CoupledKinematics(1)%TranslationDisp(:, i), wp) - END DO - - ! the deck copy back to disk once (beside the MooringFile, so its side files - ! resolve); every probe init reuses it and it is removed afterwards - CALL write_deck_copy( p, '.lin.dat', lin_deck, ErrStat2, ErrMsg2 ) - CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) - IF (ErrStat >= AbortErrLev) RETURN - - use_extf = .FALSE. - IF (ASSOCIATED(p%WaveField)) use_extf = wavefield_is_ambient( p%WaveField ) - ! each probe is a static solve in the host's steady current, as the operating point is - IF (use_extf) THEN - CALL seastate_static_current( p%WaveField, static_cur, ErrStat2, ErrMsg2 ) - CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) - IF (ErrStat >= AbortErrLev) RETURN - END IF - - DO i = 1, SIZE(Vars%u) - IF (Vars%u(i)%Field /= FieldTransDisp) CYCLE ! vel/acc/orientation: zero columns - DO j = 1, Vars%u(i)%Num - iCol = Vars%u(i)%iLoc(1) + j - 1 - node = (j - 1)/3 + 1 - comp = MOD(j - 1, 3) + 1 - IF (node > ncp) THEN - CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: linearization probe node index '// & - 'exceeds the coupled mesh.', ErrStat, ErrMsg, RoutineName ) - CALL delete_file( lin_deck ) - RETURN - END IF - DO k = 1, 2 ! +perturb then -perturb - prb_pos = op_pos - IF (k == 1) THEN - prb_pos(comp, node) = prb_pos(comp, node) + REAL(Vars%u(i)%Perturb, wp) - ELSE - prb_pos(comp, node) = prb_pos(comp, node) - REAL(Vars%u(i)%Perturb, wp) - END IF - CALL probe_loads( prb_pos, ErrStat2, ErrMsg2 ) - CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) - IF (ErrStat >= AbortErrLev) THEN - CALL delete_file( lin_deck ) - RETURN - END IF - IF (k == 1) THEN - CALL CD_VarsPackOutput( Vars, m%y_lin, m%Jac%y_pos ) - ELSE - CALL CD_VarsPackOutput( Vars, m%y_lin, m%Jac%y_neg ) - END IF - END DO - CALL MV_ComputeCentralDiff( Vars%y, Vars%u(i)%Perturb, m%Jac%y_pos, m%Jac%y_neg, dYdu(:, iCol) ) - END DO - END DO - CALL delete_file( lin_deck ) - - CONTAINS - - SUBROUTINE probe_loads( pos, PErrStat, PErrMsg ) - !! One static probe: scratch-aggregate init at the given boundary (the init - !! IS the static solve), loads + deck channels into m%y_lin, then release. - REAL(wp), INTENT(IN ) :: pos(:,:) - INTEGER(IntKi), INTENT( OUT) :: PErrStat - CHARACTER(*), INTENT( OUT) :: PErrMsg - - TYPE(CD_AGG_ModuleType) :: agg_p - REAL(wp) :: q_p(3, ncp), v_p(3, ncp), a_p(3, ncp), f_p(3, ncp) - REAL(wp) :: cval - INTEGER(IntKi) :: es_p, ich - CHARACTER(ErrMsgLen) :: em_p - - PErrStat = ErrID_None - PErrMsg = '' - CALL CD_AGG_Init_From_Deck( agg_p, TRIM(lin_deck), REAL(p%dtM0, wp), es_p, em_p, & - env_gravity=REAL(p%g, wp), env_rho_water=REAL(p%rhoW, wp), & - env_wtrdpth=REAL(p%WtrDpth, wp), external_fluid=use_extf, & - coupled_positions=pos, run_tmax=REAL(p%Tmax, wp), & - static_current=static_cur ) - IF (es_p /= CD_AGG_OK) THEN - PErrStat = ErrID_Fatal - PErrMsg = 'linearization static probe init failed: '//TRIM(em_p) - RETURN - END IF - CALL CD_AGG_CalcOutput( agg_p, es_p, em_p ) - IF (es_p == CD_AGG_OK) CALL CD_AGG_GetMovingPointMesh( agg_p, q_p, v_p, a_p, f_p, es_p, em_p ) - IF (es_p /= CD_AGG_OK) THEN - CALL CD_AGG_End( agg_p, es_p, em_p ) - PErrStat = ErrID_Fatal - PErrMsg = 'linearization static probe output failed: '//TRIM(em_p) - RETURN - END IF - DO ich = 1, ncp - m%y_lin%CoupledLoads(1)%Force(:, ich) = REAL(f_p(:, ich), ReKi) - m%y_lin%CoupledLoads(1)%Moment(:, ich) = 0.0_ReKi - END DO - DO ich = 1, p%NumOuts - CALL CD_AGG_EvalChannel( agg_p, ich, cval, es_p, em_p ) - IF (es_p /= CD_AGG_OK) THEN - CALL CD_AGG_End( agg_p, es_p, em_p ) - PErrStat = ErrID_Fatal - PErrMsg = 'linearization static probe channel failed: '//TRIM(em_p) - RETURN - END IF - m%y_lin%WriteOutput(ich) = REAL(cval, ReKi) - END DO - CALL CD_AGG_End( agg_p, es_p, em_p ) - END SUBROUTINE probe_loads - - END SUBROUTINE quasistatic_dydu !---------------------------------------------------------------------------------------------------------------------------------- SUBROUTINE CD_JacobianPContState(Vars, t, u, p, x, xd, z, OtherState, y, m, ErrStat, ErrMsg, dYdx, dXdx, dXddx, dZdx) @@ -3452,15 +3277,11 @@ SUBROUTINE CD_JacobianPContState(Vars, t, u, p, x, xd, z, OtherState, y, m, ErrS END IF RETURN END IF - ! Under linearization the module registers ZERO state variables (the MAP-shaped - ! dYdu-only reduction; see CD_InitVars), so every state Jacobian is an empty - ! block. A state-registered instance (Nx > 0) has no x' = f(x, u) surface to - ! differentiate -- fail loudly rather than fabricate one. + ! Outside a linearization run the implicit march has no x' = f(x, u) surface to + ! differentiate: fail loudly rather than fabricate one. IF (m%Jac%Nx > 0) THEN - CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: state Jacobians are undefined for the '// & - 'implicit march with registered state variables; linearization must be '// & - 'requested at Init so the module presents its zero-state (dYdu-only) '// & - 'reduction.', ErrStat, ErrMsg, RoutineName ) + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: state Jacobians exist only for a '// & + 'linearization run (Linearize = True).', ErrStat, ErrMsg, RoutineName ) RETURN END IF IF (PRESENT(dYdx)) THEN From b5e1b2074475b873026d75cb189313d91c9045cc Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Thu, 29 Oct 2026 17:34:14 +0900 Subject: [PATCH 3/3] fix(openfast): linearise the rope models' constitutive states The viscoelastic slow-branch stretch dl_1 and the Syrope slow strain are dynamic states with their own rate laws, but the linearisation held them, so D - C A^-1 B gave these ropes' instantaneous stiffness instead of their relaxed static one. They are now first-order linearisation states (VF_DerivOrder1, "Line l segment e dl1, m" / "slow strain, -"): lin_eval loads them from x and writes their rates, which the new CD_Get_Model_Internal_Rates evaluates with the instantaneous element laws (the taut series-Kelvin ODE or the slack zero-load relaxation; the Syrope kernel at dt = 0). A viscoelastic variant of the UMaine chains (150 stretches) now matches its static solutions to 7e-5 (held: 0.6 % too stiff); a taut three-leg Syrope spread with a SYROPE IC history (60 slow strains) to 6e-6 (held: 2.9 times too stiff). The Syrope running maximum and the seabed-friction stick anchors stay held: load histories, whose operating-point values are the small-motion tangent. A line or cable with VIV fails closed: it oscillates about a lock-in cycle, not an equilibrium. The A/B script's static reference adds TMax = 0 to a deck that leaves TMax to the host. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 9 +- VALIDATION.md | 9 +- doc/openfast.rst | 20 ++-- doc/troubleshooting.rst | 7 +- src/CableDyn_Model.f90 | 77 ++++++++++++++ src/CableDyn_System.f90 | 29 ++++- src/openfast/CableDyn_OF.f90 | 147 ++++++++++++++++++++++++-- validation/scripts/openfast_lin_ab.py | 4 + 8 files changed, 279 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 736ef117..2622d9a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,9 +17,12 @@ All notable changes to CableDyn are recorded in this file. The format follows perturbed state. On the UMaine chains the stiffness `D - C A^-1 B` matches MoorDyn-F's to 0.1 % and the lowest nine line-mode frequencies to 0.3 %; with a lazy-wave power cable every coupled point matches the deck's own static solutions to 3e-4, also with a hang-off spring. A cable - end connection with a numeric stiffness now linearises. Free/Connect points, a `Rigid` cable - end connection, bodies, rods, buoys, torsion and `CONTROL` fail closed with named messages. - This replaces the quasi-static linearisation without states. + end connection with a numeric stiffness now linearises. The viscoelastic slow-branch stretch + and the Syrope slow strain are first-order states, so the reduction gives these ropes' relaxed + static stiffness (each matches its deck's static solutions to 7e-5; held, they would read the + chain 0.6 % and the polyester 2.9 times too stiff). Free/Connect points, a `Rigid` cable end + connection, VIV lines, bodies, rods, buoys, torsion and `CONTROL` fail closed with named + messages. This replaces the quasi-static linearisation without states. - Section-frame curvature channels `CurvXN` and `CurvYN` on finite-EI lines: the curvature vector on the cable's cross-section axes, for the fatigue of an armour wire or conductor at a fixed point of the section. The axes start at End A from the end connection diff --git a/VALIDATION.md b/VALIDATION.md index 89918c32..6f4db7d2 100644 --- a/VALIDATION.md +++ b/VALIDATION.md @@ -390,7 +390,14 @@ scripts, results, and source provenance are in Two step sizes had to be small. A millimetre position step lifted the cable's grounded nodes out of their 0.3 mm seabed penetration on one side of the difference, and a 5 cm coupled-point step slackened the chain's last element. Each halved a stiffness (the cable's sway stiffness read 242 - instead of 2.6 N/m). States and inputs now take 1 µm. Both 50-segment models sit 7–12% above the continuous elastic catenary + instead of 2.6 N/m). States and inputs now take 1 µm. The rope models' constitutive states are + first-order states, checked the same way against each deck's static solutions. A viscoelastic + variant of the UMaine chains (`EA 3.27e9|6.54e9`, 150 slow-branch stretches) matches to 7e-5; + held, the stretches would read the chain 0.6 % too stiff. A taut three-leg Syrope polyester + spread with a `SYROPE IC` history (60 slow strains) matches to 6e-6, where held slow strains + would read it 2.9 times too stiff. With every element on one segment of the working-curve + table, the single-secant static start is exact; legs straddling a table kink differ by 2 %, + because that static start takes one secant for the whole line. Both 50-segment models sit 7–12% above the continuous elastic catenary because of the touchdown discretisation; refining to 800 segments converges to it within 0.1%. MoorDyn's reduction needs the full-precision `OutFmt`. With the usual `ES10.3E2` (4 digits), `D ≈ 1e8 N/m` cancels to a ~1e4 N/m result and the block is 57% asymmetric with sign-flipped diff --git a/doc/openfast.rst b/doc/openfast.rst index 05bc6a89..abfe73cc 100644 --- a/doc/openfast.rst +++ b/doc/openfast.rst @@ -441,15 +441,21 @@ The zero-frequency reduction ``D − C A⁻¹ B`` is the static mooring stiffnes MoorDyn-F and with CableDyn's own static solutions (:doc:`validation`). Quadratic drag has no slope at rest, so the 0.1 m/s step gives its equivalent linear damping at that velocity amplitude. CableDyn integrates the drag over the element, and a one-node step then gives about half of -MoorDyn-F's lumped value. The internal states of viscoelastic, Syrope and VIV models and the -seabed-friction anchors are held at their operating-point values: the linearisation sees the rope's -instantaneous stiffness and a stuck laid run. Linearise from a settled operating point, such as the -still-water start at ``t = 0``. +MoorDyn-F's lumped value. + +The constitutive states of the rope models are first-order states, named ``Line 1 segment 3 dl1, +m`` and ``Line 1 segment 3 slow strain, -`` (elements counted from End B, as the nodes): each +viscoelastic element's slow-branch stretch and each Syrope element's slow strain, differentiated +through their own laws. ``D − C A⁻¹ B`` then gives the relaxed static stiffness of these ropes, +not their instantaneous one. Two load histories are held at their operating-point values: the +Syrope running maximum (small motions below it stay on its working curve) and the seabed-friction +stick anchors (a stuck laid run). Linearise from a settled operating point, such as the still-water +start at ``t = 0``. Initialisation fails with a named message for Free and Connect points, Point3 buoys, Rigid6 bodies -and rods, a line restrained in torsion, a ``CONTROL`` section, a cable with a ``Rigid`` end -connection, and FAST.Farm. These carry states that are not linearisation states. Time-domain runs -support all of them. +and rods, a line restrained in torsion, a line with VIV (``Cl > 0``: it oscillates about a lock-in +cycle, not an equilibrium), a ``CONTROL`` section, a cable with a ``Rigid`` end connection, and +FAST.Farm. Their states are not linearisation states. Time-domain runs support all of them. Performance ----------- diff --git a/doc/troubleshooting.rst b/doc/troubleshooting.rst index 8842c028..5125a222 100644 --- a/doc/troubleshooting.rst +++ b/doc/troubleshooting.rst @@ -848,10 +848,11 @@ aborts with a CableDyn fatal error, check whether the deck uses one of these com combinations in :doc:`capabilities` * - OpenFAST linearisation of a cable with a ``Rigid`` ``END CONNECTIONS`` row (``formal OpenFAST linearization of a cable with a rigid end connection is not supported``), of a deck - with ``Free`` or ``Connect`` points, or with a ``CONTROL`` section + with ``Free`` or ``Connect`` points or a line with VIV (``Cl > 0``), or with a ``CONTROL`` + section - linearise a variant with a numeric rotational stiffness at the hang-off, the lines attached to - ``Fixed`` or ``Coupled`` points, and no ``CONTROL`` section; time-domain runs support all of - them + ``Fixed`` or ``Coupled`` points, ``Cl = 0`` and no ``CONTROL`` section; time-domain runs + support all of them * - a ``Rigid`` end-connection direction reversed by exactly 180 degrees in one host update - drive the platform through intermediate orientations * - VIV on a finite-EI line with two moving ends (``needs its End B fixed``) diff --git a/src/CableDyn_Model.f90 b/src/CableDyn_Model.f90 index 3c864f75..90d7b613 100644 --- a/src/CableDyn_Model.f90 +++ b/src/CableDyn_Model.f90 @@ -98,6 +98,7 @@ MODULE CableDyn_Model PUBLIC :: CD_Latch_Model_VIV_Window PUBLIC :: CD_Get_Model_VIV_State, CD_Set_Model_VIV_State, CD_Model_Has_VIV, CD_Get_Model_VIV_Lift PUBLIC :: CD_Get_Model_Tension + PUBLIC :: CD_Get_Model_Internal_Rates PUBLIC :: CD_Get_Model_EndForces PUBLIC :: CD_Get_Model_EndNodeMassDiag PUBLIC :: CD_Get_Model_EndNodeAddedMass @@ -5577,6 +5578,82 @@ SUBROUTINE CD_Get_Model_Tension(model, tension, ErrStat, ErrMsg) CALL model_law_tensions(model, tension, ErrStat, ErrMsg) END SUBROUTINE CD_Get_Model_Tension + SUBROUTINE CD_Get_Model_Internal_Rates(model, ve_rate, syrope_rate, ErrStat, ErrMsg) + !! The rates of the per-element constitutive states at the model's current q, v and states, + !! as the instantaneous (dt = 0) element loads evaluate them: the viscoelastic slow-branch + !! stretch d(dl_1)/dt (its taut ODE, or the zero-load relaxation of a slack element) and the + !! Syrope slow strain d(eps_slow)/dt; zero on the other elements. + TYPE(CD_ModelType), INTENT(IN) :: model + REAL(wp), INTENT(OUT) :: ve_rate(:), syrope_rate(:) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + + INTEGER :: e, idx(6), es + REAL(wp) :: q2(6), v2(6), chord(3), tang(3), length, lstrd, dl, bsum, ld1, ea_d_eff, ea_1_eff + REAL(wp) :: ws(CD_SYROPE_NWC), wt(CD_SYROPE_NWC), wsl(CD_SYROPE_NWC), f6(6), jq6(6, 6), t_mean, dslow + REAL(wp) :: slow_at + CHARACTER(200) :: em + + ve_rate = CD_ZERO + syrope_rate = CD_ZERO + ErrStat = CD_MODEL_OK + ErrMsg = '' + IF (.NOT. model%initialized) THEN + ErrStat = CD_MODEL_NOT_INITIALIZED + ErrMsg = 'CableDyn_Model: model is not initialized' + RETURN + END IF + IF (SIZE(ve_rate) /= model%n_elem .OR. SIZE(syrope_rate) /= model%n_elem) THEN + CALL fail(ErrStat, ErrMsg, 'internal-rate outputs must have shape (n_elem)') + RETURN + END IF + IF (model%has_viscoelastic) THEN + DO e = 1, model%n_elem + IF (model%ve_mode(e) == 0) CYCLE + CALL model_viscoelastic_coeffs(model, e, ea_d_eff, ea_1_eff, ErrStat, ErrMsg) + IF (ErrStat /= CD_MODEL_OK) RETURN + CALL extract_element_state(model, e, model%q, model%v, idx, q2, v2) + chord = q2(4:6) - q2(1:3) + length = NORM2(chord) + IF (length <= CD_VISCO_TINY_LEN) THEN + CALL fail(ErrStat, ErrMsg, 'viscoelastic element collapsed to zero length') + RETURN + END IF + tang = chord/length + lstrd = DOT_PRODUCT(tang, v2(4:6) - v2(1:3)) + dl = length - model%l0(e) + bsum = model%ve_ba_d(e) + model%ve_ba(e) + ! the taut series-Kelvin ODE; a slack chain (tension max(MagT + MagTd, 0) = 0) + ! relaxes under zero load, BA*ld_1 + EA_1*dl_1 = 0, as the element load's switch + ld1 = (ea_d_eff*dl - (ea_d_eff + ea_1_eff)*model%ve_dl_1(e) + model%ve_ba_d(e)*lstrd)/bsum + IF (ea_1_eff*model%ve_dl_1(e)/model%l0(e) + model%ve_ba(e)*ld1/model%l0(e) < CD_ZERO) THEN + ld1 = CD_ZERO + IF (model%ve_ba(e) > CD_ZERO) ld1 = -ea_1_eff*model%ve_dl_1(e)/model%ve_ba(e) + END IF + ve_rate(e) = ld1 + END DO + END IF + IF (model%has_syrope) THEN + DO e = 1, model%n_elem + IF (.NOT. model%syrope_is(e)) CYCLE + CALL extract_element_state(model, e, model%q, model%v, idx, q2, v2) + CALL CD_Syrope_Working_Curve(model%syrope_type(e), model%syrope_tmax(e), ws, wt, wsl, es, em) + IF (es /= CD_SYROPE_OK) THEN + CALL fail(ErrStat, ErrMsg, TRIM(em)); RETURN + END IF + slow_at = CD_Syrope_Branch_Divider(model%syrope_type(e), model%syrope_tmax(e)) + CALL CD_Syrope_Element_Load(q2(1:3), q2(4:6), v2(1:3), v2(4:6), model%l0(e), model%syrope_type(e), & + ws, wt, wsl, model%syrope_slow(e) < slow_at, model%syrope_slow(e), & + model%tension_only, f6, jq6, t_mean, dslow, es, em, dt=CD_ZERO, & + divider=slow_at) + IF (es /= CD_SYROPE_OK) THEN + CALL fail(ErrStat, ErrMsg, TRIM(em)); RETURN + END IF + syrope_rate(e) = dslow + END DO + END IF + END SUBROUTINE CD_Get_Model_Internal_Rates + SUBROUTINE model_law_tensions(model, tension, ErrStat, ErrMsg) !! Overwrite the entries of the viscoelastic and Syrope elements of tension (n_elem) with !! their law's tension at the committed state (CD_Get_Model_Tension); the other entries diff --git a/src/CableDyn_System.f90 b/src/CableDyn_System.f90 index 2c9e9b3b..87760f8a 100644 --- a/src/CableDyn_System.f90 +++ b/src/CableDyn_System.f90 @@ -14,7 +14,7 @@ MODULE CableDyn_System USE CableDyn_Model, ONLY: CD_ModelType, CD_Model_Is_Initialized, CD_End_Model, & CD_Model_NCoupledDOF, CD_Model_NDOF, CD_Model_NElem, & CD_Get_Model_CoupledDofs, CD_Get_Model_CoupledMotion, & - CD_Get_Model_State, CD_Get_Model_Tension, & + CD_Get_Model_State, CD_Get_Model_Tension, CD_Get_Model_Internal_Rates, & CD_Model_Has_Viscoelastic, CD_Get_Model_VE_Dl1, CD_Set_Model_VE_Dl1, & CD_Model_Has_Syrope, CD_Get_Model_Syrope_State, CD_Set_Model_Syrope_State, & CD_Model_Has_VIV, CD_Get_Model_VIV_State, CD_Set_Model_VIV_State, CD_Get_Model_VIV_Lift, & @@ -86,6 +86,7 @@ MODULE CableDyn_System PUBLIC :: CD_Get_System_Line_State PUBLIC :: CD_Get_System_Line_Tension PUBLIC :: CD_Get_System_Line_Stretch + PUBLIC :: CD_Get_System_Line_Internal_Rates PUBLIC :: CD_Get_System_CoupledMotion PUBLIC :: CD_Update_System_CoupledMotion PUBLIC :: CD_Update_System_Point_States @@ -1177,6 +1178,32 @@ SUBROUTINE CD_Get_System_Line_Stretch(system, line_index, stretch, ErrStat, ErrM END ASSOCIATE END SUBROUTINE CD_Get_System_Line_Stretch + SUBROUTINE CD_Get_System_Line_Internal_Rates(system, line_index, ve_rate, syrope_rate, ErrStat, ErrMsg) + !! The per-element constitutive-state rates of one contained line at its current state + !! (CD_Get_Model_Internal_Rates). + TYPE(CD_SystemType), INTENT(IN) :: system + INTEGER, INTENT(IN) :: line_index + REAL(wp), INTENT(OUT) :: ve_rate(:), syrope_rate(:) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + + INTEGER :: es + CHARACTER(1024) :: em + + ve_rate = CD_ZERO + syrope_rate = CD_ZERO + CALL validate_line_index(system, line_index, ErrStat, ErrMsg) + IF (ErrStat /= CD_SYSTEM_OK) RETURN + CALL CD_Get_Model_Internal_Rates(system%lines(line_index), ve_rate, syrope_rate, es, em) + IF (es /= CD_MODEL_OK) THEN + ErrStat = CD_SYSTEM_SOLVEFAIL + ErrMsg = 'CableDyn_System: line internal-rate query failed: '//TRIM(em) + RETURN + END IF + ErrStat = CD_SYSTEM_OK + ErrMsg = '' + END SUBROUTINE CD_Get_System_Line_Internal_Rates + SUBROUTINE CD_Get_System_CoupledMotion(system, q_coupled, v_coupled, a_coupled, ErrStat, ErrMsg) !! Copy aggregate compact coupled motion, concatenated line by line. TYPE(CD_SystemType), INTENT(IN) :: system diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index a9886605..14916202 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -54,9 +54,10 @@ MODULE CableDyn !! deck + state mirror, accepted on committed mooring-interval boundaries), !! linearization with the line dynamics (as MoorDyn-F: the continuous states are the !! EI=0 lines' interior-node positions and the finite-EI cables' free DOFs, positions - !! and tangents, then their velocities; A, B, C and D by central differences of - !! lin_eval, the accelerations solved at the perturbed state; Free/Connect points, - !! bodies, rods, Point3 buoys, torsion, CONTROL and rigid cable ends fail closed), and + !! and tangents, then their velocities, and the rope models' constitutive states; A, B, C + !! and D by central differences of lin_eval, the accelerations and state rates evaluated + !! at the perturbed state; Free/Connect points, VIV lines, bodies, rods, Point3 buoys, + !! torsion, CONTROL and rigid cable ends fail closed), and !! FAST.Farm farm-level moorings (FarmSize > 0: Turbine decks, !! per-turbine coupled meshes, shared lines; still-water hydro; farm restart and !! farm linearization fail closed with named messages). Checkpoint restart re-parses a @@ -107,7 +108,7 @@ MODULE CableDyn USE CableDyn_LoadPredictor, ONLY: CD_Predictor_Ready, CD_Predictor_Fraction, CD_Predict_Loads USE CableDyn_Profile, ONLY: CD_Profile_Arm, CD_Profile_Disarm, CD_Profile_Kernels, CD_PROF_K_RESIDUAL, & CD_PROF_K_TANGENT, CD_PROF_K_FACTOR, CD_PROF_K_SOLVE, CD_PROF_NKERNEL - USE CableDyn_System, ONLY: CD_Get_System_Line_Stretch + USE CableDyn_System, ONLY: CD_Get_System_Line_Stretch, CD_Get_System_Line_Internal_Rates USE CableDyn_EndConnection, ONLY: CD_ENDCONN_RIGID USE CableDyn_System, ONLY: CD_System_NLines, CD_System_Line_NDOF, CD_System_Line_NElem, & CD_Get_System_DynamicPoint_States, CD_Set_System_DynamicPoint_States, & @@ -131,6 +132,9 @@ MODULE CableDyn PRIVATE + ! the kinds of first-order linearization state (lin_state_map) + INTEGER(IntKi), PARAMETER :: LIN1_VE = 1, LIN1_SYROPE = 2 + TYPE(ProgDesc), PARAMETER :: CableDyn_ProgDesc = ProgDesc( 'CableDyn', 'v0.3.0', '2026-10-23' ) INTERFACE ! 1 when the CableDyn core targets x86-64-v3 (CABLEDYN_TARGET_AVX2) and carries the @@ -202,6 +206,10 @@ END FUNCTION cd_cpu_guard_armed ! buffers of lin_eval LOGICAL :: lin_states = .FALSE. INTEGER(IntKi), ALLOCATABLE :: lin_pos(:), lin_vel(:), lin_acc(:) + ! the first-order linearization states, the per-element constitutive states of the + ! EI = 0 lines: mirror slot, line, element and kind (LIN1_VE: the viscoelastic slow-branch + ! stretch dl_1; LIN1_SYROPE: the Syrope slow strain) + INTEGER(IntKi), ALLOCATABLE :: lin1_slot(:), lin1_line(:), lin1_elem(:), lin1_kind(:) REAL(R8Ki), ALLOCATABLE :: ws_lsave(:), ws_lwork(:) ! FAST.Farm: turbine count (0 = plain single-turbine mode), the driving turbine ! per flat aggregate moving slot, that slot's node index within its turbine's @@ -805,6 +813,26 @@ SUBROUTINE CD_Init(InitInp, u, p, x, xd, z, other, y, m, DTcoupling, InitOut, Er ! A Free/Connect point steps with its own state through the implicit point-line coupling; ! the linearization states are the line and cable DOFs only, so the point would be held ! where it is and its compliance omitted. + ! A line with VIV oscillates about a lock-in limit cycle, not about an equilibrium, and its + ! shedding phase and running mean squares are not linearization states either. + IF (InitInp%Linearize) THEN + DO il = 1, Inst(id)%nlines + IF (CD_System_Line_VIV_MirrorSize( Inst(id)%agg%sys%fast%system, il ) > 0) THEN + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: formal OpenFAST linearization '// & + 'of a line with VIV (LINE TYPES Cl > 0) is not supported; set Cl = 0 to '// & + 'linearize.', ErrStat, ErrMsg, RoutineName ) + RETURN + END IF + END DO + DO ic = 1, Inst(id)%agg%ncable + IF (Inst(id)%agg%cables(ic)%line%has_viv) THEN + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: formal OpenFAST linearization '// & + 'of a cable with VIV (LINE TYPES Cl > 0) is not supported; set Cl = 0 to '// & + 'linearize.', ErrStat, ErrMsg, RoutineName ) + RETURN + END IF + END DO + END IF IF (InitInp%Linearize .AND. CD_AGG_NDynamicPoints( Inst(id)%agg ) > 0) THEN CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: formal OpenFAST linearization '// & 'with Free or Connect points is not supported; their states are not '// & @@ -2691,8 +2719,9 @@ SUBROUTINE lin_state_map( inst_e, m, ErrStat, ErrMsg ) TYPE(CD_MiscVarType), INTENT(IN) :: m INTEGER(IntKi), INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg - INTEGER(IntKi) :: il, ic, ndofl, nin, nf, csz, koff, n, k, j, es + INTEGER(IntKi) :: il, ic, ndofl, nin, nf, csz, koff, n, k, j, es, n1, k1, kind CHARACTER(ErrMsgLen) :: em + LOGICAL, ALLOCATABLE :: mask(:) ErrStat = ErrID_None ErrMsg = '' @@ -2708,6 +2737,34 @@ SUBROUTINE lin_state_map( inst_e, m, ErrStat, ErrMsg ) IF (CD_HFMF_MirrorSize( inst_e%agg%cables(ic) ) <= 0) CYCLE n = n + COUNT(inst_e%agg%cables(ic)%line%freemask) END DO + ! the constitutive states: every viscoelastic and Syrope element, the per-element tail + ! after the line's interior block (as pack_state_mirror) + n1 = 0 + DO il = 1, inst_e%nlines + n1 = n1 + COUNT(lin1_element(il, LIN1_VE)) + COUNT(lin1_element(il, LIN1_SYROPE)) + END DO + IF (ALLOCATED(inst_e%lin1_slot)) DEALLOCATE (inst_e%lin1_slot, inst_e%lin1_line, inst_e%lin1_elem, & + inst_e%lin1_kind) + ALLOCATE (inst_e%lin1_slot(n1), inst_e%lin1_line(n1), inst_e%lin1_elem(n1), inst_e%lin1_kind(n1), STAT=es) + IF (es /= 0) THEN + CALL SetErrStat( ErrID_Fatal, 'Could not allocate the linearization state map.', ErrStat, ErrMsg, & + 'lin_state_map' ); RETURN + END IF + k1 = 0 + DO il = 1, inst_e%nlines + nin = CD_System_Line_NDOF( inst_e%agg%sys%fast%system, il, es, em ) - 6 + DO kind = LIN1_VE, LIN1_SYROPE + mask = lin1_element(il, kind) + DO j = 1, SIZE(mask) + IF (.NOT. mask(j)) CYCLE + k1 = k1 + 1 + inst_e%lin1_slot(k1) = m%LineStateIs1(il) + 3*nin + j - 1 + inst_e%lin1_line(k1) = il + inst_e%lin1_elem(k1) = j + inst_e%lin1_kind(k1) = kind + END DO + END DO + END DO IF (ALLOCATED(inst_e%lin_pos)) DEALLOCATE (inst_e%lin_pos, inst_e%lin_vel, inst_e%lin_acc) IF (ALLOCATED(inst_e%ws_lsave)) DEALLOCATE (inst_e%ws_lsave, inst_e%ws_lwork) ALLOCATE (inst_e%lin_pos(n), inst_e%lin_vel(n), inst_e%lin_acc(n), inst_e%ws_lsave(m%Nx), & @@ -2744,8 +2801,31 @@ SUBROUTINE lin_state_map( inst_e, m, ErrStat, ErrMsg ) koff = koff + csz END DO inst_e%lin_states = .TRUE. + + CONTAINS + + FUNCTION lin1_element(il_, kind_) RESULT(msk) + !! The elements of line il_ carrying a constitutive state of kind kind_. + INTEGER(IntKi), INTENT(IN) :: il_, kind_ + LOGICAL, ALLOCATABLE :: msk(:) + msk = lin1_mask( inst_e, il_, kind_ ) + END FUNCTION lin1_element END SUBROUTINE lin_state_map + FUNCTION lin1_mask( inst_, il, kind ) RESULT(msk) + !! The elements of EI = 0 line il that carry a first-order linearization state of the kind: + !! viscoelastic (ElasticMod 2/3) elements for LIN1_VE, Syrope elements for LIN1_SYROPE. + TYPE(CD_OF_Instance), INTENT(IN) :: inst_ + INTEGER(IntKi), INTENT(IN) :: il, kind + LOGICAL, ALLOCATABLE :: msk(:) + ASSOCIATE (ln => inst_%agg%sys%fast%system%lines(il)) + ALLOCATE (msk(ln%n_elem)) + msk = .FALSE. + IF (kind == LIN1_VE .AND. ln%has_viscoelastic) msk = ln%ve_mode /= 0 + IF (kind == LIN1_SYROPE .AND. ln%has_syrope) msk = ln%syrope_is + END ASSOCIATE + END FUNCTION lin1_mask + SUBROUTINE lin_disp_step( inst_, dx, ErrStat, ErrMsg ) !! The coupled-point displacement step of the linearization, as MoorDyn-F's: half the !! smallest positive element stretch of the EI = 0 lines, at most dx on entry. A larger @@ -2796,7 +2876,8 @@ SUBROUTINE lin_eval( id, p, m, u, x_in, ErrStat, ErrMsg, dxdt, y_out ) TYPE(CD_OutputType), INTENT(INOUT), OPTIONAL :: y_out character(*), parameter :: RoutineName = 'CableDyn:lin_eval' - INTEGER(IntKi) :: ErrStat2, es, i, ic + INTEGER(IntKi) :: ErrStat2, es, i, ic, il, ne, k + REAL(wp), ALLOCATABLE :: ve_rate(:), syr_rate(:) CHARACTER(ErrMsgLen) :: ErrMsg2, em REAL(wp) :: cval, t_clock @@ -2818,6 +2899,7 @@ SUBROUTINE lin_eval( id, p, m, u, x_in, ErrStat, ErrMsg, dxdt, y_out ) Inst(id)%ws_lwork = Inst(id)%ws_lsave Inst(id)%ws_lwork(Inst(id)%lin_pos) = x_in%states(Inst(id)%lin_pos) Inst(id)%ws_lwork(Inst(id)%lin_vel) = x_in%states(Inst(id)%lin_vel) + Inst(id)%ws_lwork(Inst(id)%lin1_slot) = x_in%states(Inst(id)%lin1_slot) CALL reload_interiors_ary( Inst(id), m, Inst(id)%ws_lwork, t_clock, ErrStat2, ErrMsg2 ) CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) IF (ErrStat >= AbortErrLev) THEN @@ -2856,6 +2938,26 @@ SUBROUTINE lin_eval( id, p, m, u, x_in, ErrStat, ErrMsg, dxdt, y_out ) dxdt%states = 0.0_R8Ki dxdt%states(Inst(id)%lin_pos) = Inst(id)%ws_lwork(Inst(id)%lin_vel) dxdt%states(Inst(id)%lin_vel) = Inst(id)%ws_lwork(Inst(id)%lin_acc) + ! the constitutive states' rates at this state (the instantaneous element laws) + DO il = 1, Inst(id)%nlines + IF (.NOT. ANY(Inst(id)%lin1_line == il)) CYCLE + ne = CD_System_Line_NElem( Inst(id)%agg%sys%fast%system, il, es, em ) + ALLOCATE (ve_rate(ne), syr_rate(ne)) + CALL CD_Get_System_Line_Internal_Rates( Inst(id)%agg%sys%fast%system, il, ve_rate, syr_rate, es, em ) + IF (es /= CD_SYSTEM_OK) THEN + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: '//TRIM(em), ErrStat, ErrMsg, RoutineName ) + CALL restore; RETURN + END IF + DO k = 1, SIZE(Inst(id)%lin1_slot) + IF (Inst(id)%lin1_line(k) /= il) CYCLE + IF (Inst(id)%lin1_kind(k) == LIN1_VE) THEN + dxdt%states(Inst(id)%lin1_slot(k)) = REAL(ve_rate(Inst(id)%lin1_elem(k)), R8Ki) + ELSE + dxdt%states(Inst(id)%lin1_slot(k)) = REAL(syr_rate(Inst(id)%lin1_elem(k)), R8Ki) + END IF + END DO + DEALLOCATE (ve_rate, syr_rate) + END DO END IF IF (PRESENT(y_out)) THEN CALL CD_AGG_CalcOutput( Inst(id)%agg, es, em ) @@ -3398,6 +3500,11 @@ SUBROUTINE CD_InitVars(Vars, u, p, x, y, m, inst_, Linearize, ErrStat, ErrMsg) ! rate takes the same amplitude over its mean element length. REAL(R8Ki), PARAMETER :: LIN_DX = 1.0E-6_R8Ki, LIN_DV = 0.1_R8Ki REAL(R8Ki), PARAMETER :: LIN_DT = 1.0E-6_R8Ki + ! the constitutive states: a viscoelastic slow-branch stretch (m) takes the position step, + ! a Syrope slow strain the strain of a micrometre over a metre + REAL(R8Ki), PARAMETER :: LIN_DSLOW = 1.0E-6_R8Ki + LOGICAL, ALLOCATABLE :: lin1m(:) + INTEGER(IntKi) :: kind1 INTEGER(IntKi) :: ipass, nnc, inode, ikind, i0, nrun, icomp, k ! the position step of the line states and the coupled-point displacement step of the ! inputs under linearization (lin_disp_step), and a cable's tangent-rate step @@ -3418,8 +3525,9 @@ SUBROUTINE CD_InitVars(Vars, u, p, x, y, m, inst_, Linearize, ErrStat, ErrMsg) ! Linearization with the line dynamics, as MoorDyn-F: the continuous states are the ! positions of every EI = 0 line's interior nodes and of every finite-EI cable's free ! DOFs (node positions r and tangents m = dr/ds), then their velocities, held in the - ! x%states mirror slots (lin_state_map). The acceleration and the other mirror blocks - ! are not registered: the glue would take every registered x as a state. + ! x%states mirror slots (lin_state_map), and the per-element constitutive states of the + ! viscoelastic and Syrope ropes as first-order states. The acceleration and the other + ! mirror blocks are not registered: the glue would take every registered x as a state. ALLOCATE (Vars%x(0), STAT=ErrStat2) IF (ErrStat2 /= 0) THEN CALL SetErrStat( ErrID_Fatal, 'Could not allocate Vars%x.', ErrStat, ErrMsg, RoutineName ); RETURN @@ -3516,6 +3624,29 @@ SUBROUTINE CD_InitVars(Vars, u, p, x, y, m, inst_, Linearize, ErrStat, ErrMsg) koff = koff + csz END DO END DO + ! the per-element constitutive states of the EI = 0 lines, first-order states: the + ! viscoelastic slow-branch stretch dl_1 and the Syrope slow strain (the Syrope running + ! maximum is a load history, held as the operating point's) + DO il = 1, inst_%nlines + ndofl = CD_System_Line_NDOF( inst_%agg%sys%fast%system, il, es, em ) + nin = ndofl - 6 + DO kind1 = LIN1_VE, LIN1_SYROPE + lin1m = lin1_mask( inst_, il, kind1 ) + DO j = 1, SIZE(lin1m) + IF (.NOT. lin1m(j)) CYCLE + LinStr = 'Line '//TRIM(Num2LStr(il))//' segment '//TRIM(Num2LStr(j)) + IF (kind1 == LIN1_VE) THEN + CALL MV_AddVar( Vars%x, LinStr, FieldScalar, DatLoc(CD_x_states), & + iAry=m%LineStateIs1(il) + 3*nin + j - 1, Num=1, Flags=VF_DerivOrder1, & + Perturb=LIN_DX, LinNames=[TRIM(LinStr)//' dl1, m'] ) + ELSE + CALL MV_AddVar( Vars%x, LinStr, FieldScalar, DatLoc(CD_x_states), & + iAry=m%LineStateIs1(il) + 3*nin + j - 1, Num=1, Flags=VF_DerivOrder1, & + Perturb=LIN_DSLOW, LinNames=[TRIM(LinStr)//' slow strain, -'] ) + END IF + END DO + END DO + END DO ELSE ! position states (interior line nodes; the mirror layout stores [rd, r] per diff --git a/validation/scripts/openfast_lin_ab.py b/validation/scripts/openfast_lin_ab.py index bb98b2e8..82f41a69 100644 --- a/validation/scripts/openfast_lin_ab.py +++ b/validation/scripts/openfast_lin_ab.py @@ -386,9 +386,13 @@ def driver_point_loads(driver: Path, deck: Path, work: Path, pid: int, xyz: list lines[row] = " ".join(tok[:2] + [f"{v:.10f}" for v in xyz] + tok[5:]) out: list[str] = [] in_outputs = False + has_tmax = any(re.match(r"^\s*\S+\s+TMax\b", ln) for ln in lines) for ln in lines: up = ln.strip().upper() if ln.lstrip().startswith("-") and "OUTPUTS" in up: + if not has_tmax: + # a coupled deck leaves TMax to the host: the static start alone + out.append("0.0 TMax - Standalone duration (s); 0 solves the static start") in_outputs = True out.append(ln) out.extend(f'"Point{p}F{c}"' for p in coupled for c in "xyz")