Apply trapping based on algorithm described by Y. Masson [1]. It is applied as a post-process and runs the percolation algorithm in reverse assessing the occupancy of pore neighbors. Consider the following scenario when running standard IP without trapping, three situations can happen after each invasion step:

  • The number of defending clusters stays the same and clusters can shrink

  • A cluster of size one is suppressed

  • A cluster is split into multiple clusters

In reverse the following opposite situations can happen:

  • The number of defending clusters stays the same and clusters can grow

  • A cluster of size one is created

  • Mutliple clusters merge into one cluster

With trapping the reversed rules are adjusted so that only clusters that do not connect to a sink can grow and merge. At the point that a neighbor connected to a sink is touched the trapped cluster stops growing as this is the point of trapping in forward invasion time.

Logger info displays the invasion sequence and pore index and a message with condition number based on the modified trapping rules and the assignment of the pore to a given cluster.

Initially all invaded pores are given cluster label -1 Outlets / Sinks are given -2 New clusters that grow into fully trapped clusters are either identified at the point of breakthrough or grow from nothing if the full invasion sequence is run, they are assigned numbers from 0 up.

Ref: [1] Masson, Y., 2016. A fast two-step algorithm for invasion percolation with trapping. Computers & Geosciences, 90, pp.41-48

  • outlets (list or array of pore indices for defending fluid to escape) –

  • through


  • Creates a throat array called ‘pore.clusters’ in the Algorithm

  • dictionary. Any positive number is a trapped cluster

  • Also creates 2 boolean arrays Np and Nt long called ‘<element>.trapped’