### (Deleted) auto-adaptive poisson equation

314

views

0

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)

a = sesq_inner(grad(u_r), grad(u_i), grad(v_r), grad(v_i))*dx \

- 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 =AdaptiveLinearVariationalSolver(problem,M)

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!

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)

a = sesq_inner(grad(u_r), grad(u_i), grad(v_r), grad(v_i))*dx \

- 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 =AdaptiveLinearVariationalSolver(problem,M)

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 Answer

1

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)
a = sesq_inner(grad(u_r), grad(u_i), grad(v_r), grad(v_i))*dx \
- 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 = AdaptiveLinearVariationalSolver(problem, M)
solver.solve(tol)
solver.summary()
```

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
5 months ago by
Adam Janecka

Dear Adam Janecka.

your answer give me very great help. so I get a wonderful result. but i encounter a peoblem adopting to this method in my equation. this error is following:

M =sqrt(pow(u[0],2.0)+pow(u[1],2.0))*dx

TypeError: nb_float should return float object

I need your help! thank you

best wishes!

your answer give me very great help. so I get a wonderful result. but i encounter a peoblem adopting to this method in my equation. this error is following:

M =sqrt(pow(u[0],2.0)+pow(u[1],2.0))*dx

TypeError: nb_float should return float object

I need your help! thank you

best wishes!

written
12 weeks ago by
kevin

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

The thread is closed. No new answer/comment may be added.

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!