diff --git a/src/openmc_cad_adapter/surfaces.py b/src/openmc_cad_adapter/surfaces.py index bc84384..6d7f8ae 100644 --- a/src/openmc_cad_adapter/surfaces.py +++ b/src/openmc_cad_adapter/surfaces.py @@ -307,17 +307,21 @@ class CADXCone(CADSurface, openmc.XCone): def to_cubit_surface_inner(self, ent_type, node, extents, inner_world=None, hex=False): cad_cmds = [] - cad_cmds.append( f"create frustum height {extents[0]} radius {math.sqrt(self.coefficients['r2']*extents[0])} top 0") - ids = emit_get_last_id( ent_type , cad_cmds) + cad_cmds.append( f"create frustum height {extents[0]} radius {math.sqrt(self.coefficients['r2'])*extents[0]} top 0") + ids = emit_get_last_id(ent_type, cad_cmds) + cad_cmds.append(f"body {{ {ids} }} move 0 0 -{extents[0]/2.0}") + cad_cmds.append(f"body {{ {ids} }} copy reflect z") + ids2 = emit_get_last_id(ent_type, cad_cmds) + cad_cmds.append(f"unite body {{ {ids} }} {{ {ids2} }}") cad_cmds.append( f"rotate body {{ {ids} }} about y angle 90") + x0, y0, z0 = self.coefficients['x0'], self.coefficients['y0'], self.coefficients['z0'] + cad_cmds.append(f"body {{ {ids} }} move {x0} {y0} {z0}") + 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) + wid = emit_get_last_id(ent_type , cad_cmds) cad_cmds.append(f"subtract body {{ {ids} }} from body {{ {wid} }}") - move(wid, self.coefficients['x0'], self.coefficients['y0'], self.coefficients['z0'], cad_cmds) ids = wid - else: - move(ids, self.coefficients['x0'], self.coefficients['y0'], self.coefficients['z0'], cad_cmds) return ids, cad_cmds @classmethod @@ -329,17 +333,21 @@ class CADYCone(CADSurface, openmc.YCone): def to_cubit_surface_inner(self, ent_type, node, extents, inner_world=None, hex=False): cad_cmds = [] - cad_cmds.append( f"create frustum height {extents[1]} radius {math.sqrt(self.coefficients['r2']*extents[1])} top 0") + cad_cmds.append( f"create frustum height {extents[1]} radius {math.sqrt(self.coefficients['r2'])*extents[1]} top 0") ids = emit_get_last_id(ent_type, cad_cmds) + cad_cmds.append(f"body {{ {ids} }} move 0 0 -{extents[1]/2.0}") + cad_cmds.append(f"body {{ {ids} }} copy reflect z") + ids2 = emit_get_last_id(ent_type, cad_cmds) + cad_cmds.append(f"unite body {{ {ids} }} {{ {ids2} }}") cad_cmds.append( f"rotate body {{ {ids} }} about x angle 90") + x0, y0, z0 = self.coefficients['x0'], self.coefficients['y0'], self.coefficients['z0'] + cad_cmds.append(f"body {{ {ids} }} move {x0} {y0} {z0}") + 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) + wid = emit_get_last_id(ent_type , cad_cmds) cad_cmds.append(f"subtract body {{ {ids} }} from body {{ {wid} }}") - move(wid, self.coefficients['x0'], self.coefficients['y0'], self.coefficients['z0'], cad_cmds) ids = wid - else: - move(ids, self.coefficients['x0'], self.coefficients['y0'], self.coefficients['z0'], cad_cmds) return ids, cad_cmds @classmethod @@ -351,16 +359,20 @@ class CADZCone(CADSurface, openmc.ZCone): def to_cubit_surface_inner(self, ent_type, node, extents, inner_world=None, hex=False): cad_cmds = [] - cad_cmds.append( f"create frustum height {extents[2]} radius {math.sqrt(self.coefficients['r2']*extents[2])} top 0") + cad_cmds.append( f"create frustum height {extents[2]} radius {math.sqrt(self.coefficients['r2'])*extents[2]} top 0") ids = emit_get_last_id(ent_type, cad_cmds) + cad_cmds.append(f"body {{ {ids} }} move 0 0 -{extents[2]/2.0}") + cad_cmds.append(f"body {{ {ids} }} copy reflect z") + ids2 = emit_get_last_id(ent_type, cad_cmds) + cad_cmds.append(f"unite body {{ {ids} }} {{ {ids2} }}") + x0, y0, z0 = self.coefficients['x0'], self.coefficients['y0'], self.coefficients['z0'] + cad_cmds.append(f"body {{ {ids} }} move {x0} {y0} {z0}") + 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} }}") - move(wid, self.coefficients['x0'], self.coefficients['y0'], self.coefficients['z0'], cad_cmds) ids = wid - else: - move(ids, self.coefficients['x0'], self.coefficients['y0'], self.coefficients['z0'], cad_cmds) return ids, cad_cmds @classmethod @@ -437,4 +449,4 @@ def to_cubit_surface_inner(self, ent_type, node, extents, inner_world=None, hex= _CAD_SURFACES = [CADPlane, CADXPlane, CADYPlane, CADZPlane, CADCylinder, CADXCylinder, CADYCylinder, CADZCylinder, CADSphere, CADXCone, CADYCone, CADZCone, CADXTorus, CADYTorus, CADZTorus] -_CAD_SURFACE_DICTIONARY = {s._type: s for s in _CAD_SURFACES} \ No newline at end of file +_CAD_SURFACE_DICTIONARY = {s._type: s for s in _CAD_SURFACES} diff --git a/test/gold/x_cone.jou b/test/gold/x_cone.jou index 9652ae6..62ab731 100644 --- a/test/gold/x_cone.jou +++ b/test/gold/x_cone.jou @@ -5,8 +5,12 @@ graphics pause set journal off set default autosize off #CELL 1 -create frustum height 500 radius 50.0 top 0 +create frustum height 500 radius 1118.033988749895 top 0 #{ id1 = Id("body") } +body { id1 } move 0 0 -250.0 +body { id1 } copy reflect z +#{ id2 = Id("body") } +unite body { id1 } { id2 } rotate body { id1 } about y angle 90 body { id1 } move 30.0 3.0 5.0 body { id1 } name "Cell_1" diff --git a/test/gold/y_cone.jou b/test/gold/y_cone.jou index 10701a7..c41c73a 100644 --- a/test/gold/y_cone.jou +++ b/test/gold/y_cone.jou @@ -5,8 +5,12 @@ graphics pause set journal off set default autosize off #CELL 1 -create frustum height 500 radius 31.622776601683793 top 0 +create frustum height 500 radius 707.1067811865476 top 0 #{ id1 = Id("body") } +body { id1 } move 0 0 -250.0 +body { id1 } copy reflect z +#{ id2 = Id("body") } +unite body { id1 } { id2 } rotate body { id1 } about x angle 90 body { id1 } move 40.0 20.0 7.0 body { id1 } name "Cell_1" diff --git a/test/gold/z_cone.jou b/test/gold/z_cone.jou index 6b5c518..ecb6b4c 100644 --- a/test/gold/z_cone.jou +++ b/test/gold/z_cone.jou @@ -5,8 +5,12 @@ graphics pause set journal off set default autosize off #CELL 1 -create frustum height 500 radius 22.360679774997898 top 0 +create frustum height 500 radius 250.0 top 0 #{ id1 = Id("body") } +body { id1 } move 0 0 -250.0 +body { id1 } copy reflect z +#{ id2 = Id("body") } +unite body { id1 } { id2 } body { id1 } move 50.0 10.0 2.0 body { id1 } name "Cell_1" group "mat:void" add body { id1 } diff --git a/test/test_local.py b/test/test_local.py index a09cd3f..d615f84 100644 --- a/test/test_local.py +++ b/test/test_local.py @@ -93,7 +93,7 @@ def test_y_cone(request, run_in_tmpdir): @reset_openmc_ids def test_z_cone(request, run_in_tmpdir): - z_cone = openmc.ZCone(x0=50.0, y0=10.0, z0=2.0, r2=1.0) + z_cone = openmc.ZCone(x0=50.0, y0=10.0, z0=2.0, r2=0.25) g = openmc.Geometry([openmc.Cell(region=-z_cone)]) to_cubit_journal(g, world=(500, 500, 500), filename='z_cone.jou') diff_gold_file('z_cone.jou')