Theory of simulation methods for lattice and defect energy calculations in crystals