MFIX  2016-1
get_poly_data.f
Go to the documentation of this file.
1 
2 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvC
3 ! C
4 ! Module name: GET_POLY_DATA C
5 ! Purpose: reads polygon(s) coordinates from poly.dat (2D only) C
6 ! C
7 ! Author: Jeff Dietiker Date: 30-JAN-09 C
8 ! Reviewer: Date: **-***-** C
9 ! C
10 ! Revision Number: C
11 ! Purpose: C
12 ! Author: Date: dd-mmm-yy C
13 ! Reviewer: Date: dd-mmm-yy C
14 ! C
15 ! Literature/Document References: C
16 ! C
17 ! Variables referenced: C
18 ! C
19 ! Variables modified: C
20 ! C
21 ! Local variables: C
22 ! C
23 !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^C
24 !
25  SUBROUTINE get_poly_data
26 
27 !-----------------------------------------------
28 ! M o d u l e s
29 !-----------------------------------------------
30 
31  USE compar
32  USE exit, only: mfix_exit
33  USE fldvar
34  USE funits
35  USE mpi_utility
36  USE param
37  USE param1
38  USE physprop
39  USE polygon
40  USE progress_bar
41  USE run
42  USE rxns
43  USE scalars
44  IMPLICIT NONE
45 
46  INTEGER :: POLY,V,NN,NSKIP
47  LOGICAL :: PRESENT
48 
49  WRITE(*,2000) 'READING polygon geometry from poly.dat...'
50 
51  INQUIRE(file='poly.dat',exist=present)
52  IF(.NOT.present) THEN
53  IF(mype == pe_io) THEN
54  WRITE(*,"('(PE ',I3,'): input data file, ',A11,' is missing: run aborted')") &
55  mype,'poly.dat'
56  ENDIF
57  CALL mfix_exit(mype)
58  ENDIF
59 !
60 !
61 ! OPEN poly.dat ASCII FILE
62 !
63  OPEN(convert='BIG_ENDIAN',unit=333, file='poly.dat', status='OLD', err=910)
64 
65  nskip = 13
66  DO nn=1,nskip
67  READ(333,*,err=920,end=930) ! Skip first NSKIP comment lines
68  ENDDO
69 
70  READ(333,*,err=920,end=930) n_polygon
71 
72  DO poly = 1, n_polygon
73  READ(333,*,err=920,end=930) n_vertex(poly), poly_sign(poly)
74  IF(dabs(poly_sign(poly))/=one) THEN
75  WRITE(*,*)'ERROR WHILE READIND poly.dat:'
76  WRITE(*,*)'POLYGON SIGN MUST BE +1.0 or -1.0.'
77  CALL mfix_exit(mype)
78  ENDIF
79  DO v = 1,n_vertex(poly)
80  READ(333,*,err=920,end=930) x_vertex(poly,v),y_vertex(poly,v),bc_id_p(poly,v)
81  ENDDO
82  x_vertex(poly,n_vertex(poly) + 1) = x_vertex(poly, 1) ! Copy first vertex as last vertex to close the polygon
83  y_vertex(poly,n_vertex(poly) + 1) = y_vertex(poly, 1)
84  ENDDO
85 
86  CLOSE(333)
87 
88  WRITE(*,2010) 'Polygon geometry successfully read for ', n_polygon, ' polygon(s).'
89 
90  RETURN
91 
92 !======================================================================
93 ! HERE IF AN ERROR OCCURED OPENNING/READING THE FILE
94 !======================================================================
95 !
96  910 CONTINUE
97  WRITE (*, 1500)
98  CALL mfix_exit(mype)
99  920 CONTINUE
100  WRITE (*, 1600)
101  CALL mfix_exit(mype)
102  930 CONTINUE
103  WRITE (*, 1700)
104  CALL mfix_exit(mype)
105 !
106  1500 FORMAT(/1x,70('*')//' From: GET_POLY_DATA',/' Message: ',&
107  'Unable to open poly.dat file',/1x,70('*')/)
108  1600 FORMAT(/1x,70('*')//' From: GET_POLY_DATA',/' Message: ',&
109  'Error while reading poly.dat file',/1x,70('*')/)
110  1700 FORMAT(/1x,70('*')//' From: GET_POLY_DATA',/' Message: ',&
111  'End of file reached while reading poly.dat file',/1x,70('*')/)
112  2000 FORMAT(1x,a)
113  2010 FORMAT(1x,a,i4,a)
114 
115  END SUBROUTINE get_poly_data
116 
117 
118 !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvC
119 ! C
120 ! Module name: EVAL_POLY_FCT C
121 ! Purpose: Evaluates a user-defined function C
122 ! C
123 ! Author: Jeff Dietiker Date: 21-Feb-08 C
124 ! Reviewer: Date: C
125 ! C
126 ! Revision Number # Date: ##-###-## C
127 ! Author: # C
128 ! Purpose: # C
129 ! C
130 !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^C
131  SUBROUTINE eval_poly_fct(x1,x2,x3,Q,f_pol,CLIP_FLAG,BCID)
133  USE param
134  USE param1
135  USE parallel
136  USE constant
137  USE run
138  USE toleranc
139  USE geometry
140  USE indices
141  USE compar
142  USE sendrecv
143  USE fldvar
144  USE quadric
145  USE cutcell
146  USE polygon
147 
148  IMPLICIT NONE
149  DOUBLE PRECISION x1,x2,x3
150  DOUBLE PRECISION f_pol
151  DOUBLE PRECISION, DIMENSION(DIM_POLYGON) :: F_POLY
152  INTEGER :: Q
153  LOGICAL :: CLIP_X,CLIP_Y,CLIP_FLAG
154  LOGICAL :: test1,test2
155 
156  INTEGER :: POLY,N_EDGE,COUNTER,EDGE
157  DOUBLE PRECISION :: X_VERTEX_MIN,X_VERTEX_MAX,Y_VERTEX_MIN,Y_VERTEX_MAX
158  DOUBLE PRECISION :: XV1,XV2,YV1,YV2
159  DOUBLE PRECISION :: x_west,x_east,y_north,y_south,slope,x_star,D1,D2
160  DOUBLE PRECISION :: max_slope = 200.0d0
161  DOUBLE PRECISION :: TOL_xstar
162  INTEGER :: BCID
163 
164 !======================================================================
165 ! This subroutine checks whether a point P(x1,x2,x3) lies inside any
166 ! of the N_POLGON polygon(s), using the Shimrat's algorithm:
167 ! 1) Draw a horizontal line from point P to -infinity (here taken as
168 ! the minimum x-location of the polygon vertices)
169 ! 2) Count the number of intersection(s) with all edges (COUNTER)
170 ! 3) If COUNTER is even, the point is outside
171 ! If COUNTER is odd, the point is inside
172 ! Once the point's location is determined, a value is assigned to f_pol:
173 ! fpol = 0 if point lies on top of one of the polygon's edges
174 ! (within tolerance TOL_POLY)
175 ! fpol = POLY_SIGN(POLY) if point lies inside the polygon
176 ! fpol = - POLY_SIGN(POLY) if point lies outside the polygon
177 ! where
178 ! POLY_SIGN(POLY) = -1.0 means the interior of the polygon
179 ! is part of the computational domain
180 ! POLY_SIGN(POLY) = +1.0 means the interior of the polygon
181 ! is excluded from the computational domain
182 !======================================================================
183 
184  IF(n_polygon < 1) RETURN
185 
186  bcid = -1
187 
188  DO poly = 1,n_polygon
189 
190  n_edge = n_vertex(poly)
191 
192  x_vertex_min = minval(x_vertex(poly,:)) - 2.0d0 * tol_poly
193  x_vertex_max = maxval(x_vertex(poly,:)) + 2.0d0 * tol_poly
194 
195  y_vertex_min = minval(y_vertex(poly,:)) - 2.0d0 * tol_poly
196  y_vertex_max = maxval(y_vertex(poly,:)) + 2.0d0 * tol_poly
197 
198  clip_x = (x_vertex_min <= x1).AND.( x1 <= x_vertex_max)
199  clip_y = (y_vertex_min <= x2).AND.( x2 <= y_vertex_max)
200 
201 
202  IF(clip_x.AND.clip_y) THEN
203 
204  counter = 0
205 
206  DO edge = 1, n_edge
207 
208  xv1 = x_vertex(poly,edge)
209  xv2 = x_vertex(poly,edge + 1)
210 
211  yv1 = y_vertex(poly,edge)
212  yv2 = y_vertex(poly,edge + 1)
213 
214 
215  d1 = dsqrt((x1 - xv1)**2 + (x2 - yv1)**2)
216  d2 = dsqrt((x1 - xv2)**2 + (x2 - yv2)**2)
217  IF(dmin1(d1,d2)<tol_poly) THEN
218  f_pol = zero
219  bcid = bc_id_p(poly,edge)
220  RETURN
221  ENDIF
222 
223  IF(dabs(yv2 - yv1) < tol_poly) THEN
224  test1 = (dabs(x2 - yv1) < tol_poly)
225  x_west = dmin1(xv1,xv2)
226  x_east = dmax1(xv1,xv2)
227  test2 = (x_west <= x1).AND.( x1 <= x_east)
228  IF (test1.and.test2) THEN
229  f_pol = zero
230  bcid = bc_id_p(poly,edge)
231  RETURN
232  ENDIF
233  ELSE
234  y_south = dmin1(yv1,yv2)
235  y_north = dmax1(yv1,yv2)
236  test1 = (y_south <= x2).AND.( x2 <= y_north)
237  IF(test1) THEN
238  slope = (xv2 - xv1) / (yv2 - yv1)
239  x_star = xv1 + slope * (x2 - yv1)
240 
241  IF(dabs(slope)>max_slope) THEN
242  tol_xstar = max_slope * tol_poly
243  ELSE
244  tol_xstar = tol_poly
245  ENDIF
246 
247  IF (x_star < x1 - tol_xstar) THEN
248  counter =counter + 1
249  ELSEIF(dabs(x_star - x1) <= tol_xstar) THEN
250  f_pol = zero
251  bcid = bc_id_p(poly,edge)
252  RETURN
253  ENDIF
254  ENDIF
255  ENDIF
256  ENDDO
257 
258  IF((counter/2) * 2 == counter) THEN
259  f_poly(poly) = -poly_sign(poly) ! even ==> outside
260  ELSE
261  f_poly(poly) = poly_sign(poly) ! odd ==> inside
262  ENDIF
263 
264  ELSE
265  f_poly(poly) = -poly_sign(poly) ! outside
266  ENDIF
267 
268  ENDDO
269 
270  f_pol = maxval(f_poly(1:n_polygon))
271 
272  clip_flag = .true.
273 
274  RETURN
275 
276  END SUBROUTINE eval_poly_fct
double precision, dimension(dim_polygon, dim_vertex) x_vertex
Definition: polygon_mod.f:10
integer, dimension(dim_polygon, dim_vertex) bc_id_p
Definition: polygon_mod.f:18
double precision, parameter one
Definition: param1_mod.f:29
Definition: rxns_mod.f:1
integer, dimension(dim_polygon) n_vertex
Definition: polygon_mod.f:14
double precision, dimension(:), allocatable a
Definition: scalars_mod.f:29
integer pe_io
Definition: compar_mod.f:30
subroutine mfix_exit(myID, normal_termination)
Definition: exit.f:5
subroutine get_poly_data
Definition: get_poly_data.f:26
Definition: exit.f:2
Definition: run_mod.f:13
Definition: param_mod.f:2
integer mype
Definition: compar_mod.f:24
integer n_polygon
Definition: polygon_mod.f:6
subroutine eval_poly_fct(x1, x2, x3, Q, f_pol, CLIP_FLAG, BCID)
double precision tol_poly
Definition: polygon_mod.f:16
double precision, parameter zero
Definition: param1_mod.f:27
double precision, dimension(dim_polygon) poly_sign
Definition: polygon_mod.f:12