New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
modarrays.F in trunk/AGRIF/AGRIF_FILES – NEMO

source: trunk/AGRIF/AGRIF_FILES/modarrays.F @ 662

Last change on this file since 662 was 662, checked in by opalod, 17 years ago

RB: update Agrif internal routines with a new update scheme and performance improvment

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 34.8 KB
Line 
1!
2! $Id$
3!
4C     AGRIF (Adaptive Grid Refinement In Fortran)
5C
6C     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
7C                        Christophe Vouland (Christophe.Vouland@imag.fr)   
8C
9C     This program is free software; you can redistribute it and/or modify
10C     it under the terms of the GNU General Public License as published by
11C     the Free Software Foundation; either version 2 of the License, or
12C     (at your option) any later version.
13C
14C     This program is distributed in the hope that it will be useful,
15C     but WITHOUT ANY WARRANTY; without even the implied warranty of
16C     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17C     GNU General Public License for more details.
18C
19C     You should have received a copy of the GNU General Public License
20C     along with this program; if not, write to the Free Software
21C     Foundation, Inc., 59 Temple Place- Suite 330, Boston, MA 02111-1307, USA.
22C
23C
24C
25CCC   Module Agrif_Arrays
26C     
27      Module Agrif_Arrays
28      Use Agrif_Types
29C
30      implicit none
31C     
32      Contains
33C     **************************************************************************
34CCC   Subroutine Agrif_Childbounds
35C     **************************************************************************
36C
37      Subroutine Agrif_Childbounds(nbdim,lboundloc,uboundloc,
38     &                 pttab,petab,pttruetab,cetruetab,memberin)
39C
40CCC   Description:
41CCC   Subroutine calculating the global indices of the child grid
42C
43C
44C     Declarations:
45C
46
47C
48C     Arguments
49      INTEGER :: nbdim
50      INTEGER,DIMENSION(nbdim) :: lboundloc,uboundloc
51      INTEGER,DIMENSION(nbdim) :: pttab,petab,pttruetab,cetruetab
52      LOGICAL :: memberin
53C
54C     Local variables
55      INTEGER :: i,lbglob,ubglob
56C
57#ifdef AGRIF_MPI
58      INTEGER :: indglob1,indglob2
59#endif
60C
61C
62      do i = 1,nbdim
63C
64        lbglob = lboundloc(i)
65        ubglob = uboundloc(i)
66C
67#ifdef AGRIF_MPI
68C
69        Call AGRIF_InvLoc(lbglob,Agrif_ProcRank,i,indglob1)
70C
71        Call AGRIF_InvLoc(ubglob,Agrif_ProcRank,i,indglob2)
72C
73        pttruetab(i) = max(pttab(i),indglob1)       
74C
75        cetruetab(i) = min(petab(i),indglob2)                 
76C
77#else
78C
79        pttruetab(i) = max(pttab(i),lbglob)       
80C
81        cetruetab(i) = min(petab(i),ubglob)
82C
83#endif
84C
85      enddo
86
87      memberin = .TRUE.
88
89      do i=1,nbdim
90        IF (cetruetab(i) < pttruetab(i)) THEN
91          memberin = .FALSE.
92          EXIT
93        ENDIF
94      enddo
95C
96      Return
97C
98C
99      End Subroutine Agrif_Childbounds
100C
101C
102C     **************************************************************************
103CCC   Subroutine Agrif_nbdim_Get_bound
104C     **************************************************************************
105C
106      Subroutine Agrif_nbdim_Get_bound(Variable,
107     &                           lower,upper,indice,nbdim)
108C
109CCC   Description:
110CCC   This subroutine is used to get the lower and the upper boundaries of a
111C     table. Output datas are scalar.
112C
113C     Declarations:
114C     
115     
116C
117C     Arguments     
118C
119      ! we want extract boundaries of this table
120      TYPE(AGRIF_Variable), Pointer :: Variable   
121      INTEGER              :: lower,upper ! output data
122      ! direction in wich we want to know the dimension
123      INTEGER              :: indice     
124      INTEGER              :: nbdim       ! dimension of the table
125C
126C     Local variables
127C
128      SELECT CASE (nbdim)
129      CASE (1)
130           lower = lbound(Variable % array1,indice)
131           upper = ubound(Variable % array1,indice)
132      CASE (2)
133           lower = lbound(Variable % array2,indice)
134           upper = ubound(Variable % array2,indice)
135      CASE (3)
136           lower = lbound(Variable % array3,indice)
137           upper = ubound(Variable % array3,indice)
138      CASE (4)
139           lower = lbound(Variable % array4,indice)
140           upper = ubound(Variable % array4,indice)
141      CASE (5)
142           lower = lbound(Variable % array5,indice)
143           upper = ubound(Variable % array5,indice)
144      CASE (6)
145           lower = lbound(Variable % array6,indice)
146           upper = ubound(Variable % array6,indice)
147      END SELECT
148C
149      return
150C
151      End Subroutine Agrif_nbdim_Get_bound       
152C
153C
154C     **************************************************************************
155CCC   Subroutine Agrif_Get_bound_dimension
156C     **************************************************************************
157C
158      Subroutine Agrif_nbdim_Get_bound_dimension(Variable,
159     &                              lower,upper,nbdim)
160C
161CCC   Description:
162CCC   This subroutine is used to get the lower and the upper boundaries of a
163C        table. Output datas are scalar.
164C
165C     Declarations:
166C     
167     
168C
169C     Arguments     
170C
171      ! we want extract boundaries of this table
172      TYPE(AGRIF_Variable), Pointer     :: Variable   
173      INTEGER                  :: nbdim       ! dimension of the table
174      INTEGER,DIMENSION(nbdim) :: lower,upper ! output data
175C
176C     Local variables       
177C
178      SELECT CASE (nbdim)
179      CASE (1)
180           lower = lbound(Variable % array1)
181           upper = ubound(Variable % array1)
182      CASE (2)
183           lower = lbound(Variable % array2)
184           upper = ubound(Variable % array2)
185      CASE (3)
186           lower = lbound(Variable % array3)
187           upper = ubound(Variable % array3)
188      CASE (4)
189           lower = lbound(Variable % array4)
190           upper = ubound(Variable % array4)
191      CASE (5)
192           lower = lbound(Variable % array5)
193           upper = ubound(Variable % array5)
194      CASE (6)
195           lower = lbound(Variable % array6)
196           upper = ubound(Variable % array6)
197      END SELECT
198C
199      return
200C
201      End Subroutine Agrif_nbdim_Get_bound_dimension     
202     
203C     **************************************************************************
204CCC   Subroutine Agrif_nbdim_allocation
205C     **************************************************************************
206C
207      Subroutine Agrif_nbdim_allocation(Variable,inf,sup,nbdim)
208C
209CCC   Description:
210CCC   This subroutine is used to Allocate the table Variable
211C
212C     Declarations:
213C     
214     
215C
216C     Arguments     
217C
218      TYPE(AGRIF_Variable), Pointer     :: Variable   
219      INTEGER                  :: nbdim       ! dimension of the table
220      INTEGER,DIMENSION(nbdim) :: inf,sup
221C
222C     Local variables       
223C
224      SELECT CASE (nbdim)
225      CASE (1)
226         allocate(Variable%array1(
227     &            inf(1):sup(1)))
228      CASE (2)
229          allocate(Variable%array2(
230     &            inf(1):sup(1),
231     &            inf(2):sup(2)))
232      CASE (3)
233         allocate(Variable%array3(
234     &            inf(1):sup(1),
235     &            inf(2):sup(2),
236     &            inf(3):sup(3)))
237      CASE (4)
238         allocate(Variable%array4(
239     &            inf(1):sup(1),
240     &            inf(2):sup(2),
241     &            inf(3):sup(3),
242     &            inf(4):sup(4)))
243      CASE (5)
244         allocate(Variable%array5(
245     &            inf(1):sup(1),
246     &            inf(2):sup(2),
247     &            inf(3):sup(3),
248     &            inf(4):sup(4),
249     &            inf(5):sup(5)))
250      CASE (6)
251         allocate(Variable%array6(
252     &            inf(1):sup(1),
253     &            inf(2):sup(2),
254     &            inf(3):sup(3),
255     &            inf(4):sup(4),
256     &            inf(5):sup(5),
257     &            inf(6):sup(6)))
258      END SELECT
259C
260      return
261C
262      End Subroutine Agrif_nbdim_allocation
263C
264C
265C     **************************************************************************
266CCC   Subroutine Agrif_nbdim_deallocation
267C     **************************************************************************
268C
269      Subroutine Agrif_nbdim_deallocation(Variable,nbdim)
270C
271CCC   Description:
272CCC   This subroutine is used to give the same value to the table Variable
273C
274C     Declarations:
275C     
276     
277C
278C     Arguments     
279C
280      TYPE(AGRIF_Variable), Pointer     :: Variable   
281      INTEGER                  :: nbdim       ! dimension of the table
282C
283C     Local variables       
284C
285
286      SELECT CASE (nbdim)
287      CASE (1)
288         Deallocate(Variable%array1)
289      CASE (2)
290         Deallocate(Variable%array2)
291      CASE (3)
292         Deallocate(Variable%array3)
293      CASE (4)
294         Deallocate(Variable%array4)
295      CASE (5)
296         Deallocate(Variable%array5)
297      CASE (6)
298         Deallocate(Variable%array6)
299      END SELECT
300C
301      return
302C
303      End Subroutine Agrif_nbdim_deallocation
304C
305C
306C     **************************************************************************
307CCC   Subroutine Agrif_nbdim_Full_VarEQreal
308C     **************************************************************************
309C
310      Subroutine Agrif_nbdim_Full_VarEQreal(Variable,Value,nbdim)
311C
312CCC   Description:
313CCC   This subroutine is used to get the lower and the upper boundaries of a
314C        table. Output datas are scalar.
315C
316C     Declarations:
317C     
318     
319C
320C     Arguments     
321C
322      TYPE(AGRIF_Variable), Pointer :: Variable   
323      REAL                 :: Value       
324      INTEGER              :: nbdim       ! dimension of the table
325C
326C     Local variables       
327C
328      SELECT CASE (nbdim)
329      CASE (1)
330        Variable%array1 = Value     
331      CASE (2)
332        Variable%array2 = Value
333      CASE (3)
334        Call Agrif_set_tozero3D(Variable%array3)
335!        Variable%array3 = Value
336      CASE (4)
337        Variable%array4 = Value
338      CASE (5)
339        Variable%array5 = Value
340      CASE (6)
341        Variable%array6 = Value
342      END SELECT
343C
344      return
345C
346      End Subroutine Agrif_nbdim_Full_VarEQreal   
347     
348      Subroutine Agrif_set_tozero3D(tab3D)
349      real,dimension(:,:,:),target :: tab3D
350     
351      tab3D = 0.
352     
353      end subroutine agrif_set_tozero3D   
354C
355C
356#if !defined AGRIF_MPI
357C     **************************************************************************
358CCC   Subroutine Agrif_nbdim_VarEQreal
359C     **************************************************************************
360C
361      Subroutine Agrif_nbdim_VarEQreal(Variable,inf,sup,Value,nbdim)
362C
363CCC   Description:
364CCC   This subroutine is used to give the same value to a part of 
365C        the table Variable
366C
367C     Declarations:
368C     
369     
370C
371C     Arguments     
372C
373      TYPE(AGRIF_Variable), Pointer :: Variable   
374      REAL                 :: Value       
375      INTEGER              :: nbdim       ! dimension of the table
376      INTEGER,DIMENSION(nbdim) :: inf,sup
377C
378C     Local variables       
379C
380      SELECT CASE (nbdim)
381      CASE (1)
382         Variable%array1(
383     &             inf(1):sup(1)
384     &             )  = Value
385      CASE (2)
386         Variable%array2(
387     &             inf(1):sup(1),
388     &             inf(2):sup(2)
389     &             )  = Value
390      CASE (3)
391         Variable%array3(
392     &             inf(1):sup(1),
393     &             inf(2):sup(2),
394     &             inf(3):sup(3)
395     &             )  = Value
396      CASE (4)
397         Variable%array4(
398     &             inf(1):sup(1),
399     &             inf(2):sup(2),
400     &             inf(3):sup(3),
401     &             inf(4):sup(4)
402     &             )  = Value
403      CASE (5)
404         Variable%array5(
405     &             inf(1):sup(1),
406     &             inf(2):sup(2),
407     &             inf(3):sup(3),
408     &             inf(4):sup(4),
409     &             inf(5):sup(5)
410     &             )  = Value
411      CASE (6)
412         Variable%array6(
413     &             inf(1):sup(1),
414     &             inf(2):sup(2),
415     &             inf(3):sup(3),
416     &             inf(4):sup(4),
417     &             inf(5):sup(5),
418     &             inf(6):sup(6)
419     &             )  = Value
420      END SELECT
421C
422      return
423C
424      End Subroutine Agrif_nbdim_VarEQreal       
425#endif
426C
427C
428C
429C     **************************************************************************
430CCC   Subroutine Agrif_nbdim_VarEQvar
431C     **************************************************************************
432C
433      Subroutine Agrif_nbdim_VarEQvar(Variable,inf,sup,
434     &                                Variable2,inf2,sup2,
435     &                                nbdim)
436C
437CCC   Description:
438CCC   This subroutine is used to give the value of a part of the table 
439C        Variable2 to the table Variable
440C
441C     Declarations:
442C     
443     
444C
445C     Arguments     
446C
447      TYPE(AGRIF_Variable), Pointer     :: Variable
448      TYPE(AGRIF_Variable), Pointer     :: Variable2
449      INTEGER                  :: nbdim       ! dimension of the table
450      INTEGER,DIMENSION(nbdim) :: inf,sup
451      INTEGER,DIMENSION(nbdim) :: inf2,sup2
452C
453C     Local variables       
454C
455      SELECT CASE (nbdim)
456      CASE (1)
457         Variable%array1(inf(1):sup(1)) = 
458     &         Variable2%array1(inf2(1):sup2(1))
459      CASE (2)
460     
461      Call Agrif_Copy_2d(Variable%array2,Variable2%array2,
462     &  lbound(Variable%array2),
463     &  lbound(Variable2%array2),
464     &  inf,sup,inf2,sup2)
465         
466      CASE (3)
467
468      Call Agrif_Copy_3d(Variable%array3,Variable2%array3,
469     &  lbound(Variable%array3),
470     &  lbound(Variable2%array3),
471     &  inf,sup,inf2,sup2)
472
473      CASE (4)
474     
475      Call Agrif_Copy_4d(Variable%array4,Variable2%array4,
476     &  lbound(Variable%array4),
477     &  lbound(Variable2%array4),
478     &  inf,sup,inf2,sup2)
479     
480      CASE (5)
481        Variable%array5(inf(1):sup(1),
482     &                         inf(2):sup(2), 
483     &                         inf(3):sup(3),
484     &                         inf(4):sup(4), 
485     &                         inf(5):sup(5)) = 
486     &         Variable2%array5(inf2(1):sup2(1),
487     &                          inf2(2):sup2(2),
488     &                          inf2(3):sup2(3),
489     &                          inf2(4):sup2(4),
490     &                          inf2(5):sup2(5))
491      CASE (6)
492        Variable%array6(inf(1):sup(1),
493     &                         inf(2):sup(2),
494     &                         inf(3):sup(3),
495     &                         inf(4):sup(4),
496     &                         inf(5):sup(5),
497     &                         inf(6):sup(6)) = 
498     &         Variable2%array6(inf2(1):sup2(1),
499     &                          inf2(2):sup2(2),
500     &                          inf2(3):sup2(3),
501     &                          inf2(4):sup2(4),
502     &                          inf2(5):sup2(5),
503     &                          inf2(6):sup2(6))
504      END SELECT
505C
506      return
507C
508      End Subroutine Agrif_nbdim_VarEQvar
509C
510C     **************************************************************************
511CCC   Subroutine Agrif_nbdim_Full_VarEQvar
512C     **************************************************************************
513C
514      Subroutine Agrif_nbdim_Full_VarEQvar(Variable,Variable2,
515     &                                nbdim)
516C
517CCC   Description:
518CCC   This subroutine is used to give the value of the table Variable2 
519C        to the table Variable
520C
521C     Declarations:
522C     
523     
524C
525C     Arguments     
526C
527      TYPE(AGRIF_Variable), Pointer     :: Variable
528      TYPE(AGRIF_Variable), Pointer     :: Variable2
529      INTEGER                  :: nbdim       ! dimension of the table
530C
531C     Local variables       
532C
533      SELECT CASE (nbdim)
534      CASE (1)
535          Variable%array1 = Variable2%array1
536      CASE (2)
537          Variable%array2 = Variable2%array2
538      CASE (3)
539          Variable%array3 = Variable2%array3
540      CASE (4)
541          Variable%array4 = Variable2%array4
542      CASE (5)
543          Variable%array5 = Variable2%array5
544      CASE (6)
545          Variable%array6 = Variable2%array6
546      END SELECT
547C
548      return
549C
550      End Subroutine Agrif_nbdim_Full_VarEQvar
551C
552C
553
554#ifdef AGRIF_MPI
555C     **************************************************************************
556CCC   Subroutine GiveAgrif_SpecialValueToTab_mpi
557C     **************************************************************************
558C
559      Subroutine GiveAgrif_SpecialValueToTab_mpi(Variable1,Variable2,
560     &                  bound1,lower,upper,Value,nbdim)
561C
562CCC   Description:
563CCC   
564C
565C     Declarations:
566C     
567     
568C
569C     Arguments     
570C
571      TYPE(AGRIF_VARIABLE), Pointer    :: Variable1
572      TYPE(AGRIF_VARIABLE), Pointer    :: Variable2
573      INTEGER                  :: nbdim
574      INTEGER,DIMENSION(:,:,:) :: bound1
575      INTEGER,DIMENSION(nbdim) :: lower,upper
576      REAL                     :: Value
577C
578C     Local variables       
579C
580      SELECT CASE (nbdim)
581      CASE (1)
582             Where (Variable1 % array1(
583     &           bound1(lower(1),1,2):bound1(upper(1),1,2)) 
584     &            == Value)
585             Variable2 % array1(lower(1):upper(1))
586     &                        = Value
587C     
588              End Where
589      CASE (2)
590             Where (Variable1 % array2(
591     &           bound1(lower(1),1,2):bound1(upper(1),1,2),
592     &           bound1(lower(2),2,2):bound1(upper(2),2,2)) 
593     &            == Value)
594             Variable2 % array2(lower(1):upper(1),
595     &                          lower(2):upper(2))
596     &                        = Value
597C     
598              End Where
599      CASE (3)
600             Where (Variable1 % array3(
601     &           bound1(lower(1),1,2):bound1(upper(1),1,2),
602     &           bound1(lower(2),2,2):bound1(upper(2),2,2), 
603     &           bound1(lower(3),3,2):bound1(upper(3),3,2)) 
604     &            == Value)
605             Variable2 % array3(lower(1):upper(1),
606     &                          lower(2):upper(2),
607     &                          lower(3):upper(3))
608     &                         = Value
609C     
610              End Where
611      CASE (4)
612             Where (Variable1 % array4(
613     &           bound1(lower(1),1,2):bound1(upper(1),1,2),
614     &           bound1(lower(2),2,2):bound1(upper(2),2,2), 
615     &           bound1(lower(3),3,2):bound1(upper(3),3,2),
616     &           bound1(lower(4),4,2):bound1(upper(4),4,2)) 
617     &            == Value)
618             Variable2 % array4(lower(1):upper(1),
619     &                          lower(2):upper(2),
620     &                          lower(3):upper(3),
621     &                          lower(4):upper(4))
622     &                        = Value
623C     
624              End Where
625      CASE (5)
626             Where (Variable1 % array5(
627     &           bound1(lower(1),1,2):bound1(upper(1),1,2),
628     &           bound1(lower(2),2,2):bound1(upper(2),2,2),
629     &           bound1(lower(3),3,2):bound1(upper(3),3,2),
630     &           bound1(lower(4),4,2):bound1(upper(4),4,2),
631     &           bound1(lower(5),5,2):bound1(upper(5),5,2)) 
632     &            == Value)
633             Variable2 % array5(lower(1):upper(1),
634     &                          lower(2):upper(2),
635     &                          lower(3):upper(3),
636     &                          lower(4):upper(4),
637     &                          lower(5):upper(5))
638     &                        = Value
639C     
640              End Where
641      CASE (6)
642             Where (Variable1 % array6(
643     &           bound1(lower(1),1,2):bound1(upper(1),1,2),
644     &           bound1(lower(2),2,2):bound1(upper(2),2,2),
645     &           bound1(lower(2),3,2):bound1(upper(3),3,2),
646     &           bound1(lower(4),4,2):bound1(upper(4),4,2),
647     &           bound1(lower(5),5,2):bound1(upper(5),5,2),
648     &           bound1(lower(6),6,2):bound1(upper(6),6,2)) 
649     &            == Value)
650             Variable2 % array6(lower(1):upper(1),
651     &                          lower(2):upper(2),
652     &                          lower(3):upper(3),
653     &                          lower(4):upper(4),
654     &                          lower(5):upper(5),
655     &                          lower(6):upper(6))
656     &                        = Value
657C     
658              End Where
659      END SELECT
660C
661      return
662C
663      End Subroutine GiveAgrif_SpecialValueToTab_mpi   
664#else
665C     **************************************************************************
666CCC   Subroutine GiveAgrif_SpecialValueToTab
667C     **************************************************************************
668C
669      Subroutine GiveAgrif_SpecialValueToTab(Variable1,Variable2,
670     &                  lower,upper,Value,nbdim)
671C
672CCC   Description:
673CCC   
674C
675C     Declarations:
676C     
677     
678C
679C     Arguments     
680C
681      TYPE(AGRIF_VARIABLE), Pointer    :: Variable1
682      TYPE(AGRIF_VARIABLE), Pointer    :: Variable2
683      INTEGER                  :: nbdim
684      INTEGER,DIMENSION(nbdim) :: lower,upper
685      REAL                     :: Value
686C
687C     Local variables       
688C
689      SELECT CASE (nbdim)
690      CASE (1)
691             Where (Variable1 % array1(
692     &           lower(1):upper(1))
693     &            == Value)
694             Variable2 % array1(lower(1):upper(1))
695     &                        = Value
696C     
697              End Where
698      CASE (2)
699             Where (Variable1 % array2(
700     &           lower(1):upper(1),
701     &           lower(2):upper(2)) 
702     &            == Value)
703             Variable2 % array2(lower(1):upper(1),
704     &                          lower(2):upper(2))
705     &                        = Value
706C     
707              End Where
708      CASE (3)
709             Where (Variable1 % array3(
710     &           lower(1):upper(1),
711     &           lower(2):upper(2), 
712     &           lower(3):upper(3)) 
713     &            == Value)
714             Variable2 % array3(lower(1):upper(1),
715     &                          lower(2):upper(2),
716     &                          lower(3):upper(3))
717     &                         = Value
718C     
719              End Where
720      CASE (4)
721             Where (Variable1 % array4(
722     &           lower(1):upper(1),
723     &           lower(2):upper(2), 
724     &           lower(3):upper(3),
725     &           lower(4):upper(4)) 
726     &            == Value)
727             Variable2 % array4(lower(1):upper(1),
728     &                          lower(2):upper(2),
729     &                          lower(3):upper(3),
730     &                          lower(4):upper(4))
731     &                        = Value
732C     
733              End Where
734      CASE (5)
735             Where (Variable1 % array5(
736     &           lower(1):upper(1),
737     &           lower(2):upper(2),
738     &           lower(3):upper(3),
739     &           lower(4):upper(4),
740     &           lower(5):upper(5)) 
741     &            == Value)
742             Variable2 % array5(lower(1):upper(1),
743     &                          lower(2):upper(2),
744     &                          lower(3):upper(3),
745     &                          lower(4):upper(4),
746     &                          lower(5):upper(5))
747     &                        = Value
748C     
749              End Where
750      CASE (6)
751             Where (Variable1 % array6(
752     &           lower(1):upper(1),
753     &           lower(2):upper(2),
754     &           lower(2):upper(3),
755     &           lower(4):upper(4),
756     &           lower(5):upper(5),
757     &           lower(6):upper(6)) 
758     &            == Value)
759             Variable2 % array6(lower(1):upper(1),
760     &                          lower(2):upper(2),
761     &                          lower(3):upper(3),
762     &                          lower(4):upper(4),
763     &                          lower(5):upper(5),
764     &                          lower(6):upper(6))
765     &                        = Value
766C     
767              End Where
768      END SELECT
769C
770      return
771C
772      End Subroutine GiveAgrif_SpecialValueToTab   
773#endif
774C
775C
776#ifdef AGRIF_MPI
777C     **************************************************************************
778CCC   Subroutine Where_ValTabToTab_mpi
779C     **************************************************************************
780C
781      Subroutine Where_ValTabToTab_mpi(
782     &                  Variable1,Variable2,
783     &                  lower,upper,Value,nbdim)
784C
785CCC   Description:
786CCC   
787C
788C     Declarations:
789C     
790     
791C
792C     Arguments     
793C
794      TYPE(AGRIF_VARIABLE), Pointer     :: Variable1
795      TYPE(AGRIF_VARIABLE), Pointer     :: Variable2
796      INTEGER                  :: nbdim
797      INTEGER,DIMENSION(nbdim) :: lower,upper
798      REAL                     :: Value
799      INTEGER :: i,j,k,l,m,n
800C
801C     Local variables       
802C
803      SELECT CASE (nbdim)
804      CASE (1)
805            DO i = lower(1),upper(1)
806              IF (variable1%array1(i) == Value) then
807                variable1%array1(i)=Variable2%array1(i)
808              ENDIF
809            ENDDO
810      CASE (2)
811            DO j = lower(2),upper(2)
812            DO i = lower(1),upper(1)
813              IF (variable1%array2(i,j) == Value) then
814                variable1%array2(i,j)=Variable2%array2(i,j)
815              ENDIF
816            ENDDO
817            ENDDO
818      CASE (3)
819            DO k = lower(3),upper(3)
820            DO j = lower(2),upper(2)
821            DO i = lower(1),upper(1)
822              IF (variable1%array3(i,j,k) == Value) then
823                variable1%array3(i,j,k)=Variable2%array3(i,j,k)
824              ENDIF
825            ENDDO
826            ENDDO
827            ENDDO
828      CASE (4)
829            DO l = lower(4),upper(4)
830            DO k = lower(3),upper(3)
831            DO j = lower(2),upper(2)
832            DO i = lower(1),upper(1)
833              IF (variable1%array4(i,j,k,l) == Value) then
834                variable1%array4(i,j,k,l)=Variable2%array4(i,j,k,l)
835              ENDIF
836            ENDDO
837            ENDDO
838            ENDDO
839            ENDDO
840      CASE (5)
841            DO m = lower(5),upper(5)
842            DO l = lower(4),upper(4)
843            DO k = lower(3),upper(3)
844            DO j = lower(2),upper(2)
845            DO i = lower(1),upper(1)
846              IF (variable1%array5(i,j,k,l,m) == Value) then
847              variable1%array5(i,j,k,l,m)=Variable2%array5(i,j,k,l,m)
848              ENDIF
849            ENDDO
850            ENDDO
851            ENDDO
852            ENDDO
853            ENDDO
854      CASE (6)
855            DO n = lower(6),upper(6)
856            DO m = lower(5),upper(5)
857            DO l = lower(4),upper(4)
858            DO k = lower(3),upper(3)
859            DO j = lower(2),upper(2)
860            DO i = lower(1),upper(1)
861              IF (variable1%array6(i,j,k,l,m,n) == Value) then
862            variable1%array6(i,j,k,l,m,n)=Variable2%array6(i,j,k,l,m,n)
863              ENDIF
864            ENDDO
865            ENDDO
866            ENDDO
867            ENDDO
868            ENDDO
869            ENDDO
870      END SELECT
871C
872      return
873C
874      End Subroutine Where_ValTabToTab_mpi   
875#endif
876
877C     **************************************************************************
878CCC   Subroutine PreProcessToInterpOrUpdate
879C     **************************************************************************
880C
881      Subroutine PreProcessToInterpOrUpdate(parent,child,
882     &             petab_Child,
883     &             pttab_Child,pttab_Parent,
884     &             s_Child,s_Parent,
885     &             ds_Child,ds_Parent,
886     &             nbdim)
887C
888CCC   Description:
889CCC   
890C
891C     Declarations:
892C     
893C     arguments                                   
894      TYPE(AGRIF_PVariable) :: parent   ! Variable on the parent grid
895      TYPE(AGRIF_PVariable) :: child    ! Variable on the child grid
896      INTEGER :: nbdim                 
897      INTEGER,DIMENSION(6) :: pttab_child 
898      INTEGER,DIMENSION(6) :: petab_child     
899      INTEGER,DIMENSION(6) :: pttab_parent 
900      TYPE(AGRIF_Variable), Pointer :: root ! Pointer on the variable of the
901                                            ! root grid
902      TYPE(Agrif_Grid), Pointer :: Agrif_Child_Gr,Agrif_Parent_Gr
903      REAL, DIMENSION(6) :: s_child,s_parent
904      REAL, DIMENSION(6) :: ds_child,ds_parent
905C     locals variables
906      INTEGER :: n
907     
908C
909C     Arguments     
910C
911
912C
913C     Local variables       
914C
915      Agrif_Child_Gr => Agrif_Curgrid
916      Agrif_Parent_Gr => Agrif_Curgrid % parent
917C
918      root => child % var % root_var 
919C
920C     Number of dimensions of the current grid
921      nbdim = root % nbdim
922C     
923      do n=1,nbdim
924C           
925        Select case(root % interptab(n))
926C
927C       Value of interptab(n) can be either x,y,z or N for a no space 
928C       DIMENSION           
929C
930C         The DIMENSION is 'x'
931          case('x')
932C
933            pttab_Child(n) = root % point(1)
934C           
935            pttab_Parent(n) = root % point(1)
936C       
937            s_Child(n) = Agrif_Child_Gr % Agrif_x(1)
938C
939            s_Parent(n) = Agrif_Parent_Gr % Agrif_x(1)
940C       
941            ds_Child(n) = Agrif_Child_Gr % Agrif_d(1)
942C
943            ds_Parent(n) = Agrif_Parent_Gr % Agrif_d(1)
944C                     
945            if (root % posvar(n).EQ.1) then
946C         
947              petab_Child(n) = pttab_Child(n) + Agrif_Child_Gr%nb(1)
948C       
949              else
950C         
951                petab_Child(n) = pttab_Child(n) + 
952     &                              Agrif_Child_Gr%nb(1) - 1
953C         
954                s_Child(n) = s_Child(n) + ds_Child(n)/2.
955C
956                s_Parent(n) = s_Parent(n) + ds_Parent(n)/2.
957C       
958            endif                 
959C
960C         The DIMENSION is 'y'
961          case('y')
962C
963            pttab_Child(n) = root % point(2)
964C           
965            pttab_Parent(n) = root % point(2)
966C       
967            s_Child(n) = Agrif_Child_Gr % Agrif_x(2)
968C
969            s_Parent(n) = Agrif_Parent_Gr % Agrif_x(2) 
970C       
971            ds_Child(n) = Agrif_Child_Gr % Agrif_d(2)
972C
973            ds_Parent(n) = Agrif_Parent_Gr % Agrif_d(2)
974C                     
975            if (root % posvar(n).EQ.1) then
976C         
977             petab_Child(n) = pttab_Child(n) + Agrif_Child_Gr%nb(2)
978C         
979              else
980C         
981                petab_Child(n) = pttab_Child(n) + 
982     &                       Agrif_Child_Gr%nb(2) - 1
983C         
984                s_Child(n) = s_Child(n) + ds_Child(n)/2.
985C
986                s_Parent(n) = s_Parent(n) + ds_Parent(n)/2.
987C       
988            endif
989           
990C
991C         The DIMENSION is 'z'                           
992          case('z')
993C
994            pttab_Child(n) = root % point(3)
995C           
996            pttab_Parent(n) = root % point(3)
997C       
998            s_Child(n) = Agrif_Child_Gr % Agrif_x(3)
999C
1000            s_Parent(n) = Agrif_Parent_Gr % Agrif_x(3)
1001C       
1002            ds_Child(n) = Agrif_Child_Gr % Agrif_d(3)
1003C
1004            ds_Parent(n) = Agrif_Parent_Gr % Agrif_d(3)
1005C                     
1006            if (root % posvar(n).EQ.1) then
1007C         
1008             petab_Child(n) = pttab_Child(n) + Agrif_Child_Gr%nb(3)
1009C         
1010              else
1011C         
1012                petab_Child(n) = pttab_Child(n) + 
1013     &                      Agrif_Child_Gr%nb(3) - 1
1014C
1015                s_Child(n) = s_Child(n) + ds_Child(n)/2.
1016C
1017                s_Parent(n) = s_Parent(n) + ds_Parent(n)/2.
1018C       
1019            endif       
1020C 
1021C         The DIMENSION is not space                           
1022          case('N')
1023C
1024C         The next coefficients are calculated in order to do a simple copy of 
1025C         values of the grid variable when the procedure of interpolation is 
1026C         called for this DIMENSION
1027C     
1028            Call Agrif_nbdim_Get_bound(child % var,
1029     &                           pttab_Child(n),petab_Child(n),n,nbdim)
1030C
1031C           No interpolation but only a copy of the values of the grid variable
1032C
1033            pttab_Parent(n) = pttab_Child(n)
1034C             
1035            s_Child(n)=0.
1036C     
1037            s_Parent(n)=0. 
1038C     
1039            ds_Child(n)=1.
1040C     
1041            ds_Parent(n)=1.
1042C
1043        End select
1044C           
1045      enddo     
1046C
1047      return
1048C
1049      End Subroutine PreProcessToInterpOrUpdate     
1050
1051#ifdef AGRIF_MPI
1052C
1053C     **************************************************************************
1054CCC   Subroutine GetLocalBoundaries
1055C     **************************************************************************
1056C
1057      Subroutine GetLocalBoundaries(tab1,tab2,i,lb,ub,deb,fin)
1058C
1059CCC   Descritpion:
1060C 
1061C
1062C     Declarations:
1063C
1064
1065C
1066C
1067C     Scalar arguments
1068      INTEGER  ::  tab1,tab2
1069      INTEGER  ::  i
1070      INTEGER  ::  lb,ub
1071      INTEGER  ::  deb,fin
1072C
1073C     Local scalars
1074      INTEGER  ::  imin,imax
1075      INTEGER  ::  i1,i2
1076C
1077C
1078      Call AGRIF_InvLoc(lb,AGRIF_ProcRank,i,imin)
1079C
1080      Call AGRIF_InvLoc(ub,AGRIF_ProcRank,i,imax)
1081C
1082C
1083      if (imin > tab2) then
1084C
1085          i1 = imax - imin
1086C
1087        else
1088C
1089          i1 = max(tab1 - imin,0)
1090C
1091      endif
1092C
1093      if (imax < tab1) then
1094C
1095          i2 = -(imax - imin)
1096C
1097        else
1098C
1099          i2 = min(tab2 - imax,0)
1100C
1101      endif
1102C
1103      deb = lb + i1
1104C
1105      fin = ub + i2
1106C
1107C
1108      End Subroutine GetLocalBoundaries
1109C
1110#endif
1111C
1112C
1113#ifdef AGRIF_MPI
1114C
1115C
1116C     **************************************************************************
1117CCC   Subroutine Agrif_GlobtoLocInd2
1118C     **************************************************************************
1119C
1120      Subroutine Agrif_GlobtoLocInd2(tabarray,lboundl,uboundl,tab1,tab2,
1121     &                              nbdim,rank,member)
1122C
1123CCC   Description:
1124CCC   For a global index located on the current processor, tabarray gives the 
1125CCC   corresponding local index   
1126C
1127C
1128C     Declarations:
1129C
1130
1131C
1132C     Arguments
1133      INTEGER :: nbdim
1134      INTEGER,DIMENSION(nbdim) :: tab1,tab2
1135      INTEGER,DIMENSION(nbdim,2,2 ) :: tabarray
1136      INTEGER,DIMENSION(nbdim) :: lboundl,uboundl
1137      INTEGER :: rank
1138      LOGICAL :: member
1139C   
1140C     Local variables
1141      INTEGER :: i,i1,k
1142      INTEGER :: nbloc(nbdim)
1143C
1144C
1145      tabarray(:,1,:) =  HUGE(1)
1146      tabarray(:,2,:) =  -HUGE(1)
1147
1148      nbloc = 0
1149C       
1150      do i = 1,nbdim
1151C       
1152        Call Agrif_Invloc(lboundl(i),rank,i,i1)
1153       
1154        do k=tab1(i)+lboundl(i)-i1,tab2(i)+lboundl(i)-i1
1155          IF ((k .GE. lboundl(i)) .AND. (k.LE.uboundl(i))) THEN
1156            nbloc(i) = 1
1157            tabarray(i,1,1) = min(tabarray(i,1,1),k-lboundl(i)+i1)
1158            tabarray(i,2,1) = max(tabarray(i,2,1),k-lboundl(i)+i1)
1159       
1160            tabarray(i,1,2) = min(tabarray(i,1,2),k)
1161            tabarray(i,2,2) = max(tabarray(i,2,2),k)
1162          ENDIF
1163        enddo
1164C
1165      enddo
1166
1167      member = .FALSE.
1168      IF (sum(nbloc) == nbdim) member = .TRUE.
1169C
1170      Return
1171C
1172C
1173      End Subroutine Agrif_GlobtoLocInd2
1174C
1175#endif     
1176
1177      Subroutine Agrif_Copy_2d(tabout,tabin,l,m,inf,sup,inf2,sup2)
1178      integer,dimension(2) :: l,m,inf,sup,inf2,sup2
1179      real,target,dimension(l(1):,l(2):) :: tabout
1180      real,target,dimension(m(1):,m(2):) :: tabin
1181          tabout(inf(1):sup(1),
1182     &                         inf(2):sup(2)) = 
1183     &         tabin(inf2(1):sup2(1),
1184     &                          inf2(2):sup2(2))
1185      End Subroutine Agrif_Copy_2d
1186     
1187      Subroutine Agrif_Copy_3d(tabout,tabin,l,m,inf,sup,inf2,sup2)
1188      integer,dimension(3) :: l,m,inf,sup,inf2,sup2
1189      real,target,dimension(l(1):,l(2):,l(3):) :: tabout
1190      real,target,dimension(m(1):,m(2):,m(3):) :: tabin
1191          tabout(inf(1):sup(1),
1192     &                         inf(2):sup(2), 
1193     &                         inf(3):sup(3)) = 
1194     &         tabin(inf2(1):sup2(1),
1195     &                          inf2(2):sup2(2),
1196     &                          inf2(3):sup2(3))
1197      End Subroutine Agrif_Copy_3d
1198     
1199      Subroutine Agrif_Copy_4d(tabout,tabin,l,m,inf,sup,inf2,sup2)
1200      integer,dimension(4) :: l,m,inf,sup,inf2,sup2
1201      real,target,dimension(l(1):,l(2):,l(3):,l(4):) :: tabout
1202      real,target,dimension(m(1):,m(2):,m(3):,m(4):) :: tabin
1203          tabout(inf(1):sup(1),
1204     &                         inf(2):sup(2), 
1205     &                         inf(3):sup(3), 
1206     &                         inf(4):sup(4)) = 
1207     &         tabin(inf2(1):sup2(1),
1208     &                          inf2(2):sup2(2),
1209     &                          inf2(3):sup2(3),
1210     &                          inf2(4):sup2(4))
1211      End Subroutine Agrif_Copy_4d     
1212
1213      End Module Agrif_Arrays
Note: See TracBrowser for help on using the repository browser.