diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index b8bb43bfcd4caaedb05dd3cddf9684e5dccd446c..514379ed3c5e67869216d844d1233579e3ebb90a 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -28,7 +28,7 @@ walberla_codegen_venv_install( add_executable ( HeatEquationWithMaterial ) target_sources( HeatEquationWithMaterial PRIVATE CodegenHeatEquationWithMaterial.cpp ) target_link_libraries( HeatEquationWithMaterial PRIVATE walberla::blockforest walberla::core walberla::field walberla::stencil walberla::timeloop walberla::vtk walberla::pde ) -target_link_libraries( HeatEquationWithMaterial PRIVATE interpolation_template ) +target_link_libraries( HeatEquationWithMaterial PRIVATE pymatlib_interpolators ) pystencilssfg_generate_target_sources( HeatEquationWithMaterial SCRIPTS HeatEquationKernelWithMaterial.py diff --git a/pyproject.toml b/pyproject.toml index d5499a57022828b4989391f2fec6b7dab691217e..92725cc71b07504bb04df9bfc9847aa2b1ba8cb4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,7 @@ test = [ requires = [ "setuptools>=69", "wheel", - "pybind11", + # "pybind11", "ruamel.yaml>=0.15.70", #"PyYAML", "pandas", diff --git a/requirements.txt b/requirements.txt index 30df18c9e3f892d7df256c977f37bcd00e04b059..fc39e17135769596d63048d463284f1989fc5861 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,6 +10,6 @@ matplotlib~=3.10.0 scipy~=1.15.1 setuptools~=75.8.0 versioneer~=0.29 -pybind11~=2.14.0.dev1 +# pybind11~=2.14.0.dev1 pandas~=2.2.3 openpyxl~=3.1.5 diff --git a/setup.py b/setup.py index 594f94fd72e39e0f3f954848372f5b2582c7d8be..5e7af273e6f4c92c384a4176bb2e26e4234b6c60 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,9 @@ from setuptools import setup, find_packages, Extension -import pybind11 +# import pybind11 # Define the extension module -ext_modules = [ +'''ext_modules = [ Extension( "pymatlib.core.cpp.fast_interpolation", # Module name in Python [ @@ -16,7 +16,7 @@ ext_modules = [ extra_compile_args=['-O3', '-std=c++11'], # Enable high optimization and C++11 language='c++' ), -] +]''' setup( name='pymatlib', @@ -44,7 +44,7 @@ setup( 'sympy>=1.7.0', 'pytest>=6.0.0', 'pystencils@git+https://i10git.cs.fau.de/pycodegen/pystencils.git@v2.0-dev', - 'pybind11>=2.6.0', + # 'pybind11>=2.6.0', ], extras_require={ 'dev': [ @@ -53,6 +53,6 @@ setup( 'black', # For code formatting ], }, - ext_modules=ext_modules, + # ext_modules=ext_modules, include_package_data=True, # Include package data specified in MANIFEST.in ) diff --git a/src/pymatlib/core/alloy.py b/src/pymatlib/core/alloy.py index f7b51725144c70167f92c89546307c1b9102084b..e612aec3225d4b59d5ccc83b798ef7c4a515ad82 100644 --- a/src/pymatlib/core/alloy.py +++ b/src/pymatlib/core/alloy.py @@ -76,6 +76,7 @@ class Alloy: latent_heat_of_vaporization: PropertyTypes = None specific_enthalpy: PropertyTypes = None surface_tension: PropertyTypes = None + temperature: PropertyTypes = None temperature_array: np.ndarray = field(default_factory=lambda: np.array([])) thermal_diffusivity: PropertyTypes = None thermal_expansion_coefficient: PropertyTypes = None diff --git a/src/pymatlib/core/cpp/CMakeLists.txt b/src/pymatlib/core/cpp/CMakeLists.txt index 30dbbf063ab63c0e65691060a8c01345a329f481..104090d9b8f122db6ed87140b4fbe720f9235ba1 100644 --- a/src/pymatlib/core/cpp/CMakeLists.txt +++ b/src/pymatlib/core/cpp/CMakeLists.txt @@ -1,35 +1,33 @@ cmake_minimum_required(VERSION 3.10) -project(fast_interpolation) +project(pymatlib_interpolators) # Find required packages find_package(Python COMPONENTS Interpreter Development NumPy REQUIRED) -execute_process( - COMMAND ${Python_EXECUTABLE} -m pybind11 --cmakedir - OUTPUT_VARIABLE PYBIND11_CMAKE_DIR - OUTPUT_STRIP_TRAILING_WHITESPACE -) -find_package(pybind11 PATHS ${PYBIND11_CMAKE_DIR} NO_DEFAULT_PATH REQUIRED) +# execute_process( +# COMMAND ${Python_EXECUTABLE} -m pybind11 --cmakedir +# OUTPUT_VARIABLE PYBIND11_CMAKE_DIR +# OUTPUT_STRIP_TRAILING_WHITESPACE +# ) +# find_package(pybind11 PATHS ${PYBIND11_CMAKE_DIR} NO_DEFAULT_PATH REQUIRED) # Create interface library for header-only template implementation -add_library(interpolation_template INTERFACE) -target_include_directories(interpolation_template INTERFACE - ${CMAKE_CURRENT_SOURCE_DIR} +add_library(pymatlib_interpolators INTERFACE) +target_include_directories(pymatlib_interpolators INTERFACE + # ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include ) # Add the Pybind11 module -pybind11_add_module(fast_interpolation - module.cpp - binary_search_interpolation.cpp - double_lookup_interpolation.cpp -) -target_include_directories(fast_interpolation PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/include -) -target_compile_features(fast_interpolation PRIVATE cxx_std_11) -target_compile_options(fast_interpolation PRIVATE -O3) -target_link_libraries(fast_interpolation PRIVATE - interpolation_template - pybind11::module - Python::NumPy -) +# pybind11_add_module(fast_interpolation +# module.cpp +# ) +# target_include_directories(fast_interpolation PRIVATE +# ${CMAKE_CURRENT_SOURCE_DIR}/include +# ) +# target_compile_features(fast_interpolation PRIVATE cxx_std_11) +# target_compile_options(fast_interpolation PRIVATE -O3) +# target_link_libraries(fast_interpolation PRIVATE +# interpolation_template +# pybind11::module +# Python::NumPy +# ) diff --git a/src/pymatlib/core/cpp/binary_search_interpolation.cpp b/src/pymatlib/core/cpp/binary_search_interpolation.cpp deleted file mode 100644 index 9f7926aa8e27bd9c0c8347cea5fa9f3aa6e10fba..0000000000000000000000000000000000000000 --- a/src/pymatlib/core/cpp/binary_search_interpolation.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "include/binary_search_interpolation.h" -#include <iostream> -#include <cmath> - - -double interpolate_binary_search( - const py::array_t<double>& temperature_array, - double h_in, - const py::array_t<double>& energy_density_array) { - - static constexpr double EPSILON = 1e-6; - - // Get array views - auto temp_arr = temperature_array.unchecked<1>(); - auto energy_arr = energy_density_array.unchecked<1>(); - const size_t n = temp_arr.shape(0); - - // Input validation - if (temperature_array.size() != energy_density_array.size() || n < 2) { - throw std::runtime_error("Invalid array sizes"); - } - - // Determine array order and cache indices - const bool is_ascending = temp_arr(0) < temp_arr(n-1); - - const size_t start_idx = is_ascending ? 0 : n-1; - const size_t end_idx = is_ascending ? n-1 : 0; - - // Boundary checks - if (h_in <= energy_arr(start_idx)) return temp_arr(start_idx); - if (h_in >= energy_arr(end_idx)) return temp_arr(end_idx); - - // Binary search with optimized memory access - size_t left = 0; - size_t right = n - 1; - - while (left <= right) { - const size_t mid = (left + right) / 2; - const double mid_val = energy_arr(mid); - - if (std::abs(mid_val - h_in) < EPSILON) { - return temp_arr(mid); - } - - const bool go_left = (mid_val > h_in) == is_ascending; - if (go_left) { - right = mid - 1; - } else { - left = mid + 1; - } - } - - - // Linear interpolation - const double x0 = energy_arr(right); - const double x1 = energy_arr(left); - const double y0 = temp_arr(right); - const double y1 = temp_arr(left); - - return y0 + (y1 - y0) * (h_in - x0) / (x1 - x0); -} diff --git a/src/pymatlib/core/cpp/double_lookup_interpolation.cpp b/src/pymatlib/core/cpp/double_lookup_interpolation.cpp deleted file mode 100644 index 0f7b10f1f434b29709103571ec118d567e7e8e5e..0000000000000000000000000000000000000000 --- a/src/pymatlib/core/cpp/double_lookup_interpolation.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "include/double_lookup_interpolation.h" -#include <iostream> -#include <cmath> - - -double interpolate_double_lookup( - double E_target, - const py::array_t<double>& T_eq, - const py::array_t<double>& E_neq, - const py::array_t<double>& E_eq, - double inv_delta_E_eq, - const py::array_t<int32_t>& idx_map) { - - // Get array views with bounds checking disabled for performance - auto T_eq_arr = T_eq.unchecked<1>(); - auto E_neq_arr = E_neq.unchecked<1>(); - auto E_eq_arr = E_eq.unchecked<1>(); - auto idx_map_arr = idx_map.unchecked<1>(); - - // Cache array size - const size_t n = T_eq_arr.shape(0); - - // Quick boundary checks with cached values - if (E_target <= E_neq_arr(0)) { - return T_eq_arr(0); - } - - if (E_target >= E_neq_arr(n-1)) { - return T_eq_arr(n-1); - } - - const int idx_E_eq = static_cast<int>((E_target - E_eq_arr(0)) * inv_delta_E_eq); - - int idx_E_neq = idx_map_arr(idx_E_eq); - - idx_E_neq += E_neq_arr(idx_E_neq + 1) < E_target; - - // Get interpolation index - const double E1 = E_neq_arr(idx_E_neq); - const double E2 = E_neq_arr(idx_E_neq + 1); - const double T1 = T_eq_arr(idx_E_neq); - const double T2 = T_eq_arr(idx_E_neq + 1); - - // Optimized linear interpolation - const double slope = (T2 - T1) / (E2 - E1); - return T1 + slope * (E_target - E1); -} diff --git a/src/pymatlib/core/cpp/include/binary_search_interpolation.h b/src/pymatlib/core/cpp/include/binary_search_interpolation.h deleted file mode 100644 index 2b4dc4cbd5ca06e74f6e008ef7ad5e53daddb534..0000000000000000000000000000000000000000 --- a/src/pymatlib/core/cpp/include/binary_search_interpolation.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once -#include <pybind11/pybind11.h> -#include <pybind11/numpy.h> -#include "interpolate_binary_search_cpp.h" - -namespace py = pybind11; - -/** - * Fast temperature interpolation using interpolation search with binary fallback - * - * @param temperature_array Array of temperature values (monotonically decreasing) - * @param h_in Energy density value to interpolate - * @param energy_density_array Array of energy density values (monotonically decreasing) - * @return Interpolated temperature value - * @throws std::runtime_error if arrays have different lengths or wrong monotonicity - */ -double interpolate_binary_search( - const py::array_t<double>& temperature_array, - double h_in, - const py::array_t<double>& energy_density_array); diff --git a/src/pymatlib/core/cpp/include/double_lookup_interpolation.h b/src/pymatlib/core/cpp/include/double_lookup_interpolation.h deleted file mode 100644 index 62efae5cd7fd149a5fb8a74670e0a4620494c3c7..0000000000000000000000000000000000000000 --- a/src/pymatlib/core/cpp/include/double_lookup_interpolation.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef DOUBLE_LOOKUP_INTERPOLATION_H -#define DOUBLE_LOOKUP_INTERPOLATION_H - -#include <pybind11/pybind11.h> -#include <pybind11/numpy.h> -#include "interpolate_double_lookup_cpp.h" - -namespace py = pybind11; - -double interpolate_double_lookup( - double E_target, - const py::array_t<double>& T_eq, - const py::array_t<double>& E_neq, - const py::array_t<double>& E_eq, - double inv_delta_E_eq, - const py::array_t<int32_t>& idx_map); - -#endif // DOUBLE_LOOKUP_INTERPOLATION_H diff --git a/src/pymatlib/core/cpp/include/interpolate_binary_search_cpp.h b/src/pymatlib/core/cpp/include/pymatlib_interpolators/interpolate_binary_search_cpp.h similarity index 100% rename from src/pymatlib/core/cpp/include/interpolate_binary_search_cpp.h rename to src/pymatlib/core/cpp/include/pymatlib_interpolators/interpolate_binary_search_cpp.h diff --git a/src/pymatlib/core/cpp/include/interpolate_double_lookup_cpp.h b/src/pymatlib/core/cpp/include/pymatlib_interpolators/interpolate_double_lookup_cpp.h similarity index 100% rename from src/pymatlib/core/cpp/include/interpolate_double_lookup_cpp.h rename to src/pymatlib/core/cpp/include/pymatlib_interpolators/interpolate_double_lookup_cpp.h diff --git a/src/pymatlib/core/cpp/module.cpp b/src/pymatlib/core/cpp/module.cpp deleted file mode 100644 index e05bbb873e38973d051c3971359a1e52573ba2e3..0000000000000000000000000000000000000000 --- a/src/pymatlib/core/cpp/module.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include <pybind11/pybind11.h> -#include <pybind11/numpy.h> -#include "include/binary_search_interpolation.h" -#include "include/double_lookup_interpolation.h" - -namespace py = pybind11; - -PYBIND11_MODULE(fast_interpolation, m) { - m.doc() = "Fast interpolation methods implementation"; - - m.def("interpolate_binary_search", - &interpolate_binary_search, - "Find temperature using binary search and linear interpolation", - py::arg("temperature_array"), - py::arg("h_in"), - py::arg("energy_density_array")); - - m.def("interpolate_double_lookup", - &interpolate_double_lookup, - "Fast interpolation using double lookup method and linear interpolation", - py::arg("E_target"), - py::arg("T_eq"), - py::arg("E_neq"), - py::arg("E_eq"), - py::arg("inv_delta_E_eq"), - py::arg("idx_map")); -} diff --git a/src/pymatlib/core/interpolators.py b/src/pymatlib/core/interpolators.py index 4cb90bd58710931bde0bab7b149673b4c0c3aa31..d00d314707b70b7537f47890bf59fb050b72d231 100644 --- a/src/pymatlib/core/interpolators.py +++ b/src/pymatlib/core/interpolators.py @@ -44,7 +44,7 @@ class InterpolationArrayContainer(CustomGenerator): def generate(self, sfg: SfgComposer): sfg.include("<array>") - sfg.include("interpolate_binary_search_cpp.h") + sfg.include("pymatlib_interpolators/interpolate_binary_search_cpp.h") # Binary search arrays (always included) T_bs_arr_values = ", ".join(str(v) for v in self.T_bs) @@ -65,7 +65,7 @@ class InterpolationArrayContainer(CustomGenerator): # Add double lookup if available if self.has_double_lookup: - sfg.include("interpolate_double_lookup_cpp.h") + sfg.include("pymatlib_interpolators/interpolate_double_lookup_cpp.h") T_eq_arr_values = ", ".join(str(v) for v in self.T_eq) E_neq_arr_values = ", ".join(str(v) for v in self.E_neq) diff --git a/src/pymatlib/data/alloys/SS316L/SS316L.py b/src/pymatlib/data/alloys/SS316L/SS316L.py index b346e0b3024cce7788b1fd9247526d99a4784fcd..86de8aaa5025b51dbdb960d70aff1fe05cfd40a9 100644 --- a/src/pymatlib/data/alloys/SS316L/SS316L.py +++ b/src/pymatlib/data/alloys/SS316L/SS316L.py @@ -8,8 +8,7 @@ from pymatlib.core.alloy import Alloy from pymatlib.data.element_data import Fe, Cr, Ni, Mo, Mn from pymatlib.core.models import thermal_diffusivity_by_heat_conductivity, density_by_thermal_expansion, energy_density, energy_density_total_enthalpy from pymatlib.core.data_handler import read_data_from_txt, celsius_to_kelvin, thousand_times, read_data_from_excel, read_data_from_file, plot_arrays -from pymatlib.core.interpolators import interpolate_property, prepare_interpolation_arrays#, interpolate_binary_search -from pymatlib.core.cpp.fast_interpolation import interpolate_binary_search, interpolate_double_lookup +from pymatlib.core.interpolators import interpolate_property, prepare_interpolation_arrays, interpolate_binary_search, interpolate_double_lookup def create_SS316L(T: Union[float, sp.Symbol]) -> Alloy: