Skip to content

Commit

Permalink
final files
Browse files Browse the repository at this point in the history
  • Loading branch information
wdeconinck committed Oct 2, 2024
1 parent 1971f62 commit c6240f0
Show file tree
Hide file tree
Showing 3 changed files with 412 additions and 158 deletions.
3 changes: 2 additions & 1 deletion src/atlas_f/field/atlas_MultiField_module.fypp
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ function atlas_MultiField__create_names(kind, shape, field_names) result(field)
flat_field_names((ii-1)*length+1:ii*length) = field_names(ii)
enddo

field = atlas_MultiField__cptr( atlas__MultiField__create_shape(kind, size(shape), shape, flat_field_names, length, size(field_names,kind=c_size_t)) )
field = atlas_MultiField__cptr( atlas__MultiField__create_shape(kind, size(shape), shape, &
& flat_field_names, length, size(field_names,kind=c_size_t)) )
call field%return()
end function

Expand Down
188 changes: 154 additions & 34 deletions src/tests/field/fctest_multifield_ifs.F90
Original file line number Diff line number Diff line change
Expand Up @@ -42,61 +42,181 @@ module fcta_MultiField_fixture
TEST( test_multifield )
implicit none

type(atlas_MultiField) :: multifield
type(atlas_FieldSet) :: fieldset_1, fieldset_2
type(atlas_MultiField) :: mfield(2)
type(atlas_FieldSet) :: fieldset(2)
type(atlas_Field) :: field
type(atlas_config) :: config
integer, pointer :: fdata_int_2d(:,:)
real(c_float), pointer :: fdata_real32_2d(:,:)
real(c_double), pointer :: fdata_real64_2d(:,:)
real(c_double), pointer :: fdata_real64(:,:,:)
real(c_float), pointer :: fdata_f2d(:,:), fdata_f3d(:,:,:)
real(c_double), pointer :: fdata_d3d(:,:,:)

integer, parameter :: nvar = 5;
integer, parameter :: nproma = 16;
integer, parameter :: nlev = 100;
integer, parameter :: nlev = 1;
integer, parameter :: ngptot = 2000;
type(atlas_Config), dimension(5) :: field_configs
character(len=12), parameter, dimension(nvar) :: var_names = (/ &
"temperature ", "pressure ", "density ", "clv ", "wind_u " &
/)

integer :: ivar
integer, parameter :: nblk = (ngptot + nproma - 1) / nproma
type(atlas_Config), allocatable :: field_configs(:)
integer :: i
character(len=64), parameter, dimension(5) :: var_names = [ character(64) :: &
"temperature", "pressure", "density", "clv", "wind_u" ]

config = atlas_Config()
call config%set("type", "MultiFieldCreatorIFS");
call config%set("ngptot", ngptot);
call config%set("nproma", nproma);
call config%set("nlev", nlev);
call config%set("datatype", "real64");
do ivar = 1, 5
field_configs(ivar) = atlas_Config()
call field_configs(ivar)%set("name", trim(var_names(ivar)))
allocate(field_configs(size(var_names)))
do i = 1, size(var_names)
field_configs(i) = atlas_Config()
call field_configs(i)%set("name", trim(var_names(i)))
end do
call field_configs(4)%set("nvar", 5) ! clv has five subvariables
call field_configs(4)%set("nvar", 4) ! clv has four subvariables
call config%set("fields", field_configs)

multifield = atlas_MultiField(config)
FCTEST_CHECK_EQUAL(multifield%size(), 5)
call config%set("nlev", 0); ! surface fields
call config%set("datatype", "real32");
mfield(1) = atlas_MultiField(config)

fieldset_1 = multifield%fieldset()
FCTEST_CHECK_EQUAL(fieldset_1%size(), 5)
call config%set("nlev", 4); ! fields are 3d
call config%set("datatype", "real64");
mfield(2) = atlas_MultiField(config)

fieldset(1) = mfield(1)%fieldset()
FCTEST_CHECK_EQUAL(mfield(1)%size(), 5)
FCTEST_CHECK_EQUAL(fieldset(1)%size(), 5)

fieldset_2 = atlas_FieldSet()
call fieldset_2%add(multifield%fieldset())
field = fieldset_2%field("density")
call field%data(fdata_real64)
fdata_real64(1,1,1) = 2.
fieldset(2) = atlas_FieldSet()
call fieldset(2)%add(mfield(1)%fieldset())
field = fieldset(2)%field("density")
call field%data(fdata_f2d)
fdata_f2d(1,1) = 2.
call field%rename("dens")

! check data access directly though multifield
!call multifield%data("density", fdata_real64)
call multifield%data("dens", fdata_real64)
fdata_real64(1,1,1) = 3.
call mfield(1)%data("dens", fdata_f2d)
fdata_f2d(1,1) = 3.

! check access to the renamed variable
field = fieldset(1)%field("dens")
call field%data(fdata_f2d)
FCTEST_CHECK_EQUAL(fdata_f2d(1,1), 3._c_float)

! check dimesionality
call mfield(2)%data("density", fdata_d3d)
fdata_d3d(1,1,1) = 4.
fieldset(2) = atlas_FieldSet()
call fieldset(2)%add(mfield(2)%fieldset())
field = fieldset(2)%field("density")
call field%data(fdata_d3d)
FCTEST_CHECK_EQUAL(fdata_d3d(1,1,1), 4._c_double)
END_TEST


TEST( test_multifield_array_direct_constructor )
implicit none

type(atlas_MultiField) :: mfield(2)
type(atlas_FieldSet) :: fset
type(atlas_Field) :: field
type(atlas_config) :: config
real(c_float), pointer :: fdata_f2d(:,:), fdata_f3d(:,:,:)
real(c_double), pointer :: fdata_d3d(:,:,:)

integer, parameter :: nproma = 16;
integer, parameter :: nlev = 100;
integer, parameter :: ngptot = 2000;
integer, parameter :: nblk = (ngptot + nproma - 1) / nproma
integer :: i
character(len=64), parameter, dimension(5) :: var_names = [ character(64) :: &
"temperature ", "pressure", "density", "clv", "wind_u" ]

return

field = fieldset_1%field("dens")
call field%data(fdata_real64)
FCTEST_CHECK_EQUAL(fdata_real64(1,1,1), 3._c_double)
! surface fields
mfield(1) = atlas_MultiField('real32', [nproma, -1, nblk], var_names)

! 3d fields
mfield(2) = atlas_MultiField('real64', [nproma, nlev, -1, nblk], var_names)

FCTEST_CHECK_EQUAL(mfield(1)%size(), 5)

call mfield(1)%data("density", fdata_f2d)
fdata_f2d(1,1) = 3.
call mfield(2)%data("density", fdata_d3d)
fdata_d3d(1,1,1) = 4.

fset = atlas_FieldSet()
call fset%add(mfield(1)%fieldset())
call fset%add(mfield(2)%fieldset())

END_TEST


TEST( test_multifield_array_config_constuctor )
implicit none

type(atlas_MultiField) :: mfield(2)
type(atlas_FieldSet) :: fieldset(2)
type(atlas_Field) :: field
type(atlas_config) :: config
integer, pointer :: fdata_int_2d(:,:)
real(c_float), pointer :: fdata_f2d(:,:), fdata_f3d(:,:,:)
real(c_double), pointer :: fdata_d3d(:,:,:)

integer, parameter :: nproma = 16;
integer, parameter :: nlev = 1;
integer, parameter :: nblk = 200;
type(atlas_Config), allocatable :: field_configs(:)
integer :: i
character(len=64), parameter, dimension(5) :: var_names = [ character(64) :: &
"temperature", "pressure", "density", "clv", "wind_u" ]

config = atlas_Config()
call config%set("type", "MultiFieldCreatorArray");
allocate(field_configs(size(var_names)))
do i = 1, size(var_names)
field_configs(i) = atlas_Config()
call field_configs(i)%set("name", trim(var_names(i)))
end do
call field_configs(4)%set("nvar", 5) ! clv has four subvariables
call config%set("fields", field_configs)

! surface fields
call config%set("shape", [nproma, -1, nblk]);
call config%set("datatype", "real32");
mfield(1) = atlas_MultiField(config)

! fields are 3d
call config%set("shape", [nproma, nlev, -1, nblk]);
call config%set("datatype", "real64");
mfield(2) = atlas_MultiField(config)

fieldset(1) = mfield(1)%fieldset()
FCTEST_CHECK_EQUAL(mfield(1)%size(), 9)
FCTEST_CHECK_EQUAL(fieldset(1)%size(), 9)

fieldset(2) = atlas_FieldSet()
call fieldset(2)%add(mfield(1)%fieldset())
field = fieldset(2)%field("density")
call field%data(fdata_f2d)
fdata_f2d(1,1) = 2.
call field%rename("dens")

! check data access directly though multifield
call mfield(1)%data("dens", fdata_f2d)
fdata_f2d(1,1) = 3.

! check access to the renamed variable
field = fieldset(1)%field("dens")
call field%data(fdata_f2d)
FCTEST_CHECK_EQUAL(fdata_f2d(1,1), 3._c_float)

! check dimesionality
call mfield(2)%data("density", fdata_d3d)
fdata_d3d(1,1,1) = 4.
fieldset(2) = atlas_FieldSet()
call fieldset(2)%add(mfield(2)%fieldset())
field = fieldset(2)%field("density")
call field%data(fdata_d3d)
FCTEST_CHECK_EQUAL(fdata_d3d(1,1,1), 4._c_double)
END_TEST

! -----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit c6240f0

Please sign in to comment.