Skip to content

Commit

Permalink
Finished semi-lagrangian advection
Browse files Browse the repository at this point in the history
  • Loading branch information
Zang3th committed May 16, 2024
1 parent ca5a771 commit bb040e9
Show file tree
Hide file tree
Showing 14 changed files with 2,332 additions and 247 deletions.
23 changes: 13 additions & 10 deletions Apps/Liquefied/LiquefiedApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,25 @@ namespace Liq

void LiquefiedApp::VisualizeSmoke() const
{
glm::vec3 color{0.0f};

for(Engine::uint32 x = 1; x < Engine::LiquiefiedParams::SIMULATION_WIDTH-1; x++)
{
for(Engine::uint32 y = 1; y < Engine::LiquiefiedParams::SIMULATION_HEIGHT-1; y++)
{
const float val = _fluidSimulator->GetDensity(x, y);
glm::vec3 color = {val, val, val};

if(Engine::LiquiefiedParams::scientificColorScheme)
if(Engine::LiquiefiedParams::visualizationChoice == Engine::Visualization::Greyscale)
{
color = {val, val, val};
}
else if(Engine::LiquiefiedParams::visualizationChoice == Engine::Visualization::BlackBody)
{
color = Engine::Utility::GetScienticColor(val, 0.0f, 1.0f);
color = Engine::Utility::GetColor_BlackBody(val);
}
else if(Engine::LiquiefiedParams::visualizationChoice == Engine::Visualization::ParaView)
{
color = Engine::Utility::GetColor_ParaView(val);
}

_gridRenderer->Set(x, y, color);
Expand Down Expand Up @@ -167,7 +176,7 @@ namespace Liq
{
Engine::PROFILE_SCOPE("Visualize grid");

if(Engine::LiquiefiedParams::visualizeSmoke)
if(Engine::LiquiefiedParams::visualizationChoice != Engine::Visualization::Nothing)
{
VisualizeSmoke();
_gridRenderer->UpdateGpuStorage();
Expand Down Expand Up @@ -202,12 +211,6 @@ namespace Liq
else if(glfwGetKey(Engine::Window::GetWindow(), GLFW_KEY_SPACE) == GLFW_PRESS)
Engine::LiquiefiedParams::pauseSimulation = !Engine::LiquiefiedParams::pauseSimulation;

else if(glfwGetKey(Engine::Window::GetWindow(), GLFW_KEY_S) == GLFW_PRESS)
Engine::LiquiefiedParams::visualizeSmoke = !Engine::LiquiefiedParams::visualizeSmoke;

else if(glfwGetKey(Engine::Window::GetWindow(), GLFW_KEY_C) == GLFW_PRESS)
Engine::LiquiefiedParams::scientificColorScheme = !Engine::LiquiefiedParams::scientificColorScheme;

else if(glfwGetKey(Engine::Window::GetWindow(), GLFW_KEY_R) == GLFW_PRESS)
Engine::LiquiefiedParams::resetSimulation = true;

Expand Down
100 changes: 66 additions & 34 deletions Apps/Liquefied/LiquefiedInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,48 @@ namespace Liq
ImGui::Text("%.3fms - %s", entry.second, entry.first);
}
ImGui::Separator();

// --- Simulation settings
ImGui::NewLine();
ImGui::Separator();
CenterText("Simulation settings");
ImGui::Separator();
ImGui::NewLine();
ImGui::RadioButton("Forward Euler", (int*)&Engine::LiquiefiedParams::integratorChoice, Engine::Integrator::ForwardEuler);
ImGui::RadioButton("Backward Euler", (int*)&Engine::LiquiefiedParams::integratorChoice, Engine::Integrator::BackwardEuler);
ImGui::RadioButton("Semi Lagrangian", (int*)&Engine::LiquiefiedParams::integratorChoice, Engine::Integrator::SemiLagrangian);
ImGui::NewLine();
ImGui::Text("Turbine power: ");
ImGui::SameLine();
ImGui::PushItemWidth(150.0f);
Input_u32("##Input1", &Engine::LiquiefiedParams::turbinePower, 100, 1000, ImGuiInputTextFlags_CharsDecimal);
ImGui::NewLine();
ImGui::Separator();

// --- Simulation settings
if(ImGui::BeginTabBar("##Tabs", ImGuiTabBarFlags_None))
{
ImGui::NewLine();

if(ImGui::BeginTabItem("Integrator"))
{
ImGui::NewLine();
ImGui::RadioButton("Forward Euler", (int*)&Engine::LiquiefiedParams::integratorChoice, Engine::Integrator::ForwardEuler);
ImGui::RadioButton("Modified Forward Euler", (int*)&Engine::LiquiefiedParams::integratorChoice, Engine::Integrator::ModifiedForwardEuler);
ImGui::RadioButton("Runge Kutta 2", (int*)&Engine::LiquiefiedParams::integratorChoice, Engine::Integrator::RungeKutta2);
ImGui::RadioButton("Semi Lagrangian", (int*)&Engine::LiquiefiedParams::integratorChoice, Engine::Integrator::SemiLagrangian);
ImGui::EndTabItem();
}

if(ImGui::BeginTabItem("Visualization"))
{
ImGui::NewLine();
ImGui::RadioButton("No visualization", (int*)&Engine::LiquiefiedParams::visualizationChoice, Engine::Visualization::Nothing);
ImGui::RadioButton("Greyscale", (int*)&Engine::LiquiefiedParams::visualizationChoice, Engine::Visualization::Greyscale);
ImGui::RadioButton("BlackBody", (int*)&Engine::LiquiefiedParams::visualizationChoice, Engine::Visualization::BlackBody);
ImGui::RadioButton("ParaView", (int*)&Engine::LiquiefiedParams::visualizationChoice, Engine::Visualization::ParaView);
ImGui::EndTabItem();
}

if(ImGui::BeginTabItem("Turbine"))
{
ImGui::NewLine();
ImGui::Text("Turbine power: ");
ImGui::SameLine();
ImGui::PushItemWidth(150.0f);
Input_u32("##Input1", &Engine::LiquiefiedParams::turbinePower, 10, 100, ImGuiInputTextFlags_CharsDecimal);
ImGui::EndTabItem();
}

ImGui::NewLine();
ImGui::Separator();
ImGui::EndTabBar();
}
// --- Numerical value monitoring
if(Engine::LiquiefiedParams::activateDebugging)
{
Expand Down Expand Up @@ -82,11 +106,30 @@ namespace Liq
ImGui::NewLine();
ImGui::Separator();
}

}
ImGui::End();
}

void LiquefiedInterface::AddVerticalBarDivider(float xpos) const
{
ImGui::SetCursorPosX(xpos);
ImGui::SetCursorPosY(3.0f);
ImGui::Text("|");
ImGui::SetCursorPosX(xpos);
ImGui::SetCursorPosY(16.0f);
ImGui::Text("|");
ImGui::SetCursorPosX(xpos);
ImGui::SetCursorPosY(29.0f);
ImGui::Text("|");
ImGui::SetCursorPosX(xpos);
ImGui::SetCursorPosY(42.0f);
ImGui::Text("|");
ImGui::SetCursorPosX(xpos);
ImGui::SetCursorPosY(55.0f);
ImGui::Text("|");
}


void LiquefiedInterface::AddBufferBar() const
{
ImGui::SetNextWindowBgAlpha(_windowAlphaValue);
Expand All @@ -97,33 +140,22 @@ namespace Liq
{
ImGui::SetCursorPosX(10.0f);
ImGui::SetCursorPosY(10.0f);
ImGui::Checkbox("Wireframe Rendering (W) |", &Engine::UIParams::wireframeRendering);
ImGui::Checkbox("Wireframe Rendering (W)", &Engine::UIParams::wireframeRendering);
ImGui::SetCursorPosY(45.0f);
ImGui::SetCursorPosX(10.0f);
ImGui::Checkbox("Pause Simulation (SPACE) |", &Engine::LiquiefiedParams::pauseSimulation);
ImGui::Checkbox("Pause Simulation (SPACE)", &Engine::LiquiefiedParams::pauseSimulation);
AddVerticalBarDivider(255.0f);

ImGui::SetCursorPosY(10.0f);
ImGui::SetCursorPosX(275.0f);
ImGui::Checkbox("Activate Debugging (A)", &Engine::LiquiefiedParams::activateDebugging);
ImGui::SetCursorPosY(45.0f);
ImGui::SetCursorPosX(275.0f);
if(ImGui::Button("Reset Simulation (R)"))
{
Engine::LiquiefiedParams::resetSimulation = true;
}
ImGui::SameLine();
ImGui::Text("|");
ImGui::SetCursorPosY(45.0f);
ImGui::SetCursorPosX(275.0f);
ImGui::Text(" |");

ImGui::SetCursorPosY(10.0f);
ImGui::SetCursorPosX(485.0f);
ImGui::Checkbox("Visualize Smoke (S) |", &Engine::LiquiefiedParams::visualizeSmoke);
ImGui::SetCursorPosY(45.0f);
ImGui::SetCursorPosX(485.0f);
ImGui::Checkbox("Scientific Colors (C) |", &Engine::LiquiefiedParams::scientificColorScheme);

ImGui::SetCursorPosY(10.0f);
ImGui::SetCursorPosX(725.0f);
ImGui::Checkbox("Activate Debugging (A) |", &Engine::LiquiefiedParams::activateDebugging);
AddVerticalBarDivider(500.0f);
}
ImGui::End();
}
Expand Down
1 change: 1 addition & 0 deletions Apps/Liquefied/LiquefiedInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Liq
ImVec2 _debugWindowSize = ImVec2(_debugWindowWidth,(float)Engine::WindowParams::HEIGHT);

void AddSideBar() const;
void AddVerticalBarDivider(float xpos) const;
void AddBufferBar() const;

public:
Expand Down
38 changes: 23 additions & 15 deletions Engine/Application/GlobalParams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,25 +154,33 @@ namespace Engine

enum Integrator
{
ForwardEuler = 0,
BackwardEuler = 1,
SemiLagrangian = 2
ForwardEuler = 0,
ModifiedForwardEuler = 1,
RungeKutta2 = 2,
SemiLagrangian = 3,
};

enum Visualization
{
Nothing = 0,
Greyscale = 1,
BlackBody = 2,
ParaView = 3
};

struct LiquiefiedParams
{
inline static constexpr uint32 SIMULATION_WIDTH = 150;
inline static constexpr uint32 SIMULATION_HEIGHT = 100;
inline static constexpr uint32 LIQUID_NUM_CELLS = SIMULATION_WIDTH * SIMULATION_HEIGHT;
inline static constexpr uint32 GAUSS_SEIDEL_ITERATIONS = 500;
inline static constexpr float GAUSS_SEIDEL_OVERRELAXATION = 1.9f;
inline static uint32 turbinePower = 2;
inline static bool visualizeSmoke = true;
inline static bool scientificColorScheme = false;
inline static bool pauseSimulation = true;
inline static bool resetSimulation = false;
inline static bool activateDebugging = false;
inline static Integrator integratorChoice = Integrator::ForwardEuler;
inline static constexpr uint32 SIMULATION_WIDTH = 150;
inline static constexpr uint32 SIMULATION_HEIGHT = 100;
inline static constexpr uint32 LIQUID_NUM_CELLS = SIMULATION_WIDTH * SIMULATION_HEIGHT;
inline static constexpr uint32 GAUSS_SEIDEL_ITERATIONS = 20;
inline static constexpr float GAUSS_SEIDEL_OVERRELAXATION = 1.9f;
inline static uint32 turbinePower = 50;
inline static bool pauseSimulation = true;
inline static bool resetSimulation = false;
inline static bool activateDebugging = false;
inline static Integrator integratorChoice = Integrator::SemiLagrangian;
inline static Visualization visualizationChoice = Visualization::Greyscale;
};

struct LiquefiedDebug
Expand Down
Loading

0 comments on commit bb040e9

Please sign in to comment.