# Outputting calculation grids¶

Outputs the calculation grid to the CGNS file.

Unlike ordinary solvers that simply read calculation grids from the CGNS file, these subroutines are to be used in a particular kind of solver in which a grid is created on the solver side or a three-dimensional grid is generated from a two-dimensional grid.

Grid creating program always uses these subroutines.

The subroutines here should be used when a solver output the grid in the initial state. When you want to output the grid shape modified after starting calculation, use the subroutines described in Outputting calculation grids (only in the case of a moving grid).

Subroutine |
Remarks |
---|---|

cg_iric_write_grid1d_coords |
Outputs a one-dimensional structured grid |

cg_iric_write_grid2d_coords |
Outputs a two-dimensional structured grid |

cg_iric_write_grid3d_coords |
Outputs a three-dimensional structured grid |

cg_iric_write_grid_real_node |
Outputs a grid node attribute with real number value |

cg_iric_write_grid_integer_node |
Outputs a grid node attribute with integer value |

cg_iric_write_grid_real_cell |
Outputs a grid cell attribute with real number value |

cg_iric_write_grid_integer_cell |
Outputs a grid cell attribute with integer value |

List 99 shows an example of the procedure of reading a two-dimensional grid, dividing it to generate a three-dimensional grid, and then outputting the resulting grid.

```
1program Sample7
2 use iric
3 implicit none
4
5 integer:: fin, ier, isize, jsize, ksize, i, j, k, aret
6 double precision:: time
7 double precision:: convergence
8 double precision, dimension(:,:), allocatable::grid_x, grid_y, elevation
9 double precision, dimension(:,:,:), allocatable::grid3d_x, grid3d_y, grid3d_z
10 double precision, dimension(:,:,:), allocatable:: velocity, density
11
12 ! Open CGNS file.
13 call cg_iric_open('test3d.cgn', IRIC_MODE_MODIFY, fin, ier)
14 if (ier /=0) STOP "*** Open error of CGNS file ***"
15
16 ! Check the grid size.
17 call cg_iric_read_grid2d_str_size(fin, isize, jsize, ier)
18 ! Allocate memory for loading the grid.
19 allocate(grid_x(isize,jsize), grid_y(isize,jsize), elevation(isize,jsize))
20 ! Read the grid into memory.
21 call cg_iric_read_grid2d_coords(fin, grid_x, grid_y, ier)
22 call cg_iric_read_grid_real_node(fin, 'Elevation', elevation, ier)
23
24 ! Generate a 3D grid from the 2D grid that has been read in.
25 ! To obtain a 3D grid, the grid is divided into 5 in z direction.
26
27 ksize = 6
28 allocate(grid3d_x(isize,jsize,ksize), grid3d_y(isize,jsize,ksize), grid3d_z(isize,jsize,ksize))
29 allocate(velocity(isize,jsize,ksize), STAT = aret)
30 print *, aret
31 allocate(density(isize,jsize,ksize), STAT = aret)
32 print *, aret
33 do i = 1, isize
34 do j = 1, jsize
35 do k = 1, ksize
36 grid3d_x(i,j,k) = grid_x(i,j)
37 grid3d_y(i,j,k) = grid_y(i,j)
38 grid3d_z(i,j,k) = elevation(i,j) + (k - 1)
39 velocity(i,j,k) = 0
40 density(i,j,k) = 0
41 end do
42 end do
43 end do
44 ! Output the generated 3D grid
45 call cg_iric_write_grid3d_coords(fin, isize, jsize, ksize, grid3d_x, grid3d_y, grid3d_z, ier)
46
47 ! Output the initial state information
48 time = 0
49 convergence = 0.1
50 call cg_iric_write_sol_start(fin, ier)
51 call cg_iric_write_sol_time(fin, time, ier)
52 ! Output the grid.
53 call cg_iric_write_sol_grid3d_coords(fin, grid3d_x, grid3d_y, grid3d_z, ier)
54 ! Output calculation results.
55 call cg_iric_write_sol_node_real(fin, 'Velocity', velocity, ier)
56 call cg_iric_write_sol_node_real(fin, 'Density', density, ier)
57 call cg_iric_write_sol_baseiterative_real(fin, 'Convergence', convergence, ier)
58 call cg_iric_write_sol_end(fin, ier)
59
60 do
61 time = time + 10.0
62 ! (Perform calculation here. The grid shape also changes.)
63 call cg_iric_write_sol_start(fin, ier)
64 call cg_iric_write_sol_time(fin, time, ier)
65 ! Output the grid.
66 call cg_iric_write_sol_grid3d_coords(fin, grid3d_x, grid3d_y, grid3d_z, ier)
67 ! Output calculation results.
68 call cg_iric_write_sol_node_real(fin, 'Velocity', velocity, ier)
69 call cg_iric_write_sol_node_real(fin, 'Density', density, ier)
70 call cg_iric_write_sol_baseiterative_real(fin, 'Convergence', convergence, ier)
71 call cg_iric_write_sol_end(fin, ier)
72
73 If (time > 100) exit
74 end do
75
76 ! Close CGNS file.
77 call cg_iric_close(fin, ier)
78 stop
79end program Sample7
```