PMEAL / OpenPNM

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

Stitching parts of different networks together #1700

Closed Eravalord closed 4 years ago

Eravalord commented 4 years ago

Hello everyone!

I am thinking about stitching together networks in such a manner that for example I take 2 times 10x10x10 networks with x width, and I would like to create a new network in which every pore and throat below x/2 (width) inherits 1st network's properties, and above x/2 inherits 2nd network's properties (so connections, geometries remain). Throats which overlap with both sides should be trimmed, and connections should be made with the closest possible pores at the boundaries. I would like to inquire if there is any command that could help me or do I have to create this function from the very beginning?

Thank you for your help! :)

jgostick commented 4 years ago

Perhaps a 2D drawing would be helpful to get a clearer picture, but it sounds like this example should help you.

Eravalord commented 4 years ago

I made a magnificent sketch as an aid, I hope it clarifies my problem: image So basically every pore and throat would be kept from the left side of Nw1 and from the right side of Nw2 in the combined Nw, however throats crossing boundary should be trimmed, and instead of those, new connections should be made between pores on the right and left side of the boundary (function 'stitch' has an option to connect pores in such a way).

Eravalord commented 4 years ago

I think the main difference between my hypothetical scenario is that I would like to "cut" the network at a certain coordinate, and eventually create an indentical big network as the previous two, whereas in this example the new network is going to expand in space, or am I wrong?

jgostick commented 4 years ago

The color-coding is great!

So, the 'stitching' example I pointed you to is still relevant, but you'll have to go though a few hoops. Let me try to enumerate the steps:

  1. identify the pores in each network that you plan to remove, and label them (e.g. 'pore.to_be_removed')
  2. Identify all pores in each network that are connected to a 'to_be_removed' pore, using the find_neighbor_pores method (for a tutorial on the advanced usage of this method see here.
  3. Label these pores for future reference (eg. 'pore.new_surface').
  4. Do the trimming of the pores on both networks
  5. Position the remaining portions of the networks where you want them, by adjusting one of the 'pore.coords' for example
  6. Use the 'stitch' method as illustrated in the previous example, with mode set to 'nearest'. For the P_network and P_donor, you'll use the 'pore.new_surface' label that you created in step 3.

That should do it, but nothing ever quite works right on the first try...so let me know how it goes.

Eravalord commented 4 years ago

I am almost finished with the problem exactly in the way you proposed, however the stitching does not work for this very particular reason: image Does it have anything to do with the fact that phases are added as well?

jgostick commented 4 years ago

We have relaxed that limitation in the latest versions, but I'm not sure we've merged it into the release branch yet. The problem is that we don't know what values to put into the new locations. Say you've set pore.temperature to 333K in all pores on network 1, but you just added a bunch of new pores...we don't know their temperature. In our new version we just put nans everywhere, including converting integer arrays to float arrays (since there is no nan for ints). We have one more feature to add to the current dev before we do a new release, so it won't be long. Do you know how to checkout the git repo and run openpnm from source?

Eravalord commented 4 years ago

If an algorithm will be run, and it does not rely on previously calculated data, basically it is not necessary to know those values, right? Unfortunately, I do not know how to do that, would it make possible to reach the latest unreleased updates?

jgostick commented 4 years ago

I anticipated your question and I just made a tutorial for this. It's a bit rough around the edges and could use some edits. Perhaps you could give me some feed back on how it may be improved, or better yet, make edits yourself, and make a pull request to have your edits merged in?

Eravalord commented 4 years ago

I have tried this out, but unfortunately still drops the same error:

image

Thank you, this small tutorial was really useful! For me it was a bit hard to get out information from it at first, a bit more indention and less text would highlight and make the point more transparent!

jgostick commented 4 years ago

I am so sorry...I fixed this in the merge and extend functions, where the problem actually happened, but forgot to remove it from the stitch function. I will push a fix asap, on a branch called 'fix_stitch_phase_limit', so you can pull that branch and try it out.

Eravalord commented 4 years ago

Thank you very much, that would be really nice, especially if it worked as well after the fix! 😃

Eravalord commented 4 years ago

In the meantime I have tried out the stitching, and it works with the dev, thank you very much once again! However, I encountered a problem connected to the geometry: How can I import geometry from donor geometry to main geometry including all pore and throat data? These values are not automatically included in the main geometry after stitching.

jgostick commented 4 years ago

Hmmm, I would have thought that the geometric properties of the donor were kept and transferred to the recipient. Can you do print(net1.project)? It should have 1 network and 2 geometries.

Eravalord commented 4 years ago

True, you are right! Actually, there is just one geometry, but all the pores and throats were merged into that one. Nevertheless, visualization did not work (saving to VTK), although network health is shown as good.
image

jgostick commented 4 years ago

OK, I have been able to reproduce this error when stitching two cubic networks together. I will work on a fix this morning.

NiveKulkarni commented 3 years ago

Hello!

I am trying to use a similar method to stitch two phases in the extracted network. My 3D geometry has three phases. I have extracted PNM using the snow algorithm and now I need to stitch two phases such as I could use the stitched phase as a single domain (with two subdomains). During stitching operation, I have to use all the pores (internal and boundary), but I am getting this error

'NoneType' object has no attribute 'geometries'

I am not able to pass it through this. I want to understand what should I change to stitch the networks.

Thank you for your help! :)

jgostick commented 3 years ago

I'm sorry, but it's not really clear from your explanation what you're trying to get. Could possible draw a 2D example?

BTW, the error your getting is an OpenPNM object management issue, not any sort of fundamental block. Once I see what you're trying to do I may be able to suggest a plan. If not, then I can take a look at your code to see about that error.

NiveKulkarni commented 3 years ago

OpenPNM_stitching

Thank you so much for the super quick reply :)

Phase 1 and phase 2 undergoes a chemical reaction and forms one solution. The solution then reacts with Phase 3. Hence, to solve the first reaction chemistry, I am planning to use merge phase 1 with 2

The steps I followed here are

  1. extracted pore networks using snow
  2. generated GenericNetwork
  3. Labelled the pores in the donor phase
  4. Merged networks
  5. stitching all the pores from phases 1 and 2. I am getting the error in the stitching step
NiveKulkarni commented 3 years ago

error

image

jgostick commented 3 years ago

Could you use the new snow2 algorithm in porespy v2? It automatically extracts networks for multi-phase images.

https://porespy.org/modules/generated/porespy.networks.snow2.html