Skip to content

Commit 5607f69

Browse files
committed
Add OASIS Device (Only writer)
1 parent 90f77e7 commit 5607f69

11 files changed

Lines changed: 461 additions & 1 deletion

File tree

26.5 KB
Binary file not shown.

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: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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/oasis_device.hpp>
30+
#include <cstdint>
31+
32+
namespace modmesh
33+
{
34+
35+
namespace oasis
36+
{
37+
38+
/*
39+
* Implements Manhattan 1-delta encoding as defined in SEMI Draft Document 3626
40+
* Section 7.5: the sign of the input value is encoded as a direction bit in the
41+
* least significant bit, the absolute value is shifted and combined with this
42+
* bit to form the delta value, which is then encoded using a base-128 variable-
43+
* length scheme where each byte carries 7 bits and the MSB indicates whether
44+
* additional bytes follow.
45+
*/
46+
void append_1_delta(std::vector<uint8_t> & segment, int value)
47+
{
48+
const int DIR_BIT = value < 0 ? 1 : 0;
49+
int delta_codec = abs(value) << 1 | DIR_BIT;
50+
51+
int payload = delta_codec << 1;
52+
53+
if (payload == 0)
54+
{
55+
segment.push_back(0x02);
56+
}
57+
58+
while (payload >= 1)
59+
{
60+
int first_bit = payload >= 128 ? 1 : 0;
61+
segment.push_back((first_bit << 7) | (payload % 128));
62+
payload /= 128;
63+
}
64+
}
65+
66+
std::vector<uint8_t> OasisDevice::write(const std::vector<int32_t> & values)
67+
{
68+
std::vector<uint8_t> result;
69+
70+
for (int value : values)
71+
{
72+
append_1_delta(result, value);
73+
}
74+
75+
return result;
76+
}
77+
78+
} // namespace oasis
79+
80+
} // namespace modmesh
81+
82+
// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:

cpp/modmesh/oasis/oasis_device.hpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
namespace modmesh
38+
{
39+
40+
namespace oasis
41+
{
42+
43+
/**
44+
* \class OasisDevice
45+
* \brief OASIS device converts coordinates information to OASIS format.
46+
*
47+
* OasisDevice class convert coordinates information to OASIS format, the implementation based
48+
* on OASIS specification, convert coordinates information (xy) to OASIS geometry format.
49+
* The format are represented as byte-continuations. LSB present that the next bytes is belonging
50+
* the group or not.
51+
*/
52+
53+
static void append_1_delta(std::vector<uint8_t> & segment, int value);
54+
class OasisDevice
55+
{
56+
private:
57+
public:
58+
OasisDevice() = default;
59+
OasisDevice(OasisDevice const &) = default;
60+
OasisDevice(OasisDevice &&) = default;
61+
OasisDevice & operator=(OasisDevice const &) = default;
62+
OasisDevice & operator=(OasisDevice &&) = default;
63+
~OasisDevice() = default;
64+
65+
static std::vector<uint8_t> write(const std::vector<int32_t> & values);
66+
};
67+
68+
} // namespace oasis
69+
70+
} // namespace modmesh
71+
72+
// 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: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapOasisDevice
41+
: public WrapBase<WrapOasisDevice, oasis::OasisDevice, std::shared_ptr<oasis::OasisDevice>>
42+
{
43+
44+
public:
45+
46+
using base_type = WrapBase<WrapOasisDevice, oasis::OasisDevice, std::shared_ptr<oasis::OasisDevice>>;
47+
using wrapper_type = typename base_type::wrapper_type;
48+
using wrapped_type = typename base_type::wrapped_type;
49+
50+
friend base_type;
51+
52+
protected:
53+
54+
WrapOasisDevice(pybind11::module & mod, const char * pyname, const char * clsdoc)
55+
: base_type(mod, pyname, clsdoc)
56+
{
57+
namespace py = pybind11;
58+
59+
(*this)
60+
.def(py::init())
61+
.def_static("write", &wrapped_type::write, py::arg("values"));
62+
}
63+
}; /* end class WrapOASISDevice */
64+
65+
void wrap_oasis_device(pybind11::module & mod)
66+
{
67+
WrapOasisDevice::commit(mod, "OasisDevice", "OASIS Device that support unsigned value to manhattan delta bytes");
68+
}
69+
70+
} /* end namespace python */
71+
72+
} /* end namespace modmesh */
73+
74+
// vim: set ff=unix fenc=utf8 et sw=4 ts=4 sts=4:

0 commit comments

Comments
 (0)