Skip to content

Commit 8a2d55c

Browse files
committed
Create OasisDevice and adjust tests
1 parent 82888b3 commit 8a2d55c

10 files changed

Lines changed: 441 additions & 1 deletion

File tree

cpp/modmesh/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ add_subdirectory(mesh)
3535
add_subdirectory(toggle)
3636
add_subdirectory(universe)
3737
add_subdirectory(onedim)
38+
add_subdirectory(oasis)
3839
add_subdirectory(multidim)
3940
add_subdirectory(python)
4041
add_subdirectory(spacetime)
@@ -91,6 +92,7 @@ set(MODMESH_TERMINAL_FILES
9192
${MODMESH_MULTIDIM_FILES}
9293
${MODMESH_DEVICE_FILES}
9394
${MODMESH_ONEDIM_FILES}
95+
${MODMESH_OASIS_FILES}
9496
${MODMESH_SPACETIME_FILES}
9597
${MODMESH_PYTHON_FILES}
9698
${MODMESH_INOUT_FILES}

cpp/modmesh/oasis/CMakeLists.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright (c) 2026, Han-Xuan Huang <c1ydehhx@gmail.com>
2+
# BSD-style license; see COPYING
3+
4+
cmake_minimum_required(VERSION 4.0.1)
5+
6+
set(MODMESH_OASIS_HEADERS
7+
${CMAKE_CURRENT_SOURCE_DIR}/oasis_device.hpp
8+
CACHE FILEPATH "" FORCE)
9+
10+
set(MODMESH_OASIS_SOURCES
11+
${CMAKE_CURRENT_SOURCE_DIR}/oasis_device.cpp
12+
CACHE FILEPATH "" FORCE)
13+
14+
set(MODMESH_OASIS_PYMODHEADERS
15+
${CMAKE_CURRENT_SOURCE_DIR}/pymod/oasis_pymod.hpp
16+
CACHE FILEPATH "" FORCE)
17+
18+
set(MODMESH_OASIS_PYMODSOURCES
19+
${CMAKE_CURRENT_SOURCE_DIR}/pymod/oasis_pymod.cpp
20+
${CMAKE_CURRENT_SOURCE_DIR}/pymod/wrap_oasis.cpp
21+
CACHE FILEPATH "" FORCE)
22+
23+
set(MODMESH_OASIS_FILES
24+
${MODMESH_OASIS_HEADERS}
25+
${MODMESH_OASIS_SOURCES}
26+
${MODMESH_OASIS_PYMODHEADERS}
27+
${MODMESH_OASIS_PYMODSOURCES}
28+
CACHE FILEPATH "" FORCE)
29+
30+
# vim: set ff=unix fenc=utf8 nobomb et sw=4 ts=4 sts=4:

cpp/modmesh/oasis/oasis_device.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2026, Han-Xuan Huang <c1ydehhx@gmail.com>
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
*
7+
* - Redistributions of source code must retain the above copyright notice,
8+
* this list of conditions and the following disclaimer.
9+
* - Redistributions in binary form must reproduce the above copyright notice,
10+
* this list of conditions and the following disclaimer in the documentation
11+
* and/or other materials provided with the distribution.
12+
* - Neither the name of the copyright holder nor the names of its contributors
13+
* may be used to endorse or promote products derived from this software
14+
* without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
29+
#include "oasis_device.hpp"
30+
31+
namespace modmesh
32+
{
33+
34+
namespace oasis
35+
{
36+
37+
void OasisDevice::append_1_delta(bytes & segment, int value)
38+
{
39+
int dir_bit = value < 0 ? 1 : 0;
40+
int delta_codec = abs(value) << 1 | dir_bit;
41+
42+
int payload = delta_codec << 1;
43+
44+
if (payload == 0)
45+
{
46+
segment.push_back(0x02);
47+
}
48+
49+
while (payload >= 1)
50+
{
51+
int first_bit = payload >= 128 ? 1 : 0;
52+
segment.push_back((first_bit << 7) | (payload % 128));
53+
payload /= 128;
54+
}
55+
}
56+
57+
bytes OasisDevice::writer(std::vector<int32_t> & values)
58+
{
59+
bytes result;
60+
61+
for (int value : values)
62+
{
63+
append_1_delta(result, value);
64+
}
65+
66+
return result;
67+
}
68+
69+
} // namespace oasis
70+
71+
} // namespace modmesh
72+
73+
// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:

cpp/modmesh/oasis/oasis_device.hpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#pragma once
2+
3+
/*
4+
* Copyright (c) 2026, Han-Xuan Huang <c1ydehhx@gmail.com>
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* - Redistributions of source code must retain the above copyright notice,
10+
* this list of conditions and the following disclaimer.
11+
* - Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
* - Neither the name of the copyright holder nor the names of its contributors
15+
* may be used to endorse or promote products derived from this software
16+
* without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#include <modmesh/base.hpp>
32+
#include <pybind11/stl.h>
33+
34+
#include <cstdint>
35+
#include <vector>
36+
37+
using bytes = std::vector<uint8_t>;
38+
39+
namespace modmesh
40+
{
41+
42+
namespace oasis
43+
{
44+
45+
class OasisDevice
46+
{
47+
private:
48+
static void append_1_delta(bytes & segment, int value);
49+
50+
public:
51+
OasisDevice() = default;
52+
static bytes writer(std::vector<int32_t> & values);
53+
};
54+
55+
} // namespace oasis
56+
57+
} // namespace modmesh
58+
59+
// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) 2026, Han-Xuan Huang <c1ydehhx@gmail.com>
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
*
7+
* - Redistributions of source code must retain the above copyright notice,
8+
* this list of conditions and the following disclaimer.
9+
* - Redistributions in binary form must reproduce the above copyright notice,
10+
* this list of conditions and the following disclaimer in the documentation
11+
* and/or other materials provided with the distribution.
12+
* - Neither the name of the copyright holder nor the names of its contributors
13+
* may be used to endorse or promote products derived from this software
14+
* without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
29+
#include <modmesh/oasis/pymod/oasis_pymod.hpp> // Must be the first include.
30+
#include <pybind11/stl.h>
31+
32+
#include <modmesh/modmesh.hpp>
33+
#include <modmesh/python/common.hpp>
34+
35+
namespace modmesh
36+
{
37+
38+
namespace python
39+
{
40+
41+
struct oasis_pymod_tag
42+
{
43+
};
44+
45+
template <>
46+
OneTimeInitializer<oasis_pymod_tag> & OneTimeInitializer<oasis_pymod_tag>::me()
47+
{
48+
static OneTimeInitializer<oasis_pymod_tag> instance;
49+
return instance;
50+
}
51+
52+
void initialize_oasis(pybind11::module & mod)
53+
{
54+
auto initialize_impl = [](pybind11::module & mod)
55+
{
56+
wrap_oasis_device(mod);
57+
};
58+
59+
OneTimeInitializer<oasis_pymod_tag>::me()(mod, initialize_impl);
60+
}
61+
62+
} /* end namespace python */
63+
64+
} /* end namespace modmesh */
65+
66+
// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#pragma once
2+
3+
/*
4+
* Copyright (c) 2026, Han-Xuan Huang <c1ydehhx@gmail.com>
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* - Redistributions of source code must retain the above copyright notice,
10+
* this list of conditions and the following disclaimer.
11+
* - Redistributions in binary form must reproduce the above copyright notice,
12+
* this list of conditions and the following disclaimer in the documentation
13+
* and/or other materials provided with the distribution.
14+
* - Neither the name of the copyright holder nor the names of its contributors
15+
* may be used to endorse or promote products derived from this software
16+
* without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#include <modmesh/python/python.hpp> // Must be the first include.
32+
#include <pybind11/stl.h>
33+
34+
#include <modmesh/modmesh.hpp>
35+
#include <modmesh/python/common.hpp>
36+
37+
namespace modmesh
38+
{
39+
40+
namespace python
41+
{
42+
43+
void initialize_oasis(pybind11::module & mod);
44+
void wrap_oasis_device(pybind11::module & mod);
45+
46+
} /* end namespace python */
47+
48+
} /* end namespace modmesh */
49+
50+
// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2026, Han-Xuan Huang <c1ydehhx@gmail.com>
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions are met:
6+
*
7+
* - Redistributions of source code must retain the above copyright notice,
8+
* this list of conditions and the following disclaimer.
9+
* - Redistributions in binary form must reproduce the above copyright notice,
10+
* this list of conditions and the following disclaimer in the documentation
11+
* and/or other materials provided with the distribution.
12+
* - Neither the name of the copyright holder nor the names of its contributors
13+
* may be used to endorse or promote products derived from this software
14+
* without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*/
28+
29+
#include <modmesh/oasis/pymod/oasis_pymod.hpp> // Must be the first include.
30+
#include <modmesh/modmesh.hpp>
31+
32+
#include <modmesh/oasis/oasis_device.hpp>
33+
34+
namespace modmesh
35+
{
36+
37+
namespace python
38+
{
39+
40+
using namespace modmesh::oasis; // NOLINT(google-build-using-namespace)
41+
42+
class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapOasisDevice
43+
: public WrapBase<WrapOasisDevice, OasisDevice, std::shared_ptr<OasisDevice>>
44+
{
45+
46+
public:
47+
48+
using base_type = WrapBase<WrapOasisDevice, OasisDevice, std::shared_ptr<OasisDevice>>;
49+
using wrapper_type = typename base_type::wrapper_type;
50+
using wrapped_type = typename base_type::wrapped_type;
51+
52+
friend base_type;
53+
54+
protected:
55+
56+
WrapOasisDevice(pybind11::module & mod, const char * pyname, const char * clsdoc)
57+
: base_type(mod, pyname, clsdoc)
58+
{
59+
namespace py = pybind11;
60+
61+
(*this)
62+
.def(py::init())
63+
.def_static("writer", &wrapped_type::writer, py::arg("values"));
64+
}
65+
}; /* end class WrapOASISDevice */
66+
67+
void wrap_oasis_device(pybind11::module & mod)
68+
{
69+
WrapOasisDevice::commit(mod, "OasisDevice", "OASIS Device that support unsigned value to manhattan delta bytes");
70+
}
71+
72+
} /* end namespace python */
73+
74+
} /* end namespace modmesh */
75+
76+
// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:

cpp/modmesh/python/module.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <modmesh/math/pymod/math_pymod.hpp>
3434
#include <modmesh/transform/pymod/transform_pymod.hpp>
3535
#include <modmesh/linalg/pymod/linalg_pymod.hpp>
36+
#include <modmesh/oasis/pymod/oasis_pymod.hpp>
3637

3738
#ifdef USE_PYTEST_HELPER_BINDING
3839
#include <modmesh/testhelper/pymod/testbuffer_pymod.hpp>
@@ -63,6 +64,7 @@ void initialize(pybind11::module_ mod)
6364
pybind11::module_ onedim_mod = mod.def_submodule("onedim", "onedim");
6465
initialize_onedim(onedim_mod);
6566
initialize_transform(mod);
67+
initialize_oasis(mod);
6668

6769
pybind11::module_ testhelper_mod = mod.def_submodule("testhelper", "testhelper");
6870
#ifdef USE_PYTEST_HELPER_BINDING

0 commit comments

Comments
 (0)