From c86b84b60d274a94f1928e093ae3d4eff1405b5c Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Thu, 19 Nov 2026 19:30:19 +0900 Subject: [PATCH] perf: evaluate a cable's line-wide channel values once per output row Every TwistN channel of a finite-EI cable re-evaluated the twist of every element of the line (CD_HermiteCable_Dyn_Element_Twist, with the twist reference and its Hessian per element), and every TorqN, CurvX/CurvY and VIV amplitude channel re-evaluated its own line-wide array. On the coupled OpenFAST route the channels are evaluated in every CalcOutput (about two per step) and again for the committed-step row of the .CD.out, so a deck with a few twist channels spent most of its CalcOutput time on them. The channels of one output row now share these values: CD_ChannelRow (the former load-power row cache) also carries the torsion state, the element and end twists, the node torques, the section curvature and the VIV amplitude of a cable. The first channel of a row that needs a value evaluates it with the same call the channel made before, and the cable's other channels of the row read it, so every value is bit-identical. A row is valid for one state only: CD_AGG_EvalChannels (new) clears it at the start and the end of every row, the standalone routes per row. - CD_CalcOutput, its committed-step row and lin_eval evaluate the channels with CD_AGG_EvalChannels. A supercycled module's row takes the channels the same call has just evaluated on the committed state (the re-evaluation repeated them bit for bit). - The standalone mixed route (write_mixed_row), the multibody march and the cubic-Hermite writer pass the row through CD_Eval_Aggregate_Channel / eval_cable_channel. - A channel that fails still ends the row after the channels before it. On the IEA-15MW UMaine model with a 600-element lazy-wave cable restrained in torsion (nine Twist and nine BendMom channels, DT 0.01 s), CalcOutput takes 12.3 ms per step instead of 26.6 ms (channels 1.0 ms instead of 9.9 ms, the .CD.out row 0.6 ms instead of 5.1 ms). The coupled cases, restarts, linearization files, FAST.Farm and the example decks are bit-identical to dev. Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 12 ++ CMakeLists.txt | 8 + app/cabledyn.f90 | 19 +- src/CableDyn_DeckDriver.f90 | 194 ++++++++++++++++++-- src/CableDyn_OpenFAST_Aggregate.f90 | 97 +++++++++- src/openfast/CableDyn_OF.f90 | 67 ++++--- tests/test_channel_row.f90 | 266 ++++++++++++++++++++++++++++ 7 files changed, 611 insertions(+), 52 deletions(-) create mode 100644 tests/test_channel_row.f90 diff --git a/CHANGELOG.md b/CHANGELOG.md index 294b5370..8bb5b77d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -222,6 +222,18 @@ All notable changes to CableDyn are recorded in this file. The format follows `EI = 0` lines and line systems. Outputs are unchanged to the bit; with the three line totals the VIV examples run about 11 % faster (`viv_taut_cable_inline.dat` 2.39 s to 2.14 s; the same line with 200 elements at 100 steps per cycle 18.1 s to 16.1 s). +- The output channels of one row evaluate the line-wide values a finite-EI cable's channels + share once per row instead of once per channel: the element twists and torsion state behind + every `TwistN`, the node torques of `TorqN`, the section curvature of + `CurvX`/`CurvY` and the VIV amplitude. This applies to every `CalcOutput` of the OpenFAST + module (`CompMooring = 5`) and FAST.Farm, their committed-step `.CD.out` row and + linearization, and to the standalone mixed, multibody and cubic-Hermite routes. A supercycled + module's `.CD.out` row also takes the channels the same call has just evaluated on the + committed state. Outputs, `.CD.out`, linearization files and restarts are unchanged to the + bit. On the IEA-15MW UMaine model with the three chains and a 600-element lazy-wave cable + restrained in torsion (nine `Twist` and nine `BendMom` channels, `DT = 0.01 s`), `CalcOutput` + takes 12.3 ms per step instead of 26.6 ms (the channels 1.0 ms instead of 9.9 ms, the `.CD.out` + row 0.6 ms instead of 5.1 ms), and CableDyn as a whole 26 ms instead of 42 ms. - The bending damping of a finite-EI cable (`EI|Bb`, `EI|-zeta|f`) evaluates the second derivatives of the curvature only where the position Jacobian needs them, not in every residual evaluation. Results are unchanged to the bit; the Delta Flume case 9 deck of diff --git a/CMakeLists.txt b/CMakeLists.txt index fff0998f..9865b3f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2785,6 +2785,14 @@ target_link_libraries(test_coupled_torsion PRIVATE cabledyn_core) add_test(NAME coupled_torsion COMMAND test_coupled_torsion WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) set_tests_properties(coupled_torsion PROPERTIES LABELS "fortran;unit;static;dynamic;openfast") +# The channels of one output row evaluated together (CD_AGG_EvalChannels, the line-wide twists +# and torques once per row) against one at a time, bit for bit, through a rolling march and a +# probe transfer: a row value kept from another state would fail. +add_executable(test_channel_row tests/test_channel_row.f90) +target_link_libraries(test_channel_row PRIVATE cabledyn_core) +add_test(NAME channel_row COMMAND test_channel_row WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) +set_tests_properties(channel_row PROPERTIES LABELS "fortran;unit;dynamic;openfast") + # OpenFAST linearisation of a line restrained in torsion, by the shell's lin_eval recipe on the # aggregate: the twist modes of A against n pi/L sqrt(GJ/Irn), the reduced roll stiffness GJ/L # (nodal twist and condensed), the damping and inertia columns of the platform's angular rates. diff --git a/app/cabledyn.f90 b/app/cabledyn.f90 index 750a3fcf..16ddf99b 100644 --- a/app/cabledyn.f90 +++ b/app/cabledyn.f90 @@ -29,7 +29,7 @@ PROGRAM cabledyn CD_AGG_NMovingPoints, CD_AGG_GetMovingPointMesh, & CD_AGG_Step_Moving, CD_AGG_CalcOutput, CD_AGG_End, & CD_AGG_NumChannels, CD_AGG_ChannelHeader, & - CD_AGG_EvalChannel, CD_AGG_WriteStaticProfile, & + CD_AGG_EvalChannels, CD_AGG_WriteStaticProfile, & CD_AGG_GetInitMetadata, CD_AGG_GetInitLine, & CD_AGG_Range_Sample, CD_AGG_Range_Write, CD_AGG_OK, CD_AGG_BADINPUT, & CD_AGG_UpdateStates_Moving, CD_AGG_MotionKinematics, & @@ -854,22 +854,27 @@ SUBROUTINE write_mixed_row(unit, time, aggregate, stat, msg) TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: aggregate INTEGER, INTENT(OUT) :: stat CHARACTER(*), INTENT(OUT) :: msg - INTEGER :: i, ios - REAL(wp) :: value + INTEGER :: i, ios, n_done, eval_stat + REAL(wp) :: values(CD_AGG_NumChannels(aggregate)) + CHARACTER(LEN(msg)) :: eval_msg ! full-precision time column (the deck-driver writers use the same format) WRITE (unit, '(ES25.16E3)', ADVANCE='NO', IOSTAT=ios) time IF (ios /= 0) THEN stat = CD_AGG_BADINPUT; msg = 'cannot write mixed output row'; RETURN END IF - DO i = 1, CD_AGG_NumChannels(aggregate) - CALL CD_AGG_EvalChannel(aggregate, i, value, stat, msg) - IF (stat /= CD_AGG_OK) RETURN - WRITE (unit, CD_CHANNEL_FMT, ADVANCE='NO', IOSTAT=ios) CHAR(9), value + ! the row's channels in one evaluation (their shared line-wide values once); a failed channel + ! ends the row after the channels before it, as a channel-by-channel loop would + CALL CD_AGG_EvalChannels(aggregate, values, n_done, eval_stat, eval_msg) + DO i = 1, n_done + WRITE (unit, CD_CHANNEL_FMT, ADVANCE='NO', IOSTAT=ios) CHAR(9), values(i) IF (ios /= 0) THEN stat = CD_AGG_BADINPUT; msg = 'cannot write mixed output row'; RETURN END IF END DO + IF (eval_stat /= CD_AGG_OK) THEN + stat = eval_stat; msg = eval_msg; RETURN + END IF WRITE (unit, '(A)', IOSTAT=ios) '' IF (ios /= 0) THEN stat = CD_AGG_BADINPUT; msg = 'cannot write mixed output row'; RETURN diff --git a/src/CableDyn_DeckDriver.f90 b/src/CableDyn_DeckDriver.f90 index bbb253bd..58ea9445 100644 --- a/src/CableDyn_DeckDriver.f90 +++ b/src/CableDyn_DeckDriver.f90 @@ -268,6 +268,9 @@ MODULE CableDyn_DeckDriver ! Both reuse the same private evaluators the standalone .out writers use, so a coupled run ! and the standalone driver report identical channel values on a shared configuration. PUBLIC :: CD_Eval_Aggregate_Channel, CD_Channel_Unit + ! The line-wide values one output row of channels shares per finite-EI cable (the rows argument + ! of CD_Eval_Aggregate_Channel), cleared before each row. + PUBLIC :: CD_ChannelRow, CD_Channel_Row_Reset ! The deck node of a node of a finite-EI cable's final mesh (the static-profile DeckNode column). PUBLIC :: CD_Cable_Deck_Node ! In-process object queries of the C API (CableDyn_CAPI): segment tensions in the .t.out @@ -925,12 +928,33 @@ MODULE CableDyn_DeckDriver REAL(wp), ALLOCATABLE :: line_pv(:), line_pd(:), line_pm(:) END TYPE - TYPE :: LoadPowerRow - !! The node load powers of one finite-EI cable at the committed state of one output row - !! (CD_HermiteCable_Dyn_Load_Power): the row's first load power channel of the cable - !! evaluates them and its other load power channels reuse them. + TYPE :: CD_ChannelRow + !! The line-wide values of one finite-EI cable at the state of one output row: the row's + !! first channel of the cable that needs one evaluates it, and the cable's other channels of + !! the row read it, so a row costs one line-wide evaluation per kind of value, not one per + !! channel. Each value is the one the channel would evaluate itself, bit for bit. A row is + !! valid for one state only: CD_Channel_Row_Reset clears it before every row. + !! valid: the node load powers (CD_HermiteCable_Dyn_Load_Power) LOGICAL :: valid = .FALSE. REAL(wp), ALLOCATABLE :: pv(:), pd(:), pm(:) + ! the torsion state Theta and torque (CD_HermiteCable_Dyn_Torsion_State) + LOGICAL :: tors_valid = .FALSE. + REAL(wp) :: theta = CD_ZERO, torque = CD_ZERO + ! the element twists (CD_HermiteCable_Dyn_Element_Twist) + LOGICAL :: etw_valid = .FALSE. + REAL(wp), ALLOCATABLE :: etw(:) + ! the twists of the torsional end springs (CD_HermiteCable_Dyn_End_Twist) + LOGICAL :: etw2_valid = .FALSE. + REAL(wp) :: etw2(2) = CD_ZERO + ! the node torques (CD_HermiteCable_Dyn_Node_Torque) + LOGICAL :: ntq_valid = .FALSE. + REAL(wp), ALLOCATABLE :: ntq(:) + ! the section curvature components (CD_HFMF_Section_Curvature) + LOGICAL :: sc_valid = .FALSE. + REAL(wp), ALLOCATABLE :: kxa(:), kya(:) + ! the smoothed VIV amplitude estimates (CD_HermiteCable_Dyn_VIV_Amplitude) + LOGICAL :: amp_valid = .FALSE. + REAL(wp), ALLOCATABLE :: amp(:) END TYPE TYPE :: LineStepWorkspace @@ -24007,6 +24031,8 @@ SUBROUTINE write_multibody_dynamic_out(deck_path, out_root, channels, types, bod TYPE(ModelOutputWorkspace) :: output_work TYPE(DriverProgress) :: progress TYPE(CD_RangeSet) :: mb_ranges + ! the cables' line-wide values one output row of channels shares (reset per row) + TYPE(CD_ChannelRow), ALLOCATABLE :: mb_rows(:) converged = .FALSE. ErrStat = CD_DECKDRV_OK @@ -24621,6 +24647,14 @@ SUBROUTINE mb_outputs(time) CALL CD_Deck_Range_Sample_Aggregate(mb_ranges, mb%has_sys, mb%system, mb%cables, mb%line_is_cable, & mb%line_obj_index, time, ErrStat, ErrMsg) IF (ErrStat /= CD_DECKDRV_OK) RETURN + IF (.NOT. ALLOCATED(mb_rows)) THEN + IF (ALLOCATED(mb%cables)) THEN + ALLOCATE (mb_rows(SIZE(mb%cables))) + ELSE + ALLOCATE (mb_rows(0)) + END IF + END IF + CALL CD_Channel_Row_Reset(mb_rows) DO j = 1, SIZE(channels) IF (is_object_channel(to_lower(channels(j)))) THEN CALL mb_object_channel(mb, points, opts, time, channels(j), vals(j), found, ErrStat, ErrMsg, bathymetry) @@ -24632,7 +24666,7 @@ SUBROUTINE mb_outputs(time) CALL mb_point_force(mb, channels(j), vals(j), ErrStat, ErrMsg) ELSE CALL CD_Eval_Aggregate_Channel(channels(j), mb%has_sys, mb%system, mb%cables, mb%line_is_cable, & - mb%line_obj_index, vals(j), ErrStat, ErrMsg, ranges=mb_ranges) + mb%line_obj_index, vals(j), ErrStat, ErrMsg, ranges=mb_ranges, rows=mb_rows) END IF IF (ErrStat /= CD_DECKDRV_OK) RETURN IF (.NOT. IEEE_IS_FINITE(vals(j))) THEN @@ -34311,8 +34345,9 @@ SUBROUTINE write_hermite_model_row(unit, time, channels, lines, points, cables, REAL(wp) :: val, f(3), fl(3) CHARACTER(NAMELEN) :: lo CHARACTER(1024) :: em - ! the cables' load powers at this row's state, shared by their load power channels - TYPE(LoadPowerRow) :: powers(SIZE(cables)) + ! the cables' line-wide values at this row's state (load powers, twists, torques, ...), shared by + ! their channels of the row + TYPE(CD_ChannelRow) :: powers(SIZE(cables)) ErrStat = CD_DECKDRV_OK; ErrMsg = '' IF (PRESENT(ranges)) THEN DO li = 1, SIZE(lines) @@ -39702,12 +39737,14 @@ END SUBROUTINE aggregate_tdp_value ! -------------------------------------------------------------------------- ! SUBROUTINE CD_Eval_Aggregate_Channel(ch, has_sys, system, cables, line_is_cable, line_obj_index, val, ErrStat, & - ErrMsg, cable_points, rigid_rt, rod_rt, ranges, mesh_node) + ErrMsg, cable_points, rigid_rt, rod_rt, ranges, mesh_node, rows) !! Evaluate ONE deck OUTPUTS channel token against a built aggregate. The token's deck line !! id is resolved through the map to either an EI=0 system line (eval_system_line_channel) or !! a finite-EI cable (eval_cable_channel); Point

channels read the EI=0 system point state. !! The channel is assumed already validated (parse_deck -> check_channel); an internally - !! inconsistent token or a failed state query still fails closed here. + !! inconsistent token or a failed state query still fails closed here. rows (optional, one + !! per cable): the line-wide values the channels of one output row share (CD_ChannelRow), + !! reset by the caller before the row; the value is the same with or without them. CHARACTER(*), INTENT(IN) :: ch LOGICAL, INTENT(IN) :: has_sys TYPE(CD_SystemType), INTENT(IN) :: system @@ -39730,6 +39767,7 @@ SUBROUTINE CD_Eval_Aggregate_Channel(ch, has_sys, system, cables, line_is_cable, ! A node channel names a deck node; mesh_node = .TRUE. reads it as a node of the line's final ! mesh instead (eval_cable_channel), as the static profile and the C API line arrays do LOGICAL, INTENT(IN), OPTIONAL :: mesh_node + TYPE(CD_ChannelRow), INTENT(INOUT), OPTIONAL :: rows(:) CHARACTER(NAMELEN) :: lo LOGICAL :: found @@ -39884,7 +39922,14 @@ SUBROUTINE CD_Eval_Aggregate_Channel(ch, has_sys, system, cables, line_is_cable, IF (line_obj_index(line_id) > SIZE(cables)) THEN CALL fail(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": cable index out of range'); RETURN END IF - CALL eval_cable_channel(cables(line_obj_index(line_id)), ch, val, ErrStat, ErrMsg, mesh_node=mesh_node) + c = line_obj_index(line_id) + IF (PRESENT(rows)) THEN + IF (c <= SIZE(rows)) THEN + CALL eval_cable_channel(cables(c), ch, val, ErrStat, ErrMsg, mesh_node=mesh_node, power=rows(c)) + RETURN + END IF + END IF + CALL eval_cable_channel(cables(c), ch, val, ErrStat, ErrMsg, mesh_node=mesh_node) ELSE IF (.NOT. has_sys) THEN CALL fail(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": line maps to the EI=0 system but no system '// & @@ -40404,16 +40449,17 @@ SUBROUTINE eval_cable_channel(cable, ch, val, ErrStat, ErrMsg, mesh_node, power) !! names a deck node (1 + the total NumSegs of the line's sections, End A first), read at its !! node of the final mesh on a refined line (cable%deck_node); mesh_node = .TRUE. reads the !! token's node as a node of the final mesh instead (the static profile and the C API line - !! arrays list every mesh node). power (optional), the cable's load powers at its present - !! state: a load power channel takes them when they are valid and stores them otherwise, so - !! the load power channels of one output row evaluate them once. + !! arrays list every mesh node). power (optional), the cable's line-wide values at its present + !! state (CD_ChannelRow: load powers, torsion state, element, end and node twists and + !! torques, section curvature, VIV amplitude): a channel takes a value when it is valid and + !! stores it otherwise, so the channels of one output row evaluate each kind once. TYPE(CD_HFMF_ModuleType), INTENT(INOUT) :: cable CHARACTER(*), INTENT(IN) :: ch REAL(wp), INTENT(OUT) :: val INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg LOGICAL, INTENT(IN), OPTIONAL :: mesh_node - TYPE(LoadPowerRow), INTENT(INOUT), OPTIONAL :: power + TYPE(CD_ChannelRow), INTENT(INOUT), OPTIONAL :: power CHARACTER(NAMELEN) :: lo INTEGER :: line_id, node, kind, comp, nnode, nelem, inode, es @@ -40522,6 +40568,19 @@ SUBROUTINE eval_cable_channel(cable, ch, val, ErrStat, ErrMsg, mesh_node, power) END IF END BLOCK CASE (21) ! the smoothed VIV amplitude estimate of the node (VIV AMPLITUDE) + IF (PRESENT(power)) THEN + IF (.NOT. power%amp_valid) THEN + CALL row_array(power%amp, nnode) + CALL CD_HermiteCable_Dyn_VIV_Amplitude(cable%line, power%amp, es, em) + IF (es /= CD_HCDYN_OK) THEN + CALL fail_solve(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": finite-EI VIV amplitude recovery failed: '// & + TRIM(em)); RETURN + END IF + power%amp_valid = .TRUE. + END IF + val = power%amp(inode) + RETURN + END IF BLOCK REAL(wp) :: amp(nnode) CALL CD_HermiteCable_Dyn_VIV_Amplitude(cable%line, amp, es, em) @@ -40549,6 +40608,19 @@ SUBROUTINE eval_cable_channel(cable, ch, val, ErrStat, ErrMsg, mesh_node, power) CALL fail_solve(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": '//TRIM(em)); RETURN END IF CASE (13, 14) ! the curvature vector on the section axes x, y (CD_HFMF_Section_Curvature) + IF (PRESENT(power)) THEN + IF (.NOT. power%sc_valid) THEN + CALL row_array(power%kxa, cable%line%nn) + CALL row_array(power%kya, cable%line%nn) + CALL CD_HFMF_Section_Curvature(cable, power%kxa, power%kya, es, em) + IF (es /= CD_HFMF_OK) THEN + CALL fail_solve(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": '//TRIM(em)); RETURN + END IF + power%sc_valid = .TRUE. + END IF + val = MERGE(power%kxa(inode), power%kya(inode), kind == 13) + RETURN + END IF BLOCK REAL(wp) :: kxa(cable%line%nn), kya(cable%line%nn) CALL CD_HFMF_Section_Curvature(cable, kxa, kya, es, em) @@ -40558,6 +40630,10 @@ SUBROUTINE eval_cable_channel(cable, ch, val, ErrStat, ErrMsg, mesh_node, power) val = MERGE(kxa(inode), kya(inode), kind == 13) END BLOCK CASE (9, 10, 11) ! condensed torsion: torque [N m], twist from End A to node J, total twist [deg] + IF (PRESENT(power)) THEN + CALL row_torsion_value(cable, power, kind, inode, ch, val, ErrStat, ErrMsg) + RETURN + END IF BLOCK REAL(wp) :: th, mt CALL CD_HermiteCable_Dyn_Torsion_State(cable%line, th, mt, es, em) @@ -40611,6 +40687,96 @@ SUBROUTINE eval_cable_channel(cable, ch, val, ErrStat, ErrMsg, mesh_node, power) END SELECT END SUBROUTINE eval_cable_channel + SUBROUTINE row_torsion_value(cable, row, kind, inode, ch, val, ErrStat, ErrMsg) + !! The torsion channels of eval_cable_channel (kind 9 torque, 10 twist from End A to the node, + !! 11 total twist) from the line-wide torsion values of the output row: each is evaluated once + !! per row by the first channel that needs it, the same calls in the same order as the + !! channel's own evaluation, so the value is bit for bit the one eval_cable_channel computes + !! without a row. + TYPE(CD_HFMF_ModuleType), INTENT(IN) :: cable + TYPE(CD_ChannelRow), INTENT(INOUT) :: row + INTEGER, INTENT(IN) :: kind, inode + CHARACTER(*), INTENT(IN) :: ch + REAL(wp), INTENT(OUT) :: val + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + INTEGER :: es, nelem + CHARACTER(1024) :: em + + ErrStat = CD_DECKDRV_OK + ErrMsg = '' + val = CD_ZERO + nelem = cable%line%ne + IF (.NOT. row%tors_valid) THEN + CALL CD_HermiteCable_Dyn_Torsion_State(cable%line, row%theta, row%torque, es, em) + IF (es /= CD_HCDYN_OK) THEN + CALL fail_solve(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": '//TRIM(em)); RETURN + END IF + row%tors_valid = .TRUE. + END IF + IF (kind == 9 .AND. cable%line%tw_active) THEN + ! nodal twist: the torque at the node (its elements' mean; an end node's element) + IF (.NOT. row%ntq_valid) THEN + CALL row_array(row%ntq, cable%line%nn) + CALL CD_HermiteCable_Dyn_Node_Torque(cable%line, row%ntq, es, em) + IF (es /= CD_HCDYN_OK) THEN + CALL fail_solve(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": '//TRIM(em)); RETURN + END IF + row%ntq_valid = .TRUE. + END IF + val = row%ntq(inode) + ELSE IF (kind == 9) THEN + val = row%torque + ELSE IF (cable%line%torsion%active) THEN + IF (.NOT. row%etw_valid) THEN + CALL row_array(row%etw, nelem) + CALL CD_HermiteCable_Dyn_Element_Twist(cable%line, row%etw, es, em) + IF (es /= CD_HCDYN_OK) THEN + CALL fail_solve(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": '//TRIM(em)); RETURN + END IF + row%etw_valid = .TRUE. + END IF + IF (kind == 11 .AND. cable%line%tw_active) THEN + IF (.NOT. row%etw2_valid) THEN + CALL CD_HermiteCable_Dyn_End_Twist(cable%line, row%etw2, es, em) + IF (es /= CD_HCDYN_OK) THEN + CALL fail_solve(ErrStat, ErrMsg, 'OUTPUT "'//TRIM(ch)//'": '//TRIM(em)); RETURN + END IF + row%etw2_valid = .TRUE. + END IF + val = (SUM(row%etw2) + SUM(row%etw))*45.0_wp/QUARTER_PI + ELSE IF (kind == 11) THEN + val = (row%torque*SUM(cable%line%torsion%end_compliance) + SUM(row%etw))*45.0_wp/QUARTER_PI + ELSE + val = SUM(row%etw(inode:nelem))*45.0_wp/QUARTER_PI + END IF + END IF + END SUBROUTINE row_torsion_value + + SUBROUTINE row_array(a, n) + !! A line-wide array of an output row (CD_ChannelRow) sized n; its values are not kept. + REAL(wp), ALLOCATABLE, INTENT(INOUT) :: a(:) + INTEGER, INTENT(IN) :: n + IF (ALLOCATED(a)) THEN + IF (SIZE(a) == n) RETURN + DEALLOCATE (a) + END IF + ALLOCATE (a(n)) + END SUBROUTINE row_array + + ELEMENTAL SUBROUTINE CD_Channel_Row_Reset(row) + !! Clear the line-wide values of an output row (CD_ChannelRow) before the channels of a new + !! row, or after the state they were evaluated at changed; the arrays are kept for reuse. + TYPE(CD_ChannelRow), INTENT(INOUT) :: row + row%valid = .FALSE. + row%tors_valid = .FALSE. + row%etw_valid = .FALSE. + row%etw2_valid = .FALSE. + row%ntq_valid = .FALSE. + row%sc_valid = .FALSE. + row%amp_valid = .FALSE. + END SUBROUTINE CD_Channel_Row_Reset + PURE LOGICAL FUNCTION cable_state_ready(cable) RESULT(ready) !! Whether a finite-EI cable holds the state its channels read. TYPE(CD_HFMF_ModuleType), INTENT(IN) :: cable diff --git a/src/CableDyn_OpenFAST_Aggregate.f90 b/src/CableDyn_OpenFAST_Aggregate.f90 index 0b965d12..fcc180f5 100644 --- a/src/CableDyn_OpenFAST_Aggregate.f90 +++ b/src/CableDyn_OpenFAST_Aggregate.f90 @@ -66,7 +66,7 @@ MODULE CableDyn_OpenFAST_Aggregate USE CableDyn_Model, ONLY: CD_ModelControlSaveType, CD_Recompute_Model_Acceleration, CD_MODEL_OK USE CableDyn_DeckDriver, ONLY: CD_DeckAggregateType, CD_Init_Deck_Aggregate, CD_End_Deck_Aggregate, & CD_DECKDRV_OK, CD_DECKDRV_BADINPUT, CD_Eval_Aggregate_Channel, & - CD_Cable_Deck_Node, & + CD_ChannelRow, CD_Channel_Row_Reset, CD_Cable_Deck_Node, & CD_Channel_Unit, CD_DECK_NAMELEN, CD_LineInitSummary, & DeckFailure, DeckLine, DeckPoint, CD_Fire_Deck_Failures, & CD_Replay_Deck_Failures, CD_Check_System_Plausibility, & @@ -138,7 +138,7 @@ MODULE CableDyn_OpenFAST_Aggregate ! channel count/header/unit for registration, and the per-channel evaluator for CalcOutput. PUBLIC :: CD_AGG_NumChannels PUBLIC :: CD_AGG_ChannelHeader - PUBLIC :: CD_AGG_EvalChannel + PUBLIC :: CD_AGG_EvalChannel, CD_AGG_EvalChannels PUBLIC :: CD_AGG_WriteStaticProfile ! Range graphs of the LINES flag r: the standalone mixed route and the single-turbine OpenFAST ! module sample and write them; the accumulated state rides a host's checkpoint @@ -229,6 +229,9 @@ MODULE CableDyn_OpenFAST_Aggregate CHARACTER(10), ALLOCATABLE :: chan_units(:) LOGICAL, ALLOCATABLE :: line_is_cable(:) INTEGER, ALLOCATABLE :: line_obj_index(:) + ! the line-wide values the channels of one CD_AGG_EvalChannels row share per cable (twists, + ! torques, load powers, section curvature, VIV amplitude); cleared at the start of every row + TYPE(CD_ChannelRow), ALLOCATABLE :: chan_rows(:) ! deck point ids of each cable's End A and End B (Point

F channels) INTEGER, ALLOCATABLE :: cable_points(:, :) ! FAILURE runtime table (line failures on the coupled path): rows fire at the @@ -2465,6 +2468,7 @@ SUBROUTINE CD_AGG_End(self, ErrStat, ErrMsg) IF (ALLOCATED(self%chan_units)) DEALLOCATE (self%chan_units) IF (ALLOCATED(self%line_is_cable)) DEALLOCATE (self%line_is_cable) IF (ALLOCATED(self%line_obj_index)) DEALLOCATE (self%line_obj_index) + IF (ALLOCATED(self%chan_rows)) DEALLOCATE (self%chan_rows) IF (ALLOCATED(self%cable_points)) DEALLOCATE (self%cable_points) IF (ALLOCATED(self%fl_off)) DEALLOCATE (self%fl_off) IF (ALLOCATED(self%fl_q)) DEALLOCATE (self%fl_q) @@ -2542,7 +2546,7 @@ LOGICAL FUNCTION CD_AGG_IsInitialized(self) RESULT(is_initialized) is_initialized = self%initialized END FUNCTION CD_AGG_IsInitialized - INTEGER FUNCTION CD_AGG_NumChannels(self) RESULT(n) + PURE INTEGER FUNCTION CD_AGG_NumChannels(self) RESULT(n) !! Number of deck OUTPUTS channels this module emits to the OpenFAST WriteOutput surface !! (0 when the deck declares no OUTPUTS -- the coupled run then writes no CableDyn columns). TYPE(CD_AGG_ModuleType), INTENT(IN) :: self @@ -2658,9 +2662,6 @@ SUBROUTINE CD_AGG_EvalChannel(self, i, value, ErrStat, ErrMsg) INTEGER, INTENT(OUT) :: ErrStat CHARACTER(*), INTENT(OUT) :: ErrMsg - INTEGER :: es - CHARACTER(1024) :: em - value = CD_ZERO IF (.NOT. require_initialized(self, ErrStat, ErrMsg)) RETURN IF (.NOT. ALLOCATED(self%channels) .OR. i < 1 .OR. i > CD_AGG_NumChannels(self)) THEN @@ -2668,7 +2669,87 @@ SUBROUTINE CD_AGG_EvalChannel(self, i, value, ErrStat, ErrMsg) ErrMsg = 'CableDyn_OpenFAST_Aggregate: channel index out of range' RETURN END IF - IF (self%has_rigid6) THEN + CALL eval_channel(self, i, value, .FALSE., ErrStat, ErrMsg) + END SUBROUTINE CD_AGG_EvalChannel + + SUBROUTINE CD_AGG_EvalChannels(self, values, n_done, ErrStat, ErrMsg) + !! Evaluate every channel (1 .. CD_AGG_NumChannels) into values(1:NumChannels) at the + !! aggregate's present state, as one output row: each channel's value is the one + !! CD_AGG_EvalChannel returns for it, bit for bit, while the line-wide values several channels + !! of a cable read (its element twists and torsion state, node torques, load powers, section + !! curvature, VIV amplitude) are evaluated once for the row instead of once per channel + !! (CD_ChannelRow, cleared at the start of every call, so nothing is carried from one state + !! to the next). n_done: the channels evaluated; on a failure values(1:n_done) hold the + !! channels before the one that failed, whose status and message are returned, as a loop over + !! CD_AGG_EvalChannel would stop there. + TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: self + REAL(wp), INTENT(INOUT) :: values(:) + INTEGER, INTENT(OUT) :: n_done + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + + INTEGER :: i, n, nc + + n_done = 0 + ErrStat = CD_AGG_OK + ErrMsg = '' + n = CD_AGG_NumChannels(self) + ! no channels: nothing to evaluate (as a loop over CD_AGG_EvalChannel would do nothing) + IF (n == 0) RETURN + IF (.NOT. require_initialized(self, ErrStat, ErrMsg)) RETURN + IF (SIZE(values) < n) THEN + ErrStat = CD_AGG_BADINPUT + ErrMsg = 'CableDyn_OpenFAST_Aggregate: channel value array smaller than the channel count' + RETURN + END IF + nc = 0 + IF (ALLOCATED(self%cables)) nc = SIZE(self%cables) + IF (ALLOCATED(self%chan_rows)) THEN + IF (SIZE(self%chan_rows) /= nc) DEALLOCATE (self%chan_rows) + END IF + IF (.NOT. ALLOCATED(self%chan_rows)) ALLOCATE (self%chan_rows(nc)) + CALL CD_Channel_Row_Reset(self%chan_rows) + ErrStat = CD_AGG_OK + ErrMsg = '' + DO i = 1, n + CALL eval_channel(self, i, values(i), .TRUE., ErrStat, ErrMsg) + IF (ErrStat /= CD_AGG_OK) EXIT + n_done = i + END DO + ! the row's values belong to this state only + CALL CD_Channel_Row_Reset(self%chan_rows) + END SUBROUTINE CD_AGG_EvalChannels + + SUBROUTINE eval_channel(self, i, value, use_row, ErrStat, ErrMsg) + !! Channel i (in range) at the present state through CD_Eval_Aggregate_Channel; use_row: + !! with the row values of CD_AGG_EvalChannels (self%chan_rows, sized and cleared there). + TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: self + INTEGER, INTENT(IN) :: i + REAL(wp), INTENT(OUT) :: value + LOGICAL, INTENT(IN) :: use_row + INTEGER, INTENT(OUT) :: ErrStat + CHARACTER(*), INTENT(OUT) :: ErrMsg + + INTEGER :: es + CHARACTER(1024) :: em + + IF (use_row) THEN + IF (self%has_rigid6) THEN + CALL CD_Eval_Aggregate_Channel(self%channels(i), self%has_sys, self%sys%fast%system, self%cables, & + self%line_is_cable, self%line_obj_index, value, es, em, & + cable_points=self%cable_points, rigid_rt=self%rigid6, ranges=self%ranges, & + rows=self%chan_rows) + ELSE IF (self%has_rod) THEN + CALL CD_Eval_Aggregate_Channel(self%channels(i), self%has_sys, self%sys%fast%system, self%cables, & + self%line_is_cable, self%line_obj_index, value, es, em, & + cable_points=self%cable_points, rod_rt=self%rod, ranges=self%ranges, & + rows=self%chan_rows) + ELSE + CALL CD_Eval_Aggregate_Channel(self%channels(i), self%has_sys, self%sys%fast%system, self%cables, & + self%line_is_cable, self%line_obj_index, value, es, em, & + cable_points=self%cable_points, ranges=self%ranges, rows=self%chan_rows) + END IF + ELSE IF (self%has_rigid6) THEN CALL CD_Eval_Aggregate_Channel(self%channels(i), self%has_sys, self%sys%fast%system, self%cables, & self%line_is_cable, self%line_obj_index, value, es, em, & cable_points=self%cable_points, rigid_rt=self%rigid6, ranges=self%ranges) @@ -2682,7 +2763,7 @@ SUBROUTINE CD_AGG_EvalChannel(self, i, value, ErrStat, ErrMsg) cable_points=self%cable_points, ranges=self%ranges) END IF CALL map_deck_status(es, em, ErrStat, ErrMsg) - END SUBROUTINE CD_AGG_EvalChannel + END SUBROUTINE eval_channel SUBROUTINE CD_AGG_Range_Sample(self, time, ErrStat, ErrMsg) !! Accumulate the range graphs (LINES flag r) at a committed output time: once per written diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index 5cda9ff2..ba90d6cf 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -99,6 +99,7 @@ MODULE CableDyn CD_AGG_NTurbines, CD_AGG_TurbineOfMoving, & CD_AGG_NFluidNodes, CD_AGG_GetFluidNodePositions, CD_AGG_SetFluidFields, & CD_AGG_NumChannels, CD_AGG_ChannelHeader, CD_AGG_EvalChannel, & + CD_AGG_EvalChannels, & CD_AGG_GetInitMetadata, CD_AGG_GetInitLine, & CD_AGG_WriteStaticProfile, CD_AGG_Range_Graphs, CD_AGG_Range_Sample, & CD_AGG_Range_Write, CD_AGG_Range_MirrorSize, CD_AGG_Reopen_Start, & @@ -201,6 +202,8 @@ END FUNCTION cd_cpu_guard_armed LOGICAL :: loads_cached = .FALSE. INTEGER(IntKi) :: loads_at_n = -1 REAL(wp), ALLOCATABLE :: ws_chan(:) + ! the committed-step row of the .CD.out when it evaluates its own channels (CD_CalcOutput) + REAL(wp), ALLOCATABLE :: ws_rowchan(:) ! Load predictor (nsuper > 1 with predictLoads; CableDyn_LoadPredictor): the coupled ! loads and moments of the committed solve before the last and its time (pred_t < 0: ! none), shifted in by CD_UpdateStates when a mooring step starts and mirrored into the @@ -2553,13 +2556,14 @@ SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg ) CHARACTER(*) , INTENT(INOUT) :: ErrMsg character(*), parameter :: RoutineName = 'CD_CalcOutput' - INTEGER(IntKi) :: ErrStat2, es, id, i + INTEGER(IntKi) :: ErrStat2, es, id, i, n_chan INTEGER(IntKi) :: prof_c0, prof_c1, prof_rate, prof_phase0 CHARACTER(ErrMsgLen) :: ErrMsg2 CHARACTER(ErrMsgLen) :: em - REAL(wp) :: cval REAL(wp) :: tau_pred ! load predictor: fraction of the mooring step elapsed LOGICAL :: fresh, state_overlaid + ! the channels this call evaluated are those of the committed state as it stands + LOGICAL :: chan_committed ! Report this call's OWN status: clear at entry (ErrStat is INTENT(INOUT) and ! every SetErrStat below only ACCUMULATES, so on the all-success path an @@ -2586,6 +2590,7 @@ SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg ) Inst(id)%prof_n_calcout = Inst(id)%prof_n_calcout + 1_IntKi END IF state_overlaid = .FALSE. + chan_committed = .FALSE. ! Evaluate the loads the mooring exerts on the coupling points. At nsuper = 1 (the ! mooring stepping at the glue rate) the CURRENT coupled kinematics are transferred @@ -2699,10 +2704,12 @@ SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg ) END IF ! Deck OUTPUTS channels are evaluated at the same aggregate state as the returned ! loads: with supercycling the last committed zero-order-hold mooring state, at - ! nsuper = 1 the state including the current coupled kinematics. + ! nsuper = 1 the state including the current coupled kinematics. The channels are + ! one row: the line-wide values several of a cable's channels read (its element twists, + ! node torques, ...) are evaluated once for the row (CD_AGG_EvalChannels). IF (Inst(id)%prof_enabled) CALL SYSTEM_CLOCK(prof_phase0) - DO i = 1, p%NumOuts - CALL CD_AGG_EvalChannel( Inst(id)%agg, i, cval, es, em ) + IF (p%NumOuts > 0) THEN + CALL CD_AGG_EvalChannels( Inst(id)%agg, Inst(id)%ws_chan, n_chan, es, em ) IF (es /= CD_AGG_OK) THEN CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: output channel evaluation failed: '// & TRIM(em), ErrStat, ErrMsg, RoutineName ) @@ -2712,8 +2719,9 @@ SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg ) END IF RETURN END IF - Inst(id)%ws_chan(i) = cval - END DO + END IF + ! supercycled, the state evaluated is the committed one itself (no overlay) + chan_committed = .NOT. state_overlaid IF (Inst(id)%prof_enabled) THEN CALL SYSTEM_CLOCK(prof_c1) Inst(id)%prof_t_channels = Inst(id)%prof_t_channels + & @@ -2747,7 +2755,8 @@ SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg ) ! probe/extra CalcOutput may drive with transient kinematics). The row must carry ! the committed state the stamp names, so its channels re-evaluate against the ! restored aggregate (at nsuper > 1 the committed state is live anyway and the - ! re-evaluation is identical). Keyed on last_solve_n: exactly one row per advance, + ! re-evaluation is identical, so a row whose channels this call has just evaluated on that + ! state takes them). Keyed on last_solve_n: exactly one row per advance, ! whichever call after it comes first; the t = 0 static row was written at Init. ! If a glue correction re-advances the same n, BACKSPACE replaces the provisional ! last record with the corrected committed result rather than duplicating the time. @@ -2755,14 +2764,24 @@ SUBROUTINE CD_CalcOutput( t, u, p, x, xd, z, other, y, m, ErrStat, ErrMsg ) IF (Inst(id)%prof_enabled) CALL SYSTEM_CLOCK(prof_phase0) IF (Inst(id)%last_solve_n == Inst(id)%native_wrote_n) BACKSPACE (Inst(id)%native_un) WRITE (Inst(id)%native_un, '(ES25.16E3)', ADVANCE='NO') MAX(Inst(id)%t_commit, 0.0_DbKi) - DO i = 1, p%NumOuts - CALL CD_AGG_EvalChannel( Inst(id)%agg, i, cval, es, em ) + IF (chan_committed) THEN + DO i = 1, p%NumOuts + WRITE (Inst(id)%native_un, CD_NATIVE_CHANNEL_FMT, ADVANCE='NO') CHAR(9), Inst(id)%ws_chan(i) + END DO + ELSE + IF (.NOT. ALLOCATED(Inst(id)%ws_rowchan)) ALLOCATE (Inst(id)%ws_rowchan(p%NumOuts)) + n_chan = 0 + es = CD_AGG_OK + IF (p%NumOuts > 0) CALL CD_AGG_EvalChannels( Inst(id)%agg, Inst(id)%ws_rowchan, n_chan, es, em ) + ! the channels before a failed one, as a channel-by-channel row writes them + DO i = 1, n_chan + WRITE (Inst(id)%native_un, CD_NATIVE_CHANNEL_FMT, ADVANCE='NO') CHAR(9), Inst(id)%ws_rowchan(i) + END DO IF (es /= CD_AGG_OK) THEN CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: committed-step channel record: '//TRIM(em), & ErrStat, ErrMsg, RoutineName ); RETURN END IF - WRITE (Inst(id)%native_un, CD_NATIVE_CHANNEL_FMT, ADVANCE='NO') CHAR(9), cval - END DO + END IF WRITE (Inst(id)%native_un, '(A)') '' ! keep the record readable during the run (and intact after a crash) FLUSH (Inst(id)%native_un) @@ -3304,10 +3323,10 @@ SUBROUTINE lin_eval( id, p, m, u, x_in, ErrStat, ErrMsg, dxdt, y_out ) TYPE(CD_OutputType), INTENT(INOUT), OPTIONAL :: y_out character(*), parameter :: RoutineName = 'CableDyn:lin_eval' - INTEGER(IntKi) :: ErrStat2, es, i, ic, il, ne, k + INTEGER(IntKi) :: ErrStat2, es, i, ic, il, ne, k, n_chan REAL(wp), ALLOCATABLE :: ve_rate(:), syr_rate(:) CHARACTER(ErrMsgLen) :: ErrMsg2, em - REAL(wp) :: cval, t_clock + REAL(wp) :: t_clock ErrStat = ErrID_None ErrMsg = '' @@ -3426,16 +3445,18 @@ SUBROUTINE lin_eval( id, p, m, u, x_in, ErrStat, ErrMsg, dxdt, y_out ) Inst(id)%lin_fld(:, i) = Inst(id)%ws_fld(:, i) Inst(id)%lin_moment(:, i) = Inst(id)%ws_moment(:, i) END DO - DO i = 1, p%NumOuts - CALL CD_AGG_EvalChannel( Inst(id)%agg, i, cval, es, em ) - IF (es /= CD_AGG_OK) THEN - CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: output channel evaluation failed: '// & - TRIM(em), ErrStat, ErrMsg, RoutineName ) - CALL restore; RETURN - END IF - y_out%WriteOutput(i) = REAL(cval, ReKi) - Inst(id)%lin_chan(i) = cval + ! the channels as one row (their shared line-wide values once) + n_chan = 0 + es = CD_AGG_OK + IF (p%NumOuts > 0) CALL CD_AGG_EvalChannels( Inst(id)%agg, Inst(id)%lin_chan, n_chan, es, em ) + DO i = 1, n_chan + y_out%WriteOutput(i) = REAL(Inst(id)%lin_chan(i), ReKi) END DO + IF (es /= CD_AGG_OK) THEN + CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: output channel evaluation failed: '// & + TRIM(em), ErrStat, ErrMsg, RoutineName ) + CALL restore; RETURN + END IF END IF CALL restore diff --git a/tests/test_channel_row.f90 b/tests/test_channel_row.f90 new file mode 100644 index 00000000..947abc64 --- /dev/null +++ b/tests/test_channel_row.f90 @@ -0,0 +1,266 @@ +! File: tests/test_channel_row.f90 +! SPDX-License-Identifier: Apache-2.0 +! Copyright (c) 2026 Jae Hoon Seo, SMI Lab, Inha University +PROGRAM test_channel_row + !! The deck channels of one output row evaluated together, as the OpenFAST shell's CalcOutput, + !! its committed-step record, its linearization and the standalone mixed route evaluate them + !! (CD_AGG_EvalChannels: the line-wide values a cable's channels read -- element twists, torsion + !! state, end twists, node torques, section curvature -- once per row), against the same + !! channels one at a time (CD_AGG_EvalChannel), bit for bit. The deck is coupled: an EI = 0 + !! line and two finite-EI cables restrained in torsion (nodal twist), the second with + !! torque-tension coupling (GJ|K) and a torsional end spring, every fairlead surging and + !! rolling with the platform; the channels mix twists, torques, bend moments, curvatures, + !! tensions, kinematics and point forces of all three lines. + !! 1. the static state, then every step of a rolling, surging march: a row's values must + !! follow the state (a line-wide value kept from the row before, the stale row, fails); + !! a second row at the same state repeats the first bit for bit; + !! 2. a non-stepping transfer of other kinematics (the shell's output probe) changes the + !! state without a step: the row follows it. + USE CableDyn_Precision, ONLY: wp + USE CableDyn_OpenFAST_Aggregate, ONLY: CD_AGG_ModuleType, CD_AGG_Init_From_Deck, CD_AGG_NMovingPoints, & + CD_AGG_GetMovingPointMesh, CD_AGG_UpdateStates_Moving, & + CD_AGG_Step_Moving, CD_AGG_CalcOutput, CD_AGG_NumChannels, & + CD_AGG_EvalChannel, CD_AGG_EvalChannels, CD_AGG_End, CD_AGG_OK + USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: INT64 + IMPLICIT NONE + + REAL(wp), PARAMETER :: PI = 3.14159265358979323846_wp, RHOW = 1025.0_wp + REAL(wp), PARAMETER :: DT = 0.05_wp, DEG = PI/180.0_wp + INTEGER, PARAMETER :: NSTEP = 12 + INTEGER :: n_fail = 0 + + CALL write_deck('chrow.dat') + CALL check_rows() + IF (n_fail > 0) THEN + WRITE (*, '(A,I0,A)') 'FAIL: ', n_fail, ' channel row check(s) failed' + ERROR STOP 1 + END IF + WRITE (*, '(A)') 'PASS: channel rows (one row against one channel at a time, through a march and a '// & + 'probe transfer)' + +CONTAINS + + SUBROUTINE require(cond, msg) + LOGICAL, INTENT(IN) :: cond + CHARACTER(*), INTENT(IN) :: msg + IF (.NOT. cond) THEN + n_fail = n_fail + 1 + WRITE (*, '(A,A)') 'FAILED: ', msg + END IF + END SUBROUTINE require + + LOGICAL FUNCTION same_bits(a, b) RESULT(same) + !! Whether two arrays of the same size have the same bit patterns. + REAL(wp), INTENT(IN) :: a(:), b(:) + INTEGER :: k + same = SIZE(a) == SIZE(b) + IF (.NOT. same) RETURN + DO k = 1, SIZE(a) + IF (TRANSFER(a(k), 0_INT64) /= TRANSFER(b(k), 0_INT64)) THEN + same = .FALSE. + RETURN + END IF + END DO + END FUNCTION same_bits + + SUBROUTINE write_deck(path) + !! Three taut 100 m lines from fairleads at x = 0 to anchors at x = 100 m, 40 m deep, the cables + !! neutrally buoyant: line 1 EI = 0 (twice the displaced mass); line 2 finite EI, clamped and + !! restrained in torsion at both ends with a quarter turn of pretwist; line 3 finite EI under + !! torque-tension coupling, clamped, rigid in torsion at End A and on a torsional spring at End B. + CHARACTER(*), INTENT(IN) :: path + INTEGER :: u + REAL(wp) :: m + CHARACTER(32) :: mtxt, rtxt + m = RHOW*0.25_wp*PI*0.04_wp + WRITE (mtxt, '(ES24.16)') m + OPEN (NEWUNIT=u, FILE=path, STATUS='REPLACE', ACTION='WRITE') + WRITE (u, '(A)') 'channel row gate' + 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) (-) (-) (-) (-)' + WRITE (rtxt, '(ES24.16)') 2.0_wp*m + WRITE (u, '(A)') 'rope 0.2 '//TRIM(rtxt)//' 1.0e7 0.0 0.0 0.0 0.0 0.0 0.0 1.2 0.0 1.0 0.0' + WRITE (u, '(A)') 'cab 0.2 '//TRIM(mtxt)//' 1.0e7 0.0 1.0e6 1.0e8 5.0e4 1.0 2.0 1.2 0.0 1.0 0.0' + WRITE (u, '(A)') 'arm 0.2 '//TRIM(mtxt)//' 1.0e7 0.0 1.0e6 1.0e8 5.0e4|4.0e3 1.0 2.0 1.2 0.0 1.0 0.0' + WRITE (u, '(A)') '--- POINTS ---' + WRITE (u, '(A)') 'ID Type X Y Z' + WRITE (u, '(A)') '(-) (-) (m) (m) (m)' + WRITE (u, '(A)') '1 Coupled 0.0 -20.0 -40.0' + WRITE (u, '(A)') '2 Fixed 100.0 -20.0 -40.0' + WRITE (u, '(A)') '3 Coupled 0.0 0.0 -40.0' + WRITE (u, '(A)') '4 Fixed 100.0 0.0 -40.0' + WRITE (u, '(A)') '5 Coupled 0.0 20.0 -40.0' + WRITE (u, '(A)') '6 Fixed 100.0 20.0 -40.0' + WRITE (u, '(A)') '--- LINES ---' + WRITE (u, '(A)') 'ID NodeA NodeB Outputs' + WRITE (u, '(A)') '(-) (-) (-) (-)' + WRITE (u, '(A)') '1 1 2 -' + WRITE (u, '(A)') '2 3 4 -' + WRITE (u, '(A)') '3 5 6 -' + WRITE (u, '(A)') '--- SECTIONS ---' + WRITE (u, '(A)') 'LineID LineType Length NumSegs' + WRITE (u, '(A)') '(-) (-) (m) (-)' + WRITE (u, '(A)') '1 rope 99.5 10' + WRITE (u, '(A)') '2 cab 99.5 12' + WRITE (u, '(A)') '3 arm 99.5 12' + WRITE (u, '(A)') '--- END CONNECTIONS ---' + WRITE (u, '(A)') 'LineID End Stiffness EzX EzY EzZ TorsStiffness NxX NxY NxZ Pretwist' + WRITE (u, '(A)') '(-) (-) (N-m/rad) (-) (-) (-) (N-m/rad) (-) (-) (-) (deg)' + WRITE (u, '(A)') '2 A Rigid 1 0 0 Rigid 0 0 1 0' + WRITE (u, '(A)') '2 B Rigid 1 0 0 Rigid 0 0 1 90' + WRITE (u, '(A)') '3 A Rigid 1 0 0 Rigid 0 0 1 0' + WRITE (u, '(A)') '3 B Rigid 1 0 0 2.0e4 0 0 1 45' + WRITE (u, '(A)') '--- OPTIONS ---' + WRITE (u, '(A)') '9.80665 g' + WRITE (u, '(A)') '1025.0 rhoW' + WRITE (u, '(A)') '0.05 dtM' + WRITE (u, '(A)') '--- OUTPUTS ---' + WRITE (u, '(A)') 'FairTen1' + WRITE (u, '(A)') 'L1N4pz' + WRITE (u, '(A)') 'L1N4ax' + WRITE (u, '(A)') 'Point1Fx' + WRITE (u, '(A)') 'Twist2' + WRITE (u, '(A)') 'Twist2N1' + WRITE (u, '(A)') 'Twist2N5' + WRITE (u, '(A)') 'Twist2N12' + WRITE (u, '(A)') 'Torq2N1' + WRITE (u, '(A)') 'Torq2N7' + WRITE (u, '(A)') 'BendMom2N3' + WRITE (u, '(A)') 'BendMom2N8' + WRITE (u, '(A)') 'Curv2N4' + WRITE (u, '(A)') 'CurvX2N4' + WRITE (u, '(A)') 'CurvY2N9' + WRITE (u, '(A)') 'Ten2N6' + WRITE (u, '(A)') 'L2N6vy' + WRITE (u, '(A)') 'L2N6ay' + WRITE (u, '(A)') 'FairTen2' + WRITE (u, '(A)') 'Twist3' + WRITE (u, '(A)') 'Twist3N2' + WRITE (u, '(A)') 'Twist3N11' + WRITE (u, '(A)') 'Torq3N1' + WRITE (u, '(A)') 'Torq3N13' + WRITE (u, '(A)') 'BendMom3N6' + WRITE (u, '(A)') 'CurvX3N6' + WRITE (u, '(A)') 'Ten3N6' + WRITE (u, '(A)') 'AnchTen3' + WRITE (u, '(A)') 'Point5Fz' + WRITE (u, '(A)') '--- END ---' + CLOSE (u) + END SUBROUTINE write_deck + + FUNCTION roll_dcm(phi) RESULT(r) + !! OpenFAST mesh orientation (global to local) of a roll phi about +x. + REAL(wp), INTENT(IN) :: phi + REAL(wp) :: r(3, 3) + r = 0.0_wp + r(1, 1) = 1.0_wp + r(2, 2) = COS(phi) + r(2, 3) = SIN(phi) + r(3, 2) = -SIN(phi) + r(3, 3) = COS(phi) + END FUNCTION roll_dcm + + SUBROUTINE one_at_a_time(agg, values) + TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: agg + REAL(wp), INTENT(OUT) :: values(:) + INTEGER :: i, es + CHARACTER(512) :: em + DO i = 1, SIZE(values) + CALL CD_AGG_EvalChannel(agg, i, values(i), es, em) + CALL require(es == CD_AGG_OK, 'channel evaluates: '//TRIM(em)) + END DO + END SUBROUTINE one_at_a_time + + SUBROUTINE row(agg, values) + TYPE(CD_AGG_ModuleType), INTENT(INOUT) :: agg + REAL(wp), INTENT(OUT) :: values(:) + INTEGER :: es, n_done + CHARACTER(512) :: em + values = 0.0_wp + CALL CD_AGG_EvalChannels(agg, values, n_done, es, em) + CALL require(es == CD_AGG_OK .AND. n_done == SIZE(values), 'the row evaluates: '//TRIM(em)) + END SUBROUTINE row + + SUBROUTINE check_rows() + TYPE(CD_AGG_ModuleType) :: agg + INTEGER, PARAMETER :: NCP = 3 + ! the twist and torque channels away from End A (Twist2N1, the twist from End A to End A, is 0) + INTEGER, PARAMETER :: TWIST_CH(10) = [5, 7, 8, 9, 10, 20, 21, 22, 23, 24] + REAL(wp) :: pos(3, NCP), vel(3, NCP), acc(3, NCP), load(3, NCP), orient(3, 3, NCP) + REAL(wp) :: omega(3, NCP), alpha(3, NCP), x0(3, NCP), pos2(3, NCP) + REAL(wp), ALLOCATABLE :: v_row(:), v_one(:), v_again(:), v_prev(:), v_b(:) + REAL(wp) :: phi, rate, amp, w, t + INTEGER :: es, ni, k, nmp, nch, j + LOGICAL :: cv, st, rows_ok, moved + CHARACTER(512) :: em + + CALL CD_AGG_Init_From_Deck(agg, 'chrow.dat', DT, es, em, host_orientation=.TRUE.) + CALL require(es == CD_AGG_OK, 'the channel row deck builds on the aggregate: '//TRIM(em)) + IF (es /= CD_AGG_OK) RETURN + nmp = CD_AGG_NMovingPoints(agg, es, em) + CALL require(nmp == NCP .AND. agg%ncable == 2, 'the deck is one EI = 0 line and two coupled cables') + IF (nmp /= NCP) RETURN + nch = CD_AGG_NumChannels(agg) + CALL require(nch == 29, 'the deck declares its 29 channels') + ALLOCATE (v_row(nch), v_one(nch), v_again(nch), v_prev(nch), v_b(nch)) + + ! 1. the static state, then a rolling, surging march + CALL row(agg, v_row) + CALL one_at_a_time(agg, v_one) + CALL require(same_bits(v_row, v_one), '1: static state: the row equals the channels one at a time') + CALL CD_AGG_GetMovingPointMesh(agg, pos, vel, acc, load, es, em, orientation=orient) + x0 = pos + rate = 20.0_wp*DEG + amp = 0.5_wp + w = 2.0_wp*PI/1.2_wp + rows_ok = .TRUE. + moved = .TRUE. + v_prev = v_row + DO k = 1, NSTEP + t = DT*k + phi = rate*t + DO j = 1, NCP + orient(:, :, j) = roll_dcm(phi) + pos(:, j) = x0(:, j) + pos(1, j) = x0(1, j) + amp*SIN(w*t) + vel(:, j) = 0.0_wp + vel(1, j) = amp*w*COS(w*t) + acc(:, j) = 0.0_wp + acc(1, j) = -amp*w*w*SIN(w*t) + omega(:, j) = [rate, 0.0_wp, 0.0_wp] + alpha(:, j) = 0.0_wp + END DO + CALL CD_AGG_Step_Moving(agg, DT, pos, vel, acc, cv, st, ni, es, em, orientation=orient, & + angular_velocity=omega, angular_acceleration=alpha) + CALL require(es == CD_AGG_OK .AND. cv, '1: the march step converges: '//TRIM(em)) + IF (es /= CD_AGG_OK) EXIT + CALL CD_AGG_CalcOutput(agg, es, em) + CALL row(agg, v_row) + CALL one_at_a_time(agg, v_one) + CALL row(agg, v_again) + rows_ok = rows_ok .AND. same_bits(v_row, v_one) .AND. same_bits(v_again, v_row) + ! every twist and torque channel moves with the roll: a row value kept from the state before + ! would show here + moved = moved .AND. ALL(ABS(v_row(TWIST_CH) - v_prev(TWIST_CH)) > 0.0_wp) + v_prev = v_row + END DO + CALL require(rows_ok, '1: every step: the row equals the channels one at a time, and a second row '// & + 'at the same state repeats it, bit for bit') + CALL require(moved, '1: the twist and torque channels change at every step (the rows follow the state)') + WRITE (*, '(A,F10.4,A,F10.4,A)') '1 march: Twist2 ', v_row(5), ' deg, Twist3 ', v_row(20), ' deg' + + ! 2. a non-stepping transfer of other kinematics changes the state without a step + pos2 = pos + pos2(2, :) = pos(2, :) + 0.05_wp + CALL CD_AGG_UpdateStates_Moving(agg, pos2, vel, acc, es, em, output_probe=.TRUE., orientation=orient, & + angular_velocity=omega, angular_acceleration=alpha) + CALL require(es == CD_AGG_OK, '2: the probe transfer applies: '//TRIM(em)) + CALL CD_AGG_CalcOutput(agg, es, em) + CALL row(agg, v_b) + CALL one_at_a_time(agg, v_one) + CALL require(same_bits(v_b, v_one), '2: after a probe transfer: the row equals the channels one at a time') + CALL require(.NOT. same_bits(v_b, v_row), '2: the probe transfer changes the row (it follows the state)') + CALL CD_AGG_End(agg, es, em) + END SUBROUTINE check_rows +END PROGRAM test_channel_row