blending_simulator_lib 2026.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ cmake_minimum_required(VERSION 3.15)
2
+
3
+ project(
4
+ ${SKBUILD_PROJECT_NAME}
5
+ VERSION ${SKBUILD_PROJECT_VERSION}
6
+ LANGUAGES CXX
7
+ )
8
+
9
+ find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
10
+ find_package(pybind11 CONFIG REQUIRED)
11
+
12
+ include(FetchContent)
13
+
14
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
15
+
16
+ FetchContent_Declare(
17
+ blending-simulation
18
+ GIT_REPOSITORY https://github.com/jcbachmann/blending-simulation
19
+ GIT_TAG master
20
+ )
21
+ FetchContent_MakeAvailable(blending-simulation)
22
+
23
+ pybind11_add_module(
24
+ _blending_simulator_lib
25
+ src/blending_simulator_lib/_bindings.cpp
26
+ )
27
+
28
+ set_target_properties(
29
+ _blending_simulator_lib PROPERTIES
30
+ CXX_STANDARD_REQUIRED 17
31
+ )
32
+
33
+ target_link_libraries(
34
+ _blending_simulator_lib PRIVATE
35
+ BlendingSimulator::Lib
36
+ BlendingSimulator::FastLib
37
+ BlendingSimulator::DetailedLib
38
+ pybind11::pybind11
39
+ )
40
+
41
+ install(TARGETS _blending_simulator_lib DESTINATION ${SKBUILD_PROJECT_NAME})
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Michael Cipold
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,34 @@
1
+ Metadata-Version: 2.4
2
+ Name: blending_simulator_lib
3
+ Version: 2026.1
4
+ Summary: Blending Simulation for Bulk Material Homogenization
5
+ Keywords: blending,simulation,cpp,pybind11,bmh
6
+ Author-Email: Michael Cipold <github@cipold.de>
7
+ License-Expression: MIT
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: C++
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Development Status :: 4 - Beta
12
+ Project-URL: Homepage, https://github.com/jcbachmann/blending-evaluation
13
+ Project-URL: Repository, https://github.com/jcbachmann/blending-evaluation
14
+ Requires-Python: >=3.10
15
+ Requires-Dist: numpy>=1.20.0
16
+ Provides-Extra: dev
17
+ Requires-Dist: pybind11-stubgen; extra == "dev"
18
+ Description-Content-Type: text/markdown
19
+
20
+ # Blending Simulator Lib (blending_simulator_lib)
21
+
22
+ [![PyPI version](https://img.shields.io/pypi/v/blending_simulator_lib.svg)](https://pypi.org/project/blending_simulator_lib/)
23
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
24
+
25
+ Simulation library for Bulk Material Homogenization, implemented in C++.
26
+
27
+ ## Development
28
+
29
+ After making changes to the module, you need to regenerate the stubs. To regenerate the stubs, execute this command from
30
+ the package directory:
31
+
32
+ ```bash
33
+ uv run pybind11-stubgen blending_simulator_lib._blending_simulator_lib -o src
34
+ ```
@@ -0,0 +1,15 @@
1
+ # Blending Simulator Lib (blending_simulator_lib)
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/blending_simulator_lib.svg)](https://pypi.org/project/blending_simulator_lib/)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ Simulation library for Bulk Material Homogenization, implemented in C++.
7
+
8
+ ## Development
9
+
10
+ After making changes to the module, you need to regenerate the stubs. To regenerate the stubs, execute this command from
11
+ the package directory:
12
+
13
+ ```bash
14
+ uv run pybind11-stubgen blending_simulator_lib._blending_simulator_lib -o src
15
+ ```
@@ -0,0 +1,44 @@
1
+ [build-system]
2
+ requires = ["scikit-build-core", "pybind11"]
3
+ build-backend = "scikit_build_core.build"
4
+
5
+ [project]
6
+ name = "blending_simulator_lib"
7
+ version = "2026.1"
8
+ description = "Blending Simulation for Bulk Material Homogenization"
9
+ keywords = ["blending", "simulation", "cpp", "pybind11", "bmh"]
10
+ readme = "README.md"
11
+ authors = [
12
+ { name = "Michael Cipold", email = "github@cipold.de" }
13
+ ]
14
+ requires-python = ">=3.10"
15
+ dependencies = [
16
+ "numpy>=1.20.0",
17
+ ]
18
+ license = "MIT"
19
+ classifiers = [
20
+ "Programming Language :: Python :: 3",
21
+ "Programming Language :: C++",
22
+ "Operating System :: OS Independent",
23
+ "Development Status :: 4 - Beta",
24
+ ]
25
+
26
+ [project.urls]
27
+ Homepage = "https://github.com/jcbachmann/blending-evaluation"
28
+ Repository = "https://github.com/jcbachmann/blending-evaluation"
29
+
30
+ [project.optional-dependencies]
31
+ dev = ["pybind11-stubgen"]
32
+
33
+ [tool.setuptools.package-data]
34
+ "blending_simulator_lib" = ["_blending_simulator_lib.pyi", "py.typed"]
35
+
36
+ [tool.scikit-build]
37
+ wheel.py-api = "cp312"
38
+ cmake.args = [
39
+ "-DBUILD_VISUALIZER=OFF",
40
+ "-DBUILD_TESTS=OFF",
41
+ "-DBUILD_CLI=OFF",
42
+ "-DBUILD_FAST_SIMULATOR=ON",
43
+ "-DBUILD_DETAILED_SIMULATOR=ON"
44
+ ]
@@ -0,0 +1,5 @@
1
+ from ._blending_simulator_lib import BlendingSimulatorLib
2
+
3
+ __all__ = [
4
+ "BlendingSimulatorLib",
5
+ ]
@@ -0,0 +1,167 @@
1
+ #include <iostream>
2
+
3
+ #include <pybind11/pybind11.h>
4
+ #include <pybind11/stl.h>
5
+ #include <pybind11/numpy.h>
6
+
7
+ namespace py = pybind11;
8
+ using namespace pybind11::literals;
9
+
10
+ #include "BlendingSimulator/BlendingSimulatorFast.h"
11
+ #include "BlendingSimulator/BlendingSimulatorDetailed.h"
12
+ #include "BlendingSimulator/ParticleParameters.h"
13
+
14
+ namespace bs = blendingsimulator;
15
+
16
+ class BlendingSimulatorLibPython
17
+ {
18
+ public:
19
+ BlendingSimulatorLibPython(float heapWorldSizeX, float heapWorldSizeZ, float reclaimAngle, float particlesPerCubicMeter, bool circular,
20
+ float eightLikelihood, float bulkDensityFactor, float dropHeight, bool detailed, float reclaimIncrement)
21
+ : reclaimIncrement(reclaimIncrement)
22
+ , verbose(false)
23
+ {
24
+ bs::SimulationParameters simulationParameters{
25
+ heapWorldSizeX,
26
+ heapWorldSizeZ,
27
+ reclaimAngle,
28
+ particlesPerCubicMeter,
29
+ circular,
30
+ eightLikelihood,
31
+ false, // visualize - not available in python library
32
+ bulkDensityFactor,
33
+ dropHeight
34
+ };
35
+
36
+ if (detailed) {
37
+ simulator = new bs::BlendingSimulatorDetailed<bs::AveragedParameters>(simulationParameters);
38
+ } else {
39
+ simulator = new bs::BlendingSimulatorFast<bs::AveragedParameters>(simulationParameters);
40
+ }
41
+ }
42
+
43
+ ~BlendingSimulatorLibPython()
44
+ {
45
+ delete simulator;
46
+ }
47
+
48
+ void stack(double timestamp, float x, float z, double volume, const std::vector<double>& parameter)
49
+ {
50
+ simulator->stack(x, z, bs::AveragedParameters(volume, parameter));
51
+ }
52
+
53
+ void stackList(const py::array_t<double>& data, const std::vector<std::string>& columns)
54
+ {
55
+ // int timestampCol = -1;
56
+ int xCol = -1;
57
+ int zCol = -1;
58
+ int volumeCol = -1;
59
+ std::vector<int> parameterColumnIndices;
60
+
61
+ for (int i = 0; i < columns.size(); i++) {
62
+ if (columns[i] == "timestamp") {
63
+ // timestampCol = i;
64
+ } else if (columns[i] == "x") {
65
+ xCol = i;
66
+ } else if (columns[i] == "z") {
67
+ zCol = i;
68
+ } else if (columns[i] == "volume") {
69
+ volumeCol = i;
70
+ } else {
71
+ parameterColumnIndices.push_back(i);
72
+ parameterColumns.push_back(columns[i]);
73
+ }
74
+ }
75
+
76
+ auto dataRef = data.unchecked<2>();
77
+
78
+ for (py::ssize_t i = 0; i < dataRef.shape(0); i++) {
79
+ std::vector<double> values(parameterColumnIndices.size());
80
+ for (int j = 0; j < parameterColumnIndices.size(); j++) {
81
+ values[j] = dataRef(i, parameterColumnIndices[j]);
82
+ }
83
+ simulator->stack(
84
+ (float)dataRef(i, xCol),
85
+ (float)dataRef(i, zCol),
86
+ bs::AveragedParameters(dataRef(i, volumeCol), values)
87
+ );
88
+ }
89
+ }
90
+
91
+ py::dict reclaim()
92
+ {
93
+ finishStacking();
94
+
95
+ if (verbose) {
96
+ std::cerr << "Reclaiming" << std::endl;
97
+ }
98
+
99
+ py::list x;
100
+ py::list volume;
101
+ std::vector<py::list> parameter(parameterColumns.size());
102
+
103
+ float position = 0.0f;
104
+ while (!simulator->reclaimingFinished()) {
105
+ bs::AveragedParameters p = simulator->reclaim(position);
106
+ x.append(position);
107
+ volume.append(p.getVolume());
108
+ const auto& values = p.getValues();
109
+ for (int i = 0; i < parameterColumns.size(); i++) {
110
+ parameter[i].append(i < values.size() ? values[i] : 0);
111
+ }
112
+ position += reclaimIncrement;
113
+ }
114
+
115
+ py::dict ret("x"_a = x, "volume"_a = volume);
116
+ for (int i = 0; i < parameterColumns.size(); i++) {
117
+ ret[parameterColumns[i].c_str()] = parameter[i];
118
+ }
119
+ return ret;
120
+ }
121
+
122
+ std::vector<std::vector<float>> getHeights()
123
+ {
124
+ finishStacking();
125
+
126
+ if (verbose) {
127
+ std::cerr << "Acquiring heights" << std::endl;
128
+ }
129
+
130
+ auto heapMapSize = simulator->getHeapMapSize();
131
+ std::vector<std::vector<float>> heights;
132
+ heights.reserve(heapMapSize.second);
133
+ const float* heapMap = simulator->getHeapMap(); // +1 for Y coordinate
134
+ for (int z = 0; z < heapMapSize.second; z++) {
135
+ heights.emplace_back(heapMap + z * heapMapSize.first + 1, heapMap + z * heapMapSize.first + 1 + heapMapSize.first);
136
+ }
137
+
138
+ return heights;
139
+ }
140
+
141
+ private:
142
+ bs::BlendingSimulator<bs::AveragedParameters>* simulator;
143
+ float reclaimIncrement;
144
+ std::vector<std::string> parameterColumns;
145
+ bool verbose;
146
+
147
+ void finishStacking()
148
+ {
149
+ simulator->finishStacking();
150
+
151
+ if (verbose) {
152
+ std::cerr << "Stacking finished" << std::endl;
153
+ }
154
+ }
155
+ };
156
+
157
+ PYBIND11_MODULE(_blending_simulator_lib, m)
158
+ {
159
+ m.doc() = "Blending Simulator Lib for Python";
160
+
161
+ py::class_<BlendingSimulatorLibPython>(m, "BlendingSimulatorLib")
162
+ .def(py::init<float, float, float, float, bool, float, float, float, bool, float>())
163
+ .def("stack", &BlendingSimulatorLibPython::stack)
164
+ .def("stack_list", &BlendingSimulatorLibPython::stackList)
165
+ .def("reclaim", &BlendingSimulatorLibPython::reclaim)
166
+ .def("get_heights", &BlendingSimulatorLibPython::getHeights);
167
+ }
@@ -0,0 +1,39 @@
1
+ """
2
+ Blending Simulator Lib for Python
3
+ """
4
+
5
+ from __future__ import annotations
6
+
7
+ import collections.abc
8
+ import typing
9
+
10
+ import numpy
11
+ import numpy.typing
12
+
13
+ __all__: list[str] = ["BlendingSimulatorLib"]
14
+
15
+ class BlendingSimulatorLib:
16
+ def __init__(
17
+ self,
18
+ arg0: typing.SupportsFloat | typing.SupportsIndex,
19
+ arg1: typing.SupportsFloat | typing.SupportsIndex,
20
+ arg2: typing.SupportsFloat | typing.SupportsIndex,
21
+ arg3: typing.SupportsFloat | typing.SupportsIndex,
22
+ arg4: bool,
23
+ arg5: typing.SupportsFloat | typing.SupportsIndex,
24
+ arg6: typing.SupportsFloat | typing.SupportsIndex,
25
+ arg7: typing.SupportsFloat | typing.SupportsIndex,
26
+ arg8: bool,
27
+ arg9: typing.SupportsFloat | typing.SupportsIndex,
28
+ ) -> None: ...
29
+ def get_heights(self) -> list[list[float]]: ...
30
+ def reclaim(self) -> dict: ...
31
+ def stack(
32
+ self,
33
+ arg0: typing.SupportsFloat | typing.SupportsIndex,
34
+ arg1: typing.SupportsFloat | typing.SupportsIndex,
35
+ arg2: typing.SupportsFloat | typing.SupportsIndex,
36
+ arg3: typing.SupportsFloat | typing.SupportsIndex,
37
+ arg4: collections.abc.Sequence[typing.SupportsFloat | typing.SupportsIndex],
38
+ ) -> None: ...
39
+ def stack_list(self, arg0: typing.Annotated[numpy.typing.ArrayLike, numpy.float64], arg1: collections.abc.Sequence[str]) -> None: ...