Exemplo n.º 1
0
def geom_to_h5(domain_shape, feature_count, nd_radius, out_filename=None, prefix=None):
    # Calculate the aspect of the domain (usually 1,1[,1])
    aspect = tuple(array(domain_shape)/domain_shape[0])
    
    # Generate the random points
    print "Packing. . .",
    t = time.time()
    points = random_pack_nd_points(aspect, nd_radius, feature_count)
    print time.time() - t, "seconds . . ."
    
    # Generate the actual solid array
    print "Creating array. . .",
    t = time.time()
    solid_array = nd_points_to_domain(points, nd_radius, domain_shape)
    print time.time() - t, "seconds . . ."

    # Generate the automatic name
    if out_filename==None:
        print "Creating file name hash. . .",
        t = time.time()
        out_filename = os.path.join(prefix, name_file(solid_array, int( (1. / nd_radius) + 0.5), feature_count))
        print time.time() - t, "seconds . . ."

    # Write the solid array to the h5 file
    print "Writing to h5. . .",
    t = time.time()
    hdf5.write_S(out_filename, solid_array)

    # Write the geometry
    hdf5.write_geometry(out_filename, points, nd_radius * ones(feature_count))
    print time.time() - t, "seconds . . ."
Exemplo n.º 2
0
def make_2d_cyl_validation_set(folder_to_save, lower=0.01, upper = 0.49, steps=100, shape = (200,200)):
    radii = linspace(lower, upper, steps)

    for num, radius in enumerate(radii):
        filename = os.path.join(folder_to_save, str(num) + ".h5")
        print num, filename
        domain = nd_points_to_domain(array([[0.5,0.5]]), radius, shape)    

        print "Writing for fraction:", domain.mean()

        hdf5.write_S(filename, domain)
        hdf5.write_geometry(filename, fcc[3], radius * ones(4))
Exemplo n.º 3
0
def make_3d_bcc_series(folder_to_save, number, resolution):
    radaii = linspace(0, 0.25 * sqrt(3), number+1)[0:]

    for num, radius in enumerate(radaii):
        print num
        domain = nd_points_to_domain(bcc[3], radius, resolution)    
        filename = os.path.join(folder_to_save, str(num) + ".h5")

        print "Writing for fraction:", domain.mean()

        hdf5.write_S(filename, domain)
        hdf5.write_geometry(filename, fcc[3], radius * ones(4))
Exemplo n.º 4
0
def make_3d_fcc_mesh_refine_study(smallest=10, largest=100, steps=10):
    mesh_sizes = linspace(smallest, largest, steps)

    radius = sqrt(2) / 4.
    for mesh_size in mesh_sizes:
        # Make the solid
        resolution = (mesh_size, mesh_size, mesh_size)
        domain = nd_points_to_domain(fcc[3], radius, resolution)
        
        mesh_str = "%ix%ix%i" % resolution
        print "Writing for fraction: %f (%s)" % (domain.mean(), mesh_str)

        filename = os.path.join("fcc-meshrefine", mesh_str + ".h5")
        hdf5.write_S(filename, domain)
        hdf5.write_geometry(filename, fcc[3], radius * ones(4))
Exemplo n.º 5
0
def seimran_geom_to_h5(domain_shape, feature_count, nd_radius, out_filename):
    # Calculate the aspect of the domain (usually 1,1[,1])
    aspect = tuple(array(domain_shape)/domain_shape[0])
    
    # Generate the random points
    points = semirandom_pack_nd_points(aspect, nd_radius, feature_count)

    # Generate the actual solid array
    solid_array = nd_points_to_domain(points, nd_radius, domain_shape)

    # Write the solid array to the h5 file
    hdf5.write_S(out_filename, solid_array)

    # Write the geometry
    hdf5.write_geometry(out_filename, points, nd_radius * ones(feature_count))
Exemplo n.º 6
0
def make_2_circle_series():
    nd_radius = 0.1
    aspect=(1.,1.)
    ndim = 2
    domain_shape = (150,150)
    
    center_point = array([[0.5,0.5]])
    for nx, dx in enumerate(linspace(0,0.5,100)):
        for ny, dy in enumerate(linspace(0,0.5,100)):
            new_point = center_point.copy()
            new_point[0,0] += dx
            new_point[0,1] += dy

            # Non periodic vector
            dist_vector = center_point - new_point

            # If a distance in a given vector direction is greater than half the domain width
            # Then the real distance is the domain length minus the apperent distance
            for dim in range(ndim):
                to_subtract = abs(dist_vector[:,dim]) > (aspect[dim]/2.)
                dist_vector[to_subtract,dim] = aspect[dim] - abs(dist_vector[to_subtract,dim])

            # Find Vector Magnitude 
            dist_vector = dist_vector ** 2
            dist = sqrt(dist_vector.sum(axis=1))
        
            too_close = dist < (2 * nd_radius)

            if too_close:
                continue

            points = r_[center_point, new_point]

            
            out_filename = "explore_two/x-%03i_y-%03i.h5" % (nx, ny)
            print out_filename
            # Generate the actual solid array
            solid_array = nd_points_to_domain(points, nd_radius, domain_shape)

            # Write the solid array to the h5 file
            hdf5.write_S(out_filename, solid_array)

            # Write the geometry
            hdf5.write_geometry(out_filename, points, nd_radius * ones(2))
Exemplo n.º 7
0
def make_3d_bcc_mesh_refine_study(smallest=10, largest=80, steps=8):
    mesh_sizes = linspace(smallest, largest, steps)

    print mesh_sizes

    # Match exactly zick's concentration
    conc = 0.6
    radius = (conc * (3./(8 * pi)))**(1./3)

    for mesh_size in mesh_sizes:
        # Make the solid
        resolution = (mesh_size, mesh_size, mesh_size)
        domain = nd_points_to_domain(bcc[3], radius, resolution)
        
        mesh_str = "%ix%ix%i" % resolution
        print "Writing for fraction: %f (%s)" % (domain.mean(), mesh_str)

        filename = os.path.join("bcc-final-0.6-final-refine", mesh_str + ".h5")
        hdf5.write_S(filename, domain)
        hdf5.write_geometry(filename, bcc[3], radius * ones(2))
Exemplo n.º 8
0
def points_to_sim(filename, points, ndradius, extent):
    point_count = points.shape[0]
    domain = nd_points_to_domain(points, ndradius, extent)
    print "Domain Fraction:", domain.mean()
    hdf5.write_S(filename, domain)
    hdf5.write_geometry(filename, points, ndradius * ones(point_count))