Skip to content

Commit

Permalink
added config file option and hopefully fixed circulardambreak2d
Browse files Browse the repository at this point in the history
  • Loading branch information
xLPMG committed Jan 31, 2024
1 parent c484118 commit a7459f2
Show file tree
Hide file tree
Showing 7 changed files with 103 additions and 58 deletions.
16 changes: 16 additions & 0 deletions configs/1d.json
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 4 additions & 6 deletions configs/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 11 additions & 0 deletions src/Server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")
{
Expand Down
4 changes: 2 additions & 2 deletions src/setups/CircularDamBreak2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
117 changes: 68 additions & 49 deletions src/ui/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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.");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<std::string> 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<std::string> 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);
Expand Down
1 change: 1 addition & 0 deletions src/ui/GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a7459f2

Please sign in to comment.