PMEAL / OpenPNM

A Python package for performing pore network modeling of porous media
http://openpnm.org
MIT License
454 stars 174 forks source link

Bug when mixing symmetric and asymmetric conductance in different domains #2843

Open mkaguer opened 1 year ago

mkaguer commented 1 year ago

Please refer to this line here

I ran into this problem when working on my lithium ion battery model. In the electrolyte phase I have diffusive-migrative conductance that is asymmetric meaning that the conductance is a Nt by 2 array. However, in the active material phase, I have pure diffusive conductance that is a Nt by 1 array. The code runs into a problem when it tries to merge these models from each domain. The bug occurs at the line I linked to above. To get around this issue, I wrote my own diffusive conductance model in the active material phase that writes it as an Nt by 2 array (where the conductance is the same for the first and second columns). I know this is how OpenPNM used to return conductances. Maybe we should revert back to this? Or be able to merge symmetric and asymmetric conductances together.

ma-sadeghi commented 1 year ago

I'd say let's always use Nt by 2. One downside is memory footprint, but we're storing lots of other properties (like T, p, etc.), so it's not really noticeable. Any other downsides? @jgostick @mkaguer

jgostick commented 1 year ago

I can't think of any reason why not. Just be careful with the ordering of the elements, like C vs F. I recently rediscovered that you can't just flatten our conns array and use it an an index because the two columns interlace rather than stack. I mention this because Mehrez has an explicit comment about this where he builds the Nt-by-2 conductances for advection-diffusion.

mkaguer commented 1 year ago

Should I go ahead and fix this then? I will make all conductances Nt-by-2.

ma-sadeghi commented 1 year ago

Yes, please make PR

ma-sadeghi commented 1 year ago

While you're at it, you could also add a test that goes through all our conductance models and ensures the shape is correct. Don't hardcore it, you can programmatically do this so it'll catch future conductance models as well