import numpy, vtk # set output type dropdown to vtkUnstructuredGrid output=self.GetUnstructuredGridOutput() #give an error of "object has no attribute of CellData" #print output.CellData #print output.CellData.append ringle_out_file='belt34.e_s001_Tcon70.neut.out' # basename is everything before the 2nd period in the std Ringle name # this way any ringle file can be used basename=('.').join(ringle_out_file.split('.')[:2]) neut_name=basename+".neut.out" #print neut_name neut=open(neut_name,'r') # skip 4 header lines for i in range(4): skip=neut.readline() # maybe open .e11 simultaneously and get block from that newPts=vtk.vtkPoints() # dictionary #Nodes use funny Kelliher numbers in file and element definitions #Numbered 1-numNodes here - need to map from funny node #s to these Node_map={} R_Ring=vtk.vtkIntArray() R_Ring.SetName("R_Ring") R_Ring.SetNumberOfComponents(1) nNode=0 nElem=0 # read Neutral file, create Points, count elems (for Allocate) while True: line=neut.readline() line=line.split() if (line[0]=='1'): #node Node_map[line[1]]=nNode #print 'Node ',line[1] line2=neut.readline() # coords line2=line2.split() x=float(line2[0]) y=float(line2[1]) z=float(line2[2]) newPts.InsertNextPoint(0.0,x,y) skip=neut.readline() nNode=nNode+1 # all nodes read when you get here # count elements first time through if (line[0]=='2'): #element line2=neut.readline() line3=neut.readline() nElem=nElem+1 # last line has 99 as marker if (line[0]=='99'): break numNodes=nNode numElems=nElem #print numElems R_Ring.SetNumberOfTuples(numElems) # Allocate once you know numElems output.Allocate(numElems,1) # return to top of file # re-read neutral file to define elements neut.seek(0) # skip 4 header lines for i in range(4): skip=neut.readline() #skip points, create elements elem_count=0 while True: line=neut.readline() line=line.split() if (line[0]=='1'): #node skip=neut.readline() skip=neut.readline() if (line[0]=='2'): #element # track RINGLE ring# for use plotting local_stress_strain #print 'Element',line[1] R_Ring.SetValue(elem_count,int(line[1])) elem_count+=1 eltype=line[2] line2=neut.readline() line2=line2.split() #print "numElemNodes",line2[0] numElemNodes=int(line2[0]) ptIds=vtk.vtkIdList() line3=neut.readline() line3=line3.split() for ptId in range(numElemNodes): # look up our node # for phony Kelliher node #s #print line3[ptId] #print "Node map",Node_map[line3[ptId]] ptIds.InsertId(ptId,int(Node_map[line3[ptId]])) #vtk 9=quad 5=triangle 3=line output.InsertNextCell(9,ptIds) # last line has 99 as marker if (line[0]=='99'): break #print "finished reading neutral file" neut.close() output.SetPoints(newPts) output.GetCellData().AddArray(R_Ring) #read .els file to get number of variables els_file=basename+'.els' els=open(els_file,'r') skip=els.readline() skip=els.readline() skip=skip.split() #print "numElemVars",skip[0] numElemVars=int(skip[0]) skip=els.readline() skip=els.readline() # read els template file to get names of variables e_template=basename+'_els.res_tmpl' e_tmpl=open(e_template,'r') for i in range(4): skip=e_tmpl.readline() ElemVarNames = [] var=0 while var < numElemVars: line1=e_tmpl.readline() line1=line1.split() line2=e_tmpl.readline() line3=e_tmpl.readline() line3=line3.split() Name=line3[2] Name=Name.split(".") Name=Name[1] line4=e_tmpl.readline() #print line1[2] if (line1[2]=='scalar'): ElemVarNames.append(Name) if (line1[2]=='tensor'): ElemVarNames.append(Name.replace("ij","11",1)) var += 1 ElemVarNames.append(Name.replace("ij","22",1)) var += 1 ElemVarNames.append(Name.replace("ij","33",1)) var += 1 ElemVarNames.append(Name.replace("ij","12",1)) var += 1 ElemVarNames.append(Name.replace("ij","23",1)) var += 1 ElemVarNames.append(Name.replace("ij","13",1)) # tensors have extra line for CTYPE skip=e_tmpl.readline() # skip blank line between records skip=e_tmpl.readline() var +=1 #print ElemVarNames e_tmpl.close() ElemVars=numpy.zeros( (numElemVars,numElems) ) # 6 vars per (complete) line numFullLineVars = 6 numFullLines=numElemVars/numFullLineVars numPartialLineVars=numElemVars % numFullLineVars #print "numPartialLineVars ",numPartialLineVars partialLine=False if numPartialLineVars > 0: partialLine=True #print "partialLine ", partialLine for elem in range(numElems): # skip element header skip=els.readline() var_index=0 line_count=0 for line_count in range(numFullLines): line=els.readline() #print line for value in range(numFullLineVars): # Old school Fortran77 column data #print line[value*13:value*13+13] ElemVars[var_index,elem]=float(line[value*13:value*13+13]) var_index += 1 if partialLine: line=els.readline() for value in range(numPartialLineVars): ElemVars[var_index,elem]=float(line[value*13:value*13+13]) var_index += 1 buffer=vtk.vtkFloatArray() buffer.SetNumberOfComponents(1) buffer.SetNumberOfTuples(numElems) # for variable in range(numElemVars): # buffer.Initialize() #buffer.SetNumberOfComponents(1) #buffer.SetNumberOfTuples(numElems) #buffer.SetName(ElemVarNames[variable]) #for elem in range(numElems): # buffer.SetValue(elem,ElemVars[0,elem]) #output.CellData.append(buffer) els.close()