Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions src/core_atmosphere/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,35 @@

#
# To build a dycore-only MPAS-Atmosphere model, comment-out or delete
# the definition of PHYSICS, below
# the definition of PHYSICS and CHEMISTRY, below
#
# If MPAS_CAM_DYCORE is found in CPPFLAGS, PHYSICS will become undefined automatically
# If MPAS_CAM_DYCORE is found in CPPFLAGS, PHYSICS and CHEMISTRY will become undefined automatically
#
ifeq ($(findstring MPAS_CAM_DYCORE,$(CPPFLAGS)),)
PHYSICS = -DDO_PHYSICS
CHEMISTRY = -DDO_CHEMISTRY
endif

ifdef PHYSICS
PHYSCORE = physcore
PHYS_OBJS = libphys/*.o
endif

ifdef CHEMISTRY
CHEMCORE = chemcore
CHEM_OBJS = libchem/*.o
endif

OBJS = mpas_atm_core.o \
mpas_atm_core_interface.o \
mpas_atm_dimensions.o \
mpas_atm_threading.o \
mpas_atm_halos.o

all: $(PHYSCORE) dycore diagcore atmcore utilities
all: $(PHYSCORE) $(CHEMCORE) dycore diagcore atmcore utilities

core_reg:
$(CPP) $(CPPFLAGS) $(CPPINCLUDES) $(PHYSICS) Registry.xml > Registry_processed.xml
$(CPP) $(CPPFLAGS) $(CPPINCLUDES) $(PHYSICS) $(CHEMISTRY) Registry.xml > Registry_processed.xml

core_input_gen:
if [ ! -e default_inputs ]; then mkdir default_inputs; fi
Expand All @@ -47,17 +53,21 @@ physcore: mpas_atm_dimensions.o
( cd ../..; ln -sf ./src/core_atmosphere/physics/physics_wrf/files/*DATA* .)
( cd ../..; ln -sf ./src/core_atmosphere/physics/physics_noahmp/parameters/*TBL .)

dycore: mpas_atm_dimensions.o $(PHYSCORE)
( cd dynamics; $(MAKE) all PHYSICS="$(PHYSICS)" )
chemcore: mpas_atm_dimensions.o
( cd chemistry; $(MAKE) all )
( mkdir libchem; cd libchem; ar -x ../chemistry/libchem.a )

dycore: mpas_atm_dimensions.o $(PHYSCORE) $(CHEMCORE)
( cd dynamics; $(MAKE) all PHYSICS="$(PHYSICS)"; $(MAKE) all CHEMISTRY="$(CHEMISTRY)" )

diagcore: $(PHYSCORE) dycore
( cd diagnostics; $(MAKE) all PHYSICS="$(PHYSICS)" )
diagcore: $(PHYSCORE) $(CHEMCORE) dycore
( cd diagnostics; $(MAKE) all PHYSICS="$(PHYSICS)"; $(MAKE) all CHEMISTRY="$(CHEMISTRY)" )

utilities: $(PHYSCORE)
( cd utils; $(MAKE) all PHYSICS="$(PHYSICS)" )
utilities: $(PHYSCORE) $(CHEMCORE)
( cd utils; $(MAKE) all PHYSICS="$(PHYSICS)"; $(MAKE) all CHEMISTRY="$(CHEMISTRY)" )

atmcore: $(PHYSCORE) dycore diagcore $(OBJS)
ar -ru libdycore.a $(OBJS) dynamics/*.o $(PHYS_OBJS) diagnostics/*.o
atmcore: $(PHYSCORE) $(CHEMCORE) dycore diagcore $(OBJS)
ar -ru libdycore.a $(OBJS) dynamics/*.o $(PHYS_OBJS) $(CHEM_OBJS) diagnostics/*.o

mpas_atm_core_interface.o: mpas_atm_core.o

Expand All @@ -67,6 +77,7 @@ mpas_atm_dimensions.o:

clean:
( cd physics; $(MAKE) clean )
( cd chemistry; $(MAKE) clean )
( cd dynamics; $(MAKE) clean )
( cd diagnostics; $(MAKE) clean )
( cd utils; $(MAKE) clean )
Expand All @@ -84,7 +95,7 @@ clean:
$(RM) $@ $*.mod
ifeq "$(GEN_F90)" "true"
$(CPP) $(CPPFLAGS) $(PHYSICS) $(CPPINCLUDES) -I./inc $< > $*.f90
$(FC) $(FFLAGS) -c $*.f90 $(FCINCLUDES) -I../framework -I../operators -I./physics -I./dynamics -I./diagnostics -I./physics/physics_wrf -I./physics/physics_mmm -I./physics/physics_noaa/UGWP -I../external/esmf_time_f90
$(FC) $(FFLAGS) -c $*.f90 $(FCINCLUDES) -I../framework -I../operators -I./physics -I./dynamics -I./diagnostics -I./physics/physics_wrf -I./physics/physics_mmm -I./physics/physics_noaa/UGWP -I../external/esmf_time_f90 -I./chemistry
else
$(FC) $(CPPFLAGS) $(PHYSICS) $(FFLAGS) -c $*.F $(CPPINCLUDES) $(FCINCLUDES) -I./inc -I../framework -I../operators -I./physics -I./dynamics -I./diagnostics -I./physics/physics_wrf -I./physics/physics_mmm -I./physics/physics_noaa/UGWP -I../external/esmf_time_f90
$(FC) $(CPPFLAGS) $(PHYSICS) $(FFLAGS) -c $*.F $(CPPINCLUDES) $(FCINCLUDES) -I./inc -I../framework -I../operators -I./physics -I./dynamics -I./diagnostics -I./physics/physics_wrf -I./physics/physics_mmm -I./physics/physics_noaa/UGWP -I../external/esmf_time_f90 -I./chemistry
endif
41 changes: 41 additions & 0 deletions src/core_atmosphere/chemistry/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.SUFFIXES: .F .o

ifeq ($(CORE),atmosphere)
COREDEF = -Dmpas
endif

all:
./../tools/manage_externals/checkout_externals --externals ./../Externals.cfg
$(MAKE) core_mpas_musica core_chemistry

dummy:
echo "****** compiling chemistry ******"

OBJS = \
mpas_atm_chemistry.o

core_mpas_musica:
(cd musica; $(MAKE) all COREDEF="$(COREDEF)")

core_chemistry: core_mpas_musica
($(MAKE) chem_interface COREDEF="$(COREDEF)")
ar -ru libchem.a $(OBJS)
($(MAKE) -C ./musica mpas_musica_lib)

chem_interface: $(OBJS)

clean:
$(RM) *.o *.mod *.f90 libchem.a
( cd musica; $(MAKE) clean )
@# Certain systems with intel compilers generate *.i files
@# This removes them during the clean process
$(RM) *.i

.F.o:
$(RM) $@ $*.mod
ifeq "$(GEN_F90)" "true"
$(CPP) $(CPPFLAGS) $(COREDEF) $(HYDROSTATIC) $(CPPINCLUDES) $< > $*.f90
$(FC) $(FFLAGS) -c $*.f90 $(FCINCLUDES) -I./musica -I.. -I../../framework -I../../../external/esmf_time_f90
else
$(FC) $(CPPFLAGS) $(COREDEF) $(HYDROSTATIC) $(FFLAGS) -c $*.F $(CPPINCLUDES) $(FCINCLUDES) -I./musica -I.. -I../../framework -I../../../external/esmf_time_f90
endif
121 changes: 121 additions & 0 deletions src/core_atmosphere/chemistry/mpas_atm_chemistry.F
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
! Copyright (c) 2025 The University Corporation for Atmospheric Research (UCAR).
!
! Unless noted otherwise source code is licensed under the BSD license.
! Additional copyright and license information can be found in the LICENSE file
! distributed with this code, or at https://mpas-dev.github.io/license.html .
!
!-----------------------------------------------------------------------
! mpas_atm_chemistry
!
!> \brief Manages interactions with chemistry packages
!> \author CheMPAS-A Developers
!> \date 20 August 2025
!> \details
!> This module manages the interactions with chemistry packages,
!> including initialization, time-stepping, and finalization.
!> It provides a framework for integrating various chemistry models
!> into the CheMPAS-A system.
!
!-------------------------------------------------------------------------
module mpas_atm_chemistry

implicit none

private

public :: chemistry_init, chemistry_step, chemistry_finalize

contains

!------------------------------------------------------------------------
! routine mpas_atm_chemistry_init
!
!> \brief Initializes the chemistry packages
!> \author CheMPAS-A Developers
!> \date 20 August 2025
!> \details
!> This routine initializes the chemistry packages, setting up
!> necessary parameters and data structures for the simulation.
!------------------------------------------------------------------------
! subroutine chemistry_init(configs, number_of_grid_cells)
subroutine chemistry_init(number_of_grid_cells)

#ifdef MPAS_USE_MUSICA
use mpas_musica, only: musica_init
#endif
use mpas_log, only : mpas_log_write
use mpas_derived_types, only: mpas_pool_type
use mpas_kind_types, only: StrKIND
use mpas_pool_routines, only: mpas_pool_get_config

! type (mpas_pool_type), intent(in) :: configs
integer, intent(in) :: number_of_grid_cells

integer :: error_code
character(len=:), allocatable :: error_message
! character(len=StrKIND), pointer :: filepath
character(len=StrKIND) :: filepath

#ifdef MPAS_USE_MUSICA
! call mpas_pool_get_config(configs, 'config_micm_file', filepath)
filepath = 'chapman.json'

call mpas_log_write('Initializing chemistry packages...')
call musica_init(filepath, number_of_grid_cells, error_code, error_message)

! TODO check error_code and generate MPAS error log message
#endif

end subroutine chemistry_init


!------------------------------------------------------------------------
! routine mpas_atm_chemistry_step
!
!> \brief Steps the chemistry packages
!> \author CheMPAS-A Developers
!> \date 20 August 2025
!> \details
!> This routine steps the chemistry packages, updating their state
!> based on the current simulation time and conditions.
!------------------------------------------------------------------------
subroutine chemistry_step()

#ifdef MPAS_USE_MUSICA
use mpas_musica, only: musica_step
#endif
use mpas_log, only : mpas_log_write

#ifdef MPAS_USE_MUSICA
call mpas_log_write('Stepping chemistry packages...')
! call musica_step()
#endif

end subroutine chemistry_step


!------------------------------------------------------------------------
! routine mpas_atm_chemistry_finalize
!
!> \brief Finalizes the chemistry packages
!> \author CheMPAS-A Developers
!> \date 20 August 2025
!> \details
!> This routine finalizes the chemistry packages, cleaning up
!> any resources and data structures used during the simulation.
!------------------------------------------------------------------------
subroutine chemistry_finalize()

#ifdef MPAS_USE_MUSICA
use mpas_musica, only: musica_finalize
#endif
use mpas_log, only : mpas_log_write

#ifdef MPAS_USE_MUSICA
call mpas_log_write('Finalizing chemistry packages...')
call musica_finalize()
#endif

end subroutine chemistry_finalize

end module mpas_atm_chemistry
30 changes: 30 additions & 0 deletions src/core_atmosphere/chemistry/musica/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.SUFFIXES: .F .o

.PHONY: mpas_musica mpas_musica_lib

all: dummy mpas_musica

dummy:
echo "****** compiling mpas_musica ******"

OBJS = \
mpas_musica.o

mpas_musica: $(OBJS)

mpas_musica_lib:
ar -ru ./../libchem.a $(OBJS)

clean:
$(RM) *.f90 *.o *.mod
@# Certain systems with intel compilers generate *.i files
@# This removes them during the clean process
$(RM) *.i

.F.o:
ifeq "$(GEN_F90)" "true"
$(CPP) $(CPPFLAGS) $(COREDEF) $(CPPINCLUDES) $< > $*.f90
$(FC) $(FFLAGS) -c $*.f90 $(FCINCLUDES) -I.. -I../../../framework -I../../../external/esmf_time_f90
else
$(FC) $(CPPFLAGS) $(COREDEF) $(FFLAGS) -c $*.F $(CPPINCLUDES) $(FCINCLUDES) -I.. -I../../../framework -I../../../external/esmf_time_f90
endif
Loading