Calculation of electrical resistivity produced by dislocations and grain boundaries in metals