示例#1
0
    def test_scatterercopy(self):
        '''scatterercopy'''
        # create a weird shape
        from mccomposite.geometry import primitives
        shape = primitives.block((1, 1, 1))

        #create pure python representation of scatterer composite
        composite1 = mccomposite.composite(shape)
        nprinter = NeutronPrinter(shape)
        composite1.addElement(nprinter)
        #create a copy
        copy = mccomposite.scatterercopy(composite1)

        #create a larget composite
        shape = primitives.block((1, 1, 2))
        composite = mccomposite.composite(shape)
        composite.addElement(composite1, (0, 0, -0.5))
        composite.addElement(copy, (0, 0, +0.5))

        #render the c++ representation
        ccomposite = mccomposite.scattererEngine(composite)

        ev = mcni.neutron(r=(0, 0, -5), v=(0, 0, 1))
        ccomposite.scatter(ev)

        return
示例#2
0
    def test_copy(self):
        '''copy'''
        print "This test creates two identical blocks, each of which "\
              "does not interact with neutrons. They print the info "\
              "about the neutrons passing thru them, however. "\
              "This test then send one neutron through these two "\
              "blocks, so we should see two printings of neutron info, "\
              "differing only on time-of-flight."
        # create a shape
        from mccomposite.geometry import primitives
        smallblock = primitives.block((1, 1, 1))

        #create pure python representation of scatterer composite
        composite1 = mccomposite.composite(smallblock)
        import UseNeutronPrinter2
        nprinter = UseNeutronPrinter2.NeutronPrinter(smallblock)
        composite1.addElement(nprinter)
        #create a copy
        copy = Copy.Copy(composite1)

        #create a larget composite
        largeblock = primitives.block((1, 1, 2))
        composite = mccomposite.composite(largeblock)
        composite.addElement(composite1, (0, 0, -0.5))
        #composite.addElement( nprinter, (0,0,-0.5) )
        composite.addElement(copy, (0, 0, +0.5))

        #render the c++ representation
        ccomposite = mccomposite.scattererEngine(composite)

        ev = mcni.neutron(r=(0, 0, -5), v=(0, 0, 1))

        ccomposite.scatter(ev)
        return
    def test_scatterercopy(self):
        '''scatterercopy'''
        # create a weird shape
        from mccomposite.geometry import primitives
        shape = primitives.block( (1,1,1) )

        #create pure python representation of scatterer composite
        composite1 = mccomposite.composite( shape )
        nprinter = NeutronPrinter( shape )
        composite1.addElement( nprinter )
        #create a copy
        copy = mccomposite.scatterercopy( composite1 )
        
        #create a larget composite
        shape = primitives.block( (1,1,2) )
        composite = mccomposite.composite( shape )
        composite.addElement( composite1, (0,0,-0.5) )
        composite.addElement( copy, (0,0,+0.5) )

        #render the c++ representation
        ccomposite = mccomposite.scattererEngine( composite )

        ev = mcni.neutron( r = (0,0,-5), v = (0,0,1) )
        ccomposite.scatter(ev)
        
        return
示例#4
0
    def test_copy(self):
        '''copy'''
        print "This test creates two identical blocks, each of which "\
              "does not interact with neutrons. They print the info "\
              "about the neutrons passing thru them, however. "\
              "This test then send one neutron through these two "\
              "blocks, so we should see two printings of neutron info, "\
              "differing only on time-of-flight."
        # create a shape
        from mccomposite.geometry import primitives
        smallblock = primitives.block( (1,1,1) )

        #create pure python representation of scatterer composite
        composite1 = mccomposite.composite( smallblock )
        import UseNeutronPrinter2
        nprinter = UseNeutronPrinter2.NeutronPrinter( smallblock )
        composite1.addElement( nprinter )
        #create a copy
        copy = Copy.Copy( composite1 )
        
        #create a larget composite
        largeblock = primitives.block( (1,1,2) )
        composite = mccomposite.composite( largeblock )
        composite.addElement( composite1, (0,0,-0.5) )
        #composite.addElement( nprinter, (0,0,-0.5) )
        composite.addElement( copy, (0,0,+0.5) )

        #render the c++ representation
        ccomposite = mccomposite.scattererEngine( composite )

        ev = mcni.neutron( r = (0,0,-5), v = (0,0,1) )

        ccomposite.scatter(ev)
        return
    def onSampleAssembly(self, sampleassembly):
        #
        lg = sampleassembly.local_geometer

        # XXXX
        # here we need to use the mcstas coordinate system in constructing
        # the computation engine
        from sampleassembly.geometers.CoordinateSystem import McStasCS
        lg.changeRequestCoordinateSystem(McStasCS)

        # the container
        import mccomposite
        compositeScatterer = mccomposite.composite()

        for scatterer in sampleassembly.elements():
            if scatterer.__class__.__name__ == 'Environment':
                # environment not a scatterer
                continue
            s = scatterer.identify(self)
            p = lg.position(scatterer)
            o = lg.orientation(scatterer)
            compositeScatterer.addElement(s, p, o)
            continue

        attrs = sampleassembly.attributes
        getval = lambda x: attrs.get(x) if attrs.has(x) else None
        compositeScatterer.setMultipleScatteringParams(
            max_multiplescattering_loops_among_scatterers = \
                getval('max_multiplescattering_loops_among_scatterers'),
            max_multiplescattering_loops_interactM_path1 = \
                getval('max_multiplescattering_loops_interactM_path1'),
            min_neutron_probability = getval('min_neutron_probability'),
            )
        return compositeScatterer
示例#6
0
    def onSampleAssembly(self, sampleassembly):
        #
        lg = sampleassembly.local_geometer

        # XXXX
        # here we need to use the mcstas coordinate system in constructing
        # the computation engine
        from sampleassembly.geometers.CoordinateSystem import McStasCS

        lg.changeRequestCoordinateSystem(McStasCS)

        # the container
        import mccomposite

        compositeScatterer = mccomposite.composite()

        for scatterer in sampleassembly.elements():
            if scatterer.__class__.__name__ == "Environment":
                # environment not a scatterer
                continue
            s = scatterer.identify(self)
            p = lg.position(scatterer)
            o = lg.orientation(scatterer)
            compositeScatterer.addElement(s, p, o)
            continue

        attrs = sampleassembly.attributes
        getval = lambda x: attrs.get(x) if attrs.has(x) else None
        compositeScatterer.setMultipleScatteringParams(
            max_multiplescattering_loops_among_scatterers=getval("max_multiplescattering_loops_among_scatterers"),
            max_multiplescattering_loops_interactM_path1=getval("max_multiplescattering_loops_interactM_path1"),
            min_neutron_probability=getval("min_neutron_probability"),
        )
        return compositeScatterer
示例#7
0
    def test(self):
        # create a weird shape
        from mccomposite.geometry import primitives
        block = primitives.block((1, 1, 1))
        sphere = primitives.sphere(1)
        cylinder = primitives.cylinder(2, 2.001)

        from mccomposite.geometry import operations
        dilated = operations.dilate(sphere, 2)
        translated = operations.translate(block, (0, 0, 0.5))
        united = operations.unite(dilated, translated)

        rotated = operations.rotate(united, (90, 0, 0))

        intersect = operations.intersect(rotated, cylinder)

        difference = operations.subtract(intersect, sphere)

        print mccomposite.scattererEngine(difference)

        shape = difference
        #shape = block
        #shape = dilated
        #shape = united
        #shape = intersect
        #shape = operations.rotate(block, (90,0,0) )
        #shape = rotated
        #shape = sphere
        #shape = operations.subtract(sphere, block)
        #shape = operations.subtract( primitives.cylinder(1, 2.1), sphere )

        #create pure python representation of scatterer composite
        composite = mccomposite.composite(shape)
        nprinter = NeutronPrinter(shape)
        composite.addElement(nprinter)

        #render the c++ representation
        ccomposite = mccomposite.scattererEngine(composite)

        ev = mcni.neutron(r=(0, 0, -5), v=(0, 0, 1))
        ccomposite.scatter(ev)

        return
    def test(self):
        # create a weird shape
        from mccomposite.geometry import primitives
        block = primitives.block( (1,1,1) )
        sphere = primitives.sphere( 1 )
        cylinder = primitives.cylinder( 2,2.001 )

        from mccomposite.geometry import operations
        dilated = operations.dilate( sphere, 2 )
        translated = operations.translate( block, (0,0,0.5) )
        united = operations.unite( dilated, translated )

        rotated = operations.rotate( united, (90,0,0) )

        intersect = operations.intersect( rotated, cylinder )

        difference = operations.subtract( intersect, sphere )
        
        print mccomposite.scattererEngine( difference )

        shape = difference
        #shape = block
        #shape = dilated
        #shape = united
        #shape = intersect
        #shape = operations.rotate(block, (90,0,0) )
        #shape = rotated
        #shape = sphere
        #shape = operations.subtract(sphere, block)
        #shape = operations.subtract( primitives.cylinder(1, 2.1), sphere )

        #create pure python representation of scatterer composite
        composite = mccomposite.composite( shape )
        nprinter = NeutronPrinter( shape )
        composite.addElement( nprinter )

        #render the c++ representation
        ccomposite = mccomposite.scattererEngine( composite )

        ev = mcni.neutron( r = (0,0,-5), v = (0,0,1) )
        ccomposite.scatter(ev)
        
        return