-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/iitrabhi/fenics-workshop
- Loading branch information
Showing
32 changed files
with
7,685 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
jupyter_notebooks/day-1/exercises/1_built_in_mesh.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
126
jupyter_notebooks/day-1/exercises/2_boundary_conditions.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.