OpenCCM is a CFD-based compartment modelling software package. It is primarily intended for convection dominated reactive flows which feature a weak or one-way coupling between the reactive species and the carrier fluid, i.e. the reaction does not substantially influence the fluid flow over the course of the simulation.
It uses the elements_not_in_a_compartment set inside _calculate_compartments to avoid having to change the element connectivity inside the CMesh object, allowing it to be immutable and less error prone.
It Further speeds up _calculate_compartments by changing seeds from being a List (poorly chosen on my part) to the keys in an OrderedDict.
Some more explanation on point 2. The seed elements are initially specified by the user, but the collection gets expanded upon by the _calculate_compartments as each compartment is grown. It involved tens of thousands of evaluations of if x not in seeds on large meshes, which is O(N) in time where N is the number of seed elements. N can easily get into the tens of thousands.
A replacement to List needed: 1) constant time lookup, 2) maintain insertion order, and 3) a way to pop items from the front of the insertion order. Alternative options could have been Set, Dict, or Deque but none had all three.
Instead the keys of an OrderedDict are used, which satisfies all 3 criteria. The value used for each key is None in order to keep the total size to a minimum.
This PR does two related things:
elements_not_in_a_compartment
set inside_calculate_compartments
to avoid having to change the element connectivity inside the CMesh object, allowing it to be immutable and less error prone._calculate_compartments
by changingseeds
from being a List (poorly chosen on my part) to the keys in an OrderedDict.Some more explanation on point 2. The seed elements are initially specified by the user, but the collection gets expanded upon by the
_calculate_compartments
as each compartment is grown. It involved tens of thousands of evaluations ofif x not in seeds
on large meshes, which is O(N) in time where N is the number of seed elements. N can easily get into the tens of thousands.A replacement to List needed: 1) constant time lookup, 2) maintain insertion order, and 3) a way to pop items from the front of the insertion order. Alternative options could have been Set, Dict, or Deque but none had all three.
Instead the keys of an OrderedDict are used, which satisfies all 3 criteria. The value used for each key is
None
in order to keep the total size to a minimum.