Skip to content
Merged
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 CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/fmt.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/gtest.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/yamlpp.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/eigen.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/libarchive.cmake)

if (CMAKE_CUDA_COMPILER)
find_package(CUDAToolkit REQUIRED)
Expand Down
19 changes: 19 additions & 0 deletions cmake/libarchive.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
include(FetchContent)

# ---- libarchive options (tune as needed) ----
set(ENABLE_WERROR OFF CACHE BOOL "" FORCE)
set(ENABLE_TEST OFF CACHE BOOL "" FORCE)

set(ENABLE_OPENSSL OFF CACHE BOOL "" FORCE)
set(ENABLE_LZMA OFF CACHE BOOL "" FORCE)
set(ENABLE_ZSTD OFF CACHE BOOL "" FORCE)
set(ENABLE_BZip2 OFF CACHE BOOL "" FORCE)

set(PACKAGE_NAME libarchive)
set(REPO_URL "https://github.com/libarchive/libarchive")
set(REPO_TAG "v3.8.5")

add_package(${PACKAGE_NAME} ${REPO_URL} ${REPO_TAG} "" ON)
set(LIBARCHIVE_INCLUDE_DIR
"${${PACKAGE_NAME}_SOURCE_DIR}/libarchive"
CACHE PATH "libarchive include directory")
7 changes: 4 additions & 3 deletions examples/run_hydro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ int main(int argc, char **argv) {
// initialize
std::map<std::string, torch::Tensor> vars;
vars["hydro_w"] = w;
block->initialize(vars);
double current_time = block->initialize(vars, cli->restart_filename);

// user output variables
// (1) total precipitable mass fraction [kg/kg]
Expand All @@ -152,8 +152,9 @@ int main(int argc, char **argv) {
kinet->to(device);

// time loop
double current_time = 0.;
block->make_outputs(vars, current_time);
if (cli->restart_filename == nullptr) {
block->make_outputs(vars, current_time);
}

while (!block->pintg->stop(block->cycle++, current_time)) {
auto dt = block->max_time_step(vars);
Expand Down
8 changes: 5 additions & 3 deletions examples/straka.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ int main(int argc, char** argv) {
// initialize
std::map<std::string, torch::Tensor> vars;
vars["hydro_w"] = w;
block->initialize(vars);
char const* restart = nullptr;
double current_time = block->initialize(vars, restart);

block->user_output_callback = [Rd, cp, p0](Variables const& vars) {
auto w = vars.at("hydro_w");
Expand All @@ -86,8 +87,9 @@ int main(int argc, char** argv) {
return out;
};

double current_time = 0.;
block->make_outputs(vars, current_time);
if (restart == nullptr) {
block->make_outputs(vars, current_time);
}

while (!block->pintg->stop(block->cycle++, current_time)) {
auto dt = block->max_time_step(vars);
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ requires = [
"build",
"torch>=2.7.0,<=2.7.1",
"ninja",
"kintera>=1.2.6",
"kintera>=1.2.9",
]
build-backend = "setuptools.build_meta"

Expand All @@ -21,7 +21,7 @@ readme = "README.md"
requires-python = ">=3.9"
dependencies = [
"numpy",
"kintera>=1.2.6",
"kintera>=1.2.9",
]
classifiers = [
"Development Status :: 3 - Alpha",
Expand Down
19 changes: 13 additions & 6 deletions python/csrc/pymesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,19 @@ void bind_mesh(py::module &m) {
py::arg("offset"), py::arg("exterior") = true,
py::arg("extend_x1") = 0, py::arg("extend_x2") = 0,
py::arg("extend_x3") = 0)
//.def("initialize", &snap::MeshBlockImpl::initialize)
.def("initialize",
[](snap::MeshBlockImpl &self, snap::Variables &vars) {
auto time = self.initialize(vars);
return std::make_pair(vars, time);
})
.def(
"initialize",
[](snap::MeshBlockImpl &self, snap::Variables &vars,
std::string restart_file) {
double time;
if (restart_file.empty()) {
time = self.initialize(vars);
} else {
time = self.initialize(vars, restart_file.c_str());
}
return std::make_pair(vars, time);
},
py::arg("vars"), py::arg("restart_file") = "")
.def("print_cycle_info", &snap::MeshBlockImpl::print_cycle_info)
.def("finalize", &snap::MeshBlockImpl::finalize)
.def("device", &snap::MeshBlockImpl::device)
Expand Down
9 changes: 9 additions & 0 deletions python/csrc/snapy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <snap/snap.h>

#include <snap/input/parameter_input.hpp>
#include <snap/input/read_restart_file.hpp>

// python
#include "pyoptions.hpp"
Expand Down Expand Up @@ -39,6 +40,14 @@ PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
m.attr("kIPR") = (int)snap::IPR;
m.attr("kICY") = (int)snap::ICY;

m.def(
"load_restart",
[](snap::Variables &vars, std::string const &path) {
snap::load_restart(vars, path);
return vars;
},
py::arg("vars"), py::arg("path"));

bind_layout(m);
bind_bc(m);
bind_coord(m);
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ include_directories(
${CMAKE_BINARY_DIR}
${NETCDF_INCLUDES}
${PNETCDF_INCLUDE_DIR}
SYSTEM ${LIBARCHIVE_INCLUDE_DIR}
SYSTEM ${TORCH_API_INCLUDE_DIR}
SYSTEM ${TORCH_INCLUDE_DIR}
SYSTEM ${KINTERA_INCLUDE_DIR}
Expand Down Expand Up @@ -73,6 +74,7 @@ target_link_libraries(${namel}_${buildl}
${TORCH_LIBRARY}
${TORCH_CPU_LIBRARY}
${C10_LIBRARY}
archive
fmt::fmt
yaml-cpp::yaml-cpp
)
Expand Down
2 changes: 1 addition & 1 deletion src/eos/ideal_moist.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class IdealMoistImpl final : public torch::nn::Cloneable<IdealMoistImpl>,
torch::Tensor compute(std::string ab,
std::vector<torch::Tensor> const& args) override;

//! \brief Inverse of the mean molecular weight
//! \brief Virtual factor
/*!
*! Eq.16 in Li2019
*! $ \frac{R}{R_d} = \frac{\mu_d}{\mu}$
Expand Down
Loading
Loading