Skip to content

Commit

Permalink
Refs #95. Checkpointing creating simulation IDF for VULCAN-X phase 1 …
Browse files Browse the repository at this point in the history
…and the complete version.
  • Loading branch information
wdzhou committed Sep 27, 2018
1 parent 80b2951 commit 96a7e9b
Show file tree
Hide file tree
Showing 2 changed files with 223 additions and 33 deletions.
43 changes: 19 additions & 24 deletions vulcan_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def add_tube_type(root, pixel_height, num_pixels):
:return:
"""
# define type as root
type_element = le.SubElement(root, "type", name='tube', outline='yes')
type_element = le.SubElement(root, "type", name='tube{}'.format(num_pixels), outline='yes')
le.SubElement(type_element, "properties")

# add component
Expand Down Expand Up @@ -109,18 +109,15 @@ def add_banks_type(self, root, name, components):

def add_bank(self, root, name, component_name, x, y, z, rot):
"""
Args:
root:
name:
component_name:
x:
y:
z:
rot:
Returns:
add a bank
:param root:
:param name:
:param component_name:
:param x:
:param y:
:param z:
:param rot: rotation angle in degree
:return:
"""
# type
pack_root = le.SubElement(root, 'type', name=name)
Expand All @@ -131,21 +128,19 @@ def add_bank(self, root, name, component_name, x, y, z, rot):

return

def add_n_8packs_type(self, root, name, num_tubes, tube_x):
"""
Args:
name:
num_tubes:
tube_x:
Returns:
def add_n_8packs_type(self, root, name, num_tubes, tube_x, num_tube_pixels):
""" add an N x 8packs type
:param root:
:param name:
:param num_tubes:
:param tube_x:
:param num_tube_pixels: number of tubes in order to s
:return:
"""
packs_root = le.SubElement(root, 'type', name=name)
le.SubElement(packs_root, 'properties')

comp_root = le.SubElement(packs_root, 'component', type='tube')
comp_root = le.SubElement(packs_root, 'component', type='tube{}'.format(num_tube_pixels))

tube_x_pos = (-num_tubes/2)*tube_x + tube_x * 0.5
for tube_index in range(1, num_tubes + 1):
Expand Down
213 changes: 204 additions & 9 deletions vulcan_x_geometry.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# This is the geometry/IDF generator for VULCAN-X
from vulcan_geometry import VulcanGeomIDF
import math


# Define pixel ID gap between 2 adjacent 8 packs in a same group
GAP = 10
Expand Down Expand Up @@ -82,7 +84,7 @@ def __init__(self, from_date, to_date):

return

def build_instrument(self):
def build_prototype_instrument(self):
""" Build instrument
Returns:
"""
Expand Down Expand Up @@ -138,13 +140,185 @@ def build_instrument(self):

return

def export_idf(self, out_file_name):
""" Export IDF
Args:
out_file_name:
def build_vulcan_x_phase1(self):
"""
build the IDF for VULCAN-X of phase 1 such that it will have 3 banks: west/east/high angle
:return:
"""
# source
self._vulcan.addComment("SOURCE")
self._vulcan.addModerator(VULCAN_L1)
# sample
self._vulcan.addComment("SAMPLE")
self._vulcan.addSamplePosition()
# monitor
self._vulcan.addComment("MONITORS")
self._vulcan.add_monitor_type(self._geom_root)
# self._vulcan.addMonitors(distance=[-1.5077], names=["monitor1"])

Returns:
# add detectors
self._vulcan.addComment('Define detector banks')
self._vulcan.addComponent(type_name='detectors', idlist='detectors')
# define detector type
self._vulcan.add_banks_type(root=self._geom_root, name='detectors', components=['bank1']) #, 'bank4'])

# west bank
self._vulcan.addComment('Define West Bank')
self._vulcan.add_bank(root=self._geom_root, name='bank1', component_name='pack_160tubes',
x=2.0, y=0., z=0., rot=90)

# east bank
self._vulcan.addComment('Define West Bank')
self._vulcan.add_bank(root=self._geom_root, name='bank2', component_name='pack_160tubes',
x=-2.0, y=0., z=0., rot=-90)

# high angle bank
self._vulcan.addComment('Define High Angle Bank')
self._vulcan.add_bank(root=self._geom_root, name='bank5', component_name='pack_72tubes',
x=2.*math.sin(150.*math.pi/180.), y=0., z=2.*math.cos(150.*math.pi/180.), rot=150.)

# 20 x 8 packs
self._vulcan.addComment('20 x standard 8 packs')
self._vulcan.add_n_8packs_type(self._geom_root, name='pack_160tubes', num_tubes=160, tube_x=0.01,
num_tube_pixels=512)

# single tube
self._vulcan.add_tube_type(self._geom_root, num_pixels=512, pixel_height=0.0063578125)

# 9 x 8 packs
self._vulcan.addComment('9 x standard 8 packs')
self._vulcan.add_n_8packs_type(self._geom_root, name='pack_72tubes', num_tubes=72, tube_x=0.01,
num_tube_pixels=256)

# single tube
self._vulcan.add_tube_type(self._geom_root, num_pixels=256, pixel_height=0.0063578125)

# single pixel
self._vulcan.addComment('Cylinder Pixel In Tube')
self._vulcan.add_cylinder_pixel(self._geom_root, axis=(0, 1, 0), radius=0.0047, height=0.0063578125)

# monitor shape
self._vulcan.addComment('MONITOR SHAPE')
self._vulcan.add_cylinder_pixel(self._geom_root, axis=(0, 0, 1), radius=0.0047, height=0.008, is_monitor=True)

# define detector IDs
self._vulcan.addComment('DETECTOR IDs')
num_pixels = 2 * 20 * 8 * 512 + 9 * 8 * 256
self._vulcan.define_id_list(self._geom_root, id_name='detectors', start_id=0, end_id=num_pixels-1)

# define monitor IDs
self._vulcan.addComment('MONITOR IDs')
self._vulcan.define_id_list(self._geom_root, id_name='monitors', start_id=None, end_id=None)

# define detector parameters
self._vulcan.addComment('DETECTOR PARAMETERS')
self._vulcan.define_detector_parameters(self._geom_root)

return

def build_complete_vulcan_x(self):
"""
build the IDF for VULCAN-X of phase 1 such that it will have 3 banks: west/east/high angle
:return:
"""
# source
self._vulcan.addComment("SOURCE")
self._vulcan.addModerator(VULCAN_L1)
# sample
self._vulcan.addComment("SAMPLE")
self._vulcan.addSamplePosition()
# monitor
self._vulcan.addComment("MONITORS")
self._vulcan.add_monitor_type(self._geom_root)
# self._vulcan.addMonitors(distance=[-1.5077], names=["monitor1"])

# add detectors
self._vulcan.addComment('Define detector banks')
self._vulcan.addComponent(type_name='detectors', idlist='detectors')
# define detector type
self._vulcan.add_banks_type(root=self._geom_root, name='detectors', components=['bank1']) #, 'bank4'])

# west bank: bank 1
self._vulcan.addComment('Define Bank 1/West Bank')
self._vulcan.add_bank(root=self._geom_root, name='bank1', component_name='pack_160tubes',
x=2.0, y=0., z=0., rot=90)

# east bank: bank 2
self._vulcan.addComment('Define Bank 2/East Bank')
self._vulcan.add_bank(root=self._geom_root, name='bank2', component_name='pack_160tubes',
x=-2.0, y=0., z=0., rot=-90)

# bank 3 @ 135
bank_angle = 135.
self._vulcan.addComment('Define Bank 3')
self._vulcan.add_bank(root=self._geom_root, name='bank3', component_name='pack_160tubes',
x=2.0*math.sin(bank_angle*math.pi/180.), y=0., z=2.*math.cos(bank_angle*math.pi/180.),
rot=bank_angle)

# bank 4 @ 155
bank_angle = 155.
self._vulcan.addComment('Define Bank 4')
self._vulcan.add_bank(root=self._geom_root, name='bank4', component_name='pack_160tubes',
x=2.0*math.sin(bank_angle*math.pi/180.), y=0., z=2.*math.cos(bank_angle*math.pi/180.),
rot=bank_angle)

# bank 5 (old) high angle bank @ -150
bank5_angle = -150.
self._vulcan.addComment('Define High Angle Bank at {}'.format(bank5_angle))
self._vulcan.add_bank(root=self._geom_root, name='bank5', component_name='pack_72tubes',
x=2.*math.sin(bank5_angle*math.pi/180.), y=0., z=2.*math.cos(bank5_angle*math.pi/180.),
rot=bank5_angle)

# bank 6:
bank6_angle = -120.
self._vulcan.addComment('Define Bank 6 at {}'.format(bank6_angle))
self._vulcan.add_bank(root=self._geom_root, name='bank6', component_name='pack_160tubes',
x=2.*math.sin(bank6_angle*math.pi/180.), y=0., z=2.*math.cos(bank6_angle*math.pi/180.),
rot=bank6_angle)

# 20 x 8 packs
self._vulcan.addComment('20 x standard 8 packs')
self._vulcan.add_n_8packs_type(self._geom_root, name='pack_160tubes', num_tubes=160, tube_x=0.01,
num_tube_pixels=512)

# single tube
self._vulcan.add_tube_type(self._geom_root, num_pixels=512, pixel_height=0.0063578125)

# 9 x 8 packs
self._vulcan.addComment('9 x standard 8 packs')
self._vulcan.add_n_8packs_type(self._geom_root, name='pack_72tubes', num_tubes=72, tube_x=0.01,
num_tube_pixels=256)

# single tube
self._vulcan.add_tube_type(self._geom_root, num_pixels=256, pixel_height=0.0063578125)

# single pixel
self._vulcan.addComment('Cylinder Pixel In Tube')
self._vulcan.add_cylinder_pixel(self._geom_root, axis=(0, 1, 0), radius=0.0047, height=0.0063578125)

# monitor shape
self._vulcan.addComment('MONITOR SHAPE')
self._vulcan.add_cylinder_pixel(self._geom_root, axis=(0, 0, 1), radius=0.0047, height=0.008, is_monitor=True)

# define detector IDs
self._vulcan.addComment('DETECTOR IDs')
num_pixels = 5 * 20 * 8 * 512 + 9 * 8 * 256
self._vulcan.define_id_list(self._geom_root, id_name='detectors', start_id=0, end_id=num_pixels - 1)

# define monitor IDs
self._vulcan.addComment('MONITOR IDs')
self._vulcan.define_id_list(self._geom_root, id_name='monitors', start_id=None, end_id=None)

# define detector parameters
self._vulcan.addComment('DETECTOR PARAMETERS')
self._vulcan.define_detector_parameters(self._geom_root)

return

def export_idf(self, out_file_name):
""" Export the built instrument to a Mantid IDF file
:param out_file_name:
:return:
"""
self._vulcan.writeGeom(out_file_name)

Expand All @@ -153,7 +327,28 @@ def export_idf(self, out_file_name):
# END-DEF-CLASS


def main():
"""
:return:
"""
if False:
# prototype
vulcan_simulator = SimulationVulcanXIDFGenerator('2017-03-01 00:00:01', '2020-12-31 00:00:01')
vulcan_simulator.build_prototype_instrument()
vulcan_simulator.export_idf('prototype_vulcan_x_sim.xml')

elif True:
# phase 1
vulcan_simulator = SimulationVulcanXIDFGenerator('2017-03-01 00:00:01', '2020-12-31 00:00:01')
vulcan_simulator.build_vulcan_x_phase1()
vulcan_simulator.export_idf('vulcan_x_phase1_sim.xml')

else:
# final phase
vulcan_simulator = SimulationVulcanXIDFGenerator('2017-03-01 00:00:01', '2020-12-31 00:00:01')
vulcan_simulator.build_complete_vulcan_x()
vulcan_simulator.export_idf('vulcan_x_complete_sim.xml')


if __name__ == '__main__':
vulcan_simulator = SimulationVulcanXIDFGenerator('2017-03-01 00:00:01', '2020-12-31 00:00:01')
vulcan_simulator.build_instrument()
vulcan_simulator.export_idf('vulcan_x_sim.xml')
main()

0 comments on commit 96a7e9b

Please sign in to comment.