-- FreeFem++ v4.14 (mer. 06 mars 2024 16:59:04 CET - git v4.14-1-g2b2052ae) file : poisson_1d.edp Load: lg_fem lg_mesh lg_mesh3 eigenvalue 1 : // poisson_1d.edp 2 : // 3 : // Discussion: 4 : // 5 : // Solve the Poisson equation over a 1D interval. 6 : // 7 : // - uxx + u = x, 0 < x < 1 8 : // u(0) = u(1) = 0 9 : // 10 : // Exact solution is u(x) = x - sinh(x)/sinh(1) 11 : // 12 : // Licensing: 13 : // 14 : // This code is distributed under the MIT license. 15 : // 16 : // Modified: 17 : // 18 : // 25 July 2015 19 : // 20 : // Reference: 21 : // 22 : // Frederic Hecht, 23 : // Freefem++, 24 : // Third Edition, version 3.22 25 : // 26 : cout << "\n"; 27 : cout << "poisson_1d():\n"; 28 : cout << " FreeFem++ version\n"; 29 : cout << " Trick FreeFem++ into solving a 1D Poisson probl ... : em.\n"; 30 : // 31 : // Define the 1D problem on a long rectangular strip. 32 : // Use 100 intervals in X, and 1 in Y. 33 : // The parameters X and Y run from 0 to 1. 34 : // The [ ] option allows us to rescale X or Y. 35 : // 36 : int n = 100; 37 : mesh Th = square ( n, 1, [ x, (-1+2*y) / 10 ] ); 38 : // 39 : // Plot the mesh. 40 : // 41 : plot ( Th, wait = true, aspectratio = 1, ps = "poisson_1d_mesh.ps" ); 42 : // 43 : // Define Vh, the finite element space defined over Th, using P1 basis functions. 44 : // 45 : fespace Vh ( Th, P1 ); 46 : // 47 : // Define u and v, piecewise P1 continuous functions over Th. 48 : // 49 : Vh u, v; 50 : // 51 : // Define f, the right hand side function. 52 : // 53 : func f = x; 54 : // 55 : // Request a solution of the discrete weak system. 56 : // Note that the boundary condition is included, 57 : // defined on sides 2 and 4 of the square boundary. 58 : // 59 : solve Poisson ( u, v, solver = LU ) 60 : = int2d(Th) ( dx(u)*dx(v) + u*v ) 61 : - int2d(Th) ( f*v ) 62 : + on ( 2, 4, u = 0.0 ); 63 : // 64 : // Plot the solution. 65 : // 66 : plot ( u, wait = true, dim = 3, fill = true, ps = "poisson_1d_u.ps" ); 67 : // 68 : // Save the mesh file. 69 : // 70 : savemesh ( Th, "poisson_1d.msh" ); 71 : // 72 : // Terminate. 73 : // 74 : cout << "\n"; 75 : cout << "poisson_1d():\n"; 76 : cout << " Normal end of execution.\n"; 77 : 78 : exit ( 0 ); 79 : 80 : sizestack + 1024 =1744 ( 720 ) poisson_1d(): FreeFem++ version Trick FreeFem++ into solving a 1D Poisson problem. -- Square mesh : nb vertices =202 , nb triangles = 200 , nb boundary edges 202 SkyLineMatrix: size pL/pU: 202 10401 10401 moy=51.4901 -- Solve : min 1.48326e-32 max 0.0585228 number of required edges : 0 poisson_1d(): Normal end of execution. current line = 78 exit(0) err code 0 , mpirank 0 CodeAlloc : nb ptr 3890, size :520928 mpirank: 0 Ok: Normal End