Problem with variable flux

Please edit your post and format the code (including proper indentations) as suggested by @Arjen . As it is, it is difficult to read.

Then please state more precisely what is the problem. Which values you get, and which values you are expecting. Also, without knowing the equations you are trying to translate to code, it can be hard to tell where is the problem in the code.