Automated and scalable optimal control of three-Phase embedded power grids including PLL