CHIL and PHIL Applications for Protection, Control, and Optimal Operation of Active Distribution Networks and Microgrids.