optimizing energy flow