Skip to content
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ Thumbs.db

# Folders created with unit/functional tests
_build/
build/
_run/


Expand Down
37 changes: 24 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
cmake_minimum_required(VERSION 3.10)

# Determine HLM_ROOT path (compatible with CMake 3.10+)
if (NOT DEFINED HLM_ROOT)
if (NOT "$ENV{HLM_ROOT}" STREQUAL "")
set(HLM_ROOT "$ENV{HLM_ROOT}")
else()
set(HLM_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../")
endif()
endif()
get_filename_component(HLM_ROOT "${HLM_ROOT}" ABSOLUTE)

# Force the Fortran compiler to gfortran
set(CMAKE_Fortran_COMPILER gfortran)

list(APPEND CMAKE_MODULE_PATH ${CIME_CMAKE_MODULE_DIRECTORY})
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../../share/cmake")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../components/cmeps/cmake")
list(APPEND CMAKE_MODULE_PATH "${HLM_ROOT}/share/cmake")
list(APPEND CMAKE_MODULE_PATH "${HLM_ROOT}/components/cmeps/cmake")

FIND_PATH(NETCDFC_FOUND libnetcdf.a ${NETCDF_C_DIR}/lib)
FIND_PATH(NETCDFF_FOUND libnetcdff.a ${NETCDF_FORTRAN_DIR}/lib)
Expand All @@ -18,8 +31,6 @@ project(FATES_tests Fortran C)

include(CIME_utils)

set(HLM_ROOT "../../")

if (DEFINED ENV{ESMF_ROOT})
list(APPEND CMAKE_MODULE_PATH $ENV{ESMF_ROOT}/cmake)
endif()
Expand All @@ -42,16 +53,16 @@ add_subdirectory(${HLM_ROOT}/share/src csm_share)
add_subdirectory(${HLM_ROOT}/share/unit_test_stubs/util csm_share_stubs)

# Add FATES source directories
add_subdirectory(${HLM_ROOT}/src/fates/main fates_main)
add_subdirectory(${HLM_ROOT}/src/fates/biogeochem fates_biogeochem)
add_subdirectory(${HLM_ROOT}/src/fates/biogeophys fates_biogeophys)
add_subdirectory(${HLM_ROOT}/src/fates/parteh fates_parteh)
add_subdirectory(${HLM_ROOT}/src/fates/fire fates_fire)
add_subdirectory(${HLM_ROOT}/src/fates/radiation fates_radiation)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/main fates_main)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/biogeochem fates_biogeochem)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/biogeophys fates_biogeophys)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/parteh fates_parteh)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/fire fates_fire)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/radiation fates_radiation)

# Testing directories
add_subdirectory(${HLM_ROOT}/src/fates/testing/tests/fortran_shr test_share)
add_subdirectory(${HLM_ROOT}/src/fates/testing/tests/functional/fire/shr fire_share)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/testing/tests/fortran_shr test_share)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/testing/tests/functional/fire/shr fire_share)

# Remove shr_mpi_mod from share_sources.
# This is needed because we want to use the mock shr_mpi_mod in place of the real one
Expand Down Expand Up @@ -111,4 +122,4 @@ link_directories(${CMAKE_CURRENT_BINARY_DIR})
link_libraries(esmf)

# Add the main test directory
add_subdirectory(${HLM_ROOT}/src/fates/testing)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/testing)
1 change: 1 addition & 0 deletions biogeophys/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
list(APPEND fates_sources
EDAccumulateFluxesMod.F90
FatesHydroWTFMod.F90
LeafBiophysicsMod.F90
FatesLeafBiophysParamsMod.F90
Expand Down
12 changes: 6 additions & 6 deletions biogeophys/EDAccumulateFluxesMod.F90
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,20 @@ subroutine AccumulateFluxes_ED(nsites, sites, bc_in, bc_out, dt_time)
! Accumulate fluxes from hourly to daily values.
! _tstep fluxes are KgC/indiv/timestep _acc are KgC/indiv/day

ccohort%gpp_acc = ccohort%gpp_acc + ccohort%gpp_tstep
ccohort%resp_m_acc = ccohort%resp_m_acc + ccohort%resp_m_tstep

ccohort%sym_nfix_daily = ccohort%sym_nfix_daily + ccohort%sym_nfix_tstep

! weighted mean of D13C by gpp
if((ccohort%gpp_acc + ccohort%gpp_tstep) .eq. 0.0_r8) then
if((ccohort%gpp_acc + ccohort%gpp_tstep) <= 0.0_r8) then
ccohort%c13disc_acc = 0.0_r8
else
ccohort%c13disc_acc = ((ccohort%c13disc_acc * ccohort%gpp_acc) + &
(ccohort%c13disc_clm * ccohort%gpp_tstep)) / &
(ccohort%gpp_acc + ccohort%gpp_tstep)
endif

ccohort%gpp_acc = ccohort%gpp_acc + ccohort%gpp_tstep
ccohort%resp_m_acc = ccohort%resp_m_acc + ccohort%resp_m_tstep

ccohort%sym_nfix_daily = ccohort%sym_nfix_daily + ccohort%sym_nfix_tstep

do iv=1,ccohort%nv
if(ccohort%year_net_uptake(iv) == 999._r8)then ! note that there were leaves in this layer this year.
ccohort%year_net_uptake(iv) = 0._r8
Expand Down
1 change: 1 addition & 0 deletions testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ add_subdirectory(tests/unit/count_cohorts_test fates_count_cohorts_utest)
add_subdirectory(tests/unit/fire_equations_test fates_fire_equations_utest)
add_subdirectory(tests/unit/quadratic_roots_test fates_quadratic_roots_utest)
add_subdirectory(tests/unit/great_circle_test fates_great_circle_utest)
add_subdirectory(tests/unit/ed_accumulate_fluxes_test ed_accumulate_fluxes_test)
2 changes: 2 additions & 0 deletions testing/config/unit.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ test_dir = fates_quadratic_roots_utest
[great_circle]
test_dir = fates_great_circle_utest

[ed_accumulate_fluxes]
test_dir = ed_accumulate_fluxes_test
9 changes: 6 additions & 3 deletions testing/framework/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,11 @@ def _generate_cmake_args(self, machobj):

def _find_libraries(self):
"""Locates PFUNIT and NETCDF paths."""
self.config.pfunit_path = self._query_makefile_var("PFUNIT_PATH")
self.config.pfunit_path = self._query_makefile_var("PFUNIT_PATH") or os.environ.get("PFUNIT_PATH")

if "NETCDF" not in os.environ:
self.config.netcdf_c_path = self._query_makefile_var("NETCDF_C_PATH")
self.config.netcdf_f_path = self._query_makefile_var("NETCDF_FORTRAN_PATH")
self.config.netcdf_c_path = self._query_makefile_var("NETCDF_C_PATH") or os.environ.get("NETCDF_C_PATH")
self.config.netcdf_f_path = self._query_makefile_var("NETCDF_FORTRAN_PATH") or os.environ.get("NETCDF_FORTRAN_PATH")

def _query_makefile_var(self, var_name: str) -> Optional[str]:
"""Helper to query variables from CIME makefile generation
Expand Down Expand Up @@ -233,6 +233,7 @@ def build_tests(
make_j: int,
clean: bool = False,
verbose: bool = False,
mpilib: str = _MPI_LIBRARY,
):
"""Wrapper function for building tests

Expand All @@ -242,13 +243,15 @@ def build_tests(
make_j (int): number of processes to build with
clean (bool, optional): whether or not to clean the build. Defaults to False.
verbose (bool, optional): build with verbose make. Defaults to False.
mpilib (str, optional): mpilib to use for building. Defaults to _MPI_LIBRARY.
"""
config = BuildConfig(
build_dir=build_dir,
cmake_dir=cmake_dir,
make_j=make_j,
clean=clean,
verbose=verbose,
mpilib=mpilib or _MPI_LIBRARY,
)
builder = TestBuilder(config)
builder.build()
17 changes: 15 additions & 2 deletions testing/framework/utils/path.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Utility functions related to getting paths to various important places"""

import os
import sys
import importlib
from pathlib import Path
Expand Down Expand Up @@ -38,12 +39,24 @@ def path_to_cime() -> Path:
RuntimeError: can't find path to cime

Returns:
str: full path to cime
Path: full path to cime
"""
# 1. Check HLM_ROOT environment variable if set
hlm_root = os.environ.get("HLM_ROOT")
if hlm_root:
cime_path = (Path(hlm_root) / "cime").resolve()
if cime_path.is_dir():
return cime_path

# 2. Fallback to nested location relative to FATES root
cime_path = (path_to_fates_root() / "../../cime").resolve()
if cime_path.is_dir():
return cime_path
raise RuntimeError("Cannot find cime.")

raise RuntimeError(
"Cannot find cime. Please define the HLM_ROOT environment variable "
"pointing to the parent of your local CIME directory."
)


def path_to_fates_root() -> Path:
Expand Down
11 changes: 10 additions & 1 deletion testing/run_unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ def commandline_args():
"--verbose", action="store_true", help="Run make with verbose output."
)

parser.add_argument(
"--mpilib",
type=str,
default=None,
help="MPI library to use (e.g. 'mpi-serial', 'mpich'). Overrides the MPILIB\n"
"environment variable. Defaults to the MPILIB env var, or 'mpi-serial'.\n",
)

parser.add_argument(
"-t",
"--test-list",
Expand Down Expand Up @@ -109,7 +117,8 @@ def main():

# build tests
build_tests(
build_dir, _CMAKE_BASE_DIR, args.make_j, clean=args.clean, verbose=args.verbose
build_dir, _CMAKE_BASE_DIR, args.make_j, clean=args.clean, verbose=args.verbose,
mpilib=args.mpilib,
)

# run unit tests
Expand Down
5 changes: 5 additions & 0 deletions testing/tests/unit/ed_accumulate_fluxes_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(pfunit_sources test_EDAccumulateFluxes.pf)

add_pfunit_ctest(EDAccumulateFluxes
TEST_SOURCES "${pfunit_sources}"
LINK_LIBRARIES fates csm_share)
Loading