/[MITgcm]/MITgcm_contrib/heimbach/OpenAD/code_shallow_openad/active_module.f90
ViewVC logotype

Contents of /MITgcm_contrib/heimbach/OpenAD/code_shallow_openad/active_module.f90

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download)
Thu Dec 19 16:09:57 2013 UTC (12 years, 10 months ago) by utke
Branch: MAIN
CVS Tags: HEAD
Changes since 1.4: +0 -0 lines
FILE REMOVED
stale

1
2 module active_module
3 use w2f__types
4 implicit none
5 private
6 public :: active, saxpy, sax, setderiv, zero_deriv, &
7 convert_p2a_scalar, convert_a2p_scalar, &
8 convert_p2a_vector, convert_a2p_vector, &
9 convert_p2a_matrix, convert_a2p_matrix, &
10 convert_p2a_three_tensor, convert_a2p_three_tensor, &
11 convert_p2a_four_tensor, convert_a2p_four_tensor, &
12 convert_p2a_five_tensor, convert_a2p_five_tensor
13
14
15 !
16 ! active needs to be a sequence type
17 ! with no initialization
18 !
19 type active
20 sequence
21 double precision :: v
22 ! initialization does not work for active variables
23 ! inside of common block, such as in boxmodel
24 ! initialization is required for correct adjoint
25 double precision :: d=0.0
26 ! double precision :: d
27 end type active
28
29 interface saxpy
30 module procedure saxpy_a_a
31 end interface
32
33 interface setderiv
34 module procedure setderiv_a_a
35 end interface
36
37 interface zero_deriv
38 module procedure zero_deriv_a
39 end interface
40
41 interface sax
42 module procedure sax_d_a_a, sax_i_a_a
43 end interface
44
45 interface convert_p2a_scalar
46 module procedure convert_p2a_scalar_impl
47 end interface
48 interface convert_a2p_scalar
49 module procedure convert_a2p_scalar_impl
50 end interface
51
52 interface convert_p2a_vector
53 module procedure convert_p2a_vector_impl
54 end interface
55 interface convert_a2p_vector
56 module procedure convert_a2p_vector_impl
57 end interface
58
59 interface convert_p2a_matrix
60 module procedure convert_p2a_matrix_impl
61 end interface
62 interface convert_a2p_matrix
63 module procedure convert_a2p_matrix_impl
64 end interface
65
66 interface convert_p2a_three_tensor
67 module procedure convert_p2a_three_tensor_impl
68 end interface
69 interface convert_a2p_three_tensor
70 module procedure convert_a2p_three_tensor_impl
71 end interface
72
73 interface convert_p2a_four_tensor
74 module procedure convert_p2a_four_tensor_impl
75 end interface
76 interface convert_a2p_four_tensor
77 module procedure convert_a2p_four_tensor_impl
78 end interface
79
80 interface convert_p2a_five_tensor
81 module procedure convert_p2a_five_tensor_impl
82 end interface
83 interface convert_a2p_five_tensor
84 module procedure convert_a2p_five_tensor_impl
85 end interface
86
87 contains
88
89 !
90 ! chain rule saxpy to be used in forward and reverse modes
91 !
92
93 subroutine saxpy_a_a(a,x,y)
94 double precision, intent(in) :: a
95 type(active), intent(in) :: x
96 type(active), intent(inout) :: y
97
98 y%d=y%d+x%d*a
99 end subroutine saxpy_a_a
100
101 !
102 ! chain rule saxpy to be used in forward and reverse modes
103 ! derivative component of y is equal to zero initially
104 ! note: y needs to be inout as otherwise value component gets
105 ! zeroed out
106 !
107
108 subroutine sax_d_a_a(a,x,y)
109 double precision, intent(in) :: a
110 type(active), intent(in) :: x
111 type(active), intent(inout) :: y
112
113 y%d=x%d*a
114 end subroutine sax_d_a_a
115
116 subroutine sax_i_a_a(a,x,y)
117 integer(kind=w2f__i8), intent(in) :: a
118 type(active), intent(in) :: x
119 type(active), intent(inout) :: y
120
121 y%d=x%d*a
122 end subroutine sax_i_a_a
123
124 !
125 ! set derivative of y to be equal to derivative of x
126 ! note: making y inout allows for already existing active
127 ! variables to become the target of a derivative assignment
128 !
129
130 subroutine setderiv_a_a(y,x)
131 type(active), intent(inout) :: y
132 type(active), intent(in) :: x
133
134 y%d=x%d
135 end subroutine setderiv_a_a
136
137 !
138 ! set derivative components to 0.0
139 !
140 subroutine zero_deriv_a(x)
141 type(active), intent(out) :: x
142
143 x%d=0.0d0
144 end subroutine zero_deriv_a
145
146 subroutine convert_a2p_scalar_impl(convertTo, convertFrom)
147 real(kind=w2f__8), intent(out) :: convertTo
148 type(active), intent(in) :: convertFrom
149 convertTo=convertFrom%v
150 end subroutine
151
152 subroutine convert_p2a_scalar_impl(convertTo, convertFrom)
153 real(kind=w2f__8), intent(in) :: convertFrom
154 type(active), intent(inout) :: convertTo
155 convertTo%v=convertFrom
156 end subroutine
157
158 subroutine convert_a2p_vector_impl(convertTo, convertFrom)
159 type(active), dimension(:), intent(in) :: convertFrom
160 real(kind=w2f__8), dimension(:), intent(out) :: convertTo
161 convertTo=convertFrom%v
162 end subroutine
163
164 subroutine convert_p2a_vector_impl(convertTo, convertFrom)
165 real(kind=w2f__8), dimension(:), intent(in) :: convertFrom
166 type(active), dimension(:), intent(inout) :: convertTo
167 convertTo%v=convertFrom
168 end subroutine
169
170 subroutine convert_a2p_matrix_impl(convertTo, convertFrom)
171 type(active), dimension(:,:), intent(in) :: convertFrom
172 real(kind=w2f__8), dimension(:,:), intent(out) :: convertTo
173 convertTo=convertFrom%v
174 end subroutine
175
176 subroutine convert_p2a_matrix_impl(convertTo, convertFrom)
177 real(kind=w2f__8), dimension(:,:), intent(in) :: convertFrom
178 type(active), dimension(:,:), intent(inout) :: convertTo
179 convertTo%v=convertFrom
180 end subroutine
181
182 subroutine convert_a2p_three_tensor_impl(convertTo, convertFrom)
183 type(active), dimension(:,:,:), intent(in) :: convertFrom
184 real(kind=w2f__8), dimension(:,:,:), intent(out) :: convertTo
185 convertTo=convertFrom%v
186 end subroutine
187
188 subroutine convert_p2a_three_tensor_impl(convertTo, convertFrom)
189 real(kind=w2f__8), dimension(:,:,:), intent(in) :: convertFrom
190 type(active), dimension(:,:,:), intent(inout) :: convertTo
191 convertTo%v=convertFrom
192 end subroutine
193
194 subroutine convert_a2p_four_tensor_impl(convertTo, convertFrom)
195 type(active), dimension(:,:,:,:), intent(in) :: convertFrom
196 real(kind=w2f__8), dimension(:,:,:,:), intent(out) :: convertTo
197 convertTo=convertFrom%v
198 end subroutine
199
200 subroutine convert_p2a_four_tensor_impl(convertTo, convertFrom)
201 real(kind=w2f__8), dimension(:,:,:,:), intent(in) :: convertFrom
202 type(active), dimension(:,:,:,:), intent(inout) :: convertTo
203 convertTo%v=convertFrom
204 end subroutine
205
206 subroutine convert_a2p_five_tensor_impl(convertTo, convertFrom)
207 type(active), dimension(:,:,:,:,:), intent(in) :: convertFrom
208 real(kind=w2f__8), dimension(:,:,:,:,:), intent(out) :: convertTo
209 convertTo=convertFrom%v
210 end subroutine
211
212 subroutine convert_p2a_five_tensor_impl(convertTo, convertFrom)
213 real(kind=w2f__8), dimension(:,:,:,:,:), intent(in) :: convertFrom
214 type(active), dimension(:,:,:,:,:), intent(inout) :: convertTo
215 convertTo%v=convertFrom
216 end subroutine
217
218 end module
219
220

  ViewVC Help
Powered by ViewVC 1.1.22