1 | ! |
---|
2 | ! $Id$ |
---|
3 | ! |
---|
4 | C AGRIF (Adaptive Grid Refinement In Fortran) |
---|
5 | C |
---|
6 | C Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr) |
---|
7 | C Christophe Vouland (Christophe.Vouland@imag.fr) |
---|
8 | C |
---|
9 | C This program is free software; you can redistribute it and/or modify |
---|
10 | C it under the terms of the GNU General Public License as published by |
---|
11 | C the Free Software Foundation; either version 2 of the License, or |
---|
12 | C (at your option) any later version. |
---|
13 | C |
---|
14 | C This program is distributed in the hope that it will be useful, |
---|
15 | C but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | C MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | C GNU General Public License for more details. |
---|
18 | C |
---|
19 | C You should have received a copy of the GNU General Public License |
---|
20 | C along with this program; if not, write to the Free Software |
---|
21 | C Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
22 | C |
---|
23 | C |
---|
24 | C |
---|
25 | CCC Module Agrif_Updatebasic |
---|
26 | C |
---|
27 | C |
---|
28 | Module Agrif_Updatebasic |
---|
29 | C |
---|
30 | CCC Description: |
---|
31 | CCC Module containing different procedures of update (copy,average, |
---|
32 | CCC full_weighting) used in the Agrif_Update module. |
---|
33 | C |
---|
34 | C Modules used: |
---|
35 | C |
---|
36 | USE Agrif_types |
---|
37 | |
---|
38 | IMPLICIT NONE |
---|
39 | C |
---|
40 | |
---|
41 | CONTAINS |
---|
42 | C Define procedures contained in this module |
---|
43 | C |
---|
44 | C |
---|
45 | C |
---|
46 | C ************************************************************************** |
---|
47 | CCC Subroutine Copy1d |
---|
48 | C ************************************************************************** |
---|
49 | C |
---|
50 | Subroutine copy1d(x,y,np,nc, |
---|
51 | & s_parent,s_child,ds_parent,ds_child) |
---|
52 | C |
---|
53 | CCC Description: |
---|
54 | CCC Subroutine to do a copy on a parent grid (vector x) from its child grid |
---|
55 | CCC (vector y). |
---|
56 | C |
---|
57 | CC Method: |
---|
58 | C |
---|
59 | C Declarations: |
---|
60 | C |
---|
61 | |
---|
62 | C |
---|
63 | C Arguments |
---|
64 | INTEGER :: np,nc |
---|
65 | REAL, DIMENSION(np) :: x |
---|
66 | REAL, DIMENSION(nc) :: y |
---|
67 | REAL :: s_parent,s_child |
---|
68 | REAL :: ds_parent,ds_child |
---|
69 | C |
---|
70 | C Local variables |
---|
71 | INTEGER :: i,locind_child_left,coeffraf |
---|
72 | C |
---|
73 | C |
---|
74 | coeffraf = nint(ds_parent/ds_child) |
---|
75 | C |
---|
76 | if (coeffraf == 1) then |
---|
77 | C |
---|
78 | locind_child_left = 1 + nint((s_parent - s_child)/ds_child) |
---|
79 | C |
---|
80 | x(1:np) = y(locind_child_left:locind_child_left+np-1) |
---|
81 | C |
---|
82 | return |
---|
83 | C |
---|
84 | endif |
---|
85 | C |
---|
86 | |
---|
87 | locind_child_left = 1 + nint((s_parent - s_child)/ds_child) |
---|
88 | |
---|
89 | do i = 1,np |
---|
90 | C |
---|
91 | x(i) = y(locind_child_left) |
---|
92 | C |
---|
93 | locind_child_left = locind_child_left + coeffraf |
---|
94 | C |
---|
95 | enddo |
---|
96 | |
---|
97 | C |
---|
98 | Return |
---|
99 | C |
---|
100 | C |
---|
101 | End Subroutine copy1d |
---|
102 | C |
---|
103 | C |
---|
104 | C |
---|
105 | C ************************************************************************** |
---|
106 | CCC Subroutine Average1d |
---|
107 | C ************************************************************************** |
---|
108 | C |
---|
109 | Subroutine average1d(x,y,np,nc, |
---|
110 | & s_parent,s_child,ds_parent,ds_child) |
---|
111 | C |
---|
112 | CCC Description: |
---|
113 | CCC Subroutine to do an update by average on a parent grid (vector x)from its |
---|
114 | CCC child grid (vector y). |
---|
115 | C |
---|
116 | C Arguments |
---|
117 | INTEGER :: np,nc |
---|
118 | REAL, DIMENSION(np) :: x |
---|
119 | REAL, DIMENSION(nc) :: y |
---|
120 | REAL :: s_parent,s_child |
---|
121 | REAL :: ds_parent,ds_child |
---|
122 | C |
---|
123 | C Local variables |
---|
124 | INTEGER :: i,locind_child_left,coeffraf,ii |
---|
125 | REAL :: xpos |
---|
126 | INTEGER :: nbnonnuls |
---|
127 | INTEGER :: diffmod |
---|
128 | C |
---|
129 | C |
---|
130 | coeffraf = nint(ds_parent/ds_child) |
---|
131 | C |
---|
132 | if (coeffraf == 1) then |
---|
133 | C |
---|
134 | locind_child_left = 1 + nint((s_parent - s_child)/ds_child) |
---|
135 | C |
---|
136 | x(1:np) = y(locind_child_left:locind_child_left+np-1) |
---|
137 | C |
---|
138 | return |
---|
139 | C |
---|
140 | endif |
---|
141 | C |
---|
142 | xpos = s_parent |
---|
143 | |
---|
144 | x = 0. |
---|
145 | C |
---|
146 | diffmod = 0 |
---|
147 | |
---|
148 | IF ( mod(coeffraf,2) == 0 ) diffmod = 1 |
---|
149 | |
---|
150 | do i = 1,np |
---|
151 | C |
---|
152 | locind_child_left = 1 + agrif_int((xpos - s_child)/ds_child) |
---|
153 | C |
---|
154 | if ((locind_child_left-1 < 1) |
---|
155 | & .OR. (locind_child_left+1 > nc)) then |
---|
156 | C |
---|
157 | x(i) = y(locind_child_left) |
---|
158 | C |
---|
159 | else |
---|
160 | nbnonnuls = 0 |
---|
161 | Do ii = -coeffraf/2+locind_child_left+diffmod, |
---|
162 | & coeffraf/2+locind_child_left |
---|
163 | C |
---|
164 | IF (Agrif_UseSpecialValueInUpdate) THEN |
---|
165 | IF (y(ii) .NE. Agrif_SpecialValueFineGrid) THEN |
---|
166 | nbnonnuls = nbnonnuls + 1 |
---|
167 | x(i) = x(i) + y(ii) |
---|
168 | ENDIF |
---|
169 | ELSE |
---|
170 | x(i) = x(i) + y(ii) |
---|
171 | ENDIF |
---|
172 | End Do |
---|
173 | IF (Agrif_UseSpecialValueInUpdate) THEN |
---|
174 | IF (nbnonnuls .NE. 0) THEN |
---|
175 | x(i) = x(i)/nbnonnuls |
---|
176 | ELSE |
---|
177 | x(i) = Agrif_SpecialValueFineGrid |
---|
178 | ENDIF |
---|
179 | ELSE |
---|
180 | x(i) = x(i)/coeffraf |
---|
181 | ENDIF |
---|
182 | C |
---|
183 | endif |
---|
184 | C |
---|
185 | xpos = xpos + ds_parent |
---|
186 | C |
---|
187 | enddo |
---|
188 | C |
---|
189 | Return |
---|
190 | C |
---|
191 | C |
---|
192 | End Subroutine average1d |
---|
193 | C |
---|
194 | C |
---|
195 | C |
---|
196 | C ************************************************************************** |
---|
197 | CCC Subroutine Full_weighting1d |
---|
198 | C ************************************************************************** |
---|
199 | C |
---|
200 | Subroutine full_weighting1D(x,y,np,nc, |
---|
201 | & s_parent,s_child,ds_parent,ds_child) |
---|
202 | C |
---|
203 | CCC Description: |
---|
204 | CCC Subroutine to do an update by full_weighting on a parent grid (vector x) |
---|
205 | CCC from its child grid (vector y). |
---|
206 | C |
---|
207 | C Arguments |
---|
208 | INTEGER :: np,nc |
---|
209 | REAL, DIMENSION(np) :: x |
---|
210 | REAL, DIMENSION(nc) :: y |
---|
211 | REAL :: s_parent,s_child |
---|
212 | REAL :: ds_parent,ds_child |
---|
213 | C |
---|
214 | C Local variables |
---|
215 | INTEGER :: i,locind_child_left,coeffraf |
---|
216 | REAL :: xpos |
---|
217 | C |
---|
218 | C |
---|
219 | coeffraf = nint(ds_parent/ds_child) |
---|
220 | C |
---|
221 | if (coeffraf == 1) then |
---|
222 | C |
---|
223 | locind_child_left = 1 + nint((s_parent - s_child)/ds_child) |
---|
224 | C |
---|
225 | x(1:np) = y(locind_child_left:locind_child_left+np-1) |
---|
226 | C |
---|
227 | return |
---|
228 | C |
---|
229 | endif |
---|
230 | C |
---|
231 | IF (coeffraf .NE. 3) THEN |
---|
232 | print *,'FULL WEIGHTING NOT READY FOR COEFFRAF = 3' |
---|
233 | STOP |
---|
234 | ENDIF |
---|
235 | xpos = s_parent |
---|
236 | C |
---|
237 | do i = 1,np |
---|
238 | C |
---|
239 | locind_child_left = 1 + nint((xpos - s_child)/ds_child) |
---|
240 | C |
---|
241 | if ((locind_child_left-1 < 1) |
---|
242 | & .OR. (locind_child_left+1 > nc)) then |
---|
243 | C Agrif_UseSpecialValueInUpdate = .TRUE. |
---|
244 | x(i) = y(locind_child_left) |
---|
245 | C |
---|
246 | else |
---|
247 | C |
---|
248 | x(i) = (y(locind_child_left-1)+2.*y(locind_child_left)+ |
---|
249 | & y(locind_child_left+1))/4. |
---|
250 | C |
---|
251 | endif |
---|
252 | C |
---|
253 | xpos = xpos + ds_parent |
---|
254 | C |
---|
255 | enddo |
---|
256 | C |
---|
257 | Return |
---|
258 | C |
---|
259 | C |
---|
260 | End Subroutine full_weighting1D |
---|
261 | C |
---|
262 | C |
---|
263 | C |
---|
264 | End module AGRIF_updatebasic |
---|