Variational principles and finite element analysis for polarization gradient theory