FV3 Bundle
fv3jedi_covariance_interface_mod.F90
Go to the documentation of this file.
1 ! (C) Copyright 2017 UCAR
2 !
3 ! This software is licensed under the terms of the Apache Licence Version 2.0
4 ! which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
5 
6 ! ------------------------------------------------------------------------------
7 
9 
10 use iso_c_binding
14 use fv3jedi_increment_mod, only: fv3jedi_increment, random
15 use fv3jedi_increment_interface_mod, only: fv3jedi_increment_registry
16 
17 private
18 public :: fv3jedi_covar_registry
19 ! ------------------------------------------------------------------------------
20 
21 #define LISTED_TYPE fv3jedi_covar
22 
23 !> Linked list interface - defines registry_t type
24 #include "linkedList_i.f"
25 
26 !> Global registry
27 type(registry_t) :: fv3jedi_covar_registry
28 
29 ! ------------------------------------------------------------------------------
30 
31 contains
32 
33 ! ------------------------------------------------------------------------------
34 
35 !> Linked list implementation
36 #include "linkedList_c.f"
37 
38 ! ------------------------------------------------------------------------------
39 subroutine c_fv3jedi_b_setup(c_key_self, c_conf, c_key_geom) &
40  & bind(c,name='fv3jedi_b_setup_f90')
41 
42 implicit none
43 integer(c_int), intent(inout) :: c_key_self !< Background error covariance structure
44 type(c_ptr), intent(in) :: c_conf !< Configuration
45 integer(c_int), intent(in) :: c_key_geom !< Geometry
46 type(fv3jedi_covar), pointer :: self
47 type(fv3jedi_geom), pointer :: geom
48 
49 call fv3jedi_geom_registry%get(c_key_geom, geom)
50 call fv3jedi_covar_registry%init()
51 call fv3jedi_covar_registry%add(c_key_self)
52 call fv3jedi_covar_registry%get(c_key_self, self)
53 
54 call fv3jedi_covar_setup(self, geom, c_conf)
55 
56 end subroutine c_fv3jedi_b_setup
57 
58 ! ------------------------------------------------------------------------------
59 
60 subroutine c_fv3jedi_b_delete(c_key_self) bind (c,name='fv3jedi_b_delete_f90')
61 
62 implicit none
63 integer(c_int), intent(inout) :: c_key_self !< Background error covariance structure
64 type(fv3jedi_covar), pointer :: self
65 
66 call fv3jedi_covar_registry%get(c_key_self,self)
67 call fv3jedi_covar_delete(self)
68 call fv3jedi_covar_registry%remove(c_key_self)
69 
70 end subroutine c_fv3jedi_b_delete
71 
72 ! ------------------------------------------------------------------------------
73 
74 !> Multiply streamfunction by inverse of covariance
75 
76 subroutine c_fv3jedi_b_inv_mult(c_key_self, c_key_in, c_key_out) bind(c,name='fv3jedi_b_invmult_f90')
77 
78 implicit none
79 integer(c_int), intent(in) :: c_key_self
80 integer(c_int), intent(in) :: c_key_in
81 integer(c_int), intent(in) :: c_key_out
82 type(fv3jedi_covar), pointer :: self
83 type(fv3jedi_increment), pointer :: xin
84 type(fv3jedi_increment), pointer :: xout
85 
86 call fv3jedi_covar_registry%get(c_key_self,self)
87 call fv3jedi_increment_registry%get(c_key_in,xin)
88 call fv3jedi_increment_registry%get(c_key_out,xout)
89 
90 !call fv3jedi_covar_sqrt_inv_mult(self%nx,self%ny,xctl,xin,self)
91 !call zeros(xout)
92 !call fv3jedi_covar_sqrt_inv_mult_ad(self%nx,self%ny,xctl,xout,self)
93 
94 end subroutine c_fv3jedi_b_inv_mult
95 
96 ! ------------------------------------------------------------------------------
97 
98 !> Multiply streamfunction by covariance
99 
100 subroutine c_fv3jedi_b_mult(c_key_self, c_key_in, c_key_out) bind(c,name='fv3jedi_b_mult_f90')
102 implicit none
103 integer(c_int), intent(in) :: c_key_self
104 integer(c_int), intent(in) :: c_key_in
105 integer(c_int), intent(in) :: c_key_out
106 type(fv3jedi_covar), pointer :: self
107 type(fv3jedi_increment), pointer :: xin
108 type(fv3jedi_increment), pointer :: xout
109 
110 call fv3jedi_covar_registry%get(c_key_self,self)
111 call fv3jedi_increment_registry%get(c_key_in,xin)
112 call fv3jedi_increment_registry%get(c_key_out,xout)
113 
114 !call fv3jedi_covar_sqrt_mult_ad(self%nx,self%ny,xin,xctl,self)
115 !call zeros(xout)
116 !call fv3jedi_covar_sqrt_mult(self%nx,self%ny,xout,xctl,self)
117 
118 end subroutine c_fv3jedi_b_mult
119 
120 ! ------------------------------------------------------------------------------
121 
122 !> Generate randomized increment
123 
124 subroutine c_fv3jedi_b_randomize(c_key_self, c_key_out) bind(c,name='fv3jedi_b_randomize_f90')
126 implicit none
127 integer(c_int), intent(in) :: c_key_self
128 integer(c_int), intent(in) :: c_key_out
129 type(fv3jedi_covar), pointer :: self
130 type(fv3jedi_increment), pointer :: xout
131 
132 call fv3jedi_covar_registry%get(c_key_self,self)
133 call fv3jedi_increment_registry%get(c_key_out,xout)
134 
135 call random(xout)
136 
137 end subroutine c_fv3jedi_b_randomize
138 
139 ! ------------------------------------------------------------------------------
140 
type(registry_t), public fv3jedi_geom_registry
Linked list interface - defines registry_t type.
subroutine fv3jedi_covar_setup(self, geom, c_conf)
Setup for the model&#39;s 3d error covariance matrices (B and Q_i)
Fortran derived type to hold geometry data for the FV3JEDI model.
subroutine fv3jedi_covar_delete(self)
subroutine, public random(self)
subroutine c_fv3jedi_b_inv_mult(c_key_self, c_key_in, c_key_out)
Multiply streamfunction by inverse of covariance.
subroutine c_fv3jedi_b_setup(c_key_self, c_conf, c_key_geom)
Linked list implementation.
subroutine c_fv3jedi_b_mult(c_key_self, c_key_in, c_key_out)
Multiply streamfunction by covariance.
type(registry_t), public fv3jedi_covar_registry
Linked list interface - defines registry_t type.
subroutine c_fv3jedi_b_randomize(c_key_self, c_key_out)
Generate randomized increment.
Handle increment for the FV3JEDI model.
Fortran module handling geometry for the FV3 model.
Fortran module handling geometry for the FV3 model.