CFD General Notation System (CGNS)
Usage for Structured Grids

Bruce Wedan
ANSYS/ICEM CFD

Presentation Overview

Example

Figure showing a cylindrical grid zone abutting a cubical grid zone

Example - Initialization Code

         include 'cgnslib_f.h'

         mach = 0.5
         alpha = 0
         re = 0
         time = 0

   C---- zone 1 - cube
         do n=1,3
           idim1(n,1) = 5
           idim1(n,2) = 4
           idim1(n,3) = 0
         enddo
         do i=1,5
           do j=1,5
             do k=1,5
               r1(i,j,k,1) = i - 3
               r1(i,j,k,2) = j - 3
               r1(i,j,k,3) = k - 5
               do n=1,5
                 q1(i,j,k,n) = n
               enddo
             enddo
           enddo
         enddo

   C---- zone 2 - cylinder
         do n=1,3
           idim2(n,1) = 5
           idim2(n,2) = 4
           idim2(n,3) = 0
         enddo
         idim2(2,1) = 10
         idim2(2,2) = 9
         do i=1,5
           do j=1,10
             do k=1,5
               rad = i - 1
               ang = 0.6981317*(j - 1)
               r2(i,j,k,1) = rad * cos(ang)
               r2(i,j,k,2) = rad * sin(ang)
               r2(i,j,k,3) = k - 1
               do n=1,5
                 q2(i,j,k,n) = n
               enddo
             enddo
           enddo
         enddo

Example - PLOT3D Code

   c---- write PLOT3D xyz file

         iunit = 11
         open(iunit,file='example.xyz',form='unformatted')
         write(iunit) 2
         write(iunit) (idim1(i,1),i=1,3),(idim2(i,1),i=1,3)
         write(iunit) ((((r1(i,j,k,n),i=1,5),j=1,5),k=1,5),n=1,3)
         write(iunit) ((((r2(i,j,k,n),i=1,5),j=1,10),k=1,5),n=1,3)
         close(iunit)

   c---- write PLOT3D q file

         open(iunit,file='example.q',form='unformatted')
         write(iunit) 2
         write(iunit) (idim1(i,1),i=1,3),(idim2(i,1),i=1,3)
         write(iunit) mach,alpha,re,time
         write(iunit) ((((q1(i,j,k,n),i=1,5),j=1,5),k=1,5),n=1,5)
         write(iunit) ((((q2(i,j,k,n),i=1,5),j=1,10),k=1,5),n=1,5)
         close(iunit)

Example - CGNS Code

   c---- open file and create base
         call cg_open_f('example.cgns',MODE_WRITE,ifile,ierr)
         if (ierr .ne. CG_OK) call cg_error_exit_f

         call cg_base_write_f(ifile,'Example',3,3,ibase,ierr)

   c---- zone 1 - cube

         call cg_zone_write_f(ifile,ibase,'Cube',idim1,Structured,izone,ierr)

         call cg_coord_write_f(ifile,ibase,izone,RealSingle,'CoordinateX',r1(1,1,1,1),
        &                      icoord,ierr)
         call cg_coord_write_f(ifile,ibase,izone,RealSingle,'CoordinateY',r1(1,1,1,2),
        &                      icoord,ierr)
         call cg_coord_write_f(ifile,ibase,izone,RealSingle,'CoordinateZ',r1(1,1,1,3),
        &                      icoord,ierr)
ADFviewer window showing grid coordinates node
         call cg_sol_write_f(ifile,ibase,izone,'Cube Solution',Vertex,isol,ierr)
         
         call cg_field_write_f(ifile,ibase,izone,isol,RealSingle,'Density',
        &                      q1(1,1,1,1),ifld,ierr)
         call cg_field_write_f(ifile,ibase,izone,isol,RealSingle,'MomentumX',
        &                      q1(1,1,1,2),ifld,ierr)
         call cg_field_write_f(ifile,ibase,izone,isol,RealSingle,'MomentumY',
        &                      q1(1,1,1,3),ifld,ierr)
         call cg_field_write_f(ifile,ibase,izone,isol,RealSingle,'MomentumZ',
        &                      q1(1,1,1,4),ifld,ierr)
         call cg_field_write_f(ifile,ibase,izone,isol,RealSingle,'EnergyStagnationDensity',
        &                      q1(1,1,1,5),ifld,ierr)
ADFviewer window showing flow solution node
   c---- zone 2 - cylinder

         call cg_zone_write_f(ifile,ibase,'Cylinder',idim2,Structured,izone,ierr)
         do n=1,3
           call cg_coord_write_f(ifile,ibase,izone,RealSingle,cnames(n),r2(1,1,1,n),
        &                        icoord,ierr)
         enddo
         call cg_sol_write_f(ifile,ibase,izone,'Cylinder Solution',Vertex,isol,ierr)
         do n=1,5
           call cg_field_write_f(ifile,ibase,izone,isol,RealSingle,snames(n),q2(1,1,1,n),
        &                        ifld,ierr)
         enddo

   c---- close file

         call cg_close_f(ifile,ierr)
ADFviewer window showing all nodes

What Do We Have?

But I Want Separate Files

ADFviewer window showing link node

Timings and File Size


Mesh Size   100×100×100   200×200×200   400×400×400
File Size   30.5 MB 244 MB 1.90 GB

PLOT3D 2.32 (3.62) secs 16.0 (45.8) secs 126 (216) secs
CGNS (1 file) (+6K bytes) 2.48 (0.63) secs 17.2 (7.9) secs 129 (40) secs
CGNS (2 files) (+14K bytes) 2.34 (0.67) secs 17.4 (8.1) secs 164 (41) secs

Enhancing the Data

Documentation

ADFviewer window showing DataClass node
ADFviewer window showing reference state node
ADFviewer window showing governing equations node

Coordinate Systems

ADFviewer window showing grid coordinates node

Connectivity

ADFviewer window showing 'Periodic' node under ZoneGridConnectivity
ADFviewer window showing 'Cube -> Cylinder' node under ZoneGridConnectivity

Boundary Conditions

ADFviewer window showing 'Inlet' node under ZoneBC
ADFviewer window showing 'Inflow Conditions' node under 'Inlet' node
ADFviewer window showing 'Walls' node under ZoneBC
ADFviewer window showing 'Axis' node under ZoneBC

Solution Data

ADFviewer window showing 'Cylinder Solution' node

Solutions

ADFviewer window showing 'Cylinder Solution' node with rind points

What Else Can You Do?