Пример #1
0
 def test_cone_x_up_write(self):
     card = "1 k/x 0 0 0 0.5 1"
     surfcard = MCNPSurfaceCard(card)
     surfcard.b_box = [0, 10, 0, 0, 0, 0]
     serp_string = serpent_cone_x(surfcard)
     self.assertEqual(
         serp_string, " ckx 0.000000 0.000000 0.000000 0.500000 1.000000\n")
Пример #2
0
    def __macro_rcc_cylinder(self, Surface, vector):
        new_surf_list = []

        if vector[0] == 0 and vector[1] == 0:
            plane = " pz "
            cylinder = " c/z "
            c1 = Surface.surface_coefficients[0]
            c2 = Surface.surface_coefficients[1]
            top = Surface.surface_coefficients[
                5] + Surface.surface_coefficients[2]
            bottom = Surface.surface_coefficients[2]
        elif vector[0] == 0 and vector[2] == 0:
            plane = " py "
            cylinder = " c/y "
            c1 = Surface.surface_coefficients[0]
            c2 = Surface.surface_coefficients[2]
            top = Surface.surface_coefficients[
                4] + Surface.surface_coefficients[1]
            bottom = Surface.surface_coefficients[1]
        elif vector[1] == 0 and vector[2] == 0:
            plane = " px "
            cylinder = " c/x "
            c1 = Surface.surface_coefficients[1]
            c2 = Surface.surface_coefficients[2]
            top = Surface.surface_coefficients[
                3] + Surface.surface_coefficients[0]
            bottom = Surface.surface_coefficients[0]

        # if coefficients 4 & 5 are zero then its a cz with planes at
        self.last_free_surface_index += 1
        surf = MCNPSurfaceCard(
            str(self.last_free_surface_index) + cylinder + str(c1) + " " +
            str(c2) + " " + str(Surface.surface_coefficients[6]))
        new_surf_list.append(surf)
        self.last_free_surface_index += 1
        surf = MCNPSurfaceCard(
            str(self.last_free_surface_index) + plane + str(bottom))
        new_surf_list.append(surf)
        self.last_free_surface_index += 1
        surf = MCNPSurfaceCard(
            str(self.last_free_surface_index) + plane + str(top))
        new_surf_list.append(surf)

        cell_description_inside = "("
        cell_description_inside += " -" + str(new_surf_list[0].surface_id)
        cell_description_inside += " -" + str(new_surf_list[1].surface_id)
        cell_description_inside += " -" + str(new_surf_list[2].surface_id)
        cell_description_inside += ")"

        cell_description_outside = "("
        cell_description_outside += "  " + str(new_surf_list[0].surface_id)
        cell_description_outside += ":" + str(new_surf_list[1].surface_id)
        cell_description_outside += ":" + str(new_surf_list[2].surface_id)
        cell_description_outside += ")"

        cell_description = [cell_description_inside, cell_description_outside]

        return new_surf_list, cell_description
Пример #3
0
 def test_bounding_box_px(self):
     card_string = "1 px 3"
     card = MCNPSurfaceCard(card_string)
     box = card.bounding_box()
     self.assertEqual(box[0],3)
     self.assertEqual(box[1],3)
     self.assertEqual(box[2],0)
     self.assertEqual(box[3],0)
     self.assertEqual(box[4],0)
     self.assertEqual(box[5],0)
Пример #4
0
 def test_explode_macrobody(self):
     input = MCNPInput()
     card_string = "1 rpp -1 1 -1 1 -1 1"
     Surface = MCNPSurfaceCard(card_string)
     # explode macrobody into surfaces
     cells, new_surfaces = input.explode_macrobody(Surface)
     self.assertEqual(cells[0], "( -1 -2 -3 -4 -5 -6 )")
     self.assertEqual(cells[1], "( 1 : 2 : 3 : 4 : 5 : 6)")
     self.assertEqual(len(new_surfaces), 6)
     self.assertEqual(new_surfaces[0].surface_type,
                      SurfaceCard.SurfaceType["PLANE_X"])
     self.assertEqual(new_surfaces[0].surface_coefficients[3], 1)
     self.assertEqual(new_surfaces[1].surface_type,
                      SurfaceCard.SurfaceType["PLANE_GENERAL"])
     self.assertEqual(new_surfaces[1].surface_coefficients[0], -1)
     self.assertEqual(new_surfaces[2].surface_type,
                      SurfaceCard.SurfaceType["PLANE_Y"])
     self.assertEqual(new_surfaces[2].surface_coefficients[3], 1)
     self.assertEqual(new_surfaces[3].surface_type,
                      SurfaceCard.SurfaceType["PLANE_GENERAL"])
     self.assertEqual(new_surfaces[3].surface_coefficients[1], -1)
     self.assertEqual(new_surfaces[4].surface_type,
                      SurfaceCard.SurfaceType["PLANE_Z"])
     self.assertEqual(new_surfaces[4].surface_coefficients[3], 1)
     self.assertEqual(new_surfaces[5].surface_type,
                      SurfaceCard.SurfaceType["PLANE_GENERAL"])
     self.assertEqual(new_surfaces[5].surface_coefficients[2], -1)
Пример #5
0
    def __get_surface_cards(self,idx):
        while True:
            surf_line = strip_dollar_comments(self.file_lines[idx])
            if surf_line.isspace():
                logging.debug('%s',"found end of cell cards at line " + str(idx))
                idx += 1
                break

            surf_card = surf_line
            jdx = idx + 1
            # scan until we are all done
            while True:
                surf_line = strip_dollar_comments(self.file_lines[jdx])
                # mcnp continue line is indicated by 5 spaces
                if surf_line[0:5] == "     " and not surf_line.isspace():
                    surf_card += surf_line
                else: # else we have found a new surf card
                    surfacecard = MCNPSurfaceCard(surf_card)
                    self.surface_list.append(surfacecard)
                    # update the surface index counter
                    if surfacecard.surface_id > self.last_free_surface_index: 
                        self.last_free_surface_index = surfacecard.surface_id
                    break 
                jdx += 1
            idx = jdx                  
        return idx
Пример #6
0
 def __make_new_plane(self, vector, offset):
     self.last_free_surface_index += 1
     surface_string = str(self.last_free_surface_index) + " p "
     for coeff in vector:
         surface_string += str(coeff) + " "
     surface_string += str(offset)
     surf = MCNPSurfaceCard(surface_string) # todo maybe instanciate explicitly generically?
     return surf
Пример #7
0
 def test_cz(self):
     card_string = "15000 cz 2.5"
     card = MCNPSurfaceCard(card_string)
     self.assertEqual(card.surface_type, SurfaceCard.SurfaceType["CYLINDER_Z"])
     self.assertEqual(card.surface_id, 15000)
     self.assertEqual(card.surface_coefficients[0], 0.0)
     self.assertEqual(card.surface_coefficients[1], 0.0)
     self.assertEqual(card.surface_coefficients[2], 2.5)
Пример #8
0
 def test_sy(self):
     card_string = "15000 sy 3.0 2.5"
     card = MCNPSurfaceCard(card_string)
     self.assertEqual(card.surface_type, SurfaceCard.SurfaceType["SPHERE_GENERAL"])
     self.assertEqual(card.surface_id, 15000)
     self.assertEqual(card.surface_coefficients[0], 0.0)
     self.assertEqual(card.surface_coefficients[1], 3.0)
     self.assertEqual(card.surface_coefficients[2], 0.0)
     self.assertEqual(card.surface_coefficients[3], 2.5)
Пример #9
0
 def test_sphere(self):
     card_string = "15 s 0 0 1 15"
     card = MCNPSurfaceCard(card_string)
     self.assertEqual(card.text_string, card_string)
     self.assertEqual(card.surface_type,SurfaceCard.SurfaceType["SPHERE_GENERAL"])
     self.assertEqual(card.surface_coefficients[0], 0.0)
     self.assertEqual(card.surface_coefficients[1], 0.0)
     self.assertEqual(card.surface_coefficients[2], 1.0)
     self.assertEqual(card.surface_coefficients[3],15.0)
Пример #10
0
 def test_plane_general(self):
     card_string = "1 p 0 0 1 15"
     card = MCNPSurfaceCard(card_string)
     self.assertEqual(card.text_string, card_string)
     self.assertEqual(card.surface_type,SurfaceCard.SurfaceType["PLANE_GENERAL"])
     self.assertEqual(card.surface_coefficients[0], 0.0)
     self.assertEqual(card.surface_coefficients[1], 0.0)
     self.assertEqual(card.surface_coefficients[2], 1.0)
     self.assertEqual(card.surface_coefficients[3],15.0)
Пример #11
0
 def test_plane_z(self):
     card_string = "1 pz 12.0"
     card = MCNPSurfaceCard(card_string)
     self.assertEqual(card.text_string, card_string)
     self.assertEqual(card.surface_type,SurfaceCard.SurfaceType["PLANE_Z"])
     self.assertEqual(card.surface_coefficients[0], 0.0)
     self.assertEqual(card.surface_coefficients[1], 0.0)
     self.assertEqual(card.surface_coefficients[2], 1.0)
     self.assertEqual(card.surface_coefficients[3], 12.0)
Пример #12
0
 def test_box(self):
     card_string = "15000 box -1 -1 -1 2 0 0 0 2 0 0 0 2"
     card = MCNPSurfaceCard(card_string)
     self.assertEqual(card.surface_type, SurfaceCard.SurfaceType["MACRO_RPP"])
     self.assertEqual(card.surface_id, 15000)
     self.assertEqual(card.surface_coefficients[0], -1.0)
     self.assertEqual(card.surface_coefficients[1],  1.0)
     self.assertEqual(card.surface_coefficients[2], -1.0)
     self.assertEqual(card.surface_coefficients[3],  1.0)
     self.assertEqual(card.surface_coefficients[4], -1.0)
     self.assertEqual(card.surface_coefficients[5],  1.0)
Пример #13
0
 def test_gq(self):
     card_string = "15000 gq 1 1 0 0 0 0 1 1 1 1"
     card = MCNPSurfaceCard(card_string)
     self.assertEqual(card.surface_type, SurfaceCard.SurfaceType["GENERAL_QUADRATIC"])
     self.assertEqual(card.surface_id, 15000)
     self.assertEqual(card.surface_coefficients[0], 1.0)
     self.assertEqual(card.surface_coefficients[1], 1.0)
     self.assertEqual(card.surface_coefficients[2], 0.0)
     self.assertEqual(card.surface_coefficients[3], 0.0)
     self.assertEqual(card.surface_coefficients[4], 0.0)
     self.assertEqual(card.surface_coefficients[5], 0.0)
     self.assertEqual(card.surface_coefficients[6], 1.0)
     self.assertEqual(card.surface_coefficients[7], 1.0)
     self.assertEqual(card.surface_coefficients[8], 1.0)
     self.assertEqual(card.surface_coefficients[9], 1.0)
Пример #14
0
    def explode_macrobody(self,Surface):
        new_surf_list = []
        # NOTE MCNP Macrobodies have +ve sense outside of it, and -ve sense inside
        # of it. Therefore, on a RPP the first index is the right hand side of the cube
        # and the 2nd is the left hand side
        if Surface.surface_type == SurfaceCard.SurfaceType["MACRO_RPP"]:
            # the order is weird here but so is MCNP
            id = int(Surface.surface_id)
            self.last_free_surface_index += 1
            surf = MCNPSurfaceCard(str(self.last_free_surface_index) + " px " + str(Surface.surface_coefficients[1]))
            new_surf_list.append(surf)
            self.last_free_surface_index += 1
            surf = MCNPSurfaceCard(str(self.last_free_surface_index) + " p -1.0 0 0 " + str(-1.0*Surface.surface_coefficients[0]))
            new_surf_list.append(surf)
            self.last_free_surface_index += 1
            surf = MCNPSurfaceCard(str(self.last_free_surface_index) + " py " + str(Surface.surface_coefficients[3]))
            new_surf_list.append(surf)
            self.last_free_surface_index += 1
            surf = MCNPSurfaceCard(str(self.last_free_surface_index) + " p 0 -1.0 0 " + str(-1.0*Surface.surface_coefficients[2]))
            new_surf_list.append(surf)
            self.last_free_surface_index += 1
            surf = MCNPSurfaceCard(str(self.last_free_surface_index) + " pz " + str(Surface.surface_coefficients[5]))
            new_surf_list.append(surf)
            self.last_free_surface_index += 1
            surf = MCNPSurfaceCard(str(self.last_free_surface_index) + " p 0 0 -1.0 " + str(-1.0*Surface.surface_coefficients[4]))
            new_surf_list.append(surf)
            # NOTE new_surf list here is now in MCNP facet order
            # appropriate cell description for inside the macrobody
            cell_description_inside = "( -" + str(new_surf_list[0].surface_id)
            cell_description_inside += " -" + str(new_surf_list[1].surface_id)
            cell_description_inside += " -" + str(new_surf_list[2].surface_id)
            cell_description_inside += " -" + str(new_surf_list[3].surface_id)
            cell_description_inside += " -" + str(new_surf_list[4].surface_id)
            cell_description_inside += " -" + str(new_surf_list[5].surface_id)
            cell_description_inside += " )"
            # appropriate cell descripiton for outside the macrobody
            cell_description_outside = "( " + str(new_surf_list[0].surface_id)
            cell_description_outside += " : " + str(new_surf_list[1].surface_id)
            cell_description_outside += " : " + str(new_surf_list[2].surface_id)
            cell_description_outside += " : " + str(new_surf_list[3].surface_id)
            cell_description_outside += " : " + str(new_surf_list[4].surface_id)
            cell_description_outside += " : " + str(new_surf_list[5].surface_id)
            cell_description_outside += ")"
            
            cell_description = [cell_description_inside,cell_description_outside]
            
        elif Surface.surface_type == SurfaceCard.SurfaceType["MACRO_RCC"]:
            id = int(Surface.surface_id)
            
            vector = [Surface.surface_coefficients[3],Surface.surface_coefficients[4],Surface.surface_coefficients[5]]
            new_surf_list, cell_description = self.__macro_rcc_cylinder_arbitrary(Surface,vector)

        elif Surface.surface_type == SurfaceCard.SurfaceType["MACRO_BOX"]:

            id = int(Surface.surface_id)
            
            origin = [Surface.surface_coefficients[0], Surface.surface_coefficients[1], Surface.surface_coefficients[2]]

            vec1 = [Surface.surface_coefficients[3], Surface.surface_coefficients[4], Surface.surface_coefficients[5]]
            vec2 = [Surface.surface_coefficients[6], Surface.surface_coefficients[7], Surface.surface_coefficients[8]]
            vec3 = [Surface.surface_coefficients[9], Surface.surface_coefficients[10], Surface.surface_coefficients[11]]

            vec1n = vec1/np.norm(vec1)
            vec2n = vec2/np.norm(vec2)
            vec3n = vec3/np.norm(vec3)

            d1 = vec1n[0]*origin[0] + vec1n[1]*origin[1] + vec1n[2]*origin[2] 
            d2 = vec1n[0]*(origin[0] + vec1[0]) + vec1n[1]*(origin[1]+vec1[1]) + vec1n[2]*(origin[2]+vec1[2])
            d3 = vec2n[0]*origin[0] + vec2n[1]*origin[1] + vec2n[2]*origin[2]
            d4 = vec2n[0]*(origin[0] + vec2[0]) + vec2n[1]*(origin[1]+vec2[1]) + vec2n[2]*(origin[2]+vec2[2])
            d5 = vec3n[0]*origin[0] + vec3n[1]*origin[1] + vec3n[2]*origin[2]
            d6 = vec3n[0]*(origin[0] + vec3[0]) + vec3n[1]*(origin[1]+vec3[1]) + vec3n[2]*(origin[2]+vec3[2])

            
            # cannonical facet ordering is +ve side the -ve side
            p1 = self.__make_new_plane(vec1n,d2)
            p2 = self.__make_new_plane(-1.0*vec1n,d1)

            p3 = self.__make_new_plane(vec2n,d4)
            p4 = self.__make_new_plane(-1.0*vec2n,d3)

            p5 = self.__make_new_plane(vec3n,d6)
            p6 = self.__make_new_plane(-1.0*vec3n,d5)

            new_surf_list = [p1,p2,p3,p4,p5,p6]

            cell_description_inside = "("
            cell_description_inside +=        str(new_surf_list[0].surface_id)
            cell_description_inside += " " + str(new_surf_list[1].surface_id)
            cell_description_inside += " " + str(new_surf_list[2].surface_id)
            cell_description_inside += " " + str(new_surf_list[3].surface_id)
            cell_description_inside += " " + str(new_surf_list[4].surface_id)
            cell_description_inside += " " + str(new_surf_list[5].surface_id)          
            cell_description_inside += ")"

            cell_description_outside = "("
            cell_description_outside += "-"  + str(new_surf_list[0].surface_id)
            cell_description_outside += ":-" + str(new_surf_list[1].surface_id)
            cell_description_outside += ":-"  + str(new_surf_list[2].surface_id)
            cell_description_outside += ":-" + str(new_surf_list[3].surface_id)
            cell_description_outside += ":-"  + str(new_surf_list[4].surface_id)
            cell_description_outside += ":-" + str(new_surf_list[5].surface_id)          
            cell_description_outside += ")"
            
            cell_description = [cell_description_inside,cell_description_outside]
        else:
            warnings.warn('Found an unsupported macrobody, files will not be correct',Warning)
            cell_description = ["",""]
            
        return cell_description, new_surf_list
Пример #15
0
    def __macro_rcc_cylinder_arbitrary(self,Surface,vector):

        new_surf_list = []
        cell_description = []

        # this is where the cylinder points
        axis_vector = vector/np.norm(vector)
        # the vector perpendicular to this will be the capping plane

        gq_coeffs = [0]*10

        gq_coeffs[0] = 1. - axis_vector[0]**2
        gq_coeffs[1] = 1. - axis_vector[1]**2        
        gq_coeffs[2] = 1. - axis_vector[2]**2 

        gq_coeffs[3] = -2.*axis_vector[0]*axis_vector[1]        
        gq_coeffs[4] = -2.*axis_vector[1]*axis_vector[2]        
        gq_coeffs[5] = -2.*axis_vector[0]*axis_vector[2]

        gq_coeffs[6] = -Surface.surface_coefficients[1]*gq_coeffs[3] - Surface.surface_coefficients[2]*gq_coeffs[5] \
                        -2.0*Surface.surface_coefficients[0]*gq_coeffs[0]
        gq_coeffs[7] = -Surface.surface_coefficients[0]*gq_coeffs[3] - Surface.surface_coefficients[2]*gq_coeffs[4] \
                        -2.0*Surface.surface_coefficients[1]*gq_coeffs[1]
        gq_coeffs[8] = -Surface.surface_coefficients[0]*gq_coeffs[5] - Surface.surface_coefficients[1]*gq_coeffs[4] \
                        -2.0*Surface.surface_coefficients[2]*gq_coeffs[2]

        gq_coeffs[9] = Surface.surface_coefficients[0]*Surface.surface_coefficients[1]*gq_coeffs[3] + \
                       Surface.surface_coefficients[1]*Surface.surface_coefficients[2]*gq_coeffs[4] + \
                       Surface.surface_coefficients[0]*Surface.surface_coefficients[2]*gq_coeffs[5] + \
                       Surface.surface_coefficients[0]**2*gq_coeffs[0] + \
                       Surface.surface_coefficients[1]**2*gq_coeffs[1] + \
                       Surface.surface_coefficients[2]**2*gq_coeffs[2] - \
                       Surface.surface_coefficients[6]**2

        #for idx,coeff in enumerate(gq_coeffs):
        #    gq_coeffs[idx] = nparound(coeff,decimals=15)

        self.last_free_surface_index += 1
        surface_string = str(self.last_free_surface_index) + " gq "
        for coeff in gq_coeffs:
            surface_string += str(coeff) + " "
        surf = MCNPSurfaceCard(surface_string) # todo maybe instanciate explicitly generically?
        new_surf_list.append(surf)

        # plane offset 1
        d1 =   axis_vector[0]*Surface.surface_coefficients[0] \
             + axis_vector[1]*Surface.surface_coefficients[1] \
             + axis_vector[2]*Surface.surface_coefficients[2]

        self.last_free_surface_index += 1
        surface_string = str(self.last_free_surface_index) + " p "
        for coeff in axis_vector:
            surface_string += str(-1.*coeff) + " "
        surface_string += str(d1)
        surf = MCNPSurfaceCard(surface_string) # todo maybe instanciate explicitly generically?
        new_surf_list.append(surf)


        # plane offset 2
        d2 =   axis_vector[0]*(Surface.surface_coefficients[0] + vector[0]) \
             + axis_vector[1]*(Surface.surface_coefficients[1] + vector[1]) \
             + axis_vector[2]*(Surface.surface_coefficients[2] + vector[2]) 

        self.last_free_surface_index += 1
        surface_string = str(self.last_free_surface_index) + " p "
        for coeff in axis_vector:
            surface_string += str(coeff) + " "
        surface_string += str(d2)
        surf = MCNPSurfaceCard(surface_string) # todo maybe instanciate explicitly generically?
        new_surf_list.append(surf)

        cell_description_inside = "("
        cell_description_inside += " -" + str(new_surf_list[0].surface_id)
        cell_description_inside += " -" + str(new_surf_list[1].surface_id)
        cell_description_inside += " -"  + str(new_surf_list[2].surface_id)
        cell_description_inside += ")"

        cell_description_outside = "("
        cell_description_outside += str(new_surf_list[0].surface_id)
        cell_description_outside += ":" + str(new_surf_list[1].surface_id)
        cell_description_outside += ":" + str(new_surf_list[2].surface_id)
        cell_description_outside += ")"

        cell_description = [cell_description_inside,cell_description_outside]

        return new_surf_list, cell_description