Phase-field modeling of ferroelectric switching