Skip to content

Commit

Permalink
Merge dev into main (#67)
Browse files Browse the repository at this point in the history
* update Fuzzy write function

* several stp file update

* script to color CAD document following material label

* fix rounding error of z value acos(z) evaluation

* Add a bug report template and .gitignore (#44)

* Removed unused imports and variables (#35)

* raise value error instead of exit (#41)

* Update to testing path (#40)

* changed hardcoded path to work for all users

* path update

* Update bug_report.md

* raising catchable error instead of exit (#47)

* raising catchable error instead of exit

* added new line

* added try for freecad import (#48)

* Solve SyntaxtError producing a bug (#49)

* Solve SyntaxtError producing a bug

* Limit the amount of decimals printed in the enclosure comment

* fixed error units in OpenMC output

* GEOUNED training presentation added (#53)

* Adding minimal ci to check cad converts (#52)

* added minimal CI

* all step files

* added ci yml

* removed freecadcmd arg

* Update pyproject.toml

Update url links to "GEOUNED-org"

* typo correction to test if CI is working (#54)

* typo correction

* [skip ci] added ci status badge

* opening up ci to all os systems

* fix small bug with torus (bad identification of closed mozaic faces)

* Adding minimal volume checking CI comparing CAD and CSG volumes (#56)

* added volume test to ci

* removed if os cond

* added csg vs cad volume for **most** stp files

* Added mkdocs (#57)

* added example docs

* added docs deps

* Reverting mkdocs PR 57 (#58)

* Revert "added example docs"

This reverts commit bd1c67a.

* Revert "added docs deps"

This reverts commit f31d241.

* Adding minimal particle transport tests on resulting csg files (#59)

* added transport tests

* removed files that break, raised issue

* [skip ci] remove prints

* added link to issue

* Add the name to the cells in OpenMC to improve identification (#61)

The name is the same that is used in MCNP inputs cell.Comments

* converting with no simplification = more geometry works (#62)

* reduced number of skiped geoms (#63)

* [skip ci] corrected bade to main branch (#64)

* Improved import statements (#65)

* changed single file from package to relative imports

* 2nd file converted to relative imports

* converted more fiels to relative import

* relative imports everywhere

* isort on all imports

* Add bug report and .gitignore to main (#45) (#66)

Co-authored-by: AlvaroCubi <[email protected]>

* added standard gitignore for python project (#68)

---------

Co-authored-by: psauvan <[email protected]>
Co-authored-by: Tony <[email protected]>
Co-authored-by: Jonathan Shimwell <[email protected]>
Co-authored-by: Aljaz Kolsek (F4E) <[email protected]>
Co-authored-by: Emilio Castro <[email protected]>
  • Loading branch information
6 people authored Apr 23, 2024
1 parent c426387 commit 8bc7bd0
Show file tree
Hide file tree
Showing 51 changed files with 892 additions and 302 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: CI testing

on:
pull_request:
branches:
- dev
- main
push:
branches:
- main

jobs:
testing:
name: CI (Python=${{ matrix.python-version }}, OS=${{ matrix.os }})
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -el {0}
strategy:
matrix:
os: ["ubuntu-latest", "macos-latest", "windows-latest"]
python-version: ["3.11"]

include:
- python-version: "3.8"
os: "ubuntu-latest"
- python-version: "3.9"
os: "ubuntu-latest"
- python-version: "3.10"
os: "ubuntu-latest"
steps:
- name: checkout actions
uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}
channels: conda-forge

- name: install dependencies
run: conda install -c conda-forge freecad -y

- name: install package
run: |
python -m pip install --upgrade pip
python -m pip install .
python -c 'import GEOUNED'
python -c 'from GEOReverse import reverse'
python -m pip install .[tests]
- name: testing GEOUNED functionality
run: python -m pytest -v tests/test_convert.py

- name: install openmc
if: ${{ matrix.os == 'ubuntu-latest'}}
run: conda install -c conda-forge openmc -y

- name: testing with OpenMC
if: ${{ matrix.os == 'ubuntu-latest'}}
run: |
python -m pytest -v tests/test_volumes.py
python -m pytest -v tests/test_transport.py
172 changes: 168 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,174 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

# openmc output files
*.h5
*.xml

# testing folder
tests_outputs/

.vscode
**/__pycache__
.coverage
htmlcov/*
docs/source/_build/**
docs/build/**
docs/source/_autosummary/*
docs/jupyter_execute
.pytest_cache/**
build/
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![CI testing](https://github.com/GEOUNED-org/GEOUNED/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/GEOUNED-org/GEOUNED/actions/workflows/ci.yml)

# GEOUNED
A tool to convert from CAD to CSG & CSG to CAD for Monte Carlo transport codes (MCNP & OpenMC).
This repository contains the implementation of the algorithm presented in the paper [GEOUNED: A new conversion tool from CAD to Monte Carlo geometry](https://doi.org/10.1016/j.net.2024.01.052).
Expand Down Expand Up @@ -27,7 +29,7 @@ In that case you can install directly de module using:
C:\Program Files\FreeCAD 0.XX\bin\python.exe -m pip install git+https://github.com/GEOUNED-code/GEOUNED.git
```
using this option you have directly access to both FreeCAD and GEOUNED python modules.
Furthermore, using this python compabilities problems between different versions of python are avoided (some dynamic libraries of FreeCAD depends on the version of python used during the built process).
Furthermore, using this python compatibilities problems between different versions of python are avoided (some dynamic libraries of FreeCAD depends on the version of python used during the built process).

## How to use

Expand Down
Binary file added docs/Training_on_GEOUNED_tool.pdf
Binary file not shown.
13 changes: 9 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "GEOUNED"
version = "1.0.0"
version = "1.0.1"
authors = [
{ name="Juan-Pablo Catalan", email="[email protected]" },
{ name="Patrick Sauvan", email="[email protected]" },
Expand All @@ -22,6 +22,11 @@ classifiers = [
]

[project.urls]
Homepage = "https://github.com/GEOUNED-code"
Repository = "https://github.com/GEOUNED-code/GEOUNED"
Documentation = "https://github.com/GEOUNED-code/GEOUNED/docs"
Homepage = "https://github.com/GEOUNED-org"
Repository = "https://github.com/GEOUNED-org/GEOUNED"
Documentation = "https://github.com/GEOUNED-org/GEOUNED/docs"

[project.optional-dependencies]
tests = [
"pytest",
]
50 changes: 50 additions & 0 deletions scripts/colorCADmat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import re
import sys

sys.path.append('/usr/lib64/freecad/lib64/')
import ImportGui

bd = 255
gd = 255*255
rd = 255* 255* 255
matNumber=re.compile(r"Material_(?P<matnum>\d+)")

def getColor(num,vmin=0,vmax=rd):
colRange = rd
dnum = vmax - vmin
dx = num - vmin
scale = colRange/dnum
snum = dx * scale + 1

red = snum//gd
r = snum - red * gd
green = r // bd
blue = r - green * bd
return (red/255,green/255,blue/255)

def setColorMaterial(documents):
featureObj = []
matMin = 999999999
matMax = 0
for obj in documents.Objects:
if obj.TypeId == 'Part::Feature' :
for o in obj.InListRecursive:
m = matNumber.search(o.Label)
if m :
mat = int(m.group('matnum'))
matMin = min(matMin,mat)
matMax = max(matMax,mat)
featureObj.append((obj,mat))

for obj,mat in featureObj:
obj.ViewObject.ShapeColor = getColor(mat,matMin,matMax)


# color solids in a Freecad document with respect to the material number
doc = App.ActiveDocument
setColorMaterial(doc)
name = doc.Label
outname = name+'_color'
ImportGui.export(doc.RootObjects,outname+'.stp')
doc.saveAs(outname+'.FCStd')

6 changes: 2 additions & 4 deletions scripts/geouned
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ elif len(sys.argv) == 3:
runReverse = True
inifile = sys.argv[1]
else:
print('Bad option')
exit()
raise ValueError('Bad option')
else:
print('Too many input arguments')
exit()
raise ValueError('Too many input arguments')


if not runReverse :
Expand Down
8 changes: 3 additions & 5 deletions scripts/geouned.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@
runReverse = True
inifile = sys.argv[1]
else:
print('Bad option')
exit()
else:
print('Too many input arguments')
exit()
raise ValueError('Bad option')

else:
raise ValueError('Too many input arguments')

if not runReverse :
GEO = GEOUNED.GEOUNED(inifile)
Expand Down
16 changes: 8 additions & 8 deletions src/GEOReverse/Modules/MCNPinput.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import math
import os
import sys
import re

import FreeCAD
from GEOReverse.Modules.Parser import parser as mp
from GEOReverse.Modules.remh import cell_card_string, remove_hash
from GEOReverse.Modules.Objects import *
import math
import numpy as np
from numpy import linalg as LA

from .Objects import *
from .Parser import parser as mp
from .remh import cell_card_string, remove_hash


class MCNPinput:
def __init__(self,name):
if not os.path.isfile(name):
print("File %s does not exist" %name)
sys.exit()
return
raise FileNotFoundError (f"File {name} does not exist")
self.__inputcards__ = list(mp.get_cards(name))
self.Transformations = self.__getTransList__()
return
Expand Down
Loading

0 comments on commit 8bc7bd0

Please sign in to comment.