Skip to content

Fesom2.6 recom tra diags and CI test#802

Open
ogurses wants to merge 68 commits intomainfrom
fesom2.6_recom_tra_diags
Open

Fesom2.6 recom tra diags and CI test#802
ogurses wants to merge 68 commits intomainfrom
fesom2.6_recom_tra_diags

Conversation

@ogurses
Copy link
Collaborator

@ogurses ogurses commented Oct 29, 2025

No description provided.

ogurses and others added 17 commits October 15, 2024 15:08
Define new variables to track tracer changes
due to advection and diffusion.

We want to save for now diffusion and advection
contribution to the tracer changes. Horizontal and
vertical diffusion includes Redi
parametrization (if it is set .true.).
Fill __ciso directive to ensure that
carbon isotope code works. Medusa interface is
added.
Use __coccos in src/CMakeLists.txt to
include 2 more phytoplankton classes

FESOM2.6-REcoM setup with 4 phytoplankton,
3 zooplankton and 2 detritus functional types.

BREAKING CHANGE: FESOM2.6-REcoM setup with 4p3z2d
Correct temperature function for small phytoplankton and diatoms.

Previous update for the fouth phytoplankton class and
new temperature functions for small phytoplankton and diatoms
resulted in very low Phaeocystis biomass.
We recognised that this is related to missing code lines in the
temperature function which we correct with this update.
…ostics

Use namelist.io to activate diagnostics.

Sinking velocity of particle (fast and slow) are calculated but not written into a file before.
We fix the  missing diagnostics for sinking velocity of detritus classes. Besides we
Extracted the K0, solubility  which is computed
in gasx.F90.
We add __coccos directive to get the correct temperature
function in silicate assimilation.

In the coccos and Phaeocystis version, it should be dependent on the new temperature function, Temp_diatoms.
Use the original Arrhenius function in simpler phytoplankton version. Besides, light limitation diagnostics is corrected.
It does affect only the diatoms related output.
Correct reported salt flux bug in oce_ale_tracer.F90.
#721
We commented out the linear model where degradation is directly
proportional to light intensity and the chlorophyll degradation
rate is capped at a maximum of 0.3. Reason for this is the unrealistic
air2sea co2 fluxes in the 2p3z2d setup.
The reactivated saturation model is more realistic. It accounts for light
saturation effects.
At low light, degradation increases roughly linearly with PAR
At high light, the degradation rate approaches an asymptotic maximum
…tives with namelist parameters

Replace preprocessor directives with namelist parameters:
* `__3Zoo2Det` → `enable_3zoo2det`
* `__coccos` → `enable_coccos`

* Enhanced inline comments with ecological significance and biological context
*Complete variable/parameter documentation with units and descriptions
* Clear sectioning with visual separators and variable definitions
* Equation explanations showing mathematical relationships and biological processes
* Logic documentation for decision trees and conditional blocks
* Comments now explain "why" not just "what"

**Sequence Validation**
* Generates expected tracer ID list based on configuration
* Shows exact ID order and position-by-position comparison

**Configuration-Specific Clash Detection**
* Full Model (both flags): Don't use IDs 1023-1024
* Coccos-only: Use 1023-1028 (NOT 1029-1034)
* 3Zoo2Det-only: Use 1029-1030 for microzoo (NOT 1035-1036)

**Validation Checks**
* Exact sequence matching against expected IDs
* Duplicate ID detection
*Forbidden ID detection per configuration

BREAKING CHANGE: replace  directives with namelist parameter for model configuration
@JanStreffing JanStreffing added this to the FESOM 2.7 milestone Oct 29, 2025
@JanStreffing JanStreffing changed the title Fesom2.6 recom tra diags Fesom2.6 recom tra diags and CI test Oct 29, 2025
@JanStreffing JanStreffing linked an issue Oct 29, 2025 that may be closed by this pull request
@ogurses ogurses requested a review from suvarchal October 29, 2025 14:34
@ogurses
Copy link
Collaborator Author

ogurses commented Oct 29, 2025

CI test for recom is on the way. Any help is welcome @suvarchal

@JanStreffing
Copy link
Collaborator

! O:G
! Save horizontal and vertical advective fluxes.
! We have the values on the nodes
! We do not know how much each edge contributes
! to the nodes it connects
! Notes from Patrick: del_ttf includes
! Low-order solution. But, del_ttf_advhoriz and
! del_ttf_advvert contain antidiffusive fluxes 
! from the FCT scheme

!if (.FALSE.) then
! O:G - tra_diag
!#if defined (__recom)
!        if (tracers%data(tr_num)%ltra_diag) then
!           do n=1, myDim_nod2D+eDim_nod2D
!              nu1 = ulevels_nod2D(n)
!              nl1 = nlevels_nod2D(n)
!              do nz = nu1, nl1-1
                 ! Horizontal advection part
!                 tracers%work%tra_advhoriz(nz,n,tr_num) = tracers%work%del_ttf_advhoriz(nz,n)
                 ! Vertical advection part
!                 tracers%work%tra_advvert (nz,n,tr_num) = tracers%work%del_ttf_advvert(nz,n)
!              end do
!           end do
!        end if
!#endif
!endif 

Still needed @ogurses?

!#if defined (__recom) ! not necessarily should belong to recom case
! tracers%work%tra_advhoriz = 0.0 ! O:G - tra_diag
! tracers%work%tra_advvert = 0.0
ttf_rhs_bak = 0.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Has no impact on CI test, so probably ok. Just flagging to be checked by @patrickscholz

@suvarchal
Copy link
Collaborator

CI test for recom is on the way. Any help is welcome @suvarchal

last-minute working on compute time reporting and proposal, can take a look tomorrow

Problem: Fortran NetCDF library and CDO/NCO tools use different
fill value conventions, causing NaN values in tracer initialization.

Solution: Make fill value detection more robust:
1. Try _FillValue attribute (Fortran NetCDF standard)
2. Fall back to missing_value attribute (used by CDO/NCO)
3. Use NetCDF default fill value (9.969e+36) if neither exists
4. Broadcast fill value to all MPI ranks

This fixes the 'REcoM_DIC: NaN' error during initialization by
properly handling land/missing values in input NetCDF files
created with different tools.

Fixes issue reported by colleague about incompatible fill value
conventions between different NetCDF tools.
Added diagnostic output to track where DIC becomes NaN:
- Check state(idic) and sms(idic) before DIC calculation
- Check DIC after calculation
- Print node, depth, lon/lat location when NaN detected
- Stop execution immediately to get clean traceback

This will help identify whether:
1. The state already contains NaN (initialization issue)
2. The SMS contains NaN (biogeochemistry issue)
3. The addition creates NaN (numerical issue)

The error occurs at lon=-43.88, lat=14.55 consistently, so
this should pinpoint the exact cause.
Added diagnostic checks at the point where DIC is read from state
array and converted for CO2 flux calculation.

Since the SMS debug didn't trigger, the NaN must appear between
SMS calculation and forcing. This will catch:
1. If state(one,idic) is already NaN when forcing starts
2. If the conversion to REcoM_DIC creates NaN

Will print node number, coordinates, and related state values
to identify the exact source of NaN.
@JanStreffing JanStreffing force-pushed the fesom2.6_recom_tra_diags branch from 619ee7c to c6c21e0 Compare November 12, 2025 22:28
@JanStreffing
Copy link
Collaborator

A couple of interesting changes so far. Some of the recom code was missing allocations, that triggered GNU errors. I am left with NANs in one init field that I failed to resolve.

@ogurses, @suvarchal: Can you check this out?

@JanStreffing JanStreffing modified the milestones: FESOM 2.7, FESOM 2.7.1 Nov 17, 2025
ogurses and others added 3 commits December 1, 2025 10:49
When ballasting is used, vertical sinking is adjusted
if the detritus carbon biomass exceeds a treshold value (0.001).
This results in large air-sea co2flux uptake. Weremove this constraint.
@JanStreffing JanStreffing force-pushed the fesom2.6_recom_tra_diags branch from e5e0fe2 to 075f709 Compare January 26, 2026 16:00
@JanStreffing JanStreffing modified the milestones: FESOM 2.7.1, FESOM 2.8 Feb 18, 2026
@JanStreffing
Copy link
Collaborator

@ogurses, @suvarchal, @patrickscholz
I think we should try to resolve the last issues on the CI test and merge this branch. I'm at AWI to join next week Monday to Wednesday. After that, I'm away for some weeks.

Comment on lines +425 to +433
if (tracers%data(tr_num)%ltra_diag) then
do n=1, myDim_nod2D+eDim_nod2D
nu1 = ulevels_nod2D(n)
nl1 = nlevels_nod2D(n)
do nz = nu1, nl1-1
ttf_rhs_bak(nz,n) = del_ttf(nz,n)
end do
end do
end if
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be nice if we could encapsulate this in a subroutine not to make our code messy and unreadable! Especially that this pieces repeat itself

Comment on lines +441 to +451
if (tracers%data(tr_num)%ltra_diag) then
do n=1, myDim_nod2D+eDim_nod2D
nu1 = ulevels_nod2D(n)
nl1 = nlevels_nod2D(n)
do nz = nu1, nl1-1
! horizontal diffusion (w/out Redi)
tracers%work%tra_diff_part_hor_redi(nz,n,tr_num) = (del_ttf(nz,n) - ttf_rhs_bak(nz,n)) / hnode_new(nz,n) ! Unit [Conc]
!if (mype==0) print *, tracers%work%tra_diff_part_hor_redi(nz,n,tr_num)
end do
end do
end if
Copy link
Contributor

Choose a reason for hiding this comment

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

Here that same this, this structure repeats itself and could be a re-callable subroutine

@patrickscholz
Copy link
Contributor

I talked a while a ago with Sergey about this, and we should try to encapsulate as much of RECOM as we can, To achieve that as much of RECOM lives within the recom_...F90 code files and is only called by function and subroutines (e.g boundary conditions, initialisation, ...). We have been a bit sloppy about this with all the iceberg and transient tracer stuff in the past, which made large part of the FESOM code especially the initialisation, tracer and boundary condition part very crowded and messy and more difficult to maintain.

@JanStreffing
Copy link
Collaborator

Perfect task for the AI. I had it search for more cases:

Similar repeated-structure cases in REcoM code (candidates for future refactor)

  1. src/int_recom/recom_main.F90

    • Pattern: In the main node loop (do n=1,myDim_nod2D) there is a recurring
      "backup state -> do work -> compute diagnostic delta" idiom.
    • Example: ttf_rhs_bak is filled for all tracers with ltra_diag, and later
      tracers%work%tra_recom_sms(...) is computed as values - ttf_rhs_bak.
    • Why it’s similar: conceptually the same as the backup/delta calculation
      refactored in src/oce_ale_tracer.F90 (just organized differently).
  2. src/int_recom/recom_sinking.F90

    • Pattern: long sequences of if(tracer ID == ...) blocks repeat nearly the same
      update structure for different element pools:
      • update Benthos(n,k)
      • optionally update SinkFlx_tr(n,k,tr_num) when use_MEDUSA
      • optionally update Benthos_tr(n,k,tr_num)
        repeated for N/C/Si/CaCO3 and also isotope variants.
    • Why it’s similar: repetitive boilerplate where only the tracer-ID set and the
      target index (k) changes.
  3. src/int_recom/recom_init.F90

    • Pattern: repeated min/max scanning over nodes for multiple REcoM tracers,
      followed by repeated MPI_Allreduce calls with identical structure.
    • Why it’s similar: repeated blocks of the same operation on different tracer IDs.
  4. src/int_recom/recom_sms.F90 (benthic remineralization section)

    • Pattern: repeated update equations with the same shape:
      decayBenthos(i) = rate(i) * LocBenthos(i)
      LocBenthos(i) = LocBenthos(i) - decayBenthos(i) * dt_b
      repeated across elements and (optionally) isotopes.
    • Why it’s similar: identical structure differing only by indices/parameters.

This was referenced Feb 25, 2026
@JanStreffing
Copy link
Collaborator

I tried my hands on this, but I was not able to figure out what is wrong with the DIC_PI file. Could your try this out @ogurses ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create REcoM CI test

5 participants