module argyr_swing_examples
# Argyris L-frame, large-amplitude swinging motion.
#
# An L-shaped frame is pushed at the elbow by a triangular-pulse force,
# which sends it swinging about the pinned end. The frame executes
# large-amplitude dynamic motion.

using FinEtools
using FinEtoolsDeforLinear
using FinEtoolsFlexStructures.CrossSectionModule: CrossSectionRectangle
using FinEtoolsFlexStructures.MeshFrameMemberModule: frame_member, merge_members
using FinEtoolsFlexStructures.FEMMCorotBeamModule
using FinEtoolsFlexStructures.FEMMCorotBeamModule: FEMMCorotBeam
stiffness = FEMMCorotBeamModule.stiffness
mass = FEMMCorotBeamModule.mass
distribloads_global = FEMMCorotBeamModule.distribloads_global
restoringforce = FEMMCorotBeamModule.restoringforce
gyroscopic = FEMMCorotBeamModule.gyroscopic
using FinEtoolsFlexStructures.RotUtilModule: initial_Rfield, update_rotation_field!
using LinearAlgebra: dot
using Arpack
using LinearAlgebra
using SparseArrays
using VisualStructures: plot_points, plot_nodes, plot_midline, render, plot_space_box, plot_solid, space_aspectratio
using PlotlyJS
using JSON


tipus =[-0.0000    0.0000   -0.0002
0.0000    0.0000   -0.0016
0.0000    0.0000   -0.0053
0.0000    0.0000   -0.0123
0.0000    0.0000   -0.0237
0.0000    0.0000   -0.0410
0.0000    0.0000   -0.0650
0.0001    0.0001   -0.0967
0.0002    0.0002   -0.1377
0.0003    0.0004   -0.1890
0.0005    0.0007   -0.2513
0.0009    0.0012   -0.3261
0.0015    0.0019   -0.4146
0.0023    0.0030   -0.5177
0.0035    0.0045   -0.6367
0.0052    0.0066   -0.7726
0.0075    0.0095   -0.9265
0.0106    0.0134   -1.0999
0.0147    0.0185   -1.2933
0.0200    0.0252   -1.5081
0.0268    0.0337   -1.7458
0.0355    0.0446   -2.0071
0.0464    0.0582   -2.2928
0.0600    0.0751   -2.6047
0.0767    0.0959   -2.9435
0.0971    0.1213   -3.3102
0.1219    0.1521   -3.7060
0.1517    0.1891   -4.1319
0.1873    0.2334   -4.5888
0.2296    0.2859   -5.0779
0.2796    0.3480   -5.5997
0.3383    0.4209   -6.1554
0.4069    0.5060   -6.7461
0.4867    0.6051   -7.3719
0.5791    0.7197   -8.0338
0.6856    0.8518   -8.7328
0.8078    1.0035   -9.4690
0.9475    1.1769  -10.2427
1.1067    1.3744  -11.0546
1.2873    1.5987  -11.9047
1.4917    1.8525  -12.7929
1.7220    2.1387  -13.7190
1.9808    2.4604  -14.6827
2.2707    2.8211  -15.6835
2.5945    3.2243  -16.7205
2.9551    3.6736  -17.7922
3.3555    4.1730  -18.8977
3.7989    4.7267  -20.0351
4.2886    5.3389  -21.2020
4.8279    6.0142  -22.3960
5.4205    6.7573  -23.6144
6.0697    7.5729  -24.8535
6.7792    8.4661  -26.1094
7.5527    9.4419  -27.3778
8.3937   10.5055  -28.6535
9.3058   11.6622  -29.9311
10.2925   12.9173  -31.2041
11.3572   14.2760  -32.4656
12.5031   15.7437  -33.7084
13.7332   17.3257  -34.9239
15.0501   19.0267  -36.1030
16.4564   20.8518  -37.2363
17.9539   22.8057  -38.3133
19.5441   24.8926  -39.3227
21.2280   27.1165  -40.2527
23.0060   29.4810  -41.0911
24.8777   31.9891  -41.8246
26.8422   34.6432  -42.4396
28.8973   37.4453  -42.9219
31.0405   40.3963  -43.2572
33.2679   43.4968  -43.4308
35.5748   46.7462  -43.4275
37.9554   50.1429  -43.2323
40.4028   53.6851  -42.8306
42.9092   57.3693  -42.2076
45.4652   61.1910  -41.3491
48.0607   65.1451  -40.2417
50.6846   69.2256  -38.8725
53.3244   73.4247  -37.2298
55.9667   77.7344  -35.3029
58.5976   82.1456  -33.0827
61.2020   86.6480  -30.5614
63.7643   91.2312  -27.7331
66.2684   95.8833  -24.5934
68.6977  100.5925  -21.1402
71.0358  105.3465  -17.3733
73.2659  110.1324  -13.2945
75.3713  114.9370   -8.9081
77.3362  119.7480   -4.2202
79.1450  124.5524    0.7609
80.7827  129.3377    6.0247
82.2355  134.0921   11.5588
83.4907  138.8044   17.3490
84.5366  143.4638   23.3793
85.3629  148.0606   29.6324
85.9610  152.5861   36.0896
86.3234  157.0325   42.7310
86.4445  161.3933   49.5360
86.3201  165.6627   56.4834
85.9477  169.8364   63.5513
85.3266  173.9118   70.7183
84.4574  177.8877   77.9623
83.3423  181.7644   85.2620
81.9844  185.5438   92.5967
80.3882  189.2279   99.9468
78.5592  192.8196  107.2940
76.5037  196.3225  114.6206
74.2284  199.7407  121.9101
71.7404  203.0792  129.1472
69.0478  206.3429  136.3179
66.1591  209.5364  143.4093
63.0827  212.6656  150.4099
59.8268  215.7362  157.3091
56.4003  218.7534  164.0969
52.8119  221.7227  170.7650
49.0703  224.6496  177.3064
45.1840  227.5391  183.7144
41.1610  230.3967  189.9829
37.0095  233.2272  196.1070
32.7375  236.0350  202.0827
28.3526  238.8248  207.9069
23.8620  241.6006  213.5764
19.2729  244.3662  219.0886
14.5915  247.1256  224.4418
9.8247  249.8819  229.6349
4.9787  252.6377  234.6668
0.0591  255.3964  239.5369
-4.9289  258.1605  244.2447
-9.9797  260.9321  248.7898
-15.0885  263.7132  253.1731
-20.2505  266.5056  257.3947
-25.4613  269.3109  261.4551
-30.7171  272.1306  265.3547
-36.0136  274.9658  269.0944
-41.3470  277.8172  272.6753
-46.7143  280.6861  276.0986
-52.1118  283.5729  279.3648
-57.5362  286.4781  282.4748
-62.9851  289.4023  285.4300
-68.4555  292.3455  288.2318
-73.9443  295.3078  290.8811
-79.4494  298.2894  293.3788
-84.9684  301.2904  295.7258
-90.4987  304.3103  297.9236
-96.0384  307.3490  299.9735
-101.5852  310.4061  301.8763
-107.1370  313.4813  303.6327
-112.6922  316.5744  305.2437
-118.2484  319.6845  306.7106
-123.8039  322.8109  308.0345
-129.3572  325.9535  309.2161
-134.9061  329.1113  310.2559
-140.4488  332.2835  311.1548
-145.9842  335.4696  311.9141
-151.5101  338.6685  312.5346
-157.0249  341.8794  313.0167
-162.5270  345.1015  313.3610
-168.0147  348.3338  313.5684
-173.4865  351.5752  313.6400
-178.9407  354.8248  313.5763
-184.3755  358.0813  313.3779
-189.7894  361.3438  313.0452
-195.1810  364.6113  312.5791
-200.5483  367.8822  311.9808
-205.8898  371.1553  311.2508
-211.2041  374.4297  310.3894
-216.4891  377.7038  309.3974
-221.7433  380.9761  308.2759
-226.9654  384.2456  307.0257
-232.1535  387.5107  305.6476
-237.3058  390.7699  304.1421
-242.4208  394.0217  302.5102
-247.4969  397.2646  300.7530
-252.5325  400.4971  298.8717
-257.5260  403.7177  296.8669
-262.4752  406.9245  294.7396
-267.3789  410.1161  292.4910
-272.2357  413.2910  290.1224
-277.0436  416.4471  287.6353
-281.8010  419.5829  285.0305
-286.5065  422.6970  282.3092
-291.1582  425.7872  279.4731
-295.7547  428.8520  276.5239
-300.2946  431.8897  273.4629
-304.7760  434.8985  270.2916
-309.1974  437.8767  267.0116
-313.5574  440.8225  263.6248
-317.8546  443.7342  260.1334
-322.0875  446.6103  256.5388
-326.2545  449.4488  252.8429
-330.3538  452.2478  249.0481
-334.3846  455.0061  245.1563
-338.3457  457.7222  241.1697
-342.2352  460.3939  237.0910
-346.0518  463.0198  232.9220
-349.7945  465.5985  228.6650
-353.4620  468.1284  224.3231
-357.0533  470.6081  219.8988
-360.5671  473.0360  215.3945
-364.0021  475.4107  210.8129
-367.3574  477.7313  206.1566
-370.6324  479.9968  201.4283
-373.8258  482.2066  196.6301
-376.9366  484.3601  191.7636
-379.9637  486.4566  186.8311
-382.9065  488.4957  181.8351
-385.7645  490.4770  176.7778
-388.5367  492.4000  171.6614
-391.2222  494.2640  166.4879
-393.8201  496.0685  161.2594
-396.3301  497.8134  155.9786
-398.7520  499.4982  150.6476
-401.0849  501.1226  145.2686
-403.3279  502.6860  139.8439
-405.4806  504.1881  134.3758
-407.5430  505.6289  128.8664
-409.5149  507.0081  123.3183
-411.3955  508.3253  117.7337
-413.1843  509.5802  112.1146
-414.8811  510.7727  106.4635
-416.4862  511.9028  100.7829
-417.9995  512.9703   95.0749
-419.4202  513.9750   89.3417
-420.7483  514.9167   83.5856
-421.9839  515.7954   77.8088
-423.1274  516.6113   72.0140
-424.1787  517.3643   66.2030
-425.1374  518.0543   60.3781
-426.0037  518.6811   54.5419
-426.7780  519.2451   48.6963
-427.4608  519.7465   42.8435
-428.0522  520.1852   36.9858
-428.5520  520.5612   31.1256
-428.9606  520.8747   25.2648
-429.2788  521.1260   19.4056
-429.5071  521.3154   13.5502
-429.6458  521.4430    7.7006
-429.6949  521.5089    1.8592
-429.6552  521.5134   -3.9721
-429.5275  521.4569   -9.7914
-429.3127  521.3398  -15.5964
-429.0109  521.1623  -21.3852
-428.6225  520.9245  -27.1559
-428.1486  520.6270  -32.9062
-427.5903  520.2703  -38.6344
-426.9483  519.8547  -44.3389
-426.2231  519.3806  -50.0174
-425.4153  518.8482  -55.6680
-424.5261  518.2582  -61.2890
-423.5568  517.6111  -66.8789
-422.5083  516.9074  -72.4358
-421.3810  516.1474  -77.9577
-420.1761  515.3315  -83.4429
-418.8948  514.4605  -88.8902
-417.5385  513.5350  -94.2979
-416.1082  512.5554  -99.6642
-414.6045  511.5221 -104.9876
-413.0286  510.4357 -110.2666
-411.3822  509.2970 -115.4998
-409.6667  508.1065 -120.6860
-407.8828  506.8648 -125.8237
-406.0316  505.5722 -130.9112
-404.1147  504.2295 -135.9474
-402.1334  502.8375 -140.9314
-400.0894  501.3966 -145.8619
-397.9835  499.9075 -150.7376
-395.8169  498.3706 -155.5572
-393.5913  496.7866 -160.3196
-391.3082  495.1563 -165.0244
-388.9690  493.4802 -169.6704
-386.5750  491.7588 -174.2562
-384.1272  489.9927 -178.7810
-381.6275  488.1826 -183.2443
-379.0775  486.3291 -187.6454
-376.4785  484.4328 -191.9835
-373.8316  482.4941 -196.2575
-371.1384  480.5137 -200.4666
-368.4004  478.4921 -204.6109
-365.6195  476.4300 -208.6897
-362.7968  474.3277 -212.7023
-359.9333  472.1858 -216.6479
-357.0309  470.0048 -220.5262
-354.0912  467.7852 -224.3372
-351.1155  465.5276 -228.0806
-348.1051  463.2322 -231.7558
-345.0614  460.8995 -235.3621
-341.9858  458.5300 -238.8997
-338.8797  456.1240 -242.3687
-335.7449  453.6819 -245.7689
-332.5822  451.2041 -249.0998
-329.3930  448.6907 -252.3610
-326.1787  446.1422 -255.5529
-322.9407  443.5588 -258.6759
-319.6803  440.9408 -261.7297
-316.3986  438.2883 -264.7139
-313.0966  435.6015 -267.6286
-309.7759  432.8806 -270.4741
-306.4377  430.1257 -273.2509
-303.0827  427.3368 -275.9588
-299.7122  424.5142 -278.5975
-296.3274  421.6577 -281.1671
-292.9291  418.7673 -283.6684
-289.5184  415.8432 -286.1015
-286.0963  412.8851 -288.4663
-282.6636  409.8930 -290.7625
-279.2213  406.8668 -292.9905
-275.7702  403.8064 -295.1509
-272.3109  400.7115 -297.2439
-268.8445  397.5820 -299.2690
-265.3716  394.4176 -301.2262
-261.8926  391.2182 -303.1158
-258.4085  387.9833 -304.9382
-254.9197  384.7126 -306.6935
-251.4267  381.4060 -308.3811
-247.9302  378.0631 -310.0008
-244.4306  374.6835 -311.5529
-240.9282  371.2668 -313.0376
-237.4235  367.8126 -314.4546
-233.9169  364.3207 -315.8031
-230.4086  360.7906 -317.0828
-226.8991  357.2219 -318.2939
-223.3883  353.6142 -319.4361
-219.8764  349.9671 -320.5088
-216.3642  346.2802 -321.5109
-212.8515  342.5534 -322.4419
-209.3381  338.7861 -323.3017
-205.8245  334.9780 -324.0896
-202.3108  331.1288 -324.8044
-198.7971  327.2385 -325.4449
-195.2834  323.3066 -326.0104
-191.7698  319.3330 -326.5001
-188.2561  315.3175 -326.9130
-184.7429  311.2601 -327.2475
-181.2300  307.1608 -327.5020
-177.7175  303.0198 -327.6754
-174.2056  298.8366 -327.7668
-170.6940  294.6119 -327.7744
-167.1833  290.3459 -327.6962
-163.6738  286.0389 -327.5306
-160.1655  281.6912 -327.2762
-156.6583  277.3034 -326.9313
-153.1528  272.8760 -326.4940
-149.6496  268.4099 -325.9620
-146.1489  263.9059 -325.3334
-142.6510  259.3648 -324.6066
-139.1563  254.7876 -323.7797
-135.6656  250.1755 -322.8504
-132.1798  245.5299 -321.8164
-128.6994  240.8522 -320.6756
-125.2249  236.1438 -319.4264
-121.7574  231.4059 -318.0668
-118.2979  226.6409 -316.5943
-114.8476  221.8507 -315.0068
-111.4078  217.0369 -313.3025
-107.9790  212.2018 -311.4796
-104.5628  207.3474 -309.5363
-101.1609  202.4764 -307.4704
-97.7750  197.5914 -305.2800
-94.4063  192.6947 -302.9637
-91.0563  187.7888 -300.5201
-87.7269  182.8768 -297.9475
-84.4204  177.9617 -295.2445
-81.1387  173.0464 -292.4097
-77.8836  168.1340 -289.4422
-74.6570  163.2276 -286.3410
-71.4613  158.3302 -283.1054
-68.2992  153.4457 -279.7343
-65.1729  148.5774 -276.2273
-62.0847  143.7283 -272.5843
-59.0367  138.9020 -268.8051
-56.0318  134.1021 -264.8895
-53.0730  129.3323 -260.8376
-50.1627  124.5963 -256.6499
-47.3033  119.8972 -252.3270
-44.4974  115.2386 -247.8697
-41.7481  110.6245 -243.2789
-39.0584  106.0583 -238.5555
-36.4309  101.5434 -233.7010
-33.8679   97.0835 -228.7171
-31.3723   92.6817 -223.6053
-28.9473   88.3416 -218.3676
-26.5957   84.0670 -213.0060
-24.3199   79.8607 -207.5228
-22.1223   75.7259 -201.9206
-20.0057   71.6658 -196.2019
-17.9733   67.6836 -190.3696
-16.0274   63.7824 -184.4265
-14.1703   59.9648 -178.3760
-12.4042   56.2334 -172.2211
-10.7316   52.5911 -165.9654
-9.1554   49.0408 -159.6125
-7.6776   45.5844 -153.1660
-6.2999   42.2244 -146.6297
-5.0243   38.9629 -140.0075
-3.8530   35.8021 -133.3036
-2.7884   32.7440 -126.5220
-1.8319   29.7904 -119.6670
-0.9848   26.9428 -112.7429
-0.2487   24.2028 -105.7539
0.3747   21.5720  -98.7047
0.8835   19.0517  -91.5996
1.2770   16.6431  -84.4433
1.5544   14.3470  -77.2403
1.7144   12.1643  -69.9951
1.7558   10.0960  -62.7124
1.6777    8.1430  -55.3972
1.4796    6.3054  -48.0537
1.1613    4.5837  -40.6867
0.7222    2.9783  -33.3008
0.1613    1.4895  -25.9009
-0.5214    0.1173  -18.4915
-1.3259   -1.1383  -11.0771
-2.2519   -2.2777   -3.6622
-3.2998   -3.3008    3.7484
-4.4696   -4.2080   11.1502
-5.7612   -4.9998   18.5388
-7.1735   -5.6768   25.9099
-8.7062   -6.2395   33.2592
-10.3593   -6.6887   40.5823
-12.1321   -7.0251   47.8747
-14.0237   -7.2494   55.1324
-16.0332   -7.3630   62.3514
-18.1595   -7.3666   69.5279
-20.4021   -7.2613   76.6574
-22.7601   -7.0483   83.7360
-25.2321   -6.7287   90.7601
-27.8167   -6.3041   97.7262
-30.5126   -5.7756  104.6305
-33.3189   -5.1445  111.4690
-36.2342   -4.4123  118.2383
-39.2569   -3.5806  124.9354
-42.3851   -2.6509  131.5569
-45.6174   -1.6247  138.0994
-48.9526   -0.5037  144.5596
-52.3889    0.7107  150.9343
-55.9241    2.0165  157.2209
-59.5565    3.4120  163.4166
-63.2845    4.8956  169.5183
-67.1063    6.4656  175.5230
-71.0201    8.1201  181.4283
-75.0233    9.8572  187.2317
-79.1141   11.6751  192.9311
-83.2908   13.5720  198.5237
-87.5513   15.5460  204.0068
-91.8933   17.5952  209.3785
-96.3147   19.7176  214.6372
-100.8131   21.9114  219.7806
-105.3866   24.1746  224.8062
-110.0333   26.5053  229.7123
-114.7506   28.9016  234.4973
-119.5359   31.3613  239.1597
-124.3873   33.8827  243.6977
-129.3025   36.4637  248.1094
-134.2795   39.1025  252.3934
-139.3155   41.7969  256.5485
-144.4080   44.5450  260.5736
-149.5551   47.3448  264.4673
-154.7544   50.1945  268.2280
-160.0034   53.0919  271.8546
-165.2997   56.0351  275.3466
-170.6409   59.0223  278.7032
-176.0245   62.0513  281.9231
-181.4484   65.1203  285.0051
-186.9102   68.2273  287.9489
-192.4071   71.3703  290.7540
-197.9370   74.5475  293.4200
-203.4974   77.7569  295.9458
-209.0860   80.9965  298.3307
-214.7004   84.2645  300.5749
-220.3381   87.5591  302.6781
-225.9965   90.8781  304.6401
-231.6736   94.2199  306.4603
-237.3670   97.5825  308.1383
-243.0740  100.9641  309.6745
-248.7924  104.3629  311.0692
-254.5200  107.7770  312.3223
-260.2541  111.2045  313.4333
-265.9927  114.6437  314.4024
-271.7333  118.0928  315.2305
-277.4736  121.5501  315.9178
-283.2114  125.0138  316.4645
-288.9442  128.4820  316.8706
-294.6698  131.9530  317.1366
-300.3861  135.4253  317.2635
-306.0908  138.8972  317.2521
-311.7813  142.3668  317.1024
-317.4559  145.8326  316.8148
-323.1123  149.2927  316.3904
-328.7480  152.7459  315.8304
-334.3612  156.1903  315.1356
-339.9496  159.6244  314.3062
-345.5111  163.0465  313.3432
-351.0436  166.4551  312.2478
-356.5451  169.8489  311.0214
-362.0134  173.2262  309.6649
-367.4468  176.5855  308.1790
-372.8428  179.9252  306.5648
-378.1997  183.2439  304.8239
-383.5158  186.5406  302.9578
-388.7888  189.8135  300.9675];

elbowus=[-0.0000   -0.0000    0.0007
-0.0000   -0.0000    0.0040
-0.0000   -0.0000    0.0118
-0.0000   -0.0000    0.0265
-0.0000   -0.0000    0.0506
-0.0000   -0.0000    0.0863
-0.0000   -0.0000    0.1358
-0.0001   -0.0001    0.2017
-0.0002   -0.0002    0.2860
-0.0003   -0.0003    0.3914
-0.0006   -0.0005    0.5200
-0.0009   -0.0009    0.6739
-0.0015   -0.0015    0.8559
-0.0024   -0.0023    1.0681
-0.0036   -0.0034    1.3126
-0.0053   -0.0050    1.5920
-0.0076   -0.0072    1.9086
-0.0107   -0.0102    2.2646
-0.0148   -0.0141    2.6624
-0.0201   -0.0191    3.1042
-0.0269   -0.0256    3.5925
-0.0355   -0.0339    4.1294
-0.0464   -0.0442    4.7173
-0.0598   -0.0571    5.3585
-0.0764   -0.0729    6.0553
-0.0966   -0.0922    6.8099
-0.1212   -0.1156    7.6244
-0.1506   -0.1438    8.5013
-0.1859   -0.1774    9.4429
-0.2277   -0.2174   10.4509
-0.2771   -0.2646   11.5278
-0.3352   -0.3200   12.6758
-0.4030   -0.3847   13.8968
-0.4818   -0.4600   15.1928
-0.5730   -0.5471   16.5658
-0.6781   -0.6476   18.0177
-0.7988   -0.7628   19.5504
-0.9367   -0.8946   21.1654
-1.0939   -1.0447   22.8645
-1.2722   -1.2151   24.6492
-1.4739   -1.4079   26.5209
-1.7014   -1.6252   28.4806
-1.9570   -1.8695   30.5295
-2.2434   -2.1433   32.6687
-2.5634   -2.4492   34.8984
-2.9199   -2.7900   37.2192
-3.3159   -3.1688   39.6315
-3.7548   -3.5885   42.1350
-4.2397   -4.0524   44.7293
-4.7742   -4.5638   47.4136
-5.3619   -5.1262   50.1869
-6.0064   -5.7432   53.0479
-6.7115   -6.4183   55.9943
-7.4811   -7.1554   59.0239
-8.3190   -7.9581   62.1341
-9.2291   -8.8304   65.3214
-10.2152   -9.7759   68.5819
-11.2813  -10.7984   71.9114
-12.4311  -11.9017   75.3050
-13.6681  -13.0893   78.7570
-14.9959  -14.3645   82.2614
-16.4177  -15.7308   85.8114
-17.9364  -17.1910   89.4000
-19.5548  -18.7480   93.0192
-21.2751  -20.4039   96.6604
-23.0992  -22.1609  100.3149
-25.0286  -24.0206  103.9733
-27.0640  -25.9837  107.6256
-29.2057  -28.0507  111.2614
-31.4536  -30.2217  114.8704
-33.8064  -32.4956  118.4417
-36.2625  -34.8709  121.9642
-38.8195  -37.3453  125.4270
-41.4740  -39.9157  128.8192
-44.2221  -42.5783  132.1300
-47.0591  -45.3281  135.3491
-49.9793  -48.1596  138.4666
-52.9765  -51.0664  141.4732
-56.0438  -54.0415  144.3603
-59.1736  -57.0764  147.1201
-62.3576  -60.1628  149.7461
-65.5875  -63.2912  152.2326
-68.8541  -66.4513  154.5754
-72.1482  -69.6328  156.7715
-75.4604  -72.8247  158.8192
-78.7813  -76.0158  160.7184
-82.1017  -79.1943  162.4705
-85.4125  -82.3487  164.0782
-88.7051  -85.4675  165.5459
-91.9716  -88.5393  166.8792
-95.2044  -91.5527  168.0851
-98.3968  -94.4969  169.1720
-101.5433  -97.3615  170.1492
-104.6389 -100.1369  171.0271
-107.6798 -102.8134  171.8169
-110.6634 -105.3829  172.5306
-113.5882 -107.8376  173.1803
-116.4536 -110.1704  173.7788
-119.2604 -112.3751  174.3390
-122.0103 -114.4465  174.8735
-124.7061 -116.3806  175.3944
-127.3511 -118.1751  175.9124
-129.9495 -119.8287  176.4377
-132.5059 -121.3409  176.9794
-135.0257 -122.7125  177.5453
-137.5145 -123.9440  178.1430
-139.9784 -125.0367  178.7787
-142.4238 -125.9925  179.4577
-144.8572 -126.8138  180.1844
-147.2851 -127.5027  180.9622
-149.7141 -128.0620  181.7936
-152.1505 -128.4945  182.6799
-154.6007 -128.8033  183.6219
-157.0708 -128.9914  184.6193
-159.5666 -129.0618  185.6714
-162.0934 -129.0175  186.7763
-164.6565 -128.8620  187.9316
-167.2606 -128.5980  189.1345
-169.9101 -128.2285  190.3818
-172.6089 -127.7567  191.6690
-175.3605 -127.1853  192.9922
-178.1679 -126.5170  194.3466
-181.0338 -125.7547  195.7271
-183.9605 -124.9011  197.1285
-186.9495 -123.9588  198.5453
-190.0023 -122.9301  199.9720
-193.1198 -121.8176  201.4028
-196.3025 -120.6239  202.8319
-199.5504 -119.3513  204.2534
-202.8634 -118.0020  205.6618
-206.2408 -116.5785  207.0511
-209.6816 -115.0832  208.4155
-213.1846 -113.5183  209.7497
-216.7484 -111.8861  211.0480
-220.3708 -110.1891  212.3051
-224.0498 -108.4295  213.5159
-227.7831 -106.6096  214.6754
-231.5682 -104.7320  215.7789
-235.4022 -102.7989  216.8217
-239.2820 -100.8130  217.7995
-243.2046  -98.7765  218.7083
-247.1670  -96.6919  219.5443
-251.1655  -94.5621  220.3038
-255.1965  -92.3894  220.9834
-259.2569  -90.1762  221.5803
-263.3427  -87.9253  222.0916
-267.4503  -85.6395  222.5146
-271.5762  -83.3213  222.8473
-275.7165  -80.9733  223.0875
-279.8675  -78.5982  223.2337
-284.0255  -76.1988  223.2843
-288.1870  -73.7776  223.2381
-292.3483  -71.3374  223.0942
-296.5059  -68.8808  222.8517
-300.6561  -66.4104  222.5104
-304.7957  -63.9289  222.0698
-308.9216  -61.4386  221.5299
-313.0302  -58.9424  220.8908
-317.1184  -56.4427  220.1530
-321.1835  -53.9416  219.3169
-325.2225  -51.4418  218.3832
-329.2325  -48.9457  217.3528
-333.2111  -46.4554  216.2266
-337.1557  -43.9730  215.0058
-341.0639  -41.5007  213.6916
-344.9336  -39.0407  212.2854
-348.7625  -36.5948  210.7887
-352.5489  -34.1649  209.2029
-356.2908  -31.7526  207.5296
-359.9865  -29.3601  205.7706
-363.6344  -26.9886  203.9276
-367.2335  -24.6396  202.0021
-370.7819  -22.3149  199.9961
-374.2786  -20.0156  197.9114
-377.7228  -17.7429  195.7496
-381.1133  -15.4981  193.5126
-384.4493  -13.2824  191.2021
-387.7301  -11.0966  188.8199
-390.9550   -8.9417  186.3676
-394.1236   -6.8185  183.8469
-397.2353   -4.7278  181.2594
-400.2896   -2.6704  178.6067
-403.2865   -0.6467  175.8902
-406.2256    1.3428  173.1112
-409.1066    3.2973  170.2714
-411.9295    5.2165  167.3716
-414.6944    7.1003  164.4131
-417.4010    8.9481  161.3972
-420.0493   10.7597  158.3247
-422.6395   12.5350  155.1964
-425.1715   14.2736  152.0132
-427.6454   15.9756  148.7757
-430.0612   17.6408  145.4845
-432.4190   19.2690  142.1402
-434.7189   20.8604  138.7429
-436.9608   22.4147  135.2931
-439.1447   23.9318  131.7910
-441.2706   25.4120  128.2364
-443.3385   26.8552  124.6293
-445.3480   28.2610  120.9698
-447.2989   29.6295  117.2580
-449.1904   30.9602  113.4948
-451.0213   32.2524  109.6813
-452.7909   33.5056  105.8189
-454.4980   34.7190  101.9089
-456.1417   35.8921   97.9527
-457.7211   37.0244   93.9516
-459.2353   38.1153   89.9071
-460.6834   39.1642   85.8208
-462.0646   40.1705   81.6937
-463.3779   41.1338   77.5277
-464.6225   42.0536   73.3243
-465.7976   42.9294   69.0848
-466.9025   43.7607   64.8109
-467.9364   44.5470   60.5041
-468.8986   45.2879   56.1661
-469.7883   45.9832   51.7986
-470.6049   46.6322   47.4030
-471.3476   47.2347   42.9811
-472.0159   47.7901   38.5346
-472.6092   48.2984   34.0652
-473.1268   48.7591   29.5745
-473.5682   49.1719   25.0645
-473.9329   49.5365   20.5368
-474.2203   49.8527   15.9930
-474.4300   50.1202   11.4351
-474.5615   50.3389    6.8650
-474.6143   50.5084    2.2844
-474.5882   50.6286   -2.3050
-474.4827   50.6994   -6.9012
-474.2975   50.7206  -11.5023
-474.0322   50.6922  -16.1064
-473.6867   50.6140  -20.7118
-473.2605   50.4858  -25.3166
-472.7536   50.3078  -29.9186
-472.1656   50.0799  -34.5160
-471.4964   49.8021  -39.1072
-470.7460   49.4742  -43.6897
-469.9142   49.0965  -48.2619
-469.0008   48.6690  -52.8219
-468.0060   48.1918  -57.3675
-466.9296   47.6651  -61.8969
-465.7716   47.0887  -66.4080
-464.5323   46.4631  -70.8990
-463.2114   45.7884  -75.3677
-461.8093   45.0648  -79.8122
-460.3261   44.2925  -84.2305
-458.7620   43.4717  -88.6207
-457.1170   42.6028  -92.9807
-455.3916   41.6862  -97.3085
-453.5859   40.7221 -101.6021
-451.7003   39.7109 -105.8596
-449.7351   38.6529 -110.0789
-447.6907   37.5486 -114.2579
-445.5675   36.3986 -118.3949
-443.3659   35.2032 -122.4877
-441.0865   33.9628 -126.5344
-438.7297   32.6781 -130.5330
-436.2961   31.3496 -134.4815
-433.7862   29.9780 -138.3779
-431.2006   28.5637 -142.2204
-428.5402   27.1074 -146.0068
-425.8054   25.6098 -149.7355
-422.9970   24.0717 -153.4043
-420.1158   22.4937 -157.0113
-417.1626   20.8766 -160.5547
-414.1381   19.2211 -164.0326
-411.0433   17.5280 -167.4430
-407.8791   15.7984 -170.7842
-404.6464   14.0329 -174.0542
-401.3461   12.2326 -177.2513
-397.9792   10.3981 -180.3737
-394.5469    8.5307 -183.4194
-391.0503    6.6313 -186.3869
-387.4902    4.7009 -189.2743
-383.8680    2.7405 -192.0799
-380.1850    0.7512 -194.8020
-376.4422   -1.2658 -197.4390
-372.6409   -3.3094 -199.9892
-368.7825   -5.3785 -202.4509
-364.8684   -7.4718 -204.8226
-360.8997   -9.5882 -207.1027
-356.8781  -11.7263 -209.2898
-352.8049  -13.8848 -211.3823
-348.6817  -16.0625 -213.3788
-344.5100  -18.2580 -215.2778
-340.2912  -20.4699 -217.0781
-336.0272  -22.6967 -218.7781
-331.7195  -24.9371 -220.3767
-327.3696  -27.1895 -221.8727
-322.9795  -29.4526 -223.2648
-318.5509  -31.7248 -224.5518
-314.0854  -34.0044 -225.7327
-309.5850  -36.2900 -226.8065
-305.0516  -38.5799 -227.7720
-300.4870  -40.8725 -228.6285
-295.8932  -43.1662 -229.3749
-291.2722  -45.4593 -230.0105
-286.6258  -47.7499 -230.5346
-281.9563  -50.0366 -230.9464
-277.2656  -52.3176 -231.2452
-272.5558  -54.5910 -231.4307
-267.8293  -56.8551 -231.5022
-263.0880  -59.1080 -231.4593
-258.3341  -61.3481 -231.3017
-253.5699  -63.5736 -231.0292
-248.7978  -65.7824 -230.6415
-244.0198  -67.9727 -230.1386
-239.2384  -70.1429 -229.5204
-234.4558  -72.2910 -228.7870
-229.6745  -74.4151 -227.9386
-224.8969  -76.5134 -226.9754
-220.1252  -78.5840 -225.8977
-215.3618  -80.6250 -224.7060
-210.6094  -82.6348 -223.4008
-205.8703  -84.6114 -221.9827
-201.1467  -86.5528 -220.4524
-196.4415  -88.4574 -218.8108
-191.7569  -90.3234 -217.0588
-187.0953  -92.1490 -215.1973
-182.4593  -93.9324 -213.2275
-177.8513  -95.6719 -211.1508
-173.2739  -97.3658 -208.9683
-168.7293  -99.0125 -206.6815
-164.2201 -100.6105 -204.2919
-159.7487 -102.1579 -201.8012
-155.3176 -103.6534 -199.2112
-150.9290 -105.0954 -196.5236
-146.5852 -106.4826 -193.7404
-142.2889 -107.8137 -190.8638
-138.0420 -109.0871 -187.8957
-133.8469 -110.3017 -184.8385
-129.7058 -111.4563 -181.6945
-125.6210 -112.5500 -178.4662
-121.5944 -113.5815 -175.1559
-117.6282 -114.5499 -171.7664
-113.7244 -115.4543 -168.3004
-109.8850 -116.2940 -164.7605
-106.1118 -117.0683 -161.1496
-102.4067 -117.7765 -157.4705
-98.7713 -118.4181 -153.7265
-95.2076 -118.9927 -149.9203
-91.7169 -119.4999 -146.0551
-88.3007 -119.9396 -142.1339
-84.9607 -120.3115 -138.1599
-81.6981 -120.6156 -134.1365
-78.5141 -120.8519 -130.0667
-75.4101 -121.0207 -125.9537
-72.3869 -121.1223 -121.8009
-69.4457 -121.1568 -117.6115
-66.5873 -121.1249 -113.3888
-63.8125 -121.0269 -109.1359
-61.1220 -120.8638 -104.8561
-58.5164 -120.6362 -100.5527
-55.9962 -120.3447  -96.2287
-53.5619 -119.9905  -91.8875
-51.2137 -119.5746  -87.5319
-48.9517 -119.0980  -83.1650
-46.7762 -118.5619  -78.7899
-44.6873 -117.9677  -74.4095
-42.6847 -117.3165  -70.0265
-40.7683 -116.6097  -65.6438
-38.9379 -115.8489  -61.2639
-37.1932 -115.0355  -56.8896
-35.5338 -114.1711  -52.5233
-33.9591 -113.2573  -48.1674
-32.4685 -112.2957  -43.8242
-31.0616 -111.2880  -39.4958
-29.7376 -110.2359  -35.1845
-28.4956 -109.1411  -30.8921
-27.3350 -108.0052  -26.6206
-26.2549 -106.8303  -22.3715
-25.2542 -105.6178  -18.1466
-24.3321 -104.3695  -13.9475
-23.4876 -103.0873   -9.7755
-22.7196 -101.7728   -5.6320
-22.0272 -100.4277   -1.5180
-21.4091  -99.0536    2.5653
-20.8644  -97.6523    6.6169
-20.3919  -96.2254   10.6359
-19.9905  -94.7744   14.6217
-19.6589  -93.3007   18.5736
-19.3963  -91.8060   22.4910
-19.2014  -90.2918   26.3733
-19.0730  -88.7591   30.2202
-19.0101  -87.2096   34.0314
-19.0116  -85.6444   37.8067
-19.0764  -84.0647   41.5458
-19.2034  -82.4717   45.2487
-19.3916  -80.8665   48.9153
-19.6399  -79.2499   52.5457
-19.9475  -77.6232   56.1400
-20.3132  -75.9869   59.6981
-20.7362  -74.3422   63.2203
-21.2156  -72.6896   66.7067
-21.7505  -71.0298   70.1576
-22.3400  -69.3634   73.5732
-22.9834  -67.6912   76.9537
-23.6799  -66.0135   80.2995
-24.4287  -64.3307   83.6106
-25.2291  -62.6433   86.8875
-26.0805  -60.9515   90.1306
-26.9821  -59.2556   93.3398
-27.9334  -57.5559   96.5156
-28.9339  -55.8525   99.6582
-29.9829  -54.1454  102.7679
-31.0799  -52.4349  105.8449
-32.2245  -50.7208  108.8893
-33.4160  -49.0033  111.9013
-34.6543  -47.2822  114.8812
-35.9387  -45.5573  117.8290
-37.2689  -43.8287  120.7448
-38.6445  -42.0962  123.6286
-40.0651  -40.3596  126.4805
-41.5304  -38.6186  129.3005
-43.0402  -36.8731  132.0885
-44.5939  -35.1228  134.8445
-46.1914  -33.3675  137.5682
-47.8323  -31.6069  140.2596
-49.5164  -29.8406  142.9185
-51.2433  -28.0684  145.5446
-53.0128  -26.2901  148.1378
-54.8246  -24.5053  150.6975
-56.6783  -22.7137  153.2235
-58.5739  -20.9149  155.7155
-60.5109  -19.1087  158.1730
-62.4891  -17.2948  160.5955
-64.5081  -15.4729  162.9827
-66.5677  -13.6427  165.3339
-68.6676  -11.8038  167.6486
-70.8075   -9.9561  169.9263
-72.9869   -8.0994  172.1662
-75.2057   -6.2333  174.3679
-77.4634   -4.3576  176.5305
-79.7596   -2.4719  178.6535
-82.0940   -0.5764  180.7361
-84.4663    1.3293  182.7777
-86.8759    3.2454  184.7773
-89.3224    5.1720  186.7343
-91.8055    7.1093  188.6479
-94.3246    9.0572  190.5172
-96.8792   11.0160  192.3415
-99.4688   12.9856  194.1199
-102.0929   14.9661  195.8516
-104.7510   16.9577  197.5356
-107.4425   18.9601  199.1713
-110.1667   20.9733  200.7576
-112.9231   22.9975  202.2938
-115.7111   25.0325  203.7789
-118.5299   27.0781  205.2120
-121.3789   29.1342  206.5924
-124.2575   31.2008  207.9191
-127.1647   33.2776  209.1913
-130.1000   35.3645  210.4080
-133.0626   37.4612  211.5685
-136.0516   39.5675  212.6719
-139.0662   41.6830  213.7173
-142.1056   43.8077  214.7039
-145.1690   45.9412  215.6309
-148.2555   48.0831  216.4974
-151.3641   50.2329  217.3028
-154.4939   52.3905  218.0462
-157.6441   54.5555  218.7267
-160.8137   56.7274  219.3438
-164.0015   58.9056  219.8966
-167.2067   61.0899  220.3845
-170.4284   63.2797  220.8068
-173.6652   65.4747  221.1627
-176.9163   67.6742  221.4517
-180.1807   69.8776  221.6731
-183.4572   72.0845  221.8263
-186.7446   74.2944  221.9108
-190.0419   76.5066  221.9259
-193.3479   78.7206  221.8712
-196.6616   80.9356  221.7462
-199.9817   83.1511  221.5505
-203.3069   85.3666  221.2834
-206.6363   87.5813  220.9447
-209.9686   89.7946  220.5340
-213.3024   92.0057  220.0509
-216.6367   94.2139  219.4951
-219.9702   96.4188  218.8662
-223.3016   98.6194  218.1641
-226.6298  100.8151  217.3885
-229.9534  103.0050  216.5392
-233.2711  105.1886  215.6161
-236.5818  107.3650  214.6189
-239.8840  109.5336  213.5476
-243.1766  111.6933  212.4022
-246.4583  113.8437  211.1826
-249.7277  115.9838  209.8888
-252.9835  118.1129  208.5209
-256.2245  120.2303  207.0788
-259.4494  122.3350  205.5628
-262.6567  124.4262  203.9730
-265.8453  126.5033  202.3095
-269.0139  128.5655  200.5724
-272.1611  130.6118  198.7622
-275.2856  132.6414  196.8791
-278.3862  134.6536  194.92];

function argyr_swing_animated()
    # Parameters:
    E = 71240.0;#MPa
    nu = 0.31;# Poisson ratio
    rho = 5.0e-9;
    b=10; h=30; L=240; #cross-sectional dimensions and length of each leg in millimeters
    utol = 1e-3;
    maxit = 30
    Fmag = 500;
    dt = 0.001;
    tend = 0.5;
    ng = 1/2; nb = 1/4*(1/2+ng)^2;
    # Choose the mass formulation:
    mass_type=1;

    # Cross-sectional properties
    cs = CrossSectionRectangle(s -> b, s -> h, s -> [0.0, 0.0, 1.0])

    # Select the number of elements per leg.
    n=4;
    tolerance=L/n/100;
    members = []
    push!(members, frame_member([0 L 0;L L 0], n, cs))
    push!(members, frame_member([L L 0;L 0 0], n, cs))
    fens, fes = merge_members(members; tolerance = tolerance);

    # Material properties
    material = MatDeforElastIso(DeforModelRed3D, rho, E, nu, 0.0)

    # Construct the requisite fields, geometry and displacement
    # Initialize configuration variables
    geom0 = NodalField(fens.xyz)
    u0 = NodalField(zeros(size(fens.xyz,1), 3))
    Rfield0 = initial_Rfield(fens)
    dchi = NodalField(zeros(size(fens.xyz,1), 6))

    # Locate some nodes
    box = fill(0.0, 6)
    # The pinned end is
    initbox!(box, [0,L,0])
    pinnedn = selectnode(fens; box = box, inflate = tolerance)
    # The force is applied at the elbow
    initbox!(box, [L,L,0])
    elbown = selectnode(fens; box = box, inflate = tolerance)
    # Tip is tracked
    initbox!(box, [L,0,0])
    tipn = selectnode(fens; box = box, inflate = tolerance)


    # Apply EBC's
    for i in [1, 2, 3]
        setebc!(dchi, pinnedn, true, i)
    end
    applyebc!(dchi)
    numberdofs!(dchi);
    dchi.dofnums

    # Additional fields
    stepdchi = deepcopy(dchi)
    u1 = deepcopy(u0)
    v0 = deepcopy(dchi) # need the numbering of the degrees of freedom
    v1 = deepcopy(dchi)
    a1 = deepcopy(dchi) # zero out the Acceleration
    a0 = deepcopy(dchi) # zero out the Acceleration
    Rfield1 = deepcopy(Rfield0)
    v0v = gathersysvec(v0)
    a0v = gathersysvec(a0)
    vpv = gathersysvec(v0);
    dchipv = gathersysvec(dchi);
    stepdchiv = gathersysvec(dchi);
    rhs = gathersysvec(dchi);
    TMPv = deepcopy(rhs)
    utol = 1e-13*dchi.nfreedofs;

    tbox = plot_space_box([[-1.5*L -0.5*L -1.5*L]; [1.5*L 2.5*L 1.5*L]])
    tshape0 = plot_solid(fens, fes; x = geom0.values, u = 0.0.*dchi.values[:, 1:3], R = Rfield0.values, facecolor = "rgb(125, 155, 125)", opacity = 0.3);
    plots = cat(tbox,  tshape0; dims = 1)
    pl = render(plots)
    sleep(0.5)

    femm = FEMMCorotBeam(IntegDomain(fes, GaussRule(1, 2)), material)
    loadbdry = FESetP1(reshape(elbown, 1, 1))
    lfemm = FEMMBase(IntegDomain(loadbdry, PointRule()))

    t = 0.0; #
    step = 0;
    while (t <= tend)
        t = t + dt;
        # println("Time $(t)"); # pause
        # Initialization
        applyebc!(dchi) # Apply boundary conditions
        u1.values[:] = u0.values[:]; # guess
        Rfield1.values[:] = Rfield0.values[:]; # guess
        stepdchi.values[:] .= 0.0;# Total increment in current step
        a1.values[:] = -(1/nb/dt)*v0.values[:] -(1/2-nb)/nb*a0.values[:];
        v1.values[:] = v0.values[:] + dt*((1-ng)*a0.values[:] + ng*a1.values[:]);
        gathersysvec!(v0, v0v)
        gathersysvec!(a0, a0v)
        dchipv = dt*v0v + (dt^2/2*(1-2*nb))*a0v
        vpv = v0v +(dt*(1-ng))*a0v;
        fi = ForceIntensity(FFlt[0, 0, (t<0.2)*((t<0.1)*t+(t>0.1)*(0.2-t))*Fmag, 0, 0, 0]);

        iter = 1;
        while true
            F = distribloads(lfemm, geom0, dchi, fi, 3);
            Fr = restoringforce(femm, geom0, u1, Rfield1, dchi);       # Internal forces
            @. rhs = F + Fr;
            K = stiffness(femm, geom0, u1, Rfield1, dchi);
            M = mass(femm, geom0, u1, Rfield1, dchi);
            G = gyroscopic(femm, geom0, u1, Rfield1, v1, dchi);
            gathersysvec!(stepdchi, stepdchiv)
            @. TMPv = ((-1/(nb*dt^2))*stepdchiv+(1/(nb*dt^2))*dchipv)
            rhs .+= M*TMPv
            @. TMPv = ((-ng/nb/dt)*stepdchiv+(ng/nb/dt)*dchipv - vpv)
            rhs .+= G*TMPv;
            dchi = scattersysvec!(dchi, (K+(ng/nb/dt)*G+(1/(nb*dt^2))*M)\rhs); # Disp. incr
            u1.values[:] += (dchi.values[:,1:3])[:];   # increment displacement
            stepdchi.values[:] += dchi.values[:]
            v1.values[:] += (ng/nb/dt)*dchi.values[:];
            a1.values[:] += (1/nb/dt^2)*dchi.values[:];
            update_rotation_field!(Rfield1, dchi)
            if maximum(abs.(dchi.values[:])) < utol # convergence check
                break;
            end
            if (iter > maxit)# bailout for failed convergence
                error("Possible failed convergence");
            end
            iter += 1;
        end
        u0.values[:] = u1.values[:];       # update the displacement
        Rfield0.values[:] = Rfield1.values[:]; # update the rotations
        v0.values[:] = v1.values[:];       # update the velocities
        a0.values[:] = a1.values[:];       # update the accelerations

        if mod(step, 4) == 0
            @show step
            tshape1 = plot_solid(fens, fes; x = geom0.values, u = u1.values, R = Rfield1.values, facecolor = "rgb(125, 15, 15)");
            plots = cat(tbox,  tshape0,  tshape1; dims = 1)
            pl.plot.layout[:title] = "t=$(round(t * 10000) / 10000)"
            react!(pl, plots, pl.plot.layout)
            sleep(0.5)
        end
        
        step=step+1;
    end

    return true
end # argyr_swing_animated

function argyr_swing_compare()
    # Parameters:
    E = 71240.0;#MPa
    nu = 0.31;# Poisson ratio
    rho = 5.0e-9;
    b=10; h=30; L=240; #cross-sectional dimensions and length of each leg in millimeters
    utol = 1e-3;
    maxit = 30
    Fmag = 500;
    dt = 0.001;
    tend = 0.5;
    ng = 1/2; nb = 1/4*(1/2+ng)^2;
    # Choose the mass formulation:
    mass_type=1;

    # Cross-sectional properties
    cs = CrossSectionRectangle(s -> b, s -> h, s -> [0.0, 0.0, 1.0])

    # Select the number of elements per leg.
    n=4;
    tolerance=L/n/100;
    members = []
    push!(members, frame_member([0 L 0;L L 0], n, cs))
    push!(members, frame_member([L L 0;L 0 0], n, cs))
    fens, fes = merge_members(members; tolerance = tolerance);

    # Material properties
    material = MatDeforElastIso(DeforModelRed3D, rho, E, nu, 0.0)

    # Construct the requisite fields, geometry and displacement
    # Initialize configuration variables
    geom0 = NodalField(fens.xyz)
    u0 = NodalField(zeros(size(fens.xyz,1), 3))
    Rfield0 = initial_Rfield(fens)
    dchi = NodalField(zeros(size(fens.xyz,1), 6))

    # Locate some nodes
    box = fill(0.0, 6)
    # The pinned end is
    initbox!(box, [0,L,0])
    pinnedn = selectnode(fens; box = box, inflate = tolerance)
    # The force is applied at the elbow
    initbox!(box, [L,L,0])
    elbown = selectnode(fens; box = box, inflate = tolerance)
    # Tip is tracked
    initbox!(box, [L,0,0])
    tipn = selectnode(fens; box = box, inflate = tolerance)


    # Apply EBC's
    for i in [1, 2, 3]
        setebc!(dchi, pinnedn, true, i)
    end
    applyebc!(dchi)
    numberdofs!(dchi);
    dchi.dofnums

    # Additional fields
    stepdchi = deepcopy(dchi)
    u1 = deepcopy(u0)
    v0 = deepcopy(dchi) # need the numbering of the degrees of freedom
    v1 = deepcopy(dchi)
    a1 = deepcopy(dchi) # zero out the Acceleration
    a0 = deepcopy(dchi) # zero out the Acceleration
    Rfield1 = deepcopy(Rfield0)
    v0v = gathersysvec(v0)
    a0v = gathersysvec(a0)
    vpv = gathersysvec(v0);
    dchipv = gathersysvec(dchi);
    stepdchiv = gathersysvec(dchi);
    rhs = gathersysvec(dchi);
    TMPv = deepcopy(rhs)
    utol = 1e-13*dchi.nfreedofs;

    reft = range(0, 0.5, length = size(tipus,1))
    plots = cat(
        scatter(;x=reft, y=tipus[:,1], mode="lines", line_color = "rgb(255, 0, 0)", name="Tip-x"),
        scatter(;x=reft, y=tipus[:,2], mode="lines", line_color = "rgb(0, 255, 0)", name="Tip-y"),
        scatter(;x=reft, y=tipus[:,3], mode="lines", line_color = "rgb(0, 0, 255)", name="Tip-z"),
        scatter(;x=reft, y=elbowus[:,1], mode="lines", line_color = "rgb(255, 0, 0)", name="Elbow-x"),
        scatter(;x=reft, y=elbowus[:,2], mode="lines", line_color = "rgb(0, 255, 0)", name="Elbow-y"),
        scatter(;x=reft, y=elbowus[:,3], mode="lines", line_color = "rgb(0, 0, 255)", name="Elbow-z"); 
        dims = 1)
    layout = Layout(width=700, height=500, xaxis=attr(title="Time"),
                     yaxis=attr(title="Displacement"))
    pl = plot(plots, layout)
    display(pl)

    femm = FEMMCorotBeam(IntegDomain(fes, GaussRule(1, 2)), material)
    loadbdry = FESetP1(reshape(elbown, 1, 1))
    lfemm = FEMMBase(IntegDomain(loadbdry, PointRule()))

    t = 0.0; #
    step = 0;
    while (t <= tend)
        t = t + dt;
        # println("Time $(t)"); # pause
        # Initialization
        applyebc!(dchi) # Apply boundary conditions
        u1.values[:] = u0.values[:]; # guess
        Rfield1.values[:] = Rfield0.values[:]; # guess
        stepdchi.values[:] .= 0.0;# Total increment in current step
        a1.values[:] = -(1/nb/dt)*v0.values[:] -(1/2-nb)/nb*a0.values[:];
        v1.values[:] = v0.values[:] + dt*((1-ng)*a0.values[:] + ng*a1.values[:]);
        gathersysvec!(v0, v0v)
        gathersysvec!(a0, a0v)
        dchipv = dt*v0v + (dt^2/2*(1-2*nb))*a0v
        vpv = v0v +(dt*(1-ng))*a0v;
        fi = ForceIntensity(FFlt[0, 0, (t<0.2)*((t<0.1)*t+(t>0.1)*(0.2-t))*Fmag, 0, 0, 0]);

        iter = 1;
        while true
            F = distribloads(lfemm, geom0, dchi, fi, 3);
            Fr = restoringforce(femm, geom0, u1, Rfield1, dchi);       # Internal forces
            @. rhs = F + Fr;
            K = stiffness(femm, geom0, u1, Rfield1, dchi);
            M = mass(femm, geom0, u1, Rfield1, dchi);
            G = gyroscopic(femm, geom0, u1, Rfield1, v1, dchi);
            gathersysvec!(stepdchi, stepdchiv)
            @. TMPv = ((-1/(nb*dt^2))*stepdchiv+(1/(nb*dt^2))*dchipv)
            rhs .+= M*TMPv
            @. TMPv = ((-ng/nb/dt)*stepdchiv+(ng/nb/dt)*dchipv - vpv)
            rhs .+= G*TMPv;
            dchi = scattersysvec!(dchi, (K+(ng/nb/dt)*G+(1/(nb*dt^2))*M)\rhs); # Disp. incr
            u1.values[:] += (dchi.values[:,1:3])[:];   # increment displacement
            stepdchi.values[:] += dchi.values[:]
            v1.values[:] += (ng/nb/dt)*dchi.values[:];
            a1.values[:] += (1/nb/dt^2)*dchi.values[:];
            update_rotation_field!(Rfield1, dchi)
            if maximum(abs.(dchi.values[:])) < utol # convergence check
                break;
            end
            if (iter > maxit)# bailout for failed convergence
                error("Possible failed convergence");
            end
            iter += 1;
        end
        u0.values[:] = u1.values[:];       # update the displacement
        Rfield0.values[:] = Rfield1.values[:]; # update the rotations
        v0.values[:] = v1.values[:];       # update the velocities
        a0.values[:] = a1.values[:];       # update the accelerations

        if (mod(step,10)==0)
            plots = cat(pl.plot.data, 
                scatter(;x=[t], y=[u1.values[tipn[1], 1]], mode="markers", line_color = "rgb(255, 0, 0)", showlegend=false),
                scatter(;x=[t], y=[u1.values[tipn[1], 2]], mode="markers", line_color = "rgb(0, 255, 0)", showlegend=false),
                scatter(;x=[t], y=[u1.values[tipn[1], 3]], mode="markers", line_color = "rgb(0, 0, 255)", showlegend=false),
                scatter(;x=[t], y=[u1.values[elbown[1], 1]], mode="markers", line_color = "rgb(255, 0, 0)", showlegend=false),
                scatter(;x=[t], y=[u1.values[elbown[1], 2]], mode="markers", line_color = "rgb(0, 255, 0)", showlegend=false),
                scatter(;x=[t], y=[u1.values[elbown[1], 3]], mode="markers", line_color = "rgb(0, 0, 255)", showlegend=false); 
                dims = 1)
            react!(pl, plots, pl.plot.layout)
            sleep(0.1)
        end

        step=step+1;
    end

    return true
end # argyr_swing_compare

function allrun()
    println("#####################################################")
    println("# argyr_swing_animated ")
    argyr_swing_animated()
    println("#####################################################")
    println("# argyr_swing_compare ")
    argyr_swing_compare()
    return true
end # function allrun


@info "All examples may be executed with "
println("using .$(@__MODULE__); $(@__MODULE__).allrun()")

end # module
nothing
