diff --git a/.github/workflows/regression.yaml b/.github/workflows/regression.yaml new file mode 100644 index 0000000..6542198 --- /dev/null +++ b/.github/workflows/regression.yaml @@ -0,0 +1,42 @@ +name: Regression Tests + +on: + schedule: + - cron: "0 0 * * *" + push: + branches: [main] + workflow_dispatch: + pull_request: + branches: + - main + +jobs: + run-tests: + runs-on: [self-hosted] + strategy: + fail-fast: false + steps: + - name: checkout testapp + uses: actions/checkout@v4 + - name: checkout opensn + uses: actions/checkout@v4 + with: + repository: Open-Sn/opensn + path: opensn + - name: install opensn + shell: bash + run: | + module load opensn/clang/17 python3/3.12.3 + cd opensn && mkdir build && mkdir install && cd build + cmake -DOPENSN_WITH_PYTHON=True -DCMAKE_INSTALL_PREFIX=../install .. && make -j && make install + - name: compile app + shell: bash + run: | + module load opensn/clang/17 python3/3.12.3 + cd OpenSnApp && mkdir build && cd build + cmake -DCMAKE_PREFIX_PATH=../../opensn/install .. && make -j + - name: test examples + shell: bash + run: | + module load opensn/clang/17 python3/3.12.3 + cd tests && ../build/test_app_exec -i test.py \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dc23fda --- /dev/null +++ b/.gitignore @@ -0,0 +1,89 @@ +.git +cmake-build-debug/ +cmake-build-debug +.idea +bin +build*/ +doc/documentation +doc/HTMLdocs +doc/whitepages + +# root Makefile is generated by CMake automatically +Makefile + +resources/Dependencies/lua-5.3.5/ +resources/Dependencies/ncurses/ +resources/Dependencies/readline/ +resources/Dependencies/triangle/ +resources/Dependencies/glew-2.1.0/ + +# Latex compile files +*.aux +*.lof +*.log +*.lot +*.synctex.gz +*.toc +*.pdf + +# All vtk mesh files +/*.vtu +/*.pvtu +test/**/*.pvtu +test/**/*.vtu +test/modules/linear_boltzmann_solvers/dsa/SimTest_92b_DSA_PWLC.pvtu +test/modules/linear_boltzmann_solvers/dsa/SimTest_92b_DSA_PWLC_0.vtu +test/**/*.csv + +tests/BigTests/*/solutions/ + +# All exodus files +/*.e + +resources/Dependencies/.DS_Store + +resources/.DS_Store + +# python files +.DS_Store +._.DS_Store +*.pyc +*.pmesh +__pycache__ +**/__pycache__ + +*-private.sh + +#Documentation +doc/generated_files + +#visual studio code files +.vscode/ + +test/**/out/ +tutorials/**/out/ + +#Scratch directory +scratch/ + +#general data files +*.data +tests/BigTests/c5g7/Test1/solutions/ +**/*.cmesh + +# Python generated libraries +pyopensn/libopensn*.so* +pyopensn/libopensn*.dylib +pyopensn/__init__.cpython* +pyopensn.egg-info + +# Files generated by ply package +doc/scripts/parser.out +doc/scripts/parsetab.py + +doc/**/*.pvtu +doc/**/*.vtu + +tutorials/**/*.pvtu +tutorials/**/*.vtu +tutorials/**/*.py \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..8c873af --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,54 @@ +cmake_minimum_required(VERSION 3.14) +project(MyOpenSnApp LANGUAGES C CXX) + +set(CMAKE_CXX_STANDARD 17) + +find_package(MPI REQUIRED) +find_package(VTK REQUIRED COMPONENTS + CommonCore + CommonDataModel + IOLegacy + IOCore + IOXML + ParallelCore + IOParallelXML + FiltersCore + IOEnSight + IOExodus +) +find_package(OpenSn REQUIRED) + +# Optional: find pybind11 +find_package(pybind11 REQUIRED) + +find_package(caliper REQUIRED) + +find_package(Python REQUIRED COMPONENTS Interpreter Development) + +# Python module +add_library(testapp MODULE + src/test.cc + src/testapp_py.cc +) + +execute_process( + COMMAND python3 -m pybind11 --includes + OUTPUT_VARIABLE PYBIND11_INCLUDE_FLAGS + OUTPUT_STRIP_TRAILING_WHITESPACE +) +string(REPLACE "-I" "" PYBIND11_INCLUDE_DIRS "${PYBIND11_INCLUDE_FLAGS}") +separate_arguments(PYBIND11_INCLUDE_DIRS) + +target_include_directories(testapp PRIVATE ${OPENSN_INCLUDE_DIR} ${PYBIND11_INCLUDE_DIRS}) +target_link_libraries(testapp PRIVATE opensn::libopensn MPI::MPI_C caliper pybind11::module Python::Python) + +set_target_properties(testapp PROPERTIES + PREFIX "" # remove "lib" prefix + OUTPUT_NAME "testapp" # Python import name + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/python +) + +# Optional executable +add_executable(test_app_exec src/main.cc src/test.cc) +target_include_directories(test_app_exec PRIVATE ${OPENSN_INCLUDE_DIR} ${PYBIND11_INCLUDE_DIRS}) +target_link_libraries(test_app_exec PRIVATE opensn::libopensn MPI::MPI_C caliper pybind11::module Python::Python) \ No newline at end of file diff --git a/src/main.cc b/src/main.cc new file mode 100644 index 0000000..7c59a53 --- /dev/null +++ b/src/main.cc @@ -0,0 +1,11 @@ +#include "test.h" +#include "opensn/python/lib/py_app.h" +#include "opensn/mpicpp-lite/mpicpp-lite.h" + +int main(int argc, char** argv) +{ + mpi::Environment env(argc, argv); + py::scoped_interpreter guard{}; + auto app = TestApp::Create({}); + return 0; +} diff --git a/src/test.cc b/src/test.cc new file mode 100644 index 0000000..b25f81c --- /dev/null +++ b/src/test.cc @@ -0,0 +1,28 @@ +#include "test.h" +#include "opensn/framework/logging/log.h" +#include "opensn/framework/object_factory.h" + +using namespace opensn; + +OpenSnRegisterObject(TestApp); + +InputParameters +TestApp::GetInputParameters() +{ + InputParameters params; + params.SetGeneralDescription("A dummy application for testing."); + params.AddOptionalParameter("name", "test_app", "A name for the application."); + return params; +} + +TestApp::TestApp(const InputParameters& params) : name_(params.GetParamValue("name")) +{ + opensn::log.Log() << "TestApp named " << name_ << " created."; +} + +std::shared_ptr +TestApp::Create(const ParameterBlock& params) +{ + auto& factory = opensn::ObjectFactory::GetInstance(); + return factory.Create("TestApp", params); +} diff --git a/src/test.h b/src/test.h new file mode 100644 index 0000000..2ea1caa --- /dev/null +++ b/src/test.h @@ -0,0 +1,15 @@ +#pragma once +#include "opensn/framework/object.h" + +class TestApp : public opensn::Object +{ +public: + explicit TestApp(const opensn::InputParameters& params); + +private: + const std::string name_; + +public: + static opensn::InputParameters GetInputParameters(); + static std::shared_ptr Create(const opensn::ParameterBlock& params); +}; diff --git a/src/testapp_py.cc b/src/testapp_py.cc new file mode 100644 index 0000000..e841cf1 --- /dev/null +++ b/src/testapp_py.cc @@ -0,0 +1,12 @@ +#include +#include "test.h" + +namespace py = pybind11; + +PYBIND11_MODULE(myapp, m) +{ + m.doc() = "Python bindings for my OpenSn-based TestApp"; + + py::class_>(m, "TestApp") + .def_static("Create", &TestApp::Create); +} diff --git a/tests/test.py b/tests/test.py new file mode 100644 index 0000000..693f29e --- /dev/null +++ b/tests/test.py @@ -0,0 +1,8 @@ +# test.py +import sys +sys.path.insert(0, "build/python") # where CMake drops the .so + +import myapp + +app = myapp.TestApp.Create() +print("Successfully created:", app)