Skip to main content
Glama
gabrielserrao

pyResToolbox MCP Server

gas_viscosity

Calculate gas viscosity at reservoir conditions using the Lee-Gonzalez-Eakin correlation for accurate flow rate and pressure drop analysis in petroleum engineering.

Instructions

Calculate gas viscosity (μg).

CRITICAL GAS PVT PROPERTY - Computes gas viscosity at reservoir conditions using Lee, Gonzalez & Eakin (1966) correlation, industry standard for natural gas. Viscosity affects flow rates, pressure drops, and well performance. Gas viscosity increases with pressure and temperature, opposite to liquid behavior.

Parameters:

  • sg (float, required): Gas specific gravity (air=1.0). Valid: 0.55-3.0. Typical: 0.6-1.2. Example: 0.7.

  • degf (float, required): Reservoir temperature in °F. Valid: -460 to 1000. Typical: 100-400°F. Example: 180.0.

  • p (float or list, required): Pressure(s) in psia. Must be > 0. Can be scalar or array. Example: 3500.0 or [1000, 2000, 3000, 4000].

  • h2s (float, optional, default=0.0): H2S mole fraction (0-1). Typical: 0-0.05. Example: 0.02.

  • co2 (float, optional, default=0.0): CO2 mole fraction (0-1). Typical: 0-0.20. Example: 0.05.

  • n2 (float, optional, default=0.0): N2 mole fraction (0-1). Typical: 0-0.10. Example: 0.01.

  • zmethod (str, optional, default="DAK"): Z-factor method for viscosity calculation. Options: "DAK", "HY", "WYW", "BUR". DAK recommended.

Viscosity Behavior:

  • Increases with pressure (gas molecules closer together)

  • Increases with temperature (molecular motion increases)

  • Typical range: 0.01-0.05 cP at reservoir conditions

  • At standard conditions: ~0.01 cP

Lee-Gonzalez-Eakin Correlation: Uses Z-factor internally to account for real gas behavior. More accurate than ideal gas assumptions, especially at high pressures.

Returns: Dictionary with:

  • value (float or list): Viscosity in cP (matches input p shape)

  • method (str): "Lee-Gonzalez-Eakin"

  • units (str): "cP"

  • inputs (dict): Echo of input parameters

Common Mistakes:

  • Using separator temperature instead of reservoir temperature

  • Pressure in barg/psig instead of psia (must be absolute)

  • Not accounting for non-hydrocarbon fractions

  • Confusing gas viscosity (increases with P) with oil viscosity (decreases with P)

  • Temperature in Celsius instead of Fahrenheit

Example Usage:

{ "sg": 0.7, "degf": 180.0, "p": [1000, 2000, 3000, 4000], "h2s": 0.0, "co2": 0.05, "n2": 0.01, "zmethod": "DAK" }

Result: Viscosity increases from ~0.012 cP at 1000 psia to ~0.025 cP at 4000 psia.

Note: Gas viscosity is much lower than oil viscosity (typically 0.01-0.05 cP vs 0.5-10 cP). Always use reservoir conditions, not separator conditions. Account for all non-hydrocarbon components for accuracy.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
requestYes

Implementation Reference

  • The gas_viscosity tool handler function. Calculates gas viscosity using pyrestoolbox.gas.gas_ug with Lee-Gonzalez-Eakin correlation. Handles scalar and array inputs, converts numpy arrays to lists for JSON, and returns structured response.
    @mcp.tool() def gas_viscosity(request: GasViscosityRequest) -> dict: """Calculate gas viscosity (μg). **CRITICAL GAS PVT PROPERTY** - Computes gas viscosity at reservoir conditions using Lee, Gonzalez & Eakin (1966) correlation, industry standard for natural gas. Viscosity affects flow rates, pressure drops, and well performance. Gas viscosity increases with pressure and temperature, opposite to liquid behavior. **Parameters:** - **sg** (float, required): Gas specific gravity (air=1.0). Valid: 0.55-3.0. Typical: 0.6-1.2. Example: 0.7. - **degf** (float, required): Reservoir temperature in °F. Valid: -460 to 1000. Typical: 100-400°F. Example: 180.0. - **p** (float or list, required): Pressure(s) in psia. Must be > 0. Can be scalar or array. Example: 3500.0 or [1000, 2000, 3000, 4000]. - **h2s** (float, optional, default=0.0): H2S mole fraction (0-1). Typical: 0-0.05. Example: 0.02. - **co2** (float, optional, default=0.0): CO2 mole fraction (0-1). Typical: 0-0.20. Example: 0.05. - **n2** (float, optional, default=0.0): N2 mole fraction (0-1). Typical: 0-0.10. Example: 0.01. - **zmethod** (str, optional, default="DAK"): Z-factor method for viscosity calculation. Options: "DAK", "HY", "WYW", "BUR". DAK recommended. **Viscosity Behavior:** - Increases with pressure (gas molecules closer together) - Increases with temperature (molecular motion increases) - Typical range: 0.01-0.05 cP at reservoir conditions - At standard conditions: ~0.01 cP **Lee-Gonzalez-Eakin Correlation:** Uses Z-factor internally to account for real gas behavior. More accurate than ideal gas assumptions, especially at high pressures. **Returns:** Dictionary with: - **value** (float or list): Viscosity in cP (matches input p shape) - **method** (str): "Lee-Gonzalez-Eakin" - **units** (str): "cP" - **inputs** (dict): Echo of input parameters **Common Mistakes:** - Using separator temperature instead of reservoir temperature - Pressure in barg/psig instead of psia (must be absolute) - Not accounting for non-hydrocarbon fractions - Confusing gas viscosity (increases with P) with oil viscosity (decreases with P) - Temperature in Celsius instead of Fahrenheit **Example Usage:** ```python { "sg": 0.7, "degf": 180.0, "p": [1000, 2000, 3000, 4000], "h2s": 0.0, "co2": 0.05, "n2": 0.01, "zmethod": "DAK" } ``` Result: Viscosity increases from ~0.012 cP at 1000 psia to ~0.025 cP at 4000 psia. **Note:** Gas viscosity is much lower than oil viscosity (typically 0.01-0.05 cP vs 0.5-10 cP). Always use reservoir conditions, not separator conditions. Account for all non-hydrocarbon components for accuracy. """ method_enum = getattr(z_method, request.zmethod) ug = gas.gas_ug( sg=request.sg, degf=request.degf, p=request.p, h2s=request.h2s, co2=request.co2, n2=request.n2, zmethod=method_enum, ) # Convert numpy array to list for JSON serialization if isinstance(ug, np.ndarray): value = ug.tolist() else: value = float(ug) return { "value": value, "method": "Lee-Gonzalez-Eakin", "units": "cP", "inputs": request.model_dump(), }
  • Pydantic model defining the input schema for gas_viscosity tool, including validation for fields like sg, degf, p (scalar or list), non-hydrocarbon fractions, and zmethod.
    class GasViscosityRequest(BaseModel): """Request model for gas viscosity calculation.""" sg: float = Field( ..., ge=0.5, le=2.0, description="Gas specific gravity (air=1, dimensionless)" ) degf: float = Field( ..., gt=-460, lt=1000, description="Temperature (degrees Fahrenheit)" ) p: Union[float, List[float]] = Field( ..., description="Pressure (psia) - scalar or array" ) h2s: float = Field( 0.0, ge=0.0, le=1.0, description="H2S mole fraction (dimensionless)" ) co2: float = Field( 0.0, ge=0.0, le=1.0, description="CO2 mole fraction (dimensionless)" ) n2: float = Field( 0.0, ge=0.0, le=1.0, description="N2 mole fraction (dimensionless)" ) zmethod: Literal["DAK", "HY", "WYW", "BUR"] = Field( "DAK", description="Z-factor calculation method" ) @field_validator("p") @classmethod def validate_pressure(cls, v): """Validate pressure values.""" if isinstance(v, list): if not all(p > 0 for p in v): raise ValueError("All pressure values must be positive") else: if v <= 0: raise ValueError("Pressure must be positive") return v
  • Imports and calls register_gas_tools(mcp), which defines and registers the gas_viscosity tool (among others) using @mcp.tool() decorator.
    from .tools.gas_tools import register_gas_tools from .tools.inflow_tools import register_inflow_tools from .tools.simtools_tools import register_simtools_tools from .tools.brine_tools import register_brine_tools from .tools.layer_tools import register_layer_tools from .tools.library_tools import register_library_tools register_oil_tools(mcp) register_gas_tools(mcp)

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/gabrielserrao/pyrestoolbox-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server