Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hamocc hybrid coord2 #179

Merged
merged 10 commits into from
Oct 3, 2022

Conversation

TomasTorsvik
Copy link
Contributor

For hybrid cooridinates, define depth of surface mixed layer in HAMOCC by the ocean boundary layer (OBL) variable provided by CVmix. Default value kml(i,j) = 2 used for isopycnic variables for consistency with the bulk mixed layer formulation.

@TomasTorsvik TomasTorsvik self-assigned this Jul 19, 2022
@TomasTorsvik TomasTorsvik added the iHAMOCC Issue mainly concerns the iHAMOCC code base label Jul 19, 2022
phy/mod_difest.F Outdated
@@ -1161,7 +1162,7 @@ subroutine difest_vertical_hyb(m,n,mm,nn,k1m,k1n)
. cellHeight,OBLdepth(i,j))

! gets index of the level and interface above hbl
kOBL = CVMix_kpp_compute_kOBL_depth(iFaceHeight,
kOBL(i,j) = CVMix_kpp_compute_kOBL_depth(iFaceHeight,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a bit uncertain, but CVMix_kpp_compute_kopb_depth() i) seem to return a real value and ii) depending on which index one wants, it potentially requires to subtract 1 (not sure about the vertical grid layout in BLOM) iii) why calculating it again - and not using hOBL? - from CVMix:

! !DESCRIPTION:
!  Computes the index of the level and interface above OBL\_depth. The index is
!  stored as a real number, and the integer index can be solved for in the
!  following way:\\
!    \verb|kt| = index of cell center above OBL\_depth = \verb|nint(kOBL_depth)-1|
!    \verb|kw| = index of interface above OBL\_depth = \verb|floor(kOBL_depth)|

In any case, to be clean, I guess it would be good to explicitly convert from real to integer for the k-index. This applies again below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jmaerz !

@matsbn @milicak I would like to hear from you about this issue.

I did not look into the CVMix routine itself when I made these code changes, but I agree that this looks suspicious. For iHAMOCC we probably want the index of the cell center above OBL_depth, not the index of the interface.

hOBL is computed twice, first by the subroutine CVMix_kpp_compute_OBL_depth and later by function CVMix_kpp_compute_kOBL_depth. The function CVMix_kpp_compute_kOBL_depth is used internally in CVMix_kpp_compute_OBL_depth, so there should be no need to do this again. Then kOBL is computed (twice) by the function CVMix_kpp_compute_kOBL_depth.

kOBL is used in the calculation of buoyancy flux acting on the OBL, so in this case the index may need to reference the interface. If so, we may want to define a new index OBL_cell_center = nint(hOBL) - 1 for use in iHAMOCC.

@TomasTorsvik TomasTorsvik mentioned this pull request Aug 19, 2022
@TomasTorsvik TomasTorsvik marked this pull request as draft August 26, 2022 06:19
@TomasTorsvik
Copy link
Contributor Author

Will update this PR depending on feedback for PR #182

@jmaerz
Copy link
Collaborator

jmaerz commented Aug 26, 2022

Thanks for keeping that going!

Copy link
Contributor

@JorgSchwinger JorgSchwinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't dived into the kOBL-issue, but from the HAMOCC side this looks fine to me.

hamocc/cyano.F90 Show resolved Hide resolved
@TomasTorsvik
Copy link
Contributor Author

Hi,

I have revived this PR after changing the dependency between BLOM and iHAMOCC, so now I'm porting the real value surface mixed layer depth hOBL, corresponding to the fractional depth in the index space, instead of the integer index value kOBL.

@matsbn , @milicak
There is only a minor change in mod_difest.F where I have moved the hOBL variable initiation from the difest_vertical_hyb to the main module initiation section, and made it public so that it is accessible to iHAMOCC. This should not change anything substantial in the physics part.

@jmaerz , @JorgSchwinger
The iHAMOCC implementation is mostly as before, only that now the kmle variable is defined from hOBL instead of kOBL. I had a problem with the default value spval = 1.e33, which doesn't fit a regular integer type, hence I included a test to exclude hOBL instances with this value before attempting to do nint(hOBL), and I set kmle to the default value 2 if this test fails. I'm not sure this is the best solution to this problem, please let me know if you have suggestions how to improve this.

@matsbn
Copy link
Contributor

matsbn commented Sep 28, 2022

In routine inivar_difest, you could initialise hOBL(:,:) with the following code block at the end of the routine:

c$OMP PARALLEL DO PRIVATE(l,i)
      do j=1,jj
        do l=1,isp(j)
        do i=max(1,ifp(j,l)),min(ii,ilp(j,l))
          hOBL(i,j)=3.
        enddo
        enddo
      enddo
c$OMP END PARALLEL DO

This should give kmle = 2 always at ocean grid cells, except when vcoord_type_tag == cntiso_hybrid. Maybe then you do not have to access the mod_vcoord variables in iHAMOCC for now.

@jmaerz
Copy link
Collaborator

jmaerz commented Sep 29, 2022

Hi @TomasTorsvik , just to understand the problem with the spval value: do I see it right that the moment, the whole water column is mixed, you experience the problem that hOBL is still equal to spval? - or when does the problem happen? Is spval needed for initialization for hOBL or could you also use e.g. 9999 as initialization (expecting to never reach more than 9998 layers in BLOM in the future). In any case, we don't want to end up with kmle > number of layers.

As minor thing: are the line breaks (the re-formatting) in mo_apply_rivin needed?

Apart from that the changes look fine to me.

@TomasTorsvik
Copy link
Contributor Author

As minor thing: are the line breaks (the re-formatting) in mo_apply_rivin needed?

No, I changed it back to the the original form.

@TomasTorsvik
Copy link
Contributor Author

Hi @TomasTorsvik , just to understand the problem with the spval value: do I see it right that the moment, the whole water column is mixed, you experience the problem that hOBL is still equal to spval? - or when does the problem happen? Is spval needed for initialization for hOBL or could you also use e.g. 9999 as initialization (expecting to never reach more than 9998 layers in BLOM in the future). In any case, we don't want to end up with kmle > number of layers.

Hi @jmaerz ,
the update of OBLdepth and hOBL in mod_difest.F is only done for "wet" cells, so the spaval value remained for land cells. If I had done the looping differently, i.e.

   do j=1,jj
      do l=1,isp(j)
         do i=max(1,ifp(j,l)),min(ii,ilp(j,l))
            kmle(i,j) = nint(hOBL(i,j))-1
         enddo
      enddo
   enddo

the loop should not encounter any spval values. However, if for some reason an spval value was encountered, there is the potential for having kmle > number of layers, as you say.

I have changed the initiation for hOBL so that it gets a default value of 3. (defined by hOBL_static), so that kmle gets a default value of 2. In this way we don't need to introduce an explicit dependence on vcoord_type_tag in iHAMOCC, at least for now.

@jmaerz
Copy link
Collaborator

jmaerz commented Sep 29, 2022

Ok, I see, so it was more of a theoretical problem and you haven't encountered it really. Good to know about it and thanks for the information! From my side, you've my approval to merge.

Copy link
Collaborator

@jmaerz jmaerz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved.

Copy link
Contributor

@matsbn matsbn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be OK now. I would prefer that hOBL is first set to spval everywhere, also including the halo, then initialised to hOBL_static only for wet points. The purpose of first initialising to a very large value, spval, is that the code would typically crash if using the variable where one shouldn't (e.g at land points). This can be corrected later.

@TomasTorsvik
Copy link
Contributor Author

TomasTorsvik commented Oct 3, 2022

It should be OK now. I would prefer that hOBL is first set to spval everywhere, also including the halo, then initialised to hOBL_static only for wet points. The purpose of first initialising to a very large value, spval, is that the code would typically crash if using the variable where one shouldn't (e.g at land points). This can be corrected later.

Thanks @matsbn , I see that iHAMOCC is referencing the wet points indexing at some places, but I'm not sure if this is done consistently. I therefore prefer to merge this version of the PR, and make a separate issue on the use of wet points indexing in iHAMOCC.

@TomasTorsvik TomasTorsvik merged commit 2a80c23 into NorESMhub:master Oct 3, 2022
@TomasTorsvik TomasTorsvik deleted the hamocc-hybrid_coord2 branch October 3, 2022 11:41
TomasTorsvik added a commit to TomasTorsvik/BLOM-TTfork that referenced this pull request Dec 5, 2022
Make the surface mixed layer depth fractional index `hOBL` available for use in iHAMOCC, and adjust the internal iHAMOCC index `kmle` according to `hOBL`. Default value `kmle = 2` is retained for consistency with isopycnic coordinates.
TomasTorsvik added a commit to TomasTorsvik/BLOM-TTfork that referenced this pull request Dec 5, 2022
Make the surface mixed layer depth fractional index `hOBL` available for use in iHAMOCC, and adjust the internal iHAMOCC index `kmle` according to `hOBL`. Default value `kmle = 2` is retained for consistency with isopycnic coordinates.
jmaerz added a commit that referenced this pull request Jan 25, 2023
* Dynamic mapping of pore water tracers to ocean tracers (#192)

* Initial restructuring of sediment-related tracer declaration and initialization

* Introducing mapping function

* Remove unncessary comments

* Fixed diagnostics bug and updated index naming

* Added initial support for NUOPC driver.

* Lon-lat variable sediment porosity (#189)

Introducing a static 3D sediment porosity field that can be optionally read in with effects on molecular pore water diffusion and shifting.

* Added wave forcing fields.

* Renamed folder for MCT driver.

* Moved MCT specific file from drivers/cpl_share/ to drivers/mct/.

* Rename drivers/mct/mod_swtfrz.F to drivers/mct/mod_swtfrz.F90.

* Rewrite to drivers/mct/mod_swtfrz.F90 to free format Fortran.

* Remove redundant definition of kOBL.

* Redefine kOBL, cast as integer

* Fixing variable sediment porosity - field initialization in case of `sedbypass=true` (#198)

* Removing bodensed -  Initialization of sediment parameters and fields now in mo_sedmnt

* Hamocc hybrid coord2 (#179)

Make the surface mixed layer depth fractional index `hOBL` available for use in iHAMOCC, and adjust the internal iHAMOCC index `kmle` according to `hOBL`. Default value `kmle = 2` is retained for consistency with isopycnic coordinates.

* Fix porosity read (#201)

* Fixing the reading of variable porosity input field in preparation for the NorESM 2.0.6 release

Cherry-picked from private Ncycleprivate branch 0d56930e2fdd62caba964d375b57304942568926

* Provide number of layers (3rd dim) via ks and not hard-coded

* minor clean-up

* Correct unit of diagnostic variable dp_trc.

* Made conservation and checksum diagnostics selectable by namelist options (default off).

* pCO2, Piston velocity and solubility output (#202)

* add pCO2m (moist), CO2 piston velocity and solubility output - caution: kwco2 piston velocity now really holds only piston velocity (and not times solubility)

* Bugfix pnetcdf (#208)

* Add variables used by PNETCDF to explicit use staements.

* Move implicit none statments

* update explicit use statement for pnetcdf

* fixed units and renamed calcium burial to CaCO3 burial (#212)

Fixed sediment clay units.

* Add option for surface pH output (#221)

* Remove unused parameters in wrt* subroutine calls in ncout_hamocc.F90

* Import get_bgc_namelist only in subroutine where it is needed. (#225)

Co-authored-by: Mats Bentsen <mben@norceresearch.no>
Co-authored-by: Tomas Torsvik <tomas.torsvik.work@gmail.com>
Co-authored-by: Tomas Torsvik <43031053+TomasTorsvik@users.noreply.github.com>
Co-authored-by: Jörg Schwinger <jorg.schwinger@norceresearch.no>
jmaerz added a commit that referenced this pull request Feb 9, 2023
* Dynamic mapping of pore water tracers to ocean tracers (#192)

* Initial restructuring of sediment-related tracer declaration and initialization

* Introducing mapping function

* Remove unncessary comments

* Fixed diagnostics bug and updated index naming

* Added initial support for NUOPC driver.

* Lon-lat variable sediment porosity (#189)

Introducing a static 3D sediment porosity field that can be optionally read in with effects on molecular pore water diffusion and shifting.

* Added wave forcing fields.

* Renamed folder for MCT driver.

* Moved MCT specific file from drivers/cpl_share/ to drivers/mct/.

* Rename drivers/mct/mod_swtfrz.F to drivers/mct/mod_swtfrz.F90.

* Rewrite to drivers/mct/mod_swtfrz.F90 to free format Fortran.

* Remove redundant definition of kOBL.

* Redefine kOBL, cast as integer

* Fixing variable sediment porosity - field initialization in case of `sedbypass=true` (#198)

* Removing bodensed -  Initialization of sediment parameters and fields now in mo_sedmnt

* This is the first commit of MKS units. All variables in the subroutines have been converted to MKS [meter, kg, seconds] instead of CGS [cm, gram, seconds] with necessary coefficients. The default option which is CGS reproduce old results. The new option MKS cannot reproduce because of machine precision.

* Hamocc hybrid coord2 (#179)

Make the surface mixed layer depth fractional index `hOBL` available for use in iHAMOCC, and adjust the internal iHAMOCC index `kmle` according to `hOBL`. Default value `kmle = 2` is retained for consistency with isopycnic coordinates.

* BLOM CIME cpp updates to run in NorESM

* bug fixes for the CGS MKS conversion

* cesm thermal forcing bug fixes for reproducibility

* BLOM MKS update to export winds into the CESM using proper units.

* input values in ocn_in case is updated for mks setup

* default cgsmks value changed

* Initialize some variables in the k-epsilon model.

* Fix porosity read (#201)

* Fixing the reading of variable porosity input field in preparation for the NorESM 2.0.6 release

Cherry-picked from private Ncycleprivate branch 0d56930e2fdd62caba964d375b57304942568926

* Provide number of layers (3rd dim) via ks and not hard-coded

* minor clean-up

* Correct unit of diagnostic variable dp_trc.

* Made conservation and checksum diagnostics selectable by namelist options (default off).

* pCO2, Piston velocity and solubility output (#202)

* add pCO2m (moist), CO2 piston velocity and solubility output - caution: kwco2 piston velocity now really holds only piston velocity (and not times solubility)

* Bugfix pnetcdf (#208)

* Add variables used by PNETCDF to explicit use staements.

* Move implicit none statments

* update explicit use statement for pnetcdf

* fixed units and renamed calcium burial to CaCO3 burial (#212)

Fixed sediment clay units.

* - Made the "fuk95" configuration work with MKS units.
- Removed "CGS" CPP flag.
- Changed some unit conversion factors from variables to parameters.
- Introduced rho0 (= 1/alpha0) parameter.
- Updated copyright statements.

* Correct unit conversion of mixed layer depth to pressure.

* Updated NorESM coupling scripts for the use of MKS units.

* Fixed check of unit system when building as NorESM component.

* Add option for surface pH output (#221)

* Remove unused parameters in wrt* subroutine calls in ncout_hamocc.F90

* Import get_bgc_namelist only in subroutine where it is needed. (#225)

* fix missing ' (#228)

Fixing a missing ' that only showed up when using `cisonew`

---------

Co-authored-by: Mats Bentsen <mben@norceresearch.no>
Co-authored-by: Tomas Torsvik <tomas.torsvik.work@gmail.com>
Co-authored-by: Mehmet Ilicak <milicak@itu.edu.tr>
Co-authored-by: Tomas Torsvik <43031053+TomasTorsvik@users.noreply.github.com>
Co-authored-by: Jörg Schwinger <jorg.schwinger@norceresearch.no>
jmaerz pushed a commit to jmaerz/BLOM that referenced this pull request Aug 9, 2023
Make the surface mixed layer depth fractional index `hOBL` available for use in iHAMOCC, and adjust the internal iHAMOCC index `kmle` according to `hOBL`. Default value `kmle = 2` is retained for consistency with isopycnic coordinates.
jmaerz pushed a commit to jmaerz/BLOM that referenced this pull request Aug 9, 2023
Make the surface mixed layer depth fractional index `hOBL` available for use in iHAMOCC, and adjust the internal iHAMOCC index `kmle` according to `hOBL`. Default value `kmle = 2` is retained for consistency with isopycnic coordinates.
jmaerz added a commit to jmaerz/BLOM that referenced this pull request Aug 9, 2023
* Dynamic mapping of pore water tracers to ocean tracers (NorESMhub#192)

* Initial restructuring of sediment-related tracer declaration and initialization

* Introducing mapping function

* Remove unncessary comments

* Fixed diagnostics bug and updated index naming

* Added initial support for NUOPC driver.

* Lon-lat variable sediment porosity (NorESMhub#189)

Introducing a static 3D sediment porosity field that can be optionally read in with effects on molecular pore water diffusion and shifting.

* Added wave forcing fields.

* Renamed folder for MCT driver.

* Moved MCT specific file from drivers/cpl_share/ to drivers/mct/.

* Rename drivers/mct/mod_swtfrz.F to drivers/mct/mod_swtfrz.F90.

* Rewrite to drivers/mct/mod_swtfrz.F90 to free format Fortran.

* Remove redundant definition of kOBL.

* Redefine kOBL, cast as integer

* Fixing variable sediment porosity - field initialization in case of `sedbypass=true` (NorESMhub#198)

* Removing bodensed -  Initialization of sediment parameters and fields now in mo_sedmnt

* Hamocc hybrid coord2 (NorESMhub#179)

Make the surface mixed layer depth fractional index `hOBL` available for use in iHAMOCC, and adjust the internal iHAMOCC index `kmle` according to `hOBL`. Default value `kmle = 2` is retained for consistency with isopycnic coordinates.

* Fix porosity read (NorESMhub#201)

* Fixing the reading of variable porosity input field in preparation for the NorESM 2.0.6 release

Cherry-picked from private Ncycleprivate branch 0d56930e2fdd62caba964d375b57304942568926

* Provide number of layers (3rd dim) via ks and not hard-coded

* minor clean-up

* Correct unit of diagnostic variable dp_trc.

* Made conservation and checksum diagnostics selectable by namelist options (default off).

* pCO2, Piston velocity and solubility output (NorESMhub#202)

* add pCO2m (moist), CO2 piston velocity and solubility output - caution: kwco2 piston velocity now really holds only piston velocity (and not times solubility)

* Bugfix pnetcdf (NorESMhub#208)

* Add variables used by PNETCDF to explicit use staements.

* Move implicit none statments

* update explicit use statement for pnetcdf

* fixed units and renamed calcium burial to CaCO3 burial (NorESMhub#212)

Fixed sediment clay units.

* Add option for surface pH output (NorESMhub#221)

* Remove unused parameters in wrt* subroutine calls in ncout_hamocc.F90

* Import get_bgc_namelist only in subroutine where it is needed. (NorESMhub#225)

Co-authored-by: Mats Bentsen <mben@norceresearch.no>
Co-authored-by: Tomas Torsvik <tomas.torsvik.work@gmail.com>
Co-authored-by: Tomas Torsvik <43031053+TomasTorsvik@users.noreply.github.com>
Co-authored-by: Jörg Schwinger <jorg.schwinger@norceresearch.no>
jmaerz added a commit to jmaerz/BLOM that referenced this pull request Aug 9, 2023
…b#232)

* Dynamic mapping of pore water tracers to ocean tracers (NorESMhub#192)

* Initial restructuring of sediment-related tracer declaration and initialization

* Introducing mapping function

* Remove unncessary comments

* Fixed diagnostics bug and updated index naming

* Added initial support for NUOPC driver.

* Lon-lat variable sediment porosity (NorESMhub#189)

Introducing a static 3D sediment porosity field that can be optionally read in with effects on molecular pore water diffusion and shifting.

* Added wave forcing fields.

* Renamed folder for MCT driver.

* Moved MCT specific file from drivers/cpl_share/ to drivers/mct/.

* Rename drivers/mct/mod_swtfrz.F to drivers/mct/mod_swtfrz.F90.

* Rewrite to drivers/mct/mod_swtfrz.F90 to free format Fortran.

* Remove redundant definition of kOBL.

* Redefine kOBL, cast as integer

* Fixing variable sediment porosity - field initialization in case of `sedbypass=true` (NorESMhub#198)

* Removing bodensed -  Initialization of sediment parameters and fields now in mo_sedmnt

* This is the first commit of MKS units. All variables in the subroutines have been converted to MKS [meter, kg, seconds] instead of CGS [cm, gram, seconds] with necessary coefficients. The default option which is CGS reproduce old results. The new option MKS cannot reproduce because of machine precision.

* Hamocc hybrid coord2 (NorESMhub#179)

Make the surface mixed layer depth fractional index `hOBL` available for use in iHAMOCC, and adjust the internal iHAMOCC index `kmle` according to `hOBL`. Default value `kmle = 2` is retained for consistency with isopycnic coordinates.

* BLOM CIME cpp updates to run in NorESM

* bug fixes for the CGS MKS conversion

* cesm thermal forcing bug fixes for reproducibility

* BLOM MKS update to export winds into the CESM using proper units.

* input values in ocn_in case is updated for mks setup

* default cgsmks value changed

* Initialize some variables in the k-epsilon model.

* Fix porosity read (NorESMhub#201)

* Fixing the reading of variable porosity input field in preparation for the NorESM 2.0.6 release

Cherry-picked from private Ncycleprivate branch 0d56930e2fdd62caba964d375b57304942568926

* Provide number of layers (3rd dim) via ks and not hard-coded

* minor clean-up

* Correct unit of diagnostic variable dp_trc.

* Made conservation and checksum diagnostics selectable by namelist options (default off).

* pCO2, Piston velocity and solubility output (NorESMhub#202)

* add pCO2m (moist), CO2 piston velocity and solubility output - caution: kwco2 piston velocity now really holds only piston velocity (and not times solubility)

* Bugfix pnetcdf (NorESMhub#208)

* Add variables used by PNETCDF to explicit use staements.

* Move implicit none statments

* update explicit use statement for pnetcdf

* fixed units and renamed calcium burial to CaCO3 burial (NorESMhub#212)

Fixed sediment clay units.

* - Made the "fuk95" configuration work with MKS units.
- Removed "CGS" CPP flag.
- Changed some unit conversion factors from variables to parameters.
- Introduced rho0 (= 1/alpha0) parameter.
- Updated copyright statements.

* Correct unit conversion of mixed layer depth to pressure.

* Updated NorESM coupling scripts for the use of MKS units.

* Fixed check of unit system when building as NorESM component.

* Add option for surface pH output (NorESMhub#221)

* Remove unused parameters in wrt* subroutine calls in ncout_hamocc.F90

* Import get_bgc_namelist only in subroutine where it is needed. (NorESMhub#225)

* fix missing ' (NorESMhub#228)

Fixing a missing ' that only showed up when using `cisonew`

---------

Co-authored-by: Mats Bentsen <mben@norceresearch.no>
Co-authored-by: Tomas Torsvik <tomas.torsvik.work@gmail.com>
Co-authored-by: Mehmet Ilicak <milicak@itu.edu.tr>
Co-authored-by: Tomas Torsvik <43031053+TomasTorsvik@users.noreply.github.com>
Co-authored-by: Jörg Schwinger <jorg.schwinger@norceresearch.no>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iHAMOCC Issue mainly concerns the iHAMOCC code base
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants