Commit f78a2df8 authored by Sreekanth Arikatla's avatar Sreekanth Arikatla
Browse files

Merge branch 'FixModuleTest' into 'master'

Fix module test and refactor SPHFluid example

See merge request !328
parents c5c3ea08 265ecd83
Pipeline #139867 failed with stage
in 0 seconds
###########################################################################
#
# Copyright (c) Kitware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
project(Example-SPHFluid)
#-----------------------------------------------------------------------------
# Create executable
#-----------------------------------------------------------------------------
add_executable(${PROJECT_NAME}-BallDrop SPHFluid-BallDrop.cpp Fluid.cpp Solid.cpp Bunny.cpp)
add_executable(${PROJECT_NAME}-HighViscousity SPHFluid-HighViscousity.cpp Fluid.cpp Solid.cpp Bunny.cpp)
add_executable(${PROJECT_NAME}-BunnyShape SPHFluid-BunnyShape.cpp Fluid.cpp Solid.cpp Bunny.cpp)
# Add Example subdirectories
#-----------------------------------------------------------------------------
macro(listOfSubDir result curdir)
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
set(dirlist "")
foreach(child ${children})
if(IS_DIRECTORY ${curdir}/${child})
list(APPEND dirlist ${child})
endif()
endforeach()
set(${result} ${dirlist})
endmacro()
#-----------------------------------------------------------------------------
# Link libraries to executable
#-----------------------------------------------------------------------------
target_link_libraries(${PROJECT_NAME}-BallDrop SimulationManager)
target_link_libraries(${PROJECT_NAME}-HighViscousity SimulationManager)
target_link_libraries(${PROJECT_NAME}-BunnyShape SimulationManager)
listOfSubDir(subDirs ${CMAKE_CURRENT_SOURCE_DIR})
foreach(subdir ${subDirs})
add_subdirectory(${subdir})
endforeach()
#-----------------------------------------------------------------------------
# Add shaders
#-----------------------------------------------------------------------------
include(imstkCopyAndCompileShaders)
CopyAndCompileShaders()
#-----------------------------------------------------------------------------
# Associate external data
#-----------------------------------------------------------------------------
......@@ -89,21 +89,26 @@ StdVectorOfVec3d generateBoxShapeFluid(const double particleRadius)
return particles;
}
#if SCENE_ID == 3
StdVectorOfVec3d getBunny(); // Defined in Bunny.cpp
#endif
///
/// \brief Generate a bunny-shape fluid object
///
StdVectorOfVec3d generateBunnyShapeFluid(const double particleRadius)
{
LOG_IF(FATAL, (std::abs(particleRadius - 0.08) > 1e-6)) << "Particle radius for this scene must be 0.08";
StdVectorOfVec3d particles = getBunny();
StdVectorOfVec3d particles;
#if SCENE_ID == 3
particles = getBunny();
#endif
return particles;
}
std::shared_ptr<SPHObject> generateFluid(const std::shared_ptr<Scene>&scene, int sceneIdx, const double particleRadius)
std::shared_ptr<SPHObject> generateFluid(const std::shared_ptr<Scene>&scene, const double particleRadius)
{
StdVectorOfVec3d particles;
switch (sceneIdx)
switch (SCENE_ID)
{
case 1:
particles = generateSphereShapeFluid(particleRadius);
......@@ -141,7 +146,7 @@ std::shared_ptr<SPHObject> generateFluid(const std::shared_ptr<Scene>&scene, int
// configure model
auto sphParams = std::make_shared<SPHModelConfig>(particleRadius);
sphParams->m_bNormalizeDensity = true;
if (sceneIdx == 2) // highly viscous fluid
if (SCENE_ID == 2) // highly viscous fluid
{
sphParams->m_RatioKernelOverParticleRadius = 6.0;
sphParams->m_ViscosityFluid = 0.5;
......
###########################################################################
#
# Copyright (c) Kitware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
project(Example-SPHFluid-BallDrop)
#-----------------------------------------------------------------------------
# Create executable
#-----------------------------------------------------------------------------
add_executable(${PROJECT_NAME} SPHFluid-BallDrop.cpp)
#-----------------------------------------------------------------------------
# Link libraries to executable
#-----------------------------------------------------------------------------
target_link_libraries(${PROJECT_NAME} SimulationManager)
#-----------------------------------------------------------------------------
# Add shaders
#-----------------------------------------------------------------------------
include(imstkCopyAndCompileShaders)
CopyAndCompileShaders()
#-----------------------------------------------------------------------------
# Associate external data
#-----------------------------------------------------------------------------
......@@ -21,4 +21,4 @@
// Generate a fluid simulation example in with a sphere-shape fluid dropping onto the ground
#define SCENE_ID 1
#include "SPHFluidExample.hpp"
\ No newline at end of file
#include "../SPHFluidExample.hpp"
\ No newline at end of file
###########################################################################
#
# Copyright (c) Kitware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
project(Example-SPHFluid-BunnyShape)
#-----------------------------------------------------------------------------
# Create executable
#-----------------------------------------------------------------------------
add_executable(${PROJECT_NAME} SPHFluid-BunnyShape.cpp Bunny.cpp)
#-----------------------------------------------------------------------------
# Link libraries to executable
#-----------------------------------------------------------------------------
target_link_libraries(${PROJECT_NAME} SimulationManager)
#-----------------------------------------------------------------------------
# Add shaders
#-----------------------------------------------------------------------------
include(imstkCopyAndCompileShaders)
CopyAndCompileShaders()
#-----------------------------------------------------------------------------
# Associate external data
#-----------------------------------------------------------------------------
......@@ -21,4 +21,4 @@
// Generate a fluid simulation example in with a bunny-shape fluid dropping onto a box
#define SCENE_ID 3
#include "SPHFluidExample.hpp"
\ No newline at end of file
#include "../SPHFluidExample.hpp"
\ No newline at end of file
###########################################################################
#
# Copyright (c) Kitware, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0.txt
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
project(Example-SPHFluid-HighViscousity)
#-----------------------------------------------------------------------------
# Create executable
#-----------------------------------------------------------------------------
add_executable(${PROJECT_NAME} SPHFluid-HighViscousity.cpp)
#-----------------------------------------------------------------------------
# Link libraries to executable
#-----------------------------------------------------------------------------
target_link_libraries(${PROJECT_NAME} SimulationManager)
#-----------------------------------------------------------------------------
# Add shaders
#-----------------------------------------------------------------------------
include(imstkCopyAndCompileShaders)
CopyAndCompileShaders()
#-----------------------------------------------------------------------------
# Associate external data
#-----------------------------------------------------------------------------
......@@ -21,4 +21,4 @@
// Generate a fluid simulation example in with a box-shape of highly viscous fluid dropping onto the ground
#define SCENE_ID 2
#include "SPHFluidExample.hpp"
\ No newline at end of file
#include "../SPHFluidExample.hpp"
\ No newline at end of file
......@@ -27,10 +27,10 @@
#include "imstkPlane.h"
#include "imstkSphere.h"
using namespace imstk;
#include "Fluid.hpp"
#include "Solid.hpp"
std::shared_ptr<SPHObject> generateFluid(const std::shared_ptr<Scene>&scene, int sceneIdx, const double particleRadius);
std::vector<std::shared_ptr<CollidingObject>> generateSolids(const std::shared_ptr<Scene>& scene, int sceneIdx);
using namespace imstk;
///
/// \brief Usage: ./SPHFluid [threads=<num_threads>] [radius=<particle_radius>]
......@@ -77,8 +77,8 @@ int main(int argc, char* argv[])
auto scene = sdk->createNewScene("SPH Fluid");
// Generate fluid and solid objects
auto fluidObj = generateFluid(scene, SCENE_ID, particleRadius);
auto solids = generateSolids(scene, SCENE_ID);
auto fluidObj = generateFluid(scene, particleRadius);
auto solids = generateSolids(scene);
// Collision between fluid and solid objects
auto colGraph = scene->getCollisionGraph();
......
......@@ -227,9 +227,9 @@ std::vector<std::shared_ptr<CollidingObject>> generateSolidsScene3(const std::sh
return solids;
}
std::vector<std::shared_ptr<CollidingObject>> generateSolids(const std::shared_ptr<Scene>& scene, int sceneIdx)
std::vector<std::shared_ptr<CollidingObject>> generateSolids(const std::shared_ptr<Scene>& scene)
{
switch (sceneIdx)
switch (SCENE_ID)
{
case 1:
return generateSolidsScene1(scene);
......
......@@ -39,7 +39,7 @@ TetraToTetraCD::TetraToTetraCD(std::shared_ptr<TetrahedralMesh> meshA,
void
TetraToTetraCD::findCollisionsForMeshWithinHashTable(const std::shared_ptr<TetrahedralMesh> mesh, size_t idOffset)
{
const auto eps = MACHINE_PRECISION;
const auto eps = VERY_SMALL_EPSILON;
const double eps2 = 1e-10;
//tetrahedron belonging part of penetration type does not change
......
......@@ -135,14 +135,13 @@ TEST_F(imstkModuleTest, ControlModule)
ASSERT_EQ(m_module.getStatus(), ModuleStatus::INACTIVE);
ASSERT_FALSE(m_module.m_init);
ASSERT_FALSE(m_module.m_run);
ASSERT_FALSE(m_module.m_cleanup);
ASSERT_TRUE(m_module.m_cleanup);
auto t = std::thread([this] { m_module.start(); });
std::this_thread::sleep_for(std::chrono::milliseconds(50));
ASSERT_EQ(m_module.getStatus(), ModuleStatus::RUNNING);
ASSERT_TRUE(m_module.m_init);
ASSERT_TRUE(m_module.m_run);
ASSERT_FALSE(m_module.m_cleanup);
m_module.pause();
ASSERT_EQ(m_module.getStatus(), ModuleStatus::PAUSED);
......@@ -150,14 +149,12 @@ TEST_F(imstkModuleTest, ControlModule)
std::this_thread::sleep_for(std::chrono::milliseconds(50));
ASSERT_TRUE(m_module.m_init);
ASSERT_FALSE(m_module.m_run);
ASSERT_FALSE(m_module.m_cleanup);
m_module.run();
ASSERT_EQ(m_module.getStatus(), ModuleStatus::RUNNING);
std::this_thread::sleep_for(std::chrono::milliseconds(50));
ASSERT_TRUE(m_module.m_init);
ASSERT_TRUE(m_module.m_run);
ASSERT_FALSE(m_module.m_cleanup);
m_module.end();
ASSERT_EQ(m_module.getStatus(), ModuleStatus::INACTIVE);
......
......@@ -122,15 +122,15 @@ using AffineTransform3d = Eigen::Affine3d;
#define LN2 Real(0.693147180559945309417)
#define LN10 Real(2.30258509299404568402)
#define MAX_REAL std::numeric_limits<Real>::max()
#define MIN_REAL std::numeric_limits<Real>::min()
#define MACHINE_PRECISION std::numeric_limits<Real>::epsilon()
#define MAX_REAL std::numeric_limits<Real>::max()
#define MIN_REAL std::numeric_limits<Real>::min()
#define VERY_SMALL_EPSILON std::numeric_limits<Real>::epsilon()
#define MAX_D std::numeric_limits<double>::max()
#define MIN_D std::numeric_limits<double>::min()
#define MACHINE_PRECISION_D std::numeric_limits<double>::epsilon()
#define MAX_D std::numeric_limits<double>::max()
#define MIN_D std::numeric_limits<double>::min()
#define VERY_SMALL_EPSILON_D std::numeric_limits<double>::epsilon()
#define MAX_F std::numeric_limits<float>::max()
#define MIN_F std::numeric_limits<float>::min()
#define MACHINE_PRECISION_F std::numeric_limits<float>::epsilon()
#define MAX_F std::numeric_limits<float>::max()
#define MIN_F std::numeric_limits<float>::min()
#define VERY_SMALL_EPSILON_F std::numeric_limits<float>::epsilon()
} // end namespace imstk
......@@ -20,7 +20,7 @@
=========================================================================*/
#include "imstkModule.h"
#include "imstkMath.h"
#include "g3log/g3log.hpp"
namespace imstk
......@@ -65,7 +65,7 @@ Module::start()
{
// Short path to run module if loop delay = 0
// (updating as fast as possible)
if (m_loopDelay == 0)
if (m_loopDelay < VERY_SMALL_EPSILON_D)
{
if (m_preUpdateCallback)
{
......@@ -158,7 +158,7 @@ Module::end()
while (m_status != ModuleStatus::INACTIVE) {}
}
const ModuleStatus
ModuleStatus
Module::getStatus() const
{
return m_status.load();
......@@ -188,7 +188,7 @@ Module::setLoopDelay(const double milliseconds)
double Module::getFrequency() const
{
if (m_loopDelay == 0)
if (m_loopDelay < VERY_SMALL_EPSILON_D)
{
LOG(WARNING) << "Module::getFrequency warning: loop delay is set to 0ms, "
<< "therefore not regulated by a frequency. Returning 0.";
......@@ -206,7 +206,7 @@ Module::setFrequency(const double f)
<< "or equal to 0 to run the module in a closed loop.";
return;
}
if (f == 0)
if (f < VERY_SMALL_EPSILON_D)
{
m_loopDelay = 0;
return;
......
......@@ -62,7 +62,7 @@ public:
///
/// \brief Destructor
///
~Module() = default;
virtual ~Module() = default;
///
/// \brief Start the module
......@@ -94,7 +94,7 @@ public:
///
/// \brief Get the status of the module
///
const ModuleStatus getStatus() const;
ModuleStatus getStatus() const;
///
/// \brief Get the name of the module
......@@ -148,7 +148,7 @@ protected:
std::atomic<ModuleStatus> m_status {ModuleStatus::INACTIVE}; ///> Module status
std::string m_name; ///> Name of the module
double m_loopDelay; ///> Loop delay
double m_loopDelay = 0; ///> Loop delay
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment