Density inhomogeneities and phase transitions in the universe and in relativistic heavy ion collisions