Boundaries/ mesh

Hello,

I have 3 boxes (one inside the other) and I am trying to apply boundary conditions on points on the upper side of the outside box. For example I would like to apply boundary conditions on points were -2<x<2 (with step 1) , y=0, z=2

import matplotlib.pyplot as plt
from dolfin import *
from vtkplotter.dolfin import datadir, plot
import numpy as np

mesh = Mesh(“dolfinmesh.xml”)
mesh_file_volume = MeshFunction(‘size_t’, mesh ,“dolfinmesh_volume_meshvalue.xml”)
mesh_file_boundary = MeshFunction(‘size_t’ , mesh , “dolfinmesh_bcfunc.xml”)

V = FunctionSpace(mesh, “Lagrange”, 1)

Please supply a minimal working example that illustrates what you would like to achieve.

Note that there are many examples on how to apply boundary conditions on the forum. See for instance: Transitioning from mesh.xml to mesh.xdmf, from dolfin-convert to meshio

Please format your problem using ```, and remove all unnecessary code such that it is easy to see what your issue is. For instance consider using a built-in UnitSquareMesh, and apply a boundary condition on it, such as shown in the Poisson demo:
https://bitbucket.org/fenics-project/dolfin/src/master/python/demo/documented/poisson/demo_poisson.py.rst

Sorry for my previous inaccurate posts,

Basically I have a 3D box and I want to apply boundary conditions on the specific points that I mention inside the bc1, bc2, bc3, bc4,…bc9
The points are:
(x, y, z)
2, 0, 2
1.5, 0, 2
0.5, 0, 2
0, 0, 2
-0.5, 0, 2
-1, 0, 2
-1.5, 0, 2
-2, 0, 2

import matplotlib.pyplot as plt
from dolfin import *
import numpy as np

mesh = Mesh(“dolfinmesh.xml”)
mesh_file_volume = MeshFunction(‘size_t’, mesh ,“dolfinmesh_volume_meshvalue.xml”)
mesh_file_boundary = MeshFunction(‘size_t’ , mesh , “dolfinmesh_bcfunc.xml”)

V = FunctionSpace(mesh, “Lagrange”, 1)

‘’’’
bc1 = DirichletBC(V, Constant(2.46),“near(x[0] , 2.0) && x[1] == 0.0 && x[2] == 2.0”,“pointwise”)
bc2 = DirichletBC(V, Constant(2.43),“near(x[0] , 1.5) && x[1] == 0.0 && x[2] == 2.0”,“pointwise”)
bc3 = DirichletBC(V, Constant(2.3),“near(x[0], 1.0) && x[1] == 0.0 && x[2] == 2.0”,“pointwise”)
bc4 = DirichletBC(V, Constant(2.6),“near(x[0], 0.5) && x[1] == 0.0 && x[2] == 2.0”,“pointwise”)
bc5 = DirichletBC(V, Constant(4.3),“near(x[0], 0.0) && x[1] == 0.0 && x[2] == 2.0”,“pointwise”)
bc6 = DirichletBC(V, Constant(2.44),“near(x[0], -0.5) && x[1] == 0.0 && x[2] == 2.0”,“pointwise”)
bc7 = DirichletBC(V, Constant(2.43),“near(x[0], -1.0) && x[1] == 0.0 && x[2] == 2.0”,“pointwise”)
bc8 = DirichletBC(V, Constant(2.55),“near(x[0], -1.5) && x[1] == 0.0 && x[2] == 2.0”,“pointwise”)
bc9 = DirichletBC(V, Constant(2.69),“near(x[0], -2.0) && x[1] == 0.0 && x[2] == 2.0”,“pointwise”)

bcs = [bc1, bc2, bc3, bc4, bc5, bc6, bc7, bc8, bc9]

‘’’’’

Define variational problem

u = TrialFunction(V)
v = TestFunction(V)
a = inner(Cgrad(u), grad(v))dx
f = Constant(0.0)
L = f
v
dx
A, b = assemble_system(a, L, bcs)
u_k = Function(V)
solve(A, u_k.vector(), b, ‘lu’)

File(‘saved_u.xml’) << u_k
file = File(“final2.pvd”)
file << u_k

All the above seem not to work.

Are the points vertices of your mesh? Otherwise you cannot apply pointwise BCs to them. A pointwise bc will add the condition to the single dof at that location, if there is no dof there, there will be no boundary condition.

They are not vertices of my mesh. Is there any other way that I can apply on those points boundary conditions?

You can approximate a dirac delta function in that region, Implement point source in the variational formulation
Note that this will not be 100% accurate, and will work better on a finer mesh.

The optimal solution is to ensure vertices at the points you want to apply a boundary condition on.

You can Also find the Closest degree of freedom to that point, see: How can I find the closest node to an arbitrary coordinates?

Thank you very much for your help!