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

Transferring Grid in memory #3

Open
Sumanshekhar17 opened this issue Jun 20, 2024 · 1 comment
Open

Transferring Grid in memory #3

Sumanshekhar17 opened this issue Jun 20, 2024 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@Sumanshekhar17
Copy link
Collaborator

@danrosen25 Starting an issue to track the progress of the code!

Problem description:
Right now we want to use a grid provided by another component in a NUOPC model, instead of creating a new one. This process is part of setting up the interactions between model component and DART, where one component can "accept" a grid and associated fields from another component.

Here's how we could manage this using a grid provided by another component (rough idea):

Step 1: Configuration of the Import State
To use a grid from another component, the DART component needs to properly configure its import state to indicate that it expects to receive this grid. This is typically done during the initialization phase where you define what DART would need (import) and produce (export).

Step 2: Advertise and Realize
In NUOPC, fields and their associated grids are advertised to communicate what a component can provide or needs to receive. Then, during the realization step, the component actually acquires the data structures necessary to operate on the data, including the grid. This can be done using ESMF field API ?

Tagging @amrhein @hkershaw-brown @anhpham3621 so that you guys could get notification!

@Sumanshekhar17
Copy link
Collaborator Author

code might look like this-

subroutine InitializeAdvertise(model, rc):
    type(ESMF_GridComp)   :: model
    integer, intent(out)          :: rc

    ! local variable
    type(ESMF_State)           :: importstate, exportstate
    
    rc = ESMF_SUCCESS

    call NUOPC_ModelGet(model. importState=importstate, exportState=exportstate, rc=rc)
    if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF+LogFoundError, line=__LINE__, file=__FILE__)) return ! bail out
end Subroutine InitializationAdvertise

subroutine InitializeRealize(model, rc)
    type(ESMF_GridComp)  :: model
    integer, intent(out) :: rc

    ! local variables
    type(ESMF_State)     :: importstate
    type(ESMF_Field)      :: sstField
    type(ESMF_Grid)       :: receivedGrid

    rc = ESMF_SUCCESS

    ! Get import state from the model
    call NUOPC_ModelGet(model, importState=importState, rc=rc)
    if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

    ! Get the field from the import state
    call ESMF_StateGet(importState, fieldName="sst", field=sstField, rc=rc)
    if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

    ! Retrieve the grid associated with the field
    receivedGrid = ESMF_FieldGetGrid(sstField, rc=rc)
    if (ESMF_LogFoundError(rcToCheck=rc, msg=ESMF_LOGERR_PASSTHRU, line=__LINE__, file=__FILE__)) return

    ! Now, receivedGrid contains the grid from the ocean model

    ! Further processing using receivedGrid

end subroutine InitializeRealize

However, I don't see ESMF_FieldGetGrid API in the documentation but it's there in one code https://geos5.org/svn/tags/Heracles-2_0/src/GMAO_Shared/MAPL_Base/ESMFL_Mod.P90

@danrosen25 could you please point out the similar API to fetch the grid from incoming field class?

@Sumanshekhar17 Sumanshekhar17 added the question Further information is requested label Jun 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants