Scrambler  1
layout_control.f90
Go to the documentation of this file.
00001 MODULE LayoutControl
00002    USE LayoutDeclarations
00003    USE LayoutComms
00004    USE GlobalDeclarations
00005    USE CommunicationDeclarations
00006    USE SlopeLim
00007    USE PFFT
00008    IMPLICIT NONE
00009 
00010    INTERFACE ProlongateLayout
00011       MODULE PROCEDURE ProlongateLayoutC, ProlongateLayoutR
00012    END INTERFACE ProlongateLayout
00013 
00014 
00015 CONTAINS
00016    ! Subroutine that takes a layout object that has data - and increases the level by 1 via prolongation
00017    SUBROUTINE ProlongateLayoutC(layout, data, method, FieldID)
00018       TYPE(PFFTPlanDef), POINTER :: plan, newplan
00019       TYPE(LayoutDef), POINTER :: layout
00020       TYPE(LayoutDef), POINTER :: newlayout
00021       TYPE(LayoutDef), POINTER :: parentlayout
00022       INTEGER :: method
00023       INTEGER :: FieldID(:)
00024       INTEGER, DIMENSION(3,2) :: mB, mC
00025       COMPLEX(8), DIMENSION(:,:,:,:), POINTER :: data, newdata, parentdata
00026       REAL(8), DIMENSION(:,:,:), POINTER :: temp_real, temp_cmplx
00027       INTEGER :: i, nGhost
00028 
00029 
00030       !life gets more complicated if we use an arbitrary new layout instead of just prolongating the one we have...
00031       ALLOCATE(newlayout)
00032       ALLOCATE(newlayout%mB(0:MPI_NP-1, 3, 2))
00033       newlayout%level=layout%level+1
00034       DO i=0, MPI_NP-1
00035          newlayout%mB(i,:,:)=LevelUp(layout%mB(i,:,:), layout%level)
00036       END DO
00037       mB=newlayout%mB(MPI_ID,:,:)
00038       ALLOCATE(newdata(mB(1,1):mB(1,2), mB(2,1):mB(2,2), mB(3,1):mB(3,2), size(data, 4)))
00039 
00040 
00041 
00042       IF (method == SPECTRAL_PROLONGATION) THEN
00043          !We need to take our layout - map it to a PFFT layout
00044          !And take our new layout and map it to a PFFT layout
00045          !Then load data into the low res PFFT layout and do the transform
00046          !Then map the transformed data from the old PFFT layout to the new PFFT layout
00047          !And then transform back to the new data set
00048          mC(:,1)=minval(layout%mB(:,:,1),1)
00049          mC(:,2)=maxval(layout%mB(:,:,2),1)
00050          CALL CreatePlan(plan,layout%level, mC, size(data,4))
00051          CALL TransferLayoutsC(layout, plan%layouts(1)%p, data, plan%data)
00052          CALL ExecutePlan(plan, FORWARD)
00053 
00054          CALL CreatePlan(newplan,newlayout%level, LevelUp(mC,layout%level), size(data,4))
00055 
00056 
00057          CALL SpectralProlongation(plan, newplan)
00058 
00059 
00060 
00061          !Now we need to take plan%data and map it to newplan%data and add phase shifts
00062 
00063          CALL ExecutePlan(newplan, BACKWARD)
00064          CALL TransferLayoutsC(newplan%layouts(1)%p, newlayout, newplan%data, newdata)
00065          CALL DestroyPlan(plan)
00066          CALL DestroyPlan(newplan)
00067 
00068       ELSE
00069          ALLOCATE(temp_real(mB(1,1):mB(1,2), mB(2,1):mB(2,2), mB(3,1):mB(3,2)))
00070          ALLOCATE(temp_cmplx(mB(1,1):mB(1,2), mB(2,1):mB(2,2), mB(3,1):mB(3,2)))
00071 
00072          nGhost=GetnGhost(method)
00073          IF (nGhost > 0) THEN !need to create a larger layout with ghost zones
00074             ALLOCATE(parentlayout)
00075             ALLOCATE(parentlayout%mB(0:MPI_NP-1,3,2))
00076             parentlayout%level=layout%level
00077             parentlayout%mB=layout%mB
00078             DO i=0, MPI_NP-1
00079                parentlayout%mB(i,:,:)=expand(parentlayout%mB(i,:,:), nGhost)
00080             END DO
00081 
00082             mB=parentlayout%mB(MPI_ID,:,:)
00083             ALLOCATE(parentdata(mB(1,1):mB(1,2), mB(2,1):mB(2,2), mB(3,1):mB(3,2), size(data, 4)))
00084 
00085             parentdata=0
00086             !now fill new data with fields so that external ghost zones will be populated
00087             !        DO i=0, parentlayout%level
00088             !           CALL LoadFieldIntoLayout(parentlayout, parentdata, FieldID, parentlayout%level)
00089             CALL LoadFieldIntoLayout(parentlayout, parentdata, FieldID)
00090             !        END DO
00091             !and then transfer previous data set (potentially prolongated)
00092             CALL TransferLayoutsC(layout, parentlayout, data, parentdata)
00093          ELSE
00094             parentdata=>data
00095             parentlayout=>layout
00096          END IF
00097 
00098          DO i=1,size(parentdata, 4)
00099             CALL ProlongateCellCenteredData(REAL(parentdata(:,:,:,i)), temp_real, levels(layout%level)%CoarsenRatio, nGhost, method)
00100             CALL ProlongateCellCenteredData(AIMAG(parentdata(:,:,:,i)), temp_cmplx, levels(layout%level)%CoarsenRatio, nGhost, method)
00101             newdata(:,:,:,i)=cmplx(temp_real, temp_cmplx, 8)
00102          END DO
00103 
00104          IF (nGhost > 0) THEN
00105             DEALLOCATE(parentdata)
00106             DEALLOCATE(parentlayout%mB)
00107             DEALLOCATE(parentlayout)
00108          END IF
00109 
00110          DEALLOCATE(temp_real, temp_cmplx)
00111       END IF
00112       DEALLOCATE(data)
00113       DEALLOCATE(layout%mB)
00114       DEALLOCATE(layout)
00115 
00116       data=>newdata    
00117       layout=>newlayout
00118 
00119 
00120 
00121 
00122    END SUBROUTINE ProlongateLayoutC
00123 
00124 
00125    ! Subroutine that takes a layout object that has data - and increases the level by 1 via prolongation
00126    SUBROUTINE ProlongateLayoutR(layout, data, method, FieldID)
00127       TYPE(LayoutDef), POINTER :: layout
00128       TYPE(LayoutDef), POINTER :: newlayout
00129       TYPE(LayoutDef), POINTER :: parentlayout
00130       INTEGER :: method
00131       INTEGER :: FieldID(:)
00132       INTEGER, DIMENSION(3,2) :: mB
00133       REAL(8), DIMENSION(:,:,:,:), POINTER :: data, newdata, parentdata
00134       INTEGER :: i, nGhost
00135 
00136       !life gets more complicated if we use an arbitrary new layout instead of just prolongating the one we have...
00137       ALLOCATE(newlayout)
00138       ALLOCATE(newlayout%mB(0:MPI_NP-1, 3, 2))
00139       newlayout%level=layout%level+1
00140       DO i=0, MPI_NP-1
00141          newlayout%mB(i,:,:)=LevelUp(layout%mB(i,:,:), layout%level)
00142       END DO
00143       mB=newlayout%mB(MPI_ID,:,:)
00144       ALLOCATE(newdata(mB(1,1):mB(1,2), mB(2,1):mB(2,2), mB(3,1):mB(3,2), size(data, 4)))
00145 
00146       nGhost=GetnGhost(method)
00147       IF (nGhost > 0) THEN !need to create a larger layout with ghost zones
00148          ALLOCATE(parentlayout)
00149          parentlayout%level=layout%level
00150          ALLOCATE(parentlayout%mB(0:MPI_NP-1,3,2))
00151          DO i=0, MPI_NP-1
00152             parentlayout%mB(i,:,:)=expand(parentlayout%mB(i,:,:), nGhost)
00153          END DO
00154          mB=parentlayout%mB(MPI_ID,:,:)
00155          ALLOCATE(parentdata(mB(1,1):mB(1,2), mB(2,1):mB(2,2), mB(3,1):mB(3,2), size(data, 4)))
00156          !now fill new data with fields so that external ghost zones will be populated
00157          CALL LoadFieldIntoLayout(parentlayout, parentdata, FieldID)
00158 
00159          !and then transfer previous data set (potentially prolongated)
00160          CALL TransferLayoutsR(layout, parentlayout, data, parentdata)
00161       ELSE
00162          parentdata=>data
00163          parentlayout=>layout
00164       END IF
00165       DO i=1,size(parentdata, 4)
00166          CALL ProlongateCellCenteredData(parentdata(:,:,:,i),newdata(:,:,:,i), levels(layout%level)%CoarsenRatio, nGhost, method)
00167       END DO
00168 
00169       IF (nGhost > 0) THEN
00170          DEALLOCATE(parentdata)
00171          DEALLOCATE(parentlayout%mB)
00172          DEALLOCATE(parentlayout)
00173       END IF
00174 
00175       DEALLOCATE(data)
00176       DEALLOCATE(layout%mB)
00177       DEALLOCATE(layout)
00178 
00179       data=>newdata    
00180       layout=>newlayout
00181 
00182 
00183    END SUBROUTINE ProlongateLayoutR
00184 END MODULE LayoutControl
 All Classes Files Functions Variables