Development of an ab initio electrochemical cell: Understanding the dielectric properties of interfacial water and Mg dissolution from first principles