Skip to content

Commit

Permalink
Wrapping in tuvx functions for Python wrapper, linking against C++ in…
Browse files Browse the repository at this point in the history
…terface wrapper.
  • Loading branch information
WardF committed Jul 23, 2024
1 parent 46022cd commit 727d9bd
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
pybind11_add_module(musica_python
wrapper.cpp
${PROJECT_SOURCE_DIR}/src/micm/micm.cpp
${PROJECT_SOURCE_DIR}/src/tuvx/tuvx.cpp
${PROJECT_SOURCE_DIR}/src/component_versions.cpp
${PROJECT_SOURCE_DIR}/src/util.cpp
${CMAKE_BINARY_DIR}/version.cpp
Expand Down
54 changes: 52 additions & 2 deletions python/wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
// Copyright (C) 2023-2024 National Center for Atmospheric Research
// SPDX-License-Identifier: Apache-2.0
#include <musica/micm.hpp>

#include <musica/tuvx/tuvx.hpp>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

namespace py = pybind11;

// Wraps micm.cpp
// Wraps micm.cpp and tuvx.cpp
PYBIND11_MODULE(musica, m)
{
/*
* Wrap micm
*/
py::class_<musica::MICM>(m, "micm")
.def(py::init<>())
.def("__del__", [](musica::MICM &micm) {});
Expand Down Expand Up @@ -126,4 +129,51 @@ PYBIND11_MODULE(musica, m)
return map;
},
"Return map of reaction rates");

/*
* Wrap tuvx
*/


py::class_<musica::TUVX>(m,"tuvx")
.def(py::init<>())
.def("__del__", [](musica::TUVX &tuvx) {});

m.def(
"create_tuvx",
[](const char *config_path)
{
musica::Error error;
musica::TUVX *tuvx = musica::CreateTuvx(config_path,&error);
if (!musica::IsSuccess(error))
{
std::string message = "Error creating Tuvx: " + std::string(error.message_.value_);
DeleteError(&error);
throw std::runtime_error(message);

}
return tuvx;
});

m.def("delete_tuvx", &musica::DeleteTuvx);

m.def(
"tuvx_get_grid_map",
[](musica::TUVX *tuvx)
{
musica::Error error;
musica::GridMap map = musica::GetGridMap(tuvx,&error);
if (!musica::IsSuccess(error))
{
std::string message = "Error getting tuvx gridmap: " + std::string(error.message_.value_);
DeleteError(&error);
throw std::runtime_error(message);

}

return map;


});

}

0 comments on commit 727d9bd

Please sign in to comment.