Hi, I am slowly moving in my code from python2 to python3 version. as I hope to run the FEniCS on ubuntu using the latest FEniCS version, rather than run on docker on 2017.1.0 which is in python2.
I have this line which I multiply a vector with a variable which works fine on my docker 2017.1.0 version, w is a mixed function space I created. val_dof = dofmap.cell_dofs(0)[0] val_local = w.vector()([val_dof][0])
however, when I run the same code on the latest FeniCS version, it fails and it always gives me an error TypeError: 'float' object is not subscriptable
I google the error and use 2to3 to convert python2 to python3, and use the following line. val_local = w.vector()([val_dof][0])
the new error I got is TypeError: 'dolfin.cpp.la.PETScVector' object is not callable
Any idea I can try it out so that I can make it run on python3?
Without knowing the objective and assuming that you are just trying to extract/set the dof, consider for instance
from dolfin import *
msh = UnitSquareMesh(10, 10)
V1 = VectorElement("CG", msh.ufl_cell(), 2)
V2 = FiniteElement("CG", msh.ufl_cell(), 1)
W = FunctionSpace(msh, MixedElement([V1, V2]))
set_dof = W.dofmap().cell_dofs(0)[0]
w = Function(W)
# set/get the local dof
w.vector()[set_dof] = 1. # sets the dof at the `set_dof`-th position to 1.
Thanks for helping me out. I have tried the code you provided, it works fine and I appreciate it.
However, when I expand the code and run it on python3 in latest FEniCS version, it has an error on set_local = w.vector()[set_dof][0] TypeError: 'float' object is not subscriptable
May you give me some advice on it? I attached the code here.
Thanks for pointing it out.
When I try to print the output print([set_dof]) print([set_dof][0])
it returns [1003] 1003
so I guess the problem is with w.vector()[set_dof][0] , when I run in FEniCS 2017 it goes well, but when I use latest FEniCS version in python3, it gives the floating error.
Is there anyway I can calculate as set_local = w.vector()[set_dof][0] in a way that wont trigger the floating error?