Polarization switching in PbTiO3: an ab initio finite element simulation