Labsco
1Vewton logo

Permeability

from 1Vewton

Calculate permeability of porous media using the seepage distance method, derived from the Darcy's law-based formula

🔥🔥✓ VerifiedFreeQuick setup

permeability

PyPI Downloads

中文 English

A Python package for calculating permeability of porous media using the seepage distance method, derived from the Darcy's law-based formula, with capillary pressure correction via the Young-Laplace equation:

$$ K = \frac{L^2 \cdot \mu \cdot \phi}{2 \cdot t \cdot \Delta P} $$

$$ t = \frac{\mu \cdot \phi \cdot L^2}{2 \cdot K \cdot \Delta P} $$

$$ z(t) = \sqrt{\frac{2 \cdot K \cdot \Delta P \cdot t}{\mu \cdot \phi}} $$

$$ p_c = \frac{2 \cdot \gamma \cdot \cos(\theta)}{r} $$

Capillary-Corrected Forms

When capillary pressure $p_c$ is considered, $\Delta P$ is replaced by $(\Delta P + p_c)$:

$$ K = \frac{L^2 \cdot \mu \cdot \phi}{2 \cdot t \cdot (\Delta P + p_c)} $$

$$ t = \frac{\mu \cdot \phi \cdot L^2}{2 \cdot K \cdot (\Delta P + p_c)} $$

$$ z(t) = \sqrt{\frac{2 \cdot K \cdot (\Delta P + p_c) \cdot t}{\mu \cdot \phi}} $$

$$ \Delta P = \frac{\mu \cdot \phi \cdot L^2}{2 \cdot K \cdot t} $$

$$ \Delta P = \frac{\mu \cdot \phi \cdot L^2}{2 \cdot K \cdot t} - p_c $$

Anisotropic Permeability Tensor

For orthotropic media (e.g., woven composites), the permeability is represented as a diagonal tensor:

$$ K = \begin{bmatrix} K_x & 0 & 0 \ 0 & K_y & 0 \ 0 & 0 & K_z \end{bmatrix} $$

The Darcy velocity in anisotropic media is:

$$ v = -\frac{1}{\mu} \cdot K \cdot \nabla p $$

After coordinate rotation, the tensor transforms as:

$$ K' = R \cdot K \cdot R^T $$

The effective permeability in an arbitrary direction (unit vector $n$) is:

$$ K_{\text{eff}} = n^T \cdot K \cdot n $$

Key derived quantities include the in-plane average, anisotropy ratio, and degree of anisotropy:

$$ K_{\text{in-plane}} = \frac{K_x + K_y}{2}, \qquad \beta = \frac{K_{\text{in-plane}}}{K_z}, \qquad \delta = 1 - \frac{\min(K_x, K_y, K_z)}{\max(K_x, K_y, K_z)} $$

For a full symmetric tensor $K$ (with off-diagonal components), the principal permeability values are its eigenvalues $K_1 \ge K_2 \ge K_3$, and the principal directions are the corresponding eigenvectors, obtained via eigenvalue decomposition:

$$ K \cdot \phi_i = K_i \cdot \phi_i $$

SymbolMeaningUnit
$K$Permeability
$L$Sample thickness along flow directionm
$\mu$Dynamic viscosity of fluidPa·s
$\phi$Porosity of porous mediumdimensionless
$t$Time for fluid to fully penetrate samples
$\Delta P$Constant pressure difference across samplePa
$z$Infiltration front positionm
$p_c$Capillary pressurePa
$\gamma$Surface tension of the liquidN/m
$\theta$Contact angle (wetting angle)Degrees
$r$Equivalent pore radiusm

This package also provides an MCP server that exposes these calculations as tools for AI assistants like Claude.


MCP Server

The package includes a Model Context Protocol (MCP) server that exposes permeability calculations as AI-accessible tools. After installing the package, start the server with:

Starting the Server

Once installed, simply run:

# Default port 8000 (HTTP/SSE transport)
permeability_mcp

# Custom port
permeability_mcp --port 8080

The server starts via HTTP/SSE transport (http://localhost:8000 by default).

If you prefer to try it without installing, you can also use:

uvx --from permeability permeability_mcp

Streamable HTTP Transport

For clients that support the modern Streamable HTTP transport (MCP spec), the server can be configured to use HTTP POST-based communication instead of SSE:

permeability_mcp --port 8000
# Then connect via Streamable HTTP at http://localhost:8000/mcp

Claude Desktop configuration using Streamable HTTP (claude_desktop_config.json):

{
  "mcpServers": {
    "permeability": {
      "type": "http",
      "url": "http://localhost:8000/mcp"
    }
  }
}

Cline (VS Code extension) configuration using Streamable HTTP:

{
  "mcpServers": {
    "permeability": {
      "type": "http",
      "url": "http://localhost:8000/mcp"
    }
  }
}

Note: The Streamable HTTP transport requires a client that supports the MCP Streamable HTTP specification. The server runs the same underlying implementation — only the transport protocol differs from the default SSE-based connection.

Available Tools

Once the MCP server is running, AI assistants can call:

ToolDescription
calculate_permeability_by_seepage_distanceCalculate $K$ (optionally with capillary correction via $p_c$)
calculate_infiltration_timeCalculate $t$ (optionally with capillary correction via $p_c$)
calculate_infiltration_front_positionCalculate $z(t)$ (optionally with capillary correction via $p_c$)
calculate_infiltration_front_position4multiple_timesCalculate $z(t)$ for multiple time points (optionally with capillary correction via $p_c$)
calculate_capillary_pressureCalculate $p_c = 2\gamma\cos(\theta),/,r$ (Young-Laplace equation)
calculate_pressure_differenceCalculate $\Delta P$ (optionally with capillary correction via $p_c$)
darcy_m2_converterConvert Darcy to m² and/or m² to Darcy (bidirectional)
calculate_darcy_flux_toolCompute Darcy flux in anisotropic media; accepts permeability tensor from principal values, isotropic, or transversely isotropic
calculate_anisotropy_evolution_toolAnalyze anisotropy evolution across PIP cycles; returns tensors, anisotropy ratios, and cycle-by-cycle data

Each tool accepts the same parameters as the Python API.

API Reference

Seepage.calculate_permeability(L, mu, phi, t, dP, p_c=None)

Calculate permeability from seepage distance experiment data. When $p_c$ is provided, the capillary-corrected form is used.

$$ K = \frac{L^2 \cdot \mu \cdot \phi}{2 \cdot t \cdot \Delta P} \qquad\text{or}\qquad K = \frac{L^2 \cdot \mu \cdot \phi}{2 \cdot t \cdot (\Delta P + p_c)} $$

ParameterTypeDescription
LfloatSample length/thickness along flow direction (m)
mufloatDynamic viscosity of fluid (Pa·s)
phifloatPorosity of porous medium ($0 < \phi \le 1$)
tfloatTotal time for fluid to fully penetrate sample (s)
dPfloatConstant pressure difference across sample (Pa)
p_cfloat, optionalCapillary pressure for correction (Pa)

Returns: float — Permeability $K$ (m²)


Seepage.calculate_infiltration_time(L, mu, phi, K, dP, p_c=None)

Predict the time required for fluid to fully penetrate a sample. When $p_c$ is provided, the capillary-corrected form is used.

$$ t = \frac{\mu \cdot \phi \cdot L^2}{2 \cdot K \cdot \Delta P} \qquad\text{or}\qquad t = \frac{\mu \cdot \phi \cdot L^2}{2 \cdot K \cdot (\Delta P + p_c)} $$

ParameterTypeDescription
LfloatSample length/thickness along flow direction (m)
mufloatDynamic viscosity of fluid (Pa·s)
phifloatPorosity of porous medium ($0 < \phi \le 1$)
KfloatPermeability (m²)
dPfloatConstant pressure difference across sample (Pa)
p_cfloat, optionalCapillary pressure for correction (Pa)

Returns: float — Infiltration time $t$ (s)


Seepage.calculate_infiltration_front_position(K, mu, phi, dP, t, p_c=None)

Calculate the infiltration front position at a given time. When $p_c$ is provided, the capillary-corrected form is used.

$$ z(t) = \sqrt{\frac{2 \cdot K \cdot \Delta P \cdot t}{\mu \cdot \phi}} \qquad\text{or}\qquad z(t) = \sqrt{\frac{2 \cdot K \cdot (\Delta P + p_c) \cdot t}{\mu \cdot \phi}} $$

ParameterTypeDescription
KfloatPermeability (m²)
mufloatDynamic viscosity of fluid (Pa·s)
phifloatPorosity of porous medium ($0 < \phi \le 1$)
dPfloatConstant pressure difference across sample (Pa)
tfloatTime elapsed (s)
p_cfloat, optionalCapillary pressure for correction (Pa)

Returns: float — Infiltration front position $z$ (m)


Seepage.calculate_infiltration_front_position_with_multiple_time(K, mu, phi, dP, t, p_c=None)

Calculate the infiltration front position at multiple time points (useful for plotting). When $p_c$ is provided, the capillary-corrected form is used.

$$ z(t) = \sqrt{\frac{2 \cdot K \cdot \Delta P \cdot t}{\mu \cdot \phi}} \qquad\text{or}\qquad z(t) = \sqrt{\frac{2 \cdot K \cdot (\Delta P + p_c) \cdot t}{\mu \cdot \phi}} $$

ParameterTypeDescription
KfloatPermeability (m²)
mufloatDynamic viscosity of fluid (Pa·s)
phifloatPorosity of porous medium ($0 < \phi \le 1$)
dPfloatConstant pressure difference across sample (Pa)
tnumpy.ndarrayArray of time values (s)
p_cfloat, optionalCapillary pressure for correction (Pa)

Returns: numpy.ndarray — Array of infiltration front positions $z$ (m)


Seepage.calculate_pressure_difference(L, mu, phi, K, t, p_c=None)

Calculate the pressure difference across a sample. When $p_c$ is provided, the capillary-corrected form is used.

$$ \Delta P = \frac{\mu \cdot \phi \cdot L^2}{2 \cdot K \cdot t} \qquad\text{or}\qquad \Delta P = \frac{\mu \cdot \phi \cdot L^2}{2 \cdot K \cdot t} - p_c $$

ParameterTypeDescription
LfloatSample length/thickness along flow direction (m)
mufloatDynamic viscosity of fluid (Pa·s)
phifloatPorosity of porous medium ($0 < \phi \le 1$)
KfloatPermeability (m²)
tfloatTotal time for fluid to fully penetrate sample (s)
p_cfloat, optionalCapillary pressure for correction (Pa)

Returns: float — Pressure difference $\Delta P$ (Pa)


calculate_capillary_pressure(gamma, theta, r)

Calculate capillary pressure using the Young-Laplace equation.

$$ p_c = \frac{2 \cdot \gamma \cdot \cos(\theta)}{r} $$

ParameterTypeDescription
gammafloatSurface tension of the liquid (N/m)
thetafloatContact angle / wetting angle (Degrees)
rfloatEquivalent pore radius (m)

Returns: float — Capillary pressure $p_c$ (Pa)


darcy2m2(darcyK)

Convert permeability from Darcy to m².

ParameterTypeDescription
darcyKfloatPermeability in Darcy

Returns: float — Permeability in m²


m22darcy(m2K)

Convert permeability from m² to Darcy.

ParameterTypeDescription
m2KfloatPermeability in m²

Returns: float — Permeability in Darcy


PermeabilityTensor(Kx, Ky, Kz)

Anisotropic permeability tensor for 2D woven composites. Represents a diagonal permeability tensor $K = \text{diag}(K_x, K_y, K_z)$.

ParameterTypeDescription
KxfloatPermeability in x-direction (warp/fiber direction) (m²)
KyfloatPermeability in y-direction (weft direction) (m²)
KzfloatPermeability in z-direction (through-thickness) (m²)

Class Methods

PermeabilityTensor.from_principal_values(Kx, Ky, Kz)

Construct tensor from principal direction permeabilities (orthotropic materials).

PermeabilityTensor.from_isotopic(K)

Construct an isotropic permeability tensor where $K_x = K_y = K_z = K$.

PermeabilityTensor.from_transversely_isotropic(K_in_plane, K_out_plane)

Construct a transversely isotropic permeability tensor where $K_x = K_y = K_\text{in-plane}$, $K_z = K_\text{out-plane}$ (suitable for unidirectional fiber bundles).

Properties

PropertyReturn TypeDescription
tensornumpy.ndarrayFull 3x3 diagonal tensor matrix
in_plane_averagefloatAverage in-plane permeability $(K_x + K_y),/,2$ (m²)
anisotropy_ratiofloatAnisotropy ratio $\beta = \text{in_plane_avg},/,K_z$
degree_of_anisotropyfloatDegree of anisotropy (0 = isotropic, 1 = fully anisotropic)

Methods

darcy_velocity(grad_p, mu)

Calculate Darcy velocity vector $v = -(1/\mu) \cdot K \cdot \nabla p$.

ParameterTypeDescription
grad_pnumpy.ndarrayPressure gradient vector (Pa/m), shape (3,)
mufloatDynamic viscosity (Pa·s)

Returns: numpy.ndarray — Darcy velocity vector (m/s), shape (3,)

effective_permeability_in_direction(direction=None, direction_vector=None)

Calculate effective permeability in a specified direction. For a direction unit vector $n$, $K_\text{eff} = n^T \cdot K \cdot n$.

ParameterTypeDescription
directionstr, optionalOne of 'x', 'y', 'z', 'xy' (in-plane), or 'avg'
direction_vectornumpy.ndarray, optionalArbitrary unit vector of shape (3,)

Returns: float — Effective permeability in the specified direction (m²)

rotate(R)

Rotate the permeability tensor by rotation matrix $R$: $K' = R \cdot K \cdot R^T$.

ParameterTypeDescription
Rnumpy.ndarrayOrthogonal rotation matrix (3x3)

Returns: PermeabilityTensor or FullTensor — Rotated tensor (diagonal if off-diagonal terms negligible)

to_dict()

Export tensor data as a dictionary with keys: Kx, Ky, Kz, in_plane_average, anisotropy_ratio, degree_of_anisotropy.

Returns: dict


FullTensor(matrix)

Full 3x3 symmetric permeability tensor with off-diagonal components, used after coordinate rotation.

ParameterTypeDescription
matrixnumpy.ndarrayFull 3x3 symmetric tensor matrix

Properties

PropertyReturn TypeDescription
principal_valuestuplePrincipal permeability values $(K_1, K_2, K_3)$, descending order
principal_directionsnumpy.ndarrayPrincipal permeability directions (eigenvectors), shape (3, 3)

Methods

to_principal_tensor()

Convert to diagonal PermeabilityTensor in the principal coordinate system using eigenvalues.

Returns: PermeabilityTensor


anisotropic_darcy_flux(tensor, grad_p, mu, area_normal=None)

Compute Darcy flux and related quantities for anisotropic media.

ParameterTypeDescription
tensorPermeabilityTensorAnisotropic permeability tensor
grad_pnumpy.ndarrayPressure gradient vector (Pa/m)
mufloatDynamic viscosity (Pa·s)
area_normalnumpy.ndarray, optionalUnit normal vector of cross-section area for flux computation

Returns: dict with keys:

KeyDescription
darcy_velocityDarcy velocity vector (m/s)
flux_magnitudeMagnitude of Darcy velocity (m/s)
velocity_angle_from_gradP_degAngle between velocity and pressure gradient (degrees)
area_fluxVolumetric flux per unit area (m³/s per m²), only if area_normal provided

anisotropy_evolution(K_values, cycles)

Analyze the evolution of permeability anisotropy across PIP (Polymer Infiltration and Pyrolysis) cycles.

ParameterTypeDescription
K_valuesnumpy.ndarray2D array where each row is $[K_x, K_y, K_z]$ for one PIP cycle, shape (n, 3)
cyclesnumpy.ndarray1D array of PIP cycle numbers, shape (n,)

Returns: dict with keys:

KeyDescription
tensorsList of PermeabilityTensor objects for each cycle
cyclesArray of cycle numbers
anisotropy_ratiosArray of anisotropy ratios $\beta$ for each cycle
degrees_of_anisotropyArray of degree of anisotropy $\delta$ for each cycle
anisotropy_reductionPercentage reduction in anisotropy from first to last cycle (%)

Development

Setup

git clone https://github.com/1Vewton/permeability.git
cd permeability
uv sync

Running Tests

uv run pytest

Code Style

uv run flake8