プログラムリスト
VBAのプログラムリストは以下のようになります。
'Jn=節点数'En=要素数'Fn=外力の加わる節点数'Fixn=固定端の節点数
'X(I)=節点のX座標'Y(I)=節点のY座標'PI(K)、PJ(K)=部材番号Kの節点番号
'E(K)=部材番号Kのヤング率'A(K)=部材番号Kの断面積'L(K)=部材番号Kの長さ
'PART(I,J)=部材の剛性行列'MAT(I,J)=全体の剛性行列
'F(2*I-1)=節点IのX軸荷重'F(2*I)=節点IのY軸荷重'U(I)=変位
Dim X(101), Y(101), U(201), F(201), MAT(201, 201)
Dim PI(101), PJ(101), E(101), A(101), L(101), WORK(5), PART(5, 5)
Sub Main()
'結果欄クリア
For i = 1 To 100
Sheets("Sheet1").Cells(10 + i, 5).Formula = ""
Sheets("Sheet1").Cells(10 + i, 6).Formula = ""
Sheets("Sheet1").Cells(10 + i, 15).Formula = ""
Sheets("Sheet1").Cells(10 + i, 16).Formula = ""
Next i
'基本条件入力
Jn = Sheets("Sheet1").Cells(4, 3).Value
EN = Sheets("Sheet1").Cells(5, 3).Value
Fn = Sheets("Sheet1").Cells(6, 3).Value
Fixn = Sheets("Sheet1").Cells(7, 3).Value
NMAX = Jn * 2
'配列初期化
For i = 1 To NMAX
U(i) = 0
For j = 1 To NMAX
MAT(i, j) = 0
Next j
Next i
'節点座標入力
For i = 1 To Jn
X(i) = Sheets("Sheet1").Cells(10 + i, 2).Value
Y(i) = Sheets("Sheet1").Cells(10 + i, 3).Value
Next i
For k = 1 To EN
'部材条件入力
PI(k) = Sheets("Sheet1").Cells(10 + k, 11).Value
PJ(k) = Sheets("Sheet1").Cells(10 + k, 12).Value
E(k) = Sheets("Sheet1").Cells(10 + k, 13).Value
A(k) = Sheets("Sheet1").Cells(10 + k, 14).Value
'cos、sin等定数計算
i = PI(k)
j = PJ(k)
XX = X(j) - X(i)
YY = Y(j) - Y(i)
L(k) = Sqr(XX * XX + YY * YY)
CT = E(k) * A(k) / L(k)
CC = XX / L(k)
SS = YY / L(k)
'部材kのマトリックス計算
WORK(1) = CC
WORK(2) = SS
WORK(3) = -CC
WORK(4) = -SS
For II = 1 To 4
For JJ = 1 To 4
PART(II, JJ) = CT * WORK(II) * WORK(JJ)
Next JJ
Next II
'全体マトリックス計算
WORK(1) = 2 * i - 1
WORK(2) = 2 * i
WORK(3) = 2 * j - 1
WORK(4) = 2 * j
For II = 1 To 4
For JJ = 1 To 4
I2 = WORK(II)
J2 = WORK(JJ)
MAT(I2, J2) = MAT(I2, J2) + PART(II, JJ)
Next JJ
Next II
Next k
'荷重条件入力
For k = 1 To Fn
i = Sheets("Sheet1").Cells(10 + k, 7).Value
F(2 * i - 1) = Sheets("Sheet1").Cells(10 + k, 8).Value
F(2 * i) = Sheets("Sheet1").Cells(10 + k, 9).Value
Next k
'変位計算(連立1次方程式の解計算)
INIT = 2 * Fixn + 1
For k = INIT To NMAX - 1
P = MAT(k, k)
For j = k + 1 To NMAX
MAT(k, j) = MAT(k, j) / P
Next j
F(k) = F(k) / P
For i = k + 1 To NMAX
Q = MAT(i, k)
For j = k + 1 To NMAX
MAT(i, j) = MAT(i, j) - Q * MAT(k, j)
Next j
F(i) = F(i) - Q * F(k)
Next i
Next k
U(NMAX) = F(NMAX) / MAT(NMAX, NMAX)
For k = NMAX - 1 To INIT Step -1
S = F(k)
For j = k + 1 To NMAX
S = S - MAT(k, j) * U(j)
Next j
U(k) = S
Next k
'結果出力
For i = 1 To Jn
Sheets("Sheet1").Cells(10 + i, 5).Value = U(2 * i - 1)
Sheets("Sheet1").Cells(10 + i, 6).Value = U(2 * i)
Next i
'応力と軸力の計算
For k = 1 To EN
i = PI(k)
j = PJ(k)
XX = X(j) - X(i)
YY = Y(j) - Y(i)
LU = U(2 * j - 1) - U(2 * i - 1)
lV = U(2 * j) - U(2 * i)
LL = (XX * LU + YY * lV) / L(k)
EPS = LL / L(k)
SIG = EPS * E(k)
FOC = SIG * A(k)
'結果出力
Sheets("Sheet1").Cells(10 + k, 15).Value = SIG
Sheets("Sheet1").Cells(10 + k, 16).Value = FOC
Next k
End Sub