Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new routine and variables to init in the ADI_c_binding interface #2571

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/aerodyn/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ target_link_libraries(unsteadyaero_driver basicaerolib lindynlib versioninfolib)
add_library(aerodyn_inflow_c_binding SHARED
src/AeroDyn_Inflow_C_Binding.f90
)
target_link_libraries(aerodyn_inflow_c_binding adilib aerodyn_driver_subs versioninfolib)
target_link_libraries(aerodyn_inflow_c_binding aerodyn_driver_subs versioninfolib)
if(APPLE OR UNIX)
target_compile_definitions(aerodyn_inflow_c_binding PRIVATE IMPLICIT_DLLEXPORT)
endif()
Expand Down
49 changes: 47 additions & 2 deletions modules/aerodyn/python-lib/aerodyn_inflow_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def __init__(self, library_path):
# VTK
self.WrVTK = 0 # default of no vtk output
self.WrVTK_Type = 1 # default of surface meshes
self.WrVTK_DT = 0.0 # default to all
self.VTKNacDim = np.array([-2.5,-2.5,0,10,5,5], dtype="float32") # default nacelle dimension for VTK surface rendering [x0,y0,z0,Lx,Ly,Lz] (m)
self.VTKHubRad = 1.5 # default hub radius for VTK surface rendering

Expand Down Expand Up @@ -156,6 +157,7 @@ def __init__(self, library_path):
# If HD writes a file (echo, summary, or other), use this for the
# root of the file name.
self.outRootName = "Output_ADIlib_default"
self.outVTKdir = "" # Set to specify a directory relative to the input files (created if doesn't exist)

# _initialize_routines() ------------------------------------------------------------------------------------------------------------
def _initialize_routines(self):
Expand Down Expand Up @@ -199,6 +201,7 @@ def _initialize_routines(self):
POINTER(c_char_p), # IfW input file as string
POINTER(c_int), # IfW input file string length
POINTER(c_char), # OutRootName
POINTER(c_char), # OutVTKdir
POINTER(c_float), # gravity
POINTER(c_float), # defFldDens
POINTER(c_float), # defKinVisc
Expand All @@ -213,6 +216,7 @@ def _initialize_routines(self):
POINTER(c_int), # storeHHVel
POINTER(c_int), # WrVTK
POINTER(c_int), # WrVTK_Type
POINTER(c_double), # WrVTK_DT -- 0 or negative to do every step
POINTER(c_float), # VTKNacDim
POINTER(c_float), # VTKHubRad
POINTER(c_int), # wrOuts -- file format for writing outputs
Expand Down Expand Up @@ -267,6 +271,15 @@ def _initialize_routines(self):
self.ADI_C_GetRotorLoads.restype = c_int


self.ADI_C_GetDiskAvgVel.argtypes = [
POINTER(c_int), # iturb
POINTER(c_float), # Disk average vel vector
POINTER(c_int), # ErrStat_C
POINTER(c_char) # ErrMsg_C
]
self.ADI_C_GetDiskAvgVel.restype = c_int


self.ADI_C_CalcOutput.argtypes = [
POINTER(c_double), # Time_C
POINTER(c_float), # Output Channel Values
Expand Down Expand Up @@ -370,6 +383,7 @@ def adi_init(self, AD_input_string_array, IfW_input_string_array):

# Rootname for ADI output files (echo etc).
_outRootName_c = create_string_buffer((self.outRootName.ljust(self.default_str_c_len)).encode('utf-8'))
_outVTKdir_c = create_string_buffer((self.outVTKdir.ljust(self.default_str_c_len)).encode('utf-8'))

# Flatten arrays to pass
# [x2,y1,z1, x2,y2,z2 ...]
Expand All @@ -384,6 +398,7 @@ def adi_init(self, AD_input_string_array, IfW_input_string_array):
c_char_p(IfW_input_string), # IN: IfW input file as string (or filename if IfWinputPass is false)
byref(c_int(IfW_input_string_length)), # IN: IfW input file string length
_outRootName_c, # IN: rootname for ADI file writing
_outVTKdir_c, # IN: directory for vtk output files (relative to input file)
byref(c_float(self.gravity)), # IN: gravity
byref(c_float(self.defFldDens)), # IN: defFldDens
byref(c_float(self.defKinVisc)), # IN: defKinVisc
Expand All @@ -398,6 +413,7 @@ def adi_init(self, AD_input_string_array, IfW_input_string_array):
byref(c_int(self.storeHHVel)), # IN: storeHHVel
byref(c_int(self.WrVTK)), # IN: WrVTK
byref(c_int(self.WrVTK_Type)), # IN: WrVTK_Type
byref(c_double(self.WrVTK_DT)), # IN: WrVTK_DT
VTKNacDim_c, # IN: VTKNacDim
byref(c_float(self.VTKHubRad)), # IN: VTKHubRad
byref(c_int(self.wrOuts)), # IN: wrOuts -- file format for writing outputs
Expand Down Expand Up @@ -490,7 +506,7 @@ def adi_setrotormotion(self, iturb, \
self.check_error()


# adi_calcOutput ------------------------------------------------------------------------------------------------------------
# adi_getrotorloads ---------------------------------------------------------------------------------------------------------
def adi_getrotorloads(self, iturb, meshFrcMom, hhVel=None):
# Resulting Forces/moments -- [Fx1,Fy1,Fz1,Mx1,My1,Mz1, Fx2,Fy2,Fz2,Mx2,My2,Mz2 ...]
_meshFrc_flat_c = (c_float * (6 * self.numMeshPts))(0.0,)
Expand Down Expand Up @@ -525,6 +541,28 @@ def adi_getrotorloads(self, iturb, meshFrcMom, hhVel=None):
hhVel[1] = _hhVel_flat_c[1]
hhVel[2] = _hhVel_flat_c[2]


# adi_getdiskavgvel ---------------------------------------------------------------------------------------------------------
def adi_getdiskavgvel(self, iturb, diskAvgVel):
# Resulting disk average velocity [Vx,Vy,Vz]
_diskAvgVel_flat_c = (c_float * 3)(0.0,)

# Run ADI_GetDiskAvgVel
self.ADI_C_GetDiskAvgVel(
c_int(iturb), # IN: iturb -- current turbine number
_diskAvgVel_flat_c, # OUT: disk average velocity [Vx, Vy, Vz]
byref(self.error_status_c), # OUT: ErrStat_C
self.error_message_c # OUT: ErrMsg_C
)

self.check_error()

## Disk average wind speed
diskAvgVel[0] = _diskAvgVel_flat_c[0]
diskAvgVel[1] = _diskAvgVel_flat_c[1]
diskAvgVel[2] = _diskAvgVel_flat_c[2]


# adi_calcOutput ------------------------------------------------------------------------------------------------------------
def adi_calcOutput(self, time, outputChannelValues):

Expand Down Expand Up @@ -907,6 +945,9 @@ def __init__(self,filename,numMeshPts):
self.DbgFile.write(f_string.format(f_num+"Mx" ))
self.DbgFile.write(f_string.format(f_num+"My" ))
self.DbgFile.write(f_string.format(f_num+"Mz" ))
self.DbgFile.write(f_string.format(f_num+"DskAvgVx" ))
self.DbgFile.write(f_string.format(f_num+"DskAvgVy" ))
self.DbgFile.write(f_string.format(f_num+"DskAvgVz" ))
self.DbgFile.write("\n")
self.DbgFile.write(" (s) ")
for i in range(1,self.numMeshPts+1):
Expand Down Expand Up @@ -934,10 +975,13 @@ def __init__(self,filename,numMeshPts):
self.DbgFile.write(f_string.format("(N-m)" ))
self.DbgFile.write(f_string.format("(N-m)" ))
self.DbgFile.write(f_string.format("(N-m)" ))
self.DbgFile.write(f_string.format("(m/s)" ))
self.DbgFile.write(f_string.format("(m/s)" ))
self.DbgFile.write(f_string.format("(m/s)" ))
self.DbgFile.write("\n")
self.opened = True

def write(self,t,meshPos,meshVel,meshAcc,meshFrc):
def write(self,t,meshPos,meshVel,meshAcc,meshFrc,DiskAvgVel):
t_string = "{:10.4f}"
f_string3 = "{:25.7e}"*3
f_string6 = "{:25.7e}"*6
Expand All @@ -947,6 +991,7 @@ def write(self,t,meshPos,meshVel,meshAcc,meshFrc):
self.DbgFile.write(f_string6.format(*meshVel[i,:]))
self.DbgFile.write(f_string6.format(*meshAcc[i,:]))
self.DbgFile.write(f_string6.format(*meshFrc[i,:]))
self.DbgFile.write(f_string3.format(*DiskAvgVel[:]))
self.DbgFile.write("\n")

def end(self):
Expand Down
11 changes: 6 additions & 5 deletions modules/aerodyn/src/AeroDyn_Driver_Registry.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ typedef ^ ^ character(25) Fmt_a
typedef ^ ^ character(1) delim - - - "column delimiter" "-"
typedef ^ ^ character(20) outFmt - - - "Format specifier" "-"
typedef ^ ^ IntKi fileFmt - - - "Output format 1=Text, 2=Binary, 3=Both" "-"
typedef ^ ^ IntKi wrVTK - - - "0= no vtk, 1=init only, 2=animation" "-"
typedef ^ ^ IntKi WrVTK - - - "0= no vtk, 1=init only, 2=animation" "-"
typedef ^ ^ IntKi WrVTK_Type - - - "Flag for VTK output type (1=surface, 2=line, 3=both)" -
typedef ^ ^ character(1024) Root - - - "Output file rootname" "-"
typedef ^ ^ character(1024) VTK_OutFileRoot - - - "Output file rootname for vtk" "-"
typedef ^ ^ character(1024) VTK_OutFileRoot - - - "Output file rootname for vtk (includes directory)" "-"
typedef ^ ^ character(ChanLen) WriteOutputHdr {:} - - "Channel headers" "-"
typedef ^ ^ character(ChanLen) WriteOutputUnt {:} - - "Channel units" "-"
typedef ^ ^ ReKi storage ::: - - "nTurbines x nChannel x nTime"
typedef ^ ^ ReKi outLine : - - "Output line to be written to disk"
typedef ^ ^ DvrVTK_SurfaceType VTK_surface : - - "Data for VTK surface visualization"
typedef ^ ^ INTEGER VTK_tWidth - - - "Width of number of files for leading zeros in file name format" -
typedef ^ ^ INTEGER n_VTKTime - - - "Number of time steps between writing VTK files" -
typedef ^ ^ IntKi VTK_tWidth - - - "Width of number of files for leading zeros in file name format" -
typedef ^ ^ IntKi n_VTKTime - - - "Number of time steps between writing VTK files" -
typedef ^ ^ DbKi VTK_DT - - - "Write VTK time step" -
typedef ^ ^ SiKi VTKHubRad - - - "Hub radius for visualization" m
typedef ^ ^ ReKi VTKNacDim 6 - - "Nacelle dimensions for visualization" m
typedef ^ ^ SiKi VTKRefPoint 3 - - "RefPoint for VTK outputs"
Expand Down Expand Up @@ -149,7 +150,7 @@ typedef ^ ^ IntKi iCase
typedef ^ ^ ReKi timeSeries :: - - "Times series inputs when AnalysisType=1, 6 columns, Time, WndSpeed, ShearExp, RotSpd, Pitch, Yaw" "-"
typedef ^ ^ IntKi iTimeSeries - - - "Stored index to optimize time interpolation" -
typedef ^ ^ character(1024) root - - - "Output file rootname" "-"
typedef ^ ^ Dvr_Outputs out - - - "data for driver output file" "-"
typedef ^ ^ Dvr_Outputs out - - - "data for driver output file" "-"
typedef ^ ^ ADI_IW_InputData IW_InitInp - - - "" -

# ..... Data to wrap the driver ..........................................................................................................
Expand Down
Loading