diff --git a/3rdParty/googletest/googletest/include/gtest/gtest.h b/3rdParty/googletest/googletest/include/gtest/gtest.h index c1cd69ab466c7c1b2e763680b3384a4eb87c98c3..2ed03fb6ae04d233605c2e92e4f75e4172bd0ad1 100644 --- a/3rdParty/googletest/googletest/include/gtest/gtest.h +++ b/3rdParty/googletest/googletest/include/gtest/gtest.h @@ -164,6 +164,9 @@ class UnitTestImpl* GetUnitTestImpl(); void ReportFailureInUnknownLocation(TestPartResult::Type result_type, const std::string& message); +enum GTestColor; + void GTEST_API_ ColoredPrintf(GTestColor color, const char* fmt, ...); + } // namespace internal // The friend relationship of some of these classes is cyclic. diff --git a/CMakeLists.txt b/CMakeLists.txt index 0492f04ae926213c6f89a252e4015e34f4a0848b..3637910de2ed4b9e69c2dc7da9a657778cb7dd91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,7 @@ option(HULC.BUILD_dem_coupling "Builds dem coupling " ON) option(HULC.BUILD_GPU_CODE "Build gpu VirtualFluids" ON) option(HULC.BUILD_JSONCPP "Builds json cpp " ON) option(HULC.BUILD_TESTS "Build shared libraries" ON) +option(HULC.BUILD_NUMERIC_TESTS "Build shared libraries" ON) option(VF_DOUBLE_ACCURACY "Build shared libraries" ON) @@ -175,4 +176,8 @@ if(HULC.BUILD_TESTS) add_subdirectory(targets/tests/VirtualFluidsBasicsTest) endif() +if(HULC.BUILD_NUMERIC_TESTS) + add_subdirectory(3rdParty/fftw/fftw-3.3.7) + add_subdirectory(targets/tests/TestingHULC) +endif() diff --git a/CMakeMacros/fftw/Link.cmake b/CMakeMacros/fftw/Link.cmake index 669f7b1faf1ae60d7c116a3463b13f956ff30fb5..773c45bdf88eab9c090149bce38a211e14235804 100644 --- a/CMakeMacros/fftw/Link.cmake +++ b/CMakeMacros/fftw/Link.cmake @@ -1,8 +1,7 @@ -include(${CMAKE_CURRENT_LIST_DIR}/FindFftw.cmake) macro(linkFftw targetName) - include_directories(${FFTW_INCLUDE_DIRS}) - target_link_libraries(${targetName} ${FFTW_LIBRARIES}) + include_directories(${FFTW_ROOT}/api) + target_link_libraries(${targetName} fftw3) endmacro(linkFftw) diff --git a/src/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.h b/src/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.h index 001e53d0e93bb0663a066891c6562da7643ac838..8a8810cd5eec39e56901b5c2d1f2d7f92240f8b9 100644 --- a/src/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.h +++ b/src/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.h @@ -16,7 +16,7 @@ class BoundaryValues; class BoundaryQs; class CoordNeighborGeoV; -class GridReader +class VF_PUBLIC GridReader : public GridProvider { private: @@ -27,8 +27,8 @@ private: std::vector<std::shared_ptr<BoundaryValues> > BC_Values; public: - VF_PUBLIC GridReader(bool binaer, std::shared_ptr<Parameter> para); - VF_PUBLIC ~GridReader(); + GridReader(bool binaer, std::shared_ptr<Parameter> para); + ~GridReader(); void allocArrays_CoordNeighborGeo()override; void allocArrays_BoundaryValues()override; void allocArrays_OffsetScale() override; diff --git a/src/VirtualFluids_GPU/LBM/Simulation.cpp b/src/VirtualFluids_GPU/LBM/Simulation.cpp index 97a778ac9316f4a9f2c1e250b1663b0db89063f9..ad55ee63be8b17c6c5bf7f494b0b6f0f24f0e7b8 100644 --- a/src/VirtualFluids_GPU/LBM/Simulation.cpp +++ b/src/VirtualFluids_GPU/LBM/Simulation.cpp @@ -53,6 +53,7 @@ #include "Restart/RestartPostprocessor.h" ////////////////////////////////////////////////////////////////////////// #include "DataStructureInitializer/GridProvider.h" +#include "Output/DataWriter.h" Simulation::Simulation() { @@ -64,8 +65,9 @@ Simulation::~Simulation() } -void Simulation::init(SPtr<Parameter> para, SPtr<GridProvider> gridProvider) +void Simulation::init(SPtr<Parameter> para, SPtr<GridProvider> gridProvider, std::shared_ptr<DataWriter> dataWriter) { + this->dataWriter = dataWriter; this->gridProvider = gridProvider; gridProvider->initalGridInformations(); comm = SPtr<Communicator>(Communicator::getInstanz()); @@ -320,7 +322,7 @@ void Simulation::init(SPtr<Parameter> para, SPtr<GridProvider> gridProvider) //Print Init ////////////////////////////////////////////////////////////////////////// output << "Print files Init..."; - writeInit(para); + dataWriter->writeInit(para); if (para->getCalcParticle()) copyAndPrintParticles(para.get(), 0, true); output << "done.\n"; @@ -2522,7 +2524,7 @@ void Simulation::run() ///////////////////////////////// } //////////////////////////////////////////////////////////////////////// - writeTimestep(para.get(), t); + dataWriter->writeTimestep(para, t); //////////////////////////////////////////////////////////////////////// //printDragLift(para, t); //////////////////////////////////////////////////////////////////////// diff --git a/src/VirtualFluids_GPU/LBM/Simulation.h b/src/VirtualFluids_GPU/LBM/Simulation.h index fb3d12ab3a2e3e772b9cb7d2ec94527ee1603f6f..be8e809d9072631808c8311e5b8a057b4cae3546 100644 --- a/src/VirtualFluids_GPU/LBM/Simulation.h +++ b/src/VirtualFluids_GPU/LBM/Simulation.h @@ -17,6 +17,7 @@ class PorousMedia; class RestartObject; class RestartPostprocessor; class ForceCalculations; +class DataWriter; class VF_PUBLIC Simulation @@ -25,7 +26,7 @@ public: Simulation(); ~Simulation(); void run(); - void init(SPtr<Parameter> para, SPtr<GridProvider> gridProvider); + void init(SPtr<Parameter> para, SPtr<GridProvider> gridProvider, std::shared_ptr<DataWriter> dataWriter); void bulk(); void porousMedia(); void definePMarea(PorousMedia* pm); @@ -47,6 +48,7 @@ protected: SPtr<Communicator> comm; SPtr<Parameter> para; SPtr<GridProvider> gridProvider; + SPtr<DataWriter> dataWriter; //Restart object RestartObject* restObj; diff --git a/src/VirtualFluids_GPU/Output/DataWriter.h b/src/VirtualFluids_GPU/Output/DataWriter.h new file mode 100644 index 0000000000000000000000000000000000000000..bd1f996a476c2efff25138869dc51a2a9bc5b189 --- /dev/null +++ b/src/VirtualFluids_GPU/Output/DataWriter.h @@ -0,0 +1,23 @@ +#ifndef DATA_WRITER_H +#define DATA_WRITER_H + +#define NOMINMAX + +#include <memory> +#include <vector> + + +class Parameter; + +class DataWriter +{ +public: + DataWriter() {} + virtual ~DataWriter() {} + + virtual void writeInit(std::shared_ptr<Parameter> para) = 0; + virtual void writeTimestep(std::shared_ptr<Parameter> para, unsigned int t) = 0; + + DataWriter(const DataWriter& dataWriter) {} +}; +#endif \ No newline at end of file diff --git a/src/VirtualFluids_GPU/Output/FileWriter.cpp b/src/VirtualFluids_GPU/Output/FileWriter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..657f534f057b9e3e77f62595b2031b12909b47c2 --- /dev/null +++ b/src/VirtualFluids_GPU/Output/FileWriter.cpp @@ -0,0 +1,139 @@ +#include "FileWriter.h" + +#include <stdio.h> +#include <fstream> +#include <sstream> +#include <cmath> + +#include <utilities/StringUtil/StringUtil.h> + +#include "Parameter/Parameter.h" + +#include "LBM/LB.h" +#include "LBM/D3Q27.h" + +#include <VirtualFluidsBasics/basics/writer/WbWriterVtkXmlBinary.h> + +void FileWriter::writeInit(std::shared_ptr<Parameter> para) +{ + unsigned int timestep = para->getTInit(); + for (int level = para->getCoarse(); level <= para->getFine(); level++) + writeTimestep(para, timestep, level); +} + +void FileWriter::writeTimestep(std::shared_ptr<Parameter> para, unsigned int timestep) +{ + for (int level = para->getCoarse(); level <= para->getFine(); level++) + writeTimestep(para, timestep, level); +} + +void FileWriter::writeTimestep(std::shared_ptr<Parameter> para, unsigned int timestep, int level) +{ + const unsigned int numberOfParts = para->getParH(level)->size_Mat_SP / para->getlimitOfNodesForVTK() + 1; + std::vector<std::string> fname; + for (unsigned int i = 1; i <= numberOfParts; i++) + fname.push_back(para->getFName() + "_bin_lev_" + StringUtil::toString<int>(level) + "_ID_" + StringUtil::toString<int>(para->getMyID()) + "_Part_" + StringUtil::toString<int>(i) + "_t_" + StringUtil::toString<int>(timestep) + ".vtk"); + + writeUnstrucuredGridLT(para, level, fname); +} + +void FileWriter::writeUnstrucuredGridLT(std::shared_ptr<Parameter> para, int level, std::vector<std::string >& fname) +{ + std::vector< UbTupleFloat3 > nodes; + std::vector< UbTupleUInt8 > cells; + std::vector< std::string > nodedatanames; + nodedatanames.push_back("press"); + nodedatanames.push_back("rho"); + nodedatanames.push_back("vx1"); + nodedatanames.push_back("vx2"); + nodedatanames.push_back("vx3"); + nodedatanames.push_back("geo"); + unsigned int number1, number2, number3, number4, number5, number6, number7, number8; + uint dn1, dn2, dn3, dn4, dn5, dn6, dn7, dn8; + bool neighborsAreFluid; + double vxmax = 0; + unsigned int startpos = 0; + unsigned int endpos = 0; + unsigned int sizeOfNodes = 0; + std::vector< std::vector< double > > nodedata(nodedatanames.size()); + + for (unsigned int part = 0; part < fname.size(); part++) + { + if (((part + 1)*para->getlimitOfNodesForVTK()) > para->getParH(level)->size_Mat_SP) + sizeOfNodes = para->getParH(level)->size_Mat_SP - (part * para->getlimitOfNodesForVTK()); + else + sizeOfNodes = para->getlimitOfNodesForVTK(); + + ////////////////////////////////////////////////////////////////////////// + startpos = part * para->getlimitOfNodesForVTK(); + endpos = startpos + sizeOfNodes; + ////////////////////////////////////////////////////////////////////////// + cells.clear(); + nodes.resize(sizeOfNodes); + nodedata[0].resize(sizeOfNodes); + nodedata[1].resize(sizeOfNodes); + nodedata[2].resize(sizeOfNodes); + nodedata[3].resize(sizeOfNodes); + nodedata[4].resize(sizeOfNodes); + nodedata[5].resize(sizeOfNodes); + ////////////////////////////////////////////////////////////////////////// + for (unsigned int pos = startpos; pos < endpos; pos++) + { + if (para->getParH(level)->geoSP[pos] == GEO_FLUID) + { + ////////////////////////////////////////////////////////////////////////// + double x1 = para->getParH(level)->coordX_SP[pos]; + double x2 = para->getParH(level)->coordY_SP[pos]; + double x3 = para->getParH(level)->coordZ_SP[pos]; + ////////////////////////////////////////////////////////////////////////// + number1 = pos; + dn1 = pos - startpos; + neighborsAreFluid = true; + ////////////////////////////////////////////////////////////////////////// + nodes[dn1] = (makeUbTuple((float)(x1), (float)(x2), (float)(x3))); + nodedata[0][dn1] = (double)para->getParH(level)->press_SP[pos] / (double)3.0 * (double)para->getDensityRatio() * (double)para->getVelocityRatio() * (double)para->getVelocityRatio(); + nodedata[1][dn1] = (double)para->getParH(level)->rho_SP[pos] / (double)3.0 * (double)para->getDensityRatio() * (double)para->getVelocityRatio() * (double)para->getVelocityRatio(); + nodedata[2][dn1] = (double)para->getParH(level)->vx_SP[pos] * (double)para->getVelocityRatio(); + nodedata[3][dn1] = (double)para->getParH(level)->vy_SP[pos] * (double)para->getVelocityRatio(); + nodedata[4][dn1] = (double)para->getParH(level)->vz_SP[pos] * (double)para->getVelocityRatio(); + nodedata[5][dn1] = (double)para->getParH(level)->geoSP[pos]; + ////////////////////////////////////////////////////////////////////////// + number2 = para->getParH(level)->neighborX_SP[number1]; + number3 = para->getParH(level)->neighborY_SP[number2]; + number4 = para->getParH(level)->neighborY_SP[number1]; + number5 = para->getParH(level)->neighborZ_SP[number1]; + number6 = para->getParH(level)->neighborZ_SP[number2]; + number7 = para->getParH(level)->neighborZ_SP[number3]; + number8 = para->getParH(level)->neighborZ_SP[number4]; + ////////////////////////////////////////////////////////////////////////// + if (para->getParH(level)->geoSP[number2] != GEO_FLUID || + para->getParH(level)->geoSP[number3] != GEO_FLUID || + para->getParH(level)->geoSP[number4] != GEO_FLUID || + para->getParH(level)->geoSP[number5] != GEO_FLUID || + para->getParH(level)->geoSP[number6] != GEO_FLUID || + para->getParH(level)->geoSP[number7] != GEO_FLUID || + para->getParH(level)->geoSP[number8] != GEO_FLUID) neighborsAreFluid = false; + ////////////////////////////////////////////////////////////////////////// + if (number2 > endpos || + number3 > endpos || + number4 > endpos || + number5 > endpos || + number6 > endpos || + number7 > endpos || + number8 > endpos) neighborsAreFluid = false; + ////////////////////////////////////////////////////////////////////////// + dn2 = number2 - startpos; + dn3 = number3 - startpos; + dn4 = number4 - startpos; + dn5 = number5 - startpos; + dn6 = number6 - startpos; + dn7 = number7 - startpos; + dn8 = number8 - startpos; + ////////////////////////////////////////////////////////////////////////// + if (neighborsAreFluid) + cells.push_back(makeUbTuple(dn1, dn2, dn3, dn4, dn5, dn6, dn7, dn8)); + } + } + WbWriterVtkXmlBinary::getInstance()->writeOctsWithNodeData(fname[part], nodes, cells, nodedatanames, nodedata); + } +} \ No newline at end of file diff --git a/src/VirtualFluids_GPU/Output/FileWriter.h b/src/VirtualFluids_GPU/Output/FileWriter.h new file mode 100644 index 0000000000000000000000000000000000000000..23d83096428359c6e59b75053c98bca07c7594ac --- /dev/null +++ b/src/VirtualFluids_GPU/Output/FileWriter.h @@ -0,0 +1,26 @@ +#ifndef FILE_WRITER_H +#define FILE_WRITER_H + +#include <memory> + +#include <VirtualFluidsDefinitions.h> + +#include "DataWriter.h" + +class Parameter; + +class FileWriter : public DataWriter +{ +public: + VF_PUBLIC FileWriter() {} + + void VF_PUBLIC writeInit(std::shared_ptr<Parameter> para) override; + void VF_PUBLIC writeTimestep(std::shared_ptr<Parameter> para, unsigned int timestep) override; + +private: + void writeTimestep(std::shared_ptr<Parameter> para, unsigned int timestep, int level); + void writeUnstrucuredGridLT(std::shared_ptr<Parameter> para, int level, std::vector<std::string>& fname); + + FileWriter(const FileWriter& fileWriter) {}; +}; +#endif \ No newline at end of file diff --git a/src/VirtualFluids_GPU/Parameter/Parameter.cpp b/src/VirtualFluids_GPU/Parameter/Parameter.cpp index 18ad48b308c4800b32e4b0502f09dd87d387ec93..cf4b7cb24f859bc2c3f0d8c607332c51c72896f7 100644 --- a/src/VirtualFluids_GPU/Parameter/Parameter.cpp +++ b/src/VirtualFluids_GPU/Parameter/Parameter.cpp @@ -12,7 +12,7 @@ //#endif //lib for windows Ws2_32.lib -SPtr<Parameter> Parameter::makeShared() +SPtr<Parameter> Parameter::make() { return SPtr<Parameter>(new Parameter()); } diff --git a/src/VirtualFluids_GPU/Parameter/Parameter.h b/src/VirtualFluids_GPU/Parameter/Parameter.h index b206a1ac1b0bb6645820ebe868800ad7abef4280..b5bb7c85f78466458c583fe7eaf15ae7680bb7e9 100644 --- a/src/VirtualFluids_GPU/Parameter/Parameter.h +++ b/src/VirtualFluids_GPU/Parameter/Parameter.h @@ -274,7 +274,7 @@ public: ////really ugly...should be in private... //Parameter(); //////////////////////////////////////////////////////////////////////////// - static SPtr<Parameter> makeShared(); + static SPtr<Parameter> make(); static Parameter* getInstanz(); diff --git a/targets/apps/HULC/main.cpp b/targets/apps/HULC/main.cpp index 5b4959bd873f6beef26ca2bbf2632c5b7d8a21f5..b85d1632b514074a2747f66839c6247ad233e5d0 100644 --- a/targets/apps/HULC/main.cpp +++ b/targets/apps/HULC/main.cpp @@ -33,6 +33,7 @@ #include "io/STLReaderWriter/STLReader.h" #include "io/STLReaderWriter/STLWriter.h" #include "geometries/TriangularMesh/TriangularMeshStrategy.h" +#include "Output/FileWriter.h" std::string getGridPath(std::shared_ptr<Parameter> para, std::string Gridpath) @@ -320,7 +321,7 @@ void multipleLevel(const std::string& configPath) //gridBuilder->writeGridToVTK("D:/GRIDGENERATION/gridTest_level_0", 0); //gridBuilder->writeGridToVTK("D:/GRIDGENERATION/gridTest_level_2", 2); - SPtr<Parameter> para = Parameter::makeShared(); + SPtr<Parameter> para = Parameter::make(); SPtr<GridProvider> gridGenerator = GridProvider::makeGridGenerator(gridBuilder, para); //SPtr<GridProvider> gridGenerator = GridProvider::makeGridReader(false, para); @@ -334,7 +335,8 @@ void multipleLevel(const std::string& configPath) setParameters(para, input); Simulation sim; - sim.init(para, gridGenerator); + SPtr<FileWriter> fileWriter = SPtr<FileWriter>(new FileWriter()); + sim.init(para, gridGenerator, fileWriter); sim.run(); } diff --git a/targets/tests/TestingHULC/3rdPartyLinking.cmake b/targets/tests/TestingHULC/3rdPartyLinking.cmake new file mode 100644 index 0000000000000000000000000000000000000000..fee6eff6c8413bab0effc6f1e7d1a8be68ba0225 --- /dev/null +++ b/targets/tests/TestingHULC/3rdPartyLinking.cmake @@ -0,0 +1,8 @@ +include (${CMAKE_SOURCE_DIR}/${cmakeMacroPath}/GMock/Link.cmake) +linkGMock(${targetName}) +include (${CMAKE_SOURCE_DIR}/${cmakeMacroPath}/Cuda/Link.cmake) +linkCuda(${targetName}) +include (${CMAKE_SOURCE_DIR}/${cmakeMacroPath}/MPI/Link.cmake) +linkMPI(${targetName}) +include (${CMAKE_SOURCE_DIR}/${cmakeMacroPath}/fftw/Link.cmake) +linkFftw(${targetName}) \ No newline at end of file diff --git a/targets/tests/TestingHULC/CMakeLists.txt b/targets/tests/TestingHULC/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..1ff89574c313cad237fa2196c8d6c58f1c21e9b7 --- /dev/null +++ b/targets/tests/TestingHULC/CMakeLists.txt @@ -0,0 +1,14 @@ +setTargetNameToFolderName(${CMAKE_CURRENT_LIST_DIR}) + +set(linkDirectories "") +set(libsToLink VirtualFluids_GPU cudart_static VirtualFluidsBasics) +set(includeDirectories ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/VirtualFluids_GPU ${CMAKE_SOURCE_DIR}/src/VirtualFluidsBasics) + +#glob files and save in MY_SRCS +include(CMakePackage.cmake) + +buildExe(${targetName} "${MY_SRCS}" "${linkDirectories}" "${libsToLink}" "${includeDirectories}") +groupTarget(${targetName} ${testFolder}) + +#Specify the linking to 3rdParty libs +include(3rdPartyLinking.cmake) \ No newline at end of file diff --git a/targets/tests/TestingHULC/CMakePackage.cmake b/targets/tests/TestingHULC/CMakePackage.cmake new file mode 100644 index 0000000000000000000000000000000000000000..317ed1a80f5c28a26ca65b4ade1d20ca1b422f0b --- /dev/null +++ b/targets/tests/TestingHULC/CMakePackage.cmake @@ -0,0 +1,7 @@ +#FILE ENDINGS +resetFileEndingsToCollect() +addCAndCPPFileTypes() + +#GLOB SOURCE FILES IN MY_SRCS +unset(MY_SRCS) +includeRecursiveAllFilesFrom(${targetName} ${CMAKE_CURRENT_LIST_DIR}) \ No newline at end of file diff --git a/targets/tests/TestingHULC/TaylorGreenVortex/package.include b/targets/tests/TestingHULC/TaylorGreenVortex/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Tests/DataCollector/DataCollector.cpp b/targets/tests/TestingHULC/Tests/DataCollector/DataCollector.cpp new file mode 100644 index 0000000000000000000000000000000000000000..47e363ecdeffdd50a1a5ff2bb0a16f4b2c77420d --- /dev/null +++ b/targets/tests/TestingHULC/Tests/DataCollector/DataCollector.cpp @@ -0,0 +1,60 @@ +#include "DataCollector.h" +#include "Tests\DataQueue\DataQueue.h" +#include "Utilities\EvaluationParameter\EvaluationParameter.h" + + +DataCollector::DataCollector(DataQueue * dataQueueNu, DataQueue * dataQueuePhi, const int arraySize, std::string testName) +{ + this->dataQueueNu = dataQueueNu; + this->dataQueuePhi = dataQueuePhi; + this->arraySize = arraySize; + this->testName = testName; + for (int i = 0; i < arraySize; i++) { + dataQueueNu[i].valueName = "NuDiff"; + dataQueuePhi[i].valueName = "Phi"; + } +} + +void DataCollector::addNuDiffAndPhi(double nudiff, double phi, std::shared_ptr<EvaluationParameter> evaPara) +{ + if (evaPara->getTestName() == testName) { + addDataToQueue(nudiff, dataQueueNu, evaPara); + addDataToQueue(phi, dataQueuePhi, evaPara); + } +} + +void DataCollector::addDataToQueue(double data, DataQueue * dataQueue, std::shared_ptr<EvaluationParameter> evaPara) +{ + int n = dataQueue[0].numberOfTests; + if (n == 0) { + dataQueue[n].a = data; + dataQueue[n].la = evaPara->getLx(); + } + else if (n == evaPara->getNumberOfEqualTests() - 1) { + dataQueue[n - 1].b = data; + dataQueue[n - 1].lb = evaPara->getLx(); + dataQueue[n - 1].orderOfAccuracy = log(dataQueue[n - 1].a / dataQueue[n - 1].b) / log(dataQueue[n - 1].lb / dataQueue[n - 1].la); + dataQueue[n - 1].minOrderOfAccuracy = evaPara->getMinOrderOfAccuracy(); + dataQueue[n - 1].testName = evaPara->getTestName(); + dataQueue[n - 1].expected = true; + } + else { + dataQueue[n - 1].b = data; + dataQueue[n - 1].lb = evaPara->getLx(); + dataQueue[n - 1].orderOfAccuracy = log(dataQueue[n - 1].a / dataQueue[n - 1].b) / log(dataQueue[n - 1].lb / dataQueue[n - 1].la); + dataQueue[n - 1].minOrderOfAccuracy = evaPara->getMinOrderOfAccuracy(); + dataQueue[n - 1].testName = evaPara->getTestName(); + dataQueue[n - 1].expected = true; + dataQueue[n].a = data; + dataQueue[n].la = evaPara->getLx(); + } + increaseNumberOfTestByOne(dataQueue); +} + +void DataCollector::increaseNumberOfTestByOne(DataQueue * dataQueue) +{ + for (int i = 0; i < arraySize; i++) + dataQueue[i].numberOfTests++; +} + + diff --git a/targets/tests/TestingHULC/Tests/DataCollector/DataCollector.h b/targets/tests/TestingHULC/Tests/DataCollector/DataCollector.h new file mode 100644 index 0000000000000000000000000000000000000000..8436cc06540840ccac893a2c02ddb9bbfe17c6a9 --- /dev/null +++ b/targets/tests/TestingHULC/Tests/DataCollector/DataCollector.h @@ -0,0 +1,26 @@ +#ifndef DATACONTAINERINITIALIZER_H +#define DATACONTAINERINITIALIZER_H + +#include <memory> +#include <string> + +struct DataQueue; +class EvaluationParameter; + +class DataCollector +{ +public: + DataCollector(DataQueue *DataQueueNu, DataQueue *DataQueuePhi, const int arraySize, std::string testName); + void addNuDiffAndPhi(double nudiff, double phi, std::shared_ptr<EvaluationParameter> evaPara); + + +private: + void addDataToQueue(double data, DataQueue *dataQueue, std::shared_ptr<EvaluationParameter> evaPara); + void increaseNumberOfTestByOne(DataQueue *dataQueue); + + int arraySize; + DataQueue *dataQueuePhi; + DataQueue *dataQueueNu; + std::string testName; +}; +#endif \ No newline at end of file diff --git a/targets/tests/TestingHULC/Tests/DataCollector/package.include b/targets/tests/TestingHULC/Tests/DataCollector/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Tests/DataQueue/DataQueue.cpp b/targets/tests/TestingHULC/Tests/DataQueue/DataQueue.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Tests/DataQueue/DataQueue.h b/targets/tests/TestingHULC/Tests/DataQueue/DataQueue.h new file mode 100644 index 0000000000000000000000000000000000000000..4622116734974e1e11be9a3ca093c9f35feedf12 --- /dev/null +++ b/targets/tests/TestingHULC/Tests/DataQueue/DataQueue.h @@ -0,0 +1,30 @@ +#ifndef DATASTORAGEFORTEST_H +#define DATASTORAGEFORTEST_H + +#include <string> + +struct DataQueue +{ + double a, b; + int la, lb; + bool expected; + int numberOfTests; + std::string testName; + std::string valueName; + double orderOfAccuracy, minOrderOfAccuracy; + + struct DataQueue() + { + a = 0.0; + b = 0.0; + la = 0; + lb = 0; + testName = "noTestName"; + valueName = "noValueName"; + expected = false; + numberOfTests = 0; + orderOfAccuracy = 0.0; + minOrderOfAccuracy = 0.0; + } +}; +#endif \ No newline at end of file diff --git a/targets/tests/TestingHULC/Tests/DataQueue/package.include b/targets/tests/TestingHULC/Tests/DataQueue/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Tests/OrderOfAccuracy/OrderOfAccuracy.cpp b/targets/tests/TestingHULC/Tests/OrderOfAccuracy/OrderOfAccuracy.cpp new file mode 100644 index 0000000000000000000000000000000000000000..02fa93b22bad77366aca3497968bc3042e065cc2 --- /dev/null +++ b/targets/tests/TestingHULC/Tests/OrderOfAccuracy/OrderOfAccuracy.cpp @@ -0,0 +1,17 @@ +#include "OrderOfAccuracy.h" + +#include "Tests\TestCout\TestCout.h" +#include "Tests\DataQueue\DataQueue.h" + +TEST_P(OrderOfAccuracy, Test) { + DataQueue input = GetParam(); + if (input.expected) { + TEST_COUT(input.testName, input.la, input.lb, input.valueName, input.valueName, "OrderOfAccuracy", input.a, input.b, input.orderOfAccuracy); + } + ASSERT_THAT(OrderOfAccuracy::test(input.orderOfAccuracy, input.minOrderOfAccuracy), Eq(input.expected)); +} + +bool OrderOfAccuracy::test(double a, double b) +{ + return a>b; +} diff --git a/targets/tests/TestingHULC/Tests/OrderOfAccuracy/OrderOfAccuracy.h b/targets/tests/TestingHULC/Tests/OrderOfAccuracy/OrderOfAccuracy.h new file mode 100644 index 0000000000000000000000000000000000000000..f9fb958ceefc2fbaec93e0cabfb570c2403f4ab7 --- /dev/null +++ b/targets/tests/TestingHULC/Tests/OrderOfAccuracy/OrderOfAccuracy.h @@ -0,0 +1,15 @@ +#ifndef ORDEROFACCURACY_H +#define ORDEROFACCURACY_H + +#include "gmock\gmock.h" + +using namespace testing; + +class DataQueue; + +class OrderOfAccuracy : public ::testing::TestWithParam<DataQueue> { +public: + bool test(double a, double b); + +}; +#endif \ No newline at end of file diff --git a/targets/tests/TestingHULC/Tests/OrderOfAccuracy/package.include b/targets/tests/TestingHULC/Tests/OrderOfAccuracy/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Tests/TestCout/TestCout.cpp b/targets/tests/TestingHULC/Tests/TestCout/TestCout.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e1c8e2366725ff6620c25ed4d5572cd154d55f08 --- /dev/null +++ b/targets/tests/TestingHULC/Tests/TestCout/TestCout.cpp @@ -0,0 +1,60 @@ +#include "TestCout.h" + +#include <iomanip> +#include <ctime> + +TestCout::TestCout(std::string testName1, int l1, int l2, std::string nameWerte1, std::string nameWerte2, std::string nameWerte3, double testWert1, double testWert2, double testWert3) +{ + std::ostringstream oss1; + oss1 << testName1; + std::string output1 = oss1.str(); + + std::ostringstream oss2; + oss2 << "L: " << l1 << "\t" << "\t" << "\t" << "L: " << l2; + std::string output2 = oss2.str(); + + std::ostringstream oss3; + oss3 << nameWerte1 << ": " << testWert1 << std::setw(5) << "\t" << nameWerte2 << ": " << testWert2; + std::string output3 = oss3.str(); + + std::ostringstream oss4; + oss4 << nameWerte3 << ": " << testWert3; + std::string output4 = oss4.str(); + + PRINTTESTINFOSTART(); + PRINTF(output1.c_str()); + PRINTF(output2.c_str()); + PRINTF(output3.c_str()); + PRINTF(output4.c_str()); + PRINTTESTINFOEND(); +} + +TestCout::TestCout(std::string testName, int l) +{ + std::ostringstream oss1; + oss1 << "# TEST: " << std::setfill(' ') << std::left << std::setw(40) << testName << "#"; + std::string output1 = oss1.str(); + + std::ostringstream oss2; + oss2 << "# L: " << std::setfill(' ') << std::left << std::setw(43) << l << "#"; + std::string output2 = oss2.str(); + + std::ostringstream oss3; + time_t now; + struct tm nowLocal; + now = time(NULL); + nowLocal = *localtime(&now); + oss3 << "# DATUM: " << std::setfill('0') << std::setw(2) << nowLocal.tm_mday << "." << std::setw(2) << nowLocal.tm_mon + 1 << "." << nowLocal.tm_year + 1900 << " TIME: " << std::setw(2) << nowLocal.tm_hour << ":" << std::setw(2) << nowLocal.tm_min << ":" << std::setw(2) << nowLocal.tm_sec << "\t" << "\t#"; + std::string output3 = oss3.str(); + + PRINTRAUTE(); + PRINTC(output1.c_str()); + PRINTC(output2.c_str()); + PRINTC(output3.c_str()); + PRINTRAUTE(); +} + +TestCout::~TestCout() +{ + +} diff --git a/targets/tests/TestingHULC/Tests/TestCout/TestCout.h b/targets/tests/TestingHULC/Tests/TestCout/TestCout.h new file mode 100644 index 0000000000000000000000000000000000000000..844b1e9237aaf6a6b2a5b4bde42aed9160352772 --- /dev/null +++ b/targets/tests/TestingHULC/Tests/TestCout/TestCout.h @@ -0,0 +1,49 @@ +#ifndef TEST_COUT_H +#define TEST_COUT_H + + +#include <sstream> +#include <gtest/gtest.h> + +// https://stackoverflow.com/questions/16491675/how-to-send-custom-message-in-google-c-testing-framework/29155677#29155677 +namespace testing +{ + namespace internal + { + enum GTestColor { + COLOR_DEFAULT, + COLOR_RED, + COLOR_GREEN, + COLOR_YELLOW + }; + + // in case of unresoved external while using shared libraries + // add in gtest.h line 167 and 168: + // enum GTestColor; + // void GTEST_API_ ColoredPrintf(GTestColor color, const char* fmt, ...); + // see commit: 4c0ed885ceab18b9df7a2495c77a51e236aee6f1 + extern void ColoredPrintf(GTestColor color, const char* fmt, ...); + } +} +#define PRINTTESTINFOSTART() do { testing::internal::ColoredPrintf(testing::internal::COLOR_GREEN, "[TestInfo ]");std::cout << std::endl;} while(0) +#define PRINTF(h) do { testing::internal::ColoredPrintf(testing::internal::COLOR_GREEN, "[ ] "); testing::internal::ColoredPrintf(testing::internal::COLOR_DEFAULT, h); std::cout << std::endl;} while(0) +#define PRINTTESTINFOEND() do { testing::internal::ColoredPrintf(testing::internal::COLOR_GREEN, "[ TestInfo]");std::cout << std::endl;} while(0) + +#define PRINTRAUTE() do { testing::internal::ColoredPrintf(testing::internal::COLOR_GREEN, "#################################################");std::cout << std::endl;} while(0) +#define PRINTC(h) do { testing::internal::ColoredPrintf(testing::internal::COLOR_GREEN, h); std::cout << std::endl;} while(0) + +// C++ stream interface +class TestCout : public std::stringstream +{ +public: + TestCout(std::string testName1, int l1, int l2, std::string nameWerte1, std::string nameWerte2, std::string nameWerte3, double testWert1, double testWert2, double testWert3); + TestCout(std::string testName, int l); + ~TestCout(); + +private: +}; + +#define TEST_COUT(testName1, l1, l2, nameWerte1, nameWerte2, nameWerte3, testWert1, testWert2, testWert3) TestCout(testName1, l1, l2, nameWerte1, nameWerte2, nameWerte3,testWert1, testWert2, testWert3) +#define TEST_HEAD(testName, l) TestCout(testName, l) + +#endif \ No newline at end of file diff --git a/targets/tests/TestingHULC/Tests/TestCout/package.include b/targets/tests/TestingHULC/Tests/TestCout/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/AnalyticalResultProvider/AnalyticalResultProvider.cpp b/targets/tests/TestingHULC/Utilities/AnalyticalResultProvider/AnalyticalResultProvider.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/AnalyticalResultProvider/AnalyticalResultProvider.h b/targets/tests/TestingHULC/Utilities/AnalyticalResultProvider/AnalyticalResultProvider.h new file mode 100644 index 0000000000000000000000000000000000000000..684858508c9c56e16ba100037c9a5c9682fe88f4 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/AnalyticalResultProvider/AnalyticalResultProvider.h @@ -0,0 +1,22 @@ +#ifndef ANALYTICAL_RESULT_H +#define ANALYTICAL_RESULT_H + +#include <vector> +#include <memory> + +class Results; +class Parameter; + +class AnalyticalResultProvider +{ +public: + virtual std::vector < std::shared_ptr<Results> > getAnalyticalResults() = 0; + +protected: + virtual void calculate() = 0; + virtual void init(std::vector< std::shared_ptr<Results> > simulationResults) = 0; + + std::vector< std::shared_ptr<Results> > analyticalResults; + unsigned int numberNodes; +}; +#endif \ No newline at end of file diff --git a/targets/tests/TestingHULC/Utilities/AnalyticalResultProvider/TaylorGreenVortex/TaylorGreenAnalytical.cpp b/targets/tests/TestingHULC/Utilities/AnalyticalResultProvider/TaylorGreenVortex/TaylorGreenAnalytical.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e481c3be754a6a35e52c42ae66d354968b6c0449 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/AnalyticalResultProvider/TaylorGreenVortex/TaylorGreenAnalytical.cpp @@ -0,0 +1,75 @@ +/*#include "TaylorGreenAnalytical.h" + +#include "../../Results/Results.h" +#include "utilities/TestCondition/TaylorGreenVortex/TaylorGreenTestCondition.h" + +#define _USE_MATH_DEFINES +#include <math.h> +#include <iostream> + + +TaylorGreenAnalytical::TaylorGreenAnalytical(std::vector< std::shared_ptr<Results> > simulationResults, std::shared_ptr<TaylorGreenTestCondition> testCondition) +{ + /*Amp = testCondition->getAmp(); + L = testCondition->getL(); + L0 = testCondition->getL0(); + rho0 = testCondition->getRho0(); + vis = testCondition->getViscosity(); + Lx = testCondition->getLx(); + Lz = testCondition->getLz(); + numberNodes = Lx * Lz; + this->init(simulationResults); + this->calculate(); +} + +std::vector<std::shared_ptr<Results>> TaylorGreenAnalytical::getAnalyticalResults() +{ + return analyticalResults; +} + +void TaylorGreenAnalytical::init(std::vector< std::shared_ptr<Results> > simulationResults) +{ + std::cout << "Initialize analytical Solution...\n"; + analyticalResults.resize(simulationResults.size()); + for (int i = 0; i < analyticalResults.size(); i++) + { + std::cout << "Initialize analytical solution TaylorGreenVortex 2D Timestep: " << i << std::endl; + analyticalResults[i] = std::shared_ptr<Results>(new Results); + analyticalResults[i]->setNumberofNodes(numberNodes); + + analyticalResults[i]->setTime(simulationResults[i]->getTime()); + analyticalResults[i]->setTimeStep(simulationResults[i]->getTimeStep()); + for (int j = 0; j < numberNodes; j++) + { + analyticalResults[i]->setX(j, simulationResults[i]->getX()[j]); + analyticalResults[i]->setY(j, simulationResults[i]->getY()[j]); + analyticalResults[i]->setZ(j, simulationResults[i]->getZ()[j]); + } + } + +} + +void TaylorGreenAnalytical::calculate() +{ + for (int i = 0; i < analyticalResults.size(); i++) + { + std::cout << "Calculate analytical solution TaylorGreenVortex 2D Timestep: " << i << std::endl; + t = analyticalResults[i]->getTime(); + for (int j = 0; j < numberNodes; j++) + { + x = analyticalResults[i]->getX()[j]; + z = analyticalResults[i]->getZ()[j]; + + vx = (Amp * L0 * cos((real)2.0 * M_PI * z * Lx / (Lz * L)) * sin((real)2.0 * M_PI * x / L) / L) * exp((real) -4.0 * (Lx*Lx + Lz*Lz) * M_PI*M_PI * t * vis / (L*L * Lz*Lz)); + vz = (-Amp * L0 * Lz * cos((real)2.0 * M_PI * x / L) * sin((real)2.0 * M_PI * z * Lx / (L * Lz)) / (L*Lx)) * exp((real)-4.0 * (Lx*Lx + Lz*Lz) * M_PI*M_PI * t * vis / (L*L * Lz*Lz)); + press = (Amp*Amp * L0*L0 * Lz*Lz * rho0 / ((real)16.0 * Lx*Lx * M_PI*M_PI)) * (((real)4.0 * Lx*Lx / (L*L * Lz*Lz)) * M_PI*M_PI * cos(((real)4.0 / L) * M_PI * x) + ((real)4.0 / (L*L)) * M_PI*M_PI * cos(((real)4.0 * Lx / (L * Lz)) * M_PI * z)) * exp((real)-8.0 * (Lx*Lx * Lz*Lz) * M_PI*M_PI * t * vis /(L*L * Lz*Lz)); + + analyticalResults[i]->setVx(j, vx); + analyticalResults[i]->setVy(j, (real) 0.0); + analyticalResults[i]->setVz(j, vz); + analyticalResults[i]->setPress(j, press); + + } + } + +}*/ diff --git a/targets/tests/TestingHULC/Utilities/AnalyticalResultProvider/TaylorGreenVortex/TaylorGreenAnalytical.h b/targets/tests/TestingHULC/Utilities/AnalyticalResultProvider/TaylorGreenVortex/TaylorGreenAnalytical.h new file mode 100644 index 0000000000000000000000000000000000000000..1b62f6e5039dadd03193fc7b89ed32a2d55ea037 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/AnalyticalResultProvider/TaylorGreenVortex/TaylorGreenAnalytical.h @@ -0,0 +1,29 @@ +#ifndef AN_RESULT_TAYLOR_GREEN_VORTEX_H +#define AN_RESULT_TAYLOR_GREEN_VORTEX_H + +#include "../AnalyticalResultProvider.h" +#include "VirtualFluids_GPU/LBM/LB.h" + +class Results; +class TaylorGreenTestCondition; + +class TaylorGreenAnalytical : public AnalyticalResultProvider +{ +public: + TaylorGreenAnalytical(std::vector< std::shared_ptr<Results> > simulationResults,std::shared_ptr<TaylorGreenTestCondition> testCondition); + std::vector < std::shared_ptr<Results> > getAnalyticalResults(); + +private: + void init(std::vector< std::shared_ptr<Results> > simulationResults); + void calculate(); + + real t; + real x, z; + real vx, vz; + real press; + real Amp; + real L, L0, Lx, Lz; + real rho0, vis; + +}; +#endif \ No newline at end of file diff --git a/targets/tests/TestingHULC/Utilities/AnalyticalResultProvider/TaylorGreenVortex/package.include b/targets/tests/TestingHULC/Utilities/AnalyticalResultProvider/TaylorGreenVortex/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/AnalyticalResultProvider/package.include b/targets/tests/TestingHULC/Utilities/AnalyticalResultProvider/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/Calculator/Calculator.cpp b/targets/tests/TestingHULC/Utilities/Calculator/Calculator.cpp new file mode 100644 index 0000000000000000000000000000000000000000..14e8797f3bcc94c04808480b4bbf840203105daf --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/Calculator/Calculator.cpp @@ -0,0 +1,158 @@ +#include "Calculator.h" + +#include "Utilities\Results\Results.h" +#include "Utilities\EvaluationParameter\EvaluationParameter.h" + +#define _USE_MATH_DEFINES +#include <math.h> +#include <stdlib.h> + +Calulator::Calulator(std::shared_ptr<Results> simResults, std::shared_ptr<EvaluationParameter> evaPara):simResults(simResults) +{ + if (evaPara->getDataToCalculate() == "vX") + data = simResults->getVx(); + if (evaPara->getDataToCalculate() == "vZ") + data = simResults->getVz(); + + lz = (double)simResults->getZNodes(); + lx = (double)simResults->getXNodes(); + timeStepLength = simResults->getTimeStepLength(); + vis = evaPara->getViscosity(); + numberOfTimeSteps = simResults->getNumberOfTimeSteps(); + fftCalculated = false; +} + +double Calulator::calcNu() +{ + calcLogAmplitudeForAllTimeSteps(); + std::vector<double> linReg = calcLinReg(logAmplitude); + double nu = -(1.0 / (((2.0 * M_PI / lz) * (2.0 * M_PI / lz) + (2.0 * M_PI / lx)*(2.0 * M_PI / lx)) * timeStepLength)) * linReg.at(0); + + return nu; +} + +double Calulator::calcNuDiff(double nu) +{ + double nudiff = abs((nu - vis) / vis); + return nudiff; +} + +double Calulator::calcPhiDiff() +{ + calcPhiForAllTimeSteps(); + std::vector<double> linReg = calcLinReg(phi); + + return linReg.at(0); +} + +void Calulator::calcLogAmplitudeForAllTimeSteps() +{ + calcAmplitudeForAllTimeSteps(); + logAmplitude.resize(amplitude.size()); + for(int tS=0; tS<amplitude.size();tS++) + logAmplitude.at(tS) = log(amplitude.at(tS)); +} + +std::vector<double> Calulator::calcLinReg(std::vector<double> y) +{ + std::vector<double> result; + std::vector<double> x(y.size()); + double sumX = 0.0; + double sumY = 0.0; + + for (int i = 0; i < y.size(); i++) + { + sumY += y.at(i); + x.at(i) = i; + sumX += i; + } + double avgX = sumX / y.size(); + double avgY = sumY / y.size(); + double zaehler = 0.0; + double nenner = 0.0; + for (int i = 0; i < y.size(); i++) + { + zaehler += (x.at(i) - avgX) * (y.at(i) - avgY); + nenner += (x.at(i) - avgX) * (x.at(i) - avgX); + } + double a1 = zaehler / nenner; + result.push_back(a1); + double a0 = avgY - a1*avgX; + result.push_back(a0); + + double ess = 0; + double tss = 0; + for (int i = 0; i < y.size(); i++) + { + ess += ((a0+a1*x.at(i))-avgY) * ((a0 + a1*x.at(i)) - avgY); + tss += (y.at(i)-avgY) * (y.at(i) - avgY); + } + double r2 = ess / tss; + result.push_back(r2); + return result; +} + +void Calulator::calcAmplitudeForAllTimeSteps() +{ + if (fftCalculated == false) { + for (int timeStep = 0; timeStep < numberOfTimeSteps; timeStep++) + calcFFT2D(timeStep); + fftCalculated = true; + } + int pos = 2 + (lx - 1); + for (int timeStep = 0; timeStep < numberOfTimeSteps; timeStep++) + amplitude.push_back(4.0 / (lx * lz) * sqrt(fftResultsRe.at(timeStep).at(pos) * fftResultsRe.at(timeStep).at(pos) + fftResultsIm.at(timeStep).at(pos) * fftResultsIm.at(timeStep).at(pos))); +} + +void Calulator::calcPhiForAllTimeSteps() +{ + if (fftCalculated == false) { + for (int timeStep = 0; timeStep < numberOfTimeSteps; timeStep++) + calcFFT2D(timeStep); + fftCalculated = true; + } + int pos = 2 + (lx - 1); + for (int timeStep = 0; timeStep < numberOfTimeSteps; timeStep++) + phi.push_back(atan(fftResultsIm.at(timeStep).at(pos) / fftResultsRe.at(timeStep).at(pos))); +} + +void Calulator::calcFFT2D(unsigned int timeStep) +{ + fftw_complex *in = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * lx * lz); + fftw_complex *out = (fftw_complex*)fftw_malloc(sizeof(fftw_complex) * lx * lz); + + initDataForFFT(in, timeStep); + + fftw_plan p = fftw_plan_dft_2d(lz, lx, in, out, FFTW_FORWARD, FFTW_ESTIMATE); + fftw_execute(p); + + setFFTResults(out, timeStep); + + fftw_destroy_plan(p); + fftw_free(in); + fftw_free(out); +} + +void Calulator::initDataForFFT(fftw_complex * input, unsigned int timeStep) +{ + for (int i = 0; i < data.at(timeStep).size(); i++) + { + input[i][0] = data.at(timeStep).at(i); + input[i][1] = 0; + } +} + +void Calulator::setFFTResults(fftw_complex * result, unsigned int timeStep) +{ + std::vector<double> fftRe, fftIm; + fftRe.resize(data.at(timeStep).size()); + fftIm.resize(data.at(timeStep).size()); + + for (int i = 0; i < data.at(timeStep).size(); i++) + { + fftRe.at(i) = result[i][0]; + fftIm.at(i) = result[i][1]; + } + fftResultsIm.push_back(fftIm); + fftResultsRe.push_back(fftRe); +} diff --git a/targets/tests/TestingHULC/Utilities/Calculator/Calculator.h b/targets/tests/TestingHULC/Utilities/Calculator/Calculator.h new file mode 100644 index 0000000000000000000000000000000000000000..67b8e164d499d1e6569e18b875b33fb8087fa51d --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/Calculator/Calculator.h @@ -0,0 +1,45 @@ +#ifndef CALCULATOR_H +#define CALCULATOR_H + +#include <memory> +#include <vector> +#include <fftw3.h> + +class Results; +class EvaluationParameter; + +class Calulator { +public: + Calulator(std::shared_ptr<Results> simResults, std::shared_ptr<EvaluationParameter> evaPara); + + + double calcNu(); + double calcNuDiff(double nu); + double calcPhiDiff(); + +private: + std::vector<double> calcLinReg(std::vector<double> y); + void calcLogAmplitudeForAllTimeSteps(); + void calcAmplitudeForAllTimeSteps(); + void calcPhiForAllTimeSteps(); + void calcFFT2D(unsigned int timeStep); + void initDataForFFT(fftw_complex* input, unsigned int timeStep); + void setFFTResults(fftw_complex* result, unsigned int timeStep); + + std::shared_ptr<Results> simResults; + + std::vector<std::vector<double>> data; + std::vector<std::vector<double>> fftResultsIm; + std::vector<std::vector<double>> fftResultsRe; + std::vector<double> phi; + std::vector<double> amplitude; + std::vector<double> logAmplitude; + + bool fftCalculated; + + double lx, lz; + double timeStepLength; + double vis; + int numberOfTimeSteps; +}; +#endif diff --git a/targets/tests/TestingHULC/Utilities/Calculator/package.include b/targets/tests/TestingHULC/Utilities/Calculator/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/DataWriter/ToVectorWriter.cpp b/targets/tests/TestingHULC/Utilities/DataWriter/ToVectorWriter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ddd0cabb062552132e861c576c60439fd2009d69 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/DataWriter/ToVectorWriter.cpp @@ -0,0 +1,35 @@ +#include "ToVectorWriter.h" + +#include "VirtualFluids_GPU/Output/FileWriter.h" +#include "VirtualFluids_GPU/Parameter/Parameter.h" + +ToVectorWriter::ToVectorWriter(unsigned int ySliceForCalculation, unsigned int startTimeY2dSliceToVector, unsigned int endTime, unsigned int timeStepLength, bool writeFiles, std::shared_ptr<FileWriter> fileWriter, unsigned int startTimeDataWriter) +{ + this->writeFiles = writeFiles; + this->fileWriter = fileWriter; + this->ySliceForCalculation = ySliceForCalculation; + this->startTimeY2dSliceToVector = startTimeY2dSliceToVector; + this->startTimeDataWriter = startTimeDataWriter; + this->endTime = endTime; +} + +void ToVectorWriter::writeInit(std::shared_ptr<Parameter> para) +{ + if (startTimeY2dSliceToVector == 0) + writeTimestep(para, 0); + if (writeFiles && startTimeDataWriter == 0) + fileWriter->writeTimestep(para, 0); +} + +void ToVectorWriter::writeTimestep(std::shared_ptr<Parameter> para, unsigned int t) +{ + if (startTimeY2dSliceToVector <= t && endTime >= t) + { + for (int level = para->getCoarse(); level <= para->getFine(); level++) + { + writeTimestep(para, t, level); + } + } + if (writeFiles && startTimeDataWriter < t) + fileWriter->writeTimestep(para, t); +} diff --git a/targets/tests/TestingHULC/Utilities/DataWriter/ToVectorWriter.h b/targets/tests/TestingHULC/Utilities/DataWriter/ToVectorWriter.h new file mode 100644 index 0000000000000000000000000000000000000000..ead0ac0ddae19a493b69386e8a01270c9c32fd64 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/DataWriter/ToVectorWriter.h @@ -0,0 +1,33 @@ +#ifndef WRITE_TO_VECTOR_H +#define WRITE_TO_VECTOR_H + +#include "VirtualFluids_GPU/Output/DataWriter.h" + +class Parameter; +class Results; +class FileWriter; + +class ToVectorWriter : public DataWriter +{ +public: + ToVectorWriter(unsigned int ySliceForCalculation, unsigned int startTimeY2dSliceToVector, unsigned int endTime, unsigned int timeStepLength, bool writeFiles, std::shared_ptr<FileWriter> fileWriter, unsigned int startTimeDataWriter); + + void writeInit(std::shared_ptr<Parameter> para); + void writeTimestep(std::shared_ptr<Parameter> para, unsigned int t); + +protected: + virtual void writeTimestep(std::shared_ptr<Parameter> para, unsigned int t, int level) = 0; + void writeUnstrucuredGridLT(std::shared_ptr<Parameter> para, int level, std::vector<std::string >& fname) {}; + + std::shared_ptr<FileWriter> fileWriter; + bool writeFiles; + + unsigned int ySliceForCalculation; + unsigned int counterTimeSteps; + unsigned int startTimeY2dSliceToVector, startTimeDataWriter; + unsigned int endTime; + unsigned int maxX, maxY, maxZ; +private: + +}; +#endif \ No newline at end of file diff --git a/targets/tests/TestingHULC/Utilities/DataWriter/Y2dSliceToResults/Y2dSliceToResults.cpp b/targets/tests/TestingHULC/Utilities/DataWriter/Y2dSliceToResults/Y2dSliceToResults.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8c23eb51b2fff8548e9ff23eb68e40d8a2392c68 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/DataWriter/Y2dSliceToResults/Y2dSliceToResults.cpp @@ -0,0 +1,54 @@ +#include "Y2dSliceToResults.h" + +#include "VirtualFluids_GPU/Parameter/Parameter.h" +#include "../../Results/Results.h" +#include "Utilities/TestCondition/TestCondition.h" + + +Y2dSliceToResults::Y2dSliceToResults(std::shared_ptr<Results> simResults, unsigned int ySliceForCalculation, unsigned int startTimeY2dSliceToVector, unsigned int endTime, unsigned int timeStepLength, bool writeFiles, std::shared_ptr<FileWriter> fileWriter, unsigned int startTimeDataWriter): ToVectorWriter(ySliceForCalculation, startTimeY2dSliceToVector, endTime, timeStepLength, writeFiles, fileWriter, startTimeDataWriter) +{ + this->simResults = simResults; + counterTimeSteps = 0; +} + +void Y2dSliceToResults::writeTimestep(std::shared_ptr<Parameter> para, unsigned int t, int level) +{ + counterTimeSteps++; + + maxX = para->getGridX().at(level); + maxY = para->getGridY().at(level); + maxZ = para->getGridZ().at(level); + + int numberNodes = (maxX - 1) * (maxZ - 1); + std::vector<double> x(numberNodes), z(numberNodes); + std::vector<double> vx(numberNodes), vz(numberNodes); + std::vector<double> press(numberNodes), rho(numberNodes); + + for (int posZ = 0; posZ < maxZ - 1; posZ++) + { + for (int posX = 0; posX < maxX - 1; posX++) + { + int posResults = CoordResults2DTo1D(posX, posZ); + int posPara = CoordPara3DTo1D(posX, ySliceForCalculation, posZ); + + x.at(posResults) = (double)para->getParH(level)->coordX_SP[posPara] - (double)1.0; + z.at(posResults) = (double)para->getParH(level)->coordY_SP[posPara] - (double)1.0; + vx.at(posResults) = (double)para->getParH(level)->vx_SP[posPara] * (double)para->getVelocityRatio(); + vz.at(posResults) = (double)para->getParH(level)->vz_SP[posPara] * (double)para->getVelocityRatio(); + press.at(posResults) = (double)para->getParH(level)->press_SP[posPara] / (double)3.0 * (double)para->getDensityRatio() * (double)para->getVelocityRatio() * (double)para->getVelocityRatio(); + rho.at(posResults) = (double)para->getParH(level)->rho_SP[posPara] / (double)3.0 * (double)para->getDensityRatio() * (double)para->getVelocityRatio() * (double)para->getVelocityRatio(); + } + } + simResults->addTimeStep(counterTimeSteps, t, x, z, vx, vz, press, rho); + counterTimeSteps++; +} + +int Y2dSliceToResults::CoordPara3DTo1D(int x, int y, int z) +{ + return z*maxY*maxX + y*maxX + x + 1; +} + +int Y2dSliceToResults::CoordResults2DTo1D(int x, int z) +{ + return z * (maxX - 1) + x; +} diff --git a/targets/tests/TestingHULC/Utilities/DataWriter/Y2dSliceToResults/Y2dSliceToResults.h b/targets/tests/TestingHULC/Utilities/DataWriter/Y2dSliceToResults/Y2dSliceToResults.h new file mode 100644 index 0000000000000000000000000000000000000000..947f896768cc1c9a6958523e36653b30ad84c951 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/DataWriter/Y2dSliceToResults/Y2dSliceToResults.h @@ -0,0 +1,24 @@ +#ifndef Y_2D_Slice_To_RESULTS_H +#define Y_2D_Slice_To_RESULTS_H + +#include "../ToVectorWriter.h" + +#include <vector> +#include <memory> + +class Parameter; + +class Y2dSliceToResults : public ToVectorWriter +{ +public: + Y2dSliceToResults(std::shared_ptr<Results> simResults, unsigned int ySliceForCalculation, unsigned int startTimeY2dSliceToVector, unsigned int endTime, unsigned int timeStepLength, bool writeFiles, std::shared_ptr<FileWriter> fileWriter, unsigned int startTimeDataWriter); + +private: + void writeTimestep(std::shared_ptr<Parameter> para, unsigned int t, int level); + + std::shared_ptr<Results> simResults; + int CoordPara3DTo1D(int x, int y, int z); + int CoordResults2DTo1D(int x, int z); + int counterTimeSteps; +}; +#endif \ No newline at end of file diff --git a/targets/tests/TestingHULC/Utilities/DataWriter/Y2dSliceToResults/package.include b/targets/tests/TestingHULC/Utilities/DataWriter/Y2dSliceToResults/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/DataWriter/package.include b/targets/tests/TestingHULC/Utilities/DataWriter/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/EvaluationParameter/EvaluationParameter.cpp b/targets/tests/TestingHULC/Utilities/EvaluationParameter/EvaluationParameter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b30a1064c5f44e7768dad9a5d3cbf5ac618cf747 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/EvaluationParameter/EvaluationParameter.cpp @@ -0,0 +1,67 @@ +#include "EvaluationParameter.h" + +std::shared_ptr<EvaluationParameter> EvaluationParameter::getNewInstance(std::string testNames, int numberOfEqualTests, int lx, std::string dataToCalculate, std::string logFilePath, double minOrderOfAccuracy, bool writeFiles, double viscosity) +{ + return std::shared_ptr<EvaluationParameter>(new EvaluationParameter(testNames, numberOfEqualTests, lx, dataToCalculate, logFilePath, minOrderOfAccuracy, writeFiles, viscosity)); +} + +EvaluationParameter::EvaluationParameter(std::string testName, int numberOfEqualTests, int lx, std::string dataToCalculate, std::string logFilePath, double minOrderOfAccuracy, bool writeFiles, double viscosity) + : lx(lx), testName(testName), numberOfEqualTests(numberOfEqualTests), dataToCalculate(dataToCalculate), logFilePath(logFilePath), minOrderOfAccuracy(minOrderOfAccuracy), writeFiles(writeFiles), viscosity(viscosity) +{ + +} + +std::string EvaluationParameter::getTestName() +{ + return testName; +} + +std::string EvaluationParameter::getDataToCalculate() +{ + return dataToCalculate; +} + +int EvaluationParameter::getLx() +{ + return lx; +} + +int EvaluationParameter::getNumberOfEqualTests() +{ + return numberOfEqualTests; +} + +void EvaluationParameter::setStartTime() +{ + startTime = time(NULL); +} + +void EvaluationParameter::setEndTime() +{ + endTime = time(NULL); +} + +double EvaluationParameter::getTestTime() +{ + return difftime(endTime, startTime); +} + +std::string EvaluationParameter::getLogFilePath() +{ + return logFilePath; +} + +double EvaluationParameter::getMinOrderOfAccuracy() +{ + return minOrderOfAccuracy; +} + +bool EvaluationParameter::getWriteFiles() +{ + return writeFiles; +} + +double EvaluationParameter::getViscosity() +{ + return viscosity; +} diff --git a/targets/tests/TestingHULC/Utilities/EvaluationParameter/EvaluationParameter.h b/targets/tests/TestingHULC/Utilities/EvaluationParameter/EvaluationParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..037ae9db203e6442b6d9eeb9f000a1ea9c5d1c4e --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/EvaluationParameter/EvaluationParameter.h @@ -0,0 +1,39 @@ +#ifndef EVALUATIONPARAMETER_H +#define EVALUATIONPARAMETER_H + +#include <memory> +#include <string> +#include <time.h> + +class EvaluationParameter +{ +public: + static std::shared_ptr<EvaluationParameter> getNewInstance(std::string testNames, int numberOfEqualTests, int lx, std::string dataToCalculate, std::string logFilePath, double minOrderOfAccuracy, bool writeFiles, double viscosity); + std::string getTestName(); + std::string getDataToCalculate(); + int getLx(); + int getNumberOfEqualTests(); + void setStartTime(); + void setEndTime(); + double getTestTime(); + std::string getLogFilePath(); + double getMinOrderOfAccuracy(); + bool getWriteFiles(); + double getViscosity(); + +protected: + EvaluationParameter() {}; + EvaluationParameter(std::string testNames, int numberOfEqualTests, int lx, std::string dataToCalculate, std::string logFilePath, double minOrderOfAccuracy, bool writeFiles, double viscosity); + +private: + int lx; + std::string testName; + int numberOfEqualTests; + std::string dataToCalculate; + time_t startTime, endTime; + std::string logFilePath; + double minOrderOfAccuracy; + bool writeFiles; + double viscosity; +}; +#endif diff --git a/targets/tests/TestingHULC/Utilities/EvaluationParameter/package.include b/targets/tests/TestingHULC/Utilities/EvaluationParameter/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/GridReaderforTesting/gridReaderforTesting.cpp b/targets/tests/TestingHULC/Utilities/GridReaderforTesting/gridReaderforTesting.cpp new file mode 100644 index 0000000000000000000000000000000000000000..696aefd62ea5663cab23249327f3434a55fd4034 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/GridReaderforTesting/gridReaderforTesting.cpp @@ -0,0 +1,28 @@ +#include "gridReaderforTesting.h" + +#include "VirtualFluids_GPU/Parameter/Parameter.h" + +#include "Utilities/InitialCondition/InitialCondition.h" + +#define _USE_MATH_DEFINES +#include <math.h> + + +void GridReaderforTesting::setInitalNodeValues(const int numberOfNodes, const int level) const +{ + initialCondition->init(level); + for (int j = 0; j <= numberOfNodes; j++) + { + para->getParH(level)->vx_SP[j] = initialCondition->getInitVX(j, level); + para->getParH(level)->vy_SP[j] = initialCondition->getInitVY(j, level); + para->getParH(level)->vz_SP[j] = initialCondition->getInitVZ(j, level); + para->getParH(level)->rho_SP[j] = initialCondition->getInitROH(j, level); + para->getParH(level)->press_SP[j] = initialCondition->getInitPRESS(j, level); + } +} + +GridReaderforTesting::GridReaderforTesting(std::shared_ptr<Parameter> para, std::shared_ptr<InitialCondition> initialCondition) :GridReader(true, para), initialCondition(initialCondition) +{ + +} + diff --git a/targets/tests/TestingHULC/Utilities/GridReaderforTesting/gridReaderforTesting.h b/targets/tests/TestingHULC/Utilities/GridReaderforTesting/gridReaderforTesting.h new file mode 100644 index 0000000000000000000000000000000000000000..4bbf5b2f5bddb409979ae728024f9f68e278b4b1 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/GridReaderforTesting/gridReaderforTesting.h @@ -0,0 +1,22 @@ +#ifndef GRIDREADER_FOR_TESTING_H +#define GRIDREADER_FOR_TESTING_H + +#include "VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.h" + +#include <memory> + +class InitialCondition; + +class GridReaderforTesting : public GridReader +{ +public: + + void setInitalNodeValues(const int numberOfNodes, const int level) const; + + GridReaderforTesting(std::shared_ptr<Parameter> para, std::shared_ptr<InitialCondition> initialCondition); + +private: + std::shared_ptr<InitialCondition> initialCondition; + +}; +#endif diff --git a/targets/tests/TestingHULC/Utilities/GridReaderforTesting/package.include b/targets/tests/TestingHULC/Utilities/GridReaderforTesting/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/InitialCondition/InitialCondition.h b/targets/tests/TestingHULC/Utilities/InitialCondition/InitialCondition.h new file mode 100644 index 0000000000000000000000000000000000000000..0735f39696efe134393f6fca66a5d318d59bcb13 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/InitialCondition/InitialCondition.h @@ -0,0 +1,23 @@ +#ifndef INITIAL_CONDITION_H +#define INITIAL_CONDITION_H + +#include "VirtualFluids_GPU/LBM/LB.h" + +#include <vector> +#include <memory> + +class Parameter; + +class InitialCondition +{ +public: + virtual void setParameter(std::shared_ptr<Parameter> para) = 0; + virtual void init(const int level) = 0; + virtual real getInitVX(int i, int level) = 0; + virtual real getInitVY(int i, int level) = 0; + virtual real getInitVZ(int i, int level) = 0; + virtual real getInitROH(int i, int level) = 0; + virtual real getInitPRESS(int i, int level) = 0; + +}; +#endif \ No newline at end of file diff --git a/targets/tests/TestingHULC/Utilities/InitialCondition/InitialConditionImp.cpp b/targets/tests/TestingHULC/Utilities/InitialCondition/InitialConditionImp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d9fda5e3806ffbc1bb1b55dad09c0bd93888914a --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/InitialCondition/InitialConditionImp.cpp @@ -0,0 +1,30 @@ +#include "InitialConditionImp.h" + +#include "VirtualFluids_GPU/Parameter/Parameter.h" + +void InitialConditionImp::setParameter(std::shared_ptr<Parameter> para) +{ + this->para = para; +} + +void InitialConditionImp::init(const int level) +{ + XCoordstopnode = para->getGridX().at(level) - 1.0 + 0.5; + YCoordstopnode = para->getGridY().at(level) - 1.0 + 0.5; + ZCoordstopnode = para->getGridZ().at(level) - 1.0 + 0.5; +} + +real InitialConditionImp::getXCoord(int i, int level) +{ + return (real)(para->getParH(level)->coordX_SP[i] - 1.0); +} + +real InitialConditionImp::getYCoord(int i, int level) +{ + return (real)(para->getParH(level)->coordY_SP[i] - 1.0); +} + +real InitialConditionImp::getZCoord(int i, int level) +{ + return (real)(para->getParH(level)->coordZ_SP[i] - 1.0); +} \ No newline at end of file diff --git a/targets/tests/TestingHULC/Utilities/InitialCondition/InitialConditionImp.h b/targets/tests/TestingHULC/Utilities/InitialCondition/InitialConditionImp.h new file mode 100644 index 0000000000000000000000000000000000000000..e499dfeef335181522b59780b612710dc83cba40 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/InitialCondition/InitialConditionImp.h @@ -0,0 +1,34 @@ +#ifndef INITIAL_CONDITION_IMP_H +#define INITIAL_CONDITION_IMP_H + +#include "InitialCondition.h" + +#include "VirtualFluids_GPU/LBM/LB.h" + +#include <vector> +#include <memory> + +class Parameter; + +class InitialConditionImp : public InitialCondition +{ +public: + void setParameter(std::shared_ptr<Parameter> para); + void init(const int level); + virtual real getInitVX(int i, int level) = 0; + virtual real getInitVY(int i, int level) = 0; + virtual real getInitVZ(int i, int level) = 0; + virtual real getInitROH(int i, int level) = 0; + virtual real getInitPRESS(int i, int level) = 0; + +protected: + InitialConditionImp() {}; + real getXCoord(int i, int level); + real getYCoord(int i, int level); + real getZCoord(int i, int level); + + std::shared_ptr<Parameter> para; + real XCoordstopnode, YCoordstopnode, ZCoordstopnode; + +}; +#endif \ No newline at end of file diff --git a/targets/tests/TestingHULC/Utilities/InitialCondition/ShearWave/InitialConditionShearWave.cpp b/targets/tests/TestingHULC/Utilities/InitialCondition/ShearWave/InitialConditionShearWave.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b6c56c1832203a3a6d6f355c4fc96b31fe137677 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/InitialCondition/ShearWave/InitialConditionShearWave.cpp @@ -0,0 +1,69 @@ +#include "InitialConditionShearWave.h" + +#define _USE_MATH_DEFINES +#include <math.h> + + +InitialConditionShearWave::InitialConditionShearWave(real lx, real lz, real l0, real u0, real v0, real rho0) +{ + this->l0 = l0; + this->lx = lx; + this->lz = lz; + this->rho = rho0; + this->u0 = u0; + this->v0 = v0; +} + +real InitialConditionShearWave::getInitVX(int i, int level) +{ + real x = getXCoord(i, level); + real y = getYCoord(i, level); + real z = getZCoord(i, level); + if ((i != 0) && (x != XCoordstopnode) && (y != YCoordstopnode) && (z != ZCoordstopnode)) + { + real vx = l0 * u0 / lx; + return vx; + } + else + return (real)0.0; + +} + +real InitialConditionShearWave::getInitVY(int i, int level) +{ + return (real) 0.0; +} + +real InitialConditionShearWave::getInitVZ(int i, int level) +{ + real x = getXCoord(i, level); + real y = getYCoord(i, level); + real z = getZCoord(i, level); + if ((i != 0) && (x != XCoordstopnode) && (y != YCoordstopnode) && (z != ZCoordstopnode)) + { + real vz = v0 * l0 / lx * cos((real)2.0 * M_PI * z /lz) * sin((real)2.0 * M_PI * x / lx); + return vz; + } + else + return (real) 0.0; +} + +real InitialConditionShearWave::getInitROH(int i, int level) +{ + real x = getXCoord(i, level); + real y = getYCoord(i, level); + real z = getZCoord(i, level); + if ((i != 0) && (x != XCoordstopnode) && (y != YCoordstopnode) && (z != ZCoordstopnode)) + { + real press = (l0*l0 * v0 * rho * sin(((real)2.0 * M_PI * z) / lz) * ((real)-4.0 * lz * u0 * cos((2 * M_PI * x) / lx) + lx * v0 * sin(((real)2.0 * M_PI * x) / lx)*sin(((real)2.0 * M_PI * x) / lx) * sin(((real)2.0 * M_PI * z) / lz))) / ((real)2.0 * lx*lx*lx); + return press; + } + else + return (real) 0.0; +} + +real InitialConditionShearWave::getInitPRESS(int i, int level) +{ + //nicht benötigt, da Druck aus Dichte berechnet wird + return (real) 0.0; +} \ No newline at end of file diff --git a/targets/tests/TestingHULC/Utilities/InitialCondition/ShearWave/InitialConditionShearWave.h b/targets/tests/TestingHULC/Utilities/InitialCondition/ShearWave/InitialConditionShearWave.h new file mode 100644 index 0000000000000000000000000000000000000000..9f7ddbad001a31e981436bdf10ca4908359c1b7f --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/InitialCondition/ShearWave/InitialConditionShearWave.h @@ -0,0 +1,20 @@ +#include "../InitialConditionImp.h" + + +class InitialConditionShearWave :public InitialConditionImp +{ +public: + InitialConditionShearWave(real lx, real lz, real l0, real u0, real v0, real rho0); + real getInitVX(int i, int level); + real getInitVY(int i, int level); + real getInitVZ(int i, int level); + real getInitROH(int i, int level); + real getInitPRESS(int i, int level); + +private: + InitialConditionShearWave(); + real rho; + real l0; + real lx, lz; + real u0, v0; +}; \ No newline at end of file diff --git a/targets/tests/TestingHULC/Utilities/InitialCondition/ShearWave/package.include b/targets/tests/TestingHULC/Utilities/InitialCondition/ShearWave/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/InitialCondition/TaylorGreenVortex/InitialconditionTaylorGreenVortex.cpp b/targets/tests/TestingHULC/Utilities/InitialCondition/TaylorGreenVortex/InitialconditionTaylorGreenVortex.cpp new file mode 100644 index 0000000000000000000000000000000000000000..98bdf8d60788f0d8baec08b2e813c9f2ed1409dc --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/InitialCondition/TaylorGreenVortex/InitialconditionTaylorGreenVortex.cpp @@ -0,0 +1,68 @@ +#include "InitialconditionTaylorGreenVortex.h" + +#define _USE_MATH_DEFINES +#include <math.h> + +InitialConditionTaylorGreen::InitialConditionTaylorGreen(real lx, real lz, real l0, real u0, real amplitude, real rho0) +{ + this->Amp = amplitude; + this->L0 = l0; + this->Lx = lx; + this->Lz = lz; + this->rho = rho0; + this->u0 = u0; +} + +real InitialConditionTaylorGreen::getInitVX(int i, int level) +{ + real x = getXCoord(i, level); + real y = getYCoord(i, level); + real z = getZCoord(i, level); + if ((i != 0) && (x != XCoordstopnode) && (y != YCoordstopnode) && (z != ZCoordstopnode)) + { + real vx = (u0* L0 / Lx + (Amp * L0 * cos((real)2.0 * M_PI * z / Lz) * sin((real)2.0 * M_PI * x / Lx) / Lx)); + return vx; + } + else + return (real)0.0; + +} + +real InitialConditionTaylorGreen::getInitVY(int i, int level) +{ + return (real) 0.0; +} + +real InitialConditionTaylorGreen::getInitVZ(int i, int level) +{ + real x = getXCoord(i, level); + real y = getYCoord(i, level); + real z = getZCoord(i, level); + if ((i != 0) && (x != XCoordstopnode) && (y != YCoordstopnode) && (z != ZCoordstopnode)) + { + real vz = (-Amp * L0 * Lz * cos((real)2.0 * M_PI * x / Lx) * sin((real)2.0 * M_PI * z / Lz) / (Lx*Lx)); + return vz; + } + else + return (real) 0.0; +} + +real InitialConditionTaylorGreen::getInitROH(int i, int level) +{ + real x = getXCoord(i, level); + real y = getYCoord(i, level); + real z = getZCoord(i, level); + if ((i != 0) && (x != XCoordstopnode) && (y != YCoordstopnode) && (z != ZCoordstopnode)) + { + real press = (Amp*Amp * L0*L0 * rho * ((Lx*Lx * cos((real)4.0 * M_PI * x / Lx)) + (Lz*Lz * cos((real)4.0 * M_PI * z / Lz))) / ((real)4.0 * Lx*Lx*Lx*Lx)); + return press; + } + else + return (real) 0.0; +} + +real InitialConditionTaylorGreen::getInitPRESS(int i, int level) +{ + //nicht benötigt, da Druck aus Dichte berechnet wird + return (real) 0.0; +} \ No newline at end of file diff --git a/targets/tests/TestingHULC/Utilities/InitialCondition/TaylorGreenVortex/InitialconditionTaylorGreenVortex.h b/targets/tests/TestingHULC/Utilities/InitialCondition/TaylorGreenVortex/InitialconditionTaylorGreenVortex.h new file mode 100644 index 0000000000000000000000000000000000000000..e7df574c23b9c1b363b508209bc0fa8f49b966a8 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/InitialCondition/TaylorGreenVortex/InitialconditionTaylorGreenVortex.h @@ -0,0 +1,22 @@ +#include "../InitialConditionImp.h" + + +class InitialConditionTaylorGreen :public InitialConditionImp +{ +public: + InitialConditionTaylorGreen(real lx, real lz, real l0, real u0, real amplitude, real rho0); + + real getInitVX(int i, int level); + real getInitVY(int i, int level); + real getInitVZ(int i, int level); + real getInitROH(int i, int level); + real getInitPRESS(int i, int level); + +private: + InitialConditionTaylorGreen(); + real Amp; + real rho; + real L0; + real Lx, Lz; + real u0; +}; \ No newline at end of file diff --git a/targets/tests/TestingHULC/Utilities/InitialCondition/TaylorGreenVortex/package.include b/targets/tests/TestingHULC/Utilities/InitialCondition/TaylorGreenVortex/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/InitialCondition/package.include b/targets/tests/TestingHULC/Utilities/InitialCondition/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/LogFileWriter/LogFileWriter.cpp b/targets/tests/TestingHULC/Utilities/LogFileWriter/LogFileWriter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5eeea97261837cebaf356b6b87528b5718d045ae --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/LogFileWriter/LogFileWriter.cpp @@ -0,0 +1,91 @@ +#include "LogFileWriter.h" + +#include <cuda_runtime.h> +#include <helper_functions.h> +#include <helper_cuda.h> + +#include <iomanip> +#include <ctime> + +#include "Utilities\EvaluationParameter\EvaluationParameter.h" +#include "Utilities\TestInformation\TestInformation.h" +#include "Tests\DataQueue\DataQueue.h" + +LogFileWriter::LogFileWriter(std::vector<std::shared_ptr<EvaluationParameter>> evaPara, std::shared_ptr<TestInformation> testinfo) +{ + std::ostringstream oss; + oss << evaPara.at(0)->getLogFilePath() << "\\logFile_" << calcDateAndTime() << ".txt"; + this->logFilePath = oss.str(); + + logFile.open(logFilePath, std::ios::out); + + makeCenterHead("LogFile Information"); + + logFile << "Date: "<< std::setw(2) << std::setfill('0') << nowLocal.tm_mday << "." << std::setw(2) << nowLocal.tm_mon + 1 << "." << nowLocal.tm_year + 1900 << std::endl; + logFile << "Time: " << std::setw(2) << std::setfill('0') << nowLocal.tm_hour << ":" << std::setw(2) << nowLocal.tm_min << ":" << std::setw(2) << nowLocal.tm_sec << std::endl; + logFile << std::endl; + + + int numberOfCudaDevices; + cudaGetDeviceCount(&numberOfCudaDevices); + for (int i = 0; i < numberOfCudaDevices; i++) { + cudaDeviceProp prop; + cudaGetDeviceProperties(&prop, i); + logFile <<"GPU Device " << i + 1 << ": " << prop.name << std::endl; + } + logFile << std::endl; + + logFile << testinfo->getInformation(); + + makeCenterHead("Test Time Information"); + logFile << "FileWriting: " << std::boolalpha << evaPara.at(0)->getWriteFiles() << std::endl; + logFile << std::endl; + logFile << "TestName \t \t \t" << " L\t\t" << "Time for Test" << std::endl; + logFile << std::endl; + for (int i = 0; i < evaPara.size(); i++) + logFile << std::left << std::setfill(' ') << std::setw(17) << evaPara.at(i)->getTestName() << "\t" << std::right << std::setw(3) << evaPara.at(i)->getLx() << "\t\t" << std::setw(9) << evaPara.at(i)->getTestTime() << " sec" << std::endl; + logFile << std::endl; +} + +void LogFileWriter::makeDataQueueOutput(DataQueue* data, int arraySize) +{ + if (data[0].expected) { + std::ostringstream oss; + oss << data->testName << " " << data->valueName << " Test"; + makeCenterHead(oss.str()); + + logFile << "L" << "\t" << std::setfill(' ') << std::left << std::setw(15) << data->valueName << "Order of Accuracy" << std::endl << std::endl; + + logFile << data[0].la << "\t" << data[0].a << std::endl; + for (int i = 0; i < arraySize; i++) { + if (data[i].expected) { + logFile << std::setfill(' ') << std::setw(23) << " " << data[i].orderOfAccuracy << std::endl; + logFile << data[i].lb << "\t" << data[i].b << std::endl; + } + } + + + logFile << std::endl; + } +} + +std::string LogFileWriter::calcDateAndTime() +{ + std::ostringstream oss; + now = time(NULL); + nowLocal = *localtime(&now); + oss << std::setfill('0') << nowLocal.tm_year + 1900 << std::setw(2) << nowLocal.tm_mon + 1 << std::setw(2) << nowLocal.tm_mday << "_" << std::setw(2) << nowLocal.tm_hour << std::setw(2) << nowLocal.tm_min << std::setw(2) << nowLocal.tm_sec; + return oss.str(); +} + +void LogFileWriter::makeHastTags() +{ + logFile << "#################################################" << std::endl; +} + +void LogFileWriter::makeCenterHead(std::string output) +{ + makeHastTags(); + logFile << "#" << std::setfill(' ') << std::right << std::setw(24 + output.length()/2) << output << std::setw(24 - output.length() / 2) << "#" << std::endl; + makeHastTags(); +} diff --git a/targets/tests/TestingHULC/Utilities/LogFileWriter/LogFileWriter.h b/targets/tests/TestingHULC/Utilities/LogFileWriter/LogFileWriter.h new file mode 100644 index 0000000000000000000000000000000000000000..e582c66a758b191e284f3e3b1c302f0dd83e11d1 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/LogFileWriter/LogFileWriter.h @@ -0,0 +1,30 @@ +#ifndef LOGFILEWRITER_H +#define LOGFILEWRITER_H + +#include <string> +#include <fstream> +#include <vector> +#include <memory> + +class EvaluationParameter; +class DataQueue; +class TestInformation; + +class LogFileWriter +{ +public: + LogFileWriter(std::vector<std::shared_ptr<EvaluationParameter>> evaPara, std::shared_ptr<TestInformation> testinfo); + void makeDataQueueOutput(DataQueue* data, int arraySize); + +private: + std::string calcDateAndTime(); + void makeHastTags(); + void makeCenterHead(std::string output); + + std::fstream logFile; + std::string logFilePath; + + time_t now; + struct tm nowLocal; +}; +#endif diff --git a/targets/tests/TestingHULC/Utilities/LogFileWriter/package.include b/targets/tests/TestingHULC/Utilities/LogFileWriter/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/Results/Results.cpp b/targets/tests/TestingHULC/Utilities/Results/Results.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4c274c55da645602224f72a76b5f5c00ecbaf869 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/Results/Results.cpp @@ -0,0 +1,56 @@ +#include "Results.h" + +#define _USE_MATH_DEFINES +#include <math.h> + +Results::Results(unsigned int lx, unsigned int lz, unsigned int timeStepLength) +{ + this->xNodes = lx; + this->zNodes = lz; + this->numberOfNodes = lx*lz; + this->timeStepLength = timeStepLength; + this->numberOfTimeSteps = 0; +} + +void Results::addTimeStep(unsigned int timeStep, unsigned int time, std::vector<double> x, std::vector<double> z, std::vector<double> vx, std::vector<double> vz, std::vector<double> press, std::vector<double> rho) +{ + this->timeStep.push_back(timeStep); + this->time.push_back(time); + this->x.push_back(x); + this->z.push_back(z); + this->vx.push_back(vx); + this->vz.push_back(vz); + this->press.push_back(press); + this->rho.push_back(rho); + numberOfTimeSteps++; +} + +int Results::getNumberOfTimeSteps() +{ + return numberOfTimeSteps; +} + +std::vector< std::vector<double> > Results::getVx() +{ + return vx; +} + +std::vector<std::vector<double>> Results::getVz() +{ + return vz; +} + +int Results::getXNodes() +{ + return xNodes; +} + +int Results::getZNodes() +{ + return zNodes; +} + +int Results::getTimeStepLength() +{ + return timeStepLength; +} diff --git a/targets/tests/TestingHULC/Utilities/Results/Results.h b/targets/tests/TestingHULC/Utilities/Results/Results.h new file mode 100644 index 0000000000000000000000000000000000000000..ef44a5344ef7de104299f41561133ce7d625389f --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/Results/Results.h @@ -0,0 +1,34 @@ +#ifndef RESULTS_H +#define RESULTS_H + +#include <vector> +#include <memory> + +class Results +{ +public: + Results(unsigned int lx, unsigned int lz, unsigned int timeStepLength); + void addTimeStep(unsigned int timeStep, unsigned int time, std::vector<double> x, std::vector<double> z, std::vector<double> vx, std::vector<double> vz, std::vector<double> press, std::vector<double> rho); + int getNumberOfTimeSteps(); + std::vector<std::vector<double>> getVx(); + std::vector<std::vector<double>> getVz(); + int getXNodes(); + int getZNodes(); + int getTimeStepLength(); + + +private: + unsigned int numberOfTimeSteps; + unsigned int timeStepLength; + unsigned int xNodes; + unsigned int zNodes; + unsigned int numberOfNodes; + + std::vector<unsigned int> timeStep; + std::vector<unsigned int> time; + std::vector<std::vector<double>> x, z; + std::vector<std::vector<double>> vx, vz; + std::vector<std::vector<double>> press; + std::vector<std::vector<double>> rho; +}; +#endif \ No newline at end of file diff --git a/targets/tests/TestingHULC/Utilities/Results/package.include b/targets/tests/TestingHULC/Utilities/Results/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/TestCondition/TestCondition.h b/targets/tests/TestingHULC/Utilities/TestCondition/TestCondition.h new file mode 100644 index 0000000000000000000000000000000000000000..db6d6367a92a38d0abadf95b8294ac022dde215f --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/TestCondition/TestCondition.h @@ -0,0 +1,24 @@ +#ifndef TEST_CONDITION_H +#define TEST_CONDITION_H + +#include "VirtualFluids_GPU/LBM/LB.h" + +#include <string> +#include <memory> + +class Parameter; +class GridProvider; +class DataWriter; +class Results; + +class TestCondition +{ +public: + virtual std::shared_ptr<Parameter> getParameter() = 0; + virtual std::shared_ptr<GridProvider> getGrid() = 0; + virtual std::shared_ptr<DataWriter> getDataWriter() = 0; + virtual std::shared_ptr<Results> getSimulationResults() = 0; +private: + +}; +#endif \ No newline at end of file diff --git a/targets/tests/TestingHULC/Utilities/TestCondition/TestConditionImp.cpp b/targets/tests/TestingHULC/Utilities/TestCondition/TestConditionImp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b862ac9d5056e7057a52833234610bafc9e38adb --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/TestCondition/TestConditionImp.cpp @@ -0,0 +1,123 @@ +#include "TestConditionImp.h" + +#include "VirtualFluids_GPU/Parameter/Parameter.h" +#include "VirtualFluids_GPU\Output\FileWriter.h" + +#include "Utilities\GridReaderforTesting\GridReaderforTesting.h" +#include "Utilities\Results\Results.h" +#include "Utilities\DataWriter\Y2dSliceToResults\Y2dSliceToResults.h" +#include "Utilities\InitialCondition\InitialCondition.h" + +#include <sstream> + +std::shared_ptr<Parameter> TestConditionImp::getParameter() +{ + return para; +} + +std::shared_ptr<GridProvider> TestConditionImp::getGrid() +{ + return grid; +} + +std::shared_ptr<DataWriter> TestConditionImp::getDataWriter() +{ + return writeToVector; +} + +std::shared_ptr<Results> TestConditionImp::getSimulationResults() +{ + return simResults; +} + + +std::shared_ptr<TestConditionImp> TestConditionImp::getNewInstance() +{ + return std::shared_ptr<TestConditionImp>(new TestConditionImp()); +} + +void TestConditionImp::initParameter(real viscosity, std::string aGridPath, std::string filePath, int numberOfGridLevels, unsigned int endTime, unsigned int timeStepLength) +{ + para = Parameter::make(); + + para->setMaxDev(1); + std::vector<int> devices; + devices.resize(1); + devices[0] = 1; + para->setDevices(devices); + para->setNumprocs(1); + + std::string _prefix = "cells"; + std::string gridPath = aGridPath + "\\"; + para->setFName(filePath + "/" + _prefix); + para->setPrintFiles(true); + + para->setD3Qxx(27); + para->setMaxLevel(numberOfGridLevels); + + para->setTEnd(endTime); + para->setTOut(timeStepLength); + + para->setViscosity(viscosity); + para->setVelocity(0.096); + para->setViscosityRatio(1.0); + para->setVelocityRatio(1.0); + para->setDensityRatio(1.0); + para->setFactorPressBC(100000.0); + + para->setgeoVec(gridPath + "geoVec.dat"); + para->setcoordX(gridPath + "coordX.dat"); + para->setcoordY(gridPath + "coordY.dat"); + para->setcoordZ(gridPath + "coordZ.dat"); + para->setneighborX(gridPath + "neighborX.dat"); + para->setneighborY(gridPath + "neighborY.dat"); + para->setneighborZ(gridPath + "neighborZ.dat"); + para->setgeomBoundaryBcQs(gridPath + "geomBoundaryQs.dat"); + para->setgeomBoundaryBcValues(gridPath + "geomBoundaryValues.dat"); + para->setinletBcQs(gridPath + "inletBoundaryQs.dat"); + para->setinletBcValues(gridPath + "inletBoundaryValues.dat"); + para->setoutletBcQs(gridPath + "outletBoundaryQs.dat"); + para->setoutletBcValues(gridPath + "outletBoundaryValues.dat"); + para->settopBcQs(gridPath + "topBoundaryQs.dat"); + para->settopBcValues(gridPath + "topBoundaryValues.dat"); + para->setbottomBcQs(gridPath + "bottomBoundaryQs.dat"); + para->setbottomBcValues(gridPath + "bottomBoundaryValues.dat"); + para->setfrontBcQs(gridPath + "frontBoundaryQs.dat"); + para->setfrontBcValues(gridPath + "frontBoundaryValues.dat"); + para->setbackBcQs(gridPath + "backBoundaryQs.dat"); + para->setbackBcValues(gridPath + "backBoundaryValues.dat"); + para->setnumberNodes(gridPath + "numberNodes.dat"); + para->setLBMvsSI(gridPath + "LBMvsSI.dat"); + + para->setForcing(0.0, 0.0, 0.0); + + std::vector<int> dist; + dist.resize(1); + dist[0] = 0; + para->setDistX(dist); + para->setDistY(dist); + para->setDistZ(dist); +} + +void TestConditionImp::initInitialConditions(std::shared_ptr<InitialCondition> initialCondition) +{ + this->initialCondition = initialCondition; + this->initialCondition->setParameter(para); +} + +void TestConditionImp::initGridProvider() +{ + grid = std::shared_ptr<GridProvider>(new GridReaderforTesting(para, initialCondition)); +} + +void TestConditionImp::initResults(unsigned int lx, unsigned int lz, unsigned int timeStepLength) +{ + simResults = std::shared_ptr<Results>(new Results(lx,lz,timeStepLength)); +} + +void TestConditionImp::initDataWriter(unsigned int ySliceForCalculation, unsigned int startTimeCalculation, unsigned int endTime, unsigned int timeStepLength, bool writeFiles, unsigned int startTimeDataWriter) +{ + fileWriter = std::shared_ptr<FileWriter>(new FileWriter()); + writeToVector = std::shared_ptr<ToVectorWriter>(new Y2dSliceToResults(simResults, ySliceForCalculation, startTimeCalculation, endTime, timeStepLength, writeFiles, fileWriter, startTimeDataWriter)); +} + diff --git a/targets/tests/TestingHULC/Utilities/TestCondition/TestConditionImp.h b/targets/tests/TestingHULC/Utilities/TestCondition/TestConditionImp.h new file mode 100644 index 0000000000000000000000000000000000000000..bb97158cd9fc89b8e43ab11b57484b649c0b602a --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/TestCondition/TestConditionImp.h @@ -0,0 +1,42 @@ +#ifndef TEST_CONDITION_IMP_H +#define TEST_CONDITION_IMP_H + +#include "TestCondition.h" + +#include <string> +#include <memory> + +class InitialCondition; +class FileWriter; +class ToVectorWriter; +class TestParameter; + +class TestConditionImp: public TestCondition +{ +public: + static std::shared_ptr<TestConditionImp> getNewInstance(); + void initParameter(real viscosity, std::string gridPath, std::string filePath, int numberOfGridLevels, unsigned int endTime, unsigned int timeStepLength); + void initInitialConditions(std::shared_ptr<InitialCondition> initialCondition); + void initGridProvider(); + void initResults(unsigned int lx, unsigned int lz, unsigned int timeStepLength); + void initDataWriter(unsigned int ySliceForCalculation, unsigned int startTimeCalculation, unsigned int endTime, unsigned int timeStepLength, bool writeFiles, unsigned int startTimeDataWriter); + + std::shared_ptr<Parameter> getParameter(); + std::shared_ptr<GridProvider> getGrid(); + std::shared_ptr<DataWriter> getDataWriter(); + std::shared_ptr<Results> getSimulationResults(); + +protected: + TestConditionImp() {}; + +private: + std::shared_ptr<TestParameter> testPara; + std::shared_ptr<Parameter> para; + std::shared_ptr<InitialCondition> initialCondition; + std::shared_ptr<GridProvider> grid; + std::shared_ptr<Results> simResults; + std::shared_ptr<ToVectorWriter> writeToVector; + std::shared_ptr<FileWriter> fileWriter; + +}; +#endif \ No newline at end of file diff --git a/targets/tests/TestingHULC/Utilities/TestCondition/package.include b/targets/tests/TestingHULC/Utilities/TestCondition/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/TestConditionFactory/TestConditionFactory.h b/targets/tests/TestingHULC/Utilities/TestConditionFactory/TestConditionFactory.h new file mode 100644 index 0000000000000000000000000000000000000000..354fe948e7ebed9a2e235ae802ba05c85e75c41d --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/TestConditionFactory/TestConditionFactory.h @@ -0,0 +1,15 @@ +#ifndef TEST_CONDITION_FACTORY_H +#define TEST_CONDITION_FACTORY_H + +#include <memory> +#include <vector> + +class TestCondition; +class TestParameter; + +class TestConditionFactory +{ +public: + virtual std::vector<std::shared_ptr<TestCondition>> makeTestConditions() = 0; +}; +#endif diff --git a/targets/tests/TestingHULC/Utilities/TestConditionFactory/TestConditionFactoryImp.cpp b/targets/tests/TestingHULC/Utilities/TestConditionFactory/TestConditionFactoryImp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0777858f995c85d1c217bf4105daf1627b0de2bb --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/TestConditionFactory/TestConditionFactoryImp.cpp @@ -0,0 +1,30 @@ +#include "TestConditionFactoryImp.h" + +#include "Utilities\TestParameter\TestParameter.h" +#include "Utilities\TestCondition\TestConditionImp.h" + +std::shared_ptr<TestConditionFactory> TestConditionFactoryImp::getNewInstance(std::vector<std::shared_ptr<TestParameter>> testPara) +{ + return std::shared_ptr<TestConditionFactory>(new TestConditionFactoryImp(testPara)); +} + +TestConditionFactoryImp::TestConditionFactoryImp(std::vector<std::shared_ptr<TestParameter>> testPara):testPara(testPara) +{ +} + +std::vector<std::shared_ptr<TestCondition>> TestConditionFactoryImp::makeTestConditions() +{ + std::vector<std::shared_ptr<TestCondition>> testConditions; + + for (int i = 0; i < testPara.size(); i++) { + std::shared_ptr<TestConditionImp> testCondit = TestConditionImp::getNewInstance(); + testCondit->initParameter(testPara.at(i)->getViscosity(), testPara.at(i)->getGridPath(), testPara.at(i)->getFilePath(), testPara.at(i)->getNumberOfGridLevels(), testPara.at(i)->getEndTime(), testPara.at(i)->getTimeStepLength()); + testCondit->initInitialConditions(testPara.at(i)->getInitialCondition()); + testCondit->initGridProvider(); + testCondit->initResults(testPara.at(i)->getLx(), testPara.at(i)->getLz(), testPara.at(i)->getTimeStepLength()); + testCondit->initDataWriter(testPara.at(i)->getYSliceForCalculation(), testPara.at(i)->getStartTimeCalculation(), testPara.at(i)->getEndTime(), testPara.at(i)->getTimeStepLength(), testPara.at(i)->getWriteFiles(), testPara.at(i)->getStartTimeDataWriter()); + testConditions.push_back(testCondit); + } + + return testConditions; +} diff --git a/targets/tests/TestingHULC/Utilities/TestConditionFactory/TestConditionFactoryImp.h b/targets/tests/TestingHULC/Utilities/TestConditionFactory/TestConditionFactoryImp.h new file mode 100644 index 0000000000000000000000000000000000000000..a1db82a4b3d2674acd2c2233577ecf77e3b1989a --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/TestConditionFactory/TestConditionFactoryImp.h @@ -0,0 +1,20 @@ +#ifndef TEST_CONDITION_FACTORY_IMP_H +#define TEST_CONDITION_FACTORY_IMP_H + +#include "TestConditionFactory.h" + + +class TestConditionFactoryImp: public TestConditionFactory +{ +public: + static std::shared_ptr<TestConditionFactory> getNewInstance(std::vector < std::shared_ptr < TestParameter > > testPara); + std::vector<std::shared_ptr<TestCondition>> makeTestConditions(); + +protected: + TestConditionFactoryImp() {}; + TestConditionFactoryImp(std::vector < std::shared_ptr < TestParameter > > testPara); + +private: + std::vector < std::shared_ptr < TestParameter > > testPara; +}; +#endif \ No newline at end of file diff --git a/targets/tests/TestingHULC/Utilities/TestConditionFactory/package.include b/targets/tests/TestingHULC/Utilities/TestConditionFactory/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/TestInformation/TestInformation.h b/targets/tests/TestingHULC/Utilities/TestInformation/TestInformation.h new file mode 100644 index 0000000000000000000000000000000000000000..c34e547b08d4f490f2574d61eafcded34bb449bd --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/TestInformation/TestInformation.h @@ -0,0 +1,14 @@ +#ifndef TESTINFORMATION_H +#define TESTINFORMATION_H + +#include <string> + +class TestInformation +{ +public: + virtual std::string getInformation() = 0; + +private: + +}; +#endif // !TESTINFORMATION_H diff --git a/targets/tests/TestingHULC/Utilities/TestInformation/TestInformationImp.cpp b/targets/tests/TestingHULC/Utilities/TestInformation/TestInformationImp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7ea315a2368c037a172acf5293db680ca78a13a6 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/TestInformation/TestInformationImp.cpp @@ -0,0 +1,48 @@ +#include "TestInformationImp.h" + +#include <iomanip> + +std::shared_ptr<TestInformation> TestInformationImp::getNewInstance(int numberOfTimeSteps, int basisTimeStepLength, int startStepCalculation, double viscosity, bool tgv, double u0TGV, double AmplitudeTGV, bool sw, double u0SW, double v0SW) +{ + return std::shared_ptr<TestInformation>(new TestInformationImp(numberOfTimeSteps, basisTimeStepLength, startStepCalculation, viscosity, tgv, u0TGV, AmplitudeTGV, sw, u0SW, v0SW)); +} + +TestInformationImp::TestInformationImp(int numberOfTimeSteps, int basisTimeStepLength, int startStepCalculation, double viscosity, bool tgv, double u0TGV, double amplitudeTGV, bool sw, double u0SW, double v0SW) +{ + makeCenterHead("Basic Information"); + oss << "NumberOfTimeSteps: " << numberOfTimeSteps << std::endl; + oss << "BasisTimeStepLength: " << basisTimeStepLength << std::endl; + oss << "StartStepCalculation: " << startStepCalculation << std::endl; + oss << "Viscosity: " << viscosity << std::endl; + oss << std::endl; + + if (tgv) { + makeCenterHead("TaylorGreenVortex Information"); + oss << "u0: " << u0TGV << std::endl; + oss << "Amplitude: " << amplitudeTGV << std::endl; + oss << std::endl; + } + if (sw) { + makeCenterHead("ShearWave Information"); + oss << "u0: " << u0SW << std::endl; + oss << "v0: " << v0SW << std::endl; + oss << std::endl; + } +} + +std::string TestInformationImp::getInformation() +{ + return oss.str(); +} + +void TestInformationImp::makeHastTags() +{ + oss << "#################################################" << std::endl; +} + +void TestInformationImp::makeCenterHead(std::string output) +{ + makeHastTags(); + oss << "#" << std::setfill(' ') << std::right << std::setw(24 + output.length() / 2) << output << std::setw(24 - output.length() / 2) << "#" << std::endl; + makeHastTags(); +} diff --git a/targets/tests/TestingHULC/Utilities/TestInformation/TestInformationImp.h b/targets/tests/TestingHULC/Utilities/TestInformation/TestInformationImp.h new file mode 100644 index 0000000000000000000000000000000000000000..5fa3ca0bb45eefb3d3af89f9712d6319088b2e1a --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/TestInformation/TestInformationImp.h @@ -0,0 +1,26 @@ +#ifndef TESTINFORMATIONIMP_H +#define TESTINFORMATIONIMP_H + +#include "TestInformation.h" + +#include <sstream> +#include <memory> + +class TestInformationImp : public TestInformation +{ +public: + static std::shared_ptr<TestInformation> getNewInstance(int numberOfTimeSteps, int basisTimeStepLength, int startStepCalculation, double viscosity, bool tgv, double u0TGV, double AmplitudeTGV, bool sw, double u0SW, double v0SW); + std::string getInformation(); + +protected: + TestInformationImp(int numberOfTimeSteps, int basisTimeStepLength, int startStepCalculation, double viscosity, bool tgv, double u0TGV, double AmplitudeTGV, bool sw, double u0SW, double v0SW); + TestInformationImp() {}; + +private: + void makeHastTags(); + void makeCenterHead(std::string head); + + std::ostringstream oss; + +}; +#endif // !TESTINFORMATIONIMP_H diff --git a/targets/tests/TestingHULC/Utilities/TestInformation/package.include b/targets/tests/TestingHULC/Utilities/TestInformation/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/TestParameter/ShearWaveTestParameter/ShearWaveTestParameter.cpp b/targets/tests/TestingHULC/Utilities/TestParameter/ShearWaveTestParameter/ShearWaveTestParameter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8d0da14f57b57be8345f143dfaa94648fa527b9a --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/TestParameter/ShearWaveTestParameter/ShearWaveTestParameter.cpp @@ -0,0 +1,30 @@ +#include "ShearWaveTestParameter.h" + +#include "Utilities\InitialCondition\ShearWave\InitialConditionShearWave.h" + +#include <sstream> + +std::shared_ptr<TestParameter> ShearWaveTestParameter::getNewInstance(real u0, real v0, real viscosity, unsigned int lx, unsigned int numberOfTimeSteps, unsigned int basisTimeStepLength, unsigned int startStepCalculation, unsigned int ySliceForCalculation, std::string gridPath, bool writeFiles, unsigned int startStepFileWriter, std::string filePath) +{ + return std::shared_ptr<TestParameter>(new ShearWaveTestParameter(u0, v0, + viscosity, lx, + numberOfTimeSteps, basisTimeStepLength, + startStepCalculation, ySliceForCalculation, + gridPath, + writeFiles, startStepFileWriter, filePath)); +} + +ShearWaveTestParameter::ShearWaveTestParameter(real u0, real v0, real viscosity, unsigned int lx, unsigned int numberOfTimeSteps, unsigned int basisTimeStepLength, unsigned int startStepCalculation, unsigned int ySliceForCalculation, std::string gridPath, bool writeFiles, unsigned int startStepFileWriter, std::string filePath) + :TestParameterImp(viscosity, lx, numberOfTimeSteps, basisTimeStepLength, startStepCalculation, ySliceForCalculation, gridPath, writeFiles, startStepFileWriter), u0(u0), v0(v0) +{ + std::ostringstream oss; + oss << filePath + "\\ShearWave\\grid" << lx; + this->filePath = oss.str(); + + initialCondition = std::shared_ptr<InitialConditionShearWave>(new InitialConditionShearWave((double)lx, (double)lz, (double)l0, u0, v0, rho0)); +} + +std::shared_ptr<InitialCondition> ShearWaveTestParameter::getInitialCondition() +{ + return initialCondition; +} diff --git a/targets/tests/TestingHULC/Utilities/TestParameter/ShearWaveTestParameter/ShearWaveTestParameter.h b/targets/tests/TestingHULC/Utilities/TestParameter/ShearWaveTestParameter/ShearWaveTestParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..937e758f391024931747bfd0716f00ad02ea1a58 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/TestParameter/ShearWaveTestParameter/ShearWaveTestParameter.h @@ -0,0 +1,33 @@ +#ifndef SHEARWAVETESTPARAMETER_H +#define SHEARWAVETESTPARAMETER_H + +#include "../TestParameterImp.h" + +class ShearWaveTestParameter : public TestParameterImp +{ +public: + static std::shared_ptr<TestParameter> getNewInstance(real u0, real v0, + real viscosity, unsigned int lx, + unsigned int numberOfTimeSteps, unsigned int basisTimeStepLength, + unsigned int startStepCalculation, unsigned int ySliceForCalculation, + std::string gridPath, + bool writeFiles, unsigned int startStepFileWriter, std::string filePath); + +protected: + ShearWaveTestParameter() {}; + ShearWaveTestParameter(real u0, real v0, + real viscosity, unsigned int lx, + unsigned int numberOfTimeSteps, unsigned int basisTimeStepLength, + unsigned int startStepCalculation, unsigned int ySliceForCalculation, + std::string gridPath, + bool writeFiles, unsigned int startStepFileWriter, std::string filePath); + + std::shared_ptr<InitialCondition> getInitialCondition(); + +private: + std::shared_ptr<InitialCondition> initialCondition; + + real u0, v0; +}; + +#endif // !SHEARWAVETESTPARAMETER_H diff --git a/targets/tests/TestingHULC/Utilities/TestParameter/ShearWaveTestParameter/package.include b/targets/tests/TestingHULC/Utilities/TestParameter/ShearWaveTestParameter/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/TestParameter/TaylorGreenTestParameter/TaylorGreenTestParameter.cpp b/targets/tests/TestingHULC/Utilities/TestParameter/TaylorGreenTestParameter/TaylorGreenTestParameter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ddb95439fbddd190a6d66e9e36b4f9ee73672169 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/TestParameter/TaylorGreenTestParameter/TaylorGreenTestParameter.cpp @@ -0,0 +1,30 @@ +#include "TaylorGreenTestParameter.h" + +#include "Utilities\InitialCondition\TaylorGreenVortex\InitialconditionTaylorGreenVortex.h" + +#include <sstream> + +std::shared_ptr<TestParameter> TaylorGreenTestParameter::getNewInstance(real u0, real amplitude, real viscosity, unsigned int lx, unsigned int numberOfTimeSteps, unsigned int basisTimeStepLength, unsigned int startStepCalculation, unsigned int ySliceForCalculation, std::string gridPath, bool writeFiles, unsigned int startStepFileWriter, std::string filePath) +{ + return std::shared_ptr<TestParameter>(new TaylorGreenTestParameter(u0, amplitude, + viscosity, lx, + numberOfTimeSteps, basisTimeStepLength, + startStepCalculation, ySliceForCalculation, + gridPath, + writeFiles, startStepFileWriter, filePath)); +} + +TaylorGreenTestParameter::TaylorGreenTestParameter(real u0, real amplitude, real viscosity, unsigned int lx, unsigned int numberOfTimeSteps, unsigned int basisTimeStepLength, unsigned int startStepCalculation, unsigned int ySliceForCalculation, std::string gridPath, bool writeFiles, unsigned int startStepFileWriter, std::string filePath) + :TestParameterImp(viscosity, lx, numberOfTimeSteps, basisTimeStepLength, startStepCalculation, ySliceForCalculation, gridPath, writeFiles, startStepFileWriter), u0(u0), amplitude(amplitude) +{ + std::ostringstream oss; + oss << filePath + "\\TaylorGreenVortex\\grid" << lx; + this->filePath = oss.str(); + + initialCondition = std::shared_ptr<InitialConditionTaylorGreen>(new InitialConditionTaylorGreen((double)lx, (double)lz, (double)l0, u0, amplitude, rho0)); +} + +std::shared_ptr<InitialCondition> TaylorGreenTestParameter::getInitialCondition() +{ + return initialCondition; +} diff --git a/targets/tests/TestingHULC/Utilities/TestParameter/TaylorGreenTestParameter/TaylorGreenTestParameter.h b/targets/tests/TestingHULC/Utilities/TestParameter/TaylorGreenTestParameter/TaylorGreenTestParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..06e4dd538836f125173394aef5f6d3940317f8d6 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/TestParameter/TaylorGreenTestParameter/TaylorGreenTestParameter.h @@ -0,0 +1,35 @@ +#ifndef TGVTESTPARAMETER_H +#define TGVTESTPARAMETER_H + +#include "../TestParameterImp.h" + +#include <string> +#include <memory> + +class TaylorGreenTestParameter : public TestParameterImp +{ +public: + static std::shared_ptr<TestParameter> getNewInstance(real u0, real amplitude, + real viscosity, unsigned int lx, + unsigned int numberOfTimeSteps, unsigned int basisTimeStepLength, + unsigned int startStepCalculation, unsigned int ySliceForCalculation, + std::string gridPath, + bool writeFiles, unsigned int startStepFileWriter, std::string filePath); + +protected: + TaylorGreenTestParameter(real u0, real amplitude, + real viscosity, unsigned int lx, + unsigned int numberOfTimeSteps, unsigned int basisTimeStepLength, + unsigned int startStepCalculation, unsigned int ySliceForCalculation, + std::string gridPath, + bool writeFiles, unsigned int startStepFileWriter, std::string filePath); + + std::shared_ptr<InitialCondition> getInitialCondition(); + +private: + std::shared_ptr<InitialCondition> initialCondition; + + real u0, amplitude; + +}; +#endif // !TGVTESTPARAMETER_H diff --git a/targets/tests/TestingHULC/Utilities/TestParameter/TaylorGreenTestParameter/package.include b/targets/tests/TestingHULC/Utilities/TestParameter/TaylorGreenTestParameter/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/TestParameter/TestParameter.h b/targets/tests/TestingHULC/Utilities/TestParameter/TestParameter.h new file mode 100644 index 0000000000000000000000000000000000000000..fa248e5b27fdf5a0c30cda1c0d34c04e3a9372f3 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/TestParameter/TestParameter.h @@ -0,0 +1,30 @@ +#ifndef TESTPARAMETERINT_H +#define TESTPARAMETERINT_H + +#include <memory> +#include <string> + +class InitialCondition; + +class TestParameter +{ +public: + virtual std::shared_ptr<InitialCondition> getInitialCondition() = 0; + virtual double getViscosity() = 0; + virtual std::string getGridPath() = 0; + virtual std::string getFilePath() = 0; + virtual unsigned int getNumberOfGridLevels() = 0; + virtual unsigned int getEndTime() = 0; + virtual unsigned int getTimeStepLength() = 0; + virtual unsigned int getLx() = 0; + virtual unsigned int getLz() = 0; + virtual unsigned int getYSliceForCalculation() = 0; + virtual unsigned int getStartTimeCalculation() = 0; + virtual bool getWriteFiles() = 0; + virtual unsigned int getStartTimeDataWriter() = 0; + +private: + +}; + +#endif // !TESTPARAMETER_H diff --git a/targets/tests/TestingHULC/Utilities/TestParameter/TestParameterImp.cpp b/targets/tests/TestingHULC/Utilities/TestParameter/TestParameterImp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..79fe02e4038334f72743369941fb6fcf1c11e20e --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/TestParameter/TestParameterImp.cpp @@ -0,0 +1,80 @@ +#include "TestParameterImp.h" + + +TestParameterImp::TestParameterImp(real viscosity, unsigned int lx, unsigned int numberOfTimeSteps, unsigned int basisTimeStepLength, unsigned int startStepCalculation, unsigned int ySliceForCalculation, std::string gridPath, bool writeFiles, unsigned int startStepFileWriter) + : viscosity(viscosity), lx(lx), numberOfTimeSteps(numberOfTimeSteps), basisTimeStepLength(basisTimeStepLength), startStepCalculation(startStepCalculation), ySliceForCalculation(ySliceForCalculation), gridPath(gridPath), writeFiles(writeFiles), startStepFileWriter(startStepFileWriter) +{ + maxLevel = 0; + numberOfGridLevels = 1; + l0 = 32; + rho0 = 1.0; + + lz = 3 * lx / 2; + timeStepLength = basisTimeStepLength*(lx / l0)*(lx / l0); + startTimeCalculation = timeStepLength * startStepCalculation; + startTimeDataWriter = timeStepLength * startStepFileWriter; + endTime = timeStepLength * numberOfTimeSteps; + +} + +double TestParameterImp::getViscosity() +{ + return viscosity; +} + +std::string TestParameterImp::getGridPath() +{ + return gridPath; +} + +std::string TestParameterImp::getFilePath() +{ + return filePath; +} + +unsigned int TestParameterImp::getNumberOfGridLevels() +{ + return numberOfGridLevels; +} + +unsigned int TestParameterImp::getEndTime() +{ + return endTime; +} + +unsigned int TestParameterImp::getTimeStepLength() +{ + return timeStepLength; +} + +unsigned int TestParameterImp::getLx() +{ + return lx; +} + +unsigned int TestParameterImp::getLz() +{ + return lz; +} + +unsigned int TestParameterImp::getYSliceForCalculation() +{ + return ySliceForCalculation; +} + +unsigned int TestParameterImp::getStartTimeCalculation() +{ + return startTimeCalculation; +} + +bool TestParameterImp::getWriteFiles() +{ + return writeFiles; +} + +unsigned int TestParameterImp::getStartTimeDataWriter() +{ + return startTimeDataWriter; +} + + diff --git a/targets/tests/TestingHULC/Utilities/TestParameter/TestParameterImp.h b/targets/tests/TestingHULC/Utilities/TestParameter/TestParameterImp.h new file mode 100644 index 0000000000000000000000000000000000000000..bf59245e5596c0bef0a159823ac6034ef56c2d62 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/TestParameter/TestParameterImp.h @@ -0,0 +1,51 @@ +#ifndef TESTPARAMETERIMP_H +#define TESTPARAMETERIMP_H + +#include "TestParameter.h" + +#include "LBM\LB.h" + +class TestParameterImp: public TestParameter +{ +public: + virtual std::shared_ptr<InitialCondition> getInitialCondition() = 0; + + double getViscosity(); + std::string getGridPath(); + std::string getFilePath(); + unsigned int getNumberOfGridLevels(); + unsigned int getEndTime(); + unsigned int getTimeStepLength(); + unsigned int getLx(); + unsigned int getLz(); + unsigned int getYSliceForCalculation(); + unsigned int getStartTimeCalculation(); + bool getWriteFiles(); + unsigned int getStartTimeDataWriter(); + +protected: + TestParameterImp() {}; + TestParameterImp(real viscosity, unsigned int lx, + unsigned int numberOfTimeSteps, unsigned int basisTimeStepLength, + unsigned int startStepCalculation, unsigned int ySliceForCalculation, + std::string gridPath, + bool writeFiles, unsigned int startStepFileWriter); + + std::string filePath; + real viscosity; + unsigned int lx; + unsigned int numberOfTimeSteps, basisTimeStepLength; + unsigned int startStepCalculation, startStepFileWriter, ySliceForCalculation; + std::string gridPath; + bool writeFiles; + + unsigned int maxLevel, numberOfGridLevels; + unsigned int l0, lz; + real rho0; + unsigned int timeStepLength; + unsigned int startTimeCalculation, startTimeDataWriter; + unsigned int endTime; + +}; + +#endif // !TESTPARAMETERIMP_H diff --git a/targets/tests/TestingHULC/Utilities/TestParameter/package.include b/targets/tests/TestingHULC/Utilities/TestParameter/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/reader/package.include b/targets/tests/TestingHULC/Utilities/reader/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/TestingHULC/Utilities/reader/reader.cpp b/targets/tests/TestingHULC/Utilities/reader/reader.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c0e23e4ed8e168fd5b15c37e112918e669d2b2be --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/reader/reader.cpp @@ -0,0 +1,140 @@ +#include "reader.h" + +#include <fstream> +#include <iostream> + +#include "utilities/input/Input.h" +#include "utilities/StringUtil/StringUtil.h" + +#include "Utilities\EvaluationParameter\EvaluationParameter.h" +#include "Utilities\TestInformation\TestInformationImp.h" +#include "Utilities\TestParameter\TaylorGreenTestParameter\TaylorGreenTestParameter.h" +#include "Utilities\TestParameter\ShearWaveTestParameter\ShearWaveTestParameter.h" + +void Reader::calcNumberOfEqualTests() +{ + for (int i = 0; i < tgv.size(); i++) + if (tgv.at(i)) + numberOfTaylorGreenTests++; + + for (int i = 0; i < sw.size(); i++) + if (sw.at(i)) + numberOfShearWaveTests++; +} + + +std::shared_ptr<Reader> Reader::getNewInstance(const std::string aFilePath) +{ + return std::shared_ptr<Reader>(new Reader(aFilePath)); +} + +Reader::Reader(const std::string aFilePath) +{ + std::ifstream stream; + stream.open(aFilePath.c_str(), std::ios::in); + std::unique_ptr<input::Input> input = input::Input::makeInput(stream, "config"); + + viscosity = StringUtil::toDouble(input->getValue("Viscosity")); + minOrderOfAccuracy = StringUtil::toDouble(input->getValue("MinOrderOfAccuracy")); + + amplitudeTGV = StringUtil::toDouble(input->getValue("Amplitude_TGV")); + u0TGV = StringUtil::toDouble(input->getValue("u0_TGV")); + v0SW = StringUtil::toDouble(input->getValue("v0_SW")); + u0SW = StringUtil::toDouble(input->getValue("u0_SW")); + + numberOfTimeSteps = StringUtil::toInt(input->getValue("NumberOfTimeSteps")); + basisTimeStepLength = StringUtil::toInt(input->getValue("BasisTimeStepLength")); + startStepCalculation = StringUtil::toInt(input->getValue("StartStepCalculation")); + + grids.resize(5); + grids.at(0) = input->getValue("GridPath32"); + grids.at(1) = input->getValue("GridPath64"); + grids.at(2) = input->getValue("GridPath128"); + grids.at(3) = input->getValue("GridPath256"); + grids.at(4) = input->getValue("GridPath512"); + + ySliceForCalculation = StringUtil::toInt(input->getValue("ySliceForCalculation")); + + writeFiles = StringUtil::toBool(input->getValue("WriteFiles")); + filePath = input->getValue("PathForFileWriting"); + startStepFileWriter = StringUtil::toInt(input->getValue("StartStepFileWriter")); + logFilePath= input->getValue("PathLogFile");; + + tgv.resize(5); + tgv.at(0) = StringUtil::toBool(input->getValue("TaylorGreenVortex32")); + tgv.at(1) = StringUtil::toBool(input->getValue("TaylorGreenVortex64")); + tgv.at(2) = StringUtil::toBool(input->getValue("TaylorGreenVortex128")); + tgv.at(3) = StringUtil::toBool(input->getValue("TaylorGreenVortex256")); + tgv.at(4) = StringUtil::toBool(input->getValue("TaylorGreenVortex512")); + + sw.resize(5); + sw.at(0) = StringUtil::toBool(input->getValue("ShearWave32")); + sw.at(1) = StringUtil::toBool(input->getValue("ShearWave64")); + sw.at(2) = StringUtil::toBool(input->getValue("ShearWave128")); + sw.at(3) = StringUtil::toBool(input->getValue("ShearWave256")); + sw.at(4) = StringUtil::toBool(input->getValue("ShearWave512")); + + l.resize(5); + l.at(0) = 32.0; + l.at(1) = 64.0; + l.at(2) = 128.0; + l.at(3) = 256.0; + l.at(4) = 512.0; + + stream.close(); + + numberOfTaylorGreenTests = 0; + numberOfShearWaveTests = 0; + calcNumberOfEqualTests(); +} + +std::vector<std::shared_ptr<EvaluationParameter>> Reader::makeEvaluationParameter() +{ + std::vector<std::shared_ptr<EvaluationParameter>> evaPara; + + for (int i = 0; i < tgv.size(); i++) { + if (tgv.at(i)) { + evaPara.push_back(EvaluationParameter::getNewInstance("TaylorGreenVortex", numberOfTaylorGreenTests, l.at(i),"vX", logFilePath, minOrderOfAccuracy, writeFiles, viscosity)); + } + } + for (int i = 0; i < sw.size(); i++) { + if (sw.at(i)) { + evaPara.push_back(EvaluationParameter::getNewInstance("ShearWave", numberOfShearWaveTests, l.at(i),"vZ", logFilePath, minOrderOfAccuracy, writeFiles, viscosity)); + } + } + return evaPara; +} + +std::shared_ptr<TestInformation> Reader::makeTestInformation() +{ + bool tgvTest = false; + bool swTest = false; + for (int i = 0; i < tgv.size(); i++) { + if (tgv.at(i)) + tgvTest = true; + } + for (int i = 0; i < sw.size(); i++) { + if (sw.at(i)) + swTest = true; + } + std::shared_ptr<TestInformation> testInfo = TestInformationImp::getNewInstance(numberOfTimeSteps, basisTimeStepLength, startStepCalculation, viscosity, tgvTest, u0TGV, amplitudeTGV, swTest, u0SW, v0SW); + return testInfo; +} + +std::vector<std::shared_ptr<TestParameter>> Reader::makeTestParameter() +{ + std::vector<std::shared_ptr<TestParameter>> testParameter; + + for (int i = 0; i < tgv.size(); i++) { + if (tgv.at(i)) { + testParameter.push_back(TaylorGreenTestParameter::getNewInstance(u0TGV, amplitudeTGV, viscosity, l.at(i), numberOfTimeSteps, basisTimeStepLength, startStepCalculation, ySliceForCalculation, grids.at(i), writeFiles, startStepFileWriter, filePath)); + } + } + for (int i = 0; i < sw.size(); i++) { + if (sw.at(i)) { + testParameter.push_back(ShearWaveTestParameter::getNewInstance(u0SW, v0SW, viscosity, l.at(i), numberOfTimeSteps, basisTimeStepLength, startStepCalculation, ySliceForCalculation, grids.at(i), writeFiles, startStepFileWriter, filePath)); + } + } + + return testParameter; +} diff --git a/targets/tests/TestingHULC/Utilities/reader/reader.h b/targets/tests/TestingHULC/Utilities/reader/reader.h new file mode 100644 index 0000000000000000000000000000000000000000..1071a58667ae9036c91af4581c4f5b8ea16c8a49 --- /dev/null +++ b/targets/tests/TestingHULC/Utilities/reader/reader.h @@ -0,0 +1,52 @@ +#ifndef READER_H +#define READER_H + +#include "LBM\LB.h" + +#include <memory> +#include <vector> +#include <string> + +class EvaluationParameter; +class TestInformation; +class TestParameter; + +class Reader +{ +public: + static std::shared_ptr < Reader > getNewInstance(const std::string aFilePath); + std::vector < std::shared_ptr < EvaluationParameter > > makeEvaluationParameter(); + std::shared_ptr < TestInformation > makeTestInformation(); + std::vector < std::shared_ptr < TestParameter > > makeTestParameter(); + +protected: + Reader() {}; + Reader(const std::string aFilePath); + +private: + void calcNumberOfEqualTests(); + + real viscosity; + double minOrderOfAccuracy; + + real u0SW, v0SW; + real amplitudeTGV, u0TGV; + + unsigned int numberOfTimeSteps, basisTimeStepLength, startStepCalculation; + unsigned int ySliceForCalculation; + std::vector<real> l; + + std::vector<std::string> grids; + + bool writeFiles; + std::string filePath; + unsigned int startStepFileWriter; + std::string logFilePath; + + + std::vector<bool> tgv; + std::vector<bool> sw; + + int numberOfTaylorGreenTests, numberOfShearWaveTests; +}; +#endif \ No newline at end of file diff --git a/targets/tests/TestingHULC/config.txt b/targets/tests/TestingHULC/config.txt new file mode 100644 index 0000000000000000000000000000000000000000..86fd37d76b62c0344fc7c2bf1515f04dc478fdf6 --- /dev/null +++ b/targets/tests/TestingHULC/config.txt @@ -0,0 +1,58 @@ +################################################## +# Basic Test Parameter # +################################################## +NumberOfTimeSteps=20 +BasisTimeStepLength=1000 +StartStepCalculation=11 +ySliceForCalculation=0 + +Viscosity=0.00001 + +MinOrderOfAccuracy=1.95 + +################################################## +# TaylorGreenVortex Test Parameter # +################################################## +u0_TGV=0.032 +Amplitude_TGV=0.01 + +################################################## +# Shear Wave Test Parameter # +################################################## +u0_SW=0.032 +v0_SW=0.1 + +################################################## +# Tests To Perform # +################################################## +TaylorGreenVortex32=true +TaylorGreenVortex64=true +TaylorGreenVortex128=false +TaylorGreenVortex256=false +TaylorGreenVortex512=false + +ShearWave32=true +ShearWave64=true +ShearWave128=false +ShearWave256=false +ShearWave512=false + +################################################## +# Grid Information # +################################################## +GridPath32="C:\Users\Timon\Documents\studienarbeitIRMB\grids\gridUni32x4x48" +GridPath64="C:\Users\Timon\Documents\studienarbeitIRMB\grids\gridUni64x4x96" +GridPath128="C:\Users\Timon\Documents\studienarbeitIRMB\grids\gridUni128x4x192" +GridPath256="C:\Users\Timon\Documents\studienarbeitIRMB\grids\gridUni256x4x384" +GridPath512="C:\Users\Timon\Documents\studienarbeitIRMB\grids\gridUni512x4x768" + +################################################## +# File Writing Information # +################################################## +WriteFiles=true +PathForFileWriting="C:\Users\Timon\Documents\studienarbeitIRMB\Output" +StartStepFileWriter=0 + +PathLogFile="C:\Users\Timon\Documents\studienarbeitIRMB\logFiles" + + diff --git a/targets/tests/TestingHULC/main.cpp b/targets/tests/TestingHULC/main.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ada84ac2b1cd3624677a1891ea4c167183ff60df --- /dev/null +++ b/targets/tests/TestingHULC/main.cpp @@ -0,0 +1,92 @@ +#include <gmock/gmock.h> +#include "mpi.h" + +#include "VirtualFluids_GPU\LBM\Simulation.h" + +#include "Utilities\Reader\Reader.h" +#include "Utilities\EvaluationParameter\EvaluationParameter.h" +#include "Utilities\TestCondition\TestCondition.h" +#include "Utilities\Calculator\Calculator.h" +#include "Utilities\LogFileWriter\LogFileWriter.h" +#include "Utilities\TestConditionFactory\TestConditionFactoryImp.h" + +#include "Tests\DataCollector\DataCollector.h" +#include "Tests\DataQueue\DataQueue.h" + +#include "Tests\OrderOfAccuracy\OrderOfAccuracy.h" + +#include "Tests\TestCout\TestCout.h" + +#include <iostream> + + +//muss nicht unbedingt +#include "Utilities\Results\Results.h" + +using std::shared_ptr; + + +const int numberOfTests = 5; + +DataQueue nuTGV[numberOfTests - 1]; +DataQueue phiTGV[numberOfTests - 1]; +DataQueue nuSW[numberOfTests - 1]; +DataQueue phiSW[numberOfTests - 1]; + +static void testHULC(const std::string &configFile) +{ + std::shared_ptr< Reader > configReader = Reader::getNewInstance(configFile); + + std::vector< std::shared_ptr< EvaluationParameter > > evaPara = configReader->makeEvaluationParameter(); + std::shared_ptr<TestInformation> testInfo = configReader->makeTestInformation(); + std::vector<std::shared_ptr<TestParameter>> testPara = configReader->makeTestParameter(); + + std::shared_ptr<TestConditionFactory> factory = TestConditionFactoryImp::getNewInstance(testPara); + std::vector<std::shared_ptr<TestCondition>> testConditions = factory->makeTestConditions(); + + DataCollector tgvCollector = DataCollector(nuTGV, phiTGV, numberOfTests - 1, "TaylorGreenVortex"); + DataCollector swCollector = DataCollector(nuSW, phiSW, numberOfTests - 1, "ShearWave"); + + for (int i = 0; i < testConditions.size(); i++) + { + evaPara.at(i)->setStartTime(); + TEST_HEAD(evaPara.at(i)->getTestName(), evaPara.at(i)->getLx()); + Simulation sim; + sim.init(testConditions.at(i)->getParameter(), testConditions.at(i)->getGrid(), testConditions.at(i)->getDataWriter()); + sim.run(); + evaPara.at(i)->setEndTime(); + + std::shared_ptr<Calulator> calc = std::shared_ptr<Calulator>(new Calulator(testConditions.at(i)->getSimulationResults(), evaPara.at(i))); + + double nu = calc->calcNu(); + double nudiff = calc->calcNuDiff(nu); + double phidiff = calc->calcPhiDiff(); + + tgvCollector.addNuDiffAndPhi(nudiff, phidiff, evaPara.at(i)); + swCollector.addNuDiffAndPhi(nudiff, phidiff, evaPara.at(i)); + } + + std::shared_ptr<LogFileWriter> logFile = std::shared_ptr<LogFileWriter>(new LogFileWriter(evaPara, testInfo)); + logFile->makeDataQueueOutput(nuTGV, numberOfTests - 1); + logFile->makeDataQueueOutput(phiTGV, numberOfTests - 1); + logFile->makeDataQueueOutput(nuSW, numberOfTests - 1); + logFile->makeDataQueueOutput(phiSW, numberOfTests - 1); +} + +int main(int argc, char **argv) +{ + MPI_Init(&argc, &argv); + + if (argc > 1) + testHULC(argv[1]); + + ::testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); + MPI_Finalize(); +} + +INSTANTIATE_TEST_CASE_P(TaylorGreenVortexNu, OrderOfAccuracy, ValuesIn(nuTGV)); +INSTANTIATE_TEST_CASE_P(TaylorGreenVortexPhi, OrderOfAccuracy, ValuesIn(phiTGV)); + +INSTANTIATE_TEST_CASE_P(ShearWaveNu, OrderOfAccuracy, ValuesIn(nuSW)); +INSTANTIATE_TEST_CASE_P(ShearWavePhi, OrderOfAccuracy, ValuesIn(phiSW)); \ No newline at end of file diff --git a/targets/tests/TestingHULC/package.include b/targets/tests/TestingHULC/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391