# Nonlinear finite elements/Homework 1/Solutions
## Problem 1: Mathematical Model Development

Given:
* Figure 1. The motion of a pendulum
Assumptions:
* The rod and the mass at the end are rigid.
* The mass of the rod is negligible compared to the mass of the bob.
* There is no friction at the pivot.

### Solution
#### Part 1

Find the equation of motion of the bob (angular displacement as a function of time). State all other assumptions.
The component gravitational force in the direction tangent to the motion is
    $F_{x}=-mg\sin \theta ~.$
The tangential velocity of the bob is
    $v_{x}={\cfrac {ds}{dt}}={\cfrac {d}{dt}}(l\theta )=l{\cfrac {d\theta }{dt}}$
where $s$ is an arc length along the motion of the bob.
Therefore, the tangential acceleration of the bob is
    $a_{x}={\cfrac {d}{dt}}\left(l{\cfrac {d\theta }{dt}}\right)=l{\cfrac {d^{2}\theta }{dt^{2}}}~.$
From Newton's second law (balance of momentum) we have
    $F_{x}=ma_{x}\qquad \implies \qquad -mg\sin \theta =ml{\cfrac {d^{2}\theta }{dt^{2}}}~.$
Therefore the equation of motion of the bob is
    ${{\cfrac {d^{2}\theta }{dt^{2}}}+\lambda ^{2}\sin \theta =0,~\qquad \lambda ^{2}={\cfrac {g}{l}}~.}$
Additional assumptions are lack of viscosity in the surrounding medium, no wind load, and so on.

#### Part 2

Why is the equation of motion "nonlinear"?
Let us try the technique we learned in class. Let
    $A:={\cfrac {d^{2}\theta }{dt^{2}}}~;\lambda =1~.$
Then, the equation of motion can be written as
    ${A+\sin \theta =0~.}$
Without making further assumptions, this equation cannot be expressed as the equation of a line of the form
    $y=m\theta ~.$
Hence the equation of motion is nonlinear.

#### Part 4

Assume that $\theta$ is "small". Derive the equation of motion for this situation.
From elementary calculus, for small values of $\theta$ we have
    $\sin \theta \approx \theta ~.$
Therefore, for small values of $\theta$, the equation of motion becomes
    ${{\cfrac {d^{2}\theta }{dt^{2}}}+\lambda ^{2}\theta =0~.}$

#### Part 5

Why is the small $\theta$ equation of motion "linear"?
In this case we can write the differential equation as
    ${A+\theta =0~.}$
This equation can be expressed as the equation of a line of the form
    $y=m\theta ~.$
Hence the equation of motion is linear.

#### Part 6

Derive a finite element formulation for the linear equation of motion.
We know that if we can formulate the finite element system of equations for one element, we can assemble the element equations into a global system.
Let us find the finite element system of equations for one element. In this problem, we discretize the time variable into elements. Let the element extend from time $t_{1}$ to time $t_{2}$.
The first step in the process is the derivation of a approximate weak form of the differential equation.
Let $w(t)$ be a weighting function. After multiplying the ODE by the weighting function and integrating the product over the element, we get
    $\int _{t_{1}}^{t_{2}}\left({\cfrac {d^{2}\theta }{dt^{2}}}+\lambda ^{2}\theta \right)~w(t)~dt=0~.$
After integrating the first term by parts, we get
    $\left.\left({\cfrac {d\theta }{dt}}~w\right)\right|_{t_{1}}^{t_{2}}-\int _{t_{1}}^{t_{2}}{\cfrac {d\theta }{dt}}{\cfrac {dw}{dt}}~dt+\lambda ^{2}\int _{t_{1}}^{t_{2}}\theta ~w~dt=0~.$
The rearranged weak form is
    ${\int _{t_{1}}^{t_{2}}{\cfrac {d\theta }{dt}}{\cfrac {dw}{dt}}~dt-\lambda ^{2}\int _{t_{1}}^{t_{2}}\theta ~w~dt=\left.\left({\cfrac {d\theta }{dt}}~w\right)\right|_{t_{1}}^{t_{2}}~.}$
Let $\theta _{h}(t)$ be an approximate solution. To get the approximate weak form, we plug $\theta _{h}$ into the exact weak form. Notice that the right hand side of the exact weak form contains a weighted boundary lux term. We do not approximate this term because it is presumed to be specified or known exactly. In this problem, this term represents the angular velocity $\omega =d\theta /dt$. Then the approximate weak form is
    ${\int _{t_{1}}^{t_{2}}{\cfrac {d\theta _{h}}{dt}}{\cfrac {dw}{dt}}~dt-\lambda ^{2}\int _{t_{1}}^{t_{2}}\theta _{h}~w~dt=\left.\left(\omega ~w\right)\right|_{t_{1}}^{t_{2}}~.}$
At this stage we choose the form of the approximate solution. Let us assume that each element has two nodes and the approximate solution within an element has the form
    ${\theta _{h}(t)=\theta _{1}N_{1}(t)+\theta _{2}N_{2}(t)=\sum _{j=1}^{2}\theta _{j}N_{j}(t)}$
where $\theta _{1}$ is the nodal rotation at node $1$ of the element and $\theta _{2}$ is the nodal rotation at node $2$ of the element and $N_{1}$ and $N_{2}$ are the corresponding shape functions.
We have seen that instead of thinking of the weighting function as a series of the same form as $\theta _{h}(t)$, we can just consider these functions to have the form $N_{i}$ - where the index $i$ stands for a row of the finite element system of equations. Therefore, we write
    ${w=N_{i}(t)~.}$
Plug the approximate solution and the weighting function into the weak form to get
    $\int _{t_{1}}^{t_{2}}\left(\sum _{j=1}^{2}\theta _{j}{\cfrac {dN_{j}}{dt}}\right){\cfrac {dN_{i}}{dt}}~dt-\lambda ^{2}\int _{t_{1}}^{t_{2}}\left(\sum _{j=1}^{2}\theta _{j}N_{j}\right)N_{i}~dt=\left.\left(\omega ~N_{i}\right)\right|_{t_{1}}^{t_{2}}~.$
Take the summation sign and the constants outside the integral and get
    $\sum _{j=1}^{2}\left(\theta _{j}\int _{t_{1}}^{t_{2}}{\cfrac {dN_{j}}{dt}}{\cfrac {dN_{i}}{dt}}~dt\right)-\lambda ^{2}\sum _{j=1}^{2}\left(\theta _{j}\int _{t_{1}}^{t_{2}}N_{j}N_{i}~dt\right)=\left.\left(\omega ~N_{i}\right)\right|_{t_{1}}^{t_{2}}~.$
Collect terms on the left hand side
    $\sum _{j=1}^{2}\left[\theta _{j}\int _{t_{1}}^{t_{2}}\left({\cfrac {dN_{j}}{dt}}{\cfrac {dN_{i}}{dt}}-\lambda ^{2}N_{j}N_{i}\right)~dt\right]=\left.\left(\omega ~N_{i}\right)\right|_{t_{1}}^{t_{2}}~.$
Rearrange and get
    $\sum _{j=1}^{2}\left[\int _{t_{1}}^{t_{2}}\left({\cfrac {dN_{i}}{dt}}{\cfrac {dN_{j}}{dt}}-\lambda ^{2}N_{i}N_{j}\right)~dt\right]\theta _{j}=\left.\left(\omega ~N_{i}\right)\right|_{t_{1}}^{t_{2}}~.$
The above has the form
    $\sum _{j=1}^{2}K_{ij}\theta _{j}=f_{i}$
where
    ${K_{ij}=\int _{t_{1}}^{t_{2}}\left({\cfrac {dN_{i}}{dt}}{\cfrac {dN_{j}}{dt}}-\lambda ^{2}N_{i}N_{j}\right)~dt}\qquad \leftarrow ~{\text{Element stiffness matrix.}}$
and
    ${f_{i}=\left.\left(\omega ~N_{i}\right)\right|_{t_{1}}^{t_{2}}~.}\qquad \leftarrow ~{\text{Element load vector.}}$
Given the element stiffness matrix and the element load vector, we can assemble a global system of equations and solve it for the unknown values of $\theta _{i}$.
Let us assume that the shape functions are
    ${N_{1}(t)={\cfrac {t_{2}-t}{\Delta t}}\qquad {\text{and}}\qquad N_{2}(t)={\cfrac {t-t_{1}}{\Delta t}}}$
where $\Delta t=t_{2}-t_{1}$.
Then, the element stiffness matrix terms are
    ${\begin{aligned}K_{11}&=\int _{t_{1}}^{t_{2}}\left({\cfrac {dN_{1}}{dt}}{\cfrac {dN_{1}}{dt}}-\lambda ^{2}N_{1}N_{1}\right)~dt=\int _{t_{1}}^{t_{2}}\left[{\cfrac {1}{\Delta t^{2}}}-\lambda ^{2}\left({\cfrac {t_{2}-t}{\Delta t}}\right)^{2}\right]~dt={\cfrac {1}{3\Delta t}}(\lambda ^{2}\Delta t^{2}-3)\\K_{12}&=\int _{t_{1}}^{t_{2}}\left({\cfrac {dN_{1}}{dt}}{\cfrac {dN_{2}}{dt}}-\lambda ^{2}N_{1}N_{2}\right)~dt=\int _{t_{1}}^{t_{2}}\left[-{\cfrac {1}{\Delta t^{2}}}-\lambda ^{2}{\cfrac {(t-t_{1})(t_{2}-t)}{\Delta t^{2}}}\right]~dt={\cfrac {1}{6\Delta t}}(\lambda ^{2}\Delta t^{2}+6)\\K_{22}&=\int _{t_{1}}^{t_{2}}\left({\cfrac {dN_{2}}{dt}}{\cfrac {dN_{2}}{dt}}-\lambda ^{2}N_{2}N_{2}\right)~dt=\int _{t_{1}}^{t_{2}}\left[{\cfrac {1}{\Delta t^{2}}}-\lambda ^{2}\left({\cfrac {t-t_{1}}{\Delta t}}\right)^{2}\right]~dt={\cfrac {1}{3\Delta t}}(\lambda ^{2}\Delta t^{2}-3)\end{aligned}}$
The load vector terms are
    ${\begin{aligned}f_{1}&=\left.\left(\omega ~N_{1}\right)\right|_{t_{1}}^{t_{2}}=\omega (t_{2})~N_{1}(t_{2})-\omega (t_{1})~N_{1}(t_{1})=-\omega (t_{1})=:-\omega _{1}\\f_{2}&=\left.\left(\omega ~N_{2}\right)\right|_{t_{1}}^{t_{2}}=\omega (t_{2})~N_{2}(t_{2})-\omega (t_{1})~N_{2}(t_{1})=\omega (t_{2})=:\omega _{2}\\\end{aligned}}$
In matrix form:
    ${{\cfrac {1}{3\Delta t}}{\begin{bmatrix}(\lambda \Delta t)^{2}-3&(\lambda \Delta t)^{2}/2+3\\(\lambda \Delta t)^{2}/2+3&(\lambda \Delta t)^{2}-3\end{bmatrix}}{\begin{bmatrix}\theta _{1}\\\theta _{2}\end{bmatrix}}={\begin{bmatrix}-\omega _{1}\\\omega _{2}\end{bmatrix}}}$
The Maple script for getting the components of the stiffness matrix is shown below.

#### Part 7

Use ANSYS or some other tool of your choice (including your own code) to solve the linear equation of motion via finite elements. Compare with the exact solution. You can use any reasonable values for time ($t$), mass ($m$), and length ($l$).
The Matlab script for solving the problem is given below:
Comparisons are shown below between the FEM solution and the exact solution for three sets of initial conditions.
| Figure 2 (a). Comparisons between FEM and exact solution | Figure 2 (b). Comparisons between FEM and exact solution | Figure 2 (c). Comparisons between FEM and exact solution |
* When the initial angular velocity is 0 and the initial angle is nonzero, the FEM solution is close to the exact solution. This is a lucky coincidence. The total time interval has been taken to be 2.0 secs. It turns out that at exactly 2 secs, the angular velocity goes to zero and hence the problem appears as if a angular velocity boundary condition has been applied at time $t=2$ secs. You can see the problem if you increase the time interval to $t=2.2$ secs (see Figure 3).
* Figure 3. Comparisons between FEM and exact solution if t = 2.2 secs
* In problems that involve time, we usually know only the initial state but not the final state. Therefore, integrals over the total time interval cannot be evaluated easily. That is one of the reasons why we don't use finite elements to discretize time. Instead, we use techniques that directly discretize the differential operator, i.e., we work from the strong form.
* You cannot solve a problem without specifying BCs at all points on the boundary. Applying two BCs at a single point does not work unless they are for different variables.

#### Part 8

What happens when you try to solve the nonlinear equation of motion with finite elements?
In this case, the approximate weak form becomes
    $\int _{t_{1}}^{t_{2}}{\cfrac {d\theta _{h}}{dt}}{\cfrac {dw}{dt}}~dt-\lambda ^{2}\int _{t_{1}}^{t_{2}}\sin(\theta _{h})~w~dt=\left.\left(\omega ~w\right)\right|_{t_{1}}^{t_{2}}~.$
If we plug in the approximate solution, we get
    $\sum _{j=1}^{2}\left(\int _{t_{1}}^{t_{2}}{\cfrac {dN_{i}}{dt}}{\cfrac {dN_{j}}{dt}}~dt\right)\theta _{j}-\lambda ^{2}\int _{t_{1}}^{t_{2}}\sin(\theta _{h})~N_{i}~dt=\left.\left(\omega ~N_{i}\right)\right|_{t_{1}}^{t_{2}}~.$
To get a linear system of equations, we can take the $\sin \theta$ term to the right hand side.
    $\sum _{j=1}^{2}\left(\int _{t_{1}}^{t_{2}}{\cfrac {dN_{i}}{dt}}{\cfrac {dN_{j}}{dt}}~dt\right)\theta _{j}=\lambda ^{2}\int _{t_{1}}^{t_{2}}\sin(\theta _{h})~N_{i}~dt+\left.\left(\omega ~N_{i}\right)\right|_{t_{1}}^{t_{2}}~.$
At this stage we have to start with an initial guess for $\theta _{1}$ and $\theta _{2}$, plug them into the $\sin(\theta )$ term, integrate numerically and form a right hand side. We can then solve for the $\theta$ values and get a new set. We can then plug these back into the RHS and repeat the process. A straightforward linear solution is no longer possible.

## Problem 2: Numerical Exercise

Given:
Mini-centrifuge problem.
* Mini centrifuge.
Temperature range: -80 C to 100 C., RPM: 25000 .
Assumptions: Assume that the current material is a light metal (any other material of your choice will also do). The only requirement is that it should be cheap and stiff. Ignore bending and the weight of the sample tubes.
Find:
Find the thinnest beam of the material of your choice that can stand the axial load that is generated due to rotation at the new speed. Use ANSYS or your own code to solve the problem. State all simplifying assumptions.

### Solution

Let us consider one of the spokes and assume that it's a one-dimensional bar. The governing equation equation for a 1-D bar is
    $AE{\cfrac {d^{2}u}{dx^{2}}}+q=0~.$
where $q$ is a body force which has units of force per unit length.
For a rotating bar, the axial acceleration is
    $a(x)=\omega ^{2}~x$
where $\omega$ is the angular velocity of rotation (assumed constant in this case). The acceleration of the fixed end is assumed to be zero (but may not be zero for the actual centrifuge).
Therefore, the body force per unit length due to the rotation of the bar is
    $q(x)=\rho ~A~a(x)=\rho A\omega ^{2}x$
where $\rho$ is the density of the material, and $A$ is the area of cross-section.
Therefore, the governing differential equation is
    $AE{\cfrac {d^{2}u}{dx^{2}}}+\rho A\omega ^{2}x=0$
or,
    ${E{\cfrac {d^{2}u}{dx^{2}}}+\rho \omega ^{2}x=0~.}$
Clearly, the solution for the displacement does not depend on the area of cross-section of the material. Hence, the strains do not depend on the area of cross-section and therefore, neither do the stresses. However, the stresses do depend on the length.
If we assume that the width and the length of the spokes have to be maintained constant in order to hold the tubes, the thickness of the spokes cannot be optimized on the basis of inertial forces. We have to consider bending.
If we work out the finite element equations over an element for this problem, we will get
    ${\begin{aligned}K_{ij}^{e}&=\int _{x_{1}}^{x_{2}}{\cfrac {dN_{j}}{dx}}E{\cfrac {dN_{i}}{dx}}~dx\\f_{j}^{e}&=\rho \omega ^{2}\int _{x_{1}}^{x_{2}}x~N_{j}~dx\end{aligned}}$
The second equation above shows you how to apply the body forces (assuming ANSYS does not allow that - which is surprising.)
At this stage, an ANSYS solution becomes a formality that may or may not be performed.
For the ANSYS solution, let us assume that
* The material is 6061-T6 aluminum alloy.
* The density is 2790 kg/m$^{3}$.
* The Young's modulus at 100 C is 68.8 GPa.
* The Poisson's ratio is 0.35.
* The initial yield stress at -80 C is 350 MPa.
* The initial yield stress at 100 C is 250 MPa.
* The fracture strain at -80 C is 0.05.
* The fracture strain at 100 C is 0.50.
* The length is 140 mm.
* The width is 40 mm.
* The thickness is 10 mm.
Here's a sample ANSYS script for the problem

#### Results from ANSYS

Ideally you should run a convergence study at this stage to see how close your results are to the actual solution and show plots of the results.
Numbers that have five decimal places or are close to machine precision are usually useless when presented in tables.
From the axial bar problem in the learning resources, you know the exact solution for this problem, which is
    ${\begin{aligned}u(x)&={\cfrac {\rho \omega ^{2}}{6E}}(3L^{2}x-x^{3})\\\sigma (x)&={\cfrac {\rho \omega ^{2}}{2}}(L^{2}-x^{2})\end{aligned}}$
| Node | Location ($x$) (mm) | Nodal Displacement (mm) |
| 1 | 0 | 0 |
| 2 | 46.7 | 0.12 |
| 3 | 93.4 | 0.22 |
| 4 | 140 | 0.25 |
| Element | Axial stress (MPa) |
| 1 | 180 |
| 2 | 139 |
| 3 | 56 |
Here's a comparison between the exact solution and the finite element solution
* Comparison of FE and exact solutions for axial bar.
The stresses are lower than the yield stress of Aluminium, but they are close. The strains are also relatively small (approximately 0.002). The structure should hold up under the new conditions.