27 __author__=
'IMDEA Materials-Mohammad Marvi Mashhadi: mohammad.marvi@imdea.org, mohamadmarvi@gmail.com' 29 import os,sys,datetime,re,os.path,time,commands,glob,random,math,numpy
as np
30 from itertools
import groupby
31 from scipy.integrate
import quad
32 from scipy.stats
import itemfreq
34 INPUT_FILE =
"Inputs.in" 35 OUTPUT_FILE =
"Outputs.in" 36 WORKING_DIR = os.getcwd()
38 USER = os.getenv(
"USER")
39 TIMESTAMP = str(datetime.datetime.now()).split(
'.')[0]
43 AbaqusVersion=
'abq6101' 54 PUinWall=1-strut_content
58 A1,A2,A3,A4,A5=2.77,0.962,3.4033,-0.2291,1.0255
61 mypath=WORKING_DIR+
'/' 65 while SuccessInMeshing==1:
66 SuccessInTessellation=1
67 while SuccessInTessellation==1:
68 myfile=os.path.join(mypath,
'Project01.prj')
70 f.write(
'{0:34s}\n'.format(
'# RANDOM COORDINATES: 0 OR FILE: 1'))
71 f.write(
'{0}\n{1}\n{2:d}\n{3}\n'.format(
'0',
'# NUMBER OF SPHERES',NumOfCells,
'# LENGTH IN X-, Y- AND Z-DIRECTION'))
72 f.write(
'{0:f}\n{0:f}\n{0:f}\n'.format(CubeLength))
73 f.write(
'{0}\n{1}\n{2}\n{3}\n{4}\n'.format(
'# EPSILON',
'0.0001',
'# NTAU',
'963800000',
'# NOMINAL DENSITY'))
74 f.write(
'{0}\n'.format(
'0.60'))
75 f.write(
'{0}\n{1}\n{2}\n{3}\n{4}\n'.format(
'# MAX. AND MINIM. DIAMETER',
'3.0',
'1.0',
'# MAX. NUMBER OF STEPS',
'50000000'))
76 f.write(
'{0}\n{1}\n{2}\n'.format(
'# DISTRIBUTION',
'3',
'# DISTRIBUTION PARAMETERS'))
77 f.write(
'{0:f}\n{1:f}\n'.format(MU,SIGMA))
78 f.write(
'{0}\n{1}\n{2}\n{3}\n{4}\n{5}\n{6}\n{7}\n{8}\n'.format(
'0.4',
'-3.3',
'3',
'0.10',
'0.20',
'0.70',
'0.902113',
'3.000000',
'1.000000'))
80 os.system(
'./spherepack')
82 time.sleep(1);files = os.listdir(
'.')
83 if (
'Project01.rco' in files):
85 myfile12=os.path.join(mypath,
'Project01.rco')
86 CentersRads=np.loadtxt(myfile12,usecols = (0,1,2,3))
87 CentersRads1=np.array([])
88 ExtraVolume=ExtraVolumeRatio*CubeLength
89 for i
in range(int(len(CentersRads))):
90 CentersRads1=np.append(CentersRads1,CentersRads[i][0]);CentersRads1=np.append(CentersRads1,CentersRads[i][1])
91 CentersRads1=np.append(CentersRads1,CentersRads[i][2]);CentersRads1=np.append(CentersRads1,CentersRads[i][3])
92 ExtraVolume=ExtraVolumeRatio*CubeLength
93 for i
in range(int(len(CentersRads))):
94 if (CentersRads[i][0])<(ExtraVolume):
95 CentersRads1=np.append(CentersRads1,CubeLength+(ExtraVolume-CentersRads[i][0]))
96 CentersRads1=np.append(CentersRads1,CentersRads[i][1]);CentersRads1=np.append(CentersRads1,CentersRads[i][2])
97 CentersRads1=np.append(CentersRads1,CentersRads[i][3])
98 CentersRads2=np.array([])
99 for i
in range(int(len(CentersRads1)/4)):
100 CentersRads2=np.append(CentersRads2,CentersRads1[4*i]);CentersRads2=np.append(CentersRads2,CentersRads1[1+4*i])
101 CentersRads2=np.append(CentersRads2,CentersRads1[2+4*i]);CentersRads2=np.append(CentersRads2,CentersRads1[3+4*i])
102 for i
in range(int(len(CentersRads1)/4)):
103 if (CentersRads1[1+4*i])<(ExtraVolume):
104 CentersRads2=np.append(CentersRads2,CentersRads1[4*i])
105 CentersRads2=np.append(CentersRads2,CubeLength+(ExtraVolume-CentersRads1[1+4*i]))
106 CentersRads2=np.append(CentersRads2,CentersRads1[2+4*i]);CentersRads2=np.append(CentersRads2,CentersRads1[3+4*i])
107 CentersRads3=np.array([])
108 for i
in range(int(len(CentersRads2)/4)):
109 CentersRads3=np.append(CentersRads3,CentersRads2[4*i]);CentersRads3=np.append(CentersRads3,CentersRads2[1+4*i])
110 CentersRads3=np.append(CentersRads3,CentersRads2[2+4*i]);CentersRads3=np.append(CentersRads3,CentersRads2[3+4*i])
111 for i
in range(int(len(CentersRads2)/4)):
112 if (CentersRads2[2+4*i])<(ExtraVolume):
113 CentersRads3=np.append(CentersRads3,CentersRads2[4*i]);CentersRads3=np.append(CentersRads3,CentersRads2[1+4*i])
114 CentersRads3=np.append(CentersRads3,CubeLength+(ExtraVolume-CentersRads2[2+4*i]))
115 CentersRads3=np.append(CentersRads3,CentersRads2[3+4*i])
116 myfile3=os.path.join(mypath,
'Centers.txt')
118 for i
in range(0,int(len(CentersRads3))/4):
119 ff.write(
'{0:f}\t{1:f}\t{2:f}\n'.format(CentersRads3[4*i],CentersRads3[1+4*i],CentersRads3[2+4*i]))
121 myfile4=os.path.join(mypath,
'Rads.txt')
122 fff=open(myfile4,
'w')
123 for i
in range(0,int(len(CentersRads3))/4):
124 fff.write(
'{0:f}\n'.format(CentersRads3[3+4*i]/2))
127 NumOfCells1=int(len(CentersRads3)/4)
128 RVElength=CubeLength+(ExtraVolumeRatio*CubeLength)
130 commandTessellation=
"neper -T -n {0:d} -domain 'cube({1},{1},{1})' -morphooptiini 'coo:file({2}Centers.txt),weight:file({2}Rads.txt)' -regularization 1 -mloop 1 -o {2}RVE27 -format geo -statcell vol -statedge length -statface area -statver x".format((NumOfCells1),RVElength,mypath)
131 os.system(commandTessellation)
133 files = os.listdir(
'.')
134 if (
'RVE27.geo' in files):
135 SuccessInTessellation=0
136 os.remove(
'Project01.prj');os.remove(
'Project01.rst');os.remove(
'Project01.sco');os.remove(
'Project01.rco')
137 os.remove(
'Rads.txt');os.remove(
'Centers.txt')
139 myfile12=os.path.join(mypath,
'RVE27.stver')
140 verX=np.loadtxt(myfile12)
142 myfile12=os.path.join(mypath,
'RVE27.stedge')
143 EdgesLength=np.loadtxt(myfile12)
144 NumOfEdges=len(EdgesLength)
145 EdgeLengths=np.array([])
146 for i
in range(0,int(NumOfEdges)):
147 c=np.array(EdgesLength[i])
148 EdgeLengths=np.append(EdgeLengths,c)
149 myfile12=os.path.join(mypath,
'RVE27.stface')
150 SurfacesArea=np.loadtxt(myfile12)
151 NumOfSurfaces=len(SurfacesArea)
152 myfile12=os.path.join(mypath,
'RVE27.stcell')
153 CellVolumes=np.loadtxt(myfile12)
154 NumOfVolumes=len(CellVolumes)
155 myfile12=os.path.join(mypath,
'RVE27.geo')
156 text_file = open(myfile12,
"r") lines = text_file.readlines() 158 os.remove('RVE27.geo')
159 os.remove(
'RVE27.stcell');os.remove(
'RVE27.stedge');os.remove(
'RVE27.stface');os.remove(
'RVE27.stver')
161 Nodes=range(NumOfNodes)
162 for i
in range(0,NumOfNodes):
163 currentline = lines[i].split(
"{")
164 a=currentline[1].split(
"}")
167 Nodes[t]=np.absolute(c.astype(np.float))
169 Edges=range(NumOfEdges)
172 for i
in range(NumOfNodes,NumOfNodes+NumOfEdges):
173 currentline = lines[i].split(
"{")
174 a=currentline[1].split(
"}")
177 Edges[t]=np.absolute(c.astype(np.float))
179 Faces=range(NumOfSurfaces)
182 for i
in range(0,NumOfSurfaces):
183 j=NumOfNodes+NumOfEdges+(2*i)
184 currentline = lines[j].split(
"{")
185 a=currentline[1].split(
"}")
188 Faces[t]=(c.astype(np.float))
190 Volumes=range(NumOfVolumes)
191 a=list(lines[NumOfNodes+NumOfEdges+(2*NumOfSurfaces)])
195 lines[NumOfNodes+NumOfEdges+(2*NumOfSurfaces)]=
"".join(a)
196 currentline=lines[NumOfNodes+NumOfEdges+(2*NumOfSurfaces)].split(
",")
197 c=np.array(currentline)
198 Volumes[0]=np.absolute(c.astype(np.float))
200 for i
in range(1,2*NumOfVolumes):
202 j=NumOfNodes+NumOfEdges+(2*NumOfSurfaces)+i
203 currentline = lines[j].split(
" = {")
204 a=currentline[1].split(
"}")
207 Volumes[t]=np.absolute(c.astype(np.float))
210 RemovedEdges=np.array([])
211 for i
in range(int(len(Edges))):
212 X1=abs(Nodes[int(Edges[i][0])-1][0]);Y1=abs(Nodes[int(Edges[i][0])-1][1]);Z1=abs(Nodes[int(Edges[i][0])-1][2])
213 X2=abs(Nodes[int(Edges[i][1])-1][0]);Y2=abs(Nodes[int(Edges[i][1])-1][1]);Z2=abs(Nodes[int(Edges[i][1])-1][2])
214 if ((X1==0
or X1==RVElength)
and X2==X1)
or ((Y1==0
or Y1==RVElength)
and Y2==Y1)
or ((Z1==0
or Z1==RVElength)
and Z2==Z1):
215 RemovedEdges=np.append(RemovedEdges,i+1)
216 RemovedFaces=np.array([])
217 RemainedEdges=np.array([])
218 for i
in range(int(len(Faces))):
220 for j
in range(int(len(Faces[i]))):
221 if abs(Faces[i][j])
in RemovedEdges:
222 FaceInsideCube=1+FaceInsideCube
223 if FaceInsideCube==len(Faces[i]):
224 RemovedFaces=np.append(RemovedFaces,int(i+1))
225 if FaceInsideCube!=len(Faces[i]):
226 for j
in range(int(len(Faces[i]))):
227 RemainedEdges=np.append(RemainedEdges,abs(Faces[i][j]))
229 myfile13=os.path.join(mypath,
'PeriodicRVE.geo')
230 text_GEO = open(myfile13,
"w")
231 text_GEO.write(
'{0}{1}{2}\n'.format(
'cl=',MeshSize,
';'))
232 for i
in range(int(len(Nodes))):
233 lines[i] = lines[i].replace(
'};',
',cl};')
234 text_GEO.write(
'{0}'.format(lines[i]))
235 for i
in range(int(len(Edges))):
236 if i+1
in RemainedEdges:
237 text_GEO.write(
'{0}{1}{2}{3}{4}{5}{6}\n'.format(
'Line (',int(i+1),
') = {',int(Edges[i][0]),
',',int(Edges[i][1]),
'};'))
238 for i
in range(int(len(Faces))):
239 if i+1
not in RemovedFaces:
240 text_GEO.write(
'{0}{1}{2}'.format(
'Line Loop (',int(i+1),
') = {'))
241 for j
in range(int(len(Faces[i]))):
242 text_GEO.write(
'{0}'.format(int(Faces[i][j])))
243 if j+1!=len(Faces[i]):
244 text_GEO.write(
'{0}'.format(
','))
245 text_GEO.write(
'{0}\n'.format(
'};'))
246 text_GEO.write(
'{0}{1}{2}{3}{4}{5}{6}{7}{8}\n'.format(
'Plane Surface (',int(i+1),
') = {',int(i+1),
'}; Physical Surface (',int(i+1),
') = {',int(i+1),
'};'))
249 for i
in range(0,int(len(SurfacesArea))):
250 if i+1
not in RemovedFaces:
251 c=np.array(SurfacesArea[i])
252 TotalArea=TotalArea+(np.absolute(c.astype(np.float)))
254 commandMeshing=
"gmsh PeriodicRVE.geo -2 -optimize_lloyd -o PeriodicRVE -format inp -saveall" 255 os.system(commandMeshing)
257 time.sleep(4);files = os.listdir(
'.')
258 if (
'PeriodicRVE.inp' in files):
259 SuccessInMeshing=0;
break 260 os.remove(
'PeriodicRVE.geo')
262 NoOfBeamPerEdge=np.array([])
263 INPgeom = open(
'PeriodicRVE.inp',
'r') lines = INPgeom.readlines() 265 os.remove('PeriodicRVE.inp')
266 text_inp = open(
'CorrectedINPafterGMSH.inp',
"w")
267 text_inp.write(
'{0}'.format(lines[2]))
269 while lines[i][0]!=
'*':
270 text_inp.write(
'{0}'.format(lines[i]))
273 text_inp.write(
'{0}\n'.format(
'*ELEMENT, TYPE=B31, ELSET=auto1'))
274 RemainedEdges1=np.array([])
279 if lines[i][15]!=
'C':
280 s=np.array(lines[i][31:int(len(lines[i])-1)])
281 q=np.absolute(s.astype(np.float))
283 if q
in RemovedEdges:
285 if lines[i][15]==
'C':
287 if 30>len(lines[i])
and M!=1:
288 RemainedEdges1=np.append(RemainedEdges1,int(q))
289 text_inp.write(
'{0}'.format(lines[i]))
292 NoOfBeamPerEdge=itemfreq(RemainedEdges1)
293 RemainedEdges1=np.unique(RemainedEdges1)
294 text_inp.write(
'{0}\n'.format(
'*ELEMENT, TYPE=S3R, ELSET=auto1'))
297 if ((lines[i][0]!=
'*')
and (lines[i][3]!=
'S')):
298 text_inp.write(
'{0}'.format(lines[i]))
302 text_inp.write(
'{0}'.format(
'*******'))
303 text_inp.close();time.sleep(10)
304 myfile12=os.path.join(mypath,
'CorrectedINPafterGMSH.inp')
305 INPgeom = open(myfile12,
"r") 306 lines = INPgeom.readlines() 308 os.remove('CorrectedINPafterGMSH.inp')
313 b = lines[i].split(
",")
315 Node=np.absolute(c.astype(np.float))
316 Nodes=np.append(Nodes,Node)
323 b = lines[i].split(
",")
325 Beam=np.absolute(c.astype(np.float))
326 Beams=np.append(Beams,Beam)
333 b = lines[i].split(
",")
335 Shell=np.absolute(c.astype(np.float))
336 Shells=np.append(Shells,Shell)
339 NodeNums=np.array([])
341 for i
in range(int(len(Shells)/4)):
342 NodeNums=np.append(NodeNums,int(Shells[k]))
343 NodeNums=np.append(NodeNums,int(Shells[k+1]))
344 NodeNums=np.append(NodeNums,int(Shells[k+2]))
346 BeamLengths=np.array([])
348 for i
in range(int(len(Beams)/3)):
349 x1=Nodes[1+int(4*(Beams[k]-1))];y1=Nodes[2+int(4*(Beams[k]-1))];z1=Nodes[3+int(4*(Beams[k]-1))]
350 x2=Nodes[1+int(4*(Beams[k+1]-1))];y2=Nodes[2+int(4*(Beams[k+1]-1))];z2=Nodes[3+int(4*(Beams[k+1]-1))]
351 BeamLengths=np.append(BeamLengths,((((x1-x2)**2)+((y1-y2)**2)+((z1-z2)**2))**0.5))
353 RemainedNodesNum=np.unique(NodeNums)
354 RemainedNodesBoundary=np.array([])
355 for k
in range(int(len(RemainedNodesNum))):
356 if abs(Nodes[1+(4*(RemainedNodesNum[k]-1))])==RVElength
or abs(Nodes[1+(4*(RemainedNodesNum[k]-1))])==0
or abs(Nodes[2+(4*(RemainedNodesNum[k]-1))])==RVElength
or abs(Nodes[2+(4*(RemainedNodesNum[k]-1))])==0
or abs(Nodes[3+(4*(RemainedNodesNum[k]-1))])==RVElength
or abs(Nodes[3+(4*(RemainedNodesNum[k]-1))])==0:
357 RemainedNodesBoundary=np.append(RemainedNodesBoundary,int(RemainedNodesNum[k]))
358 RemainedNodesBoundary=np.append(RemainedNodesBoundary,Nodes[1+(4*(RemainedNodesNum[k]-1))])
359 RemainedNodesBoundary=np.append(RemainedNodesBoundary,Nodes[2+(4*(RemainedNodesNum[k]-1))])
360 RemainedNodesBoundary=np.append(RemainedNodesBoundary,Nodes[3+(4*(RemainedNodesNum[k]-1))])
362 NodePairsXY=np.array([])
365 for i
in range(int(len(RemainedNodesBoundary)/4)):
366 for j
in range(i,int(len(RemainedNodesBoundary)/4)):
367 if RemainedNodesBoundary[m]!=RemainedNodesBoundary[n]
and int(A*RemainedNodesBoundary[m+1])==int(A*RemainedNodesBoundary[n+1])
and int(A*RemainedNodesBoundary[m+2])==int(A*RemainedNodesBoundary[n+2])
and (abs(RemainedNodesBoundary[m+3]-RemainedNodesBoundary[n+3])>0.98*RVElength):
368 NodePairsXY=np.append(NodePairsXY,RemainedNodesBoundary[m])
369 NodePairsXY=np.append(NodePairsXY,RemainedNodesBoundary[n])
373 NodePairsXZ=np.array([])
376 for i
in range(int(len(RemainedNodesBoundary)/4)):
377 for j
in range(i,int(len(RemainedNodesBoundary)/4)):
378 if RemainedNodesBoundary[m]!=RemainedNodesBoundary[n]
and int(A*RemainedNodesBoundary[m+1])==int(A*RemainedNodesBoundary[n+1])
and int(A*RemainedNodesBoundary[m+3])==int(A*RemainedNodesBoundary[n+3])
and (abs(RemainedNodesBoundary[m+2]-RemainedNodesBoundary[n+2])>0.98*RVElength):
379 NodePairsXZ=np.append(NodePairsXZ,RemainedNodesBoundary[m])
380 NodePairsXZ=np.append(NodePairsXZ,RemainedNodesBoundary[n])
384 NodePairsYZ=np.array([])
387 for i
in range(int(len(RemainedNodesBoundary)/4)):
388 for j
in range(i,int(len(RemainedNodesBoundary)/4)):
389 if RemainedNodesBoundary[m]!=RemainedNodesBoundary[n]
and int(A*RemainedNodesBoundary[m+2])==int(A*RemainedNodesBoundary[n+2])
and int(A*RemainedNodesBoundary[m+3])==int(A*RemainedNodesBoundary[n+3])
and (abs(RemainedNodesBoundary[m+1]-RemainedNodesBoundary[n+1])>0.98*RVElength):
390 NodePairsYZ=np.append(NodePairsYZ,RemainedNodesBoundary[m])
391 NodePairsYZ=np.append(NodePairsYZ,RemainedNodesBoundary[n])
395 NodeCordinates=np.array([])
396 for i
in range(int(len(RemainedNodesNum))):
397 K=4*(RemainedNodesNum[i]-1)
398 NodeCordinates=np.append(NodeCordinates,Nodes[K+1])
399 NodeCordinates=np.append(NodeCordinates,Nodes[K+2])
400 NodeCordinates=np.append(NodeCordinates,Nodes[K+3])
401 UpLevelOfRVE=1+int(max(NodeCordinates))
402 DistCenter=np.array([]);DistX=np.array([]);DistY=np.array([]);DistZ=np.array([])
403 NodeNums1=np.array([])
404 for i
in range(int(len(RemainedNodesNum))):
405 K=4*(RemainedNodesNum[i]-1)
406 NodeNums1=np.append(NodeNums1,Nodes[K])
407 DistCenter=np.append(DistCenter,(Nodes[K+1]**2)+(Nodes[K+2]**2)+(Nodes[K+3]**2))
408 DistX=np.append(DistX,((Nodes[K+1]-UpLevelOfRVE)**2)+((Nodes[K+2])**2)+((Nodes[K+3])**2))
409 DistY=np.append(DistY,((Nodes[K+1])**2)+((Nodes[K+2]-UpLevelOfRVE)**2)+((Nodes[K+3])**2))
410 DistZ=np.append(DistZ,((Nodes[K+1])**2)+((Nodes[K+2])**2)+((Nodes[K+3]-UpLevelOfRVE)**2))
411 CornerNode=NodeNums1[DistCenter.argmin()]
412 CornerNodeX=NodeNums1[DistX.argmin()]
413 CornerNodeY=NodeNums1[DistY.argmin()]
414 CornerNodeZ=NodeNums1[DistZ.argmin()]
415 LenNodePairsXY=len(NodePairsXY);LenNodePairsXZ=len(NodePairsXZ);LenNodePairsYZ=len(NodePairsYZ)
418 for i
in range(int(LenNodePairsXY)):
419 for j
in range(int(LenNodePairsXZ/2)):
420 if NodePairsXY[K]==NodePairsXZ[L]
or NodePairsXY[K]==NodePairsXZ[L+1]:
421 NodePairsXZ[L]=123456;NodePairsXZ[L+1]=123456
427 for i
in range(int(LenNodePairsXY)):
428 for j
in range(int(LenNodePairsYZ/2)):
429 if NodePairsXY[K]==NodePairsYZ[L]
or NodePairsXY[K]==NodePairsYZ[L+1]:
430 NodePairsYZ[L]=123456;NodePairsYZ[L+1]=123456
436 for i
in range(int(LenNodePairsXZ)):
437 for j
in range(int(LenNodePairsYZ/2)):
438 if NodePairsXZ[K]==NodePairsYZ[L]
or NodePairsXZ[K]==NodePairsYZ[L+1]:
439 NodePairsYZ[L]=123456;NodePairsYZ[L+1]=123456
444 for i
in range(int(LenNodePairsXY/2)):
445 if CornerNode==NodePairsXY[L]
or CornerNodeX==NodePairsXY[L]
or CornerNodeY==NodePairsXY[L]
or CornerNodeZ==NodePairsXY[L]
or CornerNode==NodePairsXY[L+1]
or CornerNodeX==NodePairsXY[L+1]
or CornerNodeY==NodePairsXY[L+1]
or CornerNodeZ==NodePairsXY[L+1]:
446 NodePairsXY[L]=123456;NodePairsXY[L+1]=123456
449 for i
in range(int(LenNodePairsXZ/2)):
450 if CornerNode==NodePairsXZ[L]
or CornerNodeX==NodePairsXZ[L]
or CornerNodeY==NodePairsXZ[L]
or CornerNodeZ==NodePairsXZ[L]
or CornerNode==NodePairsXZ[L+1]
or CornerNodeX==NodePairsXZ[L+1]
or CornerNodeY==NodePairsXZ[L+1]
or CornerNodeZ==NodePairsXZ[L+1]:
451 NodePairsXZ[L]=123456;NodePairsXZ[L+1]=123456
454 for i
in range(int(LenNodePairsYZ/2)):
455 if CornerNode==NodePairsYZ[L]
or CornerNodeX==NodePairsYZ[L]
or CornerNodeY==NodePairsYZ[L]
or CornerNodeZ==NodePairsYZ[L]
or CornerNode==NodePairsYZ[L+1]
or CornerNodeX==NodePairsYZ[L+1]
or CornerNodeY==NodePairsYZ[L+1]
or CornerNodeZ==NodePairsYZ[L+1]:
456 NodePairsYZ[L]=123456;NodePairsYZ[L+1]=123456
459 RVEarea=RVElength*RVElength
460 Vfoam=RVEarea*Ylength
462 SolidPUmass=rho*Vfoam
463 VsolidPUinRVE=SolidPUmass/DensityOfSolidPU
464 PUinStruts=1-PUinWall
465 Vw=VsolidPUinRVE*PUinWall
466 Vs=VsolidPUinRVE*PUinStruts
468 for i
in range(int(len(RemainedEdges1))):
469 TotalLength=TotalLength+EdgeLengths[RemainedEdges1[i]-1]
470 VolumeRatioStrut=np.array([])
471 for i
in range(int(len(RemainedEdges1))):
472 VolumeRatioStrut=np.append(VolumeRatioStrut,EdgeLengths[RemainedEdges1[i]-1]/TotalLength)
473 myfile13=os.path.join(mypath,
'INP.inp')
474 text_inp = open(myfile13,
"w")
475 text_inp.write(
'{0}{1}\n'.format(
'****Mesh Size=',MeshSize))
476 text_inp.write(
'{0}{1}\n'.format(
'*include, input=',
'PBC.txt'))
477 for i
in range(0,len(lines)):
478 text_inp.write(
'{0}'.format(lines[i]))
482 for i
in range(int(len(Beams)/3)):
483 text_inp.write(
'{0},{1},{2}\n'.format(int(Beams[k]),int(Beams[k+1]),int(Beams[k+2])))
485 text_inp.write(
'*ELEMENT, TYPE=S3R, ELSET=auto1\n')
487 for i
in range(int(len(Shells)/4)):
488 text_inp.write(
'{0},{1},{2},{3}\n'.format(int(Shells[k]),int(Shells[k+1]),int(Shells[k+2]),int(Shells[k+3])))
491 TotalVolAssignedBeams=0
493 for i
in range(int(len(NoOfBeamPerEdge))):
494 NumElinEdge=NoOfBeamPerEdge[i][1]
497 DeltaX=1.0/NumElinEdge
498 for j
in range(int(NumElinEdge)):
499 area= quad(
lambda x: (A1*((x-0.5)**4))+(A2*((x-0.5)**3))+(A3*((x-0.5)**2))+(A4*((x-0.5)**1))+A5, K, K+DeltaX)
500 TotalAreaStrut=TotalAreaStrut+area[0]
503 for j
in range(int(NumElinEdge)):
504 text_inp.write(
'{0}{1}\n'.format(
'*Elset, elset=Beam',int(BeamElCounter-1)))
505 text_inp.write(
'{0}\n'.format(int(Beams[3*(BeamElCounter-1)])))
506 text_inp.write(
'{0}{1}{2}{3}{4}\n'.format(
'*Beam Section, elset=Beam',int(BeamElCounter-1),
',material = Material-1 ',
', temperature=GRADIENTS',
',section=TRAPEZOID'))
507 Vbeam=quad(
lambda x: (A1*((x-0.5)**4))+(A2*((x-0.5)**3))+(A3*((x-0.5)**2))+(A4*((x-0.5)**1))+A5, K, K+DeltaX)
508 Vbeam1=(Vbeam[0]/TotalAreaStrut)*(Vs*VolumeRatioStrut[i])
509 Area=Vbeam1/BeamLengths[BeamElCounter-1];c=0.000001;h=(Area*(3.0**0.5))**0.5;a=h*(2.0/(3.00**0.5));d=h/3.00
511 text_inp.write(
'{0:.10f}{1}{2:.10f}{3}{4:.10f}{5}{6:.10f}\n'.format(a,
', ',h,
', ',c,
', ',d))
512 text_inp.write(
'{0}\n'.format(
'0.,0.,-1'))
513 TotalVolAssignedBeams=TotalVolAssignedBeams+(Area*BeamLengths[BeamElCounter-1])
514 BeamElCounter=BeamElCounter+1
516 ShellThickness=Vw/TotalArea
519 tt=(int((len(Shells)/4)-t))/16
522 text_inp.write(
'{0}{1}\n'.format(
'*Elset, elset=EShell',int(0)))
523 for i
in range(int(tt)):
525 text_inp.write(
'{0}{1}'.format(int(Shells[N]),
','))
530 for j
in range(int(t)):
531 text_inp.write(
'{0}{1}'.format(int(Shells[N]),
','))
535 text_inp.write(
'{0}{1}{2}\n'.format(
'*Shell Section, elset=EShell',int(0),
', material=Material-1'))
536 text_inp.write(
'{0}{1}\n'.format(ShellThickness,
', 5'));text_inp.write(
'{0}\n'.format(
'*Material, name=Material-1'))
537 text_inp.write(
'{0}\n'.format(
'*Density'));text_inp.write(
'{0}\n'.format(DensityOfSolidPU))
538 text_inp.write(
'{0}\n'.format(
'*Elastic'));text_inp.write(
'{0}{1}{2}\n'.format(E,
', ',NU))
539 text_inp.write(
'{0}\n'.format(
'**'));text_inp.write(
'{0}{1}\n'.format(
'**RVEarea',RVEarea))
540 text_inp.write(
'{0}{1}\n'.format(
'**Ylength',Ylength))
541 text_inp.write(
'{0}\n'.format(
'** STEP: Step-1'));text_inp.write(
'{0}\n'.format(
'*Step, name=Step-1, nlgeom=YES, INC=1000'))
542 text_inp.write(
'{0}\n'.format(
'*Static, stabilize=0.001'));text_inp.write(
'{0}\n'.format(
'0.001, 1., 1e-09, 0.01'))
543 text_inp.write(
'{0}\n'.format(
'** BOUNDARY CONDITIONS'));text_inp.write(
'{0}\n'.format(
'*Nset, nset=Znodepairs'))
545 for j
in range(int(LenNodePairsXY/2)):
546 if NodePairsXY[L]!=123456
and NodePairsXY[L+1]!=123456:
547 text_inp.write(
'{0}{1}{2}{3}\n'.format(int(NodePairsXY[L]),
',',int(NodePairsXY[L+1]),
','))
549 text_inp.write(
'{0}\n'.format(
'*Nset, nset=Ynodepairs'))
551 for j
in range(int(LenNodePairsXZ/2)):
552 if NodePairsXZ[L]!=123456
and NodePairsXZ[L+1]!=123456:
553 text_inp.write(
'{0}{1}{2}{3}\n'.format(int(NodePairsXZ[L]),
',',int(NodePairsXZ[L+1]),
','))
555 text_inp.write(
'{0}\n'.format(
'*Nset, nset=Xnodepairs'))
557 for j
in range(int(LenNodePairsYZ/2)):
558 if NodePairsYZ[L]!=123456
and NodePairsYZ[L+1]!=123456:
559 text_inp.write(
'{0}{1}{2}{3}\n'.format(int(NodePairsYZ[L]),
',',int(NodePairsYZ[L+1]),
','))
561 text_inp.write(
'{0}\n{1}\n'.format(
'*Nset, nset=MN0',int(CornerNode)));text_inp.write(
'{0}\n{1}\n'.format(
'*Nset, nset=MNx',int(CornerNodeX)))
562 text_inp.write(
'{0}\n{1}\n'.format(
'*Nset, nset=MNy',int(CornerNodeY)));text_inp.write(
'{0}\n{1}\n'.format(
'*Nset, nset=MNz',int(CornerNodeZ)))
563 text_inp.write(
'{0}\n{1}\n{2}\n{3}\n{4}\n'.format(
'*Boundary',
'MN0, PINNED',
'*Boundary',
'MNx, 2, 2',
'MNx, 3, 3'))
564 text_inp.write(
'{0}\n{1}\n'.format(
'*Boundary',
'MNy, 1, 1'))
565 text_inp.write(
'{0}{1}\n'.format(
'MNy, 2, 2, ',Ylength*(AppliedStrain)))
566 text_inp.write(
'{0}\n{1}\n{2}\n{3}\n{4}\n'.format(
'MNy, 3, 3',
'*Boundary',
'MNz, 1, 1',
'MNz, 2, 2',
'** OUTPUT REQUESTS'))
567 text_inp.write(
'{0}\n{1}\n'.format(
'*Restart, write, frequency=0',
'** FIELD OUTPUT: F-Output-1'))
568 text_inp.write(
'{0}\n{1}\n'.format(
'*Output, field, variable=PRESELECT',
'** HISTORY OUTPUT: H-Output-1'))
569 text_inp.write(
'{0}\n{1}\n'.format(
'*Output, history, variable=PRESELECT',
'*End Step'))
571 myfile14=os.path.join(mypath,
'PBC.txt')
572 t=open(myfile14,
"w")
573 t.write(
'{0}\n'.format(
'*EQUATION'))
575 for j
in range(int(LenNodePairsXY/2)):
576 if NodePairsXY[L]!=123456
and NodePairsXY[L+1]!=123456:
578 t.write(
'{0}\n'.format(
'3'))
579 t.write(
'{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}\n'.format(
' ',int(NodePairsXY[L+1]),
',', k+1,
' ,1.00, ',int(NodePairsXY[L]),
', ',k+1,
' ,-1.00, ',int(CornerNodeZ),
',', k+1,
' ,-1.00'))
582 for j
in range(int(LenNodePairsXZ/2)):
583 if NodePairsXZ[L]!=123456
and NodePairsXZ[L+1]!=123456:
585 t.write(
'{0}\n'.format(
'3'))
586 t.write(
'{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}\n'.format(
' ',int(NodePairsXZ[L+1]),
',', k+1,
' ,1.00, ',int(NodePairsXZ[L]),
', ',k+1,
' ,-1.00, ',int(CornerNodeY),
',', k+1,
' ,-1.00'))
589 for j
in range(int(LenNodePairsYZ/2)):
590 if NodePairsYZ[L]!=123456
and NodePairsYZ[L+1]!=123456:
592 t.write(
'{0}\n'.format(
'3'))
593 t.write(
'{0}{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}\n'.format(
' ',int(NodePairsYZ[L+1]),
',', k+1,
' ,1.00, ',int(NodePairsYZ[L]),
', ',k+1,
' ,-1.00, ',int(CornerNodeX),
',', k+1,
' ,-1.00'))
601 files = os.listdir(
'.')
602 if (
'INP.inp' in files)
and (
'PBC.txt' in files):
604 CMDforABAQUS=
'cd {0} && {1} job=INP cpus={2}'.format(mypath,AbaqusVersion,NumOfCores)
605 os.system(CMDforABAQUS)
608 files = os.listdir(
'.')
609 if (
'INP.lck' not in files)
and (
'INP.odb' in files):
612 myfile14=os.path.join(mypath,
'AbaqusPythonInpRF2U2.py')
613 q=open(myfile14,
"w")
614 q.write(
'{0}\n{1}\n{2}\n{3}\n'.format(
'from abaqus import *',
'from abaqusConstants import *',
'from viewerModules import *',
'from driverUtils import executeOnCaeStartup'))
615 q.write(
'{0}\n{1}\n{2}\n'.format(
'executeOnCaeStartup()',
'o2 = session.openOdb(',
" name='INP.odb')"))
616 q.write(
'{0}\n'.format(
"session.viewports['Viewport: 1'].setValues(displayedObject=o2)"))
617 q.write(
'{0}\n'.format(
"session.viewports['Viewport: 1'].odbDisplay.display.setValues(plotState=("))
618 q.write(
'{0}\n'.format(
" CONTOURS_ON_DEF, ))"))
619 q.write(
'{0}{1}{2}\n'.format(
"odb = session.odbs['",mypath,
"INP.odb']"))
620 q.write(
'{0}\n'.format(
"session.xyDataListFromField(odb=odb, outputPosition=NODAL, variable=(('RF',"))
621 q.write(
'{0}\n'.format(
" NODAL, ((COMPONENT, 'RF2'), )), ('U', NODAL, ((COMPONENT, 'U2'), )), ),")) q.write(
'{0}{1}{2}\n'.format(
" nodeLabels=(('PART-1-1', ('",int(CornerNodeY),
"', )), ))"))
622 q.write(
'{0}{1}{2}\n'.format(
"x0 = session.xyDataObjects['RF:RF2 PI: PART-1-1 N: ",int(CornerNodeY),
"']" ))
623 q.write(
'{0}{1}{2}\n'.format(
"x1 = session.xyDataObjects['U:U2 PI: PART-1-1 N: ",int(CornerNodeY),
"']"))
624 q.write(
'{0}\n'.format(
"session.xyReportOptions.setValues()"))
625 q.write(
'{0}\n'.format(
"session.writeXYReport(fileName='XYdataRF2U2.rpt', xyData=(x0, x1))"))
630 os.system(
'cd {0} && {1} cae noGUI=AbaqusPythonInpRF2U2.py'.format(mypath,AbaqusVersion))
633 files = os.listdir(
'.')
634 if (
'XYdataRF2U2.rpt' in files):
636 myfile14=os.path.join(mypath,
'XYdataRF2U2.rpt')
637 text_file = open(myfile14,
"r") lines = text_file.readlines() 638 os.remove('INP.com');os.remove(
'INP.dat');os.remove(
'INP.inp');os.remove(
'INP.log');os.remove(
'INP.msg');os.remove(
'INP.prt')
639 os.remove(
'INP.sim');os.remove(
'INP.sta');os.remove(
'INP.odb');os.remove(
'XYdataRF2U2.rpt');os.remove(
'PBC.txt');os.remove(
'AbaqusPythonInpRF2U2.py')
645 currentline = lines[t].split(
" ")
646 if len(currentline)==1
and currentline[0]==
'\n':
648 for i
in range(len(currentline)):
649 if currentline[i]!=
'' and x!=3
and currentline[i]!=
'\n':
650 r=float(currentline[i])
651 XYdata=np.append(XYdata,r)
657 for i
in range(int(len(XYdata)/3)):
658 Xdata=np.append(Xdata,XYdata[t+1])
659 Ydata=np.append(Ydata,XYdata[t+2])
662 Xdata=Xdata/(RVEarea*1000000)
663 [ElasticModulusOfRVE,i] = np.polyfit(Ydata, Xdata, 1)
664 print(
'ElasticModulusOfFoam=')
665 print(ElasticModulusOfRVE)
666 return ElasticModulusOfRVE
669 assert os.path.isfile(INPUT_FILE),
"Did not find file '%s'" %(INPUT_FILE)
670 print "Post processing..." 671 Outputfile=os.path.join(WORKING_DIR,OUTPUT_FILE)
672 Output=open(Outputfile,
'w')
673 Input= np.loadtxt(INPUT_FILE,dtype=float,delimiter=
",",comments=
'#',skiprows=0)
674 myfile14=os.path.join(WORKING_DIR,INPUT_FILE)
675 text_file_Inp = open(myfile14,
"r") 676 if len(text_file_Inp.readlines())<2:
677 text_file_Inp.close()
678 MU,SIGMA,strut_content,rho=Input[0],Input[1],Input[2],Input[3]
680 Output.write(
'{0:f}\n'.format(EModulus))
682 for No
in range(int(len(Input))):
683 MU,SIGMA,strut_content,rho=Input[No][0],Input[No][1],Input[No][2],Input[No][3]
685 Output.write(
'{0:f}\n'.format(EModulus))