From 49b3cd2145d5d4ba140e92a8aeb76b7608ea9a09 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 13 Sep 2019 06:32:05 -0700 Subject: [PATCH 1/8] transpose evuivalent for rot but faster --- processing/post/addStrainTensors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/processing/post/addStrainTensors.py b/processing/post/addStrainTensors.py index 2d62c31ae..97c83a9c4 100755 --- a/processing/post/addStrainTensors.py +++ b/processing/post/addStrainTensors.py @@ -137,8 +137,8 @@ for name in filenames: F = np.array(list(map(float,table.data[column:column+items['tensor']['dim']])),'d').reshape(items['tensor']['shape']) (U,S,Vh) = np.linalg.svd(F) # singular value decomposition R = np.dot(U,Vh) # rotation of polar decomposition - stretch['U'] = np.dot(np.linalg.inv(R),F) # F = RU - stretch['V'] = np.dot(F,np.linalg.inv(R)) # F = VR + stretch['U'] = np.dot(R.T,F) # F = RU + stretch['V'] = np.dot(F,R.T) # F = VR for theStretch in stretches: stretch[theStretch] = np.where(abs(stretch[theStretch]) < 1e-12, 0, stretch[theStretch]) # kill nasty noisy data From 79d2432c6cfd3f8df7f6eecdd0e039c08d192d17 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 13 Sep 2019 06:33:00 -0700 Subject: [PATCH 2/8] R not needed --- processing/post/addStrainTensors.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/processing/post/addStrainTensors.py b/processing/post/addStrainTensors.py index 97c83a9c4..b7b21c92e 100755 --- a/processing/post/addStrainTensors.py +++ b/processing/post/addStrainTensors.py @@ -136,9 +136,9 @@ for name in filenames: for column in items['tensor']['column']: # loop over all requested defgrads F = np.array(list(map(float,table.data[column:column+items['tensor']['dim']])),'d').reshape(items['tensor']['shape']) (U,S,Vh) = np.linalg.svd(F) # singular value decomposition - R = np.dot(U,Vh) # rotation of polar decomposition - stretch['U'] = np.dot(R.T,F) # F = RU - stretch['V'] = np.dot(F,R.T) # F = VR + R_inv = np.dot(U,Vh).T # rotation of polar decomposition + stretch['U'] = np.dot(R_inv,F) # F = RU + stretch['V'] = np.dot(F,R_inv) # F = VR for theStretch in stretches: stretch[theStretch] = np.where(abs(stretch[theStretch]) < 1e-12, 0, stretch[theStretch]) # kill nasty noisy data From 66d8a3e601e482445528ea9fa21ac5ab9a53c737 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 13 Sep 2019 06:34:48 -0700 Subject: [PATCH 3/8] stretch is symmetric (play it safe here) --- processing/post/addStrainTensors.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/processing/post/addStrainTensors.py b/processing/post/addStrainTensors.py index b7b21c92e..5a10f7d6e 100755 --- a/processing/post/addStrainTensors.py +++ b/processing/post/addStrainTensors.py @@ -142,17 +142,17 @@ for name in filenames: for theStretch in stretches: stretch[theStretch] = np.where(abs(stretch[theStretch]) < 1e-12, 0, stretch[theStretch]) # kill nasty noisy data - (D,V) = np.linalg.eig(stretch[theStretch]) # eigen decomposition (of symmetric matrix) + (D,V) = np.linalg.eigh((stretch[theStretch]+stretch[theStretch].T)*0.5) # eigen decomposition (of symmetric(ed) matrix) neg = np.where(D < 0.0) # find negative eigenvalues ... D[neg] *= -1. # ... flip value ... V[:,neg] *= -1. # ... and vector for i,eigval in enumerate(D): if np.dot(V[:,i],V[:,(i+1)%3]) != 0.0: # check each vector for orthogonality V[:,(i+1)%3] = np.cross(V[:,(i+2)%3],V[:,i]) # correct next vector - V[:,(i+1)%3] /= np.sqrt(np.dot(V[:,(i+1)%3],V[:,(i+1)%3].conj())) # and renormalize (hyperphobic?) + V[:,(i+1)%3] /= np.sqrt(np.dot(V[:,(i+1)%3],V[:,(i+1)%3])) # and renormalize (hyperphobic?) for theStrain in strains: d = operator(theStretch,theStrain,D) # operate on eigenvalues of U or V - eps = (np.dot(V,np.dot(np.diag(d),V.T)).real).reshape(9) # build tensor back from eigenvalue/vector basis + eps = np.dot(V,np.dot(np.diag(d),V.T)).reshape(9) # build tensor back from eigenvalue/vector basis table.data_append(list(eps)) From cd6a4d1cfd655581fbb022f0d52a868bf2144db8 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 13 Sep 2019 06:37:47 -0700 Subject: [PATCH 4/8] that's all we need --- processing/post/addStrainTensors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processing/post/addStrainTensors.py b/processing/post/addStrainTensors.py index 5a10f7d6e..2c5d2505e 100755 --- a/processing/post/addStrainTensors.py +++ b/processing/post/addStrainTensors.py @@ -146,7 +146,7 @@ for name in filenames: neg = np.where(D < 0.0) # find negative eigenvalues ... D[neg] *= -1. # ... flip value ... V[:,neg] *= -1. # ... and vector - for i,eigval in enumerate(D): + for i in [0,1,2]: if np.dot(V[:,i],V[:,(i+1)%3]) != 0.0: # check each vector for orthogonality V[:,(i+1)%3] = np.cross(V[:,(i+2)%3],V[:,i]) # correct next vector V[:,(i+1)%3] /= np.sqrt(np.dot(V[:,(i+1)%3],V[:,(i+1)%3])) # and renormalize (hyperphobic?) From 0497b58629f8ac7ef1f5158bc83b7c4fc46638eb Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 13 Sep 2019 06:38:22 -0700 Subject: [PATCH 5/8] use existing functionality --- processing/post/addStrainTensors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/processing/post/addStrainTensors.py b/processing/post/addStrainTensors.py index 2c5d2505e..44b3841b4 100755 --- a/processing/post/addStrainTensors.py +++ b/processing/post/addStrainTensors.py @@ -149,7 +149,7 @@ for name in filenames: for i in [0,1,2]: if np.dot(V[:,i],V[:,(i+1)%3]) != 0.0: # check each vector for orthogonality V[:,(i+1)%3] = np.cross(V[:,(i+2)%3],V[:,i]) # correct next vector - V[:,(i+1)%3] /= np.sqrt(np.dot(V[:,(i+1)%3],V[:,(i+1)%3])) # and renormalize (hyperphobic?) + V[:,(i+1)%3] /= np.linalg.norm(V[:,(i+1)%3]) # and renormalize (hyperphobic?) for theStrain in strains: d = operator(theStretch,theStrain,D) # operate on eigenvalues of U or V eps = np.dot(V,np.dot(np.diag(d),V.T)).reshape(9) # build tensor back from eigenvalue/vector basis From 890a6cf42fb708140068c1a810caaec2018aed00 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 13 Sep 2019 06:40:41 -0700 Subject: [PATCH 6/8] avoid floating point comparison and simply play it safe --- processing/post/addStrainTensors.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/processing/post/addStrainTensors.py b/processing/post/addStrainTensors.py index 44b3841b4..c210291d9 100755 --- a/processing/post/addStrainTensors.py +++ b/processing/post/addStrainTensors.py @@ -147,9 +147,8 @@ for name in filenames: D[neg] *= -1. # ... flip value ... V[:,neg] *= -1. # ... and vector for i in [0,1,2]: - if np.dot(V[:,i],V[:,(i+1)%3]) != 0.0: # check each vector for orthogonality - V[:,(i+1)%3] = np.cross(V[:,(i+2)%3],V[:,i]) # correct next vector - V[:,(i+1)%3] /= np.linalg.norm(V[:,(i+1)%3]) # and renormalize (hyperphobic?) + V[:,(i+1)%3] = np.cross(V[:,(i+2)%3],V[:,i]) # correct next vector + V[:,(i+1)%3] /= np.linalg.norm(V[:,(i+1)%3]) # and renormalize (hyperphobic?) for theStrain in strains: d = operator(theStretch,theStrain,D) # operate on eigenvalues of U or V eps = np.dot(V,np.dot(np.diag(d),V.T)).reshape(9) # build tensor back from eigenvalue/vector basis From a3c6f6682e7f91de665830d3f5c564c85092cd6d Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 13 Sep 2019 06:42:01 -0700 Subject: [PATCH 7/8] using eigh should ensure orthogonal eigenvectors --- processing/post/addStrainTensors.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/processing/post/addStrainTensors.py b/processing/post/addStrainTensors.py index c210291d9..d2dece05e 100755 --- a/processing/post/addStrainTensors.py +++ b/processing/post/addStrainTensors.py @@ -146,9 +146,6 @@ for name in filenames: neg = np.where(D < 0.0) # find negative eigenvalues ... D[neg] *= -1. # ... flip value ... V[:,neg] *= -1. # ... and vector - for i in [0,1,2]: - V[:,(i+1)%3] = np.cross(V[:,(i+2)%3],V[:,i]) # correct next vector - V[:,(i+1)%3] /= np.linalg.norm(V[:,(i+1)%3]) # and renormalize (hyperphobic?) for theStrain in strains: d = operator(theStretch,theStrain,D) # operate on eigenvalues of U or V eps = np.dot(V,np.dot(np.diag(d),V.T)).reshape(9) # build tensor back from eigenvalue/vector basis From 52904a81dc26bb0c93e4940d4d286af66db0f3f0 Mon Sep 17 00:00:00 2001 From: Martin Diehl Date: Fri, 13 Sep 2019 06:49:25 -0700 Subject: [PATCH 8/8] taking prospector complaints serious --- processing/post/addStrainTensors.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/processing/post/addStrainTensors.py b/processing/post/addStrainTensors.py index d2dece05e..5022c1d34 100755 --- a/processing/post/addStrainTensors.py +++ b/processing/post/addStrainTensors.py @@ -13,7 +13,7 @@ scriptName = os.path.splitext(os.path.basename(__file__))[0] scriptID = ' '.join([scriptName,damask.version]) def operator(stretch,strain,eigenvalues): - """Albrecht Bertram: Elasticity and Plasticity of Large Deformations An Introduction (3rd Edition, 2012), p. 102""" + """Albrecht Bertram: Elasticity and Plasticity of Large Deformations An Introduction (3rd Edition, 2012), p. 102.""" return { 'V#ln': np.log(eigenvalues) , 'U#ln': np.log(eigenvalues) , @@ -88,7 +88,7 @@ for name in filenames: try: table = damask.ASCIItable(name = name, buffered = False) - except: continue + except IOError: continue damask.util.report(scriptName,name) # ------------------------------------------ read header ------------------------------------------