Example #1
0
    def setup_indices_polygon(self):

        # Determine indices for polygonal region
        points = self.domain.get_centroid_coordinates(absolute=True)
        vertex_coordinates = self.domain.get_vertex_coordinates(absolute=True)

        indices = inside_polygon(points, self.polygon)

        if self.expand_polygon:
            n = len(self.polygon)
            for j in range(n):
                tris_0 = line_intersect(
                    vertex_coordinates,
                    [self.polygon[j], self.polygon[(j + 1) % n]])
                indices = num.union1d(tris_0, indices)

        if len(indices) == 0:
            self.indices = indices
        else:
            self.indices = num.asarray(indices)

        if not self.domain.parallel:
            # only warn if not parallel as we should get lots of subdomains without indices
            if len(indices) == 0:
                msg = 'No centroids found for polygon %s ' % str(self.polygon)
                import warnings
                warnings.warn(msg)
Example #2
0
    def setup_indices_polygon(self):

        # Determine indices for polygonal region
        points = self.domain.get_centroid_coordinates(absolute=True)
        vertex_coordinates = self.domain.get_vertex_coordinates(absolute=True)
        
        indices = inside_polygon(points, self.polygon)

        if self.expand_polygon :
            n = len(self.polygon)
            for j in range(n):
                tris_0 = line_intersect(vertex_coordinates,
                                        [self.polygon[j],self.polygon[(j+1)%n]])
                indices = num.union1d(tris_0, indices)            

        if len(indices) is 0:
            self.indices = indices
        else:
            self.indices = num.asarray(indices)

        
        if not self.domain.parallel:
            # only warn if not parallel as we should get lots of subdomains without indices
            if len(indices) is 0:
                msg = 'No centroids found for polygon %s '% str(self.polygon)
                import warnings
                warnings.warn(msg)
    def compute_triangle_indices(self):


        domain_centroids = self.domain.get_centroid_coordinates(absolute=True)
        vertex_coordinates = self.domain.get_full_vertex_coordinates(absolute=True)


        if self.line: # poly is a line
            self.triangle_indices = line_intersect(vertex_coordinates, self.poly)

        else: # poly is a polygon

            tris_0 = line_intersect(vertex_coordinates, [self.poly[0],self.poly[1]])
            tris_1 = inside_polygon(domain_centroids, self.poly)
            self.triangle_indices = num.union1d(tris_0, tris_1)
            #print self.triangle_indices

        for i in self.triangle_indices:
            assert self.domain.tri_full_flag[i] == 1
Example #4
0
    def compute_triangle_indices(self):

        domain_centroids = self.domain.get_centroid_coordinates(absolute=True)
        vertex_coordinates = self.domain.get_full_vertex_coordinates(
            absolute=True)

        if self.line:  # poly is a line
            self.triangle_indices = line_intersect(vertex_coordinates,
                                                   self.poly)

        else:  # poly is a polygon

            tris_0 = line_intersect(vertex_coordinates,
                                    [self.poly[0], self.poly[1]])
            tris_1 = inside_polygon(domain_centroids, self.poly)
            self.triangle_indices = num.union1d(tris_0, tris_1)
            #print self.triangle_indices

        for i in self.triangle_indices:
            assert self.domain.tri_full_flag[i] == 1
Example #5
0
    def setup_indices_line(self):

        # Determine indices for triangles intersecting a line  region
        
        vertex_coordinates = self.domain.get_vertex_coordinates(absolute=True)
        
        indices = line_intersect(vertex_coordinates, self.line) 
        
        if len(indices) is 0:
            self.indices = indices
        else:
            self.indices = num.asarray(indices)

        if not self.domain.parallel:
            msg = 'No centroids intersecting line %s '% str(self.line)
            if len(indices) is 0: raise Exception(msg)
Example #6
0
    def setup_indices_line(self):

        # Determine indices for triangles intersecting a line  region

        vertex_coordinates = self.domain.get_vertex_coordinates(absolute=True)

        indices = line_intersect(vertex_coordinates, self.line)

        if len(indices) == 0:
            self.indices = indices
        else:
            self.indices = num.asarray(indices)

        if not self.domain.parallel:
            msg = 'No centroids intersecting line %s ' % str(self.line)
            if len(indices) == 0: raise Exception(msg)
def allocate_inlet_procs(domain,
                         poly,
                         enquiry_point=None,
                         master_proc=0,
                         procs=None,
                         verbose=False):

    import pypar
    if procs is None:
        procs = range(0, pypar.size())

    myid = pypar.rank()
    vertex_coordinates = domain.get_full_vertex_coordinates(absolute=True)
    domain_centroids = domain.centroid_coordinates
    size = 0
    has_enq_point = False
    numprocs = pypar.size()

    inlet_procs = []
    max_size = -1
    inlet_master_proc = -1
    inlet_enq_proc = -1

    # Calculate the number of points of the line inside full polygon

    #tri_id = line_intersect(vertex_coordinates, poly)

    if len(poly) == 2:  # poly is a line
        if verbose: print "======================"
        tri_id = line_intersect(vertex_coordinates, poly)
    else:  # poly is a polygon
        if verbose: print "+++++++++++++++++++++++"
        tris_0 = line_intersect(vertex_coordinates, [poly[0], poly[1]])
        tris_1 = inside_polygon(domain_centroids, poly)
        tri_id = num.union1d(tris_0, tris_1)

    if verbose:
        print "P%d has %d triangles in poly %s" % (myid, len(tri_id), poly)

    size = len(tri_id)

    if enquiry_point is not None:
        try:
            k = domain.get_triangle_containing_point(enquiry_point)

            if domain.tri_full_flag[k] == 1:
                size = size + 1
                has_enq_point = True
                if verbose:
                    print "P%d has enq point %s" % (myid, enquiry_point)
            else:
                if verbose:
                    print "P%d contains ghost copy of enq point %s" % (
                        myid, enquiry_point)
                has_enq_point = False
        except:
            if verbose:
                print "P%d does not contain enq point %s" % (myid,
                                                             enquiry_point)
            has_enq_point = False

    if myid == master_proc:
        # Recieve size of overlap from each processor
        # Initialize line_master_proc and inlet_procs

        if size > 0:
            inlet_procs = [master_proc]
            max_size = size
            inlet_master_proc = master_proc
            if has_enq_point:
                inlet_enq_proc = master_proc

        # Recieve size of overlap
        for i in procs:
            if i == master_proc: continue
            x = pypar.receive(i)
            y = pypar.receive(i)

            if x > 0:
                inlet_procs.append(i)

                # Choose inlet_master_proc as the one with the most overlap
                if x > max_size:
                    max_size = x
                    inlet_master_proc = i

                if y is True:
                    assert inlet_enq_proc == -1, "Enquiry point correspond to more than one proc"
                    inlet_enq_proc = i

        assert len(inlet_procs) > 0, "Line does not intersect any domain"
        assert inlet_master_proc >= 0, "No master processor assigned"

        if enquiry_point is not None:
            msg = "Enquiry point %s doesn't intersect mesh, maybe inside a building, try reducing enquiry_gap" % str(
                enquiry_point)
            if inlet_enq_proc < 0:
                raise Exception(msg)

        # Send inlet_master_proc and inlet_procs to all processors in inlet_procs
        for i in procs:
            if i != master_proc:
                pypar.send(inlet_master_proc, i)
                pypar.send(inlet_procs, i)
                pypar.send(inlet_enq_proc, i)

    else:
        pypar.send(size, master_proc)
        pypar.send(has_enq_point, master_proc)

        inlet_master_proc = pypar.receive(master_proc)
        inlet_procs = pypar.receive(master_proc)
        inlet_enq_proc = pypar.receive(master_proc)
        if has_enq_point:
            assert inlet_enq_proc == myid, "Enquiry found in proc, but not declared globally"

    if size > 0:
        return True, inlet_master_proc, inlet_procs, inlet_enq_proc
    else:
        return False, inlet_master_proc, inlet_procs, inlet_enq_proc
Example #8
0
def allocate_inlet_procs(domain, poly, enquiry_point = None, master_proc = 0, procs = None, verbose = False):


    import pypar
    if procs is None:
        procs = range(0, pypar.size())

    myid = pypar.rank()
    vertex_coordinates = domain.get_full_vertex_coordinates(absolute=True)
    domain_centroids = domain.centroid_coordinates
    size = 0
    has_enq_point = False
    numprocs = pypar.size()

    inlet_procs = []
    max_size = -1
    inlet_master_proc = -1
    inlet_enq_proc = -1

    # Calculate the number of points of the line inside full polygon

    #tri_id = line_intersect(vertex_coordinates, poly)

    if len(poly) == 2: # poly is a line
        if verbose : print "======================"
        tri_id = line_intersect(vertex_coordinates, poly)
    else: # poly is a polygon
        if verbose : print "+++++++++++++++++++++++"
        tris_0 = line_intersect(vertex_coordinates, [poly[0],poly[1]])
        tris_1 = inside_polygon(domain_centroids, poly)
        tri_id = num.union1d(tris_0, tris_1)


    if verbose:
        print "P%d has %d triangles in poly %s" %(myid, len(tri_id), poly)

    size = len(tri_id)

    if enquiry_point is not None:
        try:
            k = domain.get_triangle_containing_point(enquiry_point)

            if domain.tri_full_flag[k] == 1:
                size = size + 1
                has_enq_point = True
                if verbose: print "P%d has enq point %s" %(myid, enquiry_point)
            else:
                if verbose: print "P%d contains ghost copy of enq point %s" %(myid, enquiry_point)
                has_enq_point = False
        except:
            if verbose: print "P%d does not contain enq point %s" %(myid, enquiry_point)
            has_enq_point = False

    if myid == master_proc:
        # Recieve size of overlap from each processor
        # Initialize line_master_proc and inlet_procs

        if size > 0:
            inlet_procs = [master_proc]
            max_size = size
            inlet_master_proc = master_proc
            if has_enq_point:
                inlet_enq_proc = master_proc

        # Recieve size of overlap
        for i in procs:
            if i == master_proc: continue
            x = pypar.receive(i)
            y = pypar.receive(i)

            if x > 0:
                inlet_procs.append(i)

                # Choose inlet_master_proc as the one with the most overlap
                if x > max_size:
                    max_size = x
                    inlet_master_proc = i

                if y is True:
                    assert inlet_enq_proc == -1, "Enquiry point correspond to more than one proc"
                    inlet_enq_proc = i

        assert len(inlet_procs) > 0, "Line does not intersect any domain"
        assert inlet_master_proc >= 0, "No master processor assigned"

        if enquiry_point is not None:
            msg = "Enquiry point %s doesn't intersect mesh, maybe inside a building, try reducing enquiry_gap" % str(enquiry_point)
            if inlet_enq_proc < 0:
                raise Exception(msg)

        # Send inlet_master_proc and inlet_procs to all processors in inlet_procs
        for i in procs:
            if i != master_proc:
                pypar.send(inlet_master_proc, i)
                pypar.send(inlet_procs, i)
                pypar.send(inlet_enq_proc, i)

    else:
        pypar.send(size, master_proc)
        pypar.send(has_enq_point, master_proc)

        inlet_master_proc = pypar.receive(master_proc)
        inlet_procs = pypar.receive(master_proc)
        inlet_enq_proc = pypar.receive(master_proc)
        if has_enq_point: assert inlet_enq_proc == myid, "Enquiry found in proc, but not declared globally"

    if size > 0:
        return True, inlet_master_proc, inlet_procs, inlet_enq_proc
    else:
        return False, inlet_master_proc, inlet_procs, inlet_enq_proc