BORES uses a system of physical constants and unit conversion factors throughout its calculations. These constants cover standard conditions (pressure, temperature), fluid densities, molecular weights, conversion factors between SI and imperial units, and numerical thresholds that control simulation behavior. Rather than scattering magic numbers throughout the code, all constants are centralized in a Constants class that you can inspect, modify, and even temporarily override during a simulation.
The constants system is designed around the reservoir engineering convention of using imperial (oilfield) units internally: pressures in psi, temperatures in Fahrenheit, permeabilities in millidarcies, viscosities in centipoise, and volumes in barrels and cubic feet. Conversion factors to SI units are provided for every quantity so you can work in whichever system you prefer for input and output.
Understanding the constants is important for two reasons. First, if your reservoir uses non-standard conditions (for example, a different standard temperature or salinity), you can adjust the constants to match. Second, when debugging unexpected results, checking whether the correct constants are being used can quickly identify unit conversion errors.
The proxy automatically returns the unwrapped value of each constant. If you need the full Constant object (with description and unit metadata), use bracket notation:
The Constants class is a dictionary-like container that stores all constants as Constant objects. Each Constant wraps a value with optional description and unit metadata.
frombores.constantsimportConstants,Constant# Create with default constantsconstants=Constants()# Access a valueprint(constants.STANDARD_PRESSURE_IMPERIAL)# 14.696# Access the full Constant objectconst=constants["STANDARD_PRESSURE_IMPERIAL"]print(const)# Constant(value=14.696, description='...', unit='psi')
You can modify constants at runtime using dot notation or bracket notation:
frombores.constantsimportConstants,Constantconstants=Constants()# Set a raw value (auto-wrapped in Constant)constants.DEFAULT_WATER_SALINITY_PPM=50000# Set with full metadataconstants["MY_CUSTOM_VALUE"]=Constant(value=42.0,description="Custom parameter for my model",unit="psi",)
For temporary overrides, use the Constants instance as a context manager. Within the context, the global proxy c points to your custom constants. Outside, the defaults are restored:
frombores.constantsimportConstants,c# Create custom constantscustom=Constants()custom.STANDARD_TEMPERATURE_IMPERIAL=70.0# Different standard temp# Temporarily override global constantswithcustom():print(c.STANDARD_TEMPERATURE_IMPERIAL)# 70.0# All BORES functions called here use 70 F as standard temperature# Outside the context, original defaults are restoredprint(c.STANDARD_TEMPERATURE_IMPERIAL)# 60.0
This mechanism uses Python's ContextVar system and is thread-safe. Each thread maintains its own constants context, so overrides in one thread do not affect other threads.
The Constants class supports iteration, length, and containment checks:
frombores.constantsimportConstantsconstants=Constants()# Count all constantsprint(len(constants))# Number of defined constants# Check if a constant existsif"MOLECULAR_WEIGHT_CO2"inconstants:print("CO2 molecular weight is defined")# Iterate over all constant namesfornameinconstants:print(name)# Iterate over name-value pairsforname,constinconstants.items():print(f"{name}: {const.value}{const.unitor''}")
You can define your own Constant objects for project-specific parameters:
frombores.constantsimportConstant,Constants# Create a Constants instance with custom valuesproject_constants=Constants()project_constants["FORMATION_WATER_VISCOSITY"]=Constant(value=0.7,description="Measured formation water viscosity at reservoir conditions",unit="cP",)project_constants["INJECTION_WATER_VISCOSITY"]=Constant(value=0.5,description="Treated injection water viscosity",unit="cP",)
Custom constants coexist with the default constants. You can use them to store project-specific parameters alongside the standard physical constants, keeping all numerical values in one inspectable location.