DART-NUOPC / NUOPC_DART-code-development

This repository is for the fortran code development branch
1 stars 1 forks source link

Transferring Grid in memory #3

Open Sumanshekhar17 opened 5 months ago

Sumanshekhar17 commented 5 months ago

@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 commented 5 months ago

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?