From a7459f2959c379fb14c6a0de85ebc7ed7cc66955 Mon Sep 17 00:00:00 2001 From: Luca G Date: Wed, 31 Jan 2024 21:57:12 +0100 Subject: [PATCH] added config file option and hopefully fixed circulardambreak2d --- configs/1d.json | 16 ++++ configs/config.json | 10 +-- src/Server.cpp | 11 +++ src/Simulator.cpp | 2 +- src/setups/CircularDamBreak2d.cpp | 4 +- src/ui/GUI.cpp | 117 +++++++++++++++++------------- src/ui/GUI.h | 1 + 7 files changed, 103 insertions(+), 58 deletions(-) create mode 100644 configs/1d.json diff --git a/configs/1d.json b/configs/1d.json new file mode 100644 index 00000000..dae5e204 --- /dev/null +++ b/configs/1d.json @@ -0,0 +1,16 @@ +{ + "solver": "fwave", + "simulationSizeX": 10, + "simulationSizeY": 1, + "offsetX": 0, + "offsetY": 0, + "nx":10, + "ny":1, + "setup":"DAMBREAK1D", + "writingFrequency":10, + "endTime":10, + "baseHeight":5, + "height":100, + "outputMethod":"csv", + "timeStepScaling":0.2 +} \ No newline at end of file diff --git a/configs/config.json b/configs/config.json index 2cfee871..e7efd8f7 100644 --- a/configs/config.json +++ b/configs/config.json @@ -8,10 +8,8 @@ "ny":100, "setup":"CIRCULARDAMBREAK2D", "writingFrequency":50, - "endTime":50, - "stations":[ - { "name":"station_1", "locX":0, "locY":10 }, - { "name":"station_2", "locX":5, "locY":10 }, - { "name":"station_3", "locX":10, "locY":10 } - ] + "endTime":30, + "baseHeight":5, + "diameter":10, + "height":100 } \ No newline at end of file diff --git a/src/Server.cpp b/src/Server.cpp index e58b461d..687fd596 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -406,6 +406,17 @@ int main(int i_argc, char *i_argv[]) { std::cout << "Warning: Could not reset because the simulation is still running." << std::endl; } + }else if (l_key == xlpmg::LOAD_CONFIG_FILE.key) + { + simulator->loadConfigDataFromFile(l_args); + if (canRunThread()) + { + m_simulationThread = std::thread(&tsunami_lab::Simulator::resetSimulator, simulator); + } + else + { + std::cout << "Warning: Could not reset because the simulation is still running." << std::endl; + } } else if (l_key == xlpmg::DELETE_CHECKPOINTS.key) { diff --git a/src/Simulator.cpp b/src/Simulator.cpp index 73d42772..4b27d80f 100644 --- a/src/Simulator.cpp +++ b/src/Simulator.cpp @@ -161,7 +161,7 @@ void tsunami_lab::Simulator::constructSetup() } else if (m_setupChoice == "DAMBREAK1D") { - m_setup = new tsunami_lab::setups::DamBreak1d(10, 5, m_simulationSizeX / 2); + m_setup = new tsunami_lab::setups::DamBreak1d(m_height, m_baseHeight, m_simulationSizeX / 2); } else if (m_setupChoice == "CIRCULARDAMBREAK2D") { diff --git a/src/setups/CircularDamBreak2d.cpp b/src/setups/CircularDamBreak2d.cpp index 175df67e..2c30e5e2 100644 --- a/src/setups/CircularDamBreak2d.cpp +++ b/src/setups/CircularDamBreak2d.cpp @@ -23,7 +23,7 @@ tsunami_lab::t_real tsunami_lab::setups::CircularDamBreak2d::getHeight(t_real i_ t_real i_y) const { tsunami_lab::t_real sumOfSquares = i_x * i_x + i_y * i_y; - return std::sqrt(sumOfSquares) < m_radius ? m_height : m_baseHeight; + return std::sqrt(sumOfSquares) < m_radius ? m_height-getBathymetry(i_x, i_y) : m_baseHeight-getBathymetry(i_x, i_y); } tsunami_lab::t_real tsunami_lab::setups::CircularDamBreak2d::getMomentumX(t_real, t_real) const @@ -38,5 +38,5 @@ tsunami_lab::t_real tsunami_lab::setups::CircularDamBreak2d::getMomentumY(t_real tsunami_lab::t_real tsunami_lab::setups::CircularDamBreak2d::getBathymetry(t_real, t_real) const { - return 0; + return -100; } \ No newline at end of file diff --git a/src/ui/GUI.cpp b/src/ui/GUI.cpp index b631b880..a2ffaa8d 100644 --- a/src/ui/GUI.cpp +++ b/src/ui/GUI.cpp @@ -209,6 +209,7 @@ int tsunami_lab::ui::GUI::launch() bool showSimulationParameterWindow = false; bool showSystemInfoWindow = false; bool showSimulationControlsWindow = false; + bool showStationDataVisualizer = false; bool showDataVisualizer = false; ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); @@ -488,12 +489,14 @@ int tsunami_lab::ui::GUI::launch() ImGui::SameLine(); HelpMarker("The continuous dimension of time is discretized using 'time steps'. The length of a time step is computed anew for each simulation in a way such that the waves do not interact with each other."); - ImGui::Text("Time per time step: %i", m_timePerTimeStep); + ImGui::ProgressBar((float)m_currentTimeStep / (float)m_maxTimeSteps, ImVec2(0.0f, 0.0f)); + + ImGui::Text("Time per time step: %ims", m_timePerTimeStep); ImGui::SetItemTooltip("in milliseconds"); ImGui::SameLine(); HelpMarker("The time the solver takes to compute one time step."); - ImGui::Text("Estimated time left: %f", m_estimatedTimeLeft); + ImGui::Text("Estimated time left: %is", (int)m_estimatedTimeLeft); ImGui::SetItemTooltip("in seconds"); ImGui::SameLine(); HelpMarker("Time until the solver has finished the whole computation."); @@ -541,6 +544,7 @@ int tsunami_lab::ui::GUI::launch() ImGui::Checkbox("Show simulation controls", &showSimulationControlsWindow); ImGui::Checkbox("Edit compiler/runtime options", &showCompilerOptionsWindow); ImGui::Checkbox("Edit simulation parameters", &showSimulationParameterWindow); + ImGui::Checkbox("Show station data visualizer", &showStationDataVisualizer); ImGui::Checkbox("Show data visualizer", &showDataVisualizer); ImGui::Checkbox("Show client log", &showClientLog); ImGui::Checkbox("Show system info", &showSystemInfoWindow); @@ -854,13 +858,26 @@ int tsunami_lab::ui::GUI::launch() short width = 24; + ImGui::InputTextWithHint("Config file path", "configs/config.json", m_configFilePath, IM_ARRAYSIZE(m_configFilePath)); + if (ImGui::Button("Load config")) + { + xlpmg::Message l_loadConfigMsg = xlpmg::LOAD_CONFIG_FILE; + l_loadConfigMsg.args = m_configFilePath; + m_communicator.sendToServer(messageToJsonString(l_loadConfigMsg)); + } + + ImGui::SeparatorText("Custom options"); + ImGui::SetNextItemWidth(ImGui::GetFontSize() * width); ImGui::Combo("Tsunami Event", &m_tsunamiEvent, m_tsunamiEvents, IM_ARRAYSIZE(m_tsunamiEvents)); if (!strcmp(m_tsunamiEvents[m_tsunamiEvent], "CIRCULARDAMBREAK2D")) { + ImGui::SetNextItemWidth(ImGui::GetFontSize() * width); ImGui::InputInt("Waterheight", &m_height, 0); + ImGui::SetNextItemWidth(ImGui::GetFontSize() * width); ImGui::InputInt("Base water Height", &m_baseHeight, 0); + ImGui::SetNextItemWidth(ImGui::GetFontSize() * width); ImGui::InputInt("Diameter", &m_diameter, 0); } @@ -1127,60 +1144,62 @@ int tsunami_lab::ui::GUI::launch() ImGui::End(); // STATIONS - ImGui::Begin("Station data"); + if (showStationDataVisualizer) + { + ImGui::Begin("Station data", &showStationDataVisualizer); - if (ImGui::Button("Select station data file")) - fileDialogStation.Open(); + if (ImGui::Button("Select station data file")) + fileDialogStation.Open(); - fileDialogStation.Display(); + fileDialogStation.Display(); - if (fileDialogStation.HasSelected()) - { - m_stationFilePath = fileDialogStation.GetSelected().string(); - fileDialogStation.ClearSelected(); - - m_stationTime.clear(); - m_stationMomentumX.clear(); - m_stationMomentumY.clear(); - m_stationBathymetry.clear(); - m_stationTotalHeight.clear(); - - // load data - std::ifstream l_inputFile(m_stationFilePath); - std::vector l_row; - std::string l_line; - std::getline(l_inputFile, l_line); // skip header - while (getline(l_inputFile, l_line)) + if (fileDialogStation.HasSelected()) { - tsunami_lab::io::Csv::splitLine(std::stringstream(l_line), ',', l_row); - m_stationTime.push_back(stof(l_row[0])); - m_stationMomentumX.push_back(stof(l_row[2])); - m_stationMomentumY.push_back(stof(l_row[3])); - m_stationBathymetry.push_back(stof(l_row[4])); - m_stationTotalHeight.push_back(stof(l_row[5])); + m_stationFilePath = fileDialogStation.GetSelected().string(); + fileDialogStation.ClearSelected(); + + m_stationTime.clear(); + m_stationMomentumX.clear(); + m_stationMomentumY.clear(); + m_stationBathymetry.clear(); + m_stationTotalHeight.clear(); + + // load data + std::ifstream l_inputFile(m_stationFilePath); + std::vector l_row; + std::string l_line; + std::getline(l_inputFile, l_line); // skip header + while (getline(l_inputFile, l_line)) + { + tsunami_lab::io::Csv::splitLine(std::stringstream(l_line), ',', l_row); + m_stationTime.push_back(stof(l_row[0])); + m_stationMomentumX.push_back(stof(l_row[2])); + m_stationMomentumY.push_back(stof(l_row[3])); + m_stationBathymetry.push_back(stof(l_row[4])); + m_stationTotalHeight.push_back(stof(l_row[5])); + } } - } - ImGui::SameLine(); - ImGui::Text("Selected file: %s", m_stationFilePath.c_str()); + ImGui::SameLine(); + ImGui::Text("Selected file: %s", m_stationFilePath.c_str()); - std::string l_plotName = m_stationFilePath.substr(m_stationFilePath.find_last_of("/\\") + 1) + ": heights"; - if (ImPlot::BeginPlot(l_plotName.c_str())) - { - ImPlot::SetupAxes("time in seconds", "height in metres"); - ImPlot::PlotLine("bathymetry", &m_stationTime[0], &m_stationBathymetry[0], m_stationTime.size()); - ImPlot::PlotLine("water level", &m_stationTime[0], &m_stationTotalHeight[0], m_stationTime.size()); - ImPlot::EndPlot(); - } - l_plotName = m_stationFilePath.substr(m_stationFilePath.find_last_of("/\\") + 1) + ": momenta"; - if (ImPlot::BeginPlot(l_plotName.c_str())) - { - ImPlot::SetupAxes("time in seconds", "momentum in m^2/s"); - ImPlot::PlotLine("momentum in x-direction", &m_stationTime[0], &m_stationMomentumX[0], m_stationTime.size()); - ImPlot::PlotLine("momentum in y-direction", &m_stationTime[0], &m_stationMomentumY[0], m_stationTime.size()); - ImPlot::EndPlot(); + std::string l_plotName = m_stationFilePath.substr(m_stationFilePath.find_last_of("/\\") + 1) + ": heights"; + if (ImPlot::BeginPlot(l_plotName.c_str())) + { + ImPlot::SetupAxes("time in seconds", "height in metres"); + ImPlot::PlotLine("bathymetry", &m_stationTime[0], &m_stationBathymetry[0], m_stationTime.size()); + ImPlot::PlotLine("water level", &m_stationTime[0], &m_stationTotalHeight[0], m_stationTime.size()); + ImPlot::EndPlot(); + } + l_plotName = m_stationFilePath.substr(m_stationFilePath.find_last_of("/\\") + 1) + ": momenta"; + if (ImPlot::BeginPlot(l_plotName.c_str())) + { + ImPlot::SetupAxes("time in seconds", "momentum in m^2/s"); + ImPlot::PlotLine("momentum in x-direction", &m_stationTime[0], &m_stationMomentumX[0], m_stationTime.size()); + ImPlot::PlotLine("momentum in y-direction", &m_stationTime[0], &m_stationMomentumY[0], m_stationTime.size()); + ImPlot::EndPlot(); + } + ImGui::End(); } - ImGui::End(); - if (showDataVisualizer) { ImGui::SetNextWindowSize(ImVec2(640, 640), ImGuiCond_FirstUseEver); diff --git a/src/ui/GUI.h b/src/ui/GUI.h index 057e79c2..24bd1ae4 100644 --- a/src/ui/GUI.h +++ b/src/ui/GUI.h @@ -74,6 +74,7 @@ class tsunami_lab::ui::GUI char m_sbTim[256] = "10:00:00"; // simulation parameters + char m_configFilePath[256] = ""; const char *m_tsunamiEvents[3] = {"CUSTOM", "ARTIFICIAL2D", "CIRCULARDAMBREAK2D"}; int m_tsunamiEvent = 0; int m_nx = 1;