A General Method for Sizing Battery Energy Storage Systems for Use in Mitigating Photovoltaic Flicker