def data_for_stress_strain(self, stands, sample_folder, job_file): """ Calculation for data of stress strain curves of multi-stand rolling. Parameters ---------- stands : int Number of stands being considered in the simulation. sample_folder : str Name of the sample folder. job_file : str Name of the output file. """ import damask fig = PyPlot.figure() max_strain = np.zeros(1) for i in range(1, stands + 1): d = damask.Result('/nethome/v.shah/{}/{}_stand/{}'.format( sample_folder, i, job_file)) d.add_Cauchy() d.add_strain_tensor() d.add_Mises('sigma') d.add_Mises('epsilon_V^0.0(F)') d.add_calculation('avg_sigma', "np.average(#sigma_vM#)") d.add_calculation('avg_epsilon', "np.average(#epsilon_V^0.0(F)_vM#)")
def eval_stress(job_file): """ return the stress as a numpy array Parameters ---------- job_file : str Name of the job_file """ d = damask.Result(job_file) stress_path = d.get_dataset_location('avg_sigma') stress = np.zeros(len(stress_path)) hdf = h5py.File(d.fname) for count, path in enumerate(stress_path): stress[count] = np.array(hdf[path]) stress = np.array(stress) / 1E6 return stress
def eval_strain(job_file): """ return the strain as a numpy array Parameters ---------- job_file : str Name of the job_file """ d = damask.Result(job_file) stress_path = d.get_dataset_location('avg_sigma') strain = np.zeros(len(stress_path)) hdf = h5py.File(d.fname) for count, path in enumerate(stress_path): strain[count] = np.array(hdf[path.split('avg_sigma')[0] + 'avg_epsilon']) return strain
def plot(job_file): """ Plot the stress strain curve from the job file Parameters ---------- job_file : str Name of the job_file """ d = damask.Result(job_file) stress_path = d.get_dataset_location('avg_sigma') stress = np.zeros(len(stress_path)) strain = np.zeros(len(stress_path)) hdf = h5py.File(d.fname) for count,path in enumerate(stress_path): stress[count] = np.array(hdf[path]) strain[count] = np.array(hdf[path.split('avg_sigma')[0] + 'avg_epsilon']) stress = np.array(stress)/1E6 PyPlot.plot(strain,stress,linestyle='-',linewidth='2.5') PyPlot.xlabel(r'$\varepsilon_{VM} $',fontsize=18) PyPlot.ylabel(r'$\sigma_{VM}$ (MPa)',fontsize=18)
def Initial_processing(self, job_file, simulation_folder): """ Initial post processing required for MDRX simulations. Parameters ---------- job_file : str Name of the damask output file to be processed. simulation_folder : str Name of the simulation folder where the job file exists. """ import damask os.chdir('/nethome/v.shah/{}/'.format(simulation_folder)) d = damask.Result('{}.hdf5'.format(job_file.split('.')[0])) orientation0 = d.get_initial_orientation() d.add_grainrotation(orientation0) d.add_Eulers('orientation') d.add_calculation( 'tot_density', 'np.sum((np.sum(#rho_mob#,1),np.sum(#rho_dip#,1)),0)') d.add_calculation('r_s', "40/np.sqrt(#tot_density#)")
def add_nuclei_info(self, sample_folder, job_file, casipt, stand): """ Add nucleation tag to the data for visualization of the nuclei. Parameters ---------- sample_folder : str Name of the sample folder. job_file : str Name of the output file (2nd stand and so on). casipt : str Name of the casipt file with nucleation info. stand : int Number of the stand. """ import damask d = damask.Result('/nethome/v.shah/{}/{}_stand/{}'.format( sample_folder, stand, job_file)) rex_array = np.loadtxt(casipt, dtype=int, usecols=(1)) total_cells = np.shape( d.read_dataset([d.get_dataset_location('grain_rotation')[-1]]))[0] nuclei_array = np.zeros(total_cells) for i in rex_array: nuclei_array[i] = 1 path = d.groups_with_datasets('rho_mob') with h5py.File(d.fname, 'a') as f: for i in range(len(path)): try: f[path[i] + '/Nucleation_tag'] != [] data = f[path[i] + '/Nucleation_tag'] data[...] = nuclei_array except KeyError: f[path[i] + '/Nucleation_tag'] = nuclei_array
'--dir', dest='dir', default='postProc', metavar='string', help= 'name of subdirectory relative to the location of the DADF5 file to hold output' ) parser.add_argument('--inc', nargs='+', help='Increment for which DREAM3D to be used, eg. 25', type=int) options = parser.parse_args() for filename in options.filenames: f = damask.Result(filename) N_digits = int(np.floor(np.log10(int(f.increments[-1][3:])))) + 1 f.pick('increments', options.inc) for inc in damask.util.show_progress(f.iterate('increments'), len(f.selection['increments'])): dirname = os.path.abspath( os.path.join(os.path.dirname(filename), options.dir)) try: os.mkdir(dirname) except FileExistsError: pass o = h5py.File(dirname + '/' + os.path.splitext(filename)[0] \ + '_inc_{}.dream3D'.format(inc[3:].zfill(N_digits)),'w') o.attrs['DADF5toDREAM3D'] = '1.0'
def __init__(self, current_file): """ Opens the HDF5 file in which rotation is to be calculated.""" import damask self.current_file = damask.Result(current_file)
def plot_stress_strain(self, stands, sample_folder, job_file): """ Plot stress strain curves of multi-stand rolling. Parameters ---------- stands : int Number of stands being considered in the simulation. sample_folder : str Name of the sample folder. job_file : str Name of the output file. """ import damask fig = PyPlot.figure() max_strain = np.zeros(1) colormap = PyPlot.cm.gist_ncar #nipy_spectral, Set1,Paired colors = [colormap(i) for i in np.linspace(0, 1, stands)] print(colors) for i in range(1, stands + 1): d = damask.Result('/nethome/v.shah/{}/{}_stand/{}'.format( sample_folder, i, job_file)) d.add_Cauchy() d.add_strain_tensor() d.add_Mises('sigma') d.add_Mises('epsilon_V^0.0(F)') d.add_calculation('avg_sigma', "np.average(#sigma_vM#)") d.add_calculation('avg_epsilon', "np.average(#epsilon_V^0.0(F)_vM#)") print(d.fname) stress_path = d.get_dataset_location('avg_sigma') stress = np.zeros(len(stress_path)) strain = np.zeros(len(stress_path)) hdf = h5py.File(d.fname) for count, path in enumerate(stress_path): stress[count] = np.array(hdf[path]) strain[count] = np.array(hdf[path.split('avg_sigma')[0] + 'avg_epsilon']) stress = np.array(stress) / 1E6 strain = (1.0 + np.array(strain)) * (1.0 + max_strain) - 1.0 PyPlot.plot(strain, stress, linestyle='-', linewidth='2.5', label='{} hit'.format(i)) PyPlot.xlabel(r'$\varepsilon_{VM} $', fontsize=18) PyPlot.ylabel(r'$\sigma_{VM}$ (MPa)', fontsize=18) axes = PyPlot.gca() max_strain = np.max(strain) expt_data = pd.read_csv( '/nethome/v.shah/{}/Shen_2016_fig2.csv'.format(sample_folder), names=['strain', 'stress'], skiprows=4, nrows=28) expt_data_1 = pd.read_csv( '/nethome/v.shah/{}/Shen_2016_fig2_2nd_hit.csv'.format( sample_folder), names=['strain', 'stress'], skiprows=1) expt_data = expt_data.append(expt_data_1) PyPlot.plot(expt_data['strain'], expt_data['stress'], 'o', label='Experimental data') PyPlot.legend() fig.savefig('/nethome/v.shah/{}/Multi_stand_stress_strain.png'.format( sample_folder), dpi=300)
import subprocess, signal, time, os import psutil import damask import h5py import re cmd = "mpiexec -n 2 DAMASK_grid -l tensionX.yaml -g 20grains16x16x16.vtr" with open('check.txt', 'w') as f: P = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) r = re.compile(' increment 3 converged') record = [] while P.poll() is None: for count, line in enumerate(iter(P.stdout.readline, b'')): record.append(line.decode('utf-8')) if re.search(r, record[-1]): os.kill(P.pid + 1, signal.SIGSTOP) d = damask.Result('20grains16x16x16_tensionX.hdf5') print(d.get_dataset_location('F')) os.kill(P.pid + 1, signal.SIGUSR2) os.kill(P.pid + 1, signal.SIGUSR1) os.kill(P.pid + 1, signal.SIGCONT) for children in psutil.Process(P.pid).children(recursive=True): if children.name() == 'DAMASK_grid': children.terminate() for line in record: f.write(line)