Hi.
I have the following problem: Consider the following matrix in a 3d Poisson equation problem: (x_i, y_i, z_i, bc_i). The (x_i, y_i, z_i) are the bounds of a 3d mesh and bc_i is the relevant boundary conditions. So, consider now making the 3d mesh and perform a numerical calculation to find the bc_i values of each boundary point (x_i, y_i, z_i).
Using those boundary conditions, I would like to use fenicsx to solve the Poisson equation in the whole mesh.
I have solved this problem some years ago in the legacy fenics as follows, with the help of a dictionary variable. Please see the example code. First, I find the boundaries of my geometry
# Calculate the boundary data
# Define the mesh of the boundary
boundary_mesh = BoundaryMesh(mesh, 'exterior')
# Create an array with the node points
boundary_nodes = boundary_mesh.coordinates()
# Dimension of the array
length = np.shape(boundary_nodes)[0]
# Create the points data from the mesh
x_boundary, y_boundary, z_boundary = np.zeros(length), np.zeros(length), np.zeros(length)
x_boundary, y_boundary, z_boundary = [boundary_nodes[i][0] for i in range(length)], [boundary_nodes[i][1] for i in range(length)], [boundary_nodes[i][2] for i in range(length)]
Then I ran the numerical calculation to find the values bc_i. Then I use the following functions and dictionary to “feed” the boundary conditions in legacy fenics:
def bound_dictionary(x,y,z,dictionary):
try:
dictionary[(x,y,z)]
except KeyError:
b=0
else:
a=dictionary[(x,y,z)]
return a
class BCfunction_dictionary(UserExpression):
def eval(self, value, x):
value[0] = bound_dictionary(x[0],x[1],x[2],dictionary)
def value_shape(self):
return ()
dictionary = {(x_boundary[i], y_boundary[i], z_boundary[i]): bc[i] for i in range(length)}
u_D = BCfunction_dictionary()
def boundary(x, on_boundary):
return on_boundary
bc = DirichletBC(V, u_D, boundary)
# Define variational problem
u_x = TrialFunction(V)
v = TestFunction(V)
f = Constant(0)
a = dot(grad(u_x), grad(v))*dx
L = f*v*dx
# Compute solution
u_x = Function(V)
solve(a == L, u_x, bc)
u=np.array(u_x.compute_vertex_values(mesh))
Obviously, it is not elegant, but it works.
Now to my question: what your suggestions for implementing this type of calculation in fenicsx are?
So far, I have found how to find in fenicsx the boundary points, but I am not sure of how to proceed from here. I am not sure how to write the appropriate function.