diff --git a/Base/Constraint/PbdConstraints/imstkPbdConstantDensityConstraint.cpp b/Base/Constraint/PbdConstraints/imstkPbdConstantDensityConstraint.cpp index 81a3fb46f4afc02cad64f67044c688624419e33d..bbcb0c2a1052d4ad6926c88daffbd3df0520d3f5 100644 --- a/Base/Constraint/PbdConstraints/imstkPbdConstantDensityConstraint.cpp +++ b/Base/Constraint/PbdConstraints/imstkPbdConstantDensityConstraint.cpp @@ -24,7 +24,6 @@ limitations under the License. namespace imstk { - void PbdConstantDensityConstraint::initConstraint(PbdModel& model, const double k) { @@ -45,9 +44,9 @@ PbdConstantDensityConstraint::initConstraint(PbdModel& model, const double k) m_deltaPositions.resize(np); m_neighbors.resize(np * m_maxNumNeighbors); - m_xPosIndexes.resize(np); - m_yPosIndexes.resize(np); - m_zPosIndexes.resize(np); + m_xPosIndexes.resize(np); + m_yPosIndexes.resize(np); + m_zPosIndexes.resize(np); } bool @@ -61,14 +60,14 @@ PbdConstantDensityConstraint::solvePositionConstraint(PbdModel& model) //This loop should be replaced with parallellization /*for (int index = 0; index < np; index++) - { - PointTable(pos[index], index); - }*/ - for (int index = 0; index < np; index++) - { - //UpdateNeighbors(index, pos); - UpdateNeighborsBruteForce(pos[index], index, pos); - } + { + PointTable(pos[index], index); + }*/ + for (int index = 0; index < np; index++) + { + //UpdateNeighbors(index, pos); + UpdateNeighborsBruteForce(pos[index], index, pos); + } for (int index = 0; index < np; index++) { CalculateDensityEstimate(pos[index], index, pos); @@ -144,83 +143,93 @@ PbdConstantDensityConstraint::Length(const Vec3d &p1) inline void PbdConstantDensityConstraint::ClearNeighbors(const int &np) { - m_numNeighbors.clear(); - m_neighbors.clear(); - m_numNeighbors.resize(np); - m_neighbors.resize(np * m_maxNumNeighbors); + m_numNeighbors.clear(); + m_neighbors.clear(); + m_numNeighbors.resize(np); + m_neighbors.resize(np * m_maxNumNeighbors); } -inline void +inline void PbdConstantDensityConstraint::PointTable(const Vec3d &pi, const int &index) { - m_xPosIndexes[index] = (pi[0] - pi[0] * m_maxDist) / m_maxDist; - m_yPosIndexes[index] = (pi[1] - pi[1] * m_maxDist) / m_maxDist; - m_zPosIndexes[index] = (pi[2] - pi[2] * m_maxDist) / m_maxDist; + m_xPosIndexes[index] = (pi[0] - pi[0] * m_maxDist) / m_maxDist; + m_yPosIndexes[index] = (pi[1] - pi[1] * m_maxDist) / m_maxDist; + m_zPosIndexes[index] = (pi[2] - pi[2] * m_maxDist) / m_maxDist; } -inline void +inline void PbdConstantDensityConstraint::UpdateNeighbors(const int &index, const StdVectorOfVec3d &positions) { - int ip = m_xPosIndexes[index]; - int jp = m_yPosIndexes[index]; - int kp = m_zPosIndexes[index]; - - int np = m_zPosIndexes.size(); - int neighborCount = 0; - - int ibound = ip - 2; - if (ibound < 0) - ibound = 0; - int jbound = jp - 2; - if (jbound < 0) - jbound = 0; - int kbound = kp - 2; - if (kbound < 0) - kbound = 0; - for (int i = 0; i < np; i++) - { - if (neighborCount >= m_maxNumNeighbors || i == index) - continue; - if (m_xPosIndexes[i] > ibound && m_xPosIndexes[i] < (ip + 2)) - { - if (m_yPosIndexes[i] > jbound && m_yPosIndexes[i] < (jp + 2)) - { - if (m_zPosIndexes[i] > kbound && m_zPosIndexes[i] < (kp + 2)) - { - m_neighbors[index * m_maxNumNeighbors + neighborCount] = i; - neighborCount++; - } - } - } - } - m_numNeighbors[index] = neighborCount; + int ip = m_xPosIndexes[index]; + int jp = m_yPosIndexes[index]; + int kp = m_zPosIndexes[index]; + + int np = m_zPosIndexes.size(); + int neighborCount = 0; + + int ibound = ip - 2; + if (ibound < 0) + { + ibound = 0; + } + int jbound = jp - 2; + if (jbound < 0) + { + jbound = 0; + } + int kbound = kp - 2; + if (kbound < 0) + { + kbound = 0; + } + for (int i = 0; i < np; i++) + { + if (neighborCount >= m_maxNumNeighbors || i == index) + { + continue; + } + if (m_xPosIndexes[i] > ibound && m_xPosIndexes[i] < (ip + 2)) + { + if (m_yPosIndexes[i] > jbound && m_yPosIndexes[i] < (jp + 2)) + { + if (m_zPosIndexes[i] > kbound && m_zPosIndexes[i] < (kp + 2)) + { + m_neighbors[index * m_maxNumNeighbors + neighborCount] = i; + neighborCount++; + } + } + } + } + m_numNeighbors[index] = neighborCount; } //brute Force -inline +inline void PbdConstantDensityConstraint::UpdateNeighborsBruteForce(const Vec3d &pi, const int &index, const StdVectorOfVec3d &positions) { - double neighborRadius = 2 * m_maxDist; - Vec3d r; - double rLength; - int neighborCount = 0; - //loop over all points - for (int j = 0; j < positions.size(); j++) - { - if (j != index) - { - if (neighborCount >= m_maxNumNeighbors) - continue; - r = pi - positions[j]; - rLength = Length(r); - if (rLength < neighborRadius) - { - m_neighbors[index * m_maxNumNeighbors + neighborCount] = j; - neighborCount++; - } - } - } - m_numNeighbors[index] = neighborCount; + double neighborRadius = 2 * m_maxDist; + Vec3d r; + double rLength; + int neighborCount = 0; + //loop over all points + for (int j = 0; j < positions.size(); j++) + { + if (j != index) + { + if (neighborCount >= m_maxNumNeighbors) + { + continue; + } + r = pi - positions[j]; + rLength = Length(r); + if (rLength < neighborRadius) + { + m_neighbors[index * m_maxNumNeighbors + neighborCount] = j; + neighborCount++; + } + } + } + m_numNeighbors[index] = neighborCount; } diff --git a/Base/Constraint/PbdConstraints/imstkPbdConstantDensityConstraint.h b/Base/Constraint/PbdConstraints/imstkPbdConstantDensityConstraint.h index 35bd739db5bccee827b0c487e71c119db601dc97..5e611d12ba054fb25761367807e0b491b2a2d041 100644 --- a/Base/Constraint/PbdConstraints/imstkPbdConstantDensityConstraint.h +++ b/Base/Constraint/PbdConstraints/imstkPbdConstantDensityConstraint.h @@ -56,9 +56,9 @@ private: double Length(const Vec3d &); void PointTable(const Vec3d &pi, const int &index); - void UpdateNeighbors(const int &index, const StdVectorOfVec3d &positions); - void UpdateNeighborsBruteForce(const Vec3d &pi, const int &index, const StdVectorOfVec3d &positions); - void ClearNeighbors(const int &np); + void UpdateNeighbors(const int &index, const StdVectorOfVec3d &positions); + void UpdateNeighborsBruteForce(const Vec3d &pi, const int &index, const StdVectorOfVec3d &positions); + void ClearNeighbors(const int &np); void CalculateDensityEstimate(const Vec3d &pi, const int &index, const StdVectorOfVec3d &positions); void CalculateLambdaScalingFactor(const Vec3d &pi, const int &index, const StdVectorOfVec3d &positions); void DeltaPosition(const Vec3d &pi, const int &index, const StdVectorOfVec3d &positions); @@ -77,9 +77,9 @@ private: std::vector<Vec3d> m_deltaPositions; ///> delta positions std::vector<int> m_neighbors; ///> index of neighbors std::vector<int> m_numNeighbors; ///> number of neighbors - std::vector<int> m_xPosIndexes; - std::vector<int> m_yPosIndexes; - std::vector<int> m_zPosIndexes; + std::vector<int> m_xPosIndexes; + std::vector<int> m_yPosIndexes; + std::vector<int> m_zPosIndexes; }; } diff --git a/Examples/Sandbox/main.cpp b/Examples/Sandbox/main.cpp index 135eb797b9689efb41a1fcc5bfce5f3523891bda..34aa6b38eb5842ea94a8b0adde75141035d8ea68 100644 --- a/Examples/Sandbox/main.cpp +++ b/Examples/Sandbox/main.cpp @@ -1840,214 +1840,214 @@ void testPbdCollision() void testPbdFluidBenchmarking() { - std::vector<int> nPointsList = { 5, 10, 20 }; - std::vector<int> cubeSizeList = { 1, 1, 2 }; - - int nPointsPerSide = 10; - double cubeLength = 1; - - auto sdk = std::make_shared<SimulationManager>(); - auto scene = sdk->createNewScene("PBDFluidBenchmarking"); - - scene->getCamera()->setPosition(0, 10.0, 25.0); - - //Create Mesh - imstk::StdVectorOfVec3d vertList; - int nPoints = pow(nPointsPerSide, 3); - const double spacing = cubeLength / nPointsPerSide; - - vertList.resize(nPoints); - for (int i = 0; i < nPointsPerSide; ++i) - { - for (int j = 0; j < nPointsPerSide; j++) - { - for (int k = 0; k < nPointsPerSide; k++) - { - vertList[i*nPointsPerSide*nPointsPerSide + j*nPointsPerSide + k] = Vec3d((double)i * spacing, (double)j * spacing, (double)k * spacing); - } - } - } - std::vector<imstk::SurfaceMesh::TriangleArray> triangles; - for (size_t i = 0; i < nPointsPerSide - 1; i++) - { - for (size_t j = 0; j < nPointsPerSide - 1; j++) - { - for (size_t k = 0; k < nPointsPerSide - 1; k++) - { - imstk::SurfaceMesh::TriangleArray tri[3]; - tri[0] = { { i*nPointsPerSide*nPointsPerSide + j*nPointsPerSide + k, i*nPointsPerSide*nPointsPerSide + (j + 1)*nPointsPerSide + k, (i + 1)*nPointsPerSide*nPointsPerSide + (j + 1)*nPointsPerSide + k } }; - tri[1] = { { i*nPointsPerSide*nPointsPerSide + j*nPointsPerSide + k, (i + 1)*nPointsPerSide*nPointsPerSide + j*nPointsPerSide + k, (i + 1)*nPointsPerSide*nPointsPerSide + (j + 1)*nPointsPerSide + k } }; - triangles.push_back(tri[0]); - triangles.push_back(tri[1]); - } - } - } - - auto cubeMeshColliding = std::make_shared<imstk::SurfaceMesh>(); - cubeMeshColliding->initialize(vertList, triangles); - auto cubeMeshVisual = std::make_shared<imstk::SurfaceMesh>(); - cubeMeshVisual->initialize(vertList, triangles); - auto cubeMeshPhysics = std::make_shared<imstk::SurfaceMesh>(); - cubeMeshPhysics->initialize(vertList, triangles); - - auto material1 = std::make_shared<RenderMaterial>(); - material1->setDisplayMode(RenderMaterial::DisplayMode::POINTS); - cubeMeshVisual->setRenderMaterial(material1); - - - auto cubeMapP2V = std::make_shared<imstk::OneToOneMap>(); - cubeMapP2V->setMaster(cubeMeshPhysics); - cubeMapP2V->setSlave(cubeMeshVisual); - cubeMapP2V->compute(); - - auto cubeMapP2C = std::make_shared<imstk::OneToOneMap>(); - cubeMapP2C->setMaster(cubeMeshPhysics); - cubeMapP2C->setSlave(cubeMeshColliding); - cubeMapP2C->compute(); - - auto cubeMapC2V = std::make_shared<imstk::OneToOneMap>(); - cubeMapC2V->setMaster(cubeMeshColliding); - cubeMapC2V->setSlave(cubeMeshVisual); - cubeMapC2V->compute(); - - auto cube = std::make_shared<PbdObject>("Cube"); - cube->setCollidingGeometry(cubeMeshColliding); - cube->setVisualGeometry(cubeMeshVisual); - cube->setPhysicsGeometry(cubeMeshPhysics); - cube->setPhysicsToCollidingMap(cubeMapP2C); - cube->setPhysicsToVisualMap(cubeMapP2V); - cube->setCollidingToVisualMap(cubeMapC2V); - - auto pbdModel = std::make_shared<PbdModel>(); - cube->setDynamicalModel(pbdModel); - - cube->initialize(/*Number of Constraints*/ 1, - /*Constraint configuration*/ "ConstantDensity 1.0 0.3", - /*Mass*/ 1.0, - /*Gravity*/ "0 -9.8 0", - /*TimeStep*/ 0.005, - /*FixedPoint*/ "", - /*NumberOfIterationInConstraintSolver*/ 2, - /*Proximity*/ 0.1, - /*Contact stiffness*/ 1.0); - - auto pbdSolver = std::make_shared<PbdSolver>(); - pbdSolver->setPbdObject(cube); - scene->addNonlinearSolver(pbdSolver); - - scene->addSceneObject(cube); - - // plane - double width = 40.0; - double height = 40.0; - int nRows = 2; - int nCols = 2; - vertList.resize(nRows*nCols); - const double dy = width / (double)(nCols - 1); - const double dx = height / (double)(nRows - 1); - for (int i = 0; i < nRows; ++i) - { - for (int j = 0; j < nCols; j++) - { - const double y = (double)dy*j; - const double x = (double)dx*i; - vertList[i*nCols + j] = Vec3d(x - 20, -0.5, y - 20); - } - } - - // c. Add connectivity data - triangles.clear(); - for (std::size_t i = 0; i < nRows - 1; ++i) - { - for (std::size_t j = 0; j < nCols - 1; j++) - { - imstk::SurfaceMesh::TriangleArray tri[2]; - tri[0] = { { i*nCols + j, i*nCols + j + 1, (i + 1)*nCols + j } }; - tri[1] = { { (i + 1)*nCols + j + 1, (i + 1)*nCols + j, i*nCols + j + 1 } }; - triangles.push_back(tri[0]); - triangles.push_back(tri[1]); - } - } - - auto floorMeshColliding = std::make_shared<imstk::SurfaceMesh>(); - floorMeshColliding->initialize(vertList, triangles); - auto floorMeshVisual = std::make_shared<imstk::SurfaceMesh>(); - floorMeshVisual->initialize(vertList, triangles); - auto floorMeshPhysics = std::make_shared<imstk::SurfaceMesh>(); - floorMeshPhysics->initialize(vertList, triangles); - - - auto floorMapP2V = std::make_shared<imstk::OneToOneMap>(); - floorMapP2V->setMaster(floorMeshPhysics); - floorMapP2V->setSlave(floorMeshVisual); - floorMapP2V->compute(); - - - auto floorMapP2C = std::make_shared<imstk::OneToOneMap>(); - floorMapP2C->setMaster(floorMeshPhysics); - floorMapP2C->setSlave(floorMeshColliding); - floorMapP2C->compute(); - - auto floorMapC2V = std::make_shared<imstk::OneToOneMap>(); - floorMapC2V->setMaster(floorMeshColliding); - floorMapC2V->setSlave(floorMeshVisual); - floorMapC2V->compute(); - - auto floor = std::make_shared<PbdObject>("Floor"); - floor->setCollidingGeometry(floorMeshColliding); - floor->setVisualGeometry(floorMeshVisual); - floor->setPhysicsGeometry(floorMeshPhysics); - floor->setPhysicsToCollidingMap(floorMapP2C); - floor->setPhysicsToVisualMap(floorMapP2V); - floor->setCollidingToVisualMap(floorMapC2V); - - auto pbdModel2 = std::make_shared<PbdModel>(); - floor->setDynamicalModel(pbdModel2); - - floor->initialize(/*Number of Constraints*/ 0, - /*Mass*/ 0.0, - /*Proximity*/ 0.1, - /*Contact stiffness*/ 1.0); - - auto pbdSolverfloor = std::make_shared<PbdSolver>(); - pbdSolverfloor->setPbdObject(floor); - scene->addNonlinearSolver(pbdSolverfloor); - - scene->addSceneObject(floor); - - // Collisions - auto colGraph = scene->getCollisionGraph(); - auto pair = std::make_shared<PbdInteractionPair>(PbdInteractionPair(cube, floor)); - pair->setNumberOfInterations(2); - - colGraph->addInteractionPair(pair); - - // Display UPS - auto ups = std::make_shared<UPSCounter>(); - auto sceneManager = sdk->getSceneManager("PBDFluidBenchmarking"); - sceneManager->setPreInitCallback([](Module* module) - { - LOG(INFO) << "-- Pre initialization of " << module->getName() << " module"; - }); - sceneManager->setPreUpdateCallback([&ups](Module* module) - { - ups->setStartPointOfUpdate(); - }); - sceneManager->setPostUpdateCallback([&ups](Module* module) - { - ups->setEndPointOfUpdate(); - std::cout << "\r-- " << module->getName() << " running at " - << ups->getUPS() << " ups " << std::flush; - }); - sceneManager->setPostCleanUpCallback([](Module* module) - { - LOG(INFO) << "\n-- Post cleanup of " << module->getName() << " module"; - }); + std::vector<int> nPointsList = { 5, 10, 20 }; + std::vector<int> cubeSizeList = { 1, 1, 2 }; + + int nPointsPerSide = 10; + double cubeLength = 1; + + auto sdk = std::make_shared<SimulationManager>(); + auto scene = sdk->createNewScene("PBDFluidBenchmarking"); + + scene->getCamera()->setPosition(0, 10.0, 25.0); + + //Create Mesh + imstk::StdVectorOfVec3d vertList; + int nPoints = pow(nPointsPerSide, 3); + const double spacing = cubeLength / nPointsPerSide; + + vertList.resize(nPoints); + for (int i = 0; i < nPointsPerSide; ++i) + { + for (int j = 0; j < nPointsPerSide; j++) + { + for (int k = 0; k < nPointsPerSide; k++) + { + vertList[i*nPointsPerSide*nPointsPerSide + j*nPointsPerSide + k] = Vec3d((double)i * spacing, (double)j * spacing, (double)k * spacing); + } + } + } + std::vector<imstk::SurfaceMesh::TriangleArray> triangles; + for (size_t i = 0; i < nPointsPerSide - 1; i++) + { + for (size_t j = 0; j < nPointsPerSide - 1; j++) + { + for (size_t k = 0; k < nPointsPerSide - 1; k++) + { + imstk::SurfaceMesh::TriangleArray tri[3]; + tri[0] = { { i*nPointsPerSide*nPointsPerSide + j*nPointsPerSide + k, i*nPointsPerSide*nPointsPerSide + (j + 1)*nPointsPerSide + k, (i + 1)*nPointsPerSide*nPointsPerSide + (j + 1)*nPointsPerSide + k } }; + tri[1] = { { i*nPointsPerSide*nPointsPerSide + j*nPointsPerSide + k, (i + 1)*nPointsPerSide*nPointsPerSide + j*nPointsPerSide + k, (i + 1)*nPointsPerSide*nPointsPerSide + (j + 1)*nPointsPerSide + k } }; + triangles.push_back(tri[0]); + triangles.push_back(tri[1]); + } + } + } + + auto cubeMeshColliding = std::make_shared<imstk::SurfaceMesh>(); + cubeMeshColliding->initialize(vertList, triangles); + auto cubeMeshVisual = std::make_shared<imstk::SurfaceMesh>(); + cubeMeshVisual->initialize(vertList, triangles); + auto cubeMeshPhysics = std::make_shared<imstk::SurfaceMesh>(); + cubeMeshPhysics->initialize(vertList, triangles); + + auto material1 = std::make_shared<RenderMaterial>(); + material1->setDisplayMode(RenderMaterial::DisplayMode::POINTS); + cubeMeshVisual->setRenderMaterial(material1); + + + auto cubeMapP2V = std::make_shared<imstk::OneToOneMap>(); + cubeMapP2V->setMaster(cubeMeshPhysics); + cubeMapP2V->setSlave(cubeMeshVisual); + cubeMapP2V->compute(); + + auto cubeMapP2C = std::make_shared<imstk::OneToOneMap>(); + cubeMapP2C->setMaster(cubeMeshPhysics); + cubeMapP2C->setSlave(cubeMeshColliding); + cubeMapP2C->compute(); + + auto cubeMapC2V = std::make_shared<imstk::OneToOneMap>(); + cubeMapC2V->setMaster(cubeMeshColliding); + cubeMapC2V->setSlave(cubeMeshVisual); + cubeMapC2V->compute(); + + auto cube = std::make_shared<PbdObject>("Cube"); + cube->setCollidingGeometry(cubeMeshColliding); + cube->setVisualGeometry(cubeMeshVisual); + cube->setPhysicsGeometry(cubeMeshPhysics); + cube->setPhysicsToCollidingMap(cubeMapP2C); + cube->setPhysicsToVisualMap(cubeMapP2V); + cube->setCollidingToVisualMap(cubeMapC2V); + + auto pbdModel = std::make_shared<PbdModel>(); + cube->setDynamicalModel(pbdModel); + + cube->initialize(/*Number of Constraints*/ 1, + /*Constraint configuration*/ "ConstantDensity 1.0 0.3", + /*Mass*/ 1.0, + /*Gravity*/ "0 -9.8 0", + /*TimeStep*/ 0.005, + /*FixedPoint*/ "", + /*NumberOfIterationInConstraintSolver*/ 2, + /*Proximity*/ 0.1, + /*Contact stiffness*/ 1.0); + + auto pbdSolver = std::make_shared<PbdSolver>(); + pbdSolver->setPbdObject(cube); + scene->addNonlinearSolver(pbdSolver); + + scene->addSceneObject(cube); + + // plane + double width = 40.0; + double height = 40.0; + int nRows = 2; + int nCols = 2; + vertList.resize(nRows*nCols); + const double dy = width / (double)(nCols - 1); + const double dx = height / (double)(nRows - 1); + for (int i = 0; i < nRows; ++i) + { + for (int j = 0; j < nCols; j++) + { + const double y = (double)dy*j; + const double x = (double)dx*i; + vertList[i*nCols + j] = Vec3d(x - 20, -0.5, y - 20); + } + } + + // c. Add connectivity data + triangles.clear(); + for (std::size_t i = 0; i < nRows - 1; ++i) + { + for (std::size_t j = 0; j < nCols - 1; j++) + { + imstk::SurfaceMesh::TriangleArray tri[2]; + tri[0] = { { i*nCols + j, i*nCols + j + 1, (i + 1)*nCols + j } }; + tri[1] = { { (i + 1)*nCols + j + 1, (i + 1)*nCols + j, i*nCols + j + 1 } }; + triangles.push_back(tri[0]); + triangles.push_back(tri[1]); + } + } + + auto floorMeshColliding = std::make_shared<imstk::SurfaceMesh>(); + floorMeshColliding->initialize(vertList, triangles); + auto floorMeshVisual = std::make_shared<imstk::SurfaceMesh>(); + floorMeshVisual->initialize(vertList, triangles); + auto floorMeshPhysics = std::make_shared<imstk::SurfaceMesh>(); + floorMeshPhysics->initialize(vertList, triangles); + + + auto floorMapP2V = std::make_shared<imstk::OneToOneMap>(); + floorMapP2V->setMaster(floorMeshPhysics); + floorMapP2V->setSlave(floorMeshVisual); + floorMapP2V->compute(); + + + auto floorMapP2C = std::make_shared<imstk::OneToOneMap>(); + floorMapP2C->setMaster(floorMeshPhysics); + floorMapP2C->setSlave(floorMeshColliding); + floorMapP2C->compute(); + + auto floorMapC2V = std::make_shared<imstk::OneToOneMap>(); + floorMapC2V->setMaster(floorMeshColliding); + floorMapC2V->setSlave(floorMeshVisual); + floorMapC2V->compute(); + + auto floor = std::make_shared<PbdObject>("Floor"); + floor->setCollidingGeometry(floorMeshColliding); + floor->setVisualGeometry(floorMeshVisual); + floor->setPhysicsGeometry(floorMeshPhysics); + floor->setPhysicsToCollidingMap(floorMapP2C); + floor->setPhysicsToVisualMap(floorMapP2V); + floor->setCollidingToVisualMap(floorMapC2V); + + auto pbdModel2 = std::make_shared<PbdModel>(); + floor->setDynamicalModel(pbdModel2); + + floor->initialize(/*Number of Constraints*/ 0, + /*Mass*/ 0.0, + /*Proximity*/ 0.1, + /*Contact stiffness*/ 1.0); + + auto pbdSolverfloor = std::make_shared<PbdSolver>(); + pbdSolverfloor->setPbdObject(floor); + scene->addNonlinearSolver(pbdSolverfloor); + + scene->addSceneObject(floor); + + // Collisions + auto colGraph = scene->getCollisionGraph(); + auto pair = std::make_shared<PbdInteractionPair>(PbdInteractionPair(cube, floor)); + pair->setNumberOfInterations(2); + + colGraph->addInteractionPair(pair); + + // Display UPS + auto ups = std::make_shared<UPSCounter>(); + auto sceneManager = sdk->getSceneManager("PBDFluidBenchmarking"); + sceneManager->setPreInitCallback([](Module* module) + { + LOG(INFO) << "-- Pre initialization of " << module->getName() << " module"; + }); + sceneManager->setPreUpdateCallback([&ups](Module* module) + { + ups->setStartPointOfUpdate(); + }); + sceneManager->setPostUpdateCallback([&ups](Module* module) + { + ups->setEndPointOfUpdate(); + std::cout << "\r-- " << module->getName() << " running at " + << ups->getUPS() << " ups " << std::flush; + }); + sceneManager->setPostCleanUpCallback([](Module* module) + { + LOG(INFO) << "\n-- Post cleanup of " << module->getName() << " module"; + }); scene->getCamera()->setPosition(0, 10.0, 10.0); - sdk->setCurrentScene(scene); - sdk->startSimulation(true); + sdk->setCurrentScene(scene); + sdk->startSimulation(true); } void testPbdFluid()