#. # Five natural modes of a cantilevered wire
#.
#. Back in [college](https://www.ib.edu.ar/), we had this subject Experimental Physics\ 101.
#. I had to measure the natual modes of two cantilevered wires and determine the
#. Young modulus of of those measurements. The [report is here](https://www.seamplex.com/fino/doc/alambre.pdf).
#. Two comments:
#
#.  1. It is in Spanish
#.  2. There was a systematic error and a factor of two sneaked in into the measured values
#.
#. Here is a finite-element version of the experimental setup with a comparison to then
#. theoretical values written directly as Markdown tables. The material (either aluminum or copper)
#. and the mesh type (either tet or hex) and be chosen at runtime through command line arguments.
#. 
#$ $ gmsh -3 wire-hex.geo
#$ [...]
#$ Info    : Done meshing order 2 (Wall 0.0169025s, CPU 0.016804s)
#$ Info    : 8398 nodes 4676 elements
#$ Info    : Writing 'wire-hex.msh'...
#$ Info    : Done writing 'wire-hex.msh'
#$ Info    : Stopped on Fri Dec 24 17:07:19 2021 (From start: Wall 0.0464517s, CPU 0.133498s)
#$ $ gmsh -3 wire-tet.geo
#$ [...]
#$ Info    : Done optimizing mesh (Wall 0.0229018s, CPU 0.022892s)
#$ Info    : 16579 nodes 13610 elements
#$ Info    : Writing 'wire-tet.msh'...
#$ Info    : Done writing 'wire-tet.msh'
#$ Info    : Stopped on Fri Dec 24 17:07:59 2021 (From start: Wall 2.5798s, CPU 2.64745s)
#$ $ feenox wire.fee 
#$   $n$   |    FEM [Hz]   |   Euler [Hz]  |  Relative difference [%]
#$ :------:|:-------------:|:-------------:|:--------------:
#$ 1       |       45.84   |       45.84   |       0.02
#$ 2       |       287.1   |       287.3   |       0.06
#$ 3       |       803.4   |       804.5   |       0.13
#$ 4       |       1573    |       1576    |       0.24
#$ 5       |       2596    |       2606    |       0.38
#$ 
#$ : copper wire over hex mesh
#$ 
#$   $n$   |          $L$          |       $\Gamma$        |      $\mu$    |       $M$
#$ :------:+:---------------------:+:---------------------:+:-------------:+:--------------:
#$ 1       |       +1.3e-03        |       +4.2e-01        |       0.1371  |       0.1371
#$ 2       |       -1.8e-03        |       -5.9e-01        |       0.2716  |       0.4087
#$ 3       |       +9.1e-05        |       +1.7e-02        |       0.0004  |       0.4091
#$ 4       |       -1.7e-03        |       -3.0e-01        |       0.1252  |       0.5343
#$ 5       |       -3.3e-05        |       -5.9e-03        |       0.0000  |       0.5343
#$ 6       |       -9.9e-04        |       -1.8e-01        |       0.0431  |       0.5775
#$ 7       |       +7.3e-04        |       +1.2e-01        |       0.0221  |       0.5995
#$ 8       |       +4.5e-06        |       +7.5e-04        |       0.0000  |       0.5995
#$ 9       |       +5.4e-04        |       +9.9e-02        |       0.0134  |       0.6129
#$ 10      |       +2.7e-05        |       +4.9e-03        |       0.0000  |       0.6129
#$ 
#$ : copper wire over hex mesh, participation and excitation factors $L$ and $\Gamma$, effective per-mode and cummulative mass fractions $\mu$ and $M$
#$ $ feenox wire.fee hex copper | pandoc -o wire-hex-copper.html
#$ $ feenox wire.fee tet copper | pandoc -o  wire-tet-copper.md
#$ $ feenox wire.fee hex aluminum | pandoc -o  wire-hex-aluminum.md
#$ $ feenox wire.fee tet aluminum | pandoc -o  wire-tet-aluminum.md
DEFAULT_ARGUMENT_VALUE 1 hex       # mesh, either hex or unstruct
DEFAULT_ARGUMENT_VALUE 2 copper    # material, either copper or aluminum

l = 0.5*303e-3   # cantilever wire length [ m ]
d = 1.948e-3     # wire diameter [ m ]


# material properties for copper
m_copper = 0.5*8.02e-3  # total mass (half the measured because of the experimental disposition) [ kg ]
E_copper = 2*66.2e9     # [ Pa ] Young modulus (twice because the factor-two error)

# material properties for aluminum
m_aluminum = 0.5*2.67e-3
E_aluminum = 2*40.2e9

# problem’s properties
E = E_$2                     # [ MPa ]
rho = m_$2/(pi*(0.5*d)^2*l)  # [ kg / m^3 ] density = mass (measured) / volume 
nu = 0                       # Poisson’s ratio (does not appear in Euler-Bernoulli)

# analytical solution
VECTOR kl[5]
VECTOR f_euler[5]

# first compute the first five roots ok cosh(kl)*cos(kl)+1 
kl[i] = root(cosh(t)*cos(t)+1, t, 3*i-2,3*i+1)

# then compute the frequencies according to Euler-Bernoulli
# note that we need to use SI inside the square root
A = pi * (d/2)^2
I = pi/4 * (d/2)^4
f_euler[i] = 1/(2*pi) * kl(i)^2 * sqrt((E * I)/(rho * A * l^4))

# now compute the modes numerically with FEM
# note that each mode is duplicated as it is degenerated
READ_MESH wire-$1.msh DIMENSIONS 3
PROBLEM modal MODES 10
BC fixed fixed
SOLVE_PROBLEM

# github-formatted markdown table
# compare the frequencies
PRINT "  \$n\$   |    FEM [Hz]   |   Euler [Hz]  |  Relative difference [%]"
PRINT   ":------:|:-------------:|:-------------:|:--------------:"
PRINT_VECTOR SEP "\t|\t" i  %.4g f(2*i-1) f_euler   %.2f 100*(f_euler(i)-f(2*i-1))/f_euler(i)
PRINT
PRINT ": $2 wire over $1 mesh"

# commonmark table
PRINT
PRINT "  \$n\$   |          \$L\$          |       \$\\Gamma\$        |      \$\\mu\$    |       \$M\$"
PRINT   ":------:+:---------------------:+:---------------------:+:-------------:+:--------------:"
PRINT_VECTOR SEP "\t|\t" i "%+.1e" L Gamma "%.4f" mu Mu  
PRINT
PRINT ": $2 wire over $1 mesh, participation and excitation factors \$L\$ and \$\\Gamma\$, effective per-mode and cummulative mass fractions \$\\mu\$ and \$M\$"

# write the modes into a vtk file
WRITE_MESH wire-$1-$2.vtk \
 VECTOR u1 v1 w1 VECTOR u2 v2 w2 VECTOR u3 v3 w3 \
 VECTOR u4 v4 w4 VECTOR u5 v5 w5 VECTOR u6 v6 w6 \
 VECTOR u7 v7 w7 VECTOR u8 v8 w8 VECTOR u9 v9 w9 VECTOR u10 v10 w10

# and into a msh file
WRITE_MESH wire-$1-$2.msh {
 u1 v1 w1
 u2 v2 w2
 u3 v3 w3
 u4 v4 w4
 u5 v5 w5
 u6 v6 w6
 u7 v7 w7
 u8 v8 w8
 u9 v9 w9
 u10 v10 w10
}
#> ```include
#> wire-hex-copper.md
#> wire-tet-copper.md
#> wire-hex-aluminum.md
#> wire-tet-aluminum.md
#> ```
