Analytic Computation of Beam Impedance in Complex Heterogeneous Accelerator Geometries