Appearance
FEniCS Installation Exercise
This short exercise helps you verify that your FEniCS installation is complete and working correctly — both in the terminal and inside Jupyter. It’s a basic test, but completing it confirms that your environment is ready for running actual simulations in later chapters.
Estimated time: 15–20 minutes What you’ll submit: A few screenshots showing your FEniCS installation and a successful solver run.
Step 1 — Check Installation in the Terminal
Open your terminal (Ubuntu in WSL or macOS Terminal) and run the following commands one by one:
bash
python3 -c "import dolfin; print('FEniCS version:', dolfin.__version__)"
python3 -c "import meshio; print('meshio version:', meshio.__version__)"
jupyter notebook --versionYou should see version numbers for FEniCS, meshio, and Jupyter printed without any errors.
Deliverable 1: Screenshot of your terminal showing all three version lines.
Step 2 — Launch Jupyter Notebook and Verify Inside
Next, open Jupyter Notebook from the same terminal:
bash
jupyter notebook --ip=0.0.0.0 --port=8888 --no-browserCopy the URL displayed in the terminal and open it in your browser. Then, create a new Python 3 notebook and run this code block:
python
import dolfin, meshio, sys
print("FEniCS:", dolfin.__version__)
print("meshio:", meshio.__version__)
print("Python:", sys.version)This confirms that FEniCS and its dependencies are correctly recognized inside your Jupyter environment.
Deliverable 2: Screenshot of the notebook cell output showing the printed versions.
Step 3 — Run a Small Test Problem
Now let’s confirm that the solver runs without errors. Copy and run this minimal Poisson example in a new notebook cell:
python
from fenics import *
mesh = UnitSquareMesh(8, 8)
V = FunctionSpace(mesh, "P", 1)
u = TrialFunction(V)
v = TestFunction(V)
f = Constant(-6.0)
a = dot(grad(u), grad(v))*dx
L = f*v*dx
u_sol = Function(V)
solve(a == L, u_sol)
print("Solver executed successfully!")If everything is set up properly, you should see the message: Solver executed successfully!
(Optional) Save the solution to a file for later visualization:
python
with XDMFFile("output_poisson.xdmf") as xf:
xf.write(u_sol)Deliverable 3: Screenshot of the notebook cell showing the success message.
Step 4 — Confirm and Save
Check that you have:
- Deliverable 1: Terminal output showing versions.
- Deliverable 2: Jupyter cell output confirming environment setup.
- Deliverable 3: Notebook showing the solver executed successfully.
(If you completed the optional step, keep output_poisson.xdmf — we’ll visualize it later in ParaView.)
Summary
This exercise confirms that your FEniCS, meshio, and Jupyter installations are correctly configured and that your solver environment runs as expected.
If you encountered any issues:
- Revisit the installation instructions for Installing FEniCS in WSL or Installing FEniCS with Conda.
- Make sure all dependencies were installed correctly and that you’re using the right Python environment.
Once you’ve completed this exercise successfully, you’re ready to move forward with geometry creation, meshing, and running full simulation workflows.