Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2b9157a
initial window and geo
austinEng Feb 28, 2016
755c068
update config for linux
austinEng Feb 28, 2016
92935f4
draw simple set of points
austinEng Feb 29, 2016
e907a72
broken box drawing
austinEng Feb 29, 2016
b0eb0e1
camera and collision drawing
austinEng Feb 29, 2016
844f63a
fixed box draw
austinEng Feb 29, 2016
7449a95
fixed jittering particles
austinEng Feb 29, 2016
e7635fe
readme
austinEng Feb 29, 2016
563caf3
add comments
austinEng Feb 29, 2016
cf24824
basic but broken functionality; libs for linux
austinEng Mar 21, 2016
e625164
AntTweakBar working
austinEng Mar 21, 2016
abb982a
some bug fixes, still velocity transfer problems
austinEng Mar 22, 2016
24aa8f1
fixed more bugs
austinEng Mar 22, 2016
65d29ea
parallelization
austinEng Mar 22, 2016
39ff851
buggy attempt at being more memory efficient
austinEng Mar 23, 2016
bdb5950
some fixes
austinEng Mar 23, 2016
994783a
update readme
austinEng Mar 23, 2016
a2e27be
huh why is this crashing
austinEng Mar 26, 2016
5da849b
fixes and marker drawing
austinEng Mar 28, 2016
133f679
cleanup
austinEng Mar 29, 2016
762c4fc
RK2
austinEng Mar 29, 2016
001bd9f
velocity extrapolation
austinEng Mar 30, 2016
b6953db
pressure does something!
austinEng Apr 8, 2016
704f61e
fixed horrible indexing bug; but still not working
austinEng Apr 9, 2016
7655bf5
things actually work
austinEng Apr 10, 2016
3dbd1ff
failed attempt at building openvdb_points
austinEng Apr 11, 2016
d5eb384
image output
austinEng Apr 11, 2016
a000fe9
extrapolate problem
austinEng Apr 21, 2016
97a6dad
it works!
austinEng Apr 21, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ CMakeFiles
CMakeCache.txt
cmake_install.cmake
CMakeLists.txt.user
.idea
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "libs/glfw"]
path = libs/glfw
url = https://github.com/glfw/glfw.git
75 changes: 54 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
##################
# Thanda #
##################

# credit - base CMake config : Yining Karl Li , edited CMake config: Akshay Shah & Debanshu Singh

#name your project
project(Thanda)
project(FluidSolver)
cmake_minimum_required(VERSION 2.8)

# set creates a variable
Expand All @@ -16,6 +12,8 @@ include_directories(
${NUPARU}/src
)

set(CMAKE_INCLUDE_CURRENT_DIR ON)

# Add path for pre-compiled libraries here (we will later link them with our compiled source)
# Add Nuparu library to path for OSX, linux and windows
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Expand All @@ -33,10 +31,20 @@ set(GLFW_LIBRARY_DIR ${CMAKE_LIBRARY_PATH})
set(GLEW_LIBRARY_DIR ${CMAKE_LIBRARY_PATH})

# Use find_package & find_library to link with
find_package(OPENGL REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLEW)
find_library(GLFW_LIBRARY "glfw3" HINTS ${GLFW_LIBRARY_DIR})
find_library(JSONCPP "jsoncpp")
find_library(JSONCPP "jsoncpp" REQUIRED)
find_library(BOOST_IOSTREAMS boost_iostreams)
find_library(BOOST_SYSTEM boost_system)
find_library(OPENVDB openvdb REQUIRED)
find_library(OPENVDB_POINTS openvdb_points)
find_library(HALF Half REQUIRED)
find_library(TBB NAMES tbb tbbmalloc)
find_library(ZLIB z)
find_library(ANT AntTweakBar)

#Iex IexMath Imath IlmThread

add_definitions(
-DTW_STATIC
Expand All @@ -46,7 +54,20 @@ add_definitions(
-D_CRT_SECURE_NO_WARNINGS
)

set(CORE_LIBS ${GLFW_LIBRARY} ${GLUT_LIBRARY} ${GLEW_LIBRARY} ${JSONCPP} ${OPENGL_LIBRARY} )
set(CORE_LIBS
${GLFW_LIBRARY}
${GLUT_LIBRARY}
${GLEW_LIBRARY}
${JSONCPP}
${OPENGL_LIBRARY}
${BOOST_IOSTREAMS}
${BOOST_SYSTEM}
${OPENVDB}
${OPENVDB_POINTS}
${TBB}
${ZLIB}
${HALF}
${ANT})

# OSX-specific hacks/fixes
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
Expand All @@ -59,36 +80,48 @@ endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

# Linux specific hacks/fixes
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lX11 -lXxf86vm -lXrandr -lpthread -lXi")
set(CORE_LIBS ${CORE_LIBS} X11 Xxf86vm Xrandr pthread Xi)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lX11 -lXxf86vm -lXrandr -lpthread -lXi -lz")
endif()

# set compiler flags for c++11
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 -m64 -msse2 -w")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Ofast -m64 -msse2 -w")
elseif(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif()

if(MSVC)
set(COMPILER_FLAGS
set(COMPILER_FLAGS
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_C_FLAGS
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
)
endif()

# Add source files you want to compile (.cpp)
set(CORE_SRC
src/main.cpp
src/camera/camera.cpp
src/viewer/viewer.cpp
src/fluidSolver/fluidSolver.cpp
src/scene/scene.cpp
src/geom/geom.cpp
)
main.cpp
core/display/InputHandler.cpp
core/display/InputHandler.h
core/display/Window.cpp
core/display/Window.h
core/fileIO/SceneLoader.cpp
core/fileIO/SceneLoader.h
core/geometry/Bound.cpp
core/geometry/Bound.h
core/geometry/Box.cpp
core/geometry/Box.h
core/geometry/Geo.cpp
core/geometry/Geo.h
core/geometry/GeoObject.h
core/solver/FluidSolver.cpp
core/solver/FluidSolver.h
core/util/math.h
core/display/shaders/particle.frag.h core/display/shaders/particle.vert.h core/display/painters/ParticlesPainter.cpp core/display/painters/ParticlesPainter.h core/display/painters/Painter.cpp core/display/painters/Painter.h core/display/painters/BoxPainter.cpp core/display/painters/BoxPainter.h core/display/shaders/flat.vert.h core/display/shaders/flat.frag.h core/scenes/default.h core/camera/Camera.cpp core/camera/Camera.h core/solver/grid/Grid.cpp core/solver/grid/Grid.h core/solver/grid/MACGrid.cpp core/solver/grid/MACGrid.h core/solver/FluidParticle.h core/fileIO/ParticlesWriter.cpp core/fileIO/ParticlesWriter.h core/util/hacks.h core/display/painters/GridVectorAttributePainter.cpp core/display/painters/GridVectorAttributePainter.h core/display/shaders/gridAttr.geo.h core/util/flags.h core/display/painters/GridScalarAttributePainter.cpp core/display/painters/GridScalarAttributePainter.h core/display/shaders/gridScal.vert.h core/display/shaders/gridScal.frag.h)

add_executable(Thanda ${CORE_SRC})
target_link_libraries(Thanda ${CORE_LIBS})
add_executable(FluidSolver ${CORE_SRC})
target_link_libraries(FluidSolver ${CORE_LIBS})
59 changes: 51 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,59 @@
# CIS563-FluidSolver
(Credit : CIS565 README)
Fluid Solver
===========

Fluid Solver Submission guidelines:
First steps toward building a fluid solver.

## User Interface:

- If you have modified any of the CMakeLists.txt files at all (aside from the list of CORE_SRC), you must test that your project can build. Beware of any build issues.
* Middle mouse scroll to zoom in/out
* Middle mouse click and drag to orbit the camera
* SHIFT + middle mouse click and drag to track/slide

- Open a GitHub pull request so that we can see that you have finished. The title should be "Submission: YOUR NAME".
## Code Overview:

- In the body of the pull request, include a link to your repository.
### Scene Loading

- Submit on canvas with a direct link to your pull request on GitHub
Scenes are loaded by passing a path to the scene file as the first program argument.
It does a simple parsing with jsoncpp to create objects.

* containerDim: size and position of the container
* particleDim: size and position of initial fluid object
* resolution: number of grid divisions on the largest axis

And you're done!
#### AntTweakBar

I've added AntTweakBar, but haven't gotten around to having it do anything yet. I also don't have a MAC so I was unable to compile the libraries for it.

### Geometry

All geometry objects implement functions for collision detection. These come in a few different forms, allowing collision detection given next and previous points, given a point and distance tolerance, as well as given a point, ray, and timestep.
All geometry objects also have a bounding box which at the moment is used to assist in converting the geometry to particles.

### Fluid Solver

Particles are created by looping over all of the geometries' bounding boxes and checking if the point is contained within them.
For solving, particles are simply accelerated by a static gravity constant and then collisions are checked against the container geometry.
All information is stored in a temporary buffer which is swapped with the particle buffer at the end of the solve.

### Drawing

A Painter class is used to define the drawing behavior of various elements in the scene. Each sets up their own shaders on initialization and implement methods to draw their respective objects.
I found it much nicer to isolate my code this way so that I didn't have a billion gl calls in my geometry classes and a billion gl calls in my Window class.
Shaders are stored as char arrays in header files. I found that the easiest way to package them with my code.

The Window sets up a glfw window and a Singleton instance of InputHandler. glfw doesn't let you have non-static callback functions so I instead have callback functions to update the state of my static InputHandler which the Window can subscribe to.
From there, I can get the window/keyboard/mouse data and do the approriate camera calculations.

## Parallelization:

TBB is used heavily to parallelize calculations on the particles and grid. This can be toggled on/off by defining/undefining USETBB in <core/util/flags.h>.

For the default scene, the parallelized code computes each frame in an average of 0.0494588 seconds. Without TBB, this is 0.0768101 seconds.

## OpenVDB:

Currently, each frame is written out as "particles_{frame}.vdb" in the current directory

## Known Problems:

There seems to be an edge indexing problem in the attribute transfer from grid to particle
53 changes: 53 additions & 0 deletions core/camera/Camera.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Created by austin on 2/29/16.
//

#include "Camera.h"

Camera::Camera(int w, int h) :
zoom(35),
eye(glm::vec3(0,0,zoom)),
tgt(glm::vec3(0,0,0)),
width(w),
height(h),
fovy(45),
near_clip(0.001f),
far_clip(1000.f),
world_up(glm::vec3(0,1,0)),
look(tgt - eye),
right(glm::cross(look, world_up)),
up(glm::cross(right, look)),
rotation(glm::mat4(1.f)) {

// rotation = glm::rotate(rotation, -PI/6, glm::vec3(1,0,0));
// rotation = glm::rotate(rotation, PI/4, glm::vec3(0,1,0));

recomputeEye();
recompute();
}

glm::mat4 Camera::viewProj() {
return _viewProj;
}

void Camera::recompute() {
float aspect = (float)width/height;
look = glm::normalize(tgt - eye);
right = glm::cross(look, world_up);
up = glm::cross(right, look);

_viewProj = glm::perspective(fovy, aspect, near_clip, far_clip) * glm::lookAt(eye, tgt, up);
}

void Camera::resize(int w, int h) {
width = w;
height = h;
recompute();
}

void Camera::recomputeEye() {
eye = glm::vec3(rotation * glm::vec4(0,0,zoom,0)) + tgt;
look = glm::normalize(tgt - eye);
right = glm::normalize(glm::cross(look, up));
up = glm::normalize(glm::cross(right, look));
}
35 changes: 35 additions & 0 deletions core/camera/Camera.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Created by austin on 2/29/16.
//

#ifndef FLUIDSOLVER_CAMERA_H
#define FLUIDSOLVER_CAMERA_H

#include <core/util/math.h>

class Camera {
private:
glm::vec3 world_up;
public:
float zoom;
glm::vec3 eye;
glm::vec3 tgt;

Camera(int w, int h);
glm::mat4 viewProj();
void recomputeEye();
void recompute();
void resize(int w, int h);

glm::vec3 look, up, right;
int width, height;
float fovy, near_clip, far_clip;
glm::mat4 rotation;

private:

glm::mat4 _viewProj;
};


#endif //FLUIDSOLVER_CAMERA_H
Loading