def test_multiplicity(self): """Int Tables of Crystallography Vol. 1 p 32.""" self.assertEqual( HklPlane(1, 0, 0).multiplicity(symmetry=Symmetry.cubic), 6) for h in range(1, 4): self.assertEqual( HklPlane(h, 0, 0).multiplicity(symmetry=Symmetry.tetragonal), 4) self.assertEqual( HklPlane(0, h, 0).multiplicity(symmetry=Symmetry.tetragonal), 4) self.assertEqual( HklPlane(h, h, 0).multiplicity(symmetry=Symmetry.tetragonal), 4) self.assertEqual( HklPlane(-h, h, 0).multiplicity(symmetry=Symmetry.tetragonal), 4) self.assertEqual( HklPlane(h, h, 1).multiplicity(symmetry=Symmetry.tetragonal), 8) self.assertEqual( HklPlane(-h, h, 1).multiplicity(symmetry=Symmetry.tetragonal), 8) self.assertEqual( HklPlane(0, 0, 1).multiplicity(symmetry=Symmetry.tetragonal), 2) self.assertEqual( HklPlane(1, 0, 2).multiplicity(symmetry=Symmetry.tetragonal), 8) self.assertEqual( HklPlane(-1, 0, 2).multiplicity(symmetry=Symmetry.tetragonal), 8) self.assertEqual( HklPlane(0, 1, 2).multiplicity(symmetry=Symmetry.tetragonal), 8) self.assertEqual( HklPlane(0, -1, 2).multiplicity(symmetry=Symmetry.tetragonal), 8) self.assertEqual( HklPlane(1, 2, 0).multiplicity(symmetry=Symmetry.tetragonal), 8) self.assertEqual( HklPlane(-1, 2, 0).multiplicity(symmetry=Symmetry.tetragonal), 8) self.assertEqual( HklPlane(1, 2, 3).multiplicity(symmetry=Symmetry.tetragonal), 16)
def test_HklPlane(self): p = HklPlane(1, 1, 1) n = p.normal() self.assertEqual(np.linalg.norm(n), 1)
def plot_sst(self, **kwargs): """ Create the inverse pole figure in the unit standard triangle. :param ax: a reference to a pyplot ax to draw the poles. :param mk: marker used to plot the poles (square by default). :param bool ann: Annotate the pole with the coordinates of the vector if True (False by default). """ # first draw the boundary of the symmetry domain limited by 3 hkl plane # normals, called here A, B and C symmetry = self.lattice.get_symmetry() ax = kwargs.get('ax') if symmetry is Symmetry.cubic: sst_poles = [(0, 0, 1), (1, 0, 1), (1, 1, 1)] ax.axis([-0.05, 0.45, -0.05, 0.40]) elif symmetry is Symmetry.hexagonal: sst_poles = [(0, 0, 1), (2, -1, 0), (1, 0, 0)] ax.axis([-0.05, 1.05, -0.05, 0.6]) else: print('unsuported symmetry: %s' % symmetry) A = HklPlane(*sst_poles[0], lattice=self.lattice) B = HklPlane(*sst_poles[1], lattice=self.lattice) C = HklPlane(*sst_poles[2], lattice=self.lattice) self.plot_line_between_crystal_dir(A.normal(), B.normal(), ax=ax, col='k') self.plot_line_between_crystal_dir(B.normal(), C.normal(), ax=ax, col='k') self.plot_line_between_crystal_dir(C.normal(), A.normal(), ax=ax, col='k') # display the 3 crystal axes poles = [A, B, C] v_align = ['top', 'top', 'bottom'] for i in range(3): hkl = poles[i] c_dir = hkl.normal() c = c_dir + self.z c /= c[2] # SP'/SP = r/z with r=1 pole_str = '%d%d%d' % hkl.miller_indices() if symmetry is Symmetry.hexagonal: pole_str = '%d%d%d%d' % HklPlane.three_to_four_indices( *hkl.miller_indices()) ax.annotate(pole_str, (c[0], c[1] - (2 * (i < 2) - 1) * 0.01), xycoords='data', fontsize=12, horizontalalignment='center', verticalalignment=v_align[i]) # now plot the sample axis if self.resize_markers: # compute the max grain volume to normalize volume_max = max(self.microstructure.get_grain_volumes()) for grain in self.microstructure.grains: g = Orientation.Rodrigues2OrientationMatrix(grain['orientation']) if self.resize_markers: kwargs['mksize'] = 0.15 * np.sqrt( grain['volume'] / volume_max) * 1000 # compute axis and apply SST symmetry if self.axis == 'Z': axis = self.z elif self.axis == 'Y': axis = self.y else: axis = self.x axis_rot = self.sst_symmetry(g.dot(axis)) label = '' if self.map_field == 'grain_id': label = 'grain ' + str(grain['idnumber']) kwargs['lab'] = label kwargs['col'] = self.get_color_from_field(grain) self.plot_crystal_dir(axis_rot, **kwargs) if self.verbose: print('plotting %s in crystal CS: %s' % (self.axis, axis_rot)) ax.axis('off') ax.set_title('%s-axis SST inverse %s projection' % (self.axis, self.proj))
def test_SchimdFactor(self): o = Orientation.from_euler([0., 0., 0.]) ss = SlipSystem(HklPlane(1, 1, 1), HklDirection(0, 1, -1)) self.assertAlmostEqual(o.schmid_factor(ss), 0.4082, 4)
# create a python Grain object from the image data orientation = Orientation.from_rodrigues(np.array([0.3889, -0.0885, 0.3268])) grain = Grain(1, orientation) grain_data = HST_read(im_file, header_size=0, autoparse_filename=True, verbose=True) grain.position = ndimage.measurements.center_of_mass(grain_data, grain_data) print('grain position:', grain.position) grain.volume = ndimage.measurements.sum(grain_data) # label is 1.0 here grain.add_vtk_mesh(grain_data, contour=False) print('adding bounding box') grain_bbox = box_3d(size=np.shape(grain_data), line_color=white) print('adding grain with slip planes') hklplanes = [HklPlane(1, 1, 1)] grain_with_planes = grain_3d(grain, hklplanes, show_normal=False, \ plane_opacity=1.0, show_orientation=True) tr = vtk.vtkTransform() tr.Translate(grain.position) grain_with_planes.SetUserTransform(tr) print('adding a lattice to picture the grain orientation') lat_size = 20 l = Lattice.face_centered_cubic(lat_size) cubic = lattice_3d_with_planes(l, hklplanes, crystal_orientation=grain.orientation, \ show_normal=True, plane_opacity=1.0, origin='mid', sphereColor=grey, sphereRadius=0.1) apply_translation_to_actor(cubic, (lat_size, lat_size, lat_size)) print('adding axes')