CAD_to_OpenMC
CAD_to_OpenMC: from CAD design to particle transport - Published in JOSS (2025)
Science Score: 46.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
✓Academic publication links
Links to: joss.theoj.org -
✓Committers with academic emails
1 of 7 committers (14.3%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (14.7%) to scientific vocabulary
Scientific Fields
Repository
code to target the conversion from a step-file to a h5m-geometry for neutronics
Basic Info
- Host: GitHub
- Owner: openmsr
- License: mit
- Language: Python
- Default Branch: main
- Size: 49 MB
Statistics
- Stars: 32
- Watchers: 1
- Forks: 21
- Open Issues: 5
- Releases: 10
Metadata Files
README.md
|Main | Development|
|---|---|
||
|
CADtoOpenMC
N.b. Development of CADtoOpenMC has moved to a new organization/repository. Please head there for updates - this repository will no longer receive updates past version 1.0.0-1
This is a python package intended to establish an open source link between CAD tools in general and the nuetron and photon transport code OpenMC. It is inspired by Paramak, and borrows concepts from steptoh5m.
Although most CAD-tools use some other internal and/or native representation for geometry, most, if not all, will be able to export to the STEP-file format. Therefore this is the format we use
CADtoOpenMC uses cadQuery and its links to OCCT
The code structure relies on a main class Assembly, which maintains the geometry in terms of a list of instances of the subclass Entity. A geometry is imported from a (set of) .step files into the entity-list. This list is passed on to a mesher-class which generates a meshed geometry.
We've written a paper covering this software:
Other options
CADtoOpenMC is certainly not the only package that tries to solve this problem. Other options include: - cadtodagmc - stellarmesher
These two packages solve the same problem as CADtoOpenMC, and in fact in many cases are interchangeable. See for instance benchmark-zoo.
To install/set up in a virtual python environment
replace <name> with an arbitrary name for your virtual environment
1. In the directory where you want your environment to reside do: python -m venv <name>
2. Activate the environment: source <name>/bin/activate
3. Build and install moab (if not already installed). The moab team relies on conda for standard installation but are working on a pip-based solution. Once that is done moab would simply be added to the requirements-file instead.
1. Clone the moab code-repository: e.g. git clone https://bitbucket.org/fathomteam/moab.git
2. Configure and build the code:
bash
mkdir build;
cd build; cmake .. -DENABLE_PYMOAB=1 -DENABLE_HDF5=1 -DCMAKE_INSTALL_PREFIX=<name>;
make;
make install;
3. Additionally you will need to build the python interface layer.
bash
cd pymoab
sudo python setup.py install
4. Install the main package: pip install CAD_to_OpenMC. This will pip-install all the required python packages in the virtual environment. This ensures that no additional conflicts are introduced with the system python.
Should you wish to install the development version of this package you may do so by cloning this repository and replace the last command by: pip install <path/to/repo>. This procedure will build and install the python package locally directly from source.
- Optionally install the msh refinement tool mmg (https://www.mmgtools.org), which may be run in conjunction with the cq/stl-mesher backend to avoid the high aspect ratio triangles that this backend tends to produce. Arch-linux users may install this from the AUR, otherwise get the source (and build from that) or binary builds from the mmg-site.
To install in a conda environment
replace <name> with an arbitrary name for your virtual environment
If instead you prefer to use a conda-environment, this is now as simple as:
1. create an environment, e.g. conda create -n <name>
2. activate it: conda activate <name>
3. install CADtoOpenMC: conda install cad-to-openmc
You may of course replace conda with mamba/micromamba, should you prefer to do so.
Known problems
- At present the parallel meshing option is buggy - it is therefore highly recommended to set the mesher to only use 1 thread. The team is working on a solution for this. See issue #80
- Geometries which lead to degenerate toroidal surfaces in the step-files, can have problems. See issue #94
- As is reported in #98 on Ubuntu 22.04 there's a problem with python 3.12. Specifically with installing "nlopt", which is used by one of the dependencies of CADtoOpenMC. We recommend to stay with python < 3.11 until this has been fixed upstream.
Use cases
We will show a few very simple uses-cases below to get you started using CADtoOpenMC, starting with a simply utility script, and then some more examples showing a few of the options later.
Simple utility script
This is the fastest way of getting up and running. A very basic script to process the file 'geometry.step' into a geometry useful for OpenMC in the 'geometry.h5m': ```python import CADtoOpenMC.assembly as ab
A=ab.Assembly('geometry.step') ab.mesherconfig['threads']=1 ab.mesherconfig['tolerance']=1e-2 ab.mesherconfig['angulartolerance']=1e-2 A.run(h5m_filename='geometry.h5m',backend='stl2') ```
This may then be included in an openmc-geometry by this snippet e.g.:
python
import openmc
universe=openmc.DAGMCUniverse('geometry.h5m').bounded_universe(padding_distance=10)
geometry=openmc.Geometry(universe)
Please note that you also have to define materials according to the tags in the h5m-file for openmc to run.
7 pin test case
The follwing code-snippet can now be run to explore the capabilities of Assembly/steptoh5m. We supply a couple of example .step-files in the examples directory. In this example we'll be using a geometry with a set of 7 pin-cells.
python
import CAD_to_OpenMC.assembly as ab
a=ab.Assembly()
a.stp_files=["examples/7pin.step"]
a.import_stp_files()
a.solids_to_h5m()
as of version 0.2.6 a simpler version of this test-script may be used as we have added a small set of convenience functions. One possibility is:
python
import CAD_to_OpenMC.assembly as ab
a=ab.Assembly(['examples/7pin.step'])
a.run()
which will read the 7pin.step example file and output a file by the default name dagmc.h5m
as usual.
Unless anything else is specified this procedure simply uses the default CADtoOpenMC parameters to create meshes using the default choice of meshing backend - namely gmsh. E.g. for the "gmsh"-backend this means sampling curves 20 times, a minimum mesh-element size of 0.1, and a maximum mesh element size of 10. This procedure will in turn call OCP and gmsh to produce a mesh with merged surfaces in the output file "dagmc.h5m"
The other available meshing backends are based on stl-export from CadQuery (accessible by setting backend='stl', or backend='stl2') which uses the parameters tolerance and angular_tolerance to set meshing quality.
E.g. choosing the 'stl2' backend would alter the call to run to:
python
a.run(backend='stl2')
Similarly the output filename may be set using the parameter h5m_filename.
Meshing parameters are changed by means of altering entries in the mesher_config-dictionary defined in the assembly module root namespace. Like:
python
ab.mesher_config['min_mesh_size']=0.2
Below is a list of the available parameters and their meanings:
- min_mesh_size
- Minimum mesh element size (gmsh backend/mmg_refinement)
- max_mesh_size
- Maximum mesh element size (gmsh backend/mmg_refinement)
- curve_samples
- The number of point samples used to approximate a curve, 1D-mesh. (gmsh backend)
- mesh_algorithm
- Integer specifying which meshing algorithm to use (gmsh backend) 1: Adaptive algorithm - most often the most robust choice.
- vetoed
- A list of surfaces that should be excluded from meshing. Useful when some surface fails for whatever reason. Be aware that this may make your geometry non-watertight.
- threads
- The number of threads to be used to speed up the meshing algorithms. Useful for multicore-computers.
- tolerance
- angular_tolerance
- Relative angular mesh tolerance (stl/stl2 backends) Lower this to get a better angular resolution.
- refine
- After the initial meshing step is done, should the mesh be refined? This option has more than one meaning depending on which backend you have chosen. - If the cq/stl-backend is active and the *refine* option is non-zero or True, the mesh-refinment tool (mmg)[https://www.mmgtools.org] is called in sequence on each surface. - If the gmsh-backend is active and the *refine* option is non-zero the gmsh-refinement tool is called on the full geometry the given number of times. A value of True is the same as setting the option to 1, i.e. it triggers a single loop through the refinement algorithm.
- verbose
- Output lots of information from the mesher backends.
As of version 0.3 We also distribute a utility script (in the scripts directory) that should be helpful in creating meshes. An example run could look like this, which furthermore sets the implicit complement to be air. (See below for more on implicit complement):
bash
c2omc_step2h5m examples/7pin.step --threads=1 --verbose=2 --implc=air --backend=stl2
For a description of all available command line options simply run
bash
c2omc_step2h5m --help
One noteable difference is that the default meshing backend is in this case 'stl2'
meshing backends
At present four different backends exist for CADtoOpenMC: 'gmsh', 'stl', 'stl2', and 'db'. It is possible to add another backend should another meshing library become available.
gmsh
The inner workings of this backend is basically a simple call to gmsh to create a 2D-mesh of the entire geometry. This has the advantage that inhenrently boundary curves are meshed only once, meaning that in theory, they can be made to account for shared surfaces without unwanted artefacts. At its present stage however there may be problems with leakage when performing transport calculation on geometries with shared surfaces. A significant drawback todoing the entire geometry all at once, is that for larger geometries memory requirements may be prohibitive.
stl
The stl backend takes a different approach. Instead each solid object in a step geometry is triangulated on its own. The triangulation itself is performed by calls to the underlying OpenCASCADE-library through the python layer cadquery. This procedure sidesteps the problem with large geometries, as each object in handled on its own. Objects cannot overlap however, and just as the case is for the gmsh-backend, surfaces should not be coincident.
stl2
As its name implies the stl2 backend builds on concepts from the stl backend. However a major difference lies in the fact that objects can now have coincident surfaces. This is achieved by splitting the tringulation operation further and instead perform it in a face-by-face manner. This way we may skip the operation is one face (or surface) is a part of two solids. Furthermore, when the surfaces are assembled into a h5m datafile, the surfaces may be appropriately flagged such that transport algorithms can handle moving from one to another. If this is important for your problem, then this is the backend you should use.
db
This meshing backend is based on the DellaBella meshing algorithm. On our test cases it tends to produce meshes that are qualitatively similar to what the 'stl2'-backend will generate. In cases however it can be more reliable, and may be able to generate watertight models with less polygons, leading to smaller files.
This backend is experimental in that installation can be tricky, since it requires a very new version of cadquery-ocp (7.7.2.1), not yet available through the pip-ecosystem. It may be installed using conda/mamba, but keep in mind that you actively have to avoid reinstalling cadquery-ocp thourhg pip. This can be accomplished by means of installing the dependencies manually (look to pyproject.toml) and lastly install cadtoopenmc using pip install --no-deps CAD_to_OpenMC
tag delimiter
As of 0.3.6 it is possible to manipulate the delimiter used when extracting material tags from part names. By default the regexp used is "\s@" meaning to split on whitespace, underscores and @. E.g. this will make parts "drbunsen" and "drbeaker" be tagged with "dr". If however the method "settagdelim" is called on an assembly object with an argument "\s@" this results in the parts being tagged "drbunsen" and "drbeaker". ```python import CADtoOpenMC.assembly as ab a=ab.Assembly() a.settag_delim("\s@") ```
implicit complement
CADtoOpenMC supports the notion of an implicit complement material, i.e. a material that fills all the space within the geometry which has not been claimed by any part in the CAD-assembly. For instance if one wanted to submerge a pincell in in water it is possible to only define the pincell as part and set the implicit complement material to water. To do so we would use code like:
python
import CAD_to_OpenMC.assembly as ab
a=ab.Assembly()
a.implicit_complement='water'
...
Of course, this means that the subsequent OpenMC transport simulation needs to define a material (with the wanted properties) named 'water'.
Intermediate datafiles
In the process of generating an .h5m-geometry file CADtoOpenMC also generates a sometimes large amount of intermediary datafiles, these may be retained for debugging purposes (the default), but by setting a flag, CADtoOpenMC can be directed to delete them automatically once they're no longer needed. Since version 0.3 the intermediate datafiles are put in a newly created subdirectory, named python
import CAD_to_OpenMC.assembly as ab
a=ab.Assembly()
a.cleanup=True
Merging a set of geometries
If you have non-overlapping geometries, it can be convenient to mesh them separately, e.g. to save memory, only to merge them at a later stage. In CADtoOpenMC this is supported (since 0.3.1) through a utility function merge2h5m. Imagine you have two step-files: one.step and two.step which you know to not overlap, but you would like them to belong to the same geometry/scene. In this case you may create a single h5m-file containing them both by means of the follwing procedure. ```python import CADtoOpenMC.assembly as ab One = ab.Assembly(['one.step]) One.run(backend='stl2', merge=True, h5m_filename='one.h5m')
Two = ab.Assembly(['two.step]) Two.run(backend='stl2', merge=True, h5m_filename='two.h5m')
ab.merge2h5m([One,Two],h5m_file='three.h5') ``` This will run the normal triangulization procedure for one and two separately, but also create a single h5m-file: three.h5m which contains both of the geometries.
Advanced example
For a more advanced example of the use of CADtoOpenMC and OpenMC we may turn to the Zero Power Reactor Experiment. This was a full-scale reactor experiment that was carried out at Oak Rodge TN in the 1960's. Copenhagen Atomics provides a CAD-drawn model of this experiment, extracted from the original reports and drawings from the original experiment, in the form of a step-file. To get access simply clone the zpre github repository and run the scripts:
bash
git clone https://www.github.com/openmsr/zpre
cd zpre
bash run.sh
The run.sh-script will the ask you what kind of calculation you'd like to perform. As a first run you might choose to ask OpenMC to simply plot the geometry of the reactor (option 2). If this is the first time you run the script, this triggers a surface-meshing operation to be performed (Be aware that by default this creates a large amount of console output - this is to be expected).
During the surface meshing operation (by default) a .vtk-file is created in addition to the .h5m-file that OpenMC (and DAGMC) needs. This is for convenience so you may inspect the created mesh using e.g. paraview, if you have access to that.
If you have paraview installed the call paraview h5m_files/zpre.vtk should yield a geometry like this
.
Once this process has finished, there should now be a file zpre.h5m inside the h5mfiles directory, and a set of plot[123].png files. which correspond to XY,XZ, and YZ-slices through the center of the reactor. If all goes well these should look something like this:
|XY|XZ|XZ|
|:--:|:--:|:--:|
|
|
|
|
The colors are chosen arbitrarily amd automatically by the OpenMC-plotting routine, which is why the same geomtrical entity gets a different color in the slices.
Owner
- Name: openmsr
- Login: openmsr
- Kind: organization
- Repositories: 8
- Profile: https://github.com/openmsr
open source software for modeling molten salt reactors
GitHub Events
Total
- Issues event: 60
- Watch event: 7
- Delete event: 2
- Issue comment event: 92
- Push event: 37
- Pull request review event: 2
- Pull request event: 23
- Fork event: 5
- Create event: 4
Last Year
- Issues event: 60
- Watch event: 7
- Delete event: 2
- Issue comment event: 92
- Push event: 37
- Pull request review event: 2
- Pull request event: 23
- Fork event: 5
- Create event: 4
Committers
Last synced: almost 3 years ago
All Time
- Total Commits: 406
- Total Committers: 7
- Avg Commits per committer: 58.0
- Development Distribution Score (DDS): 0.126
Top Committers
| Name | Commits | |
|---|---|---|
| Erik B Knudsen | e****n@c****m | 355 |
| erkn | e****k@v****g | 30 |
| LukeLabrie | l****y@g****m | 8 |
| Erik B Knudsen | e****n@f****k | 6 |
| Jonathan Shimwell | d****l@g****m | 4 |
| Daniel Kozma | k****d@g****m | 2 |
| Luke Labrie-Cleary | l****e@L****l | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 89
- Total pull requests: 72
- Average time to close issues: 6 months
- Average time to close pull requests: 1 day
- Total issue authors: 14
- Total pull request authors: 9
- Average comments per issue: 2.51
- Average comments per pull request: 0.13
- Merged pull requests: 61
- Bot issues: 0
- Bot pull requests: 4
Past Year
- Issues: 21
- Pull requests: 27
- Average time to close issues: about 1 month
- Average time to close pull requests: 1 day
- Issue authors: 6
- Pull request authors: 5
- Average comments per issue: 3.52
- Average comments per pull request: 0.07
- Merged pull requests: 20
- Bot issues: 0
- Bot pull requests: 1
Top Authors
Issue Authors
- ebknudsen (56)
- bonh (8)
- jacobmerson (6)
- nasserma (4)
- LukeLabrie (4)
- akoen (2)
- a-sunkari (1)
- kozmad (1)
- victordgehm (1)
- sjcrs (1)
- majarall (1)
- Sabyaro (1)
- jpmcg1 (1)
- eliasfrimanns (1)
Pull Request Authors
- ebknudsen (70)
- kyleniemeyer (4)
- dependabot[bot] (3)
- shimwell (2)
- jacobmerson (2)
- LukeLabrie (2)
- sjcrs (2)
- mbarzegary (2)
- kozmad (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 347 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 27
- Total maintainers: 1
pypi.org: cad-to-openmc
Package to automagically convert step-geometries to h5m descriptions for neutronics by OpenMC
- Homepage: https://github.com/openmsr/CAD_to_OpenMC
- Documentation: https://cad-to-openmc.readthedocs.io/
- License: MIT License
-
Latest release: 1.0.1
published 12 months ago
Rankings
Maintainers (1)
Dependencies
- actions/checkout v3 composite
- actions/setup-python v3 composite
- Cython ==0.29.32
- OCP *
- cadquery ==2.2.0b2
- cadquery-ocp ==7.6.3a0
- gmsh *
- meshio *
- networkx *
- numpy *
- pyparsing ==2.4
- trimesh *
- Cython ==0.29.32
- OCP *
- cadquery ==2.2.0b2
- cadquery-ocp ==7.6.3a0
- gmsh *
- meshio *
- networkx *
- numpy *
- pyparsing ==2.4
- pytest *
- trimesh *