Defining a Dirichlet boundary condition over the vector coefficients
Hi,
I would like to solve a 1D problem where the solution is 2D vector field. One of the boundary condition is of the following kind:
a * u[0] + b * u[1] = c
where a, b and c are constant. To achieve this, I use the following penalization method.
# Create mesh and define function space
mesh = UnitInterval(32)
V = VectorFunctionS
# Define left boundary domain
def left(x):
return x[0] < DOLFIN_EPS
# Define left boundary condition
bc = DirichletBC(V, Constant((0.,0.)), left)
# Penalization for the right boundary condition
a = 1.
b = 2.
c = 4.
p = Expression("x[0] == 1.0 ? 1.e6 : 0.")
# Define functions
du = TrialFunction(V) # Incremental displacement
v = TestFunction(V) # Test function
u = Function(V) # Displacement
# Total potential energy
Pi = inner( grad(u), grad(u) )*dx + p*(a*u[
# Compute first variation of Pi (directional derivative about u in the direction of v)
f = derivative(Pi, u, v)
# Compute Jacobian of F
J = derivative(f, u, du)
# Solve variational problem
solve(f == 0, u, bc, J=J)
# Plot solution
plot(u[0])
plot(u[1])
interactive()
This works fine on this small example, but i would prefer to use Lagrange multipliers for more complex cases. Is there any way to do this with DirichletBC or any other class ?
Best regards,
Camille
Question information
- Language:
- English Edit question
- Status:
- Solved
- Assignee:
- No assignee Edit question
- Solved by:
- Anders Logg
- Solved:
- Last query:
- Last reply: