psmile_remove_intersect.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
00008 !
00009 ! !INTERFACE:
00010 
00011       subroutine psmile_remove_intersect (inter, idl, idg, npart,  &
00012                       local_extent_info, global_extent_info, ierror)
00013 !
00014 ! !USES:
00015 !
00016       use PRISM_constants
00017 !
00018       use PSMILe, dummy_interface => PSMILe_Remove_intersect
00019 
00020       implicit none
00021 !
00022 ! !INPUT PARAMETERS:
00023 !
00024       Integer, Intent (In)              :: 
00025          local_extent_info (nd_extent_infos, *)
00026 !
00027 !     Local extents info with
00028 !         local_extent_info (3, :) = Transformation code
00029 !        
00030 !
00031       Integer, Intent (In)              :: 
00032          global_extent_info (nd_extent_infos, *)
00033 !
00034 !     Global extent info with
00035 !         global_extent_info (3, :) = Transformation code
00036 !
00037 !
00038 ! !INPUT/OUTPUT PARAMETERS:
00039 !
00040       Integer, Intent (InOut)           :: npart
00041 
00042 !     Number of intersections
00043 !
00044       Real (PSMILe_float_kind), Intent (InOut) :: inter (2, ndim_3d, npart)
00045 
00046 !     Intersections
00047 !
00048       Integer, Intent (InOut)           :: idl (npart)
00049 
00050 !     First (local) Id of the intersections
00051 !     (to be changed if a intersection is removed)
00052 !
00053       Integer, Intent (InOut)           :: idg (npart)
00054 
00055 !     Second (global) Id of the intersections
00056 !     (to be changed if a intersection is removed)
00057 !
00058 ! !OUTPUT PARAMETERS:
00059 !
00060       Integer, Intent (Out)             :: ierror
00061 
00062 !     Returns the error code of PSMILe_Remove_intersect;
00063 !             ierror = 0 : No error
00064 !             ierror > 0 : Severe error
00065 !
00066 ! !LOCAL PARAMETERS
00067 !
00068       Double Precision                  :: gap = 0.0d0
00069 !
00070 ! !LOCAL VARIABLES
00071 !
00072       Integer                           :: i, k, l, lbeg
00073       Integer                           :: nfit
00074       Logical                           :: fit (ndim_3d)
00075 !
00076       Integer                           :: trans_diff (npart)
00077       Real (PSMILe_float_kind)          :: common (2, ndim_3d, npart)
00078 !
00079 ! !DESCRIPTION:
00080 !
00081 ! Subroutine "PSMILe_Remove_intersect" removes the common parts
00082 ! from the intersections transferred.
00083 !
00084 ! !REVISION HISTORY:
00085 !
00086 !   Date      Programmer   Description
00087 ! ----------  ----------   -----------
00088 ! 03.07.06    H. Ritzdorf  created
00089 !
00090 !EOP
00091 !----------------------------------------------------------------------
00092 !
00093 ! $Id: psmile_remove_intersect.F90 2325 2010-04-21 15:00:07Z valcke $
00094 ! $Author: valcke $
00095 !
00096    Character(len=len_cvs_string), save :: mycvs = 
00097        '$Id: psmile_remove_intersect.F90 2325 2010-04-21 15:00:07Z valcke $'
00098 !
00099 !----------------------------------------------------------------------
00100 !
00101 !  Initialization
00102 !
00103 #ifdef VERBOSE
00104       print 9990, trim(ch_id), npart
00105 
00106       call psmile_flushstd
00107 
00108 #endif /* VERBOSE */
00109 !
00110       ierror = 0
00111 !
00112          do l = 1, npart
00113          trans_diff (l) = local_extent_info(3, idl(l)) - &
00114                          global_extent_info(3, idg(l))
00115          end do
00116 !
00117 !===> Look for common intersections
00118 !
00119       k = 1
00120           do while (k <= npart - 1)
00121 !
00122 !===> ... Get common part of inter (:, :, k) with other inter's
00123 !
00124              do l = k+1, npart
00125              common (1, :, l) = max (inter (1,:,l), inter (1,:,k))
00126              common (2, :, l) = min (inter (2,:,l), inter (2,:,k))
00127              end do ! l
00128 !
00129 !     ... Ignore parts with different transformations
00130 !         ? Wird dann noch etwas removet; Dann kann man sich die
00131 !           Routine sparen !
00132 !
00133              do l = k+1, npart
00134              if (trans_diff (l) /= trans_diff (k)) &
00135                 common (1, 1, l) = common (2, 1, l) + 1.0
00136              end do ! l
00137 !
00138           lbeg = k + 1
00139 !
00140              do while (lbeg <= npart )
00141                 do l = lbeg, npart
00142                 if (minval (common (2, :, l) - common (1, :, l)) >= 0.0d0) exit
00143                 end do
00144 !
00145              if (l > npart) exit
00146              lbeg = l + 1
00147 !
00148              if (maxval (common (2, :, l) - common (1, :, l)) == 0.0d0) cycle
00149 !
00150 !===> ...... common intersection between k and l found
00151 !            (i)   can inter (:,:,l) be removed ?
00152 !            (ii)  can inter (:,:,k) be removed ?
00153 !            (iii) can inter (:,:,l) be shrinked ?
00154 !            (iv)  ???can inter (:,:,k) be shrinked ?
00155 !
00156                 do i = 1, ndim_3d
00157                 fit (i) = maxval (abs (common (1:2,i,l) - inter (1:2,i,l))) &
00158                                  == 0.0d0
00159                 end do
00160              nfit = count (fit)
00161 !
00162 !===> ...... (i) nfit = 3: inter (:, :, l) can be removed
00163 !
00164              if (nfit == ndim_3d) then
00165                 if (l /= npart) then
00166                    inter  (:, :, l) = inter  (:, :, npart)
00167                    common (:, :, l) = common (:, :, npart)
00168                    idl (l) = idl (npart)
00169                    idg (l) = idg (npart)
00170                    trans_diff (l) = trans_diff (npart)
00171                 endif
00172 
00173                 npart = npart - 1
00174                 lbeg = l
00175 
00176                 cycle ! next l
00177              endif 
00178 !
00179 !===> ...... (ii) is inter (:, :, k) contained in inter (:, :, l)
00180 !
00181              if (maxval (abs (common (:,:,l) - inter (:,:,k))) == 0.0d0) then
00182                 inter  (:, :, k) = inter  (:, :, npart)
00183                 trans_diff (k) = trans_diff (npart)
00184 
00185                 idl (k) = idl (npart)
00186                 idg (k) = idg (npart)
00187 
00188                 npart = npart - 1
00189                 k = k - 1
00190 
00191                 exit ! next k
00192              endif
00193 !
00194 !===> ...... (iii) Can inter (:, :, l) be shrinked ?
00195 !                  changed = .true. : inter (:, :, l) was shrinked
00196 !
00197 !            changed = .false.
00198 
00199              if (nfit >= ndim_2d) then
00200                 if (fit(1) .and. fit (2)) then
00201 
00202                    if      (common (1, 3, l) == inter (1, 3, l)) then
00203                       inter (1, 3, l) = common (2, 3, l) + gap
00204 !                     changed = .true.
00205 
00206                    else if (common (2, 3, l) == inter (2, 3, l)) then
00207 
00208                       inter (2, 3, l) = common (1, 3, l) - gap
00209 !                     changed = .true.
00210                    endif
00211 
00212                 else if (fit (2) .and. fit (3)) then
00213 
00214                    if      (common (1, 1, l) == inter (1, 1, l)) then
00215                       inter (1, 1, l) = common (2, 1, l) + gap
00216 !                     changed = .true.
00217 
00218                    else if (common (2, 1, l) == inter (2, 1, l)) then
00219 
00220                       inter (2, 1, l) = common (1, 1, l) - gap
00221 !                     changed = .true.
00222                    endif
00223 
00224                 else ! if (fit (1) .and. fit (3)) then
00225 
00226                    if      (common (1, 2, l) == inter (1, 2, l)) then
00227                       inter (1, 2, l) = common (2, 2, l) + gap
00228 !                     changed = .true.
00229 
00230                    else if (common (2, 1, l) == inter (2, 1, l)) then
00231 
00232                       inter (2, 2, l) = common (1, 2, l) - gap
00233 !                     changed = .true.
00234                    endif
00235                 endif
00236              endif
00237 
00238 #ifdef WIRKLICH
00239 !
00240 ! in this case, the changed = .true. and .false. statements have to 
00241 ! be enabled.
00242 !
00243 !
00244 !===> ... Is shrinking in 3rd Dimension possible
00245 !         Currently, there ist any PRISM grid type where this is necessary !
00246 !
00247              if (! changed) then
00248 
00249                 do i = 1, ndim_3d
00250                 fitk (i) = maxval (abs (common (1:2,i,l) - inter (1:2,i,k))) &
00251                            == 0
00252                 end do
00253              nfitk = count (fitk)
00254 !
00255              if (nfitk >= ndim_2d) then
00256                 if (fitk(1) .and. fitk (2)) then
00257 
00258                    if      (common (1, 3, l) == inter (1, 3, k)) then
00259                       inter (1, 3, k) = common (2, 3, l) + gap
00260                       k = k - 1
00261                       exit ! k
00262 
00263                    else if (common (2, 3, l) == inter (2, 3, k)) then
00264 
00265                       inter (2, 3, k) = common (1, 3, l) - gap
00266                       k = k - 1
00267                       exit ! k
00268 
00269                    endif
00270 
00271                 else if (fitk (2) .and. fitk (3)) then
00272 
00273                    if      (common (1, 1, l) == inter (1, 1, k)) then
00274                       inter (1, 1, k) = common (2, 1, l) + gap
00275                       k = k - 1
00276                       exit ! k
00277 
00278                    else if (common (2, 1, l) == inter (2, 1, k)) then
00279 
00280                       inter (2, 1, k) = common (1, 1, l) - gap
00281                       k = k - 1
00282                       exit ! k
00283                    endif
00284 
00285                 else ! if (fitk (1) .and. fitk (3)) then
00286 
00287                    if      (common (1, 2, l) == inter (1, 2, k)) then
00288                       inter (1, 2, k) = common (2, 2, l) + gap
00289                       k = k - 1
00290                       exit ! k
00291 
00292                    else if (common (2, 1, l) == inter (2, 1, k)) then
00293 
00294                       inter (2, 2, k) = common (1, 2, l) - gap
00295                       k = k - 1
00296                       exit ! k
00297                    endif
00298                 endif
00299              endif
00300              endif
00301 #endif
00302 !
00303              end do ! while (lbeg <= npart)
00304 !
00305          k = k + 1
00306          end do ! while ( k <= npart )
00307 !
00308 !===> All done
00309 !
00310 #ifdef VERBOSE
00311       print 9980, trim(ch_id), ierror, npart
00312       call psmile_flushstd
00313 #endif /* VERBOSE */
00314 !
00315 !  Formats:
00316 !
00317 
00318 #ifdef VERBOSE
00319 
00320 9990 format (1x, a, ': psmile_remove_intersect: npart =', i4)
00321 9980 format (1x, a, ': psmile_remove_intersect: eof ierror =', i3, &
00322                     '; npart =', i4)
00323 
00324 #endif /* VERBOSE */ 
00325 
00326       end subroutine PSMILe_Remove_intersect

Generated on 18 Mar 2011 for Oasis4 by  doxygen 1.6.1