Skip to content

Commit

Permalink
Merge pull request #16 from frostsim/release/1.0.0
Browse files Browse the repository at this point in the history
master <- release/1.0.0
  • Loading branch information
jklae authored Oct 11, 2021
2 parents 74c5724 + cbcb31e commit 7b25859
Show file tree
Hide file tree
Showing 16 changed files with 1,631 additions and 208 deletions.
30 changes: 0 additions & 30 deletions .gitmessage

This file was deleted.

38 changes: 21 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.19.0)

# Set the project name
SET( PROJECT_NAME DXViewer )
SET( PROJECT_NAME EulerianFluids )
PROJECT(${PROJECT_NAME})

# Define character set as Unicode
add_definitions(-DUNICODE -D_UNICODE)

# Collect shader files
FILE( GLOB VS_SHD ${CMAKE_SOURCE_DIR}/shader/vertexShader.hlsl )
FILE( GLOB PS_SHD ${CMAKE_SOURCE_DIR}/shader/fragShader.hlsl )
# Set configuration types
Set(CMAKE_CONFIGURATION_TYPES Debug Release)

# Set the shader type of files
set_property(SOURCE ${VS_SHD} PROPERTY VS_SHADER_TYPE Vertex)
set_property(SOURCE ${PS_SHD} PROPERTY VS_SHADER_TYPE Pixel)
# Set the include/lib directory
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/ext/DXViewer/DXViewer-2.0.0/include)
LINK_DIRECTORIES(${CMAKE_SOURCE_DIR}/ext/DXViewer/DXViewer-2.0.0/lib)

# Set the header directory
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/ext/DXViewer/DXViewer-1.0.0/include)
# Copy DLLs
FILE(GLOB DLL ${CMAKE_SOURCE_DIR}/ext/DXViewer/DXViewer-2.0.0/bin/*.dll)
FILE(COPY ${DLL} DESTINATION ${CMAKE_BINARY_DIR})

# Copy CSOs
FILE(GLOB CSO ${CMAKE_SOURCE_DIR}/ext/DXViewer/DXViewer-2.0.0/*.cso)
FILE(COPY ${CSO} DESTINATION ${CMAKE_BINARY_DIR})

# Collect source files
FILE( GLOB SRC ${CMAKE_SOURCE_DIR}/ext/DXViewer/src/*.cpp
${CMAKE_SOURCE_DIR}/src/*.cpp)
FILE( GLOB HDR ${CMAKE_SOURCE_DIR}/ext/DXViewer/DXViewer-1.0.0/include/*.h
${CMAKE_SOURCE_DIR}/src/*.h)
FILE( GLOB SHD ${VS_SHD} ${PS_SHD} )

# Link Source files
ADD_EXECUTABLE( ${PROJECT_NAME} WIN32 ${SRC} ${HDR} ${SHD} )
FILE( GLOB SRC ${CMAKE_SOURCE_DIR}/src/*.cpp )
FILE( GLOB HDR ${CMAKE_SOURCE_DIR}/src/*.h )

# Link Source files ('WIN32' keyword is used for win32 project)
ADD_EXECUTABLE( ${PROJECT_NAME} WIN32 ${SRC} ${HDR} )

# Set 'Additional Dependencies'
SET(LIB $<$<CONFIG:DEBUG>:DXViewer.lib> $<$<CONFIG:RELEASE>:DXViewerRel.lib>)
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${LIB})
2 changes: 1 addition & 1 deletion ext/DXViewer
120 changes: 0 additions & 120 deletions src/AdhocSimulation.cpp

This file was deleted.

28 changes: 0 additions & 28 deletions src/AdhocSimulation.h

This file was deleted.

114 changes: 114 additions & 0 deletions src/EulerGasSim.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#include "EulerGasSim.h"

using namespace DirectX;
using namespace std;

EulerGasSim::EulerGasSim(float timeStep)
:GridFluidSim::GridFluidSim(timeStep)
{
}

EulerGasSim::~EulerGasSim()
{

}


void EulerGasSim::update()
{
_force();

_project();
_advect();
_project();

_updateParticlePos(_timeStep);
_paintGrid();
}


void EulerGasSim::_force()
{
_gridVelocity[_INDEX(5, 5)] = { 1.0f, 1.0f };
}

void EulerGasSim::_advect()
{
int N = _gridCount - 2;
float t0step = _timeStep * N;

float yMax = _gridPosition[_INDEX(0, N + 1)].y - 0.5f;
float yMin = _gridPosition[_INDEX(0, 0)].y + 0.5f;
float xMax = _gridPosition[_INDEX(N + 1, 0)].x - 0.5f;
float xMin = _gridPosition[_INDEX(0, 0)].x + 0.5f;

vector<XMFLOAT2> oldVelocity = _gridVelocity;

for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= N; j++)
{
XMFLOAT2 backPos =
XMFLOAT2(
_gridPosition[_INDEX(i, j)].x - t0step * oldVelocity[_INDEX(i, j)].x,
_gridPosition[_INDEX(i, j)].y - t0step * oldVelocity[_INDEX(i, j)].y
);
if (backPos.x > xMax) backPos.x = xMax;
else if (backPos.x < xMin) backPos.x = xMin;

if (backPos.y > yMax) backPos.y = yMax;
else if (backPos.y < yMin) backPos.y = yMin;


_gridVelocity[_INDEX(i, j)] = _velocityInterpolation(backPos, oldVelocity);
}
}
_setBoundary(_gridVelocity);
}

void EulerGasSim::_project()
{
int N = _gridCount - 2;
for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= N; j++)
{
_gridDivergence[_INDEX(i, j)] =
0.5f * (_gridVelocity[_INDEX(i + 1, j)].x - _gridVelocity[_INDEX(i - 1, j)].x
+ _gridVelocity[_INDEX(i, j + 1)].y - _gridVelocity[_INDEX(i, j - 1)].y) / N;
_gridPressure[_INDEX(i, j)] = 0.0f;
}
}

_setBoundary(_gridDivergence);
_setBoundary(_gridPressure);

for (int iter = 0; iter < 20; iter++)
{
for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= N; j++)
{
_gridPressure[_INDEX(i, j)] =
(
_gridDivergence[_INDEX(i, j)] -
(_gridPressure[_INDEX(i + 1, j)] + _gridPressure[_INDEX(i - 1, j)] +
_gridPressure[_INDEX(i, j + 1)] + _gridPressure[_INDEX(i, j - 1)])
) / -4.0f;
}

}
_setBoundary(_gridPressure);
}

for (int i = 1; i <= N; i++)
{
for (int j = 1; j <= N; j++)
{
_gridVelocity[_INDEX(i, j)].x -= (_gridPressure[_INDEX(i + 1, j)] - _gridPressure[_INDEX(i - 1, j)]) * 0.5f * N;
_gridVelocity[_INDEX(i, j)].y -= (_gridPressure[_INDEX(i, j + 1)] - _gridPressure[_INDEX(i, j - 1)]) * 0.5f * N;
}
}
_setBoundary(_gridVelocity);

}
18 changes: 18 additions & 0 deletions src/EulerGasSim.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#include "GridFluidSim.h"

class EulerGasSim : public GridFluidSim
{
public:
EulerGasSim(float timeStep);
~EulerGasSim() override;

void update() override;

private:

void _force();
void _advect();
void _project();
};

Loading

0 comments on commit 7b25859

Please sign in to comment.