From e854b207e30a5ac4b0fd67a25f58ff62e4bbe203 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Thu, 29 Oct 2026 20:30:17 +0900 Subject: [PATCH 1/4] feat(torsion): torsional inertia and damping, a twist angle at every node In the dynamics a finite-EI line restrained in torsion now carries a twist angle phi at every node, against reference directors that follow the node tangents by the smallest rotation over each step (time-parallel transport), so the axial angular velocity of a section is phi_dot. The statics stay condensed and set the angles from the uniform static torque. - Element twist phi_{e+1} - phi_e + beta_e - h_e: beta_e advances by the solid angles of the quadrilateral of committed and present tangents (CD_HermiteTwist_Reference, local to the element's 12 DOFs, with gradient and Hessian), so the turns live in the angles and no 2 pi branch is tracked. A rigid end takes its frame's normal carried to the node as the node's director and holds the angle; an elastic end adds its spring. - Torque M_e = (GJ/l0)(tw + (K/GJ) dl) + (Bt/l0) d/dt(...), with the polar inertia Irn (LINE TYPES column, now used) lumped at the nodes and the new torsional damping Bt of the GJ column (GJ|K|Bt, negative: -zeta of an element's critical l0 sqrt(GJ Irn)). - The angles join the generalised-alpha step; the step factors one band of [r, m, phi] per node (half-width 13). Their rows converge on the nodal torque balance, scaled by the nodal loads as the force rows are. The committed reference advances with the step's own solid angles, so the committed state reproduces the converged iterate bit for bit; the twist state joins the snapshot, the recovering step and the OpenFAST mirror. - TorqN is the node's torque (mean of its elements); end force, end moment, energy, element twist and section curvature read the nodal state. - Under torque-tension coupling each element's coupling force (K/GJ) M_e takes its own torque: in the dynamic tensile_safety audit (the converged evaluation's), the element recovery and the node tensions. Gates: the kernel against direct transports (1e-13) and FD; nodal_twist_dynamic: the condensed torsion in the limit of no inertia (<= 6e-7, clamped, bending-pinned, elastic ends), the continuum torsional wave (0.07 %), the damping decrement (6 %), energy band 4.9e-4, snapshot and mirror restart bit-identical; a zero-allocation step gate. The old quasi-static gates run at Irn 1e-9/1e-12; a non-stepping coupled write twists the end element against the frozen interior. Full suite passes; 52 of 53 examples bit-identical, the torsion example within 7e-5 of the torque. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 11 + CMakeLists.txt | 15 + VALIDATION.md | 30 +- doc/capabilities.rst | 12 +- doc/driver_format.md | 14 +- doc/outputs.rst | 16 +- doc/theory.rst | 77 +- python/cabledyn/builder.py | 12 +- python/cabledyn/deck_file.py | 18 +- python/tests/test_builder.py | 25 +- src/CableDyn_DeckDriver.f90 | 106 +- src/CableDyn_HermiteCableDynamic.f90 | 1458 +++++++++++++++++++++++++- src/CableDyn_HermiteTorsion.f90 | 282 +++++ src/CableDyn_OpenFAST_HermiteFMF.f90 | 43 +- tests/test_coupled_torsion.f90 | 22 +- tests/test_hermite_twist_kernel.f90 | 284 +++++ tests/test_nodal_twist_dynamic.f90 | 473 +++++++++ tests/test_step_allocations.f90 | 29 +- tests/test_torsion_coupling.f90 | 75 +- tests/test_torsion_deck.f90 | 9 +- 20 files changed, 2895 insertions(+), 116 deletions(-) create mode 100644 tests/test_hermite_twist_kernel.f90 create mode 100644 tests/test_nodal_twist_dynamic.f90 diff --git a/CHANGELOG.md b/CHANGELOG.md index 96b44608..57797afa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,17 @@ All notable changes to CableDyn are recorded in this file. The format follows and `SYROPE IC` applies to every Syrope section of the line. On a 400 m polyester section between chains every element starts on its OWC to 2e-11, and a still run keeps the fairlead tension. Example `composite_chain_syrope_chain.dat`, on a moving vessel. +- Torsional inertia and damping of finite-EI lines: in the dynamics a line restrained in torsion + carries a twist angle at every node, against directors that follow the node tangents by the + smallest rotation over each step, with the polar rotary inertia `Irn` of its LINE TYPES row and + the torsional damping `Bt` of a new third part of the `GJ` column (`GJ|K|Bt`, negative for a + damping ratio). The torque now varies along the line (`TorqN` is the node's) and + travels as a torsional wave; the statics stay condensed, and in the limit of a negligible + inertia the dynamics reproduce the condensed torsion. The step solves the angles with the + cable in one band of half-width 13; the twist state joins the snapshot, the recovering step + and the OpenFAST checkpoint mirror. Decks with torsion whose `Irn` was a placeholder (the + column was unused before) need the section's real value. The Python deck reader and builder + take `GJ|K|Bt` (builder `gj=(GJ, K, Bt)`). - Torque–tension coupling of finite-EI cables: the 14-column LINE TYPES row's `GJ` column takes `GJ|K`, with `K` the coupling of an armoured cable or wire rope (`T = EA ε + K τ`, `M = GJ τ + K ε`). The cable carries the axial stiffness `EA − K²/GJ` of a section free to twist. diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e19ea88..ad31d2c0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -632,6 +632,16 @@ add_test(NAME hermite_torsion_kernel COMMAND test_hermite_torsion_kernel ${CMAKE_CURRENT_SOURCE_DIR}/tests/data/torsion_oracle_reference.txt) set_tests_properties(hermite_torsion_kernel PROPERTIES LABELS "fortran;unit;static") +add_executable(test_hermite_twist_kernel tests/test_hermite_twist_kernel.f90) +target_link_libraries(test_hermite_twist_kernel PRIVATE cabledyn_core) +add_test(NAME hermite_twist_kernel COMMAND test_hermite_twist_kernel) +set_tests_properties(hermite_twist_kernel PROPERTIES LABELS "fortran;unit") + +add_executable(test_nodal_twist_dynamic tests/test_nodal_twist_dynamic.f90) +target_link_libraries(test_nodal_twist_dynamic PRIVATE cabledyn_core) +add_test(NAME nodal_twist_dynamic COMMAND test_nodal_twist_dynamic) +set_tests_properties(nodal_twist_dynamic PROPERTIES LABELS "fortran;unit;dynamic;openfast") + add_executable(test_hermite_torsion_static tests/test_hermite_torsion_static.f90) target_link_libraries(test_hermite_torsion_static PRIVATE cabledyn_core) add_test(NAME hermite_torsion_static @@ -1394,6 +1404,9 @@ if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_ID STREQUAL "GN # The same gate on a finite-EI cable with condensed torsion (a turning parent and a changing twist). add_test(NAME step_allocations_torsion COMMAND test_step_allocations torsion) set_tests_properties(step_allocations_torsion PROPERTIES LABELS "fortran;dynamic;memory") + # And with the nodal twist (polar inertia, torsional damping, the 7-DOF-per-node band). + add_test(NAME step_allocations_nodal_twist COMMAND test_step_allocations nodal) + set_tests_properties(step_allocations_nodal_twist PROPERTIES LABELS "fortran;dynamic;memory") endif() add_executable(test_snap_load tests/test_snap_load.f90) @@ -2789,6 +2802,8 @@ if(CABLEDYN_ENABLE_COVERAGE) test_line test_hermite_cable test_hermite_torsion_kernel + test_hermite_twist_kernel + test_nodal_twist_dynamic test_hermite_torsion_static test_hermite_torsion_dynamic test_hermite_cable_static diff --git a/VALIDATION.md b/VALIDATION.md index 530965a0..c1eb64a6 100644 --- a/VALIDATION.md +++ b/VALIDATION.md @@ -102,6 +102,7 @@ article's methods, are compared in | **T-8** | Cross-check with the Cosserat rod path | Cosserat path | shape 4.2e-4 L, torque 5.2e-5 | <1% | Pass | | **T-9** | Bordered Newton step on post-buckled states | predicted linear rate without the rank-one term | 3 iterations; rate 0.055 / 0.217 vs 0.055 / 0.218 | ≤4; within 25% | Pass | | **T-10** | Torsion dynamics, restart and body torque | quasi-static torque, energy, uninterrupted run, pendulum | torque 2.2e-16; energy band 4.9e-4; restart bit-identical; pendulum 6.4e-5 | see [Torsion](#torsion) | Pass | +| **T-13** | Nodal twist (torsional inertia and damping) | condensed torsion in the limit of no inertia; continuum torsional wave; `ζ = ω Bt/(2 GJ)`; energy; restart | ≤6e-7 against the condensed torsion; wave torque 0.07 %; decrement 6 %; energy band 4.9e-4; restart bit-identical | see [Torsion](#torsion) | Pass | | **T-12** | Torque–tension coupling | `T = EA ε + K τ`, `M = GJ τ + K ε` closed forms; kernel FD; march | ≤1e-7 against every closed form; kernel gradient 1.7e-10, Hessian 9.8e-11 | see [Torsion](#torsion) | Pass | | **T-11** | Torsion on the coupled OpenFAST / FAST.Farm route | `GJ (−roll)/L`; single coupled cable; uninterrupted run | twist ≤1.8e-15°, torque ≤1.7e-13 N·m; aggregate = single cable bit for bit; restart bit-identical (aggregate and `openfast -restart`) | see [Torsion](#torsion) | Pass | @@ -999,6 +1000,30 @@ in parentheses). A 20 s march that moves End A 0.1 m away and rolls it −90° ends on the static values of that state to 1e-7. `GJ|0` equals the uncoupled cable bit for bit, and `K² ≥ EA GJ` stops by name. +- **T-13 nodal twist** (`nodal_twist_dynamic`, `hermite_twist_kernel`). The reference twist of the + time-parallel-transported directors equals the direct composition of the smallest rotations + to 1e-13 (interior element, rigid End A, rigid End B, one element rigid at both ends, an + elastic end's spring), equals the fine transport along the element with the holonomy to + 1e-6, and has the gradient and Hessian of its finite differences. On the 10 m line + (EA 1e5 N, EI 100 N·m², GJ 80 N·m², 20 elements): + - with `Irn = 1e-9 kg·m` it reproduces the condensed torsion through 300 steps of sway, a + roll of more than a turn and an imposed twist, for clamped, bending-pinned and elastic + ends: centreline to 1.3e-10 m, mean torque 1.7e-12, node torques 5.9e-7, end force 9.9e-8 + and end moment 5.5e-7 relative; + - with `Irn = 0.5 kg·m`, rolled at half its first torsional frequency, the held end carries + the continuum torque `GJ A k/sin(kL)` to 0.07 %; + - with `Bt` for `ζ_1 = 0.05`, the first torsional mode rings down with the logarithmic + decrement 0.334 against 0.315 (6 %, the faster higher modes not yet gone); + - in free vibration at `ρ∞ = 1` the energy stays in a band of 4.9e-4 of the vibration energy + (3.8e-4 without torsion), and a run restored from a snapshot or rebuilt from the checkpoint + mirror continues bit-identically. + + The torsion gates of `torsion_deck`, `coupled_torsion` and `torsion_coupling` run in the + limit of a negligible polar inertia (`Irn = 1e-12` and `1e-9 kg·m`), whose closed forms they + check; at a direct non-stepping write of the coupled end, the end element alone takes the + roll (`GJ (−roll)/l_e`) against the frozen interior. The example + `torsion_lazy_wave_hangoff_twist.dat` (Irn of the section) moves by at most 7e-5 of the + torque against the condensed torsion. - **Backward compatibility and refusals** (`torsion_deck`, full suite). Without torsion columns, with `Free` columns (whatever their normal), or with one restrained end, every output is byte-identical to the 6-column deck, and `Rigid`, `Infinity`, `Inf` and a quoted `"Rigid"` @@ -1008,8 +1033,9 @@ in parentheses). (the C API) and a standalone mixed `EI = 0` + finite-EI deck without a body stop with named errors. -Limits. The torsion model is quasi-static (no torsional inertia), takes no seabed friction -against twist, and does not resolve self-contact. The torque–tension coupling is checked against +Limits. The torsion model takes no seabed friction against twist and does not resolve +self-contact; its statics are condensed (uniform torque). The nodal twist's inertia and damping +are checked against the continuum and modal closed forms only. The torque–tension coupling is checked against closed forms only; there is no cross-code or experimental record of it. Dynamic loop formation (hockling) and a twisted slack catenary against OrcaFlex are not part of this record, and there is no experimental torsion case. diff --git a/doc/capabilities.rst b/doc/capabilities.rst index 25943f26..0568936b 100644 --- a/doc/capabilities.rst +++ b/doc/capabilities.rst @@ -83,9 +83,11 @@ Line and constitutive capability fail closed by name * - Torsion of finite-EI lines - Supported with limits - - condensed isotropic torsion (uniform torque, quasi-static: no torsional inertia) of a - finite-EI line restrained in torsion at both ends (``END CONNECTIONS`` torsion columns, - explicit ``GJ``), with torque–tension coupling (``GJ|K``), in statics with a stability check and buckling descent, and in dynamics + - isotropic torsion of a finite-EI line restrained in torsion at both ends + (``END CONNECTIONS`` torsion columns, explicit ``GJ``), with torque–tension coupling + (``GJ|K``): condensed (uniform torque) in statics with a stability check and buckling + descent, and a twist angle at every node in dynamics, with the polar inertia ``Irn`` and + torsional damping (``GJ|K|Bt``), with turning Rigid6 bodies, ``vesselMotion``/``vesselRAO`` and the ``motionFile`` roll column standalone, and with the platform orientation in coupled OpenFAST and FAST.Farm runs (torque returned to the platform, ``PtfmInit``, checkpoints; see @@ -93,8 +95,8 @@ Line and constitutive capability name: the standalone mixed ``EI = 0`` + finite-EI aggregate and the C API (which move the line ends by translation only), OpenFAST linearisation of a line restrained in torsion, rod ends, bodies other than Rigid6, lines with ``ATTACHMENTS``, modal analysis, and - ``False alpha_force_blend``. Not modelled: seabed friction against twist, torque–tension - coupling, anisotropic sections, self-contact of a loop (see :ref:`theory-torsion`) + ``False alpha_force_blend``. Not modelled: seabed friction against twist, anisotropic + sections, self-contact of a loop (see :ref:`theory-torsion`) * - Hockling loops, nonlinear cross-section laws - Not provided - the buckling onset and the post-buckled shape are computed, but a loop that closes on diff --git a/doc/driver_format.md b/doc/driver_format.md index 0be83193..905f9d4e 100644 --- a/doc/driver_format.md +++ b/doc/driver_format.md @@ -256,18 +256,26 @@ row decides: A stock-order header applies only to the 10-column row. **Optional finite-EI columns.** A 14-column row adds `GAs`, `GJ`, `Irt`, `Irn` (shear stiffness, -torsional stiffness, transverse and axial rotary inertia per length): +torsional stiffness, transverse and polar (axial) rotary inertia per length): `Name Diam Mass EA BA EI GAs GJ Irt Irn Cd_n Cd_t Ca_n Ca_t`. The four extra values must be finite and either all `0` or all `> 0`. All zero, or the 10-column row, selects the circular-section closure `GAs = EA/(2(1+0.3))`, `GJ = EI/(1+0.3)`, `Irt = m d²/16`, `Irn = m d²/8`. The closure serves the secondary Cosserat path only: a finite-EI line restrained in torsion ([END CONNECTIONS](#end-connections-optional-finite-ei-lines)) takes `GJ` [N·m²/rad] from the -14-column row of each of its sections and stops by name without it. `GAs`, `Irt` and `Irn` are -not used by the cubic-Hermite route, but the all-or-nothing rule still asks for positive values. +14-column row of each of its sections and stops by name without it. In the dynamics such a line +carries a twist angle at every node, whose polar rotary inertia is `Irn` [kg·m²/m] +(`m r²/2` for a solid round section; see [Nodal twist](theory.rst)): give the section's real +value, as a placeholder `Irn` gives the line a wrong torsional inertia. `GAs` and `Irt` are not +used by the cubic-Hermite route, but the all-or-nothing rule still asks for positive values. The `GJ` column may be written `GJ|K`, with `K` [N·m] the torque–tension coupling of an armoured cable or wire rope (`T = EA ε + K τ`, `M = GJ τ + K ε`; see [Torque–tension coupling](theory.rst)). It needs a finite-EI, linear-elastic type with `K² < EA·GJ`; the two-moving-end compatibility route refuses it. `GJ|0` is the plain `GJ`. +`GJ|K|Bt` adds the torsional damping `Bt` [N·m²·s] of the nodal twist (the torque +`Bt dτ/dt`, stiffness-proportional: a torsional mode of frequency `ω` has the damping ratio +`ω Bt/(2 GJ)`); a negative `Bt` is `-ζ`, the fraction of an element's critical torsional damping +`l0 √(GJ Irn)` on the final mesh, as `BA` is for the axial damping. It needs a finite-EI type; +`GJ|0|Bt` is damping without coupling. **Viscoelastic axial stiffness (MoorDyn `ElasticMod`).** The EA and BA columns accept bar-separated parts: diff --git a/doc/outputs.rst b/doc/outputs.rst index 52c64afd..31dc068e 100644 --- a/doc/outputs.rst +++ b/doc/outputs.rst @@ -733,22 +733,26 @@ Line-node channels - deg * - ``TorqN`` - torque (twisting moment) at node ``J`` of a line restrained in torsion at both ends - (``END CONNECTIONS`` ``TorsStiffness``, see :doc:`driver_format`). It is uniform along the - line, :math:`M = (\Phi - \Theta_{\text{eff}})/C` (:math:`\Theta_{\text{eff}} = \Theta` - without torque–tension coupling); positive for a right-handed twist of End B relative + (``END CONNECTIONS`` ``TorsStiffness``, see :doc:`driver_format`). In the statics it is + uniform along the line, :math:`M = (\Phi - \Theta_{\text{eff}})/C` + (:math:`\Theta_{\text{eff}} = \Theta` without torque–tension coupling); in the dynamics it + is the nodal twist's torque at the node, the mean of its two elements' (an end node's + element; :ref:`nodal twist `). Positive for a right-handed twist of End B relative to End A about the End A → End B tangent, as OrcaFlex's ``Torque`` - N·m * - ``TwistN`` - material twist of the cable itself from End A to node ``J``, the sum of the element - twists :math:`M L_e/GJ_e` (less :math:`(K/GJ)(l_e - L_e)` under torque–tension coupling) - over the elements between them: 0 at End A, and at End B the + twists :math:`M L_e/GJ_e` (less :math:`(K/GJ)(l_e - L_e)` under torque–tension coupling; + in the dynamics the nodal twist's element twists) over the elements between them: 0 at + End A, and at End B the twist of the line without the windup of its torsional end springs. OrcaFlex reports the twist rate (``Twist``, deg/m) instead; here it is integrated from End A - deg * - ``Twist`` - total twist of the line, :math:`\Phi - \Theta = M C`, including the windup of torsional end springs: the imposed twist :math:`\Phi` less the geometric twist - :math:`\Theta` the line takes up by writhing out of its plane + :math:`\Theta` the line takes up by writhing out of its plane (in the dynamics the + element twists plus the end springs' windup) - deg Touchdown channels diff --git a/doc/theory.rst b/doc/theory.rst index 37f91c5f..76bab7a5 100644 --- a/doc/theory.rst +++ b/doc/theory.rst @@ -138,7 +138,8 @@ element, with a 2 % criterion relative to the largest local magnitude (at least The element follows the geometrically exact Kirchhoff-rod formulation of :ref:`Boyer et al. (2011) ` with the :math:`C^1` Hermite centreline interpolation of :ref:`Meier, Popp & Wall (2015) `, reduced to a torsion-free -cable. Torsion enters only through the condensed line term below. +cable. Torsion enters through the condensed line term of the statics and the nodal twist of the +dynamics below. .. _theory-bend-stiffeners: @@ -354,7 +355,8 @@ It is carried to every node by parallel transport along the centreline, eight sm rotations between the Hermite tangents per element, which does not twist it about the tangent. On a line in torsion it is then turned about :math:`\mathbf{t}` by the twist from End A, the torque times the End A compliance plus :math:`\sum l_0/GJ` from End A, right-handed about -:math:`\mathbf{t}`. With :math:`\mathbf{d}_2 = \mathbf{t} \times \mathbf{d}_1` (y), +:math:`\mathbf{t}`. In the dynamics, with the :ref:`nodal twist `, +it is the material director of each node, on the same convention. With :math:`\mathbf{d}_2 = \mathbf{t} \times \mathbf{d}_1` (y), ``CurvX`` :math:`= \kappa\mathbf{n} \cdot \mathbf{d}_1` and ``CurvY`` :math:`= \kappa\mathbf{n} \cdot \mathbf{d}_2`. A fibre at :math:`(x, y)` in the section is strained in bending by :math:`-(\kappa_x x + \kappa_y y)`. On a line twisted 90 degrees from @@ -459,13 +461,12 @@ constant-velocity joint), for which :math:`\tan x = -x/3` and :math:`M_{cr} = 4. zero tension, not the :math:`2\pi EI/L` of Greenhill's axial-torque hinge. OrcaFlex's bending-free end with a twisting spring gives the same value (see :doc:`validation`). -**Dynamics and loads.** The torsion force enters the force-blended residual like the internal -force, so a dynamic deck with torsion requires ``True alpha_force_blend`` (the default). Torsion -carries no inertia: the torque follows the imposed twist within the step, without a torsional -wave. This is accurate while the first torsional frequency of the line, -:math:`\sqrt{GJ/I_p}/(2L)` with :math:`I_p` the polar mass moment per length, is well above the -excitation; it is not for very long or torsionally soft lines. The moment of the torque on the -object at End A is :math:`M\,\partial\Theta/\partial\boldsymbol{\omega}_A`, the derivative with +**Dynamics and loads.** A deck line carries the nodal twist below in the dynamics, with the +condensed torsion as its limit of a negligible polar inertia; a line built through the API +without the polar inertia keeps the condensed torsion, whose torque follows the imposed twist +within the step, without a torsional wave. Either enters the force-blended residual like the +internal force, so a dynamic deck with torsion requires ``True alpha_force_blend`` (the +default). In the condensed torsion, the moment of the torque on the object at End A is :math:`M\,\partial\Theta/\partial\boldsymbol{\omega}_A`, the derivative with respect to a rotation :math:`\boldsymbol{\omega}_A` of that object (for a clamped end, of its frame and the end tangent together), so the virtual work of the body moment is exact; for a straight line it is the torque along the line axis. The static body equilibrium uses the same moment and @@ -499,6 +500,64 @@ cannot twist, so it carries :math:`T = EA\,\varepsilon` and :math:`M = K\varepsi tension adds the element's :math:`(K/GJ)\,M`, and the twist channels sum the element twists :math:`M L_0/GJ - (K/GJ)(l - L_0)`. +.. _theory-nodal-twist: + +**Nodal twist (dynamics).** The dynamics give every node :math:`k` a twist angle +:math:`\varphi_k`: the angle about the unit node tangent :math:`\mathbf{t}_k` from a reference +director :math:`\mathbf{u}_k` to the material director. Over each step the reference directors +follow their tangents by the smallest rotation (time-parallel transport), so the axial angular +velocity of the section is :math:`\dot\varphi_k`. The material twist of element :math:`e` +between nodes :math:`k` and :math:`k+1` is :math:`\varphi_{k+1} - \varphi_k + m_e`, with the +reference twist :math:`m_e = \beta_e - h_e`: :math:`\beta_e` the angle from :math:`\mathbf{u}_k`, +carried to node :math:`k+1` by the smallest rotation, to :math:`\mathbf{u}_{k+1}`, and :math:`h_e` +the element holonomy above. Transport around the geodesic quadrilateral of the committed and +present tangents gives + +.. math:: + + \beta_e = \beta_e^n - \Omega(\mathbf{t}_k^n, \mathbf{t}_k, \mathbf{t}_{k+1}) + - \Omega(\mathbf{t}_k^n, \mathbf{t}_{k+1}, \mathbf{t}_{k+1}^n) , + +local to the element's 12 DOFs, with the closed-form gradient and Hessian of the solid angles. +The turns of the line live in the angles, so no :math:`2\pi` branch is tracked. This is the +time-parallel reference frame of discrete elastic rods (:ref:`Bergou et al., 2008 +`) on the Hermite centreline. The element carries the torque + +.. math:: + + M_e = \frac{GJ_e}{L_{0,e}}\,\hat\tau_e + \frac{B_{t,e}}{L_{0,e}}\,\dot{\hat\tau}_e, \qquad + \hat\tau_e = \varphi_{k+1} - \varphi_k + m_e + \frac{K_e}{GJ_e}\,(l_e - L_{0,e}) , + +the elastic torque of the energy :math:`\tfrac12 (GJ/L_0)\,\hat\tau^2`, which with the cable's +axial stiffness :math:`EA - K^2/GJ` is the section energy of the torque–tension coupling, and +the Kelvin–Voigt torsional damping :math:`B_t` (``GJ|K|Bt``), whose rate takes the nodal rates +and :math:`\nabla\hat\tau\cdot\dot{\mathbf{q}}`. The damping is stiffness-proportional: the +torsional mode of frequency :math:`\omega` has the damping ratio :math:`\omega B_t/(2GJ)`. The +polar rotary inertia :math:`I_{rn}` (``Irn``) is lumped at the nodes. An elastic end adds its +spring between the end node and the end frame's normal carried to the node; a rigid end takes +that normal as its node's director and holds the node's angle (0 at the first node of the solve +order, End B, and :math:`\Phi` at End A), so a turn of the frame enters the end element's +reference twist through the same solid angles. A turn of an end frame by more than +:math:`\pi/2` about the line within one step is refused, and the step is cut. + +In the limit of a negligible inertia the element torques are uniform and equal the condensed +torque; the test suite holds the two models to 1e-6 on a rolling, swaying, bowed line with +clamped, bending-pinned and elastic ends, and checks the torque of a driven torsional wave +against the continuum, the decay of the first torsional mode under :math:`B_t`, and the energy +of a free vibration (see :doc:`validation`). + +The angles join the generalised-α step with the same Newmark scheme. The tangent couples them +to the tangent DOFs of their elements: the step factorises one band in the order +:math:`[\mathbf{r}, \mathbf{m}, \varphi]` per node (half-bandwidth 13 instead of 11), into which +the cable's tangent, the angle rows and columns, the lumped inertia and the damping are +assembled; the angle rows converge on the nodal torque balance, scaled as the force rows are by +the nodal loads. The committed reference twists are advanced with the step's own solid angles, so +the committed state reproduces the converged iterate bit for bit, and the twist state is part of +the snapshot, the recovering step and the checkpoint mirror. A host write of the coupled end +between steps (the direct feedthrough) twists the end element against the frozen interior, as +the end's translation stretches it. The node torque (``TorqN``) is the mean of its two +elements', and the material twists of the elements sum to the twist channels. + **Limits.** Seabed friction does not resist twist, so the laid part of a line twists freely (the friction torque of a cable on the seabed can be comparable with the twist torque near touchdown). There is no anisotropic or pre-twisted section, and no self-contact: a loop that diff --git a/python/cabledyn/builder.py b/python/cabledyn/builder.py index cb8cda73..56f485e3 100644 --- a/python/cabledyn/builder.py +++ b/python/cabledyn/builder.py @@ -193,7 +193,9 @@ class LineType: Optional finite-EI columns (shear and torsional stiffness, rotary inertias). All four set writes the 14-column row; all ``None`` writes the 10-column row. ``gj`` may be ``(GJ, K)``, with ``K`` the - torque-tension coupling in N m (written ``GJ|K``). + torque-tension coupling in N m (written ``GJ|K``), or ``(GJ, K, Bt)``, + with ``Bt`` the torsional damping in N m^2 s, negative for a damping + ratio (written ``GJ|K|Bt``). cl, df, cf : float | None Optional cross-flow VIV columns of a type (MoorDyn's lift coefficient and the half-range and centre of the synchronisation band @@ -212,7 +214,7 @@ class LineType: can: float = 0.0 cat: float = 0.0 gas: float | None = None - gj: float | tuple[float, float] | None = None + gj: float | tuple[float, ...] | None = None irt: float | None = None irn: float | None = None cl: float | None = None @@ -1628,7 +1630,7 @@ def add_line_type( can: float = 0.0, cat: float = 0.0, gas: float | None = None, - gj: float | tuple[float, float] | None = None, + gj: float | tuple[float, ...] | None = None, irt: float | None = None, irn: float | None = None, cl: float | None = None, @@ -2659,8 +2661,8 @@ def _line_type_table(self) -> tuple[str, str, list[list[str]]]: extra = (item.gas, item.gj, item.irt, item.irn) if all(value is not None for value in extra): wide = True - if isinstance(item.gj, tuple) and len(item.gj) != 2: - raise ValueError(f"{what}: gj is GJ or (GJ, K)") + if isinstance(item.gj, tuple) and len(item.gj) not in (2, 3): + raise ValueError(f"{what}: gj is GJ, (GJ, K) or (GJ, K, Bt)") row += [ _multi(value, what) if index == 1 else _num(value, what) for index, value in enumerate(extra) diff --git a/python/cabledyn/deck_file.py b/python/cabledyn/deck_file.py index 3fe4a0c7..c72dd9db 100644 --- a/python/cabledyn/deck_file.py +++ b/python/cabledyn/deck_file.py @@ -2655,7 +2655,7 @@ def numeric(token: str, row: DeckRecord, field: str) -> float: for row in self.line_types: for index in (1, 2, *range(5, len(row.tokens))): if len(row.tokens) == 14 and index == 7: - continue # the GJ column, GJ or GJ|K, is read below + continue # the GJ column, GJ, GJ|K or GJ|K|Bt, is read below numeric(row.tokens[index], row, f"LINE TYPES column {index + 1}") ea_parts = row.tokens[3].split("|") ba_parts = row.tokens[4].split("|") @@ -2744,14 +2744,17 @@ def numeric(token: str, row: DeckRecord, field: str) -> float: raise DeckFormatError(f"{self._at(row)}: {model} is not supported with EI > 0") gj_value = 0.0 if len(row.tokens) == 14: - # the GJ column is GJ or GJ|K (K the torque-tension coupling, N m) + # the GJ column is GJ, GJ|K or GJ|K|Bt (K the torque-tension coupling, N m; + # Bt the torsional damping, N m^2 s, negative: -zeta) gj_parts = row.tokens[7].split("|") - if len(gj_parts) > 2: + if len(gj_parts) > 3: raise DeckFormatError( - f'{self._at(row)}: LINE TYPES GJ column "{row.tokens[7]}" takes GJ or GJ|K' + f'{self._at(row)}: LINE TYPES GJ column "{row.tokens[7]}" takes GJ, GJ|K ' + "or GJ|K|Bt" ) gj_value = numeric(gj_parts[0], row, "GJ") - ktt = numeric(gj_parts[1], row, "GJ|K coupling") if len(gj_parts) == 2 else 0.0 + ktt = numeric(gj_parts[1], row, "GJ|K coupling") if len(gj_parts) >= 2 else 0.0 + btor = numeric(gj_parts[2], row, "GJ|K|Bt damping") if len(gj_parts) == 3 else 0.0 finite_ei = [ numeric(row.tokens[6], row, "LINE TYPES column 7"), gj_value, @@ -2781,6 +2784,11 @@ def numeric(token: str, row: DeckRecord, field: str) -> float: f"{self._at(row)}: LINE TYPES {name}: torque-tension coupling needs " "GJ > 0 and K^2 < EA GJ" ) + if btor != 0.0 and not (ei > 0.0 and gj_value > 0.0 and finite_ei[3] > 0.0): + raise DeckFormatError( + f"{self._at(row)}: LINE TYPES {row.tokens[0]}: torsional damping (GJ|K|Bt) " + "needs a finite-EI cable with GJ > 0 and Irn > 0" + ) line_type_meta[row.tokens[0].lower()] = ( numeric(row.tokens[1], row, "Diam"), numeric(row.tokens[2], row, "Mass"), diff --git a/python/tests/test_builder.py b/python/tests/test_builder.py index c0996a74..d3d28f19 100644 --- a/python/tests/test_builder.py +++ b/python/tests/test_builder.py @@ -962,12 +962,35 @@ def test_torque_tension_coupling_round_trips_in_the_gj_column(tmp_path: Path) -> assert next(t for t in loaded.line_types if t.name == "cable").gj == (1.0e4, 2.0e5) +def test_torsional_damping_round_trips_in_the_gj_column(tmp_path: Path) -> None: + model = _chain_model(tmp_path) + cable = model.add_line_type( + "cable", + diam=0.2, + mass=40.0, + ea=5.0e8, + ei=1.0e4, + gas=1.0e8, + gj=(1.0e4, 0.0, -0.02), + irt=0.1, + irn=0.05, + ) + assert cable.gj == (1.0e4, 0.0, -0.02) + target = model.save(tmp_path / "damped.dat") + deck = DeckFile.read(target) + row = next(r for r in deck.line_types if r.tokens[0] == "cable") + assert [float(v) for v in row.tokens[7].split("|")] == [1.0e4, 0.0, -0.02] + loaded = DeckModel.load(target) + assert next(t for t in loaded.line_types if t.name == "cable").gj == (1.0e4, 0.0, -0.02) + + @pytest.mark.parametrize( ("gj", "ei", "message"), [ ("1.0e4|1.0e7", "1.0e4", r"K\^2 < EA GJ"), ("1.0e4|1.0e3", "0.0", "needs a finite-EI cable"), - ("1.0e4|1.0e3|5.0", "1.0e4", r"takes GJ or GJ\|K"), + ("1.0e4|1.0e3|5.0|1.0", "1.0e4", r"takes GJ, GJ\|K or GJ\|K\|Bt"), + ("1.0e4|0|5.0", "0.0", "torsional damping"), ], ) def test_torque_tension_coupling_refusals(tmp_path: Path, gj: str, ei: str, message: str) -> None: diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index 67f916cd..035060bf 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -110,7 +110,8 @@ MODULE CableDyn_DeckDriver CD_HermiteCable_Dyn_Set_Control_Seabed, & CD_HermiteCable_Dyn_Max_Step_Rotation, CD_HermiteCable_Dyn_Energy, & CD_HermiteCable_Attachment_Drag, CD_HermiteCable_Dyn_Torsion_State, & - CD_HermiteCable_Dyn_Element_Twist, CD_HermiteCable_Dyn_Coupling_Tension + CD_HermiteCable_Dyn_Element_Twist, CD_HermiteCable_Dyn_Coupling_Tension, & + CD_HermiteCable_Dyn_Node_Torque, CD_HermiteCable_Dyn_End_Twist USE CableDyn_HermiteTorsion, ONLY: CD_HermiteTorsionType, CD_HermiteTorsion_Compliance, CD_HTORS_MAX_STEP, & CD_HTORS_MAX_TWIST USE CableDyn_EndConnection, ONLY: CD_ENDCONN_PINNED, CD_ENDCONN_FINITE, CD_ENDCONN_RIGID @@ -366,6 +367,10 @@ MODULE CableDyn_DeckDriver ! torque-tension coupling K [N m] of the 14-column row's GJ column (GJ|K): the axial force ! T = EA eps + K tau and the torque M = GJ tau + K eps of a finite-EI cable REAL(wp) :: ktt = CD_ZERO + ! torsional damping Bt [N m^2 s] of the GJ column's third part (GJ|K|Bt), the torque Bt dtau/dt + ! of the nodal twist; negative: -zeta, the fraction of an element's critical torsional + ! damping l0 sqrt(GJ Irn), resolved on the final mesh + REAL(wp) :: bt = CD_ZERO REAL(wp) :: i_rt = CD_ZERO, i_rn = CD_ZERO REAL(wp) :: cdn = CD_ZERO, cdt = CD_ZERO, can = CD_ZERO, cat = CD_ZERO ! Viscoelastic stiffness (MoorDyn ElasticMod): the EA column's bar-separated @@ -1736,7 +1741,7 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, INTEGER, ALLOCATABLE :: conn(:, :), fixed_dofs(:), dynamic_fixed_dofs(:) REAL(wp), ALLOCATABLE :: l0(:), ea(:), mpl(:), diam(:), ei(:), gas_in(:), gj_in(:), i_rt_in(:), i_rn_in(:) - REAL(wp), ALLOCATABLE :: ktt_in(:) + REAL(wp), ALLOCATABLE :: ktt_in(:), bt_in(:) REAL(wp), ALLOCATABLE :: gas(:), gj(:), rho_a(:), i_rt(:), i_rn(:), w(:), nodes_ref(:, :), q0(:), q_static(:) REAL(wp), ALLOCATABLE :: q_sequence(:) REAL(wp), ALLOCATABLE :: curv(:), cdn(:), cdt(:), can(:), cat(:), catenary_pos(:) @@ -1983,7 +1988,7 @@ RECURSIVE SUBROUTINE build_one_hermite_cable(ln, sections, types, points, opts, IF (as_laid_off_plane()) require_3d_static = .TRUE. CALL build_finite_section_mesh(ln, sections, types, conn, l0, ea, mpl, diam, ei, & - gas_in, gj_in, i_rt_in, i_rn_in, ErrStat, ErrMsg, ktt=ktt_in) + gas_in, gj_in, i_rt_in, i_rn_in, ErrStat, ErrMsg, ktt=ktt_in, bt=bt_in) IF (ErrStat /= CD_DECKDRV_OK) RETURN IF (ALLOCATED(ln%stf)) THEN ALLOCATE (ei_cable(SIZE(l0))) @@ -3325,6 +3330,19 @@ SUBROUTINE torsion_stage(est, emt) tors%couple = ktt_in/gj_in IF (SIZE(l0_am) /= SIZE(l0)) CALL remap_elem_by_reference_arc(tors%couple, l0, l0_am) END IF + ! the polar rotary inertia Irn per element: the dynamics then carries a twist angle at + ! every node (CD_HermiteCable_Dyn_Set_Torsion) + tors%irn = i_rn_in + IF (SIZE(l0_am) /= SIZE(l0)) CALL remap_elem_by_reference_arc(tors%irn, l0, l0_am) + ! torsional damping (GJ|K|Bt): a negative value is -zeta of an element's critical torsional + ! damping l0 sqrt(GJ Irn), on the final mesh + IF (ANY(ABS(bt_in) > CD_ZERO)) THEN + tors%bt = bt_in + IF (SIZE(l0_am) /= SIZE(l0)) CALL remap_elem_by_reference_arc(tors%bt, l0, l0_am) + DO k = 1, SIZE(tors%bt) + IF (tors%bt(k) < CD_ZERO) tors%bt(k) = -tors%bt(k)*l0_am(k)*SQRT(tors%gj(k)*tors%irn(k)) + END DO + END IF DO k = 1, 2 dvec = endconn_d0_local(:, k)/NORM2(endconn_d0_local(:, k)) IF (k == 1) THEN @@ -9859,12 +9877,13 @@ SUBROUTINE end_hermite_cables(cables) END SUBROUTINE end_hermite_cables SUBROUTINE build_finite_section_mesh(ln, sections, types, conn, l0, ea, mpl, diam, ei, gas, gj, i_rt, i_rn, & - ErrStat, ErrMsg, ktt) + ErrStat, ErrMsg, ktt, bt) !! Build a sectioned finite-EI mesh directly from deck sections. The EI=0 !! CableDyn_Line mesh builder intentionally rejects EI>0, so this path owns !! the simple serial connectivity needed by the Cosserat model. A type with torque-tension !! coupling K gives its elements the axial stiffness EA - K^2/GJ (the stretch twists the - !! cable; a line restrained in torsion adds the rest through its torque) and, with ktt, its K. + !! cable; a line restrained in torsion adds the rest through its torque) and, with ktt, its K; + !! bt returns the deck's torsional damping (unresolved: -zeta stays negative). TYPE(DeckLine), INTENT(IN) :: ln TYPE(DeckSection), INTENT(IN) :: sections(:) TYPE(DeckLineType), INTENT(IN) :: types(:) @@ -9873,10 +9892,10 @@ SUBROUTINE build_finite_section_mesh(ln, sections, types, conn, l0, ea, mpl, dia REAL(wp), ALLOCATABLE, INTENT(OUT) :: gas(:), gj(:), i_rt(:), i_rn(:) INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg - REAL(wp), ALLOCATABLE, INTENT(OUT), OPTIONAL :: ktt(:) + REAL(wp), ALLOCATABLE, INTENT(OUT), OPTIONAL :: ktt(:), bt(:) INTEGER :: n_elem, i, j, e, tidx - REAL(wp), ALLOCATABLE :: kc(:) + REAL(wp), ALLOCATABLE :: kc(:), bc(:) ErrStat = CD_DECKDRV_OK ErrMsg = '' @@ -9889,7 +9908,7 @@ SUBROUTINE build_finite_section_mesh(ln, sections, types, conn, l0, ea, mpl, dia RETURN END IF ALLOCATE (conn(2, n_elem), l0(n_elem), ea(n_elem), mpl(n_elem), diam(n_elem), ei(n_elem)) - ALLOCATE (gas(n_elem), gj(n_elem), i_rt(n_elem), i_rn(n_elem), kc(n_elem)) + ALLOCATE (gas(n_elem), gj(n_elem), i_rt(n_elem), i_rn(n_elem), kc(n_elem), bc(n_elem)) e = 0 DO i = 1, SIZE(sections) IF (sections(i)%line_id /= ln%id) CYCLE @@ -9907,6 +9926,7 @@ SUBROUTINE build_finite_section_mesh(ln, sections, types, conn, l0, ea, mpl, dia i_rt(e) = types(tidx)%i_rt i_rn(e) = types(tidx)%i_rn kc(e) = types(tidx)%ktt + bc(e) = types(tidx)%bt IF (ABS(kc(e)) > CD_ZERO) ea(e) = ea(e) - kc(e)**2/gj(e) END DO END DO @@ -9921,6 +9941,7 @@ SUBROUTINE build_finite_section_mesh(ln, sections, types, conn, l0, ea, mpl, dia i_rt = i_rt(n_elem:1:-1) i_rn = i_rn(n_elem:1:-1) IF (PRESENT(ktt)) ktt = kc(n_elem:1:-1) + IF (PRESENT(bt)) bt = bc(n_elem:1:-1) END SUBROUTINE build_finite_section_mesh SUBROUTINE finite_raw_ba_array(ln, sections, types, ba_raw) @@ -13358,30 +13379,40 @@ SUBROUTINE sniff_types_header(line, stock_cols) END SUBROUTINE sniff_types_header SUBROUTINE parse_gj_column(gj_str, t, ErrStat, ErrMsg) - !! The 14-column row's GJ column: GJ, or GJ|K with K the torque-tension coupling [N m] + !! The 14-column row's GJ column: GJ, GJ|K with K the torque-tension coupling [N m] !! (M = GJ tau + K eps, T = EA eps + K tau; K > 0 when stretching the cable twists it in the - !! sense its positive torque turns). + !! sense its positive torque turns), or GJ|K|Bt with Bt the torsional damping (DeckLineType). CHARACTER(*), INTENT(IN) :: gj_str TYPE(DeckLineType), INTENT(INOUT) :: t INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg - INTEGER :: bar, ios + INTEGER :: bar, bar2, ios ErrStat = 0; ErrMsg = '' t%ktt = CD_ZERO + t%bt = CD_ZERO bar = INDEX(gj_str, '|') IF (bar == 0) THEN READ (gj_str, *, IOSTAT=ios) t%gj ELSE - IF (INDEX(gj_str(bar + 1:), '|') > 0) THEN - CALL fail(ErrStat, ErrMsg, 'LINE TYPES GJ column "'//TRIM(gj_str)//'" takes GJ or GJ|K'); RETURN + bar2 = INDEX(gj_str(bar + 1:), '|') + IF (bar2 > 0) THEN + bar2 = bar + bar2 + IF (INDEX(gj_str(bar2 + 1:), '|') > 0) THEN + CALL fail(ErrStat, ErrMsg, 'LINE TYPES GJ column "'//TRIM(gj_str)//'" takes GJ, GJ|K or GJ|K|Bt'); RETURN + END IF END IF READ (gj_str(1:bar - 1), *, IOSTAT=ios) t%gj - IF (ios == 0) READ (gj_str(bar + 1:), *, IOSTAT=ios) t%ktt + IF (bar2 > 0) THEN + IF (ios == 0) READ (gj_str(bar + 1:bar2 - 1), *, IOSTAT=ios) t%ktt + IF (ios == 0) READ (gj_str(bar2 + 1:), *, IOSTAT=ios) t%bt + ELSE + IF (ios == 0) READ (gj_str(bar + 1:), *, IOSTAT=ios) t%ktt + END IF END IF IF (ios /= 0) THEN - CALL fail(ErrStat, ErrMsg, 'LINE TYPES GJ column "'//TRIM(gj_str)//'" is not GJ or GJ|K'); RETURN + CALL fail(ErrStat, ErrMsg, 'LINE TYPES GJ column "'//TRIM(gj_str)//'" is not GJ, GJ|K or GJ|K|Bt'); RETURN END IF - IF (.NOT. (IEEE_IS_FINITE(t%gj) .AND. IEEE_IS_FINITE(t%ktt))) THEN + IF (.NOT. (IEEE_IS_FINITE(t%gj) .AND. IEEE_IS_FINITE(t%ktt) .AND. IEEE_IS_FINITE(t%bt))) THEN CALL fail(ErrStat, ErrMsg, 'LINE TYPES GJ column "'//TRIM(gj_str)//'" must be finite'); RETURN END IF END SUBROUTINE parse_gj_column @@ -13475,6 +13506,12 @@ SUBROUTINE append_type(line, types, nt, stock_cols, ErrStat, ErrMsg) 'K^2 < EA GJ'); RETURN END IF END IF + IF (ABS(t%bt) > CD_ZERO) THEN + IF (.NOT. (t%ei > CD_ZERO .AND. t%gj > CD_ZERO .AND. t%i_rn > CD_ZERO)) THEN + CALL fail(ErrStat, ErrMsg, 'LINE TYPES '//TRIM(t%name)//': torsional damping (GJ|K|Bt) needs a '// & + 'finite-EI cable with GJ > 0 and Irn > 0'); RETURN + END IF + END IF CALL grow_types(types, nt) nt = nt + 1; types(nt) = t END SUBROUTINE append_type @@ -34597,7 +34634,19 @@ SUBROUTINE range_sample_cable(cable, rl, ErrStat, ErrMsg) IF (rl%has_torsion .AND. cable%line%torsion%active) THEN ! condensed torsion: the committed torque (uniform) and the cable's own twist from End A ! (public node 1, the last internal node), as the TorqN and TwistN channels - rl%val(CD_RQ_TORQUE, :) = cable%line%torsion%torque + IF (cable%line%tw_active) THEN + ! nodal twist: the node torques (public node j is internal node nn + 1 - j) + BLOCK + REAL(wp) :: ntq(nn) + CALL CD_HermiteCable_Dyn_Node_Torque(cable%line, ntq, es, em) + IF (es /= CD_HCDYN_OK) THEN + CALL fail_solve(ErrStat, ErrMsg, 'range-graph torque recovery failed: '//TRIM(em)); RETURN + END IF + rl%val(CD_RQ_TORQUE, 1:nn) = ntq(nn:1:-1) + END BLOCK + ELSE + rl%val(CD_RQ_TORQUE, :) = cable%line%torsion%torque + END IF rl%val(CD_RQ_TWIST, 1) = CD_ZERO BLOCK REAL(wp) :: etw(cable%line%ne) @@ -35500,7 +35549,17 @@ SUBROUTINE eval_cable_channel(cable, ch, val, ErrStat, ErrMsg, mesh_node) IF (es /= CD_HCDYN_OK) THEN CALL fail_solve(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": '//TRIM(em)); RETURN END IF - IF (kind == 9) THEN + IF (kind == 9 .AND. cable%line%tw_active) THEN + ! nodal twist: the torque at the node (its elements' mean; an end node's element) + BLOCK + REAL(wp) :: ntq(cable%line%nn) + CALL CD_HermiteCable_Dyn_Node_Torque(cable%line, ntq, es, em) + IF (es /= CD_HCDYN_OK) THEN + CALL fail_solve(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": '//TRIM(em)); RETURN + END IF + val = ntq(inode) + END BLOCK + ELSE IF (kind == 9) THEN val = mt ELSE IF (cable%line%torsion%active) THEN ! the element twists (M_t l0/GJ, less the stretch's under torque-tension coupling); @@ -35512,7 +35571,16 @@ SUBROUTINE eval_cable_channel(cable, ch, val, ErrStat, ErrMsg, mesh_node) IF (es /= CD_HCDYN_OK) THEN CALL fail_solve(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": '//TRIM(em)); RETURN END IF - IF (kind == 11) THEN + IF (kind == 11 .AND. cable%line%tw_active) THEN + BLOCK + REAL(wp) :: etw2(2) + CALL CD_HermiteCable_Dyn_End_Twist(cable%line, etw2, es, em) + IF (es /= CD_HCDYN_OK) THEN + CALL fail_solve(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": '//TRIM(em)); RETURN + END IF + val = (SUM(etw2) + SUM(etw))*45.0_wp/QUARTER_PI + END BLOCK + ELSE IF (kind == 11) THEN val = (mt*SUM(cable%line%torsion%end_compliance) + SUM(etw))*45.0_wp/QUARTER_PI ELSE val = SUM(etw(inode:nelem))*45.0_wp/QUARTER_PI diff --git a/src/CableDyn_HermiteCableDynamic.f90 b/src/CableDyn_HermiteCableDynamic.f90 index cd696c9a..f1020ab5 100644 --- a/src/CableDyn_HermiteCableDynamic.f90 +++ b/src/CableDyn_HermiteCableDynamic.f90 @@ -79,7 +79,10 @@ MODULE CableDyn_HermiteCableDynamic CD_HermiteTorsion_Compliance, CD_HermiteTorsion_Validate, CD_HTORS_OK, & CD_HTORS_MAX_STEP, CD_HermiteTorsionWorkType, CD_HermiteTorsion_Work_Init, & CD_HermiteTorsion_Work_End, CD_HermiteTorsion_Work_Add_Hessian, & - CD_HermiteTorsion_Element_Stretch + CD_HermiteTorsion_Element_Stretch, CD_HermiteTorsion_Element, & + CD_HermiteTorsion_Stretch_Derivatives, CD_HermiteTwist_Reference, & + CD_HermiteTwist_Carry, CD_HermiteTwist_Angle, CD_HermiteTwist_Omega, & + CD_HermiteTwist_Omega_Gradient, CD_HTORS_PI USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: INT64 !$ USE OMP_LIB, ONLY: omp_get_max_threads, omp_in_parallel IMPLICIT NONE @@ -94,6 +97,9 @@ MODULE CableDyn_HermiteCableDynamic PUBLIC :: CD_HermiteCable_Dyn_Torsion_State PUBLIC :: CD_HermiteCable_Dyn_Element_Twist PUBLIC :: CD_HermiteCable_Dyn_Coupling_Tension + PUBLIC :: CD_HermiteCable_Dyn_Element_Torque, CD_HermiteCable_Dyn_Node_Torque, CD_HermiteCable_Dyn_End_Twist + PUBLIC :: CD_HermiteCable_Dyn_Twist_Mirror_Size, CD_HermiteCable_Dyn_Twist_Pack, CD_HermiteCable_Dyn_Twist_Unpack + PUBLIC :: CD_HermiteCable_Dyn_Twist_Check PUBLIC :: CD_HermiteCable_Dyn_Set_Torsion_Drive PUBLIC :: CD_HermiteCable_Dyn_Set_Torsion_Frames PUBLIC :: CD_HermiteCable_Dyn_EndConnection_Moment @@ -167,6 +173,8 @@ MODULE CableDyn_HermiteCableDynamic ! general-band storage (DGBSV layout: entry (i, j) at ab(KL_D + KU_D + 1 + i - j, j), with ! KL_D extra top rows for the factorization fill) -- no dense matrices, no bandwidth scan. INTEGER, PARAMETER :: KL_D = 11, KU_D = 11 + ! Half-bandwidth of the nodal-twist tangent in 7-DOF-per-node order ([r, m, phi] per node). + INTEGER, PARAMETER :: KB7 = 13 INTEGER, PARAMETER :: LDAB_D = 2*KL_D + KU_D + 1 ! Profiling is OFF by default: SYSTEM_CLOCK in the step/residual hot path is measurable @@ -444,6 +452,46 @@ MODULE CableDyn_HermiteCableDynamic REAL(wp) :: tors_c_ends(3, 4) = CD_ZERO, tors_c_prev = CD_ZERO, tors_c_theta = CD_ZERO REAL(wp) :: tors_c_eg(6) = CD_ZERO, tors_c_gend(3, 2) = CD_ZERO LOGICAL :: tors_c_valid = .FALSE. + ! Nodal twist (the torsion carries the polar inertia irn; CD_HermiteCable_Dyn_Set_Torsion): + ! a twist angle phi per node, the angle about the node tangent from the reference director + ! u to the material director, replaces the condensed torque in the dynamics. The directors + ! follow the node tangents by the smallest rotation over each step (time-parallel + ! transport), so the axial angular velocity of a section is phi_dot. Element e twists by + ! phi_{e+1} - phi_e + rho_e(q), rho_e = beta_e - h_e + (K/GJ)(l_e - l0) (beta_e the angle + ! from u_e carried to node e + 1 to u_{e+1}, h_e the element holonomy), and carries the + ! torque M_e = (GJ/l0)(phi_{e+1} - phi_e + rho_e) + (Bt/l0) d/dt(...). An elastic end adds a + ! spring k (twist of the end node against its end frame); a rigid end takes the end frame's + ! normal carried to the node as its director and holds phi (0 at end 1, Phi at end 2). + ! Committed state: tw_phi/tw_w/tw_al (angle, rate, acceleration; nn), tw_u and tw_tn + ! (directors and unit tangents; 3 x nn), tw_beta (ne), tw_psi (the end-frame reference of + ! an elastic end) and tw_mt (element torques, ne). tw_mass is the lumped polar inertia. + ! Step scratch: tw_pn/wn/an (step start), tw_pk/wk/ak (iterate), tw_ptrial, tw_dp, tw_G, + ! tw_Gt, tw_Rk, tw_Rt, tw_R (phi residual of the last assembly), tw_fcR (the force cache's + ! phi part), tw_pe/tw_we (the angles and rates the assembly reads in a step), the element + ! and end-link tangent data of the last tangent assembly (tw_eg, tw_ehv, tw_ek, tw_ed, + ! tw_lg, tw_lk), the element torques of the last assembly (tw_me), and the 7-DOF-per-node + ! effective tangent tw_K7 with its pivots and solve vector (KL = KU = 13). + LOGICAL :: tw_active = .FALSE. + LOGICAL :: tw_rigid(2) = .FALSE. + REAL(wp), ALLOCATABLE :: tw_phi(:), tw_w(:), tw_al(:), tw_mass(:), tw_u(:, :), tw_tn(:, :) + REAL(wp), ALLOCATABLE :: tw_beta(:), tw_mt(:) + REAL(wp) :: tw_psi(2) = CD_ZERO + LOGICAL, ALLOCATABLE :: tw_free(:) + REAL(wp), ALLOCATABLE :: tw_pn(:), tw_wn(:), tw_an(:), tw_pk(:), tw_wk(:), tw_ak(:), tw_ptrial(:), tw_dp(:) + REAL(wp), ALLOCATABLE :: tw_G(:), tw_Gt(:), tw_Rk(:), tw_Rt(:), tw_R(:), tw_fcR(:), tw_pe(:), tw_we(:) + REAL(wp), ALLOCATABLE :: tw_eg(:, :), tw_ehv(:, :), tw_ek(:), tw_ed(:), tw_me(:) + REAL(wp) :: tw_lg(3, 2) = CD_ZERO, tw_lk(2) = CD_ZERO + REAL(wp), ALLOCATABLE :: tw_K7(:, :), tw_x7(:) + INTEGER, ALLOCATABLE :: tw_ipiv(:) + ! tw_tsum: the summed element and end-link twists (Phi less the condensed Theta_eff in a + ! quasi-static state) of the last assembly; tw_su/tw_stn/tw_sbeta/tw_spsi: the reference + ! state at q_{n+1} (tw_advance_reference) awaiting the commit; tw_tscale: the torque scale of + ! the step's residual norm. + REAL(wp) :: tw_tsum = CD_ZERO, tw_spsi(2) = CD_ZERO, tw_tscale = CD_ONE + REAL(wp), ALLOCATABLE :: tw_su(:, :), tw_stn(:, :), tw_sbeta(:) + ! Packed twist state (tw_pack) of the recovering step's interval start and of the snapshot, + ! and the snapshot's tw_fcR. + REAL(wp), ALLOCATABLE :: ws_recovery_tw(:), snap_tw(:), snap_tw_fcR(:) LOGICAL :: snap_valid = .FALSE. ! Adaptive-Newton warmup counters are step-history too: a staged step (aggregate ! stage-then-commit) that advances them and is then rolled back must restore them, or the @@ -1927,6 +1975,8 @@ SUBROUTINE rebuild_length_caches(model, l0_new, ErrStat, ErrMsg) CALL MOVE_ALLOC(cn_new, model%contact_cn) IF (model%fr_active) model%fr_k = model%contact_kn END IF + ! the lumped polar inertia of the nodal twist follows the lengths + IF (model%tw_active) CALL tw_set_derived(model, model%torsion) END SUBROUTINE rebuild_length_caches SUBROUTINE enter_committed_lengths(model, aside, ErrStat, ErrMsg) @@ -3343,6 +3393,10 @@ SUBROUTINE CD_HermiteCable_Dyn_Step(model, dt, max_iter, tol, ErrStat, ErrMsg, i !! consistent). Theta is unwrapped against the committed value and may change by at most pi/2 !! in a step (a larger change fails the evaluation, and the line search or the recovering step !! cuts it). It needs the force-blended generalised-alpha. + !! + !! NODAL TWIST (the torsion carries irn; see the type note): the twist angles join the step + !! with the same Newmark scheme and are solved with the cable in one band of [r, m, phi] per + !! node; an end frame may turn by at most pi/2 about the line in a step. TYPE(CD_HermiteCableDynType), INTENT(INOUT), TARGET :: model REAL(wp), INTENT(IN) :: dt, tol INTEGER, INTENT(IN) :: max_iter @@ -3462,6 +3516,44 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_Torsion_Frames(model, ends, ErrStat, ErrMsg, model%tors_drive_ends = drive_ends model%tors_drive_phi = drive_phi IF (ErrStat /= CD_HCDYN_OK) RETURN + IF (model%tw_active) THEN + ! Nodal twist: the reference re-based at the committed (or checked) configuration with the + ! new frames (tw_advance_reference: a rigid end's element takes the frame's turn, an + ! elastic end's spring its psi), then the committed torques and Theta_eff. + IF (PRESENT(q_check)) THEN + IF (SIZE(q_check) /= model%ndof) THEN + ErrStat = CD_HCDYN_BADINPUT + ErrMsg = 'CD_HermiteCable_Dyn_Set_Torsion_Frames: q_check must have ndof entries' + RETURN + END IF + CALL tw_advance_reference(model, q_check, ends, ErrStat, ErrMsg) + ELSE + CALL tw_advance_reference(model, model%q, ends, ErrStat, ErrMsg) + END IF + IF (ErrStat /= CD_HCDYN_OK) THEN + ErrMsg = 'CD_HermiteCable_Dyn_Set_Torsion_Frames: '//TRIM(ErrMsg) + RETURN + END IF + IF (PRESENT(q_check)) RETURN + ! a frame turn within one step of the end-frame constants (the wrapped change is unique) + model%tors_drive_set = .FALSE. + CALL tw_commit_reference(model) + model%torsion%ends = ends + model%tors_use_step = .FALSE. + CALL assemble_twist(model, model%q, model%v, .TRUE., .FALSE., model%ws_R, model%ws_Kb, model%ws_Kvb, & + ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) THEN + ErrMsg = 'CD_HermiteCable_Dyn_Set_Torsion_Frames: '//TRIM(ErrMsg) + RETURN + END IF + model%tw_mt = model%tw_me + model%torsion%theta = model%torsion%phi - model%tw_tsum + model%torsion%torque = model%tw_tsum/CD_HermiteTorsion_Compliance(model%torsion, model%l0) + model%fc_valid = .FALSE. + model%fc_clears = model%fc_clears + 1 + model%tr_valid = .FALSE. + RETURN + END IF IF (PRESENT(q_check)) THEN IF (SIZE(q_check) /= model%ndof) THEN ErrStat = CD_HCDYN_BADINPUT @@ -3693,6 +3785,13 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r model%ws_vn(iv) = model%v(iv) model%ws_an(iv) = model%a(iv) END DO + IF (model%tw_active) THEN + DO iv = 1, model%nn + model%tw_pn(iv) = model%tw_phi(iv) + model%tw_wn(iv) = model%tw_w(iv) + model%tw_an(iv) = model%tw_al(iv) + END DO + END IF CALL rigid_tangent_scalar_state(model, model%endconn_d0, model%ws_qn, model%ws_vn, model%ws_an, & step_n0, step_ndot0, step_nddot0) ! Total mass for this step: structural + added mass FROZEN at the beginning-of-step @@ -3751,6 +3850,11 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r DO iv = 1, SIZE(model%fc_R) model%fc_R(iv) = model%ws_R(iv) END DO + IF (model%tw_active) THEN + DO iv = 1, model%nn + model%tw_fcR(iv) = model%tw_R(iv) + END DO + END IF ! Key the recomputed force on the state it describes. model%fc_q = model%q model%fc_v = model%v @@ -3848,6 +3952,18 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r model%ws_qk(pres_dofs(ip)) = pres_q(ip) END DO END IF + ! Nodal twist: the same predictor for the angles; a rigid end holds 0 (end 1) or Phi (end 2). + IF (model%tw_active) THEN + DO iv = 1, model%nn + IF (use_ca) THEN + model%tw_pk(iv) = model%tw_pn(iv) + dt*model%tw_wn(iv) + 0.5_wp*dt*dt*model%tw_an(iv) + ELSE + model%tw_pk(iv) = model%tw_pn(iv) + dt*model%tw_wn(iv) + (0.5_wp - bt)*dt*dt*model%tw_an(iv) + END IF + END DO + IF (model%tw_rigid(1)) model%tw_pk(1) = CD_ZERO + IF (model%tw_rigid(2)) model%tw_pk(model%nn) = model%tors_step_phi + END IF CALL project_rigid_tangents(model, step_endconn_target, model%ws_qk, es, em2) IF (es /= CD_HCDYN_OK) THEN ErrStat = es @@ -3962,7 +4078,18 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r ! Factor with the model-owned pivot workspace (DGBTRF -- exactly what DGBSV runs ! internally, without its per-call pivot allocation). IF (prof_enabled) CALL SYSTEM_CLOCK(pc0) - CALL CD_Factor_Banded(model%ws_Keffb, KL_D, KU_D, model%ws_ipiv, es, em2, matrix_validated=.TRUE.) + IF (model%tw_active) THEN + ! nodal twist: the cable's band with the angles interleaved ([r, m, phi] per node) + CALL tw_build_K7(model, (CD_ONE - am)*c_a, CD_ONE - af, cw, step_rigid_basis, es, em2) + IF (es /= CD_HCDYN_OK) THEN + ErrStat = es; ErrMsg = 'CD_HermiteCable_Dyn_Step: '//TRIM(em2) + IF (attempt < n_attempt) CYCLE predict + RETURN + END IF + CALL CD_Factor_Banded(model%tw_K7, KB7, KB7, model%tw_ipiv, es, em2, matrix_validated=.TRUE.) + ELSE + CALL CD_Factor_Banded(model%ws_Keffb, KL_D, KU_D, model%ws_ipiv, es, em2, matrix_validated=.TRUE.) + END IF IF (prof_enabled) THEN CALL SYSTEM_CLOCK(pc1) prof_n_factor = prof_n_factor + 1 @@ -3973,7 +4100,7 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r IF (attempt < n_attempt) CYCLE predict RETURN END IF - IF (model%torsion%active) THEN + IF (model%torsion%active .AND. .NOT. model%tw_active) THEN ! Rank-one torsion term (1 - af) g g^T / C of the effective tangent: g in the solve ! coordinates (as the residual), its K^-1 image and the Sherman-Morrison denominator, ! all kept with this factor. @@ -4002,8 +4129,15 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r IF (.NOT. model%solve_mask(i)) model%ws_dq(i) = CD_ZERO END DO IF (prof_enabled) CALL SYSTEM_CLOCK(pc0) - CALL CD_Solve_Factored_Banded(model%ws_Keffb, KL_D, KU_D, model%ws_ipiv, model%ws_dq, es, em2, & - factor_validated=.TRUE.) + IF (model%tw_active) THEN + DO i = 1, model%nn + model%tw_dp(i) = MERGE(-model%tw_G(i), CD_ZERO, model%tw_free(i)) + END DO + CALL tw_solve(model, es, em2) + ELSE + CALL CD_Solve_Factored_Banded(model%ws_Keffb, KL_D, KU_D, model%ws_ipiv, model%ws_dq, es, em2, & + factor_validated=.TRUE.) + END IF IF (prof_enabled) THEN CALL SYSTEM_CLOCK(pc1) prof_n_solve = prof_n_solve + 1 @@ -4014,7 +4148,7 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r IF (attempt < n_attempt) CYCLE predict RETURN END IF - IF (model%torsion%active) CALL torsion_sm_correct() + IF (model%torsion%active .AND. .NOT. model%tw_active) CALL torsion_sm_correct() CALL transform_rigid_vector_to_global(model, step_rigid_basis, model%ws_dq) nsolve_step = nsolve_step + 1 IF (PRESENT(iters_out)) iters_out = nsolve_step @@ -4027,7 +4161,7 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r lambda = CD_ONE ! Condensed torsion: the linearised twist change of a trial stays within pi/4 (the ! post-trial unwrap against the committed Theta cannot tell 3 pi/2 from -pi/2) - IF (model%torsion%active) THEN + IF (model%torsion%active .AND. .NOT. model%tw_active) THEN dth_lin = ABS(DOT_PRODUCT(model%tors_g, model%ws_dq)) IF (dth_lin > 0.5_wp*CD_HTORS_MAX_STEP) lambda = 0.5_wp*CD_HTORS_MAX_STEP/dth_lin END IF @@ -4035,6 +4169,7 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r DO iv = 1, SIZE(model%ws_qtrial) model%ws_qtrial(iv) = model%ws_qk(iv) + lambda*model%ws_dq(iv) END DO + IF (model%tw_active) CALL tw_trial(lambda) CALL eval_res(model%ws_qtrial, .TRUE., rnt, es, em2) IF (es == CD_HCDYN_OK) THEN lam_ok = lambda ! loop shrinks lambda, so this ends smallest @@ -4127,6 +4262,7 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r DO iv = 1, SIZE(model%ws_qtrial) model%ws_qtrial(iv) = model%ws_qk(iv) + lambda*model%ws_dq(iv) END DO + IF (model%tw_active) CALL tw_trial(lambda) CALL eval_res(model%ws_qtrial, .TRUE., rnt, es, em2) IF (es == CD_HCDYN_OK) THEN ! The fallback step rarely improves the residual, so under modified Newton the @@ -4181,6 +4317,7 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r DO iv = 1, SIZE(model%ws_Rk) model%ws_Rk(iv) = model%ws_Rt(iv) END DO + IF (model%tw_active) CALL tw_accept() rnorm = rnt END DO EXIT predict @@ -4198,19 +4335,27 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r IF (.NOT. model%solve_mask(i)) model%ws_dq(i) = CD_ZERO END DO IF (prof_enabled) CALL SYSTEM_CLOCK(pc0) - CALL CD_Solve_Factored_Banded(model%ws_Keffb, KL_D, KU_D, model%ws_ipiv, model%ws_dq, es, em2, & - factor_validated=.TRUE.) + IF (model%tw_active) THEN + DO i = 1, model%nn + model%tw_dp(i) = MERGE(-model%tw_G(i), CD_ZERO, model%tw_free(i)) + END DO + CALL tw_solve(model, es, em2) + ELSE + CALL CD_Solve_Factored_Banded(model%ws_Keffb, KL_D, KU_D, model%ws_ipiv, model%ws_dq, es, em2, & + factor_validated=.TRUE.) + END IF IF (prof_enabled) THEN CALL SYSTEM_CLOCK(pc1) prof_n_correct = prof_n_correct + 1 prof_t_solve = prof_t_solve + REAL(pc1 - pc0, wp)/REAL(pcr, wp) END IF IF (es == CD_LINALG_OK) THEN - IF (model%torsion%active) CALL torsion_sm_correct() + IF (model%torsion%active .AND. .NOT. model%tw_active) CALL torsion_sm_correct() CALL transform_rigid_vector_to_global(model, step_rigid_basis, model%ws_dq) DO iv = 1, SIZE(model%ws_qtrial) model%ws_qtrial(iv) = model%ws_qk(iv) + model%ws_dq(iv) END DO + IF (model%tw_active) CALL tw_trial(CD_ONE) CALL eval_res(model%ws_qtrial, .TRUE., rnt, es, em2) IF (es == CD_HCDYN_OK .AND. rnt < rnorm) THEN DO iv = 1, SIZE(model%ws_qk) @@ -4222,6 +4367,7 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r DO iv = 1, SIZE(model%ws_Rk) model%ws_Rk(iv) = model%ws_Rt(iv) END DO + IF (model%tw_active) CALL tw_accept() rnorm = rnt IF (PRESENT(res_out)) res_out = rnorm ELSE @@ -4240,7 +4386,15 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r ! audit under torque-tension coupling. tors_theta_new = model%torsion%theta tors_mt_new = CD_ZERO - IF (model%torsion%active) THEN + IF (model%tw_active) THEN + ! nodal twist: the reference state at q_{n+1}, and Theta_eff = Phi less the summed twist + ! of the converged evaluation, whose element torques (tw_me) enter the audit + CALL tw_advance_reference(model, model%ws_qk, model%tors_step_ends, es, em2) + IF (es /= CD_HCDYN_OK) THEN + ErrStat = es; ErrMsg = 'CD_HermiteCable_Dyn_Step: '//TRIM(em2); RETURN + END IF + tors_theta_new = model%tors_step_phi - model%tw_tsum + ELSE IF (model%torsion%active) THEN CALL torsion_theta_at(model, model%ws_qk, model%tors_step_ends, tors_theta_new, es, em2) IF (es /= CD_HCDYN_OK) THEN ErrStat = es; ErrMsg = 'CD_HermiteCable_Dyn_Step: '//TRIM(em2); RETURN @@ -4380,6 +4534,18 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r IF (model%has_viv) CALL viv_step_end(model, dt) model%t = model%t + dt IF (has_endconn_motion) model%endconn_d0 = step_endconn_target + IF (model%tw_active) THEN + DO iv = 1, model%nn + model%tw_ak(iv) = c_a*(model%tw_pk(iv) - model%tw_pn(iv)) - c_v*model%tw_wn(iv) - c_a2*model%tw_an(iv) + model%tw_phi(iv) = model%tw_pk(iv) + model%tw_al(iv) = model%tw_ak(iv) + model%tw_w(iv) = model%tw_wn(iv) + dt*((CD_ONE - gm)*model%tw_an(iv) + gm*model%tw_ak(iv)) + END DO + CALL tw_commit_reference(model) + DO iv = 1, model%ne + model%tw_mt(iv) = model%tw_me(iv) + END DO + END IF IF (model%torsion%active) THEN model%torsion%ends = model%tors_step_ends model%torsion%phi = model%tors_step_phi @@ -4387,12 +4553,15 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r model%torsion%torque = (model%torsion%phi - tors_theta_new)/ & CD_HermiteTorsion_Compliance(model%torsion, model%l0) ! the read-only queries of the committed state (end loads, energy, channels) from the - ! cache; a failure here only leaves it invalid (a query then evaluates and reports it) - BLOCK - INTEGER :: es_tc - CHARACTER(1024) :: em_tc - CALL torsion_cache_fill(model, es_tc, em_tc) - END BLOCK + ! cache; a failure here only leaves it invalid (a query then evaluates and reports it). + ! The nodal twist answers its queries from its own committed state. + IF (.NOT. model%tw_active) THEN + BLOCK + INTEGER :: es_tc + CHARACTER(1024) :: em_tc + CALL torsion_cache_fill(model, es_tc, em_tc) + END BLOCK + END IF END IF ! Carry the factor of this step's last iteration to the next step. model%tr_valid = model%tangent_reuse .AND. factor_ok @@ -4417,6 +4586,11 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r DO iv = 1, SIZE(model%fc_R) model%fc_R(iv) = model%ws_Rk(iv) END DO + IF (model%tw_active) THEN + DO iv = 1, model%nn + model%tw_fcR(iv) = model%tw_Rk(iv) + END DO + END IF model%fc_q = model%q model%fc_v = model%v model%fc_t = model%t @@ -4462,12 +4636,17 @@ SUBROUTINE window_load(slot, e) END SUBROUTINE window_load REAL(wp) FUNCTION audit_coupling(e) RESULT(tc) - !! The torque-tension coupling force (K/GJ) M_t of element e at the converged torque. + !! The torque-tension coupling force (K/GJ) M_t of element e at the converged torque (the + !! nodal twist's own element torque, else the condensed uniform one). INTEGER, INTENT(IN) :: e tc = CD_ZERO IF (.NOT. model%torsion%active) RETURN IF (.NOT. ALLOCATED(model%torsion%couple)) RETURN - tc = model%torsion%couple(e)*tors_mt_new + IF (model%tw_active) THEN + tc = model%torsion%couple(e)*model%tw_me(e) + ELSE + tc = model%torsion%couple(e)*tors_mt_new + END IF END FUNCTION audit_coupling SUBROUTINE window_mean(slot, esx) @@ -4537,7 +4716,7 @@ SUBROUTINE eval_res(qcur, use_trial, rn, esx, emx) REAL(wp), POINTER :: Gout(:) INTEGER :: ii, nd INTEGER(INT64) :: ec0, ec1 - REAL(wp) :: xref + REAL(wp) :: xref, xd REAL(wp), PARAMETER :: RESID_ROUNDOFF = 16.0_wp REAL(wp), PARAMETER :: STATE_DIVERGED = 1.0e12_wp ec0 = 0_INT64 ! defined even with profiling off (see the step-entry note) @@ -4590,6 +4769,7 @@ SUBROUTINE eval_res(qcur, use_trial, rn, esx, emx) END DO END IF IF (has_endconn_motion) CALL impose_step_rigid_kinematics(qcur, model%ws_vk, model%ws_ak) + IF (model%tw_active) CALL tw_stage(use_trial) ! Force blend: the configuration the force (and the loop-top tangent) is evaluated at is ! the iterate itself; only the inertia uses the alpha_m blend. Configuration blend: the ! forces are evaluated at the alpha_f-blended state. @@ -4616,6 +4796,7 @@ SUBROUTINE eval_res(qcur, use_trial, rn, esx, emx) ELSE CALL vector_copy(model%ws_R, model%ws_Rk) END IF + IF (model%tw_active) CALL tw_residual(use_trial) ! total (structural + frozen added) mass inertia via the band matvec CALL band_matvec(model%ws_Msumb, model%ws_aa, model%ws_inert) IF (model%force_blend) THEN @@ -4655,6 +4836,25 @@ SUBROUTINE eval_res(qcur, use_trial, rn, esx, emx) IF (MOD(ii - 1, 6) < 3) xref = MAX(xref, ABS(qcur(ii))) END DO fscale = MAX(fscale, RESID_ROUNDOFF*EPSILON(CD_ONE)*MAXVAL(model%EA/model%l0)*xref/tol) + ! Nodal twist: the torque scale of the angle rows, frozen with fscale and formed like it + ! from the nodal loads (a node's torque imbalance, not the torque the line carries, + ! which accumulates the imbalances along the line as the tension does the force's): the + ! inertial torques and the predictor's imbalance, at least 1 N m, and the round-off + ! floor of an element twist, (GJ/l0 + Bt/l0 gamma/(beta dt)) eps (max|phi| + max|x|/l0) + ! (the damping takes the twist rate, whose Newmark rate amplifies the rounding). + IF (model%tw_active) THEN + model%tw_tscale = CD_ONE + DO ii = 1, model%nn + IF (.NOT. model%tw_free(ii)) CYCLE + model%tw_tscale = MAX(model%tw_tscale, & + ABS(model%tw_mass(ii)*((CD_ONE - am)*model%tw_ak(ii) + am*model%tw_an(ii))), & + ABS(model%tw_R(ii))) + END DO + xd = MAXVAL(model%torsion%gj/model%l0) + IF (ALLOCATED(model%torsion%bt)) xd = xd + MAXVAL(model%torsion%bt/model%l0)*gm/(bt*dt) + model%tw_tscale = MAX(model%tw_tscale, RESID_ROUNDOFF*EPSILON(CD_ONE)*xd* & + (MAX(CD_ONE, MAXVAL(ABS(model%tw_pe))) + xref/MINVAL(model%l0))/tol) + END IF scale_set = .TRUE. END IF rn = CD_ZERO @@ -4667,6 +4867,16 @@ SUBROUTINE eval_res(qcur, use_trial, rn, esx, emx) rn = MAX(rn, ABS(Gout(ii))/fscale) END IF END DO + IF (model%tw_active) THEN + DO ii = 1, model%nn + IF (.NOT. model%tw_free(ii)) CYCLE + IF (use_trial) THEN + rn = MAX(rn, ABS(model%tw_Gt(ii))/model%tw_tscale) + ELSE + rn = MAX(rn, ABS(model%tw_G(ii))/model%tw_tscale) + END IF + END DO + END IF IF (.NOT. CD_Is_Finite(rn)) THEN esx = CD_HCDYN_NOCONVERGE; emx = 'non-finite residual' END IF @@ -4786,6 +4996,65 @@ SUBROUTINE torsion_sm_correct() END DO END SUBROUTINE torsion_sm_correct + SUBROUTINE tw_stage(use_trial) + !! Nodal twist: the Newmark rates and accelerations of the iterate's (or the trial's) + !! angles, staged in tw_pe/tw_we for the assembly. + LOGICAL, INTENT(IN) :: use_trial + INTEGER :: ii + REAL(wp) :: p + DO ii = 1, model%nn + IF (use_trial) THEN + p = model%tw_ptrial(ii) + ELSE + p = model%tw_pk(ii) + END IF + model%tw_ak(ii) = c_a*(p - model%tw_pn(ii)) - c_v*model%tw_wn(ii) - c_a2*model%tw_an(ii) + model%tw_wk(ii) = model%tw_wn(ii) + dt*((CD_ONE - gm)*model%tw_an(ii) + gm*model%tw_ak(ii)) + model%tw_pe(ii) = p + model%tw_we(ii) = model%tw_wk(ii) + END DO + END SUBROUTINE tw_stage + + SUBROUTINE tw_residual(use_trial) + !! Nodal twist: the angle rows of the generalised-alpha residual, I ((1 - am) a_{n+1} + + !! am a_n) + (1 - af) R_phi(n+1) + af R_phi(n) (zero at a held angle), and the + !! unblended R_phi of the evaluation. + LOGICAL, INTENT(IN) :: use_trial + INTEGER :: ii + REAL(wp) :: gv + DO ii = 1, model%nn + gv = CD_ZERO + IF (model%tw_free(ii)) gv = model%tw_mass(ii)*((CD_ONE - am)*model%tw_ak(ii) + am*model%tw_an(ii)) + & + (CD_ONE - af)*model%tw_R(ii) + af*model%tw_fcR(ii) + IF (use_trial) THEN + model%tw_Gt(ii) = gv + model%tw_Rt(ii) = model%tw_R(ii) + ELSE + model%tw_G(ii) = gv + model%tw_Rk(ii) = model%tw_R(ii) + END IF + END DO + END SUBROUTINE tw_residual + + SUBROUTINE tw_trial(lam) + !! Nodal twist: the line-search trial angles tw_pk + lam tw_dp. + REAL(wp), INTENT(IN) :: lam + INTEGER :: ii + DO ii = 1, model%nn + model%tw_ptrial(ii) = model%tw_pk(ii) + lam*model%tw_dp(ii) + END DO + END SUBROUTINE tw_trial + + SUBROUTINE tw_accept() + !! Nodal twist: the accepted trial becomes the iterate. + INTEGER :: ii + DO ii = 1, model%nn + model%tw_pk(ii) = model%tw_ptrial(ii) + model%tw_G(ii) = model%tw_Gt(ii) + model%tw_Rk(ii) = model%tw_Rt(ii) + END DO + END SUBROUTINE tw_accept + END SUBROUTINE dyn_step_core SUBROUTINE torsion_theta_at(model, q_cfg, ends, theta, ErrStat, ErrMsg) @@ -4992,6 +5261,7 @@ SUBROUTINE CD_HermiteCable_Dyn_Step_Recovering(model, dt, max_iter, tol, ErrStat tors_theta0 = model%torsion%theta tors_phi0 = model%torsion%phi tors_ends0 = model%torsion%ends + IF (model%tw_active) CALL tw_pack(model, model%ws_recovery_tw) tors_phi1 = tors_phi0 tors_ends1 = tors_ends0 IF (model%torsion%active .AND. model%tors_drive_set) THEN @@ -5236,6 +5506,7 @@ SUBROUTINE restore_torsion() model%torsion%theta = tors_theta0 model%torsion%phi = tors_phi0 model%torsion%ends = tors_ends0 + IF (model%tw_active) CALL tw_unpack(model, model%ws_recovery_tw) model%torsion%torque = (tors_phi0 - tors_theta0)/CD_HermiteTorsion_Compliance(model%torsion, model%l0) model%tors_drive_set = .FALSE. END SUBROUTINE restore_torsion @@ -5487,7 +5758,37 @@ SUBROUTINE CD_HermiteCable_Dyn_Energy(model, kinetic, strain, ErrStat, ErrMsg, c END IF strain = strain + connection_energy END IF - IF (model%torsion%active) THEN + IF (model%tw_active) THEN + ! nodal twist: the element and end-spring energies and the polar kinetic energy + BLOCK + REAL(wp) :: rho, beta, g(12), h(12, 12), tau, psi, gl(3), hl(3, 3), tw + INTEGER :: iend + DO e = 1, model%ne + CALL twist_reference(model, e, model%q, model%torsion%ends, .FALSE., rho, beta, g, h, ErrStat, em2) + IF (ErrStat /= CD_HCDYN_OK) THEN + ErrMsg = 'CD_HermiteCable_Dyn_Energy: '//TRIM(em2) + RETURN + END IF + tau = model%tw_phi(e + 1) - model%tw_phi(e) + rho + strain = strain + 0.5_wp*model%torsion%gj(e)/model%l0(e)*tau*tau + END DO + DO iend = 1, 2 + IF (model%tw_rigid(iend)) CYCLE + CALL twist_link(model, iend, model%q, model%torsion%ends, .FALSE., psi, gl, hl, ErrStat, em2) + IF (ErrStat /= CD_HCDYN_OK) THEN + ErrMsg = 'CD_HermiteCable_Dyn_Energy: '//TRIM(em2) + RETURN + END IF + IF (iend == 1) THEN + tw = model%tw_phi(1) - psi + ELSE + tw = psi + model%torsion%phi - model%tw_phi(model%nn) + END IF + strain = strain + 0.5_wp*tw*tw/model%torsion%end_compliance(iend) + END DO + kinetic = kinetic + 0.5_wp*SUM(model%tw_mass*model%tw_w*model%tw_w) + END BLOCK + ELSE IF (model%torsion%active) THEN BLOCK REAL(wp) :: th, mt CALL CD_HermiteCable_Dyn_Torsion_State(model, th, mt, ErrStat, em2) @@ -5650,6 +5951,20 @@ SUBROUTINE CD_HermiteCable_Dyn_Section_Curvature(model, ref_a, kx, ky, ErrStat, ErrMsg = 'CD_HermiteCable_Dyn_Section_Curvature: the section reference lies along the End A tangent'; RETURN END IF d1 = d1/rn + IF (model%tw_active) THEN + ! Nodal twist: the material director Rot(t_k, phi - Phi) u of every node (t_k the solve + ! tangent, End 1 -> End 2), on the frame convention above: End A (node nn) takes the + ! reference normal turned by the End A spring twist only. + DO a = 1, model%nn + t = -unit_tangent(model, a) + phi = model%tw_phi(a) - model%torsion%phi + d = COS(phi)*model%tw_u(:, a) - SIN(phi)*cross3_local(t, model%tw_u(:, a)) + IF (PRESENT(frame)) frame(:, a) = d + kx(a) = DOT_PRODUCT(kvec(:, a), d) + ky(a) = DOT_PRODUCT(kvec(:, a), cross3_local(t, d)) + END DO + RETURN + END IF mt = CD_ZERO comp = CD_ZERO IF (model%torsion%active) THEN @@ -5999,8 +6314,18 @@ SUBROUTINE CD_HermiteCable_Dyn_End_Force(model, node, force, ErrStat, ErrMsg) END DO END IF force = -r3 - ! Condensed torsion: R carries -M_t dTheta/dq, so the end force gains +M_t dTheta/dr_end. - IF (model%torsion%active) THEN + ! Nodal twist: R carries M_e drho_e/dq of the end element (the committed torque M_e). + IF (model%tw_active) THEN + BLOCK + REAL(wp) :: rho, beta, g(12), h(12, 12) + CALL twist_reference(model, e, model%q, model%torsion%ends, .FALSE., rho, beta, g, h, es, em2) + IF (es /= CD_HCDYN_OK) THEN + ErrStat = es; ErrMsg = 'CD_HermiteCable_Dyn_End_Force: '//TRIM(em2); RETURN + END IF + force = force - model%tw_mt(e)*g(i0 + 1:i0 + 3) + END BLOCK + ! Condensed torsion: R carries -M_t dTheta/dq, so the end force gains +M_t dTheta/dr_end. + ELSE IF (model%torsion%active) THEN BLOCK REAL(wp) :: th, mt, gend(3, 2) CALL CD_HermiteCable_Dyn_Torsion_State(model, th, mt, es, em2, end_dr=gend) @@ -6235,7 +6560,11 @@ PURE REAL(wp) FUNCTION coupling_tension(model, e) RESULT(tc) IF (e < 1 .OR. e > model%ne) RETURN IF (.NOT. model%torsion%active) RETURN IF (.NOT. ALLOCATED(model%torsion%couple)) RETURN - tc = model%torsion%couple(e)*model%torsion%torque + IF (model%tw_active) THEN + tc = model%torsion%couple(e)*model%tw_mt(e) + ELSE + tc = model%torsion%couple(e)*model%torsion%torque + END IF END FUNCTION coupling_tension PURE REAL(wp) FUNCTION CD_HermiteCable_Dyn_Coupling_Tension(model, e) RESULT(tc) @@ -6280,6 +6609,25 @@ SUBROUTINE CD_HermiteCable_Dyn_Element_Twist(model, twist, ErrStat, ErrMsg) ErrMsg = 'CD_HermiteCable_Dyn_Element_Twist: twist must have one entry per element'; RETURN END IF IF (.NOT. model%torsion%active) RETURN + IF (model%tw_active) THEN + ! nodal twist: phi_{e+1} - phi_e + beta_e - h_e at the committed state + BLOCK + REAL(wp) :: rho, beta, g(12), h(12, 12), qe(12), ls + DO e = 1, model%ne + CALL twist_reference(model, e, model%q, model%torsion%ends, .FALSE., rho, beta, g, h, ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) RETURN + twist(e) = model%tw_phi(e + 1) - model%tw_phi(e) + rho + IF (ALLOCATED(model%torsion%couple)) THEN + IF (ABS(model%torsion%couple(e)) > CD_ZERO) THEN + CALL gather_elem(model, e, qe) + ls = CD_HermiteTorsion_Element_Stretch(qe, model%l0(e), model%torsion%quadrature_order) + twist(e) = twist(e) - model%torsion%couple(e)*(ls - model%l0(e)) + END IF + END IF + END DO + END BLOCK + RETURN + END IF CALL CD_HermiteCable_Dyn_Torsion_State(model, th, mt, ErrStat, ErrMsg) IF (ErrStat /= CD_HCDYN_OK) RETURN DO e = 1, model%ne @@ -6287,6 +6635,182 @@ SUBROUTINE CD_HermiteCable_Dyn_Element_Twist(model, twist, ErrStat, ErrMsg) END DO END SUBROUTINE CD_HermiteCable_Dyn_Element_Twist + SUBROUTINE CD_HermiteCable_Dyn_Element_Torque(model, torque, ErrStat, ErrMsg) + !! The torque of every element at the committed state [N m], positive for a right-handed + !! twist about the solve tangent (End 1 -> End 2): with the nodal twist the element torques + !! (elastic plus torsional damping), with the condensed torsion the uniform torque, and zero + !! for a line without torsion. Element order is the model's (End B first). + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + REAL(wp), INTENT(OUT) :: torque(:) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + torque = CD_ZERO + ErrStat = CD_HCDYN_OK; ErrMsg = '' + IF (SIZE(torque) /= model%ne) THEN + ErrStat = CD_HCDYN_BADINPUT + ErrMsg = 'CD_HermiteCable_Dyn_Element_Torque: torque must have one entry per element'; RETURN + END IF + IF (.NOT. model%torsion%active) RETURN + IF (model%tw_active) THEN + torque = model%tw_mt + ELSE + torque = model%torsion%torque + END IF + END SUBROUTINE CD_HermiteCable_Dyn_Element_Torque + + SUBROUTINE CD_HermiteCable_Dyn_Node_Torque(model, torque, ErrStat, ErrMsg) + !! The torque at every node at the committed state [N m] (the TorqN channels): an end + !! node takes its element's torque and an interior node the mean of its two elements' (the + !! uniform torque of the condensed torsion everywhere; zero without torsion). Node order is + !! the model's (End B first). + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + REAL(wp), INTENT(OUT) :: torque(:) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER :: k + torque = CD_ZERO + ErrStat = CD_HCDYN_OK; ErrMsg = '' + IF (SIZE(torque) /= model%nn) THEN + ErrStat = CD_HCDYN_BADINPUT + ErrMsg = 'CD_HermiteCable_Dyn_Node_Torque: torque must have one entry per node'; RETURN + END IF + IF (.NOT. model%torsion%active) RETURN + IF (.NOT. model%tw_active) THEN + torque = model%torsion%torque + RETURN + END IF + torque(1) = model%tw_mt(1) + torque(model%nn) = model%tw_mt(model%ne) + DO k = 2, model%nn - 1 + torque(k) = 0.5_wp*(model%tw_mt(k - 1) + model%tw_mt(k)) + END DO + END SUBROUTINE CD_HermiteCable_Dyn_Node_Torque + + SUBROUTINE CD_HermiteCable_Dyn_End_Twist(model, twist, ErrStat, ErrMsg) + !! The twist of the two torsional end springs at the committed state [rad] (internal ends 1 + !! and 2; zero at a rigid end): with the nodal twist the end node's against its end frame, + !! with the condensed torsion the torque times the end compliance. + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + REAL(wp), INTENT(OUT) :: twist(2) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp) :: psi, gl(3), hl(3, 3) + INTEGER :: iend + twist = CD_ZERO + ErrStat = CD_HCDYN_OK; ErrMsg = '' + IF (.NOT. model%torsion%active) RETURN + IF (.NOT. model%tw_active) THEN + twist = model%torsion%torque*model%torsion%end_compliance + RETURN + END IF + DO iend = 1, 2 + IF (model%tw_rigid(iend)) CYCLE + CALL twist_link(model, iend, model%q, model%torsion%ends, .FALSE., psi, gl, hl, ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) THEN + ErrMsg = 'CD_HermiteCable_Dyn_End_Twist: '//TRIM(ErrMsg) + RETURN + END IF + IF (iend == 1) THEN + twist(1) = model%tw_phi(1) - psi + ELSE + twist(2) = psi + model%torsion%phi - model%tw_phi(model%nn) + END IF + END DO + END SUBROUTINE CD_HermiteCable_Dyn_End_Twist + + SUBROUTINE CD_HermiteCable_Dyn_Twist_Check(model, q_check, ends, ErrStat, ErrMsg) + !! Read-only check that the nodal twist accepts the configuration q_check with the end + !! frames ends (a host about to write them): every element's reference twist and every + !! elastic end's spring evaluate (fold guard, an end frame within pi/2 of its committed + !! turn). Without the nodal twist it accepts. + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + REAL(wp), INTENT(IN) :: q_check(:), ends(3, 4) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp) :: rho, beta, g(12), h(12, 12), psi, gl(3), hl(3, 3) + INTEGER :: e, iend + ErrStat = CD_HCDYN_OK + ErrMsg = '' + IF (.NOT. model%tw_active) RETURN + IF (SIZE(q_check) /= model%ndof) THEN + ErrStat = CD_HCDYN_BADINPUT + ErrMsg = 'CD_HermiteCable_Dyn_Twist_Check: q_check must have ndof entries'; RETURN + END IF + DO e = 1, model%ne + CALL twist_reference(model, e, q_check, ends, .FALSE., rho, beta, g, h, ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) THEN + ErrMsg = 'CD_HermiteCable_Dyn_Twist_Check: '//TRIM(ErrMsg); RETURN + END IF + END DO + DO iend = 1, 2 + IF (model%tw_rigid(iend)) CYCLE + CALL twist_link(model, iend, q_check, ends, .FALSE., psi, gl, hl, ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) THEN + ErrMsg = 'CD_HermiteCable_Dyn_Twist_Check: '//TRIM(ErrMsg); RETURN + END IF + END DO + END SUBROUTINE CD_HermiteCable_Dyn_Twist_Check + + PURE INTEGER FUNCTION CD_HermiteCable_Dyn_Twist_Mirror_Size(model) RESULT(n) + !! Reals of the nodal-twist checkpoint mirror (CD_HermiteCable_Dyn_Twist_Pack): the + !! committed angles, rates and accelerations, directors, reference tangents, reference + !! twists, element torques, end-frame references and the force cache's angle part; 0 without + !! the nodal twist. + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + n = 0 + IF (model%tw_active) n = tw_pack_size(model) + model%nn + END FUNCTION CD_HermiteCable_Dyn_Twist_Mirror_Size + + SUBROUTINE CD_HermiteCable_Dyn_Twist_Pack(model, buf) + !! Write the nodal-twist checkpoint mirror (CD_HermiteCable_Dyn_Twist_Mirror_Size reals). + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + REAL(wp), INTENT(OUT) :: buf(:) + INTEGER :: n + IF (.NOT. model%tw_active) RETURN + n = tw_pack_size(model) + CALL tw_pack(model, buf(1:n)) + buf(n + 1:n + model%nn) = model%tw_fcR + END SUBROUTINE CD_HermiteCable_Dyn_Twist_Pack + + SUBROUTINE CD_HermiteCable_Dyn_Twist_Unpack(model, buf, ErrStat, ErrMsg, check_only) + !! Reload the nodal twist from a mirror of CD_HermiteCable_Dyn_Twist_Pack written by a + !! model built from the same input (the caller restores q, v, a and the force cache with + !! it). Fails closed on a size mismatch, a non-finite value or a non-unit director; with + !! check_only it only checks. + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + REAL(wp), INTENT(IN) :: buf(:) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + LOGICAL, INTENT(IN), OPTIONAL :: check_only + INTEGER :: n, i + ErrStat = CD_HCDYN_BADINPUT + IF (.NOT. model%tw_active) THEN + ErrMsg = 'CD_HermiteCable_Dyn_Twist_Unpack: the model has no nodal twist'; RETURN + END IF + n = tw_pack_size(model) + IF (SIZE(buf) /= n + model%nn) THEN + ErrMsg = 'CD_HermiteCable_Dyn_Twist_Unpack: the mirror does not match this line'; RETURN + END IF + IF (.NOT. CD_All_Finite(buf)) THEN + ErrMsg = 'CD_HermiteCable_Dyn_Twist_Unpack: non-finite twist state'; RETURN + END IF + DO i = 1, model%nn + IF (ABS(NORM2(buf(3*model%nn + 3*i - 2:3*model%nn + 3*i)) - CD_ONE) > 1.0e-8_wp .OR. & + ABS(NORM2(buf(6*model%nn + 3*i - 2:6*model%nn + 3*i)) - CD_ONE) > 1.0e-8_wp) THEN + ErrMsg = 'CD_HermiteCable_Dyn_Twist_Unpack: a director or reference tangent is not a unit vector'; RETURN + END IF + END DO + ErrStat = CD_HCDYN_OK + ErrMsg = '' + IF (PRESENT(check_only)) THEN + IF (check_only) RETURN + END IF + CALL tw_unpack(model, buf(1:n)) + model%tw_fcR = buf(n + 1:n + model%nn) + ErrStat = CD_HCDYN_OK + ErrMsg = '' + END SUBROUTINE CD_HermiteCable_Dyn_Twist_Unpack + SUBROUTINE node_values(model, node, fm, mm, fp, mp, tension, curvature, bend_moment, ErrStat, ErrMsg, & sleeve_moment, curvature_vector) !! Node values from the one-sided section force and moment before (fm, mm) and after @@ -6759,7 +7283,42 @@ SUBROUTINE CD_HermiteCable_Dyn_EndConnection_Moment(model, node, moment, ErrStat ErrMsg = 'CD_HermiteCable_Dyn_EndConnection_Moment: node must be a cable endpoint' RETURN END IF - IF (model%torsion%active) THEN + IF (model%tw_active) THEN + ! Nodal twist: -dE/dw of the end frame. A rigid end's element twists by rho(w) through + ! the frame (its normal carried to the end node is the node's director): -M_e drho/dw. An + ! elastic end's spring twists by -+psi(w): +-k tw dpsi/dw. With f(w) = angle(G(d' -> x) n' + ! -> u) of the frame turned by exp(w), G(d' -> x) n' = Rot(x, w . d + Omega(d, d', x)) + ! G(d -> x) n to first order, so df/dw = -d - d x dOmega/dy(d, d, x), and the frame's + ! director in a transport triangle adds d x dOmega/dd. The slaved tangent of a rigid + ! bending end adds its share through the constraint reaction below. + BLOCK + REAL(wp) :: rho, beta, g(12), h(12, 12), ew(3, 2), psi, gl(3), hl(3, 3), lw(3), tw + IF (model%tw_rigid(iend)) THEN + CALL twist_reference(model, MERGE(1, model%ne, iend == 1), model%q, model%torsion%ends, .FALSE., rho, & + beta, g, h, es, em, end_w=ew) + IF (es /= CD_HCDYN_OK) THEN + ErrStat = es + ErrMsg = 'CD_HermiteCable_Dyn_EndConnection_Moment: '//TRIM(em) + RETURN + END IF + moment = -model%tw_mt(MERGE(1, model%ne, iend == 1))*ew(:, iend) + ELSE + CALL twist_link(model, iend, model%q, model%torsion%ends, .FALSE., psi, gl, hl, es, em, end_w=lw) + IF (es /= CD_HCDYN_OK) THEN + ErrStat = es + ErrMsg = 'CD_HermiteCable_Dyn_EndConnection_Moment: '//TRIM(em) + RETURN + END IF + IF (iend == 1) THEN + tw = model%tw_phi(1) - psi + moment = tw/model%torsion%end_compliance(1)*lw + ELSE + tw = psi + model%torsion%phi - model%tw_phi(model%nn) + moment = -tw/model%torsion%end_compliance(2)*lw + END IF + END IF + END BLOCK + ELSE IF (model%torsion%active) THEN ! Torque of the condensed torsion on the support: the generalised moment ! -dE_t/dw = M_t dTheta/dw of the end frame (its axial part is -+M_t d); the slaved ! tangent of a rigid end adds its share through the constraint reaction below. @@ -6845,7 +7404,10 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_Torsion(model, torsion, ErrStat, ErrMsg) !! the torsion. The time step then carries the torsion (see CD_HermiteCable_Dyn_Step); its !! scratch is sized here, so a step allocates nothing. Like a new end connection, a change !! of the load set invalidates the step snapshot (CD_HermiteCable_Dyn_Restore then fails - !! closed); a failed call leaves the model, its snapshot included, as it was. + !! closed); a failed call leaves the model, its snapshot included, as it was. A description + !! with the polar inertia irn installs the nodal twist instead of the condensed torsion in + !! the dynamics (tw_init): the static uniform torque sets the angles, which then carry the + !! torsional inertia and the damping bt. TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model TYPE(CD_HermiteTorsionType), INTENT(IN) :: torsion INTEGER, INTENT(OUT) :: ErrStat @@ -6854,7 +7416,8 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_Torsion(model, torsion, ErrStat, ErrMsg) REAL(wp) :: th, mt REAL(wp) :: saved_step_ends(3, 4), saved_step_phi, saved_snap_theta, saved_snap_phi, saved_snap_ends(3, 4) REAL(wp) :: saved_drive_ends(3, 4), saved_drive_phi - LOGICAL :: saved_snap_valid, saved_drive_set + LOGICAL :: saved_snap_valid, saved_drive_set, saved_tw_active + REAL(wp), ALLOCATABLE :: saved_tw(:) INTEGER :: es, iend CHARACTER(1024) :: em ErrStat = CD_HCDYN_OK @@ -6865,8 +7428,14 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_Torsion(model, torsion, ErrStat, ErrMsg) RETURN END IF saved = model%torsion + saved_tw_active = model%tw_active + IF (saved_tw_active) THEN + ALLOCATE (saved_tw(tw_pack_size(model))) + CALL tw_pack(model, saved_tw) + END IF model%tors_c_valid = .FALSE. IF (.NOT. torsion%active) THEN + model%tw_active = .FALSE. model%torsion = CD_HermiteTorsionType() ELSE CALL CD_HermiteTorsion_Validate(torsion, model%l0, es, em) @@ -6908,10 +7477,12 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_Torsion(model, torsion, ErrStat, ErrMsg) model%tors_gk = CD_ZERO model%tors_zk = CD_ZERO model%tors_den = CD_ONE + model%tw_active = .FALSE. model%torsion = torsion model%tors_c_valid = .FALSE. CALL CD_HermiteCable_Dyn_Torsion_State(model, th, mt, es, em) IF (es /= CD_HCDYN_OK) THEN + CALL restore_twist() model%torsion = saved ErrStat = es ErrMsg = 'CD_HermiteCable_Dyn_Set_Torsion: '//TRIM(em) @@ -6919,6 +7490,17 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_Torsion(model, torsion, ErrStat, ErrMsg) END IF model%torsion%theta = th model%torsion%torque = mt + ! nodal twist dynamics when the torsion carries the polar rotary inertia + IF (ALLOCATED(torsion%irn)) THEN + CALL tw_init(model, mt, es, em) + IF (es /= CD_HCDYN_OK) THEN + CALL restore_twist() + model%torsion = saved + ErrStat = es + ErrMsg = 'CD_HermiteCable_Dyn_Set_Torsion: '//TRIM(em) + RETURN + END IF + END IF END IF saved_step_ends = model%tors_step_ends saved_step_phi = model%tors_step_phi @@ -6943,6 +7525,7 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_Torsion(model, torsion, ErrStat, ErrMsg) model%tr_valid = .FALSE. CALL CD_HermiteCable_Dyn_Recompute_Acceleration(model, es, em) IF (es /= CD_HCDYN_OK) THEN + CALL restore_twist() model%torsion = saved model%tors_c_valid = .FALSE. model%tors_step_ends = saved_step_ends @@ -6957,6 +7540,17 @@ SUBROUTINE CD_HermiteCable_Dyn_Set_Torsion(model, torsion, ErrStat, ErrMsg) ErrStat = es ErrMsg = 'CD_HermiteCable_Dyn_Set_Torsion: '//TRIM(em) END IF + + CONTAINS + + SUBROUTINE restore_twist() + !! The nodal twist as it was before the call (with the torsion description restored + !! after it, from which the derived rigid ends, held angles and inertia follow). + model%tw_active = saved_tw_active + IF (.NOT. saved_tw_active) RETURN + CALL tw_unpack(model, saved_tw) + CALL tw_set_derived(model, saved) + END SUBROUTINE restore_twist END SUBROUTINE CD_HermiteCable_Dyn_Set_Torsion SUBROUTINE CD_HermiteCable_Dyn_Torsion_State(model, theta, torque, ErrStat, ErrMsg, grad, end_grad, q_eval, & @@ -6986,6 +7580,14 @@ SUBROUTINE CD_HermiteCable_Dyn_Torsion_State(model, theta, torque, ErrStat, ErrM ErrStat = CD_HCDYN_OK ErrMsg = '' IF (.NOT. model%torsion%active) RETURN + ! Nodal twist: the committed Theta_eff and mean torque (the condensed kernel answers the + ! derivative queries, the quasi-static stiffness a static caller takes) + IF (model%tw_active .AND. .NOT. (PRESENT(grad) .OR. PRESENT(end_grad) .OR. PRESENT(q_eval) .OR. & + PRESENT(end_dr))) THEN + theta = model%torsion%theta + torque = model%torsion%torque + RETURN + END IF IF (.NOT. (PRESENT(grad) .OR. PRESENT(q_eval))) THEN IF (torsion_cache_matches(model)) THEN theta = model%tors_c_theta @@ -7131,6 +7733,11 @@ SUBROUTINE CD_HermiteCable_Dyn_Snapshot(model, ErrStat, ErrMsg) model%snap_torsion_theta = model%torsion%theta model%snap_torsion_phi = model%torsion%phi model%snap_torsion_ends = model%torsion%ends + IF (model%tw_active) THEN + IF (.NOT. ALLOCATED(model%snap_tw)) ALLOCATE (model%snap_tw(tw_pack_size(model)), model%snap_tw_fcR(model%nn)) + CALL tw_pack(model, model%snap_tw) + model%snap_tw_fcR = model%tw_fcR + END IF IF (model%fr_active) model%snap_fr_anchor = model%fr_anchor IF (model%has_viv) THEN model%snap_viv_phi = model%viv_phi @@ -7212,6 +7819,7 @@ SUBROUTINE CD_HermiteCable_Dyn_Restore(model, ErrStat, ErrMsg) CD_HermiteTorsion_Compliance(model%torsion, model%l0) model%tors_drive_set = .FALSE. model%tors_use_step = .FALSE. + IF (model%tw_active) CALL tw_unpack(model, model%snap_tw) IF (model%fr_active) model%fr_anchor = model%snap_fr_anchor IF (model%has_viv) THEN model%viv_phi = model%snap_viv_phi; model%viv_ms = model%snap_viv_ms @@ -7234,6 +7842,7 @@ SUBROUTINE CD_HermiteCable_Dyn_Restore(model, ErrStat, ErrMsg) ! the snapshot (the cache differs from a fresh evaluation in the last bits where a ! friction anchor slid). Otherwise the next step evaluates it afresh. IF (model%snap_fc_valid .AND. model%snap_fc_clears == model%fc_clears) THEN + IF (model%tw_active) model%tw_fcR = model%snap_tw_fcR model%fc_R = model%snap_fc_R model%fc_q = model%snap_fc_q model%fc_v = model%snap_fc_v @@ -7354,6 +7963,14 @@ SUBROUTINE CD_HermiteCable_Dyn_End(model) model%snap_torsion_theta = CD_ZERO model%snap_torsion_phi = CD_ZERO model%snap_torsion_ends = CD_ZERO + CALL tw_release(model) + model%tw_rigid = .FALSE. + model%tw_psi = CD_ZERO + model%tw_lg = CD_ZERO + model%tw_lk = CD_ZERO + model%tw_tsum = CD_ZERO + model%tw_spsi = CD_ZERO + model%tw_tscale = CD_ONE model%snap_valid = .FALSE. model%require_tensile = .FALSE. model%tensile_mode = CD_HCDYN_TENSILE_OFF @@ -7913,8 +8530,14 @@ SUBROUTINE assemble_residual(model, q_cfg, v_cfg, t_eval, want_residual, want_ta CALL asm_mark(HC_ASM_HELD, asm_t) ! Condensed torsion: R <- R - M_t dTheta/dq and Kb <- Kb - M_t d2Theta/dq2 at q_cfg (the - ! rank-one g g^T / C joins the solve by Sherman-Morrison; g is kept in tors_g). - IF (model%torsion%active .AND. (want_residual .OR. want_tangent)) THEN + ! rank-one g g^T / C joins the solve by Sherman-Morrison; g is kept in tors_g). Nodal + ! twist: the element torques and end springs (assemble_twist). + IF (model%tw_active .AND. (want_residual .OR. want_tangent)) THEN + CALL assemble_twist(model, q_cfg, v_cfg, want_residual, want_tangent, R, Kb, Kvb, es, em2) + IF (es /= CD_HCDYN_OK) THEN + ErrStat = es; ErrMsg = TRIM(em2); RETURN + END IF + ELSE IF (model%torsion%active .AND. (want_residual .OR. want_tangent)) THEN CALL assemble_torsion(model, q_cfg, want_residual, want_tangent, es, em2) IF (es /= CD_HCDYN_OK) THEN ErrStat = es; ErrMsg = TRIM(em2); RETURN @@ -7984,6 +8607,773 @@ SUBROUTINE assemble_torsion(model, q_cfg, want_residual, want_tangent, ErrStat, END IF END SUBROUTINE assemble_torsion + ! ------------------------------------------------------------------------------------------ + ! nodal twist (see the type note) + ! ------------------------------------------------------------------------------------------ + + PURE INTEGER FUNCTION tw_pack_size(model) RESULT(n) + !! Reals of the packed twist state of tw_pack: the angles, rates and accelerations, the + !! directors and unit tangents, the reference twists, the element torques and the two + !! end-frame references. + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + n = 9*model%nn + 2*model%ne + 2 + END FUNCTION tw_pack_size + + PURE SUBROUTINE tw_pack(model, buf) + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + REAL(wp), INTENT(OUT) :: buf(:) + INTEGER :: nn, ne + nn = model%nn + ne = model%ne + buf(1:nn) = model%tw_phi + buf(nn + 1:2*nn) = model%tw_w + buf(2*nn + 1:3*nn) = model%tw_al + buf(3*nn + 1:6*nn) = RESHAPE(model%tw_u, [3*nn]) + buf(6*nn + 1:9*nn) = RESHAPE(model%tw_tn, [3*nn]) + buf(9*nn + 1:9*nn + ne) = model%tw_beta + buf(9*nn + ne + 1:9*nn + 2*ne) = model%tw_mt + buf(9*nn + 2*ne + 1:9*nn + 2*ne + 2) = model%tw_psi + END SUBROUTINE tw_pack + + PURE SUBROUTINE tw_unpack(model, buf) + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + REAL(wp), INTENT(IN) :: buf(:) + INTEGER :: nn, ne + nn = model%nn + ne = model%ne + model%tw_phi = buf(1:nn) + model%tw_w = buf(nn + 1:2*nn) + model%tw_al = buf(2*nn + 1:3*nn) + model%tw_u = RESHAPE(buf(3*nn + 1:6*nn), [3, nn]) + model%tw_tn = RESHAPE(buf(6*nn + 1:9*nn), [3, nn]) + model%tw_beta = buf(9*nn + 1:9*nn + ne) + model%tw_mt = buf(9*nn + ne + 1:9*nn + 2*ne) + model%tw_psi = buf(9*nn + 2*ne + 1:9*nn + 2*ne + 2) + END SUBROUTINE tw_unpack + + ELEMENTAL REAL(wp) FUNCTION tw_wrap(x) RESULT(y) + !! x on (-pi, pi] (an angle change over one step; 0 stays exactly 0). + REAL(wp), INTENT(IN) :: x + y = x - 2.0_wp*CD_HTORS_PI*ANINT(x/(2.0_wp*CD_HTORS_PI)) + END FUNCTION tw_wrap + + PURE FUNCTION tw_cross(a, b) RESULT(c) + REAL(wp), INTENT(IN) :: a(3), b(3) + REAL(wp) :: c(3) + c = [a(2)*b(3) - a(3)*b(2), a(3)*b(1) - a(1)*b(3), a(1)*b(2) - a(2)*b(1)] + END FUNCTION tw_cross + + PURE SUBROUTINE tw_frames(model, ends, phi_end) + !! The end frames and Phi an evaluation takes: the running step's target, or the committed. + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + REAL(wp), INTENT(OUT) :: ends(3, 4), phi_end + IF (model%tors_use_step) THEN + ends = model%tors_step_ends + phi_end = model%tors_step_phi + ELSE + ends = model%torsion%ends + phi_end = model%torsion%phi + END IF + END SUBROUTINE tw_frames + + SUBROUTINE twist_reference(model, e, q_cfg, ends, want_hess, rho, beta, g, h, ErrStat, ErrMsg, end_w) + !! rho_e(q) of element e (the material twist is phi_{e+1} - phi_e + rho_e less the coupling + !! term), its gradient g and, with want_hess, Hessian h over the element's 12 DOFs, at q_cfg + !! with the end frames ends. beta is the reference-twist part: the committed tw_beta(e) plus + !! the change of the end-frame constant and of the transport solid angles since the + !! committed state, each formed as a difference so that the committed state and frames give + !! tw_beta(e) bit for bit. Interior element: beta = beta^n - Omega(a, b, c) - Omega(a, c, d), + !! a, d the committed and b, c the present unit node tangents. An element at a rigid end + !! takes the end frame's normal carried to its end node as that node's director (see + !! CD_HermiteTwist_Reference). end_w(:, k), when asked for, is d rho/d w_k for an incremental + !! rotation w_k of the end frame k (zero unless the element reaches a rigid end). + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + INTEGER, INTENT(IN) :: e + REAL(wp), INTENT(IN) :: q_cfg(:), ends(3, 4) + LOGICAL, INTENT(IN) :: want_hess + REAL(wp), INTENT(OUT) :: rho, beta, g(12), h(12, 12) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), INTENT(OUT), OPTIONAL :: end_w(3, 2) + REAL(wp) :: qe(12), tri(3, 3, 2), sg(2), fg(3, 3, 2), z(3), a(3), d(3), val, oref, cnow, cref + REAL(wp) :: he, ge(12), hk(12, 12), ls, gs(12), hs(12, 12), om, g9(9), cpl + REAL(wp) :: dA(3), nA(3), dB(3), nB(3), dAc(3), nAc(3), dBc(3), nBc(3) + INTEGER :: slot(3, 2), owner(3, 2), kind, es, k, j + CHARACTER(200) :: em + + rho = CD_ZERO + beta = CD_ZERO + g = CD_ZERO + h = CD_ZERO + IF (PRESENT(end_w)) end_w = CD_ZERO + ErrStat = CD_HCDYN_OK + ErrMsg = '' + qe = q_cfg(6*e - 5:6*e + 6) + a = model%tw_tn(:, e) + d = model%tw_tn(:, e + 1) + z = CD_ZERO + dA = ends(:, 1) + nA = ends(:, 2) + dB = ends(:, 3) + nB = ends(:, 4) + dAc = model%torsion%ends(:, 1) + nAc = model%torsion%ends(:, 2) + dBc = model%torsion%ends(:, 3) + nBc = model%torsion%ends(:, 4) + kind = 0 + IF (e == 1 .AND. model%tw_rigid(1)) kind = 1 + IF (e == model%ne .AND. model%tw_rigid(2)) kind = kind + 2 + cnow = CD_ZERO + cref = CD_ZERO + owner = 0 + sg = -CD_ONE + oref = CD_ZERO + SELECT CASE (kind) + CASE (0) + tri(:, :, 1) = RESHAPE([a, z, z], [3, 3]) + slot(:, 1) = [0, 1, 2] + tri(:, :, 2) = RESHAPE([a, z, d], [3, 3]) + slot(:, 2) = [0, 2, 0] + oref = oref + sg(1)*CD_HermiteTwist_Omega(a, a, d) + oref = oref + sg(2)*CD_HermiteTwist_Omega(a, d, d) + CASE (1) + ! node 1 director G(d_A -> t_1) n_A + tri(:, :, 1) = RESHAPE([dA, z, z], [3, 3]) + slot(:, 1) = [0, 1, 2] + owner(1, 1) = 1 + tri(:, :, 2) = RESHAPE([dA, z, d], [3, 3]) + slot(:, 2) = [0, 2, 0] + owner(1, 2) = 1 + oref = oref + sg(1)*CD_HermiteTwist_Omega(dAc, a, d) + oref = oref + sg(2)*CD_HermiteTwist_Omega(dAc, d, d) + cnow = CD_HermiteTwist_Angle(CD_HermiteTwist_Carry(dA, d, nA), model%tw_u(:, e + 1), d) + cref = CD_HermiteTwist_Angle(CD_HermiteTwist_Carry(dAc, d, nAc), model%tw_u(:, e + 1), d) + CASE (2) + ! last-node director G(d_B -> t_N) n_B + sg = [CD_ONE, -CD_ONE] + tri(:, :, 1) = RESHAPE([dB, z, a], [3, 3]) + slot(:, 1) = [0, 2, 0] + owner(1, 1) = 2 + tri(:, :, 2) = RESHAPE([a, z, z], [3, 3]) + slot(:, 2) = [0, 1, 2] + oref = oref + sg(1)*CD_HermiteTwist_Omega(dBc, d, a) + oref = oref + sg(2)*CD_HermiteTwist_Omega(a, a, d) + cnow = CD_HermiteTwist_Angle(model%tw_u(:, e), CD_HermiteTwist_Carry(dB, a, nB), a) + cref = CD_HermiteTwist_Angle(model%tw_u(:, e), CD_HermiteTwist_Carry(dBc, a, nBc), a) + CASE (3) + ! one element, rigid at both ends + sg = [CD_ONE, -CD_ONE] + tri(:, :, 1) = RESHAPE([dB, z, dA], [3, 3]) + slot(:, 1) = [0, 2, 0] + owner(1, 1) = 2 + owner(3, 1) = 1 + tri(:, :, 2) = RESHAPE([dA, z, z], [3, 3]) + slot(:, 2) = [0, 1, 2] + owner(1, 2) = 1 + oref = oref + sg(1)*CD_HermiteTwist_Omega(dBc, d, dAc) + oref = oref + sg(2)*CD_HermiteTwist_Omega(dAc, a, d) + cnow = CD_HermiteTwist_Angle(nA, CD_HermiteTwist_Carry(dB, dA, nB), dA) + cref = CD_HermiteTwist_Angle(nAc, CD_HermiteTwist_Carry(dBc, dAc, nBc), dAc) + END SELECT + IF (want_hess) THEN + CALL CD_HermiteTwist_Reference(qe, model%l0(e), tri, slot, sg, val, g, es, em, hess=h, holonomy=.FALSE., & + fixed_grad=fg) + ELSE + CALL CD_HermiteTwist_Reference(qe, model%l0(e), tri, slot, sg, val, g, es, em, holonomy=.FALSE., fixed_grad=fg) + END IF + IF (es /= CD_HTORS_OK) THEN + ErrStat = CD_HCDYN_NOCONVERGE + ErrMsg = 'twist: '//TRIM(em) + RETURN + END IF + ! the wrapped change of the end-frame constant is unique while the frame turns by less than + ! pi between two committed states; pi/2 keeps the margin of the condensed torsion + IF (ABS(tw_wrap(cnow - cref)) > CD_HTORS_MAX_STEP) THEN + ErrStat = CD_HCDYN_NOCONVERGE + ErrMsg = 'twist: an end frame turned by more than pi/2 about the line from its committed state' + RETURN + END IF + beta = model%tw_beta(e) + tw_wrap(cnow - cref) + (val - oref) + IF (want_hess) THEN + CALL CD_HermiteTorsion_Element(qe, model%l0(e), he, ge, es, em, hess=hk, & + quadrature_order=model%torsion%quadrature_order) + ELSE + CALL CD_HermiteTorsion_Element(qe, model%l0(e), he, ge, es, em, quadrature_order=model%torsion%quadrature_order) + END IF + IF (es /= CD_HTORS_OK) THEN + ErrStat = CD_HCDYN_NOCONVERGE + ErrMsg = 'twist: '//TRIM(em) + RETURN + END IF + rho = beta - he + g = g - ge + IF (want_hess) h = h - hk + cpl = CD_ZERO + IF (ALLOCATED(model%torsion%couple)) cpl = model%torsion%couple(e) + IF (ABS(cpl) > CD_ZERO) THEN + CALL CD_HermiteTorsion_Stretch_Derivatives(qe, model%l0(e), ls, gs, hs, model%torsion%quadrature_order) + rho = rho + cpl*(ls - model%l0(e)) + g = g + cpl*gs + IF (want_hess) h = h + cpl*hs + END IF + IF (PRESENT(end_w) .AND. kind > 0) THEN + ! fixed frame vertices turn with their frame: d Omega/d w = d x dOmega/dd + DO k = 1, 2 + DO j = 1, 3 + IF (owner(j, k) == 0) CYCLE + end_w(:, owner(j, k)) = end_w(:, owner(j, k)) + tw_cross(tri(:, j, k), fg(:, j, k)) + END DO + END DO + ! the end-frame constants (see the derivation in CD_HermiteCable_Dyn_EndConnection_Moment) + SELECT CASE (kind) + CASE (1) + CALL CD_HermiteTwist_Omega_Gradient(dA, dA, d, om, g9) + end_w(:, 1) = end_w(:, 1) - dA - tw_cross(dA, g9(4:6)) + CASE (2) + CALL CD_HermiteTwist_Omega_Gradient(dB, dB, a, om, g9) + end_w(:, 2) = end_w(:, 2) + dB + tw_cross(dB, g9(4:6)) + CASE (3) + CALL CD_HermiteTwist_Omega_Gradient(dB, dB, dA, om, g9) + end_w(:, 2) = end_w(:, 2) + dB + tw_cross(dB, g9(4:6)) + CALL CD_HermiteTwist_Omega_Gradient(dB, dA, dA, om, g9) + end_w(:, 1) = end_w(:, 1) - dA + tw_cross(dA, g9(4:6)) + END SELECT + END IF + END SUBROUTINE twist_reference + + SUBROUTINE twist_link(model, iend, q_cfg, ends, want_hess, psi, gl, hl, ErrStat, ErrMsg, end_w) + !! The end-frame reference psi of the elastic end iend: the angle about the end node's + !! tangent from its director to the end frame's normal carried to the node, psi = psi^n + + !! (change of angle(u^n -> G(d -> t^n) n)) + Omega(d, t, t^n) - Omega(d^n, t^n, t^n), with its + !! gradient gl and Hessian hl in the end node's tangent handle m, and, when asked for, + !! end_w = d psi/d w of an incremental rotation of the end frame. The end spring twists by + !! phi_1 - psi at end 1 and by psi + Phi - phi_N at end 2. + TYPE(CD_HermiteCableDynType), INTENT(IN) :: model + INTEGER, INTENT(IN) :: iend + REAL(wp), INTENT(IN) :: q_cfg(:), ends(3, 4) + LOGICAL, INTENT(IN) :: want_hess + REAL(wp), INTENT(OUT) :: psi, gl(3), hl(3, 3) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), INTENT(OUT), OPTIONAL :: end_w(3) + REAL(wp) :: qe(12), tri(3, 3, 1), fg(3, 3, 1), g12(12), h12(12, 12), z(3), a(3), u(3), dd(3), nd(3) + REAL(wp) :: dc(3), nc(3), val, oref, cnow, cref, om, g9(9) + INTEGER :: node, slot(3, 1), es + CHARACTER(200) :: em + psi = CD_ZERO + gl = CD_ZERO + hl = CD_ZERO + IF (PRESENT(end_w)) end_w = CD_ZERO + ErrStat = CD_HCDYN_OK + ErrMsg = '' + node = MERGE(1, model%nn, iend == 1) + qe = CD_ZERO + qe(4:6) = q_cfg(6*node - 2:6*node) + a = model%tw_tn(:, node) + u = model%tw_u(:, node) + z = CD_ZERO + dd = ends(:, 2*iend - 1) + nd = ends(:, 2*iend) + dc = model%torsion%ends(:, 2*iend - 1) + nc = model%torsion%ends(:, 2*iend) + tri(:, :, 1) = RESHAPE([dd, z, a], [3, 3]) + slot(:, 1) = [0, 1, 0] + oref = CD_ZERO + oref = oref + CD_ONE*CD_HermiteTwist_Omega(dc, a, a) + cnow = CD_HermiteTwist_Angle(u, CD_HermiteTwist_Carry(dd, a, nd), a) + cref = CD_HermiteTwist_Angle(u, CD_HermiteTwist_Carry(dc, a, nc), a) + IF (want_hess) THEN + CALL CD_HermiteTwist_Reference(qe, model%l0(1), tri, slot, [CD_ONE], val, g12, es, em, hess=h12, & + holonomy=.FALSE., fixed_grad=fg) + ELSE + CALL CD_HermiteTwist_Reference(qe, model%l0(1), tri, slot, [CD_ONE], val, g12, es, em, holonomy=.FALSE., & + fixed_grad=fg) + END IF + IF (es /= CD_HTORS_OK) THEN + ErrStat = CD_HCDYN_NOCONVERGE + ErrMsg = 'twist end link: '//TRIM(em) + RETURN + END IF + IF (ABS(tw_wrap(cnow - cref)) > CD_HTORS_MAX_STEP) THEN + ErrStat = CD_HCDYN_NOCONVERGE + ErrMsg = 'twist end link: the end frame turned by more than pi/2 about the line from its committed state' + RETURN + END IF + psi = model%tw_psi(iend) + tw_wrap(cnow - cref) + (val - oref) + gl = g12(4:6) + IF (want_hess) hl = h12(4:6, 4:6) + IF (PRESENT(end_w)) THEN + CALL CD_HermiteTwist_Omega_Gradient(dd, dd, a, om, g9) + end_w = dd + tw_cross(dd, g9(4:6)) + tw_cross(dd, fg(:, 1, 1)) + END IF + END SUBROUTINE twist_link + + SUBROUTINE assemble_twist(model, q_cfg, v_cfg, want_residual, want_tangent, R, Kb, Kvb, ErrStat, ErrMsg) + !! Nodal-twist part of assemble_residual: every element's torque M_e = (GJ/l0) tw_e + (Bt/l0) + !! d tw_e/dt (tw_e = phi_{e+1} - phi_e + rho_e(q), d/dt from the nodal rates and g . q_dot) + !! and every elastic end's spring, at q_cfg, v_cfg and the angles and rates of the running + !! step (tw_pe, tw_we) or of the committed state. R gains M_e drho_e/dq and tw_R the nodal + !! torques (want_residual); Kb gains M_e d2rho_e/dq2 + (GJ/l0) g g^T (+ the damping's + !! g (H q_dot)^T) and Kvb (Bt/l0) g g^T, and the coupling to the angles is kept per element + !! for the solve (tw_eg, tw_ehv, tw_ek, tw_ed, tw_lg, tw_lk; want_tangent). tw_me holds the + !! element torques and tw_tsum the summed twist. + TYPE(CD_HermiteCableDynType), INTENT(INOUT), TARGET :: model + REAL(wp), INTENT(IN) :: q_cfg(:), v_cfg(:) + LOGICAL, INTENT(IN) :: want_residual, want_tangent + REAL(wp), INTENT(INOUT) :: R(:), Kb(:, :), Kvb(:, :) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), POINTER :: phi(:), w(:) + REAL(wp) :: ends(3, 4), phi_end, rho, beta, g(12), h(12, 12), ve(12), hv(12), ke(12, 12), kel, kd + REAL(wp) :: tau, rate, mt, psi, gl(3), hl(3, 3), k, tw + INTEGER :: e, iend, node, b, i, j, es + CHARACTER(1024) :: em + + ErrStat = CD_HCDYN_OK + ErrMsg = '' + CALL tw_frames(model, ends, phi_end) + IF (model%tors_use_step) THEN + phi => model%tw_pe + w => model%tw_we + ELSE + phi => model%tw_phi + w => model%tw_w + END IF + IF (want_residual) model%tw_R = CD_ZERO + model%tw_tsum = CD_ZERO + DO e = 1, model%ne + CALL twist_reference(model, e, q_cfg, ends, want_tangent, rho, beta, g, h, es, em) + IF (es /= CD_HCDYN_OK) THEN + ErrStat = es + ErrMsg = TRIM(em) + RETURN + END IF + ve = v_cfg(6*e - 5:6*e + 6) + kel = model%torsion%gj(e)/model%l0(e) + kd = CD_ZERO + IF (ALLOCATED(model%torsion%bt)) kd = model%torsion%bt(e)/model%l0(e) + tau = phi(e + 1) - phi(e) + rho + rate = w(e + 1) - w(e) + DOT_PRODUCT(g, ve) + mt = kel*tau + kd*rate + model%tw_me(e) = mt + model%tw_tsum = model%tw_tsum + tau + IF (want_residual) THEN + R(6*e - 5:6*e + 6) = R(6*e - 5:6*e + 6) + mt*g + model%tw_R(e) = model%tw_R(e) - mt + model%tw_R(e + 1) = model%tw_R(e + 1) + mt + END IF + IF (want_tangent) THEN + hv = CD_ZERO + IF (kd > CD_ZERO) hv = MATMUL(h, ve) + DO j = 1, 12 + DO i = 1, 12 + ke(i, j) = mt*h(i, j) + kel*g(i)*g(j) + kd*g(i)*hv(j) + END DO + END DO + CALL scatter12_band(Kb, ke, e) + IF (kd > CD_ZERO) THEN + DO j = 1, 12 + DO i = 1, 12 + ke(i, j) = kd*g(i)*g(j) + END DO + END DO + CALL scatter12_band(Kvb, ke, e) + END IF + model%tw_eg(:, e) = g + model%tw_ehv(:, e) = hv + model%tw_ek(e) = kel + model%tw_ed(e) = kd + END IF + END DO + IF (want_tangent) THEN + model%tw_lg = CD_ZERO + model%tw_lk = CD_ZERO + END IF + DO iend = 1, 2 + IF (model%tw_rigid(iend)) CYCLE + CALL twist_link(model, iend, q_cfg, ends, want_tangent, psi, gl, hl, es, em) + IF (es /= CD_HCDYN_OK) THEN + ErrStat = es + ErrMsg = TRIM(em) + RETURN + END IF + k = CD_ONE/model%torsion%end_compliance(iend) + node = MERGE(1, model%nn, iend == 1) + b = 6*node - 3 + IF (iend == 1) THEN + tw = phi(1) - psi + ELSE + tw = psi + phi_end - phi(model%nn) + END IF + mt = k*tw + model%tw_tsum = model%tw_tsum + tw + IF (want_residual) THEN + IF (iend == 1) THEN + R(b + 1:b + 3) = R(b + 1:b + 3) - mt*gl + model%tw_R(1) = model%tw_R(1) + mt + ELSE + R(b + 1:b + 3) = R(b + 1:b + 3) + mt*gl + model%tw_R(model%nn) = model%tw_R(model%nn) - mt + END IF + END IF + IF (want_tangent) THEN + DO j = 1, 3 + DO i = 1, 3 + Kb(KL_D + KU_D + 1 + i - j, b + j) = Kb(KL_D + KU_D + 1 + i - j, b + j) + k*gl(i)*gl(j) + & + MERGE(-mt, mt, iend == 1)*hl(i, j) + END DO + END DO + model%tw_lg(:, iend) = gl + model%tw_lk(iend) = k + END IF + END DO + END SUBROUTINE assemble_twist + + SUBROUTINE tw_build_K7(model, cm, ck, cv, bases, ErrStat, ErrMsg) + !! The effective tangent of the nodal-twist step in 7-DOF-per-node order ([r, m, phi] per + !! node, KL = KU = 13) from the cable's ws_Keffb (already in the rigid-end basis, Dirichlet + !! applied) and the twist data of the last tangent assembly: cm M + ck K + cv Kv for the + !! angles' lumped inertia, stiffness and damping and their coupling to q (the q rows and + !! columns of a rigid end in its basis, those of fixed DOFs and of held angles zeroed). + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + REAL(wp), INTENT(IN) :: cm, ck, cv, bases(3, 3, 2) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER :: i6, j6, i7, j7, e, a, gi, p, iend, node, b + REAL(wp) :: colv(12), rowv(12), d, kl3(3) + ErrStat = CD_HCDYN_OK + ErrMsg = '' + model%tw_K7 = CD_ZERO + DO j6 = 1, model%ndof + j7 = j6 + (j6 - 1)/6 + DO i6 = MAX(1, j6 - KU_D), MIN(model%ndof, j6 + KL_D) + i7 = i6 + (i6 - 1)/6 + model%tw_K7(2*KB7 + 1 + i7 - j7, j7) = model%ws_Keffb(KL_D + KU_D + 1 + i6 - j6, j6) + END DO + END DO + DO e = 1, model%ne + ! q rows of the angle columns, (ck GJ/l0 + cv Bt/l0) g, and angle rows of the q columns, + ! ck (GJ/l0 g + Bt/l0 H q_dot) + cv Bt/l0 g; both + at phi_{e+1} and - at phi_e + colv = (ck*model%tw_ek(e) + cv*model%tw_ed(e))*model%tw_eg(:, e) + rowv = ck*(model%tw_ek(e)*model%tw_eg(:, e) + model%tw_ed(e)*model%tw_ehv(:, e)) + & + cv*model%tw_ed(e)*model%tw_eg(:, e) + IF (e == 1) CALL rigid_local(1, colv(4:6), rowv(4:6)) + IF (e == model%ne) CALL rigid_local(2, colv(10:12), rowv(10:12)) + d = ck*model%tw_ek(e) + cv*model%tw_ed(e) + DO a = 1, 12 + gi = elem_gdof(e, a) + IF (.NOT. model%solve_mask(gi)) CYCLE + DO p = e, e + 1 + IF (.NOT. model%tw_free(p)) CYCLE + CALL add7(gi + (gi - 1)/6, 7*p, MERGE(colv(a), -colv(a), p == e + 1)) + CALL add7(7*p, gi + (gi - 1)/6, MERGE(rowv(a), -rowv(a), p == e + 1)) + END DO + END DO + DO p = e, e + 1 + IF (.NOT. model%tw_free(p)) CYCLE + DO i6 = e, e + 1 + IF (.NOT. model%tw_free(i6)) CYCLE + CALL add7(7*p, 7*i6, MERGE(d, -d, p == i6)) + END DO + END DO + END DO + DO iend = 1, 2 + IF (.NOT. model%tw_lk(iend) > CD_ZERO) CYCLE + node = MERGE(1, model%nn, iend == 1) + IF (.NOT. model%tw_free(node)) CYCLE + kl3 = -ck*model%tw_lk(iend)*model%tw_lg(:, iend) + colv(1:3) = kl3 + rowv(1:3) = kl3 + CALL rigid_local(iend, colv(1:3), rowv(1:3)) + b = 6*node - 3 + DO a = 1, 3 + gi = b + a + IF (.NOT. model%solve_mask(gi)) CYCLE + CALL add7(gi + (gi - 1)/6, 7*node, colv(a)) + CALL add7(7*node, gi + (gi - 1)/6, rowv(a)) + END DO + CALL add7(7*node, 7*node, ck*model%tw_lk(iend)) + END DO + DO p = 1, model%nn + IF (model%tw_free(p)) THEN + CALL add7(7*p, 7*p, cm*model%tw_mass(p)) + ELSE + model%tw_K7(2*KB7 + 1, 7*p) = CD_ONE + END IF + END DO + ! column by column (a reshaped copy would be a heap temporary) + DO p = 1, SIZE(model%tw_K7, 2) + IF (.NOT. CD_All_Finite(model%tw_K7(:, p))) THEN + ErrStat = CD_HCDYN_NOCONVERGE + ErrMsg = 'twist: non-finite effective tangent' + RETURN + END IF + END DO + CONTAINS + SUBROUTINE add7(r7, c7, val) + INTEGER, INTENT(IN) :: r7, c7 + REAL(wp), INTENT(IN) :: val + model%tw_K7(2*KB7 + 1 + r7 - c7, c7) = model%tw_K7(2*KB7 + 1 + r7 - c7, c7) + val + END SUBROUTINE add7 + SUBROUTINE rigid_local(iend_l, cv3, rv3) + !! The tangent-DOF entries of a rigid end in its basis (as transform_rigid_band). + INTEGER, INTENT(IN) :: iend_l + REAL(wp), INTENT(INOUT) :: cv3(3), rv3(3) + IF (model%endconn_mode(iend_l) /= CD_ENDCONN_RIGID) RETURN + cv3 = MATMUL(TRANSPOSE(bases(:, :, iend_l)), cv3) + rv3 = MATMUL(rv3, bases(:, :, iend_l)) + END SUBROUTINE rigid_local + END SUBROUTINE tw_build_K7 + + SUBROUTINE tw_solve(model, ErrStat, ErrMsg) + !! Solve the factored tw_K7 for the direction [ws_dq, tw_dp] (right-hand sides on entry, + !! the solution on return). + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER :: i + DO i = 1, model%ndof + model%tw_x7(i + (i - 1)/6) = model%ws_dq(i) + END DO + DO i = 1, model%nn + model%tw_x7(7*i) = model%tw_dp(i) + END DO + CALL CD_Solve_Factored_Banded(model%tw_K7, KB7, KB7, model%tw_ipiv, model%tw_x7, ErrStat, ErrMsg, & + factor_validated=.TRUE.) + IF (ErrStat /= CD_LINALG_OK) RETURN + DO i = 1, model%ndof + model%ws_dq(i) = model%tw_x7(i + (i - 1)/6) + END DO + DO i = 1, model%nn + model%tw_dp(i) = model%tw_x7(7*i) + END DO + END SUBROUTINE tw_solve + + SUBROUTINE tw_init(model, mt, ErrStat, ErrMsg) + !! Install the nodal twist of the committed configuration under the uniform torque mt (the + !! condensed torque of the static state): directors carried along the line from the End-1 + !! frame (each element's own transport, so every interior reference twist is the element + !! holonomy), angles accumulated from the element twists mt l0/GJ - rho_e and the end + !! compliances, rates zero. A rigid end 2 holds phi = Phi: the last element's reference + !! twist takes the multiple of 2 pi the accumulated angle needs, as an elastic end 2's psi + !! does; a remainder above STATE_TOL (a static state off equilibrium) fails closed. + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + REAL(wp), INTENT(IN) :: mt + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), PARAMETER :: STATE_TOL = 1.0e-6_wp + INTEGER :: nn, ne, i, e, es + REAL(wp) :: v(3), t(3), he, ge(12), qe(12), rho, beta, g(12), h(12, 12), diff, kk, ends(3, 4), phi_end, psi + REAL(wp) :: tol + CHARACTER(200) :: em + CHARACTER(1024) :: em2 + ErrStat = CD_HCDYN_OK + ErrMsg = '' + nn = model%nn + ne = model%ne + IF (ALLOCATED(model%tw_phi)) THEN + IF (SIZE(model%tw_phi) /= nn) CALL tw_release(model) + END IF + IF (.NOT. ALLOCATED(model%tw_phi)) THEN + ALLOCATE (model%tw_phi(nn), model%tw_w(nn), model%tw_al(nn), model%tw_mass(nn), model%tw_u(3, nn), & + model%tw_tn(3, nn), model%tw_beta(ne), model%tw_mt(ne), model%tw_free(nn)) + ALLOCATE (model%tw_pn(nn), model%tw_wn(nn), model%tw_an(nn), model%tw_pk(nn), model%tw_wk(nn), & + model%tw_ak(nn), model%tw_ptrial(nn), model%tw_dp(nn), model%tw_G(nn), model%tw_Gt(nn), & + model%tw_Rk(nn), model%tw_Rt(nn), model%tw_R(nn), model%tw_fcR(nn), model%tw_pe(nn), & + model%tw_we(nn)) + ALLOCATE (model%tw_eg(12, ne), model%tw_ehv(12, ne), model%tw_ek(ne), model%tw_ed(ne), model%tw_me(ne)) + ALLOCATE (model%tw_K7(3*KB7 + 1, 7*nn), model%tw_x7(7*nn), model%tw_ipiv(7*nn)) + ALLOCATE (model%tw_su(3, nn), model%tw_stn(3, nn), model%tw_sbeta(ne)) + ALLOCATE (model%ws_recovery_tw(tw_pack_size(model))) + END IF + model%tw_pn = CD_ZERO; model%tw_wn = CD_ZERO; model%tw_an = CD_ZERO; model%tw_pk = CD_ZERO + model%tw_wk = CD_ZERO; model%tw_ak = CD_ZERO; model%tw_ptrial = CD_ZERO; model%tw_dp = CD_ZERO + model%tw_G = CD_ZERO; model%tw_Gt = CD_ZERO; model%tw_Rk = CD_ZERO; model%tw_Rt = CD_ZERO + model%tw_R = CD_ZERO; model%tw_fcR = CD_ZERO; model%tw_eg = CD_ZERO; model%tw_ehv = CD_ZERO + model%tw_ek = CD_ZERO; model%tw_ed = CD_ZERO; model%tw_me = CD_ZERO + CALL tw_set_derived(model, model%torsion) + DO i = 1, nn + model%tw_tn(:, i) = model%q(6*i - 2:6*i)/NORM2(model%q(6*i - 2:6*i)) + END DO + ends = model%torsion%ends + phi_end = model%torsion%phi + model%tw_u(:, 1) = unit_perp(CD_HermiteTwist_Carry(ends(:, 1), model%tw_tn(:, 1), ends(:, 2)), model%tw_tn(:, 1)) + DO e = 1, ne + qe = model%q(6*e - 5:6*e + 6) + CALL CD_HermiteTorsion_Element(qe, model%l0(e), he, ge, es, em, quadrature_order=model%torsion%quadrature_order) + IF (es /= CD_HTORS_OK) THEN + ErrStat = CD_HCDYN_BADINPUT + ErrMsg = 'twist: '//TRIM(em) + RETURN + END IF + t = model%tw_tn(:, e + 1) + v = CD_HermiteTwist_Carry(model%tw_tn(:, e), t, model%tw_u(:, e)) + model%tw_u(:, e + 1) = unit_perp(COS(he)*v + SIN(he)*tw_cross(t, v), t) + END DO + IF (model%tw_rigid(2)) model%tw_u(:, nn) = unit_perp(CD_HermiteTwist_Carry(ends(:, 3), model%tw_tn(:, nn), & + ends(:, 4)), model%tw_tn(:, nn)) + DO e = 1, ne + model%tw_beta(e) = CD_HermiteTwist_Angle(CD_HermiteTwist_Carry(model%tw_tn(:, e), model%tw_tn(:, e + 1), & + model%tw_u(:, e)), model%tw_u(:, e + 1), & + model%tw_tn(:, e + 1)) + END DO + ! a rigid end's element takes its end-frame constant in tw_beta: its formula at the + ! committed state is tw_beta itself, so take the director angle of the gauge directly + model%tw_psi = CD_ZERO + IF (.NOT. model%tw_rigid(1)) model%tw_psi(1) = CD_HermiteTwist_Angle(model%tw_u(:, 1), & + CD_HermiteTwist_Carry(ends(:, 1), & + model%tw_tn(:, 1), & + ends(:, 2)), & + model%tw_tn(:, 1)) + ! angles from the uniform torque + tol = STATE_TOL*MAX(CD_ONE, ABS(phi_end)) + model%tw_phi = CD_ZERO + IF (.NOT. model%tw_rigid(1)) model%tw_phi(1) = mt*model%torsion%end_compliance(1) + model%tw_psi(1) + model%tors_use_step = .FALSE. + DO e = 1, ne + CALL twist_reference(model, e, model%q, ends, .FALSE., rho, beta, g, h, es, em2) + IF (es /= CD_HCDYN_OK) THEN + ErrStat = CD_HCDYN_BADINPUT + ErrMsg = TRIM(em2) + RETURN + END IF + model%tw_phi(e + 1) = model%tw_phi(e) + mt*model%l0(e)/model%torsion%gj(e) - rho + IF (e == ne .AND. model%tw_rigid(2)) THEN + diff = model%tw_phi(nn) - phi_end + kk = ANINT(diff/(2.0_wp*CD_HTORS_PI)) + IF (ABS(diff - 2.0_wp*CD_HTORS_PI*kk) > tol) THEN + ErrStat = CD_HCDYN_BADINPUT + WRITE (ErrMsg, '(A,ES10.3,A)') 'twist: the static torsion state misses the End-2 twist by ', & + ABS(diff - 2.0_wp*CD_HTORS_PI*kk), ' rad (solve the statics with torsion first)' + RETURN + END IF + model%tw_beta(ne) = model%tw_beta(ne) + diff + model%tw_phi(nn) = phi_end + END IF + END DO + IF (.NOT. model%tw_rigid(2)) THEN + ! the End-2 spring: its psi at the committed state is the director angle itself, on the + ! branch that puts the static end twist mt/k_2 on it + psi = CD_HermiteTwist_Angle(model%tw_u(:, nn), CD_HermiteTwist_Carry(ends(:, 3), model%tw_tn(:, nn), & + ends(:, 4)), model%tw_tn(:, nn)) + diff = mt*model%torsion%end_compliance(2) - (psi + phi_end - model%tw_phi(nn)) + kk = ANINT(diff/(2.0_wp*CD_HTORS_PI)) + IF (ABS(diff - 2.0_wp*CD_HTORS_PI*kk) > tol) THEN + ErrStat = CD_HCDYN_BADINPUT + WRITE (ErrMsg, '(A,ES10.3,A)') 'twist: the static torsion state misses the End-2 spring twist by ', & + ABS(diff - 2.0_wp*CD_HTORS_PI*kk), ' rad (solve the statics with torsion first)' + RETURN + END IF + model%tw_psi(2) = psi + diff + END IF + model%tw_w = CD_ZERO + model%tw_al = CD_ZERO + model%tw_mt = mt + model%tw_active = .TRUE. + CONTAINS + PURE FUNCTION unit_perp(x, ax) RESULT(y) + REAL(wp), INTENT(IN) :: x(3), ax(3) + REAL(wp) :: y(3) + y = x - DOT_PRODUCT(x, ax)*ax + y = y/NORM2(y) + END FUNCTION unit_perp + END SUBROUTINE tw_init + + SUBROUTINE tw_set_derived(model, tors) + !! The rigid ends, held angles and lumped polar inertia (half of each adjacent element's + !! Irn l0) the torsion description tors gives. + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + TYPE(CD_HermiteTorsionType), INTENT(IN) :: tors + INTEGER :: e + model%tw_rigid = .NOT. (tors%end_compliance > CD_ZERO) + model%tw_free = .TRUE. + IF (model%tw_rigid(1)) model%tw_free(1) = .FALSE. + IF (model%tw_rigid(2)) model%tw_free(model%nn) = .FALSE. + model%tw_mass = CD_ZERO + DO e = 1, model%ne + model%tw_mass(e) = model%tw_mass(e) + 0.5_wp*tors%irn(e)*model%l0(e) + model%tw_mass(e + 1) = model%tw_mass(e + 1) + 0.5_wp*tors%irn(e)*model%l0(e) + END DO + END SUBROUTINE tw_set_derived + + SUBROUTINE tw_settle_committed(model) + !! After an evaluation of the committed state (solve_consistent_acceleration): the angles' + !! accelerations staged in tw_ak, the element torques, and the condensed view Theta_eff = + !! Phi - summed twist with its mean torque (Phi - Theta_eff)/C. + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + model%tw_al = model%tw_ak + model%tw_mt = model%tw_me + model%torsion%theta = model%torsion%phi - model%tw_tsum + model%torsion%torque = model%tw_tsum/CD_HermiteTorsion_Compliance(model%torsion, model%l0) + END SUBROUTINE tw_settle_committed + + SUBROUTINE tw_release(model) + !! Deallocate the nodal-twist state and scratch. + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + model%tw_active = .FALSE. + IF (ALLOCATED(model%tw_phi)) DEALLOCATE (model%tw_phi, model%tw_w, model%tw_al, model%tw_mass, model%tw_u, & + model%tw_tn, model%tw_beta, model%tw_mt, model%tw_free) + IF (ALLOCATED(model%tw_pn)) DEALLOCATE (model%tw_pn, model%tw_wn, model%tw_an, model%tw_pk, model%tw_wk, & + model%tw_ak, model%tw_ptrial, model%tw_dp, model%tw_G, model%tw_Gt, & + model%tw_Rk, model%tw_Rt, model%tw_R, model%tw_fcR, model%tw_pe, & + model%tw_we) + IF (ALLOCATED(model%tw_eg)) DEALLOCATE (model%tw_eg, model%tw_ehv, model%tw_ek, model%tw_ed, model%tw_me) + IF (ALLOCATED(model%tw_K7)) DEALLOCATE (model%tw_K7, model%tw_x7, model%tw_ipiv) + IF (ALLOCATED(model%tw_su)) DEALLOCATE (model%tw_su, model%tw_stn, model%tw_sbeta) + IF (ALLOCATED(model%ws_recovery_tw)) DEALLOCATE (model%ws_recovery_tw) + IF (ALLOCATED(model%snap_tw)) DEALLOCATE (model%snap_tw) + IF (ALLOCATED(model%snap_tw_fcR)) DEALLOCATE (model%snap_tw_fcR) + END SUBROUTINE tw_release + + SUBROUTINE tw_advance_reference(model, q_new, ends_new, ErrStat, ErrMsg) + !! The twist reference at q_new with the frames ends_new, into the commit scratch: the + !! reference twists and end-frame references (the step's own formulas, so the committed + !! state reproduces the converged iterate bit for bit), the unit tangents and the directors + !! carried over by the smallest rotation (a rigid end's: its end frame's normal carried). + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + REAL(wp), INTENT(IN) :: q_new(:), ends_new(3, 4) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER :: e, i, iend + REAL(wp) :: rho, beta, g(12), h(12, 12), psi, gl(3), hl(3, 3), u(3), t(3) + ErrStat = CD_HCDYN_OK + ErrMsg = '' + DO e = 1, model%ne + CALL twist_reference(model, e, q_new, ends_new, .FALSE., rho, beta, g, h, ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) RETURN + model%tw_sbeta(e) = beta + END DO + model%tw_spsi = model%tw_psi + DO iend = 1, 2 + IF (model%tw_rigid(iend)) CYCLE + CALL twist_link(model, iend, q_new, ends_new, .FALSE., psi, gl, hl, ErrStat, ErrMsg) + IF (ErrStat /= CD_HCDYN_OK) RETURN + model%tw_spsi(iend) = psi + END DO + DO i = 1, model%nn + t = q_new(6*i - 2:6*i)/NORM2(q_new(6*i - 2:6*i)) + model%tw_stn(:, i) = t + IF (i == 1 .AND. model%tw_rigid(1)) THEN + u = CD_HermiteTwist_Carry(ends_new(:, 1), t, ends_new(:, 2)) + ELSE IF (i == model%nn .AND. model%tw_rigid(2)) THEN + u = CD_HermiteTwist_Carry(ends_new(:, 3), t, ends_new(:, 4)) + ELSE + u = CD_HermiteTwist_Carry(model%tw_tn(:, i), t, model%tw_u(:, i)) + END IF + u = u - DOT_PRODUCT(u, t)*t + model%tw_su(:, i) = u/NORM2(u) + END DO + END SUBROUTINE tw_advance_reference + + SUBROUTINE tw_commit_reference(model) + !! Make the reference state of tw_advance_reference the committed one. + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + model%tw_beta = model%tw_sbeta + model%tw_psi = model%tw_spsi + model%tw_tn = model%tw_stn + model%tw_u = model%tw_su + END SUBROUTINE tw_commit_reference + SUBROUTINE add_endconn_band(R, Kb, q_cfg, node, k_rot, d0, want_residual, want_tangent, & ErrStat, ErrMsg) !! Scatter one rotational end connection into the dynamic residual and band tangent. @@ -9511,6 +10901,14 @@ SUBROUTINE solve_consistent_acceleration(model, ErrStat, ErrMsg, pres_dofs, pres IF (es /= CD_HCDYN_OK) THEN ErrStat = es; ErrMsg = 'solve_consistent_acceleration: '//TRIM(em2); RETURN END IF + ! Nodal twist: the angles' accelerations from their lumped inertia (a held angle keeps its + ! own), installed with the cable's at the end. + IF (model%tw_active) THEN + DO i = 1, model%nn + model%tw_ak(i) = model%tw_al(i) + IF (model%tw_free(i)) model%tw_ak(i) = -model%tw_R(i)/model%tw_mass(i) + END DO + END IF ! Total mass = structural + added (the added-mass matrix at the current configuration). model%ws_Msumb = model%Mgb IF (model%has_am) THEN @@ -9542,6 +10940,7 @@ SUBROUTINE solve_consistent_acceleration(model, ErrStat, ErrMsg, pres_dofs, pres END DO IF (nf == 0) THEN model%a = model%ws_an + IF (model%tw_active) CALL tw_settle_committed(model) RETURN END IF ! In-band Dirichlet on a mass copy + full-size banded solve. The free RHS is @@ -9565,6 +10964,7 @@ SUBROUTINE solve_consistent_acceleration(model, ErrStat, ErrMsg, pres_dofs, pres CALL transform_rigid_vector_to_global(model, rigid_basis, model%ws_dq) model%a = model%ws_dq + model%ws_an IF (has_pres) model%a(pres_dofs) = pres_a + IF (model%tw_active) CALL tw_settle_committed(model) END SUBROUTINE solve_consistent_acceleration SUBROUTINE scatter12_band(abg, Ke, e) diff --git a/src/CableDyn_HermiteTorsion.f90 b/src/CableDyn_HermiteTorsion.f90 index 35de7d21..75743309 100644 --- a/src/CableDyn_HermiteTorsion.f90 +++ b/src/CableDyn_HermiteTorsion.f90 @@ -56,6 +56,12 @@ MODULE CableDyn_HermiteTorsion PUBLIC :: CD_HermiteTorsion_Work_Init PUBLIC :: CD_HermiteTorsion_Work_End PUBLIC :: CD_HermiteTorsion_Work_Add_Hessian + PUBLIC :: CD_HermiteTwist_Reference + PUBLIC :: CD_HermiteTwist_Carry + PUBLIC :: CD_HermiteTwist_Angle + PUBLIC :: CD_HermiteTwist_Omega + PUBLIC :: CD_HermiteTwist_Omega_Gradient + PUBLIC :: CD_HermiteTorsion_Stretch_Derivatives INTEGER, PARAMETER, PUBLIC :: CD_HTORS_OK = 0 INTEGER, PARAMETER, PUBLIC :: CD_HTORS_BADINPUT = 1 @@ -109,6 +115,11 @@ MODULE CableDyn_HermiteTorsion !! unallocated: no coupling. The line's axial stiffness is then EA - K^2/GJ (the stretch !! twists the line) and its twist Theta less sum (K/GJ)(l - l0) (CD_HermiteTorsion_Line). REAL(wp), ALLOCATABLE :: couple(:) + !! Nodal-twist dynamics (CableDyn_HermiteCableDynamic): the polar rotary inertia Irn + !! [kg m^2/m] of every element and, optionally, its internal torsional damping Bt [N m^2 s] + !! (torque Bt d tau/dt). With irn unallocated the dynamics keeps the condensed, quasi-static + !! torsion; the statics never read them. + REAL(wp), ALLOCATABLE :: irn(:), bt(:) INTEGER :: quadrature_order = 4 !! State: the accepted Theta (unwrapped) once has_theta; before that theta_hint selects the !! 2 pi branch of the first evaluation (0 for an untwisted start). @@ -200,6 +211,40 @@ PURE SUBROUTINE CD_HermiteTorsion_Validate(tors, l0, ErrStat, ErrMsg) RETURN END IF END IF + IF (ALLOCATED(tors%irn)) THEN + IF (SIZE(tors%irn) /= SIZE(l0)) THEN + ErrMsg = 'torsion: the polar rotary inertia must have one entry per element' + RETURN + END IF + IF (.NOT. CD_All_Finite(tors%irn)) THEN + ErrStat = CD_HTORS_NONFINITE + ErrMsg = 'torsion: non-finite polar rotary inertia' + RETURN + END IF + IF (ANY(.NOT. (tors%irn > CD_ZERO))) THEN + ErrMsg = 'torsion: the polar rotary inertia must be positive on every element' + RETURN + END IF + END IF + IF (ALLOCATED(tors%bt)) THEN + IF (.NOT. ALLOCATED(tors%irn)) THEN + ErrMsg = 'torsion: torsional damping needs the polar rotary inertia (nodal twist)' + RETURN + END IF + IF (SIZE(tors%bt) /= SIZE(l0)) THEN + ErrMsg = 'torsion: the torsional damping must have one entry per element' + RETURN + END IF + IF (.NOT. CD_All_Finite(tors%bt)) THEN + ErrStat = CD_HTORS_NONFINITE + ErrMsg = 'torsion: non-finite torsional damping' + RETURN + END IF + IF (ANY(tors%bt < CD_ZERO)) THEN + ErrMsg = 'torsion: the torsional damping must be non-negative' + RETURN + END IF + END IF IF (ANY(tors%end_compliance < CD_ZERO)) THEN ErrMsg = 'torsion: end compliances must be non-negative' RETURN @@ -1253,6 +1298,232 @@ PURE SUBROUTINE CD_HermiteTorsion_Accept(theta_prev, theta_raw, theta_new, ErrSt ErrMsg = '' END SUBROUTINE CD_HermiteTorsion_Accept + ! ------------------------------------------------------------------------------------------ + ! nodal twist: reference twist of the time-parallel-transported directors + ! ------------------------------------------------------------------------------------------ + + PURE SUBROUTINE CD_HermiteTwist_Reference(qe, L, tri, tslot, tsign, value, grad, ErrStat, ErrMsg, hess, & + holonomy, fixed_grad, quadrature_order) + !! The reference twist of the nodal-twist model on one element [r1, m1, r2, m2] of reference + !! length L: value = sum_k tsign_k Omega(x_k, y_k, z_k) - h_e (h_e, the element holonomy, only + !! when holonomy, the default), with its gradient and optionally its Hessian over the 12 DOFs. + !! Each triangle k takes its vertices from tri(:, j, k) where tslot(j, k) = 0 (a vector fixed + !! over the step: a committed node tangent or an end director), the unit node-1 tangent + !! b = m1/|m1| where tslot(j, k) = 1 and the unit node-2 tangent c = m2/|m2| where it is 2. + !! A caller adds the step constant (the committed reference twist). fixed_grad(:, j, k) is the + !! gradient in the raw fixed vertex tri(:, j, k) (zero for a node-tangent vertex). + !! + !! An interior element with committed unit tangents a, d and committed reference twist beta^n + !! has the reference twist beta^n - Omega(a, b, c) - Omega(a, c, d) - h_e: its directors are the + !! committed ones carried by the smallest rotation from a to b and from d to c, and the + !! transport around the quadrilateral a, b, c, d turns a vector by its solid angle. A routine + !! of a single node passes no node-2 vertex and holonomy = .FALSE.; then only qe(4:6) is read. + !! Every triangle edge must satisfy 1 + x . y >= CD_HTORS_FOLD_MIN (else CD_HTORS_FOLD). + REAL(wp), INTENT(IN) :: qe(12), L, tri(:, :, :), tsign(:) + INTEGER, INTENT(IN) :: tslot(:, :) + REAL(wp), INTENT(OUT) :: value, grad(12) + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + REAL(wp), INTENT(OUT), OPTIONAL :: hess(12, 12), fixed_grad(:, :, :) + LOGICAL, INTENT(IN), OPTIONAL :: holonomy + INTEGER, INTENT(IN), OPTIONAL :: quadrature_order + INTEGER :: order, k, j, i, ntri, si, sj + LOGICAL :: want_hess, with_h, need(2), finite + REAL(wp) :: node_t(3, 2), proj(3, 3, 2), x(3, 3), om, g9(9), h9(9, 9), gt(3, 2), htt(3, 3, 2, 2) + REAL(wp) :: he, ge(12), hk(12, 12), dmy, blk(3, 3), blk2(3, 3) + CHARACTER(200) :: em + + value = CD_ZERO + grad = CD_ZERO + IF (PRESENT(hess)) hess = CD_ZERO + IF (PRESENT(fixed_grad)) fixed_grad = CD_ZERO + want_hess = PRESENT(hess) + with_h = .TRUE. + IF (PRESENT(holonomy)) with_h = holonomy + order = NG_DEFAULT + IF (PRESENT(quadrature_order)) order = quadrature_order + ntri = SIZE(tsign) + ErrStat = CD_HTORS_BADINPUT + IF (SIZE(tri, 1) /= 3 .OR. SIZE(tri, 2) /= 3 .OR. SIZE(tri, 3) /= ntri .OR. SIZE(tslot, 1) /= 3 .OR. & + SIZE(tslot, 2) /= ntri) THEN + ErrMsg = 'CD_HermiteTwist_Reference: tri(3, 3, n), tslot(3, n) and tsign(n) must agree' + RETURN + END IF + IF (PRESENT(fixed_grad)) THEN + IF (SIZE(fixed_grad, 1) /= 3 .OR. SIZE(fixed_grad, 2) /= 3 .OR. SIZE(fixed_grad, 3) /= ntri) THEN + ErrMsg = 'CD_HermiteTwist_Reference: fixed_grad must be shaped as tri' + RETURN + END IF + END IF + IF (ANY(tslot < 0) .OR. ANY(tslot > 2)) THEN + ErrMsg = 'CD_HermiteTwist_Reference: a vertex slot must be 0, 1 or 2' + RETURN + END IF + IF (order < 1 .OR. order > NG_MAX) THEN + ErrMsg = 'CD_HermiteTwist_Reference: quadrature order must lie in [1,6]' + RETURN + END IF + need(1) = ANY(tslot == 1) .OR. with_h + need(2) = ANY(tslot == 2) .OR. with_h + ! (column by column: a reshaped copy of the assumed-shape tri would be a heap temporary) + finite = CD_All_Finite(qe) .AND. CD_Is_Finite(L) .AND. CD_All_Finite(tsign) + DO k = 1, ntri + DO j = 1, 3 + finite = finite .AND. CD_All_Finite(tri(:, j, k)) + END DO + END DO + IF (.NOT. finite) THEN + ErrStat = CD_HTORS_NONFINITE + ErrMsg = 'CD_HermiteTwist_Reference: non-finite input' + RETURN + END IF + IF (with_h .AND. L <= GEOM_TOL) THEN + ErrMsg = 'CD_HermiteTwist_Reference: element length must be positive' + RETURN + END IF + node_t = CD_ZERO + proj = CD_ZERO + DO j = 1, 2 + IF (.NOT. need(j)) CYCLE + IF (NORM2(qe(6*j - 2:6*j)) <= GEOM_TOL) THEN + ErrMsg = 'CD_HermiteTwist_Reference: zero tangent handle at a node' + RETURN + END IF + node_t(:, j) = qe(6*j - 2:6*j)/NORM2(qe(6*j - 2:6*j)) + CALL normalisation_jacobian(qe(6*j - 2:6*j), proj(:, :, j)) + END DO + DO k = 1, ntri + DO j = 1, 3 + IF (tslot(j, k) == 0) THEN + IF (ABS(NORM2(tri(:, j, k)) - CD_ONE) > FRAME_TOL) THEN + ErrMsg = 'CD_HermiteTwist_Reference: a fixed triangle vertex must be a unit vector' + RETURN + END IF + END IF + END DO + END DO + + gt = CD_ZERO + htt = CD_ZERO + DO k = 1, ntri + DO j = 1, 3 + IF (tslot(j, k) == 0) THEN + x(:, j) = tri(:, j, k) + ELSE + x(:, j) = node_t(:, tslot(j, k)) + END IF + END DO + DO j = 1, 3 + IF (CD_ONE + DOT_PRODUCT(x(:, j), x(:, MOD(j, 3) + 1)) < CD_HTORS_FOLD_MIN) THEN + ErrStat = CD_HTORS_FOLD + ErrMsg = 'CD_HermiteTwist_Reference: a director turned by more than 120 degrees in one step or element' + RETURN + END IF + END DO + CALL solid_angle(x(:, 1), x(:, 2), x(:, 3), want_hess, om, g9, h9) + value = value + tsign(k)*om + DO j = 1, 3 + si = tslot(j, k) + IF (si == 0) THEN + IF (PRESENT(fixed_grad)) fixed_grad(:, j, k) = tsign(k)*g9(3*j - 2:3*j) + CYCLE + END IF + gt(:, si) = gt(:, si) + tsign(k)*g9(3*j - 2:3*j) + IF (.NOT. want_hess) CYCLE + DO i = 1, 3 + sj = tslot(i, k) + IF (sj == 0) CYCLE + htt(:, :, si, sj) = htt(:, :, si, sj) + tsign(k)*h9(3*j - 2:3*j, 3*i - 2:3*i) + END DO + END DO + END DO + ! chain to the tangent handles m1 (DOFs 4:6) and m2 (DOFs 10:12) + DO j = 1, 2 + IF (.NOT. need(j)) CYCLE + grad(6*j - 2:6*j) = MATMUL(proj(:, :, j), gt(:, j)) + IF (.NOT. want_hess) CYCLE + ! (staged in 3 x 3 locals: a result into a run-time section, or a nested product, would + ! take a heap temporary) + blk2 = htt(:, :, j, j) + blk = normalised_hessian(qe(6*j - 2:6*j), gt(:, j), blk2) + hess(6*j - 2:6*j, 6*j - 2:6*j) = blk + END DO + IF (want_hess .AND. need(1) .AND. need(2)) THEN + blk2 = MATMUL(htt(:, :, 1, 2), proj(:, :, 2)) + blk = MATMUL(proj(:, :, 1), blk2) + hess(4:6, 10:12) = blk + hess(10:12, 4:6) = TRANSPOSE(blk) + END IF + IF (with_h) THEN + CALL element_holonomy(qe, L, order, want_hess, he, ge, hk, dmy, ErrStat, em) + IF (ErrStat /= CD_HTORS_OK) THEN + ErrMsg = 'CD_HermiteTwist_Reference: '//em + value = CD_ZERO + grad = CD_ZERO + IF (PRESENT(hess)) hess = CD_ZERO + IF (PRESENT(fixed_grad)) fixed_grad = CD_ZERO + RETURN + END IF + value = value - he + grad = grad - ge + IF (want_hess) hess = hess - hk + END IF + IF (.NOT. (CD_Is_Finite(value) .AND. CD_All_Finite(grad))) THEN + ErrStat = CD_HTORS_NONFINITE + ErrMsg = 'CD_HermiteTwist_Reference: non-finite twist or derivative' + value = CD_ZERO + grad = CD_ZERO + RETURN + END IF + IF (want_hess) THEN + finite = .TRUE. + DO j = 1, 12 + finite = finite .AND. CD_All_Finite(hess(:, j)) + END DO + IF (.NOT. finite) THEN + ErrStat = CD_HTORS_NONFINITE + ErrMsg = 'CD_HermiteTwist_Reference: non-finite twist Hessian' + value = CD_ZERO + grad = CD_ZERO + hess = CD_ZERO + RETURN + END IF + END IF + ErrStat = CD_HTORS_OK + ErrMsg = '' + END SUBROUTINE CD_HermiteTwist_Reference + + PURE FUNCTION CD_HermiteTwist_Carry(from, to, v) RESULT(r) + !! The smallest rotation taking the unit vector from to the unit vector to, applied to v (the + !! parallel transport of the nodal-twist directors; requires 1 + from . to > 0). + REAL(wp), INTENT(IN) :: from(3), to(3), v(3) + REAL(wp) :: r(3) + r = smallest_rotation(from, to, v) + END FUNCTION CD_HermiteTwist_Carry + + PURE REAL(wp) FUNCTION CD_HermiteTwist_Angle(x, y, axis) RESULT(ang) + !! The angle in (-pi, pi] about axis, right-hand rule, from x to y (both perpendicular to it). + REAL(wp), INTENT(IN) :: x(3), y(3), axis(3) + ang = ATAN2(DOT_PRODUCT(axis, cross(x, y)), DOT_PRODUCT(x, y)) + END FUNCTION CD_HermiteTwist_Angle + + PURE REAL(wp) FUNCTION CD_HermiteTwist_Omega(x, y, z) RESULT(om) + !! The signed solid angle of the geodesic triangle x, y, z of CD_HermiteTwist_Reference, on + !! the same arithmetic: the value a triangle of fixed vertices takes inside that routine. + REAL(wp), INTENT(IN) :: x(3), y(3), z(3) + REAL(wp) :: g(9), h(9, 9) + CALL solid_angle(x, y, z, .FALSE., om, g, h) + END FUNCTION CD_HermiteTwist_Omega + + PURE SUBROUTINE CD_HermiteTwist_Omega_Gradient(x, y, z, om, g) + !! CD_HermiteTwist_Omega with its gradient g = [dOmega/dx, dOmega/dy, dOmega/dz] in the raw + !! vertex vectors. + REAL(wp), INTENT(IN) :: x(3), y(3), z(3) + REAL(wp), INTENT(OUT) :: om, g(9) + REAL(wp) :: h(9, 9) + CALL solid_angle(x, y, z, .FALSE., om, g, h) + END SUBROUTINE CD_HermiteTwist_Omega_Gradient + ! ------------------------------------------------------------------------------------------ ! element holonomy ! ------------------------------------------------------------------------------------------ @@ -1307,6 +1578,17 @@ PURE REAL(wp) FUNCTION CD_HermiteTorsion_Element_Stretch(qe, L, quadrature_order CALL element_stretch(qe, L, order, .FALSE., ls, g, h) END FUNCTION CD_HermiteTorsion_Element_Stretch + PURE SUBROUTINE CD_HermiteTorsion_Stretch_Derivatives(qe, L, ls, grad, hess, quadrature_order) + !! CD_HermiteTorsion_Element_Stretch with its gradient and Hessian over the 12 DOFs. + REAL(wp), INTENT(IN) :: qe(12), L + REAL(wp), INTENT(OUT) :: ls, grad(12), hess(12, 12) + INTEGER, INTENT(IN), OPTIONAL :: quadrature_order + INTEGER :: order + order = NG_DEFAULT + IF (PRESENT(quadrature_order)) order = quadrature_order + CALL element_stretch(qe, L, order, .TRUE., ls, grad, hess) + END SUBROUTINE CD_HermiteTorsion_Stretch_Derivatives + PURE SUBROUTINE element_stretch(qe, L, order, want_hess, ls, grad, hess) !! The stretched length l_e = L sum_g w_g |a_g| of one cubic-Hermite element (a = dr/ds), its !! gradient L sum_g w_g dh_i a/|a| and Hessian L sum_g w_g dh_i dh_j (I - t t^T)/|a| over the diff --git a/src/CableDyn_OpenFAST_HermiteFMF.f90 b/src/CableDyn_OpenFAST_HermiteFMF.f90 index 93b1e901..55be3705 100644 --- a/src/CableDyn_OpenFAST_HermiteFMF.f90 +++ b/src/CableDyn_OpenFAST_HermiteFMF.f90 @@ -43,7 +43,9 @@ MODULE CableDyn_OpenFAST_HermiteFMF CD_HermiteCable_Dyn_End, CD_HCDYN_OK, & CD_HermiteCable_Dyn_Set_Torsion, CD_HermiteCable_Dyn_Set_Torsion_Drive, & CD_HermiteCable_Dyn_Set_Torsion_Frames, & - CD_HermiteCable_Dyn_Set_SegmentLength + CD_HermiteCable_Dyn_Set_SegmentLength, & + CD_HermiteCable_Dyn_Twist_Mirror_Size, CD_HermiteCable_Dyn_Twist_Pack, & + CD_HermiteCable_Dyn_Twist_Unpack, CD_HermiteCable_Dyn_Twist_Check USE CableDyn_HermiteTorsion, ONLY: CD_HermiteTorsionType, CD_HermiteTorsion_Compliance, CD_HermiteTorsion_Line, & CD_HermiteTorsion_Unwrap, CD_HTORS_OK, CD_HTORS_MAX_STEP USE CableDyn_HermiteCable, ONLY: CD_HermiteCable_Shapes @@ -862,6 +864,15 @@ SUBROUTINE CD_HFMF_PreflightCoupledKinematics(self, u_pos, u_vel, u_acc, ErrStat END DO ALLOCATE (qc(SIZE(self%line%q)), g(SIZE(self%line%q))) CALL coupled_candidate_q(self, u_pos, tangent_q, qc) + IF (self%line%tw_active) THEN + ! the nodal twist: its own acceptance of the written state (CD_HermiteCable_Dyn_Twist_Check) + CALL CD_HermiteCable_Dyn_Twist_Check(self%line, qc, ends, ks, km) + IF (ks /= CD_HCDYN_OK) THEN + ErrStat = CD_HFMF_SOLVEFAIL + ErrMsg = 'CD_HFMF_PreflightCoupledKinematics: '//TRIM(km) + END IF + RETURN + END IF CALL CD_HermiteTorsion_Line(qc, self%line%l0, ends, raw, g, ks, km, & couple=self%line%torsion%couple, & quadrature_order=self%line%torsion%quadrature_order) @@ -1667,12 +1678,13 @@ INTEGER FUNCTION CD_HFMF_BoundaryMirrorSize(self) RESULT(n) END FUNCTION CD_HFMF_BoundaryMirrorSize INTEGER FUNCTION CD_HFMF_TorsionMirrorSize(self) RESULT(n) - !! Mirror slots of the condensed torsion, last: the accepted (unwrapped) Theta, Phi and the - !! four end-frame vectors (14 values); zero without torsion. + !! Mirror slots of the torsion, last: the accepted (unwrapped) Theta, Phi and the four + !! end-frame vectors (14 values), then the nodal twist's state + !! (CD_HermiteCable_Dyn_Twist_Mirror_Size); zero without torsion. TYPE(CD_HFMF_ModuleType), INTENT(IN) :: self n = 0 IF (.NOT. self%initialized) RETURN - IF (self%line%torsion%active) n = 14 + IF (self%line%torsion%active) n = 14 + CD_HermiteCable_Dyn_Twist_Mirror_Size(self%line) END FUNCTION CD_HFMF_TorsionMirrorSize INTEGER FUNCTION CD_HFMF_ForceMirrorSize(self) RESULT(n) @@ -1774,6 +1786,9 @@ SUBROUTINE CD_HFMF_PackMirror(self, buf, ErrStat, ErrMsg) buf(k + 1) = self%line%torsion%theta buf(k + 2) = self%line%torsion%phi buf(k + 3:k + 14) = RESHAPE(self%line%torsion%ends, [12]) + IF (self%line%tw_active) & + CALL CD_HermiteCable_Dyn_Twist_Pack(self%line, buf(k + 15:k + 14 + CD_HermiteCable_Dyn_Twist_Mirror_Size( & + self%line))) END IF END SUBROUTINE CD_HFMF_PackMirror @@ -1790,7 +1805,8 @@ SUBROUTINE CD_HFMF_UnpackMirror(self, buf, t, ErrStat, ErrMsg) REAL(wp), INTENT(IN) :: t INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg - INTEGER :: i, nf, nh, k, kb + INTEGER :: i, nf, nh, k, kb, es + CHARACTER(1024) :: em ErrStat = CD_HFMF_OK; ErrMsg = '' IF (.NOT. self%initialized) THEN ErrStat = CD_HFMF_BADINPUT; ErrMsg = 'CD_HFMF_UnpackMirror: module not initialised'; RETURN @@ -1808,9 +1824,18 @@ SUBROUTINE CD_HFMF_UnpackMirror(self, buf, t, ErrStat, ErrMsg) ErrStat = CD_HFMF_BADINPUT; ErrMsg = 'CD_HFMF_UnpackMirror: mirror must be finite'; RETURN END IF IF (self%line%torsion%active) THEN - ! the torsion block (last 14 values) is checked before anything is written: each end's - ! director and reference normal must be orthonormal, as Set_Torsion_Drive requires - k = SIZE(buf) - 14 + ! the torsion block (the last CD_HFMF_TorsionMirrorSize values) is checked before anything + ! is written: each end's director and reference normal must be orthonormal, as + ! Set_Torsion_Drive requires, and the nodal twist's directors unit vectors + k = SIZE(buf) - CD_HFMF_TorsionMirrorSize(self) + IF (self%line%tw_active) THEN + CALL CD_HermiteCable_Dyn_Twist_Unpack(self%line, buf(k + 15:SIZE(buf)), es, em, check_only=.TRUE.) + IF (es /= CD_HCDYN_OK) THEN + ErrStat = CD_HFMF_BADINPUT + ErrMsg = 'CD_HFMF_UnpackMirror: '//TRIM(em) + RETURN + END IF + END IF DO i = 0, 1 ASSOCIATE (dv => buf(k + 3 + 6*i:k + 5 + 6*i), nv => buf(k + 6 + 6*i:k + 8 + 6*i)) IF (ABS(NORM2(dv) - CD_ONE) > 1.0e-8_wp .OR. ABS(NORM2(nv) - CD_ONE) > 1.0e-8_wp .OR. & @@ -1910,6 +1935,8 @@ SUBROUTINE CD_HFMF_UnpackMirror(self, buf, t, ErrStat, ErrMsg) self%line%torsion%torque = (self%line%torsion%phi - self%line%torsion%theta)/ & CD_HermiteTorsion_Compliance(self%line%torsion, self%line%l0) self%line%tors_drive_set = .FALSE. + ! the nodal twist, checked above (its force-cache part rides with the cable's) + IF (self%line%tw_active) CALL CD_HermiteCable_Dyn_Twist_Unpack(self%line, buf(k + 15:SIZE(buf)), es, em) ! (a parent-attached torsion frame turns with the parent orientation, which the boundary ! block restored as committed, so a later step without u_orientation holds it) END IF diff --git a/tests/test_coupled_torsion.f90 b/tests/test_coupled_torsion.f90 index 285d0f2c..72b8c94c 100644 --- a/tests/test_coupled_torsion.f90 +++ b/tests/test_coupled_torsion.f90 @@ -7,9 +7,12 @@ PROGRAM test_coupled_torsion !! straight 100 m neutral line of test_torsion_deck (GJ 5e4 N m^2, both ends clamped and !! restrained in torsion, no pretwist), its End A on the platform fairlead (0, 0, -50) and !! End B on a fixed anchor. Rolling the platform by phi about the line axis (+x) twists the - !! line by -phi: Twist1 = -phi and Torq = GJ (-phi) / L, with no torsional inertia. - !! 1. feedthrough: a non-stepping update with a rolled orientation gives that twist and - !! torque, and the fairlead moment is the restoring torque about the line axis; + !! line by -phi: Twist1 = -phi and, with a negligible polar inertia (Irn 1e-9: the quasi-static + !! limit of the nodal twist), Torq = GJ (-phi) / L. + !! 1. feedthrough: a non-stepping update with a rolled orientation twists the end element + !! alone against the frozen interior (as the coupled end's translation stretches it): + !! Twist1 = -phi, Torq = GJ (-phi) / l_e at the fairlead and 0 at the anchor until the next + !! step, and the fairlead moment is that restoring torque about the line axis; !! 2. march: the platform rolls at 60 deg/s; every step gives Twist1 = -phi(t) and the !! quasi-static torque (the coupled twin of the standalone vessel-roll gate), and the !! single-cable entry driven with the same calls gives the same values bit for bit; @@ -41,9 +44,11 @@ PROGRAM test_coupled_torsion INTEGER :: n_fail = 0 CHARACTER(160) :: neutral_type - ! neutral 0.2 m section: mass = rhoW pi d^2 / 4; EA 1e7, EI 1e6, GAs 1e8, GJ 5e4 + ! neutral 0.2 m section: mass = rhoW pi d^2 / 4; EA 1e7, EI 1e6, GAs 1e8, GJ 5e4, Irn 1e-9 (the + ! quasi-static torsion these gates check: the nodal twist's limit of a negligible polar inertia, + ! whose inertia test_nodal_twist_dynamic gates) WRITE (neutral_type, '(A,ES24.16,A)') 'cab 0.2 ', RHOW*0.25_wp*PI*0.04_wp, & - ' 1.0e7 0.0 1.0e6 1.0e8 5.0e4 1.0 1.0 0.0 0.0 0.0 0.0' + ' 1.0e7 0.0 1.0e6 1.0e8 5.0e4 1.0 1.0e-9 0.0 0.0 0.0 0.0' CALL check_feedthrough() CALL check_march() @@ -210,11 +215,12 @@ SUBROUTINE check_feedthrough() CALL require(es == CD_AGG_OK, '1: a rolled orientation is accepted: '//TRIM(em)) CALL CD_AGG_CalcOutput(agg, es, em) CALL channels(agg, ta, tb, tw) - m_ref = GJ*(-phi)/L + ! the end element (of 40) takes the roll + m_ref = GJ*(-phi)/(L/40.0_wp) WRITE (*, '(A,3ES15.7,A,ES15.7)') '1 feedthrough: Torq A/B, Twist ', ta, tb, tw, '; ref torque ', m_ref CALL require(ABS(tw + 20.0_wp) <= 1.0e-6_wp, '1: Twist1 = -roll') - CALL require(ABS(ta - m_ref) <= 1.0e-6_wp*ABS(m_ref) .AND. ABS(tb - m_ref) <= 1.0e-6_wp*ABS(m_ref), & - '1: Torq = GJ (-roll) / L at both ends') + CALL require(ABS(ta - m_ref) <= 1.0e-6_wp*ABS(m_ref) .AND. ABS(tb) <= 1.0e-9_wp*ABS(m_ref), & + '1: Torq = GJ (-roll) / l_e at the fairlead, 0 at the anchor (the frozen interior)') CALL CD_AGG_GetMovingPointMesh(agg, pos, vel, acc, load, es, em, moment=moment) WRITE (*, '(A,3ES15.7)') '1 feedthrough: fairlead moment ', moment(:, 1) CALL require(ABS(ABS(moment(1, 1)) - ABS(m_ref)) <= 1.0e-6_wp*ABS(m_ref), & diff --git a/tests/test_hermite_twist_kernel.f90 b/tests/test_hermite_twist_kernel.f90 new file mode 100644 index 00000000..17ddfb5a --- /dev/null +++ b/tests/test_hermite_twist_kernel.f90 @@ -0,0 +1,284 @@ +! File: tests/test_hermite_twist_kernel.f90 +! SPDX-License-Identifier: Apache-2.0 +! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +PROGRAM test_hermite_twist_kernel + !! Gates for the reference twist of the nodal-twist model (CD_HermiteTwist_Reference): + !! I the solid-angle forms equal the direct composition of the smallest rotations for an + !! interior element, an element at a rigid End A, at a rigid End B, a one-element line + !! rigid at both ends, and the end links of an elastic end, + !! T with the holonomy, the reference twist is the angle from the director carried along + !! the element (fine smallest-rotation transport of its tangent) to the next director, + !! F gradient and Hessian against central differences, and the fixed-vertex gradient + !! against rotations of the fixed vertices, + !! G the fold guard and the input checks fail closed. + USE CableDyn_Precision, ONLY: wp + USE CableDyn_HermiteTorsion, ONLY: CD_HermiteTwist_Reference, CD_HermiteTwist_Carry, CD_HermiteTwist_Angle, & + CD_HTORS_OK, CD_HTORS_FOLD, CD_HTORS_BADINPUT + IMPLICIT NONE + + INTEGER :: nfail + REAL(wp) :: qe(12), el, a(3), d(3), b(3), c(3), u1n(3), u2n(3), dA(3), nA(3), dB(3), nB(3) + + nfail = 0 + CALL setup() + CALL check_identities() + CALL check_transport() + CALL check_derivatives() + CALL check_guards() + IF (nfail > 0) THEN + WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed' + ERROR STOP 1 + END IF + WRITE (*, '(A)') 'PASS: nodal-twist reference twist matches the direct transports and its derivatives' + +CONTAINS + + SUBROUTINE require(ok, label) + LOGICAL, INTENT(IN) :: ok + CHARACTER(*), INTENT(IN) :: label + IF (.NOT. ok) THEN + nfail = nfail + 1 + WRITE (*, '(A)') 'FAIL: '//label + END IF + END SUBROUTINE require + + FUNCTION unit(v) RESULT(w) + REAL(wp), INTENT(IN) :: v(3) + REAL(wp) :: w(3) + w = v/NORM2(v) + END FUNCTION unit + + FUNCTION perp(v, t) RESULT(w) + !! unit part of v perpendicular to the unit t + REAL(wp), INTENT(IN) :: v(3), t(3) + REAL(wp) :: w(3) + w = unit(v - DOT_PRODUCT(v, t)*t) + END FUNCTION perp + + FUNCTION cross(x, y) RESULT(z) + REAL(wp), INTENT(IN) :: x(3), y(3) + REAL(wp) :: z(3) + z = [x(2)*y(3) - x(3)*y(2), x(3)*y(1) - x(1)*y(3), x(1)*y(2) - x(2)*y(1)] + END FUNCTION cross + + FUNCTION rotate(v, w) RESULT(r) + !! exp(w) v (Rodrigues) + REAL(wp), INTENT(IN) :: v(3), w(3) + REAL(wp) :: r(3), th, k(3) + th = NORM2(w) + IF (th <= 0.0_wp) THEN + r = v + RETURN + END IF + k = w/th + r = v*COS(th) + cross(k, v)*SIN(th) + k*DOT_PRODUCT(k, v)*(1.0_wp - COS(th)) + END FUNCTION rotate + + SUBROUTINE setup() + !! A curved, stretched element and committed tangents a step away from its node tangents. + el = 2.3_wp + qe(1:3) = [0.1_wp, -0.2_wp, 0.05_wp] + qe(4:6) = [0.95_wp, 0.25_wp, -0.12_wp] + qe(7:9) = qe(1:3) + [2.1_wp, 0.9_wp, 0.4_wp] + qe(10:12) = [0.72_wp, 0.55_wp, 0.38_wp] + b = unit(qe(4:6)) + c = unit(qe(10:12)) + a = rotate(b, [0.03_wp, -0.07_wp, 0.05_wp]) + d = rotate(c, [-0.06_wp, 0.02_wp, 0.04_wp]) + u1n = perp([0.2_wp, 1.0_wp, -0.3_wp], a) + u2n = perp([-0.4_wp, 0.3_wp, 1.0_wp], d) + dA = rotate(b, [0.15_wp, 0.1_wp, -0.08_wp]) + nA = perp([0.0_wp, 0.3_wp, 1.0_wp], dA) + dB = rotate(c, [-0.12_wp, 0.09_wp, 0.11_wp]) + nB = perp([1.0_wp, -0.2_wp, 0.1_wp], dB) + END SUBROUTINE setup + + REAL(wp) FUNCTION ref(tri, tslot, tsign, hol) RESULT(v) + REAL(wp), INTENT(IN) :: tri(:, :, :), tsign(:) + INTEGER, INTENT(IN) :: tslot(:, :) + LOGICAL, INTENT(IN) :: hol + REAL(wp) :: g(12) + INTEGER :: es + CHARACTER(200) :: em + CALL CD_HermiteTwist_Reference(qe, el, tri, tslot, tsign, v, g, es, em, holonomy=hol) + CALL require(es == CD_HTORS_OK, 'reference evaluation: '//TRIM(em)) + END FUNCTION ref + + SUBROUTINE check_identities() + REAL(wp) :: tri(3, 3, 2), direct, formula, cst, z(3) + INTEGER :: slot(3, 2) + CHARACTER(120) :: msg + + ! interior: beta = beta^n - Omega(a, b, c) - Omega(a, c, d) + direct = CD_HermiteTwist_Angle(CD_HermiteTwist_Carry(b, c, CD_HermiteTwist_Carry(a, b, u1n)), & + CD_HermiteTwist_Carry(d, c, u2n), c) + cst = CD_HermiteTwist_Angle(CD_HermiteTwist_Carry(a, d, u1n), u2n, d) + z = 0.0_wp + tri(:, :, 1) = RESHAPE([a, z, z], [3, 3]) + tri(:, :, 2) = RESHAPE([a, z, d], [3, 3]) + slot(:, 1) = [0, 1, 2] + slot(:, 2) = [0, 2, 0] + formula = cst + ref(tri, slot, [-1.0_wp, -1.0_wp], .FALSE.) + WRITE (msg, '(A,2ES12.4)') 'I interior element: direct vs formula ', direct, formula + CALL require(ABS(direct - formula) < 1.0e-13_wp, msg) + CALL require(ABS(direct - cst) > 1.0e-3_wp, 'I interior element: the step moves the reference twist') + + ! rigid End A: u_1 = G(dA -> b) nA; beta = angle(G(dA -> d) nA -> u2n) - Omega(dA, b, c) - Omega(dA, c, d) + direct = CD_HermiteTwist_Angle(CD_HermiteTwist_Carry(b, c, CD_HermiteTwist_Carry(dA, b, nA)), & + CD_HermiteTwist_Carry(d, c, u2n), c) + cst = CD_HermiteTwist_Angle(CD_HermiteTwist_Carry(dA, d, nA), u2n, d) + tri(:, :, 1) = RESHAPE([dA, z, z], [3, 3]) + tri(:, :, 2) = RESHAPE([dA, z, d], [3, 3]) + formula = cst + ref(tri, slot, [-1.0_wp, -1.0_wp], .FALSE.) + WRITE (msg, '(A,2ES12.4)') 'I rigid End A element: direct vs formula ', direct, formula + CALL require(ABS(direct - formula) < 1.0e-13_wp, msg) + + ! rigid End B: u_2 = G(dB -> c) nB; beta = angle(u1n -> G(dB -> a) nB) + Omega(dB, c, a) - Omega(a, b, c) + direct = CD_HermiteTwist_Angle(CD_HermiteTwist_Carry(b, c, CD_HermiteTwist_Carry(a, b, u1n)), & + CD_HermiteTwist_Carry(dB, c, nB), c) + cst = CD_HermiteTwist_Angle(u1n, CD_HermiteTwist_Carry(dB, a, nB), a) + tri(:, :, 1) = RESHAPE([dB, z, a], [3, 3]) + tri(:, :, 2) = RESHAPE([a, z, z], [3, 3]) + slot(:, 1) = [0, 2, 0] + slot(:, 2) = [0, 1, 2] + formula = cst + ref(tri, slot, [1.0_wp, -1.0_wp], .FALSE.) + WRITE (msg, '(A,2ES12.4)') 'I rigid End B element: direct vs formula ', direct, formula + CALL require(ABS(direct - formula) < 1.0e-13_wp, msg) + + ! one element rigid at both ends: beta = angle(nA -> G(dB -> dA) nB) + Omega(dB, c, dA) - Omega(dA, b, c) + direct = CD_HermiteTwist_Angle(CD_HermiteTwist_Carry(b, c, CD_HermiteTwist_Carry(dA, b, nA)), & + CD_HermiteTwist_Carry(dB, c, nB), c) + cst = CD_HermiteTwist_Angle(nA, CD_HermiteTwist_Carry(dB, dA, nB), dA) + tri(:, :, 1) = RESHAPE([dB, z, dA], [3, 3]) + tri(:, :, 2) = RESHAPE([dA, z, z], [3, 3]) + slot(:, 1) = [0, 2, 0] + slot(:, 2) = [0, 1, 2] + formula = cst + ref(tri, slot, [1.0_wp, -1.0_wp], .FALSE.) + WRITE (msg, '(A,2ES12.4)') 'I rigid at both ends: direct vs formula ', direct, formula + CALL require(ABS(direct - formula) < 1.0e-13_wp, msg) + + ! elastic End A link: psi = angle(u_1 -> G(dA -> b) nA) = angle(u1n -> G(dA -> a) nA) + Omega(dA, b, a) + direct = CD_HermiteTwist_Angle(CD_HermiteTwist_Carry(a, b, u1n), CD_HermiteTwist_Carry(dA, b, nA), b) + cst = CD_HermiteTwist_Angle(u1n, CD_HermiteTwist_Carry(dA, a, nA), a) + tri(:, :, 1) = RESHAPE([dA, z, a], [3, 3]) + slot(:, 1) = [0, 1, 0] + formula = cst + ref(tri(:, :, 1:1), slot(:, 1:1), [1.0_wp], .FALSE.) + WRITE (msg, '(A,2ES12.4)') 'I elastic end link: direct vs formula ', direct, formula + CALL require(ABS(direct - formula) < 1.0e-13_wp, msg) + END SUBROUTINE check_identities + + SUBROUTINE check_transport() + !! With the holonomy, value + beta^n is the angle from u_1 carried along the element's own + !! tangent field to u_2 (both time-transported), here with u_1 = u1n, u_2 = u2n and a = b, + !! d = c (no step). + INTEGER, PARAMETER :: NSUB = 20000 + REAL(wp) :: tri(3, 3, 2), z(3), v(3), tp(3), tc(3), x, hh(4), direct, formula, cst, ua(3), ub(3) + INTEGER :: slot(3, 2), k, es + REAL(wp) :: g(12), val + CHARACTER(200) :: em + CHARACTER(120) :: msg + z = 0.0_wp + ua = perp(u1n, b) + ub = perp(u2n, c) + v = ua + tp = b + DO k = 1, NSUB + x = REAL(k, wp)/REAL(NSUB, wp) + hh = [-6.0_wp*x + 6.0_wp*x*x, el*(1.0_wp - 4.0_wp*x + 3.0_wp*x*x), 6.0_wp*x - 6.0_wp*x*x, & + el*(-2.0_wp*x + 3.0_wp*x*x)] + tc = unit(hh(1)*qe(1:3) + hh(2)*qe(4:6) + hh(3)*qe(7:9) + hh(4)*qe(10:12)) + IF (k == NSUB) tc = c + v = CD_HermiteTwist_Carry(tp, tc, v) + tp = tc + END DO + direct = CD_HermiteTwist_Angle(v, ub, c) + cst = CD_HermiteTwist_Angle(CD_HermiteTwist_Carry(b, c, ua), ub, c) + tri(:, :, 1) = RESHAPE([b, z, z], [3, 3]) + tri(:, :, 2) = RESHAPE([b, z, c], [3, 3]) + slot(:, 1) = [0, 1, 2] + slot(:, 2) = [0, 2, 0] + CALL CD_HermiteTwist_Reference(qe, el, tri, slot, [-1.0_wp, -1.0_wp], val, g, es, em, quadrature_order=6) + CALL require(es == CD_HTORS_OK, 'T transport evaluation: '//TRIM(em)) + formula = cst + val + WRITE (msg, '(A,2ES14.6)') 'T element transport: fine transport vs beta - h_e ', direct, formula + CALL require(ABS(direct - formula) < 1.0e-6_wp, msg) + CALL require(ABS(direct - cst) > 1.0e-3_wp, 'T the element holonomy is not negligible on this element') + END SUBROUTINE check_transport + + SUBROUTINE check_derivatives() + REAL(wp) :: tri(3, 3, 2), z(3), g(12), h(12, 12), gp(12), gm(12), fg(3, 3, 2), vp, vm, v0, eps + REAL(wp) :: err_g, err_h, err_f, scale_g, scale_h, q0(12), w(3), x0(3), num + INTEGER :: slot(3, 2), i, es, k, j + CHARACTER(200) :: em + CHARACTER(120) :: msg + z = 0.0_wp + tri(:, :, 1) = RESHAPE([a, z, z], [3, 3]) + tri(:, :, 2) = RESHAPE([a, z, d], [3, 3]) + slot(:, 1) = [0, 1, 2] + slot(:, 2) = [0, 2, 0] + q0 = qe + CALL CD_HermiteTwist_Reference(qe, el, tri, slot, [-1.0_wp, -1.0_wp], v0, g, es, em, hess=h, fixed_grad=fg) + CALL require(es == CD_HTORS_OK, 'F evaluation: '//TRIM(em)) + eps = 1.0e-6_wp + err_g = 0.0_wp + err_h = 0.0_wp + scale_g = MAXVAL(ABS(g)) + scale_h = MAXVAL(ABS(h)) + DO i = 1, 12 + qe = q0 + qe(i) = q0(i) + eps + CALL CD_HermiteTwist_Reference(qe, el, tri, slot, [-1.0_wp, -1.0_wp], vp, gp, es, em) + qe(i) = q0(i) - eps + CALL CD_HermiteTwist_Reference(qe, el, tri, slot, [-1.0_wp, -1.0_wp], vm, gm, es, em) + err_g = MAX(err_g, ABS((vp - vm)/(2.0_wp*eps) - g(i))) + err_h = MAX(err_h, MAXVAL(ABS((gp - gm)/(2.0_wp*eps) - h(:, i)))) + END DO + qe = q0 + WRITE (msg, '(A,2ES10.2)') 'F gradient and Hessian relative errors ', err_g/scale_g, err_h/scale_h + CALL require(err_g/scale_g < 1.0e-7_wp .AND. err_h/scale_h < 1.0e-6_wp, msg) + CALL require(MAXVAL(ABS(h - TRANSPOSE(h))) < 1.0e-10_wp*scale_h, 'F the Hessian is symmetric') + ! fixed vertices: rotate each by a small angle about a few axes + err_f = 0.0_wp + DO k = 1, 2 + DO j = 1, 3 + IF (slot(j, k) /= 0) CYCLE + x0 = tri(:, j, k) + DO i = 1, 3 + w = 0.0_wp + w(i) = 1.0_wp + tri(:, j, k) = rotate(x0, eps*w) + CALL CD_HermiteTwist_Reference(qe, el, tri, slot, [-1.0_wp, -1.0_wp], vp, gp, es, em) + tri(:, j, k) = rotate(x0, -eps*w) + CALL CD_HermiteTwist_Reference(qe, el, tri, slot, [-1.0_wp, -1.0_wp], vm, gm, es, em) + tri(:, j, k) = x0 + num = (vp - vm)/(2.0_wp*eps) + err_f = MAX(err_f, ABS(num - DOT_PRODUCT(fg(:, j, k), cross(w, x0)))) + END DO + END DO + END DO + WRITE (msg, '(A,ES10.2)') 'F fixed-vertex gradient error ', err_f + CALL require(err_f < 1.0e-8_wp, msg) + END SUBROUTINE check_derivatives + + SUBROUTINE check_guards() + REAL(wp) :: tri(3, 3, 1), z(3), g(12), v + INTEGER :: slot(3, 1), es + CHARACTER(200) :: em + z = 0.0_wp + ! a committed tangent opposite to the node tangent: folded + tri(:, :, 1) = RESHAPE([-b, z, z], [3, 3]) + slot(:, 1) = [0, 1, 2] + CALL CD_HermiteTwist_Reference(qe, el, tri, slot, [1.0_wp], v, g, es, em) + CALL require(es == CD_HTORS_FOLD, 'G a reversed tangent fails with the fold status') + ! a non-unit fixed vertex + tri(:, :, 1) = RESHAPE([2.0_wp*a, z, z], [3, 3]) + CALL CD_HermiteTwist_Reference(qe, el, tri, slot, [1.0_wp], v, g, es, em) + CALL require(es == CD_HTORS_BADINPUT, 'G a non-unit fixed vertex is refused') + ! a bad slot + tri(:, :, 1) = RESHAPE([a, z, z], [3, 3]) + slot(:, 1) = [0, 3, 2] + CALL CD_HermiteTwist_Reference(qe, el, tri, slot, [1.0_wp], v, g, es, em) + CALL require(es == CD_HTORS_BADINPUT, 'G a vertex slot outside 0..2 is refused') + END SUBROUTINE check_guards + +END PROGRAM test_hermite_twist_kernel diff --git a/tests/test_nodal_twist_dynamic.f90 b/tests/test_nodal_twist_dynamic.f90 new file mode 100644 index 00000000..d8c5e71c --- /dev/null +++ b/tests/test_nodal_twist_dynamic.f90 @@ -0,0 +1,473 @@ +! File: tests/test_nodal_twist_dynamic.f90 +! SPDX-License-Identifier: Apache-2.0 +! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +PROGRAM test_nodal_twist_dynamic + !! Gates of the nodal twist (a twist angle at every node, with the polar rotary inertia Irn) + !! on the cubic-Hermite cable, a 10 m line restrained in torsion at both ends: + !! Q quasi-static limit: with a negligible Irn the nodal twist reproduces the condensed + !! torsion on a bowed line that sways, rolls through more than a turn at its coupled end + !! and takes an imposed twist: the centreline, the mean and nodal torques, the coupled + !! end force and moment agree, for clamped ends, bending-pinned ends (the end tangent + !! moves off the end director) and elastic torsional ends; + !! W torsional waves: a straight line, clamped and rigid in torsion at both ends, driven in + !! roll at one end below its first torsional mode, carries at the other end the torque of + !! the continuum, GJ A k / sin(kL) with k = Omega sqrt(Irn/GJ); + !! D torsional damping: the first torsional mode rings down at zeta_1 = omega_1 Bt/(2 GJ); + !! E energy: free vibration of a bowed, twisted line with a real Irn (rho_inf = 1): kinetic + !! (with the polar part) + elastic (with the twist) stays within the band of the line + !! without torsion; + !! R restart: a rolling run restored from a snapshot, and one rebuilt from the checkpoint + !! mirror, continue bit-identically. + USE CableDyn_Precision, ONLY: wp + USE CableDyn_EndConnection, ONLY: CD_ENDCONN_RIGID + USE CableDyn_HermiteTorsion, ONLY: CD_HermiteTorsionType, CD_HermiteTorsion_Line, CD_HermiteTorsion_Unwrap, & + CD_HTORS_OK + USE CableDyn_HermiteCableDynamic, ONLY: CD_HermiteCableDynType, CD_HermiteCable_Dyn_Init, & + CD_HermiteCable_Dyn_Step, CD_HermiteCable_Dyn_Energy, & + CD_HermiteCable_Dyn_End, CD_HermiteCable_Dyn_Set_EndConnection, & + CD_HermiteCable_Dyn_Set_Torsion, CD_HermiteCable_Dyn_Torsion_State, & + CD_HermiteCable_Dyn_Node_Torque, CD_HCDYN_OK + USE CableDyn_OpenFAST_HermiteFMF, ONLY: CD_HFMF_ModuleType, CD_HFMF_Init, CD_HFMF_Set_EndConnection, & + CD_HFMF_Set_Torsion, CD_HFMF_UpdateStates, CD_HFMF_CalcOutput, & + CD_HFMF_Snapshot, CD_HFMF_Restore, CD_HFMF_MirrorSize, & + CD_HFMF_PackMirror, CD_HFMF_UnpackMirror, CD_HFMF_End, CD_HFMF_OK + IMPLICIT NONE + + REAL(wp), PARAMETER :: PI = 3.14159265358979323846_wp + REAL(wp), PARAMETER :: LL = 10.0_wp, EA = 1.0e5_wp, EI = 100.0_wp, GJ = 80.0_wp, RHOA = 1.0_wp + INTEGER, PARAMETER :: NE = 20, NN = NE + 1, NDOF = 6*NN + INTEGER :: nfail = 0 + + CALL check_quasi_static('clamped', .FALSE., 0.0_wp) + CALL check_quasi_static('bending-pinned', .TRUE., 0.0_wp) + CALL check_quasi_static('elastic', .FALSE., 0.05_wp) + CALL check_waves() + CALL check_damping() + CALL check_energy() + CALL check_restart() + + IF (nfail > 0) THEN + WRITE (*, '(A,I0,A)') 'FAIL: ', nfail, ' assertion(s) failed' + ERROR STOP 1 + END IF + WRITE (*, '(A)') 'PASS: nodal twist gates' + +CONTAINS + + INCLUDE 'nan_max_abs.inc' + + SUBROUTINE require(cond, label) + LOGICAL, INTENT(IN) :: cond + CHARACTER(*), INTENT(IN) :: label + IF (cond) RETURN + nfail = nfail + 1 + WRITE (*, '(A)') 'FAIL: '//TRIM(label) + END SUBROUTINE require + + FUNCTION roll_x(psi) RESULT(r) + !! Global-to-parent DCM of a parent rolled by psi about +x (the transpose of the rotation). + REAL(wp), INTENT(IN) :: psi + REAL(wp) :: r(3, 3) + r = 0.0_wp + r(1, 1) = 1.0_wp + r(2, 2) = COS(psi) + r(3, 3) = COS(psi) + r(2, 3) = SIN(psi) + r(3, 2) = -SIN(psi) + END FUNCTION roll_x + + SUBROUTINE line_seed(bow_y, bow_z, q) + !! Straight line along +x (node 1 at the origin), optionally bowed by y = bow_y sin^2(pi s/L), + !! z = bow_z sin^2(2 pi s/L) (end tangents stay along +x, as the clamps require). + REAL(wp), INTENT(IN) :: bow_y, bow_z + REAL(wp), INTENT(OUT) :: q(NDOF) + INTEGER :: k + REAL(wp) :: s + q = 0.0_wp + DO k = 1, NN + s = LL*REAL(k - 1, wp)/REAL(NE, wp) + q(6*k - 5) = s + q(6*k - 4) = bow_y*SIN(PI*s/LL)**2 + q(6*k - 3) = bow_z*SIN(2.0_wp*PI*s/LL)**2 + q(6*k - 2) = 1.0_wp + q(6*k - 1) = bow_y*(PI/LL)*SIN(2.0_wp*PI*s/LL) + q(6*k) = bow_z*(2.0_wp*PI/LL)*SIN(4.0_wp*PI*s/LL) + END DO + END SUBROUTINE line_seed + + SUBROUTINE torsion_of(q, phi, tors, irn, compliance) + !! Torsion of the line: both ends along +x with reference normal +z, GJ on every element, + !! imposed twist phi, Theta of the seed q (branch nearest 0); irn > 0 adds the polar inertia + !! (nodal twist), compliance the torsional end compliances. + REAL(wp), INTENT(IN) :: q(NDOF), phi, irn, compliance + TYPE(CD_HermiteTorsionType), INTENT(OUT) :: tors + REAL(wp) :: g(NDOF), raw, l0(NE) + INTEGER :: es + CHARACTER(200) :: em + l0 = LL/REAL(NE, wp) + tors%active = .TRUE. + tors%phi = phi + tors%ends = RESHAPE([1.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 1.0_wp, 1.0_wp, 0.0_wp, 0.0_wp, & + 0.0_wp, 0.0_wp, 1.0_wp], [3, 4]) + tors%end_compliance = compliance + ALLOCATE (tors%gj(NE)) + tors%gj = GJ + IF (irn > 0.0_wp) THEN + ALLOCATE (tors%irn(NE)) + tors%irn = irn + END IF + CALL CD_HermiteTorsion_Line(q, l0, tors%ends, raw, g, es, em) + CALL require(es == CD_HTORS_OK, 'seed twist evaluates: '//TRIM(em)) + tors%theta = CD_HermiteTorsion_Unwrap(raw, 0.0_wp) + tors%has_theta = .TRUE. + END SUBROUTINE torsion_of + + SUBROUTINE build_cable(cab, q, phi, dt, tol, rho_inf, pinned, irn, compliance) + !! HFMF cable on seed q: node NN coupled (driven), node 1 held; Rigid bending connections + !! along +x at both ends (none with pinned), the coupled one in parent axes (identity + !! attitude); torsion with the coupled end's frame attached to the parent. + TYPE(CD_HFMF_ModuleType), INTENT(INOUT) :: cab + REAL(wp), INTENT(IN) :: q(NDOF), phi, dt, tol, rho_inf, irn, compliance + LOGICAL, INTENT(IN) :: pinned + TYPE(CD_HermiteTorsionType) :: tors + REAL(wp) :: l0(NE), eye(3, 3), frame(3, 2) + INTEGER :: es + CHARACTER(300) :: em + l0 = LL/REAL(NE, wp) + eye = roll_x(0.0_wp) + CALL CD_HFMF_Init(cab, l0, [(EA, es=1, NE)], [(EI, es=1, NE)], [(RHOA, es=1, NE)], [(0.0_wp, es=1, NE)], q, & + [1, 2, 3, NDOF - 5, NDOF - 4, NDOF - 3], 0.0_wp, 0.0_wp, rho_inf, dt, NN, es, em, & + max_iter=60, tol=tol) + CALL require(es == CD_HFMF_OK, 'cable init: '//TRIM(em)) + IF (.NOT. pinned) THEN + CALL CD_HFMF_Set_EndConnection(cab, [0.0_wp, 0.0_wp], RESHAPE([1.0_wp, 0.0_wp, 0.0_wp, 1.0_wp, 0.0_wp, 0.0_wp], & + [3, 2]), es, em, & + coupled_d0_parent=[1.0_wp, 0.0_wp, 0.0_wp], parent_orientation=eye, & + connection_mode=[CD_ENDCONN_RIGID, CD_ENDCONN_RIGID]) + CALL require(es == CD_HFMF_OK, 'cable end connections: '//TRIM(em)) + END IF + CALL torsion_of(q, phi, tors, irn, compliance) + frame(:, 1) = [1.0_wp, 0.0_wp, 0.0_wp] + frame(:, 2) = [0.0_wp, 0.0_wp, 1.0_wp] + CALL CD_HFMF_Set_Torsion(cab, tors, es, em, coupled_frame_parent=frame, parent_orientation=eye) + CALL require(es == CD_HFMF_OK, 'cable torsion: '//TRIM(em)) + END SUBROUTINE build_cable + + SUBROUTINE drive(k, x, v, a, dcm, w, al, phi) + !! Coupled-end drive: a lateral sway with a roll of the parent about the line axis (3 rad/s, + !! more than a turn by step 250) and an imposed twist following it. + INTEGER, INTENT(IN) :: k + REAL(wp), INTENT(OUT) :: x(3), v(3), a(3), dcm(3, 3), w(3), al(3), phi + REAL(wp), PARAMETER :: DT = 0.01_wp, AMP = 0.05_wp, OM = 2.0_wp, ROLL_RATE = 3.0_wp + REAL(wp) :: t + t = DT*REAL(k, wp) + x = [LL, AMP*SIN(OM*t), 0.0_wp] + v = [0.0_wp, AMP*OM*COS(OM*t), 0.0_wp] + a = [0.0_wp, -AMP*OM*OM*SIN(OM*t), 0.0_wp] + dcm = roll_x(ROLL_RATE*t) + w = [ROLL_RATE, 0.0_wp, 0.0_wp] + al = 0.0_wp + phi = 1.0_wp - ROLL_RATE*t + 0.5_wp*SIN(OM*t) + END SUBROUTINE drive + + SUBROUTINE march(cab, k0, k1, ok) + TYPE(CD_HFMF_ModuleType), INTENT(INOUT) :: cab + INTEGER, INTENT(IN) :: k0, k1 + LOGICAL, INTENT(OUT) :: ok + REAL(wp) :: x(3), v(3), a(3), dcm(3, 3), w(3), al(3), phi + INTEGER :: k, es + CHARACTER(300) :: em + ok = .TRUE. + DO k = k0 + 1, k1 + CALL drive(k, x, v, a, dcm, w, al, phi) + CALL CD_HFMF_UpdateStates(cab, x, v, a, es, em, u_orientation=dcm, u_angular_velocity=w, & + u_angular_acceleration=al, u_twist=phi) + IF (es /= CD_HFMF_OK) THEN + WRITE (*, '(A,I0,A)') ' march step ', k, ': '//TRIM(em) + ok = .FALSE. + RETURN + END IF + END DO + END SUBROUTINE march + + ! ------------------------------------------------------------------------------------------ + SUBROUTINE check_quasi_static(label, pinned, compliance) + !! Q: the nodal twist with Irn = 1e-9 kg m against the condensed torsion on the same run. + CHARACTER(*), INTENT(IN) :: label + LOGICAL, INTENT(IN) :: pinned + REAL(wp), INTENT(IN) :: compliance + INTEGER, PARAMETER :: NSTEP = 300 + TYPE(CD_HFMF_ModuleType), ALLOCATABLE :: cc, cn + REAL(wp) :: q(NDOF), x(3), v(3), a(3), dcm(3, 3), w(3), al(3), phi, fc(3), mc(3), fn(3), mn(3) + REAL(wp) :: err_q, err_t, err_n, err_f, err_m, mref, thc, mtc, thn, mtn, ntq(NN) + INTEGER :: k, es, esc, esn + CHARACTER(300) :: em + ALLOCATE (cc, cn) + CALL line_seed(0.3_wp, 0.1_wp, q) + CALL build_cable(cc, q, 1.0_wp, 0.01_wp, 1.0e-10_wp, 0.8_wp, pinned, 0.0_wp, compliance) + CALL build_cable(cn, q, 1.0_wp, 0.01_wp, 1.0e-10_wp, 0.8_wp, pinned, 1.0e-9_wp, compliance) + CALL require(cn%line%tw_active .AND. .NOT. cc%line%tw_active, 'Q '//label//': the nodal twist is active') + err_q = 0.0_wp + err_t = 0.0_wp + err_n = 0.0_wp + err_f = 0.0_wp + err_m = 0.0_wp + mref = GJ/LL + DO k = 1, NSTEP + CALL drive(k, x, v, a, dcm, w, al, phi) + CALL CD_HFMF_UpdateStates(cc, x, v, a, esc, em, u_orientation=dcm, u_angular_velocity=w, & + u_angular_acceleration=al, u_twist=phi) + CALL require(esc == CD_HFMF_OK, 'Q '//label//': condensed step: '//TRIM(em)) + CALL CD_HFMF_UpdateStates(cn, x, v, a, esn, em, u_orientation=dcm, u_angular_velocity=w, & + u_angular_acceleration=al, u_twist=phi) + CALL require(esn == CD_HFMF_OK, 'Q '//label//': nodal step: '//TRIM(em)) + IF (esc /= CD_HFMF_OK .OR. esn /= CD_HFMF_OK) EXIT + err_q = nan_max_abs([err_q, nan_max_abs(cn%line%q - cc%line%q)]) + CALL CD_HermiteCable_Dyn_Torsion_State(cc%line, thc, mtc, es, em) + CALL CD_HermiteCable_Dyn_Torsion_State(cn%line, thn, mtn, es, em) + err_t = nan_max_abs([err_t, ABS(mtn - mtc)/mref]) + CALL CD_HermiteCable_Dyn_Node_Torque(cn%line, ntq, es, em) + err_n = nan_max_abs([err_n, nan_max_abs(ntq - mtc)/mref]) + CALL CD_HFMF_CalcOutput(cc, fc, es, em, y_moment=mc) + CALL CD_HFMF_CalcOutput(cn, fn, es, em, y_moment=mn) + err_f = nan_max_abs([err_f, NORM2(fn - fc)/MAX(1.0_wp, NORM2(fc))]) + err_m = nan_max_abs([err_m, NORM2(mn - mc)/MAX(mref, NORM2(mc))]) + END DO + WRITE (*, '(A,A,A,5ES10.2)') 'Q quasi-static limit (', label, '): q, torque, node torque, end force, '// & + 'end moment ', err_q, err_t, err_n, err_f, err_m + CALL require(err_q <= 1.0e-7_wp, 'Q '//label//': the centreline follows the condensed torsion') + CALL require(err_t <= 1.0e-6_wp, 'Q '//label//': the mean torque is the condensed torque') + CALL require(err_n <= 1.0e-6_wp, 'Q '//label//': every node carries the condensed torque') + CALL require(err_f <= 1.0e-6_wp, 'Q '//label//': the coupled end force agrees') + CALL require(err_m <= 1.0e-6_wp, 'Q '//label//': the coupled end moment agrees') + CALL CD_HFMF_End(cc) + CALL CD_HFMF_End(cn) + END SUBROUTINE check_quasi_static + + ! ------------------------------------------------------------------------------------------ + SUBROUTINE check_waves() + !! W: a roll A sin(Omega t) of the coupled end (amplitude ramped in over the first eight + !! periods) below the first torsional mode of the clamped line, Irn = 0.5 kg m; after the + !! ramp the held end's torque swings with the continuum's amplitude GJ A k / sin(kL). + REAL(wp), PARAMETER :: IRN = 0.5_wp, AMPR = 0.2_wp + INTEGER, PARAMETER :: NPER_RAMP = 8, NPER = 14, NPP = 200 + TYPE(CD_HFMF_ModuleType), ALLOCATABLE :: cab + REAL(wp) :: q(NDOF), c, om1, om, dt, t, env, ang, x(3), kw, ntq(NN), tmax, tmin, expect, ramp_t + INTEGER :: k, es, nstep + CHARACTER(300) :: em + ALLOCATE (cab) + c = SQRT(GJ/IRN) + om1 = PI*c/LL + om = 0.5_wp*om1 + dt = 2.0_wp*PI/om/REAL(NPP, wp) + CALL line_seed(0.0_wp, 0.0_wp, q) + CALL build_cable(cab, q, 0.0_wp, dt, 1.0e-10_wp, 0.9_wp, .FALSE., IRN, 0.0_wp) + x = q(NDOF - 5:NDOF - 3) + nstep = NPER*NPP + ramp_t = REAL(NPER_RAMP, wp)*2.0_wp*PI/om + tmax = -HUGE(1.0_wp) + tmin = HUGE(1.0_wp) + DO k = 1, nstep + t = dt*REAL(k, wp) + env = MIN(t/ramp_t, 1.0_wp) + env = env**3*(10.0_wp - 15.0_wp*env + 6.0_wp*env**2) + ang = AMPR*env*SIN(om*t) + CALL CD_HFMF_UpdateStates(cab, x, [0.0_wp, 0.0_wp, 0.0_wp], [0.0_wp, 0.0_wp, 0.0_wp], es, em, & + u_orientation=roll_x(ang)) + CALL require(es == CD_HFMF_OK, 'W: step: '//TRIM(em)) + IF (es /= CD_HFMF_OK) EXIT + IF (t > ramp_t + 2.0_wp*PI/om) THEN + CALL CD_HermiteCable_Dyn_Node_Torque(cab%line, ntq, es, em) + tmax = MAX(tmax, ntq(1)) + tmin = MIN(tmin, ntq(1)) + END IF + END DO + kw = om/c + expect = GJ*AMPR*kw/SIN(kw*LL) + WRITE (*, '(A,F8.4,A,2ES14.6,A,ES14.6)') 'W torsional wave (Omega/omega_1 = ', om/om1, & + '): held-end torque swing ', 0.5_wp*(tmax - tmin), 0.5_wp*(tmax + tmin), ' expected amplitude ', expect + CALL require(ABS(0.5_wp*(tmax - tmin) - expect) <= 1.0e-2_wp*expect, & + 'W: the held end carries the continuum torque GJ A k / sin(kL)') + CALL require(ABS(0.5_wp*(tmax + tmin)) <= 1.0e-2_wp*expect, 'W: the torque swings about zero') + CALL CD_HFMF_End(cab) + END SUBROUTINE check_waves + + ! ------------------------------------------------------------------------------------------ + SUBROUTINE check_damping() + !! D: torsional damping Bt (torque Bt dtau/dt) is stiffness-proportional, so the first + !! torsional mode of the clamped line has zeta_1 = omega_1 Bt/(2 GJ). The coupled end rolls + !! by 0.2 rad in a quarter period of that mode and holds; the held end's torque then rings + !! down about GJ 0.2/L with the logarithmic decrement 2 pi zeta_1/sqrt(1 - zeta_1^2) of the + !! first mode (the higher modes, damped in proportion to their frequency, die first). + REAL(wp), PARAMETER :: IRN = 0.5_wp, ZETA = 0.05_wp, ROLL = 0.2_wp + INTEGER, PARAMETER :: NPP = 400, NPER = 12 + TYPE(CD_HFMF_ModuleType), ALLOCATABLE :: cab + TYPE(CD_HermiteTorsionType) :: tors + REAL(wp) :: q(NDOF), c, om1, dt, t, ang, x(3), ntq(NN), bt, mst, prev, prev2, delta, expect, tq + REAL(wp) :: peaks(64), l0(NE), eye(3, 3), frame(3, 2) + INTEGER :: k, es, npk + CHARACTER(300) :: em + ALLOCATE (cab) + c = SQRT(GJ/IRN) + om1 = PI*c/LL + bt = 2.0_wp*GJ*ZETA/om1 + dt = 2.0_wp*PI/om1/REAL(NPP, wp) + l0 = LL/REAL(NE, wp) + eye = roll_x(0.0_wp) + CALL line_seed(0.0_wp, 0.0_wp, q) + CALL CD_HFMF_Init(cab, l0, [(EA, es=1, NE)], [(EI, es=1, NE)], [(RHOA, es=1, NE)], [(0.0_wp, es=1, NE)], q, & + [1, 2, 3, NDOF - 5, NDOF - 4, NDOF - 3], 0.0_wp, 0.0_wp, 1.0_wp, dt, NN, es, em, & + max_iter=60, tol=1.0e-10_wp) + CALL CD_HFMF_Set_EndConnection(cab, [0.0_wp, 0.0_wp], RESHAPE([1.0_wp, 0.0_wp, 0.0_wp, 1.0_wp, 0.0_wp, 0.0_wp], & + [3, 2]), es, em, & + coupled_d0_parent=[1.0_wp, 0.0_wp, 0.0_wp], parent_orientation=eye, & + connection_mode=[CD_ENDCONN_RIGID, CD_ENDCONN_RIGID]) + CALL torsion_of(q, 0.0_wp, tors, IRN, 0.0_wp) + ALLOCATE (tors%bt(NE)) + tors%bt = bt + frame(:, 1) = [1.0_wp, 0.0_wp, 0.0_wp] + frame(:, 2) = [0.0_wp, 0.0_wp, 1.0_wp] + CALL CD_HFMF_Set_Torsion(cab, tors, es, em, coupled_frame_parent=frame, parent_orientation=eye) + CALL require(es == CD_HFMF_OK, 'D: damped torsion: '//TRIM(em)) + x = q(NDOF - 5:NDOF - 3) + mst = GJ*ROLL/LL + npk = 0 + prev = 0.0_wp + prev2 = 0.0_wp + DO k = 1, NPER*NPP + t = dt*REAL(k, wp) + ang = ROLL*MIN(1.0_wp, t/(0.25_wp*2.0_wp*PI/om1)) + CALL CD_HFMF_UpdateStates(cab, x, [0.0_wp, 0.0_wp, 0.0_wp], [0.0_wp, 0.0_wp, 0.0_wp], es, em, & + u_orientation=roll_x(ang)) + CALL require(es == CD_HFMF_OK, 'D: step: '//TRIM(em)) + IF (es /= CD_HFMF_OK) EXIT + CALL CD_HermiteCable_Dyn_Node_Torque(cab%line, ntq, es, em) + tq = ntq(1) - mst + ! local maxima of the deviation after the first two periods + IF (k > 2 .AND. t > 2.0_wp*2.0_wp*PI/om1 .AND. prev > prev2 .AND. prev >= tq .AND. prev > 0.0_wp) THEN + IF (npk < SIZE(peaks)) THEN + npk = npk + 1 + peaks(npk) = prev + END IF + END IF + prev2 = prev + prev = tq + END DO + CALL require(npk >= 4, 'D: the torque rings down through several periods') + IF (npk < 4) RETURN + delta = LOG(peaks(1)/peaks(4))/3.0_wp + expect = 2.0_wp*PI*ZETA/SQRT(1.0_wp - ZETA**2) + WRITE (*, '(A,F8.5,A,F8.5,A,ES10.3)') 'D torsional damping: logarithmic decrement ', delta, ' expected ', & + expect, '; mean torque - GJ roll/L ', ntq(1) - mst + CALL require(ABS(delta - expect) <= 0.1_wp*expect, 'D: the first torsional mode decays at zeta = omega Bt/(2 GJ)') + CALL CD_HFMF_End(cab) + END SUBROUTINE check_damping + + ! ------------------------------------------------------------------------------------------ + SUBROUTINE energy_run(phi, irn, band, e_vib) + !! Free vibration of the bowed line clamped at both ends (no gravity, no fluid), rho_inf = 1, + !! ten periods of the first bending mode; band = (max - min) of kinetic + elastic over the + !! run, relative to the vibration energy above the straight twisted state. + REAL(wp), INTENT(IN) :: phi, irn + REAL(wp), INTENT(OUT) :: band, e_vib + TYPE(CD_HermiteCableDynType) :: m + TYPE(CD_HermiteTorsionType) :: tors + REAL(wp) :: q(NDOF), l0(NE), ke, se, e0, emax, emin, t1, dt, e_straight + INTEGER :: k, es, nstep + CHARACTER(300) :: em + l0 = LL/REAL(NE, wp) + CALL line_seed(0.05_wp, 0.03_wp, q) + CALL CD_HermiteCable_Dyn_Init(m, l0, [(EA, k=1, NE)], [(EI, k=1, NE)], [(RHOA, k=1, NE)], [(0.0_wp, k=1, NE)], q, & + [1, 2, 3, NDOF - 5, NDOF - 4, NDOF - 3], 0.0_wp, 0.0_wp, 1.0_wp, es, em) + CALL require(es == CD_HCDYN_OK, 'E: init: '//TRIM(em)) + CALL CD_HermiteCable_Dyn_Set_EndConnection(m, [0.0_wp, 0.0_wp], & + RESHAPE([1.0_wp, 0.0_wp, 0.0_wp, 1.0_wp, 0.0_wp, 0.0_wp], [3, 2]), & + es, em, connection_mode=[CD_ENDCONN_RIGID, CD_ENDCONN_RIGID]) + CALL require(es == CD_HCDYN_OK, 'E: end connections: '//TRIM(em)) + e_straight = 0.0_wp + IF (phi > 0.0_wp) THEN + CALL torsion_of(q, phi, tors, irn, 0.0_wp) + CALL CD_HermiteCable_Dyn_Set_Torsion(m, tors, es, em) + CALL require(es == CD_HCDYN_OK, 'E: torsion: '//TRIM(em)) + e_straight = 0.5_wp*(LL/GJ)*(GJ*phi/LL)**2 + END IF + t1 = 2.0_wp*PI/(22.373_wp*SQRT(EI/(RHOA*LL**4))) + dt = t1/400.0_wp + nstep = 4000 + CALL CD_HermiteCable_Dyn_Energy(m, ke, se, es, em) + e0 = ke + se + e_vib = e0 - e_straight + emax = e0 + emin = e0 + DO k = 1, nstep + CALL CD_HermiteCable_Dyn_Step(m, dt, 40, 1.0e-10_wp, es, em) + IF (es /= CD_HCDYN_OK) THEN + CALL require(.FALSE., 'E: step: '//TRIM(em)) + EXIT + END IF + CALL CD_HermiteCable_Dyn_Energy(m, ke, se, es, em) + emax = nan_max_abs([emax, ke + se]) + emin = MIN(emin, ke + se) + END DO + band = (emax - emin)/e_vib + CALL CD_HermiteCable_Dyn_End(m) + END SUBROUTINE energy_run + + SUBROUTINE check_energy() + REAL(wp) :: band0, band1, ev0, ev1 + CALL energy_run(0.0_wp, 0.0_wp, band0, ev0) + CALL energy_run(4.0_wp, 0.02_wp, band1, ev1) + WRITE (*, '(A,ES10.3,A,ES10.3,A)') 'E energy band over 10 periods (rho_inf = 1): nodal twist ', band1, & + ', untwisted ', band0, ' of the vibration energy' + CALL require(band1 <= 5.0e-3_wp, 'E: kinetic + elastic energy with the nodal twist conserved within 0.5 %') + END SUBROUTINE check_energy + + ! ------------------------------------------------------------------------------------------ + SUBROUTINE check_restart() + !! R: 150 steps, snapshot, 100 more; restore and redo the 100: identical. A fresh module + !! rebuilt from the mirror at step 150 continues identically too. + TYPE(CD_HFMF_ModuleType), ALLOCATABLE :: cab, cab2 + REAL(wp) :: q(NDOF), qref(NDOF), pref(NN), qb(NDOF), pb(NN) + REAL(wp), ALLOCATABLE :: mirror(:) + INTEGER :: es + LOGICAL :: ok + CHARACTER(300) :: em + ALLOCATE (cab, cab2) + CALL line_seed(0.3_wp, 0.1_wp, q) + CALL build_cable(cab, q, 1.0_wp, 0.01_wp, 1.0e-10_wp, 0.8_wp, .FALSE., 0.05_wp, 0.0_wp) + CALL march(cab, 0, 150, ok) + CALL require(ok, 'R: first leg') + CALL CD_HFMF_Snapshot(cab, es, em) + CALL require(es == CD_HFMF_OK, 'R: snapshot: '//TRIM(em)) + ALLOCATE (mirror(CD_HFMF_MirrorSize(cab))) + CALL CD_HFMF_PackMirror(cab, mirror, es, em) + CALL require(es == CD_HFMF_OK, 'R: mirror pack: '//TRIM(em)) + CALL march(cab, 150, 250, ok) + CALL require(ok, 'R: second leg') + qref = cab%line%q + pref = cab%line%tw_phi + CALL CD_HFMF_Restore(cab, es, em) + CALL require(es == CD_HFMF_OK, 'R: restore: '//TRIM(em)) + CALL march(cab, 150, 250, ok) + qb = cab%line%q + pb = cab%line%tw_phi + CALL require(ok .AND. ALL(bits(qb) == bits(qref)) .AND. ALL(bits(pb) == bits(pref)), & + 'R: the restored run continues bit-identically') + CALL line_seed(0.3_wp, 0.1_wp, q) + CALL build_cable(cab2, q, 1.0_wp, 0.01_wp, 1.0e-10_wp, 0.8_wp, .FALSE., 0.05_wp, 0.0_wp) + CALL CD_HFMF_UnpackMirror(cab2, mirror, 1.5_wp, es, em) + CALL require(es == CD_HFMF_OK, 'R: mirror reload: '//TRIM(em)) + CALL march(cab2, 150, 250, ok) + CALL require(ok .AND. ALL(bits(cab2%line%q) == bits(qref)) .AND. ALL(bits(cab2%line%tw_phi) == bits(pref)), & + 'R: the run rebuilt from the mirror continues bit-identically') + WRITE (*, '(A,F10.4,A)') 'R restart: end twist angle ', pref(NN), ' rad, snapshot and mirror runs identical' + CALL CD_HFMF_End(cab) + CALL CD_HFMF_End(cab2) + END SUBROUTINE check_restart + + ELEMENTAL INTEGER(8) FUNCTION bits(x) + REAL(wp), INTENT(IN) :: x + bits = TRANSFER(x, 0_8) + END FUNCTION bits + +END PROGRAM test_nodal_twist_dynamic diff --git a/tests/test_step_allocations.f90 b/tests/test_step_allocations.f90 index 13e16441..e5bc065c 100644 --- a/tests/test_step_allocations.f90 +++ b/tests/test_step_allocations.f90 @@ -21,10 +21,12 @@ PROGRAM test_step_allocations !! coupled end swaying while the parent rolls about the line axis and the imposed twist !! changes, so every step evaluates the twist kernel, its Hessian and the bordered solve. The !! committed-state outputs (CD_HFMF_SetCoupledKinematics, CD_HFMF_CalcOutput with the connection - !! moment, both end forces, the energy and the torque query) are gated as well. + !! moment, both end forces, the energy and the torque query) are gated as well. With "nodal" + !! the same cable carries the nodal twist (polar inertia and torsional damping), with its + !! 7-DOF-per-node band and the node-torque and element-twist queries. !! !! Usage: test_step_allocations [ranges] - !! test_step_allocations torsion + !! test_step_allocations torsion | nodal USE, INTRINSIC :: ISO_C_BINDING, ONLY: C_INT, C_LONG_LONG USE CableDyn_Precision, ONLY: wp USE CableDyn_EndConnection, ONLY: CD_ENDCONN_RIGID @@ -33,7 +35,8 @@ PROGRAM test_step_allocations CD_HFMF_Set_Torsion, CD_HFMF_UpdateStates, CD_HFMF_CalcOutput, CD_HFMF_End, & CD_HFMF_SetCoupledKinematics USE CableDyn_HermiteCableDynamic, ONLY: CD_HermiteCable_Dyn_End_Force, CD_HermiteCable_Dyn_Energy, & - CD_HermiteCable_Dyn_Torsion_State + CD_HermiteCable_Dyn_Torsion_State, CD_HermiteCable_Dyn_Node_Torque, & + CD_HermiteCable_Dyn_Element_Twist USE CableDyn_OpenFAST_Aggregate, ONLY: CD_AGG_ModuleType, CD_AGG_Init_From_Deck, CD_AGG_NMovingPoints, & CD_AGG_NFluidNodes, CD_AGG_NumChannels, CD_AGG_GetMovingPointMesh, & CD_AGG_Snapshot, CD_AGG_SetFluidFields, CD_AGG_Step_Moving, & @@ -64,8 +67,8 @@ END SUBROUTINE cd_test_allocation_counting IF (COMMAND_ARGUMENT_COUNT() == 1) THEN CALL GET_COMMAND_ARGUMENT(1, arg) - IF (TRIM(arg) /= 'torsion') ERROR STOP 'a single argument must be "torsion"' - CALL torsion_gate() + IF (TRIM(arg) /= 'torsion' .AND. TRIM(arg) /= 'nodal') ERROR STOP 'a single argument must be "torsion" or "nodal"' + CALL torsion_gate(TRIM(arg) == 'nodal') STOP END IF IF (COMMAND_ARGUMENT_COUNT() /= 3 .AND. COMMAND_ARGUMENT_COUNT() /= 4) THEN @@ -169,14 +172,16 @@ SUBROUTINE march(first_step, count, counted) END DO END SUBROUTINE march - SUBROUTINE torsion_gate() - !! Zero heap allocation in CD_HFMF_UpdateStates of a cable with condensed torsion. + SUBROUTINE torsion_gate(nodal) + !! Zero heap allocation in CD_HFMF_UpdateStates of a cable with condensed torsion, or with the + !! nodal twist. + LOGICAL, INTENT(IN) :: nodal INTEGER, PARAMETER :: NE = 20, NN = NE + 1, NDOF = 6*NN, N_WARM = 40, N_COUNT = 200 REAL(wp), PARAMETER :: LL = 10.0_wp, DTT = 0.01_wp TYPE(CD_HFMF_ModuleType) :: cab TYPE(CD_HermiteTorsionType) :: tors REAL(wp) :: q(NDOF), l0(NE), eye(3, 3), frame(3, 2), t, x(3), v(3), a(3), dcm(3, 3), f(3), m(3), psi - REAL(wp) :: fe(3), ke, se, th, mt + REAL(wp) :: fe(3), ke, se, th, mt, ntq(NN), etw(NE) INTEGER :: k INTEGER(C_LONG_LONG) :: c0, n_alloc, n_out, n_energy n_out = 0 @@ -206,6 +211,11 @@ SUBROUTINE torsion_gate() 0.0_wp, 0.0_wp, 1.0_wp], [3, 4]) ALLOCATE (tors%gj(NE)) tors%gj = 80.0_wp + IF (nodal) THEN + ALLOCATE (tors%irn(NE), tors%bt(NE)) + tors%irn = 0.05_wp + tors%bt = 0.5_wp + END IF tors%has_theta = .TRUE. frame(:, 1) = [1.0_wp, 0.0_wp, 0.0_wp] frame(:, 2) = [0.0_wp, 0.0_wp, 1.0_wp] @@ -241,6 +251,8 @@ SUBROUTINE torsion_gate() IF (es == 0) CALL CD_HermiteCable_Dyn_End_Force(cab%line, 1, fe, es, em) IF (es == 0) CALL CD_HermiteCable_Dyn_End_Force(cab%line, NN, fe, es, em) IF (es == 0) CALL CD_HermiteCable_Dyn_Torsion_State(cab%line, th, mt, es, em) + IF (es == 0 .AND. nodal) CALL CD_HermiteCable_Dyn_Node_Torque(cab%line, ntq, es, em) + IF (es == 0 .AND. nodal) CALL CD_HermiteCable_Dyn_Element_Twist(cab%line, etw, es, em) CALL cd_test_allocation_counting(0_C_INT) CALL check('torsion cable output') n_out = n_out + (cd_test_allocation_count() - c0) @@ -254,6 +266,7 @@ SUBROUTINE torsion_gate() CALL check('torsion cable energy') IF (k > N_WARM) n_energy = MAX(n_energy, cd_test_allocation_count() - c0) END DO + IF (nodal .AND. .NOT. cab%line%tw_active) ERROR STOP 'the nodal gate runs without the nodal twist' CALL CD_HFMF_End(cab) PRINT '(A,I0,A,I0,A,I0,A)', 'torsion cable: ', N_COUNT, ' counted steps, ', n_alloc, & ' heap allocations in the steps, ', n_out, ' in the outputs' diff --git a/tests/test_torsion_coupling.f90 b/tests/test_torsion_coupling.f90 index e47055bf..75e8fdcd 100644 --- a/tests/test_torsion_coupling.f90 +++ b/tests/test_torsion_coupling.f90 @@ -22,6 +22,9 @@ PROGRAM test_torsion_coupling !! end there, and accepts the march rolled the other way. !! 8. The coupled aggregate: a non-stepping update at the unchanged boundary is accepted (the !! preflight's twist carries the coupling, -8 rad here). + !! 9. The march with the torsional damping of GJ|K|Bt: a damping ratio (Bt < 0) gives the + !! run of the Bt it resolves to, -Bt l0 sqrt(GJ Irn), bit for bit; a fourth part of the + !! GJ column fails closed. USE CableDyn_Precision, ONLY: wp USE CableDyn_HermiteTorsion, ONLY: CD_HermiteTorsion_Line, CD_HTORS_OK, CD_HTORS_KBAND USE CableDyn_DeckDriver, ONLY: CD_Run_Deck_Driver, CD_DECKDRV_OK @@ -40,6 +43,7 @@ PROGRAM test_torsion_coupling CALL check_pretwist() CALL check_zero_and_refusal() CALL check_dynamic() + CALL check_damping_grammar() CALL check_recovery() CALL check_compression() CALL check_aggregate() @@ -297,6 +301,65 @@ SUBROUTINE check_aggregate() CALL CD_AGG_End(agg, es, em) END SUBROUTINE check_aggregate + SUBROUTINE check_damping_grammar() + !! The march of check_dynamic (its motion file) with Bt as a damping ratio (1e6, visible with + !! the negligible Irn of the case) and as the value + !! it resolves to on the 40 elements of 99/40 m (Irn 1e-9 kg m): the same outputs, byte for + !! byte; GJ|K|Bt|x is refused by name. + REAL(wp) :: bt + CHARACTER(64) :: gjtxt + LOGICAL :: conv + INTEGER :: es + CHARACTER(512) :: em + bt = 1.0e6_wp*(L0/40.0_wp)*SQRT(GJ*1.0e-9_wp) + CALL write_case('tcpl_zeta.dat', 'Rigid 1 0 0 Rigid 0 0 1 0', 'Rigid 1 0 0 Rigid 0 0 1 0', KTT, dynamic=.TRUE., & + gj_text='5.0e4|4.0e5|-1.0e6') + CALL CD_Run_Deck_Driver('tcpl_zeta.dat', 'tcpl_zeta', conv, es, em) + CALL require(es == CD_DECKDRV_OK .AND. conv, 'the march with a torsional damping ratio runs: '//TRIM(em)) + WRITE (gjtxt, '(A,ES24.16)') '5.0e4|4.0e5|', bt + gjtxt = remove_blanks(gjtxt) + CALL write_case('tcpl_bt.dat', 'Rigid 1 0 0 Rigid 0 0 1 0', 'Rigid 1 0 0 Rigid 0 0 1 0', KTT, dynamic=.TRUE., & + gj_text=TRIM(gjtxt)) + CALL CD_Run_Deck_Driver('tcpl_bt.dat', 'tcpl_bt', conv, es, em) + CALL require(es == CD_DECKDRV_OK .AND. conv, 'the march with the resolved torsional damping runs: '//TRIM(em)) + CALL require(same_file('tcpl_zeta.out', 'tcpl_bt.out'), & + 'a torsional damping ratio is the Bt it resolves to, -Bt l0 sqrt(GJ Irn), bit for bit') + CALL require(.NOT. same_file('tcpl_bt.out', 'tcpl_dyn.out'), 'the torsional damping changes the march') + CALL write_case('tcpl_bad4.dat', 'Rigid 1 0 0 Rigid 0 0 1 0', 'Rigid 1 0 0 Rigid 0 0 1 0', KTT, & + gj_text='5.0e4|0|1.0|2.0') + CALL CD_Run_Deck_Driver('tcpl_bad4.dat', 'tcpl_bad4', conv, es, em) + CALL require(es /= CD_DECKDRV_OK .AND. INDEX(em, 'takes GJ, GJ|K or GJ|K|Bt') > 0, & + 'a fourth part of the GJ column fails closed: '//TRIM(em)) + END SUBROUTINE check_damping_grammar + + LOGICAL FUNCTION same_file(a, b) RESULT(same) + !! Byte-identical text files. + CHARACTER(*), INTENT(IN) :: a, b + INTEGER :: ua, ub, ia, ib + CHARACTER(4096) :: la, lb + same = .FALSE. + OPEN (NEWUNIT=ua, FILE=a, STATUS='OLD', ACTION='READ', IOSTAT=ia) + IF (ia /= 0) RETURN + OPEN (NEWUNIT=ub, FILE=b, STATUS='OLD', ACTION='READ', IOSTAT=ib) + IF (ib /= 0) THEN + CLOSE (ua) + RETURN + END IF + DO + READ (ua, '(A)', IOSTAT=ia) la + READ (ub, '(A)', IOSTAT=ib) lb + IF (ia /= 0 .OR. ib /= 0) EXIT + IF (la /= lb) THEN + CLOSE (ua) + CLOSE (ub) + RETURN + END IF + END DO + same = ia /= 0 .AND. ib /= 0 + CLOSE (ua) + CLOSE (ub) + END FUNCTION same_file + SUBROUTINE straight_case(root, conn_a, conn_b, k, v, torsion, length, option) !! The straight case at TMax = 0: v = FairTen1, Torq1N1, Twist1, Ten1N21 (Twist and Torq zero !! for a line without torsion). @@ -333,15 +396,15 @@ SUBROUTINE straight_case(root, conn_a, conn_b, k, v, torsion, length, option) CLOSE (u) END SUBROUTINE straight_case - SUBROUTINE write_case(path, conn_a, conn_b, k, torsion, dynamic, length, option) + SUBROUTINE write_case(path, conn_a, conn_b, k, torsion, dynamic, length, option, gj_text) !! A 99 m (or length) neutral cable from a Coupled End A to a Fixed End B 100 m apart along +x, 40 - !! elements, TMax 0; the GJ column carries GJ|K (k < 0 writes the plain GJ); option is one more - !! OPTIONS row. + !! elements, TMax 0; the GJ column carries GJ|K (k < 0 writes the plain GJ), or gj_text as given; + !! option is one more OPTIONS row. CHARACTER(*), INTENT(IN) :: path, conn_a, conn_b REAL(wp), INTENT(IN) :: k LOGICAL, INTENT(IN), OPTIONAL :: torsion, dynamic REAL(wp), INTENT(IN), OPTIONAL :: length - CHARACTER(*), INTENT(IN), OPTIONAL :: option + CHARACTER(*), INTENT(IN), OPTIONAL :: option, gj_text INTEGER :: u CHARACTER(64) :: gjcol, lcol LOGICAL :: tors, dyn @@ -355,6 +418,7 @@ SUBROUTINE write_case(path, conn_a, conn_b, k, torsion, dynamic, length, option) WRITE (gjcol, '(ES12.5,A,ES12.5)') GJ, '|', k END IF gjcol = remove_blanks(gjcol) + IF (PRESENT(gj_text)) gjcol = gj_text lcol = '99.0' IF (PRESENT(length)) WRITE (lcol, '(F10.4)') length OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') @@ -362,8 +426,9 @@ SUBROUTINE write_case(path, conn_a, conn_b, k, torsion, dynamic, length, option) WRITE (u, '(A)') '--- LINE TYPES ---' WRITE (u, '(A)') 'Name Diam Mass EA BA EI GAs GJ Irt Irn Cdn Cdt Can Cat' WRITE (u, '(A)') '(-) (m) (kg/m) (N) (-) (Nm2) (N) (Nm2) (kgm) (kgm) (-) (-) (-) (-)' + ! Irn 1e-9: the march's quasi-static end state (the nodal twist without polar inertia) WRITE (u, '(A,ES24.16,A)') 'cab 0.2 ', RHOW*0.25_wp*PI*0.04_wp, ' 1.0e7 0.0 1.0e6 1.0e8 '//TRIM(gjcol)// & - ' 1.0 1.0 0.0 0.0 0.0 0.0' + ' 1.0 1.0e-9 0.0 0.0 0.0 0.0' WRITE (u, '(A)') '--- POINTS ---' WRITE (u, '(A)') 'ID Type X Y Z Mass Vol CdA Ca' WRITE (u, '(A)') '(-) (-) (m) (m) (m) (kg) (m3) (m2) (-)' diff --git a/tests/test_torsion_deck.f90 b/tests/test_torsion_deck.f90 index 428fa7ac..36734b9c 100644 --- a/tests/test_torsion_deck.f90 +++ b/tests/test_torsion_deck.f90 @@ -45,9 +45,12 @@ PROGRAM test_torsion_deck CHARACTER(16) :: arg CHARACTER(8) :: no_rows(0) - ! neutral 0.2 m section: mass = rhoW pi d^2 / 4; EA 1e7, EI 1e6, GAs 1e8, GJ 5e4 + ! neutral 0.2 m section: mass = rhoW pi d^2 / 4; EA 1e7, EI 1e6, GAs 1e8, GJ 5e4, Irn 1e-12 (the + ! massless-line torsion these gates check, down to the coarse-step pendulum's trapezoidal closed + ! form: the nodal twist's limit of a negligible polar inertia, whose inertia + ! test_nodal_twist_dynamic gates) WRITE (neutral_type, '(A,ES24.16,A)') 'cab 0.2 ', RHOW*0.25_wp*PI*0.04_wp, & - ' 1.0e7 0.0 1.0e6 1.0e8 5.0e4 1.0 1.0 0.0 0.0 0.0 0.0' + ' 1.0e7 0.0 1.0e6 1.0e8 5.0e4 1.0 1.0e-12 0.0 0.0 0.0 0.0' ! optional argument: run only gate 1..9 (diagnostics) only = 0 @@ -911,7 +914,7 @@ SUBROUTINE check_errors() CALL expect_error('an imposed twist above 1000 turns is named', 'tdeck_e16.dat', 'tdeck_e16', & 'line 1: the imposed twist Pretwist(B) - Pretwist(A) = 4.00000E+05 deg exceeds 1000 turns') ! a twist far beyond the buckling onset: the failed stage is named once, with its line - t10(1) = 'cab 0.2 32.2013246 1.0e7 0.0 1.0e6 1.0e8 5.0e4 1.0 1.0 0.0 0.0 0.0 0.0' + t10(1) = 'cab 0.2 32.2013246 1.0e7 0.0 1.0e6 1.0e8 5.0e4 1.0 1.0e-9 0.0 0.0 0.0 0.0' CALL straight_deck('tdeck_e15.dat', 'Rigid 1 0 0 Rigid 0 0 1 0', 'Rigid 1 0 0 Rigid 0 0 1 36000', OUTS, t10) CALL expect_error('a failed torsion stage is named without a doubled prefix', 'tdeck_e15.dat', 'tdeck_e15', & 'CableDyn_DeckDriver: line 1: finite-EI torsion static solve failed') From 389ad6d6f35deb75f536c47bdcec529eb8d45f75 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Fri, 30 Oct 2026 07:55:28 +0900 Subject: [PATCH 2/4] fix(torsion): damp the twist a turning end frame puts into the line An element at a rigid torsional end twists through rho as its end frame turns (a parent rolling it, CD_HFMF_UpdateStates u_orientation), but the torsional damping rate only differentiated the nodal angles and the centreline: a parent rolling the end at a steady rate loaded the line with GJ theta/L alone, without its Bt Omega/L. The step now takes each end frame's angular velocity over the step, log(R_{n+1} R_n^T)/dt (tw_frame_rates), and the end elements' damping rate adds d rho/dw . omega (end_w of twist_reference). The committed step's rates (tw_om) serve the evaluations of the committed state and join the packed twist state, so the snapshot, the recovering step and the checkpoint mirror carry them. New gate in nodal_twist_dynamic: a parent rolling the coupled end's frame at a steady 0.5 rad/s (Irn 1e-9, Bt 40) loads every node with (GJ theta + Bt Omega)/L to 4e-13 (2.0 of the 12.0 N m is the damping; the unfixed code read 10.0); the restart gate now runs with Bt and stays bit-identical through the snapshot and the mirror. Signed-off-by: Jae Hoon Seo --- src/CableDyn_HermiteCableDynamic.f90 | 61 ++++++++++++++++++++---- tests/test_nodal_twist_dynamic.f90 | 71 ++++++++++++++++++++++++---- 2 files changed, 115 insertions(+), 17 deletions(-) diff --git a/src/CableDyn_HermiteCableDynamic.f90 b/src/CableDyn_HermiteCableDynamic.f90 index f1020ab5..527e35a5 100644 --- a/src/CableDyn_HermiteCableDynamic.f90 +++ b/src/CableDyn_HermiteCableDynamic.f90 @@ -51,6 +51,7 @@ MODULE CableDyn_HermiteCableDynamic !! + (1-alpha_f) gamma/(beta dt) Kv(q_alpha, v_alpha), !! where Kv = dR/dv is the drag velocity Jacobian and gamma/(beta dt) = d v_{n+1}/d q_{n+1}. USE CableDyn_Precision, ONLY: wp, CD_ZERO, CD_ONE, CD_All_Finite, CD_Is_Finite + USE CableDyn_SO3, ONLY: CD_Log_SO3 USE CableDyn_FatalReport, ONLY: CD_Fatal_Thread_Init USE CableDyn_EndConnection, ONLY: CD_EndConn_Spring, CD_EndConn_Energy, & CD_EndConn_Reaction_Moment, CD_EndConn_Basis, & @@ -489,6 +490,10 @@ MODULE CableDyn_HermiteCableDynamic ! the step's residual norm. REAL(wp) :: tw_tsum = CD_ZERO, tw_spsi(2) = CD_ZERO, tw_tscale = CD_ONE REAL(wp), ALLOCATABLE :: tw_su(:, :), tw_stn(:, :), tw_sbeta(:) + ! tw_som(:, k): the angular velocity of end frame k over the running step, log(R_{n+1} + ! R_n^T)/dt (R = [d n d x n]); tw_om: that of the committed step. A turning frame twists + ! the element at a rigid end through rho, and the torsional damping takes that rate. + REAL(wp) :: tw_som(3, 2) = CD_ZERO, tw_om(3, 2) = CD_ZERO ! Packed twist state (tw_pack) of the recovering step's interval start and of the snapshot, ! and the snapshot's tw_fcR. REAL(wp), ALLOCATABLE :: ws_recovery_tw(:), snap_tw(:), snap_tw_fcR(:) @@ -3872,6 +3877,7 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r ! Condensed torsion: F_n above used the committed end frames and Phi; every evaluation of the ! step from here on uses the step's target (set by CD_HermiteCable_Dyn_Step). model%tors_use_step = model%torsion%active + IF (model%tw_active) CALL tw_frame_rates(model, dt) ! Newton predictor. The standard Newmark guess q_n + dt v_n + dt^2 (1/2 - beta) a_n (the ! acceleration map's base a_{n+1} = 0) is a far better start than q_n when the state is ! moving. When the committed acceleration is the physical one, the constant-acceleration @@ -4542,6 +4548,7 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r model%tw_w(iv) = model%tw_wn(iv) + dt*((CD_ONE - gm)*model%tw_an(iv) + gm*model%tw_ak(iv)) END DO CALL tw_commit_reference(model) + model%tw_om = model%tw_som DO iv = 1, model%ne model%tw_mt(iv) = model%tw_me(iv) END DO @@ -6754,8 +6761,8 @@ END SUBROUTINE CD_HermiteCable_Dyn_Twist_Check PURE INTEGER FUNCTION CD_HermiteCable_Dyn_Twist_Mirror_Size(model) RESULT(n) !! Reals of the nodal-twist checkpoint mirror (CD_HermiteCable_Dyn_Twist_Pack): the !! committed angles, rates and accelerations, directors, reference tangents, reference - !! twists, element torques, end-frame references and the force cache's angle part; 0 without - !! the nodal twist. + !! twists, element torques, end-frame references and rates, and the force cache's angle + !! part; 0 without the nodal twist. TYPE(CD_HermiteCableDynType), INTENT(IN) :: model n = 0 IF (model%tw_active) n = tw_pack_size(model) + model%nn @@ -7970,6 +7977,8 @@ SUBROUTINE CD_HermiteCable_Dyn_End(model) model%tw_lk = CD_ZERO model%tw_tsum = CD_ZERO model%tw_spsi = CD_ZERO + model%tw_som = CD_ZERO + model%tw_om = CD_ZERO model%tw_tscale = CD_ONE model%snap_valid = .FALSE. model%require_tensile = .FALSE. @@ -8613,10 +8622,10 @@ END SUBROUTINE assemble_torsion PURE INTEGER FUNCTION tw_pack_size(model) RESULT(n) !! Reals of the packed twist state of tw_pack: the angles, rates and accelerations, the - !! directors and unit tangents, the reference twists, the element torques and the two - !! end-frame references. + !! directors and unit tangents, the reference twists, the element torques, the two + !! end-frame references and the end frames' angular velocities of the committed step. TYPE(CD_HermiteCableDynType), INTENT(IN) :: model - n = 9*model%nn + 2*model%ne + 2 + n = 9*model%nn + 2*model%ne + 8 END FUNCTION tw_pack_size PURE SUBROUTINE tw_pack(model, buf) @@ -8633,6 +8642,7 @@ PURE SUBROUTINE tw_pack(model, buf) buf(9*nn + 1:9*nn + ne) = model%tw_beta buf(9*nn + ne + 1:9*nn + 2*ne) = model%tw_mt buf(9*nn + 2*ne + 1:9*nn + 2*ne + 2) = model%tw_psi + buf(9*nn + 2*ne + 3:9*nn + 2*ne + 8) = RESHAPE(model%tw_om, [6]) END SUBROUTINE tw_pack PURE SUBROUTINE tw_unpack(model, buf) @@ -8649,6 +8659,7 @@ PURE SUBROUTINE tw_unpack(model, buf) model%tw_beta = buf(9*nn + 1:9*nn + ne) model%tw_mt = buf(9*nn + ne + 1:9*nn + 2*ne) model%tw_psi = buf(9*nn + 2*ne + 1:9*nn + 2*ne + 2) + model%tw_om = RESHAPE(buf(9*nn + 2*ne + 3:9*nn + 2*ne + 8), [3, 2]) END SUBROUTINE tw_unpack ELEMENTAL REAL(wp) FUNCTION tw_wrap(x) RESULT(y) @@ -8925,6 +8936,8 @@ SUBROUTINE assemble_twist(model, q_cfg, v_cfg, want_residual, want_tangent, R, K CHARACTER(*), INTENT(OUT) :: ErrMsg REAL(wp), POINTER :: phi(:), w(:) REAL(wp) :: ends(3, 4), phi_end, rho, beta, g(12), h(12, 12), ve(12), hv(12), ke(12, 12), kel, kd + REAL(wp) :: om(3, 2), ew(3, 2) + LOGICAL :: turning REAL(wp) :: tau, rate, mt, psi, gl(3), hl(3, 3), k, tw INTEGER :: e, iend, node, b, i, j, es CHARACTER(1024) :: em @@ -8941,8 +8954,20 @@ SUBROUTINE assemble_twist(model, q_cfg, v_cfg, want_residual, want_tangent, R, K END IF IF (want_residual) model%tw_R = CD_ZERO model%tw_tsum = CD_ZERO + om = MERGE(model%tw_som, model%tw_om, model%tors_use_step) + turning = ANY(om /= CD_ZERO) .AND. ALLOCATED(model%torsion%bt) DO e = 1, model%ne - CALL twist_reference(model, e, q_cfg, ends, want_tangent, rho, beta, g, h, es, em) + kd = CD_ZERO + IF (ALLOCATED(model%torsion%bt)) kd = model%torsion%bt(e)/model%l0(e) + ! an element at a rigid end twists through rho as its end frame turns: its damping rate + ! takes d rho/dw . omega of the frames (the tangent keeps the rate's q-dependence through + ! g only, as the frame's share of it is of order omega dt) + IF (turning .AND. kd > CD_ZERO .AND. (e == 1 .OR. e == model%ne)) THEN + CALL twist_reference(model, e, q_cfg, ends, want_tangent, rho, beta, g, h, es, em, end_w=ew) + ELSE + CALL twist_reference(model, e, q_cfg, ends, want_tangent, rho, beta, g, h, es, em) + ew = CD_ZERO + END IF IF (es /= CD_HCDYN_OK) THEN ErrStat = es ErrMsg = TRIM(em) @@ -8950,10 +8975,9 @@ SUBROUTINE assemble_twist(model, q_cfg, v_cfg, want_residual, want_tangent, R, K END IF ve = v_cfg(6*e - 5:6*e + 6) kel = model%torsion%gj(e)/model%l0(e) - kd = CD_ZERO - IF (ALLOCATED(model%torsion%bt)) kd = model%torsion%bt(e)/model%l0(e) tau = phi(e + 1) - phi(e) + rho rate = w(e + 1) - w(e) + DOT_PRODUCT(g, ve) + IF (turning .AND. kd > CD_ZERO) rate = rate + DOT_PRODUCT(ew(:, 1), om(:, 1)) + DOT_PRODUCT(ew(:, 2), om(:, 2)) mt = kel*tau + kd*rate model%tw_me(e) = mt model%tw_tsum = model%tw_tsum + tau @@ -9220,6 +9244,8 @@ SUBROUTINE tw_init(model, mt, ErrStat, ErrMsg) ! a rigid end's element takes its end-frame constant in tw_beta: its formula at the ! committed state is tw_beta itself, so take the director angle of the gauge directly model%tw_psi = CD_ZERO + model%tw_som = CD_ZERO + model%tw_om = CD_ZERO IF (.NOT. model%tw_rigid(1)) model%tw_psi(1) = CD_HermiteTwist_Angle(model%tw_u(:, 1), & CD_HermiteTwist_Carry(ends(:, 1), & model%tw_tn(:, 1), & @@ -9365,6 +9391,25 @@ SUBROUTINE tw_advance_reference(model, q_new, ends_new, ErrStat, ErrMsg) END DO END SUBROUTINE tw_advance_reference + SUBROUTINE tw_frame_rates(model, dt) + !! tw_som: the angular velocity of each end frame from the committed frames to the step's, + !! log(R_{n+1} R_n^T)/dt with R = [d n d x n] (spatial, as end_w of twist_reference). + TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model + REAL(wp), INTENT(IN) :: dt + REAL(wp) :: r0(3, 3), r1(3, 3) + INTEGER :: k + model%tw_som = CD_ZERO + IF (.NOT. dt > CD_ZERO) RETURN + DO k = 1, 2 + IF (ALL(model%tors_step_ends(:, 2*k - 1:2*k) == model%torsion%ends(:, 2*k - 1:2*k))) CYCLE + r0(:, 1:2) = model%torsion%ends(:, 2*k - 1:2*k) + r0(:, 3) = tw_cross(r0(:, 1), r0(:, 2)) + r1(:, 1:2) = model%tors_step_ends(:, 2*k - 1:2*k) + r1(:, 3) = tw_cross(r1(:, 1), r1(:, 2)) + model%tw_som(:, k) = CD_Log_SO3(MATMUL(r1, TRANSPOSE(r0)))/dt + END DO + END SUBROUTINE tw_frame_rates + SUBROUTINE tw_commit_reference(model) !! Make the reference state of tw_advance_reference the committed one. TYPE(CD_HermiteCableDynType), INTENT(INOUT) :: model diff --git a/tests/test_nodal_twist_dynamic.f90 b/tests/test_nodal_twist_dynamic.f90 index d8c5e71c..dd2a5074 100644 --- a/tests/test_nodal_twist_dynamic.f90 +++ b/tests/test_nodal_twist_dynamic.f90 @@ -13,11 +13,13 @@ PROGRAM test_nodal_twist_dynamic !! roll at one end below its first torsional mode, carries at the other end the torque of !! the continuum, GJ A k / sin(kL) with k = Omega sqrt(Irn/GJ); !! D torsional damping: the first torsional mode rings down at zeta_1 = omega_1 Bt/(2 GJ); + !! a parent rolling its end frame at a steady rate Omega (negligible Irn) loads the held + !! end with (GJ theta + Bt Omega)/L, the damping of the frame's own turn included; !! E energy: free vibration of a bowed, twisted line with a real Irn (rho_inf = 1): kinetic !! (with the polar part) + elastic (with the twist) stays within the band of the line !! without torsion; - !! R restart: a rolling run restored from a snapshot, and one rebuilt from the checkpoint - !! mirror, continue bit-identically. + !! R restart: a rolling, torsionally damped run restored from a snapshot, and one rebuilt + !! from the checkpoint mirror, continue bit-identically. USE CableDyn_Precision, ONLY: wp USE CableDyn_EndConnection, ONLY: CD_ENDCONN_RIGID USE CableDyn_HermiteTorsion, ONLY: CD_HermiteTorsionType, CD_HermiteTorsion_Line, CD_HermiteTorsion_Unwrap, & @@ -43,6 +45,7 @@ PROGRAM test_nodal_twist_dynamic CALL check_quasi_static('elastic', .FALSE., 0.05_wp) CALL check_waves() CALL check_damping() + CALL check_frame_damping() CALL check_energy() CALL check_restart() @@ -95,12 +98,13 @@ SUBROUTINE line_seed(bow_y, bow_z, q) END DO END SUBROUTINE line_seed - SUBROUTINE torsion_of(q, phi, tors, irn, compliance) + SUBROUTINE torsion_of(q, phi, tors, irn, compliance, bt) !! Torsion of the line: both ends along +x with reference normal +z, GJ on every element, !! imposed twist phi, Theta of the seed q (branch nearest 0); irn > 0 adds the polar inertia - !! (nodal twist), compliance the torsional end compliances. + !! (nodal twist), compliance the torsional end compliances, bt the torsional damping. REAL(wp), INTENT(IN) :: q(NDOF), phi, irn, compliance TYPE(CD_HermiteTorsionType), INTENT(OUT) :: tors + REAL(wp), INTENT(IN), OPTIONAL :: bt REAL(wp) :: g(NDOF), raw, l0(NE) INTEGER :: es CHARACTER(200) :: em @@ -116,19 +120,24 @@ SUBROUTINE torsion_of(q, phi, tors, irn, compliance) ALLOCATE (tors%irn(NE)) tors%irn = irn END IF + IF (PRESENT(bt)) THEN + ALLOCATE (tors%bt(NE)) + tors%bt = bt + END IF CALL CD_HermiteTorsion_Line(q, l0, tors%ends, raw, g, es, em) CALL require(es == CD_HTORS_OK, 'seed twist evaluates: '//TRIM(em)) tors%theta = CD_HermiteTorsion_Unwrap(raw, 0.0_wp) tors%has_theta = .TRUE. END SUBROUTINE torsion_of - SUBROUTINE build_cable(cab, q, phi, dt, tol, rho_inf, pinned, irn, compliance) + SUBROUTINE build_cable(cab, q, phi, dt, tol, rho_inf, pinned, irn, compliance, bt) !! HFMF cable on seed q: node NN coupled (driven), node 1 held; Rigid bending connections !! along +x at both ends (none with pinned), the coupled one in parent axes (identity - !! attitude); torsion with the coupled end's frame attached to the parent. + !! attitude); torsion with the coupled end's frame attached to the parent (damping bt). TYPE(CD_HFMF_ModuleType), INTENT(INOUT) :: cab REAL(wp), INTENT(IN) :: q(NDOF), phi, dt, tol, rho_inf, irn, compliance LOGICAL, INTENT(IN) :: pinned + REAL(wp), INTENT(IN), OPTIONAL :: bt TYPE(CD_HermiteTorsionType) :: tors REAL(wp) :: l0(NE), eye(3, 3), frame(3, 2) INTEGER :: es @@ -146,7 +155,7 @@ SUBROUTINE build_cable(cab, q, phi, dt, tol, rho_inf, pinned, irn, compliance) connection_mode=[CD_ENDCONN_RIGID, CD_ENDCONN_RIGID]) CALL require(es == CD_HFMF_OK, 'cable end connections: '//TRIM(em)) END IF - CALL torsion_of(q, phi, tors, irn, compliance) + CALL torsion_of(q, phi, tors, irn, compliance, bt) frame(:, 1) = [1.0_wp, 0.0_wp, 0.0_wp] frame(:, 2) = [0.0_wp, 0.0_wp, 1.0_wp] CALL CD_HFMF_Set_Torsion(cab, tors, es, em, coupled_frame_parent=frame, parent_orientation=eye) @@ -363,6 +372,50 @@ SUBROUTINE check_damping() CALL CD_HFMF_End(cab) END SUBROUTINE check_damping + ! ------------------------------------------------------------------------------------------ + SUBROUTINE check_frame_damping() + !! D: the straight clamped line with Irn = 1e-9 kg m and Bt = 40 N m2 s; the parent rolls the + !! coupled end's frame (the imposed twist stays 0) at a rate eased in to OMR over 1 s, then + !! steady. Every element carries the torque, so the held end reads (GJ theta + Bt theta_dot)/L + !! with theta the parent's roll: the damping of the twist the frame's turn puts into the end + !! element (a sixth of the torque here) included. + REAL(wp), PARAMETER :: BT = 40.0_wp, OMR = 0.5_wp, TR = 1.0_wp, DT = 0.01_wp + INTEGER, PARAMETER :: NSTEP = 300 + TYPE(CD_HFMF_ModuleType), ALLOCATABLE :: cab + REAL(wp) :: q(NDOF), x(3), t, ang, rate, ntq(NN), expect, err, mref + INTEGER :: k, es + CHARACTER(300) :: em + ALLOCATE (cab) + CALL line_seed(0.0_wp, 0.0_wp, q) + CALL build_cable(cab, q, 0.0_wp, DT, 1.0e-11_wp, 0.8_wp, .FALSE., 1.0e-9_wp, 0.0_wp, bt=BT) + x = q(NDOF - 5:NDOF - 3) + err = 0.0_wp + mref = (GJ*OMR*REAL(NSTEP, wp)*DT + BT*OMR)/LL + DO k = 1, NSTEP + t = DT*REAL(k, wp) + IF (t < TR) THEN + ang = OMR*(t**3/TR**2 - 0.5_wp*t**4/TR**3) + rate = OMR*(3.0_wp*t**2/TR**2 - 2.0_wp*t**3/TR**3) + ELSE + ang = OMR*(t - 0.5_wp*TR) + rate = OMR + END IF + CALL CD_HFMF_UpdateStates(cab, x, [0.0_wp, 0.0_wp, 0.0_wp], [0.0_wp, 0.0_wp, 0.0_wp], es, em, & + u_orientation=roll_x(ang)) + CALL require(es == CD_HFMF_OK, 'D frame: step: '//TRIM(em)) + IF (es /= CD_HFMF_OK) EXIT + IF (t > TR + 0.5_wp) THEN + CALL CD_HermiteCable_Dyn_Node_Torque(cab%line, ntq, es, em) + expect = (GJ*ang + BT*rate)/LL + err = MAX(err, MAXVAL(ABS(ABS(ntq) - expect))/mref) + END IF + END DO + WRITE (*, '(A,ES10.3,A,ES12.5,A,ES12.5)') 'D frame-driven damping: node torques against (GJ theta + Bt Omega)/L ', & + err, '; held end ', ntq(1), ', elastic part ', GJ*ang/LL + CALL require(err <= 1.0e-4_wp, 'D: a turning end frame loads the line with its torsional damping') + CALL CD_HFMF_End(cab) + END SUBROUTINE check_frame_damping + ! ------------------------------------------------------------------------------------------ SUBROUTINE energy_run(phi, irn, band, e_vib) !! Free vibration of the bowed line clamped at both ends (no gravity, no fluid), rho_inf = 1, @@ -434,7 +487,7 @@ SUBROUTINE check_restart() CHARACTER(300) :: em ALLOCATE (cab, cab2) CALL line_seed(0.3_wp, 0.1_wp, q) - CALL build_cable(cab, q, 1.0_wp, 0.01_wp, 1.0e-10_wp, 0.8_wp, .FALSE., 0.05_wp, 0.0_wp) + CALL build_cable(cab, q, 1.0_wp, 0.01_wp, 1.0e-10_wp, 0.8_wp, .FALSE., 0.05_wp, 0.0_wp, bt=0.5_wp) CALL march(cab, 0, 150, ok) CALL require(ok, 'R: first leg') CALL CD_HFMF_Snapshot(cab, es, em) @@ -454,7 +507,7 @@ SUBROUTINE check_restart() CALL require(ok .AND. ALL(bits(qb) == bits(qref)) .AND. ALL(bits(pb) == bits(pref)), & 'R: the restored run continues bit-identically') CALL line_seed(0.3_wp, 0.1_wp, q) - CALL build_cable(cab2, q, 1.0_wp, 0.01_wp, 1.0e-10_wp, 0.8_wp, .FALSE., 0.05_wp, 0.0_wp) + CALL build_cable(cab2, q, 1.0_wp, 0.01_wp, 1.0e-10_wp, 0.8_wp, .FALSE., 0.05_wp, 0.0_wp, bt=0.5_wp) CALL CD_HFMF_UnpackMirror(cab2, mirror, 1.5_wp, es, em) CALL require(es == CD_HFMF_OK, 'R: mirror reload: '//TRIM(em)) CALL march(cab2, 150, 250, ok) From 6c4810c8cb3e2aff4e2363767a104b3bd385c146 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Fri, 30 Oct 2026 08:29:49 +0900 Subject: [PATCH 3/4] fix(torsion): the held end section's polar inertia in the support reaction The end node of a line rigid in torsion carries half its element's polar inertia, but its angle is held, so that inertia entered no equation: the reaction moment on the support took the element's torque alone. A driven end then loaded its body with too little rotational inertia (a single element lost all of it). The held section turns with its end frame and its held angle, chi_dot = -+ drho/dw . omega + phi_dot (End 1, End 2); the reaction now adds -I chi_ddot dchi/dw. The frames' angular acceleration at the committed state, (omega_{n+1} - omega_n)/dt, is recorded at the commit (tw_oal) and joins the packed twist state with the rates. New gates in nodal_twist_dynamic: the clamped line driven at kL = pi/2, where the continuum's torque at the driven end, GJ A k cot(kL), is zero: the axial reaction there swings by 0.13 % (parent roll) and 0.06 % (imposed twist) of GJ A k; without the section's inertia both swung by its I Omega^2 A, 3.9 %. Signed-off-by: Jae Hoon Seo --- src/CableDyn_HermiteCableDynamic.f90 | 23 ++++++++--- tests/test_nodal_twist_dynamic.f90 | 58 +++++++++++++++++++++++++++- 2 files changed, 75 insertions(+), 6 deletions(-) diff --git a/src/CableDyn_HermiteCableDynamic.f90 b/src/CableDyn_HermiteCableDynamic.f90 index 527e35a5..0a6b34f9 100644 --- a/src/CableDyn_HermiteCableDynamic.f90 +++ b/src/CableDyn_HermiteCableDynamic.f90 @@ -493,7 +493,9 @@ MODULE CableDyn_HermiteCableDynamic ! tw_som(:, k): the angular velocity of end frame k over the running step, log(R_{n+1} ! R_n^T)/dt (R = [d n d x n]); tw_om: that of the committed step. A turning frame twists ! the element at a rigid end through rho, and the torsional damping takes that rate. - REAL(wp) :: tw_som(3, 2) = CD_ZERO, tw_om(3, 2) = CD_ZERO + ! tw_oal: the frames' angular acceleration at the committed state, (tw_om - its value one + ! step earlier)/dt, which turns the held end section's polar inertia (the support reaction). + REAL(wp) :: tw_som(3, 2) = CD_ZERO, tw_om(3, 2) = CD_ZERO, tw_oal(3, 2) = CD_ZERO ! Packed twist state (tw_pack) of the recovering step's interval start and of the snapshot, ! and the snapshot's tw_fcR. REAL(wp), ALLOCATABLE :: ws_recovery_tw(:), snap_tw(:), snap_tw_fcR(:) @@ -4548,6 +4550,7 @@ SUBROUTINE dyn_step_core(model, dt, max_iter, tol, ErrStat, ErrMsg, iters_out, r model%tw_w(iv) = model%tw_wn(iv) + dt*((CD_ONE - gm)*model%tw_an(iv) + gm*model%tw_ak(iv)) END DO CALL tw_commit_reference(model) + model%tw_oal = (model%tw_som - model%tw_om)/dt model%tw_om = model%tw_som DO iv = 1, model%ne model%tw_mt(iv) = model%tw_me(iv) @@ -7297,9 +7300,11 @@ SUBROUTINE CD_HermiteCable_Dyn_EndConnection_Moment(model, node, moment, ErrStat ! -> u) of the frame turned by exp(w), G(d' -> x) n' = Rot(x, w . d + Omega(d, d', x)) ! G(d -> x) n to first order, so df/dw = -d - d x dOmega/dy(d, d, x), and the frame's ! director in a transport triangle adds d x dOmega/dd. The slaved tangent of a rigid - ! bending end adds its share through the constraint reaction below. + ! bending end adds its share through the constraint reaction below. The held end section + ! turns with the frame and its held angle, chi_dot = -+drho/dw . omega + phi_dot (End 1, + ! End 2): its polar inertia I adds -I chi_ddot dchi/dw. BLOCK - REAL(wp) :: rho, beta, g(12), h(12, 12), ew(3, 2), psi, gl(3), hl(3, 3), lw(3), tw + REAL(wp) :: rho, beta, g(12), h(12, 12), ew(3, 2), psi, gl(3), hl(3, 3), lw(3), tw, sg, chi_dd IF (model%tw_rigid(iend)) THEN CALL twist_reference(model, MERGE(1, model%ne, iend == 1), model%q, model%torsion%ends, .FALSE., rho, & beta, g, h, es, em, end_w=ew) @@ -7309,6 +7314,9 @@ SUBROUTINE CD_HermiteCable_Dyn_EndConnection_Moment(model, node, moment, ErrStat RETURN END IF moment = -model%tw_mt(MERGE(1, model%ne, iend == 1))*ew(:, iend) + sg = MERGE(-CD_ONE, CD_ONE, iend == 1) + chi_dd = sg*DOT_PRODUCT(ew(:, iend), model%tw_oal(:, iend)) + model%tw_al(node) + moment = moment - model%tw_mass(node)*chi_dd*sg*ew(:, iend) ELSE CALL twist_link(model, iend, model%q, model%torsion%ends, .FALSE., psi, gl, hl, es, em, end_w=lw) IF (es /= CD_HCDYN_OK) THEN @@ -7979,6 +7987,7 @@ SUBROUTINE CD_HermiteCable_Dyn_End(model) model%tw_spsi = CD_ZERO model%tw_som = CD_ZERO model%tw_om = CD_ZERO + model%tw_oal = CD_ZERO model%tw_tscale = CD_ONE model%snap_valid = .FALSE. model%require_tensile = .FALSE. @@ -8623,9 +8632,10 @@ END SUBROUTINE assemble_torsion PURE INTEGER FUNCTION tw_pack_size(model) RESULT(n) !! Reals of the packed twist state of tw_pack: the angles, rates and accelerations, the !! directors and unit tangents, the reference twists, the element torques, the two - !! end-frame references and the end frames' angular velocities of the committed step. + !! end-frame references and the end frames' angular velocities and accelerations of the + !! committed step. TYPE(CD_HermiteCableDynType), INTENT(IN) :: model - n = 9*model%nn + 2*model%ne + 8 + n = 9*model%nn + 2*model%ne + 14 END FUNCTION tw_pack_size PURE SUBROUTINE tw_pack(model, buf) @@ -8643,6 +8653,7 @@ PURE SUBROUTINE tw_pack(model, buf) buf(9*nn + ne + 1:9*nn + 2*ne) = model%tw_mt buf(9*nn + 2*ne + 1:9*nn + 2*ne + 2) = model%tw_psi buf(9*nn + 2*ne + 3:9*nn + 2*ne + 8) = RESHAPE(model%tw_om, [6]) + buf(9*nn + 2*ne + 9:9*nn + 2*ne + 14) = RESHAPE(model%tw_oal, [6]) END SUBROUTINE tw_pack PURE SUBROUTINE tw_unpack(model, buf) @@ -8660,6 +8671,7 @@ PURE SUBROUTINE tw_unpack(model, buf) model%tw_mt = buf(9*nn + ne + 1:9*nn + 2*ne) model%tw_psi = buf(9*nn + 2*ne + 1:9*nn + 2*ne + 2) model%tw_om = RESHAPE(buf(9*nn + 2*ne + 3:9*nn + 2*ne + 8), [3, 2]) + model%tw_oal = RESHAPE(buf(9*nn + 2*ne + 9:9*nn + 2*ne + 14), [3, 2]) END SUBROUTINE tw_unpack ELEMENTAL REAL(wp) FUNCTION tw_wrap(x) RESULT(y) @@ -9246,6 +9258,7 @@ SUBROUTINE tw_init(model, mt, ErrStat, ErrMsg) model%tw_psi = CD_ZERO model%tw_som = CD_ZERO model%tw_om = CD_ZERO + model%tw_oal = CD_ZERO IF (.NOT. model%tw_rigid(1)) model%tw_psi(1) = CD_HermiteTwist_Angle(model%tw_u(:, 1), & CD_HermiteTwist_Carry(ends(:, 1), & model%tw_tn(:, 1), & diff --git a/tests/test_nodal_twist_dynamic.f90 b/tests/test_nodal_twist_dynamic.f90 index dd2a5074..eed2df20 100644 --- a/tests/test_nodal_twist_dynamic.f90 +++ b/tests/test_nodal_twist_dynamic.f90 @@ -11,7 +11,9 @@ PROGRAM test_nodal_twist_dynamic !! moves off the end director) and elastic torsional ends; !! W torsional waves: a straight line, clamped and rigid in torsion at both ends, driven in !! roll at one end below its first torsional mode, carries at the other end the torque of - !! the continuum, GJ A k / sin(kL) with k = Omega sqrt(Irn/GJ); + !! the continuum, GJ A k / sin(kL) with k = Omega sqrt(Irn/GJ); at kL = pi/2 the driven end's + !! reaction moment is zero, GJ A k cot(kL), its held section's polar inertia included, + !! for a roll of the parent and for an imposed twist; !! D torsional damping: the first torsional mode rings down at zeta_1 = omega_1 Bt/(2 GJ); !! a parent rolling its end frame at a steady rate Omega (negligible Irn) loads the held !! end with (GJ theta + Bt Omega)/L, the damping of the frame's own turn included; @@ -44,6 +46,8 @@ PROGRAM test_nodal_twist_dynamic CALL check_quasi_static('bending-pinned', .TRUE., 0.0_wp) CALL check_quasi_static('elastic', .FALSE., 0.05_wp) CALL check_waves() + CALL check_driven_end('parent roll') + CALL check_driven_end('imposed twist') CALL check_damping() CALL check_frame_damping() CALL check_energy() @@ -301,6 +305,58 @@ SUBROUTINE check_waves() CALL CD_HFMF_End(cab) END SUBROUTINE check_waves + ! ------------------------------------------------------------------------------------------ + SUBROUTINE check_driven_end(label) + !! W: the drive of check_waves at Omega = omega_1/2 (kL = pi/2), by the parent's roll or by + !! the imposed twist: the continuum's torque at the driven end, GJ A k cos(kL)/sin(kL), is + !! zero, so the axial reaction moment there swings only by the discretisation; without the + !! held end section's inertia (Irn l0/2) it would swing by Irn l0/2 Omega^2 A, 4 % of + !! GJ A k here. + CHARACTER(*), INTENT(IN) :: label + REAL(wp), PARAMETER :: IRN = 0.5_wp, AMPR = 0.2_wp + INTEGER, PARAMETER :: NPER_RAMP = 8, NPER = 14, NPP = 200 + TYPE(CD_HFMF_ModuleType), ALLOCATABLE :: cab + REAL(wp) :: q(NDOF), c, om, dt, t, env, ang, x(3), f(3), m(3), mmax, mmin, scale, ramp_t + INTEGER :: k, es + CHARACTER(300) :: em + ALLOCATE (cab) + c = SQRT(GJ/IRN) + om = 0.5_wp*PI*c/LL + dt = 2.0_wp*PI/om/REAL(NPP, wp) + CALL line_seed(0.0_wp, 0.0_wp, q) + CALL build_cable(cab, q, 0.0_wp, dt, 1.0e-10_wp, 0.9_wp, .FALSE., IRN, 0.0_wp) + x = q(NDOF - 5:NDOF - 3) + ramp_t = REAL(NPER_RAMP, wp)*2.0_wp*PI/om + mmax = -HUGE(1.0_wp) + mmin = HUGE(1.0_wp) + DO k = 1, NPER*NPP + t = dt*REAL(k, wp) + env = MIN(t/ramp_t, 1.0_wp) + env = env**3*(10.0_wp - 15.0_wp*env + 6.0_wp*env**2) + ang = AMPR*env*SIN(om*t) + IF (label == 'parent roll') THEN + CALL CD_HFMF_UpdateStates(cab, x, [0.0_wp, 0.0_wp, 0.0_wp], [0.0_wp, 0.0_wp, 0.0_wp], es, em, & + u_orientation=roll_x(ang)) + ELSE + CALL CD_HFMF_UpdateStates(cab, x, [0.0_wp, 0.0_wp, 0.0_wp], [0.0_wp, 0.0_wp, 0.0_wp], es, em, & + u_orientation=roll_x(0.0_wp), u_twist=ang) + END IF + CALL require(es == CD_HFMF_OK, 'W '//label//': step: '//TRIM(em)) + IF (es /= CD_HFMF_OK) EXIT + IF (t > ramp_t + 2.0_wp*PI/om) THEN + CALL CD_HFMF_CalcOutput(cab, f, es, em, y_moment=m) + mmax = MAX(mmax, m(1)) + mmin = MIN(mmin, m(1)) + END IF + END DO + scale = GJ*AMPR*(om/c) + WRITE (*, '(A,A,A,ES12.4,A,ES12.4)') 'W driven end at kL = pi/2 (', label, '): axial reaction swing ', & + 0.5_wp*(mmax - mmin), ' of GJ A k ', scale + CALL require(0.5_wp*(mmax - mmin) <= 1.0e-2_wp*scale, & + 'W '//label//': the driven end reacts with the continuum torque, its section inertia included') + CALL CD_HFMF_End(cab) + END SUBROUTINE check_driven_end + ! ------------------------------------------------------------------------------------------ SUBROUTINE check_damping() !! D: torsional damping Bt (torque Bt dtau/dt) is stiffness-proportional, so the first From 8e334b93b3739d35885e79a34254d49d30a61f32 Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Fri, 30 Oct 2026 10:28:44 +0900 Subject: [PATCH 4/4] fix(torsion): a held end section's frame-driven spin in the polar kinetic energy The polar kinetic energy summed the nodal rates alone, so a rigid end driven by its parent frame, whose section spins with the frame while its held angle stands still, carried none: the energy query and the coupled energy diagnostics missed the inertia the support reaction now includes. The held end section's spin is the reaction's chi_dot = -+ drho/dw . omega + phi_dot (End 1, End 2), with the committed step's frame rates. New gate in nodal_twist_dynamic: the clamped line, its end frame rolled by the parent at a steady rate, holds the continuum's polar kinetic energy within 7e-4; without the held section's spin it fell 7.5 % short. Signed-off-by: Jae Hoon Seo --- src/CableDyn_HermiteCableDynamic.f90 | 22 +++++++++--- tests/test_nodal_twist_dynamic.f90 | 51 +++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 5 deletions(-) diff --git a/src/CableDyn_HermiteCableDynamic.f90 b/src/CableDyn_HermiteCableDynamic.f90 index 0a6b34f9..03757502 100644 --- a/src/CableDyn_HermiteCableDynamic.f90 +++ b/src/CableDyn_HermiteCableDynamic.f90 @@ -5769,12 +5769,22 @@ SUBROUTINE CD_HermiteCable_Dyn_Energy(model, kinetic, strain, ErrStat, ErrMsg, c strain = strain + connection_energy END IF IF (model%tw_active) THEN - ! nodal twist: the element and end-spring energies and the polar kinetic energy + ! nodal twist: the element and end-spring energies and the polar kinetic energy, a held + ! end section's spin chi_dot = -+drho/dw . omega + phi_dot (End 1, End 2) as in its + ! reaction (CD_HermiteCable_Dyn_EndConnection_Moment) BLOCK - REAL(wp) :: rho, beta, g(12), h(12, 12), tau, psi, gl(3), hl(3, 3), tw + REAL(wp) :: rho, beta, g(12), h(12, 12), tau, psi, gl(3), hl(3, 3), tw, ew(3, 2), ewe(3, 2), spin(2) INTEGER :: iend + ew = CD_ZERO DO e = 1, model%ne - CALL twist_reference(model, e, model%q, model%torsion%ends, .FALSE., rho, beta, g, h, ErrStat, em2) + IF (e == 1 .OR. e == model%ne) THEN + CALL twist_reference(model, e, model%q, model%torsion%ends, .FALSE., rho, beta, g, h, ErrStat, em2, & + end_w=ewe) + IF (e == 1) ew(:, 1) = ewe(:, 1) + IF (e == model%ne) ew(:, 2) = ewe(:, 2) + ELSE + CALL twist_reference(model, e, model%q, model%torsion%ends, .FALSE., rho, beta, g, h, ErrStat, em2) + END IF IF (ErrStat /= CD_HCDYN_OK) THEN ErrMsg = 'CD_HermiteCable_Dyn_Energy: '//TRIM(em2) RETURN @@ -5796,7 +5806,11 @@ SUBROUTINE CD_HermiteCable_Dyn_Energy(model, kinetic, strain, ErrStat, ErrMsg, c END IF strain = strain + 0.5_wp*tw*tw/model%torsion%end_compliance(iend) END DO - kinetic = kinetic + 0.5_wp*SUM(model%tw_mass*model%tw_w*model%tw_w) + spin = [model%tw_w(1), model%tw_w(model%nn)] + IF (model%tw_rigid(1)) spin(1) = spin(1) - DOT_PRODUCT(ew(:, 1), model%tw_om(:, 1)) + IF (model%tw_rigid(2)) spin(2) = spin(2) + DOT_PRODUCT(ew(:, 2), model%tw_om(:, 2)) + kinetic = kinetic + 0.5_wp*SUM(model%tw_mass(2:model%nn - 1)*model%tw_w(2:model%nn - 1)**2) & + + 0.5_wp*(model%tw_mass(1)*spin(1)**2 + model%tw_mass(model%nn)*spin(2)**2) END BLOCK ELSE IF (model%torsion%active) THEN BLOCK diff --git a/tests/test_nodal_twist_dynamic.f90 b/tests/test_nodal_twist_dynamic.f90 index eed2df20..f4caa2fd 100644 --- a/tests/test_nodal_twist_dynamic.f90 +++ b/tests/test_nodal_twist_dynamic.f90 @@ -19,7 +19,8 @@ PROGRAM test_nodal_twist_dynamic !! end with (GJ theta + Bt Omega)/L, the damping of the frame's own turn included; !! E energy: free vibration of a bowed, twisted line with a real Irn (rho_inf = 1): kinetic !! (with the polar part) + elastic (with the twist) stays within the band of the line - !! without torsion; + !! without torsion; a parent rolling the clamped line's end frame at a steady rate puts + !! the continuum's polar kinetic energy into it, the held end section's spin included; !! R restart: a rolling, torsionally damped run restored from a snapshot, and one rebuilt !! from the checkpoint mirror, continue bit-identically. USE CableDyn_Precision, ONLY: wp @@ -51,6 +52,7 @@ PROGRAM test_nodal_twist_dynamic CALL check_damping() CALL check_frame_damping() CALL check_energy() + CALL check_frame_energy() CALL check_restart() IF (nfail > 0) THEN @@ -531,6 +533,53 @@ SUBROUTINE check_energy() CALL require(band1 <= 5.0e-3_wp, 'E: kinetic + elastic energy with the nodal twist conserved within 0.5 %') END SUBROUTINE check_energy + ! ------------------------------------------------------------------------------------------ + SUBROUTINE check_frame_energy() + !! E: the straight clamped line with Irn = 0.5 kg m and Bt = 10 N m2 s (zeta_1 = 0.25); the + !! parent rolls the coupled end's frame (the imposed twist stays 0) at a rate eased in to OMR + !! over 5 s, then steady. The sections spin as the continuum's, OMR s/L, so the kinetic + !! energy is 1/2 sum I_j (OMR s_j/L)^2 over the lumped polar inertias, the held end's + !! (I l0/2, its section spinning at OMR with a held angle) 7 % of it here. + REAL(wp), PARAMETER :: IRN = 0.5_wp, BT = 10.0_wp, OMR = 0.5_wp, TR = 5.0_wp, DT = 0.01_wp + INTEGER, PARAMETER :: NSTEP = 1000 + TYPE(CD_HFMF_ModuleType), ALLOCATABLE :: cab + REAL(wp) :: q(NDOF), x(3), t, ang, ke, se, expect, err, l0, mj + INTEGER :: k, j, es + CHARACTER(300) :: em + ALLOCATE (cab) + CALL line_seed(0.0_wp, 0.0_wp, q) + CALL build_cable(cab, q, 0.0_wp, DT, 1.0e-11_wp, 0.8_wp, .FALSE., IRN, 0.0_wp, bt=BT) + x = q(NDOF - 5:NDOF - 3) + l0 = LL/REAL(NE, wp) + expect = 0.0_wp + DO j = 1, NN + mj = MERGE(0.5_wp, 1.0_wp, j == 1 .OR. j == NN)*IRN*l0 + expect = expect + 0.5_wp*mj*(OMR*REAL(j - 1, wp)/REAL(NE, wp))**2 + END DO + err = 0.0_wp + DO k = 1, NSTEP + t = DT*REAL(k, wp) + IF (t < TR) THEN + ang = OMR*(t**3/TR**2 - 0.5_wp*t**4/TR**3) + ELSE + ang = OMR*(t - 0.5_wp*TR) + END IF + CALL CD_HFMF_UpdateStates(cab, x, [0.0_wp, 0.0_wp, 0.0_wp], [0.0_wp, 0.0_wp, 0.0_wp], es, em, & + u_orientation=roll_x(ang)) + CALL require(es == CD_HFMF_OK, 'E frame: step: '//TRIM(em)) + IF (es /= CD_HFMF_OK) EXIT + IF (t > 0.8_wp*REAL(NSTEP, wp)*DT) THEN + CALL CD_HermiteCable_Dyn_Energy(cab%line, ke, se, es, em) + CALL require(es == CD_HCDYN_OK, 'E frame: energy: '//TRIM(em)) + err = MAX(err, ABS(ke - expect)/expect) + END IF + END DO + WRITE (*, '(A,ES10.3,A,ES12.5)') 'E frame-driven spin: kinetic energy against the continuum''s ', err, & + ' of ', expect + CALL require(err <= 1.0e-2_wp, 'E: a held end section spinning with its frame carries its kinetic energy') + CALL CD_HFMF_End(cab) + END SUBROUTINE check_frame_energy + ! ------------------------------------------------------------------------------------------ SUBROUTINE check_restart() !! R: 150 steps, snapshot, 100 more; restore and redo the 100: identical. A fresh module