def __init__( self, jdata ) : ''' --- property -- unit -- 1. Length -- nm -- self.alatt, self.first, self.second 2. Volume -- nm^3 -- self.volume 2. Time -- s -- 3. Temperature -- K -- 4. Energy -- eV -- 5. Pressure -- Gpa -- 1 eV = 1.60217663410E-19 J -> 1 J = 1.0 / 1.60217663410 * 1.E+19 eV shear modulus: 1.0 Gpa = 1.E9 Pa = 1.E9 N / m^2 = 1.e9 J/m^3 = 1.E9 * 1.0 / 1.60217663410 * 1.E+19 eV/(10^9 nm)^3 = 1.0 / 1.60217663410 * 10 eV/nm^3 Boltzmann constant, unit: eV/ K kb = 1.380649 * 10 ** (-23) J / K = 1.380649 * 10 ** (-23) * 1.0 / 1.60217663410 * 10**( 19 ) eV/K = 1.380649 / 1.60217663410 * 1.E-4 eV/K ''' 'shear modulus, unit: eV/nm^3.' self.shear_modulus = 161.0 / 1.60217663410 * 10 'poisson ratio' self.poisson_ratio = 0.28 'lattice constant' self.alatt = j_must_have( jdata, 'alatt' ) lattice = j_must_have( jdata, 'lattice' ) if lattice == 'bcc' : 'first nearest neighbour' self.first = math.sqrt( 3.0 ) * 0.5 * self.alatt 'second nearest neighbour' self.second = self.alatt 'atomic volume' self.volume = self.alatt * self.alatt * self.alatt * 0.5 elif lattice == 'fcc' : print( '# should be change for lattice fcc !' ) pass elif lattice == 'hcp' : print( '# should be change for lattice hcp !' ) pass self.kb = 1.380649 / 1.60217663410 * 1.E-4 'prefactor: Hz' self.prefactor = 10.0 * 10 ** 12 self.u_disk_disk_prefactor = self.shear_modulus / ( 4.0 * math.pi * ( 1.0 - self.poisson_ratio ) ) self.u_sphere_disk_prefactor = 1.0 / ( 3.0 * math.pi ) * ( 1.0 + self.poisson_ratio ) / ( 1.0 - self.poisson_ratio ) * self.shear_modulus
def __init__( self, jdata, tmp_defectObject_list ) : ''' Properties of BoxLinkcell: No change: 1. self.box 2. self.linkcell_space 3. self.nlc_vector 4. self.fnlc_vector 5. self.nlc 6. self.periodic 7. self.nnbrs 8. self.hmeps 9. self.nix, self.niy, self.niz Change : 10. self.numb_defectObject 11. self.ltop[ 0 : self.nlc ] 12. self.linkmp[ 0 : self.numb_defectObject ] ''' self.box = np.array( j_must_have( jdata, 'box' ) ) self.linkcell_space = np.array( j_must_have( jdata, 'linkcell_space' ) ) for item in self.linkcell_space > self.box : if item : raise RuntimeError( 'linkcell_space > box, wrong !' ) rcutoff_elastic = j_must_have( jdata, 'rcutoff_elastic' ) for item in self.linkcell_space < rcutoff_elastic : if item : raise RuntimeError( 'linkcell_space < rcutoff_elastic, wrong !' ) 'python3 np.divide, / and np.true_divide are same.' self.fnlc_vector = np.floor_divide( self.box, self.linkcell_space ) self.nlc_vector = convert_int_array( self.fnlc_vector ) self.nlc = self.nlc_vector[ 0 ] * self.nlc_vector[ 1 ] * self.nlc_vector[ 2 ] self.periodic = j_must_have( jdata, 'periodic' ) self.nnbrs = j_must_have( jdata, 'max_numb_in_27_cells' ) self.hmeps = -1e-9 self.nix = [ 0, -1, -1, -1, 0, 0, -1, 1, -1, 0, 1, -1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, -1, -1, -1 ] self.niy = [ 0, 0, -1, 1, 1, 0, 0, 0, -1, -1, -1, 1, 1, 1, -1, 0, 1, -1, 1, 0, -1, 0, -1, 1, 0, -1, 1 ] self.niz = [ 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1 ] self.linked( tmp_defectObject_list )
def set_min_max_nsize_dict(self, defectsys, jdata): 'set min nsize and max nsize for every defecttype.' ICluster_lower = 2 ICluster_upper = j_must_have(jdata, 'ICluster_upper') VCluster_lower = 2 VCluster_upper = VCluster_lower # ILoop100_lower = ICluster_upper + 1 ILoop100_upper = ILoop100_lower # ILoop111_lower = ICluster_upper + 1 ILoop111_upper = ILoop111_lower # VLoop100_lower = j_must_have(jdata, 'VLoop_lower') VLoop100_upper = VLoop100_lower # VLoop111_lower = VLoop100_lower VLoop111_upper = VLoop111_lower # self.min_nsize_dict = { 'I': 1, 'V': 1, 'ICluster': ICluster_lower, 'VCluster': VCluster_lower, 'ILoop100': ILoop100_lower, 'VLoop100': VLoop100_lower, 'ILoop111': ILoop111_lower, 'VLoop111': VLoop111_lower } self.max_nsize_dict = { 'I': 1, 'V': 1, 'ICluster': ICluster_upper, 'VCluster': VCluster_upper, 'ILoop100': ILoop100_upper, 'VLoop100': VLoop100_upper, 'ILoop111': ILoop111_upper, 'VLoop111': VLoop111_upper } for item in defectsys.defectObject_list: tmp_defecttype = item.defecttype tmp_nsize = item.nsize if self.max_nsize_dict[tmp_defecttype] < tmp_nsize: self.max_nsize_dict[tmp_defecttype] = tmp_nsize self.max_nsize = max(item for item in self.max_nsize_dict.values())
def output_points(self, defectsys, jdata): ''' format: I 1 10.0 10.0 10.0 V 1 10.0 10.0 10.0 ''' box = np.array(j_must_have(jdata, 'box')) total_point_defects_str_list = self._return_points(defectsys, jdata) new_total_point_defects_str_list = [ to_str(box) + ' # b011, b022, b033\n' ] for item in total_point_defects_str_list: defectStr = item.lstrip().rstrip() defectStr_list = defectStr.split() position = np.array( [np.float64(item2) for item2 in defectStr_list[0:3]]) * box if defectStr_list[3] == '0': new_defectStr = 'V ' + ' 1 ' + to_str(position) + '\n' else: new_defectStr = 'I ' + ' 1 ' + to_str(position) + '\n' new_total_point_defects_str_list.append(new_defectStr) self.file_out_points.writelines(new_total_point_defects_str_list)
def output_area_density(self, jdata): ''' format: I 1 1.0 V 1 1.0 ICluster nsize 1.0 VCluster nsize 1.0 ILoop100 nsize 1.0 ILoop111 nsize 1.0 VLoop100 nsize 1.0 VLoop111 nsize 1.0 ''' box = j_must_have(jdata, 'box') area = box[0] * box[1] density_str_list = [ '#--(1) Dtype--(2) nsize--(3) density( nm^-2 )---\n' ] for item in self.sum_numb_nsize_dict.keys(): min_size = self.min_nsize_dict[item] max_size = self.max_nsize_dict[item] for i in range(self.sum_numb_nsize_dict[item].size): if i >= min_size and i <= max_size: density_str = item + ' ' + str(i) + ' ' + str( self.sum_numb_nsize_dict[item][i] / area) + '\n' density_str_list.append(density_str) self.file_out_area_density.writelines(density_str_list)
def set_sum_numb_nsize_dict(self, defectsys, jdata): defecttypes = j_must_have(jdata, 'defecttype') self.sum_numb_nsize_dict = {} for item in defecttypes: self.sum_numb_nsize_dict[item] = np.zeros(self.max_nsize + 1) for item in defectsys.defectObject_list: tmp_defecttype = item.defecttype tmp_nsize = item.nsize self.sum_numb_nsize_dict[tmp_defecttype][tmp_nsize] += 1.0
def multi_cascade_annealing(jdata, cascade): tmp_ConstNumber = ConstNumber(jdata) box = j_must_have(jdata, 'box') trap = False trapSys = None if j_have(jdata, 'trap'): trap = jdata['trap'] if trap: trapSys = TrapSystem(jdata) total_cascade_numb = int(jdata['fluence'] * box[0] * box[1]) position_random = jdata['position_random'] cascade_numb = cascade.return_cascade_numb() i_select = np.random.randint(0, cascade_numb) 'build a defectSys of Class DefectSystem for okmc simulation.' defectSys = DefectSystem(jdata, cascade.return_defectStr_list(jdata, i_select)) outputFile = OutputFile(defectSys, jdata) print('# %d cascades in database, total %d cascades annealing' % (cascade_numb, total_cascade_numb)) for i in range(total_cascade_numb): start_time = time.time() 'reset trap for all defectObject in model of Class DefectSystem.' if trap: defectSys.reset_trap_defectSystem(jdata, trapSys) defectSys.evolution(jdata, outputFile, trapSys) i_select = np.random.randint(0, cascade_numb) add_defectStr_list = cascade.return_defectStr_list(jdata, i_select) defectSys.add_defectObject(jdata, add_defectStr_list, position_random) defectSys.set_initial_recombine_and_related_properties( jdata, tmp_ConstNumber) defectSys.set_zero_c_time() end_time = time.time() print('# cascade %d running time: %.3f s' % (i, end_time - start_time)) print('# ') print('# All cascades annealing done !') return None
def load_point_defects_uniform_distribution(self, jdata, seed=None): ''' self.defectStr_list, format: 'I 1 10.0 10.0 10.0\n' 'V 1 10.0 10.0 10.0\n' len( ) == 5 ''' if seed != None: np.random.seed(seed) tmp_box = np.array(j_must_have(jdata, 'box')) self.defectStr_list = [] for i in range(self.I_total): position = np.random.random(3) * tmp_box defectStr = 'I 1 ' + to_str(position) + '\n' self.defectStr_list.append(defectStr) for i in range(self.I_total): position = np.random.random(3) * tmp_box defectStr = 'V 1 ' + to_str(position) + '\n' self.defectStr_list.append(defectStr)
def output_cfg(self, defectsys, jdata): ''' output configuration file with format *.cfg: Number of particles = 10000 A = 1 Angstrom (basic length-scale) H0(1,1) = 760.164 A H0(1,2) = 0 A H0(1,3) = 0 A H0(2,1) = 0 A H0(2,2) = 760.164 A H0(2,3) = 0 A H0(3,1) = 0 A H0(3,2) = 0 A H0(3,3) = 760.164 A .NO_VELOCITY. entry_count = 4 auxiliary[0] = IV 183.839996 W 0 0 0 1 183.839996 W 0.00208333 0.00208333 0.00208 0 ''' box = j_must_have(jdata, 'box') mass = j_must_have(jdata, 'mass') symbol = j_must_have(jdata, 'symbol') total_point_defects_str_list = self._return_points(defectsys, jdata) numb_point_defects = len(total_point_defects_str_list) head_str_list = [] head_str_list.append('Number of particles = ' + str(numb_point_defects) + '\n') head_str_list.append('A = 1 Angstrom (basic length-scale)' + '\n') head_str_list.append('H0(1,1) = ' + str(box[0] * 10.0) + ' ' + 'A' + '\n') head_str_list.append('H0(1,2) = 0 A' + '\n') head_str_list.append('H0(1,3) = 0 A' + '\n') head_str_list.append('H0(2,1) = 0 A' + '\n') head_str_list.append('H0(2,2) = ' + str(box[1] * 10.0) + ' ' + 'A' + '\n') head_str_list.append('H0(2,3) = 0 A' + '\n') head_str_list.append('H0(3,1) = 0 A' + '\n') head_str_list.append('H0(3,2) = 0 A' + '\n') head_str_list.append('H0(3,3) = ' + str(box[2] * 10.0) + ' ' + 'A' + '\n') head_str_list.append('.NO_VELOCITY.' + '\n') head_str_list.append('entry_count = 4' + '\n') head_str_list.append('auxiliary[0] = IV' + '\n') self.file_out_cfg.writelines(head_str_list) new_total_point_defects_str_list = [] for item in total_point_defects_str_list: new_total_point_defects_str_list.append(str(mass) + '\n') new_total_point_defects_str_list.append(symbol + '\n') new_total_point_defects_str_list.append(item) self.file_out_cfg.writelines(new_total_point_defects_str_list)
def __init__(self, defectsys, jdata, index=None): 'property' self.out_dir = os.path.join(j_must_have(jdata, 'out_dir'), 'output') if index == None or index == 0: if os.path.exists(self.out_dir): shutil.rmtree(self.out_dir) os.mkdir(self.out_dir) if index != None: self.out_dir = os.path.join(self.out_dir, str(index)) if os.path.exists(self.out_dir): shutil.rmtree(self.out_dir) os.mkdir(self.out_dir) self.step = defectsys.c_step self.time = defectsys.c_time self.out_style_freq = j_must_have(jdata, 'out_style_freq') self.out_cfg = False if j_have(jdata, 'out_cfg_dir_name'): '0. self.out_cfg, 1. self.cfg_path, 2. self.cfg_name, 3. self.target_cfg' self.out_cfg = True out_cfg_dir_name = jdata['out_cfg_dir_name'] self.cfg_path = os.path.join(self.out_dir, out_cfg_dir_name[0]) os.mkdir(self.cfg_path) self.cfg_name = out_cfg_dir_name[1] self.target_cfg = os.path.join( self.cfg_path, self.cfg_name + '.' + str(self.step) + '.cfg') self.out_defectStr = False if j_have(jdata, 'out_defectStr_dir_name'): '0. self.out_defectStr, 1. self.defectStr_path, 2. self.defectStr_name, 3. self.target_defectStr' self.out_defectStr = True out_defectStr_dir_name = jdata['out_defectStr_dir_name'] self.defectStr_path = os.path.join(self.out_dir, out_defectStr_dir_name[0]) os.mkdir(self.defectStr_path) self.defectStr_name = out_defectStr_dir_name[1] self.target_defectStr = os.path.join( self.defectStr_path, self.defectStr_name + '.' + str(self.step)) self.out_volume_density = False if j_have(jdata, 'out_volume_density_dir_name'): '0. self.out_volume_density, 1. self.volume_density_path, 2. self.volume_density_name, 3. self.target_volume_density' self.out_volume_density = True out_volume_density_dir_name = jdata['out_volume_density_dir_name'] self.volume_density_path = os.path.join( self.out_dir, out_volume_density_dir_name[0]) os.mkdir(self.volume_density_path) self.volume_density_name = out_volume_density_dir_name[1] self.target_volume_density = os.path.join( self.volume_density_path, self.volume_density_name + '.' + str(self.step)) self.out_area_density = False if j_have(jdata, 'out_area_density_dir_name'): '0. self.out_area_density, 1. self.area_density_path, 2. self.area_density_name, 3. self.target_area_density' self.out_area_density = True out_area_density_dir_name = jdata['out_area_density_dir_name'] self.area_density_path = os.path.join(self.out_dir, out_area_density_dir_name[0]) os.mkdir(self.area_density_path) self.area_density_name = out_area_density_dir_name[1] self.target_area_density = os.path.join( self.area_density_path, self.area_density_name + '.' + str(self.step)) self.out_points = False if j_have(jdata, 'out_point_defects_dir_name'): '0. self.out_points, 1. self.points_path, 2. self.points_name, 3. self.target_points' self.out_points = True out_points_dir_name = jdata['out_point_defects_dir_name'] self.points_path = os.path.join(self.out_dir, out_points_dir_name[0]) os.mkdir(self.points_path) self.points_name = out_points_dir_name[1] self.target_points = os.path.join( self.points_path, self.points_name + '.' + str(self.step)) self.out_size_distri = False if j_have(jdata, 'out_size_distri_dir_name'): '0. self.out_size_distri, 1. self.size_distri_path, 2. self.size_distri_name, 3. self.target_size_distri.' self.out_size_distri = True out_size_distri_dir_name = jdata['out_size_distri_dir_name'] self.size_distri_path = os.path.join(self.out_dir, out_size_distri_dir_name) os.mkdir(self.size_distri_path) self.out_size_distri_defecttype = jdata[ 'out_size_distri_defecttype'] for item in self.out_size_distri_defecttype: os.mkdir(os.path.join(self.size_distri_path, item)) '1. self.target_steptime.' out_steptime_dir_name = j_must_have(jdata, 'out_steptime_dir_name') steptime_path = os.path.join(self.out_dir, out_steptime_dir_name[0]) os.mkdir(steptime_path) self.target_steptime = os.path.join(steptime_path, out_steptime_dir_name[1]) self.file_out_steptime = open(self.target_steptime, 'w') self.file_out_steptime.writelines([ '# step, c_time(s), total_defects_I, total_defects_V, numb_defectObject' + '\n' ]) self.file_out_steptime.close() self.set_min_max_nsize_dict(defectsys, jdata) self.set_sum_numb_nsize_dict(defectsys, jdata)
def load_cascade_from_file(self, jdata, serial_numb): ''' 1. self.cluster == True, cascade file format: 100.0 100.0 100.0 # b011, b022, b033, units: nm I 1 10.0 10.0 10.0 V 1 10.0 10.0 10.0 ... reading defects and convert clusters 2. self.cluster == False, cascade file format: 100.0 100.0 100.0 # b011, b022, b033, units: nm (1): ILoop100 13 10.0 10.0 10.0 (2): ILoop111 13 10.0 10.0 10.0 0.5 0.5 0.5 ... reading defects directly ''' if serial_numb > self.cascade_numb: raise RuntimeError('serial_numb %d not in range [ 0, %d ]' % (serial_numb, self.cascade_numb)) file_in = open(self.cascade_file[serial_numb], 'r') alatt = j_must_have(jdata, 'alatt') burgers_vector_unit_array = np.array( j_must_have(jdata, 'burgers_vector_unit')) burgers_vector_scale_length_array = np.array( j_must_have(jdata, 'burgers_vector_scale_length')) 'set d_probability = 1.0 / burgers_vector_scale_length_array.size + 0.037142857 formatly.' d_probability = 0.037142857 + 1.0 / burgers_vector_scale_length_array.size if j_have(jdata, 'probability'): d_probability = jdata['probability'] if self.cluster: # test_cgzhang print('defect cluster algorithm is done!') I_position_list = [] V_position_list = [] s = file_in.readline() defectStr = s.lstrip().rstrip() defectStr_list = defectStr.split() tmp_box = np.array( [np.float64(item) for item in defectStr_list[0:3]]) while True: s = file_in.readline() if s == '': break defectStr = s.lstrip().rstrip() defectStr_list = defectStr.split() position = [np.float64(item) for item in defectStr_list[2:5]] if defectStr_list[0] == 'I': I_position_list.append(position) else: V_position_list.append(position) I_position_array = np.array(I_position_list) V_position_array = np.array(V_position_list) clusterSys = ClusterSystem(alatt, self.ICluster_upper, self.VLoop_lower, 'I', self.IC_VC_rcut[0], I_position_array, tmp_box, burgers_vector_unit_array, burgers_vector_scale_length_array, d_probability) clusterSys.add_clusters(alatt, self.ICluster_upper, self.VLoop_lower, 'V', self.IC_VC_rcut[1], V_position_array, tmp_box) self.defectStr_list = clusterSys.return_defectStr_list() else: self.defectStr_list = [] s = file_in.readline() while True: s = file_in.readline() if s == '': break self.defectStr_list.append(s)
def load_cascade_from_formula(self, jdata, seed=None): ''' self.defectStr_list, defectStr format: 'I 1 10.0 10.0 10.0\n' 'ICluster 7 10.0 10.0 10.0\n' 'ILoop111 13 10.0 10.0 10.0\n' 'ILoop100 13 10.0 10.0 10.0\n' 'V 1 10.0 10.0 10.0\n' 'VCluster 7 10.0 10.0 10.0\n' 'VLoop111 13 10.0 10.0 10.0\n' 'VLoop100 13 10.0 10.0 10.0\n' ''' if seed != None: np.random.seed(seed) tmp_box = np.array(j_must_have(jdata, 'box')) self.create_defects_formula_distribution() self.defectStr_list = [] for item in self.int_defect_size_R: if item[0] == 1: defecttype = 'I' elif item[0] >= 2 and item[0] <= self.ICluster_upper: defecttype = 'ICluster' elif item[0] > self.ICluster_upper: if np.random.rand() < self.ratio_ILoop111_ILoop100[0]: defecttype = 'ILoop111' else: defecttype = 'ILoop100' position = 0.5 * tmp_box + R_convert_to_position(item[1]) defectStr = defecttype + ' ' + str( item[0]) + ' ' + to_str(position) + '\n' self.defectStr_list.append(defectStr) for item in self.vac_defect_size_R: if item[0] == 1: defecttype = 'V' elif item[0] >= 2 and item[0] < self.VLoop_lower: defecttype = 'VCluster' elif item[0] >= self.VLoop_lower: kesi = np.random.rand() if kesi < self.ratio_VCluster_VLoop100_VLoop111[0]: defecttype = 'VCluster' elif kesi < self.ratio_VCluster_VLoop100_VLoop111[ 0] + self.ratio_VCluster_VLoop100_VLoop111[1]: defecttype = 'VLoop100' else: defecttype = 'VLoop111' position = 0.5 * tmp_box + R_convert_to_position(item[1]) defectStr = defecttype + ' ' + str( item[0]) + ' ' + to_str(position) + '\n' self.defectStr_list.append(defectStr)
def __init__(self, jdata): ''' Class Cascade properties: 1. self.defectStr_list format: (1): ILoop100 13 10.0 10.0 10.0 (2): ILoop111 13 10.0 10.0 10.0 0.5 0.5 0.5 mode : 1. cascade from formula 2. cascade from file a. self.cluster == True, defects of I and V convert into clusters b. self.cluster == False, defects of I and V does not convert into clusters 3. cascade I and V randomly and uniformly distributed in simulation box, for electron irradiation ''' self.cascade_from_formula = False if j_have(jdata, 'cascade_from_formula'): self.cascade_from_formula = jdata['cascade_from_formula'] if self.cascade_from_formula: self.cascade_numb = j_must_have(jdata, 'cascade_numb') self.I_total = j_must_have(jdata, 'I_total') self.SI = j_must_have(jdata, 'SI') self.mu = j_must_have(jdata, 'mu') self.sigma = j_must_have(jdata, 'sigma') self.SV = j_must_have(jdata, 'SV') self.ICluster_upper = j_must_have(jdata, 'ICluster_upper') self.ratio_ILoop111_ILoop100 = j_must_have( jdata, 'ratio_ILoop111_ILoop100') self.VLoop_lower = j_must_have(jdata, 'VLoop_lower') self.ratio_VCluster_VLoop100_VLoop111 = j_must_have( jdata, 'ratio_VCluster_VLoop100_VLoop111') self.cascade_from_file = False if j_have(jdata, 'cascade_from_file'): self.cascade_from_file = jdata['cascade_from_file'] if self.cascade_from_file: sys_path = j_must_have(jdata, 'systems') cascade_prefix = j_must_have(jdata, 'cascade_prefix') if j_have(jdata, 'sys_defects_cfg'): sys_defects_cfg = jdata['sys_defects_cfg'] defects_cfg_prefix = j_must_have(jdata, 'defects_cfg_prefix') self.defects_cfg_file = glob.glob( os.path.join(sys_defects_cfg, defects_cfg_prefix + '.*')) self.defects_cfg_file.sort(key=return_serial_numb_in_str) if os.path.exists(sys_path): shutil.rmtree(sys_path) os.mkdir(sys_path) self.cascade_cfg_2_points_defectStr(sys_path, cascade_prefix) self.cascade_file = glob.glob( os.path.join(sys_path, cascade_prefix + '.*')) self.cascade_file.sort(key=return_serial_numb_in_str) self.cascade_numb = len(self.cascade_file) self.cluster = j_must_have(jdata, 'cluster') if self.cluster: self.IC_VC_rcut = j_must_have(jdata, 'IC_VC_rcut') self.VLoop_lower = j_must_have(jdata, 'VLoop_lower') self.ICluster_upper = j_must_have(jdata, 'ICluster_upper') self.point_defects_uniform_distribution = False if j_have(jdata, 'point_defects_uniform_distribution'): self.point_defects_uniform_distribution = jdata[ 'point_defects_uniform_distribution'] if self.point_defects_uniform_distribution: self.cascade_numb = j_must_have(jdata, 'cascade_numb') self.I_total = j_must_have(jdata, 'I_total')