Skip to content

Commit

Permalink
add a unit test for Fortran API CoellColumns
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrdar committed Nov 20, 2023
1 parent 3a952b5 commit e553044
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/atlas_f/atlas_module.F90
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ module atlas_module
& atlas_Vertical
use atlas_functionspace_EdgeColumns_module, only: &
& atlas_functionspace_EdgeColumns
use atlas_functionspace_CellColumns_module, only: &
& atlas_functionspace_CellColumns
use atlas_functionspace_NodeColumns_module, only: &
& atlas_functionspace_NodeColumns
use atlas_functionspace_PointCloud_module, only: &
Expand Down
214 changes: 213 additions & 1 deletion src/tests/functionspace/fctest_functionspace.F90
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ module fcta_FunctionSpace_fxt
! -----------------------------------------------------------------------------

TEST( test_collectives )
#if 1
#if 0
use fckit_mpi_module
type(atlas_StructuredGrid) :: grid
type(atlas_MeshGenerator) :: meshgenerator
Expand Down Expand Up @@ -365,6 +365,218 @@ module fcta_FunctionSpace_fxt
#endif
END_TEST

! -----------------------------------------------------------------------------

TEST( test_cells )
#if 1
type(atlas_StructuredGrid) :: grid
type(atlas_MeshGenerator) :: meshgenerator
type(atlas_Mesh) :: mesh
type(atlas_functionspace_CellColumns) :: fs
type(atlas_Field) :: field, template
type(atlas_mesh_Nodes) :: cells
integer :: halo_size, nb_cells
halo_size = 1

grid = atlas_StructuredGrid("N24")
meshgenerator = atlas_MeshGenerator()
mesh = meshgenerator%generate(grid)
call meshgenerator%final()
fs = atlas_functionspace_CellColumns(mesh,halo_size)
cells = fs%cells()
nb_cells = fs%nb_cells()
write(msg,*) "nb_cells = ",nb_cells; call atlas_log%info(msg)

field = fs%create_field(atlas_real(c_float))
FCTEST_CHECK_EQUAL( field%rank() , 1 )
FCTEST_CHECK_EQUAL( field%name() , "" )
FCTEST_CHECK_EQUAL( field%kind() , atlas_real(c_float) )
call field%final()

field = fs%create_field(name="field",kind=atlas_real(c_float))
FCTEST_CHECK_EQUAL( field%rank() , 1 )
FCTEST_CHECK_EQUAL( field%name() , "field" )
FCTEST_CHECK_EQUAL( field%kind() , atlas_real(c_float) )
call field%final()

field = fs%create_field(atlas_real(c_float),variables=2)
FCTEST_CHECK_EQUAL( field%rank() , 2 )
FCTEST_CHECK_EQUAL( field%name() , "" )
call field%final()

field = fs%create_field(name="field",kind=atlas_integer(c_int),variables=2*2)
FCTEST_CHECK_EQUAL( field%rank() , 2 )
FCTEST_CHECK_EQUAL( field%name() , "field" )
template = field

field = fs%create_field(template)
FCTEST_CHECK_EQUAL( field%rank() , 2 )
FCTEST_CHECK_EQUAL( field%name() , template%name() )
call field%final()

field = fs%create_field(template,name="field")
FCTEST_CHECK_EQUAL( field%rank() , 2 )
FCTEST_CHECK_EQUAL( field%name() , "field" )
call field%final()
call template%final()


field = fs%create_field(atlas_real(c_float),global=.True.)
FCTEST_CHECK_EQUAL( field%rank() , 1 )
FCTEST_CHECK_EQUAL( field%name() , "" )
FCTEST_CHECK_EQUAL( field%kind() , atlas_real(c_float) )
call field%final()

field = fs%create_field(name="field",kind=atlas_real(c_float),global=.True.)
FCTEST_CHECK_EQUAL( field%rank() , 1 )
FCTEST_CHECK_EQUAL( field%name() , "field" )
FCTEST_CHECK_EQUAL( field%kind() , atlas_real(c_float) )
call field%final()

field = fs%create_field(atlas_real(c_float),variables=2,global=.True.)
FCTEST_CHECK_EQUAL( field%rank() , 2 )
FCTEST_CHECK_EQUAL( field%name() , "" )
call field%final()

field = fs%create_field(name="field",kind=atlas_integer(c_int),variables=2*2,global=.True.)
FCTEST_CHECK_EQUAL( field%rank() , 2 )
FCTEST_CHECK_EQUAL( field%name() , "field" )
template = field

field = fs%create_field(template,global=.True.)
FCTEST_CHECK_EQUAL( field%rank() , 2 )
FCTEST_CHECK_EQUAL( field%name() , template%name() )
call field%final()

field = fs%create_field(template,name="field",global=.True.)
FCTEST_CHECK_EQUAL( field%rank() , 2 )
FCTEST_CHECK_EQUAL( field%name() , "field" )
call field%final()
call template%final()

call fs%final()
call mesh%final()
call grid%final()
#else
#warning test test_cells disabled
#endif
END_TEST

! -----------------------------------------------------------------------------


TEST( test_cellscolumns )
#if 1
type(atlas_StructuredGrid) :: grid
type(atlas_MeshGenerator) :: meshgenerator
type(atlas_Mesh) :: mesh
type(atlas_functionspace_CellColumns) :: fs
type(atlas_Field) :: field, template
integer :: halo_size, levels
halo_size = 1
levels = 10

FCTEST_CHECK(.false.)
return

grid = atlas_StructuredGrid("N24")
meshgenerator = atlas_MeshGenerator()
mesh = meshgenerator%generate(grid)
call meshgenerator%final()
fs = atlas_functionspace_CellColumns(mesh,halo_size)

!levels = fs%nb_levels()
write(msg,*) "nb_levels = ",levels; call atlas_log%info(msg)

field = fs%create_field(atlas_real(c_float),levels=levels)
FCTEST_CHECK_EQUAL( field%rank() , 2 )
FCTEST_CHECK_EQUAL( field%name() , "" )
FCTEST_CHECK_EQUAL( field%kind() , atlas_real(c_float) )
call field%final()

field = fs%create_field(name="field",kind=atlas_real(c_float),levels=levels)
FCTEST_CHECK_EQUAL( field%rank() , 2 )
FCTEST_CHECK_EQUAL( field%name() , "field" )
FCTEST_CHECK_EQUAL( field%kind() , atlas_real(c_float) )
call field%final()

field = fs%create_field(atlas_real(c_float),levels=levels,variables=2)
FCTEST_CHECK_EQUAL( field%rank() , 3 )
FCTEST_CHECK_EQUAL( field%name() , "" )
call field%final()

field = fs%create_field(name="field",kind=atlas_integer(c_int),levels=levels,variables=2*2)
FCTEST_CHECK_EQUAL( field%rank() , 3 )
FCTEST_CHECK_EQUAL( field%name() , "field" )
template = field

field = fs%create_field(template)
FCTEST_CHECK_EQUAL( field%rank() , 3 )
FCTEST_CHECK_EQUAL( field%name() , template%name() )
call field%final()

field = fs%create_field(template,name="field")
FCTEST_CHECK_EQUAL( field%rank() , 3 )
FCTEST_CHECK_EQUAL( field%name() , "field" )
call field%final()
call template%final()


field = fs%create_field(atlas_real(c_float),levels=levels,global=.True.)
FCTEST_CHECK_EQUAL( field%rank() , 2 )
FCTEST_CHECK_EQUAL( field%name() , "" )
FCTEST_CHECK_EQUAL( field%kind() , atlas_real(c_float) )
call field%final()

field = fs%create_field(name="field",kind=atlas_real(c_float),levels=levels,global=.True.)
FCTEST_CHECK_EQUAL( field%rank() , 2 )
FCTEST_CHECK_EQUAL( field%name() , "field" )
FCTEST_CHECK_EQUAL( field%kind() , atlas_real(c_float) )
call field%final()

field = fs%create_field(atlas_real(c_float),levels=levels,variables=2,global=.True.)
FCTEST_CHECK_EQUAL( field%rank() , 3 )
FCTEST_CHECK_EQUAL( field%name() , "" )
call field%final()

field = fs%create_field(name="field",kind=atlas_integer(c_int),levels=levels,variables=2*2,global=.True.)
FCTEST_CHECK_EQUAL( field%rank() , 3 )
FCTEST_CHECK_EQUAL( field%name() , "field" )
template = field

field = fs%create_field(template,global=.True.)
FCTEST_CHECK_EQUAL( field%rank() , 3 )
FCTEST_CHECK_EQUAL( field%name() , template%name() )
call field%final()

field = fs%create_field(template,name="field",global=.True.)
FCTEST_CHECK_EQUAL( field%rank() , 3 )
FCTEST_CHECK_EQUAL( field%name() , "field" )
call field%final()
call template%final()

fs = atlas_functionspace_CellColumns(mesh,levels=5)
field = fs%create_field(atlas_real(c_float))
FCTEST_CHECK_EQUAL( field%rank() , 2 )
FCTEST_CHECK_EQUAL( field%name() , "" )
FCTEST_CHECK_EQUAL( field%kind() , atlas_real(c_float) )
call field%final()

FCTEST_CHECK_EQUAL( fs%owners(), 1 )
call fs%final()

FCTEST_CHECK_EQUAL( mesh%owners(), 1 )
call mesh%final()

FCTEST_CHECK_EQUAL( grid%owners(), 1 )
call grid%final()
#else
#warning test test_cellscolumns disabled
#endif
END_TEST

! -----------------------------------------------------------------------------




Expand Down

0 comments on commit e553044

Please sign in to comment.