  A method to sum over logarithmic potential in 2D and Coulomb potential in 3D
with periodic boundary conditions in all directions is given. We consider the
most general form of unit cells, the rhombic cell in 2D and the triclinic cell
in 3D. For the 3D case, this paper presents a generalization of Sperb's work
[R. Sperb, Mol. Simulation, \textbf{22}, 199-212(1999)]. The expressions
derived in this work converge extremely fast in all region of the simulation
cell. We also obtain results for slab geometry. Furthermore, self-energies for
both 2D as well as 3D cases are derived. Our general formulas can be employed
to obtain Madelung constants for periodic structures.
