Esteemed,
I am studying about frequency domain and found the following page describing an example of a frequency domain problem. But in the code available there are some points that I’m not able to solve, such as the term i,j,k,l=indices(4)
, where I’ve never seen this function for fenics.
I made some modifications so I don’t need to use the .xml file and updated the mixed functions, but I still can’t run the code.
Can this code still be “updated” or is there already a better way to solve the frequency domain problem?
Follow the website: http://mypages.iit.edu/~asriva13/?page_id=779
Link with theory: http://mypages.iit.edu/~asriva13/wp-content/uploads/2015/09/Frequency-Domain.pdf
Code:
from dolfin import *
import numpy
from ufl import indices
frequency=50000
omega=2*numpy.pi*frequency
#Mesh information
#mesh = Mesh("geom.xml");
#cd=MeshFunction('size_t',mesh,"geom_physical_region.xml");
#fd=MeshFunction('size_t',mesh,"geom_facet_region.xml");
L = 0.2
H = 0.01
Nx = 200
Ny = 10
mesh = RectangleMesh(Point(0., 0.), Point(L, H), Nx, Ny)
#Function space definition over the mesh
#V = VectorFunctionSpace(mesh, "CG", 1) ##Continuous Galerkin for the displacement field
#Vcomplex = V*V
Element1 = FiniteElement("CG", mesh.ufl_cell(), 1)
Element2 = FiniteElement("CG", mesh.ufl_cell(), 1)
# Define the mixed element
V_elem = MixedElement([Element1, Element2])
# Define the mixed function space
Vcomplex = FunctionSpace(mesh, V_elem)
V0=FunctionSpace(mesh, 'DG', 0) ##Discontinuous Galerkin for the material property fields
M0=TensorFunctionSpace(mesh, 'DG', 0, shape=(2,2,2,2))
#Material properties
E, rho, nu = 300E+8, 8000, 0.3
lam=E*nu/((1+nu)*(1-2*nu))
mu=E/(2*(1+nu))
i,j,k,l=indices(4)
delta=Identity(2)
C=as_tensor((lam*(delta[i,j]*delta[k,l])+mu*(delta[i,k]*delta[j,l]+delta[i,l]*delta[j,k])),(i,j,k,l))
#Applying the Boundary conditions
zero=Constant((0.0, 0.0))
one=Constant((1.0, 0.0))
def left(x, on_boundary):
return near(x[0], 0.)
boundary = [DirichletBC(Vcomplex.sub(0), zero, left), DirichletBC(Vcomplex.sub(1), zero, left)]
#boundary = [DirichletBC(Vcomplex.sub(0), zero, fd, 12), DirichletBC(Vcomplex.sub(1), zero, fd, 12)]
#source = [DirichletBC(Vcomplex.sub(0), one, fd, 11), DirichletBC(Vcomplex.sub(1), one, fd, 11)]
#bc=boundary+source
bc=boundary
#Real and Imaginary parts of the trial and test functions
uR, uI = TrialFunctions(Vcomplex)
wR, wI = TestFunctions(Vcomplex)
strainR=as_tensor(0.5*(Dx(uR[i],j)+Dx(uR[j],i)),(i,j))
strainI=as_tensor(0.5*(Dx(uI[i],j)+Dx(uI[j],i)),(i,j))
stressR=as_tensor((C[i,j,k,l]*strainR[k,l]),[i,j])
stressI=as_tensor((C[i,j,k,l]*strainI[k,l]),[i,j])
F=omega**2*rho*(dot(uR,wR)+dot(uI,wI))*dx-(inner(stressR, grad(wR))+inner(stressI, grad(wI)))*dx
a, L = lhs(F), rhs(F)
# Set up the PDE
solnU = Function(Vcomplex)
problem = LinearVariationalProblem(a, L, solnU, bcs=bc)
solver = LinearVariationalSolver(problem)
solver.solve()
solnUR, solnUI=solnU.split()
plot(solnUI)
interactive()