// poisson_1d.edp // // Discussion: // // Solve the Poisson equation over a 1D interval. // // - uxx + u = x, 0 < x < 1 // u(0) = u(1) = 0 // // Exact solution is u(x) = x - sinh(x)/sinh(1) // // Location: // // http://people.sc.fsu.edu/~jburkardt/freefem_src/poisson_1d/poisson_1d.edp // // Licensing: // // This code is distributed under the MIT license. // // Modified: // // 25 July 2015 // // Reference: // // Frederic Hecht, // Freefem++, // Third Edition, version 3.22 // cout << "\n"; cout << "poisson_1d\n"; cout << " FreeFem++ version\n"; cout << " Trick FreeFem++ into solving a 1D Poisson problem.\n"; // // Define the 1D problem on a long rectangular strip. // Use 100 intervals in X, and 1 in Y. // The parameters X and Y run from 0 to 1. // The [ ] option allows us to rescale X or Y. // int n = 100; mesh Th = square ( n, 1, [ x, (-1+2*y) / 10 ] ); // // Plot the mesh. // plot ( Th, wait = true, aspectratio = 1, ps = "poisson_1d_mesh.ps" ); // // Define Vh, the finite element space defined over Th, using P1 basis functions. // fespace Vh ( Th, P1 ); // // Define u and v, piecewise P1 continuous functions over Th. // Vh u, v; // // Define f, the right hand side function. // func f = x; // // Request a solution of the discrete weak system. // Note that the boundary condition is included, // defined on sides 2 and 4 of the square boundary. // solve Poisson ( u, v, solver = LU ) = int2d(Th) ( dx(u)*dx(v) + u*v ) - int2d(Th) ( f*v ) + on ( 2, 4, u = 0.0 ); // // Plot the solution. // plot ( u, wait = true, dim = 3, fill = true, ps = "poisson_1d_u.ps" ); // // Save the mesh file. // savemesh ( Th, "poisson_1d.msh" ); // // Terminate. // cout << "\n"; cout << "poisson_1d\n"; cout << " Normal end of execution.\n"; exit ( 0 );