Fix bugs in computing energy.
add input for rho too.