Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvinoli committed Jan 7, 2025
2 parents a4afb9a + 5aa9e33 commit ae92840
Show file tree
Hide file tree
Showing 32 changed files with 7,685 additions and 52 deletions.
54 changes: 2 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,18 @@

This is a five-day course focused on solving partial differential equations (PDEs) using the FEniCS software package. The goal is to introduce the students to PDEs encountered in various engineering and science disciplines, such as solid mechanics, heat transfer, and mass transport.

Website: [https://abhigupta.io/fenics-workshop](https://abhigupta.io/fenics-workshop)

The course materials, including tutorials and exercises, were created as part of a five-day workshop at IIT Madras, in collaboration with Vanderbilt University, USA. These materials are presented in [Jupyter Notebooks](https://jupyter.org/), which allow you to see both the code and its explanations, as well as the results, all together.

The `tutorials` are comprehensive notebooks that demonstrate how to approach different types of problems using FEniCS. On the other hand, the `exercises` are meant to be interactive, and they encourage you to expand the notebooks by adding new functionalities. This way, you can develop your expertise in using FEniCS.

If you just want to view the tutorials and exercises without making any changes, you can access them on [on nbviewer](https://nbviewer.org/github/iitrabhi/iitm-fenics-course/blob/48a6a14f8f7c27f2a32cf1ea101e18934d254b01/README.ipynb) without installing FEniCS. However, if you want to edit and undertake the exercises, you will need to [install FEniCS](install-instructions.ipynb). Additionally, you have the option to either clone the repository or download the code from the provided link.

## What is FEniCS

FEniCS is an acronym that stands for "Finite Element Computational Software." The inclusion of "ni" in the name is to create a balanced and appealing composition. The FEniCS software package was compiled at the University of Chicago, whose Phoenix mascot likely influenced the choice of the name.

FEniCS is a high-performance computing (HPC) capable tool that efficiently utilizes supercomputers and high-performance clusters to solve complex scientific problems. It supports parallel computing, JIT compilation, and integrates with PETSc and MPI for scalability and performance. Its HPC capabilities enable researchers to perform large-scale simulations and analyses effectively.

## Contents
- [Instructions for installing FEniCS](install-instructions.ipynb)
- Day 1
- Tutorials
- [Tutorial 1-1: Solving linear Poisson's equation](src/day-1/tutorials/1_linear_poisson.ipynb)
- [Tutorial 1-2: Visualization](src/day-1/tutorials/2_visualization.ipynb)
- Exercises
- [Exercise 1-1: Built in meshes](src/day-1/exercises/1_built_in_mesh.ipynb)
- [Exercise 1-2: Boundary conditions](src/day-1/exercises/2_boundary_conditions.ipynb)
- [Exercise 1-3: Expressions](src/day-1/exercises/3_expressions.ipynb)
- [Exercise 1-4: Spacially varying properties](src/day-1/exercises/4_spacially_varying_properties.ipynb)
- [Exercise 1-5: Convergence](src/day-1/exercises/5_convergence.ipynb)
- Day 2
- Tutorials
- [Tutorial 2-1: Solving non-linear Poisson's equation using Picard Iteration](src/day-2/tutorials/1_non_linear_poisson_picard.ipynb)
- [Tutorial 2-3: Solving non-linear Poisson's equation using Newton Iteration](src/day-2/tutorials/2_non_linear_poisson_newton.ipynb)
- [Tutorial 2-3: Newton method with Manual Differentiation](src/day-2/tutorials/3_non_linear_poisson_newton_manual_diff.ipynb)
- [Tutorial 2-4: Newton method with Automatic Differentiation](src/day-2/tutorials/4_non_linear_poisson_newton_auto_diff.ipynb)
- Exercises
- [Exercise 2-1: 2D and 3D Domains](src/day-2/exercises/1_2d_3d_domains.ipynb)
- [Exercise 2-2: Boundary Conditions](src/day-2/exercises/2_boundary_conditions.ipynb)
- [Exercise 2-3: Non-Linearity and Tolerances](src/day-2/exercises/3_non_linearity_tolerances.ipynb)
- [Exercise 2-4: Manual vs Auto differentiation](src/day-2/exercises/4_manual_auto_differentiation.ipynb)
- Day 3
- Tutorials
- [Tutorial 3-1: Beam bending](src/day-3/tutorials/1_beam_bending.ipynb)
- [Tutorial 3-2: Loads and boundary conditions](src/day-3/tutorials/2_load_and_boundary_conditions.ipynb)
- [Tutorial 3-3: Solver design](src/day-3/tutorials/3_solver.ipynb)
- Exercises
- [Exercise 3-1: 3D Uniaxial](src/day-3/exercises/1_3d_uniaxial.ipynb)
- [Exercise 3-2: Plane Stress v/s Plane strain](src/day-3/exercises/2_plane_stress_strain.ipynb)
- [Exercise 3-3: Effect of solver design](src/day-3/exercises/3_solver_design.ipynb)
- Day 4
- Tutorials
- [Tutorial 4-1: Solving hyper elasticity in FEniCS](src/day-4/tutorials/1_hyper_elastic.ipynb)
- [Tutorial 4-1: Pseudo time stepping in hyper elasticity](src/day-4/tutorials/2_load_displacement.ipynb)
- Exercises
- [Exercise 4-1: Mooney rivlin material model](src/day-4/exercises/1_mooney-rivlin.ipynb)
- [Exercise 4-2: Comparison between elastic and hyperelastic solution](src/day-4/exercises/2_comparison.ipynb)
- Day 5
- Tutorials
- [Tutorial 5-1:Thermoelasticity](src/day-5/tutorials/1_thermoelasticity.ipynb)
- [Tutorial 5-2:Multi-material domains](src/day-5/tutorials/2_multi_material.ipynb)
- [Tutorial 5-3:Transient analysis](src/day-5/tutorials/3_transient_analysis.ipynb)
- Exercise
- [Exercise 5-1:Bi-metallic quasi static analysis](src/day-5/exercises/1_bi_metallic_quasi_static.ipynb)
- [Exercise 5-2:Transient thermo-mechanical analysis](src/day-5/exercises/2_thermo_mechanical_transient.ipynb)



## Where to find help

When in doubt about any specific FEniCS command or implementation, there are several resources you can refer to for clarification and assistance:
Expand Down
100 changes: 100 additions & 0 deletions jupyter_notebooks/day-1/exercises/1_built_in_mesh.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Built in meshes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"FEniCS provides built-in capabilities to generate various types of meshes, allowing users to focus on the core of their simulations. Please visit the official documentation link provided to learn how to modify the mesh. After familiarizing yourself with the process, return here to implement the changes and visualize the updated results.\n",
"\n",
"https://fenicsproject.org/olddocs/dolfin/latest/python/demos/built-in-meshes/demo_built-in-meshes.py.html"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"from dolfin import *"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Change this portion of the code to:**\n",
"1. Make a 2D unit square mesh.\n",
"2. Make a rectangle mesh with dimension $2 \\times 1$"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"mesh = IntervalMesh(30, 0, 1)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [],
"source": [
"U = FunctionSpace(mesh, \"CG\", 1)\n",
"\n",
"u_D = Constant(0.0)\n",
"boundary = CompiledSubDomain(\"on_boundary\")\n",
"bc = DirichletBC(U, u_D, boundary)\n",
"u, v = TrialFunction(U), TestFunction(U)\n",
"\n",
"a = inner(grad(u), grad(v)) * dx\n",
"f_expr = Expression(\"pi*pi*sin(pi*x[0])\", pi=np.pi, degree=2)\n",
"L = f_expr * v * dx\n",
"\n",
"u_sol = Function(U, name = \"field\")\n",
"solve(a == L, u_sol, bc)\n",
"\n",
"with XDMFFile(\"output/result.xdmf\") as outfile:\n",
" outfile.write(u_sol)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
126 changes: 126 additions & 0 deletions jupyter_notebooks/day-1/exercises/2_boundary_conditions.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Boundary conditions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In FEniCS, the \"CompiledSubDomain\" class is a useful tool that allows users to define complex subdomains within a given computational domain for finite element simulations. Subdomains are portions of the computational domain where different physical or material properties are applied, or specific boundary conditions are imposed.\n",
"\n",
"The primary advantage of using the \"CompiledSubDomain\" class is that it allows you to define subdomains using mathematical expressions or conditions, which are then compiled into efficient C++ code. This compiled code is utilized during the simulation, providing a significant performance boost compared to interpreting the subdomain expressions directly in Python.\n",
"\n",
"Please visit the official documentation link provided to learn how to modify the bounday conditions using \"CompiledSubDomain\". After familiarizing yourself with the process, return here to implement the changes and visualize the updated results.\n",
"\n",
"https://hplgit.github.io/fenics-tutorial/pub/sphinx1/._ftut1005.html#using-c-code-snippets-to-define-subdomains"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from dolfin import *"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Change this portion of the code to:**\n",
"1. Make a 2D unit square mesh."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"mesh = IntervalMesh(30, 0, 1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"U = FunctionSpace(mesh, \"CG\", 1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Change this portion of the code to:**\n",
"1. Mark only the left edge as fixed.\n",
"2. Mark the left and top edge as fixed."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"u_D = Constant(0.0)\n",
"boundary = CompiledSubDomain(\"on_boundary\")\n",
"bc = DirichletBC(U, u_D, boundary)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"u, v = TrialFunction(U), TestFunction(U)\n",
"\n",
"a = inner(grad(u), grad(v)) * dx\n",
"f_expr = Expression(\"pi*pi*sin(pi*x[0])\", pi=np.pi, degree=2)\n",
"L = f_expr * v * dx\n",
"\n",
"u_sol = Function(U, name = \"field\")\n",
"solve(a == L, u_sol, bc)\n",
"\n",
"with XDMFFile(\"output/result.xdmf\") as outfile:\n",
" outfile.write(u_sol)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.7"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit ae92840

Please sign in to comment.