[SOLVED] How to give the Dirichlet boundary values correctly ? (The value needed to calculated before boundary definition )


96
views
0
4 months ago by
Hi, all

I confused by a new question, which can be expressed as follows.
I want to solve a Poisson equation, whose boundary conditions are not a function or a constant. 
 $\Delta u=f$Δu=ƒ  ; in  $\Omega$Ω  with boundary conditions    $u=g\left(\phi\right);$u=g(ϕ); on  $\partial\Omega$∂Ω   . 
The solution  $u$u is a vector.  So, the boundary condition value can be written in a form   $g=(0,\frac{d\phi}{dx})^T$g=(0,dϕdx )T  , where,  $\phi$ϕ is a function or  a solution comes from the previous step, and the superscript T is a transposition of a vector.

some example code:

grad_phi = project(grad(phi), V)
left = DirichletBC(V,(0,grad_phi[1]),Left)

AND THE ERROR:
File "/usr/lib/python2.7/dist-packages/dolfin/functions/expression.py", line 602, in __new__
mpi_comm=mpi_comm)
File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/expressions.py", line 217, in compile_expressions
mpi_comm=mpi_comm)
File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/expressions.py", line 145, in compile_expression_code
mpi_comm=mpi_comm)
File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/jit.py", line 64, in mpi_jit
return local_jit(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/dolfin/compilemodules/compilemodule.py", line 458, in compile_extension_module
**instant_kwargs)
File "/usr/lib/python2.7/dist-packages/instant/build.py", line 563, in build_module
recompile(modulename, module_path, new_compilation_checksum, build_system)
File "/usr/lib/python2.7/dist-packages/instant/build.py", line 165, in recompile
instant_error(msg % (cmd, compile_log_filename_dest))


I know the assignment, must be wrong, however, i do not know how to make it to work.


Anyone can help to make it clear?

Best, Hamilton
Community: FEniCS Project

1 Answer


1
4 months ago by
If V is a vector function space you can try something like this

left = DirichletBC(V, as_vector([0, grad_phi[0]]), Left)​
Hi, It seems to do not work.

V = VectorFunctionSpace(mesh, "Lagrange", 2); V is a VectorFcuntionSpace
TypeError: 'VectorFunctionSpace' object does not support indexing
written 4 months ago by Hamilton  
That is weird. The next example works fine for me in dolfin 2017.1

from dolfin import *

mesh = UnitSquareMesh(10,10)
V = VectorFunctionSpace(mesh, "Lagrange", 2)

# Create boundary condition
grad_phi = project(Expression(("x[0]", "x[1]"), degree=2), V)
bc = DirichletBC(V, as_vector([0, grad_phi[1]]), "on_boundary")

# Test
u = Function(V)
bc.apply(u.vector())
plot(u, interactive=True)​
written 4 months ago by Hernán Mella  
It works for me now.
I made a mistake definition.

THE METHOD WORKS!

Thanks so much

Best, Hamilton
written 4 months ago by Hamilton  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »