1 | module Agrif_Variables |
---|
2 | ! |
---|
3 | use Agrif_CurgridFunctions |
---|
4 | ! |
---|
5 | implicit none |
---|
6 | ! |
---|
7 | #if defined AGRIF_MPI |
---|
8 | interface |
---|
9 | subroutine Agrif_InvLoc ( indloc, proc_id, dir, indglob ) |
---|
10 | integer, intent(in) :: indloc !< local index |
---|
11 | integer, intent(in) :: proc_id !< rank of the proc calling this function |
---|
12 | integer, intent(in) :: dir !< direction of the index |
---|
13 | integer, intent(out) :: indglob !< global index |
---|
14 | end subroutine Agrif_InvLoc |
---|
15 | end interface |
---|
16 | private :: Agrif_InvLoc |
---|
17 | #endif |
---|
18 | |
---|
19 | contains |
---|
20 | ! |
---|
21 | !=================================================================================================== |
---|
22 | ! subroutine Agrif_Declare_Variable |
---|
23 | ! |
---|
24 | !> Declare a new variable profile |
---|
25 | !--------------------------------------------------------------------------------------------------- |
---|
26 | subroutine Agrif_Declare_Variable ( posvar, firstpoint, raf, lb, ub, varid, torestore ) |
---|
27 | !--------------------------------------------------------------------------------------------------- |
---|
28 | integer, dimension(:), intent(in) :: posvar !< position of the variable on the cell |
---|
29 | !< (1 for the border of the edge, 2 for the center) |
---|
30 | integer, dimension(:), intent(in) :: firstpoint !< index of the first point in the real domain |
---|
31 | character(*), dimension(:), intent(in) :: raf !< Array indicating the type of dimension (space or not) |
---|
32 | !< for each of them |
---|
33 | integer, dimension(:), intent(in) :: lb !< Lower bounds of the array |
---|
34 | integer, dimension(:), intent(in) :: ub !< Upper bounds of the array |
---|
35 | integer, intent(out) :: varid !< Id number of the newly created variable |
---|
36 | logical, optional, intent(in) :: torestore !< Indicates if the array restore is used |
---|
37 | ! |
---|
38 | type(Agrif_Variables_List), pointer :: new_varlist |
---|
39 | type(Agrif_Variable), pointer :: var |
---|
40 | integer :: nbdim |
---|
41 | logical :: restore |
---|
42 | #if defined AGRIF_MPI |
---|
43 | include 'mpif.h' |
---|
44 | integer :: i |
---|
45 | integer,dimension(6,2) :: iminmaxg, lubglob |
---|
46 | integer :: code |
---|
47 | #endif |
---|
48 | |
---|
49 | restore = .FALSE. |
---|
50 | if ( Agrif_Mygrid % ngridstep /= 0 ) then |
---|
51 | if (present(torestore)) restore = torestore |
---|
52 | endif |
---|
53 | ! |
---|
54 | nbdim = SIZE(posvar) |
---|
55 | ! |
---|
56 | allocate(new_varlist) |
---|
57 | allocate(new_varlist % var) |
---|
58 | |
---|
59 | var => new_varlist % var |
---|
60 | |
---|
61 | allocate(var % posvar(nbdim)) |
---|
62 | allocate(var % interptab(nbdim)) |
---|
63 | ! |
---|
64 | var % interptab = raf |
---|
65 | var % nbdim = nbdim |
---|
66 | var % posvar = posvar |
---|
67 | var % point(1:nbdim) = firstpoint |
---|
68 | var % restore = restore |
---|
69 | |
---|
70 | var % lb(1:nbdim) = lb(1:nbdim) |
---|
71 | var % ub(1:nbdim) = ub(1:nbdim) |
---|
72 | |
---|
73 | #if defined AGRIF_MPI |
---|
74 | do i = 1,nbdim |
---|
75 | call Agrif_Invloc(lb(i), Agrif_Procrank, i, iminmaxg(i,1)) |
---|
76 | call Agrif_Invloc(ub(i), Agrif_Procrank, i, iminmaxg(i,2)) |
---|
77 | enddo |
---|
78 | ! |
---|
79 | iminmaxg(1:nbdim,2) = - iminmaxg(1:nbdim,2) |
---|
80 | call MPI_ALLREDUCE(iminmaxg(1:nbdim,:), lubglob(1:nbdim,:), 2*nbdim, MPI_INTEGER,MPI_MIN,Agrif_mpi_comm, code) |
---|
81 | lubglob(1:nbdim,2) = - lubglob(1:nbdim,2) |
---|
82 | var % lbglob(1:nbdim) = lubglob(1:nbdim,1) |
---|
83 | var % ubglob(1:nbdim) = lubglob(1:nbdim,2) |
---|
84 | #else |
---|
85 | var % lbglob(1:nbdim) = var % lb(1:nbdim) |
---|
86 | var % ubglob(1:nbdim) = var % ub(1:nbdim) |
---|
87 | #endif |
---|
88 | |
---|
89 | if ( restore ) then |
---|
90 | select case(nbdim) |
---|
91 | case(1) |
---|
92 | allocate(var % Restore1D(lb(1):ub(1))) |
---|
93 | var % Restore1D = 0 |
---|
94 | case(2) |
---|
95 | allocate(var % Restore2D(lb(1):ub(1), & |
---|
96 | lb(2):ub(2))) |
---|
97 | var % Restore2D = 0 |
---|
98 | case(3) |
---|
99 | allocate(var % Restore3D(lb(1):ub(1), & |
---|
100 | lb(2):ub(2), & |
---|
101 | lb(3):ub(3))) |
---|
102 | var % Restore3D = 0 |
---|
103 | case(4) |
---|
104 | allocate(var % Restore4D(lb(1):ub(1), & |
---|
105 | lb(2):ub(2), & |
---|
106 | lb(3):ub(3), & |
---|
107 | lb(4):ub(4))) |
---|
108 | var % Restore4D = 0 |
---|
109 | case(5) |
---|
110 | allocate(var % Restore5D(lb(1):ub(1), & |
---|
111 | lb(2):ub(2), & |
---|
112 | lb(3):ub(3), & |
---|
113 | lb(4):ub(4), & |
---|
114 | lb(5):ub(5))) |
---|
115 | var % Restore5D = 0 |
---|
116 | end select |
---|
117 | endif |
---|
118 | |
---|
119 | new_varlist % next => Agrif_Curgrid % variables |
---|
120 | |
---|
121 | Agrif_Curgrid % variables => new_varlist |
---|
122 | Agrif_Curgrid % Nbvariables = Agrif_Curgrid % Nbvariables + 1 |
---|
123 | |
---|
124 | varid = -Agrif_Curgrid % Nbvariables |
---|
125 | |
---|
126 | var % parent_var => Agrif_Search_Variable(Agrif_Curgrid % parent, Agrif_Curgrid % nbvariables) |
---|
127 | var % root_var => Agrif_Search_Variable(Agrif_Mygrid, Agrif_Curgrid % nbvariables) |
---|
128 | !--------------------------------------------------------------------------------------------------- |
---|
129 | end subroutine Agrif_Declare_Variable |
---|
130 | !=================================================================================================== |
---|
131 | ! |
---|
132 | !=================================================================================================== |
---|
133 | ! function Agrif_Search_Variable |
---|
134 | ! |
---|
135 | !> Returns a pointer to the variable varid for the grid grid. |
---|
136 | !--------------------------------------------------------------------------------------------------- |
---|
137 | function Agrif_Search_Variable ( grid, varid ) result(outvar) |
---|
138 | !--------------------------------------------------------------------------------------------------- |
---|
139 | type(Agrif_Grid), pointer :: grid !< Pointer on the current grid. |
---|
140 | integer, intent(in) :: varid !< ID number of the variable we are looking for. |
---|
141 | ! |
---|
142 | type(Agrif_Variable), pointer :: outvar |
---|
143 | type(Agrif_Variables_List), pointer :: parcours |
---|
144 | integer :: nb, varidinv |
---|
145 | ! |
---|
146 | if ( .not.associated(grid)) then |
---|
147 | outvar => NULL() |
---|
148 | return |
---|
149 | endif |
---|
150 | ! |
---|
151 | parcours => grid % variables |
---|
152 | |
---|
153 | if (.not. associated(parcours)) then ! can occur on the grand mother grid |
---|
154 | outvar => NULL() ! during the first call by agrif_mygrid |
---|
155 | return |
---|
156 | endif |
---|
157 | |
---|
158 | |
---|
159 | varidinv = 1 + grid % nbvariables - varid |
---|
160 | |
---|
161 | do nb = 1,varidinv-1 |
---|
162 | parcours => parcours % next |
---|
163 | enddo |
---|
164 | |
---|
165 | outvar => parcours % var |
---|
166 | |
---|
167 | !--------------------------------------------------------------------------------------------------- |
---|
168 | end function Agrif_Search_variable |
---|
169 | !=================================================================================================== |
---|
170 | ! |
---|
171 | end module Agrif_Variables |
---|