コード例 #1
0
ファイル: nd_domain.py プロジェクト: meawoppl/ndsolver
def hypersphere(filename):
    s = zeros((25,25,25,25))
    x, y, z, q = mgrid[-1:1:25j,-1:1:25j,-1:1:25j,-1:1:25j]
    dist = sqrt(x**2 + y**2 + z**2 + q**2)
    s[dist < dist] = 1.

    hdf5.write_S(filename, s)
コード例 #2
0
ファイル: nd_domain.py プロジェクト: meawoppl/ndsolver
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 . . ."
コード例 #3
0
ファイル: nd_domain.py プロジェクト: meawoppl/ndsolver
def make_dilute_meshstudy(start=10, stop=60, steps=11):
    for x in linspace(start,stop,steps):
        print "writing", x
        domain = zeros((x,x,x))
        domain[0,0,0] = 1

        mesh_str = "%ix%ix%i.h5" % (x,x,x)
        filename = os.path.join("dilute-refine", mesh_str)        

        hdf5.write_S(filename, domain)
コード例 #4
0
ファイル: nd_domain.py プロジェクト: meawoppl/ndsolver
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))
コード例 #5
0
ファイル: nd_domain.py プロジェクト: meawoppl/ndsolver
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))
コード例 #6
0
ファイル: nd_domain.py プロジェクト: meawoppl/ndsolver
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))
コード例 #7
0
ファイル: nd_domain.py プロジェクト: meawoppl/ndsolver
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))
コード例 #8
0
ファイル: nd_domain.py プロジェクト: meawoppl/ndsolver
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))
コード例 #9
0
ファイル: nd_domain.py プロジェクト: meawoppl/ndsolver
def make_halfpipe_meshrefine(smallest=10, largest=100, steps=10):
    mesh_sizes = linspace(smallest, largest, steps)

    print mesh_sizes

    # Match exactly zick's concentration
    for mesh_size in mesh_sizes:
        # Make the solid
        resolution = (mesh_size, mesh_size, mesh_size)
        x, y, z = mgrid[-1:1:1j*resolution[0],
                        -1:1:1j*resolution[0],
                        -1:1:1j*resolution[0]]

        domain = 1.0 * ((x**2 + y**2) > 0.5**2)

        mesh_str = "%ix%ix%i" % resolution
        print "Writing for fraction: %f (%s)" % (domain.mean(), mesh_str)

        filename = os.path.join("halfpipe", mesh_str + ".h5")
        hdf5.write_S(filename, domain)
コード例 #10
0
ファイル: nd_domain.py プロジェクト: meawoppl/ndsolver
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))
コード例 #11
0
ファイル: nd_domain.py プロジェクト: meawoppl/ndsolver
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))
コード例 #12
0
ファイル: cli.py プロジェクト: meawoppl/ndsolver
        # open the h5 and get the dimensionality
        h5 = hdf5.openFile(f)
        ndim = len(h5.root.geometry.S.shape)
        h5.close()
    else:
        # Default to trying an image . . .
        print f, "is not and HDF5 file . . . trying image?"
        S = 1. * ( misc.imread(f, flatten=True) < (255/2.) )

        # Appropriate image transformation to make x/y convention meaningful
        S = S[::-1].T

        ndim = 2

        # Make a h5 file for the results
        hdf5.write_S(save_path, S)

    # Get the domain dimensionality 
    print "Dimension:", ndim

    # Populate the pressure drops based on user input
    # Done here and not earlier b/c we need to know the dimensionality
    dPs = []
    # Have dp/dx
    if   options.x and ndim == 2:
        dPs.append((1,0))
    elif options.x and ndim == 3:
        dPs.append((1,0,0))

    # have dp/dy 
    if   options.y and ndim == 2: