Skip to content

Commit

Permalink
Added value monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Zang3th committed Apr 30, 2024
1 parent c812c02 commit da1af3f
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Apps/CellSim/CellSimInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace CS

// --- Profiling/Timing-Results
ImGui::Separator();
for(auto const& entry : Engine::Profiler::_results)
for(auto const& entry : Engine::Profiler::results)
{
ImGui::Text("%.3fms - %s", entry.second, entry.first);
}
Expand Down
2 changes: 1 addition & 1 deletion Apps/GreenWorld/GreenWorldInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace GW
// --- Profiling/Timing-Results
ImGui::NewLine();
ImGui::Separator();
for(auto const& entry : Engine::Profiler::_results)
for(auto const& entry : Engine::Profiler::results)
{
ImGui::Text("%.3fms - %s", entry.second, entry.first);
}
Expand Down
6 changes: 5 additions & 1 deletion Apps/Liquefied/LiquefiedApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,11 @@ namespace Liq
if(_physicsTimer->CheckElapsedAndReset())
{
//Add a horizontal turbine (initial velocity)
_fluidSimulator->AddHorizonalTurbine(1, 50, 50.0f);
_fluidSimulator->AddHorizonalTurbine(1, 48, (float)Engine::LiquiefiedParams::turbinePower);
_fluidSimulator->AddHorizonalTurbine(1, 49, (float)Engine::LiquiefiedParams::turbinePower);
_fluidSimulator->AddHorizonalTurbine(1, 50, (float)Engine::LiquiefiedParams::turbinePower);
_fluidSimulator->AddHorizonalTurbine(1, 51, (float)Engine::LiquiefiedParams::turbinePower);
_fluidSimulator->AddHorizonalTurbine(1, 52, (float)Engine::LiquiefiedParams::turbinePower);

//Run simulation timestep and visualize result
_fluidSimulator->TimeStep();
Expand Down
29 changes: 28 additions & 1 deletion Apps/Liquefied/LiquefiedInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,26 @@ namespace Liq
// --- Profiling/Timing-Results
ImGui::NewLine();
ImGui::Separator();
for(auto const& entry : Engine::Profiler::_results)
for(auto const& entry : Engine::Profiler::results)
{
ImGui::Text("%.3fms - %s", entry.second, entry.first);
}
ImGui::Separator();

// --- Numerical value monitoring
ImGui::NewLine();
ImGui::Separator();
CenterText("Numerical value monitoring");
ImGui::Separator();
ImGui::NewLine();
for(auto const& entry : Engine::Monitor::values)
{
ImGui::Text("\t%s (min): %5.3f", entry.first, entry.second.min);
ImGui::Text("\t%s (max): %5.3f", entry.first, entry.second.max);
ImGui::Text("\t%s (val): %5.3f", entry.first, entry.second.val);
ImGui::NewLine();
}
ImGui::Separator();
}
ImGui::End();
}
Expand Down Expand Up @@ -63,6 +78,18 @@ namespace Liq
{
Engine::LiquiefiedParams::resetSimulation = true;
}
ImGui::SameLine();
ImGui::Text(" |");
ImGui::SetCursorPosY(45.0f);
ImGui::SetCursorPosX(515.0f);
ImGui::Text("Turbine power:\t");
ImGui::SameLine();
ImGui::SetCursorPosY(45.0f);
ImGui::SetCursorPosX(640.0f);
ImGui::PushItemWidth(125.0f);
Input_u32("##Input1", &Engine::LiquiefiedParams::turbinePower, 10, 100, ImGuiInputTextFlags_CharsDecimal);
ImGui::SameLine();
ImGui::Text("|");
}
ImGui::End();
}
Expand Down
1 change: 1 addition & 0 deletions Engine/Application/GlobalParams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ namespace Engine
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 visualizeSmoke = true;
inline static bool scientificColorScheme = false;
inline static bool pauseSimulation = true;
Expand Down
37 changes: 37 additions & 0 deletions Engine/Core/Monitor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "Monitor.hpp"

namespace Engine
{
// ----- Public -----

void Monitor::MinMaxAvg(const char* name, const float value)
{
//Add new value if it's not already getting monitored
if(values.find(name) == values.end())
{
values[name] = {value, value, value};
return;
}

//Get current struct
MinMaxAvg_t valueStruct = values[name];

//Add min if it's less than current min
if(valueStruct.min > value)
valueStruct.min = value;
//Add max if it's more than current max
else if(valueStruct.max < value)
valueStruct.max = value;

//Add value
valueStruct.val = value;

//Assign new values
values[name] = valueStruct;
}

void Monitor::Reset()
{
values.clear();
}
}
19 changes: 19 additions & 0 deletions Engine/Core/Monitor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include "Types.hpp"

#include <map>

namespace Engine
{
class Monitor
{
public:
Monitor() = delete;

static void MinMaxAvg(const char* name, float value);
static void Reset();

inline static std::map<const char*, MinMaxAvg_t> values = std::map<const char*, MinMaxAvg_t>();
};
}
14 changes: 7 additions & 7 deletions Engine/Core/Profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ namespace Engine
: _scopeName(name)
{
//Check for new entry
if(_results.find(_scopeName) == _results.end())
_results[_scopeName] = 0.0f;
if(results.find(_scopeName) == results.end())
results[_scopeName] = 0.0f;

_startTime = std::chrono::high_resolution_clock::now();
}

Profiler::~Profiler()
{
auto endTime = std::chrono::high_resolution_clock::now();
const auto endTime = std::chrono::high_resolution_clock::now();

long long start = std::chrono::time_point_cast<std::chrono::microseconds>(_startTime).time_since_epoch().count();
long long end = std::chrono::time_point_cast<std::chrono::microseconds>(endTime).time_since_epoch().count();
const auto start = std::chrono::time_point_cast<std::chrono::microseconds>(_startTime).time_since_epoch().count();
const auto end = std::chrono::time_point_cast<std::chrono::microseconds>(endTime).time_since_epoch().count();

float duration = (float)(end - start) * 0.001f;
_results[_scopeName] = duration;
const float duration = (float)(end - start) * 0.001f;
results[_scopeName] = duration;
}
}
4 changes: 2 additions & 2 deletions Engine/Core/Profiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <chrono>
#include <map>
#include <string>

namespace Engine
{
Expand All @@ -17,6 +16,7 @@ namespace Engine
public:
explicit Profiler(const char* name);
~Profiler();
inline static std::map<const char*, float> _results = std::map<const char*, float>();

inline static std::map<const char*, float> results = std::map<const char*, float>();
};
}
7 changes: 7 additions & 0 deletions Engine/Core/Types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@ namespace Engine
#define COLOR_RED glm::vec3(1.0f, 0.0f, 0.0f)
#define COLOR_GREEN glm::vec3(0.0f, 1.0f, 0.0f)
#define COLOR_BLUE glm::vec3(0.0f, 0.0f, 1.0f)

typedef struct MinMaxAvg
{
float min;
float max;
float val;
} MinMaxAvg_t;
}
1 change: 1 addition & 0 deletions Engine/Engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "App.hpp"
#include "Utility.hpp"
#include "Timer.hpp"
#include "Monitor.hpp"

// ----- Resources and renderables -----
#include "ResourceManager.hpp"
Expand Down
15 changes: 10 additions & 5 deletions Engine/Physics/FluidSimulation/FluidSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,19 @@ namespace Engine
float divergence = _grid.u_At(x+1, y) - _grid.u_At(x, y) +
_grid.v_At(x, y+1) - _grid.v_At(x, y);

Monitor::MinMaxAvg("Divergence", divergence);

//Apply overrelaxation to speed up convergence
divergence *= OVERRELAX;

//Get the amount of border cells in the area
float rightNeighbor = _grid.s_At(x+1, y);
float leftNeighbor = _grid.s_At(x-1, y);
float upperNeigbor = _grid.s_At(x, y+1);
float lowerNeighbor = _grid.s_At(x, y-1);
const float rightNeighbor = _grid.s_At(x+1, y);
const float leftNeighbor = _grid.s_At(x-1, y);
const float upperNeigbor = _grid.s_At(x, y+1);
const float lowerNeighbor = _grid.s_At(x, y-1);

// Sum them up to later divide the divergence by the correct amount
float s_sum = rightNeighbor + leftNeighbor + upperNeigbor + lowerNeighbor;
const float s_sum = rightNeighbor + leftNeighbor + upperNeigbor + lowerNeighbor;

//Push all velocities out by the same amout to force incompressibility
_grid.u_At(x, y) += divergence * (leftNeighbor / s_sum);
Expand Down Expand Up @@ -100,9 +102,11 @@ namespace Engine

//u-component (horizontal advection)
_grid.u_temp_At(x, y) = ForwardEuler(dt, _grid.deltaX, _grid.u_At(x, y), _grid.u_At(x, y), _grid.u_At(x+1, y), _grid.u_At(x-1, y));
Monitor::MinMaxAvg("u-component", _grid.u_temp_At(x, y));

//v-component (vertical advection)
_grid.v_temp_At(x, y) = ForwardEuler(dt, _grid.deltaY, _grid.v_At(x, y), _grid.v_At(x, y), _grid.v_At(x, y+1), _grid.v_At(x, y-1));
Monitor::MinMaxAvg("v-component", _grid.v_temp_At(x, y));
}
}

Expand Down Expand Up @@ -172,6 +176,7 @@ namespace Engine
void FluidSimulator::Reset()
{
Init();
Monitor::Reset();
}

void FluidSimulator::AddHorizonalTurbine(const uint32 x, const uint32 y, const float power)
Expand Down
1 change: 1 addition & 0 deletions Engine/Physics/FluidSimulation/FluidSimulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "Window.hpp"
#include "GlobalParams.hpp"
#include "Monitor.hpp"

#include <cstring>

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ Nature scene with water rendering, normal mapped objects, and a particle system

2D Eulerian Fluid Simulation on the CPU.

![Liquefied](Res/Screenshots/Liquefied/Screenshot_Liq_004.png)
![Liquefied](Res/Screenshots/Liquefied/Screenshot_Liq_005.png)

## Building and compiling

Expand Down
Binary file added Res/Screenshots/Liquefied/Screenshot_Liq_005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit da1af3f

Please sign in to comment.