2022-03-15 07:04:08 +00:00
{
"cells": [
{
"cell_type": "code",
2022-03-16 14:44:49 +00:00
"execution_count": 158,
2022-03-15 07:04:08 +00:00
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import mpl_toolkits.mplot3d\n",
"import numpy as np\n",
"import scipy.sparse as scps\n",
"import scipy.sparse.linalg as ssl\n",
"import math"
]
},
{
"cell_type": "code",
2022-03-16 14:44:49 +00:00
"execution_count": 159,
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",
" n (int): nombre de points par cote du care => Npts points de discretisation au total\n",
"\n",
" Returns:\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",
" 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",
" \"\"\"\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-03-16 14:44:49 +00:00
"execution_count": 160,
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",
" elements3 : matrice a trois colonnes contenant les elements triangles de la discretisation, identifies par les indices de leurs trois sommets.\n",
" coordinates : matrice a deux colonnes contenant les coordonnes 2D des points de la discretisation.\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",
"\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": [
"**Partie I : maillage triangulaire et conditions de Dirichlet**\n"
]
},
{
"cell_type": "code",
2022-03-16 14:44:49 +00:00
"execution_count": 161,
2022-03-15 07:04:08 +00:00
"metadata": {},
"outputs": [],
"source": [
"def f(x, y):\n",
2022-03-16 14:44:41 +00:00
" # return 2 * np.pi ** 2 * np.sin(np.pi * x) * np.sin(np.pi * y)\n",
" try:\n",
" return np.ones(x.shape[0])\n",
" except:\n",
" return 1\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-03-16 14:44:07 +00:00
" # return np.zeros(x.shape[0])\n",
" # return 1\n",
" return np.ones(x.shape[0])\n",
2022-03-15 07:04:08 +00:00
"\n",
"def g(x):\n",
2022-03-16 14:44:07 +00:00
" # return np.cos(x)\n",
" return 1"
2022-03-15 07:04:08 +00:00
]
},
{
"cell_type": "code",
2022-03-16 14:44:49 +00:00
"execution_count": 162,
2022-03-15 07:04:08 +00:00
"metadata": {},
"outputs": [
{
"data": {
2022-03-16 14:44:49 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAADyCAYAAACLfbNuAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAACEsElEQVR4nO29d3hkd3X//7rTm0Yzo96llbb36oZtSgBj3Kg2JAZTY0I3JIGEJ3EK5QGSfPPFlN8XnJhQjLEN2GCzAQw2GBt7d70rrXZXq97LjKb3en9/jO7dGWmatJJ21zvv5/EDq7lz752Zez7nfM55n/cRRFGkjDLKePlDcaFvoIwyylgflI29jDIuE5SNvYwyLhOUjb2MMi4TlI29jDIuE5SNvYwyLhOoirxersuVUcbaQ1iPi5Q9exll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IUE4lEcLlcjI+PEwgEMBqNsvGvtnGuxtiqxcg1zroUZNb429raSKVS+Hw+ec/v9/sZGRmhqqpqVWv8xb7TUChUNvbVQL7aeSkeN5VKcfbsWcLhMAcPHswaj1QqCtXmJabd5s2bqa6uXtZ5zwc6nY7GxkYaGxvlUNflctHf34/f78doNMr1b7VavW73VSpWawFRKBRYLBYsFgsdHR0cOXKEqqoqvF4vY2NjAOtS44/H4xeMOZgPl5yxF6qdK5XKglnyUChET08P9fX1cqJsJRrtuRJ0oigyOjqK3W7PW7IrFedbZ88MdVtbWxkbGyORSBAIBJiYmEAURSwWCzabbUUP/Fp59rUKt6urq+WFN5FI4PF4cDqd59XHf7HnQHLhkjH2UmrnCoUib1PL7OwsQ0ND7Ni
2022-03-15 07:04:08 +00:00
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"n = 10\n",
"coords, elems3, dirichlet, neumann = maillage_carre(n)\n",
"show(coords, f(coords[:, 0], coords[:, 1]))\n",
"# show(coords, u_ex(coords[:, 0], coords[:, 1]))\n",
"# print(maillage_carre(3))"
]
},
{
"cell_type": "code",
2022-03-16 14:44:49 +00:00
"execution_count": 163,
2022-03-15 07:04:08 +00:00
"metadata": {},
"outputs": [],
"source": [
"def raideur(triangle):\n",
" M = np.zeros((3, 3))\n",
" x = triangle[:, 0]\n",
" y = triangle[:, 1]\n",
"\n",
" # calcul de alpha\n",
" 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",
" alpha = np.linalg.det(mat_alpha)\n",
"\n",
"\n",
" 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",
" return M / alpha / 2"
]
},
{
"cell_type": "code",
2022-03-16 14:44:49 +00:00
"execution_count": 164,
2022-03-15 07:04:08 +00:00
"metadata": {},
"outputs": [
{
2022-03-15 07:05:49 +00:00
"data": {
2022-03-16 14:44:49 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPsAAADyCAYAAACLfbNuAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAC+1UlEQVR4nOz9eZRdWXbWi/7W7k8fcaIPhfoulcpeKdku7AIuPC7w7oDBfdQDc9+zDeaCMfajuxgwxmBz7QsYYxv7YsC4KRqXwQbcFlUu92W70qnMlJTqUr0Uir45/Tm7X+v9sfY5pVSqiYiUlMrK+MbIkZkRp9lxzp5rzTXnN79PKKXYxja28aUP44O+gG1sYxtPBtvBvo1tfESwHezb2MZHBNvBvo1tfESwHezb2MZHBNvBvo1tfERgPeT32325bWzj8UM8iTfZ3tm3sY2PCLaDfRvb+IhgO9i3sY2PCLaDfRvb+IhgO9i3sY2PCLaDfRvb+IhgO9i3sY2PCLaDfRvb+IhgO9i3sY2PCLaDfRvb+IhgO9i3sY2PCLaDfRvb+IhgO9i3sY2PCLaDfRvb+IhgO9i3sY2PCLaD/QOAUoooikiShG0p7208KTxMvGIbjxhSSqIoIgiCwc9M08S2bSzLwjRNhHgiWgbb+IhBPGRn2d52HhGUUiRJQpIkCCGI43jwc6UUUspBkIdhSKlUwnGc7eD/aOCJfMHbO/sTQD9tvzOg+xBCIITAMIzBY69du8aePXvI5/PA9s6/jUeD7WB/zEiShLm5OdI0ZceOHQghBrv5vYK2H/ymaWKa5mDX931/8HjLsgb/bAf/NjaK7WB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288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPcAAADyCAYAAACRQVPgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAADENElEQVR4nOz9d5heWX7Xi37WWju9sXJQlVTKsdXqoFbPjDn3mnuI9nNteLgc7oXLwVwbzsUH+8A55gAGXxwwDjgQbGODx8YmGYPHOHucxvYAnh6pW2rlHEqqKlUOb9pxrXX/2PXWlKolVWhJ091T3+fR0+rSu/d+a+/13b/f+oXvT1hr2cY2tvHRg/xif4FtbGMbzwfb5N7GNj6i2Cb3NrbxEcU2ubexjY8otsm9jW18RLFN7m1s4yMKZ51/386TbWMbzx/ieZx023JvYxsfUWyTexvb+Ihim9zb2MZHFNvk3sY2PqLYJvc2tvERxTa5t7GNjyi2yb2NbXxEsU3ubWzjI4ptcm9jGx9RbJN7G9v4iGKb3NvYxkcU2+TexjY+otgm9za28RHFNrm3sY2PKLbJvY1tfESxTe4vAqy1JElClmVsS0tv43lhPbGGbTxjGGNIkoQoilZ+ppTCdV0cx0EphRDPpXd/G19iEOtYjm2z8oxgrSXLMrIsQwhBmqYrP7fWYoxZIXUcx1QqFTzP2yb7lwaeywPettwvAG03fDWB2xBCIIRASrny2du3b7Nnzx6KxSKwbdm3sTVsk/s5I8syxsbG0FozPDyMEGLFWj+OpG2yK6VQSq1Y9TAMVz7vOM7Kn22yb+NJ2Cb3c8JqN9wYs+KObxaPs+xaa7IsW/mM4zgrll1KuU32bQDb5H4uMMaQpumKG9621hvF0z7fPl8ba8kuhHjEsm+T/UsX2+R+hmgTrR0sa1vbJ5H1Sa75ZvA4smdZtvId2lbfcRw8z9sm+5cQtsn9jGCtJU1TtNbvIdxacq9nzTdr6dceu5bsY2NjAOzYsWPbsn8J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u+etlqtbXJvBU/KXT+LtNZapGnKpUuXCIJgxQ1vNpvbSp+PQaFQYHh4eKVMttlsMj8/z40bN4jjmEqlshKJ9zzvkWM/bG75ekjT9D2/44vGh47cT8tdK6XQWm/qfE8j99LSEpcvX2bfvn0r1ql9zPuxhm2xhjRN6enped958ReNjRBRCEG5XKZcLq+UybYj8ePj42itHymTfZ4W9nnFRT7o+NCQeyO5aynlpptAHkfudsPBw4cPefXVVykWi4/8+/shn9aay5cvA1AsFlesWrVaXbFqH3RsxcpKKeno6KCjo4O9e/eitWZxcZGFhQXu3bu38gwWFhbo6Oj4oqeRnob1nv3z8kI2iw8FuTeau34Wbnmaply+fBnP8zh16tRjGy+2ch3IgywXLlxg165dDA4OkmXZe5o/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"
2022-03-15 07:04:08 +00:00
}
],
"source": [
"def assemblage(coords, elems3):\n",
" Ns = len(coords)\n",
" A = np.zeros((Ns, Ns))\n",
" for triangle in elems3:\n",
" M = raideur(coords[triangle])\n",
" for i, a in enumerate(triangle):\n",
" for j, b in enumerate(triangle):\n",
" A[a, b] += M[i, j]\n",
" return A\n",
"\n",
"\n",
"def second_membre(coords, elem3, f):\n",
" Ns = len(coords)\n",
" b = np.zeros(Ns)\n",
" for triangle in elem3:\n",
" coords_triangle = coords[triangle]\n",
" centre = np.mean(coords_triangle, 0)\n",
"\n",
" # calcul de alpha\n",
" x = coords_triangle[:, 0]\n",
" y = coords_triangle[:, 1]\n",
" mat_alpha = np.array([[x[1] - x[0], x[2] - x[0]], [y[1] - y[0], y[2] - y[0]]])\n",
" alpha = np.linalg.det(mat_alpha)\n",
"\n",
" b[triangle] += alpha / 6 * f(centre[0], centre[1])\n",
"\n",
" return b\n",
"\n",
"\n",
"def calcul_Ud(coords, dirichlet):\n",
" Ns = len(coords)\n",
" U = np.zeros(Ns)\n",
" # for d in dirichlet:\n",
" # x, y = coords[d].flatten()\n",
" # U[d] = u_d(x, y)\n",
" U[dirichlet.T] = u_d(coords[dirichlet, 0], coords[dirichlet, 1])\n",
"\n",
" return U\n",
"\n",
"\n",
"def tildage(A, b, coords, dirichlet):\n",
" A_tild = np.delete(A, dirichlet, 0)\n",
" A_tild = np.delete(A_tild, dirichlet, 1)\n",
" b_tild = np.delete(b, dirichlet, 0)\n",
" coords_tild = np.delete(coords, dirichlet, 0)\n",
"\n",
" return A_tild, b_tild, coords_tild\n",
"\n",
"\n",
"def untildage(x, dirichlet, U_d):\n",
" 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",
" # print(x_untild)\n",
" # print(not_dirichlet)\n",
" # print(dirichlet)\n",
" # print(x)\n",
2022-03-15 07:04:08 +00:00
"\n",
" x_untild[dirichlet] = U_d[dirichlet]\n",
" x_untild[not_dirichlet] = x\n",
"\n",
" return x_untild\n",
"\n",
"n = 50\n",
"coords, elems3, dirichlet, neumann = maillage_carre(n)\n",
"\n",
"A = assemblage(coords, elems3)\n",
"b = second_membre(coords, elems3, f)\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",
"\n",
"# show(coords_tild, x)\n",
"# print(coords.shape, x_untild.shape)\n",
"# print(coords, x_untild)\n",
"show(coords, x_untild)\n",
"show(coords, u_ex(coords[:, 0], coords[:, 1]))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Partie II : maillage mixte et ajoût des conditions de Neumann**\n"
]
},
{
"cell_type": "code",
2022-03-16 14:44:49 +00:00
"execution_count": 165,
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",
" [0.0, 0.0],\n",
" [1 / 3, 0],\n",
" [0.53333333333333, 0.0],\n",
" [2 / 3, 1 / 3],\n",
" [1.0, 0.47],\n",
" [1, 2 / 3],\n",
" [1.0, 1.0],\n",
" [2 / 3, 1.0],\n",
" [1 / 3, 1.0],\n",
" [0.0, 1.0],\n",
" [0.0, 2 / 3],\n",
" [0.0, 1 / 3],\n",
" [1 / 3, 1 / 3],\n",
" [1 / 3, 2 / 3],\n",
" [2 / 3, 2 / 3],\n",
" [1.0, 0.0],\n",
" ]\n",
")"
]
},
{
"cell_type": "code",
2022-03-16 14:44:49 +00:00
"execution_count": 166,
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-03-16 14:44:49 +00:00
"execution_count": 166,
2022-03-16 14:44:07 +00:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def raideur_quadrangle(quadrangle):\n",
" x = quadrangle[:, 0]\n",
" y = quadrangle[:, 1]\n",
"\n",
" # calcul de la jacobienne\n",
" J_kk = np.array([[x[1] - x[0], x[3] - x[0]], [y[1] - y[0], y[3] - y[0]]])\n",
"\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",
"raideur_quadrangle(ccs[e4[0]])"
]
2022-03-15 07:04:08 +00:00
},
{
"cell_type": "code",
2022-03-16 14:44:49 +00:00
"execution_count": 167,
2022-03-15 07:04:08 +00:00
"metadata": {},
2022-03-16 14:44:07 +00:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2022-03-16 14:44:49 +00:00
"[-0.30555556 1.63888889 -1.67777778 2.11685185 -1.69356874 1.65116133\n",
" -0.30555556 -0.94444444 -0.61111111 -0.30555556 -0.61111111 -0.94444444\n",
" 1.31296296 1.77777778 1.31777778 -0.35296296]\n"
2022-03-16 14:44:07 +00:00
]
},
{
"data": {
2022-03-16 14:44:49 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPoAAADyCAYAAABkv9hQAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAABerElEQVR4nO2dd3xb9b3330eSJe+97XgkjrOcYSdOApSE0RIaSpLSAiktu6VwGS20t5S2Ty/tvaU83YMWnkvTlrJHCqSMUHaBQpb3iPdesi0P2dbWef5wpMiyxpEs2U6s9+sVSOyjc45sfc7v+/tOQRRFQoQIcXYjW+gbCBEiRPAJCT1EiCVASOghQiwBQkIPEWIJEBJ6iBBLgJDQQ4RYAii8fD8UewsRIvgIwb5AaEUPEWIJEBJ6iBBLgJDQQ4RYAoSEHiLEEiAk9BAhlgAhoYcIsQQICT1EiCVASOghQiwBQkIPEWIJEBJ6iBBLgJDQQ4RYAoSEHiLEEiAk9BAhlgAhoYcIsQQICT1EiCVASOgLgCiKGI1GzGYzoXbbIeYDb40nQgQYq9WK0WhEr9fbvyaXywkLC0OhUCCXyxGEoPchCLHEELysKKHlJkCIoojZbMZsNiMIAiaTyf51URSxWq12gRsMBmJiYlAqlSHhLw2C/gsOrejzgM1UdxSzDUEQEAQBmUxmP7alpYW8vDwiIyOB0IofYu6EhB5kzGYz3d3dWCwWsrKyEATBvoq7EqxN+HK5HLlcbl/tdTqd/XiFQmH/ExJ+CCmEhB4kHE11q9VqN9l9xdWKb7FYMJvN9mMUCoV9xZfJZCHhh5hFSOhBwGq1YjKZ7Ka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ASqUiNze
2022-03-16 14:44:07 +00:00
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"def assemblage_quadrangle(coords, elems4):\n",
" Ns = len(coords)\n",
" A = np.zeros((Ns, Ns))\n",
" for quadrangle in elems4:\n",
" M = raideur_quadrangle(coords[quadrangle])\n",
" for i, a in enumerate(quadrangle):\n",
" for j, b in enumerate(quadrangle):\n",
" A[a, b] += M[i, j]\n",
" return A\n",
"\n",
"def second_membre_quadrangle(coords, elem4, f):\n",
" Ns = len(coords)\n",
" b = np.zeros(Ns)\n",
" for quadrangle in elem4:\n",
" coords_triangle = coords[quadrangle]\n",
" centre = np.mean(coords_triangle, 0)\n",
"\n",
" # calcul de alpha\n",
" x = coords_triangle[:, 0]\n",
" y = coords_triangle[:, 1]\n",
" mat_alpha = np.array([[x[1] - x[0], x[2] - x[0]], [y[1] - y[0], y[2] - y[0]]])\n",
" alpha = np.linalg.det(mat_alpha)\n",
"\n",
" b[quadrangle] += alpha / 4 * f(centre[0], centre[1])\n",
"\n",
" return b\n",
"\n",
"def condition_neumann(ccs, nns):\n",
" Ns = len(ccs)\n",
" coeffs = np.zeros(Ns)\n",
" for i, j in nns:\n",
" point1 = ccs[i]\n",
" point2 = ccs[j]\n",
" \n",
" valeur = np.linalg.norm(point1 - point2) / 2 * g((point1 + point2) / 2)\n",
" coeffs[i] += valeur\n",
" coeffs[j] += valeur\n",
"\n",
" return coeffs\n",
"\n",
"#------------------------------------------------------------------------------------------------------------------------\n",
"\n",
"A3 = assemblage(ccs, e3)\n",
"A4 = assemblage_quadrangle(ccs, e4)\n",
"\n",
"b3 = second_membre(ccs, e3, f)\n",
"b4 = second_membre_quadrangle(ccs, e4, f)\n",
"\n",
"A = A3 + A4\n",
"b = b3 + b4\n",
"\n",
"# print(A)\n",
"\n",
"U_d = calcul_Ud(ccs, dds)\n",
"b -= np.dot(A, U_d)\n",
"b += condition_neumann(ccs, nns)\n",
"print(b)\n",
"\n",
"# print(b3)\n",
"# print(b4)\n",
"\n",
"# A_tild, b_tild, ccs_tild = tildage_quadrangle(A, b, ccs, dds, nns)\n",
"A_tild, b_tild, ccs_tild = tildage(A, b, ccs, dds)\n",
"\n",
"x = np.linalg.solve(A_tild, b_tild)\n",
"# print(x)\n",
"x_untild = untildage(x, dds, U_d)\n",
"\n",
"# print(A)\n",
"# print(b)\n",
"# print(U_d)\n",
"show(ccs, x_untild)\n",
"# show(ccs, u_ex(ccs[:, 0], ccs[:, 1]))"
]
2022-03-24 07:10:59 +00:00
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Compléments d'analyse du système**\n"
]
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",
"version": "3.10.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}