A Modular Arbitrary-Order Ocean-Atmosphere Model -- Stochastic implementation
maooam_stoch.f90
Go to the documentation of this file.
1 
2 ! maooam_stoch.f90
3 !
4 !> Fortran 90 implementation of the stochastic modular arbitrary-order
5 !> ocean-atmosphere model MAOOAM
6 !>
7 !
8 !> @copyright
9 !> 2018 Jonathan Demaeyer.
10 !> See LICENSE.txt for license information.
11 !
12 !---------------------------------------------------------------------------!
13 !
14 !> @remark
15 !> There are four dynamics modes:
16 !> - full: generate the full dynamics
17 !> - unres: generate the intrinsic unresolved dynamics
18 !> - qfst: generate dynamics given by the quadratic terms
19 !> of the unresolved tendencies
20 !> - reso: use the resolved dynamics alone
21 !
22 !---------------------------------------------------------------------------
23 
24 PROGRAM maooam_stoch
25  USE params, only: ndim, dt, tw, t_trans, t_run, writeout
26  USE stoch_params, only: dtn,mode
27  USE aotensor_def, only: init_aotensor
28  USE dec_tensor, only: init_dec_tensor
29  USE ic_def, only: load_ic, ic
31  USE stat
32  IMPLICIT NONE
33 
34  REAL(KIND=8), DIMENSION(:), ALLOCATABLE :: X !< State variable in the model
35  REAL(KIND=8), DIMENSION(:), ALLOCATABLE :: Xnew !< Updated state variable
36  REAL(KIND=8), DIMENSION(:), ALLOCATABLE :: tend !< Store the tendencies
37  REAL(KIND=8) :: t=0.d0 !< Time variable
38  REAL(KIND=8) :: t_up !< Update time for the progress bar
39  CHARACTER*4 :: force !< Selector for the dynamics
40  INTEGER :: is,lg !< Dummy integers
41 
42  print*, 'Model MAOOAM v1.3 stochastic'
43  print*, 'Loading information...'
44 
45  CALL get_command_argument(1,force,lg,is)
46 
47  CALL init_aotensor ! Initialize the aotensor
48  CALL init_dec_tensor ! Compute the tensor
49 
50  CALL load_ic ! Load the initial condition
51 
52  ! Initialize the integrator
53  IF (is.ne.0) THEN
54  print*, 'No or bad dynamics specified, using the full one!'
55  CALL init_integrator('full')
56  ELSE
57  IF (force.eq.'para') THEN
58  CALL init_integrator
59  print*, 'Using the stoch_params.nml specified dynamics: ', mode
60  ELSE
61  print*, 'Using the ', force, ' dynamics!'
62  CALL init_integrator(force)
63  ENDIF
64  ENDIF
65 
66  t_up=dt/t_trans*100.d0
67 
68  IF (writeout) OPEN(10,file='evol_field.dat')
69 
70  ALLOCATE(x(0:ndim),xnew(0:ndim),tend(0:ndim))
71 
72  x=ic
73 
74  print*, 'Starting the transient time evolution...'
75 
76  DO WHILE (t<t_trans)
77  CALL step(x,t,dt,dtn,xnew,tend)
78  x=xnew
79  IF (mod(t/t_trans*100.d0,0.1)<t_up) WRITE(*,'(" Progress ",F6.1," %",A,$)') t/t_trans*100.d0,char(13)
80  END DO
81 
82  print*, 'Starting the time evolution...'
83 
84  CALL init_stat
85 
86  t=0.d0
87  t_up=dt/t_run*100.d0
88 
89  IF (writeout) WRITE(10,*) t,x(1:ndim)
90 
91  DO WHILE (t<t_run)
92  CALL step(x,t,dt,dtn,xnew,tend)
93  x=xnew
94  IF (mod(t,tw)<dt) THEN
95  IF (writeout) WRITE(10,*) t,x(1:ndim)
96  CALL acc(x)
97  END IF
98  IF (mod(t/t_run*100.d0,0.1)<t_up) WRITE(*,'(" Progress ",F6.1," %",A,$)') t/t_run*100.d0,char(13)
99  END DO
100 
101  print*, 'Evolution finished.'
102 
103  IF (writeout) CLOSE(10)
104 
105  IF (writeout) OPEN(10,file='mean_field.dat')
106 
107  x=mean()
108  IF (writeout) WRITE(10,*) x(1:ndim)
109  IF (writeout) CLOSE(10)
110 
111 END PROGRAM maooam_stoch
The stochastic models parameters module.
Module to load the initial condition.
Definition: ic_def.f90:12
integer ndim
Number of variables (dimension of the model)
Definition: params.f90:85
real(kind=8) tw
Write all variables every tw time units.
Definition: params.f90:78
Statistics accumulators.
Definition: stat.f90:14
The resolved-unresolved components decomposition of the tensor.
Definition: dec_tensor.f90:16
subroutine, public init_integrator(force)
Subroutine to initialize the integrator.
logical writeout
Write to file boolean.
Definition: params.f90:79
real(kind=8) t_run
Effective intergration time (length of the generated trajectory)
Definition: params.f90:76
subroutine, public acc(x)
Accumulate one state.
Definition: stat.f90:48
The equation tensor for the coupled ocean-atmosphere model with temperature which allows for an exten...
real(kind=8) dtn
Square root of the timestep.
real(kind=8), dimension(:), allocatable, public ic
Initial condition vector.
Definition: ic_def.f90:23
subroutine, public step(y, t, dt, dtn, res, tend)
Routine to perform a stochastic step of the selected dynamics (Heun algorithm). The incremented time ...
subroutine, public init_stat
Initialise the accumulators.
Definition: stat.f90:35
The model parameters module.
Definition: params.f90:18
program maooam_stoch
Fortran 90 implementation of the stochastic modular arbitrary-order ocean-atmosphere model MAOOAM...
real(kind=8) function, dimension(0:ndim), public mean()
Function returning the mean.
Definition: stat.f90:60
real(kind=8) dt
Integration time step.
Definition: params.f90:77
subroutine, public load_ic
Subroutine to load the initial condition if IC.nml exists. If it does not, then write IC...
Definition: ic_def.f90:32
character(len=4) mode
Stochastic mode parameter.
subroutine, public init_dec_tensor
Subroutine that initialize and compute the decomposed tensors.
Definition: dec_tensor.f90:195
real(kind=8) t_trans
Transient time period.
Definition: params.f90:75
subroutine, public init_aotensor
Subroutine to initialise the aotensor tensor.
Module with the stochastic rk2 integration routines.