A Modular Arbitrary-Order Ocean-Atmosphere Model -- Stochastic implementation
sf_def.f90
Go to the documentation of this file.
1 
2 ! sf_def.f90
3 !
4 !> Module to select the resolved-unresolved components.
5 !
6 !> @copyright
7 !> 2018 Jonathan Demaeyer
8 !> See LICENSE.txt for license information.
9 !
10 !---------------------------------------------------------------------------!
11 
12 MODULE sf_def
13 
14  USE params, only: natm,noc,ndim
15  USE util, only: str,rstr
17  IMPLICIT NONE
18 
19  PRIVATE
20 
21  LOGICAL :: exists !< Boolean to test for file existence.
22 
23  INTEGER, DIMENSION(:), ALLOCATABLE, PUBLIC :: sf !< Unresolved variable definition vector
24  INTEGER, DIMENSION(:), ALLOCATABLE, PUBLIC :: ind,rind !< Unresolved reduction indices
25  INTEGER, DIMENSION(:), ALLOCATABLE, PUBLIC :: sl_ind,sl_rind !< Resolved reduction indices
26  INTEGER, PUBLIC :: n_unres !< Number of unresolved variables
27  INTEGER, PUBLIC :: n_res !< Number of resolved variables
28  INTEGER, DIMENSION(:,:), ALLOCATABLE, PUBLIC :: bar,bau,bor,bou !< Filter matrices
29 
30  PUBLIC :: load_sf
31 
32 CONTAINS
33 
34  !> Subroutine to load the unresolved variable defintion vector `SF` from SF.nml if it exists.
35  !> If it does not, then write SF.nml with no unresolved variables specified (null vector).
36  SUBROUTINE load_sf
37  INTEGER :: i,AllocStat,n,ns
38  CHARACTER(len=20) :: fm
39 
40  namelist /sflist/ sf
41 
42  fm(1:6)='(F3.1)'
43 
44  IF (ndim == 0) stop "*** Number of dimensions is 0! ***"
45  ALLOCATE(sf(0:ndim), stat=allocstat)
46  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
47 
48  INQUIRE(file='./SF.nml',exist=exists)
49 
50  IF (exists) THEN
51  OPEN(8, file="SF.nml", status='OLD', recl=80, delim='APOSTROPHE')
52  READ(8,nml=sflist)
53  CLOSE(8)
54  n_unres=0
55  DO i=1,ndim ! Computing the number of unresolved variables
56  IF (sf(i)==1) n_unres=n_unres+1
57  ENDDO
58  IF (n_unres==0) stop "*** No unresolved variable specified! ***"
60  ALLOCATE(ind(n_unres), rind(0:ndim), sl_ind(n_res), sl_rind(0:ndim), stat=allocstat)
61  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
62  ALLOCATE(bar(0:ndim,0:ndim), bau(0:ndim,0:ndim), bor(0:ndim,0:ndim), bou(0:ndim,0:ndim), stat=allocstat)
63  IF (allocstat /= 0) stop "*** Not enough memory ! ***"
64  rind=0
65  n=1
66  ns=1
67  DO i=1,ndim
68  IF (sf(i)==1) THEN
69  ind(n)=i
70  rind(i)=n
71  n=n+1
72  ELSE
73  sl_ind(ns)=i
74  sl_rind(i)=ns
75  ns=ns+1
76  ENDIF
77  ENDDO
78  bar=0
79  bau=0
80  bor=0
81  bou=0
82  DO i=1,2*natm
83  IF (sf(i)==1) THEN
84  bau(i,i)=1
85  ELSE
86  bar(i,i)=1
87  ENDIF
88  ENDDO
89  DO i=2*natm+1,ndim
90  IF (sf(i)==1) THEN
91  bou(i,i)=1
92  ELSE
93  bor(i,i)=1
94  ENDIF
95  ENDDO
96  ELSE
97  OPEN(8, file="SF.nml", status='NEW')
98  WRITE(8,'(a)') "!------------------------------------------------------------------------------!"
99  WRITE(8,'(a)') "! Namelist file : !"
100  WRITE(8,'(a)') "! Unresolved variables specification (1 -> unresolved, 0 -> resolved) !"
101  WRITE(8,'(a)') "!------------------------------------------------------------------------------!"
102  WRITE(8,*) ""
103  WRITE(8,'(a)') "&SFLIST"
104  WRITE(8,*) " ! psi variables"
105  DO i=1,natm
106  WRITE(8,*) " SF("//trim(str(i))//") = 0"//" ! typ= "&
107  &//awavenum(i)%typ//", Nx= "//trim(rstr(awavenum(i)&
108  &%Nx,fm))//", Ny= "//trim(rstr(awavenum(i)%Ny,fm))
109  END DO
110  WRITE(8,*) " ! theta variables"
111  DO i=1,natm
112  WRITE(8,*) " SF("//trim(str(i+natm))//") = 0"//" ! typ= "&
113  &//awavenum(i)%typ//", Nx= "//trim(rstr(awavenum(i)&
114  &%Nx,fm))//", Ny= "//trim(rstr(awavenum(i)%Ny,fm))
115  END DO
116 
117  WRITE(8,*) " ! A variables"
118  DO i=1,noc
119  WRITE(8,*) " SF("//trim(str(i+2*natm))//") = 0"//" ! Nx&
120  &= "//trim(rstr(owavenum(i)%Nx,fm))//", Ny= "&
121  &//trim(rstr(owavenum(i)%Ny,fm))
122  END DO
123  WRITE(8,*) " ! T variables"
124  DO i=1,noc
125  WRITE(8,*) " SF("//trim(str(i+noc+2*natm))//") = 0"//" &
126  &! Nx= "//trim(rstr(owavenum(i)%Nx,fm))//", Ny= "&
127  &//trim(rstr(owavenum(i)%Ny,fm))
128  END DO
129 
130  WRITE(8,'(a)') "&END"
131  WRITE(8,*) ""
132  CLOSE(8)
133  stop "*** SF.nml namelist written. Fill in the file and rerun !***"
134  ENDIF
135  END SUBROUTINE load_sf
136 END MODULE sf_def
integer ndim
Number of variables (dimension of the model)
Definition: params.f90:85
integer noc
Number of oceanic basis functions.
Definition: params.f90:84
Utility module.
Definition: util.f90:12
subroutine, public load_sf
Subroutine to load the unresolved variable defintion vector SF from SF.nml if it exists. If it does not, then write SF.nml with no unresolved variables specified (null vector).
Definition: sf_def.f90:37
Inner products between the truncated set of basis functions for the ocean and atmosphere streamfuncti...
Statistics accumulators.
Definition: stat.f90:14
character(len=40) function, public rstr(x, fm)
Convert a real to string with a given format.
Definition: util.f90:38
integer, dimension(:), allocatable, public rind
Unresolved reduction indices.
Definition: sf_def.f90:24
integer, dimension(:,:), allocatable, public bau
Definition: sf_def.f90:28
integer, dimension(:,:), allocatable, public bar
Definition: sf_def.f90:28
character(len=20) function, public str(k)
Convert an integer to string.
Definition: util.f90:31
type(ocean_wavenum), dimension(:), allocatable, public owavenum
Oceanic blocs specification.
integer, dimension(:), allocatable, public sf
Unresolved variable definition vector.
Definition: sf_def.f90:23
type(atm_wavenum), dimension(:), allocatable, public awavenum
Atmospheric blocs specification.
integer natm
Number of atmospheric basis functions.
Definition: params.f90:83
integer, dimension(:,:), allocatable, public bou
Filter matrices.
Definition: sf_def.f90:28
integer, public n_unres
Number of unresolved variables.
Definition: sf_def.f90:26
integer, dimension(:), allocatable, public sl_rind
Resolved reduction indices.
Definition: sf_def.f90:25
logical exists
Boolean to test for file existence.
Definition: sf_def.f90:21
integer, dimension(:), allocatable, public ind
Definition: sf_def.f90:24
The model parameters module.
Definition: params.f90:18
Module to select the resolved-unresolved components.
Definition: sf_def.f90:12
integer, public n_res
Number of resolved variables.
Definition: sf_def.f90:27
integer, dimension(:,:), allocatable, public bor
Definition: sf_def.f90:28
integer, dimension(:), allocatable, public sl_ind
Definition: sf_def.f90:25