1 | !> \file resol_adv_diff_2D-sept2009.f90 |
---|
2 | !!Resoud l equation adv-diffusion par une methode de relaxation |
---|
3 | !< |
---|
4 | |
---|
5 | !> \namespace reso_adv_diff_2D_vect |
---|
6 | !! Resoud l equation adv-diffusion par une methode de relaxation |
---|
7 | !! @note - passage du vecteur et de l epaisseur en dummy |
---|
8 | !! @note - epaisseur prescrite selon un masque |
---|
9 | !! @note use module3D_phy |
---|
10 | !! @todo essayer dans le futur la methode de Richard dUX/dx = H dU/dx + U dH/dx |
---|
11 | !< |
---|
12 | |
---|
13 | module reso_adv_diff_2D_vect |
---|
14 | |
---|
15 | use module3D_phy |
---|
16 | |
---|
17 | |
---|
18 | |
---|
19 | implicit none |
---|
20 | real :: omega !< parametre schema temporel de la resolution partie diffusion |
---|
21 | real :: mu_adv !< parametre schema temporel de la resolution advection |
---|
22 | real :: upwind !< schema spatial pour l'advection |
---|
23 | |
---|
24 | ! tableaux de travail. resolution M H = Frelax |
---|
25 | real,dimension(nx,ny) :: crelax !< diagnonale de M |
---|
26 | real,dimension(nx,ny) :: arelax !< sous diagonale selon x |
---|
27 | real,dimension(nx,ny) :: brelax !< sur diagonale selon x |
---|
28 | real,dimension(nx,ny) :: drelax !< sous diagonale selon y |
---|
29 | real,dimension(nx,ny) :: erelax !< sur diagonale selon y |
---|
30 | real,dimension(nx,ny) :: frelax !< vecteur |
---|
31 | real,dimension(nx,ny) :: c_west !< sur demi mailles Ux |
---|
32 | real,dimension(nx,ny) :: c_east !< sur demi mailles Ux |
---|
33 | real,dimension(nx,ny) :: c_north !< sur demi mailles Uy |
---|
34 | real,dimension(nx,ny) :: c_south !< sur demi mailles Uy |
---|
35 | |
---|
36 | real,dimension(nx,ny) :: bdx !< pente socle |
---|
37 | real,dimension(nx,ny) :: bdy !< pente socle |
---|
38 | |
---|
39 | real,dimension(nx,ny) :: hdx !< pente epaisseur |
---|
40 | real,dimension(nx,ny) :: hdy !< pente epaisseur |
---|
41 | |
---|
42 | |
---|
43 | |
---|
44 | |
---|
45 | integer, dimension(2) :: ijmax ! position de maxval |
---|
46 | integer :: iFAIL |
---|
47 | |
---|
48 | contains |
---|
49 | |
---|
50 | !> initialise init_reso_adv_diff_2D |
---|
51 | !! definition des parametres qui gerent la resolution |
---|
52 | !! @return omega, mu_adv, upwind |
---|
53 | |
---|
54 | subroutine init_reso_adv_diff_2D |
---|
55 | |
---|
56 | |
---|
57 | write(num_rep_42,*)'partie diffusive' |
---|
58 | write(num_rep_42,*)'le type de schema temporel diffusif depend de omega' |
---|
59 | write(num_rep_42,*)'0 -> explicite, 0.5 -> Crank-Nicolson' |
---|
60 | write(num_rep_42,*)'1 -> semi implicite, >1 -> over-implicite' |
---|
61 | |
---|
62 | ! over implicite propose par Hindmasrsh |
---|
63 | |
---|
64 | omega = 2.5 |
---|
65 | |
---|
66 | write(num_rep_42,*)'omega = ',omega |
---|
67 | |
---|
68 | write(num_rep_42,*) |
---|
69 | write(num_rep_42,*)'partie advective' |
---|
70 | write(num_rep_42,*)' le schéma temporel advectif dépend de mu' |
---|
71 | write(num_rep_42,*)'0 -> explicite, 0.5 -> Crank-Nicolson' |
---|
72 | write(num_rep_42,*)'1 -> semi implicite, >1 -> over-implicite' |
---|
73 | |
---|
74 | mu_adv=1. ! l'over implicite ne s'applique pas a l'equation advective |
---|
75 | write(num_rep_42,*)'mu_adv = ',mu_adv |
---|
76 | |
---|
77 | write(num_rep_42,*)' le schéma spatial dépend de upwind' |
---|
78 | write(num_rep_42,*)'1 -> schema upwind, 0.5 -> schema centre' |
---|
79 | |
---|
80 | upwind=1 |
---|
81 | |
---|
82 | write(num_rep_42,*)'upwind = ',upwind |
---|
83 | |
---|
84 | |
---|
85 | write(num_rep_42,*)'------------------------------------------------------' |
---|
86 | |
---|
87 | return |
---|
88 | end subroutine init_reso_adv_diff_2D |
---|
89 | !------------------------------------------------------------------ |
---|
90 | |
---|
91 | !> subroutine resol_adv_diff_2D_Hpresc |
---|
92 | !! definition des parametres qui gerent la resolution |
---|
93 | !! @param Dfx,Dfy termes diffusifs |
---|
94 | !! @param advx,advy termes advectifs |
---|
95 | !! @param vieuxH ancienne valeur de H |
---|
96 | !! @param H_presc la valeur H prescrit pour certains noeuds |
---|
97 | !! @param i_Hpresc le masque ou la valeur de H est prescrite |
---|
98 | !! @param bil le bilan pour la colonne |
---|
99 | !! @return newH la valeur de H apres le pas de temps |
---|
100 | |
---|
101 | subroutine resol_adv_diff_2D_vect(Dfx,Dfy,advx,advy,H_presc,i_Hpresc,bil,vieuxH,newH) |
---|
102 | |
---|
103 | implicit none |
---|
104 | |
---|
105 | real,dimension(nx,ny), intent(in) :: Dfx !< terme diffusif selon x |
---|
106 | real,dimension(nx,ny), intent(in) :: Dfy !< terme diffusif selon y |
---|
107 | real,dimension(nx,ny), intent(in) :: Advx !< terme advectif selon x |
---|
108 | real,dimension(nx,ny), intent(in) :: Advy !< terme advectif selon y |
---|
109 | real,dimension(nx,ny), intent(in) :: vieuxH !< ancienne valeur de H |
---|
110 | real,dimension(nx,ny), intent(out):: newH !< nouvelle valeur de H |
---|
111 | |
---|
112 | real,dimension(nx,ny), intent(in) :: bil !< bilan de masse pour la colonne |
---|
113 | |
---|
114 | real,dimension(nx,ny), intent(in) :: H_presc !< H value if prescribed |
---|
115 | integer,dimension(nx,ny), intent(in) :: i_Hpresc !< 1 if H is prescribed on this node, else 0 |
---|
116 | |
---|
117 | |
---|
118 | ! tableaux de travail. resolution M H = Frelax |
---|
119 | !!$real,dimension(nx,ny) :: crelax !< diagnonale de M |
---|
120 | !!$real,dimension(nx,ny) :: arelax !< sous diagonale selon x |
---|
121 | !!$real,dimension(nx,ny) :: brelax !< sur diagonale selon x |
---|
122 | !!$real,dimension(nx,ny) :: drelax !< sous diagonale selon y |
---|
123 | !!$real,dimension(nx,ny) :: erelax !< sur diagonale selon y |
---|
124 | !!$real,dimension(nx,ny) :: frelax !< vecteur |
---|
125 | !!$real,dimension(nx,ny) :: c_west !< sur demi mailles Ux |
---|
126 | !!$real,dimension(nx,ny) :: c_east !< sur demi mailles Ux |
---|
127 | !!$real,dimension(nx,ny) :: c_north !< sur demi mailles Uy |
---|
128 | !!$real,dimension(nx,ny) :: c_south !<sur demi mailles Ux |
---|
129 | |
---|
130 | !!$real,dimension(nx,ny) :: bdx !< pente socle |
---|
131 | !!$real,dimension(nx,ny) :: bdy !< pente socle |
---|
132 | !!$ |
---|
133 | !!$real,dimension(nx,ny) :: hdx !< pente epaisseur |
---|
134 | !!$real,dimension(nx,ny) :: hdy !< pente epaisseur |
---|
135 | |
---|
136 | real :: frdx,frdy !< pour calcul frelax : termes diffusion |
---|
137 | real :: fraxw,fraxe,frays,frayn !< termes advection |
---|
138 | |
---|
139 | real,dimension(nx,ny) :: deltah ! dans calcul relax |
---|
140 | real :: delh ! dans calcul relax |
---|
141 | real :: testh ! dans calcul relax |
---|
142 | |
---|
143 | logical :: stopp |
---|
144 | integer :: ntour |
---|
145 | real :: reste |
---|
146 | |
---|
147 | |
---|
148 | integer :: it1,it2,jt1,jt2 ! pour des tests d'asymétrie |
---|
149 | |
---|
150 | |
---|
151 | if (itracebug.eq.1) call tracebug(' Entree dans routine resolution_diffusion') |
---|
152 | |
---|
153 | |
---|
154 | ! calcul de bdx et hdx |
---|
155 | hdx(:,:)=dx1*(vieuxH(:,:)-eoshift(vieuxH(:,:),shift=-1,boundary=0.,dim=1)) |
---|
156 | hdy(:,:)=dx1*(vieuxH(:,:)-eoshift(vieuxH(:,:),shift=-1,boundary=0.,dim=2)) |
---|
157 | bdx(:,:)=dx1*(B(:,:)-eoshift(B(:,:),shift=-1,boundary=0.,dim=1)) |
---|
158 | bdy(:,:)=dx1*(B(:,:)-eoshift(B(:,:),shift=-1,boundary=0.,dim=2)) |
---|
159 | |
---|
160 | |
---|
161 | ! initialisations (qui feront aussi les conditions aux limites) |
---|
162 | Arelax(:,:)=0. |
---|
163 | Brelax(:,:)=0. |
---|
164 | Drelax(:,:)=0. |
---|
165 | Erelax(:,:)=0. |
---|
166 | Crelax(:,:)=1. |
---|
167 | Frelax(:,:)=0. |
---|
168 | DeltaH(:,:)=0. |
---|
169 | |
---|
170 | |
---|
171 | ! schema spatial |
---|
172 | |
---|
173 | if (upwind.eq.1.) then !schema amont |
---|
174 | |
---|
175 | where (Advx(:,:).ge.0.) |
---|
176 | c_west(:,:)=1. |
---|
177 | c_east(:,:)=0. |
---|
178 | elsewhere |
---|
179 | c_west(:,:)=0. |
---|
180 | c_east(:,:)=1. |
---|
181 | end where |
---|
182 | |
---|
183 | where (Advy(:,:).ge.0.) |
---|
184 | c_south(:,:)=1. |
---|
185 | c_north(:,:)=0. |
---|
186 | elsewhere |
---|
187 | c_south(:,:)=0. |
---|
188 | c_north(:,:)=1. |
---|
189 | end where |
---|
190 | |
---|
191 | else if (upwind.lt.1.) then ! schema centre |
---|
192 | c_west(:,:)=0.5 |
---|
193 | c_east(:,:)=0.5 |
---|
194 | c_south(:,:)=0.5 |
---|
195 | c_north(:,:)=0.5 |
---|
196 | end if |
---|
197 | |
---|
198 | ! attribution des elements des diagonales |
---|
199 | do j=2,ny-1 |
---|
200 | do i=2,nx-1 |
---|
201 | |
---|
202 | ! sous diagonale en x |
---|
203 | arelax(i,j)=-omega*Dtdx2*Dfx(i,j) & ! partie diffusive en x |
---|
204 | -mu_adv*dtdx*c_west(i,j)*Advx(i,j) ! partie advective en x |
---|
205 | |
---|
206 | ! sur diagonale en x |
---|
207 | brelax(i,j)=-omega*Dtdx2*Dfx(i+1,j) & ! partie diffusive |
---|
208 | +mu_adv*dtdx*c_east(i+1,j)*Advx(i+1,j) ! partie advective |
---|
209 | |
---|
210 | ! sous diagonale en y |
---|
211 | drelax(i,j)=-omega*Dtdx2*Dfy(i,j) & ! partie diffusive en y |
---|
212 | -mu_adv*dtdx*c_south(i,j)*Advy(i,j) ! partie advective en y |
---|
213 | |
---|
214 | ! sur diagonale en y |
---|
215 | erelax(i,j)=-omega*Dtdx2*Dfy(i,j+1) & ! partie diffusive |
---|
216 | +mu_adv*dtdx*c_north(i,j+1)*Advy(i,j+1) ! partie advective |
---|
217 | |
---|
218 | |
---|
219 | |
---|
220 | ! diagonale |
---|
221 | crelax(i,j)=omega*Dtdx2*((Dfx(i+1,j)+Dfx(i,j)) & ! partie diffusive en x |
---|
222 | +(Dfy(i,j+1)+Dfy(i,j))) ! partie diffusive en y |
---|
223 | crelax(i,j)=crelax(i,j)+mu_adv*dtdx* & |
---|
224 | ( (c_west(i+1,j)*Advx(i+1,j)-c_east(i,j)*Advx(i,j)) & !partie advective en x |
---|
225 | +(c_south(i,j+1)*Advy(i,j+1)-c_north(i,j)*Advy(i,j))) !partie advective en y |
---|
226 | crelax(i,j)=1.+crelax(i,j) ! partie temporelle |
---|
227 | |
---|
228 | |
---|
229 | ! terme du vecteur |
---|
230 | |
---|
231 | frdx= -Dfx(i,j) * (Bdx(i,j) +(1.-omega)*Hdx(i,j)) & ! partie diffusive en x |
---|
232 | +Dfx(i+1,j)*(Bdx(i+1,j)+(1.-omega)*Hdx(i+1,j)) |
---|
233 | |
---|
234 | frdy= -Dfy(i,j) * (Bdy(i,j) +(1.-omega)*Hdy(i,j)) & ! partie diffusive en y |
---|
235 | +Dfy(i,j+1)*(Bdy(i,j+1)+(1.-omega)*Hdy(i,j+1)) |
---|
236 | |
---|
237 | fraxw= -c_west(i,j)* Advx(i,j) * vieuxH(i-1,j) & ! partie advective en x |
---|
238 | +c_west(i+1,j)*Advx(i+1,j)*vieuxH(i,j) ! venant de l'west |
---|
239 | |
---|
240 | fraxe= -c_east(i,j) * Advx(i,j) * vieuxH(i,j) & ! partie advective en x |
---|
241 | +c_east(i+1,j)*Advx(i+1,j)*vieuxH(i+1,j) ! venant de l'est |
---|
242 | |
---|
243 | frays= -c_south(i,j) * Advy(i,j) * vieuxH(i,j-1) & ! partie advective en y |
---|
244 | +c_south(i,j+1)*Advy(i,j+1)*vieuxH(i,j) ! venant du sud |
---|
245 | |
---|
246 | frayn= -c_north(i,j) * Advy(i,j) * vieuxH(i,j) & ! partie advective en y |
---|
247 | +c_north(i,j+1)*Advy(i,j+1)*vieuxH(i,j+1) ! venant du nord |
---|
248 | |
---|
249 | |
---|
250 | |
---|
251 | frelax(i,j) = vieuxH(i,j) + Dt*bil(i,j) & |
---|
252 | + dtdx*(frdx+frdy) & ! termes lies a la diffusion (socle, omega) |
---|
253 | + (1.-mu_adv)*dtdx*((fraxw+fraxe)+(frays+frayn)) |
---|
254 | ! le dernier terme serait pour |
---|
255 | ! de l'over implicite en diffusion |
---|
256 | ! (en pratique pas utilise) |
---|
257 | end do |
---|
258 | end do |
---|
259 | |
---|
260 | |
---|
261 | where (i_hpresc(:,:) .eq.1) ! thickness prescribed |
---|
262 | frelax(:,:) = H_presc(:,:) |
---|
263 | arelax(:,:) = 0. |
---|
264 | brelax(:,:) = 0. |
---|
265 | crelax(:,:) = 1. |
---|
266 | drelax(:,:) = 0. |
---|
267 | erelax(:,:) = 0. |
---|
268 | end where |
---|
269 | |
---|
270 | stopp = .false. |
---|
271 | ntour=0 |
---|
272 | |
---|
273 | |
---|
274 | |
---|
275 | relax_loop: do while(.not.stopp) |
---|
276 | ntour=ntour+1 |
---|
277 | |
---|
278 | |
---|
279 | do j=2,ny-1 |
---|
280 | do i=2,nx-1 |
---|
281 | |
---|
282 | reste = (((arelax(i,j)*newH(i-1,j) +drelax(i,j)*newH(i,j-1)) & |
---|
283 | + (brelax(i,j)*newH(i+1,j) + erelax(i,j)*newH(i,j+1))) & |
---|
284 | + crelax(i,j)*newH(i,j))- frelax(i,j) |
---|
285 | |
---|
286 | if (ntour.eq.1) debug_3D(i,j,49)=(((arelax(i,j)*newH(i-1,j) +drelax(i,j)*newH(i,j-1)) & |
---|
287 | + (brelax(i,j)*newH(i+1,j) + erelax(i,j)*newH(i,j+1))) & |
---|
288 | + crelax(i,j)*newH(i,j)) |
---|
289 | |
---|
290 | |
---|
291 | deltaH(i,j) = reste/crelax(i,j) |
---|
292 | |
---|
293 | end do |
---|
294 | end do |
---|
295 | |
---|
296 | debug_3D(:,:,50)=arelax(:,:) |
---|
297 | debug_3D(:,:,51)=brelax(:,:) |
---|
298 | debug_3D(:,:,52)=crelax(:,:) |
---|
299 | debug_3D(:,:,53)=drelax(:,:) |
---|
300 | debug_3D(:,:,54)=erelax(:,:) |
---|
301 | debug_3D(:,:,55)=frelax(:,:) |
---|
302 | |
---|
303 | |
---|
304 | |
---|
305 | newH(:,:)=newH(:,:)-deltaH(:,:) |
---|
306 | |
---|
307 | |
---|
308 | |
---|
309 | |
---|
310 | ! critere d'arret: |
---|
311 | ! ---------------- |
---|
312 | |
---|
313 | delh=0 |
---|
314 | |
---|
315 | |
---|
316 | do j=2,ny-1 |
---|
317 | do i=2,nx-1 |
---|
318 | delh=delh+deltaH(i,j)**2 |
---|
319 | end do |
---|
320 | end do |
---|
321 | |
---|
322 | if (delh.gt.0.) then |
---|
323 | testh=sqrt(delh)/((nx-2)*(ny-2)) |
---|
324 | else |
---|
325 | testh=0. |
---|
326 | endif |
---|
327 | stopp = (testh.lt.1.e-4).or.(ntour.gt.100) |
---|
328 | |
---|
329 | |
---|
330 | |
---|
331 | end do relax_loop |
---|
332 | |
---|
333 | |
---|
334 | ! thickness at the upwind node |
---|
335 | do j = 1, ny |
---|
336 | do i = 2, nx |
---|
337 | debug_3D(i,j,92) = c_west(i,j) * newH(i-1,j) + c_east(i,j) * newH(i,j) |
---|
338 | end do |
---|
339 | end do |
---|
340 | do j = 2, ny |
---|
341 | do i = 1, nx |
---|
342 | debug_3D(i,j,93) = c_south(i,j) * newH(i,j-1) + c_north(i,j) * newH(i,j) |
---|
343 | end do |
---|
344 | end do |
---|
345 | |
---|
346 | if (itracebug.eq.1) call tracebug(' fin routine resolution_diffusion') |
---|
347 | return |
---|
348 | |
---|
349 | end subroutine resol_adv_diff_2D_vect |
---|
350 | |
---|
351 | end module reso_adv_diff_2D_vect |
---|
352 | |
---|
353 | |
---|
354 | |
---|
355 | |
---|