# Export Mesh as Nastran to use in ICEM CFD

**URL:** https://discourse.paraview.org/t/export-mesh-as-nastran-to-use-in-icem-cfd/10546
**Category:** ParaView Support
**Created:** [October 18, 2022, 10:38pm UTC](https://discourse.paraview.org/t/export-mesh-as-nastran-to-use-in-icem-cfd/10546 "2022-10-18T22:38:23Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![dstansberry](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dstansberry](https://discourse.paraview.org/u/dstansberry)
#### Post date: [October 18, 2022, 10:38pm UTC](https://discourse.paraview.org/t/export-mesh-as-nastran-to-use-in-icem-cfd/10546/1 "2022-10-18T22:38:23Z")

</div>

Hello all,

I am very new to Paraview and am trying to export a mesh created with openfoam as a Nastran file to be used in ICEM CFD for a project at school. After some searching I found a post that had a python script written that could be used in the Programmable filter section. This is the infomraiton of the mesh I am trying to export:

 ![Screenshot 2022-10-18 173501](https://discourse.paraview.org/uploads/default/original/2X/7/79a83a88561805e40b4e517e54ba048565f19bd7.png)  
It looked like the person was trying to do exactly what I am but I did not get it to work. When I tried running the script I got an error.  
 ![Screenshot 2022-10-18 173126](https://discourse.paraview.org/uploads/default/original/2X/6/67a2fe3f5706a2b33355fd3a00ed1b260e41e6f7.png)  
This the code I tried running:

output\_file = ‘H:\ME5143 CFD\Final\_proj/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()

Can anyone tell me what needs to be changed to get this to work?
