uw-comphys / openccm

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.
https://uw-comphys.github.io/openccm/
GNU Lesser General Public License v2.1
0 stars 3 forks source link

Fix floating point issue in tweak_compartment_flows #13

Closed Alex-Vasile closed 5 months ago

Alex-Vasile commented 5 months ago

Current implementation performs the flow optimization on the original flowrate values. This can lead to numerical issues if there exist flowrates which are very small (order of 1e-6) which were not removed earlier in the process (e.g. if the user-set tolerance was 1e-7). The optimization routine struggled to properly account for them, resulting scenarios where net-outflow remained.

This PR scales all flows by on the smallest flowrate for the purposes of optimization, and then rescales them back to their original ranges. The checks for conservation of mass are performed after this scaling to ensure that the final values satisfy the no net-outflow condition.