Mechanistic study of the selective action of oil and water penetrating into a gel emplaced in a porous medium