2
$\begingroup$

Looking at the stokes-iterative demo of FEniCS, after solving the linear system using

U = Function(W)
solver.solve(U.vector(), bb)

the solution U is split:

u, p = U.split()

Is there a function with which I can get the indices of Uwhich contain the u solution and the p solution? For example, if U =[u1 p1 u2 p2,...] then I would like to have the arrays

indices_u = [0,2,4,...]
indices_p = [1,3,5,...]

I'm guessing it's in FEniCS somewhere since it should be used to split the solution? I'd like to know how to do this in both C++ and python. Thanks!

$\endgroup$
7
$\begingroup$

Doing

u, p = U.split()

gives you a view into U, i.e. u, p and U share degree of freedom data. Doing

u, p = U.split(deepcopy=True)

gives a u and a p that have their own degree-of-freedom vectors. Use of shallow and deep sub-functions is demonstrated in the DOLFIN demo demo/undocumented/stokes-taylor-hood (from both C++ and Python). The syntax is a bit different from the above in C++, but is shown in the demo.

There are no guarantees on the ordering of the degrees of freedom in the underlying vector. They should, in general, be accessed via function interfaces.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.