Exemple #1
0
 def compute_write_eps_sig(self,outputfile):
     """    Compute strain and stress in crystal and sample co-ordinates system    """
     
     if self.ubis is not None:
         
         writestress = True
         
         f = open(outputfile,'w')
         ''' the used parameters will be the header of the output file'''
         for k,v in sorted(self.parameterobj.parameters.iteritems()):
             f.write(("%s %s\n")%(k,v))
         ''' write titles'''
         f.write("##############################################\n")
         f.write("cell__a cell__b cell__c cell_alpha cell_beta cell_gamma u11 u12 u13 u21 u22 u23 u31 u32 u33 ")
         f.write("eps11_c eps22_c eps33_c eps12_c eps13_c eps23_c eps11_s eps22_s eps33_s eps12_s eps13_s eps23_s ")
         f.write("sig11_c sig22_c sig33_c sig12_c sig13_c sig23_c sig11_s sig22_s sig33_s sig12_s sig13_s sig23_s\n")
         
         '''this is the part where we compute strain and stress'''
         for ubi in self.ubis:
             U, eps = ubi_to_u_and_eps(ubi, self.unitcell())
             #U, eps = ubi_to_u_and_eps(ubi, ubi_to_cell(self.ubis[0]))
             epsM = [ [ eps[0], eps[1], eps[2] ],        #write the strain tensor list as a matrix
                      [ eps[1], eps[3], eps[4] ],
                      [ eps[2], eps[4], eps[5] ] ]
             epsS = np.dot( U, np.dot( epsM, U.T ) )     #epsilon in sample co-ordinates
             sigM= np.empty((3,3))
             sigS= np.empty((3,3))
             try:
                 sigM = strain2stress( np.array(epsM), self.MVStiffness() )      #write the stress tensor as a symmetric matrix in crystal co-ordinates
                 sigS = np.dot( U, np.dot( sigM, U.T ) )     #sigma in sample co-ordinates
             except:
                 print "couldn't compute stress! please check the crystal_symmetry parameters and elastic constants"
                 writestress = False
                 pass
             
             ''' writing down the results'''
             
             f.write(("%f "*6)%tuple(ubi_to_cell(ubi)))
             f.write(("%f "*9)%tuple(U.ravel()))
             ligne = ""
             for i,j in [(0,0),(1,1),(2,2),(0,1),(0,2),(1,2)]:
                 ligne = ligne + " " + str(100.*np.array(epsM)[i,j])
             for i,j in [(0,0),(1,1),(2,2),(0,1),(0,2),(1,2)]:
                 ligne = ligne + " " + str(100.*epsS[i,j])
             if writestress==True:
                 for i,j in [(0,0),(1,1),(2,2),(0,1),(0,2),(1,2)]:
                     ligne = ligne + " " + str(np.array(sigM)[i,j])
                 for i,j in [(0,0),(1,1),(2,2),(0,1),(0,2),(1,2)]:
                     ligne = ligne + " " + str(sigS[i,j])
             
             f.write(ligne[1:])
             f.write("\n")
         f.close()
Exemple #2
0
    def run_pcr(self, cif_file, grain_mask, flt, gr, number_y_scans, ymin,
                ystep):

        no_voxels = sum(grain_mask[grain_mask == 1])

        unit_cell = self.field_converter.extract_cell(self.params)

        UBI = gr.ubi.copy()
        cell = tools.ubi_to_cell(UBI)
        U, strain = tools.ubi_to_u_and_eps(UBI, unit_cell)
        euler = tools.u_to_euler(U)

        average = np.concatenate((strain, euler), axis=None)
        initial_guess = np.concatenate((average, average), axis=None)

        for i in range(no_voxels - 2):
            initial_guess = np.concatenate((initial_guess, average), axis=None)

        th_min, th_max = setup_grain.get_theta_bounds(flt, gr)
        param = setup_grain.setup_experiment(self.params, cif_file, no_voxels,
                                             ystep, th_min, th_max)
        measured_data = setup_grain.get_measured_data(gr, flt, number_y_scans,
                                                      ymin, ystep, param)

        hkl = setup_grain.get_hkls(param, flt, gr)
        voxel_positions, C, constraint = setup_grain.get_positions(
            grain_mask, ystep)

        voxel_data = find_refl_func.find_refl_func(param, hkl, voxel_positions,
                                                   measured_data, unit_cell,
                                                   initial_guess, ymin,
                                                   number_y_scans, C,
                                                   constraint)

        bounds_low, bounds_high = setup_grain.get_bounds_strain(initial_guess)

        solution = voxel_data.steepest_descent(bounds_low, bounds_high,
                                               initial_guess)

        voxels_as_grain_objects = setup_grain.map_solution_to_voxels(
            solution, grain_mask, no_voxels, voxel_data, var_choice='strain')

        return voxels_as_grain_objects
Exemple #3
0
def ubi_to_gff(ubi,par):
    from ImageD11 import grain as ig
    from ImageD11 import parameters as ip
    from string import split
    from xfab import tools
    from six.moves import range
    
    list_of_grains = ig.read_grain_file(ubi)
    p = ip.parameters()
    p.loadparameters(par)
    uc = [p.parameters['cell__a'],p.parameters['cell__b'],p.parameters['cell__c'],p.parameters['cell_alpha'],p.parameters['cell_beta'],p.parameters['cell_gamma']]
    #print(uc)
    
    grainno = []
    x = []
    y = []
    z = []
    rodx = []
    rody = []
    rodz = []
    unitcell_a = []
    unitcell_b = []
    unitcell_c = []
    unitcell_alpha = []
    unitcell_beta = []
    unitcell_gamma = []
    U11 = []
    U12 = []
    U13 = []
    U21 = []
    U22 = []
    U23 = []
    U31 = []
    U32 = []
    U33 = []
    eps11 = []
    eps22 = []
    eps33 = []
    eps23 = []
    eps13 = []
    eps12 = []
    titles = ["grainno","x","y","z","rodx","rody","rodz","U11","U12","U13","U21","U22","U23","U31","U32","U33","unitcell_a","unitcell_b","unitcell_c","unitcell_alpha","unitcell_beta","unitcell_gamma","eps11","eps22","eps33","eps23","eps13","eps12"]
    for i in range(len(list_of_grains)):
        if hasattr(list_of_grains,'name') == False:
            grainno.append(i)
        elif hasattr(list_of_grains,'name') == True:
            grainno.append(eval(split(list_of_grains[i].name,':')[0]))
        x.append(list_of_grains[i].translation[0]/1000.)
        y.append(list_of_grains[i].translation[1]/1000.)
        z.append(list_of_grains[i].translation[2]/1000.)
        ubi = list_of_grains[i].ubi
        (U,eps) = tools.ubi_to_u_and_eps(ubi,uc)
        uc_a, uc_b, uc_c, uc_alpha, uc_beta, uc_gamma = tools.ubi_to_cell(ubi)
        unitcell_a.append(uc_a)
        unitcell_b.append(uc_b)
        unitcell_c.append(uc_c)
        unitcell_alpha.append(uc_alpha)
        unitcell_beta.append(uc_beta)
        unitcell_gamma.append(uc_gamma)
        rod = tools.u_to_rod(U)
        rodx.append(rod[0])
        rody.append(rod[1])
        rodz.append(rod[2])
        U11.append(U[0,0])
        U12.append(U[0,1])
        U13.append(U[0,2])
        U21.append(U[1,0])
        U22.append(U[1,1])
        U23.append(U[1,2])
        U31.append(U[2,0])
        U32.append(U[2,1])
        U33.append(U[2,2])
        eps11.append(eps[0])
        eps12.append(eps[1])
        eps13.append(eps[2])
        eps22.append(eps[3])
        eps23.append(eps[4])
        eps33.append(eps[5])
    
    gff = cl.newcolumnfile(titles)
    gff.ncols = len(titles)
    gff.nrows = len(grainno)
    gff.bigarray = np.zeros((gff.ncols,gff.nrows))
    gff.set_attributes()
    gff.addcolumn(grainno,"grainno")
    gff.addcolumn(x,"x")
    gff.addcolumn(y,"y")
    gff.addcolumn(z,"z")
    gff.addcolumn(rodx,"rodx")
    gff.addcolumn(rody,"rody")
    gff.addcolumn(rodz,"rodz")
    gff.addcolumn(U11,"U11")
    gff.addcolumn(U12,"U12")
    gff.addcolumn(U13,"U13")
    gff.addcolumn(U21,"U21")
    gff.addcolumn(U22,"U22")
    gff.addcolumn(U23,"U23")
    gff.addcolumn(U31,"U31")
    gff.addcolumn(U32,"U32")
    gff.addcolumn(U33,"U33")
    gff.addcolumn(unitcell_a,"unitcell_a")
    gff.addcolumn(unitcell_b,"unitcell_b")
    gff.addcolumn(unitcell_c,"unitcell_c")
    gff.addcolumn(unitcell_alpha,"unitcell_alpha")
    gff.addcolumn(unitcell_beta,"unitcell_beta")
    gff.addcolumn(unitcell_gamma,"unitcell_gamma")    
    gff.addcolumn(eps11,"eps11")
    gff.addcolumn(eps22,"eps22")
    gff.addcolumn(eps33,"eps33")
    gff.addcolumn(eps23,"eps23")
    gff.addcolumn(eps13,"eps13")
    gff.addcolumn(eps12,"eps12")
    return gff, uc