diff --git a/.gitignore b/.gitignore index fbab1b2097fad956dceb05769613cb82053b27e8..63bd843b606911d303ce1476fc002c009b8ebc9a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,8 +8,10 @@ run/ _skbuild/ dist/ *.egg-info/ -__pycache__/ +**/__pycache__/ .venv/ +pythonbindings/pyfluids/bindings* +pythonbindings/pymuparser/bindings* # IDE .vscode/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 22cc5bdf03e3870b94327bf207d9ce163a321013..e6ef4c9a0584c55adc9f745bcfdca4d1bbb08fbe 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -126,13 +126,14 @@ gcc_9_python: paths: - build/ - dist/ + - _skbuild/ before_script: - export CCACHE_BASEDIR=$CI_PROJECT_DIR - export CCACHE_DIR=$CI_PROJECT_DIR/cache script: - - python3 setup.py bdist_wheel build_ext --build-temp=build + - python3 setup.py bdist_wheel build_ext --build-temp=_skbuild -- -DBUILD_VF_CPU=ON -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DCMAKE_CUDA_COMPILER_LAUNCHER=ccache -DCMAKE_C_COMPILER_LAUNCHER=ccache ############################################################################### ## Container Upload ## diff --git a/CMake/cmake_config_files/MULE.config.cmake b/CMake/cmake_config_files/MULE.config.cmake index 02f61b7988c5b3af9cd58bc52e46b1b2edfe8aae..2afbce6cc257fa0b8ff4dd7de580cb50c01369f1 100644 --- a/CMake/cmake_config_files/MULE.config.cmake +++ b/CMake/cmake_config_files/MULE.config.cmake @@ -1 +1,4 @@ -SET(CMAKE_CUDA_ARCHITECTURES "75") \ No newline at end of file +SET(CMAKE_CUDA_ARCHITECTURES "75") + +list(APPEND USER_APPS "apps/gpu/LBM/ActuatorLine") +list(APPEND USER_APPS "apps/gpu/LBM/SphereScaling") diff --git a/CMakePresets.json b/CMakePresets.json index 0f360fd303cdcad923b01d56df5c6d48ad62ca2c..c53482ec72109f1a672b97797763d027a6ec80bf 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -9,26 +9,29 @@ { "name": "default", "hidden": true, - "binaryDir": "${sourceDir}/build/", - "cacheVariables": { - "BUILD_VF_UNIT_TESTS": "ON" - } + "binaryDir": "${sourceDir}/build/" }, { - "name": "default_make", - "inherits": "default", + "name": "msvc", + "hidden": true, + "generator": "Visual Studio 16 2019", + "architecture": "x64" + }, + { + "name": "make", "hidden": true, "generator": "Unix Makefiles" }, { - "name": "default_msvc", - "inherits": "default", + "name": "unit_tests", "hidden": true, - "generator": "Visual Studio 16 2019", - "architecture": "x64" + "cacheVariables": { + "BUILD_VF_UNIT_TESTS": "ON" + } }, { - "name": "default_cpu", + "name": "cpu", + "inherits": "default", "hidden": true, "description": "CPU build of VirtualFluids", "cacheVariables": { @@ -37,7 +40,8 @@ } }, { - "name": "default_gpu", + "name": "gpu", + "inherits": "default", "hidden": true, "description": "GPU build of VirtualFluids", "cacheVariables": { @@ -46,92 +50,213 @@ } }, { - "name": "default_gpu_numerical_tests", - "inherits": [ - "default_gpu" - ], + "name": "debug", "hidden": true, - "description": "GPU numerical tests of VirtualFluids", "cacheVariables": { - "BUILD_VF_DOUBLE_ACCURACY": "ON", - "BUILD_NUMERIC_TESTS": "ON" + "CMAKE_BUILD_TYPE": "Debug" } }, { - "name": "default_all", + "name": "release", "hidden": true, - "description": "All build of VirtualFluids", - "inherits": [ - "default_cpu", - "default_gpu" - ], "cacheVariables": { - "BUILD_VF_DOUBLE_ACCURACY": "ON" + "CMAKE_BUILD_TYPE": "Release" } }, { - "name": "cpu_make", - "inherits": [ - "default_make", - "default_cpu" - ], - "displayName": "cpu make configuration" - }, - { - "name": "cpu_msvc", - "inherits": [ - "default_msvc", - "default_cpu" - ], - "displayName": "cpu msvc configuration" + "name": "min_size_rel", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "MinSizeRel" + } }, { - "name": "gpu_make", - "inherits": [ - "default_make", - "default_gpu" - ], - "displayName": "gpu make configuration" + "name": "rel_with_deb_info", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + } }, { - "name": "gpu_msvc", + "name": "gpu_numerical_tests", "inherits": [ - "default_msvc", - "default_gpu" + "gpu", + "unit_tests" ], - "displayName": "gpu msvc configuration" + "hidden": true, + "description": "GPU numerical tests of VirtualFluids", + "cacheVariables": { + "BUILD_VF_DOUBLE_ACCURACY": "ON", + "BUILD_NUMERIC_TESTS": "ON" + } }, { "name": "all_make", "inherits": [ - "default_make", - "default_all" + "cpu", + "gpu", + "unit_tests", + "make" ], "displayName": "all make configuration" }, { "name": "all_msvc", "inherits": [ - "default_msvc", - "default_all" + "cpu", + "gpu", + "unit_tests", + "msvc" ], "displayName": "all msvc configuration" }, { "name": "gpu_numerical_tests_make", "inherits": [ - "default_make", - "default_gpu_numerical_tests" + "gpu_numerical_tests", + "make" ], "displayName": "gpu numerical tests make configuration" }, { "name": "gpu_numerical_tests_msvc", "inherits": [ - "default_msvc", - "default_gpu_numerical_tests" + "msvc", + "gpu_numerical_tests" ], "displayName": "gpu numerical tests msvc configuration" + }, + { + "name": "debug_make_gpu", + "displayName": "Debug GPU Make", + "inherits": [ + "gpu", + "make", + "debug" + ] + }, + { + "name": "release_make_gpu", + "displayName": "Release GPU Make", + "inherits": [ + "gpu", + "make", + "release" + ] + }, + { + "name": "min_size_rel_make_gpu", + "displayName": "MinSizeRel GPU Make", + "inherits": [ + "gpu", + "make", + "min_size_rel" + ] + }, + { + "name": "rel_with_deb_info_make_gpu", + "displayName": "RelWithDebInfo GPU Make", + "inherits": [ + "gpu", + "make", + "rel_with_deb_info" + ] + }, + { + "name": "debug_msvc_gpu", + "displayName": "Debug GPU MSVC", + "inherits": [ + "gpu", + "msvc", + "debug" + ] + }, + { + "name": "release_msvc_gpu", + "displayName": "Release GPU MSVC", + "inherits": [ + "gpu", + "msvc", + "release" + ] + }, + { + "name": "min_size_rel_msvc_gpu", + "displayName": "MinSizeRel GPU MSVC", + "inherits": [ + "gpu", + "msvc", + "min_size_rel" + ] + }, + { + "name": "rel_with_deb_info_msvc_gpu", + "displayName": "RelWithDebInfo GPU MSVC", + "inherits": [ + "gpu", + "msvc", + "rel_with_deb_info" + ] + } + ], + "buildPresets": [ + { + "name": "Default", + "hidden": true, + "configurePreset": "default", + "jobs": 4 + }, + { + "name": "GPU", + "hidden": true, + "configurePreset": "gpu", + "targets": [ + "ActuatorLine", + "DrivenCavity", + "BoundaryLayer" + ], + "inherits": [ + "Default" + ] + }, + { + "name": "Release", + "hidden": true, + "configurePreset": "release" + }, + { + "name": "Debug_Make_GPU", + "displayName": "Debug", + "description": "Compile GPU version with debug information", + "configurePreset": "debug_make_gpu", + "inherits": [ + "GPU" + ] + }, + { + "name": "MinSizeRel_Make_GPU", + "displayName": "MinSizeRel", + "configurePreset": "min_size_rel_make_gpu", + "inherits": [ + "GPU" + ] + }, + { + "name": "RelWithDebInfo_GPU", + "displayName": "RelWithDebInfo", + "configurePreset": "rel_with_deb_info_make_gpu", + "inherits": [ + "GPU" + ] + }, + { + "name": "Release_GPU", + "description": "Build release version of GPU", + "displayName": "Release GPU", + "configurePreset": "release_make_gpu", + "inherits": [ + "GPU" + ] } ] -} +} \ No newline at end of file diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000000000000000000000000000000000000..adafcf99560acd9da79aa060194df8263b6e77e0 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include pythonbindings/*/bindings* \ No newline at end of file diff --git a/Python/SlurmTests/poiseuille/settings.py b/Python/SlurmTests/poiseuille/settings.py index 4b4a1e4e9cc7f6118a60c22a40c70b027e3ac4e2..a3cdc5dc8b627612c2d57a58db36c9fbaa72efac 100644 --- a/Python/SlurmTests/poiseuille/settings.py +++ b/Python/SlurmTests/poiseuille/settings.py @@ -1,25 +1,58 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file settings.py +! \ingroup Poiseuille +! \author Sven Marcus, Henry Korb +======================================================================================= +""" import os from acousticscaling import OneDirectionalAcousticScaling -from pyfluids.cpu.kernel import LBMKernel, KernelType -from pyfluids.cpu.parameters import RuntimeParameters, GridParameters, PhysicalParameters +from pyfluids import cpu -grid_params = GridParameters() +grid_params = cpu.parameters.GridParameters() grid_params.node_distance = 1 grid_params.number_of_nodes_per_direction = [1, 1, 16] grid_params.blocks_per_direction = [1, 1, 4] grid_params.periodic_boundary_in_x1 = True grid_params.periodic_boundary_in_x2 = True -physical_params = PhysicalParameters() +physical_params = cpu.parameters.PhysicalParameters() physical_params.lattice_viscosity = 1e-4 -runtime_params = RuntimeParameters() +runtime_params = cpu.parameters.RuntimeParameters() runtime_params.number_of_threads = int(os.environ["PYFLUIDS_NUM_THREADS"]) runtime_params.number_of_timesteps = 4_000_000 runtime_params.timestep_log_interval = 1_000_000 -kernel = LBMKernel(KernelType.CompressibleCumulantFourthOrderViscosity) +kernel = cpu.kernel.LBMKernel(cpu.kernel.KernelType.CompressibleCumulantFourthOrderViscosity) kernel.use_forcing = True kernel.forcing_in_x1 = 5e-10 diff --git a/Python/acousticscaling.py b/Python/acousticscaling.py index a664b8e924d648b680562b9aef11bee87b3562b1..7e71fed9fdd9f86415261ef4e22797021581f60c 100644 --- a/Python/acousticscaling.py +++ b/Python/acousticscaling.py @@ -1,22 +1,55 @@ -from pyfluids.cpu.kernel import LBMKernel -from pyfluids.cpu.parameters import GridParameters, PhysicalParameters, RuntimeParameters +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file acousticscaling.py +! \ingroup tests +! \author Sven Marcus, Henry Korb +======================================================================================= +""" +from pyfluids import cpu class OneDirectionalAcousticScaling: - def __init__(self, grid_parameters: GridParameters, - physical_parameters: PhysicalParameters, - runtime_parameters: RuntimeParameters, - kernel: LBMKernel): + def __init__(self, grid_parameters: cpu.parameters.GridParameters, + physical_parameters: cpu.parameters.PhysicalParameters, + runtime_parameters: cpu.parameters.RuntimeParameters, + kernel: cpu.kernel.LBMKernel): self._grid_params = grid_parameters self._physical_params = physical_parameters self._runtime_params = runtime_parameters self._kernel = kernel - def configuration_for_scale_level(self, level: int = 1) -> tuple[GridParameters, - PhysicalParameters, - RuntimeParameters, - LBMKernel]: + def configuration_for_scale_level(self, level: int = 1) -> tuple[cpu.parameters.GridParameters, + cpu.parameters.PhysicalParameters, + cpu.parameters.RuntimeParameters, + cpu.kernel.LBMKernel]: if level < 0: raise ValueError("level must be >= 0") @@ -27,8 +60,8 @@ class OneDirectionalAcousticScaling: return grid_params, physical_params, runtime_params, kernel - def clone_grid_params_for_level(self, level) -> GridParameters: - grid_params = GridParameters() + def clone_grid_params_for_level(self, level) -> cpu.parameters.GridParameters: + grid_params = cpu.parameters.GridParameters() grid_params.reference_direction_index = self._grid_params.reference_direction_index grid_params.periodic_boundary_in_x1 = self._grid_params.periodic_boundary_in_x1 grid_params.periodic_boundary_in_x2 = self._grid_params.periodic_boundary_in_x2 @@ -51,7 +84,7 @@ class OneDirectionalAcousticScaling: return grid_params def clone_physical_parameters(self, level): - physical_params = PhysicalParameters() + physical_params = cpu.parameters.PhysicalParameters() physical_params.lattice_viscosity = self._physical_params.lattice_viscosity if level > 0: @@ -60,7 +93,7 @@ class OneDirectionalAcousticScaling: return physical_params def clone_runtime_params_for_level(self, level): - runtime_params = RuntimeParameters() + runtime_params = cpu.parameters.RuntimeParameters() runtime_params.number_of_timesteps = self._runtime_params.number_of_timesteps runtime_params.number_of_threads = self._runtime_params.number_of_threads runtime_params.timestep_log_interval = self._runtime_params.timestep_log_interval @@ -71,7 +104,7 @@ class OneDirectionalAcousticScaling: return runtime_params def clone_kernel_for_level(self, level): - kernel = LBMKernel(self._kernel.type) + kernel = cpu.kernel.LBMKernel(self._kernel.type) kernel.use_forcing = self._kernel.use_forcing kernel.forcing_in_x1 = self._kernel.forcing_in_x1 kernel.forcing_in_x2 = self._kernel.forcing_in_x2 diff --git a/Python/actuator_line/actuator_line.py b/Python/actuator_line/actuator_line.py index 6e3c8608617df1267535984d53307dea9184c6ab..721af737ff6ef3340c3c2f6204aa6a7824cd1d2f 100644 --- a/Python/actuator_line/actuator_line.py +++ b/Python/actuator_line/actuator_line.py @@ -1,23 +1,48 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file actuator_line.py +! \ingroup actuator_line +! \author Henry Korb, Henrik Asmuth +======================================================================================= +""" #%% import numpy as np from pathlib import Path from mpi4py import MPI -from pyfluids import basics, gpu, logger +from pyfluids.bindings import basics, gpu, logger #%% -reference_diameter = 126 - -length = np.array([29,6,6])*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") +sim_name = "ABL" +config_file = Path(__file__).parent/"configActuatorLine.txt" output_path = Path(__file__).parent/Path("output") output_path.mkdir(exist_ok=True) -t_out = 100. -t_end = 500. + #%% logger.Logger.initialize_logger() @@ -25,87 +50,175 @@ 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) -# %% -comm = gpu.Communicator.get_instance() #%% grid_factory = gpu.grid_generator.GridFactory.make() grid_builder = gpu.grid_generator.MultipleGridBuilder.make_shared(grid_factory) +communicator = gpu.Communicator.get_instance() -#%% -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) -#%% config = basics.ConfigurationFile() config.load(str(config_file)) + +para = gpu.Parameter(communicator.get_number_of_process(), communicator.get_pid(), config) +bc_factory = gpu.BoundaryConditionFactory() + #%% -para = gpu.Parameter(config, comm.get_number_of_process(), comm.get_pid()) +turbine_diameter = config.get_float_value("turbineDiameter", 126) +boundary_layer_height = config.get_float_value("boundaryLayerHeight", 1000) +z0 = config.get_float_value("z0", 0.1) +u_star = config.get_float_value("u_star", 0.4) + +kappa = config.get_float_value("vonKarmanConstant", 0.4) # von Karman constant + +viscosity = config.get_float_value("viscosity", 1.56e-5) + +velocity = 0.5*u_star/kappa*np.log(boundary_layer_height/z0+1) #0.5 times max mean velocity at the top in m/s + +mach = config.get_float_value("Ma", 0.1) +nodes_per_height = config.get_uint_value("nz", 64) + + +turb_pos = np.array([3,3,3])*turbine_diameter +epsilon = config.get_float_value("SmearingWidth", 5) +density = config.get_float_value("Density", 1.225) +level = 0 +n_blades = 3 +n_blade_nodes = config.get_int_value("NumberOfNodesPerAL", 32) + +read_precursor = config.get_bool_value("readPrecursor", False) + +if read_precursor: + nTReadPrecursor = config.get_int_value("nTimestepsReadPrecursor") + use_distributions = config.get_bool_value("useDistributions", False) + precursor_directory = config.get_string_value("precursorDirectory") + +# all in s +t_start_out = config.get_float_value("tStartOut") +t_out = config.get_float_value("tOut") +t_end = config.get_float_value("tEnd") # total time of simulation +t_start_averaging = config.get_float_value("tStartAveraging") +t_start_tmp_averaging = config.get_float_value("tStartTmpAveraging") +t_averaging = config.get_float_value("tAveraging") +t_start_out_probe = config.get_float_value("tStartOutProbe") +t_out_probe = config.get_float_value("tOutProbe") + +#%% +length = np.array([6,4,1])*boundary_layer_height +dx = boundary_layer_height/nodes_per_height dt = dx * mach / (np.sqrt(3) * velocity) -velocity_lb = velocity * dt / dx # LB units -viscosity_lb = viscosity * dt / (dx * dx) # LB units +velocity_ratio = dx/dt +velocity_LB = velocity / velocity_ratio # LB units +viscosity_LB = viscosity / (velocity_ratio * dx) # LB units +pressure_gradient = u_star * u_star / boundary_layer_height +pressure_gradient_LB = pressure_gradient * (dt*dt)/dx + +logger.vf_log_info(f"velocity [dx/dt] = {velocity_LB}") +logger.vf_log_info(f"dt = {dt}") +logger.vf_log_info(f"dx = {dx}") +logger.vf_log_info(f"viscosity [10^8 dx^2/dt] = {viscosity_LB*1e8}") +logger.vf_log_info(f"u* /(dx/dt) = {u_star*dt/dx}") +logger.vf_log_info(f"dpdx = {pressure_gradient}") +logger.vf_log_info(f"dpdx /(dx/dt^2) = {pressure_gradient_LB}") + #%% -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_forcing(pressure_gradient_LB, 0, 0) +para.set_velocity_LB(velocity_LB) +para.set_viscosity_LB(viscosity_LB) para.set_velocity_ratio(dx/dt) para.set_viscosity_ratio(dx*dx/dt) -para.set_main_kernel("TurbulentViscosityCumulantK17CompChim") -para.set_use_AMD(True) -para.set_SGS_constant(0.083) +para.set_density_ratio(1.0) -def init_func(coord_x, coord_y, coord_z): - return [0.0, velocity_lb, 0.0, 0.0] +para.set_main_kernel("CumulantK17") -para.set_initial_condition(init_func) -para.set_t_out(int(t_out/dt)) -para.set_t_end(int(t_end/dt)) +para.set_timestep_start_out(int(t_start_out/dt)) +para.set_timestep_out(int(t_out/dt)) +para.set_timestep_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.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) +tm_factory = gpu.TurbulenceModelFactory(para) +tm_factory.read_config_file(config) +#%% +grid_scaling_factory = gpu.GridScalingFactory() +grid_scaling_factory.set_scaling_factory(gpu.GridScaling.ScaleCompressible) -grid_builder.set_pressure_boundary_condition(gpu.SideType.PX, 0.0) +grid_builder.add_coarse_grid(0.0, 0.0, 0.0, *length, dx) +grid_builder.set_periodic_boundary_condition(not read_precursor, True, False) +grid_builder.build_grids(basics.LbmOrGks.LBM, False) +sampling_offset = 2 +if read_precursor: + precursor = gpu.create_file_collection(precursor_directory + "/precursor", gpu.FileType.VTK) + grid_builder.set_precursor_boundary_condition(gpu.SideType.MX, precursor, nTReadPrecursor, 0, 0, 0) + +grid_builder.set_stress_boundary_condition(gpu.SideType.MZ, 0, 0, 1, sampling_offset, z0, dx) +para.set_has_wall_model_monitor(True) +grid_builder.set_slip_boundary_condition(gpu.SideType.PZ, 0, 0, -1) + +if read_precursor: + grid_builder.set_pressure_boundary_condition(gpu.SideType.PX, 0) +bc_factory.set_stress_boundary_condition(gpu.StressBC.StressPressureBounceBack) +bc_factory.set_slip_boundary_condition(gpu.SlipBC.SlipBounceBack) +bc_factory.set_pressure_boundary_condition(gpu.PressureBC.OutflowNonReflective) +if read_precursor: + bc_factory.set_precursor_boundary_condition(gpu.PrecursorBC.DistributionsPrecursor if use_distributions else gpu.PrecursorBC.VelocityPrecursor) +para.set_outflow_pressure_correction_factor(0.0); #%% -cuda_memory_manager = gpu.CudaMemoryManager(para) -grid_generator = gpu.GridProvider.make_grid_generator(grid_builder, para, cuda_memory_manager, comm) +# don't use python init functions, they are very slow! Just kept as an example. +# Define lambda in bindings and set it here. +# def init_func(coord_x, coord_y, coord_z): +# return [ +# 0.0, +# (u_star/0.4 * np.log(np.maximum(coord_z,z0)/z0) + 2.0*np.sin(np.pi*16*coord_x/length[0])*np.sin(np.pi*8*coord_z/boundary_layer_height)/(np.square(coord_z/boundary_layer_height)+1)) * dt / dx, +# 2.0*np.sin(np.pi*16.*coord_x/length[0])*np.sin(np.pi*8.*coord_z/boundary_layer_height)/(np.square(coord_z/boundary_layer_height)+1.) * dt / dx, +# 8.0*u_star/0.4*(np.sin(np.pi*8.0*coord_y/boundary_layer_height)*np.sin(np.pi*8.0*coord_z/boundary_layer_height)+np.sin(np.pi*8.0*coord_x/length[0]))/(np.square(length[2]/2.0-coord_z)+1.) * dt / dx] +# para.set_initial_condition(init_func) +para.set_initial_condition_perturbed_log_law(u_star, z0, length[0], length[2], boundary_layer_height, velocity_ratio) + #%% -turb_pos = np.array([3,3,3])*reference_diameter -epsilon = 5 +turb_pos = np.array([3,3,3])*turbine_diameter +epsilon = 1.5*dx 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) +omega = 1 +blade_radii = np.arange(n_blade_nodes, dtype=np.float32)/(0.5*turbine_diameter) +alm = gpu.ActuatorFarm(n_blades, density, n_blade_nodes, epsilon, level, dt, dx, True) +alm.add_turbine(turb_pos[0],turb_pos[1],turb_pos[2], turbine_diameter, omega, 0, 0, blade_radii) para.add_actuator(alm) #%% -point_probe = gpu.probes.PointProbe("pointProbe", str(output_path), 100, 1, 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_statistic(gpu.probes.Statistic.Means) - -para.add_probe(point_probe) - -plane_probe = gpu.probes.PlaneProbe("planeProbe", str(output_path), 100, 1, 500, 100) -plane_probe.set_probe_plane(5*reference_diameter, 0, 0, dx, length[1], length[2]) -para.add_probe(plane_probe) +planar_average_probe = gpu.probes.PlanarAverageProbe("horizontalPlanes", para.get_output_path(), 0, int(t_start_tmp_averaging/dt), int(t_averaging/dt) , int(t_start_out_probe/dt), int(t_out_probe/dt), 'z') +planar_average_probe.add_all_available_statistics() +planar_average_probe.set_file_name_to_n_out() +para.add_probe(planar_average_probe) #%% -sim = gpu.Simulation(para, cuda_memory_manager, comm, grid_generator) +wall_model_probe = gpu.probes.WallModelProbe("wallModelProbe", para.get_output_path(), 0, int(t_start_tmp_averaging/dt), int(t_averaging/dt/4), int(t_start_out_probe/dt), int(t_out_probe/dt)) +wall_model_probe.add_all_available_statistics() +wall_model_probe.set_file_name_to_n_out() +wall_model_probe.set_force_output_to_stress(True) +if para.get_is_body_force(): + wall_model_probe.set_evaluate_pressure_gradient(True) +para.add_probe(wall_model_probe) + +plane_locs = [100,] +if read_precursor: plane_locs.extend([1000, 1500, 2000, 2500, 0]) + +for n_probe, probe_pos in enumerate(plane_locs): + plane_probe = gpu.probes.PlaneProbe(f"planeProbe_{n_probe+1}", para.get_output_path(), int(t_start_averaging/dt), 10, int(t_start_out_probe/dt), int(t_out_probe/dt)) + plane_probe.set_probe_plane(probe_pos, 0, 0, dx, length[1], length[2]) + plane_probe.add_all_available_statistics() + para.add_probe(plane_probe) +#%% +cuda_memory_manager = gpu.CudaMemoryManager(para) +grid_generator = gpu.GridProvider.make_grid_generator(grid_builder, para, cuda_memory_manager, communicator) +#%% +#%% +sim = gpu.Simulation(para, cuda_memory_manager, communicator, grid_generator, bc_factory, tm_factory, grid_scaling_factory) #%% sim.run() -MPI.Finalize() \ No newline at end of file +MPI.Finalize() + diff --git a/Python/actuator_line/config.txt b/Python/actuator_line/config.txt deleted file mode 100644 index e4c778c4cc048f54c0a32310e6bf4a7343a263fa..0000000000000000000000000000000000000000 --- a/Python/actuator_line/config.txt +++ /dev/null @@ -1,2 +0,0 @@ -Path = . -GridPath = . diff --git a/Python/actuator_line/configActuatorLine.txt b/Python/actuator_line/configActuatorLine.txt new file mode 100644 index 0000000000000000000000000000000000000000..c45d170f039274ab355f3fe1dc044536f1f29e6f --- /dev/null +++ b/Python/actuator_line/configActuatorLine.txt @@ -0,0 +1,39 @@ +################################################## +#informations for Writing +################################################## +Path = . +################################################## +#informations for reading +################################################## +GridPath = . +################################################## +Devices = 0 +################################################## +tStartOut = 0 +tOut = 100000 +tEnd = 300000 +################################################## +tStartAveraging = 0 +tStartTmpAveraging = 100000 +tAveraging = 200 +tStartOutProbe = 0 +tOutProbe = 1000 +################################################## +Ma = 0.1 +nz = 96 + +bodyForce = true +SGSconstant = 0.333 +TurbulenceModel = QR + +QuadricLimiterP = 100000.0 +QuadricLimiterM = 100000.0 +QuadricLimiterD = 100000.0 + +################################################## +readPrecursor = false +nTimestepsReadPrecursor = 1 +precursorFile = precursor/Precursor + +################################################## +turbineDiameter = 126.0 diff --git a/Python/boundary_layer/boundary_layer.py b/Python/boundary_layer/boundary_layer.py index 1c01f50946b49bc0ddab7e50065a24aab4ae869f..6f6c64bc072d3afbb8aa5febbec209c26af2deee 100644 --- a/Python/boundary_layer/boundary_layer.py +++ b/Python/boundary_layer/boundary_layer.py @@ -1,37 +1,48 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file boundary_layer.py +! \ingroup boundary_layer +! \author Henry Korb, Henrik Asmuth +======================================================================================= +""" #%% import numpy as np from pathlib import Path from mpi4py import MPI from pyfluids import basics, gpu, logger #%% -reference_height = 1000 # boundary layer height in m - -length = np.array([6,4,1])*reference_height -viscosity = 1.56e-5 -mach = 0.1 -nodes_per_height = 32 - -z_0 = 0.1 -u_star = 0.4 -kappa = 0.4 - -velocity = 0.5*u_star/kappa*np.log(length[2]/z_0+1) -flow_through_time = length[0]/velocity -use_AMD = True - - -sim_name = "BoundaryLayer" -config_file = Path(__file__).parent/Path("config.txt") +sim_name = "ABL" +config_file = Path(__file__).parent/"configBoundaryLayer.txt" output_path = Path(__file__).parent/Path("output") output_path.mkdir(exist_ok=True) -t_out = 1000. -t_end = 5000. -t_start_averaging = 0 -t_start_tmp_averaging = 100_000 -t_averaging = 200 -t_start_out_probe = 0 -t_out_probe = 1000 #%% logger.Logger.initialize_logger() @@ -39,95 +50,161 @@ 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) -# %% -comm = gpu.Communicator.get_instance() #%% grid_factory = gpu.grid_generator.GridFactory.make() grid_builder = gpu.grid_generator.MultipleGridBuilder.make_shared(grid_factory) +communicator = gpu.Communicator.get_instance() + +config = basics.ConfigurationFile() +config.load(str(config_file)) + +para = gpu.Parameter(communicator.get_number_of_process(), communicator.get_pid(), config) +bc_factory = gpu.BoundaryConditionFactory() #%% -dx = reference_height/nodes_per_height -dt = dx * mach / (np.sqrt(3) * velocity) -velocity_lb = velocity * dt / dx # LB units -viscosity_lb = viscosity * dt / (dx * dx) # LB units +boundary_layer_height = config.get_float_value("boundaryLayerHeight", 1000) +z0 = config.get_float_value("z0", 0.1) +u_star = config.get_float_value("u_star", 0.4) -pressure_gradient = u_star**2 / reference_height -pressure_gradient_lb = pressure_gradient * dt**2 / dx +kappa = config.get_float_value("vonKarmanConstant", 0.4) # von Karman constant -logger.vf_log_info(f"velocity = {velocity_lb:1.6} dx/dt") -logger.vf_log_info(f"dt = {dt:1.6}") -logger.vf_log_info(f"dx = {dx:1.6}") -logger.vf_log_info(f"u* = {u_star:1.6}") -logger.vf_log_info(f"dpdx = {pressure_gradient:1.6}") -logger.vf_log_info(f"dpdx = {pressure_gradient_lb:1.6} dx/dt^2") -logger.vf_log_info(f"viscosity = {viscosity_lb:1.6} dx^2/dt") +viscosity = config.get_float_value("viscosity", 1.56e-5) +velocity = 0.5*u_star/kappa*np.log(boundary_layer_height/z0+1) #0.5 times max mean velocity at the top in m/s -#%% -config = basics.ConfigurationFile() -config.load(str(config_file)) -#%% -para = gpu.Parameter(config, comm.get_number_of_process(), comm.get_pid()) +mach = config.get_float_value("Ma", 0.1) +nodes_per_height = config.get_uint_value("nz", 64) + + + +write_precursor = config.get_bool_value("_p", False) +read_precursor = config.get_bool_value("readPrecursor", False) + +if write_precursor: + nTWritePrecursor = config.get_int_value("nTimestepsWritePrecursor") + t_start_precursor = config.get_float_value("tStartPrecursor") + pos_x_precursor = config.get_float_value("posXPrecursor") +if read_precursor: + nTReadPrecursor = config.get_int_value("nTimestepsReadPrecursor") +if write_precursor or read_precursor: + use_distributions = config.get_bool_value("useDistributions", False) + precursor_directory = config.get_string_value("precursorDirectory") + +# all in s +t_start_out = config.get_float_value("tStartOut") +t_out = config.get_float_value("tOut") +t_end = config.get_float_value("tEnd") # total time of simulation + +t_start_averaging = config.get_float_value("tStartAveraging") +t_start_tmp_averaging = config.get_float_value("tStartTmpAveraging") +t_averaging = config.get_float_value("tAveraging") +t_start_out_probe = config.get_float_value("tStartOutProbe") +t_out_probe = config.get_float_value("tOutProbe") + +#%% +length = np.array([6,4,1])*boundary_layer_height +dx = boundary_layer_height/nodes_per_height +dt = dx * mach / (np.sqrt(3) * velocity) +velocity_LB = velocity * dt / dx # LB units +viscosity_LB = viscosity * dt / (dx * dx) # LB units +pressure_gradient = u_star * u_star / boundary_layer_height +pressure_gradient_LB = pressure_gradient * (dt*dt)/dx + +logger.vf_log_info(f"velocity [dx/dt] = {velocity_LB}") +logger.vf_log_info(f"dt = {dt}") +logger.vf_log_info(f"dx = {dx}") +logger.vf_log_info(f"viscosity [10^8 dx^2/dt] = {viscosity_LB*1e8}") +logger.vf_log_info(f"u* /(dx/dt) = {u_star*dt/dx}") +logger.vf_log_info(f"dpdx = {pressure_gradient}") +logger.vf_log_info(f"dpdx /(dx/dt^2) = {pressure_gradient_LB}") + +#%% #%% -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_forcing(pressure_gradient_LB, 0, 0) +para.set_velocity_LB(velocity_LB) +para.set_viscosity_LB(viscosity_LB) para.set_velocity_ratio(dx/dt) para.set_viscosity_ratio(dx*dx/dt) -para.set_use_AMD(use_AMD) +para.set_density_ratio(1.0) + +para.set_main_kernel("CumulantK17") -para.set_main_kernel("TurbulentViscosityCumulantK17CompChim" if para.get_use_AMD() else "CummulantK17CompChim") +para.set_timestep_start_out(int(t_start_out/dt)) +para.set_timestep_out(int(t_out/dt)) +para.set_timestep_end(int(t_end/dt)) +para.set_is_body_force(config.get_bool_value("bodyForce")) +#%% +tm_factory = gpu.TurbulenceModelFactory(para) +tm_factory.read_config_file(config) +#%% +grid_builder.add_coarse_grid(0.0, 0.0, 0.0, *length, dx) +grid_builder.set_periodic_boundary_condition(not read_precursor, True, False) +grid_builder.build_grids(basics.LbmOrGks.LBM, False) -para.set_SGS_constant(0.083) +sampling_offset = 2 +if read_precursor: + precursor = gpu.create_file_collection(precursor_directory + "/precursor", gpu.FileType.VTK) + grid_builder.set_precursor_boundary_condition(gpu.SideType.MX, precursor, nTReadPrecursor, 0, 0, 0) +grid_builder.set_stress_boundary_condition(gpu.SideType.MZ, 0, 0, 1, sampling_offset, z0/dx) +para.set_has_wall_model_monitor(True) +grid_builder.set_slip_boundary_condition(gpu.SideType.PZ, 0, 0, -1) + +if read_precursor: + grid_builder.set_pressure_boundary_condition(gpu.SideType.PX, 0) +bc_factory.set_stress_boundary_condition(gpu.StressBC.StressPressureBounceBack) +bc_factory.set_slip_boundary_condition(gpu.SlipBC.SlipBounceBack) +bc_factory.set_pressure_boundary_condition(gpu.PressureBC.OutflowNonReflective) +bc_factory.set_precursor_boundary_condition(gpu.PrecursorBC.DistributionsPrecursor if use_distributions else gpu.PrecursorBC.VelocityPrecursor) +para.set_outflow_pressure_correction_factor(0.0); +#%% def init_func(coord_x, coord_y, coord_z): return [ 0.0, - (u_star/kappa*np.log(max(coord_z/z_0,0)+1) + 2*np.sin(np.pi*16*coord_x/length[0])*np.sin(np.pi*8*coord_z/length[2]))/((coord_z/reference_height)**2+0.1)*dt/dx, - 2*np.sin(np.pi*16*coord_x/length[0])*np.sin(np.pi*8*coord_z/length[2])/((coord_z/reference_height)**2+0.1)*dt/dx, - 8*u_star/kappa*(np.sin(np.pi*8*coord_y/reference_height)*np.sin(np.pi*8*coord_z/reference_height)+np.sin(np.pi*8*coord_x/length[0]))/((length[2]/2-coord_z)**2+0.1)*dt/dx - ] - + (u_star/0.4 * np.log(np.maximum(coord_z,z0)/z0) + 2.0*np.sin(np.pi*16*coord_x/length[0])*np.sin(np.pi*8*coord_z/boundary_layer_height)/(np.square(coord_z/boundary_layer_height)+1)) * dt / dx, + 2.0*np.sin(np.pi*16.*coord_x/length[0])*np.sin(np.pi*8.*coord_z/boundary_layer_height)/(np.square(coord_z/boundary_layer_height)+1.) * dt / dx, + 8.0*u_star/0.4*(np.sin(np.pi*8.0*coord_y/boundary_layer_height)*np.sin(np.pi*8.0*coord_z/boundary_layer_height)+np.sin(np.pi*8.0*coord_x/length[0]))/(np.square(length[2]/2.0-coord_z)+1.) * dt / dx] para.set_initial_condition(init_func) -para.set_t_out(int(t_out/dt)) -para.set_t_end(int(t_end/dt)) -para.set_is_body_force(True) -para.set_has_wall_model_monitor(True) - -grid_builder.add_coarse_grid(0.0, 0.0, 0.0, *length, dx) -grid_builder.set_periodic_boundary_condition(True, True, False) -grid_builder.build_grids(basics.LbmOrGks.LBM, False) #%% -sampling_offset = 2 -grid_builder.set_stress_boundary_condition(gpu.SideType.MZ, 0.0, 0.0, 1.0, sampling_offset, z_0/dx) -grid_builder.set_slip_boundary_condition(gpu.SideType.PZ, 0.0, 0.0, 0.0) +planar_average_probe = gpu.probes.PlanarAverageProbe("horizontalPlanes", para.get_output_path(), 0, int(t_start_tmp_averaging/dt), int(t_averaging/dt) , int(t_start_out_probe/dt), int(t_out_probe/dt), 'z') +planar_average_probe.add_all_available_statistics() +planar_average_probe.set_file_name_to_n_out() +para.add_probe(planar_average_probe) +#%% +wall_model_probe = gpu.probes.WallModelProbe("wallModelProbe", para.get_output_path(), 0, int(t_start_tmp_averaging/dt), int(t_averaging/dt/4), int(t_start_out_probe/dt), int(t_out_probe/dt)) +wall_model_probe.add_all_available_statistics() +wall_model_probe.set_file_name_to_n_out() +wall_model_probe.set_force_output_to_stress(True) +if para.get_is_body_force(): + wall_model_probe.set_evaluate_pressure_gradient(True) +para.add_probe(wall_model_probe) + +plane_locs = [100,] +if read_precursor: plane_locs.extend([1000, 1500, 2000, 2500, 0]) + +for n_probe, probe_pos in enumerate(plane_locs): + plane_probe = gpu.probes.PlaneProbe(f"planeProbe_{n_probe+1}", para.get_output_path(), int(t_start_averaging/dt), 10, int(t_start_out_probe/dt), int(t_out_probe/dt)) + plane_probe.set_probe_plane(probe_pos, 0, 0, dx, length[1], length[2]) + plane_probe.add_all_available_statistics() + para.add_probe(plane_probe) + +if write_precursor: + precursor_writer = gpu.PrecursorWriter("precursor", para.get_output_path() + precursor_directory, pos_x_precursor, 0,length[1], 0, length[2], t_start_precursor/dt, nTWritePrecursor, gpu.OutputVariable.Distributions if use_distributions else gpu.OutputVariable.Velocities) + para.add_probe(precursor_writer) #%% cuda_memory_manager = gpu.CudaMemoryManager(para) -grid_generator = gpu.GridProvider.make_grid_generator(grid_builder, para, cuda_memory_manager, comm) - +grid_generator = gpu.GridProvider.make_grid_generator(grid_builder, para, cuda_memory_manager, communicator) #%% -wall_probe = gpu.probes.WallModelProbe("wallModelProbe", str(output_path), int(t_start_averaging/dt), int(t_start_tmp_averaging/dt), int(t_averaging/dt/4), int(t_start_out_probe/dt), int(t_out_probe/dt)) -wall_probe.add_all_available_statistics() -wall_probe.set_file_name_to_n_out() -wall_probe.set_force_output_to_stress(True) -if para.get_is_body_force(): - wall_probe.set_evaluate_pressure_gradient(True) -planar_probe = gpu.probes.PlanarAverageProbe("planarAverageProbe", str(output_path), int(t_start_averaging/dt), int(t_start_tmp_averaging/dt), int(t_averaging/dt), int(t_start_out_probe/dt), int(t_out_probe/dt), "z") -para.add_probe(wall_probe) - #%% -sim = gpu.Simulation(para, cuda_memory_manager, comm, grid_generator) +sim = gpu.Simulation(para, cuda_memory_manager, communicator, grid_generator, bc_factory, tm_factory) #%% sim.run() MPI.Finalize() \ No newline at end of file diff --git a/Python/boundary_layer/config.txt b/Python/boundary_layer/config.txt deleted file mode 100644 index e4c778c4cc048f54c0a32310e6bf4a7343a263fa..0000000000000000000000000000000000000000 --- a/Python/boundary_layer/config.txt +++ /dev/null @@ -1,2 +0,0 @@ -Path = . -GridPath = . diff --git a/Python/boundary_layer/configBoundaryLayer.txt b/Python/boundary_layer/configBoundaryLayer.txt new file mode 100644 index 0000000000000000000000000000000000000000..83e7861a5fb85ea800d187699f1c6c1409422f0a --- /dev/null +++ b/Python/boundary_layer/configBoundaryLayer.txt @@ -0,0 +1,42 @@ +################################################## +#informations for Writing +################################################## +Path = . +################################################## +#informations for reading +################################################## +GridPath = . +################################################## +Devices = 0 +################################################## +tStartOut = 0 +tOut = 100000 +tEnd = 300000 +################################################## +tStartAveraging = 0 +tStartTmpAveraging = 100000 +tAveraging = 200 +tStartOutProbe = 0 +tOutProbe = 1000 +################################################## +Ma = 0.1 +nz = 96 + +bodyForce = true +UseAMD = true +SGSconstant = 0.2 +QuadricLimiterP = 100000.0 +QuadricLimiterM = 100000.0 +QuadricLimiterD = 100000.0 + +################################################## +readPrecursor = false +nTimestepsReadPrecursor = 10 +precursorFile = precursor/Precursor + +################################################## +writePrecursor = false +nTimestepsWritePrecursor = 10 + +tStartPrecursor = 100 +posXPrecursor = 3000 \ No newline at end of file diff --git a/Python/cubeflow/simulation.py b/Python/cubeflow/simulation.py index 9e77e8d747c072188d8d81150afa8e2ccb76a792..deb0411963aec65522af45cc48d7367f103232c6 100644 --- a/Python/cubeflow/simulation.py +++ b/Python/cubeflow/simulation.py @@ -1,13 +1,42 @@ -from pyfluids.cpu import Simulation -from pyfluids.cpu.boundaryconditions import NoSlipBoundaryCondition, VelocityBoundaryCondition, DensityBoundaryCondition -from pyfluids.cpu.geometry import GbCuboid3D -from pyfluids.cpu.kernel import LBMKernel, KernelType -from pyfluids.cpu.parameters import PhysicalParameters, RuntimeParameters, GridParameters -from pyfluids.cpu.writer import Writer, OutputFormat -from pymuparser import Parser - +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file simulation.py +! \ingroup cubeflow +! \author Sven Marcus, Henry Korb +======================================================================================= +""" import os +from pyfluids import cpu +from pymuparser import Parser + def get_max_length(number_of_nodes_per_direction, delta_x): return (number_of_nodes_per_direction[0] * delta_x, @@ -15,10 +44,10 @@ def get_max_length(number_of_nodes_per_direction, delta_x): number_of_nodes_per_direction[2] * delta_x) -physical_params = PhysicalParameters() +physical_params = cpu.parameters.PhysicalParameters() physical_params.lattice_viscosity = 0.005 -grid_params = GridParameters() +grid_params = cpu.parameters.GridParameters() grid_params.number_of_nodes_per_direction = [200, 120, 120] grid_params.blocks_per_direction = [2, 2, 2] grid_params.node_distance = 0.125 @@ -26,7 +55,7 @@ grid_params.periodic_boundary_in_x1 = False grid_params.periodic_boundary_in_x2 = True grid_params.periodic_boundary_in_x3 = True -runtime_params = RuntimeParameters() +runtime_params = cpu.parameters.RuntimeParameters() runtime_params.timestep_log_interval = 1000 runtime_params.number_of_timesteps = 50000 runtime_params.number_of_threads = int(os.environ.get("OMP_NUM_THREADS", 4)) @@ -39,46 +68,46 @@ def run_simulation(physical_parameters=physical_params, grid_parameters=grid_par min_x, min_y, min_z = 0, 0, 0 max_x, max_y, max_z = get_max_length(grid_parameters.number_of_nodes_per_direction, grid_parameters.node_distance) - bottom_wall = GbCuboid3D(min_x - wall_thickness, min_y - wall_thickness, min_z, max_x + wall_thickness, + bottom_wall = cpu.geometry.GbCuboid3D(min_x - wall_thickness, min_y - wall_thickness, min_z, max_x + wall_thickness, max_y + wall_thickness, min_z - wall_thickness) - top_wall = GbCuboid3D(min_x - wall_thickness, min_y - wall_thickness, max_z, max_x + wall_thickness, + top_wall = cpu.geometry.GbCuboid3D(min_x - wall_thickness, min_y - wall_thickness, max_z, max_x + wall_thickness, max_y + wall_thickness, max_z + wall_thickness) - left_wall = GbCuboid3D(min_x - wall_thickness, min_y, min_z - wall_thickness, max_x + wall_thickness, + left_wall = cpu.geometry.GbCuboid3D(min_x - wall_thickness, min_y, min_z - wall_thickness, max_x + wall_thickness, min_y - wall_thickness, max_z + wall_thickness) - right_wall = GbCuboid3D(min_x - wall_thickness, max_y, min_z - wall_thickness, max_x + wall_thickness, + right_wall = cpu.geometry.GbCuboid3D(min_x - wall_thickness, max_y, min_z - wall_thickness, max_x + wall_thickness, max_y + wall_thickness, max_z + wall_thickness) - obstacle = GbCuboid3D(7, 7, 7, 8, 8, 8) + obstacle = cpu.geometry.GbCuboid3D(7, 7, 7, 8, 8, 8) - velocity_boundary = GbCuboid3D(min_x - wall_thickness, min_y - wall_thickness, min_z - wall_thickness, min_x, + velocity_boundary = cpu.geometry.GbCuboid3D(min_x - wall_thickness, min_y - wall_thickness, min_z - wall_thickness, min_x, max_y + wall_thickness, max_z + wall_thickness) - outflow_boundary = GbCuboid3D(max_x, min_y - wall_thickness, min_z - wall_thickness, max_x + wall_thickness, + outflow_boundary = cpu.geometry.GbCuboid3D(max_x, min_y - wall_thickness, min_z - wall_thickness, max_x + wall_thickness, max_y + wall_thickness, max_z + wall_thickness) - no_slip_bc = NoSlipBoundaryCondition() + no_slip_bc = cpu.boundaryconditions.NoSlipBoundaryCondition() - outflow_bc = DensityBoundaryCondition() + outflow_bc = cpu.boundaryconditions.DensityBoundaryCondition() velocity_function = Parser() velocity_function.define_constant("u", 0.07) velocity_function.expression = "u" - velocity_bc = VelocityBoundaryCondition(True, False, False, velocity_function, 0, -10) + velocity_bc = cpu.boundaryconditions.VelocityBoundaryCondition(True, False, False, velocity_function, 0, -10) - kernel = LBMKernel(KernelType.CompressibleCumulantFourthOrderViscosity) + kernel = cpu.kernel.LBMKernel(cpu.kernel.KernelType.CompressibleCumulantFourthOrderViscosity) # kernel.use_forcing = True # kernel.forcing_in_x1 = 3e-6 - writer = Writer() + writer = cpu.writer.Writer() writer.output_path = "./output" - writer.output_format = OutputFormat.BINARY + writer.output_format = cpu.writer.OutputFormat.BINARY - simulation = Simulation() + simulation = cpu.Simulation() simulation.set_writer(writer) simulation.set_physical_parameters(physical_parameters) diff --git a/Python/liddrivencavity/simulation.py b/Python/liddrivencavity/simulation.py index 155fad2f6f8aade0368c8a7006b88f7985f8822c..3c247b87a102e3c5a720f20748acc9f9f50bb178 100644 --- a/Python/liddrivencavity/simulation.py +++ b/Python/liddrivencavity/simulation.py @@ -1,32 +1,61 @@ -from pyfluids.cpu import Simulation -from pyfluids.cpu.boundaryconditions import NoSlipBoundaryCondition, VelocityBoundaryCondition -from pyfluids.cpu.geometry import GbCuboid3D -from pyfluids.cpu.kernel import LBMKernel, KernelType -from pyfluids.cpu.parameters import GridParameters, PhysicalParameters, RuntimeParameters -from pyfluids.cpu.writer import Writer, OutputFormat +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file simulation.py +! \ingroup liddrivencavity +! \author Sven Marcus, Henry Korb +======================================================================================= +""" +from pyfluids import cpu from pymuparser import Parser -runtime_params = RuntimeParameters() +runtime_params = cpu.parameters.RuntimeParameters() runtime_params.number_of_threads = 4 runtime_params.number_of_timesteps = 10000 runtime_params.timestep_log_interval = 1000 -physical_params = PhysicalParameters() +physical_params = cpu.parameters.PhysicalParameters() physical_params.lattice_viscosity = 0.005 -grid_params = GridParameters() +grid_params = cpu.parameters.GridParameters() grid_params.number_of_nodes_per_direction = [64, 64, 64] grid_params.blocks_per_direction = [2, 2, 2] grid_params.node_distance = 1 / 10 def run_simulation(physical_params=physical_params, grid_params=grid_params, runtime_params=runtime_params): - simulation = Simulation() - kernel = LBMKernel(KernelType.CompressibleCumulantFourthOrderViscosity) + simulation = cpu.Simulation() + kernel = cpu.kernel.LBMKernel(cpu.kernel.KernelType.CompressibleCumulantFourthOrderViscosity) - writer = Writer() + writer = cpu.writer.Writer() writer.output_path = "./output" - writer.output_format = OutputFormat.BINARY + writer.output_format = cpu.writer.OutputFormat.BINARY simulation.set_grid_parameters(grid_params) simulation.set_physical_parameters(physical_params) @@ -34,12 +63,12 @@ def run_simulation(physical_params=physical_params, grid_params=grid_params, run simulation.set_kernel_config(kernel) simulation.set_writer(writer) - no_slip_bc_adapter = NoSlipBoundaryCondition() + no_slip_bc_adapter = cpu.boundaryconditions.NoSlipBoundaryCondition() fct = Parser() fct.expression = "u" fct.define_constant("u", 0.005) - velocity_bc_adapter = VelocityBoundaryCondition(True, True, False, fct, 0, -10.0) + velocity_bc_adapter = cpu.boundaryconditions.VelocityBoundaryCondition(True, True, False, fct, 0, -10.0) g_min_x1, g_min_x2, g_min_x3 = 0, 0, 0 g_max_x1 = grid_params.number_of_nodes_per_direction[0] * grid_params.node_distance @@ -48,12 +77,12 @@ def run_simulation(physical_params=physical_params, grid_params=grid_params, run dx = grid_params.node_distance - wall_x_min = GbCuboid3D(g_min_x1 - dx, g_min_x2 - dx, g_min_x3 - dx, g_min_x1, g_max_x2 + dx, g_max_x3) - wall_x_max = GbCuboid3D(g_max_x1, g_min_x2 - dx, g_min_x3 - dx, g_max_x1 + dx, g_max_x2 + dx, g_max_x3) - wall_y_min = GbCuboid3D(g_min_x1 - dx, g_min_x2 - dx, g_min_x3 - dx, g_max_x1 + dx, g_min_x2, g_max_x3) - wall_y_max = GbCuboid3D(g_min_x1 - dx, g_max_x2, g_min_x3 - dx, g_max_x1 + dx, g_max_x2 + dx, g_max_x3) - wall_z_min = GbCuboid3D(g_min_x1 - dx, g_min_x2 - dx, g_min_x3 - dx, g_max_x1 + dx, g_max_x2 + dx, g_min_x3) - wall_z_max = GbCuboid3D(g_min_x1 - dx, g_min_x2 - dx, g_max_x3, g_max_x1 + dx, g_max_x2 + dx, g_max_x3 + dx) + wall_x_min = cpu.geometry.GbCuboid3D(g_min_x1 - dx, g_min_x2 - dx, g_min_x3 - dx, g_min_x1, g_max_x2 + dx, g_max_x3) + wall_x_max = cpu.geometry.GbCuboid3D(g_max_x1, g_min_x2 - dx, g_min_x3 - dx, g_max_x1 + dx, g_max_x2 + dx, g_max_x3) + wall_y_min = cpu.geometry.GbCuboid3D(g_min_x1 - dx, g_min_x2 - dx, g_min_x3 - dx, g_max_x1 + dx, g_min_x2, g_max_x3) + wall_y_max = cpu.geometry.GbCuboid3D(g_min_x1 - dx, g_max_x2, g_min_x3 - dx, g_max_x1 + dx, g_max_x2 + dx, g_max_x3) + wall_z_min = cpu.geometry.GbCuboid3D(g_min_x1 - dx, g_min_x2 - dx, g_min_x3 - dx, g_max_x1 + dx, g_max_x2 + dx, g_min_x3) + wall_z_max = cpu.geometry.GbCuboid3D(g_min_x1 - dx, g_min_x2 - dx, g_max_x3, g_max_x1 + dx, g_max_x2 + dx, g_max_x3 + dx) simulation.add_object(wall_x_min, no_slip_bc_adapter, 1, "/geo/wallXmin") simulation.add_object(wall_x_max, no_slip_bc_adapter, 1, "/geo/wallXmax") diff --git a/Python/poiseuille/poiseuille_hpc.py b/Python/poiseuille/poiseuille_hpc.py index f5f5a1387c9fe234abae0c6f979cc7d5b283d1a4..b108f34445a71a686c4e22f685e26e10204113b3 100644 --- a/Python/poiseuille/poiseuille_hpc.py +++ b/Python/poiseuille/poiseuille_hpc.py @@ -1,15 +1,49 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file poiseuille_hpc.py +! \ingroup poiseuille +! \author Sven Marcus, Henry Korb +======================================================================================= +""" from poiseuille.simulation import run_simulation -from pyfluids.cpu.parameters import * +from pyfluids import cpu -grid_parameters = GridParameters() +grid_parameters = cpu.prameters.GridParameters() grid_parameters.number_of_nodes_per_direction = [64, 64, 512] grid_parameters.node_distance = 1 grid_parameters.blocks_per_direction = [1, 2, 2] -physical_parameters = PhysicalParameters() +physical_parameters = cpu.prameters.PhysicalParameters() physical_parameters.lattice_viscosity = 0.0005 -runtime_parameters = RuntimeParameters() +runtime_parameters = cpu.prameters.RuntimeParameters() runtime_parameters.number_of_threads = 4 runtime_parameters.number_of_timesteps = 1000 runtime_parameters.timestep_log_interval = 100 diff --git a/Python/poiseuille/simulation.py b/Python/poiseuille/simulation.py index d107801fa84cfe16d1d7e91d31dc3ff4b8671f02..a6f12e59fbd0a0ccad9a4db9ccde69b828cf90bf 100644 --- a/Python/poiseuille/simulation.py +++ b/Python/poiseuille/simulation.py @@ -1,35 +1,65 @@ -from pyfluids.cpu import Simulation -from pyfluids.cpu.boundaryconditions import NoSlipBoundaryCondition -from pyfluids.cpu.geometry import GbCuboid3D, State -from pyfluids.cpu.kernel import LBMKernel, KernelType -from pyfluids.cpu.parameters import RuntimeParameters, GridParameters, PhysicalParameters -from pyfluids.cpu.writer import Writer, OutputFormat - -default_grid_params = GridParameters() +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file simulation.py +! \ingroup poiseuille +! \author Sven Marcus, Henry Korb +======================================================================================= +""" +from pyfluids import cpu + + +default_grid_params = cpu.parameters.GridParameters() default_grid_params.node_distance = 10 / 32 default_grid_params.number_of_nodes_per_direction = [8, 8, 32] default_grid_params.blocks_per_direction = [1, 1, 4] default_grid_params.periodic_boundary_in_x1 = True default_grid_params.periodic_boundary_in_x2 = True -default_physical_params = PhysicalParameters() +default_physical_params = cpu.parameters.PhysicalParameters() default_physical_params.lattice_viscosity = 0.005 -default_runtime_params = RuntimeParameters() +default_runtime_params = cpu.parameters.RuntimeParameters() default_runtime_params.number_of_threads = 4 default_runtime_params.number_of_timesteps = 10000 default_runtime_params.timestep_log_interval = 1000 -default_kernel = LBMKernel(KernelType.CompressibleCumulantFourthOrderViscosity) +default_kernel = cpu.kernel.LBMKernel(cpu.kernel.KernelType.CompressibleCumulantFourthOrderViscosity) default_kernel.use_forcing = True default_kernel.forcing_in_x1 = 1e-8 -default_writer = Writer() +default_writer = cpu.writer.Writer() default_writer.output_path = "./output" -default_writer.output_format = OutputFormat.BINARY +default_writer.output_format = cpu.writer.OutputFormat.BINARY -default_kernel = LBMKernel(KernelType.CompressibleCumulantFourthOrderViscosity) +default_kernel = cpu.kernel.LBMKernel(cpu.kernel.KernelType.CompressibleCumulantFourthOrderViscosity) default_kernel.use_forcing = True default_kernel.forcing_in_x1 = 1e-8 @@ -39,7 +69,7 @@ def run_simulation(physical_params=default_physical_params, runtime_params=default_runtime_params, kernel=default_kernel, writer=default_writer): - simulation = Simulation() + simulation = cpu.Simulation() simulation.set_kernel_config(kernel) simulation.set_physical_parameters(physical_params) @@ -47,11 +77,11 @@ def run_simulation(physical_params=default_physical_params, simulation.set_runtime_parameters(runtime_params) simulation.set_writer(writer) - no_slip_bc = NoSlipBoundaryCondition() + no_slip_bc = cpu.boundaryconditions.NoSlipBoundaryCondition() block_thickness = 3 * grid_params.node_distance simulation.add_object( - GbCuboid3D( + cpu.geometry.GbCuboid3D( grid_params.bounding_box.min_x1 - block_thickness, grid_params.bounding_box.min_x2 - block_thickness, grid_params.bounding_box.min_x3 - block_thickness, @@ -59,10 +89,10 @@ def run_simulation(physical_params=default_physical_params, grid_params.bounding_box.max_x2 + block_thickness, grid_params.bounding_box.min_x3), no_slip_bc, - State.SOLID, "/geo/addWallZMin") + cpu.geometry.State.SOLID, "/geo/addWallZMin") simulation.add_object( - GbCuboid3D( + cpu.geometry.GbCuboid3D( grid_params.bounding_box.min_x1 - block_thickness, grid_params.bounding_box.min_x2 - block_thickness, grid_params.bounding_box.max_x3, @@ -70,7 +100,7 @@ def run_simulation(physical_params=default_physical_params, grid_params.bounding_box.max_x2 + block_thickness, grid_params.bounding_box.max_x3 + block_thickness), no_slip_bc, - State.SOLID, "/geo/addWallZMax") + cpu.geometry.State.SOLID, "/geo/addWallZMax") simulation.run_simulation() diff --git a/Python/poiseuille/test_poiseuille_l2.py b/Python/poiseuille/test_poiseuille_l2.py index 93aa2600d5260dea7e72f3aa98db7334fe5285c6..818cba40e115945c60e4fa2ac96b3b6b5ab0bba8 100644 --- a/Python/poiseuille/test_poiseuille_l2.py +++ b/Python/poiseuille/test_poiseuille_l2.py @@ -1,3 +1,37 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file test_poiseuille_l2.py +! \ingroup poiseuille +! \author Sven Marcus, Henry Korb +======================================================================================= +""" import os import shutil import unittest @@ -5,8 +39,7 @@ import unittest import matplotlib.pyplot as plt import numpy as np import pyvista as pv -from pyfluids.cpu.kernel import LBMKernel, KernelType -from pyfluids.cpu.parameters import GridParameters, PhysicalParameters, RuntimeParameters +from pyfluids import cpu from scipy import stats from errors import normalized_l2_error @@ -33,13 +66,13 @@ class TestPoiseuilleFlow(unittest.TestCase): self.skipTest("This test is not implemented correctly yet") plt.ion() - physical_params = PhysicalParameters() + physical_params = cpu.parameters.PhysicalParameters() - runtime_params = RuntimeParameters() + runtime_params = cpu.parameters.RuntimeParameters() runtime_params.number_of_threads = os.cpu_count() runtime_params.timestep_log_interval = 10000 - kernel = LBMKernel(KernelType.CompressibleCumulantFourthOrderViscosity) + kernel = cpu.kernel.LBMKernel(cpu.kernel.KernelType.CompressibleCumulantFourthOrderViscosity) kernel.use_forcing = True normalized_l2_errors = [] @@ -140,7 +173,7 @@ def get_heights_from_indices(mesh, indices): def create_grid_params_with_nodes_in_column(nodes_in_column, delta_x): - grid_params = GridParameters() + grid_params = cpu.parameters.GridParameters() grid_params.node_distance = delta_x grid_params.number_of_nodes_per_direction = [1, 1, nodes_in_column] grid_params.blocks_per_direction = [1, 1, 8] diff --git a/Python/tests/test_acousticscaling.py b/Python/tests/test_acousticscaling.py index 6413123a80db8c5882fcf1dbe6f72a1f5438736c..02454b935e3a147e045f45c273392646aeca6b8c 100644 --- a/Python/tests/test_acousticscaling.py +++ b/Python/tests/test_acousticscaling.py @@ -1,9 +1,41 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file test_acousticscaling.py +! \ingroup tests +! \author Sven Marcus, Henry Korb +======================================================================================= +""" import unittest from typing import List -from pyfluids.cpu.kernel import LBMKernel, KernelType -from pyfluids.cpu.parameters import GridParameters, PhysicalParameters, RuntimeParameters - +from pyfluids import cpu from acousticscaling import OneDirectionalAcousticScaling @@ -58,18 +90,18 @@ class OneDirectionalAcousticScalingTest(unittest.TestCase): self.assertEqual(self.grid_params.periodic_boundary_in_x2, actual_grid_params.periodic_boundary_in_x2) self.assertEqual(self.grid_params.periodic_boundary_in_x3, actual_grid_params.periodic_boundary_in_x3) - def assert_physical_params_scaled_by_factor(self, actual_params: PhysicalParameters, factor: int): + def assert_physical_params_scaled_by_factor(self, actual_params: cpu.parameters.PhysicalParameters, factor: int): self.assertEqual(self.physical_params.lattice_viscosity * factor, actual_params.lattice_viscosity) self.assertEqual(self.physical_params.bulk_viscosity_factor, actual_params.bulk_viscosity_factor) - def assert_runtime_params_scaled_by_factor(self, actual_params: RuntimeParameters, factor: int): + def assert_runtime_params_scaled_by_factor(self, actual_params: cpu.parameters.RuntimeParameters, factor: int): self.assertEqual(self.runtime_params.number_of_timesteps * factor, actual_params.number_of_timesteps) self.assertEqual(self.runtime_params.number_of_threads, actual_params.number_of_threads) self.assertEqual(self.runtime_params.timestep_log_interval, actual_params.timestep_log_interval) - def assert_kernel_forcing_scaled_by_factor(self, actual_kernel: LBMKernel, factor: int): + def assert_kernel_forcing_scaled_by_factor(self, actual_kernel: cpu.kernel.LBMKernel, factor: int): self.assertEqual(self.kernel.type, actual_kernel.type) - self.assertEqual(self.kernel.use_forcing, actual_kernel.use_forcing) + self.assertEqual(self.kernel.use_forcing, actual_kernel.cpu.parameters.use_forcing) self.assertAlmostEqual(self.kernel.forcing_in_x1 / factor, actual_kernel.forcing_in_x1) self.assertAlmostEqual(self.kernel.forcing_in_x2, actual_kernel.forcing_in_x2) self.assertAlmostEqual(self.kernel.forcing_in_x3, actual_kernel.forcing_in_x3) @@ -80,14 +112,14 @@ class OneDirectionalAcousticScalingTest(unittest.TestCase): @staticmethod def make_kernel(): - kernel = LBMKernel(KernelType.CompressibleCumulantFourthOrderViscosity) + kernel = cpu.kernel.LBMKernel(cpu.kernel.KernelType.CompressibleCumulantFourthOrderViscosity) kernel.use_forcing = True kernel.forcing_in_x1 = 5e-10 return kernel @staticmethod def make_runtime_params(): - runtime_params = RuntimeParameters() + runtime_params = cpu.parameters.RuntimeParameters() runtime_params.number_of_threads = 4 runtime_params.number_of_timesteps = 4_000_000 runtime_params.timestep_log_interval = 1_000_000 @@ -95,13 +127,13 @@ class OneDirectionalAcousticScalingTest(unittest.TestCase): @staticmethod def make_physical_params(): - physical_params = PhysicalParameters() + physical_params = cpu.parameters.PhysicalParameters() physical_params.lattice_viscosity = 1e-4 return physical_params @staticmethod def make_grid_params(): - grid_params = GridParameters() + grid_params = cpu.parameters.GridParameters() grid_params.node_distance = 1 grid_params.number_of_nodes_per_direction = [1, 1, 16] grid_params.blocks_per_direction = [1, 1, 16] diff --git a/Python/tests/test_boundaryconditions.py b/Python/tests/test_boundaryconditions.py index e004ddfa21c78ea3d63a89f5dbc3bd7438a18ff1..d914c50cad2051188331b2efe604907091fa731e 100644 --- a/Python/tests/test_boundaryconditions.py +++ b/Python/tests/test_boundaryconditions.py @@ -1,5 +1,39 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file test_boundaryconditions.py +! \ingroup tests +! \author Sven Marcus, Henry Korb +======================================================================================= +""" import unittest -from pyfluids.cpu.boundaryconditions import * +from pyfluids import cpu class BoundaryConditionsTest(unittest.TestCase): @@ -8,13 +42,13 @@ class BoundaryConditionsTest(unittest.TestCase): """ Should be able to create NoSlipBoundaryCondition """ - sut = NoSlipBoundaryCondition() + sut = cpu.boundaryconditions.NoSlipBoundaryCondition() def test__can_create_velocity_bc(self): """ Should be able to create VelocityBoundaryCondition """ - sut = VelocityBoundaryCondition() + sut = cpu.boundaryconditions.VelocityBoundaryCondition() def test__can_create_velocity_bc_with_directions_function_and_time(self): """ @@ -24,7 +58,7 @@ class BoundaryConditionsTest(unittest.TestCase): parser = Parser() parser.expression = "1" - sut = VelocityBoundaryCondition(True, True, True, parser, 0, 1) + sut = cpu.boundaryconditions.VelocityBoundaryCondition(True, True, True, parser, 0, 1) def test__can_create_velocity_bc_with_directions__function_per_direction__and__time(self): """ @@ -40,7 +74,7 @@ class BoundaryConditionsTest(unittest.TestCase): f3 = Parser() f3.expression = "1" - sut = VelocityBoundaryCondition(True, True, True, f1, f2, f3, 0, 1) + sut = cpu.boundaryconditions.VelocityBoundaryCondition(True, True, True, f1, f2, f3, 0, 1) def test__can_create_velocity_bc_with_speeds_and_times_per_direction(self): """ @@ -51,11 +85,11 @@ class BoundaryConditionsTest(unittest.TestCase): start2, end2 = 1, 2 start3, end3 = 2, 3 - sut = VelocityBoundaryCondition(vx1, start1, end1, vx2, start2, end2, vx3, start3, end3) + sut = cpu.boundaryconditions.VelocityBoundaryCondition(vx1, start1, end1, vx2, start2, end2, vx3, start3, end3) def test__can_create_non_reflecting_outflow(self): """ Should be able to create NonReflectingOutflow """ - sut = NonReflectingOutflow() + sut = cpu.boundaryconditions.NonReflectingOutflow() diff --git a/Python/tests/test_geometry.py b/Python/tests/test_geometry.py index 5bb89eb245b6055653b78fde381da050d402b0cc..3d297f5c176cd99f7969adf37333588d86b77627 100644 --- a/Python/tests/test_geometry.py +++ b/Python/tests/test_geometry.py @@ -1,6 +1,40 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file test_geometry.py +! \ingroup tests +! \author Sven Marcus, Henry Korb +======================================================================================= +""" import unittest -from pyfluids.cpu.geometry import * +from pyfluids import cpu class TestGeometry(unittest.TestCase): @@ -9,7 +43,7 @@ class TestGeometry(unittest.TestCase): """ WHEN setting point coordinates in constructor THEN point should have coordinates """ - sut = GbPoint3D(4, 8, 3) + sut = cpu.geometry.GbPoint3D(4, 8, 3) self.assertEqual(sut.x1, 4) self.assertEqual(sut.x2, 8) @@ -19,7 +53,7 @@ class TestGeometry(unittest.TestCase): """ WHEN setting point coordinates THEN point should have coordinates """ - sut = GbPoint3D() + sut = cpu.geometry.GbPoint3D() sut.x1 = 4 sut.x2 = 8 @@ -33,10 +67,10 @@ class TestGeometry(unittest.TestCase): """ WHEN setting line points THEN line should have points """ - sut = GbLine3D() + sut = cpu.geometry.GbLine3D() - point1 = GbPoint3D() - point2 = GbPoint3D() + point1 = cpu.geometry.GbPoint3D() + point2 = cpu.geometry.GbPoint3D() sut.point1 = point1 sut.point2 = point2 diff --git a/Python/tests/test_kernel.py b/Python/tests/test_kernel.py index 8f58a1c869f9e292856268d43245a75f1dcfe213..e0159bec6802cb08d73214038b177091879fee46 100644 --- a/Python/tests/test_kernel.py +++ b/Python/tests/test_kernel.py @@ -1,12 +1,46 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file test_kernel.py +! \ingroup tests +! \author Sven Marcus, Henry Korb +======================================================================================= +""" import unittest -from pyfluids.cpu.kernel import LBMKernel, KernelType +from pyfluids import cpu class TestLBMKernel(unittest.TestCase): def setUp(self) -> None: - self.sut = LBMKernel(KernelType.BGK) + self.sut = cpu.kernel.LBMKernel(cpu.kernel.KernelType.BGK) def test_lbm_kernel__when_use_forcing_set_to_true__use_forcing_should_be_true(self) -> None: """ @@ -57,4 +91,4 @@ class TestLBMKernel(unittest.TestCase): """ actual = self.sut.type - self.assertEqual(KernelType.BGK, actual) + self.assertEqual(cpu.kernel.KernelType.BGK, actual) diff --git a/apps/gpu/LBM/ActuatorLine/ActuatorLine.cpp b/apps/gpu/LBM/ActuatorLine/ActuatorLine.cpp index 58e5aede18b9c4197b4d21b129c6347023b9390e..9d982ebac0059b4512041194100f6e1fdfa61924 100644 --- a/apps/gpu/LBM/ActuatorLine/ActuatorLine.cpp +++ b/apps/gpu/LBM/ActuatorLine/ActuatorLine.cpp @@ -1,4 +1,35 @@ - +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file ActuatorLine.cpp +//! \ingroup ActuatorLine +//! \author Henry Korb, Henrik Asmuth +//======================================================================================= #define _USE_MATH_DEFINES #include <math.h> #include <string> @@ -28,12 +59,14 @@ #include "GridGenerator/grid/GridBuilder/LevelGridBuilder.h" #include "GridGenerator/grid/GridBuilder/MultipleGridBuilder.h" #include "GridGenerator/grid/BoundaryConditions/Side.h" +#include "GridGenerator/grid/BoundaryConditions/BoundaryCondition.h" + #include "GridGenerator/grid/GridFactory.h" #include "GridGenerator/io/SimulationFileWriter/SimulationFileWriter.h" #include "GridGenerator/io/GridVTKWriter/GridVTKWriter.h" -#include "GridGenerator/io/STLReaderWriter/STLReader.h" -#include "GridGenerator/io/STLReaderWriter/STLWriter.h" +#include "GridGenerator/TransientBCSetter/TransientBCSetter.h" + ////////////////////////////////////////////////////////////////////////// @@ -44,10 +77,12 @@ #include "VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.h" #include "VirtualFluids_GPU/Parameter/Parameter.h" #include "VirtualFluids_GPU/Output/FileWriter.h" -#include "VirtualFluids_GPU/PreCollisionInteractor/ActuatorLine.h" +#include "VirtualFluids_GPU/PreCollisionInteractor/ActuatorFarm.h" #include "VirtualFluids_GPU/PreCollisionInteractor/Probes/PointProbe.h" #include "VirtualFluids_GPU/PreCollisionInteractor/Probes/PlaneProbe.h" #include "VirtualFluids_GPU/Factories/BoundaryConditionFactory.h" +#include "VirtualFluids_GPU/TurbulenceModels/TurbulenceModelFactory.h" +#include "VirtualFluids_GPU/Factories/GridScalingFactory.h" #include "VirtualFluids_GPU/GPU/CudaMemoryManager.h" @@ -63,26 +98,10 @@ LbmOrGks lbmOrGks = LBM; -const real reference_diameter = 126.0; // diameter in m - -const real L_x = 10*reference_diameter; -const real L_y = 6*reference_diameter; -const real L_z = 6*reference_diameter; - -const real viscosity = 1.56e-5; - -const real velocity = 9.0; - -const real mach = 0.1; - -const uint nodes_per_diameter = 16; - std::string path("."); std::string simulationName("ActuatorLine"); -const float tOut = 100; -const float tEnd = 280; // total time of simulation in s //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -98,30 +117,59 @@ void multipleLevel(const std::string& configPath) vf::gpu::Communicator& communicator = vf::gpu::Communicator::getInstance(); auto gridFactory = GridFactory::make(); - gridFactory->setTriangularMeshDiscretizationMethod(TriangularMeshDiscretizationMethod::POINT_IN_OBJECT); auto gridBuilder = MultipleGridBuilder::makeShared(gridFactory); - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + vf::basics::ConfigurationFile config; + config.load(configPath); + + const real reference_diameter = config.getValue<real>("ReferenceDiameter"); + const uint nodes_per_diameter = config.getValue<uint>("NodesPerDiameter"); + const real velocity = config.getValue<real>("Velocity"); + + + const real L_x = 24*reference_diameter; + const real L_y = 6*reference_diameter; + const real L_z = 6*reference_diameter; + + const real viscosity = 1.56e-5; + + const real mach = 0.1; + + + const float tStartOut = config.getValue<real>("tStartOut"); + const float tOut = config.getValue<real>("tOut"); + const float tEnd = config.getValue<real>("tEnd"); // total time of simulation + + const float tStartAveraging = config.getValue<real>("tStartAveraging"); + const float tStartTmpAveraging = config.getValue<real>("tStartTmpAveraging"); + const float tAveraging = config.getValue<real>("tAveraging"); + const float tStartOutProbe = config.getValue<real>("tStartOutProbe"); + const float tOutProbe = config.getValue<real>("tOutProbe"); + + SPtr<Parameter> para = std::make_shared<Parameter>(communicator.getNummberOfProcess(), communicator.getPID(), &config); + BoundaryConditionFactory bcFactory = BoundaryConditionFactory(); + GridScalingFactory scalingFactory = GridScalingFactory(); + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// const real dx = reference_diameter/real(nodes_per_diameter); + real turbPos[3] = {3*reference_diameter, 3*reference_diameter, 3*reference_diameter}; + gridBuilder->addCoarseGrid(0.0, 0.0, 0.0, L_x, L_y, L_z, dx); + gridBuilder->setNumberOfLayers(4,0); + gridBuilder->addGrid( new Cuboid( turbPos[0]-1.5*reference_diameter, turbPos[1]-1.5*reference_diameter, turbPos[2]-1.5*reference_diameter, + turbPos[0]+10.0*reference_diameter, turbPos[1]+1.5*reference_diameter, turbPos[2]+1.5*reference_diameter) , 1 ); + para->setMaxLevel(2); + scalingFactory.setScalingFactory(GridScalingFactory::GridScaling::ScaleCompressible); + gridBuilder->setPeriodicBoundaryCondition(false, false, false); gridBuilder->buildGrids(lbmOrGks, false); // buildGrids() has to be called before setting the BCs!!!! - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - vf::basics::ConfigurationFile config; - config.load(configPath); - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////^ - SPtr<Parameter> para = std::make_shared<Parameter>(communicator.getNummberOfProcess(), communicator.getPID(), &config); - BoundaryConditionFactory bcFactory = BoundaryConditionFactory(); - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// const real dt = dx * mach / (sqrt(3) * velocity); @@ -140,14 +188,11 @@ void multipleLevel(const std::string& configPath) para->setPrintFiles(true); - para->setMaxLevel(1); - - para->setVelocityLB(velocityLB); para->setViscosityLB(viscosityLB); para->setVelocityRatio( dx / dt ); para->setViscosityRatio( dx*dx/dt ); - para->setMainKernel("CumulantK17CompChim"); + para->setMainKernel("CumulantK17"); para->setInitialCondition([&](real coordX, real coordY, real coordZ, real &rho, real &vx, real &vy, real &vz) { rho = (real)0.0; @@ -156,13 +201,15 @@ void multipleLevel(const std::string& configPath) vz = (real)0.0; }); + para->setTimestepStartOut( uint(tStartOut/dt) ); para->setTimestepOut( uint(tOut/dt) ); para->setTimestepEnd( uint(tEnd/dt) ); para->setIsBodyForce( true ); - + para->setUseStreams( true ); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + gridBuilder->setVelocityBoundaryCondition(SideType::MX, velocityLB, 0.0, 0.0); gridBuilder->setVelocityBoundaryCondition(SideType::MY, velocityLB, 0.0, 0.0); @@ -172,42 +219,52 @@ void multipleLevel(const std::string& configPath) gridBuilder->setPressureBoundaryCondition(SideType::PX, 0.0); bcFactory.setVelocityBoundaryCondition(BoundaryConditionFactory::VelocityBC::VelocityAndPressureCompressible); - bcFactory.setPressureBoundaryCondition(BoundaryConditionFactory::PressureBC::PressureNonEquilibriumCompressible); + bcFactory.setPressureBoundaryCondition(BoundaryConditionFactory::PressureBC::OutflowNonReflective); + + SPtr<TurbulenceModelFactory> tmFactory = std::make_shared<TurbulenceModelFactory>(para); + tmFactory->readConfigFile(config); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - real turbPos[3] = {3*reference_diameter, 3*reference_diameter, 3*reference_diameter}; - real epsilon = 5.f; // width of gaussian smearing - real density = 1.225f; - int level = 0; - uint nBlades = 3; - uint nBladeNodes = 32; + int level = 1; // grid level at which the turbine samples velocities and distributes forces + const real epsilon = dx*exp2(-level)*1.5; // width of gaussian smearing + const real density = 1.225f; + const uint nBlades = 3; + const uint nBladeNodes = 32; + const real tipspeed_ratio = 7.5f; // tipspeed ratio = angular vel * radius / inflow vel + const real omega = 2*tipspeed_ratio*velocity/reference_diameter; + + + SPtr<ActuatorFarm> actuator_farm = std::make_shared<ActuatorFarm>(nBlades, density, nBladeNodes, epsilon, level, dt, dx, true); + std::vector<real> bladeRadii; + real dr = reference_diameter/(nBladeNodes*2); + for(uint node=0; node<nBladeNodes; node++){ bladeRadii.emplace_back(dr*(node+1)); } + actuator_farm->addTurbine(turbPos[0], turbPos[1], turbPos[2], reference_diameter, omega, 0, 0, bladeRadii); + para->addActuator( actuator_farm ); - 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 ); - SPtr<PointProbe> pointProbe = SPtr<PointProbe>( new PointProbe("pointProbe", para->getOutputPath(), 100, 1, 500, 100) ); - std::vector<real> probeCoordsX = {reference_diameter,2*reference_diameter,5*reference_diameter}; - std::vector<real> probeCoordsY = {3*reference_diameter,3*reference_diameter,3*reference_diameter}; - std::vector<real> probeCoordsZ = {3*reference_diameter,3*reference_diameter,3*reference_diameter}; - pointProbe->addProbePointsFromList(probeCoordsX, probeCoordsY, probeCoordsZ); - // pointProbe->addProbePointsFromXNormalPlane(2*D, 0.0, 0.0, L_y, L_z, (uint)L_y/dx, (uint)L_z/dx); + // SPtr<PointProbe> pointProbe = std::make_shared<PointProbe>("pointProbe", para->getOutputPath(), 100, 1, 500, 100); + // std::vector<real> probeCoordsX = {reference_diameter,2*reference_diameter,5*reference_diameter}; + // std::vector<real> probeCoordsY = {3*reference_diameter,3*reference_diameter,3*reference_diameter}; + // std::vector<real> probeCoordsZ = {3*reference_diameter,3*reference_diameter,3*reference_diameter}; + // pointProbe->addProbePointsFromList(probeCoordsX, probeCoordsY, probeCoordsZ); + // // pointProbe->addProbePointsFromXNormalPlane(2*D, 0.0, 0.0, L_y, L_z, (uint)L_y/dx, (uint)L_z/dx); - pointProbe->addStatistic(Statistic::Means); - pointProbe->addStatistic(Statistic::Variances); - para->addProbe( pointProbe ); + // pointProbe->addStatistic(Statistic::Means); + // pointProbe->addStatistic(Statistic::Variances); + // para->addProbe( pointProbe ); - SPtr<PlaneProbe> planeProbe = SPtr<PlaneProbe>( new PlaneProbe("planeProbe", para->getOutputPath(), 100, 500, 100, 100) ); - planeProbe->setProbePlane(5*reference_diameter, 0, 0, dx, L_y, L_z); - planeProbe->addStatistic(Statistic::Means); - para->addProbe( planeProbe ); + // SPtr<PlaneProbe> planeProbe = std::make_shared<PlaneProbe>("planeProbe", para->getOutputPath(), 100, 500, 100, 100); + // planeProbe->setProbePlane(5*reference_diameter, 0, 0, dx, L_y, L_z); + // planeProbe->addStatistic(Statistic::Means); + // para->addProbe( planeProbe ); auto cudaMemoryManager = std::make_shared<CudaMemoryManager>(para); auto gridGenerator = GridProvider::makeGridGenerator(gridBuilder, para, cudaMemoryManager, communicator); - Simulation sim(para, cudaMemoryManager, communicator, *gridGenerator, &bcFactory); + Simulation sim(para, cudaMemoryManager, communicator, *gridGenerator, &bcFactory, tmFactory, &scalingFactory); sim.run(); } diff --git a/apps/gpu/LBM/ActuatorLine/configActuatorLine.txt b/apps/gpu/LBM/ActuatorLine/configActuatorLine.txt index 233994f0d32a48190d84f7044500e24b06b926a9..5799f24716777295b2f835ab00561ff767ba87b9 100644 --- a/apps/gpu/LBM/ActuatorLine/configActuatorLine.txt +++ b/apps/gpu/LBM/ActuatorLine/configActuatorLine.txt @@ -6,3 +6,29 @@ Path = . #informations for reading ################################################## GridPath=. +################################################## +ReferenceDiameter=126 +NodesPerDiameter=32 +Velocity=9 +################################################## +tStartOut=100 +tOut=100 +tEnd=1000 +################################################## + +tStartTmpAveraging=100 +tStartAveraging=100 +tAveraging=100 +tTmpAveraging=100 +tStartOutProbe=100 +tOutProbe=100 + +################################################## +#TurbulenceModel = QR +#SGSconstant = 0.3333333 +# +#QuadricLimiterP = 100000.0 +#QuadricLimiterM = 100000.0 +#QuadricLimiterD = 100000.0 +################################################## + diff --git a/apps/gpu/LBM/BoundaryLayer/BoundaryLayer.cpp b/apps/gpu/LBM/BoundaryLayer/BoundaryLayer.cpp index 991025b649d69305c030fe2f1dd1763a2137af9b..5fc31904433bfe2df0722ab1c63f574d3fcb9a35 100644 --- a/apps/gpu/LBM/BoundaryLayer/BoundaryLayer.cpp +++ b/apps/gpu/LBM/BoundaryLayer/BoundaryLayer.cpp @@ -1,4 +1,35 @@ - +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file BoundaryLayer.cpp +//! \ingroup BoundaryLayer +//! \author Henry Korb, Henrik Asmuth +//======================================================================================= #define _USE_MATH_DEFINES #include <math.h> #include <string> @@ -8,6 +39,7 @@ #include <fstream> #include <exception> #include <memory> +#include <numeric> ////////////////////////////////////////////////////////////////////////// @@ -19,6 +51,7 @@ #include "Core/VectorTypes.h" #include <basics/config/ConfigurationFile.h> +#include "lbm/constants/NumericConstants.h" #include <logger/Logger.h> @@ -28,12 +61,16 @@ #include "GridGenerator/grid/GridBuilder/LevelGridBuilder.h" #include "GridGenerator/grid/GridBuilder/MultipleGridBuilder.h" #include "GridGenerator/grid/BoundaryConditions/Side.h" +#include "GridGenerator/grid/BoundaryConditions/BoundaryCondition.h" + #include "GridGenerator/grid/GridFactory.h" +#include "geometries/Cuboid/Cuboid.h" +#include "geometries/TriangularMesh/TriangularMesh.h" + #include "GridGenerator/io/SimulationFileWriter/SimulationFileWriter.h" #include "GridGenerator/io/GridVTKWriter/GridVTKWriter.h" -#include "GridGenerator/io/STLReaderWriter/STLReader.h" -#include "GridGenerator/io/STLReaderWriter/STLWriter.h" +#include "GridGenerator/TransientBCSetter/TransientBCSetter.h" ////////////////////////////////////////////////////////////////////////// @@ -44,24 +81,28 @@ #include "VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.h" #include "VirtualFluids_GPU/Parameter/Parameter.h" #include "VirtualFluids_GPU/Output/FileWriter.h" -#include "VirtualFluids_GPU/PreCollisionInteractor/ActuatorLine.h" #include "VirtualFluids_GPU/PreCollisionInteractor/Probes/PointProbe.h" #include "VirtualFluids_GPU/PreCollisionInteractor/Probes/PlaneProbe.h" #include "VirtualFluids_GPU/PreCollisionInteractor/Probes/PlanarAverageProbe.h" #include "VirtualFluids_GPU/PreCollisionInteractor/Probes/WallModelProbe.h" +#include "VirtualFluids_GPU/PreCollisionInteractor/PrecursorWriter.h" #include "VirtualFluids_GPU/Factories/BoundaryConditionFactory.h" +#include "VirtualFluids_GPU/Factories/GridScalingFactory.h" #include "VirtualFluids_GPU/TurbulenceModels/TurbulenceModelFactory.h" #include "VirtualFluids_GPU/GPU/CudaMemoryManager.h" +#include "utilities/communication.h" + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// std::string path("."); -std::string simulationName("BoundayLayer"); +std::string simulationName("BoundaryLayer"); +using namespace vf::lbm::constant; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -87,8 +128,16 @@ void multipleLevel(const std::string& configPath) ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////^ SPtr<Parameter> para = std::make_shared<Parameter>(communicator.getNummberOfProcess(), communicator.getPID(), &config); BoundaryConditionFactory bcFactory = BoundaryConditionFactory(); - + GridScalingFactory scalingFactory = GridScalingFactory(); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + const int nProcs = communicator.getNummberOfProcess(); + const uint procID = vf::gpu::Communicator::getInstance().getPID(); + std::vector<uint> devices(10); + std::iota(devices.begin(), devices.end(), 0); + para->setDevices(devices); + para->setMaxDev(nProcs); + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // @@ -100,23 +149,45 @@ void multipleLevel(const std::string& configPath) LbmOrGks lbmOrGks = LBM; - const real H = 1000.0; // boundary layer height in m + const real H = config.getValue("boundaryLayerHeight", 1000.0); // boundary layer height in m const real L_x = 6*H; const real L_y = 4*H; - const real L_z = 1*H; + const real L_z = H; + + const real z0 = config.getValue("z0", 0.1f); // roughness length in m + const real u_star = config.getValue("u_star", 0.4f); //friction velocity in m/s + const real kappa = config.getValue("vonKarmanConstant", 0.4f); // von Karman constant - const real z0 = 0.1; // roughness length in m - const real u_star = 0.4; //friction velocity in m/s - const real kappa = 0.4; // von Karman constant + const real viscosity = config.getValue("viscosity", 1.56e-5f); - const real viscosity = 1.56e-5; + const real velocity = 0.5f*u_star/kappa*log(H/z0+1.f); //0.5 times max mean velocity at the top in m/s - const real velocity = 0.5*u_star/kappa*log(L_z/z0); //0.5 times max mean velocity at the top in m/s + const real mach = config.getValue<real>("Ma", 0.1); - const real mach = config.contains("Ma")? config.getValue<real>("Ma"): 0.1; + const uint nodes_per_H = config.getValue<uint>("nz", 64); - const uint nodes_per_H = config.contains("nz")? config.getValue<uint>("nz"): 64; + const bool writePrecursor = config.getValue("writePrecursor", false); + bool useDistributions; + std::string precursorDirectory; + int nTWritePrecursor; real tStartPrecursor, posXPrecursor; + if(writePrecursor) + { + nTWritePrecursor = config.getValue<int>("nTimestepsWritePrecursor"); + tStartPrecursor = config.getValue<real>("tStartPrecursor"); + posXPrecursor = config.getValue<real>("posXPrecursor"); + useDistributions = config.getValue<bool>("useDistributions", false); + precursorDirectory = config.getValue<std::string>("precursorDirectory"); + } + + const bool readPrecursor = config.getValue("readPrecursor", false); + int timestepsBetweenReadsPrecursor; + if(readPrecursor) + { + timestepsBetweenReadsPrecursor = config.getValue<int>("nTimestepsReadPrecursor"); + precursorDirectory = config.getValue<std::string>("precursorDirectory"); + useDistributions = config.getValue<bool>("useDistributions", false); + } // all in s const float tStartOut = config.getValue<real>("tStartOut"); @@ -130,7 +201,7 @@ void multipleLevel(const std::string& configPath) const float tOutProbe = config.getValue<real>("tOutProbe"); - const real dx = L_z/real(nodes_per_H); + const real dx = H/real(nodes_per_H); const real dt = dx * mach / (sqrt(3) * velocity); @@ -155,15 +226,17 @@ void multipleLevel(const std::string& configPath) para->setPrintFiles(true); - para->setForcing(pressureGradientLB, 0, 0); + if(!readPrecursor) para->setForcing(pressureGradientLB, 0, 0); para->setVelocityLB(velocityLB); para->setViscosityLB(viscosityLB); para->setVelocityRatio( dx / dt ); para->setViscosityRatio( dx*dx/dt ); para->setDensityRatio( 1.0 ); - para->setMainKernel("TurbulentViscosityCumulantK17CompChim"); - + bool useStreams = (nProcs > 1 ? true: false); + // useStreams=false; + para->setUseStreams(useStreams); + para->setMainKernel("CumulantK17"); para->setIsBodyForce( config.getValue<bool>("bodyForce") ); para->setTimestepStartOut(uint(tStartOut/dt) ); @@ -172,64 +245,206 @@ void multipleLevel(const std::string& configPath) //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - SPtr<TurbulenceModelFactory> tmFactory = SPtr<TurbulenceModelFactory>( new TurbulenceModelFactory(para) ); + SPtr<TurbulenceModelFactory> tmFactory = std::make_shared<TurbulenceModelFactory>(para); tmFactory->readConfigFile( config ); + ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + const real xSplit = L_x/nProcs; + const real overlap = 8.0*dx; + + real xMin = procID * xSplit; + real xMax = (procID+1) * xSplit; + real xGridMin = procID * xSplit; + real xGridMax = (procID+1) * xSplit; + + real yMin = 0.0; + real yMax = L_y; + real zMin = 0.0; + real zMax = L_z; + + bool isFirstSubDomain = (procID == 0 && nProcs > 1)? true: false; + bool isLastSubDomain = (procID == nProcs-1 && nProcs > 1)? true: false; + bool isMidSubDomain = (!isFirstSubDomain && !isLastSubDomain && nProcs > 1)? true: false; - // tmFactory->setTurbulenceModel(TurbulenceModel::AMD); - // tmFactory->setModelConstant(config.getValue<real>("SGSconstant")); + if(isFirstSubDomain) + { + xGridMax += overlap; + if(!readPrecursor) xGridMin -= overlap; + } + if(isLastSubDomain) + { + xGridMin -= overlap; + if(!readPrecursor) xGridMax += overlap; + } + if(isMidSubDomain) + { + xGridMax += overlap; + xGridMin -= overlap; + } - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + gridBuilder->addCoarseGrid( xGridMin, 0.0, 0.0, + xGridMax, L_y, L_z, dx); + if(true)// Add refinement + { + gridBuilder->setNumberOfLayers(4,0); + real xMaxRefinement = readPrecursor? xGridMax-H: xGridMax; //Stop refinement some distance before outlet if domain ist not periodic + gridBuilder->addGrid( new Cuboid( xGridMin, 0.f, 0.f, xMaxRefinement, L_y, 0.5*L_z) , 1 ); + para->setMaxLevel(2); + scalingFactory.setScalingFactory(GridScalingFactory::GridScaling::ScaleCompressible); + } + + if(nProcs > 1) + { + gridBuilder->setSubDomainBox( + std::make_shared<BoundingBox>(xMin, xMax, yMin, yMax, zMin, zMax)); + gridBuilder->setPeriodicBoundaryCondition(false, true, false); + } + else + { + gridBuilder->setPeriodicBoundaryCondition(!readPrecursor, true, false); + } - gridBuilder->addCoarseGrid(0.0, 0.0, 0.0, - L_x, L_y, L_z, dx); - // gridBuilder->setNumberOfLayers(12, 8); + gridBuilder->buildGrids(lbmOrGks, true); // buildGrids() has to be called before setting the BCs!!!! - // gridBuilder->addGrid( new Cuboid( 0.0, 0.0, 0.0, L_x, L_y, 0.3*L_z) , 1 ); - // para->setMaxLevel(2); + std::cout << "nProcs: "<< nProcs << "Proc: " << procID << " isFirstSubDomain: " << isFirstSubDomain << " isLastSubDomain: " << isLastSubDomain << " isMidSubDomain: " << isMidSubDomain << std::endl; + + if(nProcs > 1){ + if (isFirstSubDomain || isMidSubDomain) { + gridBuilder->findCommunicationIndices(CommunicationDirections::PX, lbmOrGks); + gridBuilder->setCommunicationProcess(CommunicationDirections::PX, procID+1); + } - gridBuilder->setPeriodicBoundaryCondition(true, true, false); + if (isLastSubDomain || isMidSubDomain) { + gridBuilder->findCommunicationIndices(CommunicationDirections::MX, lbmOrGks); + gridBuilder->setCommunicationProcess(CommunicationDirections::MX, procID-1); + } - gridBuilder->buildGrids(lbmOrGks, false); // buildGrids() has to be called before setting the BCs!!!! + if (isFirstSubDomain && !readPrecursor) { + gridBuilder->findCommunicationIndices(CommunicationDirections::MX, lbmOrGks); + gridBuilder->setCommunicationProcess(CommunicationDirections::MX, nProcs-1); + } + if (isLastSubDomain && !readPrecursor) { + gridBuilder->findCommunicationIndices(CommunicationDirections::PX, lbmOrGks); + gridBuilder->setCommunicationProcess(CommunicationDirections::PX, 0); + } + } uint samplingOffset = 2; - // gridBuilder->setVelocityBoundaryCondition(SideType::MZ, 0.0, 0.0, 0.0); + + std::cout << " precursorDirectory " << precursorDirectory << std::endl; + + if(readPrecursor) + { + if(isFirstSubDomain || nProcs == 1) + { + auto precursor = createFileCollection(precursorDirectory + "/precursor", FileType::VTK); + gridBuilder->setPrecursorBoundaryCondition(SideType::MX, precursor, timestepsBetweenReadsPrecursor); + // gridBuilder->setVelocityBoundaryCondition(SideType::MX, velocityLB, 0.0, 0.0); + } + + if(isLastSubDomain || nProcs == 1) + { + gridBuilder->setPressureBoundaryCondition(SideType::PX, 0.f); + } + } + gridBuilder->setStressBoundaryCondition(SideType::MZ, 0.0, 0.0, 1.0, // wall normals - samplingOffset, z0/dx); // wall model settinng - para->setHasWallModelMonitor(true); - bcFactory.setStressBoundaryCondition(BoundaryConditionFactory::StressBC::StressPressureBounceBack); + samplingOffset, z0, dx); // wall model settinng + para->setHasWallModelMonitor(true); + gridBuilder->setSlipBoundaryCondition(SideType::PZ, 0.0f, 0.0f, -1.0f); - gridBuilder->setSlipBoundaryCondition(SideType::PZ, 0.0, 0.0, 0.0); + bcFactory.setVelocityBoundaryCondition(BoundaryConditionFactory::VelocityBC::VelocityCompressible); + bcFactory.setStressBoundaryCondition(BoundaryConditionFactory::StressBC::StressPressureBounceBack); bcFactory.setSlipBoundaryCondition(BoundaryConditionFactory::SlipBC::SlipBounceBack); - + bcFactory.setPressureBoundaryCondition(BoundaryConditionFactory::PressureBC::OutflowNonReflective); + bcFactory.setPrecursorBoundaryCondition(useDistributions ? BoundaryConditionFactory::PrecursorBC::DistributionsPrecursor : BoundaryConditionFactory::PrecursorBC::VelocityPrecursor); + para->setOutflowPressureCorrectionFactor(0.0); - real cPi = 3.1415926535897932384626433832795; - para->setInitialCondition([&](real coordX, real coordY, real coordZ, real &rho, real &vx, real &vy, real &vz) { + if(readPrecursor) + { + para->setInitialCondition([&](real coordX, real coordY, real coordZ, real &rho, real &vx, real &vy, real &vz) { rho = (real)0.0; - vx = (u_star/0.4 * log(coordZ/z0) + 2.0*sin(cPi*16.0f*coordX/L_x)*sin(cPi*8.0f*coordZ/H)/(pow(coordZ/H,c2o1)+c1o1)) * dt / dx; - vy = 2.0*sin(cPi*16.0f*coordX/L_x)*sin(cPi*8.0f*coordZ/H)/(pow(coordZ/H,c2o1)+c1o1) * dt / dx; - vz = 8.0*u_star/0.4*(sin(cPi*8.0*coordY/H)*sin(cPi*8.0*coordZ/H)+sin(cPi*8.0*coordX/L_x))/(pow(L_z/2.0-coordZ, c2o1)+c1o1) * dt / dx; - }); - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + vx = rho = c0o1; + vx = u_star/c4o10*(u_star/c4o10 * log(coordZ/z0+c1o1)) * dt/dx; + vy = c0o1; + vz = c0o1; + }); + } + else + { + para->setInitialCondition([&](real coordX, real coordY, real coordZ, real &rho, real &vx, real &vy, real &vz) { + rho = (real)0.0; + vx = rho = c0o1; + vx = (u_star/c4o10 * log(coordZ/z0+c1o1) + c2o1*sin(cPi*c16o1*coordX/L_x)*sin(cPi*c8o1*coordZ/H)/(pow(coordZ/H,c2o1)+c1o1)) * dt/dx; + vy = c2o1*sin(cPi*c16o1*coordX/L_x)*sin(cPi*c8o1*coordZ/H)/(pow(coordZ/H,c2o1)+c1o1) * dt/dx; + vz = c8o1*u_star/c4o10*(sin(cPi*c8o1*coordY/H)*sin(cPi*c8o1*coordZ/H)+sin(cPi*c8o1*coordX/L_x))/(pow(c1o2*L_z-coordZ, c2o1)+c1o1) * dt/dx; + }); + } + + - SPtr<PlanarAverageProbe> planarAverageProbe = SPtr<PlanarAverageProbe>( new PlanarAverageProbe("planeProbe", para->getOutputPath(), tStartAveraging/dt, tStartTmpAveraging/dt, tAveraging/dt , tStartOutProbe/dt, tOutProbe/dt, 'z') ); - planarAverageProbe->addAllAvailableStatistics(); - planarAverageProbe->setFileNameToNOut(); - para->addProbe( planarAverageProbe ); + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + if(!readPrecursor && (isFirstSubDomain || nProcs == 1)) + { + SPtr<PlanarAverageProbe> planarAverageProbe = SPtr<PlanarAverageProbe>( new PlanarAverageProbe("planeProbe", para->getOutputPath(), tStartAveraging/dt, tStartTmpAveraging/dt, tAveraging/dt , tStartOutProbe/dt, tOutProbe/dt, 'z') ); + planarAverageProbe->addAllAvailableStatistics(); + planarAverageProbe->setFileNameToNOut(); + para->addProbe( planarAverageProbe ); + + para->setHasWallModelMonitor(true); + SPtr<WallModelProbe> wallModelProbe = SPtr<WallModelProbe>( new WallModelProbe("wallModelProbe", para->getOutputPath(), tStartAveraging/dt, tStartTmpAveraging/dt, tAveraging/dt/4.0 , tStartOutProbe/dt, tOutProbe/dt) ); + wallModelProbe->addAllAvailableStatistics(); + wallModelProbe->setFileNameToNOut(); + wallModelProbe->setForceOutputToStress(true); + if(para->getIsBodyForce()) + wallModelProbe->setEvaluatePressureGradient(true); + para->addProbe( wallModelProbe ); + } + + SPtr<PlaneProbe> planeProbe1 = SPtr<PlaneProbe>( new PlaneProbe("planeProbe_1", para->getOutputPath(), tStartAveraging/dt, 10, tStartOutProbe/dt, tOutProbe/dt) ); + planeProbe1->setProbePlane(100.0, 0.0, 0, dx, L_y, L_z); + planeProbe1->addAllAvailableStatistics(); + para->addProbe( planeProbe1 ); + + if(readPrecursor) + { + SPtr<PlaneProbe> planeProbe2 = SPtr<PlaneProbe>( new PlaneProbe("planeProbe_2", para->getOutputPath(), tStartAveraging/dt, 10, tStartOutProbe/dt, tOutProbe/dt) ); + planeProbe2->setProbePlane(1000.0, 0.0, 0, dx, L_y, L_z); + planeProbe2->addAllAvailableStatistics(); + para->addProbe( planeProbe2 ); + + SPtr<PlaneProbe> planeProbe3 = SPtr<PlaneProbe>( new PlaneProbe("planeProbe_3", para->getOutputPath(), tStartAveraging/dt, 10, tStartOutProbe/dt, tOutProbe/dt) ); + planeProbe3->setProbePlane(1500.0, 0.0, 0, dx, L_y, L_z); + planeProbe3->addAllAvailableStatistics(); + para->addProbe( planeProbe3 ); + + SPtr<PlaneProbe> planeProbe4 = SPtr<PlaneProbe>( new PlaneProbe("planeProbe_4", para->getOutputPath(), tStartAveraging/dt, 10, tStartOutProbe/dt, tOutProbe/dt) ); + planeProbe4->setProbePlane(2000.0, 0.0, 0, dx, L_y, L_z); + planeProbe4->addAllAvailableStatistics(); + para->addProbe( planeProbe4 ); + + SPtr<PlaneProbe> planeProbe5 = SPtr<PlaneProbe>( new PlaneProbe("planeProbe_5", para->getOutputPath(), tStartAveraging/dt, 10, tStartOutProbe/dt, tOutProbe/dt) ); + planeProbe5->setProbePlane(2500.0, 0.0, 0, dx, L_y, L_z); + planeProbe5->addAllAvailableStatistics(); + para->addProbe( planeProbe5 ); + + SPtr<PlaneProbe> planeProbe6 = SPtr<PlaneProbe>( new PlaneProbe("planeProbe_6", para->getOutputPath(), tStartAveraging/dt, 10, tStartOutProbe/dt, tOutProbe/dt) ); + planeProbe6->setProbePlane(0.0, L_y/2.0, 0, L_x, dx, L_z); + planeProbe6->addAllAvailableStatistics(); + para->addProbe( planeProbe6 ); + } - para->setHasWallModelMonitor(true); - SPtr<WallModelProbe> wallModelProbe = SPtr<WallModelProbe>( new WallModelProbe("wallModelProbe", para->getOutputPath(), tStartAveraging/dt, tStartTmpAveraging/dt, tAveraging/dt/4.0 , tStartOutProbe/dt, tOutProbe/dt) ); - wallModelProbe->addAllAvailableStatistics(); - wallModelProbe->setFileNameToNOut(); - wallModelProbe->setForceOutputToStress(true); - if(para->getIsBodyForce()) - wallModelProbe->setEvaluatePressureGradient(true); - para->addProbe( wallModelProbe ); + if(writePrecursor) + { + SPtr<PrecursorWriter> precursorWriter = std::make_shared<PrecursorWriter>("precursor", para->getOutputPath()+precursorDirectory, posXPrecursor, 0, L_y, 0, L_z, tStartPrecursor/dt, nTWritePrecursor, useDistributions? OutputVariable::Distributions: OutputVariable::Velocities, 1000); + para->addProbe(precursorWriter); + } auto cudaMemoryManager = std::make_shared<CudaMemoryManager>(para); auto gridGenerator = GridProvider::makeGridGenerator(gridBuilder, para, cudaMemoryManager, communicator); - Simulation sim(para, cudaMemoryManager, communicator, *gridGenerator, &bcFactory, tmFactory); + Simulation sim(para, cudaMemoryManager, communicator, *gridGenerator, &bcFactory, tmFactory, &scalingFactory); sim.run(); } diff --git a/apps/gpu/LBM/BoundaryLayer/configBoundaryLayer.txt b/apps/gpu/LBM/BoundaryLayer/configBoundaryLayer.txt index a489f0ab89738a193b16fee41c212a5943f6525d..83e7861a5fb85ea800d187699f1c6c1409422f0a 100644 --- a/apps/gpu/LBM/BoundaryLayer/configBoundaryLayer.txt +++ b/apps/gpu/LBM/BoundaryLayer/configBoundaryLayer.txt @@ -7,7 +7,7 @@ Path = . ################################################## GridPath = . ################################################## -Devices = 1 +Devices = 0 ################################################## tStartOut = 0 tOut = 100000 @@ -28,3 +28,15 @@ SGSconstant = 0.2 QuadricLimiterP = 100000.0 QuadricLimiterM = 100000.0 QuadricLimiterD = 100000.0 + +################################################## +readPrecursor = false +nTimestepsReadPrecursor = 10 +precursorFile = precursor/Precursor + +################################################## +writePrecursor = false +nTimestepsWritePrecursor = 10 + +tStartPrecursor = 100 +posXPrecursor = 3000 \ No newline at end of file diff --git a/apps/gpu/LBM/TGV_3D_MultiGPU/TGV_3D_MultiGPU.cpp b/apps/gpu/LBM/TGV_3D_MultiGPU/TGV_3D_MultiGPU.cpp index 8c303dc07c911c363e892ce53f7bfe7f48e284d6..045c208274bc6bc216d25e8c2fa905916a52f87b 100644 --- a/apps/gpu/LBM/TGV_3D_MultiGPU/TGV_3D_MultiGPU.cpp +++ b/apps/gpu/LBM/TGV_3D_MultiGPU/TGV_3D_MultiGPU.cpp @@ -1,7 +1,38 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file TGV_3d_MuitiGPU.cpp +//! \ingroup TGV_3D_MultiGPU +//! \author Martin Schoenherr +//======================================================================================= //#define MPI_LOGGING //Martin Branch - #include <mpi.h> #if defined( MPI_LOGGING ) #include <mpe.h> @@ -97,7 +128,7 @@ bool useWale = false; int mpirank; int mpiWorldSize; -std::string kernel( "CumulantK20Comp" ); +std::string kernel( "CumulantK17CompChim" ); //std::string path("F:/Work/Computations/out/TaylorGreen3DNew/"); //LEGOLAS //std::string path("results/"); //PHOENIX diff --git a/pyproject.toml b/pyproject.toml index 8fcb7926102d188b44d8c74084235b6f175edf80..257da6fd95d683081dbff865c864079eae9c675d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,9 @@ [build-system] -requires = ["setuptools", "wheel", "scikit-build"] \ No newline at end of file +requires = [ + "setuptools>=42", + "scikit-build", + "cmake", + "ninja; platform_system!='Windows'" +] +build-backend = "setup_builder" +backend-path = ["utilities"] \ No newline at end of file diff --git a/pythonbindings/CMakeLists.txt b/pythonbindings/CMakeLists.txt index 5a84adef027fdfa2953e016693bb64570e48c1ef..644b308c97760d6a8243ae7782f0737a1d168100 100644 --- a/pythonbindings/CMakeLists.txt +++ b/pythonbindings/CMakeLists.txt @@ -1,24 +1,35 @@ project(VirtualFluidsPython LANGUAGES CUDA CXX) +pybind11_add_module(python_bindings MODULE src/VirtualFluids.cpp) + +set_target_properties( python_bindings PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/pythonbindings/pyfluids + OUTPUT_NAME "bindings") + IF(BUILD_VF_GPU) - pybind11_add_module(pyfluids src/VirtualFluidsModulesGPU.cpp) - set_source_files_properties(src/VirtualFluidsModulesGPU.cpp PROPERTIES LANGUAGE CUDA) + set_source_files_properties(src/VirtualFluids.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/) + target_include_directories(python_bindings PRIVATE ${VF_THIRD_DIR}/cuda_samples/) + target_compile_definitions(python_bindings PRIVATE VF_GPU_PYTHONBINDINGS) + target_link_libraries(python_bindings PRIVATE GridGenerator VirtualFluids_GPU basics lbmCuda logger) ENDIF() + IF(BUILD_VF_CPU) - pybind11_add_module(pyfluids src/VirtualFluidsModulesCPU.cpp) - pybind11_add_module(pymuparser src/muParser.cpp) + target_compile_definitions(python_bindings PRIVATE VF_METIS VF_MPI VF_CPU_PYTHONBINDINGS) + target_link_libraries(python_bindings PRIVATE simulationconfig VirtualFluidsCore muparser basics) + + # include bindings for muparsers + pybind11_add_module(pymuparser MODULE 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) + set_target_properties( pymuparser PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/pythonbindings/pymuparser + OUTPUT_NAME "bindings") 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 + +target_include_directories(python_bindings PRIVATE ${CMAKE_SOURCE_DIR}/src/) +target_include_directories(python_bindings PRIVATE ${CMAKE_BINARY_DIR}) \ No newline at end of file diff --git a/Python/boundary_layer/__init__.py b/pythonbindings/pyfluids-stubs/__init__.pyi similarity index 100% rename from Python/boundary_layer/__init__.py rename to pythonbindings/pyfluids-stubs/__init__.pyi diff --git a/pythonbindings/pyfluids-stubs/bindings/__init__.pyi b/pythonbindings/pyfluids-stubs/bindings/__init__.pyi new file mode 100644 index 0000000000000000000000000000000000000000..4e7f353eab97cc536f8f18e72319af1cd7a1916a --- /dev/null +++ b/pythonbindings/pyfluids-stubs/bindings/__init__.pyi @@ -0,0 +1,38 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file __init__.pyi +! \ingroup bindings +! \author Henry Korb +======================================================================================= +""" +class ostream_redirect: + def __init__(self, stdout: bool = ..., stderr: bool = ...) -> None: ... + def __enter__(self) -> None: ... + def __exit__(self, *args) -> None: ... diff --git a/pythonbindings/pyfluids-stubs/bindings/basics/__init__.pyi b/pythonbindings/pyfluids-stubs/bindings/basics/__init__.pyi new file mode 100644 index 0000000000000000000000000000000000000000..a41b7934ca706dc0db5bd6188fee3150456e0cd9 --- /dev/null +++ b/pythonbindings/pyfluids-stubs/bindings/basics/__init__.pyi @@ -0,0 +1,82 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file __init__.py +! \ingroup basics +! \author Henry Korb +======================================================================================= +""" +from typing import ClassVar + +from typing import overload + +class ConfigurationFile: + def __init__(self) -> None: ... + def contains(self, key: str) -> bool: ... + @overload + def get_bool_value(self, key: str) -> bool: ... + @overload + def get_bool_value(self, key: str, default_value: bool) -> bool: ... + @overload + def get_double_value(self, key: str) -> float: ... + @overload + def get_double_value(self, key: str, default_value: float) -> float: ... + @overload + def get_float_value(self, key: str) -> float: ... + @overload + def get_float_value(self, key: str, default_value: float) -> float: ... + @overload + def get_int_value(self, key: str) -> int: ... + @overload + def get_int_value(self, key: str, default_value: int) -> int: ... + @overload + def get_string_value(self, key: str) -> str: ... + @overload + def get_string_value(self, key: str, default_value: str) -> str: ... + @overload + def get_uint_value(self, key: str) -> int: ... + @overload + def get_uint_value(self, key: str, default_value: int) -> int: ... + def load(self, file: str) -> bool: ... + +class LbmOrGks: + __members__: ClassVar[dict] = ... # read-only + GKS: ClassVar[LbmOrGks] = ... + LBM: ClassVar[LbmOrGks] = ... + __entries: ClassVar[dict] = ... + def __init__(self, arg0: int) -> None: ... + def __eq__(self, arg0: object) -> bool: ... + def __getstate__(self) -> int: ... + def __hash__(self) -> int: ... + def __index__(self) -> int: ... + def __int__(self) -> int: ... + def __ne__(self, arg0: object) -> bool: ... + def __setstate__(self, arg0: int) -> None: ... + @property + def name(self) -> str: ... diff --git a/pythonbindings/pyfluids-stubs/bindings/basics/logger.pyi b/pythonbindings/pyfluids-stubs/bindings/basics/logger.pyi new file mode 100644 index 0000000000000000000000000000000000000000..43938ff7646efd3c596ae29971cce39fed865fa6 --- /dev/null +++ b/pythonbindings/pyfluids-stubs/bindings/basics/logger.pyi @@ -0,0 +1,83 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file logger.pyi +! \ingroup basics +! \author Henry Korb +======================================================================================= +""" +from typing import Any, ClassVar + +log: None + +class Level: + __members__: ClassVar[dict] = ... # read-only + INFO_HIGH: ClassVar[Level] = ... + INFO_INTERMEDIATE: ClassVar[Level] = ... + INFO_LOW: ClassVar[Level] = ... + LOGGER_ERROR: ClassVar[Level] = ... + WARNING: ClassVar[Level] = ... + __entries: ClassVar[dict] = ... + def __init__(self, arg0: int) -> None: ... + def __eq__(self, arg0: object) -> bool: ... + def __getstate__(self) -> int: ... + def __hash__(self) -> int: ... + def __index__(self) -> int: ... + def __int__(self) -> int: ... + def __ne__(self, arg0: object) -> bool: ... + def __setstate__(self, arg0: int) -> None: ... + @property + def name(self) -> str: ... + +class Logger: + def __init__(self, *args, **kwargs) -> None: ... + @staticmethod + def add_stdout() -> None: ... + @staticmethod + def enable_printed_rank_numbers(print: bool) -> None: ... + @staticmethod + def set_debug_level(level: int) -> None: ... + @staticmethod + def time_stamp(time_stemp: TimeStamp) -> None: ... + +class TimeStamp: + __members__: ClassVar[dict] = ... # read-only + DISABLE: ClassVar[TimeStamp] = ... + ENABLE: ClassVar[TimeStamp] = ... + __entries: ClassVar[dict] = ... + def __init__(self, arg0: int) -> None: ... + def __eq__(self, arg0: object) -> bool: ... + def __getstate__(self) -> int: ... + def __hash__(self) -> int: ... + def __index__(self) -> int: ... + def __int__(self) -> int: ... + def __ne__(self, arg0: object) -> bool: ... + def __setstate__(self, arg0: int) -> None: ... + @property + def name(self) -> str: ... diff --git a/pythonbindings/pyfluids-stubs/bindings/gpu/__init__.pyi b/pythonbindings/pyfluids-stubs/bindings/gpu/__init__.pyi new file mode 100644 index 0000000000000000000000000000000000000000..36c2fea76713e980bb95eb6726d778de8c9a6583 --- /dev/null +++ b/pythonbindings/pyfluids-stubs/bindings/gpu/__init__.pyi @@ -0,0 +1,436 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file __init__.pyi +! \ingroup gpu +! \author Henry Korb +======================================================================================= +""" +from typing import Any, Callable, ClassVar, List, Optional + +from typing import overload +import numpy +import pyfluids.bindings.basics +import pyfluids.bindings.gpu.grid_generator as grid_generator + +class ActuatorFarm(PreCollisionInteractor): + def __init__(self, number_of_blades_per_turbine: int, density: float, number_of_nodes_per_blade: int, epsilon: float, level: int, delta_t: float, delta_x: float, use_host_arrays: bool) -> None: ... + def add_turbine(self, posX: float, posY: float, posZ: float, diameter: float, omega: float, azimuth: float, yaw: float, bladeRadii: List[float]) -> None: ... + def calc_blade_forces(self) -> None: ... + def get_all_azimuths(self) -> numpy.ndarray[numpy.float32]: ... + def get_all_blade_coords_x(self) -> numpy.ndarray[numpy.float32]: ... + def get_all_blade_coords_x_device(self) -> int: ... + def get_all_blade_coords_y(self) -> numpy.ndarray[numpy.float32]: ... + def get_all_blade_coords_y_device(self) -> int: ... + def get_all_blade_coords_z(self) -> numpy.ndarray[numpy.float32]: ... + def get_all_blade_coords_z_device(self) -> int: ... + def get_all_blade_forces_x(self) -> numpy.ndarray[numpy.float32]: ... + def get_all_blade_forces_x_device(self) -> int: ... + def get_all_blade_forces_y(self) -> numpy.ndarray[numpy.float32]: ... + def get_all_blade_forces_y_device(self) -> int: ... + def get_all_blade_forces_z(self) -> numpy.ndarray[numpy.float32]: ... + def get_all_blade_forces_z_device(self) -> int: ... + def get_all_blade_radii(self) -> numpy.ndarray[numpy.float32]: ... + def get_all_blade_radii_device(self) -> int: ... + def get_all_blade_velocities_x(self) -> numpy.ndarray[numpy.float32]: ... + def get_all_blade_velocities_x_device(self) -> int: ... + def get_all_blade_velocities_y(self) -> numpy.ndarray[numpy.float32]: ... + def get_all_blade_velocities_y_device(self) -> int: ... + def get_all_blade_velocities_z(self) -> numpy.ndarray[numpy.float32]: ... + def get_all_blade_velocities_z_device(self) -> int: ... + def get_all_omegas(self) -> numpy.ndarray[numpy.float32]: ... + def get_all_turbine_pos_x(self) -> numpy.ndarray[numpy.float32]: ... + def get_all_turbine_pos_y(self) -> numpy.ndarray[numpy.float32]: ... + def get_all_turbine_pos_z(self) -> numpy.ndarray[numpy.float32]: ... + def get_all_yaws(self) -> numpy.ndarray[numpy.float32]: ... + def get_turbine_azimuth(self, turbine: int) -> float: ... + def get_turbine_blade_coords_x(self, turbine: int) -> numpy.ndarray[numpy.float32]: ... + def get_turbine_blade_coords_x_device(self, turbine: int) -> int: ... + def get_turbine_blade_coords_y(self, turbine: int) -> numpy.ndarray[numpy.float32]: ... + def get_turbine_blade_coords_y_device(self, turbine: int) -> int: ... + def get_turbine_blade_coords_z(self, turbine: int) -> numpy.ndarray[numpy.float32]: ... + def get_turbine_blade_coords_z_device(self, turbine: int) -> int: ... + def get_turbine_blade_forces_x(self, turbine: int) -> numpy.ndarray[numpy.float32]: ... + def get_turbine_blade_forces_x_device(self, turbine: int) -> int: ... + def get_turbine_blade_forces_y(self, turbine: int) -> numpy.ndarray[numpy.float32]: ... + def get_turbine_blade_forces_y_device(self, turbine: int) -> int: ... + def get_turbine_blade_forces_z(self, turbine: int) -> numpy.ndarray[numpy.float32]: ... + def get_turbine_blade_forces_z_device(self, turbine: int) -> int: ... + def get_turbine_blade_radii(self, turbine: int) -> numpy.ndarray[numpy.float32]: ... + def get_turbine_blade_radii_device(self, turbine: int) -> int: ... + def get_turbine_blade_velocities_x(self, turbine: int) -> numpy.ndarray[numpy.float32]: ... + def get_turbine_blade_velocities_x_device(self, turbine: int) -> int: ... + def get_turbine_blade_velocities_y(self, turbine: int) -> numpy.ndarray[numpy.float32]: ... + def get_turbine_blade_velocities_y_device(self, turbine: int) -> int: ... + def get_turbine_blade_velocities_z(self, turbine: int) -> numpy.ndarray[numpy.float32]: ... + def get_turbine_blade_velocities_z_device(self, turbine: int) -> int: ... + def get_turbine_omega(self, turbine: int) -> float: ... + def get_turbine_pos(self, turbine: int) -> numpy.ndarray[numpy.float32]: ... + def get_turbine_yaw(self, turbine: int) -> float: ... + def set_all_azimuths(self, azimuths: numpy.ndarray[numpy.float32]) -> None: ... + def set_all_blade_coords(self, blade_coords_x: numpy.ndarray[numpy.float32], blade_coords_y: numpy.ndarray[numpy.float32], blade_coords_z: numpy.ndarray[numpy.float32]) -> None: ... + def set_all_blade_forces(self, blade_forces_x: numpy.ndarray[numpy.float32], blade_forces_y: numpy.ndarray[numpy.float32], blade_forces_z: numpy.ndarray[numpy.float32]) -> None: ... + def set_all_blade_velocities(self, blade_velocities_x: numpy.ndarray[numpy.float32], blade_velocities_y: numpy.ndarray[numpy.float32], blade_velocities_z: numpy.ndarray[numpy.float32]) -> None: ... + def set_all_omegas(self, omegas: numpy.ndarray[numpy.float32]) -> None: ... + def set_all_yaws(self, yaws: numpy.ndarray[numpy.float32]) -> None: ... + def set_turbine_azimuth(self, turbine: int, azimuth: float) -> None: ... + def set_turbine_blade_coords(self, turbine: int, blade_coords_x: numpy.ndarray[numpy.float32], blade_coords_y: numpy.ndarray[numpy.float32], blade_coords_z: numpy.ndarray[numpy.float32]) -> None: ... + def set_turbine_blade_forces(self, turbine: int, blade_forces_x: numpy.ndarray[numpy.float32], blade_forces_y: numpy.ndarray[numpy.float32], blade_forces_z: numpy.ndarray[numpy.float32]) -> None: ... + def set_turbine_blade_velocities(self, turbine: int, blade_velocities_x: numpy.ndarray[numpy.float32], blade_velocities_y: numpy.ndarray[numpy.float32], blade_velocities_z: numpy.ndarray[numpy.float32]) -> None: ... + def set_turbine_omega(self, turbine: int, omega: float) -> None: ... + def set_turbine_yaw(self, turbine: int, yaw: float) -> None: ... + @property + def delta_t(self) -> float: ... + @property + def delta_x(self) -> float: ... + @property + def density(self) -> float: ... + @property + def number_of_blades_per_turbine(self) -> int: ... + @property + def number_of_indices(self) -> int: ... + @property + def number_of_nodes(self) -> int: ... + @property + def number_of_nodes_per_blade(self) -> int: ... + @property + def number_of_turbines(self) -> int: ... + +class BoundaryConditionFactory: + def __init__(self) -> None: ... + def set_geometry_boundary_condition(self, boundary_condition_type) -> None: ... + def set_no_slip_boundary_condition(self, boundary_condition_type) -> None: ... + def set_precursor_boundary_condition(self, boundary_condition_type) -> None: ... + def set_pressure_boundary_condition(self, boundary_condition_type) -> None: ... + def set_slip_boundary_condition(self, boundary_condition_type) -> None: ... + def set_stress_boundary_condition(self, boundary_condition_type) -> None: ... + def set_velocity_boundary_condition(self, boundary_condition_type) -> None: ... + +class Communicator: + def __init__(self, *args, **kwargs) -> None: ... + @staticmethod + def get_instance() -> Communicator: ... + def get_number_of_process(self) -> int: ... + def get_pid(self) -> int: ... + +class CudaMemoryManager: + def __init__(self, parameter: Parameter) -> None: ... + +class FileType: + __members__: ClassVar[dict] = ... # read-only + VTK: ClassVar[FileType] = ... + __entries: ClassVar[dict] = ... + def __init__(self, arg0: int) -> None: ... + def __eq__(self, arg0: object) -> bool: ... + def __getstate__(self) -> int: ... + def __hash__(self) -> int: ... + def __index__(self) -> int: ... + def __int__(self) -> int: ... + def __ne__(self, arg0: object) -> bool: ... + def __setstate__(self, arg0: int) -> None: ... + @property + def name(self) -> str: ... + +class GridProvider: + def __init__(self, *args, **kwargs) -> None: ... + @staticmethod + def make_grid_generator(builder: grid_generator.GridBuilder, para: Parameter, cuda_memory_manager: CudaMemoryManager, communicator: Communicator) -> GridProvider: ... + +class GridScaling: + __members__: ClassVar[dict] = ... # read-only + NotSpecified: ClassVar[GridScaling] = ... + ScaleCompressible: ClassVar[GridScaling] = ... + ScaleRhoSq: ClassVar[GridScaling] = ... + __entries: ClassVar[dict] = ... + def __init__(self, arg0: int) -> None: ... + def __eq__(self, arg0: object) -> bool: ... + def __getstate__(self) -> int: ... + def __hash__(self) -> int: ... + def __index__(self) -> int: ... + def __int__(self) -> int: ... + def __ne__(self, arg0: object) -> bool: ... + def __setstate__(self, arg0: int) -> None: ... + @property + def name(self) -> str: ... + +class GridScalingFactory: + def __init__(self) -> None: ... + def set_scaling_factory(self, scaling_type) -> None: ... + +class NoSlipBC: + __members__: ClassVar[dict] = ... # read-only + NoSlip3rdMomentsCompressible: ClassVar[NoSlipBC] = ... + NoSlipBounceBack: ClassVar[NoSlipBC] = ... + NoSlipCompressible: ClassVar[NoSlipBC] = ... + NoSlipImplicitBounceBack: ClassVar[NoSlipBC] = ... + NoSlipIncompressible: ClassVar[NoSlipBC] = ... + __entries: ClassVar[dict] = ... + def __init__(self, arg0: int) -> None: ... + def __eq__(self, arg0: object) -> bool: ... + def __getstate__(self) -> int: ... + def __hash__(self) -> int: ... + def __index__(self) -> int: ... + def __int__(self) -> int: ... + def __ne__(self, arg0: object) -> bool: ... + def __setstate__(self, arg0: int) -> None: ... + @property + def name(self) -> str: ... + +class OutputVariable: + __members__: ClassVar[dict] = ... # read-only + Distributions: ClassVar[OutputVariable] = ... + Velocities: ClassVar[OutputVariable] = ... + __entries: ClassVar[dict] = ... + def __init__(self, arg0: int) -> None: ... + def __eq__(self, arg0: object) -> bool: ... + def __getstate__(self) -> int: ... + def __hash__(self) -> int: ... + def __index__(self) -> int: ... + def __int__(self) -> int: ... + def __ne__(self, arg0: object) -> bool: ... + def __setstate__(self, arg0: int) -> None: ... + @property + def name(self) -> str: ... + +class Parameter: + @overload + def __init__(self, number_of_processes: int, my_ID: int, config_data: Optional[pyfluids.bindings.basics.ConfigurationFile]) -> None: ... + @overload + def __init__(self, number_of_processes: int, my_ID: int) -> None: ... + @overload + def __init__(self, config_data: pyfluids.bindings.basics.ConfigurationFile) -> None: ... + def add_actuator(self, actuator: PreCollisionInteractor) -> None: ... + def add_probe(self, probe: PreCollisionInteractor) -> None: ... + def get_SGS_constant(self) -> float: ... + def get_density_ratio(self) -> float: ... + def get_force_ratio(self) -> float: ... + def get_is_body_force(self) -> bool: ... + def get_output_path(self) -> str: ... + def get_output_prefix(self) -> str: ... + def get_velocity(self) -> float: ... + def get_velocity_ratio(self) -> float: ... + def get_viscosity(self) -> float: ... + def get_viscosity_ratio(self) -> float: ... + def set_AD_kernel(self, ad_kernel: str) -> None: ... + def set_calc_turbulence_intensity(self, calc_velocity_and_fluctuations: bool) -> None: ... + def set_comp_on(self, is_comp: bool) -> None: ... + def set_density_ratio(self, density_ratio: float) -> None: ... + def set_devices(self, devices: List[int]) -> None: ... + def set_diff_on(self, is_diff: bool) -> None: ... + def set_forcing(self, forcing_x: float, forcing_y: float, forcing_z: float) -> None: ... + def set_has_wall_model_monitor(self, has_wall_monitor: bool) -> None: ... + def set_initial_condition(self, init_func: Callable[[float,float,float],List[float]]) -> None: ... + def set_initial_condition_log_law(self, u_star: float, z0: float, velocity_ratio: float) -> None: ... + def set_initial_condition_perturbed_log_law(self, u_star: float, z0: float, length_x: float, length_z: float, height: float, velocity_ratio: float) -> None: ... + def set_initial_condition_uniform(self, velocity_x: float, velocity_y: float, velocity_z: float) -> None: ... + def set_is_body_force(self, is_body_force: bool) -> None: ... + def set_main_kernel(self, kernel: str) -> None: ... + def set_max_dev(self, max_dev: int) -> None: ... + def set_max_level(self, number_of_levels: int) -> None: ... + def set_outflow_pressure_correction_factor(self, correction_factor: float) -> None: ... + def set_output_path(self, o_path: str) -> None: ... + def set_output_prefix(self, o_prefix: str) -> None: ... + def set_print_files(self, print_files: bool) -> None: ... + def set_quadric_limiters(self, quadric_limiter_p: float, quadric_limiter_m: float, quadric_limiter_d: float) -> None: ... + def set_temperature_BC(self, temp_bc: float) -> None: ... + def set_temperature_init(self, temp: float) -> None: ... + def set_timestep_end(self, tend: int) -> None: ... + def set_timestep_of_coarse_level(self, timestep: int) -> None: ... + def set_timestep_out(self, tout: int) -> None: ... + def set_timestep_start_out(self, t_start_out: int) -> None: ... + def set_use_streams(self, use_streams: bool) -> None: ... + def set_velocity_LB(self, velocity: float) -> None: ... + def set_velocity_ratio(self, velocity_ratio: float) -> None: ... + def set_viscosity_LB(self, viscosity: float) -> None: ... + def set_viscosity_ratio(self, viscosity_ratio: float) -> None: ... + +class PreCollisionInteractor: + def __init__(self, *args, **kwargs) -> None: ... + +class PrecursorBC: + __members__: ClassVar[dict] = ... # read-only + DistributionsPrecursor: ClassVar[PrecursorBC] = ... + NotSpecified: ClassVar[PrecursorBC] = ... + VelocityPrecursor: ClassVar[PrecursorBC] = ... + __entries: ClassVar[dict] = ... + def __init__(self, arg0: int) -> None: ... + def __eq__(self, arg0: object) -> bool: ... + def __getstate__(self) -> int: ... + def __hash__(self) -> int: ... + def __index__(self) -> int: ... + def __int__(self) -> int: ... + def __ne__(self, arg0: object) -> bool: ... + def __setstate__(self, arg0: int) -> None: ... + @property + def name(self) -> str: ... + +class PrecursorWriter(PreCollisionInteractor): + def __init__(self, filename: str, output_path: str, x_pos: float, y_min: float, y_max: float, z_min: float, z_max: float, t_start_out: int, t_save: int, output_variable: OutputVariable, max_timesteps_per_file: int) -> None: ... + +class PressureBC: + __members__: ClassVar[dict] = ... # read-only + NotSpecified: ClassVar[PressureBC] = ... + OutflowNonReflective: ClassVar[PressureBC] = ... + OutflowNonReflectivePressureCorrection: ClassVar[PressureBC] = ... + PressureEquilibrium: ClassVar[PressureBC] = ... + PressureEquilibrium2: ClassVar[PressureBC] = ... + PressureNonEquilibriumCompressible: ClassVar[PressureBC] = ... + PressureNonEquilibriumIncompressible: ClassVar[PressureBC] = ... + __entries: ClassVar[dict] = ... + def __init__(self, arg0: int) -> None: ... + def __eq__(self, arg0: object) -> bool: ... + def __getstate__(self) -> int: ... + def __hash__(self) -> int: ... + def __index__(self) -> int: ... + def __int__(self) -> int: ... + def __ne__(self, arg0: object) -> bool: ... + def __setstate__(self, arg0: int) -> None: ... + @property + def name(self) -> str: ... + +class SideType: + __members__: ClassVar[dict] = ... # read-only + GEOMETRY: ClassVar[SideType] = ... + MX: ClassVar[SideType] = ... + MY: ClassVar[SideType] = ... + MZ: ClassVar[SideType] = ... + PX: ClassVar[SideType] = ... + PY: ClassVar[SideType] = ... + PZ: ClassVar[SideType] = ... + __entries: ClassVar[dict] = ... + def __init__(self, arg0: int) -> None: ... + def __eq__(self, arg0: object) -> bool: ... + def __getstate__(self) -> int: ... + def __hash__(self) -> int: ... + def __index__(self) -> int: ... + def __int__(self) -> int: ... + def __ne__(self, arg0: object) -> bool: ... + def __setstate__(self, arg0: int) -> None: ... + @property + def name(self) -> str: ... + +class Simulation: + @overload + def __init__(self, parameter: Parameter, memoryManager: CudaMemoryManager, communicator, gridProvider: GridProvider, bcFactory: BoundaryConditionFactory, gridScalingFactory: GridScalingFactory) -> None: ... + @overload + def __init__(self, parameter: Parameter, memoryManager: CudaMemoryManager, communicator, gridProvider: GridProvider, bcFactory: BoundaryConditionFactory) -> None: ... + @overload + def __init__(self, parameter: Parameter, memoryManager: CudaMemoryManager, communicator, gridProvider: GridProvider, bcFactory: BoundaryConditionFactory, tmFactory: TurbulenceModelFactory, gridScalingFactory: GridScalingFactory) -> None: ... + def addEnstrophyAnalyzer(self, t_analyse: int) -> None: ... + def addKineticEnergyAnalyzer(self, t_analyse: int) -> None: ... + def run(self) -> None: ... + +class SlipBC: + __members__: ClassVar[dict] = ... # read-only + NotSpecified: ClassVar[SlipBC] = ... + SlipBounceBack: ClassVar[SlipBC] = ... + SlipCompressible: ClassVar[SlipBC] = ... + SlipCompressibleTurbulentViscosity: ClassVar[SlipBC] = ... + SlipIncompressible: ClassVar[SlipBC] = ... + SlipPressureCompressibleTurbulentViscosity: ClassVar[SlipBC] = ... + __entries: ClassVar[dict] = ... + def __init__(self, arg0: int) -> None: ... + def __eq__(self, arg0: object) -> bool: ... + def __getstate__(self) -> int: ... + def __hash__(self) -> int: ... + def __index__(self) -> int: ... + def __int__(self) -> int: ... + def __ne__(self, arg0: object) -> bool: ... + def __setstate__(self, arg0: int) -> None: ... + @property + def name(self) -> str: ... + +class StressBC: + __members__: ClassVar[dict] = ... # read-only + NotSpecified: ClassVar[StressBC] = ... + StressBounceBack: ClassVar[StressBC] = ... + StressCompressible: ClassVar[StressBC] = ... + StressPressureBounceBack: ClassVar[StressBC] = ... + __entries: ClassVar[dict] = ... + def __init__(self, arg0: int) -> None: ... + def __eq__(self, arg0: object) -> bool: ... + def __getstate__(self) -> int: ... + def __hash__(self) -> int: ... + def __index__(self) -> int: ... + def __int__(self) -> int: ... + def __ne__(self, arg0: object) -> bool: ... + def __setstate__(self, arg0: int) -> None: ... + @property + def name(self) -> str: ... + +class TurbulenceModel: + __members__: ClassVar[dict] = ... # read-only + AMD: ClassVar[TurbulenceModel] = ... + NONE: ClassVar[TurbulenceModel] = ... + QR: ClassVar[TurbulenceModel] = ... + Smagorinsky: ClassVar[TurbulenceModel] = ... + __entries: ClassVar[dict] = ... + def __init__(self, arg0: int) -> None: ... + def __eq__(self, arg0: object) -> bool: ... + def __getstate__(self) -> int: ... + def __hash__(self) -> int: ... + def __index__(self) -> int: ... + def __int__(self) -> int: ... + def __ne__(self, arg0: object) -> bool: ... + def __setstate__(self, arg0: int) -> None: ... + @property + def name(self) -> str: ... + +class TurbulenceModelFactory: + def __init__(self, para: Parameter) -> None: ... + def read_config_file(self, config_data: pyfluids.bindings.basics.ConfigurationFile) -> None: ... + def set_model_constant(self, model_constant: float) -> None: ... + def set_turbulence_model(self, turbulence_model: TurbulenceModel) -> None: ... + +class VTKFileCollection(FileCollection): + def __init__(self, prefix: str) -> None: ... + +class VelocityBC: + __members__: ClassVar[dict] = ... # read-only + NotSpecified: ClassVar[VelocityBC] = ... + VelocityAndPressureCompressible: ClassVar[VelocityBC] = ... + VelocityCompressible: ClassVar[VelocityBC] = ... + VelocityIncompressible: ClassVar[VelocityBC] = ... + VelocitySimpleBounceBackCompressible: ClassVar[VelocityBC] = ... + __entries: ClassVar[dict] = ... + def __init__(self, arg0: int) -> None: ... + def __eq__(self, arg0: object) -> bool: ... + def __getstate__(self) -> int: ... + def __hash__(self) -> int: ... + def __index__(self) -> int: ... + def __int__(self) -> int: ... + def __ne__(self, arg0: object) -> bool: ... + def __setstate__(self, arg0: int) -> None: ... + @property + def name(self) -> str: ... + +class FileCollection: + def __init__(self, *args, **kwargs) -> None: ... + +def create_file_collection(prefix: str, type: FileType) -> FileCollection: ... diff --git a/pythonbindings/pyfluids-stubs/bindings/gpu/grid_generator.pyi b/pythonbindings/pyfluids-stubs/bindings/gpu/grid_generator.pyi new file mode 100644 index 0000000000000000000000000000000000000000..8d715e4b4cd49e6dbf92da3aedddbc4b869067c4 --- /dev/null +++ b/pythonbindings/pyfluids-stubs/bindings/gpu/grid_generator.pyi @@ -0,0 +1,100 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file grid_generator.pyi +! \ingroup gpu +! \author Henry Korb +======================================================================================= +""" +from typing import Any, List + +from typing import overload +import pyfluids.bindings.basics +import pyfluids.bindings.gpu + +class BoundingBox: + def __init__(self, min_x: float, max_x: float, min_y: float, max_y: float, min_z: float, max_z: float) -> None: ... + +class Conglomerate(Object): + def __init__(self, *args, **kwargs) -> None: ... + def add(self, object: Object) -> None: ... + @staticmethod + def make_shared() -> Conglomerate: ... + def subtract(self, object: Object) -> None: ... + +class Cuboid(Object): + def __init__(self, min_x1: float, min_x2: float, min_x3: float, max_x1: float, max_x2: float, max_x3: float) -> None: ... + +class GridBuilder: + def __init__(self, *args, **kwargs) -> None: ... + def get_number_of_grid_levels(self) -> int: ... + +class GridFactory: + def __init__(self, *args, **kwargs) -> None: ... + @staticmethod + def make() -> GridFactory: ... + +class LevelGridBuilder(GridBuilder): + def __init__(self, *args, **kwargs) -> None: ... + def set_no_slip_boundary_condition(self, side_type: pyfluids.bindings.gpu.SideType) -> None: ... + def set_periodic_boundary_condition(self, periodic_x: bool, periodic_y: bool, periodic_z: bool) -> None: ... + def set_precursor_boundary_condition(self, side_type: pyfluids.bindings.gpu.SideType, file_collection: pyfluids.bindings.gpu.VelocityFileCollection, n_t_read: int, velocity_x: float = ..., velocity_y: float = ..., velocity_z: float = ..., file_level_to_grid_level_map: List[int] = ...) -> None: ... + def set_pressure_boundary_condition(self, side_type: pyfluids.bindings.gpu.SideType, rho: float) -> None: ... + def set_slip_boundary_condition(self, side_type: pyfluids.bindings.gpu.SideType, normal_x: float, normal_y: float, normal_z: float) -> None: ... + def set_stress_boundary_condition(self, side_type: pyfluids.bindings.gpu.SideType, normal_x: float, normal_y: float, normal_z: float, sampling_offset: int, z0: float, dx: float) -> None: ... + def set_velocity_boundary_condition(self, side_type: pyfluids.bindings.gpu.SideType, vx: float, vy: float, vz: float) -> None: ... + +class MultipleGridBuilder(LevelGridBuilder): + def __init__(self, *args, **kwargs) -> None: ... + def add_coarse_grid(self, start_x: float, start_y: float, start_z: float, end_x: float, end_y: float, end_z: float, delta: float) -> None: ... + @overload + def add_geometry(self, solid_object: Object) -> None: ... + @overload + def add_geometry(self, solid_object: Object, level: int) -> None: ... + @overload + def add_grid(self, grid_shape: Object) -> None: ... + @overload + def add_grid(self, grid_shape: Object, level_fine: int) -> None: ... + def build_grids(self, lbm_or_gks: pyfluids.bindings.basics.LbmOrGks, enable_thin_walls: bool) -> None: ... + def get_number_of_levels(self) -> int: ... + @staticmethod + def make_shared(grid_factory: GridFactory) -> MultipleGridBuilder: ... + +class Object: + def __init__(self, *args, **kwargs) -> None: ... + +class Sphere(Object): + def __init__(self, *args, **kwargs) -> None: ... + @staticmethod + def make_shared() -> Sphere: ... + +class TriangularMesh(Object): + def __init__(self, *args, **kwargs) -> None: ... + @staticmethod + def make() -> TriangularMesh: ... diff --git a/pythonbindings/pyfluids-stubs/bindings/gpu/probes.pyi b/pythonbindings/pyfluids-stubs/bindings/gpu/probes.pyi new file mode 100644 index 0000000000000000000000000000000000000000..af9c40078e6009efebda4450b5c5e23586aa1e83 --- /dev/null +++ b/pythonbindings/pyfluids-stubs/bindings/gpu/probes.pyi @@ -0,0 +1,85 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file probes.pyi +! \ingroup gpu +! \author Henry Korb +======================================================================================= +""" +from typing import ClassVar, List + +import pyfluids.bindings.gpu + +class PlanarAverageProbe(Probe): + def __init__(self, probe_name: str, output_path: str, t_start_avg: int, t_start_tmp_avg: int, t_avg: int, t_start_out: int, t_out: int, plane_normal: str) -> None: ... + +class PlaneProbe(Probe): + def __init__(self, probe_name: str, output_path: str, t_start_avg: int, t_avg: int, t_start_out: int, t_out: int) -> None: ... + def set_probe_plane(self, pos_x: float, pos_y: float, pos_z: float, delta_x: float, delta_y: float, delta_z: float) -> None: ... + +class PointProbe(Probe): + def __init__(self, probe_name: str, output_path: str, t_start_avg: int, t_avg: int, t_start_out: int, t_out: int, output_timeseries: bool) -> None: ... + def add_probe_points_from_list(self, point_coords_x: List[float], point_coords_y: List[float], point_coords_z: List[float]) -> None: ... + def add_probe_points_from_x_normal_plane(self, pos_x: float, pos0_y: float, pos0_z: float, pos1_y: float, pos1_z: float, n_y: int, n_z: int) -> None: ... + +class Probe(pyfluids.bindings.gpu.PreCollisionInteractor): + def __init__(self, *args, **kwargs) -> None: ... + def add_all_available_statistics(self) -> None: ... + def add_statistic(self, variable: Statistic) -> None: ... + def set_file_name_to_n_out(self) -> None: ... + +class Statistic: + __members__: ClassVar[dict] = ... # read-only + Instantaneous: ClassVar[Statistic] = ... + Means: ClassVar[Statistic] = ... + SpatialCovariances: ClassVar[Statistic] = ... + SpatialFlatness: ClassVar[Statistic] = ... + SpatialMeans: ClassVar[Statistic] = ... + SpatialSkewness: ClassVar[Statistic] = ... + SpatioTemporalCovariances: ClassVar[Statistic] = ... + SpatioTemporalFlatness: ClassVar[Statistic] = ... + SpatioTemporalMeans: ClassVar[Statistic] = ... + SpatioTemporalSkewness: ClassVar[Statistic] = ... + Variances: ClassVar[Statistic] = ... + __entries: ClassVar[dict] = ... + def __init__(self, arg0: int) -> None: ... + def __eq__(self, arg0: object) -> bool: ... + def __getstate__(self) -> int: ... + def __hash__(self) -> int: ... + def __index__(self) -> int: ... + def __int__(self) -> int: ... + def __ne__(self, arg0: object) -> bool: ... + def __setstate__(self, arg0: int) -> None: ... + @property + def name(self) -> str: ... + +class WallModelProbe(Probe): + def __init__(self, probe_name: str, output_path: str, t_start_avg: int, t_start_tmp_avg: int, t_avg: int, t_start_out: int, t_out: int) -> None: ... + def set_evaluate_pressure_gradient(self, eval_press_grad: bool) -> None: ... + def set_force_output_to_stress(self, output_stress: bool) -> None: ... diff --git a/pythonbindings/pyfluids-stubs/bindings/lbm.pyi b/pythonbindings/pyfluids-stubs/bindings/lbm.pyi new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/pythonbindings/pyfluids-stubs/bindings/logger.pyi b/pythonbindings/pyfluids-stubs/bindings/logger.pyi new file mode 100644 index 0000000000000000000000000000000000000000..fe84eeb18f3245ef72ed023b2de9db7b9131d144 --- /dev/null +++ b/pythonbindings/pyfluids-stubs/bindings/logger.pyi @@ -0,0 +1,45 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file logger.pyi +! \ingroup bindings +! \author Henry Korb +======================================================================================= +""" +class Logger: + @staticmethod + def change_log_path(path: str) -> None: ... + @staticmethod + def initialize_logger() -> None: ... + +def vf_log_critical(message: str) -> None: ... +def vf_log_debug(message: str) -> None: ... +def vf_log_info(message: str) -> None: ... +def vf_log_trace(message: str) -> None: ... +def vf_log_warning(message: str) -> None: ... diff --git a/pythonbindings/pyfluids/__init__.py b/pythonbindings/pyfluids/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..f0537b758267e22a72e5030340de7b87d52f35c3 --- /dev/null +++ b/pythonbindings/pyfluids/__init__.py @@ -0,0 +1,54 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file __init__.py +! \ingroup pyfluids +! \author Henry Korb +======================================================================================= +""" +try: + from .bindings import basics +except ImportError: + print("Basics bindings not included") +try: + from .bindings import logger +except ImportError: + print("Logger bindings not included") +try: + from .bindings import lbm +except ImportError: + print("LBM bindings not included") +try: + from .bindings import gpu +except ImportError: + print("GPU bindings not included") +try: + from .bindings import cpu +except ImportError: + print("CPU bindings not included") \ No newline at end of file diff --git a/pythonbindings/pyfluids/py.typed b/pythonbindings/pyfluids/py.typed new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/pythonbindings/pymuparser/__init__.py b/pythonbindings/pymuparser/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..398069bcba03b3fe710d9d9a6398e9c530b19ee9 --- /dev/null +++ b/pythonbindings/pymuparser/__init__.py @@ -0,0 +1,38 @@ +r""" +======================================================================================= + ____ ____ __ ______ __________ __ __ __ __ + \ \ | | | | | _ \ |___ ___| | | | | / \ | | + \ \ | | | | | |_) | | | | | | | / \ | | + \ \ | | | | | _ / | | | | | | / /\ \ | | + \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ + \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| + \ \ | | ________________________________________________________________ + \ \ | | | ______________________________________________________________| + \ \| | | | __ __ __ __ ______ _______ + \ | | |_____ | | | | | | | | | _ \ / _____) + \ | | _____| | | | | | | | | | | \ \ \_______ + \ | | | | |_____ | \_/ | | | | |_/ / _____ | + \ _____| |__| |________| \_______/ |__| |______/ (_______/ + + This file is part of VirtualFluids. VirtualFluids is free software: you can + redistribute it and/or modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, either version 3 of + the License, or (at your option) any later version. + + VirtualFluids is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License along + with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. + +! \file __init__.pyi +! \ingroup pymuparser +! \author Henry Korb +======================================================================================= +""" +try: + from .bindings import Parser +except ImportError as e: + raise ImportError("Pymuparser bindings were not built. Only included if VirtualFluids is built with VF_BUILD_CPU=ON.") \ No newline at end of file diff --git a/pythonbindings/src/VirtualFluids.cpp b/pythonbindings/src/VirtualFluids.cpp new file mode 100644 index 0000000000000000000000000000000000000000..20e5012e0af325440e502c704d6f372100306ab1 --- /dev/null +++ b/pythonbindings/src/VirtualFluids.cpp @@ -0,0 +1,63 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file VirtualFluids.cpp +//! \ingroup src +//! \author Henry Korb +//======================================================================================= +#include <pybind11/pybind11.h> +#include "basics/basics.cpp" +#include "lbm/lbm.cpp" +#include "logger/logger.cpp" + +#ifdef VF_GPU_PYTHONBINDINGS +#include "gpu/gpu.cpp" +#endif +#ifdef VF_CPU_PYTHONBINDINGS +#include "cpu/cpu.cpp" +#endif + + +namespace py_bindings +{ + namespace py = pybind11; + + PYBIND11_MODULE(bindings, m) + { + py::add_ostream_redirect(m, "ostream_redirect"); + basics::makeModule(m); + lbm::makeModule(m); + logging::makeModule(m); +#ifdef VF_GPU_PYTHONBINDINGS + gpu::makeModule(m); +#endif +#ifdef VF_CPU_PYTHONBINDINGS + cpu::makeModule(m); +#endif + } +} \ No newline at end of file diff --git a/pythonbindings/src/VirtualFluidsModulesCPU.cpp b/pythonbindings/src/VirtualFluidsModulesCPU.cpp deleted file mode 100644 index 2fba3da494f568f7d0d0a117a579a45c9c1b9245..0000000000000000000000000000000000000000 --- a/pythonbindings/src/VirtualFluidsModulesCPU.cpp +++ /dev/null @@ -1,12 +0,0 @@ -#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 deleted file mode 100644 index b96971caf381faada76ee676cf60469492d055c2..0000000000000000000000000000000000000000 --- a/pythonbindings/src/VirtualFluidsModulesGPU.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#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 index 381e345d78226b25ec3a77a14340d2ef1171c8c9..e67dfb05308511c8bf79d7e860299f062f317194 100644 --- a/pythonbindings/src/basics/basics.cpp +++ b/pythonbindings/src/basics/basics.cpp @@ -1,3 +1,35 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file basics.cpp +//! \ingroup basics +//! \author Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include "submodules/logger.cpp" #include "submodules/configuration_file.cpp" diff --git a/pythonbindings/src/basics/submodules/configuration_file.cpp b/pythonbindings/src/basics/submodules/configuration_file.cpp index f5a2f87135a17f5eda34a7467d95f9db6b1c21d1..7fcd48c34824b9370eeac1872c899bf980176a52 100644 --- a/pythonbindings/src/basics/submodules/configuration_file.cpp +++ b/pythonbindings/src/basics/submodules/configuration_file.cpp @@ -1,5 +1,37 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file configuration_file.cpp +//! \ingroup submodules +//! \author Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> -#include <basics/config/ConfigurationFile.h> +#include "basics/config/ConfigurationFile.h" namespace configuration { @@ -9,6 +41,19 @@ namespace configuration { py::class_<vf::basics::ConfigurationFile>(parentModule, "ConfigurationFile") .def(py::init<>()) - .def("load", &vf::basics::ConfigurationFile::load); + .def("load", &vf::basics::ConfigurationFile::load, py::arg("file")) + .def("contains", &vf::basics::ConfigurationFile::contains, py::arg("key")) + .def("get_int_value" , static_cast<int (vf::basics::ConfigurationFile::*)(const std::string&) const>(&vf::basics::ConfigurationFile::getValue), py::arg("key")) + .def("get_int_value" , static_cast<int (vf::basics::ConfigurationFile::*)(const std::string&, int ) const>(&vf::basics::ConfigurationFile::getValue), py::arg("key"), py::arg("default_value")) + .def("get_uint_value" , static_cast<uint (vf::basics::ConfigurationFile::*)(const std::string&) const>(&vf::basics::ConfigurationFile::getValue), py::arg("key")) + .def("get_uint_value" , static_cast<uint (vf::basics::ConfigurationFile::*)(const std::string&, uint ) const>(&vf::basics::ConfigurationFile::getValue), py::arg("key"), py::arg("default_value")) + .def("get_float_value" , static_cast<float (vf::basics::ConfigurationFile::*)(const std::string&) const>(&vf::basics::ConfigurationFile::getValue), py::arg("key")) + .def("get_float_value" , static_cast<float (vf::basics::ConfigurationFile::*)(const std::string&, float ) const>(&vf::basics::ConfigurationFile::getValue), py::arg("key"), py::arg("default_value")) + .def("get_double_value", static_cast<double (vf::basics::ConfigurationFile::*)(const std::string&) const>(&vf::basics::ConfigurationFile::getValue), py::arg("key")) + .def("get_double_value", static_cast<double (vf::basics::ConfigurationFile::*)(const std::string&, double ) const>(&vf::basics::ConfigurationFile::getValue), py::arg("key"), py::arg("default_value")) + .def("get_bool_value" , static_cast<bool (vf::basics::ConfigurationFile::*)(const std::string&) const>(&vf::basics::ConfigurationFile::getValue), py::arg("key")) + .def("get_bool_value" , static_cast<bool (vf::basics::ConfigurationFile::*)(const std::string&, bool ) const>(&vf::basics::ConfigurationFile::getValue), py::arg("key"), py::arg("default_value")) + .def("get_string_value", static_cast<std::string (vf::basics::ConfigurationFile::*)(const std::string&) const>(&vf::basics::ConfigurationFile::getValue), py::arg("key")) + .def("get_string_value", static_cast<std::string (vf::basics::ConfigurationFile::*)(const std::string&, std::string) const>(&vf::basics::ConfigurationFile::getValue), py::arg("key"), py::arg("default_value")); } } \ 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 index ed1deeca62fc57b7f44499b306e9f99b7f990604..d20cf2d1f631f6d36a80c36f1fb6c9c59d192090 100644 --- a/pythonbindings/src/basics/submodules/lbm_or_gks.cpp +++ b/pythonbindings/src/basics/submodules/lbm_or_gks.cpp @@ -1,3 +1,35 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file lbm_or_gks.cpp +//! \ingroup submodules +//! \author Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include "basics/Core/LbmOrGks.h" diff --git a/pythonbindings/src/basics/submodules/logger.cpp b/pythonbindings/src/basics/submodules/logger.cpp index d46648e349b44243581e083f3561e8a13648f3b2..fa7e00e4dca06581b7a14d2bcf2628ed6af60001 100644 --- a/pythonbindings/src/basics/submodules/logger.cpp +++ b/pythonbindings/src/basics/submodules/logger.cpp @@ -1,3 +1,35 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file logger.cpp +//! \ingroup submodules +//! \author Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include <pybind11/iostream.h> #include <basics/Core/Logger/Logger.h> @@ -12,12 +44,12 @@ namespace logger py::module loggerModule = parentModule.def_submodule("logger"); py::class_<logging::Logger>(loggerModule, "Logger") - .def("add_stdout", [](){ + .def_static("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); + .def_static("set_debug_level", &logging::Logger::setDebugLevel) + .def_static("time_stamp", &logging::Logger::timeStamp, py::arg("time_stamp")) + .def_static("enable_printed_rank_numbers", &logging::Logger::enablePrintedRankNumbers, py::arg("print")); loggerModule.attr("log") = logging::out; py::enum_<logging::Logger::Level>(loggerModule, "Level") diff --git a/pythonbindings/src/cpu/cpu.cpp b/pythonbindings/src/cpu/cpu.cpp index 554de53b47446366693aed31d534f6145ebea8ba..75143d913596c74a26f25ce64f1e6d214a442e34 100644 --- a/pythonbindings/src/cpu/cpu.cpp +++ b/pythonbindings/src/cpu/cpu.cpp @@ -1,3 +1,35 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file cpu.cpp +//! \ingroup cpu +//! \author Sven Marcus, Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include "submodules/boundaryconditions.cpp" #include "submodules/simulationconfig.cpp" diff --git a/pythonbindings/src/cpu/submodules/boundaryconditions.cpp b/pythonbindings/src/cpu/submodules/boundaryconditions.cpp index 3bff7bc069ca20fe1c0cf3d1847b9714e0381505..ac9ec8605dec51e8374c850b1c1b58314674c426 100644 --- a/pythonbindings/src/cpu/submodules/boundaryconditions.cpp +++ b/pythonbindings/src/cpu/submodules/boundaryconditions.cpp @@ -1,3 +1,35 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file boundaryconditions.cpp +//! \ingroup submodules +//! \author Sven Marcus, Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include <pybind11/stl.h> #include <BoundaryConditions/DensityBCAdapter.h> diff --git a/pythonbindings/src/cpu/submodules/geometry.cpp b/pythonbindings/src/cpu/submodules/geometry.cpp index b7ff4dd761258d41687589d2dd89c3479093753e..4c4c47b002b9c7451a8d788ba82c4a19b78ca96f 100644 --- a/pythonbindings/src/cpu/submodules/geometry.cpp +++ b/pythonbindings/src/cpu/submodules/geometry.cpp @@ -1,3 +1,35 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file geometry.cpp +//! \ingroup submodules +//! \author Sven Marcus, Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include <geometry3d/GbPoint3D.h> #include <geometry3d/GbObject3D.h> diff --git a/pythonbindings/src/cpu/submodules/kernel.cpp b/pythonbindings/src/cpu/submodules/kernel.cpp index fb291790632cc2041410f60a14fca8d966283343..b00d86579540a299e4bf3ed47bc09d4386f420a2 100644 --- a/pythonbindings/src/cpu/submodules/kernel.cpp +++ b/pythonbindings/src/cpu/submodules/kernel.cpp @@ -1,3 +1,35 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file kernel.cpp +//! \ingroup submodules +//! \author Sven Marcus, Henry Korb +//======================================================================================= #include <memory> #include <pybind11/pybind11.h> #include <simulationconfig/KernelFactory.h> diff --git a/pythonbindings/src/cpu/submodules/simulationconfig.cpp b/pythonbindings/src/cpu/submodules/simulationconfig.cpp index 60af4e36af4dca67e9262dd9f5ee1f46d5b7bb58..09d91f44e85f03c6150c56ce5762e7629212fba0 100644 --- a/pythonbindings/src/cpu/submodules/simulationconfig.cpp +++ b/pythonbindings/src/cpu/submodules/simulationconfig.cpp @@ -1,3 +1,35 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file simulationconfig.cpp +//! \ingroup submodules +//! \author Sven Marcus, Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include <simulationconfig/Simulation.h> diff --git a/pythonbindings/src/cpu/submodules/simulationparameters.cpp b/pythonbindings/src/cpu/submodules/simulationparameters.cpp index acc272f2ee412cfbafd9007b4b18610cfd0a1e9b..b33d20f9e5d335a0ed381faf8786d88cc7642738 100644 --- a/pythonbindings/src/cpu/submodules/simulationparameters.cpp +++ b/pythonbindings/src/cpu/submodules/simulationparameters.cpp @@ -1,3 +1,35 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file simulationparameters.cpp +//! \ingroup submodules +//! \author Sven Marcus, Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include <pybind11/stl.h> #include <complex> diff --git a/pythonbindings/src/cpu/submodules/writer.cpp b/pythonbindings/src/cpu/submodules/writer.cpp index d5ec527a27caf63d9a3066c51e1f675b307fe0b2..f1cfd8934c2da84266a93d5bcd91eb26f5f69d3f 100644 --- a/pythonbindings/src/cpu/submodules/writer.cpp +++ b/pythonbindings/src/cpu/submodules/writer.cpp @@ -1,3 +1,35 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file writer.cpp +//! \ingroup submodules +//! \author Sven Marcus, Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include <simulationconfig/WriterConfiguration.h> diff --git a/pythonbindings/src/gpu/gpu.cpp b/pythonbindings/src/gpu/gpu.cpp index dc110cd5e19a9aad4937f9c2133ddf74c0ddf9bf..9eb160ae7765f16a6437e343cb878bb4b80877bf 100644 --- a/pythonbindings/src/gpu/gpu.cpp +++ b/pythonbindings/src/gpu/gpu.cpp @@ -1,14 +1,50 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file gpu.cpp +//! \ingroup gpu +//! \author Henry Korb +//======================================================================================= #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/cuda_memory_manager.cpp" +#include "submodules/probes.cpp" +#include "submodules/precursor_writer.cpp" #include "submodules/grid_provider.cpp" #include "submodules/grid_generator.cpp" -#include "submodules/probes.cpp" +#include "submodules/turbulence_models.cpp" +#include "submodules/transient_bc_setter.cpp" +#include "submodules/actuator_farm.cpp" +#include "submodules/grid_scaling_factory.cpp" namespace gpu { @@ -20,13 +56,17 @@ namespace gpu simulation::makeModule(gpuModule); parameter::makeModule(gpuModule); pre_collision_interactor::makeModule(gpuModule); - actuator_line::makeModule(gpuModule); + actuator_farm::makeModule(gpuModule); boundary_conditions::makeModule(gpuModule); + transient_bc_setter::makeModule(gpuModule); communicator::makeModule(gpuModule); cuda_memory_manager::makeModule(gpuModule); - grid_provider::makeModule(gpuModule); probes::makeModule(gpuModule); + precursor_writer::makeModule(gpuModule); grid_generator::makeModule(gpuModule); + grid_provider::makeModule(gpuModule); + turbulence_model::makeModule(gpuModule); + grid_scaling_factory::makeModule(gpuModule); return gpuModule; } } \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/actuator_farm.cpp b/pythonbindings/src/gpu/submodules/actuator_farm.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a930616db3e0d0713bdf57157387d75d171603de --- /dev/null +++ b/pythonbindings/src/gpu/submodules/actuator_farm.cpp @@ -0,0 +1,171 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file actuator_farm.cpp +//! \ingroup submodules +//! \author Henry Korb +//======================================================================================= +#include <pybind11/pybind11.h> +#include <pybind11/numpy.h> +#include <gpu/VirtualFluids_GPU/PreCollisionInteractor/ActuatorFarm.h> +#include <gpu/VirtualFluids_GPU/PreCollisionInteractor/PreCollisionInteractor.h> +class PyActuatorFarm : public ActuatorFarm +{ +public: + using ActuatorFarm::ActuatorFarm; // Inherit constructors + void calcBladeForces() override + { + PYBIND11_OVERRIDE_NAME(void, ActuatorFarm, "calc_blade_forces", calcBladeForces); + } +}; +namespace actuator_farm +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + using arr = py::array_t<float, py::array::c_style>; + + py::class_<ActuatorFarm, PreCollisionInteractor, PyActuatorFarm, std::shared_ptr<ActuatorFarm>>(parentModule, "ActuatorFarm", py::dynamic_attr()) + .def(py::init< const uint, + const real, + const uint, + const real, + int, + const real, + const real, + const bool>(), + py::arg("number_of_blades_per_turbine"), + py::arg("density"), + py::arg("number_of_nodes_per_blade"), + py::arg("epsilon"), + py::arg("level"), + py::arg("delta_t"), + py::arg("delta_x"), + py::arg("use_host_arrays")) + .def_property_readonly("number_of_turbines", &ActuatorFarm::getNumberOfTurbines) + .def_property_readonly("number_of_nodes_per_blade", &ActuatorFarm::getNumberOfNodesPerBlade) + .def_property_readonly("number_of_blades_per_turbine", &ActuatorFarm::getNumberOfBladesPerTurbine) + .def_property_readonly("number_of_nodes", &ActuatorFarm::getNumberOfNodes) + .def_property_readonly("number_of_indices", &ActuatorFarm::getNumberOfIndices) + .def_property_readonly("density", &ActuatorFarm::getDensity) + .def_property_readonly("delta_t", &ActuatorFarm::getDeltaT) + .def_property_readonly("delta_x", &ActuatorFarm::getDeltaX) + + .def("add_turbine", &ActuatorFarm::addTurbine, py::arg("posX"), py::arg("posY"), py::arg("posZ"), py::arg("diameter"), py::arg("omega"), py::arg("azimuth"), py::arg("yaw"), py::arg("bladeRadii")) + + .def("get_turbine_pos", [](ActuatorFarm& al, uint turbine){ real position[3] = {al.getTurbinePosX(turbine), al.getTurbinePosY(turbine), al.getTurbinePosZ(turbine)}; return arr(3, position); }, py::arg("turbine")) + .def("get_turbine_azimuth", &ActuatorFarm::getTurbineAzimuth, py::arg("turbine")) + .def("get_turbine_yaw", &ActuatorFarm::getTurbineYaw, py::arg("turbine")) + .def("get_turbine_omega", &ActuatorFarm::getTurbineOmega, py::arg("turbine")) + .def("get_all_azimuths", [](ActuatorFarm& al){ return arr(al.getNumberOfTurbines(), al.getAllAzimuths()); } ) + .def("get_all_yaws", [](ActuatorFarm& al){ return arr(al.getNumberOfTurbines(), al.getAllYaws()); } ) + .def("get_all_omegas", [](ActuatorFarm& al){ return arr(al.getNumberOfTurbines(), al.getAllOmegas()); } ) + .def("get_all_turbine_pos_x", [](ActuatorFarm& al){ return arr(al.getNumberOfTurbines(), al.getAllTurbinePosX()); } ) + .def("get_all_turbine_pos_y", [](ActuatorFarm& al){ return arr(al.getNumberOfTurbines(), al.getAllTurbinePosY()); } ) + .def("get_all_turbine_pos_z", [](ActuatorFarm& al){ return arr(al.getNumberOfTurbines(), al.getAllTurbinePosZ()); } ) + + .def("get_all_blade_radii", [](ActuatorFarm& al){ return arr({al.getNumberOfTurbines(), al.getNumberOfNodesPerBlade()}, al.getAllBladeRadii()); } ) + .def("get_all_blade_coords_x", [](ActuatorFarm& al){ return arr({al.getNumberOfTurbines(), al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getAllBladeCoordsX()); } ) + .def("get_all_blade_coords_y", [](ActuatorFarm& al){ return arr({al.getNumberOfTurbines(), al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getAllBladeCoordsY()); } ) + .def("get_all_blade_coords_z", [](ActuatorFarm& al){ return arr({al.getNumberOfTurbines(), al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getAllBladeCoordsZ()); } ) + .def("get_all_blade_velocities_x", [](ActuatorFarm& al){ return arr({al.getNumberOfTurbines(), al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getAllBladeVelocitiesX()); } ) + .def("get_all_blade_velocities_y", [](ActuatorFarm& al){ return arr({al.getNumberOfTurbines(), al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getAllBladeVelocitiesY()); } ) + .def("get_all_blade_velocities_z", [](ActuatorFarm& al){ return arr({al.getNumberOfTurbines(), al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getAllBladeVelocitiesZ()); } ) + .def("get_all_blade_forces_x", [](ActuatorFarm& al){ return arr({al.getNumberOfTurbines(), al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getAllBladeForcesX()); } ) + .def("get_all_blade_forces_y", [](ActuatorFarm& al){ return arr({al.getNumberOfTurbines(), al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getAllBladeForcesY()); } ) + .def("get_all_blade_forces_z", [](ActuatorFarm& al){ return arr({al.getNumberOfTurbines(), al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getAllBladeForcesZ()); } ) + + .def("get_turbine_blade_radii", [](ActuatorFarm& al, uint turbine){ return arr(al.getNumberOfNodesPerBlade(), al.getTurbineBladeRadiiDevice(turbine)); } , py::arg("turbine")) + .def("get_turbine_blade_coords_x", [](ActuatorFarm& al, uint turbine){ return arr({al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getTurbineBladeCoordsXDevice(turbine)); }, py::arg("turbine") ) + .def("get_turbine_blade_coords_y", [](ActuatorFarm& al, uint turbine){ return arr({al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getTurbineBladeCoordsYDevice(turbine)); }, py::arg("turbine") ) + .def("get_turbine_blade_coords_z", [](ActuatorFarm& al, uint turbine){ return arr({al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getTurbineBladeCoordsZDevice(turbine)); }, py::arg("turbine") ) + .def("get_turbine_blade_velocities_x", [](ActuatorFarm& al, uint turbine){ return arr({al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getTurbineBladeVelocitiesXDevice(turbine)); }, py::arg("turbine") ) + .def("get_turbine_blade_velocities_y", [](ActuatorFarm& al, uint turbine){ return arr({al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getTurbineBladeVelocitiesYDevice(turbine)); }, py::arg("turbine") ) + .def("get_turbine_blade_velocities_z", [](ActuatorFarm& al, uint turbine){ return arr({al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getTurbineBladeVelocitiesZDevice(turbine)); }, py::arg("turbine") ) + .def("get_turbine_blade_forces_x", [](ActuatorFarm& al, uint turbine){ return arr({al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getTurbineBladeForcesXDevice(turbine)); }, py::arg("turbine") ) + .def("get_turbine_blade_forces_y", [](ActuatorFarm& al, uint turbine){ return arr({al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getTurbineBladeForcesYDevice(turbine)); }, py::arg("turbine") ) + .def("get_turbine_blade_forces_z", [](ActuatorFarm& al, uint turbine){ return arr({al.getNumberOfBladesPerTurbine(), al.getNumberOfNodesPerBlade()}, al.getTurbineBladeForcesZDevice(turbine)); }, py::arg("turbine") ) + + .def("get_all_blade_radii_device", [](ActuatorFarm& al) -> intptr_t { return reinterpret_cast<intptr_t>(al.getAllBladeRadiiDevice()); } ) + .def("get_all_blade_coords_x_device", [](ActuatorFarm& al) -> intptr_t { return reinterpret_cast<intptr_t> (al.getAllBladeCoordsXDevice()); } ) + .def("get_all_blade_coords_y_device", [](ActuatorFarm& al) -> intptr_t { return reinterpret_cast<intptr_t> (al.getAllBladeCoordsYDevice()); } ) + .def("get_all_blade_coords_z_device", [](ActuatorFarm& al) -> intptr_t { return reinterpret_cast<intptr_t> (al.getAllBladeCoordsZDevice()); } ) + .def("get_all_blade_velocities_x_device", [](ActuatorFarm& al) -> intptr_t { return reinterpret_cast<intptr_t> (al.getAllBladeVelocitiesXDevice()); } ) + .def("get_all_blade_velocities_y_device", [](ActuatorFarm& al) -> intptr_t { return reinterpret_cast<intptr_t> (al.getAllBladeVelocitiesYDevice()); } ) + .def("get_all_blade_velocities_z_device", [](ActuatorFarm& al) -> intptr_t { return reinterpret_cast<intptr_t> (al.getAllBladeVelocitiesZDevice()); } ) + .def("get_all_blade_forces_x_device", [](ActuatorFarm& al) -> intptr_t { return reinterpret_cast<intptr_t> (al.getAllBladeForcesXDevice()); } ) + .def("get_all_blade_forces_y_device", [](ActuatorFarm& al) -> intptr_t { return reinterpret_cast<intptr_t> (al.getAllBladeForcesYDevice()); } ) + .def("get_all_blade_forces_z_device", [](ActuatorFarm& al) -> intptr_t { return reinterpret_cast<intptr_t> (al.getAllBladeForcesZDevice()); } ) + + .def("get_turbine_blade_radii_device", [](ActuatorFarm& al, uint turbine) -> intptr_t { return reinterpret_cast<intptr_t>(al.getTurbineBladeRadiiDevice(turbine)); }, py::arg("turbine") ) + .def("get_turbine_blade_coords_x_device", [](ActuatorFarm& al, uint turbine) -> intptr_t { return reinterpret_cast<intptr_t>(al.getTurbineBladeCoordsXDevice(turbine)); }, py::arg("turbine") ) + .def("get_turbine_blade_coords_y_device", [](ActuatorFarm& al, uint turbine) -> intptr_t { return reinterpret_cast<intptr_t>(al.getTurbineBladeCoordsYDevice(turbine)); }, py::arg("turbine") ) + .def("get_turbine_blade_coords_z_device", [](ActuatorFarm& al, uint turbine) -> intptr_t { return reinterpret_cast<intptr_t>(al.getTurbineBladeCoordsZDevice(turbine)); }, py::arg("turbine") ) + .def("get_turbine_blade_velocities_x_device", [](ActuatorFarm& al, uint turbine) -> intptr_t { return reinterpret_cast<intptr_t>(al.getTurbineBladeVelocitiesXDevice(turbine)); }, py::arg("turbine") ) + .def("get_turbine_blade_velocities_y_device", [](ActuatorFarm& al, uint turbine) -> intptr_t { return reinterpret_cast<intptr_t>(al.getTurbineBladeVelocitiesYDevice(turbine)); }, py::arg("turbine") ) + .def("get_turbine_blade_velocities_z_device", [](ActuatorFarm& al, uint turbine) -> intptr_t { return reinterpret_cast<intptr_t>(al.getTurbineBladeVelocitiesZDevice(turbine)); }, py::arg("turbine") ) + .def("get_turbine_blade_forces_x_device", [](ActuatorFarm& al, uint turbine) -> intptr_t { return reinterpret_cast<intptr_t>(al.getTurbineBladeForcesXDevice(turbine)); }, py::arg("turbine") ) + .def("get_turbine_blade_forces_y_device", [](ActuatorFarm& al, uint turbine) -> intptr_t { return reinterpret_cast<intptr_t>(al.getTurbineBladeForcesYDevice(turbine)); }, py::arg("turbine") ) + .def("get_turbine_blade_forces_z_device", [](ActuatorFarm& al, uint turbine) -> intptr_t { return reinterpret_cast<intptr_t>(al.getTurbineBladeForcesZDevice(turbine)); }, py::arg("turbine") ) + + .def("set_all_azimuths", [](ActuatorFarm& al, arr azimuths){ al.setAllAzimuths(static_cast<float *>(azimuths.request().ptr)); }, py::arg("azimuths")) + .def("set_all_yaws", [](ActuatorFarm& al, arr yaws){ al.setAllYaws(static_cast<float *>(yaws.request().ptr)); }, py::arg("yaws")) + .def("set_all_omegas", [](ActuatorFarm& al, arr omegas){ al.setAllOmegas(static_cast<float *>(omegas.request().ptr)); }, py::arg("omegas")) + + .def("set_turbine_azimuth", &ActuatorFarm::setTurbineAzimuth, py::arg("turbine"), py::arg("azimuth")) + .def("set_turbine_yaw", &ActuatorFarm::setTurbineYaw, py::arg("turbine"), py::arg("yaw")) + .def("set_turbine_omega", &ActuatorFarm::setTurbineOmega, py::arg("turbine"), py::arg("omega")) + + .def("set_all_blade_coords", [](ActuatorFarm& al, arr coordsX, arr coordsY, arr coordsZ) + { + al.setAllBladeCoords(static_cast<float *>(coordsX.request().ptr), static_cast<float *>(coordsY.request().ptr), static_cast<float *>(coordsZ.request().ptr)); + }, py::arg("blade_coords_x"), py::arg("blade_coords_y"), py::arg("blade_coords_z") ) + .def("set_all_blade_velocities", [](ActuatorFarm& al, arr velocitiesX, arr velocitiesY, arr velocitiesZ) + { + al.setAllBladeVelocities(static_cast<float *>(velocitiesX.request().ptr), static_cast<float *>(velocitiesY.request().ptr), static_cast<float *>(velocitiesZ.request().ptr)); + }, py::arg("blade_velocities_x"), py::arg("blade_velocities_y"), py::arg("blade_velocities_z") ) + .def("set_all_blade_forces", [](ActuatorFarm& al, arr forcesX, arr forcesY, arr forcesZ) + { + al.setAllBladeForces(static_cast<float *>(forcesX.request().ptr), static_cast<float *>(forcesY.request().ptr), static_cast<float *>(forcesZ.request().ptr)); + }, py::arg("blade_forces_x"), py::arg("blade_forces_y"), py::arg("blade_forces_z") ) + .def("set_turbine_blade_coords", [](ActuatorFarm& al, uint turbine, arr coordsX, arr coordsY, arr coordsZ) + { + al.setTurbineBladeCoords(turbine, static_cast<float *>(coordsX.request().ptr), static_cast<float *>(coordsY.request().ptr), static_cast<float *>(coordsZ.request().ptr)); + }, py::arg("turbine"), py::arg("blade_coords_x"), py::arg("blade_coords_y"), py::arg("blade_coords_z") ) + .def("set_turbine_blade_velocities", [](ActuatorFarm& al, uint turbine, arr velocitiesX, arr velocitiesY, arr velocitiesZ) + { + al.setTurbineBladeVelocities(turbine, static_cast<float *>(velocitiesX.request().ptr), static_cast<float *>(velocitiesY.request().ptr), static_cast<float *>(velocitiesZ.request().ptr)); + }, py::arg("turbine"), py::arg("blade_velocities_x"), py::arg("blade_velocities_y"), py::arg("blade_velocities_z") ) + .def("set_turbine_blade_forces", [](ActuatorFarm& al, uint turbine, arr forcesX, arr forcesY, arr forcesZ) + { + al.setTurbineBladeForces(turbine, static_cast<float *>(forcesX.request().ptr), static_cast<float *>(forcesY.request().ptr), static_cast<float *>(forcesZ.request().ptr)); + }, py::arg("turbine"), py::arg("blade_forces_x"), py::arg("blade_forces_y"), py::arg("blade_forces_z") ) + .def("calc_blade_forces", &ActuatorFarm::calcBladeForces); + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/actuator_line.cpp b/pythonbindings/src/gpu/submodules/actuator_line.cpp deleted file mode 100644 index 3207fadbc37df38e53e00adcb9a86f0b8e82ba98..0000000000000000000000000000000000000000 --- a/pythonbindings/src/gpu/submodules/actuator_line.cpp +++ /dev/null @@ -1,72 +0,0 @@ -#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::setAzimuth) - .def_property("yaw", &ActuatorLine::getYaw, &ActuatorLine::setYaw) - .def_property_readonly("n_blades", &ActuatorLine::getNBlades) - .def_property_readonly("n_blade_nodes", &ActuatorLine::getNBladeNodes) - .def_property_readonly("n_nodes", &ActuatorLine::getNNodes) - .def_property_readonly("n_indices", &ActuatorLine::getNIndices) - .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 index 8f941a8705c225275d25291205ebdaeef8de5c9e..865817bb16f7b164c40bdc066645fb2e1f1c842e 100644 --- a/pythonbindings/src/gpu/submodules/boundary_conditions.cpp +++ b/pythonbindings/src/gpu/submodules/boundary_conditions.cpp @@ -1,5 +1,38 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file boindary_conditions.cpp +//! \ingroup submodules +//! \author Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include <gpu/GridGenerator/grid/BoundaryConditions/Side.h> +#include "gpu/VirtualFluids_GPU/Factories/BoundaryConditionFactory.h" namespace boundary_conditions { @@ -14,7 +47,59 @@ namespace boundary_conditions .value("PY", SideType::PY) .value("MZ", SideType::MZ) .value("PZ", SideType::PZ) - .value("GEOMETRY", SideType::GEOMETRY) - .export_values(); + .value("GEOMETRY", SideType::GEOMETRY); + + py::class_<BoundaryConditionFactory>(parentModule, "BoundaryConditionFactory") + .def(py::init<>()) + .def("set_velocity_boundary_condition", &BoundaryConditionFactory::setVelocityBoundaryCondition, py::arg("boundary_condition_type")) + .def("set_no_slip_boundary_condition", &BoundaryConditionFactory::setNoSlipBoundaryCondition, py::arg("boundary_condition_type")) + .def("set_slip_boundary_condition", &BoundaryConditionFactory::setSlipBoundaryCondition, py::arg("boundary_condition_type")) + .def("set_pressure_boundary_condition", &BoundaryConditionFactory::setPressureBoundaryCondition, py::arg("boundary_condition_type")) + .def("set_stress_boundary_condition", &BoundaryConditionFactory::setStressBoundaryCondition, py::arg("boundary_condition_type")) + .def("set_precursor_boundary_condition", &BoundaryConditionFactory::setPrecursorBoundaryCondition, py::arg("boundary_condition_type")) + .def("set_geometry_boundary_condition", &BoundaryConditionFactory::setGeometryBoundaryCondition, py::arg("boundary_condition_type")); + + py::enum_<BoundaryConditionFactory::VelocityBC>(parentModule, "VelocityBC") + .value("VelocitySimpleBounceBackCompressible", BoundaryConditionFactory::VelocityBC::VelocitySimpleBounceBackCompressible) + .value("VelocityIncompressible", BoundaryConditionFactory::VelocityBC::VelocityIncompressible) + .value("VelocityCompressible", BoundaryConditionFactory::VelocityBC::VelocityCompressible) + .value("VelocityAndPressureCompressible", BoundaryConditionFactory::VelocityBC::VelocityAndPressureCompressible) + .value("NotSpecified", BoundaryConditionFactory::VelocityBC::NotSpecified); + + + py::enum_<BoundaryConditionFactory::NoSlipBC>(parentModule, "NoSlipBC") + .value("NoSlipImplicitBounceBack", BoundaryConditionFactory::NoSlipBC::NoSlipImplicitBounceBack) + .value("NoSlipBounceBack", BoundaryConditionFactory::NoSlipBC::NoSlipBounceBack) + .value("NoSlipIncompressible", BoundaryConditionFactory::NoSlipBC::NoSlipIncompressible) + .value("NoSlipCompressible", BoundaryConditionFactory::NoSlipBC::NoSlipCompressible) + .value("NoSlip3rdMomentsCompressible", BoundaryConditionFactory::NoSlipBC::NoSlip3rdMomentsCompressible); + + py::enum_<BoundaryConditionFactory::SlipBC>(parentModule, "SlipBC") + .value("SlipIncompressible", BoundaryConditionFactory::SlipBC::SlipIncompressible) + .value("SlipCompressible", BoundaryConditionFactory::SlipBC::SlipCompressible) + .value("SlipBounceBack", BoundaryConditionFactory::SlipBC::SlipBounceBack) + .value("SlipCompressibleTurbulentViscosity", BoundaryConditionFactory::SlipBC::SlipCompressibleTurbulentViscosity) + .value("SlipPressureCompressibleTurbulentViscosity", BoundaryConditionFactory::SlipBC::SlipPressureCompressibleTurbulentViscosity) + .value("NotSpecified", BoundaryConditionFactory::SlipBC::NotSpecified); + + py::enum_<BoundaryConditionFactory::PressureBC>(parentModule, "PressureBC") + .value("PressureEquilibrium", BoundaryConditionFactory::PressureBC::PressureEquilibrium) + .value("PressureEquilibrium2", BoundaryConditionFactory::PressureBC::PressureEquilibrium2) + .value("PressureNonEquilibriumIncompressible", BoundaryConditionFactory::PressureBC::PressureNonEquilibriumIncompressible) + .value("PressureNonEquilibriumCompressible", BoundaryConditionFactory::PressureBC::PressureNonEquilibriumCompressible) + .value("OutflowNonReflective", BoundaryConditionFactory::PressureBC::OutflowNonReflective) + .value("OutflowNonReflectivePressureCorrection", BoundaryConditionFactory::PressureBC::OutflowNonReflectivePressureCorrection) + .value("NotSpecified", BoundaryConditionFactory::PressureBC::NotSpecified); + + py::enum_<BoundaryConditionFactory::StressBC>(parentModule, "StressBC") + .value("StressCompressible", BoundaryConditionFactory::StressBC::StressCompressible) + .value("StressBounceBack", BoundaryConditionFactory::StressBC::StressBounceBack) + .value("StressPressureBounceBack", BoundaryConditionFactory::StressBC::StressPressureBounceBack) + .value("NotSpecified", BoundaryConditionFactory::StressBC::NotSpecified); + + py::enum_<BoundaryConditionFactory::PrecursorBC>(parentModule, "PrecursorBC") + .value("VelocityPrecursor", BoundaryConditionFactory::PrecursorBC::VelocityPrecursor) + .value("DistributionsPrecursor", BoundaryConditionFactory::PrecursorBC::DistributionsPrecursor) + .value("NotSpecified", BoundaryConditionFactory::PrecursorBC::NotSpecified); } } \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/communicator.cpp b/pythonbindings/src/gpu/submodules/communicator.cpp index edb36e2c2f774903590a16a0b406c721662827b1..26a57061933fbdbfe3447ec89eeb07116a9b974b 100644 --- a/pythonbindings/src/gpu/submodules/communicator.cpp +++ b/pythonbindings/src/gpu/submodules/communicator.cpp @@ -1,3 +1,35 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file communicator.cpp +//! \ingroup submodules +//! \author Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include <gpu/VirtualFluids_GPU/Communication/Communicator.h> @@ -8,7 +40,7 @@ namespace communicator 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_static("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); } diff --git a/pythonbindings/src/gpu/submodules/cuda_memory_manager.cpp b/pythonbindings/src/gpu/submodules/cuda_memory_manager.cpp index bf27080cb3cd050343ba42b0571827ed58870cfd..bbff4832cb73f47e3d1a5a6abd78e21da2473deb 100644 --- a/pythonbindings/src/gpu/submodules/cuda_memory_manager.cpp +++ b/pythonbindings/src/gpu/submodules/cuda_memory_manager.cpp @@ -1,3 +1,35 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file cuda_memory_manager.cpp +//! \ingroup submodules +//! \author Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include <gpu/VirtualFluids_GPU/GPU/CudaMemoryManager.h> #include <gpu/VirtualFluids_GPU/Parameter/Parameter.h> @@ -10,6 +42,6 @@ namespace cuda_memory_manager void makeModule(py::module_ &parentModule) { py::class_<CudaMemoryManager, std::shared_ptr<CudaMemoryManager>>(parentModule, "CudaMemoryManager") - .def(py::init<std::shared_ptr<Parameter>>(), "parameter"); + .def(py::init<std::shared_ptr<Parameter>>(), py::arg("parameter")); } } \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/grid_generator.cpp b/pythonbindings/src/gpu/submodules/grid_generator.cpp index 579c06c4e00cae9646ced8b554d71631eeb7e793..3e9fb5655e26ffa6053a205da5a3e3f0f2ecd49f 100644 --- a/pythonbindings/src/gpu/submodules/grid_generator.cpp +++ b/pythonbindings/src/gpu/submodules/grid_generator.cpp @@ -1,4 +1,37 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file grid_generator.cpp +//! \ingroup submodules +//! \author Henry Korb, Henrik Asmuth +//======================================================================================= #include <pybind11/pybind11.h> +#include "gpu/GridGenerator/utilities/communication.h" #include "gpu/GridGenerator/geometries/Object.h" #include "gpu/GridGenerator/geometries/BoundingBox/BoundingBox.h" #include "gpu/GridGenerator/geometries/Conglomerate/Conglomerate.h" @@ -17,51 +50,63 @@ namespace grid_generator { py::module gridGeneratorModule = parentModule.def_submodule("grid_generator"); + //TODO: + // py::enum_<CommunicationDirections>(gridGeneratorModule, "CommunicationDirections") + // .value("MX", CommunicationDirections::MX) + // .value("PX", CommunicationDirections::PX) + // .value("MY", CommunicationDirections::MY) + // .value("PY", CommunicationDirections::PY) + // .value("MZ", CommunicationDirections::MZ) + // .value("PZ", CommunicationDirections::PZ); + py::class_<GridFactory, std::shared_ptr<GridFactory>>(gridGeneratorModule, "GridFactory") - .def("make", &GridFactory::make, py::return_value_policy::reference); + .def_static("make", &GridFactory::make, py::return_value_policy::reference); - py::class_<BoundingBox>(gridGeneratorModule, "BoundingBox") - .def(py::init<real, real, real, real, real, real>(),"min_x","max_x","min_y","max_y","min_z","max_z"); + py::class_<BoundingBox, std::shared_ptr<BoundingBox>>(gridGeneratorModule, "BoundingBox") + .def(py::init<real, real, real, real, real, real>(), py::arg("min_x"), py::arg("max_x"), py::arg("min_y"), py::arg("max_y"), py::arg("min_z"), py::arg("max_z")); py::class_<Object, std::shared_ptr<Object>>(gridGeneratorModule, "Object"); py::class_<Conglomerate, Object, std::shared_ptr<Conglomerate>>(gridGeneratorModule, "Conglomerate") - .def("make_shared", &Conglomerate::makeShared, py::return_value_policy::reference) - .def("add", &Conglomerate::add) - .def("subtract", &Conglomerate::subtract); + .def_static("make_shared", &Conglomerate::makeShared, py::return_value_policy::reference) + .def("add", &Conglomerate::add, py::arg("object")) + .def("subtract", &Conglomerate::subtract, py::arg("object")); py::class_<Cuboid, Object, std::shared_ptr<Cuboid>>(gridGeneratorModule, "Cuboid") .def(py::init<const double&, const double&, const double&, const double&, const double&, const double&>(), - "min_x1", "min_x2", "min_x3", "max_x1", "max_x2", "max_x3"); + py::arg("min_x1"), py::arg("min_x2"), py::arg("min_x3"), py::arg("max_x1"), py::arg("max_x2"), py::arg("max_x3")); py::class_<Sphere, Object, std::shared_ptr<Sphere>>(gridGeneratorModule, "Sphere") - .def("make_shared", &Sphere::makeShared, py::return_value_policy::reference); + .def_static("make_shared", &Sphere::makeShared, py::return_value_policy::reference); py::class_<TriangularMesh, Object, std::shared_ptr<TriangularMesh>>(gridGeneratorModule, "TriangularMesh") - .def("make", &TriangularMesh::make, py::return_value_policy::reference); + .def_static("make", &TriangularMesh::make, py::return_value_policy::reference); py::class_<GridBuilder, std::shared_ptr<GridBuilder>>(gridGeneratorModule, "GridBuilder") - .def("get_number_of_grid_levels", &GridBuilder::getNumberOfGridLevels) - .def("get_grid", &GridBuilder::getGrid); + .def("get_number_of_grid_levels", &GridBuilder::getNumberOfGridLevels); py::class_<LevelGridBuilder, GridBuilder, std::shared_ptr<LevelGridBuilder>>(gridGeneratorModule, "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) - .def("set_stress_boundary_condition", &LevelGridBuilder::setStressBoundaryCondition); + .def("set_slip_boundary_condition", &LevelGridBuilder::setSlipBoundaryCondition, py::arg("side_type"), py::arg("normal_x"), py::arg("normal_y"), py::arg("normal_z")) + .def("set_velocity_boundary_condition", &LevelGridBuilder::setVelocityBoundaryCondition, py::arg("side_type"), py::arg("vx"), py::arg("vy"), py::arg("vz")) + .def("set_pressure_boundary_condition", &LevelGridBuilder::setPressureBoundaryCondition, py::arg("side_type"), py::arg("rho")) + .def("set_periodic_boundary_condition", &LevelGridBuilder::setPeriodicBoundaryCondition, py::arg("periodic_x"), py::arg("periodic_y"), py::arg("periodic_z")) + .def("set_no_slip_boundary_condition", &LevelGridBuilder::setNoSlipBoundaryCondition, py::arg("side_type")) + .def("set_precursor_boundary_condition", &LevelGridBuilder::setPrecursorBoundaryCondition, py::arg("side_type"), py::arg("file_collection"), py::arg("n_t_read"), py::arg("velocity_x")=0.0f, py::arg("velocity_y")=0.0f, py::arg("velocity_z")=0.0f, py::arg("file_level_to_grid_level_map")=std::vector<uint>()) + .def("set_stress_boundary_condition", &LevelGridBuilder::setStressBoundaryCondition, py::arg("side_type"), py::arg("normal_x"), py::arg("normal_y"), py::arg("normal_z"), py::arg("sampling_offset"), py::arg("z0"), py::arg("dx")); py::class_<MultipleGridBuilder, LevelGridBuilder, std::shared_ptr<MultipleGridBuilder>>(gridGeneratorModule, "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_static("make_shared", &MultipleGridBuilder::makeShared, py::return_value_policy::reference, py::arg("grid_factory")) + .def("add_coarse_grid", &MultipleGridBuilder::addCoarseGrid, py::arg("start_x"), py::arg("start_y"), py::arg("start_z"), py::arg("end_x"), py::arg("end_y"), py::arg("end_z"), py::arg("delta")) + .def("add_grid", py::overload_cast<Object*>(&MultipleGridBuilder::addGrid), py::arg("grid_shape")) + .def("add_grid", py::overload_cast<Object*, uint>(&MultipleGridBuilder::addGrid), py::arg("grid_shape"), py::arg("level_fine")) + .def("add_geometry", py::overload_cast<Object*>(&MultipleGridBuilder::addGeometry), py::arg("solid_object")) + .def("add_geometry", py::overload_cast<Object*, uint>(&MultipleGridBuilder::addGeometry), py::arg("solid_object"), py::arg("level")) .def("get_number_of_levels", &MultipleGridBuilder::getNumberOfLevels) - .def("build_grids", &MultipleGridBuilder::buildGrids); + .def("build_grids", &MultipleGridBuilder::buildGrids, py::arg("lbm_or_gks"), py::arg("enable_thin_walls")) + .def("set_subdomain_box", &MultipleGridBuilder::setSubDomainBox, py::arg("bounding_box")) + .def("find_communication_indices", &MultipleGridBuilder::findCommunicationIndices) + .def("set_communication_process", &MultipleGridBuilder::setCommunicationProcess) + .def("set_number_of_layers", &MultipleGridBuilder::setNumberOfLayers, py::arg("number_of_layers_fine"), py::arg("number_of_layers_between_levels")); return gridGeneratorModule; } diff --git a/pythonbindings/src/gpu/submodules/grid_provider.cpp b/pythonbindings/src/gpu/submodules/grid_provider.cpp index 02ff273e2cd1a2022943e19c9a48a447d9dfe54b..717e9d5cd82100636a5398c09662a0895ce8fb56 100644 --- a/pythonbindings/src/gpu/submodules/grid_provider.cpp +++ b/pythonbindings/src/gpu/submodules/grid_provider.cpp @@ -1,8 +1,36 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file grid_provider +//! \author Henry Korb +//======================================================================================= #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 { @@ -11,6 +39,6 @@ namespace grid_provider 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); + .def_static("make_grid_generator", &GridProvider::makeGridGenerator, py::return_value_policy::reference, py::arg("builder"), py::arg("para"), py::arg("cuda_memory_manager"), py::arg("communicator")); } } \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/grid_scaling_factory.cpp b/pythonbindings/src/gpu/submodules/grid_scaling_factory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a3a572875a4695871c482a4308acab4214dbb481 --- /dev/null +++ b/pythonbindings/src/gpu/submodules/grid_scaling_factory.cpp @@ -0,0 +1,52 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file grid_scaling_factory.cpp +//! \ingroup submodules +//! \author Henry Korb +//======================================================================================= +#include <pybind11/pybind11.h> +#include <gpu/VirtualFluids_GPU/Factories/GridScalingFactory.h> + +namespace grid_scaling_factory +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + + py::class_<GridScalingFactory, std::shared_ptr<GridScalingFactory>>(parentModule, "GridScalingFactory") + .def(py::init<>()) + .def("set_scaling_factory", &GridScalingFactory::setScalingFactory, py::arg("scaling_type")); + + py::enum_<GridScalingFactory::GridScaling>(parentModule, "GridScaling") + .value("ScaleCompressible", GridScalingFactory::GridScaling::ScaleCompressible) + .value("ScaleRhoSq", GridScalingFactory::GridScaling::ScaleRhoSq) + .value("NotSpecified", GridScalingFactory::GridScaling::NotSpecified); + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/parameter.cpp b/pythonbindings/src/gpu/submodules/parameter.cpp index 7b4e67f101e3928abbd4262557864ea1d0f45b02..a7c42223e6a5bfa3caa89c0879e4133fc4123ad0 100644 --- a/pythonbindings/src/gpu/submodules/parameter.cpp +++ b/pythonbindings/src/gpu/submodules/parameter.cpp @@ -1,10 +1,46 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file parameter.cpp +//! \ingroup submodules +//! \author Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include <pybind11/functional.h> #include <pybind11/stl.h> #include <gpu/VirtualFluids_GPU/Parameter/Parameter.h> +#include "lbm/constants/NumericConstants.h" #include <basics/config/ConfigurationFile.h> #include <gpu/VirtualFluids_GPU/PreCollisionInteractor/PreCollisionInteractor.h> + +using namespace vf::lbm::constant; + namespace parameter { namespace py = pybind11; @@ -13,42 +49,44 @@ namespace parameter { 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_use_AMD", &Parameter::setUseAMD) - .def("set_use_Wale", &Parameter::setUseWale) - .def("set_SGS_constant", &Parameter::setSGSConstant) - .def("set_main_kernel", &Parameter::setMainKernel) - .def("set_AD_kernel", &Parameter::setADKernel) - .def("set_use_AMD", &Parameter::setUseAMD) - .def("set_use_Wale", &Parameter::setUseWale) - .def("set_SGS_constant", &Parameter::setSGSConstant) + int, + std::optional<const vf::basics::ConfigurationFile*>>(), + py::arg("number_of_processes"), + py::arg("my_ID"), + py::arg("config_data")) + .def(py::init<int, int>(), + py::arg("number_of_processes"), + py::arg("my_ID")) + .def(py::init<const vf::basics::ConfigurationFile*>(), py::arg("config_data")) + .def("set_forcing", &Parameter::setForcing, py::arg("forcing_x"), py::arg("forcing_y"), py::arg("forcing_z")) + .def("set_quadric_limiters", &Parameter::setQuadricLimiters, py::arg("quadric_limiter_p"), py::arg("quadric_limiter_m"), py::arg("quadric_limiter_d")) + .def("set_diff_on", &Parameter::setDiffOn, py::arg("is_diff")) + .def("set_comp_on", &Parameter::setCompOn, py::arg("is_comp")) + .def("set_max_level", &Parameter::setMaxLevel, py::arg("number_of_levels")) + .def("set_timestep_end", &Parameter::setTimestepEnd, py::arg("tend")) + .def("set_timestep_out", &Parameter::setTimestepOut, py::arg("tout")) + .def("set_timestep_start_out", &Parameter::setTimestepStartOut, py::arg("t_start_out")) + .def("set_timestep_of_coarse_level", &Parameter::setTimestepOfCoarseLevel, py::arg("timestep")) + .def("set_calc_turbulence_intensity", &Parameter::setCalcTurbulenceIntensity, py::arg("calc_velocity_and_fluctuations")) + .def("set_output_path", &Parameter::setOutputPath, py::arg("o_path")) + .def("set_output_prefix", &Parameter::setOutputPrefix, py::arg("o_prefix")) + .def("set_print_files", &Parameter::setPrintFiles, py::arg("print_files")) + .def("set_temperature_init", &Parameter::setTemperatureInit, py::arg("temp")) + .def("set_temperature_BC", &Parameter::setTemperatureBC, py::arg("temp_bc")) + .def("set_viscosity_LB", &Parameter::setViscosityLB, py::arg("viscosity")) + .def("set_velocity_LB", &Parameter::setVelocityLB, py::arg("velocity")) + .def("set_viscosity_ratio", &Parameter::setViscosityRatio, py::arg("viscosity_ratio")) + .def("set_velocity_ratio", &Parameter::setVelocityRatio, py::arg("velocity_ratio")) + .def("set_density_ratio", &Parameter::setDensityRatio, py::arg("density_ratio")) + .def("set_devices", &Parameter::setDevices, py::arg("devices")) + .def("set_max_dev", &Parameter::setMaxDev, py::arg("max_dev")) + .def("set_is_body_force", &Parameter::setIsBodyForce, py::arg("is_body_force")) + .def("set_use_streams", &Parameter::setUseStreams, py::arg("use_streams")) + .def("set_main_kernel", &Parameter::setMainKernel, py::arg("kernel")) + .def("set_AD_kernel", &Parameter::setADKernel, py::arg("ad_kernel")) + .def("set_has_wall_model_monitor", &Parameter::setHasWallModelMonitor, py::arg("has_wall_monitor")) + .def("set_outflow_pressure_correction_factor", &Parameter::setOutflowPressureCorrectionFactor, py::arg("correction_factor")) .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) @@ -59,9 +97,46 @@ namespace parameter vy = values[2]; vz = values[3]; }); - }) - .def("add_actuator", &Parameter::addActuator) - .def("add_probe", &Parameter::addProbe) + }, py::arg("init_func")) + .def("set_initial_condition_uniform", [](Parameter ¶, real velocity_x, real velocity_y, real velocity_z) + { + para.setInitialCondition([velocity_x, velocity_y, velocity_z](real coordX, real coordY, real coordZ, real& rho, real& vx, real& vy, real& vz) // must capture values explicitly! + { + rho = c0o1; + vx = velocity_x; + vy = velocity_y; + vz = velocity_z; + }); + }, py::arg("velocity_x"), py::arg("velocity_y"), py::arg("velocity_z")) + .def("set_initial_condition_log_law", [](Parameter ¶, real u_star, real z0, real velocityRatio) + { + para.setInitialCondition( + [u_star, z0, velocityRatio](real coordX, real coordY, real coordZ, real& rho, real& vx, real& vy, real& vz) + { + coordZ = coordZ > c0o1 ? coordZ : c0o1; + + rho = c0o1; + vx = u_star/c4o10 * log(coordZ/z0+c1o1) / velocityRatio; + vy = c0o1; + vz = c0o1; + } + ); + }, py::arg("u_star"), py::arg("z0"), py::arg("velocity_ratio")) + .def("set_initial_condition_perturbed_log_law", [](Parameter ¶, real u_star, real z0, real L_x, real L_z, real H, real velocityRatio) + { + para.setInitialCondition( + [u_star, z0, L_x, L_z, H, velocityRatio](real coordX, real coordY, real coordZ, real& rho, real& vx, real& vy, real& vz) + { + coordZ = coordZ > c0o1 ? coordZ : c0o1; + rho = c0o1; + vx = (u_star/c4o10 * log(coordZ/z0+c1o1) + c2o1*sin(cPi*c16o1*coordX/L_x)*sin(cPi*c8o1*coordZ/H)/(pow(coordZ/H,c2o1)+c1o1)) / velocityRatio; + vy = c2o1*sin(cPi*c16o1*coordX/L_x)*sin(cPi*c8o1*coordZ/H)/(pow(coordZ/H,c2o1)+c1o1) / velocityRatio; + vz = c8o1*u_star/c4o10*(sin(cPi*c8o1*coordY/H)*sin(cPi*c8o1*coordZ/H)+sin(cPi*c8o1*coordX/L_x))/(pow(c1o2*L_z-coordZ, c2o1)+c1o1) / velocityRatio; + } + ); + }, py::arg("u_star"), py::arg("z0"), py::arg("length_x"), py::arg("length_z"), py::arg("height"), py::arg("velocity_ratio")) + .def("add_actuator", &Parameter::addActuator, py::arg("actuator")) + .def("add_probe", &Parameter::addProbe, py::arg("probe")) .def("get_output_path", &Parameter::getOutputPath) .def("get_output_prefix", &Parameter::getOutputPrefix) .def("get_velocity", &Parameter::getVelocity) @@ -70,11 +145,9 @@ namespace parameter .def("get_viscosity_ratio", &Parameter::getViscosityRatio) .def("get_density_ratio", &Parameter::getDensityRatio) .def("get_force_ratio", &Parameter::getForceRatio) - .def("get_use_AMD", &Parameter::getUseAMD) - .def("get_use_Wale", &Parameter::getUseWale) .def("get_SGS_constant", &Parameter::getSGSConstant) .def("get_is_body_force", &Parameter::getIsBodyForce) - .def("set_has_wall_model_monitor", &Parameter::setHasWallModelMonitor) ; + } } \ 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 index 362ee1a8ce6112cfa9543f1b254e10f3e35822a1..308f6c37aada14c8c25c69245f603274ae2f18d8 100644 --- a/pythonbindings/src/gpu/submodules/pre_collision_interactor.cpp +++ b/pythonbindings/src/gpu/submodules/pre_collision_interactor.cpp @@ -1,3 +1,36 @@ + +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file pre_collision_interactor.cpp +//! \ingroup submodules +//! \author Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include <gpu/VirtualFluids_GPU/PreCollisionInteractor/PreCollisionInteractor.h> diff --git a/pythonbindings/src/gpu/submodules/precursor_writer.cpp b/pythonbindings/src/gpu/submodules/precursor_writer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..64164ef9993d7b4f22bff2390b418718f7c3208f --- /dev/null +++ b/pythonbindings/src/gpu/submodules/precursor_writer.cpp @@ -0,0 +1,67 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file precursor_writer.cpp +//! \ingroup submodules +//! \author Henry Korb +//======================================================================================= +#include <pybind11/pybind11.h> +#include <pybind11/stl.h> +#include <pybind11/numpy.h> +#include <gpu/VirtualFluids_GPU/PreCollisionInteractor/PreCollisionInteractor.h> +#include <gpu/VirtualFluids_GPU/PreCollisionInteractor/PrecursorWriter.h> + +namespace precursor_writer +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::enum_<OutputVariable>(parentModule, "OutputVariable") + .value("Velocities", OutputVariable::Velocities) + .value("Distributions", OutputVariable::Distributions); + + py::class_<PrecursorWriter, PreCollisionInteractor, std::shared_ptr<PrecursorWriter>>(parentModule, "PrecursorWriter") + .def(py::init < std::string, + std::string, + real, + real, real, + real, real, + uint, uint, + OutputVariable, + uint>(), + py::arg("filename"), + py::arg("output_path"), + py::arg("x_pos"), + py::arg("y_min"), py::arg("y_max"), + py::arg("z_min"), py::arg("z_max"), + py::arg("t_start_out"), py::arg("t_save"), + py::arg("output_variable"), + py::arg("max_timesteps_per_file")); + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/probes.cpp b/pythonbindings/src/gpu/submodules/probes.cpp index 6993d9617d870922d7ed90ed9ecbebb8a797be25..7c26958df81a60f00c9909a91f5576a5931652d4 100644 --- a/pythonbindings/src/gpu/submodules/probes.cpp +++ b/pythonbindings/src/gpu/submodules/probes.cpp @@ -1,3 +1,35 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file probes.cpp +//! \ingroup submodules +//! \author Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include <pybind11/stl.h> #include <gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/Probe.h> @@ -29,7 +61,7 @@ namespace probes .value("SpatioTemporalFlatness", Statistic::SpatioTemporalFlatness); py::class_<Probe, PreCollisionInteractor, std::shared_ptr<Probe>>(probeModule, "Probe") - .def("add_statistic", &Probe::addStatistic) + .def("add_statistic", &Probe::addStatistic, py::arg("variable")) .def("set_file_name_to_n_out", &Probe::setFileNameToNOut) .def("add_all_available_statistics", &Probe::addAllAvailableStatistics); @@ -41,14 +73,14 @@ namespace probes uint, uint, uint>(), - "probe_name", - "output_path" - "t_start_avg", - "t_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::arg("probe_name"), + py::arg("output_path"), + py::arg("t_start_avg"), + py::arg("t_avg"), + py::arg("t_start_out"), + py::arg("t_out")) + .def("add_probe_points_from_list", &PointProbe::addProbePointsFromList, py::arg("point_coords_x"), py::arg("point_coords_y"), py::arg("point_coords_z")) + .def("add_probe_points_from_x_normal_plane", &PointProbe::addProbePointsFromXNormalPlane, py::arg("pos_x"), py::arg("pos0_y"), py::arg("pos0_z"), py::arg("pos1_y"), py::arg("pos1_z"), py::arg("n_y"), py::arg("n_z")); py::class_<PlaneProbe, Probe, std::shared_ptr<PlaneProbe>>(probeModule, "PlaneProbe") .def(py::init< @@ -58,13 +90,13 @@ namespace probes uint, uint, uint>(), - "probe_name", - "output_path" - "t_start_avg", - "t_avg", - "t_start_out", - "t_out") - .def("set_probe_plane", &PlaneProbe::setProbePlane); + py::arg("probe_name"), + py::arg("output_path"), + py::arg("t_start_avg"), + py::arg("t_avg"), + py::arg("t_start_out"), + py::arg("t_out")) + .def("set_probe_plane", &PlaneProbe::setProbePlane, py::arg("pos_x"), py::arg("pos_y"), py::arg("pos_z"), py::arg("delta_x"), py::arg("delta_y"), py::arg("delta_z")); py::class_<PlanarAverageProbe, Probe, std::shared_ptr<PlanarAverageProbe>>(probeModule, "PlanarAverageProbe") .def(py::init< @@ -76,14 +108,14 @@ namespace probes uint, uint, char>(), - "probe_name", - "output_path", - "t_start_avg", - "t_start_tmp_avg", - "t_avg", - "t_start_out", - "t_out", - "plane_normal"); + py::arg("probe_name"), + py::arg("output_path"), + py::arg("t_start_avg"), + py::arg("t_start_tmp_avg"), + py::arg("t_avg"), + py::arg("t_start_out"), + py::arg("t_out"), + py::arg("plane_normal")); py::class_<WallModelProbe, Probe, std::shared_ptr<WallModelProbe>>(probeModule, "WallModelProbe") @@ -95,15 +127,15 @@ namespace probes uint, uint, uint>(), - "probe_name", - "output_path" - "t_start_avg", - "t_start_tmp_avg", - "t_avg", - "t_start_out", - "t_out") - .def("set_force_output_to_stress", &WallModelProbe::setForceOutputToStress) - .def("set_evaluate_pressure_gradient", &WallModelProbe::setEvaluatePressureGradient); + py::arg("probe_name"), + py::arg("output_path"), + py::arg("t_start_avg"), + py::arg("t_start_tmp_avg"), + py::arg("t_avg"), + py::arg("t_start_out"), + py::arg("t_out")) + .def("set_force_output_to_stress", &WallModelProbe::setForceOutputToStress, py::arg("output_stress")) + .def("set_evaluate_pressure_gradient", &WallModelProbe::setEvaluatePressureGradient, py::arg("eval_press_grad")); return probeModule; } diff --git a/pythonbindings/src/gpu/submodules/simulation.cpp b/pythonbindings/src/gpu/submodules/simulation.cpp index b775d604ba41530223f22738c72785b2c15348b3..d32ef272a1fd26510439dde6ab3a9438d68009a7 100644 --- a/pythonbindings/src/gpu/submodules/simulation.cpp +++ b/pythonbindings/src/gpu/submodules/simulation.cpp @@ -1,3 +1,35 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file simulation.cpp +//! \ingroup submodules +//! \author Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include <gpu/VirtualFluids_GPU/LBM/Simulation.h> #include <gpu/VirtualFluids_GPU/Communication/Communicator.h> @@ -8,6 +40,9 @@ #include <gpu/VirtualFluids_GPU/GPU/CudaMemoryManager.h> #include <gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.h> #include <gpu/VirtualFluids_GPU/Output/DataWriter.h> +#include "gpu/VirtualFluids_GPU/Factories/BoundaryConditionFactory.h" +#include "gpu/VirtualFluids_GPU/TurbulenceModels/TurbulenceModelFactory.h" +#include "gpu/VirtualFluids_GPU/Factories/GridScalingFactory.h" namespace simulation { @@ -20,13 +55,41 @@ namespace simulation .def(py::init< std::shared_ptr<Parameter>, std::shared_ptr<CudaMemoryManager>, vf::gpu::Communicator &, - GridProvider &>(), - "parameter", - "memoryManager", - "communicator", - "gridProvider") + GridProvider &, + BoundaryConditionFactory*, + GridScalingFactory*>(), + py::arg("parameter"), + py::arg("memoryManager"), + py::arg("communicator"), + py::arg("gridProvider"), + py::arg("bcFactory"), + py::arg("gridScalingFactory")) + .def(py::init< std::shared_ptr<Parameter>, + std::shared_ptr<CudaMemoryManager>, + vf::gpu::Communicator &, + GridProvider &, + BoundaryConditionFactory*>(), + py::arg("parameter"), + py::arg("memoryManager"), + py::arg("communicator"), + py::arg("gridProvider"), + py::arg("bcFactory")) + .def(py::init< std::shared_ptr<Parameter>, + std::shared_ptr<CudaMemoryManager>, + vf::gpu::Communicator &, + GridProvider &, + BoundaryConditionFactory*, + std::shared_ptr<TurbulenceModelFactory>, + GridScalingFactory*>(), + py::arg("parameter"), + py::arg("memoryManager"), + py::arg("communicator"), + py::arg("gridProvider"), + py::arg("bcFactory"), + py::arg("tmFactory"), + py::arg("gridScalingFactory")) .def("run", &Simulation::run) - .def("addKineticEnergyAnalyzer", &Simulation::addKineticEnergyAnalyzer) - .def("addEnstrophyAnalyzer", &Simulation::addEnstrophyAnalyzer); + .def("addKineticEnergyAnalyzer", &Simulation::addKineticEnergyAnalyzer, py::arg("t_analyse")) + .def("addEnstrophyAnalyzer", &Simulation::addEnstrophyAnalyzer, py::arg("t_analyse")); } } \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/transient_bc_setter.cpp b/pythonbindings/src/gpu/submodules/transient_bc_setter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..89370ef4c1b91a0c8e480e968a1df3bd4fe540ca --- /dev/null +++ b/pythonbindings/src/gpu/submodules/transient_bc_setter.cpp @@ -0,0 +1,52 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file transient_bc_setter.cpp +//! \ingroup submodules +//! \author Henry Korb +//======================================================================================= +#include <pybind11/pybind11.h> +#include <gpu/GridGenerator/TransientBCSetter/TransientBCSetter.h> + +namespace transient_bc_setter +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::enum_<FileType>(parentModule, "FileType") + .value("VTK", FileType::VTK); + + parentModule.def("create_file_collection", &createFileCollection, py::arg("prefix"), py::arg("type")); + + py::class_<FileCollection, std::shared_ptr<FileCollection>>(parentModule, "FileCollection"); + + py::class_<VTKFileCollection, FileCollection, std::shared_ptr<VTKFileCollection>>(parentModule, "VTKFileCollection") + .def(py::init <std::string>(), py::arg("prefix")); + } +} \ No newline at end of file diff --git a/pythonbindings/src/gpu/submodules/turbulence_models.cpp b/pythonbindings/src/gpu/submodules/turbulence_models.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cfbb9e56127fee0cd90a482dde258d8b96389989 --- /dev/null +++ b/pythonbindings/src/gpu/submodules/turbulence_models.cpp @@ -0,0 +1,56 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file turbulence_models.cpp +//! \ingroup submodules +//! \author Henry Korb +//======================================================================================= +#include "pybind11/pybind11.h" +#include "gpu/VirtualFluids_GPU/TurbulenceModels/TurbulenceModelFactory.h" +#include "gpu/VirtualFluids_GPU/LBM/LB.h" + +namespace turbulence_model +{ + namespace py = pybind11; + + void makeModule(py::module_ &parentModule) + { + py::enum_<TurbulenceModel>(parentModule, "TurbulenceModel") + .value("Smagorinsky", TurbulenceModel::Smagorinsky) + .value("AMD", TurbulenceModel::AMD) + .value("QR", TurbulenceModel::QR) + .value("None", TurbulenceModel::None); + + py::class_<TurbulenceModelFactory, std::shared_ptr<TurbulenceModelFactory>>(parentModule, "TurbulenceModelFactory") + .def(py::init< std::shared_ptr<Parameter>>(), py::arg("para")) + .def("set_turbulence_model", &TurbulenceModelFactory::setTurbulenceModel, py::arg("turbulence_model")) + .def("set_model_constant", &TurbulenceModelFactory::setModelConstant, py::arg("model_constant")) + .def("read_config_file", &TurbulenceModelFactory::readConfigFile, py::arg("config_data")); + + } +} \ No newline at end of file diff --git a/pythonbindings/src/lbm/lbm.cpp b/pythonbindings/src/lbm/lbm.cpp index 441b9ff372f4e4513fee58c4a8a1cd78d38582dd..90fd4a71b0101469666936c89974de316e0e2b18 100644 --- a/pythonbindings/src/lbm/lbm.cpp +++ b/pythonbindings/src/lbm/lbm.cpp @@ -1,3 +1,35 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file lbm.cpp +//! \ingroup lbm +//! \author Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> namespace lbm diff --git a/pythonbindings/src/logger/logger.cpp b/pythonbindings/src/logger/logger.cpp index 82ad3d92760ae38c0eb62b16be726e4eeaca08ac..555b502fa9a56299895de0fa6dd6cfeb66c15024 100644 --- a/pythonbindings/src/logger/logger.cpp +++ b/pythonbindings/src/logger/logger.cpp @@ -1,3 +1,35 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file logging.cpp +//! \ingroup logger +//! \author Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include <logger/Logger.h> @@ -10,15 +42,15 @@ namespace logging 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); + .def_static("initialize_logger", &vf::logging::Logger::initalizeLogger) + .def_static("change_log_path", &vf::logging::Logger::changeLogPath, py::arg("path")); // 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); }); + loggerModule.def("vf_log_trace", [](std::string message){ VF_LOG_TRACE(message); }, py::arg("message")); + loggerModule.def("vf_log_debug", [](std::string message){ VF_LOG_DEBUG(message); }, py::arg("message")); + loggerModule.def("vf_log_info", [](std::string message){ VF_LOG_INFO(message); }, py::arg("message")); + loggerModule.def("vf_log_warning", [](std::string message){ VF_LOG_WARNING(message); }, py::arg("message")); + loggerModule.def("vf_log_critical", [](std::string message){ VF_LOG_CRITICAL(message); }, py::arg("message")); return loggerModule; } diff --git a/pythonbindings/src/muParser.cpp b/pythonbindings/src/muParser.cpp index 47408c2758fc92991f1be3113d78b8741215b152..eec39de0b72c21aaa924ea805414847aa9de4492 100644 --- a/pythonbindings/src/muParser.cpp +++ b/pythonbindings/src/muParser.cpp @@ -1,9 +1,41 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file muParser.cpp +//! \ingroup src +//! \author Henry Korb +//======================================================================================= #include <pybind11/pybind11.h> #include <muParser.h> namespace py = pybind11; -PYBIND11_MODULE(pymuparser, m) { +PYBIND11_MODULE(bindings, m) { py::class_<mu::ParserBase>(m, "_ParserBase"); py::class_<mu::Parser, mu::ParserBase>(m, "Parser") diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000000000000000000000000000000000000..f3bc36f29efe64b81916efa04b9d7831a2abeb09 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,11 @@ +[metadata] +name = pyfluids +description = Python binding for VirtualFluids +long_description = file: README.md +long_description_content_type = text/markdown +platforms = any +url = https://git.rz.tu-bs.de/irmb/virtualfluids +version = 0.0.1 + +[options] +python_requires = >=3.6 diff --git a/setup.py b/setup.py index b26e1c13d09447d17f8e9fd6e2cd0d0671595bf3..530431b3775970b5222bc87d32bfb407363f95d6 100644 --- a/setup.py +++ b/setup.py @@ -1,137 +1,72 @@ -import os -import re import sys -import platform -import subprocess +from pathlib import Path +from typing import List -from setuptools import setup, Extension -from setuptools.command.build_ext import build_ext -from setuptools.command.install import install -from setuptools.command.develop import develop -from distutils.version import LooseVersion +import skbuild """ -Install python wrapper of virtual fluids -Install GPU backend with option --GPU -(pass to pip via --install-option="--GPU") +Install python wrapper of Virtual Fluids +install via python: + python setup.py install + set CMAKE Flags via -DBUILD_VF_GPU:BOOL=ON + CMAKE flags have to be separated by -- + example: python setup.py install -- -DBUILD_VF_CPU:BOOL=ON +or install via pip: + pip install . + for pip>21: + set CMAKE Flags via --config-settings "-DBUILD_VF_GPU=ON" + example: pip install . --config-settings="-DBUILD_VF_GPU=ON" + each option has to be passed in individually i.e --config-settings="-DOPT1=ON" --config-settings="-DOPT2=OFF" + for pip <21: + set CMAKE Flags via --global-option ="-DBUILD_VF_GPU=ON" + example: pip install . --global-option="-DBUILD_VF_GPU=ON" """ -vf_cmake_args = [ - "-DBUILD_VF_PYTHON_BINDINGS=ON", - "-DCMAKE_CXX_COMPILER_LAUNCHER=ccache", - "-DCMAKE_CUDA_COMPILER_LAUNCHER=ccache", - "-DCMAKE_C_COMPILER_LAUNCHER=ccache", - "-DBUILD_SHARED_LIBS=OFF", - "-DBUILD_WARNINGS_AS_ERRORS=OFF" -] - -vf_cpu_cmake_args = [ - "-DBUILD_VF_DOUBLE_ACCURACY=ON", - "-DBUILD_VF_CPU:BOOL=ON", - "-DBUILD_VF_UNIT_TESTS:BOOL=ON", - "-DUSE_METIS=ON", - "-DUSE_MPI=ON" -] - -vf_gpu_cmake_args = [ - "-DBUILD_VF_DOUBLE_ACCURACY=OFF", - "-DBUILD_VF_GPU:BOOL=ON", - "-DBUILD_VF_UNIT_TESTS:BOOL=OFF", -] - -GPU = False - -class CommandMixin: - user_options = [ - ('GPU', None, 'compile pyfluids with GPU backend'), +package_name = "pyfluids" +target = "python_bindings" +src_dir = "pythonbindings" +stub_package = package_name+"-stubs" + +stub_dir = Path(src_dir)/stub_package + + +def add_subfiles(dir_path: Path, suffix: str, root_dir: Path) -> List[str]: + files = [] + for f in dir_path.iterdir(): + if f.is_dir(): + files.extend(add_subfiles(f, suffix, root_dir)) + if f.is_file(): + if f.suffix != suffix: + continue + files.append(str(f.relative_to(root_dir))) + return files + +def add_directory(dir_path: Path, suffix: str): + return add_subfiles(dir_path, suffix, dir_path) + +stub_files = add_directory(stub_dir, ".pyi") + +# hack to get config-args for installation with pip>21 +cmake_args = [] +if "config_args" in locals(): + cmake_args.extend([f"{k}={v}" for k, v in locals()["config_args"].items()]) + +cmake_args += [ + f"-DPython3_ROOT_DIR={Path(sys.prefix)}", + "-DBUILD_VF_PYTHON_BINDINGS=ON", + "-DBUILD_SHARED_LIBS=OFF", + "-DBUILD_VF_DOUBLE_ACCURACY=OFF", + "-DBUILD_VF_UNIT_TESTS:BOOL=OFF", + "-DBUILD_WARNINGS_AS_ERRORS=OFF", ] - def initialize_options(self): - super().initialize_options() - self.GPU = False - - def finalize_options(self): - super().finalize_options() - - def run(self): - global GPU - GPU = GPU or self.GPU - super().run() - - -class InstallCommand(CommandMixin, install): - user_options = getattr(install, 'user_options', []) + CommandMixin.user_options - - -class DevelopCommand(CommandMixin, develop): - user_options = getattr(develop, 'user_options', []) + CommandMixin.user_options - - -class CMakeExtension(Extension): - def __init__(self, name, sourcedir=''): - Extension.__init__(self, name, sources=[]) - self.sourcedir = os.path.abspath(sourcedir) - - -class CMakeBuild(CommandMixin, build_ext): - user_options = getattr(build_ext, 'user_options', []) + CommandMixin.user_options - - def run(self): - super().run() - try: - out = subprocess.check_output(['cmake', '--version']) - except OSError: - raise RuntimeError("CMake must be installed to build the following extensions: " + - ", ".join(e.name for e in self.extensions)) - - if platform.system() == "Windows": - cmake_version = LooseVersion(re.search(r'version\s*([\d.]+)', out.decode()).group(1)) - if cmake_version < '3.1.0': - raise RuntimeError("CMake >= 3.1.0 is required on Windows") - - for ext in self.extensions: - self.build_extension(ext) - - def build_extension(self, ext): - extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) - # required for auto-detection of auxiliary "native" libs - if not extdir.endswith(os.path.sep): - extdir += os.path.sep - - cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, - '-DPYTHON_EXECUTABLE=' + sys.executable] - - cfg = 'Debug' if self.debug else 'Release' - build_args = ['--config', cfg] - - if platform.system() == "Windows": - cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir)] - if sys.maxsize > 2**32: - cmake_args += ['-A', 'x64'] - build_args += ['--', '/m'] - else: - cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] - build_args += ['--', '-j2'] - - cmake_args.extend(vf_cmake_args) - cmake_args.extend(vf_gpu_cmake_args if GPU else vf_cpu_cmake_args) - - env = os.environ.copy() - env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''), - self.distribution.get_version()) - if not os.path.exists(self.build_temp): - os.makedirs(self.build_temp) - cmake_cache_file = self.build_temp+"/CMakeCache.txt" - if os.path.exists(cmake_cache_file): - os.remove(cmake_cache_file) - subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env) - subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp) - - -setup( - name='pyfluids', - version='0.0.1', - ext_modules=[CMakeExtension('pyfluids')], - cmdclass={"install": InstallCommand, "develop": DevelopCommand, "build_ext": CMakeBuild}, - zip_safe=False, +skbuild.setup( + name=package_name, + packages=[package_name, "pymuparser", "pyfluids-stubs"], + package_dir={"": src_dir}, + cmake_args=cmake_args, + cmake_install_target=target, + package_data={ "pyfluids": ["py.typed"], + "pyfluids-stubs": stub_files}, + include_package_data=True, ) diff --git a/src/basics/basics/utilities/UbTuple.h b/src/basics/basics/utilities/UbTuple.h index fe9c787cead38621beafab3d082122277bdcff73..228ab48898e5e61777d2fcc0061eb6f0434d5cad 100644 --- a/src/basics/basics/utilities/UbTuple.h +++ b/src/basics/basics/utilities/UbTuple.h @@ -597,6 +597,8 @@ inline UbTuple<T1, T2, T3, T4, T5, T6, T7, T8> makeUbTuple(T1 const &a1, T2 cons // some typedefs using UbTupleFloat2 = UbTuple<float, float>; using UbTupleFloat3 = UbTuple<float, float, float>; +using UbTupleFloat4 = UbTuple<float, float, float, float>; +using UbTupleFloat6 = UbTuple<float, float, float,float, float, float>; using UbTupleInt2 = UbTuple<int, int>; using UbTupleInt3 = UbTuple<int, int, int>; using UbTupleInt4 = UbTuple<int, int, int, int>; diff --git a/src/basics/basics/writer/WbWriterVtkXmlImageBinary.cpp b/src/basics/basics/writer/WbWriterVtkXmlImageBinary.cpp new file mode 100644 index 0000000000000000000000000000000000000000..92434e18ba1a2d4b2bc2027c6697f2d1f8393cf5 --- /dev/null +++ b/src/basics/basics/writer/WbWriterVtkXmlImageBinary.cpp @@ -0,0 +1,362 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file WbWriterVtkXmlImageBinary.cpp +//! \ingroup writer +//! \author Soeren Freudiger, Sebastian Geller, Henry Korb, Henrik Asmuth +//======================================================================================= +#include <basics/utilities/UbLogger.h> +#include <basics/writer/WbWriterVtkXmlImageBinary.h> +#include <cstring> + +using namespace std; + +/*===============================================================================*/ +const std::string WbWriterVtkXmlImageBinary::pvdEndTag = " </Collection>\n</VTKFile>"; +/*===============================================================================*/ +string WbWriterVtkXmlImageBinary::writeCollection(const string &filename, const vector<string> &filenames, + const double &timeStep, const bool &sepGroups) +{ + string vtkfilename = filename + ".pvd"; + ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + string endian; + if (UbSystem::isLittleEndian()) + endian = "LittleEndian"; + else + endian = "BigEndian"; + out << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"" << endian << "\" >" << endl; + out << " <Collection>" << endl; + + int group = 0, part = 0; + for (size_t i = 0; i < filenames.size(); i++) { + out << " <DataSet timestep=\"" << timeStep << "\" group=\"" << group << "\" part=\"" << part + << "\" file=\"" << filenames[i] << "\"/>" << endl; + if (sepGroups) + group++; + else + part++; + } + out << pvdEndTag; + out.close(); + + return vtkfilename; +} +/*===============================================================================*/ +string WbWriterVtkXmlImageBinary::addFilesToCollection(const string &filename, const vector<string> &filenames, + const double &timeStep, const bool &sepGroups) +{ + string vtkfilename = filename; + fstream test(vtkfilename.c_str(), ios::in); + if (!test) { + test.clear(); + vtkfilename += ".pvd"; + test.open(vtkfilename.c_str(), ios::in); + if (!test) + return this->writeCollection(filename, filenames, timeStep, sepGroups); + } + + fstream out(vtkfilename.c_str(), ios::in | ios::out); + out.seekp(-(int)pvdEndTag.size() - 1, ios_base::end); + + int group = 0; + for (size_t i = 0; i < filenames.size(); i++) { + out << " <DataSet timestep=\"" << timeStep << "\" group=\"" << group << "\" part=\"" << i << "\" file=\"" + << filenames[i] << "\"/>" << endl; + if (sepGroups) + group++; + } + out << pvdEndTag; + + return vtkfilename; +} +/*===============================================================================*/ +string WbWriterVtkXmlImageBinary::writeParallelFile(const string &filename, const UbTupleInt6 &wholeExtent, const UbTupleFloat3 &origin, const UbTupleFloat3 &spacing, + vector<string> &pieceSources, vector<UbTupleInt6> &pieceExtents, + vector<string> &pointDataNames, vector<string> &cellDataNames) +{ + string vtkfilename = filename + ".pvti"; + UBLOG(logDEBUG1, "WbWriterVtkXmlImageBinary::writeParallelFile to " << vtkfilename << " - start"); + + ofstream out(vtkfilename.c_str()); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str()); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + // VTK FILE + out << "<VTKFile type=\"PImageData\" version=\"0.1\" byte_order=\"LittleEndian\">" + << "\n"; + out << " <PImageData " + << "WholeExtent=\"" << val<1>(wholeExtent) << " " + << val<2>(wholeExtent) << " " + << val<3>(wholeExtent) << " " + << val<4>(wholeExtent) << " " + << val<5>(wholeExtent) << " " + << val<6>(wholeExtent) << "\" " + << "GhostLevel=\"0\" " + << "Origin=\"" << val<1>(origin) << " " + << val<2>(origin) << " " + << val<3>(origin) << "\" " + << "Spacing=\"" << val<1>(spacing) << " " + << val<2>(spacing) << " " + << val<3>(spacing) << "\" " + << "> \n"; + out << " <PPointData>\n"; + for (size_t s = 0; s < pointDataNames.size(); s++) + out << " <PDataArray type=\"Float32\" Name=\"" << pointDataNames[s] << "\"/>\n"; + out << " </PPointData>\n"; + if (cellDataNames.size() > 0) { + out << " <PCellData>\n"; + for (size_t s = 0; s < cellDataNames.size(); s++) + out << " <PDataArray type=\"Float32\" Name=\"" << cellDataNames[s] << "\"/>\n"; + out << " </PCellData>\n"; + } + for (size_t s = 0; s < pieceSources.size(); s++) + out << " <Piece Extent=\"" << val<1>(pieceExtents[s]) << " " + << val<2>(pieceExtents[s]) << " " + << val<3>(pieceExtents[s]) << " " + << val<4>(pieceExtents[s]) << " " + << val<5>(pieceExtents[s]) << " " + << val<6>(pieceExtents[s]) << "\" Source=\"" << pieceSources[s] << "\"/>\n"; + out << " </PImageData>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); + UBLOG(logDEBUG1, "WbWriterVtkXmlImageBinary::writeParallelFile to " << vtkfilename << " - end"); + + return vtkfilename; +} +/*===============================================================================*/ +string WbWriterVtkXmlImageBinary::writeOctsWithCellData(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleInt8> &cells, vector<string> &datanames, + vector<vector<double>> &celldata) +{ + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlImageBinary::writeOctsWithCellData to " << vtkfilename << " - start"); + + vector<string> nodeDataNames; + vector<vector<double>> nodedata; + + UbTupleFloat3 origin, spacing; + UbTupleInt6 extent; + + getMetaDataOfImage(nodes, origin, spacing, extent); + + this->writeData(vtkfilename, nodeDataNames, datanames, nodedata, celldata, extent, origin, spacing, extent); + UBLOG(logDEBUG1, "WbWriterVtkXmlImageBinary::writeOctsWithCellData to " << vtkfilename << " - end"); + + return vtkfilename; +} +/*===============================================================================*/ +string WbWriterVtkXmlImageBinary::writeOctsWithNodeData(const string &filename, vector<UbTupleFloat3> &nodes, + vector<UbTupleUInt8> &cells, vector<string> &datanames, + vector<vector<double>> &nodedata) +{ + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlImageBinary::writeOctsWithNodeData to " << vtkfilename << " - start"); + + vector<string> cellDataNames; + vector<vector<double>> cellData; + + UbTupleFloat3 origin, spacing; + UbTupleInt6 extent; + + getMetaDataOfImage(nodes, origin, spacing, extent); + + this->writeData(vtkfilename, datanames, cellDataNames, nodedata, cellData, extent, origin, spacing, extent); + + UBLOG(logDEBUG1, "WbWriterVtkXmlImageBinary::writeOctsWithNodeData to " << vtkfilename << " - end"); + + return vtkfilename; +} +/*===============================================================================*/ +string WbWriterVtkXmlImageBinary::writeNodesWithNodeData(const string &filename, vector<UbTupleFloat3> &nodes, + vector<string> &datanames, + vector<vector<double>> &nodedata) +{ + string vtkfilename = filename + getFileExtension(); + UBLOG(logDEBUG1, "WbWriterVtkXmlImageBinary::writeNodesWithNodeData to " << vtkfilename << " - start"); + + vector<string> cellDataNames; + vector<vector<double>> cellData; + + UbTupleFloat3 origin, spacing; + UbTupleInt6 extent; + + getMetaDataOfImage(nodes, origin, spacing, extent); + this->writeData(vtkfilename, datanames, cellDataNames, nodedata, cellData, extent, origin, spacing, extent); + + return vtkfilename; +} + +void WbWriterVtkXmlImageBinary::getMetaDataOfImage(vector<UbTupleFloat3> &nodes, UbTupleFloat3& origin, UbTupleFloat3& spacing, UbTupleInt6& extent) +{ + int nofNodes = (int)nodes.size(); + val<1>(origin) = val<1>(nodes[0]); + val<2>(origin) = val<2>(nodes[0]); + val<3>(origin) = val<3>(nodes[0]); + + float l_x = val<1>(nodes[nofNodes-1])-val<1>(origin); + float l_y = val<2>(nodes[nofNodes-1])-val<2>(origin); + + val<1>(spacing) = val<1>(nodes[1])-val<1>(nodes[0]); + int nx = (l_x) / val<1>(spacing); + val<2>(spacing) = val<2>(nodes[nx])-val<2>(nodes[0]); + int ny = (l_y) / val<2>(spacing); + val<3>(spacing) = val<3>(nodes[nx*ny])-val<3>(nodes[0]); + + val<1>(extent) = val<1>(origin)/val<1>(spacing); val<2>(extent) = val<1>(nodes[nofNodes-1])/val<1>(spacing); + val<3>(extent) = val<2>(origin)/val<2>(spacing); val<4>(extent) = val<2>(nodes[nofNodes-1])/val<2>(spacing); + val<5>(extent) = val<3>(origin)/val<3>(spacing); val<6>(extent) = val<3>(nodes[nofNodes-1])/val<3>(spacing); + +} + +void WbWriterVtkXmlImageBinary::writeData(const string &vtkfilename, + vector<string> &pointDataNames, vector<string> &cellDataNames, + vector<vector<double>> &nodedata, vector<vector<double>> &celldata, + UbTupleInt6& wholeExtent, + UbTupleFloat3& origin, UbTupleFloat3& spacing, UbTupleInt6& extent, unsigned int precision) +{ + ofstream out(vtkfilename.c_str(), ios::out | ios::binary); + out.precision(precision); + + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + string path = UbSystem::getPathFromString(vtkfilename); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(vtkfilename.c_str(), ios::out | ios::binary); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + vtkfilename); + } + + size_t nPoints = pointDataNames.size()>0 ? nodedata[0].size() : celldata[0].size(); + + int bytesPerByteVal = 4; //==sizeof(int) + + int bytesScalarData = 1 /*scalar */ * (int)nPoints * sizeof(double); + + int offset = 0; + + // VTK FILE + out << "<?xml version=\"1.0\"?>\n"; + out << "<VTKFile type=\"ImageData\" version=\"0.1\" byte_order=\"LittleEndian\" >" + << "\n"; + out << " <ImageData " + << "WholeExtent=\"" << val<1>(wholeExtent) << " " + << val<2>(wholeExtent) << " " + << val<3>(wholeExtent) << " " + << val<4>(wholeExtent) << " " + << val<5>(wholeExtent) << " " + << val<6>(wholeExtent) << "\" " + << "Origin=\"" << val<1>(origin) << " " + << val<2>(origin) << " " + << val<3>(origin) << "\" " + << "Spacing=\"" << val<1>(spacing) << " " + << val<2>(spacing) << " " + << val<3>(spacing) << "\"" + << "> \n"; + out << " <Piece Extent=\"" << val<1>(extent) << " " + << val<2>(extent) << " " + << val<3>(extent) << " " + << val<4>(extent) << " " + << val<5>(extent) << " " + << val<6>(extent) << "\">\n"; + + // DATA SECTION + if (pointDataNames.size()>0) + { + out << " <PointData>\n"; + for (size_t s = 0; s < pointDataNames.size(); ++s) { + out << " <DataArray type=\"Float64\" Name=\"" << pointDataNames[s] << "\" format=\"appended\" offset=\"" + << offset << "\" /> \n"; + offset += (bytesPerByteVal + bytesScalarData); + } + out << " </PointData>\n"; + } + + if (cellDataNames.size()>0) + { + out << " <CellData>\n"; + for (size_t s = 0; s < cellDataNames.size(); ++s) { + out << " <DataArray type=\"Float64\" Name=\"" << cellDataNames[s] << "\" format=\"appended\" offset=\"" + << offset << "\" /> \n"; + offset += (bytesPerByteVal + bytesScalarData); + } + out << " </CellData>\n"; + } + + out << " </Piece>\n"; + out << " </ImageData>\n"; + + // AppendedData SECTION + out << " <AppendedData encoding=\"raw\">\n"; + out << "_"; + + + // DATA SECTION + // pointData + for (size_t s = 0; s < pointDataNames.size(); ++s) { + out.write((char *)&bytesScalarData, bytesPerByteVal); + for (size_t d = 0; d < nodedata[s].size(); ++d) { + double tmp = nodedata[s][d]; + out.write((char *)&tmp, sizeof(double)); + } + } + + // cellData + for (size_t s = 0; s < cellDataNames.size(); ++s) { + out.write((char *)&bytesScalarData, bytesPerByteVal); + for (size_t d = 0; d < celldata[s].size(); ++d) { + double tmp = celldata[s][d]; + out.write((char *)&tmp, sizeof(double)); + } + } + out << "\n </AppendedData>\n"; + out << "</VTKFile>"; + out << endl; + out.close(); +} \ No newline at end of file diff --git a/src/basics/basics/writer/WbWriterVtkXmlImageBinary.h b/src/basics/basics/writer/WbWriterVtkXmlImageBinary.h new file mode 100644 index 0000000000000000000000000000000000000000..c41ff442732e5f65db0f1dd1ec63e5c3ffca1486 --- /dev/null +++ b/src/basics/basics/writer/WbWriterVtkXmlImageBinary.h @@ -0,0 +1,110 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file WbWriterVtkXmlBinary.h +//! \ingroup writer +//! \author Soeren Freudiger, Sebastian Geller +//======================================================================================= +#ifndef WBWRITERVTKXMLIMAGEBINARY_H +#define WBWRITERVTKXMLIMAGEBINARY_H + +#include <string> + +#include <basics/writer/WbWriter.h> + +#include "basics_export.h" + +class BASICS_EXPORT WbWriterVtkXmlImageBinary : public WbWriter +{ +public: + static WbWriterVtkXmlImageBinary *getInstance() + { + static WbWriterVtkXmlImageBinary instance; + return &instance; + } + + WbWriterVtkXmlImageBinary(const WbWriterVtkXmlImageBinary &) = delete; + const WbWriterVtkXmlImageBinary &operator=(const WbWriterVtkXmlImageBinary &) = delete; + +private: + WbWriterVtkXmlImageBinary() : WbWriter() + { + if (sizeof(unsigned char) != 1) + throw UbException(UB_EXARGS, "machine error char type mismatch"); + if (sizeof(int) != 4) + throw UbException(UB_EXARGS, "machine error int type mismatch"); + if (sizeof(float) != 4) + throw UbException(UB_EXARGS, "machine error float type mismatch"); + } + + static const std::string pvdEndTag; + +public: + std::string getFileExtension() override { return ".bin.vti"; } + + // write a metafile + std::string writeCollection(const std::string &filename, const std::vector<std::string> &filenames, + const double ×tep, const bool &sepGroups); + std::string addFilesToCollection(const std::string &filename, const std::vector<std::string> &filenames, + const double ×tep, const bool &sepGroups); + std::string writeParallelFile(const std::string &filename, const UbTupleInt6 &wholeExtent, const UbTupleFloat3 &origin, const UbTupleFloat3 &spacing, + std::vector<std::string> &pieceSources, std::vector<UbTupleInt6> &pieceExtents, + std::vector<std::string> &pointDataNames, std::vector<std::string> &cellDataNames); + + ////////////////////////////////////////////////////////////////////////// + // nodes + std::string writeNodesWithNodeData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<std::string> &datanames, + std::vector<std::vector<double>> &nodedata) override; + + ////////////////////////////////////////////////////////////////////////// + // octs + // 7 ---- 6 + // /| /| + // 4 +--- 5 | + // | | | | + // | 3 ---+ 2 + // |/ |/ + // 0 ---- 1 + std::string writeOctsWithCellData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleInt8> &cells, std::vector<std::string> &datanames, + std::vector<std::vector<double>> &celldata) override; + std::string writeOctsWithNodeData(const std::string &filename, std::vector<UbTupleFloat3> &nodes, + std::vector<UbTupleUInt8> &cells, std::vector<std::string> &datanames, + std::vector<std::vector<double>> &nodedata) override; + void writeData(const std::string &vtkfilename, + std::vector<std::string> &pointDataNames, std::vector<std::string> &cellDataNames, + std::vector<std::vector<double>> &nodedata, std::vector<std::vector<double>> &celldata, + UbTupleInt6 &wholeExtent, + UbTupleFloat3 &origin, UbTupleFloat3 &spacing, UbTupleInt6 &extent, unsigned int precision=6); + +private: + void getMetaDataOfImage(std::vector<UbTupleFloat3> &nodes, UbTupleFloat3& origin, UbTupleFloat3& spacing, UbTupleInt6& extent); +}; + +#endif // WBWRITERVTKXMLIMAGEBINARY_H diff --git a/src/basics/config/ConfigurationFile.h b/src/basics/config/ConfigurationFile.h index ef7e7c9f06f94cabb3ba9cbefe95c8ee75736958..4a53f7add85b9c6461fda0bab20fa6656eebc5d3 100644 --- a/src/basics/config/ConfigurationFile.h +++ b/src/basics/config/ConfigurationFile.h @@ -64,6 +64,10 @@ public: template<class T> T getValue(const std::string& key) const; + //! get value with key and default value + template<class T> + T getValue(const std::string& key, T defaultValue) const; + private: //! the container std::map<std::string, std::string> data; @@ -138,6 +142,19 @@ T ConfigurationFile::getValue(const std::string& key) const return x; } +template<class T> +T ConfigurationFile::getValue(const std::string& key, T defaultValue) const +{ + if (contains(key)) + { + return getValue<T>(key); + } + else + { + return defaultValue; + } +} + } #endif diff --git a/src/gpu/GridGenerator/TransientBCSetter/TransientBCSetter.cpp b/src/gpu/GridGenerator/TransientBCSetter/TransientBCSetter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3026458c988c4e7624e15304f144d01f40fb0cdf --- /dev/null +++ b/src/gpu/GridGenerator/TransientBCSetter/TransientBCSetter.cpp @@ -0,0 +1,440 @@ +#include "TransientBCSetter.h" +#include "GridGenerator/grid/Grid.h" +#include "GridGenerator/grid/BoundaryConditions/BoundaryCondition.h" +#include <logger/Logger.h> + + +#include <math.h> +#include <sstream> +#include <fstream> +#include <iostream> +#include <algorithm> + +SPtr<FileCollection> createFileCollection(std::string prefix, FileType type) +{ + switch(type) + { + case FileType::VTK: + return std::make_shared<VTKFileCollection>(prefix); + break; + default: + return nullptr; + } +} + +SPtr<TransientBCInputFileReader> createReaderForCollection(SPtr<FileCollection> fileCollection, uint readLevel) +{ + switch(fileCollection->getFileType()) + { + case FileType::VTK: + return std::make_shared<VTKReader>(std::static_pointer_cast<VTKFileCollection>(fileCollection), readLevel); + break; + default: + return nullptr; + } +} + +template<typename T> +std::vector<T> readStringToVector(std::string s) +{ + std::vector<T> out; + std::stringstream input(s); + float num; + while(input >> num) + { + out.push_back(num); + } + return out; +} + +std::string readElement(std::string line) +{ + size_t elemStart = line.find("<")+1; + // size_t elemEnd = line.find("/>", elemStart); + size_t nameLen = line.find(" ", elemStart)-elemStart; + return line.substr(elemStart, nameLen); +} + +std::string readAttribute(std::string line, std::string attributeName) +{ + size_t attributeStart = line.find(attributeName)+attributeName.size() + 2; // add 2 for '="' + size_t attributeLen = line.find("\"", attributeStart)-attributeStart; + return line.substr(attributeStart, attributeLen); +} + +void VTKFile::readHeader() +{ + //TODO make this more flexible + std::ifstream file(this->fileName); + + std::string line; + + getline(file, line); // VTKFile + if(line[1]=='?') getline(file, line); // ignore first line if xml version + + getline(file, line); // ImageData + std::vector<int> wholeExtent = readStringToVector<int>(readAttribute(line, "WholeExtent")); + std::vector<float> origin = readStringToVector<float>(readAttribute(line, "Origin")); + std::vector<float> spacing = readStringToVector<float>(readAttribute(line, "Spacing")); + + getline(file, line); // Piece + std::vector<int> pieceExtent = readStringToVector<int>(readAttribute(line, "Extent")); + getline(file, line); // PointData + + getline(file, line); + while(strcmp(readElement(line).c_str(), "DataArray")==0) + { + Quantity quant = Quantity(); + quant.name = readAttribute(line, "Name"); + quant.offset = std::stoi(readAttribute(line, "offset")); + this->quantities.push_back( quant ); + getline(file, line); + } + getline(file, line); // </Piece + getline(file, line); // </ImageData + getline(file, line); // AppendedData + + int offset = int(file.tellg())+sizeof(char)+4; // skip underscore and bytesPerVal + + for(auto& quantity: this->quantities) + { + quantity.offset += offset; + } + + file.close(); + + this->deltaX = spacing[0]; + this->deltaY = spacing[1]; + this->deltaZ = spacing[2]; + + this->nx = pieceExtent[1]-pieceExtent[0]+1; + this->ny = pieceExtent[3]-pieceExtent[2]+1; + this->nz = pieceExtent[5]-pieceExtent[4]+1; + + this->minX = origin[0]+this->deltaX*pieceExtent[0]; this->maxX = (this->nx-1)*this->deltaX+this->minX; + this->minY = origin[1]+this->deltaY*pieceExtent[2]; this->maxY = (this->ny-1)*this->deltaY+this->minY; + this->minZ = origin[2]+this->deltaZ*pieceExtent[4]; this->maxZ = (this->nz-1)*this->deltaZ+this->minZ; + // printFileInfo(); + +} + +bool VTKFile::markNANs(std::vector<uint> readIndices) +{ + std::ifstream buf(fileName.c_str(), std::ios::in | std::ios::binary); + + std::vector<double> tmp; + tmp.reserve(readIndices.size()); + buf.seekg(this->quantities[0].offset); + buf.read((char*) tmp.data(), sizeof(double)*readIndices.size()); + auto firstNAN = std::find_if(tmp.begin(), tmp.end(), [](auto it){ return isnan(it); }); + + return firstNAN != tmp.end(); +} + +void VTKFile::loadFile() +{ + std::ifstream buf(this->fileName.c_str(), std::ios::in | std::ios::binary); + for(auto& quantity: this->quantities) + { + quantity.values.resize(getNumberOfPoints()); + buf.seekg(quantity.offset); + buf.read(reinterpret_cast<char*>(quantity.values.data()), this->getNumberOfPoints()*sizeof(double)); + } + + buf.close(); + + this->loaded = true; +} + +void VTKFile::unloadFile() +{ + for(auto& quantity : this->quantities) + { + std::vector<double> replacement; + quantity.values.swap(replacement); + } + this->loaded = false; +} + +void VTKFile::getData(real* data, uint numberOfNodes, const std::vector<uint>& readIndices, const std::vector<uint>& writeIndices, uint offsetRead, uint offsetWrite) +{ + if(!this->loaded) loadFile(); + + size_t nPoints = writeIndices.size(); + + for(size_t j=0; j<this->quantities.size(); j++) + { + real* quant = &data[j*numberOfNodes]; + for(size_t i=0; i<nPoints; i++) + { + quant[offsetWrite+writeIndices[i]] = this->quantities[j].values[readIndices[i]+offsetRead]; + } + } +} + +void VTKFile::printFileInfo() +{ + printf("file %s with \n nx %i ny %i nz %i \n origin %f %f %f \n spacing %f %f %f \n", + fileName.c_str(), nx, ny, nz, minX, minY, minZ, deltaX, deltaY, deltaZ); + for(auto quantity: this->quantities) + { + printf("\t quantity %s offset %i \n", quantity.name.c_str(), quantity.offset); + } + +} + + +void VTKFileCollection::findFiles() +{ + bool foundLastLevel = false; + + while(!foundLastLevel) + { + bool foundLastID = false; + std::vector<std::vector<VTKFile>> filesOnThisLevel; + while(!foundLastID) + { + bool foundLastPart = false; + std::vector<VTKFile> filesWithThisId; + while (!foundLastPart) + { + std::string fname = makeFileName((int)files.size(), (int)filesOnThisLevel.size(), (int)filesWithThisId.size()); + std::ifstream f(fname); + if(f.good()) + filesWithThisId.emplace_back(fname); + else + foundLastPart = true; + } + if(!filesWithThisId.empty()) + { + VF_LOG_INFO("VTKFileCollection found {} files with ID {} level {}", filesWithThisId.size(), filesOnThisLevel.size(), files.size() ); + filesOnThisLevel.push_back(filesWithThisId); + } + else foundLastID = true; + } + + + if(!filesOnThisLevel.empty()) + files.push_back(filesOnThisLevel); + else + foundLastLevel = true; + + } + + if(files.empty()) + VF_LOG_CRITICAL("VTKFileCollection found no files!"); +} + +void TransientBCInputFileReader::getNeighbors(uint* neighbor0PP, uint* neighbor0PM, uint* neighbor0MP, uint* neighbor0MM) +{ + std::copy(planeNeighbor0PP.begin(), planeNeighbor0PP.end(), &neighbor0PP[writingOffset]); + std::copy(planeNeighbor0PM.begin(), planeNeighbor0PM.end(), &neighbor0PM[writingOffset]); + std::copy(planeNeighbor0MP.begin(), planeNeighbor0MP.end(), &neighbor0MP[writingOffset]); + std::copy(planeNeighbor0MM.begin(), planeNeighbor0MM.end(), &neighbor0MM[writingOffset]); +} + +void TransientBCInputFileReader::getWeights(real* _weights0PP, real* _weights0PM, real* _weights0MP, real* _weights0MM) +{ + std::copy(weights0PP.begin(), weights0PP.end(), &_weights0PP[writingOffset]); + std::copy(weights0PM.begin(), weights0PM.end(), &_weights0PM[writingOffset]); + std::copy(weights0MP.begin(), weights0MP.end(), &_weights0MP[writingOffset]); + std::copy(weights0MM.begin(), weights0MM.end(), &_weights0MM[writingOffset]); +} + + +void VTKReader::initializeIndexVectors() +{ + this->readIndices.resize(this->fileCollection->files.size()); + this->writeIndices.resize(this->fileCollection->files.size()); + this->nFile.resize(this->fileCollection->files.size()); + for(size_t lev=0; lev<this->fileCollection->files.size(); lev++) + { + this->readIndices[lev].resize(this->fileCollection->files[lev].size()); + this->writeIndices[lev].resize(this->fileCollection->files[lev].size()); + this->nFile[lev].resize(this->fileCollection->files[lev].size()); + } +} + +void VTKReader::fillArrays(std::vector<real>& coordsY, std::vector<real>& coordsZ) +{ + this->nPoints = (uint)coordsY.size(); + this->initializeIndexVectors(); + real max_diff = 1e-4; // maximum distance between point on grid and precursor plane to count as exact match + real eps = 1e-7; // small number to avoid division by zero + bool perfect_match = true; + + this->weights0PP.reserve(this->nPoints); + this->weights0PM.reserve(this->nPoints); + this->weights0MP.reserve(this->nPoints); + this->weights0MM.reserve(this->nPoints); + + this->planeNeighbor0PP.reserve(this->nPoints); + this->planeNeighbor0PM.reserve(this->nPoints); + this->planeNeighbor0MP.reserve(this->nPoints); + this->planeNeighbor0MM.reserve(this->nPoints); + + for(uint i=0; i<nPoints; i++) + { + + real posY = coordsY[i]; + real posZ = coordsZ[i]; + bool found0PP = false, found0PM = false, found0MP = false, found0MM = false, foundAll = false; + + uint level = this->readLevel; + + for(int fileId=0; fileId<(int)this->fileCollection->files[level].size(); fileId++) + { + VTKFile &file = this->fileCollection->files[level][fileId][0]; + if(!file.inBoundingBox(posY, posZ, 0.0f)) continue; + + // y in simulation is x in precursor/file, z in simulation is y in precursor/file + // simulation -> file: N -> E, S -> W, T -> N, B -> S + int idx = file.findNeighborMMM(posY, posZ, 0.f); //!> index of nearest WSB neighbor on precursor file + + if(idx!=-1) + { + // Filter for exact matches + if(abs(posY-file.getX(idx)) < max_diff && abs(posZ-file.getY(idx)) < max_diff) + { + this->weights0PP.emplace_back(1e6f); + this->weights0PM.emplace_back(0.f); + this->weights0MP.emplace_back(0.f); + this->weights0MM.emplace_back(0.f); + uint writeIdx = this->getWriteIndex(level, fileId, idx); //!> writeIdx: index on host/device array where precursor value will be written to after loading from file + this->planeNeighbor0PP.push_back(writeIdx); //!> neighbor lists mapping where BC kernel should read from on host/device array + this->planeNeighbor0PM.push_back(writeIdx); + this->planeNeighbor0MP.push_back(writeIdx); + this->planeNeighbor0MM.push_back(writeIdx); + found0PP = true; found0PM = true; found0MM = true; found0MP = true; + } + else + { + perfect_match = false; + } + + if(!found0MM) + { + found0MM = true; + real dy = file.getX(idx)-posY; + real dz = file.getY(idx)-posZ; + this->weights0MM.emplace_back(1.f/(dy*dy+dz*dz+eps)); + this->planeNeighbor0MM.emplace_back(getWriteIndex(level, fileId, idx)); + } + + } + + if(!found0PP) //NT in simulation is EN in precursor + { + int idx = file.findNeighborPPM(posY, posZ, 0.f); + if(idx!=-1) + { + found0PP = true; + real dy = file.getX(idx)-posY; + real dz = file.getY(idx)-posZ; + this->weights0PP.emplace_back(1.f/(dy*dy+dz*dz+eps)); + this->planeNeighbor0PP.emplace_back(getWriteIndex(level, fileId, idx)); + } + } + + if(!found0PM) //NB in simulation is ES in precursor + { + int idx = file.findNeighborPMM(posY, posZ, 0.f); + if(idx!=-1) + { + found0PM = true; + real dy = file.getX(idx)-posY; + real dz = file.getY(idx)-posZ; + this->weights0PM.emplace_back(1.f/(dy*dy+dz*dz+eps)); + this->planeNeighbor0PP.emplace_back(getWriteIndex(level, fileId, idx)); + } + } + + if(!found0MP) //ST in simulation is WN in precursor + { + int idx = file.findNeighborMPM(posY, posZ, 0.f); + if(idx!=-1) + { + found0MP = true; + real dy = file.getX(idx)-posY; + real dz = file.getY(idx)-posZ; + this->weights0MP.emplace_back(1.f/(dy*dy+dz*dz+eps)); + this->planeNeighbor0MP.emplace_back(getWriteIndex(level, fileId, idx)); + } + } + + foundAll = found0PP && found0PM && found0MP && found0MM; + + if(foundAll) break; + } + + if(!foundAll) + { + VF_LOG_CRITICAL("Found no matching precursor neighbors for grid point at y={}, z={} \n", posY, posZ); + throw std::runtime_error("VTKReader::fillArrays(): Did not find neighbors in the FileCollection for all points"); + } + } + + if(perfect_match) + printf("Precursor was a perfect match \n"); + + + for(size_t level=0; level<this->fileCollection->files.size(); level++){ + for(size_t id=0; id<this->fileCollection->files[level].size(); id++){ + if(this->fileCollection->files[level][id][0].markNANs(this->readIndices[level][id])) + throw std::runtime_error("Found a NAN in the precursor where a velocity is needed"); + }} +} + +uint VTKReader::getWriteIndex(int level, int id, int linearIndex) +{ + auto it = std::find(this->writeIndices[level][id].begin(), this->writeIndices[level][id].end(), linearIndex); + uint idx = it-this->writeIndices[level][id].begin(); + if(it==this->writeIndices[level][id].end()) + { + this->writeIndices[level][id].push_back(this->nPointsRead); //!> index on host/device array where value from file will be written to + this->readIndices[level][id].push_back(linearIndex); //!> index in file that will be read from + this->nPointsRead++; + } + return idx; +} + + +void VTKReader::getNextData(real* data, uint numberOfNodes, real time) +{ + // for(size_t level=0; level<this->fileCollection->files.size(); level++) + // { + uint level = this->readLevel; + for(size_t id=0; id<this->fileCollection->files[level].size(); id++) + { + size_t numberOfFiles = this->nFile[level][id]; + + + if(!this->fileCollection->files[level][id][numberOfFiles].inZBounds(time)) + { + numberOfFiles++; + + printf("switching to precursor file no. %zd\n", numberOfFiles); + if(numberOfFiles == this->fileCollection->files[level][id].size()) + throw std::runtime_error("Not enough Precursor Files to read"); + + this->fileCollection->files[level][id][numberOfFiles-1].unloadFile(); + if(numberOfFiles+1<this->fileCollection->files[level][id].size()) + { + VTKFile* nextFile = &this->fileCollection->files[level][id][numberOfFiles+1]; + if(! nextFile->isLoaded()) + { + read.wait(); + read = std::async(std::launch::async, [](VTKFile* file){ file->loadFile(); }, &this->fileCollection->files[level][id][numberOfFiles+1]); + } + } + } + + + VTKFile* file = &this->fileCollection->files[level][id][numberOfFiles]; + + int off = file->getClosestIdxZ(time)*file->getNumberOfPointsInXYPlane(); + file->getData(data, numberOfNodes, this->readIndices[level][id], this->writeIndices[level][id], off, this->writingOffset); + this->nFile[level][id] = numberOfFiles; + } + // } +} \ No newline at end of file diff --git a/src/gpu/GridGenerator/TransientBCSetter/TransientBCSetter.h b/src/gpu/GridGenerator/TransientBCSetter/TransientBCSetter.h new file mode 100644 index 0000000000000000000000000000000000000000..5bee61e194670c74ca8bd8da87f3881956fff466 --- /dev/null +++ b/src/gpu/GridGenerator/TransientBCSetter/TransientBCSetter.h @@ -0,0 +1,201 @@ +#ifndef TRANSIENTBCSETTER_H_ +#define TRANSIENTBCSETTER_H_ + +#include "Core/DataTypes.h" +#include <Core/StringUtilities/StringUtil.h> +#include "PointerDefinitions.h" + +#include <string> +#include <vector> +#include <math.h> +#include <sstream> +#include <future> +class Grid; +namespace gg +{ + class BoundaryCondition; +} + + +enum class FileType +{ + VTK +}; + +struct Quantity +{ + std::string name; + int offset; + std::vector<double> values; +}; + +class VTKFile +{ +public: + VTKFile(std::string _fileName): + fileName(_fileName) + { + readHeader(); + this->loaded = false; + // printFileInfo(); + }; + + void getData(real* data, uint numberOfNodes, const std::vector<uint>& readIndices, const std::vector<uint>& writeIndices, uint offsetRead, uint offsetWrite); + bool markNANs(std::vector<uint> readIndices); + bool inBoundingBox(real posX, real posY, real posZ){return inXBounds(posX) && inYBounds(posY) && inZBounds(posZ); }; + bool inXBounds(real posX){ return posX<=maxX && posX>=minX; }; + bool inYBounds(real posY){ return posY<=maxY && posY>=minY; }; + bool inZBounds(real posZ){ return posZ<=maxZ && posZ>=minZ; }; + int findNeighborMMM(real posX, real posY, real posZ){ int idx = getLinearIndex(getIdxM00(posX) , getIdx0M0(posY) , getIdx00M(posZ) ); return (idx>=0) && (idx<nx*ny*nz) ? idx : -1; }; + int findNeighborMMP(real posX, real posY, real posZ){ int idx = getLinearIndex(getIdxM00(posX) , getIdx0M0(posY) , getIdx00M(posZ)+1); return (idx>=0) && (idx<nx*ny*nz) ? idx : -1; }; + int findNeighborMPM(real posX, real posY, real posZ){ int idx = getLinearIndex(getIdxM00(posX) , getIdx0M0(posY)+1, getIdx00M(posZ) ); return (idx>=0) && (idx<nx*ny*nz) ? idx : -1; }; + int findNeighborMPP(real posX, real posY, real posZ){ int idx = getLinearIndex(getIdxM00(posX) , getIdx0M0(posY)+1, getIdx00M(posZ)+1); return (idx>=0) && (idx<nx*ny*nz) ? idx : -1; }; + int findNeighborPMM(real posX, real posY, real posZ){ int idx = getLinearIndex(getIdxM00(posX)+1, getIdx0M0(posY) , getIdx00M(posZ) ); return (idx>=0) && (idx<nx*ny*nz) ? idx : -1; }; + int findNeighborPMP(real posX, real posY, real posZ){ int idx = getLinearIndex(getIdxM00(posX)+1, getIdx0M0(posY) , getIdx00M(posZ)+1); return (idx>=0) && (idx<nx*ny*nz) ? idx : -1; }; + int findNeighborPPM(real posX, real posY, real posZ){ int idx = getLinearIndex(getIdxM00(posX)+1, getIdx0M0(posY)+1, getIdx00M(posZ) ); return (idx>=0) && (idx<nx*ny*nz) ? idx : -1; }; + int findNeighborPPP(real posX, real posY, real posZ){ int idx = getLinearIndex(getIdxM00(posX)+1, getIdx0M0(posY)+1, getIdx00M(posZ)+1); return (idx>=0) && (idx<nx*ny*nz) ? idx : -1; }; + int getIdxX(int linearIdx){ return linearIdx%nx;}; + int getIdxY(int linearIdx){ return (linearIdx/nx)%ny;}; + int getIdxZ(int linearIdx){ return linearIdx/(nx*ny); }; + real getX(int linearIdx){ return getIdxX(linearIdx)*deltaX+minX; }; + real getY(int linearIdx){ return getIdxY(linearIdx)*deltaY+minY; }; + real getZ(int linearIdx){ return getIdxZ(linearIdx)*deltaZ+minZ; }; + int getIdxM00(real posX){ return (posX-minX)/deltaX; }; + int getIdx0M0(real posY){ return (posY-minY)/deltaY; }; + int getIdx00M(real posZ){ return (posZ-minZ)/deltaZ; }; + int getClosestIdxX(real posX){ int x = round((posX-minX)/deltaX); return x>nx ? nx : (x<0 ? 0 : x);}; + int getClosestIdxY(real posY){ int y = round((posY-minY)/deltaY); return y>ny ? ny : (y<0 ? 0 : y);}; + int getClosestIdxZ(real posZ){ int z = round((posZ-minZ)/deltaZ); return z>nz ? nz : (z<0 ? 0 : z);}; + int getLinearIndex(int idxX, int idxY, int idxZ){ return idxX + nx*(idxY+ny*idxZ); }; + int getNumberOfPointsInXYPlane(){ return nx*ny; } + int getNumberOfPointsInYZPlane(){ return ny*nz; } + int getNumberOfPointsInXZPlane(){ return nx*nz; } + int getNumberOfPoints(){ return nx*ny*nz; } + size_t getNumberOfQuantities(){ return quantities.size(); } + void loadFile(); + void unloadFile(); + bool isLoaded(){return loaded;}; + + +private: + void readHeader(); + void printFileInfo(); + +public: + +private: + std::string fileName; + real minX, maxX, minY, maxY, minZ, maxZ; + real deltaX, deltaY, deltaZ; + int nx, ny, nz; + std::vector<Quantity> quantities; + bool loaded; +}; + +class FileCollection +{ +public: + FileCollection(std::string _prefix): + prefix(_prefix){}; + + virtual ~FileCollection() = default; + + virtual size_t getNumberOfQuantities()=0; + + virtual FileType getFileType()=0; + +protected: + std::string prefix; +}; + + +class VTKFileCollection : public FileCollection +{ +public: + VTKFileCollection(std::string _prefix): + FileCollection(_prefix) + { + findFiles(); + }; + + FileType getFileType(){ return FileType::VTK; }; + size_t getNumberOfQuantities(){ return files[0][0][0].getNumberOfQuantities(); } + + +private: + void findFiles(); + std::string makeFileName(int level, int id, int part) + { + return prefix + "_lev_" + StringUtil::toString<int>(level) + + "_ID_" + StringUtil::toString<int>(id) + + "_File_" + StringUtil::toString<int>(part) + + ".bin." + suffix; + }; + + +public: + static const inline std::string suffix = "vti"; + std::vector<std::vector<std::vector<VTKFile>>> files; +}; + + +class TransientBCInputFileReader +{ +public: + TransientBCInputFileReader() + { + this->nPoints = 0; + this->nPointsRead = 0; + this->writingOffset = 0; + }; + virtual ~TransientBCInputFileReader() = default; + + virtual void getNextData(real* data, uint numberOfNodes, real time)=0; + virtual void fillArrays(std::vector<real>& coordsY, std::vector<real>& coordsZ)=0; + uint getNPoints(){return nPoints; }; + uint getNPointsRead(){return nPointsRead; }; + size_t getNumberOfQuantities(){ return nQuantities; }; + void setWritingOffset(uint offset){ this->writingOffset = offset; } + void getNeighbors(uint* neighbor0PP, uint* neighbor0PM, uint* neighbor0MP, uint* neighbor0MM); + void getWeights(real* _weights0PP, real* _weights0PM, real* _weights0MP, real* _weights0MM); + +public: + std::vector<uint> planeNeighbor0PP, planeNeighbor0PM, planeNeighbor0MP, planeNeighbor0MM; + std::vector<real> weights0PP, weights0PM, weights0MP, weights0MM; + +protected: + uint nPoints, nPointsRead, writingOffset; + uint nReads=0; + size_t nQuantities=0; +}; + + +class VTKReader : public TransientBCInputFileReader +{ +public: + VTKReader(SPtr<VTKFileCollection> _fileCollection, uint _readLevel): + fileCollection(_fileCollection), + readLevel(_readLevel) + { + this->nQuantities = fileCollection->getNumberOfQuantities(); + read = std::async([](){}); + }; + void getNextData(real* data, uint numberOfNodes, real time) override; + void fillArrays(std::vector<real>& coordsY, std::vector<real>& coordsZ) override; +private: + uint getWriteIndex(int level, int id, int linearIdx); + void initializeIndexVectors(); + +private: + std::vector<std::vector<std::vector<uint>>> readIndices, writeIndices; + std::vector<std::vector<size_t>> nFile; + SPtr<VTKFileCollection> fileCollection; + uint readLevel; + std::future<void> read; +}; + + +SPtr<FileCollection> createFileCollection(std::string prefix, FileType type); +SPtr<TransientBCInputFileReader> createReaderForCollection(SPtr<FileCollection> fileCollection, uint readLevel); + +#endif //TRANSIENTBCSETTER_H_ \ No newline at end of file diff --git a/src/gpu/GridGenerator/grid/BoundaryConditions/BoundaryCondition.cpp b/src/gpu/GridGenerator/grid/BoundaryConditions/BoundaryCondition.cpp index 5102f60fc295aadf4323a4b332bf3dd8f7f21dbf..b0fb2604946b83ead45c30adabbcfe8dc26fa656 100644 --- a/src/gpu/GridGenerator/grid/BoundaryConditions/BoundaryCondition.cpp +++ b/src/gpu/GridGenerator/grid/BoundaryConditions/BoundaryCondition.cpp @@ -36,12 +36,12 @@ #include "grid/BoundaryConditions/Side.h" #include "grid/Grid.h" +#include "GridGenerator/TransientBCSetter/TransientBCSetter.h" bool gg::BoundaryCondition::isSide( SideType side ) const { return this->side->whoAmI() == side; } - ////////////////////////////////////////////////////////////////////////// void VelocityBoundaryCondition::setVelocityProfile( @@ -124,5 +124,4 @@ void StressBoundaryCondition::fillSamplingIndices(std::vector<SPtr<Grid> > grid, this->velocitySamplingIndices.push_back( grid[level]->transCoordToIndex(x_sampling, y_sampling, z_sampling) ); } -} - +} \ No newline at end of file diff --git a/src/gpu/GridGenerator/grid/BoundaryConditions/BoundaryCondition.h b/src/gpu/GridGenerator/grid/BoundaryConditions/BoundaryCondition.h index 4a3990d9f815042297be76ae83a61268c8ad6815..22342aec9839afad9bb37b1b11812f6d1750ed7b 100644 --- a/src/gpu/GridGenerator/grid/BoundaryConditions/BoundaryCondition.h +++ b/src/gpu/GridGenerator/grid/BoundaryConditions/BoundaryCondition.h @@ -45,6 +45,8 @@ class Grid; class Side; enum class SideType; +class TransientBCInputFileReader; + namespace gg { class BoundaryCondition @@ -63,6 +65,8 @@ public: bool isSide(SideType side) const; real getQ(uint index, uint dir) { return this->qs[index][dir]; } + + void getCoords( SPtr<Grid> grid, std::vector<real>& x, std::vector<real>& y, std::vector<real>& z); }; } @@ -246,6 +250,7 @@ public: real getVy(uint index) { return this->vyList[index]; } real getVz(uint index) { return this->vzList[index]; } + void setVelocityProfile( SPtr<Grid> grid, std::function<void(real,real,real,real&,real&,real&)> velocityProfile ); }; @@ -329,5 +334,32 @@ public: real getNormalz(uint index) { return this->normalZList[index]; } }; +class PrecursorBoundaryCondition : public gg::BoundaryCondition +{ +public: + static SPtr<PrecursorBoundaryCondition> make(SPtr<TransientBCInputFileReader> reader, int timeStepsBetweenReads, real velocityX, real velocityY, real velocityZ) + { + return SPtr<PrecursorBoundaryCondition>(new PrecursorBoundaryCondition(reader, timeStepsBetweenReads, velocityX, velocityY, velocityZ)); + } + SPtr<TransientBCInputFileReader> getReader(){ return reader; } + real getVelocityX() { return velocityX; } + real getVelocityY() { return velocityY; } + real getVelocityZ() { return velocityZ; } + +private: + PrecursorBoundaryCondition(SPtr<TransientBCInputFileReader> _reader, uint _timeStepsBetweenReads, real vx, real vy, real vz) : reader(_reader), timeStepsBetweenReads(_timeStepsBetweenReads), velocityX(vx), velocityY(vy), velocityZ(vz) { }; + virtual char getType() const override + { + return vf::gpu::BC_VELOCITY; + } +public: + uint timeStepsBetweenReads; //!> read data every nth timestep + +private: + real velocityX = 0.0; + real velocityY = 0.0; + real velocityZ = 0.0; + SPtr<TransientBCInputFileReader> reader; +}; #endif \ No newline at end of file diff --git a/src/gpu/GridGenerator/grid/BoundaryConditions/Side.cpp b/src/gpu/GridGenerator/grid/BoundaryConditions/Side.cpp index 6c7bf8ca1853826d83fb6a713ffe03716bd2cf9a..0900c2d587ba9811c480427b833e7e083216cf10 100644 --- a/src/gpu/GridGenerator/grid/BoundaryConditions/Side.cpp +++ b/src/gpu/GridGenerator/grid/BoundaryConditions/Side.cpp @@ -40,6 +40,18 @@ using namespace gg; +std::vector<real> Side::getNormal() +{ + std::vector<real> normal; + if(this->getCoordinate()==X_INDEX) + normal = {(real)this->getDirection(), 0.0, 0.0}; + if(this->getCoordinate()==Y_INDEX) + normal = {0.0, (real)this->getDirection(), 0.0}; + if(this->getCoordinate()==Z_INDEX) + normal = {0.0, 0.0, (real)this->getDirection()}; + return normal; +} + void Side::addIndices(SPtr<Grid> grid, SPtr<BoundaryCondition> boundaryCondition, std::string coord, real constant, real startInner, real endInner, real startOuter, real endOuter) { @@ -49,11 +61,19 @@ void Side::addIndices(SPtr<Grid> grid, SPtr<BoundaryCondition> boundaryCondition { const uint index = getIndex(grid, coord, constant, v1, v2); - if ((index != INVALID_INDEX) && ( grid->getFieldEntry(index) == vf::gpu::FLUID - || grid->getFieldEntry(index) == vf::gpu::FLUID_CFC - || grid->getFieldEntry(index) == vf::gpu::FLUID_CFF - || grid->getFieldEntry(index) == vf::gpu::FLUID_FCC - || grid->getFieldEntry(index) == vf::gpu::FLUID_FCF )) + if ((index != INVALID_INDEX) && ( grid->getFieldEntry(index) == vf::gpu::FLUID + || grid->getFieldEntry(index) == vf::gpu::FLUID_CFC + || grid->getFieldEntry(index) == vf::gpu::FLUID_CFF + || grid->getFieldEntry(index) == vf::gpu::FLUID_FCC + || grid->getFieldEntry(index) == vf::gpu::FLUID_FCF + || grid->getFieldEntry(index) == vf::gpu::FLUID_FCF + + //! Enforce overlap of BCs on edge nodes + || grid->getFieldEntry(index) == vf::gpu::BC_PRESSURE + || grid->getFieldEntry(index) == vf::gpu::BC_VELOCITY + || grid->getFieldEntry(index) == vf::gpu::BC_NOSLIP + || grid->getFieldEntry(index) == vf::gpu::BC_SLIP + || grid->getFieldEntry(index) == vf::gpu::BC_STRESS )) { grid->setFieldEntry(index, boundaryCondition->getType()); boundaryCondition->indices.push_back(index); @@ -64,7 +84,6 @@ void Side::addIndices(SPtr<Grid> grid, SPtr<BoundaryCondition> boundaryCondition boundaryCondition->patches.push_back(0); } - } } } @@ -152,16 +171,21 @@ void Side::setQs(SPtr<Grid> grid, SPtr<BoundaryCondition> boundaryCondition, uin else neighborZ = grid->getLastFluidNode ( coords, 2, grid->getEndZ() ); } + //! Only seting q's that partially point in the Side-normal direction + bool alignedWithNormal = (this->getNormal()[0]*grid->getDirection()[dir * DIMENSION + 0]+ + this->getNormal()[1]*grid->getDirection()[dir * DIMENSION + 1]+ + this->getNormal()[2]*grid->getDirection()[dir * DIMENSION + 2] ) > 0; + uint neighborIndex = grid->transCoordToIndex( neighborX, neighborY, neighborZ ); - if( grid->getFieldEntry(neighborIndex) == vf::gpu::STOPPER_OUT_OF_GRID_BOUNDARY || - grid->getFieldEntry(neighborIndex) == vf::gpu::STOPPER_OUT_OF_GRID || - grid->getFieldEntry(neighborIndex) == vf::gpu::STOPPER_SOLID ) + if((grid->getFieldEntry(neighborIndex) == vf::gpu::STOPPER_OUT_OF_GRID_BOUNDARY || + grid->getFieldEntry(neighborIndex) == vf::gpu::STOPPER_OUT_OF_GRID || + grid->getFieldEntry(neighborIndex) == vf::gpu::STOPPER_SOLID) && + alignedWithNormal ) qNode[dir] = 0.5; else qNode[dir] = -1.0; - } - + boundaryCondition->qs.push_back(qNode); } @@ -260,7 +284,7 @@ void MY::addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<BoundaryCond real coordinateNormal = grid[level]->getStartY() + grid[level]->getDelta(); if( coordinateNormal > grid[0]->getStartY() + grid[0]->getDelta() ) return; - + Side::addIndices(grid[level], boundaryCondition, "y", coordinateNormal, startInner, endInner, startOuter, endOuter); } diff --git a/src/gpu/GridGenerator/grid/BoundaryConditions/Side.h b/src/gpu/GridGenerator/grid/BoundaryConditions/Side.h index 6df6bfccc9a39b80de3ac43d057a03945d035b34..53a763bc562ee978042b28d24856fbcca256c5f9 100644 --- a/src/gpu/GridGenerator/grid/BoundaryConditions/Side.h +++ b/src/gpu/GridGenerator/grid/BoundaryConditions/Side.h @@ -72,15 +72,17 @@ public: virtual SideType whoAmI() const = 0; + std::vector<real> getNormal(); + protected: - static void addIndices(SPtr<Grid> grid, SPtr<gg::BoundaryCondition> boundaryCondition, std::string coord, real constant, + void addIndices(SPtr<Grid> grid, SPtr<gg::BoundaryCondition> boundaryCondition, std::string coord, real constant, real startInner, real endInner, real startOuter, real endOuter); static void setPressureNeighborIndices(SPtr<gg::BoundaryCondition> boundaryCondition, SPtr<Grid> grid, const uint index); static void setStressSamplingIndices(SPtr<gg::BoundaryCondition> boundaryCondition, SPtr<Grid> grid, const uint index); - static void setQs(SPtr<Grid> grid, SPtr<gg::BoundaryCondition> boundaryCondition, uint index); + void setQs(SPtr<Grid> grid, SPtr<gg::BoundaryCondition> boundaryCondition, uint index); private: static uint getIndex(SPtr<Grid> grid, std::string coord, real constant, real v1, real v2); diff --git a/src/gpu/GridGenerator/grid/Grid.h b/src/gpu/GridGenerator/grid/Grid.h index 3f28120a5d969fcc5d7b2a3402a2169ff97c0cc3..85b19bedd470c9856954a1ca20fb446c3d875da2 100644 --- a/src/gpu/GridGenerator/grid/Grid.h +++ b/src/gpu/GridGenerator/grid/Grid.h @@ -178,6 +178,21 @@ public: virtual void findFluidNodeIndicesBorder() = 0; virtual uint getNumberOfFluidNodesBorder() const = 0; virtual void getFluidNodeIndicesBorder(uint *fluidNodeIndicesBorder) const = 0; + + virtual void addFluidNodeIndicesMacroVars(std::vector<uint> _fluidNodeIndicesMacroVars) = 0; + virtual void addFluidNodeIndicesApplyBodyForce(std::vector<uint> _fluidNodeIndicesApplyBodyForce) = 0; + virtual void addFluidNodeIndicesAllFeatures(std::vector<uint> _fluidNodeIndicesAllFeatures) = 0; + virtual void sortFluidNodeIndicesMacroVars() = 0; + virtual void sortFluidNodeIndicesApplyBodyForce() = 0; + virtual void sortFluidNodeIndicesAllFeatures() = 0; + + virtual uint getNumberOfFluidNodeIndicesMacroVars() const = 0; + virtual uint getNumberOfFluidNodeIndicesApplyBodyForce() const = 0; + virtual uint getNumberOfFluidNodeIndicesAllFeatures() const = 0; + virtual void getFluidNodeIndicesMacroVars(uint *fluidNodeIndicesMacroVars) const = 0; + virtual void getFluidNodeIndicesApplyBodyForce(uint *fluidNodeIndicesApplyBodyForce) const = 0; + virtual void getFluidNodeIndicesAllFeatures(uint *fluidNodeIndicesAllFeatures) const = 0; + }; #endif diff --git a/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h b/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h index 739aef59f76a33fa67d472a77ef258469f5e411c..065665d216e3cf7904530b94c8bb6480bb565c8a 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h +++ b/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h @@ -54,6 +54,7 @@ class GridWrapper; class Transformator; class ArrowTransformator; class PolyDataWriterWrapper; +class TransientBCInputFileReader; class BoundingBox; class Grid; @@ -113,6 +114,15 @@ public: virtual void getPressureValues(real *rho, int *indices, int *neighborIndices, int level) const = 0; virtual void getPressureQs(real *qs[27], int level) const = 0; + virtual uint getPrecursorSize(int level) const = 0; + virtual void getPrecursorValues(uint* neighbor0PP, uint* neighbor0PM, uint* neighbor0MP, uint* neighbor0MM, + real* weights0PP, real* weights0PM, real* weights0MP, real* weights0MM, + int* indices, std::vector<SPtr<TransientBCInputFileReader>>& reader, + int& numberOfPrecursorNodes, size_t& numberOfQuantities, uint& timeStepsBetweenReads, + real& velocityX, real& velocityY, real& velocityZ, int level) const = 0; + + virtual void getPrecursorQs(real* qs[27], int level) const = 0; + virtual uint getGeometrySize(int level) const = 0; virtual void getGeometryIndices(int *indices, int level) const = 0; virtual void getGeometryQs(real *qs[27], int level) const = 0; @@ -136,6 +146,21 @@ public: virtual void getReceiveIndices(int *sendIndices, int direction, int level) = 0; virtual void findFluidNodes(bool splitDomain) = 0; + + virtual void addFluidNodeIndicesMacroVars(const std::vector<uint>& fluidNodeIndicesMacroVars, uint level) = 0; + virtual void addFluidNodeIndicesApplyBodyForce(const std::vector<uint>& fluidNodeIndicesApplyBodyForce, uint level) = 0; + virtual void addFluidNodeIndicesAllFeatures(const std::vector<uint>& fluidNodeIndicesAllFeatures, uint level) = 0; + virtual void sortFluidNodeIndicesMacroVars(uint level) = 0; + virtual void sortFluidNodeIndicesApplyBodyForce(uint level) = 0; + virtual void sortFluidNodeIndicesAllFeatures(uint level) = 0; + virtual uint getNumberOfFluidNodesMacroVars(uint level) const = 0; + virtual void getFluidNodeIndicesMacroVars(uint *fluidNodeIndicesMacroVars, int level) const = 0; + virtual uint getNumberOfFluidNodesApplyBodyForce(uint level) const = 0; + virtual void getFluidNodeIndicesApplyBodyForce(uint *fluidNodeIndicesApplyBodyForce, int level) const = 0; + virtual uint getNumberOfFluidNodesAllFeatures(uint level) const = 0; + virtual void getFluidNodeIndicesAllFeatures(uint *fluidNodeIndicesAllFeatures, int level) const = 0; + + }; #endif \ No newline at end of file diff --git a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp index 083b9a51e0b151f49922df456e968c4b204e4af7..ff6f4913e4cd8a32c05272ef583f90a2cf226edc 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp +++ b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp @@ -52,6 +52,8 @@ #include "io/QLineWriter.h" #include "io/SimulationFileWriter/SimulationFileWriter.h" +#include "TransientBCSetter/TransientBCSetter.h" + #include "utilities/communication.h" #include "utilities/transformator/ArrowTransformator.h" @@ -117,14 +119,19 @@ void LevelGridBuilder::setSlipGeometryBoundaryCondition(real normalX, real norma } } +//======================================================================================= +//! \brief Set stress boundary concdition using iMEM +//! \param samplingOffset number of grid points above boundary where velocity for wall model is sampled +//! \param z0 roughness length [m] +//! \param dx dx of level 0 [m] +//! void LevelGridBuilder::setStressBoundaryCondition( SideType sideType, real nomalX, real normalY, real normalZ, - uint samplingOffset, real z0) + uint samplingOffset, real z0, real dx) { for (uint level = 0; level < getNumberOfGridLevels(); level++) { - SPtr<StressBoundaryCondition> stressBoundaryCondition = StressBoundaryCondition::make(nomalX, normalY, normalZ, samplingOffset, z0); - + SPtr<StressBoundaryCondition> stressBoundaryCondition = StressBoundaryCondition::make(nomalX, normalY, normalZ, samplingOffset, z0*pow(2.0f,level)/dx); auto side = SideFactory::make(sideType); stressBoundaryCondition->side = side; @@ -243,6 +250,39 @@ void LevelGridBuilder::setNoSlipGeometryBoundaryCondition() } } +void LevelGridBuilder::setPrecursorBoundaryCondition(SideType sideType, SPtr<FileCollection> fileCollection, int timeStepsBetweenReads, + real velocityX, real velocityY, real velocityZ, std::vector<uint> fileLevelToGridLevelMap) +{ + if(fileLevelToGridLevelMap.empty()) + { + *logging::out << logging::Logger::INFO_INTERMEDIATE << "Mapping precursor file levels to the corresponding grid levels" << "\n"; + + for (uint level = 0; level < getNumberOfGridLevels(); level++) + fileLevelToGridLevelMap.push_back(level); + } + else + { + if(fileLevelToGridLevelMap.size()!=getNumberOfGridLevels()) + throw std::runtime_error("In setPrecursorBoundaryCondition: fileLevelToGridLevelMap does not match with the number of levels"); + *logging::out << logging::Logger::INFO_INTERMEDIATE << "Using user defined file to grid level mapping" << "\n"; + } + + for (uint level = 0; level < getNumberOfGridLevels(); level++) + { + auto reader = createReaderForCollection(fileCollection, fileLevelToGridLevelMap[level]); + SPtr<PrecursorBoundaryCondition> precursorBoundaryCondition = PrecursorBoundaryCondition::make( reader, timeStepsBetweenReads, velocityX, velocityY, velocityZ); + + auto side = SideFactory::make(sideType); + + precursorBoundaryCondition->side = side; + precursorBoundaryCondition->side->addIndices(grids, level, precursorBoundaryCondition); + + boundaryConditions[level]->precursorBoundaryConditions.push_back(precursorBoundaryCondition); + + *logging::out << logging::Logger::INFO_INTERMEDIATE << "Set Precursor BC on level " << level << " with " << (int)precursorBoundaryCondition->indices.size() << "\n"; + } +} + GRIDGENERATOR_EXPORT void LevelGridBuilder::setEnableFixRefinementIntoTheWall(bool enableFixRefinementIntoTheWall) { for (uint level = 0; level < this->grids.size(); level++) @@ -594,6 +634,86 @@ void LevelGridBuilder::getPressureQs(real* qs[27], int level) const } } +uint LevelGridBuilder::getPrecursorSize(int level) const +{ + uint size = 0; + for (auto boundaryCondition : boundaryConditions[level]->precursorBoundaryConditions) + { + size += uint(boundaryCondition->indices.size()); + } + return size; +} + +void LevelGridBuilder::getPrecursorValues( uint* neighbor0PP, uint* neighbor0PM, uint* neighbor0MP, uint* neighbor0MM, + real* weights0PP, real* weights0PM, real* weights0MP, real* weights0MM, + int* indices, std::vector<SPtr<TransientBCInputFileReader>>& reader, + int& numberOfPrecursorNodes, size_t& numberOfQuantities, uint& timeStepsBetweenReads, + real& velocityX, real& velocityY, real& velocityZ, int level) const +{ + int allIndicesCounter = 0; + int allNodesCounter = 0; + uint tmpTimeStepsBetweenReads = 0; + size_t tmpNumberOfQuantities = 0; + + for (auto boundaryCondition : boundaryConditions[level]->precursorBoundaryConditions) + { + if( tmpTimeStepsBetweenReads == 0 ) + tmpTimeStepsBetweenReads = boundaryCondition->timeStepsBetweenReads; + if( tmpTimeStepsBetweenReads != boundaryCondition->timeStepsBetweenReads ) + throw std::runtime_error("All precursor boundary conditions must have the same timeStepsBetweenReads value"); + auto BCreader = boundaryCondition->getReader(); + BCreader->setWritingOffset(allIndicesCounter); + reader.push_back(BCreader); + + std::vector<real> y, z; + real xTmp, yTmp, zTmp; + for(uint i = 0; i<boundaryCondition->indices.size(); i++) + { + indices[allIndicesCounter] = grids[level]->getSparseIndex(boundaryCondition->indices[i]) + 1; + grids[level]->transIndexToCoords(boundaryCondition->indices[i], xTmp, yTmp, zTmp); + y.push_back(yTmp); + z.push_back(zTmp); + allIndicesCounter++; + } + BCreader->fillArrays(y, z); + BCreader->getNeighbors(neighbor0PP, neighbor0PM, neighbor0MP, neighbor0MM); + BCreader->getWeights(weights0PP, weights0PM, weights0MP, weights0MM); + if(tmpNumberOfQuantities == 0) + tmpNumberOfQuantities = BCreader->getNumberOfQuantities(); + if(tmpNumberOfQuantities != BCreader->getNumberOfQuantities()) + throw std::runtime_error("All precursor files must have the same quantities."); + allNodesCounter += BCreader->getNPointsRead(); + velocityX = boundaryCondition->getVelocityX(); + velocityY = boundaryCondition->getVelocityY(); + velocityZ = boundaryCondition->getVelocityZ(); + } + numberOfPrecursorNodes = allNodesCounter; + + if (tmpTimeStepsBetweenReads == 0) + throw std::runtime_error("timeStepsBetweenReads of precursor needs to be larger than 0."); + timeStepsBetweenReads = tmpTimeStepsBetweenReads; + + if (tmpNumberOfQuantities == 0) + throw std::runtime_error("Number of quantities in precursor needs to be larger than 0."); + numberOfQuantities = tmpNumberOfQuantities; +} + +void LevelGridBuilder::getPrecursorQs(real* qs[27], int level) const +{ + int allIndicesCounter = 0; + for (auto boundaryCondition : boundaryConditions[level]->precursorBoundaryConditions) + { + for ( uint index = 0; index < boundaryCondition->indices.size(); index++ ) + { + for (int dir = 0; dir <= grids[level]->getEndDirection(); dir++) + { + qs[dir][allIndicesCounter] = boundaryCondition->qs[index][dir]; + } + allIndicesCounter++; + } + } +} + uint LevelGridBuilder::getGeometrySize(int level) const { if (boundaryConditions[level]->geometryBoundaryCondition) @@ -674,4 +794,65 @@ void LevelGridBuilder::findFluidNodes(bool splitDomain) for (uint i = 0; i < grids.size(); i++) grids[i]->findFluidNodeIndices(splitDomain); *logging::out << logging::Logger::INFO_HIGH << "Done with findFluidNodes()\n"; +} + + +void LevelGridBuilder::addFluidNodeIndicesMacroVars(const std::vector<uint>& fluidNodeIndicesMacroVars, uint level) +{ + grids[level]->addFluidNodeIndicesMacroVars(fluidNodeIndicesMacroVars); +} + +void LevelGridBuilder::addFluidNodeIndicesApplyBodyForce(const std::vector<uint>& fluidNodeIndicesApplyBodyForce, uint level) +{ + grids[level]->addFluidNodeIndicesApplyBodyForce(fluidNodeIndicesApplyBodyForce); +} + +void LevelGridBuilder::addFluidNodeIndicesAllFeatures(const std::vector<uint>& fluidNodeIndicesAllFeatures, uint level) +{ + grids[level]->addFluidNodeIndicesAllFeatures(fluidNodeIndicesAllFeatures); +} + +void LevelGridBuilder::sortFluidNodeIndicesMacroVars(uint level) +{ + grids[level]->sortFluidNodeIndicesMacroVars(); +} + +void LevelGridBuilder::sortFluidNodeIndicesApplyBodyForce(uint level) +{ + grids[level]->sortFluidNodeIndicesApplyBodyForce(); +} + +void LevelGridBuilder::sortFluidNodeIndicesAllFeatures(uint level) +{ + grids[level]->sortFluidNodeIndicesAllFeatures(); +} + +uint LevelGridBuilder::getNumberOfFluidNodesMacroVars(unsigned int level) const +{ + return grids[level]->getNumberOfFluidNodeIndicesMacroVars(); +} + +void LevelGridBuilder::getFluidNodeIndicesMacroVars(uint *fluidNodeIndicesMacroVars, const int level) const +{ + grids[level]->getFluidNodeIndicesMacroVars(fluidNodeIndicesMacroVars); +} + +uint LevelGridBuilder::getNumberOfFluidNodesApplyBodyForce(unsigned int level) const +{ + return grids[level]->getNumberOfFluidNodeIndicesApplyBodyForce(); +} + +void LevelGridBuilder::getFluidNodeIndicesApplyBodyForce(uint *fluidNodeIndicesApplyBodyForce, const int level) const +{ + grids[level]->getFluidNodeIndicesApplyBodyForce(fluidNodeIndicesApplyBodyForce); +} + +uint LevelGridBuilder::getNumberOfFluidNodesAllFeatures(unsigned int level) const +{ + return grids[level]->getNumberOfFluidNodeIndicesAllFeatures(); +} + +void LevelGridBuilder::getFluidNodeIndicesAllFeatures(uint *fluidNodeIndicesAllFeatures, const int level) const +{ + grids[level]->getFluidNodeIndicesAllFeatures(fluidNodeIndicesAllFeatures); } \ No newline at end of file diff --git a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h index afb027fc1665ab874523bf39ec2a05518d28f7a1..56ae1e4fce6185591fba97f49ba504ced259aea5 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h +++ b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h @@ -38,6 +38,8 @@ #include <memory> #include <array> +#include <lbm/constants/NumericConstants.h> + #include "gpu/GridGenerator/global.h" #include "gpu/GridGenerator/grid/GridBuilder/GridBuilder.h" @@ -45,6 +47,8 @@ #include "gpu/GridGenerator/grid/GridInterface.h" #include "gpu/GridGenerator/grid/NodeValues.h" +using namespace vf::lbm::constant; + struct Vertex; class Grid; class Transformator; @@ -58,9 +62,11 @@ class SlipBoundaryCondition; class StressBoundaryCondition; class PressureBoundaryCondition; class GeometryBoundaryCondition; +class PrecursorBoundaryCondition; enum class SideType; - +class TransientBCInputFileReader; +class FileCollection; class LevelGridBuilder : public GridBuilder { @@ -75,11 +81,14 @@ public: GRIDGENERATOR_EXPORT ~LevelGridBuilder() override; GRIDGENERATOR_EXPORT void setSlipBoundaryCondition(SideType sideType, real nomalX, real normalY, real normalZ); - GRIDGENERATOR_EXPORT void setStressBoundaryCondition(SideType sideType, real nomalX, real normalY, real normalZ, uint samplingOffset, real z0); + GRIDGENERATOR_EXPORT void setStressBoundaryCondition(SideType sideType, real nomalX, real normalY, real normalZ, uint samplingOffset, real z0, real dx); GRIDGENERATOR_EXPORT void setVelocityBoundaryCondition(SideType sideType, real vx, real vy, real vz); GRIDGENERATOR_EXPORT void setPressureBoundaryCondition(SideType sideType, real rho); GRIDGENERATOR_EXPORT void setPeriodicBoundaryCondition(bool periodic_X, bool periodic_Y, bool periodic_Z); GRIDGENERATOR_EXPORT void setNoSlipBoundaryCondition(SideType sideType); + GRIDGENERATOR_EXPORT void setPrecursorBoundaryCondition(SideType sideType, SPtr<FileCollection> fileCollection, int timeStepsBetweenReads, + real velocityX=c0o1, real velocityY=c0o1, real velocityZ=c0o1, + std::vector<uint> fileLevelToGridLevelMap = {}); GRIDGENERATOR_EXPORT void setEnableFixRefinementIntoTheWall(bool enableFixRefinementIntoTheWall); @@ -121,6 +130,14 @@ public: GRIDGENERATOR_EXPORT void getPressureValues(real* rho, int* indices, int* neighborIndices, int level) const override; GRIDGENERATOR_EXPORT virtual void getPressureQs(real* qs[27], int level) const override; + GRIDGENERATOR_EXPORT uint getPrecursorSize(int level) const override; + GRIDGENERATOR_EXPORT void getPrecursorValues( uint* neighbor0PP, uint* neighbor0PM, uint* neighbor0MP, uint* neighbor0MM, + real* weights0PP, real* weights0PM, real* weights0MP, real* weights0MM, + int* indices, std::vector<SPtr<TransientBCInputFileReader>>& reader, + int& numberOfPrecursorNodes, size_t& numberOfQuantities, uint& timeStepsBetweenReads, + real& velocityX, real& velocityY, real& velocityZ, int level) const override; + GRIDGENERATOR_EXPORT virtual void getPrecursorQs(real* qs[27], int level) const override; + GRIDGENERATOR_EXPORT virtual void getGeometryQs(real *qs[27], int level) const override; GRIDGENERATOR_EXPORT virtual uint getGeometrySize(int level) const override; GRIDGENERATOR_EXPORT virtual void getGeometryIndices(int *indices, int level) const override; @@ -149,6 +166,8 @@ protected: std::vector<SPtr<VelocityBoundaryCondition>> noSlipBoundaryConditions; + std::vector<SPtr<PrecursorBoundaryCondition>> precursorBoundaryConditions; + SPtr<GeometryBoundaryCondition> geometryBoundaryCondition; }; bool geometryHasValues = false; @@ -194,6 +213,21 @@ public: // needed for CUDA Streams MultiGPU (Communication Hiding) void findFluidNodes(bool splitDomain) override; + + void addFluidNodeIndicesMacroVars(const std::vector<uint>& fluidNodeIndicesMacroVars, uint level) override; + void addFluidNodeIndicesApplyBodyForce(const std::vector<uint>& fluidNodeIndicesApplyBodyForce, uint level) override; + void addFluidNodeIndicesAllFeatures(const std::vector<uint>& fluidNodeIndicesAllFeatures, uint level) override; + + void sortFluidNodeIndicesMacroVars(uint level) override; + void sortFluidNodeIndicesApplyBodyForce(uint level) override; + void sortFluidNodeIndicesAllFeatures(uint level) override; + + uint getNumberOfFluidNodesMacroVars(unsigned int level) const override; + void getFluidNodeIndicesMacroVars(uint *fluidNodeIndicesMacroVars, const int level) const override; + uint getNumberOfFluidNodesApplyBodyForce(unsigned int level) const override; + void getFluidNodeIndicesApplyBodyForce(uint *fluidNodeIndicesApplyBodyForce, const int level) const override; + uint getNumberOfFluidNodesAllFeatures(unsigned int level) const override; + void getFluidNodeIndicesAllFeatures(uint *fluidNodeIndicesAllFeatures, const int level) const override; }; #endif diff --git a/src/gpu/GridGenerator/grid/GridImp.cpp b/src/gpu/GridGenerator/grid/GridImp.cpp index 31bbf3ddc87184846fcb01a3e6631358b6a6f864..24dd169e70288b9ae18a29c23dc0c74b14246e3f 100644 --- a/src/gpu/GridGenerator/grid/GridImp.cpp +++ b/src/gpu/GridGenerator/grid/GridImp.cpp @@ -1154,7 +1154,7 @@ void GridImp::limitToSubDomain(SPtr<BoundingBox> subDomainBox, LbmOrGks lbmOrGks // one layer for receive nodes and one for stoppers if( lbmOrGks == LBM ) tmpSubDomainBox.extend(this->delta); - + if (!tmpSubDomainBox.isInside(x, y, z) && ( this->getFieldEntry(index) == FLUID || this->getFieldEntry(index) == FLUID_CFC || @@ -1162,7 +1162,7 @@ void GridImp::limitToSubDomain(SPtr<BoundingBox> subDomainBox, LbmOrGks lbmOrGks this->getFieldEntry(index) == FLUID_FCC || this->getFieldEntry(index) == FLUID_FCF || this->getFieldEntry(index) == BC_SOLID ) ) - { + { this->setFieldEntry(index, STOPPER_OUT_OF_GRID_BOUNDARY); } } @@ -1648,10 +1648,9 @@ bool GridImp::checkIfAtLeastOneValidQ(const uint index, const Vertex & point, co void GridImp::findCommunicationIndices(int direction, SPtr<BoundingBox> subDomainBox, LbmOrGks lbmOrGks) { for( uint index = 0; index < this->size; index++ ){ - real x, y, z; this->transIndexToCoords(index, x, y, z); - + if( this->getFieldEntry(index) == INVALID_OUT_OF_GRID || this->getFieldEntry(index) == INVALID_SOLID || this->getFieldEntry(index) == INVALID_COARSE_UNDER_FINE || @@ -1660,7 +1659,6 @@ void GridImp::findCommunicationIndices(int direction, SPtr<BoundingBox> subDomai if( lbmOrGks == LBM && this->getFieldEntry(index) == STOPPER_OUT_OF_GRID_BOUNDARY ) continue; if( lbmOrGks == LBM && this->getFieldEntry(index) == STOPPER_SOLID ) continue; - if( direction == CommunicationDirections::MX ) findCommunicationIndex( index, x, subDomainBox->minX, direction); if( direction == CommunicationDirections::PX ) findCommunicationIndex( index, x, subDomainBox->maxX, direction); if( direction == CommunicationDirections::MY ) findCommunicationIndex( index, y, subDomainBox->minY, direction); @@ -1674,14 +1672,11 @@ void GridImp::findCommunicationIndex( uint index, real coordinate, real limit, i // negative direction get a negative sign real s = ( direction % 2 == 0 ) ? ( -1.0 ) : ( 1.0 ); - - if (std::abs(coordinate - (limit + s * 0.5 * this->delta)) < 0.1 * this->delta) { + if (std::abs(coordinate - (limit + s * 0.5 * this->delta)) < 0.1 * this->delta) this->communicationIndices[direction].receiveIndices.push_back(index); - } - if (std::abs(coordinate - (limit - s * 0.5 * this->delta)) < 0.1 * this->delta) { + if (std::abs(coordinate - (limit - s * 0.5 * this->delta)) < 0.1 * this->delta) this->communicationIndices[direction].sendIndices.push_back(index); - } } bool GridImp::isSendNode(int index) const @@ -2080,6 +2075,124 @@ void GridImp::getFluidNodeIndicesBorder(uint *fluidNodeIndicesBorder) const fluidNodeIndicesBorder[nodeNumber] = this->fluidNodeIndicesBorder[nodeNumber]; } +void GridImp::addFluidNodeIndicesMacroVars(std::vector<uint> _fluidNodeIndicesMacroVars) +{ + size_t newSize = this->fluidNodeIndicesMacroVars.size()+_fluidNodeIndicesMacroVars.size(); + this->fluidNodeIndicesMacroVars.reserve(newSize); + std::copy(_fluidNodeIndicesMacroVars.begin(), _fluidNodeIndicesMacroVars.end(), std::back_inserter(this->fluidNodeIndicesMacroVars)); +} + +void GridImp::addFluidNodeIndicesApplyBodyForce(std::vector<uint> _fluidNodeIndicesApplyBodyForce) +{ + + size_t newSize = this->fluidNodeIndicesApplyBodyForce.size()+_fluidNodeIndicesApplyBodyForce.size(); + this->fluidNodeIndicesApplyBodyForce.reserve(newSize); + std::copy(_fluidNodeIndicesApplyBodyForce.begin(), _fluidNodeIndicesApplyBodyForce.end(), std::back_inserter(this->fluidNodeIndicesApplyBodyForce)); +} + +void GridImp::addFluidNodeIndicesAllFeatures(std::vector<uint> _fluidNodeIndicesAllFeatures) +{ + + size_t newSize = this->fluidNodeIndicesAllFeatures.size()+_fluidNodeIndicesAllFeatures.size(); + this->fluidNodeIndicesAllFeatures.reserve(newSize); + std::copy(_fluidNodeIndicesAllFeatures.begin(), _fluidNodeIndicesAllFeatures.end(), std::back_inserter(this->fluidNodeIndicesAllFeatures)); +} + +void GridImp::sortFluidNodeIndicesMacroVars() +{ + if(this->fluidNodeIndicesMacroVars.size()>0) + { + sort(this->fluidNodeIndicesMacroVars.begin(), this->fluidNodeIndicesMacroVars.end()); + // Remove duplicates + this->fluidNodeIndicesMacroVars.erase( unique( this->fluidNodeIndicesMacroVars.begin(), this->fluidNodeIndicesMacroVars.end() ), this->fluidNodeIndicesMacroVars.end() ); + + // Remove indices of fluidNodeIndicesAllFeatures from fluidNodeIndicesMacroVars + if(this->fluidNodeIndicesAllFeatures.size()>0) + { + this->fluidNodeIndicesMacroVars.erase( std::remove_if( this->fluidNodeIndicesMacroVars.begin(), this->fluidNodeIndicesMacroVars.end(), + [&](auto x){return binary_search(fluidNodeIndicesAllFeatures.begin(),fluidNodeIndicesAllFeatures.end(),x);} ), + this->fluidNodeIndicesMacroVars.end() + ); + } + + // Remove indices of fluidNodeIndicesMacroVars from fluidNodeIndices + this->fluidNodeIndices.erase( std::remove_if( this->fluidNodeIndices.begin(), this->fluidNodeIndices.end(), + [&](auto x){return binary_search(fluidNodeIndicesMacroVars.begin(),fluidNodeIndicesMacroVars.end(),x);} ), + this->fluidNodeIndices.end() + ); + } +} + +void GridImp::sortFluidNodeIndicesApplyBodyForce() +{ + if(this->fluidNodeIndicesApplyBodyForce.size()>0) + { + sort(this->fluidNodeIndicesApplyBodyForce.begin(), this->fluidNodeIndicesApplyBodyForce.end()); + // Remove duplicates + this->fluidNodeIndicesApplyBodyForce.erase( unique( this->fluidNodeIndicesApplyBodyForce.begin(), this->fluidNodeIndicesApplyBodyForce.end() ), this->fluidNodeIndicesApplyBodyForce.end() ); + + // Remove indices of fluidNodeIndicesAllFeatures from fluidNodeIndicesMacroVars + if(this->fluidNodeIndicesAllFeatures.size()>0) + { + this->fluidNodeIndicesApplyBodyForce.erase( std::remove_if( this->fluidNodeIndicesApplyBodyForce.begin(), this->fluidNodeIndicesApplyBodyForce.end(), + [&](auto x){return binary_search(fluidNodeIndicesAllFeatures.begin(),fluidNodeIndicesAllFeatures.end(),x);} ), + this->fluidNodeIndicesApplyBodyForce.end() + ); + } + + // Remove indices of fluidNodeIndicesMacroVars from fluidNodeIndices + this->fluidNodeIndices.erase( std::remove_if( this->fluidNodeIndices.begin(), this->fluidNodeIndices.end(), + [&](auto x){return binary_search(fluidNodeIndicesApplyBodyForce.begin(),fluidNodeIndicesApplyBodyForce.end(),x);} ), + this->fluidNodeIndices.end() + ); + } +} + +void GridImp::sortFluidNodeIndicesAllFeatures() +{ + if(this->fluidNodeIndicesAllFeatures.size()>0) + { + sort(this->fluidNodeIndicesAllFeatures.begin(), this->fluidNodeIndicesAllFeatures.end()); + // Remove duplicates + this->fluidNodeIndicesAllFeatures.erase( unique( this->fluidNodeIndicesAllFeatures.begin(), this->fluidNodeIndicesAllFeatures.end() ), this->fluidNodeIndicesAllFeatures.end() ); + // Remove indices of fluidNodeIndicesMacroVars from fluidNodeIndices + this->fluidNodeIndices.erase( std::remove_if( this->fluidNodeIndices.begin(), this->fluidNodeIndices.end(), + [&](auto x){return binary_search(fluidNodeIndicesAllFeatures.begin(),fluidNodeIndicesAllFeatures.end(),x);} ), + this->fluidNodeIndices.end() + ); + } +} + +uint GridImp::getNumberOfFluidNodeIndicesMacroVars() const { + return (uint)this->fluidNodeIndicesMacroVars.size(); +} + +uint GridImp::getNumberOfFluidNodeIndicesApplyBodyForce() const { + return (uint)this->fluidNodeIndicesApplyBodyForce.size(); +} + +uint GridImp::getNumberOfFluidNodeIndicesAllFeatures() const { + return (uint)this->fluidNodeIndicesAllFeatures.size(); +} + +void GridImp::getFluidNodeIndicesMacroVars(uint *_fluidNodeIndicesMacroVars) const +{ + std::copy(fluidNodeIndicesMacroVars.begin(), fluidNodeIndicesMacroVars.end(), _fluidNodeIndicesMacroVars); +} +void GridImp::getFluidNodeIndicesApplyBodyForce(uint *_fluidNodeIndicesApplyBodyForce) const +{ + std::copy(fluidNodeIndicesApplyBodyForce.begin(), fluidNodeIndicesApplyBodyForce.end(), _fluidNodeIndicesApplyBodyForce); +} +void GridImp::getFluidNodeIndicesAllFeatures(uint *_fluidNodeIndicesAllFeatures) const +{ + std::copy(fluidNodeIndicesAllFeatures.begin(), fluidNodeIndicesAllFeatures.end(), _fluidNodeIndicesAllFeatures); +} + + + + + + void GridImp::print() const { printf("min: (%2.4f, %2.4f, %2.4f), max: (%2.4f, %2.4f, %2.4f), size: %d, delta: %2.4f\n", startX, startY, startZ, diff --git a/src/gpu/GridGenerator/grid/GridImp.h b/src/gpu/GridGenerator/grid/GridImp.h index edb5ca916bf68dcf992ea214dcddb2dc43810352..8283bf569e266b84f020334a306d93756b01c394 100644 --- a/src/gpu/GridGenerator/grid/GridImp.h +++ b/src/gpu/GridGenerator/grid/GridImp.h @@ -115,8 +115,11 @@ private: int *sparseIndices; - std::vector<uint> fluidNodeIndices; - std::vector<uint> fluidNodeIndicesBorder; + std::vector<uint> fluidNodeIndices; // run on CollisionTemplate::Default + std::vector<uint> fluidNodeIndicesBorder; // run on subdomain border nodes (CollisionTemplate::SubDomainBorder) + std::vector<uint> fluidNodeIndicesMacroVars; // run on CollisionTemplate::MacroVars + std::vector<uint> fluidNodeIndicesApplyBodyForce; // run on CollisionTemplate::ApplyBodyForce + std::vector<uint> fluidNodeIndicesAllFeatures; // run on CollisionTemplate::AllFeatures uint *qIndices; //maps from matrix index to qIndex real *qValues; @@ -364,6 +367,19 @@ public: uint getNumberOfFluidNodesBorder() const override; void getFluidNodeIndicesBorder(uint *fluidNodeIndicesBorder) const override; + void addFluidNodeIndicesMacroVars(std::vector<uint> _fluidNodeIndicesMacroVars) override; + void addFluidNodeIndicesApplyBodyForce(std::vector<uint> _fluidNodeIndicesApplyBodyForce) override; + void addFluidNodeIndicesAllFeatures(std::vector<uint> _fluidNodeIndicesAllFeatures) override; + void sortFluidNodeIndicesMacroVars() override; + void sortFluidNodeIndicesApplyBodyForce() override; + void sortFluidNodeIndicesAllFeatures() override; + + uint getNumberOfFluidNodeIndicesMacroVars() const override; + uint getNumberOfFluidNodeIndicesApplyBodyForce() const override; + uint getNumberOfFluidNodeIndicesAllFeatures() const override; + void getFluidNodeIndicesMacroVars(uint *fluidNodeIndicesMacroVars) const override; + void getFluidNodeIndicesApplyBodyForce(uint *fluidNodeIndicesApplyBodyForce) const override; + void getFluidNodeIndicesAllFeatures(uint *fluidNodeIndicesAllFeatures) const override; public: struct CommunicationIndices { diff --git a/src/gpu/VirtualFluids_GPU/Calculation/CollisisionStrategy.cpp b/src/gpu/VirtualFluids_GPU/Calculation/CollisisionStrategy.cpp index 4a14d19c10936f84379f332ef24f081f0ebb0cb7..49543f37df7fb54290f4ab6c09edb8d10c0b67be 100644 --- a/src/gpu/VirtualFluids_GPU/Calculation/CollisisionStrategy.cpp +++ b/src/gpu/VirtualFluids_GPU/Calculation/CollisisionStrategy.cpp @@ -39,8 +39,14 @@ void CollisionAndExchange_noStreams_indexKernel::operator()(UpdateGrid27 *update //! //! 1. run collision //! - updateGrid->collisionUsingIndices(level, t, para->getParD(level)->fluidNodeIndices, - para->getParD(level)->numberOfFluidNodes, -1); + for( CollisionTemplate tag: para->getParH(level)->allocatedBulkFluidNodeTags ) + { + updateGrid->collisionUsingIndices( level, t, + para->getParD(level)->taggedFluidNodeIndices[tag], + para->getParD(level)->numberOfTaggedFluidNodes[tag], + tag, + CudaStreamIndex::Legacy); + } //! 2. exchange information between GPUs updateGrid->exchangeMultiGPU_noStreams_withPrepare(level, false); @@ -61,28 +67,35 @@ void CollisionAndExchange_noStreams_oldKernel::operator()(UpdateGrid27 *updateGr void CollisionAndExchange_streams::operator()(UpdateGrid27 *updateGrid, Parameter *para, int level, unsigned int t) { - int borderStreamIndex = para->getStreamManager()->getBorderStreamIndex(); - int bulkStreamIndex = para->getStreamManager()->getBulkStreamIndex(); - //! \details steps: //! - //! 1. run collision for nodes which are at the border of the gpus/processes - //! - updateGrid->collisionUsingIndices(level, t, para->getParD(level)->fluidNodeIndicesBorder, - para->getParD(level)->numberOfFluidNodesBorder, borderStreamIndex); + //! 1. run collision for nodes which are at the border of the gpus/processes, running with WriteMacroVars in case probes sample on these nodes + //! + updateGrid->collisionUsingIndices( level, t, + para->getParD(level)->taggedFluidNodeIndices[CollisionTemplate::SubDomainBorder], + para->getParD(level)->numberOfTaggedFluidNodes[CollisionTemplate::SubDomainBorder], + CollisionTemplate::WriteMacroVars, + CudaStreamIndex::SubDomainBorder); //! 2. prepare the exchange between gpus (collect the send nodes for communication in a buffer on the gpu) and trigger bulk kernel execution when finished //! - updateGrid->prepareExchangeMultiGPU(level, borderStreamIndex); + updateGrid->prepareExchangeMultiGPU(level, CudaStreamIndex::SubDomainBorder); if (para->getUseStreams()) - para->getStreamManager()->triggerStartBulkKernel(borderStreamIndex); - - //! 3. launch the collision kernel for bulk nodes - //! - para->getStreamManager()->waitOnStartBulkKernelEvent(bulkStreamIndex); - updateGrid->collisionUsingIndices(level, t, para->getParD(level)->fluidNodeIndices, - para->getParD(level)->numberOfFluidNodes, bulkStreamIndex); - + para->getStreamManager()->triggerStartBulkKernel(CudaStreamIndex::SubDomainBorder); + + //! 3. launch the collision kernel for bulk nodes. This includes nodes with \param tag Default, WriteMacroVars, ApplyBodyForce, + //! or AllFeatures. All assigned tags are listed in \param allocatedBulkFluidNodeTags during initialization in Simulation::init + + para->getStreamManager()->waitOnStartBulkKernelEvent(CudaStreamIndex::Bulk); + + for( CollisionTemplate tag: para->getParH(level)->allocatedBulkFluidNodeTags ) + { + updateGrid->collisionUsingIndices( level, t, + para->getParD(level)->taggedFluidNodeIndices[tag], + para->getParD(level)->numberOfTaggedFluidNodes[tag], + tag, + CudaStreamIndex::Bulk); + } //! 4. exchange information between GPUs - updateGrid->exchangeMultiGPU(level, borderStreamIndex); + updateGrid->exchangeMultiGPU(level, CudaStreamIndex::SubDomainBorder); } diff --git a/src/gpu/VirtualFluids_GPU/Calculation/RefinementStrategy.cpp b/src/gpu/VirtualFluids_GPU/Calculation/RefinementStrategy.cpp index cd74216e1fbe7b718c72046ace4b7d2e7cf451fe..b8ca4e9c2020e17cd0192267ac5d931b510afc3a 100644 --- a/src/gpu/VirtualFluids_GPU/Calculation/RefinementStrategy.cpp +++ b/src/gpu/VirtualFluids_GPU/Calculation/RefinementStrategy.cpp @@ -38,67 +38,62 @@ void NoRefinement::operator()(UpdateGrid27 *updateGrid, Parameter *para, int lev void RefinementAndExchange_streams_exchangeInterface::operator()(UpdateGrid27 *updateGrid, Parameter *para, int level) { - int borderStreamIndex = para->getStreamManager()->getBorderStreamIndex(); - int bulkStreamIndex = para->getStreamManager()->getBulkStreamIndex(); - //! \details steps: //! //! 1. Interpolation fine to coarse for nodes which are at the border of the gpus/processes //! - updateGrid->fineToCoarse(level, ¶->getParD(level)->intFCBorder, para->getParD(level)->offFC, borderStreamIndex); + updateGrid->fineToCoarse(level, ¶->getParD(level)->intFCBorder, para->getParD(level)->offFC, CudaStreamIndex::SubDomainBorder); //! 2. prepare the exchange between gpus (collect the send nodes for communication in a buffer on the gpu) and trigger bulk kernel execution when finished //! - updateGrid->prepareExchangeMultiGPUAfterFtoC(level, borderStreamIndex); + updateGrid->prepareExchangeMultiGPUAfterFtoC(level, CudaStreamIndex::SubDomainBorder); if (para->getUseStreams()) - para->getStreamManager()->triggerStartBulkKernel(borderStreamIndex); + para->getStreamManager()->triggerStartBulkKernel(CudaStreamIndex::SubDomainBorder); //! 3. launch the bulk kernels for both interpolation processes (fine to coarse and coarse to fine) //! - para->getStreamManager()->waitOnStartBulkKernelEvent(bulkStreamIndex); - updateGrid->fineToCoarse(level, ¶->getParD(level)->intFCBulk, para->getParD(level)->offFCBulk, bulkStreamIndex); - updateGrid->coarseToFine(level, ¶->getParD(level)->intCFBulk, para->getParD(level)->offCFBulk, bulkStreamIndex); + para->getStreamManager()->waitOnStartBulkKernelEvent(CudaStreamIndex::Bulk); + updateGrid->fineToCoarse(level, ¶->getParD(level)->intFCBulk, para->getParD(level)->offFCBulk, CudaStreamIndex::SubDomainBorder); + updateGrid->coarseToFine(level, ¶->getParD(level)->intCFBulk, para->getParD(level)->offCFBulk, CudaStreamIndex::SubDomainBorder); //! 4. exchange information between GPUs (only nodes which are part of the interpolation) //! - updateGrid->exchangeMultiGPUAfterFtoC(level, borderStreamIndex); + updateGrid->exchangeMultiGPUAfterFtoC(level, CudaStreamIndex::SubDomainBorder); // 5. interpolation fine to coarse for nodes which are at the border of the gpus/processes //! - updateGrid->coarseToFine(level, ¶->getParD(level)->intCFBorder, para->getParD(level)->offCF, borderStreamIndex); + updateGrid->coarseToFine(level, ¶->getParD(level)->intCFBorder, para->getParD(level)->offCF, CudaStreamIndex::SubDomainBorder); cudaDeviceSynchronize(); } -void RefinementAndExchange_streams_exchangeAllNodes::operator()(UpdateGrid27 *updateGrid, Parameter *para, int level){ - int borderStreamIndex = para->getStreamManager()->getBorderStreamIndex(); - int bulkStreamIndex = para->getStreamManager()->getBulkStreamIndex(); - +void RefinementAndExchange_streams_exchangeAllNodes::operator()(UpdateGrid27 *updateGrid, Parameter *para, int level) +{ //! \details steps: //! //! 1. interpolation fine to coarse for nodes which are at the border of the gpus/processes //! - updateGrid->fineToCoarse(level, ¶->getParD(level)->intFCBorder, para->getParD(level)->offFC, borderStreamIndex); + updateGrid->fineToCoarse(level, ¶->getParD(level)->intFCBorder, para->getParD(level)->offFC, CudaStreamIndex::SubDomainBorder); //! 2. prepare the exchange between gpus (collect the send nodes for communication in a buffer on the gpu) and trigger bulk kernel execution when finished //! - updateGrid->prepareExchangeMultiGPU(level, borderStreamIndex); + updateGrid->prepareExchangeMultiGPU(level, CudaStreamIndex::SubDomainBorder); if (para->getUseStreams()) - para->getStreamManager()->triggerStartBulkKernel(borderStreamIndex); + para->getStreamManager()->triggerStartBulkKernel(CudaStreamIndex::SubDomainBorder); //! 3. launch the bulk kernels for both interpolation processes (fine to coarse and coarse to fine) //! - para->getStreamManager()->waitOnStartBulkKernelEvent(bulkStreamIndex); - updateGrid->fineToCoarse(level, ¶->getParD(level)->intFCBulk, para->getParD(level)->offFCBulk, bulkStreamIndex); - updateGrid->coarseToFine(level, ¶->getParD(level)->intCFBulk, para->getParD(level)->offCFBulk, bulkStreamIndex); + para->getStreamManager()->waitOnStartBulkKernelEvent(CudaStreamIndex::Bulk); + updateGrid->fineToCoarse(level, ¶->getParD(level)->intFCBulk, para->getParD(level)->offFCBulk, CudaStreamIndex::SubDomainBorder); + updateGrid->coarseToFine(level, ¶->getParD(level)->intCFBulk, para->getParD(level)->offCFBulk, CudaStreamIndex::SubDomainBorder); //! 4. exchange information between GPUs (all nodes) //! - updateGrid->exchangeMultiGPU(level, borderStreamIndex); + updateGrid->exchangeMultiGPU(level, CudaStreamIndex::SubDomainBorder); // 5. interpolation fine to coarse for nodes which are at the border of the gpus/processes //! - updateGrid->coarseToFine(level, ¶->getParD(level)->intCFBorder, para->getParD(level)->offCF, borderStreamIndex); + updateGrid->coarseToFine(level, ¶->getParD(level)->intCFBorder, para->getParD(level)->offCF, CudaStreamIndex::SubDomainBorder); cudaDeviceSynchronize(); } @@ -109,14 +104,14 @@ void RefinementAndExchange_noStreams_exchangeInterface::operator()(UpdateGrid27 //! //! 1. interpolation fine to coarse //! - updateGrid->fineToCoarse(level, ¶->getParD(level)->intFC, para->getParD(level)->offFC, -1); + updateGrid->fineToCoarse(level, ¶->getParD(level)->intFC, para->getParD(level)->offFC, CudaStreamIndex::Legacy); //! 2. exchange information between GPUs (only nodes which are part of the interpolation) //! updateGrid->exchangeMultiGPU_noStreams_withPrepare(level, true); //! 3. interpolation coarse to fine - updateGrid->coarseToFine(level, ¶->getParD(level)->intCF, para->getParD(level)->offCF, -1); + updateGrid->coarseToFine(level, ¶->getParD(level)->intCF, para->getParD(level)->offCF, CudaStreamIndex::Legacy); } void RefinementAndExchange_noStreams_exchangeAllNodes::operator()(UpdateGrid27 *updateGrid, Parameter *para, int level) @@ -125,14 +120,14 @@ void RefinementAndExchange_noStreams_exchangeAllNodes::operator()(UpdateGrid27 * //! //! 1. interpolation fine to coarse //! - updateGrid->fineToCoarse(level, ¶->getParD(level)->intFC, para->getParD(level)->offFC, -1); + updateGrid->fineToCoarse(level, ¶->getParD(level)->intFC, para->getParD(level)->offFC, CudaStreamIndex::Legacy); //! 2. exchange information between GPUs (all nodes) //! updateGrid->exchangeMultiGPU_noStreams_withPrepare(level, false); //! 3. interpolation coarse to fine - updateGrid->coarseToFine(level, ¶->getParD(level)->intCF, para->getParD(level)->offCF, -1); + updateGrid->coarseToFine(level, ¶->getParD(level)->intCF, para->getParD(level)->offCF, CudaStreamIndex::Legacy); } void Refinement_noExchange::operator()(UpdateGrid27 *updateGrid, Parameter *para, int level) @@ -141,7 +136,7 @@ void Refinement_noExchange::operator()(UpdateGrid27 *updateGrid, Parameter *para //! //! 1. interpolation fine to coarse //! - updateGrid->fineToCoarse(level, ¶->getParD(level)->intFC, para->getParD(level)->offFC, -1); + updateGrid->fineToCoarse(level, ¶->getParD(level)->intFC, para->getParD(level)->offFC, CudaStreamIndex::Legacy); //! 2. interpolation coarse to fine - updateGrid->coarseToFine(level, ¶->getParD(level)->intCF, para->getParD(level)->offCF, -1); + updateGrid->coarseToFine(level, ¶->getParD(level)->intCF, para->getParD(level)->offCF, CudaStreamIndex::Legacy); } diff --git a/src/gpu/VirtualFluids_GPU/Calculation/UpdateGrid27.cpp b/src/gpu/VirtualFluids_GPU/Calculation/UpdateGrid27.cpp index 296ab819c5538a6b6d6a6827b5c28cbc475af838..4136614dfbfc9e0d2fc1bf7f4b01624f94eabb6f 100644 --- a/src/gpu/VirtualFluids_GPU/Calculation/UpdateGrid27.cpp +++ b/src/gpu/VirtualFluids_GPU/Calculation/UpdateGrid27.cpp @@ -22,13 +22,17 @@ void UpdateGrid27::updateGrid(int level, unsigned int t) updateGrid(level + 1, t); } + ////////////////////////////////////////////////////////////////////////// + + interactWithProbes(level, t); + ////////////////////////////////////////////////////////////////////////// collision(this, para.get(), level, t); ////////////////////////////////////////////////////////////////////////// - postCollisionBC(level); + postCollisionBC(level, t); ////////////////////////////////////////////////////////////////////////// @@ -47,13 +51,14 @@ void UpdateGrid27::updateGrid(int level, unsigned int t) ////////////////////////////////////////////////////////////////////////// if( level != para->getFine() ) - { + { refinement(this, para.get(), level); } + ////////////////////////////////////////////////////////////////////////// + interactWithActuators(level, t); - interactWithProbes(level, t); } void UpdateGrid27::collisionAllNodes(int level, unsigned int t) @@ -71,15 +76,16 @@ void UpdateGrid27::collisionAllNodes(int level, unsigned int t) collisionAdvectionDiffusion(level); } -void UpdateGrid27::collisionUsingIndices(int level, unsigned int t, uint *fluidNodeIndices, uint numberOfFluidNodes, int stream) +void UpdateGrid27::collisionUsingIndices(int level, unsigned int t, uint *taggedFluidNodeIndices, uint numberOfTaggedFluidNodes, CollisionTemplate collisionTemplate, CudaStreamIndex stream) { - if (fluidNodeIndices != nullptr && numberOfFluidNodes != 0) - kernels.at(level)->runOnIndices(fluidNodeIndices, numberOfFluidNodes, stream); + if (taggedFluidNodeIndices != nullptr && numberOfTaggedFluidNodes != 0) + kernels.at(level)->runOnIndices(taggedFluidNodeIndices, numberOfTaggedFluidNodes, collisionTemplate, stream); else - std::cout << "In collision: fluidNodeIndices or numberOfFluidNodes not definded" + std::cout << "In collision: fluidNodeIndices or numberOfFluidNodes not defined" << std::endl; ////////////////////////////////////////////////////////////////////////// + //! \todo: AD collision and porousMedia should be called separately, not in collisionUsingIndices if (para->getSimulatePorousMedia()) collisionPorousMedia(level); @@ -118,21 +124,21 @@ void UpdateGrid27::collisionAdvectionDiffusion(int level) this->adKernelManager->runADcollisionKernel(level); } -void UpdateGrid27::prepareExchangeMultiGPU(int level, int streamIndex) +void UpdateGrid27::prepareExchangeMultiGPU(int level, CudaStreamIndex streamIndex) { prepareExchangeCollDataXGPU27AllNodes(para.get(), level, streamIndex); prepareExchangeCollDataYGPU27AllNodes(para.get(), level, streamIndex); prepareExchangeCollDataZGPU27AllNodes(para.get(), level, streamIndex); } -void UpdateGrid27::prepareExchangeMultiGPUAfterFtoC(int level, int streamIndex) +void UpdateGrid27::prepareExchangeMultiGPUAfterFtoC(int level, CudaStreamIndex streamIndex) { prepareExchangeCollDataXGPU27AfterFtoC(para.get(), level, streamIndex); prepareExchangeCollDataYGPU27AfterFtoC(para.get(), level, streamIndex); prepareExchangeCollDataZGPU27AfterFtoC(para.get(), level, streamIndex); } -void UpdateGrid27::exchangeMultiGPU(int level, int streamIndex) +void UpdateGrid27::exchangeMultiGPU(int level, CudaStreamIndex streamIndex) { ////////////////////////////////////////////////////////////////////////// // 3D domain decomposition @@ -168,30 +174,30 @@ void UpdateGrid27::exchangeMultiGPU_noStreams_withPrepare(int level, bool useRed // 3D domain decomposition if (useReducedComm) { // X - prepareExchangeCollDataXGPU27AfterFtoC(para.get(), level, -1); - exchangeCollDataXGPU27AfterFtoC(para.get(), comm, cudaMemoryManager.get(), level, -1); - scatterNodesFromRecvBufferXGPU27AfterFtoC(para.get(), level, -1); + prepareExchangeCollDataXGPU27AfterFtoC(para.get(), level, CudaStreamIndex::Legacy); + exchangeCollDataXGPU27AfterFtoC(para.get(), comm, cudaMemoryManager.get(), level, CudaStreamIndex::Legacy); + scatterNodesFromRecvBufferXGPU27AfterFtoC(para.get(), level, CudaStreamIndex::Legacy); // Y - prepareExchangeCollDataYGPU27AfterFtoC(para.get(), level, -1); - exchangeCollDataYGPU27AfterFtoC(para.get(), comm, cudaMemoryManager.get(), level, -1); - scatterNodesFromRecvBufferYGPU27AfterFtoC(para.get(), level, -1); + prepareExchangeCollDataYGPU27AfterFtoC(para.get(), level, CudaStreamIndex::Legacy); + exchangeCollDataYGPU27AfterFtoC(para.get(), comm, cudaMemoryManager.get(), level, CudaStreamIndex::Legacy); + scatterNodesFromRecvBufferYGPU27AfterFtoC(para.get(), level, CudaStreamIndex::Legacy); // Z - prepareExchangeCollDataZGPU27AfterFtoC(para.get(), level, -1); - exchangeCollDataZGPU27AfterFtoC(para.get(), comm, cudaMemoryManager.get(), level, -1); - scatterNodesFromRecvBufferZGPU27AfterFtoC(para.get(), level, -1); + prepareExchangeCollDataZGPU27AfterFtoC(para.get(), level, CudaStreamIndex::Legacy); + exchangeCollDataZGPU27AfterFtoC(para.get(), comm, cudaMemoryManager.get(), level, CudaStreamIndex::Legacy); + scatterNodesFromRecvBufferZGPU27AfterFtoC(para.get(), level, CudaStreamIndex::Legacy); } else { // X - prepareExchangeCollDataXGPU27AllNodes(para.get(), level, -1); - exchangeCollDataXGPU27AllNodes(para.get(), comm, cudaMemoryManager.get(), level, -1); - scatterNodesFromRecvBufferXGPU27AllNodes(para.get(), level, -1); + prepareExchangeCollDataXGPU27AllNodes(para.get(), level, CudaStreamIndex::Legacy); + exchangeCollDataXGPU27AllNodes(para.get(), comm, cudaMemoryManager.get(), level, CudaStreamIndex::Legacy); + scatterNodesFromRecvBufferXGPU27AllNodes(para.get(), level, CudaStreamIndex::Legacy); // Y - prepareExchangeCollDataYGPU27AllNodes(para.get(), level, -1); - exchangeCollDataYGPU27AllNodes(para.get(), comm, cudaMemoryManager.get(), level, -1); - scatterNodesFromRecvBufferYGPU27AllNodes(para.get(), level, -1); + prepareExchangeCollDataYGPU27AllNodes(para.get(), level, CudaStreamIndex::Legacy); + exchangeCollDataYGPU27AllNodes(para.get(), comm, cudaMemoryManager.get(), level, CudaStreamIndex::Legacy); + scatterNodesFromRecvBufferYGPU27AllNodes(para.get(), level, CudaStreamIndex::Legacy); // Z - prepareExchangeCollDataZGPU27AllNodes(para.get(), level, -1); - exchangeCollDataZGPU27AllNodes(para.get(), comm, cudaMemoryManager.get(), level, -1); - scatterNodesFromRecvBufferZGPU27AllNodes(para.get(), level, -1); + prepareExchangeCollDataZGPU27AllNodes(para.get(), level, CudaStreamIndex::Legacy); + exchangeCollDataZGPU27AllNodes(para.get(), comm, cudaMemoryManager.get(), level, CudaStreamIndex::Legacy); + scatterNodesFromRecvBufferZGPU27AllNodes(para.get(), level, CudaStreamIndex::Legacy); } ////////////////////////////////////////////////////////////////////////// @@ -204,7 +210,7 @@ void UpdateGrid27::exchangeMultiGPU_noStreams_withPrepare(int level, bool useRed exchangePostCollDataADZGPU27(para.get(), comm, cudaMemoryManager.get(), level); } } -void UpdateGrid27::exchangeMultiGPUAfterFtoC(int level, int streamIndex) +void UpdateGrid27::exchangeMultiGPUAfterFtoC(int level, CudaStreamIndex streamIndex) { ////////////////////////////////////////////////////////////////////////// // 3D domain decomposition @@ -227,9 +233,10 @@ void UpdateGrid27::exchangeMultiGPUAfterFtoC(int level, int streamIndex) } } -void UpdateGrid27::postCollisionBC(int level) +void UpdateGrid27::postCollisionBC(int level, uint t) { ////////////////////////////////////////////////////////////////////////// + // G E O M E T R Y // V E L O C I T Y (I N F L O W) this->bcKernelManager->runVelocityBCKernelPost(level); @@ -257,6 +264,10 @@ void UpdateGrid27::postCollisionBC(int level) // P R E S S U R E this->bcKernelManager->runPressureBCKernelPost(level); + ////////////////////////////////////////////////////////////////////////// + // P R E C U R S O R + this->bcKernelManager->runPrecursorBCKernelPost(level, t, cudaMemoryManager.get()); + ////////////////////////////////////////////////////////////////////////// // A D V E C T I O N D I F F U S I O N if (para->getDiffOn()) @@ -317,13 +328,12 @@ void UpdateGrid27::preCollisionBC(int level, unsigned int t) ////////////////////////////////////////////////////////////////////////////////// } -void UpdateGrid27::fineToCoarse(int level, InterpolationCellFC* icellFC, OffFC &offFC, - int streamIndex) +void UpdateGrid27::fineToCoarse(int level, InterpolationCellFC* icellFC, OffFC &offFC, CudaStreamIndex streamIndex) { gridScalingKernelManager->runFineToCoarseKernelLB(level, icellFC, offFC, streamIndex); if (para->getDiffOn()) { - if (streamIndex != -1) { + if (para->getStreamManager()->streamIsRegistered(streamIndex)) { printf("fineToCoarse Advection Diffusion not implemented"); // TODO return; } @@ -331,14 +341,13 @@ void UpdateGrid27::fineToCoarse(int level, InterpolationCellFC* icellFC, OffFC & } } -void UpdateGrid27::coarseToFine(int level, InterpolationCellCF* icellCF, OffCF &offCF, - int streamIndex) +void UpdateGrid27::coarseToFine(int level, InterpolationCellCF* icellCF, OffCF &offCF, CudaStreamIndex streamIndex) { this->gridScalingKernelManager->runCoarseToFineKernelLB(level, icellCF, offCF, streamIndex); if (para->getDiffOn()) { - if (streamIndex != -1){ + if(para->getStreamManager()->streamIsRegistered(streamIndex)){ printf("CoarseToFineWithStream Advection Diffusion not implemented"); // TODO return; } diff --git a/src/gpu/VirtualFluids_GPU/Calculation/UpdateGrid27.h b/src/gpu/VirtualFluids_GPU/Calculation/UpdateGrid27.h index 8110923bf066412e2bb09ffa1f10efe3ddc983c7..8ce2cf5bfd72f9f53cdb35bc92502ee9ca0d3ad8 100644 --- a/src/gpu/VirtualFluids_GPU/Calculation/UpdateGrid27.h +++ b/src/gpu/VirtualFluids_GPU/Calculation/UpdateGrid27.h @@ -4,6 +4,7 @@ #include "LBM/LB.h" #include "GPU/GPU_Interface.h" #include "Parameter/Parameter.h" +#include "Parameter/CudaStreamManager.h" #include "GPU/CudaMemoryManager.h" #include "Communication/Communicator.h" #include "Calculation/PorousMedia.h" @@ -15,7 +16,6 @@ class Kernel; class BoundaryConditionFactory; class GridScalingFactory; class TurbulenceModelFactory; - class UpdateGrid27; using CollisionStrategy = std::function<void (UpdateGrid27* updateGrid, Parameter* para, int level, unsigned int t)>; using RefinementStrategy = std::function<void (UpdateGrid27* updateGrid, Parameter* para, int level)>; @@ -31,21 +31,21 @@ public: private: void collisionAllNodes(int level, unsigned int t); - void collisionUsingIndices(int level, unsigned int t, uint *fluidNodeIndices = nullptr, uint numberOfFluidNodes = 0, int stream = -1); + void collisionUsingIndices(int level, unsigned int t, uint *taggedFluidNodeIndices = nullptr, uint numberOfTaggedFluidNodes = 0, CollisionTemplate collisionTemplate = CollisionTemplate::Default, CudaStreamIndex streamIndex=CudaStreamIndex::Legacy); void collisionAdvectionDiffusion(int level); - void postCollisionBC(int level); + void postCollisionBC(int level, unsigned int t); void preCollisionBC(int level, unsigned int t); void collisionPorousMedia(int level); - void fineToCoarse(int level, InterpolationCellFC* icellFC, OffFC &offFC, int streamIndex); - void coarseToFine(int level, InterpolationCellCF* icellCF, OffCF &offCF, int streamIndex); + void fineToCoarse(int level, InterpolationCellFC* icellFC, OffFC &offFC, CudaStreamIndex streamIndex); + void coarseToFine(int level, InterpolationCellCF* icellCF, OffCF &offCF, CudaStreamIndex streamIndex); - void prepareExchangeMultiGPU(int level, int streamIndex); - void prepareExchangeMultiGPUAfterFtoC(int level, int streamIndex); + void prepareExchangeMultiGPU(int level, CudaStreamIndex streamIndex); + void prepareExchangeMultiGPUAfterFtoC(int level, CudaStreamIndex streamIndex); - void exchangeMultiGPU(int level, int streamIndex); - void exchangeMultiGPUAfterFtoC(int level, int streamIndex); + void exchangeMultiGPU(int level, CudaStreamIndex streamIndex); + void exchangeMultiGPUAfterFtoC(int level, CudaStreamIndex streamIndex); void exchangeMultiGPU_noStreams_withPrepare(int level, bool useReducedComm); void swapBetweenEvenAndOddTimestep(int level); @@ -60,6 +60,7 @@ private: friend class CollisionAndExchange_noStreams_indexKernel; friend class CollisionAndExchange_noStreams_oldKernel; friend class CollisionAndExchange_streams; + friend class CollisionAndExchange_noStreams_withReadWriteFlags; RefinementStrategy refinement; friend class RefinementAndExchange_streams_exchangeInterface; diff --git a/src/gpu/VirtualFluids_GPU/Communication/ExchangeData27.cpp b/src/gpu/VirtualFluids_GPU/Communication/ExchangeData27.cpp index 36c250401e0775b3abcc7d25c0f89fde0556631e..00a7b45668e2050467f3d1122455dc74d0ad4f1c 100644 --- a/src/gpu/VirtualFluids_GPU/Communication/ExchangeData27.cpp +++ b/src/gpu/VirtualFluids_GPU/Communication/ExchangeData27.cpp @@ -11,12 +11,12 @@ using namespace vf::lbm::dir; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 3D domain decomposition: functions used by all directions //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void collectNodesInSendBufferGPU(Parameter *para, int level, int streamIndex, +void collectNodesInSendBufferGPU(Parameter *para, int level, CudaStreamIndex streamIndex, std::vector<ProcessNeighbor27> *sendProcessNeighbor, unsigned int numberOfSendProcessNeighbors) { - cudaStream_t stream = (streamIndex == -1) ? CU_STREAM_LEGACY : para->getStreamManager()->getStream(streamIndex); - + cudaStream_t stream = para->getStreamManager()->getStream(streamIndex); + for (unsigned int i = 0; i < numberOfSendProcessNeighbors; i++) { GetSendFsPostDev27(para->getParD(level)->distributions.f[0], (*sendProcessNeighbor)[i].f[0], @@ -32,11 +32,11 @@ void collectNodesInSendBufferGPU(Parameter *para, int level, int streamIndex, } } -void scatterNodesFromRecvBufferGPU(Parameter *para, int level, int streamIndex, +void scatterNodesFromRecvBufferGPU(Parameter *para, int level, CudaStreamIndex streamIndex, std::vector<ProcessNeighbor27> *recvProcessNeighborDev, unsigned int numberOfRecvProcessNeighbors) { - cudaStream_t stream = (streamIndex == -1) ? CU_STREAM_LEGACY : para->getStreamManager()->getStream(streamIndex); + cudaStream_t stream = para->getStreamManager()->getStream(streamIndex); for (unsigned int i = 0; i < numberOfRecvProcessNeighbors; i++) { SetRecvFsPostDev27(para->getParD(level)->distributions.f[0], (*recvProcessNeighborDev)[i].f[0], @@ -105,22 +105,22 @@ void copyEdgeNodes(std::vector<LBMSimulationParameter::EdgeNodePositions> &edgeN //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // X //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void prepareExchangeCollDataXGPU27AllNodes(Parameter *para, int level, int streamIndex) +void prepareExchangeCollDataXGPU27AllNodes(Parameter *para, int level, CudaStreamIndex streamIndex) { collectNodesInSendBufferGPU(para, level, streamIndex, ¶->getParD(level)->sendProcessNeighborX, (unsigned int)(para->getNumberOfProcessNeighborsX(level, "send"))); } -void prepareExchangeCollDataXGPU27AfterFtoC(Parameter *para, int level, int streamIndex) +void prepareExchangeCollDataXGPU27AfterFtoC(Parameter *para, int level, CudaStreamIndex streamIndex) { collectNodesInSendBufferGPU(para, level, streamIndex, ¶->getParD(level)->sendProcessNeighborsAfterFtoCX, (unsigned int)(para->getNumberOfProcessNeighborsX(level, "send"))); } void exchangeCollDataXGPU27AllNodes(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, - int level, int streamIndex) + int level, CudaStreamIndex streamIndex) { - exchangeCollDataXGPU27(para, comm, cudaMemoryManager, level, streamIndex, + exchangeCollDataXGPU27(para, comm, cudaMemoryManager, level, streamIndex, ¶->getParD(level)->sendProcessNeighborX, ¶->getParD(level)->recvProcessNeighborX, ¶->getParH(level)->sendProcessNeighborX, @@ -128,40 +128,40 @@ void exchangeCollDataXGPU27AllNodes(Parameter *para, vf::gpu::Communicator &comm } void exchangeCollDataXGPU27AfterFtoC(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, - int level, int streamIndex) + int level, CudaStreamIndex streamIndex) { - exchangeCollDataXGPU27(para, comm, cudaMemoryManager, level, streamIndex, + exchangeCollDataXGPU27(para, comm, cudaMemoryManager, level, streamIndex, ¶->getParD(level)->sendProcessNeighborsAfterFtoCX, ¶->getParD(level)->recvProcessNeighborsAfterFtoCX, ¶->getParH(level)->sendProcessNeighborsAfterFtoCX, ¶->getParH(level)->recvProcessNeighborsAfterFtoCX); } -void scatterNodesFromRecvBufferXGPU27AllNodes(Parameter *para, int level, int streamIndex) +void scatterNodesFromRecvBufferXGPU27AllNodes(Parameter *para, int level, CudaStreamIndex streamIndex) { - scatterNodesFromRecvBufferGPU(para, level, streamIndex, ¶->getParD(level)->recvProcessNeighborX, + scatterNodesFromRecvBufferGPU(para, level, streamIndex,¶->getParD(level)->recvProcessNeighborX, (unsigned int)(para->getNumberOfProcessNeighborsX(level, "send"))); } -void scatterNodesFromRecvBufferXGPU27AfterFtoC(Parameter *para, int level, int streamIndex) +void scatterNodesFromRecvBufferXGPU27AfterFtoC(Parameter *para, int level, CudaStreamIndex streamIndex) { - scatterNodesFromRecvBufferGPU(para, level, streamIndex, ¶->getParD(level)->recvProcessNeighborsAfterFtoCX, + scatterNodesFromRecvBufferGPU(para, level, streamIndex,¶->getParD(level)->recvProcessNeighborsAfterFtoCX, (unsigned int)(para->getNumberOfProcessNeighborsX(level, "send"))); } -void exchangeCollDataXGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, int level, - int streamIndex, +void exchangeCollDataXGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, + int level, CudaStreamIndex streamIndex, std::vector<ProcessNeighbor27> *sendProcessNeighborDev, std::vector<ProcessNeighbor27> *recvProcessNeighborDev, std::vector<ProcessNeighbor27> *sendProcessNeighborHost, std::vector<ProcessNeighbor27> *recvProcessNeighborHost) { - cudaStream_t stream = (streamIndex == -1) ? CU_STREAM_LEGACY : para->getStreamManager()->getStream(streamIndex); + cudaStream_t stream = para->getStreamManager()->getStream(streamIndex); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //! \details steps: //! 1. copy data from device to host for (unsigned int i = 0; i < (unsigned int)(para->getNumberOfProcessNeighborsX(level, "send")); i++) - cudaMemoryManager->cudaCopyProcessNeighborXFsDH(level, i, (*sendProcessNeighborDev)[i].memsizeFs, streamIndex); + cudaMemoryManager->cudaCopyProcessNeighborXFsDH(level, i, (*sendProcessNeighborDev)[i].memsizeFs); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //! 2. start non-blocking receive (MPI) @@ -181,7 +181,7 @@ void exchangeCollDataXGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMe /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //! 7. copy received data from host to device for (unsigned int i = 0; i < (unsigned int)(para->getNumberOfProcessNeighborsX(level, "send")); i++) - cudaMemoryManager->cudaCopyProcessNeighborXFsHD(level, i, (*recvProcessNeighborDev)[i].memsizeFs, streamIndex); + cudaMemoryManager->cudaCopyProcessNeighborXFsHD(level, i, (*recvProcessNeighborDev)[i].memsizeFs); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -189,22 +189,22 @@ void exchangeCollDataXGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMe //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Y //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void prepareExchangeCollDataYGPU27AllNodes(Parameter *para, int level, int streamIndex) +void prepareExchangeCollDataYGPU27AllNodes(Parameter *para, int level, CudaStreamIndex streamIndex) { collectNodesInSendBufferGPU(para, level, streamIndex, ¶->getParD(level)->sendProcessNeighborY, (unsigned int)(para->getNumberOfProcessNeighborsY(level, "send"))); } -void prepareExchangeCollDataYGPU27AfterFtoC(Parameter *para, int level, int streamIndex) +void prepareExchangeCollDataYGPU27AfterFtoC(Parameter *para, int level, CudaStreamIndex streamIndex) { collectNodesInSendBufferGPU(para, level, streamIndex, ¶->getParD(level)->sendProcessNeighborsAfterFtoCY, (unsigned int)(para->getNumberOfProcessNeighborsY(level, "send"))); } void exchangeCollDataYGPU27AllNodes(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, - int level, int streamIndex) + int level, CudaStreamIndex streamIndex) { - exchangeCollDataYGPU27(para, comm, cudaMemoryManager, level, streamIndex, + exchangeCollDataYGPU27(para, comm, cudaMemoryManager, level, streamIndex, ¶->getParD(level)->sendProcessNeighborY, ¶->getParD(level)->recvProcessNeighborY, ¶->getParH(level)->sendProcessNeighborY, @@ -212,38 +212,39 @@ void exchangeCollDataYGPU27AllNodes(Parameter *para, vf::gpu::Communicator &comm } void exchangeCollDataYGPU27AfterFtoC(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, - int level, int streamIndex) + int level, CudaStreamIndex streamIndex) { - exchangeCollDataYGPU27(para, comm, cudaMemoryManager, level, streamIndex, + exchangeCollDataYGPU27(para, comm, cudaMemoryManager, level, streamIndex, ¶->getParD(level)->sendProcessNeighborsAfterFtoCY, ¶->getParD(level)->recvProcessNeighborsAfterFtoCY, ¶->getParH(level)->sendProcessNeighborsAfterFtoCY, ¶->getParH(level)->recvProcessNeighborsAfterFtoCY); } -void scatterNodesFromRecvBufferYGPU27AllNodes(Parameter *para, int level, int streamIndex) +void scatterNodesFromRecvBufferYGPU27AllNodes(Parameter *para, int level, CudaStreamIndex streamIndex) { scatterNodesFromRecvBufferGPU(para, level, streamIndex, ¶->getParD(level)->recvProcessNeighborY, (unsigned int)(para->getNumberOfProcessNeighborsY(level, "send"))); } -void scatterNodesFromRecvBufferYGPU27AfterFtoC(Parameter *para, int level, int streamIndex) +void scatterNodesFromRecvBufferYGPU27AfterFtoC(Parameter *para, int level, CudaStreamIndex streamIndex) { scatterNodesFromRecvBufferGPU(para, level, streamIndex, ¶->getParD(level)->recvProcessNeighborsAfterFtoCY, (unsigned int)(para->getNumberOfProcessNeighborsY(level, "send"))); } void exchangeCollDataYGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, int level, - int streamIndex, std::vector<ProcessNeighbor27> *sendProcessNeighborDev, + CudaStreamIndex streamIndex, + std::vector<ProcessNeighbor27> *sendProcessNeighborDev, std::vector<ProcessNeighbor27> *recvProcessNeighborDev, std::vector<ProcessNeighbor27> *sendProcessNeighborHost, std::vector<ProcessNeighbor27> *recvProcessNeighborHost) { - cudaStream_t stream = (streamIndex == -1) ? CU_STREAM_LEGACY : para->getStreamManager()->getStream(streamIndex); + cudaStream_t stream = para->getStreamManager()->getStream(CudaStreamIndex::SubDomainBorder); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // copy Device to Host for (unsigned int i = 0; i < (unsigned int)(para->getNumberOfProcessNeighborsY(level, "send")); i++) - cudaMemoryManager->cudaCopyProcessNeighborYFsDH(level, i, (*sendProcessNeighborDev)[i].memsizeFs, streamIndex); + cudaMemoryManager->cudaCopyProcessNeighborYFsDH(level, i, (*sendProcessNeighborDev)[i].memsizeFs); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// startNonBlockingMpiReceive((unsigned int)(*sendProcessNeighborHost).size(), comm, recvProcessNeighborHost); @@ -276,7 +277,7 @@ void exchangeCollDataYGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMe /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // copy Host to Device for (unsigned int i = 0; i < (unsigned int)(para->getNumberOfProcessNeighborsY(level, "send")); i++) { - cudaMemoryManager->cudaCopyProcessNeighborYFsHD(level, i, (*recvProcessNeighborDev)[i].memsizeFs, streamIndex); + cudaMemoryManager->cudaCopyProcessNeighborYFsHD(level, i, (*recvProcessNeighborDev)[i].memsizeFs); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } @@ -285,61 +286,62 @@ void exchangeCollDataYGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMe //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Z //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void prepareExchangeCollDataZGPU27AllNodes(Parameter *para, int level, int streamIndex) +void prepareExchangeCollDataZGPU27AllNodes(Parameter *para, int level, CudaStreamIndex streamIndex) { collectNodesInSendBufferGPU(para, level, streamIndex, ¶->getParD(level)->sendProcessNeighborZ, (unsigned int)(para->getNumberOfProcessNeighborsZ(level, "send"))); } -void prepareExchangeCollDataZGPU27AfterFtoC(Parameter *para, int level, int streamIndex) +void prepareExchangeCollDataZGPU27AfterFtoC(Parameter *para, int level, CudaStreamIndex streamIndex) { collectNodesInSendBufferGPU(para, level, streamIndex, ¶->getParD(level)->sendProcessNeighborsAfterFtoCZ, (unsigned int)(para->getNumberOfProcessNeighborsZ(level, "send"))); } void exchangeCollDataZGPU27AllNodes(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, - int level, int streamIndex) + int level, CudaStreamIndex streamIndex) { - exchangeCollDataZGPU27(para, comm, cudaMemoryManager, level, streamIndex, + exchangeCollDataZGPU27(para, comm, cudaMemoryManager, level, streamIndex, ¶->getParD(level)->sendProcessNeighborZ, ¶->getParD(level)->recvProcessNeighborZ, ¶->getParH(level)->sendProcessNeighborZ, ¶->getParH(level)->recvProcessNeighborZ); } void exchangeCollDataZGPU27AfterFtoC(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, - int level, int streamIndex) + int level, CudaStreamIndex streamIndex) { - exchangeCollDataZGPU27(para, comm, cudaMemoryManager, level, streamIndex, + exchangeCollDataZGPU27(para, comm, cudaMemoryManager, level, streamIndex, ¶->getParD(level)->sendProcessNeighborsAfterFtoCZ, ¶->getParD(level)->recvProcessNeighborsAfterFtoCZ, ¶->getParH(level)->sendProcessNeighborsAfterFtoCZ, ¶->getParH(level)->recvProcessNeighborsAfterFtoCZ); } -void scatterNodesFromRecvBufferZGPU27AllNodes(Parameter *para, int level, int streamIndex) +void scatterNodesFromRecvBufferZGPU27AllNodes(Parameter *para, int level, CudaStreamIndex streamIndex) { scatterNodesFromRecvBufferGPU(para, level, streamIndex, ¶->getParD(level)->recvProcessNeighborZ, (unsigned int)(para->getNumberOfProcessNeighborsZ(level, "send"))); } -void scatterNodesFromRecvBufferZGPU27AfterFtoC(Parameter *para, int level, int streamIndex) +void scatterNodesFromRecvBufferZGPU27AfterFtoC(Parameter *para, int level, CudaStreamIndex streamIndex) { scatterNodesFromRecvBufferGPU(para, level, streamIndex, ¶->getParD(level)->recvProcessNeighborsAfterFtoCZ, (unsigned int)(para->getNumberOfProcessNeighborsZ(level, "send"))); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void exchangeCollDataZGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, int level, - int streamIndex, std::vector<ProcessNeighbor27> *sendProcessNeighborDev, +void exchangeCollDataZGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, int level, + CudaStreamIndex streamIndex, + std::vector<ProcessNeighbor27> *sendProcessNeighborDev, std::vector<ProcessNeighbor27> *recvProcessNeighborDev, std::vector<ProcessNeighbor27> *sendProcessNeighborHost, std::vector<ProcessNeighbor27> *recvProcessNeighborHost) { - cudaStream_t stream = (streamIndex == -1) ? CU_STREAM_LEGACY : para->getStreamManager()->getStream(streamIndex); + cudaStream_t stream = para->getStreamManager()->getStream(streamIndex); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // copy Device to Host for (unsigned int i = 0; i < (unsigned int)(para->getNumberOfProcessNeighborsZ(level, "send")); i++) - cudaMemoryManager->cudaCopyProcessNeighborZFsDH(level, i, (*sendProcessNeighborDev)[i].memsizeFs, streamIndex); + cudaMemoryManager->cudaCopyProcessNeighborZFsDH(level, i, (*sendProcessNeighborDev)[i].memsizeFs); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// startNonBlockingMpiReceive((unsigned int)(*sendProcessNeighborHost).size(), comm, recvProcessNeighborHost); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -386,7 +388,7 @@ void exchangeCollDataZGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMe // copy Host to Device for (unsigned int i = 0; i < (unsigned int)(para->getNumberOfProcessNeighborsZ(level, "send")); i++) { - cudaMemoryManager->cudaCopyProcessNeighborZFsHD(level, i, (*recvProcessNeighborDev)[i].memsizeFs, streamIndex); + cudaMemoryManager->cudaCopyProcessNeighborZFsHD(level, i, (*recvProcessNeighborDev)[i].memsizeFs); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// } diff --git a/src/gpu/VirtualFluids_GPU/Communication/ExchangeData27.h b/src/gpu/VirtualFluids_GPU/Communication/ExchangeData27.h index ec930ebbc06554e948204b74e79e0e25b85f57b5..8302ffdc47bfa012c47df00f90c2491039f4eaee 100644 --- a/src/gpu/VirtualFluids_GPU/Communication/ExchangeData27.h +++ b/src/gpu/VirtualFluids_GPU/Communication/ExchangeData27.h @@ -6,6 +6,7 @@ #include "GPU/GPU_Interface.h" #include "LBM/LB.h" #include "Parameter/Parameter.h" +#include "Parameter/CudaStreamManager.h" //! \file ExchangeData27.h //! \ingroup GPU @@ -14,9 +15,9 @@ ////////////////////////////////////////////////////////////////////////// // 1D domain decomposition -void exchangePreCollDataGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, +void exchangePreCollDataGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, int level); -void exchangePostCollDataGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, +void exchangePostCollDataGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, int level); ////////////////////////////////////////////////////////////////////////// // 3D domain decomposition @@ -24,13 +25,13 @@ void exchangePostCollDataGPU27(Parameter *para, vf::gpu::Communicator &comm, Cud // functions used for all directions //! \brief Collect the send nodes in a buffer on the gpu -void collectNodesInSendBufferGPU(Parameter *para, int level, int streamIndex, - std::vector<ProcessNeighbor27> *sendProcessNeighbor, - unsigned int numberOfSendProcessNeighbors); +void collectNodesInSendBufferGPU(Parameter *para, int level, CudaStreamIndex streamIndex, + std::vector<ProcessNeighbor27> *sendProcessNeighbor, + unsigned int numberOfSendProcessNeighbors); //! \brief Distribute the receive nodes from the buffer on the gpu -void scatterNodesFromRecvBufferGPU(Parameter *para, int level, int streamIndex, - std::vector<ProcessNeighbor27> *recvProcessNeighborDev, - unsigned int numberOfRecvProcessNeighbors); +void scatterNodesFromRecvBufferGPU(Parameter *para, int level, CudaStreamIndex streamIndex, + std::vector<ProcessNeighbor27> *recvProcessNeighborDev, + unsigned int numberOfRecvProcessNeighbors); //! \brief Copy nodes which are part of the communication in multiple directions //! \details The nodes are copied from the receive buffer in one direction to the send buffer in another direction. The //! copy operation is conducted on the cpu. @@ -49,21 +50,20 @@ void copyEdgeNodes(std::vector<LBMSimulationParameter::EdgeNodePositions> &edgeN //! \brief Collect the send nodes for communication in the x direction in a buffer on the gpu //! \details Needed to exchange all nodes, used in the communication after collision step -void prepareExchangeCollDataXGPU27AllNodes(Parameter *para, int level, int streamIndex); +void prepareExchangeCollDataXGPU27AllNodes(Parameter *para, int level, CudaStreamIndex streamIndex); //! \brief Collect the send nodes for communication in the x direction in a buffer on the gpu //! \details Only exchange nodes which are part of the interpolation process on refined grids. This function is used in //! the exchange which takes place after the interpolation fine to coarse and before the interpolation coarse to fine. //! See [master thesis of Anna Wellmann] -void prepareExchangeCollDataXGPU27AfterFtoC(Parameter *para, int level, int streamIndex); +void prepareExchangeCollDataXGPU27AfterFtoC(Parameter *para, int level, CudaStreamIndex streamIndex); //! \brief Exchange routine in x direction for simulations on multiple gpus //! \details Send and receive the nodes from the communication buffers on the gpus. //! \param Communicator is needed for the communication between the processes with mpi //! \param CudaMemoryManager is needed for moving the data between host and device -//! \param streamIndex is the index of a CUDA Stream, which is needed for communication hiding //! \param sendProcessNeighborDev, recvProcessNeighborDev, sendProcessNeighborHost, recvProcessNeighborHost are pointers //! to the send and receive arrays, both on the device and the host void exchangeCollDataXGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, - int level, int streamIndex, + int level, CudaStreamIndex streamIndex, std::vector<ProcessNeighbor27> *sendProcessNeighborDev, std::vector<ProcessNeighbor27> *recvProcessNeighborDev, std::vector<ProcessNeighbor27> *sendProcessNeighborHost, @@ -71,59 +71,59 @@ void exchangeCollDataXGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMe //! \brief Calls exchangeCollDataXGPU27() for exchanging all nodes //! \details Used in the communication after collision step void exchangeCollDataXGPU27AllNodes(Parameter *para, vf::gpu::Communicator &comm, - CudaMemoryManager *cudaMemoryManager, int level, int streamIndex); + CudaMemoryManager *cudaMemoryManager, int level, CudaStreamIndex streamIndex); //! \brief Calls exchangeCollDataXGPU27() for exchanging the nodes, which are part of the communication between the two //! interpolation processes on refined grids //! \details Only exchange nodes which are part of the interpolation process on //! refined grids. This function is used in the exchange which takes place after the interpolation fine to coarse and //! before the interpolation coarse to fine. See [master thesis of Anna Wellmann] void exchangeCollDataXGPU27AfterFtoC(Parameter *para, vf::gpu::Communicator &comm, - CudaMemoryManager *cudaMemoryManager, int level, int streamIndex); + CudaMemoryManager *cudaMemoryManager, int level, CudaStreamIndex streamIndex); //! \brief Distribute the receive nodes (x direction) from the buffer on the gpu //! \details Needed to exchange all nodes, used in the communication after collision step -void scatterNodesFromRecvBufferXGPU27AllNodes(Parameter *para, int level, int streamIndex); +void scatterNodesFromRecvBufferXGPU27AllNodes(Parameter *para, int level, CudaStreamIndex streamIndex); //! \brief Distribute the receive nodes (x direction) from the buffer on the gpu //! \details Only exchange nodes which are part of the interpolation process on refined grids. This function is used in //! the exchange which takes place after the interpolation fine to coarse and before the interpolation coarse to fine. //! See [master thesis of Anna Wellmann] -void scatterNodesFromRecvBufferXGPU27AfterFtoC(Parameter *para, int level, int streamIndex); +void scatterNodesFromRecvBufferXGPU27AfterFtoC(Parameter *para, int level, CudaStreamIndex streamIndex); ////////////////////////////////////////////////////////////////////////// // y -void prepareExchangeCollDataYGPU27AllNodes(Parameter *para, int level, int streamIndex); -void prepareExchangeCollDataYGPU27AfterFtoC(Parameter *para, int level, int streamIndex); +void prepareExchangeCollDataYGPU27AllNodes(Parameter *para, int level, CudaStreamIndex streamIndex); +void prepareExchangeCollDataYGPU27AfterFtoC(Parameter *para, int level, CudaStreamIndex streamIndex); void exchangeCollDataYGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, - int level, int streamIndex, + int level,CudaStreamIndex streamIndex, std::vector<ProcessNeighbor27> *sendProcessNeighborDev, std::vector<ProcessNeighbor27> *recvProcessNeighborDev, std::vector<ProcessNeighbor27> *sendProcessNeighborHost, std::vector<ProcessNeighbor27> *recvProcessNeighborHos); void exchangeCollDataYGPU27AllNodes(Parameter *para, vf::gpu::Communicator &comm, - CudaMemoryManager *cudaMemoryManager, int level, int streamIndex); + CudaMemoryManager *cudaMemoryManager, int level, CudaStreamIndex streamIndex); void exchangeCollDataYGPU27AfterFtoC(Parameter *para, vf::gpu::Communicator &comm, - CudaMemoryManager *cudaMemoryManager, int level, int streamIndex); -void scatterNodesFromRecvBufferYGPU27AllNodes(Parameter *para, int level, int streamIndex); -void scatterNodesFromRecvBufferYGPU27AfterFtoC(Parameter *para, int level, int streamIndex); + CudaMemoryManager *cudaMemoryManager, int level, CudaStreamIndex streamIndex); +void scatterNodesFromRecvBufferYGPU27AllNodes(Parameter *para, int level, CudaStreamIndex streamIndex); +void scatterNodesFromRecvBufferYGPU27AfterFtoC(Parameter *para, int level, CudaStreamIndex streamIndex); // z -void prepareExchangeCollDataZGPU27AllNodes(Parameter *para, int level, int streamIndex); -void prepareExchangeCollDataZGPU27AfterFtoC(Parameter *para, int level, int streamIndex); +void prepareExchangeCollDataZGPU27AllNodes(Parameter *para, int level, CudaStreamIndex streamIndex); +void prepareExchangeCollDataZGPU27AfterFtoC(Parameter *para, int level, CudaStreamIndex streamIndex); void exchangeCollDataZGPU27(Parameter *para, vf::gpu::Communicator &comm, CudaMemoryManager *cudaMemoryManager, - int level, int streamIndex, + int level, CudaStreamIndex streamIndex, std::vector<ProcessNeighbor27> *sendProcessNeighborDev, std::vector<ProcessNeighbor27> *recvProcessNeighborDev, std::vector<ProcessNeighbor27> *sendProcessNeighborHost, std::vector<ProcessNeighbor27> *recvProcessNeighborHost); void exchangeCollDataZGPU27AllNodes(Parameter *para, vf::gpu::Communicator &comm, - CudaMemoryManager *cudaMemoryManager, int level, int streamIndex); + CudaMemoryManager *cudaMemoryManager, int level, CudaStreamIndex streamIndex); void exchangeCollDataZGPU27AfterFtoC(Parameter *para, vf::gpu::Communicator &comm, - CudaMemoryManager *cudaMemoryManager, int level, int streamIndex); + CudaMemoryManager *cudaMemoryManager, int level, CudaStreamIndex streamIndex); -void scatterNodesFromRecvBufferZGPU27AllNodes(Parameter *para, int level, int streamIndex); -void scatterNodesFromRecvBufferZGPU27AfterFtoC(Parameter *para, int level, int streamIndex); +void scatterNodesFromRecvBufferZGPU27AllNodes(Parameter *para, int level, CudaStreamIndex streamIndex); +void scatterNodesFromRecvBufferZGPU27AfterFtoC(Parameter *para, int level, CudaStreamIndex streamIndex); ////////////////////////////////////////////////////////////////////////// // 3D domain decomposition convection diffusion diff --git a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.cpp b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.cpp index e197fb5c28611e77406b30ab39aa6af2f54b9ef5..c996525ee78e6ba87fe0972df084aedccfefd39a 100644 --- a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.cpp +++ b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.cpp @@ -29,15 +29,10 @@ void GridProvider::setNumberOfNodes(const int numberOfNodes, const int level) co para->getParD(level)->mem_size_int_SP = sizeof(uint) * para->getParD(level)->numberOfNodes; } -void GridProvider::setNumberOfFluidNodes(const int numberOfNodes, const int level) const +void GridProvider::setNumberOfTaggedFluidNodes(const int numberOfNodes, CollisionTemplate tag, const int level) const { - para->getParH(level)->numberOfFluidNodes = numberOfNodes; - para->getParD(level)->numberOfFluidNodes = numberOfNodes; -} - -void GridProvider::setNumberOfFluidNodesBorder(const int numberOfNodes, const int level) const { - para->getParH(level)->numberOfFluidNodesBorder = numberOfNodes; - para->getParD(level)->numberOfFluidNodesBorder = numberOfNodes; + para->getParH(level)->numberOfTaggedFluidNodes[tag] = numberOfNodes; + para->getParD(level)->numberOfTaggedFluidNodes[tag] = numberOfNodes; } void GridProvider::setInitalNodeValues(const int numberOfNodes, const int level) const diff --git a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.h b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.h index 5fc5826735643ec748da169160e782004d7e5fb7..42ba7a464a6e76fd747cc6d11a01e3957c865765 100644 --- a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.h +++ b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.h @@ -5,7 +5,7 @@ #include <vector> #include <memory> - +#include "LBM/LB.h" #include "PointerDefinitions.h" #include "VirtualFluids_GPU_export.h" #include "gpu/GridGenerator/io/SimulationFileWriter/SimulationFileWriter.h" @@ -28,8 +28,10 @@ public: virtual void allocArrays_BoundaryValues() = 0; virtual void allocArrays_BoundaryQs() = 0; virtual void allocArrays_OffsetScale() = 0; - virtual void allocArrays_fluidNodeIndices() = 0; - virtual void allocArrays_fluidNodeIndicesBorder() = 0; + virtual void allocArrays_taggedFluidNodes() = 0; + + virtual void tagFluidNodeIndices(std::vector<uint> taggedFluidNodeIndices, CollisionTemplate tag, uint level) = 0; + virtual void sortFluidNodeTags() = 0; virtual void setDimensions() = 0; virtual void setBoundingBox() = 0; @@ -45,8 +47,7 @@ public: protected: void setNumberOfNodes(const int numberOfNodes, const int level) const; - void setNumberOfFluidNodes(const int numberOfNodes, const int level) const; - void setNumberOfFluidNodesBorder(const int numberOfNodes, const int level) const; + void setNumberOfTaggedFluidNodes(const int numberOfNodes, CollisionTemplate tag, const int level) const; virtual void setInitalNodeValues(const int numberOfNodes, const int level) const; void setPressSizePerLevel(int level, int sizePerLevel) const; diff --git a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.cpp b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.cpp index fa432a1d9c3922b88e93588548db74083275ef1e..793400869dd29fe12be357ffcf87c0238ea70eb9 100644 --- a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.cpp +++ b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.cpp @@ -218,16 +218,20 @@ void GridReader::allocArrays_OffsetScale() std::cout << "-----Ende OffsetScale------" << std::endl; } -void GridReader::allocArrays_fluidNodeIndices() { +void GridReader::allocArrays_taggedFluidNodes() { std::cout << "GridReader::allocArrays_fluidNodeIndices not implemented" << std::endl; // TODO } -void GridReader::allocArrays_fluidNodeIndicesBorder() { - std::cout << "GridReader::allocArrays_fluidNodeIndicesBorder not implemented" << std::endl; +void GridReader::tagFluidNodeIndices(std::vector<uint> taggedFluidNodeIndices, CollisionTemplate tag, uint level){ + std::cout << "GridReader::tagFluidNodeIndices not implemented" << std::endl; // TODO } +void GridReader::sortFluidNodeTags(){ + std::cout << "GridReader::sortFluidNodeTags not implemented" << std::endl; + // TODO +} void GridReader::setPressureValues(int channelSide) const { diff --git a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.h b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.h index 18efb6a7885191312ea4e2fbb22eb45162ab1de1..2c17c28022d88a65e922e23d1c89f5166f5a1716 100644 --- a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.h +++ b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.h @@ -39,8 +39,10 @@ public: void allocArrays_CoordNeighborGeo() override; void allocArrays_BoundaryValues() override; void allocArrays_OffsetScale() override; - void allocArrays_fluidNodeIndices() override; - void allocArrays_fluidNodeIndicesBorder() override; + void allocArrays_taggedFluidNodes() override; + + void tagFluidNodeIndices(std::vector<uint> taggedFluidNodeIndices, CollisionTemplate tag, uint level) override; + void sortFluidNodeTags() override; void initalValuesDomainDecompostion(int level); diff --git a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.cpp b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.cpp index 7f61b4357276f38d8fde71489dcf60348b402941..d89f4cd85985694b4529d338ab5e4c5a86cd3a38 100644 --- a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.cpp +++ b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.cpp @@ -1,5 +1,6 @@ #include "GridGenerator.h" +#include "LBM/LB.h" #include "Parameter/Parameter.h" #include "GridGenerator/grid/GridBuilder/GridBuilder.h" #include "GPU/CudaMemoryManager.h" @@ -10,10 +11,13 @@ #include <algorithm> #include "utilities/math/Math.h" #include "Output/QDebugWriter.hpp" +#include "GridGenerator/TransientBCSetter/TransientBCSetter.h" #include "utilities/communication.h" #include "Communication/Communicator.h" +#include <logger/Logger.h> + using namespace vf::lbm::dir; GridGenerator::GridGenerator(std::shared_ptr<GridBuilder> builder, std::shared_ptr<Parameter> para, std::shared_ptr<CudaMemoryManager> cudaMemoryManager, vf::gpu::Communicator& communicator): @@ -100,22 +104,98 @@ void GridGenerator::allocArrays_CoordNeighborGeo() std::cout << "-----finish Coord, Neighbor, Geo------" << std::endl; } -void GridGenerator::allocArrays_fluidNodeIndices() { - for (uint level = 0; level < builder->getNumberOfGridLevels(); level++) { - setNumberOfFluidNodes(builder->getNumberOfFluidNodes(level), level); - cudaMemoryManager->cudaAllocFluidNodeIndices(level); - builder->getFluidNodeIndices(para->getParH(level)->fluidNodeIndices, level); - cudaMemoryManager->cudaCopyFluidNodeIndices(level); - } +void GridGenerator::allocArrays_taggedFluidNodes() { + + for (uint level = 0; level < builder->getNumberOfGridLevels(); level++) + { + for ( CollisionTemplate tag: all_CollisionTemplate ) + { //TODO: Need to add CollisionTemplate to GridBuilder to allow as argument and get rid of indivual get funtions for fluid node indices... and clean up this mess + switch(tag) + { + case CollisionTemplate::Default: + this->setNumberOfTaggedFluidNodes(builder->getNumberOfFluidNodes(level), CollisionTemplate::Default, level); + cudaMemoryManager->cudaAllocTaggedFluidNodeIndices(CollisionTemplate::Default, level); + builder->getFluidNodeIndices(para->getParH(level)->taggedFluidNodeIndices[CollisionTemplate::Default], level); + cudaMemoryManager->cudaCopyTaggedFluidNodeIndices(CollisionTemplate::Default, level); + if(para->getParH(level)->numberOfTaggedFluidNodes[tag]>0) + para->getParH(level)->allocatedBulkFluidNodeTags.push_back(tag); + break; + case CollisionTemplate::SubDomainBorder: + this->setNumberOfTaggedFluidNodes(builder->getNumberOfFluidNodesBorder(level), CollisionTemplate::SubDomainBorder, level); + cudaMemoryManager->cudaAllocTaggedFluidNodeIndices(CollisionTemplate::SubDomainBorder, level); + builder->getFluidNodeIndicesBorder(para->getParH(level)->taggedFluidNodeIndices[CollisionTemplate::SubDomainBorder], level); + cudaMemoryManager->cudaCopyTaggedFluidNodeIndices(CollisionTemplate::SubDomainBorder, level); + break; + case CollisionTemplate::WriteMacroVars: + this->setNumberOfTaggedFluidNodes(builder->getNumberOfFluidNodesMacroVars(level), CollisionTemplate::WriteMacroVars, level); + cudaMemoryManager->cudaAllocTaggedFluidNodeIndices(CollisionTemplate::WriteMacroVars, level); + builder->getFluidNodeIndicesMacroVars(para->getParH(level)->taggedFluidNodeIndices[CollisionTemplate::WriteMacroVars], level); + cudaMemoryManager->cudaCopyTaggedFluidNodeIndices(CollisionTemplate::WriteMacroVars, level); + if(para->getParH(level)->numberOfTaggedFluidNodes[tag]>0) + para->getParH(level)->allocatedBulkFluidNodeTags.push_back(tag); + break; + case CollisionTemplate::ApplyBodyForce: + this->setNumberOfTaggedFluidNodes(builder->getNumberOfFluidNodesApplyBodyForce(level), CollisionTemplate::ApplyBodyForce, level); + cudaMemoryManager->cudaAllocTaggedFluidNodeIndices(CollisionTemplate::ApplyBodyForce, level); + builder->getFluidNodeIndicesApplyBodyForce(para->getParH(level)->taggedFluidNodeIndices[CollisionTemplate::ApplyBodyForce], level); + cudaMemoryManager->cudaCopyTaggedFluidNodeIndices(CollisionTemplate::ApplyBodyForce, level); + if(para->getParH(level)->numberOfTaggedFluidNodes[tag]>0) + para->getParH(level)->allocatedBulkFluidNodeTags.push_back(tag); + break; + case CollisionTemplate::AllFeatures: + this->setNumberOfTaggedFluidNodes(builder->getNumberOfFluidNodesAllFeatures(level), CollisionTemplate::AllFeatures, level); + cudaMemoryManager->cudaAllocTaggedFluidNodeIndices(CollisionTemplate::AllFeatures, level); + builder->getFluidNodeIndicesAllFeatures(para->getParH(level)->taggedFluidNodeIndices[CollisionTemplate::AllFeatures], level); + cudaMemoryManager->cudaCopyTaggedFluidNodeIndices(CollisionTemplate::AllFeatures, level); + if(para->getParH(level)->numberOfTaggedFluidNodes[tag]>0) + para->getParH(level)->allocatedBulkFluidNodeTags.push_back(tag); + break; + default: + break; + } + } + VF_LOG_INFO("Number of tagged nodes on level {}:", level); + VF_LOG_INFO("Default: {}, Border: {}, WriteMacroVars: {}, ApplyBodyForce: {}, AllFeatures: {}", + para->getParH(level)->numberOfTaggedFluidNodes[CollisionTemplate::Default], + para->getParH(level)->numberOfTaggedFluidNodes[CollisionTemplate::SubDomainBorder], + para->getParH(level)->numberOfTaggedFluidNodes[CollisionTemplate::WriteMacroVars], + para->getParH(level)->numberOfTaggedFluidNodes[CollisionTemplate::ApplyBodyForce], + para->getParH(level)->numberOfTaggedFluidNodes[CollisionTemplate::AllFeatures] ); + } } -void GridGenerator::allocArrays_fluidNodeIndicesBorder() { - for (uint level = 0; level < builder->getNumberOfGridLevels(); level++) { - setNumberOfFluidNodesBorder(builder->getNumberOfFluidNodesBorder(level), level); - cudaMemoryManager->cudaAllocFluidNodeIndicesBorder(level); - builder->getFluidNodeIndicesBorder(para->getParH(level)->fluidNodeIndicesBorder, level); - cudaMemoryManager->cudaCopyFluidNodeIndicesBorder(level); +void GridGenerator::tagFluidNodeIndices(std::vector<uint> taggedFluidNodeIndices, CollisionTemplate tag, uint level) { + switch(tag) + { + case CollisionTemplate::WriteMacroVars: + builder->addFluidNodeIndicesMacroVars( taggedFluidNodeIndices, level ); + break; + case CollisionTemplate::ApplyBodyForce: + builder->addFluidNodeIndicesApplyBodyForce( taggedFluidNodeIndices, level ); + break; + case CollisionTemplate::AllFeatures: + builder->addFluidNodeIndicesAllFeatures( taggedFluidNodeIndices, level ); + break; + case CollisionTemplate::Default: + case CollisionTemplate::SubDomainBorder: + throw std::runtime_error("Cannot tag fluid nodes as Default or SubDomainBorder!"); + default: + throw std::runtime_error("Tagging fluid nodes with invald tag!"); + break; + + } + +} + +void GridGenerator::sortFluidNodeTags() { + VF_LOG_INFO("Start sorting tagged fluid nodes..."); + for (uint level = 0; level < builder->getNumberOfGridLevels(); level++) + { + builder->sortFluidNodeIndicesAllFeatures(level); //has to be called first! + builder->sortFluidNodeIndicesMacroVars(level); + builder->sortFluidNodeIndicesApplyBodyForce(level); } + VF_LOG_INFO("done."); } void GridGenerator::allocArrays_BoundaryValues() @@ -129,6 +209,7 @@ void GridGenerator::allocArrays_BoundaryValues() //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// para->getParH(level)->pressureBC.numberOfBCnodes = 0; + para->getParD(level)->outflowPressureCorrectionFactor = para->getOutflowPressureCorrectionFactor(); if (numberOfPressureValues > 1) { blocks = (numberOfPressureValues / para->getParH(level)->numberofthreads) + 1; @@ -242,6 +323,98 @@ void GridGenerator::allocArrays_BoundaryValues() para->getParD(level)->numberOfVeloBCnodesRead = para->getParH(level)->velocityBC.numberOfBCnodes * para->getD3Qxx(); } + for (uint level = 0; level < builder->getNumberOfGridLevels(); level++) { + const auto numberOfPrecursorValues = int(builder->getPrecursorSize(level)); + *logging::out << logging::Logger::INFO_INTERMEDIATE << "size precursor level " << level << " : " << numberOfPrecursorValues << "\n"; + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + int blocks = (numberOfPrecursorValues / para->getParH(level)->numberofthreads) + 1; + para->getParH(level)->precursorBC.sizeQ = blocks * para->getParH(level)->numberofthreads; + para->getParD(level)->precursorBC.sizeQ = para->getParH(level)->precursorBC.sizeQ; + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + para->getParH(level)->precursorBC.numberOfBCnodes = numberOfPrecursorValues; + para->getParD(level)->precursorBC.numberOfBCnodes = numberOfPrecursorValues; + para->getParH(level)->numberOfPrecursorBCnodesRead = numberOfPrecursorValues * para->getD3Qxx(); + para->getParD(level)->numberOfPrecursorBCnodesRead = numberOfPrecursorValues * para->getD3Qxx(); + + if (numberOfPrecursorValues > 1) + { + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + cudaMemoryManager->cudaAllocPrecursorBC(level); + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + builder->getPrecursorValues( + para->getParH(level)->precursorBC.planeNeighbor0PP, para->getParH(level)->precursorBC.planeNeighbor0PM, + para->getParH(level)->precursorBC.planeNeighbor0MP, para->getParH(level)->precursorBC.planeNeighbor0MM, + para->getParH(level)->precursorBC.weights0PP, para->getParH(level)->precursorBC.weights0PM, + para->getParH(level)->precursorBC.weights0MP, para->getParH(level)->precursorBC.weights0MM, + para->getParH(level)->precursorBC.k, para->getParH(level)->transientBCInputFileReader, para->getParH(level)->precursorBC.numberOfPrecursorNodes, + para->getParH(level)->precursorBC.numberOfQuantities, para->getParH(level)->precursorBC.timeStepsBetweenReads, + para->getParH(level)->precursorBC.velocityX, para->getParH(level)->precursorBC.velocityY, para->getParH(level)->precursorBC.velocityZ, + level); + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + para->getParD(level)->precursorBC.numberOfPrecursorNodes = para->getParH(level)->precursorBC.numberOfPrecursorNodes; + para->getParD(level)->precursorBC.numberOfQuantities = para->getParH(level)->precursorBC.numberOfQuantities; + para->getParD(level)->precursorBC.timeStepsBetweenReads = para->getParH(level)->precursorBC.timeStepsBetweenReads; + para->getParD(level)->precursorBC.velocityX = para->getParH(level)->precursorBC.velocityX; + para->getParD(level)->precursorBC.velocityY = para->getParH(level)->precursorBC.velocityY; + para->getParD(level)->precursorBC.velocityZ = para->getParH(level)->precursorBC.velocityZ; + + for(auto reader : para->getParH(level)->transientBCInputFileReader) + { + if(reader->getNumberOfQuantities() != para->getParD(level)->precursorBC.numberOfQuantities) throw std::runtime_error("Number of quantities in reader and number of quantities needed for precursor don't match!"); + } + + cudaMemoryManager->cudaCopyPrecursorBC(level); + cudaMemoryManager->cudaAllocPrecursorData(level); + + // read first timestep of precursor into next and copy to next on device + for(auto reader : para->getParH(level)->transientBCInputFileReader) + { + reader->getNextData(para->getParH(level)->precursorBC.next, para->getParH(level)->precursorBC.numberOfPrecursorNodes, 0); + } + + cudaMemoryManager->cudaCopyPrecursorData(level); + + //switch next with last pointers + real* tmp = para->getParD(level)->precursorBC.last; + para->getParD(level)->precursorBC.last = para->getParD(level)->precursorBC.next; + para->getParD(level)->precursorBC.next = tmp; + + //read second timestep of precursor into next and copy next to device + real nextTime = para->getParD(level)->precursorBC.timeStepsBetweenReads*pow(2,-((real)level))*para->getTimeRatio(); + for(auto reader : para->getParH(level)->transientBCInputFileReader) + { + reader->getNextData(para->getParH(level)->precursorBC.next, para->getParH(level)->precursorBC.numberOfPrecursorNodes, nextTime); + } + + cudaMemoryManager->cudaCopyPrecursorData(level); + + para->getParD(level)->precursorBC.nPrecursorReads = 1; + + + //switch next with current pointers + tmp = para->getParD(level)->precursorBC.current; + para->getParD(level)->precursorBC.current = para->getParD(level)->precursorBC.next; + para->getParD(level)->precursorBC.next = tmp; + + //start usual cycle of loading, i.e. read velocities of timestep after current and copy asynchronously to device + for(auto reader : para->getParH(level)->transientBCInputFileReader) + { + reader->getNextData(para->getParH(level)->precursorBC.next, para->getParH(level)->precursorBC.numberOfPrecursorNodes, 2*nextTime); + } + + cudaMemoryManager->cudaCopyPrecursorData(level); + + para->getParD(level)->precursorBC.nPrecursorReads = 2; + } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // advection - diffusion stuff + if (para->getDiffOn()==true){ + throw std::runtime_error(" Advection Diffusion not implemented for Precursor!"); + } + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + } + if (builder->hasGeometryValues()) { @@ -874,6 +1047,50 @@ void GridGenerator::allocArrays_BoundaryQs() } } + for (uint i = 0; i < builder->getNumberOfGridLevels(); i++) { + const auto numberOfPrecursorNodes = int(builder->getPrecursorSize(i)); + if (numberOfPrecursorNodes > 0) + { + std::cout << "size velocity level " << i << " : " << numberOfPrecursorNodes << std::endl; + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + //preprocessing + real* QQ = para->getParH(i)->precursorBC.q27[0]; + unsigned int sizeQ = para->getParH(i)->precursorBC.numberOfBCnodes; + QforBoundaryConditions Q; + getPointersToBoundaryConditions(Q, QQ, sizeQ); + + builder->getPrecursorQs(Q.q27, i); + + if (para->getDiffOn()) { + throw std::runtime_error("Advection diffusion not implemented for Precursor!"); + ////////////////////////////////////////////////////////////////////////// + // para->getParH(i)->TempVel.kTemp = numberOfVelocityNodes; + // para->getParD(i)->TempVel.kTemp = numberOfVelocityNodes; + // std::cout << "Groesse TempVel.kTemp = " << para->getParH(i)->TempPress.kTemp << std::endl; + // std::cout << "getTemperatureInit = " << para->getTemperatureInit() << std::endl; + // std::cout << "getTemperatureBC = " << para->getTemperatureBC() << std::endl; + // ////////////////////////////////////////////////////////////////////////// + // cudaMemoryManager->cudaAllocTempVeloBC(i); + // //cout << "nach alloc " << std::endl; + // ////////////////////////////////////////////////////////////////////////// + // for (int m = 0; m < numberOfVelocityNodes; m++) + // { + // para->getParH(i)->TempVel.temp[m] = para->getTemperatureInit(); + // para->getParH(i)->TempVel.tempPulse[m] = para->getTemperatureBC(); + // para->getParH(i)->TempVel.velo[m] = para->getVelocity(); + // para->getParH(i)->TempVel.k[m] = para->getParH(i)->Qinflow.k[m]; + // } + // ////////////////////////////////////////////////////////////////////////// + // //cout << "vor copy " << std::endl; + // cudaMemoryManager->cudaCopyTempVeloBCHD(i); + // //cout << "nach copy " << std::endl; + ////////////////////////////////////////////////////////////////////////// + } + cudaMemoryManager->cudaCopyPrecursorBC(i); + } + } + + for (uint i = 0; i < builder->getNumberOfGridLevels(); i++) { const int numberOfGeometryNodes = builder->getGeometrySize(i); diff --git a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h index d2f56e1df4ee5658c61b8e8a3e94a820d1a4f2f1..cee661a0c1092e7a3d334018133fd2f963ada991 100644 --- a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h +++ b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h @@ -40,6 +40,7 @@ #include "LBM/LB.h" + class Parameter; class GridBuilder; class IndexRearrangementForStreams; @@ -75,8 +76,10 @@ public: //! \brief allocates and initialized the sub-grid distances at the boundary conditions void allocArrays_BoundaryQs() override; void allocArrays_OffsetScale() override; - void allocArrays_fluidNodeIndices() override; - void allocArrays_fluidNodeIndicesBorder() override; + void allocArrays_taggedFluidNodes() override; + + void tagFluidNodeIndices(std::vector<uint> taggedFluidNodeIndices, CollisionTemplate tag, uint level) override; + void sortFluidNodeTags() override; virtual void setDimensions() override; virtual void setBoundingBox() override; diff --git a/src/gpu/VirtualFluids_GPU/Factories/BoundaryConditionFactory.cpp b/src/gpu/VirtualFluids_GPU/Factories/BoundaryConditionFactory.cpp index bff054eb174a0f5fa34119deedde6f1c9733d83c..b1c398638cff1ec1b6d52f59f8e773183e270331 100644 --- a/src/gpu/VirtualFluids_GPU/Factories/BoundaryConditionFactory.cpp +++ b/src/gpu/VirtualFluids_GPU/Factories/BoundaryConditionFactory.cpp @@ -35,6 +35,11 @@ void BoundaryConditionFactory::setStressBoundaryCondition(const StressBC boundar this->stressBoundaryCondition = boundaryConditionType; } +void BoundaryConditionFactory::setPrecursorBoundaryCondition(const PrecursorBC boundaryConditionType) +{ + this->precursorBoundaryCondition = boundaryConditionType; +} + boundaryCondition BoundaryConditionFactory::getVelocityBoundaryConditionPost(bool isGeometryBC) const { const VelocityBC &boundaryCondition = @@ -132,6 +137,22 @@ boundaryCondition BoundaryConditionFactory::getPressureBoundaryConditionPre() co case PressureBC::OutflowNonReflective: return QPressNoRhoDev27; break; + case PressureBC::OutflowNonReflectivePressureCorrection: + return QPressZeroRhoOutflowDev27; + default: + return nullptr; + } +} + +precursorBoundaryConditionFunc BoundaryConditionFactory::getPrecursorBoundaryConditionPost() const +{ + switch (this->precursorBoundaryCondition) { + case PrecursorBC::VelocityPrecursor: + return QPrecursorDevCompZeroPress; + break; + case PrecursorBC::DistributionsPrecursor: + return PrecursorDevDistributions; + break; default: return nullptr; } diff --git a/src/gpu/VirtualFluids_GPU/Factories/BoundaryConditionFactory.h b/src/gpu/VirtualFluids_GPU/Factories/BoundaryConditionFactory.h index 9d6872c4847be72dff4be7137b774c8082e39e34..c6877cbfeffe5b32c0c2d336e46b02d68cd946a3 100644 --- a/src/gpu/VirtualFluids_GPU/Factories/BoundaryConditionFactory.h +++ b/src/gpu/VirtualFluids_GPU/Factories/BoundaryConditionFactory.h @@ -42,11 +42,13 @@ #include "Parameter/Parameter.h" #include "gpu/GridGenerator/grid/BoundaryConditions/Side.h" + struct LBMSimulationParameter; class Parameter; using boundaryCondition = std::function<void(LBMSimulationParameter *, QforBoundaryConditions *)>; using boundaryConditionWithParameter = std::function<void(Parameter *, QforBoundaryConditions *, const int level)>; +using precursorBoundaryConditionFunc = std::function<void(LBMSimulationParameter *, QforPrecursorBoundaryConditions *, real timeRatio, real velocityRatio)>; class BoundaryConditionFactory { @@ -109,6 +111,8 @@ public: PressureNonEquilibriumCompressible, //! - OutflowNonReflective = outflow boundary condition, should be combined with VelocityAndPressureCompressible OutflowNonReflective, + //! - OutflowNonreflectivePressureCorrection = like OutflowNonReflective, but also reduces pressure overshoot + OutflowNonReflectivePressureCorrection, //! - NotSpecified = the user did not set a boundary condition NotSpecified }; @@ -128,11 +132,21 @@ public: // enum class OutflowBoundaryCondition {}; // TODO: // https://git.rz.tu-bs.de/m.schoenherr/VirtualFluids_dev/-/issues/16 + enum class PrecursorBC { + //! - VelocityPrecursor + VelocityPrecursor, + //! - DisitributionsPrecursor + DistributionsPrecursor, + //! - NotSpecified = the user did not set a boundary condition + NotSpecified + }; + void setVelocityBoundaryCondition(const BoundaryConditionFactory::VelocityBC boundaryConditionType); void setNoSlipBoundaryCondition(const BoundaryConditionFactory::NoSlipBC boundaryConditionType); void setSlipBoundaryCondition(const BoundaryConditionFactory::SlipBC boundaryConditionType); void setPressureBoundaryCondition(const BoundaryConditionFactory::PressureBC boundaryConditionType); void setStressBoundaryCondition(const BoundaryConditionFactory::StressBC boundaryConditionType); + void setPrecursorBoundaryCondition(const BoundaryConditionFactory::PrecursorBC boundaryConditionType); //! \brief set a boundary condition for the geometry //! param boundaryConditionType: a velocity, no-slip or slip boundary condition //! \details suggestions for boundaryConditionType: @@ -152,6 +166,8 @@ public: [[nodiscard]] boundaryCondition getSlipBoundaryConditionPost(bool isGeometryBC = false) const; [[nodiscard]] boundaryCondition getPressureBoundaryConditionPre() const; [[nodiscard]] boundaryCondition getGeometryBoundaryConditionPost() const; + [[nodiscard]] precursorBoundaryConditionFunc getPrecursorBoundaryConditionPost() const; + [[nodiscard]] boundaryConditionWithParameter getStressBoundaryConditionPost() const; @@ -162,6 +178,7 @@ private: PressureBC pressureBoundaryCondition = PressureBC::NotSpecified; std::variant<VelocityBC, NoSlipBC, SlipBC> geometryBoundaryCondition = NoSlipBC::NoSlipImplicitBounceBack; StressBC stressBoundaryCondition = StressBC::NotSpecified; + PrecursorBC precursorBoundaryCondition = PrecursorBC::NotSpecified; // OutflowBoundaryConditon outflowBC // TODO: https://git.rz.tu-bs.de/m.schoenherr/VirtualFluids_dev/-/issues/16 }; diff --git a/src/gpu/VirtualFluids_GPU/GPU/CudaMemoryManager.cpp b/src/gpu/VirtualFluids_GPU/GPU/CudaMemoryManager.cpp index 22192216927f91c33fafc23c54c3fae334abdd34..f5908517491e252eae5078ec5ede4d5ba452bda7 100644 --- a/src/gpu/VirtualFluids_GPU/GPU/CudaMemoryManager.cpp +++ b/src/gpu/VirtualFluids_GPU/GPU/CudaMemoryManager.cpp @@ -5,14 +5,17 @@ #include <math.h> #include <Parameter/Parameter.h> + #include "Parameter/CudaStreamManager.h" -#include "PreCollisionInteractor/ActuatorLine.h" +#include "PreCollisionInteractor/ActuatorFarm.h" #include "PreCollisionInteractor/Probes/Probe.h" +#include <PreCollisionInteractor/PrecursorWriter.h> #include "Calculation/PorousMedia.h" #include "lbm/constants/NumericConstants.h" + void CudaMemoryManager::cudaAllocFull(int lev) { checkCudaErrors( cudaMallocHost((void**) &(parameter->getParH(lev)->geo ), parameter->getParH(lev)->mem_size_int )); @@ -239,6 +242,7 @@ void CudaMemoryManager::cudaCopyVeloBC(int lev) checkCudaErrors( cudaMemcpy(parameter->getParD(lev)->velocityBC.deltaVz, parameter->getParH(lev)->velocityBC.deltaVz, mem_size_inflow_Q_q, cudaMemcpyHostToDevice)); } + void CudaMemoryManager::cudaFreeVeloBC(int lev) { checkCudaErrors( cudaFreeHost(parameter->getParH(lev)->velocityBC.q27[0] )); @@ -524,24 +528,24 @@ void CudaMemoryManager::cudaCopyProcessNeighborXIndex(int lev, unsigned int proc cudaMemcpyHostToDevice)); } void CudaMemoryManager::cudaCopyProcessNeighborXFsHD(int lev, unsigned int processNeighbor, - const unsigned int &memsizeFsRecv, int streamIndex) + const unsigned int &memsizeFsRecv) { - if (streamIndex == -1) + if (!parameter->getStreamManager()->streamIsRegistered(CudaStreamIndex::SubDomainBorder)) checkCudaErrors( cudaMemcpy(parameter->getParD(lev)->recvProcessNeighborX[processNeighbor].f[0], parameter->getParH(lev)->recvProcessNeighborX[processNeighbor].f[0], parameter->getD3Qxx() * memsizeFsRecv, cudaMemcpyHostToDevice)); else checkCudaErrors( cudaMemcpyAsync(parameter->getParD(lev)->recvProcessNeighborX[processNeighbor].f[0], - parameter->getParH(lev)->recvProcessNeighborX[processNeighbor].f[0], - parameter->getD3Qxx() * memsizeFsRecv, - cudaMemcpyHostToDevice, - parameter->getStreamManager()->getStream(streamIndex))); + parameter->getParH(lev)->recvProcessNeighborX[processNeighbor].f[0], + parameter->getD3Qxx() * memsizeFsRecv, + cudaMemcpyHostToDevice, + parameter->getStreamManager()->getStream(CudaStreamIndex::SubDomainBorder))); } void CudaMemoryManager::cudaCopyProcessNeighborXFsDH(int lev, unsigned int processNeighbor, - const unsigned int &memsizeFsSend, int streamIndex) -{ - if (streamIndex == -1) + const unsigned int &memsizeFsSend) +{ + if (!parameter->getStreamManager()->streamIsRegistered(CudaStreamIndex::SubDomainBorder)) checkCudaErrors( cudaMemcpy(parameter->getParH(lev)->sendProcessNeighborX[processNeighbor].f[0], parameter->getParD(lev)->sendProcessNeighborX[processNeighbor].f[0], parameter->getD3Qxx() * memsizeFsSend, @@ -551,7 +555,7 @@ void CudaMemoryManager::cudaCopyProcessNeighborXFsDH(int lev, unsigned int proce parameter->getParD(lev)->sendProcessNeighborX[processNeighbor].f[0], parameter->getD3Qxx() * memsizeFsSend, cudaMemcpyDeviceToHost, - parameter->getStreamManager()->getStream(streamIndex))); + parameter->getStreamManager()->getStream(CudaStreamIndex::SubDomainBorder))); } void CudaMemoryManager::cudaFreeProcessNeighborX(int lev, unsigned int processNeighbor) { @@ -594,35 +598,33 @@ void CudaMemoryManager::cudaCopyProcessNeighborYIndex(int lev, unsigned int proc parameter->getParH(lev)->recvProcessNeighborY[processNeighbor].memsizeIndex, cudaMemcpyHostToDevice)); } -void CudaMemoryManager::cudaCopyProcessNeighborYFsHD(int lev, unsigned int processNeighbor, const unsigned int &memsizeFsRecv, - int streamIndex) +void CudaMemoryManager::cudaCopyProcessNeighborYFsHD(int lev, unsigned int processNeighbor, const unsigned int &memsizeFsRecv) { - if (streamIndex == -1) + if (!parameter->getStreamManager()->streamIsRegistered(CudaStreamIndex::SubDomainBorder)) checkCudaErrors( cudaMemcpy(parameter->getParD(lev)->recvProcessNeighborY[processNeighbor].f[0], parameter->getParH(lev)->recvProcessNeighborY[processNeighbor].f[0], parameter->getD3Qxx() * memsizeFsRecv, cudaMemcpyHostToDevice)); else - checkCudaErrors(cudaMemcpyAsync(parameter->getParD(lev)->recvProcessNeighborY[processNeighbor].f[0], - parameter->getParH(lev)->recvProcessNeighborY[processNeighbor].f[0], - parameter->getD3Qxx() * memsizeFsRecv, - cudaMemcpyHostToDevice, - parameter->getStreamManager()->getStream(streamIndex))); + checkCudaErrors( cudaMemcpyAsync(parameter->getParD(lev)->recvProcessNeighborY[processNeighbor].f[0], + parameter->getParH(lev)->recvProcessNeighborY[processNeighbor].f[0], + parameter->getD3Qxx() * memsizeFsRecv, + cudaMemcpyHostToDevice, + parameter->getStreamManager()->getStream(CudaStreamIndex::SubDomainBorder))); } -void CudaMemoryManager::cudaCopyProcessNeighborYFsDH(int lev, unsigned int processNeighbor, const unsigned int &memsizeFsSend, - int streamIndex) +void CudaMemoryManager::cudaCopyProcessNeighborYFsDH(int lev, unsigned int processNeighbor, const unsigned int &memsizeFsSend) { - if (streamIndex == -1) + if (!parameter->getStreamManager()->streamIsRegistered(CudaStreamIndex::SubDomainBorder)) checkCudaErrors( cudaMemcpy(parameter->getParH(lev)->sendProcessNeighborY[processNeighbor].f[0], parameter->getParD(lev)->sendProcessNeighborY[processNeighbor].f[0], parameter->getD3Qxx() * memsizeFsSend, cudaMemcpyDeviceToHost)); else - checkCudaErrors( - cudaMemcpyAsync(parameter->getParH(lev)->sendProcessNeighborY[processNeighbor].f[0], - parameter->getParD(lev)->sendProcessNeighborY[processNeighbor].f[0], - parameter->getD3Qxx() * memsizeFsSend, - cudaMemcpyDeviceToHost, parameter->getStreamManager()->getStream(streamIndex))); + checkCudaErrors( cudaMemcpyAsync(parameter->getParH(lev)->sendProcessNeighborY[processNeighbor].f[0], + parameter->getParD(lev)->sendProcessNeighborY[processNeighbor].f[0], + parameter->getD3Qxx() * memsizeFsSend, + cudaMemcpyDeviceToHost, + parameter->getStreamManager()->getStream(CudaStreamIndex::SubDomainBorder))); } void CudaMemoryManager::cudaFreeProcessNeighborY(int lev, unsigned int processNeighbor) { @@ -666,9 +668,9 @@ void CudaMemoryManager::cudaCopyProcessNeighborZIndex(int lev, unsigned int proc cudaMemcpyHostToDevice)); } void CudaMemoryManager::cudaCopyProcessNeighborZFsHD(int lev, unsigned int processNeighbor, - const unsigned int &memsizeFsRecv, int streamIndex) + const unsigned int &memsizeFsRecv) { - if (streamIndex == -1) + if (!parameter->getStreamManager()->streamIsRegistered(CudaStreamIndex::SubDomainBorder)) checkCudaErrors( cudaMemcpy(parameter->getParD(lev)->recvProcessNeighborZ[processNeighbor].f[0], parameter->getParH(lev)->recvProcessNeighborZ[processNeighbor].f[0], parameter->getD3Qxx() * memsizeFsRecv, @@ -678,12 +680,12 @@ void CudaMemoryManager::cudaCopyProcessNeighborZFsHD(int lev, unsigned int proce parameter->getParH(lev)->recvProcessNeighborZ[processNeighbor].f[0], parameter->getD3Qxx() * memsizeFsRecv, cudaMemcpyHostToDevice, - parameter->getStreamManager()->getStream(streamIndex))); + parameter->getStreamManager()->getStream(CudaStreamIndex::SubDomainBorder))); } void CudaMemoryManager::cudaCopyProcessNeighborZFsDH(int lev, unsigned int processNeighbor, - const unsigned int &memsizeFsSend, int streamIndex) + const unsigned int &memsizeFsSend) { - if (streamIndex == -1) + if (!parameter->getStreamManager()->streamIsRegistered(CudaStreamIndex::SubDomainBorder)) checkCudaErrors( cudaMemcpy(parameter->getParH(lev)->sendProcessNeighborZ[processNeighbor].f[0], parameter->getParD(lev)->sendProcessNeighborZ[processNeighbor].f[0], parameter->getD3Qxx() * memsizeFsSend, @@ -693,7 +695,7 @@ void CudaMemoryManager::cudaCopyProcessNeighborZFsDH(int lev, unsigned int proce parameter->getParD(lev)->sendProcessNeighborZ[processNeighbor].f[0], parameter->getD3Qxx() * memsizeFsSend, cudaMemcpyDeviceToHost, - parameter->getStreamManager()->getStream(streamIndex))); + parameter->getStreamManager()->getStream(CudaStreamIndex::SubDomainBorder))); } void CudaMemoryManager::cudaFreeProcessNeighborZ(int lev, unsigned int processNeighbor) { @@ -1655,6 +1657,133 @@ void CudaMemoryManager::cudaFreeWallModel(int lev, bool hasWallModelMonitor) } } + +//Precursor BC +void CudaMemoryManager::cudaAllocPrecursorBC(int lev) +{ + uint memSizeQInt = parameter->getParH(lev)->precursorBC.numberOfBCnodes*sizeof(int); + uint memSizeQUint = parameter->getParH(lev)->precursorBC.numberOfBCnodes*sizeof(uint); + uint memSizeQReal = parameter->getParH(lev)->precursorBC.numberOfBCnodes*sizeof(real); + + checkCudaErrors( cudaMallocHost((void**) ¶meter->getParH(lev)->precursorBC.k, memSizeQInt)); + checkCudaErrors( cudaMallocHost((void**) ¶meter->getParH(lev)->precursorBC.q27[0], parameter->getD3Qxx()*memSizeQReal)); + + + checkCudaErrors( cudaMallocHost((void**) ¶meter->getParH(lev)->precursorBC.planeNeighbor0PP, memSizeQUint)); + checkCudaErrors( cudaMallocHost((void**) ¶meter->getParH(lev)->precursorBC.planeNeighbor0PM, memSizeQUint)); + checkCudaErrors( cudaMallocHost((void**) ¶meter->getParH(lev)->precursorBC.planeNeighbor0MP, memSizeQUint)); + checkCudaErrors( cudaMallocHost((void**) ¶meter->getParH(lev)->precursorBC.planeNeighbor0MM, memSizeQUint)); + + checkCudaErrors( cudaMallocHost((void**) ¶meter->getParH(lev)->precursorBC.weights0PP, memSizeQReal)); + checkCudaErrors( cudaMallocHost((void**) ¶meter->getParH(lev)->precursorBC.weights0PM, memSizeQReal)); + checkCudaErrors( cudaMallocHost((void**) ¶meter->getParH(lev)->precursorBC.weights0MP, memSizeQReal)); + checkCudaErrors( cudaMallocHost((void**) ¶meter->getParH(lev)->precursorBC.weights0MM, memSizeQReal)); + + checkCudaErrors( cudaMalloc((void**) ¶meter->getParD(lev)->precursorBC.k, memSizeQInt)); + checkCudaErrors( cudaMalloc((void**) ¶meter->getParD(lev)->precursorBC.q27[0], parameter->getD3Qxx()*memSizeQReal)); + + checkCudaErrors( cudaMalloc((void**) ¶meter->getParD(lev)->precursorBC.planeNeighbor0PP, memSizeQUint)); + checkCudaErrors( cudaMalloc((void**) ¶meter->getParD(lev)->precursorBC.planeNeighbor0PM, memSizeQUint)); + checkCudaErrors( cudaMalloc((void**) ¶meter->getParD(lev)->precursorBC.planeNeighbor0MP, memSizeQUint)); + checkCudaErrors( cudaMalloc((void**) ¶meter->getParD(lev)->precursorBC.planeNeighbor0MM, memSizeQUint)); + + checkCudaErrors( cudaMalloc((void**) ¶meter->getParD(lev)->precursorBC.weights0PP, memSizeQReal)); + checkCudaErrors( cudaMalloc((void**) ¶meter->getParD(lev)->precursorBC.weights0PM, memSizeQReal)); + checkCudaErrors( cudaMalloc((void**) ¶meter->getParD(lev)->precursorBC.weights0MP, memSizeQReal)); + checkCudaErrors( cudaMalloc((void**) ¶meter->getParD(lev)->precursorBC.weights0MM, memSizeQReal)); + + real memSize = memSizeQInt+4*memSizeQUint+(4+parameter->getD3Qxx())*memSizeQReal; + setMemsizeGPU(memSize, false); + +} + + +void CudaMemoryManager::cudaAllocPrecursorData(int lev) +{ + size_t size = parameter->getParH(lev)->precursorBC.numberOfPrecursorNodes*sizeof(real)*parameter->getParH(lev)->precursorBC.numberOfQuantities; + + checkCudaErrors( cudaMallocHost((void**) ¶meter->getParH(lev)->precursorBC.last, size)); + checkCudaErrors( cudaMallocHost((void**) ¶meter->getParH(lev)->precursorBC.current, size)); + checkCudaErrors( cudaMallocHost((void**) ¶meter->getParH(lev)->precursorBC.next, size)); + + checkCudaErrors( cudaMalloc((void**) ¶meter->getParD(lev)->precursorBC.last, size)); + checkCudaErrors( cudaMalloc((void**) ¶meter->getParD(lev)->precursorBC.current, size)); + checkCudaErrors( cudaMalloc((void**) ¶meter->getParD(lev)->precursorBC.next, size)); + setMemsizeGPU(3*size, false); +} + + +void CudaMemoryManager::cudaCopyPrecursorBC(int lev) +{ + uint memSizeQInt = parameter->getParH(lev)->precursorBC.numberOfBCnodes*sizeof(int); + uint memSizeQUint = parameter->getParH(lev)->precursorBC.numberOfBCnodes*sizeof(uint); + uint memSizeQReal = parameter->getParH(lev)->precursorBC.numberOfBCnodes*sizeof(real); + + checkCudaErrors( cudaMemcpy(parameter->getParD(lev)->precursorBC.k, parameter->getParH(lev)->precursorBC.k, memSizeQInt, cudaMemcpyHostToDevice)); + + checkCudaErrors( cudaMemcpy(parameter->getParD(lev)->precursorBC.q27[0], parameter->getParH(lev)->precursorBC.q27[0], memSizeQReal*parameter->getD3Qxx(), cudaMemcpyHostToDevice)); + + checkCudaErrors( cudaMemcpy(parameter->getParD(lev)->precursorBC.planeNeighbor0PP, parameter->getParH(lev)->precursorBC.planeNeighbor0PP, memSizeQUint, cudaMemcpyHostToDevice)); + checkCudaErrors( cudaMemcpy(parameter->getParD(lev)->precursorBC.planeNeighbor0PM, parameter->getParH(lev)->precursorBC.planeNeighbor0PM, memSizeQUint, cudaMemcpyHostToDevice)); + checkCudaErrors( cudaMemcpy(parameter->getParD(lev)->precursorBC.planeNeighbor0MP, parameter->getParH(lev)->precursorBC.planeNeighbor0MP, memSizeQUint, cudaMemcpyHostToDevice)); + checkCudaErrors( cudaMemcpy(parameter->getParD(lev)->precursorBC.planeNeighbor0MM, parameter->getParH(lev)->precursorBC.planeNeighbor0MM, memSizeQUint, cudaMemcpyHostToDevice)); + + checkCudaErrors( cudaMemcpy(parameter->getParD(lev)->precursorBC.weights0PP, parameter->getParH(lev)->precursorBC.weights0PP, memSizeQReal, cudaMemcpyHostToDevice)); + checkCudaErrors( cudaMemcpy(parameter->getParD(lev)->precursorBC.weights0PM, parameter->getParH(lev)->precursorBC.weights0PM, memSizeQReal, cudaMemcpyHostToDevice)); + checkCudaErrors( cudaMemcpy(parameter->getParD(lev)->precursorBC.weights0MP, parameter->getParH(lev)->precursorBC.weights0MP, memSizeQReal, cudaMemcpyHostToDevice)); + checkCudaErrors( cudaMemcpy(parameter->getParD(lev)->precursorBC.weights0MM, parameter->getParH(lev)->precursorBC.weights0MM, memSizeQReal, cudaMemcpyHostToDevice)); +} +void CudaMemoryManager::cudaCopyPrecursorData(int lev) +{ + auto prec = ¶meter->getParH(lev)->precursorBC; + auto precStream = parameter->getStreamManager()->getStream(CudaStreamIndex::Precursor); + size_t memSize = prec->numberOfPrecursorNodes*sizeof(real)*prec->numberOfQuantities; + checkCudaErrors( cudaStreamSynchronize(precStream) ); + checkCudaErrors( cudaMemcpyAsync(parameter->getParD(lev)->precursorBC.next, prec->next, memSize, cudaMemcpyHostToDevice, precStream) ); +} + + +void CudaMemoryManager::cudaFreePrecursorBC(int lev) +{ + checkCudaErrors( cudaFreeHost( parameter->getParH(lev)->precursorBC.k)); + + checkCudaErrors( cudaFreeHost( parameter->getParH(lev)->precursorBC.q27[0])); + + checkCudaErrors( cudaFreeHost( parameter->getParH(lev)->precursorBC.planeNeighbor0PP)); + checkCudaErrors( cudaFreeHost( parameter->getParH(lev)->precursorBC.planeNeighbor0PM)); + checkCudaErrors( cudaFreeHost( parameter->getParH(lev)->precursorBC.planeNeighbor0MP)); + checkCudaErrors( cudaFreeHost( parameter->getParH(lev)->precursorBC.planeNeighbor0MM)); + + checkCudaErrors( cudaFreeHost( parameter->getParH(lev)->precursorBC.weights0PP)); + checkCudaErrors( cudaFreeHost( parameter->getParH(lev)->precursorBC.weights0PM)); + checkCudaErrors( cudaFreeHost( parameter->getParH(lev)->precursorBC.weights0MP)); + checkCudaErrors( cudaFreeHost( parameter->getParH(lev)->precursorBC.weights0MM)); + + checkCudaErrors( cudaFree( parameter->getParD(lev)->precursorBC.k)); + + checkCudaErrors( cudaFree( parameter->getParD(lev)->precursorBC.q27[0])); + + checkCudaErrors( cudaFree( parameter->getParD(lev)->precursorBC.planeNeighbor0PP)); + checkCudaErrors( cudaFree( parameter->getParD(lev)->precursorBC.planeNeighbor0PM)); + checkCudaErrors( cudaFree( parameter->getParD(lev)->precursorBC.planeNeighbor0MP)); + checkCudaErrors( cudaFree( parameter->getParD(lev)->precursorBC.planeNeighbor0MM)); + + checkCudaErrors( cudaFree( parameter->getParD(lev)->precursorBC.weights0PP)); + checkCudaErrors( cudaFree( parameter->getParD(lev)->precursorBC.weights0PM)); + checkCudaErrors( cudaFree( parameter->getParD(lev)->precursorBC.weights0MP)); + checkCudaErrors( cudaFree( parameter->getParD(lev)->precursorBC.weights0MM)); +} + +void CudaMemoryManager::cudaFreePrecursorData(int lev) +{ + checkCudaErrors( cudaFreeHost( parameter->getParH(lev)->precursorBC.last)); + checkCudaErrors( cudaFreeHost( parameter->getParH(lev)->precursorBC.current)); + checkCudaErrors( cudaFreeHost( parameter->getParH(lev)->precursorBC.next)); + + checkCudaErrors( cudaFree( parameter->getParD(lev)->precursorBC.last)); + checkCudaErrors( cudaFree( parameter->getParD(lev)->precursorBC.current)); + checkCudaErrors( cudaFree( parameter->getParD(lev)->precursorBC.next)); +} //Test roundoff error void CudaMemoryManager::cudaAllocTestRE(int lev, unsigned int size) { @@ -2921,231 +3050,297 @@ void CudaMemoryManager::cudaFree2ndOrderDerivitivesIsoTest(int lev) } -void CudaMemoryManager::cudaAllocFluidNodeIndices(int lev) { - uint mem_size_geo_fluid_nodes = sizeof(uint) * parameter->getParH(lev)->numberOfFluidNodes; +void CudaMemoryManager::cudaAllocTaggedFluidNodeIndices(CollisionTemplate tag, int lev) { + uint mem_size_tagged_fluid_nodes = sizeof(uint) * parameter->getParH(lev)->numberOfTaggedFluidNodes[tag]; // Host - checkCudaErrors(cudaMallocHost((void **)&(parameter->getParH(lev)->fluidNodeIndices), mem_size_geo_fluid_nodes)); + checkCudaErrors(cudaMallocHost((void **)&(parameter->getParH(lev)->taggedFluidNodeIndices[tag]), mem_size_tagged_fluid_nodes)); // Device - checkCudaErrors(cudaMalloc((void **)&(parameter->getParD(lev)->fluidNodeIndices), mem_size_geo_fluid_nodes)); + checkCudaErrors(cudaMalloc((void **)&(parameter->getParD(lev)->taggedFluidNodeIndices[tag]), mem_size_tagged_fluid_nodes)); ////////////////////////////////////////////////////////////////////////// - setMemsizeGPU((double)mem_size_geo_fluid_nodes, false); + setMemsizeGPU((double)mem_size_tagged_fluid_nodes, false); } -void CudaMemoryManager::cudaCopyFluidNodeIndices(int lev) { - uint mem_size_geo_fluid_nodes = sizeof(uint) * parameter->getParH(lev)->numberOfFluidNodes; - checkCudaErrors(cudaMemcpy(parameter->getParD(lev)->fluidNodeIndices, - parameter->getParH(lev)->fluidNodeIndices, - mem_size_geo_fluid_nodes, cudaMemcpyHostToDevice)); +void CudaMemoryManager::cudaCopyTaggedFluidNodeIndices(CollisionTemplate tag, int lev) { + uint mem_size_tagged_fluid_nodes = sizeof(uint) * parameter->getParH(lev)->numberOfTaggedFluidNodes[tag]; + checkCudaErrors(cudaMemcpy(parameter->getParD(lev)->taggedFluidNodeIndices[tag], + parameter->getParH(lev)->taggedFluidNodeIndices[tag], + mem_size_tagged_fluid_nodes, cudaMemcpyHostToDevice)); } -void CudaMemoryManager::cudaFreeFluidNodeIndices(int lev) { - checkCudaErrors(cudaFreeHost(parameter->getParH(lev)->fluidNodeIndices)); +void CudaMemoryManager::cudaFreeTaggedFluidNodeIndices(CollisionTemplate tag, int lev) { + checkCudaErrors(cudaFreeHost(parameter->getParH(lev)->taggedFluidNodeIndices[tag])); } -void CudaMemoryManager::cudaAllocFluidNodeIndicesBorder(int lev) { - uint mem_size_fluid_nodes_border = sizeof(uint) * parameter->getParH(lev)->numberOfFluidNodesBorder; - // Host - checkCudaErrors( - cudaMallocHost((void **)&(parameter->getParH(lev)->fluidNodeIndicesBorder), mem_size_fluid_nodes_border)); - // Device - checkCudaErrors( - cudaMalloc((void **)&(parameter->getParD(lev)->fluidNodeIndicesBorder), mem_size_fluid_nodes_border)); - ////////////////////////////////////////////////////////////////////////// - setMemsizeGPU((double)mem_size_fluid_nodes_border, false); -} +//////////////////////////////////////////////////////////////////////////////////// +// ActuatorFarm +/////////////////////////////////////////////////////////////////////////////// +void CudaMemoryManager::cudaAllocBladeGeometries(ActuatorFarm* actuatorFarm) +{ + uint sizeRealTurbine = sizeof(real)*actuatorFarm->getNumberOfTurbines(); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->bladeRadiiH, sizeRealTurbine*actuatorFarm->getNumberOfNodesPerBlade()) ); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->diametersH, sizeRealTurbine) ); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->turbinePosXH, sizeRealTurbine) ); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->turbinePosYH, sizeRealTurbine) ); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->turbinePosZH, sizeRealTurbine) ); + + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeRadiiD, sizeRealTurbine*actuatorFarm->getNumberOfNodesPerBlade()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->diametersD, sizeRealTurbine) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->turbinePosXD, sizeRealTurbine) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->turbinePosYD, sizeRealTurbine) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->turbinePosZD, sizeRealTurbine) ); + setMemsizeGPU(sizeof(real)*(actuatorFarm->getNumberOfNodesPerBlade()+4)*actuatorFarm->getNumberOfTurbines(), false); -void CudaMemoryManager::cudaCopyFluidNodeIndicesBorder(int lev) { - uint mem_size_fluid_nodes_border = sizeof(uint) * parameter->getParH(lev)->numberOfFluidNodesBorder; - checkCudaErrors(cudaMemcpy(parameter->getParD(lev)->fluidNodeIndicesBorder, - parameter->getParH(lev)->fluidNodeIndicesBorder, - mem_size_fluid_nodes_border, cudaMemcpyHostToDevice)); } +void CudaMemoryManager::cudaCopyBladeGeometriesHtoD(ActuatorFarm* actuatorFarm) +{ + uint sizeRealTurbine = sizeof(real)*actuatorFarm->getNumberOfTurbines(); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeRadiiD, actuatorFarm->bladeRadiiH, sizeRealTurbine*actuatorFarm->getNumberOfNodesPerBlade(), cudaMemcpyHostToDevice) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->diametersD, actuatorFarm->diametersH, sizeRealTurbine, cudaMemcpyHostToDevice) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->turbinePosXD, actuatorFarm->turbinePosXH, sizeRealTurbine, cudaMemcpyHostToDevice) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->turbinePosYD, actuatorFarm->turbinePosYH, sizeRealTurbine, cudaMemcpyHostToDevice) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->turbinePosZD, actuatorFarm->turbinePosZH, sizeRealTurbine, cudaMemcpyHostToDevice) ); -void CudaMemoryManager::cudaFreeFluidNodeIndicesBorder(int lev) { - checkCudaErrors(cudaFreeHost(parameter->getParH(lev)->fluidNodeIndicesBorder)); } +void CudaMemoryManager::cudaCopyBladeGeometriesDtoH(ActuatorFarm* actuatorFarm) +{ + uint sizeRealTurbine = sizeof(real)*actuatorFarm->getNumberOfTurbines(); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeRadiiH, actuatorFarm->bladeRadiiD, sizeRealTurbine*actuatorFarm->getNumberOfNodesPerBlade(), cudaMemcpyDeviceToHost) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->diametersH, actuatorFarm->diametersD, sizeRealTurbine, cudaMemcpyDeviceToHost) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->turbinePosXH, actuatorFarm->turbinePosXD, sizeRealTurbine, cudaMemcpyDeviceToHost) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->turbinePosYH, actuatorFarm->turbinePosYD, sizeRealTurbine, cudaMemcpyDeviceToHost) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->turbinePosZH, actuatorFarm->turbinePosZD, sizeRealTurbine, cudaMemcpyDeviceToHost) ); -//////////////////////////////////////////////////////////////////////////////////// -// ActuatorLine -/////////////////////////////////////////////////////////////////////////////// +} +void CudaMemoryManager::cudaFreeBladeGeometries(ActuatorFarm* actuatorFarm) +{ + checkCudaErrors( cudaFree(actuatorFarm->bladeRadiiD) ); + checkCudaErrors( cudaFree(actuatorFarm->diametersD) ); + checkCudaErrors( cudaFree(actuatorFarm->turbinePosXD) ); + checkCudaErrors( cudaFree(actuatorFarm->turbinePosYD) ); + checkCudaErrors( cudaFree(actuatorFarm->turbinePosZD) ); + + checkCudaErrors( cudaFreeHost(actuatorFarm->bladeRadiiH) ); + checkCudaErrors( cudaFreeHost(actuatorFarm->diametersH) ); + checkCudaErrors( cudaFreeHost(actuatorFarm->turbinePosXH) ); + checkCudaErrors( cudaFreeHost(actuatorFarm->turbinePosYH) ); + checkCudaErrors( cudaFreeHost(actuatorFarm->turbinePosZH) ); +} -void CudaMemoryManager::cudaAllocBladeRadii(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaAllocBladeOrientations(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaMallocHost((void**) &actuatorLine->bladeRadiiH, sizeof(real)*actuatorLine->getNBladeNodes()) ); + uint sizeRealTurbine = sizeof(real)*actuatorFarm->getNumberOfTurbines(); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->omegasH, sizeRealTurbine) ); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->azimuthsH, sizeRealTurbine) ); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->yawsH, sizeRealTurbine) ); - checkCudaErrors( cudaMalloc((void**) &actuatorLine->bladeRadiiD, sizeof(real)*actuatorLine->getNBladeNodes()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->omegasD, sizeRealTurbine) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->azimuthsD, sizeRealTurbine) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->yawsD, sizeRealTurbine) ); - setMemsizeGPU(sizeof(real)*actuatorLine->getNBladeNodes(), false); -} + setMemsizeGPU(3*sizeRealTurbine, false); -void CudaMemoryManager::cudaCopyBladeRadiiHtoD(ActuatorLine* actuatorLine) -{ - checkCudaErrors( cudaMemcpy(actuatorLine->bladeRadiiD, actuatorLine->bladeRadiiH, sizeof(real)*actuatorLine->getNBladeNodes(), cudaMemcpyHostToDevice) ); } +void CudaMemoryManager::cudaCopyBladeOrientationsHtoD(ActuatorFarm* actuatorFarm) +{ + uint sizeRealTurbine = sizeof(real)*actuatorFarm->getNumberOfTurbines(); + checkCudaErrors( cudaMemcpy(actuatorFarm->omegasD, actuatorFarm->omegasH, sizeRealTurbine, cudaMemcpyHostToDevice) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->azimuthsD, actuatorFarm->azimuthsH, sizeRealTurbine, cudaMemcpyHostToDevice) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->yawsD, actuatorFarm->yawsH, sizeRealTurbine, cudaMemcpyHostToDevice) ); -void CudaMemoryManager::cudaCopyBladeRadiiDtoH(ActuatorLine* actuatorLine) +} +void CudaMemoryManager::cudaCopyBladeOrientationsDtoH(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaMemcpy(actuatorLine->bladeRadiiH, actuatorLine->bladeRadiiD, sizeof(real)*actuatorLine->getNBladeNodes(), cudaMemcpyDeviceToHost) ); + uint sizeRealTurbine = sizeof(real)*actuatorFarm->getNumberOfTurbines(); + checkCudaErrors( cudaMemcpy(actuatorFarm->omegasH, actuatorFarm->omegasD, sizeRealTurbine, cudaMemcpyDeviceToHost) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->azimuthsH, actuatorFarm->azimuthsD, sizeRealTurbine, cudaMemcpyDeviceToHost) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->yawsH, actuatorFarm->yawsD, sizeRealTurbine, cudaMemcpyDeviceToHost) ); } - -void CudaMemoryManager::cudaFreeBladeRadii(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaFreeBladeOrientations(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaFree(actuatorLine->bladeRadiiD) ); + checkCudaErrors( cudaFree((void**) &actuatorFarm->omegasD) ); + checkCudaErrors( cudaFree((void**) &actuatorFarm->azimuthsD) ); + checkCudaErrors( cudaFree((void**) &actuatorFarm->yawsD) ); - checkCudaErrors( cudaFreeHost(actuatorLine->bladeRadiiH) ); + checkCudaErrors( cudaFreeHost((void**) &actuatorFarm->omegasH) ); + checkCudaErrors( cudaFreeHost((void**) &actuatorFarm->azimuthsH) ); + checkCudaErrors( cudaFreeHost((void**) &actuatorFarm->yawsH) ); } -void CudaMemoryManager::cudaAllocBladeCoords(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaAllocBladeCoords(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaMallocHost((void**) &actuatorLine->bladeCoordsXH, sizeof(real)*actuatorLine->getNNodes()) ); - checkCudaErrors( cudaMallocHost((void**) &actuatorLine->bladeCoordsYH, sizeof(real)*actuatorLine->getNNodes()) ); - checkCudaErrors( cudaMallocHost((void**) &actuatorLine->bladeCoordsZH, sizeof(real)*actuatorLine->getNNodes()) ); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->bladeCoordsXH, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->bladeCoordsYH, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->bladeCoordsZH, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); - checkCudaErrors( cudaMalloc((void**) &actuatorLine->bladeCoordsXD, sizeof(real)*actuatorLine->getNNodes()) ); - checkCudaErrors( cudaMalloc((void**) &actuatorLine->bladeCoordsYD, sizeof(real)*actuatorLine->getNNodes()) ); - checkCudaErrors( cudaMalloc((void**) &actuatorLine->bladeCoordsZD, sizeof(real)*actuatorLine->getNNodes()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeCoordsXDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeCoordsYDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeCoordsZDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeCoordsXDPreviousTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeCoordsYDPreviousTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeCoordsZDPreviousTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); - setMemsizeGPU(3.f*actuatorLine->getNNodes(), false); + setMemsizeGPU(6.f*actuatorFarm->getNumberOfNodes(), false); } -void CudaMemoryManager::cudaCopyBladeCoordsHtoD(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaCopyBladeCoordsHtoD(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaMemcpy(actuatorLine->bladeCoordsXD, actuatorLine->bladeCoordsXH, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyHostToDevice) ); - checkCudaErrors( cudaMemcpy(actuatorLine->bladeCoordsYD, actuatorLine->bladeCoordsYH, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyHostToDevice) ); - checkCudaErrors( cudaMemcpy(actuatorLine->bladeCoordsZD, actuatorLine->bladeCoordsZH, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyHostToDevice) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeCoordsXDCurrentTimestep, actuatorFarm->bladeCoordsXH, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyHostToDevice) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeCoordsYDCurrentTimestep, actuatorFarm->bladeCoordsYH, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyHostToDevice) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeCoordsZDCurrentTimestep, actuatorFarm->bladeCoordsZH, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyHostToDevice) ); } -void CudaMemoryManager::cudaCopyBladeCoordsDtoH(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaCopyBladeCoordsDtoH(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaMemcpy(actuatorLine->bladeCoordsXH, actuatorLine->bladeCoordsXD, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyDeviceToHost) ); - checkCudaErrors( cudaMemcpy(actuatorLine->bladeCoordsYH, actuatorLine->bladeCoordsYD, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyDeviceToHost) ); - checkCudaErrors( cudaMemcpy(actuatorLine->bladeCoordsZH, actuatorLine->bladeCoordsZD, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyDeviceToHost) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeCoordsXH, actuatorFarm->bladeCoordsXDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyDeviceToHost) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeCoordsYH, actuatorFarm->bladeCoordsYDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyDeviceToHost) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeCoordsZH, actuatorFarm->bladeCoordsZDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyDeviceToHost) ); } -void CudaMemoryManager::cudaFreeBladeCoords(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaFreeBladeCoords(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaFree(actuatorLine->bladeCoordsXD) ); - checkCudaErrors( cudaFree(actuatorLine->bladeCoordsYD) ); - checkCudaErrors( cudaFree(actuatorLine->bladeCoordsZD) ); + checkCudaErrors( cudaFree(actuatorFarm->bladeCoordsXDCurrentTimestep) ); + checkCudaErrors( cudaFree(actuatorFarm->bladeCoordsYDCurrentTimestep) ); + checkCudaErrors( cudaFree(actuatorFarm->bladeCoordsZDCurrentTimestep) ); + + checkCudaErrors( cudaFree(actuatorFarm->bladeCoordsXDPreviousTimestep) ); + checkCudaErrors( cudaFree(actuatorFarm->bladeCoordsYDPreviousTimestep) ); + checkCudaErrors( cudaFree(actuatorFarm->bladeCoordsZDPreviousTimestep) ); - checkCudaErrors( cudaFreeHost(actuatorLine->bladeCoordsXH) ); - checkCudaErrors( cudaFreeHost(actuatorLine->bladeCoordsYH) ); - checkCudaErrors( cudaFreeHost(actuatorLine->bladeCoordsZH) ); + checkCudaErrors( cudaFreeHost(actuatorFarm->bladeCoordsXH) ); + checkCudaErrors( cudaFreeHost(actuatorFarm->bladeCoordsYH) ); + checkCudaErrors( cudaFreeHost(actuatorFarm->bladeCoordsZH) ); } -void CudaMemoryManager::cudaAllocBladeIndices(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaAllocBladeIndices(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaMallocHost((void**) &actuatorLine->bladeIndicesH, sizeof(uint)*actuatorLine->getNNodes()) ); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->bladeIndicesH, sizeof(uint)*actuatorFarm->getNumberOfNodes()) ); - checkCudaErrors( cudaMalloc((void**) &actuatorLine->bladeIndicesD, sizeof(uint)*actuatorLine->getNNodes()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeIndicesD, sizeof(uint)*actuatorFarm->getNumberOfNodes()) ); - setMemsizeGPU(sizeof(uint)*actuatorLine->getNNodes(), false); + setMemsizeGPU(sizeof(uint)*actuatorFarm->getNumberOfNodes(), false); } -void CudaMemoryManager::cudaCopyBladeIndicesHtoD(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaCopyBladeIndicesHtoD(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaMemcpy(actuatorLine->bladeIndicesD, actuatorLine->bladeIndicesH, sizeof(uint)*actuatorLine->getNNodes(), cudaMemcpyHostToDevice) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeIndicesD, actuatorFarm->bladeIndicesH, sizeof(uint)*actuatorFarm->getNumberOfNodes(), cudaMemcpyHostToDevice) ); } -void CudaMemoryManager::cudaFreeBladeIndices(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaFreeBladeIndices(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaFree(actuatorLine->bladeIndicesD) ); + checkCudaErrors( cudaFree(actuatorFarm->bladeIndicesD) ); - checkCudaErrors( cudaFreeHost(actuatorLine->bladeIndicesH) ); + checkCudaErrors( cudaFreeHost(actuatorFarm->bladeIndicesH) ); } -void CudaMemoryManager::cudaAllocBladeVelocities(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaAllocBladeVelocities(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaMallocHost((void**) &actuatorLine->bladeVelocitiesXH, sizeof(real)*actuatorLine->getNNodes()) ); - checkCudaErrors( cudaMallocHost((void**) &actuatorLine->bladeVelocitiesYH, sizeof(real)*actuatorLine->getNNodes()) ); - checkCudaErrors( cudaMallocHost((void**) &actuatorLine->bladeVelocitiesZH, sizeof(real)*actuatorLine->getNNodes()) ); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->bladeVelocitiesXH, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->bladeVelocitiesYH, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->bladeVelocitiesZH, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); - checkCudaErrors( cudaMalloc((void**) &actuatorLine->bladeVelocitiesXD, sizeof(real)*actuatorLine->getNNodes()) ); - checkCudaErrors( cudaMalloc((void**) &actuatorLine->bladeVelocitiesYD, sizeof(real)*actuatorLine->getNNodes()) ); - checkCudaErrors( cudaMalloc((void**) &actuatorLine->bladeVelocitiesZD, sizeof(real)*actuatorLine->getNNodes()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeVelocitiesXDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeVelocitiesYDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeVelocitiesZDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); - setMemsizeGPU(3.*sizeof(real)*actuatorLine->getNNodes(), false); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeVelocitiesXDPreviousTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeVelocitiesYDPreviousTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeVelocitiesZDPreviousTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + + setMemsizeGPU(3.*sizeof(real)*actuatorFarm->getNumberOfNodes(), false); } -void CudaMemoryManager::cudaCopyBladeVelocitiesHtoD(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaCopyBladeVelocitiesHtoD(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaMemcpy(actuatorLine->bladeVelocitiesXD, actuatorLine->bladeVelocitiesXH, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyHostToDevice) ); - checkCudaErrors( cudaMemcpy(actuatorLine->bladeVelocitiesYD, actuatorLine->bladeVelocitiesYH, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyHostToDevice) ); - checkCudaErrors( cudaMemcpy(actuatorLine->bladeVelocitiesZD, actuatorLine->bladeVelocitiesZH, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyHostToDevice) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeVelocitiesXDCurrentTimestep, actuatorFarm->bladeVelocitiesXH, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyHostToDevice) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeVelocitiesYDCurrentTimestep, actuatorFarm->bladeVelocitiesYH, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyHostToDevice) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeVelocitiesZDCurrentTimestep, actuatorFarm->bladeVelocitiesZH, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyHostToDevice) ); } -void CudaMemoryManager::cudaCopyBladeVelocitiesDtoH(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaCopyBladeVelocitiesDtoH(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaMemcpy(actuatorLine->bladeVelocitiesXH, actuatorLine->bladeVelocitiesXD, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyDeviceToHost) ); - checkCudaErrors( cudaMemcpy(actuatorLine->bladeVelocitiesYH, actuatorLine->bladeVelocitiesYD, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyDeviceToHost) ); - checkCudaErrors( cudaMemcpy(actuatorLine->bladeVelocitiesZH, actuatorLine->bladeVelocitiesZD, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyDeviceToHost) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeVelocitiesXH, actuatorFarm->bladeVelocitiesXDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyDeviceToHost) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeVelocitiesYH, actuatorFarm->bladeVelocitiesYDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyDeviceToHost) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeVelocitiesZH, actuatorFarm->bladeVelocitiesZDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyDeviceToHost) ); } -void CudaMemoryManager::cudaFreeBladeVelocities(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaFreeBladeVelocities(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaFree(actuatorLine->bladeVelocitiesXD) ); - checkCudaErrors( cudaFree(actuatorLine->bladeVelocitiesYD) ); - checkCudaErrors( cudaFree(actuatorLine->bladeVelocitiesZD) ); + checkCudaErrors( cudaFree(actuatorFarm->bladeVelocitiesXDCurrentTimestep) ); + checkCudaErrors( cudaFree(actuatorFarm->bladeVelocitiesYDCurrentTimestep) ); + checkCudaErrors( cudaFree(actuatorFarm->bladeVelocitiesZDCurrentTimestep) ); + + checkCudaErrors( cudaFree(actuatorFarm->bladeVelocitiesXDPreviousTimestep) ); + checkCudaErrors( cudaFree(actuatorFarm->bladeVelocitiesYDPreviousTimestep) ); + checkCudaErrors( cudaFree(actuatorFarm->bladeVelocitiesZDPreviousTimestep) ); - checkCudaErrors( cudaFreeHost(actuatorLine->bladeVelocitiesXH) ); - checkCudaErrors( cudaFreeHost(actuatorLine->bladeVelocitiesYH) ); - checkCudaErrors( cudaFreeHost(actuatorLine->bladeVelocitiesZH) ); + checkCudaErrors( cudaFreeHost(actuatorFarm->bladeVelocitiesXH) ); + checkCudaErrors( cudaFreeHost(actuatorFarm->bladeVelocitiesYH) ); + checkCudaErrors( cudaFreeHost(actuatorFarm->bladeVelocitiesZH) ); } -void CudaMemoryManager::cudaAllocBladeForces(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaAllocBladeForces(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaMallocHost((void**) &actuatorLine->bladeForcesXH, sizeof(real)*actuatorLine->getNNodes()) ); - checkCudaErrors( cudaMallocHost((void**) &actuatorLine->bladeForcesYH, sizeof(real)*actuatorLine->getNNodes()) ); - checkCudaErrors( cudaMallocHost((void**) &actuatorLine->bladeForcesZH, sizeof(real)*actuatorLine->getNNodes()) ); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->bladeForcesXH, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->bladeForcesYH, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMallocHost((void**) &actuatorFarm->bladeForcesZH, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeForcesXDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeForcesYDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeForcesZDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); - checkCudaErrors( cudaMalloc((void**) &actuatorLine->bladeForcesXD, sizeof(real)*actuatorLine->getNNodes()) ); - checkCudaErrors( cudaMalloc((void**) &actuatorLine->bladeForcesYD, sizeof(real)*actuatorLine->getNNodes()) ); - checkCudaErrors( cudaMalloc((void**) &actuatorLine->bladeForcesZD, sizeof(real)*actuatorLine->getNNodes()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeForcesXDPreviousTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeForcesYDPreviousTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); + checkCudaErrors( cudaMalloc((void**) &actuatorFarm->bladeForcesZDPreviousTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes()) ); - setMemsizeGPU(3.*sizeof(real)*actuatorLine->getNNodes(), false); + setMemsizeGPU(3.*sizeof(real)*actuatorFarm->getNumberOfNodes(), false); } -void CudaMemoryManager::cudaCopyBladeForcesHtoD(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaCopyBladeForcesHtoD(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaMemcpy(actuatorLine->bladeForcesXD, actuatorLine->bladeForcesXH, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyHostToDevice) ); - checkCudaErrors( cudaMemcpy(actuatorLine->bladeForcesYD, actuatorLine->bladeForcesYH, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyHostToDevice) ); - checkCudaErrors( cudaMemcpy(actuatorLine->bladeForcesZD, actuatorLine->bladeForcesZH, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyHostToDevice) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeForcesXDCurrentTimestep, actuatorFarm->bladeForcesXH, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyHostToDevice) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeForcesYDCurrentTimestep, actuatorFarm->bladeForcesYH, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyHostToDevice) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeForcesZDCurrentTimestep, actuatorFarm->bladeForcesZH, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyHostToDevice) ); } -void CudaMemoryManager::cudaCopyBladeForcesDtoH(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaCopyBladeForcesDtoH(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaMemcpy(actuatorLine->bladeForcesXH, actuatorLine->bladeForcesXD, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyDeviceToHost) ); - checkCudaErrors( cudaMemcpy(actuatorLine->bladeForcesYH, actuatorLine->bladeForcesYD, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyDeviceToHost) ); - checkCudaErrors( cudaMemcpy(actuatorLine->bladeForcesZH, actuatorLine->bladeForcesZD, sizeof(real)*actuatorLine->getNNodes(), cudaMemcpyDeviceToHost) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeForcesXH, actuatorFarm->bladeForcesXDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyDeviceToHost) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeForcesYH, actuatorFarm->bladeForcesYDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyDeviceToHost) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->bladeForcesZH, actuatorFarm->bladeForcesZDCurrentTimestep, sizeof(real)*actuatorFarm->getNumberOfNodes(), cudaMemcpyDeviceToHost) ); } -void CudaMemoryManager::cudaFreeBladeForces(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaFreeBladeForces(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaFree(actuatorLine->bladeForcesXD) ); - checkCudaErrors( cudaFree(actuatorLine->bladeForcesYD) ); - checkCudaErrors( cudaFree(actuatorLine->bladeForcesZD) ); + checkCudaErrors( cudaFree(actuatorFarm->bladeForcesXDCurrentTimestep) ); + checkCudaErrors( cudaFree(actuatorFarm->bladeForcesYDCurrentTimestep) ); + checkCudaErrors( cudaFree(actuatorFarm->bladeForcesZDCurrentTimestep) ); + + checkCudaErrors( cudaFree(actuatorFarm->bladeForcesXDPreviousTimestep) ); + checkCudaErrors( cudaFree(actuatorFarm->bladeForcesYDPreviousTimestep) ); + checkCudaErrors( cudaFree(actuatorFarm->bladeForcesZDPreviousTimestep) ); - checkCudaErrors( cudaFreeHost(actuatorLine->bladeForcesXH) ); - checkCudaErrors( cudaFreeHost(actuatorLine->bladeForcesYH) ); - checkCudaErrors( cudaFreeHost(actuatorLine->bladeForcesZH) ); + checkCudaErrors( cudaFreeHost(actuatorFarm->bladeForcesXH) ); + checkCudaErrors( cudaFreeHost(actuatorFarm->bladeForcesYH) ); + checkCudaErrors( cudaFreeHost(actuatorFarm->bladeForcesZH) ); } -void CudaMemoryManager::cudaAllocSphereIndices(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaAllocSphereIndices(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaMallocHost((void**) &(actuatorLine->boundingSphereIndicesH), sizeof(int)*actuatorLine->getNIndices())); - checkCudaErrors( cudaMalloc((void**) &(actuatorLine->boundingSphereIndicesD), sizeof(int)*actuatorLine->getNIndices())); - setMemsizeGPU(sizeof(int)*actuatorLine->getNIndices(), false); + checkCudaErrors( cudaMallocHost((void**) &(actuatorFarm->boundingSphereIndicesH), sizeof(int)*actuatorFarm->getNumberOfIndices())); + checkCudaErrors( cudaMalloc((void**) &(actuatorFarm->boundingSphereIndicesD), sizeof(int)*actuatorFarm->getNumberOfIndices())); + setMemsizeGPU(sizeof(int)*actuatorFarm->getNumberOfIndices(), false); } -void CudaMemoryManager::cudaCopySphereIndicesHtoD(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaCopySphereIndicesHtoD(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaMemcpy(actuatorLine->boundingSphereIndicesD, actuatorLine->boundingSphereIndicesH, sizeof(int)*actuatorLine->getNIndices(), cudaMemcpyHostToDevice) ); + checkCudaErrors( cudaMemcpy(actuatorFarm->boundingSphereIndicesD, actuatorFarm->boundingSphereIndicesH, sizeof(int)*actuatorFarm->getNumberOfIndices(), cudaMemcpyHostToDevice) ); } -void CudaMemoryManager::cudaFreeSphereIndices(ActuatorLine* actuatorLine) +void CudaMemoryManager::cudaFreeSphereIndices(ActuatorFarm* actuatorFarm) { - checkCudaErrors( cudaFreeHost(actuatorLine->boundingSphereIndicesH) ); - checkCudaErrors( cudaFree(actuatorLine->boundingSphereIndicesD) ); + checkCudaErrors( cudaFreeHost(actuatorFarm->boundingSphereIndicesH) ); + checkCudaErrors( cudaFree(actuatorFarm->boundingSphereIndicesD) ); } //////////////////////////////////////////////////////////////////////////////////// @@ -3231,8 +3426,11 @@ void CudaMemoryManager::cudaCopyProbeQuantityArrayHtoD(Probe* probe, int level) } void CudaMemoryManager::cudaCopyProbeQuantityArrayDtoH(Probe* probe, int level) { - checkCudaErrors( cudaMemcpy(probe->getProbeStruct(level)->quantitiesArrayH, probe->getProbeStruct(level)->quantitiesArrayD, probe->getProbeStruct(level)->nArrays*sizeof(real)*probe->getProbeStruct(level)->nPoints, cudaMemcpyDeviceToHost) ); + auto probeStruct = probe->getProbeStruct(level); + + checkCudaErrors( cudaMemcpy(probeStruct->quantitiesArrayH, probeStruct->quantitiesArrayD, probeStruct->nArrays*sizeof(real)*probeStruct->nPoints, cudaMemcpyDeviceToHost) ); } + void CudaMemoryManager::cudaFreeProbeQuantityArray(Probe* probe, int level) { checkCudaErrors( cudaFreeHost(probe->getProbeStruct(level)->quantitiesArrayH) ); @@ -3262,6 +3460,7 @@ void CudaMemoryManager::cudaCopyProbeQuantitiesAndOffsetsDtoH(Probe* probe, int checkCudaErrors( cudaMemcpy(probe->getProbeStruct(level)->quantitiesH, probe->getProbeStruct(level)->quantitiesD, int(Statistic::LAST)*sizeof(bool), cudaMemcpyDeviceToHost) ); checkCudaErrors( cudaMemcpy(probe->getProbeStruct(level)->arrayOffsetsH, probe->getProbeStruct(level)->arrayOffsetsD, int(Statistic::LAST)*sizeof(int), cudaMemcpyDeviceToHost) ); } + void CudaMemoryManager::cudaFreeProbeQuantitiesAndOffsets(Probe* probe, int level) { checkCudaErrors( cudaFreeHost(probe->getProbeStruct(level)->quantitiesH) ); @@ -3270,23 +3469,51 @@ void CudaMemoryManager::cudaFreeProbeQuantitiesAndOffsets(Probe* probe, int leve checkCudaErrors( cudaFree (probe->getProbeStruct(level)->arrayOffsetsD) ); } +void CudaMemoryManager::cudaAllocPrecursorWriter(PrecursorWriter* writer, int level) +{ + auto prec = writer->getPrecursorStruct(level); + size_t indSize = prec->numberOfPointsInBC*sizeof(uint); + checkCudaErrors( cudaStreamCreate(&prec->stream) ); + checkCudaErrors( cudaMallocHost((void**) &prec->indicesH, indSize)); + checkCudaErrors( cudaMalloc((void**) &prec->indicesD, indSize)); + size_t dataSize = prec->numberOfPointsInBC*sizeof(real)*prec->numberOfQuantities; + size_t dataSizeH = dataSize * prec->numberOfTimestepsPerFile; + + checkCudaErrors( cudaMallocHost((void**) &prec->dataH, dataSizeH)); + checkCudaErrors( cudaMallocHost((void**) &prec->bufferH, dataSizeH)); + checkCudaErrors( cudaMalloc((void**) &prec->dataD, dataSize)); + checkCudaErrors( cudaMalloc((void**) &prec->bufferD, dataSize)); + setMemsizeGPU(indSize+2*dataSize, false); +} +void CudaMemoryManager::cudaCopyPrecursorWriterIndicesHtoD(PrecursorWriter* writer, int level) +{ + checkCudaErrors( cudaMemcpy(writer->getPrecursorStruct(level)->indicesD, writer->getPrecursorStruct(level)->indicesH, writer->getPrecursorStruct(level)->numberOfPointsInBC*sizeof(uint), cudaMemcpyHostToDevice) ); +} +void CudaMemoryManager::cudaCopyPrecursorWriterOutputVariablesDtoH(PrecursorWriter* writer, int level) +{ + auto prec = writer->getPrecursorStruct(level); + int sizeTimestep = prec->numberOfPointsInBC*prec->numberOfQuantities; + checkCudaErrors( cudaStreamSynchronize(prec->stream) ); + checkCudaErrors( cudaMemcpyAsync( &prec->bufferH[prec->numberOfTimestepsBuffered*sizeTimestep], prec->bufferD, sizeof(real)*sizeTimestep, cudaMemcpyDeviceToHost, prec->stream)); +} +void CudaMemoryManager::cudaFreePrecursorWriter(PrecursorWriter* writer, int level) +{ + checkCudaErrors( cudaFreeHost(writer->getPrecursorStruct(level)->indicesH)); + checkCudaErrors( cudaFree(writer->getPrecursorStruct(level)->indicesD)); - - - - - - - - + checkCudaErrors( cudaFreeHost(writer->getPrecursorStruct(level)->dataH)); + checkCudaErrors( cudaFreeHost(writer->getPrecursorStruct(level)->bufferH)); + checkCudaErrors( cudaFree(writer->getPrecursorStruct(level)->dataD)); + checkCudaErrors( cudaFree(writer->getPrecursorStruct(level)->bufferD)); +} CudaMemoryManager::CudaMemoryManager(std::shared_ptr<Parameter> parameter) : parameter(parameter) diff --git a/src/gpu/VirtualFluids_GPU/GPU/CudaMemoryManager.h b/src/gpu/VirtualFluids_GPU/GPU/CudaMemoryManager.h index d410340d2de7797cf23a781a64d11f592d62a6fb..67347d005b1abb6ae6b6badf8f187a11b2bde15a 100644 --- a/src/gpu/VirtualFluids_GPU/GPU/CudaMemoryManager.h +++ b/src/gpu/VirtualFluids_GPU/GPU/CudaMemoryManager.h @@ -18,8 +18,10 @@ class Parameter; class PorousMedia; -class ActuatorLine; +class ActuatorFarm; class Probe; +class VelocitySetter; +class PrecursorWriter; class VIRTUALFLUIDS_GPU_EXPORT CudaMemoryManager { @@ -92,26 +94,20 @@ public: ////////////////////////////////////////////////////////////////////////// //3D domain decomposition virtual void cudaAllocProcessNeighborX(int lev, unsigned int processNeighbor); - void cudaCopyProcessNeighborXFsHD(int lev, unsigned int processNeighbor, const unsigned int &memsizeFsRecv, - int streamIndex); - void cudaCopyProcessNeighborXFsDH(int lev, unsigned int processNeighbor, const unsigned int &memsizeFsSend, - int streamIndex); + void cudaCopyProcessNeighborXFsHD(int lev, unsigned int processNeighbor, const unsigned int &memsizeFsRecv); + void cudaCopyProcessNeighborXFsDH(int lev, unsigned int processNeighbor, const unsigned int &memsizeFsSend); virtual void cudaCopyProcessNeighborXIndex(int lev, unsigned int processNeighbor); void cudaFreeProcessNeighborX(int lev, unsigned int processNeighbor); // virtual void cudaAllocProcessNeighborY(int lev, unsigned int processNeighbor); - void cudaCopyProcessNeighborYFsHD(int lev, unsigned int processNeighbor, const unsigned int &memsizeFsRecv, - int streamIndex); - void cudaCopyProcessNeighborYFsDH(int lev, unsigned int processNeighbor, const unsigned int &memsizeFsSend, - int streamIndex); + void cudaCopyProcessNeighborYFsHD(int lev, unsigned int processNeighbor, const unsigned int &memsizeFsRecv); + void cudaCopyProcessNeighborYFsDH(int lev, unsigned int processNeighbor, const unsigned int &memsizeFsSend); virtual void cudaCopyProcessNeighborYIndex(int lev, unsigned int processNeighbor); void cudaFreeProcessNeighborY(int lev, unsigned int processNeighbor); // virtual void cudaAllocProcessNeighborZ(int lev, unsigned int processNeighbor); - void cudaCopyProcessNeighborZFsHD(int lev, unsigned int processNeighbor, const unsigned int &memsizeFsRecv, - int streamIndex); - void cudaCopyProcessNeighborZFsDH(int lev, unsigned int processNeighbor, const unsigned int &memsizeFsSend, - int streamIndex); + void cudaCopyProcessNeighborZFsHD(int lev, unsigned int processNeighbor, const unsigned int &memsizeFsRecv); + void cudaCopyProcessNeighborZFsDH(int lev, unsigned int processNeighbor, const unsigned int &memsizeFsSend); virtual void cudaCopyProcessNeighborZIndex(int lev, unsigned int processNeighbor); void cudaFreeProcessNeighborZ(int lev, unsigned int processNeighbor); @@ -183,6 +179,13 @@ public: void cudaCopyStressBC(int lev); void cudaFreeStressBC(int lev); + void cudaAllocPrecursorBC(int lev); + void cudaAllocPrecursorData(int lev); + void cudaCopyPrecursorBC(int lev); + void cudaCopyPrecursorData(int lev); + void cudaFreePrecursorBC(int lev); + void cudaFreePrecursorData(int lev); + void cudaAllocWallModel(int lev, bool hasWallModelMonitor); void cudaCopyWallModel(int lev, bool hasWallModelMonitor); void cudaFreeWallModel(int lev, bool hasWallModelMonitor); @@ -346,42 +349,44 @@ public: void cudaCopyProcessNeighborADZIndex(int lev, unsigned int processNeighbor); void cudaFreeProcessNeighborADZ(int lev, unsigned int processNeighbor); - void cudaAllocFluidNodeIndices(int lev); - void cudaCopyFluidNodeIndices(int lev); - void cudaFreeFluidNodeIndices(int lev); - void cudaAllocFluidNodeIndicesBorder(int lev); - void cudaCopyFluidNodeIndicesBorder(int lev); - void cudaFreeFluidNodeIndicesBorder(int lev); - - // Actuator Line - void cudaAllocBladeRadii(ActuatorLine* actuatorLine); - void cudaCopyBladeRadiiHtoD(ActuatorLine* actuatorLine); - void cudaCopyBladeRadiiDtoH(ActuatorLine* actuatorLine); - void cudaFreeBladeRadii(ActuatorLine* actuatorLine); - - void cudaAllocBladeCoords(ActuatorLine* actuatorLine); - void cudaCopyBladeCoordsHtoD(ActuatorLine* actuatorLine); - void cudaCopyBladeCoordsDtoH(ActuatorLine* actuatorLine); - void cudaFreeBladeCoords(ActuatorLine* actuatorLine); - - void cudaAllocBladeIndices(ActuatorLine* actuatorLine); - void cudaCopyBladeIndicesHtoD(ActuatorLine* actuatorLine); - void cudaFreeBladeIndices(ActuatorLine* actuatorLine); - - void cudaAllocBladeVelocities(ActuatorLine* actuatorLine); - void cudaCopyBladeVelocitiesHtoD(ActuatorLine* actuatorLine); - void cudaCopyBladeVelocitiesDtoH(ActuatorLine* actuatorLine); - void cudaFreeBladeVelocities(ActuatorLine* actuatorLine); - - void cudaAllocBladeForces(ActuatorLine* actuatorLine); - void cudaCopyBladeForcesHtoD(ActuatorLine* actuatorLine); - void cudaCopyBladeForcesDtoH(ActuatorLine* actuatorLine); - void cudaFreeBladeForces(ActuatorLine* actuatorLine); - - void cudaAllocSphereIndices(ActuatorLine* actuatorLine); - void cudaCopySphereIndicesHtoD(ActuatorLine* actuatorLine); - void cudaFreeSphereIndices(ActuatorLine* actuatorLine); - + void cudaAllocTaggedFluidNodeIndices(CollisionTemplate tag, int lev); + void cudaCopyTaggedFluidNodeIndices(CollisionTemplate tag, int lev); + void cudaFreeTaggedFluidNodeIndices(CollisionTemplate tag, int lev); + + // ActuatorFarm + void cudaAllocBladeGeometries(ActuatorFarm* actuatorFarm); + void cudaCopyBladeGeometriesHtoD(ActuatorFarm* actuatorFarm); + void cudaCopyBladeGeometriesDtoH(ActuatorFarm* actuatorFarm); + void cudaFreeBladeGeometries(ActuatorFarm* actuatorFarm); + + void cudaAllocBladeOrientations(ActuatorFarm* actuatorFarm); + void cudaCopyBladeOrientationsHtoD(ActuatorFarm* actuatorFarm); + void cudaCopyBladeOrientationsDtoH(ActuatorFarm* actuatorFarm); + void cudaFreeBladeOrientations(ActuatorFarm* actuatorFarm); + + void cudaAllocBladeCoords(ActuatorFarm* actuatorFarm); + void cudaCopyBladeCoordsHtoD(ActuatorFarm* actuatorFarm); + void cudaCopyBladeCoordsDtoH(ActuatorFarm* actuatorFarm); + void cudaFreeBladeCoords(ActuatorFarm* actuatorFarm); + + void cudaAllocBladeIndices(ActuatorFarm* actuatorFarm); + void cudaCopyBladeIndicesHtoD(ActuatorFarm* actuatorFarm); + void cudaFreeBladeIndices(ActuatorFarm* actuatorFarm); + + void cudaAllocBladeVelocities(ActuatorFarm* actuatorFarm); + void cudaCopyBladeVelocitiesHtoD(ActuatorFarm* actuatorFarm); + void cudaCopyBladeVelocitiesDtoH(ActuatorFarm* actuatorFarm); + void cudaFreeBladeVelocities(ActuatorFarm* actuatorFarm); + + void cudaAllocBladeForces(ActuatorFarm* actuatorFarm); + void cudaCopyBladeForcesHtoD(ActuatorFarm* actuatorFarm); + void cudaCopyBladeForcesDtoH(ActuatorFarm* actuatorFarm); + void cudaFreeBladeForces(ActuatorFarm* actuatorFarm); + + void cudaAllocSphereIndices(ActuatorFarm* actuatorFarm); + void cudaCopySphereIndicesHtoD(ActuatorFarm* actuatorFarm); + void cudaFreeSphereIndices(ActuatorFarm* actuatorFarm); + // Probes void cudaAllocProbeDistances(Probe* probe, int level); void cudaCopyProbeDistancesHtoD(Probe* probe, int level); void cudaCopyProbeDistancesDtoH(Probe* probe, int level); @@ -402,6 +407,12 @@ public: void cudaCopyProbeQuantitiesAndOffsetsDtoH(Probe* probe, int level); void cudaFreeProbeQuantitiesAndOffsets(Probe* probe, int level); + //Precursor Writer + void cudaAllocPrecursorWriter(PrecursorWriter* writer, int level); + void cudaCopyPrecursorWriterIndicesHtoD(PrecursorWriter* writer, int level); + void cudaCopyPrecursorWriterOutputVariablesDtoH(PrecursorWriter* writer, int level); + void cudaFreePrecursorWriter(PrecursorWriter* writer, int level); + private: std::shared_ptr<Parameter> parameter; double memsizeGPU = 0.0; diff --git a/src/gpu/VirtualFluids_GPU/GPU/GPU_Interface.h b/src/gpu/VirtualFluids_GPU/GPU/GPU_Interface.h index ee987ae23402ef304220349db77084cc341ccd5a..ceb70fb123c52c282200137a00522ff2b9905f86 100644 --- a/src/gpu/VirtualFluids_GPU/GPU/GPU_Interface.h +++ b/src/gpu/VirtualFluids_GPU/GPU/GPU_Interface.h @@ -900,6 +900,8 @@ void QPressDevDirDepBot27(unsigned int numberOfThreads, void QPressNoRhoDev27(LBMSimulationParameter* parameterDevice, QforBoundaryConditions* boundaryCondition); +void QPressZeroRhoOutflowDev27(LBMSimulationParameter* parameterDevice, QforBoundaryConditions* boundaryCondition); + void QInflowScaleByPressDev27(LBMSimulationParameter* parameterDevice, QforBoundaryConditions* boundaryCondition); void QPressDevOld27(unsigned int numberOfThreads, @@ -1007,6 +1009,14 @@ void VelSchlaffer27( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep); +void QPrecursorDevCompZeroPress(LBMSimulationParameter* parameterDevice, QforPrecursorBoundaryConditions* boundaryCondition, real tRatio, real velocityRatio); + +void PrecursorDevEQ27(LBMSimulationParameter* parameterDevice, QforPrecursorBoundaryConditions* boundaryCondition, real tRatio, real velocityRatio); + +void PrecursorDevDistributions(LBMSimulationParameter* parameterDevice, QforPrecursorBoundaryConditions* boundaryCondition, real tRatio, real velocityRatio); + +void QPrecursorDevDistributions(LBMSimulationParameter* parameterDevice, QforPrecursorBoundaryConditions* boundaryCondition, real tRatio, real velocityRatio); + void QADDev7(unsigned int numberOfThreads, real* DD, real* DD7, diff --git a/src/gpu/VirtualFluids_GPU/GPU/GPU_Kernels.cuh b/src/gpu/VirtualFluids_GPU/GPU/GPU_Kernels.cuh index 94b9704b7ca57df4cd985f5aff9521b8a087b97f..a7b22c244da368b9591c5f528bb7bd5eaea91e50 100644 --- a/src/gpu/VirtualFluids_GPU/GPU/GPU_Kernels.cuh +++ b/src/gpu/VirtualFluids_GPU/GPU/GPU_Kernels.cuh @@ -1080,7 +1080,7 @@ __global__ void QPressDeviceDirDepBot27( real* rhoBC, bool isEvenTimestep); __global__ void QPressNoRhoDevice27( real* rhoBC, - real* DD, + real* distributions, int* k_Q, int* k_N, int numberOfBCnodes, @@ -1088,8 +1088,23 @@ __global__ void QPressNoRhoDevice27( real* rhoBC, unsigned int* neighborX, unsigned int* neighborY, unsigned int* neighborZ, - unsigned int size_Mat, - bool isEvenTimestep); + unsigned int numberOfLBnodes, + bool isEvenTimestep, + int direction); + +__global__ void QPressZeroRhoOutflowDevice27( real* rhoBC, + real* distributions, + int* k_Q, + int* k_N, + int numberOfBCnodes, + real om1, + unsigned int* neighborX, + unsigned int* neighborY, + unsigned int* neighborZ, + unsigned int numberOfLBnodes, + bool isEvenTimestep, + int direction, + real densityCorrectionFactor); __global__ void QInflowScaleByPressDevice27( real* rhoBC, real* DD, @@ -1228,6 +1243,103 @@ __global__ void VelSchlaff27( int t, unsigned int size_Mat, bool isEvenTimestep); +__global__ void QPrecursorDeviceCompZeroPress( int* subgridDistanceIndices, + int numberOfBCnodes, + int numberOfPrecursorNodes, + int sizeQ, + real omega, + real* distributions, + real* subgridDistances, + uint* neighborX, + uint* neighborY, + uint* neighborZ, + uint* neighborsNT, + uint* neighborsNB, + uint* neighborsST, + uint* neighborsSB, + real* weights0PP, + real* weights0PM, + real* weights0MP, + real* weights0MM, + real* vLast, + real* vCurrent, + real velocityX, + real velocityY, + real velocityZ, + real timeRatio, + real velocityRatio, + unsigned long long numberOfLBnodes, + bool isEvenTimestep); + +__global__ void PrecursorDeviceEQ27( int* subgridDistanceIndices, + int numberOfBCnodes, + int numberOfPrecursorNodes, + real omega, + real* distributions, + uint* neighborX, + uint* neighborY, + uint* neighborZ, + uint* neighborsNT, + uint* neighborsNB, + uint* neighborsST, + uint* neighborsSB, + real* weights0PP, + real* weights0PM, + real* weights0MP, + real* weights0MM, + real* vLast, + real* vCurrent, + real velocityX, + real velocityY, + real velocityZ, + real timeRatio, + real velocityRatio, + unsigned long long numberOfLBnodes, + bool isEvenTimestep); + +__global__ void PrecursorDeviceDistributions( int* subgridDistanceIndices, + int numberOfBCNodes, + int numberOfPrecursorNodes, + real* distributions, + uint* neighborX, + uint* neighborY, + uint* neighborZ, + uint* neighborsNT, + uint* neighborsNB, + uint* neighborsST, + uint* neighborsSB, + real* weights0PP, + real* weights0PM, + real* weights0MP, + real* weights0MM, + real* fsLast, + real* fsNext, + real timeRatio, + unsigned long long numberOfLBnodes, + bool isEvenTimestep); +__global__ void QPrecursorDeviceDistributions( int* subgridDistanceIndices, + real* subgridDistances, + int sizeQ, + int numberOfBCNodes, + int numberOfPrecursorNodes, + real* distributions, + uint* neighborX, + uint* neighborY, + uint* neighborZ, + uint* neighborsNT, + uint* neighborsNB, + uint* neighborsST, + uint* neighborsSB, + real* weights0PP, + real* weights0PM, + real* weights0MP, + real* weights0MM, + real* fsLast, + real* fsNext, + real timeRatio, + unsigned long long numberOfLBnodes, + bool isEvenTimestep); + //Advection / Diffusion BCs __global__ void QAD7( real* DD, real* DD7, diff --git a/src/gpu/VirtualFluids_GPU/GPU/LBMKernel.cu b/src/gpu/VirtualFluids_GPU/GPU/LBMKernel.cu index 63fc5be0ebe5d4a26d4662ee8c0dddbc3098247a..363fb76626b256205346a290a42a1da40e1c7445 100644 --- a/src/gpu/VirtualFluids_GPU/GPU/LBMKernel.cu +++ b/src/gpu/VirtualFluids_GPU/GPU/LBMKernel.cu @@ -54,22 +54,9 @@ void KernelCasSP27( unsigned int numberOfThreads, int size_Mat, bool EvenOrOdd) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LB_Kernel_Casc_SP_27<<< grid, threads >>>(s9, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LB_Kernel_Casc_SP_27<<< grid.grid, grid.threads >>>(s9, bcMatD, neighborX, neighborY, @@ -90,22 +77,9 @@ void KernelCasSPMS27( unsigned int numberOfThreads, int size_Mat, bool EvenOrOdd) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LB_Kernel_Casc_SP_MS_27<<< grid, threads >>>(s9, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LB_Kernel_Casc_SP_MS_27<<< grid.grid, grid.threads >>>(s9, bcMatD, neighborX, neighborY, @@ -126,22 +100,9 @@ void KernelCasSPMSOHM27( unsigned int numberOfThreads, int size_Mat, bool EvenOrOdd) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LB_Kernel_Casc_SP_MS_OHM_27<<< grid, threads >>>( s9, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LB_Kernel_Casc_SP_MS_OHM_27<<< grid.grid, grid.threads >>>( s9, bcMatD, neighborX, neighborY, @@ -165,22 +126,9 @@ void KernelKumCompSRTSP27( real* forces, bool EvenOrOdd) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LB_Kernel_Kum_New_Comp_SRT_SP_27 <<< grid, threads >>>( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LB_Kernel_Kum_New_Comp_SRT_SP_27 <<< grid.grid, grid.threads >>>( omega, bcMatD, neighborX, @@ -209,22 +157,9 @@ void KernelKum1hSP27( unsigned int numberOfThreads, int size_Mat, bool EvenOrOdd) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LB_Kernel_Kum_1h_SP_27<<< grid, threads >>>(omega, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LB_Kernel_Kum_1h_SP_27<<< grid.grid, grid.threads >>>(omega, deltaPhi, angularVelocity, bcMatD, @@ -250,22 +185,9 @@ void KernelCascadeSP27( unsigned int numberOfThreads, int size_Mat, bool EvenOrOdd) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LB_Kernel_Cascade_SP_27<<< grid, threads >>>(s9, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LB_Kernel_Cascade_SP_27<<< grid.grid, grid.threads >>>(s9, bcMatD, neighborX, neighborY, @@ -286,22 +208,10 @@ void KernelKumNewSP27( unsigned int numberOfThreads, int size_Mat, bool EvenOrOdd) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LB_Kernel_Kum_New_SP_27<<< grid, threads >>>(s9, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + + LB_Kernel_Kum_New_SP_27<<< grid.grid, grid.threads >>>(s9, bcMatD, neighborX, neighborY, @@ -329,22 +239,9 @@ void KernelKumNewCompSP27(unsigned int numberOfThreads, //dim3 grid(Grid, 1, 1); //dim3 threads(numberOfThreads, 1, 1 ); - int Grid = (size_Mat / numberOfThreads) + 1; - int Grid1, Grid2; - if (Grid > 512) - { - Grid1 = 512; - Grid2 = (Grid / Grid1) + 1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2, 1); - dim3 threads(numberOfThreads, 1, 1); - - //LB_Kernel_Kum_New_Comp_SP_27<<< grid, threads >>>( s9, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + //LB_Kernel_Kum_New_Comp_SP_27<<< grid.grid, grid.threads >>>( s9, // bcMatD, // neighborX, // neighborY, @@ -375,22 +272,10 @@ void CumulantOnePreconditionedErrorDiffusionChimCompSP27(unsigned int numberOfTh //dim3 grid(Grid, 1, 1); //dim3 threads(numberOfThreads, 1, 1 ); - int Grid = (size_Mat / numberOfThreads) + 1; - int Grid1, Grid2; - if (Grid > 512) - { - Grid1 = 512; - Grid2 = (Grid / Grid1) + 1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2, 1); - dim3 threads(numberOfThreads, 1, 1); - - Cumulant_One_preconditioned_errorDiffusion_chim_Comp_SP_27 <<< grid, threads >>>( s9, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + + Cumulant_One_preconditioned_errorDiffusion_chim_Comp_SP_27 <<< grid.grid, grid.threads >>>( s9, bcMatD, neighborX, neighborY, @@ -420,22 +305,10 @@ void CumulantOnePreconditionedChimCompSP27( unsigned int numberOfThreads, //dim3 grid(Grid, 1, 1); //dim3 threads(numberOfThreads, 1, 1 ); - int Grid = (size_Mat / numberOfThreads) + 1; - int Grid1, Grid2; - if (Grid > 512) - { - Grid1 = 512; - Grid2 = (Grid / Grid1) + 1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2, 1); - dim3 threads(numberOfThreads, 1, 1); - - Cumulant_One_preconditioned_chim_Comp_SP_27 <<< grid, threads >>>( s9, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + + Cumulant_One_preconditioned_chim_Comp_SP_27 <<< grid.grid, grid.threads >>>( s9, bcMatD, neighborX, neighborY, @@ -465,22 +338,10 @@ void CumulantOneChimCompSP27(unsigned int numberOfThreads, //dim3 grid(Grid, 1, 1); //dim3 threads(numberOfThreads, 1, 1 ); - int Grid = (size_Mat / numberOfThreads) + 1; - int Grid1, Grid2; - if (Grid > 512) - { - Grid1 = 512; - Grid2 = (Grid / Grid1) + 1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2, 1); - dim3 threads(numberOfThreads, 1, 1); - - Cumulant_One_chim_Comp_SP_27 <<< grid, threads >>>( s9, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + + Cumulant_One_chim_Comp_SP_27 <<< grid.grid, grid.threads >>>( s9, bcMatD, neighborX, neighborY, @@ -506,22 +367,10 @@ void KernelKumIsoTestSP27(unsigned int numberOfThreads, int size_Mat, bool EvenOrOdd) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LB_Kernel_Kum_IsoTest_SP_27<<< grid, threads >>>(s9, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + + LB_Kernel_Kum_IsoTest_SP_27<<< grid.grid, grid.threads >>>(s9, bcMatD, neighborX, neighborY, @@ -545,22 +394,10 @@ void KernelKumCompSP27( unsigned int numberOfThreads, int size_Mat, bool EvenOrOdd) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LB_Kernel_Kum_Comp_SP_27<<< grid, threads >>>(s9, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + + LB_Kernel_Kum_Comp_SP_27<<< grid.grid, grid.threads >>>(s9, bcMatD, neighborX, neighborY, @@ -587,22 +424,10 @@ void KernelPMCumOneCompSP27(unsigned int numberOfThreads, unsigned int* nodeIdsPorousMedia, bool EvenOrOdd) { - int Grid = (size_Mat / numberOfThreads) + 1; - int Grid1, Grid2; - if (Grid > 512) - { - Grid1 = 512; - Grid2 = (Grid / Grid1) + 1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2, 1); - dim3 threads(numberOfThreads, 1, 1); - - LB_Kernel_PM_Cum_One_Comp_SP_27 <<< grid, threads >>>(omega, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + + LB_Kernel_PM_Cum_One_Comp_SP_27 <<< grid.grid, grid.threads >>>(omega, neighborX, neighborY, neighborZ, @@ -642,22 +467,10 @@ void KernelWaleBySoniMalavCumAA2016CompSP27( //dim3 grid(Grid, 1, 1); //dim3 threads(numberOfThreads, 1, 1 ); - int Grid = (size_Mat / numberOfThreads) + 1; - int Grid1, Grid2; - if (Grid > 512) - { - Grid1 = 512; - Grid2 = (Grid / Grid1) + 1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2, 1); - dim3 threads(numberOfThreads, 1, 1); - - LB_Kernel_WaleBySoniMalav_Cum_AA2016_Comp_SP_27 << < grid, threads >> >( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + + LB_Kernel_WaleBySoniMalav_Cum_AA2016_Comp_SP_27 << < grid.grid, grid.threads >> >( s9, bcMatD, neighborX, @@ -687,22 +500,9 @@ void KernelADincomp7( unsigned int numberOfThreads, int size_Mat, bool EvenOrOdd) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LB_Kernel_AD_Incomp_7<<< grid, threads >>>( diffusivity, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LB_Kernel_AD_Incomp_7<<< grid.grid, grid.threads >>>( diffusivity, bcMatD, neighborX, neighborY, @@ -725,22 +525,9 @@ void KernelADincomp27( unsigned int numberOfThreads, int size_Mat, bool EvenOrOdd) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LB_Kernel_AD_Incomp_27<<< grid, threads >>>( diffusivity, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LB_Kernel_AD_Incomp_27<<< grid.grid, grid.threads >>>( diffusivity, bcMatD, neighborX, neighborY, @@ -749,7 +536,7 @@ void KernelADincomp27( unsigned int numberOfThreads, DD27, size_Mat, EvenOrOdd); - getLastCudaError("LB_Kernel_AD_Incomp_27 execution failed"); + getLastCudaError("LB_Kernel_AD_Incomp_27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void Init27( int myid, @@ -771,7 +558,7 @@ void Init27( int myid, dim3 threads ( grid_nx, 1, 1 ); dim3 grid ( grid_ny, grid_nz ); // Gitter fuer Kollision und Propagation - LBInit27<<< grid, threads >>> ( myid, + LBInit27<<< grid, threads >>> ( myid, numprocs, u0, geoD, @@ -786,7 +573,7 @@ void Init27( int myid, DD, level, maxlevel); - getLastCudaError("LBInit27 execution failed"); + getLastCudaError("LBInit27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void InitNonEqPartSP27( unsigned int numberOfThreads, @@ -804,22 +591,9 @@ void InitNonEqPartSP27( unsigned int numberOfThreads, real omega, bool EvenOrOdd) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LBInitNonEqPartSP27<<< grid, threads >>>( neighborX, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LBInitNonEqPartSP27<<< grid.grid, grid.threads >>>( neighborX, neighborY, neighborZ, neighborWSB, @@ -832,7 +606,7 @@ void InitNonEqPartSP27( unsigned int numberOfThreads, DD, omega, EvenOrOdd); - getLastCudaError("LBInitNonEqPartSP27 execution failed"); + getLastCudaError("LBInitNonEqPartSP27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void InitThS7( unsigned int numberOfThreads, @@ -848,22 +622,9 @@ void InitThS7( unsigned int numberOfThreads, real* DD7, bool EvenOrOdd) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - InitAD7<<< grid, threads >>>( neighborX, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + InitAD7<<< grid.grid, grid.threads >>>( neighborX, neighborY, neighborZ, geoD, @@ -874,7 +635,7 @@ void InitThS7( unsigned int numberOfThreads, size_Mat, DD7, EvenOrOdd); - getLastCudaError("InitAD7 execution failed"); + getLastCudaError("InitAD7 execution failed"); } ////////////////////////////////////////////////////////////////////////// void InitADDev27( unsigned int numberOfThreads, @@ -890,22 +651,9 @@ void InitADDev27( unsigned int numberOfThreads, real* DD27, bool EvenOrOdd) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - InitAD27<<< grid, threads >>>(neighborX, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + InitAD27<<< grid.grid, grid.threads >>>(neighborX, neighborY, neighborZ, geoD, @@ -916,7 +664,7 @@ void InitADDev27( unsigned int numberOfThreads, size_Mat, DD27, EvenOrOdd); - getLastCudaError("InitAD27 execution failed"); + getLastCudaError("InitAD27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void PostProcessorF3_2018Fehlberg( @@ -937,22 +685,9 @@ void PostProcessorF3_2018Fehlberg( real* forces, bool EvenOrOdd) { - int Grid = (size_Mat / numberOfThreads) + 1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid / Grid1) + 1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1); - - LB_PostProcessor_F3_2018_Fehlberg <<< grid, threads >>> ( omega, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LB_PostProcessor_F3_2018_Fehlberg <<< grid.grid, grid.threads >>> ( omega, bcMatD, neighborX, neighborY, @@ -967,7 +702,7 @@ void PostProcessorF3_2018Fehlberg( level, forces, EvenOrOdd); - getLastCudaError("LB_PostProcessor_F3_2018_Fehlberg execution failed"); + getLastCudaError("LB_PostProcessor_F3_2018_Fehlberg execution failed"); } ////////////////////////////////////////////////////////////////////////// void CalcMac27( real* vxD, @@ -988,7 +723,7 @@ void CalcMac27( real* vxD, dim3 threads ( grid_nx, 1, 1 ); dim3 grid ( grid_ny, grid_nz ); - LBCalcMac27<<< grid, threads >>> ( vxD, + LBCalcMac27<<< grid, threads >>> ( vxD, vyD, vzD, rhoD, @@ -999,7 +734,7 @@ void CalcMac27( real* vxD, size_Mat, DD, isEvenTimestep); - getLastCudaError("LBCalcMac27 execution failed"); + getLastCudaError("LBCalcMac27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void CalcMacSP27( real* vxD, @@ -1016,22 +751,9 @@ void CalcMacSP27( real* vxD, real* DD, bool isEvenTimestep) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LBCalcMacSP27<<< grid, threads >>> ( vxD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LBCalcMacSP27<<< grid.grid, grid.threads >>> ( vxD, vyD, vzD, rhoD, @@ -1043,7 +765,7 @@ void CalcMacSP27( real* vxD, size_Mat, DD, isEvenTimestep); - getLastCudaError("LBCalcMacSP27 execution failed"); + getLastCudaError("LBCalcMacSP27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void CalcMacCompSP27( real* vxD, @@ -1060,22 +782,9 @@ void CalcMacCompSP27( real* vxD, real* DD, bool isEvenTimestep) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LBCalcMacCompSP27<<< grid, threads >>> ( vxD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LBCalcMacCompSP27<<< grid.grid, grid.threads >>> ( vxD, vyD, vzD, rhoD, @@ -1087,7 +796,7 @@ void CalcMacCompSP27( real* vxD, size_Mat, DD, isEvenTimestep); - getLastCudaError("LBCalcMacSP27 execution failed"); + getLastCudaError("LBCalcMacSP27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void CalcMacThS7( real* Conc, @@ -1100,22 +809,9 @@ void CalcMacThS7( real* Conc, real* DD7, bool isEvenTimestep) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - CalcConc7<<< grid, threads >>> (Conc, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + CalcConc7<<< grid.grid, grid.threads >>> (Conc, geoD, neighborX, neighborY, @@ -1123,7 +819,7 @@ void CalcMacThS7( real* Conc, size_Mat, DD7, isEvenTimestep); - getLastCudaError("CalcConc7 execution failed"); + getLastCudaError("CalcConc7 execution failed"); } ////////////////////////////////////////////////////////////////////////// void PlaneConcThS7(real* Conc, @@ -1138,22 +834,9 @@ void PlaneConcThS7(real* Conc, real* DD7, bool isEvenTimestep) { - int Grid = (numberOfPointskPC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - GetPlaneConc7<<< grid, threads >>> ( Conc, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfPointskPC); + + GetPlaneConc7<<< grid.grid, grid.threads >>> ( Conc, kPC, numberOfPointskPC, geoD, @@ -1163,7 +846,7 @@ void PlaneConcThS7(real* Conc, size_Mat, DD7, isEvenTimestep); - getLastCudaError("GetPlaneConc7 execution failed"); + getLastCudaError("GetPlaneConc7 execution failed"); } ////////////////////////////////////////////////////////////////////////// void PlaneConcThS27(real* Conc, @@ -1178,22 +861,9 @@ void PlaneConcThS27(real* Conc, real* DD27, bool isEvenTimestep) { - int Grid = (numberOfPointskPC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - GetPlaneConc27<<< grid, threads >>> ( Conc, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfPointskPC); + + GetPlaneConc27<<< grid.grid, grid.threads >>> ( Conc, kPC, numberOfPointskPC, geoD, @@ -1203,7 +873,7 @@ void PlaneConcThS27(real* Conc, size_Mat, DD27, isEvenTimestep); - getLastCudaError("GetPlaneConc27 execution failed"); + getLastCudaError("GetPlaneConc27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void CalcConcentration27( unsigned int numberOfThreads, @@ -1216,22 +886,9 @@ void CalcConcentration27( unsigned int numberOfThreads, real* DD27, bool isEvenTimestep) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - CalcConc27<<< grid, threads >>> ( Conc, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + CalcConc27<<< grid.grid, grid.threads >>> ( Conc, geoD, neighborX, neighborY, @@ -1239,7 +896,7 @@ void CalcConcentration27( unsigned int numberOfThreads, size_Mat, DD27, isEvenTimestep); - getLastCudaError("CalcConc27 execution failed"); + getLastCudaError("CalcConc27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void CalcMedSP27( real* vxD, @@ -1256,22 +913,9 @@ void CalcMedSP27( real* vxD, real* DD, bool isEvenTimestep) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LBCalcMedSP27<<< grid, threads >>> ( vxD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LBCalcMedSP27<<< grid.grid, grid.threads >>> ( vxD, vyD, vzD, rhoD, @@ -1283,7 +927,7 @@ void CalcMedSP27( real* vxD, size_Mat, DD, isEvenTimestep); - getLastCudaError("LBCalcMedSP27 execution failed"); + getLastCudaError("LBCalcMedSP27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void CalcMedCompSP27( real* vxD, @@ -1300,22 +944,9 @@ void CalcMedCompSP27( real* vxD, real* DD, bool isEvenTimestep) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LBCalcMedCompSP27<<< grid, threads >>> ( vxD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LBCalcMedCompSP27<<< grid.grid, grid.threads >>> ( vxD, vyD, vzD, rhoD, @@ -1327,7 +958,7 @@ void CalcMedCompSP27( real* vxD, size_Mat, DD, isEvenTimestep); - getLastCudaError("LBCalcMedSP27 execution failed"); + getLastCudaError("LBCalcMedSP27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void CalcMedCompAD27( @@ -1347,22 +978,9 @@ void CalcMedCompAD27( real* DD_AD, bool isEvenTimestep) { - int Grid = (size_Mat / numberOfThreads) + 1; - int Grid1, Grid2; - if (Grid > 512) - { - Grid1 = 512; - Grid2 = (Grid / Grid1) + 1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1); - - LBCalcMedCompAD27 <<< grid, threads >>> ( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LBCalcMedCompAD27 <<< grid.grid, grid.threads >>> ( vxD, vyD, vzD, @@ -1394,22 +1012,9 @@ void CalcMacMedSP27( real* vxD, unsigned int numberOfThreads, bool isEvenTimestep) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LBCalcMacMedSP27<<< grid, threads >>> ( vxD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LBCalcMacMedSP27<<< grid.grid, grid.threads >>> ( vxD, vyD, vzD, rhoD, @@ -1421,7 +1026,7 @@ void CalcMacMedSP27( real* vxD, tdiff, size_Mat, isEvenTimestep); - getLastCudaError("LBCalcMacMedSP27 execution failed"); + getLastCudaError("LBCalcMacMedSP27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void ResetMedianValuesSP27( @@ -1434,22 +1039,10 @@ void ResetMedianValuesSP27( unsigned int numberOfThreads, bool isEvenTimestep) { - int Grid = (size_Mat / numberOfThreads) + 1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid / Grid1) + 1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1); - - LBResetMedianValuesSP27 << < grid, threads >> > ( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + + LBResetMedianValuesSP27 << < grid.grid, grid.threads >> > ( vxD, vyD, vzD, @@ -1471,22 +1064,9 @@ void ResetMedianValuesAD27( unsigned int numberOfThreads, bool isEvenTimestep) { - int Grid = (size_Mat / numberOfThreads) + 1; - int Grid1, Grid2; - if (Grid > 512) - { - Grid1 = 512; - Grid2 = (Grid / Grid1) + 1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1); - - LBResetMedianValuesAD27 << < grid, threads >> > ( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LBResetMedianValuesAD27 << < grid.grid, grid.threads >> > ( vxD, vyD, vzD, @@ -1512,22 +1092,9 @@ void Calc2ndMomentsIncompSP27(real* kxyFromfcNEQ, real* DD, bool isEvenTimestep) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LBCalc2ndMomentsIncompSP27<<< grid, threads >>> ( kxyFromfcNEQ, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LBCalc2ndMomentsIncompSP27<<< grid.grid, grid.threads >>> ( kxyFromfcNEQ, kyzFromfcNEQ, kxzFromfcNEQ, kxxMyyFromfcNEQ, @@ -1539,7 +1106,7 @@ void Calc2ndMomentsIncompSP27(real* kxyFromfcNEQ, size_Mat, DD, isEvenTimestep); - getLastCudaError("LBCalc2ndMomentsIncompSP27 execution failed"); + getLastCudaError("LBCalc2ndMomentsIncompSP27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void Calc2ndMomentsCompSP27( real* kxyFromfcNEQ, @@ -1556,22 +1123,9 @@ void Calc2ndMomentsCompSP27( real* kxyFromfcNEQ, real* DD, bool isEvenTimestep) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LBCalc2ndMomentsCompSP27<<< grid, threads >>> (kxyFromfcNEQ, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LBCalc2ndMomentsCompSP27<<< grid.grid, grid.threads >>> (kxyFromfcNEQ, kyzFromfcNEQ, kxzFromfcNEQ, kxxMyyFromfcNEQ, @@ -1583,7 +1137,7 @@ void Calc2ndMomentsCompSP27( real* kxyFromfcNEQ, size_Mat, DD, isEvenTimestep); - getLastCudaError("LBCalc2ndMomentsCompSP27 execution failed"); + getLastCudaError("LBCalc2ndMomentsCompSP27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void Calc3rdMomentsIncompSP27(real* CUMbbb, @@ -1602,22 +1156,9 @@ void Calc3rdMomentsIncompSP27(real* CUMbbb, real* DD, bool isEvenTimestep) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LBCalc3rdMomentsIncompSP27<<< grid, threads >>> ( CUMbbb, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LBCalc3rdMomentsIncompSP27<<< grid.grid, grid.threads >>> ( CUMbbb, CUMabc, CUMbac, CUMbca, @@ -1631,7 +1172,7 @@ void Calc3rdMomentsIncompSP27(real* CUMbbb, DD, size_Mat, isEvenTimestep); - getLastCudaError("LBCalc3rdMomentsIncompSP27 execution failed"); + getLastCudaError("LBCalc3rdMomentsIncompSP27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void Calc3rdMomentsCompSP27( real* CUMbbb, @@ -1650,22 +1191,9 @@ void Calc3rdMomentsCompSP27( real* CUMbbb, real* DD, bool isEvenTimestep) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LBCalc3rdMomentsCompSP27<<< grid, threads >>> (CUMbbb, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LBCalc3rdMomentsCompSP27<<< grid.grid, grid.threads >>> (CUMbbb, CUMabc, CUMbac, CUMbca, @@ -1679,7 +1207,7 @@ void Calc3rdMomentsCompSP27( real* CUMbbb, DD, size_Mat, isEvenTimestep); - getLastCudaError("LBCalc3rdMomentsCompSP27 execution failed"); + getLastCudaError("LBCalc3rdMomentsCompSP27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void CalcHigherMomentsIncompSP27(real* CUMcbb, @@ -1701,22 +1229,9 @@ void CalcHigherMomentsIncompSP27(real* CUMcbb, real* DD, bool isEvenTimestep) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LBCalcHigherMomentsIncompSP27<<< grid, threads >>> (CUMcbb, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LBCalcHigherMomentsIncompSP27<<< grid.grid, grid.threads >>> (CUMcbb, CUMbcb, CUMbbc, CUMcca, @@ -1733,7 +1248,7 @@ void CalcHigherMomentsIncompSP27(real* CUMcbb, DD, size_Mat, isEvenTimestep); - getLastCudaError("LBCalcHigherMomentsIncompSP27 execution failed"); + getLastCudaError("LBCalcHigherMomentsIncompSP27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void CalcHigherMomentsCompSP27( real* CUMcbb, @@ -1755,22 +1270,9 @@ void CalcHigherMomentsCompSP27( real* CUMcbb, real* DD, bool isEvenTimestep) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LBCalcHigherMomentsCompSP27<<< grid, threads >>> ( CUMcbb, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + + LBCalcHigherMomentsCompSP27<<< grid.grid, grid.threads >>> ( CUMcbb, CUMbcb, CUMbbc, CUMcca, @@ -1787,7 +1289,7 @@ void CalcHigherMomentsCompSP27( real* CUMcbb, DD, size_Mat, isEvenTimestep); - getLastCudaError("LBCalcHigherMomentsCompSP27 execution failed"); + getLastCudaError("LBCalcHigherMomentsCompSP27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void LBCalcMeasurePoints27(real* vxMP, @@ -1807,22 +1309,9 @@ void LBCalcMeasurePoints27(real* vxMP, unsigned int numberOfThreads, bool isEvenTimestep) { - int Grid = (numberOfPointskMP / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LBCalcMeasurePoints<<< grid, threads >>> (vxMP, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfPointskMP); + + LBCalcMeasurePoints<<< grid.grid, grid.threads >>> (vxMP, vyMP, vzMP, rhoMP, @@ -1837,7 +1326,7 @@ void LBCalcMeasurePoints27(real* vxMP, size_Mat, DD, isEvenTimestep); - getLastCudaError("LBCalcMeasurePoints execution failed"); + getLastCudaError("LBCalcMeasurePoints execution failed"); } ////////////////////////////////////////////////////////////////////////// void BcPress27( int nx, @@ -1853,10 +1342,10 @@ void BcPress27( int nx, unsigned int size_Mat, bool isEvenTimestep) { - dim3 threads ( grid_nx, 1, 1 ); - dim3 grid ( grid_ny, 1 ); + dim3 threads ( grid_nx, 1, 1 ); + dim3 grid ( grid_ny, 1 ); - LB_BC_Press_East27<<< grid, threads >>> ( nx, + LB_BC_Press_East27<<< grid, threads >>> ( nx, ny, tz, bcMatD, @@ -1866,7 +1355,7 @@ void BcPress27( int nx, DD, size_Mat, isEvenTimestep); - getLastCudaError("LB_BC_Press_East27 execution failed"); + getLastCudaError("LB_BC_Press_East27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void BcVel27(int nx, @@ -1885,10 +1374,10 @@ void BcVel27(int nx, real u0x, real om) { - dim3 threads ( grid_nx, 1, 1 ); - dim3 grid ( grid_ny, 1 ); + dim3 threads ( grid_nx, 1, 1 ); + dim3 grid ( grid_ny, 1 ); - LB_BC_Vel_West_27<<< grid, threads >>> ( nx, + LB_BC_Vel_West_27<<< grid, threads >>> ( nx, ny, nz, itz, @@ -1903,7 +1392,7 @@ void BcVel27(int nx, grid_nx, grid_ny, om); - getLastCudaError("LB_BC_Vel_West_27 execution failed"); + getLastCudaError("LB_BC_Vel_West_27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void QADPressDev7( unsigned int numberOfThreads, @@ -1922,22 +1411,9 @@ void QADPressDev7( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QADPress7<<< gridQ, threads >>>( DD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QADPress7<<< grid.grid, grid.threads >>>( DD, DD7, temp, velo, @@ -1951,7 +1427,7 @@ void QADPressDev7( unsigned int numberOfThreads, neighborZ, size_Mat, isEvenTimestep); - getLastCudaError("QADPress7 execution failed"); + getLastCudaError("QADPress7 execution failed"); } ////////////////////////////////////////////////////////////////////////// void QADPressDev27(unsigned int numberOfThreads, @@ -1970,22 +1446,9 @@ void QADPressDev27(unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QADPress27<<< gridQ, threads >>>( DD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QADPress27<<< grid.grid, grid.threads >>>( DD, DD27, temp, velo, @@ -1999,7 +1462,7 @@ void QADPressDev27(unsigned int numberOfThreads, neighborZ, size_Mat, isEvenTimestep); - getLastCudaError("QADPress27 execution failed"); + getLastCudaError("QADPress27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void QADPressNEQNeighborDev27( @@ -2017,22 +1480,9 @@ void QADPressNEQNeighborDev27( ) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QADPressNEQNeighbor27<<< gridQ, threads >>>( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QADPressNEQNeighbor27<<< grid.grid, grid.threads >>>( DD, DD27, k_Q, @@ -2044,7 +1494,7 @@ void QADPressNEQNeighborDev27( size_Mat, isEvenTimestep ); - getLastCudaError("QADPressNEQNeighbor27 execution failed"); + getLastCudaError("QADPressNEQNeighbor27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void QADVelDev7(unsigned int numberOfThreads, @@ -2063,22 +1513,9 @@ void QADVelDev7(unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QADVel7<<< gridQ, threads >>> ( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QADVel7<<< grid.grid, grid.threads >>> ( DD, DD7, temp, @@ -2093,7 +1530,7 @@ void QADVelDev7(unsigned int numberOfThreads, neighborZ, size_Mat, isEvenTimestep); - getLastCudaError("QADVel7 execution failed"); + getLastCudaError("QADVel7 execution failed"); } ////////////////////////////////////////////////////////////////////////// void QADVelDev27( unsigned int numberOfThreads, @@ -2112,22 +1549,9 @@ void QADVelDev27( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QADVel27<<< gridQ, threads >>> ( DD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QADVel27<<< grid.grid, grid.threads >>> ( DD, DD27, temp, velo, @@ -2159,22 +1583,9 @@ void QADDev7(unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QAD7<<< gridQ, threads >>> ( DD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QAD7<<< grid.grid, grid.threads >>> ( DD, DD7, temp, diffusivity, @@ -2242,11 +1653,9 @@ void ADSlipVelDevComp( uint size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads) + 1; - dim3 gridQ(Grid, 1, 1); - dim3 threads(numberOfThreads, 1, 1); + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); - AD_SlipVelDeviceComp << < gridQ, threads >> > ( + AD_SlipVelDeviceComp << < grid.grid, grid.threads >> > ( normalX, normalY, normalZ, @@ -2280,22 +1689,9 @@ void QADDirichletDev27( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QADDirichlet27<<< gridQ, threads >>> ( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QADDirichlet27<<< grid.grid, grid.threads >>> ( DD, DD27, temp, @@ -2327,22 +1723,9 @@ void QADBBDev27(unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QADBB27<<< gridQ, threads >>> ( DD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QADBB27<<< grid.grid, grid.threads >>> ( DD, DD27, temp, diffusivity, @@ -2373,22 +1756,9 @@ void QNoSlipADincompDev7(unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QNoSlipADincomp7<<< gridQ, threads >>> ( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QNoSlipADincomp7<<< grid.grid, grid.threads >>> ( DD, DD7, temp, @@ -2420,22 +1790,9 @@ void QNoSlipADincompDev27( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QNoSlipADincomp27<<< gridQ, threads >>> ( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QNoSlipADincomp27<<< grid.grid, grid.threads >>> ( DD, DD27, temp, @@ -2468,24 +1825,10 @@ void QADVeloIncompDev7( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QADVeloIncomp7<<< gridQ, threads >>> ( - DD, - DD7, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QADVeloIncomp7<<< grid.grid, grid.threads >>> ( DD, + DD7, temp, velo, diffusivity, @@ -2517,22 +1860,9 @@ void QADVeloIncompDev27( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QADVeloIncomp27<<< gridQ, threads >>> ( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QADVeloIncomp27<<< grid.grid, grid.threads >>> ( DD, DD27, temp, @@ -2566,22 +1896,9 @@ void QADPressIncompDev7( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QADPressIncomp7<<< gridQ, threads >>>( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QADPressIncomp7<<< grid.grid, grid.threads >>>( DD, DD7, temp, @@ -2615,24 +1932,10 @@ void QADPressIncompDev27( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QADPressIncomp27<<< gridQ, threads >>>( - DD, - DD27, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QADPressIncomp27<<< grid.grid, grid.threads >>>(DD, + DD27, temp, velo, diffusivity, @@ -2701,22 +2004,9 @@ void QDevCompThinWalls27(unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QDeviceCompThinWallsPartOne27 <<< gridQ, threads >>> (DD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QDeviceCompThinWallsPartOne27 <<< grid.grid, grid.threads >>> (DD, k_Q, QQ, numberOfBCnodes, @@ -2728,7 +2018,7 @@ void QDevCompThinWalls27(unsigned int numberOfThreads, isEvenTimestep); getLastCudaError("QDeviceCompThinWallsPartOne27 execution failed"); - QThinWallsPartTwo27 <<< gridQ, threads >>> ( DD, + QThinWallsPartTwo27 <<< grid.grid, grid.threads >>> ( DD, k_Q, QQ, numberOfBCnodes, @@ -2774,22 +2064,9 @@ void QDevIncompHighNu27( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QDeviceIncompHighNu27<<< gridQ, threads >>> ( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QDeviceIncompHighNu27<<< grid.grid, grid.threads >>> ( DD, k_Q, QQ, @@ -2815,22 +2092,9 @@ void QDevCompHighNu27( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QDeviceCompHighNu27<<< gridQ, threads >>> ( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QDeviceCompHighNu27<<< grid.grid, grid.threads >>> ( DD, k_Q, QQ, @@ -2880,22 +2144,9 @@ void QVelDeviceCouette27(unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QVelDevCouette27<<< gridQ, threads >>> ( vx, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QVelDevCouette27<<< grid.grid, grid.threads >>> ( vx, vy, vz, DD, @@ -2933,22 +2184,9 @@ void QVelDevice1h27( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QVelDev1h27<<< gridQ, threads >>> (nx, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QVelDev1h27<<< grid.grid, grid.threads >>> (nx, ny, vx, vy, @@ -3010,22 +2248,9 @@ void QVelDevCompPlusSlip27(unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QVelDeviceCompPlusSlip27<<< gridQ, threads >>> ( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QVelDeviceCompPlusSlip27<<< grid.grid, grid.threads >>> ( vx, vy, vz, @@ -3081,22 +2306,9 @@ void QVelDevCompThinWalls27(unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QVelDeviceCompThinWallsPartOne27<<< gridQ, threads >>> (vx, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QVelDeviceCompThinWallsPartOne27<<< grid.grid, grid.threads >>> (vx, vy, vz, DD, @@ -3111,7 +2323,7 @@ void QVelDevCompThinWalls27(unsigned int numberOfThreads, isEvenTimestep); getLastCudaError("QVelDeviceCompThinWallsPartOne27 execution failed"); - QThinWallsPartTwo27 <<< gridQ, threads >>> ( + QThinWallsPartTwo27 <<< grid.grid, grid.threads >>> ( DD, k_Q, QQ, @@ -3163,22 +2375,9 @@ void QVelDevIncompHighNu27(unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QVelDeviceIncompHighNu27<<< gridQ, threads >>> ( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QVelDeviceIncompHighNu27<<< grid.grid, grid.threads >>> ( vx, vy, vz, @@ -3210,22 +2409,9 @@ void QVelDevCompHighNu27( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QVelDeviceCompHighNu27<<< gridQ, threads >>> ( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QVelDeviceCompHighNu27<<< grid.grid, grid.threads >>> ( vx, vy, vz, @@ -3256,22 +2442,9 @@ void QVeloDevEQ27(unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QVeloDeviceEQ27<<< gridQ, threads >>> (VeloX, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QVeloDeviceEQ27<<< grid.grid, grid.threads >>> (VeloX, VeloY, VeloZ, DD, @@ -3301,22 +2474,9 @@ void QVeloStreetDevEQ27( uint size_Mat, bool isEvenTimestep) { - int Grid = (numberOfStreetNodes / numberOfThreads) + 1; - int Grid1, Grid2; - if (Grid > 512) - { - Grid1 = 512; - Grid2 = (Grid / Grid1) + 1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1); - - QVeloStreetDeviceEQ27 << < gridQ, threads >> > ( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfStreetNodes); + + QVeloStreetDeviceEQ27 << < grid.grid, grid.threads >> > ( veloXfraction, veloYfraction, naschVelo, @@ -3355,7 +2515,7 @@ void QSlipDevCompTurbulentViscosity27(LBMSimulationParameter* parameterDevice, Q { dim3 grid = vf::cuda::getCudaGrid( parameterDevice->numberofthreads, boundaryCondition->numberOfBCnodes); dim3 threads(parameterDevice->numberofthreads, 1, 1 ); - + QSlipDeviceComp27TurbViscosity<<< grid, threads >>> ( parameterDevice->distributions.f[0], boundaryCondition->k, @@ -3395,7 +2555,7 @@ void QSlipDevComp27(LBMSimulationParameter* parameterDevice, QforBoundaryConditi { dim3 grid = vf::cuda::getCudaGrid( parameterDevice->numberofthreads, boundaryCondition->numberOfBCnodes); dim3 threads(parameterDevice->numberofthreads, 1, 1 ); - + QSlipDeviceComp27<<< grid, threads >>> ( parameterDevice->distributions.f[0], boundaryCondition->k, @@ -3444,22 +2604,9 @@ void QSlipGeomDevComp27(unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QSlipGeomDeviceComp27<<< gridQ, threads >>> (DD, + vf::cuda::CudaGrid grid(numberOfThreads, numberOfBCnodes); + + QSlipGeomDeviceComp27<<< grid.grid, grid.threads >>> (DD, k_Q, QQ, numberOfBCnodes, @@ -3472,7 +2619,7 @@ void QSlipGeomDevComp27(unsigned int numberOfThreads, neighborZ, size_Mat, isEvenTimestep); - getLastCudaError("QSlipGeomDeviceComp27 execution failed"); + getLastCudaError("QSlipGeomDeviceComp27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void QSlipNormDevComp27(unsigned int numberOfThreads, @@ -3490,22 +2637,9 @@ void QSlipNormDevComp27(unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QSlipNormDeviceComp27<<< gridQ, threads >>> (DD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QSlipNormDeviceComp27<<< grid.grid, grid.threads >>> (DD, k_Q, QQ, numberOfBCnodes, @@ -3676,22 +2810,9 @@ void QPressDevAntiBB27( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QPressDeviceAntiBB27<<< gridQ, threads >>>( rhoBC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QPressDeviceAntiBB27<<< grid.grid, grid.threads >>>( rhoBC, vx, vy, vz, @@ -3705,7 +2826,7 @@ void QPressDevAntiBB27( unsigned int numberOfThreads, neighborZ, size_Mat, isEvenTimestep); - getLastCudaError("QPressDeviceAntiBB27 execution failed"); + getLastCudaError("QPressDeviceAntiBB27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void QPressDevFixBackflow27( unsigned int numberOfThreads, @@ -3720,22 +2841,9 @@ void QPressDevFixBackflow27( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QPressDeviceFixBackflow27<<< gridQ, threads >>> ( rhoBC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QPressDeviceFixBackflow27<<< grid.grid, grid.threads >>> ( rhoBC, DD, k_Q, numberOfBCnodes, @@ -3745,7 +2853,7 @@ void QPressDevFixBackflow27( unsigned int numberOfThreads, neighborZ, size_Mat, isEvenTimestep); - getLastCudaError("QPressDeviceFixBackflow27 execution failed"); + getLastCudaError("QPressDeviceFixBackflow27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void QPressDevDirDepBot27( unsigned int numberOfThreads, @@ -3760,22 +2868,9 @@ void QPressDevDirDepBot27( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QPressDeviceDirDepBot27<<< gridQ, threads >>> ( rhoBC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QPressDeviceDirDepBot27<<< grid.grid, grid.threads >>> ( rhoBC, DD, k_Q, numberOfBCnodes, @@ -3785,7 +2880,7 @@ void QPressDevDirDepBot27( unsigned int numberOfThreads, neighborZ, size_Mat, isEvenTimestep); - getLastCudaError("QPressDeviceDirDepBot27 execution failed"); + getLastCudaError("QPressDeviceDirDepBot27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void QPressNoRhoDev27(LBMSimulationParameter* parameterDevice, QforBoundaryConditions* boundaryCondition) @@ -3804,10 +2899,33 @@ void QPressNoRhoDev27(LBMSimulationParameter* parameterDevice, QforBoundaryCondi parameterDevice->neighborY, parameterDevice->neighborZ, parameterDevice->numberOfNodes, - parameterDevice->isEvenTimestep); + parameterDevice->isEvenTimestep, + vf::lbm::dir::DIR_P00); getLastCudaError("QPressNoRhoDevice27 execution failed"); } ////////////////////////////////////////////////////////////////////////// +void QPressZeroRhoOutflowDev27(LBMSimulationParameter* parameterDevice, QforBoundaryConditions* boundaryCondition) +{ + dim3 grid = vf::cuda::getCudaGrid( parameterDevice->numberofthreads, boundaryCondition->numberOfBCnodes); + dim3 threads(parameterDevice->numberofthreads, 1, 1 ); + + QPressZeroRhoOutflowDevice27<<< grid, threads >>> ( + boundaryCondition->RhoBC, + parameterDevice->distributions.f[0], + boundaryCondition->k, + boundaryCondition->kN, + boundaryCondition->numberOfBCnodes, + parameterDevice->omega, + parameterDevice->neighborX, + parameterDevice->neighborY, + parameterDevice->neighborZ, + parameterDevice->numberOfNodes, + parameterDevice->isEvenTimestep, + vf::lbm::dir::DIR_P00, + parameterDevice->outflowPressureCorrectionFactor); + getLastCudaError("QPressZeroRhoOutflowDev27 execution failed"); +} +////////////////////////////////////////////////////////////////////////// void QInflowScaleByPressDev27(LBMSimulationParameter* parameterDevice, QforBoundaryConditions* boundaryCondition) { dim3 grid = vf::cuda::getCudaGrid( parameterDevice->numberofthreads, boundaryCondition->numberOfBCnodes); @@ -3841,22 +2959,9 @@ void QPressDevOld27( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QPressDeviceOld27<<< gridQ, threads >>> ( rhoBC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QPressDeviceOld27<<< grid.grid, grid.threads >>> ( rhoBC, DD, k_Q, k_N, @@ -3867,7 +2972,7 @@ void QPressDevOld27( unsigned int numberOfThreads, neighborZ, size_Mat, isEvenTimestep); - getLastCudaError("QPressDeviceOld27 execution failed"); + getLastCudaError("QPressDeviceOld27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void QPressDevIncompNEQ27(LBMSimulationParameter* parameterDevice, QforBoundaryConditions* boundaryCondition) @@ -3941,22 +3046,9 @@ void QPressDevZero27(unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QPressDeviceZero27<<< gridQ, threads >>> (DD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QPressDeviceZero27<<< grid.grid, grid.threads >>> (DD, k_Q, numberOfBCnodes, neighborX, @@ -3964,7 +3056,7 @@ void QPressDevZero27(unsigned int numberOfThreads, neighborZ, size_Mat, isEvenTimestep); - getLastCudaError("QPressDeviceOld27 execution failed"); + getLastCudaError("QPressDeviceOld27 execution failed"); } ////////////////////////////////////////////////////////////////////////// void QPressDevFake27( unsigned int numberOfThreads, @@ -3980,22 +3072,10 @@ void QPressDevFake27( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QPressDeviceFake27<<< gridQ, threads >>> (rhoBC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + + QPressDeviceFake27<<< grid.grid, grid.threads >>> (rhoBC, DD, k_Q, k_N, @@ -4040,22 +3120,9 @@ void QPressDev27_IntBB( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - QPressDevice27_IntBB<<< gridQ, threads >>> (rho, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + QPressDevice27_IntBB<<< grid.grid, grid.threads >>> (rho, DD, k_Q, QQ, @@ -4066,7 +3133,7 @@ void QPressDev27_IntBB( unsigned int numberOfThreads, neighborZ, size_Mat, isEvenTimestep); - getLastCudaError("QPressDevice27_IntBB execution failed"); + getLastCudaError("QPressDevice27_IntBB execution failed"); } // TODO: https://git.rz.tu-bs.de/irmb/VirtualFluids_dev/-/issues/29 ////////////////////////////////////////////////////////////////////////// @@ -4087,22 +3154,9 @@ void PressSchlaffer27(unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - PressSchlaff27<<< gridQ, threads >>>( rhoBC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + PressSchlaff27<<< grid.grid, grid.threads >>>( rhoBC, DD, vx0, vy0, @@ -4117,7 +3171,7 @@ void PressSchlaffer27(unsigned int numberOfThreads, neighborZ, size_Mat, isEvenTimestep); - getLastCudaError("PressSchlaff27 execution failed"); + getLastCudaError("PressSchlaff27 execution failed"); } // TODO: https://git.rz.tu-bs.de/irmb/VirtualFluids_dev/-/issues/29 ////////////////////////////////////////////////////////////////////////// @@ -4136,22 +3190,9 @@ void VelSchlaffer27( unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - VelSchlaff27<<< gridQ, threads >>>( t, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + VelSchlaff27<<< grid.grid, grid.threads >>>( t, DD, vz0, deltaVz0, @@ -4167,7 +3208,150 @@ void VelSchlaffer27( unsigned int numberOfThreads, getLastCudaError("VelSchlaff27 execution failed"); } ////////////////////////////////////////////////////////////////////////// -void PropVelo( unsigned int numberOfThreads, +void QPrecursorDevCompZeroPress(LBMSimulationParameter* parameterDevice, + QforPrecursorBoundaryConditions* boundaryCondition, + real timeRatio, + real velocityRatio) +{ + + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(parameterDevice->numberofthreads, boundaryCondition->numberOfBCnodes); + + QPrecursorDeviceCompZeroPress<<< grid.grid, grid.threads >>>(boundaryCondition->k, + boundaryCondition->numberOfBCnodes, + boundaryCondition->numberOfPrecursorNodes, + boundaryCondition->sizeQ, + parameterDevice->omega, + parameterDevice->distributions.f[0], + boundaryCondition->q27[0], + parameterDevice->neighborX, + parameterDevice->neighborY, + parameterDevice->neighborZ, + boundaryCondition->planeNeighbor0PP, + boundaryCondition->planeNeighbor0PM, + boundaryCondition->planeNeighbor0MP, + boundaryCondition->planeNeighbor0MM, + boundaryCondition->weights0PP, + boundaryCondition->weights0PM, + boundaryCondition->weights0MP, + boundaryCondition->weights0MM, + boundaryCondition->last, + boundaryCondition->current, + boundaryCondition->velocityX, + boundaryCondition->velocityY, + boundaryCondition->velocityZ, + timeRatio, + velocityRatio, + parameterDevice->numberOfNodes, + parameterDevice->isEvenTimestep); + getLastCudaError("QPrecursorDeviceCompZeroPress execution failed"); + +} +////////////////////////////////////////////////////////////////////////// +void PrecursorDevEQ27( LBMSimulationParameter* parameterDevice, + QforPrecursorBoundaryConditions* boundaryCondition, + real timeRatio, + real velocityRatio) +{ + + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(parameterDevice->numberofthreads, boundaryCondition->numberOfBCnodes); + + PrecursorDeviceEQ27<<< grid.grid, grid.threads >>>(boundaryCondition->k, + boundaryCondition->numberOfBCnodes, + boundaryCondition->numberOfPrecursorNodes, + parameterDevice->omega, + parameterDevice->distributions.f[0], + parameterDevice->neighborX, + parameterDevice->neighborX, + parameterDevice->neighborX, + boundaryCondition->planeNeighbor0PP, + boundaryCondition->planeNeighbor0PM, + boundaryCondition->planeNeighbor0MP, + boundaryCondition->planeNeighbor0MM, + boundaryCondition->weights0PP, + boundaryCondition->weights0PM, + boundaryCondition->weights0MP, + boundaryCondition->weights0MM, + boundaryCondition->last, + boundaryCondition->current, + boundaryCondition->velocityX, + boundaryCondition->velocityY, + boundaryCondition->velocityZ, + timeRatio, + velocityRatio, + parameterDevice->numberOfNodes, + parameterDevice->isEvenTimestep); + getLastCudaError("PrecursorDeviceEQ27 execution failed"); + +} +////////////////////////////////////////////////////////////////////////// +void PrecursorDevDistributions( LBMSimulationParameter* parameterDevice, + QforPrecursorBoundaryConditions* boundaryCondition, + real timeRatio, + real velocityRatio) +{ + + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(parameterDevice->numberofthreads, boundaryCondition->numberOfBCnodes); + + PrecursorDeviceDistributions<<< grid.grid, grid.threads >>>(boundaryCondition->k, + boundaryCondition->numberOfBCnodes, + boundaryCondition->numberOfPrecursorNodes, + parameterDevice->distributions.f[0], + parameterDevice->neighborX, + parameterDevice->neighborY, + parameterDevice->neighborZ, + boundaryCondition->planeNeighbor0PP, + boundaryCondition->planeNeighbor0PM, + boundaryCondition->planeNeighbor0MP, + boundaryCondition->planeNeighbor0MM, + boundaryCondition->weights0PP, + boundaryCondition->weights0PM, + boundaryCondition->weights0MP, + boundaryCondition->weights0MM, + boundaryCondition->last, + boundaryCondition->current, + timeRatio, + parameterDevice->numberOfNodes, + parameterDevice->isEvenTimestep); + getLastCudaError("QPrecursorDeviceCompZeroPress execution failed"); + +} + +////////////////////////////////////////////////////////////////////////// +void QPrecursorDevDistributions( LBMSimulationParameter* parameterDevice, + QforPrecursorBoundaryConditions* boundaryCondition, + real timeRatio, + real velocityRatio) +{ + + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(parameterDevice->numberofthreads, boundaryCondition->numberOfBCnodes); + + QPrecursorDeviceDistributions<<< grid.grid, grid.threads >>>(boundaryCondition->k, + boundaryCondition->q27[0], + boundaryCondition->sizeQ, + boundaryCondition->numberOfBCnodes, + boundaryCondition->numberOfPrecursorNodes, + parameterDevice->distributions.f[0], + parameterDevice->neighborX, + parameterDevice->neighborY, + parameterDevice->neighborZ, + boundaryCondition->planeNeighbor0PP, + boundaryCondition->planeNeighbor0PM, + boundaryCondition->planeNeighbor0MP, + boundaryCondition->planeNeighbor0MM, + boundaryCondition->weights0PP, + boundaryCondition->weights0PM, + boundaryCondition->weights0MP, + boundaryCondition->weights0MM, + boundaryCondition->last, + boundaryCondition->current, + timeRatio, + parameterDevice->numberOfNodes, + parameterDevice->isEvenTimestep); + getLastCudaError("QPrecursorDeviceCompZeroPress execution failed"); + +} +////////////////////////////////////////////////////////////////////////// +extern "C" void PropVelo( unsigned int numberOfThreads, unsigned int* neighborX, unsigned int* neighborY, unsigned int* neighborZ, @@ -4182,22 +3366,9 @@ void PropVelo( unsigned int numberOfThreads, real* DD, bool EvenOrOdd) { - int Grid = (size_Prop / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - PropellerBC<<< grid, threads >>>(neighborX, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Prop); + + PropellerBC<<< grid.grid, grid.threads >>>(neighborX, neighborY, neighborZ, rho, @@ -4236,22 +3407,9 @@ void ScaleCF27( real* DC, unsigned int nyF, unsigned int numberOfThreads) { - int Grid = (kCF / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_CF(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleCF27<<< gridINT_CF, threads >>> ( DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kCF); + + scaleCF27<<< grid.grid, grid.threads >>> ( DC, DF, neighborCX, neighborCY, @@ -4299,22 +3457,9 @@ void ScaleCFEff27(real* DC, unsigned int numberOfThreads, OffCF offCF) { - int Grid = (kCF / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_CF(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleCFEff27<<< gridINT_CF, threads >>> ( DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kCF); + + scaleCFEff27<<< grid.grid, grid.threads >>> ( DC, DF, neighborCX, neighborCY, @@ -4363,22 +3508,9 @@ void ScaleCFLast27(real* DC, unsigned int numberOfThreads, OffCF offCF) { - int Grid = (kCF / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_CF(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleCFLast27<<< gridINT_CF, threads >>> (DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kCF); + + scaleCFLast27<<< grid.grid, grid.threads >>> (DC, DF, neighborCX, neighborCY, @@ -4427,22 +3559,9 @@ void ScaleCFpress27( real* DC, unsigned int numberOfThreads, OffCF offCF) { - int Grid = (kCF / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_CF(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleCFpress27<<< gridINT_CF, threads >>>(DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kCF); + + scaleCFpress27<<< grid.grid, grid.threads >>>(DC, DF, neighborCX, neighborCY, @@ -4491,22 +3610,9 @@ void ScaleCF_Fix_27( real* DC, unsigned int numberOfThreads, OffCF offCF) { - int Grid = (kCF / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_CF(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleCF_Fix_27<<< gridINT_CF, threads >>>(DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kCF); + + scaleCF_Fix_27<<< grid.grid, grid.threads >>>(DC, DF, neighborCX, neighborCY, @@ -4555,22 +3661,9 @@ void ScaleCF_Fix_comp_27( real* DC, unsigned int numberOfThreads, OffCF offCF) { - int Grid = (kCF / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_CF(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleCF_Fix_comp_27<<< gridINT_CF, threads >>>( DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kCF); + + scaleCF_Fix_comp_27<<< grid.grid, grid.threads >>>( DC, DF, neighborCX, neighborCY, @@ -4620,22 +3713,9 @@ void ScaleCF_0817_comp_27(real* DC, OffCF offCF, CUstream_st *stream) { - int Grid = (kCF / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_CF(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleCF_0817_comp_27<<< gridINT_CF, threads, 0, stream >>>( DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kCF); + + scaleCF_0817_comp_27<<< grid.grid, grid.threads, 0, stream >>>( DC, DF, neighborCX, neighborCY, @@ -4685,22 +3765,9 @@ void ScaleCF_comp_D3Q27F3_2018(real* DC, unsigned int numberOfThreads, OffCF offCF) { - int Grid = (kCF / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_CF(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleCF_comp_D3Q27F3_2018 <<< gridINT_CF, threads >>>(DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kCF); + + scaleCF_comp_D3Q27F3_2018 <<< grid.grid, grid.threads >>>(DC, DF, G6, neighborCX, @@ -4752,22 +3819,9 @@ void ScaleCF_comp_D3Q27F3(real* DC, OffCF offCF, CUstream_st *stream) { - int Grid = (kCF / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_CF(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleCF_comp_D3Q27F3 <<< gridINT_CF, threads, 0, stream >>>( DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kCF); + + scaleCF_comp_D3Q27F3 <<< grid.grid, grid.threads, 0, stream >>>( DC, DF, G6, neighborCX, @@ -4817,22 +3871,9 @@ void ScaleCF_staggered_time_comp_27( real* DC, unsigned int numberOfThreads, OffCF offCF) { - int Grid = (kCF / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_CF(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleCF_staggered_time_comp_27<<< gridINT_CF, threads >>>( DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kCF); + + scaleCF_staggered_time_comp_27<<< grid.grid, grid.threads >>>( DC, DF, neighborCX, neighborCY, @@ -4911,6 +3952,7 @@ void ScaleCF_compressible(LBMSimulationParameter * parameterDeviceC, LBMSimulati parameterDeviceC->omega, parameterDeviceF->omega, offsetCF); + getLastCudaError("scaleCF_compressible execution failed"); } @@ -4940,22 +3982,9 @@ void ScaleCF_RhoSq_3rdMom_comp_27(real* DC, OffCF offCF, CUstream_st *stream) { - int Grid = (kCF / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_CF(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleCF_RhoSq_3rdMom_comp_27<<< gridINT_CF, threads, 0, stream >>>( DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kCF); + + scaleCF_RhoSq_3rdMom_comp_27<<< grid.grid, grid.threads, 0, stream >>>( DC, DF, neighborCX, neighborCY, @@ -5005,22 +4034,9 @@ void ScaleCF_AA2016_comp_27(real* DC, OffCF offCF, CUstream_st *stream) { - int Grid = (kCF / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_CF(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleCF_AA2016_comp_27<<< gridINT_CF, threads, 0, stream >>>(DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kCF); + + scaleCF_AA2016_comp_27<<< grid.grid, grid.threads, 0, stream >>>(DC, DF, neighborCX, neighborCY, @@ -5069,22 +4085,9 @@ void ScaleCF_NSPress_27( real* DC, unsigned int numberOfThreads, OffCF offCF) { - int Grid = (kCF / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_CF(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleCF_NSPress_27<<< gridINT_CF, threads >>>(DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kCF); + + scaleCF_NSPress_27<<< grid.grid, grid.threads >>>(DC, DF, neighborCX, neighborCY, @@ -5130,22 +4133,9 @@ void ScaleCFThSMG7( real* DC, unsigned int numberOfThreads, OffCF offCF) { - int Grid = (kCF / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_CF(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleCFThSMG7<<< gridINT_CF, threads >>> (DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kCF); + + scaleCFThSMG7<<< grid.grid, grid.threads >>> (DC, DF, DD7C, DD7F, @@ -5187,22 +4177,9 @@ void ScaleCFThS7( real* DC, real diffusivity_fine, unsigned int numberOfThreads) { - int Grid = (kCF / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_CF(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleCFThS7<<< gridINT_CF, threads >>> ( DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kCF); + + scaleCFThS7<<< grid.grid, grid.threads >>> ( DC, DF, DD7C, DD7F, @@ -5244,22 +4221,9 @@ void ScaleCFThS27( real* DC, unsigned int numberOfThreads, OffCF offCF) { - int Grid = (kCF / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_CF(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleCFThS27<<< gridINT_CF, threads >>> ( DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kCF); + + scaleCFThS27<<< grid.grid, grid.threads >>> ( DC, DF, DD27C, DD27F, @@ -5304,22 +4268,10 @@ void ScaleFC27( real* DC, unsigned int nyF, unsigned int numberOfThreads) { - int Grid = (kFC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_FC(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleFC27<<< gridINT_FC, threads >>> ( DC, + + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kFC); + + scaleFC27<<< grid.grid, grid.threads >>> ( DC, DF, neighborCX, neighborCY, @@ -5367,22 +4319,9 @@ void ScaleFCEff27(real* DC, unsigned int numberOfThreads, OffFC offFC) { - int Grid = (kFC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_FC(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleFCEff27<<< gridINT_FC, threads >>> ( DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kFC); + + scaleFCEff27<<< grid.grid, grid.threads >>> ( DC, DF, neighborCX, neighborCY, @@ -5431,22 +4370,9 @@ void ScaleFCLast27(real* DC, unsigned int numberOfThreads, OffFC offFC) { - int Grid = (kFC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_FC(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleFCLast27<<< gridINT_FC, threads >>> (DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kFC); + + scaleFCLast27<<< grid.grid, grid.threads >>> (DC, DF, neighborCX, neighborCY, @@ -5495,22 +4421,9 @@ void ScaleFCpress27(real* DC, unsigned int numberOfThreads, OffFC offFC) { - int Grid = (kFC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_FC(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleFCpress27<<< gridINT_FC, threads >>> ( DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kFC); + + scaleFCpress27<<< grid.grid, grid.threads >>> ( DC, DF, neighborCX, neighborCY, @@ -5559,22 +4472,9 @@ void ScaleFC_Fix_27(real* DC, unsigned int numberOfThreads, OffFC offFC) { - int Grid = (kFC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_FC(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleFC_Fix_27<<< gridINT_FC, threads >>> ( DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kFC); + + scaleFC_Fix_27<<< grid.grid, grid.threads >>> ( DC, DF, neighborCX, neighborCY, @@ -5623,22 +4523,9 @@ void ScaleFC_Fix_comp_27( real* DC, unsigned int numberOfThreads, OffFC offFC) { - int Grid = (kFC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_FC(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleFC_Fix_comp_27<<< gridINT_FC, threads >>> ( DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kFC); + + scaleFC_Fix_comp_27<<< grid.grid, grid.threads >>> ( DC, DF, neighborCX, neighborCY, @@ -5688,22 +4575,9 @@ void ScaleFC_0817_comp_27( real* DC, OffFC offFC, CUstream_st *stream) { - int Grid = (kFC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_FC(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleFC_0817_comp_27<<< gridINT_FC, threads, 0, stream >>> (DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kFC); + + scaleFC_0817_comp_27<<< grid.grid, grid.threads, 0, stream >>> (DC, DF, neighborCX, neighborCY, @@ -5753,22 +4627,9 @@ void ScaleFC_comp_D3Q27F3_2018( real* DC, unsigned int numberOfThreads, OffFC offFC) { - int Grid = (kFC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_FC(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleFC_comp_D3Q27F3_2018 <<< gridINT_FC, threads >>> (DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kFC); + + scaleFC_comp_D3Q27F3_2018 <<< grid.grid, grid.threads >>> (DC, DF, G6, neighborCX, @@ -5820,22 +4681,9 @@ void ScaleFC_comp_D3Q27F3( real* DC, OffFC offFC, CUstream_st *stream) { - int Grid = (kFC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_FC(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleFC_comp_D3Q27F3 <<< gridINT_FC, threads, 0, stream >>> (DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kFC); + + scaleFC_comp_D3Q27F3 <<< grid.grid, grid.threads, 0, stream >>> (DC, DF, G6, neighborCX, @@ -5885,22 +4733,9 @@ void ScaleFC_staggered_time_comp_27( real* DC, unsigned int numberOfThreads, OffFC offFC) { - int Grid = (kFC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_FC(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleFC_staggered_time_comp_27<<< gridINT_FC, threads >>> ( DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kFC); + + scaleFC_staggered_time_comp_27<<< grid.grid, grid.threads >>> ( DC, DF, neighborCX, neighborCY, @@ -6007,22 +4842,9 @@ void ScaleFC_RhoSq_3rdMom_comp_27( real* DC, OffFC offFC, CUstream_st *stream) { - int Grid = (kFC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_FC(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleFC_RhoSq_3rdMom_comp_27<<< gridINT_FC, threads, 0, stream >>>(DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kFC); + + scaleFC_RhoSq_3rdMom_comp_27<<< grid.grid, grid.threads, 0, stream >>>(DC, DF, neighborCX, neighborCY, @@ -6072,22 +4894,9 @@ void ScaleFC_AA2016_comp_27( real* DC, OffFC offFC, CUstream_st *stream) { - int Grid = (kFC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_FC(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleFC_AA2016_comp_27<<< gridINT_FC, threads, 0, stream >>>(DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kFC); + + scaleFC_AA2016_comp_27<<< grid.grid, grid.threads, 0, stream >>>(DC, DF, neighborCX, neighborCY, @@ -6136,22 +4945,9 @@ void ScaleFC_NSPress_27(real* DC, unsigned int numberOfThreads, OffFC offFC) { - int Grid = (kFC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_FC(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleFC_NSPress_27<<< gridINT_FC, threads >>> ( DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kFC); + + scaleFC_NSPress_27<<< grid.grid, grid.threads >>> ( DC, DF, neighborCX, neighborCY, @@ -6197,22 +4993,9 @@ void ScaleFCThSMG7(real* DC, unsigned int numberOfThreads, OffFC offFC) { - int Grid = (kFC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_FC(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleFCThSMG7<<< gridINT_FC, threads >>>( DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kFC); + + scaleFCThSMG7<<< grid.grid, grid.threads >>>( DC, DF, DD7C, DD7F, @@ -6254,22 +5037,9 @@ void ScaleFCThS7( real* DC, real diffusivity_coarse, unsigned int numberOfThreads) { - int Grid = (kFC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_FC(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleFCThS7<<< gridINT_FC, threads >>>(DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kFC); + + scaleFCThS7<<< grid.grid, grid.threads >>>(DC, DF, DD7C, DD7F, @@ -6311,22 +5081,9 @@ void ScaleFCThS27( real* DC, unsigned int numberOfThreads, OffFC offFC) { - int Grid = (kFC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridINT_FC(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - scaleFCThS27<<< gridINT_FC, threads >>>( DC, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, kFC); + + scaleFCThS27<<< grid.grid, grid.threads >>>( DC, DF, DD27C, DD27F, @@ -6362,22 +5119,9 @@ void DragLiftPostD27(real* DD, bool isEvenTimestep, unsigned int numberOfThreads) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - DragLiftPost27<<< grid, threads >>>(DD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + DragLiftPost27<<< grid.grid, grid.threads >>>(DD, k_Q, QQ, numberOfBCnodes, @@ -6406,22 +5150,9 @@ void DragLiftPreD27( real* DD, bool isEvenTimestep, unsigned int numberOfThreads) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - DragLiftPre27<<< grid, threads >>>( DD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + DragLiftPre27<<< grid.grid, grid.threads >>>( DD, k_Q, QQ, numberOfBCnodes, @@ -6447,22 +5178,9 @@ void CalcCPtop27(real* DD, bool isEvenTimestep, unsigned int numberOfThreads) { - int Grid = (nonCp / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - CalcCP27<<< grid, threads >>>(DD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, nonCp); + + CalcCP27<<< grid.grid, grid.threads >>>(DD, cpIndex, nonCp, cpPress, @@ -6485,22 +5203,9 @@ void CalcCPbottom27( real* DD, bool isEvenTimestep, unsigned int numberOfThreads) { - int Grid = (nonCp / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - CalcCP27<<< grid, threads >>>(DD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, nonCp); + + CalcCP27<<< grid.grid, grid.threads >>>(DD, cpIndex, nonCp, cpPress, @@ -6524,22 +5229,9 @@ void GetSendFsPreDev27(real* DD, unsigned int numberOfThreads, cudaStream_t stream) { - int Grid = (buffmax / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - getSendFsPre27<<< grid, threads, 0, stream >>>(DD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, buffmax); + + getSendFsPre27<<< grid.grid, grid.threads, 0, stream >>>(DD, bufferFs, sendIndex, buffmax, @@ -6563,22 +5255,9 @@ void GetSendFsPostDev27(real* DD, unsigned int numberOfThreads, cudaStream_t stream) { - int Grid = (buffmax / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - getSendFsPost27<<< grid, threads, 0, stream >>>(DD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, buffmax); + + getSendFsPost27<<< grid.grid, grid.threads, 0, stream >>>(DD, bufferFs, sendIndex, buffmax, @@ -6602,22 +5281,9 @@ void SetRecvFsPreDev27(real* DD, unsigned int numberOfThreads, cudaStream_t stream) { - int Grid = (buffmax / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - setRecvFsPre27<<< grid, threads, 0, stream >>>(DD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, buffmax); + + setRecvFsPre27<<< grid.grid, grid.threads, 0, stream >>>(DD, bufferFs, recvIndex, buffmax, @@ -6641,22 +5307,9 @@ void SetRecvFsPostDev27(real* DD, unsigned int numberOfThreads, cudaStream_t stream) { - int Grid = (buffmax / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - setRecvFsPost27<<< grid, threads, 0, stream >>>(DD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, buffmax); + + setRecvFsPost27<<< grid.grid, grid.threads, 0, stream >>>(DD, bufferFs, recvIndex, buffmax, @@ -6680,22 +5333,9 @@ void getSendGsDevF3( bool isEvenTimestep, unsigned int numberOfThreads) { - int Grid = (buffmax / numberOfThreads) + 1; - int Grid1, Grid2; - if (Grid > 512) - { - Grid1 = 512; - Grid2 = (Grid / Grid1) + 1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1); - - getSendGsF3 <<< grid, threads >>> ( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, buffmax); + + getSendGsF3 <<< grid.grid, grid.threads >>> ( G6, bufferGs, sendIndex, @@ -6720,22 +5360,9 @@ void setRecvGsDevF3( bool isEvenTimestep, unsigned int numberOfThreads) { - int Grid = (buffmax / numberOfThreads) + 1; - int Grid1, Grid2; - if (Grid > 512) - { - Grid1 = 512; - Grid2 = (Grid / Grid1) + 1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 grid(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1); - - setRecvGsF3 <<< grid, threads >>> ( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, buffmax); + + setRecvGsF3 <<< grid.grid, grid.threads >>> ( G6, bufferGs, recvIndex, @@ -6763,22 +5390,9 @@ void WallFuncDev27(unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (numberOfBCnodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - WallFunction27<<< gridQ, threads >>> ( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfBCnodes); + + WallFunction27<<< grid.grid, grid.threads >>> ( vx, vy, vz, @@ -6814,22 +5428,9 @@ void SetOutputWallVelocitySP27(unsigned int numberOfThreads, real* DD, bool isEvenTimestep) { - int Grid = (numberOfWallNodes / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - LBSetOutputWallVelocitySP27<<< gridQ, threads >>> ( vxD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfWallNodes); + + LBSetOutputWallVelocitySP27<<< grid.grid, grid.threads >>> ( vxD, vyD, vzD, vxWall, @@ -6862,22 +5463,9 @@ void GetVelotoForce27(unsigned int numberOfThreads, unsigned int size_Mat, bool isEvenTimestep) { - int Grid = (nonAtBC / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - GetVeloforForcing27<<< gridQ, threads >>> (DD, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, nonAtBC); + + GetVeloforForcing27<<< grid.grid, grid.threads >>> (DD, bcIndex, nonAtBC, Vx, @@ -6911,27 +5499,14 @@ void InitParticlesDevice(real* coordX, unsigned int* neighborY, unsigned int* neighborZ, unsigned int* neighborWSB, - int level, + int level, unsigned int numberOfParticles, unsigned int size_Mat, unsigned int numberOfThreads) { - int Grid = (numberOfParticles / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - InitParticles<<< gridQ, threads >>> (coordX, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfParticles); + + InitParticles<<< grid.grid, grid.threads >>> (coordX, coordY, coordZ, coordParticleXlocal, @@ -6986,22 +5561,9 @@ void MoveParticlesDevice(real* coordX, unsigned int numberOfThreads, bool isEvenTimestep) { - int Grid = (numberOfParticles / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - MoveParticles<<< gridQ, threads >>> (coordX, + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, numberOfParticles); + + MoveParticles<<< grid.grid, grid.threads >>> (coordX, coordY, coordZ, coordParticleXlocal, @@ -7035,22 +5597,8 @@ void initRandomDevice(curandState* state, unsigned int size_Mat, unsigned int numberOfThreads) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - initRandom<<< gridQ, threads >>> (state); + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + initRandom<<< grid.grid, grid.threads >>> (state); getLastCudaError("initRandom execution failed"); } ////////////////////////////////////////////////////////////////////////// @@ -7059,22 +5607,8 @@ void generateRandomValuesDevice( curandState* state, real* randArray, unsigned int numberOfThreads) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - generateRandomValues<<< gridQ, threads >>> (state,randArray); + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + generateRandomValues<<< grid.grid, grid.threads >>> (state,randArray); getLastCudaError("generateRandomValues execution failed"); } ////////////////////////////////////////////////////////////////////////// @@ -7097,22 +5631,8 @@ void CalcTurbulenceIntensityDevice( bool isEvenTimestep, uint numberOfThreads) { - int Grid = (size_Mat / numberOfThreads)+1; - int Grid1, Grid2; - if (Grid>512) - { - Grid1 = 512; - Grid2 = (Grid/Grid1)+1; - } - else - { - Grid1 = 1; - Grid2 = Grid; - } - dim3 gridQ(Grid1, Grid2); - dim3 threads(numberOfThreads, 1, 1 ); - - CalcTurbulenceIntensity<<<gridQ, threads>>>( + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(numberOfThreads, size_Mat); + CalcTurbulenceIntensity<<<grid.grid, grid.threads>>>( vxx, vyy, vzz, diff --git a/src/gpu/VirtualFluids_GPU/GPU/PrecursorBCs27.cu b/src/gpu/VirtualFluids_GPU/GPU/PrecursorBCs27.cu new file mode 100644 index 0000000000000000000000000000000000000000..78b190e37ebaa395c89aae3b47cd4cc4f3147306 --- /dev/null +++ b/src/gpu/VirtualFluids_GPU/GPU/PrecursorBCs27.cu @@ -0,0 +1,967 @@ +#include "LBM/LB.h" +#include <lbm/constants/NumericConstants.h> +#include <lbm/constants/D3Q27.h> +#include <lbm/MacroscopicQuantities.h> + +#include "VirtualFluids_GPU/Kernel/Utilities/DistributionHelper.cuh" +#include "VirtualFluids_GPU/GPU/KernelUtilities.h" + +using namespace vf::lbm::constant; +using namespace vf::lbm::dir; + +__global__ void QPrecursorDeviceCompZeroPress( int* subgridDistanceIndices, + int numberOfBCnodes, + int numberOfPrecursorNodes, + int sizeQ, + real omega, + real* distributions, + real* subgridDistances, + uint* neighborX, + uint* neighborY, + uint* neighborZ, + uint* neighbors0PP, + uint* neighbors0PM, + uint* neighbors0MP, + uint* neighbors0MM, + real* weights0PP, + real* weights0PM, + real* weights0MP, + real* weights0MM, + real* vLast, + real* vCurrent, + real velocityX, + real velocityY, + real velocityZ, + real timeRatio, + real velocityRatio, + unsigned long long numberOfLBnodes, + bool isEvenTimestep) +{ + const unsigned k = vf::gpu::getNodeIndex(); + + if(k>=numberOfBCnodes) return; + + //////////////////////////////////////////////////////////////////////////////// + // interpolation of velocity + real vxLastInterpd, vyLastInterpd, vzLastInterpd; + real vxNextInterpd, vyNextInterpd, vzNextInterpd; + + uint kNeighbor0PP = neighbors0PP[k]; + real d0PP = weights0PP[k]; + + real* vxLast = vLast; + real* vyLast = &vLast[numberOfPrecursorNodes]; + real* vzLast = &vLast[2*numberOfPrecursorNodes]; + + real* vxCurrent = vCurrent; + real* vyCurrent = &vCurrent[numberOfPrecursorNodes]; + real* vzCurrent = &vCurrent[2*numberOfPrecursorNodes]; + + if(d0PP < 1e6) + { + uint kNeighbor0PM = neighbors0PM[k]; + uint kNeighbor0MP = neighbors0MP[k]; + uint kNeighbor0MM = neighbors0MM[k]; + + real d0PM = weights0PM[k]; + real d0MP = weights0MP[k]; + real d0MM = weights0MM[k]; + + real invWeightSum = 1.f/(d0PP+d0PM+d0MP+d0MM); + + vxLastInterpd = (vxLast[kNeighbor0PP]*d0PP + vxLast[kNeighbor0PM]*d0PM + vxLast[kNeighbor0MP]*d0MP + vxLast[kNeighbor0MM]*d0MM)*invWeightSum; + vyLastInterpd = (vyLast[kNeighbor0PP]*d0PP + vyLast[kNeighbor0PM]*d0PM + vyLast[kNeighbor0MP]*d0MP + vyLast[kNeighbor0MM]*d0MM)*invWeightSum; + vzLastInterpd = (vzLast[kNeighbor0PP]*d0PP + vzLast[kNeighbor0PM]*d0PM + vzLast[kNeighbor0MP]*d0MP + vzLast[kNeighbor0MM]*d0MM)*invWeightSum; + + vxNextInterpd = (vxCurrent[kNeighbor0PP]*d0PP + vxCurrent[kNeighbor0PM]*d0PM + vxCurrent[kNeighbor0MP]*d0MP + vxCurrent[kNeighbor0MM]*d0MM)*invWeightSum; + vyNextInterpd = (vyCurrent[kNeighbor0PP]*d0PP + vyCurrent[kNeighbor0PM]*d0PM + vyCurrent[kNeighbor0MP]*d0MP + vyCurrent[kNeighbor0MM]*d0MM)*invWeightSum; + vzNextInterpd = (vzCurrent[kNeighbor0PP]*d0PP + vzCurrent[kNeighbor0PM]*d0PM + vzCurrent[kNeighbor0MP]*d0MP + vzCurrent[kNeighbor0MM]*d0MM)*invWeightSum; + } + else + { + vxLastInterpd = vxLast[kNeighbor0PP]; + vyLastInterpd = vyLast[kNeighbor0PP]; + vzLastInterpd = vzLast[kNeighbor0PP]; + + vxNextInterpd = vxCurrent[kNeighbor0PP]; + vyNextInterpd = vyCurrent[kNeighbor0PP]; + vzNextInterpd = vzCurrent[kNeighbor0PP]; + } + + // if(k==16300)s printf("%f %f %f\n", vxLastInterpd, vyLastInterpd, vzLastInterpd); + real VeloX = (velocityX + (1.f-timeRatio)*vxLastInterpd + timeRatio*vxNextInterpd)/velocityRatio; + real VeloY = (velocityY + (1.f-timeRatio)*vyLastInterpd + timeRatio*vyNextInterpd)/velocityRatio; + real VeloZ = (velocityZ + (1.f-timeRatio)*vzLastInterpd + timeRatio*vzNextInterpd)/velocityRatio; + // From here on just a copy of QVelDeviceCompZeroPress + //////////////////////////////////////////////////////////////////////////////// + + Distributions27 dist; + getPointersToDistributions(dist, distributions, numberOfLBnodes, isEvenTimestep); + + unsigned int KQK = subgridDistanceIndices[k]; + unsigned int k000= KQK; + unsigned int kP00 = KQK; + unsigned int kM00 = neighborX[KQK]; + unsigned int k0P0 = KQK; + unsigned int k0M0 = neighborY[KQK]; + unsigned int k00P = KQK; + unsigned int k00M = neighborZ[KQK]; + unsigned int kMM0 = neighborY[kM00]; + unsigned int kPP0 = KQK; + unsigned int kPM0 = k0M0; + unsigned int kMP0 = kM00; + unsigned int kM0M = neighborZ[kM00]; + unsigned int kP0P = KQK; + unsigned int kP0M = k00M; + unsigned int kM0P = kM00; + unsigned int k0PP = KQK; + unsigned int k0MM = neighborZ[k0M0]; + unsigned int k0PM = k00M; + unsigned int k0MP = k0M0; + unsigned int kPMP = k0M0; + unsigned int kMPM = kM0M; + unsigned int kMPP = kM00; + unsigned int kPMM = k0MM; + unsigned int kMMP = kMM0; + unsigned int kPPM = k00M; + unsigned int kPPP = KQK; + unsigned int kMMM = neighborZ[kMM0]; + + //////////////////////////////////////////////////////////////////////////////// + //! - Set local distributions + //! + real f_M00 = (dist.f[DIR_P00])[kP00]; + real f_P00 = (dist.f[DIR_M00])[kM00]; + real f_0M0 = (dist.f[DIR_0P0])[k0P0]; + real f_0P0 = (dist.f[DIR_0M0])[k0M0]; + real f_00M = (dist.f[DIR_00P])[k00P]; + real f_00P = (dist.f[DIR_00M])[k00M]; + real f_MM0 = (dist.f[DIR_PP0])[kPP0]; + real f_PP0 = (dist.f[DIR_MM0])[kMM0]; + real f_MP0 = (dist.f[DIR_PM0])[kPM0]; + real f_PM0 = (dist.f[DIR_MP0])[kMP0]; + real f_M0M = (dist.f[DIR_P0P])[kP0P]; + real f_P0P = (dist.f[DIR_M0M])[kM0M]; + real f_M0P = (dist.f[DIR_P0M])[kP0M]; + real f_P0M = (dist.f[DIR_M0P])[kM0P]; + real f_0MM = (dist.f[DIR_0PP])[k0PP]; + real f_0PP = (dist.f[DIR_0MM])[k0MM]; + real f_0MP = (dist.f[DIR_0PM])[k0PM]; + real f_0PM = (dist.f[DIR_0MP])[k0MP]; + real f_MMM = (dist.f[DIR_PPP])[kPPP]; + real f_PPM = (dist.f[DIR_MMP])[kMMP]; + real f_MPM = (dist.f[DIR_PMP])[kPMP]; + real f_PMM = (dist.f[DIR_MPP])[kMPP]; + real f_MMP = (dist.f[DIR_PPM])[kPPM]; + real f_PPP = (dist.f[DIR_MMM])[kMMM]; + real f_MPP = (dist.f[DIR_PMM])[kPMM]; + real f_PMP = (dist.f[DIR_MPM])[kMPM]; + + SubgridDistances27 subgridD; + getPointersToSubgridDistances(subgridD, subgridDistances, numberOfBCnodes); + + //////////////////////////////////////////////////////////////////////////////// + real drho = f_PMP + f_MPP + f_PPP + f_MMP + f_PMM + f_MPM + f_PPM + f_MMM + + f_0PM + f_0PP + f_0MP + f_0MM + f_P0M + f_M0P + f_P0P + f_M0M + f_PM0 + f_MP0 + f_PP0 + f_MM0 + + f_00P + f_00M + f_0P0 + f_0M0 + f_P00 + f_M00 + ((dist.f[DIR_000])[k000]); + + real vx1 = (((f_PMP - f_MPM) - (f_MPP - f_PMM)) + ((f_PPP - f_MMM) - (f_MMP - f_PPM)) + + ((f_P0M - f_M0P) + (f_P0P - f_M0M)) + ((f_PM0 - f_MP0) + (f_PP0 - f_MM0)) + + (f_P00 - f_M00)) / (c1o1 + drho); + + + real vx2 = ((-(f_PMP - f_MPM) + (f_MPP - f_PMM)) + ((f_PPP - f_MMM) - (f_MMP - f_PPM)) + + ((f_0PM - f_0MP) + (f_0PP - f_0MM)) + (-(f_PM0 - f_MP0) + (f_PP0 - f_MM0)) + + (f_0P0 - f_0M0)) / (c1o1 + drho); + + real vx3 = (((f_PMP - f_MPM) + (f_MPP - f_PMM)) + ((f_PPP - f_MMM) + (f_MMP - f_PPM)) + + (-(f_0PM - f_0MP) + (f_0PP - f_0MM)) + ((f_P0P - f_M0M) - (f_P0M - f_M0P)) + + (f_00P - f_00M)) / (c1o1 + drho); + + + // if(k==16383 || k==0) printf("k %d kQ %d drho = %f u %f v %f w %f\n",k, KQK, drho, vx1, vx2, vx3); + real cu_sq=c3o2*(vx1*vx1+vx2*vx2+vx3*vx3) * (c1o1 + drho); + ////////////////////////////////////////////////////////////////////////// + + + //////////////////////////////////////////////////////////////////////////////// + //! - Update distributions with subgrid distance (q) between zero and one + real feq, q, velocityLB, velocityBC; + q = (subgridD.q[DIR_P00])[k]; + if (q>=c0o1 && q<=c1o1) // only update distribution for q between zero and one + { + velocityLB = vx1; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c2o27); + velocityBC = VeloX; + (dist.f[DIR_M00])[kM00] = getInterpolatedDistributionForVeloWithPressureBC(q, f_P00, f_M00, feq, omega, drho, velocityBC, c2o27); + } + + q = (subgridD.q[DIR_M00])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = -vx1; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c2o27); + velocityBC = -VeloX; + (dist.f[DIR_P00])[kP00] = getInterpolatedDistributionForVeloWithPressureBC(q, f_M00, f_P00, feq, omega, drho, velocityBC, c2o27); + } + + q = (subgridD.q[DIR_0P0])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = vx2; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c2o27); + velocityBC = VeloY; + (dist.f[DIR_0M0])[DIR_0M0] = getInterpolatedDistributionForVeloWithPressureBC(q, f_0P0, f_0M0, feq, omega, drho, velocityBC, c2o27); + } + + q = (subgridD.q[DIR_0M0])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = -vx2; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c2o27); + velocityBC = -VeloY; + (dist.f[DIR_0P0])[k0P0] = getInterpolatedDistributionForVeloWithPressureBC(q, f_0M0, f_0P0, feq, omega, drho, velocityBC, c2o27); + } + + q = (subgridD.q[DIR_00P])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c2o27); + velocityBC = VeloZ; + (dist.f[DIR_00M])[k00M] = getInterpolatedDistributionForVeloWithPressureBC(q, f_00P, f_00M, feq, omega, drho, velocityBC, c2o27); + } + + q = (subgridD.q[DIR_00M])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = -vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c2o27); + velocityBC = -VeloZ; + (dist.f[DIR_00P])[k00P] = getInterpolatedDistributionForVeloWithPressureBC(q, f_00M, f_00P, feq, omega, drho, velocityBC, c2o27); + } + + q = (subgridD.q[DIR_PP0])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = vx1 + vx2; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o54); + velocityBC = VeloX + VeloY; + (dist.f[DIR_MM0])[kMM0] = getInterpolatedDistributionForVeloWithPressureBC(q, f_PP0, f_MM0, feq, omega, drho, velocityBC, c1o54); + } + + q = (subgridD.q[DIR_MM0])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = -vx1 - vx2; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o54); + velocityBC = -VeloX - VeloY; + (dist.f[DIR_PP0])[kPP0] = getInterpolatedDistributionForVeloWithPressureBC(q, f_MM0, f_PP0, feq, omega, drho, velocityBC, c1o54); + } + + q = (subgridD.q[DIR_PM0])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = vx1 - vx2; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o54); + velocityBC = VeloX - VeloY; + (dist.f[DIR_MP0])[kMP0] = getInterpolatedDistributionForVeloWithPressureBC(q, f_PM0, f_MP0, feq, omega, drho, velocityBC, c1o54); + } + + q = (subgridD.q[DIR_MP0])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = -vx1 + vx2; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o54); + velocityBC = -VeloX + VeloY; + (dist.f[DIR_PM0])[kPM0] = getInterpolatedDistributionForVeloWithPressureBC(q, f_MP0, f_PM0, feq, omega, drho, velocityBC, c1o54); + } + + q = (subgridD.q[DIR_P0P])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = vx1 + vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o54); + velocityBC = VeloX + VeloZ; + (dist.f[DIR_M0M])[kM0M] = getInterpolatedDistributionForVeloWithPressureBC(q, f_P0P, f_M0M, feq, omega, drho, velocityBC, c1o54); + } + + q = (subgridD.q[DIR_M0M])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = -vx1 - vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o54); + velocityBC = -VeloX - VeloZ; + (dist.f[DIR_P0P])[kP0P] = getInterpolatedDistributionForVeloWithPressureBC(q, f_M0M, f_P0P, feq, omega, drho, velocityBC, c1o54); + } + + q = (subgridD.q[DIR_P0M])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = vx1 - vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o54); + velocityBC = VeloX - VeloZ; + (dist.f[DIR_M0P])[kM0P] = getInterpolatedDistributionForVeloWithPressureBC(q, f_P0M, f_M0P, feq, omega, drho, velocityBC, c1o54); + } + + q = (subgridD.q[DIR_M0P])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = -vx1 + vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o54); + velocityBC = -VeloX + VeloZ; + (dist.f[DIR_P0M])[kP0M] = getInterpolatedDistributionForVeloWithPressureBC(q, f_M0P, f_P0M, feq, omega, drho, velocityBC, c1o54); + } + + q = (subgridD.q[DIR_0PP])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = vx2 + vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o54); + velocityBC = VeloY + VeloZ; + (dist.f[DIR_0MM])[k0MM] = getInterpolatedDistributionForVeloWithPressureBC(q, f_0PP, f_0MM, feq, omega, drho, velocityBC, c1o54); + } + + q = (subgridD.q[DIR_0MM])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = -vx2 - vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o54); + velocityBC = -VeloY - VeloZ; + (dist.f[DIR_0PP])[k0PP] = getInterpolatedDistributionForVeloWithPressureBC(q, f_0MM, f_0PP, feq, omega, drho, velocityBC, c1o54); + } + + q = (subgridD.q[DIR_0PM])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = vx2 - vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o54); + velocityBC = VeloY - VeloZ; + (dist.f[DIR_0MP])[k0MP] = getInterpolatedDistributionForVeloWithPressureBC(q, f_0PM, f_0PP, feq, omega, drho, velocityBC, c1o54); + } + + q = (subgridD.q[DIR_0MP])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = -vx2 + vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o54); + velocityBC = -VeloY + VeloZ; + (dist.f[DIR_0PM])[k0PM] = getInterpolatedDistributionForVeloWithPressureBC(q, f_0PP, f_0PM, feq, omega, drho, velocityBC, c1o54); + } + + q = (subgridD.q[DIR_PPP])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = vx1 + vx2 + vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o216); + velocityBC = VeloX + VeloY + VeloZ; + (dist.f[DIR_MMM])[kMMM] = getInterpolatedDistributionForVeloWithPressureBC(q, f_PPP, f_MMM, feq, omega, drho, velocityBC, c1o216); + } + + q = (subgridD.q[DIR_MMM])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = -vx1 - vx2 - vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o216); + velocityBC = -VeloX - VeloY - VeloZ; + (dist.f[DIR_PPP])[kPPP] = getInterpolatedDistributionForVeloWithPressureBC(q, f_MMM, f_PPP, feq, omega, drho, velocityBC, c1o216); + } + + q = (subgridD.q[DIR_PPM])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = vx1 + vx2 - vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o216); + velocityBC = VeloX + VeloY - VeloZ; + (dist.f[DIR_MMP])[kMMP] = getInterpolatedDistributionForVeloWithPressureBC(q, f_PPM, f_MMP, feq, omega, drho, velocityBC, c1o216); + } + + q = (subgridD.q[DIR_MMP])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = -vx1 - vx2 + vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o216); + velocityBC = -VeloX - VeloY + VeloZ; + (dist.f[DIR_PPM])[kPPM] = getInterpolatedDistributionForVeloWithPressureBC(q, f_MMP, f_PPM, feq, omega, drho, velocityBC, c1o216); + } + + q = (subgridD.q[DIR_PMP])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = vx1 - vx2 + vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o216); + velocityBC = VeloX - VeloY + VeloZ; + (dist.f[DIR_MPM])[kMPM] = getInterpolatedDistributionForVeloWithPressureBC(q, f_PMP, f_MPM, feq, omega, drho, velocityBC, c1o216); + } + + q = (subgridD.q[DIR_MPM])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = -vx1 + vx2 - vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o216); + velocityBC = -VeloX + VeloY - VeloZ; + (dist.f[DIR_PMP])[kPMP] = getInterpolatedDistributionForVeloWithPressureBC(q, f_MPM, f_PMP, feq, omega, drho, velocityBC, c1o216); + } + + q = (subgridD.q[DIR_PMM])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = vx1 - vx2 - vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o216); + velocityBC = VeloX - VeloY - VeloZ; + (dist.f[DIR_MPP])[kMPP] = getInterpolatedDistributionForVeloWithPressureBC(q, f_PMM, f_MPP, feq, omega, drho, velocityBC, c1o216); + } + + q = (subgridD.q[DIR_MPP])[k]; + if (q>=c0o1 && q<=c1o1) + { + velocityLB = -vx1 + vx2 + vx3; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c1o216); + velocityBC = -VeloX + VeloY + VeloZ; + (dist.f[DIR_PMM])[kPMM] = getInterpolatedDistributionForVeloWithPressureBC(q, f_MPP, f_PMM, feq, omega, drho, velocityBC, c1o216); + } +} +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +__global__ void PrecursorDeviceEQ27( int* subgridDistanceIndices, + int numberOfBCnodes, + int numberOfPrecursorNodes, + real omega, + real* distributions, + uint* neighborX, + uint* neighborY, + uint* neighborZ, + uint* neighbors0PP, + uint* neighbors0PM, + uint* neighbors0MP, + uint* neighbors0MM, + real* weights0PP, + real* weights0PM, + real* weights0MP, + real* weights0MM, + real* vLast, + real* vCurrent, + real velocityX, + real velocityY, + real velocityZ, + real timeRatio, + real velocityRatio, + unsigned long long numberOfLBnodes, + bool isEvenTimestep) +{ + const unsigned k = vf::gpu::getNodeIndex(); + + if(k>=numberOfBCnodes) return; + + //////////////////////////////////////////////////////////////////////////////// + // interpolation of velocity + real vxLastInterpd, vyLastInterpd, vzLastInterpd; + real vxNextInterpd, vyNextInterpd, vzNextInterpd; + + uint kNeighbor0PP = neighbors0PP[k]; + real d0PP = weights0PP[k]; + + real* vxLast = vLast; + real* vyLast = &vLast[numberOfPrecursorNodes]; + real* vzLast = &vLast[2*numberOfPrecursorNodes]; + + real* vxCurrent = vCurrent; + real* vyCurrent = &vCurrent[numberOfPrecursorNodes]; + real* vzCurrent = &vCurrent[2*numberOfPrecursorNodes]; + + if(d0PP < 1e6) + { + uint kNeighbor0PM = neighbors0PM[k]; + uint kNeighbor0MP = neighbors0MP[k]; + uint kNeighbor0MM = neighbors0MM[k]; + + real d0PM = weights0PM[k]; + real d0MP = weights0MP[k]; + real d0MM = weights0MM[k]; + + real invWeightSum = 1.f/(d0PP+d0PM+d0MP+d0MM); + + vxLastInterpd = (vxLast[kNeighbor0PP]*d0PP + vxLast[kNeighbor0PM]*d0PM + vxLast[kNeighbor0MP]*d0MP + vxLast[kNeighbor0MM]*d0MM)*invWeightSum; + vyLastInterpd = (vyLast[kNeighbor0PP]*d0PP + vyLast[kNeighbor0PM]*d0PM + vyLast[kNeighbor0MP]*d0MP + vyLast[kNeighbor0MM]*d0MM)*invWeightSum; + vzLastInterpd = (vzLast[kNeighbor0PP]*d0PP + vzLast[kNeighbor0PM]*d0PM + vzLast[kNeighbor0MP]*d0MP + vzLast[kNeighbor0MM]*d0MM)*invWeightSum; + + vxNextInterpd = (vxCurrent[kNeighbor0PP]*d0PP + vxCurrent[kNeighbor0PM]*d0PM + vxCurrent[kNeighbor0MP]*d0MP + vxCurrent[kNeighbor0MM]*d0MM)*invWeightSum; + vyNextInterpd = (vyCurrent[kNeighbor0PP]*d0PP + vyCurrent[kNeighbor0PM]*d0PM + vyCurrent[kNeighbor0MP]*d0MP + vyCurrent[kNeighbor0MM]*d0MM)*invWeightSum; + vzNextInterpd = (vzCurrent[kNeighbor0PP]*d0PP + vzCurrent[kNeighbor0PM]*d0PM + vzCurrent[kNeighbor0MP]*d0MP + vzCurrent[kNeighbor0MM]*d0MM)*invWeightSum; + } + else + { + vxLastInterpd = vxLast[kNeighbor0PP]; + vyLastInterpd = vyLast[kNeighbor0PP]; + vzLastInterpd = vzLast[kNeighbor0PP]; + + vxNextInterpd = vxCurrent[kNeighbor0PP]; + vyNextInterpd = vyCurrent[kNeighbor0PP]; + vzNextInterpd = vzCurrent[kNeighbor0PP]; + } + + // if(k==16300) printf("%f %f %f\n", vxLastInterpd, vyLastInterpd, vzLastInterpd); + real VeloX = (velocityX + (1.f-timeRatio)*vxLastInterpd + timeRatio*vxNextInterpd)/velocityRatio; + real VeloY = (velocityY + (1.f-timeRatio)*vyLastInterpd + timeRatio*vyNextInterpd)/velocityRatio; + real VeloZ = (velocityZ + (1.f-timeRatio)*vzLastInterpd + timeRatio*vzNextInterpd)/velocityRatio; + // From here on just a copy of QVelDeviceCompZeroPress + //////////////////////////////////////////////////////////////////////////////// + + Distributions27 dist; + getPointersToDistributions(dist, distributions, numberOfLBnodes, !isEvenTimestep); + + unsigned int KQK = subgridDistanceIndices[k]; //QK + unsigned int k000 = KQK; //000 + unsigned int kP00 = KQK; //P00 + unsigned int kM00 = neighborX[KQK]; //M00 + unsigned int k0P0 = KQK; //n + unsigned int k0M0 = neighborY[KQK]; //s + unsigned int k00P = KQK; //t + unsigned int k00M = neighborZ[KQK]; //b + unsigned int kMM0 = neighborY[kM00]; //sw + unsigned int kPP0 = KQK; //ne + unsigned int kPM0 = k0M0; //se + unsigned int kMP0 = kM00; //nw + unsigned int kM0M = neighborZ[kM00]; //bw + unsigned int kP0P = KQK; //te + unsigned int kP0M = k00M; //be + unsigned int k0PP = KQK; //tn + unsigned int k0MM = neighborZ[k0M0]; //bs + unsigned int kM0P = kM00; //tw + unsigned int k0PM = k00M; //bn + unsigned int k0MP = k0M0; //ts + unsigned int kPMP = k0M0; //tse + unsigned int kMPM = kM0M; //bnw + unsigned int kMPP = kM00; //tnw + unsigned int kPMM = k0MM; //bse + unsigned int kMMP = kMM0; //tsw + unsigned int kPPM = k00M; //bne + unsigned int kPPP = KQK; //tne + unsigned int kMMM = neighborZ[kMM0]; //bsw + + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // based on BGK Plus Comp + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + real f_M00 = (dist.f[DIR_P00])[kP00]; + real f_P00 = (dist.f[DIR_M00])[kM00]; + real f_0M0 = (dist.f[DIR_0P0])[k0P0]; + real f_0P0 = (dist.f[DIR_0M0])[k0M0]; + real f_00M = (dist.f[DIR_00P])[k00P]; + real f_00P = (dist.f[DIR_00M])[k00M]; + real f_MM0 = (dist.f[DIR_PP0])[kPP0]; + real f_PP0 = (dist.f[DIR_MM0])[kMM0]; + real f_MP0 = (dist.f[DIR_PM0])[kPM0]; + real f_PM0 = (dist.f[DIR_MP0])[kMP0]; + real f_M0M = (dist.f[DIR_P0P])[kP0P]; + real f_P0P = (dist.f[DIR_M0M])[kM0M]; + real f_M0P = (dist.f[DIR_P0M])[kP0M]; + real f_P0M = (dist.f[DIR_M0P])[kM0P]; + real f_0MM = (dist.f[DIR_0PP])[k0PP]; + real f_0PP = (dist.f[DIR_0MM])[k0MM]; + real f_0PM = (dist.f[DIR_0MP])[k0MP]; + real f_0MP = (dist.f[DIR_0PM])[k0PM]; + real f_000 = (dist.f[DIR_000])[k000]; + real f_MMM = (dist.f[DIR_PPP])[kPPP]; + real f_PPM = (dist.f[DIR_MMP])[kMMP]; + real f_MPM = (dist.f[DIR_PMP])[kPMP]; + real f_PMM = (dist.f[DIR_MPP])[kMPP]; + real f_MMP = (dist.f[DIR_PPM])[kPPM]; + real f_PPP = (dist.f[DIR_MMM])[kMMM]; + real f_MPP = (dist.f[DIR_PMM])[kPMM]; + real f_PMP = (dist.f[DIR_MPM])[kMPM]; + + //////////////////////////////////////////////////////////////////////////////// + //! - Set macroscopic quantities + //! + real drho = c0o1; + + real vx1 = VeloX; + + real vx2 = VeloY; + + real vx3 = VeloZ; + + real cusq = c3o2 * (vx1 * vx1 + vx2 * vx2 + vx3 * vx3); + + //////////////////////////////////////////////////////////////////////////////// + f_000 = c8o27* (drho-(drho+c1o1)*cusq); + f_P00 = c2o27* (drho+(drho+c1o1)*(c3o1*( vx1 )+c9o2*( vx1 )*( vx1 )-cusq)); + f_M00 = c2o27* (drho+(drho+c1o1)*(c3o1*(-vx1 )+c9o2*(-vx1 )*(-vx1 )-cusq)); + f_0P0 = c2o27* (drho+(drho+c1o1)*(c3o1*( vx2 )+c9o2*( vx2 )*( vx2 )-cusq)); + f_0M0 = c2o27* (drho+(drho+c1o1)*(c3o1*( -vx2 )+c9o2*( -vx2 )*( -vx2 )-cusq)); + f_00P = c2o27* (drho+(drho+c1o1)*(c3o1*( vx3)+c9o2*( vx3)*( vx3)-cusq)); + f_00M = c2o27* (drho+(drho+c1o1)*(c3o1*( -vx3)+c9o2*( -vx3)*( -vx3)-cusq)); + f_PP0 = c1o54* (drho+(drho+c1o1)*(c3o1*( vx1+vx2 )+c9o2*( vx1+vx2 )*( vx1+vx2 )-cusq)); + f_MM0 = c1o54* (drho+(drho+c1o1)*(c3o1*(-vx1-vx2 )+c9o2*(-vx1-vx2 )*(-vx1-vx2 )-cusq)); + f_PM0 = c1o54* (drho+(drho+c1o1)*(c3o1*( vx1-vx2 )+c9o2*( vx1-vx2 )*( vx1-vx2 )-cusq)); + f_MP0 = c1o54* (drho+(drho+c1o1)*(c3o1*(-vx1+vx2 )+c9o2*(-vx1+vx2 )*(-vx1+vx2 )-cusq)); + f_P0P = c1o54* (drho+(drho+c1o1)*(c3o1*( vx1 +vx3)+c9o2*( vx1 +vx3)*( vx1 +vx3)-cusq)); + f_M0M = c1o54* (drho+(drho+c1o1)*(c3o1*(-vx1 -vx3)+c9o2*(-vx1 -vx3)*(-vx1 -vx3)-cusq)); + f_P0M = c1o54* (drho+(drho+c1o1)*(c3o1*( vx1 -vx3)+c9o2*( vx1 -vx3)*( vx1 -vx3)-cusq)); + f_M0P = c1o54* (drho+(drho+c1o1)*(c3o1*(-vx1 +vx3)+c9o2*(-vx1 +vx3)*(-vx1 +vx3)-cusq)); + f_0PP = c1o54* (drho+(drho+c1o1)*(c3o1*( vx2+vx3)+c9o2*( vx2+vx3)*( vx2+vx3)-cusq)); + f_0MM = c1o54* (drho+(drho+c1o1)*(c3o1*( -vx2-vx3)+c9o2*( -vx2-vx3)*( -vx2-vx3)-cusq)); + f_0PM = c1o54* (drho+(drho+c1o1)*(c3o1*( vx2-vx3)+c9o2*( vx2-vx3)*( vx2-vx3)-cusq)); + f_0MP = c1o54* (drho+(drho+c1o1)*(c3o1*( -vx2+vx3)+c9o2*( -vx2+vx3)*( -vx2+vx3)-cusq)); + f_PPP = c1o216*(drho+(drho+c1o1)*(c3o1*( vx1+vx2+vx3)+c9o2*( vx1+vx2+vx3)*( vx1+vx2+vx3)-cusq)); + f_MMM = c1o216*(drho+(drho+c1o1)*(c3o1*(-vx1-vx2-vx3)+c9o2*(-vx1-vx2-vx3)*(-vx1-vx2-vx3)-cusq)); + f_PPM = c1o216*(drho+(drho+c1o1)*(c3o1*( vx1+vx2-vx3)+c9o2*( vx1+vx2-vx3)*( vx1+vx2-vx3)-cusq)); + f_MMP = c1o216*(drho+(drho+c1o1)*(c3o1*(-vx1-vx2+vx3)+c9o2*(-vx1-vx2+vx3)*(-vx1-vx2+vx3)-cusq)); + f_PMP = c1o216*(drho+(drho+c1o1)*(c3o1*( vx1-vx2+vx3)+c9o2*( vx1-vx2+vx3)*( vx1-vx2+vx3)-cusq)); + f_MPM = c1o216*(drho+(drho+c1o1)*(c3o1*(-vx1+vx2-vx3)+c9o2*(-vx1+vx2-vx3)*(-vx1+vx2-vx3)-cusq)); + f_PMM = c1o216*(drho+(drho+c1o1)*(c3o1*( vx1-vx2-vx3)+c9o2*( vx1-vx2-vx3)*( vx1-vx2-vx3)-cusq)); + f_MPP = c1o216*(drho+(drho+c1o1)*(c3o1*(-vx1+vx2+vx3)+c9o2*(-vx1+vx2+vx3)*(-vx1+vx2+vx3)-cusq)); + + //////////////////////////////////////////////////////////////////////////////// + //! write the new distributions to the bc nodes + //! + (dist.f[DIR_P00])[kP00] = f_M00; + (dist.f[DIR_PP0])[kPP0] = f_MM0; + (dist.f[DIR_P0M])[kP0M] = f_M0P; + (dist.f[DIR_PM0])[kPM0] = f_MP0; + (dist.f[DIR_PMP])[kPMP] = f_MPM; + (dist.f[DIR_P0P])[kP0P] = f_M0M; + (dist.f[DIR_PPM])[kPPM] = f_MMP; + (dist.f[DIR_PPP])[kPPP] = f_MMM; + (dist.f[DIR_PMM])[kPMM] = f_MPP; + + (dist.f[DIR_M00])[kM00] = f_P00; + (dist.f[DIR_MM0])[kMM0] = f_PP0; + (dist.f[DIR_M0M])[kM0M] = f_P0P; + (dist.f[DIR_MP0])[kMP0] = f_PM0; + (dist.f[DIR_M0P])[kM0P] = f_P0M; + (dist.f[DIR_MMM])[kMMM] = f_PPP; + (dist.f[DIR_MMP])[kMMP] = f_PPM; + (dist.f[DIR_MPP])[kMPP] = f_PMM; + (dist.f[DIR_MPM])[kMPM] = f_PMP; + + (dist.f[DIR_0P0])[k0P0] = f_0M0; + (dist.f[DIR_0M0])[k0M0] = f_0P0; + (dist.f[DIR_00P])[k00P] = f_00M; + (dist.f[DIR_00M])[k00M] = f_00P; + (dist.f[DIR_0PP])[k0PP] = f_0MM; + (dist.f[DIR_0MM])[k0MM] = f_0PP; + (dist.f[DIR_0PM])[k0PM] = f_0MP; + (dist.f[DIR_0MP])[k0MP] = f_0PM; + (dist.f[DIR_000])[k000] = f_000; +} +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + + +__global__ void PrecursorDeviceDistributions( int* subgridDistanceIndices, + int numberOfBCnodes, + int numberOfPrecursorNodes, + real* distributions, + uint* neighborX, + uint* neighborY, + uint* neighborZ, + uint* neighbors0PP, + uint* neighbors0PM, + uint* neighbors0MP, + uint* neighbors0MM, + real* weights0PP, + real* weights0PM, + real* weights0MP, + real* weights0MM, + real* fsLast, + real* fsNext, + real timeRatio, + unsigned long long numberOfLBnodes, + bool isEvenTimestep) +{ + const unsigned k = vf::gpu::getNodeIndex(); + + if(k>=numberOfBCnodes) return; + + uint kNeighbor0PP = neighbors0PP[k]; + real d0PP = weights0PP[k]; + + real f0LastInterp, f1LastInterp, f2LastInterp, f3LastInterp, f4LastInterp, f5LastInterp, f6LastInterp, f7LastInterp, f8LastInterp; + real f0NextInterp, f1NextInterp, f2NextInterp, f3NextInterp, f4NextInterp, f5NextInterp, f6NextInterp, f7NextInterp, f8NextInterp; + + real* f0Last = fsLast; + real* f1Last = &fsLast[ numberOfPrecursorNodes]; + real* f2Last = &fsLast[2*numberOfPrecursorNodes]; + real* f3Last = &fsLast[3*numberOfPrecursorNodes]; + real* f4Last = &fsLast[4*numberOfPrecursorNodes]; + real* f5Last = &fsLast[5*numberOfPrecursorNodes]; + real* f6Last = &fsLast[6*numberOfPrecursorNodes]; + real* f7Last = &fsLast[7*numberOfPrecursorNodes]; + real* f8Last = &fsLast[8*numberOfPrecursorNodes]; + + real* f0Next = fsNext; + real* f1Next = &fsNext[ numberOfPrecursorNodes]; + real* f2Next = &fsNext[2*numberOfPrecursorNodes]; + real* f3Next = &fsNext[3*numberOfPrecursorNodes]; + real* f4Next = &fsNext[4*numberOfPrecursorNodes]; + real* f5Next = &fsNext[5*numberOfPrecursorNodes]; + real* f6Next = &fsNext[6*numberOfPrecursorNodes]; + real* f7Next = &fsNext[7*numberOfPrecursorNodes]; + real* f8Next = &fsNext[8*numberOfPrecursorNodes]; + + + if(d0PP<1e6) + { + uint kNeighbor0PM = neighbors0PM[k]; + uint kNeighbor0MP = neighbors0MP[k]; + uint kNeighbor0MM = neighbors0MM[k]; + + real d0PM = weights0PM[k]; + real d0MP = weights0MP[k]; + real d0MM = weights0MM[k]; + + real invWeightSum = 1.f/(d0PP+d0PM+d0MP+d0MM); + + f0LastInterp = (f0Last[kNeighbor0PP]*d0PP + f0Last[kNeighbor0PM]*d0PM + f0Last[kNeighbor0MP]*d0MP + f0Last[kNeighbor0MM]*d0MM)*invWeightSum; + f0NextInterp = (f0Next[kNeighbor0PP]*d0PP + f0Next[kNeighbor0PM]*d0PM + f0Next[kNeighbor0MP]*d0MP + f0Next[kNeighbor0MM]*d0MM)*invWeightSum; + + f1LastInterp = (f1Last[kNeighbor0PP]*d0PP + f1Last[kNeighbor0PM]*d0PM + f1Last[kNeighbor0MP]*d0MP + f1Last[kNeighbor0MM]*d0MM)*invWeightSum; + f1NextInterp = (f1Next[kNeighbor0PP]*d0PP + f1Next[kNeighbor0PM]*d0PM + f1Next[kNeighbor0MP]*d0MP + f1Next[kNeighbor0MM]*d0MM)*invWeightSum; + + f2LastInterp = (f2Last[kNeighbor0PP]*d0PP + f2Last[kNeighbor0PM]*d0PM + f2Last[kNeighbor0MP]*d0MP + f2Last[kNeighbor0MM]*d0MM)*invWeightSum; + f2NextInterp = (f2Next[kNeighbor0PP]*d0PP + f2Next[kNeighbor0PM]*d0PM + f2Next[kNeighbor0MP]*d0MP + f2Next[kNeighbor0MM]*d0MM)*invWeightSum; + + f3LastInterp = (f3Last[kNeighbor0PP]*d0PP + f3Last[kNeighbor0PM]*d0PM + f3Last[kNeighbor0MP]*d0MP + f3Last[kNeighbor0MM]*d0MM)*invWeightSum; + f3NextInterp = (f3Next[kNeighbor0PP]*d0PP + f3Next[kNeighbor0PM]*d0PM + f3Next[kNeighbor0MP]*d0MP + f3Next[kNeighbor0MM]*d0MM)*invWeightSum; + + f4LastInterp = (f4Last[kNeighbor0PP]*d0PP + f4Last[kNeighbor0PM]*d0PM + f4Last[kNeighbor0MP]*d0MP + f4Last[kNeighbor0MM]*d0MM)*invWeightSum; + f4NextInterp = (f4Next[kNeighbor0PP]*d0PP + f4Next[kNeighbor0PM]*d0PM + f4Next[kNeighbor0MP]*d0MP + f4Next[kNeighbor0MM]*d0MM)*invWeightSum; + + f5LastInterp = (f5Last[kNeighbor0PP]*d0PP + f5Last[kNeighbor0PM]*d0PM + f5Last[kNeighbor0MP]*d0MP + f5Last[kNeighbor0MM]*d0MM)*invWeightSum; + f5NextInterp = (f5Next[kNeighbor0PP]*d0PP + f5Next[kNeighbor0PM]*d0PM + f5Next[kNeighbor0MP]*d0MP + f5Next[kNeighbor0MM]*d0MM)*invWeightSum; + + f6LastInterp = (f6Last[kNeighbor0PP]*d0PP + f6Last[kNeighbor0PM]*d0PM + f6Last[kNeighbor0MP]*d0MP + f6Last[kNeighbor0MM]*d0MM)*invWeightSum; + f6NextInterp = (f6Next[kNeighbor0PP]*d0PP + f6Next[kNeighbor0PM]*d0PM + f6Next[kNeighbor0MP]*d0MP + f6Next[kNeighbor0MM]*d0MM)*invWeightSum; + + f7LastInterp = (f7Last[kNeighbor0PP]*d0PP + f7Last[kNeighbor0PM]*d0PM + f7Last[kNeighbor0MP]*d0MP + f7Last[kNeighbor0MM]*d0MM)*invWeightSum; + f7NextInterp = (f7Next[kNeighbor0PP]*d0PP + f7Next[kNeighbor0PM]*d0PM + f7Next[kNeighbor0MP]*d0MP + f7Next[kNeighbor0MM]*d0MM)*invWeightSum; + + f8LastInterp = (f8Last[kNeighbor0PP]*d0PP + f8Last[kNeighbor0PM]*d0PM + f8Last[kNeighbor0MP]*d0MP + f8Last[kNeighbor0MM]*d0MM)*invWeightSum; + f8NextInterp = (f8Next[kNeighbor0PP]*d0PP + f8Next[kNeighbor0PM]*d0PM + f8Next[kNeighbor0MP]*d0MP + f8Next[kNeighbor0MM]*d0MM)*invWeightSum; + + } else { + f0LastInterp = f0Last[kNeighbor0PP]; + f1LastInterp = f1Last[kNeighbor0PP]; + f2LastInterp = f2Last[kNeighbor0PP]; + f3LastInterp = f3Last[kNeighbor0PP]; + f4LastInterp = f4Last[kNeighbor0PP]; + f5LastInterp = f5Last[kNeighbor0PP]; + f6LastInterp = f6Last[kNeighbor0PP]; + f7LastInterp = f7Last[kNeighbor0PP]; + f8LastInterp = f8Last[kNeighbor0PP]; + + f0NextInterp = f0Next[kNeighbor0PP]; + f1NextInterp = f1Next[kNeighbor0PP]; + f2NextInterp = f2Next[kNeighbor0PP]; + f3NextInterp = f3Next[kNeighbor0PP]; + f4NextInterp = f4Next[kNeighbor0PP]; + f5NextInterp = f5Next[kNeighbor0PP]; + f6NextInterp = f6Next[kNeighbor0PP]; + f7NextInterp = f7Next[kNeighbor0PP]; + f8NextInterp = f8Next[kNeighbor0PP]; + } + Distributions27 dist; + getPointersToDistributions(dist, distributions, numberOfLBnodes, !isEvenTimestep); + + unsigned int KQK = subgridDistanceIndices[k]; + // unsigned int k000= KQK; + unsigned int kP00 = KQK; + // unsigned int kM00 = neighborX[KQK]; + // unsigned int k0P0 = KQK; + unsigned int k0M0 = neighborY[KQK]; + // unsigned int k00P = KQK; + unsigned int k00M = neighborZ[KQK]; + // unsigned int kMM0 = neighborY[kM00]; + unsigned int kPP0 = KQK; + unsigned int kPM0 = k0M0; + // unsigned int kMP0 = kM00; + // unsigned int kM0M = neighborZ[kM00]; + unsigned int kP0P = KQK; + unsigned int kP0M = k00M; + // unsigned int kM0P = kM00; + unsigned int k0MM = neighborZ[k0M0]; + // unsigned int k0PM = k00M; + // unsigned int k0MP = k0M0; + unsigned int kPMP = k0M0; + // unsigned int kMPM = kM0M; + // unsigned int kMPP = kM00; + unsigned int kPMM = k0MM; + // unsigned int kMMP = kMM0; + unsigned int kPPM = k00M; + unsigned int kPPP = KQK; + // unsigned int kMMM = neighborZ[kMM0]; + + dist.f[DIR_P00][kP00] = f0LastInterp*(1.f-timeRatio) + f0NextInterp*timeRatio; + dist.f[DIR_PP0][kPP0] = f1LastInterp*(1.f-timeRatio) + f1NextInterp*timeRatio; + dist.f[DIR_PM0][kPM0] = f2LastInterp*(1.f-timeRatio) + f2NextInterp*timeRatio; + dist.f[DIR_P0P][kP0P] = f3LastInterp*(1.f-timeRatio) + f3NextInterp*timeRatio; + dist.f[DIR_P0M][kP0M] = f4LastInterp*(1.f-timeRatio) + f4NextInterp*timeRatio; + dist.f[DIR_PPP][kPPP] = f5LastInterp*(1.f-timeRatio) + f5NextInterp*timeRatio; + dist.f[DIR_PMP][kPMP] = f6LastInterp*(1.f-timeRatio) + f6NextInterp*timeRatio; + dist.f[DIR_PPM][kPPM] = f7LastInterp*(1.f-timeRatio) + f7NextInterp*timeRatio; + dist.f[DIR_PMM][kPMM] = f8LastInterp*(1.f-timeRatio) + f8NextInterp*timeRatio; +} +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +//NOTE: Has not been tested after bug fix! +__global__ void QPrecursorDeviceDistributions( int* subgridDistanceIndices, + real* subgridDistances, + int sizeQ, + int numberOfBCnodes, + int numberOfPrecursorNodes, + real* distributions, + uint* neighborX, + uint* neighborY, + uint* neighborZ, + uint* neighbors0PP, + uint* neighbors0PM, + uint* neighbors0MP, + uint* neighbors0MM, + real* weights0PP, + real* weights0PM, + real* weights0MP, + real* weights0MM, + real* fsLast, + real* fsNext, + real timeRatio, + unsigned long long numberOfLBnodes, + bool isEvenTimestep) +{ + const unsigned k = vf::gpu::getNodeIndex(); + + if(k>=numberOfBCnodes) return; + + uint kNeighbor0PP = neighbors0PP[k]; + real d0PP = weights0PP[k]; + + real f0LastInterp, f1LastInterp, f2LastInterp, f3LastInterp, f4LastInterp, f5LastInterp, f6LastInterp, f7LastInterp, f8LastInterp; + real f0NextInterp, f1NextInterp, f2NextInterp, f3NextInterp, f4NextInterp, f5NextInterp, f6NextInterp, f7NextInterp, f8NextInterp; + + real* f0Last = fsLast; + real* f1Last = &fsLast[ numberOfPrecursorNodes]; + real* f2Last = &fsLast[2*numberOfPrecursorNodes]; + real* f3Last = &fsLast[3*numberOfPrecursorNodes]; + real* f4Last = &fsLast[4*numberOfPrecursorNodes]; + real* f5Last = &fsLast[5*numberOfPrecursorNodes]; + real* f6Last = &fsLast[6*numberOfPrecursorNodes]; + real* f7Last = &fsLast[7*numberOfPrecursorNodes]; + real* f8Last = &fsLast[8*numberOfPrecursorNodes]; + + real* f0Next = fsNext; + real* f1Next = &fsNext[ numberOfPrecursorNodes]; + real* f2Next = &fsNext[2*numberOfPrecursorNodes]; + real* f3Next = &fsNext[3*numberOfPrecursorNodes]; + real* f4Next = &fsNext[4*numberOfPrecursorNodes]; + real* f5Next = &fsNext[5*numberOfPrecursorNodes]; + real* f6Next = &fsNext[6*numberOfPrecursorNodes]; + real* f7Next = &fsNext[7*numberOfPrecursorNodes]; + real* f8Next = &fsNext[8*numberOfPrecursorNodes]; + + + if(d0PP<1e6) + { + uint kNeighbor0PM = neighbors0PM[k]; + uint kNeighbor0MP = neighbors0MP[k]; + uint kNeighbor0MM = neighbors0MM[k]; + + real d0PM = weights0PM[k]; + real d0MP = weights0MP[k]; + real d0MM = weights0MM[k]; + + real invWeightSum = 1.f/(d0PP+d0PM+d0MP+d0MM); + + f0LastInterp = (f0Last[kNeighbor0PP]*d0PP + f0Last[kNeighbor0PM]*d0PM + f0Last[kNeighbor0MP]*d0MP + f0Last[kNeighbor0MM]*d0MM)*invWeightSum; + f0NextInterp = (f0Next[kNeighbor0PP]*d0PP + f0Next[kNeighbor0PM]*d0PM + f0Next[kNeighbor0MP]*d0MP + f0Next[kNeighbor0MM]*d0MM)*invWeightSum; + + f1LastInterp = (f1Last[kNeighbor0PP]*d0PP + f1Last[kNeighbor0PM]*d0PM + f1Last[kNeighbor0MP]*d0MP + f1Last[kNeighbor0MM]*d0MM)*invWeightSum; + f1NextInterp = (f1Next[kNeighbor0PP]*d0PP + f1Next[kNeighbor0PM]*d0PM + f1Next[kNeighbor0MP]*d0MP + f1Next[kNeighbor0MM]*d0MM)*invWeightSum; + + f2LastInterp = (f2Last[kNeighbor0PP]*d0PP + f2Last[kNeighbor0PM]*d0PM + f2Last[kNeighbor0MP]*d0MP + f2Last[kNeighbor0MM]*d0MM)*invWeightSum; + f2NextInterp = (f2Next[kNeighbor0PP]*d0PP + f2Next[kNeighbor0PM]*d0PM + f2Next[kNeighbor0MP]*d0MP + f2Next[kNeighbor0MM]*d0MM)*invWeightSum; + + f3LastInterp = (f3Last[kNeighbor0PP]*d0PP + f3Last[kNeighbor0PM]*d0PM + f3Last[kNeighbor0MP]*d0MP + f3Last[kNeighbor0MM]*d0MM)*invWeightSum; + f3NextInterp = (f3Next[kNeighbor0PP]*d0PP + f3Next[kNeighbor0PM]*d0PM + f3Next[kNeighbor0MP]*d0MP + f3Next[kNeighbor0MM]*d0MM)*invWeightSum; + + f4LastInterp = (f4Last[kNeighbor0PP]*d0PP + f4Last[kNeighbor0PM]*d0PM + f4Last[kNeighbor0MP]*d0MP + f4Last[kNeighbor0MM]*d0MM)*invWeightSum; + f4NextInterp = (f4Next[kNeighbor0PP]*d0PP + f4Next[kNeighbor0PM]*d0PM + f4Next[kNeighbor0MP]*d0MP + f4Next[kNeighbor0MM]*d0MM)*invWeightSum; + + f5LastInterp = (f5Last[kNeighbor0PP]*d0PP + f5Last[kNeighbor0PM]*d0PM + f5Last[kNeighbor0MP]*d0MP + f5Last[kNeighbor0MM]*d0MM)*invWeightSum; + f5NextInterp = (f5Next[kNeighbor0PP]*d0PP + f5Next[kNeighbor0PM]*d0PM + f5Next[kNeighbor0MP]*d0MP + f5Next[kNeighbor0MM]*d0MM)*invWeightSum; + + f6LastInterp = (f6Last[kNeighbor0PP]*d0PP + f6Last[kNeighbor0PM]*d0PM + f6Last[kNeighbor0MP]*d0MP + f6Last[kNeighbor0MM]*d0MM)*invWeightSum; + f6NextInterp = (f6Next[kNeighbor0PP]*d0PP + f6Next[kNeighbor0PM]*d0PM + f6Next[kNeighbor0MP]*d0MP + f6Next[kNeighbor0MM]*d0MM)*invWeightSum; + + f7LastInterp = (f7Last[kNeighbor0PP]*d0PP + f7Last[kNeighbor0PM]*d0PM + f7Last[kNeighbor0MP]*d0MP + f7Last[kNeighbor0MM]*d0MM)*invWeightSum; + f7NextInterp = (f7Next[kNeighbor0PP]*d0PP + f7Next[kNeighbor0PM]*d0PM + f7Next[kNeighbor0MP]*d0MP + f7Next[kNeighbor0MM]*d0MM)*invWeightSum; + + f8LastInterp = (f8Last[kNeighbor0PP]*d0PP + f8Last[kNeighbor0PM]*d0PM + f8Last[kNeighbor0MP]*d0MP + f8Last[kNeighbor0MM]*d0MM)*invWeightSum; + f8NextInterp = (f8Next[kNeighbor0PP]*d0PP + f8Next[kNeighbor0PM]*d0PM + f8Next[kNeighbor0MP]*d0MP + f8Next[kNeighbor0MM]*d0MM)*invWeightSum; + + } else { + f0LastInterp = f0Last[kNeighbor0PP]; + f1LastInterp = f1Last[kNeighbor0PP]; + f2LastInterp = f2Last[kNeighbor0PP]; + f3LastInterp = f3Last[kNeighbor0PP]; + f4LastInterp = f4Last[kNeighbor0PP]; + f5LastInterp = f5Last[kNeighbor0PP]; + f6LastInterp = f6Last[kNeighbor0PP]; + f7LastInterp = f7Last[kNeighbor0PP]; + f8LastInterp = f8Last[kNeighbor0PP]; + + f0NextInterp = f0Next[kNeighbor0PP]; + f1NextInterp = f1Next[kNeighbor0PP]; + f2NextInterp = f2Next[kNeighbor0PP]; + f3NextInterp = f3Next[kNeighbor0PP]; + f4NextInterp = f4Next[kNeighbor0PP]; + f5NextInterp = f5Next[kNeighbor0PP]; + f6NextInterp = f6Next[kNeighbor0PP]; + f7NextInterp = f7Next[kNeighbor0PP]; + f8NextInterp = f8Next[kNeighbor0PP]; + } + Distributions27 dist; + getPointersToDistributions(dist, distributions, numberOfLBnodes, !isEvenTimestep); + + unsigned int KQK = subgridDistanceIndices[k]; + // unsigned int k000= KQK; + unsigned int kP00 = KQK; + // unsigned int kM00 = neighborX[KQK]; + // unsigned int k0P0 = KQK; + unsigned int k0M0 = neighborY[KQK]; + // unsigned int k00P = KQK; + unsigned int k00M = neighborZ[KQK]; + // unsigned int kMM0 = neighborY[kM00]; + unsigned int kPP0 = KQK; + unsigned int kPM0 = k0M0; + // unsigned int kMP0 = kM00; + // unsigned int kM0M = neighborZ[kM00]; + unsigned int kP0P = KQK; + unsigned int kP0M = k00M; + // unsigned int kM0P = kM00; + unsigned int k0MM = neighborZ[k0M0]; + // unsigned int k0PM = k00M; + // unsigned int k0MP = k0M0; + unsigned int kPMP = k0M0; + // unsigned int kMPM = kM0M; + // unsigned int kMPP = kM00; + unsigned int kPMM = k0MM; + // unsigned int kMMP = kMM0; + unsigned int kPPM = k00M; + unsigned int kPPP = KQK; + // unsigned int kMMM = neighborZ[kMM0]; + SubgridDistances27 qs; + getPointersToSubgridDistances(qs, subgridDistances, sizeQ); + + real q; + q = qs.q[DIR_P00][k]; if(q>= c0o1 && q <= c1o1) dist.f[DIR_P00][kP00] = f0LastInterp*(1.f-timeRatio) + f0NextInterp*timeRatio; + q = qs.q[DIR_PP0][k]; if(q>= c0o1 && q <= c1o1) dist.f[DIR_PP0][kPP0] = f1LastInterp*(1.f-timeRatio) + f1NextInterp*timeRatio; + q = qs.q[DIR_PM0][k]; if(q>= c0o1 && q <= c1o1) dist.f[DIR_PM0][kPM0] = f2LastInterp*(1.f-timeRatio) + f2NextInterp*timeRatio; + q = qs.q[DIR_P0P][k]; if(q>= c0o1 && q <= c1o1) dist.f[DIR_P0P][kP0P] = f3LastInterp*(1.f-timeRatio) + f3NextInterp*timeRatio; + q = qs.q[DIR_P0M][k]; if(q>= c0o1 && q <= c1o1) dist.f[DIR_P0M][kP0M] = f4LastInterp*(1.f-timeRatio) + f4NextInterp*timeRatio; + q = qs.q[DIR_PPP][k]; if(q>= c0o1 && q <= c1o1) dist.f[DIR_PPP][kPPP] = f5LastInterp*(1.f-timeRatio) + f5NextInterp*timeRatio; + q = qs.q[DIR_PMP][k]; if(q>= c0o1 && q <= c1o1) dist.f[DIR_PMP][kPMP] = f6LastInterp*(1.f-timeRatio) + f6NextInterp*timeRatio; + q = qs.q[DIR_PPM][k]; if(q>= c0o1 && q <= c1o1) dist.f[DIR_PPM][kPPM] = f7LastInterp*(1.f-timeRatio) + f7NextInterp*timeRatio; + q = qs.q[DIR_PMM][k]; if(q>= c0o1 && q <= c1o1) dist.f[DIR_PMM][kPMM] = f8LastInterp*(1.f-timeRatio) + f8NextInterp*timeRatio; + +} +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/VirtualFluids_GPU/GPU/PressBCs27.cu b/src/gpu/VirtualFluids_GPU/GPU/PressBCs27.cu index ccb2ce79c63515e59e4f9ae75016f44ced71a170..6a14cebd465a1e79acf14ea019abb34e66d9c85f 100644 --- a/src/gpu/VirtualFluids_GPU/GPU/PressBCs27.cu +++ b/src/gpu/VirtualFluids_GPU/GPU/PressBCs27.cu @@ -2,6 +2,9 @@ #include "LBM/LB.h" #include "lbm/constants/D3Q27.h" #include "lbm/constants/NumericConstants.h" +#include "lbm/MacroscopicQuantities.h" +#include "Kernel/Utilities/DistributionHelper.cuh" + #include "KernelUtilities.h" using namespace vf::lbm::constant; @@ -2793,12 +2796,14 @@ __global__ void QPressDeviceDirDepBot27( real* rhoBC, - - +__host__ __device__ real computeOutflowDistribution(const real* const &f, const real* const &f1, const int dir, const real cs) +{ + return f1[dir] * cs + (c1o1 - cs) * f[dir]; +} //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -__global__ void QPressNoRhoDevice27( real* rhoBC, - real* DD, +__global__ void QPressNoRhoDevice27( real* rhoBC, + real* distributions, int* k_Q, int* k_N, int numberOfBCnodes, @@ -2806,483 +2811,419 @@ __global__ void QPressNoRhoDevice27( real* rhoBC, unsigned int* neighborX, unsigned int* neighborY, unsigned int* neighborZ, - unsigned int size_Mat, - bool isEvenTimestep) + unsigned int numberOfLBnodes, + bool isEvenTimestep, + int direction) { //////////////////////////////////////////////////////////////////////////////// - const unsigned x = threadIdx.x; // Globaler x-Index - const unsigned y = blockIdx.x; // Globaler y-Index - const unsigned z = blockIdx.y; // Globaler z-Index - const unsigned nx = blockDim.x; - const unsigned ny = gridDim.x; - const unsigned k = nx*(ny*z + y) + x; + const unsigned k = vf::gpu::getNodeIndex(); ////////////////////////////////////////////////////////////////////////// - if(k<numberOfBCnodes) - { - //////////////////////////////////////////////////////////////////////////////// - //index - unsigned int KQK = k_Q[k]; - //unsigned int kzero= KQK; - unsigned int ke = KQK; - unsigned int kw = neighborX[KQK]; - unsigned int kn = KQK; - unsigned int ks = neighborY[KQK]; - unsigned int kt = KQK; - unsigned int kb = neighborZ[KQK]; - unsigned int ksw = neighborY[kw]; - unsigned int kne = KQK; - unsigned int kse = ks; - unsigned int knw = kw; - unsigned int kbw = neighborZ[kw]; - unsigned int kte = KQK; - unsigned int kbe = kb; - unsigned int ktw = kw; - unsigned int kbs = neighborZ[ks]; - unsigned int ktn = KQK; - unsigned int kbn = kb; - unsigned int kts = ks; - unsigned int ktse = ks; - unsigned int kbnw = kbw; - unsigned int ktnw = kw; - unsigned int kbse = kbs; - unsigned int ktsw = ksw; - unsigned int kbne = kb; - unsigned int ktne = KQK; - unsigned int kbsw = neighborZ[ksw]; - //////////////////////////////////////////////////////////////////////////////// - //index1 - unsigned int K1QK = k_N[k]; - //unsigned int k1zero= K1QK; - unsigned int k1e = K1QK; - unsigned int k1w = neighborX[K1QK]; - unsigned int k1n = K1QK; - unsigned int k1s = neighborY[K1QK]; - unsigned int k1t = K1QK; - unsigned int k1b = neighborZ[K1QK]; - unsigned int k1sw = neighborY[k1w]; - unsigned int k1ne = K1QK; - unsigned int k1se = k1s; - unsigned int k1nw = k1w; - unsigned int k1bw = neighborZ[k1w]; - unsigned int k1te = K1QK; - unsigned int k1be = k1b; - unsigned int k1tw = k1w; - unsigned int k1bs = neighborZ[k1s]; - unsigned int k1tn = K1QK; - unsigned int k1bn = k1b; - unsigned int k1ts = k1s; - unsigned int k1tse = k1s; - unsigned int k1bnw = k1bw; - unsigned int k1tnw = k1w; - unsigned int k1bse = k1bs; - unsigned int k1tsw = k1sw; - unsigned int k1bne = k1b; - unsigned int k1tne = K1QK; - unsigned int k1bsw = neighborZ[k1sw]; - //////////////////////////////////////////////////////////////////////////////// - Distributions27 D; - if (isEvenTimestep==true) - { - D.f[DIR_P00 ] = &DD[DIR_P00 *size_Mat]; - D.f[DIR_M00 ] = &DD[DIR_M00 *size_Mat]; - D.f[DIR_0P0 ] = &DD[DIR_0P0 *size_Mat]; - D.f[DIR_0M0 ] = &DD[DIR_0M0 *size_Mat]; - D.f[DIR_00P ] = &DD[DIR_00P *size_Mat]; - D.f[DIR_00M ] = &DD[DIR_00M *size_Mat]; - D.f[DIR_PP0 ] = &DD[DIR_PP0 *size_Mat]; - D.f[DIR_MM0 ] = &DD[DIR_MM0 *size_Mat]; - D.f[DIR_PM0 ] = &DD[DIR_PM0 *size_Mat]; - D.f[DIR_MP0 ] = &DD[DIR_MP0 *size_Mat]; - D.f[DIR_P0P ] = &DD[DIR_P0P *size_Mat]; - D.f[DIR_M0M ] = &DD[DIR_M0M *size_Mat]; - D.f[DIR_P0M ] = &DD[DIR_P0M *size_Mat]; - D.f[DIR_M0P ] = &DD[DIR_M0P *size_Mat]; - D.f[DIR_0PP ] = &DD[DIR_0PP *size_Mat]; - D.f[DIR_0MM ] = &DD[DIR_0MM *size_Mat]; - D.f[DIR_0PM ] = &DD[DIR_0PM *size_Mat]; - D.f[DIR_0MP ] = &DD[DIR_0MP *size_Mat]; - D.f[DIR_000] = &DD[DIR_000*size_Mat]; - D.f[DIR_PPP ] = &DD[DIR_PPP *size_Mat]; - D.f[DIR_MMP ] = &DD[DIR_MMP *size_Mat]; - D.f[DIR_PMP ] = &DD[DIR_PMP *size_Mat]; - D.f[DIR_MPP ] = &DD[DIR_MPP *size_Mat]; - D.f[DIR_PPM ] = &DD[DIR_PPM *size_Mat]; - D.f[DIR_MMM ] = &DD[DIR_MMM *size_Mat]; - D.f[DIR_PMM ] = &DD[DIR_PMM *size_Mat]; - D.f[DIR_MPM ] = &DD[DIR_MPM *size_Mat]; - } - else - { - D.f[DIR_M00 ] = &DD[DIR_P00 *size_Mat]; - D.f[DIR_P00 ] = &DD[DIR_M00 *size_Mat]; - D.f[DIR_0M0 ] = &DD[DIR_0P0 *size_Mat]; - D.f[DIR_0P0 ] = &DD[DIR_0M0 *size_Mat]; - D.f[DIR_00M ] = &DD[DIR_00P *size_Mat]; - D.f[DIR_00P ] = &DD[DIR_00M *size_Mat]; - D.f[DIR_MM0 ] = &DD[DIR_PP0 *size_Mat]; - D.f[DIR_PP0 ] = &DD[DIR_MM0 *size_Mat]; - D.f[DIR_MP0 ] = &DD[DIR_PM0 *size_Mat]; - D.f[DIR_PM0 ] = &DD[DIR_MP0 *size_Mat]; - D.f[DIR_M0M ] = &DD[DIR_P0P *size_Mat]; - D.f[DIR_P0P ] = &DD[DIR_M0M *size_Mat]; - D.f[DIR_M0P ] = &DD[DIR_P0M *size_Mat]; - D.f[DIR_P0M ] = &DD[DIR_M0P *size_Mat]; - D.f[DIR_0MM ] = &DD[DIR_0PP *size_Mat]; - D.f[DIR_0PP ] = &DD[DIR_0MM *size_Mat]; - D.f[DIR_0MP ] = &DD[DIR_0PM *size_Mat]; - D.f[DIR_0PM ] = &DD[DIR_0MP *size_Mat]; - D.f[DIR_000] = &DD[DIR_000*size_Mat]; - D.f[DIR_PPP ] = &DD[DIR_MMM *size_Mat]; - D.f[DIR_MMP ] = &DD[DIR_PPM *size_Mat]; - D.f[DIR_PMP ] = &DD[DIR_MPM *size_Mat]; - D.f[DIR_MPP ] = &DD[DIR_PMM *size_Mat]; - D.f[DIR_PPM ] = &DD[DIR_MMP *size_Mat]; - D.f[DIR_MMM ] = &DD[DIR_PPP *size_Mat]; - D.f[DIR_PMM ] = &DD[DIR_MPP *size_Mat]; - D.f[DIR_MPM ] = &DD[DIR_PMP *size_Mat]; - } - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - real f1_E = (D.f[DIR_P00 ])[k1e ]; - real f1_W = (D.f[DIR_M00 ])[k1w ]; - real f1_N = (D.f[DIR_0P0 ])[k1n ]; - real f1_S = (D.f[DIR_0M0 ])[k1s ]; - real f1_T = (D.f[DIR_00P ])[k1t ]; - real f1_B = (D.f[DIR_00M ])[k1b ]; - real f1_NE = (D.f[DIR_PP0 ])[k1ne ]; - real f1_SW = (D.f[DIR_MM0 ])[k1sw ]; - real f1_SE = (D.f[DIR_PM0 ])[k1se ]; - real f1_NW = (D.f[DIR_MP0 ])[k1nw ]; - real f1_TE = (D.f[DIR_P0P ])[k1te ]; - real f1_BW = (D.f[DIR_M0M ])[k1bw ]; - real f1_BE = (D.f[DIR_P0M ])[k1be ]; - real f1_TW = (D.f[DIR_M0P ])[k1tw ]; - real f1_TN = (D.f[DIR_0PP ])[k1tn ]; - real f1_BS = (D.f[DIR_0MM ])[k1bs ]; - real f1_BN = (D.f[DIR_0PM ])[k1bn ]; - real f1_TS = (D.f[DIR_0MP ])[k1ts ]; - //real f1_ZERO = (D.f[DIR_000])[k1zero]; - real f1_TNE = (D.f[DIR_PPP ])[k1tne ]; - real f1_TSW = (D.f[DIR_MMP ])[k1tsw ]; - real f1_TSE = (D.f[DIR_PMP ])[k1tse ]; - real f1_TNW = (D.f[DIR_MPP ])[k1tnw ]; - real f1_BNE = (D.f[DIR_PPM ])[k1bne ]; - real f1_BSW = (D.f[DIR_MMM ])[k1bsw ]; - real f1_BSE = (D.f[DIR_PMM ])[k1bse ]; - real f1_BNW = (D.f[DIR_MPM ])[k1bnw ]; - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - real f_E = (D.f[DIR_P00 ])[ke ]; - real f_W = (D.f[DIR_M00 ])[kw ]; - real f_N = (D.f[DIR_0P0 ])[kn ]; - real f_S = (D.f[DIR_0M0 ])[ks ]; - real f_T = (D.f[DIR_00P ])[kt ]; - real f_B = (D.f[DIR_00M ])[kb ]; - real f_NE = (D.f[DIR_PP0 ])[kne ]; - real f_SW = (D.f[DIR_MM0 ])[ksw ]; - real f_SE = (D.f[DIR_PM0 ])[kse ]; - real f_NW = (D.f[DIR_MP0 ])[knw ]; - real f_TE = (D.f[DIR_P0P ])[kte ]; - real f_BW = (D.f[DIR_M0M ])[kbw ]; - real f_BE = (D.f[DIR_P0M ])[kbe ]; - real f_TW = (D.f[DIR_M0P ])[ktw ]; - real f_TN = (D.f[DIR_0PP ])[ktn ]; - real f_BS = (D.f[DIR_0MM ])[kbs ]; - real f_BN = (D.f[DIR_0PM ])[kbn ]; - real f_TS = (D.f[DIR_0MP ])[kts ]; - //real f_ZERO = (D.f[DIR_000])[kzero]; - real f_TNE = (D.f[DIR_PPP ])[ktne ]; - real f_TSW = (D.f[DIR_MMP ])[ktsw ]; - real f_TSE = (D.f[DIR_PMP ])[ktse ]; - real f_TNW = (D.f[DIR_MPP ])[ktnw ]; - real f_BNE = (D.f[DIR_PPM ])[kbne ]; - real f_BSW = (D.f[DIR_MMM ])[kbsw ]; - real f_BSE = (D.f[DIR_PMM ])[kbse ]; - real f_BNW = (D.f[DIR_MPM ])[kbnw ]; - ////////////////////////////////////////////////////////////////////////// - - //real vx1, vx2, vx3, drho; - //real vx1, vx2, vx3, drho, drho1; - ////////////////////////////////////////////////////////////////////////// - //Dichte - // drho1 = f1_TSE + f1_TNW + f1_TNE + f1_TSW + f1_BSE + f1_BNW + f1_BNE + f1_BSW + - // f1_BN + f1_TS + f1_TN + f1_BS + f1_BE + f1_TW + f1_TE + f1_BW + f1_SE + f1_NW + f1_NE + f1_SW + - // f1_T + f1_B + f1_N + f1_S + f1_E + f1_W + ((D.f[DIR_000])[k1zero]); - // drho = f_TSE + f_TNW + f_TNE + f_TSW + f_BSE + f_BNW + f_BNE + f_BSW + - // f_BN + f_TS + f_TN + f_BS + f_BE + f_TW + f_TE + f_BW + f_SE + f_NW + f_NE + f_SW + - // f_T + f_B + f_N + f_S + f_E + f_W + ((D.f[DIR_000])[kzero]); - - ////////////////////////////////////////////////////////////////////////// - //Ux - - //vx1 = (((f_TSE - f_BNW) - (f_TNW - f_BSE)) + ((f_TNE - f_BSW) - (f_TSW - f_BNE)) + - // ((f_BE - f_TW) + (f_TE - f_BW)) + ((f_SE - f_NW) + (f_NE - f_SW)) + - // (f_E - f_W)) /(one + drho); - - - // vx2 = ((-(f_TSE - f_BNW) + (f_TNW - f_BSE)) + ((f_TNE - f_BSW) - (f_TSW - f_BNE)) + - // ((f_BN - f_TS) + (f_TN - f_BS)) + (-(f_SE - f_NW) + (f_NE - f_SW)) + - // (f_N - f_S)) /(one + drho); - - // vx3 = (((f_TSE - f_BNW) + (f_TNW - f_BSE)) + ((f_TNE - f_BSW) + (f_TSW - f_BNE)) + - // (-(f_BN - f_TS) + (f_TN - f_BS)) + ((f_TE - f_BW) - (f_BE - f_TW)) + - // (f_T - f_B)) /(one + drho); + if(k>=numberOfBCnodes) return; + //////////////////////////////////////////////////////////////////////////////// + //index + unsigned int KQK = k_Q[k]; + // unsigned int kzero= KQK; + unsigned int ke = KQK; + unsigned int kw = neighborX[KQK]; + unsigned int kn = KQK; + unsigned int ks = neighborY[KQK]; + unsigned int kt = KQK; + unsigned int kb = neighborZ[KQK]; + unsigned int ksw = neighborY[kw]; + unsigned int kne = KQK; + unsigned int kse = ks; + unsigned int knw = kw; + unsigned int kbw = neighborZ[kw]; + unsigned int kte = KQK; + unsigned int kbe = kb; + unsigned int ktw = kw; + unsigned int kbs = neighborZ[ks]; + unsigned int ktn = KQK; + unsigned int kbn = kb; + unsigned int kts = ks; + unsigned int ktse = ks; + unsigned int kbnw = kbw; + unsigned int ktnw = kw; + unsigned int kbse = kbs; + unsigned int ktsw = ksw; + unsigned int kbne = kb; + unsigned int ktne = KQK; + unsigned int kbsw = neighborZ[ksw]; + //////////////////////////////////////////////////////////////////////////////// + //index1 + unsigned int K1QK = k_N[k]; + //unsigned int k1zero= K1QK; + unsigned int k1e = K1QK; + unsigned int k1w = neighborX[K1QK]; + unsigned int k1n = K1QK; + unsigned int k1s = neighborY[K1QK]; + unsigned int k1t = K1QK; + unsigned int k1b = neighborZ[K1QK]; + unsigned int k1sw = neighborY[k1w]; + unsigned int k1ne = K1QK; + unsigned int k1se = k1s; + unsigned int k1nw = k1w; + unsigned int k1bw = neighborZ[k1w]; + unsigned int k1te = K1QK; + unsigned int k1be = k1b; + unsigned int k1tw = k1w; + unsigned int k1bs = neighborZ[k1s]; + unsigned int k1tn = K1QK; + unsigned int k1bn = k1b; + unsigned int k1ts = k1s; + unsigned int k1tse = k1s; + unsigned int k1bnw = k1bw; + unsigned int k1tnw = k1w; + unsigned int k1bse = k1bs; + unsigned int k1tsw = k1sw; + unsigned int k1bne = k1b; + unsigned int k1tne = K1QK; + unsigned int k1bsw = neighborZ[k1sw]; + //////////////////////////////////////////////////////////////////////////////// + Distributions27 dist; + getPointersToDistributions(dist, distributions, numberOfLBnodes, isEvenTimestep); + real f[27], f1[27]; + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + f1[DIR_P00] = (dist.f[DIR_P00])[k1e ]; + f1[DIR_M00] = (dist.f[DIR_M00])[k1w ]; + f1[DIR_0P0] = (dist.f[DIR_0P0])[k1n ]; + f1[DIR_0M0] = (dist.f[DIR_0M0])[k1s ]; + f1[DIR_00P] = (dist.f[DIR_00P])[k1t ]; + f1[DIR_00M] = (dist.f[DIR_00M])[k1b ]; + f1[DIR_PP0] = (dist.f[DIR_PP0])[k1ne ]; + f1[DIR_MM0] = (dist.f[DIR_MM0])[k1sw ]; + f1[DIR_PM0] = (dist.f[DIR_PM0])[k1se ]; + f1[DIR_MP0] = (dist.f[DIR_MP0])[k1nw ]; + f1[DIR_P0P] = (dist.f[DIR_P0P])[k1te ]; + f1[DIR_M0M] = (dist.f[DIR_M0M])[k1bw ]; + f1[DIR_P0M] = (dist.f[DIR_P0M])[k1be ]; + f1[DIR_M0P] = (dist.f[DIR_M0P])[k1tw ]; + f1[DIR_0PP] = (dist.f[DIR_0PP])[k1tn ]; + f1[DIR_0MM] = (dist.f[DIR_0MM])[k1bs ]; + f1[DIR_0PM] = (dist.f[DIR_0PM])[k1bn ]; + f1[DIR_0MP] = (dist.f[DIR_0MP])[k1ts ]; + // f1[DIR_000] = (dist.f[DIR_000])[k1zero]; + f1[DIR_PPP] = (dist.f[DIR_PPP])[k1tne ]; + f1[DIR_MMP] = (dist.f[DIR_MMP])[k1tsw ]; + f1[DIR_PMP] = (dist.f[DIR_PMP])[k1tse ]; + f1[DIR_MPP] = (dist.f[DIR_MPP])[k1tnw ]; + f1[DIR_PPM] = (dist.f[DIR_PPM])[k1bne ]; + f1[DIR_MMM] = (dist.f[DIR_MMM])[k1bsw ]; + f1[DIR_PMM] = (dist.f[DIR_PMM])[k1bse ]; + f1[DIR_MPM] = (dist.f[DIR_MPM])[k1bnw ]; + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + f[DIR_P00] = (dist.f[DIR_P00])[ke ]; + f[DIR_M00] = (dist.f[DIR_M00])[kw ]; + f[DIR_0P0] = (dist.f[DIR_0P0])[kn ]; + f[DIR_0M0] = (dist.f[DIR_0M0])[ks ]; + f[DIR_00P] = (dist.f[DIR_00P])[kt ]; + f[DIR_00M] = (dist.f[DIR_00M])[kb ]; + f[DIR_PP0] = (dist.f[DIR_PP0])[kne ]; + f[DIR_MM0] = (dist.f[DIR_MM0])[ksw ]; + f[DIR_PM0] = (dist.f[DIR_PM0])[kse ]; + f[DIR_MP0] = (dist.f[DIR_MP0])[knw ]; + f[DIR_P0P] = (dist.f[DIR_P0P])[kte ]; + f[DIR_M0M] = (dist.f[DIR_M0M])[kbw ]; + f[DIR_P0M] = (dist.f[DIR_P0M])[kbe ]; + f[DIR_M0P] = (dist.f[DIR_M0P])[ktw ]; + f[DIR_0PP] = (dist.f[DIR_0PP])[ktn ]; + f[DIR_0MM] = (dist.f[DIR_0MM])[kbs ]; + f[DIR_0PM] = (dist.f[DIR_0PM])[kbn ]; + f[DIR_0MP] = (dist.f[DIR_0MP])[kts ]; + // f[DIR_000] = (dist.f[DIR_000])[kzero]; + f[DIR_PPP] = (dist.f[DIR_PPP])[ktne ]; + f[DIR_MMP] = (dist.f[DIR_MMP])[ktsw ]; + f[DIR_PMP] = (dist.f[DIR_PMP])[ktse ]; + f[DIR_MPP] = (dist.f[DIR_MPP])[ktnw ]; + f[DIR_PPM] = (dist.f[DIR_PPM])[kbne ]; + f[DIR_MMM] = (dist.f[DIR_MMM])[kbsw ]; + f[DIR_PMM] = (dist.f[DIR_PMM])[kbse ]; + f[DIR_MPM] = (dist.f[DIR_MPM])[kbnw ]; + ////////////////////////////////////////////////////////////////////////// - //real cu_sq=c3o2*(vx1*vx1+vx2*vx2+vx3*vx3); - // ////////////////////////////////////////////////////////////////////////// - ////real omega = om1; - // real cusq = c3o2*(vx1*vx1+vx2*vx2+vx3*vx3); - // ////////////////////////////////////////////////////////////////////////// - ////T�st MK - ////if(vx1 < zero) vx1 = zero; - // ////////////////////////////////////////////////////////////////////////// - // real fZERO = c8over27* (drho1-(one + drho1)*(cusq)) ; - // real fE = c2over27* (drho1+(one + drho1)*(three*( vx1 )+c9over2*( vx1 )*( vx1 )-cusq)); - // real fW = c2over27* (drho1+(one + drho1)*(three*(-vx1 )+c9over2*(-vx1 )*(-vx1 )-cusq)); - // real fN = c2over27* (drho1+(one + drho1)*(three*( vx2 )+c9over2*( vx2 )*( vx2 )-cusq)); - // real fS = c2over27* (drho1+(one + drho1)*(three*( -vx2 )+c9over2*( -vx2 )*( -vx2 )-cusq)); - // real fT = c2over27* (drho1+(one + drho1)*(three*( vx3)+c9over2*( vx3)*( vx3)-cusq)); - // real fB = c2over27* (drho1+(one + drho1)*(three*( -vx3)+c9over2*( -vx3)*( -vx3)-cusq)); - // real fNE = c1over54* (drho1+(one + drho1)*(three*( vx1+vx2 )+c9over2*( vx1+vx2 )*( vx1+vx2 )-cusq)); - // real fSW = c1over54* (drho1+(one + drho1)*(three*(-vx1-vx2 )+c9over2*(-vx1-vx2 )*(-vx1-vx2 )-cusq)); - // real fSE = c1over54* (drho1+(one + drho1)*(three*( vx1-vx2 )+c9over2*( vx1-vx2 )*( vx1-vx2 )-cusq)); - // real fNW = c1over54* (drho1+(one + drho1)*(three*(-vx1+vx2 )+c9over2*(-vx1+vx2 )*(-vx1+vx2 )-cusq)); - // real fTE = c1over54* (drho1+(one + drho1)*(three*( vx1 +vx3)+c9over2*( vx1 +vx3)*( vx1 +vx3)-cusq)); - // real fBW = c1over54* (drho1+(one + drho1)*(three*(-vx1 -vx3)+c9over2*(-vx1 -vx3)*(-vx1 -vx3)-cusq)); - // real fBE = c1over54* (drho1+(one + drho1)*(three*( vx1 -vx3)+c9over2*( vx1 -vx3)*( vx1 -vx3)-cusq)); - // real fTW = c1over54* (drho1+(one + drho1)*(three*(-vx1 +vx3)+c9over2*(-vx1 +vx3)*(-vx1 +vx3)-cusq)); - // real fTN = c1over54* (drho1+(one + drho1)*(three*( vx2+vx3)+c9over2*( vx2+vx3)*( vx2+vx3)-cusq)); - // real fBS = c1over54* (drho1+(one + drho1)*(three*( -vx2-vx3)+c9over2*( -vx2-vx3)*( -vx2-vx3)-cusq)); - // real fBN = c1over54* (drho1+(one + drho1)*(three*( vx2-vx3)+c9over2*( vx2-vx3)*( vx2-vx3)-cusq)); - // real fTS = c1over54* (drho1+(one + drho1)*(three*( -vx2+vx3)+c9over2*( -vx2+vx3)*( -vx2+vx3)-cusq)); - // real fTNE = c1over216* (drho1+(one + drho1)*(three*( vx1+vx2+vx3)+c9over2*( vx1+vx2+vx3)*( vx1+vx2+vx3)-cusq)); - // real fBSW = c1over216* (drho1+(one + drho1)*(three*(-vx1-vx2-vx3)+c9over2*(-vx1-vx2-vx3)*(-vx1-vx2-vx3)-cusq)); - // real fBNE = c1over216* (drho1+(one + drho1)*(three*( vx1+vx2-vx3)+c9over2*( vx1+vx2-vx3)*( vx1+vx2-vx3)-cusq)); - // real fTSW = c1over216* (drho1+(one + drho1)*(three*(-vx1-vx2+vx3)+c9over2*(-vx1-vx2+vx3)*(-vx1-vx2+vx3)-cusq)); - // real fTSE = c1over216* (drho1+(one + drho1)*(three*( vx1-vx2+vx3)+c9over2*( vx1-vx2+vx3)*( vx1-vx2+vx3)-cusq)); - // real fBNW = c1over216* (drho1+(one + drho1)*(three*(-vx1+vx2-vx3)+c9over2*(-vx1+vx2-vx3)*(-vx1+vx2-vx3)-cusq)); - // real fBSE = c1over216* (drho1+(one + drho1)*(three*( vx1-vx2-vx3)+c9over2*( vx1-vx2-vx3)*( vx1-vx2-vx3)-cusq)); - // real fTNW = c1over216* (drho1+(one + drho1)*(three*(-vx1+vx2+vx3)+c9over2*(-vx1+vx2+vx3)*(-vx1+vx2+vx3)-cusq)); + real cs = c1o1 / sqrtf(c3o1); - real cs = c1o1 / sqrtf(c3o1); - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //no velocity - ////////////////////////////////////////// - f_E = f1_E * cs + (c1o1 - cs) * f_E ; - f_W = f1_W * cs + (c1o1 - cs) * f_W ; - f_N = f1_N * cs + (c1o1 - cs) * f_N ; - f_S = f1_S * cs + (c1o1 - cs) * f_S ; - f_T = f1_T * cs + (c1o1 - cs) * f_T ; - f_B = f1_B * cs + (c1o1 - cs) * f_B ; - f_NE = f1_NE * cs + (c1o1 - cs) * f_NE ; - f_SW = f1_SW * cs + (c1o1 - cs) * f_SW ; - f_SE = f1_SE * cs + (c1o1 - cs) * f_SE ; - f_NW = f1_NW * cs + (c1o1 - cs) * f_NW ; - f_TE = f1_TE * cs + (c1o1 - cs) * f_TE ; - f_BW = f1_BW * cs + (c1o1 - cs) * f_BW ; - f_BE = f1_BE * cs + (c1o1 - cs) * f_BE ; - f_TW = f1_TW * cs + (c1o1 - cs) * f_TW ; - f_TN = f1_TN * cs + (c1o1 - cs) * f_TN ; - f_BS = f1_BS * cs + (c1o1 - cs) * f_BS ; - f_BN = f1_BN * cs + (c1o1 - cs) * f_BN ; - f_TS = f1_TS * cs + (c1o1 - cs) * f_TS ; - f_TNE = f1_TNE * cs + (c1o1 - cs) * f_TNE ; - f_TSW = f1_TSW * cs + (c1o1 - cs) * f_TSW ; - f_TSE = f1_TSE * cs + (c1o1 - cs) * f_TSE ; - f_TNW = f1_TNW * cs + (c1o1 - cs) * f_TNW ; - f_BNE = f1_BNE * cs + (c1o1 - cs) * f_BNE ; - f_BSW = f1_BSW * cs + (c1o1 - cs) * f_BSW ; - f_BSE = f1_BSE * cs + (c1o1 - cs) * f_BSE ; - f_BNW = f1_BNW * cs + (c1o1 - cs) * f_BNW ; - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //with velocity - //if(true){//vx1 >= zero){ - // real csMvx = one / sqrtf(three) - vx1; - // //real csMvy = one / sqrtf(three) - vx2; - // /////////////////////////////////////////// - // // X - // f_W = f1_W * csMvx + (one - csMvx) * f_W ;//- c2over27 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx1); - // f_NW = f1_NW * csMvx + (one - csMvx) * f_NW ;//- c1over54 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx1); - // f_SW = f1_SW * csMvx + (one - csMvx) * f_SW ;//- c1over54 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx1); - // f_TW = f1_TW * csMvx + (one - csMvx) * f_TW ;//- c1over54 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx1); - // f_BW = f1_BW * csMvx + (one - csMvx) * f_BW ;//- c1over54 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx1); - // f_TNW = f1_TNW * csMvx + (one - csMvx) * f_TNW ;//- c1over216 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx1); - // f_TSW = f1_TSW * csMvx + (one - csMvx) * f_TSW ;//- c1over216 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx1); - // f_BNW = f1_BNW * csMvx + (one - csMvx) * f_BNW ;//- c1over216 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx1); - // f_BSW = f1_BSW * csMvx + (one - csMvx) * f_BSW ;//- c1over216 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx1); - // /////////////////////////////////////////// - // // Y - // //f_S = f1_S * csMvy + (one - csMvy) * f_S ;//- c2over27 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx2); - // //f_SE = f1_SE * csMvy + (one - csMvy) * f_SE ;//- c1over54 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx2); - // //f_SW = f1_SW * csMvy + (one - csMvy) * f_SW ;//- c1over54 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx2); - // //f_TS = f1_TS * csMvy + (one - csMvy) * f_TS ;//- c1over54 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx2); - // //f_BS = f1_BS * csMvy + (one - csMvy) * f_BS ;//- c1over54 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx2); - // //f_TSE = f1_TSE * csMvy + (one - csMvy) * f_TSE ;//- c1over216 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx2); - // //f_TSW = f1_TSW * csMvy + (one - csMvy) * f_TSW ;//- c1over216 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx2); - // //f_BSE = f1_BSE * csMvy + (one - csMvy) * f_BSE ;//- c1over216 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx2); - // //f_BSW = f1_BSW * csMvy + (one - csMvy) * f_BSW ;//- c1over216 * ((drho + drho1)*c1o2-((drho + drho1)*c1o2 )*three*vx2); - // //f_S = f1_S * csMvy + (one - csMvy) * f_S; - // //f_SE = f1_SE * csMvy + (one - csMvy) * f_SE; - // //f_SW = f1_SW * csMvy + (one - csMvy) * f_SW; - // //f_TS = f1_TS * csMvy + (one - csMvy) * f_TS; - // //f_BS = f1_BS * csMvy + (one - csMvy) * f_BS; - // //f_TSE = f1_TSE * csMvy + (one - csMvy) * f_TSE; - // //f_TSW = f1_TSW * csMvy + (one - csMvy) * f_TSW; - // //f_BSE = f1_BSE * csMvy + (one - csMvy) * f_BSE; - // //f_BSW = f1_BSW * csMvy + (one - csMvy) * f_BSW; - // ////////////////////////////////////////////////////////////////////////// - //} - //else - //{ - // /////////////////////////////////////////// - // // X - // vx1 = vx1 * 0.9; - // f_W = f_E - six * c2over27 * ( vx1 ); - // f_NW = f_SE - six * c1over54 * ( vx1-vx2 ); - // f_SW = f_NE - six * c1over54 * ( vx1+vx2 ); - // f_TW = f_BE - six * c1over54 * ( vx1 -vx3); - // f_BW = f_TE - six * c1over54 * ( vx1 +vx3); - // f_TNW = f_BSE - six * c1over216 * ( vx1-vx2-vx3); - // f_TSW = f_BNE - six * c1over216 * ( vx1+vx2-vx3); - // f_BNW = f_TSE - six * c1over216 * ( vx1-vx2+vx3); - // f_BSW = f_TNE - six * c1over216 * ( vx1+vx2+vx3); - // /////////////////////////////////////////// - // // Y - // //vx2 = vx2 * 0.9; - // //f_S = f_N - six * c2over27 * ( vx2 ); - // //f_SE = f_NW - six * c1over54 * (-vx1+vx2 ); - // //f_SW = f_NE - six * c1over54 * ( vx1+vx2 ); - // //f_TS = f_BN - six * c1over54 * ( vx2-vx3); - // //f_BS = f_TN - six * c1over54 * ( vx2+vx3); - // //f_TSE = f_BNW - six * c1over216 * (-vx1+vx2-vx3); - // //f_TSW = f_BNE - six * c1over216 * ( vx1+vx2-vx3); - // //f_BSE = f_TNW - six * c1over216 * (-vx1+vx2+vx3); - // //f_BSW = f_TNE - six * c1over216 * ( vx1+vx2+vx3); - // /////////////////////////////////////////// - //} - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////// - if (isEvenTimestep==false) - { - D.f[DIR_P00 ] = &DD[DIR_P00 *size_Mat]; - D.f[DIR_M00 ] = &DD[DIR_M00 *size_Mat]; - D.f[DIR_0P0 ] = &DD[DIR_0P0 *size_Mat]; - D.f[DIR_0M0 ] = &DD[DIR_0M0 *size_Mat]; - D.f[DIR_00P ] = &DD[DIR_00P *size_Mat]; - D.f[DIR_00M ] = &DD[DIR_00M *size_Mat]; - D.f[DIR_PP0 ] = &DD[DIR_PP0 *size_Mat]; - D.f[DIR_MM0 ] = &DD[DIR_MM0 *size_Mat]; - D.f[DIR_PM0 ] = &DD[DIR_PM0 *size_Mat]; - D.f[DIR_MP0 ] = &DD[DIR_MP0 *size_Mat]; - D.f[DIR_P0P ] = &DD[DIR_P0P *size_Mat]; - D.f[DIR_M0M ] = &DD[DIR_M0M *size_Mat]; - D.f[DIR_P0M ] = &DD[DIR_P0M *size_Mat]; - D.f[DIR_M0P ] = &DD[DIR_M0P *size_Mat]; - D.f[DIR_0PP ] = &DD[DIR_0PP *size_Mat]; - D.f[DIR_0MM ] = &DD[DIR_0MM *size_Mat]; - D.f[DIR_0PM ] = &DD[DIR_0PM *size_Mat]; - D.f[DIR_0MP ] = &DD[DIR_0MP *size_Mat]; - D.f[DIR_000] = &DD[DIR_000*size_Mat]; - D.f[DIR_PPP ] = &DD[DIR_PPP *size_Mat]; - D.f[DIR_MMP ] = &DD[DIR_MMP *size_Mat]; - D.f[DIR_PMP ] = &DD[DIR_PMP *size_Mat]; - D.f[DIR_MPP ] = &DD[DIR_MPP *size_Mat]; - D.f[DIR_PPM ] = &DD[DIR_PPM *size_Mat]; - D.f[DIR_MMM ] = &DD[DIR_MMM *size_Mat]; - D.f[DIR_PMM ] = &DD[DIR_PMM *size_Mat]; - D.f[DIR_MPM ] = &DD[DIR_MPM *size_Mat]; - } - else - { - D.f[DIR_M00 ] = &DD[DIR_P00 *size_Mat]; - D.f[DIR_P00 ] = &DD[DIR_M00 *size_Mat]; - D.f[DIR_0M0 ] = &DD[DIR_0P0 *size_Mat]; - D.f[DIR_0P0 ] = &DD[DIR_0M0 *size_Mat]; - D.f[DIR_00M ] = &DD[DIR_00P *size_Mat]; - D.f[DIR_00P ] = &DD[DIR_00M *size_Mat]; - D.f[DIR_MM0 ] = &DD[DIR_PP0 *size_Mat]; - D.f[DIR_PP0 ] = &DD[DIR_MM0 *size_Mat]; - D.f[DIR_MP0 ] = &DD[DIR_PM0 *size_Mat]; - D.f[DIR_PM0 ] = &DD[DIR_MP0 *size_Mat]; - D.f[DIR_M0M ] = &DD[DIR_P0P *size_Mat]; - D.f[DIR_P0P ] = &DD[DIR_M0M *size_Mat]; - D.f[DIR_M0P ] = &DD[DIR_P0M *size_Mat]; - D.f[DIR_P0M ] = &DD[DIR_M0P *size_Mat]; - D.f[DIR_0MM ] = &DD[DIR_0PP *size_Mat]; - D.f[DIR_0PP ] = &DD[DIR_0MM *size_Mat]; - D.f[DIR_0MP ] = &DD[DIR_0PM *size_Mat]; - D.f[DIR_0PM ] = &DD[DIR_0MP *size_Mat]; - D.f[DIR_000] = &DD[DIR_000*size_Mat]; - D.f[DIR_PPP ] = &DD[DIR_MMM *size_Mat]; - D.f[DIR_MMP ] = &DD[DIR_PPM *size_Mat]; - D.f[DIR_PMP ] = &DD[DIR_MPM *size_Mat]; - D.f[DIR_MPP ] = &DD[DIR_PMM *size_Mat]; - D.f[DIR_PPM ] = &DD[DIR_MMP *size_Mat]; - D.f[DIR_MMM ] = &DD[DIR_PPP *size_Mat]; - D.f[DIR_PMM ] = &DD[DIR_MPP *size_Mat]; - D.f[DIR_MPM ] = &DD[DIR_PMP *size_Mat]; - } - ////////////////////////////////////////////////////////////////////////// - //__syncthreads(); - // -X - //(D.f[DIR_P00 ])[ke ] = f_E ; - //(D.f[DIR_PM0 ])[kse ] = f_SE ; - //(D.f[DIR_PP0 ])[kne ] = f_NE ; - //(D.f[DIR_P0M ])[kbe ] = f_BE ; - //(D.f[DIR_P0P ])[kte ] = f_TE ; - //(D.f[DIR_PMP ])[ktse ] = f_TSE ; - //(D.f[DIR_PPP ])[ktne ] = f_TNE ; - //(D.f[DIR_PMM ])[kbse ] = f_BSE ; - //(D.f[DIR_PPM ])[kbne ] = f_BNE ; - // X - (D.f[DIR_M00 ])[kw ] = f_W ; - (D.f[DIR_MM0 ])[ksw ] = f_SW ; - (D.f[DIR_MP0 ])[knw ] = f_NW ; - (D.f[DIR_M0M ])[kbw ] = f_BW ; - (D.f[DIR_M0P ])[ktw ] = f_TW ; - (D.f[DIR_MMP ])[ktsw ] = f_TSW ; - (D.f[DIR_MPP ])[ktnw ] = f_TNW ; - (D.f[DIR_MMM ])[kbsw ] = f_BSW ; - (D.f[DIR_MPM ])[kbnw ] = f_BNW ; - // Y - //(D.f[DIR_0M0 ])[ks ] = f_S ; - //(D.f[DIR_PM0 ])[kse ] = f_SE ; - //(D.f[DIR_MM0 ])[ksw ] = f_SW ; - //(D.f[DIR_0MP ])[kts ] = f_TS ; - //(D.f[DIR_0MM ])[kbs ] = f_BS ; - //(D.f[DIR_PMP ])[ktse ] = f_TSE ; - //(D.f[DIR_MMP ])[ktsw ] = f_TSW ; - //(D.f[DIR_PMM ])[kbse ] = f_BSE ; - //(D.f[DIR_MMM ])[kbsw ] = f_BSW ; - // Z - //(D.f[DIR_00M ])[kb ] = f_B ; - //(D.f[DIR_P0M ])[kbe ] = f_BE ; - //(D.f[DIR_M0M ])[kbw ] = f_BW ; - //(D.f[DIR_0PM ])[kbn ] = f_BN ; - //(D.f[DIR_0MM ])[kbs ] = f_BS ; - //(D.f[DIR_PPM ])[kbne ] = f_BNE ; - //(D.f[DIR_MPM ])[kbnw ] = f_BNW ; - //(D.f[DIR_PMM ])[kbse ] = f_BSE ; - //(D.f[DIR_MMM ])[kbsw ] = f_BSW ; - ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + getPointersToDistributions(dist, distributions, numberOfLBnodes, !isEvenTimestep); + switch(direction) + { + case MZZ: + (dist.f[DIR_P00])[ke ] = computeOutflowDistribution(f, f1, DIR_P00, cs); + (dist.f[DIR_PM0])[kse ] = computeOutflowDistribution(f, f1, DIR_PM0, cs); + (dist.f[DIR_PP0])[kne ] = computeOutflowDistribution(f, f1, DIR_PP0, cs); + (dist.f[DIR_P0M])[kbe ] = computeOutflowDistribution(f, f1, DIR_P0M, cs); + (dist.f[DIR_P0P])[kte ] = computeOutflowDistribution(f, f1, DIR_P0P, cs); + (dist.f[DIR_PMP])[ktse ] = computeOutflowDistribution(f, f1, DIR_PMP, cs); + (dist.f[DIR_PPP])[ktne ] = computeOutflowDistribution(f, f1, DIR_PPP, cs); + (dist.f[DIR_PMM])[kbse ] = computeOutflowDistribution(f, f1, DIR_PMM, cs); + (dist.f[DIR_PPM])[kbne ] = computeOutflowDistribution(f, f1, DIR_PPM, cs); + break; + + case PZZ: + (dist.f[DIR_M00])[kw ] = computeOutflowDistribution(f, f1, DIR_M00, cs); + (dist.f[DIR_MM0])[ksw ] = computeOutflowDistribution(f, f1, DIR_MM0, cs); + (dist.f[DIR_MP0])[knw ] = computeOutflowDistribution(f, f1, DIR_MP0, cs); + (dist.f[DIR_M0M])[kbw ] = computeOutflowDistribution(f, f1, DIR_M0M, cs); + (dist.f[DIR_M0P])[ktw ] = computeOutflowDistribution(f, f1, DIR_M0P, cs); + (dist.f[DIR_MMP])[ktsw ] = computeOutflowDistribution(f, f1, DIR_MMP, cs); + (dist.f[DIR_MPP])[ktnw ] = computeOutflowDistribution(f, f1, DIR_MPP, cs); + (dist.f[DIR_MMM])[kbsw ] = computeOutflowDistribution(f, f1, DIR_MMM, cs); + (dist.f[DIR_MPM])[kbnw ] = computeOutflowDistribution(f, f1, DIR_MPM, cs); + break; + + case ZMZ: + (dist.f[DIR_0P0])[kn ] = computeOutflowDistribution(f, f1, DIR_0P0, cs); + (dist.f[DIR_PP0])[kne ] = computeOutflowDistribution(f, f1, DIR_PP0, cs); + (dist.f[DIR_MP0])[knw ] = computeOutflowDistribution(f, f1, DIR_MP0, cs); + (dist.f[DIR_0PP])[ktn ] = computeOutflowDistribution(f, f1, DIR_0PP, cs); + (dist.f[DIR_0PM])[kbn ] = computeOutflowDistribution(f, f1, DIR_0PM, cs); + (dist.f[DIR_PPP])[ktne ] = computeOutflowDistribution(f, f1, DIR_PPP, cs); + (dist.f[DIR_MPP])[ktnw ] = computeOutflowDistribution(f, f1, DIR_MPP, cs); + (dist.f[DIR_PPM])[kbne ] = computeOutflowDistribution(f, f1, DIR_PPM, cs); + (dist.f[DIR_MPM])[kbnw ] = computeOutflowDistribution(f, f1, DIR_MPM, cs); + break; + + case ZPZ: + (dist.f[DIR_0M0])[ks ] = computeOutflowDistribution(f, f1, DIR_0M0, cs); + (dist.f[DIR_PM0])[kse ] = computeOutflowDistribution(f, f1, DIR_PM0, cs); + (dist.f[DIR_MM0])[ksw ] = computeOutflowDistribution(f, f1, DIR_MM0, cs); + (dist.f[DIR_0MP])[kts ] = computeOutflowDistribution(f, f1, DIR_0MP, cs); + (dist.f[DIR_0MM])[kbs ] = computeOutflowDistribution(f, f1, DIR_0MM, cs); + (dist.f[DIR_PMP])[ktse ] = computeOutflowDistribution(f, f1, DIR_PMP, cs); + (dist.f[DIR_MMP])[ktsw ] = computeOutflowDistribution(f, f1, DIR_MMP, cs); + (dist.f[DIR_PMM])[kbse ] = computeOutflowDistribution(f, f1, DIR_PMM, cs); + (dist.f[DIR_MMM])[kbsw ] = computeOutflowDistribution(f, f1, DIR_MMM, cs); + break; + + case ZZM: + (dist.f[DIR_00P])[kt ] = computeOutflowDistribution(f, f1, DIR_00P, cs); + (dist.f[DIR_P0P])[kte ] = computeOutflowDistribution(f, f1, DIR_P0P, cs); + (dist.f[DIR_M0P])[ktw ] = computeOutflowDistribution(f, f1, DIR_M0P, cs); + (dist.f[DIR_0PP])[ktn ] = computeOutflowDistribution(f, f1, DIR_0PP, cs); + (dist.f[DIR_0MP])[kts ] = computeOutflowDistribution(f, f1, DIR_0MP, cs); + (dist.f[DIR_PPP])[ktne ] = computeOutflowDistribution(f, f1, DIR_PPP, cs); + (dist.f[DIR_MPP])[ktnw ] = computeOutflowDistribution(f, f1, DIR_MPP, cs); + (dist.f[DIR_PMP])[ktse ] = computeOutflowDistribution(f, f1, DIR_PMP, cs); + (dist.f[DIR_MMP])[ktsw ] = computeOutflowDistribution(f, f1, DIR_MMP, cs); + break; + + case ZZP: + (dist.f[DIR_00M])[kb ] = computeOutflowDistribution(f, f1, DIR_00M, cs); + (dist.f[DIR_P0M])[kbe ] = computeOutflowDistribution(f, f1, DIR_P0M, cs); + (dist.f[DIR_M0M])[kbw ] = computeOutflowDistribution(f, f1, DIR_M0M, cs); + (dist.f[DIR_0PM])[kbn ] = computeOutflowDistribution(f, f1, DIR_0PM, cs); + (dist.f[DIR_0MM])[kbs ] = computeOutflowDistribution(f, f1, DIR_0MM, cs); + (dist.f[DIR_PPM])[kbne ] = computeOutflowDistribution(f, f1, DIR_PPM, cs); + (dist.f[DIR_MPM])[kbnw ] = computeOutflowDistribution(f, f1, DIR_MPM, cs); + (dist.f[DIR_PMM])[kbse ] = computeOutflowDistribution(f, f1, DIR_PMM, cs); + (dist.f[DIR_MMM])[kbsw ] = computeOutflowDistribution(f, f1, DIR_MMM, cs); + break; + default: + break; } } -//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +__host__ __device__ real computeOutflowDistribution(const real* const &f, const real* const &f1, const int dir, const real rhoCorrection, const real cs, const real weight) +{ + return f1[dir ] * cs + (c1o1 - cs) * f[dir ] - weight *rhoCorrection; +} +__global__ void QPressZeroRhoOutflowDevice27( real* rhoBC, + real* distributions, + int* k_Q, + int* k_N, + int numberOfBCnodes, + real om1, + unsigned int* neighborX, + unsigned int* neighborY, + unsigned int* neighborZ, + unsigned int numberOfLBnodes, + bool isEvenTimestep, + int direction, + real densityCorrectionFactor) +{ + //////////////////////////////////////////////////////////////////////////////// + const unsigned k = vf::gpu::getNodeIndex(); + + ////////////////////////////////////////////////////////////////////////// + if(k>=numberOfBCnodes) return; + //////////////////////////////////////////////////////////////////////////////// + //index + uint k_000 = k_Q[k]; + uint k_M00 = neighborX[k_000]; + uint k_0M0 = neighborY[k_000]; + uint k_00M = neighborZ[k_000]; + uint k_MM0 = neighborY[k_M00]; + uint k_M0M = neighborZ[k_M00]; + uint k_0MM = neighborZ[k_0M0]; + uint k_MMM = neighborZ[k_MM0]; + //////////////////////////////////////////////////////////////////////////////// + //index of neighbor + uint kN_000 = k_N[k]; + uint kN_M00 = neighborX[k_000]; + uint kN_0M0 = neighborY[k_000]; + uint kN_00M = neighborZ[k_000]; + uint kN_MM0 = neighborY[k_M00]; + uint kN_M0M = neighborZ[k_M00]; + uint kN_0MM = neighborZ[k_0M0]; + uint kN_MMM = neighborZ[k_MM0]; + //////////////////////////////////////////////////////////////////////////////// + Distributions27 dist; + getPointersToDistributions(dist, distributions, numberOfLBnodes, isEvenTimestep); + real f[27], fN[27]; + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + f[DIR_000] = (dist.f[DIR_000])[k_000]; + f[DIR_P00] = (dist.f[DIR_P00])[k_000]; + f[DIR_M00] = (dist.f[DIR_M00])[k_M00]; + f[DIR_0P0] = (dist.f[DIR_0P0])[k_000]; + f[DIR_0M0] = (dist.f[DIR_0M0])[k_0M0]; + f[DIR_00P] = (dist.f[DIR_00P])[k_000]; + f[DIR_00M] = (dist.f[DIR_00M])[k_00M]; + f[DIR_PP0] = (dist.f[DIR_PP0])[k_000]; + f[DIR_MM0] = (dist.f[DIR_MM0])[k_MM0]; + f[DIR_PM0] = (dist.f[DIR_PM0])[k_0M0]; + f[DIR_MP0] = (dist.f[DIR_MP0])[k_M00]; + f[DIR_P0P] = (dist.f[DIR_P0P])[k_000]; + f[DIR_M0M] = (dist.f[DIR_M0M])[k_M0M]; + f[DIR_P0M] = (dist.f[DIR_P0M])[k_00M]; + f[DIR_M0P] = (dist.f[DIR_M0P])[k_M00]; + f[DIR_0PP] = (dist.f[DIR_0PP])[k_000]; + f[DIR_0MM] = (dist.f[DIR_0MM])[k_0MM]; + f[DIR_0PM] = (dist.f[DIR_0PM])[k_00M]; + f[DIR_0MP] = (dist.f[DIR_0MP])[k_0M0]; + f[DIR_PPP] = (dist.f[DIR_PPP])[k_000]; + f[DIR_MPP] = (dist.f[DIR_MPP])[k_M00]; + f[DIR_PMP] = (dist.f[DIR_PMP])[k_0M0]; + f[DIR_MMP] = (dist.f[DIR_MMP])[k_MM0]; + f[DIR_PPM] = (dist.f[DIR_PPM])[k_00M]; + f[DIR_MPM] = (dist.f[DIR_MPM])[k_M0M]; + f[DIR_PMM] = (dist.f[DIR_PMM])[k_0MM]; + f[DIR_MMM] = (dist.f[DIR_MMM])[k_MMM]; + ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + fN[DIR_000] = (dist.f[DIR_000])[kN_000]; + fN[DIR_P00] = (dist.f[DIR_P00])[kN_000]; + fN[DIR_M00] = (dist.f[DIR_M00])[kN_M00]; + fN[DIR_0P0] = (dist.f[DIR_0P0])[kN_000]; + fN[DIR_0M0] = (dist.f[DIR_0M0])[kN_0M0]; + fN[DIR_00P] = (dist.f[DIR_00P])[kN_000]; + fN[DIR_00M] = (dist.f[DIR_00M])[kN_00M]; + fN[DIR_PP0] = (dist.f[DIR_PP0])[kN_000]; + fN[DIR_MM0] = (dist.f[DIR_MM0])[kN_MM0]; + fN[DIR_PM0] = (dist.f[DIR_PM0])[kN_0M0]; + fN[DIR_MP0] = (dist.f[DIR_MP0])[kN_M00]; + fN[DIR_P0P] = (dist.f[DIR_P0P])[kN_000]; + fN[DIR_M0M] = (dist.f[DIR_M0M])[kN_M0M]; + fN[DIR_P0M] = (dist.f[DIR_P0M])[kN_00M]; + fN[DIR_M0P] = (dist.f[DIR_M0P])[kN_M00]; + fN[DIR_0PP] = (dist.f[DIR_0PP])[kN_000]; + fN[DIR_0MM] = (dist.f[DIR_0MM])[kN_0MM]; + fN[DIR_0PM] = (dist.f[DIR_0PM])[kN_00M]; + fN[DIR_0MP] = (dist.f[DIR_0MP])[kN_0M0]; + fN[DIR_PPP] = (dist.f[DIR_PPP])[kN_000]; + fN[DIR_MPP] = (dist.f[DIR_MPP])[kN_M00]; + fN[DIR_PMP] = (dist.f[DIR_PMP])[kN_0M0]; + fN[DIR_MMP] = (dist.f[DIR_MMP])[kN_MM0]; + fN[DIR_PPM] = (dist.f[DIR_PPM])[kN_00M]; + fN[DIR_MPM] = (dist.f[DIR_MPM])[kN_M0M]; + fN[DIR_PMM] = (dist.f[DIR_PMM])[kN_0MM]; + fN[DIR_MMM] = (dist.f[DIR_MMM])[kN_MMM]; + ////////////////////////////////////////////////////////////////////////// + real drho = vf::lbm::getDensity(f); + + real rhoCorrection = densityCorrectionFactor*drho; + + real cs = c1o1 / sqrtf(c3o1); + getPointersToDistributions(dist, distributions, numberOfLBnodes, !isEvenTimestep); + switch(direction) + { + case MZZ: + (dist.f[DIR_P00])[k_000] = computeOutflowDistribution(f, fN, DIR_P00 , rhoCorrection, cs, c2o27); + (dist.f[DIR_PM0])[k_0M0] = computeOutflowDistribution(f, fN, DIR_PM0, rhoCorrection, cs, c1o54); + (dist.f[DIR_PP0])[k_000] = computeOutflowDistribution(f, fN, DIR_PP0, rhoCorrection, cs, c1o54); + (dist.f[DIR_P0M])[k_00M] = computeOutflowDistribution(f, fN, DIR_P0M, rhoCorrection, cs, c1o54); + (dist.f[DIR_P0P])[k_000] = computeOutflowDistribution(f, fN, DIR_P0P, rhoCorrection, cs, c1o54); + (dist.f[DIR_PMP])[k_0M0] = computeOutflowDistribution(f, fN, DIR_PMP, rhoCorrection, cs, c1o216); + (dist.f[DIR_PPP])[k_000] = computeOutflowDistribution(f, fN, DIR_PPP, rhoCorrection, cs, c1o216); + (dist.f[DIR_PMM])[k_0MM] = computeOutflowDistribution(f, fN, DIR_PMM, rhoCorrection, cs, c1o216); + (dist.f[DIR_PPM])[k_00M] = computeOutflowDistribution(f, fN, DIR_PPM, rhoCorrection, cs, c1o216); + break; + + case PZZ: + (dist.f[DIR_M00])[k_M00] = computeOutflowDistribution(f, fN, DIR_M00, rhoCorrection, cs, c2o27); + (dist.f[DIR_MM0])[k_MM0] = computeOutflowDistribution(f, fN, DIR_MM0, rhoCorrection, cs, c1o54); + (dist.f[DIR_MP0])[k_M00] = computeOutflowDistribution(f, fN, DIR_MP0, rhoCorrection, cs, c1o54); + (dist.f[DIR_M0M])[k_M0M] = computeOutflowDistribution(f, fN, DIR_M0M, rhoCorrection, cs, c1o54); + (dist.f[DIR_M0P])[k_M00] = computeOutflowDistribution(f, fN, DIR_M0P, rhoCorrection, cs, c1o54); + (dist.f[DIR_MMP])[k_MM0] = computeOutflowDistribution(f, fN, DIR_MMP, rhoCorrection, cs, c1o216); + (dist.f[DIR_MPP])[k_M00] = computeOutflowDistribution(f, fN, DIR_MPP, rhoCorrection, cs, c1o216); + (dist.f[DIR_MMM])[k_MMM] = computeOutflowDistribution(f, fN, DIR_MMM, rhoCorrection, cs, c1o216); + (dist.f[DIR_MPM])[k_M0M] = computeOutflowDistribution(f, fN, DIR_MPM, rhoCorrection, cs, c1o216); + break; + + case ZMZ: + (dist.f[DIR_0P0])[k_000] = computeOutflowDistribution(f, fN, DIR_0P0, rhoCorrection, cs, c2o27); + (dist.f[DIR_PP0])[k_000] = computeOutflowDistribution(f, fN, DIR_PP0, rhoCorrection, cs, c1o54); + (dist.f[DIR_MP0])[k_M00] = computeOutflowDistribution(f, fN, DIR_MP0, rhoCorrection, cs, c1o54); + (dist.f[DIR_0PP])[k_000] = computeOutflowDistribution(f, fN, DIR_0PP, rhoCorrection, cs, c1o54); + (dist.f[DIR_0PM])[k_00M] = computeOutflowDistribution(f, fN, DIR_0PM, rhoCorrection, cs, c1o54); + (dist.f[DIR_PPP])[k_000] = computeOutflowDistribution(f, fN, DIR_PPP, rhoCorrection, cs, c1o216); + (dist.f[DIR_MPP])[k_M00] = computeOutflowDistribution(f, fN, DIR_MPP, rhoCorrection, cs, c1o216); + (dist.f[DIR_PPM])[k_00M] = computeOutflowDistribution(f, fN, DIR_PPM, rhoCorrection, cs, c1o216); + (dist.f[DIR_MPM])[k_M0M] = computeOutflowDistribution(f, fN, DIR_MPM, rhoCorrection, cs, c1o216); + break; + + case ZPZ: + (dist.f[DIR_0M0])[k_0M0] =computeOutflowDistribution(f, fN, DIR_0M0, rhoCorrection, cs, c2o27); + (dist.f[DIR_PM0])[k_0M0] =computeOutflowDistribution(f, fN, DIR_PM0, rhoCorrection, cs, c1o54); + (dist.f[DIR_MM0])[k_MM0] =computeOutflowDistribution(f, fN, DIR_MM0, rhoCorrection, cs, c1o54); + (dist.f[DIR_0MP])[k_0M0] =computeOutflowDistribution(f, fN, DIR_0MP, rhoCorrection, cs, c1o54); + (dist.f[DIR_0MM])[k_0MM] =computeOutflowDistribution(f, fN, DIR_0MM, rhoCorrection, cs, c1o54); + (dist.f[DIR_PMP])[k_0M0] =computeOutflowDistribution(f, fN, DIR_PMP, rhoCorrection, cs, c1o216); + (dist.f[DIR_MMP])[k_MM0] =computeOutflowDistribution(f, fN, DIR_MMP, rhoCorrection, cs, c1o216); + (dist.f[DIR_PMM])[k_0MM] =computeOutflowDistribution(f, fN, DIR_PMM, rhoCorrection, cs, c1o216); + (dist.f[DIR_MMM])[k_MMM] =computeOutflowDistribution(f, fN, DIR_MMM, rhoCorrection, cs, c1o216); + break; + + case ZZM: + (dist.f[DIR_00P])[k_000] = computeOutflowDistribution(f, fN, DIR_00P, rhoCorrection, cs, c2o27); + (dist.f[DIR_P0P])[k_000] = computeOutflowDistribution(f, fN, DIR_P0P, rhoCorrection, cs, c1o54); + (dist.f[DIR_M0P])[k_M00] = computeOutflowDistribution(f, fN, DIR_M0P, rhoCorrection, cs, c1o54); + (dist.f[DIR_0PP])[k_000] = computeOutflowDistribution(f, fN, DIR_0PP, rhoCorrection, cs, c1o54); + (dist.f[DIR_0MP])[k_0M0] = computeOutflowDistribution(f, fN, DIR_0MP, rhoCorrection, cs, c1o54); + (dist.f[DIR_PPP])[k_000] = computeOutflowDistribution(f, fN, DIR_PPP, rhoCorrection, cs, c1o216); + (dist.f[DIR_MPP])[k_M00] = computeOutflowDistribution(f, fN, DIR_MPP, rhoCorrection, cs, c1o216); + (dist.f[DIR_PMP])[k_0M0] = computeOutflowDistribution(f, fN, DIR_PMP, rhoCorrection, cs, c1o216); + (dist.f[DIR_MMP])[k_MM0] = computeOutflowDistribution(f, fN, DIR_MMP, rhoCorrection, cs, c1o216); + break; + + case ZZP: + (dist.f[DIR_00M])[k_00M] = computeOutflowDistribution(f, fN, DIR_00M, rhoCorrection, cs, c2o27); + (dist.f[DIR_P0M])[k_00M] = computeOutflowDistribution(f, fN, DIR_P0M, rhoCorrection, cs, c1o54); + (dist.f[DIR_M0M])[k_M0M] = computeOutflowDistribution(f, fN, DIR_M0M, rhoCorrection, cs, c1o54); + (dist.f[DIR_0PM])[k_00M] = computeOutflowDistribution(f, fN, DIR_0PM, rhoCorrection, cs, c1o54); + (dist.f[DIR_0MM])[k_0MM] = computeOutflowDistribution(f, fN, DIR_0MM, rhoCorrection, cs, c1o54); + (dist.f[DIR_PPM])[k_00M] = computeOutflowDistribution(f, fN, DIR_PPM, rhoCorrection, cs, c1o216); + (dist.f[DIR_MPM])[k_M0M] = computeOutflowDistribution(f, fN, DIR_MPM, rhoCorrection, cs, c1o216); + (dist.f[DIR_PMM])[k_0MM] = computeOutflowDistribution(f, fN, DIR_PMM, rhoCorrection, cs, c1o216); + (dist.f[DIR_MMM])[k_MMM] = computeOutflowDistribution(f, fN, DIR_MMM, rhoCorrection, cs, c1o216); + break; + default: + break; + } +} +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/VirtualFluids_GPU/GPU/TurbulentViscosityInlines.cuh b/src/gpu/VirtualFluids_GPU/GPU/TurbulentViscosityInlines.cuh index eb301515527a9e8a3056676b0d4dffe8197c7dbe..58856f624fa1dfd2488c3061721e9dac53a67d07 100644 --- a/src/gpu/VirtualFluids_GPU/GPU/TurbulentViscosityInlines.cuh +++ b/src/gpu/VirtualFluids_GPU/GPU/TurbulentViscosityInlines.cuh @@ -53,8 +53,8 @@ __inline__ __device__ real calcTurbulentViscosityQR(real C, real dxux, real dyuy //! Second invariant of the strain-rate tensor real Q = c1o2*( dxux*dxux + dyuy*dyuy + dzuz*dzuz ) + c1o4*( Dxy*Dxy + Dxz*Dxz + Dyz*Dyz); //! Third invariant of the strain-rate tensor (determinant) - real R = - dxux*dyuy*dzuz - c1o4*( Dxy*Dxz*Dyz + dxux*Dyz*Dyz + dyuy*Dxz*Dxz + dzuz*Dxy*Dxy ); - + // real R = - dxux*dyuy*dzuz - c1o4*( Dxy*Dxz*Dyz + dxux*Dyz*Dyz + dyuy*Dxz*Dxz + dzuz*Dxy*Dxy ); + real R = - dxux*dyuy*dzuz + c1o4*( -Dxy*Dxz*Dyz + dxux*Dyz*Dyz + dyuy*Dxz*Dxz + dzuz*Dxy*Dxy ); return C * max(R, c0o1) / Q; } diff --git a/src/gpu/VirtualFluids_GPU/GPU/TurbulentViscosityKernels.cu b/src/gpu/VirtualFluids_GPU/GPU/TurbulentViscosityKernels.cu index 3719ca3712e6f63a77f62bf314af7d19eea01f4c..a8f02fee717caf7f67624243b873fe993b5c7927 100644 --- a/src/gpu/VirtualFluids_GPU/GPU/TurbulentViscosityKernels.cu +++ b/src/gpu/VirtualFluids_GPU/GPU/TurbulentViscosityKernels.cu @@ -38,6 +38,7 @@ #include <cuda_runtime.h> #include <helper_cuda.h> #include "LBM/LB.h" +#include "Kernel/Utilities/DistributionHelper.cuh" using namespace vf::lbm::constant; @@ -64,15 +65,7 @@ __global__ void calcAMD(real* vx, uint size_Mat, real SGSConstant) { - - const uint x = threadIdx.x; - const uint y = blockIdx.x; - const uint z = blockIdx.y; - - const uint nx = blockDim.x; - const uint ny = gridDim.x; - - const uint k = nx*(ny*z + y) + x; + const uint k = vf::gpu::getNodeIndex(); if(k >= size_Mat) return; if(typeOfGridNode[k] != GEO_FLUID) return; @@ -102,7 +95,7 @@ __global__ void calcAMD(real* vx, (dvxdx*dvzdx + dvxdy*dvzdy + dvxdz*dvzdz) * (dvxdz+dvzdx) + (dvydx*dvzdx + dvydy*dvzdy + dvydz*dvzdz) * (dvydz+dvzdy); - turbulentViscosity[k] = max(c0o1,-SGSConstant*enumerator)/denominator; + turbulentViscosity[k] = denominator != c0o1 ? max(c0o1,-SGSConstant*enumerator)/denominator : c0o1; } void calcTurbulentViscosityAMD(Parameter* para, int level) diff --git a/src/gpu/VirtualFluids_GPU/Init/PositionReader.cpp b/src/gpu/VirtualFluids_GPU/Init/PositionReader.cpp index 4e5a862d3fd1ed19109073aae0fe4c731f7f3e91..04052b38cbfb59bfe620354b62da70402d74bdbd 100644 --- a/src/gpu/VirtualFluids_GPU/Init/PositionReader.cpp +++ b/src/gpu/VirtualFluids_GPU/Init/PositionReader.cpp @@ -3,6 +3,7 @@ #include "Parameter/Parameter.h" #include <basics/utilities/UbFileInputASCII.h> + using namespace vf::lbm::dir; ////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernel.h b/src/gpu/VirtualFluids_GPU/Kernel/Kernel.h index 9f9f7539bc5a1e28612d956ca32234c5a3589f8a..50b4460d774010ea7d7b98cfa6fa505cdfeb88c2 100644 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernel.h +++ b/src/gpu/VirtualFluids_GPU/Kernel/Kernel.h @@ -3,8 +3,11 @@ #include <vector> +#include "LBM/LB.h" + #include "Kernel/Utilities/KernelGroup.h" #include "PreProcessor/PreProcessorType.h" +#include "Parameter/CudaStreamManager.h" #include <helper_cuda.h> @@ -13,7 +16,7 @@ class Kernel public: virtual ~Kernel() = default; virtual void run() = 0; - virtual void runOnIndices(const unsigned int *indices, unsigned int size_indices, int stream = -1) = 0; //if stream == -1: run on default stream + virtual void runOnIndices(const unsigned int *indices, unsigned int size_indices, CollisionTemplate collisionTemplate, CudaStreamIndex streamIdx=CudaStreamIndex::Legacy) = 0; virtual bool checkParameter() = 0; virtual std::vector<PreProcessorType> getPreProcessorTypes() = 0; diff --git a/src/gpu/VirtualFluids_GPU/Kernel/KernelImp.cpp b/src/gpu/VirtualFluids_GPU/Kernel/KernelImp.cpp index 630aaf7339afc2907ab6bfbf65bd5fc55f75e215..9bd3945aa81147d03be2b1eac3ddec7c24d71532 100644 --- a/src/gpu/VirtualFluids_GPU/Kernel/KernelImp.cpp +++ b/src/gpu/VirtualFluids_GPU/Kernel/KernelImp.cpp @@ -1,9 +1,11 @@ #include "KernelImp.h" +#include "LBM/LB.h" + #include "Kernel/Utilities/CheckParameterStrategy/CheckParameterStrategy.h" -void KernelImp::runOnIndices(const unsigned int *indices, unsigned int size_indices, int stream) +void KernelImp::runOnIndices(const unsigned int *indices, unsigned int size_indices, CollisionTemplate collisionTemplate, CudaStreamIndex streamIndex) { printf("Method not implemented for this Kernel \n"); } diff --git a/src/gpu/VirtualFluids_GPU/Kernel/KernelImp.h b/src/gpu/VirtualFluids_GPU/Kernel/KernelImp.h index 0141ddda7e9579cc84148d26727ed81c084ea0c5..a96c2c123472ca33f635273e06a5bf36a745654d 100644 --- a/src/gpu/VirtualFluids_GPU/Kernel/KernelImp.h +++ b/src/gpu/VirtualFluids_GPU/Kernel/KernelImp.h @@ -1,6 +1,8 @@ #ifndef KERNEL_IMP_H #define KERNEL_IMP_H +#include "LBM/LB.h" + #include "Kernel.h" #include <memory> @@ -9,12 +11,12 @@ class CheckParameterStrategy; class Parameter; - +class CudaStreamManager; class KernelImp : public Kernel { public: virtual void run() = 0; - virtual void runOnIndices(const unsigned int *indices, unsigned int size_indices, int stream = -1); + virtual void runOnIndices(const unsigned int *indices, unsigned int size_indices, CollisionTemplate collisionTemplate, CudaStreamIndex streamIndex=CudaStreamIndex::Legacy); bool checkParameter(); std::vector<PreProcessorType> getPreProcessorTypes(); diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17.cu b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17.cu new file mode 100644 index 0000000000000000000000000000000000000000..70b0c4352afee850a4e17243979268bd126b7b4a --- /dev/null +++ b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17.cu @@ -0,0 +1,140 @@ +#include "CumulantK17.h" +#include <logger/Logger.h> +#include "Parameter/Parameter.h" +#include "Parameter/CudaStreamManager.h" +#include "CumulantK17_Device.cuh" + +#include <cuda.h> + +template<TurbulenceModel turbulenceModel> +std::shared_ptr< CumulantK17<turbulenceModel> > CumulantK17<turbulenceModel>::getNewInstance(std::shared_ptr<Parameter> para, int level) +{ + return std::shared_ptr<CumulantK17<turbulenceModel> >(new CumulantK17<turbulenceModel>(para,level)); +} + +template<TurbulenceModel turbulenceModel> +void CumulantK17<turbulenceModel>::run() +{ + LB_Kernel_CumulantK17 < turbulenceModel, false, false > <<< cudaGrid.grid, cudaGrid.threads >>>( para->getParD(level)->omega, + para->getParD(level)->neighborX, para->getParD(level)->neighborY, para->getParD(level)->neighborZ, + para->getParD(level)->distributions.f[0], + para->getParD(level)->rho, + para->getParD(level)->velocityX, para->getParD(level)->velocityY, para->getParD(level)->velocityZ, + para->getParD(level)->turbViscosity, + para->getSGSConstant(), + (unsigned long)para->getParD(level)->numberOfNodes, + level, + para->getForcesDev(), + para->getParD(level)->forceX_SP, para->getParD(level)->forceY_SP, para->getParD(level)->forceZ_SP, + para->getQuadricLimitersDev(), + para->getParD(level)->isEvenTimestep, + para->getParD(level)->taggedFluidNodeIndices[CollisionTemplate::Default], + para->getParD(level)->numberOfTaggedFluidNodes[CollisionTemplate::Default]); + + getLastCudaError("LB_Kernel_CumulantK17 execution failed"); +} + +template<TurbulenceModel turbulenceModel> +void CumulantK17<turbulenceModel>::runOnIndices( const unsigned int *indices, unsigned int size_indices, CollisionTemplate collisionTemplate, CudaStreamIndex streamIndex ) +{ + cudaStream_t stream = para->getStreamManager()->getStream(streamIndex); + + switch (collisionTemplate) + { + case CollisionTemplate::Default: + LB_Kernel_CumulantK17 < turbulenceModel, false, false > <<< cudaGrid.grid, cudaGrid.threads, 0, stream >>>(para->getParD(level)->omega, + para->getParD(level)->neighborX, para->getParD(level)->neighborY, para->getParD(level)->neighborZ, + para->getParD(level)->distributions.f[0], + para->getParD(level)->rho, + para->getParD(level)->velocityX, para->getParD(level)->velocityY, para->getParD(level)->velocityZ, + para->getParD(level)->turbViscosity, + para->getSGSConstant(), + (unsigned long)para->getParD(level)->numberOfNodes, + level, + para->getForcesDev(), + para->getParD(level)->forceX_SP, para->getParD(level)->forceY_SP, para->getParD(level)->forceZ_SP, + para->getQuadricLimitersDev(), + para->getParD(level)->isEvenTimestep, + indices, + size_indices); + break; + + case CollisionTemplate::WriteMacroVars: + LB_Kernel_CumulantK17 < turbulenceModel, true, false > <<< cudaGrid.grid, cudaGrid.threads, 0, stream >>>( para->getParD(level)->omega, + para->getParD(level)->neighborX, para->getParD(level)->neighborY, para->getParD(level)->neighborZ, + para->getParD(level)->distributions.f[0], + para->getParD(level)->rho, + para->getParD(level)->velocityX, para->getParD(level)->velocityY, para->getParD(level)->velocityZ, + para->getParD(level)->turbViscosity, + para->getSGSConstant(), + (unsigned long)para->getParD(level)->numberOfNodes, + level, + para->getForcesDev(), + para->getParD(level)->forceX_SP, para->getParD(level)->forceY_SP, para->getParD(level)->forceZ_SP, + para->getQuadricLimitersDev(), + para->getParD(level)->isEvenTimestep, + indices, + size_indices); + break; + + case CollisionTemplate::SubDomainBorder: + case CollisionTemplate::AllFeatures: + LB_Kernel_CumulantK17 < turbulenceModel, true, true > <<< cudaGrid.grid, cudaGrid.threads, 0, stream >>>( para->getParD(level)->omega, + para->getParD(level)->neighborX, para->getParD(level)->neighborY, para->getParD(level)->neighborZ, + para->getParD(level)->distributions.f[0], + para->getParD(level)->rho, + para->getParD(level)->velocityX, para->getParD(level)->velocityY, para->getParD(level)->velocityZ, + para->getParD(level)->turbViscosity, + para->getSGSConstant(), + (unsigned long)para->getParD(level)->numberOfNodes, + level, + para->getForcesDev(), + para->getParD(level)->forceX_SP, para->getParD(level)->forceY_SP, para->getParD(level)->forceZ_SP, + para->getQuadricLimitersDev(), + para->getParD(level)->isEvenTimestep, + indices, + size_indices); + break; case CollisionTemplate::ApplyBodyForce: + LB_Kernel_CumulantK17 < turbulenceModel, false, true > <<< cudaGrid.grid, cudaGrid.threads, 0, stream >>>( para->getParD(level)->omega, + para->getParD(level)->neighborX, para->getParD(level)->neighborY, para->getParD(level)->neighborZ, + para->getParD(level)->distributions.f[0], + para->getParD(level)->rho, + para->getParD(level)->velocityX, para->getParD(level)->velocityY, para->getParD(level)->velocityZ, + para->getParD(level)->turbViscosity, + para->getSGSConstant(), + (unsigned long)para->getParD(level)->numberOfNodes, + level, + para->getForcesDev(), + para->getParD(level)->forceX_SP, para->getParD(level)->forceY_SP, para->getParD(level)->forceZ_SP, + para->getQuadricLimitersDev(), + para->getParD(level)->isEvenTimestep, + indices, + size_indices); + break; default: + throw std::runtime_error("Invalid CollisionTemplate in CumulantK17::runOnIndices()"); + break; + } + + getLastCudaError("LB_Kernel_CumulantK17 execution failed"); +} + +template<TurbulenceModel turbulenceModel> +CumulantK17<turbulenceModel>::CumulantK17(std::shared_ptr<Parameter> para, int level) +{ + this->para = para; + this->level = level; + + myPreProcessorTypes.push_back(InitCompSP27); + + myKernelGroup = BasicKernel; + + this->cudaGrid = vf::cuda::CudaGrid(para->getParD(level)->numberofthreads, para->getParD(level)->numberOfNodes); + this->kernelUsesFluidNodeIndices = true; + + VF_LOG_INFO("Using turbulence model: {}", turbulenceModel); +} + +template class CumulantK17<TurbulenceModel::AMD>; +template class CumulantK17<TurbulenceModel::Smagorinsky>; +template class CumulantK17<TurbulenceModel::QR>; +template class CumulantK17<TurbulenceModel::None>; diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17.h b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17.h new file mode 100644 index 0000000000000000000000000000000000000000..00c79a30c9ccf9a89901165d020fc85d5a479c1d --- /dev/null +++ b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17.h @@ -0,0 +1,20 @@ +#ifndef CUMULANT_K17_H +#define CUMULANT_K17_H + +#include "Kernel/KernelImp.h" +#include "Parameter/Parameter.h" + +template<TurbulenceModel turbulenceModel> +class CumulantK17 : public KernelImp +{ +public: + static std::shared_ptr< CumulantK17<turbulenceModel> > getNewInstance(std::shared_ptr< Parameter> para, int level); + void run() override; + void runOnIndices(const unsigned int *indices, unsigned int size_indices, CollisionTemplate collisionTemplate, CudaStreamIndex streamIndex) override; + +private: + CumulantK17(); + CumulantK17(std::shared_ptr<Parameter> para, int level); +}; + +#endif diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17Comp.cu b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17Comp.cu deleted file mode 100644 index b176b94d07e7f280d738a797d5bd853095e3caed..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17Comp.cu +++ /dev/null @@ -1,33 +0,0 @@ -#include "CumulantK17Comp.h" - -#include "Parameter/Parameter.h" -#include "CumulantK17Comp_Device.cuh" -#include "cuda/CudaGrid.h" - -std::shared_ptr<CumulantK17Comp> CumulantK17Comp::getNewInstance(std::shared_ptr<Parameter> para, int level) -{ - return std::shared_ptr<CumulantK17Comp>(new CumulantK17Comp(para,level)); -} - -void CumulantK17Comp::run() -{ - LB_Kernel_CumulantK17Comp <<< cudaGrid.grid, cudaGrid.threads >>>(para->getParD(level)->omega, - para->getParD(level)->typeOfGridNode, - para->getParD(level)->neighborX, - para->getParD(level)->neighborY, - para->getParD(level)->neighborZ, - para->getParD(level)->distributions.f[0], - para->getParD(level)->numberOfNodes, - level, - para->getForcesDev(), - para->getQuadricLimitersDev(), - para->getParD(level)->isEvenTimestep); - getLastCudaError("LB_Kernel_CumulantK17Comp execution failed"); -} - -CumulantK17Comp::CumulantK17Comp(std::shared_ptr<Parameter> para, int level): KernelImp(para, level) -{ - myPreProcessorTypes.push_back(InitCompSP27); - myKernelGroup = BasicKernel; - this->cudaGrid = vf::cuda::CudaGrid(para->getParD(level)->numberofthreads, para->getParD(level)->numberOfNodes); -} \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17Comp.h b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17Comp.h deleted file mode 100644 index 22a95a688e5d078d7b710f494bfea360c9af0d6b..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17Comp.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef CUMULANT_K17_COMP_H -#define CUMULANT_K17_COMP_H - -#include "Kernel/KernelImp.h" - -class CumulantK17Comp : public KernelImp -{ -public: - static std::shared_ptr<CumulantK17Comp> getNewInstance(std::shared_ptr< Parameter> para, int level); - void run(); - -private: - CumulantK17Comp(); - CumulantK17Comp(std::shared_ptr< Parameter> para, int level); -}; - -#endif diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17Comp_Device.cu b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17Comp_Device.cu deleted file mode 100644 index 7cf27aa883cbfd3a0e4a0a36fa61649a62d06eeb..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17Comp_Device.cu +++ /dev/null @@ -1,1040 +0,0 @@ -#include "LBM/LB.h" -#include "lbm/constants/D3Q27.h" -#include <lbm/constants/NumericConstants.h> - -using namespace vf::lbm::constant; -using namespace vf::lbm::dir; -#include "math.h" - - -__global__ void LB_Kernel_CumulantK17Comp(real omega, - unsigned int* bcMatD, - unsigned int* neighborX, - unsigned int* neighborY, - unsigned int* neighborZ, - real* DDStart, - int size_Mat, - int level, - real* forces, - real* quadricLimiters, - bool EvenOrOdd) -{ - //////////////////////////////////////////////////////////////////////////////// - const unsigned x = threadIdx.x; // Globaler x-Index - const unsigned y = blockIdx.x; // Globaler y-Index - const unsigned z = blockIdx.y; // Globaler z-Index - - const unsigned nx = blockDim.x; - const unsigned ny = gridDim.x; - - const unsigned k = nx*(ny*z + y) + x; - ////////////////////////////////////////////////////////////////////////// - - if (k<size_Mat) - { - //////////////////////////////////////////////////////////////////////////////// - unsigned int BC; - BC = bcMatD[k]; - - if ((BC != GEO_SOLID) && (BC != GEO_VOID)) - { - Distributions27 D; - if (EvenOrOdd == true) - { - D.f[DIR_P00] = &DDStart[DIR_P00 *size_Mat]; - D.f[DIR_M00] = &DDStart[DIR_M00 *size_Mat]; - D.f[DIR_0P0] = &DDStart[DIR_0P0 *size_Mat]; - D.f[DIR_0M0] = &DDStart[DIR_0M0 *size_Mat]; - D.f[DIR_00P] = &DDStart[DIR_00P *size_Mat]; - D.f[DIR_00M] = &DDStart[DIR_00M *size_Mat]; - D.f[DIR_PP0] = &DDStart[DIR_PP0 *size_Mat]; - D.f[DIR_MM0] = &DDStart[DIR_MM0 *size_Mat]; - D.f[DIR_PM0] = &DDStart[DIR_PM0 *size_Mat]; - D.f[DIR_MP0] = &DDStart[DIR_MP0 *size_Mat]; - D.f[DIR_P0P] = &DDStart[DIR_P0P *size_Mat]; - D.f[DIR_M0M] = &DDStart[DIR_M0M *size_Mat]; - D.f[DIR_P0M] = &DDStart[DIR_P0M *size_Mat]; - D.f[DIR_M0P] = &DDStart[DIR_M0P *size_Mat]; - D.f[DIR_0PP] = &DDStart[DIR_0PP *size_Mat]; - D.f[DIR_0MM] = &DDStart[DIR_0MM *size_Mat]; - D.f[DIR_0PM] = &DDStart[DIR_0PM *size_Mat]; - D.f[DIR_0MP] = &DDStart[DIR_0MP *size_Mat]; - D.f[DIR_000] = &DDStart[DIR_000*size_Mat]; - D.f[DIR_PPP] = &DDStart[DIR_PPP *size_Mat]; - D.f[DIR_MMP] = &DDStart[DIR_MMP *size_Mat]; - D.f[DIR_PMP] = &DDStart[DIR_PMP *size_Mat]; - D.f[DIR_MPP] = &DDStart[DIR_MPP *size_Mat]; - D.f[DIR_PPM] = &DDStart[DIR_PPM *size_Mat]; - D.f[DIR_MMM] = &DDStart[DIR_MMM *size_Mat]; - D.f[DIR_PMM] = &DDStart[DIR_PMM *size_Mat]; - D.f[DIR_MPM] = &DDStart[DIR_MPM *size_Mat]; - } - else - { - D.f[DIR_M00] = &DDStart[DIR_P00 *size_Mat]; - D.f[DIR_P00] = &DDStart[DIR_M00 *size_Mat]; - D.f[DIR_0M0] = &DDStart[DIR_0P0 *size_Mat]; - D.f[DIR_0P0] = &DDStart[DIR_0M0 *size_Mat]; - D.f[DIR_00M] = &DDStart[DIR_00P *size_Mat]; - D.f[DIR_00P] = &DDStart[DIR_00M *size_Mat]; - D.f[DIR_MM0] = &DDStart[DIR_PP0 *size_Mat]; - D.f[DIR_PP0] = &DDStart[DIR_MM0 *size_Mat]; - D.f[DIR_MP0] = &DDStart[DIR_PM0 *size_Mat]; - D.f[DIR_PM0] = &DDStart[DIR_MP0 *size_Mat]; - D.f[DIR_M0M] = &DDStart[DIR_P0P *size_Mat]; - D.f[DIR_P0P] = &DDStart[DIR_M0M *size_Mat]; - D.f[DIR_M0P] = &DDStart[DIR_P0M *size_Mat]; - D.f[DIR_P0M] = &DDStart[DIR_M0P *size_Mat]; - D.f[DIR_0MM] = &DDStart[DIR_0PP *size_Mat]; - D.f[DIR_0PP] = &DDStart[DIR_0MM *size_Mat]; - D.f[DIR_0MP] = &DDStart[DIR_0PM *size_Mat]; - D.f[DIR_0PM] = &DDStart[DIR_0MP *size_Mat]; - D.f[DIR_000] = &DDStart[DIR_000*size_Mat]; - D.f[DIR_MMM] = &DDStart[DIR_PPP *size_Mat]; - D.f[DIR_PPM] = &DDStart[DIR_MMP *size_Mat]; - D.f[DIR_MPM] = &DDStart[DIR_PMP *size_Mat]; - D.f[DIR_PMM] = &DDStart[DIR_MPP *size_Mat]; - D.f[DIR_MMP] = &DDStart[DIR_PPM *size_Mat]; - D.f[DIR_PPP] = &DDStart[DIR_MMM *size_Mat]; - D.f[DIR_MPP] = &DDStart[DIR_PMM *size_Mat]; - D.f[DIR_PMP] = &DDStart[DIR_MPM *size_Mat]; - } - - //////////////////////////////////////////////////////////////////////////////// - //index - //unsigned int kzero= k; - //unsigned int ke = k; - unsigned int kw = neighborX[k]; - //unsigned int kn = k; - unsigned int ks = neighborY[k]; - //unsigned int kt = k; - unsigned int kb = neighborZ[k]; - unsigned int ksw = neighborY[kw]; - //unsigned int kne = k; - //unsigned int kse = ks; - //unsigned int knw = kw; - unsigned int kbw = neighborZ[kw]; - //unsigned int kte = k; - //unsigned int kbe = kb; - //unsigned int ktw = kw; - unsigned int kbs = neighborZ[ks]; - //unsigned int ktn = k; - //unsigned int kbn = kb; - //unsigned int kts = ks; - //unsigned int ktse = ks; - //unsigned int kbnw = kbw; - //unsigned int ktnw = kw; - //unsigned int kbse = kbs; - //unsigned int ktsw = ksw; - //unsigned int kbne = kb; - //unsigned int ktne = k; - unsigned int kbsw = neighborZ[ksw]; - - //unsigned int kzero= k; - //unsigned int ke = k; - //unsigned int kw = neighborX[k]; - //unsigned int kn = k; - //unsigned int ks = neighborY[k]; - //unsigned int kt = k; - //unsigned int kb = neighborZ[k]; - //unsigned int ksw = neighborY[kw]; - //unsigned int kne = k; - //unsigned int kse = ks; - //unsigned int knw = kw; - //unsigned int kbw = neighborZ[kw]; - //unsigned int kte = k; - //unsigned int kbe = kb; - //unsigned int ktw = kw; - //unsigned int kbs = neighborZ[ks]; - //unsigned int ktn = k; - //unsigned int kbn = kb; - //unsigned int kts = ks; - //unsigned int ktse = ks; - //unsigned int kbnw = kbw; - //unsigned int ktnw = kw; - //unsigned int kbse = kbs; - //unsigned int ktsw = ksw; - //unsigned int kbne = kb; - //unsigned int ktne = k; - //unsigned int kbsw = neighborZ[ksw]; - ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - real mfcbb = (D.f[DIR_P00])[k];//[ke ];// + c2over27 ;(D.f[DIR_P00 ])[k ];//ke - real mfabb = (D.f[DIR_M00])[kw];//[kw ];// + c2over27 ;(D.f[DIR_M00 ])[kw ]; - real mfbcb = (D.f[DIR_0P0])[k];//[kn ];// + c2over27 ;(D.f[DIR_0P0 ])[k ];//kn - real mfbab = (D.f[DIR_0M0])[ks];//[ks ];// + c2over27 ;(D.f[DIR_0M0 ])[ks ]; - real mfbbc = (D.f[DIR_00P])[k];//[kt ];// + c2over27 ;(D.f[DIR_00P ])[k ];//kt - real mfbba = (D.f[DIR_00M])[kb];//[kb ];// + c2over27 ;(D.f[DIR_00M ])[kb ]; - real mfccb = (D.f[DIR_PP0])[k];//[kne ];// + c1over54 ;(D.f[DIR_PP0 ])[k ];//kne - real mfaab = (D.f[DIR_MM0])[ksw];//[ksw ];// + c1over54 ;(D.f[DIR_MM0 ])[ksw]; - real mfcab = (D.f[DIR_PM0])[ks];//[kse ];// + c1over54 ;(D.f[DIR_PM0 ])[ks ];//kse - real mfacb = (D.f[DIR_MP0])[kw];//[knw ];// + c1over54 ;(D.f[DIR_MP0 ])[kw ];//knw - real mfcbc = (D.f[DIR_P0P])[k];//[kte ];// + c1over54 ;(D.f[DIR_P0P ])[k ];//kte - real mfaba = (D.f[DIR_M0M])[kbw];//[kbw ];// + c1over54 ;(D.f[DIR_M0M ])[kbw]; - real mfcba = (D.f[DIR_P0M])[kb];//[kbe ];// + c1over54 ;(D.f[DIR_P0M ])[kb ];//kbe - real mfabc = (D.f[DIR_M0P])[kw];//[ktw ];// + c1over54 ;(D.f[DIR_M0P ])[kw ];//ktw - real mfbcc = (D.f[DIR_0PP])[k];//[ktn ];// + c1over54 ;(D.f[DIR_0PP ])[k ];//ktn - real mfbaa = (D.f[DIR_0MM])[kbs];//[kbs ];// + c1over54 ;(D.f[DIR_0MM ])[kbs]; - real mfbca = (D.f[DIR_0PM])[kb];//[kbn ];// + c1over54 ;(D.f[DIR_0PM ])[kb ];//kbn - real mfbac = (D.f[DIR_0MP])[ks];//[kts ];// + c1over54 ;(D.f[DIR_0MP ])[ks ];//kts - real mfbbb = (D.f[DIR_000])[k];//[kzero];// + c8over27 ;(D.f[DIR_000])[k ];//kzero - real mfccc = (D.f[DIR_PPP])[k];//[ktne ];// + c1over216;(D.f[DIR_PPP ])[k ];//ktne - real mfaac = (D.f[DIR_MMP])[ksw];//[ktsw ];// + c1over216;(D.f[DIR_MMP ])[ksw];//ktsw - real mfcac = (D.f[DIR_PMP])[ks];//[ktse ];// + c1over216;(D.f[DIR_PMP ])[ks ];//ktse - real mfacc = (D.f[DIR_MPP])[kw];//[ktnw ];// + c1over216;(D.f[DIR_MPP ])[kw ];//ktnw - real mfcca = (D.f[DIR_PPM])[kb];//[kbne ];// + c1over216;(D.f[DIR_PPM ])[kb ];//kbne - real mfaaa = (D.f[DIR_MMM])[kbsw];//[kbsw ];// + c1over216;(D.f[DIR_MMM ])[kbsw]; - real mfcaa = (D.f[DIR_PMM])[kbs];//[kbse ];// + c1over216;(D.f[DIR_PMM ])[kbs];//kbse - real mfaca = (D.f[DIR_MPM])[kbw];//[kbnw ];// + c1over216;(D.f[DIR_MPM ])[kbw];//kbnw - //////////////////////////////////////////////////////////////////////////////////// - real drho = ((((mfccc + mfaaa) + (mfaca + mfcac)) + ((mfacc + mfcaa) + (mfaac + mfcca))) + - (((mfbac + mfbca) + (mfbaa + mfbcc)) + ((mfabc + mfcba) + (mfaba + mfcbc)) + ((mfacb + mfcab) + (mfaab + mfccb))) + - ((mfabb + mfcbb) + (mfbab + mfbcb) + (mfbba + mfbbc))) + mfbbb; - - real rho = c1o1 + drho; - //////////////////////////////////////////////////////////////////////////////////// - //slow - //real oMdrho = one - ((((mfccc+mfaaa) + (mfaca+mfcac)) + ((mfacc+mfcaa) + (mfaac+mfcca))) + - // (((mfbac+mfbca) + (mfbaa+mfbcc)) + ((mfabc+mfcba) + (mfaba+mfcbc)) + ((mfacb+mfcab) + (mfaab+mfccb))) + - // ((mfabb+mfcbb) + (mfbab+mfbcb) + (mfbba+mfbbc)));//fehlt mfbbb - real vvx = ((((mfccc - mfaaa) + (mfcac - mfaca)) + ((mfcaa - mfacc) + (mfcca - mfaac))) + - (((mfcba - mfabc) + (mfcbc - mfaba)) + ((mfcab - mfacb) + (mfccb - mfaab))) + - (mfcbb - mfabb)) / rho; - real vvy = ((((mfccc - mfaaa) + (mfaca - mfcac)) + ((mfacc - mfcaa) + (mfcca - mfaac))) + - (((mfbca - mfbac) + (mfbcc - mfbaa)) + ((mfacb - mfcab) + (mfccb - mfaab))) + - (mfbcb - mfbab)) / rho; - real vvz = ((((mfccc - mfaaa) + (mfcac - mfaca)) + ((mfacc - mfcaa) + (mfaac - mfcca))) + - (((mfbac - mfbca) + (mfbcc - mfbaa)) + ((mfabc - mfcba) + (mfcbc - mfaba))) + - (mfbbc - mfbba)) / rho; - //////////////////////////////////////////////////////////////////////////////////// - //the force be with you - real fx = forces[0] / (pow((double)c2o1, (double)level)); //zero;//0.0032653/(pow(two,level)); //0.000000005;//(two/1600000.0) / 120.0; // - real fy = forces[1] / (pow((double)c2o1, (double)level)); //zero; - real fz = forces[2] / (pow((double)c2o1, (double)level)); //zero; - vvx += fx*c1o2; - vvy += fy*c1o2; - vvz += fz*c1o2; - //////////////////////////////////////////////////////////////////////////////////// - //real omega = omega_in; - //////////////////////////////////////////////////////////////////////////////////// - //fast - real oMdrho = c1o1; // comp special - //real oMdrho = one - (mfccc+mfaaa + mfaca+mfcac + mfacc+mfcaa + mfaac+mfcca + - // mfbac+mfbca + mfbaa+mfbcc + mfabc+mfcba + mfaba+mfcbc + mfacb+mfcab + mfaab+mfccb + - // mfabb+mfcbb + mfbab+mfbcb + mfbba+mfbbc + mfbbb);//fehlt mfbbb nicht mehr - //real vvx =mfccc-mfaaa + mfcac-mfaca + mfcaa-mfacc + mfcca-mfaac + - // mfcba-mfabc + mfcbc-mfaba + mfcab-mfacb + mfccb-mfaab + - // mfcbb-mfabb; - //real vvy =mfccc-mfaaa + mfaca-mfcac + mfacc-mfcaa + mfcca-mfaac + - // mfbca-mfbac + mfbcc-mfbaa + mfacb-mfcab + mfccb-mfaab + - // mfbcb-mfbab; - //real vvz =mfccc-mfaaa + mfcac-mfaca + mfacc-mfcaa + mfaac-mfcca + - // mfbac-mfbca + mfbcc-mfbaa + mfabc-mfcba + mfcbc-mfaba + - // mfbbc-mfbba; - //////////////////////////////////////////////////////////////////////////////////// - // oMdrho assembler style -------> faaaaaastaaaa - // or much sloooowaaaa ... it dep�ndssssss on sadaku - real m0, m1, m2; - //real oMdrho; - //{ - // oMdrho=mfccc+mfaaa; - // m0=mfaca+mfcac; - // m1=mfacc+mfcaa; - // m2=mfaac+mfcca; - // oMdrho+=m0; - // m1+=m2; - // oMdrho+=m1; - // m0=mfbac+mfbca; - // m1=mfbaa+mfbcc; - // m0+=m1; - // m1=mfabc+mfcba; - // m2=mfaba+mfcbc; - // m1+=m2; - // m0+=m1; - // m1=mfacb+mfcab; - // m2=mfaab+mfccb; - // m1+=m2; - // m0+=m1; - // oMdrho+=m0; - // m0=mfabb+mfcbb; - // m1=mfbab+mfbcb; - // m2=mfbba+mfbbc; - // m0+=m1+m2; - // m0+=mfbbb; //hat gefehlt - // oMdrho = one - (oMdrho + m0); - //} - //real vvx; - real vx2; - //{ - // vvx = mfccc-mfaaa; - // m0 = mfcac-mfaca; - // m1 = mfcaa-mfacc; - // m2 = mfcca-mfaac; - // vvx+= m0; - // m1 += m2; - // vvx+= m1; - // vx2 = mfcba-mfabc; - // m0 = mfcbc-mfaba; - // m1 = mfcab-mfacb; - // m2 = mfccb-mfaab; - // vx2+= m0; - // m1 += m2; - // vx2+= m1; - // vvx+= vx2; - // vx2 = mfcbb-mfabb; - // vvx+= vx2; - //} - //real vvy; - real vy2; - //{ - // vvy = mfccc-mfaaa; - // m0 = mfaca-mfcac; - // m1 = mfacc-mfcaa; - // m2 = mfcca-mfaac; - // vvy+= m0; - // m1 += m2; - // vvy+= m1; - // vy2 = mfbca-mfbac; - // m0 = mfbcc-mfbaa; - // m1 = mfacb-mfcab; - // m2 = mfccb-mfaab; - // vy2+= m0; - // m1 += m2; - // vy2+= m1; - // vvy+= vy2; - // vy2 = mfbcb-mfbab; - // vvy+= vy2; - //} - //real vvz; - real vz2; - //{ - // vvz = mfccc-mfaaa; - // m0 = mfcac-mfaca; - // m1 = mfacc-mfcaa; - // m2 = mfaac-mfcca; - // vvz+= m0; - // m1 += m2; - // vvz+= m1; - // vz2 = mfbac-mfbca; - // m0 = mfbcc-mfbaa; - // m1 = mfabc-mfcba; - // m2 = mfcbc-mfaba; - // vz2+= m0; - // m1 += m2; - // vz2+= m1; - // vvz+= vz2; - // vz2 = mfbbc-mfbba; - // vvz+= vz2; - //} - vx2 = vvx*vvx; - vy2 = vvy*vvy; - vz2 = vvz*vvz; - //////////////////////////////////////////////////////////////////////////////////// - real wadjust; - real qudricLimitP = quadricLimiters[0]; //0.01f; // * 0.0001f; // 1000000.0f; // 1000000.0f; // - real qudricLimitM = quadricLimiters[1]; //0.01f; // * 0.0001f; // 1000000.0f; // 1000000.0f; // - real qudricLimitD = quadricLimiters[2]; //0.01f; // * 0.001f; // 1000000.0f; // 1000000.0f; // - //////////////////////////////////////////////////////////////////////////////////// - //Hin - //////////////////////////////////////////////////////////////////////////////////// - // mit 1/36, 1/9, 1/36, 1/9, 4/9, 1/9, 1/36, 1/9, 1/36 Konditionieren - //////////////////////////////////////////////////////////////////////////////////// - // Z - Dir - m2 = mfaaa + mfaac; - m1 = mfaac - mfaaa; - m0 = m2 + mfaab; - mfaaa = m0; - m0 += c1o36 * oMdrho; - mfaab = m1 - m0 * vvz; - mfaac = m2 - c2o1* m1 * vvz + vz2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfaba + mfabc; - m1 = mfabc - mfaba; - m0 = m2 + mfabb; - mfaba = m0; - m0 += c1o9 * oMdrho; - mfabb = m1 - m0 * vvz; - mfabc = m2 - c2o1* m1 * vvz + vz2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfaca + mfacc; - m1 = mfacc - mfaca; - m0 = m2 + mfacb; - mfaca = m0; - m0 += c1o36 * oMdrho; - mfacb = m1 - m0 * vvz; - mfacc = m2 - c2o1* m1 * vvz + vz2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfbaa + mfbac; - m1 = mfbac - mfbaa; - m0 = m2 + mfbab; - mfbaa = m0; - m0 += c1o9 * oMdrho; - mfbab = m1 - m0 * vvz; - mfbac = m2 - c2o1* m1 * vvz + vz2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfbba + mfbbc; - m1 = mfbbc - mfbba; - m0 = m2 + mfbbb; - mfbba = m0; - m0 += c4o9 * oMdrho; - mfbbb = m1 - m0 * vvz; - mfbbc = m2 - c2o1* m1 * vvz + vz2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfbca + mfbcc; - m1 = mfbcc - mfbca; - m0 = m2 + mfbcb; - mfbca = m0; - m0 += c1o9 * oMdrho; - mfbcb = m1 - m0 * vvz; - mfbcc = m2 - c2o1* m1 * vvz + vz2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfcaa + mfcac; - m1 = mfcac - mfcaa; - m0 = m2 + mfcab; - mfcaa = m0; - m0 += c1o36 * oMdrho; - mfcab = m1 - m0 * vvz; - mfcac = m2 - c2o1* m1 * vvz + vz2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfcba + mfcbc; - m1 = mfcbc - mfcba; - m0 = m2 + mfcbb; - mfcba = m0; - m0 += c1o9 * oMdrho; - mfcbb = m1 - m0 * vvz; - mfcbc = m2 - c2o1* m1 * vvz + vz2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfcca + mfccc; - m1 = mfccc - mfcca; - m0 = m2 + mfccb; - mfcca = m0; - m0 += c1o36 * oMdrho; - mfccb = m1 - m0 * vvz; - mfccc = m2 - c2o1* m1 * vvz + vz2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////// - // mit 1/6, 0, 1/18, 2/3, 0, 2/9, 1/6, 0, 1/18 Konditionieren - //////////////////////////////////////////////////////////////////////////////////// - // Y - Dir - m2 = mfaaa + mfaca; - m1 = mfaca - mfaaa; - m0 = m2 + mfaba; - mfaaa = m0; - m0 += c1o6 * oMdrho; - mfaba = m1 - m0 * vvy; - mfaca = m2 - c2o1* m1 * vvy + vy2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfaab + mfacb; - m1 = mfacb - mfaab; - m0 = m2 + mfabb; - mfaab = m0; - mfabb = m1 - m0 * vvy; - mfacb = m2 - c2o1* m1 * vvy + vy2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfaac + mfacc; - m1 = mfacc - mfaac; - m0 = m2 + mfabc; - mfaac = m0; - m0 += c1o18 * oMdrho; - mfabc = m1 - m0 * vvy; - mfacc = m2 - c2o1* m1 * vvy + vy2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfbaa + mfbca; - m1 = mfbca - mfbaa; - m0 = m2 + mfbba; - mfbaa = m0; - m0 += c2o3 * oMdrho; - mfbba = m1 - m0 * vvy; - mfbca = m2 - c2o1* m1 * vvy + vy2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfbab + mfbcb; - m1 = mfbcb - mfbab; - m0 = m2 + mfbbb; - mfbab = m0; - mfbbb = m1 - m0 * vvy; - mfbcb = m2 - c2o1* m1 * vvy + vy2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfbac + mfbcc; - m1 = mfbcc - mfbac; - m0 = m2 + mfbbc; - mfbac = m0; - m0 += c2o9 * oMdrho; - mfbbc = m1 - m0 * vvy; - mfbcc = m2 - c2o1* m1 * vvy + vy2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfcaa + mfcca; - m1 = mfcca - mfcaa; - m0 = m2 + mfcba; - mfcaa = m0; - m0 += c1o6 * oMdrho; - mfcba = m1 - m0 * vvy; - mfcca = m2 - c2o1* m1 * vvy + vy2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfcab + mfccb; - m1 = mfccb - mfcab; - m0 = m2 + mfcbb; - mfcab = m0; - mfcbb = m1 - m0 * vvy; - mfccb = m2 - c2o1* m1 * vvy + vy2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfcac + mfccc; - m1 = mfccc - mfcac; - m0 = m2 + mfcbc; - mfcac = m0; - m0 += c1o18 * oMdrho; - mfcbc = m1 - m0 * vvy; - mfccc = m2 - c2o1* m1 * vvy + vy2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////// - // mit 1, 0, 1/3, 0, 0, 0, 1/3, 0, 1/9 Konditionieren - //////////////////////////////////////////////////////////////////////////////////// - // X - Dir - m2 = mfaaa + mfcaa; - m1 = mfcaa - mfaaa; - m0 = m2 + mfbaa; - mfaaa = m0; - m0 += c1o1* oMdrho; - mfbaa = m1 - m0 * vvx; - mfcaa = m2 - c2o1* m1 * vvx + vx2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfaba + mfcba; - m1 = mfcba - mfaba; - m0 = m2 + mfbba; - mfaba = m0; - mfbba = m1 - m0 * vvx; - mfcba = m2 - c2o1* m1 * vvx + vx2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfaca + mfcca; - m1 = mfcca - mfaca; - m0 = m2 + mfbca; - mfaca = m0; - m0 += c1o3 * oMdrho; - mfbca = m1 - m0 * vvx; - mfcca = m2 - c2o1* m1 * vvx + vx2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfaab + mfcab; - m1 = mfcab - mfaab; - m0 = m2 + mfbab; - mfaab = m0; - mfbab = m1 - m0 * vvx; - mfcab = m2 - c2o1* m1 * vvx + vx2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfabb + mfcbb; - m1 = mfcbb - mfabb; - m0 = m2 + mfbbb; - mfabb = m0; - mfbbb = m1 - m0 * vvx; - mfcbb = m2 - c2o1* m1 * vvx + vx2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfacb + mfccb; - m1 = mfccb - mfacb; - m0 = m2 + mfbcb; - mfacb = m0; - mfbcb = m1 - m0 * vvx; - mfccb = m2 - c2o1* m1 * vvx + vx2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfaac + mfcac; - m1 = mfcac - mfaac; - m0 = m2 + mfbac; - mfaac = m0; - m0 += c1o3 * oMdrho; - mfbac = m1 - m0 * vvx; - mfcac = m2 - c2o1* m1 * vvx + vx2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfabc + mfcbc; - m1 = mfcbc - mfabc; - m0 = m2 + mfbbc; - mfabc = m0; - mfbbc = m1 - m0 * vvx; - mfcbc = m2 - c2o1* m1 * vvx + vx2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - m2 = mfacc + mfccc; - m1 = mfccc - mfacc; - m0 = m2 + mfbcc; - mfacc = m0; - m0 += c1o9 * oMdrho; - mfbcc = m1 - m0 * vvx; - mfccc = m2 - c2o1* m1 * vvx + vx2 * m0; - //////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////// - - //////////////////////////////////////////////////////////////////////////////////// - // Cumulants - //////////////////////////////////////////////////////////////////////////////////// - real OxxPyyPzz = c1o1; //set the bulk viscosity one is high / two is very low and zero is (too) high ... (also called omega 2) - - //////////////////////////////////////////////////////////// - //3. - ////////////////////////////// - real OxyyPxzz = c8o1*(-c2o1 + omega)*(c1o1 + c2o1*omega) / (-c8o1 - c14o1*omega + c7o1*omega*omega);//one; - real OxyyMxzz = c8o1*(-c2o1 + omega)*(-c7o1 + c4o1*omega) / (c56o1 - c50o1*omega + c9o1*omega*omega);//one; - real Oxyz = c24o1*(-c2o1 + omega)*(-c2o1 - c7o1*omega + c3o1*omega*omega) / (c48o1 + c152o1*omega - c130o1*omega*omega + c29o1*omega*omega*omega);//one; - //////////////////////////////////////////////////////////// - //4. - ////////////////////////////// - real O4 = c1o1; - ////////////////////////////// - //real O4 = omega;//TRT - //////////////////////////////////////////////////////////// - //5. - ////////////////////////////// - real O5 = c1o1; - //////////////////////////////////////////////////////////// - //6. - ////////////////////////////// - real O6 = c1o1; - //////////////////////////////////////////////////////////// - - - //central moments to cumulants - //4. - real CUMcbb = mfcbb - ((mfcaa + c1o3) * mfabb + c2o1 * mfbba * mfbab) / rho; - real CUMbcb = mfbcb - ((mfaca + c1o3) * mfbab + c2o1 * mfbba * mfabb) / rho; - real CUMbbc = mfbbc - ((mfaac + c1o3) * mfbba + c2o1 * mfbab * mfabb) / rho; - - real CUMcca = mfcca - (((mfcaa * mfaca + c2o1 * mfbba * mfbba) + c1o3 * (mfcaa + mfaca)) / rho - c1o9*(drho / rho)); - real CUMcac = mfcac - (((mfcaa * mfaac + c2o1 * mfbab * mfbab) + c1o3 * (mfcaa + mfaac)) / rho - c1o9*(drho / rho)); - real CUMacc = mfacc - (((mfaac * mfaca + c2o1 * mfabb * mfabb) + c1o3 * (mfaac + mfaca)) / rho - c1o9*(drho / rho)); - - //5. - real CUMbcc = mfbcc - ((mfaac * mfbca + mfaca * mfbac + c4o1 * mfabb * mfbbb + c2o1 * (mfbab * mfacb + mfbba * mfabc)) + c1o3 * (mfbca + mfbac)) / rho; - real CUMcbc = mfcbc - ((mfaac * mfcba + mfcaa * mfabc + c4o1 * mfbab * mfbbb + c2o1 * (mfabb * mfcab + mfbba * mfbac)) + c1o3 * (mfcba + mfabc)) / rho; - real CUMccb = mfccb - ((mfcaa * mfacb + mfaca * mfcab + c4o1 * mfbba * mfbbb + c2o1 * (mfbab * mfbca + mfabb * mfcba)) + c1o3 * (mfacb + mfcab)) / rho; - - //6. - - real CUMccc = mfccc + ((-c4o1 * mfbbb * mfbbb - - (mfcaa * mfacc + mfaca * mfcac + mfaac * mfcca) - - c4o1 * (mfabb * mfcbb + mfbab * mfbcb + mfbba * mfbbc) - - c2o1 * (mfbca * mfbac + mfcba * mfabc + mfcab * mfacb)) / rho - + (c4o1 * (mfbab * mfbab * mfaca + mfabb * mfabb * mfcaa + mfbba * mfbba * mfaac) - + c2o1 * (mfcaa * mfaca * mfaac) - + c16o1 * mfbba * mfbab * mfabb) / (rho * rho) - - c1o3 * (mfacc + mfcac + mfcca) / rho - - c1o9 * (mfcaa + mfaca + mfaac) / rho - + (c2o1 * (mfbab * mfbab + mfabb * mfabb + mfbba * mfbba) - + (mfaac * mfaca + mfaac * mfcaa + mfaca * mfcaa) + c1o3 *(mfaac + mfaca + mfcaa)) / (rho * rho) * c2o3 - + c1o27*((drho * drho - drho) / (rho*rho))); - - //2. - // linear combinations - real mxxPyyPzz = mfcaa + mfaca + mfaac; - real mxxMyy = mfcaa - mfaca; - real mxxMzz = mfcaa - mfaac; - - //////////////////////////////////////////////////////////////////////////// - real Dxy = -c3o1*omega*mfbba; - real Dxz = -c3o1*omega*mfbab; - real Dyz = -c3o1*omega*mfabb; - - //3. - // linear combinations - - real mxxyPyzz = mfcba + mfabc; - real mxxyMyzz = mfcba - mfabc; - - real mxxzPyyz = mfcab + mfacb; - real mxxzMyyz = mfcab - mfacb; - - real mxyyPxzz = mfbca + mfbac; - real mxyyMxzz = mfbca - mfbac; - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - //incl. correction (hat noch nicht so gut funktioniert...Optimierungsbedarf??) - - real dxux = c1o2 * (-omega) *(mxxMyy + mxxMzz) + c1o2 * OxxPyyPzz * (mfaaa - mxxPyyPzz); - real dyuy = dxux + omega * c3o2 * mxxMyy; - real dzuz = dxux + omega * c3o2 * mxxMzz; - - //relax - mxxPyyPzz += OxxPyyPzz*(mfaaa - mxxPyyPzz) - c3o1 * (c1o1 - c1o2 * OxxPyyPzz) * (vx2 * dxux + vy2 * dyuy + vz2 * dzuz);//-magicBulk*OxxPyyPzz; - mxxMyy += omega * (-mxxMyy) - c3o1 * (c1o1 + c1o2 * (-omega)) * (vx2 * dxux - vy2 * dyuy); - mxxMzz += omega * (-mxxMzz) - c3o1 * (c1o1 + c1o2 * (-omega)) * (vx2 * dxux - vz2 * dzuz); - - /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - ////no correction - //mxxPyyPzz += OxxPyyPzz*(mfaaa-mxxPyyPzz);//-magicBulk*OxxPyyPzz; - //mxxMyy += -(-omega) * (-mxxMyy); - //mxxMzz += -(-omega) * (-mxxMzz); - ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - mfabb += omega * (-mfabb); - mfbab += omega * (-mfbab); - mfbba += omega * (-mfbba); - ////////////////////////////////////////////////////////////////////////// - - // linear combinations back - mfcaa = c1o3 * (mxxMyy + mxxMzz + mxxPyyPzz); - mfaca = c1o3 * (-c2o1* mxxMyy + mxxMzz + mxxPyyPzz); - mfaac = c1o3 * (mxxMyy - c2o1* mxxMzz + mxxPyyPzz); - - - //relax - ////////////////////////////////////////////////////////////////////////// - //das ist der limiter - wadjust = Oxyz + (c1o1 - Oxyz)*abs(mfbbb) / (abs(mfbbb) + qudricLimitD); - mfbbb += wadjust * (-mfbbb); - wadjust = OxyyPxzz + (c1o1 - OxyyPxzz)*abs(mxxyPyzz) / (abs(mxxyPyzz) + qudricLimitP); - mxxyPyzz += wadjust * (-mxxyPyzz); - wadjust = OxyyMxzz + (c1o1 - OxyyMxzz)*abs(mxxyMyzz) / (abs(mxxyMyzz) + qudricLimitM); - mxxyMyzz += wadjust * (-mxxyMyzz); - wadjust = OxyyPxzz + (c1o1 - OxyyPxzz)*abs(mxxzPyyz) / (abs(mxxzPyyz) + qudricLimitP); - mxxzPyyz += wadjust * (-mxxzPyyz); - wadjust = OxyyMxzz + (c1o1 - OxyyMxzz)*abs(mxxzMyyz) / (abs(mxxzMyyz) + qudricLimitM); - mxxzMyyz += wadjust * (-mxxzMyyz); - wadjust = OxyyPxzz + (c1o1 - OxyyPxzz)*abs(mxyyPxzz) / (abs(mxyyPxzz) + qudricLimitP); - mxyyPxzz += wadjust * (-mxyyPxzz); - wadjust = OxyyMxzz + (c1o1 - OxyyMxzz)*abs(mxyyMxzz) / (abs(mxyyMxzz) + qudricLimitM); - mxyyMxzz += wadjust * (-mxyyMxzz); - ////////////////////////////////////////////////////////////////////////// - //ohne limiter - //mfbbb += OxyyMxzz * (-mfbbb); - //mxxyPyzz += OxyyPxzz * (-mxxyPyzz); - //mxxyMyzz += OxyyMxzz * (-mxxyMyzz); - //mxxzPyyz += OxyyPxzz * (-mxxzPyyz); - //mxxzMyyz += OxyyMxzz * (-mxxzMyyz); - //mxyyPxzz += OxyyPxzz * (-mxyyPxzz); - //mxyyMxzz += OxyyMxzz * (-mxyyMxzz); - ////////////////////////////////////////////////////////////////////////// - - // linear combinations back - mfcba = (mxxyMyzz + mxxyPyzz) * c1o2; - mfabc = (-mxxyMyzz + mxxyPyzz) * c1o2; - mfcab = (mxxzMyyz + mxxzPyyz) * c1o2; - mfacb = (-mxxzMyyz + mxxzPyyz) * c1o2; - mfbca = (mxyyMxzz + mxyyPxzz) * c1o2; - mfbac = (-mxyyMxzz + mxyyPxzz) * c1o2; - - //4. - ////////////////////////////////////////////////////////////////////////// - //mit limiter - // wadjust = O4+(one-O4)*abs(CUMacc)/(abs(CUMacc)+qudricLimit); - //CUMacc += wadjust * (-CUMacc); - // wadjust = O4+(one-O4)*abs(CUMcac)/(abs(CUMcac)+qudricLimit); - //CUMcac += wadjust * (-CUMcac); - // wadjust = O4+(one-O4)*abs(CUMcca)/(abs(CUMcca)+qudricLimit); - //CUMcca += wadjust * (-CUMcca); - - // wadjust = O4+(one-O4)*abs(CUMbbc)/(abs(CUMbbc)+qudricLimit); - //CUMbbc += wadjust * (-CUMbbc); - // wadjust = O4+(one-O4)*abs(CUMbcb)/(abs(CUMbcb)+qudricLimit); - //CUMbcb += wadjust * (-CUMbcb); - // wadjust = O4+(one-O4)*abs(CUMcbb)/(abs(CUMcbb)+qudricLimit); - //CUMcbb += wadjust * (-CUMcbb); - ////////////////////////////////////////////////////////////////////////// - real factorA = (c4o1 + c2o1*omega - c3o1*omega*omega) / (c2o1 - c7o1*omega + c5o1*omega*omega); - real factorB = (c4o1 + c28o1*omega - c14o1*omega*omega) / (c6o1 - c21o1*omega + c15o1*omega*omega); - ////////////////////////////////////////////////////////////////////////// - //ohne limiter - //CUMacc += O4 * (-CUMacc); - //CUMcac += O4 * (-CUMcac); - //CUMcca += O4 * (-CUMcca); - //CUMbbc += O4 * (-CUMbbc); - //CUMbcb += O4 * (-CUMbcb); - //CUMcbb += O4 * (-CUMcbb); - CUMacc = -O4*(c1o1 / omega - c1o2) * (dyuy + dzuz) * c2o3 * factorA + (c1o1 - O4) * (CUMacc); - CUMcac = -O4*(c1o1 / omega - c1o2) * (dxux + dzuz) * c2o3 * factorA + (c1o1 - O4) * (CUMcac); - CUMcca = -O4*(c1o1 / omega - c1o2) * (dyuy + dxux) * c2o3 * factorA + (c1o1 - O4) * (CUMcca); - CUMbbc = -O4*(c1o1 / omega - c1o2) * Dxy * c1o3 * factorB + (c1o1 - O4) * (CUMbbc); - CUMbcb = -O4*(c1o1 / omega - c1o2) * Dxz * c1o3 * factorB + (c1o1 - O4) * (CUMbcb); - CUMcbb = -O4*(c1o1 / omega - c1o2) * Dyz * c1o3 * factorB + (c1o1 - O4) * (CUMcbb); - ////////////////////////////////////////////////////////////////////////// - - - //5. - CUMbcc += O5 * (-CUMbcc); - CUMcbc += O5 * (-CUMcbc); - CUMccb += O5 * (-CUMccb); - - //6. - CUMccc += O6 * (-CUMccc); - - - - //back cumulants to central moments - //4. - mfcbb = CUMcbb + ((mfcaa + c1o3) * mfabb + c2o1 * mfbba * mfbab) / rho; - mfbcb = CUMbcb + ((mfaca + c1o3) * mfbab + c2o1 * mfbba * mfabb) / rho; - mfbbc = CUMbbc + ((mfaac + c1o3) * mfbba + c2o1 * mfbab * mfabb) / rho; - - mfcca = CUMcca + (((mfcaa * mfaca + c2o1 * mfbba * mfbba) + c1o3 * (mfcaa + mfaca)) / rho - c1o9*(drho / rho)); - mfcac = CUMcac + (((mfcaa * mfaac + c2o1 * mfbab * mfbab) + c1o3 * (mfcaa + mfaac)) / rho - c1o9*(drho / rho)); - mfacc = CUMacc + (((mfaac * mfaca + c2o1 * mfabb * mfabb) + c1o3 * (mfaac + mfaca)) / rho - c1o9*(drho / rho)); - - //5. - mfbcc = CUMbcc + ((mfaac * mfbca + mfaca * mfbac + c4o1 * mfabb * mfbbb + c2o1 * (mfbab * mfacb + mfbba * mfabc)) + c1o3 * (mfbca + mfbac)) / rho; - mfcbc = CUMcbc + ((mfaac * mfcba + mfcaa * mfabc + c4o1 * mfbab * mfbbb + c2o1 * (mfabb * mfcab + mfbba * mfbac)) + c1o3 * (mfcba + mfabc)) / rho; - mfccb = CUMccb + ((mfcaa * mfacb + mfaca * mfcab + c4o1 * mfbba * mfbbb + c2o1 * (mfbab * mfbca + mfabb * mfcba)) + c1o3 * (mfacb + mfcab)) / rho; - - //6. - - mfccc = CUMccc - ((-c4o1 * mfbbb * mfbbb - - (mfcaa * mfacc + mfaca * mfcac + mfaac * mfcca) - - c4o1 * (mfabb * mfcbb + mfbab * mfbcb + mfbba * mfbbc) - - c2o1 * (mfbca * mfbac + mfcba * mfabc + mfcab * mfacb)) / rho - + (c4o1 * (mfbab * mfbab * mfaca + mfabb * mfabb * mfcaa + mfbba * mfbba * mfaac) - + c2o1 * (mfcaa * mfaca * mfaac) - + c16o1 * mfbba * mfbab * mfabb) / (rho * rho) - - c1o3 * (mfacc + mfcac + mfcca) / rho - - c1o9 * (mfcaa + mfaca + mfaac) / rho - + (c2o1 * (mfbab * mfbab + mfabb * mfabb + mfbba * mfbba) - + (mfaac * mfaca + mfaac * mfcaa + mfaca * mfcaa) + c1o3 *(mfaac + mfaca + mfcaa)) / (rho * rho) * c2o3 - + c1o27*((drho * drho - drho) / (rho*rho))); - //////////////////////////////////////////////////////////////////////////////////// - - //////////////////////////////////////////////////////////////////////////////////// - //the force be with you - mfbaa = -mfbaa; - mfaba = -mfaba; - mfaab = -mfaab; - //////////////////////////////////////////////////////////////////////////////////// - - - //////////////////////////////////////////////////////////////////////////////////// - //back - //////////////////////////////////////////////////////////////////////////////////// - //mit 1, 0, 1/3, 0, 0, 0, 1/3, 0, 1/9 Konditionieren - //////////////////////////////////////////////////////////////////////////////////// - // Z - Dir - m0 = mfaac * c1o2 + mfaab * (vvz - c1o2) + (mfaaa + c1o1* oMdrho) * (vz2 - vvz) * c1o2; - m1 = -mfaac - c2o1* mfaab * vvz + mfaaa * (c1o1 - vz2) - c1o1* oMdrho * vz2; - m2 = mfaac * c1o2 + mfaab * (vvz + c1o2) + (mfaaa + c1o1* oMdrho) * (vz2 + vvz) * c1o2; - mfaaa = m0; - mfaab = m1; - mfaac = m2; - //////////////////////////////////////////////////////////////////////////////////// - m0 = mfabc * c1o2 + mfabb * (vvz - c1o2) + mfaba * (vz2 - vvz) * c1o2; - m1 = -mfabc - c2o1* mfabb * vvz + mfaba * (c1o1 - vz2); - m2 = mfabc * c1o2 + mfabb * (vvz + c1o2) + mfaba * (vz2 + vvz) * c1o2; - mfaba = m0; - mfabb = m1; - mfabc = m2; - //////////////////////////////////////////////////////////////////////////////////// - m0 = mfacc * c1o2 + mfacb * (vvz - c1o2) + (mfaca + c1o3 * oMdrho) * (vz2 - vvz) * c1o2; - m1 = -mfacc - c2o1* mfacb * vvz + mfaca * (c1o1 - vz2) - c1o3 * oMdrho * vz2; - m2 = mfacc * c1o2 + mfacb * (vvz + c1o2) + (mfaca + c1o3 * oMdrho) * (vz2 + vvz) * c1o2; - mfaca = m0; - mfacb = m1; - mfacc = m2; - //////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////// - m0 = mfbac * c1o2 + mfbab * (vvz - c1o2) + mfbaa * (vz2 - vvz) * c1o2; - m1 = -mfbac - c2o1* mfbab * vvz + mfbaa * (c1o1 - vz2); - m2 = mfbac * c1o2 + mfbab * (vvz + c1o2) + mfbaa * (vz2 + vvz) * c1o2; - mfbaa = m0; - mfbab = m1; - mfbac = m2; - /////////b////////////////////////////////////////////////////////////////////////// - m0 = mfbbc * c1o2 + mfbbb * (vvz - c1o2) + mfbba * (vz2 - vvz) * c1o2; - m1 = -mfbbc - c2o1* mfbbb * vvz + mfbba * (c1o1 - vz2); - m2 = mfbbc * c1o2 + mfbbb * (vvz + c1o2) + mfbba * (vz2 + vvz) * c1o2; - mfbba = m0; - mfbbb = m1; - mfbbc = m2; - /////////b////////////////////////////////////////////////////////////////////////// - m0 = mfbcc * c1o2 + mfbcb * (vvz - c1o2) + mfbca * (vz2 - vvz) * c1o2; - m1 = -mfbcc - c2o1* mfbcb * vvz + mfbca * (c1o1 - vz2); - m2 = mfbcc * c1o2 + mfbcb * (vvz + c1o2) + mfbca * (vz2 + vvz) * c1o2; - mfbca = m0; - mfbcb = m1; - mfbcc = m2; - //////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////// - m0 = mfcac * c1o2 + mfcab * (vvz - c1o2) + (mfcaa + c1o3 * oMdrho) * (vz2 - vvz) * c1o2; - m1 = -mfcac - c2o1* mfcab * vvz + mfcaa * (c1o1 - vz2) - c1o3 * oMdrho * vz2; - m2 = mfcac * c1o2 + mfcab * (vvz + c1o2) + (mfcaa + c1o3 * oMdrho) * (vz2 + vvz) * c1o2; - mfcaa = m0; - mfcab = m1; - mfcac = m2; - /////////c////////////////////////////////////////////////////////////////////////// - m0 = mfcbc * c1o2 + mfcbb * (vvz - c1o2) + mfcba * (vz2 - vvz) * c1o2; - m1 = -mfcbc - c2o1* mfcbb * vvz + mfcba * (c1o1 - vz2); - m2 = mfcbc * c1o2 + mfcbb * (vvz + c1o2) + mfcba * (vz2 + vvz) * c1o2; - mfcba = m0; - mfcbb = m1; - mfcbc = m2; - /////////c////////////////////////////////////////////////////////////////////////// - m0 = mfccc * c1o2 + mfccb * (vvz - c1o2) + (mfcca + c1o9 * oMdrho) * (vz2 - vvz) * c1o2; - m1 = -mfccc - c2o1* mfccb * vvz + mfcca * (c1o1 - vz2) - c1o9 * oMdrho * vz2; - m2 = mfccc * c1o2 + mfccb * (vvz + c1o2) + (mfcca + c1o9 * oMdrho) * (vz2 + vvz) * c1o2; - mfcca = m0; - mfccb = m1; - mfccc = m2; - //////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////// - //mit 1/6, 2/3, 1/6, 0, 0, 0, 1/18, 2/9, 1/18 Konditionieren - //////////////////////////////////////////////////////////////////////////////////// - // Y - Dir - m0 = mfaca * c1o2 + mfaba * (vvy - c1o2) + (mfaaa + c1o6 * oMdrho) * (vy2 - vvy) * c1o2; - m1 = -mfaca - c2o1* mfaba * vvy + mfaaa * (c1o1 - vy2) - c1o6 * oMdrho * vy2; - m2 = mfaca * c1o2 + mfaba * (vvy + c1o2) + (mfaaa + c1o6 * oMdrho) * (vy2 + vvy) * c1o2; - mfaaa = m0; - mfaba = m1; - mfaca = m2; - //////////////////////////////////////////////////////////////////////////////////// - m0 = mfacb * c1o2 + mfabb * (vvy - c1o2) + (mfaab + c2o3 * oMdrho) * (vy2 - vvy) * c1o2; - m1 = -mfacb - c2o1* mfabb * vvy + mfaab * (c1o1 - vy2) - c2o3 * oMdrho * vy2; - m2 = mfacb * c1o2 + mfabb * (vvy + c1o2) + (mfaab + c2o3 * oMdrho) * (vy2 + vvy) * c1o2; - mfaab = m0; - mfabb = m1; - mfacb = m2; - //////////////////////////////////////////////////////////////////////////////////// - m0 = mfacc * c1o2 + mfabc * (vvy - c1o2) + (mfaac + c1o6 * oMdrho) * (vy2 - vvy) * c1o2; - m1 = -mfacc - c2o1* mfabc * vvy + mfaac * (c1o1 - vy2) - c1o6 * oMdrho * vy2; - m2 = mfacc * c1o2 + mfabc * (vvy + c1o2) + (mfaac + c1o6 * oMdrho) * (vy2 + vvy) * c1o2; - mfaac = m0; - mfabc = m1; - mfacc = m2; - //////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////// - m0 = mfbca * c1o2 + mfbba * (vvy - c1o2) + mfbaa * (vy2 - vvy) * c1o2; - m1 = -mfbca - c2o1* mfbba * vvy + mfbaa * (c1o1 - vy2); - m2 = mfbca * c1o2 + mfbba * (vvy + c1o2) + mfbaa * (vy2 + vvy) * c1o2; - mfbaa = m0; - mfbba = m1; - mfbca = m2; - /////////b////////////////////////////////////////////////////////////////////////// - m0 = mfbcb * c1o2 + mfbbb * (vvy - c1o2) + mfbab * (vy2 - vvy) * c1o2; - m1 = -mfbcb - c2o1* mfbbb * vvy + mfbab * (c1o1 - vy2); - m2 = mfbcb * c1o2 + mfbbb * (vvy + c1o2) + mfbab * (vy2 + vvy) * c1o2; - mfbab = m0; - mfbbb = m1; - mfbcb = m2; - /////////b////////////////////////////////////////////////////////////////////////// - m0 = mfbcc * c1o2 + mfbbc * (vvy - c1o2) + mfbac * (vy2 - vvy) * c1o2; - m1 = -mfbcc - c2o1* mfbbc * vvy + mfbac * (c1o1 - vy2); - m2 = mfbcc * c1o2 + mfbbc * (vvy + c1o2) + mfbac * (vy2 + vvy) * c1o2; - mfbac = m0; - mfbbc = m1; - mfbcc = m2; - //////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////// - m0 = mfcca * c1o2 + mfcba * (vvy - c1o2) + (mfcaa + c1o18 * oMdrho) * (vy2 - vvy) * c1o2; - m1 = -mfcca - c2o1* mfcba * vvy + mfcaa * (c1o1 - vy2) - c1o18 * oMdrho * vy2; - m2 = mfcca * c1o2 + mfcba * (vvy + c1o2) + (mfcaa + c1o18 * oMdrho) * (vy2 + vvy) * c1o2; - mfcaa = m0; - mfcba = m1; - mfcca = m2; - /////////c////////////////////////////////////////////////////////////////////////// - m0 = mfccb * c1o2 + mfcbb * (vvy - c1o2) + (mfcab + c2o9 * oMdrho) * (vy2 - vvy) * c1o2; - m1 = -mfccb - c2o1* mfcbb * vvy + mfcab * (c1o1 - vy2) - c2o9 * oMdrho * vy2; - m2 = mfccb * c1o2 + mfcbb * (vvy + c1o2) + (mfcab + c2o9 * oMdrho) * (vy2 + vvy) * c1o2; - mfcab = m0; - mfcbb = m1; - mfccb = m2; - /////////c////////////////////////////////////////////////////////////////////////// - m0 = mfccc * c1o2 + mfcbc * (vvy - c1o2) + (mfcac + c1o18 * oMdrho) * (vy2 - vvy) * c1o2; - m1 = -mfccc - c2o1* mfcbc * vvy + mfcac * (c1o1 - vy2) - c1o18 * oMdrho * vy2; - m2 = mfccc * c1o2 + mfcbc * (vvy + c1o2) + (mfcac + c1o18 * oMdrho) * (vy2 + vvy) * c1o2; - mfcac = m0; - mfcbc = m1; - mfccc = m2; - //////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////// - //mit 1/36, 1/9, 1/36, 1/9, 4/9, 1/9, 1/36, 1/9, 1/36 Konditionieren - //////////////////////////////////////////////////////////////////////////////////// - // X - Dir - m0 = mfcaa * c1o2 + mfbaa * (vvx - c1o2) + (mfaaa + c1o36 * oMdrho) * (vx2 - vvx) * c1o2; - m1 = -mfcaa - c2o1* mfbaa * vvx + mfaaa * (c1o1 - vx2) - c1o36 * oMdrho * vx2; - m2 = mfcaa * c1o2 + mfbaa * (vvx + c1o2) + (mfaaa + c1o36 * oMdrho) * (vx2 + vvx) * c1o2; - mfaaa = m0; - mfbaa = m1; - mfcaa = m2; - //////////////////////////////////////////////////////////////////////////////////// - m0 = mfcba * c1o2 + mfbba * (vvx - c1o2) + (mfaba + c1o9 * oMdrho) * (vx2 - vvx) * c1o2; - m1 = -mfcba - c2o1* mfbba * vvx + mfaba * (c1o1 - vx2) - c1o9 * oMdrho * vx2; - m2 = mfcba * c1o2 + mfbba * (vvx + c1o2) + (mfaba + c1o9 * oMdrho) * (vx2 + vvx) * c1o2; - mfaba = m0; - mfbba = m1; - mfcba = m2; - //////////////////////////////////////////////////////////////////////////////////// - m0 = mfcca * c1o2 + mfbca * (vvx - c1o2) + (mfaca + c1o36 * oMdrho) * (vx2 - vvx) * c1o2; - m1 = -mfcca - c2o1* mfbca * vvx + mfaca * (c1o1 - vx2) - c1o36 * oMdrho * vx2; - m2 = mfcca * c1o2 + mfbca * (vvx + c1o2) + (mfaca + c1o36 * oMdrho) * (vx2 + vvx) * c1o2; - mfaca = m0; - mfbca = m1; - mfcca = m2; - //////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////// - m0 = mfcab * c1o2 + mfbab * (vvx - c1o2) + (mfaab + c1o9 * oMdrho) * (vx2 - vvx) * c1o2; - m1 = -mfcab - c2o1* mfbab * vvx + mfaab * (c1o1 - vx2) - c1o9 * oMdrho * vx2; - m2 = mfcab * c1o2 + mfbab * (vvx + c1o2) + (mfaab + c1o9 * oMdrho) * (vx2 + vvx) * c1o2; - mfaab = m0; - mfbab = m1; - mfcab = m2; - ///////////b//////////////////////////////////////////////////////////////////////// - m0 = mfcbb * c1o2 + mfbbb * (vvx - c1o2) + (mfabb + c4o9 * oMdrho) * (vx2 - vvx) * c1o2; - m1 = -mfcbb - c2o1* mfbbb * vvx + mfabb * (c1o1 - vx2) - c4o9 * oMdrho * vx2; - m2 = mfcbb * c1o2 + mfbbb * (vvx + c1o2) + (mfabb + c4o9 * oMdrho) * (vx2 + vvx) * c1o2; - mfabb = m0; - mfbbb = m1; - mfcbb = m2; - ///////////b//////////////////////////////////////////////////////////////////////// - m0 = mfccb * c1o2 + mfbcb * (vvx - c1o2) + (mfacb + c1o9 * oMdrho) * (vx2 - vvx) * c1o2; - m1 = -mfccb - c2o1* mfbcb * vvx + mfacb * (c1o1 - vx2) - c1o9 * oMdrho * vx2; - m2 = mfccb * c1o2 + mfbcb * (vvx + c1o2) + (mfacb + c1o9 * oMdrho) * (vx2 + vvx) * c1o2; - mfacb = m0; - mfbcb = m1; - mfccb = m2; - //////////////////////////////////////////////////////////////////////////////////// - //////////////////////////////////////////////////////////////////////////////////// - m0 = mfcac * c1o2 + mfbac * (vvx - c1o2) + (mfaac + c1o36 * oMdrho) * (vx2 - vvx) * c1o2; - m1 = -mfcac - c2o1* mfbac * vvx + mfaac * (c1o1 - vx2) - c1o36 * oMdrho * vx2; - m2 = mfcac * c1o2 + mfbac * (vvx + c1o2) + (mfaac + c1o36 * oMdrho) * (vx2 + vvx) * c1o2; - mfaac = m0; - mfbac = m1; - mfcac = m2; - ///////////c//////////////////////////////////////////////////////////////////////// - m0 = mfcbc * c1o2 + mfbbc * (vvx - c1o2) + (mfabc + c1o9 * oMdrho) * (vx2 - vvx) * c1o2; - m1 = -mfcbc - c2o1* mfbbc * vvx + mfabc * (c1o1 - vx2) - c1o9 * oMdrho * vx2; - m2 = mfcbc * c1o2 + mfbbc * (vvx + c1o2) + (mfabc + c1o9 * oMdrho) * (vx2 + vvx) * c1o2; - mfabc = m0; - mfbbc = m1; - mfcbc = m2; - ///////////c//////////////////////////////////////////////////////////////////////// - m0 = mfccc * c1o2 + mfbcc * (vvx - c1o2) + (mfacc + c1o36 * oMdrho) * (vx2 - vvx) * c1o2; - m1 = -mfccc - c2o1* mfbcc * vvx + mfacc * (c1o1 - vx2) - c1o36 * oMdrho * vx2; - m2 = mfccc * c1o2 + mfbcc * (vvx + c1o2) + (mfacc + c1o36 * oMdrho) * (vx2 + vvx) * c1o2; - mfacc = m0; - mfbcc = m1; - mfccc = m2; - //////////////////////////////////////////////////////////////////////////////////// - - //////////////////////////////////////////////////////////////////////////////////// - (D.f[DIR_P00])[k] = mfabb;//(D.f[ DIR_P00 ])[ke ] = mfabb;// - c2over27 ; (D.f[ DIR_P00 ])[k ] - (D.f[DIR_M00])[kw] = mfcbb;//(D.f[ DIR_M00 ])[kw ] = mfcbb;// - c2over27 ; (D.f[ DIR_M00 ])[kw ] - (D.f[DIR_0P0])[k] = mfbab;//(D.f[ DIR_0P0 ])[kn ] = mfbab;// - c2over27 ; (D.f[ DIR_0P0 ])[k ] - (D.f[DIR_0M0])[ks] = mfbcb;//(D.f[ DIR_0M0 ])[ks ] = mfbcb;// - c2over27 ; (D.f[ DIR_0M0 ])[ks ] - (D.f[DIR_00P])[k] = mfbba;//(D.f[ DIR_00P ])[kt ] = mfbba;// - c2over27 ; (D.f[ DIR_00P ])[k ] - (D.f[DIR_00M])[kb] = mfbbc;//(D.f[ DIR_00M ])[kb ] = mfbbc;// - c2over27 ; (D.f[ DIR_00M ])[kb ] - (D.f[DIR_PP0])[k] = mfaab;//(D.f[ DIR_PP0 ])[kne ] = mfaab;// - c1over54 ; (D.f[ DIR_PP0 ])[k ] - (D.f[DIR_MM0])[ksw] = mfccb;//(D.f[ DIR_MM0 ])[ksw ] = mfccb;// - c1over54 ; (D.f[ DIR_MM0 ])[ksw ] - (D.f[DIR_PM0])[ks] = mfacb;//(D.f[ DIR_PM0 ])[kse ] = mfacb;// - c1over54 ; (D.f[ DIR_PM0 ])[ks ] - (D.f[DIR_MP0])[kw] = mfcab;//(D.f[ DIR_MP0 ])[knw ] = mfcab;// - c1over54 ; (D.f[ DIR_MP0 ])[kw ] - (D.f[DIR_P0P])[k] = mfaba;//(D.f[ DIR_P0P ])[kte ] = mfaba;// - c1over54 ; (D.f[ DIR_P0P ])[k ] - (D.f[DIR_M0M])[kbw] = mfcbc;//(D.f[ DIR_M0M ])[kbw ] = mfcbc;// - c1over54 ; (D.f[ DIR_M0M ])[kbw ] - (D.f[DIR_P0M])[kb] = mfabc;//(D.f[ DIR_P0M ])[kbe ] = mfabc;// - c1over54 ; (D.f[ DIR_P0M ])[kb ] - (D.f[DIR_M0P])[kw] = mfcba;//(D.f[ DIR_M0P ])[ktw ] = mfcba;// - c1over54 ; (D.f[ DIR_M0P ])[kw ] - (D.f[DIR_0PP])[k] = mfbaa;//(D.f[ DIR_0PP ])[ktn ] = mfbaa;// - c1over54 ; (D.f[ DIR_0PP ])[k ] - (D.f[DIR_0MM])[kbs] = mfbcc;//(D.f[ DIR_0MM ])[kbs ] = mfbcc;// - c1over54 ; (D.f[ DIR_0MM ])[kbs ] - (D.f[DIR_0PM])[kb] = mfbac;//(D.f[ DIR_0PM ])[kbn ] = mfbac;// - c1over54 ; (D.f[ DIR_0PM ])[kb ] - (D.f[DIR_0MP])[ks] = mfbca;//(D.f[ DIR_0MP ])[kts ] = mfbca;// - c1over54 ; (D.f[ DIR_0MP ])[ks ] - (D.f[DIR_000])[k] = mfbbb;//(D.f[ DIR_000])[kzero] = mfbbb;// - c8over27 ; (D.f[ DIR_000])[k ] - (D.f[DIR_PPP])[k] = mfaaa;//(D.f[ DIR_PPP ])[ktne ] = mfaaa;// - c1over216; (D.f[ DIR_PPP ])[k ] - (D.f[DIR_PMP])[ks] = mfaca;//(D.f[ DIR_PMP ])[ktse ] = mfaca;// - c1over216; (D.f[ DIR_PMP ])[ks ] - (D.f[DIR_PPM])[kb] = mfaac;//(D.f[ DIR_PPM ])[kbne ] = mfaac;// - c1over216; (D.f[ DIR_PPM ])[kb ] - (D.f[DIR_PMM])[kbs] = mfacc;//(D.f[ DIR_PMM ])[kbse ] = mfacc;// - c1over216; (D.f[ DIR_PMM ])[kbs ] - (D.f[DIR_MPP])[kw] = mfcaa;//(D.f[ DIR_MPP ])[ktnw ] = mfcaa;// - c1over216; (D.f[ DIR_MPP ])[kw ] - (D.f[DIR_MMP])[ksw] = mfcca;//(D.f[ DIR_MMP ])[ktsw ] = mfcca;// - c1over216; (D.f[ DIR_MMP ])[ksw ] - (D.f[DIR_MPM])[kbw] = mfcac;//(D.f[ DIR_MPM ])[kbnw ] = mfcac;// - c1over216; (D.f[ DIR_MPM ])[kbw ] - (D.f[DIR_MMM])[kbsw] = mfccc;//(D.f[ DIR_MMM ])[kbsw ] = mfccc;// - c1over216; (D.f[ DIR_MMM ])[kbsw] - //////////////////////////////////////////////////////////////////////////////////// - } - } -} \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17Comp_Device.cuh b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17Comp_Device.cuh deleted file mode 100644 index f44842057d554498b0b5d4c733e2425e524a3b75..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17Comp_Device.cuh +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef LB_Kernel_CUMULANT_K17_COMP_H -#define LB_Kernel_CUMULANT_K17_COMP_H - -#include <DataTypes.h> -#include <curand.h> - -__global__ void LB_Kernel_CumulantK17Comp( real omega, - unsigned int* bcMatD, - unsigned int* neighborX, - unsigned int* neighborY, - unsigned int* neighborZ, - real* DDStart, - int size_Mat, - int level, - real* forces, - real* quadricLimiters, - bool EvenOrOdd); -#endif diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimRedesigned/CumulantK17CompChimRedesignedDevice.cu b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17_Device.cu similarity index 65% rename from src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimRedesigned/CumulantK17CompChimRedesignedDevice.cu rename to src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17_Device.cu index db8caf1b23c2087a4c5c76886fb4530bc6272a1d..34a444230019a1c6cfacb18e12fd73607fb2e09a 100644 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimRedesigned/CumulantK17CompChimRedesignedDevice.cu +++ b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17_Device.cu @@ -1,4 +1,4 @@ -//======================================================================================= + // ____ ____ __ ______ __________ __ __ __ __ // \ \ | | | | | _ \ |___ ___| | | | | / \ | | // \ \ | | | | | |_) | | | | | | | / \ | | @@ -26,9 +26,20 @@ // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // -//! \file Cumulant27chimStream.cu -//! \ingroup GPU -//! \author Martin Schoenherr, Anna Wellmann +//! \file CumlantK17_Device.cu +//! \author Anna Wellmann, Martin Schönherr, Henry Korb, Henrik Asmuth +//! \date 05/12/2022 +//! \brief Kernel for CumulantK17 including different turbulence models and options for local body forces and writing macroscopic variables +//! +//! CumulantK17 kernel using chimera transformations and quartic limiters as present in Geier et al. (2017). Additional options are three different +//! eddy-viscosity turbulence models (Smagorinsky, AMD, QR) that can be set via the template parameter turbulenceModel (with default +//! TurbulenceModel::None). +//! The kernel is executed separately for each subset of fluid node indices with a different tag CollisionTemplate. For each subset, only the locally +//! required options are switched on ( \param writeMacroscopicVariables and/or \param applyBodyForce) in order to minimize memory accesses. The default +//! refers to the plain cumlant kernel (CollisionTemplate::Default). +//! Nodes are added to subsets (taggedFluidNodes) in Simulation::init using a corresponding tag with different values of CollisionTemplate. These subsets +//! are provided by the utilized PostCollisionInteractiors depending on they specifc requirements (e.g. writeMacroscopicVariables for probes). + //======================================================================================= /* Device code */ #include "LBM/LB.h" @@ -36,22 +47,35 @@ #include <lbm/constants/NumericConstants.h> #include "Kernel/Utilities/DistributionHelper.cuh" +#include "GPU/TurbulentViscosityInlines.cuh" + using namespace vf::lbm::constant; using namespace vf::lbm::dir; #include "Kernel/Utilities/ChimeraTransformation.h" + //////////////////////////////////////////////////////////////////////////////// -__global__ void LB_Kernel_CumulantK17CompChimRedesigned( - real omega, - uint* neighborX, - uint* neighborY, - uint* neighborZ, - real* distributions, - unsigned long numberOfLBnodes, - int level, - real* forces, - real* quadricLimiters, - bool isEvenTimestep, +template<TurbulenceModel turbulenceModel, bool writeMacroscopicVariables, bool applyBodyForce> +__global__ void LB_Kernel_CumulantK17( + real omega_in, + uint* neighborX, + uint* neighborY, + uint* neighborZ, + real* distributions, + real* rho, + real* vx, + real* vy, + real* vz, + real* turbulentViscosity, + real SGSconstant, + unsigned long numberOfLBnodes, + int level, + real* forces, + real* bodyForceX, + real* bodyForceY, + real* bodyForceZ, + real* quadricLimiters, + bool isEvenTimestep, const uint *fluidNodeIndices, uint numberOfFluidNodes) { @@ -64,15 +88,14 @@ __global__ void LB_Kernel_CumulantK17CompChimRedesigned( //! The cumulant kernel is executed in the following steps //! //////////////////////////////////////////////////////////////////////////////// - //! - Get the thread index coordinates from threadIdx, blockIdx, blockDim and gridDim. + //! - Get node index coordinates from threadIdx, blockIdx, blockDim and gridDim. //! const unsigned kThread = vf::gpu::getNodeIndex(); - + ////////////////////////////////////////////////////////////////////////// - //! - Return for non-fluid nodes + // run for all indices in size_Mat and fluid nodes if (kThread >= numberOfFluidNodes) return; - //////////////////////////////////////////////////////////////////////////////// //! - Get the node index from the array containing all indices of fluid nodes //! @@ -85,10 +108,9 @@ __global__ void LB_Kernel_CumulantK17CompChimRedesigned( //! DOI:10.3390/computation5020019 ]</b></a> //! Distributions27 dist = vf::gpu::getDistributionReferences27(distributions, numberOfLBnodes, isEvenTimestep); - + //////////////////////////////////////////////////////////////////////////////// //! - Set neighbor indices (necessary for indirect addressing) - //! uint k_M00 = neighborX[k_000]; uint k_0M0 = neighborY[k_000]; uint k_00M = neighborZ[k_000]; @@ -96,9 +118,8 @@ __global__ void LB_Kernel_CumulantK17CompChimRedesigned( uint k_M0M = neighborZ[k_M00]; uint k_0MM = neighborZ[k_0M0]; uint k_MMM = neighborZ[k_MM0]; - //////////////////////////////////////////////////////////////////////////////////// - //! - Set local distributions (f's): + //! - Set local distributions //! real f_000 = (dist.f[DIR_000])[k_000]; real f_P00 = (dist.f[DIR_P00])[k_000]; @@ -159,45 +180,84 @@ __global__ void LB_Kernel_CumulantK17CompChimRedesigned( real& m_200 = f_PMM; real& m_000 = f_MMM; - //////////////////////////////////////////////////////////////////////////////////// + //////////////////////////////////////////////////////(unsigned long)////////////////////////////// //! - Calculate density and velocity using pyramid summation for low round-off errors as in Eq. (J1)-(J3) \ref //! <a href="https://doi.org/10.1016/j.camwa.2015.05.001"><b>[ M. Geier et al. (2015), //! DOI:10.1016/j.camwa.2015.05.001 ]</b></a> //! real drho = ((((f_PPP + f_MMM) + (f_MPM + f_PMP)) + ((f_MPP + f_PMM) + (f_MMP + f_PPM))) + - (((f_0MP + f_0PM) + (f_0MM + f_0PP)) + ((f_M0P + f_P0M) + (f_M0M + f_P0P)) + - ((f_MP0 + f_PM0) + (f_MM0 + f_PP0))) + - ((f_M00 + f_P00) + (f_0M0 + f_0P0) + (f_00M + f_00P))) + + (((f_0MP + f_0PM) + (f_0MM + f_0PP)) + ((f_M0P + f_P0M) + (f_M0M + f_P0P)) + + ((f_MP0 + f_PM0) + (f_MM0 + f_PP0))) + + ((f_M00 + f_P00) + (f_0M0 + f_0P0) + (f_00M + f_00P))) + f_000; real oneOverRho = c1o1 / (c1o1 + drho); real vvx = ((((f_PPP - f_MMM) + (f_PMP - f_MPM)) + ((f_PMM - f_MPP) + (f_PPM - f_MMP))) + (((f_P0M - f_M0P) + (f_P0P - f_M0M)) + ((f_PM0 - f_MP0) + (f_PP0 - f_MM0))) + (f_P00 - f_M00)) * - oneOverRho; + oneOverRho; real vvy = ((((f_PPP - f_MMM) + (f_MPM - f_PMP)) + ((f_MPP - f_PMM) + (f_PPM - f_MMP))) + (((f_0PM - f_0MP) + (f_0PP - f_0MM)) + ((f_MP0 - f_PM0) + (f_PP0 - f_MM0))) + (f_0P0 - f_0M0)) * - oneOverRho; + oneOverRho; real vvz = ((((f_PPP - f_MMM) + (f_PMP - f_MPM)) + ((f_MPP - f_PMM) + (f_MMP - f_PPM))) + (((f_0MP - f_0PM) + (f_0PP - f_0MM)) + ((f_M0P - f_P0M) + (f_P0P - f_M0M))) + (f_00P - f_00M)) * - oneOverRho; - + oneOverRho; + //////////////////////////////////////////////////////////////////////////////////// //! - Add half of the acceleration (body force) to the velocity as in Eq. (42) \ref //! <a href="https://doi.org/10.1016/j.camwa.2015.05.001"><b>[ M. Geier et al. (2015), //! DOI:10.1016/j.camwa.2015.05.001 ]</b></a> //! real factor = c1o1; - // The factor has to be scaled for each level to get the correct acceleration. for (size_t i = 1; i <= level; i++) { factor *= c2o1; } - real fx = forces[0] / factor; - real fy = forces[1] / factor; - real fz = forces[2] / factor; - vvx += fx * c1o2; - vvy += fy * c1o2; - vvz += fz * c1o2; + + real fx = forces[0]; + real fy = forces[1]; + real fz = forces[2]; + + if( applyBodyForce ){ + fx += bodyForceX[k_000]; + fy += bodyForceY[k_000]; + fz += bodyForceZ[k_000]; + + // real vx = vvx; + // real vy = vvy; + // real vz = vvz; + real acc_x = fx * c1o2 / factor; + real acc_y = fy * c1o2 / factor; + real acc_z = fz * c1o2 / factor; + + vvx += acc_x; + vvy += acc_y; + vvz += acc_z; + + // Reset body force. To be used when not using round-off correction. + bodyForceX[k_000] = 0.0f; + bodyForceY[k_000] = 0.0f; + bodyForceZ[k_000] = 0.0f; + + //////////////////////////////////////////////////////////////////////////////////// + //!> Round-off correction + //! + //!> Similar to Kahan summation algorithm (https://en.wikipedia.org/wiki/Kahan_summation_algorithm) + //!> Essentially computes the round-off error of the applied force and adds it in the next time step as a compensation. + //!> Seems to be necesseary at very high Re boundary layers, where the forcing and velocity can + //!> differ by several orders of magnitude. + //!> \note 16/05/2022: Testing, still ongoing! + //! + // bodyForceX[k_000] = (acc_x-(vvx-vx))*factor*c2o1; + // bodyForceY[k_000] = (acc_y-(vvy-vy))*factor*c2o1; + // bodyForceZ[k_000] = (acc_z-(vvz-vz))*factor*c2o1; + } + else{ + vvx += fx * c1o2 / factor; + vvy += fy * c1o2 / factor; + vvz += fz * c1o2 / factor; + } + + //////////////////////////////////////////////////////////////////////////////////// // calculate the square of velocities for this lattice node real vx2 = vvx * vvx; @@ -272,15 +332,21 @@ __global__ void LB_Kernel_CumulantK17CompChimRedesigned( //! - Fifth order cumulants \f$ C_{221}, C_{212}, C_{122}\f$: \f$\omega_9=O5=1.0\f$. //! - Sixth order cumulant \f$ C_{222}\f$: \f$\omega_{10}=O6=1.0\f$. //! + //////////////////////////////////////////////////////////////////////////////////// + //! - Calculate modified omega with turbulent viscosity + //! + real omega = omega_in; + if(turbulenceModel != TurbulenceModel::None){ omega /= (c1o1 + c3o1*omega_in*turbulentViscosity[k_000]); } //////////////////////////////////////////////////////////// // 2. real OxxPyyPzz = c1o1; //////////////////////////////////////////////////////////// // 3. - real OxyyPxzz = c8o1 * (-c2o1 + omega) * (c1o1 + c2o1 * omega) / (-c8o1 - c14o1 * omega + c7o1 * omega * omega); - real OxyyMxzz = c8o1 * (-c2o1 + omega) * (-c7o1 + c4o1 * omega) / (c56o1 - c50o1 * omega + c9o1 * omega * omega); - real Oxyz = c24o1 * (-c2o1 + omega) * (-c2o1 - c7o1 * omega + c3o1 * omega * omega) / - (c48o1 + c152o1 * omega - c130o1 * omega * omega + c29o1 * omega * omega * omega); + real OxyyPxzz = c8o1 * (-c2o1 + omega) * (c1o1 + c2o1 * omega) / (-c8o1 - c14o1 * omega + c7o1 * omega * omega); + real OxyyMxzz = + c8o1 * (-c2o1 + omega) * (-c7o1 + c4o1 * omega) / (c56o1 - c50o1 * omega + c9o1 * omega * omega); + real Oxyz = c24o1 * (-c2o1 + omega) * (-c2o1 - c7o1 * omega + c3o1 * omega * omega) / + (c48o1 + c152o1 * omega - c130o1 * omega * omega + c29o1 * omega * omega * omega); //////////////////////////////////////////////////////////// // 4. real O4 = c1o1; @@ -292,16 +358,16 @@ __global__ void LB_Kernel_CumulantK17CompChimRedesigned( real O6 = c1o1; //////////////////////////////////////////////////////////////////////////////////// - //! - A and B: parameters for fourth order convergence of the diffusion term according to Eq. (115) and (116) + //! - A and DIR_00M: parameters for fourth order convergence of the diffusion term according to Eq. (115) and (116) //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> with simplifications assuming \f$ \omega_2 = 1.0 \f$ (modify for //! different bulk viscosity). //! - real factorA = (c4o1 + c2o1 * omega - c3o1 * omega * omega) / (c2o1 - c7o1 * omega + c5o1 * omega * omega); + real factorA = (c4o1 + c2o1 * omega - c3o1 * omega * omega) / (c2o1 - c7o1 * omega + c5o1 * omega * omega); real factorB = (c4o1 + c28o1 * omega - c14o1 * omega * omega) / (c6o1 - c21o1 * omega + c15o1 * omega * omega); //////////////////////////////////////////////////////////////////////////////////// - //! - Compute cumulants (c's) from central moments according to Eq. (20)-(23) in + //! - Compute cumulants from central moments according to Eq. (20)-(23) in //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> //! @@ -318,27 +384,27 @@ __global__ void LB_Kernel_CumulantK17CompChimRedesigned( // 5. real c_122 = m_122 - ((m_002 * m_120 + m_020 * m_102 + c4o1 * m_011 * m_111 + c2o1 * (m_101 * m_021 + m_110 * m_012)) + - c1o3 * (m_120 + m_102)) * - oneOverRho; + c1o3 * (m_120 + m_102)) * + oneOverRho; real c_212 = m_212 - ((m_002 * m_210 + m_200 * m_012 + c4o1 * m_101 * m_111 + c2o1 * (m_011 * m_201 + m_110 * m_102)) + - c1o3 * (m_210 + m_012)) * - oneOverRho; + c1o3 * (m_210 + m_012)) * + oneOverRho; real c_221 = m_221 - ((m_200 * m_021 + m_020 * m_201 + c4o1 * m_110 * m_111 + c2o1 * (m_101 * m_120 + m_011 * m_210)) + - c1o3 * (m_021 + m_201)) * - oneOverRho; + c1o3 * (m_021 + m_201)) * + oneOverRho; //////////////////////////////////////////////////////////// // 6. real c_222 = m_222 + ((-c4o1 * m_111 * m_111 - (m_200 * m_022 + m_020 * m_202 + m_002 * m_220) - c4o1 * (m_011 * m_211 + m_101 * m_121 + m_110 * m_112) - c2o1 * (m_120 * m_102 + m_210 * m_012 + m_201 * m_021)) * oneOverRho + - (c4o1 * (m_101 * m_101 * m_020 + m_011 * m_011 * m_200 + m_110 * m_110 * m_002) + + (c4o1 * (m_101 * m_101 * m_020 + m_011 * m_011 * m_200 + m_110 * m_110 * m_002) + c2o1 * (m_200 * m_020 * m_002) + c16o1 * m_110 * m_101 * m_011) * oneOverRho * oneOverRho - c1o3 * (m_022 + m_202 + m_220) * oneOverRho - c1o9 * (m_200 + m_020 + m_002) * oneOverRho + - (c2o1 * (m_101 * m_101 + m_011 * m_011 + m_110 * m_110) + + (c2o1 * (m_101 * m_101 + m_011 * m_011 + m_110 * m_110) + (m_002 * m_020 + m_002 * m_200 + m_020 * m_200) + c1o3 * (m_002 + m_020 + m_200)) * oneOverRho * oneOverRho * c2o3 + c1o27 * ((drho * drho - drho) * oneOverRho * oneOverRho)); @@ -378,6 +444,22 @@ __global__ void LB_Kernel_CumulantK17CompChimRedesigned( real dxux = c1o2 * (-omega) * (mxxMyy + mxxMzz) + c1o2 * OxxPyyPzz * (m_000 - mxxPyyPzz); real dyuy = dxux + omega * c3o2 * mxxMyy; real dzuz = dxux + omega * c3o2 * mxxMzz; + + //////////////////////////////////////////////////////////////////////////////////// + switch (turbulenceModel) + { + case TurbulenceModel::None: + case TurbulenceModel::AMD: //AMD is computed in separate kernel + break; + case TurbulenceModel::Smagorinsky: + turbulentViscosity[k_000] = calcTurbulentViscositySmagorinsky(SGSconstant, dxux, dyuy, dzuz, Dxy, Dxz , Dyz); + break; + case TurbulenceModel::QR: + turbulentViscosity[k_000] = calcTurbulentViscosityQR(SGSconstant, dxux, dyuy, dzuz, Dxy, Dxz , Dyz); + break; + default: + break; + } //////////////////////////////////////////////////////////// //! - Relaxation of second order cumulants with correction terms according to Eq. (33)-(35) in //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), @@ -386,7 +468,6 @@ __global__ void LB_Kernel_CumulantK17CompChimRedesigned( mxxPyyPzz += OxxPyyPzz * (m_000 - mxxPyyPzz) - c3o1 * (c1o1 - c1o2 * OxxPyyPzz) * (vx2 * dxux + vy2 * dyuy + vz2 * dzuz); mxxMyy += omega * (-mxxMyy) - c3o1 * (c1o1 + c1o2 * (-omega)) * (vx2 * dxux - vy2 * dyuy); mxxMzz += omega * (-mxxMzz) - c3o1 * (c1o1 + c1o2 * (-omega)) * (vx2 * dxux - vz2 * dzuz); - ////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// ////no correction @@ -394,18 +475,18 @@ __global__ void LB_Kernel_CumulantK17CompChimRedesigned( // mxxMyy += -(-omega) * (-mxxMyy); // mxxMzz += -(-omega) * (-mxxMzz); ////////////////////////////////////////////////////////////////////////// - m_011 += omega * (-m_011); m_101 += omega * (-m_101); m_110 += omega * (-m_110); + //////////////////////////////////////////////////////////////////////////////////// + // relax ////////////////////////////////////////////////////////////////////////// + // incl. limiter //! - Relaxation of third order cumulants including limiter according to Eq. (116)-(123) //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> //! - ////////////////////////////////////////////////////////////////////////// - // incl. limiter real wadjust = Oxyz + (c1o1 - Oxyz) * abs(m_111) / (abs(m_111) + quadricLimitD); m_111 += wadjust * (-m_111); wadjust = OxyyPxzz + (c1o1 - OxyyPxzz) * abs(mxxyPyzz) / (abs(mxxyPyzz) + quadricLimitP); @@ -459,6 +540,7 @@ __global__ void LB_Kernel_CumulantK17CompChimRedesigned( c_121 = -O4 * (c1o1 / omega - c1o2) * Dxz * c1o3 * factorB + (c1o1 - O4) * (c_121); c_211 = -O4 * (c1o1 / omega - c1o2) * Dyz * c1o3 * factorB + (c1o1 - O4) * (c_211); + ////////////////////////////////////////////////////////////////////////// // 5. c_122 += O5 * (-c_122); @@ -503,17 +585,17 @@ __global__ void LB_Kernel_CumulantK17CompChimRedesigned( ////////////////////////////////////////////////////////////////////////// // 6. m_222 = c_222 - ((-c4o1 * m_111 * m_111 - (m_200 * m_022 + m_020 * m_202 + m_002 * m_220) - - c4o1 * (m_011 * m_211 + m_101 * m_121 + m_110 * m_112) - - c2o1 * (m_120 * m_102 + m_210 * m_012 + m_201 * m_021)) * - oneOverRho + - (c4o1 * (m_101 * m_101 * m_020 + m_011 * m_011 * m_200 + m_110 * m_110 * m_002) + - c2o1 * (m_200 * m_020 * m_002) + c16o1 * m_110 * m_101 * m_011) * - oneOverRho * oneOverRho - - c1o3 * (m_022 + m_202 + m_220) * oneOverRho - c1o9 * (m_200 + m_020 + m_002) * oneOverRho + - (c2o1 * (m_101 * m_101 + m_011 * m_011 + m_110 * m_110) + - (m_002 * m_020 + m_002 * m_200 + m_020 * m_200) + c1o3 * (m_002 + m_020 + m_200)) * - oneOverRho * oneOverRho * c2o3 + - c1o27 * ((drho * drho - drho) * oneOverRho * oneOverRho)); + c4o1 * (m_011 * m_211 + m_101 * m_121 + m_110 * m_112) - + c2o1 * (m_120 * m_102 + m_210 * m_012 + m_201 * m_021)) * + oneOverRho + + (c4o1 * (m_101 * m_101 * m_020 + m_011 * m_011 * m_200 + m_110 * m_110 * m_002) + + c2o1 * (m_200 * m_020 * m_002) + c16o1 * m_110 * m_101 * m_011) * + oneOverRho * oneOverRho - + c1o3 * (m_022 + m_202 + m_220) * oneOverRho - c1o9 * (m_200 + m_020 + m_002) * oneOverRho + + (c2o1 * (m_101 * m_101 + m_011 * m_011 + m_110 * m_110) + + (m_002 * m_020 + m_002 * m_200 + m_020 * m_200) + c1o3 * (m_002 + m_020 + m_200)) * + oneOverRho * oneOverRho * c2o3 + + c1o27 * ((drho * drho - drho) * oneOverRho * oneOverRho)); //////////////////////////////////////////////////////////////////////////////////// //! - Add acceleration (body force) to first order cumulants according to Eq. (85)-(87) in @@ -524,6 +606,15 @@ __global__ void LB_Kernel_CumulantK17CompChimRedesigned( m_010 = -m_010; m_001 = -m_001; + //Write to array here to distribute read/write + if(writeMacroscopicVariables) + { + rho[k_000] = drho; + vx[k_000] = vvx; + vy[k_000] = vvy; + vz[k_000] = vvz; + } + //////////////////////////////////////////////////////////////////////////////////// //! - Chimera transform from central moments to well conditioned distributions as defined in Appendix J in //! <a href="https://doi.org/10.1016/j.camwa.2015.05.001"><b>[ M. Geier et al. (2015), @@ -573,31 +664,63 @@ __global__ void LB_Kernel_CumulantK17CompChimRedesigned( //! <a href="https://doi.org/10.3390/computation5020019"><b>[ M. Geier et al. (2017), //! DOI:10.3390/computation5020019 ]</b></a> //! - (dist.f[DIR_P00])[k_000] = f_M00; - (dist.f[DIR_M00])[k_M00] = f_P00; - (dist.f[DIR_0P0])[k_000] = f_0M0; - (dist.f[DIR_0M0])[k_0M0] = f_0P0; - (dist.f[DIR_00P])[k_000] = f_00M; - (dist.f[DIR_00M])[k_00M] = f_00P; - (dist.f[DIR_PP0])[k_000] = f_MM0; - (dist.f[DIR_MM0])[k_MM0] = f_PP0; - (dist.f[DIR_PM0])[k_0M0] = f_MP0; - (dist.f[DIR_MP0])[k_M00] = f_PM0; - (dist.f[DIR_P0P])[k_000] = f_M0M; - (dist.f[DIR_M0M])[k_M0M] = f_P0P; - (dist.f[DIR_P0M])[k_00M] = f_M0P; - (dist.f[DIR_M0P])[k_M00] = f_P0M; - (dist.f[DIR_0PP])[k_000] = f_0MM; - (dist.f[DIR_0MM])[k_0MM] = f_0PP; - (dist.f[DIR_0PM])[k_00M] = f_0MP; - (dist.f[DIR_0MP])[k_0M0] = f_0PM; + (dist.f[DIR_P00])[k_000] = f_M00; + (dist.f[DIR_M00])[k_M00] = f_P00; + (dist.f[DIR_0P0])[k_000] = f_0M0; + (dist.f[DIR_0M0])[k_0M0] = f_0P0; + (dist.f[DIR_00P])[k_000] = f_00M; + (dist.f[DIR_00M])[k_00M] = f_00P; + (dist.f[DIR_PP0])[k_000] = f_MM0; + (dist.f[DIR_MM0])[k_MM0] = f_PP0; + (dist.f[DIR_PM0])[k_0M0] = f_MP0; + (dist.f[DIR_MP0])[k_M00] = f_PM0; + (dist.f[DIR_P0P])[k_000] = f_M0M; + (dist.f[DIR_M0M])[k_M0M] = f_P0P; + (dist.f[DIR_P0M])[k_00M] = f_M0P; + (dist.f[DIR_M0P])[k_M00] = f_P0M; + (dist.f[DIR_0PP])[k_000] = f_0MM; + (dist.f[DIR_0MM])[k_0MM] = f_0PP; + (dist.f[DIR_0PM])[k_00M] = f_0MP; + (dist.f[DIR_0MP])[k_0M0] = f_0PM; (dist.f[DIR_000])[k_000] = f_000; - (dist.f[DIR_PPP])[k_000] = f_MMM; - (dist.f[DIR_PMP])[k_0M0] = f_MPM; - (dist.f[DIR_PPM])[k_00M] = f_MMP; - (dist.f[DIR_PMM])[k_0MM] = f_MPP; - (dist.f[DIR_MPP])[k_M00] = f_PMM; - (dist.f[DIR_MMP])[k_MM0] = f_PPM; - (dist.f[DIR_MPM])[k_M0M] = f_PMP; - (dist.f[DIR_MMM])[k_MMM] = f_PPP; -} \ No newline at end of file + (dist.f[DIR_PPP])[k_000] = f_MMM; + (dist.f[DIR_PMP])[k_0M0] = f_MPM; + (dist.f[DIR_PPM])[k_00M] = f_MMP; + (dist.f[DIR_PMM])[k_0MM] = f_MPP; + (dist.f[DIR_MPP])[k_M00] = f_PMM; + (dist.f[DIR_MMP])[k_MM0] = f_PPM; + (dist.f[DIR_MPM])[k_M0M] = f_PMP; + (dist.f[DIR_MMM])[k_MMM] = f_PPP; +} + +template __global__ void LB_Kernel_CumulantK17 < TurbulenceModel::AMD, true, true > ( real omega_in, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep, const uint *fluidNodeIndices, uint numberOfFluidNodes); + +template __global__ void LB_Kernel_CumulantK17 < TurbulenceModel::Smagorinsky, true, true > ( real omega_in, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep, const uint *fluidNodeIndices, uint numberOfFluidNodes); + +template __global__ void LB_Kernel_CumulantK17 < TurbulenceModel::QR, true, true > ( real omega_in, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep, const uint *fluidNodeIndices, uint numberOfFluidNodes); + +template __global__ void LB_Kernel_CumulantK17 < TurbulenceModel::None, true, true > ( real omega_in, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep, const uint *fluidNodeIndices, uint numberOfFluidNodes); + +template __global__ void LB_Kernel_CumulantK17 < TurbulenceModel::AMD, true, false > ( real omega_in, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep, const uint *fluidNodeIndices, uint numberOfFluidNodes); + +template __global__ void LB_Kernel_CumulantK17 < TurbulenceModel::Smagorinsky, true, false > ( real omega_in, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep, const uint *fluidNodeIndices, uint numberOfFluidNodes); + +template __global__ void LB_Kernel_CumulantK17 < TurbulenceModel::QR, true, false > ( real omega_in, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep, const uint *fluidNodeIndices, uint numberOfFluidNodes); + +template __global__ void LB_Kernel_CumulantK17 < TurbulenceModel::None, true, false > ( real omega_in, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep, const uint *fluidNodeIndices, uint numberOfFluidNodes); + +template __global__ void LB_Kernel_CumulantK17 < TurbulenceModel::AMD, false, true > ( real omega_in, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep, const uint *fluidNodeIndices, uint numberOfFluidNodes); + +template __global__ void LB_Kernel_CumulantK17 < TurbulenceModel::Smagorinsky, false, true > ( real omega_in, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep, const uint *fluidNodeIndices, uint numberOfFluidNodes); + +template __global__ void LB_Kernel_CumulantK17 < TurbulenceModel::QR, false, true > ( real omega_in, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep, const uint *fluidNodeIndices, uint numberOfFluidNodes); + +template __global__ void LB_Kernel_CumulantK17 < TurbulenceModel::None, false, true > ( real omega_in, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep, const uint *fluidNodeIndices, uint numberOfFluidNodes); + +template __global__ void LB_Kernel_CumulantK17 < TurbulenceModel::AMD, false, false > ( real omega_in, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep, const uint *fluidNodeIndices, uint numberOfFluidNodes); + +template __global__ void LB_Kernel_CumulantK17 < TurbulenceModel::Smagorinsky, false, false > ( real omega_in, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep, const uint *fluidNodeIndices, uint numberOfFluidNodes); + +template __global__ void LB_Kernel_CumulantK17 < TurbulenceModel::QR, false, false > ( real omega_in, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep, const uint *fluidNodeIndices, uint numberOfFluidNodes); + +template __global__ void LB_Kernel_CumulantK17 < TurbulenceModel::None, false, false > ( real omega_in, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep, const uint *fluidNodeIndices, uint numberOfFluidNodes); \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/CumulantK17chim/TurbulentViscosityCumulantK17CompChim_Device.cuh b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17_Device.cuh similarity index 51% rename from src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/CumulantK17chim/TurbulentViscosityCumulantK17CompChim_Device.cuh rename to src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17_Device.cuh index 5ef37557399f263d25edf03b02b00f6a03c6e1cb..b8cc9543e9b531c5aa90cb2961416a6cbc52377d 100644 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/CumulantK17chim/TurbulentViscosityCumulantK17CompChim_Device.cuh +++ b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17_Device.cuh @@ -1,12 +1,11 @@ -#ifndef LB_Kernel_TURBULENT_VISCOSITY_CUMULANT_K17_COMP_CHIM_H -#define LB_Kernel_TURBULENT_VISCOSITY_CUMULANT_K17_COMP_CHIM_H +#ifndef LB_Kernel_CUMULANT_K17_H +#define LB_Kernel_CUMULANT_K17_H #include <DataTypes.h> #include <curand.h> -template< TurbulenceModel turbulenceModel > __global__ void LB_Kernel_TurbulentViscosityCumulantK17CompChim( +template< TurbulenceModel turbulenceModel, bool writeMacroscopicVariables, bool applyBodyForce > __global__ void LB_Kernel_CumulantK17( real omega_in, - uint* typeOfGridNode, uint* neighborX, uint* neighborY, uint* neighborZ, @@ -17,13 +16,14 @@ template< TurbulenceModel turbulenceModel > __global__ void LB_Kernel_TurbulentV real* vz, real* turbulentViscosity, real SGSconstant, - unsigned long size_Mat, + unsigned long numberOfLBnodes, int level, - bool bodyForce, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, - bool isEvenTimestep); + bool isEvenTimestep, + const uint *fluidNodeIndices, + uint numberOfFluidNodes); #endif diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimRedesigned/CumulantK17CompChimRedesigned.cu b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimRedesigned/CumulantK17CompChimRedesigned.cu deleted file mode 100644 index 8c06b7117c8b1ef62b932a76bf5de0be2ae99b1c..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimRedesigned/CumulantK17CompChimRedesigned.cu +++ /dev/null @@ -1,61 +0,0 @@ -#include "CumulantK17CompChimRedesigned.h" - -#include "Parameter/Parameter.h" -#include "Parameter/CudaStreamManager.h" -#include "CumulantK17CompChimRedesigned_Device.cuh" - -#include <cuda.h> - -std::shared_ptr<CumulantK17CompChimRedesigned> CumulantK17CompChimRedesigned::getNewInstance(std::shared_ptr<Parameter> para, - int level) -{ - return std::shared_ptr<CumulantK17CompChimRedesigned>(new CumulantK17CompChimRedesigned(para, level)); -} - -void CumulantK17CompChimRedesigned::run() -{ - LB_Kernel_CumulantK17CompChimRedesigned <<< cudaGrid.grid, cudaGrid.threads >>>( - para->getParD(level)->omega, - para->getParD(level)->neighborX, - para->getParD(level)->neighborY, - para->getParD(level)->neighborZ, - para->getParD(level)->distributions.f[0], - para->getParD(level)->numberOfNodes, - level, - para->getForcesDev(), - para->getQuadricLimitersDev(), - para->getParD(level)->isEvenTimestep, - para->getParD(level)->fluidNodeIndices, - para->getParD(level)->numberOfFluidNodes); - getLastCudaError("LB_Kernel_CumulantK17CompChim execution failed"); -} - -void CumulantK17CompChimRedesigned::runOnIndices(const unsigned int *indices, unsigned int size_indices, int streamIndex) -{ - cudaStream_t stream = (streamIndex == -1) ? CU_STREAM_LEGACY : para->getStreamManager()->getStream(streamIndex); - - LB_Kernel_CumulantK17CompChimRedesigned<<< cudaGrid.grid, cudaGrid.threads, 0, stream>>>( - para->getParD(level)->omega, - para->getParD(level)->neighborX, - para->getParD(level)->neighborY, - para->getParD(level)->neighborZ, - para->getParD(level)->distributions.f[0], - para->getParD(level)->numberOfNodes, - level, - para->getForcesDev(), - para->getQuadricLimitersDev(), - para->getParD(level)->isEvenTimestep, - indices, - size_indices); - getLastCudaError("LB_Kernel_CumulantK17CompChim execution failed"); - -} - -CumulantK17CompChimRedesigned::CumulantK17CompChimRedesigned(std::shared_ptr<Parameter> para, int level): KernelImp(para, level) -{ - myPreProcessorTypes.push_back(InitCompSP27); - myKernelGroup = BasicKernel; - this->cudaGrid = vf::cuda::CudaGrid(para->getParD(level)->numberofthreads, para->getParD(level)->numberOfNodes); - this->kernelUsesFluidNodeIndices = true; -} - diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimRedesigned/CumulantK17CompChimRedesigned.h b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimRedesigned/CumulantK17CompChimRedesigned.h deleted file mode 100644 index 4658075de330665fdba88a5ec8149a9b476d5ac7..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimRedesigned/CumulantK17CompChimRedesigned.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef CUMULANT_K17_COMP_CHIM_REDESIGN_H -#define CUMULANT_K17_COMP_CHIM_REDESIGN_H - -#include "Kernel/KernelImp.h" - -class CumulantK17CompChimRedesigned : public KernelImp -{ -public: - static std::shared_ptr<CumulantK17CompChimRedesigned> getNewInstance(std::shared_ptr<Parameter> para, int level); - void run() override; - void runOnIndices(const unsigned int *indices, unsigned int size_indices, int stream = -1) override; - -private: - CumulantK17CompChimRedesigned(); - CumulantK17CompChimRedesigned(std::shared_ptr<Parameter> para, int level); -}; - -#endif diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimRedesigned/CumulantK17CompChimRedesigned_Device.cuh b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimRedesigned/CumulantK17CompChimRedesigned_Device.cuh deleted file mode 100644 index 00628efc76447a09504d2fd32a26a63a4d611c66..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimRedesigned/CumulantK17CompChimRedesigned_Device.cuh +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef LB_Kernel_CUMULANT_K17_COMP_CHIM_REDESIGN_H -#define LB_Kernel_CUMULANT_K17_COMP_CHIM_REDESIGN_H - -#include <DataTypes.h> -#include <curand.h> - -__global__ void LB_Kernel_CumulantK17CompChimRedesigned( - real omega, - uint* neighborX, - uint* neighborY, - uint* neighborZ, - real* distributions, - unsigned long numberOfLBnodes, - int level, - real* forces, - real* quadricLimiters, - bool isEvenTimestep, - const uint* fluidNodeIndices, - uint numberOfFluidNodes); -#endif diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimStream/CumulantK17CompChimStream.cu b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimStream/CumulantK17CompChimStream.cu deleted file mode 100644 index 6fae9f6d4845019afd363790eea0ee17c69a060f..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimStream/CumulantK17CompChimStream.cu +++ /dev/null @@ -1,61 +0,0 @@ -#include "CumulantK17CompChimStream.h" - -#include "Parameter/Parameter.h" -#include "Parameter/CudaStreamManager.h" -#include "CumulantK17CompChimStream_Device.cuh" - -#include <cuda.h> - -std::shared_ptr<CumulantK17CompChimStream> CumulantK17CompChimStream::getNewInstance(std::shared_ptr<Parameter> para, - int level) -{ - return std::shared_ptr<CumulantK17CompChimStream>(new CumulantK17CompChimStream(para, level)); -} - -void CumulantK17CompChimStream::run() -{ - LB_Kernel_CumulantK17CompChimStream <<< cudaGrid.grid, cudaGrid.threads >>>( - para->getParD(level)->omega, - para->getParD(level)->neighborX, - para->getParD(level)->neighborY, - para->getParD(level)->neighborZ, - para->getParD(level)->distributions.f[0], - para->getParD(level)->numberOfNodes, - level, - para->getForcesDev(), - para->getQuadricLimitersDev(), - para->getParD(level)->isEvenTimestep, - para->getParD(level)->fluidNodeIndices, - para->getParD(level)->numberOfFluidNodes); - getLastCudaError("LB_Kernel_CumulantK17CompChim execution failed"); -} - -void CumulantK17CompChimStream::runOnIndices(const unsigned int *indices, unsigned int size_indices, int streamIndex) -{ - cudaStream_t stream = (streamIndex == -1) ? CU_STREAM_LEGACY : para->getStreamManager()->getStream(streamIndex); - - LB_Kernel_CumulantK17CompChimStream<<< cudaGrid.grid, cudaGrid.threads, 0, stream>>>( - para->getParD(level)->omega, - para->getParD(level)->neighborX, - para->getParD(level)->neighborY, - para->getParD(level)->neighborZ, - para->getParD(level)->distributions.f[0], - para->getParD(level)->numberOfNodes, - level, - para->getForcesDev(), - para->getQuadricLimitersDev(), - para->getParD(level)->isEvenTimestep, - indices, - size_indices); - getLastCudaError("LB_Kernel_CumulantK17CompChim execution failed"); - -} - -CumulantK17CompChimStream::CumulantK17CompChimStream(std::shared_ptr<Parameter> para, int level): KernelImp(para, level) -{ - myPreProcessorTypes.push_back(InitCompSP27); - myKernelGroup = BasicKernel; - this->cudaGrid = vf::cuda::CudaGrid(para->getParD(level)->numberofthreads, para->getParD(level)->numberOfNodes); - this->kernelUsesFluidNodeIndices = true; -} - diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimStream/CumulantK17CompChimStream.h b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimStream/CumulantK17CompChimStream.h deleted file mode 100644 index 325826e04c893b7c56b7f00bb2503a4eb1fda441..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimStream/CumulantK17CompChimStream.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef CUMULANT_K17_COMP_CHIM_SPARSE_H -#define CUMULANT_K17_COMP_CHIM_SPARSE_H - -#include "Kernel/KernelImp.h" - -class CumulantK17CompChimStream : public KernelImp -{ -public: - static std::shared_ptr<CumulantK17CompChimStream> getNewInstance(std::shared_ptr<Parameter> para, int level); - void run() override; - void runOnIndices(const unsigned int *indices, unsigned int size_indices, int stream = -1) override; - -private: - CumulantK17CompChimStream(); - CumulantK17CompChimStream(std::shared_ptr<Parameter> para, int level); -}; - -#endif diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimStream/CumulantK17CompChimStreamDevice.cu b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimStream/CumulantK17CompChimStreamDevice.cu deleted file mode 100644 index 830fcc6c328f2ecd0f626539040868696065065f..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimStream/CumulantK17CompChimStreamDevice.cu +++ /dev/null @@ -1,640 +0,0 @@ -//======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ -// \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ -// -// This file is part of VirtualFluids. VirtualFluids is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file Cumulant27chimStream.cu -//! \ingroup GPU -//! \author Martin Schoenherr, Anna Wellmann -//======================================================================================= -/* Device code */ -#include "LBM/LB.h" -#include "lbm/constants/D3Q27.h" -#include <lbm/constants/NumericConstants.h> - -using namespace vf::lbm::constant; -using namespace vf::lbm::dir; -#include "Kernel/Utilities/ChimeraTransformation.h" - -//////////////////////////////////////////////////////////////////////////////// -__global__ void LB_Kernel_CumulantK17CompChimStream( - real omega, - uint* neighborX, - uint* neighborY, - uint* neighborZ, - real* distributions, - unsigned long size_Mat, - int level, - real* forces, - real* quadricLimiters, - bool isEvenTimestep, - const uint *fluidNodeIndices, - uint numberOfFluidNodes) -{ - ////////////////////////////////////////////////////////////////////////// - //! Cumulant K17 Kernel is based on \ref - //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), DOI:10.1016/j.jcp.2017.05.040 - //! ]</b></a> and \ref <a href="https://doi.org/10.1016/j.jcp.2017.07.004"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.07.004 ]</b></a> - //! - //! The cumulant kernel is executed in the following steps - //! - //////////////////////////////////////////////////////////////////////////////// - //! - Get node index coordinates from threadIdx, blockIdx, blockDim and gridDim. - //! - const unsigned x = threadIdx.x; - const unsigned y = blockIdx.x; - const unsigned z = blockIdx.y; - - const unsigned nx = blockDim.x; - const unsigned ny = gridDim.x; - - const unsigned k_thread = nx * (ny * z + y) + x; - - ////////////////////////////////////////////////////////////////////////// - // run for all indices in fluidNodeIndices - if (k_thread < numberOfFluidNodes) { - ////////////////////////////////////////////////////////////////////////// - //! - Read distributions: style of reading and writing the distributions from/to stored arrays dependent on - //! timestep is based on the esoteric twist algorithm \ref <a - //! href="https://doi.org/10.3390/computation5020019"><b>[ M. Geier et al. (2017), - //! DOI:10.3390/computation5020019 ]</b></a> - - const unsigned k = fluidNodeIndices[k_thread]; - - Distributions27 dist; - if (isEvenTimestep) { - dist.f[DIR_P00] = &distributions[DIR_P00 * size_Mat]; - dist.f[DIR_M00] = &distributions[DIR_M00 * size_Mat]; - dist.f[DIR_0P0] = &distributions[DIR_0P0 * size_Mat]; - dist.f[DIR_0M0] = &distributions[DIR_0M0 * size_Mat]; - dist.f[DIR_00P] = &distributions[DIR_00P * size_Mat]; - dist.f[DIR_00M] = &distributions[DIR_00M * size_Mat]; - dist.f[DIR_PP0] = &distributions[DIR_PP0 * size_Mat]; - dist.f[DIR_MM0] = &distributions[DIR_MM0 * size_Mat]; - dist.f[DIR_PM0] = &distributions[DIR_PM0 * size_Mat]; - dist.f[DIR_MP0] = &distributions[DIR_MP0 * size_Mat]; - dist.f[DIR_P0P] = &distributions[DIR_P0P * size_Mat]; - dist.f[DIR_M0M] = &distributions[DIR_M0M * size_Mat]; - dist.f[DIR_P0M] = &distributions[DIR_P0M * size_Mat]; - dist.f[DIR_M0P] = &distributions[DIR_M0P * size_Mat]; - dist.f[DIR_0PP] = &distributions[DIR_0PP * size_Mat]; - dist.f[DIR_0MM] = &distributions[DIR_0MM * size_Mat]; - dist.f[DIR_0PM] = &distributions[DIR_0PM * size_Mat]; - dist.f[DIR_0MP] = &distributions[DIR_0MP * size_Mat]; - dist.f[DIR_000] = &distributions[DIR_000 * size_Mat]; - dist.f[DIR_PPP] = &distributions[DIR_PPP * size_Mat]; - dist.f[DIR_MMP] = &distributions[DIR_MMP * size_Mat]; - dist.f[DIR_PMP] = &distributions[DIR_PMP * size_Mat]; - dist.f[DIR_MPP] = &distributions[DIR_MPP * size_Mat]; - dist.f[DIR_PPM] = &distributions[DIR_PPM * size_Mat]; - dist.f[DIR_MMM] = &distributions[DIR_MMM * size_Mat]; - dist.f[DIR_PMM] = &distributions[DIR_PMM * size_Mat]; - dist.f[DIR_MPM] = &distributions[DIR_MPM * size_Mat]; - } else { - dist.f[DIR_M00] = &distributions[DIR_P00 * size_Mat]; - dist.f[DIR_P00] = &distributions[DIR_M00 * size_Mat]; - dist.f[DIR_0M0] = &distributions[DIR_0P0 * size_Mat]; - dist.f[DIR_0P0] = &distributions[DIR_0M0 * size_Mat]; - dist.f[DIR_00M] = &distributions[DIR_00P * size_Mat]; - dist.f[DIR_00P] = &distributions[DIR_00M * size_Mat]; - dist.f[DIR_MM0] = &distributions[DIR_PP0 * size_Mat]; - dist.f[DIR_PP0] = &distributions[DIR_MM0 * size_Mat]; - dist.f[DIR_MP0] = &distributions[DIR_PM0 * size_Mat]; - dist.f[DIR_PM0] = &distributions[DIR_MP0 * size_Mat]; - dist.f[DIR_M0M] = &distributions[DIR_P0P * size_Mat]; - dist.f[DIR_P0P] = &distributions[DIR_M0M * size_Mat]; - dist.f[DIR_M0P] = &distributions[DIR_P0M * size_Mat]; - dist.f[DIR_P0M] = &distributions[DIR_M0P * size_Mat]; - dist.f[DIR_0MM] = &distributions[DIR_0PP * size_Mat]; - dist.f[DIR_0PP] = &distributions[DIR_0MM * size_Mat]; - dist.f[DIR_0MP] = &distributions[DIR_0PM * size_Mat]; - dist.f[DIR_0PM] = &distributions[DIR_0MP * size_Mat]; - dist.f[DIR_000] = &distributions[DIR_000 * size_Mat]; - dist.f[DIR_MMM] = &distributions[DIR_PPP * size_Mat]; - dist.f[DIR_PPM] = &distributions[DIR_MMP * size_Mat]; - dist.f[DIR_MPM] = &distributions[DIR_PMP * size_Mat]; - dist.f[DIR_PMM] = &distributions[DIR_MPP * size_Mat]; - dist.f[DIR_MMP] = &distributions[DIR_PPM * size_Mat]; - dist.f[DIR_PPP] = &distributions[DIR_MMM * size_Mat]; - dist.f[DIR_MPP] = &distributions[DIR_PMM * size_Mat]; - dist.f[DIR_PMP] = &distributions[DIR_MPM * size_Mat]; - } - //////////////////////////////////////////////////////////////////////////////// - //! - Set neighbor indices (necessary for indirect addressing) - uint kw = neighborX[k]; - uint ks = neighborY[k]; - uint kb = neighborZ[k]; - uint ksw = neighborY[kw]; - uint kbw = neighborZ[kw]; - uint kbs = neighborZ[ks]; - uint kbsw = neighborZ[ksw]; - //////////////////////////////////////////////////////////////////////////////////// - //! - Set local distributions - //! - real mfcbb = (dist.f[DIR_P00])[k]; - real mfabb = (dist.f[DIR_M00])[kw]; - real mfbcb = (dist.f[DIR_0P0])[k]; - real mfbab = (dist.f[DIR_0M0])[ks]; - real mfbbc = (dist.f[DIR_00P])[k]; - real mfbba = (dist.f[DIR_00M])[kb]; - real mfccb = (dist.f[DIR_PP0])[k]; - real mfaab = (dist.f[DIR_MM0])[ksw]; - real mfcab = (dist.f[DIR_PM0])[ks]; - real mfacb = (dist.f[DIR_MP0])[kw]; - real mfcbc = (dist.f[DIR_P0P])[k]; - real mfaba = (dist.f[DIR_M0M])[kbw]; - real mfcba = (dist.f[DIR_P0M])[kb]; - real mfabc = (dist.f[DIR_M0P])[kw]; - real mfbcc = (dist.f[DIR_0PP])[k]; - real mfbaa = (dist.f[DIR_0MM])[kbs]; - real mfbca = (dist.f[DIR_0PM])[kb]; - real mfbac = (dist.f[DIR_0MP])[ks]; - real mfbbb = (dist.f[DIR_000])[k]; - real mfccc = (dist.f[DIR_PPP])[k]; - real mfaac = (dist.f[DIR_MMP])[ksw]; - real mfcac = (dist.f[DIR_PMP])[ks]; - real mfacc = (dist.f[DIR_MPP])[kw]; - real mfcca = (dist.f[DIR_PPM])[kb]; - real mfaaa = (dist.f[DIR_MMM])[kbsw]; - real mfcaa = (dist.f[DIR_PMM])[kbs]; - real mfaca = (dist.f[DIR_MPM])[kbw]; - //////////////////////////////////////////////////////////////////////////////////// - //! - Calculate density and velocity using pyramid summation for low round-off errors as in Eq. (J1)-(J3) \ref - //! <a href="https://doi.org/10.1016/j.camwa.2015.05.001"><b>[ M. Geier et al. (2015), - //! DOI:10.1016/j.camwa.2015.05.001 ]</b></a> - //! - real drho = ((((mfccc + mfaaa) + (mfaca + mfcac)) + ((mfacc + mfcaa) + (mfaac + mfcca))) + - (((mfbac + mfbca) + (mfbaa + mfbcc)) + ((mfabc + mfcba) + (mfaba + mfcbc)) + - ((mfacb + mfcab) + (mfaab + mfccb))) + - ((mfabb + mfcbb) + (mfbab + mfbcb) + (mfbba + mfbbc))) + - mfbbb; - - real rho = c1o1 + drho; - real OOrho = c1o1 / rho; - - real vvx = ((((mfccc - mfaaa) + (mfcac - mfaca)) + ((mfcaa - mfacc) + (mfcca - mfaac))) + - (((mfcba - mfabc) + (mfcbc - mfaba)) + ((mfcab - mfacb) + (mfccb - mfaab))) + (mfcbb - mfabb)) * - OOrho; - real vvy = ((((mfccc - mfaaa) + (mfaca - mfcac)) + ((mfacc - mfcaa) + (mfcca - mfaac))) + - (((mfbca - mfbac) + (mfbcc - mfbaa)) + ((mfacb - mfcab) + (mfccb - mfaab))) + (mfbcb - mfbab)) * - OOrho; - real vvz = ((((mfccc - mfaaa) + (mfcac - mfaca)) + ((mfacc - mfcaa) + (mfaac - mfcca))) + - (((mfbac - mfbca) + (mfbcc - mfbaa)) + ((mfabc - mfcba) + (mfcbc - mfaba))) + (mfbbc - mfbba)) * - OOrho; - //////////////////////////////////////////////////////////////////////////////////// - //! - Add half of the acceleration (body force) to the velocity as in Eq. (42) \ref - //! <a href="https://doi.org/10.1016/j.camwa.2015.05.001"><b>[ M. Geier et al. (2015), - //! DOI:10.1016/j.camwa.2015.05.001 ]</b></a> - //! - real factor = c1o1; - for (size_t i = 1; i <= level; i++) { - factor *= c2o1; - } - real fx = forces[0] / factor; - real fy = forces[1] / factor; - real fz = forces[2] / factor; - vvx += fx * c1o2; - vvy += fy * c1o2; - vvz += fz * c1o2; - //////////////////////////////////////////////////////////////////////////////////// - // calculate the square of velocities for this lattice node - real vx2 = vvx * vvx; - real vy2 = vvy * vvy; - real vz2 = vvz * vvz; - //////////////////////////////////////////////////////////////////////////////////// - //! - Set relaxation limiters for third order cumulants to default value \f$ \lambda=0.001 \f$ according to - //! section 6 in \ref <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> - //! - real wadjust; - real qudricLimitP = quadricLimiters[0]; - real qudricLimitM = quadricLimiters[1]; - real qudricLimitD = quadricLimiters[2]; - //////////////////////////////////////////////////////////////////////////////////// - //! - Chimera transform from well conditioned distributions to central moments as defined in Appendix J in \ref - //! <a href="https://doi.org/10.1016/j.camwa.2015.05.001"><b>[ M. Geier et al. (2015), - //! DOI:10.1016/j.camwa.2015.05.001 ]</b></a> see also Eq. (6)-(14) in \ref <a - //! href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), DOI:10.1016/j.jcp.2017.05.040 - //! ]</b></a> - //! - //////////////////////////////////////////////////////////////////////////////////// - // Z - Dir - forwardInverseChimeraWithK(mfaaa, mfaab, mfaac, vvz, vz2, c36o1, c1o36); - forwardInverseChimeraWithK(mfaba, mfabb, mfabc, vvz, vz2, c9o1, c1o9); - forwardInverseChimeraWithK(mfaca, mfacb, mfacc, vvz, vz2, c36o1, c1o36); - forwardInverseChimeraWithK(mfbaa, mfbab, mfbac, vvz, vz2, c9o1, c1o9); - forwardInverseChimeraWithK(mfbba, mfbbb, mfbbc, vvz, vz2, c9o4, c4o9); - forwardInverseChimeraWithK(mfbca, mfbcb, mfbcc, vvz, vz2, c9o1, c1o9); - forwardInverseChimeraWithK(mfcaa, mfcab, mfcac, vvz, vz2, c36o1, c1o36); - forwardInverseChimeraWithK(mfcba, mfcbb, mfcbc, vvz, vz2, c9o1, c1o9); - forwardInverseChimeraWithK(mfcca, mfccb, mfccc, vvz, vz2, c36o1, c1o36); - - //////////////////////////////////////////////////////////////////////////////////// - // Y - Dir - forwardInverseChimeraWithK(mfaaa, mfaba, mfaca, vvy, vy2, c6o1, c1o6); - forwardChimera(mfaab, mfabb, mfacb, vvy, vy2); - forwardInverseChimeraWithK(mfaac, mfabc, mfacc, vvy, vy2, c18o1, c1o18); - forwardInverseChimeraWithK(mfbaa, mfbba, mfbca, vvy, vy2, c3o2, c2o3); - forwardChimera(mfbab, mfbbb, mfbcb, vvy, vy2); - forwardInverseChimeraWithK(mfbac, mfbbc, mfbcc, vvy, vy2, c9o2, c2o9); - forwardInverseChimeraWithK(mfcaa, mfcba, mfcca, vvy, vy2, c6o1, c1o6); - forwardChimera(mfcab, mfcbb, mfccb, vvy, vy2); - forwardInverseChimeraWithK(mfcac, mfcbc, mfccc, vvy, vy2, c18o1, c1o18); - - //////////////////////////////////////////////////////////////////////////////////// - // X - Dir - forwardInverseChimeraWithK(mfaaa, mfbaa, mfcaa, vvx, vx2, c1o1, c1o1); - forwardChimera(mfaba, mfbba, mfcba, vvx, vx2); - forwardInverseChimeraWithK(mfaca, mfbca, mfcca, vvx, vx2, c3o1, c1o3); - forwardChimera(mfaab, mfbab, mfcab, vvx, vx2); - forwardChimera(mfabb, mfbbb, mfcbb, vvx, vx2); - forwardChimera(mfacb, mfbcb, mfccb, vvx, vx2); - forwardInverseChimeraWithK(mfaac, mfbac, mfcac, vvx, vx2, c3o1, c1o3); - forwardChimera(mfabc, mfbbc, mfcbc, vvx, vx2); - forwardInverseChimeraWithK(mfacc, mfbcc, mfccc, vvx, vx2, c3o1, c1o9); - - //////////////////////////////////////////////////////////////////////////////////// - //! - Setting relaxation rates for non-hydrodynamic cumulants (default values). Variable names and equations - //! according to <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> - //! => [NAME IN PAPER]=[NAME IN CODE]=[DEFAULT VALUE]. - //! - Trace of second order cumulants \f$ C_{200}+C_{020}+C_{002} \f$ used to adjust bulk - //! viscosity:\f$\omega_2=OxxPyyPzz=1.0 \f$. - //! - Third order cumulants \f$ C_{120}+C_{102}, C_{210}+C_{012}, C_{201}+C_{021} \f$: \f$ \omega_3=OxyyPxzz - //! \f$ set according to Eq. (111) with simplifications assuming \f$ \omega_2=1.0\f$. - //! - Third order cumulants \f$ C_{120}-C_{102}, C_{210}-C_{012}, C_{201}-C_{021} \f$: \f$ \omega_4 = OxyyMxzz - //! \f$ set according to Eq. (112) with simplifications assuming \f$ \omega_2 = 1.0\f$. - //! - Third order cumulants \f$ C_{111} \f$: \f$ \omega_5 = Oxyz \f$ set according to Eq. (113) with - //! simplifications assuming \f$ \omega_2 = 1.0\f$ (modify for different bulk viscosity). - //! - Fourth order cumulants \f$ C_{220}, C_{202}, C_{022}, C_{211}, C_{121}, C_{112} \f$: for simplification - //! all set to the same default value \f$ \omega_6=\omega_7=\omega_8=O4=1.0 \f$. - //! - Fifth order cumulants \f$ C_{221}, C_{212}, C_{122}\f$: \f$\omega_9=O5=1.0\f$. - //! - Sixth order cumulant \f$ C_{222}\f$: \f$\omega_{10}=O6=1.0\f$. - //! - //////////////////////////////////////////////////////////// - // 2. - real OxxPyyPzz = c1o1; - //////////////////////////////////////////////////////////// - // 3. - real OxyyPxzz = c8o1 * (-c2o1 + omega) * (c1o1 + c2o1 * omega) / (-c8o1 - c14o1 * omega + c7o1 * omega * omega); - real OxyyMxzz = - c8o1 * (-c2o1 + omega) * (-c7o1 + c4o1 * omega) / (c56o1 - c50o1 * omega + c9o1 * omega * omega); - real Oxyz = c24o1 * (-c2o1 + omega) * (-c2o1 - c7o1 * omega + c3o1 * omega * omega) / - (c48o1 + c152o1 * omega - c130o1 * omega * omega + c29o1 * omega * omega * omega); - //////////////////////////////////////////////////////////// - // 4. - real O4 = c1o1; - //////////////////////////////////////////////////////////// - // 5. - real O5 = c1o1; - //////////////////////////////////////////////////////////// - // 6. - real O6 = c1o1; - - //////////////////////////////////////////////////////////////////////////////////// - //! - A and DIR_00M: parameters for fourth order convergence of the diffusion term according to Eq. (115) and (116) - //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> with simplifications assuming \f$ \omega_2 = 1.0 \f$ (modify for - //! different bulk viscosity). - //! - real factorA = (c4o1 + c2o1 * omega - c3o1 * omega * omega) / (c2o1 - c7o1 * omega + c5o1 * omega * omega); - real factorB = (c4o1 + c28o1 * omega - c14o1 * omega * omega) / (c6o1 - c21o1 * omega + c15o1 * omega * omega); - - //////////////////////////////////////////////////////////////////////////////////// - //! - Compute cumulants from central moments according to Eq. (20)-(23) in - //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> - //! - //////////////////////////////////////////////////////////// - // 4. - real CUMcbb = mfcbb - ((mfcaa + c1o3) * mfabb + c2o1 * mfbba * mfbab) * OOrho; - real CUMbcb = mfbcb - ((mfaca + c1o3) * mfbab + c2o1 * mfbba * mfabb) * OOrho; - real CUMbbc = mfbbc - ((mfaac + c1o3) * mfbba + c2o1 * mfbab * mfabb) * OOrho; - - real CUMcca = - mfcca - (((mfcaa * mfaca + c2o1 * mfbba * mfbba) + c1o3 * (mfcaa + mfaca)) * OOrho - c1o9 * (drho * OOrho)); - real CUMcac = - mfcac - (((mfcaa * mfaac + c2o1 * mfbab * mfbab) + c1o3 * (mfcaa + mfaac)) * OOrho - c1o9 * (drho * OOrho)); - real CUMacc = - mfacc - (((mfaac * mfaca + c2o1 * mfabb * mfabb) + c1o3 * (mfaac + mfaca)) * OOrho - c1o9 * (drho * OOrho)); - //////////////////////////////////////////////////////////// - // 5. - real CUMbcc = - mfbcc - ((mfaac * mfbca + mfaca * mfbac + c4o1 * mfabb * mfbbb + c2o1 * (mfbab * mfacb + mfbba * mfabc)) + - c1o3 * (mfbca + mfbac)) * - OOrho; - real CUMcbc = - mfcbc - ((mfaac * mfcba + mfcaa * mfabc + c4o1 * mfbab * mfbbb + c2o1 * (mfabb * mfcab + mfbba * mfbac)) + - c1o3 * (mfcba + mfabc)) * - OOrho; - real CUMccb = - mfccb - ((mfcaa * mfacb + mfaca * mfcab + c4o1 * mfbba * mfbbb + c2o1 * (mfbab * mfbca + mfabb * mfcba)) + - c1o3 * (mfacb + mfcab)) * - OOrho; - //////////////////////////////////////////////////////////// - // 6. - real CUMccc = mfccc + ((-c4o1 * mfbbb * mfbbb - (mfcaa * mfacc + mfaca * mfcac + mfaac * mfcca) - - c4o1 * (mfabb * mfcbb + mfbab * mfbcb + mfbba * mfbbc) - - c2o1 * (mfbca * mfbac + mfcba * mfabc + mfcab * mfacb)) * - OOrho + - (c4o1 * (mfbab * mfbab * mfaca + mfabb * mfabb * mfcaa + mfbba * mfbba * mfaac) + - c2o1 * (mfcaa * mfaca * mfaac) + c16o1 * mfbba * mfbab * mfabb) * - OOrho * OOrho - - c1o3 * (mfacc + mfcac + mfcca) * OOrho - c1o9 * (mfcaa + mfaca + mfaac) * OOrho + - (c2o1 * (mfbab * mfbab + mfabb * mfabb + mfbba * mfbba) + - (mfaac * mfaca + mfaac * mfcaa + mfaca * mfcaa) + c1o3 * (mfaac + mfaca + mfcaa)) * - OOrho * OOrho * c2o3 + - c1o27 * ((drho * drho - drho) * OOrho * OOrho)); - - //////////////////////////////////////////////////////////////////////////////////// - //! - Compute linear combinations of second and third order cumulants - //! - //////////////////////////////////////////////////////////// - // 2. - real mxxPyyPzz = mfcaa + mfaca + mfaac; - real mxxMyy = mfcaa - mfaca; - real mxxMzz = mfcaa - mfaac; - //////////////////////////////////////////////////////////// - // 3. - real mxxyPyzz = mfcba + mfabc; - real mxxyMyzz = mfcba - mfabc; - - real mxxzPyyz = mfcab + mfacb; - real mxxzMyyz = mfcab - mfacb; - - real mxyyPxzz = mfbca + mfbac; - real mxyyMxzz = mfbca - mfbac; - - //////////////////////////////////////////////////////////////////////////////////// - // incl. correction - //////////////////////////////////////////////////////////// - //! - Compute velocity gradients from second order cumulants according to Eq. (27)-(32) - //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> Further explanations of the correction in viscosity in Appendix H of - //! <a href="https://doi.org/10.1016/j.camwa.2015.05.001"><b>[ M. Geier et al. (2015), - //! DOI:10.1016/j.camwa.2015.05.001 ]</b></a> Note that the division by rho is omitted here as we need rho times - //! the gradients later. - //! - real Dxy = -c3o1 * omega * mfbba; - real Dxz = -c3o1 * omega * mfbab; - real Dyz = -c3o1 * omega * mfabb; - real dxux = c1o2 * (-omega) * (mxxMyy + mxxMzz) + c1o2 * OxxPyyPzz * (mfaaa - mxxPyyPzz); - real dyuy = dxux + omega * c3o2 * mxxMyy; - real dzuz = dxux + omega * c3o2 * mxxMzz; - //////////////////////////////////////////////////////////// - //! - Relaxation of second order cumulants with correction terms according to Eq. (33)-(35) in - //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> - //! - mxxPyyPzz += - OxxPyyPzz * (mfaaa - mxxPyyPzz) - c3o1 * (c1o1 - c1o2 * OxxPyyPzz) * (vx2 * dxux + vy2 * dyuy + vz2 * dzuz); - mxxMyy += omega * (-mxxMyy) - c3o1 * (c1o1 + c1o2 * (-omega)) * (vx2 * dxux - vy2 * dyuy); - mxxMzz += omega * (-mxxMzz) - c3o1 * (c1o1 + c1o2 * (-omega)) * (vx2 * dxux - vz2 * dzuz); - - //////////////////////////////////////////////////////////////////////////////////// - ////no correction - // mxxPyyPzz += OxxPyyPzz*(mfaaa - mxxPyyPzz); - // mxxMyy += -(-omega) * (-mxxMyy); - // mxxMzz += -(-omega) * (-mxxMzz); - ////////////////////////////////////////////////////////////////////////// - mfabb += omega * (-mfabb); - mfbab += omega * (-mfbab); - mfbba += omega * (-mfbba); - - //////////////////////////////////////////////////////////////////////////////////// - // relax - ////////////////////////////////////////////////////////////////////////// - // incl. limiter - //! - Relaxation of third order cumulants including limiter according to Eq. (116)-(123) - //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> - //! - wadjust = Oxyz + (c1o1 - Oxyz) * abs(mfbbb) / (abs(mfbbb) + qudricLimitD); - mfbbb += wadjust * (-mfbbb); - wadjust = OxyyPxzz + (c1o1 - OxyyPxzz) * abs(mxxyPyzz) / (abs(mxxyPyzz) + qudricLimitP); - mxxyPyzz += wadjust * (-mxxyPyzz); - wadjust = OxyyMxzz + (c1o1 - OxyyMxzz) * abs(mxxyMyzz) / (abs(mxxyMyzz) + qudricLimitM); - mxxyMyzz += wadjust * (-mxxyMyzz); - wadjust = OxyyPxzz + (c1o1 - OxyyPxzz) * abs(mxxzPyyz) / (abs(mxxzPyyz) + qudricLimitP); - mxxzPyyz += wadjust * (-mxxzPyyz); - wadjust = OxyyMxzz + (c1o1 - OxyyMxzz) * abs(mxxzMyyz) / (abs(mxxzMyyz) + qudricLimitM); - mxxzMyyz += wadjust * (-mxxzMyyz); - wadjust = OxyyPxzz + (c1o1 - OxyyPxzz) * abs(mxyyPxzz) / (abs(mxyyPxzz) + qudricLimitP); - mxyyPxzz += wadjust * (-mxyyPxzz); - wadjust = OxyyMxzz + (c1o1 - OxyyMxzz) * abs(mxyyMxzz) / (abs(mxyyMxzz) + qudricLimitM); - mxyyMxzz += wadjust * (-mxyyMxzz); - ////////////////////////////////////////////////////////////////////////// - // no limiter - // mfbbb += OxyyMxzz * (-mfbbb); - // mxxyPyzz += OxyyPxzz * (-mxxyPyzz); - // mxxyMyzz += OxyyMxzz * (-mxxyMyzz); - // mxxzPyyz += OxyyPxzz * (-mxxzPyyz); - // mxxzMyyz += OxyyMxzz * (-mxxzMyyz); - // mxyyPxzz += OxyyPxzz * (-mxyyPxzz); - // mxyyMxzz += OxyyMxzz * (-mxyyMxzz); - - //////////////////////////////////////////////////////////////////////////////////// - //! - Compute inverse linear combinations of second and third order cumulants - //! - mfcaa = c1o3 * (mxxMyy + mxxMzz + mxxPyyPzz); - mfaca = c1o3 * (-c2o1 * mxxMyy + mxxMzz + mxxPyyPzz); - mfaac = c1o3 * (mxxMyy - c2o1 * mxxMzz + mxxPyyPzz); - - mfcba = (mxxyMyzz + mxxyPyzz) * c1o2; - mfabc = (-mxxyMyzz + mxxyPyzz) * c1o2; - mfcab = (mxxzMyyz + mxxzPyyz) * c1o2; - mfacb = (-mxxzMyyz + mxxzPyyz) * c1o2; - mfbca = (mxyyMxzz + mxyyPxzz) * c1o2; - mfbac = (-mxyyMxzz + mxyyPxzz) * c1o2; - ////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////// - // 4. - // no limiter - //! - Relax fourth order cumulants to modified equilibrium for fourth order convergence of diffusion according - //! to Eq. (43)-(48) <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> - //! - CUMacc = -O4 * (c1o1 / omega - c1o2) * (dyuy + dzuz) * c2o3 * factorA + (c1o1 - O4) * (CUMacc); - CUMcac = -O4 * (c1o1 / omega - c1o2) * (dxux + dzuz) * c2o3 * factorA + (c1o1 - O4) * (CUMcac); - CUMcca = -O4 * (c1o1 / omega - c1o2) * (dyuy + dxux) * c2o3 * factorA + (c1o1 - O4) * (CUMcca); - CUMbbc = -O4 * (c1o1 / omega - c1o2) * Dxy * c1o3 * factorB + (c1o1 - O4) * (CUMbbc); - CUMbcb = -O4 * (c1o1 / omega - c1o2) * Dxz * c1o3 * factorB + (c1o1 - O4) * (CUMbcb); - CUMcbb = -O4 * (c1o1 / omega - c1o2) * Dyz * c1o3 * factorB + (c1o1 - O4) * (CUMcbb); - - ////////////////////////////////////////////////////////////////////////// - // 5. - CUMbcc += O5 * (-CUMbcc); - CUMcbc += O5 * (-CUMcbc); - CUMccb += O5 * (-CUMccb); - - ////////////////////////////////////////////////////////////////////////// - // 6. - CUMccc += O6 * (-CUMccc); - - //////////////////////////////////////////////////////////////////////////////////// - //! - Compute central moments from post collision cumulants according to Eq. (53)-(56) in - //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> - //! - - ////////////////////////////////////////////////////////////////////////// - // 4. - mfcbb = CUMcbb + c1o3 * ((c3o1 * mfcaa + c1o1) * mfabb + c6o1 * mfbba * mfbab) * OOrho; - mfbcb = CUMbcb + c1o3 * ((c3o1 * mfaca + c1o1) * mfbab + c6o1 * mfbba * mfabb) * OOrho; - mfbbc = CUMbbc + c1o3 * ((c3o1 * mfaac + c1o1) * mfbba + c6o1 * mfbab * mfabb) * OOrho; - - mfcca = - CUMcca + - (((mfcaa * mfaca + c2o1 * mfbba * mfbba) * c9o1 + c3o1 * (mfcaa + mfaca)) * OOrho - (drho * OOrho)) * c1o9; - mfcac = - CUMcac + - (((mfcaa * mfaac + c2o1 * mfbab * mfbab) * c9o1 + c3o1 * (mfcaa + mfaac)) * OOrho - (drho * OOrho)) * c1o9; - mfacc = - CUMacc + - (((mfaac * mfaca + c2o1 * mfabb * mfabb) * c9o1 + c3o1 * (mfaac + mfaca)) * OOrho - (drho * OOrho)) * c1o9; - - ////////////////////////////////////////////////////////////////////////// - // 5. - mfbcc = CUMbcc + c1o3 * - (c3o1 * (mfaac * mfbca + mfaca * mfbac + c4o1 * mfabb * mfbbb + - c2o1 * (mfbab * mfacb + mfbba * mfabc)) + - (mfbca + mfbac)) * - OOrho; - mfcbc = CUMcbc + c1o3 * - (c3o1 * (mfaac * mfcba + mfcaa * mfabc + c4o1 * mfbab * mfbbb + - c2o1 * (mfabb * mfcab + mfbba * mfbac)) + - (mfcba + mfabc)) * - OOrho; - mfccb = CUMccb + c1o3 * - (c3o1 * (mfcaa * mfacb + mfaca * mfcab + c4o1 * mfbba * mfbbb + - c2o1 * (mfbab * mfbca + mfabb * mfcba)) + - (mfacb + mfcab)) * - OOrho; - - ////////////////////////////////////////////////////////////////////////// - // 6. - mfccc = CUMccc - ((-c4o1 * mfbbb * mfbbb - (mfcaa * mfacc + mfaca * mfcac + mfaac * mfcca) - - c4o1 * (mfabb * mfcbb + mfbab * mfbcb + mfbba * mfbbc) - - c2o1 * (mfbca * mfbac + mfcba * mfabc + mfcab * mfacb)) * - OOrho + - (c4o1 * (mfbab * mfbab * mfaca + mfabb * mfabb * mfcaa + mfbba * mfbba * mfaac) + - c2o1 * (mfcaa * mfaca * mfaac) + c16o1 * mfbba * mfbab * mfabb) * - OOrho * OOrho - - c1o3 * (mfacc + mfcac + mfcca) * OOrho - c1o9 * (mfcaa + mfaca + mfaac) * OOrho + - (c2o1 * (mfbab * mfbab + mfabb * mfabb + mfbba * mfbba) + - (mfaac * mfaca + mfaac * mfcaa + mfaca * mfcaa) + c1o3 * (mfaac + mfaca + mfcaa)) * - OOrho * OOrho * c2o3 + - c1o27 * ((drho * drho - drho) * OOrho * OOrho)); - - //////////////////////////////////////////////////////////////////////////////////// - //! - Add acceleration (body force) to first order cumulants according to Eq. (85)-(87) in - //! <a href="https://doi.org/10.1016/j.camwa.2015.05.001"><b>[ M. Geier et al. (2015), - //! DOI:10.1016/j.camwa.2015.05.001 ]</b></a> - //! - mfbaa = -mfbaa; - mfaba = -mfaba; - mfaab = -mfaab; - - //////////////////////////////////////////////////////////////////////////////////// - //! - Chimera transform from central moments to well conditioned distributions as defined in Appendix J in - //! <a href="https://doi.org/10.1016/j.camwa.2015.05.001"><b>[ M. Geier et al. (2015), - //! DOI:10.1016/j.camwa.2015.05.001 ]</b></a> see also Eq. (88)-(96) in <a - //! href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), DOI:10.1016/j.jcp.2017.05.040 - //! ]</b></a> - //! - //////////////////////////////////////////////////////////////////////////////////// - // X - Dir - backwardInverseChimeraWithK(mfaaa, mfbaa, mfcaa, vvx, vx2, c1o1, c1o1); - backwardChimera(mfaba, mfbba, mfcba, vvx, vx2); - backwardInverseChimeraWithK(mfaca, mfbca, mfcca, vvx, vx2, c3o1, c1o3); - backwardChimera(mfaab, mfbab, mfcab, vvx, vx2); - backwardChimera(mfabb, mfbbb, mfcbb, vvx, vx2); - backwardChimera(mfacb, mfbcb, mfccb, vvx, vx2); - backwardInverseChimeraWithK(mfaac, mfbac, mfcac, vvx, vx2, c3o1, c1o3); - backwardChimera(mfabc, mfbbc, mfcbc, vvx, vx2); - backwardInverseChimeraWithK(mfacc, mfbcc, mfccc, vvx, vx2, c9o1, c1o9); - - //////////////////////////////////////////////////////////////////////////////////// - // Y - Dir - backwardInverseChimeraWithK(mfaaa, mfaba, mfaca, vvy, vy2, c6o1, c1o6); - backwardChimera(mfaab, mfabb, mfacb, vvy, vy2); - backwardInverseChimeraWithK(mfaac, mfabc, mfacc, vvy, vy2, c18o1, c1o18); - backwardInverseChimeraWithK(mfbaa, mfbba, mfbca, vvy, vy2, c3o2, c2o3); - backwardChimera(mfbab, mfbbb, mfbcb, vvy, vy2); - backwardInverseChimeraWithK(mfbac, mfbbc, mfbcc, vvy, vy2, c9o2, c2o9); - backwardInverseChimeraWithK(mfcaa, mfcba, mfcca, vvy, vy2, c6o1, c1o6); - backwardChimera(mfcab, mfcbb, mfccb, vvy, vy2); - backwardInverseChimeraWithK(mfcac, mfcbc, mfccc, vvy, vy2, c18o1, c1o18); - - //////////////////////////////////////////////////////////////////////////////////// - // Z - Dir - backwardInverseChimeraWithK(mfaaa, mfaab, mfaac, vvz, vz2, c36o1, c1o36); - backwardInverseChimeraWithK(mfaba, mfabb, mfabc, vvz, vz2, c9o1, c1o9); - backwardInverseChimeraWithK(mfaca, mfacb, mfacc, vvz, vz2, c36o1, c1o36); - backwardInverseChimeraWithK(mfbaa, mfbab, mfbac, vvz, vz2, c9o1, c1o9); - backwardInverseChimeraWithK(mfbba, mfbbb, mfbbc, vvz, vz2, c9o4, c4o9); - backwardInverseChimeraWithK(mfbca, mfbcb, mfbcc, vvz, vz2, c9o1, c1o9); - backwardInverseChimeraWithK(mfcaa, mfcab, mfcac, vvz, vz2, c36o1, c1o36); - backwardInverseChimeraWithK(mfcba, mfcbb, mfcbc, vvz, vz2, c9o1, c1o9); - backwardInverseChimeraWithK(mfcca, mfccb, mfccc, vvz, vz2, c36o1, c1o36); - - //////////////////////////////////////////////////////////////////////////////////// - //! - Write distributions: style of reading and writing the distributions from/to - //! stored arrays dependent on timestep is based on the esoteric twist algorithm - //! <a href="https://doi.org/10.3390/computation5020019"><b>[ M. Geier et al. (2017), - //! DOI:10.3390/computation5020019 ]</b></a> - //! - (dist.f[DIR_P00])[k] = mfabb; - (dist.f[DIR_M00])[kw] = mfcbb; - (dist.f[DIR_0P0])[k] = mfbab; - (dist.f[DIR_0M0])[ks] = mfbcb; - (dist.f[DIR_00P])[k] = mfbba; - (dist.f[DIR_00M])[kb] = mfbbc; - (dist.f[DIR_PP0])[k] = mfaab; - (dist.f[DIR_MM0])[ksw] = mfccb; - (dist.f[DIR_PM0])[ks] = mfacb; - (dist.f[DIR_MP0])[kw] = mfcab; - (dist.f[DIR_P0P])[k] = mfaba; - (dist.f[DIR_M0M])[kbw] = mfcbc; - (dist.f[DIR_P0M])[kb] = mfabc; - (dist.f[DIR_M0P])[kw] = mfcba; - (dist.f[DIR_0PP])[k] = mfbaa; - (dist.f[DIR_0MM])[kbs] = mfbcc; - (dist.f[DIR_0PM])[kb] = mfbac; - (dist.f[DIR_0MP])[ks] = mfbca; - (dist.f[DIR_000])[k] = mfbbb; - (dist.f[DIR_PPP])[k] = mfaaa; - (dist.f[DIR_PMP])[ks] = mfaca; - (dist.f[DIR_PPM])[kb] = mfaac; - (dist.f[DIR_PMM])[kbs] = mfacc; - (dist.f[DIR_MPP])[kw] = mfcaa; - (dist.f[DIR_MMP])[ksw] = mfcca; - (dist.f[DIR_MPM])[kbw] = mfcac; - (dist.f[DIR_MMM])[kbsw] = mfccc; - } -} \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimStream/CumulantK17CompChimStream_Device.cuh b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimStream/CumulantK17CompChimStream_Device.cuh deleted file mode 100644 index f74192c0423ba9dc96820d7f46eecb9d49a39ed4..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimStream/CumulantK17CompChimStream_Device.cuh +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef LB_Kernel_CUMULANT_K17_COMP_CHIM_SPARSE_H -#define LB_Kernel_CUMULANT_K17_COMP_CHIM_SPARSE_H - -#include <DataTypes.h> -#include <curand.h> - -__global__ void LB_Kernel_CumulantK17CompChimStream( - real omega, - uint* neighborX, - uint* neighborY, - uint* neighborZ, - real* distributions, - unsigned long size_Mat, - int level, - real* forces, - real* quadricLimiters, - bool isEvenTimestep, - const uint* fluidNodeIndices, - uint numberOfFluidNodes); -#endif diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/CumulantK17chim/TurbulentViscosityCumulantK17CompChim.cu b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/CumulantK17chim/TurbulentViscosityCumulantK17CompChim.cu deleted file mode 100644 index a9d518d14a286ae3f6b565176969162994afa269..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/CumulantK17chim/TurbulentViscosityCumulantK17CompChim.cu +++ /dev/null @@ -1,57 +0,0 @@ -#include "TurbulentViscosityCumulantK17CompChim.h" -#include "cuda/CudaGrid.h" -#include <logger/Logger.h> -#include "Parameter/Parameter.h" -#include "TurbulentViscosityCumulantK17CompChim_Device.cuh" - -template<TurbulenceModel turbulenceModel> -std::shared_ptr< TurbulentViscosityCumulantK17CompChim<turbulenceModel> > TurbulentViscosityCumulantK17CompChim<turbulenceModel>::getNewInstance(std::shared_ptr<Parameter> para, int level) -{ - return std::shared_ptr<TurbulentViscosityCumulantK17CompChim<turbulenceModel> >(new TurbulentViscosityCumulantK17CompChim<turbulenceModel>(para,level)); -} - -template<TurbulenceModel turbulenceModel> -void TurbulentViscosityCumulantK17CompChim<turbulenceModel>::run() -{ - vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(para->getParH(level)->numberofthreads, para->getParH(level)->numberOfNodes); - - LB_Kernel_TurbulentViscosityCumulantK17CompChim < turbulenceModel > <<< grid.grid, grid.threads >>>( para->getParD(level)->omega, - para->getParD(level)->typeOfGridNode, para->getParD(level)->neighborX, - para->getParD(level)->neighborY, - para->getParD(level)->neighborZ, - para->getParD(level)->distributions.f[0], - para->getParD(level)->rho, - para->getParD(level)->velocityX, - para->getParD(level)->velocityY, - para->getParD(level)->velocityZ, - para->getParD(level)->turbViscosity, - para->getSGSConstant(), - (unsigned long)para->getParD(level)->numberOfNodes, - level, - para->getIsBodyForce(), - para->getForcesDev(), - para->getParD(level)->forceX_SP, - para->getParD(level)->forceY_SP, - para->getParD(level)->forceZ_SP, - para->getQuadricLimitersDev(), - para->getParD(level)->isEvenTimestep); - - getLastCudaError("LB_Kernel_TurbulentViscosityCumulantK17CompChim execution failed"); -} - -template<TurbulenceModel turbulenceModel> -TurbulentViscosityCumulantK17CompChim<turbulenceModel>::TurbulentViscosityCumulantK17CompChim(std::shared_ptr<Parameter> para, int level) -{ - this->para = para; - this->level = level; - - myPreProcessorTypes.push_back(InitCompSP27); - - myKernelGroup = BasicKernel; - - VF_LOG_INFO("Using turbulence model: {}", turbulenceModel); -} - -template class TurbulentViscosityCumulantK17CompChim<TurbulenceModel::AMD>; -template class TurbulentViscosityCumulantK17CompChim<TurbulenceModel::Smagorinsky>; -template class TurbulentViscosityCumulantK17CompChim<TurbulenceModel::QR>; diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/CumulantK17chim/TurbulentViscosityCumulantK17CompChim.h b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/CumulantK17chim/TurbulentViscosityCumulantK17CompChim.h deleted file mode 100644 index 0d35b68c916e54c6ec6eeeacd7189fe4d9a33c10..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/CumulantK17chim/TurbulentViscosityCumulantK17CompChim.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef TurbulentViscosityCUMULANT_K17_COMP_CHIM_H -#define TurbulentViscosityCUMULANT_K17_COMP_CHIM_H - -#include "Kernel/KernelImp.h" -#include "Parameter/Parameter.h" - -template<TurbulenceModel turbulenceModel> -class TurbulentViscosityCumulantK17CompChim : public KernelImp -{ -public: - static std::shared_ptr< TurbulentViscosityCumulantK17CompChim<turbulenceModel> > getNewInstance(std::shared_ptr< Parameter> para, int level); - void run(); - -private: - TurbulentViscosityCumulantK17CompChim(); - TurbulentViscosityCumulantK17CompChim(std::shared_ptr<Parameter> para, int level); -}; - -#endif diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/CumulantK17chim/TurbulentViscosityCumulantK17CompChim_Device.cu b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/CumulantK17chim/TurbulentViscosityCumulantK17CompChim_Device.cu deleted file mode 100644 index 32350b95107b68103af0f238fefe095882919092..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/CumulantK17chim/TurbulentViscosityCumulantK17CompChim_Device.cu +++ /dev/null @@ -1,687 +0,0 @@ -//======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ -// \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ -// -// This file is part of VirtualFluids. VirtualFluids is free software: you can -// redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of -// the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. -// -// You should have received a copy of the GNU General Public License along -// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. -// -//! \file TurbulentViscosityCumulantK17CompChim_Device.cu -//! \author Henry Korb, Henrik Asmuth -//! \date 16/05/2022 -//! \brief CumulantK17CompChim kernel by Martin Schönherr that inlcudes turbulent viscosity and other small mods. -//! -//! Additions to CumulantK17CompChim: -//! - can incorporate local body force -//! - when applying a local body force, the total round of error of forcing+bodyforce is saved and added in next time step -//! - uses turbulent viscosity that is computed in separate kernel (as of now AMD) -//! - saves macroscopic values (needed for instance for probes, AMD, and actuator models) -//! -//======================================================================================= -/* Device code */ -#include "LBM/LB.h" -#include "lbm/constants/D3Q27.h" -#include <lbm/constants/NumericConstants.h> -#include "Kernel/Utilities/DistributionHelper.cuh" - -#include "GPU/TurbulentViscosityInlines.cuh" - -using namespace vf::lbm::constant; -using namespace vf::lbm::dir; -#include "Kernel/Utilities/ChimeraTransformation.h" - - -//////////////////////////////////////////////////////////////////////////////// -template<TurbulenceModel turbulenceModel> -__global__ void LB_Kernel_TurbulentViscosityCumulantK17CompChim( - real omega_in, - uint* typeOfGridNode, - uint* neighborX, - uint* neighborY, - uint* neighborZ, - real* distributions, - real* rho, - real* vx, - real* vy, - real* vz, - real* turbulentViscosity, - real SGSconstant, - unsigned long size_Mat, - int level, - bool bodyForce, - real* forces, - real* bodyForceX, - real* bodyForceY, - real* bodyForceZ, - real* quadricLimiters, - bool isEvenTimestep) -{ - ////////////////////////////////////////////////////////////////////////// - //! Cumulant K17 Kernel is based on \ref - //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), DOI:10.1016/j.jcp.2017.05.040 - //! ]</b></a> and \ref <a href="https://doi.org/10.1016/j.jcp.2017.07.004"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.07.004 ]</b></a> - //! - //! The cumulant kernel is executed in the following steps - //! - //////////////////////////////////////////////////////////////////////////////// - //! - Get node index coordinates from threadIdx, blockIdx, blockDim and gridDim. - //! - const unsigned k_000 = vf::gpu::getNodeIndex(); - - ////////////////////////////////////////////////////////////////////////// - // run for all indices in size_Mat and fluid nodes - if ((k_000 < size_Mat) && (typeOfGridNode[k_000] == GEO_FLUID)) { - ////////////////////////////////////////////////////////////////////////// - //! - Read distributions: style of reading and writing the distributions from/to stored arrays dependent on - //! timestep is based on the esoteric twist algorithm \ref <a - //! href="https://doi.org/10.3390/computation5020019"><b>[ M. Geier et al. (2017), - //! DOI:10.3390/computation5020019 ]</b></a> - //! - Distributions27 dist = vf::gpu::getDistributionReferences27(distributions, size_Mat, isEvenTimestep); - - //////////////////////////////////////////////////////////////////////////////// - //! - Set neighbor indices (necessary for indirect addressing) - uint k_M00 = neighborX[k_000]; - uint k_0M0 = neighborY[k_000]; - uint k_00M = neighborZ[k_000]; - uint k_MM0 = neighborY[k_M00]; - uint k_M0M = neighborZ[k_M00]; - uint k_0MM = neighborZ[k_0M0]; - uint k_MMM = neighborZ[k_MM0]; - //////////////////////////////////////////////////////////////////////////////////// - //! - Set local distributions - //! - real f_000 = (dist.f[DIR_000])[k_000]; - real f_P00 = (dist.f[DIR_P00])[k_000]; - real f_M00 = (dist.f[DIR_M00])[k_M00]; - real f_0P0 = (dist.f[DIR_0P0])[k_000]; - real f_0M0 = (dist.f[DIR_0M0])[k_0M0]; - real f_00P = (dist.f[DIR_00P])[k_000]; - real f_00M = (dist.f[DIR_00M])[k_00M]; - real f_PP0 = (dist.f[DIR_PP0])[k_000]; - real f_MM0 = (dist.f[DIR_MM0])[k_MM0]; - real f_PM0 = (dist.f[DIR_PM0])[k_0M0]; - real f_MP0 = (dist.f[DIR_MP0])[k_M00]; - real f_P0P = (dist.f[DIR_P0P])[k_000]; - real f_M0M = (dist.f[DIR_M0M])[k_M0M]; - real f_P0M = (dist.f[DIR_P0M])[k_00M]; - real f_M0P = (dist.f[DIR_M0P])[k_M00]; - real f_0PP = (dist.f[DIR_0PP])[k_000]; - real f_0MM = (dist.f[DIR_0MM])[k_0MM]; - real f_0PM = (dist.f[DIR_0PM])[k_00M]; - real f_0MP = (dist.f[DIR_0MP])[k_0M0]; - real f_PPP = (dist.f[DIR_PPP])[k_000]; - real f_MPP = (dist.f[DIR_MPP])[k_M00]; - real f_PMP = (dist.f[DIR_PMP])[k_0M0]; - real f_MMP = (dist.f[DIR_MMP])[k_MM0]; - real f_PPM = (dist.f[DIR_PPM])[k_00M]; - real f_MPM = (dist.f[DIR_MPM])[k_M0M]; - real f_PMM = (dist.f[DIR_PMM])[k_0MM]; - real f_MMM = (dist.f[DIR_MMM])[k_MMM]; - - //////////////////////////////////////////////////////////////////////////////////// - //! - Define aliases to use the same variable for the moments (m's): - //! - real& m_111 = f_000; - real& m_211 = f_P00; - real& m_011 = f_M00; - real& m_121 = f_0P0; - real& m_101 = f_0M0; - real& m_112 = f_00P; - real& m_110 = f_00M; - real& m_221 = f_PP0; - real& m_001 = f_MM0; - real& m_201 = f_PM0; - real& m_021 = f_MP0; - real& m_212 = f_P0P; - real& m_010 = f_M0M; - real& m_210 = f_P0M; - real& m_012 = f_M0P; - real& m_122 = f_0PP; - real& m_100 = f_0MM; - real& m_120 = f_0PM; - real& m_102 = f_0MP; - real& m_222 = f_PPP; - real& m_022 = f_MPP; - real& m_202 = f_PMP; - real& m_002 = f_MMP; - real& m_220 = f_PPM; - real& m_020 = f_MPM; - real& m_200 = f_PMM; - real& m_000 = f_MMM; - - //////////////////////////////////////////////////////(unsigned long)////////////////////////////// - //! - Calculate density and velocity using pyramid summation for low round-off errors as in Eq. (J1)-(J3) \ref - //! <a href="https://doi.org/10.1016/j.camwa.2015.05.001"><b>[ M. Geier et al. (2015), - //! DOI:10.1016/j.camwa.2015.05.001 ]</b></a> - //! - real drho = ((((f_PPP + f_MMM) + (f_MPM + f_PMP)) + ((f_MPP + f_PMM) + (f_MMP + f_PPM))) + - (((f_0MP + f_0PM) + (f_0MM + f_0PP)) + ((f_M0P + f_P0M) + (f_M0M + f_P0P)) + - ((f_MP0 + f_PM0) + (f_MM0 + f_PP0))) + - ((f_M00 + f_P00) + (f_0M0 + f_0P0) + (f_00M + f_00P))) + - f_000; - - real oneOverRho = c1o1 / (c1o1 + drho); - - real vvx = ((((f_PPP - f_MMM) + (f_PMP - f_MPM)) + ((f_PMM - f_MPP) + (f_PPM - f_MMP))) + - (((f_P0M - f_M0P) + (f_P0P - f_M0M)) + ((f_PM0 - f_MP0) + (f_PP0 - f_MM0))) + (f_P00 - f_M00)) * - oneOverRho; - real vvy = ((((f_PPP - f_MMM) + (f_MPM - f_PMP)) + ((f_MPP - f_PMM) + (f_PPM - f_MMP))) + - (((f_0PM - f_0MP) + (f_0PP - f_0MM)) + ((f_MP0 - f_PM0) + (f_PP0 - f_MM0))) + (f_0P0 - f_0M0)) * - oneOverRho; - real vvz = ((((f_PPP - f_MMM) + (f_PMP - f_MPM)) + ((f_MPP - f_PMM) + (f_MMP - f_PPM))) + - (((f_0MP - f_0PM) + (f_0PP - f_0MM)) + ((f_M0P - f_P0M) + (f_P0P - f_M0M))) + (f_00P - f_00M)) * - oneOverRho; - - //////////////////////////////////////////////////////////////////////////////////// - //! - Add half of the acceleration (body force) to the velocity as in Eq. (42) \ref - //! <a href="https://doi.org/10.1016/j.camwa.2015.05.001"><b>[ M. Geier et al. (2015), - //! DOI:10.1016/j.camwa.2015.05.001 ]</b></a> - //! - real factor = c1o1; - for (size_t i = 1; i <= level; i++) { - factor *= c2o1; - } - - real fx = forces[0]; - real fy = forces[1]; - real fz = forces[2]; - - if( bodyForce ){ - fx += bodyForceX[k_000]; - fy += bodyForceY[k_000]; - fz += bodyForceZ[k_000]; - - real vx = vvx; - real vy = vvy; - real vz = vvz; - real acc_x = fx * c1o2 / factor; - real acc_y = fy * c1o2 / factor; - real acc_z = fz * c1o2 / factor; - - vvx += acc_x; - vvy += acc_y; - vvz += acc_z; - - // // Reset body force. To be used when not using round-off correction. - // bodyForceX[k] = 0.0f; - // bodyForceY[k] = 0.0f; - // bodyForceZ[k] = 0.0f; - - //////////////////////////////////////////////////////////////////////////////////// - //!> Round-off correction - //! - //!> Similar to Kahan summation algorithm (https://en.wikipedia.org/wiki/Kahan_summation_algorithm) - //!> Essentially computes the round-off error of the applied force and adds it in the next time step as a compensation. - //!> Seems to be necesseary at very high Re boundary layers, where the forcing and velocity can - //!> differ by several orders of magnitude. - //!> \note 16/05/2022: Testing, still ongoing! - //! - bodyForceX[k_000] = (acc_x-(vvx-vx))*factor*c2o1; - bodyForceY[k_000] = (acc_y-(vvy-vy))*factor*c2o1; - bodyForceZ[k_000] = (acc_z-(vvz-vz))*factor*c2o1; - } - else{ - vvx += fx * c1o2 / factor; - vvy += fy * c1o2 / factor; - vvz += fz * c1o2 / factor; - } - - - //////////////////////////////////////////////////////////////////////////////////// - // calculate the square of velocities for this lattice node - real vx2 = vvx * vvx; - real vy2 = vvy * vvy; - real vz2 = vvz * vvz; - //////////////////////////////////////////////////////////////////////////////////// - //! - Set relaxation limiters for third order cumulants to default value \f$ \lambda=0.001 \f$ according to - //! section 6 in \ref <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> - //! - real quadricLimitP = quadricLimiters[0]; - real quadricLimitM = quadricLimiters[1]; - real quadricLimitD = quadricLimiters[2]; - //////////////////////////////////////////////////////////////////////////////////// - //! - Chimera transform from well conditioned distributions to central moments as defined in Appendix J in \ref - //! <a href="https://doi.org/10.1016/j.camwa.2015.05.001"><b>[ M. Geier et al. (2015), - //! DOI:10.1016/j.camwa.2015.05.001 ]</b></a> see also Eq. (6)-(14) in \ref <a - //! href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), DOI:10.1016/j.jcp.2017.05.040 - //! ]</b></a> - //! - //////////////////////////////////////////////////////////////////////////////////// - // Z - Dir - forwardInverseChimeraWithK(f_MMM, f_MM0, f_MMP, vvz, vz2, c36o1, c1o36); - forwardInverseChimeraWithK(f_M0M, f_M00, f_M0P, vvz, vz2, c9o1, c1o9); - forwardInverseChimeraWithK(f_MPM, f_MP0, f_MPP, vvz, vz2, c36o1, c1o36); - forwardInverseChimeraWithK(f_0MM, f_0M0, f_0MP, vvz, vz2, c9o1, c1o9); - forwardInverseChimeraWithK(f_00M, f_000, f_00P, vvz, vz2, c9o4, c4o9); - forwardInverseChimeraWithK(f_0PM, f_0P0, f_0PP, vvz, vz2, c9o1, c1o9); - forwardInverseChimeraWithK(f_PMM, f_PM0, f_PMP, vvz, vz2, c36o1, c1o36); - forwardInverseChimeraWithK(f_P0M, f_P00, f_P0P, vvz, vz2, c9o1, c1o9); - forwardInverseChimeraWithK(f_PPM, f_PP0, f_PPP, vvz, vz2, c36o1, c1o36); - - //////////////////////////////////////////////////////////////////////////////////// - // Y - Dir - forwardInverseChimeraWithK(f_MMM, f_M0M, f_MPM, vvy, vy2, c6o1, c1o6); - forwardChimera( f_MM0, f_M00, f_MP0, vvy, vy2); - forwardInverseChimeraWithK(f_MMP, f_M0P, f_MPP, vvy, vy2, c18o1, c1o18); - forwardInverseChimeraWithK(f_0MM, f_00M, f_0PM, vvy, vy2, c3o2, c2o3); - forwardChimera( f_0M0, f_000, f_0P0, vvy, vy2); - forwardInverseChimeraWithK(f_0MP, f_00P, f_0PP, vvy, vy2, c9o2, c2o9); - forwardInverseChimeraWithK(f_PMM, f_P0M, f_PPM, vvy, vy2, c6o1, c1o6); - forwardChimera( f_PM0, f_P00, f_PP0, vvy, vy2); - forwardInverseChimeraWithK(f_PMP, f_P0P, f_PPP, vvy, vy2, c18o1, c1o18); - - //////////////////////////////////////////////////////////////////////////////////// - // X - Dir - forwardInverseChimeraWithK(f_MMM, f_0MM, f_PMM, vvx, vx2, c1o1, c1o1); - forwardChimera( f_M0M, f_00M, f_P0M, vvx, vx2); - forwardInverseChimeraWithK(f_MPM, f_0PM, f_PPM, vvx, vx2, c3o1, c1o3); - forwardChimera( f_MM0, f_0M0, f_PM0, vvx, vx2); - forwardChimera( f_M00, f_000, f_P00, vvx, vx2); - forwardChimera( f_MP0, f_0P0, f_PP0, vvx, vx2); - forwardInverseChimeraWithK(f_MMP, f_0MP, f_PMP, vvx, vx2, c3o1, c1o3); - forwardChimera( f_M0P, f_00P, f_P0P, vvx, vx2); - forwardInverseChimeraWithK(f_MPP, f_0PP, f_PPP, vvx, vx2, c3o1, c1o9); - - //////////////////////////////////////////////////////////////////////////////////// - //! - Setting relaxation rates for non-hydrodynamic cumulants (default values). Variable names and equations - //! according to <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> - //! => [NAME IN PAPER]=[NAME IN CODE]=[DEFAULT VALUE]. - //! - Trace of second order cumulants \f$ C_{200}+C_{020}+C_{002} \f$ used to adjust bulk - //! viscosity:\f$\omega_2=OxxPyyPzz=1.0 \f$. - //! - Third order cumulants \f$ C_{120}+C_{102}, C_{210}+C_{012}, C_{201}+C_{021} \f$: \f$ \omega_3=OxyyPxzz - //! \f$ set according to Eq. (111) with simplifications assuming \f$ \omega_2=1.0\f$. - //! - Third order cumulants \f$ C_{120}-C_{102}, C_{210}-C_{012}, C_{201}-C_{021} \f$: \f$ \omega_4 = OxyyMxzz - //! \f$ set according to Eq. (112) with simplifications assuming \f$ \omega_2 = 1.0\f$. - //! - Third order cumulants \f$ C_{111} \f$: \f$ \omega_5 = Oxyz \f$ set according to Eq. (113) with - //! simplifications assuming \f$ \omega_2 = 1.0\f$ (modify for different bulk viscosity). - //! - Fourth order cumulants \f$ C_{220}, C_{202}, C_{022}, C_{211}, C_{121}, C_{112} \f$: for simplification - //! all set to the same default value \f$ \omega_6=\omega_7=\omega_8=O4=1.0 \f$. - //! - Fifth order cumulants \f$ C_{221}, C_{212}, C_{122}\f$: \f$\omega_9=O5=1.0\f$. - //! - Sixth order cumulant \f$ C_{222}\f$: \f$\omega_{10}=O6=1.0\f$. - //! - //////////////////////////////////////////////////////////////////////////////////// - //! - Calculate modified omega with turbulent viscosity - //! - real omega = omega_in / (c1o1 + c3o1*omega_in*turbulentViscosity[k_000]); - //////////////////////////////////////////////////////////// - // 2. - real OxxPyyPzz = c1o1; - //////////////////////////////////////////////////////////// - // 3. - real OxyyPxzz = c8o1 * (-c2o1 + omega) * (c1o1 + c2o1 * omega) / (-c8o1 - c14o1 * omega + c7o1 * omega * omega); - real OxyyMxzz = - c8o1 * (-c2o1 + omega) * (-c7o1 + c4o1 * omega) / (c56o1 - c50o1 * omega + c9o1 * omega * omega); - real Oxyz = c24o1 * (-c2o1 + omega) * (-c2o1 - c7o1 * omega + c3o1 * omega * omega) / - (c48o1 + c152o1 * omega - c130o1 * omega * omega + c29o1 * omega * omega * omega); - //////////////////////////////////////////////////////////// - // 4. - real O4 = c1o1; - //////////////////////////////////////////////////////////// - // 5. - real O5 = c1o1; - //////////////////////////////////////////////////////////// - // 6. - real O6 = c1o1; - - //////////////////////////////////////////////////////////////////////////////////// - //! - A and DIR_00M: parameters for fourth order convergence of the diffusion term according to Eq. (115) and (116) - //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> with simplifications assuming \f$ \omega_2 = 1.0 \f$ (modify for - //! different bulk viscosity). - //! - real factorA = (c4o1 + c2o1 * omega - c3o1 * omega * omega) / (c2o1 - c7o1 * omega + c5o1 * omega * omega); - real factorB = (c4o1 + c28o1 * omega - c14o1 * omega * omega) / (c6o1 - c21o1 * omega + c15o1 * omega * omega); - - //////////////////////////////////////////////////////////////////////////////////// - //! - Compute cumulants from central moments according to Eq. (20)-(23) in - //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> - //! - //////////////////////////////////////////////////////////// - // 4. - real c_211 = m_211 - ((m_200 + c1o3) * m_011 + c2o1 * m_110 * m_101) * oneOverRho; - real c_121 = m_121 - ((m_020 + c1o3) * m_101 + c2o1 * m_110 * m_011) * oneOverRho; - real c_112 = m_112 - ((m_002 + c1o3) * m_110 + c2o1 * m_101 * m_011) * oneOverRho; - - real c_220 = m_220 - (((m_200 * m_020 + c2o1 * m_110 * m_110) + c1o3 * (m_200 + m_020)) * oneOverRho - c1o9 * (drho * oneOverRho)); - real c_202 = m_202 - (((m_200 * m_002 + c2o1 * m_101 * m_101) + c1o3 * (m_200 + m_002)) * oneOverRho - c1o9 * (drho * oneOverRho)); - real c_022 = m_022 - (((m_002 * m_020 + c2o1 * m_011 * m_011) + c1o3 * (m_002 + m_020)) * oneOverRho - c1o9 * (drho * oneOverRho)); - //////////////////////////////////////////////////////////// - // 5. - real c_122 = - m_122 - ((m_002 * m_120 + m_020 * m_102 + c4o1 * m_011 * m_111 + c2o1 * (m_101 * m_021 + m_110 * m_012)) + - c1o3 * (m_120 + m_102)) * - oneOverRho; - real c_212 = - m_212 - ((m_002 * m_210 + m_200 * m_012 + c4o1 * m_101 * m_111 + c2o1 * (m_011 * m_201 + m_110 * m_102)) + - c1o3 * (m_210 + m_012)) * - oneOverRho; - real c_221 = - m_221 - ((m_200 * m_021 + m_020 * m_201 + c4o1 * m_110 * m_111 + c2o1 * (m_101 * m_120 + m_011 * m_210)) + - c1o3 * (m_021 + m_201)) * - oneOverRho; - //////////////////////////////////////////////////////////// - // 6. - real c_222 = m_222 + ((-c4o1 * m_111 * m_111 - (m_200 * m_022 + m_020 * m_202 + m_002 * m_220) - - c4o1 * (m_011 * m_211 + m_101 * m_121 + m_110 * m_112) - - c2o1 * (m_120 * m_102 + m_210 * m_012 + m_201 * m_021)) * - oneOverRho + - (c4o1 * (m_101 * m_101 * m_020 + m_011 * m_011 * m_200 + m_110 * m_110 * m_002) + - c2o1 * (m_200 * m_020 * m_002) + c16o1 * m_110 * m_101 * m_011) * - oneOverRho * oneOverRho - - c1o3 * (m_022 + m_202 + m_220) * oneOverRho - c1o9 * (m_200 + m_020 + m_002) * oneOverRho + - (c2o1 * (m_101 * m_101 + m_011 * m_011 + m_110 * m_110) + - (m_002 * m_020 + m_002 * m_200 + m_020 * m_200) + c1o3 * (m_002 + m_020 + m_200)) * - oneOverRho * oneOverRho * c2o3 + - c1o27 * ((drho * drho - drho) * oneOverRho * oneOverRho)); - - //////////////////////////////////////////////////////////////////////////////////// - //! - Compute linear combinations of second and third order cumulants - //! - //////////////////////////////////////////////////////////// - // 2. - real mxxPyyPzz = m_200 + m_020 + m_002; - real mxxMyy = m_200 - m_020; - real mxxMzz = m_200 - m_002; - //////////////////////////////////////////////////////////// - // 3. - real mxxyPyzz = m_210 + m_012; - real mxxyMyzz = m_210 - m_012; - - real mxxzPyyz = m_201 + m_021; - real mxxzMyyz = m_201 - m_021; - - real mxyyPxzz = m_120 + m_102; - real mxyyMxzz = m_120 - m_102; - - //////////////////////////////////////////////////////////////////////////////////// - // incl. correction - //////////////////////////////////////////////////////////// - //! - Compute velocity gradients from second order cumulants according to Eq. (27)-(32) - //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> Further explanations of the correction in viscosity in Appendix H of - //! <a href="https://doi.org/10.1016/j.camwa.2015.05.001"><b>[ M. Geier et al. (2015), - //! DOI:10.1016/j.camwa.2015.05.001 ]</b></a> Note that the division by rho is omitted here as we need rho times - //! the gradients later. - //! - real Dxy = -c3o1 * omega * m_110; - real Dxz = -c3o1 * omega * m_101; - real Dyz = -c3o1 * omega * m_011; - real dxux = c1o2 * (-omega) * (mxxMyy + mxxMzz) + c1o2 * OxxPyyPzz * (m_000 - mxxPyyPzz); - real dyuy = dxux + omega * c3o2 * mxxMyy; - real dzuz = dxux + omega * c3o2 * mxxMzz; - - //////////////////////////////////////////////////////////////////////////////////// - switch (turbulenceModel) - { - case TurbulenceModel::AMD: //AMD is computed in separate kernel - break; - case TurbulenceModel::Smagorinsky: - turbulentViscosity[k_000] = calcTurbulentViscositySmagorinsky(SGSconstant, dxux, dyuy, dzuz, Dxy, Dxz , Dyz); - break; - case TurbulenceModel::QR: - turbulentViscosity[k_000] = calcTurbulentViscosityQR(SGSconstant, dxux, dyuy, dzuz, Dxy, Dxz , Dyz); - break; - default: - break; - } - //////////////////////////////////////////////////////////// - //! - Relaxation of second order cumulants with correction terms according to Eq. (33)-(35) in - //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> - //! - mxxPyyPzz += OxxPyyPzz * (m_000 - mxxPyyPzz) - c3o1 * (c1o1 - c1o2 * OxxPyyPzz) * (vx2 * dxux + vy2 * dyuy + vz2 * dzuz); - mxxMyy += omega * (-mxxMyy) - c3o1 * (c1o1 + c1o2 * (-omega)) * (vx2 * dxux - vy2 * dyuy); - mxxMzz += omega * (-mxxMzz) - c3o1 * (c1o1 + c1o2 * (-omega)) * (vx2 * dxux - vz2 * dzuz); - - //////////////////////////////////////////////////////////////////////////////////// - ////no correction - // mxxPyyPzz += OxxPyyPzz*(mfaaa - mxxPyyPzz); - // mxxMyy += -(-omega) * (-mxxMyy); - // mxxMzz += -(-omega) * (-mxxMzz); - ////////////////////////////////////////////////////////////////////////// - m_011 += omega * (-m_011); - m_101 += omega * (-m_101); - m_110 += omega * (-m_110); - - //////////////////////////////////////////////////////////////////////////////////// - // relax - ////////////////////////////////////////////////////////////////////////// - // incl. limiter - //! - Relaxation of third order cumulants including limiter according to Eq. (116)-(123) - //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> - //! - real wadjust = Oxyz + (c1o1 - Oxyz) * abs(m_111) / (abs(m_111) + quadricLimitD); - m_111 += wadjust * (-m_111); - wadjust = OxyyPxzz + (c1o1 - OxyyPxzz) * abs(mxxyPyzz) / (abs(mxxyPyzz) + quadricLimitP); - mxxyPyzz += wadjust * (-mxxyPyzz); - wadjust = OxyyMxzz + (c1o1 - OxyyMxzz) * abs(mxxyMyzz) / (abs(mxxyMyzz) + quadricLimitM); - mxxyMyzz += wadjust * (-mxxyMyzz); - wadjust = OxyyPxzz + (c1o1 - OxyyPxzz) * abs(mxxzPyyz) / (abs(mxxzPyyz) + quadricLimitP); - mxxzPyyz += wadjust * (-mxxzPyyz); - wadjust = OxyyMxzz + (c1o1 - OxyyMxzz) * abs(mxxzMyyz) / (abs(mxxzMyyz) + quadricLimitM); - mxxzMyyz += wadjust * (-mxxzMyyz); - wadjust = OxyyPxzz + (c1o1 - OxyyPxzz) * abs(mxyyPxzz) / (abs(mxyyPxzz) + quadricLimitP); - mxyyPxzz += wadjust * (-mxyyPxzz); - wadjust = OxyyMxzz + (c1o1 - OxyyMxzz) * abs(mxyyMxzz) / (abs(mxyyMxzz) + quadricLimitM); - mxyyMxzz += wadjust * (-mxyyMxzz); - ////////////////////////////////////////////////////////////////////////// - // no limiter - // mfbbb += OxyyMxzz * (-mfbbb); - // mxxyPyzz += OxyyPxzz * (-mxxyPyzz); - // mxxyMyzz += OxyyMxzz * (-mxxyMyzz); - // mxxzPyyz += OxyyPxzz * (-mxxzPyyz); - // mxxzMyyz += OxyyMxzz * (-mxxzMyyz); - // mxyyPxzz += OxyyPxzz * (-mxyyPxzz); - // mxyyMxzz += OxyyMxzz * (-mxyyMxzz); - - //////////////////////////////////////////////////////////////////////////////////// - //! - Compute inverse linear combinations of second and third order cumulants - //! - m_200 = c1o3 * (mxxMyy + mxxMzz + mxxPyyPzz); - m_020 = c1o3 * (-c2o1 * mxxMyy + mxxMzz + mxxPyyPzz); - m_002 = c1o3 * (mxxMyy - c2o1 * mxxMzz + mxxPyyPzz); - - m_210 = ( mxxyMyzz + mxxyPyzz) * c1o2; - m_012 = (-mxxyMyzz + mxxyPyzz) * c1o2; - m_201 = ( mxxzMyyz + mxxzPyyz) * c1o2; - m_021 = (-mxxzMyyz + mxxzPyyz) * c1o2; - m_120 = ( mxyyMxzz + mxyyPxzz) * c1o2; - m_102 = (-mxyyMxzz + mxyyPxzz) * c1o2; - ////////////////////////////////////////////////////////////////////////// - - ////////////////////////////////////////////////////////////////////////// - // 4. - // no limiter - //! - Relax fourth order cumulants to modified equilibrium for fourth order convergence of diffusion according - //! to Eq. (43)-(48) <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> - //! - c_022 = -O4 * (c1o1 / omega - c1o2) * (dyuy + dzuz) * c2o3 * factorA + (c1o1 - O4) * (c_022); - c_202 = -O4 * (c1o1 / omega - c1o2) * (dxux + dzuz) * c2o3 * factorA + (c1o1 - O4) * (c_202); - c_220 = -O4 * (c1o1 / omega - c1o2) * (dyuy + dxux) * c2o3 * factorA + (c1o1 - O4) * (c_220); - c_112 = -O4 * (c1o1 / omega - c1o2) * Dxy * c1o3 * factorB + (c1o1 - O4) * (c_112); - c_121 = -O4 * (c1o1 / omega - c1o2) * Dxz * c1o3 * factorB + (c1o1 - O4) * (c_121); - c_211 = -O4 * (c1o1 / omega - c1o2) * Dyz * c1o3 * factorB + (c1o1 - O4) * (c_211); - - - ////////////////////////////////////////////////////////////////////////// - // 5. - c_122 += O5 * (-c_122); - c_212 += O5 * (-c_212); - c_221 += O5 * (-c_221); - - ////////////////////////////////////////////////////////////////////////// - // 6. - c_222 += O6 * (-c_222); - - //////////////////////////////////////////////////////////////////////////////////// - //! - Compute central moments from post collision cumulants according to Eq. (53)-(56) in - //! <a href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), - //! DOI:10.1016/j.jcp.2017.05.040 ]</b></a> - //! - - ////////////////////////////////////////////////////////////////////////// - // 4. - m_211 = c_211 + c1o3 * ((c3o1 * m_200 + c1o1) * m_011 + c6o1 * m_110 * m_101) * oneOverRho; - m_121 = c_121 + c1o3 * ((c3o1 * m_020 + c1o1) * m_101 + c6o1 * m_110 * m_011) * oneOverRho; - m_112 = c_112 + c1o3 * ((c3o1 * m_002 + c1o1) * m_110 + c6o1 * m_101 * m_011) * oneOverRho; - - m_220 = - c_220 + (((m_200 * m_020 + c2o1 * m_110 * m_110) * c9o1 + c3o1 * (m_200 + m_020)) * oneOverRho - (drho * oneOverRho)) * c1o9; - m_202 = - c_202 + (((m_200 * m_002 + c2o1 * m_101 * m_101) * c9o1 + c3o1 * (m_200 + m_002)) * oneOverRho - (drho * oneOverRho)) * c1o9; - m_022 = - c_022 + (((m_002 * m_020 + c2o1 * m_011 * m_011) * c9o1 + c3o1 * (m_002 + m_020)) * oneOverRho - (drho * oneOverRho)) * c1o9; - - ////////////////////////////////////////////////////////////////////////// - // 5. - m_122 = c_122 + c1o3 * - (c3o1 * (m_002 * m_120 + m_020 * m_102 + c4o1 * m_011 * m_111 + c2o1 * (m_101 * m_021 + m_110 * m_012)) + - (m_120 + m_102)) * oneOverRho; - m_212 = c_212 + c1o3 * - (c3o1 * (m_002 * m_210 + m_200 * m_012 + c4o1 * m_101 * m_111 + c2o1 * (m_011 * m_201 + m_110 * m_102)) + - (m_210 + m_012)) * oneOverRho; - m_221 = c_221 + c1o3 * - (c3o1 * (m_200 * m_021 + m_020 * m_201 + c4o1 * m_110 * m_111 + c2o1 * (m_101 * m_120 + m_011 * m_210)) + - (m_021 + m_201)) * oneOverRho; - - ////////////////////////////////////////////////////////////////////////// - // 6. - m_222 = c_222 - ((-c4o1 * m_111 * m_111 - (m_200 * m_022 + m_020 * m_202 + m_002 * m_220) - - c4o1 * (m_011 * m_211 + m_101 * m_121 + m_110 * m_112) - - c2o1 * (m_120 * m_102 + m_210 * m_012 + m_201 * m_021)) * - oneOverRho + - (c4o1 * (m_101 * m_101 * m_020 + m_011 * m_011 * m_200 + m_110 * m_110 * m_002) + - c2o1 * (m_200 * m_020 * m_002) + c16o1 * m_110 * m_101 * m_011) * - oneOverRho * oneOverRho - - c1o3 * (m_022 + m_202 + m_220) * oneOverRho - c1o9 * (m_200 + m_020 + m_002) * oneOverRho + - (c2o1 * (m_101 * m_101 + m_011 * m_011 + m_110 * m_110) + - (m_002 * m_020 + m_002 * m_200 + m_020 * m_200) + c1o3 * (m_002 + m_020 + m_200)) * - oneOverRho * oneOverRho * c2o3 + - c1o27 * ((drho * drho - drho) * oneOverRho * oneOverRho)); - - //////////////////////////////////////////////////////////////////////////////////// - //! - Add acceleration (body force) to first order cumulants according to Eq. (85)-(87) in - //! <a href="https://doi.org/10.1016/j.camwa.2015.05.001"><b>[ M. Geier et al. (2015), - //! DOI:10.1016/j.camwa.2015.05.001 ]</b></a> - //! - m_100 = -m_100; - m_010 = -m_010; - m_001 = -m_001; - - //Write to array here to distribute read/write - rho[k_000] = drho; - vx[k_000] = vvx; - vy[k_000] = vvy; - vz[k_000] = vvz; - - //////////////////////////////////////////////////////////////////////////////////// - //! - Chimera transform from central moments to well conditioned distributions as defined in Appendix J in - //! <a href="https://doi.org/10.1016/j.camwa.2015.05.001"><b>[ M. Geier et al. (2015), - //! DOI:10.1016/j.camwa.2015.05.001 ]</b></a> see also Eq. (88)-(96) in <a - //! href="https://doi.org/10.1016/j.jcp.2017.05.040"><b>[ M. Geier et al. (2017), DOI:10.1016/j.jcp.2017.05.040 - //! ]</b></a> - //! - //////////////////////////////////////////////////////////////////////////////////// - // X - Dir - backwardInverseChimeraWithK(m_000, m_100, m_200, vvx, vx2, c1o1, c1o1); - backwardChimera( m_010, m_110, m_210, vvx, vx2); - backwardInverseChimeraWithK(m_020, m_120, m_220, vvx, vx2, c3o1, c1o3); - backwardChimera( m_001, m_101, m_201, vvx, vx2); - backwardChimera( m_011, m_111, m_211, vvx, vx2); - backwardChimera( m_021, m_121, m_221, vvx, vx2); - backwardInverseChimeraWithK(m_002, m_102, m_202, vvx, vx2, c3o1, c1o3); - backwardChimera( m_012, m_112, m_212, vvx, vx2); - backwardInverseChimeraWithK(m_022, m_122, m_222, vvx, vx2, c9o1, c1o9); - - //////////////////////////////////////////////////////////////////////////////////// - // Y - Dir - backwardInverseChimeraWithK(m_000, m_010, m_020, vvy, vy2, c6o1, c1o6); - backwardChimera( m_001, m_011, m_021, vvy, vy2); - backwardInverseChimeraWithK(m_002, m_012, m_022, vvy, vy2, c18o1, c1o18); - backwardInverseChimeraWithK(m_100, m_110, m_120, vvy, vy2, c3o2, c2o3); - backwardChimera( m_101, m_111, m_121, vvy, vy2); - backwardInverseChimeraWithK(m_102, m_112, m_122, vvy, vy2, c9o2, c2o9); - backwardInverseChimeraWithK(m_200, m_210, m_220, vvy, vy2, c6o1, c1o6); - backwardChimera( m_201, m_211, m_221, vvy, vy2); - backwardInverseChimeraWithK(m_202, m_212, m_222, vvy, vy2, c18o1, c1o18); - - //////////////////////////////////////////////////////////////////////////////////// - // Z - Dir - backwardInverseChimeraWithK(m_000, m_001, m_002, vvz, vz2, c36o1, c1o36); - backwardInverseChimeraWithK(m_010, m_011, m_012, vvz, vz2, c9o1, c1o9); - backwardInverseChimeraWithK(m_020, m_021, m_022, vvz, vz2, c36o1, c1o36); - backwardInverseChimeraWithK(m_100, m_101, m_102, vvz, vz2, c9o1, c1o9); - backwardInverseChimeraWithK(m_110, m_111, m_112, vvz, vz2, c9o4, c4o9); - backwardInverseChimeraWithK(m_120, m_121, m_122, vvz, vz2, c9o1, c1o9); - backwardInverseChimeraWithK(m_200, m_201, m_202, vvz, vz2, c36o1, c1o36); - backwardInverseChimeraWithK(m_210, m_211, m_212, vvz, vz2, c9o1, c1o9); - backwardInverseChimeraWithK(m_220, m_221, m_222, vvz, vz2, c36o1, c1o36); - - //////////////////////////////////////////////////////////////////////////////////// - //! - Write distributions: style of reading and writing the distributions from/to - //! stored arrays dependent on timestep is based on the esoteric twist algorithm - //! <a href="https://doi.org/10.3390/computation5020019"><b>[ M. Geier et al. (2017), - //! DOI:10.3390/computation5020019 ]</b></a> - //! - (dist.f[DIR_P00])[k_000] = f_M00; - (dist.f[DIR_M00])[k_M00] = f_P00; - (dist.f[DIR_0P0])[k_000] = f_0M0; - (dist.f[DIR_0M0])[k_0M0] = f_0P0; - (dist.f[DIR_00P])[k_000] = f_00M; - (dist.f[DIR_00M])[k_00M] = f_00P; - (dist.f[DIR_PP0])[k_000] = f_MM0; - (dist.f[DIR_MM0])[k_MM0] = f_PP0; - (dist.f[DIR_PM0])[k_0M0] = f_MP0; - (dist.f[DIR_MP0])[k_M00] = f_PM0; - (dist.f[DIR_P0P])[k_000] = f_M0M; - (dist.f[DIR_M0M])[k_M0M] = f_P0P; - (dist.f[DIR_P0M])[k_00M] = f_M0P; - (dist.f[DIR_M0P])[k_M00] = f_P0M; - (dist.f[DIR_0PP])[k_000] = f_0MM; - (dist.f[DIR_0MM])[k_0MM] = f_0PP; - (dist.f[DIR_0PM])[k_00M] = f_0MP; - (dist.f[DIR_0MP])[k_0M0] = f_0PM; - (dist.f[DIR_000])[k_000] = f_000; - (dist.f[DIR_PPP])[k_000] = f_MMM; - (dist.f[DIR_PMP])[k_0M0] = f_MPM; - (dist.f[DIR_PPM])[k_00M] = f_MMP; - (dist.f[DIR_PMM])[k_0MM] = f_MPP; - (dist.f[DIR_MPP])[k_M00] = f_PMM; - (dist.f[DIR_MMP])[k_MM0] = f_PPM; - (dist.f[DIR_MPM])[k_M0M] = f_PMP; - (dist.f[DIR_MMM])[k_MMM] = f_PPP; - } -} - -template __global__ void LB_Kernel_TurbulentViscosityCumulantK17CompChim < TurbulenceModel::AMD > ( real omega_in, uint* typeOfGridNode, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, bool bodyForce, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep); - -template __global__ void LB_Kernel_TurbulentViscosityCumulantK17CompChim < TurbulenceModel::Smagorinsky > ( real omega_in, uint* typeOfGridNode, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, bool bodyForce, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep); - -template __global__ void LB_Kernel_TurbulentViscosityCumulantK17CompChim < TurbulenceModel::QR > ( real omega_in, uint* typeOfGridNode, uint* neighborX, uint* neighborY, uint* neighborZ, real* distributions, real* rho, real* vx, real* vy, real* vz, real* turbulentViscosity, real SGSconstant, unsigned long size_Mat, int level, bool bodyForce, real* forces, real* bodyForceX, real* bodyForceY, real* bodyForceZ, real* quadricLimiters, bool isEvenTimestep); diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/TurbulentViscosityFluidFlowCompStrategy.cpp b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/TurbulentViscosityFluidFlowCompStrategy.cpp deleted file mode 100644 index f3615a89994f0ca1fafdc1eda905d3c3b615d478..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/TurbulentViscosityFluidFlowCompStrategy.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include "TurbulentViscosityFluidFlowCompStrategy.h" - -#include "Parameter/Parameter.h" - -std::shared_ptr<TurbulentViscosityFluidFlowCompStrategy> TurbulentViscosityFluidFlowCompStrategy::getInstance() -{ - static std::shared_ptr<TurbulentViscosityFluidFlowCompStrategy> uniqueInstance; - if (!uniqueInstance) - uniqueInstance = std::shared_ptr<TurbulentViscosityFluidFlowCompStrategy>(new TurbulentViscosityFluidFlowCompStrategy()); - return uniqueInstance; -} - -bool TurbulentViscosityFluidFlowCompStrategy::checkParameter(std::shared_ptr<Parameter> para) -{ - if (!para->getUseTurbulentViscosity()) - return false; - else if (!para->getCompOn()) - return false; - else - return true; -} - -TurbulentViscosityFluidFlowCompStrategy::TurbulentViscosityFluidFlowCompStrategy() {} diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/TurbulentViscosityFluidFlowCompStrategy.h b/src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/TurbulentViscosityFluidFlowCompStrategy.h deleted file mode 100644 index 95eff17777f7f0d1c3e05fe1b0d93892a88646a4..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/TurbulentViscosityFluidFlowCompStrategy.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef AMD_FLUID_FLOW_COMP_STRATEGY_H -#define AMD_FLUID_FLOW_COMP_STRATEGY_H - -#include "Kernel/Utilities/CheckParameterStrategy/CheckParameterStrategy.h" - - -class TurbulentViscosityFluidFlowCompStrategy : public CheckParameterStrategy -{ -public: - static std::shared_ptr<TurbulentViscosityFluidFlowCompStrategy> getInstance(); - - bool checkParameter(std::shared_ptr<Parameter> para); - -private: - TurbulentViscosityFluidFlowCompStrategy(); - -}; -#endif \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/Kernel/Utilities/KernelFactory/KernelFactoryImp.cpp b/src/gpu/VirtualFluids_GPU/Kernel/Utilities/KernelFactory/KernelFactoryImp.cpp index 53ec240f096080097416e640fdd095c3812fb34c..5a2d8c9a426e5cb23ca75f91aaf6fbff75cba72b 100644 --- a/src/gpu/VirtualFluids_GPU/Kernel/Utilities/KernelFactory/KernelFactoryImp.cpp +++ b/src/gpu/VirtualFluids_GPU/Kernel/Utilities/KernelFactory/KernelFactoryImp.cpp @@ -8,11 +8,9 @@ #include "Kernel/Kernels/BasicKernels/FluidFlow/Compressible/BGKPlus/BGKPlusCompSP27.h" #include "Kernel/Kernels/BasicKernels/FluidFlow/Compressible/Cascade/CascadeCompSP27.h" #include "Kernel/Kernels/BasicKernels/FluidFlow/Compressible/Cumulant/CumulantCompSP27.h" -#include "Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17Comp.h" #include "Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17Unified/CumulantK17Unified.h" #include "Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chim/CumulantK17CompChim.h" -#include "Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimStream/CumulantK17CompChimStream.h" -#include "Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17chimRedesigned/CumulantK17CompChimRedesigned.h" +#include "Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17/CumulantK17.h" #include "Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK17Bulk/CumulantK17BulkComp.h" #include "Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantAll4/CumulantAll4CompSP27.h" #include "Kernel/Kernels/BasicKernels/FluidFlow/Compressible/CumulantK18/CumulantK18Comp.h" @@ -49,9 +47,6 @@ #include "Kernel/Kernels/WaleKernels/FluidFlow/Compressible/CumulantK15/WaleCumulantK15Comp.h" #include "Kernel/Kernels/WaleKernels/FluidFlow/Compressible/CumulantK15BySoniMalav/WaleBySoniMalavCumulantK15Comp.h" -//turbulent viscosity kernel -#include "Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/CumulantK17chim/TurbulentViscosityCumulantK17CompChim.h" - //strategies #include "Kernel/Kernels/BasicKernels/FluidFlow/Compressible/FluidFlowCompStrategy.h" #include "Kernel/Kernels/BasicKernels/FluidFlow/Incompressible/FluidFlowIncompStrategy.h" @@ -61,7 +56,6 @@ #include "Kernel/Kernels/BasicKernels/AdvectionDiffusion/Incompressible/Mod7/ADMod7IncompStrategy.h" #include "Kernel/Kernels/PorousMediaKernels/FluidFlow/Compressible/PMFluidFlowCompStrategy.h" #include "Kernel/Kernels/WaleKernels/FluidFlow/Compressible/WaleFluidFlowCompStrategy.h" -#include "Kernel/Kernels/TurbulentViscosityKernels/FluidFlow/Compressible/TurbulentViscosityFluidFlowCompStrategy.h" std::vector<std::shared_ptr<Kernel>> KernelFactoryImp::makeKernels(std::shared_ptr<Parameter> para) { @@ -118,9 +112,6 @@ std::shared_ptr<Kernel> KernelFactoryImp::makeKernel(std::shared_ptr<Parameter> } else if (kernel == "CumulantCompSP27") { newKernel = CumulantCompSP27::getNewInstance(para, level); checkStrategy = FluidFlowCompStrategy::getInstance(); - } else if (kernel == "CumulantK17Comp") { - newKernel = CumulantK17Comp::getNewInstance(para, level); - checkStrategy = FluidFlowCompStrategy::getInstance(); } else if (kernel == "CumulantK15Unified") { newKernel = std::make_shared<vf::gpu::CumulantK15Unified>(para, level); checkStrategy = FluidFlowCompStrategy::getInstance(); @@ -133,12 +124,26 @@ std::shared_ptr<Kernel> KernelFactoryImp::makeKernel(std::shared_ptr<Parameter> } else if (kernel == "CumulantK17CompChim") { newKernel = CumulantK17CompChim::getNewInstance(para, level); checkStrategy = FluidFlowCompStrategy::getInstance(); - } else if (kernel == "CumulantK17CompChimStream") { - newKernel = CumulantK17CompChimStream::getNewInstance(para, level); - checkStrategy = FluidFlowCompStrategy::getInstance(); - } else if (kernel == "CumulantK17CompChimRedesigned") { - newKernel = CumulantK17CompChimRedesigned::getNewInstance(para, level); - checkStrategy = FluidFlowCompStrategy::getInstance(); + } else if (kernel == "CumulantK17"){ + switch(para->getTurbulenceModel()) + { + case TurbulenceModel::AMD: + newKernel = CumulantK17<TurbulenceModel::AMD>::getNewInstance(para, level); + break; + case TurbulenceModel::Smagorinsky: + newKernel = CumulantK17<TurbulenceModel::Smagorinsky>::getNewInstance(para, level); + break; + case TurbulenceModel::QR: + newKernel = CumulantK17<TurbulenceModel::QR>::getNewInstance(para, level); + break; + case TurbulenceModel::None: + newKernel = CumulantK17<TurbulenceModel::None>::getNewInstance(para, level); + break; + default: + throw std::runtime_error("Unknown turbulence model!"); + break; + } + checkStrategy = FluidFlowCompStrategy::getInstance(); } else if (kernel == "CumulantAll4CompSP27") { newKernel = CumulantAll4CompSP27::getNewInstance(para, level); checkStrategy = FluidFlowCompStrategy::getInstance(); @@ -197,35 +202,9 @@ std::shared_ptr<Kernel> KernelFactoryImp::makeKernel(std::shared_ptr<Parameter> newKernel = WaleBySoniMalavCumulantK15Comp::getNewInstance(para, level);// || checkStrategy = WaleFluidFlowCompStrategy::getInstance(); // wale model } //=============== - else if (kernel == "TurbulentViscosityCumulantK17CompChim"){ // compressible with turbulent viscosity - switch(para->getTurbulenceModel()) // || - { // \/ // - case TurbulenceModel::AMD: - newKernel = TurbulentViscosityCumulantK17CompChim<TurbulenceModel::AMD>::getNewInstance(para, level); - break; - case TurbulenceModel::Smagorinsky: - newKernel = TurbulentViscosityCumulantK17CompChim<TurbulenceModel::Smagorinsky>::getNewInstance(para, level); - break; - case TurbulenceModel::QR: - newKernel = TurbulentViscosityCumulantK17CompChim<TurbulenceModel::QR>::getNewInstance(para, level); - break; - case TurbulenceModel::None: - throw std::runtime_error("TurbulentViscosityCumulantK17CompChim currently not implemented for TurbulenceModel::None!"); - break; - default: - throw std::runtime_error("Unknown turbulence model!"); - break; - } - checkStrategy = TurbulentViscosityFluidFlowCompStrategy::getInstance(); - // /\ // - // || - // compressible with turbulent viscosity - //=============== - } else { throw std::runtime_error("KernelFactory does not know the KernelType."); } - newKernel->setCheckParameterStrategy(checkStrategy); para->setKernelNeedsFluidNodeIndicesToRun(newKernel->getKernelUsesFluidNodeIndices()); return newKernel; diff --git a/src/gpu/VirtualFluids_GPU/KernelManager/BCKernelManager.cpp b/src/gpu/VirtualFluids_GPU/KernelManager/BCKernelManager.cpp index cc945ea225a28c58dca4ceefdb80fffb76228b21..1310cf09e5ce05270e88cd3a53e4910816bd7628 100644 --- a/src/gpu/VirtualFluids_GPU/KernelManager/BCKernelManager.cpp +++ b/src/gpu/VirtualFluids_GPU/KernelManager/BCKernelManager.cpp @@ -38,6 +38,7 @@ #include "BCKernelManager.h" #include "Factories/BoundaryConditionFactory.h" +#include "GridGenerator/TransientBCSetter/TransientBCSetter.h" #include "Calculation/Cp.h" #include "Calculation/DragLift.h" #include "GPU/GPU_Interface.h" @@ -51,6 +52,7 @@ BCKernelManager::BCKernelManager(SPtr<Parameter> parameter, BoundaryConditionFac this->pressureBoundaryConditionPre = bcFactory->getPressureBoundaryConditionPre(); this->geometryBoundaryConditionPost = bcFactory->getGeometryBoundaryConditionPost(); this->stressBoundaryConditionPost = bcFactory->getStressBoundaryConditionPost(); + this->precursorBoundaryConditionPost = bcFactory->getPrecursorBoundaryConditionPost(); checkBoundaryCondition(this->velocityBoundaryConditionPost, this->para->getParD(0)->velocityBC, "velocityBoundaryConditionPost"); @@ -64,6 +66,8 @@ BCKernelManager::BCKernelManager(SPtr<Parameter> parameter, BoundaryConditionFac "geometryBoundaryConditionPost"); checkBoundaryCondition(this->stressBoundaryConditionPost, this->para->getParD(0)->stressBC, "stressBoundaryConditionPost"); + checkBoundaryCondition(this->precursorBoundaryConditionPost, this->para->getParD(0)->precursorBC, + "precursorBoundaryConditionPost"); } void BCKernelManager::runVelocityBCKernelPre(const int level) const @@ -387,3 +391,41 @@ void BCKernelManager::runNoSlipBCKernelPost(const int level) const{ noSlipBoundaryConditionPost(para->getParD(level).get(), &(para->getParD(level)->noSlipBC)); } } + +void BCKernelManager::runPrecursorBCKernelPost(int level, uint t, CudaMemoryManager* cudaMemoryManager) +{ + if(para->getParH(level)->precursorBC.numberOfBCnodes == 0) return; + + uint t_level = para->getTimeStep(level, t, true); + + uint lastTime = (para->getParD(level)->precursorBC.nPrecursorReads-2)*para->getParD(level)->precursorBC.timeStepsBetweenReads; // timestep currently loaded into last arrays + uint currentTime = (para->getParD(level)->precursorBC.nPrecursorReads-1)*para->getParD(level)->precursorBC.timeStepsBetweenReads; // timestep currently loaded into current arrays + uint nextTime = para->getParD(level)->precursorBC.nPrecursorReads *para->getParD(level)->precursorBC.timeStepsBetweenReads; // timestep currently loaded into next arrays + + if(t_level>=currentTime) + { + //cycle time + lastTime = currentTime; + currentTime = nextTime; + nextTime += para->getParD(level)->precursorBC.timeStepsBetweenReads; + + //cycle pointers + real* tmp = para->getParD(level)->precursorBC.last; + para->getParD(level)->precursorBC.last = para->getParD(level)->precursorBC.current; + para->getParD(level)->precursorBC.current = para->getParD(level)->precursorBC.next; + para->getParD(level)->precursorBC.next = tmp; + + real loadTime = nextTime*pow(2,-level)*para->getTimeRatio(); + + for(auto reader : para->getParH(level)->transientBCInputFileReader) + { + reader->getNextData(para->getParH(level)->precursorBC.next, para->getParH(level)->precursorBC.numberOfPrecursorNodes, loadTime); + } + cudaMemoryManager->cudaCopyPrecursorData(level); + para->getParD(level)->precursorBC.nPrecursorReads++; + para->getParH(level)->precursorBC.nPrecursorReads++; + } + + real tRatio = real(t_level-lastTime)/para->getParD(level)->precursorBC.timeStepsBetweenReads; + precursorBoundaryConditionPost(para->getParD(level).get(), ¶->getParD(level)->precursorBC, tRatio, para->getVelocityRatio()); +} \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/KernelManager/BCKernelManager.h b/src/gpu/VirtualFluids_GPU/KernelManager/BCKernelManager.h index 423a9cc9056281a3a2a135ae32fa26cc47f93967..339100e6b5307e8e60f8d0846560bf89c6eea1a1 100644 --- a/src/gpu/VirtualFluids_GPU/KernelManager/BCKernelManager.h +++ b/src/gpu/VirtualFluids_GPU/KernelManager/BCKernelManager.h @@ -41,6 +41,7 @@ #include "PointerDefinitions.h" #include "VirtualFluids_GPU_export.h" + class CudaMemoryManager; class BoundaryConditionFactory; class Parameter; @@ -48,6 +49,7 @@ struct LBMSimulationParameter; using boundaryCondition = std::function<void(LBMSimulationParameter *, QforBoundaryConditions *)>; using boundaryConditionWithParameter = std::function<void(Parameter *, QforBoundaryConditions *, const int level)>; +using precursorBoundaryCondition = std::function<void(LBMSimulationParameter *, QforPrecursorBoundaryConditions *, real tRatio, real velocityRatio)>; //! \class BCKernelManager //! \brief manage the cuda kernel calls to boundary conditions @@ -84,7 +86,10 @@ public: //! \brief calls the device function of the pressure boundary condition (post-collision) void runPressureBCKernelPost(const int level) const; - //! \brief calls the device function of the outflow boundary condition (pre-collision) + //! \brief calls the device function of the precursor boundary condition + void runPrecursorBCKernelPost(int level, uint t, CudaMemoryManager* cudaMemoryManager); + + //! \brief calls the device function of the outflow boundary condition void runOutflowBCKernelPre(const int level) const; //! \brief calls the device function of the stress wall model (post-collision) @@ -96,13 +101,16 @@ private: //! \param boundaryCondition: a kernel function for the boundary condition //! \param bcStruct: a struct containing the grid nodes which are part of the boundary condition //! \param bcName: the name of the checked boundary condition - template <typename bcFunction> - void checkBoundaryCondition(const bcFunction &boundaryCondition, const QforBoundaryConditions &bcStruct, const std::string &bcName) + template <typename bcFunction, typename QforBC> + void checkBoundaryCondition(const bcFunction &boundaryCondition, const QforBC &bcStruct, const std::string &bcName) { if (!boundaryCondition && bcStruct.numberOfBCnodes > 0) throw std::runtime_error("The boundary condition " + bcName + " was not set!"); } + void runDistributionPrecursorBCKernelPost(int level, uint t, CudaMemoryManager* cudaMemoryManager); + void runVelocityPrecursorBCKernelPost(int level, uint t, CudaMemoryManager* cudaMemoryManager); + SPtr<Parameter> para; boundaryCondition velocityBoundaryConditionPost = nullptr; @@ -111,5 +119,6 @@ private: boundaryCondition pressureBoundaryConditionPre = nullptr; boundaryCondition geometryBoundaryConditionPost = nullptr; boundaryConditionWithParameter stressBoundaryConditionPost = nullptr; + precursorBoundaryCondition precursorBoundaryConditionPost = nullptr; }; #endif diff --git a/src/gpu/VirtualFluids_GPU/KernelManager/BCKernelManagerTest.cpp b/src/gpu/VirtualFluids_GPU/KernelManager/BCKernelManagerTest.cpp index d55fa51bd8a225dd4e89e684bc81cd56f3f450c0..a0e02112e821eedcfeb013d3465529f668309529 100644 --- a/src/gpu/VirtualFluids_GPU/KernelManager/BCKernelManagerTest.cpp +++ b/src/gpu/VirtualFluids_GPU/KernelManager/BCKernelManagerTest.cpp @@ -53,3 +53,9 @@ TEST_F(BCKernelManagerTest_BCsNotSpecified, stressBoundaryConditionPost_NotSpeci para->getParD(0)->stressBC.numberOfBCnodes = 1; EXPECT_THROW(BCKernelManager(para, &bcFactory), std::runtime_error); } + +TEST_F(BCKernelManagerTest_BCsNotSpecified, precursorBoundaryConditionPost_NotSpecified) +{ + para->getParD(0)->precursorBC.numberOfBCnodes = 1; + EXPECT_THROW(BCKernelManager(para, &bcFactory), std::runtime_error); +} diff --git a/src/gpu/VirtualFluids_GPU/KernelManager/GridScalingKernelManager.cpp b/src/gpu/VirtualFluids_GPU/KernelManager/GridScalingKernelManager.cpp index c3129e31a9c750a012a26d58961062eaf3f40add..2b6a266c0d4e5f523091fa4982eee5d83b2ec675 100644 --- a/src/gpu/VirtualFluids_GPU/KernelManager/GridScalingKernelManager.cpp +++ b/src/gpu/VirtualFluids_GPU/KernelManager/GridScalingKernelManager.cpp @@ -59,8 +59,9 @@ GridScalingKernelManager::GridScalingKernelManager(SPtr<Parameter> parameter, Gr VF_LOG_TRACE("Function for scalingCoarseToFine is nullptr"); } -void GridScalingKernelManager::runFineToCoarseKernelLB(const int level, InterpolationCellFC *icellFC, OffFC &offFC, int streamIndex) const{ - cudaStream_t stream = (streamIndex == -1) ? CU_STREAM_LEGACY : para->getStreamManager()->getStream(streamIndex); +void GridScalingKernelManager::runFineToCoarseKernelLB(const int level, InterpolationCellFC *icellFC, OffFC &offFC, CudaStreamIndex streamIndex) const +{ + cudaStream_t stream = para->getStreamManager()->getStream(streamIndex); this->scalingFineToCoarse(para->getParD(level).get(), para->getParD(level+1).get(), icellFC, offFC, stream); @@ -327,9 +328,9 @@ void GridScalingKernelManager::runFineToCoarseKernelAD(const int level) const } } -void GridScalingKernelManager::runCoarseToFineKernelLB(const int level, InterpolationCellCF* icellCF, OffCF &offCF, int streamIndex) const +void GridScalingKernelManager::runCoarseToFineKernelLB(const int level, InterpolationCellCF* icellCF, OffCF &offCF, CudaStreamIndex streamIndex) const { - cudaStream_t stream = (streamIndex == -1) ? CU_STREAM_LEGACY : para->getStreamManager()->getStream(streamIndex); + cudaStream_t stream = para->getStreamManager()->getStream(streamIndex); this->scalingCoarseToFine(para->getParD(level).get(), para->getParD(level+1).get(), icellCF, offCF, stream); // ScaleCF_comp_D3Q27F3( diff --git a/src/gpu/VirtualFluids_GPU/KernelManager/GridScalingKernelManager.h b/src/gpu/VirtualFluids_GPU/KernelManager/GridScalingKernelManager.h index 85cdd88ec2e3a6622108026ce8f53c5c770f8afe..3c78ee7f9db254556e8ec6dbbafaf51cd995f10b 100644 --- a/src/gpu/VirtualFluids_GPU/KernelManager/GridScalingKernelManager.h +++ b/src/gpu/VirtualFluids_GPU/KernelManager/GridScalingKernelManager.h @@ -44,6 +44,7 @@ class Parameter; class CudaMemoryManager; class GridScalingFactory; +enum class CudaStreamIndex; struct LBMSimulationParameter; struct CUstream_st; @@ -62,14 +63,14 @@ public: //! \throws std::runtime_error when the user forgets to specify a scaling function GridScalingKernelManager(SPtr<Parameter> parameter, GridScalingFactory *gridScalingFactory); - //! \brief calls the device function of the fine to coarse grid interpolation kernel - void runFineToCoarseKernelLB(const int level, InterpolationCellFC *icellFC, OffFC &offFC, int streamIndex) const; + //! \brief calls the device function of the fine to coarse grid interpolation kernelH + void runFineToCoarseKernelLB(const int level, InterpolationCellFC *icellFC, OffFC &offFC, CudaStreamIndex streamIndex) const; //! \brief calls the device function of the fine to coarse grid interpolation kernel (advection diffusion) void runFineToCoarseKernelAD(const int level) const; //! \brief calls the device function of the coarse to fine grid interpolation kernel - void runCoarseToFineKernelLB(const int level, InterpolationCellCF *icellCF, OffCF &offCF, int streamIndex) const; + void runCoarseToFineKernelLB(const int level, InterpolationCellCF *icellCF, OffCF &offCF, CudaStreamIndex streamIndex) const; //! \brief calls the device function of the coarse to fine grid interpolation kernel (advection diffusion) void runCoarseToFineKernelAD(const int level) const; diff --git a/src/gpu/VirtualFluids_GPU/LBM/LB.h b/src/gpu/VirtualFluids_GPU/LBM/LB.h index eea4adfda3c1ef0862f39ef58fc6e065af7bab1b..a7517ca0f07b9c1379501aa3ff750637d230a7bd 100644 --- a/src/gpu/VirtualFluids_GPU/LBM/LB.h +++ b/src/gpu/VirtualFluids_GPU/LBM/LB.h @@ -53,17 +53,33 @@ //! \brief An enumeration for selecting a turbulence model enum class TurbulenceModel { //! - Smagorinsky - Smagorinsky, + Smagorinsky, //! - AMD (Anisotropic Minimum Dissipation) model, see e.g. Rozema et al., Phys. Fluids 27, 085107 (2015), https://doi.org/10.1063/1.4928700 - AMD, + AMD, //! - QR model by Verstappen - QR, + QR, //! - TODO: move the WALE model here from the old kernels //WALE //! - No turbulence model - None + None }; +//! \brief An enumeration for selecting a template of the collision kernel (CumulantK17) +enum class CollisionTemplate { + //! - Default: plain collision without additional read/write + Default, + //! - WriteMacroVars: collision \w write out macroscopic variables + WriteMacroVars, + //! - ApplyBodyForce: collision \w read and apply body force in the collision kernel + ApplyBodyForce, + //! - AllFeatures: collision \w write out macroscopic variables AND read and apply body force + AllFeatures, + //! - Border: collision on border nodes + SubDomainBorder +}; +constexpr std::initializer_list<CollisionTemplate> all_CollisionTemplate = { CollisionTemplate::Default, CollisionTemplate::WriteMacroVars, CollisionTemplate::ApplyBodyForce, CollisionTemplate::AllFeatures, CollisionTemplate::SubDomainBorder}; +constexpr std::initializer_list<CollisionTemplate> bulk_CollisionTemplate = { CollisionTemplate::Default, CollisionTemplate::WriteMacroVars, CollisionTemplate::ApplyBodyForce, CollisionTemplate::AllFeatures}; + struct InitCondition { real Re; @@ -144,6 +160,7 @@ struct InitCondition bool hasWallModelMonitor {false}; bool simulatePorousMedia {false}; bool streetVelocityFile {false}; + real outflowPressureCorrectionFactor {0.0}; }; //Interface Cells @@ -214,6 +231,21 @@ typedef struct QforBC{ real *normalX, *normalY, *normalZ; }QforBoundaryConditions; +typedef struct QforPrecursorBC{ + int* k; + int numberOfBCnodes=0; + int sizeQ; + int numberOfPrecursorNodes=0; + uint nPrecursorReads=0; + uint timeStepsBetweenReads; + size_t numberOfQuantities; + real* q27[27]; + uint* planeNeighbor0PP, *planeNeighbor0PM, *planeNeighbor0MP, *planeNeighbor0MM; + real* weights0PP, *weights0PM, *weights0MP, *weights0MM; + real* last, *current, *next; + real velocityX, velocityY, velocityZ; +}QforPrecursorBoundaryConditions; + //BCTemp typedef struct TempforBC{ int* k; @@ -249,6 +281,7 @@ typedef struct WMparas{ real* Fz; }WallModelParameters; + //measurePoints typedef struct MeasP{ std::string name; diff --git a/src/gpu/VirtualFluids_GPU/LBM/Simulation.cpp b/src/gpu/VirtualFluids_GPU/LBM/Simulation.cpp index 703e935e6edb5676c7d6e045a38e3ec20d7a4b41..84ab84ff93fa7706bcc27d7e61a18f580f3c8dbe 100644 --- a/src/gpu/VirtualFluids_GPU/LBM/Simulation.cpp +++ b/src/gpu/VirtualFluids_GPU/LBM/Simulation.cpp @@ -97,11 +97,7 @@ void Simulation::init(GridProvider &gridProvider, BoundaryConditionFactory *bcFa gridProvider.allocAndCopyForcing(); gridProvider.allocAndCopyQuadricLimiters(); - if (para->getKernelNeedsFluidNodeIndicesToRun()) { - gridProvider.allocArrays_fluidNodeIndices(); - gridProvider.allocArrays_fluidNodeIndicesBorder(); - } - + gridProvider.setDimensions(); gridProvider.setBoundingBox(); @@ -113,12 +109,7 @@ void Simulation::init(GridProvider &gridProvider, BoundaryConditionFactory *bcFa para->setStartTurn((unsigned int)0); // 100000 restart_object = std::make_shared<ASCIIRestartObject>(); - ////////////////////////////////////////////////////////////////////////// - // CUDA streams - if (para->getUseStreams()) { - para->getStreamManager()->launchStreams(2u); - para->getStreamManager()->createCudaEvents(); - } + ////////////////////////////////////////////////////////////////////////// VF_LOG_INFO("LB_Modell: D3Q{}", para->getD3Qxx()); VF_LOG_INFO("Re: {}", para->getRe()); @@ -134,14 +125,32 @@ void Simulation::init(GridProvider &gridProvider, BoundaryConditionFactory *bcFa ////////////////////////////////////////////////////////////////////////// allocNeighborsOffsetsScalesAndBoundaries(gridProvider); + //! Get tagged fluid nodes with corresponding value for CollisionTemplate from interactors for (SPtr<PreCollisionInteractor> actuator : para->getActuators()) { actuator->init(para.get(), &gridProvider, cudaMemoryManager.get()); + actuator->getTaggedFluidNodes( para.get(), &gridProvider ); } for (SPtr<PreCollisionInteractor> probe : para->getProbes()) { probe->init(para.get(), &gridProvider, cudaMemoryManager.get()); + probe->getTaggedFluidNodes( para.get(), &gridProvider ); } + ////////////////////////////////////////////////////////////////////////// + // CUDA streams + if (para->getUseStreams()) { + para->getStreamManager()->registerStream(CudaStreamIndex::SubDomainBorder); + para->getStreamManager()->registerStream(CudaStreamIndex::Bulk); + para->getStreamManager()->launchStreams(); + para->getStreamManager()->createCudaEvents(); + } + ////////////////////////////////////////////////////////////////////////// + + if (para->getKernelNeedsFluidNodeIndicesToRun()) + { + gridProvider.sortFluidNodeTags(); + gridProvider.allocArrays_taggedFluidNodes(); + } ////////////////////////////////////////////////////////////////////////// // Kernel init ////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/VirtualFluids_GPU/Output/DistributionDebugInspector.cu b/src/gpu/VirtualFluids_GPU/Output/DistributionDebugInspector.cu new file mode 100644 index 0000000000000000000000000000000000000000..9ff86ea36c5b3c465990d622547d98cb4686f929 --- /dev/null +++ b/src/gpu/VirtualFluids_GPU/Output/DistributionDebugInspector.cu @@ -0,0 +1,143 @@ + +#include "DistributionDebugInspector.h" + +#include "Parameter/Parameter.h" +#include "LBM/LB.h" +#include "lbm/constants/D3Q27.h" +#include <lbm/constants/NumericConstants.h> +#include "Kernel/Utilities/DistributionHelper.cuh" + +#include <cuda/CudaGrid.h> +#include <cuda.h> + +#include <iostream> + +using namespace vf::lbm::constant; +using namespace vf::lbm::dir; + +__global__ void printFs( real* distributions, + bool isEvenTimestep, + unsigned long numberOfFluidNodes, + uint* neighborX, + uint* neighborY, + uint* neighborZ, + uint* typeOfGridNode, + real* coordX, + real* coordY, + real* coordZ, + real minX, + real maxX, + real minY, + real maxY, + real minZ, + real maxZ) + { + const unsigned k_000 = vf::gpu::getNodeIndex(); + + if (k_000 >= numberOfFluidNodes || typeOfGridNode[k_000]!=GEO_FLUID ) + return; + + real coordNodeX = coordX[k_000]; + real coordNodeY = coordY[k_000]; + real coordNodeZ = coordZ[k_000]; + + if( coordNodeX>=minX && coordNodeX<=maxX && + coordNodeY>=minY && coordNodeY<=maxY && + coordNodeZ>=minZ && coordNodeZ<=maxZ ) + { + Distributions27 dist = vf::gpu::getDistributionReferences27(distributions, numberOfFluidNodes, isEvenTimestep); + //////////////////////////////////////////////////////////////////////////////// + //! - Set neighbor indices (necessary for indirect addressing) + uint k_M00 = neighborX[k_000]; + uint k_0M0 = neighborY[k_000]; + uint k_00M = neighborZ[k_000]; + uint k_MM0 = neighborY[k_M00]; + uint k_M0M = neighborZ[k_M00]; + uint k_0MM = neighborZ[k_0M0]; + uint k_MMM = neighborZ[k_MM0]; + //////////////////////////////////////////////////////////////////////////////////// + //! - Set local distributions + //! + real f_000 = (dist.f[DIR_000])[k_000]; + real f_P00 = (dist.f[DIR_P00])[k_000]; + real f_M00 = (dist.f[DIR_M00])[k_M00]; + real f_0P0 = (dist.f[DIR_0P0])[k_000]; + real f_0M0 = (dist.f[DIR_0M0])[k_0M0]; + real f_00P = (dist.f[DIR_00P])[k_000]; + real f_00M = (dist.f[DIR_00M])[k_00M]; + real f_PP0 = (dist.f[DIR_PP0])[k_000]; + real f_MM0 = (dist.f[DIR_MM0])[k_MM0]; + real f_PM0 = (dist.f[DIR_PM0])[k_0M0]; + real f_MP0 = (dist.f[DIR_MP0])[k_M00]; + real f_P0P = (dist.f[DIR_P0P])[k_000]; + real f_M0M = (dist.f[DIR_M0M])[k_M0M]; + real f_P0M = (dist.f[DIR_P0M])[k_00M]; + real f_M0P = (dist.f[DIR_M0P])[k_M00]; + real f_0PP = (dist.f[DIR_0PP])[k_000]; + real f_0MM = (dist.f[DIR_0MM])[k_0MM]; + real f_0PM = (dist.f[DIR_0PM])[k_00M]; + real f_0MP = (dist.f[DIR_0MP])[k_0M0]; + real f_PPP = (dist.f[DIR_PPP])[k_000]; + real f_MPP = (dist.f[DIR_MPP])[k_M00]; + real f_PMP = (dist.f[DIR_PMP])[k_0M0]; + real f_MMP = (dist.f[DIR_MMP])[k_MM0]; + real f_PPM = (dist.f[DIR_PPM])[k_00M]; + real f_MPM = (dist.f[DIR_MPM])[k_M0M]; + real f_PMM = (dist.f[DIR_PMM])[k_0MM]; + real f_MMM = (dist.f[DIR_MMM])[k_MMM]; + + real drho = ((((f_PPP + f_MMM) + (f_MPM + f_PMP)) + ((f_MPP + f_PMM) + (f_MMP + f_PPM))) + + (((f_0MP + f_0PM) + (f_0MM + f_0PP)) + ((f_M0P + f_P0M) + (f_M0M + f_P0P)) + + ((f_MP0 + f_PM0) + (f_MM0 + f_PP0))) + + ((f_M00 + f_P00) + (f_0M0 + f_0P0) + (f_00M + f_00P))) + + f_000; + + real oneOverRho = c1o1 / (c1o1 + drho); + + real vvx = ((((f_PPP - f_MMM) + (f_PMP - f_MPM)) + ((f_PMM - f_MPP) + (f_PPM - f_MMP))) + + (((f_P0M - f_M0P) + (f_P0P - f_M0M)) + ((f_PM0 - f_MP0) + (f_PP0 - f_MM0))) + (f_P00 - f_M00)) * + oneOverRho; + real vvy = ((((f_PPP - f_MMM) + (f_MPM - f_PMP)) + ((f_MPP - f_PMM) + (f_PPM - f_MMP))) + + (((f_0PM - f_0MP) + (f_0PP - f_0MM)) + ((f_MP0 - f_PM0) + (f_PP0 - f_MM0))) + (f_0P0 - f_0M0)) * + oneOverRho; + real vvz = ((((f_PPP - f_MMM) + (f_PMP - f_MPM)) + ((f_MPP - f_PMM) + (f_MMP - f_PPM))) + + (((f_0MP - f_0PM) + (f_0PP - f_0MM)) + ((f_M0P - f_P0M) + (f_P0P - f_M0M))) + (f_00P - f_00M)) * + oneOverRho; + + printf("Node %u \t (%f\t%f\t%f)\n rho: %f\t velo: %f\t %f \t %f\n\n" , k_000, coordNodeX, coordNodeY, coordNodeZ, drho, vvx, vvy, vvz); + printf("Node %u \t (%f\t%f\t%f)\n f_M00\t%f\t f_000\t%f\t f_P00\t%f\n f_MP0\t%f\t f_0P0\t%f\t f_PP0\t%f\n f_MM0\t%f\t f_0M0\t%f\t f_PM0\t%f\n f_M0P\t%f\t f_00P\t%f\t f_P0P\t%f\n f_M0M\t%f\t f_00M\t%f\t f_P0M\t%f\n f_MPP\t%f\t f_0PP\t%f\t f_PPP\t%f\n f_MPM\t%f\t f_0PM\t%f\t f_PPM\t%f\n f_MMP\t%f\t f_0MP\t%f\t f_PMP\t%f\n f_MMM\t%f\t f_0MM\t%f\t f_PMM\t%f\n\n\n" , k_000, coordNodeX, coordNodeY, coordNodeZ, f_M00, f_000, f_P00,f_MP0, f_0P0, f_PP0, f_MM0, f_0M0, f_PM0, f_M0P, f_00P, f_P0P, f_M0M, f_00M, f_P0M, f_MPP, f_0PP, f_PPP, f_MPM, f_0PM, f_PPM, f_MMP, f_0MP, f_PMP, f_MMM, f_0MM, f_PMM); + + } + + } + + + + +void DistributionDebugInspector::inspect(std::shared_ptr<Parameter> para, uint level, uint t){ + + if(this->inspectionLevel!=level) + return; + + std::cout << tag << ": distributions on level " << level << " at t " << t << std::endl; + + vf::cuda::CudaGrid cudaGrid = vf::cuda::CudaGrid(para->getParD(level)->numberofthreads, para->getParD(level)->numberOfNodes); + + printFs <<< cudaGrid.grid, cudaGrid.threads >>>( para->getParD(level)->distributions.f[0], + para->getParD(level)->isEvenTimestep, + (unsigned long)para->getParD(level)->numberOfNodes, + para->getParD(level)->neighborX, + para->getParD(level)->neighborY, + para->getParD(level)->neighborZ, + para->getParD(level)->typeOfGridNode, + para->getParD(level)->coordinateX, + para->getParD(level)->coordinateY, + para->getParD(level)->coordinateZ, + minX, + maxX, + minY, + maxY, + minZ, + maxZ); + +} \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/Output/DistributionDebugInspector.h b/src/gpu/VirtualFluids_GPU/Output/DistributionDebugInspector.h new file mode 100644 index 0000000000000000000000000000000000000000..53e030c0d16116a4edef0135f9ab435c853fd66b --- /dev/null +++ b/src/gpu/VirtualFluids_GPU/Output/DistributionDebugInspector.h @@ -0,0 +1,76 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file DistributionDebugInspector.h +//! \author Henrik Asmuth +//! \date 13/012/2022 +//! \brief Basic debugging class to print out f's in a certain area of the domain +//! +//! Basic debugging class. Needs to be directly added in UpdateGrid (could potentially also be added as a proper Probe in the future) +//! How to use: Define a part of the domain via min/max x, y, and z. The DistributionDebugInspector will print out all f's in that area. +//! +//======================================================================================= + +#ifndef DISTRIBUTION_INSPECTOR_H +#define DISTRIBUTION_INSPECTOR_H + +#include "Parameter/Parameter.h" + + +class DistributionDebugInspector +{ +public: + DistributionDebugInspector(uint _inspectionLevel, real _minX, real _maxX, real _minY, real _maxY, real _minZ, real _maxZ, std::string _tag): + inspectionLevel(_inspectionLevel), + minX(_minX), + maxX(_maxX), + minY(_minY), + maxY(_maxY), + minZ(_minZ), + maxZ(_maxZ), + tag(_tag) + {}; + + ~DistributionDebugInspector(){} + + void inspect(std::shared_ptr<Parameter> para, uint level, uint t); + + +private: +uint inspectionLevel; +real minX; +real maxX; +real minY; +real maxY; +real minZ; +real maxZ; +std::string tag; + +}; + +#endif \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/Parameter/CudaStreamManager.cpp b/src/gpu/VirtualFluids_GPU/Parameter/CudaStreamManager.cpp index 3731836f336d91c1bc4cc5f1a8f5ea0a10bee0a6..3cc771e413134e90b0d09d8eeb6dfee791f8a1e2 100644 --- a/src/gpu/VirtualFluids_GPU/Parameter/CudaStreamManager.cpp +++ b/src/gpu/VirtualFluids_GPU/Parameter/CudaStreamManager.cpp @@ -31,25 +31,39 @@ #include <helper_cuda.h> #include <iostream> -void CudaStreamManager::launchStreams(uint numberOfStreams) +void CudaStreamManager::registerStream(CudaStreamIndex streamIndex) +{ + if(streamIndex != CudaStreamIndex::Legacy) + cudaStreams.emplace(streamIndex, nullptr); +} +void CudaStreamManager::launchStreams() { - cudaStreams.resize(numberOfStreams); - for (cudaStream_t &stream : cudaStreams) - cudaStreamCreate(&stream); + for (auto &stream : cudaStreams) + cudaStreamCreate(&stream.second); } void CudaStreamManager::terminateStreams() { - for (cudaStream_t &stream : cudaStreams) - cudaStreamDestroy(stream); + for (auto &stream : cudaStreams) + cudaStreamDestroy(stream.second); } -cudaStream_t &CudaStreamManager::getStream(uint streamIndex) -{ return cudaStreams[streamIndex]; } - -int CudaStreamManager::getBorderStreamIndex() { return borderStreamIndex; } +cudaStream_t &CudaStreamManager::getStream(CudaStreamIndex streamIndex, uint multiStreamIndex) +{ + if(streamIndex == CudaStreamIndex::Legacy) return legacyStream; + if(streamIsRegistered(streamIndex)) + { + auto it = cudaStreams.find(streamIndex); + for(uint idx=0; idx<multiStreamIndex; idx++) it++; + return it->second; + } + return legacyStream; +} -int CudaStreamManager::getBulkStreamIndex() { return bulkStreamIndex; } +bool CudaStreamManager::streamIsRegistered(CudaStreamIndex streamIndex) +{ + return cudaStreams.count(streamIndex) > 0; +} void CudaStreamManager::createCudaEvents() { @@ -61,12 +75,12 @@ void CudaStreamManager::destroyCudaEvents() checkCudaErrors(cudaEventDestroy(startBulkKernel)); } -void CudaStreamManager::triggerStartBulkKernel(int streamIndex) +void CudaStreamManager::triggerStartBulkKernel(CudaStreamIndex streamIndex, uint multiStreamIndex) { - checkCudaErrors(cudaEventRecord(startBulkKernel, cudaStreams[streamIndex])); + checkCudaErrors(cudaEventRecord(startBulkKernel, getStream(streamIndex, multiStreamIndex))); } -void CudaStreamManager::waitOnStartBulkKernelEvent(int streamIndex) +void CudaStreamManager::waitOnStartBulkKernelEvent(CudaStreamIndex streamIndex, uint multiStreamIndex) { - checkCudaErrors(cudaStreamWaitEvent(cudaStreams[streamIndex], startBulkKernel)); + checkCudaErrors(cudaStreamWaitEvent(getStream(streamIndex, multiStreamIndex), startBulkKernel)); } diff --git a/src/gpu/VirtualFluids_GPU/Parameter/CudaStreamManager.h b/src/gpu/VirtualFluids_GPU/Parameter/CudaStreamManager.h index c2d515ab5fe9c24388632a7ca9e1e4c78b7f1467..5c59bcd3a5e6178d6e70a63f803caf8e29f32604 100644 --- a/src/gpu/VirtualFluids_GPU/Parameter/CudaStreamManager.h +++ b/src/gpu/VirtualFluids_GPU/Parameter/CudaStreamManager.h @@ -30,32 +30,40 @@ #ifndef STREAM_MANAGER_H #define STREAM_MANAGER_H -#include <vector> -#include "Core/DataTypes.h" - +#include <map> +#include <cuda.h> #include <cuda_runtime.h> +#include "Core/DataTypes.h" +enum class CudaStreamIndex + { + Legacy, + Bulk, + SubDomainBorder, + Precursor, + ActuatorFarm + }; class CudaStreamManager -{ +{ private: - std::vector<cudaStream_t> cudaStreams; + std::multimap<CudaStreamIndex, cudaStream_t> cudaStreams; cudaEvent_t startBulkKernel = NULL; - const int borderStreamIndex = 1; - const int bulkStreamIndex = 0; + cudaStream_t legacyStream = CU_STREAM_LEGACY; + public: - void launchStreams(uint numberOfStreams); + void registerStream(CudaStreamIndex streamIndex); + void launchStreams(); void terminateStreams(); - cudaStream_t &getStream(uint streamIndex); - - int getBorderStreamIndex(); - int getBulkStreamIndex(); + cudaStream_t &getStream(CudaStreamIndex streamIndex, uint multiStreamIndex=0); + bool streamIsRegistered(CudaStreamIndex streamIndex); // Events void createCudaEvents(); void destroyCudaEvents(); - void triggerStartBulkKernel(int streamIndex); - void waitOnStartBulkKernelEvent(int strteamIndex); + + void triggerStartBulkKernel(CudaStreamIndex streamIndex, uint multiStreamIndex=0); + void waitOnStartBulkKernelEvent(CudaStreamIndex streamIndex, uint multiStreamIndex=0); }; #endif diff --git a/src/gpu/VirtualFluids_GPU/Parameter/Parameter.cpp b/src/gpu/VirtualFluids_GPU/Parameter/Parameter.cpp index 7687ec926270f23e57608ca5f3084bd26d4de20e..d1568932d9802d1060e37d26ed37fa48de1abb05 100644 --- a/src/gpu/VirtualFluids_GPU/Parameter/Parameter.cpp +++ b/src/gpu/VirtualFluids_GPU/Parameter/Parameter.cpp @@ -65,6 +65,8 @@ Parameter::Parameter(int numberOfProcesses, int myId, std::optional<const vf::ba initGridPaths(); initGridBasePoints(); initDefaultLBMkernelAllLevels(); + + this->cudaStreamManager = std::make_unique<CudaStreamManager>(); } Parameter::~Parameter() = default; @@ -829,7 +831,7 @@ real Parameter::getLengthRatio() } real Parameter::getForceRatio() { - return this->getDensityRatio() * this->getVelocityRatio()/this->getTimeRatio(); + return (this->getDensityRatio()+1.0) * this->getVelocityRatio()/this->getTimeRatio(); } real Parameter::getScaledViscosityRatio(int level) { @@ -859,6 +861,10 @@ real Parameter::getScaledForceRatio(int level) { return this->getForceRatio()*(level+1); } +real Parameter::getScaledStressRatio(int level) +{ + return this->getVelocityRatio()*this->getVelocityRatio(); +} void Parameter::setRealX(real RealX) { ic.RealX = RealX; @@ -883,6 +889,10 @@ void Parameter::setPressOutZ(unsigned int PressOutZ) { ic.PressOutZ = PressOutZ; } +void Parameter::setOutflowPressureCorrectionFactor(real pressBCrhoCorrectionFactor) +{ + ic.outflowPressureCorrectionFactor = pressBCrhoCorrectionFactor; +} void Parameter::setMaxDev(int maxdev) { ic.maxdev = maxdev; @@ -1607,7 +1617,7 @@ void Parameter::setOutflowBoundaryNormalZ(std::string outflowNormalZ) void Parameter::setMainKernel(std::string kernel) { this->mainKernel = kernel; - if (kernel.find("Stream") != std::string::npos || kernel.find("Redesigned") != std::string::npos) + if ( kernel.find("CumulantK17") != std::string::npos ) this->kernelNeedsFluidNodeIndicesToRun = true; } void Parameter::setMultiKernelOn(bool isOn) @@ -1916,6 +1926,10 @@ unsigned int Parameter::getPressOutZ() { return ic.PressOutZ; } +real Parameter::getOutflowPressureCorrectionFactor() +{ + return ic.outflowPressureCorrectionFactor; +} int Parameter::getMaxDev() { return ic.maxdev; @@ -2657,8 +2671,7 @@ void Parameter::setUseStreams(bool useStreams) if (useStreams) { if (this->getNumprocs() != 1) { this->useStreams = useStreams; - this->cudaStreamManager = std::make_unique<CudaStreamManager>(); - return; + return; } else { std::cout << "Can't use streams with only one process!" << std::endl; } diff --git a/src/gpu/VirtualFluids_GPU/Parameter/Parameter.h b/src/gpu/VirtualFluids_GPU/Parameter/Parameter.h index cbb8bfd68702bc2285947eb76e6d0adc54a5b6c1..86b7bc2a058d69ba878d4445953a4dc56e524027 100644 --- a/src/gpu/VirtualFluids_GPU/Parameter/Parameter.h +++ b/src/gpu/VirtualFluids_GPU/Parameter/Parameter.h @@ -54,6 +54,8 @@ class ConfigurationFile; } class CudaStreamManager; +class TransientBCInputFileReader; + //! \struct LBMSimulationParameter //! \brief struct holds and manages the LB-parameter of the simulation //! \brief For this purpose it holds structures and pointer for host and device data, respectively. @@ -218,16 +220,16 @@ struct LBMSimulationParameter { OffsetFC offFCBulk; unsigned int mem_size_kCF_off; unsigned int mem_size_kFC_off; - - // BC's//////////////////// + //! \brief stores the boundary condition data QforBoundaryConditions noSlipBC, velocityBC, outflowBC, slipBC, stressBC, pressureBC; //! \brief number of lattice nodes for the boundary conditions - unsigned int numberOfNoSlipBCnodesRead, numberOfVeloBCnodesRead, numberOfOutflowBCnodesRead, numberOfSlipBCnodesRead, numberOfStressBCnodesRead, numberOfPressureBCnodesRead; + unsigned int numberOfNoSlipBCnodesRead, numberOfVeloBCnodesRead, numberOfOutflowBCnodesRead, numberOfSlipBCnodesRead, numberOfStressBCnodesRead, numberOfPressureBCnodesRead, numberOfPrecursorBCnodesRead; QforBoundaryConditions QpressX0, QpressX1, QpressY0, QpressY1, QpressZ0, QpressZ1; // DEPRECATED QforBoundaryConditions propellerBC; QforBoundaryConditions geometryBC; + QforPrecursorBoundaryConditions precursorBC; QforBoundaryConditions geometryBCnormalX, geometryBCnormalY, geometryBCnormalZ; QforBoundaryConditions inflowBCnormalX, inflowBCnormalY, inflowBCnormalZ; QforBoundaryConditions outflowBCnormalX, outflowBCnormalY, outflowBCnormalZ; @@ -235,6 +237,8 @@ struct LBMSimulationParameter { unsigned int kInletQread, kOutletQread; // DEPRECATED WallModelParameters wallModel; + std::vector<SPtr<TransientBCInputFileReader>> transientBCInputFileReader; + real outflowPressureCorrectionFactor; // testRoundoffError Distributions27 kDistTestRE; @@ -367,10 +371,19 @@ struct LBMSimulationParameter { std::vector<EdgeNodePositions> edgeNodesYtoZ; /////////////////////////////////////////////////////// - uint *fluidNodeIndices; - uint numberOfFluidNodes; - uint *fluidNodeIndicesBorder; - uint numberOfFluidNodesBorder; + std::map<CollisionTemplate, uint*> taggedFluidNodeIndices = {{CollisionTemplate::Default, nullptr}, + {CollisionTemplate::SubDomainBorder,nullptr}, + {CollisionTemplate::WriteMacroVars, nullptr}, + {CollisionTemplate::ApplyBodyForce, nullptr}, + {CollisionTemplate::AllFeatures, nullptr}}; + std::map<CollisionTemplate, uint > numberOfTaggedFluidNodes = {{CollisionTemplate::Default, 0}, + {CollisionTemplate::SubDomainBorder,0}, + {CollisionTemplate::WriteMacroVars, 0}, + {CollisionTemplate::ApplyBodyForce, 0}, + {CollisionTemplate::AllFeatures, 0}}; + + std::vector<CollisionTemplate> allocatedBulkFluidNodeTags = {}; + }; //! \brief Class for LBM-parameter management @@ -471,6 +484,7 @@ public: void setpressBcPos(std::string pressBcPos); void setpressBcQs(std::string pressBcQs); void setpressBcValue(std::string pressBcValue); + void setOutflowPressureCorrectionFactor(real correctionFactor); void setpressBcValues(std::string pressBcValues); void setvelBcQs(std::string velBcQs); void setvelBcValues(std::string velBcValues); @@ -527,7 +541,6 @@ public: void setUseWale(bool useWale); void setTurbulenceModel(TurbulenceModel turbulenceModel); void setUseTurbulentViscosity(bool useTurbulentViscosity); - void setUseAMD(bool useAMD); void setSGSConstant(real SGSConstant); void setHasWallModelMonitor(bool hasWallModelMonitor); void setUseInitNeq(bool useInitNeq); @@ -765,6 +778,8 @@ public: real getScaledDensityRatio(int level); //! \returns the pressure ratio in SI/LB units scaled to the respective level real getScaledPressureRatio(int level); + //! \returns the stress ratio in SI/LB units scaled to the respective level + real getScaledStressRatio(int level); //! \returns the time ratio in SI/LB units scaled to the respective level real getScaledTimeRatio(int level); //! \returns the length ratio in SI/LB units scaled to the respective level @@ -853,6 +868,7 @@ public: std::string getOutflowBoundaryNormalX(); std::string getOutflowBoundaryNormalY(); std::string getOutflowBoundaryNormalZ(); + real getOutflowPressureCorrectionFactor(); // CUDA random number curandState *getRandomState(); // Kernel diff --git a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/ActuatorFarm.cu b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/ActuatorFarm.cu new file mode 100644 index 0000000000000000000000000000000000000000..626e3bc0b745a8f8b029afb38028c81bd8d659e7 --- /dev/null +++ b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/ActuatorFarm.cu @@ -0,0 +1,594 @@ +#include "ActuatorFarm.h" + +#include <cuda.h> +#include <cuda_runtime.h> +#include <helper_cuda.h> + +#include <cuda/CudaGrid.h> +#include "VirtualFluids_GPU/GPU/GeometryUtils.h" +#include "VirtualFluids_GPU/Kernel/Utilities/DistributionHelper.cuh" + +#include "Parameter/Parameter.h" +#include "Parameter/CudaStreamManager.h" +#include "DataStructureInitializer/GridProvider.h" +#include "GPU/CudaMemoryManager.h" +#include <lbm/constants/NumericConstants.h> +#include <logger/Logger.h> + +using namespace vf::lbm::constant; + + +__host__ __device__ __inline__ uint calcNode(uint bladeNode, uint numberOfBladeNodes, uint blade, uint numberOfBlades, uint turbine, uint numberOfTurbines) +{ + + return bladeNode+numberOfBladeNodes*(blade+numberOfBlades*turbine); +} + +__host__ __device__ __inline__ void calcTurbineBladeAndBladeNode(uint node, uint& bladeNode, uint numberOfBladeNodes, uint& blade, uint numberOfBlades, uint& turbine, uint numberOfTurbines) +{ + turbine = node/(numberOfBladeNodes*numberOfBlades); + uint x_off = turbine*numberOfBladeNodes*numberOfBlades; + blade = (node - x_off)/numberOfBlades; + uint y_off = numberOfBladeNodes*blade+x_off; + bladeNode = (node - y_off)/numberOfBladeNodes; +} + +__host__ __device__ __forceinline__ real distSqrd(real distX, real distY, real distZ) +{ + return distX*distX+distY*distY+distZ*distZ; +} + +void swapArrays(real* &arr1, real* &arr2) +{ + real* tmp = arr1; + arr1 = arr2; + arr2 = tmp; +} + +__host__ __device__ __inline__ void rotateFromBladeToGlobal( + real& bladeCoordX_BF, real& bladeCoordY_BF, real& bladeCoordZ_BF, + real& bladeCoordX_GF, real& bladeCoordY_GF, real& bladeCoordZ_GF, + real& azimuth, real& yaw) +{ + real tmpX, tmpY, tmpZ; + + rotateAboutX3D(azimuth, bladeCoordX_BF, bladeCoordY_BF, bladeCoordZ_BF, tmpX, tmpY, tmpZ); + rotateAboutZ3D(yaw, tmpX, tmpY, tmpZ, bladeCoordX_GF, bladeCoordY_GF, bladeCoordZ_GF); + +} + +__host__ __device__ __inline__ void rotateFromGlobalToBlade( + real& bladeCoordX_BF, real& bladeCoordY_BF, real& bladeCoordZ_BF, + real& bladeCoordX_GF, real& bladeCoordY_GF, real& bladeCoordZ_GF, + real& azimuth, real& yaw) +{ + real tmpX, tmpY, tmpZ; + + invRotateAboutZ3D(yaw, bladeCoordX_GF, bladeCoordY_GF, bladeCoordZ_GF, tmpX, tmpY, tmpZ); + invRotateAboutX3D(azimuth, tmpX, tmpY, tmpZ, bladeCoordX_BF, bladeCoordY_BF, bladeCoordZ_BF); +} + +__global__ void interpolateVelocities(real* gridCoordsX, real* gridCoordsY, real* gridCoordsZ, + uint* neighborsX, uint* neighborsY, uint* neighborsZ, uint* neighborsWSB, + real* vx, real* vy, real* vz, + real* bladeCoordsX, real* bladeCoordsY, real* bladeCoordsZ, + real* bladeVelocitiesX, real* bladeVelocitiesY, real* bladeVelocitiesZ, + uint numberOfTurbines, uint numberOfBlades, uint numberOfBladeNodes, + real* azimuths, real* yaws, real* omegas, + real* turbPosX, real* turbPosY, real* turbPosZ, + uint* bladeIndices, real velocityRatio, real invDeltaX) +{ + + const uint node = vf::gpu::getNodeIndex(); + + if(node>=numberOfBladeNodes*numberOfBlades*numberOfTurbines) return; + + uint turbine, bladeNode, blade; + + calcTurbineBladeAndBladeNode(node, bladeNode, numberOfBladeNodes, blade, numberOfBlades, turbine, numberOfTurbines); + + real bladeCoordX_BF = bladeCoordsX[node]; + real bladeCoordY_BF = bladeCoordsY[node]; + real bladeCoordZ_BF = bladeCoordsZ[node]; + + real bladeCoordX_GF, bladeCoordY_GF, bladeCoordZ_GF; + + real localAzimuth = azimuths[turbine]+blade*c2Pi/numberOfBlades; + real yaw = yaws[turbine]; + + + rotateFromBladeToGlobal(bladeCoordX_BF, bladeCoordY_BF, bladeCoordZ_BF, + bladeCoordX_GF, bladeCoordY_GF, bladeCoordZ_GF, + localAzimuth, yaw); + + bladeCoordX_GF += turbPosX[turbine]; + bladeCoordY_GF += turbPosY[turbine]; + bladeCoordZ_GF += turbPosZ[turbine]; + + uint k, ke, kn, kt; + uint kne, kte, ktn, ktne; + + k = findNearestCellBSW(bladeIndices[node], + gridCoordsX, gridCoordsY, gridCoordsZ, + bladeCoordX_GF, bladeCoordY_GF, bladeCoordZ_GF, + neighborsX, neighborsY, neighborsZ, neighborsWSB); + + bladeIndices[node] = k; + + getNeighborIndicesOfBSW(k, ke, kn, kt, kne, kte, ktn, ktne, neighborsX, neighborsY, neighborsZ); + + real dW, dE, dN, dS, dT, dB; + + real distX = invDeltaX*(bladeCoordX_GF-gridCoordsX[k]); + real distY = invDeltaX*(bladeCoordY_GF-gridCoordsY[k]); + real distZ = invDeltaX*(bladeCoordZ_GF-gridCoordsZ[k]); + + getInterpolationWeights(dW, dE, dN, dS, dT, dB, distX, distY, distZ); + + real bladeVelX_GF = trilinearInterpolation(dW, dE, dN, dS, dT, dB, k, ke, kn, kt, kne, kte, ktn, ktne, vx)*velocityRatio; + real bladeVelY_GF = trilinearInterpolation(dW, dE, dN, dS, dT, dB, k, ke, kn, kt, kne, kte, ktn, ktne, vy)*velocityRatio; + real bladeVelZ_GF = trilinearInterpolation(dW, dE, dN, dS, dT, dB, k, ke, kn, kt, kne, kte, ktn, ktne, vz)*velocityRatio; + + real bladeVelX_BF, bladeVelY_BF, bladeVelZ_BF; + + rotateFromGlobalToBlade(bladeVelX_BF, bladeVelY_BF, bladeVelZ_BF, + bladeVelX_GF, bladeVelY_GF, bladeVelZ_GF, + localAzimuth, yaw); + + bladeVelocitiesX[node] = bladeVelX_BF; + bladeVelocitiesY[node] = bladeVelY_BF+omegas[turbine]*bladeCoordZ_BF; + bladeVelocitiesZ[node] = bladeVelZ_BF; +} + + +__global__ void applyBodyForces(real* gridCoordsX, real* gridCoordsY, real* gridCoordsZ, + real* gridForcesX, real* gridForcesY, real* gridForcesZ, + real* bladeCoordsX, real* bladeCoordsY, real* bladeCoordsZ, + real* bladeForcesX, real* bladeForcesY, real* bladeForcesZ, + const uint numberOfTurbines, const uint numberOfBlades, const uint numberOfBladeNodes, + real* azimuths, real* yaws, real* diameters, + real* turbPosX, real* turbPosY, real* turbPosZ, + uint* gridIndices, uint nIndices, + const real invEpsilonSqrd, const real factorGaussian) +{ + + const uint index = vf::gpu::getNodeIndex(); + + if(index>=nIndices) return; + + + uint gridIndex = gridIndices[index]; + + real gridCoordX_GF = gridCoordsX[gridIndex]; + real gridCoordY_GF = gridCoordsY[gridIndex]; + real gridCoordZ_GF = gridCoordsZ[gridIndex]; + + real gridForceX_RF = c0o1; + real gridForceY_RF = c0o1; + real gridForceZ_RF = c0o1; + + real dAzimuth = c2Pi/numberOfBlades; + + for(uint turbine = 0; turbine<numberOfTurbines; turbine++) + { + real radius = c1o2*diameters[turbine]; + real gridCoordX_RF = gridCoordX_GF - turbPosX[turbine]; + real gridCoordY_RF = gridCoordY_GF - turbPosY[turbine]; + real gridCoordZ_RF = gridCoordZ_GF - turbPosZ[turbine]; + + if(distSqrd(gridCoordX_RF, gridCoordY_RF, gridCoordZ_RF)*invEpsilonSqrd > radius*radius*invEpsilonSqrd+c7o1) + continue; + + real azimuth = azimuths[turbine]; + real yaw = yaws[turbine]; + + for( uint blade=0; blade<numberOfBlades; blade++) + { + real localAzimuth = azimuth+blade*dAzimuth; + + + real gridCoordX_BF, gridCoordY_BF, gridCoordZ_BF; + + rotateFromGlobalToBlade(gridCoordX_BF, gridCoordY_BF, gridCoordZ_BF, + gridCoordX_RF, gridCoordY_RF, gridCoordZ_RF, + localAzimuth, yaw); + + uint node; + uint nextNode = calcNode(0, numberOfBladeNodes, blade, numberOfBlades, turbine, numberOfTurbines); + + real last_z = c0o1; + real current_z = c0o1; + real next_z = bladeCoordsZ[nextNode]; + + real x, y, dz, eta, forceX_RF, forceY_RF, forceZ_RF; + + for( uint bladeNode=0; bladeNode<numberOfBladeNodes-1; bladeNode++) + { + node = nextNode; + nextNode = calcNode(bladeNode+1, numberOfBladeNodes, blade, numberOfBlades, turbine, numberOfTurbines); + + x = bladeCoordsX[node]; + y = bladeCoordsY[node]; + last_z = current_z; + current_z = next_z; + next_z = bladeCoordsZ[nextNode]; + + dz = c1o2*(next_z-last_z); + + eta = dz*factorGaussian*exp(-distSqrd(x-gridCoordX_BF, y-gridCoordY_BF, current_z-gridCoordZ_BF)*invEpsilonSqrd); + rotateFromBladeToGlobal(bladeForcesX[node], bladeForcesY[node], bladeForcesZ[node], + forceX_RF, forceY_RF, forceZ_RF, + localAzimuth, yaw); + + gridForceX_RF += forceX_RF*eta; + gridForceY_RF += forceY_RF*eta; + gridForceZ_RF += forceZ_RF*eta; + } + + //Handle last node separately + + node = nextNode; + + x = bladeCoordsX[node]; + y = bladeCoordsY[node]; + last_z = current_z; + current_z = next_z; + + dz = c1o2*(radius-last_z); + + eta = dz*factorGaussian*exp(-distSqrd(x-gridCoordX_BF, y-gridCoordY_BF, current_z-gridCoordZ_BF)*invEpsilonSqrd); + + rotateFromBladeToGlobal(bladeForcesX[node], bladeForcesY[node], bladeForcesZ[node], + forceX_RF, forceY_RF, forceZ_RF, + localAzimuth, yaw); + + gridForceX_RF += forceX_RF*eta; + gridForceY_RF += forceY_RF*eta; + gridForceZ_RF += forceZ_RF*eta; + } + } + + gridForcesX[gridIndex] += gridForceX_RF; + gridForcesY[gridIndex] += gridForceY_RF; + gridForcesZ[gridIndex] += gridForceZ_RF; +} + +void ActuatorFarm::addTurbine(real posX, real posY, real posZ, real diameter, real omega, real azimuth, real yaw, std::vector<real> bladeRadii) +{ + preInitPosX.push_back(posX); + preInitPosY.push_back(posY); + preInitPosZ.push_back(posZ); + preInitOmegas.push_back(omega); + preInitAzimuths.push_back(azimuth); + preInitYaws.push_back(yaw); + preInitDiameters.push_back(diameter); + preInitBladeRadii.push_back(bladeRadii); +} + +void ActuatorFarm::init(Parameter* para, GridProvider* gridProvider, CudaMemoryManager* cudaMemoryManager) +{ + if(!para->getIsBodyForce()) throw std::runtime_error("try to allocate ActuatorFarm but BodyForce is not set in Parameter."); + this->forceRatio = para->getForceRatio(); + this->initTurbineGeometries(cudaMemoryManager); + this->initBladeCoords(cudaMemoryManager); + this->initBladeIndices(para, cudaMemoryManager); + this->initBladeVelocities(cudaMemoryManager); + this->initBladeForces(cudaMemoryManager); + this->initBoundingSpheres(para, cudaMemoryManager); + this->streamIndex = 0; +} + +void ActuatorFarm::interact(Parameter* para, CudaMemoryManager* cudaMemoryManager, int level, unsigned int t) +{ + if (level != this->level) return; + + cudaStream_t stream = para->getStreamManager()->getStream(CudaStreamIndex::ActuatorFarm, this->streamIndex); + + if(useHostArrays) cudaMemoryManager->cudaCopyBladeCoordsHtoD(this); + + vf::cuda::CudaGrid bladeGrid = vf::cuda::CudaGrid(para->getParH(level)->numberofthreads, this->numberOfNodes); + + interpolateVelocities<<< bladeGrid.grid, bladeGrid.threads, 0, stream >>>( + para->getParD(this->level)->coordinateX, para->getParD(this->level)->coordinateY, para->getParD(this->level)->coordinateZ, + para->getParD(this->level)->neighborX, para->getParD(this->level)->neighborY, para->getParD(this->level)->neighborZ, para->getParD(this->level)->neighborInverse, + para->getParD(this->level)->velocityX, para->getParD(this->level)->velocityY, para->getParD(this->level)->velocityZ, + this->bladeCoordsXDCurrentTimestep, this->bladeCoordsYDCurrentTimestep, this->bladeCoordsZDCurrentTimestep, + this->bladeVelocitiesXDCurrentTimestep, this->bladeVelocitiesYDCurrentTimestep, this->bladeVelocitiesZDCurrentTimestep, + this->numberOfTurbines, this->numberOfBlades, this->numberOfBladeNodes, + this->azimuthsD, this->yawsD, this->omegasD, + this->turbinePosXD, this->turbinePosYD, this->turbinePosZD, + this->bladeIndicesD, para->getVelocityRatio(), this->invDeltaX); + + cudaStreamSynchronize(stream); + if(useHostArrays) cudaMemoryManager->cudaCopyBladeVelocitiesDtoH(this); + this->calcBladeForces(); + this->swapDeviceArrays(); + + if(useHostArrays) cudaMemoryManager->cudaCopyBladeForcesHtoD(this); + + vf::cuda::CudaGrid sphereGrid = vf::cuda::CudaGrid(para->getParH(level)->numberofthreads, this->numberOfIndices); + + applyBodyForces<<<sphereGrid.grid, sphereGrid.threads, 0, stream>>>( + para->getParD(this->level)->coordinateX, para->getParD(this->level)->coordinateY, para->getParD(this->level)->coordinateZ, + para->getParD(this->level)->forceX_SP, para->getParD(this->level)->forceY_SP, para->getParD(this->level)->forceZ_SP, + this->bladeCoordsXDCurrentTimestep, this->bladeCoordsYDCurrentTimestep, this->bladeCoordsZDCurrentTimestep, + this->bladeForcesXDCurrentTimestep, this->bladeForcesYDCurrentTimestep, this->bladeForcesZDCurrentTimestep, + this->numberOfTurbines, this->numberOfBlades, this->numberOfBladeNodes, + this->azimuthsD, this->yawsD, this->diametersD, + this->turbinePosXD, this->turbinePosYD, this->turbinePosZD, + this->boundingSphereIndicesD, this->numberOfIndices, + this->invEpsilonSqrd, this->factorGaussian); + cudaMemoryManager->cudaCopyBladeOrientationsHtoD(this); + cudaStreamSynchronize(stream); +} + + +void ActuatorFarm::free(Parameter* para, CudaMemoryManager* cudaMemoryManager) +{ + cudaMemoryManager->cudaFreeBladeGeometries(this); + cudaMemoryManager->cudaFreeBladeOrientations(this); + cudaMemoryManager->cudaFreeBladeCoords(this); + cudaMemoryManager->cudaFreeBladeVelocities(this); + cudaMemoryManager->cudaFreeBladeForces(this); + cudaMemoryManager->cudaFreeBladeIndices(this); + cudaMemoryManager->cudaFreeSphereIndices(this); +} + + +void ActuatorFarm::calcForcesEllipticWing() +{ + real u_rel, v_rel, u_rel_sq; + real phi; + real Cl = c1o1; + real Cd = c0o1; + real c0 = 20*c1o10; + real c, Cn, Ct; + for(uint turbine=0; turbine<this->numberOfTurbines; turbine++) + { + real diameter = this->diametersH[turbine]; + for( uint blade=0; blade<this->numberOfBlades; blade++) + { + for( uint bladeNode=0; bladeNode<this->numberOfBladeNodes; bladeNode++) + { + uint node = calcNode(bladeNode, this->numberOfBladeNodes, blade, this->numberOfBlades, turbine, this->numberOfTurbines); + + u_rel = this->bladeVelocitiesXH[node]; + v_rel = this->bladeVelocitiesYH[node]; + u_rel_sq = u_rel*u_rel+v_rel*v_rel; + phi = atan2(u_rel, v_rel); + + real tmp = c4o1*this->bladeRadiiH[bladeNode]/diameter-c1o1; + c = c0 * sqrt( c1o1- tmp*tmp ); + Cn = Cl*cos(phi)+Cd*sin(phi); + Ct = Cl*sin(phi)-Cd*cos(phi); + real fx = c1o2*u_rel_sq*c*this->density*Cn; + real fy = c1o2*u_rel_sq*c*this->density*Ct; + this->bladeForcesXH[node] = -fx; + this->bladeForcesYH[node] = -fy; + this->bladeForcesZH[node] = c0o1; + // printf("u %f v %f fx %f fy %f \n", u_rel, v_rel, fx, fy); + } + } + azimuthsH[turbine] = azimuthsH[turbine]+deltaT*omegasH[turbine]; + } +} + +void ActuatorFarm::calcBladeForces() +{ + this->calcForcesEllipticWing(); +} + +void ActuatorFarm::getTaggedFluidNodes(Parameter *para, GridProvider* gridProvider) +{ + std::vector<uint> indicesInSphere(this->boundingSphereIndicesH, this->boundingSphereIndicesH+this->numberOfIndices); + gridProvider->tagFluidNodeIndices(indicesInSphere, CollisionTemplate::AllFeatures, this->level); +} + + +void ActuatorFarm::initTurbineGeometries(CudaMemoryManager* cudaMemoryManager) +{ + this->numberOfTurbines = uint(this->preInitDiameters.size()); + this->numberOfNodes = numberOfTurbines*numberOfBladeNodes*numberOfBlades; + + cudaMemoryManager->cudaAllocBladeGeometries(this); + cudaMemoryManager->cudaAllocBladeOrientations(this); + + for(uint turbine=0; turbine<this->numberOfTurbines; turbine++) + { + for(uint node=0; node<this->numberOfBladeNodes; node++) + { + this->bladeRadiiH[calcNode(node, numberOfBladeNodes, 0, 1, turbine, numberOfTurbines)] = this->preInitBladeRadii[turbine][node]; + } + + } + std::copy(preInitPosX.begin(), preInitPosX.end(), turbinePosXH); + std::copy(preInitPosY.begin(), preInitPosY.end(), turbinePosYH); + std::copy(preInitPosZ.begin(), preInitPosZ.end(), turbinePosZH); + std::copy(preInitDiameters.begin(), preInitDiameters.end(), diametersH); + + cudaMemoryManager->cudaCopyBladeGeometriesHtoD(this); + std::copy(preInitAzimuths.begin(), preInitAzimuths.end(), this->azimuthsH); + std::copy(preInitOmegas.begin(), preInitOmegas.end(), this->omegasH); + std::copy(preInitYaws.begin(), preInitYaws.end(), this->yawsH); + + cudaMemoryManager->cudaCopyBladeOrientationsHtoD(this); + this->factorGaussian = pow(this->epsilon*sqrt(cPi),-c3o1)/this->forceRatio; +} + +void ActuatorFarm::initBladeCoords(CudaMemoryManager* cudaMemoryManager) +{ + cudaMemoryManager->cudaAllocBladeCoords(this); + + for(uint turbine=0; turbine<numberOfTurbines; turbine++) + { + for(uint blade=0; blade<this->numberOfBlades; blade++) + { + for(uint bladeNode=0; bladeNode<this->numberOfBladeNodes; bladeNode++) + { + uint node = calcNode(bladeNode, this->numberOfBladeNodes, blade, this->numberOfBlades, turbine, this->numberOfTurbines); + + this->bladeCoordsXH[node] = c0o1; + this->bladeCoordsYH[node] = c0o1; + this->bladeCoordsZH[node] = this->bladeRadiiH[calcNode(bladeNode, numberOfBladeNodes, 0, 1, turbine, numberOfTurbines)]; + } + } + } + cudaMemoryManager->cudaCopyBladeCoordsHtoD(this); + swapArrays(this->bladeCoordsXDCurrentTimestep, this->bladeCoordsXDPreviousTimestep); + swapArrays(this->bladeCoordsYDCurrentTimestep, this->bladeCoordsYDPreviousTimestep); + swapArrays(this->bladeCoordsZDCurrentTimestep, this->bladeCoordsZDPreviousTimestep); + cudaMemoryManager->cudaCopyBladeCoordsHtoD(this); +} + +void ActuatorFarm::initBladeVelocities(CudaMemoryManager* cudaMemoryManager) +{ + cudaMemoryManager->cudaAllocBladeVelocities(this); + + std::fill_n(this->bladeVelocitiesXH, this->numberOfNodes, c0o1); + std::fill_n(this->bladeVelocitiesYH, this->numberOfNodes, c0o1); + std::fill_n(this->bladeVelocitiesZH, this->numberOfNodes, c0o1); + + cudaMemoryManager->cudaCopyBladeVelocitiesHtoD(this); + swapArrays(this->bladeVelocitiesXDCurrentTimestep, this->bladeVelocitiesXDPreviousTimestep); + swapArrays(this->bladeVelocitiesYDCurrentTimestep, this->bladeVelocitiesYDPreviousTimestep); + swapArrays(this->bladeVelocitiesZDCurrentTimestep, this->bladeVelocitiesZDPreviousTimestep); + cudaMemoryManager->cudaCopyBladeVelocitiesHtoD(this); +} + +void ActuatorFarm::initBladeForces(CudaMemoryManager* cudaMemoryManager) +{ + cudaMemoryManager->cudaAllocBladeForces(this); + + std::fill_n(this->bladeForcesXH, this->numberOfNodes, c0o1); + std::fill_n(this->bladeForcesYH, this->numberOfNodes, c0o1); + std::fill_n(this->bladeForcesZH, this->numberOfNodes, c0o1); + + cudaMemoryManager->cudaCopyBladeForcesHtoD(this); + swapArrays(this->bladeForcesXDCurrentTimestep, this->bladeForcesXDPreviousTimestep); + swapArrays(this->bladeForcesYDCurrentTimestep, this->bladeForcesYDPreviousTimestep); + swapArrays(this->bladeForcesZDCurrentTimestep, this->bladeForcesZDPreviousTimestep); + cudaMemoryManager->cudaCopyBladeForcesHtoD(this); +} + +void ActuatorFarm::initBladeIndices(Parameter* para, CudaMemoryManager* cudaMemoryManager) +{ + cudaMemoryManager->cudaAllocBladeIndices(this); + + std::fill_n(this->bladeIndicesH, this->numberOfNodes, 1); + + cudaMemoryManager->cudaCopyBladeIndicesHtoD(this); +} + +void ActuatorFarm::initBoundingSpheres(Parameter* para, CudaMemoryManager* cudaMemoryManager) +{ + std::vector<int> nodesInSpheres; + + for(uint turbine=0; turbine<this->numberOfTurbines; turbine++) + { + real sphereRadius = c1o2*this->diametersH[turbine]+c4o1*this->epsilon; + + real posX = this->turbinePosXH[turbine]; + real posY = this->turbinePosYH[turbine]; + real posZ = this->turbinePosZH[turbine]; + + real sphereRadiusSqrd = sphereRadius*sphereRadius; + + uint minimumNumberOfNodesPerSphere = (uint)(c4o3*cPi*pow(sphereRadius-this->deltaX, c3o1)/pow(this->deltaX, c3o1)); + uint nodesInThisSphere = 0; + + for (uint j = 1; j <= para->getParH(this->level)->numberOfNodes; j++) + { + const real distX = para->getParH(this->level)->coordinateX[j]-posX; + const real distY = para->getParH(this->level)->coordinateY[j]-posY; + const real distZ = para->getParH(this->level)->coordinateZ[j]-posZ; + if(distSqrd(distX,distY,distZ) < sphereRadiusSqrd) + { + nodesInSpheres.push_back(j); + nodesInThisSphere++; + } + } + + if(nodesInThisSphere<minimumNumberOfNodesPerSphere) + { + VF_LOG_CRITICAL("Found only {} nodes in bounding sphere of turbine no. {}, expected at least {}!", nodesInThisSphere, turbine, minimumNumberOfNodesPerSphere); + throw std::runtime_error("ActuatorFarm::initBoundingSpheres: Turbine bounding sphere partially out of domain."); + } + } + + this->numberOfIndices = uint(nodesInSpheres.size()); + + cudaMemoryManager->cudaAllocSphereIndices(this); + std::copy(nodesInSpheres.begin(), nodesInSpheres.end(), this->boundingSphereIndicesH); + cudaMemoryManager->cudaCopySphereIndicesHtoD(this); +} + +void ActuatorFarm::setAllAzimuths(real* _azimuths) +{ + std::copy_n(_azimuths, this->numberOfTurbines, this->azimuthsH); +} + +void ActuatorFarm::setAllOmegas(real* _omegas) +{ + std::copy_n(_omegas, this->numberOfTurbines, this->omegasH); +} + +void ActuatorFarm::setAllYaws(real* _yaws) +{ + std::copy_n(_yaws, this->numberOfTurbines, this->yawsH); +} + +void ActuatorFarm::setAllBladeCoords(real* _bladeCoordsX, real* _bladeCoordsY, real* _bladeCoordsZ) +{ + std::copy_n(_bladeCoordsX, this->numberOfNodes, this->bladeCoordsXH); + std::copy_n(_bladeCoordsY, this->numberOfNodes, this->bladeCoordsYH); + std::copy_n(_bladeCoordsZ, this->numberOfNodes, this->bladeCoordsZH); +} + +void ActuatorFarm::setAllBladeVelocities(real* _bladeVelocitiesX, real* _bladeVelocitiesY, real* _bladeVelocitiesZ) +{ + std::copy_n(_bladeVelocitiesX, this->numberOfNodes, this->bladeVelocitiesXH); + std::copy_n(_bladeVelocitiesY, this->numberOfNodes, this->bladeVelocitiesYH); + std::copy_n(_bladeVelocitiesZ, this->numberOfNodes, this->bladeVelocitiesZH); +} + +void ActuatorFarm::setAllBladeForces(real* _bladeForcesX, real* _bladeForcesY, real* _bladeForcesZ) +{ + std::copy_n(_bladeForcesX, this->numberOfNodes, this->bladeForcesXH); + std::copy_n(_bladeForcesY, this->numberOfNodes, this->bladeForcesYH); + std::copy_n(_bladeForcesZ, this->numberOfNodes, this->bladeForcesZH); + +}void ActuatorFarm::setTurbineBladeCoords(uint turbine, real* _bladeCoordsX, real* _bladeCoordsY, real* _bladeCoordsZ) +{ + std::copy_n(_bladeCoordsX, numberOfBladeNodes*numberOfBlades, &this->bladeCoordsXH[turbine*numberOfBladeNodes*numberOfBlades]); + std::copy_n(_bladeCoordsY, numberOfBladeNodes*numberOfBlades, &this->bladeCoordsYH[turbine*numberOfBladeNodes*numberOfBlades]); + std::copy_n(_bladeCoordsZ, numberOfBladeNodes*numberOfBlades, &this->bladeCoordsZH[turbine*numberOfBladeNodes*numberOfBlades]); +} + +void ActuatorFarm::setTurbineBladeVelocities(uint turbine, real* _bladeVelocitiesX, real* _bladeVelocitiesY, real* _bladeVelocitiesZ) +{ + std::copy_n(_bladeVelocitiesX, numberOfBladeNodes*numberOfBlades, &this->bladeVelocitiesXH[turbine*numberOfBladeNodes*numberOfBlades]); + std::copy_n(_bladeVelocitiesY, numberOfBladeNodes*numberOfBlades, &this->bladeVelocitiesYH[turbine*numberOfBladeNodes*numberOfBlades]); + std::copy_n(_bladeVelocitiesZ, numberOfBladeNodes*numberOfBlades, &this->bladeVelocitiesZH[turbine*numberOfBladeNodes*numberOfBlades]); +} + +void ActuatorFarm::setTurbineBladeForces(uint turbine, real* _bladeForcesX, real* _bladeForcesY, real* _bladeForcesZ) +{ + std::copy_n(_bladeForcesX, numberOfBladeNodes*numberOfBlades, &this->bladeForcesXH[turbine*numberOfBladeNodes*numberOfBlades]); + std::copy_n(_bladeForcesY, numberOfBladeNodes*numberOfBlades, &this->bladeForcesYH[turbine*numberOfBladeNodes*numberOfBlades]); + std::copy_n(_bladeForcesZ, numberOfBladeNodes*numberOfBlades, &this->bladeForcesZH[turbine*numberOfBladeNodes*numberOfBlades]); +} + +void ActuatorFarm::swapDeviceArrays() +{ + swapArrays(this->bladeCoordsXDPreviousTimestep, this->bladeCoordsXDCurrentTimestep); + swapArrays(this->bladeCoordsYDPreviousTimestep, this->bladeCoordsYDCurrentTimestep); + swapArrays(this->bladeCoordsZDPreviousTimestep, this->bladeCoordsZDCurrentTimestep); + + swapArrays(this->bladeVelocitiesXDPreviousTimestep, this->bladeVelocitiesXDCurrentTimestep); + swapArrays(this->bladeVelocitiesYDPreviousTimestep, this->bladeVelocitiesYDCurrentTimestep); + swapArrays(this->bladeVelocitiesZDPreviousTimestep, this->bladeVelocitiesZDCurrentTimestep); + + swapArrays(this->bladeForcesXDPreviousTimestep, this->bladeForcesXDCurrentTimestep); + swapArrays(this->bladeForcesYDPreviousTimestep, this->bladeForcesYDCurrentTimestep); + swapArrays(this->bladeForcesZDPreviousTimestep, this->bladeForcesZDCurrentTimestep); +} \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/ActuatorFarm.h b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/ActuatorFarm.h new file mode 100644 index 0000000000000000000000000000000000000000..f771ce10cdfe81237ae1caa8a26f887488839aa4 --- /dev/null +++ b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/ActuatorFarm.h @@ -0,0 +1,200 @@ +#ifndef ActuatorFarm_H +#define ActuatorFarm_H + +#include "PreCollisionInteractor.h" +#include "PointerDefinitions.h" +#include "lbm/constants/NumericConstants.h" +#include <stdexcept> + +using namespace vf::lbm::constant; + +class Parameter; +class GridProvider; +using namespace vf::lbm::constant; + +class ActuatorFarm : public PreCollisionInteractor +{ +public: + ActuatorFarm( + const uint _nBlades, + const real _density, + const uint _nBladeNodes, + const real _epsilon, + int _level, + const real _deltaT, + const real _deltaX, + const bool _useHostArrays + ) : + numberOfBlades(_nBlades), + density(_density), + numberOfBladeNodes(_nBladeNodes), + epsilon(_epsilon), + level(_level), + useHostArrays(_useHostArrays), + numberOfTurbines(0), + numberOfNodes(0), + PreCollisionInteractor() + { + this->deltaT = _deltaT*exp2(-this->level); + this->deltaX = _deltaX*exp2(-this->level); + this->invEpsilonSqrd = 1/(epsilon*epsilon); + this->invDeltaX = c1o1/this->deltaX; + + if(this->epsilon<this->deltaX) + throw std::runtime_error("ActuatorFarm::ActuatorFarm: epsilon needs to be larger than dx!"); + } + + virtual ~ActuatorFarm() + { + + } + void addTurbine(real turbinePosX, real turbinePosY, real turbinePosZ, real diameter, real omega, real azimuth, real yaw, std::vector<real> bladeRadii); + void init(Parameter* para, GridProvider* gridProvider, CudaMemoryManager* cudaManager) override; + void interact(Parameter* para, CudaMemoryManager* cudaManager, int level, uint t) override; + void free(Parameter* para, CudaMemoryManager* cudaManager) override; + void getTaggedFluidNodes(Parameter *para, GridProvider* gridProvider) override; + + void write(uint t); + + real getDensity(){ return this->density; }; + real getDeltaT(){ return this->deltaT; }; + real getDeltaX(){ return this->deltaX; }; + + uint getNumberOfTurbines(){ return this->numberOfTurbines; }; + uint getNumberOfNodesPerBlade(){ return this->numberOfBladeNodes; }; + uint getNumberOfBladesPerTurbine(){ return this->numberOfBlades; }; + + uint getNumberOfIndices(){ return this->numberOfIndices; }; + uint getNumberOfNodes(){ return this->numberOfNodes; }; + + real* getAllAzimuths(){ return azimuthsH; }; + real* getAllOmegas(){ return omegasH; }; + real* getAllYaws(){ return yawsH; }; + + real* getAllTurbinePosX(){ return turbinePosXH; }; + real* getAllTurbinePosY(){ return turbinePosYH; }; + real* getAllTurbinePosZ(){ return turbinePosZH; }; + + real getTurbineAzimuth(uint turbine){ return azimuthsH[turbine]; }; + real getTurbineOmega (uint turbine){ return omegasH[turbine]; }; + real getTurbineYaw (uint turbine){ return yawsH[turbine]; }; + + real getTurbinePosX(uint turbine){ return turbinePosXH[turbine]; }; + real getTurbinePosY(uint turbine){ return turbinePosYH[turbine]; }; + real getTurbinePosZ(uint turbine){ return turbinePosZH[turbine]; }; + + real* getAllBladeRadii(){ return this->bladeRadiiH; }; + real* getAllBladeCoordsX(){ return this->bladeCoordsXH; }; + real* getAllBladeCoordsY(){ return this->bladeCoordsYH; }; + real* getAllBladeCoordsZ(){ return this->bladeCoordsZH; }; + real* getAllBladeVelocitiesX(){ return this->bladeVelocitiesXH; }; + real* getAllBladeVelocitiesY(){ return this->bladeVelocitiesYH; }; + real* getAllBladeVelocitiesZ(){ return this->bladeVelocitiesZH; }; + real* getAllBladeForcesX(){ return this->bladeForcesXH; }; + real* getAllBladeForcesY(){ return this->bladeForcesYH; }; + real* getAllBladeForcesZ(){ return this->bladeForcesZH; }; + + real* getTurbineBladeRadii(uint turbine){ return &this->bladeRadiiH[turbine*numberOfBladeNodes*numberOfBlades]; }; + real* getTurbineBladeCoordsX(uint turbine){ return &this->bladeCoordsXH[turbine*numberOfBladeNodes*numberOfBlades]; }; + real* getTurbineBladeCoordsY(uint turbine){ return &this->bladeCoordsYH[turbine*numberOfBladeNodes*numberOfBlades]; }; + real* getTurbineBladeCoordsZ(uint turbine){ return &this->bladeCoordsZH[turbine*numberOfBladeNodes*numberOfBlades]; }; + real* getTurbineBladeVelocitiesX(uint turbine){ return &this->bladeVelocitiesXH[turbine*numberOfBladeNodes*numberOfBlades]; }; + real* getTurbineBladeVelocitiesY(uint turbine){ return &this->bladeVelocitiesYH[turbine*numberOfBladeNodes*numberOfBlades]; }; + real* getTurbineBladeVelocitiesZ(uint turbine){ return &this->bladeVelocitiesZH[turbine*numberOfBladeNodes*numberOfBlades]; }; + real* getTurbineBladeForcesX(uint turbine){ return &this->bladeForcesXH[turbine*numberOfBladeNodes*numberOfBlades]; }; + real* getTurbineBladeForcesY(uint turbine){ return &this->bladeForcesYH[turbine*numberOfBladeNodes*numberOfBlades]; }; + real* getTurbineBladeForcesZ(uint turbine){ return &this->bladeForcesZH[turbine*numberOfBladeNodes*numberOfBlades]; }; + + real* getAllBladeRadiiDevice(){ return this->bladeRadiiD; }; + real* getAllBladeCoordsXDevice(){ return this->bladeCoordsXDCurrentTimestep; }; + real* getAllBladeCoordsYDevice(){ return this->bladeCoordsYDCurrentTimestep; }; + real* getAllBladeCoordsZDevice(){ return this->bladeCoordsZDCurrentTimestep; }; + real* getAllBladeVelocitiesXDevice(){ return this->bladeVelocitiesXDCurrentTimestep; }; + real* getAllBladeVelocitiesYDevice(){ return this->bladeVelocitiesYDCurrentTimestep; }; + real* getAllBladeVelocitiesZDevice(){ return this->bladeVelocitiesZDCurrentTimestep; }; + real* getAllBladeForcesXDevice(){ return this->bladeForcesXDCurrentTimestep; }; + real* getAllBladeForcesYDevice(){ return this->bladeForcesYDCurrentTimestep; }; + real* getAllBladeForcesZDevice(){ return this->bladeForcesZDCurrentTimestep; }; + + real* getTurbineBladeRadiiDevice(uint turbine){ return &this->bladeRadiiD[turbine*numberOfBladeNodes]; }; + real* getTurbineBladeCoordsXDevice(uint turbine){ return &this->bladeCoordsXDCurrentTimestep[turbine*numberOfBladeNodes*numberOfBlades]; }; + real* getTurbineBladeCoordsYDevice(uint turbine){ return &this->bladeCoordsYDCurrentTimestep[turbine*numberOfBladeNodes*numberOfBlades]; }; + real* getTurbineBladeCoordsZDevice(uint turbine){ return &this->bladeCoordsZDCurrentTimestep[turbine*numberOfBladeNodes*numberOfBlades]; }; + real* getTurbineBladeVelocitiesXDevice(uint turbine){ return &this->bladeVelocitiesXDCurrentTimestep[turbine*numberOfBladeNodes*numberOfBlades]; }; + real* getTurbineBladeVelocitiesYDevice(uint turbine){ return &this->bladeVelocitiesYDCurrentTimestep[turbine*numberOfBladeNodes*numberOfBlades]; }; + real* getTurbineBladeVelocitiesZDevice(uint turbine){ return &this->bladeVelocitiesZDCurrentTimestep[turbine*numberOfBladeNodes*numberOfBlades]; }; + real* getTurbineBladeForcesXDevice(uint turbine){ return &this->bladeForcesXDCurrentTimestep[turbine*numberOfBladeNodes*numberOfBlades]; }; + real* getTurbineBladeForcesYDevice(uint turbine){ return &this->bladeForcesYDCurrentTimestep[turbine*numberOfBladeNodes*numberOfBlades]; }; + real* getTurbineBladeForcesZDevice(uint turbine){ return &this->bladeForcesZDCurrentTimestep[turbine*numberOfBladeNodes*numberOfBlades]; }; + + void setAllAzimuths(real* _azimuth); + void setAllOmegas(real* _omegas); + void setAllYaws(real* yaws); + + void setTurbineAzimuth(uint turbine, real azimuth){ azimuthsH[turbine] = azimuth; }; + void setTurbineYaw(uint turbine, real yaw){ yawsH[turbine] = yaw; }; + void setTurbineOmega(uint turbine, real omega){ omegasH[turbine] = omega; }; + + void setAllBladeCoords(real* _bladeCoordsX, real* _bladeCoordsY, real* _bladeCoordsZ); + void setAllBladeVelocities(real* _bladeVelocitiesX, real* _bladeVelocitiesY, real* _bladeVelocitiesZ); + void setAllBladeForces(real* _bladeForcesX, real* _bladeForcesY, real* _bladeForcesZ); + + void setTurbineBladeCoords(uint turbine, real* _bladeCoordsX, real* _bladeCoordsY, real* _bladeCoordsZ); + void setTurbineBladeVelocities(uint turbine, real* _bladeVelocitiesX, real* _bladeVelocitiesY, real* _bladeVelocitiesZ); + void setTurbineBladeForces(uint turbine, real* _bladeForcesX, real* _bladeForcesY, real* _bladeForcesZ); + + virtual void calcBladeForces(); + +private: + void initTurbineGeometries(CudaMemoryManager* cudaManager); + void initBoundingSpheres(Parameter* para, CudaMemoryManager* cudaManager); + void initBladeCoords(CudaMemoryManager* cudaManager); + void initBladeVelocities(CudaMemoryManager* cudaManager); + void initBladeForces(CudaMemoryManager* cudaManager); + void initBladeIndices(Parameter* para, CudaMemoryManager* cudaManager); + + void calcForcesEllipticWing(); + void rotateBlades(real angle, uint turbineID); + + void writeBladeCoords(uint t); + void writeBladeForces(uint t); + void writeBladeVelocities(uint t); + + void swapDeviceArrays(); + +public: + real* bladeRadiiH; + real* bladeRadiiD; + real* bladeCoordsXH, * bladeCoordsYH, * bladeCoordsZH; + real* bladeCoordsXDPreviousTimestep, * bladeCoordsYDPreviousTimestep, * bladeCoordsZDPreviousTimestep; + real* bladeCoordsXDCurrentTimestep, * bladeCoordsYDCurrentTimestep, * bladeCoordsZDCurrentTimestep; + real* bladeVelocitiesXH, * bladeVelocitiesYH, * bladeVelocitiesZH; + real* bladeVelocitiesXDPreviousTimestep, * bladeVelocitiesYDPreviousTimestep, * bladeVelocitiesZDPreviousTimestep; + real* bladeVelocitiesXDCurrentTimestep, * bladeVelocitiesYDCurrentTimestep, * bladeVelocitiesZDCurrentTimestep; + real* bladeForcesXH, * bladeForcesYH, * bladeForcesZH; + real* bladeForcesXDPreviousTimestep, * bladeForcesYDPreviousTimestep, * bladeForcesZDPreviousTimestep; + real* bladeForcesXDCurrentTimestep, * bladeForcesYDCurrentTimestep, * bladeForcesZDCurrentTimestep; + uint* bladeIndicesH; + uint* bladeIndicesD; + uint* boundingSphereIndicesH; + uint* boundingSphereIndicesD; + real* turbinePosXH, *turbinePosYH, *turbinePosZH, *omegasH, *azimuthsH, *yawsH, *diametersH; + real* turbinePosXD, *turbinePosYD, *turbinePosZD, *omegasD, *azimuthsD, *yawsD, *diametersD; + +private: + std::vector<real> preInitPosX, preInitPosY, preInitPosZ, preInitDiameters, preInitOmegas, preInitAzimuths, preInitYaws; + std::vector<std::vector<real>> preInitBladeRadii; + const bool useHostArrays; + const real density; + real deltaT, deltaX; + const uint numberOfBladeNodes, numberOfBlades; + uint numberOfTurbines; + const real epsilon; // in m + const int level; + uint numberOfIndices; + uint numberOfNodes; + real forceRatio, factorGaussian, invEpsilonSqrd, invDeltaX; + int streamIndex; +}; + +#endif \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/ActuatorLine.cu b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/ActuatorLine.cu deleted file mode 100644 index 71897bd21ea4fb299d3cc0ffa385506d4503f360..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/ActuatorLine.cu +++ /dev/null @@ -1,423 +0,0 @@ -#include "ActuatorLine.h" - -#include <cuda.h> -#include <cuda_runtime.h> -#include <helper_cuda.h> - -#include <cuda/CudaGrid.h> -#include "VirtualFluids_GPU/GPU/GeometryUtils.h" - -#include "Parameter/Parameter.h" -#include "DataStructureInitializer/GridProvider.h" -#include "GPU/CudaMemoryManager.h" - -__host__ __device__ __inline__ uint calcNode(uint bladeNode, uint nBladeNodes, uint blade, uint nBlades) -{ - return bladeNode+blade*nBladeNodes; -} - -__host__ __device__ __inline__ void calcBladeAndBladeNode(uint node, uint& bladeNode, uint nBladeNodes, uint& blade, uint nBlades) -{ - blade = node/nBladeNodes; - bladeNode = node - blade*nBladeNodes; -} - -__host__ __device__ __forceinline__ real distSqrd(real distX, real distY, real distZ) -{ - return distX*distX+distY*distY+distZ*distZ; -} - -__host__ __device__ __inline__ void rotateFromBladeToGlobal( - real& bladeCoordX_BF, real& bladeCoordY_BF, real& bladeCoordZ_BF, - real& bladeCoordX_GF, real& bladeCoordY_GF, real& bladeCoordZ_GF, - real& azimuth, real& yaw) -{ - real tmpX, tmpY, tmpZ; - - rotateAboutX3D(azimuth, bladeCoordX_BF, bladeCoordY_BF, bladeCoordZ_BF, tmpX, tmpY, tmpZ); - rotateAboutZ3D(yaw, tmpX, tmpY, tmpZ, bladeCoordX_GF, bladeCoordY_GF, bladeCoordZ_GF); - -} - -__host__ __device__ __inline__ void rotateFromGlobalToBlade( - real& bladeCoordX_BF, real& bladeCoordY_BF, real& bladeCoordZ_BF, - real& bladeCoordX_GF, real& bladeCoordY_GF, real& bladeCoordZ_GF, - real& azimuth, real& yaw) -{ - real tmpX, tmpY, tmpZ; - - invRotateAboutZ3D(yaw, bladeCoordX_GF, bladeCoordY_GF, bladeCoordZ_GF, tmpX, tmpY, tmpZ); - invRotateAboutX3D(azimuth, tmpX, tmpY, tmpZ, bladeCoordX_BF, bladeCoordY_BF, bladeCoordZ_BF); -} - -__global__ void interpolateVelocities(real* gridCoordsX, real* gridCoordsY, real* gridCoordsZ, - uint* neighborsX, uint* neighborsY, uint* neighborsZ, uint* neighborsWSB, - real* vx, real* vy, real* vz, - real* bladeCoordsX, real* bladeCoordsY, real* bladeCoordsZ, - real* bladeVelocitiesX, real* bladeVelocitiesY, real* bladeVelocitiesZ, - uint nBlades, uint nBladeNodes, - real azimuth, real yaw, real omega, - real turbPosX, real turbPosY, real turbPosZ, - uint* bladeIndices, real velocityRatio, real invDeltaX) -{ - const uint x = threadIdx.x; - const uint y = blockIdx.x; - const uint z = blockIdx.y; - - const uint nx = blockDim.x; - const uint ny = gridDim.x; - - const uint node = nx*(ny*z + y) + x; - - uint bladeNode, blade; - - calcBladeAndBladeNode(node, bladeNode, nBladeNodes, blade, nBlades); - - if(node>=nBladeNodes*nBlades) return; - - real bladeCoordX_BF = bladeCoordsX[node]; - real bladeCoordY_BF = bladeCoordsY[node]; - real bladeCoordZ_BF = bladeCoordsZ[node]; - - real bladeCoordX_GF, bladeCoordY_GF, bladeCoordZ_GF; - - real localAzimuth = azimuth+blade*c2Pi/nBlades; - - rotateFromBladeToGlobal(bladeCoordX_BF, bladeCoordY_BF, bladeCoordZ_BF, - bladeCoordX_GF, bladeCoordY_GF, bladeCoordZ_GF, - localAzimuth, yaw); - - bladeCoordX_GF += turbPosX; - bladeCoordY_GF += turbPosY; - bladeCoordZ_GF += turbPosZ; - - uint k, ke, kn, kt; - uint kne, kte, ktn, ktne; - - k = findNearestCellBSW(bladeIndices[node], - gridCoordsX, gridCoordsY, gridCoordsZ, - bladeCoordX_GF, bladeCoordY_GF, bladeCoordZ_GF, - neighborsX, neighborsY, neighborsZ, neighborsWSB); - - bladeIndices[node] = k; - - getNeighborIndicesOfBSW(k, ke, kn, kt, kne, kte, ktn, ktne, neighborsX, neighborsY, neighborsZ); - - real dW, dE, dN, dS, dT, dB; - - real distX = invDeltaX*(bladeCoordX_GF-gridCoordsX[k]); - real distY = invDeltaX*(bladeCoordY_GF-gridCoordsY[k]); - real distZ = invDeltaX*(bladeCoordZ_GF-gridCoordsZ[k]); - - getInterpolationWeights(dW, dE, dN, dS, dT, dB, distX, distY, distZ); - - real bladeVelX_GF = trilinearInterpolation(dW, dE, dN, dS, dT, dB, k, ke, kn, kt, kne, kte, ktn, ktne, vx)*velocityRatio; - real bladeVelY_GF = trilinearInterpolation(dW, dE, dN, dS, dT, dB, k, ke, kn, kt, kne, kte, ktn, ktne, vy)*velocityRatio; - real bladeVelZ_GF = trilinearInterpolation(dW, dE, dN, dS, dT, dB, k, ke, kn, kt, kne, kte, ktn, ktne, vz)*velocityRatio; - - real bladeVelX_BF, bladeVelY_BF, bladeVelZ_BF; - - rotateFromGlobalToBlade(bladeVelX_BF, bladeVelY_BF, bladeVelZ_BF, - bladeVelX_GF, bladeVelY_GF, bladeVelZ_GF, - localAzimuth, yaw); - - bladeVelocitiesX[node] = bladeVelX_BF; - bladeVelocitiesY[node] = bladeVelY_BF+omega*bladeCoordZ_BF; - bladeVelocitiesZ[node] = bladeVelZ_BF; -} - - -__global__ void applyBodyForces(real* gridCoordsX, real* gridCoordsY, real* gridCoordsZ, - real* gridForcesX, real* gridForcesY, real* gridForcesZ, - real* bladeCoordsX, real* bladeCoordsY, real* bladeCoordsZ, - real* bladeForcesX, real* bladeForcesY,real* bladeForcesZ, - uint nBlades, uint nBladeNodes, - real azimuth, real yaw, real omega, - real turbPosX, real turbPosY, real turbPosZ, - uint* gridIndices, uint nIndices, - real invEpsilonSqrd, real factorGaussian) -{ - const uint x = threadIdx.x; - const uint y = blockIdx.x; - const uint z = blockIdx.y; - - const uint nx = blockDim.x; - const uint ny = gridDim.x; - - const uint index = nx*(ny*z + y) + x; - - if(index>=nIndices) return; - - uint gridIndex = gridIndices[index]; - - real gridCoordX_RF = gridCoordsX[gridIndex] - turbPosX; - real gridCoordY_RF = gridCoordsY[gridIndex] - turbPosY; - real gridCoordZ_RF = gridCoordsZ[gridIndex] - turbPosZ; - - real gridForceX_RF = c0o1; - real gridForceY_RF = c0o1; - real gridForceZ_RF = c0o1; - - real dAzimuth = c2Pi/nBlades; - - for( uint blade=0; blade<nBlades; blade++) - { - real localAzimuth = azimuth+blade*dAzimuth; - - real gridCoordX_BF, gridCoordY_BF, gridCoordZ_BF; - - rotateFromGlobalToBlade(gridCoordX_BF, gridCoordY_BF, gridCoordZ_BF, - gridCoordX_RF, gridCoordY_RF, gridCoordZ_RF, - localAzimuth, yaw); - - for( uint bladeNode=0; bladeNode<nBladeNodes; bladeNode++) - { - uint node = calcNode(bladeNode, nBladeNodes, blade, nBlades); - - real eta = factorGaussian*exp(-distSqrd(bladeCoordsX[node]-gridCoordX_BF, bladeCoordsY[node]-gridCoordY_BF, bladeCoordsZ[node]-gridCoordZ_BF)*invEpsilonSqrd); - - real forceX_RF, forceY_RF, forceZ_RF; - - rotateFromBladeToGlobal(bladeForcesX[node], bladeForcesY[node], bladeForcesZ[node], - forceX_RF, forceY_RF, forceZ_RF, - localAzimuth, yaw); - - gridForceX_RF += forceX_RF*eta; - gridForceY_RF += forceY_RF*eta; - gridForceZ_RF += forceZ_RF*eta; - } - } - - atomicAdd(&gridForcesX[gridIndex], gridForceX_RF); - atomicAdd(&gridForcesY[gridIndex], gridForceY_RF); - atomicAdd(&gridForcesZ[gridIndex], gridForceZ_RF); -} - - -void ActuatorLine::init(Parameter* para, GridProvider* gridProvider, CudaMemoryManager* cudaMemoryManager) -{ - if(!para->getIsBodyForce()) throw std::runtime_error("try to allocate ActuatorLine but BodyForce is not set in Parameter."); - this->initBladeRadii(cudaMemoryManager); - this->initBladeCoords(cudaMemoryManager); - this->initBladeIndices(para, cudaMemoryManager); - this->initBladeVelocities(cudaMemoryManager); - this->initBladeForces(cudaMemoryManager); - this->initBoundingSphere(para, cudaMemoryManager); -} - - -void ActuatorLine::interact(Parameter* para, CudaMemoryManager* cudaMemoryManager, int level, unsigned int t) -{ - if (level != this->level) return; - - cudaMemoryManager->cudaCopyBladeCoordsHtoD(this); - - vf::cuda::CudaGrid bladeGrid = vf::cuda::CudaGrid(para->getParH(level)->numberofthreads, this->nNodes); - - interpolateVelocities<<< bladeGrid.grid, bladeGrid.threads >>>( - para->getParD(this->level)->coordinateX, para->getParD(this->level)->coordinateY, para->getParD(this->level)->coordinateZ, - para->getParD(this->level)->neighborX, para->getParD(this->level)->neighborY, para->getParD(this->level)->neighborZ, para->getParD(this->level)->neighborInverse, - para->getParD(this->level)->velocityX, para->getParD(this->level)->velocityY, para->getParD(this->level)->velocityZ, - this->bladeCoordsXD, this->bladeCoordsYD, this->bladeCoordsZD, - this->bladeVelocitiesXD, this->bladeVelocitiesYD, this->bladeVelocitiesZD, - this->nBlades, this->nBladeNodes, - this->azimuth, this->yaw, this->omega, - this->turbinePosX, this->turbinePosY, this->turbinePosZ, - this->bladeIndicesD, para->getVelocityRatio(), this->invDeltaX); - - cudaMemoryManager->cudaCopyBladeVelocitiesDtoH(this); - - this->calcBladeForces(); - - cudaMemoryManager->cudaCopyBladeForcesHtoD(this); - - vf::cuda::CudaGrid sphereGrid = vf::cuda::CudaGrid(para->getParH(level)->numberofthreads, this->nIndices); - - applyBodyForces<<<sphereGrid.grid, sphereGrid.threads>>>( - para->getParD(this->level)->coordinateX, para->getParD(this->level)->coordinateY, para->getParD(this->level)->coordinateZ, - para->getParD(this->level)->forceX_SP, para->getParD(this->level)->forceY_SP, para->getParD(this->level)->forceZ_SP, - this->bladeCoordsXD, this->bladeCoordsYD, this->bladeCoordsZD, - this->bladeForcesXD, this->bladeForcesYD, this->bladeForcesZD, - this->nBlades, this->nBladeNodes, - this->azimuth, this->yaw, this->omega, - this->turbinePosX, this->turbinePosY, this->turbinePosZ, - this->boundingSphereIndicesD, this->nIndices, - this->invEpsilonSqrd, this->factorGaussian); - - this->azimuth = fmod(this->azimuth+this->omega*this->deltaT,c2Pi); -} - - -void ActuatorLine::free(Parameter* para, CudaMemoryManager* cudaMemoryManager) -{ - cudaMemoryManager->cudaFreeBladeRadii(this); - cudaMemoryManager->cudaFreeBladeCoords(this); - cudaMemoryManager->cudaFreeBladeVelocities(this); - cudaMemoryManager->cudaFreeBladeForces(this); - cudaMemoryManager->cudaFreeBladeIndices(this); - cudaMemoryManager->cudaFreeSphereIndices(this); -} - - -void ActuatorLine::calcForcesEllipticWing() -{ - uint node; - real u_rel, v_rel, u_rel_sq; - real phi; - real Cl = c1o1; - real Cd = c0o1; - real c0 = c1o1; - - real c, Cn, Ct; - - for( uint blade=0; blade<this->nBlades; blade++) - { - for( uint bladeNode=0; bladeNode<this->nBladeNodes; bladeNode++) - { - node = calcNode(bladeNode, this->nBladeNodes, blade, this->nBlades); - - u_rel = this->bladeVelocitiesXH[node]; - v_rel = this->bladeVelocitiesYH[node]; - u_rel_sq = u_rel*u_rel+v_rel*v_rel; - phi = atan2(u_rel, v_rel); - - real tmp = c4o1*this->bladeRadiiH[bladeNode]/this->diameter-c1o1; - c = c0 * sqrt( c1o1- tmp*tmp ); - Cn = Cl*cos(phi)+Cd*sin(phi); - Ct = Cl*sin(phi)-Cd*cos(phi); - - this->bladeForcesXH[node] = -c1o2*u_rel_sq*c*this->density*Cn; - this->bladeForcesYH[node] = -c1o2*u_rel_sq*c*this->density*Ct; - this->bladeForcesZH[node] = c0o1; - } - } -} - -void ActuatorLine::calcBladeForces() -{ - this->calcForcesEllipticWing(); -} - -void ActuatorLine::initBladeRadii(CudaMemoryManager* cudaMemoryManager) -{ - cudaMemoryManager->cudaAllocBladeRadii(this); - - real dr = c1o2*this->diameter/this->nBladeNodes; - - for(uint node=0; node<this->nBladeNodes; node++) - { - this->bladeRadiiH[node] = dr*(node+1); - } - cudaMemoryManager->cudaCopyBladeRadiiHtoD(this); - - real dxOPiSqrtEps = pow(this->deltaX/(this->epsilon*sqrt(cPi)),c3o1); - this->factorGaussian = dr*dxOPiSqrtEps/this->forceRatio; -} - -void ActuatorLine::initBladeCoords(CudaMemoryManager* cudaMemoryManager) -{ - cudaMemoryManager->cudaAllocBladeCoords(this); - - for(uint blade=0; blade<this->nBlades; blade++) - { - for(uint bladeNode=0; bladeNode<this->nBladeNodes; bladeNode++) - { - uint node = calcNode(bladeNode, this->nBladeNodes, blade, this->nBlades); - - this->bladeCoordsXH[node] = c0o1; - this->bladeCoordsYH[node] = c0o1; - this->bladeCoordsZH[node] = this->bladeRadiiH[bladeNode]; - } - } - cudaMemoryManager->cudaCopyBladeCoordsHtoD(this); -} - -void ActuatorLine::initBladeVelocities(CudaMemoryManager* cudaMemoryManager) -{ - cudaMemoryManager->cudaAllocBladeVelocities(this); - - for(uint node=0; node<this->nNodes; node++) - { - this->bladeVelocitiesXH[node] = c0o1; - this->bladeVelocitiesYH[node] = c0o1; - this->bladeVelocitiesZH[node] = c0o1; - } - cudaMemoryManager->cudaCopyBladeVelocitiesHtoD(this); -} - -void ActuatorLine::initBladeForces(CudaMemoryManager* cudaMemoryManager) -{ - cudaMemoryManager->cudaAllocBladeForces(this); - - for(uint node=0; node<this->nNodes; node++) - { - this->bladeForcesXH[node] = c0o1; - this->bladeForcesYH[node] = c0o1; - this->bladeForcesZH[node] = c0o1; - } - cudaMemoryManager->cudaCopyBladeForcesHtoD(this); -} - -void ActuatorLine::initBladeIndices(Parameter* para, CudaMemoryManager* cudaMemoryManager) -{ - cudaMemoryManager->cudaAllocBladeIndices(this); - - for(uint node=0; node<this->nNodes; node++) - - { - this->bladeIndicesH[node] = 1; - } - cudaMemoryManager->cudaCopyBladeIndicesHtoD(this); -} - -void ActuatorLine::initBoundingSphere(Parameter* para, CudaMemoryManager* cudaMemoryManager) -{ - // Actuator line exists only on 1 level - std::vector<int> nodesInSphere; - real sphereRadius = c1o2*this->diameter+c4o1*this->epsilon; - real sphereRadiusSqrd = sphereRadius*sphereRadius; - - for (uint j = 1; j <= para->getParH(this->level)->numberOfNodes; j++) - { - const real distX = para->getParH(this->level)->coordinateX[j]-this->turbinePosX; - const real distY = para->getParH(this->level)->coordinateY[j]-this->turbinePosY; - const real distZ = para->getParH(this->level)->coordinateZ[j]-this->turbinePosZ; - if(distSqrd(distX,distY,distZ) < sphereRadiusSqrd) nodesInSphere.push_back(j); - } - - this->nIndices = uint(nodesInSphere.size()); - cudaMemoryManager->cudaAllocSphereIndices(this); - std::copy(nodesInSphere.begin(), nodesInSphere.end(), this->boundingSphereIndicesH); - cudaMemoryManager->cudaCopySphereIndicesHtoD(this); -} - -void ActuatorLine::setBladeCoords(real* _bladeCoordsX, real* _bladeCoordsY, real* _bladeCoordsZ) -{ - - for(uint node=0; node<this->nNodes; node++) - { - this->bladeCoordsXH[node] = _bladeCoordsX[node]; - this->bladeCoordsYH[node] = _bladeCoordsY[node]; - this->bladeCoordsZH[node] = _bladeCoordsZ[node]; - } -} - -void ActuatorLine::setBladeVelocities(real* _bladeVelocitiesX, real* _bladeVelocitiesY, real* _bladeVelocitiesZ) -{ - for(uint node=0; node<this->nNodes; node++) - { - this->bladeVelocitiesXH[node] = _bladeVelocitiesX[node]; - this->bladeVelocitiesYH[node] = _bladeVelocitiesY[node]; - this->bladeVelocitiesZH[node] = _bladeVelocitiesZ[node]; - } -} - -void ActuatorLine::setBladeForces(real* _bladeForcesX, real* _bladeForcesY, real* _bladeForcesZ) -{ - for(uint node=0; node<this->nNodes; node++) - { - this->bladeForcesXH[node] = _bladeForcesX[node]; - this->bladeForcesYH[node] = _bladeForcesY[node]; - this->bladeForcesZH[node] = _bladeForcesZ[node]; - } -} \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/ActuatorLine.h b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/ActuatorLine.h deleted file mode 100644 index b44c89c5020eb206baa3bba1994b1e45f760c3bb..0000000000000000000000000000000000000000 --- a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/ActuatorLine.h +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef ActuatorLine_H -#define ActuatorLine_H - -#include "PreCollisionInteractor.h" -#include "PointerDefinitions.h" -#include "VirtualFluids_GPU_export.h" -#include "lbm/constants/NumericConstants.h" - -class Parameter; -class GridProvider; - -using namespace vf::lbm::constant; -class VIRTUALFLUIDS_GPU_EXPORT ActuatorLine : public PreCollisionInteractor -{ -public: - ActuatorLine( - const uint _nBlades, - const real _density, - const uint _nBladeNodes, - const real _epsilon, - real _turbinePosX, real _turbinePosY, real _turbinePosZ, - const real _diameter, - int _level, - const real _deltaT, - const real _deltaX - ) : nBlades(_nBlades), - density(_density), - nBladeNodes(_nBladeNodes), - epsilon(_epsilon), - turbinePosX(_turbinePosX), turbinePosY(_turbinePosY), turbinePosZ(_turbinePosZ), - diameter(_diameter), - level(_level), - PreCollisionInteractor() - { - this->deltaT = _deltaT*exp2(-this->level); - this->deltaX = _deltaX*exp2(-this->level); - this->invDeltaX = c1o1/this->deltaX; - this->forceRatio = this->density*pow(this->deltaX,4)*pow(this->deltaT,-2); - this->invEpsilonSqrd = c1o1/(this->epsilon*this->epsilon); - this->nNodes = this->nBladeNodes*this->nBlades; - this->omega = c1o1; - this->azimuth = c0o1; - this->yaw = c0o1; - }; - - virtual ~ActuatorLine(){}; - - void init(Parameter* para, GridProvider* gridProvider, CudaMemoryManager* cudaMemoryManager) override; - void interact(Parameter* para, CudaMemoryManager* cudaMemoryManager, int level, uint t) override; - void free(Parameter* para, CudaMemoryManager* cudaMemoryManager) override; - void write(uint t); - - uint getNBladeNodes(){ return this->nBladeNodes; }; - uint getNBlades(){ return this->nBlades;}; - uint getNIndices(){ return this->nIndices; }; - uint getNNodes(){ return this->nNodes; }; - real getOmega(){ return this->omega; }; - real getAzimuth(){ return this->azimuth; }; - real getYaw(){ return this->yaw; }; - real getDensity(){ return this->density; }; - real getPositionX(){ return this->turbinePosX; }; - real getPositionY(){ return this->turbinePosY; }; - real getPositionZ(){ return this->turbinePosZ; }; - real* getBladeRadii(){ return this->bladeRadiiH; }; - real* getBladeCoordsX(){ return this->bladeCoordsXH; }; - real* getBladeCoordsY(){ return this->bladeCoordsYH; }; - real* getBladeCoordsZ(){ return this->bladeCoordsZH; }; - real* getBladeVelocitiesX(){ return this->bladeVelocitiesXH; }; - real* getBladeVelocitiesY(){ return this->bladeVelocitiesYH; }; - real* getBladeVelocitiesZ(){ return this->bladeVelocitiesZH; }; - real* getBladeForcesX(){ return this->bladeForcesXH; }; - real* getBladeForcesY(){ return this->bladeForcesYH; }; - real* getBladeForcesZ(){ return this->bladeForcesZH; }; - - void setOmega(real _omega){ this->omega = _omega; }; - void setAzimuth(real _azimuth){ this->azimuth = _azimuth; }; - void setYaw(real _yaw){ this->yaw = _yaw; }; - void setBladeCoords(real* _bladeCoordsX, real* _bladeCoordsY, real* _bladeCoordsZ); - void setBladeVelocities(real* _bladeVelocitiesX, real* _bladeVelocitiesY, real* _bladeVelocitiesZ); - void setBladeForces(real* _bladeForcesX, real* _bladeForcesY, real* _bladeForcesZ); - virtual void calcBladeForces(); - -private: - void initBoundingSphere(Parameter* para, CudaMemoryManager* cudaMemoryManager); - - void initBladeRadii(CudaMemoryManager* cudaMemoryManager); - void initBladeCoords(CudaMemoryManager* cudaMemoryManager); - void initBladeVelocities(CudaMemoryManager* cudaMemoryManager); - void initBladeForces(CudaMemoryManager* cudaMemoryManager); - void initBladeIndices(Parameter* para, CudaMemoryManager* cudaMemoryManager); - - void calcForcesEllipticWing(); - -public: - real* bladeRadiiH; - real* bladeRadiiD; - real* bladeCoordsXH, * bladeCoordsYH, * bladeCoordsZH; - real* bladeCoordsXD, * bladeCoordsYD, * bladeCoordsZD; - real* bladeVelocitiesXH, * bladeVelocitiesYH, * bladeVelocitiesZH; - real* bladeVelocitiesXD, * bladeVelocitiesYD, * bladeVelocitiesZD; - real* bladeForcesXH, * bladeForcesYH, * bladeForcesZH; - real* bladeForcesXD, * bladeForcesYD, * bladeForcesZD; - uint* bladeIndicesH; - uint* bladeIndicesD; - uint* boundingSphereIndicesH; - uint* boundingSphereIndicesD; - -private: - const real density; - real turbinePosX, turbinePosY, turbinePosZ; - real omega, azimuth, yaw, deltaT, deltaX, invDeltaX, forceRatio, factorGaussian, invEpsilonSqrd; - const real diameter; - const uint nBladeNodes; - const uint nBlades; - const real epsilon; // in m - const int level; - uint nIndices, nNodes; -}; - -#endif \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/PreCollisionInteractor.h b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/PreCollisionInteractor.h index a9b233f3035890c2617d3a00b639f995be6c218f..f9a87f613e7607301e59a7c1e67eb556418892e4 100644 --- a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/PreCollisionInteractor.h +++ b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/PreCollisionInteractor.h @@ -33,6 +33,7 @@ public: virtual void init(Parameter *para, GridProvider *gridProvider, CudaMemoryManager *cudaMemoryManager) = 0; virtual void interact(Parameter *para, CudaMemoryManager *cudaMemoryManager, int level, uint t) = 0; virtual void free(Parameter *para, CudaMemoryManager *cudaMemoryManager) = 0; + virtual void getTaggedFluidNodes(Parameter *para, GridProvider* gridProvider) = 0; protected: uint updateInterval; diff --git a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/PrecursorWriter.cu b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/PrecursorWriter.cu new file mode 100644 index 0000000000000000000000000000000000000000..aacb1721ad90e9178b3c2ccf49a2aa9ec79d5504 --- /dev/null +++ b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/PrecursorWriter.cu @@ -0,0 +1,321 @@ +#include "PrecursorWriter.h" +#include "basics/writer/WbWriterVtkXmlImageBinary.h" + +#include <cuda.h> +#include <cuda_runtime.h> +#include <helper_cuda.h> +#include <cuda/CudaGrid.h> +#include "Kernel/Utilities/DistributionHelper.cuh" + +#include <Core/StringUtilities/StringUtil.h> + +#include "Parameter/Parameter.h" +#include "DataStructureInitializer/GridProvider.h" +#include "GPU/CudaMemoryManager.h" + +using namespace vf::lbm::dir; + + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +//TODO check everything for multiple level +void index1d(int& idx, int y, int z, int ny, int nz) +{ + idx = y+ny*z; +} + +void index2d(int idx, int& y, int& z, int ny, int nz) +{ + z = idx/ny; + y = idx-ny*z; +} + +__inline__ __host__ __device__ uint linearIdx(const uint component, const uint node, const uint timestep, const uint numberOfComponents, const uint numberOfNodes) +{ + return node+numberOfNodes*(component+numberOfComponents*timestep); +} + +__inline__ __host__ __device__ uint linearIdx(const uint component, const uint node, const uint numberOfNodes) +{ + return node+component*numberOfNodes; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +__global__ void fillArrayVelocities(const uint numberOfPrecursorNodes, + uint* indices, + real *precursorData, + real *vx, + real *vy, + real *vz, + real velocityRatio) + + +{ + const uint node = vf::gpu::getNodeIndex(); + + if(node>=numberOfPrecursorNodes) return; + + precursorData[linearIdx(0u, node, numberOfPrecursorNodes)] = vx[indices[node]]*velocityRatio; + precursorData[linearIdx(1u, node, numberOfPrecursorNodes)] = vy[indices[node]]*velocityRatio; + precursorData[linearIdx(2u, node, numberOfPrecursorNodes)] = vz[indices[node]]*velocityRatio; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +__global__ void fillArrayDistributions( uint numberOfPrecursorNodes, + uint* indices, + real* precursorData, + real* distributions, + uint* neighborX, uint* neighborY, uint* neighborZ, + bool isEvenTimestep, + unsigned long numberOfLBnodes) +{ + const uint node = vf::gpu::getNodeIndex(); + + if(node>=numberOfPrecursorNodes) return; + + Distributions27 dist = vf::gpu::getDistributionReferences27(distributions, numberOfLBnodes, isEvenTimestep); + + //////////////////////////////////////////////////////////////////////////////// + // ! - Set neighbor indices (necessary for indirect addressing) + uint k_000 = indices[node]; + // uint k_M00 = neighborX[k_000]; + uint k_0M0 = neighborY[k_000]; + uint k_00M = neighborZ[k_000]; + // uint k_MM0 = neighborY[k_M00]; + // uint k_M0M = neighborZ[k_M00]; + uint k_0MM = neighborZ[k_0M0]; + // uint k_MMM = neighborZ[k_MM0]; + + //////////////////////////////////////////////////////////////////////////////////// + //! - Get local distributions in PX directions + //! + precursorData[linearIdx(PrecP00, node, numberOfPrecursorNodes)] = (dist.f[DIR_P00])[k_000]; + precursorData[linearIdx(PrecPP0, node, numberOfPrecursorNodes)] = (dist.f[DIR_PP0])[k_000]; + precursorData[linearIdx(PrecPM0, node, numberOfPrecursorNodes)] = (dist.f[DIR_PM0])[k_0M0]; + precursorData[linearIdx(PrecP0P, node, numberOfPrecursorNodes)] = (dist.f[DIR_P0P])[k_000]; + precursorData[linearIdx(PrecP0M, node, numberOfPrecursorNodes)] = (dist.f[DIR_P0M])[k_00M]; + precursorData[linearIdx(PrecPPP, node, numberOfPrecursorNodes)] = (dist.f[DIR_PPP])[k_000]; + precursorData[linearIdx(PrecPMP, node, numberOfPrecursorNodes)] = (dist.f[DIR_PMP])[k_0M0]; + precursorData[linearIdx(PrecPPM, node, numberOfPrecursorNodes)] = (dist.f[DIR_PPM])[k_00M]; + precursorData[linearIdx(PrecPMM, node, numberOfPrecursorNodes)] = (dist.f[DIR_PMM])[k_0MM]; +} + + +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +void PrecursorWriter::init(Parameter* para, GridProvider* gridProvider, CudaMemoryManager* cudaManager) +{ + VF_LOG_INFO("PrecursorWriter: Start initializing..."); + VF_LOG_INFO("Writing yz-planes at x={}m every {}. timestep, starting at t={}", this->xPos, this->tSave, this->tStartOut); + + precursorStructs.resize(para->getMaxLevel()+1); + for(int level=0; level<=para->getMaxLevel(); level++) + { + + real dx = abs(para->getParH(level)->coordinateX[1]-para->getParH(level)->coordinateX[para->getParH(level)->neighborX[1]]); + int maxPoints = (int((yMax-yMin)/dx)+1)* (int((zMax-zMin)/dx)+1); + + real lowestY, lowestZ, highestY, highestZ; + + lowestY = para->getParH(level)->coordinateY[para->getParH(level)->numberOfNodes-1]; + highestY = para->getParH(level)->coordinateY[1]; + + lowestZ = para->getParH(level)->coordinateZ[para->getParH(level)->numberOfNodes-1]; + highestZ = para->getParH(level)->coordinateZ[1]; + + std::vector<uint> indicesOnGrid; + std::vector<int> indicesOnPlane; + std::vector<real> coordY, coordZ; + + for(uint j=1; j<para->getParH(level)->numberOfNodes; j++ ) + { + real pointCoordX = para->getParH(level)->coordinateX[j]; + real pointCoordY = para->getParH(level)->coordinateY[j]; + real pointCoordZ = para->getParH(level)->coordinateZ[j]; + if( para->getParH(level)->typeOfGridNode[j] == GEO_FLUID && + pointCoordX < (dx+xPos) && pointCoordX >= xPos && + pointCoordY<=yMax && pointCoordY>=yMin && + pointCoordZ<=zMax && pointCoordZ>=zMin) + { + highestY = max(highestY, pointCoordY); + highestZ = max(highestZ, pointCoordZ); + + lowestY = min(lowestY, pointCoordY); + lowestZ = min(lowestZ, pointCoordZ); + indicesOnGrid.push_back(j); + coordY.push_back(pointCoordY); + coordZ.push_back(pointCoordZ); + } + } + if(indicesOnGrid.size()==0) + throw std::runtime_error("PrecursorWriter did not find any points on the grid"); + + int ny = int((highestY-lowestY)/dx)+1; + int nz = int((highestZ-lowestZ)/dx)+1; + + for(uint i=0;i<indicesOnGrid.size(); i++) + { + int idxY = int((coordY[i]-lowestY)/dx); + int idxZ = int((coordZ[i]-lowestZ)/dx); + int idx; + index1d(idx, idxY, idxZ, ny, nz); + indicesOnPlane.push_back(idx); + } + + precursorStructs[level] = SPtr<PrecursorStruct>(new PrecursorStruct); + precursorStructs[level]->numberOfPointsInBC = (uint)indicesOnGrid.size(); + precursorStructs[level]->indicesOnPlane = (int*) malloc(precursorStructs[level]->numberOfPointsInBC*sizeof(int)); + precursorStructs[level]->spacing = makeUbTuple(dx, dx, tSave*para->getTimeRatio()*pow(2,-level)); + precursorStructs[level]->origin = makeUbTuple(lowestY, lowestZ); + precursorStructs[level]->extent = makeUbTuple(0, ny-1, 0, nz-1); + precursorStructs[level]->numberOfPointsInData = ny*nz; + precursorStructs[level]->numberOfTimestepsPerFile = min(para->getlimitOfNodesForVTK()/(ny*nz), maxtimestepsPerFile); + precursorStructs[level]->numberOfFilesWritten = 0; + precursorStructs[level]->numberOfTimestepsBuffered = 0; + + switch (outputVariable) + { + case OutputVariable::Velocities: + precursorStructs[level]->numberOfQuantities = 3; + break; + case OutputVariable::Distributions: + precursorStructs[level]->numberOfQuantities = 9; + break; + + default: + break; + } + + cudaManager->cudaAllocPrecursorWriter(this, level); + + std::copy(indicesOnGrid.begin(), indicesOnGrid.end(), precursorStructs[level]->indicesH); + std::copy(indicesOnPlane.begin(), indicesOnPlane.end(), precursorStructs[level]->indicesOnPlane); + + cudaManager->cudaCopyPrecursorWriterIndicesHtoD(this, level); + + VF_LOG_INFO("Found {} points in precursor plane on level {}", precursorStructs[level]->numberOfPointsInBC, level); + } + VF_LOG_INFO("PrecursorWriter: Done initializing."); +} + + +void PrecursorWriter::interact(Parameter* para, CudaMemoryManager* cudaManager, int level, uint t) +{ + uint t_level = para->getTimeStep(level, t, true); + uint tStartOut_level = tStartOut*pow(2, level); + uint tEnd_level = para->getTimestepEnd()*pow(2, level); + + if(t_level>tStartOut_level && ((t_level-tStartOut_level) % tSave)==0) + { + vf::cuda::CudaGrid grid = vf::cuda::CudaGrid(para->getParH(level)->numberofthreads, precursorStructs[level]->numberOfPointsInBC); + + if(this->outputVariable==OutputVariable::Velocities) + { + fillArrayVelocities<<<grid.grid, grid.threads>>>( precursorStructs[level]->numberOfPointsInBC, precursorStructs[level]->indicesD, + precursorStructs[level]->bufferD, + para->getParD(level)->velocityX, para->getParD(level)->velocityY, para->getParD(level)->velocityZ, + para->getVelocityRatio()); + getLastCudaError("In PrecursorWriter::interact fillArrayVelocities execution failed"); + } + else if(this->outputVariable==OutputVariable::Distributions) + { + fillArrayDistributions<<<grid.grid, grid.threads>>>(precursorStructs[level]->numberOfPointsInBC, precursorStructs[level]->indicesD, + precursorStructs[level]->bufferD, + para->getParD(level)->distributions.f[0], + para->getParD(level)->neighborX, para->getParD(level)->neighborY, para->getParD(level)->neighborZ, + para->getEvenOrOdd(level), para->getParD(level)->numberOfNodes); + getLastCudaError("In PrecursorWriter::interact fillArrayDistributions execution failed"); + } + cudaManager->cudaCopyPrecursorWriterOutputVariablesDtoH(this, level); + + // switch device buffer and data pointer so precursor data is gathered in buffer and copied from bufferD to bufferH + real *tmp = precursorStructs[level]->bufferD; + precursorStructs[level]->bufferD = precursorStructs[level]->dataD; + precursorStructs[level]->dataD = tmp; + + precursorStructs[level]->numberOfTimestepsBuffered++; + + if(precursorStructs[level]->numberOfTimestepsBuffered >= precursorStructs[level]->numberOfTimestepsPerFile || t == para->getTimestepEnd()) + { + // switch host buffer and data pointer so precursor data is copied in buffer and written from data + + tmp = precursorStructs[level]->bufferH; + precursorStructs[level]->bufferH = precursorStructs[level]->dataH; + precursorStructs[level]->dataH = tmp; + + writeFuture.wait(); + writeFuture = std::async(std::launch::async, [this](Parameter* para, uint level, uint timesteps){ this->write(para, level, timesteps); }, para, level, precursorStructs[level]->numberOfTimestepsBuffered); + precursorStructs[level]->numberOfTimestepsBuffered = 0; + } + } +} + + +void PrecursorWriter::free(Parameter* para, CudaMemoryManager* cudaManager) +{ + writeFuture.wait(); + for(int level=0; level<=para->getMaxLevel(); level++) + { + if(getPrecursorStruct(level)->numberOfTimestepsBuffered>0) + write(para, level, getPrecursorStruct(level)->numberOfTimestepsBuffered); + + cudaManager->cudaFreePrecursorWriter(this, level); + } +} + + +void PrecursorWriter::write(Parameter* para, int level, uint numberOfTimestepsBuffered) +{ + std::string fname = this->makeFileName(fileName, level, para->getMyProcessID(), precursorStructs[level]->numberOfFilesWritten) + getWriter()->getFileExtension(); + std::string wholeName = outputPath + "/" + fname; + + uint numberOfPointsInData = precursorStructs[level]->numberOfPointsInData; + + int startTime = precursorStructs[level]->numberOfFilesWritten*precursorStructs[level]->numberOfTimestepsPerFile; + + UbTupleInt6 extent = makeUbTuple( val<1>(precursorStructs[level]->extent), val<2>(precursorStructs[level]->extent), + val<3>(precursorStructs[level]->extent), val<4>(precursorStructs[level]->extent), + startTime, startTime+(int)numberOfTimestepsBuffered-1); + + UbTupleFloat3 origin = makeUbTuple( val<1>(precursorStructs[level]->origin), val<2>(precursorStructs[level]->origin), 0.f); + + std::vector<std::vector<double>> nodedata; + + for(uint quant=0; quant<precursorStructs[level]->numberOfQuantities; quant++) + { + std::vector<double> doubleArr(numberOfPointsInData*numberOfTimestepsBuffered, NAN); + for( uint timestep=0; timestep<numberOfTimestepsBuffered; timestep++) + { + for (uint pos=0; pos < precursorStructs[level]->numberOfPointsInBC; pos++) + { + int indexOnPlane = precursorStructs[level]->indicesOnPlane[pos]+timestep*numberOfPointsInData; + doubleArr[indexOnPlane] = double(precursorStructs[level]->dataH[linearIdx(quant, pos, timestep, precursorStructs[level]->numberOfQuantities, precursorStructs[level]->numberOfPointsInBC)]); + } + } + nodedata.push_back(doubleArr); + } + + std::vector<std::vector<double>> celldata; + getWriter()->writeData(wholeName, nodedatanames, celldatanames, nodedata, celldata, extent, origin, precursorStructs[level]->spacing, extent, this->writePrecision); + precursorStructs[level]->numberOfFilesWritten++; +} + +std::string PrecursorWriter::makeFileName(std::string fileName, int level, int id, uint numberOfFilesWritten) +{ + return fileName + "_lev_" + StringUtil::toString<int>(level) + + "_ID_" + StringUtil::toString<int>(id) + + "_File_" + StringUtil::toString<int>(numberOfFilesWritten); +} + +void PrecursorWriter::getTaggedFluidNodes(Parameter *para, GridProvider* gridProvider) +{ + for(uint level=0; level<(uint)para->getMaxLevel(); level++) + { + if(outputVariable==OutputVariable::Velocities) + { + std::vector<uint> indices(precursorStructs[level]->indicesH, precursorStructs[level]->indicesH+precursorStructs[level]->numberOfPointsInBC); + gridProvider->tagFluidNodeIndices(indices, CollisionTemplate::WriteMacroVars, level); + } + } +} \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/PrecursorWriter.h b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/PrecursorWriter.h new file mode 100644 index 0000000000000000000000000000000000000000..3959fb2d8f5e719084d2d55e6f6ef84076383b45 --- /dev/null +++ b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/PrecursorWriter.h @@ -0,0 +1,161 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// This file is part of VirtualFluids. VirtualFluids is free software: you can +// redistribute it and/or modify it under the terms of the GNU General Public +// License as published by the Free Software Foundation, either version 3 of +// the License, or (at your option) any later version. +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. +// +// You should have received a copy of the GNU General Public License along +// with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. +// +//! \file PrecursorWriter.h +//! \author Henry Korb, Henrik Asmuth +//! \date 05/12/2022 +//! \brief Probe writing planes of data to be used as inflow data in successor simulation using PrecursorBC +//! +//! The probe writes out yz-planes at a specifc x position ( \param xPos ) of either velocity or distributions +//! that can be read by PrecursorBC as inflow data. +//======================================================================================= + + +#ifndef PRECURSORPROBE_H_ +#define PRECURSORPROBE_H_ + +#include "PreCollisionInteractor.h" +#include "WbWriterVtkXmlImageBinary.h" +#include "LBM/LB.h" +#include <string> +#include <vector> +#include <future> +#include "PointerDefinitions.h" +#include "Logger.h" + +class Parameter; +class CudaMemoryManager; +class GridProvider; + +enum class OutputVariable { + //! - Velocities + Velocities, + //! - Distributions + Distributions +}; + +static constexpr uint PrecP00 = 0; +static constexpr uint PrecPP0 = 1; +static constexpr uint PrecPM0 = 2; +static constexpr uint PrecP0P = 3; +static constexpr uint PrecP0M = 4; +static constexpr uint PrecPPP = 5; +static constexpr uint PrecPMP = 6; +static constexpr uint PrecPPM = 7; +static constexpr uint PrecPMM = 8; + +struct PrecursorStruct +{ + uint numberOfPointsInBC, numberOfPointsInData, numberOfTimestepsPerFile, numberOfFilesWritten, numberOfTimestepsBuffered; + uint *indicesH, *indicesD; + real *dataH, *dataD; + real *bufferH, *bufferD; + uint numberOfQuantities; + UbTupleInt4 extent; + UbTupleFloat2 origin; + UbTupleFloat3 spacing; + int* indicesOnPlane; + cudaStream_t stream; +}; + +class PrecursorWriter : public PreCollisionInteractor +{ +public: + PrecursorWriter( + const std::string _fileName, + const std::string _outputPath, + real _xPos, + real _yMin, real _yMax, + real _zMin, real _zMax, + uint _tStartOut, + uint _tSave, + OutputVariable _outputVariable, + uint _maxTimestepsPerFile=uint(1e4) + ): + fileName(_fileName), + outputPath(_outputPath), + xPos(_xPos), + yMin(_yMin), + yMax(_yMax), + zMin(_zMin), + zMax(_zMax), + tStartOut(_tStartOut), + tSave(_tSave), + outputVariable(_outputVariable), + maxtimestepsPerFile(_maxTimestepsPerFile) + { + nodedatanames = determineNodeDataNames(); + writeFuture = std::async([](){}); + }; + + void init(Parameter* para, GridProvider* gridProvider, CudaMemoryManager* cudaManager) override; + void interact(Parameter* para, CudaMemoryManager* cudaManager, int level, uint t) override; + void free(Parameter* para, CudaMemoryManager* cudaManager) override; + void getTaggedFluidNodes(Parameter *para, GridProvider* gridProvider) override; + + OutputVariable getOutputVariable(){ return this->outputVariable; } + + SPtr<PrecursorStruct> getPrecursorStruct(int level){return precursorStructs[level];} + static std::string makeFileName(std::string fileName, int level, int id, uint part); + + void setWritePrecision(uint _writePrecision){ this->writePrecision=_writePrecision;} + +private: + WbWriterVtkXmlImageBinary* getWriter(){ return WbWriterVtkXmlImageBinary::getInstance(); }; + void write(Parameter* para, int level, uint numberOfTimestepsBuffered); + + std::vector<std::string> determineNodeDataNames() + { + switch (outputVariable) + { + case OutputVariable::Velocities: + return {"vx", "vy", "vz"}; + break; + case OutputVariable::Distributions: + return {"fP00", "fPP0", "fPM0", "fP0P", "fP0M", "fPPP", "fPMP", "fPPM", "fPMM"}; + break; + + default: + throw std::runtime_error("Invalid OutputVariable for PrecursorWriter"); + break; + } + } + +private: + std::vector<SPtr<PrecursorStruct>> precursorStructs; + std::string fileName, outputPath; + std::vector<std::string> nodedatanames; + std::vector<std::string> celldatanames; + uint tStartOut, tSave, maxtimestepsPerFile; + real xPos, yMin, yMax, zMin, zMax; + OutputVariable outputVariable; + std::future<void> writeFuture; + uint writePrecision = 8; +}; + +#endif //PRECURSORPROBE_H_ \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PlanarAverageProbe.cu b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PlanarAverageProbe.cu index f5b520acfad74f6787e9e657fce3ccdceed9d539..4f4affd9fffdfd2d7a91a14051ff49b354473b6a 100644 --- a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PlanarAverageProbe.cu +++ b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PlanarAverageProbe.cu @@ -15,6 +15,7 @@ #include "Parameter/Parameter.h" #include "DataStructureInitializer/GridProvider.h" #include "GPU/CudaMemoryManager.h" +#include "GPU/GPU_Interface.h" #include <algorithm> @@ -268,6 +269,15 @@ void PlanarAverageProbe::findPoints(Parameter* para, GridProvider* gridProvider, void PlanarAverageProbe::calculateQuantities(SPtr<ProbeStruct> probeStruct, Parameter* para, uint t_level, int level) { + // Compute macroscopic variables in entire domain + CalcMacCompSP27(para->getParD(level)->velocityX, para->getParD(level)->velocityY, para->getParD(level)->velocityZ, + para->getParD(level)->rho, para->getParD(level)->pressure, para->getParD(level)->typeOfGridNode, + para->getParD(level)->neighborX, para->getParD(level)->neighborY, + para->getParD(level)->neighborZ, para->getParD(level)->numberOfNodes, + para->getParD(level)->numberofthreads, para->getParD(level)->distributions.f[0], + para->getParD(level)->isEvenTimestep); + getLastCudaError("In PlanarAverageProbe Kernel CalcMacSP27 execution failed"); + // Definition of normal and inplane directions for moveIndices kernels uint *neighborNormal, *neighborInplane1, *neighborInplane2; if( this->planeNormal == 'x' ) diff --git a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PlanarAverageProbe.h b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PlanarAverageProbe.h index d11f8e76e4d13113b201af5494b7d0cfcfe18353..3d3533f74501e776f9150c83c9d9101a0be7ecbc 100644 --- a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PlanarAverageProbe.h +++ b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PlanarAverageProbe.h @@ -74,6 +74,7 @@ public: planeNormal(_planeNormal) { + if (_tStartTmpAvg<_tStartAvg) throw std::runtime_error("Probe: tStartTmpAvg must be larger than tStartAvg!"); if(!(_planeNormal == 'x' || _planeNormal == 'y' || _planeNormal == 'z')) throw std::runtime_error("PlanarAverageProbe: planeNormal must be 'x', 'y' or 'z'!"); } diff --git a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PlaneProbe.cu b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PlaneProbe.cu index 7d1c0205219737e4b28acbb1a893a0a6071ae9de..8e0bf1faf87a251d41f1b5deeda698c75d9706c6 100644 --- a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PlaneProbe.cu +++ b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PlaneProbe.cu @@ -106,4 +106,14 @@ void PlaneProbe::calculateQuantities(SPtr<ProbeStruct> probeStruct, Parameter* p para->getParD(level)->velocityX, para->getParD(level)->velocityY, para->getParD(level)->velocityZ, para->getParD(level)->rho, para->getParD(level)->neighborX, para->getParD(level)->neighborY, para->getParD(level)->neighborZ, probeStruct->quantitiesD, probeStruct->arrayOffsetsD, probeStruct->quantitiesArrayD); +} + +void PlaneProbe::getTaggedFluidNodes(Parameter *para, GridProvider* gridProvider) +{ + for(int level=0; level<=para->getMaxLevel(); level++) + { + SPtr<ProbeStruct> probeStruct = this->getProbeStruct(level); + std::vector<uint> probeIndices( probeStruct->pointIndicesH, probeStruct->pointIndicesH+probeStruct->nIndices); + gridProvider->tagFluidNodeIndices( probeIndices, CollisionTemplate::WriteMacroVars, level); + } } \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PlaneProbe.h b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PlaneProbe.h index 3440c01020f9b3505be7148024e47373b76648ff..180169707a6d7f3f7975f6a2bc4009f7c0aba527 100644 --- a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PlaneProbe.h +++ b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PlaneProbe.h @@ -54,7 +54,7 @@ public: ): Probe(_probeName, _outputPath, _tStartAvg, - 0, + _tStartAvg+1, _tAvg, _tStartOut, _tOut, @@ -72,6 +72,8 @@ public: this->deltaZ = _deltaZ; } + void getTaggedFluidNodes(Parameter *para, GridProvider* gridProvider) override; + private: bool isAvailableStatistic(Statistic _variable) override; diff --git a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PointProbe.cu b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PointProbe.cu index e78a98f02ac2093fc46b4daa4a2485ed1395275b..37beeed05e498028356cd89b416e5269c070de81 100644 --- a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PointProbe.cu +++ b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PointProbe.cu @@ -140,4 +140,14 @@ void PointProbe::addProbePointsFromXNormalPlane(real pos_x, real pos0_y, real po } printf("Added %u points \n", n_y*n_z); +} + +void PointProbe::getTaggedFluidNodes(Parameter *para, GridProvider* gridProvider) +{ + for(int level=0; level<=para->getMaxLevel(); level++) + { + SPtr<ProbeStruct> probeStruct = this->getProbeStruct(level); + std::vector<uint> probeIndices( probeStruct->pointIndicesH, probeStruct->pointIndicesH+probeStruct->nIndices); + gridProvider->tagFluidNodeIndices( probeIndices, CollisionTemplate::WriteMacroVars, level); + } } \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PointProbe.h b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PointProbe.h index 6a6fbe76f089acfafc22672dd3e9d71bd193a3b3..08c359705f03b20fbd3276fe209b6ff4d782a5e5 100644 --- a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PointProbe.h +++ b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/PointProbe.h @@ -64,6 +64,7 @@ public: void addProbePointsFromList(std::vector<real>& _pointCoordsX, std::vector<real>& _pointCoordsY, std::vector<real>& _pointCoordsZ); void addProbePointsFromXNormalPlane(real pos_x, real pos0_y, real pos0_z, real pos1_y, real pos1_z, uint n_y, uint n_z); + void getTaggedFluidNodes(Parameter *para, GridProvider* gridProvider) override; private: bool isAvailableStatistic(Statistic _variable) override; diff --git a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/Probe.cu b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/Probe.cu index cc027b07bded01455437e65e08ccdcd51bcf7dc0..03c18f5a9a2133bec244053113209abc70469a2a 100644 --- a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/Probe.cu +++ b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/Probe.cu @@ -187,7 +187,7 @@ void Probe::init(Parameter* para, GridProvider* gridProvider, CudaMemoryManager* this->velocityRatio = std::bind(&Parameter::getScaledVelocityRatio, para, _1); this->densityRatio = std::bind(&Parameter::getScaledDensityRatio, para, _1); this->forceRatio = std::bind(&Parameter::getScaledForceRatio, para, _1); - this->stressRatio = std::bind(&Parameter::getScaledPressureRatio, para, _1); + this->stressRatio = std::bind(&Parameter::getScaledStressRatio, para, _1); this->viscosityRatio = std::bind(&Parameter::getScaledViscosityRatio, para, _1); this->nondimensional = std::bind(&Probe::getNondimensionalConversionFactor, this, _1); @@ -315,6 +315,12 @@ void Probe::free(Parameter* para, CudaMemoryManager* cudaMemoryManager) } } +void Probe::getTaggedFluidNodes(Parameter *para, GridProvider* gridProvider) +{ + // Do nothing +}; + + void Probe::addStatistic(Statistic variable) { if (!this->isAvailableStatistic(variable)) throw std::runtime_error("Probe::addStatistic(): Statistic not available for this probe type!"); @@ -329,6 +335,22 @@ void Probe::addStatistic(Statistic variable) } } +std::string Probe::makeParallelFileName(int id, int t) +{ + return this->probeName + "_bin_ID_" + StringUtil::toString<int>(id) + + "_t_" + StringUtil::toString<int>(t) + + ".vtk"; +} + +std::string Probe::makeGridFileName(int level, int id, int t, uint part) +{ + return this->probeName + "_bin_lev_" + StringUtil::toString<int>(level) + + "_ID_" + StringUtil::toString<int>(id) + + "_Part_" + StringUtil::toString<int>(part) + + "_t_" + StringUtil::toString<int>(t) + + ".vtk"; +} + void Probe::addAllAvailableStatistics() { for( int var=0; var < int(Statistic::LAST); var++) @@ -347,119 +369,76 @@ void Probe::write(Parameter* para, int level, int t) std::vector<std::string> fnames; for (uint i = 1; i <= numberOfParts; i++) { - std::string fname = this->probeName + "_bin_lev_" + StringUtil::toString<int>(level) - + "_ID_" + StringUtil::toString<int>(para->getMyProcessID()) - + "_Part_" + StringUtil::toString<int>(i); - if(!this->outputTimeSeries) fname += "_t_" + StringUtil::toString<int>(t_write); - fname += ".vtk"; - fnames.push_back(fname); - this->fileNamesForCollectionFile.push_back(fname); + this->writeGridFile(para, level, t_write, i); } - this->writeGridFiles(para, level, fnames, t); - - if(level == 0 && !this->outputTimeSeries) this->writeCollectionFile(para, t); + if(level == 0&& !this->outputTimeSeries) this->writeParallelFile(para, t); } -void Probe::writeCollectionFile(Parameter* para, int t) +void Probe::writeParallelFile(Parameter* para, int t) { int t_write = this->fileNameLU ? t: t/this->tOut; - std::string filename = this->probeName + "_bin_ID_" + StringUtil::toString<int>(para->getMyProcessID()) - + "_t_" + StringUtil::toString<int>(t_write) - + ".vtk"; - - std::ofstream file; - - file.open(this->outputPath + "/" + filename + ".pvtu" ); - - ////////////////////////////////////////////////////////////////////////// - - file << "<VTKFile type=\"PUnstructuredGrid\" version=\"1.0\" byte_order=\"LittleEndian\" header_type=\"UInt64\">" << std::endl; - file << " <PUnstructuredGrid GhostLevel=\"1\">" << std::endl; - - file << " <PPointData>" << std::endl; - - for(std::string varName: this->getVarNames()) //TODO - { - file << " <DataArray type=\"Float64\" Name=\""<< varName << "\" /> " << std::endl; - } - file << " </PPointData>" << std::endl; - - file << " <PPoints>" << std::endl; - file << " <PDataArray type=\"Float32\" Name=\"Points\" NumberOfComponents=\"3\"/>" << std::endl; - file << " </PPoints>" << std::endl; - - for( auto& fname : this->fileNamesForCollectionFile ) - { - const auto filenameWithoutPath=fname.substr( fname.find_last_of('/') + 1 ); - file << " <Piece Source=\"" << filenameWithoutPath << ".bin.vtu\"/>" << std::endl; - } - - file << " </PUnstructuredGrid>" << std::endl; - file << "</VTKFile>" << std::endl; + std::string filename = this->outputPath + "/" + this->makeParallelFileName(para->getMyProcessID(), t_write); - ////////////////////////////////////////////////////////////////////////// + std::vector<std::string> nodedatanames = this->getVarNames(); + std::vector<std::string> cellNames; - file.close(); + getWriter()->writeParallelFile(filename, fileNamesForCollectionFile, nodedatanames, cellNames); this->fileNamesForCollectionFile.clear(); } -void Probe::writeGridFiles(Parameter* para, int level, std::vector<std::string>& fnames, int t) +void Probe::writeGridFile(Parameter* para, int level, int t, uint part) { + std::string fname = this->outputPath + "/" + this->makeGridFileName(level, para->getMyProcessID(), t, part); + std::vector< UbTupleFloat3 > nodes; std::vector< std::string > nodedatanames = this->getVarNames(); - uint startpos = 0; - uint endpos = 0; - uint sizeOfNodes = 0; std::vector< std::vector< double > > nodedata(nodedatanames.size()); SPtr<ProbeStruct> probeStruct = this->getProbeStruct(level); - for (uint part = 0; part < fnames.size(); part++) - { - startpos = part * para->getlimitOfNodesForVTK(); - uint nDataPoints = this->outputTimeSeries? this->tProbe: probeStruct->nPoints; - sizeOfNodes = min(para->getlimitOfNodesForVTK(), nDataPoints - startpos); - endpos = startpos + sizeOfNodes; + uint startpos = (part-1) * para->getlimitOfNodesForVTK(); + uint sizeOfNodes = min(para->getlimitOfNodesForVTK(), probeStruct->nPoints - startpos); + uint endpos = startpos + sizeOfNodes; - ////////////////////////////////////////////////////////////////////////// - nodes.resize(sizeOfNodes); + ////////////////////////////////////////////////////////////////////////// + nodes.resize(sizeOfNodes); - for (uint pos = startpos; pos < endpos; pos++) - { - nodes[pos-startpos] = makeUbTuple( float(probeStruct->pointCoordsX[pos]), - float(probeStruct->pointCoordsY[pos]), - float(probeStruct->pointCoordsZ[pos])); - } + for (uint pos = startpos; pos < endpos; pos++) + { + nodes[pos-startpos] = makeUbTuple( float(probeStruct->pointCoordsX[pos]), + float(probeStruct->pointCoordsY[pos]), + float(probeStruct->pointCoordsZ[pos])); + } - for( auto it=nodedata.begin(); it!=nodedata.end(); it++) it->resize(sizeOfNodes); + for( auto it=nodedata.begin(); it!=nodedata.end(); it++) it->resize(sizeOfNodes); - for( int var=0; var < int(Statistic::LAST); var++){ - if(this->quantities[var]) - { - Statistic statistic = static_cast<Statistic>(var); - real coeff; + for( int var=0; var < int(Statistic::LAST); var++){ + if(this->quantities[var]) + { + Statistic statistic = static_cast<Statistic>(var); + real coeff; - std::vector<PostProcessingVariable> postProcessingVariables = this->getPostProcessingVariables(statistic); - uint n_arrs = uint(postProcessingVariables.size()); + std::vector<PostProcessingVariable> postProcessingVariables = this->getPostProcessingVariables(statistic); + uint n_arrs = uint(postProcessingVariables.size()); - uint arrOff = probeStruct->arrayOffsetsH[var]; - uint arrLen = probeStruct->nPoints; + uint arrOff = probeStruct->arrayOffsetsH[var]; + uint arrLen = probeStruct->nPoints; + + for(uint arr=0; arr<n_arrs; arr++) + { + coeff = postProcessingVariables[arr].conversionFactor(level); - for(uint arr=0; arr<n_arrs; arr++) + for (uint pos = startpos; pos < endpos; pos++) { - coeff = postProcessingVariables[arr].conversionFactor(level); - - for (uint pos = startpos; pos < endpos; pos++) - { - nodedata[arrOff+arr][pos-startpos] = double(probeStruct->quantitiesArrayH[(arrOff+arr)*arrLen+pos]*coeff); - } + nodedata[arrOff+arr][pos-startpos] = double(probeStruct->quantitiesArrayH[(arrOff+arr)*arrLen+pos]*coeff); } } } - WbWriterVtkXmlBinary::getInstance()->writeNodesWithNodeData(this->outputPath + "/" + fnames[part], nodes, nodedatanames, nodedata); } + std::string fullName = getWriter()->writeNodesWithNodeData(fname, nodes, nodedatanames, nodedata); + this->fileNamesForCollectionFile.push_back(fullName.substr(fullName.find_last_of('/') + 1)); } std::vector<std::string> Probe::getVarNames() diff --git a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/Probe.h b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/Probe.h index 9cb0bd43e27fb7a28cae9c363ce245fbd9cc5677..aaf294e87d23c64707a16692b9337d6e9ff9c896 100644 --- a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/Probe.h +++ b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/Probe.h @@ -49,6 +49,7 @@ #include "PreCollisionInteractor/PreCollisionInteractor.h" #include "PointerDefinitions.h" +#include "WbWriterVtkXmlBinary.h" //======================================================================================= //! \note How to add new Statistics @@ -153,12 +154,12 @@ public: PreCollisionInteractor() { if (_tStartOut<_tStartAvg) throw std::runtime_error("Probe: tStartOut must be larger than tStartAvg!"); - if (_tStartTmpAvg<_tStartAvg) throw std::runtime_error("Probe: tStartTmpAvg must be larger than tStartAvg!"); } void init(Parameter* para, GridProvider* gridProvider, CudaMemoryManager* cudaMemoryManager) override; void interact(Parameter* para, CudaMemoryManager* cudaMemoryManager, int level, uint t) override; void free(Parameter* para, CudaMemoryManager* cudaMemoryManager) override; + virtual void getTaggedFluidNodes(Parameter *para, GridProvider* gridProvider) override; SPtr<ProbeStruct> getProbeStruct(int level){ return this->probeParams[level]; } @@ -171,6 +172,8 @@ public: void setFileNameToNOut(){this->fileNameLU = false;} void setTStartTmpAveraging(uint _tStartTmpAveraging){this->tStartTmpAveraging = _tStartTmpAveraging;} +protected: + virtual WbWriterVtkXmlBinary* getWriter(){ return WbWriterVtkXmlBinary::getInstance(); }; real getNondimensionalConversionFactor(int level); private: @@ -188,12 +191,15 @@ private: int level); virtual void calculateQuantities(SPtr<ProbeStruct> probeStruct, Parameter* para, uint t, int level) = 0; - void write(Parameter* para, int level, int t); - void writeCollectionFile(Parameter* para, int t); - void writeGridFiles(Parameter* para, int level, std::vector<std::string >& fnames, int t); + virtual void write(Parameter* para, int level, int t); + virtual void writeParallelFile(Parameter* para, int t); + virtual void writeGridFile(Parameter* para, int level, int t, uint part); + std::vector<std::string> getVarNames(); - -private: + std::string makeGridFileName(int level, int id, int t, uint part); + std::string makeParallelFileName(int id, int t); + +protected: const std::string probeName; const std::string outputPath; @@ -202,7 +208,6 @@ private: bool hasDeviceQuantityArray; //!> flag initiating memCopy in Point and PlaneProbe. Other probes are only based on thrust reduce functions and therefore dont need explict memCopy in interact() bool outputTimeSeries; //!> flag initiating overwrite of output vtk files, skipping collection files and limiting the length of the written data to the current time step (currently only used for WallModelProbe) std::vector<std::string> fileNamesForCollectionFile; - std::vector<std::string> varNames; bool fileNameLU = true; //!> if true, written file name contains time step in LU, else is the number of the written probe files @@ -215,7 +220,6 @@ protected: uint tProbe = 0; //!> counter for number of probe evaluations. Only used when outputting timeseries - std::function<real(int)> velocityRatio; std::function<real(int)> densityRatio; std::function<real(int)> forceRatio; diff --git a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/WallModelProbe.h b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/WallModelProbe.h index d6464c5ca2aa60310cc6bb7ca0a210bc12e755ff..4ea90f74c7a0d57af4995e1b5874234967f1e901 100644 --- a/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/WallModelProbe.h +++ b/src/gpu/VirtualFluids_GPU/PreCollisionInteractor/Probes/WallModelProbe.h @@ -55,14 +55,17 @@ public: uint _tStartOut, uint _tOut ): Probe(_probeName, - _outputPath, - _tStartAvg, - _tStartTmpAvg, - _tAvg, - _tStartOut, - _tOut, - false, - true){} + _outputPath, + _tStartAvg, + _tStartTmpAvg, + _tAvg, + _tStartOut, + _tOut, + false, + true) + { + if (_tStartTmpAvg<_tStartAvg) throw std::runtime_error("Probe: tStartTmpAvg must be larger than tStartAvg!"); + } void setForceOutputToStress(bool _outputStress){ this->outputStress = _outputStress; } diff --git a/src/lbm/constants/NumericConstants.h b/src/lbm/constants/NumericConstants.h index 4918d49aaa0431de639ea8ba3320c4fa45e539d4..b61e994e726e0b5cd85d8130bd6548ccebdc27f6 100644 --- a/src/lbm/constants/NumericConstants.h +++ b/src/lbm/constants/NumericConstants.h @@ -18,6 +18,7 @@ static constexpr double c1o8 = 0.125; static constexpr double c1o9 = 0.111111111111111; static constexpr double c2o9 = 0.222222222222222; static constexpr double c4o9 = 0.444444444444444; +static constexpr double c4o10 = 0.4; static constexpr double c1o10 = 0.1; static constexpr double c1o12 = 0.083333333333333; static constexpr double c1o16 = 0.0625; @@ -48,6 +49,7 @@ static constexpr double c99o100 = 0.99; static constexpr double c1o126 = 0.007936507936508; static constexpr double c1o216 = 0.004629629629630; static constexpr double c5o4 = 1.25; +static constexpr double c4o3 = 1.333333333333333; static constexpr double c9o4 = 2.25; static constexpr double c5o2 = 2.5; static constexpr double c9o2 = 4.5; @@ -99,15 +101,15 @@ static constexpr double c72o1 = 72.; static constexpr double c84o1 = 84.; static constexpr double c88o1 = 88.; static constexpr double c96o1 = 96.; -static constexpr double c100o1 = 10.; -static constexpr double c130o1 = 13.; -static constexpr double c152o1 = 15.; -static constexpr double c166o1 = 16.; -static constexpr double c195o1 = 19.; -static constexpr double c216o1 = 21.; -static constexpr double c264o1 = 26.; -static constexpr double c290o1 = 29.; -static constexpr double c367o1 = 36.; +static constexpr double c100o1 = 100.; +static constexpr double c130o1 = 130.; +static constexpr double c152o1 = 152.; +static constexpr double c166o1 = 166.; +static constexpr double c195o1 = 195.; +static constexpr double c216o1 = 216.; +static constexpr double c264o1 = 264.; +static constexpr double c290o1 = 290.; +static constexpr double c367o1 = 367.; static constexpr double Op0000002 = 0.0000002; static constexpr double c10eM30 = 1e-30; @@ -132,6 +134,7 @@ static constexpr float c1o8 = 0.125f; static constexpr float c1o9 = (1.0f / 9.0f); static constexpr float c2o9 = (2.0f / 9.0f); static constexpr float c4o9 = (4.0f / 9.0f); +static constexpr float c4o10 = 0.4f; static constexpr float c1o10 = 0.1f; static constexpr float c1o12 = (1.0f / 12.0f); static constexpr float c1o16 = 0.0625f; @@ -162,6 +165,7 @@ static constexpr float c99o100 = 0.99f; static constexpr float c1o126 = (1.0f / 126.0f); static constexpr float c1o216 = (1.0f / 216.0f); static constexpr float c5o4 = 1.25f; +static constexpr float c4o3 = (4.0f / 3.0f); static constexpr float c9o4 = 2.25f; static constexpr float c5o2 = 2.5f; static constexpr float c9o2 = 4.5f; diff --git a/utilities/setup_builder.py b/utilities/setup_builder.py new file mode 100644 index 0000000000000000000000000000000000000000..94e4f805b3e05024742ead72e3ffb28c477c282f --- /dev/null +++ b/utilities/setup_builder.py @@ -0,0 +1,34 @@ +from setuptools import build_meta + +class builder(build_meta._BuildMetaBackend): + + def run_setup(self, setup_script='setup.py'): + # Note that we can reuse our build directory between calls + # Correctness comes first, then optimization later + __file__ = setup_script + __name__ = '__main__' + + with build_meta._open_setup_script(__file__) as f: + code = f.read().replace(r'\r\n', r'\n') + args = locals() + args["config_args"] = self.extra_args + exec(code, args) + + + def add_settings(self, config_settings): + self.extra_args = dict() + if config_settings: + self.extra_args = config_settings + + def build_wheel(self, wheel_directory, config_settings=None, + metadata_directory=None): + self.add_settings(config_settings) + return super().build_wheel(wheel_directory, config_settings, metadata_directory) + + def build_sdist(self, sdist_directory, config_settings=None): + self.add_settings(config_settings) + return super().build_wheel(sdist_directory, config_settings) + +build = builder() +build_wheel = build.build_wheel +build_sdist = build.build_sdist \ No newline at end of file