# Install fenics-shells

**URL:** <https://fenicsproject.discourse.group/t/install-fenics-shells/14510>\
**Category:** Legacy DOLFIN\
**Created:** [May 2, 2024, 3:33pm UTC](https://fenicsproject.discourse.group/t/install-fenics-shells/14510 "2024-05-02T15:33:39Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![HumbertHumbert7](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/humberthumbert7/32/6805_2.png) [@HumbertHumbert7](https://fenicsproject.discourse.group/u/HumbertHumbert7)\
**Post date:** [May 2, 2024, 3:33pm UTC](https://fenicsproject.discourse.group/t/install-fenics-shells/14510/1 "2024-05-02T15:33:39Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![francesco-ballarin](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@francesco-ballarin](https://fenicsproject.discourse.group/u/francesco-ballarin)\
**Post date:** [May 2, 2024, 3:42pm UTC](https://fenicsproject.discourse.group/t/install-fenics-shells/14510/2 "2024-05-02T15:42:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HumbertHumbert7](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/humberthumbert7/32/6805_2.png) [@HumbertHumbert7](https://fenicsproject.discourse.group/u/HumbertHumbert7)\
**Post date:** [May 2, 2024, 3:56pm UTC](https://fenicsproject.discourse.group/t/install-fenics-shells/14510/3 "2024-05-02T15:56:05Z")

</div>

Ok,

```python
try:
    import dolfin
except ImportError:
    !wget "https://fem-on-colab.github.io/releases/fenics-install-real.sh" -O "/tmp/fenics-install.sh" && bash "/tmp/fenics-install.sh"
    import dolfin

```

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

```python
!git clone https://bitbucket.org/unilucompmech/fenics-shells.git

!cd fenics-shells
!./launch-container.sh

```

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

Then when I try to import fenics\_shells:  
ModuleNotFoundError: No module named ‘fenics\_shells’

---

<div class="post-metadata">

**Author:** ![francesco-ballarin](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@francesco-ballarin](https://fenicsproject.discourse.group/u/francesco-ballarin)\
**Post date:** [May 2, 2024, 4:09pm UTC](https://fenicsproject.discourse.group/t/install-fenics-shells/14510/4 "2024-05-02T16:09:16Z")

</div>

Try with

```auto
!git clone https://bitbucket.org/unilucompmech/fenics-shells.git && 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](https://fenicsproject.discourse.group/t/announcement-ufl-legacy-and-legacy-dolfin/11583), 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](https://fenics-shells.github.io/fenicsx-shells/) 😉

---

<div class="post-metadata">

**Author:** ![HumbertHumbert7](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/humberthumbert7/32/6805_2.png) [@HumbertHumbert7](https://fenicsproject.discourse.group/u/HumbertHumbert7)\
**Post date:** [May 2, 2024, 4:16pm UTC](https://fenicsproject.discourse.group/t/install-fenics-shells/14510/5 "2024-05-02T16:16:03Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![francesco-ballarin](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@francesco-ballarin](https://fenicsproject.discourse.group/u/francesco-ballarin)\
**Post date:** [May 2, 2024, 4:28pm UTC](https://fenicsproject.discourse.group/t/install-fenics-shells/14510/6 "2024-05-02T16:28:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![HumbertHumbert7](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/humberthumbert7/32/6805_2.png) [@HumbertHumbert7](https://fenicsproject.discourse.group/u/HumbertHumbert7)\
**Post date:** [May 2, 2024, 4:35pm UTC](https://fenicsproject.discourse.group/t/install-fenics-shells/14510/7 "2024-05-02T16:35:08Z")

</div>

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](https://fenics-shells.readthedocs.io/en/latest/demo/nonlinear-vonkarman-composite/demo_von-karman-composite.py.html)

```python
try:
    import dolfin
except ImportError:
    !wget "https://fem-on-colab.github.io/releases/fenics-install-real.sh" -O "/tmp/fenics-install.sh" && bash "/tmp/fenics-install.sh"
    import dolfin

!git clone https://bitbucket.org/unilucompmech/fenics-shells.git && 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
!./launch-container.sh

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

---

<div class="post-metadata">

**Author:** ![francesco-ballarin](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@francesco-ballarin](https://fenicsproject.discourse.group/u/francesco-ballarin)\
**Post date:** [May 2, 2024, 4:37pm UTC](https://fenicsproject.discourse.group/t/install-fenics-shells/14510/8 "2024-05-02T16:37:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![HumbertHumbert7](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/humberthumbert7/32/6805_2.png) [@HumbertHumbert7](https://fenicsproject.discourse.group/u/HumbertHumbert7)\
**Post date:** [May 2, 2024, 4:38pm UTC](https://fenicsproject.discourse.group/t/install-fenics-shells/14510/9 "2024-05-02T16:38:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![HumbertHumbert7](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/humberthumbert7/32/6805_2.png) [@HumbertHumbert7](https://fenicsproject.discourse.group/u/HumbertHumbert7)\
**Post date:** [May 2, 2024, 4:42pm UTC](https://fenicsproject.discourse.group/t/install-fenics-shells/14510/10 "2024-05-02T16:42:53Z")

</div>

Now you should be able to run it

---

<div class="post-metadata">

**Author:** ![francesco-ballarin](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@francesco-ballarin](https://fenicsproject.discourse.group/u/francesco-ballarin)\
**Post date:** [May 2, 2024, 4:45pm UTC](https://fenicsproject.discourse.group/t/install-fenics-shells/14510/11 "2024-05-02T16:45:18Z")

</div>

OK, please see the updated installation cell below

```auto
!git clone https://bitbucket.org/unilucompmech/fenics-shells.git && 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

```auto
!cd fenics-shells
!./launch-container.sh

```

are not needed.

---

<div class="post-metadata">

**Author:** ![HumbertHumbert7](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/humberthumbert7/32/6805_2.png) [@HumbertHumbert7](https://fenicsproject.discourse.group/u/HumbertHumbert7)\
**Post date:** [May 2, 2024, 4:58pm UTC](https://fenicsproject.discourse.group/t/install-fenics-shells/14510/12 "2024-05-02T16:58:43Z")

</div>

It works, thank you very much.

---

<div class="post-metadata">

**Author:** ![francesco-ballarin](https://avatars.discourse-cdn.com/v4/letter/f/f05b48/32.png) [@francesco-ballarin](https://fenicsproject.discourse.group/u/francesco-ballarin)\
**Post date:** [May 2, 2024, 5:01pm UTC](https://fenicsproject.discourse.group/t/install-fenics-shells/14510/13 "2024-05-02T17:01:54Z")

</div>

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.
