From ca0a1c0c9c8b408c112596684fb1023abe5ef60b Mon Sep 17 00:00:00 2001 From: Jae Hoon Seo Date: Tue, 3 Nov 2026 22:49:18 +0900 Subject: [PATCH] fix(openfast): linearise from double-precision loads in a single-precision OpenFAST The release openfast.exe is OpenFAST's Visual Studio Release configuration, single precision (ReKi = 4 bytes). The linearisation of the line dynamics differenced the ReKi output mesh over a 1 um position step; with fairlead loads of a few MN the 7-digit mesh cannot resolve the change, and the reduced mooring stiffness of the IEA-15 MW UMaine chains read 3.2e3 N/m in surge against MoorDyn-F's 7.7e4 N/m (symmetry error 1.18), with the line modes, A and B unaffected. The gfortran CMake builds this was validated with are double precision. lin_eval now keeps its coupled loads and deck channels in double precision, and the two linearisation Jacobians pack those (pack_lin_outputs) in place of the ReKi mesh. A double-precision build packs the same values. RELEASE.md asks for the linearisation check on the release executable as well. Checked with gfortran OpenFAST builds at DOUBLE_PRECISION=OFF: before, openfast_lin_ab.py fails as the release executable does; after, it passes (surge 7.721e4 vs 7.716e4 N/m, symmetry 7e-6, fairlead blocks to 1.1e-3, the mixed cable deck's point stiffness to its static solves to 1e-4). Signed-off-by: Jae Hoon Seo --- CHANGELOG.md | 5 +++- RELEASE.md | 3 +- doc/openfast.rst | 6 +++- src/openfast/CableDyn_OF.f90 | 55 +++++++++++++++++++++++++++++++++--- 4 files changed, 62 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b4018d6..0d5fed4f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -143,7 +143,10 @@ All notable changes to CableDyn are recorded in this file. The format follows static stiffness (each matches its deck's static solutions to 7e-5; held, they would read the chain 0.6 % and the polyester 2.9 times too stiff). Free/Connect points, a `Rigid` cable end connection, VIV lines, bodies, rods, buoys and `CONTROL` fail closed with named messages. This - replaces the quasi-static linearisation without states. + replaces the quasi-static linearisation without states. The output differences use + CableDyn's double-precision loads, so a single-precision OpenFAST build (the release + `openfast.exe`, Visual Studio `Release`) linearises as a double-precision one; through its + 7-digit output mesh the UMaine chains' surge stiffness read 3.2e3 instead of 7.7e4 N/m. - Composite Syrope lines: a Syrope polyester section between plain `EI = 0` sections, such as a chain-polyester-chain mooring, in one LINE. The static start puts every Syrope element on the rest curve of its load history with its own secant EA (the tension varies along a sagging diff --git a/RELEASE.md b/RELEASE.md index 19dd0d58..57f76a2b 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -67,7 +67,8 @@ only the `cabledyn` package and its metadata. [DEVELOPMENT.md](DEVELOPMENT.md#openfast-integration)). It builds `openfast.exe` with CableDyn, checks that a coupled run prints the CableDyn banner, and checks that the output is finite. -2. **Linearisation check**: with the built executable, run +2. **Linearisation check**: with the built executable and again with the release workflow's + `openfast.exe` (single precision, the Visual Studio `Release` configuration), run `python validation/scripts/openfast_lin_ab.py --exe --case-dir `, where `` holds the `examples/openfast` IEA-15 UMaine twin decks and the r-test `MD_Shared` turbine-1 ElastoDyn, HydroDyn, SeaState and HydroData diff --git a/doc/openfast.rst b/doc/openfast.rst index 9b170d51..462fe6e7 100644 --- a/doc/openfast.rst +++ b/doc/openfast.rst @@ -474,7 +474,11 @@ are named ``Cable 1 node 2 Px, m``, ``Cable 1 node 2 Tx, -`` (tangent) and ``Cab differences: at each perturbed state or input, the accelerations are solved without a time step. Positions, tangents and coupled-point displacements are stepped by 1 µm, which stays inside the seabed penetration of a light cable and the stretch of every taut element. Velocities are stepped -by 0.1 m/s, MoorDyn-F's step. +by 0.1 m/s, MoorDyn-F's step. The output differences are taken from CableDyn's own +double-precision loads and channels, not from the OpenFAST output mesh, so a single-precision +OpenFAST build (the Visual Studio ``Release`` configuration, as the release ``openfast.exe``) +linearises as a double-precision one: its mesh carries 7 digits, too few for loads of a few MN +over a 1 µm step. A line restrained in torsion adds the twist angle of every node that its end frames do not hold (all nodes but a torsionally ``Rigid`` end), after the cables' positions and tangents, and their diff --git a/src/openfast/CableDyn_OF.f90 b/src/openfast/CableDyn_OF.f90 index 595c40d3..7e817107 100644 --- a/src/openfast/CableDyn_OF.f90 +++ b/src/openfast/CableDyn_OF.f90 @@ -179,6 +179,11 @@ END FUNCTION cd_cpu_guard_armed REAL(wp), ALLOCATABLE :: ws_pos(:,:), ws_vel(:,:), ws_acc(:,:), ws_fld(:,:), ws_moment(:,:) REAL(wp), ALLOCATABLE :: ws_omega(:,:), ws_alpha(:,:) REAL(wp), ALLOCATABLE :: ws_orient(:,:,:) + ! the coupled loads (3, ncp) and deck channels of the last lin_eval, in double precision: + ! the linearization Jacobians difference these (pack_lin_outputs), not the ReKi output + ! mesh, which a single-precision OpenFAST build (the Visual Studio Release configuration) + ! rounds to 7 digits, too few for loads of order 1e6 N over a 1 um step + REAL(wp), ALLOCATABLE :: lin_fld(:,:), lin_moment(:,:), lin_chan(:) ! saved committed coupled kinematics for the state-const CalcOutput at nsuper = 1 ! (save -> transfer u -> evaluate -> restore; see CD_CalcOutput) REAL(wp), ALLOCATABLE :: sv_pos(:,:), sv_vel(:,:), sv_acc(:,:), sv_orient(:,:,:) @@ -3066,9 +3071,18 @@ SUBROUTINE lin_eval( id, p, m, u, x_in, ErrStat, ErrMsg, dxdt, y_out ) CALL SetErrStat( ErrID_Fatal, 'CableDyn mooring module: '//TRIM(em), ErrStat, ErrMsg, RoutineName ) CALL restore; RETURN END IF + IF (ALLOCATED(Inst(id)%lin_fld)) THEN + IF (SIZE(Inst(id)%lin_fld, 2) /= Inst(id)%ncp .OR. SIZE(Inst(id)%lin_chan) /= p%NumOuts) & + DEALLOCATE (Inst(id)%lin_fld, Inst(id)%lin_moment, Inst(id)%lin_chan) + END IF + IF (.NOT. ALLOCATED(Inst(id)%lin_fld)) & + ALLOCATE (Inst(id)%lin_fld(3, Inst(id)%ncp), Inst(id)%lin_moment(3, Inst(id)%ncp), & + Inst(id)%lin_chan(p%NumOuts)) DO i = 1, Inst(id)%ncp y_out%CoupledLoads(1)%Force(:, i) = REAL(Inst(id)%ws_fld(:, i), ReKi) y_out%CoupledLoads(1)%Moment(:, i) = REAL(Inst(id)%ws_moment(:, i), ReKi) + 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 ) @@ -3078,6 +3092,7 @@ SUBROUTINE lin_eval( id, p, m, u, x_in, ErrStat, ErrMsg, dxdt, y_out ) CALL restore; RETURN END IF y_out%WriteOutput(i) = REAL(cval, ReKi) + Inst(id)%lin_chan(i) = cval END DO END IF CALL restore @@ -3097,6 +3112,38 @@ SUBROUTINE restore() END SUBROUTINE restore END SUBROUTINE lin_eval + SUBROUTINE pack_lin_outputs( id, Vars, y_lin, ValAry ) + !! The outputs of the last lin_eval packed as CD_VarsPackOutput packs y_lin, with the + !! coupled loads and the deck channels taken from lin_eval's double-precision copies: the + !! central differences of the loads over a 1 um position step resolve the stiffness of a + !! fairlead carrying a few MN in every build, the single-precision one included, where + !! the ReKi mesh carries 7 digits (the stiffness of the IEA-15 MW UMaine chains read 3.2e3 + !! instead of 7.7e4 N/m in surge). The other outputs (visualisation meshes) keep y_lin's. + INTEGER(IntKi), INTENT(IN ) :: id + TYPE(ModVarsType), INTENT(IN ) :: Vars + TYPE(CD_OutputType), INTENT(IN ) :: y_lin + REAL(R8Ki), INTENT(INOUT) :: ValAry(:) + INTEGER(IntKi) :: i, n + CALL CD_VarsPackOutput( Vars, y_lin, ValAry ) + IF (.NOT. ALLOCATED(Inst(id)%lin_fld)) RETURN + DO i = 1, SIZE(Vars%y) + n = Vars%y(i)%iLoc(2) - Vars%y(i)%iLoc(1) + 1 + SELECT CASE (Vars%y(i)%DL%Num) + CASE (CD_y_CoupledLoads) + IF (Vars%y(i)%DL%i1 /= 1 .OR. n /= SIZE(Inst(id)%lin_fld)) CYCLE + IF (Vars%y(i)%Field == FieldForce) THEN + ValAry(Vars%y(i)%iLoc(1):Vars%y(i)%iLoc(2)) = PACK(REAL(Inst(id)%lin_fld, R8Ki), .TRUE.) + ELSE IF (Vars%y(i)%Field == FieldMoment) THEN + ValAry(Vars%y(i)%iLoc(1):Vars%y(i)%iLoc(2)) = PACK(REAL(Inst(id)%lin_moment, R8Ki), .TRUE.) + END IF + CASE (CD_y_WriteOutput) + IF (Vars%y(i)%iLB < 1 .OR. Vars%y(i)%iUB > SIZE(Inst(id)%lin_chan) .OR. & + n /= Vars%y(i)%iUB - Vars%y(i)%iLB + 1) CYCLE + ValAry(Vars%y(i)%iLoc(1):Vars%y(i)%iLoc(2)) = REAL(Inst(id)%lin_chan(Vars%y(i)%iLB:Vars%y(i)%iUB), R8Ki) + END SELECT + END DO + END SUBROUTINE pack_lin_outputs + !---------------------------------------------------------------------------------------------------------------------------------- SUBROUTINE CD_End(u, p, x, xd, z, other, y, m, ErrStat , ErrMsg) USE, INTRINSIC :: ISO_FORTRAN_ENV, ONLY: int64 @@ -3306,13 +3353,13 @@ SUBROUTINE CD_JacobianPInput(Vars, t, u, p, x, xd, z, OtherState, y, m, ErrStat, CALL CD_VarsUnpackInput( Vars, m%Jac%u_perturb, m%u_perturb ) CALL lin_eval( m%CDInst, p, m, m%u_perturb, x, ErrStat2, ErrMsg2, dxdt=m%dxdt_lin, y_out=m%y_lin ) IF (Failed()) RETURN - CALL CD_VarsPackOutput( Vars, m%y_lin, m%Jac%y_pos ) + CALL pack_lin_outputs( m%CDInst, Vars, m%y_lin, m%Jac%y_pos ) CALL CD_VarsPackContStateDeriv( Vars, m%dxdt_lin, m%Jac%x_pos ) CALL MV_Perturb( Vars%u(i), j, -1, m%Jac%u, m%Jac%u_perturb ) CALL CD_VarsUnpackInput( Vars, m%Jac%u_perturb, m%u_perturb ) CALL lin_eval( m%CDInst, p, m, m%u_perturb, x, ErrStat2, ErrMsg2, dxdt=m%dxdt_lin, y_out=m%y_lin ) IF (Failed()) RETURN - CALL CD_VarsPackOutput( Vars, m%y_lin, m%Jac%y_neg ) + CALL pack_lin_outputs( m%CDInst, Vars, m%y_lin, m%Jac%y_neg ) CALL CD_VarsPackContStateDeriv( Vars, m%dxdt_lin, m%Jac%x_neg ) IF (PRESENT(dYdu)) CALL MV_ComputeCentralDiff( Vars%y, Vars%u(i)%Perturb, m%Jac%y_pos, m%Jac%y_neg, & dYdu(:, iCol) ) @@ -3452,14 +3499,14 @@ SUBROUTINE CD_JacobianPContState(Vars, t, u, p, x, xd, z, OtherState, y, m, ErrS CALL lin_eval( m%CDInst, p, m, u, m%x_perturb, ErrStat2, ErrMsg2, dxdt=m%dxdt_lin, y_out=m%y_lin ) CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) IF (ErrStat >= AbortErrLev) RETURN - CALL CD_VarsPackOutput( Vars, m%y_lin, m%Jac%y_pos ) + CALL pack_lin_outputs( m%CDInst, Vars, m%y_lin, m%Jac%y_pos ) CALL CD_VarsPackContStateDeriv( Vars, m%dxdt_lin, m%Jac%x_pos ) CALL MV_Perturb( Vars%x(i), j, -1, m%Jac%x, m%Jac%x_perturb ) CALL CD_VarsUnpackContState( Vars, m%Jac%x_perturb, m%x_perturb ) CALL lin_eval( m%CDInst, p, m, u, m%x_perturb, ErrStat2, ErrMsg2, dxdt=m%dxdt_lin, y_out=m%y_lin ) CALL SetErrStat( ErrStat2, ErrMsg2, ErrStat, ErrMsg, RoutineName ) IF (ErrStat >= AbortErrLev) RETURN - CALL CD_VarsPackOutput( Vars, m%y_lin, m%Jac%y_neg ) + CALL pack_lin_outputs( m%CDInst, Vars, m%y_lin, m%Jac%y_neg ) CALL CD_VarsPackContStateDeriv( Vars, m%dxdt_lin, m%Jac%x_neg ) IF (PRESENT(dYdx)) CALL MV_ComputeCentralDiff( Vars%y, Vars%x(i)%Perturb, m%Jac%y_pos, m%Jac%y_neg, & dYdx(:, iCol) )