This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Moving mesh to specific points

0 votes

I have a unit square mesh with a Dirichlet line defined by points 'a' and 'b'. I have defined a function that returns true if an input 'x' is on this line, which I input into DirichletBC. That is, something like:

def u0_boundary(x, on_boundary):
    return on_boundary or on_line(x, line_x)
bc = DirichletBC(V, u0, u0_boundary)

However, I'm having trouble getting the mesh to overlap with this line, so that the vertex is actually defined as a boundary condition.

I imagine the easiest way to do this is to adjust the mesh using mesh.move, but I'm having trouble parsing the documentation to figure out how this would work. Can I query the boundary with BoundaryMesh and append the line somehow? Do I need to manually define the mesh with MeshEditor?

Any advice would be greatly appreciated! Thank you!

asked Sep 14, 2016 by rizii FEniCS Novice (170 points)

It's not really clear from your description. What does on_line() do? It is better if you provide a minimal working example.

Yes, of course. Here's a fully functioning snippet.

from dolfin import *
import numpy as np

mesh = UnitSquareMesh(100, 100)

V = FunctionSpace(mesh, 'Lagrange', 1)
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(-1.0)
a = inner(nabla_grad(u), nabla_grad(v))*dx
L = f*v*dx
u0 = Constant(0.0)

def on_line(x):
    return abs(x[1] - 1.1*x[0]) < 1E-15
def u0_boundary(x, on_boundary):
    return on_boundary or on_line(x)

bc = DirichletBC(V, u0, u0_boundary)
u = Function(V)
solve(a == L, u, bc)

plot(u)
file = File("fenics-output.pvd")
file << u

Changing the value 1.1 in on_line to 1 aligns the values with the mesh, causing it to give the correct solution. But as is, it does not.

1 Answer

+3 votes

Ok, you can move points quite easily (in current dolfin)

mesh = UnitSquareMesh(10, 10)
for x in mesh.coordinates():
    x[0] += 0.1*x[1]

for example

answered Sep 15, 2016 by chris_richardson FEniCS Expert (31,740 points)

Thank you for the response. This helps!

...