def surface_areas(d): ''' input: origin-to-planes distances. volume_calc: the natural or unscaled volume of the polyhedron. area_p: areas of all the planes. points_p: interception points on the planes, grouped by plane. return: area_ps: the area of each plane family (sum of areas of surfaces of a plane family). ''' global Gamma_ratio ps_setd_mingled(number_planes, planes, d) planes_c = [p.as_list() for p in planes] pr = enclosure(planes_c) volume_calc = pr[0] # the natural or unscaled volume of the polyhedron. area_p = pr[1] # areas of all the planes. points_p = pr[2] # interception points on the planes, grouped by plane. area_ps = [ ] # area of each plane family: sum of areas of surfaces of a plane family. index_start = 0 for subset_n in number_planes: index_end = index_start + subset_n area_ps.append(np.sum(area_p[index_start:index_end])) index_start = index_end global volume diameter = 20.0 volume = 4.0 / 3.0 * np.pi * ( diameter * 0.5)**3 # this volume was used to scale the calculated volume. area_ps = np.array(area_ps) * np.power(volume / volume_calc, 2.0 / 3) return area_ps
def intersection_point(number_planes, planes, d): ''' Calculate the intersection points of surfaces of a plane family. ''' ps_setd_mingled(number_planes, planes, d) planes_c = [p.as_list() for p in planes] pr = enclosure(planes_c) points_p = pr[2] return points_p
def main(): print '' print '1. Format of surface families should be [[a1, b1, c1], [a2, b2, c2],...,[an, bn, cn]], n >= 1.' print '2. Distance between the center of the polyhedron and the surface should be positive.' print '3. Color (r, g, b) is represented by the number from 0 to 1.' print '' hkl = surface_index() # surface family print '' surf_dist = surface_distance(hkl) # distance print '' surf_color = surface_color(hkl) # surface color print 'surface_color', surf_color print '' planes, number_planes = crystal_plane(hkl) ps_setd_mingled(number_planes, planes, surf_dist) diameter = 20.0 volume = 4.0 / 3.0 * np.pi * (diameter * 0.5)**3 qfp = enclose_polyhedron(number_planes, planes, volume) p1 = tvtk.PolyData() n_planes = len(qfp[2]) for i in np.arange(len(number_planes)): for surf_index in np.arange(sum(number_planes[0:i]), sum(number_planes[0:i + 1])): print 'surf_index', surf_index p1.points = qfp[2][ surf_index] # the coordinates of the intersection of each plane. faces = crystal_surface(qfp[2][surf_index]) cells = tvtk.CellArray( ) # create a new CellArray object to assign the polys property. cells.set_cells( 1, faces ) # the first parameter is the number of faces (here is 1), p1.polys = cells # and the second parameter is an array describing the composition of each face. p1.point_data.scalars = np.linspace(0.0, 1.0, len(p1.points)) mlab.figure(number_planes, fgcolor=(0, 0, 0), bgcolor=(1, 1, 1)) mlab.pipeline.surface(p1, representation='surface', opacity=1.0, color=surf_color[i]) axe = tvtk.AxesActor(total_length=(3, 3, 3)) mlab.show()
def surface_areas(d): ''' input: origin-to-planes distances. volume_calc: the natural or unscaled volume of the polyhedron. area_p: areas of all the planes. points_p: interception points on the planes, grouped by plane. return: area_ps: the area of each plane family (sum of areas of surfaces of a plane family). ''' ps_setd_mingled(number_planes, planes, d) planes_c = [p.as_list() for p in planes] pr = enclosure(planes_c) volume_calc = pr[0] # the natural or unscaled volume of the polyhedron. area_p = pr[1] # areas of all the planes. points_p = pr[2] # interception points on the planes, grouped by plane. # print points_p area_ps = [ ] # area of each plane family: sum of areas of surfaces of a plane family. index_start = 0 for subset_n in number_planes: index_end = index_start + subset_n area_ps.append(np.sum(area_p[index_start:index_end])) index_start = index_end # diameter = 1.0e-9 # volume = 4.0/3.0*np.pi* (diameter*0.5)**3 # this volume was used to scale the calculated volume. area_ps = np.array(area_ps) * np.power(volume / volume_calc, 2.0 / 3) Vn, En, vl = vertices_number(number_planes, planes, d) edge_sort = edge_length_sort(number_planes, planes, d, vl) edge_length_f, edge_length_o = edge_length_fraction( edge_sort, volume, volume_calc) return area_ps, edge_length_f, edge_length_o
if len(hkl) == 2: planes, number_planes = crystal_plane(hkl) area_target = [0.8, 0.2] # the sum of the area fractions is 1. Iter_max = 5000 re_xtol = 1e-12 abs_ftol = 1e-12 d0 = [1, 1] dx = 0.0001 res = optimal_distance_local(Iter_max, re_xtol, abs_ftol, d0, dx) areas = surface_areas(res[0]) areas_fraction = [ areas[0] / (areas[0] + areas[1]), areas[1] / (areas[0] + areas[1]) ] print 'The optimal distance d is', res[0], ', area is ', areas, '.' print 'The area fraction is ', areas_fraction, ', target area fraction is', area_target, '.' ps_setd_mingled(number_planes, planes, res[0]) # set distances of planes. if len(hkl) == 1: planes, number_planes = crystal_plane(hkl) ps_setd_mingled(number_planes, planes, [2]) # set distances of planes. qfp = enclose_polyhedron(number_planes, planes, volume) n_qfp2, qfp2_list = array_to_list(qfp[2]) point_for_plane = open('point_for_plane.txt', 'w+') # open the file point_for_plane.truncate() # empty the file np.savetxt('point_for_plane.txt', qfp2_list) number_of_plane = open('number_of_plane.txt', 'w+') number_of_plane.truncate() np.savetxt('number_of_plane.txt', n_qfp2)