Multiphase multicomponent buoyancy discretization#1482
Conversation
Create test_fluid_property_library.py Create test_buoyancy_flow_benchmark.py Create test_buoyancy_flow.py Create buoyancy_flow_model.py Update compositional_flow.py
328294d to
dced645
Compare
ec12595 to
a4efd54
Compare
|
Thanks for the PR, @OmarDuran, this is a great contribution! I will start the review today or tomorrow, but it may take a little while to digest it all. From a very brief glance, it appears that I may have some questions or suggestions regarding how the functionality is included in the multiphysics models, but I have to read more carefully to move any further there. As mentioned previously, I am prepared to help out or take care of most of any modifications to the code; let's discuss when we get there. I see that two tests are failing since the I can also have a look at what happens with |
Regarding the test failures, they are now resolved. The dependency on chemicals is important for practical applications, so I would appreciate it if #1461 could be merged soon. For this PR, however, I have refactored and removed the dependency on chemicals. For further modifications, I would like to stay in the loop, as I am finalizing a manuscript on this subject and need to closely follow any changes. Regarding the inclusion in multiphysics models. The main challenge, in my view, is distinguishing what belongs to the discretization from what belongs to the reformulated expressions. I also find it difficult to understand why |
|
Thanks for taking care of the tests. We also hope #1461 to be completed soon, though it will still take a little while due to other commitments.
Of course!
This is indeed a good question, that part of the code is best though of as still under construction. We may revisit this as part of this PR, but it could be better to do that in a separate process to limit the number of moving parts. I will have to read the code more deeply to make an assessment. |
Avoid Ad operator evaluation inside a tight loop.
keileg
left a comment
There was a problem hiding this comment.
I think this mainly looks good. The discretization itself is very well structured and should be easy to follow. The few questions that I have are minor stuff, partly on documentation.
I pushed a change that should speed up the update of some parameter dictionaries by avoiding Ad evaluation inside a tight loop. The computations remain really slow, I guess due to the size of the Ad operator tree for upwinding. To try to be constructive, this should be a good test case for improving evaluation speed.
Location of the upwinding: I agree that fluid_property_library is not a logical home for this code. The most natural option is constitutive_laws, but as you know all too well, that file is far too large already. I suggest we leave this for now and then possibly move later - it should make no difference to your future use of the code (right?).
To move forward, I suggest that you have a look at my comments and see what makes sense and not. Let me know if you want me to take care of the implementation of some of the parts. I would also like to add some more documentation, including method docstrings, so that I will recall what the methods are doing in half a year. I'll try to do this over the next 1-2 days, if you don't mind; no code will be touched, so there should be no impact for your work.
Let me know what you think.
I think the following context is important. This is a non-isothermal, compositional multiphase implementation that relies heavily on the Upwind and UpwindCoupling classes. The test and benchmark files run simulations with at most three components and three phases, and as you know, nonlinear mixed-dimensional simulations in PorePy are naturally slow. I can improve the runtime by roughly half, but the current implementation is already as fast as possible given the extra upwinding. Further speed-ups in the Upwind and UpwindCoupling classes would require clear guidance from your end on how to do so. The good news is that if a faster implementation of the Upwind and UpwindCoupling classes is available, this code will automatically benefit from it. Another point is that including all terms required for buoyancy effects in non-isothermal compositional multiphase equations naturally increases the AD operator tree, and including capillarity would make it even larger. If you expand and account all those non-linear terms, it makes this clear. Overall, the proposed implementation is compact and can be reused for capillary effects, which is a major advantage.
To be honest, I also don’t find it logical to mix constitutive laws with discretizations. I think we can follow up this in another PR if needed.
I have almost addressed your comments.
|
|
To clarify my comment regarding computational cost: This was not meant as criticism of the implementation - the formulation is what it is and as you point out, the assembly scales poorly with growing size of the operator trees. Rather, my point was that the availability of this functionality will accentuate the need for doing more fundamental work on the assembly, but that is my job, not yours. So, no worries! |
Co-authored-by: Eirik Keilegavlen <Eirik.Keilegavlen@uib.no>
The new location is applications.test_utils, together with other such arrays of reference values
The current Ad framework makes this too slow even as a skipped test
|
I pushed some changes:
Does this sound fair to you? |
Thanks for the updates. The docstrings for the upwinding discretization look good, no issues there. I agree with reducing the test load in Overall, the changes look good to me. |
|
Thanks. I will delete the commented lines and then approve and merge. |
Proposed changes
This PR introduces a mixed-dimensional hybrid upwind discretization for non-isothermal (enthalpy-based) multiphase, multicomponent flow. The implementation is based on the fractional flow formulation of the compositional equations I proposed a few years ago. It reuses the existing upwind discretization to minimize changes to the framework. Support for the standard form of the equations is not included in this PR but could be added by unfolding the definitions of the fractional flow formulation.
The following test are included
porepy/tests/models/test_fluid_property_library.py
This is a unit test for FluidBuoyancy.
porepy/tests/functional/test_buoyancy_flow.py
The integration/application test includes the following combination
Fluid type: N-phase N-components, N = {2,3} (x2)
Geometry type: Fixed- and Mixed-dimensional (x2)
Dimension: d = {2,3} (x2)
Order of conservation loss (overall mass, component mass, total fluid energy): order = {2,3,4} (x3)
Total number of test = 2x2x2x3 = 24
This test is a slow test and mark skipped.
porepy/tests/functional/test_buoyancy_flow_benchmark.py
This test runs a 3D simulation of two-phase flow in a vertical column under the effect of gravity. It is parameterized to run for three different density contrasts between the two fluids. The test validates the numerical results by comparing the final saturation profile against a reference analytical solution from Hayek, M., et al. (2009),
"An analytical solution for one-dimensional, two-phase, immiscible flow in a
porous medium," published in Advances in Water Resources.
This benchmark test provides a plotting functionality. It is controlled by an environment variable. To generate plots, run:



(Linux/macOS):
export RUN_PLOTS=1pytest --run-skipped tests/functional/test_buoyancy_flow_benchmark.pyTest plot for low density contrast:
Test plot for moderate density contrast:
Test plot for high density contrast:
This test is a slow test and mark skipped.
As an example of the functionality, here you can see an example of mixed-dimensional segregation of two phases in 3D:
https://github.com/user-attachments/assets/69d0ce8e-4e9a-45a4-a3d2-fe1be0e77b94
Types of changes
What types of changes does this PR introduce to PorePy?
Put an
xin the boxes that apply.Checklist
Put an
xin the boxes that apply or explain briefly why the box is not relevant.pytestwas run with the--run-skippedflag.