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 agrif_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 agrif_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 | locind_child_left = 1 + agrif_int((xpos - s_child)/ds_child) |
---|
151 | |
---|
152 | do i = 1,np |
---|
153 | C |
---|
154 | |
---|
155 | C |
---|
156 | c if ((locind_child_left-1 < 1) |
---|
157 | c & .OR. (locind_child_left+1 > nc)) then |
---|
158 | C |
---|
159 | c x(i) = y(locind_child_left) |
---|
160 | C |
---|
161 | c else |
---|
162 | nbnonnuls = 0 |
---|
163 | Do ii = -coeffraf/2+locind_child_left+diffmod, |
---|
164 | & coeffraf/2+locind_child_left |
---|
165 | C |
---|
166 | IF (Agrif_UseSpecialValueInUpdate) THEN |
---|
167 | IF (y(ii) .NE. Agrif_SpecialValueFineGrid) THEN |
---|
168 | nbnonnuls = nbnonnuls + 1 |
---|
169 | x(i) = x(i) + y(ii) |
---|
170 | ENDIF |
---|
171 | ELSE |
---|
172 | x(i) = x(i) + y(ii) |
---|
173 | ENDIF |
---|
174 | End Do |
---|
175 | IF (Agrif_UseSpecialValueInUpdate) THEN |
---|
176 | IF (nbnonnuls .NE. 0) THEN |
---|
177 | x(i) = x(i)/nbnonnuls |
---|
178 | ELSE |
---|
179 | x(i) = Agrif_SpecialValueFineGrid |
---|
180 | ENDIF |
---|
181 | ELSE |
---|
182 | x(i) = x(i)/coeffraf |
---|
183 | ENDIF |
---|
184 | C |
---|
185 | c endif |
---|
186 | C |
---|
187 | c xpos = xpos + ds_parent |
---|
188 | locind_child_left = locind_child_left + coeffraf |
---|
189 | C |
---|
190 | enddo |
---|
191 | C |
---|
192 | Return |
---|
193 | C |
---|
194 | C |
---|
195 | End Subroutine average1d |
---|
196 | C |
---|
197 | C |
---|
198 | C |
---|
199 | C ************************************************************************** |
---|
200 | CCC Subroutine Full_weighting1d |
---|
201 | C ************************************************************************** |
---|
202 | C |
---|
203 | Subroutine full_weighting1D(x,y,np,nc, |
---|
204 | & s_parent,s_child,ds_parent,ds_child, |
---|
205 | & coeffraf,locind_child_left) |
---|
206 | C |
---|
207 | CCC Description: |
---|
208 | CCC Subroutine to do an update by full_weighting on a parent grid (vector x) |
---|
209 | CCC from its child grid (vector y). |
---|
210 | C |
---|
211 | C Arguments |
---|
212 | INTEGER :: np,nc |
---|
213 | REAL, DIMENSION(np) :: x |
---|
214 | REAL, DIMENSION(nc) :: y |
---|
215 | REAL :: s_parent,s_child |
---|
216 | REAL :: ds_parent,ds_child |
---|
217 | C |
---|
218 | C Local variables |
---|
219 | INTEGER :: i,locind_child_left,coeffraf |
---|
220 | REAL :: xpos,sumweight,weight |
---|
221 | INTEGER :: ii,diffmod |
---|
222 | REAL :: xposfin |
---|
223 | INTEGER :: it1,it2 |
---|
224 | INTEGER :: i1,i2 |
---|
225 | REAL :: invsumweight |
---|
226 | REAL :: weights(-(coeffraf-1):coeffraf-1) |
---|
227 | |
---|
228 | C |
---|
229 | C |
---|
230 | if (coeffraf == 1) then |
---|
231 | C |
---|
232 | x(1:np) = y(locind_child_left:locind_child_left+np-1) |
---|
233 | C |
---|
234 | return |
---|
235 | C |
---|
236 | endif |
---|
237 | C |
---|
238 | xpos = s_parent |
---|
239 | |
---|
240 | x = 0. |
---|
241 | |
---|
242 | xposfin = s_child + ds_child * (locind_child_left - 1) |
---|
243 | IF (abs(xposfin - xpos).LT.0.001) THEN |
---|
244 | diffmod = 0 |
---|
245 | ELSE |
---|
246 | diffmod = 1 |
---|
247 | ENDIF |
---|
248 | C |
---|
249 | |
---|
250 | it1 = -(coeffraf-1) |
---|
251 | i1 = -(coeffraf-1)+locind_child_left+diffmod |
---|
252 | i2 = 2*coeffraf - 2 |
---|
253 | |
---|
254 | invsumweight=1./coeffraf**2 |
---|
255 | do i=-(coeffraf-1),0 |
---|
256 | weights(i) = invsumweight*(coeffraf + i) |
---|
257 | enddo |
---|
258 | do i=1,coeffraf-1 |
---|
259 | weights(i) = invsumweight*(coeffraf - i) |
---|
260 | enddo |
---|
261 | |
---|
262 | sumweight = 0 |
---|
263 | do i = 1,np |
---|
264 | C |
---|
265 | it2 = it1 |
---|
266 | Do ii = i1,i1+i2 |
---|
267 | C |
---|
268 | IF (Agrif_UseSpecialValueInUpdate) THEN |
---|
269 | IF (y(ii) .NE. Agrif_SpecialValueFineGrid) THEN |
---|
270 | x(i) = x(i) + weights(it2)*y(ii) |
---|
271 | sumweight = sumweight+weights(it2) |
---|
272 | ENDIF |
---|
273 | ELSE |
---|
274 | x(i) = x(i) + weights(it2)*y(ii) |
---|
275 | ENDIF |
---|
276 | |
---|
277 | it2 = it2+1 |
---|
278 | End Do |
---|
279 | |
---|
280 | IF (Agrif_UseSpecialValueInUpdate) THEN |
---|
281 | IF (sumweight .NE. 0.) THEN |
---|
282 | x(i) = x(i)/sumweight |
---|
283 | sumweight = 0 |
---|
284 | ELSE |
---|
285 | x(i) = Agrif_SpecialValueFineGrid |
---|
286 | ENDIF |
---|
287 | ENDIF |
---|
288 | |
---|
289 | i1 = i1 + coeffraf |
---|
290 | C |
---|
291 | enddo |
---|
292 | C |
---|
293 | Return |
---|
294 | C |
---|
295 | C |
---|
296 | End Subroutine full_weighting1D |
---|
297 | |
---|
298 | C |
---|
299 | End module AGRIF_updatebasic |
---|