-- FreeFem++ v4.14 (mer. 06 mars 2024 16:59:04 CET - git v4.14-1-g2b2052ae) file : membrane_error.edp Load: lg_fem lg_mesh lg_mesh3 eigenvalue 1 : // membrane_error.edp 2 : // 3 : // Discussion: 4 : // 5 : // Solve the membrane problem using a manufactured solution. 6 : // 7 : // We use a circular domain C with boundary Gamma1 + Gamma2. 8 : // 9 : // We have 10 : // u = sin ( x^2 + y^2 - 1 ) 11 : // for which we need to specify a nonhomogeneous Neumann condition on Gamma2. 12 : // 13 : // Licensing: 14 : // 15 : // This code is distributed under the MIT license. 16 : // 17 : // Modified: 18 : // 19 : // 28 July 2015 20 : // 21 : // Reference: 22 : // 23 : // Frederic Hecht, 24 : // Freefem++, 25 : // Third Edition, version 3.22 26 : // 27 : cout << "\n"; 28 : cout << "membrane_error():\n"; 29 : cout << " FreeFem++ version.\n"; 30 : cout << " Solve the membrane problem using a manufactured ... : solution.\n"; 31 : // 32 : // Define Gamma1 and Gamma2, the boundaries. 33 : // A and B are the lengths of the semimajor and semiminor axes: 34 : // THETA specifies the angle at which we switch from GAMMA1 to GAMMA2. 35 : // 36 : real a = 1.0; 37 : real b = 1.0; 38 : real theta = 4.0 * pi / 3.0; 39 : border Gamma1 ( t = 0, theta ) { x = a * cos(t); y = b*sin(t); } 40 : border Gamma2 ( t = theta, 2 * pi ) { x = a * cos(t); y = b*sin(t); } 41 : // 42 : // uexact: the exact solution. 43 : // 44 : func uexact = sin ( x^2 + y^2 - 1.0 ); 45 : // 46 : // Make space for the errors. 47 : // 48 : real[int] L2error(2); 49 : 50 : int n; 51 : 52 : for ( n = 0; n < 2; n++ ) 53 : { 54 : // 55 : // Define Th, the triangulation of the "left" side of the boundaries. 56 : // 57 : mesh Th = buildmesh ( Gamma1(20*(n+1)) + Gamma2(10*(n+1)) ); 58 : // 59 : // Define Vh, the finite element space defined over Th, using P2 basis functions. 60 : // 61 : fespace Vh ( Th, P2 ); 62 : // 63 : // Define U and V, piecewise P2 continuous functions over Th. 64 : // 65 : Vh u; 66 : Vh v; 67 : // 68 : // Define F, the right hand side. 69 : // 70 : func f = - 4.0 * ( cos ( x^2 + y^2 - 1.0 ) 71 : - ( x^2 + y^2 ) * sin ( x^2 + y^2 - 1.0 ) ); 72 : // 73 : // Solve the problem. 74 : // 75 : solve Laplace ( u, v ) 76 : = int2d ( Th ) ( dx(u)*dx(v) + dy(u)*dy(v) ) 77 : - int2d ( Th ) ( f * v ) 78 : - int1d ( Th, Gamma2 ) ( 2.0 * v ) 79 : + on ( Gamma1, u = 0.0 ); 80 : // 81 : // Plot the solution. 82 : // 83 : plot ( u, fill = true, wait = true, ps = "membrane_error_u_"+n+".ps" ); 84 : // 85 : // Plot the mesh. 86 : // 87 : plot ( Th, wait = true, ps = "membrane_error_mesh_"+n+".ps" ); 88 : // 89 : // Compute the error. 90 : // 91 : L2error[n] = sqrt ( int2d ( Th ) ( ( u - uexact )^2 ) ); 92 : cout << " L2error " << n << " = " << L2error[n] << endl; 93 : } 94 : 95 : cout << " Convergence rate = " 96 : << log ( L2error[0] / L2error[1] ) / log ( 2.0 ) << endl; 97 : // 98 : // Terminate. 99 : // 100 : cout << "\n"; 101 : cout << "membrane_error():\n"; 102 : cout << " FreeFem++ version.\n"; 103 : 104 : exit ( 0 ); 105 : sizestack + 1024 =3272 ( 2248 ) membrane_error(): FreeFem++ version. Solve the membrane problem using a manufactured solution. -- mesh: Nb of Triangles = 162, Nb of Vertices 97 -- Solve : min -0.831386 max 0.0182362 L2error 0 = 0.0183715 -- mesh: Nb of Triangles = 640, Nb of Vertices 351 -- Solve : min -0.83894 max 0.00464906 L2error 1 = 0.0046527 Convergence rate = 1.98133 membrane_error(): FreeFem++ version. current line = 104 exit(0) err code 0 , mpirank 0 CodeAlloc : nb ptr 4081, size :528048 mpirank: 0 Ok: Normal End