Skip to content

Commit 48ff3cd

Browse files
committed
Support 'hconfig' object in CompCreate().
1 parent 0f85c3c commit 48ff3cd

File tree

5 files changed

+236
-28
lines changed

5 files changed

+236
-28
lines changed

src/Superstructure/Component/src/ESMF_Comp.F90

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,8 @@ impure elemental function ESMF_ctne(ct1, ct2)
557557
! !IROUTINE: ESMF_CompConstruct - Internal routine to fill in a comp struct
558558

559559
! !INTERFACE:
560-
recursive subroutine ESMF_CompConstruct(compp, compType, name, &
561-
dirPath, configFile, config, clock, petlist, devlist, contextflag, rc)
560+
recursive subroutine ESMF_CompConstruct(compp, compType, name, dirPath, &
561+
configFile, config, hconfig, clock, petlist, devlist, contextflag, rc)
562562
!
563563
! !ARGUMENTS:
564564
type(ESMF_CompClass), pointer :: compp
@@ -567,6 +567,7 @@ recursive subroutine ESMF_CompConstruct(compp, compType, name, &
567567
character(len=*), intent(in), optional :: dirPath
568568
character(len=*), intent(in), optional :: configFile
569569
type(ESMF_Config), intent(in), optional :: config
570+
type(ESMF_HConfig), intent(in), optional :: hconfig
570571
type(ESMF_Clock), intent(in), optional :: clock
571572
integer, intent(in), optional :: petlist(:)
572573
integer, intent(in), optional :: devlist(:)
@@ -591,7 +592,9 @@ recursive subroutine ESMF_CompConstruct(compp, compType, name, &
591592
! File containing configuration information, either absolute filename
592593
! or relative to {\tt dirPath}.
593594
! \item[{[config]}]
594-
! Already created {\tt config} object.
595+
! Already created Config object.
596+
! \item[{[hconfig]}]
597+
! Already created HConfig object.
595598
! \item[{[clock]}]
596599
! Private {\tt clock} for this {\tt Component}.
597600
! \item[{[petlist]}]
@@ -611,9 +614,9 @@ recursive subroutine ESMF_CompConstruct(compp, compType, name, &
611614
integer :: localrc ! local return code
612615
integer :: npets, mypet, i, petCount
613616
integer, pointer :: petlist_loc(:), devlist_loc(:)
614-
character(len=ESMF_MAXPATHLEN) :: fullpath ! config file + dirPath
615-
character(len=ESMF_MAXSTR) :: msgbuf
616-
type(ESMF_VM):: vm
617+
character(len=ESMF_MAXPATHLEN) :: fullpath ! config file + dirPath
618+
character(len=ESMF_MAXSTR) :: msgbuf
619+
type(ESMF_VM) :: vm
617620

618621
! Assume not implemented until success
619622
if (present(rc)) rc = ESMF_RC_NOT_IMPL
@@ -674,14 +677,29 @@ recursive subroutine ESMF_CompConstruct(compp, compType, name, &
674677
endif
675678

676679
! config handling
677-
if (present(config)) then
678-
compp%config = config
680+
if (present(hconfig)) then
681+
if (present(config).or.present(configFile)) then
682+
call ESMF_LogSetError(ESMF_RC_ARG_BAD, &
683+
msg="Must only specify one of: "// &
684+
"'hconfig', 'config', or 'configFile' arguments!", &
685+
ESMF_CONTEXT, rcToReturn=rc)
686+
return
687+
endif
688+
compp%config = ESMF_ConfigCreate(hconfig=hconfig, rc=localrc)
689+
if (ESMF_LogFoundError(localrc, &
690+
ESMF_ERR_PASSTHRU, &
691+
ESMF_CONTEXT, rcToReturn=rc)) return
679692
compp%compStatus%configIsPresent = .true.
693+
else if (present(config)) then
680694
if (present(configFile)) then
681-
! a config object gets priority over a name if both are specified.
682-
call ESMF_LogWrite("Ignoring configFile because config object given.", &
683-
ESMF_LOGMSG_WARNING)
695+
call ESMF_LogSetError(ESMF_RC_ARG_BAD, &
696+
msg="Must only specify one of: "// &
697+
"'hconfig', 'config', or 'configFile' arguments!", &
698+
ESMF_CONTEXT, rcToReturn=rc)
699+
return
684700
endif
701+
compp%config = config
702+
compp%compStatus%configIsPresent = .true.
685703
else if (present(configFile)) then
686704
! name of a specific config file. open it and store the config object.
687705
compp%configFile = configFile

src/Superstructure/Component/src/ESMF_CplComp.F90

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,14 +358,15 @@ end function ESMF_CplCompNE
358358
! !IROUTINE: ESMF_CplCompCreate - Create a CplComp
359359
!
360360
! !INTERFACE:
361-
recursive function ESMF_CplCompCreate(keywordEnforcer, config, configFile, &
362-
clock, petList, devList, contextflag, name, rc)
361+
recursive function ESMF_CplCompCreate(keywordEnforcer, hconfig, config, &
362+
configFile, clock, petList, devList, contextflag, name, rc)
363363
!
364364
! !RETURN VALUE:
365365
type(ESMF_CplComp) :: ESMF_CplCompCreate
366366
!
367367
! !ARGUMENTS:
368368
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
369+
type(ESMF_HConfig), intent(in), optional :: hconfig
369370
type(ESMF_Config), intent(in), optional :: config
370371
character(len=*), intent(in), optional :: configFile
371372
type(ESMF_Clock), intent(in), optional :: clock
@@ -382,6 +383,8 @@ recursive function ESMF_CplCompCreate(keywordEnforcer, config, configFile, &
382383
! \begin{description}
383384
! \item[8.6.0] Added argument {\tt devList} to support management of accelerator
384385
! devices.
386+
! \item[8.7.0] Added argument {\tt hconfig} to simplify direct usage of
387+
! {\tt ESMF\_HConfig} objects with Components.
385388
! \end{description}
386389
! \end{itemize}
387390
!
@@ -400,18 +403,23 @@ recursive function ESMF_CplCompCreate(keywordEnforcer, config, configFile, &
400403
!
401404
! The arguments are:
402405
! \begin{description}
406+
! \item[{[hconfig]}]
407+
! An already-created {\tt ESMF\_HConfig} object to be attached to the newly
408+
! created component.
409+
! Only one of {\tt hconfig}, {\tt config}, or {\tt configFile} must be
410+
! specified.
403411
! \item[{[config]}]
404412
! An already-created {\tt ESMF\_Config} object to be attached to the newly
405413
! created component.
406-
! If both {\tt config} and {\tt configFile} arguments are specified,
407-
! {\tt config} takes priority.
414+
! Only one of {\tt hconfig}, {\tt config}, or {\tt configFile} must be
415+
! specified.
408416
! \item[{[configFile]}]
409-
! The filename of an {\tt ESMF\_Config} format file.
417+
! The filename of a config file.
410418
! If specified, a new {\tt ESMF\_Config} object is created and attached to the
411419
! newly created component. The {\tt configFile} file is opened and associated
412420
! with the new config object.
413-
! If both {\tt config} and {\tt configFile} arguments are specified,
414-
! {\tt config} takes priority.
421+
! Only one of {\tt hconfig}, {\tt config}, or {\tt configFile} must be
422+
! specified.
415423
! \item[{[clock]}]
416424
! \begin{sloppypar}
417425
! Component-specific {\tt ESMF\_Clock}. This clock is available to be
@@ -466,8 +474,8 @@ recursive function ESMF_CplCompCreate(keywordEnforcer, config, configFile, &
466474

467475
! call Comp method
468476
call ESMF_CompConstruct(compclass, ESMF_COMPTYPE_CPL, name, &
469-
configFile=configFile, config=config, clock=clock, petList=petList, &
470-
devList=devList, contextflag=contextflag, rc=localrc)
477+
configFile=configFile, config=config, hconfig=hconfig, clock=clock, &
478+
petList=petList, devList=devList, contextflag=contextflag, rc=localrc)
471479
if (ESMF_LogFoundError(localrc, &
472480
ESMF_ERR_PASSTHRU, &
473481
ESMF_CONTEXT, rcToReturn=rc)) then

src/Superstructure/Component/src/ESMF_GridComp.F90

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ end function ESMF_GridCompNE
366366
! !INTERFACE:
367367
recursive function ESMF_GridCompCreate(keywordEnforcer, grid, gridList, &
368368
mesh, meshList, locstream, locstreamList, xgrid, xgridList, &
369-
config, configFile, clock, petList, devList, contextflag, name, rc)
369+
hconfig, config, configFile, clock, petList, devList, contextflag, name, rc)
370370
!
371371
! !RETURN VALUE:
372372
type(ESMF_GridComp) :: ESMF_GridCompCreate
@@ -381,6 +381,7 @@ recursive function ESMF_GridCompCreate(keywordEnforcer, grid, gridList, &
381381
type(ESMF_LocStream), intent(in), optional :: locstreamList(:)
382382
type(ESMF_XGrid), intent(in), optional :: xgrid
383383
type(ESMF_XGrid), intent(in), optional :: xgridList(:)
384+
type(ESMF_HConfig), intent(in), optional :: hconfig
384385
type(ESMF_Config), intent(in), optional :: config
385386
character(len=*), intent(in), optional :: configFile
386387
type(ESMF_Clock), intent(in), optional :: clock
@@ -403,6 +404,8 @@ recursive function ESMF_GridCompCreate(keywordEnforcer, grid, gridList, &
403404
! {\tt ESMF\_GridComp} object.
404405
! \item[8.6.0] Added argument {\tt devList} to support management of accelerator
405406
! devices.
407+
! \item[8.7.0] Added argument {\tt hconfig} to simplify direct usage of
408+
! {\tt ESMF\_HConfig} objects with Components.
406409
! \end{sloppypar}
407410
! \end{description}
408411
! \end{itemize}
@@ -502,18 +505,23 @@ recursive function ESMF_GridCompCreate(keywordEnforcer, grid, gridList, &
502505
! error is returned in {\tt rc}.
503506
! By default, i.e. if neither {\tt xgrid} nor {\tt xgridList} are provided,
504507
! no {\tt ESMF\_XGrid} objects are associated with the component.
508+
! \item[{[hconfig]}]
509+
! An already-created {\tt ESMF\_HConfig} object to be attached to the newly
510+
! created component.
511+
! Only one of {\tt hconfig}, {\tt config}, or {\tt configFile} must be
512+
! specified.
505513
! \item[{[config]}]
506514
! An already-created {\tt ESMF\_Config} object to be attached to the newly
507515
! created component.
508-
! If both {\tt config} and {\tt configFile} arguments are specified,
509-
! {\tt config} takes priority.
516+
! Only one of {\tt hconfig}, {\tt config}, or {\tt configFile} must be
517+
! specified.
510518
! \item[{[configFile]}]
511-
! The filename of an {\tt ESMF\_Config} format file.
519+
! The filename of a config file.
512520
! If specified, a new {\tt ESMF\_Config} object is created and attached to the
513521
! newly created component. The {\tt configFile} file is opened and associated
514522
! with the new config object.
515-
! If both {\tt config} and {\tt configFile} arguments are specified,
516-
! {\tt config} takes priority.
523+
! Only one of {\tt hconfig}, {\tt config}, or {\tt configFile} must be
524+
! specified.
517525
! \item[{[clock]}]
518526
! \begin{sloppypar}
519527
! Component-specific {\tt ESMF\_Clock}. This clock is available to be
@@ -551,6 +559,7 @@ recursive function ESMF_GridCompCreate(keywordEnforcer, grid, gridList, &
551559
integer :: localrc ! local error status
552560

553561
ESMF_INIT_CHECK_DEEP(ESMF_GridGetInit,grid,rc)
562+
ESMF_INIT_CHECK_DEEP(ESMF_HConfigGetInit,hconfig,rc)
554563
ESMF_INIT_CHECK_DEEP(ESMF_ConfigGetInit,config,rc)
555564
ESMF_INIT_CHECK_DEEP(ESMF_ClockGetInit,clock,rc)
556565

@@ -569,8 +578,8 @@ recursive function ESMF_GridCompCreate(keywordEnforcer, grid, gridList, &
569578

570579
! call Comp method
571580
call ESMF_CompConstruct(compclass, ESMF_COMPTYPE_GRID, name, &
572-
configFile=configFile, config=config, clock=clock, petList=petList, &
573-
devList=devList, contextflag=contextflag, rc=localrc)
581+
configFile=configFile, config=config, hconfig=hconfig, clock=clock, &
582+
petList=petList, devList=devList, contextflag=contextflag, rc=localrc)
574583
if (ESMF_LogFoundError(localrc, &
575584
ESMF_ERR_PASSTHRU, &
576585
ESMF_CONTEXT, rcToReturn=rc)) then

src/Superstructure/Component/tests/ESMF_CplCompCreateUTest.F90

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,92 @@ program ESMF_CplCompCreateUTest
609609
write(name, *) "HConfig handling Test - validate attribute value"
610610
call ESMF_Test((fred==1), name, failMsg, result, ESMF_SRCLINE)
611611

612+
!-------------------------------------------------------------------------
613+
! !
614+
!EX_UTest
615+
! ! Test creation of a Component
616+
write(name, *) "Creating a Component with Config Test"
617+
write(failMsg, *) "Did not return ESMF_SUCCESS"
618+
619+
cpl2 = ESMF_CplCompCreate(name="TestComp", config=config, rc=rc)
620+
621+
call ESMF_Test((rc.eq.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE)
622+
623+
!-------------------------------------------------------------------------
624+
! !
625+
!EX_UTest
626+
write(name, *) "GridCompDestroy Test"
627+
write(failMsg, *) "Did not return ESMF_SUCCESS"
628+
call ESMF_CplCompDestroy(cpl2, rc=rc)
629+
call ESMF_Test((rc.eq.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE)
630+
631+
!-------------------------------------------------------------------------
632+
! !
633+
!EX_UTest
634+
! ! Test creation of a Component
635+
write(name, *) "Creating a Component with HConfig Test"
636+
write(failMsg, *) "Did not return ESMF_SUCCESS"
637+
638+
cpl2 = ESMF_CplCompCreate(name="TestComp", hconfig=hconfig, rc=rc)
639+
640+
call ESMF_Test((rc.eq.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE)
641+
642+
!-------------------------------------------------------------------------
643+
! !
644+
!EX_UTest
645+
write(name, *) "GridCompDestroy Test"
646+
write(failMsg, *) "Did not return ESMF_SUCCESS"
647+
call ESMF_CplCompDestroy(cpl2, rc=rc)
648+
call ESMF_Test((rc.eq.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE)
649+
650+
!-------------------------------------------------------------------------
651+
! !
652+
!EX_UTest
653+
! ! Test creation of a Component
654+
write(name, *) "Creating a Component with too many config args Test"
655+
write(failMsg, *) "Did not return expected return code"
656+
657+
cpl2 = ESMF_CplCompCreate(name="TestComp", hconfig=hconfig, &
658+
config=config, rc=rc)
659+
660+
call ESMF_Test((rc.ne.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE)
661+
662+
!-------------------------------------------------------------------------
663+
! !
664+
!EX_UTest
665+
! ! Test creation of a Component
666+
write(name, *) "Creating a Component with too many config args Test"
667+
write(failMsg, *) "Did not return expected return code"
668+
669+
cpl2 = ESMF_CplCompCreate(name="TestComp", config=config, &
670+
configFile="comp.yaml", rc=rc)
671+
672+
call ESMF_Test((rc.ne.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE)
673+
674+
!-------------------------------------------------------------------------
675+
! !
676+
!EX_UTest
677+
! ! Test creation of a Component
678+
write(name, *) "Creating a Component with too many config args Test"
679+
write(failMsg, *) "Did not return expected return code"
680+
681+
cpl2 = ESMF_CplCompCreate(name="TestComp", hconfig=hconfig, &
682+
configFile="comp.yaml", rc=rc)
683+
684+
call ESMF_Test((rc.ne.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE)
685+
686+
!-------------------------------------------------------------------------
687+
! !
688+
!EX_UTest
689+
! ! Test creation of a Component
690+
write(name, *) "Creating a Component with too many config args Test"
691+
write(failMsg, *) "Did not return expected return code"
692+
693+
cpl2 = ESMF_CplCompCreate(name="TestComp", hconfig=hconfig, &
694+
config=config, configFile="comp.yaml", rc=rc)
695+
696+
call ESMF_Test((rc.ne.ESMF_SUCCESS), name, failMsg, result, ESMF_SRCLINE)
697+
612698
!-------------------------------------------------------------------------
613699
! !
614700
!EX_UTest

0 commit comments

Comments
 (0)