def test3(self):
        '''create pure python representation of a homogeneous scatterer with
        composite kernel. render the c++ computation engine of that kernel.
        '''
        #shape
        from mccomposite.geometry import primitives
        shape = primitives.block( (1,1,1) )

        #kernel
        nprinter = NeutronPrinter( )
        
        #composite kernel
        composite_kernel = hs.compositeKernel()
        composite_kernel.addElement( nprinter )

        #scatterer
        scatterer = hs.homogeneousScatterer(
            shape, composite_kernel)

        #render the c++ representation
        cscatterer = hs.scattererEngine( scatterer )

        for i in range(10):
            ev = mcni.neutron( r = (0,0,-5), v = (0,0,1) )
            cscatterer.scatter(ev)
            continue
        return
Example #2
0
    def test3(self):
        '''create pure python representation of a homogeneous scatterer with
        composite kernel. render the c++ computation engine of that kernel.
        '''
        #shape
        from mccomposite.geometry import primitives
        shape = primitives.block((1, 1, 1))

        #kernel
        nprinter = NeutronPrinter()

        #composite kernel
        composite_kernel = hs.compositeKernel()
        composite_kernel.addElement(nprinter)

        #scatterer
        scatterer = hs.homogeneousScatterer(shape, composite_kernel)

        #render the c++ representation
        cscatterer = hs.scattererEngine(scatterer)

        for i in range(10):
            ev = mcni.neutron(r=(0, 0, -5), v=(0, 0, 1))
            cscatterer.scatter(ev)
            continue
        return
 def onHe3Tube( self, he3tube ):
     '''construct computation engine of given he3tube description'''
     from mccomposite.geometry import locate
     
     # assume all elements of he3tube are pixels
     pixels = he3tube.elements()
     npixels = len(pixels) 
     
     #shape of he3tube
     shape = he3tube.shape()
     if not shape: raise "shape of he3tube %s is not specified" % he3tube
     cshape = shape.identify(self)
     
     #make sure pixels are in the he3tube
     geometer = he3tube.geometer
     for element in pixels:
         position = geometer.position(element)/units.length.meter
         cposition = self.factory.position( position )
         assert self.factory.locate( cposition, cshape ) == "inside", \
                "pixel at %s is not inside the tube %s" % (
             position, cshape)
         continue
     
     #find the axis direction of the he3tube tube
     pixel0position = geometer.position(pixels[0]) / units.length.meter
     axisDirection = geometer.position(pixels[-1]) / units.length.meter - pixel0position
     import numpy, numpy.linalg as nl
     axisDirection = numpy.array(axisDirection)
     len1 = float(nl.norm(axisDirection))
     axisDirection /= len1
     #detector length. len1 is the length of (n-1) pixels
     tubeLength = len1 * npixels / (npixels-1)
     
     #pressure
     pressure = he3tube.pressure()
     
     #kernel
     import mccomponents.detector as md
     kernel = md.he3tubeKernel(
         pressure, self._indexes_in_detsys,
         tubeLength, npixels, axisDirection, pixel0position)
     
     try:
         mcweights = he3tube.mcweights
     except AttributeError:
         from mccomponents.detector import default_mc_weights_for_detector_scatterer
         mcweights = default_mc_weights_for_detector_scatterer
         
     # treat this detector as  a homogeneous scatterer
     import mccomponents.homogeneous_scatterer as mh
     scatterer = mh.homogeneousScatterer(
         shape, kernel,
         mcweights = mcweights )
     ret = scatterer.identify(self)
     return ret
    def onHe3Tube(self, he3tube):
        '''construct computation engine of given he3tube description'''
        from mccomposite.geometry import locate

        # assume all elements of he3tube are pixels
        pixels = he3tube.elements()
        npixels = len(pixels)

        #shape of he3tube
        shape = he3tube.shape()
        if not shape: raise "shape of he3tube %s is not specified" % he3tube
        cshape = shape.identify(self)

        #make sure pixels are in the he3tube
        geometer = he3tube.geometer
        for element in pixels:
            position = geometer.position(element) / units.length.meter
            cposition = self.factory.position(position)
            assert self.factory.locate( cposition, cshape ) == "inside", \
                   "pixel at %s is not inside the tube %s" % (
                position, cshape)
            continue

        #find the axis direction of the he3tube tube
        pixel0position = geometer.position(pixels[0]) / units.length.meter
        axisDirection = geometer.position(
            pixels[-1]) / units.length.meter - pixel0position
        import numpy, numpy.linalg as nl
        axisDirection = numpy.array(axisDirection)
        len1 = float(nl.norm(axisDirection))
        axisDirection /= len1
        #detector length. len1 is the length of (n-1) pixels
        tubeLength = len1 * npixels / (npixels - 1)

        #pressure
        pressure = he3tube.pressure()

        #kernel
        import mccomponents.detector as md
        kernel = md.he3tubeKernel(pressure, self._indexes_in_detsys,
                                  tubeLength, npixels, axisDirection,
                                  pixel0position)

        try:
            mcweights = he3tube.mcweights
        except AttributeError:
            from mccomponents.detector import default_mc_weights_for_detector_scatterer
            mcweights = default_mc_weights_for_detector_scatterer

        # treat this detector as  a homogeneous scatterer
        import mccomponents.homogeneous_scatterer as mh
        scatterer = mh.homogeneousScatterer(shape, kernel, mcweights=mcweights)
        ret = scatterer.identify(self)
        return ret
    def test2(self):
        '''create pure python representation of a homogeneous scatterer,
        and render the c++ computation engine of that kernel
        '''
        from mccomposite.geometry import primitives
        shape = primitives.block( (1,1,1) )
        nprinter = NeutronPrinter( )
        scatterer = hs.homogeneousScatterer(shape, nprinter)

        #render the c++ representation
        cscatterer = hs.scattererEngine( scatterer )

        for i in range(10):
            ev = mcni.neutron( r = (0,0,-5), v = (0,0,1) )
            cscatterer.scatter(ev)
            print ev
            continue
        return
Example #6
0
    def test2(self):
        '''create pure python representation of a homogeneous scatterer,
        and render the c++ computation engine of that kernel
        '''
        from mccomposite.geometry import primitives
        shape = primitives.block((1, 1, 1))
        nprinter = NeutronPrinter()
        scatterer = hs.homogeneousScatterer(shape, nprinter)

        #render the c++ representation
        cscatterer = hs.scattererEngine(scatterer)

        for i in range(10):
            ev = mcni.neutron(r=(0, 0, -5), v=(0, 0, 1))
            cscatterer.scatter(ev)
            print ev
            continue
        return
 def notify(self, parent):
     #shape might come from sample assembly xml
     try: shape = self._shape
     except: shape = None
     #
     kernel = self._kernel
     mcweights = self._mcweights
     max_multiplescattering_loops = self._max_multiplescattering_loops
     min_neutron_probability = self._min_neutron_probability
     packing_factor = self._packing_factor
     
     from mccomponents.homogeneous_scatterer import homogeneousScatterer
     scatterer = homogeneousScatterer(
         shape, kernel,
         mcweights = mcweights,
         max_multiplescattering_loops = max_multiplescattering_loops,
         min_neutron_probability = min_neutron_probability,
         packing_factor = packing_factor,
         )
     
     #parent is the Document node. 
     parent.document = scatterer
     return
 def onHomogeneousScatterer(self, scatterer):
     import mccomponents.homogeneous_scatterer as hs
     s = hs.homogeneousScatterer(scatterer.shape(), kernel=None)
     s.origin = scatterer
     return s
Example #9
0
    def onHomogeneousScatterer(self, scatterer):
        import mccomponents.homogeneous_scatterer as hs

        s = hs.homogeneousScatterer(scatterer.shape(), kernel=None)
        s.origin = scatterer
        return s