Skip to content

Commit

Permalink
Some small work on the fluid simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
Zang3th committed Apr 22, 2024
1 parent d3bec53 commit e0fe0c9
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Apps/Liquefied/LiquefiedInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace Liq

void LiquefiedInterface::AddBufferBar() const
{
ImGui::SetNextWindowBgAlpha(0.9f);
ImGui::SetNextWindowBgAlpha(_windowAlphaValue);
ImGui::SetNextWindowPos(_bufferBarPos, ImGuiCond_Always);
ImGui::SetNextWindowSize(_bufferBarSize);

Expand Down
49 changes: 39 additions & 10 deletions Engine/Physics/FluidSimulation/FluidSimulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,66 @@ namespace Engine
{
// ----- Private -----

/* Applies forces to the liquid - just gravity in our case */
void FluidSimulator::AddForces(float dt)
/* Applies forces to the liquid - just gravity in our case. */
void FluidSimulator::AddForces(const float dt)
{

for(uint32 x = 0; x < num_X; x++)
{
for(uint32 y = 0; y < num_Y; y++)
{
//Check for border cell
if(_s_staggered[x * num_Y + y] != 0.0f)
{
_v_staggered[x * num_Y + y] += _gravity * dt;
}
}
}
}

/* Projection calculates and applies the right amount of pressure to make the *
* velocity field divergence-free and also enforces solid wall boundary conditions. */
void FluidSimulator::Project(float dt)
void FluidSimulator::Project(const float dt)
{

}

/* Advection moves the quantity, or molecules, or particles, along the velocity field. */
void FluidSimulator::AdvectVelocity(float dt)
void FluidSimulator::AdvectVelocity(const float dt)
{

}

/* To visualize the flow, we store a density value at the center of each cell *
* and advect it like the velocity field. */
void FluidSimulator::AdvectSmoke(const float dt)
{

}

/* To visualize the flow, we store a density or dye value at the center of each cell *
* and advect it like the velocity field. */
void FluidSimulator::AdvectSmoke(float dt)
void FluidSimulator::Init()
{

//Initialize border cells
for(uint32 x = 0; x < num_X; x++)
{
for(uint32 y = 0; y < num_Y; y++)
{
float cellValue = 1.0f; //Fluid cell

if((x == 0) || (y == 0) || (x == num_X - 1) || (y == num_Y - 1))
{
cellValue = 0.0f; //Solid cell
}

_s_staggered[x * num_Y + y] = cellValue;
}
}
}

// ----- Public -----

FluidSimulator::FluidSimulator()
{

Init();
}

FluidSimulator::~FluidSimulator()
Expand Down
17 changes: 14 additions & 3 deletions Engine/Physics/FluidSimulation/FluidSimulator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,32 @@
#include "Window.hpp"
#include "GlobalParams.hpp"

#define at(x, y) ((x) * Liquiedfied::Params::SIMULATION_HEIGHT + (y))
#define num_X LiquiefiedParams::SIMULATION_WIDTH
#define num_Y LiquiefiedParams::SIMULATION_HEIGHT

namespace Engine
{
class FluidSimulator
{
private:
float _gravity = -9.81f;
float _velocityField[LiquiefiedParams::LIQUID_NUM_CELLS] = {0};
float _smokeField[LiquiefiedParams::LIQUID_NUM_CELLS] = {0};

//Horizontal u-component is sampled at the centers of the vertical cell faces.
float _u_staggered[LiquiefiedParams::LIQUID_NUM_CELLS] = {0.0f};

//Vertical v-component is sampled at the centers of the horizontal cell faces.
float _v_staggered[LiquiefiedParams::LIQUID_NUM_CELLS] = {0.0f};

//s-component gets set to 0 for border cells.
float _s_staggered[LiquiefiedParams::LIQUID_NUM_CELLS] = {0.0f};

float _smokeField[LiquiefiedParams::LIQUID_NUM_CELLS] = {0.0f};

void AddForces(float dt);
void Project(float dt);
void AdvectVelocity(float dt);
void AdvectSmoke(float dt);
void Init();

public:
FluidSimulator();
Expand Down

0 comments on commit e0fe0c9

Please sign in to comment.