Skip to content
Draft
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
3 changes: 2 additions & 1 deletion applications/jules/build/compile_options.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ $(info UM physics specific compile options)

include $(PROJECT_DIR)/build/fortran/$(FORTRAN_COMPILER).mk

science/%.o: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
casim/%.o: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
ukca/%.o: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
jules/%.o: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
socrates/%.o: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
legacy/%.o: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
Expand Down
2 changes: 1 addition & 1 deletion applications/lfric_atm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ build: export BIN_DIR ?= $(PROJECT_DIR)/bin
build: export CXX_LINK = YES
build: export PROGRAMS := $(basename $(notdir $(shell find source -maxdepth 1 -name '*.[Ff]90' -exec egrep -l "^\s*program" {} \;)))
build: export PROJECT = lfric_atm
build: export SCRATCH_DIR := $(WORKING_DIR)/../physics_scratch
build: export SCRATCH_DIR := $(WORKING_DIR)/..
build: export WORKING_DIR := $(WORKING_DIR)

build: export LDFLAGS_GROUPS = OPENMP
Expand Down
3 changes: 2 additions & 1 deletion applications/lfric_atm/build/compile_options.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ $(info UM physics specific compile options)

include $(PROJECT_DIR)/build/fortran/$(FORTRAN_COMPILER).mk

science/%.o: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
casim/%.o: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
ukca/%.o: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
jules/%.o: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
socrates/%.o: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
legacy/%.o: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
Expand Down
31 changes: 31 additions & 0 deletions applications/lfric_atm/metadata/lfric_dictionary.xml
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@
<field id="tile_fraction" name="tile_fraction" long_name="surface_tile_fraction" unit="1" domain_ref="face" axis_ref="surface_tiles" />
<field id="tile_temperature" name="tile_temperature" long_name="surface_tile_temperature" unit="K" domain_ref="face" axis_ref="surface_tiles" />
<field id="tile_lw_grey_albedo" name="tile_lw_grey_albedo" long_name="surface_tile_lw_grey_albedo" unit="1" domain_ref="face" axis_ref="surface_tiles" />
<field id="tile_moisture_flux" name="tile_moisture_flux" long_name="tile_moisture_flux" unit="kg m-2 s-1" domain_ref="face" axis_ref="surface_tiles"/>
<field id="snowice_melt" name="snowice_melt" long_name="snowice_melt" unit="kg m-2 s-1" domain_ref="face" axis_ref="surface_tiles"/>
<field id="surf_ht_flux" name="surf_ht_flux" long_name="surf_ht_flux" unit="W m-2" domain_ref="face" axis_ref="surface_tiles"/>
<field id="snowice_sublimation" name="snowice_sublimation" long_name="snowice_sublimation" unit="kg m-2 s-1" domain_ref="face" axis_ref="surface_tiles"/>
<field id="screen_temperature" name="screen_temperature" long_name="screen_temperature_on_tiles" unit="K" domain_ref="face" axis_ref="surface_tiles" />
<field id="time_since_transition" name="time_since_transition" long_name="time_since_decoupled_screen_transition" unit="s" domain_ref="face" />
<field id="canopy_water" name="canopy_water" long_name="canopy_water_content_on_tiles" unit="kg m-2" domain_ref="face" axis_ref="surface_tiles" />
Expand All @@ -288,6 +292,7 @@
<field id="albedo_obs_scaling" name="albedo_obs_scaling" long_name="albedo_obs_scaling" unit="1" domain_ref="face" axis_ref="land_tile_rad_band" />
<field id="sea_ice_thickness" name="sea_ice_thickness" long_name="sea_ice_thickness" unit="m" domain_ref="face" axis_ref="sea_ice_categories" />
<field id="sea_ice_temperature" name="sea_ice_temperature" long_name="sea_ice_bulk_temperature" unit="K" domain_ref="face" axis_ref="sea_ice_categories" />
<field id="sea_ice_pensolar" name="sea_ice_pensolar" long_name="sea_ice_pensolar" unit="W m-2" domain_ref="face" axis_ref="sea_ice_categories"/>
<field id="sea_surf_temp_pert" name="sea_surf_temp_pert" long_name="sea_surface_temperature_perturbation" unit="K" domain_ref="face" />
<field id="internal_flux" name="internal_flux" long_name="internal_flux" unit="W m-2" domain_ref="face" />
<!-- orography fields -->
Expand Down Expand Up @@ -393,5 +398,31 @@
<field id="frozen_soil_moisture" name="frozen_soil_moisture" long_name="mass_fraction_of_frozen_water_in_saturated_soil_moisture" unit="1" domain_ref="face" axis_ref="soil_levels" />
<!-- energy correction -->
<field id="temperature_correction_rate" name="temperature_correction_rate" long_name="temperature_rate_for_energy_correction" unit="K s-1" axis_ref="scalar_axis" />
<field id="lf_icefrc" name="lf_icefrc" long_name="lf_icefrc" unit="1" domain_ref="face" axis_ref="sea_ice_categories" />
<field id="lf_icetck" name="lf_icetck" long_name="lf_icetck" unit="m" domain_ref="face" axis_ref="sea_ice_categories" />
<field id="lf_icelayert" name="lf_icelayert" long_name="lf_icelayert" unit="m" domain_ref="face" axis_ref="sea_ice_categories" />
<field id="lf_ocn_sst" name="lf_ocn_sst" long_name="lf_ocn_sst" unit="K" domain_ref="face" />
<field id="lf_taux" name="lf_taux" long_name="lf_taux" unit="m" domain_ref="face" />
<field id="lf_tauy" name="lf_tauy" long_name="lf_tauy" unit="m" domain_ref="face" />
<field id="lf_solar" name="lf_solar" long_name="lf_solar" unit="m" domain_ref="face" />
<field id="lf_heatflux" name="lf_heatflux" long_name="lf_heatflux" unit="m" domain_ref="face" />
<field id="lf_train" name="lf_train" long_name="lf_train" unit="m" domain_ref="face" />
<field id="lf_tsnow" name="lf_tsnow" long_name="lf_tsnow" unit="" domain_ref="face" />
<field id="lf_w10" name="lf_w10" long_name="lf_w10" unit="" domain_ref="face" />
<field id="lf_rsurf" name="lf_rsurf" long_name="lf_rsurf" unit="kg m-2 s-1" domain_ref="face" />
<field id="lf_rsub" name="lf_rsub" long_name="lf_rsub" unit="kg m-2 s-1" domain_ref="face" />
<field id="lf_evap" name="lf_evap" long_name="lf_evap" unit="kg m-2 s-1" domain_ref="face" />
<field id="lf_topmelt" name="lf_topmelt" long_name="lf_topmelt" unit="W m-2" domain_ref="face" axis_ref="sea_ice_categories" />
<field id="lf_iceheatflux" name="lf_iceheatflux" long_name="lf_iceheatflux" unit="W m-2" domain_ref="face" axis_ref="sea_ice_categories" />
<field id="lf_sublimation" name="lf_sublimation" long_name="lf_sublimation" unit="kg m-2 s-1" domain_ref="face" axis_ref="sea_ice_categories" />
<field id="lf_iceskint" name="lf_iceskint" long_name="lf_iceskint" unit="K" domain_ref="face" axis_ref="sea_ice_categories" />
<field id="lf_pensolar" name="lf_pensolar" long_name="lf_pensolar" unit="W m-2" domain_ref="face" axis_ref="sea_ice_categories" />
<field id="lf_conductivity" name="lf_conductivity" long_name="lf_conductivity" unit="W m-2 K-1" domain_ref="face" axis_ref="sea_ice_categories" />
<field id="lf_snow_depth" name="lf_snow_depth" long_name="snow depth on sea ice" unit="m" domain_ref="face" axis_ref="sea_ice_categories" />
<field id="lf_pond_frac" name="lf_pond_frac" long_name="lf_pond_frac" unit="1" domain_ref="face" axis_ref="sea_ice_categories" />
<field id="lf_pond_depth" name="lf_pond_depth" long_name="lf_pond_depth" unit="m" domain_ref="face" axis_ref="sea_ice_categories" />
<field id="lf_sunocean" name="lf_sunocean" long_name="lf_sunocean" unit="ms-1" domain_ref="face" />
<field id="lf_svnocean" name="lf_svnocean" long_name="lf_svnocean" unit="ms-1" domain_ref="face" />

</field_group>
</field_definition>
2 changes: 1 addition & 1 deletion applications/lfric_coupled/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ document-api: api-documentation
build: export BIN_DIR ?= $(PROJECT_DIR)/bin
build: export CXX_LINK = TRUE
build: export PROGRAMS := $(basename $(notdir $(shell find source -maxdepth 1 -name '*.[Ff]90' -print)))
build: export SCRATCH_DIR := $(WORKING_DIR)/../physics_scratch
build: export SCRATCH_DIR := $(WORKING_DIR)/..
build: export PROJECT = $(PROJECT_NAME)
build: export WORKING_DIR := $(WORKING_DIR)/$(PROJECT_NAME)

Expand Down
3 changes: 2 additions & 1 deletion applications/lfric_coupled/build/compile_options.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ $(info UM physics specific compile options for $(FORTRAN_COMPILER) compiler)

include $(PROJECT_DIR)/build/fortran/$(FORTRAN_COMPILER).mk

science/%.o science/%.mod: private FFLAGS_EXTRA += $(FFLAGS_UM_PHYSICS)
casim/%.o science/%.mod: private FFLAGS_EXTRA += $(FFLAGS_UM_PHYSICS)
ukca/%.o science/%.mod: private FFLAGS_EXTRA += $(FFLAGS_UM_PHYSICS)
jules/%.o jules/%.mod: private FFLAGS_EXTRA += $(FFLAGS_UM_PHYSICS)
socrates/%.o socrates/%.mod: private FFLAGS_EXTRA += $(FFLAGS_UM_PHYSICS)
legacy/%.o legacy/%.mod: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
Expand Down
2 changes: 1 addition & 1 deletion applications/ngarch/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ document-api: api-documentation
build: export BIN_DIR ?= $(PROJECT_DIR)/bin
build: export CXX_LINK = TRUE
build: export PROGRAMS := $(basename $(notdir $(shell find source -maxdepth 1 -name '*.[Ff]90' -print)))
build: export SCRATCH_DIR := $(WORKING_DIR)/../physics_scratch
build: export SCRATCH_DIR := $(WORKING_DIR)/..
build: export PROJECT = $(PROJECT_NAME)
build: export WORKING_DIR := $(WORKING_DIR)

Expand Down
3 changes: 2 additions & 1 deletion applications/ngarch/build/compile_options.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ $(info UM physics specific compile options)

include $(PROJECT_DIR)/build/fortran/$(FORTRAN_COMPILER).mk

science/%.o science/%.mod: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
casim/%.o science/%.mod: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
ukca/%.o science/%.mod: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
jules/%.o jules/%.mod: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
socrates/%.o socrates/%.mod: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
legacy/%.o legacy/%.mod: private FFLAGS_EXTRA = $(FFLAGS_UM_PHYSICS)
Expand Down
5 changes: 1 addition & 4 deletions build/extract/extract_physics.mk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,4 @@

extract:
# Retrieve and preprocess the UKCA and CASIM code
python $(APPS_ROOT_DIR)/build/extract/extract_science.py -d $(APPS_ROOT_DIR)/dependencies.yaml -w $(SCRATCH_DIR) -e $(APPS_ROOT_DIR)/build/extract/extract.yaml
$Qrsync -acvz $(SCRATCH_DIR)/ukca $(WORKING_DIR)/science/
$Qrsync -acvz $(SCRATCH_DIR)/casim $(WORKING_DIR)/science/

python $(APPS_ROOT_DIR)/build/extract/extract_science.py -d $(APPS_ROOT_DIR)/dependencies.yaml -w $(WORKING_DIR) -e $(APPS_ROOT_DIR)/build/extract/extract.yaml
130 changes: 46 additions & 84 deletions build/extract/extract_science.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,12 @@
import argparse
import subprocess
import os
import tempfile
import yaml
from shutil import rmtree
from pathlib import Path
from typing import Dict, List
from get_git_sources import clone_and_merge, run_command
import logging


def run_command(command):
"""
Run a subprocess command and check output
Inputs:
- command, str with command to run
"""
command = command.split()
result = subprocess.run(
command,
capture_output=True,
text=True,
timeout=120,
shell=False,
check=False,
)
if result.returncode:
raise RuntimeError(
f"The command '{command}' failed with error:\n\n{result.stderr}"
)


def load_yaml(fpath: Path) -> Dict:
def load_yaml(fpath: Path) -> dict:
"""
Read in the dependencies.yaml file
"""
Expand All @@ -40,56 +17,45 @@ def load_yaml(fpath: Path) -> Dict:
return sources


def clone_dependency(values: Dict, temp_dep: Path) -> None:
"""
Clone the physics dependencies into a temporary directory
"""

source = values["source"]
ref = values["ref"]

commands = (
f"git -C {temp_dep} init",
f"git -C {temp_dep} remote add origin {source}",
f"git -C {temp_dep} fetch origin {ref}",
f"git -C {temp_dep} checkout FETCH_HEAD"
)
for command in commands:
run_command(command)


def extract_files(dependency: str, values: Dict, files: List[str], working: Path):
def extract_files(dependencies: dict, extract_lists: dict, working: Path) -> None:
"""
Clone the dependency to a temporary location
Then copy the desired files to the working directory
Then delete the temporary directory
"""

tempdir = Path(tempfile.mkdtemp())
if (
"PHYSICS_ROOT" not in os.environ
or not Path(os.environ["PHYSICS_ROOT"]).exists()
):
temp_dep = tempdir / dependency
temp_dep.mkdir(parents=True)
clone_dependency(values, temp_dep)
else:
temp_dep = Path(os.environ["PHYSICS_ROOT"]) / dependency

working_dep = working / dependency

# make the working directory location
working_dep.mkdir(parents=True)

for extract_file in files:
source_file = temp_dep / extract_file
dest_file = working_dep / extract_file
run_command(f"mkdir -p {dest_file.parents[0]}")
copy_command = f"cp -r {source_file} {dest_file}"
mirror_loc = os.getenv("MIRROR_LOC", "")
use_mirrors = bool(mirror_loc)
mirror_loc = Path(mirror_loc)

for dependency, sources in dependencies.items():
if dependency not in extract_lists:
continue
files = extract_lists[dependency]

# If the PHYSICS_ROOT environment variable is provided, then use sources there
if "PHYSICS_ROOT" in os.environ and Path(os.environ["PHYSICS_ROOT"]).exists():
clone_loc = Path(os.environ["PHYSICS_ROOT"]) / dependency
else:
clone_loc = working.parent / "scratch" / dependency
clone_and_merge(dependency, sources, clone_loc, use_mirrors, mirror_loc)

# make the working directory location
working_dir = working / dependency
working_dir.mkdir(parents=True, exist_ok=True)

# rsync extract files from clone loc to the working directory
copy_command = "rsync --include='**/' "
for extract_file in files:
if not extract_file:
continue
if Path(clone_loc / extract_file).is_dir():
extract_file = extract_file.rstrip("/")
extract_file += "/**"
copy_command += f"--include='{extract_file}' "
copy_command += f"--exclude='*' -avmq {clone_loc}/ {working_dir}"
run_command(copy_command)

rmtree(tempdir)


def parse_args() -> argparse.Namespace:
"""
Expand All @@ -101,34 +67,30 @@ def parse_args() -> argparse.Namespace:
"-d",
"--dependencies",
default="./dependencies.yaml",
help="The dependencies file for the apps working copy.",
)
parser.add_argument(
"-w", "--working", default=".", help="Location to perform extract steps in."
help="The dependencies file for the apps working copy",
)
parser.add_argument("-w", "--working", default=".", help="Build location")
parser.add_argument(
"-e",
"--extract",
default="./extract.yaml",
help="Path to file containing extract lists",
)
return parser.parse_args()

args = parser.parse_args()
args.working = Path(args.working)
return args


def main():
args: argparse.Namespace = parse_args()

extract_lists: Dict = load_yaml(args.extract)
dependencies: Dict = load_yaml(args.dependencies)

for dependency in dependencies:
if dependency in extract_lists:
extract_files(
dependency,
dependencies[dependency],
extract_lists[dependency],
Path(args.working),
)
logging.basicConfig(level=logging.INFO)

extract_lists: dict = load_yaml(args.extract)
dependencies: dict = load_yaml(args.dependencies)

extract_files(dependencies, extract_lists, args.working)


if __name__ == "__main__":
Expand Down
Loading
Loading