Phase transitions and thermal expansion in pyroelectric energy conversion