Patent ID: 8763696

Claim:
A method, comprising: initiating circulation of a mud in a pipe string from a mud pit through a surface port in the pipe string to a downhole diverter sub, wherein the pipe string is suspended in a wellbore extending into a subterranean formation; operating a downhole pump to pump formation fluid from the subterranean formation, wherein the formation fluid contains at least one of a free gas or a dissolved gas; mixing the formation fluid that has been pumped with the mud that has been circulated to form a mixture of formation fluid and mud such that a proportion of the at least one of the free gas or the dissolved gas in the mixture is maintained below a threshold value determined at least in part based on a gas content of the formation fluid; performing a thermo-hydraulic simulation to predict a response of the mixture to conditions of the subterranean formation, wherein the response comprises fluid pressures of the mixture; and adjusting the threshold value in response to determining that the fluid pressures of the mixture indicate a wellbore integrity condition.