-- FreeFem++ v4.6 (Thu Apr 2 15:47:38 CEST 2020 - git v4.6) Load: lg_fem lg_mesh lg_mesh3 eigenvalue 1 : // Location: 2 : // 3 : // http://people.sc.fsu.edu/~jburkardt/freefem_src/exec_test/exec_test.edp 4 : // 5 : // Discussion: 6 : // 7 : // We solve the Poisson equation in a square. 8 : // 9 : // - uxx - uyy = u 10 : // 11 : // and then: 12 : // 13 : // * sample the solution, writing the data to a file. 14 : // * use EXEC() to run GNUPLOT and create a plot of the data. 15 : // 16 : // Licensing: 17 : // 18 : // This code is distributed under the GNU LGPL license. 19 : // 20 : // Modified: 21 : // 22 : // 27 January 2015 23 : // 24 : // Reference: 25 : // 26 : // John Chrispell, Jason Howell, 27 : // Finite Element Approximation of Partial Differential Equations 28 : // Using FreeFem++, or, How I Learned to Stop Worrying and Love 29 : // Numerical Analysis. 30 : // 31 : // Frederic Hecht, 32 : // New development in FreeFem++, 33 : // Journal of Numerical Mathematics, 34 : // Volume 20, Number 3-4, 2012, pages 251-265. 35 : // 36 : cout << "\n"; 37 : cout << "exec_test\n"; 38 : cout << " FreeFem++ version.\n"; 39 : cout << " Use the exec() function to issue an external co ... : mmand\n"; 40 : cout << " In this case, call gnuplot() to plot some resul ... : ts.\n"; 41 : // 42 : // Define Th, the triangulation of the square. 43 : // 44 : int n = 10; 45 : 46 : mesh Th = square ( n, n ); 47 : // 48 : // Define Vh, the finite element space for 49 : // 2D velocity vector (piecewise linear "bubble") and 50 : // pressure (piecewise linear). 51 : // 52 : fespace Vh ( Th, P1 ); 53 : // 54 : // Define UH, the trial function. 55 : // 56 : Vh uh; 57 : // 58 : // Define VH, test function. 59 : // 60 : Vh vh; 61 : // 62 : // Define F(X,Y), the right hand side function. 63 : // 64 : func f = 65 : + sin(5*pi*x*(1-x)) * sin(4*pi*y*(1-y)) * pow(5*pi*(1-x)-5*pi*x,2) 66 : + 10 * cos(5*pi*x*(1-x)) * pi * sin(4*pi*y*(1-y)) 67 : + sin(5*pi*x*(1-x)) * sin(4*pi*y*(1-y)) * pow(4*pi*(1-y)-4*pi*y,2) 68 : + 8 * sin(5*pi*x*(1-x)) * pi * cos(4*pi*y*(1-y)); 69 : // 70 : // Define G(X,Y), the boundary condition function. 71 : // 72 : func g = 0.0; 73 : // 74 : // Define POISSON, the problem to be solved. 75 : // 76 : problem poisson ( uh, vh ) 77 : = int2d ( Th ) 78 : ( 79 : dx(uh) * dx(vh) 80 : + dy(uh) * dy(vh) 81 : ) 82 : - int2d ( Th ) 83 : ( 84 : f * vh 85 : ) 86 : + on ( 1, 2, 3, 4, uh = g ); 87 : // 88 : // Solve the POISSON problem. 89 : // This puts the solution into UH. 90 : // 91 : poisson; 92 : // 93 : // Define DATAFILE, the name to use for the file storing the data. 94 : // 95 : string datafile = "poisson" + n + ".txt"; 96 : // 97 : // Define PLOTUNIT, an output device associated with "poissonN.sol" 98 : // 99 : { 100 : ofstream plotunit ( datafile ); 101 : // 102 : // Write a list of X, Y, UH(X,Y) values to the datafile. 103 : // 104 : { 105 : for ( int i = 0; i <= n ; i++ ) 106 : { 107 : real xx = real ( i ) / real ( n ); 108 : for ( int j = 0; j <= n ; j++ ) 109 : { 110 : real yy = real ( j ) / real ( n ); 111 : plotunit << xx << " " << yy << " " << uh( xx, yy ) << endl; 112 : } 113 : plotunit << endl; 114 : } 115 : } 116 : } 117 : // 118 : // Define PLOTFILE, the name of a graphics file to be created. 119 : // 120 : string plotfile = "poisson" + n + ".png"; 121 : // 122 : // Using EXEC ( "command" ) create a stream of input to gnuplot. 123 : // 124 : exec 125 : ( 126 : "echo" 127 : + " '" 128 : + "set parametric\n" 129 : + "set term png\n" 130 : + "set hidden\n" 131 : + "set contour base\n" 132 : + "set style data lines\n" 133 : + "set output \"" 134 : + plotfile 135 : + "\"\n" 136 : + "splot \"" 137 : + datafile 138 : + "\"\n" 139 : + " ' | gnuplot" 140 : ); 141 : // 142 : // Terminate. 143 : // 144 : cout << "\n"; 145 : cout << "exec_test\n"; 146 : cout << " Normal end of execution.\n"; 147 : sizestack + 1024 =6592 ( 5568 ) exec_test FreeFem++ version. Use the exec() function to issue an external command In this case, call gnuplot() to plot some results. -- Square mesh : nb vertices =121 , nb triangles = 200 , nb boundary edges 40 -- Solve : min -0.617154 max 0.856647 exec: echo 'set parametric set term png set hidden set contour base set style data lines set output "poisson10.png" splot "poisson10.txt" ' | gnuplot exec_test Normal end of execution. times: compile 0.005277s, execution 0.003653s, mpirank:0 CodeAlloc : nb ptr 3783, size :479136 mpirank: 0 Ok: Normal End