設計シートに使う構造体について

設計シートに使う構造体についての説明を行う

構造体とは

詳しくは次のようなサイトを参考にするといい

【VBA入門】構造体の使い方(宣言、初期化、引数、コピー、定数)

設計シート上での構造体

設計シートで用いる構造体は以下の2つである

'変数の構造体の宣言
Public Type variables
    
    '状態変数
    alpha As Double '全機迎角
    beta As Double '横滑り角
    Vair As Double '対気速度
    hE As Double '対地高度
    p As Double 'ロール角速度
    q As Double 'ピッチ角速度
    r As Double 'ヨー角速度
    dh As Double '重心移動量 [-]
    de As Double 'エレベータ舵角 [deg]
    dr As Double 'ラダー舵角 [deg]
    '環境変数
    rho As Double '空気密度 [kg/m^3]
    mu As Double '動粘性係数 [m^2/s]
        
End Type
'翼諸元の構造体の宣言
Public Type Specifications
    span_div As Integer 'スパン方向分割数
    chord_div As Integer
    '翼の幾何学形状
    dy As Double '翼素間隔 [m]
    hac As Double '空力中心位置 [-]
    hspar As Double 'スパー位置 [-]
    chord_mac As Double '平均空力翼弦長 [m]
    '翼の空力計算
    dynamic_pressure As Double '動圧 [N/m^2]
    S As Double '翼面積 [m^2]
    b As Double 'スパン [m]
    AR As Double 'アスペクト比 [-]
    y_ As Double '片翼面積中心 [m]
    e As Double '翼効率 [-]
    epsilon As Double '平均誘導迎角 [deg]
    aw As Double '三次元揚力傾斜 [1/deg]
    Cla As Double '二次元揚力傾斜 [-]
    de_da As Double '∂ε/∂α
    CL As Double '揚力係数 [-]
    Cdp As Double '有害抗力係数 [-]
    CDi As Double '誘導抗力係数 [-]
    CD As Double '抗力係数 [-]
    Cm_ac As Double '空力中心周りのピッチングモーメント係数 [-]
    Cm_cg As Double '桁位置周りのピッチングモーメント係数 [-]
    L_D As Double '揚抗比
    '機体形状
    lt As Double 'cgー水平ac間距離 [m]
    zf As Double '垂直尾翼下端位置 [m]
    lf As Double 'cg-垂直尾翼ac間距離 [m]
    VH As Double '水平尾翼容積比 [-]
    VF As Double '垂直尾翼容積比 [-]
    it As Double '水平尾翼取り付け角 [deg]
    '安定微係数
    Clb As Double
    Clp As Double
    Cnp As Double
    Clr As Double
    Cnr As Double
    Cyb As Double
    Lift As Double '揚力 [N]
    Drag_parasite As Double '有害抗力 [N]
    Drag_induced As Double '誘導抗力 [N]
    Drag As Double '抗力 [N]
    L_roll As Double 'ローリングモーメント [N*m]
    M_pitch As Double 'ピッチングモーメント [N*m]
    N_yaw As Double 'ヨーイングモーメント [N*m]
End Type

構造体の読み込み

構造体の読み込みには以下のFunctionを用いる

どちらも値を格納したい構造体とシート番号を引数とし,関数内部で場合分けを施し構造体に値を格納して返す関数である

Function ReadState(ByRef state As variables, ByVal n_sht As Integer) As variables
'状態変数の読み込み
'ワークシートの定義
Dim sht As Worksheet
Set sht0 = Sheets("各種パラメータ(sht0)")
Application.ScreenUpdating = False '画面更新の非表示
If n_sht = 1 Then
    Set sht = Sheets("主翼(sht1)")
ElseIf n_sht = 3 Then
    Set sht = Sheets("水平尾翼(sht3)")
ElseIf n_sht = 4 Then
    Set sht = Sheets("垂直尾翼(sht4)")
Else
    Set sht = Sheets("全機計算(sht8)")
End If
With sht
    state.alpha = .Range("BB20") '全機迎角 [deg]
    state.beta = .Range("BB21")
    state.Vair = .Range("BB22") '対気速度 [m/s]
    state.hE = .Range("BB23") '高度 [m]
    state.p = .Range("BB24") 'ロール角速度 [deg/s]
    state.q = .Range("BB25") 'ロール角速度 [deg/s]
    state.r = .Range("BB26") 'ロール角速度 [deg/s]
    state.dh = .Range("BB27") '頭下げのモーメントを生じるほうが正
    state.de = .Range("BB28") '頭下げのモーメントを生じるほうが正
    state.dr = .Range("BB29")
End With
state.rho = sht0.Range("N4") '空気密度 [kg/m^3]
state.mu = sht0.Range("N7") '動粘性係数 [m^2/s]
ReadState = state
End Function
Function Read_value(ByRef Wing As Specifications, ByRef state As variables, ByVal n_sht As Integer) As Specifications
'状態変数の読み込み
'ワークシートの定義
Dim sht As Worksheet
Set sht0 = Sheets("各種パラメータ(sht0)")
Set sht3 = Sheets("水平尾翼(sht3)")
Set sht8 = Sheets("全機計算(sht8)")
Application.ScreenUpdating = False '画面更新の非表示
If n_sht = 1 Then
    Set sht = Sheets("主翼(sht1)")
ElseIf n_sht = 3 Then
    Set sht = Sheets("水平尾翼(sht3)")
ElseIf n_sht = 4 Then
    Set sht = Sheets("垂直尾翼(sht4)")
Else
    Set sht = Sheets("全機計算(sht8)")
    Wing.b = sht.Range("S13")
    Wing.S = sht.Range("N30")
    Wing.chord_mac = sht.Range("S15") '主翼平均空力翼弦長 [m]
End If
Wing.dynamic_pressure = (1 / 2) * state.rho * state.Vair * state.Vair '動圧の計算 [N/m^2]
With sht
    Wing.span_div = sht.Range("D33") 'セミスパンの分割数.片翼のリブ枚数.
    Wing.chord_div = sht.Range("AR5") 'セミスパンの分割数.片翼のリブ枚数.
    Wing.dy = sht.Range("D30") 'スパーに沿ったリブ間隔 [m]
    ds = dy / 2 'パネルの半幅 [m]
    Wing.hac = sht.Range("D14") '空力中心位置 [-]
    Wing.hspar = sht.Range("D31") '桁位置 [-]
End With
With sht8
    Wing.lt = .Range("N4") 'cg-水平尾翼尾翼ac間距離 [m]
    Wing.de_da = .Range("N16")
    Wing.zf = .Range("N7") '垂直尾翼下端位置
    Wing.lf = .Range("N6") 'cg-垂直尾翼ac間距離 [m]
    Wing.VF = .Range("N15") '垂直尾翼容積比
    Wing.it = .Range("N9") '尾翼取り付け角 [deg]
    If .Range("N19") = "Conventional" Then
        Wing.epsilon = .Range("S20") * 2 '尾翼位置における吹きおろし角 [deg]
    Else
        Wing.epsilon = 0 '尾翼位置における吹きおろし角 [deg]
    End If
End With
Read_value = Wing '値を返す
End Function

以上

まとめ

構造体を使うと複数の値をまとめて取り扱えるので非常に便利である


記事一覧に戻る

【更新情報】20191219
  1. 構造体stateにエレベータ舵角deとラダー舵角drを追加
  2. ↑に伴いReadStateを変更
  3. ReadValueを若干変更
【ミス修正】20200911

同モジュール内で,Worksheetオブジェクトを宣言しておく

Publicで宣言しておけば,すべてのモジュール内でこれらの変数を使うことができる

'ワークシートの定義
Public sht As Worksheet
Public sht0 As Worksheet
Public sht1 As Worksheet
Public sht2 As Worksheet
Public sht3 As Worksheet
Public sht4 As Worksheet
Public sht5 As Worksheet
Public sht6 As Worksheet
Public sht7 As Worksheet
Public sht8 As Worksheet
Public sht9 As Worksheet
Public sht10 As Worksheet
Public sht11 As Worksheet
Public sht12 As Worksheet
Public sht13 As Worksheet
Public sht14 As Worksheet
Public sht15 As Worksheet
Public sht16 As Worksheet
Public sht18 As Worksheet
Public sht19 As Worksheet
Public sht20 As Worksheet

Sponsored Link

コメント

タイトルとURLをコピーしました