Re: [firedrake] Faster way to do this?
Hi Justin, I'm kind of surprised that the vector access is the slow bit here (as opposed to the solve), but yes, you can make this much faster. There are two ways of getting access to a numpy array containing the DoF values. One is: u.vector().array() the other is: u.dat.data (or u.dat.data_ro if you want to tell PyOP2 you're not going to change the data). The two are essentially equivalent for scalar Functions. For functions in a VectorFunctionSpace the dat version returns a 2D array while vector() is flattened to 1D. Regards, David On Tue, 20 Oct 2015 at 23:07 Justin Chang <jychang48@gmail.com> wrote:
Hi all,
I am currently writing my own point-wise petsc4py solver which needs data that lives in u = Function(Q), where Q is of type CG1 (i.e., a P1 element, same as the coordinates).
Right now I am doing something like this:
for i in range(mesh.num_vertices()): FormInitialGuess(u.vector()[i]) Solve(...) ...
but it seems the u.vector()[i] operation is extremely slow. Is there a faster or more efficient way of calling or extracting pointwise values?
Thanks, Justin
participants (1)
-
David Ham