Warning: Found no facets matching domain for boundary condition

Hello everyone,

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)  

Your help is much appreciated!

1 Like

You need to specify that the corner BCs are to be applied pointwise, instead of the default behavior or applying them on entire facets:

BC_pin = DirichletBC(V, Constant((0, 0)), pin, method="pointwise")
BC_roller = DirichletBC(V.sub(1), Constant(0), roller, method="pointwise")
2 Likes

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:

from dolfin_adjoint import *
import moola
v = project(y, V, bcs=bcs)
J = assemble( W(y)*dx  - dot(T, (y - y_reference))*dss(1) )
J_hat = ReducedFunctional(J, Control(y))   
y_opt = minimize(J_hat, method = "L-BFGS-B", options = {"gtol": 1e-6, "ftol": 1e-16, "maxfun": 30000, "maxiter": 30000, "maxls": 40})
J_hat(y_opt)

y = Function(V)
y = project (y_opt, V, bcs=bcs)

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.

Thanks for your help.

Please make a minimal example, as I cannot reproduce this with the following minimal example:

from dolfin import *
from dolfin_adjoint import *
mesh = UnitSquareMesh(10, 10)
V = FunctionSpace(mesh, "CG", 1)
bc = DirichletBC(V, 1.0, "on_boundary", method="pointwise")
x = SpatialCoordinate(mesh)
c = Constant(2)
u = project(x[0]*c, V, bcs=[bc])

J = assemble(u**2*dx)
J_hat = ReducedFunctional(J, Control(c))
print(J_hat.derivative())

Hello Mr. Dokken, and thanks for your reply.
I tried to run your code, and I am getting the same error here. This is the output of my run:

Traceback (most recent call last):
  File "example.py", line 15, in <module>
    u = project(x[0]*c, V, bcs=[bc])
  File "/home/fenics/.local/lib/python3.8/site-packages/fenics_adjoint/projection.py", line 24, in project
    block = ProjectBlock(args[0], args[1], output, bcs, **sb_kwargs)
  File "/home/fenics/.local/lib/python3.8/site-packages/fenics_adjoint/projection.py", line 45, in __init__
    super(ProjectBlock, self).__init__(a == L, output, bcs, *args, **kwargs)
  File "/home/fenics/.local/lib/python3.8/site-packages/fenics_adjoint/solving.py", line 76, in __init__
    self._init_dependencies(*args, **kwargs)
  File "/home/fenics/.local/lib/python3.8/site-packages/fenics_adjoint/solving.py", line 152, in _init_dependencies
    self.add_dependency(bc, no_duplicates=True)
  File "/home/fenics/.local/lib/python3.8/site-packages/pyadjoint/block.py", line 51, in add_dependency
    dep._ad_will_add_as_dependency()
  File "/home/fenics/.local/lib/python3.8/site-packages/pyadjoint/overloaded_type.py", line 365, in _ad_will_add_as_dependency
    self._ad_annotate_block()
  File "/home/fenics/.local/lib/python3.8/site-packages/pyadjoint/overloaded_type.py", line 379, in _ad_annotate_block
    block = self.block_class(*self._ad_args, **self._ad_kwargs)
TypeError: __init__() got an unexpected keyword argument 'method'

Please let me know if I should check anything?

Thank you so much!

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.

1 Like

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 dolfin-adjoint), 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)?

Thanks a lot for the help!

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.

1 Like

Thank you so much for your great help! It solved my problem.