I am trying to solve an elasticity problem for a square domain. In my problem, the right-bottom and left-bottom corners are supported by the pin and roller supports, respectively. Also, I have fixed the displacement of the top boundary to a constant amount. After applying constant traction on the bottom boundary of the domain, I get the warning Warning: Found no facets matching domain for boundary condition.
Can you please tell me why I am getting this error? I have attached my code as below:
import numpy as np
from dolfin import *
parameters["form_compiler"]["cpp_optimize"] = True
parameters["form_compiler"]["representation"] = "uflacs"
mesh = UnitSquareMesh(4, 4)
V = VectorFunctionSpace(mesh, "CG", 1)
def bottom(x, on_boundary):
return x[1] > DOLFIN_EPS and on_boundary
def top(x, on_boundary):
return x[1] > 1 - DOLFIN_EPS and on_boundary
boundary_subdomains = MeshFunction("size_t", mesh, mesh.topology().dim() - 1)
boundary_subdomains.set_all(0)
AutoSubDomain(bottom).mark(boundary_subdomains, 1)
dss = ds(subdomain_data=boundary_subdomains)
y_BC = Expression(("x[0]", "1.2*x[1]"), degree=1)
BC1 = DirichletBC(V, y_BC, top)
def pin(x):
return x[0] < DOLFIN_EPS and x[1] < DOLFIN_EPS
def roller(x):
return x[0]-1 < DOLFIN_EPS and x[1] < DOLFIN_EPS
BC_pin = DirichletBC(V, Constant((0, 0)), pin)
BC_roller = DirichletBC(V.sub(1), Constant(0), roller)
bcs = [BC1, BC_pin, BC_roller]
# Define functions
dy = TrialFunction(V)
v = TestFunction(V)
y = Function(V)
y0 = Function(V)
y_reference = Expression(("x[0]","x[1]"),degree=1)
y.assign(project(y_reference, V)) #initial guess
T = Constant((0, -1))
def W(y):
F = grad(y)
C = F.T*F
J = det(F)
energy = 0.5*tr(C) + (J-1)**2
return energy
# Total potential energy
Pi = W(y)*dx - dot(T, (y - y_reference))*dss(1)
residual = derivative(Pi, y, v)
jacobian = derivative(residual, y, dy)
solve(residual == 0, y, bcs, J=jacobian)
Thank you so much for your response. This is solving the problem for this code, but in my main code, I am using this in Dolfin-adjoint. For that, instead of last line solve(residual == 0, y, bcs, J=jacobian) , I am using these scripts:
However, I am getting the error: TypeError: __init__() got an unexpected keyword argument 'method'
Is there any way to fix it? (I also installed dolfin-adjoint master branch using pip3 install git+https://github.com/dolfin-adjoint/pyadjoint.git and pip3 install git+https://github.com/dolfin-adjoint/pyadjoint.git@master , but the problem is not resolved.
Make sure that the installed vesion of dolfin-adjoint is the actual latest version. With the following I am able to run the script from the previous post: docker run -ti -v $PWD:/home/shared -w /home/shared --rm quay.io/fenicsproject/dev
then install pyadjoint/dolfin-adjoint as: pip3 install git+https://github.com/dolfin-adjoint/pyadjoint.git
I would suggest removing the folder /home/fenics/.local/lib/python3.8/site-packages/fenics_adjoint and reinstalling pyadjoint.
Thanks for the reply. For installing dolfin-adjoint, I have previousely used `
git clone -b libadjoint-1.6 https://bitbucket.org/dolfin-adjoint/libadjoint , which was working with Fenics that I have installed on Ubuntu. For the new version of dolfin-adjoint (Installing pyadjoint), do I need to uninstall Fenics from Ubuntu, and install it on docker? If I need to install on docker, should I install docker on Windows or virtual Ubuntu (that I was using before for running Fenics/ dolfin-adjoint)?
Libadjoint is a very old version of dolfin-adjoint, and should definitely be uninstalled before installing a new version. You do not Need to use docker to use dolfin-adjoint, I simply use docker because it makes it easy to create new environments. Use whatever system you are used to.