Hello,
I would like to use a macro to compute derivative of several fields.
Concretly, in a simplified context, I have the following issue:
for the macro
macro testij(i,j) esc(:(a[$i]=b[$j] )) end
for a
and b
defined, if I do @macroexpand @testij(1+2,2)
I get
:(a[1 + 2] = b[2])
I would like to obtain this :(a[3] = b[2])
, how can I do it ?
In my particular case I do operation on several field:
macro compute_∇P(li,lj) esc(
quote
∂xPx = (P_shared[$li+1,$lj,1] - P_shared[$li-1,$lj,1])*0.5/Δ
∂zPx = (P_shared[$li,$lj+1,1] - P_shared[$li,$lj-1,1])*0.5/Δ
∂xPz = (P_shared[$li+1,$lj,2] - P_shared[$li-1,$lj,2])*0.5/Δ
∂zPz = (P_shared[$li,$lj+1,2] - P_shared[$li,$lj-1,2])*0.5/Δ
end)
end
For boundary conditions I do
i_ = mod(i-1,1:N)
@compute_∇P(i_,j)
but I would like to write it this way @compute_∇P(mod(i-1,1:N),j)
without computing the modulus several time.
Thank you for your help,
Best