コード例 #1
0
def test_2d_5():
    # Domain with many little stellar holes
    # Define the rectangles
    width = 2
    height = 2
    rect_out = [(0, 0), (2, 2)]
    rect_in_1 = [(.25, .25), (.75, .75)]
    rect_in_2 = [(1.25, .25), (1.75, .75)]
    rect_in_3 = [(1.25, 1.25), (1.75, 1.75)]
    rect_in_4 = [(.25, 1.25), (.75, 1.75)]

    # Set periodic_boundary, True or False for outer rectangle

    topo = Topology(rect_out, [rect_in_1, rect_in_2, rect_in_3, rect_in_4],
                    periodic_boundary=True)

    # Make some holes
    N = 50
    counter = 0
    i = 0
    while counter < N and i < 1000:
        i += 1
        print(i)
        midpoint_s = rd.uniform(0, width), rd.uniform(0, height)
        radius = rd.uniform(0, .5)
        stellar_hole = Circle(midpoint_s, radius)

        if topo.add_hole(stellar_hole, refs=30):
            counter += 1

    print("Needed ", i, "runs for ", N, "holes")

    # Make geometry, set filled True or False if the inclusion is a hole or not
    geo = topo.get_geometry(filled=True)
    write_geo(geo, "test")
コード例 #2
0
    def createTopology(x0, y0, periodic_boundary=False):

        rect_out = [(x0,y0),(x0 + width, y0 + height)]

        rects_in = []   

        # local placement of rectangles   s1 free  s2 rect  s3 free
        s1, s2, s3 = 1./4, 1./2, 1./4    # must sum to 1
        
        w_loc = width / N   # local width  of a N equidistant subdivided rectangles from Domain one
        h_loc = height / N  # local height of a N equidistant subdivided rectangles from Domain one

        xshift = s1*w_loc  # midpoint offset for rectangle in x direction
        yshift = s1*h_loc  # midpoint offset for rectangle in y direction

        w = s2 * w_loc  # width of subrectangle
        h = s2 * h_loc  # height of subrectangle

        for i in range( N ) : 
            for j in range( N ) : 
                # midpoint of new sub rectangle
                M = xshift + i * w_loc,  yshift + j * h_loc
                rect = [(M[0],M[1]),(M[0]+w,M[1]+h)]
                rects_in.append(rect)           
        


        discrete_Holes = []

    
        refs = 40      # refs for the interior inclusions


        if not loadbug : 
            # Set periodic_boundary, True or False for outer rectangle
            topo = Topology(rect_out, rects_in, periodic_boundary= periodic_boundary)

            nCounter = 0
            #for k in range(100):
            while nCounter < nHoles:
                    
                midpoint_s = rd.uniform(0, width), rd.uniform(0, height)
                radius = 0.015 * min(width, height)  #rd.uniform(0,.1)
                stellar_hole = Circle(midpoint_s,radius) 
                        
                if topo.add_hole(stellar_hole,refs=refs): 
                    discrete_Holes.append(stellar_hole.discretize_hole(refs))
                    nCounter += 1

                    # make a random composite material via filled setted to true option
            topo.safe_json(fname)
                    
            # write geo file
            topo.write_geo(fname, filled = filled, lc_in=.025, lc_out=.025)
            print("Geo file written : ", fname)

        else : 
            topo = Topology.load_topology("bug")
コード例 #3
0
def test_2d_3():
    width = 2
    height = 2
    rect_out = [(0, 0), (2, 2)]
    rect_in = [(.5, .5), (1.5, 1.5)]
    rect_in_1 = [(.25, .25), (.75, .75)]
    rect_in_2 = [(1.25, .25), (1.75, .75)]
    rect_in_3 = [(1.25, 1.25), (1.75, 1.75)]
    rect_in_4 = [(.25, 1.25), (.75, 1.75)]

    #topo = Topology(rect_out, [rect_in_1, rect_in_2,rect_in_3,rect_in_4])
    topo = Topology(rect_out, [rect_in])

    #midpoint_s = rd.uniform(0, width), rd.uniform(0, height)
    midpoint_s = (.5, 1)  # TODO: check error!
    ## this way you define a Stellar hole
    stellar_hole = Circle(midpoint_s, .05)

    topo.add_hole(stellar_hole, refs=10)

    midpoint_s = (.51, 1.51)  # TODO: check error!
    # this way you define a Stellar hole
    stellar_hole = Circle(midpoint_s, .05)

    topo.add_hole(stellar_hole, refs=10)

    #midpoint_s = (.51,.51) # TODO: check error!
    # this way you define a Stellar hole
    #stellar_hole = Circle(midpoint_s, .05)

    #topo.add_hole(stellar_hole,refs=10)

    #midpoint_s = (.01,.01) # TODO: check error!
    # this way you define a Stellar hole
    #stellar_hole = Circle(midpoint_s, .05)

    #topo.add_hole(stellar_hole,refs=10)

    topo.write_geo("test", flag="hole")
コード例 #4
0
def test_2d_4():
    rect_out = [(0, 0), (2, 2)]

    rect_in_1 = [(.25, .25), (.75, .75)]
    rect_in_2 = [(1.25, .25), (1.75, .75)]
    rect_in_3 = [(1.25, 1.25), (1.75, 1.75)]
    rect_in_4 = [(.25, 1.25), (.75, 1.75)]

    topo = Topology(rect_out, [rect_in_1, rect_in_2, rect_in_3, rect_in_4],
                    periodic_boundary=False)

    midpoint_s = (1, .01)
    stellar_hole = Circle(midpoint_s, .05)
    added = topo.add_hole(stellar_hole, refs=10)

    midpoint_s = (2.01, .01)
    stellar_hole = Circle(midpoint_s, .05)
    added = topo.add_hole(stellar_hole, refs=20)

    midpoint_s = (.251, .251)
    stellar_hole = Circle(midpoint_s, .05)
    added = topo.add_hole(stellar_hole, refs=10)

    midpoint_s = (.251, .51)
    stellar_hole = Circle(midpoint_s, .05)
    added = topo.add_hole(stellar_hole, refs=10)

    midpoint_s = (1.251, 1.251)
    stellar_hole = Circle(midpoint_s, .05)
    added = topo.add_hole(stellar_hole, refs=10)

    midpoint_s = (.4, .4)
    stellar_hole = Circle(midpoint_s, .05)
    added = topo.add_hole(stellar_hole, refs=10)

    midpoint_s = (1.751, 1.251)
    stellar_hole = Circle(midpoint_s, .05)
    added = topo.add_hole(stellar_hole, refs=10)

    midpoint_s = (1.251, 1.751)
    stellar_hole = Circle(midpoint_s, .05)
    added = topo.add_hole(stellar_hole, refs=10)

    geo = topo.get_geometry(filled=True)
    write_geo(geo, "test")
コード例 #5
0
def CouldNotProcessBugMinimal(verbose = False):
    width = 1.
    height = 1.
    domain = {"x0" : 0, 
              "y0" : 0, 
              "w"  : width,
              "h"  : height
    }
    x0, y0 = (domain["x0"], domain["y0"]) 

    N = 2
    filled = True

    rect_out = [(x0,y0),(x0 + width, y0 + height)]

    rects_in = []   

    # local placement of rectangles   s1 free  s2 rect  s3 free
    s1, s2, s3 = 1./4, 1./2, 1./4    # must sum to 1
        
    w_loc = width / N   # local width  of a N equidistant subdivided rectangles from Domain one
    h_loc = height / N  # local height of a N equidistant subdivided rectangles from Domain one

    xshift = s1*w_loc  # midpoint offset for rectangle in x direction
    yshift = s1*h_loc  # midpoint offset for rectangle in y direction

    w = s2 * w_loc  # width of subrectangle
    h = s2 * h_loc  # height of subrectangle

    for i in range( N ) : 
        for j in range( N ) : 
            # midpoint of new sub rectangle
            M = xshift + i * w_loc,  yshift + j * h_loc
            rect = [(M[0],M[1]),(M[0]+w,M[1]+h)]
            rects_in.append(rect)           
  

    refsNew = 40      # the number of refs does not change the appearance of the bug
    periodic_boundary = False

    topo = Topology(rect_out, rects_in, periodic_boundary= periodic_boundary, method = 'linear')


    if verbose:
        plt.plot( [domain["x0"], domain["x0"]+domain["w"], domain["x0"]+domain["w"], domain["x0"], domain["x0"]],
                    [domain["y0"], domain["y0"], domain["y0"]+domain["h"], domain["y0"]+domain["h"], domain["y0"]],
                    'k--'
            )

        for rect in rects_in : 
            A, B = rect[0], rect[1]

            plt.plot([A[0], B[0], B[0], A[0], A[0]], [A[1],A[1],B[1],B[1],A[1]], 'k--', linewidth = 0.5)


    with open("bugHole" + ".json", 'r') as fp:
        holes_json = json.load(fp)
        k = '0'
        hole_data, refs = holes_json[k]

        M , r = hole_data['midpoint'], hole_data['radius']

        if verbose : 
            s = 2*pi / refs
            x = [M[0] + r * np.cos( n * s * 2*np.pi) for n in range(refsNew)]
            y = [M[1] + r * np.sin( n * s * 2*np.pi) for n in range(refsNew)]
            plt.plot(x,y, 'r.', ms = 3)
            plt.show()



        hole = Circle(M, r)
        topo.add_hole(hole,refs=refsNew)

        fname = "bugHole"

        topo.write_geo(fname, filled = filled, lc_in=.025, lc_out=.025)
        print("Geo file written : ", fname)


        topoOpt = Topology(rect_out, rects_in, periodic_boundary= periodic_boundary, method = 'optimise')
        topoOpt.add_hole(hole,refs=refsNew)
        topoOpt.write_geo(fname+'Opt', filled = filled, lc_in=.025, lc_out=.025)

        #exit()
        mesh = dolfin_mesh(fname)
        meshOpt = dolfin_mesh(fname+'Opt')

        #plt.subplot(1,2,1)
        plot(mesh, color = 'red')

        #plt.subplot(1,2,2)
        plot(meshOpt, color = 'blue')
        plt.show()
コード例 #6
0
def ExtractProcessBug():
    width = 1.
    height = 1.
    domain = {"x0" : 0, 
              "y0" : 0, 
              "w"  : width,
              "h"  : height
    }
    x0, y0 = (domain["x0"], domain["y0"]) 

    N = 2
    nHoles = 100
    filled = True

    rect_out = [(x0,y0),(x0 + width, y0 + height)]

    rects_in = []   

    # local placement of rectangles   s1 free  s2 rect  s3 free
    s1, s2, s3 = 1./4, 1./2, 1./4    # must sum to 1
        
    w_loc = width / N   # local width  of a N equidistant subdivided rectangles from Domain one
    h_loc = height / N  # local height of a N equidistant subdivided rectangles from Domain one

    xshift = s1*w_loc  # midpoint offset for rectangle in x direction
    yshift = s1*h_loc  # midpoint offset for rectangle in y direction

    w = s2 * w_loc  # width of subrectangle
    h = s2 * h_loc  # height of subrectangle

    for i in range( N ) : 
        for j in range( N ) : 
            # midpoint of new sub rectangle
            M = xshift + i * w_loc,  yshift + j * h_loc
            rect = [(M[0],M[1]),(M[0]+w,M[1]+h)]
            rects_in.append(rect)           
        
    discrete_Holes = []

    refs = 40      # refs for the interior inclusions
    periodic_boundary = False


    topo = Topology(rect_out, rects_in, periodic_boundary= periodic_boundary)

    file_name = "notProcessBug"

    with open(file_name + ".json", 'r') as fp:
        holes_json = json.load(fp)

        #print(holes_json)

        k = 0

        while str(k) in holes_json:
            hole_data, refs, added = holes_json[str(k)]

            print(str(k), " : ", holes_json[str(k)], "\n")

            hole = Circle(hole_data['midpoint'], hole_data['radius'])
            if str(k) == '36':
                bugHole = {}
                bugHole[0] = [hole.to_dict() , refs]

                with open("bugHole" + ".json", 'w') as fp:
                    json.dump(bugHole, fp, indent=2)


                topo.add_hole(hole,refs=refs)

            k+=1
コード例 #7
0
def couldNotProcessBug(fname):
    width = 1.
    height = 1.
    domain = {"x0" : 0, 
              "y0" : 0, 
              "w"  : width,
              "h"  : height
    }
    x0, y0 = (domain["x0"], domain["y0"]) 

    N = 2
    nHoles = 100
    filled = True

    rect_out = [(x0,y0),(x0 + width, y0 + height)]

    rects_in = []   

    # local placement of rectangles   s1 free  s2 rect  s3 free
    s1, s2, s3 = 1./4, 1./2, 1./4    # must sum to 1
        
    w_loc = width / N   # local width  of a N equidistant subdivided rectangles from Domain one
    h_loc = height / N  # local height of a N equidistant subdivided rectangles from Domain one

    xshift = s1*w_loc  # midpoint offset for rectangle in x direction
    yshift = s1*h_loc  # midpoint offset for rectangle in y direction

    w = s2 * w_loc  # width of subrectangle
    h = s2 * h_loc  # height of subrectangle

    for i in range( N ) : 
        for j in range( N ) : 
            # midpoint of new sub rectangle
            M = xshift + i * w_loc,  yshift + j * h_loc
            rect = [(M[0],M[1]),(M[0]+w,M[1]+h)]
            rects_in.append(rect)           
        
    discrete_Holes = []

    refs = 40      # refs for the interior inclusions
    periodic_boundary = False



    M = 100 


    for m in range(M):

        print(" =================== START NEW TOPOLOGY ===================")

        topo = Topology(rect_out, rects_in, periodic_boundary= periodic_boundary)


        hNa = 0    # attempted hole number
        ddict = {} # debug storage dict


        nCounter = 0
        #for k in range(100):
        while nCounter < nHoles:
                    
            midpoint_s = rd.uniform(0, width), rd.uniform(0, height)
            radius = 0.015 * min(width, height)  #rd.uniform(0,.1)
            hole = Circle(midpoint_s,radius) 

            ddict[hNa] = [hole.to_dict() , refs, False]

            hNa +=1


            with open(fname + ".json", 'w') as fp:
                json.dump(ddict, fp, indent=2)

                        
            if topo.add_hole(hole,refs=refs): 
                nCounter += 1

                ddict[hNa-1][2] = True  # hole has been added