### How can I define smallest singular value and smallest eigen value in fenics

62

views

0

Hi,

I am trying to find both smallest singular value (SV) and smallest eigenvalue of my stiffness matrix. I know how can I save my stiffness matrix as .m file but Matlab cannot calculate SV and eig for big matrix that's why im looking for a way to do that in fenics.

Thanks.

I am trying to find both smallest singular value (SV) and smallest eigenvalue of my stiffness matrix. I know how can I save my stiffness matrix as .m file but Matlab cannot calculate SV and eig for big matrix that's why im looking for a way to do that in fenics.

Thanks.

```
import dolfin
from dolfin import *
import scipy
from scipy.linalg import sqrtm
from petsc4py import PETSc
from numpy import array2string
import numpy as np
import sys
import time
import mshr
start_time = time.time()
# Create mesh
mesh = UnitSquareMesh(25, 25)
# Define function spaces
BDM = VectorElement("BDM", mesh.ufl_cell(), 2, dim=2)
CG = VectorElement("CG", mesh.ufl_cell(), 2, dim=2)
element = MixedElement([CG, BDM])
V = FunctionSpace(mesh, element)
w = Function(V)
#Define DOFs
Gdof = V.dim()
Z ,Q = TrialFunctions(V)
yup ,R = TestFunctions(V)
ncells = [ mesh.num_vertices(), mesh.num_edges(), mesh.num_faces(), mesh.num_facets(), mesh.num_cells() ]
# Define bilinear form and right hand side
a = (dot(Q[0], grad(yup[0])) + dot(Q[1], grad(yup[1])) \
+ dot(Z[0], yup[0]) + dot(Z[1], yup[1]) + dot(grad(Z[0]), grad(yup[0])) + dot(grad(Z[1]), grad(yup[1])) \
+ dot(Q[0], R[0]) + dot(Q[1], R[1]) + ((div(Q[0]) * div(R[0]))) + ((div(Q[1]) * div(R[1]))))*dx
#####################################################
print('Global_DOF',Gdof)
matA = assemble(a)
# Possiblity 1:
# Produce Matlab/Octave data file. This writes out an ASCII representation
# of the sparse matrix that can be read in via Matlab/Octave and manipulated
# as needed.
print(ncells)
viewer = PETSc.Viewer().createASCII("T25.m","w")
viewer.pushFormat(PETSc.Viewer.Format.ASCII_MATLAB)
viewer(as_backend_type(matA).mat())
#interactive()
```

Community: FEniCS Project

Please login to add an answer/comment or follow this question.