MoDeNa  1.0
Software framework facilitating sequential multi-scale modelling
AbaqusSimulation.py
1 #!/usr/bin/python
2 
26 
27 __author__='IMDEA Materials-Mohammad Marvi Mashhadi: mohammad.marvi@imdea.org, mohamadmarvi@gmail.com'
28 
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
33 # ------------------------ Convinience variables ---------------------------- #
34 INPUT_FILE = "Inputs.in" # Name of the input file
35 OUTPUT_FILE = "Outputs.in" # Name of the output file
36 WORKING_DIR = os.getcwd() # Directory in which the script is being executed
37 OS = sys.platform # Platform executing the script
38 USER = os.getenv("USER") # Name of the user executing the script
39 TIMESTAMP = str(datetime.datetime.now()).split('.')[0] # Time stamp
40 # --------------------------- FoamElasticModulus ------------------------------ #
41 def FoamElasticModulus(MU,SIGMA,strut_content,rho):
42  # Main Inputs:
43  AbaqusVersion='abq6101' #ABAQUS version
44  NumOfCores='20' #Number of processors available in the machine(At least 1)
45 
47  E='2.4e9' #Elastic modulus of Solid Polyurethan (Pa)
48  G='0.9e9' #Shear modulus of Solid Polyurethan (Pa)
49  NU='0.35' #Poisson ratio of Solid Polyurethan
50  NumOfCells=40 #Number of cells in RVE (Representative Volume Element)
51  MeshSize=0.1 #Size of mesh used to mesh the geometry
52  AppliedStrain=-0.001 #Compressive strain
53  DensityOfSolidPU=1200 #Real density of Solid Polyurethan (kg/m3)
54  PUinWall=1-strut_content#Amount of material in walls (in percentage %)
55  CubeLength=1 #Primary length of RVE (mm)
56 
58  A1,A2,A3,A4,A5=2.77,0.962,3.4033,-0.2291,1.0255
59 
61  mypath=WORKING_DIR+'/'
62  os.chdir(mypath)
63  ExtraVolumeRatio=0.50
64  SuccessInMeshing=1
65  while SuccessInMeshing==1:
66  SuccessInTessellation=1
67  while SuccessInTessellation==1:
68  myfile=os.path.join(mypath,'Project01.prj')
69  f=open(myfile,'w')
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'))
79  f.close()
80  os.system('./spherepack')
81  while True:
82  time.sleep(1);files = os.listdir('.')
83  if ('Project01.rco' in files):
84  break
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')
117  ff=open(myfile3,'w')
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]))
120  ff.close()
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))
125  fff.close()
126  time.sleep(3)
127  NumOfCells1=int(len(CentersRads3)/4)
128  RVElength=CubeLength+(ExtraVolumeRatio*CubeLength)
129  #commandTessellation="neper -T -n {0:d} -domain 'cube({1},{1},{1})' -morpho @{2}Centers.txt -weight @{2}Rads.txt -regularization 1 -mloop 1 -o {2}RVE27 -format geo -statcell vol -statedge length -statface area -statver x".format((NumOfCells1),RVElength,mypath)
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)
132  time.sleep(5)
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')
138 
139  myfile12=os.path.join(mypath,'RVE27.stver')
140  verX=np.loadtxt(myfile12)
141  NumOfNodes=len(verX)
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()
157  text_file.close()
158  os.remove('RVE27.geo')
159  os.remove('RVE27.stcell');os.remove('RVE27.stedge');os.remove('RVE27.stface');os.remove('RVE27.stver')
160  t=0
161  Nodes=range(NumOfNodes)
162  for i in range(0,NumOfNodes):
163  currentline = lines[i].split("{")
164  a=currentline[1].split("}")
165  b=a[0].split(",")
166  c=np.array(b)
167  Nodes[t]=np.absolute(c.astype(np.float))
168  t=t+1
169  Edges=range(NumOfEdges)
170  r=0
171  t=0
172  for i in range(NumOfNodes,NumOfNodes+NumOfEdges):
173  currentline = lines[i].split("{")
174  a=currentline[1].split("}")
175  b=a[0].split(",")
176  c=np.array(b)
177  Edges[t]=np.absolute(c.astype(np.float))
178  t=t+1
179  Faces=range(NumOfSurfaces)
180  r=0
181  t=0
182  for i in range(0,NumOfSurfaces):
183  j=NumOfNodes+NumOfEdges+(2*i)
184  currentline = lines[j].split("{")
185  a=currentline[1].split("}")
186  b=a[0].split(",")
187  c=np.array(b)
188  Faces[t]=(c.astype(np.float))
189  t=t+1
190  Volumes=range(NumOfVolumes)
191  a=list(lines[NumOfNodes+NumOfEdges+(2*NumOfSurfaces)])
192  a[0:20]=''
193  o=len(a)
194  a[o-3:]=''
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))
199  t=1
200  for i in range(1,2*NumOfVolumes):
201  if i%2==0:
202  j=NumOfNodes+NumOfEdges+(2*NumOfSurfaces)+i
203  currentline = lines[j].split(" = {")
204  a=currentline[1].split("}")
205  b=a[0].split(",")
206  c=np.array(b)
207  Volumes[t]=np.absolute(c.astype(np.float))
208  t=t+1
209 
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))):
219  FaceInsideCube=0
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]))
228 
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),'};'))
247  text_GEO.close()
248  TotalArea=0
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)))
253  time.sleep(5)
254  commandMeshing="gmsh PeriodicRVE.geo -2 -optimize_lloyd -o PeriodicRVE -format inp -saveall"
255  os.system(commandMeshing)
256  while True:
257  time.sleep(4);files = os.listdir('.')
258  if ('PeriodicRVE.inp' in files):
259  SuccessInMeshing=0;break
260  os.remove('PeriodicRVE.geo')
261  # Creating Corrected INP To Be processed In Next Step
262  NoOfBeamPerEdge=np.array([])
263  INPgeom = open('PeriodicRVE.inp', 'r') lines = INPgeom.readlines()
264  INPgeom.close()
265  os.remove('PeriodicRVE.inp')
266  text_inp = open('CorrectedINPafterGMSH.inp', "w")
267  text_inp.write('{0}'.format(lines[2]))
268  i=3
269  while lines[i][0]!='*':
270  text_inp.write('{0}'.format(lines[i]))
271  i=i+1
272  i=i+1
273  text_inp.write('{0}\n'.format('*ELEMENT, TYPE=B31, ELSET=auto1'))
274  RemainedEdges1=np.array([])
275  K=0
276  N=0
277  while K==0:
278  if len(lines[i])>30:
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))
282  M=0
283  if q in RemovedEdges:
284  M=1
285  if lines[i][15]=='C':
286  K=1
287  if 30>len(lines[i]) and M!=1:
288  RemainedEdges1=np.append(RemainedEdges1,int(q))
289  text_inp.write('{0}'.format(lines[i]))
290  N=N+1
291  i=i+1
292  NoOfBeamPerEdge=itemfreq(RemainedEdges1)
293  RemainedEdges1=np.unique(RemainedEdges1)
294  text_inp.write('{0}\n'.format('*ELEMENT, TYPE=S3R, ELSET=auto1'))
295  K=0
296  while K==0:
297  if ((lines[i][0]!='*') and (lines[i][3]!='S')):
298  text_inp.write('{0}'.format(lines[i]))
299  if lines[i][3]=='S':
300  K=1
301  i=i+1
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()
307  INPgeom.close()
308  os.remove('CorrectedINPafterGMSH.inp')
309  i=1
310  r=lines[1][0]
311  Nodes=np.array([])
312  while r!='*':
313  b = lines[i].split(",")
314  c=np.array(b)
315  Node=np.absolute(c.astype(np.float))
316  Nodes=np.append(Nodes,Node)
317  i=i+1
318  r=lines[i][0]
319  i=i+1
320  r=lines[i][0]
321  Beams=np.array([])
322  while r!='*':
323  b = lines[i].split(",")
324  c=np.array(b)
325  Beam=np.absolute(c.astype(np.float))
326  Beams=np.append(Beams,Beam)
327  i=i+1
328  r=lines[i][0]
329  i=i+1
330  r=lines[i][0]
331  Shells=np.array([])
332  while r!='*':
333  b = lines[i].split(",")
334  c=np.array(b)
335  Shell=np.absolute(c.astype(np.float))
336  Shells=np.append(Shells,Shell)
337  i=i+1
338  r=lines[i][0]
339  NodeNums=np.array([])
340  k=1
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]))
345  k=k+4
346  BeamLengths=np.array([])
347  k=1
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))
352  k=k+3
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))])
361  A=10000
362  NodePairsXY=np.array([])
363  m=0
364  n=0
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])
370  n=n+4
371  m=m+4
372  n=m
373  NodePairsXZ=np.array([])
374  m=0
375  n=0
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):# and (RemainedNodes[m+1]<1.3 or RemainedNodes[m+1]>1.7) and (RemainedNodes[m+3]<1.3 or RemainedNodes[m+3]>1.7):
379  NodePairsXZ=np.append(NodePairsXZ,RemainedNodesBoundary[m])
380  NodePairsXZ=np.append(NodePairsXZ,RemainedNodesBoundary[n])
381  n=n+4
382  m=m+4
383  n=m
384  NodePairsYZ=np.array([])
385  m=0
386  n=0
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):# and (RemainedNodes[m+3]<1.0 or RemainedNodes[m+3]>1.2) and (RemainedNodes[m+2]<1.3 or RemainedNodes[m+2]>1.7):
390  NodePairsYZ=np.append(NodePairsYZ,RemainedNodesBoundary[m])
391  NodePairsYZ=np.append(NodePairsYZ,RemainedNodesBoundary[n])
392  n=n+4
393  m=m+4
394  n=m
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)
416  K=0
417  L=0
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
422  L=L+2
423  L=0
424  K=K+1
425  K=0
426  L=0
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
431  L=L+2
432  L=0
433  K=K+1
434  K=0
435  L=0
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
440  L=L+2
441  L=0
442  K=K+1
443  L=0
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
447  L=L+2
448  L=0
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
452  L=L+2
453  L=0
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
457  L=L+2
458  Ylength=RVElength
459  RVEarea=RVElength*RVElength
460  Vfoam=RVEarea*Ylength
461  #How material distributed between walls and struts (Vw , Vs) :
462  SolidPUmass=rho*Vfoam #rho is the real density of the foam (kg/m3)
463  VsolidPUinRVE=SolidPUmass/DensityOfSolidPU
464  PUinStruts=1-PUinWall
465  Vw=VsolidPUinRVE*PUinWall #Volume of solid PU in walls
466  Vs=VsolidPUinRVE*PUinStruts #Volume of solid PU in Struts
467  TotalLength=0
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]))
479  if lines[i][1]=='E':
480  break
481  k=0
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])))
484  k=k+3
485  text_inp.write('*ELEMENT, TYPE=S3R, ELSET=auto1\n')
486  k=0
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])))
489  k=k+4
490  #Section assignment for Beam Elements
491  TotalVolAssignedBeams=0
492  BeamElCounter=1
493  for i in range(int(len(NoOfBeamPerEdge))):
494  NumElinEdge=NoOfBeamPerEdge[i][1]
495  TotalAreaStrut=0
496  K=0
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]
501  K=K+DeltaX
502  K=0.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
510  K=K+DeltaX
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
515  #Calculation of shell thickness:
516  ShellThickness=Vw/TotalArea
517  #Section assignment for shell elements:
518  t=(len(Shells)/4)%16
519  tt=(int((len(Shells)/4)-t))/16
520  N=0
521  M=1
522  text_inp.write('{0}{1}\n'.format('*Elset, elset=EShell',int(0)))
523  for i in range(int(tt)):
524  for j in range(16):
525  text_inp.write('{0}{1}'.format(int(Shells[N]),','))
526  N=N+4
527  M=M+1
528  text_inp.write('\n')
529  if t>0:
530  for j in range(int(t)):
531  text_inp.write('{0}{1}'.format(int(Shells[N]),','))
532  N=N+4
533  if t>0:
534  text_inp.write('\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'))
544  L=0
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]),','))
548  L=L+2
549  text_inp.write('{0}\n'.format('*Nset, nset=Ynodepairs'))
550  L=0
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]),','))
554  L=L+2
555  text_inp.write('{0}\n'.format('*Nset, nset=Xnodepairs'))
556  L=0
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]),','))
560  L=L+2
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'))
570  text_inp.close()
571  myfile14=os.path.join(mypath,'PBC.txt')
572  t=open(myfile14, "w")
573  t.write('{0}\n'.format('*EQUATION'))
574  L=0
575  for j in range(int(LenNodePairsXY/2)):
576  if NodePairsXY[L]!=123456 and NodePairsXY[L+1]!=123456:
577  for k in range(6):
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'))
580  L=L+2
581  L=0
582  for j in range(int(LenNodePairsXZ/2)):
583  if NodePairsXZ[L]!=123456 and NodePairsXZ[L+1]!=123456:
584  for k in range(6):
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'))
587  L=L+2
588  L=0
589  for j in range(int(LenNodePairsYZ/2)):
590  if NodePairsYZ[L]!=123456 and NodePairsYZ[L+1]!=123456:
591  for k in range(6):
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'))
594  L=L+2
595  t.close()
596 
599  while True:
600  time.sleep(1)
601  files = os.listdir('.')
602  if ('INP.inp' in files) and ('PBC.txt' in files):
603  break
604  CMDforABAQUS='cd {0} && {1} job=INP cpus={2}'.format(mypath,AbaqusVersion,NumOfCores)
605  os.system(CMDforABAQUS)
606  while True:
607  time.sleep(1)
608  files = os.listdir('.')
609  if ('INP.lck' not in files) and ('INP.odb' in files):
610  break
611  #Creation of RF2 and U2 report file:
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))"))
626  q.close()
627 
630  os.system('cd {0} && {1} cae noGUI=AbaqusPythonInpRF2U2.py'.format(mypath,AbaqusVersion)) #Executing .py to get the XY data from ODB
631  while True:
632  time.sleep(1)
633  files = os.listdir('.')
634  if ('XYdataRF2U2.rpt' in files):
635  break
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')
640  XYdata=np.array([])
641  b=1
642  t=4
643  while b==1:
644  x=0
645  currentline = lines[t].split(" ")
646  if len(currentline)==1 and currentline[0]=='\n':
647  b=2
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)
652  x=x+1
653  t=t+1
654  Xdata=np.array([])
655  Ydata=np.array([])
656  t=0
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])
660  t=t+3
661  Ydata=Ydata/Ylength
662  Xdata=Xdata/(RVEarea*1000000)
663  [ElasticModulusOfRVE,i] = np.polyfit(Ydata, Xdata, 1)
664  print('ElasticModulusOfFoam=')
665  print(ElasticModulusOfRVE)
666  return ElasticModulusOfRVE
667 
668 # ------------------ Read input file && Printing E based on INPUTS------------------ #
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]
679  EModulus=FoamElasticModulus(MU,SIGMA,strut_content,rho)
680  Output.write('{0:f}\n'.format(EModulus))
681 else:
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]
684  EModulus=FoamElasticModulus(MU,SIGMA,strut_content,rho)
685  Output.write('{0:f}\n'.format(EModulus))
686 Output.close()
687 
Python Module.
Definition: __init__.py:1