pyopmnearwell.utils.formulas module
Provide useful mathematical formulas for reservoir modelling.
TODO: The typing is off in this module. Instead of returning an ArrayLike, most functions should return an np.ndarray, however that does not work when a float is passed as then an np.float64 or similar is returned. Not sure how to fix this.
- pyopmnearwell.utils.formulas.area_squaredcircle(radius: ArrayLike, sidelength: ArrayLike) ArrayLike
Calculate the area that lies both inside a circle and inside a square centered at the origin.
- Parameters:
radius (ArrayLike) – The radius of the circle.
sidelength (ArrayLike) – The sidelength of the square.
- Returns:
The calculated area.
- Return type:
ArrayLike
- Raises:
ValueError – If
radiusorsidelengthcontain a negative value.
Examples
>>> area_squaredcircle(3.0, 3.0) 9.0 # Area of a sqare with sidelength 3.0
>>> area_squaredcircle(2.0, 4.0) 12.566370614359172 # Area of a circle with radius 2.0
>>> area_squaredcircle(2.0, 3.0) 6.283185307179586 # Area inside a 2.0
- pyopmnearwell.utils.formulas.cell_size(radii: ArrayLike) ArrayLike
Calculate the size of a quadratic cell for a given equivalent well block radius.
- Parameters:
delta_x (ArrayLike) – _description_
- Returns:
_description_
- Return type:
(ArrayLike)
- pyopmnearwell.utils.formulas.co2brinepvt(pressure: float, temperature: float, phase_property: Literal['density', 'viscosity'], phase: Literal['CO2', 'water'], OPM: str | Path) float
Call OPM’s
co2brinepvtto calculate density/viscosity.- Parameters:
pressure (float) – Unit: [Pa].
temperature (float) – Unit: [K].
property (Literal["density", "viscosity"]) – Phase property to return.
phase (Literal["CO2", "water"]) – Phase of interest.
OPM – (str | pathlib.Path): Path to OPM installation.
- Returns:
Density (unit: [kg/m^3]) or viscosity (unit: [Pa*s])
- Return type:
quantity (float)
- pyopmnearwell.utils.formulas.data_WI(q: ArrayLike, p_w: ArrayLike, p_gb: ArrayLike, well_type: Literal['injector', 'producer'] = 'injector') ArrayLike
Compute the well productivity index from given data.
\[WI = \frac{q}{p_w - p_{gb}\]- Parameters:
q (ArrayLike) – Injection rate. Unit: [m^3/s].
p_w (ArrayLike) – Bottom hole pressure. Unit: [Pa].
p_gb (ArrayLike) – Grid block pressure. Unit: [Pa].
well_type (Literal["injector", "producer], optional) – Calculate WI for injector
"injector". (or producer. Defaults to)
- Returns:
\(WI\). Unit: [m^4*s/kg].
- Return type:
WI (ArrayLike)
- Raises:
ValueError – If bottom hole pressure and grid block pressure are equal for any point.
- pyopmnearwell.utils.formulas.equivalent_well_radius(delta_x: ArrayLike) ndarray
Calculate the equivalent well block radius for a given quadratic cell size.
- Parameters:
delta_x (ArrayLike) – _description_
- Returns:
_description_
- Return type:
(ArrayLike)
- pyopmnearwell.utils.formulas.hydrostatic_fluid(rho: ArrayLike, height: ArrayLike, gravity: ArrayLike = 9.8067) ArrayLike
Calculate the pressure due to hydrostatic fluid.
This function calculates the pressure due to hydrostatic fluid using the formula:
..math:
P = rho * g * h,
where \(P\) is the pressure, \(rho\) is the fluid density, \(g\) is the acceleration due to gravity, and \(h\) is the height.
- Parameters:
rho (ArrayLike) – Fluid density. Unit [kg/m^3].
height (ArrayLike) – Height of the fluid column. Unit [m].
gravity (ArrayLike, optional) – Acceleration due to gravity. Unit [m/s^2]. Defaults to
units.GRAVITATIONAL_ACCELERATION, i.e., \(\approx 9.8\).
- Returns:
Hydrostatic pressure at the given height. Unit [Pa].
- Return type:
ArrayLike
Examples
>>> hydrostatic_fluid(1000, 10) 98067.0
- pyopmnearwell.utils.formulas.hydrostatic_gas(reference_pressure: ArrayLike, height: ArrayLike, temperature: ArrayLike, molecule_mass: ArrayLike, gravity: ArrayLike = 9.8067) ArrayLike
Calculate the pressure due to a column of gas in hydrostatic equilibrium.
This function calculates the pressure due to a column of gas in hydrostatic equilibrium using the ideal gas law and the hydrostatic equilibrium formula. The formula is:
..math:
P = P_0 * e^((-m * g * h) / (R^* * T)),
where \(P is the pressure,\) \(P_0 is the reference pressure,\) \(m is the molecular mass of the gas,\) \(g is the acceleration due to gravity,\) \(h is the height,\) \(R^* is the universal gas constant, and\) \(T is the temperature.\)
- Parameters:
reference_pressure (ArrayLike) – Reference pressure at height 0. Unit [Pa].
height (ArrayLike) – Height of the gas column. Unit [m].
temperature (ArrayLike) – Temperature. Unit [K].
molecule_mass (ArrayLike) – Molecular mass of the gas. Unit [kg/mol].
gravity (ArrayLike, optional) – Acceleration due to gravity. Unit [m/s^2].
units.GRAVITATIONAL_ACCELERATION (Defaults to)
i.e.
9.8`. (ca.)
- Returns:
Hydrostatic pressure at the given height. Unit [Pa].
- Return type:
ArrayLike
Examples
>>> hydrostatic_gas(101325, 5000, 300, 0.029, 9.81) 75819.90376642203
- pyopmnearwell.utils.formulas.peaceman_WI(k_h: ArrayLike, r_e: ArrayLike, r_w: ArrayLike, rho: ArrayLike, mu: ArrayLike) ArrayLike
Compute the well productivity index (adjusted for density and viscosity) from the Peaceman well model.
\[WI = \frac{2 \pi h \mathbf{k} \frac{\mu}{\rho}}{\ln(r_e/r_w)}\]- Parameters:
k_h (ArrayLike) – Permeability times the cell thickness. Unit: [m^3].
r_e (ArrayLike) – Equivalent well-block radius. Needs to have the same unit as
r_w.r_w (ArrayLike) – Wellbore radius. Needs to have the same unit as
r_e.rho (ArrayLike) – Density. Unit: [kg/m^3].
mu (ArrayLike) – Viscosity. Unit: [Pa*s].
- Returns:
\(WI\). Unit: [m*s].
- Return type:
WI (ArrayLike)
- pyopmnearwell.utils.formulas.peaceman_matrix_WI(k_h: ArrayLike, r_e: ArrayLike, r_w: ArrayLike) ArrayLike
- Compute the well productivity index (without taking into account density and
viscosity) from the Peaceman well model.
\[WI = \frac{2 \pi h \mathbf{k}}{\ln(r_e/r_w)}\]- Parameters:
k_h (ArrayLike) – Permeability times the cell thickness. Unit: [m^3].
r_e (ArrayLike) – Equivalent well-block radius. Needs to have the same unit as
r_w.r_w (ArrayLike) – Wellbore radius. Needs to have the same unit as
r_e.
- Returns:
\(WI\). Unit: [m^3].
- Return type:
WI (ArrayLike)
- Raises:
ValueError – If r_w is zero for any point.
ValueError – If either r_e or r_w contains a negative value
- pyopmnearwell.utils.formulas.pyopmnearwell_correction(angle: ArrayLike = 1.0471975511965976) ArrayLike
Calculate a correction factor that scales cell volume, equivalent radius etc. from a 2D triangle grid to a radial grid.
In pyopmnearwell, when using the cake grid, a 2D triangle grid is used. As the scaling for cell volumes between a radial and a triangular grid is linear, the radial solution can be recovered. This function calculates the ratio
\[r_{radial_grid} / x_{triangle_grid},\]where \(x_{triangle_grid}\) is the altitude of the triangle, s.t. the solution on the triangle grid is equal to the solution on a radial grid with the given cell radii.
- Parameters:
angle (ArrayLike) – Angle between both sides of the triangle grid. Default is \(\pi/3\).
- Returns:
\(r_{radial_grid} / x_{triangle_grid}\)
- Return type:
ArrayLike
- pyopmnearwell.utils.formulas.two_phase_peaceman_WI(k_h: ArrayLike, r_e: ArrayLike, r_w: ArrayLike, rho_1: ArrayLike, mu_1: ArrayLike, k_r1: ArrayLike, rho_2: ArrayLike, mu_2: ArrayLike, k_r2: ArrayLike) ArrayLike
Compute the well productivity index (adjusted for density, viscosity and relative permeabilties) from the Ptwo-phase eaceman well model.
Cf. [A. Yapparova, B. Lamy-Chappuis, S. W. Scott, and T. Driesner, “A Peaceman-type well model for the 3D Control Volume Finite Element Method and numerical simulations of supercritical geothermal resource utilization” 2022, doi: 10.1016/j.geothermics.2022.102516.]
\[WI = \frac{2 \pi h \mathbf{k}}{\ln(r_e/r_w)} \left(\frac{k_{r,1}}{\mu_1} + \frac{k_{r,2}}{\mu_2})\right)\]Note
The result is only accurate for fine grid sizes.
- Parameters:
k_h (ArrayLike) – Permeability times the cell thickness. Unit: [m^3].
r_e (ArrayLike) – Equivalent well-block radius. Needs to have the same unit as
r_w.r_w (ArrayLike) – Wellbore radius. Needs to have the same unit as
r_e.rho_1 (ArrayLike) – Density of phase 1. Unit: [kg/m^3].
mu_1 (ArrayLike) – Viscosity of phase 1. Unit: [Pa*s].
k_r1 (ArrayLike) – Relative permeability of phase 1.
rho_2 (ArrayLike) – Density of phase 2. Unit: [kg/m^3].
mu_2 (ArrayLike) – Viscosity of phase 2. Unit: [Pa*s].
k_r2 (ArrayLike) – Relative permeability of phase 2.
- Returns:
\(WI\). Unit: [m*s].
- Return type:
WI (ArrayLike)