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.
modcurgridfunctions.F90 in vendors/AGRIF/CMEMS_2020/AGRIF_FILES – NEMO

source: vendors/AGRIF/CMEMS_2020/AGRIF_FILES/modcurgridfunctions.F90 @ 10725

Last change on this file since 10725 was 10725, checked in by rblod, 5 years ago

Update agrif library and conv see ticket #2129

  • Property svn:keywords set to Id
File size: 42.1 KB
Line 
1!
2! $Id$
3!
4!     AGRIF (Adaptive Grid Refinement In Fortran)
5!
6!     Copyright (C) 2003 Laurent Debreu (Laurent.Debreu@imag.fr)
7!                        Christophe Vouland (Christophe.Vouland@imag.fr)
8!
9!     This program is free software; you can redistribute it and/or modify
10!     it under the terms of the GNU General Public License as published by
11!     the Free Software Foundation; either version 2 of the License, or
12!     (at your option) any later version.
13!
14!     This program is distributed in the hope that it will be useful,
15!     but WITHOUT ANY WARRANTY; without even the implied warranty of
16!     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17!     GNU General Public License for more details.
18!
19!     You should have received a copy of the GNU General Public License
20!     along with this program; if not, write to the Free Software
21!     Foundation, Inc., 59 Temple Place-  Suite 330, Boston, MA 02111-1307, USA.
22!
23!> Module to define some procedures concerning the current grid
24!
25module Agrif_CurgridFunctions
26!
27    use Agrif_Init
28!
29    implicit none
30!
31
32    interface Agrif_Parent
33        module procedure Agrif_Parent_Real_4,   &
34                         Agrif_Parent_Real_8,   &
35                         Agrif_Parent_Array2_Real_8,   &
36                         Agrif_Parent_Integer, &
37                         Agrif_Parent_Character, &
38                         Agrif_Parent_Logical
39    end interface
40   
41contains
42!
43!===================================================================================================
44!  function Agrif_rel_dt
45!
46!> Returns the time step of the current grid, relatively to the root grid (for which dt=1.).
47!---------------------------------------------------------------------------------------------------
48function Agrif_rel_dt ( ) result( rel_dt )
49!---------------------------------------------------------------------------------------------------
50    integer :: i
51    real    :: rel_dt
52!
53    rel_dt = 1.
54!
55    do i = 1,Agrif_Probdim
56        rel_dt = min(rel_dt, Agrif_Curgrid % Agrif_dt(i))
57    enddo
58!---------------------------------------------------------------------------------------------------
59end function Agrif_rel_dt
60!===================================================================================================
61!
62!===================================================================================================
63!  function Agrif_rel_idt
64!
65!> Returns the time refinement factor of the current grid, relatively to the root grid (for which idt=1).
66!---------------------------------------------------------------------------------------------------
67function Agrif_rel_idt ( ) result( rel_idt )
68!---------------------------------------------------------------------------------------------------
69    integer :: rel_idt
70!
71    rel_idt = nint(1./Agrif_rel_dt())
72!---------------------------------------------------------------------------------------------------
73end function Agrif_rel_idt
74!===================================================================================================
75!
76!===================================================================================================
77!  function Agrif_IRhot
78!
79!> Returns the time refinement factor of the current grid.
80!---------------------------------------------------------------------------------------------------
81function Agrif_IRhot ( ) result( irhot )
82!---------------------------------------------------------------------------------------------------
83    integer :: i, irhot
84!
85    irhot = 1
86!
87    do i = 1,Agrif_Probdim
88        irhot = max(irhot, Agrif_Curgrid % timeref(i))
89    enddo
90!---------------------------------------------------------------------------------------------------
91end function Agrif_IRhot
92!===================================================================================================
93!
94!===================================================================================================
95!  function Agrif_Rhot
96!
97!> Returns the time refinement factor of the current grid.
98!---------------------------------------------------------------------------------------------------
99function Agrif_Rhot ( ) result( rhot )
100!---------------------------------------------------------------------------------------------------
101    real    :: rhot
102!
103    rhot = float(Agrif_IRhot())
104!---------------------------------------------------------------------------------------------------
105end function Agrif_Rhot
106!===================================================================================================
107!
108!===================================================================================================
109!  function Agrif_Parent_IRhot
110!
111!> Returns the time refinement factor of the parent of the current grid.
112!---------------------------------------------------------------------------------------------------
113function Agrif_Parent_IRhot ( ) result( irhot )
114!---------------------------------------------------------------------------------------------------
115    integer :: i, irhot
116!
117    irhot = 1
118!
119    do i = 1,Agrif_Probdim
120        irhot = max(irhot, Agrif_Curgrid % parent % timeref(i))
121    enddo
122!---------------------------------------------------------------------------------------------------
123end function Agrif_Parent_IRhot
124!===================================================================================================
125!
126!===================================================================================================
127!  function Agrif_Parent_Rhot
128!
129!> Returns the time refinement factor of the parent of the current grid.
130!---------------------------------------------------------------------------------------------------
131function Agrif_Parent_Rhot ( ) result( rhot )
132!---------------------------------------------------------------------------------------------------
133    real :: rhot
134!
135    rhot = float(Agrif_Parent_IRhot())
136!---------------------------------------------------------------------------------------------------
137end function Agrif_Parent_Rhot
138!===================================================================================================
139!
140!===================================================================================================
141!  function Agrif_Nbstepint
142!
143!> function for the calculation of the coefficients used for the time interpolation
144!! (module #Agrif_Boundary).
145!---------------------------------------------------------------------------------------------------
146function Agrif_Nbstepint ( )
147!---------------------------------------------------------------------------------------------------
148    integer :: Agrif_nbstepint ! result
149!
150    Agrif_nbstepint = mod(Agrif_Curgrid % ngridstep, Agrif_iRhot())
151!---------------------------------------------------------------------------------------------------
152end function Agrif_Nbstepint
153!===================================================================================================
154!
155!===================================================================================================
156!  function Agrif_Parent_Nbstepint
157!
158!> function for the calculation of the coefficients used for the time interpolation
159!! (module #Agrif_Boundary).
160!---------------------------------------------------------------------------------------------------
161function Agrif_Parent_Nbstepint ( )
162!---------------------------------------------------------------------------------------------------
163    integer :: Agrif_Parent_Nbstepint ! result
164!
165    Agrif_Parent_Nbstepint = mod(Agrif_Curgrid % parent % ngridstep, int(Agrif_Parent_Rhot()))
166!---------------------------------------------------------------------------------------------------
167end function Agrif_Parent_Nbstepint
168!===================================================================================================
169!
170!===================================================================================================
171!  subroutine Agrif_InterpNearBorderX
172!
173!> Allows to interpolate (in the x direction) on a near border of the current grid if this one
174!! has a common border with the root coarse grid.
175!---------------------------------------------------------------------------------------------------
176subroutine Agrif_InterpNearBorderX ( )
177!---------------------------------------------------------------------------------------------------
178    Agrif_Curgrid % NearRootBorder(1) = .FALSE.
179!---------------------------------------------------------------------------------------------------
180end subroutine Agrif_InterpNearBorderX
181!===================================================================================================
182!
183!===================================================================================================
184!  subroutine Agrif_InterpDistantBorderX
185!
186!> Allows to interpolate (in the x direction) on a distant border of the current grid if this one
187!! has a common border with the root coarse grid.
188!---------------------------------------------------------------------------------------------------
189subroutine Agrif_InterpDistantBorderX ( )
190!---------------------------------------------------------------------------------------------------
191    Agrif_Curgrid % DistantRootBorder(1) = .FALSE.
192!---------------------------------------------------------------------------------------------------
193end subroutine Agrif_InterpDistantBorderX
194!===================================================================================================
195!
196!===================================================================================================
197!  subroutine Agrif_InterpNearBorderY
198!
199!> Allows to interpolate (in the y direction) on a near border of the current grid if this one
200!! has a common border with the root coarse grid.
201!---------------------------------------------------------------------------------------------------
202subroutine Agrif_InterpNearBorderY ( )
203!---------------------------------------------------------------------------------------------------
204    Agrif_Curgrid % NearRootBorder(2) = .FALSE.
205!---------------------------------------------------------------------------------------------------
206end subroutine Agrif_InterpNearBorderY
207!===================================================================================================
208!
209!===================================================================================================
210!  subroutine Agrif_InterpDistantBorderY
211!
212!> Allows to interpolate (in the y direction) on a distant border of the current grid if this one
213!! has a common border with the root coarse grid.
214!---------------------------------------------------------------------------------------------------
215subroutine Agrif_InterpDistantBorderY ( )
216!---------------------------------------------------------------------------------------------------
217    Agrif_Curgrid % DistantRootBorder(2) = .FALSE.
218!---------------------------------------------------------------------------------------------------
219end subroutine Agrif_InterpDistantBorderY
220!===================================================================================================
221!
222!===================================================================================================
223!  subroutine Agrif_InterpNearBorderZ
224!
225!> Allows to interpolate (in the z direction) on a near border of the current grid if this one
226!! has a common border with the root coarse grid.
227!---------------------------------------------------------------------------------------------------
228subroutine Agrif_InterpNearBorderZ ( )
229!---------------------------------------------------------------------------------------------------
230    Agrif_Curgrid % NearRootBorder(3) = .FALSE.
231!---------------------------------------------------------------------------------------------------
232end subroutine Agrif_InterpNearBorderZ
233!===================================================================================================
234!
235!===================================================================================================
236!  subroutine Agrif_InterpDistantBorderZ
237!
238!> Allows to interpolate (in the z direction) on a distant border of the current grid if this one
239!! has a common border with the root coarse grid.
240!---------------------------------------------------------------------------------------------------
241subroutine Agrif_InterpDistantBorderZ()
242!---------------------------------------------------------------------------------------------------
243    Agrif_Curgrid % DistantRootBorder(3) = .FALSE.
244!---------------------------------------------------------------------------------------------------
245end subroutine Agrif_InterpDistantBorderZ
246!===================================================================================================
247!
248!===================================================================================================
249!  function Agrif_Parent_Nb_Step
250!
251!> Returns the number of time steps of the parent of the current grid.
252!---------------------------------------------------------------------------------------------------
253function Agrif_Parent_Nb_Step ( )
254!---------------------------------------------------------------------------------------------------
255    integer :: Agrif_Parent_Nb_Step ! Result
256!
257    if (Agrif_Root()) then
258        Agrif_Parent_Nb_Step = -1
259    else
260        Agrif_Parent_Nb_Step = Agrif_Curgrid % parent % ngridstep
261    endif
262!---------------------------------------------------------------------------------------------------
263end function Agrif_Parent_Nb_Step
264!===================================================================================================
265!
266!===================================================================================================
267!  function Agrif_Root
268!
269!> Indicates if the current grid is or not the root grid.
270!---------------------------------------------------------------------------------------------------
271function Agrif_Root ( )
272!---------------------------------------------------------------------------------------------------
273    logical :: Agrif_Root ! Result
274!
275    Agrif_Root = (Agrif_Curgrid % fixedrank == 0)
276!---------------------------------------------------------------------------------------------------
277end function Agrif_Root
278!===================================================================================================
279!
280!===================================================================================================
281!  function Agrif_GrandMother
282!
283!> Indicates if the current grid is or not the root grid.
284!---------------------------------------------------------------------------------------------------
285function Agrif_GrandMother ( )
286!---------------------------------------------------------------------------------------------------
287    logical :: Agrif_GrandMother ! Result
288!
289    Agrif_GrandMother = Agrif_Curgrid % grand_mother_grid
290!---------------------------------------------------------------------------------------------------
291end function Agrif_GrandMother
292!===================================================================================================
293!
294!===================================================================================================
295!  function Agrif_Parent_Root
296!
297!> Indicates if the parent of the current grid is or not the root grid.
298!---------------------------------------------------------------------------------------------------
299function Agrif_Parent_Root ( )
300!---------------------------------------------------------------------------------------------------
301    logical :: Agrif_Parent_Root ! Result
302!
303    Agrif_Parent_Root = (Agrif_Curgrid % parent % fixedrank == 0)
304!---------------------------------------------------------------------------------------------------
305end function Agrif_Parent_Root
306!===================================================================================================
307!
308!===================================================================================================
309!  function Agrif_Fixed
310!
311!> Returns the number of the current grid.
312!---------------------------------------------------------------------------------------------------
313function Agrif_Fixed ( )
314!---------------------------------------------------------------------------------------------------
315    integer :: Agrif_Fixed   ! Result
316!
317    if (Agrif_Curgrid % fixed) then
318        Agrif_Fixed = Agrif_Curgrid % fixedrank
319    else
320        Agrif_Fixed = -1
321    endif
322!---------------------------------------------------------------------------------------------------
323end function Agrif_Fixed
324!===================================================================================================
325!
326!===================================================================================================
327!  function Agrif_Parent_Fixed
328!
329!> Returns the number of the parent of the current grid.
330!---------------------------------------------------------------------------------------------------
331function Agrif_Parent_Fixed ( )
332!---------------------------------------------------------------------------------------------------
333    integer :: Agrif_Parent_Fixed   ! Result
334!
335    if (Agrif_Curgrid % parent % fixed) then
336        Agrif_Parent_Fixed = Agrif_Curgrid % parent % fixedrank
337    else
338        Agrif_Parent_Fixed = 0
339    endif
340!---------------------------------------------------------------------------------------------------
341end function Agrif_Parent_Fixed
342!===================================================================================================
343!
344!===================================================================================================
345!  function Agrif_Is_Fixed
346!
347!> Returns .TRUE. if the current grid is fixed.
348!---------------------------------------------------------------------------------------------------
349function Agrif_Is_Fixed ( )
350!---------------------------------------------------------------------------------------------------
351    logical :: Agrif_Is_Fixed   ! Result
352!
353    Agrif_Is_Fixed = Agrif_Curgrid % fixed
354!---------------------------------------------------------------------------------------------------
355end function Agrif_Is_Fixed
356!===================================================================================================
357!
358!===================================================================================================
359!  function Agrif_Parent_Is_Fixed
360!
361!> Returns .TRUE. if the parent of the current grid is fixed.
362!---------------------------------------------------------------------------------------------------
363function Agrif_Parent_Is_Fixed ( )
364!---------------------------------------------------------------------------------------------------
365    logical :: Agrif_Parent_Is_Fixed   ! Result
366!
367    Agrif_Parent_Is_Fixed = Agrif_Curgrid % parent % fixed
368!---------------------------------------------------------------------------------------------------
369end function Agrif_Parent_Is_Fixed
370!===================================================================================================
371!
372!===================================================================================================
373!  function Agrif_CFixed
374!
375!> Returns the number of the current grid.
376!---------------------------------------------------------------------------------------------------
377function Agrif_CFixed ( )
378!---------------------------------------------------------------------------------------------------
379    character(3) :: Agrif_CFixed   ! Result
380!
381    character(3) :: cfixed
382    integer      :: fixed
383!
384    fixed = Agrif_Fixed()
385!
386    if (fixed /= -1) then
387!
388        if (fixed <= 9) then
389            write(cfixed,'(i1)') fixed
390        else
391            write(cfixed,'(i2)') fixed
392        endif
393!
394        Agrif_CFixed = cfixed
395       
396        if (associated(agrif_curgrid,agrif_coarsegrid)) then
397          Agrif_CFixed = 'gm'
398        endif
399!
400    else
401        print*,'Call to Agrif_CFixed() on a moving grid'
402        stop
403    endif
404!---------------------------------------------------------------------------------------------------
405end function Agrif_CFixed
406!===================================================================================================
407!
408!===================================================================================================
409!  function Agrid_Parent_CFixed
410!
411!> Returns the number of the parent of the current grid.
412!---------------------------------------------------------------------------------------------------
413function Agrid_Parent_CFixed ( )
414!---------------------------------------------------------------------------------------------------
415    character(3) :: Agrid_Parent_CFixed   ! Result
416!
417    character(3) :: cfixed
418    integer      :: fixed
419!
420    fixed = Agrif_Parent_Fixed()
421!
422    if(fixed /= -1) then
423!
424        if (fixed <= 9) then
425            write(cfixed,'(i1)')fixed
426        else
427            write(cfixed,'(i2)')fixed
428        endif
429!
430        Agrid_Parent_CFixed=cfixed
431!
432    else
433        print*,'Illegal call to Agrid_Parent_CFixed()'
434        stop
435    endif
436!---------------------------------------------------------------------------------------------------
437end function Agrid_Parent_CFixed
438!===================================================================================================
439!
440!===================================================================================================
441!  subroutine Agrif_ChildGrid_to_ParentGrid
442!
443!> Make the pointer #Agrif_Curgrid point on the parent grid of the current grid.
444!---------------------------------------------------------------------------------------------------
445subroutine Agrif_ChildGrid_to_ParentGrid ( )
446!---------------------------------------------------------------------------------------------------
447    Agrif_Curgrid % parent % save_grid => Agrif_Curgrid
448    call Agrif_Instance(Agrif_Curgrid%parent)
449!---------------------------------------------------------------------------------------------------
450end subroutine Agrif_ChildGrid_to_ParentGrid
451!===================================================================================================
452!
453!===================================================================================================
454!  subroutine Agrif_ParentGrid_to_ChildGrid
455!
456!> Make the pointer #Agrif_Curgrid point on the child grid after having called the
457!! #Agrif_ChildGrid_to_ParentGrid subroutine.
458!---------------------------------------------------------------------------------------------------
459subroutine Agrif_ParentGrid_to_ChildGrid ( )
460!---------------------------------------------------------------------------------------------------
461    call Agrif_Instance(Agrif_Curgrid%save_grid)
462!---------------------------------------------------------------------------------------------------
463end subroutine Agrif_ParentGrid_to_ChildGrid
464!===================================================================================================
465!
466!===================================================================================================
467!  function Agrif_Get_Unit
468!
469!> Returns a unit not connected to any file.
470!---------------------------------------------------------------------------------------------------
471function Agrif_Get_Unit ( )
472!---------------------------------------------------------------------------------------------------
473    integer :: Agrif_Get_Unit  ! Result
474!
475    integer :: n
476    logical :: op
477!
478    integer :: nunit
479    integer :: iii, out, iiimax
480    logical :: bexist
481    integer,dimension(1:1000) :: forbiddenunit
482!
483!   Load forbidden Unit if the file Agrif_forbidenUnit exist
484!
485    INQUIRE(file='Agrif_forbiddenUnit.txt', exist=bexist)
486!
487    if (.not. bexist) then
488!       File Agrif_forbiddenUnit.txt not found
489    else
490        nunit = 777
491        OPEN(nunit,file='Agrif_forbiddenUnit.txt', form='formatted', status="old")
492        iii = 1
493        do while ( .TRUE. )
494            READ(nunit,*, end=99) forbiddenunit(iii)
495            iii = iii + 1
496        enddo
497   99   continue
498        iiimax = iii
499        close(nunit)
500    endif
501!
502    do n = 7,1000
503!
504        INQUIRE(Unit=n,Opened=op)
505!
506        out = 0
507        if ( bexist .AND. (.NOT.op) ) then
508            do iii = 1,iiimax
509                if ( n == forbiddenunit(iii) ) out = 1
510            enddo
511        endif
512!
513        if ( (.NOT.op) .AND. (out == 0) ) exit
514!
515    enddo
516!
517    Agrif_Get_Unit = n
518!---------------------------------------------------------------------------------------------------
519end function Agrif_Get_Unit
520!===================================================================================================
521!
522!===================================================================================================
523!  subroutine Agrif_Set_Extra_Boundary_Cells
524!---------------------------------------------------------------------------------------------------
525subroutine Agrif_Set_Extra_Boundary_Cells ( nb_extra_cells )
526!---------------------------------------------------------------------------------------------------
527    integer, intent(in) :: nb_extra_cells
528!
529    Agrif_Extra_Boundary_Cells = nb_extra_cells
530!---------------------------------------------------------------------------------------------------
531end subroutine Agrif_Set_Extra_Boundary_Cells
532!===================================================================================================
533!
534!===================================================================================================
535!  subroutine Agrif_Set_Efficiency
536!---------------------------------------------------------------------------------------------------
537subroutine Agrif_Set_Efficiency ( eff )
538!---------------------------------------------------------------------------------------------------
539    real, intent(in) :: eff
540!
541    if ( (eff < 0.) .OR. (eff > 1) ) then
542        write(*,*) 'Error Efficiency should be between 0 and 1'
543        stop
544    else
545        Agrif_Efficiency = eff
546    endif
547!---------------------------------------------------------------------------------------------------
548end subroutine Agrif_Set_Efficiency
549!===================================================================================================
550!
551!===================================================================================================
552!  subroutine Agrif_Set_Regridding
553!---------------------------------------------------------------------------------------------------
554subroutine Agrif_Set_Regridding ( regfreq )
555!---------------------------------------------------------------------------------------------------
556    integer, intent(in) :: regfreq
557!
558    if (regfreq < 0) then
559        write(*,*) 'Regridding frequency should be positive'
560        stop
561    else
562        Agrif_Regridding = regfreq
563    endif
564!---------------------------------------------------------------------------------------------------
565end subroutine Agrif_Set_Regridding
566!===================================================================================================
567!
568!===================================================================================================
569!  subroutine Agrif_Set_coeffref_x
570!---------------------------------------------------------------------------------------------------
571subroutine Agrif_Set_coeffref_x ( coeffref )
572!---------------------------------------------------------------------------------------------------
573    integer, intent(in) :: coeffref
574
575      if (coeffref < 0) then
576         write(*,*) 'Coefficient of raffinement should be positive'
577         stop
578      else
579         Agrif_coeffref(1) = coeffref
580      endif
581!---------------------------------------------------------------------------------------------------
582end subroutine Agrif_Set_coeffref_x
583!===================================================================================================
584!
585!===================================================================================================
586!  subroutine Agrif_Set_coeffref_y
587!---------------------------------------------------------------------------------------------------
588subroutine Agrif_Set_coeffref_y ( coeffref )
589!---------------------------------------------------------------------------------------------------
590    integer, intent(in) :: coeffref
591
592    if (coeffref < 0) then
593        write(*,*) 'Coefficient of raffinement should be positive'
594        stop
595    else
596        Agrif_coeffref(2) = coeffref
597    endif
598!---------------------------------------------------------------------------------------------------
599end subroutine Agrif_Set_coeffref_y
600!===================================================================================================
601!
602!===================================================================================================
603!  subroutine Agrif_Set_coeffref_z
604!---------------------------------------------------------------------------------------------------
605subroutine Agrif_Set_coeffref_z ( coeffref )
606!---------------------------------------------------------------------------------------------------
607    integer, intent(in) :: coeffref
608!
609    if (coeffref < 0) then
610        write(*,*) 'Coefficient of raffinement should be positive'
611        stop
612    else
613        Agrif_coeffref(3) = coeffref
614    endif
615!---------------------------------------------------------------------------------------------------
616end subroutine Agrif_Set_coeffref_z
617!===================================================================================================
618!
619!===================================================================================================
620!  subroutine Agrif_Set_coeffreft_x
621!---------------------------------------------------------------------------------------------------
622subroutine Agrif_Set_coeffreft_x ( coeffref )
623!---------------------------------------------------------------------------------------------------
624    integer, intent(in) :: coeffref
625
626    if (coeffref < 0) then
627        write(*,*) 'Coefficient of time raffinement should be positive'
628        stop
629    else
630        Agrif_coeffreft(1) = coeffref
631    endif
632!---------------------------------------------------------------------------------------------------
633end subroutine Agrif_Set_coeffreft_x
634!===================================================================================================
635!
636!===================================================================================================
637!  subroutine Agrif_Set_coeffreft_y
638!---------------------------------------------------------------------------------------------------
639subroutine Agrif_Set_coeffreft_y ( coeffref )
640!---------------------------------------------------------------------------------------------------
641    integer, intent(in) :: coeffref
642!
643    if (coeffref < 0) then
644        write(*,*) 'Coefficient of time raffinement should be positive'
645        stop
646    else
647        Agrif_coeffreft(2) = coeffref
648    endif
649!---------------------------------------------------------------------------------------------------
650end subroutine Agrif_Set_coeffreft_y
651!===================================================================================================
652!
653!===================================================================================================
654!  subroutine Agrif_Set_coeffreft_z
655!---------------------------------------------------------------------------------------------------
656subroutine Agrif_Set_coeffreft_z ( coeffref )
657!---------------------------------------------------------------------------------------------------
658    integer, intent(in) :: coeffref
659
660    if (coeffref < 0) then
661        write(*,*)'Coefficient of time raffinement should be positive'
662        stop
663    else
664        Agrif_coeffreft(3) = coeffref
665    endif
666!---------------------------------------------------------------------------------------------------
667end subroutine Agrif_Set_coeffreft_z
668!===================================================================================================
669!
670!===================================================================================================
671!  subroutine Agrif_Set_Minwidth
672!---------------------------------------------------------------------------------------------------
673subroutine Agrif_Set_Minwidth ( coefminwidth )
674!---------------------------------------------------------------------------------------------------
675    integer, intent(in) :: coefminwidth
676!
677    if (coefminwidth < 0) then
678        write(*,*)'Coefficient of Minwidth should be positive'
679        stop
680    else
681        Agrif_Minwidth = coefminwidth
682    endif
683!---------------------------------------------------------------------------------------------------
684end subroutine Agrif_Set_Minwidth
685!===================================================================================================
686!
687!===================================================================================================
688!  subroutine Agrif_Set_Rafmax
689!---------------------------------------------------------------------------------------------------
690subroutine Agrif_Set_Rafmax ( coefrafmax )
691!---------------------------------------------------------------------------------------------------
692    integer, intent(in) :: coefrafmax
693!
694    integer :: i
695    real    :: res
696!
697    if (coefrafmax < 0) then
698        write(*,*)'Coefficient of  should be positive'
699        stop
700    else
701        res = 1.
702        do i = 1,coefrafmax-1
703            res = res * FLOAT(Agrif_coeffref(1))
704        enddo
705        if ( res == 0 ) res = 1
706        Agrif_Mind(1) = 1. / res
707!
708        res = 1.
709        do i = 1,coefrafmax-1
710            res = res * FLOAT(Agrif_coeffref(2))
711        enddo
712        if ( res == 0 ) res = 1
713        Agrif_Mind(2) = 1. / res
714!
715        res = 1.
716        do i = 1,coefrafmax-1
717            res = res * FLOAT(Agrif_coeffref(3))
718        enddo
719        if ( res == 0 ) res = 1
720        Agrif_Mind(3) = 1. / res
721!
722      endif
723!---------------------------------------------------------------------------------------------------
724end subroutine Agrif_Set_Rafmax
725!===================================================================================================
726!
727!===================================================================================================
728!  subroutine Agrif_Set_MaskMaxSearch
729!---------------------------------------------------------------------------------------------------
730subroutine Agrif_Set_MaskMaxSearch ( mymaxsearch )
731!---------------------------------------------------------------------------------------------------
732    integer, intent(in) :: mymaxsearch
733!
734    MaxSearch = mymaxsearch
735!---------------------------------------------------------------------------------------------------
736end subroutine Agrif_Set_MaskMaxSearch
737!===================================================================================================
738!
739!===================================================================================================
740!  function Agrif_Level
741!---------------------------------------------------------------------------------------------------
742function Agrif_Level ( )
743!---------------------------------------------------------------------------------------------------
744    integer :: Agrif_Level  ! Result
745!
746    Agrif_Level = Agrif_Curgrid % level
747!---------------------------------------------------------------------------------------------------
748end function Agrif_Level
749!===================================================================================================
750!
751!===================================================================================================
752!  function Agrif_MaxLevel
753!---------------------------------------------------------------------------------------------------
754function Agrif_MaxLevel ( )
755!---------------------------------------------------------------------------------------------------
756    integer :: Agrif_MaxLevel  ! Result
757!
758    Agrif_MaxLevel = Agrif_MaxLevelLoc
759!---------------------------------------------------------------------------------------------------
760end function Agrif_MaxLevel
761!===================================================================================================
762!
763!===================================================================================================
764!  function Agrif_GridAllocation_is_done
765!---------------------------------------------------------------------------------------------------
766function Agrif_GridAllocation_is_done ( ) result(isdone)
767!---------------------------------------------------------------------------------------------------
768    logical :: isdone
769!
770    isdone = Agrif_Curgrid % allocation_is_done
771!---------------------------------------------------------------------------------------------------
772end function Agrif_GridAllocation_is_done
773!===================================================================================================
774!
775
776function Agrif_Parent_Real_4(real_variable) result(real_variable_parent)
777real(KIND=4) :: real_variable
778real(KIND=4) :: real_variable_parent
779
780integer :: i
781logical :: i_found
782
783i_found = .FALSE.
784
785do i=1,Agrif_NbVariables(2)
786  if (LOC(real_variable) == LOC(agrif_curgrid%tabvars_r(i)%array0)) then
787     real_variable_parent = agrif_curgrid%tabvars_r(i)%parent_var%array0
788     i_found = .TRUE.
789     EXIT
790  endif
791enddo
792
793IF (.NOT.i_found) THEN
794do i=1,Agrif_NbVariables(2)
795  if (LOC(real_variable) == LOC(agrif_curgrid%tabvars_r(i)%sarray0)) then
796     real_variable_parent = agrif_curgrid%tabvars_r(i)%parent_var%sarray0
797     i_found = .TRUE.
798     EXIT
799  endif
800enddo
801ENDIF
802
803if (.NOT.i_found) STOP 'Agrif_Parent_Real_4 : Variable not found'
804
805end function Agrif_Parent_Real_4
806
807function Agrif_Parent_Real_8(real_variable) result(real_variable_parent)
808real(KIND=8) :: real_variable
809real(KIND=8) :: real_variable_parent
810
811integer :: i
812logical :: i_found
813
814i_found = .FALSE.
815
816do i=1,Agrif_NbVariables(2)
817  if (LOC(real_variable) == LOC(agrif_curgrid%tabvars_r(i)%array0)) then
818     real_variable_parent = agrif_curgrid%tabvars_r(i)%parent_var%array0
819     i_found = .TRUE.
820     EXIT
821  endif
822enddo
823
824IF (.NOT.i_found) THEN
825do i=1,Agrif_NbVariables(2)
826  if (LOC(real_variable) == LOC(agrif_curgrid%tabvars_r(i)%darray0)) then
827     real_variable_parent = agrif_curgrid%tabvars_r(i)%parent_var%darray0
828     i_found = .TRUE.
829     EXIT
830  endif
831enddo
832ENDIF
833
834if (.NOT.i_found) STOP 'Agrif_Parent_Real_8 : Variable not found'
835
836end function Agrif_Parent_Real_8
837
838function Agrif_Parent_Array2_Real_8(real_variable,ji,jj) result(real_variable_parent)
839real(KIND=8), DIMENSION(:,:) :: real_variable
840real(KIND=8) :: real_variable_parent
841integer :: ji,jj
842
843integer :: i
844logical :: i_found
845
846i_found = .FALSE.
847
848do i=1,Agrif_NbVariables(0)
849  if (LOC(real_variable) == LOC(agrif_curgrid%tabvars(i)%array2)) then
850     real_variable_parent = agrif_curgrid%tabvars(i)%parent_var%array2(ji,jj)
851     i_found = .TRUE.
852     EXIT
853  endif
854enddo
855
856if (.NOT.i_found) STOP 'Agrif_Parent_Array2_Real_8 : Variable not found'
857
858end function Agrif_Parent_Array2_Real_8
859
860
861function Agrif_Parent_Integer(integer_variable) result(integer_variable_parent)
862integer :: integer_variable
863integer :: integer_variable_parent
864
865integer :: i
866logical :: i_found
867
868i_found = .FALSE.
869
870do i=1,Agrif_NbVariables(4)
871  if (LOC(integer_variable) == LOC(agrif_curgrid%tabvars_i(i)%iarray0)) then
872     integer_variable_parent = agrif_curgrid%tabvars_i(i)%parent_var%iarray0
873     i_found = .TRUE.
874     EXIT
875  endif
876enddo
877
878if (.NOT.i_found) STOP 'Agrif_Parent : Variable not found'
879
880end function Agrif_Parent_Integer
881
882function Agrif_Parent_Character(character_variable) result(character_variable_parent)
883character(*) :: character_variable
884character(len(character_variable)) :: character_variable_parent
885
886integer :: i
887logical :: i_found
888
889i_found = .FALSE.
890
891do i=1,Agrif_NbVariables(1)
892  if (LOC(character_variable) == LOC(agrif_curgrid%tabvars_c(i)%carray0)) then
893     character_variable_parent = agrif_curgrid%tabvars_c(i)%parent_var%carray0
894     i_found = .TRUE.
895     EXIT
896  endif
897enddo
898
899if (.NOT.i_found) STOP 'Agrif_Parent : Variable not found'
900
901end function Agrif_Parent_Character
902
903function Agrif_Parent_Logical(logical_variable) result(logical_variable_parent)
904logical :: logical_variable
905logical :: logical_variable_parent
906
907integer :: i
908logical :: i_found
909
910i_found = .FALSE.
911
912do i=1,Agrif_NbVariables(3)
913  if (LOC(logical_variable) == LOC(agrif_curgrid%tabvars_l(i)%larray0)) then
914     logical_variable_parent = agrif_curgrid%tabvars_l(i)%parent_var%larray0
915     i_found = .TRUE.
916     EXIT
917  endif
918enddo
919
920if (.NOT.i_found) STOP 'Agrif_Parent : Variable not found'
921
922end function Agrif_Parent_Logical
923
924function Agrif_Irhox() result(i_val)
925integer :: i_val
926i_val = agrif_curgrid%spaceref(1)
927end function Agrif_Irhox
928
929function Agrif_Irhoy() result(i_val)
930integer :: i_val
931i_val = agrif_curgrid%spaceref(2)
932end function Agrif_Irhoy
933
934function Agrif_Irhoz() result(i_val)
935integer :: i_val
936i_val = agrif_curgrid%spaceref(3)
937end function Agrif_Irhoz
938
939function Agrif_NearCommonBorderX() result(l_val)
940logical :: l_val
941l_val = agrif_curgrid%nearRootBorder(1)
942end function Agrif_NearCommonBorderX
943
944function Agrif_NearCommonBorderY() result(l_val)
945logical :: l_val
946l_val = agrif_curgrid%nearRootBorder(2)
947end function Agrif_NearCommonBorderY
948
949function Agrif_NearCommonBorderZ() result(l_val)
950logical :: l_val
951l_val = agrif_curgrid%nearRootBorder(3)
952end function Agrif_NearCommonBorderZ
953
954function Agrif_DistantCommonBorderX() result(l_val)
955logical :: l_val
956l_val = agrif_curgrid%DistantRootBorder(1)
957end function Agrif_DistantCommonBorderX
958
959function Agrif_DistantCommonBorderY() result(l_val)
960logical :: l_val
961l_val = agrif_curgrid%DistantRootBorder(2)
962end function Agrif_DistantCommonBorderY
963
964function Agrif_DistantCommonBorderZ() result(l_val)
965logical :: l_val
966l_val = agrif_curgrid%DistantRootBorder(3)
967end function Agrif_DistantCommonBorderZ
968
969function Agrif_Ix() result(i_val)
970integer :: i_val
971i_val = agrif_curgrid%ix(1)
972end function Agrif_Ix
973
974function Agrif_Iy() result(i_val)
975integer :: i_val
976i_val = agrif_curgrid%ix(2)
977end function Agrif_Iy
978
979function Agrif_Iz() result(i_val)
980integer :: i_val
981i_val = agrif_curgrid%ix(3)
982end function Agrif_Iz
983
984function Agrif_Get_grid_id() result(i_val)
985integer :: i_val
986i_val = agrif_curgrid % grid_id
987end function Agrif_Get_grid_id
988
989function Agrif_Get_parent_id() result(i_val)
990integer :: i_val
991i_val = agrif_curgrid % parent % grid_id
992end function Agrif_Get_parent_id
993
994function Agrif_rhox() result(r_val)
995real :: r_val
996r_val = real(agrif_curgrid%spaceref(1))
997end function Agrif_rhox
998
999function Agrif_rhoy() result(r_val)
1000real :: r_val
1001r_val = real(agrif_curgrid%spaceref(2))
1002end function Agrif_rhoy
1003
1004function Agrif_rhoz() result(r_val)
1005real :: r_val
1006r_val = real(agrif_curgrid%spaceref(3))
1007end function Agrif_rhoz
1008
1009function Agrif_Nb_Step() result(i_val)
1010integer :: i_val
1011i_val = agrif_curgrid%ngridstep
1012end function Agrif_Nb_Step
1013
1014function Agrif_Nb_Fine_Grids() result(i_val)
1015integer :: i_val
1016i_val = Agrif_nbfixedgrids
1017end function Agrif_Nb_Fine_Grids
1018
1019end module Agrif_CurgridFunctions
Note: See TracBrowser for help on using the repository browser.