Skip to content

Commit 16cf01b

Browse files
authored
Merge pull request #38 from equinor/update-density-correction
Update density correction
2 parents 979f717 + 80c48ca commit 16cf01b

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

pvtlib/fluid_mechanics.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,12 +437,14 @@ def mass_percent_to_volume_percent(ContaminantMassP, DominantPhase_EOS_density,
437437

438438
def dominant_phase_corrected_density(measured_total_density, ContaminantVolP, ContaminantPhase_EOS_density):
439439
'''
440-
Use measured total density (for example from a coriolis meter) to estimate a "measured" density of the dominant phase corrected for contamination,
440+
Use measured total density (for example from a coriolis meter) to estimate a "measured" density of the dominant phase corrected for contamination,
441441
i.e. the density with the contaminant phase removed.
442442
The EOS density can be calculated from an equation of state, or from another source, as long as it represents the density of the dominant and contaminant phases.
443443
444+
If ContaminantVolP is zero, the function returns the measured_total_density.
445+
444446
Example of usage: What is the density of the oil phase if the measured density is 800 kg/m3 and the water fraction is 1vol%?
445-
447+
446448
Parameters
447449
----------
448450
measured_total_density : float
@@ -456,6 +458,7 @@ def dominant_phase_corrected_density(measured_total_density, ContaminantVolP, Co
456458
-------
457459
Density_dominant_corr : float
458460
Estimated density of the dominant phase, based on measured density, corrected for contaminant phase [kg/m3]
461+
If ContaminantVolP is zero, returns measured_total_density.
459462
460463
'''
461464

@@ -464,6 +467,8 @@ def dominant_phase_corrected_density(measured_total_density, ContaminantVolP, Co
464467
# Check for division by zero error, in which the function will return nan
465468
if (1 - Contaminant_alpha) == 0:
466469
Density_dominant_corr = np.nan
470+
elif Contaminant_alpha == 0:
471+
Density_dominant_corr = measured_total_density
467472
else:
468473
Density_dominant_corr = (measured_total_density - ContaminantPhase_EOS_density * Contaminant_alpha) / (
469474
1 - Contaminant_alpha)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def parse_requirements(filename):
2929

3030
setup(
3131
name='pvtlib',
32-
version='1.9.0',
32+
version='1.9.1',
3333
author='Christian Hågenvik',
3434
author_email='[email protected]',
3535
description='A library containing various tools in the categories of thermodynamics, fluid mechanics, metering etc.',

tests/test_fluid_mechanics.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,33 @@ def test_dominant_phase_corrected_density_3():
305305

306306
assert round(corrected_density, 2) == 888.89, f'Dominant phase corrected density calculation failed'
307307

308+
def test_dominant_phase_corrected_density_4():
309+
'''
310+
Test calculation of dominant phase corrected density.
311+
Example: Contaminant volume fraction is 0 vol%, should return measured density.
312+
'''
313+
314+
corrected_density = fluid_mechanics.dominant_phase_corrected_density(
315+
measured_total_density=900,
316+
ContaminantVolP=0,
317+
ContaminantPhase_EOS_density=1000
318+
)
319+
320+
assert round(corrected_density, 2) == 900.0, f'Dominant phase corrected density calculation failed'
321+
322+
def test_dominant_phase_corrected_density_5():
323+
'''
324+
Test calculation of dominant phase corrected density.
325+
Example: Contaminant volume fraction is 0 vol% and ContaminantPhase_EOS_density is np.nan, should return measured density.
326+
'''
327+
328+
corrected_density = fluid_mechanics.dominant_phase_corrected_density(
329+
measured_total_density=900,
330+
ContaminantVolP=0,
331+
ContaminantPhase_EOS_density=np.nan
332+
)
333+
334+
assert round(corrected_density, 2) == 900.0, f'Dominant phase corrected density calculation failed'
308335

309336
def test_dominant_phase_corrected_density_all_zeros():
310337
'''

0 commit comments

Comments
 (0)