transmutagen 1.1.0
Code geneartion tools for transmutation solvers
License: BSD 3-clause

# Transmutagen

Transmutation SymPy Code Generator

[![Build Status](https://travis-ci.org/ergs/transmutagen.svg?branch=master)](https://travis-ci.org/ergs/transmutagen)

# Usage

First, get the git master version of SymPy and set `PYTHONPATH` to point to
it.

Transmutagen also depends on

 - mpmath
 - sympy >= 1.1
 - matplotlib
 - numpy
 - scipy
 - pyne
 - jinja2
 - gmpy2
 - Cython

## Generating the CRAM approximation to exp(-x) on [0, oo)

Run

    python -m transmutagen.cram D N

where `D` is the degree of the approximation and `N` is the number of digits.
A typical run would be something like

    python -m transmutagen.cram 14 200

Note that the digits returned are not necessarily all accurate. To compute `N`
correct digits one generally needs to many more working digits in the
computation. Furthermore, when roots are taken, the precision may decrease
even further. So it is recommend to always compute the CRAM expression with a
very high number of digits.

There are many options, but it is not recommending changing them unless you
know what you are doing. See `python -m transmutagen --help`. To
increase/reduce the verbosity of the output, use the `--log-level` flag.

If you use iTerm2, install `iterm2-tools` (from conda-forge) to get plots in
the terminal.

Note: all output and plots are logged to the `logs` and `plots` directories.

## Generating solver code

To generate solver code, use

    python -m transmutagen.gensolve

This will generate ``solve.c`` and ``solve.h``. Use

    python -m transmutagen.gensolve --help

to see various options, such as how to change the degrees that are generated,
and the namespace of the generated functions.

This will use a default list of nuclides and sparsity pattern. To add or
remove nuclides, modify the JSON file, and pass it in with

    python -m transmutagen.gensolve --json-file gensolve.json

The format of the JSON file is

``` json
{
    "nucs": ["H1", "H2", ...],
    "fromto": [["H1", "H1"], ["H1", "H2"], ...]
}
```

Where ``"nucs"`` is a list of nuclides and ``"fromto"`` is a list of lists of
every possible reaction product pair. Every nuclide should be listed as a
reaction with itself.

To generate a JSON file from ORIGEN libraries, run

    python -m transmutagen.generate_json /path/to/origen/libs/ --outfile gensolve.json

This will save the JSON to ``gensolve.json``. Note that transmutagen comes
with a a JSON file generated from ORIGEN in
``transmutagen/data/gensolve_origen.json`` as well as one generated from PyNE
in ``transmutagen/data/gensolve.json``.

The resulting solve.c will have functions
``{namespace}_expm_multiply{N}(double* A, double* b, double* x)``, where
``{namespace}`` is the namespace specified by the ``--namespace`` flag to
``python -m transmutagen.gensolve`` (the default is ``transmutagen``), and
``{N}`` is the degree of the approximation used in the solve, specified by the
``--degree`` flag (the default is ``14``). The function computes ``exp(A)*b``
and stores the result in ``x``.  ``A`` should be in a flattened format,
according to the sparsity pattern the solver was generated from.

## Converting ORIGEN libraries to a sparse matrix representation

If you'd like to convert an origen file to a matrix representation, please
use something like:

    python -m transmutagen.tape9sparse ~/origen22/libs/pwru50.lib --decay ~/origen22/libs/decay.lib

See `--help` and the `transmutagen.tape9utils` docs for more details.

## Running tests against ORIGEN

Put `ORIGEN.zip` in the `docker/` directory. Then run

    ./docker/origen_all/build_and_run.sh

This requires the docker daemon to be running, and may require `sudo`. There
are various options, which you can see with

    ./docker/origen_all/build_and_run.sh --help

This will run both ORIGEN and transmutagen (CRAM) on a suite of ORIGEN
libraries, starting nuclides, and times, writing the results to
`data/results.hdf5`. The output will also be logged to `logs/origen_all.log`.
Be warned total suite takes over 24 hours to run.