コード例 #1
0
ファイル: geometry.py プロジェクト: gimac/pyrticle
 def refine_func(vertices, area):
     from pytools import average
     centroid_y = average(vertex[1] for vertex in vertices)
     if a[1]+fine_start_h <= centroid_y <= a[1]+fine_end_h:
         return area > inner_max_area
     else:
         return area > max_area
コード例 #2
0
ファイル: static_field.py プロジェクト: ra2003/pyrticle
    def __init__(self, units, mass, charge, c, ez, bz, radius, nparticles):
        self.units = units
        self.ez = ez
        self.bz = bz
        StaticFieldSetup.__init__(self, mass, charge, c)

        if nparticles == 1:
            self.particle_offsets = [numpy.zeros((3, ))]
        elif nparticles == 4:
            self.particle_offsets = [
                numpy.array([-0.1, -0.1, 0]),
                numpy.array([0.1, -0.1, 0]),
                numpy.array([-0.1, 0.1, 0]),
                numpy.array([0.1, 0.1, 0])
            ]
        else:
            raise ValueError, "invalid number of particles"

        self.shift = numpy.zeros((3, ))

        c = self.c = self.units.VACUUM_LIGHT_SPEED()
        self.R = mass * c / (charge * bz)  # converted to SI
        self.rho = ez / (c * bz)  # converted to SI

        self.scaling = radius / self.R

        from pytools import average
        self.shift[2] = average(self.positions(0))[2]

        self._check_t_phi()
        self._check_velocities(deriv_dt=1e-14,
                               threshold=1e-8,
                               final_time=self.R / self.c)
コード例 #3
0
ファイル: static_field.py プロジェクト: gimac/pyrticle
    def __init__(self, units, mass, charge, c, ez, bz, radius, nparticles):
        self.units = units
        self.ez = ez
        self.bz = bz
        StaticFieldSetup.__init__(self, mass, charge, c)

        if nparticles == 1:
            self.particle_offsets = [numpy.zeros((3,))]
        elif nparticles == 4:
            self.particle_offsets = [
                    numpy.array([-0.1, -0.1, 0]),
                    numpy.array([ 0.1, -0.1, 0]),
                    numpy.array([-0.1,  0.1, 0]),
                    numpy.array([ 0.1,  0.1, 0])
                    ]
        else:
            raise ValueError, "invalid number of particles"

        self.shift = numpy.zeros((3,))

        c = self.c = self.units.VACUUM_LIGHT_SPEED()
        self.R = mass*c/(charge*bz) # converted to SI
        self.rho = ez/(c*bz) # converted to SI

        self.scaling = radius/self.R

        from pytools import average
        self.shift[2] = average(self.positions(0))[2]

        self._check_t_phi()
        self._check_velocities(deriv_dt=1e-14, threshold=1e-8, final_time=self.R/self.c)
コード例 #4
0
ファイル: geometry.py プロジェクト: ra2003/pyrticle
 def refine_func(vertices, area):
     from pytools import average
     centroid_y = average(vertex[1] for vertex in vertices)
     if a[1] + fine_start_h <= centroid_y <= a[1] + fine_end_h:
         return area > inner_max_area
     else:
         return area > max_area
コード例 #5
0
ファイル: local.py プロジェクト: yangzilongdmgy/hedge
 def order_number_for_node_tuple(nt):
     faces = self.faces_for_node_tuple(nt)
     if not faces:
         return -1
     elif len(faces) >= 3:
         return 1000
     else:
         return average(faces)
コード例 #6
0
ファイル: local.py プロジェクト: allansnielsen/hedge
 def order_number_for_node_tuple(nt):
     faces = self.faces_for_node_tuple(nt)
     if not faces:
         return -1
     elif len(faces) >= 3:
         return 1000
     else:
         return average(faces)
コード例 #7
0
ファイル: meshdata.py プロジェクト: gimac/pyrticle
    def fill_from_hedge(self, discr):
        self.discr = discr

        # add periodicity -----------------------------------------------------
        from pyrticle._internal import PeriodicityAxis
        for axis, ((ax_min, ax_max), periodicity_tags) in enumerate(zip(
                zip(*discr.mesh.bounding_box()), discr.mesh.periodicity)):
            pa = PeriodicityAxis()
            if periodicity_tags is not None:
                pa.min = ax_min
                pa.max = ax_max
            else:
                pa.min = 0
                pa.max = 0
            self.periodicities.append(pa)

        # add elements --------------------------------------------------------
        mesh = discr.mesh

        neighbor_map = {}
        for face, (e2, f2) in discr.mesh.both_interfaces():
            neighbor_map[face] = e2.id
        from hedge.mesh import TAG_ALL
        for face in discr.mesh.tag_to_boundary[TAG_ALL]:
            neighbor_map[face] = MeshData.INVALID_ELEMENT

        from pyrticle._internal import ElementInfo, FaceInfo

        self.element_info.reserve(len(mesh.elements))
        for i, el in enumerate(mesh.elements):
            ei = ElementInfo()
            ei.id = i
            ei.inverse_map = el.inverse_map
            ei.norm_forward_map = la.norm(el.map.matrix, 2)
            ei.jacobian = abs(el.map.jacobian())
            el_range = discr.find_el_range(el.id)
            ei.start, ei.end = el_range.start, el_range.stop

            ei.vertices.extend([int(vi) for vi in el.vertex_indices])

            all_face_vertex_indices = el.face_vertices(el.vertex_indices)

            for face_idx, face_normal in enumerate(el.face_normals):
                fi = FaceInfo()
                fi.normal = face_normal
                fi.neighbor = neighbor_map[el, face_idx] 

                this_fvi = all_face_vertex_indices[face_idx]
                try:
                    fi.neighbor_periodicity_axis = mesh.periodic_opposite_faces[this_fvi][1]
                except KeyError:
                    fi.neighbor_periodicity_axis = MeshData.INVALID_AXIS

                this_face_vertices = [mesh.points[fvi] 
                        for fvi in all_face_vertex_indices[face_idx]]

                rhs = [numpy.dot(face_normal, fv) for fv in this_face_vertices]
                from pytools import all_roughly_equal, average
                assert all_roughly_equal(rhs, 1e-14)

                fi.face_plane_eqn_rhs = average(rhs)
                fi.face_centroid = average(this_face_vertices)

                fi.face_radius_from_centroid = max(
                        la.norm(fv - fi.face_centroid) for fv in this_face_vertices)

                ei.faces.append(fi)

            self.element_info.append(ei)

        # add vertices --------------------------------------------------------
        vertex_to_element_map = {} # map vertex to (via_periodic, el_id)

        for el in mesh.elements:
            for vi in el.vertex_indices:
                vertex_to_element_map.setdefault(vi, set()).add((
                    _internal.MeshData.INVALID_AXIS, el.id))
                for other_vi, per_axis in mesh.periodic_opposite_vertices.get(vi, []):
                    vertex_to_element_map.setdefault(other_vi, set()).add((per_axis, el.id))

        self.set_vertices(mesh.points)

        from pyrticle._internal import UnsignedVector
        self.vertex_adj_elements.reserve(
                2*discr.dimensions*len(mesh.points))
        self.vertex_adj_element_starts.reserve(len(mesh.points))
        self.vertex_adj_element_starts.append(0)

        for vi in xrange(len(mesh.points)):
            adj_periodicity_axes, adj_ids = zip(*vertex_to_element_map[vi])
            self.vertex_adj_elements.extend(adj_ids)
            self.vertex_adj_periodicity_axes.extend(adj_periodicity_axes)
            self.vertex_adj_element_starts.append(
                    len(self.vertex_adj_elements))

        # add nodes -----------------------------------------------------------
        self.set_nodes(discr.nodes)
コード例 #8
0
ファイル: meshdata.py プロジェクト: ra2003/pyrticle
    def fill_from_hedge(self, discr):
        self.discr = discr

        # add periodicity -----------------------------------------------------
        from pyrticle._internal import PeriodicityAxis
        for axis, ((ax_min, ax_max), periodicity_tags) in enumerate(
                zip(zip(*discr.mesh.bounding_box()), discr.mesh.periodicity)):
            pa = PeriodicityAxis()
            if periodicity_tags is not None:
                pa.min = ax_min
                pa.max = ax_max
            else:
                pa.min = 0
                pa.max = 0
            self.periodicities.append(pa)

        # add elements --------------------------------------------------------
        mesh = discr.mesh

        neighbor_map = {}
        for face, (e2, f2) in discr.mesh.both_interfaces():
            neighbor_map[face] = e2.id
        from hedge.mesh import TAG_ALL
        for face in discr.mesh.tag_to_boundary[TAG_ALL]:
            neighbor_map[face] = MeshData.INVALID_ELEMENT

        from pyrticle._internal import ElementInfo, FaceInfo

        self.element_info.reserve(len(mesh.elements))
        for i, el in enumerate(mesh.elements):
            ei = ElementInfo()
            ei.id = i
            ei.inverse_map = el.inverse_map
            ei.norm_forward_map = la.norm(el.map.matrix, 2)
            ei.jacobian = abs(el.map.jacobian())
            el_range = discr.find_el_range(el.id)
            ei.start, ei.end = el_range.start, el_range.stop

            ei.vertices.extend([int(vi) for vi in el.vertex_indices])

            all_face_vertex_indices = el.face_vertices(el.vertex_indices)

            for face_idx, face_normal in enumerate(el.face_normals):
                fi = FaceInfo()
                fi.normal = face_normal
                fi.neighbor = neighbor_map[el, face_idx]

                this_fvi = all_face_vertex_indices[face_idx]
                try:
                    fi.neighbor_periodicity_axis = mesh.periodic_opposite_faces[
                        this_fvi][1]
                except KeyError:
                    fi.neighbor_periodicity_axis = MeshData.INVALID_AXIS

                this_face_vertices = [
                    mesh.points[fvi]
                    for fvi in all_face_vertex_indices[face_idx]
                ]

                rhs = [numpy.dot(face_normal, fv) for fv in this_face_vertices]
                from pytools import all_roughly_equal, average
                assert all_roughly_equal(rhs, 1e-14)

                fi.face_plane_eqn_rhs = average(rhs)
                fi.face_centroid = average(this_face_vertices)

                fi.face_radius_from_centroid = max(
                    la.norm(fv - fi.face_centroid)
                    for fv in this_face_vertices)

                ei.faces.append(fi)

            self.element_info.append(ei)

        # add vertices --------------------------------------------------------
        vertex_to_element_map = {}  # map vertex to (via_periodic, el_id)

        for el in mesh.elements:
            for vi in el.vertex_indices:
                vertex_to_element_map.setdefault(vi, set()).add(
                    (_internal.MeshData.INVALID_AXIS, el.id))
                for other_vi, per_axis in mesh.periodic_opposite_vertices.get(
                        vi, []):
                    vertex_to_element_map.setdefault(other_vi, set()).add(
                        (per_axis, el.id))

        self.set_vertices(mesh.points)

        from pyrticle._internal import UnsignedVector
        self.vertex_adj_elements.reserve(2 * discr.dimensions *
                                         len(mesh.points))
        self.vertex_adj_element_starts.reserve(len(mesh.points))
        self.vertex_adj_element_starts.append(0)

        for vi in xrange(len(mesh.points)):
            adj_periodicity_axes, adj_ids = zip(*vertex_to_element_map[vi])
            self.vertex_adj_elements.extend(adj_ids)
            self.vertex_adj_periodicity_axes.extend(adj_periodicity_axes)
            self.vertex_adj_element_starts.append(len(
                self.vertex_adj_elements))

        # add nodes -----------------------------------------------------------
        self.set_nodes(discr.nodes)