2022-03-15 07:04:08 +00:00
{
"cells": [
{
"cell_type": "code",
2022-04-03 20:18:44 +00:00
"execution_count": 54,
2022-03-15 07:04:08 +00:00
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
2022-04-03 20:18:44 +00:00
"import matplotlib.pyplot as plt"
2022-03-15 07:04:08 +00:00
]
},
{
"cell_type": "code",
2022-04-03 20:18:44 +00:00
"execution_count": 55,
2022-03-15 07:04:08 +00:00
"metadata": {},
"outputs": [],
"source": [
"def maillage_carre(n: int):\n",
" \"\"\"\n",
" Une discrétisation possible d'une EDP elliptique sur le domaine ]0,1[ x ]0,1[.\n",
" Le carre [0,1]x[0,1] est maille uniquement avec des triangles.\n",
" Les conditions limites sont de type Dirichlet uniquement -> `neumann=[]`.\n",
"\n",
" Args:\n",
2022-04-03 20:18:44 +00:00
" n: nombre de points par cote du care => Npts points de discretisation au total\n",
2022-03-15 07:04:08 +00:00
"\n",
" Returns:\n",
2022-04-03 20:18:44 +00:00
" coordinates: matrice a deux colonnes. Chaque ligne contient les coordonnes 2D d'un des points de la discretisation. Ces sommets seront identifies a l'indice de la ligne correspondante dans la matrice coordinates.\n",
" elements3: matrice a trois colonnes. Chaque ligne contient les indices des sommets d'un element triangle, dans le sens antihoraire.\n",
" dirichlet: vecteur colonne des indices des sommets de la frontiere de Dirichlet.\n",
" neumann: matrice a deux colonnes. Chaque ligne contient les indices des deux sommets d'une arete de la frontiere de Neumann. (neumann est vide sur cet exemple)\n",
2022-03-15 07:04:08 +00:00
" \"\"\"\n",
"\n",
" h = 1 / (n - 1)\n",
" n_pts = n * n\n",
" n_elm = 2 * (n - 1) * (n - 1)\n",
" coordinates = np.zeros((n_pts, 2))\n",
" elements3 = np.zeros((n_elm, 3), dtype=int)\n",
" neumann = []\n",
" dirichlet = np.zeros((4 * n - 4, 1), dtype=int)\n",
"\n",
" # Coordonnees et connectivites :\n",
" e = -1\n",
" p = -1\n",
" x = np.zeros((n + 1, 1))\n",
" x[n, 0] = 1.0\n",
"\n",
" for l in range(n + 1):\n",
" x[l, 0] = l * h\n",
"\n",
" for j in range(n):\n",
" for i in range(n):\n",
" p = p + 1\n",
" coordinates[p, 0] = x[i, 0]\n",
" coordinates[p, 1] = x[j, 0]\n",
" if (i != n - 1) & (j != n - 1):\n",
" p1 = p\n",
" p2 = p1 + 1\n",
" p3 = p1 + n\n",
" p4 = p2 + n\n",
" e = e + 1\n",
" elements3[e, 0] = p1\n",
" elements3[e, 1] = p2\n",
" elements3[e, 2] = p3\n",
" e = e + 1\n",
" elements3[e, 0] = p4\n",
" elements3[e, 1] = p3\n",
" elements3[e, 2] = p2\n",
"\n",
" # Liste des sommets de la frontiere de Dirichlet:\n",
" p = -1\n",
" for j in range(n):\n",
" p = p + 1\n",
" dirichlet[p, 0] = j\n",
"\n",
" for j in range(n * 2 - 1, n * (n - 1), n):\n",
" p = p + 1\n",
" dirichlet[p, 0] = j\n",
"\n",
" for j in range(n * n - 1, n * n - n - 1, -1):\n",
" p = p + 1\n",
" dirichlet[p, 0] = j\n",
"\n",
" for j in range(n * n - 2 * n, n - 1, -n):\n",
" p = p + 1\n",
" dirichlet[p, 0] = j\n",
"\n",
" return coordinates, elements3, dirichlet, neumann\n"
]
},
{
"cell_type": "code",
2022-04-03 20:18:44 +00:00
"execution_count": 56,
2022-03-15 07:04:08 +00:00
"metadata": {},
"outputs": [],
"source": [
"def show(coordinates, u) -> None:\n",
" \"\"\"Fonction d'affichage de la solution u sur le maillage defini par elements3, coordinates.\n",
"\n",
" Args:\n",
2022-04-03 20:18:44 +00:00
" coordinates: matrice a deux colonnes. Chaque ligne contient les coordonnes 2D d'un des points de la discretisation. Ces sommets seront identifies a l'indice de la ligne correspondante dans la matrice coordinates.\n",
" u: vecteur colonne de longueur egale au nombre de lignes de coordinates contenant les valeurs de la solution a afficher aux points de la discretisation.\n",
2022-03-15 07:04:08 +00:00
"\n",
" Returns:\n",
" None, plots a figure\n",
" \"\"\"\n",
"\n",
" ax = plt.figure().add_subplot(projection=\"3d\")\n",
" ax.plot_trisurf(\n",
" coordinates[:, 0], coordinates[:, 1], u, linewidth=0.2, antialiased=True\n",
" )\n",
" plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2022-04-03 20:18:44 +00:00
"## Partie I : maillage triangulaire et conditions de Dirichlet\n",
"\n",
"$$\n",
"\\left\\{\n",
"\\begin{array}{rll}\n",
"\n",
"\\displaystyle -\\delta u (x, y) &= f(x, y) &\\text{sur } \\Omega \\\\\n",
"\\displaystyle u (x, y) &= u_d(x, y) &\\text{sur } \\partial\\Omega_d \\\\\n",
"\\displaystyle \\frac{\\partial u (x, y)}{\\partial n} &= g(x, y) &\\text{sur } \\partial\\Omega_n\n",
"\n",
"\\end{array}\n",
"\\right.\n",
"$$\n"
2022-03-15 07:04:08 +00:00
]
},
{
"cell_type": "code",
2022-04-03 20:18:44 +00:00
"execution_count": 57,
2022-03-15 07:04:08 +00:00
"metadata": {},
"outputs": [],
"source": [
"def f(x, y):\n",
2022-04-03 20:18:44 +00:00
" return 2 * np.pi ** 2 * np.sin(np.pi * x) * np.sin(np.pi * y)\n",
2022-03-15 07:04:08 +00:00
"\n",
"\n",
"def u_ex(x, y):\n",
" return np.sin(np.pi * x) * np.sin(np.pi * y)\n",
"\n",
"\n",
"def u_d(x, y):\n",
2022-04-03 20:18:44 +00:00
" return np.zeros(x.shape[0])"
2022-03-15 07:04:08 +00:00
]
},
{
"cell_type": "code",
2022-04-03 20:18:44 +00:00
"execution_count": 58,
2022-03-15 07:04:08 +00:00
"metadata": {},
"outputs": [
{
2022-04-03 20:18:44 +00:00
"name": "stdout",
"output_type": "stream",
"text": [
"coords = [[0. 0. ]\n",
" [0.5 0. ]\n",
" [1. 0. ]\n",
" [0. 0.5]\n",
" [0.5 0.5]\n",
" [1. 0.5]\n",
" [0. 1. ]\n",
" [0.5 1. ]\n",
" [1. 1. ]]\n",
"\n",
"elems3 = [[0 1 3]\n",
" [4 3 1]\n",
" [1 2 4]\n",
" [5 4 2]\n",
" [3 4 6]\n",
" [7 6 4]\n",
" [4 5 7]\n",
" [8 7 5]]\n",
"\n",
"dirichlet = [[0]\n",
" [1]\n",
" [2]\n",
" [5]\n",
" [8]\n",
" [7]\n",
" [6]\n",
" [3]]\n",
"\n",
"neumman = []\n"
]
2022-03-15 07:04:08 +00:00
}
],
"source": [
2022-04-03 20:18:44 +00:00
"# affichage d'un petit maillage\n",
"coords, elems3, dirichlet, neumann = maillage_carre(3)\n",
"print(\n",
" f\"coords = {coords}\",\n",
" f\"elems3 = {elems3}\",\n",
" f\"dirichlet = {dirichlet}\",\n",
" f\"neumman = {neumann}\",\n",
" sep=\"\\n\\n\"\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"$$\n",
"[M^A_T]_{ij} = \\displaystyle \\int_T \\nabla \\eta_i (x, y) \\eta_j (x, y) \\ dx \\ dy\n",
"$$\n"
2022-03-15 07:04:08 +00:00
]
},
{
"cell_type": "code",
2022-04-03 20:18:44 +00:00
"execution_count": 59,
2022-03-15 07:04:08 +00:00
"metadata": {},
"outputs": [],
"source": [
2022-04-03 20:18:44 +00:00
"def calcul_alpha(x, y):\n",
" \"\"\"Calcul du coefficient alpha.\n",
"\n",
" Args:\n",
" x (np.array): les coordonnées x du triangle.\n",
" y (np.array): les coordonnées y du triangle.\n",
2022-03-15 07:04:08 +00:00
"\n",
2022-04-03 20:18:44 +00:00
" Returns:\n",
" float: le coefficient alpha.\n",
" \"\"\"\n",
2022-03-15 07:04:08 +00:00
" mat_alpha = np.array(\n",
" [\n",
" [x[1] - x[0], x[2] - x[0]],\n",
" [y[1] - y[0], y[2] - y[0]]\n",
" ]\n",
" )\n",
"\n",
2022-04-03 20:18:44 +00:00
" return np.linalg.det(mat_alpha)"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1. , -0.5, -0.5],\n",
" [-0.5, 0.5, 0. ],\n",
" [-0.5, 0. , 0.5]])"
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def raideur(triangle):\n",
" \"\"\"Construction de la matrice de raideur ́elementaire relative à un ́élément triangle.\n",
"\n",
" Args:\n",
" triangle: les coordonnées x et y des trois points formant le triangle.\n",
2022-03-15 07:04:08 +00:00
"\n",
2022-04-03 20:18:44 +00:00
" Returns:\n",
" M: La matrice de raideur ́elementaire.\n",
" \"\"\"\n",
" M = np.zeros((3, 3))\n",
" x = triangle[:, 0]\n",
" y = triangle[:, 1]\n",
"\n",
" alpha = calcul_alpha(x, y)\n",
"\n",
" # calcul de la matrice M\n",
2022-03-15 07:04:08 +00:00
" for i in range(3):\n",
" grad_eta_i = np.array(\n",
" [\n",
" y[(i+1)%3] - y[(i+2)%3],\n",
" x[(i+2)%3] - x[(i+1)%3]\n",
" ]\n",
" )\n",
" for j in range(3):\n",
" grad_eta_j = np.array(\n",
" [\n",
" y[(j+1)%3] - y[(j+2)%3],\n",
" x[(j+2)%3] - x[(j+1)%3]\n",
" ]\n",
" )\n",
"\n",
" M[i, j] = np.dot(grad_eta_i, grad_eta_j)\n",
"\n",
2022-04-03 20:18:44 +00:00
" return M / alpha / 2\n",
"\n",
"# on affiche la première matrice de raideur pour vérifier\n",
"raideur(coords[elems3[0]])"
2022-03-15 07:04:08 +00:00
]
},
{
"cell_type": "code",
2022-04-03 20:18:44 +00:00
"execution_count": 61,
2022-03-15 07:04:08 +00:00
"metadata": {},
2022-04-03 20:18:44 +00:00
"outputs": [],
2022-03-15 07:04:08 +00:00
"source": [
2022-04-03 20:18:44 +00:00
"def assemblage(coordinates, elements3):\n",
" \"\"\"Assemblage de la matrice A dans le cas d'un maillage constitué uniquement d'éléments triangles.\n",
"\n",
" Args:\n",
" coordinates: matrice a deux colonnes. Chaque ligne contient les coordonnes 2D d'un des points de la discretisation. Ces sommets seront identifies a l'indice de la ligne correspondante dans la matrice coordinates.\n",
" elements3: matrice a trois colonnes. Chaque ligne contient les indices des sommets d'un element triangle, dans le sens antihoraire.\n",
"\n",
" Returns:\n",
" A: matrice nécéssaire à la résolution de la formulation variationnelle du problème.\n",
" \"\"\"\n",
" Ns = len(coordinates)\n",
2022-03-15 07:04:08 +00:00
" A = np.zeros((Ns, Ns))\n",
2022-04-03 20:18:44 +00:00
"\n",
" for triangle in elements3:\n",
" M = raideur(coordinates[triangle])\n",
2022-03-15 07:04:08 +00:00
" for i, a in enumerate(triangle):\n",
" for j, b in enumerate(triangle):\n",
" A[a, b] += M[i, j]\n",
2022-04-03 20:18:44 +00:00
" \n",
" return A"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [],
"source": [
"def second_membre(coordinates, elements3):\n",
" \"\"\"Calcul le second membre.\n",
2022-03-15 07:04:08 +00:00
"\n",
2022-04-03 20:18:44 +00:00
" Args:\n",
" coordinates: matrice a deux colonnes. Chaque ligne contient les coordonnes 2D d'un des points de la discretisation. Ces sommets seront identifies a l'indice de la ligne correspondante dans la matrice coordinates.\n",
" elements3: matrice a trois colonnes. Chaque ligne contient les indices des sommets d'un element triangle, dans le sens antihoraire.\n",
2022-03-15 07:04:08 +00:00
"\n",
2022-04-03 20:18:44 +00:00
" Returns:\n",
" b: vecteur b nécéssaire à la résolution de la formulation variationnelle du problème, sans les conditions de Dirichlet.\n",
" \"\"\"\n",
" Ns = len(coordinates)\n",
2022-03-15 07:04:08 +00:00
" b = np.zeros(Ns)\n",
2022-04-03 20:18:44 +00:00
" for triangle in elements3:\n",
" coords_triangle = coordinates[triangle]\n",
2022-03-15 07:04:08 +00:00
" centre = np.mean(coords_triangle, 0)\n",
" x = coords_triangle[:, 0]\n",
" y = coords_triangle[:, 1]\n",
"\n",
2022-04-03 20:18:44 +00:00
" alpha = calcul_alpha(x, y)\n",
"\n",
" # approximation pour la quadrature du second membre\n",
2022-03-15 07:04:08 +00:00
" b[triangle] += alpha / 6 * f(centre[0], centre[1])\n",
"\n",
2022-04-03 20:18:44 +00:00
" return b"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [],
"source": [
"def calcul_Ud(coords, dirichlet):\n",
" \"\"\"Calcul le vecteur Ud nécéssaire à l'application des conditions de Dirichlet.\n",
2022-03-15 07:04:08 +00:00
"\n",
2022-04-03 20:18:44 +00:00
" Args:\n",
" coordinates: matrice a deux colonnes. Chaque ligne contient les coordonnes 2D d'un des points de la discretisation. Ces sommets seront identifies a l'indice de la ligne correspondante dans la matrice coordinates.\n",
" dirichlet: vecteur colonne des indices des sommets de la frontiere de Dirichlet.\n",
2022-03-15 07:04:08 +00:00
"\n",
2022-04-03 20:18:44 +00:00
" Returns:\n",
" Ud: vecteur pour appliquer les conditions de Dirichlet.\n",
" \"\"\"\n",
2022-03-15 07:04:08 +00:00
" Ns = len(coords)\n",
" U = np.zeros(Ns)\n",
2022-04-03 20:18:44 +00:00
"\n",
2022-03-15 07:04:08 +00:00
" U[dirichlet.T] = u_d(coords[dirichlet, 0], coords[dirichlet, 1])\n",
"\n",
2022-04-03 20:18:44 +00:00
" return U"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [],
"source": [
"def tildage(A, b, coordinates, dirichlet):\n",
" \"\"\"Permet de retirer les parties de A et b soumis au conditions de Dirichlet, nécéssaire avant la résolution numérique.\n",
2022-03-15 07:04:08 +00:00
"\n",
2022-04-03 20:18:44 +00:00
" Args:\n",
" A: La matrice A de la résolution numérique.\n",
" b: Le vecteur b de la résolution numérique.\n",
" coordinates: matrice a deux colonnes. Chaque ligne contient les coordonnes 2D d'un des points de la discretisation. Ces sommets seront identifies a l'indice de la ligne correspondante dans la matrice coordinates.\n",
" dirichlet: vecteur colonne des indices des sommets de la frontiere de Dirichlet.\n",
2022-03-15 07:04:08 +00:00
"\n",
2022-04-03 20:18:44 +00:00
" Returns:\n",
" A: La matrice A de la résolution numérique tildée.\n",
" b: Le vecteur b de la résolution numérique tildé.\n",
" coordinates: matrice a deux colonnes. Chaque ligne contient les coordonnes 2D d'un des points de la discretisation non soumis ausx conditions de Dirichlet. Ces sommets seront identifies a l'indice de la ligne correspondante dans la matrice coordinates.\n",
" \"\"\"\n",
2022-03-15 07:04:08 +00:00
" A_tild = np.delete(A, dirichlet, 0)\n",
" A_tild = np.delete(A_tild, dirichlet, 1)\n",
2022-04-03 20:18:44 +00:00
" \n",
2022-03-15 07:04:08 +00:00
" b_tild = np.delete(b, dirichlet, 0)\n",
2022-04-03 20:18:44 +00:00
" \n",
" coords_tild = np.delete(coordinates, dirichlet, 0)\n",
2022-03-15 07:04:08 +00:00
"\n",
2022-04-03 20:18:44 +00:00
" return A_tild, b_tild, coords_tild"
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [],
"source": [
"def untildage(x, dirichlet, U_d):\n",
" \"\"\"Opération inverse de la fonction tildage, place dans le vecteur x aux coordonnées de dirichlet les valeurs des conditions\n",
2022-03-15 07:04:08 +00:00
"\n",
2022-04-03 20:18:44 +00:00
" Args:\n",
" x: le vecteur solution trouvé après résolution.\n",
" dirichlet: vecteur colonne des indices des sommets de la frontiere de Dirichlet.\n",
" Ud: vecteur pour appliquer les conditions de Dirichlet.\n",
2022-03-15 07:04:08 +00:00
"\n",
2022-04-03 20:18:44 +00:00
" Returns:\n",
" x: le vecteur solution complet, avec les conditions aux bords.\n",
" \"\"\"\n",
2022-03-15 07:04:08 +00:00
" x_untild = np.zeros(U_d.shape[0])\n",
2022-03-16 14:44:07 +00:00
" not_dirichlet = np.setdiff1d(range(U_d.shape[0]), dirichlet)\n",
"\n",
2022-03-15 07:04:08 +00:00
" x_untild[dirichlet] = U_d[dirichlet]\n",
" x_untild[not_dirichlet] = x\n",
"\n",
2022-04-03 20:18:44 +00:00
" return x_untild"
]
},
{
"cell_type": "code",
"execution_count": 66,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPcAAADyCAYAAACRQVPgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwga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rJEnyQJns07SwTysu8kHHh4bcG8ldSyk33QTyMHJba7l16xazs7O89tpr77Iy74V8SinOnz+P67oUi8UHmj96e3s31Z32fmErVlYIQaVSoVKpMDY2hjGGer2+4sZ3ntvc3Bzd3d247gd3aa737J+WF7JZfHDv4CpsNHf9JNzyNE155513KJVKHD9+/IloqHXQbDY5d+4ce/bsYXBwEKXUA80fCwsLnD9/njiOKRQKhGFId3f3B64e/El4FVJKuru76e7uZu/evSuFNLVajfHxcYQQK1b9gyZYsZEa/Q8CwT/w5N7M6J6tBtQ66LjhBw4ceGw6bSuWO8syzp07x4svvkilUlnpTOqcr9P8sWfPHiYnJ2k2mywsLHDz5s33FIV+WnjS30EIQaFQYP/+/UB+vxYXF98lWNHb2/u+lsnC+uRWSn0gXsgfWHJvRf5ISrnpPXfnWrdu3WJmZuahbvjDrrPRl4gxhitXrpBlGV/6pV+64m4+bnFKKSkWi+zatQvIo9ALCwtMTEzQaDRWSkR7e3vfl1zq07BKa8/Z6cHuvGQ7ghV37959QLCicw+eJdm11o9dj61Wi1Kp9My+z6PwgSS31ppms4nv+5uq192Ku5ymKVEUEcfxI93wtdio5Y7jmLfffpvBwUEKhcKG95Frzx8EwQNiDZ0S0U5gqlM19qz6t58Gudc
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPcAAADyCAYAAACRQVPgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAADENElEQVR4nOz9d5heWX7Xi37WWju9sXJQlVTKsdXqoFbPjDn3mnuI9nNteLgc7oXLwVwbzsUH+8A55gAGXxwwDjgQbGODx8YmGYPHOHucxvYAnh6pW2rlHEqqKlUOb9pxrXX/2PXWlKolVWhJ091T3+fR0+rSu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xg165dDA4OkmXZe5o/Hjx4QJIkFAoFisXiB3KhPwuvQin1SJlsO902PT3NrVu3cBxn5WX3QROsaKfBnoYPAsE/8OTezOierQbU2mi74Xv37mXHjh1PPWazCzxNU86fP8/x48epVqsrnUnw3uaPtkjD9PQ0N2/eXKkH7+7u3nQU+nnhWX8HKSXFYpFDhw4BeR98u9Ot0WhQKBRWgnNbFax4VliP3FmWfSC68T6w5N6K/JGUctN77va17t+/z/j4OK+88sqKvtnTrrPRl4gxhps3b5KmKV/2ZV+2UuW13kuqVCqxa9cugBWxhtVR6O7ubrq7u19oiWgbz8MqrT2n7/vs2LGDHTt2rAhWzM/PrwhWrI7Eb0Sw4llCa/3U9dhsNtddQy8CH0hya61pNBp4nrepet2tuMtZlhGGIfV6nTfffHNDb9yNWu62GGJ3dzeFQmHD5Ztrz18oFCgUCiv14I1G45ES0dW
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
2022-03-15 07:04:08 +00:00
"n = 50\n",
"coords, elems3, dirichlet, neumann = maillage_carre(n)\n",
"\n",
2022-04-03 20:18:44 +00:00
"# calcul du premier membre de l'équation\n",
2022-03-15 07:04:08 +00:00
"A = assemblage(coords, elems3)\n",
2022-04-03 20:18:44 +00:00
"\n",
"# calcul du second membre de l'équation\n",
"b = second_membre(coords, elems3)\n",
"\n",
"# calcul du vecteur des conditions de dirichlet\n",
2022-03-15 07:04:08 +00:00
"U_d = calcul_Ud(coords, dirichlet)\n",
2022-04-03 20:18:44 +00:00
"\n",
"# on modifie b pour vérifier les conditions \n",
2022-03-15 07:04:08 +00:00
"b -= np.dot(A, U_d)\n",
"\n",
2022-04-03 20:18:44 +00:00
"# on enlève les conditions aux bords avant résolution\n",
2022-03-15 07:04:08 +00:00
"A_tild, b_tild, coords_tild = tildage(A, b, coords, dirichlet)\n",
"\n",
2022-04-03 20:18:44 +00:00
"# on résoud le système\n",
2022-03-15 07:04:08 +00:00
"x = np.linalg.solve(A_tild, b_tild)\n",
2022-04-03 20:18:44 +00:00
"\n",
"# on remet les conditions aux bords\n",
2022-03-15 07:04:08 +00:00
"x_untild = untildage(x, dirichlet, U_d)\n",
"\n",
2022-04-03 20:18:44 +00:00
"# on affiche le résultat\n",
2022-03-15 07:04:08 +00:00
"show(coords, x_untild)\n",
2022-04-03 20:18:44 +00:00
"\n",
"# on compare avec le résultat théorique exacte\n",
2022-03-15 07:04:08 +00:00
"show(coords, u_ex(coords[:, 0], coords[:, 1]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2022-04-03 20:18:44 +00:00
"## Partie II : maillage mixte et ajoût des conditions de Neumann\n"
2022-03-15 07:04:08 +00:00
]
},
{
"cell_type": "code",
2022-04-03 20:18:44 +00:00
"execution_count": 67,
"metadata": {},
"outputs": [],
"source": [
"def f(x, y):\n",
" return 1\n",
"\n",
"\n",
"def u_d(x, y):\n",
" return 1\n",
"\n",
"\n",
"def g(x):\n",
" return 1"
]
},
{
"cell_type": "code",
"execution_count": 68,
2022-03-15 07:04:08 +00:00
"metadata": {},
"outputs": [],
"source": [
"e3 = np.array(\n",
" [[1, 2, 12], [2, 3, 12], [3, 4, 14], [4, 5, 14], [2, 15, 3], [3, 15, 4]]\n",
").astype(int)\n",
"\n",
"e4 = np.array(\n",
" [\n",
" [0, 1, 12, 11],\n",
" [11, 12, 13, 10],\n",
" [12, 3, 14, 13],\n",
" [10, 13, 8, 9],\n",
" [13, 14, 7, 8],\n",
" [14, 5, 6, 7],\n",
" ]\n",
").astype(int)\n",
"\n",
"dds = np.array([2, 15, 4, 6, 7, 8, 9, 10, 11, 0]).astype(int)\n",
"\n",
"nns = np.array([[4, 5], [5, 6], [0, 1], [1, 2]]).astype(int)\n",
"\n",
"ccs = np.array(\n",
" [\n",
2022-04-03 20:18:44 +00:00
" [0, 0],\n",
2022-03-15 07:04:08 +00:00
" [1 / 3, 0],\n",
2022-04-03 20:18:44 +00:00
" [16 / 30, 0],\n",
2022-03-15 07:04:08 +00:00
" [2 / 3, 1 / 3],\n",
2022-04-03 20:18:44 +00:00
" [1, 14 / 30],\n",
2022-03-15 07:04:08 +00:00
" [1, 2 / 3],\n",
2022-04-03 20:18:44 +00:00
" [1, 1],\n",
" [2 / 3, 1],\n",
" [1 / 3, 1],\n",
" [0, 1],\n",
" [0, 2 / 3],\n",
" [0, 1 / 3],\n",
2022-03-15 07:04:08 +00:00
" [1 / 3, 1 / 3],\n",
" [1 / 3, 2 / 3],\n",
" [2 / 3, 2 / 3],\n",
2022-04-03 20:18:44 +00:00
" [1, 0],\n",
2022-03-15 07:04:08 +00:00
" ]\n",
")"
]
},
{
"cell_type": "code",
2022-04-03 20:18:44 +00:00
"execution_count": 69,
2022-03-15 07:04:08 +00:00
"metadata": {},
2022-03-16 14:44:07 +00:00
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0.66666667, -0.16666667, -0.33333333, -0.16666667],\n",
" [-0.16666667, 0.66666667, -0.16666667, -0.33333333],\n",
" [-0.33333333, -0.16666667, 0.66666667, -0.16666667],\n",
" [-0.16666667, -0.33333333, -0.16666667, 0.66666667]])"
]
},
2022-04-03 20:18:44 +00:00
"execution_count": 69,
2022-03-16 14:44:07 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def raideur_quadrangle(quadrangle):\n",
2022-04-03 20:18:44 +00:00
" \"\"\"Construction de la matrice de raideur ́elementaire relative à un ́élément quadrangle.\n",
"\n",
" Args:\n",
" quadrangle: les coordonnées x et y des quatres points formant le quadrangle.\n",
"\n",
" Returns:\n",
" M: La matrice de raideur ́elementaire.\n",
" \"\"\"\n",
2022-03-16 14:44:07 +00:00
" x = quadrangle[:, 0]\n",
" y = quadrangle[:, 1]\n",
"\n",
2022-04-03 20:18:44 +00:00
" # calcul de la jacobienne et de son déterminant\n",
2022-03-16 14:44:07 +00:00
" J_kk = np.array([[x[1] - x[0], x[3] - x[0]], [y[1] - y[0], y[3] - y[0]]])\n",
" det_J_kk = np.linalg.det(J_kk)\n",
"\n",
" # on récupère les coefficients\n",
" coeffs = np.linalg.inv(np.matmul(J_kk.T, J_kk))\n",
" a = coeffs[0, 0]\n",
" b = coeffs[0, 1]\n",
" c = coeffs[1, 1]\n",
"\n",
" # on calcul M (on a calculé toutes les intégrales au préalable)\n",
" M = np.array(\n",
" [\n",
" [2 * a + 3 * b + 2 * c, -2 * a + c, -a - 3 * b - c, a - 2 * c],\n",
" [-2 * a + c, 2 * a - 3 * b + 2 * c, a - 2 * c, -a + 3 * b - c],\n",
" [-a - 3 * b - c, a - 2 * c, 2 * a + 3 * b + 2 * c, -2 * a + c],\n",
" [a - 2 * c, -a + 3 * b - c, -2 * a + c, 2 * a - 3 * b + 2 * c],\n",
" ]\n",
" )\n",
"\n",
" return det_J_kk / 6 * M\n",
"\n",
2022-04-03 20:18:44 +00:00
"# on affiche la première matrice de raideur pour vérifier\n",
2022-03-16 14:44:07 +00:00
"raideur_quadrangle(ccs[e4[0]])"
]
2022-03-15 07:04:08 +00:00
},
{
"cell_type": "code",
2022-04-03 20:18:44 +00:00
"execution_count": 70,
2022-03-15 07:04:08 +00:00
"metadata": {},
2022-04-03 20:18:44 +00:00
"outputs": [],
2022-03-16 14:44:07 +00:00
"source": [
2022-04-03 20:18:44 +00:00
"def assemblage_quadrangle(coordinates, elements4):\n",
" \"\"\"Assemblage de la matrice A dans le cas d'un maillage constitué uniquement d'éléments quadrangles.\n",
"\n",
" Args:\n",
" coordinates: matrice a deux colonnes. Chaque ligne contient les coordonnes 2D d'un des points de la discretisation. Ces sommets seront identifies a l'indice de la ligne correspondante dans la matrice coordinates.\n",
" elements4: matrice a quatre colonnes. Chaque ligne contient les indices des sommets d'un element quadrangle, dans le sens antihoraire.\n",
"\n",
" Returns:\n",
" A: matrice nécéssaire à la résolution de la formulation variationnelle du problème.\n",
" \"\"\"\n",
" Ns = len(coordinates)\n",
2022-03-16 14:44:07 +00:00
" A = np.zeros((Ns, Ns))\n",
2022-04-03 20:18:44 +00:00
"\n",
" for quadrangle in elements4:\n",
" M = raideur_quadrangle(coordinates[quadrangle])\n",
2022-03-16 14:44:07 +00:00
" for i, a in enumerate(quadrangle):\n",
" for j, b in enumerate(quadrangle):\n",
" A[a, b] += M[i, j]\n",
2022-04-03 20:18:44 +00:00
" \n",
" return A"
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {},
"outputs": [],
"source": [
"def second_membre_quadrangle(coordinates, elements4):\n",
" \"\"\"Calcul le second membre.\n",
2022-03-16 14:44:07 +00:00
"\n",
2022-04-03 20:18:44 +00:00
" Args:\n",
" coordinates: matrice a deux colonnes. Chaque ligne contient les coordonnes 2D d'un des points de la discretisation. Ces sommets seront identifies a l'indice de la ligne correspondante dans la matrice coordinates.\n",
" elements4: matrice a quatre colonnes. Chaque ligne contient les indices des sommets d'un element quadrangle, dans le sens antihoraire.\n",
"\n",
" Returns:\n",
" b: vecteur b nécéssaire à la résolution de la formulation variationnelle du problème, sans les conditions de Dirichlet.\n",
" \"\"\"\n",
" Ns = len(coordinates)\n",
2022-03-16 14:44:07 +00:00
" b = np.zeros(Ns)\n",
2022-04-03 20:18:44 +00:00
" for quadrangle in elements4:\n",
" coords_quadrangle = coordinates[quadrangle]\n",
" centre = np.mean(coords_quadrangle, 0)\n",
" x = coords_quadrangle[:, 0]\n",
" y = coords_quadrangle[:, 1]\n",
2022-03-16 14:44:07 +00:00
"\n",
2022-04-03 20:18:44 +00:00
" alpha = calcul_alpha(x, y)\n",
2022-03-16 14:44:07 +00:00
"\n",
" b[quadrangle] += alpha / 4 * f(centre[0], centre[1])\n",
"\n",
2022-04-03 20:18:44 +00:00
" return b"
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {},
"outputs": [],
"source": [
"def condition_neumann(coordinates, neumann):\n",
" \"\"\"Calcul le vecteur nécéssaire à l'application des conditions de Neumann.\n",
2022-03-16 14:44:07 +00:00
"\n",
2022-04-03 20:18:44 +00:00
" Args:\n",
" coordinates: matrice a deux colonnes. Chaque ligne contient les coordonnes 2D d'un des points de la discretisation. Ces sommets seront identifies a l'indice de la ligne correspondante dans la matrice coordinates.\n",
" neumann: vecteur colonne des indices des sommets de la frontiere de Neumann.\n",
"\n",
" Returns:\n",
" Ud: vecteur pour appliquer les conditions de Neumann.\n",
" \"\"\"\n",
" Ns = len(coordinates)\n",
2022-03-16 14:44:07 +00:00
" coeffs = np.zeros(Ns)\n",
2022-04-03 20:18:44 +00:00
" for i, j in neumann:\n",
" point1 = coordinates[i]\n",
" point2 = coordinates[j]\n",
2022-03-16 14:44:07 +00:00
" \n",
" valeur = np.linalg.norm(point1 - point2) / 2 * g((point1 + point2) / 2)\n",
" coeffs[i] += valeur\n",
" coeffs[j] += valeur\n",
"\n",
2022-04-03 20:18:44 +00:00
" return coeffs"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPoAAADyCAYAAABkv9hQAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAABfUUlEQVR4nO29d3xb9b3//zySLHnvbccrjhNnOHESJwFKwiiQBkhSWiCllz0KJdAWektp++ul3G8pty23ixZuIW1pyyYFUkYoexWyvEdsx3svecnW1vn94UiRZY0jWbKdWM/HI5DYR+cc2Xqdz/vznoIoigQJEuTMRjbfNxAkSJDAExR6kCCLgKDQgwRZBASFHiTIIiAo9CBBFgFBoQcJsghQePh+MPYWJEjgEQJ9geCKHiTIIiAo9CBBFgFBoQcJsggICj1IkEVAUOhBgiwCgkIPEmQREBR6kCCLgKDQgwRZBASFHiTIIiAo9CBBFgFBoQcJsggICj1IkEVAUOhBgiwCgkIPEmQREBR6kCCLgKDQ5wFRFDEYDJhMJoLttoPMBZ4aTwTxMxaLBYPBgE6ns31NLpcTEhKCQqFALpcjCAHvQxBkkSF4WFGC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ITYPNILKZUSAvMQ8kWUrhx71lLcsLAwDAYDOp3Or449Kc644IqO/0x1R6SutAaDgaqqKiIiIigpKeHQoUNerVK+CN1oNFJRUcGaNWuIjo6e8UAKDQ0lPT2d9PR0+vv7UavV6HQ6qqurbQ0jpO5N54L5WNHd4azH3sDAAK2trX5x7NljNpvdFjEteq+7t7Fxb3/5UoQ+MjJCTU0N+fn5pKSkTHu
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"# calcul de premier membre de l'équation\n",
2022-03-16 14:44:07 +00:00
"A3 = assemblage(ccs, e3)\n",
"A4 = assemblage_quadrangle(ccs, e4)\n",
"A = A3 + A4\n",
"\n",
2022-04-03 20:18:44 +00:00
"# calcul du second membre de l'équation\n",
"b3 = second_membre(ccs, e3)\n",
"b4 = second_membre_quadrangle(ccs, e4)\n",
"b = b3 + b4\n",
2022-03-16 14:44:07 +00:00
"\n",
2022-04-03 20:18:44 +00:00
"# calcul de Ud pour les conditions de Dirichlet\n",
2022-03-16 14:44:07 +00:00
"U_d = calcul_Ud(ccs, dds)\n",
2022-04-03 20:18:44 +00:00
"\n",
"# modifiction de b pour vérifier Dirichlet\n",
2022-03-16 14:44:07 +00:00
"b -= np.dot(A, U_d)\n",
"\n",
2022-04-03 20:18:44 +00:00
"# modification de b pour vérifier Neumann\n",
"b += condition_neumann(ccs, nns)\n",
2022-03-16 14:44:07 +00:00
"\n",
2022-04-03 20:18:44 +00:00
"# on enlève les conditions aux bords (Dirichlet) avant résolution\n",
2022-03-16 14:44:07 +00:00
"A_tild, b_tild, ccs_tild = tildage(A, b, ccs, dds)\n",
"\n",
2022-04-03 20:18:44 +00:00
"# on résoud le système\n",
2022-03-16 14:44:07 +00:00
"x = np.linalg.solve(A_tild, b_tild)\n",
2022-04-03 20:18:44 +00:00
"\n",
"# on remet les conditions aux bords (Dirichlet)\n",
2022-03-16 14:44:07 +00:00
"x_untild = untildage(x, dds, U_d)\n",
"\n",
2022-04-03 20:18:44 +00:00
"# on affiche le résultat\n",
"show(ccs, x_untild)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Compléments d'analyse du système\n"
2022-03-16 14:44:07 +00:00
]
2022-03-24 07:10:59 +00:00
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
2022-04-03 20:18:44 +00:00
"### Analyse de l’ ordre du schéma de discrétisation dans le cas d'éléments Triangle\n"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {},
"outputs": [],
"source": [
"def f(x, y):\n",
" return 2 * np.pi ** 2 * np.sin(np.pi * x) * np.sin(np.pi * y)\n",
"\n",
"\n",
"def u_ex(x, y):\n",
" return np.sin(np.pi * x) * np.sin(np.pi * y)\n",
"\n",
"\n",
"def u_d(x, y):\n",
" return np.zeros(x.shape[0])"
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"98/98\r"
]
}
],
"source": [
"erreurs = []\n",
"hs = []\n",
"range_n = range(3, 100, 5)\n",
"\n",
"for n in range_n:\n",
" print(f\"{n}/{max(range_n)}\", end=\"\\r\")\n",
" coords, elems3, dirichlet, neumann = maillage_carre(n)\n",
"\n",
" A = assemblage(coords, elems3)\n",
" b = second_membre(coords, elems3)\n",
" U_d = calcul_Ud(coords, dirichlet)\n",
" b -= np.dot(A, U_d)\n",
"\n",
" A_tild, b_tild, coords_tild = tildage(A, b, coords, dirichlet)\n",
"\n",
" x = np.linalg.solve(A_tild, b_tild)\n",
" x_untild = untildage(x, dirichlet, U_d)\n",
" x_ex = u_ex(coords[:, 0], coords[:, 1])\n",
"\n",
" v = x_untild - x_ex\n",
" h = np.sqrt(1/len(v))\n",
" hs.append(h)\n",
" erreur = h * np.linalg.norm(v)\n",
" erreurs.append(erreur)"
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"regression linéaire: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bbbSEhIoLCwkCeffJLY2Fi8vLx4++23iYqKYv78+SxbtozLly+TlpbG1KlTeeutt2o1dkI0NKsTTvLK4oNcLrby1pjm3OV3EI+zF6BDf+h+MzRqanTE62JIYVBKvQ5MAWzAaeBhrfUJI7I4S0pKCl988QWXLl1i4cKF7N69G601kydPZsuWLTRt2pRFixYRHx9PSUkJgwcPJjw8/Or3i4uLiY2NpaSkhNGjR7N06VLatm3L999/z5w5c/jss8948803ycjIoLi4GKvVCsDcuXP56KOPGDlyJBaLBe9fFLePPvoIpRQHDx4kMTGRcePGkZycDMD+/fvZt28fTZo0oXfv3jzzzDMEBQXV3aAJYTKXCkv4y9JDLN53nPBAbz4cdokOl/eDagkD7oFWwUZHdAqj9hj+obX+M4BS6lngf4Hrv+9zNb/ZV6U0Lw+uo+12ly5dGD58OLNnz2bt2rVXexFZLBZSUlLIy8tjypQpeHt74+3tfbXN9hUzZswAqm6D3b9/f2bOnMn48eO59957gbKmeS+88AIzZ85k2rRpdOpUvj3v1q1beeaZZwDo06cPXbp0uVoYxowZQ/PmzQHo168fWVlZUhiEqMT21DPMXhDPqbxCXrvBg/tbJ+BZUAidh9sb3jUyOqLTGFIYtNbX3mbNFzD9Xe6vtMHWWvPKK6/w+OOPl/v83Xffdfj7lbXB/umnn9iyZQuLFi3i7bff5uDBg/zhD3/g1ltvZeXKlYwcOZI1a9b8aq+hMr9sFV5aWurQ94RoSApLrLy1OonPtmUQ1hq+HXeGrvoEeLeH3jPAv73REZ3OsDkGpdRfgQe
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"log_hs = np.log(hs)\n",
"log_erreurs = np.log(erreurs)\n",
"\n",
"# affichage des erreurs\n",
"plt.plot(log_hs, log_erreurs, label=\"numérique\")\n",
"\n",
"# regression linéaire\n",
"coeffs = np.polyfit(log_hs, log_erreurs, 1)\n",
"reg = np.poly1d(coeffs)\n",
"\n",
"# affichage de la regression linéaire\n",
"plt.plot(log_hs, reg(log_hs), alpha=0.5, label=\"regression\")\n",
"plt.xlabel(\"log(h)\")\n",
"plt.ylabel(\"log(erreur)\")\n",
"plt.grid()\n",
"plt.legend()\n",
"\n",
"print(f\"regression linéaire: {reg}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Résolution du système linéaire par une méthode directe\n"
]
},
{
"cell_type": "code",
"execution_count": 77,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"98/98\r"
]
}
],
"source": [
"zeros_A = []\n",
"zeros_L = []\n",
"range_n = range(3, 100, 5)\n",
"\n",
"for n in range_n:\n",
" print(f\"{n}/{max(range_n)}\", end=\"\\r\")\n",
" coords, elems3, dirichlet, neumann = maillage_carre(n)\n",
"\n",
" A = assemblage(coords, elems3)\n",
"\n",
" A_tild = np.delete(A, dirichlet, 0)\n",
" A_tild = np.delete(A_tild, dirichlet, 1)\n",
"\n",
" L = np.linalg.cholesky(A_tild)\n",
"\n",
" zeros_A.append(len(np.where(A == 0)[0]))\n",
" zeros_L.append(len(np.where(L == 0)[0]))"
]
},
{
"cell_type": "code",
"execution_count": 78,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.legend.Legend at 0x7faf9ed53a30>"
]
},
"execution_count": 78,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAXkAAAERCAYAAACepNcKAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAtWElEQVR4nO3deXhU1f3H8ffJThYChE0IkrCJCIKC7CqIWnfcxbrgikurttpWra3W2tr2Z6tSW9u6ohVBxQVQlLJWWWXf97AkkLAkJGTf5vz+uEPJSgJkciczn9fzzJOZe+7c+z1zw5eTc8+cY6y1iIhIYApxOwAREfEdJXkRk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fgpkrIXr3oCwyEaPrb7UkhcRqcGK3Yf5dutBxl3QhZiqrfiyYpj7gvPN1j43uRNgPaklLyJSg1dnbyUhJoI7h3SuXrjsLcjeA7d/BiH+3Vb27+hERFywfFcW3207xAMXdiE6okpbuDAbvn0JuoyAbqPcCO+EKMmLiFTx6uxttI6N4PbBNbTiF77qTCl88fONHtfJUJIXEalg2a4sFmw/xAMXdK3eis/Z6ywK0ucm6NDPlfhOlJK8iEgFr8zaSuvYyJpb8fNfBOuBi37V+IGdJCV5ERGvpSmZLNqRyYMXdqFZRGjlwgObYPWHcN590DLJlfhOhpK8iIjXK7O30iaullb87N9ARCyc/7NGj+tUKMmLiACLd2SyJCWLhy7sSlR4lVb8roWw9RsY/hOISXAlvpOlJC8iQc9ayyuzt9I2LpI
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.plot(range_n, zeros_A, label=\"A\")\n",
"plt.plot(range_n, zeros_L, label=\"L\")\n",
"plt.xlabel(\"n\")\n",
"plt.ylabel(\"#zéros\")\n",
"plt.grid()\n",
"plt.legend()"
2022-03-24 07:10:59 +00:00
]
2022-03-15 07:04:08 +00:00
}
],
"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",
2022-04-03 20:18:44 +00:00
"version": "3.10.4"
2022-03-15 07:04:08 +00:00
}
},
"nbformat": 4,
"nbformat_minor": 4
}