acroucher / PyTOUGH

A Python library for automating TOUGH2 simulations of subsurface fluid and heat flow
GNU Lesser General Public License v3.0
96 stars 36 forks source link

MULGraph grid to TOUGH2 grid fails due to deleted columns in 1.5.4 #27

Closed matthiaskardel closed 3 years ago

matthiaskardel commented 3 years ago

When deleting a column of a MULGraph Grid the conversion into a TOUGH2 Grid fails. This is due to a call in t2grids.add_underground_blocks, which references potentially deleted columns, here.

A possible workaround is a continue the for loop in add_underground_blocks on a KeyError exception, yet not very elegant.

Reproduction:

  1. Have a mulgrid
  2. Delete column on mulgrid
  3. Convert mulgrid to t2 grid t2grids.t2grid().fromgeo(mulgrid)
acroucher commented 3 years ago

If you are doing any low-level surgery on your mulgrid geometry, like adding or deleting individual columns, you will need to rebuild the global lists of blocks and connections before converting to a t2grid.

This is not done automatically in methods like mulgrid.delete_column(), because rebuilding these global lists is expensive - so it would slow your code down significantly if you were adding or deleting a lot of columns. For that reason, users of low-level methods need to rebuild them explicitly,

You just need to call these two methods after your column deletion code (if your mulgrid is called geo):

geo.setup_block_name_index()
geo.setup_block_connection_name_index()
matthiaskardel commented 3 years ago

Thank you for the quick answer!

acroucher commented 3 years ago

Does that resolve your problem?

matthiaskardel commented 3 years ago

Yes, thanks!