Option Explicit On Option Strict On Public Class Form4 Private KTE As Integer = 20000 Private KTJ As Integer = 20000 Private KED As Integer = 20000 Private KCM As Integer = 100 Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Call SQRELOCA() Me.Close() End Sub Private Sub SQRELOCA() Dim NODE As Integer Dim NELM As Integer Dim mtj(,) As Integer Dim px() As Double Dim py() As Double Dim ifix() As Integer ReDim mtj(KTE, 4) ReDim px(KTJ) ReDim py(KTJ) ReDim ifix(KTJ) Call SQINPUT(NELM, NODE, mtj, px, py, ifix) Call SQLAPLAS(NELM, NODE, mtj, px, py, ifix) Call SQDATA(NELM, NODE, mtj, px, py, ifix) End Sub Private Sub SQINPUT(ByRef NELM As Integer, ByRef NODE As Integer, ByRef mtj(,) As Integer, _ ByRef px() As Double, ByRef py() As Double, ByRef ifix() As Integer) Dim sr As System.IO.StreamReader Dim dat As String Dim sbuf() As String Dim delim() As Char = {","c} Dim fname1 As String Dim i As Integer Dim j As Integer fname1 = My.Forms.Form1.Label1.Text fname1 = System.IO.Path.GetDirectoryName(fname1) fname1 = fname1 & "\workf3.csv" sr = New System.IO.StreamReader(fname1, System.Text.Encoding.Default) dat = sr.ReadLine() : sbuf = dat.Split(delim) NODE = CInt(sbuf(0)) NELM = CInt(sbuf(1)) For i = 1 To NELM dat = sr.ReadLine() : sbuf = dat.Split(delim) For j = 1 To 4 mtj(i, j) = CInt(sbuf(j - 1)) Next j, i For i = 1 To NODE dat = sr.ReadLine() : sbuf = dat.Split(delim) px(i) = CDbl(sbuf(0)) py(i) = CDbl(sbuf(1)) ifix(i) = CInt(sbuf(2)) Next i sr.Close() End Sub Private Sub SQLAPLAS(ByRef NELM As Integer, ByRef NODE As Integer, ByRef mtj(,) As Integer, _ ByRef px() As Double, ByRef py() As Double, ByRef ifix() As Integer) Dim i As Integer Dim j As Integer Dim k As Integer Dim l As Integer Dim ja As Integer Dim jb As Integer Dim ip As Integer Dim ix As Integer Dim ka As Integer Dim kb As Integer Dim la As Integer Dim lb As Integer Dim itera As Integer Dim it As Integer Dim j1 As Integer Dim j2 As Integer Dim j3 As Integer Dim j4 As Integer Dim ielm As Integer Dim gx As Double Dim gy As Double Dim ar As Double Dim s As Double Dim xc As Double Dim yc As Double Dim cgrax As Double Dim cgray As Double Dim jac(,) As Integer Dim ihen(,) As Integer Dim jhen() As Integer Dim khen() As Integer Dim jnb() As Integer Dim nei(,) As Integer ReDim jac(KED, 4) ReDim ihen(KED, 2) ReDim jhen(KED) ReDim khen(KED) ReDim jnb(KED) ReDim nei(KED, KCM) For i = 1 To KTE For j = 1 To 4 jac(i, j) = 0 Next j, i ix = 0 For i = 1 To KED ihen(i, 1) = 0 ihen(i, 2) = 0 jhen(i) = 0 khen(i) = 0 Next i For i = 1 To KTJ jnb(i) = 0 For j = 1 To KCM nei(i, j) = 0 Next j, i For j = 1 To NELM For k = 1 To 4 ka = mtj(j, k) kb = mtj(j, (k Mod 4) + 1) For l = 1 To ix la = ihen(l, 1) lb = ihen(l, 2) If (ka = lb) And (kb = la) Then GoTo sqlaplas70 Next l ix = ix + 1 ihen(ix, 1) = ka ihen(ix, 2) = kb jhen(ix) = j khen(ix) = k GoTo sqlaplas50 sqlaplas70: jac(j, k) = jhen(l) jac(jhen(l), khen(l)) = j sqlaplas50: Next k, j For i = 1 To NELM For j = 1 To 4 If jac(i, j) = 0 Then ja = mtj(i, j) jb = mtj(i, (j Mod 4) + 1) ifix(ja) = 1 ifix(jb) = 1 End If Next j, i For i = 1 To NELM For j = 1 To 4 ip = mtj(i, j) jnb(ip) = jnb(ip) + 1 nei(ip, jnb(ip)) = i Next j, i itera = 5 For it = 1 To itera For i = 1 To NODE If ifix(i) = 0 Then gx = 0.0 gy = 0.0 ar = 0.0 For j = 1 To jnb(i) ielm = nei(i, j) j1 = mtj(ielm, 1) j2 = mtj(ielm, 2) j3 = mtj(ielm, 3) j4 = mtj(ielm, 4) s = SQAREA(ielm, mtj, px, py) xc = (px(j1) + px(j2) + px(j3) + px(j4)) / 4.0 yc = (py(j1) + py(j2) + py(j3) + py(j4)) / 4.0 ar = ar + s gx = gx + s * xc gy = gy + s * yc Next j cgrax = gx / ar cgray = gy / ar px(i) = cgrax py(i) = cgray End If Next i Next it End Sub Private Function SQAREA(ByRef ielm As Integer, ByRef mtj(,) As Integer, ByRef px() As Double, ByRef py() As Double) As Double Dim j1 As Integer Dim j2 As Integer Dim j3 As Integer Dim j4 As Integer Dim area1 As Double Dim area2 As Double j1 = mtj(ielm, 1) j2 = mtj(ielm, 2) j3 = mtj(ielm, 3) j4 = mtj(ielm, 4) area1 = 0.5 * (px(j1) * py(j2) + px(j2) * py(j3) + px(j3) * py(j1) - px(j1) * py(j3) - px(j2) * py(j1) - px(j3) * py(j2)) area2 = 0.5 * (px(j1) * py(j3) + px(j3) * py(j4) + px(j4) * py(j1) - px(j1) * py(j4) - px(j3) * py(j1) - px(j4) * py(j3)) SQAREA = area1 + area2 End Function Private Sub SQDATA(ByRef NELM As Integer, ByRef NODE As Integer, ByRef mtj(,) As Integer, _ ByRef px() As Double, ByRef py() As Double, ByRef ifix() As Integer) Dim sw As System.IO.StreamWriter Dim dat As String Dim fname2 As String Dim i As Integer fname2 = My.Forms.Form1.Label2.Text sw = New System.IO.StreamWriter(fname2, False, System.Text.Encoding.Default) dat = NODE.ToString & "," & NELM.ToString : sw.WriteLine(dat) For i = 1 To NELM dat = mtj(i, 1).ToString & "," & mtj(i, 2).ToString & "," & mtj(i, 3).ToString & "," & mtj(i, 4).ToString sw.WriteLine(dat) Next i For i = 1 To NODE dat = px(i).ToString("0.000") & "," & py(i).ToString("0.000") sw.WriteLine(dat) Next i sw.Close() End Sub End Class