GEOS-ESM / MAPL

MAPL is a foundation layer of the GEOS architecture, whose original purpose is to supplement the Earth System Modeling Framework (ESMF)
https://geos-esm.github.io/MAPL/
Apache License 2.0
25 stars 18 forks source link

How to specify export bundle fields in HISTORY.rc #30

Closed lizziel closed 3 years ago

lizziel commented 5 years ago

I have a general MAPL history question. I have code below that creates an ‘MSA’ field in the ‘AEROSOLS’ bundle within the ‘AERO’ export.

In SetServices:

call MAPL_AddExportSpec(GC,                    &
       SHORT_NAME = 'AERO',                        &
       LONG_NAME  = 'aerosol_mass_mixing_ratios',  &
       UNITS      = 'kg kg-1',                     &
       DIMS       = MAPL_DimsHorzVert,             &
       VLOCATION  = MAPL_VLocationCenter,          &
       DATATYPE   = MAPL_StateItem, __RC__)

In Initialize:

call ESMF_StateGet(expChem, 'AERO', aero, __RC__)
aero_state_aerosols = ESMF_FieldBundleCreate(name='AEROSOLS', __RC__)
call MAPL_StateAdd(aero, aero_state_aerosols, __RC__)
call ESMF_StateGet(INTERNAL,’GOCART::MSA_ForBundle', FIELD, __RC__ )
fld = MAPL_FieldCreate(FIELD, name=’MSA’, __RC__)
call MAPL_FieldBundleAdd(aero_state_aerosols, fld, __RC__)

My question is how do I output the ‘MSA’ field via History? Is there syntax for specifying export/bundle/field? I realize perhaps outputting the internal state here is a better option, but I would like to know how to get at the AERO export contents directly.

lizziel commented 5 years ago

@bena-nasa Following our discussion last week I tried adding each of these to HISTORY.rc, specifying gridcomp 'GOCART': 'AEROSOLS%MSA' 'AERO%AEROSOLS%MSA' 'AERO%MSA' 'MSA' 'AERO'

All of these combinations failed with MAPL_StateGet errors in History. Do you know for certain that export bundle fields can be output via MAPL History?

bena-nasa commented 5 years ago

Lizzie, First, we never add states to state like that in the addexport, importspec. If you add the spec like you do in the example I'm sure it will not work.

In SetServices you create the bundle in the export state like this:

call MAPL_AddExportSpec(GC,                    &
       SHORT_NAME = 'AERO',                        &
       LONG_NAME  = 'aerosol_mass_mixing_ratios',  &
       UNITS      = 'kg kg-1',                     &
       DIMS       = MAPL_DimsHorzVert,             &
       VLOCATION  = MAPL_VLocationCenter,          &
       DATATYPE   = MAPL_BundleItem, __RC__)

Then in the component declaring this after generic intialize has run you can retrieve the bundle from the state.

call ESMF_StateGet(EXPORT, 'AERO',    AERO,        RC=STATUS); VERIFY_(STATUS)

At that point you can add fields to it with the appropriate MAPL or ESMF call like MAPL_FieldBundleAdd

Like I said, if those fields are not created the way History expects, (i.e. the way they are created by the AddExport/Import/InternalSpec call which adds multiple attributes to the field such as units, long_name, and dimensionality information) it will have problems. Most of the time we are adding fields to bundles with all this friendly business so it is usually pulling them from other components.

The bundle retrieval definitely works. Our chemistry people have been using.

lizziel commented 5 years ago

@bena-nasa My example code is cut and pasted from GOCART in a fairly recent version of GEOSgcm. I did not edit it beyond omitting non-relevant lines of code. It seems to work okay for exporting the aerosol bundle from GOCART to Radiation since it has been in place for a while. I believe Elliot Sherman is working to rewrite GOCART to clean up the code. Perhaps this is an area that could be made more standard?

I am going to close this issue since it is no longer a problem for me. I am getting the array values I want to History via other means.