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.
1program SampleProgram
2 implicit none
3 include 'cgnslib_f.h'
4 include 'iriclib_f.h'
5 integer:: fin, ier
6 integer:: icount, istatus
7 character(200)::condFile
8 integer:: maxiterations
9 double precision:: timestep
10 integer:: surfacetype
11 double precision:: constantsurface
12 integer:: variable_surface_size
13 double precision, dimension(:), allocatable:: variable_surface_time
14 double precision, dimension(:), allocatable:: variable_surface_elevation
15
16 integer:: isize, jsize
17 double precision, dimension(:,:), allocatable:: grid_x, grid_y
18 double precision, dimension(:,:), allocatable:: elevation
19 integer, dimension(:,:), allocatable:: obstacle
20
21 integer:: inflowid
22 integer:: inflow_count
23 integer:: inflow_element_max
24 integer:: discharge_variable_sizemax
25 integer, dimension(:), allocatable:: inflow_element_count
26 integer, dimension(:,:,:), allocatable:: inflow_element
27 integer, dimension(:), allocatable:: discharge_type
28 double precision, dimension(:), allocatable:: discharge_constant
29 integer, dimension(:), allocatable:: discharge_variable_size
30 double precision, dimension(:,:), allocatable:: discharge_variable_time
31 double precision, dimension(:,:), allocatable:: discharge_variable_value
32
33 write(*,*) "Sample Program"
34
35 ! (abbr)
36
37 ! Initializes iRIClib
38 call cg_iric_init_f(fin, ier)
39 if (ier /=0) STOP "*** Initialize error of CGNS file ***"
40 ! Set options
41 call iric_initoption_f(IRIC_OPTION_CANCEL, ier)
42 if (ier /=0) STOP "*** Initialize option error***"
43
44 ! Loads calculation condition
45 call cg_iric_read_integer_f("maxIteretions", maxiterations, ier)
46 call cg_iric_read_real_f("timeStep", timestep, ier)
47 call cg_iric_read_integer_f("surfaceType", surfacetype, ier)
48 call cg_iric_read_real_f("constantSurface", constantsurface, ier)
49
50 call cg_iric_read_functionalsize_f("variableSurface", variable_surface_size, ier)
51 allocate(variable_surface_time(variable_surface_size))
52 allocate(variable_surface_elevation(variable_surface_size))
53 call cg_iric_read_functional_f("variableSurface", variable_surface_time, variable_surface_elevation, ier)
54
55 ! Check the grid size
56 call cg_iric_gotogridcoord2d_f(isize, jsize, ier)
57
58 ! Allocate the memory to read grid coordinates
59 allocate(grid_x(isize,jsize), grid_y(isize,jsize))
60 ! Loads grid coordinates
61 call cg_iric_getgridcoord2d_f(grid_x, grid_y, ier)
62
63 ! Allocate the memory to load grid attributes defined at grid nodes and grid cells
64 allocate(elevation(isize, jsize))
65 allocate(obstacle(isize - 1, jsize - 1))
66
67 ! Loads grid attributes
68 call cg_iric_read_grid_real_node_f("Elevation", elevation, ier)
69 call cg_iric_read_grid_integer_cell_f("Obstacle", obstacle, ier)
70
71 ! Allocate memory to load boundary conditions (inflow)
72 allocate(inflow_element_count(inflow_count))
73 allocate(discharge_type(inflow_count), discharge_constant(inflow_count))
74 allocate(discharge_variable_size(inflow_count))
75
76 ! Check the number of grid nodes assigned as inflow, and the size of time-dependent discharge.
77 inflow_element_max = 0
78 do inflowid = 1, inflow_count
79 ! Read the number of grid nodes assigned as inflow
80 call cg_iric_read_bc_indicessize_f('inflow', inflowid, inflow_element_count(inflowid))
81 if (inflow_element_max < inflow_element_count(inflowid)) then
82 inflow_element_max = inflow_element_count(inflowid)
83 end if
84 ! Read the size of time-dependent discharge
85 call cg_iric_read_bc_functionalsize_f('inflow', inflowid, 'FunctionalDischarge', discharge_variable_size(inflowid), ier);
86 if (discharge_variable_sizemax < discharge_variable_size(inflowid)) then
87 discharge_variable_sizemax = discharge_variable_size(inflowid)
88 end if
89 end do
90
91 ! Allocate the memory to load grid nodes assigned as inflow, and time-dependent discharge.
92 allocate(inflow_element(inflow_count, 2, inflow_element_max))
93 allocate(discharge_variable_time(inflow_count, discharge_variable_sizemax))
94 allocate(discharge_variable_value(inflow_count, discharge_variable_sizemax))
95
96 ! Loads boundary condition
97 do inflowid = 1, inflow_count
98 ! Loads the grid nodes assigned as inflow
99 call cg_iric_read_bc_indices_f('inflow', inflowid, inflow_element(inflowid:inflowid,:,:), ier)
100 ! Loads the inflow type (0 = constant, 1 = time-dependent)
101 call cg_iric_read_bc_integer_f('inflow', inflowid, 'Type', discharge_type(inflowid:inflowid), ier)
102 ! Loads the discharge (constant)
103 call cg_iric_read_bc_real_f('inflow', inflowid, 'ConstantDischarge', discharge_constant(inflowid:inflowid), ier)
104 ! Loads the discharge (time-dependent)
105 call cg_iric_read_bc_functional_f('inflow', inflowid, 'FunctionalDischarge', discharge_variable_time(inflowid:inflowid,:), discharge_variable_value(inflowid:inflowid,:), ier)
106 end do
107
108 ! Closes the calculation data file
109 call cg_close_f(fin, ier)
110 stop
111end 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.