Skip to content

Commit

Permalink
Remove SOCA internal variable names (#1082)
Browse files Browse the repository at this point in the history
* adjust print size automatically

* ssh

* tocn

* mld

* socn

* more vars

* make a bunch of tests work

* more tests updated

* all tests pass

* revert depth_below_sea_surface

* get rid of unused metadata fields

* fix everything else I forgot

* forgot a "<"
  • Loading branch information
travissluka authored Oct 17, 2024
1 parent 761d271 commit 8a721c0
Show file tree
Hide file tree
Showing 77 changed files with 1,150 additions and 517 deletions.
8 changes: 7 additions & 1 deletion src/soca/Fields/Fields.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ double Fields::norm() const {
void Fields::print(std::ostream & os) const {
os << std::endl << " Valid time: " << validTime();

// find the longest field name, for use in formatting of the print
size_t maxNameLen = 0;
for (const auto & field : fieldSet_) {
maxNameLen = std::max(maxNameLen, field.name().size());
}

// for each field
for (const auto & field : fieldSet_) {
size_t count = 0;
Expand Down Expand Up @@ -175,7 +181,7 @@ void Fields::print(std::ostream & os) const {
if (count > 0) sum /= count;

// done with this field, print information
os << std::endl << std::right << std::setw(7) << field.name()
os << std::endl << std::right << std::setw(maxNameLen) << field.name()
<< " min=" << std::fixed << std::setw(12) <<
std::right << min
<< " max=" << std::fixed << std::setw(12) <<
Expand Down
11 changes: 4 additions & 7 deletions src/soca/Fields/FieldsMetadata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,18 @@ FieldsMetadata::FieldsMetadata(const std::string & filename) {
// read in portion of the values (not all are read in on the C++ side, until
// needed)
f->name = config.getString("name");
f->getvalName = config.getString("getval name", f->name);
f->getvalNameSurface = config.getString("getval name surface", "");
f->nameSurface = config.getString("name surface", "");

// check for duplicates
if (fieldMetadata_.count(f->name) > 0 ||
fieldMetadata_.count(f->getvalName) > 0 ||
fieldMetadata_.count(f->getvalNameSurface) > 0) {
fieldMetadata_.count(f->nameSurface) > 0) {
util::abor1_cpp("Duplicate field metadata: " + f->name);
}

// insert into the maps, multiple copies are inserted for valid name
fieldMetadata_[f->name] = f;
fieldMetadata_[f->getvalName] = f;
if (f->getvalNameSurface != "") {
fieldMetadata_[f->getvalNameSurface] = f;
if (f->nameSurface != "") {
fieldMetadata_[f->nameSurface] = f;
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/soca/Fields/FieldsMetadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ namespace soca {
/// variable name used by UFO, and the variable name used by UFO for the surface
/// (if this is a 3D field).
struct FieldMetadata {
std::string name; ///< The internal (within soca) variable name.
std::string getvalName; ///< The variable name used by UFO.
std::string getvalNameSurface; ///< The variable name used by UFO for the surface
/// (if this is a 3D field).
std::string name; ///< The soca and JEDI name.
std::string nameSurface; ///< The variable name used by UFO for the surface
/// (if this is a 3D field).
};

// --------------------------------------------------------------------------------------
Expand Down
28 changes: 9 additions & 19 deletions src/soca/Fields/soca_fields_metadata_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ module soca_fields_metadata_mod
!!
!! Instances of these types are to be held by soca_fields_metadata
type, public :: soca_field_metadata
character(len=:), allocatable :: name !< internal name used only by soca code
character(len=:), allocatable :: name !< name used by soca and JEDI
character(len=:), allocatable :: name_surface !< name used by UFO for the surface (if this is a 3D field)
character(len=1) :: grid !< "h", "u" or "v"
logical :: masked !< should use land mask when interpolating
character(len=:), allocatable :: levels !< "1", or "full_ocn"
character(len=:), allocatable :: getval_name !< variable name used by UFO
character(len=:), allocatable :: getval_name_surface ! name used by UFO for the surface (if this is a 3D field)
character(len=:), allocatable :: io_file !< the restart file domain (ocn, sfc, ice). Or if "CONSTANT" use the value in "constant_value"
character(len=:), allocatable :: io_name !< the name use in the restart IO
character(len=:), allocatable :: property !< physical property of the field, "none" or "positive_definite"
Expand Down Expand Up @@ -88,6 +87,9 @@ subroutine soca_fields_metadata_create(self, filename)

call conf_list(i)%get_or_die("name", self%metadata(i)%name)

if(.not. conf_list(i)%get("name surface", str)) str=""
self%metadata(i)%name_surface = str

if(.not. conf_list(i)%get("grid", str)) str = 'h'
self%metadata(i)%grid = str

Expand All @@ -97,12 +99,6 @@ subroutine soca_fields_metadata_create(self, filename)
if(.not. conf_list(i)%get("levels", str)) str = "1"
self%metadata(i)%levels = str

if(.not. conf_list(i)%get("getval name", str)) str=self%metadata(i)%name
self%metadata(i)%getval_name = str

if(.not. conf_list(i)%get("getval name surface", str)) str=""
self%metadata(i)%getval_name_surface = str

if(.not. conf_list(i)%get("io name", str)) str = ""
self%metadata(i)%io_name = str

Expand Down Expand Up @@ -140,14 +136,9 @@ subroutine soca_fields_metadata_create(self, filename)
do i=1,size(self%metadata)
do j=i+1,size(self%metadata)
if ( self%metadata(i)%name == self%metadata(j)%name .or. &
self%metadata(i)%name == self%metadata(j)%getval_name .or. &
self%metadata(i)%name == self%metadata(j)%getval_name_surface .or. &
self%metadata(i)%getval_name == self%metadata(j)%name .or. &
self%metadata(i)%getval_name == self%metadata(j)%getval_name .or. &
self%metadata(i)%getval_name == self%metadata(j)%getval_name_surface .or. &
( self%metadata(i)%getval_name_surface /= "" .and. ( &
self%metadata(i)%getval_name_surface == self%metadata(j)%name .or. &
self%metadata(i)%getval_name_surface == self%metadata(j)%getval_name ))) then
self%metadata(i)%name == self%metadata(j)%name_surface .or. &
( self%metadata(i)%name_surface /= "" .and. &
self%metadata(i)%name_surface == self%metadata(j)%name)) then
str=repeat(" ",1024)
write(str, *) "Duplicate field metadata: ", i, self%metadata(i)%name, &
j, self%metadata(j)%name
Expand Down Expand Up @@ -186,8 +177,7 @@ function soca_fields_metadata_get(self, name) result(field)
! find the field by any of its internal or getval names
do i=1,size(self%metadata)
if( trim(self%metadata(i)%name) == trim(name) .or. &
trim(self%metadata(i)%getval_name) == trim(name) .or. &
trim(self%metadata(i)%getval_name_surface) == trim(name) ) then
trim(self%metadata(i)%name_surface) == trim(name) ) then
field = self%metadata(i)
return
endif
Expand Down
16 changes: 8 additions & 8 deletions src/soca/Fields/soca_fields_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ subroutine soca_fields_init_vars(self, vars)
end select

! determine number of levels
if (self%fields(i)%name == self%fields(i)%metadata%getval_name_surface) then
if (self%fields(i)%name == self%fields(i)%metadata%name_surface) then
! if this field is a surface getval, override the number of levels with 1
nz = 1
else
Expand Down Expand Up @@ -727,7 +727,7 @@ subroutine soca_fields_read(self, f_conf, vdate)

! iread = 1 (state) or 3 (increment): Read restart file
if ((iread==1).or.(iread==3)) then
if (self%has("hocn")) call self%get("hocn", hocn)
if (self%has("sea_water_cell_thickness")) call self%get("sea_water_cell_thickness", hocn)
! filename for ocean
call f_conf%get_or_die("basename", str)
basename = str
Expand Down Expand Up @@ -900,19 +900,19 @@ subroutine soca_fields_read(self, f_conf, vdate)

! Initialize mid-layer depth from layer thickness
! TODO, this shouldn't live here, it should be part of the variable change class only
if (self%has("layer_depth")) then
call self%get("layer_depth", layer_depth)
if (self%has("sea_water_depth")) then
call self%get("sea_water_depth", layer_depth)
layer_depth%val = 0.5 * hocn%val
do k = 2, hocn%nz
layer_depth%val(:,:,k) = layer_depth%val(:,:,k) + sum(hocn%val(:,:,1:k-1), dim=3)
end do
end if

! Compute mixed layer depth TODO: Move somewhere else ...
if (self%has("mld") .and. self%has("layer_depth")) then
call self%get("tocn", field)
call self%get("socn", field2)
call self%get("mld", mld)
if (self%has("ocean_mixed_layer_thickness") .and. self%has("sea_water_depth")) then
call self%get("sea_water_potential_temperature", field)
call self%get("sea_water_salinity", field2)
call self%get("ocean_mixed_layer_thickness", mld)
mld%val = 0.0
do i = isc, iec
do j = jsc, jec
Expand Down
2 changes: 1 addition & 1 deletion src/soca/Geometry/soca_geom.interface.F90
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ subroutine soca_geo_get_num_levels_c(c_key_self, c_vars, c_levels_size, c_levels
case ("1")
c_levels(i) = 1
case ("full_ocn")
if (field_name == field%getval_name_surface) then
if (field_name == field%name_surface) then
c_levels(i) = 1
else
c_levels(i) = self%nzo
Expand Down
20 changes: 10 additions & 10 deletions src/soca/Increment/soca_increment_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ subroutine soca_increment_random(self)
field => self%fields(i)
! TODO remove this once increment / state are fully separated
! NOTE: can't randomize "hocn", testIncrementInterpAD fails
if (field%name == 'hocn') cycle
if (field%name == "sea_water_cell_thickness") cycle
call normal_distribution(field%val, 0.0_kind_real, 1.0_kind_real, rseed)
end do

Expand Down Expand Up @@ -149,23 +149,23 @@ subroutine soca_increment_dirac(self, f_conf)
field => null()
select case(ifdir(n))
case (1)
call self%get("tocn", field)
call self%get("sea_water_potential_temperature", field)
case (2)
call self%get("socn", field)
call self%get("sea_water_salinity", field)
case (3)
call self%get("ssh", field)
call self%get("sea_surface_height_above_geoid", field)
case (4)
call self%get("cicen", field)
call self%get("sea_ice_category_area_fraction", field)
case (5)
call self%get("hicen", field)
call self%get("sea_ice_category_thickness", field)
case (6)
call self%get("chl", field)
call self%get("mass_concentration_of_chlorophyll_in_sea_water", field)
case (7)
call self%get("biop", field)
call self%get("molar_concentration_of_biomass_in_sea_water_in_p_units", field)
case (8)
call self%get("uocn", field)
call self%get("eastward_sea_water_velocity", field)
case (9)
call self%get("vocn", field)
call self%get("northward_sea_water_velocity", field)
case default
! TODO print error that out of range
end select
Expand Down
54 changes: 27 additions & 27 deletions src/soca/LinearVariableChange/Balance/soca_balance_mod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ subroutine soca_balance_setup(self, f_conf, traj, geom)
jsd=geom%jsd; jed=geom%jed

! Get required fields
call traj%get("tocn", tocn)
call traj%get("socn", socn)
call traj%get("hocn", hocn)
call traj%get("mld", mld)
call traj%get("layer_depth", layer_depth)
if (traj%has("cicen")) call traj%get("cicen", cicen)
call traj%get("sea_water_potential_temperature", tocn)
call traj%get("sea_water_salinity", socn)
call traj%get("sea_water_cell_thickness", hocn)
call traj%get("ocean_mixed_layer_thickness", mld)
call traj%get("sea_water_depth", layer_depth)
if (traj%has("sea_ice_category_area_fraction")) call traj%get("sea_ice_category_area_fraction", cicen)

! allocate space
nl = hocn%nz
Expand Down Expand Up @@ -179,7 +179,7 @@ subroutine soca_balance_setup(self, f_conf, traj, geom)
deallocate(jac)

! Compute Kct
if (traj%has("cicen")) then
if (traj%has("sea_ice_category_area_fraction")) then
! Setup dc/dT
allocate(kct(isd:ied,jsd:jed))
kct = 0.0_kind_real
Expand Down Expand Up @@ -240,8 +240,8 @@ subroutine soca_balance_mult(self, dxa, dxm)
!> K= [ Ketat Ketas I 0 ]
!> [ Kct 0 0 I ]

call dxa%get("tocn",tocn_a)
call dxa%get("socn",socn_a)
call dxa%get("sea_water_potential_temperature",tocn_a)
call dxa%get("sea_water_salinity",socn_a)

do n=1, size(dxm%fields)
fld_m => dxm%fields(n)
Expand All @@ -253,19 +253,19 @@ subroutine soca_balance_mult(self, dxa, dxm)
case default
fld_m%val(i,j,:) = fld_a%val(i,j,:)

case("socn") ! Salinity
case("sea_water_salinity") ! Salinity
fld_m%val(i,j,:) = fld_a%val(i,j,:) + &
& self%kst%jacobian(i,j,:) * tocn_a%val(i,j,:)

case ("ssh") ! SSH
case ("sea_surface_height_above_geoid") ! SSH
fld_m%val(i,j,:) = fld_a%val(i,j,:)
do k = 1, tocn_a%nz
fld_m%val(i,j,:) = fld_m%val(i,j,:) + &
& self%ksshts%kssht(i,j,k) * tocn_a%val(i,j,k) + &
& self%ksshts%ksshs(i,j,k) * socn_a%val(i,j,k)
end do

case ("cicen") ! Ice fraction
case ("sea_ice_category_area_fraction") ! Ice fraction
do k = 1, fld_m%nz
fld_m%val(i,j,k) = fld_a%val(i,j,k) + &
& self%kct(i,j) * tocn_a%val(i,j,1)
Expand Down Expand Up @@ -293,9 +293,9 @@ subroutine soca_balance_multad(self, dxa, dxm)

cicen_m => null()

call dxm%get("socn", socn_m)
call dxm%get("ssh", ssh_m)
if (dxm%has("cicen")) call dxm%get("cicen",cicen_m)
call dxm%get("sea_water_salinity", socn_m)
call dxm%get("sea_surface_height_above_geoid", ssh_m)
if (dxm%has("sea_ice_category_area_fraction")) call dxm%get("sea_ice_category_area_fraction",cicen_m)

do n = 1, size(dxa%fields)
fld_a => dxa%fields(n)
Expand All @@ -307,7 +307,7 @@ subroutine soca_balance_multad(self, dxa, dxm)
case default
fld_a%val(i,j,:) = fld_m%val(i,j,:)

case ("tocn") ! Temperature
case ("sea_water_potential_temperature") ! Temperature
fld_a%val(i,j,:) = fld_m%val(i,j,:) + &
& self%kst%jacobian(i,j,:) * socn_m%val(i,j,:) + &
& self%ksshts%kssht(i,j,:) * ssh_m%val(i,j,1)
Expand All @@ -317,7 +317,7 @@ subroutine soca_balance_multad(self, dxa, dxm)
& self%kct(i,j) * sum(cicen_m%val(i,j,:))
end if

case ("socn") ! Salinity
case ("sea_water_salinity") ! Salinity
fld_a%val(i,j,:) = fld_m%val(i,j,:) + &
& self%ksshts%ksshs(i,j,:) * ssh_m%val(i,j, 1)

Expand All @@ -341,8 +341,8 @@ subroutine soca_balance_multinv(self, dxa, dxm)
type(soca_field), pointer :: fld_m, fld_a
type(soca_field), pointer :: tocn_m, socn_m

call dxm%get("tocn", tocn_m)
call dxm%get("socn", socn_m)
call dxm%get("sea_water_potential_temperature", tocn_m)
call dxm%get("sea_water_salinity", socn_m)

do n = 1, size(dxa%fields)
fld_a => dxa%fields(n)
Expand All @@ -354,11 +354,11 @@ subroutine soca_balance_multinv(self, dxa, dxm)
case default
fld_a%val(i,j,:) = fld_m%val(i,j,:)

case ('socn') ! Salinity
case ('sea_water_salinity') ! Salinity
fld_a%val(i,j,:) = fld_m%val(i,j,:) - &
& self%kst%jacobian(i,j,:) * tocn_m%val(i,j,:)

case ('ssh') ! SSH
case ('sea_surface_height_above_geoid') ! SSH
fld_a%val(i,j, :) = fld_m%val(i,j, :)
do k = 1, tocn_m%nz
fld_a%val(i,j,:) = fld_a%val(i,j,:) + &
Expand All @@ -367,7 +367,7 @@ subroutine soca_balance_multinv(self, dxa, dxm)
& self%ksshts%ksshs(i,j,k) * socn_m%val(i,j,k)
end do

case ('cicen') ! Ice fraction
case ('sea_ice_category_area_fraction') ! Ice fraction
fld_a%val(i,j,:) = fld_m%val(i,j,:)
do k = 1, fld_m%nz
fld_a%val(i,j,k) = fld_a%val(i,j,k) - &
Expand Down Expand Up @@ -396,9 +396,9 @@ subroutine soca_balance_multinvad(self, dxa, dxm)

cicen_a => null()

call dxa%get("socn", socn_a)
call dxa%get("ssh", ssh_a)
if (dxa%has("cicen")) call dxa%get("cicen",cicen_a)
call dxa%get("sea_water_salinity", socn_a)
call dxa%get("sea_surface_height_above_geoid", ssh_a)
if (dxa%has("sea_ice_category_area_fraction")) call dxa%get("sea_ice_category_area_fraction",cicen_a)

do n = 1, size(dxm%fields)
fld_m => dxm%fields(n)
Expand All @@ -410,7 +410,7 @@ subroutine soca_balance_multinvad(self, dxa, dxm)
case default
fld_m%val(i,j,:) = fld_a%val(i,j,:)

case ('tocn') ! Temperature
case ('sea_water_potential_temperature') ! Temperature
fld_m%val(i,j,:) = fld_a%val(i,j,:) &
& - self%kst%jacobian(i,j,:) * socn_a%val(i,j,:) &
& + ( self%ksshts%ksshs(i,j,:) * self%kst%jacobian(i,j,:) &
Expand All @@ -421,7 +421,7 @@ subroutine soca_balance_multinvad(self, dxa, dxm)
& - self%kct(i,j) * sum(cicen_a%val(i,j,:))
end if

case ('socn') ! Salinity
case ('sea_water_salinity') ! Salinity
fld_m%val(i,j,:) = fld_a%val(i,j,:) - &
& self%ksshts%ksshs(i,j,:) * ssh_a%val(i,j,1)

Expand Down
Loading

0 comments on commit 8a721c0

Please sign in to comment.