Repast System Dynamics - order of stocks and rates calculation in generated code
I am encountering an issue after generating and running a code for my system dynamics model. The order of stocks and rates calculations in the generated code causes the rate to be updated to next period value before it's current value is added or subtracted from the stock it influences. This is happening only for some rates and stocks while others are in the correct order. I have included below a part of the code (stripped out the rest) which shows a different order of calculation for two similarly built stocks and flows. You'll notice that the rate is updated after the stock in the case of second stock while for the first it's updated before the stock. Also, for some reason, the part of code which calculates stock value is generated twice.
Not sure if I am doing something wrong when building up the diagram. Will be grateful for any suggestions. Is this something you encountered before or can someone shed some light on what drives the order in which the statements are generated for stocks and flows?