Getting error on assemble
In Python, I am trying to solve finite element methods for optimal control problems on Neumann conditions. But assemble does not work properly getting some error in line writing likes this given below
error_y = (y - y_e)*(y - y_e)*dx
error = sqrt(assemble(
print"y_
Similiar, Same way getting error in line given below
A = assemble(a, exterior_
b = assemble(L, exterior_
*******
Here Python Code for Finite element methods for optimal control problems for further clarification.
*******
from dolfin import *
from math import *
import sys
#Create mesh and define function space
nx = 32
ny = 32
y_0=0
mesh = UnitSquare (nx,ny)
X = FunctionSpace (mesh,'Lagrange',1)
Y = FunctionSpace (mesh,'Lagrange',1)
Z = X*Y
(y,p) = TrialFunctions(Z)
(si,phi) = TestFunctions(Z)
# Define Sourse values
f = Expression(
y0 = Constant ('1')
d = Constant('1') # regularize parameter
a = inner(grad(
L = f*si*dx-
#boundary
boundary_parts = MeshFunction ('uint', mesh, 1)
#Mark lower boundary facets as subdomain 0
class LowerNeumannBou
def inside(
tol = 1E-14
return on_boundary and abs(x[1]) < tol
# tolerance for coordinate comparisons
L = LowerNeumannBou
L.mark(
# Mark upper boundary facets as subdomain 1
class UpperNeumannBou
def inside(self, x, on_boundary):
tol = 1E-14
return on_boundary and abs(x[1] - 1) < tol
# tolerance for coordinate comparisons
U = UpperNeumannBou
U.mark(
#all of the Rest boundaries
class RestNeumannBoun
def inside(self, x, on_boundary):
tol = 1E-14
return on_boundary and (abs(x[0]) < tol or abs (x[0] - 1) < tol)
# tolerance for coordinate comparisons
#Verification
u=0
y_exact = Expression(
p_exact = Expression(
u_exact = Expression(
Xe = FunctionSpace(mesh, 'Lagrange', 5)
y_e = interpolate(
Ye = FunctionSpace(mesh, 'Lagrange', 5)
p_e = interpolate (p_exact, Ye,)
ze = FunctionSpace(mesh, 'Lagrange', 5)
u_e = interpolate(u_exact ,ze)
error_y = (y - y_e)*(y - y_e)*dx
error = sqrt(assemble(
print"y_
error_p = (p - p_e)*(p - p_e)*dx
error = sqrt(assemble(
print"p_
error_u = (u - u_e)*(u - u_e)*dx
error = sqrt(assemble(
print"u_
R = RestNeumannBoun
R.mark(
M= assemble(
# Compute solution
A = assemble(a, exterior_
b = assemble(L, exterior_
s = Function(Z)
solve(A,
(y,p) = s.split()
print'(y,p) :',s.vector(
print'n'
print'(y) :',y.vector(
print'n'
print'(p) :',p.vector(
print'(M) :',M.array()
B= (.5,.5)
print'y_e at the centor:',y_e(B)
print'y at the centor:',y(B)
print'p_e at the centor:',p_e(B)
print'p at the centor:',p(B)
cost=inner(
J_h=(1.
coste=inner(
J_ex=(1.
E5=abs(J_h-J_ex)
t_j=f_pv+s_pv
print'(y_m):',max (y.vector(
print'(y_em):',max (y_e_Ve.
print'(y_n):',min (y.vector(
print'(y_en):',min (y_e_Ve.
print"n"
print'f_pv:',f_pv
print's_pv:',s_pv
print'tot:',t_j
print'J_
print'J_
print'(p_m):', max(p.vector(
print'(p_em):', max(p_e_
print'(p_n):', min(p.vector(
print'(p_en):', min(p_e_
#Plot solution
plot(y,
plot(p,
plot(mesh,
interactive()
Some one help to rectify error.
Thanks
Manickam.K
Question information
- Language:
- English Edit question
- Status:
- Answered
- For:
- DOLFIN Edit question
- Assignee:
- No assignee Edit question
- Last query:
- Last reply:
Can you help with this problem?
Provide an answer of your own, or ask K.Manickam for more information if necessary.