From 3068357025d8aedca456d952b00dc288ff2e9315 Mon Sep 17 00:00:00 2001 From: AlvaroDFC Date: Tue, 10 Nov 2026 14:22:46 -0700 Subject: [PATCH] added option to return the static (potential flow), dynamic(morrison elements) or combined added mass for the c-bindings. --- glue-codes/python/pyOpenFAST/hydrodyn.py | 8 +++++--- modules/hydrodyn/src/HydroDyn_C_Binding.f90 | 12 ++++++++++-- reg_tests/r-test | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/glue-codes/python/pyOpenFAST/hydrodyn.py b/glue-codes/python/pyOpenFAST/hydrodyn.py index 507554a9fc..bdd6c3369e 100644 --- a/glue-codes/python/pyOpenFAST/hydrodyn.py +++ b/glue-codes/python/pyOpenFAST/hydrodyn.py @@ -192,7 +192,8 @@ def _initialize_routines(self): POINTER(c_float), # nodeAdm -- node added mass matrix in flat array of 6*numNodePts*6*numNodePts POINTER(c_float), # Output Channel Values POINTER(c_int), # ErrStat_C - POINTER(c_char) # ErrMsg_C + POINTER(c_char), # ErrMsg_C + POINTER(c_int) # DynamicOnly_C -- optional (NULL = full added mass; nonzero = strip-theory part only) ] self.HydroDyn_C_CalcOutput_and_AddedMass.restype = c_int @@ -359,7 +360,7 @@ def hydrodyn_calcOutput(self, time, nodePos, nodeVel, nodeAcc, nodeFrcMom, outpu outputChannelValues[k] = float(outputChannelValues_c[k]) # hydrodyn_calcOutput_and_addedMass ------------------------------------------------------------------------------------------------------ - def hydrodyn_calcOutput_and_addedMass(self, time, nodePos, nodeVel, nodeFrcMom, nodeAdm, outputChannelValues): + def hydrodyn_calcOutput_and_addedMass(self, time, nodePos, nodeVel, nodeFrcMom, nodeAdm, outputChannelValues, dynamicOnly=None): # Check input motion info self.check_input_motions_noAcc(time,nodePos,nodeVel) @@ -396,7 +397,8 @@ def hydrodyn_calcOutput_and_addedMass(self, time, nodePos, nodeVel, nodeFrcMom, nodeAdm_flat_c, # OUT: resulting forces/moments array outputChannelValues_c, # OUT: output channel values as described in input file byref(self.error_status_c), # OUT: ErrStat_C - self.error_message_c # OUT: ErrMsg_C + self.error_message_c, # OUT: ErrMsg_C + None if dynamicOnly is None else byref(c_int(int(bool(dynamicOnly)))) # IN (optional): nonzero returns only the strip-theory added mass ) self.check_error() diff --git a/modules/hydrodyn/src/HydroDyn_C_Binding.f90 b/modules/hydrodyn/src/HydroDyn_C_Binding.f90 index ac713ce40d..b40bdef6ef 100644 --- a/modules/hydrodyn/src/HydroDyn_C_Binding.f90 +++ b/modules/hydrodyn/src/HydroDyn_C_Binding.f90 @@ -859,10 +859,12 @@ END SUBROUTINE HydroDyn_C_CalcOutput !-------------------------------------- HydroDyn CalcOutput_and_AddedMass -------------------------------------- !> This routine is similar to the HydroDyn_C_CalcOutput, but splits the forces returned from HydroDyn_CalcOutput !! into the hydrodynamic forces without added mass, and a separate added mass matrix. +!! If the optional DynamicOnly_C is passed and nonzero, the matrix holds only the strip-theory (Morison) +!! contribution; the potential-flow (WAMIT) contribution is omitted. Otherwise the full matrix is returned. !=============================================================================================================== SUBROUTINE HydroDyn_C_CalcOutput_and_AddedMass(Time_C, NumNodePts_C, NodePos_C, NodeVel_C, & - NodeFrc_C, NodeAdm_C, OutputChannelValues_C, ErrStat_C, ErrMsg_C) BIND (C, NAME='HydroDyn_C_CalcOutput_and_AddedMass') + NodeFrc_C, NodeAdm_C, OutputChannelValues_C, ErrStat_C, ErrMsg_C, DynamicOnly_C) BIND (C, NAME='HydroDyn_C_CalcOutput_and_AddedMass') implicit none #ifndef IMPLICIT_DLLEXPORT !DEC$ ATTRIBUTES DLLEXPORT :: HydroDyn_C_CalcOutput_and_AddedMass @@ -877,8 +879,10 @@ SUBROUTINE HydroDyn_C_CalcOutput_and_AddedMass(Time_C, NumNodePts_C, NodePos_C, real(c_float), intent( out) :: OutputChannelValues_C(SeaSt%p%NumOuts+HD%p%NumOuts) integer(c_int), intent( out) :: ErrStat_C character(kind=c_char), intent( out) :: ErrMsg_C(ErrMsgLen_C) + integer(c_int), intent(in ), optional :: DynamicOnly_C !< if present and nonzero, NodeAdm_C excludes the potential-flow (WAMIT) contribution ! Local variables + logical :: DynamicOnly real(DbKi) :: Time integer(IntKi) :: iNode,i,j,k,m integer(IntKi) :: ErrStat !< aggregated error status @@ -891,6 +895,9 @@ SUBROUTINE HydroDyn_C_CalcOutput_and_AddedMass(Time_C, NumNodePts_C, NodePos_C, ErrStat = ErrID_None ErrMsg = "" + DynamicOnly = .false. + if (present(DynamicOnly_C)) DynamicOnly = DynamicOnly_C /= 0_c_int + ! Sanity check -- number of node points cannot change if ( NumNodePts /= int(NumNodePts_C, IntKi) ) then ErrStat2 = ErrID_Fatal @@ -933,7 +940,8 @@ SUBROUTINE HydroDyn_C_CalcOutput_and_AddedMass(Time_C, NumNodePts_C, NodePos_C, Perturbed = .false. ! Contributions from potential-flow bodies - need to perturb the acceleration of one node at a time, but only need to consider nodes with motion mapping to WAMIT mesh - if ( HD%u(1)%WAMITMesh%Committed ) then + ! (skipped when only the dynamic, strip-theory part is requested) + if ( HD%u(1)%WAMITMesh%Committed .and. .not. DynamicOnly ) then ! Map the potential-flow loads without added-mass contributions and strip-theory contributions to HD_LoadMesh as a baseline call Transfer_Point_to_Point( HD%y%WAMITMesh, HD_LoadMesh, Map_HD_WB_P_2_Load, ErrStat2, ErrMsg2, HD%u(1)%WAMITMesh, HD_MotionMesh ) diff --git a/reg_tests/r-test b/reg_tests/r-test index dfb039d208..792eae450b 160000 --- a/reg_tests/r-test +++ b/reg_tests/r-test @@ -1 +1 @@ -Subproject commit dfb039d20845b292c2df21fdf2dcbe1b1eb499b3 +Subproject commit 792eae450bc40ff62dff5664008f170d39cb463c