Function mean unexpected behaviour

Could somebody please explain the behaviour of mean function?

For example this case works:

real x0 = 0, x1 = 1.;
real y0 = 0, y1 = 0.5;
int n = 80, m = 40;
mesh Th = square(n, m, [x0 + (x1 - x0) * x, y0 + (y1 - y0) * y]);

fespace Vh(Th, P2);

Vh r = 0;

cout << mean(r) << endl;

but a change as simple as different mesh:

real radius1 = 1.0;
real radius2 = 1.3;
border left(t = 0, 1){x = 0; y = radius2 - (radius2 - radius1) * t; label=3;}
border inner(t = pi / 2., 0){x = radius1 * cos(t); y = radius1 * sin(t); label=2;}
border bottom(t = 0, 1){x = radius1 + (radius2 - radius1) * t; y = 0; label=4;}
border outter(t = 0, pi / 2.){x = radius2 * cos(t); y = radius2 * sin(t); label=1;}
mesh Th = buildmesh(left(10) + inner(35) + bottom(10) + outter(50));

fespace Vh(Th, P2);

Vh r = 0;

cout << mean(r) << endl;

results in execution error. Ehm… Why and how to compute the mean in the second case?

In the FreeFem++ documentation (Third edition, Version 3.48) the keyword index has a single entry for mean in the following sentence:

The characteristics of FreeFem++ are:

  • [..]
  • Tools to define discontinuous Galerkin finite element formulations P0, P1dc, P2dc and keywords: jump, mean, intalledges.
  • [...]

The list of built-in functions also doesn’t include mean. So it seems like mean has a different meaning than one would typically expect.

Perhaps @frederichecht can shed more light on this.

1 Like

You are meant to use mean inside a varf. This is not computing what you want. What mean do you want in your case? If it’s arithmetic, then you can do cout << r[].sum/r[].n << endl;

3 Likes

This would give the mean of the array of DOF’s, right?

Yes, is that what you want?

1 Like