In this paper the attention is focused on the analysis and the optimization of energy flows in networked systems via a fluid-dynamic model. In particular, a cost functional that represents a term proportional to the kinetic energy of an energy system is studied. First, the functional is optimized for a simple network having a unique node, with an incoming arc and two outgoing ones. The optimization deals with distribution coefficients and explicit solutions are found. Then, the global optimization is obtained using the local optimal parameters at the various nodes of the system. Considering the case study of an energy hub, interesting results are obtained for the whole network, proving the correctness of the proposed approach.