diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index f6d8377..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,35 +0,0 @@ -# Python CircleCI 2.0 configuration file -# -# Check https://circleci.com/docs/2.0/language-python/ for more details -# -version: 2 -jobs: - build: - docker: - - image: circleci/python:stretch - - # Specify service dependencies here if necessary - # CircleCI maintains a library of pre-built images - # documented at https://circleci.com/docs/2.0/circleci-images/ - # - image: circleci/postgres:9.4 - - working_directory: ~/repo - - steps: - - checkout - - - # run tests! - - run: - name: run tests - command: | - pip3 install numpy --user - python setup.py install --user - cd csg2csg - cd test - ./run_tests - - - store_artifacts: - path: test-reports - destination: test-reports - diff --git a/.github/workflows/auto_format_pep8.yml b/.github/workflows/auto_format_pep8.yml deleted file mode 100644 index 8299648..0000000 --- a/.github/workflows/auto_format_pep8.yml +++ /dev/null @@ -1,32 +0,0 @@ -name: auto_format_pep8 - -on: - push: - paths: - - '**.py' - -defaults: - run: - shell: bash - -jobs: - auto_format_pep8: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - with: - ref: ${{ github.head_ref }} - - name: Setup Python - uses: actions/setup-python@v2 - with: - python-version: 3.x - - name: Install black - run: | - python -m pip install --upgrade pip - pip install black - - name: Run black - run: | - black . - - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: "[skip ci] Apply pep8 formatting changes" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..18ee3e5 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,28 @@ +name: CI + +on: [push, pull_request] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: 3.7 + cache: 'pip' + + - name: Install packages + run: | + pip install .[dev] + + - name: Test with pytest + run: | + pytest --cov=csg2csg + + - name: Lint with Ruff + run: | + ruff --format=github --target-version=py37 . + continue-on-error: true diff --git a/.gitignore b/.gitignore index 3536433..52dab22 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,6 @@ share/python-wheels/ *.egg-info/ .installed.cfg *.egg -MANIFEST \ No newline at end of file +MANIFEST + +*~ diff --git a/README.md b/README.md index 6a3d6bd..77e3cfe 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ - -[![CircleCI](https://circleci.com/gh/makeclean/csg2csg.svg?style=svg)](https://circleci.com/gh/makeclean/csg2csg) +[![CI test results](https://github.com/makeclean/csg2csg/actions/workflows/ci.yaml/badge.svg)](https://github.com/makeclean/csg2csg/actions/workflows/ci.yaml) # csg2csg A tool to translate common Monte Carlo geometry formats between each other. diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..e69de29 diff --git a/csg2csg/.gitignore b/csg2csg/.gitignore deleted file mode 100644 index e4e5f6c..0000000 --- a/csg2csg/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*~ \ No newline at end of file diff --git a/csg2csg/Input.py b/csg2csg/Input.py index 9a236c6..5f09c38 100644 --- a/csg2csg/Input.py +++ b/csg2csg/Input.py @@ -46,7 +46,7 @@ def find_cell(self, cell_id): # read the whole file into a big list for further # procesing def read(self): - with open(self.filename, "rU", errors="replace") as f: + with open(self.filename, errors="replace") as f: self.file_lines = f.readlines() # sometimes truely monstrous people stuff weird diff --git a/csg2csg/MaterialCard.py b/csg2csg/MaterialCard.py index 54bc8fb..56b0f0e 100644 --- a/csg2csg/MaterialCard.py +++ b/csg2csg/MaterialCard.py @@ -93,17 +93,16 @@ class MaterialCard(Card): approach is taken here for maximal compability amongst codes. """ - material_name = "" - material_number = 0 - composition_dictionary = {} - xsid_dictionary = {} - density = 0 - mat_data = 0 - material_colour = 0 - # constructor def __init__(self, material_number=0, card_string=""): Card.__init__(self, card_string) + self.material_name = "" + self.material_number = 0 + self.composition_dictionary = {} + self.xsid_dictionary = {} + self.density = 0 + self.mat_data = 0 + self.material_colour = 0 self.material_number = material_number self.mat_data = MaterialData() diff --git a/csg2csg/test/UnitTestMCNPCell.py b/csg2csg/test/UnitTestMCNPCell.py deleted file mode 100644 index a570f5b..0000000 --- a/csg2csg/test/UnitTestMCNPCell.py +++ /dev/null @@ -1,86 +0,0 @@ -#!/usr/env/python3 - -import unittest -import sys - -sys.path.append("..") -from csg2csg.MCNPCellCard import MCNPCellCard, mcnp_line_formatter -from csg2csg.CellCard import CellCard - - -class TestMCNPCellMethods(unittest.TestCase): - - # TODO definitely add some more robust testing of the position of the - # logical operations - Very Important - - def test_simple_cell(self): - card_string = "1 1 -1.0 -4 5 -6 7" - card = MCNPCellCard(card_string) - self.assertEqual(card.text_string, card_string) - self.assertEqual(card.cell_id, 1) - self.assertEqual(card.cell_density, -1.0) - - def test_more_complex_cell(self): - card_string = "2 3 -14.0 (-4 5 -6 7):(9 12 13)" - card = MCNPCellCard(card_string) - self.assertEqual(card.text_string, card_string) - self.assertEqual(card.cell_id, 2) - self.assertEqual(card.cell_material_number, 3) - self.assertEqual(card.cell_density, -14.0) - - def test_mcnp_detect_keywords_all(self): - string = "2 3 -14.0 1 imp:n=1 imp:p=1 u=3 fill=12 vol=150" - cell_card = MCNPCellCard(string) - new_string = cell_card._MCNPCellCard__detect_keywords( - ["imp", "u", "fill", "vol"], string - ) - self.assertEqual(new_string, "2 3 -14.0 1 ") - - def test_mcnp_detect_keywords_imp(self): - string = "2 3 -14.0 1 imp:n=1 imp:p=1 " - cell_card = MCNPCellCard(string) - new_string = cell_card._MCNPCellCard__detect_keywords(["imp"], string) - self.assertEqual(new_string, "2 3 -14.0 1 ") - - def test_mcnp_detect_keywords_uni(self): - string = "2 3 -14.0 1 u=1 " - cell_card = MCNPCellCard(string) - new_string = cell_card._MCNPCellCard__detect_keywords(["u"], string) - self.assertEqual(new_string, "2 3 -14.0 1 ") - - def test_mcnp_detect_keywords_fill(self): - string = "2 3 -14.0 1 fill=3" - cell_card = MCNPCellCard(string) - new_string = cell_card._MCNPCellCard__detect_keywords(["fill"], string) - self.assertEqual(new_string, "2 3 -14.0 1 ") - - def test_mcnp_detect_keywords_vol(self): - string = "2 3 -14.0 1 vol=300" - cell_card = MCNPCellCard(string) - new_string = cell_card._MCNPCellCard__detect_keywords(["vol"], string) - self.assertEqual(new_string, "2 3 -14.0 1 ") - - def test_mcnp_detect_keywords_tmp(self): - string = "2 3 -14.0 1 tmp=300" - cell_card = MCNPCellCard(string) - new_string = cell_card._MCNPCellCard__detect_keywords(["tmp"], string) - self.assertEqual(new_string, "2 3 -14.0 1 ") - - def test_mcnp_line_format(self): - string = "1 0 (-1 3 4 5 6 8 9 ( 12 13 15))" - mcnp_string = mcnp_line_formatter(string) - self.assertEqual(string, mcnp_string) - # note these horrendously long lines - is actually what im trying to test and furthermore - # all of the standard techniques to break the string across multuple lines like - # https://stackoverflow.com/questions/5437619/python-style-line-continuation-with-strings - # dont actually work - string = "1 0 (-1 3 4 5 6 8 9 ( 12 13 15) ( 12 13 15) ( 12 13 15) ( 12 13 15) ( 12 13 15))" - mcnp_string = mcnp_line_formatter(string) - self.assertEqual( - "1 0 (-1 3 4 5 6 8 9 ( 12 13 15) ( 12 13 15) ( 12 13 15) ( 12 13 15) (\n 12 13 15))", - mcnp_string, - ) - - -if __name__ == "__main__": - unittest.main() diff --git a/csg2csg/test/UnitTestMCNPFormatter.py b/csg2csg/test/UnitTestMCNPFormatter.py deleted file mode 100644 index 2d2806b..0000000 --- a/csg2csg/test/UnitTestMCNPFormatter.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/env/python3 - -import unittest -import sys - -sys.path.append("..") - -from csg2csg.MCNPFormatter import get_fortran_formatted_number - - -class TestFortranReadMethods(unittest.TestCase): - def test_fortran_format(self): - string = "-1.0-1" - number = get_fortran_formatted_number(string) - self.assertEqual(number, -1.0e-1) - - string = "-1.0+1" - number = get_fortran_formatted_number(string) - self.assertEqual(number, -1.0e1) - - string = "1.0+1" - number = get_fortran_formatted_number(string) - self.assertEqual(number, 1.0e1) - - string = "15.0-100" - number = get_fortran_formatted_number(string) - self.assertEqual(number, 1.5e-99) - - string = "-15.0+39" - number = get_fortran_formatted_number(string) - self.assertEqual(number, -1.5e40) - - string = "-15.0+309" - number = get_fortran_formatted_number(string) - self.assertEqual(number, -1.5e310) - - string = "6.1000" - number = get_fortran_formatted_number(string) - self.assertEqual(number, 6.1000) - - string = "-6.1000" - number = get_fortran_formatted_number(string) - self.assertEqual(number, -6.1000) - - -if __name__ == "__main__": - unittest.main() diff --git a/csg2csg/test/UnitTestMCNPInput.py b/csg2csg/test/UnitTestMCNPInput.py deleted file mode 100644 index fc78753..0000000 --- a/csg2csg/test/UnitTestMCNPInput.py +++ /dev/null @@ -1,534 +0,0 @@ -#!/usr/env/python3 - -import unittest -import sys -import logging - -sys.path.append("..") -from csg2csg.MCNPInput import MCNPInput # , explode_macrobody -from csg2csg.MCNPSurfaceCard import MCNPSurfaceCard -from csg2csg.SurfaceCard import SurfaceCard - - -class TestBlockBreaks(unittest.TestCase): - def test_spaces_block_breaks(self): - input_string = ["this is a title\n"] - input_string.append("1 1 -1.0 -3\n") - input_string.append("2 0 3\n") - input_string.append(" \n") - input_string.append("3 rpp -1 1 -1 1 -1 1\n") - input_string.append(" \n") - input_string.append("m1 1001 1.0\n") - input_string.append(" 1002 1.0\n") - - # setup input - input = MCNPInput() - input.cell_list = [] - input.file_lines = input_string - input.total_num_lines = len(input_string) - input.process() - - # check number of cells found - self.assertEqual(len(input.cell_list), 2) - - def test_white_spaces_block_breaks(self): - input_string = ["this is a title\n"] - input_string.append("1 1 -1.0 -3\n") - input_string.append("2 0 3\n") - input_string.append(" \t \n") - input_string.append("3 rpp -1 1 -1 1 -1 1\n") - input_string.append(" \t \n") - input_string.append("m1 1001 1.0\n") - input_string.append(" 1002 1.0\n") - - # setup input - input = MCNPInput() - input.cell_list = [] - input.file_lines = input_string - input.total_num_lines = len(input_string) - input.process() - - # check number of cells found - self.assertEqual(len(input.cell_list), 2) - - def test_comment_lines(self): - input_string = ["this is a title\n"] - input_string.append( - "4980 130 0.06026342 8085 -8086 8654 -4684 27 100 -200 imp:n=1\n" - ) - input_string.append( - "4985 130 0.06000038 8011 -8086 4684 -4682 27 100 -200 imp:n=1\n" - ) - input_string.append( - "4995 130 0.099591 8011 -8086 4682 -53 27 100 -200 imp:n=1\n" - ) - input_string.append("c\n") - input_string.append( - "c Comment line sandwiched by two blank comment lines\n" - ) - input_string.append("c\n") - input_string.append( - "5001 130 0.099591 7511 -7586 -67 7602 -53 100 -200 imp:n=1\n" - ) - input_string.append( - "5002 130 0.06000038 7511 -7586 -7602 7604 -53 100 -200 imp:n=1 \n" - ) - input_string.append(" \t \n") - input_string.append("8085 so 10.\n") - input_string.append("8086 so 11.\n") - input_string.append("8654 so 12.\n") - input_string.append("4684 so 13.\n") - input_string.append("27 so 14.\n") - input_string.append("100 so 15.\n") - input_string.append("200 so 16.\n") - input_string.append(" \t \n") - input_string.append("m130 1001 1.0\n") - input_string.append(" 1002 1.0\n") - - # setup input - input = MCNPInput() - input.cell_list = [] - input.surface_list = [] - input.file_lines = input_string - input.total_num_lines = len(input_string) - input.process() - - # check number of cells found is 5 and does not include the c - self.assertEqual(len(input.cell_list), 5) - - # checks the number of surfaces found is 7 - self.assertEqual(len(input.surface_list), 7) - - -class TestMCNPInputMethods(unittest.TestCase): - def test_explode_macrobody(self): - input = MCNPInput() - card_string = "1 rpp -1 1 -1 1 -1 1" - Surface = MCNPSurfaceCard(card_string) - # explode macrobody into surfaces - cells, new_surfaces = input.explode_macrobody(Surface) - self.assertEqual(cells[0], "( -1 -2 -3 -4 -5 -6 )") - self.assertEqual(cells[1], "( 1 : 2 : 3 : 4 : 5 : 6)") - self.assertEqual(len(new_surfaces), 6) - self.assertEqual( - new_surfaces[0].surface_type, SurfaceCard.SurfaceType["PLANE_X"] - ) - self.assertEqual(new_surfaces[0].surface_coefficients[3], 1) - self.assertEqual( - new_surfaces[1].surface_type, SurfaceCard.SurfaceType["PLANE_GENERAL"] - ) - self.assertEqual(new_surfaces[1].surface_coefficients[0], -1) - self.assertEqual( - new_surfaces[2].surface_type, SurfaceCard.SurfaceType["PLANE_Y"] - ) - self.assertEqual(new_surfaces[2].surface_coefficients[3], 1) - self.assertEqual( - new_surfaces[3].surface_type, SurfaceCard.SurfaceType["PLANE_GENERAL"] - ) - self.assertEqual(new_surfaces[3].surface_coefficients[1], -1) - self.assertEqual( - new_surfaces[4].surface_type, SurfaceCard.SurfaceType["PLANE_Z"] - ) - self.assertEqual(new_surfaces[4].surface_coefficients[3], 1) - self.assertEqual( - new_surfaces[5].surface_type, SurfaceCard.SurfaceType["PLANE_GENERAL"] - ) - self.assertEqual(new_surfaces[5].surface_coefficients[2], -1) - - def test_flatten_macrobodies(self): - input_string = ["this is a title\n"] - input_string.append("1 1 -1.0 -3\n") - input_string.append("2 0 3\n") - input_string.append("\n") - input_string.append("3 rpp -1 1 -1 1 -1 1\n") - input_string.append("\n") - input_string.append("m1 1001 1.0\n") - input_string.append(" 1002 1.0\n") - - # setup input - input = MCNPInput() - input.file_lines = input_string - input.total_num_lines = len(input_string) - input.process() - - # cell card - cell1 = input.cell_list[0] - cell2 = input.cell_list[1] - - self.assertEqual(cell1.text_string, "1 1 -1.0 ( -4 -5 -6 -7 -8 -9 )") - self.assertEqual(cell2.text_string, "2 0 ( 4 : 5 : 6 : 7 : 8 : 9)") - - # test case for the box macrobody - def test_flatten_macrobodies(self): - input_string = ["this is a title\n"] - input_string.append("1 1 -1.0 -3\n") - input_string.append("2 0 3\n") - input_string.append("\n") - input_string.append("3 box -1 -1 -1 2 0 0 0 2 0 0 0 2\n") - input_string.append("\n") - input_string.append("m1 1001 1.0\n") - input_string.append(" 1002 1.0\n") - - # setup input - input = MCNPInput() - input.file_lines = input_string - input.total_num_lines = len(input_string) - input.process() - - # cell card - cell1 = input.cell_list[0] - cell2 = input.cell_list[1] - - self.assertEqual(cell1.text_string, "1 1 -1.0 ( -4 -5 -6 -7 -8 -9 )") - self.assertEqual(cell2.text_string, "2 0 ( 4 : 5 : 6 : 7 : 8 : 9)") - - # surface card - surface1 = input.surface_list[0] - surface2 = input.surface_list[1] - self.assertEqual(surface1.surface_type, SurfaceCard.SurfaceType["PLANE_X"]) - self.assertEqual(surface1.surface_coefficients, [1, 0, 0, 1]) - self.assertEqual( - surface2.surface_type, SurfaceCard.SurfaceType["PLANE_GENERAL"] - ) - self.assertEqual(surface2.surface_coefficients, [-1, 0, 0, 1]) - - def test_flatten_macrobodies_with_other_surfs(self): - input_string = ["this is a title\n"] - input_string.append("1 1 -1.0 -7 3\n") - input_string.append("2 0 -3\n") - input_string.append("3 0 7\n") - input_string.append("\n") - input_string.append("3 rpp -1 1 -1 1 -1 1\n") - input_string.append("7 so 10.\n") - input_string.append("\n") - input_string.append("m1 1001 1.0\n") - input_string.append(" 1002 1.0\n") - - # setup input - input = MCNPInput() - - input.cell_list = [] - input.surface_list = [] - input.material_list = {} - input.transform_list = {} - - self.assertEqual(len(input.cell_list), 0) - input.file_lines = input_string - input.total_num_lines = len(input_string) - input.process() - - # cell card - cell1 = input.cell_list[0] - cell2 = input.cell_list[1] - cell3 = input.cell_list[2] - self.assertEqual(len(input.cell_list), 3) - - # surface numbering should start at 7 - self.assertEqual(cell3.text_string, "3 0 7") - self.assertEqual(cell2.text_string, "2 0 ( -8 -9 -10 -11 -12 -13 )") - self.assertEqual(cell1.text_string, "1 1 -1.0 -7 ( 8 : 9 : 10 : 11 : 12 : 13)") - - # surfaces should be numbered from 7 to 13 contiguously - for i in range(0, len(input.surface_list)): - self.assertEqual(input.surface_list[i].surface_id, 7 + i) - - # surface 7 should be a sphere - # self.assertEqual(input.surface_list[0].surface_type, SurfaceCard.SurfaceType["SPHERE_GENERAL"]) - # 8-9 px 10-11 py 12-13 pz - self.assertEqual( - input.surface_list[1].surface_type, SurfaceCard.SurfaceType["PLANE_X"] - ) - self.assertEqual( - input.surface_list[2].surface_type, SurfaceCard.SurfaceType["PLANE_GENERAL"] - ) - self.assertEqual( - input.surface_list[3].surface_type, SurfaceCard.SurfaceType["PLANE_Y"] - ) - self.assertEqual( - input.surface_list[4].surface_type, SurfaceCard.SurfaceType["PLANE_GENERAL"] - ) - self.assertEqual( - input.surface_list[5].surface_type, SurfaceCard.SurfaceType["PLANE_Z"] - ) - self.assertEqual( - input.surface_list[6].surface_type, SurfaceCard.SurfaceType["PLANE_GENERAL"] - ) - - def test_flatten_macrobodies_with_multiple_macrobodies(self): - input_string = ["this is a title\n"] - input_string.append("1 1 -1.0 -3\n") - input_string.append("2 0 3 -4\n") - input_string.append("3 0 4 -5\n") - input_string.append("4 0 5\n") - input_string.append("\n") - input_string.append("3 rpp -5 5 -5 5 -5 5\n") - input_string.append("4 rpp -10 10 -10 10 -10 10\n") - input_string.append("5 rpp -15 15 -15 15 -15 15\n") - input_string.append("\n") - input_string.append("m1 1001 1.0\n") - input_string.append(" 1002 1.0\n") - input_string.append("\n") - - # setup input - input = MCNPInput() - input.cell_list = [] - input.surface_list = [] - input.material_list = {} - input.transform_list = {} - - self.assertEqual(len(input.cell_list), 0) - input.file_lines = input_string - input.total_num_lines = len(input_string) - input.process() - - # cell card - cell1 = input.cell_list[0] - cell2 = input.cell_list[1] - cell3 = input.cell_list[2] - cell4 = input.cell_list[3] - self.assertEqual(len(input.cell_list), 4) - - # are surfaces correctly processed - self.assertEqual( - input.surface_list[0].surface_type, SurfaceCard.SurfaceType["PLANE_X"] - ) - self.assertEqual( - input.surface_list[1].surface_type, SurfaceCard.SurfaceType["PLANE_GENERAL"] - ) - self.assertEqual( - input.surface_list[2].surface_type, SurfaceCard.SurfaceType["PLANE_Y"] - ) - self.assertEqual( - input.surface_list[3].surface_type, SurfaceCard.SurfaceType["PLANE_GENERAL"] - ) - self.assertEqual( - input.surface_list[4].surface_type, SurfaceCard.SurfaceType["PLANE_Z"] - ) - self.assertEqual( - input.surface_list[5].surface_type, SurfaceCard.SurfaceType["PLANE_GENERAL"] - ) - - self.assertEqual( - input.surface_list[6].surface_type, SurfaceCard.SurfaceType["PLANE_X"] - ) - self.assertEqual( - input.surface_list[7].surface_type, SurfaceCard.SurfaceType["PLANE_GENERAL"] - ) - self.assertEqual( - input.surface_list[8].surface_type, SurfaceCard.SurfaceType["PLANE_Y"] - ) - self.assertEqual( - input.surface_list[9].surface_type, SurfaceCard.SurfaceType["PLANE_GENERAL"] - ) - self.assertEqual( - input.surface_list[10].surface_type, SurfaceCard.SurfaceType["PLANE_Z"] - ) - self.assertEqual( - input.surface_list[11].surface_type, - SurfaceCard.SurfaceType["PLANE_GENERAL"], - ) - - self.assertEqual( - input.surface_list[12].surface_type, SurfaceCard.SurfaceType["PLANE_X"] - ) - self.assertEqual( - input.surface_list[13].surface_type, - SurfaceCard.SurfaceType["PLANE_GENERAL"], - ) - self.assertEqual( - input.surface_list[14].surface_type, SurfaceCard.SurfaceType["PLANE_Y"] - ) - self.assertEqual( - input.surface_list[15].surface_type, - SurfaceCard.SurfaceType["PLANE_GENERAL"], - ) - self.assertEqual( - input.surface_list[16].surface_type, SurfaceCard.SurfaceType["PLANE_Z"] - ) - self.assertEqual( - input.surface_list[17].surface_type, - SurfaceCard.SurfaceType["PLANE_GENERAL"], - ) - - # surface numbering should start at 6 - self.assertEqual(cell1.text_string, "1 1 -1.0 ( -6 -7 -8 -9 -10 -11 )") - self.assertEqual( - cell2.text_string, - "2 0 ( 6 : 7 : 8 : 9 : 10 : 11 ) ( -12 -13 -14 -15 -16 -17 )", - ) - self.assertEqual( - cell3.text_string, - "3 0 ( 12 : 13 : 14 : 15 : 16 : 17 ) ( -18 -19 -20 -21 -22 -23 )", - ) - - return - - # surfaces should be numbered from 7 to 13 contiguously - for i in range(0, len(input.surface_list)): - self.assertEqual(input.surface_list[i].surface_id, 7 + i) - - # surface 7 should be a sphere - # 8-9 px 10-11 py 12-13 pz - - def test_cone_expansion(self): - input_string = ["this is a title\n"] - input_string.append("1 1 -1.0 -1\n") - input_string.append("2 0 1\n") - input_string.append("\n") - input_string.append("1 k/z 0 0 5 0.5 -1\n") - input_string.append("\n") - input_string.append("m1 1001 1.0\n") - input_string.append(" 1002 1.0\n") - input_string.append("\n") - - # setup input - input = MCNPInput() - input.cell_list = [] - input.surface_list = [] - input.material_list = {} - input.transform_list = {} - - input.file_lines = input_string - input.total_num_lines = len(input_string) - input.process() - - # are surfaces correctly processed - self.assertEqual( - input.surface_list[0].surface_type, SurfaceCard.SurfaceType["CONE_Z"] - ) - - # surface numbering should start at 6 - cell1 = input.cell_list[0] - cell2 = input.cell_list[1] - self.assertEqual(cell1.text_string, "1 1 -1.0 ( -1 -2 )") - self.assertEqual(cell2.text_string, "2 0 ( 1 -2 : 2)") - - return - - -class TestMCNPInputRegressions(unittest.TestCase): - def test_parenthesis_bug(self): - input_string = ["this is a title\n"] - input_string.append("1 0 (3) \n") - input_string.append("2 0 (#1)\n") - input_string.append(" \n") - input_string.append("3 cz 300\n") - input_string.append(" \n") - input_string.append("m1 1001 1.0\n") - input_string.append(" 1002 1.0\n") - - # setup input - input = MCNPInput() - input.cell_list = [] - input.file_lines = input_string - input.total_num_lines = len(input_string) - input.process() - - # check number of cells found - self.assertEqual(len(input.cell_list), 2) - self.assertEqual(input.cell_list[0].text_string, "1 0 (3) \n") - self.assertEqual(input.cell_list[1].text_string, "2 0 (#1)\n") - - del input - - def test_parenthesis_plane_bug(self): - input_string = ["this is a title\n"] - input_string.append("1 1 -1.0 -1\n") - input_string.append("2 0 1\n") - input_string.append(" \n") - input_string.append("1 1 px 2.0\n") - input_string.append(" \n") - input_string.append("*tr1 0 0.15 0 45 90 45 90 0 90 135 90 45\n") - input_string.append("m1 1001 1.0\n") - input_string.append(" 1002 1.0\n") - - # setup input - input = MCNPInput() - input.cell_list = [] - input.file_lines = input_string - input.total_num_lines = len(input_string) - input.process() - - # check number of cells found - self.assertEqual(len(input.cell_list), 2) - self.assertEqual(len(input.surface_list), 1) - self.assertEqual(len(input.surface_list[0].surface_coefficients), 4) - self.assertEqual( - input.surface_list[0].surface_coefficients[0], 0.7071067811865476 - ) - self.assertEqual( - input.surface_list[0].surface_coefficients[1], 6.123233995736766e-17 - ) - self.assertEqual( - input.surface_list[0].surface_coefficients[2], 0.7071067811865476 - ) - self.assertEqual(input.surface_list[0].surface_coefficients[3], 2.0) - - del input - - def test_duplicate_surface_without_rot(self): - input_string = ["this is a title\n"] - input_string.append("1 1 -1.0 -1\n") - input_string.append("2 1 -1.0 2\n") - input_string.append(" \n") - input_string.append("1 px 2.0\n") - input_string.append("2 px 2.0\n") - input_string.append(" \n") - input_string.append("m1 1001 1.0\n") - input_string.append(" 1002 1.0\n") - - # setup input - input = MCNPInput() - input.cell_list = [] - input.file_lines = input_string - input.total_num_lines = len(input_string) - input.quick_process = False - input.process() - - self.assertEqual(len(input.surface_list), 1) - - def test_duplicate_surface_with_rot(self): - input_string = ["this is a title\n"] - input_string.append("1 1 -1.0 -1\n") - input_string.append("2 1 -1.0 2\n") - input_string.append(" \n") - input_string.append("1 1 px 2.0\n") - input_string.append("2 1 px 2.0\n") - input_string.append(" \n") - input_string.append("*tr1 0 0.15 0 45 90 45 90 0 90 135 90 45\n") - input_string.append("m1 1001 1.0\n") - input_string.append(" 1002 1.0\n") - - # setup input - input = MCNPInput() - input.cell_list = [] - input.file_lines = input_string - input.total_num_lines = len(input_string) - input.process() - - self.assertEqual(len(input.surface_list), 1) - - def test_duplicate_surface_with_macro(self): - input_string = ["this is a title\n"] - input_string.append("1 0 -1\n") - input_string.append("2 0 -2\n") - input_string.append(" \n") - input_string.append("1 px 2.0\n") - input_string.append("2 rpp -2 2 -2 2 -2 2\n") - input_string.append(" \n") - input_string.append("*tr1 0 0.15 0 45 90 45 90 0 90 135 90 45\n") - input_string.append("m1 1001 1.0\n") - input_string.append(" 1002 1.0\n") - - # setup input - input = MCNPInput() - input.cell_list = [] - input.file_lines = input_string - input.total_num_lines = len(input_string) - input.process() - - self.assertEqual(len(input.surface_list), 6) - - -if __name__ == "__main__": - unittest.main() diff --git a/csg2csg/test/UnitTestMCNPMaterial.py b/csg2csg/test/UnitTestMCNPMaterial.py deleted file mode 100644 index 525b37a..0000000 --- a/csg2csg/test/UnitTestMCNPMaterial.py +++ /dev/null @@ -1,117 +0,0 @@ -#!/usr/env/python3 - -import unittest -import sys - -sys.path.append("..") - -from csg2csg.MCNPMaterialCard import MCNPMaterialCard -from csg2csg.MCNPInput import MCNPInput - - -class TestMCNPMaterial(unittest.TestCase): - def test_mcnp_material(self): - string = "29063 6.917000e-01 \n" + "29065.31c 3.083000e-01 \n" - number = 1 - name = "M1" - matcard = MCNPMaterialCard(number, string) - - self.assertEqual(matcard.material_number, number) - self.assertEqual(matcard.material_name, name) - self.assertEqual(len(matcard.composition_dictionary), 2) - - self.assertEqual(list(matcard.composition_dictionary.keys())[0], "29063") - self.assertEqual(list(matcard.composition_dictionary.keys())[1], "29065") - - self.assertEqual(list(matcard.composition_dictionary.values())[0], 6.917000e-01) - self.assertEqual(list(matcard.composition_dictionary.values())[1], 3.083000e-01) - - self.assertEqual(len(matcard.xsid_dictionary), 2) - - self.assertEqual(list(matcard.xsid_dictionary.keys())[0], "29063") - self.assertEqual(list(matcard.xsid_dictionary.keys())[1], "29065") - - self.assertEqual(list(matcard.xsid_dictionary.values())[0], "") - self.assertEqual(list(matcard.xsid_dictionary.values())[1], "31c") - - def test_mcnp_material_with_duplicates(self): - string = "29063 2.e-01 \n" + "29063 1.e-01 \n" + "29065.31c 3.083000e-01 \n" - number = 1 - name = "M1" - matcard = MCNPMaterialCard(number, string) - - self.assertEqual(matcard.material_number, number) - self.assertEqual(matcard.material_name, name) - self.assertEqual(len(matcard.composition_dictionary), 2) - - self.assertEqual(list(matcard.composition_dictionary.keys())[0], "29063") - self.assertEqual(list(matcard.composition_dictionary.keys())[1], "29065") - - self.assertAlmostEqual( - list(matcard.composition_dictionary.values())[0], 3.0e-01 - ) - self.assertEqual(list(matcard.composition_dictionary.values())[1], 3.083000e-01) - - self.assertEqual(len(matcard.xsid_dictionary), 2) - - self.assertEqual(list(matcard.xsid_dictionary.keys())[0], "29063") - self.assertEqual(list(matcard.xsid_dictionary.keys())[1], "29065") - - self.assertEqual(list(matcard.xsid_dictionary.values())[0], "") - self.assertEqual(list(matcard.xsid_dictionary.values())[1], "31c") - - def test_mcnp_material_with_keywords(self): - string = ( - "29063 6.917000e-01 \n" - + "29065.31c 3.083000e-01 \n" - + "hlib=.70h pnlib=70u" - ) - number = 1 - name = "M1" - matcard = MCNPMaterialCard(number, string) - - self.assertEqual(matcard.material_number, number) - self.assertEqual(matcard.material_name, name) - self.assertEqual(len(matcard.composition_dictionary), 2) - - self.assertEqual(list(matcard.composition_dictionary.keys())[0], "29063") - self.assertEqual(list(matcard.composition_dictionary.keys())[1], "29065") - - self.assertEqual(list(matcard.composition_dictionary.values())[0], 6.917000e-01) - self.assertEqual(list(matcard.composition_dictionary.values())[1], 3.083000e-01) - - self.assertEqual(len(matcard.xsid_dictionary), 2) - - self.assertEqual(list(matcard.xsid_dictionary.keys())[0], "29063") - self.assertEqual(list(matcard.xsid_dictionary.keys())[1], "29065") - - self.assertEqual(list(matcard.xsid_dictionary.values())[0], "") - self.assertEqual(list(matcard.xsid_dictionary.values())[1], "31c") - - def test_mcnp_material_with_keyword(self): - string = "29063 6.917000e-01 \n" + "29065.31c 3.083000e-01 \n" + "hlib=.70h" - number = 1 - name = "M1" - matcard = MCNPMaterialCard(number, string) - - self.assertEqual(matcard.material_number, number) - self.assertEqual(matcard.material_name, name) - self.assertEqual(len(matcard.composition_dictionary), 2) - - self.assertEqual(list(matcard.composition_dictionary.keys())[0], "29063") - self.assertEqual(list(matcard.composition_dictionary.keys())[1], "29065") - - self.assertEqual(list(matcard.composition_dictionary.values())[0], 6.917000e-01) - self.assertEqual(list(matcard.composition_dictionary.values())[1], 3.083000e-01) - - self.assertEqual(len(matcard.xsid_dictionary), 2) - - self.assertEqual(list(matcard.xsid_dictionary.keys())[0], "29063") - self.assertEqual(list(matcard.xsid_dictionary.keys())[1], "29065") - - self.assertEqual(list(matcard.xsid_dictionary.values())[0], "") - self.assertEqual(list(matcard.xsid_dictionary.values())[1], "31c") - - -if __name__ == "__main__": - unittest.main() diff --git a/csg2csg/test/UnitTestMCNPParticle.py b/csg2csg/test/UnitTestMCNPParticle.py deleted file mode 100644 index fbb292e..0000000 --- a/csg2csg/test/UnitTestMCNPParticle.py +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/env/python3 - -import unittest -import sys - -sys.path.append("..") - -from csg2csg.ParticleNames import ParticleNames -from csg2csg.MCNPParticleNames import particleToMCNP, mcnpToParticle - - -class TestMCNPParticleMethods(unittest.TestCase): - def test_generic(self): - - for i in range(len(list(ParticleNames))): - self.assertEqual(particleToMCNP(i), mcnpToParticle(particleToMCNP(i))) - - -if __name__ == "__main__": - unittest.main() diff --git a/csg2csg/test/UnitTestMCNPSurface.py b/csg2csg/test/UnitTestMCNPSurface.py deleted file mode 100644 index e4201dc..0000000 --- a/csg2csg/test/UnitTestMCNPSurface.py +++ /dev/null @@ -1,176 +0,0 @@ -#!/usr/env/python3 - -import unittest -import sys - -sys.path.append("..") -from csg2csg.MCNPSurfaceCard import MCNPSurfaceCard, surface_has_transform -from csg2csg.SurfaceCard import SurfaceCard - - -class TestMCNPSurfaceMethods(unittest.TestCase): - def test_plane_x(self): - card_string = "1 px 12.0" - card = MCNPSurfaceCard(card_string) - self.assertEqual(card.text_string, card_string) - self.assertEqual(card.surface_type, SurfaceCard.SurfaceType["PLANE_X"]) - self.assertEqual(card.surface_coefficients[0], 1.0) - self.assertEqual(card.surface_coefficients[1], 0.0) - self.assertEqual(card.surface_coefficients[2], 0.0) - self.assertEqual(card.surface_coefficients[3], 12.0) - - def test_plane_y(self): - card_string = "1 py 12.0" - card = MCNPSurfaceCard(card_string) - self.assertEqual(card.text_string, card_string) - self.assertEqual(card.surface_type, SurfaceCard.SurfaceType["PLANE_Y"]) - self.assertEqual(card.surface_coefficients[0], 0.0) - self.assertEqual(card.surface_coefficients[1], 1.0) - self.assertEqual(card.surface_coefficients[2], 0.0) - self.assertEqual(card.surface_coefficients[3], 12.0) - - def test_plane_z(self): - card_string = "1 pz 12.0" - card = MCNPSurfaceCard(card_string) - self.assertEqual(card.text_string, card_string) - self.assertEqual(card.surface_type, SurfaceCard.SurfaceType["PLANE_Z"]) - self.assertEqual(card.surface_coefficients[0], 0.0) - self.assertEqual(card.surface_coefficients[1], 0.0) - self.assertEqual(card.surface_coefficients[2], 1.0) - self.assertEqual(card.surface_coefficients[3], 12.0) - - def test_plane_general(self): - card_string = "1 p 0 0 1 15" - card = MCNPSurfaceCard(card_string) - self.assertEqual(card.text_string, card_string) - self.assertEqual(card.surface_type, SurfaceCard.SurfaceType["PLANE_GENERAL"]) - self.assertEqual(card.surface_coefficients[0], 0.0) - self.assertEqual(card.surface_coefficients[1], 0.0) - self.assertEqual(card.surface_coefficients[2], 1.0) - self.assertEqual(card.surface_coefficients[3], 15.0) - - def test_sphere(self): - card_string = "15 s 0 0 1 15" - card = MCNPSurfaceCard(card_string) - self.assertEqual(card.text_string, card_string) - self.assertEqual(card.surface_type, SurfaceCard.SurfaceType["SPHERE_GENERAL"]) - self.assertEqual(card.surface_coefficients[0], 0.0) - self.assertEqual(card.surface_coefficients[1], 0.0) - self.assertEqual(card.surface_coefficients[2], 1.0) - self.assertEqual(card.surface_coefficients[3], 15.0) - - def test_gq(self): - card_string = "15000 gq 1 1 0 0 0 0 1 1 1 1" - card = MCNPSurfaceCard(card_string) - self.assertEqual( - card.surface_type, SurfaceCard.SurfaceType["GENERAL_QUADRATIC"] - ) - self.assertEqual(card.surface_id, 15000) - self.assertEqual(card.surface_coefficients[0], 1.0) - self.assertEqual(card.surface_coefficients[1], 1.0) - self.assertEqual(card.surface_coefficients[2], 0.0) - self.assertEqual(card.surface_coefficients[3], 0.0) - self.assertEqual(card.surface_coefficients[4], 0.0) - self.assertEqual(card.surface_coefficients[5], 0.0) - self.assertEqual(card.surface_coefficients[6], 1.0) - self.assertEqual(card.surface_coefficients[7], 1.0) - self.assertEqual(card.surface_coefficients[8], 1.0) - self.assertEqual(card.surface_coefficients[9], 1.0) - - def test_so(self): - card_string = "15000 so 2.5" - card = MCNPSurfaceCard(card_string) - self.assertEqual(card.surface_type, SurfaceCard.SurfaceType["SPHERE_GENERAL"]) - self.assertEqual(card.surface_id, 15000) - self.assertEqual(card.surface_coefficients[0], 0.0) - self.assertEqual(card.surface_coefficients[1], 0.0) - self.assertEqual(card.surface_coefficients[2], 0.0) - self.assertEqual(card.surface_coefficients[3], 2.5) - - def test_sx(self): - card_string = "15000 sx 3.0 2.5" - card = MCNPSurfaceCard(card_string) - self.assertEqual(card.surface_type, SurfaceCard.SurfaceType["SPHERE_GENERAL"]) - self.assertEqual(card.surface_id, 15000) - self.assertEqual(card.surface_coefficients[0], 3.0) - self.assertEqual(card.surface_coefficients[1], 0.0) - self.assertEqual(card.surface_coefficients[2], 0.0) - self.assertEqual(card.surface_coefficients[3], 2.5) - - def test_sy(self): - card_string = "15000 sy 3.0 2.5" - card = MCNPSurfaceCard(card_string) - self.assertEqual(card.surface_type, SurfaceCard.SurfaceType["SPHERE_GENERAL"]) - self.assertEqual(card.surface_id, 15000) - self.assertEqual(card.surface_coefficients[0], 0.0) - self.assertEqual(card.surface_coefficients[1], 3.0) - self.assertEqual(card.surface_coefficients[2], 0.0) - self.assertEqual(card.surface_coefficients[3], 2.5) - - def test_cz(self): - card_string = "15000 cz 2.5" - card = MCNPSurfaceCard(card_string) - self.assertEqual(card.surface_type, SurfaceCard.SurfaceType["CYLINDER_Z"]) - self.assertEqual(card.surface_id, 15000) - self.assertEqual(card.surface_coefficients[0], 0.0) - self.assertEqual(card.surface_coefficients[1], 0.0) - self.assertEqual(card.surface_coefficients[2], 2.5) - - def test_rpp(self): - card_string = "15000 rpp -1 1 -1 1 -1 1" - card = MCNPSurfaceCard(card_string) - self.assertEqual(card.surface_type, SurfaceCard.SurfaceType["MACRO_RPP"]) - self.assertEqual(card.surface_id, 15000) - self.assertEqual(card.surface_coefficients[0], -1.0) - self.assertEqual(card.surface_coefficients[1], 1.0) - self.assertEqual(card.surface_coefficients[2], -1.0) - self.assertEqual(card.surface_coefficients[3], 1.0) - self.assertEqual(card.surface_coefficients[4], -1.0) - self.assertEqual(card.surface_coefficients[5], 1.0) - - def test_box(self): - card_string = "15000 box -1 -1 -1 2 0 0 0 2 0 0 0 2" - card = MCNPSurfaceCard(card_string) - self.assertEqual(card.surface_type, SurfaceCard.SurfaceType["MACRO_RPP"]) - self.assertEqual(card.surface_id, 15000) - self.assertEqual(card.surface_coefficients[0], -1.0) - self.assertEqual(card.surface_coefficients[1], 1.0) - self.assertEqual(card.surface_coefficients[2], -1.0) - self.assertEqual(card.surface_coefficients[3], 1.0) - self.assertEqual(card.surface_coefficients[4], -1.0) - self.assertEqual(card.surface_coefficients[5], 1.0) - - def test_surfacetransform_detect(self): - card = "1 2 px 3" - self.assertEqual(surface_has_transform(card), True) - card = "1 PX 3" - self.assertEqual(surface_has_transform(card), False) - - def test_bounding_box_px(self): - card_string = "1 px 3" - card = MCNPSurfaceCard(card_string) - box = card.bounding_box() - self.assertEqual(box[0], 3) - self.assertEqual(box[1], 3) - self.assertEqual(box[2], 0) - self.assertEqual(box[3], 0) - self.assertEqual(box[4], 0) - self.assertEqual(box[5], 0) - - # generate a bounding box for py - """ - def test_bounding_box_py(self): - card_string = "1 py 3" - card = MCNPSurfaceCard(card_string) - box = card.bounding_box() - self.assertEqual(box[0],0) - self.assertEqual(box[1],0) - self.assertEqual(box[2],3) - self.assertEqual(box[3],3) - self.assertEqual(box[4],0) - self.assertEqual(box[5],0) - """ - - -if __name__ == "__main__": - unittest.main() diff --git a/csg2csg/test/UnitTestMaterialData.py b/csg2csg/test/UnitTestMaterialData.py deleted file mode 100644 index 5161c4c..0000000 --- a/csg2csg/test/UnitTestMaterialData.py +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/env/python3 - -import unittest -import sys - -sys.path.append("..") - -from csg2csg.MaterialData import MaterialData - - -class TestMaterialDataMethods(unittest.TestCase): - def test_get_nucs(self): - mat_data = MaterialData() - nuclides = mat_data.get_nucs(1000) - self.assertEqual(len(nuclides), 2) - self.assertEqual(1001 in nuclides, True) - self.assertEqual(1002 in nuclides, True) - - def test_get_nucs_fe(self): - mat_data = MaterialData() - nuclides = mat_data.get_nucs(26000) - self.assertEqual(len(nuclides), 4) - self.assertEqual(26054 in nuclides, True) - self.assertEqual(26056 in nuclides, True) - self.assertEqual(26057 in nuclides, True) - self.assertEqual(26058 in nuclides, True) - - def test_get_nucs_u(self): - mat_data = MaterialData() - nuclides = mat_data.get_nucs(92000) - self.assertEqual(len(nuclides), 3) - self.assertEqual(92234 in nuclides, True) - self.assertEqual(92235 in nuclides, True) - self.assertEqual(92238 in nuclides, True) - - def test_atomic_mass_calc(self): - mat_data = MaterialData() - atomic_mass = mat_data.atomic_mass(1000) - self.assertEqual(atomic_mass, 1.0079407540557772) - - atomic_mass = mat_data.atomic_mass(2000) - self.assertEqual(atomic_mass, 4.002601932120928) - - atomic_mass = mat_data.atomic_mass(26000) - self.assertEqual(atomic_mass, 55.84514442998594) - - def test_zz_zaid(self): - mat_data = MaterialData() - zz = mat_data.get_zz(1001) - self.assertEqual(zz, 1) - zz = mat_data.get_zz(26000) - self.assertEqual(zz, 26) - zz = mat_data.get_zz(92000) - self.assertEqual(zz, 92) - - def test_aa_zaid(self): - mat_data = MaterialData() - aa = mat_data.get_aa(1001) - self.assertEqual(aa, 1) - aa = mat_data.get_aa(26000) - self.assertEqual(aa, 0) - aa = mat_data.get_aa(92235) - self.assertEqual(aa, 235) - - -if __name__ == "__main__": - unittest.main() diff --git a/csg2csg/test/UnitTestOpenMCMaterial.py b/csg2csg/test/UnitTestOpenMCMaterial.py deleted file mode 100644 index 0e1633a..0000000 --- a/csg2csg/test/UnitTestOpenMCMaterial.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/env/python3 - -import unittest -import sys - -sys.path.append("..") - -from csg2csg.OpenMCMaterial import zaid_to_name - - -class TestOpenMCMaterial(unittest.TestCase): - def test_zaid_name_conversion(self): - name = "1001" - self.assertEqual(zaid_to_name(name), "H1") - name = "26056" - print(name[0:0], name[1:1]) - self.assertEqual(zaid_to_name(name), "Fe56") - name = "53133" - self.assertEqual(zaid_to_name(name), "I133") - name = "56133" - self.assertEqual(zaid_to_name(name), "Ba133") - name = "118294" - self.assertEqual(zaid_to_name(name), "Og294") - - -if __name__ == "__main__": - unittest.main() diff --git a/csg2csg/test/UnitTestParticle.py b/csg2csg/test/UnitTestParticle.py deleted file mode 100644 index 821d5b9..0000000 --- a/csg2csg/test/UnitTestParticle.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/env/python3 - -import unittest -import sys - -sys.path.append("..") - -from csg2csg.ParticleNames import particleToGeneric, ParticleNames - - -class TestParticleMethods(unittest.TestCase): - def test_generic(self): - self.assertEqual(None, particleToGeneric("NEUTRON")) - self.assertEqual("Neutron", particleToGeneric(ParticleNames["NEUTRON"])) - self.assertEqual("Electron", particleToGeneric(ParticleNames["ELECTRON"])) - self.assertEqual("Positron", particleToGeneric(ParticleNames["POSITRON"])) - self.assertEqual("Proton", particleToGeneric(ParticleNames["PROTON"])) - self.assertEqual("Deuteron", particleToGeneric(ParticleNames["DEUTERON"])) - self.assertEqual("Triton", particleToGeneric(ParticleNames["TRITON"])) - self.assertEqual("Alpha", particleToGeneric(ParticleNames["ALPHA"])) - self.assertEqual("Positive Pion", particleToGeneric(ParticleNames["PION_PLUS"])) - self.assertEqual("Negative Pion", particleToGeneric(ParticleNames["PION_NEG"])) - self.assertEqual("Helion", particleToGeneric(ParticleNames["HELION"])) - self.assertEqual("Negative Muon", particleToGeneric(ParticleNames["MUON_NEG"])) - - -if __name__ == "__main__": - unittest.main() diff --git a/csg2csg/test/UnitTestSerpentMaterial.py b/csg2csg/test/UnitTestSerpentMaterial.py deleted file mode 100644 index b395a80..0000000 --- a/csg2csg/test/UnitTestSerpentMaterial.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/env/python3 - -import unittest -import sys - -sys.path.append("..") - -from csg2csg.SerpentMaterialCard import SerpentMaterialCard -from csg2csg.SerpentInput import SerpentInput - - -class TestSerpentMaterial(unittest.TestCase): - def test_serpent_material(self): - string = "29063 6.917000e-01 \n" + "29065.31c 3.083000e-01 \n" - number = 1 - name = "copper" - density = 8.93 - matcard = SerpentMaterialCard(number, name, density, string) - - self.assertEqual(matcard.density, density) - self.assertEqual(matcard.material_number, number) - self.assertEqual(matcard.material_name, name) - self.assertEqual(len(matcard.composition_dictionary), 2) - - self.assertEqual(list(matcard.composition_dictionary.keys())[0], "29063") - self.assertEqual(list(matcard.composition_dictionary.keys())[1], "29065") - - self.assertEqual(list(matcard.composition_dictionary.values())[0], 6.917000e-01) - self.assertEqual(list(matcard.composition_dictionary.values())[1], 3.083000e-01) - - self.assertEqual(len(matcard.xsid_dictionary), 2) - - self.assertEqual(list(matcard.xsid_dictionary.keys())[0], "29063") - self.assertEqual(list(matcard.xsid_dictionary.keys())[1], "29065") - - self.assertEqual(list(matcard.xsid_dictionary.values())[0], "") - self.assertEqual(list(matcard.xsid_dictionary.values())[1], "31c") - - def test_serpent_mat_input(self): - string = ["mat 1 8.93\n", "29063 6.917000e-01\n", "29065 3.083000e-01\n"] - - serpent = SerpentInput() - serpent.file_lines = string - serpent.process() - - -if __name__ == "__main__": - unittest.main() diff --git a/csg2csg/test/UnitTestSerpentSurface.py b/csg2csg/test/UnitTestSerpentSurface.py deleted file mode 100644 index 5ab295e..0000000 --- a/csg2csg/test/UnitTestSerpentSurface.py +++ /dev/null @@ -1,36 +0,0 @@ -#!/usr/env/python3 - -import unittest -import sys - -sys.path.append("..") - -from csg2csg.SurfaceCard import SurfaceCard -from csg2csg.MCNPSurfaceCard import MCNPSurfaceCard -from csg2csg.SerpentSurfaceCard import serpent_cone_x -from math import sqrt - - -class TestSerpentSurface(unittest.TestCase): - def test_cone_x_up_write(self): - card = "1 k/x 0 0 0 0.5 1" - surfcard = MCNPSurfaceCard(card) - surfcard.b_box = [0, 10, 0, 0, 0, 0] - serp_string = serpent_cone_x(surfcard) - self.assertEqual( - serp_string, " ckx 0.000000 0.000000 0.000000 0.500000 1.000000\n" - ) - - def test_cone_x_down_write(self): - card = "1 k/x 0 0 0 0.5 -1" - surfcard = MCNPSurfaceCard(card) - surfcard.b_box = [0, 0, 0, 0, 0, 0] - surfcard.b_box = [-10, 0, 0, 0, 0, 0] - serp_string = serpent_cone_x(surfcard) - self.assertEqual( - serp_string, " ckx 0.000000 0.000000 0.000000 0.500000 -1.000000\n" - ) - - -if __name__ == "__main__": - unittest.main() diff --git a/csg2csg/test/UnitTestSurface.py b/csg2csg/test/UnitTestSurface.py deleted file mode 100644 index 8964907..0000000 --- a/csg2csg/test/UnitTestSurface.py +++ /dev/null @@ -1,111 +0,0 @@ -#!/usr/env/python3 - -import unittest -import sys - -sys.path.append("..") -from SurfaceCard import SurfaceCard - - -class SurfaceMethods(unittest.TestCase): - def test_simplify_plane_to_plane(self): - surface = SurfaceCard("") - surface_coefficients = [1.0, 1.0, 0.0, 10.0] - transform_id = 0 - surface_type = surface.SurfaceType["PLANE_GENERAL"] - surface_id = 1 - surface.set_type(surface_id, transform_id, surface_type, surface_coefficients) - surface.simplify() - self.assertEqual(surface.surface_type, surface.SurfaceType["PLANE_GENERAL"]) - - def test_simplify_gq_to_plane(self): - surface = SurfaceCard("") - surface_coefficients = [0, 0, 0, 0, 0, 0, 1.0, 1.0, 0.0, -10.0] - transform_id = 0 - surface_type = surface.SurfaceType["GENERAL_QUADRATIC"] - surface_id = 1 - surface.set_type(surface_id, transform_id, surface_type, surface_coefficients) - surface.simplify() - self.assertEqual(surface.surface_type, surface.SurfaceType["PLANE_GENERAL"]) - - def test_generalise(self): - surface = SurfaceCard("") - surface_coefficients = [1.0, 1.0, 0.0, -10.0] - transform_id = 0 - surface_type = surface.SurfaceType["PLANE_GENERAL"] - surface_id = 1 - surface.set_type(surface_id, transform_id, surface_type, surface_coefficients) - surface.generalise() - self.assertEqual(surface.surface_type, surface.SurfaceType["GENERAL_QUADRATIC"]) - for i in range(6): - self.assertEqual(surface.surface_coefficients[i], 0.0) - - def test_generalise_simplify_general_plane(self): - surface = SurfaceCard("") - surface_coefficients = [1.0, 1.0, 0.0, -10.0] - transform_id = 0 - surface_type = surface.SurfaceType["PLANE_GENERAL"] - surface_id = 1 - surface.set_type(surface_id, transform_id, surface_type, surface_coefficients) - surface.generalise() - self.assertEqual(surface.surface_type, surface.SurfaceType["GENERAL_QUADRATIC"]) - for i in range(6): - self.assertEqual(surface.surface_coefficients[i], 0.0) - surface.simplify() - # make sure we get a general plane back - self.assertEqual(surface.surface_type, surface.SurfaceType["PLANE_GENERAL"]) - self.assertEqual(surface.surface_coefficients[0], 1.0) - self.assertEqual(surface.surface_coefficients[1], 1.0) - self.assertEqual(surface.surface_coefficients[2], 0.0) - self.assertEqual(surface.surface_coefficients[3], -10.0) - - # test the surface.generalise() function - def test_surface_reverse(self): - # first surface - surface1 = SurfaceCard("") - surface_coefficients = [1.0, 0.0, 0.0, -10.0] - transform_id = 0 - surface_type = surface1.SurfaceType["PLANE_GENERAL"] - surface_id = 1 - surface1.set_type(surface_id, transform_id, surface_type, surface_coefficients) - surface1.generalise() - self.assertEqual(surface1.surface_coefficients[6], -1.0) - self.assertEqual(surface1.surface_coefficients[9], -10.0) - - # test the surface.reverse() function - def test_surface_reverse(self): - # first surface - surface1 = SurfaceCard("") - surface_coefficients = [1.0, 0.0, 0.0, -10.0] - transform_id = 0 - surface_type = surface1.SurfaceType["PLANE_GENERAL"] - surface_id = 1 - surface1.set_type(surface_id, transform_id, surface_type, surface_coefficients) - surface1.generalise() - surface1.reverse() - self.assertEqual(surface1.surface_coefficients[6], -1.0) - self.assertEqual(surface1.surface_coefficients[9], -10.0) - - def test_surface_two_planes_compare(self): - # first surface - surface1 = SurfaceCard("") - surface_coefficients = [1.0, 0.0, 0.0, 10.0] - transform_id = 0 - surface_type = surface1.SurfaceType["PLANE_GENERAL"] - surface_id = 1 - surface1.set_type(surface_id, transform_id, surface_type, surface_coefficients) - - # second surface - surface2 = SurfaceCard("") - surface_coefficients = [-1.0, 0.0, 0.0, -10.0] - transform_id = 0 - surface_type = surface2.SurfaceType["PLANE_GENERAL"] - surface_id = 2 - surface2.set_type(surface_id, transform_id, surface_type, surface_coefficients) - - self.assertEqual(surface1.diff(surface2, False), (False, False)) - self.assertEqual(surface1.diff(surface2), (True, True)) - - -if __name__ == "__main__": - unittest.main() diff --git a/csg2csg/test/UnitTestVector.py b/csg2csg/test/UnitTestVector.py deleted file mode 100644 index ce3ed30..0000000 --- a/csg2csg/test/UnitTestVector.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/env/python3 - -import unittest -import sys - -sys.path.append("..") - -from csg2csg.Vector import add, cross, subtract - - -class TestVectorMethods(unittest.TestCase): - def test_subtract(self): - a = [1, 0, 0] - b = [1, 0, 0] - c = subtract(a, b) - - self.assertEqual(c[0], 0.0) - self.assertEqual(c[1], 0.0) - self.assertEqual(c[2], 0.0) - - def test_add(self): - a = [1, 0, 0] - b = [0, 1, 0] - c = add(a, b) - - self.assertEqual(c[0], 1.0) - self.assertEqual(c[1], 1.0) - self.assertEqual(c[2], 0.0) - - def test_cross(self): - a = [1, 0, 0] - b = [0, 1, 0] - c = cross(a, b) - - self.assertEqual(c[0], 0.0) - self.assertEqual(c[1], 0.0) - self.assertEqual(c[2], 1.0) - - -if __name__ == "__main__": - unittest.main() diff --git a/csg2csg/test/integration/TestWindowsLineEndings.py b/csg2csg/test/integration/TestWindowsLineEndings.py deleted file mode 100644 index 3f98a14..0000000 --- a/csg2csg/test/integration/TestWindowsLineEndings.py +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/env/python - -import unittest -import subprocess - - -def cleanup(): - subprocess.call("rm -rf mcnp fluka openmc serpent file.mcnp", shell=True) - - -class TestWindowsLineEndings(unittest.TestCase): - def test_windows_line_endings(self): - - return_code = subprocess.call( - "csg2csg -i files/spheres.i -f mcnp -o all", shell=True - ) - self.assertEqual(return_code, 0) - return_code = subprocess.call( - "sed -e 's/$/\r/' files/spheres.i > spheres_win.i # UNIX to DOS (adding CRs)", - shell=True, - ) - return_code = subprocess.call( - "csg2csg -i spheres_win.i -f mcnp -o all", shell=True - ) - self.assertEqual(return_code, 0) - cleanup() - - # round trip the MCNP file produced from the line above - it should be - # identical - def test_round_trip(self): - cleanup() - return_code = subprocess.call( - "csg2csg -i files/spheres.i -f mcnp -o mcnp", shell=True - ) - self.assertEqual(return_code, 0) - - return_code = subprocess.call("mv mcnp/file.mcnp . ", shell=True) - self.assertEqual(return_code, 0) - return_code = subprocess.call("rm -rf mcnp fluka openmc serpent", shell=True) - self.assertEqual(return_code, 0) - - return_code = subprocess.call( - "csg2csg -i file.mcnp -f mcnp -o mcnp", shell=True - ) - self.assertEqual(return_code, 0) - return_code = subprocess.call("diff file.mcnp mcnp/file.mcnp", shell=True) - self.assertEqual(return_code, 0) - cleanup() - - -if __name__ == "__main__": - unittest.main() diff --git a/csg2csg/test/integration/run_tests b/csg2csg/test/integration/run_tests deleted file mode 100755 index c7029a7..0000000 --- a/csg2csg/test/integration/run_tests +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -set -ex - -for i in `ls *.py` ; do - python3 $i -done diff --git a/csg2csg/test/run_tests b/csg2csg/test/run_tests deleted file mode 100755 index 1555b8a..0000000 --- a/csg2csg/test/run_tests +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -set -ex - -for i in `ls *.py` ; do - python3 $i -done - -cd integration -./run_tests -cd .. diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..ef09b54 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,38 @@ +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "csg2csg" +version = "0.0.27" +authors = [ + { name="Andrew Davis", email="andrew.davis@ukaea.uk" }, +] +description = "Convert CSG geometry into different formats" +readme = "README.md" +requires-python = ">=3.7" +dependencies = [ + "numpy", +] +classifiers = [ + "Programming Language :: Python :: 3", +# "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", +] + +[project.optional-dependencies] +dev = [ + "pytest", + "pytest-cov", + "ruff", +] + +[project.scripts] +csg2csg = "csg2csg.__main__:main" + +[project.urls] +"Homepage" = "https://github.com/makeclean/csg2csg" +"Bug Tracker" = "https://github.com/makeclean/csg2csg/issues" + +[tool.setuptools] +packages = ["csg2csg"] diff --git a/setup.py b/setup.py deleted file mode 100644 index 1d608c0..0000000 --- a/setup.py +++ /dev/null @@ -1,23 +0,0 @@ -import setuptools - -with open("README.md", "r") as fh: - long_description = fh.read() - -setuptools.setup( - name="csg2csg", - version="0.0.27", - author="andrew davis", - author_email="andrew.davis@ukaea.uk", - description="Convert CSG geometry into different formats", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/makeclean/csg2csg", - packages=setuptools.find_packages(), - entry_points=dict(console_scripts=["csg2csg=csg2csg.__main__:main"]), - install_requires=["numpy"], - classifiers=[ - "Programming Language :: Python :: 3", - # "License :: OSI Approved :: License name here", - "Operating System :: OS Independent", - ], -) diff --git a/csg2csg/test/integration/files/spheres.i b/test-data/spheres.i similarity index 100% rename from csg2csg/test/integration/files/spheres.i rename to test-data/spheres.i diff --git a/tests/terst_openmcmaterial.py b/tests/terst_openmcmaterial.py new file mode 100644 index 0000000..b9766a4 --- /dev/null +++ b/tests/terst_openmcmaterial.py @@ -0,0 +1,15 @@ +from csg2csg.OpenMCMaterial import zaid_to_name + + +def test_zaid_name_conversion(): + name = "1001" + assert zaid_to_name(name) == "H1" + name = "26056" + print(name[0:0], name[1:1]) + assert zaid_to_name(name) == "Fe56" + name = "53133" + assert zaid_to_name(name) == "I133" + name = "56133" + assert zaid_to_name(name) == "Ba133" + name = "118294" + assert zaid_to_name(name) == "Og294" diff --git a/tests/test_lineendings.py b/tests/test_lineendings.py new file mode 100644 index 0000000..bb35162 --- /dev/null +++ b/tests/test_lineendings.py @@ -0,0 +1,39 @@ +import subprocess + + +def cleanup(): + subprocess.check_call("rm -rf mcnp fluka openmc serpent file.mcnp", shell=True) + + +def test_windows_line_endings(): + + subprocess.check_call( + "csg2csg -i test-data/spheres.i -f mcnp -o all", shell=True + ) + # UNIX to DOS (adding CRs) + subprocess.check_call( + r"sed -e 's/$/\r/' test-data/spheres.i > spheres_win.i", + shell=True, + ) + subprocess.check_call( + "csg2csg -i spheres_win.i -f mcnp -o all", shell=True + ) + cleanup() + + +# round trip the MCNP file produced from the line above - it should be +# identical +def test_round_trip(): + cleanup() + subprocess.check_call( + "csg2csg -i test-data/spheres.i -f mcnp -o mcnp", shell=True + ) + + subprocess.check_call("mv mcnp/file.mcnp . ", shell=True) + subprocess.check_call("rm -rf mcnp fluka openmc serpent", shell=True) + + subprocess.check_call( + "csg2csg -i file.mcnp -f mcnp -o mcnp", shell=True + ) + subprocess.check_call("diff file.mcnp mcnp/file.mcnp", shell=True) + cleanup() diff --git a/tests/test_materialdata.py b/tests/test_materialdata.py new file mode 100644 index 0000000..9162e04 --- /dev/null +++ b/tests/test_materialdata.py @@ -0,0 +1,60 @@ +from csg2csg.MaterialData import MaterialData + + +def test_get_nucs(): + mat_data = MaterialData() + nuclides = mat_data.get_nucs(1000) + assert len(nuclides) == 2 + assert 1001 in nuclides + assert 1002 in nuclides + + +def test_get_nucs_fe(): + mat_data = MaterialData() + nuclides = mat_data.get_nucs(26000) + assert len(nuclides) == 4 + assert 26054 in nuclides + assert 26056 in nuclides + assert 26057 in nuclides + assert 26058 in nuclides + + +def test_get_nucs_u(): + mat_data = MaterialData() + nuclides = mat_data.get_nucs(92000) + assert len(nuclides) == 3 + assert 92234 in nuclides + assert 92235 in nuclides + assert 92238 in nuclides + + +def test_atomic_mass_calc(): + mat_data = MaterialData() + atomic_mass = mat_data.atomic_mass(1000) + assert atomic_mass == 1.0079407540557772 + + atomic_mass = mat_data.atomic_mass(2000) + assert atomic_mass == 4.002601932120928 + + atomic_mass = mat_data.atomic_mass(26000) + assert atomic_mass == 55.84514442998594 + + +def test_zz_zaid(): + mat_data = MaterialData() + zz = mat_data.get_zz(1001) + assert zz == 1 + zz = mat_data.get_zz(26000) + assert zz == 26 + zz = mat_data.get_zz(92000) + assert zz == 92 + + +def test_aa_zaid(): + mat_data = MaterialData() + aa = mat_data.get_aa(1001) + assert aa == 1 + aa = mat_data.get_aa(26000) + assert aa == 0 + aa = mat_data.get_aa(92235) + assert aa == 235 diff --git a/tests/test_mcnpcell.py b/tests/test_mcnpcell.py new file mode 100644 index 0000000..c96a0f2 --- /dev/null +++ b/tests/test_mcnpcell.py @@ -0,0 +1,81 @@ +from csg2csg.MCNPCellCard import MCNPCellCard, mcnp_line_formatter + + +# TODO definitely add some more robust testing of the position of the +# logical operations - Very Important + + +def test_simple_cell(): + card_string = "1 1 -1.0 -4 5 -6 7" + card = MCNPCellCard(card_string) + assert card.text_string == card_string + assert card.cell_id == 1 + assert card.cell_density == -1.0 + + +def test_more_complex_cell(): + card_string = "2 3 -14.0 (-4 5 -6 7):(9 12 13)" + card = MCNPCellCard(card_string) + assert card.text_string == card_string + assert card.cell_id == 2 + assert card.cell_material_number == 3 + assert card.cell_density == -14.0 + + +def test_mcnp_detect_keywords_all(): + string = "2 3 -14.0 1 imp:n=1 imp:p=1 u=3 fill=12 vol=150" + cell_card = MCNPCellCard(string) + new_string = cell_card._MCNPCellCard__detect_keywords( + ["imp", "u", "fill", "vol"], string + ) + assert new_string == "2 3 -14.0 1 " + + +def test_mcnp_detect_keywords_imp(): + string = "2 3 -14.0 1 imp:n=1 imp:p=1 " + cell_card = MCNPCellCard(string) + new_string = cell_card._MCNPCellCard__detect_keywords(["imp"], string) + assert new_string == "2 3 -14.0 1 " + + +def test_mcnp_detect_keywords_uni(): + string = "2 3 -14.0 1 u=1 " + cell_card = MCNPCellCard(string) + new_string = cell_card._MCNPCellCard__detect_keywords(["u"], string) + assert new_string == "2 3 -14.0 1 " + + +def test_mcnp_detect_keywords_fill(): + string = "2 3 -14.0 1 fill=3" + cell_card = MCNPCellCard(string) + new_string = cell_card._MCNPCellCard__detect_keywords(["fill"], string) + assert new_string == "2 3 -14.0 1 " + + +def test_mcnp_detect_keywords_vol(): + string = "2 3 -14.0 1 vol=300" + cell_card = MCNPCellCard(string) + new_string = cell_card._MCNPCellCard__detect_keywords(["vol"], string) + assert new_string == "2 3 -14.0 1 " + + +def test_mcnp_detect_keywords_tmp(): + string = "2 3 -14.0 1 tmp=300" + cell_card = MCNPCellCard(string) + new_string = cell_card._MCNPCellCard__detect_keywords(["tmp"], string) + assert new_string == "2 3 -14.0 1 " + + +def test_mcnp_line_format(): + string = "1 0 (-1 3 4 5 6 8 9 ( 12 13 15))" + mcnp_string = mcnp_line_formatter(string) + assert string == mcnp_string + # note these horrendously long lines - is actually what im trying to test and furthermore + # all of the standard techniques to break the string across multuple lines like + # https://stackoverflow.com/questions/5437619/python-style-line-continuation-with-strings + # dont actually work + string = "1 0 (-1 3 4 5 6 8 9 ( 12 13 15) ( 12 13 15) ( 12 13 15) ( 12 13 15) ( 12 13 15))" + result = mcnp_line_formatter(string) + assert result == ( + "1 0 (-1 3 4 5 6 8 9 ( 12 13 15) ( 12 13 15) ( 12 13 15) ( 12 13 15) (\n 12 13 15))" + ) diff --git a/tests/test_mcnpformatter.py b/tests/test_mcnpformatter.py new file mode 100644 index 0000000..776bc73 --- /dev/null +++ b/tests/test_mcnpformatter.py @@ -0,0 +1,35 @@ +from csg2csg.MCNPFormatter import get_fortran_formatted_number + + +def test_fortran_format(): + string = "-1.0-1" + number = get_fortran_formatted_number(string) + assert number == -1.0e-1 + + string = "-1.0+1" + number = get_fortran_formatted_number(string) + assert number == -1.0e1 + + string = "1.0+1" + number = get_fortran_formatted_number(string) + assert number == 1.0e1 + + string = "15.0-100" + number = get_fortran_formatted_number(string) + assert number == 1.5e-99 + + string = "-15.0+39" + number = get_fortran_formatted_number(string) + assert number == -1.5e40 + + string = "-15.0+309" + number = get_fortran_formatted_number(string) + assert number == -1.5e310 + + string = "6.1000" + number = get_fortran_formatted_number(string) + assert number == 6.1000 + + string = "-6.1000" + number = get_fortran_formatted_number(string) + assert number == -6.1000 diff --git a/tests/test_mcnpinput.py b/tests/test_mcnpinput.py new file mode 100644 index 0000000..e166408 --- /dev/null +++ b/tests/test_mcnpinput.py @@ -0,0 +1,463 @@ +from csg2csg.MCNPInput import MCNPInput # , explode_macrobody +from csg2csg.MCNPSurfaceCard import MCNPSurfaceCard +from csg2csg.SurfaceCard import SurfaceCard + + +def test_spaces_block_breaks(): + input_string = [ + "this is a title\n", + "1 1 -1.0 -3\n", + "2 0 3\n", + " \n", + "3 rpp -1 1 -1 1 -1 1\n", + " \n", + "m1 1001 1.0\n", + " 1002 1.0\n", + ] + + # setup input + input = MCNPInput() + input.cell_list = [] + input.file_lines = input_string + # TODO: why is this being set, it doesn't seem to be used anywhere + input.total_num_lines = len(input_string) + input.process() + + # check number of cells found + assert len(input.cell_list) == 2 + + +def test_white_spaces_block_breaks(): + input_string = [ + "this is a title\n", + "1 1 -1.0 -3\n", + "2 0 3\n", + " \t \n", + "3 rpp -1 1 -1 1 -1 1\n", + " \t \n", + "m1 1001 1.0\n", + " 1002 1.0\n", + ] + + # setup input + input = MCNPInput() + input.cell_list = [] + input.file_lines = input_string + input.total_num_lines = len(input_string) + input.process() + + # check number of cells found + assert len(input.cell_list) == 2 + + +def test_comment_lines(): + input_string = [ + "this is a title\n", + "4980 130 0.06026342 8085 -8086 8654 -4684 27 100 -200 imp:n=1\n", + "4985 130 0.06000038 8011 -8086 4684 -4682 27 100 -200 imp:n=1\n", + "4995 130 0.099591 8011 -8086 4682 -53 27 100 -200 imp:n=1\n", + "c\n", + "c Comment line sandwiched by two blank comment lines\n", + "c\n", + "5001 130 0.099591 7511 -7586 -67 7602 -53 100 -200 imp:n=1\n", + "5002 130 0.06000038 7511 -7586 -7602 7604 -53 100 -200 imp:n=1 \n", + " \t \n", + "8085 so 10.\n", + "8086 so 11.\n", + "8654 so 12.\n", + "4684 so 13.\n", + "27 so 14.\n", + "100 so 15.\n", + "200 so 16.\n", + " \t \n", + "m130 1001 1.0\n", + " 1002 1.0\n", + ] + + # setup input + input = MCNPInput() + input.cell_list = [] + input.surface_list = [] + input.file_lines = input_string + input.total_num_lines = len(input_string) + input.process() + + # check number of cells found is 5 and does not include the c + assert len(input.cell_list) == 5 + + # checks the number of surfaces found is 7 + assert len(input.surface_list) == 7 + + +def test_explode_macrobody(): + input = MCNPInput() + card_string = "1 rpp -1 1 -1 1 -1 1" + Surface = MCNPSurfaceCard(card_string) + # explode macrobody into surfaces + cells, new_surfaces = input.explode_macrobody(Surface) + assert cells[0] == "( -1 -2 -3 -4 -5 -6 )" + assert cells[1] == "( 1 : 2 : 3 : 4 : 5 : 6)" + assert len(new_surfaces) == 6 + assert new_surfaces[0].surface_type == SurfaceCard.SurfaceType["PLANE_X"] + assert new_surfaces[0].surface_coefficients[3] == 1 + assert new_surfaces[1].surface_type == SurfaceCard.SurfaceType["PLANE_GENERAL"] + assert new_surfaces[1].surface_coefficients[0] == -1 + assert new_surfaces[2].surface_type == SurfaceCard.SurfaceType["PLANE_Y"] + assert new_surfaces[2].surface_coefficients[3] == 1 + assert new_surfaces[3].surface_type == SurfaceCard.SurfaceType["PLANE_GENERAL"] + assert new_surfaces[3].surface_coefficients[1] == -1 + assert new_surfaces[4].surface_type == SurfaceCard.SurfaceType["PLANE_Z"] + assert new_surfaces[4].surface_coefficients[3] == 1 + assert new_surfaces[5].surface_type == SurfaceCard.SurfaceType["PLANE_GENERAL"] + assert new_surfaces[5].surface_coefficients[2] == -1 + + +def test_flatten_macrobodies(): + input_string = [ + "this is a title\n", + "1 1 -1.0 -3\n", + "2 0 3\n", + "\n", + "3 rpp -1 1 -1 1 -1 1\n", + "\n", + "m1 1001 1.0\n", + " 1002 1.0\n", + ] + + # setup input + input = MCNPInput() + input.file_lines = input_string + input.total_num_lines = len(input_string) + input.process() + + # cell card + cell1 = input.cell_list[0] + cell2 = input.cell_list[1] + + assert cell1.text_string == "1 1 -1.0 ( -4 -5 -6 -7 -8 -9 )" + assert cell2.text_string == "2 0 ( 4 : 5 : 6 : 7 : 8 : 9)" + + +# test case for the box macrobody +def test_box_macrobody(): + input_string = [ + "this is a title\n", + "1 1 -1.0 -3\n", + "2 0 3\n", + "\n", + "3 box -1 -1 -1 2 0 0 0 2 0 0 0 2\n", + "\n", + "m1 1001 1.0\n", + " 1002 1.0\n", + ] + + # setup input + input = MCNPInput() + input.file_lines = input_string + input.total_num_lines = len(input_string) + input.process() + + # cell card + cell1 = input.cell_list[0] + cell2 = input.cell_list[1] + + assert cell1.text_string == "1 1 -1.0 ( -4 -5 -6 -7 -8 -9 )" + assert cell2.text_string == "2 0 ( 4 : 5 : 6 : 7 : 8 : 9)" + + # surface card + surface1 = input.surface_list[0] + surface2 = input.surface_list[1] + assert surface1.surface_type == SurfaceCard.SurfaceType["PLANE_X"] + assert surface1.surface_coefficients == [1, 0, 0, 1] + assert surface2.surface_type == SurfaceCard.SurfaceType["PLANE_GENERAL"] + assert surface2.surface_coefficients == [-1, 0, 0, 1] + + +def test_flatten_macrobodies_with_other_surfs(): + input_string = [ + "this is a title\n", + "1 1 -1.0 -7 3\n", + "2 0 -3\n", + "3 0 7\n", + "\n", + "3 rpp -1 1 -1 1 -1 1\n", + "7 so 10.\n", + "\n", + "m1 1001 1.0\n", + " 1002 1.0\n", + ] + + # setup input + input = MCNPInput() + + input.cell_list = [] + input.surface_list = [] + input.material_list = {} + input.transform_list = {} + + assert len(input.cell_list) == 0 + input.file_lines = input_string + input.total_num_lines = len(input_string) + input.process() + + # cell card + cell1 = input.cell_list[0] + cell2 = input.cell_list[1] + cell3 = input.cell_list[2] + assert len(input.cell_list) == 3 + + # surface numbering should start at 7 + assert cell3.text_string == "3 0 7" + assert cell2.text_string == "2 0 ( -8 -9 -10 -11 -12 -13 )" + assert cell1.text_string == "1 1 -1.0 -7 ( 8 : 9 : 10 : 11 : 12 : 13)" + + # surfaces should be numbered from 7 to 13 contiguously + for i in range(0, len(input.surface_list)): + assert input.surface_list[i].surface_id == 7 + i + + # surface 7 should be a sphere + # assert input.surface_list[0].surface_type == SurfaceCard.SurfaceType["SPHERE_GENERAL"] + # 8-9 px 10-11 py 12-13 pz + assert input.surface_list[1].surface_type == SurfaceCard.SurfaceType["PLANE_X"] + assert input.surface_list[2].surface_type == SurfaceCard.SurfaceType["PLANE_GENERAL"] + assert input.surface_list[3].surface_type == SurfaceCard.SurfaceType["PLANE_Y"] + assert input.surface_list[4].surface_type == SurfaceCard.SurfaceType["PLANE_GENERAL"] + assert input.surface_list[5].surface_type == SurfaceCard.SurfaceType["PLANE_Z"] + assert input.surface_list[6].surface_type == SurfaceCard.SurfaceType["PLANE_GENERAL"] + + +def test_flatten_macrobodies_with_multiple_macrobodies(): + input_string = [ + "this is a title\n", + "1 1 -1.0 -3\n", + "2 0 3 -4\n", + "3 0 4 -5\n", + "4 0 5\n", + "\n", + "3 rpp -5 5 -5 5 -5 5\n", + "4 rpp -10 10 -10 10 -10 10\n", + "5 rpp -15 15 -15 15 -15 15\n", + "\n", + "m1 1001 1.0\n", + " 1002 1.0\n", + "\n", + ] + + # setup input + input = MCNPInput() + input.cell_list = [] + input.surface_list = [] + input.material_list = {} + input.transform_list = {} + + assert len(input.cell_list) == 0 + input.file_lines = input_string + input.total_num_lines = len(input_string) + input.process() + + # cell card + cell1 = input.cell_list[0] + cell2 = input.cell_list[1] + cell3 = input.cell_list[2] + cell4 = input.cell_list[3] + assert len(input.cell_list) == 4 + + # are surfaces correctly processed + assert input.surface_list[0].surface_type == SurfaceCard.SurfaceType["PLANE_X"] + assert input.surface_list[1].surface_type == SurfaceCard.SurfaceType["PLANE_GENERAL"] + assert input.surface_list[2].surface_type == SurfaceCard.SurfaceType["PLANE_Y"] + assert input.surface_list[3].surface_type == SurfaceCard.SurfaceType["PLANE_GENERAL"] + assert input.surface_list[4].surface_type == SurfaceCard.SurfaceType["PLANE_Z"] + assert input.surface_list[5].surface_type == SurfaceCard.SurfaceType["PLANE_GENERAL"] + + assert input.surface_list[6].surface_type == SurfaceCard.SurfaceType["PLANE_X"] + assert input.surface_list[7].surface_type == SurfaceCard.SurfaceType["PLANE_GENERAL"] + assert input.surface_list[8].surface_type == SurfaceCard.SurfaceType["PLANE_Y"] + assert input.surface_list[9].surface_type == SurfaceCard.SurfaceType["PLANE_GENERAL"] + assert input.surface_list[10].surface_type == SurfaceCard.SurfaceType["PLANE_Z"] + assert input.surface_list[11].surface_type == SurfaceCard.SurfaceType["PLANE_GENERAL"] + + assert input.surface_list[12].surface_type == SurfaceCard.SurfaceType["PLANE_X"] + assert input.surface_list[13].surface_type == SurfaceCard.SurfaceType["PLANE_GENERAL"] + assert input.surface_list[14].surface_type == SurfaceCard.SurfaceType["PLANE_Y"] + assert input.surface_list[15].surface_type == SurfaceCard.SurfaceType["PLANE_GENERAL"] + assert input.surface_list[16].surface_type == SurfaceCard.SurfaceType["PLANE_Z"] + assert input.surface_list[17].surface_type == SurfaceCard.SurfaceType["PLANE_GENERAL"] + + # surface numbering should start at 6 + assert cell1.text_string == "1 1 -1.0 ( -6 -7 -8 -9 -10 -11 )" + assert cell2.text_string == "2 0 ( 6 : 7 : 8 : 9 : 10 : 11 ) ( -12 -13 -14 -15 -16 -17 )" + assert cell3.text_string == "3 0 ( 12 : 13 : 14 : 15 : 16 : 17 ) ( -18 -19 -20 -21 -22 -23 )" + # TODO: check that this is correct, previously wasn't being tested + assert cell4.text_string == "4 0 ( 18 : 19 : 20 : 21 : 22 : 23)" + + # TODO: why was this test returning here + return + + # surfaces should be numbered from 7 to 13 contiguously + for i in range(0, len(input.surface_list)): + assert input.surface_list[i].surface_id == 7 + i + + # surface 7 should be a sphere + # 8-9 px 10-11 py 12-13 pz + + +def test_cone_expansion(): + input_string = [ + "this is a title\n", + "1 1 -1.0 -1\n", + "2 0 1\n", + "\n", + "1 k/z 0 0 5 0.5 -1\n", + "\n", + "m1 1001 1.0\n", + " 1002 1.0\n", + "\n", + ] + + # setup input + input = MCNPInput() + input.cell_list = [] + input.surface_list = [] + input.material_list = {} + input.transform_list = {} + + input.file_lines = input_string + input.total_num_lines = len(input_string) + input.process() + + # are surfaces correctly processed + assert input.surface_list[0].surface_type == SurfaceCard.SurfaceType["CONE_Z"] + + # surface numbering should start at 6 + cell1 = input.cell_list[0] + cell2 = input.cell_list[1] + assert cell1.text_string == "1 1 -1.0 ( -1 -2 )" + assert cell2.text_string == "2 0 ( 1 -2 : 2)" + + +def test_parenthesis_bug(): + input_string = [ + "this is a title\n", + "1 0 (3) \n", + "2 0 (#1)\n", + " \n", + "3 cz 300\n", + " \n", + "m1 1001 1.0\n", + " 1002 1.0\n", + ] + + # setup input + input = MCNPInput() + input.cell_list = [] + input.file_lines = input_string + input.total_num_lines = len(input_string) + input.process() + + # check number of cells found + assert len(input.cell_list) == 2 + assert input.cell_list[0].text_string == "1 0 (3) \n" + assert input.cell_list[1].text_string == "2 0 (#1)\n" + + +def test_parenthesis_plane_bug(): + input_string = [ + "this is a title\n", + "1 1 -1.0 -1\n", + "2 0 1\n", + " \n", + "1 1 px 2.0\n", + " \n", + "*tr1 0 0.15 0 45 90 45 90 0 90 135 90 45\n", + "m1 1001 1.0\n", + " 1002 1.0\n", + ] + + # setup input + input = MCNPInput() + input.cell_list = [] + input.file_lines = input_string + input.total_num_lines = len(input_string) + input.process() + + # check number of cells found + assert len(input.cell_list) == 2 + assert len(input.surface_list) == 1 + assert len(input.surface_list[0].surface_coefficients) == 4 + assert input.surface_list[0].surface_coefficients[0] == 0.7071067811865476 + assert input.surface_list[0].surface_coefficients[1] == 6.123233995736766e-17 + assert input.surface_list[0].surface_coefficients[2] == 0.7071067811865476 + assert input.surface_list[0].surface_coefficients[3] == 2.0 + + +def test_duplicate_surface_without_rot(): + input_string = [ + "this is a title\n", + "1 1 -1.0 -1\n", + "2 1 -1.0 2\n", + " \n", + "1 px 2.0\n", + "2 px 2.0\n", + " \n", + "m1 1001 1.0\n", + " 1002 1.0\n", + ] + + # setup input + input = MCNPInput() + input.cell_list = [] + input.file_lines = input_string + input.total_num_lines = len(input_string) + input.quick_process = False + input.process() + + assert len(input.surface_list) == 1 + + +def test_duplicate_surface_with_rot(): + input_string = [ + "this is a title\n", + "1 1 -1.0 -1\n", + "2 1 -1.0 2\n", + " \n", + "1 1 px 2.0\n", + "2 1 px 2.0\n", + " \n", + "*tr1 0 0.15 0 45 90 45 90 0 90 135 90 45\n", + "m1 1001 1.0\n", + " 1002 1.0\n", + ] + + # setup input + input = MCNPInput() + input.cell_list = [] + input.file_lines = input_string + input.total_num_lines = len(input_string) + input.process() + + assert len(input.surface_list) == 1 + + +def test_duplicate_surface_with_macro(): + input_string = [ + "this is a title\n", + "1 0 -1\n", + "2 0 -2\n", + " \n", + "1 px 2.0\n", + "2 rpp -2 2 -2 2 -2 2\n", + " \n", + "*tr1 0 0.15 0 45 90 45 90 0 90 135 90 45\n", + "m1 1001 1.0\n", + " 1002 1.0\n", + ] + + # setup input + input = MCNPInput() + input.cell_list = [] + input.file_lines = input_string + input.total_num_lines = len(input_string) + input.process() + + assert len(input.surface_list) == 6 diff --git a/tests/test_mcnpmaterial.py b/tests/test_mcnpmaterial.py new file mode 100644 index 0000000..b10babb --- /dev/null +++ b/tests/test_mcnpmaterial.py @@ -0,0 +1,116 @@ +from csg2csg.MCNPMaterialCard import MCNPMaterialCard + + +def test_mcnp_material(): + string = ( + "29063 6.917000e-01 \n" + "29065.31c 3.083000e-01 \n" + ) + number = 1 + name = "M1" + matcard = MCNPMaterialCard(number, string) + + assert matcard.material_number == number + assert matcard.material_name == name + assert len(matcard.composition_dictionary) == 2 + + assert list(matcard.composition_dictionary.keys())[0] == "29063" + assert list(matcard.composition_dictionary.keys())[1] == "29065" + + assert list(matcard.composition_dictionary.values())[0] == 6.917000e-01 + assert list(matcard.composition_dictionary.values())[1] == 3.083000e-01 + + assert len(matcard.xsid_dictionary) == 2 + + assert list(matcard.xsid_dictionary.keys())[0] == "29063" + assert list(matcard.xsid_dictionary.keys())[1] == "29065" + + assert list(matcard.xsid_dictionary.values())[0] == "" + assert list(matcard.xsid_dictionary.values())[1] == "31c" + + +def test_mcnp_material_with_duplicates(): + string = ( + "29063 2.e-00 \n" + "29063 1.e-00 \n" + "29065.31c 3.083000e-01 \n" + ) + number = 1 + name = "M1" + matcard = MCNPMaterialCard(number, string) + + assert matcard.material_number == number + assert matcard.material_name == name + assert len(matcard.composition_dictionary) == 2 + + assert list(matcard.composition_dictionary.keys())[0] == "29063" + assert list(matcard.composition_dictionary.keys())[1] == "29065" + + assert list(matcard.composition_dictionary.values())[0] == 3. + assert list(matcard.composition_dictionary.values())[1] == 3.083000e-01 + + assert len(matcard.xsid_dictionary) == 2 + + assert list(matcard.xsid_dictionary.keys())[0] == "29063" + assert list(matcard.xsid_dictionary.keys())[1] == "29065" + + assert list(matcard.xsid_dictionary.values())[0] == "" + assert list(matcard.xsid_dictionary.values())[1] == "31c" + + +def test_mcnp_material_with_keywords(): + string = ( + "29063 6.917000e-01 \n" + "29065.31c 3.083000e-01 \n" + "hlib=.70h pnlib=70u" + ) + number = 1 + name = "M1" + matcard = MCNPMaterialCard(number, string) + + assert matcard.material_number == number + assert matcard.material_name == name + assert len(matcard.composition_dictionary) == 2 + + assert list(matcard.composition_dictionary.keys())[0] == "29063" + assert list(matcard.composition_dictionary.keys())[1] == "29065" + + assert list(matcard.composition_dictionary.values())[0] == 6.917000e-01 + assert list(matcard.composition_dictionary.values())[1] == 3.083000e-01 + + assert len(matcard.xsid_dictionary) == 2 + + assert list(matcard.xsid_dictionary.keys())[0], "29063" + assert list(matcard.xsid_dictionary.keys())[1], "29065" + + assert list(matcard.xsid_dictionary.values())[0] == "" + assert list(matcard.xsid_dictionary.values())[1] == "31c" + + +def test_mcnp_material_with_keyword(): + string = ( + "29063 6.917000e-01 \n" + "29065.31c 3.083000e-01 \n" + "hlib=.70h" + ) + number = 1 + name = "M1" + matcard = MCNPMaterialCard(number, string) + + assert matcard.material_number == number + assert matcard.material_name == name + assert len(matcard.composition_dictionary) == 2 + + assert list(matcard.composition_dictionary.keys())[0] == "29063" + assert list(matcard.composition_dictionary.keys())[1] == "29065" + + assert list(matcard.composition_dictionary.values())[0] == 6.917000e-01 + assert list(matcard.composition_dictionary.values())[1] == 3.083000e-01 + + assert len(matcard.xsid_dictionary) == 2 + + assert list(matcard.xsid_dictionary.keys())[0] == "29063" + assert list(matcard.xsid_dictionary.keys())[1] == "29065" + + assert list(matcard.xsid_dictionary.values())[0] == "" + assert list(matcard.xsid_dictionary.values())[1] == "31c" diff --git a/tests/test_mcnpparticle.py b/tests/test_mcnpparticle.py new file mode 100644 index 0000000..8444140 --- /dev/null +++ b/tests/test_mcnpparticle.py @@ -0,0 +1,10 @@ +from csg2csg.ParticleNames import ParticleNames +from csg2csg.MCNPParticleNames import particleToMCNP, mcnpToParticle + + +def test_generic(): + for particle in ParticleNames: + name = particleToMCNP(particle) + assert isinstance(name, str) + assert len(name) > 0 + assert mcnpToParticle(name) == particle diff --git a/tests/test_mcnpsurface.py b/tests/test_mcnpsurface.py new file mode 100644 index 0000000..fbf70e7 --- /dev/null +++ b/tests/test_mcnpsurface.py @@ -0,0 +1,176 @@ +from csg2csg.MCNPSurfaceCard import MCNPSurfaceCard, surface_has_transform +from csg2csg.SurfaceCard import SurfaceCard + + +def test_plane_x(): + card_string = "1 px 12.0" + card = MCNPSurfaceCard(card_string) + assert card.text_string == card_string + assert card.surface_type == SurfaceCard.SurfaceType["PLANE_X"] + assert card.surface_coefficients[0] == 1.0 + assert card.surface_coefficients[1] == 0.0 + assert card.surface_coefficients[2] == 0.0 + assert card.surface_coefficients[3] == 12.0 + + +def test_plane_y(): + card_string = "1 py 12.0" + card = MCNPSurfaceCard(card_string) + assert card.text_string == card_string + assert card.surface_type == SurfaceCard.SurfaceType["PLANE_Y"] + assert card.surface_coefficients[0] == 0.0 + assert card.surface_coefficients[1] == 1.0 + assert card.surface_coefficients[2] == 0.0 + assert card.surface_coefficients[3] == 12.0 + + +def test_plane_z(): + card_string = "1 pz 12.0" + card = MCNPSurfaceCard(card_string) + assert card.text_string == card_string + assert card.surface_type == SurfaceCard.SurfaceType["PLANE_Z"] + assert card.surface_coefficients[0] == 0.0 + assert card.surface_coefficients[1] == 0.0 + assert card.surface_coefficients[2] == 1.0 + assert card.surface_coefficients[3] == 12.0 + + +def test_plane_general(): + card_string = "1 p 0 0 1 15" + card = MCNPSurfaceCard(card_string) + assert card.text_string == card_string + assert card.surface_type == SurfaceCard.SurfaceType["PLANE_GENERAL"] + assert card.surface_coefficients[0] == 0.0 + assert card.surface_coefficients[1] == 0.0 + assert card.surface_coefficients[2] == 1.0 + assert card.surface_coefficients[3] == 15.0 + + +def test_sphere(): + card_string = "15 s 0 0 1 15" + card = MCNPSurfaceCard(card_string) + assert card.text_string == card_string + assert card.surface_type == SurfaceCard.SurfaceType["SPHERE_GENERAL"] + assert card.surface_coefficients[0] == 0.0 + assert card.surface_coefficients[1] == 0.0 + assert card.surface_coefficients[2] == 1.0 + assert card.surface_coefficients[3] == 15.0 + + +def test_gq(): + card_string = "15000 gq 1 1 0 0 0 0 1 1 1 1" + card = MCNPSurfaceCard(card_string) + assert card.surface_type == SurfaceCard.SurfaceType["GENERAL_QUADRATIC"] + assert card.surface_id == 15000 + assert card.surface_coefficients[0] == 1.0 + assert card.surface_coefficients[1] == 1.0 + assert card.surface_coefficients[2] == 0.0 + assert card.surface_coefficients[3] == 0.0 + assert card.surface_coefficients[4] == 0.0 + assert card.surface_coefficients[5] == 0.0 + assert card.surface_coefficients[6] == 1.0 + assert card.surface_coefficients[7] == 1.0 + assert card.surface_coefficients[8] == 1.0 + assert card.surface_coefficients[9] == 1.0 + + +def test_so(): + card_string = "15000 so 2.5" + card = MCNPSurfaceCard(card_string) + assert card.surface_type == SurfaceCard.SurfaceType["SPHERE_GENERAL"] + assert card.surface_id == 15000 + assert card.surface_coefficients[0] == 0.0 + assert card.surface_coefficients[1] == 0.0 + assert card.surface_coefficients[2] == 0.0 + assert card.surface_coefficients[3] == 2.5 + + +def test_sx(): + card_string = "15000 sx 3.0 2.5" + card = MCNPSurfaceCard(card_string) + assert card.surface_type == SurfaceCard.SurfaceType["SPHERE_GENERAL"] + assert card.surface_id == 15000 + assert card.surface_coefficients[0] == 3.0 + assert card.surface_coefficients[1] == 0.0 + assert card.surface_coefficients[2] == 0.0 + assert card.surface_coefficients[3] == 2.5 + + +def test_sy(): + card_string = "15000 sy 3.0 2.5" + card = MCNPSurfaceCard(card_string) + assert card.surface_type == SurfaceCard.SurfaceType["SPHERE_GENERAL"] + assert card.surface_id == 15000 + assert card.surface_coefficients[0] == 0.0 + assert card.surface_coefficients[1] == 3.0 + assert card.surface_coefficients[2] == 0.0 + assert card.surface_coefficients[3] == 2.5 + + +def test_cz(): + card_string = "15000 cz 2.5" + card = MCNPSurfaceCard(card_string) + assert card.surface_type == SurfaceCard.SurfaceType["CYLINDER_Z"] + assert card.surface_id == 15000 + assert card.surface_coefficients[0] == 0.0 + assert card.surface_coefficients[1] == 0.0 + assert card.surface_coefficients[2] == 2.5 + + +def test_rpp(): + card_string = "15000 rpp -1 1 -1 1 -1 1" + card = MCNPSurfaceCard(card_string) + assert card.surface_type == SurfaceCard.SurfaceType["MACRO_RPP"] + assert card.surface_id == 15000 + assert card.surface_coefficients[0] == -1.0 + assert card.surface_coefficients[1] == 1.0 + assert card.surface_coefficients[2] == -1.0 + assert card.surface_coefficients[3] == 1.0 + assert card.surface_coefficients[4] == -1.0 + assert card.surface_coefficients[5] == 1.0 + + +def test_box(): + card_string = "15000 box -1 -1 -1 2 0 0 0 2 0 0 0 2" + card = MCNPSurfaceCard(card_string) + assert card.surface_type == SurfaceCard.SurfaceType["MACRO_RPP"] + assert card.surface_id == 15000 + assert card.surface_coefficients[0] == -1.0 + assert card.surface_coefficients[1] == 1.0 + assert card.surface_coefficients[2] == -1.0 + assert card.surface_coefficients[3] == 1.0 + assert card.surface_coefficients[4] == -1.0 + assert card.surface_coefficients[5] == 1.0 + + +def test_surfacetransform_detect(): + card = "1 2 px 3" + assert surface_has_transform(card) + card = "1 PX 3" + assert not surface_has_transform(card) + + +def test_bounding_box_px(): + card_string = "1 px 3" + card = MCNPSurfaceCard(card_string) + box = card.bounding_box() + assert box[0] == 3 + assert box[1] == 3 + assert box[2] == 0 + assert box[3] == 0 + assert box[4] == 0 + assert box[5] == 0 + +# generate a bounding box for py +""" +def test_bounding_box_py(): + card_string = "1 py 3" + card = MCNPSurfaceCard(card_string) + box = card.bounding_box() + assert box[0] ==0 + assert box[1] ==0 + assert box[2] ==3 + assert box[3] ==3 + assert box[4] ==0 + assert box[5] ==0 +""" diff --git a/tests/test_particle.py b/tests/test_particle.py new file mode 100644 index 0000000..63f524c --- /dev/null +++ b/tests/test_particle.py @@ -0,0 +1,16 @@ +from csg2csg.ParticleNames import particleToGeneric, ParticleNames + + +def test_generic(): + assert particleToGeneric("NEUTRON") is None + assert "Neutron" == particleToGeneric(ParticleNames["NEUTRON"]) + assert "Electron" == particleToGeneric(ParticleNames["ELECTRON"]) + assert "Positron" == particleToGeneric(ParticleNames["POSITRON"]) + assert "Proton" == particleToGeneric(ParticleNames["PROTON"]) + assert "Deuteron" == particleToGeneric(ParticleNames["DEUTERON"]) + assert "Triton" == particleToGeneric(ParticleNames["TRITON"]) + assert "Alpha" == particleToGeneric(ParticleNames["ALPHA"]) + assert "Positive Pion" == particleToGeneric(ParticleNames["PION_PLUS"]) + assert "Negative Pion" == particleToGeneric(ParticleNames["PION_NEG"]) + assert "Helion" == particleToGeneric(ParticleNames["HELION"]) + assert "Negative Muon" == particleToGeneric(ParticleNames["MUON_NEG"]) diff --git a/tests/test_serpentmaterial.py b/tests/test_serpentmaterial.py new file mode 100644 index 0000000..1ae38dd --- /dev/null +++ b/tests/test_serpentmaterial.py @@ -0,0 +1,40 @@ +from csg2csg.SerpentMaterialCard import SerpentMaterialCard +from csg2csg.SerpentInput import SerpentInput + + +def test_serpent_material(): + string = ( + "29063 6.917000e-01 \n" + "29065.31c 3.083000e-01 \n" + ) + number = 1 + name = "copper" + density = 8.93 + matcard = SerpentMaterialCard(number, name, density, string) + + assert matcard.density == density + assert matcard.material_number == number + assert matcard.material_name == name + assert len(matcard.composition_dictionary) == 2 + + assert list(matcard.composition_dictionary.keys())[0] == "29063" + assert list(matcard.composition_dictionary.keys())[1] == "29065" + + assert list(matcard.composition_dictionary.values())[0] == 6.917000e-01 + assert list(matcard.composition_dictionary.values())[1] == 3.083000e-01 + + assert len(matcard.xsid_dictionary) == 2 + + assert list(matcard.xsid_dictionary.keys())[0] == "29063" + assert list(matcard.xsid_dictionary.keys())[1] == "29065" + + assert list(matcard.xsid_dictionary.values())[0] == "" + assert list(matcard.xsid_dictionary.values())[1] == "31c" + + +def test_serpent_mat_input(): + string = ["mat 1 8.93\n", "29063 6.917000e-01\n", "29065 3.083000e-01\n"] + + serpent = SerpentInput() + serpent.file_lines = string + serpent.process() diff --git a/tests/test_serpentsurface.py b/tests/test_serpentsurface.py new file mode 100644 index 0000000..df1c19f --- /dev/null +++ b/tests/test_serpentsurface.py @@ -0,0 +1,19 @@ +from csg2csg.MCNPSurfaceCard import MCNPSurfaceCard +from csg2csg.SerpentSurfaceCard import serpent_cone_x + + +def test_cone_x_up_write(): + card = "1 k/x 0 0 0 0.5 1" + surfcard = MCNPSurfaceCard(card) + surfcard.b_box = [0, 10, 0, 0, 0, 0] + result = serpent_cone_x(surfcard) + assert result == " ckx 0.000000 0.000000 0.000000 0.500000 1.000000\n" + + +def test_cone_x_down_write(): + card = "1 k/x 0 0 0 0.5 -1" + surfcard = MCNPSurfaceCard(card) + surfcard.b_box = [0, 0, 0, 0, 0, 0] + surfcard.b_box = [-10, 0, 0, 0, 0, 0] + result = serpent_cone_x(surfcard) + assert result == " ckx 0.000000 0.000000 0.000000 0.500000 -1.000000\n" diff --git a/tests/test_surface.py b/tests/test_surface.py new file mode 100644 index 0000000..0753a2c --- /dev/null +++ b/tests/test_surface.py @@ -0,0 +1,106 @@ +from csg2csg.SurfaceCard import SurfaceCard + + +def test_simplify_plane_to_plane(): + surface = SurfaceCard("") + surface_coefficients = [1.0, 1.0, 0.0, 10.0] + transform_id = 0 + surface_type = surface.SurfaceType["PLANE_GENERAL"] + surface_id = 1 + surface.set_type(surface_id, transform_id, surface_type, surface_coefficients) + surface.simplify() + assert surface.surface_type == surface.SurfaceType["PLANE_GENERAL"] + + +def test_simplify_gq_to_plane(): + surface = SurfaceCard("") + surface_coefficients = [0, 0, 0, 0, 0, 0, 1.0, 1.0, 0.0, -10.0] + transform_id = 0 + surface_type = surface.SurfaceType["GENERAL_QUADRATIC"] + surface_id = 1 + surface.set_type(surface_id, transform_id, surface_type, surface_coefficients) + surface.simplify() + assert surface.surface_type == surface.SurfaceType["PLANE_GENERAL"] + + +def test_generalise(): + surface = SurfaceCard("") + surface_coefficients = [1.0, 1.0, 0.0, -10.0] + transform_id = 0 + surface_type = surface.SurfaceType["PLANE_GENERAL"] + surface_id = 1 + surface.set_type(surface_id, transform_id, surface_type, surface_coefficients) + surface.generalise() + assert surface.surface_type == surface.SurfaceType["GENERAL_QUADRATIC"] + for i in range(6): + assert surface.surface_coefficients[i] == 0.0 + + +def test_generalise_simplify_general_plane(): + surface = SurfaceCard("") + surface_coefficients = [1.0, 1.0, 0.0, -10.0] + transform_id = 0 + surface_type = surface.SurfaceType["PLANE_GENERAL"] + surface_id = 1 + surface.set_type(surface_id, transform_id, surface_type, surface_coefficients) + surface.generalise() + assert surface.surface_type == surface.SurfaceType["GENERAL_QUADRATIC"] + for i in range(6): + assert surface.surface_coefficients[i] == 0.0 + surface.simplify() + # make sure we get a general plane back + assert surface.surface_type == surface.SurfaceType["PLANE_GENERAL"] + assert surface.surface_coefficients[0] == 1.0 + assert surface.surface_coefficients[1] == 1.0 + assert surface.surface_coefficients[2] == 0.0 + assert surface.surface_coefficients[3] == -10.0 + + +# test the surface.generalise() function +def test_surface_generalise(): + # first surface + surface1 = SurfaceCard("") + surface_coefficients = [1.0, 0.0, 0.0, -10.0] + transform_id = 0 + surface_type = surface1.SurfaceType["PLANE_GENERAL"] + surface_id = 1 + surface1.set_type(surface_id, transform_id, surface_type, surface_coefficients) + surface1.generalise() + assert surface1.surface_coefficients[6] == 1.0 + assert surface1.surface_coefficients[9] == 10.0 + + +# test the surface.reverse() function +def test_surface_reverse(): + # first surface + surface1 = SurfaceCard("") + surface_coefficients = [1.0, 0.0, 0.0, -10.0] + transform_id = 0 + surface_type = surface1.SurfaceType["PLANE_GENERAL"] + surface_id = 1 + surface1.set_type(surface_id, transform_id, surface_type, surface_coefficients) + surface1.generalise() + surface1.reverse() + assert surface1.surface_coefficients[6] == -1.0 + assert surface1.surface_coefficients[9] == -10.0 + + +def test_surface_two_planes_compare(): + # first surface + surface1 = SurfaceCard("") + surface_coefficients = [1.0, 0.0, 0.0, 10.0] + transform_id = 0 + surface_type = surface1.SurfaceType["PLANE_GENERAL"] + surface_id = 1 + surface1.set_type(surface_id, transform_id, surface_type, surface_coefficients) + + # second surface + surface2 = SurfaceCard("") + surface_coefficients = [-1.0, 0.0, 0.0, -10.0] + transform_id = 0 + surface_type = surface2.SurfaceType["PLANE_GENERAL"] + surface_id = 2 + surface2.set_type(surface_id, transform_id, surface_type, surface_coefficients) + + assert surface1.diff(surface2, False) == (False, False) + assert surface1.diff(surface2) == (True, True) diff --git a/tests/test_vector.py b/tests/test_vector.py new file mode 100644 index 0000000..1e0112f --- /dev/null +++ b/tests/test_vector.py @@ -0,0 +1,31 @@ +from csg2csg.Vector import add, cross, subtract + + +def test_subtract(): + a = [1, 0, 0] + b = [1, 0, 0] + c = subtract(a, b) + + assert c[0] == 0.0 + assert c[1] == 0.0 + assert c[2] == 0.0 + + +def test_add(): + a = [1, 0, 0] + b = [0, 1, 0] + c = add(a, b) + + assert c[0] == 1.0 + assert c[1] == 1.0 + assert c[2] == 0.0 + + +def test_cross(): + a = [1, 0, 0] + b = [0, 1, 0] + c = cross(a, b) + + assert c[0] == 0.0 + assert c[1] == 0.0 + assert c[2] == 1.0