Hi,
I have implemented a piece of code adding a body forcing with a number of Fourier mode with random phase. The random phases will be updated while run time so it has been passed by the external variable hphs0:
<%pyfr:macro name='bdforc' params='t, u, ploc, src' externs='hphs0'>
// Spatial variable
fpdtype_t ploc_t = atan2(ploc[1], ploc[2]);
// Declare hz
fpdtype_t hz;
// Generate function hz
% for j in range(nphase):
hz += sin(${j}*ploc_t + hphs0[0][${j}] * 2 * ${np.pi});
% endfor
% for i in range(3):
src[${i + 1}] += ${Amp} * hz;
% endfor
</%pyfr:macro>
This code is working however the performance is not ideal. The reason is that it has to add up all Fourier modes considered by variable nphase
which could be a few hundred. But phase is not updating every single step. In fact it often do several thousand steps. So question is that is it possible to cache hz
in the backend? Or is there any better way to pass this variable?
Regards,
Zhenyang