eaasfasffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
VIETNAM NATIONAL UNIVERSITY, HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY FACULTY OF COMPUTER SCIENCE AND ENGINEERING CONTINUUM MECHANICS Mini Project GVHD: Mr Nguyễn Nhã Student: Nguyễn Quốc Khánh 2153447 Nguyễn Hải Đăng 2153294 Vũ Thái Tuấn 2153947 Nguyễn Quốc Huy 2153387 Hứa Đại Hùng 2153402 Table of contents Work assignment table I.Problem II.Theoretical basis .4 1.The deformation gradient tensor F in matrix forms: .4 The deformation tensor G The Jacobian J The strain tensor E 5 The right-stretch tensor U, the left-stretch tensor V, and the rotation tensor R Plot the initial unit sphere X 12+ X 22+ X 32=1 and its shape after the deformation Example: III CODE .9 Work assignment table Nguyễn Quốc Khánh Nguyễn Hải Đăng Vũ Thái Tuấn Nguyễn Quốc Huy Hứa Đại Hùng Main code Support code Find information Write report Support code 30% 15% 20% 20% 15% I.Problem Mini project: Continuum mechanics Students work in group and write computer programs using Matlab or Python language to these tasks: Input: Nine values in a tensor to describe the mapping from reference to current coordinates Output: The deformation gradient tensor F The deformation tensor G The Jacobian J The strain tensor E The right-stretch tensor U, the left-stretch tensor V, and the rotation tensor R Plot the initial unit sphere X 21 + X 22+ X 23=1 and its shape after the deformation II.Theoretical basis 1.The deformation gradient tensor F in matrix forms: The deformation gradient F is the derivative of each component of the deformed x vector with respect to each component of the reference X vector For x=x(X), then : ∂ x1 ∂ X1 ∂ xi ∂ x2 F ij= xi , j= = ∂ X j ∂ X1 ∂ x3 ∂ X1 ∂ x1 ∂ X2 ∂ x2 ∂ X2 ∂ x3 ∂ X2 ∂ x1 ∂ X3 ∂ x2 ∂ X3 ∂ x3 ∂ X3 [ ] (Eq 5.10) The deformation tensor G The tensor g is called the Cauchy deformation tensor We may express the deformation tensors G as: G=F F T (Eq 5.26) The Jacobian J J=det ( F) (Eq 5.12) The strain tensor E E= (G−I ) (Eq 5.31) ∂ Ui E= (∇ U +∇ U T +∇ U T ∇ U ) mà ∇ U = ∂ Xj The right-stretch tensor U, the left-stretch tensor V, and the rotation tensor R We have : F=RU =VU G=F F T =V 2=VV F F T =U 2=UU The right-stretch tensor U : U =R−1 F The left-stretch tensor V : V =G the rotation tensor R : R=V −1 F Plot the initial unit sphere X + X + X =1 and its shape after the deformation 2 2 [ x i] = [a¿¿ ij]¿[ X i ¿ [ x i] [a¿¿ ij]−1=¿ ¿[ X i ¿ x1 x2 x3 [ ][ S 11 S 12 S 13 X1 S 21 S 22 S 23 = X X3 S 31 S 32 S 33 ][] { X 1=S 11 x + S12 x +S 13 x X 2=S21 x1 + S22 x + S23 x X 3=S 31 x1 + S32 x + S33 x { X 12=S 112 x12 + S122 x 22+ S 132 x 32 +2 S 11 x S12 x +2 S 11 x S 13 x 3+ S12 x2 S 13 x X 22=S212 x 12+ S 222 x 22 + S232 x32 +2 S 21 x S22 x +2 S 21 x S23 x3 +2 S 22 x S 23 x X 32=S312 x 12 +S 322 x 22+ S 332 x32 +2 S 31 x S32 x +2 S 31 x S33 x3 +2 S 32 x S33 x ( S¿¿ 11¿ ¿2+ S 212 + S312) x12 +( S 122 + S222+ S 322 ) x 22 ¿ ¿ +(S 132+ S 232 + S332) x 32 +2( S11 S12+ S 21 S22+ S 31 S32 ¿ x x 2+2( S11 S13 +S 21 S23 +S 31 S33 ¿ x1 x3 +2( S12 S13 + S22 S 23+ S32 S 33 ¿ x x 3= => Become 3D shape Example: x 1=X +2 X 2, x 2=−2 X + X 2, x 3=X The deformation gradient tensor F ∂ x1 ∂ X1 ∂ xi ∂ x2 F= = ∂ X j ∂ X1 ∂ x3 ∂ X1 ∂ x1 ∂ X2 ∂ x2 ∂ X2 ∂ x3 ∂ X2 ∂ x1 ∂X3 ∂ x2 = −2 ∂X3 0 ∂ x3 ∂X3 [ ] → F2D= −2 [ [ ] ] The deformation tensor G G=F F T = −2 = −2 [ ][ ] [ ] The Jacobian J J=det ( F )=5 The strain tensor E 1 E= (G−I )= −1 = 2 ([ ] [ ] ) [ ] ∂ Ui E= ( ∇ U + ∇ U T + ∇ U T ∇ U ) mà ∇ U = = ∂ X j −2 [ −2 + + −2 −2 −2 ([ ] [ ] [ ][ 0 E= + = ( [ 0 ] [ ]) [ ] E= ] ]) The right-stretch tensor U, the left-stretch tensor V, and the rotation tensor R F=RU =VU G=F F T =V 2=VV F F T =U 2=UU V =G = √ [ √5 ] R=V −1 F= √ 1 = √5 −2 −2 √5 √5 U =R−1 F= √ √5 −2 √ = √5 −2 √5 √5 √5 [ ][ ] [ ] [ ][ ] [ ] ¿ [√ √5 0 √5 ] Plot the initial unit sphere X 21 + X 22+ X 23=1 and its shape after the deformation X =x1−2 X x 2=−2 x 1+ X + X 2=5 X 2−2 X 1=¿ X 2= x 1=X + x1 + x2 x +2 x2 x 1−2 x =¿ X = 5 X 21 + X 22+ X 23=1 x21 −4 x x +4 x22 x 21+ x x + x 22 + + x 3=1 25 25 x 21+ x22 +5 x 23=5 Become ellipsoid shape III CODE Input information: The deformation gradient tensor F: The deformation tensor G and the Jacobian J: 10 The strain tensor E: The right-stretch tensor U, the left-stretch tensor V, and the rotation tensor R: 11 Plot the initial unit sphere X deformation: + X 22+ X 23=1 12 and its shape after the CODE: #Input thông tin import numpy as np m1 = [] print("Mời nhập giá trị tensor mô tả ánh xạ:") R = C = int(input("nxn: ")) m1 = [[int(input()) for x in range (C)] for y in range(R)] a11= m1[0][0] a22= m1[1][1] a33= m1[2][2] a12= m1[0][1] a13= m1[0][2] a21= m1[1][0] a31= m1[2][0] a23= m1[1][2] a32= m1[2][1] # The deformation gradient tensor F import numpy as np F = np.array([[a11, a12, a13], [a21, a22, a23], [a31, a32, a33] ]) print (F) # The transpose F FT = np.transpose(F) print(FT) #The deformation tensor G G = np.dot(F, FT) print(G) #The Jacobian J det = np.linalg.det(F) #The strain tensor E I=np.eye(3) E= 1/2*(G-I) #The right-stretch tensor U, the left-stretch tensor V, and the rotation tensor R V=G**(1/2) V_inv = np.linalg.inv(V) R=np.dot(V_inv, F) R_inv = np.linalg.inv(R) U = R=np.dot(R_inv, F) print(V,R,U) 13 Plot the initial unit sphere X 21 + X 22+ X 23=1 and its shape after the deformation code Step 1: Import the necessary libraries: matplotlib.pyplot: to plot mpl_toolkits.mplot3d.Axes3D: to plot 3D numpy: to perform calculations of matrices Step 2: get the matrix from the problem data mat= np.linalg.inv(F) Step 3: Initialize the figure with subplots (2 columns side by side) # Initialize figure with subplots fig = plt.figure() a1 = fig.add_subplot(121, projection='3d') a2 = fig.add_subplot(122, projection='3d') • a1 is used to draw the initial unit sphere • a2 is used to draw the deformed sphere through the imported matrix Step 4: Initialize the initial unit sphere with the following arguments: # Initialize unit sphere u, v = np.mgrid[0:2*np.pi:20j, 0:np.pi:10j] x = np.cos(u) * np.sin(v) y = np.sin(u) * np.sin(v) z = np.cos(v) cmap = plt.get_cmap('rainbow') norm = plt.Normalize(z.min(), z.max()) facecolors = cmap(norm(z)) circle1 = a1.plot_surface(x, y, z, facecolors=facecolors, shade=False) 14 • np.mgrid[0:2*np.pi:20j, 0:np.pi:10j]: Creates a grid of points in 2D coordinate space • np.cos(u) * np.sin(v): Calculate the x-value • np.sin(u) * np.sin(v): Calculate the y-value • np.cos(v): Calculate the z-value cmap = plt.get_cmap('viridis'): Get a viridis colormap from Matplotlib package The viridis colormap is a popular colormap which ranges from dark blue to yellow, with green in the middle norm = plt.Normalize(z.min(), z.max()): Normalize the variable z to a range between its minimum and maximum values This is important to ensure that the values in z are mapped proportionally to the colors in the colormap facecolors = cmap(norm(z)): Create an array of colors based on the normalized values in z using the viridis colormap This array of colors will be used to color the faces of the 3D plot, with darker colors representing smaller values of z and lighter colors representing larger values of z Step 5: Perform matrix transformation to transform the original sphere into a deformed sphere through the imported matrix # Initialize deformed sphere cds = np.vstack((x.flatten(), y.flatten(), z.flatten())) new_cds = mat.dot(cds) xnew = new_cds[0, ].reshape(x.shape) ynew = new_cds[1, ].reshape(y.shape) znew = new_cds[2, ].reshape(z.shape) facecolors_new = cmap(norm(znew)) strange_cirlce2 = a2.plot_surface(xnew, ynew, znew, facecolors=facecolors_new, shade=False) cds: Generate an nxn matrix (n is the number of points of the original sphere) 15 new_cds: Perform the coords matrix mathematical transformation through the imported matrix mat xnew, ynew, znew: Calculate the x, y, z values of the deformed sphere after matrixing facecolors_new: Use to set the color for the sphere This code is used to initialize and display a deformed sphere on the x, y and z coordinate axes Implementation steps: Make a list of the coordinates of the points on the sphere by taking all the values of x, y, z stored in the array and then aggregating them into a dimensional array of coordinates in vertical order by columns Use the matrix to transform these coordinates, then store the new coordinates in the variables xnew, ynew and znew The color of each point is determined by its z value and normalized to include it in a cmap (color map) Create a deformed sphere object with new coordinates and colors, then display it on an axis named a2 With 3D rendering properties, the sum of all the above steps is to render a deformed 3D sphere # Function update frame def update(num): a1.view_init(elev=10., azim=num) a2.view_init(elev=10., azim=num) return circle1, strange_cirlce2 • ax1 view_init and ax2 view_init: Change the viewing angle of the subplots (ax1 and ax2) to ensure the animation is done in a good perspective • Returns s1 (original unit sphere) and s2 (deformed sphere) objects to update the sphere in each frame 16 Step 7: Display 17