diff --git a/src/VirtualFluidsBasics/utilities/logger/Logger.cpp b/src/VirtualFluidsBasics/utilities/logger/Logger.cpp index 4e8a939244aafc225c2f48e6d71fbe7ec1e80472..e2fab72e523cfd22f0ebed620a800aefcc084857 100644 --- a/src/VirtualFluidsBasics/utilities/logger/Logger.cpp +++ b/src/VirtualFluidsBasics/utilities/logger/Logger.cpp @@ -9,16 +9,16 @@ namespace logging { - std::shared_ptr<Logger> out = std::make_shared<LoggerImp>(std::cout); + std::shared_ptr<Logger> out = nullptr; logging::Logger::Level logging::Logger::globalLogLevel = logging::Logger::INTERMEDIATE; logging::Logger::Level logging::Logger::localLogLevel = logging::Logger::INTERMEDIATE; bool logging::Logger::printRankNumber = false; - logging::Logger::Logger(std::ostream &stream) : stream(stream) + logging::Logger::Logger(std::ostream* stream) { - + streams.push_back(stream); } logging::Logger::~Logger() @@ -26,11 +26,40 @@ namespace logging { } - void logging::Logger::setStream(std::ostream &stream) + void Logger::addStreamToList(std::ostream* stream) + { + streams.push_back(stream); + } + + void Logger::resetStreamList() + { + streams.clear(); + } + + +//-----------static methods----------------// + void logging::Logger::resetStreams() + { + if (!out) + out = std::make_shared<LoggerImp>(&std::cout); + + out->resetStreamList(); + } + + void logging::Logger::setStream(std::ostream* stream) { out = std::make_shared<LoggerImp>(stream); } + void logging::Logger::addStream(std::ostream* stream) + { + if (!out) + out = std::make_shared<LoggerImp>(stream); + else + out->addStreamToList(stream); + } + + void logging::Logger::setDebugLevel(const Level &level) { globalLogLevel = level; diff --git a/src/VirtualFluidsBasics/utilities/logger/Logger.h b/src/VirtualFluidsBasics/utilities/logger/Logger.h index 7461fff912d2d1f7fbfc17a7155cb65f6b490446..8ff9af0e29d4b9e3a2d097ff0a3ee302d6983b70 100644 --- a/src/VirtualFluidsBasics/utilities/logger/Logger.h +++ b/src/VirtualFluidsBasics/utilities/logger/Logger.h @@ -6,14 +6,15 @@ #include <string> #include <memory> #include <ostream> - +#include <vector> +#include "../../../core/PointerDefinitions.h" namespace logging { class __declspec(dllexport) Logger { protected: - Logger(std::ostream &stream); + Logger(std::ostream* stream); public: virtual ~Logger(); @@ -22,10 +23,15 @@ namespace logging { HIGH = 3, INTERMEDIATE = 2, - LOW = 1 + LOW = 1, + WARNING = 0, + ERROR = -1 }; - static void setStream(std::ostream &stream); + static void setStream(std::ostream* stream); + static void addStream(std::ostream* stream); + static void resetStreams(); + static void setDebugLevel(const Level &level = Level::HIGH); static void enablePrintedRankNumbers(bool printRankNumbers); @@ -36,7 +42,11 @@ namespace logging virtual Logger& operator<<(const double &log) = 0; protected: - std::ostream &stream; + void addStreamToList(std::ostream* stream); + void resetStreamList(); + + std::vector<std::ostream*> streams; + static Level globalLogLevel; static Level localLogLevel; static bool printRankNumber; diff --git a/src/VirtualFluidsBasics/utilities/logger/implementations/LoggerImp.cpp b/src/VirtualFluidsBasics/utilities/logger/implementations/LoggerImp.cpp index 16486dcaebd56c3224dcaa261dc43511a4d1f139..55f0267f73437222568984ec5289f725e50b2ccc 100644 --- a/src/VirtualFluidsBasics/utilities/logger/implementations/LoggerImp.cpp +++ b/src/VirtualFluidsBasics/utilities/logger/implementations/LoggerImp.cpp @@ -5,7 +5,7 @@ #include <memory> #include <iostream> -logging::LoggerImp::LoggerImp(std::ostream &stream) : logging::Logger(stream) +logging::LoggerImp::LoggerImp(std::ostream* stream) : logging::Logger(stream) { } @@ -21,7 +21,7 @@ logging::Logger& logging::LoggerImp::operator<<(const Level &level) return *this; } -bool logging::LoggerImp::isLocalLogLevelHighEnough() +bool logging::LoggerImp::isLocalLogLevel_greateEqual_GlobalLevel() { return localLogLevel >= globalLogLevel; } @@ -46,17 +46,17 @@ logging::Logger& logging::LoggerImp::operator<<(const double &message) return this->log(std::to_string(message)); } - logging::Logger& logging::LoggerImp::log(const std::string &message) { - if (isLocalLogLevelHighEnough()) - stream << getRankString() + message; + if (isLocalLogLevel_greateEqual_GlobalLevel()) + { + for(auto stream : streams) + *stream << message; + } return *this; } - - std::string logging::LoggerImp::getRankString() { int rank; diff --git a/src/VirtualFluidsBasics/utilities/logger/implementations/LoggerImp.h b/src/VirtualFluidsBasics/utilities/logger/implementations/LoggerImp.h index 58c7c693392d31fa81704f7f47e957ca4ada6bcc..d29755e049137fb9223179162805325514205174 100644 --- a/src/VirtualFluidsBasics/utilities/logger/implementations/LoggerImp.h +++ b/src/VirtualFluidsBasics/utilities/logger/implementations/LoggerImp.h @@ -17,19 +17,19 @@ namespace logging class __declspec(dllexport) LoggerImp : public Logger { public: - LoggerImp(std::ostream &stream); + LoggerImp(std::ostream* stream); virtual ~LoggerImp(); - Logger& operator<<(const Level &level); - Logger& operator<<(const std::string &message); - Logger& operator<<(const int &message); - Logger& operator<<(const float &message); - Logger& operator<<(const double &message); + Logger& operator<<(const Level &level) override; + Logger& operator<<(const std::string &message) override; + Logger& operator<<(const int &message) override; + Logger& operator<<(const float &message) override; + Logger& operator<<(const double &message) override; private: std::string getRankString(); - bool isLocalLogLevelHighEnough(); + static bool isLocalLogLevel_greateEqual_GlobalLevel(); logging::Logger& log(const std::string &message); diff --git a/src/VirtualFluidsBasics/utilities/logger/implementations/LoggerTest.cpp b/src/VirtualFluidsBasics/utilities/logger/implementations/LoggerTest.cpp index 7d2ca8d04733b2388bc5953e6e1080f62a30ea9e..4f401ee4ce15aafdfadcfd1f1956f26f501fc0fa 100644 --- a/src/VirtualFluidsBasics/utilities/logger/implementations/LoggerTest.cpp +++ b/src/VirtualFluidsBasics/utilities/logger/implementations/LoggerTest.cpp @@ -8,7 +8,7 @@ TEST(LoggerTest, logStringWithoutSettingLevels_WillPutTheLogMesssageIntoTheStream) { std::ostringstream stream; - logging::Logger::setStream(stream); + logging::Logger::setStream(&stream); *logging::out << "Hello World\n"; @@ -18,10 +18,24 @@ TEST(LoggerTest, logStringWithoutSettingLevels_WillPutTheLogMesssageIntoTheStrea TEST(LoggerTest, logStringWithHighDebugLevel_logOnlyHighLevelMessages) { std::ostringstream stream; - logging::Logger::setStream(stream); + logging::Logger::setStream(&stream); logging::Logger::setDebugLevel(logging::Logger::HIGH); *logging::out << logging::Logger::LOW << "Low Debug Message\n" << logging::Logger::HIGH << "HIGH Debug Message\n"; EXPECT_THAT(stream.str(), "HIGH Debug Message\n"); -} \ No newline at end of file +} + +TEST(LoggerTest, addTwoStreams_shouldWriteToBoth) +{ + logging::Logger::resetStreams(); + + std::ostringstream stream1, stream2; + logging::out->addStream(&stream1); + logging::out->addStream(&stream2); + + *logging::out << "Hello World\n"; + + EXPECT_THAT(stream1.str(), "Hello World\n"); + EXPECT_THAT(stream2.str(), "Hello World\n"); +} diff --git a/targets/apps/HULC/main.cpp b/targets/apps/HULC/main.cpp index f9e1340b7df58579e052c582791789d972664071..c6407ca3b09c1ee9024bb22db5658e4f0a559612 100644 --- a/targets/apps/HULC/main.cpp +++ b/targets/apps/HULC/main.cpp @@ -25,6 +25,11 @@ #include "geometries/Geometry/Geometry.cuh" #include "grid/GridFactory.h" +#include "grid/GridBuilder/MultipleGridBuilder.h" +#include <grid/GridMocks.h> +#include "grid/GridStrategy/GridStrategyMocks.h" +#include "VirtualFluidsBasics/utilities/logger/Logger.h" + std::string getGridPath(std::shared_ptr<Parameter> para, std::string Gridpath) { @@ -232,17 +237,34 @@ void setParameters(std::shared_ptr<Parameter> para, std::unique_ptr<input::Input void multipleLevel(const std::string& configPath) { - auto gridBuilder = LevelGridBuilder::makeShared("cpu", "D3Q27"); + logging::Logger::setStream(&std::cout); + logging::Logger::setDebugLevel(logging::Logger::HIGH); + + auto gridFactory = SPtr<GridFactory<GridDummy> >(new GridFactory<GridDummy>()); + gridFactory->setGridStrategy(SPtr<GridStrategy>(new GridStrategyDummy())); + auto gridBuilderlevel = LevelGridBuilder::makeShared(Device::CPU, "D3Q27"); + auto gridBuilder = MultipleGridBuilder<GridDummy>::makeShared(gridFactory); + gridBuilder->addCoarseGrid(-10.0, -10.0, -10.0, 30.0, 30.0, 30.0, 1.0); + + + + gridBuilder->addFineGrid(7.0, 7.0, 7.0, 10.0, 10.0, 10.0, 4); + + //const uint level = 2; + //gridBuilder->addFineGrid(0.0, 0.0, 0.0, 10.0, 10.0, 10.0, level); + gridBuilderlevel->setGrids(gridBuilder->getGrids()); + + //gridBuilder->addGrid(14.4921875, 14.4921875, 14.4921875, 16.5078125, 16.5078125, 16.5078125, 0.015625, "cpu", "D3Q27", false, false, false); //gridBuilder->addGrid(13.984375, 13.984375, 13.984375, 17.015625, 17.015625, 17.015625, 0.03125, "cpu", "D3Q27", false, false, false); //gridBuilder->addGrid(13.46875, 13.46875, 13.46875, 17.53125, 17.53125, 17.53125, 0.0625, "cpu", "D3Q27", false, false, false); - gridBuilder->addGrid(12.4375, 12.4375, 12.4375, 18.5625, 18.5625, 18.5625, 0.125, "gpu", "D3Q27", false, false, false); - gridBuilder->addGrid(10.375, 10.375, 10.375, 20.625, 20.625, 20.625, 0.25, "gpu", "D3Q27", false, false, false); - gridBuilder->addGrid(5.25, 5.25, 5.25, 24.75, 24.75, 24.75, 0.5, "gpu", "D3Q27", false, false, false); - gridBuilder->addGrid(0.0, 0.0, 0.0, 30.0, 30.0, 30.0, 1.0, "gpu", "D3Q27", true, true, true); + //gridBuilder->addGrid(12.4375, 12.4375, 12.4375, 18.5625, 18.5625, 18.5625, 0.125, "gpu", "D3Q27", false, false, false); + //gridBuilder->addGrid(10.375, 10.375, 10.375, 20.625, 20.625, 20.625, 0.25, "gpu", "D3Q27", false, false, false); + //gridBuilder->addGrid(5.25, 5.25, 5.25, 24.75, 24.75, 24.75, 0.5, "gpu", "D3Q27", false, false, false); + //gridBuilder->addGrid(0.0, 0.0, 0.0, 30.0, 30.0, 30.0, 1.0, "gpu", "D3Q27", true, true, true); - gridBuilder->copyDataFromGpu(); + //gridBuilder->copyDataFromGpu(); //SimulationFileWriter::write("D:/GRIDGENERATION/couplingVF/periodicTaylorThreeLevel/simu/", gridBuilder, FILEFORMAT::ASCII); //gridBuilder->meshGeometry("D:/GRIDGENERATION/STL/circleBinaer.stl", 1); @@ -252,7 +274,7 @@ void multipleLevel(const std::string& configPath) //gridBuilder->writeGridToVTK("D:/GRIDGENERATION/gridTest_level_2", 2); SPtr<Parameter> para = Parameter::makeShared(); - SPtr<GridProvider> gridGenerator = GridProvider::makeGridGenerator(gridBuilder, para); + SPtr<GridProvider> gridGenerator = GridProvider::makeGridGenerator(gridBuilderlevel, para); //SPtr<GridProvider> gridGenerator = GridProvider::makeGridReader(false, para); std::ifstream stream; @@ -284,9 +306,9 @@ int main( int argc, char* argv[]) { multipleLevel(str2); } - catch (std::string e) + catch (std::exception e) { - std::cout << e << std::flush; + std::cout << e.what() << std::flush; //MPI_Abort(MPI_COMM_WORLD, -1); } }