Skip to content

Commit

Permalink
Merge pull request #7 from boutproject/v2.2.1
Browse files Browse the repository at this point in the history
V2.2.1
  • Loading branch information
johnomotani authored Oct 8, 2022
2 parents 604f7e3 + 463f702 commit b1038b2
Show file tree
Hide file tree
Showing 14 changed files with 697 additions and 278 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,7 @@ data_*
*.txt
storm2d/storm2d
storm3d/storm_version.hxx

# CMake build directories #
###########################
build*
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Change log
==========

This file records 'breaking' changes that might require alterations to input files, etc.


v2.2.1 (5/4/2022)
-----------------

* `nu_parallel0` input setting renamed to `nu_parallel0_scalar`. (!153)
49 changes: 49 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
cmake_minimum_required(VERSION 3.18)
cmake_policy(VERSION 3.18)

project(storm
LANGUAGES CXX)

find_package(bout++
REQUIRED)

add_executable(storm
storm3d/storm.cxx storm3d/boundaries.cxx storm3d/initialise.cxx storm3d/monitors.cxx storm3d/operators.cxx storm3d/utilities.cxx shared/fast_output.cxx shared/BoutEquation/equation.cxx storm3d/neutral-rates.cxx storm3d/D-vpar.cxx storm3d/neutral-model.cxx)

target_link_libraries(storm
PRIVATE bout++::bout++)


# Write git hash and diff to ${CMAKE_CURRENT_BINARY_DIR}/include/storm_version.hxx at every build
# Original version inspired by https://stackoverflow.com/a/39960540.
# Modified because original version did not always regenerate storm_version.hxx. Problem
# seems to be fixed by putting the COMMAND directly into add_custom_target() instead of
# using add_custom_command(), and explicitly adding 'GitVersion' as a dependency of
# 'storm', rather than having
# '${CMAKE_CURRENT_BINARY_DIR}/include/storm_version.hxx' as a dependency. Modifications
# inspired by https://stackoverflow.com/a/51881170/13577592.
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include)
target_include_directories(storm PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)
# Remove storm_version.hxx from the source directory (if it exists). It may have been
# generated by a configure/make in-source build, but should not be used here. There does
# not seem to be a way to prevent the source-directory version from taking precedence
# except deleting it (changing `#include "storm_version.hxx"` to `#include
# <storm_version.hxx>` should work, but would break the configure/make build).
file(REMOVE ${CMAKE_CURRENT_SOURCE_DIR}/storm3d/storm_version.hxx)

add_custom_target(GitVersion
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/build_tools/save_git_version.py ${PROJECT_BINARY_DIR}/include ${PROJECT_BINARY_DIR} > /dev/null
COMMENT "Generating include/storm_version.hxx")
add_dependencies(storm GitVersion)


# Copy useful scripts, etc. into build directory
add_custom_command(TARGET storm POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/storm3d/create_bg_1d $<TARGET_FILE_DIR:storm>)


# Copy tests into build directory so that we can run them locally
# See https://newbedev.com/how-to-copy-contents-of-a-directory-into-build-directory-after-make-with-cmake
add_custom_command(TARGET storm POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/tests3d $<TARGET_FILE_DIR:storm>/tests3d)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ UKAEA/CCFE may have significant features added that are not yet included in
this public release. If you are interested in using features that have not been
released yet, please contact us to set up a collaboration.

This version of STORM has been tested with BOUT++ v4.3.3.
This version of STORM has been tested with BOUT++ v4.4.2.

Table of Contents
-----------------
Expand Down
113 changes: 101 additions & 12 deletions build_tools/save_git_version.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,131 @@
#!/usr/bin/env python3

import argparse
from boututils.run_wrapper import shell_safe
from pathlib import Path
from string import ascii_uppercase

try:
from git import Repo
from git import Repo, InvalidGitRepositoryError
except ImportError:
# print a return code to stdout so we can capture and test it in the makefile
print(11)
raise
raise ImportError(
"gitpython not installed. You can install with 'conda install gitpython' or "
"'pip3 install --user gitpython'"
)

scriptdir = Path(__file__).resolve().parent

scriptdir = Path(__file__).parent
parser = argparse.ArgumentParser()
parser.add_argument(
"output_directory",
type=str,
nargs="?",
default=scriptdir.parent.joinpath("storm3d"),
)
parser.add_argument("cmake_directory", type=str, nargs="?", default=None)
args = parser.parse_args()
output_directory = Path(args.output_directory)
cmake_directory = None if args.cmake_directory is None else Path(args.cmake_directory)

repo = Repo(scriptdir.parent)

diff = repo.git.diff()

# Get version info for storm-configs, if it is being used
try:
storm_configs_repo = Repo(scriptdir.resolve().parent.parent)
except InvalidGitRepositoryError:
storm_configs_repo = None

if storm_configs_repo is not None:
# Check that storm_configs_repo is really storm-configs
*_, first_commit = storm_configs_repo.iter_commits()
if str(first_commit) != "f45792f72fb401014459987d1064113fa572c625":
storm_configs_repo = None
else:
storm_configs_diff = storm_configs_repo.git.diff()
bout_configs_repo = Repo(
scriptdir.resolve().parent.parent.joinpath("BOUT-configs")
)
bout_configs_diff = bout_configs_repo.git.diff()

# Get contents of CMakeCache.txt, if CMake is being used
if cmake_directory is not None:
with open(cmake_directory.joinpath("CMakeCache.txt"), "r") as f:
storm_cmake_cache = f.read()

# Get modules, if the system has a 'module' command
try:
_, module_list = shell_safe("module list", pipe=True)
except RuntimeError:
module_list = None

# Find a string to use for the delimiter
if storm_configs_repo is not None:
combined_diff = diff + "\n" + storm_configs_diff + "\n" + bout_configs_diff
else:
combined_diff = diff
if cmake_directory is not None:
combined_diff += "\n" + storm_cmake_cache
if module_list is not None:
combined_diff += "\n" + module_list
delimiter = "_STORM_DIFF_"
for letter in ascii_uppercase:
if ")" + delimiter not in diff:
delimiter_success = True
if ")" + delimiter not in combined_diff:
break
delimiter = "_STORM_DIFF_" + letter + "_"
if ")" + delimiter in diff:
if ")" + delimiter in combined_diff:
# print a return code to stdout so we can capture and test it in the makefile
print(12)
raise ValueError(
"save_git_version.py failed to find a delimiter that is not in the git diff"
)

with open("storm_version.hxx", "w") as f:
f.write("constexpr auto storm_git_hash = \"")
f.write(repo.git.describe(abbrev=40, dirty=True, always=True, tags=True))
f.write("\";\n")
f.write("constexpr auto storm_git_diff = R\"" + delimiter + "(")
with open(output_directory.joinpath("storm_version.hxx"), "w") as f:
f.write('constexpr auto storm_git_hash = "')
f.write(repo.git.describe(abbrev=40, dirty=True, always=True, tags=True, long=True))
f.write('";\n')
f.write('constexpr auto storm_git_diff = R"' + delimiter + "(")
f.write(diff)
f.write(")" + delimiter + "\";\n")
f.write(")" + delimiter + '";\n')

if storm_configs_repo is None:
f.write('constexpr auto storm_configs_git_hash = "";\n')
f.write('constexpr auto storm_configs_git_diff = "";\n')
f.write('constexpr auto bout_configs_git_diff = "";\n')
else:
f.write('constexpr auto storm_configs_git_hash = "')
f.write(
storm_configs_repo.git.describe(
abbrev=40,
dirty=True,
always=True,
tags=True,
),
)
f.write('";\n')
f.write('constexpr auto storm_configs_git_diff = R"' + delimiter + "(")
f.write(storm_configs_diff)
f.write(")" + delimiter + '";\n')
f.write('constexpr auto bout_configs_git_diff = R"' + delimiter + "(")
f.write(bout_configs_diff)
f.write(")" + delimiter + '";\n')

if cmake_directory is None:
f.write('std::string storm_cmake_cache = "";\n')
else:
f.write('std::string storm_cmake_cache = R"' + delimiter + "(")
f.write(storm_cmake_cache)
f.write(")" + delimiter + '";\n')

if module_list is None:
f.write('std::string module_list = "";\n')
else:
f.write('std::string module_list = R"' + delimiter + "(")
f.write(module_list)
f.write(")" + delimiter + '";\n')

# print a return code to stdout so we can capture and test it in the makefile
print(0)
2 changes: 1 addition & 1 deletion shared/BoutEquation
Submodule BoutEquation updated 1 files
+7 −0 README.md
67 changes: 38 additions & 29 deletions storm3d/D-vpar.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -340,14 +340,9 @@ int NeutralDVpar::timestepmonitor(BoutReal simtime) {
if( monitor_minmaxmean ) {
if(minmaxmean_timelast < 0.){
minmaxmean_timelast = simtime;
}else if(simtime - minmaxmean_timelast > 5.){
} else if (simtime - minmaxmean_timelast > 5.) {
minmaxmean_timelast = simtime;
output.write("\nmin(nn) = %e, max(nn) = %e, mean(nn) = %e\n",
min(nn,true,"RGN_NOBNDRY"),max(nn,true,"RGN_NOBNDRY"),mean(nn,true,"RGN_NOBNDRY"));
output.write("min(nvn) = %e, max(nvn) = %e, mean(nvn) = %e\n",
min(nvn,true,"RGN_NOBNDRY"),max(nvn,true,"RGN_NOBNDRY"),mean(nvn,true,"RGN_NOBNDRY"));
output.write("min(vn) = %e, max(vn) = %e, mean(vn) = %e\n\n",
min(vn,true,"RGN_NOBNDRY"),max(vn,true,"RGN_NOBNDRY"),mean(vn,true,"RGN_NOBNDRY"));
printMinMaxMean();
}
}

Expand All @@ -357,25 +352,39 @@ int NeutralDVpar::timestepmonitor(BoutReal simtime) {
int NeutralDVpar::OutputMonitor::call(Solver* UNUSED(solver), BoutReal UNUSED(simtime),
int UNUSED(iter), int UNUSED(NOUT)) {
if (neutral_dvpar->monitor_minmaxmean) {
output.write("min(nn) = %e, max(nn) = %e, mean(nn) = %e\n",
min(neutral_dvpar->nn,true,"RGN_NOBNDRY"),
max(neutral_dvpar->nn,true,"RGN_NOBNDRY"),
mean(neutral_dvpar->nn,true,"RGN_NOBNDRY")
);
output.write("min(nvn) = %e, max(nvn) = %e, mean(nvn) = %e\n",
min(neutral_dvpar->nvn,true,"RGN_NOBNDRY"),
max(neutral_dvpar->nvn,true,"RGN_NOBNDRY"),
mean(neutral_dvpar->nvn,true,"RGN_NOBNDRY")
);
output.write("min(vn) = %e, max(vn) = %e, mean(vn) = %e\n\n",
min(neutral_dvpar->vn,true,"RGN_NOBNDRY"),
max(neutral_dvpar->vn,true,"RGN_NOBNDRY"),
mean(neutral_dvpar->vn,true,"RGN_NOBNDRY")
);
neutral_dvpar->printMinMaxMean();
}
return 0;
}

void NeutralDVpar::printMinMaxMean() {
output.write("min(nn) = %e, max(nn) = %e, mean(nn) = %e, ",
min(nn,true,"RGN_NOBNDRY"),
max(nn,true,"RGN_NOBNDRY"),
mean(nn,true,"RGN_NOBNDRY")
);
output.write("min(ddt(lognn)) = %e, max(ddt(lognn)) = %e, mean(ddt(lognn)) = %e\n",
min(ddt(lognn),true,"RGN_NOBNDRY"),
max(ddt(lognn),true,"RGN_NOBNDRY"),
mean(ddt(lognn),true,"RGN_NOBNDRY")
);
output.write("min(nvn) = %e, max(nvn) = %e, mean(nvn) = %e, ",
min(nvn,true,"RGN_NOBNDRY"),
max(nvn,true,"RGN_NOBNDRY"),
mean(nvn,true,"RGN_NOBNDRY")
);
output.write("min(ddt(nvn)) = %e, max(ddt(nvn)) = %e, mean(ddt(nvn)) = %e\n",
min(ddt(nvn),true,"RGN_NOBNDRY"),
max(ddt(nvn),true,"RGN_NOBNDRY"),
mean(ddt(nvn),true,"RGN_NOBNDRY")
);
output.write("min(vn) = %e, max(vn) = %e, mean(vn) = %e\n\n",
min(vn,true,"RGN_NOBNDRY"),
max(vn,true,"RGN_NOBNDRY"),
mean(vn,true,"RGN_NOBNDRY")
);
}

void NeutralDVpar::precon(BoutReal UNUSED(t), BoutReal gamma, BoutReal UNUSED(delta)) {
// Neutral gas diffusion
// Solve (1 - gamma*Dn*Delp2)^{-1}
Expand Down Expand Up @@ -576,7 +585,7 @@ void NeutralDVpar::recycleFluxes(BoutReal time) {
}
}

delete particlesdt;
delete [] particlesdt;
}

}
Expand Down Expand Up @@ -647,14 +656,14 @@ void NeutralDVpar::initialiseSource(Options &options) {
profileSn_upper(ix,localyindex) = profile_upper[iy]/intupper;
}
}
delete profile_upper;
delete profile_lower;
delete ydistance_upper;
delete ydistance_lower;
delete recvbuffer;
delete [] profile_upper;
delete [] profile_lower;
delete [] ydistance_upper;
delete [] ydistance_lower;
delete [] recvbuffer;
}
}
delete sendbuffer;
delete [] sendbuffer;
mesh->communicate(profileSn_lower);
mesh->communicate(profileSn_upper);
profileSn_lower.applyBoundary("free_o3");
Expand Down
16 changes: 10 additions & 6 deletions storm3d/D-vpar.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ public:

void precon(BoutReal t, BoutReal gamma, BoutReal delta);
private:
int rhs_counter = 0;
Equation neutral_density_equation{lognn, "lognn", Options::root()["save_equations"],
dump, rhs_counter};
Equation neutral_momentum_equation{nvn, "nvn", Options::root()["save_equations"], dump,
rhs_counter};

Field3D nn, nvn;
Field3D Tn;
Field3D lognn;
Expand All @@ -56,6 +50,12 @@ private:
Field2D g_23og_22;
std::string orderupwindscheme;

int rhs_counter = 0;
Equation neutral_density_equation{lognn, "lognn", Options::root()["save_equations"],
dump, rhs_counter};
Equation neutral_momentum_equation{nvn, "nvn", Options::root()["save_equations"], dump,
rhs_counter};

BoutReal Tn0; // Uniform temperature of neutrals
BoutReal munvn; // numerical dissipation in neutral momentum equation
BoutReal lambdamax; // maximum mean free path for neutrals
Expand Down Expand Up @@ -111,6 +111,10 @@ private:
NeutralDVpar* neutral_dvpar;
};
OutputMonitor my_output_monitor;

// Print minimum, maximum and mean of evolving variables. Used when
// monitor_minmaxmean=true
void printMinMaxMean();
};

#endif // __NEUTRAL_DVPAR_H__
Loading

0 comments on commit b1038b2

Please sign in to comment.