Skip to content
ukaeaPublic

About

Monte Carlo Input/Output - A python API and command line tool for the production of constructive solid geometry (CSG), either parametrically or via CAD-to-CSG

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

33 Commits

Folders and files

Repository files navigation

MCIO

Publish docs and badges Tests Coverage Ruff score Documentation Release Python License: MIT

Docs

https://ukaea.github.io/mcio/

Quick start

Warning

  • MCIO uses CM for length and MeV for energy.
  • MCIO requires STEP files to use the AP242 schema.

The MCIO CAD-to-CSG package can be installed for the end user and run via the command line.

python -m mcio decompose -i my_model.stp -m my_materials.json -t my_tallies.json --cores 20

The above will convert a step file (AP242 standard) to CSG then to MCNP file, writing the output to MCNP6 input format to output/mcnp_model.i and to OpenMC XML format if installed to output/openmc.

Installation

End user installation (dependencies via Pip - Windows, Mac and latest debian Linux)

MCIO can be installed from source using the below commands, with the dependencies installed for cad and jupyter using the extras [cad,jupyter]. The CAD and Jupyter dependencies are not required to run the non-CAD-to-CSG.

git clone https://github.com/ukaea/mcio.git

python -m pip install .[cad,jupyter]

To write OpenMC models, install its Python API, see the OpenMC installation guide.

Dev installation

For those wishing to contribute to development, you can install all dependencies for docs,

git clone -b dev https://github.com/ukaea/mcio.git

python -m pip install .[dev,docs,cad,jupyter]

The test suite also needs OpenMC; CI installs it with:

python -m pip install "openmc @ git+https://github.com/openmc-dev/openmc.git@83a30f6860c79fac8fd58584489cc0d1abcb0376"

Running MCIO - command line

Running MCIO via the command line is the easiest way to produce a model with materials and some common tally types. The below example runs via 20 core multiprocess and assigns materials by RGB and some basic tally types. Materials are assigned by RGB colour or by m1 type labels, depending on the keys used in the materials JSON.

python -m mcio decompose -c 20 -i my_model.stp -m my_mats_rgb.json --tally my_tallies.json
{
    "_m1_": {
        "density": 0.997,
        "composition": {
            "H": 0.666667,
            "O": 0.333333
        },
        "number": 100,
        "reference": "https://www.pnnl.gov/main/publications/external/technical_reports/PNNL-15870Rev2.pdf",
        "fraction_type": "ao",
        "density_type": "g/cc",
        "name": "Water, Liquid",
        "mcnp": {
            "sab_cards": [],
            "libs": {},
            "library": ""
        }
    }
}

The open cascade based OCP modules (the CAD-to-CSG decomposer and its helpers) are loaded automatically by import mcio when OCP is installed.

This allows users who don't need the CAD-to-CSG decomposer not to need OCP installed, which can require Conda on non Windows/modern Debian systems. Without OCP, import mcio logs a warning and the non-CAD modules (surfaces, cells, materials, tallies, sources and MCNP/OpenMC output) work as normal.

import mcio

Development

Branches

Work is done on feature/<name> branches, which are the only branches that can be pushed to directly.

  1. Branch from dev and push your changes to a feature/ branch.
  2. Open a pull request from the feature branch into dev.
  3. Releases are made by a pull request from dev into main; pull requests into main from any other branch are rejected.

Pull requests need an approval and passing checks before they can be merged.

Tests

Tests are run with pytest, with coverage collected in the same run:

python -m pytest --cov

Linting and formatting

Code is linted and formatted with ruff. CI only blocks a pull request on real bugs (syntax errors and invalid constructs); all other findings and formatting lower the ruff score but do not fail the check. CI does not change files, so to tidy up before pushing run:

ruff format mcio tests
ruff check --fix mcio tests

The pylint-style score shown on the Ruff badge can be produced locally with:

python scripts/ruff_score.py mcio

About

Monte Carlo Input/Output - A python API and command line tool for the production of constructive solid geometry (CSG), either parametrically or via CAD-to-CSG

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages