Fix bugs in well_state *RateSI() unit conversion#1212
Conversation
af6352b to
7bcccc8
Compare
| LAB_UNITS = 3 | ||
|
|
||
| # Unit conversion constants | ||
| INCH = 0.0254 |
There was a problem hiding this comment.
For readability, append # meters
| LITER = 0.001 | ||
| MILLI_LITER = LITER * 0.001 | ||
| GAS_FIELD = (FEET**3) * 1_000_000 | ||
| HOUR = 3600 |
| FEET = 12 * INCH | ||
| GALLON = 231 * INCH**3 | ||
| BARREL = GALLON * 42 | ||
| LITER = 0.001 |
| BARREL = GALLON * 42 | ||
| LITER = 0.001 | ||
| MILLI_LITER = LITER * 0.001 | ||
| GAS_FIELD = (FEET**3) * 1_000_000 |
There was a problem hiding this comment.
Suggest to rename this variable to MMCF
7bcccc8 to
cabdbfe
Compare
| # The reservoir volume rate is unit-independent and equals its SI value. | ||
|
|
||
| # The reservoir volume rate is implemented as being unit-independent, | ||
| # I have not confirmed that this is correct |
cabdbfe to
a5c1fb7
Compare
a5c1fb7 to
b1f6d51
Compare
| #ifdef __cplusplus | ||
| } | ||
|
|
||
| inline double liquid_conversion_rate(ert_rd_unit_enum unit_system) { |
There was a problem hiding this comment.
rename to liquid_conversion_factor?
| double conversion_factor = 1; | ||
|
|
||
| if (unit_system == RD_METRIC_UNITS) | ||
| conversion_factor = 1.0 / RD_UNITS_TIME_DAY; |
There was a problem hiding this comment.
(I guess you could return directly in each if-statement)
| return conversion_factor; | ||
| } | ||
|
|
||
| inline double gas_conversion_rate(ert_rd_unit_enum unit_system) { |
berland
left a comment
There was a problem hiding this comment.
merge at will (friday-deployday!)
b1f6d51 to
2884d99
Compare
There was a problem hiding this comment.
Pull request overview
This PR corrects SI unit conversion for well and connection rate accessors (*RateSI()) by fixing conversion-factor handling (including a macro expansion precedence issue) and by ensuring the declared restart-file unit system is used when computing SI rates. It also replaces an Equinor-data-based test with self-contained restart-file writer tests to validate rate conversions across unit systems.
Changes:
- Fix SI conversions for well-state and well-connection rates (including reservoir volume rates) based on the restart file’s unit system.
- Add unit-system-aware restart writer utilities/tests (XWEL + XCON) to validate SI scaling for METRIC/FIELD/LAB.
- Refactor/centralize C++ conversion factors and correct XWEL index constants used for oil/water/gas rates.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/well_tests/test_rd_well3.py | Removes legacy Equinor dataset-based rate assertions. |
| tests/test_well.py | Adds unit-system-aware restart writing (INTEHEAD unit system + XCON) and new parametrized SI conversion tests. |
| python/resdata/well/well_state.py | Documents raw-vs-SI semantics for rate getters. |
| lib/resdata/well_state.cpp | Uses shared conversion helpers for SI rates and applies conversion to volume_rate_si; fixes XWEL oil index usage via constant update. |
| lib/resdata/well_conn.cpp | Stores unit system on connections and applies SI conversions to connection rates. |
| lib/resdata/tests/well_segment_conn.cpp | Updates test allocations to pass unit system. |
| lib/resdata/tests/well_conn.cpp | Updates test allocations to pass unit system. |
| lib/include/resdata/well/well_const.hpp | Corrects XWEL_RES_ORAT_ITEM index. |
| lib/include/resdata/well/well_conn.hpp | Extends allocation API to accept unit_system. |
| lib/include/resdata/rd_units.hpp | Fixes macro precedence with parentheses and adds shared conversion-factor helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There were a number of bugs with the *RateSI() function 1. The conversion rates would be off due to a macro expansion bug. 2 in ebd5ddd, the unit_system is now initialized in RSTHead, so prior to that commit, SI units were always equal to the raw units. 3) by outputting the WVPR with OPM flow, which should correspond to volumeRate, we have confirmed that volumeRate should have the same conversion factor as oil. Before the conversion rate was always 1.0. 4) by looking at a well with one connection we got values in XCON that matched XWEL with OPM flow. Which confirms that these values have the same units and the corresponding conversion should be done for rateSI() in WellConnection. Before the raw value was used.
2884d99 to
177fbe6
Compare
The rates would be off due to a macro expansion bug. Also, in ebd5ddd, the unit_system is now initialized in RSTHead, so prior to that commit, SI units were always equal to the raw units.
Resolves #1213