I am new in FEniCS and i am trying to solve a 2D time-independant Schrödinger with a parameter, the idea is to study the evolution in the energy (eigenvalues) with the increase of the parameter (in my case alpha). So, i made a loop before the definition of the variational form, created a file for print the eigenvalues and i thought that the PDE will be solve n-times, but after the first case, it stoped.
domain = Circle(Point(0,0),5.5)+Circle(Point(10,0),5.5)+Circle(Point(5,8.66),5.5)
mesh = generate_mesh(domain,8)
n = mesh.num_vertices()
d = mesh.geometry().dim()
# Create the triangulation
mesh_coordinates = mesh.coordinates().reshape((n, d))
triangles = np.asarray([cell.entities(0) for cell in cells(mesh)])
triangulation = tri.Triangulation(mesh_coordinates[:, 0],
mesh_coordinates[:, 1],
triangles)
# Plot the mesh
plt.figure()
plt.triplot(triangulation)
plt.savefig('mesh.png')
V = FunctionSpace(mesh, 'Lagrange', 1)
#build essential boundary conditions
def u0_boundary(x, on_boundary):
return on_boundary
bc = DirichletBC(V,Constant(0.0) , u0_boundary)
#define functions
u = TrialFunction(V)
v = TestFunction(V)
Pot = Expression('0.0')
alpha = 0.0
for alpha in [float(j) / 100 for j in range(0, 100, 1)]:
print alpha
terminocampoe = Expression('1*x[0]')
#define problem
a = (inner(grad(u), grad(v)) \
+ Pot*u*v + alpha*inner(terminocampoe,v))*dx
m = u*v*dx
#
A = PETScMatrix()
M = PETScMatrix()
_ = PETScVector()
L = Constant(1)*v*dx
assemble_system(a, L, bc, A_tensor=A, b_tensor=_)
assemble_system(m, L,bc, A_tensor=M, b_tensor=_)
assemble_system(m, L, A_tensor=M, b_tensor=_)
#create eigensolver
eigensolver = SLEPcEigenSolver(A,M)
eigensolver.parameters['spectrum'] = 'smallest magnitude'
eigensolver.parameters['tolerance'] = 1.e-15
#solve for eigenvalues
eigensolver.solve()
p = eigensolver.get_number_converged()
print "numero de eigenvalores", p
u = Function(V)
energiaArchivo = open('energia_campoe','w')
energiaArchivo.write(str(alpha)+' ')
energiaArchivo.close()
for i in range(0,20):
energiaArchivo = open('energia_campoe','a')
#extract next eigenpair
r, c, rx, cx = eigensolver.get_eigenpair(i)
energiaArchivo.write(str(r)+' ')
and the error is:
Traceback (most recent call last):
File "prueba_tresminf_campoe.py", line 72, in <module>
assemble_system(a, L, bc, A_tensor=A, b_tensor=_)
File "/home/adriana/.hashdist/bld/profile/mcfwu2rmfcy2/lib/python2.7/site-packages/dolfin/fem/assembling.py", line 254, in assemble_system
assembler = cpp.SystemAssembler(A_dolfin_form, b_dolfin_form, bcs)
File "/home/adriana/.hashdist/bld/profile/mcfwu2rmfcy2/lib/python2.7/site-packages/dolfin/cpp/fem.py", line 2338, in __init__
_fem.SystemAssembler_swiginit(self,_fem.new_SystemAssembler(*args))
RuntimeError:
*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
*** fenics@fenicsproject.org
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to assemble system.
*** Reason: expected a bilinear form for a.
*** Where: This error was encountered inside SystemAssembler.cpp.
*** Process: 0
***
*** DOLFIN version: 1.6.0
*** Git changeset:
*** -------------------------------------------------------------------------
I don't understand what happen. Please help me.