Macroscopic dynamics of a trapped Bose-Einstein condensate in the presence of 1D and 2D optical lattices