Create an integer dolfin.la.vector

Hi all,

This is either very easy or simply impossible. I want to create a dolfin vector with integer values. Let’s say:
x = Vector(MPI.comm.world, 3)

the result will be:
[0. 0. 0.]
How can I make all 3 of these integer without needing to do it component by component?

Best,

Consider:

from dolfin import *
from mpi4py import MPI
x= Vector(MPI.COMM_WORLD, 3)
x[:] = 3
print(x.get_local())

which returns:

fenics@a946e9337d58:~/shared$ python3 vector.py 
0 [ 3.  3.  3.]
fenics@a946e9337d58:~/shared$ mpirun -n 2 python3 vector.py 
1 [ 3.]
0 [ 3.  3.]
1 Like

Thank you but these are still not integers. I know how to initialize them but no matter what you put in there it puts that decimal point in front. I need to use these vectors as an indexing vector.

Depending on you use-case, it is easy to transform a decimal value to an integer in python by int(x[i]) at evaluation.

but this is component by component. For example for a numpy array you can just say
np.array([1.2,3.2], dtype=int)
Is there a syntax like dtype that can apply to all the components of Vector at once.

No, not as far as Im aware.

just apply map(int, some_vector) to the vector entries?

If you need a PETSc structure to hold indices then you should probably use IndexSet, not a linear algebra vector.

1 Like