-- FreeFem++ v4.14 (mer. 06 mars 2024 16:59:04 CET - git v4.14-1-g2b2052ae) file : gnuplot_contour.edp Load: lg_fem lg_mesh lg_mesh3 eigenvalue 1 : // gnuplot_contour.edp 2 : // 3 : // Discussion: 4 : // 5 : // Let an ellipse have semimajor axis 2 and semiminor axis 1: 6 : // (x/2)^2 + (y/1)^2 = 1. 7 : // Let Gamma1 be the ellipse boundary from 0 to 4pi/3, and 8 : // Gamm2 the boundary from 4pi/3 to 2pi. 9 : // 10 : // Solve: 11 : // -uxx - uyy = f in Gamma1 + Gamma2, 12 : // u = x on Gamma1. 13 : // du/dn = 0, natural boundary condition on Gamma2. 14 : // 15 : // Licensing: 16 : // 17 : // This code is distributed under the MIT license. 18 : // 19 : // Modified: 20 : // 21 : // 23 May 2020 22 : // 23 : // Reference: 24 : // 25 : // Frederic Hecht, 26 : // Freefem++, 27 : // Third Edition, version 3.22 28 : // 29 : cout << "\n"; 30 : cout << "gnuplot_contour():\n"; 31 : cout << " FreeFem++ version\n"; 32 : cout << " Demonstrate how to write data that gnuplot() ca ... : n use\n"; 33 : cout << " to make a contour plot of the solution.\n"; 34 : // 35 : // Define Gamma1 and Gamma2, the boundaries. 36 : // A and B are the lengths of the semimajor and semiminor axes: 37 : // THETA specifies the angle at which we switch from GAMMA1 to GAMMA2. 38 : // 39 : real a = 2.0; 40 : real b = 1.0; 41 : real theta = 4.0 * pi / 3.0; 42 : border Gamma1 ( t = 0, theta ) { x = a * cos(t); y = b*sin(t); } 43 : border Gamma2 ( t = theta, 2*pi ) { x = a * cos(t); y = b*sin(t); } 44 : // 45 : // Th: the triangulation of the "left" side of the boundaries. 46 : // 47 : mesh Th = buildmesh ( Gamma1(100) + Gamma2(50) ); 48 : // 49 : // Plot the mesh. 50 : // 51 : plot ( Th, wait = false, ps = "gnuplot_contour_mesh.ps" ); 52 : // 53 : // Define Vh, the finite element space defined over Th, using P2 basis functions. 54 : // 55 : fespace Vh ( Th, P2 ); 56 : // 57 : // Define U, V, and F, piecewise P2 continuous functions over Th. 58 : // F is a constant function. 59 : // 60 : Vh u; 61 : Vh v; 62 : Vh f = 1.0; 63 : // 64 : // Define G, a function for the Dirichlet boundary conditions. 65 : // 66 : func g = x; 67 : // 68 : // Define the weak form of the PDE. 69 : // 70 : problem poisson ( u, v ) 71 : = int2d ( Th ) ( dx(u)*dx(v) + dy(u)*dy(v) ) 72 : - int2d ( Th ) ( f * v ) 73 : + on ( Gamma1, u = g ); 74 : // 75 : // Solve the PDE. 76 : // 77 : poisson; 78 : // 79 : // Write gnuplot data. 80 : // 81 : ofstream dataunit ( "gnuplot_contour_data.txt" ); 82 : for ( int i = 0; i < Th.nt; i++ ) 83 : { 84 : for ( int j = 0; j <= 3; j++ ) 85 : { 86 : int jj = ( j % 3 ); 87 : dataunit << " " << Th[i][jj].x 88 : << " " << Th[i][jj].y 89 : << " " << u[][Vh(i,jj)] << "\n"; 90 : } 91 : } 92 : // 93 : // Write gnuplot commands. 94 : // 95 : ofstream commandunit ( "gnuplot_contour_commands.txt" ); 96 : commandunit << "# gnuplot_contour_commands.txt\n"; 97 : commandunit << "# usage: gnuplot < gnuplot_contour_commands.txt\n ... : "; 98 : commandunit << "#\n"; 99 : commandunit << "set term png\n"; 100 : commandunit << "set size ratio -1\n"; 101 : commandunit << "set output 'gnuplot_contour.png'\n"; 102 : commandunit << "set pm3d\n"; 103 : commandunit << "unset surface\n"; 104 : commandunit << "set view map\n"; 105 : commandunit << "set contour\n"; 106 : commandunit << "set nokey\n"; 107 : commandunit << "set cntrparam cubicspline # smooth out the lines ... : \n"; 108 : commandunit << "set cntrparam levels 50 # sets the num of cont ... : our lines\n"; 109 : commandunit << "set pm3d interpolate 20,20 # interpolate the colo ... : r\n"; 110 : commandunit << "set palette model RGB defined ( 0'black', 1'blue' ... : , 2'cyan',3'green',4'yellow',5'red',8'purple' )\n"; 111 : commandunit << "set xlabel '<--X-->'\n"; 112 : commandunit << "set ylabel '<--Y-->'\n"; 113 : commandunit << "set title 'Solution contours'\n"; 114 : commandunit << "set timestamp\n"; 115 : commandunit << "set dgrid3d 10, 10, 1\n"; 116 : commandunit << "splot 'gnuplot_contour_data.txt' with lines lt 1\n"; 117 : // 118 : // Terminate. 119 : // 120 : cout << "\n"; 121 : cout << "gnuplot_contour():\n"; 122 : cout << " Normal end of execution.\n"; 123 : 124 : exit ( 0 ); 125 : sizestack + 1024 =2464 ( 1440 ) gnuplot_contour(): FreeFem++ version Demonstrate how to write data that gnuplot() can use to make a contour plot of the solution. -- mesh: Nb of Triangles = 2568, Nb of Vertices 1360 -- Solve : min -2 max 2 gnuplot_contour(): Normal end of execution. current line = 124 exit(0) err code 0 , mpirank 0 CodeAlloc : nb ptr 4098, size :527080 mpirank: 0 Ok: Normal End