Modernization efforts for the R -Matrix code SAMMY

. The R-Matrix code SAMMY [1] is a widely used nuclear data evaluation code focused on the resolved range, which includes corrections for experimental e ﬀ ects. The code is still mostly written in FORTRAN 77 and uses a memory management system suitable for the time of its initial writing in 1984. A modernization e ﬀ ort is underway to update the code to modern software development practices. A continuous-integration testing framework was added to automate the large existing set of test cases. Improvements in memory management were implemented to make the code easier to maintain and enable enhancements. The resonance parameters and covariance information are now stored in C ++ objects shared by SAMMY and AMPX [2], which is the processing code that generates nuclear data libraries for SCALE [3]. Further plans include switching to the Evaluated Nuclear Data File (ENDF) reading and writing routines in AMPX because these routines are more robust, easier to maintain, and support more features. Support for the new Generalized Nuclear Database Structure (GNDS) format [4] is also of interest. GNDS will share not only the resonance parameters but also the parameters associated with experimental correction in GNDS. The data are currently available in a binary SAMMY format, and the ability to export them to GNDS would make them more widely available and shareable. The next step will be to use the same resonance processing code at 0K in AMPX and SAMMY as an available formalism. Then, any improvements in the formalism can immediately be tested in SCALE because the reconstruction in AMPX will use the same cross section model. The new data library can then be used for testing using the VALID Benchmark suite [5] or other suitable benchmark suites.


Introduction
The R-Matrix code SAMMY [1] is widely used to analyze experimental data in the resolved resonance range (RR). Although mostly focused on evaluation in the RR, some capabilities for the unresolved resonance range (URR) are also available. The RR has a extensive set of corrections for experimental effects that aids in the analysis.
At the beginning of the modernization cycle, SAMMY still mostly consisted of fixed length Fortran 77 code and used a memory management system suitable for the time of its initial writing in 1984. A modernization effort is underway to update the code to modern software development practices and allow the use of modern tools for better code error detection. However, because SAMMY is * e-mail: wiardadam@ornl. gov This manuscript has been authored by UT-Battelle, LLC, under contract DE-AC05-00OR22725 with the US Department of Energy (DOE). The US government retains and the publisher, by accepting the article for publication, acknowledges that the US government retains a nonexclusive, paid-up, irrevocable, worldwide license to publish or reproduce the published form of this manuscript, or allow others to do so, for US government purposes. DOE will provide public access to these results of federally sponsored research in accordance with the DOE Public Access Plan (http://energy.gov/downloads/doe-public-access-plan). used in production environments, functionality cannot be lost during the modernization effort. Also, because of the complexity of the experimental corrections and intricacies of the fitting algorithm, SAMMY cannot be rewritten from scratch to modern software specifications. Nevertheless, modernization is needed to enable the addition of new features (e.g., new and improved algorithms in the resolved range).
SAMMY has a large suite of regression tests that can be run and checked against known, good outputs. This suite of regression tests has been automated to indicate any relevant changes in the output due to changes in the code. During the modernization process, this test suite will be run on each commit to ensure continued correctness of the results. The known, good test results will not be changed unless errors in the original coding are found and corrected. Several members of the SAMMY team carefully review these changes before accepting them. was limited. Although the design choices were excellent for that time, faster computers and the availability of more memory allow to update the code easier to make it easier read and maintain. The two main components in SAMMY that are attributable to the initial design choice are (1) the container array and (2) writing various scratch files. The scratch files are eliminated as new parts of the SAMMY code base are modernized. In the original design, a large chunk of memory was created at compile time, and pieces are allotted to arrays as needed during calculations. Drawbacks include the need to determine at compile time the size of the problems that SAMMY can handle and the need for SAMMY to handle memory allocation-a task the operating system is better equipped to handle. Additionally, modern tools such as Vagrind [6] cannot be used to detect overstepped array bounds.
Researchers decided to take two different approaches: (1) use FORTRAN dynamically allocated arrays where appropriate and (2) use internal C++ storage options where code is converted. Although both methods might be less efficient than using the allocation from a large existing array, they provide better error detection and more granularity on the memory used. They will also allow performance bottlenecks to be pinpointed, which will addressed as needed without affecting the internal working in SAMMY. This is especially true for the internal C++ classes because SAMMY only accesses the information via well-defined interfaces.
The use of the container array in SAMMY was completely eliminated, and the use of tools such as Valgrind aided greatly in finding and fixing many memory errors in SAMMY. Although these code errors did not necessarily affect the test results, they can affect SAMMY analysis. New test cases were added to capture behavior that was not previously tested. One added benefit is that the size of the problem that can be analyzed now depends on the computer memory and no longer depends on compile time options.

Modular design
Because of the computing power limitations at the initial writing of SAMMY, various parts of the code needed to be very interdependent and share many global parameters. This made the code more difficult to understand and update with new features. In addition it was not possible to reuse parts of SAMMY in other projects (e.g., resonance reconstruction, experimental correction), or to implement other fitting routines into SAMMY. The ability to share resonance reconstruction and derivatives of the resonance parameters with respect to cross section with AMPX [2] would be very useful. Because AMPX uses many of the same developers as SAMMY, it is advantageous to share as much code as possible. Sharing code would make SAMMY more efficient and allow any new features in the resonance algorithm to be available in AMPX and thus in SCALE [3] transport libraries. Thus, the desired outcome is an application program interface (API) for major components in SAMMY. These components (e.g., reconstruction of cross section and angular distributions from resonance parameters, Doppler broadening, resolution broadening, and parameter adjustment) should not use any global parameters.
AMPX has an in-memory C++ class that collects all RR and URR parameters, and this class is now used throughout SAMMY, thus enabling the easy exchange of resonance parameters between SAMMY and other programs. This feature has already been used to explore different adjustment methods [7]. Additionally, the resonance processing for the RR in SAMMY can now be called via an API. Unfortunately, because of how the fitting and covariance information are set up in SAMMY, the resonance processing at 0K still uses a few global parameters, not the resonance parameters. The user input determines which algorithm to use for the cross section calculation and sets up the correct module so that the API for each of the modules is independent of the algorithm. The same is true for the Doppler broadening modules. Modularization of the resolution broadening routines is currently in progress.
A new C++ in-memory class was added to SAMMY to address the storage of cross section, angular distributions, and derivatives. This class offers easy access methods to the underlying information. The calling routines are thus shielded from internal storage information, which might change in future updates to speed up access. This class allowed much duplicate code to be removed from the existing code base that repeatedly had complicated access patterns to this information and made it much easier to separate data storage from the algorithm. These updates also uncovered and fixed previous errors in which the cross section or derivatives were not placed in the correct position on the FORTRAN arrays.
One integral part of the adjustment procedure is the covariance matrix with respect to the varied parameters. There are two aspects to the covariance matrix as it pertains to SAMMY: the covariance matrix itself and the index into the matrix for a given varied parameter. For the covariance matrix, the storage was switched to a C++ matrix class from AMPX. The class offers convenience functions to set and retrieve matrix elements while shielding SAMMY code from the underlying storage information, enabling a matrix object to be used that internally suppresses zeros without needing the client code to have any knowledge of the suppression. Previously, the covariance matrix was stored and retrieved many times in scratch files. The change to the AMPX covariance matrix class enabled the elimination of scratch files connected to this information. Additionally, a new class was added to track the indices of the varied parameters in the covariance matrix. SAMMY enables unvaried parameters with uncertainties incorporated into the data covariance matrix. In the context of SAMMY, these parameters are called pup'ed parameters. The new class is especially helpful in managing these two types of parameters because the parameter type was previously determined by the order in the covariance matrix. A new function was also added to determine the parameter type, so client code does not need to be concerned with the order of the covariance matrix.
As the modularization progresses, it will be possible to access various aspects, such as resonance reconstruction or experimental correction, from programs outside SAMMY. To allow this, a prototypical API was added to SAMMY. Currently, the API only offers methods to (1) read input and experimental data information; (2) calculate cross sections corrected for experimental conditions, including derivatives; (3) update adjusted parameters to enable external fitting routines; and (4) retrieve covariance information for resonance parameters. Currently, the use of global parameters poses some limitation on API functionality. However, as these limitations are removed, the API should become easier to use.

Future updates
SAMMY currently uses its own routines to write Evaluated Nuclear Data File (ENDF)-formatted files [8]. Because of the computing power limitations at the time of writing SAMMY and the constraints this puts on the code, these routines are becoming more difficult to maintain, especially because the resonance parameters and covariance information were moved to C++ storage. However, AMPX has extensive support for reading ENDF-formatted files and some support for writing. SAMMY will be changed to use these routines, and the writing capablity in AMPX will be updated as needed. The ENDF community is switching to a new ENDF format called Generalized Nuclear Database Structure (GNDS) [4]. AMPX already has support to handle this new format, thus enabling SAMMY to gain the capability to natively support the new format. This will become especially important as updates to the resonance formalism are proposed and added to the GNDS format.
Additional planned updates include introducing an imaginary component to the R-matrix channel radii to parameterize eliminated direct capture channels in Reich-Moore approximation. Improvements in the URR are also needed, especially to enable the simultaneous fitting of the RR and the URR. Ultimately, the modularization of the code and the elimination of global parameters will enable the use of multiple targets and compound systems.

Conclusion
A significant modernization effort for the R-Matrix code SAMMY is underway. Thus far, the work has focused on making the code easier to maintain while not breaking any functionality. To make this process more efficient, some functionality already available in AMPX was used in SAMMY. These changes will enable the sharing of resonance structure and formalism, as well as make it easier to test advancements in resonance formalism in the SCALE transport code. Additionally, the code base was made more modular, enabling a cleaner interface to reconstruct cross sections, Doppler broadening, and resolution broadening. This enabled researchers to build a prototypical API to SAMMY that can be used in external programs to use any of these parts separately. Although further work is needed to improve this API, it already has already been used in a current project [7].