Turning FEniCS functions into structured field

Hi! Hope everyone is safe and healthy.

I am a little (read: very) confused with turning my solutions from FEniCS functions to BoxField objects. I really want to do that as I must work with matplotlib (for instance, show my solutions as contour plots streamplots, etc).

I will be using the poisson equation as an example, in a square domain, as well as on a circular domain. For the square domain,

#Create mesh and define function space
nx=22
ny=22

mesh = UnitSquareMesh(nx, ny)
V = FunctionSpace(mesh, 'P', 1)

and solve just as in the example ft01_poisson.py. Then, after obtaining my FEniCS function u, I write

u_box = FEniCSBoxField(u, (nx, ny))

#Set coordinates and extract values
X = 0; Y = 1
u_ = u_box.values
cv = u_box.grid.coorv

following ft10_poisson_extended.py especially line 564.

This works fine!

Now, suppose however my domain is not the one above, but rather the unit disk. In this case, I have

# Create mesh and define function space

domain = Circle(Point(0,0),1) 
mesh = generate_mesh(domain, 64)
V = FunctionSpace(mesh, 'P', 1)

How would I now represent u as a structured field? I am a little confused about how Iā€™d do this generally.

Please note that the problem I ultimately want to solve will have u (the solution) as a 3D vector, and the domain will be a cone. Suppose I have solved the Poisson equation inside the cone and I have u as a FEniCS function. How would I represent it as a structure field in order to be able to plot it with matplotlib?

Thanks! :slight_smile:

I would suggest using VTKplotter (see; New vtkplotter module for visualization) or Paraview for 3D visualization.
Note that you can plot 2D fields with matplotlib using built in dolfin functions, see for instance: https://bitbucket.org/fenics-project/dolfin/src/master/python/demo/documented/stokes-taylor-hood/demo_stokes-taylor-hood.py

3 Likes

Note that vtkplotter renamed to vedo.
I think we have an example of the above here

3 Likes