Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ option(WITH_BOX2D_EXAMPLE "Build Box2D integration example" OFF)
option(WITH_BULLET_EXAMPLE "Build Bullet integration example (requires the BulletIntegration library)" OFF)
cmake_dependent_option(WITH_CUBEMAP_EXAMPLE "Build CubeMap example (requires some JPEG importer plugin)" OFF "NOT MAGNUM_TARGET_GLES" OFF)
option(WITH_DART_EXAMPLE "Build DART integration example (requires the DartIntegration library)" OFF)
option(WITH_FEMSIMULATION_EXAMPLE "Build Finite Element Method Simulation example (requires the ImGui integration and Eigen)" OFF)
option(WITH_FLUIDSIMULATION2D_EXAMPLE "Build 2D Fluid Simulation example (requires the ImGui integration)" OFF)
option(WITH_FLUIDSIMULATION3D_EXAMPLE "Build 3D Fluid Simulation example (requires the ImGui integration)" OFF)
option(WITH_IMGUI_EXAMPLE "Build ImGui example" OFF)
Expand Down
2 changes: 2 additions & 0 deletions doc/building-examples.dox
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ integration libraries, see @ref building-plugins, @ref building-integration and
not available in OpenGL ES.
- `WITH_DART_EXAMPLE` --- Build the @ref examples-dart example. Requires
the @ref DartIntegration library.
- `WITH_FEMSIMULATION_EXAMPLE` -- Build the @ref examples-femsimulation
example.
- `WITH_FLUIDSIMULATION3D_EXAMPLE` -- Build the @ref examples-fluidsimulation3d
example.
- `WITH_LEAPMOTION_EXAMPLE` --- Build the @ref examples-leapmotion example.
Expand Down
103 changes: 103 additions & 0 deletions doc/femsimulation.dox
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
This file is part of Magnum.

Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020 Vladimír Vondruš <mosra@centrum.cz>
2020 — Nghia Truong <nghiatruong.vn@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/

namespace Magnum {
/** @page examples-femsimulation Finite Element Method Simulation
@brief Finite Element Method Simulation example.
@m_since_{examples,2020,06}

@m_footernavigation

@image html femsimulation1.png width=400px
@image html femsimulation2.png width=400px

A Finite Element Method simulation using the technique proposed in the paper [Quasi-Newton Methods for Real-Time Simulation of Hyperelastic Materials](https://dl.acm.org/doi/10.1145/2990496).
With a L-BFGS updates, the method can accelerate the simulation significantly, producing a real-time frame rate even for relatively large tetrahedral meshes.
This example is heavily adopted from the [source code provided by the paper authors](https://github.com/ltt1598/Quasi-Newton-Methods-for-Real-time-Simulation-of-Hyperelastic-Materials).

After the simulation started, wind force will be added after 10 seconds. The wind parameters, along with other simulation parameters, can be changed at run time.

@section examples-femsimulation-controls Controls

- @m_class{m-label m-default} **mouse drag** rotates the view
- @m_class{m-label m-warning} **Shift** @m_class{m-label m-default} **mouse drag**
pans the view
- @m_class{m-label m-default} **H** shows / hides the overlay menu
- @m_class{m-label m-default} **S** toggle smooth camera navigation
- @m_class{m-label m-default} **R** resets the camera view
- @m_class{m-label m-default} **Space** starts/pauses the simulation
- @m_class{m-label m-default} **F5** resets the simulation

@section examples-femsimulation-credits Credits

This example was originally contributed by [Nghia Truong](https://github.com/ttnghia).

@m_class{m-block m-success}

@thirdparty This example makes use of the [Adobe Source Sans Pro](https://github.com/adobe-fonts/source-sans-pro)
font, licensed under @m_class{m-label m-success} **OFL 1.1**
([license text](https://github.com/adobe-fonts/source-sans-pro/blob/release/LICENSE.txt),
[choosealicense.com](https://choosealicense.com/licenses/ofl-1.1/)).
Attribution is required for public use.

@section examples-femsimulation-source Source

Full source code is linked below and also available in the
[magnum-examples GitHub repository](https://github.com/mosra/magnum-examples/tree/master/src/femsimulation).
This example depends on the @ref examples-arcball example for camera
navigation and @ref examples-fluidsimulation3d for wireframe grid rendering.
In addition, it also requires the @ref ImGuiIntegration and Eigen libraries which are not parts
of the core Magnum repository, see its documentation for usage instructions.

- @ref femsimulation/CMakeLists.txt "CMakeLists.txt"
- @ref femsimulation/Data/longbar.mesh "Data/longbar.mesh"
- @ref femsimulation/Data/squirrel.mesh "Data/squirrel.mesh"
- @ref femsimulation/FEMSimulationExample.cpp "FEMSimulationExample.cpp"
- @ref femsimulation/resources.conf "resources.conf"
- @ref femsimulation/Simulation/Constraints.cpp "Simulation/Constraints.cpp"
- @ref femsimulation/Simulation/Constraints.h "Simulation/Constraints.h"
- @ref femsimulation/Simulation/MathDefinitions.h "Simulation/MathDefinitions.h"
- @ref femsimulation/Simulation/Simulator.cpp "Simulation/Simulator.cpp"
- @ref femsimulation/Simulation/Simulator.h "Simulation/Simulator.h"
- @ref femsimulation/Simulation/TetMesh.cpp "Simulation/TetMesh.cpp"
- @ref femsimulation/Simulation/TetMesh.h "Simulation/TetMesh.h"


@example femsimulation/CMakeLists.txt @m_examplenavigation{examples-femsimulation,femsimulation/} @m_footernavigation
@example femsimulation/Data/longbar.mesh @m_examplenavigation{examples-femsimulation,femsimulation/} @m_footernavigation
@example femsimulation/Data/squirrel.mesh @m_examplenavigation{examples-femsimulation,femsimulation/} @m_footernavigation
@example femsimulation/FEMSimulationExample.cpp @m_examplenavigation{examples-femsimulation,femsimulation/} @m_footernavigation
@example femsimulation/resources.conf @m_examplenavigation{examples-femsimulation,femsimulation/} @m_footernavigation
@example femsimulation/Simulation/Constraints.cpp @m_examplenavigation{examples-femsimulation,femsimulation/} @m_footernavigation
@example femsimulation/Simulation/Constraints.h @m_examplenavigation{examples-femsimulation,femsimulation/} @m_footernavigation
@example femsimulation/Simulation/MathDefinitions.h @m_examplenavigation{examples-femsimulation,femsimulation/} @m_footernavigation
@example femsimulation/Simulation/Simulator.cpp @m_examplenavigation{examples-femsimulation,femsimulation/} @m_footernavigation
@example femsimulation/Simulation/Simulator.h @m_examplenavigation{examples-femsimulation,femsimulation/} @m_footernavigation
@example femsimulation/Simulation/TetMesh.cpp @m_examplenavigation{examples-femsimulation,femsimulation/} @m_footernavigation
@example femsimulation/Simulation/TetMesh.h @m_examplenavigation{examples-femsimulation,femsimulation/} @m_footernavigation

*/
}
Binary file added doc/femsimulation1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/femsimulation2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions package/ci/appveyor-desktop-gles.bat
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ cmake .. ^
-DWITH_BULLET_EXAMPLE=ON ^
-DWITH_CUBEMAP_EXAMPLE=OFF ^
-DWITH_DART_EXAMPLE=OFF ^
-DWITH_FEMSIMULATION_EXAMPLE=OFF ^
-DWITH_FLUIDSIMULATION2D_EXAMPLE=OFF ^
-DWITH_FLUIDSIMULATION3D_EXAMPLE=OFF ^
-DWITH_IMGUI_EXAMPLE=ON ^
Expand Down
1 change: 1 addition & 0 deletions package/ci/appveyor-desktop-mingw.bat
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ cmake .. ^
-DWITH_BULLET_EXAMPLE=ON ^
-DWITH_CUBEMAP_EXAMPLE=ON ^
-DWITH_DART_EXAMPLE=OFF ^
-DWITH_FEMSIMULATION_EXAMPLE=ON ^
-DWITH_FLUIDSIMULATION2D_EXAMPLE=ON ^
-DWITH_FLUIDSIMULATION3D_EXAMPLE=ON ^
-DWITH_IMGUI_EXAMPLE=ON ^
Expand Down
1 change: 1 addition & 0 deletions package/ci/appveyor-desktop.bat
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ cmake .. ^
-DWITH_BULLET_EXAMPLE=ON ^
-DWITH_CUBEMAP_EXAMPLE=ON ^
-DWITH_DART_EXAMPLE=OFF ^
-DWITH_FEMSIMULATION_EXAMPLE=ON ^
-DWITH_FLUIDSIMULATION2D_EXAMPLE=ON ^
-DWITH_FLUIDSIMULATION3D_EXAMPLE=ON ^
-DWITH_IMGUI_EXAMPLE=ON ^
Expand Down
1 change: 1 addition & 0 deletions package/ci/travis-desktop-gles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ cmake .. \
-DWITH_BULLET_EXAMPLE=ON \
-DWITH_CUBEMAP_EXAMPLE=OFF \
-DWITH_DART_EXAMPLE=OFF \
-DWITH_FEMSIMULATION_EXAMPLE=OFF \
-DWITH_FLUIDSIMULATION2D_EXAMPLE=OFF \
-DWITH_FLUIDSIMULATION3D_EXAMPLE=OFF \
-DWITH_IMGUI_EXAMPLE=ON \
Expand Down
1 change: 1 addition & 0 deletions package/ci/travis-desktop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ cmake .. \
-DWITH_BULLET_EXAMPLE=ON \
-DWITH_CUBEMAP_EXAMPLE=ON \
-DWITH_DART_EXAMPLE=$WITH_DART \
-DWITH_FEMSIMULATION_EXAMPLE=ON \
-DWITH_FLUIDSIMULATION2D_EXAMPLE=ON \
-DWITH_FLUIDSIMULATION3D_EXAMPLE=ON \
-DWITH_IMGUI_EXAMPLE=ON \
Expand Down
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ if(WITH_DART_EXAMPLE)
add_subdirectory(dart)
endif()

if(WITH_FEMSIMULATION_EXAMPLE)
add_subdirectory(femsimulation)
endif()

if(WITH_FLUIDSIMULATION2D_EXAMPLE)
add_subdirectory(fluidsimulation2d)
endif()
Expand Down
92 changes: 92 additions & 0 deletions src/femsimulation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#
# This file is part of Magnum.
#
# Original authors — credit is appreciated but not required:
#
# 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 —
# Vladimír Vondruš <mosra@centrum.cz>
# 2020 — Nghia Truong <nghiatruong.vn@gmail.com>
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or distribute
# this software, either in source code form or as a compiled binary, for any
# purpose, commercial or non-commercial, and by any means.
#
# In jurisdictions that recognize copyright laws, the author or authors of
# this software dedicate any and all copyright interest in the software to
# the public domain. We make this dedication for the benefit of the public
# at large and to the detriment of our heirs and successors. We intend this
# dedication to be an overt act of relinquishment in perpetuity of all
# present and future rights to this software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#

cmake_minimum_required(VERSION 3.4)

project(FEMSimulationExample CXX)

# Add module path in case this is project root
if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/../../modules/" ${CMAKE_MODULE_PATH})
endif()

find_package(Corrade REQUIRED Main)
find_package(Magnum REQUIRED
DebugTools
GL
MeshTools
Primitives
SceneGraph
Shaders
Sdl2Application)
find_package(MagnumIntegration REQUIRED ImGui)
find_package(Eigen3 REQUIRED NO_MODULE)

set_directory_properties(PROPERTIES CORRADE_USE_PEDANTIC_FLAGS ON)
corrade_add_resource(FEMSimulationExample_RESOURCES resources.conf)

add_executable(magnum-femsimulation WIN32
../arcball/ArcBall.cpp
../fluidsimulation3d/DrawableObjects/WireframeObjects.h
FEMSimulationExample.cpp
Simulation/Constraints.cpp
Simulation/Constraints.h
Simulation/MathDefinitions.h
Simulation/Simulator.cpp
Simulation/Simulator.h
Simulation/TetMesh.cpp
Simulation/TetMesh.h
${FEMSimulationExample_RESOURCES}
)

# Need this to access WireframeGrid
include_directories(../fluidsimulation3d)

target_link_libraries(magnum-femsimulation PRIVATE
Corrade::Main
Magnum::Application
Magnum::DebugTools
Magnum::GL
Magnum::Magnum
Magnum::MeshTools
Magnum::Primitives
Magnum::SceneGraph
Magnum::Shaders
MagnumIntegration::ImGui
Eigen3::Eigen)

target_include_directories(magnum-femsimulation PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR})

install(TARGETS magnum-femsimulation DESTINATION ${MAGNUM_BINARY_INSTALL_DIR})

# Make the executable a default target to build & run in Visual Studio
set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT magnum-femsimulation)
Loading