| 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_GridDistribution_module |
| 12 |
|
| 13 |
use fckit_owned_object_module, only: fckit_owned_object |
| 14 |
use, intrinsic :: iso_c_binding, only : c_ptr |
| 15 |
|
| 16 |
implicit none |
| 17 |
|
| 18 |
public :: atlas_GridDistribution |
| 19 |
|
| 20 |
private |
| 21 |
|
| 22 |
!----------------------------- |
| 23 |
! atlas_GridDistribution ! |
| 24 |
!----------------------------- |
| 25 |
|
| 26 |
|
| 27 |
!------------------------------------------------------------------------------ |
| 28 |
TYPE, extends(fckit_owned_object) :: atlas_GridDistribution |
| 29 |
|
| 30 |
! Purpose : |
| 31 |
! ------- |
| 32 |
! *GridDistribution* : Object passed from atlas to inspect grid distribution |
| 33 |
|
| 34 |
! Methods : |
| 35 |
! ------- |
| 36 |
|
| 37 |
! Author : |
| 38 |
! ------ |
| 39 |
! 12-Mar-2014 Willem Deconinck *ECMWF* |
| 40 |
|
| 41 |
!------------------------------------------------------------------------------ |
| 42 |
contains |
| 43 |
procedure :: nb_partitions => atlas_GridDistribution__nb_partitions |
| 44 |
procedure :: nb_pts => atlas_GridDistribution__nb_pts |
| 45 |
procedure, private :: partition_int32 |
| 46 |
procedure, private :: partition_int64 |
| 47 |
generic :: partition => partition_int32, partition_int64 |
| 48 |
|
| 49 |
#if FCKIT_FINAL_NOT_INHERITING |
| 50 |
final :: atlas_GridDistribution__final_auto |
| 51 |
#endif |
| 52 |
END TYPE atlas_GridDistribution |
| 53 |
|
| 54 |
!------------------------------------------------------------------------------ |
| 55 |
|
| 56 |
interface atlas_GridDistribution |
| 57 |
module procedure atlas_GridDistribution__cptr |
| 58 |
module procedure atlas_GridDistribution__ctor |
| 59 |
module procedure atlas_GridDistribution__ctor_Grid_Config |
| 60 |
module procedure atlas_GridDistribution__ctor_Grid_Partitioner |
| 61 |
end interface |
| 62 |
|
| 63 |
private :: c_ptr |
| 64 |
private :: fckit_owned_object |
| 65 |
|
| 66 |
!======================================================== |
| 67 |
contains |
| 68 |
!======================================================== |
| 69 |
! ----------------------------------------------------------------------------- |
| 70 |
! GridDistribution routines |
| 71 |
|
| 72 |
function atlas_GridDistribution__cptr( cptr ) result(this) |
| 73 |
use atlas_distribution_c_binding |
| 74 |
type(atlas_GridDistribution) :: this |
| 75 |
type(c_ptr) :: cptr |
| 76 |
call this%reset_c_ptr( cptr ) |
| 77 |
call this%return() |
| 78 |
end function |
| 79 |
|
| 80 |
function atlas_GridDistribution__ctor( part, part0 ) result(this) |
| 81 |
use atlas_distribution_c_binding |
| 82 |
use atlas_kinds_module, only : ATLAS_KIND_IDX |
| 83 |
type(atlas_GridDistribution) :: this |
| 84 |
integer, intent(in) :: part(:) |
| 85 |
integer, intent(in), optional :: part0 |
| 86 |
integer(ATLAS_KIND_IDX) :: npts |
| 87 |
integer :: opt_part0 |
| 88 |
opt_part0 = 0 |
| 89 |
if( present(part0) ) opt_part0 = part0 |
| 90 |
npts = size(part) |
| 91 |
call this%reset_c_ptr( atlas__GridDistribution__new(npts, part, opt_part0) ) |
| 92 |
call this%return() |
| 93 |
end function |
| 94 |
|
| 95 |
!fckit_owned_object |
| 96 |
function atlas_GridDistribution__ctor_Grid_Config( grid, config ) result(this) |
| 97 |
use atlas_distribution_c_binding |
| 98 |
use atlas_Grid_module, only : atlas_Grid |
| 99 |
use atlas_Config_module, only : atlas_Config |
| 100 |
type(atlas_GridDistribution) :: this |
| 101 |
class(atlas_Grid), intent (in) :: grid |
| 102 |
type(atlas_Config), intent(in) :: config |
| 103 |
call this%reset_c_ptr( atlas__GridDistribution__new__Grid_Config(grid%CPTR_PGIBUG_A, config%CPTR_PGIBUG_B) ) |
| 104 |
call this%return() |
| 105 |
end function |
| 106 |
|
| 107 |
function atlas_GridDistribution__ctor_Grid_Partitioner( grid, partitioner ) result(this) |
| 108 |
use atlas_distribution_c_binding |
| 109 |
use atlas_Grid_module, only : atlas_Grid |
| 110 |
use atlas_Config_module, only : atlas_Config |
| 111 |
type(atlas_GridDistribution) :: this |
| 112 |
class(atlas_Grid), intent (in) :: grid |
| 113 |
class(fckit_owned_object), intent(in) :: partitioner ! cannot use atlas_Partitioner as it would cause cyclic module dependencies |
| 114 |
call this%reset_c_ptr( atlas__GridDistribution__new__Grid_Partitioner(grid%CPTR_PGIBUG_A, partitioner%CPTR_PGIBUG_A) ) |
| 115 |
call this%return() |
| 116 |
end function |
| 117 |
|
| 118 |
|
| 119 |
function partition_int32(this, i) result(partition) |
| 120 |
use, intrinsic :: iso_c_binding, only: c_long, c_int |
| 121 |
use atlas_distribution_c_binding |
| 122 |
integer(c_int) :: partition |
| 123 |
class(atlas_GridDistribution), intent(in) :: this |
| 124 |
integer(c_int), intent(in) :: i |
| 125 |
partition = atlas__GridDistribution__partition_int32(this%CPTR_PGIBUG_A, i-1) |
| 126 |
end function |
| 127 |
|
| 128 |
function partition_int64(this, i) result(partition) |
| 129 |
use, intrinsic :: iso_c_binding, only: c_long, c_int |
| 130 |
use atlas_distribution_c_binding |
| 131 |
integer(c_int) :: partition |
| 132 |
class(atlas_GridDistribution), intent(in) :: this |
| 133 |
integer(c_long), intent(in) :: i |
| 134 |
partition = atlas__GridDistribution__partition_int64(this%CPTR_PGIBUG_A, i-1) |
| 135 |
end function |
| 136 |
|
| 137 |
|
| 138 |
function atlas_GridDistribution__nb_pts(this) result(nb_pts) |
| 139 |
use atlas_distribution_c_binding |
| 140 |
use atlas_kinds_module, only : ATLAS_KIND_IDX |
| 141 |
class(atlas_GridDistribution) :: this |
| 142 |
integer(kind=ATLAS_KIND_IDX), allocatable :: nb_pts(:) |
| 143 |
allocate (nb_pts (this%nb_partitions ())) |
| 144 |
call atlas__GridDistribution__nb_pts(this%CPTR_PGIBUG_A, nb_pts) |
| 145 |
end function |
| 146 |
|
| 147 |
function atlas_GridDistribution__nb_partitions(this) result(nb_partitions) |
| 148 |
use, intrinsic :: iso_c_binding, only: c_long |
| 149 |
use atlas_distribution_c_binding |
| 150 |
class(atlas_GridDistribution), intent(in) :: this |
| 151 |
integer(c_long) :: nb_partitions |
| 152 |
nb_partitions = atlas__atlas__GridDistribution__nb_partitions(this%CPTR_PGIBUG_A) |
| 153 |
end function |
| 154 |
|
| 155 |
! ---------------------------------------------------------------------------------------- |
| 156 |
|
| 157 |
#if FCKIT_FINAL_NOT_INHERITING |
| 158 |
ATLAS_FINAL subroutine atlas_GridDistribution__final_auto(this) |
| 159 |
type(atlas_GridDistribution), intent(inout) :: this |
| 160 |
#if FCKIT_FINAL_DEBUGGING |
| 161 |
write(0,*) "atlas_GridDistribution__final_auto" |
| 162 |
#endif |
| 163 |
#if FCKIT_FINAL_NOT_PROPAGATING |
| 164 |
call this%final() |
| 165 |
#endif |
| 166 |
FCKIT_SUPPRESS_UNUSED( this ) |
| 167 |
end subroutine |
| 168 |
#endif |
| 169 |
|
| 170 |
! ---------------------------------------------------------------------------------------- |
| 171 |
|
| 172 |
end module atlas_GridDistribution_module |