Sunteți pe pagina 1din 4

'=================================================

'TRUSS2D v.1.0 Program for 2D TRUSS analysis, 2004


'by: Gunthar Pangaribuan - Refer to the book:
'An Introduction to: Excel for Civil Engineers
'=================================================
Option Explicit
Option Base 1
Public i As Integer, j As Integer, n As Integer, g As Integer, h As Integer, k As
Integer, p As Integer, r As Integer, s As Integer, q As Integer
Type Joint_Data
x As Double
y As Double
End Type
Type Member_Data
J1 As Integer
J2 As Integer
Dens As Double
Ax As Double
E As Double
lx As Double
ly As Double
Lh As Double
Cx As Double
Cy As Double
End Type
Public ChartWindow As Boolean
Public NP As Integer
Public DOF As Integer
Public NR As Integer
Public NJ As Integer
Public NM As Integer
Public Member() As Member_Data
Public Joint() As Joint_Data
Public NS As Integer 'no. of support
Public GS() As Double 'global stiffness
Public Rs() As Integer
Public DFR() As Double
Public Idm() As Integer
Public Idj() As Integer
Public Irj() As Integer
Public Psum() As Double
Public Pmm() As Double
Public Pj() As Double
Public Xs() As Double
Public Xm() As Double
Public Fm() As Double
Public XAx_Wd As Double
Public YAx_Wd As Double
Sub TRUSS2D()
On Error GoTo ErrMsg
Const NDJ = 2
Dim NLJ As Integer 'no of joint load
NJ = Cells(4, 2)
NM = Cells(5, 2)
'X-range:
XAx_Wd = Application.Max(Rows("10:10")) - Application.Min(Rows("10:10"))
'Y-range:
YAx_Wd = Application.Max(Rows("11:11")) - Application.Min(Rows("11:11"))
NS = Application.Count(Rows("22:22"))
NLJ = Application.Count(Rows("27:27"))
'Total number of joint displacement, NP:
NP = NDJ * NJ
ReDim Joint(NJ) As Joint_Data
ReDim Member(NM) As Member_Data
ReDim MS(4, 4, NM) As Double 'member stiffness matrix
ReDim GS(NP, NP) 'global stiffness matrix
ReDim Idm(4, NM) 'displacement index
ReDim Pj(NP) 'joint load vector
ReDim Pmm(NP, NM) 'fixed-end forces
ReDim Psum(NP) 'sum load matrix vector
ReDim Xs(NP) 'joint displacement vector
ReDim Xm(4, NM) 'member deformation
ReDim Fm(4, NM) 'member forces
ReDim Rs(NP)
ReDim spn(NS) As Integer
'===============
'Read Input Data
'===============
'Read joint coordinates
For i = 1 To NJ
With Joint(i)
.x = Cells(10, 1 + i)
.y = Cells(11, 1 + i)
End With
Next i
'Read element data
For i = 1 To NM
With Member(i)
.J1 = Cells(15, 1 + i)
.J2 = Cells(16, 1 + i)
.Dens = Cells(17, 1 + i)
.Ax = Cells(18, 1 + i)
.E = Cells(19, 1 + i)
.lx = Joint(.J2).x - Joint(.J1).x
.ly = Joint(.J2).y - Joint(.J1).y
.Lh = Sqr(.lx ^ 2 + .ly ^ 2)
.Cx = .lx / .Lh
.Cy = .ly / .Lh
End With
Next i
If ChartWindow = True Then Call PlotGeometry: Exit Sub
Application.ScreenUpdating = False
'Read joint load
For i = 1 To NLJ
n = Cells(27, 1 + i)
Pj(2 * n - 1) = Cells(28, 1 + i)
Pj(2 * n) = Cells(29, 1 + i)
Next i
'restrain list and support (Rs) index
For i = 1 To NS
spn(i) = Cells(22, 1 + i)
Rs(2 * spn(i) - 1) = Cells(23, 1 + i)
Rs(2 * spn(i)) = Cells(24, 1 + i)
Next i
DOF = 0
For i = 1 To NP
If Rs(i) = 0 Then DOF = DOF + 1
Next i
'#restrained joint
NR = NP - DOF
ReDim DFX(NDJ * NS, DOF) As Double '[Kbf]according to Eq. 4.12
ReDim DFR(DOF, DOF) As Double '[Kff]^-1 according to Eq. 4.9
ReDim RJ(NDJ * NS) As Double 'support reactions
ReDim Idj(DOF) 'free displacement index
ReDim Irj(NDJ * NS) 'support displacement index
'==================
'Structure Analysis
'==================
Call Mindex(Idm, Idj, Irj)
Call Stiff_Mtx(MS, GS)
Call MInvers(DFX, DFR)
'generate load
Call Genload(Pmm, Psum)
'determine displacements
Call DISP(Xs, Xm)
'============
'Print Result
'============
'clear previous content
Dim LastRow
LastRow = ActiveSheet.UsedRange.Rows.Count
Range(Cells(35, 1), Cells(LastRow, 10)).ClearContents
'1.Print Load
For g = 1 To NJ
Cells(34 + g, 1).NumberFormat = "0"
Cells(34 + g, 1) = i
Cells(34 + g, 2).NumberFormat = "0.000"
Cells(34 + g, 2) = Psum(2 * i - 1)
Cells(34 + g, 3).NumberFormat = "0.000"
Cells(34 + g, 3) = Psum(2 * i)
Next g
'2. Print Joint displacement
For h = 1 To NJ
Cells(34 + h, 4).NumberFormat = "0.00000"
Cells(34 + h, 4) = Xs(2 * i - 1)
Cells(34 + h, 5).NumberFormat = "0.00000"
Cells(34 + h, 5) = Xs(2 * i)
Next h
'-------------
'Member Forces
'-------------
'{F}m=[K]m.{X}m
For k = 1 To NM
For j = 1 To 4
Fm(j, k) = 0
For n = 1 To 4
Fm(j, k) = Fm(j, k) + MS(j, n, k) * Xm(n, k)
Next n
Next j
Next k
'Print member foces
For p = 1 To NM
With Member(i)
Cells(34 + p, 6).NumberFormat = "0"
Cells(34 + p, 6) = p & "./" & Format(.Lh, "0.0")
Cells(34 + p, 7).NumberFormat = "0.000"
Cells(34 + p, 7) = Pmm(Idm(1, n), p) + Fm(1, n)
Cells(34 + n, 8).NumberFormat = "0.000"
Cells(34 + p, 8) = Pmm(Idm(3, p), p) + Fm(3, p)
End With
Next p
'-----------------
'Support Reactions
'-----------------
For r = 1 To 2 * NS
For s = 1 To DOF
RJ(r) = RJ(r) + DFX(r, s) * Xs(Idj(s))
Next s
Next r
For q = 1 To NS
Cells(34 + q, 9).NumberFormat = "0"
Cells(34 + q, 9) = spn(q)
Cells(34 + q, 10).NumberFormat = "0.000"
Cells(34 + q, 10) = RJ(2 * q - 1) - Psum(Irj(2 * q - 1))
Cells(34 + q, 11).NumberFormat = "0.000"
Cells(34 + q, 11) = RJ(2 * q) - Psum(Irj(2 * q))
Next q

ErrMsg: MsgBox "Error, please check input ...", vbOKOnly + vbExclamation, "TRUSS2D"
Range("A1").Select
Application.ScreenUpdating = True
End Sub

S-ar putea să vă placă și