# flux (momentum, heat) calculation with a mean flow

Dear All,

I am trying to calculate momentum and heat fluxes in a presence of mean flow. The mean velocity field is estimated using ave/spatial along z direction. In equilibrium I normally calculate fluxes using per atom quantities (e.g. stress/atom virial, KE or PE, …) in spatial bins in z direction.
I don’t know how to correctly subtract a position dependent velocity vector v_mean(z) from instantaneous atom velocities in every bin inside the input file.

This is how the stress and fluxes calculated in equilibrium:

If what you mean is you want to subtract a mean velocity
from every atom which is the mean velocity of the bin
the atom is in (as computed by fix ave/spatial), then
I don't know if you can do that in an input script variable
it computes as a global vector (actually array), so you would
need a per-atom variable that converts the atom position
to a bin ID. Then use that variable to index the fix array
in your per-atom formula. But it is tricky to get the bin #
correct, accounting for periodic boundaries, and atoms outside
the box, etc. Fix ave/spatial has logic to do that which you
cannot hope to duplicate in an input script. So if you can't
get it to work satisfactorily, I suggest just post-processing
what you want.

Steve

Thanks for the explanation. Considering the post processing as the second option, What do you think about changing the computes (e.g. stress/atom, ke/atom, pe/atom) in the source code (subtracting the mean from v[][]) if I use the global ave/spatial array? Since I need to call the fix ave/spatial first and let it run for a while to collect the average velocities, do I have access to the instantaneous box size in the stress compute for tracking down the atoms?

You can look at compute temp/profile. It calculates
a temperature after subtracting out a spatially averaged
flow field.

Steve