Skip to content

Improved Euler Sim#2

Open
exMachina316 wants to merge 3 commits intomainfrom
flip_sim_devel
Open

Improved Euler Sim#2
exMachina316 wants to merge 3 commits intomainfrom
flip_sim_devel

Conversation

@exMachina316
Copy link
Owner

  • Optimized sim logic (not calling redundant functions)
  • Visualization for pressure/divergence

- Introduced methods for normalized pressure and divergence retrieval.
- Added pressure and divergence arrays to store simulation data.
- Updated project method to enforce mass conservation.
- Implemented shaders for pressure field visualization.
- Enhanced main loop to toggle pressure field rendering.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR optimizes the Euler fluid simulation by removing redundant operations and adds pressure/divergence field visualization. The changes include streamlining the velocity step algorithm, adding pressure field rendering capabilities, and introducing a new FLIP (Fluid Implicit Particle) simulation implementation.

  • Removed redundant noise injection and diffusion operations from the Euler simulation
  • Added pressure and divergence field visualization with new shaders and keyboard controls
  • Introduced complete FLIP simulation implementation with particle-based fluid dynamics

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
src/main.cpp Added pressure field visualization shaders, keyboard controls (P/D keys), and optimized rendering loop
src/fluid_sim.cpp Streamlined velocity step by removing noise injection and diffusion, added pressure tracking
src/flip_sim.cpp New FLIP simulation implementation with particle-based fluid dynamics
include/fluid_sim.h Added pressure/divergence field accessors and removed unused constants
include/flip_sim.h New header for FLIP simulation class and enums
CMakeLists.txt Added flip_sim.cpp to build targets
.clang-format Added Google-based code formatting configuration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

if (!success)
{
glGetShaderInfoLog(pressureFragmentShader, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::DENSITY_FRAGMENT::COMPILATION_FAILED\n"
Copy link

Copilot AI Sep 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message incorrectly identifies the shader type as 'DENSITY_FRAGMENT' when it should be 'PRESSURE_FRAGMENT' since this is handling pressure fragment shader compilation errors.

Suggested change
std::cout << "ERROR::SHADER::DENSITY_FRAGMENT::COMPILATION_FAILED\n"
std::cout << "ERROR::SHADER::PRESSURE_FRAGMENT::COMPILATION_FAILED\n"

Copilot uses AI. Check for mistakes.
Comment on lines +166 to +167
// Link density shaders
pressureShaderProgram = glCreateProgram();
Copy link

Copilot AI Sep 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment incorrectly states 'Link density shaders' when the code is actually linking pressure shaders. This should be 'Link pressure shaders'.

Copilot uses AI. Check for mistakes.
if (!success)
{
glGetProgramInfoLog(pressureShaderProgram, 512, NULL, infoLog);
std::cout << "ERROR::SHADER::DENSITY_PROGRAM::LINKING_FAILED\n"
Copy link

Copilot AI Sep 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message incorrectly identifies the program as 'DENSITY_PROGRAM' when it should be 'PRESSURE_PROGRAM' since this is handling pressure shader program linking errors.

Suggested change
std::cout << "ERROR::SHADER::DENSITY_PROGRAM::LINKING_FAILED\n"
std::cout << "ERROR::SHADER::PRESSURE_PROGRAM::LINKING_FAILED\n"

Copilot uses AI. Check for mistakes.
}
}

// Render density field if we have any vertices
Copy link

Copilot AI Sep 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment incorrectly states 'Render density field' when the code block is actually rendering the pressure field. This should be 'Render pressure field if we have any vertices'.

Suggested change
// Render density field if we have any vertices
// Render pressure field if we have any vertices

Copilot uses AI. Check for mistakes.
{
if (x >= 0 && x < width && y >= 0 && y < height)
{
return sqrt(pressure[x][y]/maxPressure);
Copy link

Copilot AI Sep 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Division by zero will occur if maxPressure is 0.0. This could happen when no pressure calculations have been performed yet or when all pressure values are zero.

Copilot uses AI. Check for mistakes.
{
if (x >= 0 && x < width && y >= 0 && y < height)
{
return sqrt(divergence[x][y]/maxDivergence);
Copy link

Copilot AI Sep 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Division by zero will occur if maxDivergence is 0.0. This could happen when no divergence calculations have been performed yet or when all divergence values are zero.

Suggested change
return sqrt(divergence[x][y]/maxDivergence);
if (maxDivergence > 0.0001f) // Avoid division by zero
{
return sqrt(divergence[x][y] / maxDivergence);
}

Copilot uses AI. Check for mistakes.
}

if (toGrid) {
int length = sizeof(f) / sizeof(float);
Copy link

Copilot AI Sep 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This calculation is incorrect. f is a pointer, so sizeof(f) returns the size of the pointer (typically 8 bytes), not the array size. This should use fNumCells_ instead of length.

Suggested change
int length = sizeof(f) / sizeof(float);
int length = fNumCells_;

Copilot uses AI. Check for mistakes.
void simulate(float dt, float gravity, float flipRatio,
int numPressureIters, int numParticleIters,
float overRelaxation, bool compensateDrift,
bool seperateParticles, float obstacleX, float obstacleY,
Copy link

Copilot AI Sep 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter name 'seperateParticles' is misspelled. It should be 'separateParticles'.

Suggested change
bool seperateParticles, float obstacleX, float obstacleY,
bool separateParticles, float obstacleX, float obstacleY,

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants