From 9e25022a44274fe3965011c450141e953158304d Mon Sep 17 00:00:00 2001 From: Yung-Yu Chen Date: Thu, 1 Aug 2024 21:35:54 +0800 Subject: [PATCH 1/2] Add placeholder for the 2/3D Euler CESE solver * Add the the placeholder `modmesh::EulerCore` C++ class and wrap it to Python as `modmesh.EulerCore`. * Add the test file `tests/test_euler.py` --- cpp/modmesh/CMakeLists.txt | 2 + cpp/modmesh/multidim/CMakeLists.txt | 30 +++++++ cpp/modmesh/multidim/euler.hpp | 86 +++++++++++++++++++ cpp/modmesh/multidim/multidim.hpp | 38 ++++++++ cpp/modmesh/multidim/pymod/multidim_pymod.cpp | 66 ++++++++++++++ cpp/modmesh/multidim/pymod/multidim_pymod.hpp | 50 +++++++++++ cpp/modmesh/multidim/pymod/wrap_multidim.cpp | 83 ++++++++++++++++++ cpp/modmesh/python/module.cpp | 2 + modmesh/core.py | 1 + tests/test_euler.py | 38 ++++++++ 10 files changed, 396 insertions(+) create mode 100644 cpp/modmesh/multidim/CMakeLists.txt create mode 100644 cpp/modmesh/multidim/euler.hpp create mode 100644 cpp/modmesh/multidim/multidim.hpp create mode 100644 cpp/modmesh/multidim/pymod/multidim_pymod.cpp create mode 100644 cpp/modmesh/multidim/pymod/multidim_pymod.hpp create mode 100644 cpp/modmesh/multidim/pymod/wrap_multidim.cpp create mode 100644 tests/test_euler.py diff --git a/cpp/modmesh/CMakeLists.txt b/cpp/modmesh/CMakeLists.txt index 884707fd..7ac0341b 100644 --- a/cpp/modmesh/CMakeLists.txt +++ b/cpp/modmesh/CMakeLists.txt @@ -35,6 +35,7 @@ add_subdirectory(mesh) add_subdirectory(toggle) add_subdirectory(universe) add_subdirectory(onedim) +add_subdirectory(multidim) add_subdirectory(python) add_subdirectory(spacetime) add_subdirectory(view) @@ -84,6 +85,7 @@ set(MODMESH_TERMINAL_FILES ${MODMESH_TOGGLE_FILES} ${MODMESH_UNIVERSE_FILES} ${MODMESH_MESH_FILES} + ${MODMESH_MULTIDIM_FILES} ${MODMESH_DEVICE_FILES} ${MODMESH_ONEDIM_FILES} ${MODMESH_SPACETIME_FILES} diff --git a/cpp/modmesh/multidim/CMakeLists.txt b/cpp/modmesh/multidim/CMakeLists.txt new file mode 100644 index 00000000..eb239636 --- /dev/null +++ b/cpp/modmesh/multidim/CMakeLists.txt @@ -0,0 +1,30 @@ +# Copyright (c) 2019, Yung-Yu Chen +# BSD-style license; see COPYING + +cmake_minimum_required(VERSION 3.16) + +set(MODMESH_MULTIDIM_HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/multidim.hpp + ${CMAKE_CURRENT_SOURCE_DIR}/euler.hpp + CACHE FILEPATH "" FORCE) + +set(MODMESH_MULTIDIM_SOURCES + CACHE FILEPATH "" FORCE) + +set(MODMESH_MULTIDIM_PYMODHEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/pymod/multidim_pymod.hpp + CACHE FILEPATH "" FORCE) + +set(MODMESH_MULTIDIM_PYMODSOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/pymod/multidim_pymod.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/pymod/wrap_multidim.cpp + CACHE FILEPATH "" FORCE) + +set(MODMESH_MULTIDIM_FILES + ${MODMESH_MULTIDIM_HEADERS} + ${MODMESH_MULTIDIM_SOURCES} + ${MODMESH_MULTIDIM_PYMODHEADERS} + ${MODMESH_MULTIDIM_PYMODSOURCES} + CACHE FILEPATH "" FORCE) + +# vim: set ff=unix fenc=utf8 nobomb et sw=4 ts=4 sts=4: diff --git a/cpp/modmesh/multidim/euler.hpp b/cpp/modmesh/multidim/euler.hpp new file mode 100644 index 00000000..284a5306 --- /dev/null +++ b/cpp/modmesh/multidim/euler.hpp @@ -0,0 +1,86 @@ +#pragma once + +/* + * Copyright (c) 2024, Yung-Yu Chen + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * The space-time CESE solver for the Euler equation. + */ + +#include + +namespace modmesh +{ + +class EulerCore + : public NumberBase + , public std::enable_shared_from_this +{ + +private: + + class ctor_passkey + { + }; + +public: + + using number_base = NumberBase; + using int_type = typename number_base::int_type; + using uint_type = typename number_base::uint_type; + using real_type = typename number_base::real_type; + + template + static std::shared_ptr construct(Args &&... args) + { + return std::make_shared(std::forward(args)..., ctor_passkey()); + } + + EulerCore(std::shared_ptr const & mesh, real_type time_increment, ctor_passkey const &) + : m_mesh(mesh) + , m_time_increment(time_increment) + { + } + + EulerCore() = delete; + EulerCore(EulerCore const &) = delete; + EulerCore(EulerCore &&) = delete; + EulerCore operator=(EulerCore const &) = delete; + EulerCore operator=(EulerCore &&) = delete; + ~EulerCore() = default; + +private: + + std::shared_ptr m_mesh; + real_type m_time_increment = 0.0; + +}; /* end class EulerCore */ + +} /* end namespace modmesh */ + +// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4: diff --git a/cpp/modmesh/multidim/multidim.hpp b/cpp/modmesh/multidim/multidim.hpp new file mode 100644 index 00000000..52c19ac3 --- /dev/null +++ b/cpp/modmesh/multidim/multidim.hpp @@ -0,0 +1,38 @@ +#pragma once + +/* + * Copyright (c) 2024, Yung-Yu Chen + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/** + * Multi-dimensional space-time CESE solver. + */ + +#include +#include + +// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4: diff --git a/cpp/modmesh/multidim/pymod/multidim_pymod.cpp b/cpp/modmesh/multidim/pymod/multidim_pymod.cpp new file mode 100644 index 00000000..14bf2a0d --- /dev/null +++ b/cpp/modmesh/multidim/pymod/multidim_pymod.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024, Yung-Yu Chen + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include // Must be the first include for Python. +#include + +#include +#include + +namespace modmesh +{ + +namespace python +{ + +struct multidim_pymod_tag +{ +}; + +template <> +OneTimeInitializer & OneTimeInitializer::me() +{ + static OneTimeInitializer instance; + return instance; +} + +void initialize_multidim(pybind11::module & mod) +{ + auto initialize_impl = [](pybind11::module & mod) + { + wrap_multidim(mod); + }; + + OneTimeInitializer::me()(mod, initialize_impl); +} + +} /* end namespace python */ + +} /* end namespace modmesh */ + +// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4: diff --git a/cpp/modmesh/multidim/pymod/multidim_pymod.hpp b/cpp/modmesh/multidim/pymod/multidim_pymod.hpp new file mode 100644 index 00000000..d99563aa --- /dev/null +++ b/cpp/modmesh/multidim/pymod/multidim_pymod.hpp @@ -0,0 +1,50 @@ +#pragma once + +/* + * Copyright (c) 2024, Yung-Yu Chen + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include // Must be the first include. +#include + +#include +#include + +namespace modmesh +{ + +namespace python +{ + +void initialize_multidim(pybind11::module & mod); +void wrap_multidim(pybind11::module & mod); + +} /* end namespace python */ + +} /* end namespace modmesh */ + +// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4: diff --git a/cpp/modmesh/multidim/pymod/wrap_multidim.cpp b/cpp/modmesh/multidim/pymod/wrap_multidim.cpp new file mode 100644 index 00000000..7684ee14 --- /dev/null +++ b/cpp/modmesh/multidim/pymod/wrap_multidim.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2024, Yung-Yu Chen + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * - Neither the name of the copyright holder nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include // Must be the first include. + +#include + +namespace modmesh +{ + +namespace python +{ + +using namespace modmesh; // NOLINT(google-build-using-namespace) + +class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapEulerCore + : public WrapBase> +{ + +public: + + using base_type = WrapBase>; + using wrapper_type = typename base_type::wrapper_type; + using wrapped_type = typename base_type::wrapped_type; + + friend base_type; + +protected: + + WrapEulerCore(pybind11::module & mod, const char * pyname, const char * clsdoc) + : base_type(mod, pyname, clsdoc) + { + + namespace py = pybind11; + + (*this) + .def( + py::init( + [](std::shared_ptr const & mesh, wrapped_type::real_type time_increment) + { + return wrapped_type::construct(mesh, time_increment); + }), + py::arg("mesh"), + py::arg("time_increment")); + } + +}; /* end class WrapEulerCore */ + +void wrap_multidim(pybind11::module & mod) +{ + WrapEulerCore::commit(mod, "EulerCore", "Solve the Euler equation"); +} + +} /* end namespace python */ + +} /* end namespace modmesh */ + +// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4: diff --git a/cpp/modmesh/python/module.cpp b/cpp/modmesh/python/module.cpp index e734110e..0b80766e 100644 --- a/cpp/modmesh/python/module.cpp +++ b/cpp/modmesh/python/module.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -48,6 +49,7 @@ void initialize(pybind11::module_ mod) initialize_buffer(mod); initialize_universe(mod); initialize_mesh(mod); + initialize_multidim(mod); initialize_inout(mod); pybind11::module_ spacetime_mod = mod.def_submodule("spacetime", "spacetime"); initialize_spacetime(spacetime_mod); diff --git a/modmesh/core.py b/modmesh/core.py index ea452942..2b1fca42 100644 --- a/modmesh/core.py +++ b/modmesh/core.py @@ -78,6 +78,7 @@ 'StaticGrid2d', 'StaticGrid3d', 'StaticMesh', + 'EulerCore', 'HierarchicalToggleAccess', 'Toggle', 'CommandLineInfo', diff --git a/tests/test_euler.py b/tests/test_euler.py new file mode 100644 index 00000000..947b8a60 --- /dev/null +++ b/tests/test_euler.py @@ -0,0 +1,38 @@ +# Copyright (c) 2024, Yung-Yu Chen +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# - Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# - Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# - Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. + +import unittest + +import modmesh as mm + + +class EulerCoreTC(unittest.TestCase): + + def test_construct(self): + mh = mm.StaticMesh(ndim=2, nnode=0) + mm.EulerCore(mesh=mh, time_increment=0.0) + +# vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4: From a51342040209db0a89997fe93f22d33dd0005a5c Mon Sep 17 00:00:00 2001 From: Yung-Yu Chen Date: Thu, 8 Aug 2024 10:43:45 +0800 Subject: [PATCH 2/2] Remove unnecessary namespace using --- cpp/modmesh/multidim/pymod/wrap_multidim.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/cpp/modmesh/multidim/pymod/wrap_multidim.cpp b/cpp/modmesh/multidim/pymod/wrap_multidim.cpp index 7684ee14..e8151728 100644 --- a/cpp/modmesh/multidim/pymod/wrap_multidim.cpp +++ b/cpp/modmesh/multidim/pymod/wrap_multidim.cpp @@ -36,8 +36,6 @@ namespace modmesh namespace python { -using namespace modmesh; // NOLINT(google-build-using-namespace) - class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapEulerCore : public WrapBase> {