Abaqus vs Paraview

Petit script python pour transformer un fichier *.inp Abaqus en fichier *.vtk, pour Paraview (évidemment, ce n'est pas complet)


import os
from os import chdir
currentName = 'nomDuCae'
chdir("/MonChemin")
obFichier = open(currentName+'.inp','r')
myLines = obFichier.readlines()
myNodes = []
isNode = False
myElts  = []
isElt = False
myElset = []
myElsetName = []
mySolidSectionName = []
cellColor=[]
curentColor = 0
isElset = False
isOrientation = False
isSolidSection = False
isInstance = False
isGenerated = False
for currentLine in myLines: # je parcoure le fichier
  myString=currentLine.split()
  currentString = myString[0]
  if (currentString[0] != '*'):
    if (isNode == True and isInstance == True):
      myNodes.append((myString[1].rstrip(','),myString[2].rstrip(','),myString[3].rstrip(',')))
    if (isElt == True and isInstance == True):
      myElts.append((myString[1].rstrip(','),myString[2].rstrip(','),myString[3].rstrip(','),myString[4].rstrip(','),myString[5].rstrip(','),myString[6].rstrip(','),))      
      cellColor.append(0)
    if (isElset == True and isInstance == True):
      tmp=[]
      if (isGenerated):
        i = int(myString[0].rstrip(','))
        while i <= int(myString[1].rstrip(',')):
          tmp.append(i)
          i = i + int(myString[2])
        myElset.append(tmp)
    if (isSolidSection == True and isInstance == True):
      for i in range(0, len(myElsetName)): # recherche de l'elset concerne
        if (myElsetName[i] == mySolidSectionName[-1]):
          # ecriture dans le fichier de sortie
          curentColor += 2
          if (curentColor == 114):
            print myElsetName[i]
          for j in range(0,len(myElset[i])):
            cellColor[myElset[i][j]-1] = curentColor
  if (currentString[0] == '*'):
    currentKw = currentString.lstrip('*') # nouveau mot clef
    currentKw = currentKw.rstrip(',')
    if (currentKw=='Node' and len(myString)==1):
      isNode = True
      isElt = False
      isElset = False
      isOrientation = False
      isSolidSection = False
      isGenerated = False
    elif (currentKw=='Element' and len(myString)==2):
      isNode = False
      isElt = True
      isElset = False
      isOrientation = False
      isSolidSection = False
      isGenerated = False
    elif (currentKw=='Elset'):
      isNode = False
      isElt = False
      isElset = True
      isOrientation = False
      isSolidSection = False
      isGenerated = False
      if (len(myString) == 4 and myString[3] == 'generate'):
        isGenerated = True
      myElsetName.append(myString[1].lstrip('elset='))
    elif (currentKw=='Orientation'):
      isNode = False
      isElt = False
      isElset = False
      isOrientation = True
      isSolidSection = False
      isGenerated = False
    elif (currentKw=='Solid' and myString[1].rstrip(',') == 'Section'):
      isNode = False
      isElt = False
      isElset = False
      isOrientation = False
      isSolidSection = True
      isGenerated = False
      if (myString[3][0:11]=='orientation'):
        mySolidSectionName.append(myString[2].lstrip('elset='))
    elif (currentKw=='Instance' and isInstance == False):
      isNode = False
      isElt = False
      isElset = False
      isOrientation = False
      isSolidSection = False
      isInstance = True
      isGenerated = False
    elif (currentKw=='Instance' and isInstance == True):
      isNode = False
      isElt = False
      isElset = False
      isOrientation = False
      isSolidSection = False
      isInstance = False
      isGenerated = False
    else:
      isNode = False
      isElt = False
      isElset = False
      isOrientation = False
      isSolidSection = False
      isGenerated = False

obFichier.close()

outFichier = open(currentName+'.vtk','w')
outFichier.writelines('# vtk DataFile Version 2.0 (1) \n')
outFichier.writelines('Unstructured Grid Example \n')
outFichier.writelines('ASCII \n')
outFichier.writelines('DATASET UNSTRUCTURED_GRID \n')
outFichier.writelines('POINTS '+str(len(myNodes))+' float \n')

for i in range(0,len(myNodes)):
  outFichier.writelines(str(myNodes[i][0])+' '+str(myNodes[i][1])+' '+str(myNodes[i][2]+ ' \n'))

currentElemNumber = len(myElts)

outFichier.writelines('CELLS '+str(currentElemNumber)+' '+str(7*currentElemNumber)+' \n')

for i in range(0,currentElemNumber):
  outFichier.writelines('6 ' + str(int(myElts[i][0])-1)+' '+str(int(myElts[i][1])-1)+' '+str(int(myElts[i][2])-1)+' '+str(int(myElts[i][3])-1)+' '+str(int(myElts[i][4])-1)+' '+str(int(myElts[i][5])-1)+ ' \n')

outFichier.writelines('CELL_TYPES '+str(currentElemNumber)+' \n')
for i in range(0,currentElemNumber):
  outFichier.writelines(str(13)+ ' \n')

outFichier.writelines('CELL_DATA '+str(currentElemNumber)+' \n')
outFichier.writelines('SCALARS cell_scalars int 1'+' \n')
outFichier.writelines('LOOKUP_TABLE default'+' \n')

for i in range(0,len(myElts)):
  outFichier.writelines(str(cellColor[i])+ ' \n')

outFichier.close()

Écrire un commentaire

Quelle est la quatrième lettre du mot wkqdd ? :