# Modal Analysis of the beam structure

**URL:** <https://fenicsproject.discourse.group/t/modal-analysis-of-the-beam-structure/6651>\
**Category:** Uncategorized\
**Created:** [September 23, 2021, 6:03am UTC](https://fenicsproject.discourse.group/t/modal-analysis-of-the-beam-structure/6651 "2021-09-23T06:03:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gunasheela](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/gunasheela/32/2573_2.png) [@Gunasheela](https://fenicsproject.discourse.group/u/Gunasheela)\
**Post date:** [September 23, 2021, 6:03am UTC](https://fenicsproject.discourse.group/t/modal-analysis-of-the-beam-structure/6651/1 "2021-09-23T06:03:20Z")

</div>

Hi,  
I am currently working on a modal analysis of beam structure. In the postprocessing part, I am able to save my results in XDMF file format. Once I import the xdmf file format into ParaView, am only able to see the first eigenvector, am not able to visualize the other 5 eigenvectors. Can anyone guide me with this?. I have also attached my code below.

from dolfin import \*

import numpy as np  
import matplotlib.pyplot as plt

L, B, H = 20., 0.5, 1.  
Nx = 200  
Ny = int(B/L_Nx)+1  
Nz = int(H/L_Nx)+1  
mesh = BoxMesh(Point(0.,0.,0.),Point(L,B,H), Nx, Ny, Nz)

# Material parameters and elastic constitutive relations

E, nu = Constant(1e5), Constant(0.)  
rho = Constant(1e-3)

# Lame coefficient for constitutive relation

mu = E/2./(1+nu)  
lmbda = E_nu/(1+nu)/(1-2_nu)

def eps(v):

```
return sym(grad(v))

```

def sigma(v):

```
dim = v.geometric_dimension()

return 2.0*mu*eps(v) + lmbda*tr(eps(v))*Identity(dim)

```

# Standard FunctionSpace is defined and boundary conditions correspond to a fully clamped support at :math:`x=0`::

V = VectorFunctionSpace(mesh, ‘Lagrange’, degree=1)  
u\_ = TrialFunction(V)  
du = TestFunction(V)

def left(x, on\_boundary):

```
return near(x[0],0.)

```

bc = DirichletBC(V, Constant((0.,0.,0.)), left)

# The system stiffness matrix :math:`[K]` and mass matrix :math:`[M]` are respectively obtained from assembling the corresponding variational forms::

k\_form = inner(sigma(du),eps(u\_))\*dx  
l\_form = Constant(1.)\*u\_[0]_dx  
K = PETScMatrix()  
b = PETScVector()  
assemble\_system(k\_form, l\_form, bc, A\_tensor=K, b\_tensor=b)  
m\_form = rho_dot(du,u\_)\*dx  
M = PETScMatrix()  
assemble(m\_form, tensor=M)

# Matrices :math:`[K]` and :math:`[M]` are first defined as PETSc Matrix and forms are assembled into it to ensure that they have the right type.

eigensolver = SLEPcEigenSolver(K, M)  
eigensolver.parameters[‘problem\_type’] = ‘gen\_hermitian’  
eigensolver.parameters[‘spectral\_transform’] = ‘shift-and-invert’  
eigensolver.parameters[‘spectral\_shift’] = 0.  
N\_eig = 6 # number of eigenvalues  
#print(“Computing {} first eigenvalues…”.format(N\_eig))  
eigensolver.solve(N\_eig)

# Post-process

# Set up file for exporting results

file\_results = XDMFFile(“MA.xdmf”)  
file\_results.parameters[“flush\_output”] = True  
file\_results.parameters[“functions\_share\_mesh”] = True

# Eigenfrequencies

for i in range(N\_eig):  
r, c, rx, cx = eigensolver.get\_eigenpair(i)

```
# Calculation of eigenfrequency from real part of eigenvalue

freq_3D = sqrt(r)/2/pi

print("Eigenfrequency: {0:8.5f} [Hz]".format(freq_3D))

# Initialize function and assign eigenvector

eigenmode = Function(V, name="Eigenvector " + str(i))
eigenmode.vector()[:] = rx

# Write i-th eigenfunction to xdmf file

file_results.write(eigenmode, i)

```

---

<div class="post-metadata">

**Author:** ![bleyerj](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/bleyerj/32/6020_2.png) [@bleyerj](https://fenicsproject.discourse.group/u/bleyerj)\
**Post date:** [September 23, 2021, 7:14am UTC](https://fenicsproject.discourse.group/t/modal-analysis-of-the-beam-structure/6651/2 "2021-09-23T07:14:05Z")

</div>

Hi,  
using

```auto
file_results.write(eigenmode, i)

```

will output each vector to a different time step with time t=i. Replace i with 0 to have all eigenvectors at a single time step.
