MFIX  2016-1
read_particle_input.f
Go to the documentation of this file.
1 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv!
2 ! Subroutine: READ_PAR_INPUT !
3 ! !
4 ! Purpose: Read the particle input and broadcasts the particle data to !
5 ! respective processors. !
6 !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^!
7  SUBROUTINE read_par_input
8 
9 !-----------------------------------------------
10 ! Modules
11 !-----------------------------------------------
12  USE discretelement
13  use cdist
14  use compar
15  use desmpi
16  use error_manager
17  use functions
18  use funits
19  use geometry, only: no_k
21  use mpi_utility
22 
23  implicit none
24 !-----------------------------------------------
25 ! Local variables
26 !-----------------------------------------------
27 ! indices
28  integer :: k
29 ! index of particle
30  INTEGER :: lcurpar
31 ! local unit
32  INTEGER, PARAMETER :: lunit=10
33 ! local filename
34  character(255) lfilename
35 ! IO Status:
36  INTEGER :: IOS
37 ! Flag to indicate if file exists.
38  LOGICAL :: lEXISTS
39 ! Read dimension: 2D vs 3D data
40  integer :: RDMN
41 !-----------------------------------------------
42 
43 
44  CALL init_err_msg("READ_PAR_INPUT")
45 
46 
47  ios = 0
48  rdmn = merge(2,3,no_k)
49 
50 ! Setup the file name based on distributed or serial IO.
51  IF(bdist_io) THEN
52  lfilename = ''
53  WRITE(lfilename,'("particle_input_",I4.4,".dat")') mype
54  ELSE
55  lfilename= "particle_input.dat"
56  ENDIF
57 
58 ! Check the the file exists and open it.
59  IF(bdist_io .OR. mype == pe_io) THEN
60  INQUIRE(file=lfilename, exist=lexists)
61  IF(.NOT.lexists) THEN
62  WRITE(err_msg, 1100)
63  CALL flush_err_msg
64  ios = 1
65  ELSE
66  OPEN(convert='BIG_ENDIAN',unit=lunit, file=lfilename, form="FORMATTED")
67  ENDIF
68  ENDIF
69 
70 ! Collect the error message and quit.
71  CALL global_all_sum(ios)
72  IF(ios /= 0) CALL mfix_exit(mype)
73 
74  1100 FORMAT('Error 1100: FATAL - DEM particle input file not found!')
75 
76 ! Read the file
77 !----------------------------------------------------------------->>>
78 ! In distributed IO the first line of the file will be number of
79 ! particles in that processor
80  IF (bdist_io) then
81  read(lunit,*) pip
82  DO lcurpar = 1,pip
83  call set_normal(lcurpar)
84  read (lunit,*) (des_pos_new(lcurpar,k),k=1,rdmn),&
85  des_radius(lcurpar), ro_sol(lcurpar),&
86  (des_vel_new(lcurpar,k),k=1,rdmn)
87  ENDDO
88 
89 ! Serial IO (not bDIST_IO)
90  ELSE
91 !----------------------------------------------------------------->>>
92 
93 ! Read into temporary variable and scatter
94  IF (mype .eq. pe_io) THEN
95 
96 ! Allocate and initialize temporary variables.
97  ALLOCATE (dpar_pos(particles,3)); dpar_pos=0.0
98  ALLOCATE (dpar_vel(particles,3)); dpar_vel=0.0
99  ALLOCATE (dpar_rad(particles)); dpar_rad=0.0
100  ALLOCATE (dpar_den(particles)); dpar_den = 0.0
101 ! Loop through the input file.
102  DO lcurpar = 1, particles
103  read (lunit,*,iostat=ios) &
104  (dpar_pos(lcurpar,k),k=1,rdmn),dpar_rad(lcurpar), &
105  dpar_den(lcurpar),(dpar_vel(lcurpar,k),k=1,rdmn)
106 
107 ! Report read errors.
108  IF(ios > 0) THEN
109  WRITE(err_msg,1200)
110  CALL flush_err_msg
111  EXIT
112  1200 FORMAT('Error 1200: Error reported when reading particle input ',&
113  'file.',/'A common error is 2D input for 3D cases.')
114 
115 ! Report End-of-File errors.
116  ELSEIF(ios < 0) THEN
117  WRITE(err_msg,1201) &
118  trim(ival(lcurpar)), trim(ival(particles))
119  CALL flush_err_msg
120  EXIT
121  1201 FORMAT('Error 1201: Error reported when reading particle input ',&
122  'file.',/'End-of-File found for particle ',a,' and ',a,1x, &
123  'entries are expected.')
124 
125  ENDIF
126 
127  ENDDO
128 
129  ENDIF
130 
131  CALL global_all_sum(ios)
132  IF(ios /= 0) CALL mfix_exit(mype)
133 
135 
136  IF(mype == pe_io) &
137  deallocate (dpar_pos,dpar_vel,dpar_rad,dpar_den)
138 
139  ENDIF ! end if/else bdist_io
140 !-----------------------------------------------------------------<<<
141 
142  IF(bdist_io .OR. mype == pe_io) CLOSE(lunit)
143 
144  CALL finl_err_msg()
145 
146  RETURN
147 
148  CALL mfix_exit(mype)
149 
150  END SUBROUTINE read_par_input
151 
subroutine read_par_input
logical bdist_io
Definition: cdist_mod.f:4
subroutine finl_err_msg
double precision, dimension(:), allocatable dpar_rad
Definition: desmpi_mod.f:61
subroutine des_scatter_particle
double precision, dimension(:), allocatable dpar_den
Definition: desmpi_mod.f:60
subroutine init_err_msg(CALLER)
integer pe_io
Definition: compar_mod.f:30
Definition: cdist_mod.f:2
double precision, dimension(:,:), allocatable dpar_pos
Definition: desmpi_mod.f:58
logical no_k
Definition: geometry_mod.f:28
integer mype
Definition: compar_mod.f:24
character(len=line_length), dimension(line_count) err_msg
double precision, dimension(:,:), allocatable dpar_vel
Definition: desmpi_mod.f:59
subroutine flush_err_msg(DEBUG, HEADER, FOOTER, ABORT, LOG, CALL_TREE)