Actual source code: example7.edp
 1 /*******************************************************
 2  *  This file is part of the FreeFEM tutorial made by  *
 3  *      Pierre Jolivet <pierre@joliv.et>               *
 4  *                                                     *
 5  *  See https://joliv.et/FreeFem-tutorial for more     *
 6  *                                                     *
 7  *   Description: additional plugins, functions,       *
 8  *                and macros                           *
 9  *******************************************************/
 
11 load "example7"
 
13 func int myFunc(int& a) {
14     return a * 4.0;
15 }
 
17 func real[int] myFuncWithMesh(int coefficient, mesh& Th) {
18     real[int] out(Th.nt);
19     for(int i = 0; i < Th.nt; ++i)
20         out[i] = coefficient * Th[i].region;
21     return out;
22 }
 
24 mesh sq = square(10, 10);
25 int a = 10;
26 cout << myFunc(a) << endl;
27 sq = change(sq, fregion = (x < 0.5 ? 2 : 1));
28 a = 2;
29 real[int] reg = myFuncWithMesh(a, sq);
30 cout << reg << endl;
 
32 macro myMesh()mesh3// EOM
33 include "cube.idp"
34 myMesh cb = cube(10, 10, 10);
 
36 IFMACRO(macroCL)
37 cout << macroCL << endl;
38 ENDIFMACRO
 
40 func f = 1;
41 varf vPb(u, v) = int2d(sq)(dx(u) * dx(v) + dy(u) * dy(v)) + int2d(sq)(f * v) + on(1, u = 1.0);
42 fespace Vh(sq, P1);
 
44 matrix A = vPb(Vh, Vh, tgv = -1);
45 Vh b = vPb(0, Vh, tgv = -1);
46 real[int] x(b[].n);
47 func real[int] op(real[int]& in) {
48     real[int] out(in.n);
49     out = A * in;
50     return out;
51 }
52 LinearGMRES(op, x, b[]);
53 b[] = x;
54 plot(b);