Bonjour,

Avant tout, desolé si c'est pas le forum correct pour cette question.

J'essai de "Traudire" un logiciel excel vers vb.net.

Le problemme est que la syntaxe n'est pas exactement la meme, et en plus l'option Base 1 de vba n'est pas disponible sur vb.net.

J'ai essaie de la "repliquer" avec changemments comme:

Dim nf as long (1 to ndof, 1 to nn)

Remplace par:

Dim nf As array = Array.CreateInstance(GetType(Long), {ndof,nn}, {1,1})

Mais le code n'arrive a marcher bien.

Est ce que quelqu'un pourrait m'orienter?

Vous pouvez trouver un exemple du logiciel d'origin:

https://newtonexcelbach.com/2009/09/...oads-on-piles/






Les 2 codes sont ci desus:
Code vba : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
Option Explicit
 
Option Base 1
Function BoEFA(beamA As Variant, LoadA As Variant, Optional FixedNodes As Variant, Optional NIP As Long = 2) As Variant
    Dim Numnodes As Long, resa() As Double
 
    If TypeName(beamA) = "Range" Then beamA = beamA.Value2
    If TypeName(LoadA) = "Range" Then LoadA = LoadA.Value2
    If TypeName(FixedNodes) = "Range" Then FixedNodes = FixedNodes.Value2
 
    Numnodes = UBound(beamA)
    If IsMissing(FixedNodes) = True Then FixedNodes = 0
 
    ReDim resa(1 To Numnodes, 1 To 4)
    Call BoEF(beamA, LoadA, FixedNodes, NIP, resa)
 
    BoEFA = resa
 
End Function
 
' Programs in this module are based on Fortran programs taken from "Prgramming The Finite Element Method"
' by IM Smith ans D.V. Griffiths, published by John Wiley & Sons
 
 
Sub BoEF(beamA As Variant, LoadA As Variant, FixedNodeA As Variant, NIP As Long, resa() As Double)
 
    Dim nels As Long, neq As Long, nn As Long, nband As Long, nr As Long
    Dim iel As Long, i As Long, j As Long, k As Long, l As Long
    Dim loaded_nodes As Long, fixed_nodes As Long, FixedCols As Long, Sense As Long, Value As Double, Node As Long
    Dim fs As Double, fs0 As Double, fs1 As Double, x As Double, samp_pt As Double, EI0 As Double, EI1 As Double, EI As Double
 
    Dim km() As Double, mm() As Double, eld() As Double, kv() As Double, Loads() As Double, coord() As Double
    Dim action As Variant, g_coord() As Double, ftf() As Double, dtd() As Double
    Dim der2() As Double, fun() As Double, mom() As Double, store_km() As Double, points() As Double
    Dim weights() As Double, ell() As Double
    Dim nf() As Long, g() As Long, num() As Long, g_num() As Long, no() As Long, g_g() As Long
    Dim etype() As Long, n As Long
 
    Const nod As Long = 2, nodof As Long = 2, ndof As Long = 4, ndim As Long = 1
    Const element As String = "line"
 
    If TypeName(beamA) = "Range" Then beamA = beamA.Value2
    If TypeName(FixedNodeA) = "Range" Then FixedNodeA = FixedNodeA.Value2
    If TypeName(LoadA) = "Range" Then LoadA = LoadA.Value2
 
    loaded_nodes = UBound(LoadA)
    nels = UBound(beamA) - 1
    If NIP < 2 Then NIP = 2
    If NIP > 6 Then NIP = 6
 
    nn = nels + 1
 
 
    ReDim nf(nodof, nn)
    ReDim km(ndof, ndof)
    ReDim coord(nod, ndim)
    ReDim g_coord(ndim, nn)
    ReDim eld(ndof)
    ReDim g_num(nod, nels)
    ReDim num(nod)
    ReDim g(ndof)
    ReDim g_g(ndof, nels)
    ReDim mm(ndof, ndof)
    ReDim ftf(ndof, ndof)
    ReDim ell(nels)
    ReDim dtd(ndof, ndof)
    ReDim store_km(ndof, ndof, nels)
    ReDim der2(ndof)
    ReDim fun(ndof)
    ReDim mom(nn)
    ReDim points(NIP, ndim)
    ReDim weights(NIP)
    ReDim etype(nels)
 
    fs0 = beamA(1, 3)
    fs1 = beamA(2, 3)
    EI = beamA(1, 2)
 
    For i = 1 To nels
        ell(i) = beamA(i + 1, 1) - beamA(i, 1)
        etype(i) = 1
    Next i
    nr = 0
 
    For i = 1 To nodof
        For j = 1 To nn
            nf(i, j) = 1
        Next j
    Next i
 
    If nr > 0 Then
        'read(10,*)(k,nf(:,k),i=1,nr)
    End If
    Call formnf(nf)
    neq = WorksheetFunction.max(nf)
 
    '!--------------loop the elements to find global array sizes--------------------
    nband = 0
 
    For iel = 1 To nels
        Call geometry_2l(iel, ell(iel), coord, num)
        Call num_to_g(num, nf, g, ndof)
 
        For i = 1 To nod
            g_num(i, iel) = num(i)
        Next i
 
        For j = 1 To nod
            g_coord(1, num(j)) = coord(j, 1)
        Next j
 
        For i = 1 To ndof
            g_g(i, iel) = g(i)
        Next i
 
 
        If nband < bandwidth(g) Then nband = bandwidth(g)
    Next iel
 
    ReDim kv(neq * (nband + 1))
    ReDim Loads(0 To neq)
 
    Call sample(element, points, weights)
 
    x = 0#
 
    For iel = 1 To nels
        ReDim km(ndof, ndof)
        ReDim mm(ndof, ndof)
        For i = 1 To ndof
            g(i) = g_g(i, iel)
        Next i
 
        fs0 = beamA(iel, 3)
        fs1 = beamA(iel + 1, 3)
        EI0 = beamA(iel, 2)
        EI1 = beamA(iel + 1, 2)
        For i = 1 To NIP
            samp_pt = ell(iel) * 0.5 * (points(i, 1) + 1#)
            fs = samp_pt / (ell(iel)) * (fs1 - fs0) + fs0
            EI = samp_pt / (ell(iel)) * (EI1 - EI0) + EI0
            Call fmbeam(der2, fun, points, i, ell(iel))
            For k = 1 To ndof
                For l = 1 To ndof
                    ftf(k, l) = fun(k) * fun(l) * weights(i) * 0.5 * ell(iel) * fs
                    dtd(k, l) = der2(k) * der2(l) * weights(i) * 8# * EI / (ell(iel) ^ 3)
                    mm(k, l) = mm(k, l) + ftf(k, l)
                    km(k, l) = km(k, l) + dtd(k, l)
 
                Next l
            Next k
        Next i
 
        For i = 1 To ndof
            For j = 1 To ndof
                km(i, j) = km(i, j) + mm(i, j)
                store_km(i, j, iel) = km(i, j)
            Next j
        Next i
 
        x = beamA(iel, 1)
        Call formkv(kv, km, g, neq, iel)
    Next iel
 
    '!-----------------------------read loads---------------------------------------
 
    If loaded_nodes <> 0 Then
 
        For i = 1 To loaded_nodes
            k = LoadA(i, 1)
            For j = 1 To nodof
                Loads(nf(j, k)) = LoadA(i, j + 1)
            Next j
        Next i
    End If
 
    'read (10,*)fixed_nodes
    If IsArray(FixedNodeA) = True Then
    fixed_nodes = UBound(FixedNodeA)
    FixedCols = UBound(FixedNodeA, 2)
    Else
    fixed_nodes = 0
    End If
 
    If fixed_nodes <> 0 Then
          For i = 1 To fixed_nodes
          Node = FixedNodeA(i, 1)
          Sense = 0
          If FixedNodeA(i, 2) = 1 Then Sense = 1
          If FixedNodeA(i, 3) = 1 Then Sense = Sense + 2
          If Sense = 1 Or Sense = 3 Then
          If FixedCols > 3 Then Value = FixedNodeA(i, 4) Else Value = 0
          n = nf(1, Node)
          kv(n) = kv(n) + 1E+20
          Loads(n) = kv(n) * Value
          Sense = Sense - 1
          End If
          If Sense = 2 Then
           If FixedCols > 4 Then Value = FixedNodeA(i, 5) Else Value = 0
          n = nf(2, Node)
          kv(n) = kv(n) + 1E+20
          Loads(n) = kv(n) * Value
          End If
          Next i
 
    End If
 
    '!-----------------------------equation solution -------------------------------
    Call banred(kv, neq)
    Call bacsub(kv, Loads)
 
    '!-----------------------retrieve element end actions---------------------------
    For iel = 1 To nels
        For i = 1 To ndof
            For j = 1 To ndof
                km(i, j) = store_km(i, j, iel)
            Next j
            g(i) = g_g(i, iel)
            eld(i) = Loads(g(i))
        Next i
 
 
        action = MATMUL(km, eld)
        resa(iel, 3) = -action(2)
        resa(iel, 4) = action(1)
 
    Next iel
    resa(iel, 3) = -action(4)
    resa(iel, 4) = -action(3)
    For i = 1 To nn
        resa(i, 1) = beamA(i, 1)
        resa(i, 2) = Loads(2 * i - 1)
    Next i
 
End Sub
 
 
Sub formnf(nf)
 
'  ! reform nf
    Dim i As Long, j As Long, M As Long
    M = 0
    For j = 1 To UBound(nf, 2)
        For i = 1 To UBound(nf, 1)
            If (nf(i, j) <> 0) Then
                M = M + 1
                nf(i, j) = M
            End If
        Next i
    Next j
 
End Sub
 
 
'!----------------Node to freedom number conversion ----------------------------
Sub num_to_g(num, nf, g, ndof)
 
' !finds the g vector from num and nf
    Dim i As Long, j As Long, k As Long, nod As Long, nodof As Long
 
    nod = UBound(num, 1)
    nodof = UBound(nf, 1)
    For i = 1 To nod
        k = i * nodof
        For j = 1 To nodof
            g(k - nodof + j) = nf(j, num(i))
        Next j
    Next i
 
End Sub
 
 
' !-------------------------------- Lines  --------------------------------------
 
Sub geometry_2l(iel, ell, coord, num)
 
' ! node numbers, nodal coordinates and steering vectors for
' ! a line of (nonuniform) beam elements
    num(1) = iel
    num(2) = iel + 1
    If (iel = 1) Then
        coord(1, 1) = 0#
        coord(2, 1) = ell
    Else
        coord(1, 1) = coord(2, 1)
        coord(2, 1) = coord(2, 1) + ell
    End If
End Sub
 
Sub rod_km(km, ea, Length)
 
    Dim Stiff As Double
    Stiff = ea / Length
    km(1, 1) = Stiff
    km(2, 2) = Stiff
    km(1, 2) = -Stiff
    km(2, 1) = -Stiff
 
End Sub
 
Sub formkv(bk, km, g, n, iel)
 
' !global stiffness matrix stored as a vector (upper triangle)
    Dim idof As Long, i As Long, j As Long, icd As Long, ival As Long
    idof = UBound(km, 1) - LBound(km, 1) + 1
 
    For i = 1 To idof
        If (g(i) <> 0) Then
            For j = 1 To idof
                If (g(j) <> 0) Then
                    icd = g(j) - g(i) + 1
                    If (icd - 1 >= 0) Then
                        ival = n * (icd - 1) + g(i)
                        bk(ival) = bk(ival) + km(i, j)
                    End If
                End If
            Next j
 
        End If
 
    Next i
 
 
    ' Return
End Sub
 
 
Sub banred(bk, n)
 
' ! gaussian reduction on a vector stored as an upper triangle
    Dim i As Long, il1 As Long, kbl As Long, j As Long, ij As Long, nkb As Long, M As Long, ni As Long, nj As Long, iw As Long
    Dim sum As Double
 
    iw = UBound(bk, 1) / n - 1
    For i = 2 To n
        il1 = i - 1
        kbl = il1 + iw + 1
        If (kbl - n > 0) Then kbl = n
        For j = i To kbl
            ij = (j - i) * n + i
            sum = bk(ij)
            nkb = j - iw
            If (nkb <= 0) Then nkb = 1
            If (nkb - il1 <= 0) Then
                For M = nkb To il1
                    ni = (i - M) * n + M
                    nj = (j - M) * n + M
                    sum = sum - bk(ni) * bk(nj) / bk(M)
                Next M
            End If
            bk(ij) = sum
        Next j
    Next i
 
End Sub
 
Sub bacsub(bk, Loads)
 
 
' ! performs the complete gaussian backsubstitution
    Dim nkb As Long, k As Long, i As Long, jn As Long, jj As Long, i1 As Long, n As Long, iw As Long
    Dim sum As Double
    n = UBound(Loads, 1)
    iw = UBound(bk, 1) / n - 1
    Loads(1) = Loads(1) / bk(1)
    For i = 2 To n
        sum = Loads(i)
        i1 = i - 1
        nkb = i - iw
        If (nkb <= 0) Then nkb = 1
        For k = nkb To i1
            jn = (i - k) * n + k
            sum = sum - bk(jn) * Loads(k)
        Next k
        Loads(i) = sum / bk(i)
    Next i
    For jj = 2 To n
        i = n - jj + 1
        sum = 0#
        i1 = i + 1
        nkb = i + iw
        If (nkb - n > 0) Then nkb = n
        For k = i1 To nkb
            jn = (k - i) * n + i
            sum = sum + bk(jn) * Loads(k)
        Next k
        Loads(i) = Loads(i) - sum / bk(i)
    Next jj
    ' Return
End Sub
 
 
Function MATMUL(A, b)
'
'      PRODUCT OF TWO MATRICES
'
    Dim i As Long, j As Long, k As Long, Mat, x As Double, l As Long, n As Long
    l = UBound(A, 2)
    n = UBound(A)
    ReDim Mat(l) As Double
    For i = 1 To l
        For j = 1 To n
            x = 0#
            For k = 1 To l
                x = x + A(i, k) * b(k)
            Next k
            Mat(i) = x
        Next j
    Next i
    MATMUL = Mat
End Function
 
 
'
Sub MATRAN(A, IA, b, IB, M, n)
'
'      FORMS THE TRANSPOSE OF A MATRIX
'
'     REAL A(IA,*),B(IB,*)
'     DO 1 I = 1,M
'         DO 1 J = 1,N
'     A(j, i) = B(i, j)
 
End Sub
 
Sub MSMULT(A, IA, c, M, n)
'
'      MULTIPLIES A MATRIX BY A SCALAR
'
'      REAL A(IA,*)
'      DO 1 I = 1,M
'          DO 1 J = 1,N
'     A(i, j) = A(i, j) * c
End Sub
 
Sub MVMULT(M, v, k, l, y)
 
'      MULTIPLIES A MATRIX BY A VECTOR
 
 
    Dim i As Long, j As Long, x As Double
    ' ReDim Preserve M(k, l), V(l), Y(k)
    ReDim y(k)
    For i = 1 To k
        x = 0#
        For j = 1 To l
            x = x + M(i, j) * v(j)
        Next j
        y(i) = x
    Next i
End Sub
 
Function bandwidth(g)
 
 
'! finds the element bandwidth from g
    If WorksheetFunction.min(g) > 0 Then
        bandwidth = WorksheetFunction.max(g) - WorksheetFunction.min(g)
    Else
        bandwidth = 0
    End If
End Function
 
 
Sub sample(element, s, wt)
 
' ! returns the local coordinates of the integrating points
 
' ****  Edited for line element only  *****
 
    Dim NIP As Long, root3 As Double, R15 As Double, w(1 To 3) As Double, v(1 To 9) As Double, b As Double, c As Double, i As Long
 
    root3 = 1# / (3#) ^ 0.5
    R15 = 0.2 * (15#) ^ 0.5
    NIP = UBound(s, 1)
    w(1) = 5# / 9#
    w(2) = 8# / 9#
    w(3) = 5# / 9#
    For i = 1 To 7 Step 3
        v(i) = 5# / 9# * w(1)
        v(i + 1) = 8# / 9# * w(2)
        v(i + 2) = 5# / 9# * w(3)
    Next i
    Select Case element
    Case "line"
 
        Select Case (NIP)
        Case (1)
            s(1, 1) = 0#
            wt(1) = 2#
        Case (2)
            s(1, 1) = root3
            s(2, 1) = -s(1, 1)
            wt(1) = 1#
            wt(2) = 1#
        Case (3)
            s(1, 1) = R15
            s(2, 1) = 0#
            s(3, 1) = -s(1, 1)
            wt = w
        Case (4)
            s(1, 1) = 0.861136311594053
            s(2, 1) = 0.339981043584856
            s(3, 1) = -s(2, 1)
            s(4, 1) = -s(1, 1)
 
            wt(1) = 0.347854845137454
            wt(2) = 0.652145154862546
            wt(3) = wt(2)
            wt(4) = wt(1)
        Case (5)
            s(1, 1) = 0.906179845938664
            s(2, 1) = 0.538469310105683
            s(3, 1) = 0#
            s(4, 1) = -s(2, 1)
            s(5, 1) = -s(1, 1)
            wt(1) = 0.236926885056189
            wt(2) = 0.478628670499366
            wt(3) = 0.568888888888889
            wt(4) = wt(2)
            wt(5) = wt(1)
        Case (6)
            s(1, 1) = 0.932469514203152
            s(2, 1) = 0.661209386466265
            s(3, 1) = 0.238619186083197
            s(4, 1) = -s(3, 1)
            s(5, 1) = -s(2, 1)
            s(6, 1) = -s(1, 1)
            wt(1) = 0.17132449237917
            wt(2) = 0.360761573048139
            wt(3) = 0.467913934572691
            wt(4) = wt(3)
            wt(5) = wt(2)
            wt(6) = wt(1)
        Case Default
            '      print*,"wrong number of integrating points for a line"
        End Select
    End Select
 
End Sub
 
 
Sub fmbeam(der2, fun, points, i, ell)
 
 
' !
' ! this subroutine forms the beam shape functions
' ! and their 2nd derivatives in local coordinates
' !
 
    Dim xi As Double, xi2 As Double, xi3
 
    xi = points(i, 1)
    xi2 = xi * xi
    xi3 = xi2 * xi
 
    fun(1) = 0.25 * (xi3 - 3# * xi + 2#)
    fun(2) = 0.125 * ell * (xi3 - xi2 - xi + 1#)
    fun(3) = 0.25 * (-xi3 + 3# * xi + 2#)
    fun(4) = 0.125 * ell * (xi3 + xi2 - xi - 1#)
    der2(1) = 1.5 * xi
    der2(2) = 0.25 * ell * (3# * xi - 1#)
    der2(3) = -1.5 * xi
    der2(4) = 0.25 * ell * (3# * xi + 1#)
 
 
End Sub






Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
    ' Programs in this module are based on Fortran programs taken from "Prgramming The Finite Element Method"
    ' by IM Smith ans D.V. Griffiths, published by John Wiley & Sons
 
 
    Sub BoEF(beamA As Array, LoadA As Array, FixedNodeA As Object, NIP As Long, ByRef resa(,) As Double)
 
        Dim nels As Long, neq As Long, nn As Long, nband As Long, nr As Long
        Dim iel As Long, i As Long, j As Long, k As Long, l As Long
        Dim loaded_nodes As Long, fixed_nodes As Long, FixedCols As Long, Sense As Long, Value As Double, Node As Long
        Dim fs As Double, fs0 As Double, fs1 As Double, x As Double, samp_pt As Double, EI0 As Double, EI1 As Double, EI As Double
 
        Dim Loads() As Double
        Dim action As Object
        Dim no() As Long
        Dim n As Long
 
        Const nod As Long = 2, nodof As Long = 2, ndof As Long = 4, ndim As Long = 1
        Const element As String = "line"
 
 
        loaded_nodes = UBound(LoadA)
        nels = UBound(beamA) - 1
        If NIP < 2 Then NIP = 2
        If NIP > 6 Then NIP = 6
 
        nn = nels + 1
 
        Dim nf As Array = Array.CreateInstance(GetType(Long), {nodof, nn}, {1, 1})
        Dim km As Array = Array.CreateInstance(GetType(Double), {ndof, ndof}, {1, 1})
        Dim coord As Array = Array.CreateInstance(GetType(Double), {nod, ndim}, {1, 1})
        Dim g_coord As Array = Array.CreateInstance(GetType(Double), {ndim, nn}, {1, 1})
        Dim eld As Array = Array.CreateInstance(GetType(Double), {ndof}, {1})
        Dim g_num As Array = Array.CreateInstance(GetType(Long), {nod, nels}, {1, 1})
        Dim num As Array = Array.CreateInstance(GetType(Long), {nod}, {1})
        Dim g As Array = Array.CreateInstance(GetType(Long), {ndof}, {1})
        Dim g_g As Array = Array.CreateInstance(GetType(Long), {ndof, nels}, {1, 1})
        Dim mm As Array = Array.CreateInstance(GetType(Double), {ndof, ndof}, {1, 1})
        Dim ftf As Array = Array.CreateInstance(GetType(Double), {ndof, ndof}, {1, 1})
        Dim ell As Array = Array.CreateInstance(GetType(Double), {nels}, {1})
        Dim dtd As Array = Array.CreateInstance(GetType(Double), {ndof, ndof}, {1, 1})
        Dim store_km As Array = Array.CreateInstance(GetType(Double), {ndof, ndof, nels}, {1, 1, 1})
        Dim der2 As Array = Array.CreateInstance(GetType(Double), {ndof}, {1})
        Dim fun As Array = Array.CreateInstance(GetType(Double), {ndof}, {1})
        Dim mom As Array = Array.CreateInstance(GetType(Double), {nn}, {1})
        Dim points As Array = Array.CreateInstance(GetType(Double), {NIP, ndim}, {1, 1})
        Dim weights As Array = Array.CreateInstance(GetType(Double), {NIP}, {1})
        Dim etype As Array = Array.CreateInstance(GetType(Long), {nels}, {1})
 
 
 
        fs0 = beamA(1, 3)
        fs1 = beamA(2, 3)
        EI = beamA(1, 2)
 
        For i = 1 To nels
            ell(i) = beamA(i + 1, 1) - beamA(i, 1)
            etype(i) = 1
        Next i
        nr = 0
 
        For i = 1 To nodof
            For j = 1 To nn
                nf(i, j) = 1
            Next j
        Next i
 
        If nr > 0 Then
            'read(10,*)(k,nf(:,k),i=1,nr)
        End If
        Call formnf(nf)
        neq = WorksheetMax(nf)
 
        '!--------------loop the elements to find global array sizes--------------------
        nband = 0
 
        For iel = 1 To nels
            Call geometry_2l(iel, ell(iel), coord, num)
            Call num_to_g(num, nf, g, ndof)
 
            For i = 1 To nod
                g_num(i, iel) = num(i)
            Next i
 
            For j = 1 To nod
                g_coord(1, num(j)) = coord(j, 1)
            Next j
 
            For i = 1 To ndof
                g_g(i, iel) = g(i)
            Next i
 
 
            If nband < bandwidth(g) Then nband = bandwidth(g)
        Next iel
 
        Dim kv As Array = Array.CreateInstance(GetType(Double), {neq * (nband + 1)}, {1})
        Loads = Array.CreateInstance(GetType(Double), {neq + 1}, {0})
 
        Call sample(element, points, weights)
 
        x = 0#
 
        For iel = 1 To nels
            km = Array.CreateInstance(GetType(Double), {ndof, ndof}, {1, 1})
            mm = Array.CreateInstance(GetType(Double), {ndof, ndof}, {1, 1})
 
            For i = 1 To ndof
                    g(i) = g_g(i, iel)
                Next i
 
                fs0 = beamA(iel, 3)
                fs1 = beamA(iel + 1, 3)
                EI0 = beamA(iel, 2)
                EI1 = beamA(iel + 1, 2)
                For i = 1 To NIP
                    samp_pt = ell(iel) * 0.5 * (points(i, 1) + 1.0#)
                    fs = samp_pt / (ell(iel)) * (fs1 - fs0) + fs0
                    EI = samp_pt / (ell(iel)) * (EI1 - EI0) + EI0
                    Call fmbeam(der2, fun, points, i, ell(iel))
                    For k = 1 To ndof
                        For l = 1 To ndof
                            ftf(k, l) = fun(k) * fun(l) * weights(i) * 0.5 * ell(iel) * fs
                            dtd(k, l) = der2(k) * der2(l) * weights(i) * 8.0# * EI / (ell(iel) ^ 3)
                            mm(k, l) = mm(k, l) + ftf(k, l)
                            km(k, l) = km(k, l) + dtd(k, l)
 
                        Next l
                    Next k
                Next i
 
                For i = 1 To ndof
                    For j = 1 To ndof
                        km(i, j) = km(i, j) + mm(i, j)
                        store_km(i, j, iel) = km(i, j)
                    Next j
                Next i
 
                x = beamA(iel, 1)
            Call formkv(kv, km, g, neq, iel)
 
        Next iel
 
        '!-----------------------------read loads---------------------------------------
 
        If loaded_nodes <> 0 Then
            '
            For i = 1 To loaded_nodes
                k = LoadA(i, 1)
                For j = 1 To nodof
                    Loads(nf(j, k)) = LoadA(i, j + 1)
                Next j
            Next i
        End If
 
        'read (10,*)fixed_nodes
        If IsArray(FixedNodeA) = True Then
            fixed_nodes = UBound(FixedNodeA)
            FixedCols = UBound(FixedNodeA, 2)
        Else
            fixed_nodes = 0
        End If
        If fixed_nodes <> 0 Then
            For i = 1 To fixed_nodes
                Node = FixedNodeA(i, 1)
                Sense = 0
                If FixedNodeA(i, 2) = 1 Then Sense = 1
                If FixedNodeA(i, 3) = 1 Then Sense = Sense + 2
                If Sense = 1 Or Sense = 3 Then
                    If FixedCols > 3 Then Value = FixedNodeA(i, 4) Else Value = 0
                    n = nf(1, Node)
                    kv(n) = kv(n) + 1.0E+20
                    Loads(n) = kv(n) * Value
                    Sense = Sense - 1
                End If
                If Sense = 2 Then
                    If FixedCols > 4 Then Value = FixedNodeA(i, 5) Else Value = 0
                    n = nf(2, Node)
                    kv(n) = kv(n) + 1.0E+20
                    Loads(n) = kv(n) * Value
                End If
            Next i
 
        End If
 
        '!-----------------------------equation solution -------------------------------
        Call banred(kv, neq)
        Call bacsub(kv, Loads)
 
        '!-----------------------retrieve element end actions---------------------------
        For iel = 1 To nels
            For i = 1 To ndof
                For j = 1 To ndof
                    km(i, j) = store_km(i, j, iel)
                Next j
                g(i) = g_g(i, iel)
                eld(i) = Loads(g(i))
            Next i
 
 
            action = MATMUL(km, eld)
            resa(iel, 3) = -action(2)
            resa(iel, 4) = action(1)
 
        Next iel
        resa(iel, 3) = -action(4)
        resa(iel, 4) = -action(3)
        For i = 1 To nn
            resa(i, 1) = beamA(i, 1)
            resa(i, 2) = Loads(2 * i - 1)
        Next i
 
 
    End Sub
 
    Sub formnf(nf)
 
        Static TimeofFunction
        Dim Stopwatch1 As Stopwatch = Stopwatch.StartNew()
 
        '  ! reform nf
        Dim i As Long, j As Long, M As Long
        M = 0
        For j = 1 To UBound(nf, 2)
            For i = 1 To UBound(nf, 1)
                If (nf(i, j) <> 0) Then
                    M = M + 1
                    nf(i, j) = M
                End If
            Next i
        Next j
 
        Stopwatch1.Stop()
        TimeofFunction = TimeofFunction + Stopwatch1.Elapsed
 
 
    End Sub
 
 
    '!----------------Node to freedom number conversion ----------------------------
    Sub num_to_g(num, nf, g, ndof)
 
        Static TimeofFunction
        Dim Stopwatch1 As Stopwatch = Stopwatch.StartNew()
 
        ' !finds the g vector from num and nf
        Dim i As Long, j As Long, k As Long, nod As Long, nodof As Long
 
        nod = UBound(num, 1)
        nodof = UBound(nf, 1)
        For i = 1 To nod
            k = i * nodof
            For j = 1 To nodof
                g(k - nodof + j) = nf(j, num(i))
            Next j
        Next i
        Stopwatch1.Stop()
        TimeofFunction = TimeofFunction + Stopwatch1.Elapsed
 
 
    End Sub
 
 
    ' !-------------------------------- Lines  --------------------------------------
 
    Sub geometry_2l(iel, ell, coord, num)
 
        Static TimeofFunction
        Dim Stopwatch1 As Stopwatch = Stopwatch.StartNew()
 
        ' ! node numbers, nodal coordinates and steering vectors for
        ' ! a line of (nonuniform) beam elements
        num(1) = iel
        num(2) = iel + 1
        If (iel = 1) Then
            coord(1, 1) = 0#
            coord(2, 1) = ell
        Else
            coord(1, 1) = coord(2, 1)
            coord(2, 1) = coord(2, 1) + ell
        End If
 
        Stopwatch1.Stop()
        TimeofFunction = TimeofFunction + Stopwatch1.Elapsed
 
    End Sub
 
    Sub rod_km(km, ea, Length)
 
        Static TimeofFunction
        Dim Stopwatch1 As Stopwatch = Stopwatch.StartNew()
 
        Dim Stiff As Double
        Stiff = ea / Length
        km(1, 1) = Stiff
        km(2, 2) = Stiff
        km(1, 2) = -Stiff
        km(2, 1) = -Stiff
 
        Stopwatch1.Stop()
        TimeofFunction = TimeofFunction + Stopwatch1.Elapsed
    End Sub
 
    Sub formkv(bk, km, g, n, iel)
 
        Static TimeofFunction
        Dim Stopwatch1 As Stopwatch = Stopwatch.StartNew()
 
        ' !global stiffness matrix stored as a vector (upper triangle)
        Dim idof As Long, i As Long, j As Long, icd As Long, ival As Long
        idof = UBound(km, 1) - LBound(km, 1) + 1
 
        For i = 1 To idof
            If (g(i) <> 0) Then
                For j = 1 To idof
                    If (g(j) <> 0) Then
                        icd = g(j) - g(i) + 1
                        If (icd - 1 >= 0) Then
                            ival = n * (icd - 1) + g(i)
                            bk(ival) = bk(ival) + km(i, j)
                        End If
                    End If
                Next j
 
            End If
 
        Next i
 
        Stopwatch1.Stop()
        TimeofFunction = TimeofFunction + Stopwatch1.Elapsed
 
        ' Return
    End Sub
 
 
    Sub banred(bk, n)
 
        Static TimeofFunction
        Dim Stopwatch1 As Stopwatch = Stopwatch.StartNew()
 
        ' ! gaussian reduction on a vector stored as an upper triangle
        Dim i As Long, il1 As Long, kbl As Long, j As Long, ij As Long, nkb As Long, M As Long, ni As Long, nj As Long, iw As Long
        Dim sum As Double
 
        iw = UBound(bk, 1) / n - 1
        For i = 2 To n
            il1 = i - 1
            kbl = il1 + iw + 1
            If (kbl - n > 0) Then kbl = n
            For j = i To kbl
                ij = (j - i) * n + i
                sum = bk(ij)
                nkb = j - iw
                If (nkb <= 0) Then nkb = 1
                If (nkb - il1 <= 0) Then
                    For M = nkb To il1
                        ni = (i - M) * n + M
                        nj = (j - M) * n + M
                        sum = sum - bk(ni) * bk(nj) / bk(M)
                    Next M
                End If
                bk(ij) = sum
            Next j
        Next i
 
        Stopwatch1.Stop()
        TimeofFunction = TimeofFunction + Stopwatch1.Elapsed
 
    End Sub
 
    Sub bacsub(bk, Loads)
        Static TimeofFunction
        Dim Stopwatch1 As Stopwatch = Stopwatch.StartNew()
 
        ' ! performs the complete gaussian backsubstitution
        Dim nkb As Long, k As Long, i As Long, jn As Long, jj As Long, i1 As Long, n As Long, iw As Long
        Dim sum As Double
        n = UBound(Loads, 1)
        iw = UBound(bk, 1) / n - 1
        Loads(1) = Loads(1) / bk(1)
        For i = 2 To n
            sum = Loads(i)
            i1 = i - 1
            nkb = i - iw
            If (nkb <= 0) Then nkb = 1
            For k = nkb To i1
                jn = (i - k) * n + k
                sum = sum - bk(jn) * Loads(k)
            Next k
            Loads(i) = sum / bk(i)
        Next i
        For jj = 2 To n
            i = n - jj + 1
            sum = 0#
            i1 = i + 1
            nkb = i + iw
            If (nkb - n > 0) Then nkb = n
            For k = i1 To nkb
                jn = (k - i) * n + i
                sum = sum + bk(jn) * Loads(k)
            Next k
            Loads(i) = Loads(i) - sum / bk(i)
        Next jj
        ' Return
 
        Stopwatch1.Stop()
        TimeofFunction = TimeofFunction + Stopwatch1.Elapsed
 
    End Sub
 
 
    Function MATMUL(A, b)
        Static TimeofFunction
        Dim Stopwatch1 As Stopwatch = Stopwatch.StartNew()
 
        '      PRODUCT OF TWO MATRICES
        '
        Dim i As Long, j As Long, k As Long, x As Double, l As Long, n As Long
        l = UBound(A, 2)
        n = UBound(A)
        Dim Mat = Array.CreateInstance(GetType(Double), {l}, {1})
        For i = 1 To l
            For j = 1 To n
                x = 0#
                For k = 1 To l
                    x = x + A(i, k) * b(k)
                Next k
                Mat(i) = x
            Next j
        Next i
        MATMUL = Mat
 
        Stopwatch1.Stop()
        TimeofFunction = TimeofFunction + Stopwatch1.Elapsed
 
    End Function
 
 
    '
    Sub MATRAN(A, IA, b, IB, M, n)
        '
        '      FORMS THE TRANSPOSE OF A MATRIX
        '
        '     REAL A(IA,*),B(IB,*)
        '     DO 1 I = 1,M
        '         DO 1 J = 1,N
        '     A(j, i) = B(i, j)
 
    End Sub
 
    Sub MSMULT(A, IA, c, M, n)
        '
        '      MULTIPLIES A MATRIX BY A SCALAR
        '
        '      REAL A(IA,*)
        '      DO 1 I = 1,M
        '          DO 1 J = 1,N
        '     A(i, j) = A(i, j) * c
    End Sub
 
    Sub MVMULT(M, v, k, l, y)
 
        Static TimeofFunction
        Dim Stopwatch1 As Stopwatch = Stopwatch.StartNew()
 
        '      MULTIPLIES A MATRIX BY A VECTOR
 
 
        Dim i As Long, j As Long, x As Double
        ' ReDim Preserve M(k, l), V(l), Y(k)
        ReDim y(k)
        For i = 1 To k
            x = 0#
            For j = 1 To l
                x = x + M(i, j) * v(j)
            Next j
            y(i) = x
        Next i
 
        Stopwatch1.Stop()
        TimeofFunction = TimeofFunction + Stopwatch1.Elapsed
 
    End Sub
 
    Function bandwidth(g)
 
        Static TimeofFunction
        Dim Stopwatch1 As Stopwatch = Stopwatch.StartNew()
 
        '! finds the element bandwidth from g
        If WorksheetMin(g) > 0 Then
            bandwidth = WorksheetMax(g) - WorksheetMin(g)
        Else
            bandwidth = 0
        End If
 
        Stopwatch1.Stop()
        TimeofFunction = TimeofFunction + Stopwatch1.Elapsed
 
    End Function
 
 
    Sub sample(element, s, wt)
 
        Static TimeofFunction
        Dim Stopwatch1 As Stopwatch = Stopwatch.StartNew()
        ' ! returns the local coordinates of the integrating points
 
        ' ****  Edited for line element only  *****
 
        Dim NIP As Long, root3 As Double, R15 As Double
        Dim w = Array.CreateInstance(GetType(Double), {3}, {1})
        Dim v = Array.CreateInstance(GetType(Double), {9}, {1})
        Dim b As Double, c As Double, i As Long
 
        root3 = 1.0# / (3.0#) ^ 0.5
        R15 = 0.2 * (15.0#) ^ 0.5
        NIP = UBound(s, 1)
        w(1) = 5.0# / 9.0#
        w(2) = 8.0# / 9.0#
        w(3) = 5.0# / 9.0#
        For i = 1 To 7 Step 3
            v(i) = 5.0# / 9.0# * w(1)
            v(i + 1) = 8.0# / 9.0# * w(2)
            v(i + 2) = 5.0# / 9.0# * w(3)
        Next i
        Select Case element
            Case "line"
 
                Select Case (NIP)
                    Case (1)
                        s(1, 1) = 0#
                        wt(1) = 2.0#
                    Case (2)
                        s(1, 1) = root3
                        s(2, 1) = -s(1, 1)
                        wt(1) = 1.0#
                        wt(2) = 1.0#
                    Case (3)
                        s(1, 1) = R15
                        s(2, 1) = 0#
                        s(3, 1) = -s(1, 1)
                        wt = w
                    Case (4)
                        s(1, 1) = 0.861136311594053
                        s(2, 1) = 0.339981043584856
                        s(3, 1) = -s(2, 1)
                        s(4, 1) = -s(1, 1)
 
                        wt(1) = 0.347854845137454
                        wt(2) = 0.652145154862546
                        wt(3) = wt(2)
                        wt(4) = wt(1)
                    Case (5)
                        s(1, 1) = 0.906179845938664
                        s(2, 1) = 0.538469310105683
                        s(3, 1) = 0#
                        s(4, 1) = -s(2, 1)
                        s(5, 1) = -s(1, 1)
                        wt(1) = 0.236926885056189
                        wt(2) = 0.478628670499366
                        wt(3) = 0.568888888888889
                        wt(4) = wt(2)
                        wt(5) = wt(1)
                    Case (6)
                        s(1, 1) = 0.932469514203152
                        s(2, 1) = 0.661209386466265
                        s(3, 1) = 0.238619186083197
                        s(4, 1) = -s(3, 1)
                        s(5, 1) = -s(2, 1)
                        s(6, 1) = -s(1, 1)
                        wt(1) = 0.17132449237917
                        wt(2) = 0.360761573048139
                        wt(3) = 0.467913934572691
                        wt(4) = wt(3)
                        wt(5) = wt(2)
                        wt(6) = wt(1)
 
                End Select
        End Select
        Stopwatch1.Stop()
        TimeofFunction = TimeofFunction + Stopwatch1.Elapsed
    End Sub
 
 
    Sub fmbeam(der2, fun, points, i, ell)
 
        Static TimeofFunction
        Dim Stopwatch1 As Stopwatch = Stopwatch.StartNew()
 
        ' !
        ' ! this subroutine forms the beam shape functions
        ' ! and their 2nd derivatives in local coordinates
        ' !
 
        Dim xi As Double, xi2 As Double, xi3
 
        xi = points(i, 1)
        xi2 = xi * xi
        xi3 = xi2 * xi
 
        fun(1) = 0.25 * (xi3 - 3.0# * xi + 2.0#)
        fun(2) = 0.125 * ell * (xi3 - xi2 - xi + 1.0#)
        fun(3) = 0.25 * (-xi3 + 3.0# * xi + 2.0#)
        fun(4) = 0.125 * ell * (xi3 + xi2 - xi - 1.0#)
        der2(1) = 1.5 * xi
        der2(2) = 0.25 * ell * (3.0# * xi - 1.0#)
        der2(3) = -1.5 * xi
        der2(4) = 0.25 * ell * (3.0# * xi + 1.0#)
 
        Stopwatch1.Stop()
        TimeofFunction = TimeofFunction + Stopwatch1.Elapsed
 
    End Sub
 
 
 
    Function WorksheetMax(tr As Object, Optional InitialRowNumber As Integer = 0, Optional InitialColumnNumber As Integer = 0)
 
        Static TimeofFunction
        Dim Stopwatch1 As Stopwatch = Stopwatch.StartNew()
 
        WorksheetMax = Nothing
 
        For Each element In tr
 
            If IsNumeric(element) Then
 
                If IsNothing(WorksheetMax) Then
                    WorksheetMax = element
                Else
                    If element > WorksheetMax Then WorksheetMax = element
                End If
 
            End If
        Next
 
        Stopwatch1.Stop()
        TimeofFunction = TimeofFunction + Stopwatch1.Elapsed
 
    End Function
 
    Function WorksheetMin(tr As Object, Optional InitialRowNumber As Integer = 0, Optional InitialColumnNumber As Integer = 0)
        Static TimeofFunction
        Dim Stopwatch1 As Stopwatch = Stopwatch.StartNew()
 
        WorksheetMin = Nothing
 
        For Each element In tr
 
            If IsNumeric(element) Then
 
 
                If IsNothing(WorksheetMin) Then
                    WorksheetMin = element
                Else
                    If element < WorksheetMin Then WorksheetMin = element
                End If
 
            End If
 
        Next
 
        Stopwatch1.Stop()
        TimeofFunction = TimeofFunction + Stopwatch1.Elapsed
 
    End Function