I am converting from the legacy dolfin to dolfinx C++. We used set/get local values of a function vector by
std::vector<double> cell_voltages ( cells.size() );
// update cell_voltages based on reaction part, transfer to u_prev
( *u_prev.vector() ).set_local( cell_voltages );
//after solution of u, assigning back to cell_voltages
u.vector()->get_local( cell_voltages );
I have some difficulties in finding the c++ function for the get_lcoal and set_local functions in dolfinx. So far, I am using std::copy() to perform the vector value assignment.
Thanks,
In DOLFINx (v0.10.0), the suggested way of doing this is by accessing the dolfinx.la.Vector and its underlying array object:
// Fill in initial data
std::vector<T> cell_voltages(V->dofmap()->index_map->size_local());
std::iota(cell_voltages.begin(), cell_voltages.end(), 10);
// Copy data into uh
dolfinx::fem::Function<T> uh(V);
std::ranges::copy_n(cell_voltages.begin(), cell_voltages.size(),
uh.x()->array().begin());
// Inspect data
for(auto c: uh.x()->array())
std::cout << c << " ";
std::cout << "\n";
In DOLFINx, we favor using the C++ standard functions on arrays, rather than implementing our own logic for assigning data.