General density gradients in general domains: the “two-tank” method revisited