Parameterized macro?

Hello FreeFem community,

Is it possible to define a parameterized macro with a parameter inside in order to use it in varf.
In fact, this parameter could be the index of region. For example :

real [int, int][int] c(10)
for (i=1;i<=3;i++) {c[i].resize(7,7);c[i] = 0.;} and after c[i] (j,k) are filled.

for (i=1;i<=3;i++) {
macro F…[i]…?(u,v) (c[i] (1,1) * S1(u)+c[i] (1,2) * S2(v)) // EOM
}
varf K(u,v) = int3d(Th3,1)(F…[1]…?(u,v)) + int3d(Th3,2)(F…[2]…?(u,v)) + int3d(Th3,3)(F…[3]…?(u,v))+ …

Thanks in advance,

The answer is no, but I do not understand what you want to do,
remark, you can defined macro in macro with the new syntax

you can see this exemple

Thanks for the answer.
In fact I imagine this for attributing physical property to each material, see below, is it correct ?

real [int, int][int] z(4)
for (i=1;i<=3;i++) {
z[i].resize(4,4); z[i] = 0.; // for instance 3 materials (I don’t use 0 index)
}

// Def for a physical property to whatever i material
macro Z(i) [[ z[i] (1,1), z[i] (1,2), z[i] (1,3) ],
[ z[i] (2,1), z[i] (2,2), z[i] (2,3) ],
[ z[i] (3,1), z[i] (3,2), z[i] (3,3) ]] // EOM
// and the varf for each material…1,2,3
varf VZ(u,v) = int3d(Th,1)( grad(v)’ *(Z(1)*grad(u)) )
+ int3d(Th,2)( grad(v)’ *(Z(2)*grad(u)) )
+ int3d(Th,3)( grad(v)’ *(Z(3)*grad(u)) );

Dear freefem community,

I follow my previous post, and I would like to have your advices for the best implementation of anisotropic physical property for each material.

Is the proposal of my previous post correct ?

Or should I use definition with

Ph Phy = Phy1*(region==1)+Phy2*(region==2) + etc. But the latter definition is well documented only for scalar values even for elasticity in isotropic conditions with E, nu or lambda, mu.

In fact, I am searching for the best way to properly model these anisotropic properties, especially when some solution fields are dependent of such region property (for instance stress field).

Best regards.

Hello,
It seems like I didn’t get why and how to use the macros. The book “FreeFEM documentation, 4.13” didn’t help me. I have a very non-linear equation to solve and wanted to divide it in few parts as follows:

macro grad(u1)[dx(u1),dy(u1)] //// def of grad operator
macro w(u2) 1+(abs(grad(u2)))^2 //// in equation
macro inter(w1) sqrt(w1-(w1-1)(n1/n2)^2) //// intermediate
macro F(u3,hh) (H-hh)
(inter(u3)-n1/n2)/(inter(u3)+n1/n2*(u3-1)) // //
problem disturb (h,v)
=int2d(Th1)
(
dx(h)dx(v)+dy(h)dy(v)
)
-int2d(Th1)
(v
(
dx(F(w(h),h))

(
dx(h)*dy(dy(h))-dy(h)dx(dy(h))
)
+dy(F(w(h),h))

(
dx(dx(h))*dy(h)-dx(h)dx(dy(h))
)
+F(w(h),h)
(dx(dx(h))*dy(dy(h))-(dx(dy(h)))^2)
-grad(log(F(w(h),h)))'*grad(h)
-Ll2/F(w(h),h)
)
)
+on(bord1,h=0);

The program falls with error at the moment when it tries to start the macro, “error operator ( <7E_Array>”, and concludes with the compilation error: “before token )” for the line where the macro is called. What is my error in this part of code, maybe the syntax is wrong?

The problem is not in the macro, but in the fact that your expression is nonlinear in h.
h is the unknown in your problem disturb (h,v). FF can only solve linear systems. For nonlinear problems you need to define an iterative scheme, each iteration containing only linear problems, as the Newton method for example.

Thank you for the answer, but the macros still do not work. I try to use it for simple calculation of a function value, just to prove (I received the result manually). Here is a piece of code:
Vh3 f,f1,f2,h = 0; // function f(h), first and second derivative, initial guess h0
Vh3 htil;
//…
macro finter(h)
dx(dx(h))+dy(dy(h))
-dx(F(h))*(dx(h)*dy(dy(h))-dy(h)dx(dy(h)))
-dy(F(h))
(dy(h)*dx(dx(h))-dx(h)dx(dy(h)))
-F(h)
(dx(dx(h))*dy(dy(h))-(dx(dy(h)))^2)
+dx(log(F(h)))*dx(h)+dy(log(F(h)))*dy(h)
+Ll2/F(h)
// //…
htil = finter(h);

and the compiler gives a very the same error: it goes to the called macro and cannot work with it, finding an extra bracket: “before token ‘(’” It seems like the macro is described in wrong way. There is one more thing which confuses me: in the macro, the operators ‘dx’ and ‘dy’ which, as I guess, are in-built operators of space derivatives, are in some lines black as variables, and in other places brown as functions|operators.
Sorry for the long message, I hope that it will help to someone who has the same issue

You have to know that the operators dx or dy work only on arguments that
are declared variables in a fespace.
In particular you cannot write dx(dx(h))
Instead you should write for example

Vh3 h=exp(x);
Wh hx;
Zh hxx;
hx=dx(h);
hxx=dx(hx);

Where Vh3, Wh, Zh are defined fespace.
Same remark for dx(F(h)): you have to define first F(h) as a variable in a fespace.

Notice anyway that computing a second derivative of a function h in a fespace is in general problematic because the first order derivatives of h are discontinuous.