cyclus/cyclus — pull request #505 by katyhuff (2013-07-07 17:50:49+00:00)
Title: Threshold

This pull request addresses issues #483 and #484. This pull request is long overdue (I completed it over a month ago, but have had other things going on.) Though it may not seem like it, these changes actually support most of the goals of CEP 17 by adding some needed robustness to the material class and separating the thresholding from previous material equality functionality. By virtue of making these functions more modular, I expect these changes will reduce the coding burden if that CEP is approved. If it is not, these changes and helpful new tests are still quite necessary for material class robustness.

In summary, things that changed in this pull request :

- Things with boost smart pointers should not be passed by reference if they can be passed as boost smart pointers ( it can result in disastrous memory leaks ). So, in a number of cases where CompMap& is seen, it was replaced with the preferred CompMapPtr, which is the boost smart pointer.

- a function called almostEqual() was created to allow a user to compare two CompMaps , given a threshold under which differences are considered negligible by the user.

- instances in which summation over a CompMap occurred can be screwed up by floating point issues if the summation is done naively. Those instances were replaced by a scheme by which summations are conducted using a well known summation algorithm called the KahanSum (a KahanSum algorithm function was introduced in the CycArithmetic class).

- some cleanup was undertaken such that iterators are prepended (that is ++it is preferred over it++ ) .

- a function reporting the diff between two materials was added.

- a function reporting the diff between a material and another composition and corresponding amount was also added.

- a function applying a threshold to a composition was added. That is this function returns the composition such that all elements with an amount below the threshold have been set to zero.

- the == operator was overloaded in the material class to return almostEqual() for a threshold of 0.

- the almostEqual function was introduced in the material class and simply calls back to the compmap almost equal funciton, utilizing information about the material.

- unnormalizeComp was made to be more flexible concerning units.

- a number of tests were added for these new features.