def read_and_calc(self, target): uobj = UDFManager(target) time = [] g = [] temp = [] # データ読み込み prev_g = 0. for i in range(1, uobj.totalRecord()): print("Reading Rec.=", i) uobj.jump(i) # time.append(uobj.get("Time")) temp.append(uobj.get('Statistics_Data.Temperature.Batch_Average')) # if self.mode == 'elong': stress = uobj.get("Statistics_Data.Stress.Total.Batch_Average") tmp_g = (stress[2] - (stress[0] + stress[1]) / 2.) / (self.deform**2 - 1 / self.deform) elif self.mode == 'shear': tmp_stress = uobj.get( 'Statistics_Data.Stress.Total.Batch_Average.xy' ) - self.ave_xy tmp_g = tmp_stress / self.deform if tmp_g <= 0: tmp_g = prev_g g.append(tmp_g) prev_g = tmp_g # smoothing mod_g = signal.savgol_filter(g, 11, 3) # pack up data = np.stack([time, g, temp], 1) data_mod = np.stack([time, mod_g, temp], 1) return data, data_mod
def read_and_calc(self, target, c_strain): uobj = UDFManager(target) time = [] temp = [] stress = [] strain = [] # データ読み込み prev_stress = 0. for i in range(1, uobj.totalRecord()): print("Reading Rec.=", i) uobj.jump(i) # time.append(uobj.get("Time")) temp.append(uobj.get('Statistics_Data.Temperature.Batch_Average')) # if self.mode == 'elong': strs = uobj.get("Statistics_Data.Stress.Total.Batch_Average") tmp_stress = strs[2] - (strs[0] + strs[1]) / 2. elif self.mode == 'shear': tmp_stress = uobj.get( 'Statistics_Data.Stress.Total.Batch_Average.xy' ) #- self.ave_xy if tmp_stress <= 0: tmp_stress = prev_stress # stress.append(tmp_stress) strain.append(c_strain) prev_stress = tmp_stress # stress_part = np.stack([time, stress, temp], 1) strain_part = np.stack([time, strain, temp], 1) return stress_part, strain_part
def make_base_udf(self, t_udf): if self.calc_mode == 'cycle': lamd_str = str(self.cycle_lamd).replace('.', '_') rate_str = str("{0:4.0e}".format(self.rate)).replace('.', '_') calc_dir = 'Hysteresis_' + self.calc_mode + '_rate_' + rate_str + '_lambda_' + lamd_str if os.path.exists(calc_dir): print("Use existing dir of ", calc_dir) else: print("Make new dir of ", calc_dir) os.makedirs(calc_dir) # base = os.path.join(calc_dir, self.base_udf) print("Readin file = ", t_udf) udf = UDFManager(t_udf) self.mod_base_udf(udf) udf.write(base) return base, calc_dir
def calc_init(self, target): uobj = UDFManager(target) uobj.jump(0) # cell = uobj.get("Structure.Unit_Cell.Cell_Size") area_init = cell[0] * cell[1] z_init = cell[2] # uobj.jump(1) vol = uobj.get("Statistics_Data.Volume.Batch_Average") return area_init, z_init
def read_and_calc(target, c_strain, mode): # low = 1e-5 uobj = UDFManager(target) time = [] temp = [] stress = [] strain = [] gt = [] # データ読み込み prev_stress = 0. for i in range(1, uobj.totalRecord()): print("Reading Rec.=", i) uobj.jump(i) # time.append(uobj.get("Time")) temp.append(uobj.get('Statistics_Data.Temperature.Batch_Average')) # if mode == 'elong': strs = uobj.get("Statistics_Data.Stress.Total.Batch_Average") tmp_stress = strs[2] - (strs[0] + strs[1]) / 2. if tmp_stress <= 0.05 * prev_stress: tmp_stress = 4 * prev_stress / 5 if tmp_stress < 1e-4: tmp_stress = 1e-4 tmp_gt = tmp_stress / c_strain / 3. elif mode == 'shear': tmp_stress = uobj.get( 'Statistics_Data.Stress.Total.Batch_Average.xy' ) #- self.ave_xy if tmp_stress <= 0.05 * prev_stress: tmp_stress = 4 * prev_stress / 5 if tmp_stress < 1e-4: tmp_stress = 1e-4 tmp_gt = tmp_stress / c_strain # tmp_stress = low # stress.append(tmp_stress) strain.append(c_strain) gt.append(tmp_gt) prev_stress = tmp_stress # mod_stress = signal.savgol_filter(stress, 5, 3) stress_part = np.stack([time, mod_stress, temp], 1) strain_part = np.stack([time, strain, temp], 1) gt_part = np.stack([time, gt, temp], 1) return stress_part, strain_part, gt_part
def make_base_udf(self, t_udf): if os.path.exists(self.calc_dir): print("Use existing dir of ", self.calc_dir) else: print("Make new dir of ", self.calc_dir) os.makedirs(self.calc_dir) # base = os.path.join(self.calc_dir, self.base_udf) print("Readin file = ", t_udf) u = UDFManager(t_udf) u.jump(1) u.eraseRecord(record_pos=-999,record_num=-999) u.write(base) return base
def read_and_calc(target): uobj = UDFManager(target) data = [] for i in range(1, uobj.totalRecord()): print("Reading Rec.=", i) uobj.jump(i) # stress = uobj.get('Statistics_Data.Stress.Total.Batch_Average.xy') # strain = uobj.get('Structure.Unit_Cell.Shear_Strain') # data.append([strain, stress]) return data
def make_base_udf(self, t_udf): if os.path.exists(self.calc_dir): print("Use existing dir of ", self.calc_dir) else: print("Make new dir of ", self.calc_dir) os.makedirs(self.calc_dir) # base = os.path.join(self.calc_dir, self.base_udf) print("Readin file = ", t_udf) u = UDFManager(t_udf) # u.jump(u.totalRecord() - 1) # ave_xy = u.get('Statistics_Data.Stress.Total.Total_Average.xy') u.eraseRecord(0, u.totalRecord() - 2) u.write(base) return base
def mod_udf(self, udf_in, rate): if self.def_mode == 'elong': time_1_step = int(self.res/self.time_div/rate) time_total = time_1_step*(self.deform_max - 1)/self.res elif self.def_mode == 'shear': deform_time = self.deform_max/rate time_total = round(deform_time/self.time_div) time_1_step = int(self.res/self.time_div/rate) # u = UDFManager(udf_in) # goto global data u.jump(-1) # Dynamics_Conditions p = 'Simulation_Conditions.Dynamics_Conditions.' u.put(100000., p + 'Max_Force') u.put(self.time_div, p + 'Time.delta_T') u.put(time_total, p + 'Time.Total_Steps') u.put(time_1_step, p + 'Time.Output_Interval_Steps') u.put(1.0, p + 'Temperature.Temperature') u.put(0, p + 'Temperature.Interval_of_Scale_Temp') u.put(0, p + 'Pressure_Stress.Pressure') # Deformation if self.def_mode == 'elong': p = "Simulation_Conditions.Dynamics_Conditions.Deformation." u.put('Cell_Deformation', p + 'Method') u.put('Simple_Elongation', p + 'Cell_Deformation.Method') u.put('Initial_Strain_Rate', p + 'Cell_Deformation.Simple_Elongation.Input_Method') u.put(rate, p + 'Cell_Deformation.Simple_Elongation.Initial_Strain_Rate.Rate') u.put(0.5, p + 'Cell_Deformation.Simple_Elongation.Poisson_Ratio') u.put('z', p + 'Cell_Deformation.Simple_Elongation.Axis') u.put(1, p + 'Cell_Deformation.Interval_of_Deform') u.put(0, p + 'Cell_Deformation.Deform_Atom') elif self.def_mode == 'shear': p = "Simulation_Conditions.Dynamics_Conditions.Deformation." u.put('Lees_Edwards', p + 'Method') u.put('Steady', p + 'Lees_Edwards.Method') u.put(rate, p + 'Lees_Edwards.Steady.Shear_Rate') # Output_Flags u.put([1, 1, 1], 'Simulation_Conditions.Output_Flags.Structure') # Read_Set_of_Molecules p = 'Initial_Structure.Read_Set_of_Molecules' u.put(['', -1], p) # Generate_Method p = 'Initial_Structure.Generate_Method.' u.put('Restart', p + 'Method') u.put(['', -1, 1, 1], p + 'Restart') # Relaxation p = 'Initial_Structure.Relaxation.' u.put(0, p + 'Relaxation') #--- Write UDF --- u.write(udf_in) return
import math from numpy import * from UDFManager import * uobj=UDFManager("./output.udf") Ns=len(uobj.get("object_type.spherical_particle.Particle_spec[]")) Nc=uobj.get("object_type.spherical_particle.Particle_spec[].Particle_number") N1=0 for i in range(Ns): N1=N1+Nc[i] print Ns, Nc, N1 nx=uobj.get("mesh.NPX") ny=uobj.get("mesh.NPY") nz=uobj.get("mesh.NPZ") lx=2**nx ly=2**ny lz=2**nz pi2=3.14159265358979*2.0 dia=uobj.get("A")*2.0 print "#",N1,lx,ly,lz,dia f_sk = open('sk.dat','w') mxk=100000 k01=arange(0,mxk) k02=arange(0,mxk) k03=arange(0,mxk) n1 = 10 n2 = 10 delk = pi2/float(50) nnk = 0 iz = 0 iy = 0 for ix in range(1, n1):
def mod_udf(self, uin, pre, direction, lamd): time_1_step = round(self.resol/self.time_div/self.rate, -2) time_total = round(time_1_step*(lamd - 1)/self.resol, -2) # udf = UDFManager(uin) udf.jump(-1) # Dynamics_Conditions p = 'Simulation_Conditions.Dynamics_Conditions.' udf.put(time_total, p + 'Time.Total_Steps') udf.put(time_1_step, p + 'Time.Output_Interval_Steps') if direction == 'backward': # Deformation p = "Simulation_Conditions.Dynamics_Conditions.Deformation." srate = udf.get(p + 'Cell_Deformation.Simple_Elongation.Deformation_Speed.Speed') udf.put(-1*srate, p + 'Cell_Deformation.Simple_Elongation.Deformation_Speed.Speed') # Generate_Method p = 'Initial_Structure.Generate_Method.' udf.put('Restart', p + 'Method') udf.put([pre, -1, 1, 0], p + 'Restart') #--- Write UDF --- udf.write(uin) return
def mod_udf(self, udf_in, rate): time_1_step = int(self.res/self.time_div/rate) time_total = time_1_step*(self.Lamd_max - 1)/self.res # u = UDFManager(udf_in) # goto global data u.jump(-1) # Dynamics_Conditions p = 'Simulation_Conditions.Dynamics_Conditions.' u.put(100000., p + 'Max_Force') u.put(self.time_div, p + 'Time.delta_T') u.put(time_total, p + 'Time.Total_Steps') u.put(time_1_step, p + 'Time.Output_Interval_Steps') u.put(1.0, p + 'Temperature.Temperature') u.put(0, p + 'Temperature.Interval_of_Scale_Temp') u.put(0, p + 'Pressure_Stress.Pressure') # Deformation p = "Simulation_Conditions.Dynamics_Conditions.Deformation." u.put('Cell_Deformation', p + 'Method') u.put('Simple_Elongation', p + 'Cell_Deformation.Method') u.put('Initial_Strain_Rate', p + 'Cell_Deformation.Simple_Elongation.Input_Method') u.put(rate, p + 'Cell_Deformation.Simple_Elongation.Initial_Strain_Rate.Rate') u.put(0.5, p + 'Cell_Deformation.Simple_Elongation.Poisson_Ratio') u.put('z', p + 'Cell_Deformation.Simple_Elongation.Axis') u.put(1, p + 'Cell_Deformation.Interval_of_Deform') u.put(0, p + 'Cell_Deformation.Deform_Atom') # Read_Set_of_Molecules p = 'Initial_Structure.Read_Set_of_Molecules' u.put([self.base_udf, -1], p) # Generate_Method p = 'Initial_Structure.Generate_Method.' u.put('Restart', p + 'Method') u.put([self.base_udf, -1, 1, 0], p + 'Restart') # Relaxation p = 'Initial_Structure.Relaxation.' u.put(0, p + 'Relaxation') #--- Write UDF --- u.write(udf_in) return
def read_and_calc(area_init, z_init, target): uobj = UDFManager(target) data = [] for i in range(1, uobj.totalRecord()): print("Reading Rec.=", i) uobj.jump(i) # cell = uobj.get("Structure.Unit_Cell.Cell_Size") # stress = uobj.get("Statistics_Data.Stress.Total.Batch_Average") t_stress = calc_stress(cell, stress, area_init) # bond_stress = uobj.get("Statistics_Data.Stress.Bond.Batch_Average") bond = calc_stress(cell, bond_stress, area_init) # non_bond_stress = uobj.get( "Statistics_Data.Stress.Non_Bond.Batch_Average") non_bond = calc_stress(cell, non_bond_stress, area_init) # strain = uobj.get("Structure.Unit_Cell.Cell_Size.c") / z_init # temp = uobj.get("Statistics_Data.Temperature.Batch_Average") # data.append([strain, t_stress, non_bond, bond, temp]) return data
def step_elong(self, base, udf_in, time_temp): u = UDFManager(base) u.jump(-1) # Dynamics_Conditions p = 'Simulation_Conditions.Dynamics_Conditions.' u.put(100000., p + 'Max_Force') u.put(time_temp[0], p + 'Time.delta_T') u.put(time_temp[1], p + 'Time.Total_Steps') u.put(time_temp[2], p + 'Time.Output_Interval_Steps') # u.put(1.0, p + 'Temperature.Temperature') u.put(time_temp[4], p + 'Temperature.Interval_of_Scale_Temp') # u.put(0, p + 'Pressure_Stress.Pressure') # Deformation p = "Simulation_Conditions.Dynamics_Conditions.Deformation." u.put('Cell_Deformation', p + 'Method') u.put('Simple_Elongation', p + 'Cell_Deformation.Method') u.put('Initial_Strain_Rate', p + 'Cell_Deformation.Simple_Elongation.Input_Method') u.put(self.step_rate, p + 'Cell_Deformation.Simple_Elongation.Initial_Strain_Rate.Rate') u.put(0.5, p + 'Cell_Deformation.Simple_Elongation.Poisson_Ratio') u.put('z', p + 'Cell_Deformation.Simple_Elongation.Axis') u.put(1, p + 'Cell_Deformation.Interval_of_Deform') u.put(0, p + 'Cell_Deformation.Deform_Atom') # Read_Set_of_Molecules p = 'Initial_Structure.Read_Set_of_Molecules' u.put([self.base_udf, -1], p) # Generate_Method p = 'Initial_Structure.Generate_Method.' u.put('Restart', p + 'Method') u.put([self.base_udf, -1, 1, 1], p + 'Restart') # Relaxation p = 'Initial_Structure.Relaxation.' u.put(0, p + 'Relaxation') #--- Write UDF --- u.write(os.path.join(self.calc_dir, udf_in)) return
def step_deform(self, base, axis, udf_in, time_temp, target_dir): u = UDFManager(base) u.jump(-1) # Dynamics_Conditions p = 'Simulation_Conditions.Dynamics_Conditions.' u.put(100000., p + 'Max_Force') u.put(time_temp[0], p + 'Time.delta_T') u.put(time_temp[1], p + 'Time.Total_Steps') u.put(time_temp[2], p + 'Time.Output_Interval_Steps') # u.put(1.0, p + 'Temperature.Temperature') u.put(time_temp[4], p + 'Temperature.Interval_of_Scale_Temp') # u.put(0, p + 'Pressure_Stress.Pressure') # Deformation if self.mode == 'elong': p = "Simulation_Conditions.Dynamics_Conditions.Deformation." u.put('Cell_Deformation', p + 'Method') u.put('Simple_Elongation', p + 'Cell_Deformation.Method') u.put('Initial_Strain_Rate', p + 'Cell_Deformation.Simple_Elongation.Input_Method') u.put( self.step_rate, p + 'Cell_Deformation.Simple_Elongation.Initial_Strain_Rate.Rate') u.put(0.5, p + 'Cell_Deformation.Simple_Elongation.Poisson_Ratio') u.put('z', p + 'Cell_Deformation.Simple_Elongation.Axis') u.put(1, p + 'Cell_Deformation.Interval_of_Deform') u.put(0, p + 'Cell_Deformation.Deform_Atom') elif self.mode == 'shear': p = "Simulation_Conditions.Dynamics_Conditions.Deformation." u.put('Lees_Edwards', p + 'Method') u.put('Steady', p + 'Lees_Edwards.Method') u.put(self.step_rate, p + 'Lees_Edwards.Steady.Shear_Rate') # Output_Flags u.put([1, 1, 1], 'Simulation_Conditions.Output_Flags.Structure') # Read_Set_of_Molecules p = 'Initial_Structure.Read_Set_of_Molecules' u.put(['', -1], p) # Generate_Method p = 'Initial_Structure.Generate_Method.' u.put('Restart', p + 'Method') u.put(['', -1, 1, 1], p + 'Restart') # Relaxation p = 'Initial_Structure.Relaxation.' u.put(0, p + 'Relaxation') # Rotate system self.rotate_position(u, axis) #--- Write UDF --- u.write(os.path.join(target_dir, udf_in)) return
def read_step_stress(self, t_udf): print("Readin file = ", t_udf) area_init, z_init = self.calc_init(t_udf) uobj = UDFManager(t_udf) time = [] strain = [] g = [] stress = [] temp = [] # データ読み込み prev_stress = 0. prev_g = 0. for rec in range(uobj.totalRecord()): print("Reading Rec.=", rec) uobj.jump(rec) # time.append(uobj.get("Time")) if self.mode == 'elong': tmp_strain = uobj.get( "Structure.Unit_Cell.Cell_Size.c") / z_init elif self.mode == 'shear': tmp_strain = uobj.get('Structure.Unit_Cell.Shear_Strain') strain.append(tmp_strain) # if rec == 0: tmp_stress = prev_stress tmp_g = prev_g temp.append(1.) else: temp.append( uobj.get('Statistics_Data.Temperature.Batch_Average')) if self.mode == 'elong': stress_list = uobj.get( "Statistics_Data.Stress.Total.Batch_Average") tmp_stress = stress_list[2] - (stress_list[0] + stress_list[1]) / 2. tmp_g = tmp_stress / (tmp_strain**2 - 1 / tmp_strain) elif self.mode == 'shear': tmp_stress = uobj.get( 'Statistics_Data.Stress.Total.Batch_Average.xy' ) - self.ave_xy tmp_g = tmp_stress / tmp_strain if tmp_stress <= 0: tmp_stress = prev_stress tmp_g = prev_g stress.append(tmp_stress) g.append(tmp_g) # prev_stress = tmp_stress prev_g = tmp_g # mod_g = signal.savgol_filter(g, 11, 3) # gt_step_mod = np.stack([time, mod_g, temp], 1) gt_step = np.stack([time, g, temp], 1) ss_step = np.stack([strain, stress, temp], 1) self.save_data(ss_step, 'ss_step.dat') self.save_data(gt_step, 'gt_step.dat') self.save_data(gt_step_mod, 'gt_step_mod.dat') return gt_step, gt_step_mod
def eq_udf(self, template, read_udf, present_udf, time_temp): u = UDFManager(os.path.join(self.calc_dir, template)) u.jump(-1) #--- Simulation_Conditions --- # Dynamics_Conditions p = 'Simulation_Conditions.Dynamics_Conditions.' u.put(time_temp[0], p+'Time.delta_T') u.put(time_temp[1], p+'Time.Total_Steps') u.put(time_temp[2], p+'Time.Output_Interval_Steps') u.put(time_temp[4], p + 'Temperature.Interval_of_Scale_Temp') # Deformation p = "Simulation_Conditions.Dynamics_Conditions.Deformation." u.put('None', p + 'Method') #--- Initial_Structure --- p = 'Initial_Structure.Read_Set_of_Molecules' u.put([self.base_udf, -1], p) p = 'Initial_Structure.Generate_Method.' u.put('Restart', p+'Method') u.put([read_udf, -1, 1, 1], p+'Restart') #--- Write UDF --- u.write(os.path.join(self.calc_dir, present_udf)) return
def read_and_calc(target): if target.split('_')[0] == 'Cycle': sim_type = target.split('_')[4] else: sim_type = target.split('_')[3] uobj = UDFManager(target) if sim_type == 'forward': uobj.jump(0) cell = uobj.get("Structure.Unit_Cell.Cell_Size") area_init = cell[0] * cell[1] z_init = cell[2] data = [[1.0, 0, 0, 0]] elif sim_type == 'backward': uobj.jump(1) vol = uobj.get("Statistics_Data.Volume.Batch_Average") area_init = vol**(2. / 3.) z_init = vol**(1. / 3.) data = [] for i in range(1, uobj.totalRecord()): print("Reading Rec.=", i) uobj.jump(i) # cell = uobj.get("Structure.Unit_Cell.Cell_Size") # stress = uobj.get("Statistics_Data.Stress.Total.Batch_Average") t_stress = calc_stress(cell, stress, area_init) # bond_stress = uobj.get("Statistics_Data.Stress.Bond.Batch_Average") bond = calc_stress(cell, bond_stress, area_init) # non_bond_stress = uobj.get( "Statistics_Data.Stress.Non_Bond.Batch_Average") non_bond = calc_stress(cell, non_bond_stress, area_init) # strain = uobj.get("Structure.Unit_Cell.Cell_Size.c") / z_init # temp = uobj.get("Statistics_Data.Temperature.Batch_Average") # data.append([strain, t_stress, non_bond, bond, temp]) return data
def read_step_stress(self, t_udf): print("Readin file = ", t_udf) area_init, z_init = self.calc_init(t_udf) uobj = UDFManager(t_udf) time = [] strain = [] stress = [] temp = [] # データ読み込み prev_stress = 0. for rec in range(uobj.totalRecord()): print("Reading Rec.=", rec) uobj.jump(rec) # time.append(uobj.get("Time")) if self.mode == 'elong': tmp_strain = uobj.get( "Structure.Unit_Cell.Cell_Size.c") / z_init elif self.mode == 'shear': tmp_strain = uobj.get('Structure.Unit_Cell.Shear_Strain') strain.append(tmp_strain) # if rec == 0: tmp_stress = prev_stress temp.append(1.) else: temp.append( uobj.get('Statistics_Data.Temperature.Batch_Average')) if self.mode == 'elong': stress_list = uobj.get( "Statistics_Data.Stress.Total.Batch_Average") tmp_stress = stress_list[2] - (stress_list[0] + stress_list[1]) / 2. elif self.mode == 'shear': tmp_stress = uobj.get( 'Statistics_Data.Stress.Total.Batch_Average.xy' ) #- self.ave_xy if tmp_stress <= 0: tmp_stress = prev_stress stress.append(tmp_stress) # prev_stress = tmp_stress # stress_step = np.stack([time, stress, temp], 1) strain_step = np.stack([time, strain, temp], 1) ss = np.stack([strain, stress, temp], 1) self.plot(strain_step, 'strain_step.dat') self.plot(stress_step, 'stress_step.dat') self.plot(ss, 'ss.dat') return stress_step, strain_step