123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586 |
- !
- ! $Id: modmask.F90 4779 2014-09-19 14:21:37Z rblod $
- !
- ! AGRIF (Adaptive Grid Refinement In Fortran)
- !
- ! Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
- ! Christophe Vouland (Christophe.Vouland@imag.fr)
- !
- ! This program is free software; you can redistribute it and/or modify
- ! it under the terms of the GNU General Public License as published by
- ! the Free Software Foundation; either version 2 of the License, or
- ! (at your option) any later version.
- !
- ! This program is distributed in the hope that it will be useful,
- ! but WITHOUT ANY WARRANTY; without even the implied warranty of
- ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ! GNU General Public License for more details.
- !
- ! You should have received a copy of the GNU General Public License
- ! along with this program; if not, write to the Free Software
- ! Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- !
- !
- !> Module Agrif_Mask.
- !>
- !> Module for masks.
- !
- module Agrif_Mask
- !
- use Agrif_Types
- !
- implicit none
- !
- contains
- !
- !===================================================================================================
- ! subroutine Agrif_CheckMasknD
- !
- !> Called in the procedure #Agrif_InterpnD to recalculate the value of the parent grid variable
- !! when this one is equal to Agrif_SpecialValue.
- !---------------------------------------------------------------------------------------------------
- subroutine Agrif_CheckMasknD ( tempP, parent, pbtab, petab, ppbtab, ppetab, noraftab, nbdim )
- !---------------------------------------------------------------------------------------------------
- type(Agrif_Variable), pointer :: tempP !< Part of the parent grid used for the interpolation of the child grid
- type(Agrif_Variable), pointer :: parent !< The parent grid
- integer, dimension(nbdim) :: pbtab !< limits of the parent grid used
- integer, dimension(nbdim) :: petab !< interpolation of the child grid
- integer, dimension(nbdim) :: ppbtab, ppetab
- logical, dimension(nbdim) :: noraftab
- integer :: nbdim
- !
- integer :: i0,j0,k0,l0,m0,n0
- !
- select case (nbdim)
- case (1)
- do i0 = pbtab(1),petab(1)
- if (tempP%array1(i0) == Agrif_SpecialValue) then
- call CalculNewValTempP((/i0/),tempP,parent,ppbtab,ppetab,noraftab,nbdim)
- endif
- enddo
- case (2)
- do j0 = pbtab(2),petab(2)
- do i0 = pbtab(1),petab(1)
- if (tempP%array2(i0,j0) == Agrif_SpecialValue) then
- call CalculNewValTempP((/i0,j0/),tempP,parent,ppbtab,ppetab, noraftab,nbdim)
- endif
- enddo
- enddo
- case (3)
- do k0 = pbtab(3),petab(3)
- do j0 = pbtab(2),petab(2)
- do i0 = pbtab(1),petab(1)
- if (tempP%array3(i0,j0,k0) == Agrif_SpecialValue) then
- !------CDIR NEXPAND
- call CalculNewValTempP3D((/i0,j0,k0/), &
- tempP%array3(ppbtab(1),ppbtab(2),ppbtab(3)), &
- parent%array3(ppbtab(1),ppbtab(2),ppbtab(3)), &
- ppbtab,ppetab,noraftab,MaxSearch,Agrif_SpecialValue)
- ! Call CalculNewValTempP((/i0,j0,k0/),
- ! & tempP,parent,
- ! & ppbtab,ppetab,
- ! & noraftab,nbdim)
- endif
- enddo
- enddo
- enddo
- case (4)
- do l0 = pbtab(4),petab(4)
- do k0 = pbtab(3),petab(3)
- do j0 = pbtab(2),petab(2)
- do i0 = pbtab(1),petab(1)
- if (tempP%array4(i0,j0,k0,l0) == Agrif_SpecialValue) then
- call CalculNewValTempP4D((/i0,j0,k0,l0/), &
- tempP%array4(ppbtab(1),ppbtab(2),ppbtab(3),ppbtab(4)), &
- parent%array4(ppbtab(1),ppbtab(2),ppbtab(3),ppbtab(4)), &
- ppbtab,ppetab,noraftab,MaxSearch,Agrif_SpecialValue)
- endif
- enddo
- enddo
- enddo
- enddo
- case (5)
- do m0 = pbtab(5),petab(5)
- do l0 = pbtab(4),petab(4)
- do k0 = pbtab(3),petab(3)
- do j0 = pbtab(2),petab(2)
- do i0 = pbtab(1),petab(1)
- if (tempP%array5(i0,j0,k0,l0,m0) == Agrif_SpecialValue) then
- call CalculNewValTempP((/i0,j0,k0,l0,m0/), &
- tempP,parent,ppbtab,ppetab,noraftab,nbdim)
- endif
- enddo
- enddo
- enddo
- enddo
- enddo
- case (6)
- do n0 = pbtab(6),petab(6)
- do m0 = pbtab(5),petab(5)
- do l0 = pbtab(4),petab(4)
- do k0 = pbtab(3),petab(3)
- do j0 = pbtab(2),petab(2)
- do i0 = pbtab(1),petab(1)
- if (tempP%array6(i0,j0,k0,l0,m0,n0) == Agrif_SpecialValue) then
- call CalculNewValTempP((/i0,j0,k0,l0,m0,n0/), &
- tempP,parent,ppbtab,ppetab,noraftab,nbdim)
- endif
- enddo
- enddo
- enddo
- enddo
- enddo
- enddo
- end select
- !---------------------------------------------------------------------------------------------------
- end subroutine Agrif_CheckMasknD
- !===================================================================================================
- !
- !===================================================================================================
- ! subroutine CalculNewValTempP
- !
- !> Called in the procedure #Agrif_InterpnD to recalculate the value of the parent grid variable
- !! when this one is equal to Agrif_SpecialValue.
- !---------------------------------------------------------------------------------------------------
- subroutine CalculNewValTempP ( indic, tempP, parent, ppbtab, ppetab, noraftab, nbdim )
- !---------------------------------------------------------------------------------------------------
- integer, dimension(nbdim) :: indic
- type(Agrif_Variable), pointer :: tempP !< Part of the parent grid used for the interpolation of the child grid
- type(Agrif_Variable), pointer :: parent !< The parent grid
- integer, dimension(nbdim) :: ppbtab, ppetab
- logical, dimension(nbdim) :: noraftab
- integer :: nbdim
- !
- integer :: i,ii,iii,jj,kk,ll,mm,nn
- integer, dimension(nbdim) :: imin,imax,idecal
- integer :: nbvals
- real :: res
- real :: valparent
- integer :: ValMax
- logical :: firsttest
- !
- ValMax = 1
- do iii = 1,nbdim
- if (.NOT.noraftab(iii)) then
- ValMax = max(ValMax,ppetab(iii)-indic(iii))
- ValMax = max(ValMax,indic(iii)-ppbtab(iii))
- endif
- enddo
- !
- Valmax = min(Valmax,MaxSearch)
- !
- !CDIR NOVECTOR
- imin = indic
- !CDIR NOVECTOR
- imax = indic
- !
- i = 1
- firsttest = .TRUE.
- !
- do while (i <= ValMax)
- !
- if ( (i == 1).AND.(firsttest) ) i = Valmax
- !
- do iii = 1,nbdim
- if (.NOT.noraftab(iii)) then
- imin(iii) = max(indic(iii) - i,ppbtab(iii))
- imax(iii) = min(indic(iii) + i,ppetab(iii))
- if (firsttest) then
- if (indic(iii) > ppbtab(iii)) then
- !CDIR NOVECTOR
- idecal = indic
- idecal(iii) = idecal(iii)-1
- SELECT CASE(nbdim)
- CASE (1)
- if (tempP%array1(idecal(1) &
- ) == Agrif_SpecialValue) imin(iii) = imax(iii)
- CASE (2)
- if (tempP%array2(idecal(1), idecal(2) &
- ) == Agrif_SpecialValue) imin(iii) = imax(iii)
- CASE (3)
- if (tempP%array3(idecal(1), &
- idecal(2), idecal(3) &
- ) == Agrif_SpecialValue) imin(iii) = imax(iii)
- CASE (4)
- if (tempP%array4(idecal(1), idecal(2), &
- idecal(3), idecal(4) &
- ) == Agrif_SpecialValue) imin(iii) = imax(iii)
- CASE (5)
- if (tempP%array5(idecal(1), idecal(2), &
- idecal(3), idecal(4), &
- idecal(5) &
- ) == Agrif_SpecialValue) imin(iii) = imax(iii)
- CASE (6)
- if (tempP%array6(idecal(1), idecal(2), &
- idecal(3), idecal(4), &
- idecal(5), idecal(6) &
- ) == Agrif_SpecialValue) imin(iii) = imax(iii)
- END SELECT
- endif
- endif
- endif
- enddo
- !
- Res = 0.
- Nbvals = 0
- !
- SELECT CASE(nbdim)
- CASE (1)
- !CDIR ALTCODE
- !CDIR SHORTLOOP
- do ii = imin(1),imax(1)
- ValParent = parent%array1(ii)
- if ( ValParent /= Agrif_SpecialValue) then
- Res = Res + ValParent
- Nbvals = Nbvals + 1
- endif
- enddo
- !
- CASE (2)
- do jj = imin(2),imax(2)
- !CDIR ALTCODE
- !CDIR SHORTLOOP
- do ii = imin(1),imax(1)
- ValParent = parent%array2(ii,jj)
- if ( ValParent /= Agrif_SpecialValue) then
- Res = Res + ValParent
- Nbvals = Nbvals + 1
- endif
- enddo
- enddo
- CASE (3)
- do kk = imin(3),imax(3)
- do jj = imin(2),imax(2)
- !CDIR ALTCODE
- !CDIR SHORTLOOP
- do ii = imin(1),imax(1)
- ValParent = parent%array3(ii,jj,kk)
- if ( ValParent /= Agrif_SpecialValue) then
- Res = Res + ValParent
- Nbvals = Nbvals + 1
- endif
- enddo
- enddo
- enddo
- CASE (4)
- do ll = imin(4),imax(4)
- do kk = imin(3),imax(3)
- do jj = imin(2),imax(2)
- !CDIR ALTCODE
- !CDIR SHORTLOOP
- do ii = imin(1),imax(1)
- ValParent = parent%array4(ii,jj,kk,ll)
- if ( ValParent /= Agrif_SpecialValue) then
- Res = Res + ValParent
- Nbvals = Nbvals + 1
- endif
- enddo
- enddo
- enddo
- enddo
- CASE (5)
- do mm = imin(5),imax(5)
- do ll = imin(4),imax(4)
- do kk = imin(3),imax(3)
- do jj = imin(2),imax(2)
- !CDIR ALTCODE
- !CDIR SHORTLOOP
- do ii = imin(1),imax(1)
- ValParent = parent%array5(ii,jj,kk,ll,mm)
- if ( ValParent /= Agrif_SpecialValue) then
- Res = Res + ValParent
- Nbvals = Nbvals + 1
- endif
- enddo
- enddo
- enddo
- enddo
- enddo
- CASE (6)
- do nn = imin(6),imax(6)
- do mm = imin(5),imax(5)
- do ll = imin(4),imax(4)
- do kk = imin(3),imax(3)
- do jj = imin(2),imax(2)
- !CDIR ALTCODE
- !CDIR SHORTLOOP
- do ii = imin(1),imax(1)
- ValParent = parent%array6(ii,jj,kk,ll,mm,nn)
- if ( ValParent /= Agrif_SpecialValue) then
- Res = Res + ValParent
- Nbvals = Nbvals + 1
- endif
- enddo
- enddo
- enddo
- enddo
- enddo
- enddo
- END SELECT
- !
- if (Nbvals > 0) then
- if (firsttest) then
- firsttest = .FALSE.
- i=1
- cycle
- endif
- SELECT CASE(nbdim)
- CASE (1)
- tempP%array1(indic(1)) = Res/Nbvals
- CASE (2)
- tempP%array2(indic(1), indic(2)) = Res/Nbvals
- CASE (3)
- tempP%array3(indic(1), indic(2), &
- indic(3)) = Res/Nbvals
- CASE (4)
- tempP%array4(indic(1), indic(2), &
- indic(3), indic(4)) = Res/Nbvals
- CASE (5)
- tempP%array5(indic(1), indic(2), &
- indic(3), indic(4), &
- indic(5)) = Res/Nbvals
- CASE (6)
- tempP%array6(indic(1), indic(2), &
- indic(3), indic(4), &
- indic(5), indic(6)) = Res/Nbvals
- END SELECT
- exit
- else
- if (firsttest) exit
- i = i + 1
- endif
- !
- enddo
- !---------------------------------------------------------------------------------------------------
- end subroutine CalculNewValTempP
- !===================================================================================================
- !
- !===================================================================================================
- ! subroutine CalculNewValTempP3D
- !
- !> Called in the procedure #Agrif_InterpnD to recalculate the value of the parent grid variable
- !! when this one is equal to Agrif_SpecialValue.
- !---------------------------------------------------------------------------------------------------
- subroutine CalculNewValTempP3D ( indic, tempP, parent, ppbtab, ppetab, noraftab, &
- MaxSearch, Agrif_SpecialValue )
- !---------------------------------------------------------------------------------------------------
- integer, parameter :: nbdim = 3
- integer, dimension(nbdim) :: indic
- integer, dimension(nbdim) :: ppbtab, ppetab
- logical, dimension(nbdim) :: noraftab
- integer :: MaxSearch
- real :: Agrif_SpecialValue
- real, dimension(ppbtab(1):ppetab(1), &
- ppbtab(2):ppetab(2), &
- ppbtab(3):ppetab(3)) &
- :: tempP, parent !< Part of the parent grid used for
- !< the interpolation of the child grid
- !
- integer :: i,ii,iii,jj,kk
- integer, dimension(nbdim) :: imin,imax,idecal
- integer :: Nbvals
- real :: Res
- real :: ValParent
- integer :: ValMax
- logical :: Existunmasked
- !
- ValMax = 1
- !CDIR NOVECTOR
- do iii = 1,nbdim
- if (.NOT.noraftab(iii)) then
- ValMax = max(ValMax,ppetab(iii)-indic(iii))
- ValMax = max(ValMax,indic(iii)-ppbtab(iii))
- endif
- enddo
- !
- Valmax = min(Valmax,MaxSearch)
- !
- !CDIR NOVECTOR
- imin = indic
- !CDIR NOVECTOR
- imax = indic
- !CDIR NOVECTOR
- idecal = indic
- i = Valmax
- !
- do iii = 1,nbdim
- if (.NOT.noraftab(iii)) then
- imin(iii) = max(indic(iii) - i,ppbtab(iii))
- imax(iii) = min(indic(iii) + i,ppetab(iii))
- if (indic(iii) > ppbtab(iii)) then
- idecal(iii) = idecal(iii)-1
- if (tempP(idecal(1),idecal(2),idecal(3)) == Agrif_SpecialValue) then
- imin(iii) = imax(iii)
- endif
- idecal(iii) = idecal(iii)+1
- endif
- endif
- enddo
- !
- Existunmasked = .FALSE.
- !
- do kk = imin(3),imax(3)
- do jj = imin(2),imax(2)
- !CDIR NOVECTOR
- do ii = imin(1),imax(1)
- if ( parent(ii,jj,kk) /= Agrif_SpecialValue) then
- Existunmasked = .TRUE.
- exit
- endif
- enddo
- enddo
- enddo
- !
- if (.Not.Existunmasked) return
- !
- i = 1
- !
- do while(i <= ValMax)
- !
- do iii = 1 , nbdim
- if (.NOT.noraftab(iii)) then
- imin(iii) = max(indic(iii) - i,ppbtab(iii))
- imax(iii) = min(indic(iii) + i,ppetab(iii))
- endif
- enddo
- !
- Res = 0.
- Nbvals = 0
- !
- do kk = imin(3),imax(3)
- do jj = imin(2),imax(2)
- !CDIR NOVECTOR
- do ii = imin(1),imax(1)
- ValParent = parent(ii,jj,kk)
- if ( ValParent /= Agrif_SpecialValue) then
- Res = Res + ValParent
- Nbvals = Nbvals + 1
- endif
- enddo
- enddo
- enddo
- !
- if (Nbvals > 0) then
- tempP(indic(1),indic(2),indic(3)) = Res/Nbvals
- exit
- else
- i = i + 1
- endif
- enddo
- !---------------------------------------------------------------------------------------------------
- end subroutine CalculNewValTempP3D
- !===================================================================================================
- !
- !===================================================================================================
- ! subroutine CalculNewValTempP4D
- !
- !> Called in the procedure #Agrif_InterpnD to recalculate the value of the parent grid variable
- !! when this one is equal to Agrif_SpecialValue.
- !---------------------------------------------------------------------------------------------------
- subroutine CalculNewValTempP4D ( indic, tempP, parent, ppbtab, ppetab, noraftab, &
- MaxSearch, Agrif_SpecialValue )
- !---------------------------------------------------------------------------------------------------
- integer, parameter :: nbdim = 4
- integer, dimension(nbdim) :: indic
- integer, dimension(nbdim) :: ppbtab, ppetab
- logical, dimension(nbdim) :: noraftab
- integer :: MaxSearch
- real :: Agrif_SpecialValue
- real, dimension(ppbtab(1):ppetab(1), &
- ppbtab(2):ppetab(2), &
- ppbtab(3):ppetab(3), &
- ppbtab(4):ppetab(4)) &
- :: tempP, parent !< Part of the parent grid used for
- !< the interpolation of the child grid
- !
- integer :: i,ii,iii,jj,kk,ll
- integer, dimension(nbdim) :: imin,imax,idecal
- integer :: Nbvals
- real :: Res
- real :: ValParent
- integer :: ValMax
- !
- logical :: firsttest
- !
- ValMax = 1
- do iii = 1,nbdim
- if (.NOT.noraftab(iii)) then
- ValMax = max(ValMax,ppetab(iii)-indic(iii))
- ValMax = max(ValMax,indic(iii)-ppbtab(iii))
- endif
- enddo
- !
- Valmax = min(Valmax,MaxSearch)
- !
- imin = indic
- imax = indic
- !
- i = 1
- firsttest = .TRUE.
- idecal = indic
- !
- do while (i <= ValMax)
- !
- if ((i == 1).AND.(firsttest)) i = Valmax
- do iii = 1,nbdim
- if (.NOT.noraftab(iii)) then
- imin(iii) = max(indic(iii) - i,ppbtab(iii))
- imax(iii) = min(indic(iii) + i,ppetab(iii))
- if (firsttest) then
- if (indic(iii) > ppbtab(iii)) then
- idecal(iii) = idecal(iii)-1
- if (tempP(idecal(1),idecal(2),idecal(3),idecal(4)) == Agrif_SpecialValue) then
- imin(iii) = imax(iii)
- endif
- idecal(iii) = idecal(iii)+1
- endif
- endif
- endif
- enddo
- !
- Res = 0.
- Nbvals = 0
- !
- do ll = imin(4),imax(4)
- do kk = imin(3),imax(3)
- do jj = imin(2),imax(2)
- do ii = imin(1),imax(1)
- ValParent = parent(ii,jj,kk,ll)
- if ( ValParent /= Agrif_SpecialValue) then
- Res = Res + ValParent
- Nbvals = Nbvals + 1
- endif
- enddo
- enddo
- enddo
- enddo
- !
- if (Nbvals > 0) then
- if (firsttest) then
- firsttest = .FALSE.
- i=1
- cycle
- endif
- tempP(indic(1),indic(2),indic(3),indic(4)) = Res/Nbvals
- exit
- else
- if (firsttest) exit
- i = i + 1
- endif
- enddo
- !---------------------------------------------------------------------------------------------------
- end subroutine CalculNewValTempP4D
- !===================================================================================================
- !
- end module Agrif_Mask
|