Debian Codegraph @

src/atlas_f/functionspace/atlas_FunctionSpace_module.F90

raw
1 ! (C) Copyright 2013 ECMWF.
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 ! In applying this licence, ECMWF does not waive the privileges and immunities
6 ! granted to it by virtue of its status as an intergovernmental organisation nor
7 ! does it submit to any jurisdiction.
8
9 #include "atlas/atlas_f.h"
10
11 module atlas_functionspace_module
12
13 use fckit_owned_object_module, only : fckit_owned_object
14 use atlas_field_module, only : atlas_Field
15 use atlas_fieldset_module, only : atlas_FieldSet
16 use atlas_config_module, only : atlas_Config
17
18 implicit none
19
20 private :: fckit_owned_object
21 private :: atlas_Field
22 private :: atlas_FieldSet
23 private :: atlas_Config
24
25 public :: atlas_FunctionSpace
26
27 private
28
29 !------------------------------------------------------------------------------
30 TYPE, extends(fckit_owned_object) :: atlas_FunctionSpace
31
32 ! Purpose :
33 ! -------
34 ! *FunctionSpace* :
35 ! Describes how nodes are ordered
36 ! Describes how parallelisation for fields is done
37
38 ! Methods :
39 ! -------
40 ! name : The name or tag this function space was created with
41
42 ! Author :
43 ! ------
44 ! 20-Nov-2013 Willem Deconinck *ECMWF*
45
46 !------------------------------------------------------------------------------
47 contains
48 procedure, public :: name => atlas_FunctionSpace__name
49
50 procedure, private :: create_field_args
51 procedure, private :: create_field_template
52 procedure, private :: deprecated_create_field_1 ! deprecated
53 procedure, private :: deprecated_create_field_2 ! deprecated
54
55 procedure, private :: halo_exchange_field
56 procedure, private :: halo_exchange_fieldset
57
58 procedure, private :: adjoint_halo_exchange_field
59 procedure, private :: adjoint_halo_exchange_fieldset
60
61 generic, public :: create_field => &
62 & create_field_args, &
63 & create_field_template, &
64 & deprecated_create_field_1, &
65 & deprecated_create_field_2
66
67 generic, public :: halo_exchange => halo_exchange_field, halo_exchange_fieldset
68 generic, public :: adjoint_halo_exchange => adjoint_halo_exchange_field, adjoint_halo_exchange_fieldset
69
70 #if FCKIT_FINAL_NOT_INHERITING
71 final :: atlas_FunctionSpace__final_auto
72 #endif
73
74 END TYPE atlas_FunctionSpace
75
76 interface atlas_FunctionSpace
77 module procedure atlas_FunctionSpace__cptr
78 end interface
79
80 !========================================================
81 contains
82 !========================================================
83
84 function atlas_FunctionSpace__cptr(cptr) result(this)
85 use, intrinsic :: iso_c_binding, only : c_ptr
86 type(atlas_FunctionSpace) :: this
87 type(c_ptr), intent(in) :: cptr
88 call this%reset_c_ptr( cptr )
89 call this%return()
90 end function
91
92 function atlas_FunctionSpace__name(this) result(name)
93 use atlas_functionspace_c_binding
94 use fckit_c_interop_module, only : c_ptr_to_string, c_ptr_free
95 use, intrinsic :: iso_c_binding, only : c_ptr
96 class(atlas_FunctionSpace), intent(in) :: this
97 character(len=:), allocatable :: name
98 type(c_ptr) :: name_c_str
99 integer :: size
100 call atlas__FunctionSpace__name(this%CPTR_PGIBUG_A, name_c_str, size )
101 name = c_ptr_to_string(name_c_str)
102 call c_ptr_free(name_c_str)
103 end function
104
105
106
107
108 function create_field_args(this,kind,name,levels,variables,type,alignment,global,owner) result(field)
109 use atlas_functionspace_c_binding
110 use, intrinsic :: iso_c_binding, only : c_int
111 type(atlas_Field) :: field
112 class(atlas_Functionspace), intent(in) :: this
113 integer, intent(in) :: kind
114 character(len=*), intent(in), optional :: name
115 integer(c_int), intent(in), optional :: levels
116 integer(c_int), intent(in), optional :: variables
117 character(len=*), intent(in), optional :: type
118 integer(c_int), intent(in), optional :: alignment
119 logical, intent(in), optional :: global
120 integer(c_int), intent(in), optional :: owner
121
122 type(atlas_Config) :: options
123 options = atlas_Config()
124
125 call options%set("datatype",kind)
126 if( present(name) ) call options%set("name",name)
127 if( present(owner) ) call options%set("owner",owner)
128 if( present(global) ) call options%set("global",global)
129 if( present(levels) ) call options%set("levels",levels)
130 if( present(variables) ) call options%set("variables",variables)
131 if( present(type) ) call options%set("type",type)
132 if( present(alignment) ) call options%set("alignment",alignment)
133
134 field = atlas_Field( atlas__FunctionSpace__create_field( this%CPTR_PGIBUG_A, options%CPTR_PGIBUG_B ) )
135
136 call field%return()
137 call options%final()
138 end function
139
140 !------------------------------------------------------------------------------
141
142 function create_field_template(this,template,name,global,owner) result(field)
143 use atlas_functionspace_c_binding
144 use, intrinsic :: iso_c_binding, only : c_int
145 type(atlas_Field) :: field
146 class(atlas_Functionspace), intent(in) :: this
147 type(atlas_Field), intent(in) :: template
148
149 character(len=*), intent(in), optional :: name
150 logical, intent(in), optional :: global
151 integer(c_int), intent(in), optional :: owner
152
153 type(atlas_Config) :: options
154 options = atlas_Config()
155
156 if( present(name) ) call options%set("name",name)
157 if( present(owner) ) call options%set("owner",owner)
158 if( present(global) ) call options%set("global",global)
159
160 field = atlas_Field( atlas__FunctionSpace__create_field_template( &
161 & this%CPTR_PGIBUG_A, template%CPTR_PGIBUG_A,options%CPTR_PGIBUG_B) )
162
163 call options%final()
164
165 call field%return()
166 end function
167
168 !------------------------------------------------------------------------------
169
170 subroutine halo_exchange_fieldset(this,fieldset)
171 use atlas_functionspace_c_binding
172 class(atlas_Functionspace), intent(in) :: this
173 type(atlas_FieldSet), intent(inout) :: fieldset
174 call atlas__FunctionSpace__halo_exchange_fieldset(this%CPTR_PGIBUG_A,fieldset%CPTR_PGIBUG_A)
175 end subroutine
176
177 !------------------------------------------------------------------------------
178
179 subroutine halo_exchange_field(this,field)
180 use atlas_functionspace_c_binding
181 class(atlas_Functionspace), intent(in) :: this
182 type(atlas_Field), intent(inout) :: field
183 call atlas__FunctionSpace__halo_exchange_field(this%CPTR_PGIBUG_A,field%CPTR_PGIBUG_A)
184 end subroutine
185
186
187 !------------------------------------------------------------------------------
188
189 subroutine adjoint_halo_exchange_fieldset(this,fieldset)
190 use atlas_functionspace_c_binding
191 class(atlas_Functionspace), intent(in) :: this
192 type(atlas_FieldSet), intent(inout) :: fieldset
193 call atlas__FunctionSpace__adjoint_halo_exchange_fieldset(this%CPTR_PGIBUG_A,fieldset%CPTR_PGIBUG_A)
194 end subroutine
195
196 !------------------------------------------------------------------------------
197
198 subroutine adjoint_halo_exchange_field(this,field)
199 use atlas_functionspace_c_binding
200 class(atlas_Functionspace), intent(in) :: this
201 type(atlas_Field), intent(inout) :: field
202 call atlas__FunctionSpace__adjoint_halo_exchange_field(this%CPTR_PGIBUG_A,field%CPTR_PGIBUG_A)
203 end subroutine
204
205 !------------------------------------------------------------------------------
206
207 !------------------------------------------------------------------------------
208
209 ! Deprecated versions compatible to support IFS CY45R1
210
211 function deprecated_create_field_1(this,name,kind,levels,vars) result(field)
212 use atlas_functionspace_c_binding
213 use, intrinsic :: iso_c_binding, only : c_int
214 type(atlas_Field) :: field
215 class(atlas_Functionspace), intent(in) :: this
216 character(len=*), intent(in) :: name
217 integer, intent(in) :: kind
218 integer(c_int), intent(in) :: levels
219 integer(c_int), intent(in) :: vars(:)
220
221 integer(c_int) :: opt_variables
222
223 type(atlas_Config) :: options
224 options = atlas_Config()
225
226 call options%set("datatype",kind)
227 call options%set("name",name)
228 call options%set("levels",levels)
229 opt_variables = sum(vars)
230 call options%set("variables",opt_variables)
231
232 field = atlas_Field( atlas__FunctionSpace__create_field( this%CPTR_PGIBUG_A, options%CPTR_PGIBUG_B ) )
233
234 call options%final()
235
236 call field%return()
237 end function
238
239 function deprecated_create_field_2(this,require_name,kind,levels) result(field)
240 use atlas_functionspace_c_binding
241 use, intrinsic :: iso_c_binding, only : c_int
242 type(atlas_Field) :: field
243 class(atlas_Functionspace), intent(in) :: this
244 character(len=*), intent(in) :: require_name
245 integer, intent(in) :: kind
246 integer(c_int), intent(in) :: levels
247
248 type(atlas_Config) :: options
249 options = atlas_Config()
250
251 call options%set("datatype",kind)
252 call options%set("name",require_name)
253 call options%set("levels",levels)
254
255 field = atlas_Field( atlas__FunctionSpace__create_field( this%CPTR_PGIBUG_A, options%CPTR_PGIBUG_B ) )
256 call options%final()
257
258 call field%return()
259 end function
260
261 !-------------------------------------------------------------------------------
262
263 #if FCKIT_FINAL_NOT_INHERITING
264 ATLAS_FINAL subroutine atlas_FunctionSpace__final_auto(this)
265 type(atlas_FunctionSpace), intent(inout) :: this
266 #if FCKIT_FINAL_DEBUGGING
267 write(0,*) "atlas_FunctionSpace__final_auto"
268 #endif
269 #if FCKIT_FINAL_NOT_PROPAGATING
270 call this%final()
271 #endif
272 FCKIT_SUPPRESS_UNUSED( this )
273 end subroutine
274 #endif
275
276 !------------------------------------------------------------------------------
277
278
279 end module atlas_functionspace_module
280