当前位置: 首页>>代码示例>>Python>>正文


Python Geometry.get_outer_material方法代码示例

本文整理汇总了Python中geometry.Geometry.get_outer_material方法的典型用法代码示例。如果您正苦于以下问题:Python Geometry.get_outer_material方法的具体用法?Python Geometry.get_outer_material怎么用?Python Geometry.get_outer_material使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在geometry.Geometry的用法示例。


在下文中一共展示了Geometry.get_outer_material方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Simulation

# 需要导入模块: from geometry import Geometry [as 别名]
# 或者: from geometry.Geometry import get_outer_material [as 别名]
class Simulation(object):
    def __init__(self, universe_material, nbins, diameter=100., detector_width=100., detector='plane'):
        self.universe_material = universe_material
        self.geometry = Geometry()
        self.source = np.array([-diameter / 2., 0.])
        if detector == 'plane':
            self.detector = DetectorPlane([diameter / 2., 0.], detector_width, nbins)
        elif detector == 'arc':
            self.detector = DetectorArc(self.source, diameter, detector_width / 2., -detector_width / 2., nbins)

    def get_intersecting_segments(self, start, end, ray=False):
        """
        Find intersection points and lixels which intersect ray (start, end).
        """
        intercepts, indexes = [], []
        intersect_segment = np.array([start, end])

        for i, segment in enumerate(self.geometry.mesh.segments):
            intercept = math2d.intersect(segment, intersect_segment, ray)
            if intercept is not None:
                intercepts.append(intercept)
                indexes.append(i)

        return intercepts, indexes
   
    def attenuation_length(self, start, end):
        """
        Calculate attenuation length for geometry.

        Can account for starting and ending in any position.
        """
        intercepts, indexes = self.get_intersecting_segments(start, end)

        if len(intercepts) == 0:
            ray_intercepts, ray_indexes = self.get_intersecting_segments(start, end, ray=True)
            if len(ray_intercepts) == 0:
                return np.linalg.norm(start - end) * self.universe_material.attenuation

            distances = np.linalg.norm(np.add(ray_intercepts, -start), axis=1)
            distances_argmin = np.argmin(distances)
            closest_index = ray_indexes[distances_argmin]
            closest_intercept = ray_intercepts[distances_argmin]
            closest_normal = math2d.normal(self.geometry.mesh.segments[closest_index])
            start_sign = np.sign(np.dot(start - closest_intercept, closest_normal))

            if start_sign > 0:
                outer_atten = self.geometry.outer_materials[closest_index].attenuation
                atten_length = np.linalg.norm(start - end) * outer_atten
            else:
                inner_atten = self.geometry.inner_materials[closest_index].attenuation
                atten_length = np.linalg.norm(start - end) * inner_atten

            return atten_length

        distances = np.linalg.norm(np.add(intercepts, -start), axis=1)
        distances_argmin = np.argmin(distances)
        closest_index = indexes[distances_argmin]
        closest_intercept = intercepts[distances_argmin]
        closest_normal = math2d.normal(self.geometry.mesh.segments[closest_index])
        start_sign = np.sign(np.dot(start - closest_intercept, closest_normal))

        if start_sign > 0:
            outer_atten = self.geometry.outer_materials[closest_index].attenuation
            atten_length = np.linalg.norm(start - end) * outer_atten
        else:
            inner_atten = self.geometry.inner_materials[closest_index].attenuation
            atten_length = np.linalg.norm(start - end) * inner_atten

        for intercept, index in zip(intercepts, indexes):
            normal =  math2d.normal(self.geometry.mesh.segments[index])
            start_sign = np.sign(np.dot(start - intercept, normal))
            end_sign = np.sign(np.dot(end - intercept, normal))
            inner_atten = self.geometry.inner_materials[index].attenuation
            outer_atten = self.geometry.outer_materials[index].attenuation

            atten_length += start_sign * np.linalg.norm(intercept - end) * (inner_atten - outer_atten)
        
        return atten_length

    def fission_segments(self, start, end):
        """
        Return list of line segments where fissions may occur.
        """
        segments, cross_sections = [], []

        intercepts, indexes = self.get_intersecting_lixels(start, end)

        # otherwise
        fission_indexes = []
        fission_intercepts = []
        for index, intercept in zip(indexes, intercepts):
            # test if lixel is border of fissionable material(s)
            inner_material = self.geometry.get_inner_material(index)
            outer_material = self.geometry.get_outer_material(index)
            if inner_material.is_fissionable or outer_material.is_fissionable:
                fission_indexes.append(index)
                fission_intercepts.append(intercept)

        # account for no intersections with fissionable materials
        if len(fission_intercepts) == 0:
#.........这里部分代码省略.........
开发者ID:lynch829,项目名称:PyTracer,代码行数:103,代码来源:simulation.py


注:本文中的geometry.Geometry.get_outer_material方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。