Skip to content

Commit b4894c7

Browse files
committed
Add MPAS NUOPC cap stub to core_atmosphere
* add installation locations for MPAS_PREFIX, MPAS_LIBDIR, MPAS_MODDIR * add NUOPC option for building caps * add nuopc folder to core_atmosphere with stub cap
1 parent 8da696a commit b4894c7

11 files changed

Lines changed: 340 additions & 4 deletions

File tree

Makefile

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,17 @@ intel: # BUILDTARGET Intel oneAPI Fortran, C, and C++ compiler suite
684684
CPPINCLUDES =
685685
FCINCLUDES =
686686
LIBS =
687+
MPAS_PREFIX ?= $(CURDIR)
688+
MPAS_LIBDIR ?= $(MPAS_PREFIX)/lib
689+
MPAS_MODDIR ?= $(MPAS_PREFIX)/mod
690+
691+
NUOPC ?= false
692+
ifeq ($(NUOPC), true)
693+
MPAS_ESMF = external
694+
NUOPC_MESSAGE="MPAS was built with NUOPC cap libraries."
695+
else
696+
NUOPC_MESSAGE="MPAS was built without NUOPC cap libraries."
697+
endif
687698

688699
export MPAS_ESMF ?= embedded
689700
ifeq "$(MPAS_ESMF)" "external"
@@ -1537,6 +1548,8 @@ SCOTCH_MESSAGE = "MPAS was NOT linked with the Scotch graph partitioning library
15371548
endif
15381549

15391550
mpas_main: $(MAIN_DEPS)
1551+
if [ ! -d $(MPAS_LIBDIR) ]; then mkdir $(MPAS_LIBDIR); fi
1552+
if [ ! -d $(MPAS_MODDIR) ]; then mkdir $(MPAS_MODDIR); fi
15401553
cd src; $(MAKE) FC="$(FC)" \
15411554
CC="$(CC)" \
15421555
CXX="$(CXX)" \
@@ -1558,7 +1571,11 @@ mpas_main: $(MAIN_DEPS)
15581571
AUTOCLEAN_DEPS="$(AUTOCLEAN_DEPS)" \
15591572
GEN_F90="$(GEN_F90)" \
15601573
NAMELIST_SUFFIX="$(NAMELIST_SUFFIX)" \
1561-
EXE_NAME="$(EXE_NAME)"
1574+
EXE_NAME="$(EXE_NAME)" \
1575+
MPAS_PREFIX="$(MPAS_PREFIX)" \
1576+
MPAS_LIBDIR="$(MPAS_LIBDIR)" \
1577+
MPAS_MODDIR="$(MPAS_MODDIR)" \
1578+
NUOPC="$(NUOPC)"
15621579

15631580
if [ -e src/$(EXE_NAME) ]; then mv src/$(EXE_NAME) .; fi
15641581
( cd src/core_$(CORE); $(MAKE) ROOT_DIR="$(PWD)" post_build )
@@ -1582,14 +1599,17 @@ endif
15821599
@echo $(TIMER_MESSAGE)
15831600
@echo $(IO_MESSAGE)
15841601
@echo $(ESMF_MESSAGE)
1602+
@echo $(NUOPC_MESSAGE)
15851603
@echo "*******************************************************************************"
15861604
clean:
1587-
cd src; $(MAKE) clean RM="$(RM)" CORE="$(CORE)" AUTOCLEAN="$(AUTOCLEAN)"
1605+
cd src; $(MAKE) clean RM="$(RM)" CORE="$(CORE)" AUTOCLEAN="$(AUTOCLEAN)" NUOPC="$(NUOPC)"
15881606
$(RM) $(EXE_NAME)
15891607
$(RM) namelist.$(NAMELIST_SUFFIX).defaults
15901608
$(RM) streams.$(NAMELIST_SUFFIX).defaults
15911609
if [ -f .build_opts.framework ]; then $(RM) .build_opts.framework; fi
15921610
if [ -f .build_opts.$(CORE) ]; then $(RM) .build_opts.$(CORE); fi
1611+
if [ -d $(MPAS_LIBDIR) ]; then $(RM) -r $(MPAS_LIBDIR); fi
1612+
if [ -d $(MPAS_MODDIR) ]; then $(RM) -r $(MPAS_MODDIR); fi
15931613

15941614
core_error:
15951615
@echo ""
@@ -1641,6 +1661,7 @@ errmsg:
16411661
@echo " MPAS_ESMF=opt - Selects the ESMF library to be used for MPAS. Options are:"
16421662
@echo " MPAS_ESMF=embedded - Use the embedded ESMF timekeeping library (default)"
16431663
@echo " MPAS_ESMF=external - Use an external ESMF library, determined by ESMFMKFILE"
1664+
@echo " NUOPC=true - builds NUOPC library (libmpas_nuopc.a) and installs to lib/ with mod files to mod/. Default is false."
16441665
@echo ""
16451666
@echo "Ensure that NETCDF, PNETCDF, PIO, and PAPI (if USE_PAPI=true) are environment variables"
16461667
@echo "that point to the absolute paths for the libraries."

src/Makefile

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ include Makefile.in.$(ESM)
66

77
else
88

9-
all: mpas
9+
BUILD_ALL = mpas
10+
ifeq "$(NUOPC)" "true"
11+
BUILD_ALL += nuopc_lib
12+
endif
13+
14+
all: $(BUILD_ALL)
1015

1116
mpas: $(AUTOCLEAN_DEPS) externals frame ops dycore drver
1217
$(LINKER) $(LDFLAGS) -o $(EXE_NAME) driver/*.o -L. -ldycore -lops -lframework $(LIBS) $(MPAS_ESMF_INC) $(MPAS_ESMF_LIB)
@@ -35,8 +40,18 @@ dycore: $(AUTOCLEAN_DEPS) build_tools externals frame ops
3540
( cd core_$(CORE); $(MAKE) CPPFLAGS="$(CPPFLAGS)" CPPINCLUDES="$(CPPINCLUDES)" all )
3641
ln -sf core_$(CORE)/libdycore.a libdycore.a
3742

43+
nuopc_lib: mpas
44+
( cd core_$(CORE); $(MAKE) CPPFLAGS="$(CPPFLAGS)" CPPINCLUDES="$(CPPINCLUDES)" FFLAGS="$(FFLAGS)" FCINCLUDES="$(FCINCLUDES)" nuopc )
45+
ar -ru $(MPAS_LIBDIR)/libmpas_nuopc.a libframework.a libops.a libdycore.a core_$(CORE)/nuopc/*.o
46+
ranlib $(MPAS_LIBDIR)/libmpas_nuopc.a
47+
cp core_$(CORE)/nuopc/*.mod $(MPAS_MODDIR)/.
3848

39-
clean: clean_shared clean_core
49+
CLEAN_ALL = clean_shared clean_core
50+
ifeq "$(NUOPC)" "true"
51+
CLEAN_ALL += clean_nuopc
52+
endif
53+
54+
clean: $(CLEAN_ALL)
4055

4156
clean_core:
4257
ifeq "$(AUTOCLEAN)" "true"
@@ -64,3 +79,12 @@ endif
6479
( cd framework; $(MAKE) clean )
6580
( cd operators; $(MAKE) clean )
6681
( cd driver; $(MAKE) clean )
82+
83+
clean_nuopc:
84+
$(info )
85+
$(info *********************************************************************************************)
86+
$(info The NUOPC library will be cleaned.)
87+
$(info *********************************************************************************************)
88+
$(info )
89+
$(RM) $(MPAS_LIBDIR)/libmpas_nuopc.a
90+
$(RM) $(MPAS_MODDIR)/*.mod

src/core_atmosphere/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ utilities: $(PHYSCORE)
6969
atmcore: $(PHYSCORE) dycore diagcore $(OBJS)
7070
ar -ru libdycore.a $(OBJS) dynamics/*.o $(PHYS_OBJS) $(CHEM_OBJS) diagnostics/*.o
7171

72+
nuopc: $(PHYSCORE) dycore diagcore $(OBJS)
73+
( cd nuopc; $(MAKE) all )
74+
7275
mpas_atm_core_interface.o: mpas_atm_core.o
7376

7477
mpas_atm_core.o: dycore diagcore mpas_atm_threading.o mpas_atm_halos.o
@@ -81,6 +84,7 @@ clean:
8184
( cd dynamics; $(MAKE) clean )
8285
( cd diagnostics; $(MAKE) clean )
8386
( cd utils; $(MAKE) clean )
87+
( cd nuopc; $(MAKE) clean )
8488
( cd ../..; rm -f *TBL )
8589
( cd ../..; rm -f *DATA* )
8690
$(RM) -r libphys

src/core_atmosphere/nuopc/Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.SUFFIXES: .F90 .o
2+
3+
OBJS = mpas_nuopc_atm.o
4+
5+
all: $(OBJS)
6+
7+
clean:
8+
$(RM) *.o *.mod
9+
@# Certain systems with intel compilers generate *.i files
10+
@# This removes them during the clean process
11+
$(RM) *.i
12+
13+
%.o: %.F90
14+
$(RM) $@ $*.mod
15+
$(FC) $(CPPFLAGS) $(PHYSICS) $(FFLAGS) -c $< -o $@ $(CPPINCLUDES) $(FCINCLUDES) $(MPAS_ESMF_INC)
16+
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
#define ESMF_ERR_RETURN(rc) if (ESMF_LogFoundError( \
2+
rcToCheck=rc, \
3+
msg=ESMF_LOGERR_PASSTHRU, \
4+
line=__LINE__, \
5+
file=__FILE__) \
6+
) return
7+
8+
module mpas_nuopc_atm
9+
!> MPAS NUOPC Cap for Atmosphere
10+
11+
use ESMF
12+
use NUOPC
13+
use NUOPC_Model, &
14+
modelSS => SetServices
15+
16+
implicit none
17+
18+
private
19+
20+
public SetVM, SetServices
21+
22+
!-----------------------------------------------------------------------------
23+
contains
24+
!-----------------------------------------------------------------------------
25+
26+
subroutine SetServices(model, rc)
27+
!> Register model entry points:
28+
!> Advertise: advertise import and export fields
29+
!> Realize: realize connected fields
30+
!> SetClock: initialize model clock
31+
!> DataInitialize: initialize data in import and export states
32+
!> Advance: advance model by a single time step
33+
!> Finalize: finalize model and cleanup memory
34+
35+
! arguments
36+
type(ESMF_GridComp) :: model
37+
integer, intent(out) :: rc
38+
39+
rc = ESMF_SUCCESS
40+
41+
! derive from NUOPC_Model
42+
call NUOPC_CompDerive(model, modelSS, rc=rc)
43+
ESMF_ERR_RETURN(rc)
44+
45+
! specialize model entry points
46+
call NUOPC_CompSpecialize(model, specLabel=label_Advertise, &
47+
specRoutine=Advertise, rc=rc)
48+
ESMF_ERR_RETURN(rc)
49+
call NUOPC_CompSpecialize(model, specLabel=label_RealizeProvided, &
50+
specRoutine=Realize, rc=rc)
51+
ESMF_ERR_RETURN(rc)
52+
call NUOPC_CompSpecialize(model, specLabel=label_SetClock, &
53+
specRoutine=SetClock, rc=rc)
54+
ESMF_ERR_RETURN(rc)
55+
call NUOPC_CompSpecialize(model, specLabel=label_DataInitialize, &
56+
specRoutine=DataInitialize, rc=rc)
57+
ESMF_ERR_RETURN(rc)
58+
call NUOPC_CompSpecialize(model, specLabel=label_Advance, &
59+
specRoutine=Advance, rc=rc)
60+
ESMF_ERR_RETURN(rc)
61+
call NUOPC_CompSpecialize(model, specLabel=label_Finalize, &
62+
specRoutine=Finalize, rc=rc)
63+
ESMF_ERR_RETURN(rc)
64+
65+
end subroutine SetServices
66+
67+
!-----------------------------------------------------------------------------
68+
69+
subroutine Advertise(model, rc)
70+
!> Advertise available export fields and desired import fields
71+
72+
! arguments
73+
type(ESMF_GridComp) :: model
74+
integer, intent(out) :: rc
75+
76+
! local variables
77+
type(ESMF_State) :: importState, exportState
78+
79+
rc = ESMF_SUCCESS
80+
81+
call NUOPC_ModelGet(model, importState=importState, &
82+
exportState=exportState, rc=rc)
83+
ESMF_ERR_RETURN(rc)
84+
85+
call ESMF_LogWrite(logmsgFlag=ESMF_LOGMSG_ERROR, &
86+
msg="MPAS NUOPC ATM - Advertise has not been implemented", &
87+
line=__LINE__, &
88+
file=__FILE__)
89+
90+
end subroutine Advertise
91+
92+
!-----------------------------------------------------------------------------
93+
94+
subroutine Realize(model, rc)
95+
!> Check field connections and realize connected fields
96+
97+
! arguments
98+
type(ESMF_GridComp) :: model
99+
integer, intent(out) :: rc
100+
101+
! local variables
102+
type(ESMF_State) :: importState, exportState
103+
104+
rc = ESMF_SUCCESS
105+
106+
call NUOPC_ModelGet(model, importState=importState, &
107+
exportState=exportState, rc=rc)
108+
ESMF_ERR_RETURN(rc)
109+
110+
call ESMF_LogWrite(logmsgFlag=ESMF_LOGMSG_ERROR, &
111+
msg="MPAS NUOPC ATM - Realize has not been implemented", &
112+
line=__LINE__, &
113+
file=__FILE__)
114+
115+
end subroutine Realize
116+
117+
!-----------------------------------------------------------------------------
118+
119+
subroutine SetClock(model, rc)
120+
!> Adjust model clock and time step during initialization
121+
122+
! arguments
123+
type(ESMF_GridComp) :: model
124+
integer, intent(out) :: rc
125+
126+
! local variables
127+
type(ESMF_Clock) :: clock
128+
type(ESMF_State) :: importState, exportState
129+
130+
rc = ESMF_SUCCESS
131+
132+
call NUOPC_ModelGet(model, modelClock=clock, &
133+
importState=importState, &
134+
exportState=exportState, rc=rc)
135+
ESMF_ERR_RETURN(rc)
136+
137+
call ESMF_LogWrite(logmsgFlag=ESMF_LOGMSG_ERROR, &
138+
msg="MPAS NUOPC ATM - SetClock has not been implemented", &
139+
line=__LINE__, &
140+
file=__FILE__)
141+
142+
end subroutine SetClock
143+
144+
!-----------------------------------------------------------------------------
145+
146+
subroutine DataInitialize(model, rc)
147+
!> Initialize data in import and export states
148+
149+
! arguments
150+
type(ESMF_GridComp) :: model
151+
integer, intent(out) :: rc
152+
153+
! local variables
154+
type(ESMF_Clock) :: clock
155+
type(ESMF_State) :: importState, exportState
156+
157+
rc = ESMF_SUCCESS
158+
159+
call NUOPC_ModelGet(model, modelClock=clock, &
160+
importState=importState, &
161+
exportState=exportState, rc=rc)
162+
ESMF_ERR_RETURN(rc)
163+
164+
call NUOPC_CompAttributeSet(model, &
165+
name="InitializeDataComplete", value="true", rc=rc)
166+
ESMF_ERR_RETURN(rc)
167+
168+
call ESMF_LogWrite(logmsgFlag=ESMF_LOGMSG_ERROR, &
169+
msg="MPAS NUOPC ATM - DataInitialize has not been implemented", &
170+
line=__LINE__, &
171+
file=__FILE__)
172+
173+
end subroutine DataInitialize
174+
175+
!-----------------------------------------------------------------------------
176+
177+
subroutine Advance(model, rc)
178+
!> Advance model by a single time step
179+
180+
! arguments
181+
type(ESMF_GridComp) :: model
182+
integer, intent(out) :: rc
183+
184+
! local variables
185+
type(ESMF_Clock) :: clock
186+
type(ESMF_State) :: importState, exportState
187+
188+
rc = ESMF_SUCCESS
189+
190+
call NUOPC_ModelGet(model, modelClock=clock, &
191+
importState=importState, &
192+
exportState=exportState, rc=rc)
193+
ESMF_ERR_RETURN(rc)
194+
195+
call ESMF_LogWrite(logmsgFlag=ESMF_LOGMSG_ERROR, &
196+
msg="MPAS NUOPC ATM - Advance has not been implemented", &
197+
line=__LINE__, &
198+
file=__FILE__)
199+
200+
end subroutine Advance
201+
202+
!-----------------------------------------------------------------------------
203+
204+
subroutine Finalize(model, rc)
205+
!> Finalize model and cleanup memory allocations
206+
207+
! arguments
208+
type(ESMF_GridComp) :: model
209+
integer, intent(out) :: rc
210+
211+
! local variables
212+
type(ESMF_State) :: importState, exportState
213+
214+
rc = ESMF_SUCCESS
215+
216+
call NUOPC_ModelGet(model, importState=importState, &
217+
exportState=exportState, rc=rc)
218+
ESMF_ERR_RETURN(rc)
219+
220+
call ESMF_LogWrite(logmsgFlag=ESMF_LOGMSG_ERROR, &
221+
msg="MPAS NUOPC ATM - Finalize has not been implemented", &
222+
line=__LINE__, &
223+
file=__FILE__)
224+
225+
end subroutine Finalize
226+
227+
!-----------------------------------------------------------------------------
228+
229+
end module mpas_nuopc_atm

src/core_init_atmosphere/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ core_input_gen:
4242
( cd default_inputs; $(NL_GEN) ../Registry_processed.xml namelist.init_atmosphere in_defaults=true )
4343
( cd default_inputs; $(ST_GEN) ../Registry_processed.xml streams.init_atmosphere stream_list.init_atmosphere. listed )
4444

45+
nuopc:
46+
@echo "************ ERROR ************"
47+
@echo "NUOPC build does not exist for the init_atmosphere core. Quitting."
48+
@echo "************ ERROR ************"
49+
@echo ""
50+
exit 1
51+
4552
gen_includes:
4653
$(CPP) $(CPPFLAGS) $(CPPINCLUDES) Registry.xml > Registry_processed.xml
4754
(if [ ! -d inc ]; then mkdir -p inc; fi) # To generate *.inc files

0 commit comments

Comments
 (0)