psmile_remove_intersect_int.F90

Go to the documentation of this file.
00001 !-----------------------------------------------------------------------
00002 ! Copyright 2006-2010, NEC Europe Ltd., London, UK.
00003 ! All rights reserved. Use is subject to OASIS4 license terms.
00004 !-----------------------------------------------------------------------
00005 !BOP
00006 !
00007 ! !ROUTINE: PSMILe_Remove_intersect_int
00008 !
00009 ! !INTERFACE:
00010 
00011       subroutine psmile_remove_intersect_int (inter, id1, id2, npart, ierror)
00012 !
00013 ! !USES:
00014 !
00015       use PRISM_constants
00016 !
00017       use PSMILe, dummy_interface => PSMILe_Remove_intersect_int
00018 
00019       implicit none
00020 !
00021 ! !INPUT/OUTPUT PARAMETERS:
00022 !
00023       Integer, Intent (InOut)           :: npart
00024 
00025 !     Number of intersections
00026 !
00027       Integer, Intent (InOut)           :: inter (2, ndim_3d, npart)
00028 
00029 !     Intersections
00030 !
00031       Integer, Intent (InOut)           :: id1 (npart)
00032 
00033 !     First Id of the intersections (to be changed if a intersection is
00034 !     removed)
00035 !
00036       Integer, Intent (InOut)           :: id2 (npart)
00037 
00038 !     Second Id of the intersections (to be changed if a intersection is
00039 !     removed)
00040 !
00041 ! !OUTPUT PARAMETERS:
00042 !
00043       Integer, Intent (Out)             :: ierror
00044 
00045 !     Returns the error code of PSMILe_Remove_intersect_int;
00046 !             ierror = 0 : No error
00047 !             ierror > 0 : Severe error
00048 !
00049 ! !LOCAL VARIABLES
00050 !
00051       Integer                           :: i, k, l, lbeg
00052       Integer                           :: nfit
00053       Logical                           :: fit (ndim_3d)
00054 !
00055       Integer                           :: common (2, ndim_3d, npart)
00056 !
00057 ! !DESCRIPTION:
00058 !
00059 ! Subroutine "PSMILe_Remove_intersect_int" removes the common parts
00060 ! from the intersections transferred.
00061 !
00062 ! !REVISION HISTORY:
00063 !
00064 !   Date      Programmer   Description
00065 ! ----------  ----------   -----------
00066 ! 05.10.05    H. Ritzdorf  created
00067 !
00068 !EOP
00069 !----------------------------------------------------------------------
00070 !
00071 ! $Id: psmile_remove_intersect_int.F90 2325 2010-04-21 15:00:07Z valcke $
00072 ! $Author: valcke $
00073 !
00074    Character(len=len_cvs_string), save :: mycvs = 
00075        '$Id: psmile_remove_intersect_int.F90 2325 2010-04-21 15:00:07Z valcke $'
00076 !
00077 !----------------------------------------------------------------------
00078 !
00079 !  Initialization
00080 !
00081 #ifdef VERBOSE
00082       print 9990, trim(ch_id), npart
00083 
00084       call psmile_flushstd
00085 #endif /* VERBOSE */
00086 !
00087       ierror = 0
00088 !
00089 !===> Look for common intersections
00090 !
00091       k = 1
00092           do while (k <= npart - 1)
00093 !
00094 !===> ... Get common part of inter (:, :, k) with other inter's
00095 !
00096              do l = k+1, npart
00097              common (1, :, l) = max (inter (1,:,l), inter (1,:,k))
00098              common (2, :, l) = min (inter (2,:,l), inter (2,:,k))
00099              end do ! l
00100 !
00101           lbeg = k + 1
00102 !
00103              do while (lbeg <= npart )
00104                 do l = lbeg, npart
00105                 if (minval (common (2, :, l) - common (1, :, l)) >= 0) exit
00106                 end do
00107 !
00108              if (l > npart) exit
00109              lbeg = l + 1
00110 !
00111              if (maxval (common (2, :, l) - common (1, :, l)) == 0) cycle
00112 !
00113 !===> ...... common intersection between k and l found
00114 !            (i)   can inter (:,:,l) be removed ?
00115 !            (ii)  can inter (:,:,k) be removed ?
00116 !            (iii) can inter (:,:,l) be shrinked ?
00117 !            (iv)  ???can inter (:,:,k) be shrinked ?
00118 !
00119                 do i = 1, ndim_3d
00120                 fit (i) = maxval (abs (common (1:2,i,l) - inter (1:2,i,l))) &
00121                                  == 0
00122                 end do
00123              nfit = count (fit)
00124 !
00125 !===> ...... (i) nfit = 3: inter (:, :, l) can be removed
00126 !
00127              if (nfit == ndim_3d) then
00128                 if (l /= npart) then
00129                    inter  (:, :, l) = inter  (:, :, npart)
00130                    common (:, :, l) = common (:, :, npart)
00131                    id1 (l) = id1 (npart)
00132                    id2 (l) = id2 (npart)
00133                 endif
00134 
00135                 npart = npart - 1
00136                 lbeg = l
00137 
00138                 cycle ! next l
00139              endif 
00140 !
00141 !===> ...... (ii) is inter (:, :, k) contained in inter (:, :, l)
00142 !
00143              if (maxval (abs (common (:,:,l) - inter (:,:,k))) == 0) then
00144                 inter  (:, :, k) = inter  (:, :, npart)
00145 
00146                 id1 (k) = id1 (npart)
00147                 id2 (k) = id2 (npart)
00148 
00149                 npart = npart - 1
00150                 k = k - 1
00151 
00152                 exit ! next k
00153              endif
00154 !
00155 !===> ...... (iii) Can inter (:, :, l) be shrinked ?
00156 !                  changed = .true. : inter (:, :, l) was shrinked
00157 !
00158 !            changed = .false.
00159 
00160              if (nfit >= ndim_2d) then
00161                 if (fit(1) .and. fit (2)) then
00162 
00163                    if      (common (1, 3, l) == inter (1, 3, l)) then
00164                       inter (1, 3, l) = common (2, 3, l) + 1
00165 !                     changed = .true.
00166 
00167                    else if (common (2, 3, l) == inter (2, 3, l)) then
00168 
00169                       inter (2, 3, l) = common (1, 3, l) - 1
00170 !                     changed = .true.
00171                    endif
00172 
00173                 else if (fit (2) .and. fit (3)) then
00174 
00175                    if      (common (1, 1, l) == inter (1, 1, l)) then
00176                       inter (1, 1, l) = common (2, 1, l) + 1
00177 !                     changed = .true.
00178 
00179                    else if (common (2, 1, l) == inter (2, 1, l)) then
00180 
00181                       inter (2, 1, l) = common (1, 1, l) - 1
00182 !                     changed = .true.
00183                    endif
00184 
00185                 else ! if (fit (1) .and. fit (3)) then
00186 
00187                    if      (common (1, 2, l) == inter (1, 2, l)) then
00188                       inter (1, 2, l) = common (2, 2, l) + 1
00189 !                     changed = .true.
00190 
00191                    else if (common (2, 1, l) == inter (2, 1, l)) then
00192 
00193                       inter (2, 2, l) = common (1, 2, l) - 1
00194 !                     changed = .true.
00195                    endif
00196                 endif
00197              endif
00198 
00199 #ifdef WIRKLICH
00200 !
00201 ! in this case, the changed = .true. and .false. statements have to 
00202 ! be enabled.
00203 !
00204 !
00205 !===> ... Is shrinking in 3rd Dimension possible
00206 !         Currently, there ist any PRISM grid type where this is necessary !
00207 !
00208              if (! changed) then
00209 
00210                 do i = 1, ndim_3d
00211                 fitk (i) = maxval (abs (common (1:2,i,l) - inter (1:2,i,k))) &
00212                            == 0
00213                 end do
00214              nfitk = count (fitk)
00215 !
00216              if (nfitk >= ndim_2d) then
00217                 if (fitk(1) .and. fitk (2)) then
00218 
00219                    if      (common (1, 3, l) == inter (1, 3, k)) then
00220                       inter (1, 3, k) = common (2, 3, l) + 1
00221                       k = k - 1
00222                       exit ! k
00223 
00224                    else if (common (2, 3, l) == inter (2, 3, k)) then
00225 
00226                       inter (2, 3, k) = common (1, 3, l) - 1
00227                       k = k - 1
00228                       exit ! k
00229 
00230                    endif
00231 
00232                 else if (fitk (2) .and. fitk (3)) then
00233 
00234                    if      (common (1, 1, l) == inter (1, 1, k)) then
00235                       inter (1, 1, k) = common (2, 1, l) + 1
00236                       k = k - 1
00237                       exit ! k
00238 
00239                    else if (common (2, 1, l) == inter (2, 1, k)) then
00240 
00241                       inter (2, 1, k) = common (1, 1, l) - 1
00242                       k = k - 1
00243                       exit ! k
00244                    endif
00245 
00246                 else ! if (fitk (1) .and. fitk (3)) then
00247 
00248                    if      (common (1, 2, l) == inter (1, 2, k)) then
00249                       inter (1, 2, k) = common (2, 2, l) + 1
00250                       k = k - 1
00251                       exit ! k
00252 
00253                    else if (common (2, 1, l) == inter (2, 1, k)) then
00254 
00255                       inter (2, 2, k) = common (1, 2, l) - 1
00256                       k = k - 1
00257                       exit ! k
00258                    endif
00259                 endif
00260              endif
00261              endif
00262 #endif
00263 !
00264              end do ! while (lbeg <= npart)
00265 !
00266          k = k + 1
00267          end do ! while ( k <= npart )
00268 !
00269 !===> All done
00270 !
00271 #ifdef VERBOSE
00272       print 9980, trim(ch_id), ierror, npart
00273       call psmile_flushstd
00274 #endif /* VERBOSE */
00275 !
00276 !  Formats:
00277 !
00278 
00279 #ifdef VERBOSE
00280 
00281 9990 format (1x, a, ': psmile_remove_intersect_int: npart =', i4)
00282 9980 format (1x, a, ': psmile_remove_intersect_int: eof ierror =', i3, &
00283                     '; npart =', i4)
00284 
00285 #endif /* VERBOSE */ 
00286 
00287       end subroutine PSMILe_Remove_intersect_int

Generated on 18 Mar 2011 for Oasis4 by  doxygen 1.6.1