How to export domain from paraview to ANSYS or any meshing software?

Nastran format is also supported in ICEM CFD, and you can easily export all of the domain in a Nastran file by using a Programmable Filter. Would you take a look at the attached state file for more details.toNastran.zip (41.7 KB)


output_file = 'your_path/output.nas'

input = self.GetInput()

f = open(output_file, 'w')
f.write('{:80}\n'.format('$ Generated by ToNastran program'))
f.write('{:80}\n'.format('$ Nastran input deck'))
f.write('{:80}\n'.format('SOL 103'))
f.write('{:80}\n'.format('CEND'))
f.write('{:80}\n'.format('$'))
f.write('{:80}\n'.format('BEGIN BULK'))
f.write('{:80}\n'.format('$'))
f.write('{:80}\n'.format('$       grid data              0'))

print('number of points in input is ' + str(input.GetNumberOfPoints()))
for i in range(input.GetNumberOfPoints()):
    point = input.GetPoint(i)
    id = i + 1
    f.write('GRID*{:>19}{:>16} {:<15f}{:<16f}*{:>7}\n'.format(id,0,point[0],point[1],id))
    f.write('*{:>7}{:>12f}{:>20}{:>32}{:8}\n'.format(id,point[2],0,0,''))

materialName = 'BlockIdScalars'
materialArray = input.GetCellData().GetArray(materialName)
print(materialArray)

mats = {}
for i in range(input.GetNumberOfCells()):
    material = int(materialArray.GetTuple1(i))
    mats.setdefault(material, []).append(i)

id = 0
for mat in mats:
    f.write('{:80}\n'.format('$       Volume element data for family'))
    f.write('{:6}{:10}{:64}\n'.format('PSOLID',mat,'       0       0       0'))

    for i in mats[mat]:
        id += 1
        cell = input.GetCell(i)
        cellType = cell.GetCellType()
        pntIds = cell.GetPointIds()

        if cellType == vtk.VTK_TETRA:
            f.write('{:6}{:>10}{:>8}{:>8}{:>8}{:>8}{:>8}{:24}\n'.format('CTETRA',id,mat,pntIds.GetId(0)+1,pntIds.GetId(1)+1,pntIds.GetId(2)+1,pntIds.GetId(3)+1,''))
        elif cellType == vtk.VTK_HEXAHEDRON:
            f.write('{:6}{:>10}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:8}\n'.format('CHEXA',id,mat,pntIds.GetId(0)+1,pntIds.GetId(1)+1,pntIds.GetId(2)+1,pntIds.GetId(3)+1,pntIds.GetId(4)+1,pntIds.GetId(5)+1,''))
            f.write('{:6}{:>10}{:>8}{:56}\n'.format('',pntIds.GetId(6)+1,pntIds.GetId(7)+1,''))
        elif cellType == vtk.VTK_WEDGE:
            f.write('{:6}{:>10}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:8}\n'.format('CPENTA',id,mat,pntIds.GetId(0)+1,pntIds.GetId(1)+1,pntIds.GetId(2)+1,pntIds.GetId(3)+1,pntIds.GetId(4)+1,pntIds.GetId(5)+1,''))
        elif cellType == vtk.VTK_PYRAMID:
#            f.write('{:6}{:>10}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:8}\n'.format('CHEXA',id,mat,pntIds.GetId(0)+1,pntIds.GetId(1)+1,pntIds.GetId(2)+1,pntIds.GetId(3)+1,pntIds.GetId(4)+1,pntIds.GetId(4)+1,''))
#            f.write('{:6}{:>10}{:>8}{:56}\n'.format('',pntIds.GetId(4)+1,pntIds.GetId(4)+1,''))
            f.write('{:6}{:>10}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:>8}{:8}\n'.format('CPENTA',id,mat,pntIds.GetId(0)+1,pntIds.GetId(3)+1,pntIds.GetId(4)+1,pntIds.GetId(1)+1,pntIds.GetId(2)+1,pntIds.GetId(4)+1,''))

f.write('{:80}\n'.format('$  Geometry defaults data'))
f.write('{:80}\n'.format('$  Material Properties'))
f.write('{:80}\n'.format('$  Analysis type data'))
f.write('{:80}\n'.format('$  Load defaults data'))
f.write('{:80}\n'.format('$  Coordinate systems'))
f.write('{:80}\n'.format('ENDDATA'))

f.close()
1 Like