From 516d0aca07269f106832dec1c478e0d17abe7d45 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 6 Nov 2024 22:15:14 -0600 Subject: [PATCH 1/6] Adding block for positive side of spheres and adding a nested spheres test --- src/openmc_cad_adapter/surfaces.py | 5 +++++ test/gold/nested_spheres.jou | 28 ++++++++++++++++++++++++++++ test/test_local.py | 14 ++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 test/gold/nested_spheres.jou diff --git a/src/openmc_cad_adapter/surfaces.py b/src/openmc_cad_adapter/surfaces.py index 434bd4d..bc84384 100644 --- a/src/openmc_cad_adapter/surfaces.py +++ b/src/openmc_cad_adapter/surfaces.py @@ -283,6 +283,11 @@ def to_cubit_surface_inner(self, ent_type, node, extents, inner_world=None, hex= cad_cmds.append( f"sphere radius {self.r}") ids = emit_get_last_id(ent_type, cad_cmds) move(ids, self.x0, self.y0, self.z0, cad_cmds) + if node.side != '-': + cad_cmds.append( f"brick x {extents[0]} y {extents[1]} z {extents[2]}" ) + wid = emit_get_last_id( ent_type , cad_cmds) + cad_cmds.append(f"subtract body {{ {ids} }} from body {{ {wid} }}") + ids = wid return ids, cad_cmds @classmethod diff --git a/test/gold/nested_spheres.jou b/test/gold/nested_spheres.jou new file mode 100644 index 0000000..e2115a6 --- /dev/null +++ b/test/gold/nested_spheres.jou @@ -0,0 +1,28 @@ +set echo off +set info off +set warning off +graphics pause +set journal off +set default autosize off +#CELL 4 +sphere radius 30.0 +#{ id1 = Id("body") } +body { id1 } name "Cell_4" +group "mat:void" add body { id1 } +#CELL 3 +sphere radius 20.0 +#{ id2 = Id("body") } +body { id2 } name "Cell_3" +group "mat:void" add body { id2 } +#CELL 2 +sphere radius 10.0 +#{ id3 = Id("body") } +body { id3 } name "Cell_2" +group "mat:void" add body { id3 } +graphics flush +set default autosize on +zoom reset +set echo on +set info on +set warning on +set journal on diff --git a/test/test_local.py b/test/test_local.py index d17d551..4e7feb9 100644 --- a/test/test_local.py +++ b/test/test_local.py @@ -34,6 +34,20 @@ def test_planes(request, run_in_tmpdir): diff_gold_file('plane.jou') +def test_nested_spheres(request, run_in_tmpdir): + inner_sphere = openmc.Sphere(r=10.0) + middle_sphere = openmc.Sphere(r=20.0) + outer_sphere = openmc.Sphere(r=30.0) + + inner_cell = openmc.Cell(region=-inner_sphere) + middle_cell = openmc.Cell(region=-middle_sphere) + outer_cell = openmc.Cell(region=-outer_sphere) + + g = openmc.Geometry([outer_cell, middle_cell, inner_cell]) + to_cubit_journal(g, world=(500, 500, 500), filename='nested_spheres.jou') + diff_gold_file('nested_spheres.jou') + + # Test the XCylinder and YCylinder classes, the ZCylinder surface is tested # extensively in the OpenMC example tests @reset_openmc_ids From 983bb3da55d4c0f9a5d61701122673a583201873 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Wed, 6 Nov 2024 22:17:47 -0600 Subject: [PATCH 2/6] Adding openmc id reset decorator --- test/gold/nested_spheres.jou | 12 ++++++------ test/test_local.py | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/test/gold/nested_spheres.jou b/test/gold/nested_spheres.jou index e2115a6..3dffddc 100644 --- a/test/gold/nested_spheres.jou +++ b/test/gold/nested_spheres.jou @@ -4,20 +4,20 @@ set warning off graphics pause set journal off set default autosize off -#CELL 4 +#CELL 3 sphere radius 30.0 #{ id1 = Id("body") } -body { id1 } name "Cell_4" +body { id1 } name "Cell_3" group "mat:void" add body { id1 } -#CELL 3 +#CELL 2 sphere radius 20.0 #{ id2 = Id("body") } -body { id2 } name "Cell_3" +body { id2 } name "Cell_2" group "mat:void" add body { id2 } -#CELL 2 +#CELL 1 sphere radius 10.0 #{ id3 = Id("body") } -body { id3 } name "Cell_2" +body { id3 } name "Cell_1" group "mat:void" add body { id3 } graphics flush set default autosize on diff --git a/test/test_local.py b/test/test_local.py index 4e7feb9..d6f4a15 100644 --- a/test/test_local.py +++ b/test/test_local.py @@ -34,6 +34,7 @@ def test_planes(request, run_in_tmpdir): diff_gold_file('plane.jou') +@reset_openmc_ids def test_nested_spheres(request, run_in_tmpdir): inner_sphere = openmc.Sphere(r=10.0) middle_sphere = openmc.Sphere(r=20.0) From 4d969681e09541931171ca352df273ab2bb3a2cf Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 7 Nov 2024 10:58:36 -0600 Subject: [PATCH 3/6] Update test/test_local.py Co-authored-by: Ethan Peterson --- test/test_local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_local.py b/test/test_local.py index d6f4a15..d6487c3 100644 --- a/test/test_local.py +++ b/test/test_local.py @@ -42,7 +42,7 @@ def test_nested_spheres(request, run_in_tmpdir): inner_cell = openmc.Cell(region=-inner_sphere) middle_cell = openmc.Cell(region=-middle_sphere) - outer_cell = openmc.Cell(region=-outer_sphere) + outer_cell = openmc.Cell(region=+middle_sphere & -outer_sphere) g = openmc.Geometry([outer_cell, middle_cell, inner_cell]) to_cubit_journal(g, world=(500, 500, 500), filename='nested_spheres.jou') From 4ff7f5a697d2b3c15b6c56978939c74d54605ad1 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 7 Nov 2024 10:58:41 -0600 Subject: [PATCH 4/6] Update test/test_local.py Co-authored-by: Ethan Peterson --- test/test_local.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_local.py b/test/test_local.py index d6487c3..a09cd3f 100644 --- a/test/test_local.py +++ b/test/test_local.py @@ -41,7 +41,7 @@ def test_nested_spheres(request, run_in_tmpdir): outer_sphere = openmc.Sphere(r=30.0) inner_cell = openmc.Cell(region=-inner_sphere) - middle_cell = openmc.Cell(region=-middle_sphere) + middle_cell = openmc.Cell(region=+inner_sphere & -middle_sphere) outer_cell = openmc.Cell(region=+middle_sphere & -outer_sphere) g = openmc.Geometry([outer_cell, middle_cell, inner_cell]) From 5ead7f1fbcfc3a5a05aab22b13a40d9c9d3a459c Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 7 Nov 2024 11:05:42 -0600 Subject: [PATCH 5/6] Updating the nested spheres gold file now that they are actually nested spheres. --- test/gold/nested_spheres.jou | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/test/gold/nested_spheres.jou b/test/gold/nested_spheres.jou index 3dffddc..cba93a3 100644 --- a/test/gold/nested_spheres.jou +++ b/test/gold/nested_spheres.jou @@ -5,20 +5,38 @@ graphics pause set journal off set default autosize off #CELL 3 -sphere radius 30.0 +sphere radius 20.0 #{ id1 = Id("body") } -body { id1 } name "Cell_3" -group "mat:void" add body { id1 } +brick x 500 y 500 z 500 +#{ id2 = Id("body") } +subtract body { id1 } from body { id2 } +sphere radius 30.0 +#{ id3 = Id("body") } +#{ id4 = Id("body") } +intersect body { id2 } { id3 } +#{ id5 = Id("body") } +#{id6 = ( id4 == id5 ) ? id3 : id5} +body { id6 } name "Cell_3" +group "mat:void" add body { id6 } #CELL 2 +sphere radius 10.0 +#{ id7 = Id("body") } +brick x 500 y 500 z 500 +#{ id8 = Id("body") } +subtract body { id7 } from body { id8 } sphere radius 20.0 -#{ id2 = Id("body") } -body { id2 } name "Cell_2" -group "mat:void" add body { id2 } +#{ id9 = Id("body") } +#{ id10 = Id("body") } +intersect body { id8 } { id9 } +#{ id11 = Id("body") } +#{id12 = ( id10 == id11 ) ? id9 : id11} +body { id12 } name "Cell_2" +group "mat:void" add body { id12 } #CELL 1 sphere radius 10.0 -#{ id3 = Id("body") } -body { id3 } name "Cell_1" -group "mat:void" add body { id3 } +#{ id13 = Id("body") } +body { id13 } name "Cell_1" +group "mat:void" add body { id13 } graphics flush set default autosize on zoom reset From e2a95d38cfc60f52608033c31de0b8ebc9a103c6 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 7 Nov 2024 11:07:31 -0600 Subject: [PATCH 6/6] Ensuring all tests are run in CI --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b82ad90..0cd30cc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,7 +34,7 @@ jobs: - name: Test examples run: | micromamba activate test-env - OPENMC_EXAMPLES_DIR=$HOME/openmc/examples pytest -v ./test/test_examples.py + OPENMC_EXAMPLES_DIR=$HOME/openmc/examples pytest -v ./test - name: Setup tmate session if: ${{ failure() }}