2022-03-15 07:04:08 +00:00
{
"cells": [
{
"cell_type": "code",
2022-03-16 14:44:20 +00:00
"execution_count": 147,
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:20 +00:00
"execution_count": 148,
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:20 +00:00
"execution_count": 149,
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:20 +00:00
"execution_count": 150,
2022-03-15 07:04:08 +00:00
"metadata": {},
"outputs": [],
"source": [
"def f(x, y):\n",
2022-03-15 07:05:49 +00:00
" return 2 * np.pi ** 2 * np.sin(np.pi * x) * np.sin(np.pi * y)\n",
2022-03-16 14:44:07 +00:00
" # 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:20 +00:00
"execution_count": 151,
2022-03-15 07:04:08 +00:00
"metadata": {},
"outputs": [
{
"data": {
2022-03-16 14:44:20 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPYAAADyCAYAAAB+gzjeAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAAB8OUlEQVR4nO29d3hcZ5n+/zln+qj3almyZcu922kLIbRkAymUkCyQQqgBwpJAQkL4sYFdyhdIWMouWSAQajokgYQkEEiANHdLtmxLVi+WRm2k6eWc9/fHaEZTzhTJki3bc19XrlgzZ06ZOfd5nvcp9yMJIcgiiyzOLMin+gSyyCKL+UeW2FlkcQYiS+wssjgDkSV2FlmcgcgSO4sszkBkiZ1FFmcg9Gn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w2LPd/6TLy03/+wwHu4fIMelYUZ7HxVsaefeFm+b9/BbCzQwHz0wmUySVGO5Bn5iYiPSgRwfiTlUPenxxSjxOdQ4bFhmxw7lpn8/Hvn37OPfcc2d1A82V2IqisHPnTurq6qitrU27/WILnv3mpUN86/GX8QRUQMbr8DPmmeK1nr189Xe7ydcFWL+kiA++fQcXbW6aF1LON7G1HhbRPejh0len05lxD/pC/UbpXPGsxY5CdG46XA0225tnLumuwcFBPB4P5513Hnl5eRl95kRdca/Xy4EDByI3ZtgChW/MTB8ctkkXH7/vLxzsHECKcg2FJMH09yckmUnVxD973PzzJy8iKX+mOt/AG9bU8sG3bmdlXcWsz38hCJPJ7y1JEnl5eeTl5UV
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:20 +00:00
"execution_count": 152,
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:20 +00:00
"execution_count": 153,
2022-03-15 07:04:08 +00:00
"metadata": {},
"outputs": [
{
2022-03-15 07:05:49 +00:00
"data": {
2022-03-16 14:44:20 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPcAAADyCAYAAACRQVPgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAADDBklEQVR4nOz9eZRdWV7fiX723me8U8yDpFBISs1K5ZwSVbYfuO2Fn/08NWv5YeN+xnTZbUwDnvADm3bTLrDBmMk2NGAoJmO7sB9gJkM1ZqgyDZWVykwplZrHkBQRCsV4405n3Hu/P07cIKTUEKEMKYeK71q5MjPinnNunLO/5/fbv+H7E9ZatrCFLXz0IN/vL7CFLWzhyWCL3FvYwkcUW+TewhY+otgi9xa28BHFFrm3sIWPKLbIvYUtfEThPOL3W3myLWzhyUM8iZNuWe4tbOEjii1yb2ELH1FskXsLW/iIYovcW9jCRxRb5N7CFj6i2CL3FrbwEcUWubewhY8otsi9hS18RLFF7i1s4SOKLXJvYQsfUWyRewtb+Ihii9xb2MJHFFvk3sIWPqLYIvcWtvARxRa5t7CFjyi2yP0+wFpLmqbkec6WtPQWnhQeJdawhU2GMYY0TYnjePVnSilc18VxHJRSCPFEeve38EUG8QjLsWVWNgnWWvI8J89zhBBkWbb6c2stxphVUidJQrVaxfO8LbJ/ceCJPOAty/0U0HXD1xK4CyEEQgiklKufvXr1Krt376ZUKgFbln0Lj4ctcj9h5HnO5OQkWmt27NiBEGLVWt+PpF2yK6VQSq1a9SiKVj/vOM7qP1tk38KDsEXuJ4S1brgxZtUd3yjuZ9m11uR5vvoZx3FWLb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k8keuuFx9act9vdI9S6rFc7EcdY63l2rVrLCws8Morr9BoNFheXn7s7772vE8jALfZXkD3e7uuy9DQEENDQ0Dh1SwtLTE1NUWz2SQIgtX9erlcfigZ7jfeeDPwpMj9qHva6XS2yP04eFDuejPSWvciTVNOnz5NtVpddcObzeaW0ud94Ps+o6OjjI6OYq1djcRPTEysWrK1kfi1+LC55Y9ClmXv6tN/2vjQkfthuWulFFrrDZ3vYeTuBpIOHDiwap26x7wXa2itZWpqiizLGBgYeFfzxwcpdXY/rIeIQghKpRKlUokdO3ZgraXVarG0tMSlS5dIkuSuMtknaWGfVFzkg44PDbnXk7uWUm64CeR+5LbWcv36debm5nj55ZffZWXeC/nyPOfMmTM4jkOpVLqr+aO/v39D3WnvFx7HygohqFarVKtVxsfHMcbQaDRW3fjuc5ufn6e3txfH+eAuzUc9+yflhWwUH9w7uAbrzV1vhluepinvvPMO5XKZY8eObYqGWhetVovTp0+ze/duhoeHyfP8ruaPxcVFzpw5QxzHhGFIEAT09vZ+4OrBN8OrkFLS29tLb28ve/bsWS2kqdfrTExMIIRYteofNMGK9dTofxAI/oEn90ZG9zxuQK2Lrhu+f//+h6bTHsdyZ1nG6dOnee6556hWq6udSd3zdZs/du/ezdTUFK1Wi8XFRa5du/aeotBPCpv9HYQQhGHIvn37gOJ+LS0tvUuwor+//30tk4VHkzvP8w/EC/kDS+7HkT+SUm54z9291vXr15mdnb2vG36/66z3JWKM4eLFi2RZxh/9o3901d182OKUUlIqldi5cydQRKEXFxeZnJyk2Wyuloj29/e/L7nUJ2GV7j1ntwe7+5LtClbcunXrLsGK7j14mmTXWj90Pbbbbcrl8lP7Pg/CB5LcWmtarRae522oXvdx3OU0TYmiiDiOH+iG34v1Wu44jnn77bcZHh4mDMN17yPvPb/v+3eJNXRLRLuBqW7V2NP
2022-03-15 07:05:49 +00:00
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
},
{
"data": {
"image/png":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sMj8/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:20 +00:00
"execution_count": 154,
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:20 +00:00
"execution_count": 155,
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:20 +00:00
"execution_count": 155,
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": "markdown",
"metadata": {},
"source": [
"**Compléments d'analyse du système**\n"
]
},
{
"cell_type": "code",
2022-03-16 14:44:20 +00:00
"execution_count": 156,
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:20 +00:00
"[-0.19625549 1.80841983 -1.29709571 3.27946985 -1.31278846 1.81960843\n",
" -0.19625549 -0.58876648 -0.25543315 -0.19625549 -0.25543315 -0.58876648\n",
" 2.4657089 2.90036722 2.46946706 -0.14351276]\n"
2022-03-16 14:44:07 +00:00
]
},
{
"data": {
2022-03-16 14:44:20 +00:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAPgAAADyCAYAAABgSghtAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/YYfK9AAAACXBIWXMAAAsTAAALEwEAmpwYAABirklEQVR4nO2dd3hb9dn+P0eSJe894tiJneVMx3ESJyEUwoYGCNCyWyDQlsILdNBBaftr6QLeTtrSwlugpRQIIwHCTBmFQIEkTuLEK7EdO96x5W1Z1jzn/P5wjpBtjSNZsp1E93X5gkhnSTr3eZ7vM+5HkGWZCCKI4OSEZqovIIIIIggfIgSPIIKTGBGCRxDBSYwIwSOI4CRGhOARRHASI0LwCCI4iaHz834khxZBBOGHEK4DRyx4BBGcxIgQPIIITmJECB5BBCcxIgSPIIKTGBGCRxDBSYwIwSOI4CRGhOARRHASI0LwCCI4iREheAQRnMSIEDyCCE5iRAgeQQQnMSIEjyCCkxgRgkcQwUmMCMEjiOAkRoTgEURwEiNC8CmALMvY7XacTicR2eoIwgl/gg8RhBiSJGG327Fara7XtFotUVFR6HQ6tFotghC2/v8ITjEIfixIxLyECLIs43Q6cTqdCIKAw+FwvS7LMpIkuYhts9lISEhAr9dHCH9qIGw/cMSCTwIUl9ydxAoEQUAQBDQajWvb+vp68vPziY2NBSIWPoLgESF4mOF0OmltbUUURXJychAEwWW1PRFVIbxWq0Wr1bqsu8VicW2v0+lcfxHCR+ALEYKHCe4uuSRJLtc8UHiy8KIo4nQ6XdvodDqXhddoNBHCR+BChOBhgCRJOBwOl0uuWG0FZrOZuro6YmN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
]
},
"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-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
}