Vector source function from numerical nodal array

7 months ago by
I am trying to solve the following weak formulation:

   $\int_{\Omega}\left(\nabla u\cdot\nabla v\right)d\Omega=\int_{\Omega}\textbf{b}\cdot\nabla vd\Omega$Ω(u·v)dΩ=Ωb·vdΩ   

in a 3D mesh, where b is a numerical numpy array (number of nodes x 3) representing nodal values. The product inside the integral on the rhs can also be written as:
  $\sum_k\int_{\Omega}b_k\cdot\frac{\partial v_n}{\partial x_k}d\Omega$kΩbk·vnxk dΩ  for n=1,...N
N being the number of nodes per element.

I have looked at other similar questions but I still cannot wrap my head around this.
How can I write this problem in a way dolfin is able to interpret?

Thank you.
Community: FEniCS Project
How is the array b ordered? with respect to the mesh coordinates? with respect to the dofs of the function space? Maybe this answer can help you (the second part):
written 7 months ago by Miguel  
Array b is ordered in this way: b[i] corresponds to nodes[i] and so on. The question you cite did not help much :(
written 7 months ago by Semion  

1 Answer

7 months ago by
If b[i] corresponds to nodes[i] and the dofs of your function space are defined on the vertices of the mesh, consider this:

from dolfin import *
import numpy as np

mesh = BoxMesh(Point(0,0,0), Point(1,1,1), 2, 2, 2)
V = VectorFunctionSpace(mesh, "CG", 1)

# numpy array
b = np.zeros([mesh.num_vertices(), 3])
b[:,0] = 1.0    # non-zero component just in x-direction

# Vertex to dofmap
v2d = vertex_to_dof_map(V)

# reshape numpy array
b = b.reshape([len(v2d), 1])

# Fill function with the numpy values
B = Function(V)
B.vector()[v2d] = b

plot(B, interactive=True)
Please login to add an answer/comment or follow this question.

Similar posts:
Search »