Hi

I am having trouble with implementing f.vector()[:] in C++.

In my calculation, instead of an analytical source f=Expression(‘function of x[0] and x[1]’) , I want this vector as a source for all my N nodal points. So I use the following script in python to implement the above problem

F = FunctionSpace(mesh, ‘CG’, 1) # so that dofs are only in mesh vertices

f = Function(F)

n_vertices=mesh.num_vertices()#number of vertices in a mesh

vertex_values = np.zeros(mesh.num_vertices())#Putting zeros to the number of vertics

for vert in vertices(mesh):

vertex_values[vert.index()] = vert.index()

f.vector()[:] = vertex_values[dof_to_vertex_map(F)]

## plot(f,“Source Term”)

I have tried to implement the same with C++, So I have used the following script

int n_vertices1=mesh.num_vertices();

Array vect(n_vertices1);

for( VertexIterator vert(mesh); !vert.end(); ++vert){

vect[vert->index()]= vert->index();

}

for(int i=0; i<n_vertices1; i++){

*f.vector()=vect[dof_to_vertex_map(F).at(i)];

}

plot(f,“Source term”);

L.f=f;

But I am not able to match the source term plot. I think there is problem in converting f.vector()[:] to C++.

Could you please help in that

Thanks

Waseem