diff --git a/.gitignore b/.gitignore index f05ddbd29708e88ed8a0e886626a12d26f3cff7f..ae19800aa7dd8a859144426e8280eb3718add848 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,9 @@ __pycache__/ output/ logs/ +# grid +grid/ + # scripts scripts/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2c6c35332b372379891de0c1ecc14640b48cbca8..bab479082aa0927a86eb8224fdcd83031cf792f9 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -102,11 +102,6 @@ msvc_16: - cmake .. --preset=all_msvc -DCMAKE_CUDA_ARCHITECTURES=61 -DBUILD_WARNINGS_AS_ERRORS=ON - MSBuild.exe VirtualFluids.sln /property:Configuration=$env:BUILD_CONFIGURATION /verbosity:minimal /maxcpucount:4 - cache: - key: "$CI_JOB_NAME-$CI_COMMIT_REF_SLUG" - paths: - - $CI_PROJECT_DIR/$env:BUILD_FOLDER/ - artifacts: expire_in: 1 hrs paths: diff --git a/apps/gpu/LBM/DrivenCavity/DrivenCavity.cpp b/apps/gpu/LBM/DrivenCavity/DrivenCavity.cpp index 2cde1330ba9832dc9ee7a68542b25541d104a2cc..f5ccbe2552b721186cef2a2891ca75e82bfe5f30 100644 --- a/apps/gpu/LBM/DrivenCavity/DrivenCavity.cpp +++ b/apps/gpu/LBM/DrivenCavity/DrivenCavity.cpp @@ -94,6 +94,7 @@ const real dt = (real)0.5e-3; const uint nx = 64; std::string path("output/"); +std::string gridPath("grid/"); std::string simulationName("DrivenCavityChim"); @@ -175,12 +176,11 @@ void multipleLevel(const std::string& configPath) para->setDevices(std::vector<uint>{(uint)0}); - para->setOutputPath( path ); + para->setOutputPath( path ); // optional, default is output/ + para ->setGridPath( gridPath ); // optional, default is grid/ para->setOutputPrefix( simulationName ); - para->setFName(para->getOutputPath() + "/" + para->getOutputPrefix()); - para->setPrintFiles(true); para->setMaxLevel(2); @@ -215,7 +215,7 @@ void multipleLevel(const std::string& configPath) //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// - gridBuilder->writeGridsToVtk(path + "/grid/"); + gridBuilder->writeGridsToVtk(para->getGridPath()); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/apps/gpu/LBM/DrivenCavity/configDrivenCavity.txt b/apps/gpu/LBM/DrivenCavity/configDrivenCavity.txt index 1a37302828a3673afe4f89eea07e6ffc0638aba9..458346a67c7f001580494af1dc9262034613be68 100644 --- a/apps/gpu/LBM/DrivenCavity/configDrivenCavity.txt +++ b/apps/gpu/LBM/DrivenCavity/configDrivenCavity.txt @@ -7,14 +7,13 @@ ################################################## #informations for Writing ################################################## -Path=output/DrivenCavity/ -#Prefix=DrivenCavity +#Path = "output/" +#Prefix="DrivenCavity" #WriteGrid=true ################################################## #informations for reading ################################################## -#GridPath="E:/DrivenCavity/dummy" -GridPath="C:" +#GridPath="grid/" ################################################## #number of grid levels diff --git a/src/gpu/VirtualFluids_GPU/Communication/ExchangeData27Test.cpp b/src/gpu/VirtualFluids_GPU/Communication/ExchangeData27Test.cpp index 3afedfb061211a15b74573d4e6043e8c3e59671b..df4e1ea9e1224c8fc513ba14f0f1aca56c608971 100644 --- a/src/gpu/VirtualFluids_GPU/Communication/ExchangeData27Test.cpp +++ b/src/gpu/VirtualFluids_GPU/Communication/ExchangeData27Test.cpp @@ -7,15 +7,6 @@ #include <basics/config/ConfigurationFile.h> -SPtr<Parameter> initParameterClass() -{ - std::filesystem::path filePath = __FILE__; // assuming that the config file is stored parallel to this file. - filePath.replace_filename("ExchangeData27Test.cfg"); - vf::basics::ConfigurationFile config; - config.load(filePath.string()); - return std::make_shared<Parameter>(config, 1, 0); -} - void setUpFsByCopyingF0(std::vector<real> &distributionVector, int numberOfNodes) { for (uint direction = 0; direction < dirEND; direction++) { @@ -37,7 +28,7 @@ protected: void SetUp() override { - para = initParameterClass(); + para = std::make_shared<Parameter>(1, 0); para->setMaxLevel(level + 1); // setMaxLevel resizes parH para->initLBMSimulationParameter(); // init parH diff --git a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/IndexRearrangementForStreamsTest.cpp b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/IndexRearrangementForStreamsTest.cpp index f8aa867d17624851f8beb85bf8cf564b5289531a..6e777e2c13212d33251f563dcad525bf92f9d566 100644 --- a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/IndexRearrangementForStreamsTest.cpp +++ b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/IndexRearrangementForStreamsTest.cpp @@ -99,15 +99,6 @@ struct CFBorderBulk { std::vector<real> offsetCFz_Bulk_expected = { 1001, 1003, 1005, 1007 }; }; -static SPtr<Parameter> initParameterClass() -{ - std::filesystem::path filePath = __FILE__; // assuming that the config file is stored parallel to this file. - filePath.replace_filename("IndexRearrangementForStreamsTest.cfg"); - vf::basics::ConfigurationFile config; - config.load(filePath.string()); - return std::make_shared<Parameter>(config, 1, 0); -} - class IndexRearrangementForStreamsTest_IndicesCFBorderBulkTest : public testing::Test { protected: @@ -141,7 +132,7 @@ private: void SetUp() override { - para = initParameterClass(); + para = std::make_shared<Parameter>(1, 0); testSubject = createTestSubjectCFBorderBulk(); } }; @@ -223,7 +214,7 @@ private: void SetUp() override { - para = initParameterClass(); + para = std::make_shared<Parameter>(1, 0); testSubject = createTestSubjectFCBorderBulk(); } }; @@ -322,7 +313,7 @@ private: void SetUp() override { - para = initParameterClass(); + para = std::make_shared<Parameter>(1, 0); testSubject = createTestSubjectReorderSendIndices(); }; }; diff --git a/src/gpu/VirtualFluids_GPU/GPU/NoSlipBCs27.cu b/src/gpu/VirtualFluids_GPU/GPU/NoSlipBCs27.cu index 163c91ebc010fce6578bd6761600fab4e8b8bd69..fccebd57315d4ff258af4b53ae68211e1bc20be4 100644 --- a/src/gpu/VirtualFluids_GPU/GPU/NoSlipBCs27.cu +++ b/src/gpu/VirtualFluids_GPU/GPU/NoSlipBCs27.cu @@ -1775,6 +1775,7 @@ extern "C" __global__ void QDeviceComp27( if (q>=c0o1 && q<=c1o1) { velocityLB = -vx1; + feq = getEquilibriumForBC(drho, velocityLB, cu_sq, c2o27); (dist.f[dirE])[ke] = getInterpolatedDistributionForNoSlipBC(q, f_W, f_E, feq, omega); } diff --git a/src/gpu/VirtualFluids_GPU/LBM/LB.h b/src/gpu/VirtualFluids_GPU/LBM/LB.h index 0cfab0031fef1aaaed421104e107bc0baac58f7d..ba92d8b8382deb22934bc053fdc2ca7feecc3f51 100644 --- a/src/gpu/VirtualFluids_GPU/LBM/LB.h +++ b/src/gpu/VirtualFluids_GPU/LBM/LB.h @@ -78,7 +78,9 @@ struct InitCondition std::vector<int> GridX, GridY, GridZ, DistX, DistY, DistZ; std::vector<real> scaleLBMtoSI, translateLBMtoSI; std::vector<real> minCoordX, minCoordY, minCoordZ, maxCoordX, maxCoordY, maxCoordZ; - std::string fname, oPath; + std::string fname; + std::string oPath {"output/"}; + std::string gridPath {"grid/"}; std::string oPrefix {"MyFile"}; std::string geometryFileC, geometryFileM, geometryFileF; std::string kFull, geoFull, geoVec, coordX, coordY, coordZ, neighborX, neighborY, neighborZ, neighborWSB, scaleCFC, scaleCFF, scaleFCC, scaleFCF, scaleOffsetCF, scaleOffsetFC; diff --git a/src/gpu/VirtualFluids_GPU/Parameter/EdgeNodeFinderTest.cpp b/src/gpu/VirtualFluids_GPU/Parameter/EdgeNodeFinderTest.cpp index 91fd9a4161c5b6d0786c545f63e6116a66bb5868..89f300b4ce9e14d76ee54fb02ba5f9102893bb98 100644 --- a/src/gpu/VirtualFluids_GPU/Parameter/EdgeNodeFinderTest.cpp +++ b/src/gpu/VirtualFluids_GPU/Parameter/EdgeNodeFinderTest.cpp @@ -6,15 +6,6 @@ #include "Parameter.h" #include "basics/config/ConfigurationFile.h" -static std::shared_ptr<Parameter> initParameterClass() -{ - std::filesystem::path filePath = __FILE__; // assuming that the config file is stored parallel to this file. - filePath.replace_filename("parameterTest.cfg"); - vf::basics::ConfigurationFile config; - config.load(filePath.string()); - return std::make_shared<Parameter>(config, 1, 0); -} - bool compareEdgeNodesRecv(const std::vector<LBMSimulationParameter::EdgeNodePositions> &actual, const std::vector<std::pair<int, int>> &expected) { @@ -52,7 +43,7 @@ protected: private: void SetUp() override { - para = initParameterClass(); + para = std::make_shared<Parameter>(1, 0); para->initLBMSimulationParameter(); } }; diff --git a/src/gpu/VirtualFluids_GPU/Parameter/Parameter.cpp b/src/gpu/VirtualFluids_GPU/Parameter/Parameter.cpp index 7651a0c0295617ccd92893c2e1d8d1bd85d57567..42e53bb681b3977f42ea8ebfebd0fbdebae37444 100644 --- a/src/gpu/VirtualFluids_GPU/Parameter/Parameter.cpp +++ b/src/gpu/VirtualFluids_GPU/Parameter/Parameter.cpp @@ -44,12 +44,31 @@ #include "Parameter/CudaStreamManager.h" +Parameter::Parameter(int numberOfProcesses, int myId) +{ + this->ic.numprocs = numberOfProcesses; + this->ic.myid = myId; + + initGridPaths(); + initGridBasePoints(); + initDefaultLBMkernelAllLevels(); + this->setFName(this->getOutputPath() + this->getOutputPrefix()); + + // initLBMSimulationParameter(); +} + Parameter::Parameter(const vf::basics::ConfigurationFile &configData, int numberOfProcesses, int myId) { - ic.numprocs = numberOfProcesses; - ic.myid = myId; + this->ic.numprocs = numberOfProcesses; + this->ic.myid = myId; readConfigData(configData); + + initGridPaths(); + initGridBasePoints(); + initDefaultLBMkernelAllLevels(); + this->setFName(this->getOutputPath() + this->getOutputPrefix()); + // initLBMSimulationParameter(); } @@ -59,16 +78,12 @@ void Parameter::readConfigData(const vf::basics::ConfigurationFile &configData) { if (configData.contains("NumberOfDevices")) this->setMaxDev(configData.getValue<int>("NumberOfDevices")); - ////////////////////////////////////////////////////////////////////////// if (configData.contains("Devices")) this->setDevices(configData.getVector<uint>("Devices")); ////////////////////////////////////////////////////////////////////////// if (configData.contains("Path")) this->setOutputPath(configData.getValue<std::string>("Path")); - else - throw std::runtime_error("<Path> need to be defined in config file!"); - ////////////////////////////////////////////////////////////////////////// if (configData.contains("Prefix")) this->setOutputPrefix(configData.getValue<std::string>("Prefix")); @@ -246,72 +261,10 @@ void Parameter::readConfigData(const vf::basics::ConfigurationFile &configData) ////////////////////////////////////////////////////////////////////////// - std::string gridPath{ "" }; if (configData.contains("GridPath")) - gridPath = configData.getValue<std::string>("GridPath"); - else - throw std::runtime_error("GridPath has to be defined in config file!"); + this->setGridPath(configData.getValue<std::string>("GridPath")); - if (this->getNumprocs() == 1) - gridPath += "/"; - else - gridPath += "/" + StringUtil::toString(this->getMyID()) + "/"; - - // ////////////////////////////////////////////////////////////////////////// - this->setFName(this->getOutputPath() + "/" + this->getOutputPrefix()); - ////////////////////////////////////////////////////////////////////////// - this->setgeoVec(gridPath + "geoVec.dat"); - this->setcoordX(gridPath + "coordX.dat"); - this->setcoordY(gridPath + "coordY.dat"); - this->setcoordZ(gridPath + "coordZ.dat"); - this->setneighborX(gridPath + "neighborX.dat"); - this->setneighborY(gridPath + "neighborY.dat"); - this->setneighborZ(gridPath + "neighborZ.dat"); - this->setneighborWSB(gridPath + "neighborWSB.dat"); - this->setscaleCFC(gridPath + "scaleCFC.dat"); - this->setscaleCFF(gridPath + "scaleCFF.dat"); - this->setscaleFCC(gridPath + "scaleFCC.dat"); - this->setscaleFCF(gridPath + "scaleFCF.dat"); - this->setscaleOffsetCF(gridPath + "offsetVecCF.dat"); - this->setscaleOffsetFC(gridPath + "offsetVecFC.dat"); - this->setgeomBoundaryBcQs(gridPath + "geomBoundaryQs.dat"); - this->setgeomBoundaryBcValues(gridPath + "geomBoundaryValues.dat"); - this->setinletBcQs(gridPath + "inletBoundaryQs.dat"); - this->setinletBcValues(gridPath + "inletBoundaryValues.dat"); - this->setoutletBcQs(gridPath + "outletBoundaryQs.dat"); - this->setoutletBcValues(gridPath + "outletBoundaryValues.dat"); - this->settopBcQs(gridPath + "topBoundaryQs.dat"); - this->settopBcValues(gridPath + "topBoundaryValues.dat"); - this->setbottomBcQs(gridPath + "bottomBoundaryQs.dat"); - this->setbottomBcValues(gridPath + "bottomBoundaryValues.dat"); - this->setfrontBcQs(gridPath + "frontBoundaryQs.dat"); - this->setfrontBcValues(gridPath + "frontBoundaryValues.dat"); - this->setbackBcQs(gridPath + "backBoundaryQs.dat"); - this->setbackBcValues(gridPath + "backBoundaryValues.dat"); - this->setnumberNodes(gridPath + "numberNodes.dat"); - this->setLBMvsSI(gridPath + "LBMvsSI.dat"); - this->setmeasurePoints(gridPath + "measurePoints.dat"); - this->setpropellerValues(gridPath + "propellerValues.dat"); - this->setcpTop(gridPath + "cpTop.dat"); - this->setcpBottom(gridPath + "cpBottom.dat"); - this->setcpBottom2(gridPath + "cpBottom2.dat"); - this->setConcentration(gridPath + "conc.dat"); - this->setStreetVelocity(gridPath + "streetVector.dat"); - ////////////////////////////////////////////////////////////////////////// - // Normals - Geometry - this->setgeomBoundaryNormalX(gridPath + "geomBoundaryNormalX.dat"); - this->setgeomBoundaryNormalY(gridPath + "geomBoundaryNormalY.dat"); - this->setgeomBoundaryNormalZ(gridPath + "geomBoundaryNormalZ.dat"); - // Normals - Inlet - this->setInflowBoundaryNormalX(gridPath + "inletBoundaryNormalX.dat"); - this->setInflowBoundaryNormalY(gridPath + "inletBoundaryNormalY.dat"); - this->setInflowBoundaryNormalZ(gridPath + "inletBoundaryNormalZ.dat"); - // Normals - Outlet - this->setOutflowBoundaryNormalX(gridPath + "outletBoundaryNormalX.dat"); - this->setOutflowBoundaryNormalY(gridPath + "outletBoundaryNormalY.dat"); - this->setOutflowBoundaryNormalZ(gridPath + "outletBoundaryNormalZ.dat"); - ////////////////////////////////////////////////////////////////////////// - // //Forcing + // Forcing real forcingX = 0.0; real forcingY = 0.0; real forcingZ = 0.0; @@ -357,28 +310,6 @@ void Parameter::readConfigData(const vf::basics::ConfigurationFile &configData) if (configData.contains("endXHotWall")) this->setEndXHotWall(configData.getValue<real>("endXHotWall")); - ////////////////////////////////////////////////////////////////////////// - // for Multi GPU - if (this->getNumprocs() > 1) { - ////////////////////////////////////////////////////////////////////////// - // 3D domain decomposition - std::vector<std::string> sendProcNeighborsX, sendProcNeighborsY, sendProcNeighborsZ; - std::vector<std::string> recvProcNeighborsX, recvProcNeighborsY, recvProcNeighborsZ; - for (int i = 0; i < this->getNumprocs(); i++) { - sendProcNeighborsX.push_back(gridPath + StringUtil::toString(i) + "Xs.dat"); - sendProcNeighborsY.push_back(gridPath + StringUtil::toString(i) + "Ys.dat"); - sendProcNeighborsZ.push_back(gridPath + StringUtil::toString(i) + "Zs.dat"); - recvProcNeighborsX.push_back(gridPath + StringUtil::toString(i) + "Xr.dat"); - recvProcNeighborsY.push_back(gridPath + StringUtil::toString(i) + "Yr.dat"); - recvProcNeighborsZ.push_back(gridPath + StringUtil::toString(i) + "Zr.dat"); - } - this->setPossNeighborFilesX(sendProcNeighborsX, "send"); - this->setPossNeighborFilesY(sendProcNeighborsY, "send"); - this->setPossNeighborFilesZ(sendProcNeighborsZ, "send"); - this->setPossNeighborFilesX(recvProcNeighborsX, "recv"); - this->setPossNeighborFilesY(recvProcNeighborsY, "recv"); - this->setPossNeighborFilesZ(recvProcNeighborsZ, "recv"); - } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Restart @@ -397,14 +328,6 @@ void Parameter::readConfigData(const vf::basics::ConfigurationFile &configData) if (configData.contains("NOGL")) setMaxLevel(configData.getValue<int>("NOGL")); - this->setGridX(std::vector<int>(this->getMaxLevel() + 1, 32)); - this->setGridY(std::vector<int>(this->getMaxLevel() + 1, 32)); - this->setGridZ(std::vector<int>(this->getMaxLevel() + 1, 32)); - - this->setDistX(std::vector<int>(this->getMaxLevel() + 1, 32)); - this->setDistY(std::vector<int>(this->getMaxLevel() + 1, 32)); - this->setDistZ(std::vector<int>(this->getMaxLevel() + 1, 32)); - if (configData.contains("GridX")) this->setGridX(configData.getVector<int>("GridX")); @@ -433,17 +356,134 @@ void Parameter::readConfigData(const vf::basics::ConfigurationFile &configData) if (configData.contains("MultiKernelLevel")) this->setMultiKernelLevel(configData.getVector<int>("MultiKernelLevel")); - else if (this->getMultiKernelOn()) { + + if (configData.contains("MultiKernelName")) + this->setMultiKernel(configData.getVector<std::string>("MultiKernelName")); +} + +void Parameter::initGridPaths(){ + std::string gridPath = this->getGridPath(); + + // add missing slash to gridPath + if (gridPath.back() != '/') { + gridPath += "/"; + ic.gridPath = gridPath; + } + + // for multi-gpu add process id (if not already there) + if (this->getNumprocs() > 1) { + gridPath += StringUtil::toString(this->getMyID()) + "/"; + ic.gridPath = gridPath; + } + + ////////////////////////////////////////////////////////////////////////// + + this->setgeoVec(gridPath + "geoVec.dat"); + this->setcoordX(gridPath + "coordX.dat"); + this->setcoordY(gridPath + "coordY.dat"); + this->setcoordZ(gridPath + "coordZ.dat"); + this->setneighborX(gridPath + "neighborX.dat"); + this->setneighborY(gridPath + "neighborY.dat"); + this->setneighborZ(gridPath + "neighborZ.dat"); + this->setneighborWSB(gridPath + "neighborWSB.dat"); + this->setscaleCFC(gridPath + "scaleCFC.dat"); + this->setscaleCFF(gridPath + "scaleCFF.dat"); + this->setscaleFCC(gridPath + "scaleFCC.dat"); + this->setscaleFCF(gridPath + "scaleFCF.dat"); + this->setscaleOffsetCF(gridPath + "offsetVecCF.dat"); + this->setscaleOffsetFC(gridPath + "offsetVecFC.dat"); + this->setgeomBoundaryBcQs(gridPath + "geomBoundaryQs.dat"); + this->setgeomBoundaryBcValues(gridPath + "geomBoundaryValues.dat"); + this->setinletBcQs(gridPath + "inletBoundaryQs.dat"); + this->setinletBcValues(gridPath + "inletBoundaryValues.dat"); + this->setoutletBcQs(gridPath + "outletBoundaryQs.dat"); + this->setoutletBcValues(gridPath + "outletBoundaryValues.dat"); + this->settopBcQs(gridPath + "topBoundaryQs.dat"); + this->settopBcValues(gridPath + "topBoundaryValues.dat"); + this->setbottomBcQs(gridPath + "bottomBoundaryQs.dat"); + this->setbottomBcValues(gridPath + "bottomBoundaryValues.dat"); + this->setfrontBcQs(gridPath + "frontBoundaryQs.dat"); + this->setfrontBcValues(gridPath + "frontBoundaryValues.dat"); + this->setbackBcQs(gridPath + "backBoundaryQs.dat"); + this->setbackBcValues(gridPath + "backBoundaryValues.dat"); + this->setnumberNodes(gridPath + "numberNodes.dat"); + this->setLBMvsSI(gridPath + "LBMvsSI.dat"); + this->setmeasurePoints(gridPath + "measurePoints.dat"); + this->setpropellerValues(gridPath + "propellerValues.dat"); + this->setcpTop(gridPath + "cpTop.dat"); + this->setcpBottom(gridPath + "cpBottom.dat"); + this->setcpBottom2(gridPath + "cpBottom2.dat"); + this->setConcentration(gridPath + "conc.dat"); + this->setStreetVelocity(gridPath + "streetVector.dat"); + + ////////////////////////////////////////////////////////////////////////// + // Normals - Geometry + this->setgeomBoundaryNormalX(gridPath + "geomBoundaryNormalX.dat"); + this->setgeomBoundaryNormalY(gridPath + "geomBoundaryNormalY.dat"); + this->setgeomBoundaryNormalZ(gridPath + "geomBoundaryNormalZ.dat"); + // Normals - Inlet + this->setInflowBoundaryNormalX(gridPath + "inletBoundaryNormalX.dat"); + this->setInflowBoundaryNormalY(gridPath + "inletBoundaryNormalY.dat"); + this->setInflowBoundaryNormalZ(gridPath + "inletBoundaryNormalZ.dat"); + // Normals - Outlet + this->setOutflowBoundaryNormalX(gridPath + "outletBoundaryNormalX.dat"); + this->setOutflowBoundaryNormalY(gridPath + "outletBoundaryNormalY.dat"); + this->setOutflowBoundaryNormalZ(gridPath + "outletBoundaryNormalZ.dat"); + ////////////////////////////////////////////////////////////////////////// + + ////////////////////////////////////////////////////////////////////////// + // for Multi GPU + if (this->getNumprocs() > 1) { + + // 3D domain decomposition + std::vector<std::string> sendProcNeighborsX, sendProcNeighborsY, sendProcNeighborsZ; + std::vector<std::string> recvProcNeighborsX, recvProcNeighborsY, recvProcNeighborsZ; + for (int i = 0; i < this->getNumprocs(); i++) { + sendProcNeighborsX.push_back(gridPath + StringUtil::toString(i) + "Xs.dat"); + sendProcNeighborsY.push_back(gridPath + StringUtil::toString(i) + "Ys.dat"); + sendProcNeighborsZ.push_back(gridPath + StringUtil::toString(i) + "Zs.dat"); + recvProcNeighborsX.push_back(gridPath + StringUtil::toString(i) + "Xr.dat"); + recvProcNeighborsY.push_back(gridPath + StringUtil::toString(i) + "Yr.dat"); + recvProcNeighborsZ.push_back(gridPath + StringUtil::toString(i) + "Zr.dat"); + } + this->setPossNeighborFilesX(sendProcNeighborsX, "send"); + this->setPossNeighborFilesY(sendProcNeighborsY, "send"); + this->setPossNeighborFilesZ(sendProcNeighborsZ, "send"); + this->setPossNeighborFilesX(recvProcNeighborsX, "recv"); + this->setPossNeighborFilesY(recvProcNeighborsY, "recv"); + this->setPossNeighborFilesZ(recvProcNeighborsZ, "recv"); + + ////////////////////////////////////////////////////////////////////////// + } +} + +void Parameter::initGridBasePoints() +{ + if (this->getGridX().empty()) + this->setGridX(std::vector<int>(this->getMaxLevel() + 1, 32)); + if (this->getGridY().empty()) + this->setGridY(std::vector<int>(this->getMaxLevel() + 1, 32)); + if (this->getGridZ().empty()) + this->setGridZ(std::vector<int>(this->getMaxLevel() + 1, 32)); + + if (this->getDistX().empty()) + this->setDistX(std::vector<int>(this->getMaxLevel() + 1, 32)); + if (this->getDistY().empty()) + this->setDistY(std::vector<int>(this->getMaxLevel() + 1, 32)); + if (this->getDistZ().empty()) + this->setDistZ(std::vector<int>(this->getMaxLevel() + 1, 32)); +} + +void Parameter::initDefaultLBMkernelAllLevels(){ + if (this->getMultiKernelOn() && this->getMultiKernelLevel().empty()) { std::vector<int> tmp; for (int i = 0; i < this->getMaxLevel() + 1; i++) { tmp.push_back(i); } this->setMultiKernelLevel(tmp); } - - if (configData.contains("MultiKernelName")) - this->setMultiKernel(configData.getVector<std::string>("MultiKernelName")); - else if (this->getMultiKernelOn()) { + + if (this->getMultiKernelOn() && this->getMultiKernel().empty()) { std::vector<std::string> tmp; for (int i = 0; i < this->getMaxLevel() + 1; i++) { tmp.push_back("CumulantK17Comp"); @@ -709,18 +749,25 @@ void Parameter::setTimeCalcMedEnd(int CalcMedEnd) } void Parameter::setOutputPath(std::string oPath) { + // add missing slash to outputPath + if (oPath.back() != '/') + oPath += "/"; + ic.oPath = oPath; } void Parameter::setOutputPrefix(std::string oPrefix) { - // std::string test = fname; ic.oPrefix = oPrefix; } void Parameter::setFName(std::string fname) { - // std::string test = fname; ic.fname = fname; } +void Parameter::setGridPath(std::string gridPath) +{ + ic.gridPath = gridPath; + this->initGridPaths(); +} void Parameter::setPrintFiles(bool printfiles) { ic.printFiles = printfiles; @@ -1766,6 +1813,10 @@ std::string Parameter::getFName() { return ic.fname; } +std::string Parameter::getGridPath() +{ + return ic.gridPath; +} bool Parameter::getPrintFiles() { return ic.printFiles; diff --git a/src/gpu/VirtualFluids_GPU/Parameter/Parameter.h b/src/gpu/VirtualFluids_GPU/Parameter/Parameter.h index 21b3643ba062ccb0ca168e25c285afcec55dfafe..d77048629e719788d2868a44b0b1322be8e111d0 100644 --- a/src/gpu/VirtualFluids_GPU/Parameter/Parameter.h +++ b/src/gpu/VirtualFluids_GPU/Parameter/Parameter.h @@ -378,6 +378,7 @@ class VIRTUALFLUIDS_GPU_EXPORT Parameter { public: Parameter(const vf::basics::ConfigurationFile &configData, int numberOfProcesses, int myId); + Parameter(int numberOfProcesses, int myId); ~Parameter(); void initLBMSimulationParameter(); @@ -433,6 +434,7 @@ public: void setOutputPath(std::string oPath); void setOutputPrefix(std::string oPrefix); void setFName(std::string fname); + void setGridPath(std::string gridPath); void setGeometryFileC(std::string GeometryFileC); void setGeometryFileM(std::string GeometryFileM); void setGeometryFileF(std::string GeometryFileF); @@ -650,6 +652,7 @@ public: std::string getOutputPath(); std::string getOutputPrefix(); std::string getFName(); + std::string getGridPath(); std::string getGeometryFileC(); std::string getGeometryFileM(); std::string getGeometryFileF(); @@ -856,7 +859,11 @@ public: private: void readConfigData(const vf::basics::ConfigurationFile &configData); + void initGridPaths(); + void initGridBasePoints(); + void initDefaultLBMkernelAllLevels(); +private: bool compOn{ false }; bool diffOn{ false }; bool isF3{ false }; diff --git a/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp b/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp index 876cc3c4f7df639f8f8186e09a6291ecb44f5074..5d9485b5aa0715f7141d8db411b3e1ce5399bd41 100644 --- a/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp +++ b/src/gpu/VirtualFluids_GPU/Parameter/ParameterTest.cpp @@ -15,7 +15,7 @@ auto RealEq = [](auto value) { #endif }; -TEST(ParameterTest, passingEmptyFileWithoutPath_ShouldThrow) +TEST(ParameterTest, passingEmptyFileWithoutPath_ShouldNotThrow) { // assuming that the config files is stored parallel to this file. std::filesystem::path filePath = __FILE__; @@ -24,7 +24,7 @@ TEST(ParameterTest, passingEmptyFileWithoutPath_ShouldThrow) vf::basics::ConfigurationFile config; config.load(filePath.string()); - EXPECT_THROW(Parameter para(config, 1, 0), std::runtime_error); + EXPECT_NO_THROW(Parameter para(config, 1, 0)); } // TODO: test setPossNeighborFilesX @@ -41,12 +41,10 @@ TEST(ParameterTest, check_all_Parameter_CanBePassedToConstructor) Parameter para(config, 1, 0); - // this two parameters need to be defined in each config file - EXPECT_THAT(para.getOutputPath(), testing::Eq("/output/path")); - EXPECT_THAT(para.getgeoVec(), testing::Eq("/path/to/grid/geoVec.dat")); - // ... all grid files could be tested as well - // test optional parameter + EXPECT_THAT(para.getOutputPath(), testing::Eq("/output/path/")); + EXPECT_THAT(para.getGridPath(), testing::Eq("/path/to/grid/")); // ... all grid files (e.g. multi-gpu/ multi-level) could be tested as well + EXPECT_THAT(para.getgeoVec(), testing::Eq("/path/to/grid/geoVec.dat")); EXPECT_THAT(para.getMaxDev(), testing::Eq(2)); EXPECT_THAT(para.getDevices(), testing::ElementsAreArray({ 2, 3 })); EXPECT_THAT(para.getOutputPrefix(), testing::Eq("MyPrefix")); @@ -149,4 +147,62 @@ TEST(ParameterTest, check_all_Parameter_CanBePassedToConstructor) EXPECT_THAT(para.getFine(), testing::Eq(1)); // NOGL - 1 EXPECT_THAT(para.parH.size(), testing::Eq(2)); EXPECT_THAT(para.parD.size(), testing::Eq(2)); +} + +TEST(ParameterTest, defaultGridPath) +{ + Parameter para(1, 0); + EXPECT_THAT(para.getGridPath(), testing::Eq("grid/")); + EXPECT_THAT(para.getConcentration(), testing::Eq("grid/conc.dat")); +} + +TEST(ParameterTest, defaultGridPathMultiGPU) +{ + Parameter para(2, 1); + + EXPECT_THAT(para.getGridPath(), testing::Eq("grid/1/")); + EXPECT_THAT(para.getConcentration(), testing::Eq("grid/1/conc.dat")); +} + +TEST(ParameterTest, setGridPathOverridesDefaultGridPath) +{ + Parameter para(2, 1); + para.setGridPath("gridPathTest"); + + EXPECT_THAT( para.getGridPath(), testing::Eq("gridPathTest/1/")); + EXPECT_THAT(para.getConcentration(), testing::Eq("gridPathTest/1/conc.dat")); +} + +TEST(ParameterTest, setGridPathOverridesConfigFile) +{ + // assuming that the config files is stored parallel to this file. + std::filesystem::path filePath = __FILE__; + filePath.replace_filename("parameterTest.cfg"); + vf::basics::ConfigurationFile config; + config.load(filePath.string()); + auto para = Parameter(config, 2, 0); + para.setGridPath("gridPathTest"); + + EXPECT_THAT( para.getGridPath(), testing::Eq("gridPathTest/0/")); + EXPECT_THAT(para.getConcentration(), testing::Eq("gridPathTest/0/conc.dat")); + +} + +TEST(ParameterTest, userMissedSlash) +{ + Parameter para(1, 0); + para.setGridPath("gridPathTest"); + + EXPECT_THAT(para.getGridPath(), testing::Eq("gridPathTest/")); + EXPECT_THAT(para.getConcentration(), testing::Eq("gridPathTest/conc.dat")); + +} + +TEST(ParameterTest, userMissedSlashMultiGPU) +{ + Parameter para(2, 0); + para.setGridPath("gridPathTest"); + + EXPECT_THAT(para.getGridPath(), testing::Eq("gridPathTest/0/")); + EXPECT_THAT(para.getConcentration(), testing::Eq("gridPathTest/0/conc.dat")); } \ No newline at end of file