Skip to content

Commit be13d4d

Browse files
pchakrabortytclune
andauthored
Field copy - return if both fields point to the same data (#4713)
* MAPL_GridCompAddSpec: rename default_value -> fill_value Also propagate the name change downstream to VariableSpec and state item specs (Field, Bracket, Vector) and affected routines * FieldCopy: return early if both fields point to the same data * Make FieldBundleCopy available to users * Fixed tests * Fixed tests --------- Co-authored-by: Tom Clune <thomas.l.clune@nasa.gov>
1 parent 8e0ba69 commit be13d4d

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

field/FieldPointerUtilities.F90

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module MAPL_FieldPointerUtilities
44
use ESMF
55
use MAPL_ExceptionHandling
6-
use, intrinsic :: iso_c_binding, only: c_ptr, c_f_pointer, c_loc
6+
use, intrinsic :: iso_c_binding, only: c_ptr, c_f_pointer, c_loc, c_associated
77
implicit none
88
private
99

@@ -788,20 +788,21 @@ subroutine copy(x, y, rc)
788788
logical :: conformable
789789
logical :: x_is_double
790790
logical :: y_is_double
791-
character(len=*), parameter :: UNSUPPORTED_TK = &
792-
'Unsupported typekind in FieldCOPY() for '
791+
character(len=*), parameter :: UNSUPPORTED_TK = 'Unsupported typekind in FieldCOPY() for '
793792

794793
conformable = FieldsAreConformable(x, y)
795794
!wdb fixme need to pass RC
796795
_ASSERT(conformable, 'FieldCopy() - fields not conformable.')
796+
797797
call FieldGetCptr(x, cptr_x, _RC)
798+
call FieldGetCptr(y, cptr_y, _RC)
799+
_RETURN_IF(c_associated(cptr_x, cptr_y)) ! nothing to copy if both point to the same data
800+
798801
call ESMF_FieldGet(x, typekind = tk_x, _RC)
802+
call ESMF_FieldGet(y, typekind = tk_y, _RC)
799803

800804
n = FieldGetLocalSize(x, _RC)
801805

802-
call FieldGetCptr(y, cptr_y, _RC)
803-
call ESMF_FieldGet(y, typekind = tk_y, _RC)
804-
805806
!wdb fixme convert between precisions ? get rid of extra cases
806807
y_is_double = (tk_y == ESMF_TYPEKIND_R8)
807808
_ASSERT(y_is_double .or. (tk_y == ESMF_TYPEKIND_R4), UNSUPPORTED_TK//'y.')
@@ -919,7 +920,7 @@ subroutine MAPL_FieldGetLocalElementCount(field,local_count,rc)
919920
end select
920921
_RETURN(_SUCCESS)
921922
end if
922-
923+
923924
if (tk == ESMF_TypeKind_R8) then
924925
select case(rank)
925926
case(1)

field_bundle/API.F90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module mapl3g_FieldBundle_API
1010
use mapl3g_FieldBundleInfo, only: MAPL_FieldBundleInfoGetInternal => FieldBundleInfoGetInternal
1111
use mapl3g_FieldBundleInfo, only: MAPL_FieldBundleInfoSetInternal => FieldBundleInfoSetInternal
1212
use mapl3g_FieldBundleGetPointer, only: MAPL_FieldBundleGetPointer => FieldBundleGetPointerToData
13+
use mapl3g_FieldBundleCopy, only: MAPL_FieldBundleCopy => FieldBundleCopy
1314

1415
implicit none
1516

@@ -22,6 +23,7 @@ module mapl3g_FieldBundle_API
2223
public :: MAPL_FieldBundleSet
2324
public :: MAPL_FieldBundleAdd
2425
public :: MAPL_FieldBundleGetPointer
26+
public :: MAPL_FieldBundleCopy
2527
! Maybe these should be private?
2628
public :: MAPL_FieldBundleInfoGetInternal
2729
public :: MAPL_FieldBundleInfoSetInternal

0 commit comments

Comments
 (0)