Domain switching and spatial dependence of permittivity in ferroelectric thin films