# to avoid confusion vol_frac_goal = np.double(vol_frac_goal) L = np.double(L) M = np.int(M) mc_steps = np.int(mc_steps) kBT = np.double(kBT) nr_tries = np.int(nr_tries) trunc_triangles = ccb.prepare_triangles(1.0, L) # Using 1.0 instead of vol_frac_goal in order to obtain enough inputs. #ccb.optimize_midpoints(L, trunc_triangles) with open('trunc_triangles_0.data', 'wb') as f: pickle.dump(L, f, pickle.HIGHEST_PROTOCOL) pickle.dump(trunc_triangles, f, pickle.HIGHEST_PROTOCOL) grain_ids_0, overlaps_0, voxel_indices_0 = ccb_c.populate_voxels(M, L, trunc_triangles, nr_tries, delta, vol_frac_goal) phases_0, good_voxels_0, euler_angles_0, phase_volumes_0, grain_volumes_0 = ccb_c.calc_grain_prop(M, grain_ids_0, trunc_triangles) surface_voxels_0, gb_voxels_0, interface_voxels_0 = ccb_c.calc_surface_prop(M, grain_ids_0) vol_frac_WC_0 = phase_volumes_0[1]/np.float(np.sum(phase_volumes_0)) vol_frac_Co_0 = 1 - vol_frac_WC_0 mass_frac_WC_0 = ccb.mass_fraction(vol_frac_WC_0) d_eq_0 = ccb.volume_to_eq_d(grain_volumes_0*delta_x**3) sum_gb_voxels_0 = np.sum(gb_voxels_0) contiguity_0 = sum_gb_voxels_0 / np.float(sum_gb_voxels_0 + np.sum(interface_voxels_0)) ccb.write_hdf5('testfile_0.hdf5', 3*[M], 3*[delta_x], trunc_triangles, grain_ids_0, phases_0, good_voxels_0, euler_angles_0, surface_voxels_0, gb_voxels_0, interface_voxels_0, overlaps_0) # Compute actual volume fraction:
trunc_triangles = ccb.prepare_triangles(vol_frac_goal, L, r, k, d_eq) # Sort triangles w.r.t. volume, so that large triangles are added to the box first (better packing) trunc_triangles.sort(key=lambda m: m.volume, reverse=True) if use_potential: ccb.optimize_midpoints(L, trunc_triangles) print('Prepared', len(trunc_triangles), 'triangles') with open('trunc_triangles_0.data', 'wb') as f: pickle.dump(L, f, pickle.HIGHEST_PROTOCOL) pickle.dump(trunc_triangles, f, pickle.HIGHEST_PROTOCOL) if m_coarse == m: grain_ids_0, overlaps_0, voxel_indices_0 = ccb_c.populate_voxels(M, L, trunc_triangles, nr_tries, M, 1.0) else: if nr_tries > 0: # Optimization: Use coarser grid for packing, then insert packed grains into fine grid grain_ids_coarse_0, overlaps_coarse_0, voxel_indices_coarse_0 = ccb_c.populate_voxels(M_coarse, L, trunc_triangles, nr_tries, M_coarse, 1.0) grain_ids_0, overlaps_0, voxel_indices_0 = ccb_c.populate_voxels(M, L, trunc_triangles, 1, 0, 1.0) phases_0, good_voxels_0, euler_angles_0, phase_volumes_0, grain_volumes_0 = ccb_c.calc_grain_prop(M, grain_ids_0, trunc_triangles) surface_voxels_0, gb_voxels_0, interface_voxels_0 = ccb_c.calc_surface_prop(M, grain_ids_0) vol_frac_WC_0 = phase_volumes_0[1]/np.float(np.sum(phase_volumes_0)) vol_frac_Co_0 = 1 - vol_frac_WC_0 mass_frac_WC_0 = ccb.mass_fraction(vol_frac_WC_0) d_eq_0 = ccb.volume_to_eq_d(grain_volumes_0*delta_x**3) sum_gb_voxels_0 = np.sum(gb_voxels_0) contiguity_0 = sum_gb_voxels_0 / np.float(sum_gb_voxels_0 + np.sum(interface_voxels_0))