###################################################################################################################################
# Registry for BEMT in the FAST Modularization Framework
# This Registry file is used to create MODULE BEMT  which contains all of the user-defined types needed in BEMT.
# It also contains copy, destroy, pack,  and unpack routines associated with each defined data types.
# See NWTC Programmer's Handbook for further information on the format/contents of this file.
#
# Entries are of the form
# <keyword>         <ModuleName/ModName>          <TypeName>          <FieldType>         <FieldName>         <Dims>    <IO>      <DNAME>   <DESCRIP> <UNITS>
#
# Use ^ as a shortcut for the value in the same column from the previous line.
###################################################################################################################################

# ...... Include files (definitions from NWTC Library) ............................................................................
include   Registry_NWTC_Library.txt
usefrom   AirfoilInfo_Registry.txt
usefrom   UnsteadyAero_Registry.txt
usefrom   DBEMT_Registry.txt

#param     BEMT/BEMT                   -                              INTEGER                 SkewMod_Uncoupled           -      1     -   "Uncoupled (no correction)" -
#param     BEMT/BEMT                   -                              INTEGER                 SkewMod_PittPeters          -      2     -   "Pitt/Peters" -
#param     BEMT/BEMT                   -                              INTEGER                 SkewMod_Coupled             -      3     -   "Coupled" -


#
#
# ..... Initialization data .......................................................................................................
# Define inputs that the initialization routine may need here:
#   e.g.,  the name of the input file,  the file root name,etc.
#
typedef   BEMT/BEMT                    InitInputType                 ReKi                     chord                           {:}{:}     -         -        "Chord length at node" m
typedef   ^                            ^                             INTEGER                  numBlades                       -          -         -        "Number of blades"    -
typedef   ^                            ^                             ReKi                     airDens                         -          -         -        "Air density"        kg/m^3
typedef   ^                            ^                             ReKi                     kinVisc                         -          -         -        "Kinematic air viscosity"       m^2/s
typedef   ^                            ^                             INTEGER                  skewWakeMod                     -          -         -        "Type of skewed-wake correction model [switch] {1=uncoupled, 2=Pitt/Peters, 3=coupled}"  -
typedef   ^                            ^                             ReKi                     aTol                            -          -         -        "Tolerance for the induction solution" -
typedef   ^                            ^                             LOGICAL                  useTipLoss                      -          -         -        "Use the Prandtl tip-loss model?  [flag]"        -
typedef   ^                            ^                             LOGICAL                  useHubLoss                      -          -         -        "Use the Prandtl hub-loss model?  [flag]"        -
typedef   ^                            ^                             LOGICAL                  useInduction                    -          -         -        "Include induction in BEMT calculations [flag] { If FALSE then useTanInd will be set to FALSE}"        -
typedef   ^                            ^                             LOGICAL                  useTanInd                       -          -         -        "Include tangential induction in BEMT calculations [flag]"        -
typedef   ^                            ^                             LOGICAL                  useAIDrag                       -          -         -        "Include the drag term in the axial-induction calculation?  [flag]"        -
typedef   ^                            ^                             LOGICAL                  useTIDrag                       -          -         -        "Include the drag term in the tangential-induction calculation?  Ignored if TanInd is False.  [flag]"        -
typedef   ^                            ^                             INTEGER                  numBladeNodes                   -          -         -        "Number of blade nodes used in the analysis"        -
typedef   ^                            ^                             INTEGER                  numReIterations                 -          -         -        "Number of iterations for finding the Reynolds number"        -
typedef   ^                            ^                             INTEGER                  maxIndIterations                -          -         -        "Maximum number of iterations of induction factor solve"        -
typedef   ^                            ^                             INTEGER                  AFindx                          {:}{:}     -         -        "Index of airfoil data file for blade node location [array of numBladeNodes]"        -
typedef   ^                            ^                             ReKi                     zHub                            {:}        -         -        "Distance to hub for each blade" m
typedef   ^                            ^                             ReKi                     zLocal                          {:}{:}     -         -        "Distance to blade node, measured along the blade" m
typedef   ^                            ^                             ReKi                     zTip                            {:}        -         -        "Distance to blade tip, measured along the blade" m
typedef   ^                            ^                             ReKi                     rLocal                          {:}{:}     -         -        "Radial distance to blade node from the center of rotation, measured in the rotor plane, needed for DBEMT" m
typedef   ^                            ^                             INTEGER                  UAMod                           -          -         -        "Model for the dynamic stall equations [1 = Leishman/Beddoes, 2 = Gonzalez, 3 = Minnema]"    -
typedef   ^                            ^                             LOGICAL                  UA_Flag                         -          -         -        "logical flag indicating whether to use UnsteadyAero"        -
typedef   ^                            ^                             LOGICAL                  Flookup                         -          -         -        "Use table lookup for f' and f'' "    -
typedef   ^                            ^                             ReKi                     a_s                             -          -         -        "speed of sound"        m/s
typedef   ^                            ^                             IntKi                    DBEMT_Mod                       -          -         -        "DBEMT model.  1 = constant tau1, 2 = time dependent tau1" -
typedef   ^                            ^                             ReKi                     tau1_const                      -          -         -        "DBEMT time constant (when DBEMT_Mod=1)"        s
typedef   ^                            ^                             ReKi                     yawCorrFactor                   -          -         -        "constant used in Pitt/Peters skewed wake model (default is 15*pi/32)" -
typedef   ^                            ^                             INTEGER                  UAOff_innerNode                 {:}        -         -        "Last node on each blade where UA should be turned off based on span location from blade root (0 if always on)"    -
typedef   ^                            ^                             INTEGER                  UAOff_outerNode                 {:}        -         -        "First node on each blade where UA should be turned off based on span location from blade tip (>nNodesPerBlade if always on)"    -
typedef   ^                            ^                             CHARACTER(1024)          RootName                         -         -         -        "RootName for writing output files" -
typedef   ^                            ^                             LOGICAL                  SumPrint                         -         -         -        "logical flag indicating whether to use UnsteadyAero"        -
#
#
# Define outputs from the initialization routine here:
#
typedef   ^                            InitOutputType                ProgDesc                 Version                          -          -        -         ""    -
#
#
# ..... States ....................................................................................................................
# Define continuous (differentiable) states here:
#
typedef   ^                            ContinuousStateType      UA_ContinuousStateType         UA                      -          -        -        "UA module continuous states"        -
typedef   ^                            ContinuousStateType      DBEMT_ContinuousStateType      DBEMT                   -          -        -        "DBEMT module continuous states"        -
#
#
# Define discrete (non-differentiable) states here:
#
typedef   ^                            DiscreteStateType             UA_DiscreteStateType     UA                        -             -         -        "states for UnsteadyAero"        -
#
#
# Define constraint states here:
#
typedef   ^                            ConstraintStateType           ReKi                     phi                             {:}{:}         -         -         "angle between the plane of rotation and the direction of the local wind" rad
#
#
# Define any other states, including integer or logical states here:
#
typedef   ^                            OtherStateType                UA_OtherStateType        UA                                  -           -         -        "other states for UnsteadyAero"        -
typedef   ^                            OtherStateType                DBEMT_OtherStateType     DBEMT                             -             -         -        "other states for DBEMT"        -
typedef   ^                            ^                             LOGICAL                  ValidPhi                        {:}{:}          -         -        "set to indicate when there is no valid Phi for this node at this time (temporarially turn off induction when this is false)" -
typedef   ^                            OtherStateType                Logical                  nodesInitialized                -               -         -        "the node states have been initialized properly" -

# ..... 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                   Logical                  FirstWarn_Skew                  -             -         -        "flag so invalid skew warning doesn't get repeated forever" -
typedef   ^                            MiscVarType                   Logical                  FirstWarn_Phi                   -             -         -        "flag so Invalid Phi warning doesn't get repeated forever" -
typedef   ^                            MiscVarType                   Logical                  FirstWarn_BEMoff                -             -         -        "flag to warn the BEM was turned off" -
typedef   ^                            MiscVarType                   UA_MiscVarType           UA                              -             -         -        "misc vars for UnsteadyAero"        -
typedef   ^                            MiscVarType                   DBEMT_MiscVarType        DBEMT                           -             -         -        "misc vars for DBEMT"        -
typedef   ^                            MiscVarType                   UA_OutputType            y_UA                            -             -         -        "outputs from UnsteadyAero"        -
typedef   ^                            MiscVarType                   UA_InputType             u_UA                           {:}{:}{:}      -         -        "inputs to UnsteadyAero at t and t+dt"        -
typedef   ^                            MiscVarType                   DBEMT_InputType          u_DBEMT                        {:}            -         -        "inputs to DBEMT"        -
typedef   ^                            MiscVarType                   ReKi                     TnInd_op                       {:}{:}         -         -        "tangential induction at the operating point (for linearization with frozen wake assumption)"
typedef   ^                            MiscVarType                   ReKi                     AxInd_op                       {:}{:}         -         -        "axial induction at the operating point (for linearization) with frozen wake assumption"
typedef   ^                            MiscVarType                   ReKi                     AxInduction                    {:}{:}         -         -        "axial induction used for code run-time optimization" -
typedef   ^                            MiscVarType                   ReKi                     TanInduction                   {:}{:}         -         -        "tangential induction used for code run-time optimization" -
typedef   ^                            MiscVarType                   Logical                  UseFrozenWake                   -             -         -        "flag set to determine if frozen values of TnInd_op and AxInd_op should be used for this calculation in the linearization process"   
typedef   ^                            MiscVarType                   ReKi                     Rtip                           {:}            -         -        "maximum rlocal value for each blade (typically the value at the tip)" m
typedef   ^                            MiscVarType                   ReKi                     phi                            {:}{:}         -         -        "temp variable used in update states for returning phi (to allow computing inputs and states at multiple times)" -
typedef   ^                            MiscVarType                   ReKi                     chi                            {:}{:}         -         -        "temp variable used in update states for returning chi (to allow calling same routine from CalcOutput and UpdateStates)" -
typedef   ^                            MiscVarType                   Logical                  ValidPhi                       {:}{:}         -         -        "temp variable used in calcOutput for ValidPhi (to allow calling same routine from CalcOutput and UpdateStates)" -
typedef   ^                            MiscVarType                   ReKi                     BEM_weight                                    -         -        "temp variable used to turn off BEM for low TSR and/or large skew angles" -

# ..... 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                 DbKi                     DT                              -             -         -        "time step" s
typedef   ^                            ^                             ReKi                     chord                           {:}{:}        -         -        "Chord length at node" m
typedef   ^                            ^                             INTEGER                  numBlades                       -             -         -        "Number of blades"    -
typedef   ^                            ^                             ReKi                     airDens                         -             -         -        "Air density"        kg/m^3
typedef   ^                            ^                             ReKi                     kinVisc                         -             -         -        "Kinematic air viscosity"       m^2/s
typedef   ^                            ^                             INTEGER                  skewWakeMod                     -             -         -        "Type of skewed-wake correction model [switch] {1=uncoupled, 2=Pitt/Peters, 3=coupled}"  -
typedef   ^                            ^                             ReKi                     aTol                            -             -         -        "Tolerance for the induction solution" -
typedef   ^                            ^                             LOGICAL                  useTipLoss                      -             -         -        "Use the Prandtl tip-loss model?  [flag]"        -
typedef   ^                            ^                             LOGICAL                  useHubLoss                      -             -         -        "Use the Prandtl hub-loss model?  [flag]"        -
typedef   ^                            ^                             LOGICAL                  useInduction                    -             -         -        "Include induction in BEMT calculations [flag] { If FALSE then useTanInd will be set to FALSE}"        -
typedef   ^                            ^                             LOGICAL                  useTanInd                       -             -         -        "Include tangential induction in BEMT calculations [flag]"        -
typedef   ^                            ^                             LOGICAL                  useAIDrag                       -             -         -        "Include the drag term in the axial-induction calculation?  [flag]"        -
typedef   ^                            ^                             LOGICAL                  useTIDrag                       -             -         -        "Include the drag term in the tangential-induction calculation?  Ignored if TanInd is False.  [flag]"        -
typedef   ^                            ^                             INTEGER                  numBladeNodes                   -             -         -        "Number of blade nodes used in the analysis"        -
typedef   ^                            ^                             INTEGER                  numReIterations                 -             -         -        "Number of iterations for finding the Reynolds number"        -
typedef   ^                            ^                             INTEGER                  maxIndIterations                -             -         -        "Maximum number of iterations of induction factor solve"        -
typedef   ^                            ^                             INTEGER                  AFindx                          {:}{:}        -         -        "Index of airfoil data file for blade node location [array of numBladeNodes]"        -
typedef   ^                            ^                             ReKi                     tipLossConst                    {:}{:}        -         -        "A constant computed during initialization based on B*(zTip-zLocal)/(2*zLocal)" -
typedef   ^                            ^                             ReKi                     hubLossConst                    {:}{:}        -         -        "A constant computed during initialization based on B*(zLocal-zHub)/(2*zHub)" -
typedef   ^                            ^                             ReKi                     zHub                            {:}           -         -        "Distance to hub for each blade" m
typedef   ^                            ^                             UA_ParameterType         UA                              -             -         -        "parameters for UnsteadyAero"        -
typedef   ^                            ^                             DBEMT_ParameterType      DBEMT                           -             -         -        "parameters for DBEMT"        -
typedef   ^                            ^                             LOGICAL                  UA_Flag                         -             -         -        "logical flag indicating whether to use UnsteadyAero"        -
typedef   ^                            ^                             IntKi                    DBEMT_Mod                       -             -         -        "DBEMT Model.  0 = constant tau1, 1 = time dependent tau1" -
typedef   ^                            ^                             ReKi                     yawCorrFactor                   -             -         -        "constant used in Pitt/Peters skewed wake model (default is 15*pi/32)" -
typedef   ^                            ^                             LOGICAL                  FixedInductions                 {:}{:}        -         -        "flag to determine if BEM inductions should be fixed and not modified by dbemt or skewed wake" -
#

#
# ..... Inputs ....................................................................................................................
# Define inputs that are contained on the mesh here:
#
typedef   ^                            InputType                     ReKi                     theta                           {:}{:}         -         -         "Twist angle (includes all sources of twist)  [Array of size (NumBlNds,numBlades)]" rad
typedef   ^                            ^                             ReKi                     chi0                            -              -         -         "Angle between the vector normal to the rotor plane and the wind vector (e.g., the yaw angle in the case of no tilt)" rad
typedef   ^                            ^                             ReKi                     psi                             {:}            -         -         "Azimuth angle" rad
typedef   ^                            ^                             ReKi                     omega                           -              -         -         "Angular velocity of rotor" rad/s
typedef   ^                            ^                             ReKi                     TSR                             -              -         -         "Tip-speed ratio (to check if BEM should be turned off)" -
typedef   ^                            ^                             ReKi                     Vx                              {:}{:}         -         -         "Local axial velocity at node" m/s
typedef   ^                            ^                             ReKi                     Vy                              {:}{:}         -         -         "Local tangential velocity at node" m/s
typedef   ^                            ^                             ReKi                     Vx_elast_dot                    {:}{:}         -         -         "Local relative axial acceleration at node (for CDBEMT)" "m/s^2"
typedef   ^                            ^                             ReKi                     Vy_elast_dot                    {:}{:}         -         -         "Local relative tangential acceleration at node (for CDBEMT)" "m/s^2"
typedef   ^                            ^                             ReKi                     omega_z                         {:}{:}         -         -         "rotation of no-sweep-pitch-twist coordinate system around z (for CDBEMT and CUA)" "rad/s"
typedef   ^                            ^                             ReKi                     rLocal                          {:}{:}         -         -         "Radial distance from center-of-rotation to node" m
typedef   ^                            InputType                     ReKi                     Un_disk                         -              -         -         "disk-averaged velocity normal to the rotor disk (for input to DBEMT)" m/s
typedef   ^                            ^                             ReKi                     UserProp                        {:}{:}         -         -         "Optional user property for interpolating airfoils (per element per blade)" -
#
# ..... Outputs ...................................................................................................................
# Define outputs that are contained on the mesh here:
typedef   ^                            OutputType                    ReKi                     Vrel                            {:}{:}         -         -         "Total local relative velocity" m/s
typedef   ^                            ^                             ReKi                     phi                             {:}{:}         -         -         "angle between the plane of rotation and the direction of the local wind" rad
typedef   ^                            ^                             ReKi                     axInduction                     {:}{:}         -         -         "axial induction"   -
typedef   ^                            ^                             ReKi                     tanInduction                    {:}{:}         -         -         "tangential induction"   -
typedef   ^                            ^                             ReKi                     Re                              {:}{:}         -         -         "Reynold's number"   -
typedef   ^                            ^                             ReKi                     AOA                             {:}{:}         -         -         "angle of attack"   rad
typedef   ^                            ^                             ReKi                     Cx                              {:}{:}         -         -         "normal force coefficient (normal to the plane, not chord) of the jth node in the kth blade"   -
typedef   ^                            ^                             ReKi                     Cy                              {:}{:}         -         -         "tangential force coefficient (tangential to the plane, not chord) of the jth node in the kth blade"   -
typedef   ^                            ^                             ReKi                     Cm                              {:}{:}         -         -         "pitching moment coefficient of the jth node in the kth blade"   -
typedef   ^                            ^                             ReKi                     Cl                              {:}{:}         -         -         "lift coefficient"   -
typedef   ^                            ^                             ReKi                     Cd                              {:}{:}         -         -         "drag coefficient"   -
typedef   ^                            ^                             ReKi                     chi                             {:}{:}         -         -         "wake skew angle"   rad
typedef   ^                            ^                             ReKi                     Cpmin                           {:}{:}         -         -         "min Cpressure"      -
