How to plot 2D cross-sections ? (Unable to install fenicstools and scitools)

Hello, I hope this isn’t a known issue, I didn’t find anything about it on the forum.
I computed some 3D solution in a given domain, and I wanted to plot a 2D cross-section of that solution in Jupyter-Notebook.

I found this topic : https://fenicsproject.org/qa/2775/visualization-of-2d-cross-sections-from-3d-mesh-solution/ ; and saw that it could be handled with fenicstools and scitools

However, when i tried to install those two module (pip3 install fenicstools and pip3 install scitools), I got the following errors respectively:
“Client Error: Not Found for url: https://pypi.org/simple/fenicstools/
“Could not find a version that satisfies the requirement scitools (from versions: )
No matching distribution found for scitools”

Does anyone know how to solve this?

Thanks a lot!
Grepnas.

I don’t know about doing it inside jupyter, but an alternative approach is to save your solution to an xdmf file and then use paraview to get your cross-section.

1 Like

Fenicstools has not been updated since 2017. I would suggest going with @dparsons approach and save the function to xdmf and use Paraview.

It might be that vtkplotter can handle cross sections, I recommend checking the documentation.

2 Likes

Thanks for the answer :smiley:
I tried and it works fine, I would’ve loved to plot it inside jupyter but I think it’ll do !

That’s a shame for Fenicstools :frowning: I tried to use vtkplotter but I am having trouble making it work on Jupyter for some reason so I’ll go for @dparsons’ solution,
Thank you both :smiley:

1 Like

@marcomusy might know about getting vtkplotter working in jupyter.

2 Likes

this should work… you can make pop up a vtk rendering window or embed the output in the notebook (using k3d) with a little hack:

from dolfin import *

# Create mesh and define function space
mesh = UnitCubeMesh(10, 10, 10)
V = VectorFunctionSpace(mesh, "Lagrange", 1)

# Mark boundary subdomains
left  = CompiledSubDomain("near(x[0], side) && on_boundary", side=0.0)
right = CompiledSubDomain("near(x[0], side) && on_boundary", side=1.0)

# Define Dirichlet boundary (x=0 or x=1)
c = Constant((0.0, 0.0, 0.0))
r = Expression((
        "scale*0.0",
        "scale*(y0 + (x[1]-y0)*cos(theta) - (x[2]-z0)*sin(theta)-x[1])",
        "scale*(z0 + (x[1]-y0)*sin(theta) + (x[2]-z0)*cos(theta)-x[2])",
    ), scale=0.5, y0=0.5, z0=0.5, theta=pi/4, degree=2 )
bcl = DirichletBC(V, c, left)
bcr = DirichletBC(V, r, right)

w = TrialFunction(V)  # Incremental displacement
v = TestFunction(V)   # Test function
u = Function(V)       # Solution

solve(inner(grad(w), grad(v)) * dx == inner(c, v) * dx, u, [bcl, bcr])

from vtkplotter.dolfin import plot, show, embedWindow
from vtkplotter import settings

# to pop up the rendering window
# embedWindow(False)
# mesh = plot(u, mode='displaced mesh', offscreen=1).actors[0]
# mesh.lineWidth(0)
# mesh.cutWithPlane(origin=(1.8,0,0), normal=(1,1,1))
# show(mesh, newPlotter=True, axes=1).close()

# to embed in notebook with k3d (pip install k3d)
embedWindow('k3d')
plot(u, mode='displaced mesh')
mesh = settings.plotter_instance.actors[0]
mesh.lw(0)
mesh.cutWithPlane(origin=(1.8,0,0), normal=(1,1,1))

show(mesh, newPlotter=True, axes=1)

1 Like