Skip to content

Commit 88271ac

Browse files
committed
Merge branch 'InteractiveComputerGraphics:master' into fix-macos
2 parents abb983d + 2f1cae8 commit 88271ac

File tree

303 files changed

+45749
-13500
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

303 files changed

+45749
-13500
lines changed

CMake/Common.cmake

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ set(CMAKE_MINSIZEREL_POSTFIX "_ms")
1010

1111
include(CMakeDependentOption)
1212

13+
1314
OPTION(USE_DOUBLE_PRECISION "Use double precision" OFF)
1415
if (USE_DOUBLE_PRECISION)
1516
add_definitions( -DUSE_DOUBLE)
@@ -18,11 +19,28 @@ endif (USE_DOUBLE_PRECISION)
1819

1920
cmake_dependent_option(USE_AVX "Use AVX" ON "NOT USE_DOUBLE_PRECISION" OFF)
2021
if (USE_AVX)
21-
message(STATUS "If your CPU does not support AVX or Accelerate, turn off the USE_AVX flag.")
22-
add_definitions(-DUSE_AVX)
22+
set(FOUND_ACCELERATE OFF)
23+
if (APPLE)
24+
find_library(ACCELERATE Accelerate)
25+
endif()
26+
if (ACCELERATE)
27+
set(FOUND_ACCELERATE ON)
28+
message(STATUS "Using Accelerate")
29+
link_libraries(${ACCELERATE})
30+
else()
31+
include(avx)
32+
set_avx_flags()
33+
if (FOUND_AVX2)
34+
message(STATUS "Using AVX2")
35+
endif()
36+
endif()
37+
if (FOUND_ACCELERATE OR FOUND_AVX2)
38+
set(FOUND_SIMD ON)
39+
add_definitions(-DUSE_AVX)
40+
endif()
2341
endif()
2442

25-
cmake_dependent_option(USE_PERFORMANCE_OPTIMIZATION "Optimize performance (higher memory consumption)" ON "USE_AVX" OFF)
43+
cmake_dependent_option(USE_PERFORMANCE_OPTIMIZATION "Optimize performance (higher memory consumption)" ON "FOUND_SIMD" OFF)
2644
if (USE_PERFORMANCE_OPTIMIZATION)
2745
add_definitions( -DUSE_PERFORMANCE_OPTIMIZATION)
2846
endif (USE_PERFORMANCE_OPTIMIZATION)
@@ -74,8 +92,8 @@ if (MSVC)
7492
set(CMAKE_CXX_FLAGS_RELEASE "/MD /MP /Ox /Ob2 /Oi /Ot /fp:fast /D NDEBUG")
7593
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MD /Zi /MP /Ox /Ob2 /Oi /Ot /fp:fast /D NDEBUG")
7694
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MP")
77-
if (USE_AVX)
78-
add_compile_options("/arch:AVX")
95+
if (FOUND_AVX2)
96+
add_compile_options(${AVX_FLAGS})
7997
endif()
8098
endif (MSVC)
8199

@@ -93,13 +111,8 @@ if (UNIX OR MINGW)
93111
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -DNDEBUG -march=native")
94112
endif ()
95113
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
96-
if (USE_AVX)
97-
if (APPLE)
98-
link_libraries("-framework Accelerate")
99-
else()
100-
add_compile_options("-mavx")
101-
add_compile_options("-mfma")
102-
endif()
114+
if (FOUND_AVX2)
115+
add_compile_options(${AVX_FLAGS})
103116
endif()
104117
endif (UNIX OR MINGW)
105118
if(MINGW)

CMake/SetUpExternalProjects.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ ExternalProject_Add(
4747
Ext_PBD
4848
PREFIX "${CMAKE_BINARY_DIR}/extern/PositionBasedDynamics"
4949
GIT_REPOSITORY https://github.com/ruberith/PositionBasedDynamics.git
50-
GIT_TAG "66081a7fe5b62a7e44553d49a7c3f12b38275544"
50+
GIT_TAG "3bdc9079b8354a8ee2c25c3d842f4e8c96077eb3"
5151
INSTALL_DIR ${ExternalInstallDir}/PositionBasedDynamics
5252
DEPENDS Ext_GenericParameters Ext_Discregrid
5353
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${EXT_CMAKE_BUILD_TYPE}
5454
-DCMAKE_INSTALL_PREFIX:PATH=${ExternalInstallDir}/PositionBasedDynamics
55-
-DPBD_NO_DEMOS:BOOL=1
55+
-DPBD_LIBS_ONLY:BOOL=1
5656
-DPBD_EXTERNALINSTALLDIR:PATH=${ExternalInstallDir}
5757
-DUSE_DOUBLE_PRECISION:BOOL=${USE_DOUBLE_PRECISION}
5858
-DGenericParameters_INCLUDE_DIR:PATH=${GENERICPARAMETERS_INCLUDE_DIR}

CMake/avx.cmake

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
macro(set_avx_flags)
2+
set(AVX_FLAGS)
3+
4+
include(CheckCXXSourceRuns)
5+
set(CMAKE_REQUIRED_FLAGS)
6+
7+
# AVX
8+
if(MSVC AND NOT MSVC_VERSION LESS 1600)
9+
set(CMAKE_REQUIRED_FLAGS "/arch:AVX")
10+
elseif(UNIX OR MINGW)
11+
set(CMAKE_REQUIRED_FLAGS "-mavx")
12+
endif()
13+
14+
check_cxx_source_runs("
15+
#include <immintrin.h>
16+
int main()
17+
{
18+
float v[8] = { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f };
19+
float r[8];
20+
__m256 first = _mm256_loadu_ps(v);
21+
__m256 second = _mm256_setr_ps(0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f, 0.5f);
22+
__m256 result = _mm256_add_ps(first, second);
23+
_mm256_storeu_ps(r, result);
24+
25+
for( int i = 0; i < 8; i++)
26+
if ((i+1)*1.0f+0.5f != r[i])
27+
return -1;
28+
return 0;
29+
}"
30+
FOUND_AVX)
31+
32+
# AVX2
33+
if(MSVC AND NOT MSVC_VERSION LESS 1800)
34+
set(CMAKE_REQUIRED_FLAGS "/arch:AVX2")
35+
elseif(UNIX OR MINGW)
36+
set(CMAKE_REQUIRED_FLAGS "-mavx2")
37+
endif()
38+
39+
check_cxx_source_runs("
40+
#include <immintrin.h>
41+
int main()
42+
{
43+
int v[8] = {10, 20, 30, 40, 50, 60, 70, 80};
44+
int r[8];
45+
__m256i first = _mm256_loadu_si256((__m256i*)v);
46+
__m256i second = _mm256_set_epi32(5, 5, 5, 5, 5, 5, 5, 5);
47+
__m256i result = _mm256_add_epi32(first, second);
48+
_mm256_storeu_si256((__m256i*)r, result);
49+
50+
for( int i = 0; i < 8; i++)
51+
if ((i+1)*10+5 != r[i])
52+
return -1;
53+
return 0;
54+
}"
55+
FOUND_AVX2)
56+
57+
# set compiler flags
58+
if (FOUND_AVX2)
59+
if(MSVC)
60+
set(AVX_FLAGS "/arch:AVX2")
61+
elseif(UNIX OR MINGW)
62+
set(AVX_FLAGS "-mavx2;-mfma")
63+
endif()
64+
elseif (FOUND_AVX)
65+
if(MSVC)
66+
set(AVX_FLAGS "/arch:AVX")
67+
elseif(UNIX OR MINGW)
68+
set(AVX_FLAGS "-mavx")
69+
endif()
70+
endif()
71+
endmacro()

CMakeLists.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@ add_subdirectory(extern/partio)
3131
add_subdirectory(extern/md5)
3232
add_subdirectory(extern/tinyexpr)
3333
if (NOT SPH_LIBS_ONLY)
34-
add_subdirectory(extern/AntTweakBar)
3534
add_subdirectory(extern/glfw)
36-
add_subdirectory(extern/imgui)
35+
if (USE_IMGUI)
36+
add_subdirectory(extern/imgui)
37+
else()
38+
add_subdirectory(extern/AntTweakBar)
39+
endif()
3740
if (USE_PYTHON_BINDINGS)
3841
add_subdirectory(extern/pybind)
3942
endif ()

Changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2.11.3
2+
- updated to Eigen 3.4.0
3+
- updated to PBD 2.0.1
4+
15
2.11.2
26
- fixed command line parameter evaluation
37
- updated documentation

SPlisHSPlasH/Elasticity/Elasticity_Kugelstadt2021.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,9 @@ void Elasticity_Kugelstadt2021::initFactorization(std::shared_ptr<Factorization>
629629
unsigned int row_index = 0;
630630
for (int i = 0; i < (int)numParticles; i++)
631631
{
632-
int particleIndex = group[i];
633-
const unsigned int i0 = m_current_to_initial_index[particleIndex];
632+
int particleIndex0 = group[i];
633+
const unsigned int i0 = particleIndex0;
634+
unsigned int particleIndex = m_initial_to_current_index[i0];
634635

635636
const double restVolumes_id = m_restVolumes[i];
636637

@@ -651,7 +652,7 @@ void Elasticity_Kugelstadt2021::initFactorization(std::shared_ptr<Factorization>
651652
for (unsigned int j = 0; j < numNeighbors; j++)
652653
{
653654
const unsigned int neighborIndex0 = m_initialNeighbors[i0][j];
654-
const unsigned int neighborIndex = m_initial_to_current_index[m_initialNeighbors[i0][j]];
655+
const unsigned int neighborIndex = m_initial_to_current_index[neighborIndex0];
655656
const Eigen::Vector3d xj0d = m_model->getPosition0(neighborIndex0).cast<double>();
656657

657658
const Eigen::Vector3d correctedKernelGradient = m_L[particleIndex].cast<double>() * sim->gradW((xi0d - xj0d).cast<Real>()).cast<double>();
@@ -680,7 +681,7 @@ void Elasticity_Kugelstadt2021::initFactorization(std::shared_ptr<Factorization>
680681
for (unsigned int k = 0; k < numNeighbors; k++)
681682
{
682683
const unsigned int kIndex0 = m_initialNeighbors[i0][k];
683-
const unsigned int kIndex = m_initial_to_current_index[m_initialNeighbors[i0][k]];
684+
const unsigned int kIndex = m_initial_to_current_index[kIndex0];
684685
const Eigen::Vector3d xk0d = m_model->getPosition0(kIndex0).cast<double>();
685686

686687
const Eigen::Vector3d correctedKernelGradientd = m_L[particleIndex].cast<double>() * sim->gradW((xi0d - xk0d).cast<Real>()).cast<double>();
@@ -810,6 +811,7 @@ void Elasticity_Kugelstadt2021::performNeighborhoodSearchSort()
810811
d.sort_field(&m_current_to_initial_index[0]);
811812
d.sort_field(&m_L[0]);
812813
d.sort_field(&m_restVolumes[0]);
814+
d.sort_field(&m_vDiff[0]);
813815

814816
for (unsigned int i = 0; i < numPart; i++)
815817
m_initial_to_current_index[m_current_to_initial_index[i]] = i;
@@ -845,9 +847,9 @@ void Elasticity_Kugelstadt2021::computeMatrixL()
845847
//////////////////////////////////////////////////////////////////////////
846848
for (unsigned int j = 0; j < numNeighbors; j++)
847849
{
848-
const unsigned int neighborIndex = m_initial_to_current_index[m_initialNeighbors[i0][j]];
849850
// get initial neighbor index considering the current particle order
850851
const unsigned int neighborIndex0 = m_initialNeighbors[i0][j];
852+
const unsigned int neighborIndex = m_initial_to_current_index[neighborIndex0];
851853

852854
const Vector3r &xj0 = m_model->getPosition0(neighborIndex0);
853855
const Vector3r xj_xi_0 = xj0 - xi0;
@@ -1002,7 +1004,7 @@ void Elasticity_Kugelstadt2021::rotationMatricesToAVXQuaternions()
10021004
{
10031005
const int count = std::min(numParticles - i * 8, 8);
10041006

1005-
// store the deformation gradient of 8 particles in avx vectors
1007+
// store the rotation matrices of 8 particles in avx vectors
10061008
int idx[8];
10071009
for (int j = 0; j < count; j++)
10081010
idx[j] = m_initial_to_current_index[group[8 * i + j]];
@@ -1011,9 +1013,9 @@ void Elasticity_Kugelstadt2021::rotationMatricesToAVXQuaternions()
10111013

10121014
Quaternionr q[8];
10131015
for (auto j = 0; j < count; j++)
1014-
q[j] = Quaternionr(m_rotations[idx[j]].transpose());
1016+
q[j] = Quaternionr(m_rotations[idx[j]]).normalized();
10151017
for (auto j = count; j < 8; j++)
1016-
q[j] = Quaternionr();
1018+
q[j] = Quaternionr(1,0,0,0);
10171019

10181020
Quaternion8f& q_avx = quats[i];
10191021
q_avx.set(q);
@@ -1128,9 +1130,9 @@ void Elasticity_Kugelstadt2021::computeRotations()
11281130
R3.store(r2.data());
11291131
for (auto j = 0; j < count; j++)
11301132
{
1131-
m_rotations[idx[j]].row(0) = r0[j];
1132-
m_rotations[idx[j]].row(1) = r1[j];
1133-
m_rotations[idx[j]].row(2) = r2[j];
1133+
m_rotations[idx[j]].col(0) = r0[j];
1134+
m_rotations[idx[j]].col(1) = r1[j];
1135+
m_rotations[idx[j]].col(2) = r2[j];
11341136
}
11351137
}
11361138
}
@@ -1588,9 +1590,9 @@ void Elasticity_Kugelstadt2021::computeRHS(VectorXr & rhs)
15881590
//const Real trace = RTF(0, 0) + RTF(1, 1) + RTF(2, 2) - 3.0;
15891591

15901592
// short form of: trace(R^T F - I)
1591-
const Real trace = m_rotations[i].col(0).dot(m_F[i].col(0)) +
1592-
m_rotations[i].col(1).dot(m_F[i].col(1)) +
1593-
m_rotations[i].col(2).dot(m_F[i].col(2)) - static_cast<Real>(3.0);
1593+
const Real trace = m_rotations[i].row(0).dot(m_F[i].col(0)) +
1594+
m_rotations[i].row(1).dot(m_F[i].col(1)) +
1595+
m_rotations[i].row(2).dot(m_F[i].col(2)) - static_cast<Real>(3.0);
15941596

15951597
m_stress[i] = m_lambda * trace;
15961598
}
@@ -2215,7 +2217,7 @@ void Elasticity_Kugelstadt2021::precomputeValues()
22152217
#pragma omp for schedule(static)
22162218
for (int i = 0; i < (int)numParticles; i++)
22172219
{
2218-
m_RL[i] = m_rotations[i] * m_L[i];
2220+
m_RL[i] = m_rotations[i].transpose() * m_L[i];
22192221
}
22202222
#pragma omp for schedule(static)
22212223
for (int i = 0; i < (int)numParticles; i++)

SPlisHSPlasH/Elasticity/Elasticity_Peer2018.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ namespace SPH
1010
{
1111
/** \brief This class implements the implicit SPH formulation for
1212
* incompressible linearly elastic solids introduced
13-
* by Peer et al. [PGBT17].
13+
* by Peer et al. [PGBT18].
1414
*
1515
* References:
16-
* - [PGBT17] Andreas Peer, Christoph Gissler, Stefan Band, and Matthias Teschner. An implicit SPH formulation for incompressible linearly elastic solids. Computer Graphics Forum, 2017. URL: http://dx.doi.org/10.1111/cgf.13317
16+
* - [PGBT18] Andreas Peer, Christoph Gissler, Stefan Band, and Matthias Teschner. An implicit SPH formulation for incompressible linearly elastic solids. Computer Graphics Forum, 2018. URL: http://dx.doi.org/10.1111/cgf.13317
1717
*/
1818
class Elasticity_Peer2018 : public ElasticityBase
1919
{

SPlisHSPlasH/FluidModel.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,13 @@ void FluidModel::setSurfaceTensionMethod(const unsigned int val)
493493
m_surfaceTension = nullptr;
494494

495495
m_surfaceTensionMethod = stm;
496-
int method_id = getValue<int>(FluidModel::SURFACE_TENSION_METHOD);
497496
for (unsigned int i = 0; i < stMethods.size(); i++)
498497
{
499-
if (stMethods[i].m_id == method_id)
498+
if (stMethods[i].m_id == m_surfaceTensionMethod)
499+
{
500500
m_surfaceTension = static_cast<SurfaceTensionBase*>(stMethods[i].m_creator(this));
501+
break;
502+
}
501503
}
502504

503505
if (m_surfaceTension != nullptr)
@@ -585,10 +587,9 @@ void FluidModel::setVorticityMethod(const unsigned int val)
585587

586588
m_vorticityMethod = vm;
587589

588-
int method_id = getValue<int>(FluidModel::VORTICITY_METHOD);
589590
for (unsigned int i = 0; i < vorticityMethods.size(); i++)
590591
{
591-
if (vorticityMethods[i].m_id == method_id)
592+
if (vorticityMethods[i].m_id == m_vorticityMethod)
592593
m_vorticity = static_cast<VorticityBase*>(vorticityMethods[i].m_creator(this));
593594
}
594595

@@ -630,10 +631,9 @@ void FluidModel::setDragMethod(const unsigned int val)
630631

631632
m_dragMethod = dm;
632633

633-
int method_id = getValue<int>(FluidModel::DRAG_METHOD);
634634
for (unsigned int i = 0; i < dragMethods.size(); i++)
635635
{
636-
if (dragMethods[i].m_id == method_id)
636+
if (dragMethods[i].m_id == m_dragMethod)
637637
m_drag = static_cast<DragBase*>(dragMethods[i].m_creator(this));
638638
}
639639

@@ -674,11 +674,9 @@ void FluidModel::setElasticityMethod(const unsigned int val)
674674
m_elasticity = nullptr;
675675

676676
m_elasticityMethod = em;
677-
678-
int method_id = getValue<int>(FluidModel::ELASTICITY_METHOD);
679677
for (unsigned int i = 0; i < elasticityMethods.size(); i++)
680678
{
681-
if (elasticityMethods[i].m_id == method_id)
679+
if (elasticityMethods[i].m_id == m_elasticityMethod)
682680
m_elasticity = static_cast<ElasticityBase*>(elasticityMethods[i].m_creator(this));
683681
}
684682

SPlisHSPlasH/RigidBodyObject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ namespace SPH
1919

2020
virtual bool isDynamic() const = 0;
2121
bool isAnimated() const { return m_isAnimated; }
22-
virtual void setIsAnimated(const bool b) { m_isAnimated = true; }
22+
virtual void setIsAnimated(const bool b) { m_isAnimated = b; }
2323

2424
virtual Real const getMass() const = 0;
2525
virtual Vector3r const& getPosition() const = 0;

SPlisHSPlasH/TimeStep.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,6 @@ void TimeStep::precomputeValues()
525525
{
526526
for (unsigned int pid = 0; pid < nFluids; pid++)
527527
{
528-
FluidModel* fm_neighbor = sim->getFluidModelFromPointSet(pid);
529528
const unsigned int maxN = sim->numberOfNeighbors(fluidModelIndex, pid, i);
530529

531530
// same phase
@@ -551,7 +550,7 @@ void TimeStep::precomputeValues()
551550
{
552551
const Vector3r& xi = model->getPosition(i);
553552
const Vector3f8 xi_avx(xi);
554-
unsigned int base = precomputed_indices[i];
553+
const unsigned int base = precomputed_indices[i];
555554
unsigned int idx = 0;
556555
forall_fluid_neighbors_avx(
557556
const Scalarf8 Vj_avx = convert_zero(fm_neighbor->getVolume(0), count);

0 commit comments

Comments
 (0)