NREL / GEOPHIRES-X

MIT License
29 stars 24 forks source link

Investigate using CoolProp instead of/in addition to IAPWS to handle mixed state #113

Closed softwareengineerprogrammer closed 7 months ago

softwareengineerprogrammer commented 8 months ago

Per sync discussion 2024-02-06

https://github.com/CoolProp/CoolProp


https://github.com/softwareengineerprogrammer/GEOPHIRES-X/pull/10

softwareengineerprogrammer commented 7 months ago

@malcolm-dsider via email:

I did a bit of IAPWS97 vs CoolProp investigation, just looking at the calculation of water density to start.

What I determined was that CoolProp & IAPWS produce very similar results (differences in the tenths of a percent) for the density of water for the way we are currently using them (but not exactly the same, suggesting they are not the same code base).

I also determined that they have the same upper-temperature limit for how we are currently using them – the input temperature cannot be higher than ~373 C (at the built-in default pressure). But I also determined that this is not a hard limit for either library (which is correct, it shouldn’t be). If we include pressure, the temperature limit for both can go way up – 700 C or more, depending on the pressure. And the results the libraries produce remain similar for that T & P. The conclusion I draw from that is two-fold: if we want to go to super-hot/super-critical temperatures, we must include pressure in our calculations. And if we stick to water (or ~seawater) as a working fluid, we can stick with IAPWS97. But if we eventually want to go to mixed-state fluids or a different working fluid (like steam+liquid, CO2, Ammonia+water, or one of a dozen more), we need to transition to CoolProp, which can handle all of those conditions, and IAPWS97 cannot.

So I suggest we proceed with an update using smart defaults in the most backwardly compatible way possible. If we are making this transition, I suggest we go all the way: switch to CoolProp and add pressure to our calculations. If we are doing that, I suggest we also add the ability to change salinity to the calculation (with a default of 0 for now), since the changes will be similar and fairly simple. We won’t use salinity and mixed-state fluids yet, but they will be there when we are ready.

I see that as a multi-step process:

  1. Change all the appropriate functions in GEOPHIRESUtils.py so that they are completely backward compatible with current results.
  2. Take advantage of those new functions in HIP-RA-X first because HIP-RA-X is not public (or at least available via the web UI). This will require that we account for pressure in HIP-RA-X, which we currently do not do. If we follow the idea that HIP-RA-X is intended for use when you know only a minimum amount of information about a reservoir, I would suggest we add two optional parameters: “Reservoir Depth” and “Reservoir Pressure.” If the user provides pressure, then we use it in the calculations. If they don’t, then they can optionally provide a depth. If they do, then we convert that to pressure, assuming a lithostatic pressure state. We can calculate that pressure with depth, rock density (which we have), and g. If they don’t provide the depth, then we calculate one, assuming a 30 C/km gradient (the worldwide average). We have the surface temperature and reservoir temperature, so we can calculate a depth based on that. We would then use the depth in the same way if the user had provided a depth.
  3. Update the outputs, reports, and test results for HIP-RA-X so everything passes (once we are sure we have the right answer).
  4. Update GEOPHIRES in the same way. I think GEOPHIRES has depth to the reservoir and pressure in the reservoir already, so it may be simpler. No need for new parameters.
  5. Update the outputs, reports, and test results for GEOPHIRES so everything passes (once we are sure we have the right answer).
softwareengineerprogrammer commented 7 months ago

https://github.com/softwareengineerprogrammer/GEOPHIRES-X/tree/pressure-based-calcs

  1. [X] Change all the appropriate functions in GEOPHIRESUtils.py so that they are completely backward compatible with current results.
  2. [ ] 🚧 Take advantage of those new functions in HIP-RA-X first because HIP-RA-X is not public (or at least available via the web UI). This will require that we account for pressure in HIP-RA-X, which we currently do not do. If we follow the idea that HIP-RA-X is intended for use when you know only a minimum amount of information about a reservoir, I would suggest we add two optional parameters: “Reservoir Depth” and “Reservoir Pressure.” If the user provides pressure, then we use it in the calculations. If they don’t, then they can optionally provide a depth. If they do, then we convert that to pressure, assuming a lithostatic pressure state. We can calculate that pressure with depth, rock density (which we have), and g. If they don’t provide the depth, then we calculate one, assuming a 30 C/km gradient (the worldwide average). We have the surface temperature and reservoir temperature, so we can calculate a depth based on that. We would then use the depth in the same way if the user had provided a depth.
  3. [ ] 🚧 Update the outputs, reports, and test results for HIP-RA-X so everything passes (once we are sure we have the right answer).
  4. [ ] 🚧 Update GEOPHIRES in the same way. I think GEOPHIRES has depth to the reservoir and pressure in the reservoir already, so it may be simpler. No need for new parameters.
  5. [ ] 🚧 Update the outputs, reports, and test results for GEOPHIRES so everything passes (once we are sure we have the right answer).
softwareengineerprogrammer commented 7 months ago

I have switched over to CoolProp on working branch and am now positioned to start incorporating pressure as an additional parameter to water property functions. I've arbitrarily chosen water density first.

@malcolm-dsider or @kfbeckers can either you identify the applicable pressure variable or calculation to pass to density_water_kg_per_m3 in the following usages:

  1. https://github.com/softwareengineerprogrammer/GEOPHIRES-X/blob/db80cbffb08c14afc368cd54d4a410c19070dc48/src/geophires_x/Reservoir.py#L779-L780
  2. https://github.com/softwareengineerprogrammer/GEOPHIRES-X/blob/ed438dc5f48c3ada7076e47a3857eec65ff78f03/src/geophires_x/WellBores.py#L144
  3. https://github.com/softwareengineerprogrammer/GEOPHIRES-X/blob/ed438dc5f48c3ada7076e47a3857eec65ff78f03/src/geophires_x/WellBores.py#L323-L324 https://github.com/softwareengineerprogrammer/GEOPHIRES-X/blob/ed438dc5f48c3ada7076e47a3857eec65ff78f03/src/geophires_x/WellBores.py#L443-L444
  4. https://github.com/softwareengineerprogrammer/GEOPHIRES-X/blob/ed438dc5f48c3ada7076e47a3857eec65ff78f03/src/geophires_x/WellBores.py#L87-L88
malcolm-dsider commented 7 months ago

Having reviewed the GEOPHIRES code, it seems the reservoir lithostatic pressure is not being calculated. I see a hydrostatic pressure (essentially the “weight of the column of working fluid in the vertical drill pipe), and plant production pressure, and the like, but not reservoir pressure. I am surprised by this! Is that true, @kfbeckers https://github.com/kfbeckers ?

If so, we need to derive pressure by making a lthostatic assumption using the function below. Depth would be reservoir.depth.value, and density would be self.rhorock.value. This assumes that the whole column of rock is the same density as the reservoir, which is probably too high, but we don’t have any oter rock densities from the overlying layers to use, so we have to live with that approximation.

In the case of HIP-RA-X, we don’t evenhave the concept of depth. Did you already figure out how to deal with that one?

If so, then the pressure in MPa would be:

def lithostatic_pressure(rho, depth):

"""

Calculate lithostatic pressure in a reservoir.

Args:

rho (float): Density of the fluid in kg/m^3.

depth (float): Depth of the reservoir in meters.

Returns:

float: Lithostatic pressure in megapascals (MPa).

"""

# Acceleration due to gravity (m/s^2)

g = 9.81

# Conversion factor from Pa to MPa

pa_to_mpa = 1e-6

# Calculate lithostatic pressure

pressure = rho * g * depth

# Convert pressure to megapascals

pressure_mpa = pressure * pa_to_mpa

return pressure_mpa

Here is a link that explains it: https://earthscience.stackexchange.com/questions/2106/how-do-i-derive-the-formula-for-lithostatic-overburden-pressure

From: Jonathan Pezzino @.> Sent: Monday, February 12, 2024 3:39 PM To: NREL/GEOPHIRES-X @.> Cc: Malcolm Ross @.>; Mention @.> Subject: Re: [NREL/GEOPHIRES-X] Investigate using CoolProp instead of/in addition to IAPWS to handle mixed state (Issue #113)

I have switched over to CoolProp on working branch and am now positioned to start incorporating pressure as an additional parameter to water property functions. I've arbitrarily chosen water density first. @malcolm-dsider https://github.com/malcolm-dsider or @kfbeckers https://github.com/kfbeckers can either you identify the applicable pressure variable or calculation to pass to density_water_kg_per_m3 in the following usages?

Density:

  1. https://github.com/softwareengineerprogrammer/GEOPHIRES-X/blob/db80cbffb08c14afc368cd54d4a410c19070dc48/src/geophires_x/Reservoir.py#L779-L780
  2. https://github.com/softwareengineerprogrammer/GEOPHIRES-X/blob/ed438dc5f48c3ada7076e47a3857eec65ff78f03/src/geophires_x/WellBores.py#L144
  3. https://github.com/softwareengineerprogrammer/GEOPHIRES-X/blob/ed438dc5f48c3ada7076e47a3857eec65ff78f03/src/geophires_x/WellBores.py#L323-L324 https://github.com/softwareengineerprogrammer/GEOPHIRES-X/blob/ed438dc5f48c3ada7076e47a3857eec65ff78f03/src/geophires_x/WellBores.py#L443-L444
  4. https://github.com/softwareengineerprogrammer/GEOPHIRES-X/blob/ed438dc5f48c3ada7076e47a3857eec65ff78f03/src/geophires_x/WellBores.py#L87-L88

— Reply to this email directly, view it on GitHub https://github.com/NREL/GEOPHIRES-X/issues/113#issuecomment-1939629647 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AWGVYTZJYYPIPC6QDYEDA53YTKDYRAVCNFSM6AAAAABC4TLVL2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZZGYZDSNRUG4 . You are receiving this because you were mentioned. https://github.com/notifications/beacon/AWGVYT6RYEQEOHJWPS35Q7TYTKDYRA5CNFSM6AAAAABC4TLVL2WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTTTRTE6.gif Message ID: @. @.> >

softwareengineerprogrammer commented 7 months ago

@malcolm-dsider Just to confirm - lithostatic pressure calculated per the function you've just provided is the correct pressure for all instances of water density cited in https://github.com/NREL/GEOPHIRES-X/issues/113#issuecomment-1939629647? (I'm assuming the answer is yes but just double-checking)

malcolm-dsider commented 7 months ago

Yes, as long as the units are correct.

I suggested we start this process in HIP-RA-X, since it isn’t “in production” (via the web UI). Have you dopne that?

From: Jonathan Pezzino @.> Sent: Tuesday, February 13, 2024 8:32 AM To: NREL/GEOPHIRES-X @.> Cc: Malcolm Ross @.>; Mention @.> Subject: Re: [NREL/GEOPHIRES-X] Investigate using CoolProp instead of/in addition to IAPWS to handle mixed state (Issue #113)

@malcolm-dsider https://github.com/malcolm-dsider Just to confirm - lithostatic pressure calculated per the function you've just provided is the correct pressure for all instances of water density cited in #113 (comment) https://github.com/NREL/GEOPHIRES-X/issues/113#issuecomment-1939629647 ? (I'm assuming the answer is yes but just double-checking)

— Reply to this email directly, view it on GitHub https://github.com/NREL/GEOPHIRES-X/issues/113#issuecomment-1941644272 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AWGVYT2OLLVEIN43X3DMVYDYTN2NDAVCNFSM6AAAAABC4TLVL2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBRGY2DIMRXGI . You are receiving this because you were mentioned. https://github.com/notifications/beacon/AWGVYT7QTB2E7B7UALSIONLYTN2NDA5CNFSM6AAAAABC4TLVL2WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTTXMR7A.gif Message ID: @. @.> >

softwareengineerprogrammer commented 7 months ago

Thanks for confirming. (I will be plumbing units in through pint quantities to reduce chance of mixup, btw)

Current priority is on extending GEOPHIRES support for temps >373℃ so I am starting with that. I will send PRs for any potential significant changes to outputs before merging them to my own fork's main branch and/or deploying to the web interface as applicable.

Happy to review any corresponding changes in HIP-RA you want to make in parallel, although I'd suggest it will probably be more efficient for me to establish the patterns for passing/calculating with pressure in GEOPHIRES first and then integrating into HIP-RA afterwards, vs. having 2 parallel implementations for pressure in GEOPHIRES and HIP-RA if we work separately.

malcolm-dsider commented 7 months ago

Sounds good. Go ahead with doing HIP-RA after GEOPHIRES. If you get stuck, let me know.

From: Jonathan Pezzino @.> Sent: Tuesday, February 13, 2024 8:53 AM To: NREL/GEOPHIRES-X @.> Cc: Malcolm Ross @.>; Mention @.> Subject: Re: [NREL/GEOPHIRES-X] Investigate using CoolProp instead of/in addition to IAPWS to handle mixed state (Issue #113)

Current priority is on extending GEOPHIRES support for temps >373℃ so I am starting with that. I will send PRs for any potential significant changes to outputs before merging them to my own fork's main branch and/or deploying to the web interface as applicable.

Happy to review any corresponding changes in HIP-RA you want to make in parallel, although I'd suggest it will probably be more efficient for me to establish the patterns for passing/calculating with pressure in GEOPHIRES first and then integrating into HIP-RA afterwards, vs. having 2 parallel implementations for pressure in GEOPHIRES and HIP-RA if we work separately.

— Reply to this email directly, view it on GitHub https://github.com/NREL/GEOPHIRES-X/issues/113#issuecomment-1941689512 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AWGVYTYWILM3FLJSWTCBWQDYTN43FAVCNFSM6AAAAABC4TLVL2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBRGY4DSNJRGI . You are receiving this because you were mentioned. https://github.com/notifications/beacon/AWGVYTYFDBCOELQ7CNEKKRLYTN43FA5CNFSM6AAAAABC4TLVL2WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTTXPKKQ.gif Message ID: @. @.> >

softwareengineerprogrammer commented 7 months ago

@malcolm-dsider Is lithostatic pressure still applicable here, in AGSWellBores.laplace_solution? https://github.com/softwareengineerprogrammer/GEOPHIRES-X/blob/86437fa104a20d1f9f5effc7f8475c5aad70b8bd/src/geophires_x/AGSWellBores.py#L253-L256

malcolm-dsider commented 7 months ago

yes

From: Jonathan Pezzino @.> Sent: Tuesday, February 13, 2024 10:29 AM To: NREL/GEOPHIRES-X @.> Cc: Malcolm Ross @.>; Mention @.> Subject: Re: [NREL/GEOPHIRES-X] Investigate using CoolProp instead of/in addition to IAPWS to handle mixed state (Issue #113)

@malcolm-dsider https://github.com/malcolm-dsider Is lithostatic pressure still applicable here, in AGSWellBores.laplace_solution? https://github.com/softwareengineerprogrammer/GEOPHIRES-X/blob/86437fa104a20d1f9f5effc7f8475c5aad70b8bd/src/geophires_x/AGSWellBores.py#L253-L256

— Reply to this email directly, view it on GitHub https://github.com/NREL/GEOPHIRES-X/issues/113#issuecomment-1941951134 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AWGVYTYGN4VJOWXT7B4SGF3YTOIDHAVCNFSM6AAAAABC4TLVL2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBRHE2TCMJTGQ . You are receiving this because you were mentioned. https://github.com/notifications/beacon/AWGVYTZIZGFJJDXFGXQ7ETTYTOIDHA5CNFSM6AAAAABC4TLVL2WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTTX7JJ4.gif Message ID: @. @.> >

softwareengineerprogrammer commented 7 months ago

Looking at providing lithostatic pressure to vapor pressure calcs now. Initial implementation yields drastic changes in results - unclear to me whether this is expected/accurate/correct or a miscalculation. (By comparison, making density, heat capacity, and viscosity, pressure-aware resulted in relatively small changes to results, on the order of 1-15% in most cases.) It may also be an issue with CoolProp - at 100 MPa it gives very large numbers that seem like some kind of fallback/giving up, but I'm not familiar enough with vapor pressure to evaluate whether this is reasonable/expected behavior.

@malcolm-dsider can you confirm lithostatic pressure is appropriate to use in the following usages of vapor_pressure_water_kPa?

  1. https://github.com/softwareengineerprogrammer/GEOPHIRES-X/blob/d779d662678e5bfe44da6db41ea6fd15ce3dfabb/src/geophires_x/WellBores.py#L349
  2. https://github.com/softwareengineerprogrammer/GEOPHIRES-X/blob/d779d662678e5bfe44da6db41ea6fd15ce3dfabb/src/geophires_x/WellBores.py#L469
malcolm-dsider commented 7 months ago

Let’s discuss this in our meeting today. I think Koenraad will have to weigh in on this one.

From: Jonathan Pezzino @.> Sent: Tuesday, February 13, 2024 12:02 PM To: NREL/GEOPHIRES-X @.> Cc: Malcolm Ross @.>; Mention @.> Subject: Re: [NREL/GEOPHIRES-X] Investigate using CoolProp instead of/in addition to IAPWS to handle mixed state (Issue #113)

Looking at providing lithostatic pressure to vapor pressure calcs now. Initial implementation yields drastic changes in results - unclear to me whether this is expected/accurate/correct or a miscalculation. (By comparison, making density, heat capacity, and viscosity, pressure-aware resulted in relatively small changes to results, on the order of 1-15% in most cases.) It may also be an issue with CoolProp - at 100 MPa it gives very large numbers that seem like some kind of fallback/giving up, but I'm not familiar enough with vapor pressure to evaluate whether this is reasonable/expected behavior.

@malcolm-dsider https://github.com/malcolm-dsider can you confirm lithostatic pressure is appropriate to use in the following usages of vapor_pressure_water_kPa?

  1. https://github.com/softwareengineerprogrammer/GEOPHIRES-X/blob/d779d662678e5bfe44da6db41ea6fd15ce3dfabb/src/geophires_x/WellBores.py#L349
  2. https://github.com/softwareengineerprogrammer/GEOPHIRES-X/blob/d779d662678e5bfe44da6db41ea6fd15ce3dfabb/src/geophires_x/WellBores.py#L469

— Reply to this email directly, view it on GitHub https://github.com/NREL/GEOPHIRES-X/issues/113#issuecomment-1942113946 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AWGVYT5PKQLMUF55ZK7QVA3YTOTC5AVCNFSM6AAAAABC4TLVL2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBSGEYTGOJUGY . You are receiving this because you were mentioned. https://github.com/notifications/beacon/AWGVYT6SOSQ6OJKSFH4UPHDYTOTC5A5CNFSM6AAAAABC4TLVL2WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTTYJHJU.gif Message ID: @. @.> >

softwareengineerprogrammer commented 7 months ago

Per sync discussion with @malcolm-dsider 2024-02-13, deferring calculating vapor_pressure_water_kPa with pressure for now since existing calculation should be sufficient for continuing with other SHR work, created tracking issue: https://github.com/NREL/GEOPHIRES-X/issues/118

softwareengineerprogrammer commented 7 months ago

Deferring pressure for enthalpy/entropy for now since those are only relevant to HIP-RA, tracking with https://github.com/NREL/GEOPHIRES-X/issues/119