| 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_Elements_module |
| 12 |
|
| 13 |
use fckit_owned_object_module, only: fckit_owned_object |
| 14 |
use atlas_kinds_module, only : ATLAS_KIND_IDX |
| 15 |
|
| 16 |
implicit none |
| 17 |
|
| 18 |
private :: fckit_owned_object |
| 19 |
|
| 20 |
public :: atlas_Elements |
| 21 |
|
| 22 |
private |
| 23 |
|
| 24 |
!----------------------------- |
| 25 |
! atlas_Elements ! |
| 26 |
!----------------------------- |
| 27 |
|
| 28 |
type, extends(fckit_owned_object) :: atlas_Elements |
| 29 |
contains |
| 30 |
! Public methods |
| 31 |
procedure, public :: size => atlas_Elements__size |
| 32 |
procedure, public :: begin => atlas_Elements__begin |
| 33 |
procedure, public :: end => atlas_Elements__end |
| 34 |
|
| 35 |
procedure, public :: node_connectivity |
| 36 |
procedure, public :: edge_connectivity |
| 37 |
procedure, public :: cell_connectivity |
| 38 |
|
| 39 |
generic, public :: add => add_elements_long, add_elements_int |
| 40 |
generic, public :: field => field_by_idx_long, field_by_idx_int, field_by_name |
| 41 |
|
| 42 |
procedure, public :: element_type |
| 43 |
|
| 44 |
procedure, public :: nb_fields |
| 45 |
procedure, public :: has_field |
| 46 |
procedure, public :: global_index |
| 47 |
procedure, public :: remote_index |
| 48 |
procedure, public :: partition |
| 49 |
procedure, public :: halo |
| 50 |
|
| 51 |
! Private methods |
| 52 |
procedure, private :: field_by_idx_int |
| 53 |
procedure, private :: field_by_idx_long |
| 54 |
procedure, private :: field_by_name |
| 55 |
procedure, private :: add_elements_long |
| 56 |
procedure, private :: add_elements_int |
| 57 |
|
| 58 |
#if FCKIT_FINAL_NOT_INHERITING |
| 59 |
final :: atlas_Elements__final_auto |
| 60 |
#endif |
| 61 |
end type |
| 62 |
|
| 63 |
interface atlas_Elements |
| 64 |
module procedure atlas_Elements__cptr |
| 65 |
end interface |
| 66 |
|
| 67 |
|
| 68 |
!======================================================== |
| 69 |
contains |
| 70 |
!======================================================== |
| 71 |
|
| 72 |
function atlas_Elements__cptr(cptr) result(this) |
| 73 |
use, intrinsic :: iso_c_binding, only: c_ptr |
| 74 |
type(atlas_Elements) :: this |
| 75 |
type(c_ptr), intent(in) :: cptr |
| 76 |
call this%reset_c_ptr( cptr ) |
| 77 |
call this%return() |
| 78 |
end function |
| 79 |
|
| 80 |
function atlas_Elements__size(this) result(val) |
| 81 |
use atlas_elements_c_binding |
| 82 |
integer(ATLAS_KIND_IDX) :: val |
| 83 |
class(atlas_Elements), intent(in) :: this |
| 84 |
val = atlas__mesh__Elements__size(this%CPTR_PGIBUG_A) |
| 85 |
end function |
| 86 |
|
| 87 |
function node_connectivity(this) result(connectivity) |
| 88 |
use atlas_elements_c_binding |
| 89 |
use atlas_Connectivity_module, only: atlas_BlockConnectivity |
| 90 |
class(atlas_Elements), intent(in) :: this |
| 91 |
type(atlas_BlockConnectivity) :: connectivity |
| 92 |
connectivity = atlas_BlockConnectivity( & |
| 93 |
atlas__mesh__Elements__node_connectivity(this%CPTR_PGIBUG_A) ) |
| 94 |
!call connectivity%return() |
| 95 |
end function |
| 96 |
|
| 97 |
function edge_connectivity(this) result(connectivity) |
| 98 |
use atlas_elements_c_binding |
| 99 |
use atlas_Connectivity_module, only: atlas_BlockConnectivity |
| 100 |
class(atlas_Elements), intent(in) :: this |
| 101 |
type(atlas_BlockConnectivity) :: connectivity |
| 102 |
connectivity = atlas_BlockConnectivity( & |
| 103 |
atlas__mesh__Elements__edge_connectivity(this%CPTR_PGIBUG_A) ) |
| 104 |
!call connectivity%return() |
| 105 |
end function |
| 106 |
|
| 107 |
function cell_connectivity(this) result(connectivity) |
| 108 |
use atlas_elements_c_binding |
| 109 |
use atlas_Connectivity_module, only: atlas_BlockConnectivity |
| 110 |
class(atlas_Elements), intent(in) :: this |
| 111 |
type(atlas_BlockConnectivity) :: connectivity |
| 112 |
connectivity = atlas_BlockConnectivity( & |
| 113 |
atlas__mesh__Elements__cell_connectivity(this%CPTR_PGIBUG_A) ) |
| 114 |
!call connectivity%return() |
| 115 |
end function |
| 116 |
|
| 117 |
function element_type(this) result(etype) |
| 118 |
use atlas_elements_c_binding |
| 119 |
use atlas_ElementType_module, only: atlas_ElementType |
| 120 |
class(atlas_Elements), intent(in) :: this |
| 121 |
type(atlas_ElementType) :: etype |
| 122 |
etype = atlas_ElementType( & |
| 123 |
atlas__mesh__Elements__element_type(this%CPTR_PGIBUG_A) ) |
| 124 |
call etype%return() |
| 125 |
end function |
| 126 |
|
| 127 |
subroutine add_elements_long(this,nb_elements) |
| 128 |
use, intrinsic :: iso_c_binding, only: c_long, c_int |
| 129 |
use atlas_elements_c_binding |
| 130 |
class(atlas_Elements), intent(inout) :: this |
| 131 |
integer(c_long) :: nb_elements |
| 132 |
call atlas__mesh__Elements__add(this%CPTR_PGIBUG_A,int(nb_elements,ATLAS_KIND_IDX)) |
| 133 |
end subroutine |
| 134 |
|
| 135 |
subroutine add_elements_int(this,nb_elements) |
| 136 |
use, intrinsic :: iso_c_binding, only: c_int |
| 137 |
use atlas_elements_c_binding |
| 138 |
class(atlas_Elements), intent(inout) :: this |
| 139 |
integer(c_int) :: nb_elements |
| 140 |
call atlas__mesh__Elements__add(this%CPTR_PGIBUG_A,int(nb_elements,ATLAS_KIND_IDX)) |
| 141 |
end subroutine |
| 142 |
|
| 143 |
function nb_fields(this) result(val) |
| 144 |
use atlas_elements_c_binding |
| 145 |
integer(ATLAS_KIND_IDX) :: val |
| 146 |
class(atlas_Elements), intent(in) :: this |
| 147 |
val = atlas__mesh__Elements__nb_fields(this%CPTR_PGIBUG_A) |
| 148 |
end function |
| 149 |
|
| 150 |
function has_field(this,name) result(val) |
| 151 |
use fckit_c_interop_module, only: c_str |
| 152 |
use atlas_elements_c_binding |
| 153 |
logical :: val |
| 154 |
class(atlas_Elements), intent(in) :: this |
| 155 |
character(len=*), intent(in) :: name |
| 156 |
if( atlas__mesh__Elements__has_field(this%CPTR_PGIBUG_A,c_str(name)) == 0 ) then |
| 157 |
val = .False. |
| 158 |
else |
| 159 |
val = .True. |
| 160 |
endif |
| 161 |
end function |
| 162 |
|
| 163 |
function field_by_name(this,name) result(field) |
| 164 |
use fckit_c_interop_module, only: c_str |
| 165 |
use atlas_elements_c_binding |
| 166 |
use atlas_Field_module, only: atlas_Field |
| 167 |
type(atlas_Field) :: field |
| 168 |
class(atlas_Elements), intent(in) :: this |
| 169 |
character(len=*), intent(in) :: name |
| 170 |
field = atlas_Field( atlas__mesh__Elements__field_by_name(this%CPTR_PGIBUG_A,c_str(name)) ) |
| 171 |
call field%return() |
| 172 |
end function |
| 173 |
|
| 174 |
function field_by_idx_long(this,idx) result(field) |
| 175 |
use, intrinsic :: iso_c_binding, only: c_long |
| 176 |
use atlas_elements_c_binding |
| 177 |
use atlas_Field_module, only: atlas_Field |
| 178 |
type(atlas_Field) :: field |
| 179 |
class(atlas_Elements), intent(in) :: this |
| 180 |
integer(c_long), intent(in) :: idx |
| 181 |
field = atlas_Field( atlas__mesh__Elements__field_by_idx(this%CPTR_PGIBUG_A,int(idx-1_c_long,ATLAS_KIND_IDX) ) ) |
| 182 |
call field%return() |
| 183 |
end function |
| 184 |
|
| 185 |
function field_by_idx_int(this,idx) result(field) |
| 186 |
use, intrinsic :: iso_c_binding, only: c_int |
| 187 |
use atlas_elements_c_binding |
| 188 |
use atlas_Field_module, only: atlas_Field |
| 189 |
type(atlas_Field) :: field |
| 190 |
class(atlas_Elements), intent(in) :: this |
| 191 |
integer(c_int), intent(in) :: idx |
| 192 |
field = atlas_Field( atlas__mesh__Elements__field_by_idx(this%CPTR_PGIBUG_A,int(idx-1_c_int,ATLAS_KIND_IDX) ) ) |
| 193 |
call field%return() |
| 194 |
end function |
| 195 |
|
| 196 |
function global_index(this) result(field) |
| 197 |
use atlas_elements_c_binding |
| 198 |
use atlas_Field_module, only: atlas_Field |
| 199 |
type(atlas_Field) :: field |
| 200 |
class(atlas_Elements), intent(in) :: this |
| 201 |
field = atlas_Field( atlas__mesh__Elements__global_index(this%CPTR_PGIBUG_A) ) |
| 202 |
call field%return() |
| 203 |
end function |
| 204 |
|
| 205 |
function remote_index(this) result(field) |
| 206 |
use atlas_elements_c_binding |
| 207 |
use atlas_Field_module, only: atlas_Field |
| 208 |
type(atlas_Field) :: field |
| 209 |
class(atlas_Elements), intent(in) :: this |
| 210 |
field = atlas_Field( atlas__mesh__Elements__remote_index(this%CPTR_PGIBUG_A) ) |
| 211 |
call field%return() |
| 212 |
end function |
| 213 |
|
| 214 |
function partition(this) result(field) |
| 215 |
use atlas_elements_c_binding |
| 216 |
use atlas_Field_module, only: atlas_Field |
| 217 |
type(atlas_Field) :: field |
| 218 |
class(atlas_Elements), intent(in) :: this |
| 219 |
field = atlas_Field( atlas__mesh__Elements__partition(this%CPTR_PGIBUG_A) ) |
| 220 |
call field%return() |
| 221 |
end function |
| 222 |
|
| 223 |
function halo(this) result(field) |
| 224 |
use atlas_elements_c_binding |
| 225 |
use atlas_Field_module, only: atlas_Field |
| 226 |
type(atlas_Field) :: field |
| 227 |
class(atlas_Elements), intent(in) :: this |
| 228 |
field = atlas_Field( atlas__mesh__Elements__halo(this%CPTR_PGIBUG_A) ) |
| 229 |
call field%return() |
| 230 |
end function |
| 231 |
|
| 232 |
function atlas_Elements__begin(this) result(val) |
| 233 |
use atlas_elements_c_binding |
| 234 |
integer(ATLAS_KIND_IDX) :: val |
| 235 |
class(atlas_Elements), intent(in) :: this |
| 236 |
val = atlas__mesh__Elements__begin(this%CPTR_PGIBUG_A) + 1 |
| 237 |
end function |
| 238 |
|
| 239 |
function atlas_Elements__end(this) result(val) |
| 240 |
use atlas_elements_c_binding |
| 241 |
integer(ATLAS_KIND_IDX) :: val |
| 242 |
class(atlas_Elements), intent(in) :: this |
| 243 |
val = atlas__mesh__Elements__end(this%CPTR_PGIBUG_A) |
| 244 |
end function |
| 245 |
|
| 246 |
!------------------------------------------------------------------------------- |
| 247 |
|
| 248 |
#if FCKIT_FINAL_NOT_INHERITING |
| 249 |
ATLAS_FINAL subroutine atlas_Elements__final_auto(this) |
| 250 |
type(atlas_Elements), intent(inout) :: this |
| 251 |
#if FCKIT_FINAL_DEBUGGING |
| 252 |
write(0,*) "atlas_Elements__final_auto" |
| 253 |
#endif |
| 254 |
#if FCKIT_FINAL_NOT_PROPAGATING |
| 255 |
call this%final() |
| 256 |
#endif |
| 257 |
FCKIT_SUPPRESS_UNUSED( this ) |
| 258 |
end subroutine |
| 259 |
#endif |
| 260 |
|
| 261 |
end module atlas_Elements_module |