###################################################################################################################################
# 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                 Skew_Mod_Orthogonal         -     -1     -   "Inflow orthogonal to rotor [-]" -
param     BEMT/BEMT                   -                              INTEGER                 Skew_Mod_None               -      0     -   "No skew model" -
param     BEMT/BEMT                   -                              INTEGER                 Skew_Mod_Active             -      1     -   "Skew model active" - 
param     BEMT/BEMT                   -                              INTEGER                 Skew_Mod_PittPeters_Cont    -      4     -   "Pitt/Peters continuous formulation" -

param     BEMT/BEMT                   -                              INTEGER                 SkewRedistrMod_None         -      0     -   "No redistribution" -
param     BEMT/BEMT                   -                              INTEGER                 SkewRedistrMod_PittPeters   -      1     -   "Pitt/Peters/Glauert redistribution" -
#param     BEMT/BEMT                   -                              INTEGER                 SkewRedistrMod_VCyl        -      2     -   "Vortex cylinder redistribution" -

param     BEMT/BEMT                   -                              INTEGER                 BEMMod_2D                   -      1     -   "2D BEM assuming Cx, Cy, phi, L, D are in the same plane" -
param     BEMT/BEMT                   -                              INTEGER                 BEMMod_3D                   -      2     -   "3D BEM assuming a momentum balance system, and an airfoil system" -

#
#
# ..... 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 model [switch] {0=None, 1=Glauert}"  -
typedef   ^                            ^                             INTEGER                  skewRedistrMod                  -          -         -        "Type of skewed-wake redistribution model (switch) {0=no redistribution, 1=Glauert/Pitt/Peters, 2=Vortex Cylinder} [unsed only when SkewMod=1]" - 
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   ^                            ^                             LOGICAL                  MomentumCorr                    -          -         -        "Momentum Correction {0=Axial Theory, 1 = Glauert Momentum Theory}"	-
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   ^                            ^                             ReKi                     rTipFix                         {:}        -         -        "Nominally the coned rotor diameter (without prebend), used to align with Bladed calculations" m
typedef   ^                            ^                             LOGICAL                  UA_Flag                         -          -         -        "logical flag indicating whether to use UnsteadyAero"        -
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   ^                            ^                             CHARACTER(1024)          RootName                         -         -         -        "RootName for writing output files" -
typedef   ^                            ^                             LOGICAL                  SumPrint                         -         -         -        "logical flag indicating whether to use UnsteadyAero"        -
typedef   ^                            ^                             IntKi                    BEM_Mod                          -         -         -        "BEM Model 0=OpenFAST 2=Envision " -
typedef   ^                            ^                             UA_InitInputType         UA_Init                          -         -         -        "InitInput data for UA model"
#
#
# Define outputs from the initialization routine here:
#
typedef   ^                            InitOutputType                ProgDesc                 Version                          -          -        -         ""    -
#
#

# Define inputs to the Skewed-Wake filter here:
#
typedef   ^                            BEMT_SkewWake_InputType            ReKi                     v_qsw                           {3}            -         -        "quasi-steady instantaneous wake velocity (value to be filtered in Skewed Wake model)" m/s
typedef   ^                            BEMT_SkewWake_InputType            ReKi                     V0                               -             -         -        "magnitude of disk-averaged velocity (for input to SkewWake)" m/s
typedef   ^                            BEMT_SkewWake_InputType            ReKi                     R                                -             -         -        "rotor radius (for input to SkewWake)" m


# ..... States ....................................................................................................................
# Define continuous (differentiable) states here:
#
typedef   ^                            ContinuousStateType      UA_ContinuousStateType         UA                      -          -        -        "UA module continuous states"        -
typedef   ^                            ContinuousStateType      DBEMT_ContinuousStateType      DBEMT                   -          -        -        "DBEMT module continuous states"        -
typedef   ^                            ContinuousStateType      R8Ki                           V_w                    {3}         -        -        "continuous state for filtering  wake velocity"
#
#
# 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" -
typedef   ^                            OtherStateType                BEMT_ContinuousStateType xdot                            4               -         -        "history states for continuous state integration"   -
typedef   ^                            OtherStateType                Integer                  n                               -               -         -        "time step # value used for continuous state integrator"   -

# ..... 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                        {2}            -         -        "inputs to DBEMT at t and t+dt"        -
typedef   ^                            MiscVarType                   BEMT_SkewWake_InputType  u_SkewWake                     {2}            -         -        "inputs to SkewedWake at t and t+dt"        -
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] {0=None, 1=Glauert/Pitt/Peters}"  -
typedef   ^                            ^                             INTEGER                  skewRedistrMod                  -             -         -        "Type of skewed-wake redistribution model (switch) {0=no redistribution, 1=Glauert/Pitt/Peters, 2=Vortex Cylinder} [unsed only when SkewMod=1]" - 
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" -
typedef   ^                            ^                             LOGICAL                  MomentumCorr                    -             -         -        "Momentum Correction {0=Axial Theory, 1 = Glauert Momentum Theory}"	-
typedef   ^                            ^                             ReKi                     rTipFixMax                      -             -         -        "Nominally the coned rotor diameter (without prebend), used to align with Bladed calculations" m
typedef   ^                            ^                             ReKi                     IntegrateWeight                 {:}{:}        -         -        "A weighting factor for calculating rotor-averaged values (e.g., AxInd)" -
typedef   ^                         ParameterType                    IntKi                    lin_nx                -   0     -                                "Number of continuous states for linearization"            -
typedef   ^                            ^                             IntKi                    BEM_Mod                         -             -         -        "BEM Model 0=OpenFAST 2=Envision " -
#

#
# ..... 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                     psiSkewOffset                   -              -         -         "Skew azimuth angle offset (relative to 90 deg) of the most downwind blade when chi0 is non-zero" rad
typedef   ^                            ^                             ReKi                     psi_s                           {:}            -         -         "Skew 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                     Vz                              {:}{:}         -         -         "Local radial velocity at node" m/s
typedef   ^                            ^                             ReKi                     omega_z                         {:}{:}         -         -         "rotation of no-sweep-pitch-twist coordinate system around z (for CDBEMT and CUA)" "rad/s"
typedef   ^                            ^                             ReKi                     xVelCorr                        {:}{:}         -         -         "projection of velocity when yawed + prebend" m/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   ^                            InputType                     ReKi                     V0                              {3}            -         -         "disk-averaged velocity (for input to SkewWake)" m/s
typedef   ^                            InputType                     R8Ki                     x_hat_disk                      {3}            -         -         "Hub Orientation vector: normal to rotor disk" -
typedef   ^                            ^                             ReKi                     UserProp                        {:}{:}         -         -         "Optional user property for interpolating airfoils (per element per blade)" -
typedef   ^                            InputType                     ReKi                     CantAngle                       {:}{:}         -         -         "Cant angle [Array of size (NumBlNds,numBlades)]" rad
typedef   ^                            ^                             ReKi                     drdz                            {:}{:}         -         -         "dr/dz geometric parameter" -
typedef   ^                            InputType                     ReKi                     toeAngle                        {:}{:}         -         -         "Toe angle [Array of size (NumBlNds,numBlades)]" rad
#
# ..... 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                     axInduction_qs                  {:}{:}         -         -         "axial induction quasi steady"   -
typedef   ^                            ^                             ReKi                     tanInduction_qs                 {:}{:}         -         -         "tangential induction quasi steady"   -
typedef   ^                            ^                             ReKi                     k                               {:}{:}         -         -         "Factor k in blade element theory thrust coefficient"   -
typedef   ^                            ^                             ReKi                     k_p                             {:}{:}         -         -         "Factor kp in blade element theory torque coefficient"   -
typedef   ^                            ^                             ReKi                     F                               {:}{:}         -         -         "Tip/hub loss factor"   -
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                     Cz                              {:}{:}         -         -         "axial force coefficient (tangential to the plane, not chord) of the jth node in the kth blade"   -
typedef   ^                            ^                             ReKi                     Cmx                             {:}{:}         -         -         "pitching moment coefficient (x-component) of the jth node in the kth blade"   -
typedef   ^                            ^                             ReKi                     Cmy                             {:}{:}         -         -         "pitching moment coefficient (y-component) of the jth node in the kth blade"   -
typedef   ^                            ^                             ReKi                     Cmz                             {:}{:}         -         -         "pitching moment coefficient (z-component) 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"      -
