diff --git a/CMakeLists.txt b/CMakeLists.txt index ba35020d9d893637d82d968b68116ff6a922e99a..163ec4f05ee8b12d7641f3856ae4640565101851 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -199,3 +199,8 @@ if(BUILD_VF_GPU OR BUILD_VF_GKS) add_subdirectory(src/cuda) include (gpu.cmake) endif() + +if (BUILD_VF_PYTHON_BINDINGS) + add_subdirectory(${VF_THIRD_DIR}/pybind11/pybind11-2.6.0) + add_subdirectory(pythonbindings) +endif() diff --git a/Python/acousticscaling.py b/Python/acousticscaling.py index 50b81db064251fa269f29bf72a561567ddedafbc..6622685a9f2d2ce14cb952cc92dcd9580e535bae 100644 --- a/Python/acousticscaling.py +++ b/Python/acousticscaling.py @@ -13,10 +13,10 @@ class OneDirectionalAcousticScaling: self._runtime_params = runtime_parameters self._kernel = kernel - def configuration_for_scale_level(self, level: int = 1) -> (GridParameters, + def configuration_for_scale_level(self, level: int = 1) -> tuple[GridParameters, PhysicalParameters, RuntimeParameters, - LBMKernel): + LBMKernel]: if level < 0: raise ValueError("level must be >= 0") diff --git a/Python/actuator_line/__init__.py b/Python/actuator_line/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/Python/actuator_line/actuator_line.py b/Python/actuator_line/actuator_line.py new file mode 100644 index 0000000000000000000000000000000000000000..4a05398d52fbb770ccbbd42a7b2d387cc827ac08 --- /dev/null +++ b/Python/actuator_line/actuator_line.py @@ -0,0 +1,108 @@ +#%% +import numpy as np +from pathlib import Path +from mpi4py import MPI +from pyfluids import basics, gpu, logger +#%% +reference_diameter = 126 + +length = np.array([30,8,8])*reference_diameter +viscosity = 1.56e-5 +velocity = 9 +mach = 0.1 +nodes_per_diameter = 32 + +sim_name = "ActuatorLine" +config_file = Path(__file__).parent/Path("config.txt") +output_path = Path(__file__).parent/Path("output") +output_path.mkdir(exist_ok=True) +timeStepOut = 500 +t_end = 50 + +#%% +logger.Logger.initialize_logger() +basics.logger.Logger.add_stdout() +basics.logger.Logger.set_debug_level(basics.logger.Level.INFO_LOW) +basics.logger.Logger.time_stamp(basics.logger.TimeStamp.ENABLE) +basics.logger.Logger.enable_printed_rank_numbers(True) +#%% +grid_builder = gpu.MultipleGridBuilder.make_shared() +dx = reference_diameter/nodes_per_diameter + +grid_builder.add_coarse_grid(0.0, 0.0, 0.0, *length, dx) +grid_builder.set_periodic_boundary_condition(False, False, False) +grid_builder.build_grids(basics.LbmOrGks.LBM, False) +# %% +comm = gpu.Communicator.get_instance() +#%% +config = basics.ConfigurationFile() +config.load(str(config_file)) +#%% +para = gpu.Parameter(config, comm.get_number_of_process(), comm.get_pid()) + +dt = dx * mach / (np.sqrt(3) * velocity) +velocity_lb = velocity * dt / dx # LB units +viscosity_lb = viscosity * dt / (dx * dx) # LB units + +#%% +para.set_devices([0]) +para.set_output_prefix(sim_name) +para.set_output_path(str(output_path)) +para.set_f_name(para.get_output_path() + "/" + para.get_output_prefix()) +para.set_print_files(True) +para.set_max_level(1) +#%% +para.set_velocity(velocity_lb) +para.set_viscosity(viscosity_lb) +para.set_velocity_ratio(dx/dt) +para.set_main_kernel("CumulantK17CompChim") + +def init_func(coord_x, coord_y, coord_z): + return [0.0, velocity_lb, 0.0, 0.0] + +para.set_initial_condition(init_func) +para.set_t_out(timeStepOut) +para.set_t_end(int(t_end/dt)) +para.set_is_body_force(True) + +#%% +grid_builder.set_velocity_boundary_condition(gpu.SideType.MX, velocity_lb, 0.0, 0.0) +grid_builder.set_velocity_boundary_condition(gpu.SideType.PX, velocity_lb, 0.0, 0.0) + +grid_builder.set_velocity_boundary_condition(gpu.SideType.MY, velocity_lb, 0.0, 0.0) +grid_builder.set_velocity_boundary_condition(gpu.SideType.PY, velocity_lb, 0.0, 0.0) + +grid_builder.set_velocity_boundary_condition(gpu.SideType.MZ, velocity_lb, 0.0, 0.0) +grid_builder.set_velocity_boundary_condition(gpu.SideType.PZ, velocity_lb, 0.0, 0.0) + +#%% +cuda_memory_manager = gpu.CudaMemoryManager.make(para) +grid_generator = gpu.GridProvider.make_grid_generator(grid_builder, para, cuda_memory_manager) +#%% +turb_pos = np.array([3,3,3])*reference_diameter +epsilon = 5 +density = 1.225 +level = 0 +n_blades = 3 +n_blade_nodes = 32 +alm = gpu.ActuatorLine(n_blades, density, n_blade_nodes, epsilon, *turb_pos, reference_diameter, level, dt, dx) +para.add_actuator(alm) +#%% +point_probe = gpu.probes.PointProbe("pointProbe", str(output_path), 100, 500, 100) +point_probe.add_probe_points_from_list(np.array([1,2,5])*reference_diameter, np.array([3,3,3])*reference_diameter, np.array([3,3,3])*reference_diameter) +point_probe.add_post_processing_variable(gpu.probes.PostProcessingVariable.Means) + +para.add_probe(point_probe) + +plane_probe = gpu.probes.PlaneProbe("planeProbe", str(output_path), 100, 500, 100) +plane_probe.set_probe_plane(5*reference_diameter, 0, 0, dx, length[1], length[2]) +para.add_probe(plane_probe) +#%% +sim = gpu.Simulation(comm) +kernel_factory = gpu.KernelFactory.get_instance() +sim.set_factories(kernel_factory, gpu.PreProcessorFactory.get_instance()) +sim.init(para, grid_generator, gpu.FileWriter(), cuda_memory_manager) +#%% +sim.run() +sim.free() +MPI.Finalize() \ No newline at end of file diff --git a/Python/actuator_line/config.txt b/Python/actuator_line/config.txt new file mode 100644 index 0000000000000000000000000000000000000000..e4c778c4cc048f54c0a32310e6bf4a7343a263fa --- /dev/null +++ b/Python/actuator_line/config.txt @@ -0,0 +1,2 @@ +Path = . +GridPath = . diff --git a/apps/gpu/LBM/ActuatorLine/ActuatorLine.cpp b/apps/gpu/LBM/ActuatorLine/ActuatorLine.cpp index ad4b4e0a2e3629455ceebd2a2441eb48dedf99a6..8deb6b37ca8726cb4e7891caff3f24130540da7a 100644 --- a/apps/gpu/LBM/ActuatorLine/ActuatorLine.cpp +++ b/apps/gpu/LBM/ActuatorLine/ActuatorLine.cpp @@ -144,11 +144,11 @@ void multipleLevel(const std::string& configPath) para->setMaxLevel(1); + para->setVelocity(velocityLB); para->setViscosity(viscosityLB); - para->setVelocityRatio( dx / dt ); - + para->setViscosityRatio( dx*dx/dt ); para->setMainKernel("CumulantK17CompChim"); para->setInitialCondition([&](real coordX, real coordY, real coordZ, real &rho, real &vx, real &vy, real &vz) { @@ -186,7 +186,6 @@ void multipleLevel(const std::string& configPath) uint nBlades = 3; uint nBladeNodes = 32; - SPtr<ActuatorLine> actuator_line =SPtr<ActuatorLine>( new ActuatorLine(nBlades, density, nBladeNodes, epsilon, turbPos[0], turbPos[1], turbPos[2], reference_diameter, level, dt, dx) ); para->addActuator( actuator_line ); diff --git a/cpu.cmake b/cpu.cmake index bad575aa3854fb2be777e90bba9ea71fb2cbba5a..a6220ec1ffb9641b824ee26b8be8497ea340173f 100644 --- a/cpu.cmake +++ b/cpu.cmake @@ -80,9 +80,7 @@ add_subdirectory(${VF_THIRD_DIR}/MuParser) add_subdirectory(src/cpu/VirtualFluidsCore) if(BUILD_VF_PYTHON_BINDINGS) - add_subdirectory(${VF_THIRD_DIR}/pybind11/pybind11-2.6.0) add_subdirectory(src/cpu/simulationconfig) - add_subdirectory(src/cpu/pythonbindings) endif() set (APPS_ROOT_CPU "${VF_ROOT_DIR}/apps/cpu/") diff --git a/gpu.cmake b/gpu.cmake index ead5e26bca299819513e4f7639d5431d8973c927..10482f78592aefe6d8b1aae4d30dc6088c9bca88 100644 --- a/gpu.cmake +++ b/gpu.cmake @@ -37,8 +37,8 @@ IF (BUILD_VF_GPU) #add_subdirectory(targets/apps/LBM/BaselNU) #add_subdirectory(targets/apps/LBM/BaselMultiGPU) - add_subdirectory(apps/gpu/LBM/DrivenCavity) - add_subdirectory(apps/gpu/LBM/WTG_RUB) + #add_subdirectory(apps/gpu/LBM/DrivenCavity) + #add_subdirectory(apps/gpu/LBM/WTG_RUB) #add_subdirectory(apps/gpu/LBM/gridGeneratorTest) #add_subdirectory(apps/gpu/LBM/TGV_3D) #add_subdirectory(apps/gpu/LBM/TGV_3D_MultiGPU) @@ -136,4 +136,4 @@ endif() if(BUILD_VF_TRAFFIC) add_subdirectory(src/gpu/Traffic) add_subdirectory(apps/gpu/LBM/TrafficTest) -endif() +endif() \ No newline at end of file diff --git a/pythonbindings/CMakeLists.txt b/pythonbindings/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..5a84adef027fdfa2953e016693bb64570e48c1ef --- /dev/null +++ b/pythonbindings/CMakeLists.txt @@ -0,0 +1,24 @@ +project(VirtualFluidsPython LANGUAGES CUDA CXX) +IF(BUILD_VF_GPU) + pybind11_add_module(pyfluids src/VirtualFluidsModulesGPU.cpp) + set_source_files_properties(src/VirtualFluidsModulesGPU.cpp PROPERTIES LANGUAGE CUDA) + + target_link_libraries(pyfluids PRIVATE GridGenerator VirtualFluids_GPU basics lbmCuda logger) + target_include_directories(pyfluids PRIVATE ${VF_THIRD_DIR}/cuda_samples/) + +ENDIF() +IF(BUILD_VF_CPU) + pybind11_add_module(pyfluids src/VirtualFluidsModulesCPU.cpp) + pybind11_add_module(pymuparser src/muParser.cpp) + + # TODO: Move this to MuParser CMakeLists.txt + set_target_properties(muparser PROPERTIES POSITION_INDEPENDENT_CODE ON) + + target_compile_definitions(pyfluids PRIVATE VF_METIS VF_MPI) + target_compile_definitions(pymuparser PRIVATE VF_METIS VF_MPI) + + target_link_libraries(pyfluids PRIVATE simulationconfig VirtualFluidsCore muparser basics) + target_link_libraries(pymuparser PRIVATE muparser) +ENDIF() +target_include_directories(pyfluids PRIVATE ${CMAKE_SOURCE_DIR}/src/) +target_include_directories(pyfluids PRIVATE ${CMAKE_BINARY_DIR}) \ No newline at end of file diff --git a/pythonbindings/src/VirtualFluidsModulesCPU.cpp b/pythonbindings/src/VirtualFluidsModulesCPU.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2fba3da494f568f7d0d0a117a579a45c9c1b9245 --- /dev/null +++ b/pythonbindings/src/VirtualFluidsModulesCPU.cpp @@ -0,0 +1,12 @@ +#include <pybind11/pybind11.h> +#include "cpu/cpu.cpp" + +namespace py_bindings +{ + namespace py = pybind11; + + PYBIND11_MODULE(pyfluids, m) + { + cpu::makeModule(m); + } +} \ No newline at end of file diff --git a/pythonbindings/src/VirtualFluidsModulesGPU.cpp b/pythonbindings/src/VirtualFluidsModulesGPU.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b96971caf381faada76ee676cf60469492d055c2 --- /dev/null +++ b/pythonbindings/src/VirtualFluidsModulesGPU.cpp @@ -0,0 +1,19 @@ +#include <pybind11/pybind11.h> +#include "basics/basics.cpp" +#include "lbm/lbm.cpp" +#include "gpu/gpu.cpp" +#include "logger/logger.cpp" + +namespace py_bindings +{ + namespace py = pybind11; + + PYBIND11_MODULE(pyfluids, m) + { + basics::makeModule(m); + gpu::makeModule(m); + lbm::makeModule(m); + logging::makeModule(m); + py::add_ostream_redirect(m, "ostream_redirect"); + } +} \ No newline at end of file diff --git a/pythonbindings/src/basics/basics.cpp b/pythonbindings/src/basics/basics.cpp new file mode 100644 index 0000000000000000000000000000000000000000..381e345d78226b25ec3a77a14340d2ef1171c8c9 --- /dev/null +++ b/pythonbindings/src/basics/basics.cpp @@ -0,0 +1,20 @@ +#include <pybind11/pybind11.h> +#include "submodules/logger.cpp" +#include "submodules/configuration_file.cpp" +#include "submodules/lbm_or_gks.cpp" + +namespace basics +{ + namespace py = pybind11; + + py::module makeModule(py::module_ &parentModule) + { + py::module basicsModule = parentModule.def_submodule("basics"); + + logger::makeModule(basicsModule); + configuration::makeModule(basicsModule); + lbmOrGks::makeModule(basicsModule); + + return basicsModule; + } +} \ No newline at end of file diff --git a/pythonbindings/src/basics/submodules/configuration_file.cpp b/pythonbindings/src/basics/submodules/configuration_file.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f5a2f87135a17f5eda34a7467d95f9db6b1c21d1 --- /dev/null +++ b/pythonbindings/src/basics/submodules/configuration_file.cpp @@ -0,0 +1,14 @@ +#include <pybind11/pybind11.h> +#include <basics/config/ConfigurationFile.h> + +namespace configuration +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::class_<vf::basics::ConfigurationFile>(parentModule, "ConfigurationFile") + .def(py::init<>()) + .def("load", &vf::basics::ConfigurationFile::load); + } +} \ No newline at end of file diff --git a/pythonbindings/src/basics/submodules/lbm_or_gks.cpp b/pythonbindings/src/basics/submodules/lbm_or_gks.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ed1deeca62fc57b7f44499b306e9f99b7f990604 --- /dev/null +++ b/pythonbindings/src/basics/submodules/lbm_or_gks.cpp @@ -0,0 +1,14 @@ +#include <pybind11/pybind11.h> +#include "basics/Core/LbmOrGks.h" + +namespace lbmOrGks +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::enum_<LbmOrGks>(parentModule, "LbmOrGks") + .value("LBM", LbmOrGks::LBM) + .value("GKS", LbmOrGks::GKS); + } +} \ No newline at end of file diff --git a/pythonbindings/src/basics/submodules/logger.cpp b/pythonbindings/src/basics/submodules/logger.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d46648e349b44243581e083f3561e8a13648f3b2 --- /dev/null +++ b/pythonbindings/src/basics/submodules/logger.cpp @@ -0,0 +1,36 @@ +#include <pybind11/pybind11.h> +#include <pybind11/iostream.h> +#include <basics/Core/Logger/Logger.h> +#include <basics/Core/Logger/implementations/LoggerImp.h> + +namespace logger +{ + namespace py = pybind11; + + py::module makeModule(py::module_ &parentModule) + { + py::module loggerModule = parentModule.def_submodule("logger"); + + py::class_<logging::Logger>(loggerModule, "Logger") + .def("add_stdout", [](){ + logging::Logger::addStream(&std::cout); + }) + .def("set_debug_level", &logging::Logger::setDebugLevel) + .def("time_stamp", &logging::Logger::timeStamp) + .def("enable_printed_rank_numbers", &logging::Logger::enablePrintedRankNumbers); + + loggerModule.attr("log") = logging::out; + py::enum_<logging::Logger::Level>(loggerModule, "Level") + .value("INFO_LOW", logging::Logger::Level::INFO_LOW) + .value("INFO_INTERMEDIATE", logging::Logger::Level::INFO_INTERMEDIATE) + .value("INFO_HIGH", logging::Logger::Level::INFO_HIGH) + .value("WARNING", logging::Logger::Level::WARNING) + .value("LOGGER_ERROR", logging::Logger::Level::LOGGER_ERROR); + + py::enum_<logging::Logger::TimeStamp>(loggerModule, "TimeStamp") + .value("ENABLE", logging::Logger::TimeStamp::ENABLE) + .value("DISABLE", logging::Logger::TimeStamp::DISABLE); + + return loggerModule; + } +} \ No newline at end of file diff --git a/pythonbindings/src/cpu/cpu.cpp b/pythonbindings/src/cpu/cpu.cpp new file mode 100644 index 0000000000000000000000000000000000000000..554de53b47446366693aed31d534f6145ebea8ba --- /dev/null +++ b/pythonbindings/src/cpu/cpu.cpp @@ -0,0 +1,23 @@ +#include <pybind11/pybind11.h> +#include "submodules/boundaryconditions.cpp" +#include "submodules/simulationconfig.cpp" +#include "submodules/geometry.cpp" +#include "submodules/kernel.cpp" +#include "submodules/simulationparameters.cpp" +#include "submodules/writer.cpp" + +namespace cpu +{ + namespace py = pybind11; + py::module makeModule(py::module_ &parentModule) + { + py::module cpuModule = parentModule.def_submodule("cpu"); + boundaryconditions::makeModule(cpuModule); + simulation::makeModule(cpuModule); + geometry::makeModule(cpuModule); + kernel::makeModule(cpuModule); + parameters::makeModule(cpuModule); + writer::makeModule(cpuModule); + return cpuModule; + } +} \ No newline at end of file diff --git a/pythonbindings/src/cpu/submodules/boundaryconditions.cpp b/pythonbindings/src/cpu/submodules/boundaryconditions.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3bff7bc069ca20fe1c0cf3d1847b9714e0381505 --- /dev/null +++ b/pythonbindings/src/cpu/submodules/boundaryconditions.cpp @@ -0,0 +1,64 @@ +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> +#include <BoundaryConditions/DensityBCAdapter.h> +#include <BoundaryConditions/NonReflectingOutflowBCAlgorithm.h> +#include <BoundaryConditions/BCAdapter.h> +#include <BoundaryConditions/NoSlipBCAdapter.h> +#include <BoundaryConditions/VelocityBCAdapter.h> +#include <BoundaryConditions/NoSlipBCAlgorithm.h> +#include <BoundaryConditions/VelocityBCAlgorithm.h> +#include <BoundaryConditions/HighViscosityNoSlipBCAlgorithm.h> + +namespace boundaryconditions +{ + namespace py = pybind11; + using namespace py::literals; + + template<class adapter, class algorithm, + class = std::enable_if_t<std::is_base_of<BCAdapter, adapter>::value>, + class = std::enable_if_t<std::is_base_of<BCAlgorithm, algorithm>::value>> + class PyBoundaryCondition : public adapter + { + public: + template<typename ...Args> + PyBoundaryCondition(Args &&... args) : adapter(std::forward<Args>(args)...) + { + this->setBcAlgorithm(std::make_shared<algorithm>()); + } + }; + + template<class adapter, class algorithm> + using bc_class = py::class_<PyBoundaryCondition<adapter, algorithm>, BCAdapter, + std::shared_ptr<PyBoundaryCondition<adapter, algorithm>>>; + + void makeModule(py::module_ &parentModule) + { + py::module_ bcModule = parentModule.def_submodule("boundaryconditions"); + + auto _ = py::class_<BCAdapter, std::shared_ptr<BCAdapter>>(bcModule, "BCAdapter"); + + bc_class<NoSlipBCAdapter, NoSlipBCAlgorithm>(bcModule, "NoSlipBoundaryCondition") + .def(py::init()); + + bc_class<NoSlipBCAdapter, HighViscosityNoSlipBCAlgorithm>(bcModule, "HighViscosityNoSlipBoundaryCondition") + .def(py::init()); + + bc_class<VelocityBCAdapter, VelocityBCAlgorithm>(bcModule, "VelocityBoundaryCondition") + .def(py::init()) + .def(py::init<bool &, bool &, bool &, mu::Parser &, double &, double &>(), + "vx1"_a, "vx2"_a, "vx3"_a, + "function"_a, "start_time"_a, "end_time"_a) + .def(py::init<bool &, bool &, bool &, mu::Parser &, mu::Parser &, mu::Parser &, double &, double &>(), + "vx1"_a, "vx2"_a, "vx3"_a, + "function_vx1"_a, "function_vx2"_a, "function_vx2"_a, + "start_time"_a, "end_time"_a) + .def(py::init<double &, double &, double &, double &, double &, double &, double &, double &, double &>(), + "vx1"_a, "vx1_start_time"_a, "vx1_end_time"_a, + "vx2"_a, "vx2_start_time"_a, "vx2_end_time"_a, + "vx3"_a, "vx3_start_time"_a, "vx3_end_time"_a); + + bc_class<DensityBCAdapter, NonReflectingOutflowBCAlgorithm>(bcModule, "NonReflectingOutflow") + .def(py::init()); + } + +} \ No newline at end of file diff --git a/pythonbindings/src/cpu/submodules/geometry.cpp b/pythonbindings/src/cpu/submodules/geometry.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b7ff4dd761258d41687589d2dd89c3479093753e --- /dev/null +++ b/pythonbindings/src/cpu/submodules/geometry.cpp @@ -0,0 +1,84 @@ +#include <pybind11/pybind11.h> +#include <geometry3d/GbPoint3D.h> +#include <geometry3d/GbObject3D.h> +#include <geometry3d/GbCuboid3D.h> +#include <geometry3d/GbLine3D.h> +#include <Interactors/Interactor3D.h> + + +namespace geometry +{ + namespace py = pybind11; + + template<class GeoObject> + using py_geometry = py::class_<GeoObject, GbObject3D, std::shared_ptr<GeoObject>>; + + std::string GbPoint3D_repr_(const GbPoint3D &instance) + { + std::ostringstream stream; + stream << "<GbPoint3D" + << " x1: " << instance.getX1Coordinate() + << " x2: " << instance.getX2Coordinate() + << " x3: " << instance.getX3Coordinate() << ">"; + + return stream.str(); + } + + void makeModule(py::module_ &parentModule) + { + py::module geometry = parentModule.def_submodule("geometry"); + + py::class_<GbObject3D, std::shared_ptr<GbObject3D>>(geometry, "GbObject3D"); + + py_geometry<GbPoint3D>(geometry, "GbPoint3D") + .def(py::init()) + .def(py::init<double &, double &, double &>()) + .def(py::init<GbPoint3D *>()) + .def_property("x1", &GbPoint3D::getX1Coordinate, &GbPoint3D::setX1) + .def_property("x2", &GbPoint3D::getX2Coordinate, &GbPoint3D::setX2) + .def_property("x3", &GbPoint3D::getX3Coordinate, &GbPoint3D::setX3) + .def("get_distance", &GbPoint3D::getDistance) + .def("__repr__", &GbPoint3D_repr_); + + py_geometry<GbCuboid3D>(geometry, "GbCuboid3D") + .def(py::init()) + .def(py::init<double &, double &, double &, double &, double &, double &>()) + .def(py::init<GbPoint3D *, GbPoint3D *>()) + .def(py::init<GbCuboid3D *>()) + .def_property("point1", &GbCuboid3D::getPoint1, &GbCuboid3D::setPoint1) + .def_property("point2", &GbCuboid3D::getPoint2, &GbCuboid3D::setPoint2) + .def("__repr__", [&](GbCuboid3D &instance) + { + std::ostringstream stream; + stream << "<GbCuboid3D" << std::endl + << "point1: " << GbPoint3D_repr_(instance.getPoint1()) << std::endl + << "point2: " << GbPoint3D_repr_(instance.getPoint2()) << ">"; + return stream.str(); + }); + + py_geometry<GbLine3D>(geometry, "GbLine3D") + .def(py::init()) + .def(py::init<GbPoint3D *, GbPoint3D *>()) + .def(py::init<GbLine3D>()) + .def_property("point1", &GbLine3D::getPoint1, &GbLine3D::setPoint1) + .def_property("point2", &GbLine3D::getPoint2, &GbLine3D::setPoint2) + .def("__repr__", [&](GbLine3D &instance) + { + std::ostringstream stream; + stream << "<GbLine3D" << std::endl + << "point1: " << GbPoint3D_repr_(instance.getPoint1()) << std::endl + << "point2: " << GbPoint3D_repr_(instance.getPoint2()) << ">"; + return stream.str(); + }); + + + py::class_<Interactor3D, std::shared_ptr<Interactor3D>>(geometry, "State") + .def_readonly_static("SOLID", &Interactor3D::SOLID) + .def_readonly_static("INVERSESOLID", &Interactor3D::INVERSESOLID) + .def_readonly_static("TIMEDEPENDENT", &Interactor3D::TIMEDEPENDENT) + .def_readonly_static("FLUID", &Interactor3D::FLUID) + .def_readonly_static("MOVEABLE", &Interactor3D::MOVEABLE) + .def_readonly_static("CHANGENOTNECESSARY", &Interactor3D::CHANGENOTNECESSARY); + } + +} \ No newline at end of file diff --git a/pythonbindings/src/cpu/submodules/kernel.cpp b/pythonbindings/src/cpu/submodules/kernel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fb291790632cc2041410f60a14fca8d966283343 --- /dev/null +++ b/pythonbindings/src/cpu/submodules/kernel.cpp @@ -0,0 +1,45 @@ +#include <memory> +#include <pybind11/pybind11.h> +#include <simulationconfig/KernelFactory.h> +#include <simulationconfig/KernelConfigStructs.h> + +namespace kernel +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::module kernelModule = parentModule.def_submodule("kernel"); + + py::enum_<KernelFactory::KernelType>(kernelModule, "KernelType") + .value("BGK", KernelFactory::BGK) + .value("CompressibleCumulantFourthOrderViscosity", + KernelFactory::COMPRESSIBLE_CUMULANT_4TH_ORDER_VISCOSITY); + + py::class_<LBMKernelConfiguration, std::shared_ptr<LBMKernelConfiguration>>(kernelModule, "LBMKernel") + .def(py::init<KernelFactory::KernelType>()) + .def_readwrite("type", &LBMKernelConfiguration::kernelType) + .def_readwrite("use_forcing", &LBMKernelConfiguration::useForcing) + .def_readwrite("forcing_in_x1", &LBMKernelConfiguration::forcingX1) + .def_readwrite("forcing_in_x2", &LBMKernelConfiguration::forcingX2) + .def_readwrite("forcing_in_x3", &LBMKernelConfiguration::forcingX3) + .def("set_forcing", [](LBMKernelConfiguration &kernelConfig, double x1, double x2, double x3) + { + kernelConfig.forcingX1 = x1; + kernelConfig.forcingX2 = x2; + kernelConfig.forcingX3 = x3; + }) + .def("__repr__", [](LBMKernelConfiguration &kernelConfig) + { + std::ostringstream stream; + stream << "<" << kernelConfig.kernelType << std::endl + << "Use forcing: " << kernelConfig.useForcing << std::endl + << "Forcing in x1: " << kernelConfig.forcingX1 << std::endl + << "Forcing in x2: " << kernelConfig.forcingX2 << std::endl + << "Forcing in x3: " << kernelConfig.forcingX3 << ">" << std::endl; + + return stream.str(); + }); + } + +} \ No newline at end of file diff --git a/pythonbindings/src/cpu/submodules/simulationconfig.cpp b/pythonbindings/src/cpu/submodules/simulationconfig.cpp new file mode 100644 index 0000000000000000000000000000000000000000..60af4e36af4dca67e9262dd9f5ee1f46d5b7bb58 --- /dev/null +++ b/pythonbindings/src/cpu/submodules/simulationconfig.cpp @@ -0,0 +1,22 @@ +#include <pybind11/pybind11.h> +#include <simulationconfig/Simulation.h> + +namespace simulation +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::class_<Simulation, std::shared_ptr<Simulation>>(parentModule, "Simulation") + .def(py::init()) + .def("set_writer", &Simulation::setWriterConfiguration) + .def("set_grid_parameters", &Simulation::setGridParameters) + .def("set_physical_parameters", &Simulation::setPhysicalParameters) + .def("set_runtime_parameters", &Simulation::setRuntimeParameters) + .def("set_kernel_config", &Simulation::setKernelConfiguration) + .def("add_object", &Simulation::addObject) + .def("add_bc_adapter", &Simulation::addBCAdapter) + .def("run_simulation", &Simulation::run); + } + +} \ No newline at end of file diff --git a/pythonbindings/src/cpu/submodules/simulationparameters.cpp b/pythonbindings/src/cpu/submodules/simulationparameters.cpp new file mode 100644 index 0000000000000000000000000000000000000000..acc272f2ee412cfbafd9007b4b18610cfd0a1e9b --- /dev/null +++ b/pythonbindings/src/cpu/submodules/simulationparameters.cpp @@ -0,0 +1,59 @@ +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> +#include <complex> +#include <simulationconfig/SimulationParameters.h> + +namespace parameters +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::module parametersModule = parentModule.def_submodule("parameters"); + + py::class_<PhysicalParameters, std::shared_ptr<PhysicalParameters>>(parametersModule, "PhysicalParameters") + .def(py::init()) + .def_readwrite("bulk_viscosity_factor", &PhysicalParameters::bulkViscosityFactor, + "The viscosity of the fluid will be multiplied with this factor to calculate its bulk viscosity. Default is 1.0") + .def_readwrite("lattice_viscosity", &PhysicalParameters::latticeViscosity, "Lattice viscosity"); + + py::class_<GridParameters, std::shared_ptr<GridParameters>>(parametersModule, "GridParameters") + .def(py::init()) + .def_readwrite("node_distance", &GridParameters::nodeDistance) + .def_readwrite("reference_direction_index", &GridParameters::referenceDirectionIndex) + .def_readwrite("number_of_nodes_per_direction", &GridParameters::numberOfNodesPerDirection) + .def_readwrite("blocks_per_direction", &GridParameters::blocksPerDirection) + .def_readwrite("periodic_boundary_in_x1", &GridParameters::periodicBoundaryInX1) + .def_readwrite("periodic_boundary_in_x2", &GridParameters::periodicBoundaryInX2) + .def_readwrite("periodic_boundary_in_x3", &GridParameters::periodicBoundaryInX3) + .def_property_readonly("bounding_box", &GridParameters::boundingBox); + + py::class_<BoundingBox, std::shared_ptr<BoundingBox>>(parametersModule, "BoundingBox") + .def_readonly("min_x1", &BoundingBox::minX1) + .def_readonly("min_x2", &BoundingBox::minX2) + .def_readonly("min_x3", &BoundingBox::minX3) + .def_readonly("max_x1", &BoundingBox::maxX1) + .def_readonly("max_x2", &BoundingBox::maxX2) + .def_readonly("max_x3", &BoundingBox::maxX3) + .def("__repr__", [](BoundingBox &self) + { + std::ostringstream stream; + stream << "<BoundingBox" << std::endl + << "min x1: " << self.minX1 << std::endl + << "min x2: " << self.minX2 << std::endl + << "min x3: " << self.minX3 << std::endl + << "max x1: " << self.maxX1 << std::endl + << "max x2: " << self.maxX2 << std::endl + << "max x3: " << self.maxX3 << std::endl << ">"; + + return stream.str(); + }); + + py::class_<RuntimeParameters, std::shared_ptr<RuntimeParameters>>(parametersModule, "RuntimeParameters") + .def(py::init()) + .def_readwrite("number_of_timesteps", &RuntimeParameters::numberOfTimeSteps) + .def_readwrite("timestep_log_interval", &RuntimeParameters::timeStepLogInterval) + .def_readwrite("number_of_threads", &RuntimeParameters::numberOfThreads); + + } +} \ No newline at end of file diff --git a/pythonbindings/src/cpu/submodules/writer.cpp b/pythonbindings/src/cpu/submodules/writer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d5ec527a27caf63d9a3066c51e1f675b307fe0b2 --- /dev/null +++ b/pythonbindings/src/cpu/submodules/writer.cpp @@ -0,0 +1,21 @@ +#include <pybind11/pybind11.h> +#include <simulationconfig/WriterConfiguration.h> + +namespace writer +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::module writerModule = parentModule.def_submodule("writer"); + + py::enum_<OutputFormat>(writerModule, "OutputFormat") + .value("ASCII", OutputFormat::ASCII) + .value("BINARY", OutputFormat::BINARY); + + py::class_<WriterConfiguration>(writerModule, "Writer") + .def(py::init()) + .def_readwrite("output_path", &WriterConfiguration::outputPath) + .def_readwrite("output_format", &WriterConfiguration::outputFormat); + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/gpu.cpp b/pythonbindings/src/gpu/gpu.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ff07dce0f3d4e3684c07a8cd6d226de5e71b7b18 --- /dev/null +++ b/pythonbindings/src/gpu/gpu.cpp @@ -0,0 +1,38 @@ +#include <pybind11/pybind11.h> +#include "submodules/actuator_line.cpp" +#include "submodules/pre_collision_interactor.cpp" +#include "submodules/simulation.cpp" +#include "submodules/parameter.cpp" +#include "submodules/boundary_conditions.cpp" +#include "submodules/communicator.cpp" +#include "submodules/grid_builder.cpp" +#include "submodules/cuda_memory_manager.cpp" +#include "submodules/grid_provider.cpp" +#include "submodules/probes.cpp" +#include "submodules/kernel_factory.cpp" +#include "submodules/pre_processor_factory.cpp" +#include "submodules/file_writer.cpp" + +namespace gpu +{ + namespace py = pybind11; + + py::module makeModule(py::module_ &parentModule) + { + py::module gpuModule = parentModule.def_submodule("gpu"); + simulation::makeModule(gpuModule); + parameter::makeModule(gpuModule); + pre_collision_interactor::makeModule(gpuModule); + actuator_line::makeModule(gpuModule); + boundary_conditions::makeModule(gpuModule); + communicator::makeModule(gpuModule); + grid_builder::makeModule(gpuModule); + cuda_memory_manager::makeModule(gpuModule); + grid_provider::makeModule(gpuModule); + probes::makeModule(gpuModule); + kernel_factory::makeModule(gpuModule); + pre_processor_factory::makeModule(gpuModule); + file_writer::makeModule(gpuModule); + return gpuModule; + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/actuator_line.cpp b/pythonbindings/src/gpu/submodules/actuator_line.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a1792c3de9fede5eaba206cc9ff6e7b29fdfbdf9 --- /dev/null +++ b/pythonbindings/src/gpu/submodules/actuator_line.cpp @@ -0,0 +1,71 @@ +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> +#include <pybind11/numpy.h> +#include <gpu/VirtualFluids_GPU/PreCollisionInteractor/ActuatorLine.h> +#include <gpu/VirtualFluids_GPU/PreCollisionInteractor/PreCollisionInteractor.h> +class PyActuatorLine : public ActuatorLine +{ +public: + using ActuatorLine::ActuatorLine; // Inherit constructors + void calcBladeForces() override + { + PYBIND11_OVERRIDE_NAME(void, ActuatorLine, "calc_blade_forces", calcBladeForces,); + } +}; +namespace actuator_line +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + using arr = py::array_t<float, py::array::c_style>; + + py::class_<ActuatorLine, PreCollisionInteractor, PyActuatorLine, std::shared_ptr<ActuatorLine>>(parentModule, "ActuatorLine", py::dynamic_attr()) + .def(py::init< const uint, + const real, + const uint, + const real, + real, real, real, + const real, + int, + const real, + const real>(), + "n_blades", + "density", + "n_blade_nodes", + "epsilon", + "turbine_pos_x", "turbine_pos_y", "turbine_pos_z", + "diameter", + "level", + "delta_t", + "delta_x") + .def_property("omega", &ActuatorLine::getOmega, &ActuatorLine::setOmega) + .def_property("azimuth", &ActuatorLine::getAzimuth, &ActuatorLine::getAzimuth) + .def_property_readonly("n_blades", &ActuatorLine::getNBlades) + .def_property_readonly("n_blade_nodes", &ActuatorLine::getNBladeNodes) + .def_property_readonly("n_nodes", &ActuatorLine::getNumberOfNodes) + .def_property_readonly("n_indices", &ActuatorLine::getNumberOfIndices) + .def_property_readonly("density", &ActuatorLine::getDensity) + .def_property_readonly("position_x", &ActuatorLine::getPositionX) + .def_property_readonly("position_y", &ActuatorLine::getPositionY) + .def_property_readonly("position_z", &ActuatorLine::getPositionZ) + .def_property_readonly("position", [](ActuatorLine& al){ real position[3] = {al.getPositionX(), al.getPositionY(), al.getPositionZ()}; return arr(3, position); } ) + .def("get_radii", [](ActuatorLine& al){ return arr(al.getNBladeNodes(), al.getBladeRadii()); } ) + .def("get_blade_coords_x", [](ActuatorLine& al){ return arr({al.getNBlades(), al.getNBladeNodes()}, al.getBladeCoordsX()); } ) + .def("get_blade_coords_y", [](ActuatorLine& al){ return arr({al.getNBlades(), al.getNBladeNodes()}, al.getBladeCoordsY()); } ) + .def("get_blade_coords_z", [](ActuatorLine& al){ return arr({al.getNBlades(), al.getNBladeNodes()}, al.getBladeCoordsZ()); } ) + .def("get_blade_velocities_x", [](ActuatorLine& al){ return arr({al.getNBlades(), al.getNBladeNodes()}, al.getBladeVelocitiesX()); } ) + .def("get_blade_velocities_y", [](ActuatorLine& al){ return arr({al.getNBlades(), al.getNBladeNodes()}, al.getBladeVelocitiesY()); } ) + .def("get_blade_velocities_z", [](ActuatorLine& al){ return arr({al.getNBlades(), al.getNBladeNodes()}, al.getBladeVelocitiesZ()); } ) + .def("get_blade_forces_x", [](ActuatorLine& al){ return arr({al.getNBlades(), al.getNBladeNodes()}, al.getBladeForcesX()); } ) + .def("get_blade_forces_y", [](ActuatorLine& al){ return arr({al.getNBlades(), al.getNBladeNodes()}, al.getBladeForcesY()); } ) + .def("get_blade_forces_z", [](ActuatorLine& al){ return arr({al.getNBlades(), al.getNBladeNodes()}, al.getBladeForcesZ()); } ) + .def("set_blade_coords", [](ActuatorLine& al, arr coordsX, arr coordsY, arr coordsZ){ + al.setBladeCoords(static_cast<float *>(coordsX.request().ptr), static_cast<float *>(coordsY.request().ptr), static_cast<float *>(coordsZ.request().ptr)); } ) + .def("set_blade_velocities", [](ActuatorLine& al, arr velocitiesX, arr velocitiesY, arr velocitiesZ){ + al.setBladeVelocities(static_cast<float *>(velocitiesX.request().ptr), static_cast<float *>(velocitiesY.request().ptr), static_cast<float *>(velocitiesZ.request().ptr)); } ) + .def("set_blade_forces", [](ActuatorLine& al, arr forcesX, arr forcesY, arr forcesZ){ + al.setBladeForces(static_cast<float *>(forcesX.request().ptr), static_cast<float *>(forcesY.request().ptr), static_cast<float *>(forcesZ.request().ptr)); } ) + .def("calc_blade_forces", &ActuatorLine::calcBladeForces); + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/boundary_conditions.cpp b/pythonbindings/src/gpu/submodules/boundary_conditions.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8f941a8705c225275d25291205ebdaeef8de5c9e --- /dev/null +++ b/pythonbindings/src/gpu/submodules/boundary_conditions.cpp @@ -0,0 +1,20 @@ +#include <pybind11/pybind11.h> +#include <gpu/GridGenerator/grid/BoundaryConditions/Side.h> + +namespace boundary_conditions +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::enum_<SideType>(parentModule, "SideType") + .value("MX", SideType::MX) + .value("PX", SideType::PX) + .value("MY", SideType::MY) + .value("PY", SideType::PY) + .value("MZ", SideType::MZ) + .value("PZ", SideType::PZ) + .value("GEOMETRY", SideType::GEOMETRY) + .export_values(); + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/communicator.cpp b/pythonbindings/src/gpu/submodules/communicator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..edb36e2c2f774903590a16a0b406c721662827b1 --- /dev/null +++ b/pythonbindings/src/gpu/submodules/communicator.cpp @@ -0,0 +1,15 @@ +#include <pybind11/pybind11.h> +#include <gpu/VirtualFluids_GPU/Communication/Communicator.h> + +namespace communicator +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::class_<vf::gpu::Communicator, std::unique_ptr<vf::gpu::Communicator, py::nodelete>>(parentModule, "Communicator") + .def("get_instance", &vf::gpu::Communicator::getInstance, py::return_value_policy::reference) + .def("get_number_of_process", &vf::gpu::Communicator::getNummberOfProcess) + .def("get_pid", &vf::gpu::Communicator::getPID); + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/cuda_memory_manager.cpp b/pythonbindings/src/gpu/submodules/cuda_memory_manager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f337aeb306fd1836e5bc2962e85f45d593185836 --- /dev/null +++ b/pythonbindings/src/gpu/submodules/cuda_memory_manager.cpp @@ -0,0 +1,15 @@ +#include <pybind11/pybind11.h> +#include <gpu/VirtualFluids_GPU/GPU/CudaMemoryManager.h> +#include <gpu/VirtualFluids_GPU/Parameter/Parameter.h> + + +namespace cuda_memory_manager +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::class_<CudaMemoryManager, std::shared_ptr<CudaMemoryManager>>(parentModule, "CudaMemoryManager") + .def("make", &CudaMemoryManager::make, py::return_value_policy::reference); + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/file_writer.cpp b/pythonbindings/src/gpu/submodules/file_writer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2ad90fe7381be215b2d257b5be99caf25db1e0ae --- /dev/null +++ b/pythonbindings/src/gpu/submodules/file_writer.cpp @@ -0,0 +1,17 @@ +#include <pybind11/pybind11.h> +#include <gpu/VirtualFluids_GPU/Output/FileWriter.h> +#include <gpu/VirtualFluids_GPU/Output/DataWriter.h> + + +namespace file_writer +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::class_<DataWriter, std::shared_ptr<DataWriter>>(parentModule, "_DataWriter"); + + py::class_<FileWriter, DataWriter, std::shared_ptr<FileWriter>>(parentModule, "FileWriter") + .def(py::init<>()); + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/grid_builder.cpp b/pythonbindings/src/gpu/submodules/grid_builder.cpp new file mode 100644 index 0000000000000000000000000000000000000000..09241f71cbe9cd013600c34e4d0a07e53a1bc79f --- /dev/null +++ b/pythonbindings/src/gpu/submodules/grid_builder.cpp @@ -0,0 +1,36 @@ +#include <pybind11/pybind11.h> +#include "gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.h" +#include "gpu/GridGenerator/grid/GridBuilder/GridBuilder.h" +#include "gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h" +#include "gpu/GridGenerator/geometries/Object.h" +#include "gpu/GridGenerator/grid/BoundaryConditions/Side.h" + +namespace grid_builder +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::class_<GridBuilder, std::shared_ptr<GridBuilder>>(parentModule, "GridBuilder") + .def("get_number_of_grid_levels", &GridBuilder::getNumberOfGridLevels) + .def("get_grid", &GridBuilder::getGrid); + + py::class_<LevelGridBuilder, GridBuilder, std::shared_ptr<LevelGridBuilder>>(parentModule, "LevelGridBuilder") + .def("get_grid", py::overload_cast<int, int>(&LevelGridBuilder::getGrid)) + .def("set_slip_boundary_condition", &LevelGridBuilder::setSlipBoundaryCondition) + .def("set_velocity_boundary_condition", &LevelGridBuilder::setVelocityBoundaryCondition) + .def("set_pressure_boundary_condition", &LevelGridBuilder::setPressureBoundaryCondition) + .def("set_periodic_boundary_condition", &LevelGridBuilder::setPeriodicBoundaryCondition) + .def("set_no_slip_boundary_condition", &LevelGridBuilder::setNoSlipBoundaryCondition); + + py::class_<MultipleGridBuilder, LevelGridBuilder, std::shared_ptr<MultipleGridBuilder>>(parentModule, "MultipleGridBuilder") + .def("make_shared", &MultipleGridBuilder::makeShared, py::return_value_policy::reference) + .def("add_coarse_grid", &MultipleGridBuilder::addCoarseGrid) + .def("add_grid", py::overload_cast<Object*>(&MultipleGridBuilder::addGrid)) + .def("add_grid", py::overload_cast<Object*, uint>(&MultipleGridBuilder::addGrid)) + .def("add_geometry", py::overload_cast<Object*>(&MultipleGridBuilder::addGeometry)) + .def("add_geometry", py::overload_cast<Object*, uint>(&MultipleGridBuilder::addGeometry)) + .def("get_number_of_levels", &MultipleGridBuilder::getNumberOfLevels) + .def("build_grids", &MultipleGridBuilder::buildGrids); + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/grid_provider.cpp b/pythonbindings/src/gpu/submodules/grid_provider.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5a5514dd8b14d24f4818740e115c8504bc973726 --- /dev/null +++ b/pythonbindings/src/gpu/submodules/grid_provider.cpp @@ -0,0 +1,16 @@ +#include <pybind11/pybind11.h> +#include "gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.h" +#include <gpu/VirtualFluids_GPU/GPU/CudaMemoryManager.h> +#include <gpu/VirtualFluids_GPU/Parameter/Parameter.h> +#include "gpu/GridGenerator/grid/GridBuilder/GridBuilder.h" + +namespace grid_provider +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::class_<GridProvider, std::shared_ptr<GridProvider>>(parentModule, "GridProvider") + .def("make_grid_generator", &GridProvider::makeGridGenerator, py::return_value_policy::reference); + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/kernel_factory.cpp b/pythonbindings/src/gpu/submodules/kernel_factory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..af710948aa75900ba9f4051360ec26dd8510118a --- /dev/null +++ b/pythonbindings/src/gpu/submodules/kernel_factory.cpp @@ -0,0 +1,16 @@ +#include <pybind11/pybind11.h> +#include <gpu/VirtualFluids_GPU/Kernel/Utilities/KernelFactory/KernelFactoryImp.h> +#include <gpu/VirtualFluids_GPU/Kernel/Utilities/KernelFactory/KernelFactory.h> + +namespace kernel_factory +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::class_<KernelFactory, std::shared_ptr<KernelFactory>>(parentModule, "_KernelFactory"); + + py::class_<KernelFactoryImp, KernelFactory, std::shared_ptr<KernelFactoryImp>>(parentModule, "KernelFactory") + .def("get_instance", &KernelFactoryImp::getInstance, py::return_value_policy::reference); + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/parameter.cpp b/pythonbindings/src/gpu/submodules/parameter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2d394da657cc7f45f1b4e7491b0d69774be7f0f8 --- /dev/null +++ b/pythonbindings/src/gpu/submodules/parameter.cpp @@ -0,0 +1,69 @@ +#include <pybind11/pybind11.h> +#include <pybind11/functional.h> +#include <pybind11/stl.h> +#include <gpu/VirtualFluids_GPU/Parameter/Parameter.h> +#include <basics/config/ConfigurationFile.h> +#include <gpu/VirtualFluids_GPU/PreCollisionInteractor/PreCollisionInteractor.h> + +namespace parameter +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::class_<Parameter, std::shared_ptr<Parameter>>(parentModule, "Parameter") + .def(py::init< + const vf::basics::ConfigurationFile&, + int, + int + >(), + "config_data", + "number_of_processes", + "my_ID") + .def("set_forcing", &Parameter::setForcing) + .def("set_diff_on", &Parameter::setDiffOn) + .def("set_comp_on", &Parameter::setCompOn) + .def("set_max_level", &Parameter::setMaxLevel) + .def("set_t_end", &Parameter::setTEnd) + .def("set_t_out", &Parameter::setTOut) + .def("set_t_start_out", &Parameter::setTStartOut) + .def("set_timestep_of_coarse_level", &Parameter::setTimestepOfCoarseLevel) + .def("set_output_path", &Parameter::setOutputPath) + .def("set_output_prefix", &Parameter::setOutputPrefix) + .def("set_f_name", &Parameter::setFName) + .def("set_print_files", &Parameter::setPrintFiles) + .def("set_temperature_init", &Parameter::setTemperatureInit) + .def("set_temperature_BC", &Parameter::setTemperatureBC) + .def("set_viscosity", &Parameter::setViscosity) + .def("set_velocity", &Parameter::setVelocity) + .def("set_viscosity_ratio", &Parameter::setViscosityRatio) + .def("set_velocity_ratio", &Parameter::setVelocityRatio) + .def("set_density_ratio", &Parameter::setDensityRatio) + .def("set_devices", &Parameter::setDevices) + .def("set_is_body_force", &Parameter::setIsBodyForce) + .def("set_main_kernel", &Parameter::setMainKernel) + .def("set_AD_kernel", &Parameter::setADKernel) + .def("set_initial_condition", [](Parameter ¶, std::function<std::vector<float>(real, real, real)> &init_func) + { + para.setInitialCondition([init_func](real coordX, real coordY, real coordZ, real& rho, real& vx, real& vy, real& vz) + { + std::vector<float> values = init_func(coordX, coordY, coordZ); + rho = values[0]; + vx = values[1]; + vy = values[2]; + vz = values[3]; + }); + }) + .def("add_actuator", &Parameter::addActuator) + .def("add_probe", &Parameter::addProbe) + .def("get_output_path", &Parameter::getOutputPath) + .def("get_output_prefix", &Parameter::getOutputPrefix) + .def("get_velocity", &Parameter::getVelocity) + .def("get_viscosity", &Parameter::getViscosity) + .def("get_velocity_ratio", &Parameter::getVelocityRatio) + .def("get_viscosity_ratio", &Parameter::getViscosityRatio) + .def("get_density_ratio", &Parameter::getDensityRatio) + .def("get_force_ratio", &Parameter::getForceRatio) + ; + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/pre_collision_interactor.cpp b/pythonbindings/src/gpu/submodules/pre_collision_interactor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..362ee1a8ce6112cfa9543f1b254e10f3e35822a1 --- /dev/null +++ b/pythonbindings/src/gpu/submodules/pre_collision_interactor.cpp @@ -0,0 +1,12 @@ +#include <pybind11/pybind11.h> +#include <gpu/VirtualFluids_GPU/PreCollisionInteractor/PreCollisionInteractor.h> + +namespace pre_collision_interactor +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::class_<PreCollisionInteractor, std::shared_ptr<PreCollisionInteractor>>(parentModule, "PreCollisionInteractor"); + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/pre_processor_factory.cpp b/pythonbindings/src/gpu/submodules/pre_processor_factory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b76ae285b413594847f6672e7f3fc0e656da3cec --- /dev/null +++ b/pythonbindings/src/gpu/submodules/pre_processor_factory.cpp @@ -0,0 +1,16 @@ +#include <pybind11/pybind11.h> +#include <gpu/VirtualFluids_GPU/PreProcessor/PreProcessorFactory/PreProcessorFactory.h> +#include <gpu/VirtualFluids_GPU/PreProcessor/PreProcessorFactory/PreProcessorFactoryImp.h> + +namespace pre_processor_factory +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::class_<PreProcessorFactory, std::shared_ptr<PreProcessorFactory>>(parentModule, "_PreProcessorFactory"); + + py::class_<PreProcessorFactoryImp, PreProcessorFactory, std::shared_ptr<PreProcessorFactoryImp>>(parentModule, "PreProcessorFactory") + .def("get_instance", &PreProcessorFactoryImp::getInstance, py::return_value_policy::reference); + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/probes.cpp b/pythonbindings/src/gpu/submodules/probes.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9b751a513d23a8a17e4e9981ababc720fc7346b0 --- /dev/null +++ b/pythonbindings/src/gpu/submodules/probes.cpp @@ -0,0 +1,55 @@ +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> +#include <gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/Probe.h> +#include <gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PointProbe.h> +#include <gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PlaneProbe.h> +#include <gpu/VirtualFluids_GPU/PreCollisionInteractor/PreCollisionInteractor.h> + +namespace probes +{ + namespace py = pybind11; + + py::module makeModule(py::module_ &parentModule) + { + py::module probeModule = parentModule.def_submodule("probes"); + + py::enum_<PostProcessingVariable>(probeModule, "PostProcessingVariable") + .value("Instantaneous", PostProcessingVariable::Instantaneous) + .value("Means", PostProcessingVariable::Means) + .value("Variances", PostProcessingVariable::Variances); + + py::class_<Probe, PreCollisionInteractor, std::shared_ptr<Probe>>(probeModule, "Probe") + .def("add_post_processing_variable", &Probe::addPostProcessingVariable); + + py::class_<PointProbe, Probe, std::shared_ptr<PointProbe>>(probeModule, "PointProbe") + .def(py::init< + const std::string, + const std::string, + uint, + uint, + uint>(), + "probe_name", + "output_path" + "t_start_avg", + "t_start_out", + "t_out") + .def("add_probe_points_from_list", &PointProbe::addProbePointsFromList) + .def("add_probe_points_from_x_normal_plane", &PointProbe::addProbePointsFromXNormalPlane); + + py::class_<PlaneProbe, Probe, std::shared_ptr<PlaneProbe>>(probeModule, "PlaneProbe") + .def(py::init< + const std::string, + const std::string, + uint, + uint, + uint>(), + "probe_name", + "output_path" + "t_start_avg", + "t_start_out", + "t_out") + .def("set_probe_plane", &PlaneProbe::setProbePlane); + + return probeModule; + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/simulation.cpp b/pythonbindings/src/gpu/submodules/simulation.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9683e8768417ad2422fb1a53ef6a428543bceffc --- /dev/null +++ b/pythonbindings/src/gpu/submodules/simulation.cpp @@ -0,0 +1,25 @@ +#include <pybind11/pybind11.h> +#include <gpu/VirtualFluids_GPU/LBM/Simulation.h> +#include <gpu/VirtualFluids_GPU/Communication/Communicator.h> +#include <gpu/VirtualFluids_GPU/Kernel/Utilities/KernelFactory/KernelFactory.h> +#include <gpu/VirtualFluids_GPU/PreProcessor/PreProcessorFactory/PreProcessorFactory.h> +#include <gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.h> +#include <gpu/VirtualFluids_GPU/Parameter/Parameter.h> +#include <gpu/VirtualFluids_GPU/GPU/CudaMemoryManager.h> +#include <gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.h> +#include <gpu/VirtualFluids_GPU/Output/DataWriter.h> + +namespace simulation +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::class_<Simulation>(parentModule, "Simulation") + .def(py::init<vf::gpu::Communicator&>(), "communicator") + .def("set_factories", &Simulation::setFactories) + .def("init", &Simulation::init) + .def("run", &Simulation::run) + .def("free", &Simulation::free); + } +} \ No newline at end of file diff --git a/pythonbindings/src/lbm/lbm.cpp b/pythonbindings/src/lbm/lbm.cpp new file mode 100644 index 0000000000000000000000000000000000000000..441b9ff372f4e4513fee58c4a8a1cd78d38582dd --- /dev/null +++ b/pythonbindings/src/lbm/lbm.cpp @@ -0,0 +1,13 @@ +#include <pybind11/pybind11.h> + +namespace lbm +{ + namespace py = pybind11; + + py::module makeModule(py::module_ &parentModule) + { + py::module lbmModule = parentModule.def_submodule("lbm"); + + return lbmModule; + } +} \ No newline at end of file diff --git a/pythonbindings/src/logger/logger.cpp b/pythonbindings/src/logger/logger.cpp new file mode 100644 index 0000000000000000000000000000000000000000..82ad3d92760ae38c0eb62b16be726e4eeaca08ac --- /dev/null +++ b/pythonbindings/src/logger/logger.cpp @@ -0,0 +1,25 @@ +#include <pybind11/pybind11.h> +#include <logger/Logger.h> + +namespace logging +{ + namespace py = pybind11; + + py::module makeModule(py::module_ &parentModule) + { + py::module loggerModule = parentModule.def_submodule("logger"); + + py::class_<vf::logging::Logger>(loggerModule, "Logger") + .def("initialize_logger", &vf::logging::Logger::initalizeLogger) + .def("change_log_path", &vf::logging::Logger::changeLogPath); + + // use f-strings (f"text {float}") in python for compounded messages + loggerModule.def("vf_log_trace", [](std::string arg){ VF_LOG_TRACE(arg); }); + loggerModule.def("vf_log_debug", [](std::string arg){ VF_LOG_DEBUG(arg); }); + loggerModule.def("vf_log_info", [](std::string arg){ VF_LOG_INFO(arg); }); + loggerModule.def("vf_log_warning", [](std::string arg){ VF_LOG_WARNING(arg); }); + loggerModule.def("vf_log_critical", [](std::string arg){ VF_LOG_CRITICAL(arg); }); + + return loggerModule; + } +} // namespace logging diff --git a/src/cpu/pythonbindings/src/muParser.cpp b/pythonbindings/src/muParser.cpp similarity index 100% rename from src/cpu/pythonbindings/src/muParser.cpp rename to pythonbindings/src/muParser.cpp diff --git a/setup.py b/setup.py index ffe6663be9561a209945b91bb396254b703ae892..0651e2f22e5f50371da42cf1abd4136d7bae990a 100644 --- a/setup.py +++ b/setup.py @@ -10,16 +10,16 @@ from distutils.version import LooseVersion vf_cmake_args = [ "-DBUILD_VF_PYTHON_BINDINGS=ON", - "-DBUILD_VF_DOUBLE_ACCURACY=ON", + "-DBUILD_VF_DOUBLE_ACCURACY=OFF", "-DCMAKE_CXX_COMPILER_LAUNCHER=ccache", "-DCMAKE_CUDA_COMPILER_LAUNCHER=ccache", "-DCMAKE_C_COMPILER_LAUNCHER=ccache", - "-DBUILD_VF_CPU:BOOL=ON", - "-DBUILD_VF_GPU:BOOL=OFF", + "-DBUILD_VF_CPU:BOOL=OFF", + "-DBUILD_VF_GPU:BOOL=ON", "-DUSE_METIS=ON", "-DUSE_MPI=ON", "-DBUILD_SHARED_LIBS=OFF", - "-DBUILD_VF_UNIT_TESTS:BOOL=ON", + "-DBUILD_VF_UNIT_TESTS:BOOL=OFF", "-DBUILD_WARNINGS_AS_ERRORS=OFF" ] diff --git a/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h b/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h index 57290025c3f6e48554e1dafe9bd101ae237b3288..6ab8efc88d02e1032c2d26c756e84d4fa33359ac 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h +++ b/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h @@ -28,7 +28,7 @@ // //! \file GridBuilder.h //! \ingroup grid -//! \author Soeren Peters, Stephan Lenz, Martin Schönherr +//! \author Soeren Peters, Stephan Lenz, Martin Sch�nherr //======================================================================================= #ifndef GridBuilder_H #define GridBuilder_H @@ -37,7 +37,7 @@ #include <string> #include <memory> -#include "GridGenerator/global.h" +#include "global.h" #define GEOMQS 6 #define INLETQS 0 diff --git a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp index 565a02a2807ef15679bf08fa001ea9a03f78ca4e..c36a8cb70e6bb36dccb9179b9c014e5fb7464a30 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp +++ b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp @@ -28,7 +28,7 @@ // //! \file MultipleGridBuilder.cpp //! \ingroup grid -//! \author Soeren Peters, Stephan Lenz, Martin Schönherr +//! \author Soeren Peters, Stephan Lenz, Martin Sch�nherr //======================================================================================= #include "MultipleGridBuilder.h" diff --git a/src/gpu/VirtualFluids_GPU/CMakeLists.txt b/src/gpu/VirtualFluids_GPU/CMakeLists.txt index 116e987664ba14b83054c823ff9cf6505fccf769..14fdadba44069dbb098f8922b208397a609275af 100644 --- a/src/gpu/VirtualFluids_GPU/CMakeLists.txt +++ b/src/gpu/VirtualFluids_GPU/CMakeLists.txt @@ -12,7 +12,7 @@ vf_add_library(PUBLIC_LINK basics lbmCuda PRIVATE_LINK ${additional_libraries} G #https://stackoverflow.com/questions/6832666/lnk2019-when-including-asio-headers-solution-generated-with-cmake #https://stackoverflow.com/questions/27442885/syntax-error-with-stdnumeric-limitsmax -set_target_properties(VirtualFluids_GPU PROPERTIES CUDA_SEPARABLE_COMPILATION ON) +set_target_properties(VirtualFluids_GPU PROPERTIES CUDA_SEPARABLE_COMPILATION ON POSITION_INDEPENDENT_CODE ON) vf_add_tests() diff --git a/src/gpu/VirtualFluids_GPU/Calculation/UpdateGrid27.cpp b/src/gpu/VirtualFluids_GPU/Calculation/UpdateGrid27.cpp index 78f8b7f589430eb303fe4a59df2458da863427fc..1fec35ed1cf86b09c04bf861a3386cab3b35410d 100644 --- a/src/gpu/VirtualFluids_GPU/Calculation/UpdateGrid27.cpp +++ b/src/gpu/VirtualFluids_GPU/Calculation/UpdateGrid27.cpp @@ -9,9 +9,6 @@ #include "Kernel/Kernel.h" #include "GPU/TurbulentViscosity.h" -void interactWithActuators(Parameter* para, CudaMemoryManager* cudaManager, int level, unsigned int t); -void interactWithProbes(Parameter* para, CudaMemoryManager* cudaManager, int level, unsigned int t); - void updateGrid27(Parameter* para, vf::gpu::Communicator& comm, CudaMemoryManager* cudaManager, diff --git a/src/gpu/VirtualFluids_GPU/Calculation/UpdateGrid27.h b/src/gpu/VirtualFluids_GPU/Calculation/UpdateGrid27.h index 68288a7fdd34b4b17ed75dd461302f49dcba6f3e..e7e411807c25022957bc0218427b2b367663a23e 100644 --- a/src/gpu/VirtualFluids_GPU/Calculation/UpdateGrid27.h +++ b/src/gpu/VirtualFluids_GPU/Calculation/UpdateGrid27.h @@ -40,4 +40,8 @@ extern "C" void coarseToFine(Parameter* para, int level); extern "C" void calcTurbulentViscosity(Parameter* para, int level); +extern "C" void interactWithActuators(Parameter* para, CudaMemoryManager* cudaManager, int level, unsigned int t); + +extern "C" void interactWithProbes(Parameter* para, CudaMemoryManager* cudaManager, int level, unsigned int t); + #endif diff --git a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.h b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.h index 70a2a8ec629809689096ce0b33a197924cf000a2..3f2834e1157f4e7f9c44fb9db8987d1b0e679a5e 100644 --- a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.h +++ b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.h @@ -9,7 +9,7 @@ #include "PointerDefinitions.h" #include "VirtualFluids_GPU_export.h" -#include <GridGenerator/io/SimulationFileWriter/SimulationFileWriter.h> +#include "gpu/GridGenerator/io/SimulationFileWriter/SimulationFileWriter.h" class Parameter; class GridBuilder; diff --git a/src/lbm/cuda/CMakeLists.txt b/src/lbm/cuda/CMakeLists.txt index 3a88d91648b960915279fc4f133f6b60047149bf..4142b7c3b1c46275c3257e3dfd657cc6b30c841d 100644 --- a/src/lbm/cuda/CMakeLists.txt +++ b/src/lbm/cuda/CMakeLists.txt @@ -4,7 +4,7 @@ project(lbmCuda LANGUAGES CUDA CXX) vf_add_library(NAME lbmCuda BUILDTYPE static PUBLIC_LINK basics FOLDER ../../lbm) -set_target_properties(lbmCuda PROPERTIES CUDA_SEPARABLE_COMPILATION ON) +set_target_properties(lbmCuda PROPERTIES CUDA_SEPARABLE_COMPILATION ON POSITION_INDEPENDENT_CODE ON) set_source_files_properties(../KernelParameter.cpp PROPERTIES LANGUAGE CUDA)