# [petsc-users] Questions about vec filter and recover

Fri Mar 10 03:34:17 CST 2023

```Hi there,

I am a fresh user of Petsc, from Jiangnan University. Now I am trying to use Petsc for FEM and topology optimization.
Since I use the background pixel elements, some of elements I don't want them to be calculated, so I have to filter them out. Then after my calculation, I want to have them back.

For example, in the context of "mpiexec -np 2":
I have a Vec xPassive=[1, 1, 0, 0, 0 | 1, 1, 1, 1, 1] showing the design-able elements (1) and the not-design-able elements (0) to be filtered out. This vec is auto sliced into 5+5  by the 2 threads.
At the same time, I have a Vec density=[0.0, 0.1, 1.0, 1.0, 1.0 | 0.5, 0.6, 0.7, 0.8, 0.9].
In order to narrow down the density, I make an array and count, like resarray=[0.0, 0.1] with count=2 and resarray=[0.5, 0.6, 0.7, 0.8, 0.9] with count=5, then by the method VecCreateMPIWithArray(PETSC_COMM_WORLD, 1, count, PETSC_DECIDE, resarray, &density_new),  I get Vec density_new = [0.0, 0.1, 0.5, 0.6, 0.7, 0.8, 0.9] successfully.
Next, I put the density_new into some methods to get the new values like density_new=[0.01, 0.11, 0.51, 0.61 | 0.71, 0.81, 0.91], note that since the density_new is of size 7, it becomes 4+3 for the 2 threads.

Finally, I have to recover them as Vec density_recover=[0.01, 0.11, 1.0, 1.0, 1.0 | 0.51, 0.61, 0.71, 0.81, 0.91], in this process I fill the default 1.0 for the place where xPassive value=0.

In the last step, when I try to recover the density vector, I tried to use VecGetValues but it seems can only get local values, cannot cross threads.

I tried also to use VecScatterCreate(density_new, NULL, density_recover, idx_to, &scatter), however, my idx_to=[0, 1 | 5, 6, 7, 8, 9] and not works well like normal [0, 1, 5, 6, 7, 8, 9].
Could you help me with this please? Thank you soooooo much for your time!

Best regards,
Qingyuan HU
School of Science, Jiangnan University
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/petsc-users/attachments/20230310/282d79e0/attachment.html>
```