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_Util |
---|
26 | C |
---|
27 | Module Agrif_Util |
---|
28 | C |
---|
29 | C |
---|
30 | CCC Description: |
---|
31 | CCC This module contains the two procedures called in the main program : |
---|
32 | CCC Agrif_Init_Grids allowing the initialization of the root coarse grid, and |
---|
33 | CCC Agrif_Step allowing the creation of the grid hierarchy and the management |
---|
34 | CCC of the time integration. |
---|
35 | C |
---|
36 | C Modules used: |
---|
37 | C |
---|
38 | Use Agrif_Clustering |
---|
39 | Use Agrif_bcfunction |
---|
40 | C |
---|
41 | IMPLICIT NONE |
---|
42 | C |
---|
43 | Contains |
---|
44 | C Definition of procedures contained in this module. |
---|
45 | C |
---|
46 | C ************************************************************************** |
---|
47 | CCC Subroutine Agrif_Step |
---|
48 | C ************************************************************************** |
---|
49 | C |
---|
50 | Subroutine Agrif_Step(procname) |
---|
51 | C |
---|
52 | CCC Description: |
---|
53 | CCC Subroutine to create the grid hierarchy and to manage the time integration |
---|
54 | CCC procedure. It is called in the main program. |
---|
55 | C |
---|
56 | CC Method: |
---|
57 | CC Call on subroutines Agrif_Regrid and Agrif_Integrate. |
---|
58 | C |
---|
59 | C Declarations: |
---|
60 | C |
---|
61 | Optional :: procname |
---|
62 | External :: procname |
---|
63 | C |
---|
64 | #ifdef key_mpp_mpi |
---|
65 | INCLUDE 'mpif.h' |
---|
66 | Integer :: code, ierr |
---|
67 | Logical :: mpi_was_called |
---|
68 | C |
---|
69 | C |
---|
70 | Call Agrif_comm_def(MPI_COMM_AGRIF) |
---|
71 | |
---|
72 | CALL mpi_initialized ( mpi_was_called, code ) |
---|
73 | IF( code /= MPI_SUCCESS ) THEN |
---|
74 | WRITE(*, *) ': Error in routine mpi_initialized' |
---|
75 | CALL mpi_abort( mpi_comm_world, code, ierr ) |
---|
76 | ENDIF |
---|
77 | |
---|
78 | IF( .NOT. mpi_was_called ) THEN |
---|
79 | CALL mpi_comm_dup( mpi_comm_world, MPI_COMM_AGRIF, code) |
---|
80 | IF( code /= MPI_SUCCESS ) THEN |
---|
81 | WRITE(*, *) ' Agrif_Step: Error in routine mpi_comm_dup' |
---|
82 | CALL mpi_abort( mpi_comm_world, code, ierr ) |
---|
83 | ENDIF |
---|
84 | ENDIF |
---|
85 | |
---|
86 | If (Agrif_Mygrid % ngridstep == 0) Then |
---|
87 | Call MPI_COMM_SIZE(MPI_COMM_AGRIF,Agrif_Nbprocs,code) |
---|
88 | Call MPI_COMM_RANK(MPI_COMM_AGRIF,Agrif_ProcRank,code) |
---|
89 | Call MPI_COMM_GROUP(MPI_COMM_AGRIF,Agrif_Group,code) |
---|
90 | endif |
---|
91 | #endif |
---|
92 | C |
---|
93 | C Creation and initialization of the grid hierarchy |
---|
94 | C |
---|
95 | C |
---|
96 | C Set the clustering variables |
---|
97 | C |
---|
98 | Call Agrif_clustering_def() |
---|
99 | C |
---|
100 | if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 1 ) then |
---|
101 | C |
---|
102 | If (Agrif_Mygrid % ngridstep == 0) then |
---|
103 | C |
---|
104 | Call Agrif_Regrid |
---|
105 | C |
---|
106 | Call Agrif_Instance |
---|
107 | & (Agrif_Mygrid) |
---|
108 | endif |
---|
109 | C |
---|
110 | else |
---|
111 | C |
---|
112 | If (mod(Agrif_Mygrid % ngridstep, Agrif_Regridding) == 0) then |
---|
113 | C |
---|
114 | Call Agrif_Regrid |
---|
115 | C |
---|
116 | Call Agrif_Instance |
---|
117 | & (Agrif_Mygrid) |
---|
118 | C |
---|
119 | endif |
---|
120 | C |
---|
121 | endif |
---|
122 | C |
---|
123 | C Time integration of the grid hierarchy |
---|
124 | C |
---|
125 | If (present(procname)) Then |
---|
126 | Call Agrif_Integrate (Agrif_Mygrid,procname) |
---|
127 | Else |
---|
128 | Call Agrif_Integrate (Agrif_Mygrid) |
---|
129 | endif |
---|
130 | C |
---|
131 | If (associated(Agrif_Mygrid%child_grids)) |
---|
132 | & Call Agrif_Instance (Agrif_Mygrid) |
---|
133 | C |
---|
134 | Return |
---|
135 | C |
---|
136 | End Subroutine Agrif_Step |
---|
137 | |
---|
138 | C ************************************************************************** |
---|
139 | CCC Subroutine Agrif_Step_Child |
---|
140 | C ************************************************************************** |
---|
141 | C |
---|
142 | Subroutine Agrif_Step_Child(procname) |
---|
143 | C |
---|
144 | CCC Description: |
---|
145 | CCC Subroutine to create the grid hierarchy and to manage the time integration |
---|
146 | CCC procedure. It is called in the main program. |
---|
147 | C |
---|
148 | CC Method: |
---|
149 | CC Call on subroutines Agrif_Regrid and Agrif_Integrate. |
---|
150 | C |
---|
151 | C Declarations: |
---|
152 | C |
---|
153 | Optional :: procname |
---|
154 | External :: procname |
---|
155 | C |
---|
156 | C Time integration of the grid hierarchy |
---|
157 | C |
---|
158 | If (present(procname)) Then |
---|
159 | Call Agrif_Integrate_Child (Agrif_Mygrid,procname) |
---|
160 | Else |
---|
161 | Call Agrif_Integrate_Child (Agrif_Mygrid) |
---|
162 | endif |
---|
163 | C |
---|
164 | If (associated(Agrif_Mygrid%child_grids)) |
---|
165 | & Call Agrif_Instance (Agrif_Mygrid) |
---|
166 | C |
---|
167 | Return |
---|
168 | C |
---|
169 | End Subroutine Agrif_Step_Child |
---|
170 | |
---|
171 | C |
---|
172 | C |
---|
173 | C |
---|
174 | C ************************************************************************** |
---|
175 | CCC Subroutine Agrif_Regrid |
---|
176 | C ************************************************************************** |
---|
177 | C |
---|
178 | Subroutine Agrif_Regrid |
---|
179 | C |
---|
180 | CCC Description: |
---|
181 | CCC Subroutine to create the grid hierarchy from fixed grids and |
---|
182 | CC adaptive mesh refinement. |
---|
183 | C |
---|
184 | CC Method: |
---|
185 | C |
---|
186 | C Declarations: |
---|
187 | C |
---|
188 | C Local variables |
---|
189 | Type(Agrif_Rectangle), Pointer :: coarsegrid_fixed |
---|
190 | Type(Agrif_Rectangle), Pointer :: coarsegrid_moving |
---|
191 | INTEGER :: j |
---|
192 | INTEGER :: nunit |
---|
193 | INTEGER :: iii |
---|
194 | Logical :: BEXIST |
---|
195 | C |
---|
196 | if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 0 ) |
---|
197 | & Call Agrif_detect_all(Agrif_Mygrid) ! Detection of areas to be refined |
---|
198 | C |
---|
199 | Allocate(coarsegrid_fixed) |
---|
200 | Allocate(coarsegrid_moving) |
---|
201 | C |
---|
202 | if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 0 ) |
---|
203 | & Call Agrif_Cluster_All(Agrif_Mygrid,coarsegrid_moving) ! Clustering |
---|
204 | C |
---|
205 | if ( Agrif_USE_FIXED_GRIDS .EQ. 1 .OR. |
---|
206 | & Agrif_USE_ONLY_FIXED_GRIDS .EQ. 1 ) then |
---|
207 | C |
---|
208 | If (Agrif_Mygrid % ngridstep == 0) Then |
---|
209 | nunit = Agrif_Get_Unit() |
---|
210 | open(nunit,file='AGRIF_FixedGrids.in',form='formatted', |
---|
211 | & status="old",ERR=99) ! Opening of the Agrif_FixedGrids.in file |
---|
212 | j = 1 |
---|
213 | C Creation of the grid hierarchy from the Agrif_FixedGrids.in file |
---|
214 | do iii = 1 , Agrif_Probdim |
---|
215 | coarsegrid_fixed % imin(iii) = 1 |
---|
216 | coarsegrid_fixed % imax(iii) = Agrif_Mygrid % nb(iii) + 1 |
---|
217 | enddo |
---|
218 | C |
---|
219 | Call Agrif_Read_Fix_Grd (coarsegrid_fixed,j,nunit) |
---|
220 | close(nunit) ! Closing of the Agrif_FixedGrids.in file |
---|
221 | C |
---|
222 | Nullify(Agrif_oldmygrid) |
---|
223 | Nullify(Agrif_Mygrid % child_grids) |
---|
224 | C |
---|
225 | C Creation of the grid hierarchy from coarsegrid_fixed |
---|
226 | Call Agrif_Create_Grids (Agrif_Mygrid,coarsegrid_fixed) |
---|
227 | Else |
---|
228 | Agrif_oldmygrid => Agrif_Mygrid % child_grids |
---|
229 | endif |
---|
230 | else |
---|
231 | Agrif_oldmygrid => Agrif_Mygrid % child_grids |
---|
232 | Nullify(Agrif_Mygrid % child_grids) |
---|
233 | endif |
---|
234 | C |
---|
235 | if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 0 ) then |
---|
236 | C |
---|
237 | Call Agrif_Save_All(Agrif_oldmygrid) |
---|
238 | C |
---|
239 | Call Agrif_Free_before_All(Agrif_oldmygrid) |
---|
240 | C |
---|
241 | C Creation of the grid hierarchy from coarsegrid_moving |
---|
242 | Call Agrif_Create_Grids |
---|
243 | & (Agrif_Mygrid,coarsegrid_moving) |
---|
244 | C |
---|
245 | endif |
---|
246 | C |
---|
247 | C Initialization of the grid hierarchy by copy or interpolation |
---|
248 | C |
---|
249 | Call Agrif_Init_Hierarchy(Agrif_Mygrid) |
---|
250 | C |
---|
251 | if ( Agrif_USE_ONLY_FIXED_GRIDS .EQ. 0 ) |
---|
252 | & Call Agrif_Free_after_All(Agrif_oldmygrid) |
---|
253 | C |
---|
254 | Deallocate(coarsegrid_fixed) |
---|
255 | Deallocate(coarsegrid_moving) |
---|
256 | C |
---|
257 | Return |
---|
258 | C |
---|
259 | C Opening error |
---|
260 | C |
---|
261 | 99 INQUIRE(FILE='AGRIF_FixedGrids.in',EXIST=BEXIST) |
---|
262 | If (.not. BEXIST) Then |
---|
263 | print*,'ERROR : File AGRIF_FixedGrids.in not found.' |
---|
264 | STOP |
---|
265 | Else |
---|
266 | print*,'Error opening file AGRIF_FixedGrids.in' |
---|
267 | STOP |
---|
268 | endif |
---|
269 | C |
---|
270 | End Subroutine Agrif_Regrid |
---|
271 | C |
---|
272 | C ************************************************************************** |
---|
273 | CCC Subroutine Agrif_detect_All |
---|
274 | C ************************************************************************** |
---|
275 | C |
---|
276 | Recursive Subroutine Agrif_detect_all(g) |
---|
277 | C |
---|
278 | CCC Description: |
---|
279 | CCC Subroutine to detect areas to be refined. |
---|
280 | C |
---|
281 | CC Method: |
---|
282 | C |
---|
283 | C Declarations: |
---|
284 | C |
---|
285 | |
---|
286 | C |
---|
287 | C Pointer argument |
---|
288 | TYPE(Agrif_Grid) ,pointer :: g ! Pointer on the current grid |
---|
289 | C |
---|
290 | C Local variables |
---|
291 | Type(Agrif_pgrid),pointer :: parcours ! Pointer for the recursive |
---|
292 | ! procedure |
---|
293 | INTEGER, DIMENSION(3) :: size |
---|
294 | INTEGER :: iii |
---|
295 | Real :: g_eps |
---|
296 | C |
---|
297 | parcours => g % child_grids |
---|
298 | C |
---|
299 | C To be positioned on the finer grids of the grid hierarchy |
---|
300 | C |
---|
301 | do while (associated(parcours)) |
---|
302 | Call Agrif_detect_all (parcours % gr) |
---|
303 | parcours => parcours % next |
---|
304 | enddo |
---|
305 | C |
---|
306 | g_eps = huge(1.) |
---|
307 | do iii = 1 , Agrif_Probdim |
---|
308 | g_eps=min(g_eps,g%Agrif_d(iii)) |
---|
309 | enddo |
---|
310 | C |
---|
311 | g_eps = g_eps/100. |
---|
312 | C |
---|
313 | if ( Agrif_Probdim .EQ. 1 ) g%tabpoint1D=0 |
---|
314 | if ( Agrif_Probdim .EQ. 2 ) g%tabpoint2D=0 |
---|
315 | if ( Agrif_Probdim .EQ. 3 ) g%tabpoint3D=0 |
---|
316 | C |
---|
317 | do iii = 1 , Agrif_Probdim |
---|
318 | if (g%Agrif_d(iii)/Agrif_coeffref(iii).LT. |
---|
319 | & (Agrif_mind(iii)-g_eps)) Return |
---|
320 | enddo |
---|
321 | C |
---|
322 | Call Agrif_instance(g) |
---|
323 | C |
---|
324 | C Detection (Agrif_detect is a user s routine) |
---|
325 | C |
---|
326 | |
---|
327 | do iii = 1 , Agrif_Probdim |
---|
328 | size(iii) = g%nb(iii) + 1 |
---|
329 | enddo |
---|
330 | C |
---|
331 | SELECT CASE (Agrif_Probdim) |
---|
332 | CASE (1) |
---|
333 | Call Agrif_detect(g%tabpoint1D,size) |
---|
334 | CASE (2) |
---|
335 | Call Agrif_detect(g%tabpoint2D,size) |
---|
336 | CASE (3) |
---|
337 | Call Agrif_detect(g%tabpoint3D,size) |
---|
338 | END SELECT |
---|
339 | C |
---|
340 | C Addition of the areas detected on the child grids |
---|
341 | C |
---|
342 | parcours => g % child_grids |
---|
343 | C |
---|
344 | Do while (associated(parcours)) |
---|
345 | Call Agrif_Add_detected_areas (g,parcours % gr) |
---|
346 | parcours => parcours % next |
---|
347 | enddo |
---|
348 | C |
---|
349 | Return |
---|
350 | C |
---|
351 | End Subroutine Agrif_detect_all |
---|
352 | C |
---|
353 | C |
---|
354 | C |
---|
355 | C ************************************************************************** |
---|
356 | CCC Subroutine Agrif_Add_detected_areas |
---|
357 | C ************************************************************************** |
---|
358 | C |
---|
359 | Subroutine Agrif_Add_detected_areas(parentgrid,childgrid) |
---|
360 | C |
---|
361 | CCC Description: |
---|
362 | CCC Subroutine to add on the parent grid the areas detected |
---|
363 | CC on its child grids. |
---|
364 | C |
---|
365 | CC Method: |
---|
366 | C |
---|
367 | C Declarations: |
---|
368 | C |
---|
369 | |
---|
370 | C |
---|
371 | Type(Agrif_Grid),pointer :: parentgrid,childgrid |
---|
372 | C |
---|
373 | Integer :: i,j,k |
---|
374 | C |
---|
375 | do i = 1,childgrid%nb(1)+1 |
---|
376 | if ( Agrif_Probdim .EQ. 1 ) then |
---|
377 | If (childgrid%tabpoint1D(i).EQ.1) Then |
---|
378 | parentgrid%tabpoint1D(childgrid%ix(1)+ |
---|
379 | & (i-1)/Agrif_Coeffref(1)) = 1 |
---|
380 | endif |
---|
381 | else |
---|
382 | do j=1,childgrid%nb(2)+1 |
---|
383 | if (Agrif_Probdim.EQ.2) then |
---|
384 | If (childgrid%tabpoint2D(i,j).EQ.1) Then |
---|
385 | parentgrid%tabpoint2D( |
---|
386 | & childgrid%ix(1)+(i-1)/Agrif_Coeffref(1), |
---|
387 | & childgrid%ix(2)+(j-1)/Agrif_Coeffref(2)) = 1 |
---|
388 | endif |
---|
389 | else |
---|
390 | do k=1,childgrid%nb(3)+1 |
---|
391 | If (childgrid%tabpoint3D(i,j,k).EQ.1) Then |
---|
392 | parentgrid%tabpoint3D( |
---|
393 | & childgrid%ix(1)+(i-1)/Agrif_Coeffref(1), |
---|
394 | & childgrid%ix(2)+(j-1)/Agrif_Coeffref(2), |
---|
395 | & childgrid%ix(3)+(k-1)/Agrif_Coeffref(3)) = 1 |
---|
396 | endif |
---|
397 | enddo |
---|
398 | endif |
---|
399 | enddo |
---|
400 | endif |
---|
401 | enddo |
---|
402 | C |
---|
403 | Return |
---|
404 | C |
---|
405 | End Subroutine Agrif_Add_detected_areas |
---|
406 | C |
---|
407 | C |
---|
408 | C ************************************************************************** |
---|
409 | CCC Subroutine Agrif_Free_before_All |
---|
410 | C ************************************************************************** |
---|
411 | C |
---|
412 | Recursive Subroutine Agrif_Free_before_All(g) |
---|
413 | C |
---|
414 | CCC Description: |
---|
415 | C |
---|
416 | CC Method: |
---|
417 | C |
---|
418 | C Declarations: |
---|
419 | C |
---|
420 | C Pointer argument |
---|
421 | Type(Agrif_pgrid),pointer :: g ! Pointer on the current grid |
---|
422 | C |
---|
423 | C Local pointer |
---|
424 | Type(Agrif_pgrid),pointer :: parcours ! Pointer for the recursive |
---|
425 | ! procedure |
---|
426 | C |
---|
427 | C |
---|
428 | parcours => g |
---|
429 | C |
---|
430 | Do while (associated(parcours)) |
---|
431 | If (.not. parcours%gr%fixed) Then |
---|
432 | Call Agrif_Free_data_before(parcours%gr) |
---|
433 | parcours % gr % oldgrid = .TRUE. |
---|
434 | endif |
---|
435 | C |
---|
436 | Call Agrif_Free_before_all (parcours % gr % child_grids) |
---|
437 | C |
---|
438 | parcours => parcours % next |
---|
439 | enddo |
---|
440 | C |
---|
441 | Return |
---|
442 | C |
---|
443 | C |
---|
444 | End Subroutine Agrif_Free_before_All |
---|
445 | C ************************************************************************** |
---|
446 | CCC Subroutine Agrif_Save_All |
---|
447 | C ************************************************************************** |
---|
448 | C |
---|
449 | Recursive Subroutine Agrif_Save_All(g) |
---|
450 | C |
---|
451 | CCC Description: |
---|
452 | C |
---|
453 | CC Method: |
---|
454 | C |
---|
455 | C Declarations: |
---|
456 | C |
---|
457 | C Pointer argument |
---|
458 | Type(Agrif_pgrid),pointer :: g ! Pointer on the current grid |
---|
459 | C |
---|
460 | C Local pointer |
---|
461 | Type(Agrif_pgrid),pointer :: parcours ! Pointer for the recursive |
---|
462 | ! procedure |
---|
463 | C |
---|
464 | C |
---|
465 | parcours => g |
---|
466 | C |
---|
467 | Do while (associated(parcours)) |
---|
468 | If (.not. parcours%gr%fixed) Then |
---|
469 | Call Agrif_Instance(parcours%gr) |
---|
470 | Call Agrif_Before_Regridding() |
---|
471 | parcours % gr % oldgrid = .TRUE. |
---|
472 | endif |
---|
473 | C |
---|
474 | Call Agrif_Save_All (parcours % gr % child_grids) |
---|
475 | C |
---|
476 | parcours => parcours % next |
---|
477 | enddo |
---|
478 | C |
---|
479 | Return |
---|
480 | C |
---|
481 | C |
---|
482 | End Subroutine Agrif_Save_All |
---|
483 | C |
---|
484 | C |
---|
485 | C |
---|
486 | C ************************************************************************** |
---|
487 | CCC Subroutine Agrif_Free_after_All |
---|
488 | C ************************************************************************** |
---|
489 | C |
---|
490 | Recursive Subroutine Agrif_Free_after_All(g) |
---|
491 | C |
---|
492 | CCC Description: |
---|
493 | C |
---|
494 | CC Method: |
---|
495 | C |
---|
496 | C Declarations: |
---|
497 | C |
---|
498 | |
---|
499 | C |
---|
500 | C Pointer argument |
---|
501 | Type(Agrif_pgrid),pointer :: g ! Pointer on the current grid |
---|
502 | C |
---|
503 | C Local pointers |
---|
504 | TYPE(Agrif_pgrid),pointer :: parcours ! Pointer for the recursive proced |
---|
505 | Type(Agrif_pgrid),pointer :: preparcours |
---|
506 | Type(Agrif_pgrid),pointer :: preparcoursini |
---|
507 | C |
---|
508 | C |
---|
509 | Allocate(preparcours) |
---|
510 | C |
---|
511 | preparcoursini => preparcours |
---|
512 | C |
---|
513 | Nullify(preparcours % gr) |
---|
514 | C |
---|
515 | preparcours % next => g |
---|
516 | C |
---|
517 | parcours => g |
---|
518 | C |
---|
519 | Do while (associated(parcours)) |
---|
520 | C |
---|
521 | if ( (.NOT. parcours% gr% fixed) .AND. |
---|
522 | & (parcours% gr% oldgrid ) ) then |
---|
523 | Call Agrif_Free_data_after(parcours%gr) |
---|
524 | endif |
---|
525 | C |
---|
526 | Call Agrif_Free_after_all (parcours % gr % child_grids) |
---|
527 | C |
---|
528 | If (parcours % gr % oldgrid) Then |
---|
529 | Deallocate(parcours % gr) |
---|
530 | preparcours % next => parcours % next |
---|
531 | Deallocate(parcours) |
---|
532 | parcours => preparcours % next |
---|
533 | Else |
---|
534 | preparcours => preparcours % next |
---|
535 | parcours => parcours % next |
---|
536 | endif |
---|
537 | enddo |
---|
538 | C |
---|
539 | Deallocate(preparcoursini) |
---|
540 | C |
---|
541 | Return |
---|
542 | C |
---|
543 | End Subroutine Agrif_Free_after_All |
---|
544 | C |
---|
545 | C |
---|
546 | C ************************************************************************** |
---|
547 | CCC Subroutine Agrif_Integrate |
---|
548 | C ************************************************************************** |
---|
549 | C |
---|
550 | Recursive Subroutine Agrif_Integrate(g, procname) |
---|
551 | C |
---|
552 | CCC Description: |
---|
553 | CCC Subroutine to manage the time integration of the grid hierarchy. |
---|
554 | C |
---|
555 | CC Method: |
---|
556 | CC Recursive subroutine and call on subroutines Agrif_Instance & Agrif_Step |
---|
557 | C |
---|
558 | C Declarations: |
---|
559 | C |
---|
560 | |
---|
561 | C |
---|
562 | C Pointer argument |
---|
563 | Type(Agrif_Grid),pointer :: g ! Pointer on the current grid |
---|
564 | C |
---|
565 | C main procedure name |
---|
566 | Optional :: procname |
---|
567 | External :: procname |
---|
568 | C |
---|
569 | C Local pointer |
---|
570 | Type(Agrif_pgrid),pointer :: parcours ! Pointer for the recursive |
---|
571 | ! procedure |
---|
572 | C |
---|
573 | C Local scalars |
---|
574 | INTEGER :: nbt ! Number of time steps |
---|
575 | ! of the current grid |
---|
576 | INTEGER :: k |
---|
577 | INTEGER :: iii |
---|
578 | C |
---|
579 | C Instanciation of the variables of the current grid |
---|
580 | If (g%fixedrank .NE.0) Then |
---|
581 | Call Agrif_Instance |
---|
582 | & (g) |
---|
583 | End If |
---|
584 | C |
---|
585 | C One step on the current grid |
---|
586 | C |
---|
587 | If (present(procname)) Then |
---|
588 | Call procname () |
---|
589 | Else |
---|
590 | write(*,*) 'The name of the step subroutine has not ' |
---|
591 | write(*,*) 'been given in the subroutine Agrif_Integrate' |
---|
592 | stop |
---|
593 | endif |
---|
594 | C |
---|
595 | C Number of time steps on the current grid |
---|
596 | C |
---|
597 | g%ngridstep = g % ngridstep + 1 |
---|
598 | C |
---|
599 | parcours => g % child_grids |
---|
600 | C |
---|
601 | C Recursive procedure for the time integration of the grid hierarchy |
---|
602 | Do while (associated(parcours)) |
---|
603 | C |
---|
604 | C Instanciation of the variables of the current grid |
---|
605 | Call Agrif_Instance |
---|
606 | & (parcours % gr) |
---|
607 | C |
---|
608 | C Number of time steps |
---|
609 | nbt = 1 |
---|
610 | do iii = 1 , Agrif_Probdim |
---|
611 | nbt = max(nbt, parcours % gr % timeref(iii)) |
---|
612 | enddo |
---|
613 | C |
---|
614 | Do k = 1,nbt |
---|
615 | C |
---|
616 | If (present(procname)) Then |
---|
617 | Call Agrif_Integrate (parcours % gr, procname) |
---|
618 | Else |
---|
619 | Call Agrif_Integrate (parcours % gr) |
---|
620 | endif |
---|
621 | C |
---|
622 | enddo |
---|
623 | C |
---|
624 | parcours => parcours % next |
---|
625 | C |
---|
626 | enddo |
---|
627 | C |
---|
628 | C |
---|
629 | End Subroutine Agrif_Integrate |
---|
630 | |
---|
631 | C ************************************************************************** |
---|
632 | CCC Subroutine Agrif_Integrate_Child |
---|
633 | C ************************************************************************** |
---|
634 | C |
---|
635 | Recursive Subroutine Agrif_Integrate_Child(g,procname) |
---|
636 | C |
---|
637 | CCC Description: |
---|
638 | CCC Subroutine to manage the time integration of the grid hierarchy. |
---|
639 | C |
---|
640 | CC Method: |
---|
641 | CC Recursive subroutine and call on subroutines Agrif_Instance & Agrif_Step. |
---|
642 | C |
---|
643 | C Declarations: |
---|
644 | C |
---|
645 | |
---|
646 | C |
---|
647 | C Pointer argument |
---|
648 | Type(Agrif_Grid),pointer :: g ! Pointer on the current grid |
---|
649 | C |
---|
650 | C main procedure name |
---|
651 | Optional :: procname |
---|
652 | External :: procname |
---|
653 | C |
---|
654 | C Local pointer |
---|
655 | Type(Agrif_pgrid),pointer :: parcours ! Pointer for the recursive |
---|
656 | ! procedure |
---|
657 | C |
---|
658 | C One step on the current grid |
---|
659 | C |
---|
660 | If (present(procname)) Then |
---|
661 | Call procname () |
---|
662 | Else |
---|
663 | write(*,*) 'The name of the step subroutine has not ' |
---|
664 | write(*,*) 'been given in the subroutine Agrif_Integrate' |
---|
665 | stop |
---|
666 | endif |
---|
667 | C |
---|
668 | C Number of time steps on the current grid |
---|
669 | C |
---|
670 | C |
---|
671 | parcours => g % child_grids |
---|
672 | C |
---|
673 | C Recursive procedure for the time integration of the grid hierarchy |
---|
674 | Do while (associated(parcours)) |
---|
675 | C |
---|
676 | C Instanciation of the variables of the current grid |
---|
677 | Call Agrif_Instance |
---|
678 | & (parcours % gr) |
---|
679 | |
---|
680 | C |
---|
681 | If (present(procname)) Then |
---|
682 | Call Agrif_Integrate_Child (parcours % gr, procname) |
---|
683 | Else |
---|
684 | Call Agrif_Integrate_Child (parcours % gr) |
---|
685 | endif |
---|
686 | C |
---|
687 | parcours => parcours % next |
---|
688 | C |
---|
689 | enddo |
---|
690 | C |
---|
691 | C |
---|
692 | End Subroutine Agrif_Integrate_Child |
---|
693 | |
---|
694 | C |
---|
695 | C |
---|
696 | C ************************************************************************** |
---|
697 | CCC Subroutine Agrif_Init_Grids |
---|
698 | C ************************************************************************** |
---|
699 | C |
---|
700 | Subroutine Agrif_Init_Grids |
---|
701 | C |
---|
702 | CCC Description: |
---|
703 | CCC Subroutine to initialize the root coarse grid pointed by Agrif_Mygrid. |
---|
704 | CCC It is called in the main program. |
---|
705 | C |
---|
706 | C Declarations: |
---|
707 | C |
---|
708 | C |
---|
709 | INTEGER :: iii |
---|
710 | C |
---|
711 | C definition of the probdim and modtypes variables |
---|
712 | C |
---|
713 | #ifdef key_mpp_mpi |
---|
714 | INCLUDE 'mpif.h' |
---|
715 | Agrif_MPIPREC = MPI_DOUBLE_PRECISION |
---|
716 | #endif |
---|
717 | Call Agrif_probdim_modtype_def() |
---|
718 | C |
---|
719 | Agrif_UseSpecialValue = .FALSE. |
---|
720 | Agrif_UseSpecialValueFineGrid = .FALSE. |
---|
721 | Agrif_SpecialValue = 0. |
---|
722 | Agrif_SpecialValueFineGrid = 0. |
---|
723 | C |
---|
724 | C Allocation of Agrif_Mygrid |
---|
725 | allocate(Agrif_Mygrid) |
---|
726 | C |
---|
727 | C Space and time refinement factors are set to 1 on the root grid |
---|
728 | C |
---|
729 | do iii = 1 , Agrif_Probdim |
---|
730 | Agrif_Mygrid % spaceref(iii) = 1 |
---|
731 | Agrif_Mygrid % timeref(iii) = 1 |
---|
732 | enddo |
---|
733 | C |
---|
734 | C Initialization of the number of time steps |
---|
735 | Agrif_Mygrid % ngridstep = 0 |
---|
736 | Agrif_Mygrid % grid_id = 0 |
---|
737 | C |
---|
738 | C No parent grid for the root coarse grid |
---|
739 | Nullify(Agrif_Mygrid % parent) |
---|
740 | C |
---|
741 | C Initialization of the minimum positions, global abscissa and space steps |
---|
742 | do iii= 1 , Agrif_Probdim |
---|
743 | Agrif_Mygrid % ix(iii) = 1 |
---|
744 | Agrif_Mygrid % Agrif_x(iii) = 0. |
---|
745 | Agrif_Mygrid % Agrif_d(iii) = 1. |
---|
746 | C Borders of the root coarse grid |
---|
747 | Agrif_Mygrid % NearRootBorder(iii) = .true. |
---|
748 | Agrif_Mygrid % DistantRootBorder(iii) = .true. |
---|
749 | enddo |
---|
750 | C |
---|
751 | C The root coarse grid is a fixed grid |
---|
752 | Agrif_Mygrid % fixed = .TRUE. |
---|
753 | C Level of the root grid |
---|
754 | Agrif_Mygrid % level = 0 |
---|
755 | C Maximum level in the hierarchy |
---|
756 | Agrif_MaxLevelLoc = 0 |
---|
757 | |
---|
758 | C |
---|
759 | C Number of the grid pointed by Agrif_Mygrid (root coarse grid) |
---|
760 | Agrif_Mygrid % rank = 1 |
---|
761 | C |
---|
762 | C Number of the root grid as a fixed grid |
---|
763 | Agrif_Mygrid % fixedrank = 0 |
---|
764 | C |
---|
765 | C Initialization of some fields of the root grid variables |
---|
766 | Call Agrif_Create_Var (Agrif_Mygrid) |
---|
767 | C |
---|
768 | C Initialization of the other fields of the root grid variables (number of |
---|
769 | C cells, positions, number and type of its dimensions, ...) |
---|
770 | Call Agrif_Set_numberofcells(Agrif_Mygrid) |
---|
771 | C |
---|
772 | Call Agrif_Instance (Agrif_Mygrid) |
---|
773 | C |
---|
774 | Call Agrif_Set_numberofcells(Agrif_Mygrid) |
---|
775 | C |
---|
776 | C Allocation of the array containing the values of the grid variables |
---|
777 | Call Agrif_Allocation (Agrif_Mygrid) |
---|
778 | C |
---|
779 | Call Agrif_initialisations(Agrif_Mygrid) |
---|
780 | C |
---|
781 | nullify(Agrif_Mygrid % child_grids) |
---|
782 | C |
---|
783 | C Total number of fixed grids |
---|
784 | Agrif_nbfixedgrids = 0 |
---|
785 | C |
---|
786 | Call Agrif_Instance (Agrif_Mygrid) |
---|
787 | C |
---|
788 | End Subroutine Agrif_Init_Grids |
---|
789 | C |
---|
790 | C |
---|
791 | C ************************************************************************** |
---|
792 | CCC Subroutine Agrif_Deallocation |
---|
793 | C ************************************************************************** |
---|
794 | C |
---|
795 | Subroutine Agrif_Deallocation |
---|
796 | C |
---|
797 | CCC Description: |
---|
798 | CCC Subroutine to initialize the root coarse grid pointed by Agrif_Mygrid. |
---|
799 | CCC It is called in the main program. |
---|
800 | C |
---|
801 | C Declarations: |
---|
802 | C |
---|
803 | C |
---|
804 | INTEGER :: nb |
---|
805 | C |
---|
806 | C definition of the probdim and modtypes variables |
---|
807 | C |
---|
808 | do nb = 1, Agrif_NbVariables |
---|
809 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % array1) ) |
---|
810 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % array1) |
---|
811 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % array2) ) |
---|
812 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % array2) |
---|
813 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % array3) ) |
---|
814 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % array3) |
---|
815 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % array4) ) |
---|
816 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % array4) |
---|
817 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % array5) ) |
---|
818 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % array5) |
---|
819 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % array6) ) |
---|
820 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % array6) |
---|
821 | C |
---|
822 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % iarray1) ) |
---|
823 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % iarray1) |
---|
824 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % iarray2) ) |
---|
825 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % iarray2) |
---|
826 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % iarray3) ) |
---|
827 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % iarray3) |
---|
828 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % iarray4) ) |
---|
829 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % iarray4) |
---|
830 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % iarray5) ) |
---|
831 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % iarray5) |
---|
832 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % iarray6) ) |
---|
833 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % iarray6) |
---|
834 | C |
---|
835 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % larray1) ) |
---|
836 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % larray1) |
---|
837 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % larray2) ) |
---|
838 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % larray2) |
---|
839 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % larray3) ) |
---|
840 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % larray3) |
---|
841 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % larray4) ) |
---|
842 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % larray4) |
---|
843 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % larray5) ) |
---|
844 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % larray5) |
---|
845 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % larray6) ) |
---|
846 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % larray6) |
---|
847 | C |
---|
848 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % carray1) ) |
---|
849 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % carray1) |
---|
850 | if ( allocated(Agrif_Mygrid % tabvars(nb) % var % carray2) ) |
---|
851 | & Deallocate(Agrif_Mygrid % tabvars(nb) % var % carray2) |
---|
852 | enddo |
---|
853 | C |
---|
854 | do nb = 1, Agrif_NbVariables |
---|
855 | Deallocate(Agrif_Mygrid % tabvars(nb) % var) |
---|
856 | enddo |
---|
857 | C |
---|
858 | Deallocate(Agrif_Mygrid % tabvars) |
---|
859 | C |
---|
860 | Deallocate(Agrif_Mygrid) |
---|
861 | C |
---|
862 | End Subroutine Agrif_Deallocation |
---|
863 | C |
---|
864 | End module Agrif_Util |
---|