Create BoxField object in parallel

I am getting an error while creating a BoxField object from FEniCS function in parallel. Below is the minimum example:

“”""
from fenics import *
from boxfield import *
from dolfin import *
import numpy as np

mesh = BoxMesh(Point(0,0,0), Point(1,1,1), 10,10,10)
V = FunctionSpace(mesh, ‘Lagrange’, 1)

w = Function(V)
w_box = FEniCSBoxField(w, (10,10,10))
w_=np.zeros((11, 11, 11))
w_[:][:][:] = w_box.values

“”""

I get the following error in boxfield.py file:
“”
nodal_values[d2v] = fenics_function.vector().get_local().copy()
ValueError: shape mismatch: value array of shape (20,) could not be broadcast to indexing result of shape (46,)
“”

Is there a way to do this in parallel?
Thank you very much!

Scitools (that supplied the boxfield function) is no longer maintained. There exists a large variety of other packages for visualization, see for instance: Turning FEniCS functions into structured field - #2 by dokken and the following post.

In general, when visualizing in parallel, I would strongly recommend you to write your data to the xdmf file format, and use Paraview for post processing.

1 Like

Thank you for your reply!
Actually, I don’t need it for visualization. But I want to use the structured data in the matrix w_[:][:][:] in my code.
Is there any other way to get this structured data from FEniCS function in parallel?

To me it is not clear what the use-case is if you want the matrix. What kind of matrix do you expect to have on each process?
Note that the degrees of freedom in dolfin is distributed over multiple processes in parallel, this means that no process has access to the full 11,11,11 matrix that you are trying to create.