Edit values of a dolfin::Function at certain co-ordinates (C++)

#1

Hi,
My problem requires me to perform a transformation on the solved values of a dolfin::Function at certain coordinates in the domain.

Some examples are available for Python, namely the answer by MiroK

I would like to perform similarly in C++.

I have extracted the coordinates from the mesh by

auto co_ordinates = mesh->coordinates();

and the Generic vector from Function as

auto E_vec = E->vector();

There are two methods namely get_local() and set_local() respectively which could facilitate me in modifying the values. But I am not really sure about the input parameters to that function.

Any alternate methods to achieve this is also highly appreciated.

#2

Hi,

an example that I use to set negative values in a vector of a function is shown below, which illustrates the usage of get_local() and set_local():

uvals = u.vector().get_local()     # temporary copy of function value arrays
uvals[uvals < 0.] = 0.               # numpy syntax for overwriting negative values
u.vector().set_local(uvals)        # overwrite function values with corrected array

This in the end returns a Dolfin function again with the corrected values. I think the notation of get/set_local will be the same in C++.
Hope this helps

#3

Thank you. I thought the same.

But, the dolfin::Function.vector() returns a reference to dolfin::GenericVector.

The get_local() method of the GenericVector has a declaration of

void get_local(double* block, const dolfin::la_index* num_rows, const dolfin::la_index* const* rows) const

I am not sure what these input parameters exactly mean.