Mechanics of Defect Evolution Library
Loading...
Searching...
No Matches
periodicEnergy/test.py
Go to the documentation of this file.
1# /opt/local/bin/python3.13 test.py
2import sys, string, os
3import numpy as np
4import matplotlib.pyplot as plt
5plt.rcParams['text.usetex'] = True
6sys.path.insert(0, '../../python')
7from modlibUtils import *
8
9compute=True
10periodicImageMatrix=np.array([[0,0,0],[1,1,1],[2,2,2],[4,4,4]])
11EwaldLengthDivisions=2
12#periodicImageMatrix=np.array([[0,0,0],[1,1,0],[2,2,0],[4,4,0],[4,4,4]])
13#EwaldLengthFactors=np.array([0.0,10.0])
14
15
16if compute:
17 curDir=os.getcwd()
18 microstrucureFile=getStringInFile('inputFiles/initialMicrostructure.txt','microstructureFile')
19 microstrucureFileName=curDir+'/inputFiles/'+microstrucureFile
20 ddFileName=curDir+'/inputFiles/DD.txt'
21
22 for k in range(0,np.size(periodicImageMatrix,0)):
23 periodicImageSize=periodicImageMatrix[k]
24 #EwaldLengthFactors=np.array([0,1,periodicImageSize[0]])
25 #EwaldLengthFactors=np.array([periodicImageSize[0]])
26# EwaldLengthFactors=np.linspace(0, periodicImageSize[0], num=EwaldLengthDivisions)
27 EwaldLengthFactors=np.linspace(0.0, 1.0, num=EwaldLengthDivisions)
28 print("periodicImageSize="+str(periodicImageSize))
29 print("EwaldLengthFactors="+str(EwaldLengthFactors))
30
31
32 for c in range(0,np.size(EwaldLengthFactors)):
33 #periodicImageSize=np.array([1,1,1])
34 EwaldLengthFactor=EwaldLengthFactors[c];
35 setInputVariable(ddFileName,'EwaldLengthFactor',str(EwaldLengthFactor))
36 setInputVector(ddFileName,'periodicImageSize',periodicImageSize,'number of periodic images along each period vector')
37
38 if microstrucureFile=='periodicDipoleIndividual.txt':
39 setInputVariable(microstrucureFileName,'periodicDipoleExitFaceIDs',str(1)) # 1=edge, 0=screw
40 #X=np.linspace(0, 200, num=40)
41 X=np.linspace(0, 110, num=20)
42# X=np.linspace(0, 110, num=10)
43
44 E=X*0.0;
45 S11=X*0.0;
46 S12=X*0.0;
47 S13=X*0.0;
48 S22=X*0.0;
49 S23=X*0.0;
50 S33=X*0.0;
51 for k in range(0,len(X)):
52 x=X[k]
53 os.system('rm -r F/*.*')
54 os.system('rm -r config/*.*')
55 setInputVariable(microstrucureFileName,'glideSteps',str(x))
56 os.system('../../build/tools/MicrostructureGenerator/microstructureGenerator '+ curDir)
57 os.system('../../build/tools/DDomp/DDomp '+ curDir)
58 F,Flabels=readFfile('./F')
59 E[k]=getFarray(F,Flabels,'dislocation elastic energy [mu b^3]')
60 aux =readAUXtxt('config/ddAux_0')
61 S11[k]=np.mean(aux.gaussPoints[:,10])
62 S12[k]=np.mean(aux.gaussPoints[:,11])
63 S13[k]=np.mean(aux.gaussPoints[:,12])
64 S22[k]=np.mean(aux.gaussPoints[:,14])
65 S23[k]=np.mean(aux.gaussPoints[:,15])
66 S33[k]=np.mean(aux.gaussPoints[:,18])
67 else:
68 print('unsupported option')
69
70 data=np.empty([np.size(X),8])
71 data[:,0]=X
72 data[:,1]=E
73 data[:,2]=S11
74 data[:,3]=S22
75 data[:,4]=S33
76 data[:,5]=S23
77 data[:,6]=S13
78 data[:,7]=S12
79 #data=np.array([X.transpose(),E.transpose(),S11.transpose(),S22.transpose(),S12.transpose()])
80 #data=np.array([X,E,S11,S22,S12]).reshape(np.size(X),5)
81# if periodicImageCentered:
82# outFilePrefix='centered'
83# else:
84# outFilePrefix='uncentered'
85
86 outFileName='data'+'_'+str(periodicImageSize[0])+'_'+str(periodicImageSize[1])+'_'+str(periodicImageSize[2])+'_'+str(EwaldLengthFactor)+'.txt'
87 np.savetxt(outFileName, data)
88
89dataDict=dict()
90#uncentered=dict()
91for k in range(0,np.size(periodicImageMatrix,0)):
92 periodicImageSize=periodicImageMatrix[k]
93 #EwaldLengthFactors=np.array([0,1,periodicImageSize[0]])
94# EwaldLengthFactors=np.array([periodicImageSize[0]])
95# EwaldLengthFactors=np.linspace(0, periodicImageSize[1], num=EwaldLengthDivisions)
96 EwaldLengthFactors=np.linspace(0.0, 1.0, num=EwaldLengthDivisions)
97
98
99 for c in range(0,np.size(EwaldLengthFactors)):
100 EwaldLengthFactor=EwaldLengthFactors[c];
101 key=str(periodicImageSize[0])+'_'+str(periodicImageSize[1])+'_'+str(periodicImageSize[2])+'_'+str(EwaldLengthFactor)
102 print(key)
103 FileName='data_'+key+'.txt'
104# uFileName='uncentered_'+str(periodicImageSize[0])+'_'+str(periodicImageSize[1])+'_'+str(periodicImageSize[2])+'.txt'
105 dataDict[key]=np.loadtxt(FileName);
106# uncentered[key]=np.loadtxt(uFileName);
107
108
109fields=['energy','sigma11','sigma22','sigma33','sigma23','sigma13','sigma12']
110fieldLabels=['elastic energy $[\mu b^3]$','$\sigma_{11}$ $[\mu]$','$\sigma_{22}$ $[\mu]$','$\sigma_{33}$ $[\mu]$','$\sigma_{23}$ $[\mu]$','$\sigma_{13}$ $[\mu]$','$\sigma_{12}$ $[\mu]$']
111for k in range(0,len(fields)):
112 # plots with centered images
113 fig1 = plt.figure()
114 ax1=plt.subplot(1,1,1)
115 for key in dataDict:
116 data=dataDict[key]
117 ax1.plot(data[:,0], data[:,k+1],label=key)
118 ax1.grid()
119 ax1.legend()
120 plt.xlabel('dipole distance $[b]$')
121 plt.ylabel(fieldLabels[k])
122 fig1.savefig(fields[k], bbox_inches='tight')
123
124 # plots with uncentered images
125# fig1 = plt.figure()
126# ax1=plt.subplot(1,1,1)
127# for key in uncentered:
128# data=uncentered[key]
129# ax1.plot(data[:,0], data[:,k+1],label=' u'+key)
130# ax1.grid()
131# ax1.legend()
132# plt.xlabel('dipole distance $[b]$')
133# plt.ylabel(fieldLabels[k])
134# fig1.savefig(fields[k]+'_uncentered', bbox_inches='tight')
setInputVector(fileName, variable, newVal, newCom)
readFfile(folder)
setInputVariable(fileName, variable, newVal)
getStringInFile(fileName, variable)
getFarray(F, Flabels, label)
readAUXtxt(filename)