Skip to content

Commit

Permalink
Merge branch 'gui_develop' of https://github.com/xLPMG/tsunami_lab in…
Browse files Browse the repository at this point in the history
…to gui_develop
  • Loading branch information
xLPMG committed Jan 11, 2024
2 parents 985476b + 7a4f8cf commit 3a1e737
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 25 deletions.
21 changes: 21 additions & 0 deletions imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Collapsed=1
[Window][Welcome to the Tsunami Simulator GUI! (NOT CONNECTED)]
Pos=60,60
Size=482,364
Collapsed=1

[Window][Welcome to the Tsunami Simulator GUI! (CONNECTED)]
Pos=76,113
Expand All @@ -45,3 +46,23 @@ Size=803,471
Pos=60,60
Size=200,117

[Window][Stacked 1]
Pos=545,372
Size=409,172

[Window][Stacked 2]
Pos=637,422
Size=226,71

[Window][Delete?]
Pos=594,405
Size=311,105

[Window][Dear ImGui Demo/ResizableChild_D5443E47]
IsChild=1
Size=499,136

[Window][Dear ImGui Demo/Red_1D4E05CE]
IsChild=1
Size=200,100

85 changes: 60 additions & 25 deletions src/ui/GUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,38 @@ static void HelpMarker(const char *desc)
}
}

// json tsunami_lab::ui::GUI::createJson(){
// if(event_current == 1){
// return json config = {
// "solver": fwave,
// "setup":TOHOKU,
// "outputFileName":tohoku_solution,
// "nx":l_simulationSizeX,
// "ny":l_simulationSizeY,
// "endTime":endTime,
// "writingFrequency":writingFrequency,
// "hasBoundaryL":outflowL,
// "hasBoundaryR":outflowR,
// "hasBoundaryT":outflowT,
// "hasBoundaryB":outflowB
// };
// } else{
// return json config = {
// "solver": fwave,
// "setup":CHILE,
// "outputFileName":chile_solution,
// "nx":l_simulationSizeX,
// "ny":l_simulationSizeY,
// "endTime":endTime,
// "writingFrequency":writingFrequency,
// "hasBoundaryL":outflowL,
// "hasBoundaryR":outflowR,
// "hasBoundaryT":outflowT,
// "hasBoundaryB":outflowB
// };
// }
// }

// Main code
int tsunami_lab::ui::GUI::launch(int i_PORT)
{
Expand Down Expand Up @@ -146,8 +178,16 @@ int tsunami_lab::ui::GUI::launch(int i_PORT)
bool openMp = false;
bool Checkpointing = false;

bool disableConfigs = false;



ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);





unsigned char *pixels = new unsigned char[100 * 100 * 3];
for (int y = 0; y < 100; ++y)
{
Expand All @@ -158,6 +198,10 @@ int tsunami_lab::ui::GUI::launch(int i_PORT)
pixels[y * 100 * 3 + x * 3 + 2] = 0x00; // B
}
}




// Main loop
while (!glfwWindowShouldClose(window))
{
Expand Down Expand Up @@ -262,8 +306,12 @@ int tsunami_lab::ui::GUI::launch(int i_PORT)
{
if (m_communicator.sendToServer(tsunami_lab::KEY_START_SIMULATION) == 0)
{
//json config = createJson();
usleep(1000);
//m_communicator.sendToServer(config);
m_communicator.sendToServer("configs/chile5000.json");

disableConfigs = true;
}
}
if (ImGui::Button("Shutdown server"))
Expand Down Expand Up @@ -343,19 +391,7 @@ int tsunami_lab::ui::GUI::launch(int i_PORT)
ImGui::EndMenu();
}
ImGui::SameLine();
HelpMarker("Determines whether the waves leaves the corresponding domain.");

// ImGui::CheckboxFlags("io.ConfigFlags: NavEnableKeyboard", &io.ConfigFlags, ImGuiConfigFlags_NavEnableKeyboard);

// ImGui::SeparatorText("Sliders");
// {
// static float f1 = 0.123f, f2 = 0.0f;
// ImGui::SliderFloat("fes", &f1, 0.0f, 1.0f, "ratio = %.3f");
// ImGui::SameLine(); HelpMarker("CTRL+click to input value.");

// // static float angle = 0.0f;
// // ImGui::SliderAngle("slider angle", &angle);
// }
HelpMarker("Determines whether the wave leaves the corresponding domain.");

if (ImGui::Button("Close"))
showSimulationParameterWindow = false;
Expand All @@ -366,13 +402,16 @@ int tsunami_lab::ui::GUI::launch(int i_PORT)
if (showCompilerOptionsWindow)
{
ImGui::Begin("Simulation parameters");
const char *items[] = {"O0", "O1", "O2"};
static int item_current = 0;
ImGui::Combo("Compiler Optimization Flag", &item_current, items, IM_ARRAYSIZE(items));
const char *flags[] = {"O0", "O1", "O2"};
ImGui::Combo("Compiler Optimization Flag", &flag_current, flags, IM_ARRAYSIZE(flags));
ImGui::Checkbox("Use OpenMp", &openMp);

if (ImGui::Button("Recompile"))
{
if (m_communicator.sendToServer(tsunami_lab::KEY_WRITE_CHECKPOINT) == 0)
{
usleep(1000);
}
}

if (ImGui::Button("Close"))
Expand All @@ -384,30 +423,25 @@ int tsunami_lab::ui::GUI::launch(int i_PORT)
// Simulation parameters
if (showSimulationParameterWindow)
{
static int l_nx = 1;
static int l_ny = 1;
static tsunami_lab::t_real l_simulationSizeX = 0;
static tsunami_lab::t_real l_simulationSizeY = 0;
static tsunami_lab::t_real endTime = 1000;
static int writingFrequency = 100; // todo: change int to t_idx

if(disableConfigs == false){
ImGui::Begin("Simulation parameters");

ImGui::InputInt("Cells X", &l_nx, 1, 100);
ImGui::InputInt("Cells Y", &l_ny, 1, 100);
l_nx = abs(l_nx);
l_ny = abs(l_ny);

const char *events[] = {"Tohoku", "Chile", "Custom"};
ImGui::Combo("Tsunami Event", &event_current, events, IM_ARRAYSIZE(events));

ImGui::InputFloat("Simulation size X", &l_simulationSizeX);
ImGui::InputFloat("Simulation size Y", &l_simulationSizeY);
l_simulationSizeX = abs(l_simulationSizeX);
l_simulationSizeY = abs(l_simulationSizeY);

ImGui::InputFloat("Endtime", &endTime);
// ImGui::InputFloat("Writingfrequency", &writingFrequency);
ImGui::SeparatorText("Sliders");
{
// static float f1 = 0.123f, f2 = 0.0f;
ImGui::SliderInt("Writingfrequency", &writingFrequency, 10, 1000);
ImGui::SameLine();
HelpMarker("CTRL+click to input value.");
Expand All @@ -418,6 +452,7 @@ int tsunami_lab::ui::GUI::launch(int i_PORT)
if (ImGui::Button("Close"))
showSimulationParameterWindow = false;
ImGui::End();
}
}
// Rendering
ImGui::Render();
Expand Down
15 changes: 15 additions & 0 deletions src/ui/GUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

#include "Communicator.hpp"

#include <nlohmann/json.hpp>
using json = nlohmann::json;


namespace tsunami_lab
{
namespace ui
Expand All @@ -30,6 +34,17 @@ class tsunami_lab::ui::GUI
public:
int launch(int PORT);

json createJson();


int event_current = 0;
int l_nx = 1;
int l_ny = 1;
float l_simulationSizeX = 0;
float l_simulationSizeY = 0;
float endTime = 1000;
int writingFrequency = 100; // todo: change int to t_idx
int flag_current = 0;

};

Expand Down

0 comments on commit 3a1e737

Please sign in to comment.