Ejemplo n.º 1
0
def test_all_shapes():
    g = construct.Geometry()
    #Box
    s = g.shapes.Box('Box')
    print('Box:', s)
    #TwistedBox
    s = g.shapes.TwistedBox('TwistedBox')
    print('TwistedBox:', s)
    #Tubs
    s = g.shapes.Tubs('Tubs')
    print('Tubs:', s)
    #Sphere
    s = g.shapes.Sphere('Sphere')
    print('Sphere:', s)
    #Cone
    s = g.shapes.Cone('Cone')
    print('Cone:', s)
    #Trapezoid
    s = g.shapes.Trapezoid('Trapezoid')
    print('Trapezoid:', s)
    #TwistedTrap
    s = g.shapes.TwistedTrap('TwistedTrap')
    print('TwistedTrap:', s)
    #TwistedTrd
    s = g.shapes.TwistedTrd('TwistedTrd')
    print('TwistedTrd:', s)
    #Paraboloid
    s = g.shapes.Paraboloid('Paraboloid')
    print('Paraboloid:', s)
    #Ellipsoid
    s = g.shapes.Ellipsoid('Ellipsoid')
    print('Ellipsoid:', s)
    #PolyhedraRegular
    s = g.shapes.PolyhedraRegular('PolyhedraRegular')
    print('PolyhedraRegular:', s)
Ejemplo n.º 2
0
def airwaterboxes():
    g = construct.Geometry()
    h = g.matter.Element("Hydrogen", "H", 1, "1.01g/mole")
    n = g.matter.Element("Nitrogen", "N", 7, "14.01*g/mole")
    o = g.matter.Element("Oxygen", "O", 8, "16.0g/mole")
    water = g.matter.Molecule("Water",
                              density="1.0kg/l",
                              elements=(("Oxygen", 1), ("Hydrogen", 2)))
    air = g.matter.Mixture("Air",
                           density="1.290*mg/cc",
                           components=(("Nitrogen", 0.7), ("Oxygen", 0.3)))

    U235 = g.matter.Isotope("U235", z=92, ia=235, a="235.0439242 g/mole")
    U238 = g.matter.Isotope("U238", z=92, ia=238, a="238.0507847 g/mole")
    enriched_uranium = g.matter.Composition("enriched_U",
                                            symbol="U",
                                            isotopes=(("U235", 0.8), ("U238",
                                                                      0.2)))

    box1 = g.shapes.Box("box1", '1cm', '2cm', '3cm')
    box2 = g.shapes.Box("box2", '1m', '2m', '3m')
    pos = g.structure.Position(None, '1cm', z='2cm')
    rot = g.structure.Rotation('', x='90deg')
    lv1 = g.structure.Volume('a_box', material=water, shape=box1)
    lv1inlv2 = g.structure.Placement("lv1_in_lv2",
                                     volume=lv1,
                                     pos=pos,
                                     rot=rot)
    lv2 = g.structure.Volume('the_world',
                             material=air,
                             shape=box2,
                             placements=[lv1inlv2],
                             params=(("foo", 42), ("bar", "baz")))
    g.set_world(lv2)
    return g
Ejemplo n.º 3
0
def test_make_some_shapes():
    g = construct.Geometry()
    try:
        b1 = g.shapes.Box("box1", 1, 2, 3)  # literal numbers should fail
    except ValueError:
        b1 = g.shapes.Box("box1", '1cm', '2cm',
                          '3cm')  # literal numbers should fail
        pass
    else:
        raise (RuntimeError,
               'Failed to catch unitless box dimensions %s' % str(b1))

    print('B1', b1)
    b2 = g.shapes.Box("box2", '1cm', dz='3cm',
                      dy='2cm')  # out of order kwargs should work
    b3 = g.shapes.Box("box3", "1cm", "2cm", "3.0cm")
    assert b1.dx == b2.dx and b2.dx == b3.dx, str([b1, b2, b3])
    assert b1.dy == b2.dy and b2.dy == b3.dy, str([b1, b2, b3])
    assert b1.dz == b2.dz and b2.dz == b3.dz, str([b1, b2, b3])
    try:
        g.shapes.Box("box4", 1, 2, dy=22, dz=33)
    except ValueError:
        print('Correctly failed with duplicate kwargs')
        pass
    else:
        raise (RuntimeError, "Didn't catch dup kwargs error")

    print('Shape store:\n\t',
          '\n\t'.join([str(v) for v in g.store.shapes.values()]))
def test_make_some_stuff():
    g = construct.Geometry()

    h = g.matter.Element("Hydrogen","H",1,"1.01g/mole")
    n = g.matter.Element("Nitrogen", "N", 7, "14.01*g/mole")
    o = g.matter.Element("Oxygen", "O", 8, "16.0g/mole")
    water = g.matter.Molecule("Water", density="1.0kg/l", elements=(("Oxygen",1),("Hydrogen",2)))
    air = g.matter.Mixture("Air", density = "1.290*mg/cc", 
                           components = (("Nitrogen", 0.7), ("Oxygen",0.3)))

    box1 = g.shapes.Box("box1",'1cm','2cm','3cm')    
    box2 = g.shapes.Box("box2",'1m','2m','3m')    

    pos = g.structure.Position(None, '1cm',z='2cm')
    assert pos.name == 'Position000000',pos.name
    print (pos)
    rot = g.structure.Rotation('', x='90deg')
    assert rot.name == 'Rotation000001', rot.name
    print (rot)

    lv1 = g.structure.Volume('a box', material=water, shape=box1)
    print (lv1)
    lv1inlv2 = g.structure.Placement("lv1_in_lv2", volume=lv1, pos=pos, rot=rot)
    print (lv1inlv2)
    lv2 = g.structure.Volume('lv2', material = air, shape=box2,
                             placements = [lv1inlv2])
    assert lv2.params is not None, 'got %s' % str(lv2.params) # want empty list
    assert not lv2.params, 'got %s' % str(lv2.params)
    lv2 = g.structure.Volume('the world', material = air, shape=box2,
                             placements = [lv1inlv2], params= (("foo",42), ("bar","baz")))
    assert lv2.params
    print (lv2)
Ejemplo n.º 5
0
def test_ascending():
    'Test ascending iteration of volumes'

    g = construct.Geometry()
    box = g.shapes.Box("box",'1mm','2mm','3mm')    

    top = g.structure.Volume('top', material='air', shape=box)
    vol = top
    for dn in range(3):
        d = g.structure.Volume('daughter_%d' % dn, material='air', shape=box)
        top.placements.append(g.structure.Placement('place_%d'%dn, volume=d).name)
        top.placements.append(g.structure.Placement('again_%d'%dn, volume=d).name)
        for gdn in range(2):
            gd = g.structure.Volume('granddaughter_%d_%d' % (dn, gdn), material='air', shape=box)
            d.placements.append(g.structure.Placement('place_%d_%d' % (dn, gdn), volume=gd).name)


    seen = set()
    for vol in ascending(g.store.structure, top):
        print (vol)
        if vol.name in seen:
            raise (ValueError, "Seen again: %s" % vol.name)
            seen.add(vol.name)

    #print (g.store.structure)
    vols = list(ascending_all(g.store.structure, top))
    #print ('\n'.join([v.name for v in vols]))
    assert len(vols) == 19, len(vols)
    assert vols[-1].name == 'top'
Ejemplo n.º 6
0
def test_units():
    g = construct.Geometry()
    g.shapes.Box("units0", '1cm', '2cm', '3cm')

    try:
        g.shapes.Box("units1", 1, '2cm', '3cm')  # should fail
    except (ValueError):
        pass
    else:
        raise (RuntimeError, "Failed to catch unit mismatch")
Ejemplo n.º 7
0
def test_pass_objects():
    g = construct.Geometry()

    n = g.matter.Element("Nitrogen", "N", 7, "14.01*g/mole")
    h = g.matter.Element("Hydrogen", "H", 1, "1.01g/mole")
    water = g.matter.Molecule("Water",
                              density="1.0kg/l",
                              elements=((n, 1), (h, 2)))
    print(water)

    assert 3 == len(g.store.matter)
Ejemplo n.º 8
0
def test_gegede_gdml_polyhedra():
    geom = construct.Geometry()
    shape = geom.shapes.PolyhedraRegular('PolyhedraRegular')
    lv = geom.structure.Volume(shape.name + '_volume',
                               material='Air',
                               shape=shape)
    geom.set_world(lv)
    obj = gegede.export.gdml.convert(geom)
    s = gegede.export.gdml.dumps(obj)
    assert s
    print(s.decode())
    gegede.export.gdml.validate(s)
Ejemplo n.º 9
0
def test_gegede_gdml_twistedbox():
    geom = construct.Geometry()
    shape = geom.shapes.TwistedBox('TwistedBox')
    lv = geom.structure.Volume(shape.name + '_volume',
                               material='Air',
                               shape=shape)
    geom.set_world(lv)
    obj = gegede.export.gdml.convert(geom)
    s = gegede.export.gdml.dumps(obj)
    assert s
    print(s.decode())
    gegede.export.gdml.validate(s)
Ejemplo n.º 10
0
def test_post_place():
    g = construct.Geometry()

    box0 = g.shapes.Box("box0",'1mm','2mm','3mm')    
    box1 = g.shapes.Box("box1",'1cm','2cm','3cm')    

    lv1 = g.structure.Volume('a box', material='water', shape=box1)
    lv0 = g.structure.Volume('daughter-box', material='air', shape=box0)

    lv0inlv1 = g.structure.Placement('lv0_in_lv1', volume=lv0)
    lv1.placements.append(lv0inlv1.name) # no boom!

    print ('DONE')
    print (g.store.structure)
Ejemplo n.º 11
0
def test_unique_shapes():
    g = construct.Geometry()
    try:
        g.shapes.Box("box0", 1, 2, 3)  # should fail
    except ValueError:
        g.shapes.Box("box0", '1cm', '2cm', '3cm')
    else:
        raise (RuntimeError, "Failed to catch unit mismatch")

    try:
        g.shapes.Box("box0", '1mm', '2mm', '3mm')
    except ValueError:
        print('Correctly failed to allow two boxes of same name')
        pass
    else:
        raise (RuntimeError, "Allowed to make two boxes of same name")
    assert len(g.store.shapes) == 1
Ejemplo n.º 12
0
def test_default_args():
    g = construct.Geometry()
    b1 = g.shapes.Box('box1')
    print('Box1:', b1)
Ejemplo n.º 13
0
def test_make_an_empty_geometry():
    construct.Geometry()
Ejemplo n.º 14
0
def test_elements():
    g = construct.Geometry()

    # Elements

    o = g.matter.Element("Oxygen", "O", 8, "16.0g/mole")
    assert o.name == 'Oxygen'
    assert o.symbol == 'O'
    assert o.z == 8
    assert o.a == Quantity(16.0, 'gram / mole')
    assert len(g.store.matter) == 1
    assert len(g.store.shapes) == 0
    print(o)

    n = g.matter.Element("Nitrogen", "N", 7, "14.01*g/mole")
    assert n.a == Quantity(14.01, 'gram/mole')
    print(n)

    h = g.matter.Element("Hydrogen", "H", 1, "1.01g/mole")
    print(h)

    # Isotopes and Compositions

    U235 = g.matter.Isotope("U235", z=92, ia=235, a="235.0439242 g/mole")
    assert U235.z == 92
    print(U235)
    U238 = g.matter.Isotope("U238", z=92, ia=238, a="238.0507847 g/mole")
    assert U238.ia == 238
    print(U238)
    enriched_uranium = g.matter.Composition("enriched U",
                                            symbol="U",
                                            isotopes=(("U235", 0.8), ("U238",
                                                                      0.2)))
    assert len(enriched_uranium.isotopes) == 2
    print(enriched_uranium)

    # Materials

    lar = g.matter.Amalgam("liquidArgon",
                           z=18,
                           a="39.95*g/mole",
                           density="1.390*g/cc")
    print(lar)
    assert lar.density.compare(Quantity(1.39, 'kilogram / liter'),
                               lambda x, y: abs(x - y) < 0.0001)

    water = g.matter.Molecule("Water",
                              density="1.0kg/l",
                              elements=(("Oxygen", 1), ("Hydrogen", 2)))
    print(water)
    assert hasattr(water, 'symbol')
    assert 2 == len(water.elements)

    air = g.matter.Mixture("Air",
                           density="1.290*mg/cc",
                           components=(("Nitrogen", 0.7), ("Oxygen", 0.3)))
    print(air)
    assert 2 == len(air.components)

    nuc_rod_mat = g.matter.Mixture(
        "U for nuclear power generation",
        density="19.050g/cc",
        # need explicit comma to tuple'ize here
        components=(("enriched U", 1.0), ))
    print(nuc_rod_mat)
    assert 1 == len(nuc_rod_mat.components)
Ejemplo n.º 15
0
def test_logical_volumes():
    g = construct.Geometry()