###################################################################################################################################
# Registry for InflowWind, creates MODULE InflowWind_Types
# Module InflowWind_Types contains all of the user-defined types needed in InflowWind. It also contains copy, destroy, pack, and
# unpack routines associated with each defined data types.
###################################################################################################################################
# Entries are of the form
# keyword <InflowWind[/ModuleAbvr]> <TypeName>   <FieldType>    <FieldName>  <Dims>  <Ctrl> <DNAME> <DESCRIP> <UNITS>
###################################################################################################################################

usefrom IfW_FlowField.txt
usefrom InflowWind_IO.txt
usefrom Lidar.txt

include Registry_NWTC_Library.txt


param    InflowWind/InflowWind   -                 IntKi             Undef_WindNumber     -     0     -     "This is the code for an undefined WindFileType"                           -
param    ^                       -                 IntKi             Steady_WindNumber    -     1     -     "Steady wind.  Calculated internally."                                     -
param    ^                       -                 IntKi             Uniform_WindNumber   -     2     -     "Uniform wind.  Formally known as a Hub-Height wind file."                 -
param    ^                       -                 IntKi             TSFF_WindNumber      -     3     -     "TurbSim full-field binary file."                                          -
param    ^                       -                 IntKi             BladedFF_WindNumber  -     4     -     "Bladed style binary full-field file.  Includes native bladed format"      -
param    ^                       -                 IntKi             HAWC_WindNumber      -     5     -     "HAWC wind file."                                                          -
param    ^                       -                 IntKi             User_WindNumber      -     6     -     "User defined wind."                                                       -
param    ^                       -                 IntKi             BladedFF_Shr_WindNumber  - 7     -     "Native Bladed binary full-field file."      -
param    ^                       -                 IntKi             FDext_WindNumber     -     8     -     "4D wind from external souce (i.e., FAST.Farm)."                                                       -
param    ^                       -                 IntKi             Point_WindNumber     -     9     -     "1D wind components from ExtInflow"                                                       -
param    ^                       -                 IntKi             Highest_WindNumber   -     9     -     "Highest wind number supported."                                           -

param    ^                       -                 IntKi             IfW_NumPtsAvg        -     144    -     "Number of points averaged for rotor-average wind speed"                                           -

#########################
# ..... Input file data ...........................................................................................................
# This is data defined in the Input File for this module (or could otherwise be passed in)
# ..... Primary Input file data ...................................................................................................
typedef  InflowWind/InflowWind   InflowWind_InputFile   LOGICAL      EchoFlag          -     -     -     "Echo the input file"                                    -
typedef  ^                       ^                 IntKi             WindType          -     0     -     "Type of windfile"                                       -
typedef  ^                       ^                 ReKi              PropagationDir    -     -     -     "Direction of wind propagation (meteorological direction)"  (degrees)
typedef  ^                       ^                 ReKi              VFlowAngle        -     -     -     "Vertical (upflow) angle"                                degrees
typedef  ^                       ^                 LOGICAL           VelInterpCubic    -   .FALSE. -     "Use cubic interpolation for velocity in time (false=linear, true=cubic) [Used with WindType=2,3,4,5,7]" -
typedef  ^                       ^                 IntKi             NWindVel          -     -     -     "Number of points to output the wind velocity (0 to 9)"
typedef  ^                       ^                 ReKi              WindVxiList       :     -     -     "List of X coordinates for wind velocity measurements"   meters
typedef  ^                       ^                 ReKi              WindVyiList       :     -     -     "List of Y coordinates for wind velocity measurements"   meters
typedef  ^                       ^                 ReKi              WindVziList       :     -     -     "List of Z coordinates for wind velocity measurements"   meters
typedef  ^                       ^                 ReKi              Steady_HWindSpeed -     -     -     "Steady wind -- horizontal windspeed"                    meters/s
typedef  ^                       ^                 ReKi              Steady_RefHt      -     -     -     "Steady wind -- reference height"                        meters
typedef  ^                       ^                 ReKi              Steady_PLexp      -     -     -     "Steady wind -- power law exponent"                      -
typedef  ^                       ^                 CHARACTER(1024)   Uniform_FileName  -     -     -     "Uniform wind -- filename"                               -
typedef  ^                       ^                 ReKi              Uniform_RefHt     -     -     -     "Uniform wind -- reference height"                       meters
typedef  ^                       ^                 ReKi              Uniform_RefLength -     -     -     "Uniform wind -- reference length"                       meters
typedef  ^                       ^                 CHARACTER(1024)   TSFF_FileName     -     -     -     "TurbSim Full-Field -- filename"                         -
typedef  ^                       ^                 CHARACTER(1024)   BladedFF_FileName -     -     -     "Bladed-style Full-Field -- filename"                    -
typedef  ^                       ^                 LOGICAL           BladedFF_TowerFile -    -     -     "Bladed-style Full-Field -- tower file exists"           -
typedef  ^                       ^                 LOGICAL           CTTS_CoherentTurb -     .FALSE.     -     "Coherent turbulence data exists"                        -
typedef  ^                       ^                 CHARACTER(1024)   CTTS_FileName     -     -     -     "Name of coherent turbulence file"                       -
typedef  ^                       ^                 CHARACTER(1024)   CTTS_Path         -     -     -     "Path to coherent turbulence binary data files"          -
typedef  ^                       ^                 CHARACTER(1024)   HAWC_FileName_u   -     -     -     "HAWC -- u component binary data file name"              -
typedef  ^                       ^                 CHARACTER(1024)   HAWC_FileName_v   -     -     -     "HAWC -- v component binary data file name"              -
typedef  ^                       ^                 CHARACTER(1024)   HAWC_FileName_w   -     -     -     "HAWC -- w component binary data file name"              -
typedef  ^                       ^                 IntKi             HAWC_nx           -     -     -     "HAWC -- number of grids in x direction"                 -
typedef  ^                       ^                 IntKi             HAWC_ny           -     -     -     "HAWC -- number of grids in y direction"                 -
typedef  ^                       ^                 IntKi             HAWC_nz           -     -     -     "HAWC -- number of grids in z direction"                 -
typedef  ^                       ^                 ReKi              HAWC_dx           -     -     -     "HAWC -- distance between points in x direction"         meters
typedef  ^                       ^                 ReKi              HAWC_dy           -     -     -     "HAWC -- distance between points in y direction"         meters
typedef  ^                       ^                 ReKi              HAWC_dz           -     -     -     "HAWC -- distance between points in z direction"         meters
typedef  ^                       ^                 LOGICAL           SumPrint          -     -     -     "Write summary info to a file <ROOTNAME>.IfW.Sum"        -
typedef  ^                       ^                 IntKi             NumOuts           -     -     -     "Number of parameters in the output list (number of outputs requested)" -
typedef  ^                       ^                 CHARACTER(ChanLen) OutList          :     -     -     "List of user-requested output channels"                 -
typedef  ^                       ^                 IntKi             SensorType        -     -     -     "Sensor type (for lidar/sensor module)"                  -
typedef  ^                       ^                 IntKi             NumBeam           -     -     -     "Number of lidar beams"                                  -
typedef  ^                       ^                 IntKi             NumPulseGate      -     -     -     "The number of range gates to return wind speeds at"     -
typedef  ^                       ^                 ReKi              RotorApexOffsetPos {3}  -     -     "Position of the lidar unit relative to the rotor apex of rotation" m
typedef  ^                       ^                 ReKi              FocalDistanceX    :     -     -     "LIDAR LOS focal distance co-ordinates in the x direction" m
typedef  ^                       ^                 ReKi              FocalDistanceY    :     -     -     "LIDAR LOS focal distance co-ordinates in the y direction" m
typedef  ^                       ^                 ReKi              FocalDistanceZ    :     -     -     "LIDAR LOS focal distance co-ordinates in the z direction" m 
typedef  ^                       ^                 ReKi              PulseSpacing      -     -     -     "Distance between range gates" m
typedef  ^                       ^                 ReKi              MeasurementInterval -   -    -      "Time between each measurement" s
typedef  ^                       ^                 ReKi              URefLid           -     -     -     "Reference average wind speed for the lidar" m/s 
typedef  ^                       ^                 LOGICAL           LidRadialVel      -     -     -     "TRUE => return radial component, FALSE => return 'x' direction estimate" - 
typedef  ^                       ^                 IntKi             ConsiderHubMotion -     -     -     "whether or not the hub motion's impact on the Lidar measurement will be considered" -
typedef  ^                       ^                 Grid3D_InitInputType     FF     -     -     -     "scaling data" -



typedef  ^                       InitInputType     CHARACTER(1024)   InputFileName     -     -     -     "Name of the InflowWind input file to use"                                    -
typedef  ^                       ^                 LOGICAL           Linearize         -   .FALSE. -     "Flag that tells this module if the glue code wants to linearize." -
typedef  ^                       ^                 LOGICAL           Use4Dext          -   .FALSE. -     "Flag that tells this module if an external module will pass it 4-D velocity grids." -
typedef  ^                       ^                 IntKi             NumWindPoints     -     -     -     "Number of wind velocity points expected"                                     -
typedef  ^                       ^                 IntKi             TurbineID         -     0     -     "Wind turbine ID number in the fixed (DEFAULT) file name when FixedWindFileRootName = .TRUE. (used by FAST.Farm)"                                     -
typedef  ^                       ^                 LOGICAL           FixedWindFileRootName - .FALSE. -   "Do the wind data files have a fixed (DEFAULT) file name? (used by FAST.Farm)" -
typedef  ^                       ^                 CHARACTER(1024)   RootName          -     -     -     "RootName for writing output files"
typedef  ^                       ^                 IntKi             FilePassingMethod -     0     -     "Method for file passing {0: None (read from file), 1: as FileInfoType to parse, 2: as InputFileType already parsed}" -
typedef  ^                       ^                 FileInfoType      PassedFileInfo    -     -     -     "If we don't use the input file, pass everything through this [FilePassingMethod = 1]" -
typedef  ^                       ^                 InflowWind_InputFile PassedFileData -     -     -     "If we don't use the input file, pass everything through this [FilePassingMethod = 2]" -
typedef  ^                       ^                 LOGICAL           OutputAccel       -     .FALSE.     -      "Flag to output wind acceleration"                                    -
typedef  ^                       ^              Grid4D_InitInputType FDext             -     -     -     "InitInput for 4D external wind data"                                             -
typedef  ^                       ^                 ReKi              RadAvg            -     -     -     "Radius (from hub) used for averaging wind speed" -
typedef  ^                       ^                 IntKi             MHK               -     -     -     "MHK turbine type switch"   -
typedef  ^                       ^                 ReKi              WtrDpth           -     -     -     "Water depth" m
typedef  ^                       ^                 ReKi              MSL2SWL           -     -     -     "Mean sea level to still water level" m
typedef  ^                       ^                 LOGICAL           BoxExceedAllow    -  .FALSE.  -     "Flag to allow Extrapolation winds outside box starting at this index (for OLAF wakes and LidarSim)" -
typedef  ^                       ^                 LOGICAL           LidarEnabled      -  .false.  -     "Enable LiDAR for this instance of InflowWind? (FAST.Farm, ADI, and InflowWind driver/library are not compatible)" -
typedef  ^                       ^                 ReKi              HubPosition      {3}     -    -     "initial position of the hub (lidar mounted on hub) [0,0,HubHeight]" "m"


# Init Output
typedef  ^                       InitOutputType    CHARACTER(ChanLen)     WriteOutputHdr    :   -   -    "Names of output-to-file channels"                       -
typedef  ^                       ^                 CHARACTER(ChanLen)     WriteOutputUnt    :   -   -    "Units of output-to-file channels"                       -
typedef  ^                       ^                 ProgDesc               Ver               -   -   -    "Version information of InflowWind module"               -
typedef  ^                       ^                 WindFileDat            WindFileInfo      -   -   -    "Meta data from the wind file"                           -
typedef  ^                       ^                 CHARACTER(LinChanLen)  LinNames_y       {:}  -   -    "Names of the outputs used in linearization" -
typedef  ^                       ^                 CHARACTER(LinChanLen)  LinNames_u       {:}  -   -    "Names of the inputs used in linearization" -
typedef  ^                       ^                 LOGICAL                RotFrame_y       {:}  -   -    "Flag that tells FAST/MBC3 if the outputs used in linearization are in the rotating frame" -
typedef  ^                       ^                 LOGICAL                RotFrame_u       {:}  -   -    "Flag that tells FAST/MBC3 if the inputs used in linearization are in the rotating frame" -
typedef  ^                       ^                 LOGICAL                IsLoad_u         {:}  -   -    "Flag that tells FAST if the inputs used in linearization are loads (for preconditioning matrix)" -
typedef  ^                       ^                 FlowFieldType         *FlowField        -   -   -    "Flow field data to represent all wind types"  -


# ..... Parameters ................................................................................................................
# Define parameters here:
# Time step for integration of continuous states (if a fixed-step integrator is used) and update of discrete states:
typedef  ^                    ParameterType        CHARACTER(1024)   RootFileName      -     -     -     "Root of the InflowWind input   filename"                -
typedef  ^                       ^                 DbKi              DT                -     -     -     "Time step for cont. state integration & disc. state update"   seconds
typedef  ^                       ^                 ReKi              WindViXYZprime    ::    -     -     "List of XYZ coordinates for velocity measurements, translated to the wind coordinate system (prime coordinates).  This equals MATMUL( RotToWind, ParamData%WindViXYZ )"  meters
typedef  ^                       ^                 ReKi              WindViXYZ         ::    -     -     "List of XYZ coordinates for wind velocity measurements, 3xNWindVel" meters
typedef  ^                       ^                 FlowFieldType    &FlowField         -     -     -     "Flow field data to represent all wind types"  -
#FIXME: PositionAvg is used for DiskVel. However DiskVel does not appear to be used anymore, so this could be removed. ADP-2024.08.01
typedef  ^                       ^                 ReKi              PositionAvg       ::    -     -     "(non-rotated) positions of points used for averaging wind speed"  meters
typedef  ^                       ^                 IntKi             NWindVel          -     -     -     "Number of points in the wind velocity list"             -
typedef  ^                       ^                 IntKi             NumOuts           -     0     -     "Number of parameters in the output list (number of outputs requested)" -
typedef  ^                       ^                 OutParmType       OutParam          {:}   -     -     "Names and units (and other characteristics) of all requested output parameters" -
typedef  ^                       ^                 IntKi             OutParamLinIndx  {:}{:} -     -     "Index into WriteOutput for WindViXYZ in linearization analysis" -
typedef  ^                       ^               lidar_ParameterType lidar             -     -     -     "Lidar parameter data"                                       -
typedef  ^                       ^                 LOGICAL           OutputAccel      -     .FALSE.     -      "Flag to output wind acceleration"                                    -


# ..... Inputs ....................................................................................................................
# Define inputs that are not on this mesh here:
typedef  ^                    InputType            ReKi              PositionXYZ       ::    -     -     "Array holding the input positions at a given timestep"  meters
typedef  ^                       ^                 lidar_InputType   lidar             -     -     -     "Lidar data"                                       -
typedef  ^                       ^                 ReKi              HubPosition      {3}    -     -     "position of the hub (inertial frame)" m
typedef  ^                       ^                 ReKi              HubOrientation   {3}{3} -     -     "orientation of the hub (direction cosine matrix)" -


# ..... Outputs ...................................................................................................................
# Define outputs that are contained on the mesh here:
typedef  ^                    OutputType           ReKi              VelocityUVW       ::    -     -     "Array holding the U,V,W velocity for a given timestep"  meters/sec
typedef  ^                    OutputType           ReKi              AccelUVW          ::    -     -     "Array holding the U,V,W acceleration for a given timestep"  meters/sec
typedef  ^                    OutputType           ReKi              WriteOutput       :     -     -     "Array with values to output to file"                    -
#FIXME: is DiskVel still used? ADP-2024.08.01
typedef  ^                       ^                 ReKi              DiskVel           {3}   -     -     "Vector holding the U,V,W average velocity of the disk"  meters/sec
typedef  ^                       ^                 ReKi              HubVel            {3}   -     -     "Vector holding the U,V,W velocity at the hub"  meters/sec
typedef  ^                       ^              lidar_OutputType     lidar             -     -     -     "Lidar data"                                       -

# ..... States not used by this module ...................................................................................................................
typedef  ^                    ContinuousStateType  ReKi              DummyContState    -     -     -     "Remove this variable if you have continuous states"     -
typedef  ^                    DiscreteStateType    ReKi              DummyDiscState    -     -     -     "Remove this variable if you have discrete states"       -
typedef  ^                    ConstraintStateType  ReKi              DummyConstrState  -     -     -     "Remove this variable if you have constraint states"     -
typedef  ^                    OtherStateType       ReKi              DummyOtherState   -     -     -     "Remove this variable if you have other states"     -


# ..... Misc/Optimization variables.................................................................................................
# Define any data that are used only for efficiency purposes (these variables are not associated with time):
#   e.g. indices for searching in an array, large arrays that are local variables in any routine called multiple times, etc.
typedef  ^                       MiscVarType       ReKi              AllOuts           :     -     -     "An array holding the value of all of the calculated (not only selected) output channels" "see OutListParameters.xlsx spreadsheet"
typedef  ^                       ^                 ReKi              WindViUVW         ::    -     -     "List of UVW velocities for wind velocity measurements, 3xNWindVel. corresponds to ParamData%WindViXYZ"  meters/second
typedef  ^                       ^                 ReKi              WindAiUVW         ::    -     -     "List of UVW accelerations for wind acceleration measurements, 3xNWindVel. corresponds to ParamData%WindViXYZ"  m/s^2
typedef  ^                       ^                 InflowWind_InputType  u_Avg         -     -     -     "inputs for computing rotor-averaged values"  -
typedef  ^                       ^                 InflowWind_OutputType y_Avg         -     -     -     "outputs for computing rotor-averaged values"  -
typedef  ^                       ^                 InflowWind_InputType  u_Hub         -     -     -     "inputs for computing hub values"  -
typedef  ^                       ^                 InflowWind_OutputType y_Hub         -     -     -     "outputs for computing hub values"  -
