Skip to content

Commit

Permalink
mixed precision: add test for coupler_types and data_override changes (
Browse files Browse the repository at this point in the history
  • Loading branch information
rem1776 authored Sep 28, 2023
1 parent acc1368 commit ea79688
Show file tree
Hide file tree
Showing 6 changed files with 419 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ settings.json
.vscode/*
*.code-workspace
# Local History for Visual Studio Code
.history/
.history/
18 changes: 4 additions & 14 deletions coupler/coupler_types.F90
Original file line number Diff line number Diff line change
Expand Up @@ -2738,7 +2738,7 @@ end subroutine CT_increment_data_3d_3d
!! @throw FATAL, "axes has less than 2 elements"
subroutine CT_set_diags_2d(var, diag_name, axes, time)
type(coupler_2d_bc_type), intent(inout) :: var !< BC_type structure for which to register diagnostics
character(len=*), intent(in) :: diag_name !< name for diagnostic file--if blank, then
character(len=*), intent(in) :: diag_name !< Module name for diagnostic file--if blank, then
!! don't register the fields
integer, dimension(:), intent(in) :: axes !< array of axes identifiers for diagnostic variable registration
type(time_type), intent(in) :: time !< model time variable for registering diagnostic field
Expand Down Expand Up @@ -2786,7 +2786,7 @@ end subroutine CT_set_diags_2d
!! @throw FATAL, "axes has less than 3 elements"
subroutine CT_set_diags_3d(var, diag_name, axes, time)
type(coupler_3d_bc_type), intent(inout) :: var !< BC_type structure for which to register diagnostics
character(len=*), intent(in) :: diag_name !< name for diagnostic file--if blank, then
character(len=*), intent(in) :: diag_name !< Module name for diagnostic file--if blank, then
!! don't register the fields
integer, dimension(:), intent(in) :: axes !< array of axes identifiers for diagnostic variable registration
type(time_type), intent(in) :: time !< model time variable for registering diagnostic field
Expand Down Expand Up @@ -3564,8 +3564,6 @@ subroutine CT_data_override_2d(gridname, var, Time)
character(len=3), intent(in) :: gridname !< 3-character long model grid ID
type(coupler_2d_bc_type), intent(inout) :: var !< BC_type structure to override
type(time_type), intent(in) :: time !< The current model time
!! TODO remove this when data_override is merged in
real(r8_kind), allocatable :: r8_field_values(:,:)
integer :: m, n

if(var%set .and. var%num_bcs .gt. 0) then
Expand All @@ -3582,10 +3580,7 @@ subroutine CT_data_override_2d(gridname, var, Time)
else if(associated(var%bc_r4)) then
do n = 1, var%num_bcs
do m = 1, var%bc_r4(n)%num_fields
!! this should be removed when data override is updated
r8_field_values = real(var%bc_r4(n)%field(m)%values, r8_kind)
call data_override(gridname, var%bc_r4(n)%field(m)%name, r8_field_values, Time)
var%bc_r4(n)%field(m)%values = real(r8_field_values, r4_kind)
call data_override(gridname, var%bc_r4(n)%field(m)%name, var%bc_r4(n)%field(m)%values, Time)
enddo
enddo
else
Expand All @@ -3598,8 +3593,6 @@ subroutine CT_data_override_3d(gridname, var, Time)
character(len=3), intent(in) :: gridname !< 3-character long model grid ID
type(coupler_3d_bc_type), intent(inout) :: var !< BC_type structure to override
type(time_type), intent(in) :: time !< The current model time
!! TODO remove this when data_override is merged in
real(r8_kind), allocatable :: r8_field_values(:,:,:)

integer :: m, n

Expand All @@ -3617,10 +3610,7 @@ subroutine CT_data_override_3d(gridname, var, Time)
else if(associated(var%bc_r4)) then
do n = 1, var%num_bcs
do m = 1, var%bc_r4(n)%num_fields
!! this should be removed when data override is updated
r8_field_values = real(var%bc_r4(n)%field(m)%values, r8_kind)
call data_override(gridname, var%bc_r4(n)%field(m)%name, r8_field_values, Time)
var%bc_r4(n)%field(m)%values = real(r8_field_values, r4_kind)
call data_override(gridname, var%bc_r4(n)%field(m)%name, var%bc_r4(n)%field(m)%values, Time)
enddo
enddo
else
Expand Down
7 changes: 6 additions & 1 deletion test_fms/coupler/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ LDADD = ${top_builddir}/libFMS/libFMS.la
# Build this test program.
check_PROGRAMS = test_coupler_2d_r4 test_coupler_2d_r8 \
test_coupler_3d_r4 test_coupler_3d_r8 \
test_coupler_types_r4 test_coupler_types_r8 \
test_atmos_ocean_fluxes_r4 test_atmos_ocean_fluxes_r8

# This is the source code for the test.
test_coupler_2d_r4_SOURCES = test_coupler_2d.F90 test_coupler_utils.inc
test_coupler_2d_r8_SOURCES = test_coupler_2d.F90 test_coupler_utils.inc
test_coupler_3d_r4_SOURCES = test_coupler_3d.F90 test_coupler_utils.inc
test_coupler_3d_r8_SOURCES = test_coupler_3d.F90 test_coupler_utils.inc
test_coupler_types_r4_SOURCES = test_coupler_types.F90 test_coupler_utils.inc
test_coupler_types_r8_SOURCES = test_coupler_types.F90 test_coupler_utils.inc
test_atmos_ocean_fluxes_r4_SOURCES = test_atmos_ocean_fluxes.F90
test_atmos_ocean_fluxes_r8_SOURCES = test_atmos_ocean_fluxes.F90

Expand All @@ -46,6 +49,8 @@ test_coupler_2d_r4_CPPFLAGS=-DFMS_CP_TEST_KIND_=r4_kind -DFMS_TEST_BC_TYPE_=bc_r
test_coupler_2d_r8_CPPFLAGS=-DFMS_CP_TEST_KIND_=r8_kind -DFMS_TEST_BC_TYPE_=bc -I$(MODDIR)
test_coupler_3d_r4_CPPFLAGS=-DFMS_CP_TEST_KIND_=r4_kind -DFMS_TEST_BC_TYPE_=bc_r4 -I$(MODDIR)
test_coupler_3d_r8_CPPFLAGS=-DFMS_CP_TEST_KIND_=r8_kind -DFMS_TEST_BC_TYPE_=bc -I$(MODDIR)
test_coupler_types_r4_CPPFLAGS=-DFMS_CP_TEST_KIND_=r4_kind -DFMS_TEST_BC_TYPE_=bc_r4 -I$(MODDIR)
test_coupler_types_r8_CPPFLAGS=-DFMS_CP_TEST_KIND_=r8_kind -DFMS_TEST_BC_TYPE_=bc -I$(MODDIR)
test_atmos_ocean_fluxes_r4_CPPFLAGS=-DFMS_CP_TEST_KIND_=r4_kind -DFMS_TEST_BC_TYPE_=bc_r4 -I$(MODDIR)
test_atmos_ocean_fluxes_r8_CPPFLAGS=-DFMS_CP_TEST_KIND_=r8_kind -DFMS_TEST_BC_TYPE_=bc -I$(MODDIR)

Expand All @@ -60,4 +65,4 @@ TESTS = test_coupler.sh
EXTRA_DIST = test_coupler.sh

# Clean up
CLEANFILES = input.nml *.nc* *.out *.dpi *.spi *.dyn *.spl diag_table*
CLEANFILES = input.nml *.nc* *.out *.dpi *.spi *.dyn *.spl *_table* INPUT/*.nc
88 changes: 78 additions & 10 deletions test_fms/coupler/test_coupler.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/bin/sh

#***********************************************************************
#* GNU Lesser General Public License
#*
Expand All @@ -18,31 +17,101 @@
#* You should have received a copy of the GNU Lesser General Public
#* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
#***********************************************************************

# This is part of the GFDL FMS package. This is a shell script to
# execute tests in the test_fms/data_override directory.
# execute tests in the test_fms/coupler directory.

# Ed Hartnett 11/26/19
# Uriel Ramirez 07/22/20

# Set common test settings.
. ../test-lib.sh

# Run the ongrid test case with 2 halos in x and y
touch input.nml

# diag_table for test
cat <<_EOF > diag_table
test_coupler
1 1 1 0 0 0
#output files
"coupler_types_test", 1, "days", 1, "days", "time"
"coupler_types_bc2", 1, "days", 1, "days", "time"
"coupler_types_bc1", 1, "days", 1, "days", "time"
#output variables
"test_coupler", "dat1", "dat1", "coupler_types_test", "all", .false., "none", 2
"test_coupler", "dat2", "dat2", "coupler_types_test", "all", .false., "none", 2
"test_coupler_types", "bc1_var2d_1", "bc1_variable_2d_1_min", "coupler_types_bc1", "all", "min", "none", 2
"test_coupler_types", "bc1_var2d_2", "bc1_variable_2d_2_max", "coupler_types_bc1", "all", "max", "none", 2
"test_coupler_types", "bc1_var3d_1", "bc1_variable_3d_1", "coupler_types_bc1", "all", "rms", "none", 2
"test_coupler_types", "bc1_var3d_2", "bc1_variable_3d_2", "coupler_types_bc1", "all", "avg", "none", 2
"test_coupler_types", "bc2_var2d_1", "bc2_variable_2d_1_min", "coupler_types_bc2", "all", "min", "none", 2
"test_coupler_types", "bc2_var2d_2", "bc2_variable_2d_2_max", "coupler_types_bc2", "all", "max", "none", 2
"test_coupler_types", "bc2_var3d_1", "bc2_variable_3d_1", "coupler_types_bc2", "all", "rms", "none", 2
"test_coupler_types", "bc2_var3d_2", "bc2_variable_3d_2", "coupler_types_bc2", "all", "avg", "none", 2
_EOF
# we'll just make both in case compiled with yaml support
cat <<_EOF > diag_table.yaml
title: test_coupler
base_date: 1 1 1 0 0 0
diag_files:
- file_name: coupler_types_bc2
filename_time: end
freq: 1 days
time_units: days
unlimdim: time
varlist:
- module: test_coupler_types
var_name: bc1_var2d_1
output_name: bc1_variable_2d_1_min
reduction: min
- module: test_coupler_types
var_name: bc1_var2d_2
output_name: bc1_variable_2d_2_max
reduction: max
- module: test_coupler_types
var_name: bc1_var3d_1
output_name: bc1_variable_3d_1
reduction: rms
- module: test_coupler_types
var_name: bc1_var3d_2
output_name: bc1_variable_3d_2
reduction: avg
- file_name: coupler_types_bc1
filename_time: end
freq: 1 days
time_units: days
unlimdim: time
varlist:
- module: test_coupler_types
var_name: bc2_var2d_1
output_name: bc2_variable_2d_1_min
reduction: min
- module: test_coupler_types
var_name: bc2_var2d_2
output_name: bc2_variable_2d_2_max
reduction: max
- module: test_coupler_types
var_name: bc2_var3d_1
output_name: bc2_variable_3d_1
reduction: rms
- module: test_coupler_types
var_name: bc2_var3d_2
output_name: bc2_variable_3d_2
reduction: avg
_EOF

cat <<_EOF > data_table
"ATM", "bc1_var2d_1", "bc1_variable_2d_1_min", "coupler_types_bc1.nc", .false., 300.0
_EOF

rm -rf INPUT
mkdir INPUT


test_expect_success "coupler types interfaces (r4_kind)" '
mpirun -n 4 ./test_coupler_types_r4
'

test_expect_success "coupler types interfaces (r8_kind)" '
mpirun -n 4 ./test_coupler_types_r8
'

mkdir RESTART

test_expect_success "coupler register restart 2D(r4_kind)" '
Expand All @@ -69,5 +138,4 @@ test_expect_success "test atmos_ocean_fluxes (r8_kind)" '
'

rm -rf RESTART

test_done
Loading

0 comments on commit ea79688

Please sign in to comment.