File: N:\mfix\model\calc_cell.f

1     !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvC
2     !                                                                      C
3     !  Subroutine name: CALC_CELL                                          C
4     !  Purpose: calculate the i, j or k cell index for the corresponding   C
5     !     x y or z reactor location. the index returned depends on which   C
6     !     half of the i, j or k cell that the x, y, or z position          C
7     !     intersects                                                       C
8     !                                                                      C
9     !  Author: P. Nicoletti                               Date: 02-DEC-91  C
10     !                                                                      C
11     !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^C
12     
13           SUBROUTINE CALC_CELL(RMIN, REACTOR_LOC, D_DIR, N_DIR, CELL_LOC)
14     
15     !-----------------------------------------------
16     ! Modules
17     !-----------------------------------------------
18           USE param1, only : half
19           IMPLICIT NONE
20     !-----------------------------------------------
21     ! Dummy arguments
22     !-----------------------------------------------
23     ! the starting value of the x, y or z axis for which the i, j or k cell
24     ! index is to be found -- XMIN need not be zero, however, YMIN and ZMIN
25     ! are assumed to be zero.
26           DOUBLE PRECISION, INTENT(IN) :: RMIN
27     ! the x, y or z location along the axis for which the cell index (i, j
28     ! or k) is to be found
29           DOUBLE PRECISION, INTENT(IN) :: REACTOR_LOC
30     ! number of cells in the corresponding direction (IMAX, JMAX, or KMAX)
31           INTEGER, INTENT(IN) :: N_DIR
32     ! the cell lengths along the corresponding axis (DX, DY or DZ)
33           DOUBLE PRECISION, INTENT(IN), DIMENSION(0:(N_DIR+3)) :: D_DIR
34     ! the i, j, or k cell index that corresponds to the x, y or z
35     ! reactor_location (calculated value)
36           INTEGER, INTENT(INOUT) :: CELL_LOC
37     !-----------------------------------------------
38     ! Local variables
39     !-----------------------------------------------
40     ! loop counter
41           INTEGER :: LC
42     ! start and end coordinate for cell
43           DOUBLE PRECISION :: CELL_START, CELL_END
44     !-----------------------------------------------
45     
46           CELL_LOC = -1
47           CELL_START = RMIN
48           DO LC = 2, N_DIR + 1
49              CELL_END = CELL_START + D_DIR(LC)
50              IF (REACTOR_LOC <= CELL_START + HALF*D_DIR(LC)) THEN
51                 CELL_LOC = LC - 1
52                 RETURN
53              ELSEIF (REACTOR_LOC <= CELL_END + HALF*D_DIR(LC+1)) THEN
54                 CELL_LOC = LC
55                 RETURN
56              ENDIF
57              CELL_START = CELL_END
58           ENDDO
59           RETURN
60           END SUBROUTINE CALC_CELL
61     
62     
63     !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvC
64     !                                                                      C
65     !  Subroutine name: CALC_LOC                                           C
66     !  Purpose: calculate the x, y, or z position corresponding to the     C
67     !     given i, j or k cell index. this call returns the x, y or z      C
68     !     position corresponding to the east, north or top face of the     C
69     !     cell with the given i, j or k index.                             C
70     !                                                                      C
71     !  Author: P. Nicoletti                               Date: 02-DEC-91  C
72     !                                                                      C
73     !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^C
74     
75           SUBROUTINE CALC_LOC(RMIN, D_DIR, CELL_LOC, REACTOR_LOC)
76     
77     !-----------------------------------------------
78     ! Modules
79     !-----------------------------------------------
80           IMPLICIT NONE
81     !-----------------------------------------------
82     ! Dummy arguments
83     !-----------------------------------------------
84     ! the starting value of the x, y or z axis for which the x, y or z
85     ! position is to be found -- XMIN need not be zero, however, YMIN and
86     ! ZMIN are assumed to be zero.
87           DOUBLE PRECISION, INTENT(IN) :: RMIN
88     ! the i, j, or k cell index that corresponds to the x, y or z
89     ! reactor_location to be found
90           INTEGER, INTENT(IN) :: CELL_LOC
91     ! the cell lengths along the corresponding axis (DX, DY or DZ)
92           DOUBLE PRECISION, INTENT(IN), DIMENSION(0:CELL_LOC) :: D_DIR
93     ! the x, y or z location along the axis that corresponds to the i, j
94     ! k cell index  (calculated value)
95           DOUBLE PRECISION, INTENT(INOUT) :: REACTOR_LOC
96     !-----------------------------------------------
97     ! Local variables
98     !-----------------------------------------------
99     ! loop counter
100           INTEGER :: LC
101     !-----------------------------------------------
102     
103           REACTOR_LOC = RMIN
104           LC = 2
105           IF (CELL_LOC - 1 > 0) THEN
106              REACTOR_LOC = REACTOR_LOC + SUM(D_DIR(2:CELL_LOC))
107              LC = CELL_LOC + 1
108           ENDIF
109           RETURN
110           END SUBROUTINE CALC_LOC
111     
112     
113     !vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv!
114     !                                                                      !
115     !  Subroutine: CALC_CELL_INTERSECT                                     !
116     !  Author: J.Musser                                   Date: 23-APR-14  !
117     !                                                                      !
118     !  Purpose: Calculate the cell index that intersects LOC. Unlike the   !
119     !  base routine (CALC_CELL), this routine does not shift the index     !
120     !  based on which half of the cell the point intersects.               !
121     !                                                                      !
122     !  Comment: This is a brute force approach and should not be called    !
123     !  from within any critical routines/loops.                            !
124     !                                                                      !
125     !^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^!
126           SUBROUTINE CALC_CELL_INTERSECT(RMIN, LOC, D_DIR, N_DIR, CELL)
127     
128           IMPLICIT NONE
129     
130     ! Passed Arguments:
131     !---------------------------------------------------------------------//
132     ! Starting value of the axis (ZERO except for maybe XMIN)
133           DOUBLE PRECISION, INTENT(in) :: RMIN
134     ! Point to check for intersection.
135           DOUBLE PRECISION, INTENT(in) :: LOC
136     ! Number of cells in this direction (IMAX,JMAX,KMAX)
137           INTEGER, INTENT(in) :: N_DIR
138     ! Cell lengths (DX,DY,DZ)
139           DOUBLE PRECISION, INTENT(IN) :: D_DIR(0:(N_DIR+3))
140     ! Cell indices corresponding to LOC
141           INTEGER, INTENT(out) :: CELL
142     
143     ! Local Variables:
144     !---------------------------------------------------------------------//
145     ! Loop counter
146           INTEGER :: LC
147     ! Start/End coordinates for cell
148           DOUBLE PRECISION :: CELL_START, CELL_END
149     !......................................................................!
150     
151          CELL = -1
152     
153           CELL_START = RMIN
154           DO LC=2, N_DIR+1
155              CELL_END = CELL_START + D_DIR(LC)
156              IF(CELL_START <= LOC .AND. LOC <= CELL_END) THEN
157                 CELL = LC
158                 RETURN
159              ENDIF
160              CELL_START=CELL_END
161           ENDDO
162     
163           RETURN
164           END SUBROUTINE CALC_CELL_INTERSECT
165