Skip to content

Commit

Permalink
Merge pull request #16 from eepeterson/cone_fix
Browse files Browse the repository at this point in the history
Cone fix
  • Loading branch information
pshriwise authored Nov 20, 2024
2 parents 70fea9a + 1cc2815 commit b238869
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 20 deletions.
44 changes: 28 additions & 16 deletions src/openmc_cad_adapter/surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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}
_CAD_SURFACE_DICTIONARY = {s._type: s for s in _CAD_SURFACES}
6 changes: 5 additions & 1 deletion test/gold/x_cone.jou
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion test/gold/y_cone.jou
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion test/gold/z_cone.jou
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
2 changes: 1 addition & 1 deletion test/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit b238869

Please sign in to comment.