diff --git a/CMake/CMakeSetCompilerFlags.cmake b/CMake/CMakeSetCompilerFlags.cmake index 2ea8c0b2faf0a398681e32232aa7d247b511c72c..26eeca2a08436c910d1b936b665ef471ed3e557b 100644 --- a/CMake/CMakeSetCompilerFlags.cmake +++ b/CMake/CMakeSetCompilerFlags.cmake @@ -47,7 +47,7 @@ endmacro() ################################################################ ### ADD_COMPILER_FLAGS_TO_PROJECT ### ################################################################ -function(addAdditionalFlags project_name) +function(addAdditionalFlags library_name) status_lib("additional compiler flags CXX: ${CS_COMPILER_FLAGS_CXX}") status_lib("additional compiler flags CXX debug: ${CS_COMPILER_FLAGS_CXX_DEBUG}") @@ -67,18 +67,18 @@ function(addAdditionalFlags project_name) # compile options foreach(flag IN LISTS CS_COMPILER_FLAGS_CXX) - target_compile_options(${project_name} PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${flag}>") + target_compile_options(${library_name} PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${flag}>") if(MSVC) - target_compile_options(${project_name} PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=${flag}>") + target_compile_options(${library_name} PRIVATE "$<$<COMPILE_LANGUAGE:CUDA>:-Xcompiler=${flag}>") endif() endforeach() foreach(flag IN LISTS CS_COMPILER_FLAGS_CXX_DEBUG) - target_compile_options(${project_name} PRIVATE "$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CONFIG:DEBUG>>:${flag}>") + target_compile_options(${library_name} PRIVATE "$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CONFIG:DEBUG>>:${flag}>") endforeach() foreach(flag IN LISTS CS_COMPILER_FLAGS_CXX_RELEASE) - target_compile_options(${project_name} PRIVATE "$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CONFIG:RELEASE>>:${flag}>") + target_compile_options(${library_name} PRIVATE "$<$<AND:$<COMPILE_LANGUAGE:CXX>,$<CONFIG:RELEASE>>:${flag}>") endforeach() endfunction() \ No newline at end of file diff --git a/CMake/VirtualFluidsMacros.cmake b/CMake/VirtualFluidsMacros.cmake index debb5ee7826d7dc3d6499b3813070dcab4b94bd4..62388cdf333aac80464e49af0edd4facdfceb6de 100644 --- a/CMake/VirtualFluidsMacros.cmake +++ b/CMake/VirtualFluidsMacros.cmake @@ -80,7 +80,7 @@ endfunction() ################################################################################# function (vf_get_library_test_name library_test_name) vf_get_library_name (folder_name) - set (${library_test_name} ${library_name}Tests PARENT_SCOPE) + set (${library_test_name} ${folder_name}Tests PARENT_SCOPE) endfunction() @@ -103,11 +103,11 @@ endfunction() function(vf_add_library) set( options ) - set( oneValueArgs ) - set( multiValueArgs NAME BUILDTYPE PUBLIC_LINK PRIVATE_LINK FILES FOLDER EXCLUDE) + set( oneValueArgs NAME BUILDTYPE) + set( multiValueArgs PUBLIC_LINK PRIVATE_LINK FILES FOLDER EXCLUDE) cmake_parse_arguments( ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) - if(${ARG_NAME}) + if(DEFINED ARG_NAME) set(library_name ${ARG_NAME}) else() vf_get_library_name (library_name) diff --git a/CMakeLists.txt b/CMakeLists.txt index ce961049d2817e54df68b9612110300f3cbca3c3..d3e51f8dc4285ca3db7c524fc4600579f1f8fba7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,7 @@ find_package(MPI REQUIRED) add_subdirectory(src/basics) add_subdirectory(src/lbm) +add_subdirectory(src/lbmApp) ################################################################################# # VIRTUAL FLUIDS CPU / GPU diff --git a/apps/cpu/sphere/CMakeLists.txt b/apps/cpu/sphere/CMakeLists.txt index d80737cdd94aa0b912a62acd69dcd30372f6fd82..8346e80d26800582c37090b208e846737e087d5d 100644 --- a/apps/cpu/sphere/CMakeLists.txt +++ b/apps/cpu/sphere/CMakeLists.txt @@ -1,6 +1,6 @@ ######################################################## ## C++ PROJECT ### ######################################################## -PROJECT(sphere) +PROJECT(sphere LANGUAGES CXX) vf_add_library(BUILDTYPE binary PRIVATE_LINK VirtualFluidsCore basics ${MPI_CXX_LIBRARIES} FILES sphere.cpp ) \ No newline at end of file diff --git a/src/cpu/VirtualFluidsCore/CMakeLists.txt b/src/cpu/VirtualFluidsCore/CMakeLists.txt index 6b1eb2af2d7867f48ce39a2d7290743da48bafce..36ac278fb8aee484d38a09a3fd4499965875f712 100644 --- a/src/cpu/VirtualFluidsCore/CMakeLists.txt +++ b/src/cpu/VirtualFluidsCore/CMakeLists.txt @@ -25,7 +25,7 @@ if(BUILD_USE_OPENMP) list(APPEND VF_LIBRARIES OpenMP::OpenMP_CXX) endif() -vf_add_library(BUILDTYPE static PUBLIC_LINK basics muparser MPI::MPI_CXX ${VF_LIBRARIES} lbm) +vf_add_library(BUILDTYPE static PUBLIC_LINK basics muparser MPI::MPI_CXX ${VF_LIBRARIES} PRIVATE_LINK lbm) vf_get_library_name(library_name) diff --git a/src/cpu/VirtualFluidsCore/LBM/D3Q27System.cpp b/src/cpu/VirtualFluidsCore/LBM/D3Q27System.cpp index 5e88242fa23bdf37386f4f4d293ed7c2c33750ee..616bc1ea318181dabe27e8641ef1075c279e54fa 100644 --- a/src/cpu/VirtualFluidsCore/LBM/D3Q27System.cpp +++ b/src/cpu/VirtualFluidsCore/LBM/D3Q27System.cpp @@ -1,5 +1,7 @@ #include "D3Q27System.h" +#include "lbm/CalcMac.h" + namespace D3Q27System { using namespace UbMath; @@ -18,4 +20,31 @@ const int INVDIR[] = { INV_E, INV_W, INV_N, INV_S, INV_T, INV_B, INV INV_NW, INV_TE, INV_BW, INV_BE, INV_TW, INV_TN, INV_BS, INV_BN, INV_TS, INV_TNE, INV_TNW, INV_TSE, INV_TSW, INV_BNE, INV_BNW, INV_BSE, INV_BSW }; + + + +LBMReal getDensity(const LBMReal *const &f /*[27]*/) +{ + return LBM::getDensity(f); +} + +LBMReal getIncompVelocityX1(const LBMReal *const &f /*[27]*/) +{ + return LBM::getIncompVelocityX1(f); +} + +LBMReal getIncompVelocityX2(const LBMReal *const &f /*[27]*/) +{ + return LBM::getIncompVelocityX2(f); +} + +LBMReal getIncompVelocityX3(const LBMReal *const &f /*[27]*/) +{ + return LBM::getIncompVelocityX3(f); +} + + + + + } // namespace D3Q27System \ No newline at end of file diff --git a/src/cpu/VirtualFluidsCore/LBM/D3Q27System.h b/src/cpu/VirtualFluidsCore/LBM/D3Q27System.h index d3b553084d0e8c9ab2696ede622c174ee07871b4..04fe8a819b143db8cc935fc893faa514805060a6 100644 --- a/src/cpu/VirtualFluidsCore/LBM/D3Q27System.h +++ b/src/cpu/VirtualFluidsCore/LBM/D3Q27System.h @@ -42,7 +42,6 @@ #include "UbException.h" #include "UbMath.h" -#include "lbm/CalcMac.h" //! \brief namespace for global system-functions namespace D3Q27System @@ -149,30 +148,21 @@ static const int ET_BNW = 11; static const int ET_TSW = 12; static const int ET_BNE = 12; + ////////////////////////////////////////////////////////////////////////// // MACROSCOPIC VALUES /*=====================================================================*/ -static LBMReal getDensity(const LBMReal *const &f /*[27]*/) -{ - return LBM::getDensity(f); -} +LBMReal getDensity(const LBMReal *const &f /*[27]*/); /*=====================================================================*/ static LBMReal getPressure(const LBMReal *const &f /*[27]*/) { return REAL_CAST(UbMath::c1o3) * getDensity(f); } /*=====================================================================*/ -static LBMReal getIncompVelocityX1(const LBMReal *const &f /*[27]*/) -{ - return LBM::getIncompVelocityX1(f); -} +LBMReal getIncompVelocityX1(const LBMReal *const &f /*[27]*/); /*=====================================================================*/ -static LBMReal getIncompVelocityX2(const LBMReal *const &f /*[27]*/) -{ - return LBM::getIncompVelocityX2(f); -} +LBMReal getIncompVelocityX2(const LBMReal *const &f /*[27]*/); /*=====================================================================*/ -static LBMReal getIncompVelocityX3(const LBMReal *const &f /*[27]*/) -{ - return LBM::getIncompVelocityX3(f); -} +LBMReal getIncompVelocityX3(const LBMReal *const &f /*[27]*/); + + /*=====================================================================*/ static void calcDensity(const LBMReal *const &f /*[27]*/, LBMReal &rho) { diff --git a/src/cpu/VirtualFluidsCore/LBM/ILBMKernel.h b/src/cpu/VirtualFluidsCore/LBM/ILBMKernel.h index 4dbe8eee09a37c0c220f47619b72bade2e6ec527..bde61d9d314b61327ff8f8a2a71d2864d50cc7f5 100644 --- a/src/cpu/VirtualFluidsCore/LBM/ILBMKernel.h +++ b/src/cpu/VirtualFluidsCore/LBM/ILBMKernel.h @@ -36,6 +36,8 @@ #include <PointerDefinitions.h> +#include "LBMSystem.h" + class BCProcessor; class DataSet3D; @@ -57,7 +59,7 @@ public: virtual void setCollisionFactor(double collFactor) = 0; virtual bool isInsideOfDomain(const int &x1, const int &x2, const int &x3) const = 0; virtual int getGhostLayerWidth() const = 0; - virtual double getDeltaT() const = 0; + virtual LBMReal getDeltaT() const = 0; virtual bool getWithForcing() const = 0; }; diff --git a/src/cpu/VirtualFluidsCore/LBM/LBMSystem.h b/src/cpu/VirtualFluidsCore/LBM/LBMSystem.h index d24775aef0fbe6822fbdc03d42e2acfeb3021430..14b4d223b2e07e3dbca9947cefd89de045bfb3cf 100644 --- a/src/cpu/VirtualFluidsCore/LBM/LBMSystem.h +++ b/src/cpu/VirtualFluidsCore/LBM/LBMSystem.h @@ -37,6 +37,8 @@ #include <iostream> #include <string> +#include "basics/Core/DataTypes.h" + //! \brief namespace for global system-functions namespace LBMSystem @@ -45,10 +47,10 @@ namespace LBMSystem //#define SINGLEPRECISION #ifdef SINGLEPRECISION -typedef float real; +//using real = float; #define REAL_CAST(x) ((LBMSystem::real)(x)) #else -using real = double; +//using real = double; #define REAL_CAST(x) (x) #endif @@ -82,6 +84,7 @@ static real calcOmega2(real viscosity, real deltaT) { return REAL_CAST(1.0 / (4. } // namespace LBMSystem // some typedefs for global namespace -using LBMReal = LBMSystem::real; +//using LBMReal = LBMSystem::real; +using LBMReal = real; #endif diff --git a/src/gpu/VirtualFluids_GPU/CMakeLists.txt b/src/gpu/VirtualFluids_GPU/CMakeLists.txt index aa313a3e7a09ee818787fb76c0ccbfe9ac87b44c..50ec200052b31d448d792b72389e736fd17b78a2 100644 --- a/src/gpu/VirtualFluids_GPU/CMakeLists.txt +++ b/src/gpu/VirtualFluids_GPU/CMakeLists.txt @@ -5,7 +5,7 @@ if(MSVC) set(additional_libraries ws2_32 Traffic) # ws_32 throws an error on Phoenix endif() -vf_add_library(PRIVATE_LINK ${additional_libraries} GridGenerator basics lbm MPI::MPI_CXX) +vf_add_library(BUILDTYPE static PRIVATE_LINK ${additional_libraries} GridGenerator basics MPI::MPI_CXX PUBLIC_LINK lbmStatic) linkBoost(COMPONENTS "serialization") @@ -13,5 +13,6 @@ linkBoost(COMPONENTS "serialization") #https://stackoverflow.com/questions/6832666/lnk2019-when-including-asio-headers-solution-generated-with-cmake #https://stackoverflow.com/questions/27442885/syntax-error-with-stdnumeric-limitsmax - +#set_target_properties(VirtualFluids_GPU PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON) set_target_properties(VirtualFluids_GPU PROPERTIES CUDA_SEPARABLE_COMPILATION ON) +#set_target_properties(VirtualFluids_GPU PROPERTIES POSITION_INDEPENDENT_CODE ON) \ No newline at end of file diff --git a/src/lbm/CMakeLists.txt b/src/lbm/CMakeLists.txt index c3895812c1cad7d6d835d1db0e4ea9a7f0cfb29d..d436a48a550b6582ff8c3746a36cf0e05f19818d 100644 --- a/src/lbm/CMakeLists.txt +++ b/src/lbm/CMakeLists.txt @@ -4,8 +4,16 @@ if(BUILD_VF_GPU) enable_language(CUDA) endif() -vf_add_library(PUBLIC_LINK basics) +vf_add_library(BUILDTYPE shared PUBLIC_LINK basics) +vf_add_library(NAME lbmStatic BUILDTYPE static PUBLIC_LINK basics) if(BUILD_VF_GPU) -set_target_properties(lbm PROPERTIES CUDA_SEPARABLE_COMPILATION ON) + #set_target_properties(lbm PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON) + set_target_properties(lbmStatic PROPERTIES CUDA_SEPARABLE_COMPILATION ON) + #set_target_properties(lbm PROPERTIES POSITION_INDEPENDENT_CODE ON) + set_source_files_properties(CalcMac.cpp PROPERTIES LANGUAGE CUDA) endif() + + +vf_add_tests() + diff --git a/src/lbm/CalcMac.cu b/src/lbm/CalcMac.cpp similarity index 100% rename from src/lbm/CalcMac.cu rename to src/lbm/CalcMac.cpp diff --git a/src/lbm/CalcMac.h b/src/lbm/CalcMac.h index fa7e83bd56f1f2fb16a159051ef358293439c4fe..a9356ce4f19b2ad242aea803bfc7e74360f11c45 100644 --- a/src/lbm/CalcMac.h +++ b/src/lbm/CalcMac.h @@ -1,10 +1,7 @@ #ifndef LBM_CALCMAC_H #define LBM_CALCMAC_H -#include "Core/DataTypes.h" - #ifdef __CUDACC__ -#pragma message ( "C Preprocessor got here!" ) #include <cuda_runtime.h> #else #ifndef __host__ @@ -13,9 +10,12 @@ #ifndef __device__ #define __device__ #endif -#endif +#endif + +#include "Core/DataTypes.h" +#include "lbm_export.h" -class LBM +class LBM_EXPORT LBM { public: diff --git a/src/lbm/CalcMacTests.cpp b/src/lbm/CalcMacTests.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eeaeb993e9e481c8d0a0ac945cf8a5b4fd8e9450 --- /dev/null +++ b/src/lbm/CalcMacTests.cpp @@ -0,0 +1,12 @@ +#include <gmock/gmock.h> + +#include "CalcMac.h" + +TEST(AAA,BBB) +{ + real f[27] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; + + double density = LBM::getDensity(f); + + ASSERT_THAT(density, testing::DoubleEq(1)); +} \ No newline at end of file diff --git a/src/lbmApp/CMakeLists.txt b/src/lbmApp/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0bd8dc446a412f0f32044bd7ad56b7d8f684ce1e --- /dev/null +++ b/src/lbmApp/CMakeLists.txt @@ -0,0 +1,8 @@ +PROJECT(LBMAPP LANGUAGES CUDA CXX) + +vf_add_library(BUILDTYPE binary PRIVATE_LINK lbmStatic FILES main.cpp) + +set_source_files_properties(main.cpp PROPERTIES LANGUAGE CUDA) + + +set_target_properties(lbmApp PROPERTIES CUDA_SEPARABLE_COMPILATION ON) \ No newline at end of file diff --git a/src/lbmApp/main.cpp b/src/lbmApp/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..16bca8434b6c470ad855804f151b0619ad1d76a9 --- /dev/null +++ b/src/lbmApp/main.cpp @@ -0,0 +1,25 @@ +#include <iostream> +#include <stdio.h> + +#include "lbm/CalcMac.h" +#include <cuda_runtime.h> + +__global__ void test() +{ + printf("Hello World from GPU!\n"); + real f[27] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}; + + double density = LBM::getDensity(f); + + printf("Hello density: %f \n", density); +} + +int main() +{ + std::cout << "hello world \n"; + + test<<<1,1>>>(); + cudaDeviceSynchronize(); + + return 0; +} \ No newline at end of file