Install fenics-shells

Hi, I have installed dolfin from fem on colab, but I’m not able to install fenic-shells. Could you write me the lines of code to use in order to install it?
Thank you

Please show us what you tried to do, so that we don’t have to do everything again from scratch.


    import dolfin
except ImportError:
    !wget "" -O "/tmp/" && bash "/tmp/"
    import dolfin

These lines are used to install dolfin.
Then I have tried to follow the instruction:

!git clone

!cd fenics-shells

It doesn’t give an error but it gives this:
/bin/bash: line 1: ./ No such file or directory

Then when I try to import fenics_shells:
ModuleNotFoundError: No module named ‘fenics_shells’

Try with

!git clone && cd fenics-shells && find ./ -type f -exec sed -i 's|import ufl|import ufl_legacy|g' {} \; && find ./ -type f -exec sed -i 's|from ufl|from ufl_legacy|g' {} \; && pip install --no-dependencies .

The two find instructions are due to Announcement: ufl_legacy and legacy dolfin, while --no-dependencies is to avoid downgrading fenics components from 2019.2.0.dev0 (packaged on Colab) to 2019.1.0. @jackhale may be able to better tell if the latter is supposed to work e.g. in all demos, but at least import fenics_shells does work for me.

@jackhale will also surely tell you that in future you may want to consider FEniCSx-Shells instead, see FEniCSx-Shells — FEniCSx-Shells 0.5.0.dev0 documentation :wink:

Thank you very much, now I’m able to install it.
However, when I try to use this function:

U = ProjectedFunctionSpace(mesh, element, num_projected_subspaces=2)

I have an error:
NameError: name ‘ufl’ is not defined

Indeed I can’t import ufl but only ufl_legacy.

Do you know what can I do?

For this post and for all your future ones, please learn to:

  1. format the code properly with “```”
  2. always provided a minimal example of what you tried.

I am willing to put some effort into helping you, since I am the developer of FEM on Colab, but you can’t expect me to dig out a fenics-shell example to see what mesh and element are in the line in your post.

Ok, thank you.
I’m just following the example in the documentation of fenics-shells, the only difference is that I have imported ufl_legacy, not ufl that provides an error while I try to import it:
Bifurcation of a composite laminate plate modeled with von-Kármán theory — fenics-shells

    import dolfin
except ImportError:
    !wget "" -O "/tmp/" && bash "/tmp/"
    import dolfin

!git clone && cd fenics-shells && find ./ -type f -exec sed -i 's|import ufl|import ufl_legacy|g' {} \; && find ./ -type f -exec sed -i 's|from ufl|from ufl_legacy|g' {} \; && pip install --no-dependencies .

!cd fenics-shells

from dolfin import *
from ufl_legacy import RestrictedElement

from fenics_shells import *
import numpy as np

import matplotlib.pyplot as plt

import mshr

a_rad = 1.0
b_rad = 0.5
n_div = 30

centre = Point(0.,0.)

geom = mshr.Ellipse(centre, a_rad, b_rad)
mesh = mshr.generate_mesh(geom, n_div)

h = interpolate(Expression('t0*(1.0 - (x[0]*x[0])/(a*a) - (x[1]*x[1])/(b*b))', t0=1E-2, a=a_rad, b=b_rad, degree=2), FunctionSpace(mesh, 'CG', 2))

thetas = [np.pi/4., -np.pi/4., -np.pi/4., np.pi/4., -np.pi/4., np.pi/4., np.pi/4., -np.pi/4.]
E1 = 40.038
E2 = 1.0
G12 = 0.5
nu12 = 0.25
G23 = 0.4

n_layers= len(thetas)
hs = h*np.ones(n_layers)/n_layers
A, B, D = laminates.ABD(E1, E2, G12, nu12, hs, thetas)
Fs = laminates.F(G12, G23, hs, thetas)

element = MixedElement([VectorElement("Lagrange", triangle, 1),
                        VectorElement("Lagrange", triangle, 2),
                        FiniteElement("Lagrange", triangle, 1),
                        FiniteElement("N1curl", triangle, 1),
                        RestrictedElement(FiniteElement("N1curl", triangle, 1), "edge")])

U = ProjectedFunctionSpace(mesh, element, num_projected_subspaces=2)
U_F = U.full_space
U_P = U.projected_space

The problem is in these lines of code

Sorry for being pedantic, but that’s not a minimal example.

A minimal example should be something I can just copy and paste into the Colab instance I currently have running, including all imports (e.g. dolfin, fenics_shells), all variables (e.g. mesh, element).

I know that I could just go to the link and copy it myself, but now I am being pedantic on purpose, so that you’ll learn for future interactions in the community.

Ok, thank you, now I copy all my code.

Now you should be able to run it

OK, please see the updated installation cell below

!git clone && cd fenics-shells && find ./ -type f -exec sed -i 's|import ufl|import ufl_legacy|g' {} \; && find ./ -type f -exec sed -i 's|from ufl|from ufl_legacy|g' {} \; && find ./ -type f -exec sed -i 's|ufl\.|ufl_legacy\.|g' {} \; && pip install --no-dependencies .

Note that there is a third find, I missed it before.

To test it, you’ll need to destroy your current Colab instance, and start from scratch. To do that, go to Runtime → Disconnect and delete runtime.

Finally, note that

!cd fenics-shells

are not needed.

It works, thank you very much.

Great. In that case, please mark that post as solution to the question, so that people that end up finding this message can jump directly to the correct installation cell, and skip the one in earlier posts that turned out to be wrong. Again, selecting the post that answers your question is a best practice that you may want to adopt in future as well.