Skip to content

Commit e5fe24a

Browse files
committed
Merge branch 'master' into more-diagnostics
2 parents 5e32dae + 017f21c commit e5fe24a

File tree

94 files changed

+1882
-742
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+1882
-742
lines changed

.gitignore

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,20 @@ BOUT.settings
77
*~
88
.DS_Store
99
/build*
10-
/docs/build/*
11-
/docs/doxygen/*
10+
__pycache__
11+
12+
# Docs
13+
/docs/build
14+
/docs/doxygen
15+
/docs/html
16+
/docs/hermes3.pdf
1217
/docs/sphinx/_breathe*
1318

1419
# IDE config files
15-
.vscode
20+
.vscode
21+
22+
# spack-related
23+
spack-build*
24+
spack.lock
25+
.spack-env
26+
views

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
path = external/BOUT-dev
66
url = https://github.com/boutproject/BOUT-dev.git
77
branch = next
8+
[submodule "BOUT-spack"]
9+
path = external/BOUT-spack
10+
url = https://github.com/boutproject/BOUT-spack.git

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ target_include_directories(hermes-3-lib PUBLIC
175175
$<INSTALL_INTERFACE:include>
176176
)
177177

178+
# Have hermes-3-lib look for dynamic libs in ./ before searching elsewhere
179+
set_target_properties(hermes-3-lib PROPERTIES BUILD_RPATH "$ORIGIN")
180+
178181
# The main executable target
179182
add_executable(hermes-3
180183
hermes-3.cxx
@@ -188,6 +191,9 @@ target_include_directories(hermes-3 PUBLIC
188191
$<INSTALL_INTERFACE:include>
189192
)
190193

194+
# Have hermes-3 look for dynamic libs in ./ before searching elsewhere
195+
set_target_properties(hermes-3 PROPERTIES BUILD_RPATH "$ORIGIN")
196+
191197
# Build the file containing just the commit hash
192198
# This will be rebuilt on every commit!
193199
configure_file(
@@ -255,6 +261,8 @@ if(HERMES_TESTS)
255261

256262
add_test(NAME hermes_unit_tests COMMAND hermes_unit_tests)
257263
target_link_libraries(hermes_unit_tests PRIVATE gtest bout++::bout++ hermes-3-lib)
264+
# Have hermes_unit_tests look for dynamic libs in ./ before searching elsewhere
265+
set_target_properties(hermes_unit_tests PROPERTIES BUILD_RPATH "$ORIGIN")
258266
endif()
259267
endif()
260268

activate_h3env

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
#!/bin/bash
2+
#
3+
# Wrapper around the spack environment that defines some useful commands.
4+
#
5+
# Activate the environment by sourcing this file with
6+
# . activate_h3env
7+
#
8+
# Run 'help_h3env' with the environment activated to see the available commands
9+
10+
# Record top-level dir
11+
REPO_ROOT=$( cd -- "$(realpath $( dirname -- "${BASH_SOURCE[0]}" ))" &> /dev/null && pwd )
12+
13+
# Save shell options
14+
OLD_SHOPTS="$(set +o)"
15+
16+
#======================= Convenience aliases/functions ========================
17+
18+
# Creates a link to the specified target (first argument) with the specified
19+
# name (second argument), unless a link with that target and name already
20+
# exists. It will overwrite links to different targets. Also print a message
21+
# saying what it is doing.
22+
_create-link() {
23+
target="$1"
24+
link="$2"
25+
if ! [[ -L "$link" && $(readlink "$link") == "$target" ]]
26+
then
27+
echo " Linking $(realpath -s --relative-to="$REPO_ROOT" "$link") => $target"
28+
rm -f "$link" > /dev/null
29+
ln -s "$target" "$link"
30+
fi
31+
}
32+
33+
# Remove the DEBUG trap and restore original shell options
34+
_disable_link_updates_hook() {
35+
trap - DEBUG
36+
set +vx; eval "${OLD_SHOPTS}"
37+
}
38+
39+
# Activate temporary DEBUG trap to update build links
40+
_enable_link_updates_hook() {
41+
shopt -s extdebug
42+
trap _update_links_on_spack_install DEBUG
43+
}
44+
45+
# Intercept all simple commands and, if spack (un)install is executing, update build links afterwards
46+
# N.B. the simple command itself runs AFTER this function iff it runs zero
47+
function _update_links_on_spack_install ()
48+
{
49+
if [[ $BASH_COMMAND == "spack "*"install"* ]]; then
50+
$BASH_COMMAND
51+
updatelinks_h3env
52+
# (We've already run the command explicitly, return non-zero so that it doesn't run again.)
53+
return 1
54+
else
55+
# (Just run the command as usual after this function returns)
56+
return 0
57+
fi
58+
}
59+
60+
# Perform cleanup tasks
61+
cleanup_h3env() {
62+
# Just update build links for now
63+
updatelinks_h3env
64+
}
65+
66+
# Remove convenience aliases/function definitions and deactivate the env
67+
deactivate_h3env() {
68+
69+
_disable_link_updates_hook
70+
71+
unset -f _create-link
72+
unset -f cleanup_h3env
73+
unset -f deactivate_h3env
74+
unset -f _disable_link_updates_hook
75+
unset -f _enable_link_updates_hook
76+
unalias help_h3env
77+
unset -f in_h3env
78+
unset REPO_ROOT
79+
unset -f _update_links_on_spack_install
80+
unset -f updatelinks_h3env
81+
unset -f usage_h3env
82+
83+
spack env deactivate
84+
}
85+
86+
# Run commands in the build environment
87+
h3spec="hermes-3%gcc"
88+
in_h3env() {
89+
if [ $# -eq 0 ]; then
90+
usage_h3env
91+
return
92+
fi
93+
cmd="spack build-env ${h3spec} $@"
94+
echo $cmd
95+
eval $cmd
96+
}
97+
98+
# Update the links at <REPO_ROOT>/builds/spack-* such that there's
99+
# exactly one link for every package returned by 'spack find hermes-3'
100+
updatelinks_h3env() {
101+
local links_dir="${REPO_ROOT}/builds"
102+
local link_prefix="spack-"
103+
104+
# Use 'spack find' to get the hashes of currently installed hermes-3 packages
105+
# Discard stderr to suppress error message when no installs are found
106+
local identifier_fmt="{hash:7}"
107+
installed_hashes=$(spack find --format "$identifier_fmt" "hermes-3" 2> /dev/null)
108+
109+
# Create any links for installed packages that don't exist already
110+
mkdir -p "${links_dir}"
111+
for hash in $installed_hashes; do
112+
spack_build_dir=$(spack location -b "hermes-3/$hash")
113+
_create-link "${spack_build_dir}" "${links_dir}/${link_prefix}${hash}"
114+
done
115+
116+
# Check whether existing links are still valid (Could also just use find -xtype l ?)
117+
for l in "${links_dir}/${link_prefix}"*; do
118+
# Skip if l isn't a link (also guards against case where pattern has zero matches)
119+
[ ! -L "$l" ] && break;
120+
hash=$(echo "$l"|rev|cut -c -7|rev)
121+
# Remove link if 'spack find' returns non-zero for this hash
122+
spack find "hermes-3/$hash" &> /dev/null
123+
if [ $? -ne 0 ]; then
124+
echo " Removing stale link at $l"
125+
rm -f "$l"
126+
fi
127+
done
128+
129+
# Also clean up top-level build links created by spack install
130+
spack_link_paths=$(find "$REPO_ROOT" -type l -regextype posix-egrep -regex "${REPO_ROOT}/build-.*-[a-z0-9]{7}$")
131+
for link_path in $spack_link_paths; do
132+
local hash="${link_path:(-7)}"
133+
if ! [[ " ${installed_hashes[*]} " =~ " ${hash} " ]]
134+
then
135+
echo " Removing stale spack link at ${link_path}"
136+
rm -Rf "$link_path" > /dev/null
137+
fi
138+
done
139+
}
140+
141+
# Print help/usage info
142+
usage_h3env() {
143+
echo " . activate_h3env : Activate the environment"
144+
echo " cleanup_h3env : Perform cleanup tasks (includes updatelinks_h3env)"
145+
echo " deactivate_h3env : Deactivate the environment"
146+
echo " help_h3env : Show this message"
147+
echo ' in_h3env [args] : Run a command in the build environment: (e.g. export h3_build="./builds/my_build" && in_h3env cmake -B "$h3_build" && in_h3env cmake --build "$h3_build" -j8)'
148+
echo " updatelinks_h3env : Update all build links (Remove stale links and add new ones in ./builds/spack-* where necessary)"
149+
}
150+
alias help_h3env=usage_h3env
151+
152+
#============================== Run on activate ===============================
153+
154+
# Check that spack has been set up
155+
spacktivate_cmd="spacktivate"
156+
if ! command -v "$spacktivate_cmd" &> /dev/null
157+
then
158+
echo "The $spacktivate_cmd alias doesn't seem to be defined. Have you installed spack and sourced \$SPACK_ROOT/share/spack/setup-env.sh?"
159+
return 1
160+
fi
161+
162+
# Check that BOUT-spack has been cloned
163+
sm_name="BOUT-spack"
164+
repo_yaml="${REPO_ROOT}/external/${sm_name}/repo.yaml"
165+
if [ ! -f "$repo_yaml" ]
166+
then
167+
echo "$repo_yaml doesn't exist. Has the ${sm_name} git submodule been initialised?"
168+
echo " (git submodule update --init)"
169+
return
170+
fi
171+
172+
# Activate the environment and load the view
173+
spacktivate . -p -v gcc
174+
175+
# Update build links
176+
cleanup_h3env
177+
178+
_enable_link_updates_hook

docs/makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ manual: all
99
pdf: sphinx-pdf
1010
html: sphinx-html
1111
man: sphinx-man
12-
sphinx: sphinx-pdf
12+
sphinx: sphinx-html
13+
14+
.PHONY: breathe-autogen, doxygen, clean, html, man, manual, pdf, sphinx, sphinx-html, sphinx-man, sphinx-pdf
1315

1416
sphinx-pdf: doxygen
1517
$(sphinx-build) -b latex sphinx/ build/

docs/sphinx/equations.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,17 @@ component also calculates the momentum.
302302

303303
Saves the temperature once as a non-evolving variable.
304304

305+
The velocity may be set in the mesh file as an array (2D or 3D), or in
306+
the options as an expression. The options value overrides the value in
307+
the mesh. If neither mesh array nor option are set then an exception
308+
will be thrown. Both mesh array and option should be specified in
309+
units of meters per second.
310+
311+
The name of the array in the mesh file is ``V<name>0`` where
312+
``<name>`` is the name of the species e.g. for species ``e``
313+
(electrons), ``fixed_velocity`` will try to read ``Ve0`` from the mesh
314+
file, and then the ``velocity`` option in the ``[e]`` section:
315+
305316
.. code-block:: ini
306317
307318
[e]

docs/sphinx/examples.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ other. Ions recycle into neutrals, which charge exchange and are
5252
ionised. A difference is that separate ion and electron temperatures
5353
are evolved here.
5454

55-
.. figure:: figs/1d_threshold.gif
55+
.. figure:: figs/1d_threshold.*
5656
:name: 1d_threshold_fig
5757
:alt:
5858
:width: 60%

docs/sphinx/figs/1d_threshold.png

23.3 KB
Loading

0 commit comments

Comments
 (0)