예제 #1
0
    def init_grain_map(self):
        """ Read from geom input.
        In damask, the microstructure indices ordered with x as fastest and z as slowest varying coordinate
        https://damask.mpie.de/Documentation/GeometryFormat
        Output:
              self.num_grain: 1D int array with size nx * ny * nz 
                              grain ID in each grid 
        """
        # find the geom file
        files = os.listdir(self.idir)
        for i in files:
            if "input_clean.geom" in i:
                geom_file = i
                break

        with open(self.idir + "/" + geom_file, 'r') as f:
            for i, line in enumerate(f):
                split_line = line.split()
                if i == 0:
                    # read how many lines before grain ID map
                    skip_line = int(split_line[0])

        # read the 2D grainID map and flatten into 1D
        self.grain_map = np.loadtxt(self.idir + "/" + geom_file,
                                    dtype=np.int32,
                                    skiprows=skip_line + 1).flatten()
예제 #2
0
    def init_slip_systems(self):
        """ Read from material.config 
            Read Euler angles of grain orientation defined in material.config and transpose the vectors
            (slip direction d, plane normal n and sense vector t) in such grain-orientation coordinate to 
            reference coordinate. 
        """
        # transpose of orientation matrix, i.e., Q^T, where Q is defined in
        # Li el.al; International Journal of Plasticity 87 (2016) 154-180; Eq. (6)
        omt = []
        with open(self.idir + "/material.config", "r") as f:
            for i, line in enumerate(f):
                split_line = line.split()
                if len(split_line) > 0 and split_line[0] == "(gauss)":
                    # a sample line is:
                    # (gauss)    phi1 323.138    Phi 59.7321    phi2 342.952    scatter 0.0    fraction 1.0
                    euler_angle = [
                        float(split_line[2]),
                        float(split_line[4]),
                        float(split_line[6])
                    ]
                    o = damask.Rotation.fromEulers(euler_angle, "-d")
                    omt.append(o.asMatrix())
        # number of grains
        ngrain = len(omt)

        # slip direction, plane normal as a function of 12 slip system and grainID. vector length 3.
        nsp = np.zeros((self.nslip, ngrain, 3))
        bsp = np.zeros((self.nslip, ngrain, 3))
        tsp = np.zeros((self.nslip, ngrain, 3))

        # transfer slip system into global coordinate, where vectors in local coordinate are defined in slip_system
        # v_global = O^{-1} * v_local = O^T * v_local
        for i in range(self.nslip):
            for j in range(ngrain):
                # slip direction
                b = np.dot(omt[j], slip_system[i, 0:3])
                b = b / np.linalg.norm(b)
                bsp[i, j] = b

                # plane normal
                n = np.dot(omt[j], slip_system[i, 3:])
                n = n / np.linalg.norm(n)
                nsp[i, j] = n

                # sense vector
                # according to line 2169, lattice_slip_transverse function in lattice.f90 in damask
                # source code, t = b x n, i.e., cross product.
                tsp[i, j] = np.cross(b, n)

        return ngrain, bsp, nsp, tsp
예제 #3
0
 def read_column(self, txt, label):
     """Return a column with label from the damask output txt file."""
     with open(txt, 'r') as f:
         for i, line in enumerate(f):
             split_line = line.split()
             if split_line[0] == "inc":  # the label line
                 label_line = i
                 # the label row
                 for j in range(len(split_line)):
                     if split_line[j] == label:
                         colID = j
                         break
                 break
     data = np.loadtxt(txt, skiprows = label_line + 1, usecols = colID)
     return data
예제 #4
0
 def read_column(self, txt, label):
     """Return a column with label from the damask output txt file."""
     with open(txt, 'r') as f:
         for i, line in enumerate(f):
             split_line = line.split()
             if split_line[0] == "inc":  # the label line
                 label_line = i
                 # the label row
                 for j in range(len(split_line)):
                     if split_line[j] == label:
                         colID = j
                         break
                 break
     print("Located IDs " + label)
     start_time = time.time()
     data = np.loadtxt(txt, skiprows=label_line + 1, usecols=colID)
     print("time used to loadtxt = ", time.time() - start_time)
     print("end loadtxt")
     return data
예제 #5
0
 def read_txt(self, txt):
     """ Read the txt file generated by postResults to get shear rate, resolved shear stress, gradient shear rate."""
     with open(txt, 'r') as f:
         for i, line in enumerate(f):
             split_line = line.split()
             if split_line[0] == "inc":  # the label line
                 label_line = i
                 # the label row
                 for j in range(len(split_line)):
                     if split_line[j] == "1_shearrate_slip":
                         colID = j
                         break
                 break
     # the column arrangement is 12 shear rate, 12 resolved shear stress, and 36 gradient of shear rate
     data = np.loadtxt(txt,
                       skiprows=label_line + 1,
                       usecols=range(colID, colID + 12 + 12 + 36))
     for i in range(self.nslip):
         self.gamma_dot[i] = data[:, i]
         self.tau[i] = data[:, i + 12]
         for j in range(3):
             self.grad_gamma_dot[i, :, j] = data[:, 24 + i * 3 + j]
예제 #6
0
    def init_load(self):
        """ Read load file to get dt"""
        # find the load file
        files = os.listdir(self.idir)
        for i in files:
            if ".load" in i:
                load_file = i
                break
        load_file = self.idir + "/" + load_file

        # at this point, assume just one line in load file
        with open(load_file, "r") as f:
            for i, line in enumerate(f):
                if i == 0:
                    split_line = line.split()
                    for j in range(len(split_line)):
                        if split_line[j] == "time":
                            time = float(split_line[j + 1])
                        if split_line[j] == "incs":
                            incs = float(split_line[j + 1])
                            self.dt = time / incs
                            return
예제 #7
0
    def init_nxyz(self):
        """ Read number of grids in three axes from the geom file.
            Output:
            nx, ny, nz: int
                        number of grids in three axes
        """

        # find the geom file
        files = os.listdir(self.idir)
        for i in files:
            if "input_clean.geom" in i:
                geom_file = i
                break

        with open(self.idir + "/" + geom_file, 'r') as f:
            for i, line in enumerate(f):
                split_line = line.split()
                if split_line[0] == "grid":
                    # read number of grids in thress axes
                    # format of this line is: grid    a NX    b NY    c NZ
                    self.nx = int(split_line[2])
                    self.ny = int(split_line[4])
                    self.nz = int(split_line[6])
                    break
예제 #8
0
def make_dicts(cursor, row):
    return dict(
        (cursor.description[idx][0], value) for idx, value in enumerate(row))