Debian Codegraph @

src/atlas_f/mesh/atlas_HybridElements_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_HybridElements_module
12
13 use fckit_owned_object_module, only: fckit_owned_object
14 use atlas_Connectivity_module, only: atlas_MultiBlockConnectivity
15 use atlas_Field_module, only: atlas_Field
16 use atlas_ElementType_module, only: atlas_ElementType
17 use atlas_Elements_module, only: atlas_Elements
18 use atlas_kinds_module, only: ATLAS_KIND_IDX
19
20 implicit none
21
22 private :: fckit_owned_object
23 private :: atlas_MultiBlockConnectivity
24 private :: atlas_Field
25 private :: atlas_ElementType
26 private :: atlas_Elements
27
28 public :: atlas_HybridElements
29
30 private
31
32 !-----------------------------
33 ! atlas_HybridElements !
34 !-----------------------------
35
36 type, extends(fckit_owned_object) :: atlas_HybridElements
37 contains
38
39 ! Public methods
40 procedure, public :: size => atlas_HybridElements__size
41
42 procedure, public :: node_connectivity
43 procedure, public :: edge_connectivity
44 procedure, public :: cell_connectivity
45
46 #if ATLAS_BITS_LOCAL != 32
47 generic, public :: add => add_elements_int, add_elements_long, add_elements_with_nodes_int, &
48 & add_elements_with_nodes_long, add_field, &
49 & add_elements_with_nodes_int_int32, add_elements_with_nodes_long_int32
50 #else
51 generic, public :: add => add_elements_int, add_elements_long, add_elements_with_nodes_int, &
52 & add_elements_with_nodes_long, add_field
53 #endif
54 generic, public :: field => field_by_idx_long, field_by_idx_int, field_by_name
55
56 generic, public :: elements => elements_int, elements_long
57
58 procedure, public :: nb_fields
59 procedure, public :: has_field
60 procedure, public :: global_index
61 procedure, public :: remote_index
62 procedure, public :: partition
63 procedure, public :: halo
64
65 procedure, public :: nb_types
66
67 ! Private methods
68 procedure, private :: add_elements_int
69 procedure, private :: add_elements_long
70 procedure, private :: add_elements_with_nodes_int
71 procedure, private :: add_elements_with_nodes_long
72 #if ATLAS_BITS_LOCAL != 32
73 procedure, private :: add_elements_with_nodes_int_int32
74 procedure, private :: add_elements_with_nodes_long_int32
75 #endif
76 procedure, private :: add_field
77 procedure, private :: field_by_idx_int
78 procedure, private :: field_by_idx_long
79 procedure, private :: field_by_name
80
81 procedure, private :: elements_int
82 procedure, private :: elements_long
83
84 #if FCKIT_FINAL_NOT_INHERITING
85 final :: atlas_HybridElements__final_auto
86 #endif
87
88 end type
89
90 interface atlas_HybridElements
91 module procedure atlas_HybridElements__cptr
92 module procedure atlas_HybridElements__constructor
93 end interface
94
95 !========================================================
96 contains
97 !========================================================
98
99 function atlas_HybridElements__cptr(cptr) result(this)
100 use, intrinsic :: iso_c_binding
101 use atlas_hybridelements_c_binding
102 type(atlas_HybridElements) :: this
103 type(c_ptr), intent(in) :: cptr
104 call this%reset_c_ptr( cptr )
105 call this%return()
106 end function
107
108 function atlas_HybridElements__constructor() result(this)
109 use atlas_hybridelements_c_binding
110 type(atlas_HybridElements) :: this
111 call this%reset_c_ptr( atlas__mesh__HybridElements__create() )
112 call this%return()
113 end function
114
115 function atlas_HybridElements__size(this) result(val)
116 use, intrinsic :: iso_c_binding
117 use atlas_hybridelements_c_binding
118 integer(ATLAS_KIND_IDX) :: val
119 class(atlas_HybridElements), intent(in) :: this
120 val = atlas__mesh__HybridElements__size(this%CPTR_PGIBUG_A)
121 end function
122
123 function node_connectivity(this) result(connectivity)
124 use atlas_hybridelements_c_binding
125 class(atlas_HybridElements), intent(in) :: this
126 type(atlas_MultiBlockConnectivity) :: connectivity
127 connectivity = atlas_MultiBlockConnectivity( &
128 atlas__mesh__HybridElements__node_connectivity(this%CPTR_PGIBUG_A) )
129 call connectivity%return()
130 end function
131
132 function edge_connectivity(this) result(connectivity)
133 use atlas_hybridelements_c_binding
134 class(atlas_HybridElements), intent(in) :: this
135 type(atlas_MultiBlockConnectivity) :: connectivity
136 connectivity = atlas_MultiBlockConnectivity( &
137 atlas__mesh__HybridElements__edge_connectivity(this%CPTR_PGIBUG_A) )
138 call connectivity%return()
139 end function
140
141 function cell_connectivity(this) result(connectivity)
142 use atlas_hybridelements_c_binding
143 class(atlas_HybridElements), intent(in) :: this
144 type(atlas_MultiBlockConnectivity) :: connectivity
145 connectivity = atlas_MultiBlockConnectivity( &
146 atlas__mesh__HybridElements__cell_connectivity(this%CPTR_PGIBUG_A) )
147 call connectivity%return()
148 end function
149
150 subroutine add_elements_int(this,elementtype,nb_elements)
151 use, intrinsic :: iso_c_binding
152 use atlas_hybridelements_c_binding
153 class(atlas_HybridElements), intent(inout) :: this
154 type(atlas_ElementType) :: elementtype
155 integer(c_int) :: nb_elements
156 call atlas__mesh__HybridElements__add_elements(this%CPTR_PGIBUG_A,elementtype%CPTR_PGIBUG_A,int(nb_elements,ATLAS_KIND_IDX))
157 end subroutine
158
159 subroutine add_elements_long(this,elementtype,nb_elements)
160 use, intrinsic :: iso_c_binding
161 use atlas_hybridelements_c_binding
162 class(atlas_HybridElements), intent(inout) :: this
163 type(atlas_ElementType) :: elementtype
164 integer(c_long) :: nb_elements
165 call atlas__mesh__HybridElements__add_elements(this%CPTR_PGIBUG_A,elementtype%CPTR_PGIBUG_A,int(nb_elements,ATLAS_KIND_IDX))
166 end subroutine
167
168 subroutine add_elements_with_nodes_int(this,elementtype,nb_elements,node_connectivity)
169 use, intrinsic :: iso_c_binding
170 use atlas_hybridelements_c_binding
171 class(atlas_HybridElements), intent(inout) :: this
172 type(atlas_ElementType), intent(in) :: elementtype
173 integer(c_int), intent(in) :: nb_elements
174 integer(ATLAS_KIND_IDX), intent(in) :: node_connectivity(:)
175 call atlas__mesh__HybridElements__add_elements_with_nodes(this%CPTR_PGIBUG_A,&
176 & elementtype%CPTR_PGIBUG_A,int(nb_elements,ATLAS_KIND_IDX),node_connectivity,1)
177 end subroutine
178
179 subroutine add_elements_with_nodes_long(this,elementtype,nb_elements,node_connectivity)
180 use, intrinsic :: iso_c_binding
181 use atlas_hybridelements_c_binding
182 class(atlas_HybridElements), intent(inout) :: this
183 type(atlas_ElementType), intent(in) :: elementtype
184 integer(c_long), intent(in) :: nb_elements
185 integer(ATLAS_KIND_IDX), intent(in) :: node_connectivity(:)
186 call atlas__mesh__HybridElements__add_elements_with_nodes(this%CPTR_PGIBUG_A,&
187 & elementtype%CPTR_PGIBUG_A,int(nb_elements,ATLAS_KIND_IDX),node_connectivity,1)
188 end subroutine
189
190 #if ATLAS_BITS_LOCAL != 32
191 subroutine add_elements_with_nodes_int_int32(this,elementtype,nb_elements,node_connectivity)
192 use, intrinsic :: iso_c_binding
193 use atlas_hybridelements_c_binding
194 class(atlas_HybridElements), intent(inout) :: this
195 type(atlas_ElementType), intent(in) :: elementtype
196 integer(c_int), intent(in) :: nb_elements
197 integer(c_int), intent(in) :: node_connectivity(:)
198 integer(ATLAS_KIND_IDX), allocatable :: idx_node_connectivity(:)
199 allocate( idx_node_connectivity( nb_elements * elementtype%nb_nodes() ) )
200 idx_node_connectivity(:) = node_connectivity(:)
201 call atlas__mesh__HybridElements__add_elements_with_nodes(this%CPTR_PGIBUG_A,&
202 & elementtype%CPTR_PGIBUG_A,int(nb_elements,ATLAS_KIND_IDX),idx_node_connectivity,1)
203 deallocate( idx_node_connectivity )
204 end subroutine
205
206 subroutine add_elements_with_nodes_long_int32(this,elementtype,nb_elements,node_connectivity)
207 use, intrinsic :: iso_c_binding
208 use atlas_hybridelements_c_binding
209 class(atlas_HybridElements), intent(inout) :: this
210 type(atlas_ElementType), intent(in) :: elementtype
211 integer(c_long), intent(in) :: nb_elements
212 integer(c_int), intent(in) :: node_connectivity(:)
213 integer(ATLAS_KIND_IDX), allocatable :: idx_node_connectivity(:)
214 allocate( idx_node_connectivity( nb_elements * elementtype%nb_nodes() ) )
215 idx_node_connectivity(:) = node_connectivity(:)
216 call atlas__mesh__HybridElements__add_elements_with_nodes(this%CPTR_PGIBUG_A,&
217 & elementtype%CPTR_PGIBUG_A,int(nb_elements,ATLAS_KIND_IDX),idx_node_connectivity,1)
218 deallocate( idx_node_connectivity )
219 end subroutine
220 #endif
221
222 subroutine add_field(this,field)
223 use atlas_hybridelements_c_binding
224 class(atlas_HybridElements), intent(inout) :: this
225 type(atlas_Field), intent(in) :: field
226 call atlas__mesh__HybridElements__add_field(this%CPTR_PGIBUG_A, field%CPTR_PGIBUG_A)
227 end subroutine
228
229
230 function nb_types(this) result(val)
231 use atlas_hybridelements_c_binding
232 integer(ATLAS_KIND_IDX) :: val
233 class(atlas_HybridElements), intent(in) :: this
234 val = atlas__mesh__HybridElements__nb_types(this%CPTR_PGIBUG_A)
235 end function
236
237 function nb_fields(this) result(val)
238 use atlas_hybridelements_c_binding
239 integer(ATLAS_KIND_IDX) :: val
240 class(atlas_HybridElements), intent(in) :: this
241 val = atlas__mesh__HybridElements__nb_fields(this%CPTR_PGIBUG_A)
242 end function
243
244 function has_field(this,name) result(val)
245 use fckit_c_interop_module, only: c_str
246 use atlas_hybridelements_c_binding
247 logical :: val
248 class(atlas_HybridElements), intent(in) :: this
249 character(len=*), intent(in) :: name
250 if( atlas__mesh__HybridElements__has_field(this%CPTR_PGIBUG_A,c_str(name)) == 0 ) then
251 val = .False.
252 else
253 val = .True.
254 endif
255 end function
256
257 function field_by_name(this,name) result(field)
258 use fckit_c_interop_module, only: c_str
259 use atlas_hybridelements_c_binding
260 type(atlas_Field) :: field
261 class(atlas_HybridElements), intent(in) :: this
262 character(len=*), intent(in) :: name
263 field = atlas_Field( atlas__mesh__HybridElements__field_by_name(this%CPTR_PGIBUG_A,c_str(name)) )
264 call field%return()
265 end function
266
267 function field_by_idx_long(this,idx) result(field)
268 use, intrinsic :: iso_c_binding
269 use atlas_hybridelements_c_binding
270 type(atlas_Field) :: field
271 class(atlas_HybridElements), intent(in) :: this
272 integer(c_long), intent(in) :: idx
273 field = atlas_Field( atlas__mesh__HybridElements__field_by_idx(this%CPTR_PGIBUG_A,int(idx-1_c_long,ATLAS_KIND_IDX) ) )
274 call field%return()
275 end function
276
277 function field_by_idx_int(this,idx) result(field)
278 use, intrinsic :: iso_c_binding
279 use atlas_hybridelements_c_binding
280 type(atlas_Field) :: field
281 class(atlas_HybridElements), intent(in) :: this
282 integer(c_int), intent(in) :: idx
283 field = atlas_Field( atlas__mesh__HybridElements__field_by_idx(this%CPTR_PGIBUG_A,int(idx-1_c_int,ATLAS_KIND_IDX) ) )
284 call field%return()
285 end function
286
287 function global_index(this) result(field)
288 use atlas_hybridelements_c_binding
289 type(atlas_Field) :: field
290 class(atlas_HybridElements), intent(in) :: this
291 field = atlas_Field( atlas__mesh__HybridElements__global_index(this%CPTR_PGIBUG_A) )
292 call field%return()
293 end function
294
295 function remote_index(this) result(field)
296 use atlas_hybridelements_c_binding
297 type(atlas_Field) :: field
298 class(atlas_HybridElements), intent(in) :: this
299 field = atlas_Field( atlas__mesh__HybridElements__remote_index(this%CPTR_PGIBUG_A) )
300 call field%return()
301 end function
302
303 function partition(this) result(field)
304 use atlas_hybridelements_c_binding
305 type(atlas_Field) :: field
306 class(atlas_HybridElements), intent(in) :: this
307 field = atlas_Field( atlas__mesh__HybridElements__partition(this%CPTR_PGIBUG_A) )
308 call field%return()
309 end function
310
311 function halo(this) result(field)
312 use atlas_hybridelements_c_binding
313 type(atlas_Field) :: field
314 class(atlas_HybridElements), intent(in) :: this
315 field = atlas_Field( atlas__mesh__HybridElements__halo(this%CPTR_PGIBUG_A) )
316 call field%return()
317 end function
318
319 function elements_long(this,idx) result(elements)
320 use, intrinsic :: iso_c_binding
321 use atlas_hybridelements_c_binding
322 type(atlas_Elements) :: elements
323 class(atlas_HybridElements), intent(in) :: this
324 integer(c_long), intent(in) :: idx
325 elements = atlas_Elements( atlas__mesh__HybridElements__elements(this%CPTR_PGIBUG_A,int(idx-1_c_long,ATLAS_KIND_IDX) ) )
326 call elements%return()
327 end function
328
329 function elements_int(this,idx) result(elements)
330 use, intrinsic :: iso_c_binding
331 use atlas_hybridelements_c_binding
332 type(atlas_Elements) :: elements
333 class(atlas_HybridElements), intent(in) :: this
334 integer(c_int), intent(in) :: idx
335 elements = atlas_Elements( atlas__mesh__HybridElements__elements(this%CPTR_PGIBUG_A,int(idx-1_c_int,ATLAS_KIND_IDX) ) )
336 call elements%return()
337 end function
338
339 !-------------------------------------------------------------------------------
340
341 #if FCKIT_FINAL_NOT_INHERITING
342 ATLAS_FINAL subroutine atlas_HybridElements__final_auto(this)
343 type(atlas_HybridElements), intent(inout) :: this
344 #if FCKIT_FINAL_DEBUGGING
345 write(0,*) "atlas_HybridElements__final_auto"
346 #endif
347 #if FCKIT_FINAL_NOT_PROPAGATING
348 call this%final()
349 #endif
350 FCKIT_SUPPRESS_UNUSED( this )
351 end subroutine
352 #endif
353
354 end module atlas_HybridElements_module
355