Skip to content

Commit 6e59e0e

Browse files
author
In-Woo Park
committed
Merge branch 'main' into plot
2 parents 7518f1b + 5573a54 commit 6e59e0e

File tree

20 files changed

+255
-87
lines changed

20 files changed

+255
-87
lines changed

.github/workflows/common-workflow.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ on:
2727
python_version:
2828
required: false
2929
type: string
30+
3031
env:
3132
ISSM_DIR: ${{ github.workspace }}
3233

.github/workflows/ubuntu-basic.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,29 @@ name: Ubuntu Basic
33
on:
44
push:
55
branches: [ "main" ]
6+
paths:
7+
- ".github/workflows/common-workflow.yml"
8+
- ".github/workflows/ubuntu-basic.yml"
9+
- "etc/**"
10+
- "externalpackages/**"
11+
- "m4/**"
12+
- "src/**"
13+
- "test/**"
14+
- "Makefile.am"
15+
- "configure.ac"
616
pull_request:
717
branches: [ "main" ]
18+
paths:
19+
- ".github/workflows/common-workflow.yml"
20+
- ".github/workflows/ubuntu-basic.yml"
21+
- "etc/**"
22+
- "externalpackages/**"
23+
- "m4/**"
24+
- "src/**"
25+
- "test/**"
26+
- "Makefile.am"
27+
- "configure.ac"
28+
829
env:
930
ISSM_DIR: ${{ github.workspace }}
1031

.github/workflows/ubuntu-codipack.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,29 @@ name: Ubuntu CodiPack
33
on:
44
push:
55
branches: [ "main" ]
6+
paths:
7+
- ".github/workflows/common-workflow.yml"
8+
- ".github/workflows/ubuntu-codipack.yml"
9+
- "etc/**"
10+
- "externalpackages/**"
11+
- "m4/**"
12+
- "src/**"
13+
- "test/**"
14+
- "Makefile.am"
15+
- "configure.ac"
616
pull_request:
717
branches: [ "main" ]
18+
paths:
19+
- ".github/workflows/common-workflow.yml"
20+
- ".github/workflows/ubuntu-codipack.yml"
21+
- "etc/**"
22+
- "externalpackages/**"
23+
- "m4/**"
24+
- "src/**"
25+
- "test/**"
26+
- "Makefile.am"
27+
- "configure.ac"
28+
829
env:
930
ISSM_DIR: ${{ github.workspace }}
1031

.github/workflows/ubuntu-python.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,29 @@ name: Ubuntu Python
33
on:
44
push:
55
branches: [ "main" ]
6+
paths:
7+
- ".github/workflows/common-workflow.yml"
8+
- ".github/workflows/ubuntu-python.yml"
9+
- "etc/**"
10+
- "externalpackages/**"
11+
- "m4/**"
12+
- "src/**"
13+
- "test/**"
14+
- "Makefile.am"
15+
- "configure.ac"
616
pull_request:
717
branches: [ "main" ]
18+
paths:
19+
- ".github/workflows/common-workflow.yml"
20+
- ".github/workflows/ubuntu-basic.yml"
21+
- "etc/**"
22+
- "externalpackages/**"
23+
- "m4/**"
24+
- "src/**"
25+
- "test/**"
26+
- "Makefile.am"
27+
- "configure.ac"
28+
829
env:
930
ISSM_DIR: ${{ github.workspace }}
1031

configure.ac

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,71 @@ AM_PROG_AR
2929
#Libtool
3030
LT_INIT([win32-dll])
3131

32-
#Run issm_options.m4
32+
# =====================================================================
33+
# Automatic-Differentiation switches
34+
# =====================================================================
35+
AC_ARG_ENABLE([ad],
36+
AS_HELP_STRING([--enable-ad],
37+
[Build ISSM with CoDiPack+MediPack (disables PETSc)]),
38+
[enable_ad=$enableval],
39+
[enable_ad=no])
40+
41+
AC_ARG_WITH([codipack-dir],
42+
AS_HELP_STRING([--with-codipack-dir=DIR], [Prefix of CoDiPack install]),
43+
[CODIPACK_DIR=$withval],
44+
[CODIPACK_DIR=])
45+
46+
AC_ARG_WITH([medipack-dir],
47+
AS_HELP_STRING([--with-medipack-dir=DIR], [Prefix of MediPack install]),
48+
[MEDIPACK_DIR=$withval],
49+
[MEDIPACK_DIR=])
50+
51+
# --- Validation & flag embedding -------------------------------------
52+
if test "x$enable_ad" = "xyes"; then
53+
if test -z "$CODIPACK_DIR" || test -z "$MEDIPACK_DIR"; then
54+
AC_MSG_ERROR([--enable-ad needs BOTH --with-codipack-dir and --with-medipack-dir])
55+
fi
56+
57+
# Tell source files we are in AD mode
58+
AC_DEFINE([ISSM_USE_AD], [1], [Define to 1 if building with automatic differentiation])
59+
60+
# Drop PETSc automatically (picked up by m4/issm_options.m4)
61+
ENABLE_PETSC=no
62+
AM_CONDITIONAL([USE_AD], [true])
63+
else
64+
ENABLE_PETSC=yes
65+
AM_CONDITIONAL([USE_AD], [false])
66+
fi
67+
68+
dnl ---- Embed include-paths, lib-paths & libs globally -----------------
69+
if test "x$enable_ad" = "xyes"; then
70+
AM_CPPFLAGS="$AM_CPPFLAGS -I$CODIPACK_DIR/include -I$MEDIPACK_DIR/include -DCODI_ForcedInlines"
71+
AM_LDFLAGS="$AM_LDFLAGS -L$CODIPACK_DIR/lib -L$MEDIPACK_DIR/lib"
72+
LIBS="$LIBS -lcodi -lmedi"
73+
fi
74+
75+
dnl Export the variables so Automake can substitute them
76+
AC_SUBST([AM_CPPFLAGS])
77+
AC_SUBST([AM_LDFLAGS])
78+
AC_SUBST([LIBS])
79+
80+
# ---------------------------------------------------------------------
81+
# Run ISSM’s usual option-detection macro collection
82+
# ---------------------------------------------------------------------
3383
ISSM_OPTIONS
3484

35-
#List all Makefiles
85+
# ---------------------------------------------------------------------
86+
# Output files
87+
# ---------------------------------------------------------------------
3688
AC_CONFIG_FILES([
37-
Makefile
38-
src/Makefile
39-
src/c/Makefile
40-
src/wrappers/Makefile
41-
src/wrappers/python/Makefile
42-
src/wrappers/matlab/Makefile
43-
src/wrappers/javascript/Makefile
44-
src/m/Makefile
89+
Makefile
90+
src/Makefile
91+
src/c/Makefile
92+
src/m/Makefile
93+
src/wrappers/Makefile
94+
src/wrappers/python/Makefile
95+
src/wrappers/matlab/Makefile
96+
src/wrappers/javascript/Makefile
4597
])
4698

47-
#End of configure.ac
4899
AC_OUTPUT

etc/environment.sh

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22
# have been installed.
33
#
44
# ISSM_DIR and ISSM_ARCH should have been defined already in your shell
5-
# settings file (i.e. .bashrc, .cshrc).
5+
# settings file (i.e., .bashrc, .zshrc, .cshrc).
66
#
77
# NOTE:
88
# - We use <PKG>_ROOT_TEMP variables because all variables are exported to
99
# environment when this script is source'd. In some cases, this may cause
1010
# conflicts (e.g. on Pleiades, we use the module copy of PETSc, which
1111
# defines PETSC_ROOT).
12-
#
1312

13+
# Silence `zsh: no matches found: <file>`
1414
if [[ -n "$ZSH_VERSION" ]]; then
15-
# Silence `zsh: no matches found: <file>`
1615
setopt +o nomatch 1> /dev/null 2>&1
1716
fi
1817

1918
## Functions
20-
#
2119
c_include_path_append(){ #{{{
2220
if [ -d "${1}" ]; then
2321
if [ -z "${C_INCLUDE_PATH}" ]; then
@@ -36,7 +34,6 @@ c_include_path_prepend(){ #{{{
3634
fi
3735
fi
3836
} #}}}
39-
4037
cpath_append(){ #{{{
4138
if [ -d "${1}" ]; then
4239
if [ -z "${CPATH}" ]; then
@@ -55,7 +52,6 @@ cpath_prepend(){ #{{{
5552
fi
5653
fi
5754
} #}}}
58-
5955
cplus_include_path_append(){ #{{{
6056
if [ -d "${1}" ]; then
6157
if [ -z "${CPLUS_INCLUDE_PATH}" ]; then
@@ -74,7 +70,6 @@ cplus_include_path_prepend(){ #{{{
7470
fi
7571
fi
7672
} #}}}
77-
7873
dyld_library_path_append(){ #{{{
7974
if [ -d "${1}" ]; then
8075
if [ -z "${DYLD_LIBRARY_PATH}" ]; then
@@ -89,7 +84,6 @@ dyld_library_path_append(){ #{{{
8984
fi
9085
fi
9186
} #}}}
92-
9387
dyld_library_path_prepend(){ #{{{
9488
if [ -d "${1}" ]; then
9589
if [ -z "${DYLD_LIBRARY_PATH}" ]; then
@@ -104,7 +98,6 @@ dyld_library_path_prepend(){ #{{{
10498
fi
10599
fi
106100
} #}}}
107-
108101
ld_library_path_append(){ #{{{
109102
if [ -d "${1}" ]; then
110103
if [ -z "${LD_LIBRARY_PATH}" ]; then
@@ -119,7 +112,6 @@ ld_library_path_append(){ #{{{
119112
fi
120113
fi
121114
} #}}}
122-
123115
ld_library_path_prepend(){ #{{{
124116
if [ -d "${1}" ]; then
125117
if [ -z "${LD_LIBRARY_PATH}" ]; then
@@ -134,7 +126,6 @@ ld_library_path_prepend(){ #{{{
134126
fi
135127
fi
136128
} #}}}
137-
138129
library_path_append(){ #{{{
139130
if [ -d "${1}" ]; then
140131
if [ -z "${LIBRARY_PATH}" ]; then
@@ -144,7 +135,6 @@ library_path_append(){ #{{{
144135
fi
145136
fi
146137
} #}}}
147-
148138
library_path_prepend(){ #{{{
149139
if [ -d "${1}" ]; then
150140
if [ -z "${LIBRARY_PATH}" ]; then
@@ -154,7 +144,6 @@ library_path_prepend(){ #{{{
154144
fi
155145
fi
156146
} #}}}
157-
158147
path_append(){ #{{{
159148
if [ -d "${1}" ] && [[ ":${PATH}:" != *":${1}:"* ]]; then
160149
PATH_IN="${1}"
@@ -164,7 +153,6 @@ path_append(){ #{{{
164153
export PATH="${PATH}:${PATH_IN}"
165154
fi
166155
} #}}}
167-
168156
path_prepend(){ #{{{
169157
if [ -d "${1}" ] && [[ ":${PATH}:" != *":${1}:"* ]]; then
170158
PATH_IN="${1}"
@@ -178,11 +166,10 @@ path_prepend(){ #{{{
178166
path_append "${ISSM_DIR}/aux-config"
179167
path_append "${ISSM_DIR}/scripts"
180168

181-
# Default path to external packages. Redefine this constant if they are
182-
# installed to a different directory. Alternatively, export it on the command
183-
# line or in a profile initialization file (that is why we check here if it is
169+
# Default path to external packages. Redefine this constant if they are
170+
# installed to a different directory. Alternatively, export it on the command
171+
# line or in a profile initialization file (that is why we check here if it is
184172
# set already).
185-
#
186173
if [ -z "${ISSM_EXT_DIR+x}" ]; then
187174
export ISSM_EXT_DIR="${ISSM_DIR}/externalpackages"
188175
fi

scripts/patch_bin.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python3
2+
import argparse, struct, pathlib
3+
from typing import Union
4+
5+
FMT2CODE = {"bool":1,"int":2,"double":3}
6+
7+
def locate(fp, field):
8+
with fp.open('rb') as f:
9+
while (raw:=f.read(4)):
10+
namelen = struct.unpack('i', raw)[0]
11+
name = f.read(namelen).decode()
12+
reclen = struct.unpack('q', f.read(8))[0]
13+
codepos = f.tell(); code = struct.unpack('i', f.read(4))[0]
14+
datapos = f.tell()
15+
if name == field: return datapos, code
16+
f.seek(reclen-4,1)
17+
raise KeyError(field)
18+
19+
def patch(fp: pathlib.Path, field: str, value: Union[str,int,float]):
20+
datapos, code = locate(fp, field)
21+
with fp.open('r+b') as f:
22+
f.seek(datapos)
23+
if code==FMT2CODE["double"]:
24+
f.write(struct.pack('d', float(value)))
25+
elif code==FMT2CODE["int"]:
26+
f.write(struct.pack('i', int(value)))
27+
elif code==FMT2CODE["bool"]:
28+
f.write(struct.pack('i', 1 if value.lower()=='true' else 0))
29+
else:
30+
raise TypeError("Only scalar bool/int/double supported in-place")
31+
32+
if __name__ == "__main__":
33+
p = argparse.ArgumentParser()
34+
p.add_argument("-f","--file", required=True)
35+
p.add_argument("-n","--name", required=True)
36+
p.add_argument("-v","--value", required=True)
37+
args = p.parse_args()
38+
patch(pathlib.Path(args.file), args.name, args.value)

src/c/classes/Elements/Element.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3850,6 +3850,7 @@ void Element::PositiveDegreeDayGCM(){/*{{{*/
38503850
IssmDouble* smb = xNew<IssmDouble>(NUM_VERTICES);
38513851
IssmDouble* accumulation= xNew<IssmDouble>(NUM_VERTICES);
38523852
IssmDouble* ablation = xNew<IssmDouble>(NUM_VERTICES);
3853+
IssmDouble* downscaleT = xNew<IssmDouble>(NUM_VERTICES);
38533854
IssmDouble* refreezing = xNew<IssmDouble>(NUM_VERTICES);
38543855
/*variables*/
38553856
IssmDouble rlaps, ref_surf, surface;
@@ -3884,8 +3885,9 @@ void Element::PositiveDegreeDayGCM(){/*{{{*/
38843885
ref_s_input->GetInputValue(&ref_surf,gauss);
38853886
surface_input->GetInputValue(&surface,gauss);
38863887

3887-
/*Step 2: downsampling temp with elevation and lapse rate*/
3888+
/*Step 2: downscaling temp with elevation and lapse rate*/
38883889
temperature = temperature + rlaps*(ref_surf - surface);
3890+
downscaleT[iv] = temperature;
38893891

38903892
/*Step 3: Accumulation*/
38913893
if (temperature <= temp_all_solid){
@@ -3912,9 +3914,11 @@ void Element::PositiveDegreeDayGCM(){/*{{{*/
39123914
/*Add input to element and Free memory*/
39133915
this->AddInput(SmbAccumulationEnum,accumulation,P1Enum);
39143916
this->AddInput(SmbAblationEnum,ablation,P1Enum);
3917+
this->AddInput(SmbDownscaleTemperatureEnum,downscaleT,P1Enum);
39153918
this->AddInput(SmbMassBalanceEnum,smb,P1Enum);
39163919
xDelete<IssmDouble>(accumulation);
39173920
xDelete<IssmDouble>(ablation);
3921+
xDelete<IssmDouble>(downscaleT);
39183922
xDelete<IssmDouble>(refreezing);
39193923
xDelete<IssmDouble>(smb);
39203924
delete gauss;

src/c/shared/Enum/Enum.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,7 @@ syn keyword cConstant SmbFACEnum
11661166
syn keyword cConstant SmbFACSubstepEnum
11671167
syn keyword cConstant SmbGCMLapseratesEnum
11681168
syn keyword cConstant SmbGCMRefSurfaceEnum
1169+
syn keyword cConstant SmbDownscaleTemperatureEnum
11691170
syn keyword cConstant SmbGdnEnum
11701171
syn keyword cConstant SmbGdniniEnum
11711172
syn keyword cConstant SmbGspEnum

src/c/shared/Enum/EnumDefinitions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,7 @@ enum definitions{
11621162
SmbFACSubstepEnum,
11631163
SmbGCMLapseratesEnum,
11641164
SmbGCMRefSurfaceEnum,
1165+
SmbDownscaleTemperatureEnum,
11651166
SmbGdnEnum,
11661167
SmbGdniniEnum,
11671168
SmbGspEnum,

0 commit comments

Comments
 (0)