-- FreeFem++ v4.14 (mer. 06 mars 2024 16:59:04 CET - git v4.14-1-g2b2052ae) file : mass_matrix.edp Load: lg_fem lg_mesh lg_mesh3 eigenvalue 1 : // mass_matrix.edp 2 : // 3 : // Discussion: 4 : // 5 : // Construct the mass matrix for the Poisson equation on the unit disk. 6 : // 7 : // Print out the mass matrix, and notice that certain entries have 8 : // unexpected values. 9 : // 10 : // Show that these values are associated with boundary nodes having Dirichlet 11 : // boundary conditions. 12 : // 13 : // Licensing: 14 : // 15 : // This code is distributed under the MIT license. 16 : // 17 : // Modified: 18 : // 19 : // 29 June 2015 20 : // 21 : // Author: 22 : // 23 : // John Burkardt 24 : // 25 : cout << "\n"; 26 : cout << "mass_matrix():\n"; 27 : cout << " FreeFem++ version:\n"; 28 : cout << "\n"; 29 : cout << " Mass matrix definition:\n"; 30 : cout << " M(i,j) = Integral Phi(i) Phi(j)\n"; 31 : cout << "\n"; 32 : cout << " For technical reasons, rows of M corresponding ... : to Dirichlet\n"; 33 : cout << " boundary conditions will have a huge number on ... : diagonal.\n"; 34 : cout << "\n"; 35 : cout << " If you don't know this, it may surprise you, or ... : cause your\n"; 36 : cout << " calculations to go astray.\n"; 37 : // 38 : // Define the mesh. 39 : // 40 : mesh Th = square ( 3, 3 ); 41 : // 42 : // Plot the mesh. 43 : // 44 : plot ( Th, ps = "mass_matrix_mesh.ps" ); 45 : // 46 : // Define the finite element space. 47 : // 48 : fespace Vh ( Th, P1 ); 49 : Vh uh; 50 : Vh vh; 51 : // 52 : // Define bilinear forms for Dirichlet and Neumann problems. 53 : // 54 : varf bid ( uh, vh ) = int2d ( Th ) ( uh * vh ) + on ( 1, 2, 3, 4, uh = 0.0 ); 55 : varf bin ( uh, vh ) = int2d ( Th ) ( uh * vh ); 56 : // 57 : // Create the corresponding mass matrices. 58 : // 59 : matrix ad = bid ( Vh, Vh ); 60 : matrix an = bin ( Vh, Vh ); 61 : // 62 : // Print the matrices. 63 : // 64 : cout << "\n"; 65 : cout << " Matrix AD:\n"; 66 : cout << " Mass matrix for system with Dirichlet condition ... : s.\n"; 67 : cout << "\n"; 68 : cout << ad; 69 : cout << "\n"; 70 : cout << " Matrix AN:\n"; 71 : cout << " Mass matrix for system with Neumann conditions. ... : \n"; 72 : cout << "\n"; 73 : cout << an; 74 : // 75 : // Terminate. 76 : // 77 : cout << "\n"; 78 : cout << "mass_matrix():\n"; 79 : cout << " Normal end of execution.\n"; 80 : 81 : exit ( 0 ); 82 : sizestack + 1024 =1584 ( 560 ) mass_matrix(): FreeFem++ version: Mass matrix definition: M(i,j) = Integral Phi(i) Phi(j) For technical reasons, rows of M corresponding to Dirichlet boundary conditions will have a huge number on diagonal. If you don't know this, it may surprise you, or cause your calculations to go astray. -- Square mesh : nb vertices =16 , nb triangles = 18 , nb boundary edges 12 Matrix AD: Mass matrix for system with Dirichlet conditions. # HashMatrix Matrix (COO) 0x6177eac17e20 # n m nnz half fortran state 16 16 82 0 0 0 0 0 0 1.0000000000000000199e+30 0 1 0.00462962962962963024 0 5 0.00925925925925926048 1 0 0.0046296296296296311074 1 1 1.0000000000000000199e+30 1 5 0.0092592592592592587453 5 0 0.0092592592592592622147 5 1 0.0092592592592592587453 5 5 0.055555555555555538594 0 4 0.00462962962962963024 5 4 0.00925925925925926048 4 0 0.00462962962962963024 4 5 0.0092592592592592587453 4 4 1.0000000000000000199e+30 1 2 0.00462962962962963024 1 6 0.00925925925925926048 2 1 0.0046296296296296311074 2 2 1.0000000000000000199e+30 2 6 0.00925925925925926048 6 1 0.0092592592592592622147 6 2 0.00925925925925926048 6 6 0.055555555555555552472 6 5 0.00925925925925926048 5 6 0.0092592592592592587453 2 3 0.0046296296296296311074 2 7 0.0092592592592592622147 3 2 0.0046296296296296311074 3 3 1.0000000000000000199e+30 3 7 0.00462962962962963024 7 2 0.0092592592592592622147 7 3 0.0046296296296296293726 7 7 1.0000000000000000199e+30 7 6 0.0092592592592592622147 6 7 0.00925925925925926048 4 9 0.00925925925925926048 5 9 0.0092592592592592587453 9 4 0.0092592592592592622147 9 5 0.0092592592592592587453 9 9 0.055555555555555538594 4 8 0.00462962962962963024 9 8 0.00925925925925926048 8 4 0.00462962962962963024 8 9 0.00925925925925926048 8 8 1.0000000000000000199e+30 5 10 0.00925925925925926048 6 10 0.00925925925925926048 10 5 0.0092592592592592622147 10 6 0.00925925925925926048 10 10 0.05555555555555555941 10 9 0.00925925925925926048 9 10 0.00925925925925926048 6 11 0.0092592592592592622147 7 11 0.00462962962962963024 11 6 0.0092592592592592622147 11 7 0.0046296296296296293726 11 11 1.0000000000000000199e+30 11 10 0.0092592592592592622147 10 11 0.0092592592592592622147 8 13 0.0092592592592592622147 9 13 0.0092592592592592622147 13 8 0.0092592592592592622147 13 9 0.00925925925925926048 13 13 1.0000000000000000199e+30 8 12 0.0046296296296296311074 13 12 0.00462962962962963024 12 8 0.0046296296296296311074 12 13 0.0046296296296296293726 12 12 1.0000000000000000199e+30 9 14 0.0092592592592592622147 10 14 0.0092592592592592622147 14 9 0.0092592592592592622147 14 10 0.00925925925925926048 14 14 1.0000000000000000199e+30 14 13 0.00462962962962963024 13 14 0.0046296296296296293726 10 15 0.0092592592592592622147 11 15 0.00462962962962963024 15 10 0.0092592592592592622147 15 11 0.00462962962962963024 15 15 1.0000000000000000199e+30 15 14 0.00462962962962963024 14 15 0.00462962962962963024 Matrix AN: Mass matrix for system with Neumann conditions. # HashMatrix Matrix (COO) 0x6177eac1c0f0 # n m nnz half fortran state 16 16 82 0 0 0 0 0 0 0.01851851851851852096 0 1 0.00462962962962963024 0 5 0.00925925925925926048 1 0 0.0046296296296296311074 1 1 0.027777777777777776236 1 5 0.0092592592592592587453 5 0 0.0092592592592592622147 5 1 0.0092592592592592587453 5 5 0.055555555555555538594 0 4 0.00462962962962963024 5 4 0.00925925925925926048 4 0 0.00462962962962963024 4 5 0.0092592592592592587453 4 4 0.027777777777777776236 1 2 0.00462962962962963024 1 6 0.00925925925925926048 2 1 0.0046296296296296311074 2 2 0.027777777777777779705 2 6 0.00925925925925926048 6 1 0.0092592592592592622147 6 2 0.00925925925925926048 6 6 0.055555555555555552472 6 5 0.00925925925925926048 5 6 0.0092592592592592587453 2 3 0.0046296296296296311074 2 7 0.0092592592592592622147 3 2 0.0046296296296296311074 3 3 0.0092592592592592587453 3 7 0.00462962962962963024 7 2 0.0092592592592592622147 7 3 0.0046296296296296293726 7 7 0.027777777777777776236 7 6 0.0092592592592592622147 6 7 0.00925925925925926048 4 9 0.00925925925925926048 5 9 0.0092592592592592587453 9 4 0.0092592592592592622147 9 5 0.0092592592592592587453 9 9 0.055555555555555538594 4 8 0.00462962962962963024 9 8 0.00925925925925926048 8 4 0.00462962962962963024 8 9 0.00925925925925926048 8 8 0.027777777777777779705 5 10 0.00925925925925926048 6 10 0.00925925925925926048 10 5 0.0092592592592592622147 10 6 0.00925925925925926048 10 10 0.05555555555555555941 10 9 0.00925925925925926048 9 10 0.00925925925925926048 6 11 0.0092592592592592622147 7 11 0.00462962962962963024 11 6 0.0092592592592592622147 11 7 0.0046296296296296293726 11 11 0.027777777777777776236 11 10 0.0092592592592592622147 10 11 0.0092592592592592622147 8 13 0.0092592592592592622147 9 13 0.0092592592592592622147 13 8 0.0092592592592592622147 13 9 0.00925925925925926048 13 13 0.027777777777777776236 8 12 0.0046296296296296311074 13 12 0.00462962962962963024 12 8 0.0046296296296296311074 12 13 0.0046296296296296293726 12 12 0.0092592592592592570105 9 14 0.0092592592592592622147 10 14 0.0092592592592592622147 14 9 0.0092592592592592622147 14 10 0.00925925925925926048 14 14 0.027777777777777776236 14 13 0.00462962962962963024 13 14 0.0046296296296296293726 10 15 0.0092592592592592622147 11 15 0.00462962962962963024 15 10 0.0092592592592592622147 15 11 0.00462962962962963024 15 15 0.018518518518518517491 15 14 0.00462962962962963024 14 15 0.00462962962962963024 mass_matrix(): Normal end of execution. current line = 81 exit(0) err code 0 , mpirank 0 CodeAlloc : nb ptr 3915, size :520088 mpirank: 0 Ok: Normal End