diff --git a/.gitignore b/.gitignore index 82c6dcbe5cfa0e301cfcbb934b3e5c4783e3b545..8708a2906743e7953fd79b8277927031b1f6a32d 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,7 @@ __pycache__/ # Simulation results output/ +logs/ # MacOS .DS_Store diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8ad5c98d9458e66f66a0e905dc045713d3d7521d..d2423ba9dc39c9d935c1d16b971396ce7d11e789 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -51,7 +51,7 @@ stages: - cd $CI_PROJECT_DIR/$BUILD_FOLDER - rm -r -f ./* - cmake .. -LAH - --preset=all_make_ccache + --preset=all_make -DBUILD_WARNINGS_AS_ERRORS=ON -DCMAKE_CUDA_ARCHITECTURES=60 - make -j4 @@ -301,7 +301,7 @@ gpu_numerical_tests: - cd $CI_PROJECT_DIR/build - rm -r -f ./* - cmake .. - --preset=gpu_numerical_tests_ccache_make + --preset=gpu_numerical_tests_make -DCMAKE_CUDA_ARCHITECTURES=60 -DPATH_NUMERICAL_TESTS=/tmp/test_data/numerical_tests_gpu - make -j4 diff --git a/CMake/Cache.cmake b/CMake/Cache.cmake new file mode 100644 index 0000000000000000000000000000000000000000..23f5e83e17b67802b4886cd76b468127047f230c --- /dev/null +++ b/CMake/Cache.cmake @@ -0,0 +1,31 @@ +option(ENABLE_CACHE "Enable cache if available" ON) +if(NOT ENABLE_CACHE) + return() +endif() + +set(CACHE_OPTION + "ccache" + CACHE STRING "Compiler cache to be used") +set(CACHE_OPTION_VALUES "ccache" "sccache") +set_property(CACHE CACHE_OPTION PROPERTY STRINGS ${CACHE_OPTION_VALUES}) +list( + FIND + CACHE_OPTION_VALUES + ${CACHE_OPTION} + CACHE_OPTION_INDEX) + +if(${CACHE_OPTION_INDEX} EQUAL -1) + message( + STATUS + "Using custom compiler cache system: '${CACHE_OPTION}', explicitly supported entries are ${CACHE_OPTION_VALUES}") +endif() + +find_program(CACHE_BINARY ${CACHE_OPTION}) +if(CACHE_BINARY) + message(STATUS "${CACHE_OPTION} found and enabled") + set(CMAKE_CXX_COMPILER_LAUNCHER ${CACHE_BINARY}) + set(CMAKE_CUDA_COMPILER_LAUNCHER ${CACHE_BINARY}) + set(CMAKE_C_COMPILER_LAUNCHER ${CACHE_BINARY}) +else() + message(WARNING "${CACHE_OPTION} is enabled but was not found. Not using it") +endif() diff --git a/CMake/CompilerWarnings.cmake b/CMake/CompilerWarnings.cmake new file mode 100644 index 0000000000000000000000000000000000000000..eafc2f7a85068ab66d9e113848e94c4a2569bdff --- /dev/null +++ b/CMake/CompilerWarnings.cmake @@ -0,0 +1,77 @@ +# from here: +# +# https://github.com/lefticus/cppbestpractices/blob/master/02-Use_the_Tools_Available.md + +function(set_project_warnings project_name) + + set(MSVC_WARNINGS + /W4 # Baseline reasonable warnings + /w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data + /w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data + /w14263 # 'function': member function does not override any base class virtual member function + /w14265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may not + # be destructed correctly + /w14287 # 'operator': unsigned/negative constant mismatch + /we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is used outside + # the for-loop scope + /w14296 # 'operator': expression is always 'boolean_value' + /w14311 # 'variable': pointer truncation from 'type1' to 'type2' + /w14545 # expression before comma evaluates to a function which is missing an argument list + /w14546 # function call before comma missing argument list + /w14547 # 'operator': operator before comma has no effect; expected operator with side-effect + /w14549 # 'operator': operator before comma has no effect; did you intend 'operator'? + /w14555 # expression has no effect; expected expression with side- effect + /w14619 # pragma warning: there is no warning number 'number' + /w14640 # Enable warning on thread un-safe static member initialization + /w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may cause unexpected runtime behavior. + /w14905 # wide string literal cast to 'LPSTR' + /w14906 # string literal cast to 'LPWSTR' + /w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied + /permissive- # standards conformance mode for MSVC compiler. + ) + + set(CLANG_WARNINGS + -Wall + -Wextra # reasonable and standard + -Wshadow # warn the user if a variable declaration shadows one from a parent context + -Wnon-virtual-dtor # warn the user if a class with virtual functions has a non-virtual destructor. This helps + # catch hard to track down memory errors + -Wold-style-cast # warn for c-style casts + -Wcast-align # warn for potential performance problem casts + -Wunused # warn on anything being unused + -Woverloaded-virtual # warn if you overload (not override) a virtual function + -Wpedantic # warn if non-standard C++ is used + -Wconversion # warn on type conversions that may lose data + -Wsign-conversion # warn on sign conversions + -Wnull-dereference # warn if a null dereference is detected + -Wdouble-promotion # warn if float is implicit promoted to double + -Wformat=2 # warn on security issues around functions that format output (ie printf) + ) + + if(BUILD_WARNINGS_AS_ERRORS) + set(CLANG_WARNINGS ${CLANG_WARNINGS} -Werror) + set(MSVC_WARNINGS ${MSVC_WARNINGS} /WX) + endif() + + set(GCC_WARNINGS + ${CLANG_WARNINGS} + -Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist + -Wduplicated-cond # warn if if / else chain has duplicated conditions + -Wduplicated-branches # warn if if / else branches have duplicated code + -Wlogical-op # warn about logical operations being used where bitwise were probably wanted + -Wuseless-cast # warn if you perform a cast to the same type + ) + + if(MSVC) + set(PROJECT_WARNINGS ${MSVC_WARNINGS}) + elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") + set(PROJECT_WARNINGS ${CLANG_WARNINGS}) + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(PROJECT_WARNINGS ${GCC_WARNINGS}) + else() + message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.") + endif() + + target_compile_options(${project_name} INTERFACE ${PROJECT_WARNINGS}) + +endfunction() diff --git a/CMake/Sanitizers.cmake b/CMake/Sanitizers.cmake new file mode 100644 index 0000000000000000000000000000000000000000..6f16207fefbc2f9ca72f065950b242a4333d442e --- /dev/null +++ b/CMake/Sanitizers.cmake @@ -0,0 +1,60 @@ +function(enable_sanitizers project_name) + + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") + + set(SANITIZERS "") + + option(ENABLE_SANITIZER_ADDRESS "Enable address sanitizer" FALSE) + if(ENABLE_SANITIZER_ADDRESS) + list(APPEND SANITIZERS "address") + endif() + + option(ENABLE_SANITIZER_LEAK "Enable leak sanitizer" FALSE) + if(ENABLE_SANITIZER_LEAK) + list(APPEND SANITIZERS "leak") + endif() + + option(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR "Enable undefined behavior sanitizer" FALSE) + if(ENABLE_SANITIZER_UNDEFINED_BEHAVIOR) + list(APPEND SANITIZERS "undefined") + endif() + + option(ENABLE_SANITIZER_THREAD "Enable thread sanitizer" FALSE) + if(ENABLE_SANITIZER_THREAD) + if("address" IN_LIST SANITIZERS OR "leak" IN_LIST SANITIZERS) + message(WARNING "Thread sanitizer does not work with Address and Leak sanitizer enabled") + else() + list(APPEND SANITIZERS "thread") + endif() + endif() + + option(ENABLE_SANITIZER_MEMORY "Enable memory sanitizer" FALSE) + if(ENABLE_SANITIZER_MEMORY AND CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") + if("address" IN_LIST SANITIZERS + OR "thread" IN_LIST SANITIZERS + OR "leak" IN_LIST SANITIZERS) + message(WARNING "Memory sanitizer does not work with Address, Thread and Leak sanitizer enabled") + else() + list(APPEND SANITIZERS "memory") + endif() + endif() + + list( + JOIN + SANITIZERS + "," + LIST_OF_SANITIZERS) + + endif() + + if(LIST_OF_SANITIZERS) + if(NOT + "${LIST_OF_SANITIZERS}" + STREQUAL + "") + target_compile_options(${project_name} INTERFACE -fsanitize=${LIST_OF_SANITIZERS}) + target_link_options(${project_name} INTERFACE -fsanitize=${LIST_OF_SANITIZERS}) + endif() + endif() + +endfunction() diff --git a/CMake/VirtualFluidsMacros.cmake b/CMake/VirtualFluidsMacros.cmake index 2c2bc1d650e5e2c402f34a1a2547b9fa6f5e063b..fbe0d9404e6c923bfb866e7d8dea7844b51ae17a 100644 --- a/CMake/VirtualFluidsMacros.cmake +++ b/CMake/VirtualFluidsMacros.cmake @@ -21,6 +21,7 @@ endfunction() include(${VF_CMAKE_DIR}/CMakeSetCompilerFlags.cmake) include(${VF_CMAKE_DIR}/FileUtilities.cmake) include(${VF_CMAKE_DIR}/3rd.cmake) +include(${VF_CMAKE_DIR}/Sanitizers.cmake) ############################################################################################################### # Reset the compiler and linker flags @@ -152,6 +153,9 @@ function(vf_add_library) ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" PDB_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") + # sanitizers + enable_sanitizers(${library_name}) + # link time optimization if(BUILD_VF_LTO) if(NOT ${ARG_BUILDTYPE} MATCHES binary) diff --git a/CMakeLists.txt b/CMakeLists.txt index 140f2b0b9da1fb15bacab931ca01da5dd7e2e21d..7796c73f8c493fa772971a4a0c36ce9967a87649 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,10 +6,6 @@ # |___/_/_/ \__/\__,_/\__,_/_/_/ /_/\__,_/_/\__,_/____/ # ################################################################################# -# required cmake versions -# CMAKE 3.13: target_link_options -# CMAKE 3.15: CMAKE_MSVC_RUNTIME_LIBRARY -################################################################################# cmake_minimum_required(VERSION 3.15..3.20 FATAL_ERROR) project(VirtualFluids @@ -38,6 +34,11 @@ set (VF_THIRD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdParty) set (VF_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) set (VF_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) + message(FATAL_ERROR "In-source builds are prohibited. " + "Create a new directory and build there.") +endif () + ################################################################################# # OPTIONS ################################################################################# @@ -45,7 +46,7 @@ option(BUILD_VF_CPU "Build VirtualFluids cpu variant" OFF) option(BUILD_VF_GPU "Build VirtualFluids gpu variant" OFF) option(BUILD_USE_OPENMP "Build VirtualFluids with openmp" ON) - +option(BUILD_USE_BOOST "Build VirtualFluids with boost" OFF) # vf gpu option(BUILD_VF_GPU "Build VirtualFluids GPU" ON ) @@ -80,6 +81,15 @@ option(BUILD_VF_DOUBLE_ACCURACY "Use double accuracy" OFF) ################################################################################# # MACROS ################################################################################# +add_library(project_warnings INTERFACE) + +# standard compiler warnings - Link this 'library' to use the warnings specified in CompilerWarnings.cmake +include(${VF_CMAKE_DIR}/CompilerWarnings.cmake) +set_project_warnings(project_warnings) + +# enable cache system +include(${VF_CMAKE_DIR}/Cache.cmake) + include(CMakePrintHelpers) include(${VF_CMAKE_DIR}/VirtualFluidsMacros.cmake) @@ -129,6 +139,21 @@ endif() ################################################################################# # COMMON LIBRARIES ################################################################################# +include(FetchContent) + +set(spdlog_version "v1.9.1") +set(spdlog_url "https://github.com/gabime/spdlog") +message(STATUS "Fetching spdlog: ${spdlog_version}") +FetchContent_Declare( + spdlog + GIT_REPOSITORY ${spdlog_url} + GIT_TAG ${spdlog_version} +) + +FetchContent_MakeAvailable(spdlog) +target_compile_options(spdlog PRIVATE "-fPIC") +groupTarget(spdlog ${thirdFolder}) + if(BUILD_VF_UNIT_TESTS) add_subdirectory(${VF_THIRD_DIR}/googletest) include(GoogleTest) @@ -141,8 +166,23 @@ endif() find_package(MPI REQUIRED) +# boost +IF(BUILD_USE_BOOST) + list(APPEND VF_COMPILER_DEFINITION BUILD_USE_BOOST) + + set(Boost_USE_STATIC_LIBS ON) + set(Boost_USE_MULTITHREADED ON) + set(Boost_USE_STATIC_RUNTIME ON) + # minimum boost version: 1.60 + # no packages specfied - only headeronly libraries + find_package(Boost 1.60 REQUIRED) +ENDIF() + +add_subdirectory(src/logger) add_subdirectory(src/basics) +#add_subdirectory(src/mpi) +#add_subdirectory(src/cuda) add_subdirectory(src/lbm) @@ -154,4 +194,4 @@ if (BUILD_VF_CPU) endif() if(BUILD_VF_GPU) include (gpu.cmake) -endif() \ No newline at end of file +endif() diff --git a/CMakePresets.json b/CMakePresets.json index 663142f01b4076bc66295549a11fb4e3b6701ce0..0f360fd303cdcad923b01d56df5c6d48ad62ca2c 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -2,7 +2,7 @@ "version": 2, "cmakeMinimumRequired": { "major": 3, - "minor": 19, + "minor": 20, "patch": 0 }, "configurePresets": [ @@ -20,16 +20,6 @@ "hidden": true, "generator": "Unix Makefiles" }, - { - "name": "default_ccache_make", - "inherits": "default_make", - "hidden": true, - "cacheVariables": { - "CMAKE_CXX_COMPILER_LAUNCHER": "ccache", - "CMAKE_CUDA_COMPILER_LAUNCHER": "ccache", - "CMAKE_C_COMPILER_LAUNCHER": "ccache" - } - }, { "name": "default_msvc", "inherits": "default", @@ -87,14 +77,6 @@ ], "displayName": "cpu make configuration" }, - { - "name": "cpu_make_ccache", - "inherits": [ - "default_ccache_make", - "default_cpu" - ], - "displayName": "cpu ccache make configuration" - }, { "name": "cpu_msvc", "inherits": [ @@ -111,14 +93,6 @@ ], "displayName": "gpu make configuration" }, - { - "name": "gpu_make_ccache", - "inherits": [ - "default_ccache_make", - "default_gpu" - ], - "displayName": "gpu ccache make configuration" - }, { "name": "gpu_msvc", "inherits": [ @@ -135,14 +109,6 @@ ], "displayName": "all make configuration" }, - { - "name": "all_make_ccache", - "inherits": [ - "default_ccache_make", - "default_all" - ], - "displayName": "all ccache make configuration" - }, { "name": "all_msvc", "inherits": [ @@ -159,14 +125,6 @@ ], "displayName": "gpu numerical tests make configuration" }, - { - "name": "gpu_numerical_tests_ccache_make", - "inherits": [ - "default_ccache_make", - "default_gpu_numerical_tests" - ], - "displayName": "gpu numerical tests ccache make configuration" - }, { "name": "gpu_numerical_tests_msvc", "inherits": [ diff --git a/apps/cpu/LaminarTubeFlow/ltf.cpp b/apps/cpu/LaminarTubeFlow/ltf.cpp index c2c3866fc11b404acb3c571450f86d8ce07a4b2f..3cffab61c644e4b0cfab2795e2a8c7698555262a 100644 --- a/apps/cpu/LaminarTubeFlow/ltf.cpp +++ b/apps/cpu/LaminarTubeFlow/ltf.cpp @@ -49,6 +49,8 @@ void run(string configname) stringstream logFilename; logFilename << pathname + "/logfile" + UbSystem::toString(UbSystem::getTimeStamp()) + ".txt"; UbLog::output_policy::setStream(logFilename.str()); + + vf::logging::Logger::changeLogPath(pathname); } } @@ -143,12 +145,12 @@ void run(string configname) if (myid == 0) { - UBLOG(logINFO, "uLb = " << uLB); - UBLOG(logINFO, "rho = " << rhoLB); - UBLOG(logINFO, "nuLb = " << nuLB); - UBLOG(logINFO, "Re = " << Re); - UBLOG(logINFO, "dx = " << dx); - UBLOG(logINFO, "Preprocess - start"); + VF_LOG_INFO("uLb = {}", uLB); + VF_LOG_INFO("rho = {}", rhoLB); + VF_LOG_INFO("nuLb = {}", nuLB); + VF_LOG_INFO("Re = {}", Re); + VF_LOG_INFO("dx = {}", dx); + VF_LOG_INFO("Preprocess - start"); } grid->setDeltaX(dx); @@ -232,19 +234,19 @@ void run(string configname) if (myid == 0) { - UBLOG(logINFO, "Number of blocks = " << numberOfBlocks); - UBLOG(logINFO, "Number of nodes = " << numberOfNodes); + VF_LOG_INFO("Number of blocks = {}", numberOfBlocks); + VF_LOG_INFO("Number of nodes = {}", numberOfNodes); int minInitLevel = grid->getCoarsestInitializedLevel(); int maxInitLevel = grid->getFinestInitializedLevel(); for (int level = minInitLevel; level <= maxInitLevel; level++) { int nobl = grid->getNumberOfBlocks(level); - UBLOG(logINFO, "Number of blocks for level " << level << " = " << nobl); - UBLOG(logINFO, "Number of nodes for level " << level << " = " << nobl*numberOfNodesPerBlock); + VF_LOG_INFO("Number of blocks for level {} = {}", level, nobl); + VF_LOG_INFO("Number of nodes for level {} = {}", level, nobl*numberOfNodesPerBlock); } - UBLOG(logINFO, "Necessary memory = " << needMemAll << " bytes"); - UBLOG(logINFO, "Necessary memory per process = " << needMem << " bytes"); - UBLOG(logINFO, "Available memory per process = " << availMem << " bytes"); + VF_LOG_INFO("Necessary memory = {} bytes", needMemAll); + VF_LOG_INFO("Necessary memory per process = {} bytes", needMem); + VF_LOG_INFO("Available memory per process = {} bytes", availMem); } SetKernelBlockVisitor kernelVisitor(kernel, nuLB, availMem, needMem); @@ -275,27 +277,27 @@ void run(string configname) ppgeo.reset(); } - if (myid == 0) UBLOG(logINFO, "Preprocess - end"); + if (myid == 0) VF_LOG_INFO("Preprocess - end"); } else { if (myid == 0) { - UBLOG(logINFO, "Parameters:"); - UBLOG(logINFO, "uLb = " << uLB); - UBLOG(logINFO, "rho = " << rhoLB); - UBLOG(logINFO, "nuLb = " << nuLB); - UBLOG(logINFO, "Re = " << Re); - UBLOG(logINFO, "dx = " << dx); - UBLOG(logINFO, "number of levels = " << refineLevel + 1); - UBLOG(logINFO, "numOfThreads = " << numOfThreads); - UBLOG(logINFO, "path = " << pathname); + VF_LOG_INFO("Parameters:"); + VF_LOG_INFO("uLb = {}", uLB); + VF_LOG_INFO("rho = {}", rhoLB); + VF_LOG_INFO("nuLb = {}", nuLB); + VF_LOG_INFO("Re = {}", Re); + VF_LOG_INFO("dx = {}", dx); + VF_LOG_INFO("number of levels = {}", refineLevel + 1); + VF_LOG_INFO("numOfThreads = {}", numOfThreads); + VF_LOG_INFO("path = {}", pathname); } migCoProcessor->restart((int)restartStep); grid->setTimeStep(restartStep); - if (myid == 0) UBLOG(logINFO, "Restart - end"); + if (myid == 0) VF_LOG_INFO("Restart - end"); } OneDistributionSetConnectorsBlockVisitor setConnsVisitor(comm); @@ -324,10 +326,9 @@ void run(string configname) calculator->addCoProcessor(migCoProcessor); calculator->addCoProcessor(timeDepBC); - if (myid == 0) UBLOG(logINFO, "Simulation-start"); + if (myid == 0) VF_LOG_INFO("Simulation-start"); calculator->calculate(); - if (myid == 0) - UBLOG(logINFO, "Simulation-end"); + if (myid == 0) VF_LOG_INFO("Simulation-end"); } catch (std::exception& e) { @@ -343,19 +344,23 @@ void run(string configname) } } -int main(int /*argc*/, char* argv[]) + + +int main(int argc, char *argv[]) { - if (argv != NULL) - { - if (argv[1] != NULL) - { - run(string(argv[1])); - } - else - { - cout << "Configuration file is missing!" << endl; - } - } + try { + vf::logging::Logger::initalizeLogger(); -} + VF_LOG_INFO("Starting VirtualFluids..."); + if (argc > 1) + run(std::string(argv[1])); + else + VF_LOG_CRITICAL("Configuration file is missing!"); + + VF_LOG_INFO("VirtualFluids is finished."); + + } catch (const spdlog::spdlog_ex &ex) { + std::cout << "Log initialization failed: " << ex.what() << std::endl; + } +} diff --git a/apps/gpu/LBM/DrivenCavity/DrivenCavity.cpp b/apps/gpu/LBM/DrivenCavity/DrivenCavity.cpp index da92fa6a3809877118f58b8367d6d06d1e158982..bee9847821e2736f08be2d60264362d159ed2e1f 100644 --- a/apps/gpu/LBM/DrivenCavity/DrivenCavity.cpp +++ b/apps/gpu/LBM/DrivenCavity/DrivenCavity.cpp @@ -25,6 +25,8 @@ #include <basics/config/ConfigurationFile.h> +#include <logger/Logger.h> + ////////////////////////////////////////////////////////////////////////// #include "GridGenerator/grid/GridBuilder/LevelGridBuilder.h" @@ -117,11 +119,7 @@ void multipleLevel(const std::string& configPath) logging::Logger::timeStamp(logging::Logger::ENABLE); logging::Logger::enablePrintedRankNumbers(logging::Logger::ENABLE); - auto gridFactory = GridFactory::make(); - gridFactory->setGridStrategy(Device::CPU); - gridFactory->setTriangularMeshDiscretizationMethod(TriangularMeshDiscretizationMethod::POINT_IN_OBJECT); - - auto gridBuilder = MultipleGridBuilder::makeShared(gridFactory); + auto gridBuilder = MultipleGridBuilder::makeShared(); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -165,8 +163,8 @@ void multipleLevel(const std::string& configPath) const real viscosityLB = nx * velocityLB / Re; // LB units - *logging::out << logging::Logger::INFO_HIGH << "velocity [dx/dt] = " << velocityLB << " \n"; - *logging::out << logging::Logger::INFO_HIGH << "viscosity [dx^2/dt] = " << viscosityLB << "\n"; + VF_LOG_INFO("velocity [dx/dt] = {}", velocityLB); + VF_LOG_INFO("viscosity [dx^2/dt] = {}", viscosityLB); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -344,23 +342,28 @@ int main( int argc, char* argv[]) try { + vf::logging::Logger::initalizeLogger(); + // assuming that the config files is stored parallel to this file. std::filesystem::path filePath = __FILE__; filePath.replace_filename("configDrivenCavity.txt"); - multipleLevel(filePath.string()); - } + multipleLevel(filePath.string()); + } + catch (const spdlog::spdlog_ex &ex) { + std::cout << "Log initialization failed: " << ex.what() << std::endl; + } catch (const std::bad_alloc& e) { - *logging::out << logging::Logger::LOGGER_ERROR << "Bad Alloc:" << e.what() << "\n"; + VF_LOG_CRITICAL("Bad Alloc: {}", e.what()); } catch (const std::exception& e) { - *logging::out << logging::Logger::LOGGER_ERROR << e.what() << "\n"; + VF_LOG_CRITICAL("exception: {}", e.what()); } catch (...) { - *logging::out << logging::Logger::LOGGER_ERROR << "Unknown exception!\n"; + VF_LOG_CRITICAL("Unknown exception!"); } MPI_Finalize(); diff --git a/apps/gpu/LBM/WTG_RUB/WTG_RUB.cpp b/apps/gpu/LBM/WTG_RUB/WTG_RUB.cpp index 86d2227d200622ab3a2d87505ba5c7afcede36fe..bc0fdfa440a1eb1fa466bccf3a68e6216a513fbb 100644 --- a/apps/gpu/LBM/WTG_RUB/WTG_RUB.cpp +++ b/apps/gpu/LBM/WTG_RUB/WTG_RUB.cpp @@ -109,11 +109,7 @@ void multipleLevel(const std::string& configPath) logging::Logger::timeStamp(logging::Logger::ENABLE); logging::Logger::enablePrintedRankNumbers(logging::Logger::ENABLE); - auto gridFactory = GridFactory::make(); - gridFactory->setGridStrategy(Device::CPU); - gridFactory->setTriangularMeshDiscretizationMethod(TriangularMeshDiscretizationMethod::POINT_IN_OBJECT); - - auto gridBuilder = MultipleGridBuilder::makeShared(gridFactory); + auto gridBuilder = MultipleGridBuilder::makeShared(); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/basics/CMakeLists.txt b/src/basics/CMakeLists.txt index 1703d6269c1cebe36005226373da85b14c5515f6..7f871424b2c6849d2c0f6e8d277b17214fa5cd9c 100644 --- a/src/basics/CMakeLists.txt +++ b/src/basics/CMakeLists.txt @@ -1,7 +1,7 @@ include(Core/buildInfo.cmake) -vf_add_library(PUBLIC_LINK MPI::MPI_CXX EXCLUDE buildInfo.in.cpp) +vf_add_library(PUBLIC_LINK logger MPI::MPI_CXX EXCLUDE buildInfo.in.cpp) vf_get_library_name (library_name) target_include_directories(${library_name} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/Core) diff --git a/src/basics/geometry3d/KdTree/KdTree.h b/src/basics/geometry3d/KdTree/KdTree.h index 42c337f66cdddb450108e973fc0a75323512a149..f3859f95a8a1eb48be6f4c76e0ba156b586e7f93 100644 --- a/src/basics/geometry3d/KdTree/KdTree.h +++ b/src/basics/geometry3d/KdTree/KdTree.h @@ -75,7 +75,7 @@ public: new std::vector<GbTriFaceMesh3D::TriFace>(*mesh.getTriangles())); const int maxLevel = - static_cast<int>(lround(8.0 + 1.3 * std::log((double)triFaces->size()))); // TODO: remove magic numbers + static_cast<int>(std::lround(8.0 + 1.3 * std::log((double)triFaces->size()))); // TODO: remove magic numbers rootNode = new Node<T>(T(mesh.getX1Minimum()), T(mesh.getX2Minimum()), T(mesh.getX3Minimum()), T(mesh.getX1Maximum()), diff --git a/src/cpu/VirtualFluids.h b/src/cpu/VirtualFluids.h index f5064398a6a2953c20f844be3db5865a16620e93..f52a4634f8266a886598558c205560a85bdbc21e 100644 --- a/src/cpu/VirtualFluids.h +++ b/src/cpu/VirtualFluids.h @@ -43,6 +43,7 @@ #include <basics/PointerDefinitions.h> #include <basics/config/ConfigurationFile.h> +#include <logger/Logger.h> #include <basics/container/CbArray2D.h> #include <basics/container/CbArray3D.h> diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/WriteBlocksCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/WriteBlocksCoProcessor.cpp index bac7c9c346c24198b56ce8a77cf884c0a660bb1f..ed624de5bb0e750c9e2f3cfaf301cdc7f66fd2a3 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/WriteBlocksCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/WriteBlocksCoProcessor.cpp @@ -33,6 +33,7 @@ #include "WriteBlocksCoProcessor.h" #include "basics/writer/WbWriterVtkXmlASCII.h" +#include <logger/Logger.h> #include "Block3D.h" #include "Communicator.h" @@ -180,6 +181,6 @@ void WriteBlocksCoProcessor::collectData(double step) istep, false); } - UBLOG(logINFO, "WriteBlocksCoProcessor step: " << istep); + VF_LOG_INFO("WriteBlocksCoProcessor step: {}", istep); } } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/WriteBoundaryConditionsCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/WriteBoundaryConditionsCoProcessor.cpp index 117088f67aa0e832608d96480e15bde2fb5dec3b..02f7bb4a28972f946d7d6a3d45487a7906494fea 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/WriteBoundaryConditionsCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/WriteBoundaryConditionsCoProcessor.cpp @@ -37,6 +37,8 @@ #include <string> #include <vector> +#include <logger/Logger.h> + #include "BCArray3D.h" #include "Block3D.h" #include "CbArray3D.h" @@ -114,7 +116,7 @@ void WriteBoundaryConditionsCoProcessor::collectData(double step) } else { WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(cfilePath, filenames, istep, false); } - UBLOG(logINFO, "WriteBoundaryConditionsCoProcessor step: " << istep); + VF_LOG_INFO("WriteBoundaryConditionsCoProcessor step: {}", istep); } clearData(); diff --git a/src/gpu/GridGenerator/CMakeLists.txt b/src/gpu/GridGenerator/CMakeLists.txt index 844e933d5c053aaeef38085c5c5a9e01721ff6aa..8f65576fc55767f4eea1c30a6241f03fe031bbc5 100644 --- a/src/gpu/GridGenerator/CMakeLists.txt +++ b/src/gpu/GridGenerator/CMakeLists.txt @@ -1,10 +1,3 @@ -project(GridGenerator LANGUAGES CUDA CXX) - +project(GridGenerator LANGUAGES CXX) vf_add_library(PRIVATE_LINK basics OpenMP::OpenMP_CXX) - -vf_get_library_name(library_name) -set_target_properties(${library_name} PROPERTIES CUDA_SEPARABLE_COMPILATION ON) - -# we want to suppress all cuda warnings so far for this library. -target_compile_options(${library_name} PUBLIC $<$<COMPILE_LANGUAGE:CUDA>:-Xcudafe "-w" >) diff --git a/src/gpu/GridGenerator/StreetPointFinder/JunctionReader.cpp b/src/gpu/GridGenerator/StreetPointFinder/JunctionReader.cpp index 065d4ae646674992889d528a347b8172df98aec6..bac17264d1c00389bbefacc4063d7801e8f5baa7 100644 --- a/src/gpu/GridGenerator/StreetPointFinder/JunctionReader.cpp +++ b/src/gpu/GridGenerator/StreetPointFinder/JunctionReader.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 JunctionReader.cpp +//! \ingroup StreetPointFinder +//! \author Stephan Lenz +//======================================================================================= #include "JunctionReader.h" #include <fstream> diff --git a/src/gpu/GridGenerator/StreetPointFinder/JunctionReader.h b/src/gpu/GridGenerator/StreetPointFinder/JunctionReader.h index dea2a6a91028bbde0aab876e871e12dbbdac40d9..5b68b0357ea2432dfde6d167b27908fe1aa4348a 100644 --- a/src/gpu/GridGenerator/StreetPointFinder/JunctionReader.h +++ b/src/gpu/GridGenerator/StreetPointFinder/JunctionReader.h @@ -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 JunctionReader.h +//! \ingroup StreetPointFinder +//! \author Stephan Lenz +//======================================================================================= #ifndef JUNCTIONREADER_H #define JUNCTIONREADER_H diff --git a/src/gpu/GridGenerator/StreetPointFinder/SinkReader.cpp b/src/gpu/GridGenerator/StreetPointFinder/SinkReader.cpp index 3c3e766898dd001c92206f945066b180ed2c19ad..1224f1bf7cad8e535e842426406aacc619dad314 100644 --- a/src/gpu/GridGenerator/StreetPointFinder/SinkReader.cpp +++ b/src/gpu/GridGenerator/StreetPointFinder/SinkReader.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 SinkReader.cpp +//! \ingroup StreetPointFinder +//! \author Stephan Lenz +//======================================================================================= #include "SinkReader.h" #include <fstream> diff --git a/src/gpu/GridGenerator/StreetPointFinder/SinkReader.h b/src/gpu/GridGenerator/StreetPointFinder/SinkReader.h index 115aea55257f8a2086098699e3d8fc24a8a1d1b5..ba28596b0eb63954eb5f7162c4849f863e15f657 100644 --- a/src/gpu/GridGenerator/StreetPointFinder/SinkReader.h +++ b/src/gpu/GridGenerator/StreetPointFinder/SinkReader.h @@ -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 SinkReader.h +//! \ingroup StreetPointFinder +//! \author Stephan Lenz +//======================================================================================= #ifndef SINKREADER_H #define SINKREADER_H diff --git a/src/gpu/GridGenerator/StreetPointFinder/SourceReader.cpp b/src/gpu/GridGenerator/StreetPointFinder/SourceReader.cpp index e9cab08476f10a0f61860225b4d9771ef3166638..a3a62f942f96fa1faf9e49448ed3ae627d985273 100644 --- a/src/gpu/GridGenerator/StreetPointFinder/SourceReader.cpp +++ b/src/gpu/GridGenerator/StreetPointFinder/SourceReader.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 SourceReader.cpp +//! \ingroup StreetPointFinder +//! \author Stephan Lenz +//======================================================================================= #include "SourceReader.h" #include <fstream> diff --git a/src/gpu/GridGenerator/StreetPointFinder/SourceReader.h b/src/gpu/GridGenerator/StreetPointFinder/SourceReader.h index db95259ea91a60fc2c9ef1721272a4915374e646..f79c618d06ff9f72738c7b69767a8dd3c5443fac 100644 --- a/src/gpu/GridGenerator/StreetPointFinder/SourceReader.h +++ b/src/gpu/GridGenerator/StreetPointFinder/SourceReader.h @@ -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 SourceReader.h +//! \ingroup StreetPointFinder +//! \author Stephan Lenz +//======================================================================================= #ifndef SOURCEREADER_H #define SOURCEREADER_H diff --git a/src/gpu/GridGenerator/StreetPointFinder/StreetPointFinder.cpp b/src/gpu/GridGenerator/StreetPointFinder/StreetPointFinder.cpp index 3a764dd353824df4dcd07aee2557ccc031648b6f..9fbd3933a5457e96d2d1aa01f1fadcf675be1980 100644 --- a/src/gpu/GridGenerator/StreetPointFinder/StreetPointFinder.cpp +++ b/src/gpu/GridGenerator/StreetPointFinder/StreetPointFinder.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 StreetPointFinder.cpp +//! \ingroup StreetPointFinder +//! \author Stephan Lenz +//======================================================================================= #include "StreetPointFinder.h" #include "Core/Logger/Logger.h" diff --git a/src/gpu/GridGenerator/StreetPointFinder/StreetPointFinder.h b/src/gpu/GridGenerator/StreetPointFinder/StreetPointFinder.h index 73d1e0de07c34188d879323a3a762a82f2ed4543..feb3618f64b0a6f757930772594878a6ca7c0144 100644 --- a/src/gpu/GridGenerator/StreetPointFinder/StreetPointFinder.h +++ b/src/gpu/GridGenerator/StreetPointFinder/StreetPointFinder.h @@ -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 StreetPointFinder.h +//! \ingroup StreetPointFinder +//! \author Stephan Lenz +//======================================================================================= #ifndef StreetPointFinder_H #define StreetPointFinder_H diff --git a/src/gpu/GridGenerator/geometries/Arrow/Arrow.h b/src/gpu/GridGenerator/geometries/Arrow/Arrow.h index dfd006042c63a35236e0fab886a527a86fa84896..945f1e3a8af7bd14fb9c3a8d5d9d26ab7405a7b7 100644 --- a/src/gpu/GridGenerator/geometries/Arrow/Arrow.h +++ b/src/gpu/GridGenerator/geometries/Arrow/Arrow.h @@ -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 Arrow.h +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef Arrow_H #define Arrow_H diff --git a/src/gpu/GridGenerator/geometries/Arrow/ArrowImp.cpp b/src/gpu/GridGenerator/geometries/Arrow/ArrowImp.cpp index 28176b4f5657a2e5907fd1d308af7aba13330220..f7ee7330c6c57f076fd4f45c8bf7a3f0749df6a1 100644 --- a/src/gpu/GridGenerator/geometries/Arrow/ArrowImp.cpp +++ b/src/gpu/GridGenerator/geometries/Arrow/ArrowImp.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 ArrowImp.cpp +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "ArrowImp.h" #include "../Vertex/Vertex.h" diff --git a/src/gpu/GridGenerator/geometries/Arrow/ArrowImp.h b/src/gpu/GridGenerator/geometries/Arrow/ArrowImp.h index 195223d9125c265905b6c47ee8dc09edb205f267..ef145b7def48803b7e2d043f7a5862ee21f954c4 100644 --- a/src/gpu/GridGenerator/geometries/Arrow/ArrowImp.h +++ b/src/gpu/GridGenerator/geometries/Arrow/ArrowImp.h @@ -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 ArrowImp.h +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef ArrowImp_H #define ArrowImp_H diff --git a/src/gpu/GridGenerator/geometries/BoundingBox/BoundingBox.cu b/src/gpu/GridGenerator/geometries/BoundingBox/BoundingBox.cpp similarity index 65% rename from src/gpu/GridGenerator/geometries/BoundingBox/BoundingBox.cu rename to src/gpu/GridGenerator/geometries/BoundingBox/BoundingBox.cpp index 75ae002813541bfdb73b0f3dcc179270c31fa5df..1532e57e8cc4b0db93ed79c03074d7845ff9c87f 100644 --- a/src/gpu/GridGenerator/geometries/BoundingBox/BoundingBox.cu +++ b/src/gpu/GridGenerator/geometries/BoundingBox/BoundingBox.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 BoundingBox.cpp +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "BoundingBox.h" #include "../Triangle/Triangle.h" @@ -10,18 +42,7 @@ BoundingBox::BoundingBox(real minX, real maxX, real minY, real maxY, real minZ, real maxZ) : minX(minX), maxX(maxX), minY(minY), maxY(maxY), minZ(minZ), maxZ(maxZ) {} - HOSTDEVICE BoundingBox::BoundingBox() : - minX(0), - maxX(0), - minY(0), - maxY(0), - minZ(0), - maxZ(0) {} - - BoundingBox::BoundingBox(const BoundingBox &t) : minX(t.minX), maxX(t.maxX), minY(t.minY), maxY(t.maxY), minZ(t.minZ), maxZ(t.maxZ) {} - - - CUDA_HOST BoundingBox BoundingBox::makeInvalidMinMaxBox() + BoundingBox BoundingBox::makeInvalidMinMaxBox() { BoundingBox box = BoundingBox(std::numeric_limits<real>::max(), std::numeric_limits<real>::lowest(), @@ -32,11 +53,11 @@ return box; } - void BoundingBox::setMinMax(const Triangle& t) + void BoundingBox::setMinMax(const Triangle &t) { real minX, maxX, minY, maxY, minZ, maxZ; t.setMinMax(minX, maxX, minY, maxY, minZ, maxZ); - if(minX < this->minX) + if (minX < this->minX) this->minX = minX; if (minY < this->minY) this->minY = minY; @@ -51,20 +72,18 @@ this->maxZ = maxZ; } - bool BoundingBox::intersect(const Triangle &t) const { - if (isInside(t.v1) || isInside(t.v2) || isInside(t.v3)) - return true; - return false; + if (isInside(t.v1) || isInside(t.v2) || isInside(t.v3)) + return true; + return false; } - bool BoundingBox::isInside(const Triangle &t) const { - if (isInside(t.v1) && isInside(t.v2) && isInside(t.v3)) - return true; - return false; + if (isInside(t.v1) && isInside(t.v2) && isInside(t.v3)) + return true; + return false; } bool BoundingBox::isInside(const real x, const real y, const real z) const @@ -157,7 +176,7 @@ } - CUDA_HOST bool BoundingBox::operator==(const BoundingBox &box) const + bool BoundingBox::operator==(const BoundingBox &box) const { return vf::Math::equal(minX, box.minX) && vf::Math::equal(maxX, box.maxX) diff --git a/src/gpu/GridGenerator/geometries/BoundingBox/BoundingBox.h b/src/gpu/GridGenerator/geometries/BoundingBox/BoundingBox.h index e1d4f24e450400154498f716bd1fa4042be795f6..1fa27b68ecb127c469a6a4f7fc7f7d094110dd8f 100644 --- a/src/gpu/GridGenerator/geometries/BoundingBox/BoundingBox.h +++ b/src/gpu/GridGenerator/geometries/BoundingBox/BoundingBox.h @@ -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 BoundingBox.h +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef BoundingBox_h #define BoundingBox_h #include <vector> #include <cuda_runtime.h> -#include "GridGenerator_export.h" + #include "global.h" struct Vertex; @@ -21,23 +53,22 @@ public: real maxZ; BoundingBox(real minX, real maxX, real minY, real maxY, real minZ, real maxZ); - HOSTDEVICE BoundingBox(); - BoundingBox(const BoundingBox &t); + BoundingBox() = default; public: - CUDA_HOST static BoundingBox makeInvalidMinMaxBox(); + static BoundingBox makeInvalidMinMaxBox(); - void setMinMax(const Triangle& t); - void print() const; + void setMinMax(const Triangle &t); + void print() const; bool isInside(const Triangle &t) const; - bool isInside(const real x, const real y, const real z) const; - bool intersect(const Triangle &t) const; + bool isInside(const real x, const real y, const real z) const; + bool intersect(const Triangle &t) const; std::vector<std::vector<Vertex> > getIntersectionPoints(const BoundingBox &b) const; bool intersect(const BoundingBox &box) const; - CUDA_HOST bool operator==(const BoundingBox &box) const; + bool operator==(const BoundingBox &box) const; void extend(real delta); diff --git a/src/gpu/GridGenerator/geometries/Conglomerate/Conglomerate.cu b/src/gpu/GridGenerator/geometries/Conglomerate/Conglomerate.cpp similarity index 67% rename from src/gpu/GridGenerator/geometries/Conglomerate/Conglomerate.cu rename to src/gpu/GridGenerator/geometries/Conglomerate/Conglomerate.cpp index b87eba98c1ed10b6be0f70abf2093ff00f132050..331b928c6f5542584cffdcc1b17df7207981b8f8 100644 --- a/src/gpu/GridGenerator/geometries/Conglomerate/Conglomerate.cu +++ b/src/gpu/GridGenerator/geometries/Conglomerate/Conglomerate.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 Conglomerate.cpp +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "Conglomerate.h" Conglomerate::Conglomerate() diff --git a/src/gpu/GridGenerator/geometries/Conglomerate/Conglomerate.h b/src/gpu/GridGenerator/geometries/Conglomerate/Conglomerate.h index cca1a85f5110514d560481e25cc55068569a3107..8cb26137d6ab4e4c52bed34aa1d044121ac4bf3d 100644 --- a/src/gpu/GridGenerator/geometries/Conglomerate/Conglomerate.h +++ b/src/gpu/GridGenerator/geometries/Conglomerate/Conglomerate.h @@ -1,9 +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 Conglomerate.h +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef CONGLOMERATE_H #define CONGLOMERATE_H @@ -16,16 +42,16 @@ class GRIDGENERATOR_EXPORT Conglomerate : public Object { public: - HOSTDEVICE Conglomerate(); - HOSTDEVICE virtual ~Conglomerate(); + Conglomerate(); + virtual ~Conglomerate(); - CUDA_HOST static SPtr<Conglomerate> makeShared(); + static SPtr<Conglomerate> makeShared(); - HOSTDEVICE void add(Object* object); - HOSTDEVICE void subtract(Object* objectStub); + void add(Object* object); + void subtract(Object* objectStub); - HOSTDEVICE Object* clone() const override; + Object* clone() const override; double getX1Centroid() override; double getX1Minimum() override; @@ -39,9 +65,9 @@ public: void scale(double delta) override; - HOSTDEVICE bool isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, const double& maxOffset) override; + bool isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, const double& maxOffset) override; - CUDA_HOST void findInnerNodes(SPtr<GridImp> grid) override; + void findInnerNodes(SPtr<GridImp> grid) override; protected: static double getMinimum(double val1, double val2); diff --git a/src/gpu/GridGenerator/geometries/Cuboid/Cuboid.cpp b/src/gpu/GridGenerator/geometries/Cuboid/Cuboid.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e64a202ca9bcd5a33fcc9ba85e7bd35fa67a1d4e --- /dev/null +++ b/src/gpu/GridGenerator/geometries/Cuboid/Cuboid.cpp @@ -0,0 +1,153 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// 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 Cuboid.cpp +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= +#include "Cuboid.h" + +#include "utilities/math/Math.h" + +Cuboid::Cuboid(const double& x1a,const double& x2a, const double& x3a, const double& x1b,const double& x2b, const double& x3b) + : minX1(x1a), minX2(x2a), minX3(x3a), maxX1(x1b), maxX2(x2b), maxX3(x3b) +{ + +} + +Cuboid::~Cuboid() +{ + +} + +Object* Cuboid::clone() const +{ + return new Cuboid(minX1, minX2, minX3, maxX1, maxX2, maxX3); +} + +double Cuboid::getX1Centroid() +{ + return getCenter(minX1, maxX1); +} + +double Cuboid::getX1Minimum() +{ + return getMinimum(minX1, maxX1); +} + +double Cuboid::getX1Maximum() +{ + return getMaximum(minX1, maxX1); +} + +double Cuboid::getX2Centroid() +{ + return getCenter(minX2, maxX2); +} + +double Cuboid::getX2Minimum() +{ + return getMinimum(minX2, maxX2); +} + +double Cuboid::getX2Maximum() +{ + return getMaximum(minX2, maxX2); +} + +double Cuboid::getX3Centroid() +{ + return getCenter(minX3, maxX3); +} + +double Cuboid::getX3Minimum() +{ + return getMinimum(minX3, maxX3); +} + +double Cuboid::getX3Maximum() +{ + return getMaximum(minX3, maxX3); +} + +double Cuboid::getCenter(double x1, double x2) +{ + return 0.5 * (x1 + x2); +} + +double Cuboid::getMinimum(double x1, double x2) +{ + return (x1 < x2 ? x1 : x2); +} + +double Cuboid::getMaximum(double x1, double x2) +{ + return (x1 > x2 ? x1 : x2); +} + +bool Cuboid::isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, const double& maxOffset) +{ + //false, if 'not in Object' or 'on Boundary'! + if (vf::Math::lessEqual((real)x1, (real)this->getX1Minimum() + (real)minOffset)) + return false; + if (vf::Math::lessEqual((real)x2, (real)this->getX2Minimum() + (real)minOffset)) + return false; + if (vf::Math::lessEqual((real)x3, (real)this->getX3Minimum() + (real)minOffset)) + return false; + if (vf::Math::greaterEqual((real)x1, (real)this->getX1Maximum() - (real)maxOffset)) + return false; + if (vf::Math::greaterEqual((real)x2, (real)this->getX2Maximum() - (real)maxOffset)) + return false; + if (vf::Math::greaterEqual((real)x3, (real)this->getX3Maximum() - (real)maxOffset)) + return false; + + return true; +} + + +bool Cuboid::isOn(const real& coord, const real& plane1, const real& plane2) +{ + return vf::Math::equal(coord, plane1) || vf::Math::equal(coord, plane2); +} + +bool Cuboid::isBetween(const real& coord, const real& start, const real& end) +{ + return vf::Math::greaterEqual(coord, start) && vf::Math::lessEqual(coord, end); +} + + +void Cuboid::scale(double delta) +{ + this->minX1 -= delta; + this->minX2 -= delta; + this->minX3 -= delta; + + this->maxX1 += delta; + this->maxX2 += delta; + this->maxX3 += delta; +} diff --git a/src/gpu/GridGenerator/geometries/Cuboid/Cuboid.cu b/src/gpu/GridGenerator/geometries/Cuboid/Cuboid.cu deleted file mode 100644 index af7cb42c2ec428341145e22d6b58384ae152c5a1..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/geometries/Cuboid/Cuboid.cu +++ /dev/null @@ -1,115 +0,0 @@ -#include "Cuboid.h" - -#include "utilities/math/Math.h" - -Cuboid::Cuboid(const double& x1a,const double& x2a, const double& x3a, const double& x1b,const double& x2b, const double& x3b) - : minX1(x1a), minX2(x2a), minX3(x3a), maxX1(x1b), maxX2(x2b), maxX3(x3b) -{ - -} - -Cuboid::~Cuboid() -{ - -} - -Object* Cuboid::clone() const -{ - return new Cuboid(minX1, minX2, minX3, maxX1, maxX2, maxX3); -} - -double Cuboid::getX1Centroid() -{ - return getCenter(minX1, maxX1); -} - -double Cuboid::getX1Minimum() -{ - return getMinimum(minX1, maxX1); -} - -double Cuboid::getX1Maximum() -{ - return getMaximum(minX1, maxX1); -} - -double Cuboid::getX2Centroid() -{ - return getCenter(minX2, maxX2); -} - -double Cuboid::getX2Minimum() -{ - return getMinimum(minX2, maxX2); -} - -double Cuboid::getX2Maximum() -{ - return getMaximum(minX2, maxX2); -} - -double Cuboid::getX3Centroid() -{ - return getCenter(minX3, maxX3); -} - -double Cuboid::getX3Minimum() -{ - return getMinimum(minX3, maxX3); -} - -double Cuboid::getX3Maximum() -{ - return getMaximum(minX3, maxX3); -} - -double Cuboid::getCenter(double x1, double x2) -{ - return 0.5 * (x1 + x2); -} - -double Cuboid::getMinimum(double x1, double x2) -{ - return (x1 < x2 ? x1 : x2); -} - -double Cuboid::getMaximum(double x1, double x2) -{ - return (x1 > x2 ? x1 : x2); -} - -bool Cuboid::isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, const double& maxOffset) -{ - //false, if 'not in Object' or 'on Boundary'! - if (vf::Math::lessEqual(x1, this->getX1Minimum() + minOffset)) return false; - if (vf::Math::lessEqual(x2, this->getX2Minimum() + minOffset)) return false; - if (vf::Math::lessEqual(x3, this->getX3Minimum() + minOffset)) return false; - if (vf::Math::greaterEqual(x1, this->getX1Maximum() - maxOffset)) return false; - if (vf::Math::greaterEqual(x2, this->getX2Maximum() - maxOffset)) return false; - if (vf::Math::greaterEqual(x3, this->getX3Maximum() - maxOffset)) return false; - - return true; -} - - -bool Cuboid::isOn(const real& coord, const real& plane1, const real& plane2) -{ - return vf::Math::equal(coord, plane1) || vf::Math::equal(coord, plane2); -} - -bool Cuboid::isBetween(const real& coord, const real& start, const real& end) -{ - return vf::Math::greaterEqual(coord, start) && vf::Math::lessEqual(coord, end); -} - - -void Cuboid::scale(double delta) -{ - this->minX1 -= delta; - this->minX2 -= delta; - this->minX3 -= delta; - - this->maxX1 += delta; - this->maxX2 += delta; - this->maxX3 += delta; -} diff --git a/src/gpu/GridGenerator/geometries/Cuboid/Cuboid.h b/src/gpu/GridGenerator/geometries/Cuboid/Cuboid.h index 46202f07b77f997ce25068cf55b3515c28bd9636..0351bd3ed847f9702e3c64bce4dcef514804e23a 100644 --- a/src/gpu/GridGenerator/geometries/Cuboid/Cuboid.h +++ b/src/gpu/GridGenerator/geometries/Cuboid/Cuboid.h @@ -1,24 +1,49 @@ -// _ ___ __ __________ _ __ -// | | / (_)____/ /___ ______ _/ / ____/ /_ __(_)___/ /____ -// | | / / / ___/ __/ / / / __ `/ / /_ / / / / / / __ / ___/ -// | |/ / / / / /_/ /_/ / /_/ / / __/ / / /_/ / / /_/ (__ ) -// |___/_/_/ \__/\__,_/\__,_/_/_/ /_/\__,_/_/\__,_/____/ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // +// 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 Cuboid.h +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef CUBOID_H #define CUBOID_H #include "global.h" -#include "GridGenerator_export.h" #include "geometries/Object.h" class GRIDGENERATOR_EXPORT Cuboid : public Object { public: - HOSTDEVICE Cuboid(const double& minX1, const double& minX2, const double& minX3, const double& maxX1,const double& maxX2, const double& maxX3); - HOSTDEVICE virtual ~Cuboid(); + Cuboid(const double& minX1, const double& minX2, const double& minX3, const double& maxX1,const double& maxX2, const double& maxX3); + virtual ~Cuboid(); - HOSTDEVICE Object* clone() const override; + Object* clone() const override; double getX1Centroid() override; double getX1Minimum() override; @@ -32,7 +57,7 @@ public: void scale(double delta) override; - HOSTDEVICE bool isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, const double& maxOffset) override; + bool isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, const double& maxOffset) override; private: static double getCenter(double x1, double x2); diff --git a/src/gpu/GridGenerator/geometries/Object.cpp b/src/gpu/GridGenerator/geometries/Object.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c162b3b1db8654f36a0fe6f3c20f79b34a157338 --- /dev/null +++ b/src/gpu/GridGenerator/geometries/Object.cpp @@ -0,0 +1,44 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// 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 Object.cpp +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= +#include "Object.h" +#include "grid/GridImp.h" + +void Object::findInnerNodes(SPtr<GridImp> grid) +{ + grid->findInnerNodes(); +} + +int Object::getIntersection(const Vertex &P, const Vertex &direction, Vertex &pointOnObject, real &qVal) +{ + return 1; +} diff --git a/src/gpu/GridGenerator/geometries/Object.cu b/src/gpu/GridGenerator/geometries/Object.cu deleted file mode 100644 index a5167f7fb14970d520b7ebe4b92d4ae9a3dcc94b..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/geometries/Object.cu +++ /dev/null @@ -1,13 +0,0 @@ -#include "Object.h" -#include "grid/GridImp.h" -#include "grid/GridStrategy/GridStrategy.h" - -void Object::findInnerNodes(SPtr<GridImp> grid) -{ - grid->getGridStrategy()->findInnerNodes( grid ); -} - -CUDA_HOST int Object::getIntersection(const Vertex & P, const Vertex & direction, Vertex & pointOnObject, real & qVal) -{ - return 1; -} diff --git a/src/gpu/GridGenerator/geometries/Object.h b/src/gpu/GridGenerator/geometries/Object.h index e26ff324f27cf68a3d86afb35720af7c32671688..b92cca7992dcb06c1f230da8d8c9ce46bb7a3416 100644 --- a/src/gpu/GridGenerator/geometries/Object.h +++ b/src/gpu/GridGenerator/geometries/Object.h @@ -1,12 +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 Object.h +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef OBJECT_H #define OBJECT_H -#include "GridGenerator_export.h" + #include "grid/Cell.h" #include "global.h" @@ -17,8 +43,8 @@ struct Vertex; class GRIDGENERATOR_EXPORT Object { public: - HOSTDEVICE virtual ~Object() {} - HOSTDEVICE virtual Object* clone() const = 0; + virtual ~Object() {} + virtual Object* clone() const = 0; virtual double getX1Centroid() = 0; virtual double getX1Minimum() = 0; @@ -36,9 +62,9 @@ public: virtual void scale(double delta) = 0; - HOSTDEVICE virtual bool isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, const double& maxOffset) = 0; + virtual bool isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, const double& maxOffset) = 0; - HOSTDEVICE virtual bool isCellInObject(const Cell& cell) { + virtual bool isCellInObject(const Cell& cell) { for (const auto point : cell) { const bool isInObject = isPointInObject(point.x, point.y, point.z, 0.0, 0.0); @@ -48,9 +74,9 @@ public: return true; } - CUDA_HOST virtual void findInnerNodes(SPtr<GridImp> grid); + virtual void findInnerNodes(SPtr<GridImp> grid); - CUDA_HOST virtual int getIntersection(const Vertex &P, const Vertex &direction, Vertex &pointOnObject, real &qVal); + virtual int getIntersection(const Vertex &P, const Vertex &direction, Vertex &pointOnObject, real &qVal); }; diff --git a/src/gpu/GridGenerator/geometries/Point/Point.cpp b/src/gpu/GridGenerator/geometries/Point/Point.cpp deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/src/gpu/GridGenerator/geometries/Point/Point.h b/src/gpu/GridGenerator/geometries/Point/Point.h deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/src/gpu/GridGenerator/geometries/Sphere/Sphere.cu b/src/gpu/GridGenerator/geometries/Sphere/Sphere.cpp similarity index 57% rename from src/gpu/GridGenerator/geometries/Sphere/Sphere.cu rename to src/gpu/GridGenerator/geometries/Sphere/Sphere.cpp index 1b316ae74384b4e2f67decd6ab319e0f0d1db2cf..fa460bc021cdca1159f272e3bcb4d4dad50fc352 100644 --- a/src/gpu/GridGenerator/geometries/Sphere/Sphere.cu +++ b/src/gpu/GridGenerator/geometries/Sphere/Sphere.cpp @@ -1,7 +1,40 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// 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 Sphere.cpp +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "Sphere.h" #include <algorithm> // std::min #include <float.h> +#include <cmath> #include "geometries/Vertex/Vertex.h" @@ -91,7 +124,7 @@ void Sphere::scale(double delta) this->radius += delta; } -CUDA_HOST int Sphere::getIntersection(const Vertex & point, const Vertex & direction, Vertex & pointOnObject, real & qVal) +int Sphere::getIntersection(const Vertex & point, const Vertex & direction, Vertex & pointOnObject, real & qVal) { Vertex relativePoint( point.x - this->centerX, diff --git a/src/gpu/GridGenerator/geometries/Sphere/Sphere.h b/src/gpu/GridGenerator/geometries/Sphere/Sphere.h index 48a3cfb67a502e8537a6a5c0e2ea0f584c56583a..ba5821f5bfed5b4d25c1ee3c5abecb168db462e7 100644 --- a/src/gpu/GridGenerator/geometries/Sphere/Sphere.h +++ b/src/gpu/GridGenerator/geometries/Sphere/Sphere.h @@ -1,9 +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 Sphere.h +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef SPHERE_H #define SPHERE_H @@ -14,12 +40,12 @@ class GRIDGENERATOR_EXPORT Sphere : public Object { public: - HOSTDEVICE Sphere(const double& centerX, const double& centerY, const double& centerZ, const double& radius); - HOSTDEVICE virtual ~Sphere(); + Sphere(const double& centerX, const double& centerY, const double& centerZ, const double& radius); + virtual ~Sphere(); static SPtr<Sphere> makeShared(double centerX, double centerY, double centerZ, double radius); - HOSTDEVICE Object* clone() const override; + Object* clone() const override; double getX1Centroid() override; double getX1Minimum() override; @@ -31,12 +57,12 @@ public: double getX3Minimum() override; double getX3Maximum() override; - HOSTDEVICE bool isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, const double& maxOffset) override; + bool isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, const double& maxOffset) override; void scale(double delta) override; - CUDA_HOST int getIntersection(const Vertex &P, const Vertex &direction, Vertex &pointOnObject, real &qVal) override; + int getIntersection(const Vertex &P, const Vertex &direction, Vertex &pointOnObject, real &qVal) override; protected: diff --git a/src/gpu/GridGenerator/geometries/Triangle/Triangle.cu b/src/gpu/GridGenerator/geometries/Triangle/Triangle.cpp similarity index 60% rename from src/gpu/GridGenerator/geometries/Triangle/Triangle.cu rename to src/gpu/GridGenerator/geometries/Triangle/Triangle.cpp index 3ba2179a2b93d4249ec84100d8c62eefff2be86f..bf272b9e7f46c413ae6edce62c05d1be20d327de 100644 --- a/src/gpu/GridGenerator/geometries/Triangle/Triangle.cu +++ b/src/gpu/GridGenerator/geometries/Triangle/Triangle.cpp @@ -1,5 +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 Triangle.cpp +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "Triangle.h" -#include "TriangleException.h" #include "utilities/math/Math.h" @@ -7,11 +38,11 @@ using namespace vf::gpu; -HOSTDEVICE Triangle::Triangle(Vertex &v1, Vertex &v2, Vertex &v3, Vertex &normal) : v1(v1), v2(v2), v3(v3), normal(normal), patchIndex(INVALID_INDEX) {} -HOSTDEVICE Triangle::Triangle(Vertex &v1, Vertex &v2, Vertex &v3) : v1(v1), v2(v2), v3(v3), patchIndex(INVALID_INDEX) { calcNormal(); } -HOSTDEVICE Triangle::Triangle(){} +Triangle::Triangle(Vertex &v1, Vertex &v2, Vertex &v3, Vertex &normal) : v1(v1), v2(v2), v3(v3), normal(normal), patchIndex(INVALID_INDEX) {} +Triangle::Triangle(Vertex &v1, Vertex &v2, Vertex &v3) : v1(v1), v2(v2), v3(v3), patchIndex(INVALID_INDEX) { calcNormal(); } +Triangle::Triangle(){} -HOSTDEVICE void Triangle::set(const Vertex &v1, const Vertex &v2, const Vertex &v3) +void Triangle::set(const Vertex &v1, const Vertex &v2, const Vertex &v3) { this->v1 = v1; this->v2 = v2; @@ -19,7 +50,7 @@ HOSTDEVICE void Triangle::set(const Vertex &v1, const Vertex &v2, const Vertex & this->calcNormal(); } -HOSTDEVICE void Triangle::set(int index, Vertex value) +void Triangle::set(int index, Vertex value) { if (index == 0) v1 = value; @@ -29,7 +60,7 @@ HOSTDEVICE void Triangle::set(int index, Vertex value) v3 = value; } -HOSTDEVICE Vertex Triangle::get(int index) +Vertex Triangle::get(int index) { if (index == 0) return v1; @@ -41,7 +72,7 @@ HOSTDEVICE Vertex Triangle::get(int index) return Vertex((real)-999999999999999, (real)-99999999999999, (real)-9999999999999); } -HOSTDEVICE void Triangle::calcNormal() +void Triangle::calcNormal() { Vertex edge1 = v2 - v1; Vertex edge2 = v3 - v1; @@ -49,27 +80,31 @@ HOSTDEVICE void Triangle::calcNormal() normal.normalize(); } -HOSTDEVICE void Triangle::initalLayerThickness(real delta) +void Triangle::initalLayerThickness(real delta) { - this->layerThickness = delta*(abs(this->normal.x) + abs(this->normal.y) + abs(this->normal.z)); + this->layerThickness = delta * (std::abs(this->normal.x) + std::abs(this->normal.y) + std::abs(this->normal.z)); } -HOSTDEVICE char Triangle::isUnderFace(const Vertex &point) const +char Triangle::isUnderFace(const Vertex &point) const { real s; - if (this->isUnterExtendedFace(point, s)) - if (this->isNotNextToFace(point)) - if (this->isUnderAngleToNeighbors(point)) - if (this->isNegativeDirectionBorder(point)) + if (this->isUnterExtendedFace(point, s)) { + if (this->isNotNextToFace(point)) { + if (this->isUnderAngleToNeighbors(point)) { + if (this->isNegativeDirectionBorder(point)) { return NEGATIVE_DIRECTION_BORDER; - else + } else { return INSIDE; - else + } + } else { return 4; - else + } + } else { return 3; + } + } if (this->isQNode(point, s)) @@ -78,36 +113,36 @@ HOSTDEVICE char Triangle::isUnderFace(const Vertex &point) const return FLUID; } -HOSTDEVICE bool Triangle::isUnterExtendedFace(const Vertex & point, real &s) const +bool Triangle::isUnterExtendedFace(const Vertex & point, real &s) const { s = this->getPerpedicularDistanceFrom(point); return ((vf::Math::greaterEqual(s, 0.0f)) && s < this->layerThickness); } -HOSTDEVICE real Triangle::getPerpedicularDistanceFrom(const Vertex &P) const +real Triangle::getPerpedicularDistanceFrom(const Vertex &P) const { Vertex v = P - v1; return (v * -1.0f) * normal; } -HOSTDEVICE Vertex Triangle::getPerpedicularPointFrom(const Vertex &P) const +Vertex Triangle::getPerpedicularPointFrom(const Vertex &P) const { return P + normal * getPerpedicularDistanceFrom(P); } -HOSTDEVICE bool Triangle::isQNode(const Vertex & point, const real &s) const +bool Triangle::isQNode(const Vertex & point, const real &s) const { return (s < 0 && vf::Math::lessEqual(-s, this->layerThickness)); //calculateQs(actualPoint, actualTriangle); } -HOSTDEVICE bool Triangle::isNegativeDirectionBorder(const Vertex &point) const +bool Triangle::isNegativeDirectionBorder(const Vertex &point) const { return normal.x < 0.0f || normal.y < 0.0f || normal.z < 0.0f; //return (sVector.x < 0.0f && sVector.y < 0.0f && sVector.z < 0.0f); } -HOSTDEVICE bool Triangle::isNotNextToFace(const Vertex &point) const +bool Triangle::isNotNextToFace(const Vertex &point) const { Vertex Pb = getPerpedicularPointFrom(point); @@ -126,7 +161,7 @@ HOSTDEVICE bool Triangle::isNotNextToFace(const Vertex &point) const return vf::Math::lessEqual(g1, 0.0f) && vf::Math::lessEqual(g2, 0.0f) && vf::Math::lessEqual(g3, 0.0f); } -HOSTDEVICE bool Triangle::isUnderAngleToNeighbors(const Vertex &point) const +bool Triangle::isUnderAngleToNeighbors(const Vertex &point) const { Vertex Pci[3]; this->getClosestPointsOnEdges(Pci, point); @@ -147,7 +182,7 @@ HOSTDEVICE bool Triangle::isUnderAngleToNeighbors(const Vertex &point) const return (vf::Math::lessEqual(betaAngles[0], alphaAngles[0], eps) && vf::Math::lessEqual(betaAngles[1], alphaAngles[1], eps) && vf::Math::lessEqual(betaAngles[2], alphaAngles[2], eps)); } -HOSTDEVICE void Triangle::getClosestPointsOnEdges(Vertex arr[], const Vertex &P) const +void Triangle::getClosestPointsOnEdges(Vertex arr[], const Vertex &P) const { Vertex Pc1, Pc2, Pc3; Vertex v4 = P - v1; @@ -235,7 +270,7 @@ bool Triangle::contains(const Vertex& v) const } -HOSTDEVICE int Triangle::getNumberOfCommonEdge(const Triangle &t2) const +int Triangle::getNumberOfCommonEdge(const Triangle &t2) const { int commonEdge = 0; if (t2.contains(v1)) @@ -250,7 +285,7 @@ HOSTDEVICE int Triangle::getNumberOfCommonEdge(const Triangle &t2) const } -HOSTDEVICE int Triangle::getTriangleIntersection(const Vertex &P, const Vertex &direction, Vertex &pointOnTri, real &qVal) const +int Triangle::getTriangleIntersection(const Vertex &P, const Vertex &direction, Vertex &pointOnTri, real &qVal) const { ///// taken from ///// //http://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/moller-trumbore-ray-triangle-intersection @@ -295,7 +330,7 @@ HOSTDEVICE int Triangle::getTriangleIntersection(const Vertex &P, const Vertex & return 0; } -HOSTDEVICE void Triangle::print() const +void Triangle::print() const { printf("v1: "); v1.print(); @@ -307,14 +342,14 @@ HOSTDEVICE void Triangle::print() const normal.print(); } -CUDA_HOST bool Triangle::operator==(const Triangle &t) const +bool Triangle::operator==(const Triangle &t) const { return v1 == t.v1 && v2 == t.v2 && v3 == t.v3 && vf::Math::equal(alphaAngles[0], t.alphaAngles[0]) && vf::Math::equal(alphaAngles[1], t.alphaAngles[1]) && vf::Math::equal(alphaAngles[2], t.alphaAngles[2]); } -HOSTDEVICE void Triangle::setMinMax(real &minX, real &maxX, real &minY, real &maxY, real &minZ, real &maxZ) const +void Triangle::setMinMax(real &minX, real &maxX, real &minY, real &maxY, real &minZ, real &maxZ) const { Vertex::setMinMax(minX, maxX, minY, maxY, minZ, maxZ, v1, v2, v3); } diff --git a/src/gpu/GridGenerator/geometries/Triangle/Triangle.h b/src/gpu/GridGenerator/geometries/Triangle/Triangle.h index 9c5a33895ed57ce4beaaf1c019a15766779b9942..0017d2f71145f2608976a95018816bf81cef44b7 100644 --- a/src/gpu/GridGenerator/geometries/Triangle/Triangle.h +++ b/src/gpu/GridGenerator/geometries/Triangle/Triangle.h @@ -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 Triangle.h +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef Triangle_h #define Triangle_h @@ -17,16 +49,16 @@ struct GRIDGENERATOR_EXPORT Triangle uint patchIndex; - HOSTDEVICE Triangle(Vertex &v1, Vertex &v2, Vertex &v3, Vertex &normal); - HOSTDEVICE Triangle(Vertex &v1, Vertex &v2, Vertex &v3); - HOSTDEVICE Triangle(); + Triangle(Vertex &v1, Vertex &v2, Vertex &v3, Vertex &normal); + Triangle(Vertex &v1, Vertex &v2, Vertex &v3); + Triangle(); - HOSTDEVICE void set(const Vertex &v1, const Vertex &v2, const Vertex &v3); - HOSTDEVICE void set(int index, Vertex value); - HOSTDEVICE Vertex get(int index); - HOSTDEVICE void calcNormal(); + void set(const Vertex &v1, const Vertex &v2, const Vertex &v3); + void set(int index, Vertex value); + Vertex get(int index); + void calcNormal(); - HOSTDEVICE void initalLayerThickness(real delta); + void initalLayerThickness(real delta); Vertex getCenterOfMass() const; @@ -36,28 +68,28 @@ struct GRIDGENERATOR_EXPORT Triangle int getCommonEdge(const Triangle &t2) const; bool contains(const Vertex& v)const; - HOSTDEVICE int getNumberOfCommonEdge(const Triangle &t2) const; - HOSTDEVICE int getTriangleIntersection(const Vertex &P, const Vertex &direction, Vertex &pointOnTri, real &qVal) const; - HOSTDEVICE void print() const; + int getNumberOfCommonEdge(const Triangle &t2) const; + int getTriangleIntersection(const Vertex &P, const Vertex &direction, Vertex &pointOnTri, real &qVal) const; + void print() const; - HOSTDEVICE char isUnderFace(const Vertex &point) const; + char isUnderFace(const Vertex &point) const; - HOSTDEVICE bool isUnterExtendedFace(const Vertex & point, real &s) const; - HOSTDEVICE bool isNotNextToFace(const Vertex &point) const; - HOSTDEVICE bool isUnderAngleToNeighbors(const Vertex &point) const; - HOSTDEVICE void getClosestPointsOnEdges(Vertex arr[], const Vertex &P) const; - HOSTDEVICE real getPerpedicularDistanceFrom(const Vertex &P) const; - HOSTDEVICE Vertex getPerpedicularPointFrom(const Vertex &P) const; - HOSTDEVICE bool isQNode(const Vertex & point, const real &s) const; - HOSTDEVICE bool isNegativeDirectionBorder(const Vertex & point) const; + bool isUnterExtendedFace(const Vertex & point, real &s) const; + bool isNotNextToFace(const Vertex &point) const; + bool isUnderAngleToNeighbors(const Vertex &point) const; + void getClosestPointsOnEdges(Vertex arr[], const Vertex &P) const; + real getPerpedicularDistanceFrom(const Vertex &P) const; + Vertex getPerpedicularPointFrom(const Vertex &P) const; + bool isQNode(const Vertex & point, const real &s) const; + bool isNegativeDirectionBorder(const Vertex & point) const; - CUDA_HOST bool operator==(const Triangle &t) const; + bool operator==(const Triangle &t) const; - CUDA_HOST TriangleMemento getState() const; - CUDA_HOST void setState(const TriangleMemento &memento); + TriangleMemento getState() const; + void setState(const TriangleMemento &memento); - HOSTDEVICE void setMinMax(real &minX, real &maxX, real &minY, real &maxY, real &minZ, real &maxZ) const; + void setMinMax(real &minX, real &maxX, real &minY, real &maxY, real &minZ, real &maxZ) const; }; #endif diff --git a/src/gpu/GridGenerator/geometries/Triangle/TriangleException.h b/src/gpu/GridGenerator/geometries/Triangle/TriangleException.h deleted file mode 100644 index 962a471b3afb80066047e80ab34601d8266c9937..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/geometries/Triangle/TriangleException.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef meshGenExcpetion_h -#define meshGenExcpetion_h - -#include <exception> -#include <iostream> -#include <string> -#include <sstream> - -class meshGenExcpetion : public std::exception { -public: - virtual const char* what() const throw() = 0; -}; - -class nullVectorImpossibleToCalculateAngle : public meshGenExcpetion -{ - const char* what() const throw() { - std::ostringstream getNr; - getNr << "nullVectorImpossibleToCalculateAngle."; - return getNr.str().c_str(); - } -}; - -class calculateAngleWhenTrianglesHaveNoCommonEdge : public meshGenExcpetion -{ - const char* what() const throw() { - std::ostringstream getNr; - getNr << "Triangles have no common Edge."; - return getNr.str().c_str(); - } -}; - -class invalidTriangles : public meshGenExcpetion -{ - const char* what() const throw() { - std::ostringstream getNr; - getNr << "Triangles not valid."; - return getNr.str().c_str(); - } -}; - -class invalidDelta : public meshGenExcpetion -{ - const char* what() const throw() { - std::ostringstream getNr; - getNr << "Delta cant be < Null. To enable no changes change delta to 1.0."; - return getNr.str().c_str(); - } -}; - -class compareSameTriangleToFindNeighbor : public meshGenExcpetion -{ - const char* what() const throw() { - std::ostringstream getNr; - getNr << "Triangle Container function problem."; - return getNr.str().c_str(); - } -}; - -class normalFromTwoAdjacentTrianglesShowInOppositeDirection : public meshGenExcpetion -{ - const char* what() const throw() { - std::ostringstream getNr; - getNr << "STL broken, it is not allowed that two adjacent Triangles have a normal that shows in the opposite direction."; - return getNr.str().c_str(); - } -}; - - -#endif diff --git a/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMesh.cu b/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMesh.cpp similarity index 74% rename from src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMesh.cu rename to src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMesh.cpp index 31d8af624f35f1cc20ad1b8f627f5a56408f35f4..a11384887074aa6b42bff77dd8b7ee1ade8fc9e0 100644 --- a/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMesh.cu +++ b/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMesh.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 TriangularMesh.cpp +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "TriangularMesh.h" #include "Core/Timer/Timer.h" @@ -96,12 +128,12 @@ void TriangularMesh::initalizeDataFromTriangles() this->triangles = triangleVec.data(); this->size = long(triangleVec.size()); - for (std::size_t i = 0; i < this->size; i++) { + for (std::size_t i = 0; i < (size_t)this->size; i++) { this->minmax.setMinMax(this->triangleVec[i]); } } -CUDA_HOST bool TriangularMesh::operator==(const TriangularMesh &geometry) const +bool TriangularMesh::operator==(const TriangularMesh &geometry) const { if (!(minmax == geometry.minmax)) return false; @@ -116,12 +148,12 @@ CUDA_HOST bool TriangularMesh::operator==(const TriangularMesh &geometry) const } -HOSTDEVICE GbTriFaceMesh3D* TriangularMesh::getGbTriFaceMesh3D() const +GbTriFaceMesh3D* TriangularMesh::getGbTriFaceMesh3D() const { return this->VF_GbTriFaceMesh3D.get(); } -CUDA_HOST GRIDGENERATOR_EXPORT void TriangularMesh::generateGbTriFaceMesh3D() +GRIDGENERATOR_EXPORT void TriangularMesh::generateGbTriFaceMesh3D() { if( this->VF_GbTriFaceMesh3D ) return; @@ -130,7 +162,7 @@ CUDA_HOST GRIDGENERATOR_EXPORT void TriangularMesh::generateGbTriFaceMesh3D() std::vector<GbTriFaceMesh3D::Vertex> *gbVertices = new std::vector<GbTriFaceMesh3D::Vertex>(this->triangleVec.size() * 3); std::vector<GbTriFaceMesh3D::TriFace> *gbTriangles = new std::vector<GbTriFaceMesh3D::TriFace>(this->triangleVec.size()); - for (int i = 0; i < this->triangleVec.size(); i++) + for (int i = 0; i < (int)this->triangleVec.size(); i++) { (*gbVertices)[i * 3] = GbTriFaceMesh3D::Vertex(triangles[i].v1.x, triangles[i].v1.y, triangles[i].v1.z); (*gbVertices)[i * 3 + 1] = GbTriFaceMesh3D::Vertex(triangles[i].v2.x, triangles[i].v2.y, triangles[i].v2.z); @@ -244,8 +276,8 @@ std::vector<Vertex> TriangularMesh::getAverrageNormalsPerVertex(std::vector<std: void TriangularMesh::eliminateTriangleswithIdenticialNormal(std::vector<Triangle> &triangles) { - for (int i = 0; i < triangles.size() - 1; i++) { - for (int j = i + 1; j < triangles.size(); j++) { + for (std::size_t i = 0; i < triangles.size() - 1; i++) { + for (std::size_t j = i + 1; j < triangles.size(); j++) { if (triangles[i].normal == triangles[j].normal) triangles.erase(triangles.begin() + i); } diff --git a/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMesh.h b/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMesh.h index fcb937f552e9d4ccb20b0c2cc15380918dc9b2e5..3ecacc9f71f6817659f67431dd91d95e40455ad4 100644 --- a/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMesh.h +++ b/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMesh.h @@ -1,5 +1,37 @@ -#ifndef Geometry_h -#define Geometry_h +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// 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 TriangularMesh.h +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz, Martin Schoenherr +//======================================================================================= +#ifndef TriangularMesh_h +#define TriangularMesh_h #include <stdio.h> #include <cuda_runtime.h> @@ -28,7 +60,7 @@ public: GRIDGENERATOR_EXPORT TriangularMesh(); GRIDGENERATOR_EXPORT TriangularMesh(const std::string& inputPath, const std::vector<uint> ignorePatches = std::vector<uint>()); GRIDGENERATOR_EXPORT TriangularMesh(const std::string& inputPath, const BoundingBox &box); - HOSTDEVICE GRIDGENERATOR_EXPORT ~TriangularMesh(); + GRIDGENERATOR_EXPORT ~TriangularMesh(); GRIDGENERATOR_EXPORT uint getNumberOfTriangles() const; @@ -42,13 +74,13 @@ public: SPtr<GbTriFaceMesh3D> VF_GbTriFaceMesh3D; - CUDA_HOST GRIDGENERATOR_EXPORT bool operator==(const TriangularMesh &geometry) const; + GRIDGENERATOR_EXPORT bool operator==(const TriangularMesh &geometry) const; GRIDGENERATOR_EXPORT void findNeighbors(); - HOSTDEVICE GRIDGENERATOR_EXPORT GbTriFaceMesh3D* getGbTriFaceMesh3D() const; + GRIDGENERATOR_EXPORT GbTriFaceMesh3D* getGbTriFaceMesh3D() const; - CUDA_HOST GRIDGENERATOR_EXPORT void generateGbTriFaceMesh3D(); + GRIDGENERATOR_EXPORT void generateGbTriFaceMesh3D(); private: @@ -58,7 +90,7 @@ private: static void eliminateTriangleswithIdenticialNormal(std::vector<Triangle> &triangles); public: - HOSTDEVICE Object* clone() const override; + Object* clone() const override; double getX1Centroid() override { throw "Not implemented in TriangularMesh"; } double getX1Minimum() override { return minmax.minX; } double getX1Maximum() override { return minmax.maxX; } @@ -69,7 +101,7 @@ public: double getX3Minimum() override { return minmax.minZ; } double getX3Maximum() override { return minmax.maxZ; } void scale(double delta) override; - HOSTDEVICE bool isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, + bool isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, const double& maxOffset) override { return false; } diff --git a/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMeshStrategy.cpp b/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMeshStrategy.cpp index 61a499a31a57a60f3c98bd4a7c600699cea77aa2..d9c1486e2ca9469d55174eca673f22f180a78294 100644 --- a/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMeshStrategy.cpp +++ b/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMeshStrategy.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 TriangularMeshStrategy.cpp +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "TriangularMeshStrategy.h" #include "Core/Timer/Timer.h" @@ -248,7 +280,7 @@ void PointUnderTriangleStrategy::meshReverse(Triangle& triangle, GridImp* grid, } } -HOSTDEVICE void PointUnderTriangleStrategy::findInsideNodes(GridImp* grid, char innerType) +void PointUnderTriangleStrategy::findInsideNodes(GridImp* grid, char innerType) { bool foundInsideNode = true; while (foundInsideNode) @@ -259,7 +291,7 @@ HOSTDEVICE void PointUnderTriangleStrategy::findInsideNodes(GridImp* grid, char } } -HOSTDEVICE void PointUnderTriangleStrategy::setInsideNode(GridImp* grid, const uint &index, bool &insideNodeFound, char innerType) +void PointUnderTriangleStrategy::setInsideNode(GridImp* grid, const uint &index, bool &insideNodeFound, char innerType) { if (grid->isNode(index, NEGATIVE_DIRECTION_BORDER)) return; @@ -271,7 +303,7 @@ HOSTDEVICE void PointUnderTriangleStrategy::setInsideNode(GridImp* grid, const u } } -HOSTDEVICE void PointUnderTriangleStrategy::setNegativeDirBorderTo(GridImp* grid, const uint &index, char innerType) +void PointUnderTriangleStrategy::setNegativeDirBorderTo(GridImp* grid, const uint &index, char innerType) { if (grid->isNode(index, NEGATIVE_DIRECTION_BORDER)) grid->setNodeTo(index, innerType); diff --git a/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMeshStrategy.h b/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMeshStrategy.h index 98d852962310fb135a19fc57067d417b86994a2c..573a464844ac769ebd1127c666481b87f363099f 100644 --- a/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMeshStrategy.h +++ b/src/gpu/GridGenerator/geometries/TriangularMesh/TriangularMeshStrategy.h @@ -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 TriangularMeshStrategy.h +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef TriangularMeshStrategy_H #define TriangularMeshStrategy_H @@ -53,13 +85,13 @@ public: void doDiscretize(TriangularMesh* triangularMesh, GridImp* grid, char innerType, char outerType) override; private: - HOSTDEVICE void meshReverse(Triangle& triangle, GridImp* grid, char innerType); + void meshReverse(Triangle& triangle, GridImp* grid, char innerType); - HOSTDEVICE void findInsideNodes(GridImp* grid, char innerType); + void findInsideNodes(GridImp* grid, char innerType); - HOSTDEVICE void setInsideNode(GridImp* grid, const uint &index, bool &insideNodeFound, char innerType); + void setInsideNode(GridImp* grid, const uint &index, bool &insideNodeFound, char innerType); - HOSTDEVICE void setNegativeDirBorderTo(GridImp* grid, const uint &index, char innerType); + void setNegativeDirBorderTo(GridImp* grid, const uint &index, char innerType); }; diff --git a/src/gpu/GridGenerator/geometries/TriangularMesh/triangleNeighborFinder/TriangleNeighborFinder.cpp b/src/gpu/GridGenerator/geometries/TriangularMesh/triangleNeighborFinder/TriangleNeighborFinder.cpp index 4fc0e6dedc287ced661bbea5d1a1f6c30734c70b..08984d872ebf07cbe1d88658b48a7850077f188f 100644 --- a/src/gpu/GridGenerator/geometries/TriangularMesh/triangleNeighborFinder/TriangleNeighborFinder.cpp +++ b/src/gpu/GridGenerator/geometries/TriangularMesh/triangleNeighborFinder/TriangleNeighborFinder.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 TriangleNeighborFinder.cpp +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "TriangleNeighborFinder.h" #include <omp.h> diff --git a/src/gpu/GridGenerator/geometries/TriangularMesh/triangleNeighborFinder/TriangleNeighborFinder.h b/src/gpu/GridGenerator/geometries/TriangularMesh/triangleNeighborFinder/TriangleNeighborFinder.h index be0ebc5d004bd8bff9b96d48d68064d134238afb..b0dda279c5f95a621b5875e78b5cdb7479b98a54 100644 --- a/src/gpu/GridGenerator/geometries/TriangularMesh/triangleNeighborFinder/TriangleNeighborFinder.h +++ b/src/gpu/GridGenerator/geometries/TriangularMesh/triangleNeighborFinder/TriangleNeighborFinder.h @@ -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 TriangleNeighborFinder.h +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef TriangleNeighborFinder_h #define TriangleNeighborFinder_h diff --git a/src/gpu/GridGenerator/geometries/TriangularMesh/triangleRefinement/TriangleRefinement.cpp b/src/gpu/GridGenerator/geometries/TriangularMesh/triangleRefinement/TriangleRefinement.cpp index d979839251d3e3efc2d610c29a5323f9560a6611..c1babac2324e80362c62c2b448cd1e309d7c5adf 100644 --- a/src/gpu/GridGenerator/geometries/TriangularMesh/triangleRefinement/TriangleRefinement.cpp +++ b/src/gpu/GridGenerator/geometries/TriangularMesh/triangleRefinement/TriangleRefinement.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 TriangleRefinement.cpp +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "TriangleRefinement.h" #include <GridGenerator/geometries/Triangle/Triangle.h> diff --git a/src/gpu/GridGenerator/geometries/TriangularMesh/triangleRefinement/TriangleRefinement.h b/src/gpu/GridGenerator/geometries/TriangularMesh/triangleRefinement/TriangleRefinement.h index 2cd5045a12ef5267f0d1971f799a55cd081badbd..a9c5262fbf0ee701e26885fb54d96cd079038a87 100644 --- a/src/gpu/GridGenerator/geometries/TriangularMesh/triangleRefinement/TriangleRefinement.h +++ b/src/gpu/GridGenerator/geometries/TriangularMesh/triangleRefinement/TriangleRefinement.h @@ -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 TriangleRefinement.h +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef TriangleRefinement_h #define TriangleRefinement_h diff --git a/src/gpu/GridGenerator/geometries/Vertex/Vertex.cpp b/src/gpu/GridGenerator/geometries/Vertex/Vertex.cpp new file mode 100644 index 0000000000000000000000000000000000000000..100e88dda9567a43f90ea346260164b30f06e2c9 --- /dev/null +++ b/src/gpu/GridGenerator/geometries/Vertex/Vertex.cpp @@ -0,0 +1,195 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// 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 Vertex.cpp +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= +#include "Vertex.h" + +#include "utilities/math/Math.h" + +Vertex::Vertex(real x, real y, real z) : x(x), y(y), z(z){} +Vertex::Vertex() { x = 0.0f; y = 0.0f; z = 0.0f; } + + real Vertex::getEuclideanDistanceTo(const Vertex &w) const +{ + return vf::Math::sqrtReal((x - w.x)*(x - w.x) + (y - w.y)*(y - w.y) + (z - w.z)*(z - w.z)); +} + +Vertex Vertex::operator-(const Vertex &v) const +{ + return Vertex(x - v.x, y - v.y, z - v.z); +} + +Vertex Vertex::operator+(const Vertex &v) const +{ + return Vertex(this->x + v.x, this->y + v.y, this->z + v.z); +} + +Vertex Vertex::operator*(const real& value) const +{ + return Vertex(value * this->x, value * this->y, value * this->z); +} + +Vertex Vertex::operator/(const real& value) const +{ + return *this * ((real)1.0 / value); +} + +real Vertex::operator*(const Vertex &w) const +{ + return x*w.x + y*w.y + z*w.z; +} + +struct Vertex Vertex::crossProduct(const Vertex &w) const +{ + real a = y*w.z - z*w.y; + real b = z*w.x - x*w.z; + real c = x*w.y - y*w.x; + return Vertex(a, b, c); +} + +real Vertex::length() const +{ + return vf::Math::sqrtReal(x * x + y * y + z * z); +} + +void Vertex::normalize() +{ + real len = length(); + + if (len > EPSILON) + { + real invLen = 1.0f / len; + x *= invLen; + y *= invLen; + z *= invLen; + } +} + +real Vertex::getMagnitude() const +{ + real temp = x*x + y*y + z*z; + return vf::Math::sqrtReal(temp); +} + +int Vertex::isEqual(const Vertex &w) const +{ + return vf::Math::equal(x, w.x) && vf::Math::equal(y, w.y) && vf::Math::equal(z, w.z); +} + +real Vertex::getInnerAngle(const Vertex &w) const +{ + if (isEqual(w)) + return 0.0; + if (this->getMagnitude() == 0 || w.getMagnitude() == 0) + return 0.0; + + real mag = this->getMagnitude() * w.getMagnitude(); + real skal = *this * w; + if (mag - std::abs(skal) < 0.0001) + return 0.0f; + return vf::Math::acosReal(skal / mag) * 180.0f / vf::Math::acosReal(-1.0f); // acos(-1.0f) = PI +} + +void Vertex::print() const +{ + printf("(%2.8f,%2.8f,%2.8f)\n", x, y, z); +} + +void Vertex::print(std::ostream &ost) const +{ + ost.write((char*)&x, 4); + ost.write((char*)&y, 4); + ost.write((char*)&z, 4); +} + +void Vertex::printFormatted(std::ostream &ost) const +{ + ost << x << " " << y << " " << z; +} + + + +bool Vertex::operator==(const Vertex &v) const +{ + return vf::Math::equal(x, v.x) && vf::Math::equal(y, v.y) && vf::Math::equal(z, v.z); +} + + +bool Vertex::isXbetween(real min, real max) const +{ + return x >= min && x <= max; +} + +bool Vertex::isYbetween(real min, real max) const +{ + return y >= min && y <= max; +} + +bool Vertex::isZbetween(real min, real max) const +{ + return z >= min && z <= max; +} + +void Vertex::setMinMax(real & minX, real & maxX, real & minY, real & maxY, real & minZ, real & maxZ, const Vertex & v1, const Vertex & v2, const Vertex & v3) +{ + calculateMinMax(v1.x, v2.x, v3.x, minX, maxX); + calculateMinMax(v1.y, v2.y, v3.y, minY, maxY); + calculateMinMax(v1.z, v2.z, v3.z, minZ, maxZ); +} + + +real getMinimum(const real &value1, const real &value2) +{ + return value1 < value2 ? value1 : value2; +} + +real getMaximum(const real &value1, const real &value2) +{ + return value1 > value2 ? value1 : value2; +} + + +void Vertex::calculateMinMax(const real &value1, const real &value2, const real &value3, real &min, real &max) +{ + + real newMinimum = value1; + newMinimum = getMinimum(value2, newMinimum); + newMinimum = getMinimum(value3, newMinimum); + + real newMaximum = value1; + newMaximum = getMaximum(value2, newMaximum); + newMaximum = getMaximum(value3, newMaximum); + + min = newMinimum; + max = newMaximum; +} + + diff --git a/src/gpu/GridGenerator/geometries/Vertex/Vertex.cu b/src/gpu/GridGenerator/geometries/Vertex/Vertex.cu deleted file mode 100644 index 875bd4c1d03013f3e33fb9c30f583b82feb6bcf6..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/geometries/Vertex/Vertex.cu +++ /dev/null @@ -1,178 +0,0 @@ -#include "Vertex.h" - -#include "utilities/math/Math.h" - -HOSTDEVICE Vertex::Vertex(real x, real y, real z) : x(x), y(y), z(z){} -HOSTDEVICE Vertex::Vertex() { x = 0.0f; y = 0.0f; z = 0.0f; } - -HOSTDEVICE Vertex::Vertex(const Vertex& v) -{ - this->x = v.x; - this->y = v.y; - this->z = v.z; -} - -HOSTDEVICE Vertex& Vertex::operator=(const Vertex& v) -{ - this->x = v.x; - this->y = v.y; - this->z = v.z; - return *this; -} - -HOSTDEVICE real Vertex::getEuclideanDistanceTo(const Vertex &w) const -{ - return vf::Math::sqrtReal((x - w.x)*(x - w.x) + (y - w.y)*(y - w.y) + (z - w.z)*(z - w.z)); -} - -HOSTDEVICE Vertex Vertex::operator-(const Vertex &v) const -{ - return Vertex(x - v.x, y - v.y, z - v.z); -} - -HOSTDEVICE Vertex Vertex::operator+(const Vertex &v) const -{ - return Vertex(this->x + v.x, this->y + v.y, this->z + v.z); -} - -HOSTDEVICE Vertex Vertex::operator*(const real& value) const -{ - return Vertex(value * this->x, value * this->y, value * this->z); -} - -HOSTDEVICE Vertex Vertex::operator/(const real& value) const -{ - return *this * (1.0 / value); -} - -HOSTDEVICE real Vertex::operator*(const Vertex &w) const -{ - return x*w.x + y*w.y + z*w.z; -} - -HOSTDEVICE struct Vertex Vertex::crossProduct(const Vertex &w) const -{ - real a = y*w.z - z*w.y; - real b = z*w.x - x*w.z; - real c = x*w.y - y*w.x; - return Vertex(a, b, c); -} - -HOSTDEVICE real Vertex::length() const -{ - return vf::Math::sqrtReal(x * x + y * y + z * z); -} - -HOSTDEVICE void Vertex::normalize() -{ - real len = length(); - - if (len > EPSILON) - { - real invLen = 1.0f / len; - x *= invLen; - y *= invLen; - z *= invLen; - } -} - -HOSTDEVICE real Vertex::getMagnitude() const -{ - real temp = x*x + y*y + z*z; - return vf::Math::sqrtReal(temp); -} - -HOSTDEVICE int Vertex::isEqual(const Vertex &w) const -{ - return vf::Math::equal(x, w.x) && vf::Math::equal(y, w.y) && vf::Math::equal(z, w.z); -} - -HOSTDEVICE real Vertex::getInnerAngle(const Vertex &w) const -{ - if (isEqual(w)) - return 0.0; - if (this->getMagnitude() == 0 || w.getMagnitude() == 0) - return 0.0; - - real mag = this->getMagnitude() * w.getMagnitude(); - real skal = *this * w; - if (mag - fabs(skal) < 0.0001) - return 0.0f; - return vf::Math::acosReal(skal / mag) * 180.0f / vf::Math::acosReal(-1.0f); // acos(-1.0f) = PI -} - -HOSTDEVICE void Vertex::print() const -{ - printf("(%2.8f,%2.8f,%2.8f)\n", x, y, z); -} - -CUDA_HOST void Vertex::print(std::ostream &ost) const -{ - ost.write((char*)&x, 4); - ost.write((char*)&y, 4); - ost.write((char*)&z, 4); -} - -CUDA_HOST void Vertex::printFormatted(std::ostream &ost) const -{ - ost << x << " " << y << " " << z; -} - - - -HOSTDEVICE bool Vertex::operator==(const Vertex &v) const -{ - return vf::Math::equal(x, v.x) && vf::Math::equal(y, v.y) && vf::Math::equal(z, v.z); -} - - -CUDA_HOST bool Vertex::isXbetween(real min, real max) const -{ - return x >= min && x <= max; -} - -CUDA_HOST bool Vertex::isYbetween(real min, real max) const -{ - return y >= min && y <= max; -} - -CUDA_HOST bool Vertex::isZbetween(real min, real max) const -{ - return z >= min && z <= max; -} - -HOSTDEVICE void Vertex::setMinMax(real & minX, real & maxX, real & minY, real & maxY, real & minZ, real & maxZ, const Vertex & v1, const Vertex & v2, const Vertex & v3) -{ - calculateMinMax(v1.x, v2.x, v3.x, minX, maxX); - calculateMinMax(v1.y, v2.y, v3.y, minY, maxY); - calculateMinMax(v1.z, v2.z, v3.z, minZ, maxZ); -} - - -HOSTDEVICE real getMinimum(const real &value1, const real &value2) -{ - return value1 < value2 ? value1 : value2; -} - -HOSTDEVICE real getMaximum(const real &value1, const real &value2) -{ - return value1 > value2 ? value1 : value2; -} - - -HOSTDEVICE void Vertex::calculateMinMax(const real &value1, const real &value2, const real &value3, real &min, real &max) -{ - - real newMinimum = value1; - newMinimum = getMinimum(value2, newMinimum); - newMinimum = getMinimum(value3, newMinimum); - - real newMaximum = value1; - newMaximum = getMaximum(value2, newMaximum); - newMaximum = getMaximum(value3, newMaximum); - - min = newMinimum; - max = newMaximum; -} - - diff --git a/src/gpu/GridGenerator/geometries/Vertex/Vertex.h b/src/gpu/GridGenerator/geometries/Vertex/Vertex.h index cabbc21c92113b490d31b6e6ae9ad834b41fd44b..492c7e1a0de34336d15a8a3c3030dc6733310d8b 100644 --- a/src/gpu/GridGenerator/geometries/Vertex/Vertex.h +++ b/src/gpu/GridGenerator/geometries/Vertex/Vertex.h @@ -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 Vertex.h +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef VERTEX_H #define VERTEX_H @@ -8,48 +40,41 @@ #include "global.h" -class VertexMemento; - struct GRIDGENERATOR_EXPORT Vertex { public: real x, y, z; - HOSTDEVICE Vertex(real x, real y, real z); - HOSTDEVICE Vertex(); - HOSTDEVICE Vertex(const Vertex& v); - HOSTDEVICE Vertex& operator=(const Vertex&); - HOSTDEVICE ~Vertex() {} - - HOSTDEVICE real getEuclideanDistanceTo(const Vertex &w) const; - HOSTDEVICE Vertex operator-(const Vertex &v) const; - HOSTDEVICE Vertex operator+(const Vertex &v) const; - HOSTDEVICE Vertex operator*(const real& value) const; - HOSTDEVICE Vertex operator/(const real& value) const; - - HOSTDEVICE real operator*(const Vertex &w) const; - HOSTDEVICE struct Vertex crossProduct(const Vertex &w) const; - HOSTDEVICE real length() const; - HOSTDEVICE void normalize(); - HOSTDEVICE real getMagnitude() const; - HOSTDEVICE int isEqual(const Vertex &w) const; - HOSTDEVICE real getInnerAngle(const Vertex &w) const; - - HOSTDEVICE bool operator==(const Vertex &v) const; - - CUDA_HOST VertexMemento getState() const; - CUDA_HOST void setState(const VertexMemento &memento); - - CUDA_HOST bool isXbetween(real min, real max) const; - CUDA_HOST bool isYbetween(real min, real max) const; - CUDA_HOST bool isZbetween(real min, real max) const; - - HOSTDEVICE static void setMinMax(real &minX, real &maxX, real &minY, real &maxY, real &minZ, real &maxZ, const Vertex &v1, const Vertex &v2, const Vertex &v3); - HOSTDEVICE static void calculateMinMax(const real &value1, const real &value2, const real &value3, real &min, real &max); - - HOSTDEVICE void print() const; - CUDA_HOST void print(std::ostream &ost) const; - CUDA_HOST void printFormatted(std::ostream &ost) const; + Vertex(real x, real y, real z); + Vertex(); + ~Vertex() {} + + real getEuclideanDistanceTo(const Vertex &w) const; + Vertex operator-(const Vertex &v) const; + Vertex operator+(const Vertex &v) const; + Vertex operator*(const real& value) const; + Vertex operator/(const real& value) const; + + real operator*(const Vertex &w) const; + struct Vertex crossProduct(const Vertex &w) const; + real length() const; + void normalize(); + real getMagnitude() const; + int isEqual(const Vertex &w) const; + real getInnerAngle(const Vertex &w) const; + + bool operator==(const Vertex &v) const; + + bool isXbetween(real min, real max) const; + bool isYbetween(real min, real max) const; + bool isZbetween(real min, real max) const; + + static void setMinMax(real &minX, real &maxX, real &minY, real &maxY, real &minZ, real &maxZ, const Vertex &v1, const Vertex &v2, const Vertex &v3); + static void calculateMinMax(const real &value1, const real &value2, const real &value3, real &min, real &max); + + void print() const; + void print(std::ostream &ost) const; + void printFormatted(std::ostream &ost) const; }; diff --git a/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.cpp b/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.cpp new file mode 100644 index 0000000000000000000000000000000000000000..89bcd50349fe1a7591c5a873b5924a0c8ce8c2f3 --- /dev/null +++ b/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.cpp @@ -0,0 +1,122 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// 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 VerticalCylinder.cpp +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= +#include "VerticalCylinder.h" + +VerticalCylinder::VerticalCylinder(const double& centerX, const double& centerY, const double& centerZ, const double& radius, const double& height) + : centerX(centerX), centerY(centerY), centerZ(centerZ), radius(radius), height(height) +{ + +} + +VerticalCylinder::~VerticalCylinder() +{ +} + +SPtr<VerticalCylinder> VerticalCylinder::makeShared(double centerX, double centerY, double centerZ, double radius, double height) +{ + return SPtr<VerticalCylinder>(new VerticalCylinder(centerX, centerY, centerZ, radius, height)); +} + +Object* VerticalCylinder::clone() const +{ + return new VerticalCylinder(centerX, centerY, centerZ, radius, height); +} + +double VerticalCylinder::getX1Centroid() +{ + return centerX; +} + +double VerticalCylinder::getX1Minimum() +{ + return centerX - radius; +} + +double VerticalCylinder::getX1Maximum() +{ + return centerX + radius; +} + +double VerticalCylinder::getX2Centroid() +{ + return centerY; +} + +double VerticalCylinder::getX2Minimum() +{ + return centerY - radius; +} + +double VerticalCylinder::getX2Maximum() +{ + return centerY + radius; +} + +double VerticalCylinder::getX3Centroid() +{ + return centerZ; +} + +double VerticalCylinder::getX3Minimum() +{ + return centerZ - 0.5 * height; +} + +double VerticalCylinder::getX3Maximum() +{ + return centerZ + 0.5 * height; +} + +bool VerticalCylinder::isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, const double& maxOffset) +{ + double offset = maxOffset; + if (x1 < centerX || x2 < centerY || x3 < centerZ) + offset = minOffset; + + + const double deltaX1 = x1 - centerX; + const double deltaX2 = x2 - centerY; + const double deltaX3 = x3 - centerZ; + + if( deltaX3 > 0.5 * height || deltaX3 < - 0.5 * height ) + return false; + + return (deltaX1*deltaX1 + deltaX2*deltaX2) < ((this->radius - offset) * (this->radius - offset)); +} + + +void VerticalCylinder::scale(double delta) +{ + this->radius += delta; + this->height += delta; +} diff --git a/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.cu b/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.cu deleted file mode 100644 index 16a2640c17b861c90e0610aa51ae4f25140853cf..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.cu +++ /dev/null @@ -1,90 +0,0 @@ -#include "VerticalCylinder.h" - -VerticalCylinder::VerticalCylinder(const double& centerX, const double& centerY, const double& centerZ, const double& radius, const double& height) - : centerX(centerX), centerY(centerY), centerZ(centerZ), radius(radius), height(height) -{ - -} - -VerticalCylinder::~VerticalCylinder() -{ -} - -SPtr<VerticalCylinder> VerticalCylinder::makeShared(double centerX, double centerY, double centerZ, double radius, double height) -{ - return SPtr<VerticalCylinder>(new VerticalCylinder(centerX, centerY, centerZ, radius, height)); -} - -Object* VerticalCylinder::clone() const -{ - return new VerticalCylinder(centerX, centerY, centerZ, radius, height); -} - -double VerticalCylinder::getX1Centroid() -{ - return centerX; -} - -double VerticalCylinder::getX1Minimum() -{ - return centerX - radius; -} - -double VerticalCylinder::getX1Maximum() -{ - return centerX + radius; -} - -double VerticalCylinder::getX2Centroid() -{ - return centerY; -} - -double VerticalCylinder::getX2Minimum() -{ - return centerY - radius; -} - -double VerticalCylinder::getX2Maximum() -{ - return centerY + radius; -} - -double VerticalCylinder::getX3Centroid() -{ - return centerZ; -} - -double VerticalCylinder::getX3Minimum() -{ - return centerZ - 0.5 * height; -} - -double VerticalCylinder::getX3Maximum() -{ - return centerZ + 0.5 * height; -} - -bool VerticalCylinder::isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, const double& maxOffset) -{ - double offset = maxOffset; - if (x1 < centerX || x2 < centerY || x3 < centerZ) - offset = minOffset; - - - const double deltaX1 = x1 - centerX; - const double deltaX2 = x2 - centerY; - const double deltaX3 = x3 - centerZ; - - if( deltaX3 > 0.5 * height || deltaX3 < - 0.5 * height ) - return false; - - return (deltaX1*deltaX1 + deltaX2*deltaX2) < ((this->radius - offset) * (this->radius - offset)); -} - - -void VerticalCylinder::scale(double delta) -{ - this->radius += delta; - this->height += delta; -} diff --git a/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.h b/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.h index e1ee6fc3dbfe3f4594e344c0cb54136bca8149a1..24d9383bf5628e46b1d634874f79ceb73eaa6cae 100644 --- a/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.h +++ b/src/gpu/GridGenerator/geometries/VerticalCylinder/VerticalCylinder.h @@ -1,9 +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 VerticalCylinder.h +//! \ingroup geometries +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef VERTICAL_CYLINDER_H #define VERTICAL_CYLINDER_H @@ -14,12 +40,12 @@ class GRIDGENERATOR_EXPORT VerticalCylinder : public Object { public: - HOSTDEVICE VerticalCylinder(const double& centerX, const double& centerY, const double& centerZ, const double& radius, const double& height); - HOSTDEVICE virtual ~VerticalCylinder(); + VerticalCylinder(const double& centerX, const double& centerY, const double& centerZ, const double& radius, const double& height); + virtual ~VerticalCylinder(); static SPtr<VerticalCylinder> makeShared(double centerX, double centerY, double centerZ, double radius, double height); - HOSTDEVICE Object* clone() const override; + Object* clone() const override; double getX1Centroid() override; double getX1Minimum() override; @@ -31,7 +57,7 @@ public: double getX3Minimum() override; double getX3Maximum() override; - HOSTDEVICE bool isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, const double& maxOffset) override; + bool isPointInObject(const double& x1, const double& x2, const double& x3, const double& minOffset, const double& maxOffset) override; void scale(double delta) override; diff --git a/src/gpu/GridGenerator/global.h b/src/gpu/GridGenerator/global.h index 3378265eaa60cd713f4d932f59eaa04f680b4543..19bedc95b9a767f30761279500c6b8c036509eba 100644 --- a/src/gpu/GridGenerator/global.h +++ b/src/gpu/GridGenerator/global.h @@ -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 global.h +//! \ingroup GridGenerator +//! \author Soeren Peters +//======================================================================================= #ifndef global_h #define global_h @@ -8,6 +40,7 @@ #define MASTERRANK 0 + #include "GridGenerator_export.h" #include "PointerDefinitions.h" @@ -15,6 +48,4 @@ #include "Core/Logger/Logger.h" -#include "utilities/cuda/cudaDefines.h" - #endif diff --git a/src/gpu/GridGenerator/grid/BoundaryConditions/BoundaryCondition.cpp b/src/gpu/GridGenerator/grid/BoundaryConditions/BoundaryCondition.cpp index fb60958c61e6fa53a546a8b5783e313712897123..8930bdf3b165b4e0dbb497773fd0b6cf6ec6f8f7 100644 --- a/src/gpu/GridGenerator/grid/BoundaryConditions/BoundaryCondition.cpp +++ b/src/gpu/GridGenerator/grid/BoundaryConditions/BoundaryCondition.cpp @@ -1,24 +1,57 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// 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 BoundaryCondition.cpp +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "BoundaryCondition.h" #include <cmath> -#include "GridGenerator_export.h" + #include "grid/BoundaryConditions/Side.h" #include "grid/Grid.h" -bool BoundaryCondition::isSide( SideType side ) const +bool gg::BoundaryCondition::isSide( SideType side ) const { return this->side->whoAmI() == side; } -GRIDGENERATOR_EXPORT void VelocityBoundaryCondition::setVelocityProfile(SPtr<Grid> grid, std::function<void(real, real, real, real&, real&, real&)> velocityProfile) +void VelocityBoundaryCondition::setVelocityProfile( + SPtr<Grid> grid, std::function<void(real, real, real, real &, real &, real &)> velocityProfile) { - for( uint index = 0; index < this->indices.size(); index++ ){ + for (uint index = 0; index < this->indices.size(); index++) { - real x, y, z; + real x, y, z; - grid->transIndexToCoords( this->indices[index], x, y, z ); + grid->transIndexToCoords(this->indices[index], x, y, z); - velocityProfile(x,y,z,this->vxList[index],this->vyList[index],this->vzList[index]); + velocityProfile(x, y, z, this->vxList[index], this->vyList[index], this->vzList[index]); } } diff --git a/src/gpu/GridGenerator/grid/BoundaryConditions/BoundaryCondition.h b/src/gpu/GridGenerator/grid/BoundaryConditions/BoundaryCondition.h index 9da79497ca2825ab25f62c6e622ee852342cf25c..9ae5f09e208e92213ca90ff75f095eddd5dbeaf1 100644 --- a/src/gpu/GridGenerator/grid/BoundaryConditions/BoundaryCondition.h +++ b/src/gpu/GridGenerator/grid/BoundaryConditions/BoundaryCondition.h @@ -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 BoundaryCondition.h +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz, Martin Schoenherr +//======================================================================================= #ifndef BoundaryCondition_H #define BoundaryCondition_H @@ -13,6 +45,8 @@ class Grid; class Side; enum class SideType; +namespace gg +{ class BoundaryCondition { public: @@ -20,20 +54,22 @@ public: std::vector<uint> indices; SPtr<Side> side; - std::vector<std::vector<real> > qs; + std::vector<std::vector<real>> qs; std::vector<uint> patches; virtual char getType() const = 0; - bool isSide( SideType side ) const; + bool isSide(SideType side) const; - real getQ( uint index, uint dir ){ return this->qs[index][dir]; } + real getQ(uint index, uint dir) { return this->qs[index][dir]; } }; +} + ////////////////////////////////////////////////////////////////////////// -class PressureBoundaryCondition : public BoundaryCondition +class PressureBoundaryCondition : public gg::BoundaryCondition { public: static SPtr<PressureBoundaryCondition> make(real rho) @@ -62,7 +98,47 @@ public: ////////////////////////////////////////////////////////////////////////// -class VelocityBoundaryCondition : public BoundaryCondition +class SlipBoundaryCondition : public gg::BoundaryCondition +{ +public: + static SPtr<SlipBoundaryCondition> make(real normalX, real normalY, real normalZ) + { + return SPtr<SlipBoundaryCondition>(new SlipBoundaryCondition(normalX, normalY, normalZ)); + } + + real normalX, normalY, normalZ; + std::vector<real> normalXList, normalYList, normalZList; +protected: + SlipBoundaryCondition(real normalX, real normalY, real normalZ) : normalX(normalX), normalY(normalY), normalZ(normalZ) { } + +public: + virtual char getType() const override + { + return vf::gpu::BC_SLIP; + } + + void fillSlipNormalLists() + { + for (uint index : this->indices) { + (void)index; + this->normalXList.push_back(normalX); + this->normalYList.push_back(normalY); + this->normalZList.push_back(normalZ); + } + } + + real getNormalx() { return this->normalX; } + real getNormaly() { return this->normalY; } + real getNormalz() { return this->normalZ; } + + real getNormalx(uint index) { return this->normalXList[index]; } + real getNormaly(uint index) { return this->normalYList[index]; } + real getNormalz(uint index) { return this->normalZList[index]; } +}; + +////////////////////////////////////////////////////////////////////////// + +class VelocityBoundaryCondition : public gg ::BoundaryCondition { public: static SPtr<VelocityBoundaryCondition> make(real vx, real vy, real vz) @@ -98,8 +174,8 @@ public: real getVx(uint index) { return this->vxList[index]; } real getVy(uint index) { return this->vyList[index]; } real getVz(uint index) { return this->vzList[index]; } - - GRIDGENERATOR_EXPORT void setVelocityProfile( SPtr<Grid> grid, std::function<void(real,real,real,real&,real&,real&)> velocityProfile ); + + void setVelocityProfile( SPtr<Grid> grid, std::function<void(real,real,real,real&,real&,real&)> velocityProfile ); }; ////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/GridGenerator/grid/BoundaryConditions/Side.cpp b/src/gpu/GridGenerator/grid/BoundaryConditions/Side.cpp index 75cb8e23fca1a9643dbb7901f628b9e30cb1b4d7..02d61a83456090a3b96b207de5761b70d9b30fca 100644 --- a/src/gpu/GridGenerator/grid/BoundaryConditions/Side.cpp +++ b/src/gpu/GridGenerator/grid/BoundaryConditions/Side.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 Side.cpp +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "Side.h" #include "grid/BoundaryConditions/BoundaryCondition.h" @@ -6,7 +38,7 @@ #include "utilities/math/Math.h" -using namespace vf::gpu; +using namespace gg; void Side::addIndices(SPtr<Grid> grid, SPtr<BoundaryCondition> boundaryCondition, std::string coord, real constant, real startInner, real endInner, real startOuter, real endOuter) @@ -17,11 +49,11 @@ 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) == FLUID - || grid->getFieldEntry(index) == FLUID_CFC - || grid->getFieldEntry(index) == FLUID_CFF - || grid->getFieldEntry(index) == FLUID_FCC - || grid->getFieldEntry(index) == 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->setFieldEntry(index, boundaryCondition->getType()); boundaryCondition->indices.push_back(index); @@ -69,36 +101,15 @@ void Side::setQs(SPtr<Grid> grid, SPtr<BoundaryCondition> boundaryCondition, uin real x,y,z; grid->transIndexToCoords( index, x, y, z ); - real coords[3] = {x,y,z}; + x += grid->getDirection()[dir * DIMENSION + 0] * grid->getDelta(); + y += grid->getDirection()[dir * DIMENSION + 1] * grid->getDelta(); + z += grid->getDirection()[dir * DIMENSION + 2] * grid->getDelta(); - real neighborX = x + grid->getDirection()[dir * DIMENSION + 0] * grid->getDelta(); - real neighborY = y + grid->getDirection()[dir * DIMENSION + 1] * grid->getDelta(); - real neighborZ = z + grid->getDirection()[dir * DIMENSION + 2] * grid->getDelta(); + uint neighborIndex = grid->transCoordToIndex( x, y, z ); - // correct neighbor coordinates in case of periodic boundaries - if( grid->getPeriodicityX() && grid->getFieldEntry( grid->transCoordToIndex( neighborX, y, z ) ) == STOPPER_OUT_OF_GRID_BOUNDARY ) - { - if( neighborX > x ) neighborX = grid->getFirstFluidNode( coords, 0, grid->getStartX() ); - else neighborX = grid->getLastFluidNode ( coords, 0, grid->getEndX() ); - } - - if( grid->getPeriodicityY() && grid->getFieldEntry( grid->transCoordToIndex( x, neighborY, z ) ) == STOPPER_OUT_OF_GRID_BOUNDARY ) - { - if( neighborY > y ) neighborY = grid->getFirstFluidNode( coords, 1, grid->getStartY() ); - else neighborY = grid->getLastFluidNode ( coords, 1, grid->getEndY() ); - } - - if( grid->getPeriodicityZ() && grid->getFieldEntry( grid->transCoordToIndex( x, y, neighborZ ) ) == STOPPER_OUT_OF_GRID_BOUNDARY ) - { - if( neighborZ > z ) neighborZ = grid->getFirstFluidNode( coords, 2, grid->getStartZ() ); - else neighborZ = grid->getLastFluidNode ( coords, 2, grid->getEndZ() ); - } - - uint neighborIndex = grid->transCoordToIndex( neighborX, neighborY, neighborZ ); - - if( grid->getFieldEntry(neighborIndex) == STOPPER_OUT_OF_GRID_BOUNDARY || - grid->getFieldEntry(neighborIndex) == STOPPER_OUT_OF_GRID || - grid->getFieldEntry(neighborIndex) == 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 ) qNode[dir] = 0.5; else qNode[dir] = -1.0; @@ -119,47 +130,6 @@ uint Side::getIndex(SPtr<Grid> grid, std::string coord, real constant, real v1, } -void Geometry::addIndices(std::vector<SPtr<Grid> > grids, uint level, SPtr<BoundaryCondition> boundaryCondition) -{ - auto geometryBoundaryCondition = std::dynamic_pointer_cast<GeometryBoundaryCondition>(boundaryCondition); - - std::vector<real> qNode(grids[level]->getEndDirection() + 1); - - for (uint index = 0; index < grids[level]->getSize(); index++) - { - if (grids[level]->getFieldEntry(index) != BC_SOLID) - continue; - - for (int dir = 0; dir <= grids[level]->getEndDirection(); dir++) - { - const real q = grids[level]->getQValue(index, dir); - - qNode[dir] = q; - - // also the neighbor if any Qs are required - real x,y,z; - grids[level]->transIndexToCoords( index, x, y, z ); - - x += grids[level]->getDirection()[dir * DIMENSION + 0] * grids[level]->getDelta(); - y += grids[level]->getDirection()[dir * DIMENSION + 1] * grids[level]->getDelta(); - z += grids[level]->getDirection()[dir * DIMENSION + 2] * grids[level]->getDelta(); - - uint neighborIndex = grids[level]->transCoordToIndex( x, y, z ); - - if( qNode[dir] < -0.5 && ( grids[level]->getFieldEntry(neighborIndex) == STOPPER_OUT_OF_GRID_BOUNDARY || - grids[level]->getFieldEntry(neighborIndex) == STOPPER_OUT_OF_GRID || - grids[level]->getFieldEntry(neighborIndex) == STOPPER_SOLID ) ) - qNode[dir] = 0.5; - } - - geometryBoundaryCondition->indices.push_back(index); - geometryBoundaryCondition->qs.push_back(qNode); - geometryBoundaryCondition->patches.push_back( grids[level]->getQPatch(index) ); - } -} - - - void MX::addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<BoundaryCondition> boundaryCondition) { real startInner = grid[level]->getStartY(); diff --git a/src/gpu/GridGenerator/grid/BoundaryConditions/Side.h b/src/gpu/GridGenerator/grid/BoundaryConditions/Side.h index 13522cf2e9802f8bb4ad5f02ef0ca87fa1a56336..260bc18967296e63cc21fc0454c86cdcb65e8719 100644 --- a/src/gpu/GridGenerator/grid/BoundaryConditions/Side.h +++ b/src/gpu/GridGenerator/grid/BoundaryConditions/Side.h @@ -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 Side.h +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef SIDE_H #define SIDE_H @@ -14,7 +46,11 @@ #define NEGATIVE_DIR -1 class Grid; + +namespace gg +{ class BoundaryCondition; +} class Side; @@ -29,8 +65,7 @@ class Side { public: virtual ~Side() = default; - - virtual void addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<BoundaryCondition> boundaryCondition) = 0; + virtual void addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<gg::BoundaryCondition> boundaryCondition) = 0; virtual int getCoordinate() const = 0; virtual int getDirection() const = 0; @@ -38,42 +73,21 @@ public: virtual SideType whoAmI() const = 0; protected: - static void addIndices(SPtr<Grid> grid, SPtr<BoundaryCondition> boundaryCondition, std::string coord, real constant, + static 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<BoundaryCondition> boundaryCondition, SPtr<Grid> grid, const uint index); + static void setPressureNeighborIndices(SPtr<gg::BoundaryCondition> boundaryCondition, SPtr<Grid> grid, const uint index); - static void setQs(SPtr<Grid> grid, SPtr<BoundaryCondition> boundaryCondition, uint index); + static 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); }; -class Geometry : public Side -{ -public: - void addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<BoundaryCondition> boundaryCondition) override; - - int getCoordinate() const override - { - return X_INDEX; - } - - int getDirection() const override - { - return NEGATIVE_DIR; - } - - SideType whoAmI() const override - { - return SideType::GEOMETRY; - } -}; - class MX : public Side { public: - void addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<BoundaryCondition> boundaryCondition) override; + void addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<gg::BoundaryCondition> boundaryCondition) override; int getCoordinate() const override { @@ -94,7 +108,7 @@ public: class PX : public Side { public: - void addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<BoundaryCondition> boundaryCondition) override; + void addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<gg::BoundaryCondition> boundaryCondition) override; int getCoordinate() const override { @@ -116,7 +130,7 @@ public: class MY : public Side { public: - void addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<BoundaryCondition> boundaryCondition) override; + void addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<gg::BoundaryCondition> boundaryCondition) override; int getCoordinate() const override { @@ -137,7 +151,7 @@ public: class PY : public Side { public: - void addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<BoundaryCondition> boundaryCondition) override; + void addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<gg::BoundaryCondition> boundaryCondition) override; int getCoordinate() const override { @@ -159,7 +173,7 @@ public: class MZ : public Side { public: - void addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<BoundaryCondition> boundaryCondition) override; + void addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<gg::BoundaryCondition> boundaryCondition) override; int getCoordinate() const override { @@ -180,7 +194,7 @@ public: class PZ : public Side { public: - void addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<BoundaryCondition> boundaryCondition) override; + void addIndices(std::vector<SPtr<Grid> > grid, uint level, SPtr<gg::BoundaryCondition> boundaryCondition) override; int getCoordinate() const override { @@ -219,7 +233,7 @@ public: case SideType::PZ: return SPtr<Side>(new PZ()); case SideType::GEOMETRY: - return SPtr<Side>(new Geometry()); + throw std::runtime_error("SideFactory::make() - SideType::GEOMETRY not supported."); default: throw std::runtime_error("SideFactory::make() - SideType not valid."); } diff --git a/src/gpu/GridGenerator/grid/Cell.h b/src/gpu/GridGenerator/grid/Cell.h index 845e02eaa66a5b2327b5a2ba63b1227962ab8f61..a7a64917025742217be88e7ebe1ccc9e669fc7c0 100644 --- a/src/gpu/GridGenerator/grid/Cell.h +++ b/src/gpu/GridGenerator/grid/Cell.h @@ -1,14 +1,44 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// 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 Cell.h +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef CELL_H #define CELL_H #include "global.h" -#include "utilities/cuda/cudaDefines.h" - struct Point { - HOSTDEVICE Point() : x(0.0), y(0.0), z(0.0) {} - HOSTDEVICE Point(real x, real y, real z) : x(x), y(y), z(z) {} + Point() : x(0.0), y(0.0), z(0.0) {} + Point(real x, real y, real z) : x(x), y(y), z(z) {} real x, y, z; }; @@ -18,7 +48,7 @@ public: typedef Point* iterator; typedef const Point* const_iterator; - HOSTDEVICE Cell(real startX, real startY, real startZ, real delta) + Cell(real startX, real startY, real startZ, real delta) { points = new Point[size]; points[0] = Point(startX, startY, startZ); // 0,0,0 @@ -32,15 +62,15 @@ public: points[7] = Point(startX + delta, startY + delta, startZ + delta); // 1,1,1 } - HOSTDEVICE ~Cell() + ~Cell() { delete[] points; } - HOSTDEVICE iterator begin() { return &points[0]; } - HOSTDEVICE const_iterator begin() const { return &points[0]; } - HOSTDEVICE iterator end() { return &points[size]; } - HOSTDEVICE const_iterator end() const { return &points[size]; } + iterator begin() { return &points[0]; } + const_iterator begin() const { return &points[0]; } + iterator end() { return &points[size]; } + const_iterator end() const { return &points[size]; } private: Point* points; diff --git a/src/gpu/GridGenerator/grid/Field.cpp b/src/gpu/GridGenerator/grid/Field.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d8ac2a80ea6fc5da879c5378aac2eab70016ff72 --- /dev/null +++ b/src/gpu/GridGenerator/grid/Field.cpp @@ -0,0 +1,177 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// 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 Field.cpp +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz, Martin Schoenherr +//======================================================================================= +#include "Field.h" + +#include "grid/NodeValues.h" + +using namespace vf::gpu; + +Field::Field(uint size) : size(size) +{ + +} + +void Field::allocateMemory() +{ + this->field = new char[this->size]; +} + +void Field::freeMemory() +{ + delete[] this->field; +} + +// --------------------------------------------------------- // +// Getter // +// --------------------------------------------------------- // +uint Field::getSize() const +{ + return this->size; +} + +char Field::getFieldEntry(uint index) const +{ + return this->field[index]; +} + +// --------------------------------------------------------- // +// Is // +// --------------------------------------------------------- // +bool Field::is(uint index, char type) const +{ + return field[index] == type; +} + +bool Field::isCoarseToFineNode(uint index) const +{ + return field[index] == FLUID_CFC; +} + +bool Field::isFineToCoarseNode(uint index) const +{ + return field[index] == FLUID_FCC; +} + +bool Field::isFluid(uint index) const +{ + const char type = field[index]; + return type == FLUID || type == FLUID_CFC || type == FLUID_CFF || type == FLUID_FCC || type == FLUID_FCF || isBoundaryConditionNode(index); +} + +bool Field::isInvalidSolid(uint index) const +{ + return field[index] == INVALID_SOLID; +} + +bool Field::isInvalidOutOfGrid(uint index) const +{ + return field[index] == INVALID_OUT_OF_GRID; +} + +bool Field::isInvalidCoarseUnderFine(uint index) const +{ + return field[index] == INVALID_COARSE_UNDER_FINE; +} + +bool Field::isStopperOutOfGrid(uint index) const +{ + return field[index] == STOPPER_OUT_OF_GRID; +} + +bool Field::isStopperCoarseUnderFine(uint index) const +{ + return field[index] == STOPPER_COARSE_UNDER_FINE; +} + +bool Field::isStopperSolid(uint index) const +{ + return field[index] == STOPPER_SOLID; +} + +bool Field::isStopper(uint index) const +{ + return isStopperOutOfGrid(index) || isStopperCoarseUnderFine(index) || isStopperSolid(index) || is(index, STOPPER_OUT_OF_GRID_BOUNDARY); +} + +bool Field::isQ(uint index) const +{ + return field[index] == Q_DEPRECATED; +} + +bool Field::isBoundaryConditionNode(uint index) const +{ + return field[index] == BC_SOLID || field[index] == BC_OUTFLOW || field[index] == BC_VELOCITY || field[index] == BC_PRESSURE || field[index] == BC_SLIP; +} + +// --------------------------------------------------------- // +// Setter // +// --------------------------------------------------------- // +void Field::setFieldEntry(uint index, char val) +{ + this->field[index] = val; +} + +void Field::setFieldEntryToFluid(uint index) +{ + this->field[index] = FLUID; +} + +void Field::setFieldEntryToInvalidSolid(uint index) +{ + this->field[index] = INVALID_SOLID; +} + +void Field::setFieldEntryToStopperOutOfGrid(uint index) +{ + this->field[index] = STOPPER_OUT_OF_GRID; +} + +void Field::setFieldEntryToStopperOutOfGridBoundary(uint index) +{ + this->field[index] = STOPPER_OUT_OF_GRID_BOUNDARY; +} + +void Field::setFieldEntryToStopperCoarseUnderFine(uint index) +{ + this->field[index] = STOPPER_COARSE_UNDER_FINE; +} + +void Field::setFieldEntryToInvalidCoarseUnderFine(uint index) +{ + this->field[index] = INVALID_COARSE_UNDER_FINE; +} + +void Field::setFieldEntryToInvalidOutOfGrid(uint index) +{ + this->field[index] = INVALID_OUT_OF_GRID; +} diff --git a/src/gpu/GridGenerator/grid/Field.cu b/src/gpu/GridGenerator/grid/Field.cu deleted file mode 100644 index 6272a3a6e324395de0a22705ac6e9a61b2879e44..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/grid/Field.cu +++ /dev/null @@ -1,156 +0,0 @@ -#include "Field.h" - -#include "grid/NodeValues.h" -#include "grid/GridStrategy/GridStrategy.h" - -using namespace vf::gpu; - -CUDA_HOST Field::Field(SPtr<GridStrategy> gridStrategy, uint size) : gridStrategy(gridStrategy), size(size) -{ - -} - -Field::Field() -{ - -} - -Field::~Field() -{ - -} - -CUDA_HOST void Field::allocateMemory() -{ - gridStrategy->allocateFieldMemory(this); -} - -CUDA_HOST void Field::freeMemory() -{ - gridStrategy->freeFieldMemory(this); -} - -// --------------------------------------------------------- // -// Getter // -// --------------------------------------------------------- // -HOSTDEVICE uint Field::getSize() const -{ - return this->size; -} - -HOSTDEVICE char Field::getFieldEntry(uint index) const -{ - return this->field[index]; -} - -// --------------------------------------------------------- // -// Is // -// --------------------------------------------------------- // -HOSTDEVICE bool Field::is(uint index, char type) const -{ - return field[index] == type; -} - -HOSTDEVICE bool Field::isCoarseToFineNode(uint index) const -{ - return field[index] == FLUID_CFC; -} - -HOSTDEVICE bool Field::isFineToCoarseNode(uint index) const -{ - return field[index] == FLUID_FCC; -} - -HOSTDEVICE bool Field::isFluid(uint index) const -{ - const char type = field[index]; - return type == FLUID || type == FLUID_CFC || type == FLUID_CFF || type == FLUID_FCC || type == FLUID_FCF || isBoundaryConditionNode(index); -} - -HOSTDEVICE bool Field::isInvalidSolid(uint index) const -{ - return field[index] == INVALID_SOLID; -} - -HOSTDEVICE bool Field::isInvalidOutOfGrid(uint index) const -{ - return field[index] == INVALID_OUT_OF_GRID; -} - -HOSTDEVICE bool Field::isInvalidCoarseUnderFine(uint index) const -{ - return field[index] == INVALID_COARSE_UNDER_FINE; -} - -HOSTDEVICE bool Field::isStopperOutOfGrid(uint index) const -{ - return field[index] == STOPPER_OUT_OF_GRID; -} - -HOSTDEVICE bool Field::isStopperCoarseUnderFine(uint index) const -{ - return field[index] == STOPPER_COARSE_UNDER_FINE; -} - -HOSTDEVICE bool Field::isStopperSolid(uint index) const -{ - return field[index] == STOPPER_SOLID; -} - -HOSTDEVICE bool Field::isStopper(uint index) const -{ - return isStopperOutOfGrid(index) || isStopperCoarseUnderFine(index) || isStopperSolid(index) || is(index, STOPPER_OUT_OF_GRID_BOUNDARY); -} - -HOSTDEVICE bool Field::isQ(uint index) const -{ - return field[index] == Q_DEPRECATED; -} - -HOSTDEVICE bool Field::isBoundaryConditionNode(uint index) const -{ - return field[index] == BC_SOLID || field[index] == BC_OUTFLOW || field[index] == BC_VELOCITY || field[index] == BC_PRESSURE || field[index] == BC_SLIP; -} - -// --------------------------------------------------------- // -// Setter // -// --------------------------------------------------------- // -HOSTDEVICE void Field::setFieldEntry(uint index, char val) -{ - this->field[index] = val; -} - -HOSTDEVICE void Field::setFieldEntryToFluid(uint index) -{ - this->field[index] = FLUID; -} - -HOSTDEVICE void Field::setFieldEntryToInvalidSolid(uint index) -{ - this->field[index] = INVALID_SOLID; -} - -HOSTDEVICE void Field::setFieldEntryToStopperOutOfGrid(uint index) -{ - this->field[index] = STOPPER_OUT_OF_GRID; -} - -HOSTDEVICE void Field::setFieldEntryToStopperOutOfGridBoundary(uint index) -{ - this->field[index] = STOPPER_OUT_OF_GRID_BOUNDARY; -} - -HOSTDEVICE void Field::setFieldEntryToStopperCoarseUnderFine(uint index) -{ - this->field[index] = STOPPER_COARSE_UNDER_FINE; -} - -HOSTDEVICE void Field::setFieldEntryToInvalidCoarseUnderFine(uint index) -{ - this->field[index] = INVALID_COARSE_UNDER_FINE; -} - -HOSTDEVICE void Field::setFieldEntryToInvalidOutOfGrid(uint index) -{ - this->field[index] = INVALID_OUT_OF_GRID; -} diff --git a/src/gpu/GridGenerator/grid/Field.h b/src/gpu/GridGenerator/grid/Field.h index f79797afab158f0f80d515f2aa38ed8b91438dc2..002c8c108bd405f4077cd2779f5e59232135ace9 100644 --- a/src/gpu/GridGenerator/grid/Field.h +++ b/src/gpu/GridGenerator/grid/Field.h @@ -1,54 +1,79 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// 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 Field.h +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz, Martin Schoenherr +//======================================================================================= #ifndef FIELD_H #define FIELD_H #include "global.h" struct Vertex; -class GridStrategy; class GRIDGENERATOR_EXPORT Field : public enableSharedFromThis<Field> { public: - CUDA_HOST Field(SPtr<GridStrategy> gridStrategy, uint size); - HOSTDEVICE Field(); - HOSTDEVICE ~Field(); - CUDA_HOST void allocateMemory(); - CUDA_HOST void freeMemory(); - - HOSTDEVICE uint getSize() const; - HOSTDEVICE char getFieldEntry(uint index) const; - - HOSTDEVICE bool is(uint index, char type) const; - HOSTDEVICE bool isCoarseToFineNode(uint index) const; - HOSTDEVICE bool isFineToCoarseNode(uint index) const; - HOSTDEVICE bool isFluid(uint index) const; - HOSTDEVICE bool isInvalidSolid(uint index) const; - HOSTDEVICE bool isQ(uint index) const; - HOSTDEVICE bool isBoundaryConditionNode(uint index) const; - HOSTDEVICE bool isInvalidCoarseUnderFine(uint index) const; - HOSTDEVICE bool isStopperOutOfGrid(uint index) const; - HOSTDEVICE bool isStopperCoarseUnderFine(uint index) const; - HOSTDEVICE bool isStopperSolid(uint index) const; - HOSTDEVICE bool isStopper(uint index) const; - HOSTDEVICE bool isInvalidOutOfGrid(uint index) const; - - HOSTDEVICE void setFieldEntry(uint index, char val); - HOSTDEVICE void setFieldEntryToFluid(uint index); - HOSTDEVICE void setFieldEntryToInvalidSolid(uint index); - HOSTDEVICE void setFieldEntryToStopperOutOfGrid(uint index); - HOSTDEVICE void setFieldEntryToStopperOutOfGridBoundary(uint index); - HOSTDEVICE void setFieldEntryToStopperCoarseUnderFine(uint index); - HOSTDEVICE void setFieldEntryToInvalidCoarseUnderFine(uint index); - HOSTDEVICE void setFieldEntryToInvalidOutOfGrid(uint index); + Field(uint size); + Field() = default; + void allocateMemory(); + void freeMemory(); -private: - SPtr<GridStrategy> gridStrategy; + uint getSize() const; + char getFieldEntry(uint index) const; + + bool is(uint index, char type) const; + bool isCoarseToFineNode(uint index) const; + bool isFineToCoarseNode(uint index) const; + bool isFluid(uint index) const; + bool isInvalidSolid(uint index) const; + bool isQ(uint index) const; + bool isBoundaryConditionNode(uint index) const; + bool isInvalidCoarseUnderFine(uint index) const; + bool isStopperOutOfGrid(uint index) const; + bool isStopperCoarseUnderFine(uint index) const; + bool isStopperSolid(uint index) const; + bool isStopper(uint index) const; + bool isInvalidOutOfGrid(uint index) const; + + void setFieldEntry(uint index, char val); + void setFieldEntryToFluid(uint index); + void setFieldEntryToInvalidSolid(uint index); + void setFieldEntryToStopperOutOfGrid(uint index); + void setFieldEntryToStopperOutOfGridBoundary(uint index); + void setFieldEntryToStopperCoarseUnderFine(uint index); + void setFieldEntryToInvalidCoarseUnderFine(uint index); + void setFieldEntryToInvalidOutOfGrid(uint index); +private: char *field; uint size; - - friend class GridGpuStrategy; - friend class GridCpuStrategy; }; #endif diff --git a/src/gpu/GridGenerator/grid/Grid.h b/src/gpu/GridGenerator/grid/Grid.h index f6c17551e170a78376b5e0d4075895c710651ead..3407b23c1efbb4143d06ded7880c26d7c0eb6599 100644 --- a/src/gpu/GridGenerator/grid/Grid.h +++ b/src/gpu/GridGenerator/grid/Grid.h @@ -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 Grid.h +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz, Martin Schönherr +//======================================================================================= #ifndef GRID_H #define GRID_H @@ -12,7 +44,6 @@ class TriangularMesh; struct Vertex; struct Triangle; -class GridStrategy; class GridInterface; class Object; class BoundingBox; @@ -20,121 +51,119 @@ class BoundingBox; class GRIDGENERATOR_EXPORT Grid { public: - HOSTDEVICE virtual ~Grid() {} + virtual ~Grid() = default; - HOSTDEVICE virtual const Object* getObject() const = 0; + virtual const Object* getObject() const = 0; - HOSTDEVICE virtual real getDelta() const = 0; - HOSTDEVICE virtual uint getSparseSize() const = 0; - HOSTDEVICE virtual uint getSize() const = 0; + virtual real getDelta() const = 0; + virtual uint getSparseSize() const = 0; + virtual uint getSize() const = 0; - HOSTDEVICE virtual real getStartX() const = 0; - HOSTDEVICE virtual real getStartY() const = 0; - HOSTDEVICE virtual real getStartZ() const = 0; + virtual real getStartX() const = 0; + virtual real getStartY() const = 0; + virtual real getStartZ() const = 0; - HOSTDEVICE virtual real getEndX() const = 0; - HOSTDEVICE virtual real getEndY() const = 0; - HOSTDEVICE virtual real getEndZ() const = 0; + virtual real getEndX() const = 0; + virtual real getEndY() const = 0; + virtual real getEndZ() const = 0; - HOSTDEVICE virtual Vertex getMinimumOnNode(Vertex exact) const = 0; - HOSTDEVICE virtual Vertex getMaximumOnNode(Vertex exact) const = 0; + virtual Vertex getMinimumOnNode(Vertex exact) const = 0; + virtual Vertex getMaximumOnNode(Vertex exact) const = 0; - HOSTDEVICE virtual uint getNumberOfNodesX() const = 0; - HOSTDEVICE virtual uint getNumberOfNodesY() const = 0; - HOSTDEVICE virtual uint getNumberOfNodesZ() const = 0; + virtual uint getNumberOfNodesX() const = 0; + virtual uint getNumberOfNodesY() const = 0; + virtual uint getNumberOfNodesZ() const = 0; - HOSTDEVICE virtual uint getNumberOfNodesCF() const = 0; - HOSTDEVICE virtual uint getNumberOfNodesFC() const = 0; + virtual uint getNumberOfNodesCF() const = 0; + virtual uint getNumberOfNodesFC() const = 0; - HOSTDEVICE virtual int getSparseIndex(uint matrixIndex) const = 0; - HOSTDEVICE virtual char getFieldEntry(uint matrixIndex) const = 0; - HOSTDEVICE virtual void setFieldEntry(uint matrixIndex, char type) = 0; + virtual int getSparseIndex(uint matrixIndex) const = 0; + virtual char getFieldEntry(uint matrixIndex) const = 0; + virtual void setFieldEntry(uint matrixIndex, char type) = 0; - CUDA_HOST virtual void getGridInterfaceIndices(uint* iCellCfc, uint* iCellCff, uint* iCellFcc, uint* iCellFcf) const = 0; + virtual void getGridInterfaceIndices(uint* iCellCfc, uint* iCellCff, uint* iCellFcc, uint* iCellFcf) const = 0; - CUDA_HOST virtual int *getNeighborsX() const = 0; - CUDA_HOST virtual int *getNeighborsY() const = 0; - CUDA_HOST virtual int *getNeighborsZ() const = 0; - CUDA_HOST virtual int *getNeighborsNegative() const = 0; + virtual int *getNeighborsX() const = 0; + virtual int *getNeighborsY() const = 0; + virtual int *getNeighborsZ() const = 0; + virtual int *getNeighborsNegative() const = 0; - CUDA_HOST virtual uint* getCF_coarse() const = 0; - CUDA_HOST virtual uint* getCF_fine() const = 0; - CUDA_HOST virtual uint* getCF_offset() const = 0; + virtual uint *getCF_coarse() const = 0; + virtual uint *getCF_fine() const = 0; + virtual uint *getCF_offset() const = 0; - CUDA_HOST virtual uint* getFC_coarse() const = 0; - CUDA_HOST virtual uint* getFC_fine() const = 0; - CUDA_HOST virtual uint* getFC_offset() const = 0; + virtual uint *getFC_coarse() const = 0; + virtual uint *getFC_fine() const = 0; + virtual uint *getFC_offset() const = 0; - CUDA_HOST virtual real* getDistribution() const = 0; - CUDA_HOST virtual int* getDirection() const = 0; - CUDA_HOST virtual int getStartDirection() const = 0; - CUDA_HOST virtual int getEndDirection() const = 0; + virtual real *getDistribution() const = 0; + virtual int* getDirection() const = 0; + virtual int getStartDirection() const = 0; + virtual int getEndDirection() const = 0; - CUDA_HOST virtual void getNodeValues(real *xCoords, real *yCoords, real *zCoords, uint *neighborX, uint *neighborY, uint *neighborZ, uint *neighborNegative, uint *geo) const = 0; + virtual void getNodeValues(real *xCoords, real *yCoords, real *zCoords, uint *neighborX, uint *neighborY, uint *neighborZ, uint *neighborNegative, uint *geo) const = 0; - CUDA_HOST virtual SPtr<GridStrategy> getGridStrategy() const = 0; - HOSTDEVICE virtual void transIndexToCoords(uint index, real &x, real &y, real &z) const = 0; - HOSTDEVICE virtual uint transCoordToIndex(const real &x, const real &y, const real &z) const = 0; + virtual void transIndexToCoords(uint index, real &x, real &y, real &z) const = 0; + virtual uint transCoordToIndex(const real &x, const real &y, const real &z) const = 0; - CUDA_HOST virtual void inital(const SPtr<Grid> fineGrid, uint numberOfLayers) = 0; + virtual void inital(const SPtr<Grid> fineGrid, uint numberOfLayers) = 0; - CUDA_HOST virtual void setOddStart( bool xOddStart, bool yOddStart, bool zOddStart ) = 0; + virtual void setOddStart(bool xOddStart, bool yOddStart, bool zOddStart) = 0; - CUDA_HOST virtual void findGridInterface(SPtr<Grid> grid, LbmOrGks lbmOrGks) = 0; + virtual void findGridInterface(SPtr<Grid> grid, LbmOrGks lbmOrGks) = 0; - HOSTDEVICE virtual void repairGridInterfaceOnMultiGPU(SPtr<Grid> fineGrid) = 0; + virtual void repairGridInterfaceOnMultiGPU(SPtr<Grid> fineGrid) = 0; - CUDA_HOST virtual void limitToSubDomain(SPtr<BoundingBox> subDomainBox, LbmOrGks lbmOrGks) = 0; - - CUDA_HOST virtual void enableFindSolidBoundaryNodes() = 0; - CUDA_HOST virtual void enableComputeQs() = 0; + virtual void limitToSubDomain(SPtr<BoundingBox> subDomainBox, LbmOrGks lbmOrGks) = 0; - CUDA_HOST virtual void mesh(TriangularMesh& geometry) = 0; - CUDA_HOST virtual void mesh(Object* object) = 0; + virtual void enableFindSolidBoundaryNodes() = 0; + virtual void enableComputeQs() = 0; - CUDA_HOST virtual void closeNeedleCells() = 0; - CUDA_HOST virtual void closeNeedleCellsThinWall() = 0; + virtual void mesh(TriangularMesh &geometry) = 0; + virtual void mesh(Object *object) = 0; - CUDA_HOST virtual void findQs(Object* object) = 0; + virtual void closeNeedleCells() = 0; + virtual void closeNeedleCellsThinWall() = 0; - CUDA_HOST virtual void setPeriodicity(bool periodicityX, bool periodicityY, bool periodicityZ) = 0; - CUDA_HOST virtual void setPeriodicityX(bool periodicity) = 0; - CUDA_HOST virtual void setPeriodicityY(bool periodicity) = 0; - CUDA_HOST virtual void setPeriodicityZ(bool periodicity) = 0; + virtual void findQs(Object *object) = 0; - CUDA_HOST virtual bool getPeriodicityX() = 0; - CUDA_HOST virtual bool getPeriodicityY() = 0; - CUDA_HOST virtual bool getPeriodicityZ() = 0; + virtual void setPeriodicity(bool periodicityX, bool periodicityY, bool periodicityZ) = 0; + virtual void setPeriodicityX(bool periodicity) = 0; + virtual void setPeriodicityY(bool periodicity) = 0; + virtual void setPeriodicityZ(bool periodicity) = 0; - CUDA_HOST virtual void setEnableFixRefinementIntoTheWall( bool enableFixRefinementIntoTheWall ) = 0; + virtual bool getPeriodicityX() = 0; + virtual bool getPeriodicityY() = 0; + virtual bool getPeriodicityZ() = 0; - CUDA_HOST virtual void freeMemory() = 0; + virtual void setEnableFixRefinementIntoTheWall(bool enableFixRefinementIntoTheWall) = 0; + virtual void freeMemory() = 0; - HOSTDEVICE virtual bool nodeInCellIs(Cell& cell, char type) const = 0; + virtual bool nodeInCellIs(Cell& cell, char type) const = 0; - CUDA_HOST virtual void findSparseIndices(SPtr<Grid> fineGrid) = 0; + virtual void findSparseIndices(SPtr<Grid> fineGrid) = 0; - HOSTDEVICE virtual real getFirstFluidNode(real coords[3], int direction, real startCoord) const = 0; - HOSTDEVICE virtual real getLastFluidNode(real coords[3], int direction, real startCoord) const = 0; + virtual real getFirstFluidNode(real coords[3], int direction, real startCoord) const = 0; + virtual real getLastFluidNode(real coords[3], int direction, real startCoord) const = 0; - CUDA_HOST virtual uint getNumberOfSolidBoundaryNodes() const = 0; - CUDA_HOST virtual void setNumberOfSolidBoundaryNodes(uint numberOfSolidBoundaryNodes) = 0; + virtual uint getNumberOfSolidBoundaryNodes() const = 0; + virtual void setNumberOfSolidBoundaryNodes(uint numberOfSolidBoundaryNodes) = 0; - CUDA_HOST virtual real getQValue(const uint index, const uint dir) const = 0; - CUDA_HOST virtual uint getQPatch(const uint index) const = 0; + virtual real getQValue(const uint index, const uint dir) const = 0; + virtual uint getQPatch(const uint index) const = 0; - CUDA_HOST virtual void setInnerRegionFromFinerGrid( bool innerRegionFromFinerGrid ) = 0; + virtual void setInnerRegionFromFinerGrid(bool innerRegionFromFinerGrid) = 0; - CUDA_HOST virtual void setNumberOfLayers( uint numberOfLayers ) = 0; + virtual void setNumberOfLayers(uint numberOfLayers) = 0; virtual void findCommunicationIndices(int direction, SPtr<BoundingBox> subDomainBox, LbmOrGks lbmOrGks) = 0; - virtual uint getNumberOfSendNodes(int direction) = 0; - virtual uint getNumberOfReceiveNodes(int direction) = 0; + virtual uint getNumberOfSendNodes(int direction) = 0; + virtual uint getNumberOfReceiveNodes(int direction) = 0; - virtual uint getSendIndex(int direction, uint index) = 0; - virtual uint getReceiveIndex(int direction, uint index) = 0; + virtual uint getSendIndex(int direction, uint index) = 0; + virtual uint getReceiveIndex(int direction, uint index) = 0; virtual void repairCommunicationInices(int direction) = 0; diff --git a/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h b/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h index 8136bd38d97820955be5b1210293b6abcd4b64ff..57290025c3f6e48554e1dafe9bd101ae237b3288 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h +++ b/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h @@ -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 GridBuilder.h +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz, Martin Schönherr +//======================================================================================= #ifndef GridBuilder_H #define GridBuilder_H @@ -5,7 +37,7 @@ #include <string> #include <memory> -#include "global.h" +#include "GridGenerator/global.h" #define GEOMQS 6 #define INLETQS 0 @@ -28,7 +60,10 @@ class Grid; enum class SideType; +namespace gg +{ class BoundaryCondition; +} class GeometryBoundaryCondition; class GridBuilder @@ -43,10 +78,9 @@ public: virtual void getGridInformations(std::vector<int>& gridX, std::vector<int>& gridY, std::vector<int>& gridZ, std::vector<int>& distX, std::vector<int>& distY, std::vector<int>& distZ) = 0; virtual GRIDGENERATOR_EXPORT uint getNumberOfGridLevels() const = 0; - virtual void writeArrows(std::string fileName) const = 0; - virtual SPtr<Grid> getGrid(uint level) = 0; + virtual SPtr<Grid> getGrid(uint level) = 0; virtual unsigned int getNumberOfNodes(unsigned int level) const = 0; virtual void getNodeValues(real *xCoords, real *yCoords, real *zCoords, @@ -60,30 +94,34 @@ public: virtual void getOffsetFC(real* xOffCf, real* yOffCf, real* zOffCf, int level) = 0; virtual void getOffsetCF(real* xOffFc, real* yOffFc, real* zOffFc, int level) = 0; + virtual uint getSlipSize(int level) const = 0; + virtual void getSlipValues(real *normalX, real *normalY, real *normalZ, int *indices, int level) const = 0; + virtual void getSlipQs(real* qs[27], int level) const = 0; + virtual uint getVelocitySize(int level) const = 0; virtual void getVelocityValues(real* vx, real* vy, real* vz, int* indices, int level) const = 0; - virtual uint getPressureSize(int level) const = 0; - virtual void getPressureValues(real* rho, int* indices, int* neighborIndices, int level) const = 0; virtual void getVelocityQs(real* qs[27], int level) const = 0; - virtual void getPressureQs(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; - virtual bool hasGeometryValues() const = 0; - virtual void getGeometryValues(real* vx, real* vy, real* vz, int level) const = 0; + virtual uint getPressureSize(int level) const = 0; + 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 getCommunicationProcess(int direction) = 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; + virtual bool hasGeometryValues() const = 0; + virtual void getGeometryValues(real *vx, real *vy, real *vz, int level) const = 0; - virtual SPtr<BoundaryCondition> getBoundaryCondition( SideType side, uint level ) const = 0; + virtual SPtr<gg::BoundaryCondition> getBoundaryCondition(SideType side, uint level) const = 0; - virtual SPtr<GeometryBoundaryCondition> getGeometryBoundaryCondition( uint level ) const = 0; + virtual SPtr<GeometryBoundaryCondition> getGeometryBoundaryCondition(uint level) const = 0; - virtual uint getNumberOfSendIndices( int direction, uint level ) = 0; - virtual uint getNumberOfReceiveIndices( int direction, uint level ) = 0; - virtual void getSendIndices( int* sendIndices, int direction, int level ) = 0; - virtual void getReceiveIndices( int* sendIndices, int direction, int level ) = 0; + virtual uint getCommunicationProcess(int direction) = 0; + virtual uint getNumberOfSendIndices(int direction, uint level) = 0; + virtual uint getNumberOfReceiveIndices(int direction, uint level) = 0; + virtual void getSendIndices(int *sendIndices, int direction, int level) = 0; + virtual void getReceiveIndices(int *sendIndices, int direction, int level) = 0; }; #endif diff --git a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp index 92bb2040fdc963e1ba991b531fd91bc8ef14674e..20c285c13aa2c7644fc1ac6ea6a87b5d8dc7f72c 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp +++ b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp @@ -1,38 +1,65 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// 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 LevelGridBuilder.cpp +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz, Martin Schönherr +//======================================================================================= #include "LevelGridBuilder.h" #include <stdio.h> #include <iostream> #include "geometries/Arrow/ArrowImp.h" -#include "geometries/Triangle/Triangle.h" #include "geometries/BoundingBox/BoundingBox.h" +#include "geometries/Triangle/Triangle.h" #include "geometries/TriangularMesh/TriangularMesh.h" #include "grid/BoundaryConditions/BoundaryCondition.h" #include "grid/BoundaryConditions/Side.h" -#include "grid/GridStrategy/GridGpuStrategy/GridGpuStrategy.h" -#include "grid/GridStrategy/GridCpuStrategy/GridCpuStrategy.h" -#include "grid/partition/Partition.h" -#include "grid/NodeValues.h" +#include "grid/Grid.h" #include "grid/GridFactory.h" #include "grid/GridInterface.h" -#include "grid/Grid.h" +#include "grid/NodeValues.h" #include "io/GridVTKWriter/GridVTKWriter.h" -#include "io/SimulationFileWriter/SimulationFileWriter.h" -#include "io/VTKWriterWrapper/UnstructuredGridWrapper.h" -#include "io/VTKWriterWrapper/PolyDataWriterWrapper.h" #include "io/QLineWriter.h" +#include "io/SimulationFileWriter/SimulationFileWriter.h" -#include "utilities/transformator/ArrowTransformator.h" #include "utilities/communication.h" +#include "utilities/transformator/ArrowTransformator.h" #define GEOFLUID 19 #define GEOSOLID 16 using namespace vf::gpu; -LevelGridBuilder::LevelGridBuilder(Device device, const std::string& d3qxx) : device(device), d3qxx(d3qxx) +LevelGridBuilder::LevelGridBuilder() { this->communicationProcesses[CommunicationDirections::MX] = INVALID_INDEX; this->communicationProcesses[CommunicationDirections::PX] = INVALID_INDEX; @@ -42,33 +69,41 @@ LevelGridBuilder::LevelGridBuilder(Device device, const std::string& d3qxx) : de this->communicationProcesses[CommunicationDirections::PZ] = INVALID_INDEX; } -std::shared_ptr<LevelGridBuilder> LevelGridBuilder::makeShared(Device device, const std::string& d3qxx) +std::shared_ptr<LevelGridBuilder> LevelGridBuilder::makeShared() { - return SPtr<LevelGridBuilder>(new LevelGridBuilder(device, d3qxx)); + return SPtr<LevelGridBuilder>(new LevelGridBuilder()); +} + +void LevelGridBuilder::setSlipBoundaryCondition(SideType sideType, real nomalX, real normalY, real normalZ) +{ + SPtr<SlipBoundaryCondition> slipBoundaryCondition = SlipBoundaryCondition::make(nomalX, normalY, normalZ); + + auto side = SideFactory::make(sideType); + + slipBoundaryCondition->side = side; + slipBoundaryCondition->side->addIndices(grids, 0, slipBoundaryCondition); + + slipBoundaryCondition->fillSlipNormalLists(); + + boundaryConditions[0]->slipBoundaryConditions.push_back(slipBoundaryCondition); + + *logging::out << logging::Logger::INFO_INTERMEDIATE << "Set Slip BC on level " << 0 << " with " << (int)slipBoundaryCondition->indices.size() << "\n"; } void LevelGridBuilder::setVelocityBoundaryCondition(SideType sideType, real vx, real vy, real vz) { - if (sideType == SideType::GEOMETRY) - setVelocityGeometryBoundaryCondition(vx, vy, vz); - else - { - for (uint level = 0; level < getNumberOfGridLevels(); level++) - { - SPtr<VelocityBoundaryCondition> velocityBoundaryCondition = VelocityBoundaryCondition::make(vx, vy, vz); + SPtr<VelocityBoundaryCondition> velocityBoundaryCondition = VelocityBoundaryCondition::make(vx, vy, vz); - auto side = SideFactory::make(sideType); + auto side = SideFactory::make(sideType); - velocityBoundaryCondition->side = side; - velocityBoundaryCondition->side->addIndices(grids, level, velocityBoundaryCondition); + velocityBoundaryCondition->side = side; + velocityBoundaryCondition->side->addIndices(grids, 0, velocityBoundaryCondition); - velocityBoundaryCondition->fillVelocityLists(); + velocityBoundaryCondition->fillVelocityLists(); - boundaryConditions[level]->velocityBoundaryConditions.push_back(velocityBoundaryCondition); + boundaryConditions[0]->velocityBoundaryConditions.push_back(velocityBoundaryCondition); - *logging::out << logging::Logger::INFO_INTERMEDIATE << "Set Velocity BC on level " << level << " with " << (int)velocityBoundaryCondition->indices.size() <<"\n"; - } - } + *logging::out << logging::Logger::INFO_INTERMEDIATE << "Set Velocity BC on level " << 0 << " with " << (int)velocityBoundaryCondition->indices.size() <<"\n"; } void LevelGridBuilder::setVelocityGeometryBoundaryCondition(real vx, real vy, real vz) @@ -130,8 +165,8 @@ void LevelGridBuilder::setNoSlipBoundaryCondition(SideType sideType) GRIDGENERATOR_EXPORT void LevelGridBuilder::setEnableFixRefinementIntoTheWall(bool enableFixRefinementIntoTheWall) { - for( uint level = 0; level < this->grids.size(); level++ ) - grids[level]->setEnableFixRefinementIntoTheWall( enableFixRefinementIntoTheWall ); + for (uint level = 0; level < this->grids.size(); level++) + grids[level]->setEnableFixRefinementIntoTheWall(enableFixRefinementIntoTheWall); } GRIDGENERATOR_EXPORT void LevelGridBuilder::setCommunicationProcess(int direction, uint process) @@ -144,19 +179,6 @@ GRIDGENERATOR_EXPORT uint LevelGridBuilder::getCommunicationProcess(int directio return this->communicationProcesses[direction]; } - - -void LevelGridBuilder::copyDataFromGpu() -{ - for (const auto& grid : grids) - { - auto gridGpuStrategy = std::dynamic_pointer_cast<GridGpuStrategy>(grid->getGridStrategy()); - if(gridGpuStrategy) - gridGpuStrategy->copyDataFromGPU(std::static_pointer_cast<GridImp>(grid)); - } - -} - LevelGridBuilder::~LevelGridBuilder() { for (const auto& grid : grids) @@ -173,7 +195,7 @@ void LevelGridBuilder::getGridInformations(std::vector<int>& gridX, std::vector< std::vector<int>& gridZ, std::vector<int>& distX, std::vector<int>& distY, std::vector<int>& distZ) { - for (const auto& grid : grids) + for (const auto &grid : grids) { gridX.push_back(int(grid->getNumberOfNodesX())); gridY.push_back(int(grid->getNumberOfNodesY())); @@ -292,66 +314,77 @@ void LevelGridBuilder::getNodeValues(real *xCoords, real *yCoords, real *zCoords grids[level]->getNodeValues(xCoords, yCoords, zCoords, neighborX, neighborY, neighborZ, neighborNegative, geo); } -//TODO: add getSlipSize... - -uint LevelGridBuilder::getVelocitySize(int level) const +uint LevelGridBuilder::getSlipSize(int level) const { uint size = 0; - for (auto boundaryCondition : boundaryConditions[level]->velocityBoundaryConditions) + for (auto boundaryCondition : boundaryConditions[level]->slipBoundaryConditions) { size += uint(boundaryCondition->indices.size()); } return size; } -//TODO: add getSlipIndices... +void LevelGridBuilder::getSlipValues(real* normalX, real* normalY, real* normalZ, int* indices, int level) const +{ + int allIndicesCounter = 0; + for (auto boundaryCondition : boundaryConditions[level]->slipBoundaryConditions) + { + for (uint index = 0; index < boundaryCondition->indices.size(); index++) + { + indices[allIndicesCounter] = grids[level]->getSparseIndex(boundaryCondition->indices[index]) + 1; + normalX[allIndicesCounter] = boundaryCondition->getNormalx(index); + normalY[allIndicesCounter] = boundaryCondition->getNormaly(index); + normalZ[allIndicesCounter] = boundaryCondition->getNormalz(index); + allIndicesCounter++; + } + } +} -void LevelGridBuilder::getVelocityValues(real* vx, real* vy, real* vz, int* indices, int level) const +void LevelGridBuilder::getSlipQs(real* qs[27], int level) const { int allIndicesCounter = 0; - for (auto boundaryCondition : boundaryConditions[level]->velocityBoundaryConditions) + for (auto boundaryCondition : boundaryConditions[level]->slipBoundaryConditions) { - for(std::size_t i = 0; i < boundaryCondition->indices.size(); i++) + for (uint index = 0; index < boundaryCondition->indices.size(); index++) { - indices[allIndicesCounter] = grids[level]->getSparseIndex(boundaryCondition->indices[i]) +1; - vx[allIndicesCounter] = (real)boundaryCondition->getVx((uint)i); - vy[allIndicesCounter] = (real)boundaryCondition->getVy((uint)i); - vz[allIndicesCounter] = (real)boundaryCondition->getVz((uint)i); + for (int dir = 0; dir <= grids[level]->getEndDirection(); dir++) + { + qs[dir][allIndicesCounter] = boundaryCondition->qs[index][dir]; + } allIndicesCounter++; } } } -uint LevelGridBuilder::getPressureSize(int level) const +uint LevelGridBuilder::getVelocitySize(int level) const { uint size = 0; - for (auto boundaryCondition : boundaryConditions[level]->pressureBoundaryConditions) + for (auto boundaryCondition : boundaryConditions[level]->velocityBoundaryConditions) { size += uint(boundaryCondition->indices.size()); } return size; } -void LevelGridBuilder::getPressureValues(real* rho, int* indices, int* neighborIndices, int level) const +void LevelGridBuilder::getVelocityValues(real* vx, real* vy, real* vz, int* indices, int level) const { int allIndicesCounter = 0; - for (auto boundaryCondition : boundaryConditions[level]->pressureBoundaryConditions) + for (auto boundaryCondition : boundaryConditions[level]->velocityBoundaryConditions) { - for (std::size_t i = 0; i < boundaryCondition->indices.size(); i++) + for(std::size_t i = 0; i < boundaryCondition->indices.size(); i++) { - indices[allIndicesCounter] = grids[level]->getSparseIndex(boundaryCondition->indices[i]) + 1; - - neighborIndices[allIndicesCounter] = grids[level]->getSparseIndex(boundaryCondition->neighborIndices[i]) + 1; + indices[allIndicesCounter] = grids[level]->getSparseIndex(boundaryCondition->indices[i]) +1; - rho[allIndicesCounter] = boundaryCondition->rho; + vx[allIndicesCounter] = boundaryCondition->getVx((uint)i); + vy[allIndicesCounter] = boundaryCondition->getVy((uint)i); + vz[allIndicesCounter] = boundaryCondition->getVz((uint)i); allIndicesCounter++; } } } - void LevelGridBuilder::getVelocityQs(real* qs[27], int level) const { int allIndicesCounter = 0; @@ -362,23 +395,34 @@ void LevelGridBuilder::getVelocityQs(real* qs[27], int level) const for (int dir = 0; dir <= grids[level]->getEndDirection(); dir++) { qs[dir][allIndicesCounter] = boundaryCondition->qs[index][dir]; + } + allIndicesCounter++; + } + } +} - //real x,y,z; - //grids[level]->transIndexToCoords( index, x, y, z ); +uint LevelGridBuilder::getPressureSize(int level) const +{ + uint size = 0; + for (auto boundaryCondition : boundaryConditions[level]->pressureBoundaryConditions) + { + size += uint(boundaryCondition->indices.size()); + } + return size; +} - //x += grids[level]->getDirection()[dir * DIMENSION + 0] * grids[level]->getDelta(); - //y += grids[level]->getDirection()[dir * DIMENSION + 1] * grids[level]->getDelta(); - //z += grids[level]->getDirection()[dir * DIMENSION + 2] * grids[level]->getDelta(); +void LevelGridBuilder::getPressureValues(real* rho, int* indices, int* neighborIndices, int level) const +{ + int allIndicesCounter = 0; + for (auto boundaryCondition : boundaryConditions[level]->pressureBoundaryConditions) + { + for (std::size_t i = 0; i < boundaryCondition->indices.size(); i++) + { + indices[allIndicesCounter] = grids[level]->getSparseIndex(boundaryCondition->indices[i]) + 1; - //uint neighborIndex = grids[level]->transCoordToIndex( x, y, z ); + neighborIndices[allIndicesCounter] = grids[level]->getSparseIndex(boundaryCondition->neighborIndices[i]) + 1; - //if( grids[level]->getFieldEntry(neighborIndex) == STOPPER_OUT_OF_GRID_BOUNDARY || - // grids[level]->getFieldEntry(neighborIndex) == STOPPER_OUT_OF_GRID || - // grids[level]->getFieldEntry(neighborIndex) == STOPPER_SOLID) - // qs[dir][allIndicesCounter] = 0.5; - //else - // qs[dir][allIndicesCounter] = -1.0; - } + rho[allIndicesCounter] = boundaryCondition->rho; allIndicesCounter++; } } @@ -394,29 +438,12 @@ void LevelGridBuilder::getPressureQs(real* qs[27], int level) const for (int dir = 0; dir <= grids[level]->getEndDirection(); dir++) { qs[dir][allIndicesCounter] = boundaryCondition->qs[index][dir]; - - //real x,y,z; - //grids[level]->transIndexToCoords( index, x, y, z ); - - //x += grids[level]->getDirection()[dir * DIMENSION + 0] * grids[level]->getDelta(); - //y += grids[level]->getDirection()[dir * DIMENSION + 1] * grids[level]->getDelta(); - //z += grids[level]->getDirection()[dir * DIMENSION + 2] * grids[level]->getDelta(); - - //uint neighborIndex = grids[level]->transCoordToIndex( x, y, z ); - - //if( grids[level]->getFieldEntry(neighborIndex) == STOPPER_OUT_OF_GRID_BOUNDARY || - // grids[level]->getFieldEntry(neighborIndex) == STOPPER_OUT_OF_GRID || - // grids[level]->getFieldEntry(neighborIndex) == STOPPER_SOLID) - // qs[dir][allIndicesCounter] = 0.5; - //else - // qs[dir][allIndicesCounter] = -1.0; } allIndicesCounter++; } } } - uint LevelGridBuilder::getGeometrySize(int level) const { if (boundaryConditions[level]->geometryBoundaryCondition) @@ -438,7 +465,6 @@ bool LevelGridBuilder::hasGeometryValues() const return geometryHasValues; } - void LevelGridBuilder::getGeometryValues(real* vx, real* vy, real* vz, int level) const { for (uint i = 0; i < boundaryConditions[level]->geometryBoundaryCondition->indices.size(); i++) @@ -449,7 +475,6 @@ void LevelGridBuilder::getGeometryValues(real* vx, real* vy, real* vz, int level } } - void LevelGridBuilder::getGeometryQs(real* qs[27], int level) const { for (std::size_t i = 0; i < boundaryConditions[level]->geometryBoundaryCondition->indices.size(); i++) @@ -461,28 +486,28 @@ void LevelGridBuilder::getGeometryQs(real* qs[27], int level) const } } - - - - void LevelGridBuilder::writeArrows(std::string fileName) const { QLineWriter::writeArrows(fileName, boundaryConditions[getNumberOfGridLevels() - 1]->geometryBoundaryCondition, grids[getNumberOfGridLevels() - 1]); } -GRIDGENERATOR_EXPORT SPtr<BoundaryCondition> LevelGridBuilder::getBoundaryCondition(SideType side, uint level) const +GRIDGENERATOR_EXPORT SPtr<gg::BoundaryCondition> LevelGridBuilder::getBoundaryCondition(SideType side, uint level) const { - for( auto bc : this->boundaryConditions[level]->pressureBoundaryConditions ) - if( bc->isSide(side) ) + for (auto bc : this->boundaryConditions[level]->slipBoundaryConditions) + if (bc->isSide(side)) return bc; - - for( auto bc : this->boundaryConditions[level]->velocityBoundaryConditions ) + + for (auto bc : this->boundaryConditions[level]->velocityBoundaryConditions) if( bc->isSide(side) ) return bc; + for (auto bc : this->boundaryConditions[level]->pressureBoundaryConditions) + if (bc->isSide(side)) + return bc; + auto bc = this->boundaryConditions[level]->geometryBoundaryCondition; - - if( bc && bc->isSide(side) ) + + if (bc && bc->isSide(side)) return bc; return nullptr; diff --git a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h index fe7b53f5270f7b5235fdb8a0419558fa106ef878..f2325435d99140f33eee9844c13908de87788558 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h +++ b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h @@ -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 LevelGridBuilder.h +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz, Martin Schönherr +//======================================================================================= #ifndef LEVEL_GRID_BUILDER_H #define LEVEL_GRID_BUILDER_H @@ -10,7 +42,7 @@ #include "grid/GridBuilder/GridBuilder.h" #include "grid/Grid.h" -#include "grid/GridInterface.h" +#include "grid/NodeValues.h" struct Vertex; class Grid; @@ -18,10 +50,10 @@ class Transformator; class ArrowTransformator; class PolyDataWriterWrapper; class BoundingBox; -enum class Device; class Side; class VelocityBoundaryCondition; +class SlipBoundaryCondition; class PressureBoundaryCondition; class GeometryBoundaryCondition; enum class SideType; @@ -31,22 +63,22 @@ enum class SideType; class LevelGridBuilder : public GridBuilder { protected: - GRIDGENERATOR_EXPORT LevelGridBuilder(Device device, const std::string& d3qxx); + GRIDGENERATOR_EXPORT LevelGridBuilder(); public: - GRIDGENERATOR_EXPORT static std::shared_ptr<LevelGridBuilder> makeShared(Device device, const std::string& d3qxx); + GRIDGENERATOR_EXPORT static std::shared_ptr<LevelGridBuilder> makeShared(); GRIDGENERATOR_EXPORT SPtr<Grid> getGrid(uint level) override; - GRIDGENERATOR_EXPORT void copyDataFromGpu(); GRIDGENERATOR_EXPORT virtual ~LevelGridBuilder(); + GRIDGENERATOR_EXPORT void setSlipBoundaryCondition(SideType sideType, real nomalX, real normalY, real normalZ); 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 setEnableFixRefinementIntoTheWall( bool enableFixRefinementIntoTheWall ); + GRIDGENERATOR_EXPORT void setEnableFixRefinementIntoTheWall(bool enableFixRefinementIntoTheWall); GRIDGENERATOR_EXPORT void setCommunicationProcess(int direction, uint process); @@ -54,7 +86,6 @@ public: GRIDGENERATOR_EXPORT virtual std::shared_ptr<Grid> getGrid(int level, int box); - GRIDGENERATOR_EXPORT virtual unsigned int getNumberOfNodes(unsigned int level) const override; @@ -64,23 +95,27 @@ public: GRIDGENERATOR_EXPORT virtual void getDimensions(int &nx, int &ny, int &nz, const int level) const override; + GRIDGENERATOR_EXPORT uint getSlipSize(int level) const override; + GRIDGENERATOR_EXPORT virtual void getSlipValues(real* normalX, real* normalY, real* normalZ, int* indices, int level) const override; + GRIDGENERATOR_EXPORT virtual void getSlipQs(real* qs[27], int level) const override; + GRIDGENERATOR_EXPORT uint getVelocitySize(int level) const override; GRIDGENERATOR_EXPORT virtual void getVelocityValues(real* vx, real* vy, real* vz, int* indices, int level) const override; GRIDGENERATOR_EXPORT virtual void getVelocityQs(real* qs[27], int level) const override; + GRIDGENERATOR_EXPORT uint getPressureSize(int level) const override; 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 virtual void getGeometryQs(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; + GRIDGENERATOR_EXPORT virtual void getGeometryIndices(int *indices, int level) const override; GRIDGENERATOR_EXPORT virtual bool hasGeometryValues() const override; - GRIDGENERATOR_EXPORT virtual void getGeometryValues(real* vx, real* vy, real* vz, int level) const override; - + GRIDGENERATOR_EXPORT virtual void getGeometryValues(real *vx, real *vy, real *vz, int level) const override; GRIDGENERATOR_EXPORT void writeArrows(std::string fileName) const override; - GRIDGENERATOR_EXPORT SPtr<BoundaryCondition> getBoundaryCondition( SideType side, uint level ) const override; + GRIDGENERATOR_EXPORT SPtr<gg::BoundaryCondition> getBoundaryCondition( SideType side, uint level ) const override; GRIDGENERATOR_EXPORT SPtr<GeometryBoundaryCondition> getGeometryBoundaryCondition(uint level) const override; protected: @@ -88,14 +123,13 @@ protected: struct BoundaryConditions { - BoundaryConditions() : geometryBoundaryCondition(nullptr) {} - - std::vector<SPtr<VelocityBoundaryCondition> > velocityBoundaryConditions; - std::vector<SPtr<PressureBoundaryCondition> > pressureBoundaryConditions; + BoundaryConditions() {} - //TODO: add slip BC + std::vector<SPtr<SlipBoundaryCondition>> slipBoundaryConditions; + std::vector<SPtr<VelocityBoundaryCondition>> velocityBoundaryConditions; + std::vector<SPtr<PressureBoundaryCondition>> pressureBoundaryConditions; std::vector<SPtr<VelocityBoundaryCondition> > noSlipBoundaryConditions; @@ -105,7 +139,7 @@ protected: std::vector<std::shared_ptr<Grid> > grids; std::vector<SPtr<BoundaryConditions> > boundaryConditions; - + std::array<uint, 6> communicationProcesses; void checkLevel(int level); @@ -120,10 +154,6 @@ protected: Vertex getVertex(const int matrixIndex) const; -private: - Device device; - std::string d3qxx; - public: GRIDGENERATOR_EXPORT void getGridInformations(std::vector<int>& gridX, std::vector<int>& gridY, std::vector<int>& gridZ, std::vector<int>& distX, std::vector<int>& distY, @@ -138,11 +168,10 @@ public: GRIDGENERATOR_EXPORT void getOffsetFC(real* xOffCf, real* yOffCf, real* zOffCf, int level) override; GRIDGENERATOR_EXPORT void getOffsetCF(real* xOffFc, real* yOffFc, real* zOffFc, int level) override; - GRIDGENERATOR_EXPORT uint getNumberOfSendIndices( int direction, uint level ) override; - GRIDGENERATOR_EXPORT uint getNumberOfReceiveIndices( int direction, uint level ) override; - GRIDGENERATOR_EXPORT void getSendIndices( int* sendIndices, int direction, int level ) override; - GRIDGENERATOR_EXPORT void getReceiveIndices( int* sendIndices, int direction, int level ) override; - + GRIDGENERATOR_EXPORT uint getNumberOfSendIndices(int direction, uint level) override; + GRIDGENERATOR_EXPORT uint getNumberOfReceiveIndices(int direction, uint level) override; + GRIDGENERATOR_EXPORT void getSendIndices(int *sendIndices, int direction, int level) override; + GRIDGENERATOR_EXPORT void getReceiveIndices(int *sendIndices, int direction, int level) override; }; #endif diff --git a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp index bd8bcbd4d0a059acede4e95fa8f06d102904351f..565a02a2807ef15679bf08fa001ea9a03f78ca4e 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.cpp +++ b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.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 MultipleGridBuilder.cpp +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz, Martin Schönherr +//======================================================================================= #include "MultipleGridBuilder.h" #include <sstream> @@ -14,18 +46,17 @@ #include "grid/Grid.h" #include "grid/GridFactory.h" -#include "io/STLReaderWriter/STLWriter.h" #include "io/GridVTKWriter/GridVTKWriter.h" +#include "io/STLReaderWriter/STLWriter.h" -MultipleGridBuilder::MultipleGridBuilder(SPtr<GridFactory> gridFactory, Device device, const std::string &d3qxx) : - LevelGridBuilder(device, d3qxx), gridFactory(gridFactory), solidObject(nullptr), numberOfLayersFine(12), numberOfLayersBetweenLevels(8), subDomainBox(nullptr) +MultipleGridBuilder::MultipleGridBuilder() : LevelGridBuilder(), numberOfLayersFine(12), numberOfLayersBetweenLevels(8), subDomainBox(nullptr) { } -SPtr<MultipleGridBuilder> MultipleGridBuilder::makeShared(SPtr<GridFactory> gridFactory) +SPtr<MultipleGridBuilder> MultipleGridBuilder::makeShared() { - return SPtr<MultipleGridBuilder>(new MultipleGridBuilder(gridFactory)); + return SPtr<MultipleGridBuilder>(new MultipleGridBuilder()); } void MultipleGridBuilder::addCoarseGrid(real startX, real startY, real startZ, real endX, real endY, real endZ, real delta) @@ -60,9 +91,6 @@ void MultipleGridBuilder::addGeometry(Object* solidObject, uint level) auto gridShape = solidObject->clone(); gridShape->scale(4.0); - //TriangularMesh* triangularMesh = dynamic_cast<TriangularMesh*>(gridShape); - //STLWriter::writeSTL(triangularMesh->triangleVec, "D:/GRIDGENERATION/STL/bridge.stl"); - this->addGrid(gridShape, level); } @@ -124,7 +152,6 @@ void MultipleGridBuilder::addIntermediateGridsToList(uint levelDifference, uint { auto spacings = getSpacingFactors(levelDifference); - // start = startFine - SUM(nodesBetweenGrids * 2^i * dxfine) uint level = getNumberOfLevels(); for (int i = levelDifference - 1; i >= 0; i--) { @@ -166,10 +193,9 @@ void MultipleGridBuilder::addGridToListIfValid(SPtr<Grid> grid) addGridToList(grid); } - SPtr<Grid> MultipleGridBuilder::makeGrid(Object* gridShape, real startX, real startY, real startZ, real endX, real endY, real endZ, real delta, uint level) const { - return gridFactory->makeGrid(gridShape, startX, startY, startZ, endX, endY, endZ, delta, level); + return GridImp::makeShared(gridShape, startX, startY, startZ, endX, endY, endZ, delta, "D3Q27", level); } bool MultipleGridBuilder::coarseGridExists() const @@ -366,6 +392,7 @@ bool MultipleGridBuilder::isGridInCoarseGrid(SPtr<Grid> grid) const vf::Math::lessEqual(grid->getEndZ(), grids[0]->getEndZ()); } + uint MultipleGridBuilder::getNumberOfLevels() const { return uint(grids.size()); @@ -577,7 +604,6 @@ GRIDGENERATOR_EXPORT void MultipleGridBuilder::setNumberOfLayers(uint numberOfLa this->numberOfLayersBetweenLevels = numberOfLayersBetweenLevels; } - void MultipleGridBuilder::emitNoCoarseGridExistsWarning() { *logging::out << logging::Logger::WARNING << "No Coarse grid was added before. Actual Grid is not added, please create coarse grid before.\n"; @@ -609,12 +635,6 @@ void MultipleGridBuilder::writeGridsToVtk(const std::string& path) const GridVTKWriter::writeGridToVTKXML(grids[level], ss.str()); - //if( level != 0 ) - // GridVTKWriter::writeInterpolationCellsToVTKXML(grids[level], grids[level-1], ss.str() + ".InterpolationCells"); - //else - // GridVTKWriter::writeInterpolationCellsToVTKXML(grids[level], nullptr , ss.str() + ".InterpolationCells"); - - //GridVTKWriter::writeSparseGridToVTK(grids[level], ss.str()); } } @@ -622,3 +642,4 @@ GRIDGENERATOR_EXPORT void MultipleGridBuilder::setSubDomainBox(SPtr<BoundingBox> { this->subDomainBox = subDomainBox; } + diff --git a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.h b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.h index 8fa61f8484c77d539331697e22b383176cdd19f4..fa3defd96c4012cb53cbd7d559771c0f07ae85d5 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.h +++ b/src/gpu/GridGenerator/grid/GridBuilder/MultipleGridBuilder.h @@ -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 MultipleGridBuilder.h +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz, Martin Schoenherr +//======================================================================================= #ifndef MULTIPLE_GRID_BUILDER_H #define MULTIPLE_GRID_BUILDER_H @@ -9,7 +41,7 @@ #include "global.h" #include "grid/GridBuilder/LevelGridBuilder.h" -#include "grid/GridFactory.h" +#include "grid/distributions/Distribution.h" class Object; class BoundingBox; @@ -17,17 +49,17 @@ class BoundingBox; class MultipleGridBuilder : public LevelGridBuilder { private: - GRIDGENERATOR_EXPORT MultipleGridBuilder(SPtr<GridFactory> gridFactory, Device device = Device::CPU, const std::string &d3qxx = "D3Q27"); + GRIDGENERATOR_EXPORT MultipleGridBuilder(); public: - GRIDGENERATOR_EXPORT static SPtr<MultipleGridBuilder> makeShared(SPtr<GridFactory> gridFactory); + GRIDGENERATOR_EXPORT static SPtr<MultipleGridBuilder> makeShared(); GRIDGENERATOR_EXPORT void addCoarseGrid(real startX, real startY, real startZ, real endX, real endY, real endZ, real delta); - GRIDGENERATOR_EXPORT void addGrid(Object* gridShape); - GRIDGENERATOR_EXPORT void addGrid(Object* gridShape, uint levelFine); + GRIDGENERATOR_EXPORT void addGrid(Object *gridShape); + GRIDGENERATOR_EXPORT void addGrid(Object *gridShape, uint levelFine); - GRIDGENERATOR_EXPORT void addGeometry(Object* gridShape); - GRIDGENERATOR_EXPORT void addGeometry(Object* solidObject, uint level); + GRIDGENERATOR_EXPORT void addGeometry(Object *gridShape); + GRIDGENERATOR_EXPORT void addGeometry(Object *solidObject, uint level); GRIDGENERATOR_EXPORT uint getNumberOfLevels() const; GRIDGENERATOR_EXPORT real getDelta(uint level) const; @@ -45,7 +77,7 @@ public: GRIDGENERATOR_EXPORT void setNumberOfLayers( uint numberOfLayersFine, uint numberOfLayersBetweenLevels ); - GRIDGENERATOR_EXPORT void writeGridsToVtk(const std::string& path) const; + GRIDGENERATOR_EXPORT void writeGridsToVtk(const std::string &path) const; GRIDGENERATOR_EXPORT void setSubDomainBox(SPtr<BoundingBox> subDomainBox); @@ -55,26 +87,23 @@ private: bool coarseGridExists() const; bool isGridInCoarseGrid(SPtr<Grid> grid) const; - void addFineGridToList(uint level, Object* gridShape); - void addIntermediateGridsToList(uint levelDifference, uint levelFine, uint nodesBetweenGrids, Object* gridShape); + void addFineGridToList(uint level, Object *gridShape); + void addIntermediateGridsToList(uint levelDifference, uint levelFine, uint nodesBetweenGrids, Object *gridShape); void eraseGridsFromListIfInvalid(uint oldSize); void addGridToListIfValid(SPtr<Grid> grid); - std::array<real, 6> getStaggeredCoordinates(Object* gridShape, uint level, uint levelFine, bool& xOddStart, bool& yOddStart, bool& zOddStart) const; + std::array<real, 6> getStaggeredCoordinates(Object *gridShape, uint level, uint levelFine, bool &xOddStart, bool &yOddStart, bool &zOddStart) const; std::array<real, 6> getStaggeredCoordinates(real startX, real startY, real startZ, real endX, real endY, real endZ, real delta, uint level) const; std::array<real, 3> getOffset(real delta) const; std::vector<uint> getSpacingFactors(uint levelDifference) const; - SPtr<Grid> makeGrid(Object* gridShape, uint level, uint levelFine); - SPtr<Grid> makeGrid(Object* gridShape, real startX, real startY, real startZ, real endX, real endY, real endZ, real delta, uint level) const; + SPtr<Grid> makeGrid(Object *gridShape, uint level, uint levelFine); + SPtr<Grid> makeGrid(Object *gridShape, real startX, real startY, real startZ, real endX, real endY, real endZ, real delta, uint level) const; static void emitNoCoarseGridExistsWarning(); static void emitGridIsNotInCoarseGridWarning(); - //std::vector<SPtr<Grid> > grids; - - SPtr<GridFactory> gridFactory; - Object* solidObject; + Object *solidObject; uint numberOfLayersFine; uint numberOfLayersBetweenLevels; @@ -82,8 +111,7 @@ private: SPtr<BoundingBox> subDomainBox; public: - - GRIDGENERATOR_EXPORT void findCommunicationIndices( int direction, LbmOrGks lbmOrGks ); + GRIDGENERATOR_EXPORT void findCommunicationIndices(int direction, LbmOrGks lbmOrGks); }; #endif diff --git a/src/gpu/GridGenerator/grid/GridFactory.cpp b/src/gpu/GridGenerator/grid/GridFactory.cpp deleted file mode 100644 index 3e2297c2105908c50485d1556c7060c9a3e15b74..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/grid/GridFactory.cpp +++ /dev/null @@ -1,4 +0,0 @@ -#include "GridFactory.h" - - - diff --git a/src/gpu/GridGenerator/grid/GridFactory.h b/src/gpu/GridGenerator/grid/GridFactory.h index b22d01ea12bbbc2cbf932d7b11eeb404dddffa58..b525596fa670a026d60b1297c75ef69c46b23498 100644 --- a/src/gpu/GridGenerator/grid/GridFactory.h +++ b/src/gpu/GridGenerator/grid/GridFactory.h @@ -1,22 +1,44 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// 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 GridFactory.h +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef GRID_FACTORY_H #define GRID_FACTORY_H #include "global.h" #include "geometries/Cuboid/Cuboid.h" -#include "geometries/Sphere/Sphere.h" -#include "geometries/TriangularMesh/TriangularMeshStrategy.h" -#include "grid/GridStrategy/GridCpuStrategy/GridCpuStrategy.h" -#include "grid/GridStrategy/GridGpuStrategy/GridGpuStrategy.h" -#include "grid/distributions/Distribution.h" #include "grid/GridImp.h" -enum class Device -{ - CPU, GPU -}; - enum class TriangularMeshDiscretizationMethod { RAYCASTING, POINT_IN_OBJECT, POINT_UNDER_TRIANGLE @@ -30,63 +52,10 @@ public: return SPtr<GridFactory>(new GridFactory()); } -private: - GridFactory() - { - gridStrategy = SPtr<GridStrategy>(new GridCpuStrategy()); - triangularMeshDiscretizationStrategy = new RayCastingDiscretizationStrategy(); - } - -public: SPtr<Grid> makeGrid(Object* gridShape, real startX, real startY, real startZ, real endX, real endY, real endZ, real delta, uint level, const std::string& d3Qxx = "D3Q27") { - Distribution distribution = DistributionHelper::getDistribution(d3Qxx); - - SPtr<GridImp> grid; - - grid = GridImp::makeShared(gridShape, startX, startY, startZ, endX, endY, endZ, delta, gridStrategy, distribution, level); - - grid->setTriangularMeshDiscretizationStrategy(this->triangularMeshDiscretizationStrategy); - - return grid; - } - - - void setGridStrategy(Device device) - { - switch (device) - { - case Device::CPU: - gridStrategy = SPtr<GridStrategy>(new GridCpuStrategy()); break; - case Device::GPU: - gridStrategy = SPtr<GridStrategy>(new GridGpuStrategy()); break; - } + return GridImp::makeShared(gridShape, startX, startY, startZ, endX, endY, endZ, delta, d3Qxx, level); } - - void setGridStrategy(SPtr<GridStrategy> gridStrategy) - { - this->gridStrategy = gridStrategy; - } - - void setTriangularMeshDiscretizationMethod(TriangularMeshDiscretizationMethod triangularMeshDiscretizationMethod) - { - switch (triangularMeshDiscretizationMethod) - { - case TriangularMeshDiscretizationMethod::POINT_UNDER_TRIANGLE: - triangularMeshDiscretizationStrategy = new PointUnderTriangleStrategy(); - break; - case TriangularMeshDiscretizationMethod::RAYCASTING: - triangularMeshDiscretizationStrategy = new RayCastingDiscretizationStrategy(); - break; - case TriangularMeshDiscretizationMethod::POINT_IN_OBJECT: - triangularMeshDiscretizationStrategy = new PointInObjectDiscretizationStrategy(); - break; - } - } - -private: - TriangularMeshDiscretizationStrategy* triangularMeshDiscretizationStrategy; - SPtr<GridStrategy> gridStrategy; }; diff --git a/src/gpu/GridGenerator/grid/GridImp.cu b/src/gpu/GridGenerator/grid/GridImp.cpp similarity index 73% rename from src/gpu/GridGenerator/grid/GridImp.cu rename to src/gpu/GridGenerator/grid/GridImp.cpp index 0be79ce95a26ac3a9bfe6c3e98286c7cce96563d..efe62002ac6ea00e90e63a7253324b44a77d5b9c 100644 --- a/src/gpu/GridGenerator/grid/GridImp.cu +++ b/src/gpu/GridGenerator/grid/GridImp.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 GridImp.cpp +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz, Martin Schoenherr +//======================================================================================= #include "GridImp.h" #include <stdio.h> @@ -5,6 +37,7 @@ #include <iostream> #include <omp.h> #include <sstream> +#include <cmath> #include "global.h" @@ -15,7 +48,6 @@ #include "geometries/TriangularMesh/TriangularMeshStrategy.h" #include "geometries/BoundingBox/BoundingBox.h" -#include "grid/GridStrategy/GridStrategy.h" #include "grid/distributions/Distribution.h" #include "grid/Field.h" #include "grid/GridInterface.h" @@ -26,12 +58,11 @@ #include "utilities/communication.h" #include "utilities/math/Math.h" -CONSTANT int DIRECTIONS[DIR_END_MAX][DIMENSION]; +int DIRECTIONS[DIR_END_MAX][DIMENSION]; using namespace vf::gpu; - -CUDA_HOST GridImp::GridImp(Object* object, real startX, real startY, real startZ, real endX, real endY, real endZ, real delta, SPtr<GridStrategy> gridStrategy, Distribution distribution, uint level) +GridImp::GridImp(Object* object, real startX, real startY, real startZ, real endX, real endY, real endZ, real delta, Distribution distribution, uint level) : object(object), startX(startX), startY(startY), @@ -40,7 +71,6 @@ CUDA_HOST GridImp::GridImp(Object* object, real startX, real startY, real startZ endY(endY), endZ(endZ), delta(delta), - gridStrategy(gridStrategy), distribution(distribution), level(level), periodicityX(false), @@ -63,9 +93,10 @@ CUDA_HOST GridImp::GridImp(Object* object, real startX, real startY, real startZ initalNumberOfNodesAndSize(); } -CUDA_HOST SPtr<GridImp> GridImp::makeShared(Object* object, real startX, real startY, real startZ, real endX, real endY, real endZ, real delta, SPtr<GridStrategy> gridStrategy, Distribution d, uint level) +SPtr<GridImp> GridImp::makeShared(Object* object, real startX, real startY, real startZ, real endX, real endY, real endZ, real delta, std::string d3Qxx, uint level) { - SPtr<GridImp> grid(new GridImp(object, startX, startY, startZ, endX, endY, endZ, delta, gridStrategy, d, level)); + Distribution distribution = DistributionHelper::getDistribution(d3Qxx); + SPtr<GridImp> grid(new GridImp(object, startX, startY, startZ, endX, endY, endZ, delta, distribution, level)); return grid; } @@ -76,25 +107,35 @@ void GridImp::initalNumberOfNodesAndSize() const real width = endY - startY; const real height = endZ - startZ; - nx = lround((length + delta) / delta); - ny = lround((width + delta) / delta); - nz = lround((height + delta) / delta); + nx = std::lround((length + delta) / delta); + ny = std::lround((width + delta) / delta); + nz = std::lround((height + delta) / delta); this->size = nx * ny * nz; this->sparseSize = size; distribution.setSize(size); - - this->numberOfSolidBoundaryNodes = 0; } -CUDA_HOST void GridImp::inital(const SPtr<Grid> fineGrid, uint numberOfLayers) +void GridImp::inital(const SPtr<Grid> fineGrid, uint numberOfLayers) { - field = Field(gridStrategy, size); + field = Field(size); field.allocateMemory(); - gridStrategy->allocateGridMemory(shared_from_this()); - + + this->neighborIndexX = new int[this->size]; + this->neighborIndexY = new int[this->size]; + this->neighborIndexZ = new int[this->size]; + this->neighborIndexNegative = new int[this->size]; + + this->sparseIndices = new int[this->size]; + + this->qIndices = new uint[this->size]; + for (uint i = 0; i < this->size; i++) + this->qIndices[i] = INVALID_INDEX; + *logging::out << logging::Logger::INFO_INTERMEDIATE << "Start initalNodesToOutOfGrid()\n"; - gridStrategy->initalNodesToOutOfGrid(shared_from_this()); +#pragma omp parallel for + for (int index = 0; index < (int)this->size; index++) + this->initalNodeToOutOfGrid(index); if( this->innerRegionFromFinerGrid ){ *logging::out << logging::Logger::INFO_INTERMEDIATE << "Start setInnerBasedOnFinerGrid()\n"; @@ -109,54 +150,81 @@ CUDA_HOST void GridImp::inital(const SPtr<Grid> fineGrid, uint numberOfLayers) this->addOverlap(); *logging::out << logging::Logger::INFO_INTERMEDIATE << "Start fixOddCells()\n"; - gridStrategy->fixOddCells( shared_from_this() ); +#pragma omp parallel for + for (int index = 0; index < (int)this->size; index++) + this->fixOddCell(index); if( enableFixRefinementIntoTheWall ) { *logging::out << logging::Logger::INFO_INTERMEDIATE << "Start fixRefinementIntoWall()\n"; - gridStrategy->fixRefinementIntoWall(shared_from_this()); +#pragma omp parallel for + for (int xIdx = 0; xIdx < (int)this->nx; xIdx++) { + for (uint yIdx = 0; yIdx < this->ny; yIdx++) { + this->fixRefinementIntoWall(xIdx, yIdx, 0, 3); + this->fixRefinementIntoWall(xIdx, yIdx, this->nz - 1, -3); + } + } + +#pragma omp parallel for + for (int xIdx = 0; xIdx < (int)this->nx; xIdx++) { + for (uint zIdx = 0; zIdx < this->nz; zIdx++) { + this->fixRefinementIntoWall(xIdx, 0, zIdx, 2); + this->fixRefinementIntoWall(xIdx, this->ny - 1, zIdx, -2); + } + } + +#pragma omp parallel for + for (int yIdx = 0; yIdx < (int)this->ny; yIdx++) { + for (uint zIdx = 0; zIdx < this->nz; zIdx++) { + this->fixRefinementIntoWall(0, yIdx, zIdx, 1); + this->fixRefinementIntoWall(this->nx - 1, yIdx, zIdx, -1); + } + } } *logging::out << logging::Logger::INFO_INTERMEDIATE << "Start findEndOfGridStopperNodes()\n"; - gridStrategy->findEndOfGridStopperNodes(shared_from_this()); +#pragma omp parallel for + for (int index = 0; index < (int)this->size; index++) + this->findEndOfGridStopperNode(index); *logging::out << logging::Logger::INFO_INTERMEDIATE << "Grid created: " << "from (" << this->startX << ", " << this->startY << ", " << this->startZ << ") to (" << this->endX << ", " << this->endY << ", " << this->endZ << ")\n" << "nodes: " << this->nx << " x " << this->ny << " x " << this->nz << " = " << this->size << "\n"; } -CUDA_HOST void GridImp::setOddStart(bool xOddStart, bool yOddStart, bool zOddStart) +void GridImp::setOddStart(bool xOddStart, bool yOddStart, bool zOddStart) { this->xOddStart = xOddStart; this->yOddStart = yOddStart; this->zOddStart = zOddStart; } -HOSTDEVICE void GridImp::initalNodeToOutOfGrid(uint index) -{ +void GridImp::initalNodeToOutOfGrid(uint index) { this->field.setFieldEntryToInvalidOutOfGrid(index); } -CUDA_HOST void GridImp::freeMemory() +void GridImp::freeMemory() { - gridStrategy->freeMemory(shared_from_this()); + if( this->neighborIndexX != nullptr ) { delete[] this->neighborIndexX; this->neighborIndexX = nullptr; } + if( this->neighborIndexY != nullptr ) { delete[] this->neighborIndexY; this->neighborIndexY = nullptr; } + if( this->neighborIndexZ != nullptr ) { delete[] this->neighborIndexZ; this->neighborIndexZ = nullptr; } + if( this->neighborIndexNegative != nullptr ) { delete[] this->neighborIndexNegative; this->neighborIndexNegative = nullptr; } + if( this->sparseIndices != nullptr ) { delete[] this->sparseIndices; this->sparseIndices = nullptr; } + if( this->qIndices != nullptr ) { delete[] this->qIndices; this->qIndices = nullptr; } + if( this->qValues != nullptr ) { delete[] this->qValues; this->qValues = nullptr; } + if( this->qPatches != nullptr ) { delete[] this->qPatches; this->qPatches = nullptr; } - gridStrategy->freeFieldMemory(&field); + field.freeMemory(); } -CUDA_HOST GridImp::GridImp() +void GridImp::findInnerNodes() { - //printf("Constructor\n"); - //this->print(); -} - -CUDA_HOST GridImp::~GridImp() -{ - //printf("Destructor\n"); - //this->print(); +#pragma omp parallel for + for (int index = 0; index < (int)this->size; index++) + this->findInnerNode(index); } -HOSTDEVICE void GridImp::findInnerNode(uint index) +void GridImp::findInnerNode(uint index) { this->sparseIndices[index] = index; @@ -179,7 +247,7 @@ HOSTDEVICE void GridImp::findInnerNode(uint index) } } -HOSTDEVICE void GridImp::discretize(Object* solidObject, char innerType, char outerType) +void GridImp::discretize(Object* solidObject, char innerType, char outerType) { #pragma omp parallel for for (int index = 0; index < (int)this->size; index++) @@ -215,7 +283,7 @@ bool GridImp::isInside(const Cell& cell) const // even even even // odd odd odd // -HOSTDEVICE Cell GridImp::getOddCellFromIndex(uint index) const +Cell GridImp::getOddCellFromIndex(uint index) const { real x, y, z; this->transIndexToCoords(index, x, y, z); @@ -239,7 +307,7 @@ HOSTDEVICE Cell GridImp::getOddCellFromIndex(uint index) const return Cell(xCellStart, yCellStart, zCellStart, delta); } -HOSTDEVICE void GridImp::setInnerBasedOnFinerGrid(const SPtr<Grid> fineGrid) +void GridImp::setInnerBasedOnFinerGrid(const SPtr<Grid> fineGrid) { for( uint index = 0; index < this->size; index++ ){ @@ -266,14 +334,20 @@ HOSTDEVICE void GridImp::setInnerBasedOnFinerGrid(const SPtr<Grid> fineGrid) } } -HOSTDEVICE void GridImp::addOverlap() +void GridImp::addOverlap() { for( uint layer = 0; layer < this->numberOfLayers; layer++ ){ - this->gridStrategy->addOverlap( shared_from_this() ); +#pragma omp parallel for + for (int index = 0; index < (int)this->size; index++) + this->setOverlapTmp(index); + +#pragma omp parallel for + for (int index = 0; index < (int)this->size; index++) + this->setOverlapFluid(index); } } -HOSTDEVICE void GridImp::setOverlapTmp( uint index ) +void GridImp::setOverlapTmp( uint index ) { if( this->field.is( index, INVALID_OUT_OF_GRID ) ){ @@ -283,14 +357,14 @@ HOSTDEVICE void GridImp::setOverlapTmp( uint index ) } } -HOSTDEVICE void GridImp::setOverlapFluid( uint index ) +void GridImp::setOverlapFluid( uint index ) { if( this->field.is( index, OVERLAP_TMP ) ){ this->field.setFieldEntry( index, FLUID ); } } -HOSTDEVICE void GridImp::fixRefinementIntoWall(uint xIndex, uint yIndex, uint zIndex, int dir) +void GridImp::fixRefinementIntoWall(uint xIndex, uint yIndex, uint zIndex, int dir) { real x = this->startX + this->delta * xIndex; @@ -310,7 +384,7 @@ HOSTDEVICE void GridImp::fixRefinementIntoWall(uint xIndex, uint yIndex, uint zI ////////////////////////////////////////////////////////////////////////// - real dx, dy, dz; + real dx{ 0.0 }, dy{ 0.0 }, dz{ 0.0 }; if ( dir == 1 ){ dx = this->delta; dy = 0.0; dz = 0.0; } else if ( dir == -1 ){ dx = - this->delta; dy = 0.0; dz = 0.0; } @@ -349,7 +423,7 @@ HOSTDEVICE void GridImp::fixRefinementIntoWall(uint xIndex, uint yIndex, uint zI } } -HOSTDEVICE void GridImp::findStopperNode(uint index) // deprecated +void GridImp::findStopperNode(uint index) // deprecated { if(isValidEndOfGridStopper(index)) this->field.setFieldEntryToStopperOutOfGrid(index); @@ -358,7 +432,7 @@ HOSTDEVICE void GridImp::findStopperNode(uint index) // deprecated this->field.setFieldEntry(index, STOPPER_SOLID); } -HOSTDEVICE void GridImp::findEndOfGridStopperNode(uint index) +void GridImp::findEndOfGridStopperNode(uint index) { if (isValidEndOfGridStopper(index)){ if( this->level != 0 ) @@ -371,13 +445,13 @@ HOSTDEVICE void GridImp::findEndOfGridStopperNode(uint index) this->field.setFieldEntryToStopperOutOfGridBoundary(index); } -HOSTDEVICE void GridImp::findSolidStopperNode(uint index) +void GridImp::findSolidStopperNode(uint index) { if (isValidSolidStopper(index)) this->field.setFieldEntry(index, STOPPER_SOLID); } -HOSTDEVICE void GridImp::findBoundarySolidNode(uint index) +void GridImp::findBoundarySolidNode(uint index) { if (shouldBeBoundarySolidNode(index)) { @@ -387,7 +461,7 @@ HOSTDEVICE void GridImp::findBoundarySolidNode(uint index) } } -HOSTDEVICE void GridImp::fixOddCell(uint index) +void GridImp::fixOddCell(uint index) { Cell cell = getOddCellFromIndex(index); if (isOutSideOfGrid(cell)) @@ -396,7 +470,7 @@ HOSTDEVICE void GridImp::fixOddCell(uint index) setNodeTo(cell, FLUID); } -HOSTDEVICE bool GridImp::isOutSideOfGrid(Cell &cell) const +bool GridImp::isOutSideOfGrid(Cell &cell) const { for (const auto point : cell) { if (point.x < startX || point.x > endX @@ -407,7 +481,7 @@ HOSTDEVICE bool GridImp::isOutSideOfGrid(Cell &cell) const return false; } -HOSTDEVICE bool GridImp::contains(Cell &cell, char type) const +bool GridImp::contains(Cell &cell, char type) const { for (const auto point : cell) { uint index = transCoordToIndex(point.x, point.y, point.z); @@ -419,7 +493,7 @@ HOSTDEVICE bool GridImp::contains(Cell &cell, char type) const return false; } -HOSTDEVICE bool GridImp::cellContainsOnly(Cell &cell, char type) const +bool GridImp::cellContainsOnly(Cell &cell, char type) const { for (const auto point : cell) { uint index = transCoordToIndex(point.x, point.y, point.z); @@ -431,7 +505,7 @@ HOSTDEVICE bool GridImp::cellContainsOnly(Cell &cell, char type) const return true; } -HOSTDEVICE bool GridImp::cellContainsOnly(Cell &cell, char typeA, char typeB) const +bool GridImp::cellContainsOnly(Cell &cell, char typeA, char typeB) const { for (const auto point : cell) { uint index = transCoordToIndex(point.x, point.y, point.z); @@ -443,12 +517,12 @@ HOSTDEVICE bool GridImp::cellContainsOnly(Cell &cell, char typeA, char typeB) co return true; } -HOSTDEVICE const Object * GridImp::getObject() const +const Object * GridImp::getObject() const { return this->object; } -HOSTDEVICE void GridImp::setNodeTo(Cell &cell, char type) +void GridImp::setNodeTo(Cell &cell, char type) { for (const auto point : cell) { uint index = transCoordToIndex(point.x, point.y, point.z); @@ -458,61 +532,48 @@ HOSTDEVICE void GridImp::setNodeTo(Cell &cell, char type) } } -HOSTDEVICE void GridImp::setNodeTo(uint index, char type) +void GridImp::setNodeTo(uint index, char type) { if( index != INVALID_INDEX ) field.setFieldEntry(index, type); } -HOSTDEVICE bool GridImp::isNode(uint index, char type) const +bool GridImp::isNode(uint index, char type) const { if( index != INVALID_INDEX ) - return field.is(index, type); + return field.is(index, type); - return false; - // TODO: cannot throw on gpu: throw std::runtime_error("GridImp::isNode() -> index == INVALID_INDEX not supported."); + throw std::runtime_error("GridImp::isNode() -> index == INVALID_INDEX not supported."); } -HOSTDEVICE bool GridImp::isValidEndOfGridStopper(uint index) const +bool GridImp::isValidEndOfGridStopper(uint index) const { // Lenz: also includes corner stopper nodes if (!this->field.is(index, INVALID_OUT_OF_GRID)) return false; return hasNeighborOfType(index, FLUID); - - //previous version of S�ren P. - //return this->field.is(index, OUT_OF_GRID) && (nodeInNextCellIs(index, FLUID) || nodeInNextCellIs(index, FLUID_CFF)) - // || this->field.is(index, OUT_OF_GRID) && (nodeInPreviousCellIs(index, FLUID) || nodeInPreviousCellIs(index, FLUID_CFF)); } -HOSTDEVICE bool GridImp::isValidEndOfGridBoundaryStopper(uint index) const +bool GridImp::isValidEndOfGridBoundaryStopper(uint index) const { // Lenz: also includes corner stopper nodes if (!this->field.is(index, FLUID)) return false; return ! hasAllNeighbors(index); - - //previous version of S�ren P. - //return this->field.is(index, OUT_OF_GRID) && (nodeInNextCellIs(index, FLUID) || nodeInNextCellIs(index, FLUID_CFF)) - // || this->field.is(index, OUT_OF_GRID) && (nodeInPreviousCellIs(index, FLUID) || nodeInPreviousCellIs(index, FLUID_CFF)); } -HOSTDEVICE bool GridImp::isValidSolidStopper(uint index) const +bool GridImp::isValidSolidStopper(uint index) const { // Lenz: also includes corner stopper nodes if (!this->field.is(index, INVALID_SOLID)) return false; return hasNeighborOfType(index, FLUID); - - //previous version of S�ren P. - //return this->field.is(index, SOLID) && (nodeInNextCellIs(index, FLUID) || nodeInNextCellIs(index, FLUID_CFF)) - // || this->field.is(index, SOLID) && (nodeInPreviousCellIs(index, FLUID) || nodeInPreviousCellIs(index, FLUID_CFF)); } -HOSTDEVICE bool GridImp::shouldBeBoundarySolidNode(uint index) const +bool GridImp::shouldBeBoundarySolidNode(uint index) const { if (!this->field.is(index, FLUID)) return false; @@ -520,7 +581,7 @@ HOSTDEVICE bool GridImp::shouldBeBoundarySolidNode(uint index) const return hasNeighborOfType(index, STOPPER_SOLID); } -HOSTDEVICE bool GridImp::hasAllNeighbors(uint index) const +bool GridImp::hasAllNeighbors(uint index) const { // new version by Lenz, utilizes the range based for loop for all directions real x, y, z; @@ -534,7 +595,7 @@ HOSTDEVICE bool GridImp::hasAllNeighbors(uint index) const return true; } -HOSTDEVICE bool GridImp::hasNeighborOfType(uint index, char type) const +bool GridImp::hasNeighborOfType(uint index, char type) const { // new version by Lenz, utilizes the range based for loop for all directions real x, y, z; @@ -549,47 +610,9 @@ HOSTDEVICE bool GridImp::hasNeighborOfType(uint index, char type) const } return false; - - //real x, y, z; - //this->transIndexToCoords(index, x, y, z); - - //const real neighborX = x + this->delta > endX ? endX : x + this->delta; - //const real neighborY = y + this->delta > endY ? endY : y + this->delta; - //const real neighborZ = z + this->delta > endZ ? endZ : z + this->delta; - - //const real neighborMinusX = x - this->delta < startX ? startX : x - this->delta; - //const real neighborMinusY = y - this->delta < startY ? startY : y - this->delta; - //const real neighborMinusZ = z - this->delta < startZ ? startZ : z - this->delta; - - - //const uint indexMXY = transCoordToIndex(-neighborX, neighborY, z); - //const uint indexMYZ = transCoordToIndex(x, -neighborY, neighborZ); - //const uint indexMXZ = transCoordToIndex(-neighborX, y, neighborZ); - - //const uint indexXMY = transCoordToIndex(neighborX, -neighborY, z); - //const uint indexYMZ = transCoordToIndex(x, neighborY, -neighborZ); - //const uint indexXMZ = transCoordToIndex(neighborX, y, -neighborZ); - - //const uint indexMXYMZ = transCoordToIndex(-neighborX, neighborY, -neighborZ); - //const uint indexMXYZ = transCoordToIndex(-neighborX, neighborY, neighborZ); - //const uint indexMXMYZ = transCoordToIndex(-neighborX, -neighborY, neighborZ); - //const uint indexXMYMZ = transCoordToIndex(neighborX, -neighborY, -neighborZ); - //const uint indexXMYZ = transCoordToIndex(neighborX, -neighborY, neighborZ); - //const uint indexXYMZ = transCoordToIndex(neighborX, neighborY, -neighborZ); - - - - //return nodeInNextCellIs(index, type) || nodeInPreviousCellIs(index, type) || indexMXY || indexMYZ || indexMXZ || indexXMY || indexYMZ || indexXMZ - // || indexMXYMZ - // || indexMXYZ - // || indexMXMYZ - // || indexXMYMZ - // || indexXMYZ - // || indexXYMZ; - } -HOSTDEVICE bool GridImp::nodeInNextCellIs(int index, char type) const +bool GridImp::nodeInNextCellIs(int index, char type) const { real x, y, z; this->transIndexToCoords(index, x, y, z); @@ -620,7 +643,7 @@ HOSTDEVICE bool GridImp::nodeInNextCellIs(int index, char type) const || typeXZ || typeXYZ; } -HOSTDEVICE bool GridImp::nodeInPreviousCellIs(int index, char type) const +bool GridImp::nodeInPreviousCellIs(int index, char type) const { real x, y, z; this->transIndexToCoords(index, x, y, z); @@ -651,7 +674,7 @@ HOSTDEVICE bool GridImp::nodeInPreviousCellIs(int index, char type) const || typeXZ || typeXYZ; } -HOSTDEVICE bool GridImp::nodeInCellIs(Cell& cell, char type) const +bool GridImp::nodeInCellIs(Cell& cell, char type) const { for (const auto node : cell) { @@ -700,7 +723,7 @@ void GridImp::setNonStopperOutOfGridCellTo(uint index, char type) } -CUDA_HOST void GridImp::setPeriodicity(bool periodicityX, bool periodicityY, bool periodicityZ) +void GridImp::setPeriodicity(bool periodicityX, bool periodicityY, bool periodicityZ) { this->periodicityX = periodicityX; this->periodicityY = periodicityY; @@ -709,17 +732,17 @@ CUDA_HOST void GridImp::setPeriodicity(bool periodicityX, bool periodicityY, boo void GridImp::setPeriodicityX(bool periodicity) { - this->periodicityX = periodicityX; + this->periodicityX = periodicity; } void GridImp::setPeriodicityY(bool periodicity) { - this->periodicityY = periodicityY; + this->periodicityY = periodicity; } void GridImp::setPeriodicityZ(bool periodicity) { - this->periodicityZ = periodicityZ; + this->periodicityZ = periodicity; } bool GridImp::getPeriodicityX() @@ -742,7 +765,7 @@ void GridImp::setEnableFixRefinementIntoTheWall(bool enableFixRefinementIntoTheW this->enableFixRefinementIntoTheWall = enableFixRefinementIntoTheWall; } -HOSTDEVICE uint GridImp::transCoordToIndex(const real &x, const real &y, const real &z) const +uint GridImp::transCoordToIndex(const real &x, const real &y, const real &z) const { const uint xIndex = getXIndex(x); const uint yIndex = getYIndex(y); @@ -754,21 +777,21 @@ HOSTDEVICE uint GridImp::transCoordToIndex(const real &x, const real &y, const r return xIndex + nx * (yIndex + ny * zIndex); } -HOSTDEVICE void GridImp::transIndexToCoords(uint index, real &x, real &y, real &z) const +void GridImp::transIndexToCoords(uint index, real &x, real &y, real &z) const { if (index == INVALID_INDEX) printf("Function: transIndexToCoords. GridImp Index: %d, size: %d. Exit Program!\n", index, size); - x = index % nx; - y = (index / nx) % ny; - z = ((index / nx) / ny) % nz; + x = (real)(index % nx); + y = (real)((index / nx) % ny); + z = (real)(((index / nx) / ny) % nz); x = (x * delta) + startX; y = (y * delta) + startY; z = (z * delta) + startZ; } -CUDA_HOST uint GridImp::getLevel(real startDelta) const +uint GridImp::getLevel(real startDelta) const { uint level = 0; real delta = this->delta; @@ -780,50 +803,50 @@ CUDA_HOST uint GridImp::getLevel(real startDelta) const return level; } -CUDA_HOST uint GridImp::getLevel() const +uint GridImp::getLevel() const { return this->level; } -CUDA_HOST void GridImp::setTriangularMeshDiscretizationStrategy(TriangularMeshDiscretizationStrategy* triangularMeshDiscretizationStrategy) +void GridImp::setTriangularMeshDiscretizationStrategy(TriangularMeshDiscretizationStrategy* triangularMeshDiscretizationStrategy) { this->triangularMeshDiscretizationStrategy = triangularMeshDiscretizationStrategy; } -CUDA_HOST TriangularMeshDiscretizationStrategy * GridImp::getTriangularMeshDiscretizationStrategy() +TriangularMeshDiscretizationStrategy * GridImp::getTriangularMeshDiscretizationStrategy() { return this->triangularMeshDiscretizationStrategy; } -CUDA_HOST uint GridImp::getNumberOfSolidBoundaryNodes() const +uint GridImp::getNumberOfSolidBoundaryNodes() const { return this->numberOfSolidBoundaryNodes; } -CUDA_HOST void GridImp::setNumberOfSolidBoundaryNodes(uint numberOfSolidBoundaryNodes) +void GridImp::setNumberOfSolidBoundaryNodes(uint numberOfSolidBoundaryNodes) { if (numberOfSolidBoundaryNodes < INVALID_INDEX) this->numberOfSolidBoundaryNodes = numberOfSolidBoundaryNodes; } -CUDA_HOST real GridImp::getQValue(const uint index, const uint dir) const +real GridImp::getQValue(const uint index, const uint dir) const { const int qIndex = dir * this->numberOfSolidBoundaryNodes + this->qIndices[index]; return this->qValues[qIndex]; } -CUDA_HOST uint GridImp::getQPatch(const uint index) const +uint GridImp::getQPatch(const uint index) const { return this->qPatches[ this->qIndices[index] ]; } -CUDA_HOST void GridImp::setInnerRegionFromFinerGrid(bool innerRegionFromFinerGrid) +void GridImp::setInnerRegionFromFinerGrid(bool innerRegionFromFinerGrid) { this->innerRegionFromFinerGrid = innerRegionFromFinerGrid; } -CUDA_HOST void GridImp::setNumberOfLayers(uint numberOfLayers) +void GridImp::setNumberOfLayers(uint numberOfLayers) { this->numberOfLayers = numberOfLayers; } @@ -832,13 +855,28 @@ CUDA_HOST void GridImp::setNumberOfLayers(uint numberOfLayers) // Set Sparse Indices // // --------------------------------------------------------- // -CUDA_HOST void GridImp::findSparseIndices(SPtr<Grid> fineGrid) +void GridImp::findSparseIndices(SPtr<Grid> finerGrid) { - this->gridStrategy->findSparseIndices(shared_from_this(), std::static_pointer_cast<GridImp>(fineGrid)); + *logging::out << logging::Logger::INFO_INTERMEDIATE << "Find sparse indices..."; + auto fineGrid = std::static_pointer_cast<GridImp>(finerGrid); + + this->updateSparseIndices(); + +#pragma omp parallel for + for (int index = 0; index < (int)this->getSize(); index++) + this->setNeighborIndices(index); + + if (fineGrid) { + fineGrid->updateSparseIndices(); + } + + const uint newGridSize = this->getSparseSize(); + *logging::out << logging::Logger::INFO_INTERMEDIATE << "... done. new size: " << newGridSize + << ", delete nodes:" << this->getSize() - newGridSize << "\n"; } -CUDA_HOST void GridImp::updateSparseIndices() +void GridImp::updateSparseIndices() { int removedNodes = 0; int newIndex = 0; @@ -858,7 +896,7 @@ CUDA_HOST void GridImp::updateSparseIndices() sparseSize = size - removedNodes; } -HOSTDEVICE void GridImp::setNeighborIndices(uint index) +void GridImp::setNeighborIndices(uint index) { real x, y, z; this->transIndexToCoords(index, x, y, z); @@ -893,7 +931,7 @@ HOSTDEVICE void GridImp::setNeighborIndices(uint index) this->neighborIndexNegative[index] = neighborNegative; } -HOSTDEVICE void GridImp::setStopperNeighborCoords(uint index) +void GridImp::setStopperNeighborCoords(uint index) { real x, y, z; this->transIndexToCoords(index, x, y, z); @@ -916,7 +954,7 @@ HOSTDEVICE void GridImp::setStopperNeighborCoords(uint index) } } -HOSTDEVICE void GridImp::getNeighborCoords(real &neighborX, real &neighborY, real &neighborZ, real x, real y, real z) const +void GridImp::getNeighborCoords(real &neighborX, real &neighborY, real &neighborZ, real x, real y, real z) const { real coords[3] = { x, y, z }; neighborX = getNeighborCoord(periodicityX, startX, coords, 0); @@ -924,7 +962,7 @@ HOSTDEVICE void GridImp::getNeighborCoords(real &neighborX, real &neighborY, rea neighborZ = getNeighborCoord(periodicityZ, startZ, coords, 2); } -HOSTDEVICE real GridImp::getNeighborCoord(bool periodicity, real startCoord, real coords[3], int direction) const +real GridImp::getNeighborCoord(bool periodicity, real startCoord, real coords[3], int direction) const { if (periodicity) { @@ -932,11 +970,6 @@ HOSTDEVICE real GridImp::getNeighborCoord(bool periodicity, real startCoord, rea neighborCoords[direction] = neighborCoords[direction] + delta; const int neighborIndex = this->transCoordToIndex(neighborCoords[0], neighborCoords[1], neighborCoords[2]); - //if(!field.isStopperOutOfGrid(neighborIndex) && !field.is(neighborIndex, STOPPER_OUT_OF_GRID_BOUNDARY) ) - // return coords[direction] + delta; - - //return getFirstFluidNode(coords, direction, startCoord); - ////////////////////////////////////////////////////////////////////////// if( field.is(neighborIndex, STOPPER_OUT_OF_GRID_BOUNDARY) ) @@ -949,7 +982,7 @@ HOSTDEVICE real GridImp::getNeighborCoord(bool periodicity, real startCoord, rea return coords[direction] + delta; } -HOSTDEVICE void GridImp::getNegativeNeighborCoords(real &neighborX, real &neighborY, real &neighborZ, real x, real y, real z) const +void GridImp::getNegativeNeighborCoords(real &neighborX, real &neighborY, real &neighborZ, real x, real y, real z) const { real coords[3] = { x, y, z }; @@ -958,13 +991,13 @@ HOSTDEVICE void GridImp::getNegativeNeighborCoords(real &neighborX, real &neighb neighborZ = getNegativeNeighborCoord(periodicityZ, endZ, coords, 2); } -HOSTDEVICE real GridImp::getNegativeNeighborCoord(bool periodicity, real startCoord, real coords[3], int direction) const +real GridImp::getNegativeNeighborCoord(bool periodicity, real startCoord, real coords[3], int direction) const { if (periodicity) { real neighborCoords[3] = {coords[0], coords[1] , coords[2] }; neighborCoords[direction] = neighborCoords[direction] - delta; - const int neighborIndex = this->transCoordToIndex(neighborCoords[0], neighborCoords[1], neighborCoords[2]); + const uint neighborIndex = this->transCoordToIndex(neighborCoords[0], neighborCoords[1], neighborCoords[2]); if(neighborIndex != INVALID_INDEX && !field.isStopperOutOfGrid(neighborIndex) && !field.is(neighborIndex, STOPPER_OUT_OF_GRID_BOUNDARY) ) return coords[direction] - delta; @@ -976,10 +1009,10 @@ HOSTDEVICE real GridImp::getNegativeNeighborCoord(bool periodicity, real startCo } -HOSTDEVICE real GridImp::getLastFluidNode(real coords[3], int direction, real startCoord) const +real GridImp::getLastFluidNode(real coords[3], int direction, real startCoord) const { coords[direction] = startCoord; - int index = this->transCoordToIndex(coords[0], coords[1], coords[2]); + uint index = this->transCoordToIndex(coords[0], coords[1], coords[2]); while (index != INVALID_INDEX && !field.isFluid(index)) { coords[direction] -= delta; @@ -988,7 +1021,7 @@ HOSTDEVICE real GridImp::getLastFluidNode(real coords[3], int direction, real st return coords[direction]; } -HOSTDEVICE real GridImp::getFirstFluidNode(real coords[3], int direction, real startCoord) const +real GridImp::getFirstFluidNode(real coords[3], int direction, real startCoord) const { coords[direction] = startCoord; uint index = this->transCoordToIndex(coords[0], coords[1], coords[2]); @@ -1001,27 +1034,57 @@ HOSTDEVICE real GridImp::getFirstFluidNode(real coords[3], int direction, real s } -HOSTDEVICE int GridImp::getSparseIndex(const real &x, const real &y, const real &z) const +int GridImp::getSparseIndex(const real &x, const real &y, const real &z) const { const int matrixIndex = transCoordToIndex(x, y, z); return sparseIndices[matrixIndex]; } - // --------------------------------------------------------- // // Find Interface // // --------------------------------------------------------- // -CUDA_HOST void GridImp::findGridInterface(SPtr<Grid> finerGrid, LbmOrGks lbmOrGks) +void GridImp::findGridInterface(SPtr<Grid> finerGrid, LbmOrGks lbmOrGks) { - gridStrategy->findGridInterface(shared_from_this(), std::static_pointer_cast<GridImp>(finerGrid), lbmOrGks); + auto fineGrid = std::static_pointer_cast<GridImp>(finerGrid); + const auto coarseLevel = this->getLevel(); + const auto fineLevel = fineGrid->getLevel(); + + *logging::out << logging::Logger::INFO_INTERMEDIATE << "find interface level " << coarseLevel << " -> " + << fineLevel; + + this->gridInterface = new GridInterface(); + // TODO: this is stupid! concave refinements can easily have many more interface cells + const uint sizeCF = 10 * (fineGrid->nx * fineGrid->ny + fineGrid->ny * fineGrid->nz + fineGrid->nx * fineGrid->nz); + this->gridInterface->cf.coarse = new uint[sizeCF]; + this->gridInterface->cf.fine = new uint[sizeCF]; + this->gridInterface->cf.offset = new uint[sizeCF]; + this->gridInterface->fc.coarse = new uint[sizeCF]; + this->gridInterface->fc.fine = new uint[sizeCF]; + this->gridInterface->fc.offset = new uint[sizeCF]; + + for (uint index = 0; index < this->getSize(); index++) + this->findGridInterfaceCF(index, *fineGrid, lbmOrGks); + + for (uint index = 0; index < this->getSize(); index++) + this->findGridInterfaceFC(index, *fineGrid); + + for (uint index = 0; index < this->getSize(); index++) + this->findOverlapStopper(index, *fineGrid); + + if (lbmOrGks == GKS) { + for (uint index = 0; index < this->getSize(); index++) + this->findInvalidBoundaryNodes(index); + } + + *logging::out << logging::Logger::INFO_INTERMEDIATE << " ... done. \n"; } -HOSTDEVICE void GridImp::repairGridInterfaceOnMultiGPU(SPtr<Grid> fineGrid) +void GridImp::repairGridInterfaceOnMultiGPU(SPtr<Grid> fineGrid) { this->gridInterface->repairGridInterfaceOnMultiGPU( shared_from_this(), std::static_pointer_cast<GridImp>(fineGrid) ); } -CUDA_HOST void GridImp::limitToSubDomain(SPtr<BoundingBox> subDomainBox, LbmOrGks lbmOrGks) +void GridImp::limitToSubDomain(SPtr<BoundingBox> subDomainBox, LbmOrGks lbmOrGks) { for( uint index = 0; index < this->size; index++ ){ @@ -1060,11 +1123,9 @@ CUDA_HOST void GridImp::limitToSubDomain(SPtr<BoundingBox> subDomainBox, LbmOrGk this->setFieldEntry(index, INVALID_OUT_OF_GRID); } } - - //this->gridStrategy->findEndOfGridStopperNodes(shared_from_this()); } -HOSTDEVICE void GridImp::findGridInterfaceCF(uint index, GridImp& finerGrid, LbmOrGks lbmOrGks) +void GridImp::findGridInterfaceCF(uint index, GridImp& finerGrid, LbmOrGks lbmOrGks) { if (lbmOrGks == LBM) { @@ -1075,17 +1136,17 @@ HOSTDEVICE void GridImp::findGridInterfaceCF(uint index, GridImp& finerGrid, Lbm gridInterface->findInterfaceCF_GKS(index, this, &finerGrid); } -HOSTDEVICE void GridImp::findGridInterfaceFC(uint index, GridImp& finerGrid) +void GridImp::findGridInterfaceFC(uint index, GridImp& finerGrid) { gridInterface->findInterfaceFC(index, this, &finerGrid); } -HOSTDEVICE void GridImp::findOverlapStopper(uint index, GridImp& finerGrid) +void GridImp::findOverlapStopper(uint index, GridImp& finerGrid) { gridInterface->findOverlapStopper(index, this, &finerGrid); } -HOSTDEVICE void GridImp::findInvalidBoundaryNodes(uint index) +void GridImp::findInvalidBoundaryNodes(uint index) { gridInterface->findInvalidBoundaryNodes(index, this); } @@ -1093,28 +1154,35 @@ HOSTDEVICE void GridImp::findInvalidBoundaryNodes(uint index) // --------------------------------------------------------- // // Mesh Triangle // // --------------------------------------------------------- // -CUDA_HOST void GridImp::mesh(Object* object) +void GridImp::mesh(Object* object) { TriangularMesh* triangularMesh = dynamic_cast<TriangularMesh*>(object); if (triangularMesh) triangularMeshDiscretizationStrategy->discretize(triangularMesh, this, INVALID_SOLID, FLUID); else - //gridStrategy->findInnerNodes(shared_from_this()); //TODO: adds INNERTYPE AND OUTERTYPE to findInnerNodes //new method for geometric primitives (not cell based) to be implemented this->discretize(object, INVALID_SOLID, FLUID); this->closeNeedleCells(); - gridStrategy->findSolidStopperNodes(shared_from_this()); - gridStrategy->findBoundarySolidNodes(shared_from_this()); + #pragma omp parallel for + for (int index = 0; index < (int)this->size; index++) + this->findSolidStopperNode(index); + + //#pragma omp parallel for + for (int index = 0; index < (int)this->size; index++) { + this->findBoundarySolidNode(index); + } } -CUDA_HOST void GridImp::mesh(TriangularMesh &triangularMesh) +void GridImp::mesh(TriangularMesh &triangularMesh) { const clock_t begin = clock(); - gridStrategy->mesh(shared_from_this(), triangularMesh); +#pragma omp parallel for + for (int i = 0; i < triangularMesh.size; i++) + this->mesh(triangularMesh.triangles[i]); const clock_t end = clock(); const real time = (real)(real(end - begin) / CLOCKS_PER_SEC); @@ -1122,7 +1190,7 @@ CUDA_HOST void GridImp::mesh(TriangularMesh &triangularMesh) *logging::out << logging::Logger::INFO_INTERMEDIATE << "time grid generation: " << time << "s\n"; } -HOSTDEVICE void GridImp::mesh(Triangle &triangle) +void GridImp::mesh(Triangle &triangle) { auto box = this->getBoundingBoxOnNodes(triangle); triangle.initalLayerThickness(getDelta()); @@ -1148,20 +1216,25 @@ HOSTDEVICE void GridImp::mesh(Triangle &triangle) } } -CUDA_HOST void GridImp::closeNeedleCells() +void GridImp::closeNeedleCells() { *logging::out << logging::Logger::INFO_INTERMEDIATE << "Start closeNeedleCells()\n"; uint numberOfClosedNeedleCells = 0; do{ - numberOfClosedNeedleCells = this->gridStrategy->closeNeedleCells( shared_from_this() ); +#pragma omp parallel for reduction(+ : numberOfClosedNeedleCells) + for (int index = 0; index < (int)this->size; index++) { + if (this->closeCellIfNeedle(index)) + numberOfClosedNeedleCells++; + } + *logging::out << logging::Logger::INFO_INTERMEDIATE << numberOfClosedNeedleCells << " cells closed!\n"; } while( numberOfClosedNeedleCells > 0 ); } -HOSTDEVICE bool GridImp::closeCellIfNeedle(uint index) +bool GridImp::closeCellIfNeedle(uint index) { if( !this->getField().is( index, FLUID ) ) return false; @@ -1183,38 +1256,31 @@ HOSTDEVICE bool GridImp::closeCellIfNeedle(uint index) return false; } -CUDA_HOST void GridImp::closeNeedleCellsThinWall() +void GridImp::closeNeedleCellsThinWall() { *logging::out << logging::Logger::INFO_INTERMEDIATE << "Start closeNeedleCellsThinWall()\n"; uint numberOfClosedNeedleCells = 0; do{ - numberOfClosedNeedleCells = this->gridStrategy->closeNeedleCellsThinWall( shared_from_this() ); +#pragma omp parallel for reduction(+ : numberOfClosedNeedleCells) + for (int index = 0; index < (int)this->size; index++) { + if (this->closeCellIfNeedleThinWall(index)) + numberOfClosedNeedleCells++; + } + *logging::out << logging::Logger::INFO_INTERMEDIATE << numberOfClosedNeedleCells << " cells closed!\n"; } while( numberOfClosedNeedleCells > 0 ); } -HOSTDEVICE bool GridImp::closeCellIfNeedleThinWall(uint index) +bool GridImp::closeCellIfNeedleThinWall(uint index) { if( !this->getField().is( index, BC_SOLID ) ) return false; real x, y, z; this->transIndexToCoords(index, x, y, z); - //bool noValidNeighborInX = !this->getField().is( this->transCoordToIndex( x + this->delta, y, z ) , FLUID ) && - // !this->getField().is( this->transCoordToIndex( x - this->delta, y, z ) , FLUID ); - //bool noValidNeighborInY = !this->getField().is( this->transCoordToIndex( x, y + this->delta, z ) , FLUID ) && - // !this->getField().is( this->transCoordToIndex( x, y - this->delta, z ) , FLUID ); - //bool noValidNeighborInZ = !this->getField().is( this->transCoordToIndex( x, y, z + this->delta ) , FLUID ) && - // !this->getField().is( this->transCoordToIndex( x, y, z - this->delta ) , FLUID ); - - //if( noValidNeighborInX && noValidNeighborInY && noValidNeighborInZ ){ - // this->setFieldEntry(index, STOPPER_SOLID); - // return true; - //} - if( !this->hasNeighborOfType(index, FLUID) ){ this->setFieldEntry(index, STOPPER_SOLID); return true; @@ -1225,7 +1291,7 @@ HOSTDEVICE bool GridImp::closeCellIfNeedleThinWall(uint index) -CUDA_HOST void GridImp::findQs(Object* object) //TODO: enable qs for primitive objects +void GridImp::findQs(Object* object) //TODO: enable qs for primitive objects { TriangularMesh* triangularMesh = dynamic_cast<TriangularMesh*>(object); if (triangularMesh) @@ -1234,15 +1300,31 @@ CUDA_HOST void GridImp::findQs(Object* object) //TODO: enable qs for primitive o findQsPrimitive(object); } -CUDA_HOST void GridImp::findQs(TriangularMesh &triangularMesh) +void GridImp::allocateQs() { - const clock_t begin = clock(); + this->qPatches = new uint[this->getNumberOfSolidBoundaryNodes()]; - if( this->qComputationStage == qComputationStageType::ComputeQs ){ - gridStrategy->allocateQs(shared_from_this()); - } + for (uint i = 0; i < this->getNumberOfSolidBoundaryNodes(); i++) + this->qPatches[i] = INVALID_INDEX; + + const uint numberOfQs = this->getNumberOfSolidBoundaryNodes() * (this->distribution.dir_end + 1); + this->qValues = new real[numberOfQs]; +#pragma omp parallel for + for (int i = 0; i < (int)numberOfQs; i++) + this->qValues[i] = -1.0; +} - gridStrategy->findQs(shared_from_this(), triangularMesh); +void GridImp::findQs(TriangularMesh &triangularMesh) +{ + const clock_t begin = clock(); + + if( this->qComputationStage == qComputationStageType::ComputeQs ) + allocateQs(); + + +#pragma omp parallel for + for (int i = 0; i < triangularMesh.size; i++) + this->findQs(triangularMesh.triangles[i]); const clock_t end = clock(); const real time = (real)(real(end - begin) / CLOCKS_PER_SEC); @@ -1250,7 +1332,7 @@ CUDA_HOST void GridImp::findQs(TriangularMesh &triangularMesh) *logging::out << logging::Logger::INFO_INTERMEDIATE << "time finding qs: " << time << "s\n"; } -HOSTDEVICE void GridImp::findQs(Triangle &triangle) +void GridImp::findQs(Triangle &triangle) { auto box = this->getBoundingBoxOnNodes(triangle); triangle.initalLayerThickness(getDelta()); @@ -1293,12 +1375,11 @@ HOSTDEVICE void GridImp::findQs(Triangle &triangle) } } -CUDA_HOST void GridImp::findQsPrimitive(Object * object) +void GridImp::findQsPrimitive(Object * object) { - if( this->qComputationStage == qComputationStageType::ComputeQs ){ - gridStrategy->allocateQs(shared_from_this()); - } + if( this->qComputationStage == qComputationStageType::ComputeQs ) + allocateQs(); for( int index = 0; index < (int)this->size; index++ ) @@ -1333,7 +1414,7 @@ CUDA_HOST void GridImp::findQsPrimitive(Object * object) } } -HOSTDEVICE void GridImp::calculateQs(const uint index, const Vertex &point, Object* object) const +void GridImp::calculateQs(const uint index, const Vertex &point, Object* object) const { Vertex pointOnTriangle, direction; @@ -1371,7 +1452,7 @@ HOSTDEVICE void GridImp::calculateQs(const uint index, const Vertex &point, Obje } } -HOSTDEVICE bool GridImp::checkIfAtLeastOneValidQ(const uint index, const Vertex &point, Object* object) const +bool GridImp::checkIfAtLeastOneValidQ(const uint index, const Vertex &point, Object* object) const { Vertex pointOnTriangle, direction; @@ -1401,7 +1482,7 @@ HOSTDEVICE bool GridImp::checkIfAtLeastOneValidQ(const uint index, const Vertex return false; } -HOSTDEVICE void GridImp::setDebugPoint(uint index, int pointValue) +void GridImp::setDebugPoint(uint index, int pointValue) { if (field.isInvalidCoarseUnderFine(index) && pointValue == INVALID_SOLID) field.setFieldEntry(index, pointValue); @@ -1410,10 +1491,9 @@ HOSTDEVICE void GridImp::setDebugPoint(uint index, int pointValue) field.setFieldEntry(index, pointValue); } -HOSTDEVICE void GridImp::calculateQs(const Vertex &point, const Triangle &triangle) const // NOT USED !!!! +void GridImp::calculateQs(const Vertex &point, const Triangle &triangle) const // NOT USED !!!! { Vertex pointOnTriangle, direction; - //VertexInteger solid_node; real subdistance; int error; for (int i = distribution.dir_start; i <= distribution.dir_end; i++) @@ -1427,21 +1507,17 @@ HOSTDEVICE void GridImp::calculateQs(const Vertex &point, const Triangle &triang error = triangle.getTriangleIntersection(point, direction, pointOnTriangle, subdistance); - //real lengthDirection = sqrt(direction.x * direction.x + direction.y * direction.y + direction.z * direction.z); - subdistance /= /*lengthDirection **/ this->delta; + subdistance /= this->delta; if (error == 0 && subdistance < 1.0 && subdistance > 0.0) { - //solid_node = VertexInteger(actualPoint.x + direction.x, actualPoint.y + direction.y, actualPoint.z + direction.z); distribution.f[i*size + transCoordToIndex(point.x, point.y, point.z)] = subdistance; - //printf("Q%d %d: %2.8f \n", i, grid.transCoordToIndex(actualPoint), grid.d.f[index]); - } /*else - distribution.f[i*size + transCoordToIndex(point.x, point.y, point.z)] = -1.0;*/ + } } } -HOSTDEVICE void GridImp::calculateQs(const uint index, const Vertex &point, const Triangle &triangle) const +void GridImp::calculateQs(const uint index, const Vertex &point, const Triangle &triangle) const { Vertex pointOnTriangle, direction; real subdistance; @@ -1474,14 +1550,12 @@ HOSTDEVICE void GridImp::calculateQs(const uint index, const Vertex &point, cons this->qValues[i*this->numberOfSolidBoundaryNodes + this->qIndices[index]] = subdistance; this->qPatches[ this->qIndices[index] ] = triangle.patchIndex; - - //printf("%d %f \n", this->qIndices[index], subdistance); } } } } -HOSTDEVICE bool GridImp::checkIfAtLeastOneValidQ(const uint index, const Vertex & point, const Triangle & triangle) const +bool GridImp::checkIfAtLeastOneValidQ(const uint index, const Vertex & point, const Triangle & triangle) const { Vertex pointOnTriangle, direction; real subdistance; @@ -1523,7 +1597,6 @@ void GridImp::findCommunicationIndices(int direction, SPtr<BoundingBox> subDomai if( this->getFieldEntry(index) == INVALID_OUT_OF_GRID || this->getFieldEntry(index) == INVALID_SOLID || this->getFieldEntry(index) == INVALID_COARSE_UNDER_FINE || - //this->getFieldEntry(index) == STOPPER_SOLID || this->getFieldEntry(index) == STOPPER_OUT_OF_GRID || this->getFieldEntry(index) == STOPPER_COARSE_UNDER_FINE ) continue; @@ -1540,7 +1613,6 @@ void GridImp::findCommunicationIndices(int direction, SPtr<BoundingBox> subDomai } void GridImp::findCommunicationIndex( uint index, real coordinate, real limit, int direction ){ - // // negative direction get a negative sign real s = ( direction % 2 == 0 ) ? ( -1.0 ) : ( 1.0 ); @@ -1601,59 +1673,56 @@ void GridImp::repairCommunicationInices(int direction ) // --------------------------------------------------------- // // Getter // // --------------------------------------------------------- // -HOSTDEVICE int GridImp::getSparseIndex(uint matrixIndex) const +int GridImp::getSparseIndex(uint matrixIndex) const { return this->sparseIndices[matrixIndex]; } -CUDA_HOST real* GridImp::getDistribution() const +real* GridImp::getDistribution() const { return this->distribution.f; } -CUDA_HOST int* GridImp::getDirection() const +int* GridImp::getDirection() const { return this->distribution.dirs; } -CUDA_HOST int GridImp::getStartDirection() const +int GridImp::getStartDirection() const { return this->distribution.dir_start; } -CUDA_HOST int GridImp::getEndDirection() const +int GridImp::getEndDirection() const { return this->distribution.dir_end; } -HOSTDEVICE BoundingBox GridImp::getBoundingBoxOnNodes(Triangle &triangle) const +BoundingBox GridImp::getBoundingBoxOnNodes(Triangle &triangle) const { real minX, maxX, minY, maxY, minZ, maxZ; triangle.setMinMax(minX, maxX, minY, maxY, minZ, maxZ); - //const Vertex minOnNodes = getMinimumOnNode(Vertex(minX, minY, minZ)); - //const Vertex maxOnNodes = getMaximumOnNode(Vertex(maxX, maxY, maxZ)); - int minXIndex = lround(floor((minX - this->startX) / this->delta)) - 1; - int minYIndex = lround(floor((minY - this->startY) / this->delta)) - 1; - int minZIndex = lround(floor((minZ - this->startZ) / this->delta)) - 1; + int minXIndex = std::lround(floor((minX - this->startX) / this->delta)) - 1; + int minYIndex = std::lround(floor((minY - this->startY) / this->delta)) - 1; + int minZIndex = std::lround(floor((minZ - this->startZ) / this->delta)) - 1; - int maxXIndex = lround(ceil ((maxX - this->startX) / this->delta)) + 1; - int maxYIndex = lround(ceil ((maxY - this->startY) / this->delta)) + 1; - int maxZIndex = lround(ceil ((maxZ - this->startZ) / this->delta)) + 1; + int maxXIndex = std::lround(ceil((maxX - this->startX) / this->delta)) + 1; + int maxYIndex = std::lround(ceil((maxY - this->startY) / this->delta)) + 1; + int maxZIndex = std::lround(ceil((maxZ - this->startZ) / this->delta)) + 1; - minX = this->startX + minXIndex * this->delta; - minY = this->startY + minYIndex * this->delta; - minZ = this->startZ + minZIndex * this->delta; + minX = this->startX + minXIndex * this->delta; + minY = this->startY + minYIndex * this->delta; + minZ = this->startZ + minZIndex * this->delta; - maxX = this->startX + maxXIndex * this->delta; - maxY = this->startY + maxYIndex * this->delta; - maxZ = this->startZ + maxZIndex * this->delta; + maxX = this->startX + maxXIndex * this->delta; + maxY = this->startY + maxYIndex * this->delta; + maxZ = this->startZ + maxZIndex * this->delta; - //return BoundingBox(minOnNodes.x, maxOnNodes.x, minOnNodes.y, maxOnNodes.y, minOnNodes.z, maxOnNodes.z); - return BoundingBox( minX, maxX, minY, maxY, minZ, maxZ ); + return BoundingBox(minX, maxX, minY, maxY, minZ, maxZ); } -HOSTDEVICE Vertex GridImp::getMinimumOnNode(Vertex exact) const //deprecated +Vertex GridImp::getMinimumOnNode(Vertex exact) const // deprecated { const real minX = getMinimumOnNodes(exact.x, vf::Math::getDecimalPart(startX), delta); const real minY = getMinimumOnNodes(exact.y, vf::Math::getDecimalPart(startY), delta); @@ -1661,7 +1730,7 @@ HOSTDEVICE Vertex GridImp::getMinimumOnNode(Vertex exact) const //deprecated return Vertex(minX, minY, minZ); } -HOSTDEVICE real GridImp::getMinimumOnNodes(const real& minExact, const real& decimalStart, const real& delta) //deprecated +real GridImp::getMinimumOnNodes(const real &minExact, const real &decimalStart, const real &delta) // deprecated { real minNode = ceil(minExact - 1.0); minNode += decimalStart; @@ -1673,7 +1742,7 @@ HOSTDEVICE real GridImp::getMinimumOnNodes(const real& minExact, const real& dec return minNode; } -HOSTDEVICE Vertex GridImp::getMaximumOnNode(Vertex exact) const //deprecated +Vertex GridImp::getMaximumOnNode(Vertex exact) const // deprecated { const real maxX = getMaximumOnNodes(exact.x, vf::Math::getDecimalPart(startX), delta); const real maxY = getMaximumOnNodes(exact.y, vf::Math::getDecimalPart(startY), delta); @@ -1681,7 +1750,7 @@ HOSTDEVICE Vertex GridImp::getMaximumOnNode(Vertex exact) const //deprecated return Vertex(maxX, maxY, maxZ); } -HOSTDEVICE real GridImp::getMaximumOnNodes(const real& maxExact, const real& decimalStart, const real& delta) //deprecated +real GridImp::getMaximumOnNodes(const real &maxExact, const real &decimalStart, const real &delta) // deprecated { real maxNode = ceil(maxExact - 1.0); maxNode += decimalStart; @@ -1691,40 +1760,37 @@ HOSTDEVICE real GridImp::getMaximumOnNodes(const real& maxExact, const real& dec return maxNode; } -HOSTDEVICE uint GridImp::getXIndex(real x) const -{ - return lround((x - startX) / delta); - //return int((x - startX) / delta); +uint GridImp::getXIndex(real x) const +{ + return std::lround((x - startX) / delta); } -HOSTDEVICE uint GridImp::getYIndex(real y) const -{ - return lround((y - startY) / delta); - //return int((y - startY) / delta); +uint GridImp::getYIndex(real y) const +{ + return std::lround((y - startY) / delta); } -HOSTDEVICE uint GridImp::getZIndex(real z) const -{ - return lround((z - startZ) / delta); - //return int((z - startZ) / delta); +uint GridImp::getZIndex(real z) const +{ + return std::lround((z - startZ) / delta); } -HOSTDEVICE real GridImp::getDelta() const +real GridImp::getDelta() const { return delta; } -HOSTDEVICE uint GridImp::getSize() const +uint GridImp::getSize() const { return this->size; } -HOSTDEVICE uint GridImp::getSparseSize() const +uint GridImp::getSparseSize() const { return this->sparseSize; } -HOSTDEVICE Field GridImp::getField() const +Field GridImp::getField() const { return this->field; } @@ -1734,7 +1800,7 @@ char GridImp::getFieldEntry(uint index) const return this->field.getFieldEntry(index); } -HOSTDEVICE void GridImp::setFieldEntry(uint matrixIndex, char type) +void GridImp::setFieldEntry(uint matrixIndex, char type) { this->field.setFieldEntry(matrixIndex, type); } @@ -1785,11 +1851,6 @@ uint GridImp::getNumberOfNodesZ() const return nz; } -SPtr<GridStrategy> GridImp::getGridStrategy() const -{ - return gridStrategy; -} - int* GridImp::getNeighborsX() const { @@ -1811,7 +1872,6 @@ int* GridImp::getNeighborsNegative() const return this->neighborIndexNegative; } - uint GridImp::getNumberOfNodesCF() const { if(this->gridInterface) @@ -1836,7 +1896,7 @@ uint* GridImp::getCF_fine() const return this->gridInterface->cf.fine; } -CUDA_HOST uint * GridImp::getCF_offset() const +uint * GridImp::getCF_offset() const { return this->gridInterface->cf.offset; } @@ -1851,7 +1911,7 @@ uint* GridImp::getFC_fine() const return this->gridInterface->fc.fine; } -CUDA_HOST uint * GridImp::getFC_offset() const +uint * GridImp::getFC_offset() const { return this->gridInterface->fc.offset; } @@ -1873,7 +1933,7 @@ void GridImp::getGridInterface(uint* gridInterfaceList, const uint* oldGridInter #define GEOFLUID 19 #define GEOSOLID 16 -CUDA_HOST void GridImp::getNodeValues(real *xCoords, real *yCoords, real *zCoords, uint *neighborX, uint *neighborY, uint *neighborZ, uint *neighborNegative, uint *geo) const +void GridImp::getNodeValues(real *xCoords, real *yCoords, real *zCoords, uint *neighborX, uint *neighborY, uint *neighborZ, uint *neighborNegative, uint *geo) const { xCoords[0] = 0; yCoords[0] = 0; @@ -1898,8 +1958,6 @@ CUDA_HOST void GridImp::getNodeValues(real *xCoords, real *yCoords, real *zCoord const uint neighborZIndex = uint(this->neighborIndexZ[i] + 1); const uint neighborNegativeIndex = uint(this->neighborIndexNegative[i] + 1); - const char type2 = this->field.getFieldEntry(i); - const uint type = uint(this->field.isFluid(i) ? GEOFLUID : GEOSOLID); xCoords[nodeNumber + 1] = x; @@ -1922,4 +1980,4 @@ void GridImp::print() const endX, endY, endZ, size, delta); if(this->gridInterface) this->gridInterface->print(); -} +} \ No newline at end of file diff --git a/src/gpu/GridGenerator/grid/GridImp.h b/src/gpu/GridGenerator/grid/GridImp.h index 314020d0e6a271d0761d6935f8e55c5c7ea6bade..7d44b0bb58168a6bf4da87ad94cf5a8f533002ed 100644 --- a/src/gpu/GridGenerator/grid/GridImp.h +++ b/src/gpu/GridGenerator/grid/GridImp.h @@ -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 GridImp.h +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz, Martin Schönherr +//======================================================================================= #ifndef GRID_IMP_H #define GRID_IMP_H @@ -15,55 +47,53 @@ class TriangularMesh; struct Vertex; struct Triangle; -class GridStrategy; class GridInterface; class Object; class BoundingBox; class TriangularMeshDiscretizationStrategy; #ifdef __GNUC__ - #ifndef __clang__ - #pragma push - #pragma diag_suppress = 3156 - #endif +#ifndef __clang__ +#pragma push +#pragma diag_suppress = 3156 +#endif #endif -//GCC: warning #3156-D: extern declaration of the entity DIRECTIONS is treated as a static definition -extern CONSTANT int DIRECTIONS[DIR_END_MAX][DIMENSION]; +// GCC: warning #3156-D: extern declaration of the entity DIRECTIONS is treated as a static definition +extern int DIRECTIONS[DIR_END_MAX][DIMENSION]; #ifdef __GNUC__ - #ifndef __clang__ - #pragma pop - #endif +#ifndef __clang__ +#pragma pop +#endif #endif class GRIDGENERATOR_EXPORT GridImp : public enableSharedFromThis<GridImp>, public Grid { private: - CUDA_HOST GridImp(); - CUDA_HOST GridImp(Object* object, real startX, real startY, real startZ, real endX, real endY, real endZ, real delta, SPtr<GridStrategy> gridStrategy, Distribution d, uint level); + GridImp() = default; + GridImp(Object* object, real startX, real startY, real startZ, real endX, real endY, real endZ, real delta, Distribution d, uint level); public: - virtual HOSTDEVICE ~GridImp(); - static CUDA_HOST SPtr<GridImp> makeShared(Object* object, real startX, real startY, real startZ, real endX, real endY, real endZ, real delta, SPtr<GridStrategy> gridStrategy, Distribution d, uint level); + static SPtr<GridImp> makeShared(Object* object, real startX, real startY, real startZ, real endX, real endY, real endZ, real delta, std::string d3Qxx, uint level); private: - CUDA_HOST void initalNumberOfNodesAndSize(); - HOSTDEVICE Cell getOddCellFromIndex(uint index) const; - HOSTDEVICE bool isValidSolidStopper(uint index) const; - HOSTDEVICE bool shouldBeBoundarySolidNode(uint index) const; - HOSTDEVICE bool isValidEndOfGridStopper(uint index) const; - HOSTDEVICE bool isValidEndOfGridBoundaryStopper(uint index) const; - HOSTDEVICE bool isOutSideOfGrid(Cell &cell) const; - HOSTDEVICE bool contains(Cell &cell, char type) const; - HOSTDEVICE void setNodeTo(Cell &cell, char type); - - HOSTDEVICE bool nodeInPreviousCellIs(int index, char type) const; - HOSTDEVICE bool nodeInCellIs(Cell& cell, char type) const override; - - HOSTDEVICE uint getXIndex(real x) const; - HOSTDEVICE uint getYIndex(real y) const; - HOSTDEVICE uint getZIndex(real z) const; + void initalNumberOfNodesAndSize(); + Cell getOddCellFromIndex(uint index) const; + bool isValidSolidStopper(uint index) const; + bool shouldBeBoundarySolidNode(uint index) const; + bool isValidEndOfGridStopper(uint index) const; + bool isValidEndOfGridBoundaryStopper(uint index) const; + bool isOutSideOfGrid(Cell &cell) const; + bool contains(Cell &cell, char type) const; + void setNodeTo(Cell &cell, char type); + + bool nodeInPreviousCellIs(int index, char type) const; + bool nodeInCellIs(Cell& cell, char type) const override; + + uint getXIndex(real x) const; + uint getYIndex(real y) const; + uint getZIndex(real z) const; uint level; @@ -81,7 +111,7 @@ private: Field field; Object* object; - GridInterface* gridInterface; + GridInterface *gridInterface; int *neighborIndexX, *neighborIndexY, *neighborIndexZ, *neighborIndexNegative; int *sparseIndices; @@ -94,19 +124,18 @@ private: uint numberOfLayers; - SPtr<GridStrategy> gridStrategy; - TriangularMeshDiscretizationStrategy* triangularMeshDiscretizationStrategy; + TriangularMeshDiscretizationStrategy *triangularMeshDiscretizationStrategy; - uint numberOfSolidBoundaryNodes; + uint numberOfSolidBoundaryNodes; bool enableFixRefinementIntoTheWall; public: - CUDA_HOST void inital(const SPtr<Grid> fineGrid, uint numberOfLayers) override; - CUDA_HOST void setOddStart( bool xOddStart, bool yOddStart, bool zOddStart ) override; - HOSTDEVICE void fixOddCell(uint index); + void inital(const SPtr<Grid> fineGrid, uint numberOfLayers) override; + void setOddStart(bool xOddStart, bool yOddStart, bool zOddStart) override; + void fixOddCell(uint index); - CUDA_HOST void setPeriodicity(bool periodicityX, bool periodicityY, bool periodicityZ) override; + void setPeriodicity(bool periodicityX, bool periodicityY, bool periodicityZ) override; void setPeriodicityX(bool periodicity) override; void setPeriodicityY(bool periodicity) override; void setPeriodicityZ(bool periodicity) override; @@ -115,192 +144,190 @@ public: bool getPeriodicityY() override; bool getPeriodicityZ() override; - void setEnableFixRefinementIntoTheWall( bool enableFixRefinementIntoTheWall ) override; + void setEnableFixRefinementIntoTheWall(bool enableFixRefinementIntoTheWall) override; - HOSTDEVICE void setCellTo(uint index, char type); - HOSTDEVICE void setNonStopperOutOfGridCellTo(uint index, char type); + void setCellTo(uint index, char type); + void setNonStopperOutOfGridCellTo(uint index, char type); - HOSTDEVICE uint transCoordToIndex(const real &x, const real &y, const real &z) const override; - HOSTDEVICE void transIndexToCoords(uint index, real &x, real &y, real &z) const override; + uint transCoordToIndex(const real &x, const real &y, const real &z) const override; + void transIndexToCoords(uint index, real &x, real &y, real &z) const override; - CUDA_HOST virtual void findGridInterface(SPtr<Grid> grid, LbmOrGks lbmOrGks) override; + virtual void findGridInterface(SPtr<Grid> grid, LbmOrGks lbmOrGks) override; - HOSTDEVICE void repairGridInterfaceOnMultiGPU(SPtr<Grid> fineGrid) override; + void repairGridInterfaceOnMultiGPU(SPtr<Grid> fineGrid) override; - CUDA_HOST virtual void limitToSubDomain(SPtr<BoundingBox> subDomainBox, LbmOrGks lbmOrGks) override; + virtual void limitToSubDomain(SPtr<BoundingBox> subDomainBox, LbmOrGks lbmOrGks) override; - CUDA_HOST void freeMemory() override; + void freeMemory() override; - CUDA_HOST uint getLevel(real levelNull) const; - CUDA_HOST uint getLevel() const; - CUDA_HOST void setTriangularMeshDiscretizationStrategy(TriangularMeshDiscretizationStrategy* triangularMeshDiscretizationStrategy); - CUDA_HOST TriangularMeshDiscretizationStrategy* getTriangularMeshDiscretizationStrategy(); + uint getLevel(real levelNull) const; + uint getLevel() const; - CUDA_HOST uint getNumberOfSolidBoundaryNodes() const override; - CUDA_HOST void setNumberOfSolidBoundaryNodes(uint numberOfSolidBoundaryNodes) override; + void setTriangularMeshDiscretizationStrategy(TriangularMeshDiscretizationStrategy *triangularMeshDiscretizationStrategy); + TriangularMeshDiscretizationStrategy *getTriangularMeshDiscretizationStrategy(); - CUDA_HOST real getQValue(const uint index, const uint dir) const override; - CUDA_HOST uint getQPatch(const uint index) const override; + uint getNumberOfSolidBoundaryNodes() const override; + void setNumberOfSolidBoundaryNodes(uint numberOfSolidBoundaryNodes) override; - CUDA_HOST void setInnerRegionFromFinerGrid( bool innerRegionFromFinerGrid ) override; + real getQValue(const uint index, const uint dir) const override; + uint getQPatch(const uint index) const override; - CUDA_HOST void setNumberOfLayers( uint numberOfLayers ) override; + void setInnerRegionFromFinerGrid(bool innerRegionFromFinerGrid) override; + + void setNumberOfLayers(uint numberOfLayers) override; public: Distribution distribution; - HOSTDEVICE void initalNodeToOutOfGrid(uint index); + void initalNodeToOutOfGrid(uint index); - HOSTDEVICE void findInnerNode(uint index); + void findInnerNodes(); + void findInnerNode(uint index); - HOSTDEVICE void discretize(Object* object, char innerType, char outerType); + void discretize(Object *object, char innerType, char outerType); - bool isInside(const Cell& cell) const; + bool isInside(const Cell &cell) const; - HOSTDEVICE void setInnerBasedOnFinerGrid(const SPtr<Grid> fineGrid); - - HOSTDEVICE void addOverlap(); - HOSTDEVICE void setOverlapTmp( uint index ); - HOSTDEVICE void setOverlapFluid( uint index ); - - HOSTDEVICE void fixRefinementIntoWall(uint xIndex, uint yIndex, uint zIndex, int dir); - HOSTDEVICE void findStopperNode(uint index); - HOSTDEVICE void findEndOfGridStopperNode(uint index); - HOSTDEVICE void findSolidStopperNode(uint index); - HOSTDEVICE void findBoundarySolidNode(uint index); - - HOSTDEVICE void findGridInterfaceCF(uint index, GridImp& finerGrid, LbmOrGks lbmOrGks); - HOSTDEVICE void findGridInterfaceFC(uint index, GridImp& finerGrid); - HOSTDEVICE void findOverlapStopper(uint index, GridImp& finerGrid); - HOSTDEVICE void findInvalidBoundaryNodes(uint index); - - HOSTDEVICE void setNodeTo(uint index, char type); - HOSTDEVICE bool isNode(uint index, char type) const; - HOSTDEVICE bool nodeInNextCellIs(int index, char type) const; - HOSTDEVICE bool hasAllNeighbors(uint index) const; - HOSTDEVICE bool hasNeighborOfType(uint index, char type)const; - HOSTDEVICE bool cellContainsOnly(Cell &cell, char type) const; - HOSTDEVICE bool cellContainsOnly(Cell &cell, char typeA, char typeB) const; - - HOSTDEVICE const Object* getObject() const override; - - HOSTDEVICE Field getField() const; - HOSTDEVICE char getFieldEntry(uint index) const override; - HOSTDEVICE void setFieldEntry(uint matrixIndex, char type) override; - - - HOSTDEVICE real getDelta() const override; - HOSTDEVICE uint getSize() const override; - HOSTDEVICE uint getSparseSize() const override; - HOSTDEVICE int getSparseIndex(uint matrixIndex) const override; - CUDA_HOST real* getDistribution() const override; - CUDA_HOST int* getDirection() const override; - CUDA_HOST int getStartDirection() const override; - CUDA_HOST int getEndDirection() const override; - - HOSTDEVICE Vertex getMinimumOnNode(Vertex exact) const override; - HOSTDEVICE Vertex getMaximumOnNode(Vertex exact) const override; - - HOSTDEVICE real getStartX() const override; - HOSTDEVICE real getStartY() const override; - HOSTDEVICE real getStartZ() const override; - HOSTDEVICE real getEndX() const override; - HOSTDEVICE real getEndY() const override; - HOSTDEVICE real getEndZ() const override; - HOSTDEVICE uint getNumberOfNodesX() const override; - HOSTDEVICE uint getNumberOfNodesY() const override; - HOSTDEVICE uint getNumberOfNodesZ() const override; - CUDA_HOST void getNodeValues(real *xCoords, real *yCoords, real *zCoords, uint *neighborX, uint *neighborY, uint *neighborZ, uint *neighborNegative, uint *geo) const override; - - HOSTDEVICE uint getNumberOfNodesCF() const override; - HOSTDEVICE uint getNumberOfNodesFC() const override; - CUDA_HOST void getGridInterfaceIndices(uint* iCellCfc, uint* iCellCff, uint* iCellFcc, uint* iCellFcf) const override; - CUDA_HOST static void getGridInterface(uint* gridInterfaceList, const uint* oldGridInterfaceList, uint size); - - int* getNeighborsX() const override; - int* getNeighborsY() const override; - int* getNeighborsZ() const override; - int* getNeighborsNegative() const override; + void setInnerBasedOnFinerGrid(const SPtr<Grid> fineGrid); - CUDA_HOST uint* getCF_coarse() const override; - CUDA_HOST uint* getCF_fine() const override; - CUDA_HOST uint* getCF_offset() const override; + void addOverlap(); + void setOverlapTmp(uint index); + void setOverlapFluid(uint index); + void fixRefinementIntoWall(uint xIndex, uint yIndex, uint zIndex, int dir); + void findStopperNode(uint index); + void findEndOfGridStopperNode(uint index); + void findSolidStopperNode(uint index); + void findBoundarySolidNode(uint index); - CUDA_HOST uint* getFC_coarse() const override; - CUDA_HOST uint* getFC_fine() const override; - CUDA_HOST uint* getFC_offset() const override; + void findGridInterfaceCF(uint index, GridImp &finerGrid, LbmOrGks lbmOrGks); + void findGridInterfaceFC(uint index, GridImp &finerGrid); + void findOverlapStopper(uint index, GridImp &finerGrid); + void findInvalidBoundaryNodes(uint index); - SPtr<GridStrategy> getGridStrategy() const override; + void setNodeTo(uint index, char type); + bool isNode(uint index, char type) const; + bool nodeInNextCellIs(int index, char type) const; + bool hasAllNeighbors(uint index) const; + bool hasNeighborOfType(uint index, char type)const; + bool cellContainsOnly(Cell &cell, char type) const; + bool cellContainsOnly(Cell &cell, char typeA, char typeB) const; + const Object* getObject() const override; - HOSTDEVICE void print() const; + Field getField() const; + char getFieldEntry(uint index) const override; + void setFieldEntry(uint matrixIndex, char type) override; + real getDelta() const override; + uint getSize() const override; + uint getSparseSize() const override; + int getSparseIndex(uint matrixIndex) const override; + real* getDistribution() const override; + int* getDirection() const override; + int getStartDirection() const override; + int getEndDirection() const override; + + Vertex getMinimumOnNode(Vertex exact) const override; + Vertex getMaximumOnNode(Vertex exact) const override; + + real getStartX() const override; + real getStartY() const override; + real getStartZ() const override; + real getEndX() const override; + real getEndY() const override; + real getEndZ() const override; + uint getNumberOfNodesX() const override; + uint getNumberOfNodesY() const override; + uint getNumberOfNodesZ() const override; + void getNodeValues(real *xCoords, real *yCoords, real *zCoords, uint *neighborX, uint *neighborY, uint *neighborZ, uint *neighborNegative, uint *geo) const override; + + uint getNumberOfNodesCF() const override; + uint getNumberOfNodesFC() const override; + void getGridInterfaceIndices(uint *iCellCfc, uint *iCellCff, uint *iCellFcc, uint *iCellFcf) const override; + static void getGridInterface(uint *gridInterfaceList, const uint *oldGridInterfaceList, uint size); + + int *getNeighborsX() const override; + int* getNeighborsY() const override; + int* getNeighborsZ() const override; + int* getNeighborsNegative() const override; + + uint *getCF_coarse() const override; + uint *getCF_fine() const override; + uint *getCF_offset() const override; + + uint *getFC_coarse() const override; + uint *getFC_fine() const override; + uint *getFC_offset() const override; + + void print() const; + public: - CUDA_HOST virtual void findSparseIndices(SPtr<Grid> fineGrid) override; + virtual void findSparseIndices(SPtr<Grid> fineGrid) override; - CUDA_HOST void updateSparseIndices(); - HOSTDEVICE void setNeighborIndices(uint index); - HOSTDEVICE real getFirstFluidNode(real coords[3], int direction, real startCoord) const override; - HOSTDEVICE real getLastFluidNode(real coords[3], int direction, real startCoord) const override; + void updateSparseIndices(); + void setNeighborIndices(uint index); + real getFirstFluidNode(real coords[3], int direction, real startCoord) const override; + real getLastFluidNode(real coords[3], int direction, real startCoord) const override; private: - HOSTDEVICE void setStopperNeighborCoords(uint index); - HOSTDEVICE void getNeighborCoords(real &neighborX, real &neighborY, real &neighborZ, real x, real y, real z) const; - HOSTDEVICE real getNeighborCoord(bool periodicity, real endCoord, real coords[3], int direction) const; - HOSTDEVICE void getNegativeNeighborCoords(real &neighborX, real &neighborY, real &neighborZ, real x, real y, real z) const; - HOSTDEVICE real getNegativeNeighborCoord(bool periodicity, real endCoord, real coords[3], int direction) const; + void setStopperNeighborCoords(uint index); + void getNeighborCoords(real &neighborX, real &neighborY, real &neighborZ, real x, real y, real z) const; + real getNeighborCoord(bool periodicity, real endCoord, real coords[3], int direction) const; + void getNegativeNeighborCoords(real &neighborX, real &neighborY, real &neighborZ, real x, real y, real z) const; + real getNegativeNeighborCoord(bool periodicity, real endCoord, real coords[3], int direction) const; - HOSTDEVICE int getSparseIndex(const real &expectedX, const real &expectedY, const real &expectedZ) const; + int getSparseIndex(const real &expectedX, const real &expectedY, const real &expectedZ) const; - HOSTDEVICE static real getMinimumOnNodes(const real& minExact, const real& decimalStart, const real& delta); - HOSTDEVICE static real getMaximumOnNodes(const real& maxExact, const real& decimalStart, const real& delta); + static real getMinimumOnNodes(const real &minExact, const real &decimalStart, const real &delta); + static real getMaximumOnNodes(const real &maxExact, const real &decimalStart, const real &delta); public: - HOSTDEVICE BoundingBox getBoundingBoxOnNodes(Triangle &triangle) const; + BoundingBox getBoundingBoxOnNodes(Triangle &triangle) const; - CUDA_HOST void mesh(Object* object) override; + void mesh(Object *object) override; - CUDA_HOST void mesh(TriangularMesh &geometry) override; - HOSTDEVICE void mesh(Triangle &triangle); + void mesh(TriangularMesh &geometry) override; + void mesh(Triangle &triangle); - CUDA_HOST void closeNeedleCells() override; - HOSTDEVICE bool closeCellIfNeedle(uint index); + void closeNeedleCells() override; + bool closeCellIfNeedle(uint index); - CUDA_HOST void closeNeedleCellsThinWall() override; - HOSTDEVICE bool closeCellIfNeedleThinWall(uint index); + void closeNeedleCellsThinWall() override; + bool closeCellIfNeedleThinWall(uint index); - CUDA_HOST void findQs(Object* object) override; - CUDA_HOST void findQs(TriangularMesh &triangularMesh); - HOSTDEVICE void findQs(Triangle &triangle); + void findQs(Object *object) override; + void findQs(TriangularMesh &triangularMesh); + void findQs(Triangle &triangle); - CUDA_HOST void findQsPrimitive(Object* object); -private: + void findQsPrimitive(Object *object); - enum class qComputationStageType{ - FindSolidBoundaryNodes, - ComputeQs - } qComputationStage; +private: + enum class qComputationStageType { FindSolidBoundaryNodes, ComputeQs } qComputationStage; public: - CUDA_HOST void enableFindSolidBoundaryNodes() override{ qComputationStage = qComputationStageType::FindSolidBoundaryNodes; } - CUDA_HOST void enableComputeQs() override{ qComputationStage = qComputationStageType::ComputeQs; } + void enableFindSolidBoundaryNodes() override + { + qComputationStage = qComputationStageType::FindSolidBoundaryNodes; + } + void enableComputeQs() override { qComputationStage = qComputationStageType::ComputeQs; } private: - HOSTDEVICE void setDebugPoint(uint index, int pointValue); - HOSTDEVICE void calculateQs(const Vertex &point, const Triangle &triangle) const; - HOSTDEVICE void calculateQs(const uint index, const Vertex &point, const Triangle &triangle) const; - CUDA_HOST void calculateQs(const uint index, const Vertex &point, Object* object) const; + void setDebugPoint(uint index, int pointValue); + void calculateQs(const Vertex &point, const Triangle &triangle) const; + void calculateQs(const uint index, const Vertex &point, const Triangle &triangle) const; + void calculateQs(const uint index, const Vertex &point, Object *object) const; - CUDA_HOST bool checkIfAtLeastOneValidQ(const uint index, const Vertex &point, const Triangle &triangle) const; + bool checkIfAtLeastOneValidQ(const uint index, const Vertex &point, const Triangle &triangle) const; - CUDA_HOST bool checkIfAtLeastOneValidQ(const uint index, const Vertex &point, Object* object) const; + bool checkIfAtLeastOneValidQ(const uint index, const Vertex &point, Object *object) const; -public: + void allocateQs(); +public: void findCommunicationIndices(int direction, SPtr<BoundingBox> subDomainBox, LbmOrGks lbmOrGks) override; - void findCommunicationIndex( uint index, real coordinate, real limit, int direction ); + void findCommunicationIndex(uint index, real coordinate, real limit, int direction); uint getNumberOfSendNodes(int direction) override; uint getNumberOfReceiveNodes(int direction) override; @@ -311,19 +338,13 @@ public: void repairCommunicationInices(int direction) override; public: - - struct CommunicationIndices - { + struct CommunicationIndices { std::vector<uint> sendIndices; std::vector<uint> receiveIndices; }; std::array<CommunicationIndices, 6> communicationIndices; - -private: - friend class GridGpuStrategy; - friend class GridCpuStrategy; }; #endif diff --git a/src/gpu/GridGenerator/grid/GridInterface.cu b/src/gpu/GridGenerator/grid/GridInterface.cpp similarity index 83% rename from src/gpu/GridGenerator/grid/GridInterface.cu rename to src/gpu/GridGenerator/grid/GridInterface.cpp index 423f9788fe44e73c37c1c09c726596923737e871..47cb8ef9dd7c4704e420ca68888ce0d56c48a59e 100644 --- a/src/gpu/GridGenerator/grid/GridInterface.cu +++ b/src/gpu/GridGenerator/grid/GridInterface.cpp @@ -1,6 +1,39 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// 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 GridInterface.cpp +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "GridInterface.h" #include <iostream> +#include <cstring> #include "grid/distributions/D3Q27.h" #include "grid/GridImp.h" @@ -132,7 +165,7 @@ void GridInterface::findInterfaceFC(const uint& indexOnCoarseGrid, GridImp* coar for (const auto dir : coarseGrid->distribution) { - const int neighborIndex = coarseGrid->transCoordToIndex(x + dir[0] * coarseGrid->getDelta(), y + dir[1] * coarseGrid->getDelta(), z + dir[2] * coarseGrid->getDelta()); + const uint neighborIndex = coarseGrid->transCoordToIndex(x + dir[0] * coarseGrid->getDelta(), y + dir[1] * coarseGrid->getDelta(), z + dir[2] * coarseGrid->getDelta()); if (neighborIndex != INVALID_INDEX) { const bool neighborBelongsToCoarseToFineInterpolationCell = coarseGrid->getField().isCoarseToFineNode(neighborIndex); @@ -163,7 +196,7 @@ void GridInterface::findOverlapStopper(const uint& indexOnCoarseGrid, GridImp* c if (indexOnFineGridFC == -1) return; - real x, y, z; + real x, y, z; coarseGrid->transIndexToCoords(indexOnCoarseGrid, x, y, z); bool neighborBelongsToFineToCoarseInterpolationCell = false; @@ -172,7 +205,7 @@ void GridInterface::findOverlapStopper(const uint& indexOnCoarseGrid, GridImp* c //if (dir[0] > 0 || dir[1] > 0 || dir[2] > 0) //only Esoteric Twist stopper, not perfectly implemented // continue; //should not be here, should be made conditional - const int neighborIndex = coarseGrid->transCoordToIndex(x + dir[0] * coarseGrid->getDelta(), y + dir[1] * coarseGrid->getDelta(), z + dir[2] * coarseGrid->getDelta()); + const uint neighborIndex = coarseGrid->transCoordToIndex(x + dir[0] * coarseGrid->getDelta(), y + dir[1] * coarseGrid->getDelta(), z + dir[2] * coarseGrid->getDelta()); neighborBelongsToFineToCoarseInterpolationCell = neighborIndex != INVALID_INDEX ? coarseGrid->getField().isFineToCoarseNode(neighborIndex) : false; if (neighborBelongsToFineToCoarseInterpolationCell) { @@ -256,7 +289,7 @@ void GridInterface::findForGridInterfaceSparseIndexFC(GridImp* coarseGrid, GridI findSparseIndex(fc.fine, fineGrid, index); } -CUDA_HOST void GRIDGENERATOR_EXPORT GridInterface::repairGridInterfaceOnMultiGPU(SPtr<GridImp> coarseGrid, SPtr<GridImp> fineGrid) +void GRIDGENERATOR_EXPORT GridInterface::repairGridInterfaceOnMultiGPU(SPtr<GridImp> coarseGrid, SPtr<GridImp> fineGrid) { { std::vector<uint> tmpCFC; @@ -332,7 +365,7 @@ void GridInterface::findSparseIndex(uint* indices, GridImp* grid, uint index) indices[index] = sparseIndex; } -HOSTDEVICE uint GridInterface::findOffsetCF(const uint& indexOnCoarseGrid, GridImp* coarseGrid, uint interfaceIndex) +uint GridInterface::findOffsetCF(const uint& indexOnCoarseGrid, GridImp* coarseGrid, uint interfaceIndex) { real x, y, z; coarseGrid->transIndexToCoords(indexOnCoarseGrid, x, y, z); @@ -367,7 +400,7 @@ HOSTDEVICE uint GridInterface::findOffsetCF(const uint& indexOnCoarseGrid, GridI return indexOnCoarseGrid; } -HOSTDEVICE uint GridInterface::findOffsetFC(const uint& indexOnFineGrid, GridImp* fineGrid, uint interfaceIndex) +uint GridInterface::findOffsetFC(const uint& indexOnFineGrid, GridImp* fineGrid, uint interfaceIndex) { real x, y, z; fineGrid->transIndexToCoords(indexOnFineGrid, x, y, z); diff --git a/src/gpu/GridGenerator/grid/GridInterface.h b/src/gpu/GridGenerator/grid/GridInterface.h index d0f04ea3451b3044c349aa0e27d2f7c6e567128c..303d79d4995ea04fe30b2a004c5738bf9c926cf2 100644 --- a/src/gpu/GridGenerator/grid/GridInterface.h +++ b/src/gpu/GridGenerator/grid/GridInterface.h @@ -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 GridInterface.h +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef GRID_INTERFACE_H #define GRID_INTERFACE_H @@ -8,26 +40,26 @@ class GridImp; class GridInterface { public: - HOSTDEVICE GRIDGENERATOR_EXPORT GridInterface(); - HOSTDEVICE GRIDGENERATOR_EXPORT ~GridInterface(); + GRIDGENERATOR_EXPORT GridInterface(); + GRIDGENERATOR_EXPORT ~GridInterface(); - HOSTDEVICE void GRIDGENERATOR_EXPORT findInterfaceCF(const uint& indexOnCoarseGrid, GridImp* coarseGrid, GridImp* fineGrid); - HOSTDEVICE void GRIDGENERATOR_EXPORT findBoundaryGridInterfaceCF(const uint& indexOnCoarseGrid, GridImp* coarseGrid, GridImp* fineGrid); + void GRIDGENERATOR_EXPORT findInterfaceCF(const uint& indexOnCoarseGrid, GridImp* coarseGrid, GridImp* fineGrid); + void GRIDGENERATOR_EXPORT findBoundaryGridInterfaceCF(const uint& indexOnCoarseGrid, GridImp* coarseGrid, GridImp* fineGrid); - HOSTDEVICE void GRIDGENERATOR_EXPORT findInterfaceCF_GKS(const uint& indexOnCoarseGrid, GridImp* coarseGrid, GridImp* fineGrid); + void GRIDGENERATOR_EXPORT findInterfaceCF_GKS(const uint& indexOnCoarseGrid, GridImp* coarseGrid, GridImp* fineGrid); - HOSTDEVICE void GRIDGENERATOR_EXPORT findInterfaceFC(const uint& indexOnCoarseGrid, GridImp* coarseGrid, GridImp* fineGrid); - HOSTDEVICE void GRIDGENERATOR_EXPORT findOverlapStopper(const uint& indexOnCoarseGrid, GridImp* coarseGrid, GridImp* fineGrid); + void GRIDGENERATOR_EXPORT findInterfaceFC(const uint& indexOnCoarseGrid, GridImp* coarseGrid, GridImp* fineGrid); + void GRIDGENERATOR_EXPORT findOverlapStopper(const uint& indexOnCoarseGrid, GridImp* coarseGrid, GridImp* fineGrid); - HOSTDEVICE void GRIDGENERATOR_EXPORT findInvalidBoundaryNodes(const uint& indexOnCoarseGrid, GridImp* coarseGrid); + void GRIDGENERATOR_EXPORT findInvalidBoundaryNodes(const uint& indexOnCoarseGrid, GridImp* coarseGrid); - HOSTDEVICE void GRIDGENERATOR_EXPORT findForGridInterfaceSparseIndexCF(GridImp* coarseGrid, GridImp* fineGrid, uint index); - HOSTDEVICE void GRIDGENERATOR_EXPORT findForGridInterfaceSparseIndexFC(GridImp* coarseGrid, GridImp* fineGrid, uint index); + void GRIDGENERATOR_EXPORT findForGridInterfaceSparseIndexCF(GridImp* coarseGrid, GridImp* fineGrid, uint index); + void GRIDGENERATOR_EXPORT findForGridInterfaceSparseIndexFC(GridImp* coarseGrid, GridImp* fineGrid, uint index); - CUDA_HOST void GRIDGENERATOR_EXPORT repairGridInterfaceOnMultiGPU(SPtr<GridImp> coarseGrid, SPtr<GridImp> fineGrid); + void GRIDGENERATOR_EXPORT repairGridInterfaceOnMultiGPU(SPtr<GridImp> coarseGrid, SPtr<GridImp> fineGrid); - HOSTDEVICE void GRIDGENERATOR_EXPORT print() const; + void GRIDGENERATOR_EXPORT print() const; struct Interface { @@ -38,16 +70,16 @@ public: private: - HOSTDEVICE uint getCoarseToFineIndexOnFineGrid(const uint& indexOnCoarseGrid, const GridImp* coarseGrid, const GridImp* fineGrid); - HOSTDEVICE bool isNeighborFineInvalid(real x, real y, real z, const GridImp* coarseGrid, const GridImp* fineGrid); + uint getCoarseToFineIndexOnFineGrid(const uint& indexOnCoarseGrid, const GridImp* coarseGrid, const GridImp* fineGrid); + bool isNeighborFineInvalid(real x, real y, real z, const GridImp* coarseGrid, const GridImp* fineGrid); - HOSTDEVICE uint getFineToCoarseIndexOnFineGrid(const uint& indexOnCoarseGrid, const GridImp* coarseGrid, const GridImp* fineGrid); + uint getFineToCoarseIndexOnFineGrid(const uint& indexOnCoarseGrid, const GridImp* coarseGrid, const GridImp* fineGrid); - HOSTDEVICE static void findSparseIndex(uint* indices, GridImp* grid, uint index); + static void findSparseIndex(uint* indices, GridImp* grid, uint index); - HOSTDEVICE uint findOffsetCF( const uint& indexOnCoarseGrid, GridImp* coarseGrid, uint interfaceIndex ); + uint findOffsetCF( const uint& indexOnCoarseGrid, GridImp* coarseGrid, uint interfaceIndex ); - HOSTDEVICE uint findOffsetFC( const uint& indexOnCoarseGrid, GridImp* coarseGrid, uint interfaceIndex ); + uint findOffsetFC( const uint& indexOnCoarseGrid, GridImp* coarseGrid, uint interfaceIndex ); }; diff --git a/src/gpu/GridGenerator/grid/GridStrategy/GridCpuStrategy/GridCpuStrategy.cpp b/src/gpu/GridGenerator/grid/GridStrategy/GridCpuStrategy/GridCpuStrategy.cpp deleted file mode 100644 index 3d5cda94a16f5948cd6fe60ab4aa8acf8ca7fadd..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/grid/GridStrategy/GridCpuStrategy/GridCpuStrategy.cpp +++ /dev/null @@ -1,291 +0,0 @@ -#include "GridCpuStrategy.h" - -#include <time.h> -#include <stdio.h> -#include <omp.h> -#include <vector> -#include <iostream> - -#include "geometries/TriangularMesh/TriangularMesh.h" - -#include "grid/distributions/Distribution.h" -#include "grid/GridInterface.h" -#include "grid/GridImp.h" -#include "grid/NodeValues.h" - -using namespace vf::gpu; - -void GridCpuStrategy::allocateGridMemory(SPtr<GridImp> grid) -{ - grid->neighborIndexX = new int[grid->size]; - grid->neighborIndexY = new int[grid->size]; - grid->neighborIndexZ = new int[grid->size]; - grid->neighborIndexNegative = new int[grid->size]; - - grid->sparseIndices = new int[grid->size]; - - grid->qIndices = new uint[grid->size]; - for (size_t i = 0; i < grid->size; i++) - grid->qIndices[i] = INVALID_INDEX; - - // unsigned long distributionSize = grid->size * (grid->distribution.dir_end + 1); - // real sizeInMB = distributionSize * sizeof(real) / (1024.f*1024.f); - - // //*logging::out << logging::Logger::LOW << "Allocating " << sizeInMB << " [MB] host memory for distributions.\n"; - - // grid->distribution.f = new real[distributionSize](); // automatic initialized with zeros - //for (uint index = 0; index < distributionSize; index++) grid->distribution.f[index] = -1.0; -} - -void GridCpuStrategy::allocateQs(SPtr<GridImp> grid) -{ - grid->qPatches = new uint[grid->getNumberOfSolidBoundaryNodes()]; - //grid->qPatches.resize( grid->getNumberOfSolidBoundaryNodes() ); - - for( uint i = 0; i < grid->getNumberOfSolidBoundaryNodes(); i++ ) - grid->qPatches[i] = INVALID_INDEX; - - const uint numberOfQs = grid->getNumberOfSolidBoundaryNodes() * (grid->distribution.dir_end + 1); - grid->qValues = new real[numberOfQs]; -#pragma omp parallel for - for (int i = 0; i < (int)numberOfQs; i++) - grid->qValues[i] = -1.0; -} - -void GridCpuStrategy::initalNodesToOutOfGrid(SPtr<GridImp> grid) -{ -#pragma omp parallel for - for (int index = 0; index < (int)grid->size; index++) - grid->initalNodeToOutOfGrid(index); -} - -void GridCpuStrategy::allocateFieldMemory(Field* field) -{ - field->field = new char[field->size]; -} - - -void GridCpuStrategy::findInnerNodes(SPtr<GridImp> grid) -{ -#pragma omp parallel for - for (int index = 0; index < (int)grid->size; index++) - grid->findInnerNode(index); -} - -void GridCpuStrategy::addOverlap(SPtr<GridImp> grid) -{ - -#pragma omp parallel for - for( int index = 0; index < (int)grid->size; index++ ) - grid->setOverlapTmp( index ); - -#pragma omp parallel for - for( int index = 0; index < (int)grid->size; index++ ) - grid->setOverlapFluid( index ); -} - - -void GridCpuStrategy::fixOddCells(SPtr<GridImp> grid) -{ -#pragma omp parallel for - for (int index = 0; index < (int)grid->size; index++) - grid->fixOddCell(index); -} - -void GridCpuStrategy::fixRefinementIntoWall(SPtr<GridImp> grid) -{ -#pragma omp parallel for - for (int xIdx = 0; xIdx < (int)grid->nx; xIdx++){ - for (uint yIdx = 0; yIdx < grid->ny; yIdx++){ - grid->fixRefinementIntoWall( xIdx, yIdx, 0 , 3 ); - grid->fixRefinementIntoWall( xIdx, yIdx, grid->nz-1, -3 ); - } - } - -#pragma omp parallel for - for (int xIdx = 0; xIdx < (int)grid->nx; xIdx++){ - for (uint zIdx = 0; zIdx < grid->nz; zIdx++){ - grid->fixRefinementIntoWall( xIdx, 0, zIdx, 2 ); - grid->fixRefinementIntoWall( xIdx, grid->ny-1, zIdx, -2 ); - } - } - -#pragma omp parallel for - for (int yIdx = 0; yIdx < (int)grid->ny; yIdx++){ - for (uint zIdx = 0; zIdx < grid->nz; zIdx++){ - grid->fixRefinementIntoWall( 0, yIdx, zIdx, 1 ); - grid->fixRefinementIntoWall( grid->nx-1, yIdx, zIdx, -1 ); - } - } -} - - -void GridCpuStrategy::findStopperNodes(SPtr<GridImp> grid) -{ -#pragma omp parallel for - for (int index = 0; index < (int)grid->size; index++) - grid->findStopperNode(index); -} - -void GridCpuStrategy::findEndOfGridStopperNodes(SPtr<GridImp> grid) -{ -#pragma omp parallel for - for (int index = 0; index < (int)grid->size; index++) - grid->findEndOfGridStopperNode(index); -} - -void GridCpuStrategy::findSolidStopperNodes(SPtr<GridImp> grid) -{ -#pragma omp parallel for - for (int index = 0; index < (int)grid->size; index++) - grid->findSolidStopperNode(index); -} - -void GridCpuStrategy::findBoundarySolidNodes(SPtr<GridImp> grid) -{ -//#pragma omp parallel for - for (int index = 0; index < (int)grid->size; index++) - { - grid->findBoundarySolidNode(index); - } -} - -void GridCpuStrategy::mesh(SPtr<GridImp> grid, TriangularMesh &geom) -{ -#pragma omp parallel for - for (int i = 0; i < geom.size; i++) - grid->mesh(geom.triangles[i]); -} - -uint GridCpuStrategy::closeNeedleCells(SPtr<GridImp> grid) -{ - uint numberOfClosedNeedleCells = 0; - -#pragma omp parallel for reduction(+:numberOfClosedNeedleCells) - for (int index = 0; index < (int)grid->size; index++) - { - if( grid->closeCellIfNeedle(index) ) - numberOfClosedNeedleCells++; - } - - return numberOfClosedNeedleCells; -} - -uint GridCpuStrategy::closeNeedleCellsThinWall(SPtr<GridImp> grid) -{ - uint numberOfClosedNeedleCells = 0; - -#pragma omp parallel for reduction(+:numberOfClosedNeedleCells) - for (int index = 0; index < (int)grid->size; index++) - { - if( grid->closeCellIfNeedleThinWall(index) ) - numberOfClosedNeedleCells++; - } - - return numberOfClosedNeedleCells; -} - -void GridCpuStrategy::findQs(SPtr<GridImp> grid, TriangularMesh &geom) -{ -#pragma omp parallel for - for (int i = 0; i < geom.size; i++) - grid->findQs(geom.triangles[i]); -} - - -void GridCpuStrategy::findGridInterface(SPtr<GridImp> grid, SPtr<GridImp> fineGrid, LbmOrGks lbmOrGks) -{ - const auto coarseLevel = grid->getLevel(); - const auto fineLevel = fineGrid->getLevel(); - - *logging::out << logging::Logger::INFO_INTERMEDIATE << "find interface level " << coarseLevel << " -> " << fineLevel; - - grid->gridInterface = new GridInterface(); - // TODO: this is stupid! concave refinements can easily have many more interface cells - const uint sizeCF = 10*(fineGrid->nx * fineGrid->ny + fineGrid->ny * fineGrid->nz + fineGrid->nx * fineGrid->nz); - grid->gridInterface->cf.coarse = new uint[sizeCF]; - grid->gridInterface->cf.fine = new uint[sizeCF]; - grid->gridInterface->cf.offset = new uint[sizeCF]; - grid->gridInterface->fc.coarse = new uint[sizeCF]; - grid->gridInterface->fc.fine = new uint[sizeCF]; - grid->gridInterface->fc.offset = new uint[sizeCF]; - - for (uint index = 0; index < grid->getSize(); index++) - grid->findGridInterfaceCF(index, *fineGrid, lbmOrGks); - - for (uint index = 0; index < grid->getSize(); index++) - grid->findGridInterfaceFC(index, *fineGrid); - - for (uint index = 0; index < grid->getSize(); index++) - grid->findOverlapStopper(index, *fineGrid); - - if( lbmOrGks == GKS ) - { - for (uint index = 0; index < grid->getSize(); index++) - grid->findInvalidBoundaryNodes(index); - } - - *logging::out << logging::Logger::INFO_INTERMEDIATE << " ... done. \n"; -} - -void GridCpuStrategy::findSparseIndices(SPtr<GridImp> coarseGrid, SPtr<GridImp> fineGrid) -{ - *logging::out << logging::Logger::INFO_INTERMEDIATE << "Find sparse indices..."; - - coarseGrid->updateSparseIndices(); - findForNeighborsNewIndices(coarseGrid); - if (fineGrid) - { - fineGrid->updateSparseIndices(); - findForGridInterfaceNewIndices(coarseGrid, fineGrid); - } - - const uint newGridSize = coarseGrid->getSparseSize(); - *logging::out << logging::Logger::INFO_INTERMEDIATE << "... done. new size: " << newGridSize << ", delete nodes:" << coarseGrid->getSize() - newGridSize << "\n"; -} - - -void GridCpuStrategy::findForNeighborsNewIndices(SPtr<GridImp> grid) -{ -#pragma omp parallel for - for (int index = 0; index < (int)grid->getSize(); index++) - grid->setNeighborIndices(index); -} - -void GridCpuStrategy::findForGridInterfaceNewIndices(SPtr<GridImp> grid, SPtr<GridImp> fineGrid) -{ -#pragma omp parallel for - for (int index = 0; index < (int)grid->getNumberOfNodesCF(); index++) - grid->gridInterface->findForGridInterfaceSparseIndexCF(grid.get(), fineGrid.get(), index); - -#pragma omp parallel for - for (int index = 0; index < (int)grid->getNumberOfNodesFC(); index++) - grid->gridInterface->findForGridInterfaceSparseIndexFC(grid.get(), fineGrid.get(), index); -} - - - -void GridCpuStrategy::freeFieldMemory(Field* field) -{ - delete[] field->field; -} - - - -void GridCpuStrategy::freeMemory(SPtr<GridImp> grid) -{ - //if(grid->gridInterface) - //delete grid->gridInterface; - - if( grid->neighborIndexX != nullptr ) { delete[] grid->neighborIndexX; grid->neighborIndexX = nullptr; } - if( grid->neighborIndexY != nullptr ) { delete[] grid->neighborIndexY; grid->neighborIndexY = nullptr; } - if( grid->neighborIndexZ != nullptr ) { delete[] grid->neighborIndexZ; grid->neighborIndexZ = nullptr; } - if( grid->neighborIndexNegative != nullptr ) { delete[] grid->neighborIndexNegative; grid->neighborIndexNegative = nullptr; } - if( grid->sparseIndices != nullptr ) { delete[] grid->sparseIndices; grid->sparseIndices = nullptr; } - if( grid->qIndices != nullptr ) { delete[] grid->qIndices; grid->qIndices = nullptr; } - if( grid->qValues != nullptr ) { delete[] grid->qValues; grid->qValues = nullptr; } - if( grid->qPatches != nullptr ) { delete[] grid->qPatches; grid->qPatches = nullptr; } - - //delete[] grid->distribution.f; -} - diff --git a/src/gpu/GridGenerator/grid/GridStrategy/GridCpuStrategy/GridCpuStrategy.h b/src/gpu/GridGenerator/grid/GridStrategy/GridCpuStrategy/GridCpuStrategy.h deleted file mode 100644 index af4b1791b0970f1f26483b46953ebc2512dd23bc..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/grid/GridStrategy/GridCpuStrategy/GridCpuStrategy.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef GRID_CPU_STRATEGY_H -#define GRID_CPU_STRATEGY_H - -#include "global.h" - -#include "grid/GridStrategy/GridStrategy.h" - -class GridImp; -class TriangularMesh; - -class GRIDGENERATOR_EXPORT GridCpuStrategy : public GridStrategy -{ -public: - virtual ~GridCpuStrategy() {}; - - void allocateGridMemory(SPtr<GridImp> grid) override; - - void allocateQs(SPtr<GridImp> grid) override; - - void initalNodesToOutOfGrid(SPtr<GridImp> grid) override; - void fixOddCells(SPtr<GridImp> grid) override; - void findInnerNodes(SPtr<GridImp> grid) override; - void addOverlap(SPtr<GridImp> grid) override; - void fixRefinementIntoWall(SPtr<GridImp> grid) override; - void findStopperNodes(SPtr<GridImp> grid) override; - void findBoundarySolidNodes(SPtr<GridImp> grid) override; - void findEndOfGridStopperNodes(SPtr<GridImp> grid) override; - void findSolidStopperNodes(SPtr<GridImp> grid) override; - - void mesh(SPtr<GridImp> grid, TriangularMesh &geom) override; - - uint closeNeedleCells(SPtr<GridImp> grid) override; - uint closeNeedleCellsThinWall(SPtr<GridImp> grid) override; - - void findQs(SPtr<GridImp> grid, TriangularMesh &geom) override; - - void findGridInterface(SPtr<GridImp> grid, SPtr<GridImp> fineGrid, LbmOrGks lbmOrGks) override; - - void freeMemory(SPtr<GridImp> grid) override; - - - - virtual void copyDataFromGPU() {}; - -protected: - static void findForNeighborsNewIndices(SPtr<GridImp> grid); - static void findForGridInterfaceNewIndices(SPtr<GridImp> grid, SPtr<GridImp> fineGrid); -public: - void allocateFieldMemory(Field* field) override; - void freeFieldMemory(Field* field) override; - void findSparseIndices(SPtr<GridImp> coarseGrid, SPtr<GridImp> fineGrid) override; - -}; - -#endif \ No newline at end of file diff --git a/src/gpu/GridGenerator/grid/GridStrategy/GridGpuStrategy/GridGpuStrategy.cpp b/src/gpu/GridGenerator/grid/GridStrategy/GridGpuStrategy/GridGpuStrategy.cpp deleted file mode 100644 index a19daf22aba77480763c7c91f6bf29bb6ebacdd3..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/grid/GridStrategy/GridGpuStrategy/GridGpuStrategy.cpp +++ /dev/null @@ -1,430 +0,0 @@ -#include "GridGpuStrategy.h" - -#include "Core/Timer/Timer.h" - -#include "geometries/BoundingBox/BoundingBox.h" -#include "geometries/TriangularMesh/TriangularMesh.h" - -#include "grid/kernel/runGridKernelGPU.cuh" -#include "grid/distributions/Distribution.h" -#include "grid/GridImp.h" -#include "grid/GridInterface.h" - -#include "utilities/cuda/CudaErrorCheck.cu" -#include "utilities/cuda/LaunchParameter.cuh" - -void GridGpuStrategy::allocateGridMemory(SPtr<GridImp> grid) -{ - //printCudaInformation(0); - cudaSetDevice(0); - - this->allocDistribution(grid); - this->allocField(grid); - this->allocMatrixIndicesOnGPU(grid); - this->allocNeighborsIndices(grid); -} - -void GridGpuStrategy::allocateQs(SPtr<GridImp> grid) -{ -} - -void GridGpuStrategy::initalNodesToOutOfGrid(SPtr<GridImp> grid) -{ - -} - -void GridGpuStrategy::fixOddCells(SPtr<GridImp> grid) -{ -} - - - -void GridGpuStrategy::findInnerNodes(SPtr<GridImp> grid) -{ - //float time = runKernelInitalUniformGrid3d(LaunchParameter::make_2D1D_launchParameter(grid->size, 256), *grid.get()); -} - -void GridGpuStrategy::addOverlap(SPtr<GridImp> grid) -{ -} - -void GridGpuStrategy::fixRefinementIntoWall(SPtr<GridImp> grid) -{ -} - -void GridGpuStrategy::findStopperNodes(SPtr<GridImp> grid) -{ - -} - -void GridGpuStrategy::findBoundarySolidNodes(SPtr<GridImp> grid) -{ -} - -void GridGpuStrategy::findEndOfGridStopperNodes(SPtr<GridImp> grid) -{ - -} - -void GridGpuStrategy::findSolidStopperNodes(SPtr<GridImp> grid) -{ - -} - -void GridGpuStrategy::mesh(SPtr<GridImp> grid, TriangularMesh &geom) -{ - *logging::out << logging::Logger::INFO_INTERMEDIATE << "start meshing on GPU...\n"; - allocAndCopyTrianglesToGPU(geom); - - /*---------------------------------------------------------------------------------*/ - float time = runKernelToMesh(LaunchParameter::make_1D1D_launchParameter(geom.size, 256), *grid.get(), geom); - /*---------------------------------------------------------------------------------*/ - *logging::out << logging::Logger::INFO_INTERMEDIATE << "Time GPU build grid: " << time / 1000 << "sec\n"; - *logging::out << logging::Logger::INFO_INTERMEDIATE << "-------------------------------------------\n"; - - freeTrianglesFromGPU(geom); - -} - -uint GridGpuStrategy::closeNeedleCells(SPtr<GridImp> grid) -{ - return uint(); -} - -uint GridGpuStrategy::closeNeedleCellsThinWall(SPtr<GridImp> grid) -{ - return uint(); -} - - -void GridGpuStrategy::findQs(SPtr<GridImp> grid, TriangularMesh &geom) -{ - -} - - -void GridGpuStrategy::findGridInterface(SPtr<GridImp> grid, SPtr<GridImp> fineGrid, LbmOrGks lbmOrGks) -{ - //copyAndFreeFieldFromGPU(grid->getField()); - //copyAndFreeFieldFromGPU(fineGrid->getField()); - //copyAndFreeMatrixIndicesFromGPU(grid, grid->size); - //copyAndFreeMatrixIndicesFromGPU(fineGrid, fineGrid->getSize()); - - //grid->gridInterface = new GridInterface(); - //const uint sizeCF = fineGrid->nx * fineGrid->ny + fineGrid->ny * fineGrid->nz + fineGrid->nx * fineGrid->nz; - //grid->gridInterface->cf.coarse = new uint[sizeCF]; - //grid->gridInterface->cf.fine = new uint[sizeCF]; - //grid->gridInterface->fc.coarse = new uint[sizeCF]; - //grid->gridInterface->fc.fine = new uint[sizeCF]; - - ////for (uint index = 0; index < grid->getSize(); index++) - //// grid->findGridInterface(index, *fineGrid.get()); - - //uint *cfc; - //uint *cff; - //uint *fcc; - //uint *fcf; - - //CudaSafeCall(cudaMalloc(&cfc, sizeCF * sizeof(uint))); - //CudaSafeCall(cudaMalloc(&cff, sizeCF * sizeof(uint))); - //CudaSafeCall(cudaMalloc(&fcc, sizeCF * sizeof(uint))); - //CudaSafeCall(cudaMalloc(&fcf, sizeCF * sizeof(uint))); - - //CudaSafeCall(cudaMemcpy(cfc, grid->gridInterface->cf.coarse, grid->gridInterface->cf.numberOfEntries * sizeof(uint), cudaMemcpyHostToDevice)); - //CudaSafeCall(cudaMemcpy(cff, grid->gridInterface->cf.fine, grid->gridInterface->cf.numberOfEntries * sizeof(uint), cudaMemcpyHostToDevice)); - //CudaSafeCall(cudaMemcpy(fcc, grid->gridInterface->fc.coarse, grid->gridInterface->fc.numberOfEntries * sizeof(uint), cudaMemcpyHostToDevice)); - //CudaSafeCall(cudaMemcpy(fcf, grid->gridInterface->fc.fine, grid->gridInterface->fc.numberOfEntries * sizeof(uint), cudaMemcpyHostToDevice)); - - //grid->gridInterface->cf.coarse = cfc; - //grid->gridInterface->cf.fine = cff; - //grid->gridInterface->fc.coarse = fcc; - //grid->gridInterface->fc.fine = fcf; - - //GridInterface *gridInterface_d; - //CudaSafeCall(cudaMalloc(&gridInterface_d, sizeof(GridInterface))); - //CudaSafeCall(cudaMemcpy(gridInterface_d, grid->gridInterface, sizeof(GridInterface), cudaMemcpyHostToDevice)); - //grid->gridInterface = gridInterface_d; - //CudaCheckError(); - - - //grid->updateSparseIndices(); - - //allocAndCopyFieldToGPU(grid->getField()); - //allocAndCopyFieldToGPU(fineGrid->getField()); - //allocAndCopyMatrixIndicesToGPU(grid, grid->size); - //allocAndCopyMatrixIndicesToGPU(fineGrid, fineGrid->size); - - //float time = runKernelToFindNeighborsNewIndices(LaunchParameter::make_2D1D_launchParameter(grid->size, 256), *grid.get()); - //float time2 = runKernelToFindGridInterfaceNewIndices(LaunchParameter::make_2D1D_launchParameter(grid->size, 256), *grid.get()); - - //copyAndFreeGridInterfaceFromGPU(grid); - - - ////*logging::out << logging::Logger::INTERMEDIATE << "time find indices: " << time / 1000 << "sec\n"; -} - -//void GridGpuStrategy::deleteSolidNodes(SPtr<GridImp> grid) -//{ -// float time1 = runKernelSetToInvalid(LaunchParameter::make_2D1D_launchParameter(grid->size, 512), *grid.get()); -// -// copyAndFreeFieldFromGPU(grid->getField()); -// copyAndFreeMatrixIndicesFromGPU(grid, grid->size); -// -// grid->updateSparseIndices(); -// -// allocAndCopyFieldToGPU(grid->getField()); -// allocAndCopyMatrixIndicesToGPU(grid, grid->size); -// -// float time2 = runKernelFindIndices(LaunchParameter::make_2D1D_launchParameter(grid->size, 256), *grid.get()); -// *logging::out << logging::Logger::INFO_INTERMEDIATE << "time delete solid nodes: " << (time1 + time2) / 1000 << "sec\n"; -//} - - - -void GridGpuStrategy::freeMemory(SPtr<GridImp> grid) -{ - //delete[] grid->gridInterface->cf.coarse; - //delete[] grid->gridInterface->cf.fine; - - //delete[] grid->gridInterface->fc.coarse; - //delete[] grid->gridInterface->fc.fine; - - //delete grid->gridInterface; - - delete[] grid->neighborIndexX; - delete[] grid->neighborIndexY; - delete[] grid->neighborIndexZ; - delete[] grid->neighborIndexNegative; - delete[] grid->sparseIndices; - - delete[] grid->distribution.f; -} - - - -void GridGpuStrategy::copyDataFromGPU(SPtr<GridImp> grid) -{ - //copyAndFreeFieldFromGPU(grid->getField()); - //copyAndFreeNeighborsToCPU(grid); - //copyAndFreeMatrixIndicesFromGPU(grid, grid->size); - //copyAndFreeDistributiondFromGPU(grid); -} - -void GridGpuStrategy::allocField(SPtr<GridImp> grid) -{ - //int size_in_bytes = grid->size * sizeof(char); - //CudaSafeCall(cudaMalloc(grid->getField().field, size_in_bytes)); -} - - -void GridGpuStrategy::allocateFieldMemory(Field* field) -{ - long size = field->size * sizeof(char) / 1000 / 1000; - *logging::out << logging::Logger::INFO_INTERMEDIATE << "alloc on device for grid field: " << int(size) << " MB\n"; - - char *field_d; - CudaSafeCall(cudaMalloc(&field_d, field->size * sizeof(char))); - field->field = field_d; -} - -void GridGpuStrategy::freeFieldMemory(Field* field) -{ -} - -void GridGpuStrategy::findSparseIndices(SPtr<GridImp> coarseGrid, SPtr<GridImp> fineGrid) -{ -} - -// -//void GridWrapperGPU::markNodesToDeleteOutsideOfGeometry() -//{ -// int numberOfEdgeNodes = grid.ny * grid.nz; -// -// /*---------------------------------------------------------------------------------*/ -// float time = runKernelToMarkNodesToDeleteOutsideOfGeometry(LaunchParameter::make_1D1D_launchParameter(numberOfEdgeNodes, 256), grid); -// /*---------------------------------------------------------------------------------*/ -// -// *logging::out << logging::Logger::INTERMEDIATE << "mark nodes to delete: " << time / 1000 << "sec\n"; -// *logging::out << logging::Logger::INTERMEDIATE << "-------------------------------------------\n"; -//} - -/*#################################################################################*/ -/*--------------------------------private methods----------------------------------*/ -/*---------------------------------------------------------------------------------*/ - -void GridGpuStrategy::allocDistribution(SPtr<GridImp> grid) -{ - CudaSafeCall(cudaMemcpyToSymbol(DIRECTIONS, grid->distribution.dirs, grid->distribution.dir_end * DIMENSION * sizeof(int))); - CudaCheckError(); - - unsigned long long distributionSize = grid->size * (grid->distribution.dir_end + 1); - unsigned long long size_in_bytes = distributionSize * sizeof(real); - real sizeInMB = size_in_bytes / (1024.f*1024.f); - *logging::out << logging::Logger::INFO_INTERMEDIATE << "Allocating " << sizeInMB << " [MB] device memory for distributions.\n\n"; - - CudaSafeCall(cudaMalloc(&grid->distribution.f, size_in_bytes)); - CudaCheckError(); -} - -void GridGpuStrategy::allocNeighborsIndices(SPtr<GridImp> grid) -{ - int size_in_bytes_neighbors = grid->size * sizeof(int); - int *neighborIndexX, *neighborIndexY, *neighborIndexZ, *neighborIndexNegative;; - - CudaSafeCall(cudaMalloc(&neighborIndexX, size_in_bytes_neighbors)); - CudaSafeCall(cudaMalloc(&neighborIndexY, size_in_bytes_neighbors)); - CudaSafeCall(cudaMalloc(&neighborIndexZ, size_in_bytes_neighbors)); - CudaSafeCall(cudaMalloc(&neighborIndexNegative, size_in_bytes_neighbors)); - - grid->neighborIndexX = neighborIndexX; - grid->neighborIndexY = neighborIndexY; - grid->neighborIndexZ = neighborIndexZ; - grid->neighborIndexNegative = neighborIndexNegative; - - CudaCheckError(); -} - -void GridGpuStrategy::allocMatrixIndicesOnGPU(SPtr<GridImp> grid) -{ - int size_in_bytes_nodes_reduced = grid->size * sizeof(int); - int* indices_reduced_d; - CudaSafeCall(cudaMalloc(&indices_reduced_d, size_in_bytes_nodes_reduced)); - grid->sparseIndices = indices_reduced_d; - CudaCheckError(); -} - - -void GridGpuStrategy::allocAndCopyTrianglesToGPU(TriangularMesh &geom) -{ - *logging::out << logging::Logger::INFO_INTERMEDIATE << "start copying triangles ...\n"; - //clock_t begin = clock(); - int size_in_bytes_triangles = sizeof(Triangle)*geom.size; - real sizeInMB = size_in_bytes_triangles / (1024.f*1024.f); - - *logging::out << logging::Logger::INFO_INTERMEDIATE << "Allocating " << sizeInMB << " [MB] device memory for triangles.\n\n"; - - Triangle *triangles_d; - CudaSafeCall(cudaMalloc(&triangles_d, size_in_bytes_triangles)); - CudaSafeCall(cudaMemcpy(triangles_d, geom.triangles, size_in_bytes_triangles, cudaMemcpyHostToDevice)); - geom.triangles = triangles_d; - CudaCheckError(); - //clock_t end = clock(); - //real time = real(end - begin) / CLOCKS_PER_SEC; - //*logging::out << logging::Logger::INFO_INTERMEDIATE << "time copying triangles: " << time << "s\n"; - *logging::out << logging::Logger::INFO_INTERMEDIATE << "...copying triangles finish!\n\n"; -} - -void GridGpuStrategy::freeTrianglesFromGPU(const TriangularMesh &geom) -{ - CudaSafeCall(cudaFree(geom.triangles)); - CudaCheckError(); -} - -void GridGpuStrategy::allocAndCopyMatrixIndicesToGPU(SPtr<GridImp> grid, const uint& size) -{ - int size_in_bytes_nodes_reduced = size * sizeof(int); - int* indices_reduced_d; - CudaSafeCall(cudaMalloc(&indices_reduced_d, size_in_bytes_nodes_reduced)); - CudaSafeCall(cudaMemcpy(indices_reduced_d, grid->sparseIndices, size_in_bytes_nodes_reduced, cudaMemcpyHostToDevice)); - delete[] grid->sparseIndices; - grid->sparseIndices = indices_reduced_d; - CudaCheckError(); -} - -void GridGpuStrategy::allocAndCopyFieldToGPU(Field& field) -{ - int size_in_bytes_grid = field.getSize() * sizeof(char); - char* field_d; - CudaSafeCall(cudaMalloc(&field_d, size_in_bytes_grid)); - CudaSafeCall(cudaMemcpy(field_d, field.field, size_in_bytes_grid, cudaMemcpyHostToDevice)); - delete[] field.field; - field.field = field_d; - CudaCheckError(); -} - -void GridGpuStrategy::copyAndFreeFieldFromGPU(Field& field) -{ - char *field_h = new char[field.size]; - CudaSafeCall(cudaMemcpy(field_h, field.field, field.size * sizeof(char), cudaMemcpyDeviceToHost)); - CudaSafeCall(cudaFree(field.field)); - CudaCheckError(); - field.field = field_h; -} - -void GridGpuStrategy::copyAndFreeDistributiondFromGPU(SPtr<GridImp> grid) -{ - unsigned long long distributionSize = grid->size * (grid->distribution.dir_end + 1); - real *f_host = new real[distributionSize]; - CudaSafeCall(cudaMemcpy(f_host, grid->distribution.f, distributionSize * sizeof(real), cudaMemcpyDeviceToHost)); - CudaSafeCall(cudaFree(grid->distribution.f)); - CudaCheckError(); - grid->distribution.f = f_host; -} - - - -void GridGpuStrategy::copyAndFreeNeighborsToCPU(SPtr<GridImp> grid) -{ - int size_in_bytes_neighbors = grid->size * sizeof(int); - int *neighborIndexX_h, *neighborIndexY_h, *neighborIndexZ_h, *neighborIndexNegative_h; - neighborIndexX_h = new int[grid->size]; - neighborIndexY_h = new int[grid->size]; - neighborIndexZ_h = new int[grid->size]; - neighborIndexNegative_h = new int[grid->size]; - - CudaSafeCall(cudaMemcpy(neighborIndexX_h, grid->neighborIndexX, size_in_bytes_neighbors, cudaMemcpyDeviceToHost)); - CudaSafeCall(cudaMemcpy(neighborIndexY_h, grid->neighborIndexY, size_in_bytes_neighbors, cudaMemcpyDeviceToHost)); - CudaSafeCall(cudaMemcpy(neighborIndexZ_h, grid->neighborIndexZ, size_in_bytes_neighbors, cudaMemcpyDeviceToHost)); - CudaSafeCall(cudaMemcpy(neighborIndexNegative_h, grid->neighborIndexNegative, size_in_bytes_neighbors, cudaMemcpyDeviceToHost)); - - CudaSafeCall(cudaFree(grid->neighborIndexX)); - CudaSafeCall(cudaFree(grid->neighborIndexY)); - CudaSafeCall(cudaFree(grid->neighborIndexZ)); - CudaSafeCall(cudaFree(grid->neighborIndexNegative)); - - grid->neighborIndexX = neighborIndexX_h; - grid->neighborIndexY = neighborIndexY_h; - grid->neighborIndexZ = neighborIndexZ_h; - grid->neighborIndexNegative = neighborIndexNegative_h; - CudaCheckError(); -} - -void GridGpuStrategy::copyAndFreeMatrixIndicesFromGPU(SPtr<GridImp> grid, int size) -{ - int size_in_bytes_nodes_reduced = size * sizeof(int); - int *indices_reduced_h = new int[size]; - CudaSafeCall(cudaMemcpy(indices_reduced_h, grid->sparseIndices, size_in_bytes_nodes_reduced, cudaMemcpyDeviceToHost)); - CudaSafeCall(cudaFree(grid->sparseIndices)); - grid->sparseIndices = indices_reduced_h; - CudaCheckError(); -} - - -void GridGpuStrategy::copyAndFreeGridInterfaceFromGPU(SPtr<GridImp> grid) -{ - GridInterface *gridInterface = new GridInterface(); - CudaSafeCall(cudaMemcpy(gridInterface, grid->gridInterface, sizeof(GridInterface), cudaMemcpyDeviceToHost)); - - uint *cfc = new uint[gridInterface->cf.numberOfEntries]; - uint *cff = new uint[gridInterface->cf.numberOfEntries]; - uint *fcc = new uint[gridInterface->fc.numberOfEntries]; - uint *fcf = new uint[gridInterface->fc.numberOfEntries]; - - - CudaSafeCall(cudaMemcpy(cfc, gridInterface->cf.coarse, gridInterface->cf.numberOfEntries * sizeof(uint), cudaMemcpyDeviceToHost)); - CudaSafeCall(cudaMemcpy(cff, gridInterface->cf.fine, gridInterface->cf.numberOfEntries * sizeof(uint), cudaMemcpyDeviceToHost)); - CudaSafeCall(cudaMemcpy(fcc, gridInterface->fc.coarse, gridInterface->fc.numberOfEntries * sizeof(uint), cudaMemcpyDeviceToHost)); - CudaSafeCall(cudaMemcpy(fcf, gridInterface->fc.fine, gridInterface->fc.numberOfEntries * sizeof(uint), cudaMemcpyDeviceToHost)); - CudaSafeCall(cudaFree(gridInterface->cf.coarse)); - CudaSafeCall(cudaFree(gridInterface->cf.fine)); - CudaSafeCall(cudaFree(gridInterface->fc.coarse)); - CudaSafeCall(cudaFree(gridInterface->fc.fine)); - CudaSafeCall(cudaFree(grid->gridInterface)); - - grid->gridInterface = gridInterface; - grid->gridInterface->cf.coarse = cfc; - grid->gridInterface->cf.fine = cff; - grid->gridInterface->fc.coarse = fcc; - grid->gridInterface->fc.fine = fcf; - CudaCheckError(); -} diff --git a/src/gpu/GridGenerator/grid/GridStrategy/GridGpuStrategy/GridGpuStrategy.h b/src/gpu/GridGenerator/grid/GridStrategy/GridGpuStrategy/GridGpuStrategy.h deleted file mode 100644 index fb886824ad35e6657f49c23a3fc25e19aabf0783..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/grid/GridStrategy/GridGpuStrategy/GridGpuStrategy.h +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef GRID_GPU_STRATEGY_H -#define GRID_GPU_STRATEGY_H - -#include "global.h" - -#include "grid/GridStrategy/GridStrategy.h" - -class BoundingBox; -class TriangularMesh; - -class GRIDGENERATOR_EXPORT GridGpuStrategy : public GridStrategy -{ -public: - virtual ~GridGpuStrategy() {}; - - void allocateGridMemory(SPtr<GridImp> grid) override; - - void allocateQs(SPtr<GridImp> grid) override; - - void initalNodesToOutOfGrid(SPtr<GridImp> grid) override; - void fixOddCells(SPtr<GridImp> grid) override; - void findInnerNodes(SPtr<GridImp> grid) override; - void addOverlap(SPtr<GridImp> grid) override; - void fixRefinementIntoWall(SPtr<GridImp> grid) override; - void findStopperNodes(SPtr<GridImp> grid) override; - void findBoundarySolidNodes(SPtr<GridImp> grid) override; - void findEndOfGridStopperNodes(SPtr<GridImp> grid) override; - void findSolidStopperNodes(SPtr<GridImp> grid) override; - - void mesh(SPtr<GridImp> grid, TriangularMesh &geom) override; - - uint closeNeedleCells(SPtr<GridImp> grid) override; - uint closeNeedleCellsThinWall(SPtr<GridImp> grid) override; - - void findQs(SPtr<GridImp> grid, TriangularMesh &geom) override; - - - void findGridInterface(SPtr<GridImp> grid, SPtr<GridImp> fineGrid, LbmOrGks lbmOrGks) override; - - void freeMemory(SPtr<GridImp> grid) override; - - - - void copyAndFreeGridInterfaceFromGPU(SPtr<GridImp> grid); - virtual void copyDataFromGPU(SPtr<GridImp> grid); - - //void markNodesToDeleteOutsideOfGeometry(); - -private: - void allocField(SPtr<GridImp> grid); - void allocDistribution(SPtr<GridImp> grid); - void allocNeighborsIndices(SPtr<GridImp> grid); - void allocMatrixIndicesOnGPU(SPtr<GridImp> grid); - - void allocAndCopyTrianglesToGPU(TriangularMesh &geom); - void freeTrianglesFromGPU(const TriangularMesh &geom); - - - void allocAndCopyMatrixIndicesToGPU(SPtr<GridImp> grid, const uint& size); - - void allocAndCopyFieldToGPU(Field& field); - void copyAndFreeFieldFromGPU(Field& field); - - void copyAndFreeDistributiondFromGPU(SPtr<GridImp> grid); - - void copyAndFreeNeighborsToCPU(SPtr<GridImp> grid); - void copyAndFreeMatrixIndicesFromGPU(SPtr<GridImp> grid, int size); - -public: - void allocateFieldMemory(Field* field) override; - void freeFieldMemory(Field* field) override; - void findSparseIndices(SPtr<GridImp> coarseGrid, SPtr<GridImp> fineGrid) override; - -}; - -#endif diff --git a/src/gpu/GridGenerator/grid/GridStrategy/GridStrategy.h b/src/gpu/GridGenerator/grid/GridStrategy/GridStrategy.h deleted file mode 100644 index 4bf735f90dab005241160266836b910e1c113cea..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/grid/GridStrategy/GridStrategy.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef GRID_STRATEGY_H -#define GRID_STRATEGY_H - -#include "Core/LbmOrGks.h" - -#include "global.h" - -#include "grid/Field.h" - -struct Vertex; -class TriangularMesh; -class GridImp; - -class GRIDGENERATOR_EXPORT GridStrategy -{ -public: - virtual ~GridStrategy() {} - - virtual void allocateFieldMemory(Field* field) = 0; - virtual void freeFieldMemory(Field* field) = 0; - - virtual void allocateGridMemory(SPtr<GridImp> grid) = 0; - - virtual void allocateQs(SPtr<GridImp> grid) = 0; - - virtual void initalNodesToOutOfGrid(SPtr<GridImp> grid) = 0; - virtual void fixOddCells(SPtr<GridImp> grid) = 0; - virtual void findInnerNodes(SPtr<GridImp> grid) = 0; - virtual void addOverlap(SPtr<GridImp> grid) = 0; - - virtual void fixRefinementIntoWall(SPtr<GridImp> grid) = 0; - virtual void findStopperNodes(SPtr<GridImp> grid) = 0; - virtual void findBoundarySolidNodes(SPtr<GridImp> grid) = 0; - virtual void findEndOfGridStopperNodes(SPtr<GridImp> grid) = 0; - virtual void findSolidStopperNodes(SPtr<GridImp> grid) = 0; - - virtual void mesh(SPtr<GridImp> grid, TriangularMesh &geom) = 0; - - virtual uint closeNeedleCells(SPtr<GridImp> grid) = 0; - virtual uint closeNeedleCellsThinWall(SPtr<GridImp> grid) = 0; - - virtual void findQs(SPtr<GridImp> grid, TriangularMesh &geom) = 0; - - virtual void findGridInterface(SPtr<GridImp> grid, SPtr<GridImp> fineGrid, LbmOrGks lbmOrGks) = 0; - - virtual void findSparseIndices(SPtr<GridImp> coarseGrid, SPtr<GridImp> fineGrid) = 0; - - - virtual void freeMemory(SPtr<GridImp> grid) = 0; - -}; - -#endif diff --git a/src/gpu/GridGenerator/grid/NodeValues.h b/src/gpu/GridGenerator/grid/NodeValues.h index b5661f081873cbb9e632f76be97ba9bc409071ed..c726fdf85c8199633e118d8f8a5365ee658d4e6a 100644 --- a/src/gpu/GridGenerator/grid/NodeValues.h +++ b/src/gpu/GridGenerator/grid/NodeValues.h @@ -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 NodeValues.h +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz, Martin Schoenherr +//======================================================================================= #ifndef NodeValues_H #define NodeValues_H @@ -14,34 +46,33 @@ static constexpr char FLUID_CFF = 2; static constexpr char FLUID_FCC = 3; static constexpr char FLUID_FCF = 4; -static constexpr char MULTI_GPU_SEND = 10; +static constexpr char MULTI_GPU_SEND = 10; static constexpr char MULTI_GPU_RECIEVE = 11; static constexpr char BC_PRESSURE = 20; static constexpr char BC_VELOCITY = 21; -static constexpr char BC_SOLID = 22; +static constexpr char BC_SOLID = 22; -static constexpr char BC_SLIP = 23; -static constexpr char BC_NOSLIP = 24; +static constexpr char BC_SLIP = 23; +static constexpr char BC_NOSLIP = 24; static constexpr char BC_OUTFLOW = 25; -static constexpr char STOPPER_OUT_OF_GRID = 30; -static constexpr char STOPPER_COARSE_UNDER_FINE = 31; -static constexpr char STOPPER_SOLID = 32; +static constexpr char STOPPER_OUT_OF_GRID = 30; +static constexpr char STOPPER_COARSE_UNDER_FINE = 31; +static constexpr char STOPPER_SOLID = 32; static constexpr char STOPPER_OUT_OF_GRID_BOUNDARY = 33; -static constexpr char INVALID_OUT_OF_GRID = 40; +static constexpr char INVALID_OUT_OF_GRID = 40; static constexpr char INVALID_COARSE_UNDER_FINE = 41; -static constexpr char INVALID_SOLID = 42; +static constexpr char INVALID_SOLID = 42; -//????WTF????? -static constexpr char INSIDE = 50; +static constexpr char INSIDE = 50; static constexpr char NEGATIVE_DIRECTION_BORDER = 51; -static constexpr char Q_DEPRECATED = 52; +static constexpr char Q_DEPRECATED = 52; static constexpr char OVERLAP_TMP = 60; -} -} +} // namespace gpu +} // namespace vf #endif diff --git a/src/gpu/GridGenerator/grid/distributions/D3Q13.h b/src/gpu/GridGenerator/grid/distributions/D3Q13.h deleted file mode 100644 index f314b970c2c6766ce367342ca649629d23131db6..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/grid/distributions/D3Q13.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef D3Q13_H -#define D3Q13_H - -#define DIR_13_R 0 -#define DIR_13_NE 1 -#define DIR_13_SW 2 -#define DIR_13_SE 3 -#define DIR_13_NW 4 -#define DIR_13_TE 5 -#define DIR_13_BW 6 -#define DIR_13_BE 7 -#define DIR_13_TW 8 -#define DIR_13_TN 9 -#define DIR_13_BS 10 -#define DIR_13_BN 11 -#define DIR_13_TS 12 - -#define DIR_13_START 0 -#define DIR_13_END 12 - - -#define DIR_13_NE_X 1 -#define DIR_13_NE_Y 1 -#define DIR_13_NE_Z 0 - -#define DIR_13_SW_X -1 -#define DIR_13_SW_Y -1 -#define DIR_13_SW_Z 0 - -#define DIR_13_SE_X 1 -#define DIR_13_SE_Y -1 -#define DIR_13_SE_Z 0 - -#define DIR_13_NW_X -1 -#define DIR_13_NW_Y 1 -#define DIR_13_NW_Z 0 - -#define DIR_13_TE_X 1 -#define DIR_13_TE_Y 0 -#define DIR_13_TE_Z 1 - -#define DIR_13_BW_X -1 -#define DIR_13_BW_Y 0 -#define DIR_13_BW_Z -1 - -#define DIR_13_BE_X 1 -#define DIR_13_BE_Y 0 -#define DIR_13_BE_Z -1 - -#define DIR_13_TW_X -1 -#define DIR_13_TW_Y 0 -#define DIR_13_TW_Z 1 - -#define DIR_13_TN_X 0 -#define DIR_13_TN_Y 1 -#define DIR_13_TN_Z 1 - -#define DIR_13_BS_X 0 -#define DIR_13_BS_Y -1 -#define DIR_13_BS_Z -1 - -#define DIR_13_BN_X 0 -#define DIR_13_BN_Y 1 -#define DIR_13_BN_Z -1 - -#define DIR_13_TS_X 0 -#define DIR_13_TS_Y -1 -#define DIR_13_TS_Z 1 - -#endif diff --git a/src/gpu/GridGenerator/grid/distributions/D3Q19.h b/src/gpu/GridGenerator/grid/distributions/D3Q19.h deleted file mode 100644 index 3f48a3bb11f78d68b53fabcfa8ea8ff475a88f6d..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/grid/distributions/D3Q19.h +++ /dev/null @@ -1,100 +0,0 @@ -#ifndef D3Q19_H_ -#define D3Q19_H_ - -#define DIR_19_E 0 -#define DIR_19_W 1 -#define DIR_19_N 2 -#define DIR_19_S 3 -#define DIR_19_T 4 -#define DIR_19_B 5 -#define DIR_19_NE 6 -#define DIR_19_SW 7 -#define DIR_19_SE 8 -#define DIR_19_NW 9 -#define DIR_19_TE 10 -#define DIR_19_BW 11 -#define DIR_19_BE 12 -#define DIR_19_TW 13 -#define DIR_19_TN 14 -#define DIR_19_BS 15 -#define DIR_19_BN 16 -#define DIR_19_TS 17 -#define DIR_19_ZERO 18 - -#define DIR_19_START 0 -#define DIR_19_END 18 - - -#define DIR_19_E_X 1 -#define DIR_19_E_Y 0 -#define DIR_19_E_Z 0 - -#define DIR_19_W_X -1 -#define DIR_19_W_Y 0 -#define DIR_19_W_Z 0 - -#define DIR_19_N_X 0 -#define DIR_19_N_Y 1 -#define DIR_19_N_Z 0 - -#define DIR_19_S_X 0 -#define DIR_19_S_Y -1 -#define DIR_19_S_Z 0 - -#define DIR_19_T_X 0 -#define DIR_19_T_Y 0 -#define DIR_19_T_Z 1 - -#define DIR_19_B_X 0 -#define DIR_19_B_Y 0 -#define DIR_19_B_Z -1 - -#define DIR_19_NE_X 1 -#define DIR_19_NE_Y 1 -#define DIR_19_NE_Z 0 - -#define DIR_19_SW_X -1 -#define DIR_19_SW_Y -1 -#define DIR_19_SW_Z 0 - -#define DIR_19_SE_X 1 -#define DIR_19_SE_Y -1 -#define DIR_19_SE_Z 0 - -#define DIR_19_NW_X -1 -#define DIR_19_NW_Y 1 -#define DIR_19_NW_Z 0 - -#define DIR_19_TE_X 1 -#define DIR_19_TE_Y 0 -#define DIR_19_TE_Z 1 - -#define DIR_19_BW_X -1 -#define DIR_19_BW_Y 0 -#define DIR_19_BW_Z -1 - -#define DIR_19_BE_X 1 -#define DIR_19_BE_Y 0 -#define DIR_19_BE_Z -1 - -#define DIR_19_TW_X -1 -#define DIR_19_TW_Y 0 -#define DIR_19_TW_Z 1 - -#define DIR_19_TN_X 0 -#define DIR_19_TN_Y 1 -#define DIR_19_TN_Z 1 - -#define DIR_19_BS_X 0 -#define DIR_19_BS_Y -1 -#define DIR_19_BS_Z -1 - -#define DIR_19_BN_X 0 -#define DIR_19_BN_Y 1 -#define DIR_19_BN_Z -1 - -#define DIR_19_TS_X 0 -#define DIR_19_TS_Y -1 -#define DIR_19_TS_Z 1 - -#endif diff --git a/src/gpu/GridGenerator/grid/distributions/D3Q27.h b/src/gpu/GridGenerator/grid/distributions/D3Q27.h index b849b9e37f518e87a6d7249de476827cd83d7ae2..680fa88305b793934747d09113f284bfe96b4988 100644 --- a/src/gpu/GridGenerator/grid/distributions/D3Q27.h +++ b/src/gpu/GridGenerator/grid/distributions/D3Q27.h @@ -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 D3Q27.h +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef D3Q27_H_ #define D3Q27_H_ diff --git a/src/gpu/GridGenerator/grid/distributions/D3Q7.h b/src/gpu/GridGenerator/grid/distributions/D3Q7.h index 6654cc1475d87875407d107ec9e300744831a7b9..f43aeb01c5ebf85f4b2f97e90f61585d4dd6da88 100644 --- a/src/gpu/GridGenerator/grid/distributions/D3Q7.h +++ b/src/gpu/GridGenerator/grid/distributions/D3Q7.h @@ -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 D3Q7.h +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef D3Q7_H #define D3Q7_H diff --git a/src/gpu/GridGenerator/grid/distributions/Distribution.cpp b/src/gpu/GridGenerator/grid/distributions/Distribution.cpp index f23c545cd6cb88892724fec5afb29d2f454e96a2..b0200812631aeff1947a56f78cae4232bd4d3ee7 100644 --- a/src/gpu/GridGenerator/grid/distributions/Distribution.cpp +++ b/src/gpu/GridGenerator/grid/distributions/Distribution.cpp @@ -1,197 +1,43 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// 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 Distribution.cpp +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "Distribution.h" #include <stdio.h> - -#include "grid/distributions/D3Q7.h" -#include "grid/distributions/D3Q13.h" -#include "grid/distributions/D3Q19.h" + #include "grid/distributions/D3Q27.h" #include "grid/Grid.h" -Distribution DistributionHelper::getDistribution7() -{ - Distribution d7; - d7.name = "D3Q7"; - d7.dir_start = DIR_7_START; - d7.dir_end = DIR_7_END; - - d7.dirs = new int[DIR_7_END * DIMENSION]; - - int dir_num = 0; - d7.dirs[dir_num++] = DIR_7_E_X; - d7.dirs[dir_num++] = DIR_7_E_Y; - d7.dirs[dir_num++] = DIR_7_E_Z; - - d7.dirs[dir_num++] = DIR_7_W_X; - d7.dirs[dir_num++] = DIR_7_W_Y; - d7.dirs[dir_num++] = DIR_7_W_Z; - - d7.dirs[dir_num++] = DIR_7_N_X; - d7.dirs[dir_num++] = DIR_7_N_Y; - d7.dirs[dir_num++] = DIR_7_N_Z; - - d7.dirs[dir_num++] = DIR_7_S_X; - d7.dirs[dir_num++] = DIR_7_S_Y; - d7.dirs[dir_num++] = DIR_7_S_Z; - - d7.dirs[dir_num++] = DIR_7_T_X; - d7.dirs[dir_num++] = DIR_7_T_Y; - d7.dirs[dir_num++] = DIR_7_T_Z; - - d7.dirs[dir_num++] = DIR_7_B_X; - d7.dirs[dir_num++] = DIR_7_B_Y; - d7.dirs[dir_num++] = DIR_7_B_Z; - - return d7; -} - -Distribution DistributionHelper::getDistribution13() -{ - Distribution d13; - d13.name = "D3Q13"; - d13.dir_start = DIR_13_START; - d13.dir_end = DIR_13_END; - - d13.dirs = new int[DIR_13_END * DIMENSION]; - - int dir_num = 0; - d13.dirs[dir_num++] = DIR_13_NE_X; - d13.dirs[dir_num++] = DIR_13_NE_Y; - d13.dirs[dir_num++] = DIR_13_NE_Z; - - d13.dirs[dir_num++] = DIR_13_SW_X; - d13.dirs[dir_num++] = DIR_13_SW_Y; - d13.dirs[dir_num++] = DIR_13_SW_Z; - - d13.dirs[dir_num++] = DIR_13_SE_X; - d13.dirs[dir_num++] = DIR_13_SE_Y; - d13.dirs[dir_num++] = DIR_13_SE_Z; - - d13.dirs[dir_num++] = DIR_13_NW_X; - d13.dirs[dir_num++] = DIR_13_NW_Y; - d13.dirs[dir_num++] = DIR_13_NW_Z; - - d13.dirs[dir_num++] = DIR_13_TE_X; - d13.dirs[dir_num++] = DIR_13_TE_Y; - d13.dirs[dir_num++] = DIR_13_TE_Z; - - d13.dirs[dir_num++] = DIR_13_BW_X; - d13.dirs[dir_num++] = DIR_13_BW_Y; - d13.dirs[dir_num++] = DIR_13_BW_Z; - - d13.dirs[dir_num++] = DIR_13_BE_X; - d13.dirs[dir_num++] = DIR_13_BE_Y; - d13.dirs[dir_num++] = DIR_13_BE_Z; - - d13.dirs[dir_num++] = DIR_13_TW_X; - d13.dirs[dir_num++] = DIR_13_TW_Y; - d13.dirs[dir_num++] = DIR_13_TW_Z; - - d13.dirs[dir_num++] = DIR_13_TN_X; - d13.dirs[dir_num++] = DIR_13_TN_Y; - d13.dirs[dir_num++] = DIR_13_TN_Z; - - d13.dirs[dir_num++] = DIR_13_BS_X; - d13.dirs[dir_num++] = DIR_13_BS_Y; - d13.dirs[dir_num++] = DIR_13_BS_Z; - - d13.dirs[dir_num++] = DIR_13_BN_X; - d13.dirs[dir_num++] = DIR_13_BN_Y; - d13.dirs[dir_num++] = DIR_13_BN_Z; - - d13.dirs[dir_num++] = DIR_13_TS_X; - d13.dirs[dir_num++] = DIR_13_TS_Y; - d13.dirs[dir_num++] = DIR_13_TS_Z; - - return d13; -} - -Distribution DistributionHelper::getDistribution19() -{ - Distribution d19; - d19.name = "D3Q19"; - d19.dir_start = DIR_19_START; - d19.dir_end = DIR_19_END; - - d19.dirs = new int[DIR_19_END * DIMENSION]; - - int dir_num = 0; - d19.dirs[dir_num++] = DIR_19_E_X; - d19.dirs[dir_num++] = DIR_19_E_Y; - d19.dirs[dir_num++] = DIR_19_E_Z; - - d19.dirs[dir_num++] = DIR_19_W_X; - d19.dirs[dir_num++] = DIR_19_W_Y; - d19.dirs[dir_num++] = DIR_19_W_Z; - - d19.dirs[dir_num++] = DIR_19_N_X; - d19.dirs[dir_num++] = DIR_19_N_Y; - d19.dirs[dir_num++] = DIR_19_N_Z; - - d19.dirs[dir_num++] = DIR_19_S_X; - d19.dirs[dir_num++] = DIR_19_S_Y; - d19.dirs[dir_num++] = DIR_19_S_Z; - - d19.dirs[dir_num++] = DIR_19_T_X; - d19.dirs[dir_num++] = DIR_19_T_Y; - d19.dirs[dir_num++] = DIR_19_T_Z; - - d19.dirs[dir_num++] = DIR_19_B_X; - d19.dirs[dir_num++] = DIR_19_B_Y; - d19.dirs[dir_num++] = DIR_19_B_Z; - - d19.dirs[dir_num++] = DIR_19_NE_X; - d19.dirs[dir_num++] = DIR_19_NE_Y; - d19.dirs[dir_num++] = DIR_19_NE_Z; - - d19.dirs[dir_num++] = DIR_19_SW_X; - d19.dirs[dir_num++] = DIR_19_SW_Y; - d19.dirs[dir_num++] = DIR_19_SW_Z; - - d19.dirs[dir_num++] = DIR_19_SE_X; - d19.dirs[dir_num++] = DIR_19_SE_Y; - d19.dirs[dir_num++] = DIR_19_SE_Z; - - d19.dirs[dir_num++] = DIR_19_NW_X; - d19.dirs[dir_num++] = DIR_19_NW_Y; - d19.dirs[dir_num++] = DIR_19_NW_Z; - - d19.dirs[dir_num++] = DIR_19_TE_X; - d19.dirs[dir_num++] = DIR_19_TE_Y; - d19.dirs[dir_num++] = DIR_19_TE_Z; - - d19.dirs[dir_num++] = DIR_19_BW_X; - d19.dirs[dir_num++] = DIR_19_BW_Y; - d19.dirs[dir_num++] = DIR_19_BW_Z; - - d19.dirs[dir_num++] = DIR_19_BE_X; - d19.dirs[dir_num++] = DIR_19_BE_Y; - d19.dirs[dir_num++] = DIR_19_BE_Z; - - d19.dirs[dir_num++] = DIR_19_TW_X; - d19.dirs[dir_num++] = DIR_19_TW_Y; - d19.dirs[dir_num++] = DIR_19_TW_Z; - - d19.dirs[dir_num++] = DIR_19_TN_X; - d19.dirs[dir_num++] = DIR_19_TN_Y; - d19.dirs[dir_num++] = DIR_19_TN_Z; - - d19.dirs[dir_num++] = DIR_19_BS_X; - d19.dirs[dir_num++] = DIR_19_BS_Y; - d19.dirs[dir_num++] = DIR_19_BS_Z; - - d19.dirs[dir_num++] = DIR_19_BN_X; - d19.dirs[dir_num++] = DIR_19_BN_Y; - d19.dirs[dir_num++] = DIR_19_BN_Z; - - d19.dirs[dir_num++] = DIR_19_TS_X; - d19.dirs[dir_num++] = DIR_19_TS_Y; - d19.dirs[dir_num++] = DIR_19_TS_Z; - - return d19; -} - Distribution DistributionHelper::getDistribution27() { Distribution d27; @@ -357,12 +203,6 @@ Distribution DistributionHelper::getDistribution27() Distribution DistributionHelper::getDistribution(std::string name) { - if (name == "D3Q7") - return getDistribution7(); - if (name == "D3Q13") - return getDistribution13(); - if (name == "D3Q19") - return getDistribution19(); if (name == "D3Q27") return getDistribution27(); diff --git a/src/gpu/GridGenerator/grid/distributions/Distribution.h b/src/gpu/GridGenerator/grid/distributions/Distribution.h index b05b5db3652ee952ff083db560ed8316688819c9..abc6d8105c9daeb83f4e31478a55942f48bf5e65 100644 --- a/src/gpu/GridGenerator/grid/distributions/Distribution.h +++ b/src/gpu/GridGenerator/grid/distributions/Distribution.h @@ -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 Distribution.h +//! \ingroup grid +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef Distribution_H #define Distribution_H @@ -11,21 +43,21 @@ struct Direction { - HOSTDEVICE Direction() + Direction() { dir[0] = 0; dir[1] = 0; dir[2] = 0; } - HOSTDEVICE Direction(int dx, int dy, int dz) + Direction(int dx, int dy, int dz) { dir[0] = dx; dir[1] = dy; dir[2] = dz; } - HOSTDEVICE int operator[](uint dir) const + int operator[](uint dir) const { if (dir < 3) return this->dir[dir]; @@ -52,10 +84,10 @@ struct Distribution fSize = size * (dir_end + 1); } - HOSTDEVICE iterator begin() { return &directions[0]; } - HOSTDEVICE const_iterator begin() const { return &directions[0]; } - HOSTDEVICE iterator end() { return &directions[dir_end + 1]; } - HOSTDEVICE const_iterator end() const { return &directions[dir_end + 1]; } + iterator begin() { return &directions[0]; } + const_iterator begin() const { return &directions[0]; } + iterator end() { return &directions[dir_end + 1]; } + const_iterator end() const { return &directions[dir_end + 1]; } }; class Grid; @@ -63,9 +95,6 @@ class Grid; class GRIDGENERATOR_EXPORT DistributionHelper { public: - static Distribution getDistribution7(); - static Distribution getDistribution13(); - static Distribution getDistribution19(); static Distribution getDistribution27(); static Distribution getDistribution(std::string name); diff --git a/src/gpu/GridGenerator/grid/kernel/runGridKernelGPU.cu b/src/gpu/GridGenerator/grid/kernel/runGridKernelGPU.cu deleted file mode 100644 index ff137357b5bd7904253db372b37ca5d9e47bd102..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/grid/kernel/runGridKernelGPU.cu +++ /dev/null @@ -1,215 +0,0 @@ -#include "runGridKernelGPU.cuh" - -#include "utilities/cuda/cudaDefines.h" -#include "utilities/cuda/cudaKernelCall.h" -#include "utilities/cuda/LaunchParameter.cuh" -#include "grid/GridImp.h" -#include "geometries/TriangularMesh/TriangularMesh.h" - -GLOBAL void initalField(GridImp grid); -GLOBAL void runMeshing(GridImp grid, const TriangularMesh geom); - -GLOBAL void findGridInterface(GridImp grid, GridImp finerGrid); -GLOBAL void runKernelTomarkNodesToDeleteOutsideOfGeometry(GridImp grid); -GLOBAL void markNodesToDeleteOutsideOfGeometry(GridImp grid); -GLOBAL void findNeighborIndicesKernel(GridImp grid); -GLOBAL void setOverlapNodesToInvalid(GridImp grid, GridImp finderGrid); - -////////////////////////////////////////////////////////////////////////// - -float runKernelInitalUniformGrid3d(const LaunchParameter& para, GridImp &grid) -{ - return runKernel(initalField, para, grid); -} - -GLOBAL void initalField(GridImp grid) -{ - //TODO: outcomment because of nvlink warning caused by the new allocation in Cell(). - //uint index = LaunchParameter::getGlobalIdx_2D_1D(); - //if (index < grid.getSize()) - // grid.findInnerNode(index); -} - -////////////////////////////////////////////////////////////////////////// - -float runKernelToMesh(const LaunchParameter& para, GridImp &grid, const TriangularMesh &geom) -{ - return runKernel(runMeshing, para, grid, geom); -} - -GLOBAL void runMeshing(GridImp grid, const TriangularMesh geom) -{ - // TODO: outcomment because of nvlink warning caused by the new allocation in Cell(). - //unsigned int i = LaunchParameter::getGlobalIdx_1D_1D(); - //if (i < geom.size) - // grid.mesh(geom.triangles[i]); -} - -////////////////////////////////////////////////////////////////////////// - -float runKernelToMarkNodesToDeleteOutsideOfGeometry(const LaunchParameter& para, GridImp &grid) -{ - return runKernel(markNodesToDeleteOutsideOfGeometry, para, grid); -} - -GLOBAL void markNodesToDeleteOutsideOfGeometry(GridImp grid) -{ - //int numberOfEdgeNodes = grid.ny * grid.nz; - //unsigned int i = LaunchParameter::getGlobalIdx_1D_1D(); - - //if (i < numberOfEdgeNodes) - //{ - // int x = 0; - // int y = i % grid.ny; - // int z = i / grid.ny; - - // grid.setFieldEntryToSolid(grid.transCoordToIndex(x, y, z)); - - // while (grid.isFluid(i) && x < grid.nx - 1) - // { - // x += 1; - // grid.setFieldEntryToSolid(grid.transCoordToIndex(x, y, z)); - // } - //} - -} - - -////////////////////////////////////////////////////////////////////////// - -float runKernelSetOverlapNodesToInvalid(const LaunchParameter& para, GridImp &grid, GridImp &finerGrid) -{ - return runKernel(setOverlapNodesToInvalid, para, grid, finerGrid); -} - -GLOBAL void setOverlapNodesToInvalid(GridImp grid, GridImp finerGrid) -{ - // not up to date - //const uint index = LaunchParameter::getGlobalIdx_2D_1D(); - //if (index < grid.getSize()) - //grid.findGridInterfaceCF(index, finerGrid); -} - - - -/*#################################################################################*/ -/*---------------------------------find invalid nodes------------------------------*/ -/*---------------------------------------------------------------------------------*/ -GLOBAL void setInvalidNodes(GridImp grid, bool *foundInvalidNode); -/*---------------------------------------------------------------------------------*/ - -float runKernelSetToInvalid(const LaunchParameter& para, GridImp &grid) -{ - bool* foundInvalidNode_d; - bool* foundInvalidNode_h = new bool(); - *foundInvalidNode_h = true; - CudaSafeCall( cudaMalloc(&foundInvalidNode_d, sizeof(bool))); - CudaCheckError(); - cudaEvent_t start, stop; - cudaEventCreate(&start); - cudaEventCreate(&stop); - cudaEventRecord(start, 0); - - while (*foundInvalidNode_h) - { - *foundInvalidNode_h = false; - CudaSafeCall(cudaMemcpy(foundInvalidNode_d, foundInvalidNode_h, sizeof(bool), cudaMemcpyHostToDevice)); - setInvalidNodes << <para.blocks, para.threads >> >(grid, foundInvalidNode_d); - cudaDeviceSynchronize(); - CudaCheckError(); - - CudaSafeCall(cudaMemcpy(foundInvalidNode_h, foundInvalidNode_d, sizeof(bool), cudaMemcpyDeviceToHost)); - } - - cudaDeviceSynchronize(); - cudaEventRecord(stop, 0); - cudaEventSynchronize(stop); - float elapsedTime; - cudaEventElapsedTime(&elapsedTime, start, stop); - - cudaEventDestroy(start); - cudaEventDestroy(stop); - - CudaCheckError(); - cudaFree(foundInvalidNode_d); - delete foundInvalidNode_h; - - return elapsedTime; -} - - -GLOBAL void setInvalidNodes(GridImp grid, bool *foundInvalidNode) -{ - uint index = LaunchParameter::getGlobalIdx_2D_1D(); - //if (index < grid.getSize()) - //grid.setInsideNode(index, *foundInvalidNode); -} - - -/*#################################################################################*/ - -float runKernelFindIndices(const LaunchParameter& para, GridImp &grid) -{ - return runKernel(findNeighborIndicesKernel, para, grid); -} - -GLOBAL void findNeighborIndicesKernel(GridImp grid) -{ - uint index = LaunchParameter::getGlobalIdx_2D_1D(); - if (index < grid.getSize()) - grid.setNeighborIndices(index); -} - - -/*#################################################################################*/ - -float runKernelToFindGridInterface(const LaunchParameter& para, GridImp &grid, GridImp &finerGrid) -{ - return runKernel(findGridInterface, para, grid, finerGrid); -} - -GLOBAL void findGridInterface(GridImp grid, GridImp finerGrid) -{ - // not up to date - //uint index = LaunchParameter::getGlobalIdx_2D_1D(); - //if (index < grid.getSize()) - // grid.findGridInterfaceCF(index, finerGrid); -} -/*#################################################################################*/ - -GLOBAL void findNeighborsNewIndices(GridImp grid); -float runKernelToFindNeighborsNewIndices(const LaunchParameter& para, GridImp &grid) -{ - return runKernel(findNeighborsNewIndices, para, grid); -} - -GLOBAL void findNeighborsNewIndices(GridImp grid) -{ - unsigned int index = LaunchParameter::getGlobalIdx_2D_1D(); - if (index < grid.getSize()) - grid.setNeighborIndices(index); -} -/*#################################################################################*/ - -GLOBAL void findGridInterfaceNewIndicesFC(GridImp grid); -GLOBAL void findGridInterfaceNewIndicesCF(GridImp grid); -float runKernelToFindGridInterfaceNewIndices(const LaunchParameter& para, GridImp &grid) -{ - runKernel(findGridInterfaceNewIndicesCF, para, grid); - return runKernel(findGridInterfaceNewIndicesFC, para, grid); -} - - -GLOBAL void findGridInterfaceNewIndicesCF(GridImp grid) -{ - unsigned int index = LaunchParameter::getGlobalIdx_2D_1D(); - //if (index < grid.getNumberOfNodesCF()) - //grid.findForGridInterfaceSparseIndexCF(index); -} - -GLOBAL void findGridInterfaceNewIndicesFC(GridImp grid) -{ - unsigned int index = LaunchParameter::getGlobalIdx_2D_1D(); - //if (index < grid.getNumberOfNodesFC()) - // grid.findForGridInterfaceSparseIndexFCcoarse(index); -} diff --git a/src/gpu/GridGenerator/grid/kernel/runGridKernelGPU.cuh b/src/gpu/GridGenerator/grid/kernel/runGridKernelGPU.cuh deleted file mode 100644 index e63e4288182ce91e2b8c2fbbb26bb84bf8fb77a5..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/grid/kernel/runGridKernelGPU.cuh +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef runGridKernelGPU_H -#define runGridKernelGPU_H - - -class Grid; -class GridImp; -class TriangularMesh; -class LaunchParameter; - -float runKernelInitalUniformGrid3d(const LaunchParameter& para, GridImp &grid); -float runKernelToMesh(const LaunchParameter& para, GridImp &grid, const TriangularMesh &geom); -float runKernelToMarkNodesToDeleteOutsideOfGeometry(const LaunchParameter& para, GridImp &grid); - -float runKernelToFindGridInterface(const LaunchParameter& para, GridImp &grid, GridImp &finerGrid); -float runKernelToFindNeighborsNewIndices(const LaunchParameter& para, GridImp &grid); -float runKernelToFindGridInterfaceNewIndices(const LaunchParameter& para, GridImp &grid); - - -float runKernelSetOverlapNodesToInvalid(const LaunchParameter& para, GridImp &grid, GridImp &finerGrid); -float runKernelSetToInvalid(const LaunchParameter& para, GridImp &grid); -float runKernelFindIndices(const LaunchParameter& para, GridImp &grid); - -#endif diff --git a/src/gpu/GridGenerator/grid/partition/Partition.cpp b/src/gpu/GridGenerator/grid/partition/Partition.cpp deleted file mode 100644 index 970599105e9363f37f930480f1874827672c86d2..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/grid/partition/Partition.cpp +++ /dev/null @@ -1,653 +0,0 @@ -//#include "Partition.h" -// -//#include "metis.h" -//#include <stdio.h> -//#include <iostream> -// -//#include <global.h> -//#include <GridGenerator/grid/Grid.h> -//#include <GridGenerator/geometries/Triangle/Triangle.h> -//#include <GridGenerator/geometries/Vertex/Vertex.h> -//#include <GridGenerator/geometries/BoundingBox/BoundingBox.h> -//#include <GridGenerator/io/GridVTKWriter/GridVTKWriter.h> -//#include <GridGenerator/io/VTKWriterWrapper/UnstructuredGridWrapper.h> -//#include <GridGenerator/utilities/Transformator/TransformatorImp.h> -// -//#include <utilities/logger/Logger.h> -// -//int Partition::calcEdgesFromGraph(SPtr<Grid> grid) -//{ -// int insideNeighbors = 6; -// int cornerNeighbors = 3; -// int outsideEdgesNeighbors = 4; -// int ousiteAreaNeighbors = 5; -// -// int corner = 8; -// int outsiteEdges = grid->getNumberOfNodesX() * 4 + grid->getNumberOfNodesY() * 4 + grid->getNumberOfNodesZ() * 4 - 24; -// int outsideArea = 2 * grid->getNumberOfNodesX()*grid->getNumberOfNodesY() + 2 * grid->getNumberOfNodesX()*grid->getNumberOfNodesZ() + 2 * grid->getNumberOfNodesY()*grid->getNumberOfNodesZ() - 8 * grid->getNumberOfNodesX() - 8 * grid->getNumberOfNodesY() - 8 * grid->getNumberOfNodesZ() + 24; -// int inside = grid->getSize() - corner - outsiteEdges - outsideArea; -// return inside * insideNeighbors + outsideArea * ousiteAreaNeighbors + outsiteEdges * outsideEdgesNeighbors + corner * cornerNeighbors; -//} -// -//void Partition::partitionGridMesh(SPtr<Grid> grid) -//{ -// printf("MESH\n"); -// -// idx_t nelements = (grid->getNumberOfNodesX() - 1) * (grid->getNumberOfNodesY() - 1) * (grid->getNumberOfNodesZ() - 1); -// idx_t nNodes = nelements * 8; -// idx_t nWeightsMesh = 1; -// idx_t nPartsMesh = 2; -// -// idx_t *partMeshNodes = new idx_t[nNodes]; -// idx_t *partMeshElements = new idx_t[nelements]; -// idx_t objval; -// -// // Indexes of starting points in adjacent array -// idx_t *eptr = new idx_t[nelements + 1]; -// -// for (int i = 0; i < nelements + 1; i++) { -// eptr[i] = i * 8; -// } -// -// // Adjacent vertices in consecutive index order -// idx_t *eind = new idx_t[nNodes]; -// -// real x, y, z, newX, newY, newZ; -// int nIndex; -// int numberNode = 0; -// for (unsigned int index = 0; index < grid->getSize(); index++) { -// grid->transIndexToCoords(index, x, y, z); -// -// newX = x + 1; -// newY = y + 1; -// newZ = z + 1; -// if (newX >= grid->getNumberOfNodesX() || newY >= grid->getNumberOfNodesY() || newZ >= grid->getNumberOfNodesZ()) -// continue; -// -// // self -// eind[numberNode] = index; -// numberNode++; -// -// //+x -// nIndex = grid->transCoordToIndex(newX, y, z); -// eind[numberNode] = nIndex; -// numberNode++; -// -// //x//+y -// nIndex = grid->transCoordToIndex(newX, newY, z); -// eind[numberNode] = nIndex; -// numberNode++; -// -// //+y -// nIndex = grid->transCoordToIndex(x, newY, z); -// eind[numberNode] = nIndex; -// numberNode++; -// -// //+z -// nIndex = grid->transCoordToIndex(x, y, newZ); -// eind[numberNode] = nIndex; -// numberNode++; -// -// //+z//+x -// nIndex = grid->transCoordToIndex(newX, y, newZ); -// eind[numberNode] = nIndex; -// numberNode++; -// -// //+z//+x//+y -// nIndex = grid->transCoordToIndex(newX, newY, newZ); -// eind[numberNode] = nIndex; -// numberNode++; -// -// //+z//+y -// nIndex = grid->transCoordToIndex(x, newY, newZ); -// eind[numberNode] = nIndex; -// numberNode++; -// -// } -// -// -// //for (int i = 0; i < nelements; i++) { -// // printf("element %d: ", i); -// // for (int v = eptr[i]; v < eptr[i + 1]; v++) { -// // printf("%d ", eind[v]); -// // } -// // printf("\n"); -// //} -// -// // Weights of vertices -// // if all weights are equal then can be set to NULL -// //idx_t vwgtMesh[nNodes * nWeightsMesh] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 }; -// -// idx_t ncommon = 4; -// -// rstatus_et ret = (rstatus_et)METIS_PartMeshDual(&nelements, &nNodes, eptr, eind, -// NULL, NULL, &ncommon, &nPartsMesh, -// NULL, NULL, &objval, partMeshElements, partMeshNodes); -// -// std::cout << ret << std::endl; -// -// for (int part_i = 0; part_i < nelements; part_i++){ -// std::cout << part_i << " " << partMeshElements[part_i] << std::endl; -// } -// -// -// for (unsigned int part_i = 0; part_i < grid->getSize(); part_i++){ -// //grid->setFieldEntry(part_i, partMeshNodes[part_i]); -// } -// -// GridVTKWriter::writeSparseGridToVTK(grid, "../../../../metisGridMesh.vtk"); -// -// delete[] partMeshNodes; -// delete[] partMeshElements; -// delete[] eptr; -// delete[] eind; -//} -// -//void Partition::partitionGrid(SPtr<Grid> grid) { -// idx_t nVertices = grid->getSize(); -// idx_t nEdges = calcEdgesFromGraph(grid); -// idx_t nWeights = 1; -// idx_t nParts = 4; -// -// idx_t objval; -// idx_t* part = new idx_t[nVertices]; -// idx_t* xadj = new idx_t[nVertices + 1]; -// idx_t* adjncy = new idx_t[nEdges]; -// -// xadj[0] = 0; -// real x, y, z, newX, newY, newZ; -// int nIndex; -// int numberOfNeighbors = 0; -// int counter = 0; -// for (int index = 0; index < nVertices; index++) { -// grid->transIndexToCoords(index, x, y, z); -// //+x -// newX = x + 1; -// if (newX >= 0 && newX < grid->getNumberOfNodesX()) { -// nIndex = grid->transCoordToIndex(newX, y, z); -// adjncy[numberOfNeighbors] = nIndex; -// numberOfNeighbors++; -// } -// //-x -// newX = x - 1; -// if (newX >= 0 && newX < grid->getNumberOfNodesX()) { -// nIndex = grid->transCoordToIndex(newX, y, z); -// adjncy[numberOfNeighbors] = nIndex; -// numberOfNeighbors++; -// } -// -// //+y -// newY = y + 1; -// if (newY >= 0 && newY < grid->getNumberOfNodesY()) { -// nIndex = grid->transCoordToIndex(x, newY, z); -// adjncy[numberOfNeighbors] = nIndex; -// numberOfNeighbors++; -// } -// -// //-y -// newY = y - 1; -// if (newY >= 0 && newY < grid->getNumberOfNodesY()) { -// nIndex = grid->transCoordToIndex(x, newY, z); -// adjncy[numberOfNeighbors] = nIndex; -// numberOfNeighbors++; -// } -// -// //+z -// newZ = z + 1; -// if (newZ >= 0 && newZ < grid->getNumberOfNodesZ()) { -// nIndex = grid->transCoordToIndex(x, y, newZ); -// adjncy[numberOfNeighbors] = nIndex; -// numberOfNeighbors++; -// } -// -// //-z -// newZ = z - 1; -// if (newZ >= 0 && newZ < grid->getNumberOfNodesZ()) { -// nIndex = grid->transCoordToIndex(x, y, newZ); -// adjncy[numberOfNeighbors] = nIndex; -// numberOfNeighbors++; -// } -// xadj[index + 1] = numberOfNeighbors; -// } -// -// -// // Indexes of starting points in adjacent array -// //idx_t xadj[nVertices + 1] = { 0, 2, 5, 7, 9, 12, 14 }; -// -// // Adjacent vertices in consecutive index order -// //idx_t adjncy[2 * nEdges] = { 1, 3, 0, 4, 2, 1, 5, 0, 4, 3, 1, 5, 4, 2 }; -// -// -// //for (int index = 0; index < nVertices; index++) { -// // printf("vertexNachbarn von %d: ", index); -// // printf("Grenzen: %d - %d, ", xadj[index], xadj[index + 1]); -// // for (int v = xadj[index]; v < xadj[index + 1]; v++) { -// // printf("%d ", adjncy[v]); -// // } -// // printf("\n"); -// //} -// -// // Weights of vertices -// // if all weights are equal then can be set to NULL -// //idx_t* vwgt = new idx_t[nVertices * nWeights]; -// -// idx_t options[METIS_NOPTIONS]; -// METIS_SetDefaultOptions(options); -// -// options[METIS_OPTION_OBJTYPE] = METIS_OBJTYPE_CUT; //minimizing the edge-cut communication -// -// options[METIS_OPTION_NCUTS] = 1; // number of different partitioning //default 1 -// options[METIS_OPTION_CONTIG] = 1; // force contiguous partitions -// options[METIS_OPTION_DBGLVL] = 0; //print debugging information -// -// rstatus_et ret = (rstatus_et)METIS_PartGraphKway(&nVertices, &nWeights, xadj, adjncy, -// NULL, NULL, NULL, &nParts, NULL, -// NULL, options, &objval, part); -// -// std::cout << ret << std::endl; -// -// //for (unsigned part_i = 0; part_i < nVertices; part_i++){ -// // std::cout << part_i << " " << part[part_i] << std::endl; -// //} -// -// for (int part_i = 0; part_i < nVertices; part_i++){ -// //grid->setFieldEntry(part_i, part[part_i]); -// } -// -// GridVTKWriter::writeSparseGridToVTK(grid, "../../../../metisGridFineFourParts.vtk"); -//} -// -//std::vector<std::vector<int> > Partition::partitionBoxes(std::vector<std::vector<BoundingBox> > boxes, int processes, std::vector< std::shared_ptr<Transformator> > transformators) -//{ -// if (processes == 1){ -// std::vector<std::vector<int> > tasks; -// tasks.resize(processes); -// tasks[0].push_back(0); -// tasks[0].push_back(0); -// return tasks; -// } -// -// std::vector<idx_t> xadj; -// std::vector<idx_t> adjncy; -// -// int numberOfNeighbors = 0; -// xadj.push_back(0); -// for (int level = 0; level < boxes.size(); level++) { -// for (int i = 0; i < boxes[level].size(); i++) { -// -// BoundingBox box = boxes[level][i]; -// transformators[level]->transformGridToWorld(box); -// -// int index = i + (int)boxes[level].size() * level; -// for (int levelCompare = 0; levelCompare < boxes.size(); levelCompare++) { -// for (int iCompare = 0; iCompare < boxes[levelCompare].size(); iCompare++) { -// int indexCompare = iCompare + (int)boxes[levelCompare].size() * levelCompare; -// if (index == indexCompare) -// continue; -// -// BoundingBox boxCompare = boxes[levelCompare][iCompare]; -// transformators[level]->transformGridToWorld(boxCompare); -// if (box.intersect(boxCompare)) { -// adjncy.push_back(indexCompare); -// numberOfNeighbors++; -// } -// } -// } -// xadj.push_back(numberOfNeighbors); -// } -// } -// -// //logging::Logger::getInstance()->logTerminal("Metis Graph Structure:"); -// //for (int index = 0; index < xadj.size() - 1; index++) { -// // logging::Logger::getInstance()->logTerminal("vertex neighbor [" + SSTR(index) + "]"); -// // logging::Logger::getInstance()->logTerminal(" boundary: " + SSTR(xadj[index]) + " - " + SSTR(xadj[index + 1]) + ","); -// // for (int v = xadj[index]; v < xadj[index + 1]; v++) { -// // logging::Logger::getInstance()->logTerminal(SSTR(adjncy[v]) + " "); -// // } -// // logging::Logger::getInstance()->logTerminal("\n"); -// //} -// -// // Weights of vertices -// // if all weights are equal then can be set to NULL -// //idx_t* vwgt = new idx_t[nVertices * nWeights]; -// -// idx_t options[METIS_NOPTIONS]; -// METIS_SetDefaultOptions(options); -// -// options[METIS_OPTION_OBJTYPE] = METIS_OBJTYPE_CUT; //minimizing the edge-cut communication -// -// options[METIS_OPTION_NCUTS] = 1; // number of different partitioning //default 1 -// options[METIS_OPTION_CONTIG] = 1; // force contiguous partitions -// options[METIS_OPTION_DBGLVL] = 0; //print debugging information -// -// idx_t nVertices = (idx_t)xadj.size() - 1; -// idx_t nWeights = 1; -// idx_t nParts = processes; -// -// idx_t objval; -// idx_t* part = new idx_t[nVertices]; -// -// //rstatus_et ret = (rstatus_et)METIS_PartGraphKway(&nVertices, &nWeights, xadj.data(), adjncy.data(), -// // NULL, NULL, NULL, &nParts, NULL, -// // NULL, options, &objval, part); -// -// rstatus_et ret = (rstatus_et)METIS_PartGraphRecursive(&nVertices, &nWeights, xadj.data(), adjncy.data(), -// NULL, NULL, NULL, &nParts, NULL, -// NULL, options, &objval, part); -// -// if (ret == METIS_OK) -// *logging::out << logging::Logger::INFO_INTERMEDIATE << "Metis Status: OK\n"; -// -// -// -// for (int part_i = 0; part_i < nVertices; part_i++) -// *logging::out << logging::Logger::INFO_INTERMEDIATE << "Block: " << part_i << " - Partition: " << part[part_i] << "\n"; -// -// -// std::vector<std::vector<int> > tasks; -// tasks.resize(processes); -// -// for (int i = 0; i < nVertices; i++) { -// int x = i % boxes[0].size(); -// int level = (i - x) / (int)boxes[0].size(); -// tasks[part[i]].push_back(level); -// tasks[part[i]].push_back(x); -// } -// -// return tasks; -//} -// -//std::vector<BoundingBox> Partition::getProcessBoxes(const int numberOfProcesses, const int globalNx, const int globalNy, const int globalNz) -//{ -// std::vector<BoundingBox> boxes; -// BoundingBox b(0, globalNx, 0, globalNy, 0, globalNz); -// boxes.push_back(b); -// if (numberOfProcesses == 1) -// return boxes; -// -// bool splitX, splitY, splitZ; -// while (boxes.size() < numberOfProcesses) -// { -// findMaxBoxSize(boxes, splitX, splitY, splitZ); -// if (numberOfProcesses % 3 == 0) -// splitAllBoxesInThreePieces(boxes, splitX, splitY, splitZ); -// else -// splitAllBoxesInTwoPieces(boxes, splitX, splitY, splitZ); -// } -// return boxes; -//} -// -//std::vector<std::vector<Triangle> > Partition::getTrianglesPerProcess(std::vector<BoundingBox> &boxes, Triangle *triangles, int nTriangles) -//{ -// std::vector<Triangle> triangleVec; -// triangleVec.resize(nTriangles); -// for (int i = 0; i < nTriangles; i++) -// triangleVec[i] = triangles[i]; -// -// std::vector<std::vector<Triangle> > trianglesPerProcess; -// trianglesPerProcess.resize(boxes.size()); -// -// for (int j = 0; j < triangleVec.size(); j++) { -// for (int i = 0; i < boxes.size(); i++) { -// if (boxes[i].isInside(triangleVec[j])) { -// trianglesPerProcess[i].push_back(triangleVec[j]); -// triangleVec.erase(triangleVec.begin() + j); -// j--; -// break; -// } -// else if (boxes[i].intersect(triangleVec[j])) { -// //splitAndPushTriangle(boxes[i], trianglesPerProcess[i], triangleVec, j); -// trianglesPerProcess[i].push_back(triangleVec[j]); -// } -// } -// } -// return trianglesPerProcess; -//} -// -//void Partition::findMaxBoxSize(std::vector<BoundingBox> &boxes, bool &splitX, bool &splitY, bool &splitZ) -//{ -// int lengthX, lengthY, lengthZ; -// lengthX = boxes[0].maxX - boxes[0].minX; -// lengthY = boxes[0].maxY - boxes[0].minY; -// lengthZ = boxes[0].maxZ - boxes[0].minZ; -// -// splitX = true, splitY = false, splitZ = false; -// if (lengthX < lengthY){ -// splitX = splitZ = false; -// splitY = true; -// } -// else if (lengthY < lengthZ){ -// splitX = splitY = false; -// splitZ = true; -// } -//} -// -//void Partition::splitAllBoxesInThreePieces(std::vector<BoundingBox> &boxes, bool splitX, bool splitY, bool splitZ) -//{ -// std::vector<BoundingBox> boxesTemp; -// for (int i = 0; i < boxes.size(); i++) { -// if (splitX) { -// int newLengthX = (boxes[i].maxX - boxes[i].minX) / 3; -// BoundingBox splitBox1(boxes[i].minX, boxes[i].minX + newLengthX, boxes[i].minY, boxes[i].maxY, boxes[i].minZ, boxes[i].maxZ); -// BoundingBox splitBox2(boxes[i].minX, boxes[i].minX + newLengthX + newLengthX, boxes[i].minY, boxes[i].maxY, boxes[i].minZ, boxes[i].maxZ); -// BoundingBox splitBox3(boxes[i].minX + newLengthX + newLengthX, boxes[i].maxX, boxes[i].minY, boxes[i].maxY, boxes[i].minZ, boxes[i].maxZ); -// boxesTemp.push_back(splitBox1); -// boxesTemp.push_back(splitBox2); -// boxesTemp.push_back(splitBox3); -// } -// if (splitY) { -// int newLengthY = (boxes[i].maxY - boxes[i].minY) / 3; -// BoundingBox splitBox1(boxes[i].minX, boxes[i].maxX, boxes[i].minY, boxes[i].minY + newLengthY, boxes[i].minZ, boxes[i].maxZ); -// BoundingBox splitBox2(boxes[i].minX, boxes[i].maxX, boxes[i].minY + newLengthY, boxes[i].minY + newLengthY + newLengthY, boxes[i].minZ, boxes[i].maxZ); -// BoundingBox splitBox3(boxes[i].minX, boxes[i].maxX, boxes[i].minY + newLengthY + newLengthY, boxes[i].maxY, boxes[i].minZ, boxes[i].maxZ); -// boxesTemp.push_back(splitBox1); -// boxesTemp.push_back(splitBox2); -// boxesTemp.push_back(splitBox3); -// } -// if (splitZ) { -// int newLengthZ = (boxes[i].maxZ - boxes[i].minZ) / 3; -// BoundingBox splitBox1(boxes[i].minX, boxes[i].maxX, boxes[i].minY, boxes[i].maxY, boxes[i].minZ, boxes[i].minZ + newLengthZ); -// BoundingBox splitBox2(boxes[i].minX, boxes[i].maxX, boxes[i].minY, boxes[i].maxY, boxes[i].minZ + newLengthZ, boxes[i].minZ + newLengthZ + newLengthZ); -// BoundingBox splitBox3(boxes[i].minX, boxes[i].maxX, boxes[i].minY, boxes[i].maxY, boxes[i].minZ + newLengthZ + newLengthZ, boxes[i].maxZ); -// boxesTemp.push_back(splitBox1); -// boxesTemp.push_back(splitBox2); -// boxesTemp.push_back(splitBox3); -// } -// } -// boxes.clear(); -// boxes = boxesTemp; -//} -// -//void Partition::splitAllBoxesInTwoPieces(std::vector<BoundingBox> &boxes, bool splitX, bool splitY, bool splitZ) -//{ -// std::vector<BoundingBox> boxesTemp; -// for (int i = 0; i < boxes.size(); i++) { -// if (splitX) { -// int newLengthX = (boxes[i].maxX - boxes[i].minX) / 2; -// BoundingBox splitBox1(boxes[i].minX, boxes[i].minX + newLengthX, boxes[i].minY, boxes[i].maxY, boxes[i].minZ, boxes[i].maxZ); -// BoundingBox splitBox2(boxes[i].minX + newLengthX, boxes[i].maxX, boxes[i].minY, boxes[i].maxY, boxes[i].minZ, boxes[i].maxZ); -// boxesTemp.push_back(splitBox1); -// boxesTemp.push_back(splitBox2); -// } -// if (splitY) { -// int newLengthY = (boxes[i].maxY - boxes[i].minY) / 2; -// BoundingBox splitBox1(boxes[i].minX, boxes[i].maxX, boxes[i].minY, boxes[i].minY + newLengthY, boxes[i].minZ, boxes[i].maxZ); -// BoundingBox splitBox2(boxes[i].minX, boxes[i].maxX, boxes[i].minY + newLengthY, boxes[i].maxY, boxes[i].minZ, boxes[i].maxZ); -// boxesTemp.push_back(splitBox1); -// boxesTemp.push_back(splitBox2); -// } -// if (splitZ) { -// int newLengthZ = (boxes[i].maxZ - boxes[i].minZ) / 2; -// BoundingBox splitBox1(boxes[i].minX, boxes[i].maxX, boxes[i].minY, boxes[i].maxY, boxes[i].minZ, boxes[i].minZ + newLengthZ); -// BoundingBox splitBox2(boxes[i].minX, boxes[i].maxX, boxes[i].minY, boxes[i].maxY, boxes[i].minZ + newLengthZ, boxes[i].maxZ); -// boxesTemp.push_back(splitBox1); -// boxesTemp.push_back(splitBox2); -// } -// } -// boxes.clear(); -// boxes = boxesTemp; -//} -// -//std::vector<std::vector<Triangle> > Partition::splitTriangles(std::vector<Triangle> &triangleVec, std::vector<BoundingBox> boxes) -//{ -// std::vector<std::vector<Triangle> > trianglesPerProcess; -// trianglesPerProcess.resize(boxes.size()); -// -// for (int j = 0; j < triangleVec.size(); j++) { -// for (int i = 0; i < boxes.size(); i++) { -// if (boxes[i].isInside(triangleVec[j])) { -// trianglesPerProcess[i].push_back(triangleVec[j]); -// triangleVec.erase(triangleVec.begin() + j); -// j--; -// break; -// } -// else if (boxes[i].intersect(triangleVec[j])) { -// splitAndPushTriangle(boxes[i], trianglesPerProcess[i], triangleVec, j); -// //trianglesPerProcess[i].push_back(triangleVec[j]); -// } -// } -// } -// -// return trianglesPerProcess; -// -//} -// -// -// -//void Partition::splitAndPushTriangle(BoundingBox &box, std::vector<Triangle> &trianglesPerProcess, std::vector<Triangle> &triangleVec, int indexTriangle) -//{ -// Triangle triangleToSplit = triangleVec[indexTriangle]; -// //BoundingBox triangleBox = BoundingBox::makeExactBox(triangleToSplit); -// //std::vector<std::vector<Vertex> > intersectionsBox = box.getIntersectionPoints(triangleBox); -// -// //UnstructuredGridWriter writer; -// //double v1[3] = { triangleToSplit.v1.x, triangleToSplit.v1.y, triangleToSplit.v1.z }; -// //double v2[3] = { triangleToSplit.v2.x, triangleToSplit.v2.y, triangleToSplit.v2.z }; -// //double v3[3] = { triangleToSplit.v3.x, triangleToSplit.v3.y, triangleToSplit.v3.z }; -// //writer.addTriangle(v1, v2, v3); -// //double b[6] = { box.minX, box.maxX, box.minY, box.maxY, box.minZ, box.maxZ }; -// //writer.addBoundingBox(b); -// //double b2[6] = { triangleBox.minX, triangleBox.maxX, triangleBox.minY, triangleBox.maxY, triangleBox.minZ, triangleBox.maxZ }; -// //writer.addBoundingBox(b2); -// //writer.writeUnstructuredGridToFile("testIntersectionTriangle"); -// -// -// //for (int i = 0; i < intersectionsBox.size(); i++) { -// // if (intersectionsBox[i].size() == 0) -// // continue; -// -// // Vertex edge1 = intersectionsBox[i][0] - intersectionsBox[i][1]; -// // Vertex edge2 = intersectionsBox[i][1] - intersectionsBox[i][2]; -// // Vertex normal = edge1.crossProduct(edge2); -// // normal.normalize(); -// -// // Vertex point(intersectionsBox[i][0].x, intersectionsBox[i][0].y, intersectionsBox[i][0].z); -// // Vertex v4 = (triangleToSplit.v1 - point); -// // Vertex v5 = (triangleToSplit.v2 - point); -// // Vertex v6 = (triangleToSplit.v3 - point); -// -// // real d1 = v4 * normal; -// // real d2 = v5 * normal; -// // real d3 = v6 * normal; -// -// // // a to b crosses the clipping plane -// // if (d1 * d2 < 0.0f) -// // sliceTriangle(trianglesPerProcess, triangleVec, indexTriangle, triangleToSplit.v1, triangleToSplit.v2, triangleToSplit.v3, d1, d2, d3); -// -// // // a to c crosses the clipping plane -// // else if (d1 * d3 < 0.0f) -// // sliceTriangle(trianglesPerProcess, triangleVec, indexTriangle, triangleToSplit.v3, triangleToSplit.v1, triangleToSplit.v2, d3, d1, d2); -// -// // // b to c crosses the clipping plane -// // else if (d2 * d3 < 0.0f) -// // sliceTriangle(trianglesPerProcess, triangleVec, indexTriangle, triangleToSplit.v2, triangleToSplit.v3, triangleToSplit.v1, d2, d3, d1); -// //} -//} -// -// -//void Partition::sliceTriangle( -// std::vector<Triangle>& out, -// std::vector<Triangle>& triangleVec, -// int index, -// const Vertex& a, // First point on triangle, CCW order -// const Vertex& b, // Second point on triangle, CCW order -// const Vertex& c, // Third point on triangle, CCW order -// real d1, // Distance of point a to the splitting plane -// real d2, // Distance of point b to the splitting plane -// real d3 // Distance of point c to the splitting plane -// ) -//{ -// // Calculate the intersection point from a to b -// Vertex ab = a + ((b - a) * (d1 / (d1 - d2)) ); -// Triangle tri; -// -// if (d1 < 0.0f) -// { -// // b to c crosses the clipping plane -// if (d3 < 0.0f) -// { -// // Calculate intersection point from b to c -// Vertex bc = b + ((c - b) * (d2 / (d2 - d3))); -// -// tri.set(b, bc, ab); -// triangleVec.push_back(tri); -// -// tri.set(bc, c, a); -// triangleVec.push_back(tri); -// -// tri.set(ab, bc, a); -// triangleVec.push_back(tri); -// } -// -// // c to a crosses the clipping plane -// else -// { -// // Calculate intersection point from a to c -// Vertex ac = a + ((c - a) * (d1 / (d1 - d3))); -// -// tri.set(a, ab, ac); -// triangleVec.push_back(tri); -// -// tri.set(ab, b, c); -// triangleVec.push_back(tri); -// -// tri.set(ac, ab, c); -// triangleVec.push_back(tri); -// } -// } -// else -// { -// // c to a crosses the clipping plane -// if (d3 < 0.0f) -// { -// // Calculate intersection point from a to c -// Vertex ac = a + ((c - a) * (d1 / (d1 - d3))); -// -// tri.set(a, ab, ac); -// triangleVec.push_back(tri); -// -// tri.set(ac, ab, b); -// triangleVec.push_back(tri); -// -// tri.set(b, c, ac); -// triangleVec.push_back(tri); -// } -// -// // b to c crosses the clipping plane -// else -// { -// // Calculate intersection point from b to c -// Vertex bc = b + ((c - b) * (d2 / (d2 - d3))); -// -// tri.set(b, bc, ab); -// triangleVec.push_back(tri); -// -// tri.set(a, ab, bc); -// triangleVec.push_back(tri); -// -// tri.set(c, a, bc); -// triangleVec.push_back(tri); -// } -// } -//} -// diff --git a/src/gpu/GridGenerator/grid/partition/Partition.h b/src/gpu/GridGenerator/grid/partition/Partition.h deleted file mode 100644 index a45f7668b871f6910332de7262c6d407f32d1d7f..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/grid/partition/Partition.h +++ /dev/null @@ -1,45 +0,0 @@ -//#ifndef Partition_H -//#define Partition_H -// -//#include "global.h" -// -// -//#include <vector> -//#include <string> -//#include <memory> -// -//class BoundingBox; -//struct Triangle; -//struct Vertex; -//class Grid; -//class Transformator; -// -//class GRIDGENERATOR_EXPORT Partition -//{ -//public: -// static void partitionGridMesh(SPtr<Grid> grid); -// static void partitionGrid(SPtr<Grid> grid); -// -// static std::vector<BoundingBox > getProcessBoxes(const int numberOfProcesses, const int globalNx, const int globalNy, const int globalNz); -// static std::vector<std::vector<int> > partitionBoxes(std::vector<std::vector<BoundingBox> >, int processes, std::vector< std::shared_ptr<Transformator> > transformators); -// -// static std::vector<std::vector<Triangle> > getTrianglesPerProcess(std::vector<BoundingBox> &boxes, Triangle *triangles, int nTriangles); -// -// static std::vector<std::vector<Triangle> > splitTriangles(std::vector<Triangle> &triangleVec, std::vector<BoundingBox> boxes); -// -//private: -// Partition(){}; -// ~Partition(){}; -// -// static int calcEdgesFromGraph(SPtr<Grid> grid); -// -// static void splitAllBoxesInThreePieces(std::vector<BoundingBox> &boxes, bool splitX, bool splitY, bool splitZ); -// static void splitAllBoxesInTwoPieces(std::vector<BoundingBox> &boxes, bool splitX, bool splitY, bool splitZ); -// static void findMaxBoxSize(std::vector<BoundingBox> &boxes, bool &splitX, bool &splitY, bool &splitZ); -// -// static void splitAndPushTriangle(BoundingBox &box, std::vector<Triangle> &trianglesPerProcess, std::vector<Triangle> &triangleVec, int indexTriangle); -// static void sliceTriangle(std::vector<Triangle> &out, std::vector<Triangle>& triangleVec, int index, const Vertex& a, const Vertex& b, const Vertex& c, real d1, real d2, real d3); -// -//}; -// -//#endif diff --git a/src/gpu/GridGenerator/io/GridVTKWriter/GridVTKWriter.cpp b/src/gpu/GridGenerator/io/GridVTKWriter/GridVTKWriter.cpp index 835cdf8d61bfa650eb2fefb003a37e19fb029abb..2c8624732d70e52ac24d843888548bdaf5585686 100644 --- a/src/gpu/GridGenerator/io/GridVTKWriter/GridVTKWriter.cpp +++ b/src/gpu/GridGenerator/io/GridVTKWriter/GridVTKWriter.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 GridVTKWriter.cpp +//! \ingroup io +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #define _CRT_SECURE_NO_DEPRECATE #include "GridVTKWriter.h" @@ -241,74 +273,6 @@ void GridVTKWriter::writeInterpolationCellsToVTKXML(SPtr<Grid> grid, SPtr<Grid> } WbWriterVtkXmlBinary::getInstance()->writeOctsWithCellData(name, nodes, cells, celldatanames, celldata); } -//deprecated -//void GridVTKWriter::writeGridToVTKXML(SPtr<Grid> grid, const std::string& name, WRITING_FORMAT format) -//{ -// std::vector<UbTupleFloat3> nodes; -// std::vector<UbTupleUInt8> cells; -// std::vector<std::string> nodedatanames; -// std::vector< std::vector<double> > nodedata; -// -// nodedatanames.push_back("types"); -// -// -// nodedata.resize(nodedatanames.size()); -// -// CbArray3D<int> nodeNumbers(grid->getNumberOfNodesX(), grid->getNumberOfNodesY(), grid->getNumberOfNodesZ(), -1); -// int nr = 0; -// -// for (real x = grid->getStartX(); x <= grid->getEndX(); x += grid->getDelta()) -// { -// for (real y = grid->getStartY(); y <= grid->getEndY(); y += grid->getDelta()) -// { -// for (real z = grid->getStartZ(); z <= grid->getEndZ(); z += grid->getDelta()) -// { -// const auto xTranslate = int((x - grid->getStartX()) / grid->getDelta()); -// const auto yTranslate = int((y - grid->getStartY()) / grid->getDelta()); -// const auto zTranslate = int((z - grid->getStartZ()) / grid->getDelta()); -// nodeNumbers(xTranslate, yTranslate, zTranslate) = nr++; -// nodes.push_back(UbTupleFloat3(float(x), float(y),float(z))); -// -// const char type = grid->getFieldEntry(grid->transCoordToIndex(x, y, z)); -// nodedata[0].push_back(type); -// } -// } -// } -// -// int SWB, SEB, NEB, NWB, SWT, SET, NET, NWT; -// for (real x = grid->getStartX(); x < grid->getEndX(); x += grid->getDelta()) -// { -// for (real y = grid->getStartY(); y < grid->getEndY(); y += grid->getDelta()) -// { -// for (real z = grid->getStartZ(); z < grid->getEndZ(); z += grid->getDelta()) -// { -// const auto xTranslate = int((x - grid->getStartX()) / grid->getDelta()); -// const auto yTranslate = int((y - grid->getStartY()) / grid->getDelta()); -// const auto zTranslate = int((z - grid->getStartZ()) / grid->getDelta()); -// -// if (!nodeNumbers.indicesInRange(xTranslate + 1, yTranslate +1, zTranslate +1)) // blame Lenz -// continue; -// -// if ((SWB = nodeNumbers(xTranslate, yTranslate, zTranslate)) >= 0 -// && (SEB = nodeNumbers(xTranslate + 1, yTranslate, zTranslate)) >= 0 -// && (NEB = nodeNumbers(xTranslate + 1, yTranslate + 1, zTranslate)) >= 0 -// && (NWB = nodeNumbers(xTranslate, yTranslate + 1, zTranslate)) >= 0 -// && (SWT = nodeNumbers(xTranslate, yTranslate, zTranslate + 1)) >= 0 -// && (SET = nodeNumbers(xTranslate + 1, yTranslate, zTranslate + 1)) >= 0 -// && (NET = nodeNumbers(xTranslate + 1, yTranslate + 1, zTranslate + 1)) >= 0 -// && (NWT = nodeNumbers(xTranslate, yTranslate + 1, zTranslate + 1)) >= 0) -// { -// Cell cell(x, y, z, grid->getDelta()); -// if(grid->nodeInCellIs(cell, OUT_OF_GRID) || grid->nodeInCellIs(cell, INVALID_NODE)) -// continue; -// -// cells.push_back(makeUbTuple(uint(SWB), uint(SEB), uint(NEB), uint(NWB), uint(SWT), uint(SET), uint(NET), uint(NWT))); -// } -// } -// } -// } -// WbWriterVtkXmlBinary::getInstance()->writeOctsWithNodeData(name, nodes, cells, nodedatanames, nodedata); -//} /*#################################################################################*/ diff --git a/src/gpu/GridGenerator/io/GridVTKWriter/GridVTKWriter.h b/src/gpu/GridGenerator/io/GridVTKWriter/GridVTKWriter.h index 43fe611459a2509ddb032cce993b171673fa407f..cf33df096a6e670b65f79831d59927e3d7cea389 100644 --- a/src/gpu/GridGenerator/io/GridVTKWriter/GridVTKWriter.h +++ b/src/gpu/GridGenerator/io/GridVTKWriter/GridVTKWriter.h @@ -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 GridVTKWriter.h +//! \ingroup io +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef GridVTKWriter_h #define GridVTKWriter_h diff --git a/src/gpu/GridGenerator/io/QLineWriter.cpp b/src/gpu/GridGenerator/io/QLineWriter.cpp index 6df995b2d5ef73c7797234a61f78810666f675f0..29894e8d589fb59c1dbf57e08692dddfc03619a1 100644 --- a/src/gpu/GridGenerator/io/QLineWriter.cpp +++ b/src/gpu/GridGenerator/io/QLineWriter.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 QLineWriter.cpp +//! \ingroup io +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "QLineWriter.h" #include <vector> diff --git a/src/gpu/GridGenerator/io/QLineWriter.h b/src/gpu/GridGenerator/io/QLineWriter.h index 01596adbd026404db74d7029218d90171b3b09dc..c7fed1a8ff16e81398e18c7fdde347cd09a93452 100644 --- a/src/gpu/GridGenerator/io/QLineWriter.h +++ b/src/gpu/GridGenerator/io/QLineWriter.h @@ -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 QLineWriter.h +//! \ingroup io +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef QLINEWRITER_H #define QLINEWRITER_H diff --git a/src/gpu/GridGenerator/io/STLReaderWriter/STLReader.cpp b/src/gpu/GridGenerator/io/STLReaderWriter/STLReader.cpp index a1d0fbbd484d705f6f4f1d28a95e9c0e5ff42442..173f79c184c0a455ffd5b27cae59e07fa6dd4fa6 100644 --- a/src/gpu/GridGenerator/io/STLReaderWriter/STLReader.cpp +++ b/src/gpu/GridGenerator/io/STLReaderWriter/STLReader.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 STLReader.cpp +//! \ingroup io +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #define _CRT_SECURE_NO_DEPRECATE #include "STLReader.h" @@ -181,18 +213,17 @@ std::vector<Triangle> STLReader::readBinarySTL(const std::string& name) FILE *file = fopen(name.c_str(), mode.c_str()); char header_info[80] = ""; - auto read_values = fread(header_info, sizeof(char), 80, file); + size_t sizef = fread(header_info, sizeof(char), 80, file); char nTri[4]; - read_values = fread(nTri, sizeof(char), 4, file); + sizef = fread(nTri, sizeof(char), 4, file); unsigned long nTriLong = *((unsigned long*)nTri); *logging::out << logging::Logger::INFO_INTERMEDIATE << "Number of Triangles: " << nTriLong << "\n"; std::vector<Triangle> triangles; char facet[50]; for (unsigned int i = 0; i < nTriLong; i++){ - read_values = fread(facet, sizeof(char), 50, file); - (void) read_values; + sizef = fread(facet, sizeof(char), 50, file); Vertex normal = getVertexFromChar(facet); @@ -202,6 +233,7 @@ std::vector<Triangle> STLReader::readBinarySTL(const std::string& name) triangles.push_back(Triangle(p1, p2, p3, normal)); } + (void)sizef; fclose(file); return triangles; @@ -273,10 +305,10 @@ std::vector<Triangle> STLReader::readBinarySTL(const BoundingBox &box, const std char nTri[4]; unsigned long nTriLong; - auto read_values = fread(header_info, sizeof(char), 80, file); + size_t sizef = fread(header_info, sizeof(char), 80, file); - read_values = fread(nTri, sizeof(char), 4, file); + sizef = fread(nTri, sizeof(char), 4, file); nTriLong = *((unsigned long*)nTri); *logging::out << logging::Logger::INFO_INTERMEDIATE << "Number of Triangles complete geometry: " << nTriLong << "\n"; @@ -284,8 +316,7 @@ std::vector<Triangle> STLReader::readBinarySTL(const BoundingBox &box, const std char facet[50]; for (unsigned int i = 0; i < nTriLong; i++){ - read_values = fread(facet, sizeof(char), 50, file); - (void) read_values; + sizef = fread(facet, sizeof(char), 50, file); Vertex normal = getVertexFromChar(facet); @@ -300,7 +331,7 @@ std::vector<Triangle> STLReader::readBinarySTL(const BoundingBox &box, const std int size = (int)triangles.size(); *logging::out << logging::Logger::INFO_INTERMEDIATE << "Number of Triangles in process: " << size << "\n"; *logging::out << logging::Logger::INFO_INTERMEDIATE << "Complete reading STL file. \n"; - + (void)sizef; fclose(file); return triangles; diff --git a/src/gpu/GridGenerator/io/STLReaderWriter/STLReader.h b/src/gpu/GridGenerator/io/STLReaderWriter/STLReader.h index 3e7beef8c6b0d81c454d2ca6fec5fca5d0d7f6d4..333313727530ae551c76a76984cd63f6cd0f11ce 100644 --- a/src/gpu/GridGenerator/io/STLReaderWriter/STLReader.h +++ b/src/gpu/GridGenerator/io/STLReaderWriter/STLReader.h @@ -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 STLReader.h +//! \ingroup io +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef STLReader_H #define STLReader_H diff --git a/src/gpu/GridGenerator/io/STLReaderWriter/STLWriter.cpp b/src/gpu/GridGenerator/io/STLReaderWriter/STLWriter.cpp index 36e099c61d495f7402c68e581e4c68e194dad6b4..e29320cbd6867e1ae5a65cf41623780cd83aead7 100644 --- a/src/gpu/GridGenerator/io/STLReaderWriter/STLWriter.cpp +++ b/src/gpu/GridGenerator/io/STLReaderWriter/STLWriter.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 STLWriter.cpp +//! \ingroup io +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #define _CRT_SECURE_NO_DEPRECATE #include "STLWriter.h" diff --git a/src/gpu/GridGenerator/io/STLReaderWriter/STLWriter.h b/src/gpu/GridGenerator/io/STLReaderWriter/STLWriter.h index c6185480237cf5a8dab0fc8c9b71044a420fd70c..4ba87fd82e147fd94507d5557a078f5c581c6d07 100644 --- a/src/gpu/GridGenerator/io/STLReaderWriter/STLWriter.h +++ b/src/gpu/GridGenerator/io/STLReaderWriter/STLWriter.h @@ -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 STLWriter.h +//! \ingroup io +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef STLWriter_H #define STLWriter_H diff --git a/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileNames.cpp b/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileNames.cpp index 7cf2412a35ca15ac63ae36ad55dbed58cf9cec5a..34b6b1d3c30b15333afb0afeb5d35d2894e07e52 100644 --- a/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileNames.cpp +++ b/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileNames.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 SimulationFileNames.cpp +//! \ingroup io +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "SimulationFileNames.h" const std::string fileEnding = ".dat"; diff --git a/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileNames.h b/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileNames.h index fdc09047f7037d60df1f3de5c33be57137c06286..4be5b44bd4760764da672239052e17bd406316d3 100644 --- a/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileNames.h +++ b/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileNames.h @@ -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 SimulationFileNames.h +//! \ingroup io +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef SimulationFileNames_H #define SimulationFileNames_H diff --git a/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileWriter.cpp b/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileWriter.cpp index 53ce24344ab430e0a65ada9c78506f4f0440ca8b..320a6e5fb7bb8e52a335722bca71d7d6a2a0c6de 100644 --- a/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileWriter.cpp +++ b/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileWriter.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 SimulationFileWriter.cpp +//! \ingroup io +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #define _CRT_SECURE_NO_DEPRECATE #include "SimulationFileWriter.h" @@ -514,7 +546,7 @@ void SimulationFileWriter::writeBoundaryQsFile(SPtr<GridBuilder> builder) SideType sides[] = {SideType::MX, SideType::PX, SideType::PZ, SideType::MZ, SideType::MY, SideType::PY, SideType::GEOMETRY}; - for (int side = 0; side < QFILES; side++) { + for (uint side = 0; side < QFILES; side++) { for (uint level = 0; level < builder->getNumberOfGridLevels(); level++) { @@ -575,7 +607,7 @@ void SimulationFileWriter::writeBoundaryShort(std::vector<real> boundary, int rb *valueStreams[rb] << "\n"; } -void SimulationFileWriter::writeBoundaryShort(SPtr<Grid> grid, SPtr<BoundaryCondition> boundaryCondition, uint side) +void SimulationFileWriter::writeBoundaryShort(SPtr<Grid> grid, SPtr<gg::BoundaryCondition> boundaryCondition, uint side) { uint numberOfBoundaryNodes = (uint)boundaryCondition->indices.size(); diff --git a/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileWriter.h b/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileWriter.h index eb10c9c107bb8e777e6f9a5d7bb4a57d021266fe..d5d2a377b33697704b86f8b78987fd0af75be415 100644 --- a/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileWriter.h +++ b/src/gpu/GridGenerator/io/SimulationFileWriter/SimulationFileWriter.h @@ -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 SimulationFileWriter.h +//! \ingroup io +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef SimulationFileWriter_H #define SimulationFileWriter_H @@ -15,7 +47,10 @@ class UnstructuredGridBuilder; class GridBuilder; class Grid; +namespace gg +{ class BoundaryCondition; +} enum class FILEFORMAT { @@ -51,7 +86,7 @@ private: static void fillRBForNode(int index, int direction, int directionSign, int rb, std::vector<std::vector<std::vector<real> > > &qs, SPtr<Grid> grid); static void writeBoundary(std::vector<real> boundary, int rb); static void writeBoundaryShort(std::vector<real> boundary, int rb); - static void writeBoundaryShort(SPtr<Grid> grid, SPtr<BoundaryCondition> boundaryCondition, uint side); + static void writeBoundaryShort(SPtr<Grid> grid, SPtr<gg::BoundaryCondition> boundaryCondition, uint side); static void writeCommunicationFiles(SPtr<GridBuilder> builder); diff --git a/src/gpu/GridGenerator/io/VTKWriterWrapper/PolyDataWriterWrapper.cpp b/src/gpu/GridGenerator/io/VTKWriterWrapper/PolyDataWriterWrapper.cpp deleted file mode 100644 index 3ce6742b1615e80e028b10b24870e593a3672819..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/io/VTKWriterWrapper/PolyDataWriterWrapper.cpp +++ /dev/null @@ -1,29 +0,0 @@ -//#include "PolyDataWriterWrapper.h" -// -//#include <VTKWriter/PolyDataWriter/PolyDataWriterImp.h> -// -//#include <GridGenerator/geometries/Arrow/Arrow.h> -//#include <GridGenerator/geometries/Vertex/Vertex.h> -// -// -//PolyDataWriterWrapper::PolyDataWriterWrapper() -//{ -// writer = std::shared_ptr<PolyDataWriter>(new PolyDataWriterImp()); -//} -// -//PolyDataWriterWrapper::~PolyDataWriterWrapper() -//{ -// -//} -// -//void PolyDataWriterWrapper::addVectorArrow(std::shared_ptr<const Arrow> arrow) -//{ -// double startPoint[] = { arrow->getStart()->x, arrow->getStart()->y, arrow->getStart()->z }; -// double endPoint[] = { arrow->getEnd()->x, arrow->getEnd()->y, arrow->getEnd()->z }; -// writer->addVectorArrow(startPoint, endPoint); -//} -// -//void PolyDataWriterWrapper::writePolyDataToFile(const std::string& filename) const -//{ -// writer->writePolyDataToFile(filename); -//} diff --git a/src/gpu/GridGenerator/io/VTKWriterWrapper/PolyDataWriterWrapper.h b/src/gpu/GridGenerator/io/VTKWriterWrapper/PolyDataWriterWrapper.h deleted file mode 100644 index c7b3829d65db5520ee0170897d46c540dedcdb24..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/io/VTKWriterWrapper/PolyDataWriterWrapper.h +++ /dev/null @@ -1,26 +0,0 @@ -//#ifndef PolyDataWriterWrapper_H -//#define PolyDataWriterWrapper_H -// -// -//#include <string> -//#include <memory> -// -//class PolyDataWriter; -//class Arrow; -// -//class PolyDataWriterWrapper -//{ -//public: -// GRIDGENERATOR_EXPORT PolyDataWriterWrapper(); -// GRIDGENERATOR_EXPORT ~PolyDataWriterWrapper(); -// -// GRIDGENERATOR_EXPORT virtual void addVectorArrow(std::shared_ptr<const Arrow> arrow); -// GRIDGENERATOR_EXPORT virtual void writePolyDataToFile(const std::string &filename) const; -// -//private: -// std::shared_ptr<PolyDataWriter> writer; -// -//}; -// -// -//#endif diff --git a/src/gpu/GridGenerator/io/VTKWriterWrapper/UnstructuredGridWrapper.cpp b/src/gpu/GridGenerator/io/VTKWriterWrapper/UnstructuredGridWrapper.cpp deleted file mode 100644 index b2de0057c2aa8effae238b1c1aba1805ec540939..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/io/VTKWriterWrapper/UnstructuredGridWrapper.cpp +++ /dev/null @@ -1,137 +0,0 @@ -//#define _CRT_SECURE_NO_DEPRECATE -//#include "UnstructuredGridWrapper.h" -//#include <iostream> -// -//#include <VTKWriter/UnstructuredGridWriter/UnstructuredGridWriter.h> -// -//#include <GridGenerator/geometries/Triangle/Triangle.h> -//#include <GridGenerator/geometries/Vertex/Vertex.h> -//#include <GridGenerator/geometries/BoundingBox/BoundingBox.h> -//#include <GridGenerator/grid/Grid.cuh> -// -//UnstructuredGridWrapper::UnstructuredGridWrapper() -//{ -//#ifndef __unix__ -// this->writer = new UnstructuredGridWriter(); -//#endif -//} -// -//UnstructuredGridWrapper::~UnstructuredGridWrapper() -//{ -//#ifndef __unix__ -// delete this->writer; -//#endif -//} -// -//void UnstructuredGridWrapper::addBoundingBox(double boundingBox[6], int type) -//{ -//#ifndef __unix__ -// this->writer->addBoundingBox(boundingBox, type); -//#endif -//} -// -//template <typename T> -//void UnstructuredGridWrapper::addBoundingBox(BoundingBox<T> box, int type) -//{ -//#ifndef __unix__ -// double b[6] = {box.minX,box.maxX,box.minY,box.maxY,box.minZ,box.maxZ }; -// this->writer->addBoundingBox(b, type); -//#endif -//} -// -//void UnstructuredGridWrapper::addVoxel(double node[3], double nodeNX[3], double nodeNY[3], double nodeNZ[3], double nodeNYNX[3], double nodeNZNY[3], double nodeNZNX[3], double nodeNZNYNX[3], int nodeTypes[8]) -//{ -//#ifndef __unix__ -// this->writer->addVoxel(node, nodeNX, nodeNY, nodeNZ, nodeNYNX, nodeNZNY, nodeNZNX, nodeNZNYNX, nodeTypes); -//#endif -//} -// -//void UnstructuredGridWrapper::addTriangle(double v1[3], double v2[3], double v3[3], int type[3]) -//{ -//#ifndef __unix__ -// this->writer->addTriangle(v1, v2, v3, type); -//#endif -//} -// -//void UnstructuredGridWrapper::addTriangle(Triangle t, int type[3]) -//{ -//#ifndef __unix__ -// double v1[3] = { t.v1.x, t.v1.y, t.v1.z }; -// double v2[3] = { t.v2.x, t.v2.y, t.v2.z }; -// double v3[3] = { t.v3.x, t.v3.y, t.v3.z }; -// -// this->writer->addTriangle(v1, v2, v3, type); -//#endif -//} -// -//void UnstructuredGridWrapper::addTriangles(std::vector<Triangle> triangles) -//{ -//#ifndef __unix__ -// for (int i = 0; i < triangles.size(); i++) { -// double v1[3] = { triangles[i].v1.x, triangles[i].v1.y, triangles[i].v1.z }; -// double v2[3] = { triangles[i].v2.x, triangles[i].v2.y, triangles[i].v2.z }; -// double v3[3] = { triangles[i].v3.x, triangles[i].v3.y, triangles[i].v3.z }; -// -// this->writer->addTriangle(v1, v2, v3, 0); -// } -//#endif -//} -// -//void UnstructuredGridWrapper::addGridPoints(double grid[], int nx, int ny, int nz) -//{ -//#ifndef __unix__ -// this->writer->addGridPoints(grid, nx, ny, nz); -//#endif -//} -// -//void UnstructuredGridWrapper::addGridPoint(int x, int y, int z, int type) -//{ -//#ifndef __unix__ -// this->writer->addGridPoint(x, y, z, type); -//#endif -//} -// -//void UnstructuredGridWrapper::addGridPoint(Vertex v, int type) -//{ -//#ifndef __unix__ -// this->writer->addGridPoint((int)v.x, (int)v.y, (int)v.z, type); -//#endif -//} -// -//void UnstructuredGridWrapper::writeUnstructuredGridToFile(std::string filename) -//{ -//#ifndef __unix__ -// std::string path = PATH_TO_DATA; -// filename = path + filename; -// this->writer->writeUnstructuredGridToFile(filename); -//#endif -//} -// -//void UnstructuredGridWrapper::displayUnstructuredGrid() -//{ -//#ifndef __unix__ -// this->writer->displayUnstructuredGrid(); -//#endif -//} -// -//void UnstructuredGridWrapper::displayUnstructuredGrid(std::string filename) -//{ -//#ifndef __unix__ -// std::string path = PATH_TO_DATA; -// filename = path + filename; -// this->writer->displayUnstructuredGrid(filename); -//#endif -//} -//template <typename T> -//void UnstructuredGridWrapper::writeBoxesToFile(std::vector<BoundingBox<T>> boxes, std::string name) -//{ -//#ifndef __unix__ -// UnstructuredGridWrapper writer; -// for (int i = 0; i < boxes.size(); i++) { -// writer.addBoundingBox(boxes[i], 0); -// } -// writer.writeUnstructuredGridToFile(name); -//#endif -//} -// -//template void UnstructuredGridWrapper::addBoundingBox(BoundingBox b, int type); diff --git a/src/gpu/GridGenerator/io/VTKWriterWrapper/UnstructuredGridWrapper.h b/src/gpu/GridGenerator/io/VTKWriterWrapper/UnstructuredGridWrapper.h deleted file mode 100644 index 6e13ba9ddfcb2ccce633f700ad04e0ec27642f4f..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/io/VTKWriterWrapper/UnstructuredGridWrapper.h +++ /dev/null @@ -1,53 +0,0 @@ -//#ifndef UnstructuredGridWrapper_H -//#define UnstructuredGridWrapper_H -// -// -//#include <string> -//#include <vector> -// -//class UnstructuredGridWriter; -//struct Triangle; -// -//template <class T> -//class BoundingBox; -//struct Vertex; -//class Grid; -// -//class GRIDGENERATOR_EXPORT UnstructuredGridWrapper -//{ -//public: -// UnstructuredGridWrapper(); -// ~UnstructuredGridWrapper(); -// -// void addBoundingBox(double boundingBox[6], int type); -// template <typename T> -// void addBoundingBox(BoundingBox<T> b, int type); -// void addVoxel(double node[3], double nodeNX[3], double nodeNY[3], double nodeNZ[3], -// double nodeNYNX[3], double nodeNZNY[3], double nodeNZNX[3], double nodeNZNYNX[3], int nodeTypes[8]); -// -// void addTriangle(double v1[3], double v2[3], double v3[3], int type[3]); -// void addTriangle(Triangle t, int type[3]); -// void addTriangles(std::vector<Triangle> triangles); -// -// void addGridPoints(double grid[], int nx, int ny, int nz); -// -// void addGridPoint(int x, int y, int z, int type); -// void addGridPoint(Vertex v, int type); -// -// void writeUnstructuredGridToFile(std::string filename); -// -// void displayUnstructuredGrid(); -// void displayUnstructuredGrid(std::string filename); -// -// template <typename T> -// static void writeBoxesToFile(std::vector<BoundingBox<T>>, std::string name); -// -//private: -//#ifndef __unix__ -// UnstructuredGridWriter *writer; -//#endif -// -//}; -// -// -//#endif diff --git a/src/gpu/GridGenerator/utilities/communication.h b/src/gpu/GridGenerator/utilities/communication.h index 23dbd0832cd17a0a22ac8bf6f58965bd9d6199c9..11a1085f6a21db1dfb26025514d8b3a9501fba5e 100644 --- a/src/gpu/GridGenerator/utilities/communication.h +++ b/src/gpu/GridGenerator/utilities/communication.h @@ -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 Communication.h +//! \ingroup utilities +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef Communication_H #define Communication_H diff --git a/src/gpu/GridGenerator/utilities/cuda/CudaErrorCheck.cu b/src/gpu/GridGenerator/utilities/cuda/CudaErrorCheck.cu deleted file mode 100644 index 1d06e178332933a1dd88b1de7095de36601cd5ab..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/utilities/cuda/CudaErrorCheck.cu +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef CudaErrorCheck_cu -#define CudaErrorCheck_cu - - -#include "cuda.h" -#include "cuda_runtime.h" -#include "device_launch_parameters.h" -#include <stdio.h> - -#define CUDA_ERROR_CHECK - -#define CudaSafeCall( err ) __cudaSafeCall( err, __FILE__, __LINE__ ) -#define CudaCheckError() __cudaCheckError( __FILE__, __LINE__ ) - -inline void __cudaSafeCall(cudaError err, const char *file, const int line) -{ -#ifdef CUDA_ERROR_CHECK - if (cudaSuccess != err) - { - fprintf(stderr, "cudaSafeCall() failed at %s:%i : %s\n", - file, line, cudaGetErrorString(err)); - exit(-1); - } -#endif - - return; -} - -inline void __cudaCheckError(const char *file, const int line) -{ -#ifdef CUDA_ERROR_CHECK - cudaError err = cudaGetLastError(); - if (cudaSuccess != err) - { - fprintf(stderr, "cudaCheckError() failed at %s\nline:%i : %s\n", - file, line, cudaGetErrorString(err)); - fprintf(stderr, "CudaError: %d\n", err); - exit(-1); - } - - // More careful checking. However, this will affect performance. - // Comment away if needed. - err = cudaDeviceSynchronize(); - if (cudaSuccess != err) - { - fprintf(stderr, "cudaCheckError() with sync failed at %s:%i : %s\n", - file, line, cudaGetErrorString(err)); - exit(-1); - } -#endif - - return; -} - -#endif diff --git a/src/gpu/GridGenerator/utilities/cuda/LaunchParameter.cu b/src/gpu/GridGenerator/utilities/cuda/LaunchParameter.cu deleted file mode 100644 index 8e7702ccde425f67a9755e4eebff82f63238ba11..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/utilities/cuda/LaunchParameter.cu +++ /dev/null @@ -1,50 +0,0 @@ -#include "LaunchParameter.cuh" - -#define MAXBLOCKSIZE 65535 - -CUDA_HOST LaunchParameter::LaunchParameter() -{ - -} - -CUDA_HOST LaunchParameter LaunchParameter::make_2D1D_launchParameter(int size, int threadDim) -{ - LaunchParameter para; - para.threads = dim3(threadDim, 1, 1); - - int blocks_ = (int)(ceil((size / ((real)threadDim)))); - para.blocks = dim3(blocks_, 1, 1); - - if (blocks_ > MAXBLOCKSIZE) { - blocks_ = (int)sqrt((double)blocks_); - para.blocks = dim3(blocks_, blocks_, 1); - } - return para; -} - -CUDA_HOST LaunchParameter LaunchParameter::make_1D1D_launchParameter(int size, int threadDim) -{ - LaunchParameter para; - para.threads = dim3(threadDim, 1, 1); - int blocks_ = (int)(ceil((real)size / (real)threadDim)); - para.blocks = dim3(blocks_, 1); - return para; -} - -DEVICE int LaunchParameter::getGlobalIdx_2D_1D() -{ - int blockId = blockIdx.y * gridDim.x + blockIdx.x; - int threadId = blockId * blockDim.x + threadIdx.x; - return threadId; -} - -DEVICE int LaunchParameter::getGlobalIdx_1D_1D() -{ - return blockIdx.x *blockDim.x + threadIdx.x; -} - -CUDA_HOST void LaunchParameter::print() const -{ - *logging::out << logging::Logger::INFO_INTERMEDIATE << "blocks: (" << blocks.x << ", " << blocks.y << ", " << blocks.z << ")" - << ", threads: (" << threads.x << ", " << threads.y << ", " << threads.z << ")\n"; -} diff --git a/src/gpu/GridGenerator/utilities/cuda/LaunchParameter.cuh b/src/gpu/GridGenerator/utilities/cuda/LaunchParameter.cuh deleted file mode 100644 index 20406fdb5f048d65a73dd55eec2dd3b31b11a76c..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/utilities/cuda/LaunchParameter.cuh +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef kernelHelper_CUH -#define kernelHelper_CUH - -#include <cuda.h> -#include <cuda_runtime.h> -#include <device_launch_parameters.h> -#include <stdio.h> - -#include "global.h" - -class LaunchParameter -{ -public: - CUDA_HOST GRIDGENERATOR_EXPORT LaunchParameter(); - - CUDA_HOST GRIDGENERATOR_EXPORT static LaunchParameter make_2D1D_launchParameter(int size, int threadDim); - CUDA_HOST GRIDGENERATOR_EXPORT static LaunchParameter make_1D1D_launchParameter(int size, int threadDim); - - DEVICE static int getGlobalIdx_2D_1D(); - DEVICE static int getGlobalIdx_1D_1D(); - - CUDA_HOST void print() const; - - dim3 threads; - dim3 blocks; -}; - - -#endif diff --git a/src/gpu/GridGenerator/utilities/cuda/cudaDefines.h b/src/gpu/GridGenerator/utilities/cuda/cudaDefines.h deleted file mode 100644 index b20401ef493c16d413f41db91c42c102e63d7d2f..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/utilities/cuda/cudaDefines.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef CUDA_DEFINES_H -#define CUDA_DEFINES_H - -#include <cuda_runtime.h> -#include <stdio.h> - -#define CUDA_HOST __host__ -#define DEVICE __device__ -#define GLOBAL __global__ -#define CONSTANT __constant__ - - -#define HOSTDEVICE CUDA_HOST DEVICE - -static void printCudaInformation(int i) { - cudaDeviceProp prop; - cudaGetDeviceProperties(&prop, i); - printf(" --- General Information for device %d ---\n", i); - printf("Name: %s\n", prop.name); - printf("Compute capability: %d.%d\n", prop.major, prop.minor); - printf("Clock rate: %d\n", prop.clockRate); - printf("Device copy overlap: "); - if (prop.deviceOverlap) - printf("Enabled\n"); - else - printf("Disabled\n"); - printf("Kernel execition timeout : "); - if (prop.kernelExecTimeoutEnabled) - printf("Enabled\n"); - else - printf("Disabled\n"); - printf(" --- Memory Information for device %d ---\n", i); - printf("Total global mem: %zu\n", prop.totalGlobalMem); - printf("Total constant Mem: %zu\n", prop.totalConstMem); - printf("Max mem pitch: %zu\n", prop.memPitch); - printf("Texture Alignment: %zu\n", prop.textureAlignment); - printf("max Texture 1D: %d\n", prop.maxTexture1D); - printf("max Texture 2D: %d, %d\n", prop.maxTexture2D[0], prop.maxTexture2D[1]); - printf("max Texture 3D: %d, %d, %d\n", prop.maxTexture3D[0], prop.maxTexture3D[1], prop.maxTexture3D[2]); - printf(" --- MP Information for device %d ---\n", i); - printf("Multiprocessor count: %d\n", - prop.multiProcessorCount); - printf("Shared mem per mp: %zd\n", prop.sharedMemPerBlock); - printf("Registers per mp: %d\n", prop.regsPerBlock); - printf("Threads in warp: %d\n", prop.warpSize); - printf("Max threads per block: %d\n", - prop.maxThreadsPerBlock); - printf("Max thread dimensions: (%d, %d, %d)\n", - prop.maxThreadsDim[0], prop.maxThreadsDim[1], - prop.maxThreadsDim[2]); - printf("Max grid dimensions: (%d, %d, %d)\n", - prop.maxGridSize[0], prop.maxGridSize[1], - prop.maxGridSize[2]); - printf(" --- -------------------------------- ---\n"); - printf("\n"); - - cudaSetDevice(i); - size_t free; - size_t total; - cudaMemGetInfo(&free, &total); - printf("Free: %zu Bytes, Total: %zu Bytes\n", free, total); - printf("Free: %zu MB, Total: %zu MB\n", free / 1000 / 1000, total / 1000 / 1000); - //cudaDeviceSetLimit(cudaLimitMallocHeapSize, free); -} - -#endif diff --git a/src/gpu/GridGenerator/utilities/cuda/cudaKernelCall.h b/src/gpu/GridGenerator/utilities/cuda/cudaKernelCall.h deleted file mode 100644 index 5911977428cda9acd5e2190a4b5c1579e08a211f..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/utilities/cuda/cudaKernelCall.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef cudaKernelCall_H -#define cudaKernelCall_H - -#include "utilities/cuda/cudaDefines.h" -#include "utilities/cuda/CudaErrorCheck.cu" -#include "utilities/cuda/LaunchParameter.cuh" - -template<typename Functor, typename... TArgs> -CUDA_HOST float runKernel(Functor kernel, const LaunchParameter& para, TArgs... args) -{ - para.print(); - - cudaEvent_t start, stop; - cudaEventCreate(&start); - cudaEventCreate(&stop); - - cudaEventRecord(start, 0); - kernel << < para.blocks, para.threads >> >(args...); - CudaCheckError(); - cudaDeviceSynchronize(); - cudaEventRecord(stop, 0); - - cudaEventSynchronize(stop); - float elapsedTime; - cudaEventElapsedTime(&elapsedTime, start, stop); - cudaEventDestroy(start); - cudaEventDestroy(stop); - - return elapsedTime; -} - - -#endif diff --git a/src/gpu/GridGenerator/utilities/math/Math.cpp b/src/gpu/GridGenerator/utilities/math/Math.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0f5f5cc8e05c9ce08a2854c0354371e18964610e --- /dev/null +++ b/src/gpu/GridGenerator/utilities/math/Math.cpp @@ -0,0 +1,83 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// 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 Math.cpp +//! \ingroup utilities +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= +#include "Math.h" + +#include <cmath> + + + +bool vf::Math::equal(const real& val1, const real& val2, real maxRelDiff) +{ + const real diff = std::fabs(val1 - val2); + const real val1_abs = std::fabs(val1); + const real val2_abs = std::fabs(val2); + + const real largest = (val2_abs > val1_abs) ? val2_abs : val1_abs; + if (diff <= largest * maxRelDiff) + return true; + return false; +} + +bool vf::Math::lessEqual(const real& val1, const real& val2, real maxRelDiff) +{ + if (val1 < val2 || equal(val1, val2, maxRelDiff)) + return true; + return false; +} + +bool vf::Math::greaterEqual(const real& val1, const real& val2, real maxRelDiff) +{ + if (val1 > val2 || equal(val1, val2, maxRelDiff)) + return true; + return false; +} + +real vf::Math::sqrtReal(const real& val) +{ +#ifdef VF_DOUBLE_ACCURACY + return sqrt(val); +#else + return sqrtf(val); +#endif +} + +real vf::Math::acosReal(const real& val) +{ +#ifdef VF_DOUBLE_ACCURACY + return acos(val); +#else + return acosf(val); +#endif +} + + diff --git a/src/gpu/GridGenerator/utilities/math/Math.cu b/src/gpu/GridGenerator/utilities/math/Math.cu deleted file mode 100644 index ef05bf52b5535682b65261d377f7efdb02af59e3..0000000000000000000000000000000000000000 --- a/src/gpu/GridGenerator/utilities/math/Math.cu +++ /dev/null @@ -1,51 +0,0 @@ -#include "Math.h" - -#include <cmath> - - - -HOSTDEVICE bool vf::Math::equal(const real& val1, const real& val2, real maxRelDiff) -{ - const real diff = std::fabs(val1 - val2); - const real val1_abs = std::fabs(val1); - const real val2_abs = std::fabs(val2); - - const real largest = (val2_abs > val1_abs) ? val2_abs : val1_abs; - if (diff <= largest * maxRelDiff) - return true; - return false; -} - -HOSTDEVICE bool vf::Math::lessEqual(const real& val1, const real& val2, real maxRelDiff) -{ - if (val1 < val2 || equal(val1, val2, maxRelDiff)) - return true; - return false; -} - -HOSTDEVICE bool vf::Math::greaterEqual(const real& val1, const real& val2, real maxRelDiff) -{ - if (val1 > val2 || equal(val1, val2, maxRelDiff)) - return true; - return false; -} - -HOSTDEVICE real vf::Math::sqrtReal(const real& val) -{ -#ifdef VF_DOUBLE_ACCURACY - return sqrt(val); -#else - return sqrtf(val); -#endif -} - -HOSTDEVICE real vf::Math::acosReal(const real& val) -{ -#ifdef VF_DOUBLE_ACCURACY - return acos(val); -#else - return acosf(val); -#endif -} - - diff --git a/src/gpu/GridGenerator/utilities/math/Math.h b/src/gpu/GridGenerator/utilities/math/Math.h index b47f03b07fbcd04cbd2e5337882aa197e33ca7b5..95b01e77561c8e9965ed64604395eda8ef4cc2f1 100644 --- a/src/gpu/GridGenerator/utilities/math/Math.h +++ b/src/gpu/GridGenerator/utilities/math/Math.h @@ -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 Math.h +//! \ingroup utilities +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef CudaMath_H #define CudaMath_H @@ -5,8 +37,6 @@ #include "global.h" -#include "utilities/cuda/cudaDefines.h" - #define EPSILON FLT_EPSILON namespace vf @@ -14,14 +44,14 @@ namespace vf class GRIDGENERATOR_EXPORT Math { public: - HOSTDEVICE static bool equal(const real& val1, const real& val2, real maxRelDiff = EPSILON); - HOSTDEVICE static bool lessEqual(const real& val1, const real& val2, real maxRelDiff = EPSILON); - HOSTDEVICE static bool greaterEqual(const real& val1, const real& val2, real maxRelDiff = EPSILON); + static bool equal(const real& val1, const real& val2, real maxRelDiff = EPSILON); + static bool lessEqual(const real& val1, const real& val2, real maxRelDiff = EPSILON); + static bool greaterEqual(const real& val1, const real& val2, real maxRelDiff = EPSILON); - HOSTDEVICE static real sqrtReal(const real& val); - HOSTDEVICE static real acosReal(const real& val); + static real sqrtReal(const real& val); + static real acosReal(const real& val); - HOSTDEVICE static real getDecimalPart(real number) { + static real getDecimalPart(real number) { return number - real(int(number)); } }; diff --git a/src/gpu/GridGenerator/utilities/transformator/ArrowTransformator.cpp b/src/gpu/GridGenerator/utilities/transformator/ArrowTransformator.cpp index 7ec055c5973b1edbdd93cf912cfc17f44ab923ea..74a33c31b4b87edd736e9beea783075906772829 100644 --- a/src/gpu/GridGenerator/utilities/transformator/ArrowTransformator.cpp +++ b/src/gpu/GridGenerator/utilities/transformator/ArrowTransformator.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 ArrowTransformator.h +//! \ingroup utilities +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "ArrowTransformator.h" #include "utilities/transformator/TransformatorImp.h" diff --git a/src/gpu/GridGenerator/utilities/transformator/ArrowTransformator.h b/src/gpu/GridGenerator/utilities/transformator/ArrowTransformator.h index 186b66838c3aa7398a7fc8a494c3f41372c30727..ad80114945c9e9be4cc38afa46c493edc1c55b66 100644 --- a/src/gpu/GridGenerator/utilities/transformator/ArrowTransformator.h +++ b/src/gpu/GridGenerator/utilities/transformator/ArrowTransformator.h @@ -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 ArrowTransformator.h +//! \ingroup utilities +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef ArrowTransformator_h #define ArrowTransformator_h diff --git a/src/gpu/GridGenerator/utilities/transformator/Transformator.cpp b/src/gpu/GridGenerator/utilities/transformator/Transformator.cpp index 4f59dc64856ac2e1023363ff6b6a1d1063893fe8..7e854c4baa21bb6d59834b2e099c5857389fd50c 100644 --- a/src/gpu/GridGenerator/utilities/transformator/Transformator.cpp +++ b/src/gpu/GridGenerator/utilities/transformator/Transformator.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 Transformator.cpp +//! \ingroup utilities +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "Transformator.h" #include "utilities/transformator/TransformatorImp.h" diff --git a/src/gpu/GridGenerator/utilities/transformator/Transformator.h b/src/gpu/GridGenerator/utilities/transformator/Transformator.h index 0f092ddb90ce0ea60aed6b17edc415596669422c..9510e818f3467bc4346fc9e8ece58a83c139e11d 100644 --- a/src/gpu/GridGenerator/utilities/transformator/Transformator.h +++ b/src/gpu/GridGenerator/utilities/transformator/Transformator.h @@ -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 Transformator.h +//! \ingroup utilities +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef Transformator_h #define Transformator_h diff --git a/src/gpu/GridGenerator/utilities/transformator/TransformatorImp.cpp b/src/gpu/GridGenerator/utilities/transformator/TransformatorImp.cpp index 224dda4971cac288e9f354b772d42100c5cf4284..3c7a3b675104eabab89c59d481797ff41b2033c8 100644 --- a/src/gpu/GridGenerator/utilities/transformator/TransformatorImp.cpp +++ b/src/gpu/GridGenerator/utilities/transformator/TransformatorImp.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 TransformatorImp.cpp +//! \ingroup utilities +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #include "TransformatorImp.h" #include <memory> diff --git a/src/gpu/GridGenerator/utilities/transformator/TransformatorImp.h b/src/gpu/GridGenerator/utilities/transformator/TransformatorImp.h index 626abacaf1c75c406c7f8fbe830f86fa0d679adf..81ba5a25badc879aa501256ed67eed0a4b39961c 100644 --- a/src/gpu/GridGenerator/utilities/transformator/TransformatorImp.h +++ b/src/gpu/GridGenerator/utilities/transformator/TransformatorImp.h @@ -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 TransformatorImp.h +//! \ingroup utilities +//! \author Soeren Peters, Stephan Lenz +//======================================================================================= #ifndef TransformatorImp_h #define TransformatorImp_h diff --git a/src/gpu/VirtualFluids_GPU/LBM/Simulation.cpp b/src/gpu/VirtualFluids_GPU/LBM/Simulation.cpp index 275e5e51ba0eb6a8fc6e502b70281953121db22a..5080c137d4b1a9354c10bbafd7c6b133881f1641 100644 --- a/src/gpu/VirtualFluids_GPU/LBM/Simulation.cpp +++ b/src/gpu/VirtualFluids_GPU/LBM/Simulation.cpp @@ -568,7 +568,7 @@ void Simulation::run() { MeasurePointWriter::writeMeasurePoints(para.get(), lev, j, t); } - MeasurePointWriter::calcAndWriteMeanAndFluctuations(para.get(), lev, t, para->getTStartOut()); + //MeasurePointWriter::calcAndWriteMeanAndFluctuations(para.get(), lev, t, para->getTStartOut()); } t_MP = 0; } diff --git a/src/lbm/CMakeLists.txt b/src/lbm/CMakeLists.txt index 6e9f76793825ccf4e4e9e921e9fd4b6ab3584707..56b03bded71b83d112d994959db0ba1d6245dc63 100644 --- a/src/lbm/CMakeLists.txt +++ b/src/lbm/CMakeLists.txt @@ -1,10 +1,12 @@ -project(lbm LANGUAGES CXX) +if(BUILD_VF_CPU) + project(lbm LANGUAGES CXX) -vf_add_library(NAME lbm PUBLIC_LINK basics) + vf_add_library(NAME lbm PUBLIC_LINK basics) + target_link_libraries(lbm PRIVATE project_warnings) + + vf_add_tests() +endif() if(BUILD_VF_GPU) add_subdirectory(cuda) endif() - - -vf_add_tests() diff --git a/src/lbm/cuda/CMakeLists.txt b/src/lbm/cuda/CMakeLists.txt index be16988a480650cbab416652655af9766bcf8ec7..3a88d91648b960915279fc4f133f6b60047149bf 100644 --- a/src/lbm/cuda/CMakeLists.txt +++ b/src/lbm/cuda/CMakeLists.txt @@ -6,7 +6,7 @@ vf_add_library(NAME lbmCuda BUILDTYPE static PUBLIC_LINK basics FOLDER ../../lbm set_target_properties(lbmCuda PROPERTIES CUDA_SEPARABLE_COMPILATION ON) -set_source_files_properties(../KernelParameter.cpp PROPERTIES LANGUAGE CUDA) +set_source_files_properties(../KernelParameter.cpp PROPERTIES LANGUAGE CUDA) set_source_files_properties(../CumulantChimera.cpp PROPERTIES LANGUAGE CUDA) -set_source_files_properties(../BGK.cpp PROPERTIES LANGUAGE CUDA) \ No newline at end of file +set_source_files_properties(../BGK.cpp PROPERTIES LANGUAGE CUDA) diff --git a/src/logger/CMakeLists.txt b/src/logger/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..4c6c5294241eb5f3587e126003e7f669592905fa --- /dev/null +++ b/src/logger/CMakeLists.txt @@ -0,0 +1,2 @@ + +vf_add_library(NAME logger PUBLIC_LINK spdlog) diff --git a/src/logger/Logger.cpp b/src/logger/Logger.cpp new file mode 100644 index 0000000000000000000000000000000000000000..708e359c8430380dd57c404ed9b3c41f53dcb714 --- /dev/null +++ b/src/logger/Logger.cpp @@ -0,0 +1,54 @@ +#include "Logger.h" + +#include <spdlog/spdlog.h> +#include <spdlog/sinks/stdout_color_sinks.h> +#include <spdlog/sinks/daily_file_sink.h> +#include <spdlog/sinks/basic_file_sink.h> + +namespace vf::logging +{ + + std::string Logger::logPath = {"logs/"}; + + void Logger::initalizeLogger() + { + updateDefaultLogger(); + + // setting default log level to trace + // levels: trace < debug < info < warn < error < critical + spdlog::set_level(spdlog::level::trace); + + // setting the log pattern + // formatting is documented here: https://github.com/gabime/spdlog/wiki/3.-Custom-formatting + spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%^%l%$] %v"); + + // according to the flush policy https://github.com/gabime/spdlog/wiki/7.-Flush-policy + spdlog::flush_on(spdlog::level::info); + } + + + void Logger::changeLogPath(const std::string& path) + { + logPath = path; + + updateDefaultLogger(); + } + + + void Logger::updateDefaultLogger() + { + // initialize stdout sink with colored output + auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>(); + + // initialize daily file sink + // files will be written into "logs" folder relative to pwd. A new files is created at 0:00 o'clock. + auto daily_file_sink = std::make_shared<spdlog::sinks::daily_file_sink_mt>(logPath + "daily.txt", 0, 0); + + // initialize last run file sink + auto last_run_file_sink = std::make_shared<spdlog::sinks::basic_file_sink_mt>(logPath + "last_run.txt", true); + + // creating default logger with console and file sink + spdlog::set_default_logger(std::make_shared<spdlog::logger>("default", spdlog::sinks_init_list({console_sink, daily_file_sink, last_run_file_sink}))); + } + +} diff --git a/src/logger/Logger.h b/src/logger/Logger.h new file mode 100644 index 0000000000000000000000000000000000000000..594decaf5bd85913335e6d1659b6d89cad6d0610 --- /dev/null +++ b/src/logger/Logger.h @@ -0,0 +1,73 @@ +//======================================================================================= +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ +// \ | | | | |_____ | \_/ | | | | |_/ / _____ | +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// +// 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/>. +// +//! \author Soeren Peters +//======================================================================================= +#ifndef VF_LOGGER_H +#define VF_LOGGER_H + +// VirtualFluids is using the spdlog logger https://github.com/gabime/spdlog +#include <spdlog/spdlog.h> +// To initialize spdlog initalizeLogger() must be called. +// spdlog supports 5 log level, which can be changed at runtime e.g.: +// spdlog::set_level(spdlog::level::debug) +// The default log level is set to trace. Supported levels: trace < debug < info < warning < critical +// +// The logging is realized in 3 different log sinks: +// 1. colorded console output +// 2. a daily log file +// 3. a log file from the last run of VirtualFluids +// The default file path is relativ to executed command logs/ +// File path can be changed via changeLogPath() + +#define VF_LOG_TRACE(...) spdlog::trace(__VA_ARGS__) +#define VF_LOG_DEBUG(...) spdlog::debug(__VA_ARGS__) +#define VF_LOG_INFO(...) spdlog::info(__VA_ARGS__) +#define VF_LOG_WARNING(...) spdlog::warning(__VA_ARGS__) +#define VF_LOG_CRITICAL(...) spdlog::critical(__VA_ARGS__) + + +namespace vf::logging +{ + class Logger + { + public: + // initalizing the above named logger + static void initalizeLogger(); + + // changing the path of the log files + static void changeLogPath(const std::string& path); + + private: + static void updateDefaultLogger(); + + static std::string logPath; + }; +} + +#endif