Skip to content

Refactor OBC segment init/update (Part 1)#1053

Open
herrwang0 wants to merge 3 commits intoNOAA-GFDL:dev/gfdlfrom
herrwang0:refactor-obc-init-segment-step1-allocate
Open

Refactor OBC segment init/update (Part 1)#1053
herrwang0 wants to merge 3 commits intoNOAA-GFDL:dev/gfdlfrom
herrwang0:refactor-obc-init-segment-step1-allocate

Conversation

@herrwang0
Copy link

@herrwang0 herrwang0 commented Mar 13, 2026

Overview

This PR is the first one of a series of PRs on OBC refactor, targeting how segment data is initialized and updated, specifically subroutines initialize_segment_data and update_OBC_segment_data. The work is broken down to three parts to hopefully make review easier.

The refactor is driven by a bug in the OBC where segment data fails to update correctly when using the VALUE option. This specific issue will be addressed in the last part of this series.

Changes in this PR

This PR contains three incremental, compartmentalized commits. While the commit messages provide granular details, here is a summary of their objectives:

d8d4bf3 Renames indexing variables in update_OBC_segment_data to match the rest of the module. This improves consistency and simplifies the migration of logic into the subroutine to initialize_segment_data.

b55e0a6 Moves the allocation of buffer_dst arrays from update_OBC_segment_data to initialize_segment_data. Since these arrays are always allocated, they are more appropriately handled during the initialization phase.

fa220e4 Extracts the allocations of both buffer_dst and buffer_src arrays out of the main body of initialize_segment_data. This improves readability and prepares for separating physical and BGC fields in the next PR.

Each commit is tested to be compilable and introduces no answer change.

This commit changes the indexing variables in open boundary routine
update_OBC_segment_data, so that they are consistent with the rest of
the model. The changes improve readability and prepares moving part of
the subroutine to initialize_segment_data.

The changes includes,
* Use [ij][se]d and [IJ][se]dB aliases for indexings in segment%HI
* Replace [ij][se]_obc with [IJ][se]dB
* For interior cells, retire [ij]shift and use [ij]sd that are already
saved in segment%HI

Other minor changes:
* Add a comment that segment%Cg is never used by the model
* Change normal_trans_bt in update_OBC_segment_data from an allocatable
array to a scalar
This commit moves allocating buffer_dst array of segment%field type to
routine initialize_segment_data from update_OBC_segment_data. This array
is always allocated and exits in the duration of the run. It makes more
sense to have the allocation occur in the init subroutine, than a
routine called every time step.

Other changes
* Simplify remapping_core_h call in update_OBC_segment_data.
* make dz_stack a fix-sized array than an allocatable
@herrwang0 herrwang0 added the refactor Code cleanup with no changes in functionality or results label Mar 13, 2026
@herrwang0 herrwang0 force-pushed the refactor-obc-init-segment-step1-allocate branch 2 times, most recently from 765ba50 to 59a219a Compare March 13, 2026 02:55
This commit moves out all allocations from initialize_segment_data to a
new subroutine allocate_segment_field_data, which includes buffer_src
and buffer_dst. allocate_segment_field_data always assigns other
attributes of segment%field, including "on_face", "scale", "use_IO"

Minor updates
* Remove OBC%thickness_segment_data_exists, which is never used.
* Change string "genre" in segment%field to logical "bgc_tracer"
* Remove GV input (unused) from subroutine scale_factor_from_name
* Rename local variables in initialize_segment_data for clarity
    * fields -> field_names
    * fieldname -> varname
@herrwang0 herrwang0 force-pushed the refactor-obc-init-segment-step1-allocate branch from 59a219a to 5e369f2 Compare March 13, 2026 03:03
@herrwang0 herrwang0 changed the title Refactor OBC segment init/update (Part 1/3) Refactor OBC segment init/update (Part 1) Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Code cleanup with no changes in functionality or results

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant