Skip to content

iriclib interface change with iRIC v4

Keisuke Inoue edited this page Jun 21, 2021 · 5 revisions

iriclib interface change with iRIC v4

With iRIC v4, new version of iriclib is released, for improvements and cleaning the APIs.

This page explains how iriclib will be changed.

Changing internal structure

iriclib used to use cgnslib, but now it does not use cgnslib, but uses HDF5 library directly.

Because of this change, iriclib can open CGNS files much faster, and it is more stable.

Add function to output multiple grids

New iRIClib has function to output calculation results for multiple grids.

Functions for outputting multiple grids has "_withgridid" suffix.

Ex. Outputting calculation results for both 2D and 3D grid

gridid_2d = 1  ! gridid for 2D grid is 1.

! output 3D grid. gridid_3d is a return value, and it is the grid ID for 3D grid.
call cg_iric_write_grid3d_coords_withgridid(fid, isize, jsize, ksize, x, y, z, gridid_3d, ier)

do while (t < tmax)
  (calculation)

  call cg_iric_write_sol_node_real_withgridid(fid, gridid_2d, 'Depth', depth, ier) ! output 2D result
  call cg_iric_write_sol_node_real_withgridid(fid, gridid_3d, 'Concentration', concentration, ier) ! output 3D result
end do

Add functions to read unstructured grid

call cg_iric_read_grid_nodecount(fid, node_count, ier)
call cg_iric_read_grid_cellcount(fid, cell_count, ier)
(allocate memory here)
call cg_iric_read_grid2d_coords(fid, x, y, ier)
call cg_iric_read_grid_triangleelements(fid, nodeids, ier) ! nodeids stores the IDs of nodes that consists triangles.

Creating iric.f90

New iriclib contains iric.f90, that defines iriclib interfaces for FORTRAN 90.

Some part of iric.f90 is shown below:

module iric
  implicit none

  integer, parameter:: IRIC_MODE_READ = 0
  integer, parameter:: IRIC_MODE_WRITE = 1
  integer, parameter:: IRIC_MODE_MODIFY = 2

  ...

  subroutine cg_iric_read_integer(fid, name, value, ier)
    integer, intent(in):: fid
    character(*), intent(in):: name
    integer, intent(out):: value
    integer, intent(out):: ier

    call cg_iric_read_integer_f2c &
      (fid, name, value, ier)

  end subroutine

  ...

end module

You can use it for the following purposes:

  • Read it to check iriclib subroutine interface for FORTRAN
  • Build solver with iric.f90. Compiler will show errors if the arguments are invalid, so it will be easier to find bugs.

How to change solver source code

  • Remove "include 'cgnslib_f.h'" and "include 'iriclib_f.h".
  • Add "use iric" where iriclib functions are used.
  • Remove "_f". New iriclib functions for FORTRAN 90 do not have suffix "_f" so that the names are the same to those for C/C++ and Python.

Example is shown below:

subroutine write_cgns()
  use iric

  call cg_iric_write_sol_time(fid, time, ier)
  call cg_iric_write_sol_baseiterative_real(fid, "Discharge(m3s-1)", disch, ier)
end subroutine

How to build solver

  1. Compile iric.f90
  2. Compile your source code
  3. Build solver, by linking *.obj and iriclib.lib.

For example:

ifort iric.f90 /MD /c
ifort source.f90 /MD /c
ifort *.obj libs\iriclib.lib -o solver.exe

Cleaning interface

Interfaces of iriclib functions are changed so that they become more clean and consistent.

Add fid to all cg_iric_XXXX functions

Before:

call cg_iric_read_integer_f('mode', mode, ier)

After:

call cg_iric_read_integer(fid, 'mode', mode, ier)

Because of this change, cg_iRIC_XXXX_Mul() are removed.

Functions for opening and closing CGNS files

Currently, subroutines provided by cgnslib (cg_open and cg_close) are used to open and close CGNS files. Now new iriclib provides its own subroutines for opening and closing CGNS files, so please use them instead.

New constants IRIC_MODE_MODIFY, and IRIC_MODE_READ are defined to be used with cg_iric_open.

Before:

call cg_open(filename, CG_MODE_MODIFY, fid, ier)

...

call cg_close(fid, ier)

After:

call cg_iric_open(filename, IRIC_MODE_MODIFY, fid, ier)

...

call cg_iric_close(fid, ier)

Changing cg_iric_flush interface

Before:

call cg_iric_flush_f(cgnsName, fid, ier)

After:

call cg_iric_flush(fid, ier)

Changing function names

Names of functions are changed, so that the names are more consistent with the other functions.

Before After
cg_iRIC_GotoGridCoord2d cg_iRIC_Read_Grid2d_Str_Size
cg_iRIC_GetGridCoord2d cg_iRIC_Read_Grid2d_Coords
cg_iRIC_WriteGridCoord1d cg_iRIC_Write_Grid1d_Coords
cg_iRIC_WriteGridCoord2d cg_iRIC_Write_Grid2d_Coords
cg_iRIC_WriteGridCoord3d cg_iRIC_Write_Grid3d_Coords
cg_iRIC_Read_Sol_GridCoord2d cg_iRIC_Read_Sol_Grid2d_Coords
cg_iRIC_Read_Sol_GridCoord3d cg_iRIC_Read_Sol_Grid3d_Coords
cg_iRIC_Write_Sol_GridCoord2d cg_iRIC_Write_Sol_Grid2d_Coords
cg_iRIC_Write_Sol_GridCoord3d cg_iRIC_Write_Sol_Grid3d_Coords
cg_iRIC_Read_Sol_Integer cg_iRIC_Read_Sol_Node_Integer
cg_iRIC_Read_Sol_Real cg_iRIC_Read_Sol_Node_Real
cg_iRIC_Write_Sol_Integer cg_iRIC_Write_Sol_Node_Integer
cg_iRIC_Write_Sol_Real cg_iRIC_Write_Sol_Node_Real

Remove deprecated functions

The functions below are deprecated and removed. Please remove the lines to call the deprecated functions.

  • cg_iRIC_Init
  • cg_iRIC_InitRead
  • cg_iRIC_GotoBase
  • cg_iRIC_GotoCC
  • cg_iRIC_GoToRawDataTop
  • iRIC_Write_Sol_Start
  • iRIC_Write_Sol_End
  • iRIC_Check_Lock

Merging iricsolverlib to iriclib

There was an unofficial library named "iricsolverlib", that provides misc functions for handling grids. Now iricsolverlib is merged to iriclib, and the API interface is changed so that they are more consistent with other iriclib functions.

The main functions are as below:

  • cg_iRIC_Read_Grid2d_CellArea: Calculate area of cell
  • cg_iRIC_Read_Grid2d_Interpolate: Find grid cell that contains the point, and calculate weights for interpolation

Example is shown below.

call cg_iRIC_Open(fname, IRIC_MODE_MODIFY, fid, ier)

! load grid and get grid_handle
call cg_iRIC_Read_Grid2d_Open(fid, grid_handle, ier)
! calculate cell area
call cg_iRIC_Read_Grid2d_CellArea(grid_handle, cellid, area, ier)
! find grid cell that contains the point, and calculate weights for interpolation
call cg_iRIC_Read_Grid2d_Interpolate(grid_handle, x, y, ok, count, nodeids, weights, ier)
! close grid
call cg_iRIC_Read_Grid2d_Close(grid_handle, ier)

call cg_iRIC_Close(fid, ier)