<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Simultaneous deformation
Step1:  Naive concept of simultaneous deformation
Here we try to split simple shear and pure shear to several incremental steps and mutually superposed those increments to simulate simultaneous deformation. We will use following deformation gradients for total simple shear and pure shear
Step2:  To divide simple shear deformation with $\gamma$=1 to n incremental steps
Step3:  To check that supperposition of those increments give as total deformation, we can use allclose numpy function
Step4:  Knowing that deformation superposition is not cimmutative, we can check that axial ratio of finite strain resulting from simple shear superposed on pure shear and vice-versa is really different
Step5:  Lets try to split those deformation to two increments and mutually mix them
Step6:  It is now close to each other, but still quite different. So let's split it to much more increments....
Step7:  Now it is very close. Let's visualize how finite strain converge with increasing number of increments
Step8:  Using spatial velocity gradient
We need to import matrix exponential and matrix logarithm functions from scipy.linalg
Step9:  Spatial velocity gradient could be obtained as matrix logarithm of deformation gradient
Step10:  Total spatial velocity gradient of simulatanous deformation could be calculated by summation of individual ones
Step11:  Resulting deformation gradient could be calculated as matrix exponential of total spatial velocity gradient
Step12:  Lets overlay it on previous diagram
Step13:  Decomposition of spatial velocity gradient
Here we will decompose spatial velocity gradient of simple shear to rate of deformation tensor and spin tensor.
Step14:  Check that decomposition give total spatial velocity gradient
Step15:  Visualize spatial velocity gradients for rate of deformation tensor
Step16:  Visualize spatial velocity gradients for spin tensor
<ASSISTANT_TASK:>
Python Code:
%pylab inline
from sg2lib import *
Explanation: Simultaneous deformation
End of explanation
gamma = 1
Sx = 2
Fs = array([[1, gamma], [0, 1]])
Fp = array([[Sx, 0], [0, 1/Sx]])
Explanation: Naive concept of simultaneous deformation
Here we try to split simple shear and pure shear to several incremental steps and mutually superposed those increments to simulate simultaneous deformation. We will use following deformation gradients for total simple shear and pure shear:
End of explanation
n = 10
Fsi = array([[1, gamma/n], [0, 1]])
print('Incremental deformation gradient:')
print(Fsi)
Explanation: To divide simple shear deformation with $\gamma$=1 to n incremental steps
End of explanation
array_equal(matrix_power(Fsi, n), Fs)
Fpi = array([[Sx**(1/n), 0], [0, Sx**(-1/n)]])
print('Incremental deformation gradient:')
print(Fpi)
allclose(matrix_power(Fpi, n), Fp)
Explanation: To check that supperposition of those increments give as total deformation, we can use allclose numpy function
End of explanation
u,s,v = svd(Fs @ Fp)
print('Axial ratio of finite strain resulting from simple shear superposed on pure shear: {}'.format(s[0]/s[1]))
u,s,v = svd(Fp @ Fs)
print('Axial ratio of finite strain resulting from pure shear superposed on simple shear: {}'.format(s[0]/s[1]))
Explanation: Knowing that deformation superposition is not cimmutative, we can check that axial ratio of finite strain resulting from simple shear superposed on pure shear and vice-versa is really different:
End of explanation
Fsi = array([[1, gamma/2], [0, 1]])
Fpi = array([[Sx**(1/2), 0], [0, Sx**(-1/2)]])
u,s,v = svd(Fsi @ Fpi @ Fsi @ Fpi)
print('Axial ratio of finite strain of superposed increments starting with pure shear: {}'.format(s[0]/s[1]))
u,s,v = svd(Fpi @ Fsi @ Fpi @ Fsi)
print('Axial ratio of finite strain of superposed increments starting with simple shear: {}'.format(s[0]/s[1]))
Explanation: Lets try to split those deformation to two increments and mutually mix them:
End of explanation
n = 100
Fsi = array([[1, gamma/n], [0, 1]])
Fpi = array([[Sx**(1/n), 0], [0, Sx**(-1/n)]])
u,s,v = svd(matrix_power(Fsi @ Fpi, n))
print('Axial ratio of finite strain of superposed increments starting with pure shear: {}'.format(s[0]/s[1]))
u,s,v = svd(matrix_power(Fpi @ Fsi, n))
print('Axial ratio of finite strain of superposed increments starting with simple shear: {}'.format(s[0]/s[1]))
Explanation: It is now close to each other, but still quite different. So let's split it to much more increments....
End of explanation
arp = []
ars = []
ninc = range(1, 201)
for n in ninc:
    Fsi = array([[1, gamma/n], [0, 1]])
    Fpi = array([[Sx**(1/n), 0], [0, Sx**(-1/n)]])
    u,s,v = svd(matrix_power(Fsi @ Fpi, n))
    arp.append(s[0]/s[1])
    u,s,v = svd(matrix_power(Fpi @ Fsi, n))
    ars.append(s[0]/s[1])
figure(figsize=(16, 4))
semilogy(ninc, arp, 'r', label='Pure shear first')
semilogy(ninc, ars, 'g', label='Simple shear first')
legend()
xlim(1, 200)
xlabel('Number of increments')
ylabel('Finite strain axial ratio');
Explanation: Now it is very close. Let's visualize how finite strain converge with increasing number of increments:
End of explanation
from scipy.linalg import expm, logm
Explanation: Using spatial velocity gradient
We need to import matrix exponential and matrix logarithm functions from scipy.linalg
End of explanation
Lp = logm(Fp)
Ls = logm(Fs)
Explanation: Spatial velocity gradient could be obtained as matrix logarithm of deformation gradient
End of explanation
L = Lp + Ls
Explanation: Total spatial velocity gradient of simulatanous deformation could be calculated by summation of individual ones
End of explanation
F = expm(L)
u,s,v = svd(F)
sar = s[0]/s[1]
print('Axial| ratio of finite strain of simultaneous pure shear and simple shear: {}'.format(sar))
Explanation: Resulting deformation gradient could be calculated as matrix exponential of total spatial velocity gradient
End of explanation
arp = []
ars = []
ninc = range(1, 201)
for n in ninc:
    Fsi = array([[1, gamma/n], [0, 1]])
    Fpi = array([[Sx**(1/n), 0], [0, Sx**(-1/n)]])
    u,s,v = svd(matrix_power(Fsi @ Fpi, n))
    arp.append(s[0]/s[1])
    u,s,v = svd(matrix_power(Fpi @ Fsi, n))
    ars.append(s[0]/s[1])
figure(figsize=(16, 4))
semilogy(ninc, arp, 'r', label='Pure shear first')
semilogy(ninc, ars, 'g', label='Simple shear first')
legend()
xlim(1, 200)
axhline(sar)
xlabel('Number of increments')
ylabel('Finite strain axial ratio');
Explanation: Lets overlay it on previous diagram
End of explanation
L = logm(Fs)
D = (L + L.T)/2
W = (L - L.T)/2
Explanation: Decomposition of spatial velocity gradient
Here we will decompose spatial velocity gradient of simple shear to rate of deformation tensor and spin tensor.
End of explanation
allclose(D + W, L)
Explanation: Check that decomposition give total spatial velocity gradient
End of explanation
vel_field(D)
Explanation: Visualize spatial velocity gradients for rate of deformation tensor
End of explanation
vel_field(W)
Explanation: Visualize spatial velocity gradients for spin tensor
End of explanation
<END_TASK>