454
views
0
12 months ago by
Hello everyone:
I am trying slove a poisson equation comtained complex compute by using auto adaptive,my code is following:

from dolfin import*
def sesq_inner(u_r, u_i, v_r, v_i):
re_part = inner(u_r, v_r) + inner(u_i, v_i)
im_part = -inner(u_r, v_i) + inner(u_i, v_r)
return re_part + im_part
mesh =UnitSquareMesh(4,4)
V = VectorFunctionSpace(mesh,"CG", 2)

u_r,u_i = TrialFunction(V)
v_r,v_i=TestFuction(V)

omega = Constant(4.0*pi)

- omega**2*sesq_inner(u_r, u_i, v_r, v_i)*dx

l = Constant(1.0)*v_r*dx
F=a+l
A=lhs(F)
L=rhs(F)

bcs = [DirichletBC(V, Constant((1.0,0.0)), "near(x[1], 0.0)")] # Imaginary BC
u = Function(V)
M =u*dx
tol=1e-6
problem = LinearVariationalProblem(A,L,u,bcs)
solver.solve(tol)
solver.summary()
interactive()

but i don't know how to choose goal function(M=u*dx)? or how to solve the complex poission equation by auto-adaptive

Best wishes!
Community: FEniCS Project

1
10 months ago by
Hopefully, this works for you:
from fenics import *

def sesq_inner(u_r, u_i, v_r, v_i):
re_part =  inner(u_r, v_r) + inner(u_i, v_i)
im_part = -inner(u_r, v_i) + inner(u_i, v_r)
return re_part + im_part

mesh = UnitSquareMesh(4, 4)
V = VectorFunctionSpace(mesh, 'P', 2)

(u_r, u_i) = TrialFunctions(V)
(v_r, v_i) = TestFunctions(V)

omega = Constant(4.0*pi)

- omega**2*sesq_inner(u_r, u_i, v_r, v_i)*dx

l = Constant(1.0)*v_r*dx
F = a + l

A = lhs(F)
L = rhs(F)

bc = DirichletBC(V, Constant((1.0, 0.0)), 'near(x[1], 0.0)')

u = Function(V)
M = sqrt(pow(u[0], 2.0) + pow(u[1], 2.0))*dx
tol = 1.0e-4

problem = LinearVariationalProblem(A, L, u, bc)
solver.solve(tol)
solver.summary()​
Thanks for your reply! I get a good result .  However in the plot(u_r.root_node(), title="Solution on initial mesh")

plot(u_r.leaf_node(), title="Solution on final mesh"), appear the error"AttributeError: 'Indexed' object has no attribute 'root_node'".
I should plot the first result and final result?  Thank you!
written 10 months ago by kevin
For exmaple, to plot u_r you might use:
plot(u.root_node().sub(0), title="Solution on initial mesh")
plot(u.leaf_node().sub(0), title="Solution on final mesh")​
written 10 months ago by Adam Janecka