A classical virial theorem for open systems