FreeFEM Documentation on GitHub

stars - forks

Visualization

Plot

 1 mesh Th = square(5,5);
 2 fespace Vh(Th, P1);
 3 
 4 // Plot scalar and vectorial FE function
 5 Vh uh=x*x+y*y, vh=-y^2+x^2;
 6 plot(Th, uh, [uh, vh], value=true, wait=true);
 7 
 8 // Zoom on box defined by the two corner points [0.1,0.2] and [0.5,0.6]
 9 plot(uh, [uh, vh], bb=[[0.1, 0.2], [0.5, 0.6]],
10     wait=true, grey=true, fill=true, value=true);
11 
12 // Compute a cut
13 int n = 10;
14 real[int] xx(10), yy(10);
15 for (int i = 0; i < n; i++){
16     x = i/real(n);
17     y = i/real(n);
18     xx[i] = i;
19     yy[i] = uh; // Value of uh at point (i/10., i/10.)
20 }
21 plot([xx, yy], wait=true);
22 
23 { // File for gnuplot
24     ofstream gnu("plot.gp");
25     for (int i = 0; i < n; i++)
26         gnu << xx[i] << " " << yy[i] << endl;
27 }
28 
29 // Calls the gnuplot command, waits 5 seconds and generates a postscript plot (UNIX ONLY)
30 exec("echo 'plot \"plot.gp\" w l \n pause 5 \n set term postscript \n set output \"gnuplot.eps\" \n replot \n quit' | gnuplot");
Plot1

Fig. 208 First plot

Plot2

Fig. 209 Second plot

Plot3

Fig. 210 Gnuplot

Plot

HSV

 1 // From: http://en.wikipedia.org/wiki/HSV_color_space
 2 // The HSV (Hue, Saturation, Value) model defines a color space
 3 // in terms of three constituent components:
 4 // HSV color space as a color wheel
 5 // Hue, the color type (such as red, blue, or yellow):
 6 // Ranges from 0-360 (but normalized to 0-100% in some applications like here)
 7 // Saturation, the "vibrancy" of the color: Ranges from 0-100%
 8 // The lower the saturation of a color, the more "grayness" is present
 9 // and the more faded the color will appear.
10 // Value, the brightness of the color: Ranges from 0-100%
11 
12 mesh Th = square(10, 10, [2*x-1, 2*y-1]);
13 
14 fespace Vh(Th, P1);
15 Vh uh=2-x*x-y*y;
16 
17 real[int] colorhsv=[ // Color hsv model
18     4./6., 1 , 0.5, // Dark blue
19     4./6., 1 , 1, // Blue
20     5./6., 1 , 1, // Magenta
21     1, 1. , 1, // Red
22     1, 0.5 , 1 // Light red
23     ];
24  real[int] viso(31);
25 
26  for (int i = 0; i < viso.n; i++)
27     viso[i] = i*0.1;
28 
29  plot(uh, viso=viso(0:viso.n-1), value=true, fill=true, wait=true, hsv=colorhsv);
../_images/HSV.jpg

Fig. 211 Result

Medit

 1 load "medit"
 2 
 3 mesh Th = square(10, 10, [2*x-1, 2*y-1]);
 4 
 5 fespace Vh(Th, P1);
 6 Vh u=2-x*x-y*y;
 7 
 8 medit("u", Th, u);
 9 
10 // Old way
11 savemesh(Th, "u", [x, y, u*.5]); // Saves u.points and u.faces file
12 // build a u.bb file for medit
13 {
14     ofstream file("u.bb");
15     file << "2 1 1 " << u[].n << " 2 \n";
16     for (int j = 0; j < u[].n; j++)
17         file << u[][j] << endl;
18 }
19 // Calls medit command
20 exec("ffmedit u");
21 // Cleans files on unix-like OS
22 exec("rm u.bb u.faces u.points");
Medit1

Fig. 212 2D plot

Medit2

Fig. 213 Plot with elevation

Medit

Paraview

 1 load "iovtk"
 2 
 3 mesh Th = square(10, 10, [2*x-1, 2*y-1]);
 4 
 5 fespace Vh(Th, P1);
 6 Vh u=2-x*x-y*y;
 7 
 8 int[int] Order = [1];
 9 string DataName = "u";
10 savevtk("u.vtu", Th, u, dataname=DataName, order=Order);
../_images/Paraview.jpg

Fig. 214 Result

Table of content