Adding codes to load calculation conditions, calculation grids, and boundary conditions

Adds codes to load calculation conditions, calculation girds, and boundary conditions.

iRIC will output calculation conditions, grids, grid attributes, and boundary condition according to the solver definition file that you've created in Creating a solver definition file. So, the solver has to load them to coincide with the description in the solver definition file.

List 8 shows the source code with lines to load calculation condition, grid and boundary condition. The added lines are shown with highlight.

List 8 The source code with lines to load calculation condition, grid and boundary condition
  1program SampleProgram
  2  use iric
  3  implicit none
  4  integer:: fin, ier
  5  integer:: icount, istatus
  6  character(200)::condFile
  7  integer:: maxiterations
  8  double precision:: timestep
  9  integer:: surfacetype
 10  double precision:: constantsurface
 11  integer:: variable_surface_size
 12  double precision, dimension(:), allocatable:: variable_surface_time
 13  double precision, dimension(:), allocatable:: variable_surface_elevation
 14
 15  integer:: isize, jsize
 16  double precision, dimension(:,:), allocatable:: grid_x, grid_y
 17  double precision, dimension(:,:), allocatable:: elevation
 18  integer, dimension(:,:), allocatable:: obstacle
 19
 20  integer:: inflowid
 21  integer:: inflow_count
 22  integer:: inflow_element_max
 23  integer:: discharge_variable_sizemax
 24  integer, dimension(:), allocatable:: inflow_element_count
 25  integer, dimension(:,:,:), allocatable:: inflow_element
 26  integer, dimension(:), allocatable:: discharge_type
 27  double precision, dimension(:), allocatable:: discharge_constant
 28  integer, dimension(:), allocatable:: discharge_variable_size
 29  double precision, dimension(:,:), allocatable:: discharge_variable_time
 30  double precision, dimension(:,:), allocatable:: discharge_variable_value
 31
 32  write(*,*) "Sample Program"
 33
 34  ! (abbr)
 35
 36  ! Loads calculation condition
 37  call cg_iric_read_integer(fin, "maxIteretions", maxiterations, ier)
 38  call cg_iric_read_real(fin, "timeStep", timestep, ier)
 39  call cg_iric_read_integer(fin, "surfaceType", surfacetype, ier)
 40  call cg_iric_read_real(fin, "constantSurface", constantsurface, ier)
 41
 42  call cg_iric_read_functionalsize(fin, "variableSurface", variable_surface_size, ier)
 43  allocate(variable_surface_time(variable_surface_size))
 44  allocate(variable_surface_elevation(variable_surface_size))
 45  call cg_iric_read_functional(fin, "variableSurface", variable_surface_time, variable_surface_elevation, ier)
 46
 47  ! Check the grid size
 48  call cg_iric_read_grid2d_str_size(fin, isize, jsize, ier)
 49
 50  ! Allocate the memory to read grid coordinates
 51  allocate(grid_x(isize,jsize), grid_y(isize,jsize))
 52  ! Loads grid coordinates
 53  call cg_iric_read_grid2d_coords(fin, grid_x, grid_y, ier)
 54
 55  ! Allocate the memory to load grid attributes defined at grid nodes and grid cells
 56  allocate(elevation(isize, jsize))
 57  allocate(obstacle(isize - 1, jsize - 1))
 58
 59  ! Loads grid attributes
 60  call cg_iric_read_grid_real_node(fin, "Elevation", elevation, ier)
 61  call cg_iric_read_grid_integer_cell(fin, "Obstacle", obstacle, ier)
 62
 63  ! Allocate memory to load boundary conditions (inflow)
 64  allocate(inflow_element_count(inflow_count))
 65  allocate(discharge_type(inflow_count), discharge_constant(inflow_count))
 66  allocate(discharge_variable_size(inflow_count))
 67
 68  ! Check the number of grid nodes assigned as inflow, and the size of time-dependent discharge.
 69  inflow_element_max = 0
 70  do inflowid = 1, inflow_count
 71    ! Read the number of grid nodes assigned as inflow
 72    call cg_iric_read_bc_indicessize(fin, 'inflow', inflowid, inflow_element_count(inflowid))
 73    if (inflow_element_max < inflow_element_count(inflowid)) then
 74      inflow_element_max = inflow_element_count(inflowid)
 75    end if
 76    ! Read the size of time-dependent discharge
 77    call cg_iric_read_bc_functionalsize(fin, 'inflow', inflowid, 'FunctionalDischarge', discharge_variable_size(inflowid), ier);
 78    if (discharge_variable_sizemax < discharge_variable_size(inflowid)) then
 79      discharge_variable_sizemax = discharge_variable_size(inflowid)
 80    end if
 81  end do
 82
 83  ! Allocate the memory to load grid nodes assigned as inflow, and time-dependent discharge.
 84  allocate(inflow_element(inflow_count, 2, inflow_element_max))
 85  allocate(discharge_variable_time(inflow_count, discharge_variable_sizemax))
 86  allocate(discharge_variable_value(inflow_count, discharge_variable_sizemax))
 87
 88  ! Loads boundary condition
 89  do inflowid = 1, inflow_count
 90    ! Loads the grid nodes assigned as inflow
 91    call cg_iric_read_bc_indices(fin, 'inflow', inflowid, inflow_element(inflowid:inflowid,:,:), ier)
 92    ! Loads the inflow type (0 = constant, 1 = time-dependent)
 93    call cg_iric_read_bc_integer(fin, 'inflow', inflowid, 'Type', discharge_type(inflowid:inflowid), ier)
 94    ! Loads the discharge (constant)
 95    call cg_iric_read_bc_real(fin, 'inflow', inflowid, 'ConstantDischarge', discharge_constant(inflowid:inflowid), ier)
 96    ! Loads the discharge (time-dependent)
 97    call cg_iric_read_bc_functional(fin, 'inflow', inflowid, 'FunctionalDischarge', discharge_variable_time(inflowid:inflowid,:), discharge_variable_value(inflowid:inflowid,:), ier)
 98  end do
 99
100  ! Closes the calculation data file
101  call cg_iric_close(fin, ier)
102  stop
103end program SampleProgram

Note that the arguments passed to load calculation conditions, grid attributes and boundary conditions are the same to the [name] attributes of Items defined in Defining calculation conditions, Defining Grid attributes.

Refer to Examples of calculation conditions, boundary conditions, and grid generating condition for the relationship between definitions of calculation condition, grid attributes, boundary conditions and the iRIClib subroutines to load them.

Refer to Reading calculation conditions, Reading calculation grid and Reading boundary conditions for the detail of subroutines to load calculation condition, grids, and boundary conditions.