diff --git a/CMakeLists.txt b/CMakeLists.txt index 8cd313f..3826c28 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,13 +7,19 @@ set(LIBIGL_EIGEN_VERSION 3.3.7 CACHE STRING "Eigen version") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -# libigl -option(LIBIGL_WITH_OPENGL "Use OpenGL" ON) -option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" ON) -option(LIBIGL_WITH_OPENGL_GLFW_IMGUI "Use ImGui" ON) -option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" ON) +# Detects whether this is a top-level project +get_directory_property(LIBSHELL_PARENT_DIR PARENT_DIRECTORY) +if(NOT LIBSHELL_PARENT_DIR) + set(LIBSHELL_TOPLEVEL_PROJECT ON) +else() + set(LIBSHELL_TOPLEVEL_PROJECT OFF) +endif() + +# Build tests +option(LIBSHELL_BUILD_EXEC "Build libshell executable" ${LIBSHELL_TOPLEVEL_PROJECT}) +option(LIBSHELL_BUILD_TESTS "Build libshell tests" ${LIBSHELL_TOPLEVEL_PROJECT}) -find_package(LIBIGL QUIET) +find_package(Eigen3 3.3 REQUIRED NO_MODULE) # Add your project files if(MSVC) @@ -22,17 +28,28 @@ endif() file(GLOB LIBFILES src/*.cpp src/SecondFundamentalForm/*.cpp src/MaterialModel/*.cpp) add_library(${PROJECT_NAME} STATIC ${LIBFILES}) -if(LIBIGL_FOUND) - target_link_libraries(${PROJECT_NAME} igl::core) -else() - target_include_directories(${PROJECT_NAME} PRIVATE "$ENV{EIGEN3_INCLUDE_DIR}" ) + +# install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_CURRENT_LIST_DIR}/lib) +target_include_directories(libshell PRIVATE "${EIGEN3_INCLUDE_DIR}") +target_include_directories(libshell PUBLIC "${CMAKE_CURRENT_LIST_DIR}/include") + +if(LIBSHELL_BUILD_EXEC) + find_package(LIBIGL QUIET) + + # libigl + option(LIBIGL_WITH_OPENGL "Use OpenGL" ON) + option(LIBIGL_WITH_OPENGL_GLFW "Use GLFW" ON) + option(LIBIGL_WITH_OPENGL_GLFW_IMGUI "Use ImGui" ON) + option(LIBIGL_WITH_VIEWER "Use OpenGL viewer" ON) + + file(GLOB EXAMPLEFILES example/*.cpp) + add_executable(example_${PROJECT_NAME} ${EXAMPLEFILES}) + target_link_libraries(example_${PROJECT_NAME} ${PROJECT_NAME} igl::core igl::opengl_glfw igl::opengl_glfw_imgui) endif() -install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_CURRENT_LIST_DIR}/lib) -file(GLOB EXAMPLEFILES example/*.cpp) -add_executable(example_${PROJECT_NAME} ${EXAMPLEFILES}) -target_link_libraries(example_${PROJECT_NAME} ${PROJECT_NAME} igl::core igl::opengl_glfw igl::opengl_glfw_imgui) -file(GLOB TESTFILES tests/*.cpp) -add_executable(tests_${PROJECT_NAME} ${TESTFILES}) -target_link_libraries(tests_${PROJECT_NAME} ${PROJECT_NAME} igl::core) +if(LIBSHELL_BUILD_TESTS) + file(GLOB TESTFILES tests/*.cpp) + add_executable(tests_${PROJECT_NAME} ${TESTFILES}) + target_link_libraries(tests_${PROJECT_NAME} ${PROJECT_NAME}) +endif() diff --git a/example/StaticSolve.h b/example/StaticSolve.h index 180458b..9542857 100644 --- a/example/StaticSolve.h +++ b/example/StaticSolve.h @@ -4,9 +4,9 @@ #include #include -#include "../include/MaterialModel.h" -#include "../include/MeshConnectivity.h" -#include "../include/ElasticShell.h" +#include "libshell/MaterialModel.h" +#include "libshell/MeshConnectivity.h" +#include "libshell/ElasticShell.h" template void takeOneStep(const LibShell::MeshConnectivity &mesh, diff --git a/example/main.cpp b/example/main.cpp index 7cd70ff..cfda6d0 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -1,17 +1,17 @@ -#include -#include "../include/MeshConnectivity.h" -#include "../include/ElasticShell.h" +#include "libshell/ElasticShell.h" +#include "libshell/MeshConnectivity.h" +#include "libshell/MidedgeAngleTanFormulation.h" +#include "libshell/MidedgeAngleSinFormulation.h" +#include "libshell/MidedgeAverageFormulation.h" +#include "libshell/StVKMaterial.h" +#include "libshell/TensionFieldStVKMaterial.h" +#include "libshell/NeoHookeanMaterial.h" +#include "libshell/RestState.h" #include "StaticSolve.h" +#include #include #include -#include -#include "../include/MidedgeAngleTanFormulation.h" -#include "../include/MidedgeAngleSinFormulation.h" -#include "../include/MidedgeAverageFormulation.h" -#include "../include/StVKMaterial.h" -#include "../include/TensionFieldStVKMaterial.h" -#include "../include/NeoHookeanMaterial.h" -#include "../include/RestState.h" +#include int numSteps; double thickness; diff --git a/include/BilayerStVKMaterial.h b/include/libshell/BilayerStVKMaterial.h similarity index 99% rename from include/BilayerStVKMaterial.h rename to include/libshell/BilayerStVKMaterial.h index d4df704..8e98d01 100644 --- a/include/BilayerStVKMaterial.h +++ b/include/libshell/BilayerStVKMaterial.h @@ -53,6 +53,6 @@ namespace LibShell { }; -}; +} #endif \ No newline at end of file diff --git a/include/ElasticShell.h b/include/libshell/ElasticShell.h similarity index 99% rename from include/ElasticShell.h rename to include/libshell/ElasticShell.h index ae4078b..73cf8c1 100644 --- a/include/ElasticShell.h +++ b/include/libshell/ElasticShell.h @@ -2,8 +2,8 @@ #define ELASTICSHELL_H #include -#include #include +#include #include "MaterialModel.h" namespace LibShell { @@ -70,5 +70,5 @@ namespace LibShell { ET_BENDING = 2 }; }; -}; +} #endif diff --git a/include/MaterialModel.h b/include/libshell/MaterialModel.h similarity index 99% rename from include/MaterialModel.h rename to include/libshell/MaterialModel.h index e3e03c1..7132cb5 100644 --- a/include/MaterialModel.h +++ b/include/libshell/MaterialModel.h @@ -29,6 +29,6 @@ namespace LibShell { Eigen::Matrix* derivative, // F(face, i), then the three vertices opposite F(face,i), then the extra DOFs on oppositeEdge(face,i) Eigen::Matrix* hessian) const = 0; }; -}; +} #endif \ No newline at end of file diff --git a/include/MeshConnectivity.h b/include/libshell/MeshConnectivity.h similarity index 99% rename from include/MeshConnectivity.h rename to include/libshell/MeshConnectivity.h index 298e11c..a2b9a90 100644 --- a/include/MeshConnectivity.h +++ b/include/libshell/MeshConnectivity.h @@ -41,6 +41,6 @@ namespace LibShell { Eigen::MatrixXi EF; Eigen::MatrixXi EOpp; }; -}; +} #endif \ No newline at end of file diff --git a/include/MidedgeAngleSinFormulation.h b/include/libshell/MidedgeAngleSinFormulation.h similarity index 99% rename from include/MidedgeAngleSinFormulation.h rename to include/libshell/MidedgeAngleSinFormulation.h index 15e04d5..b17156f 100644 --- a/include/MidedgeAngleSinFormulation.h +++ b/include/libshell/MidedgeAngleSinFormulation.h @@ -28,6 +28,6 @@ namespace LibShell { Eigen::Matrix* derivative, // F(face, i), then the three vertices opposite F(face,i), then the thetas on oppositeEdge(face,i) std::vector < Eigen::Matrix >* hessian); }; -}; +} #endif diff --git a/include/MidedgeAngleTanFormulation.h b/include/libshell/MidedgeAngleTanFormulation.h similarity index 99% rename from include/MidedgeAngleTanFormulation.h rename to include/libshell/MidedgeAngleTanFormulation.h index 4f1b0f6..485cd86 100644 --- a/include/MidedgeAngleTanFormulation.h +++ b/include/libshell/MidedgeAngleTanFormulation.h @@ -27,6 +27,6 @@ namespace LibShell { Eigen::Matrix* derivative, // F(face, i), then the three vertices opposite F(face,i), then the thetas on oppositeEdge(face,i) std::vector >* hessian); }; -}; +} #endif \ No newline at end of file diff --git a/include/MidedgeAverageFormulation.h b/include/libshell/MidedgeAverageFormulation.h similarity index 99% rename from include/MidedgeAverageFormulation.h rename to include/libshell/MidedgeAverageFormulation.h index 428efe0..f03f90e 100644 --- a/include/MidedgeAverageFormulation.h +++ b/include/libshell/MidedgeAverageFormulation.h @@ -23,6 +23,6 @@ namespace LibShell { Eigen::Matrix* derivative, // F(face, i), then the three vertices opposite F(face,i), then the thetas on oppositeEdge(face,i) std::vector >* hessian); }; -}; +} #endif \ No newline at end of file diff --git a/include/NeoHookeanMaterial.h b/include/libshell/NeoHookeanMaterial.h similarity index 99% rename from include/NeoHookeanMaterial.h rename to include/libshell/NeoHookeanMaterial.h index d2f779e..16c9371 100644 --- a/include/NeoHookeanMaterial.h +++ b/include/libshell/NeoHookeanMaterial.h @@ -45,6 +45,6 @@ namespace LibShell { }; -}; +} #endif diff --git a/include/RestState.h b/include/libshell/RestState.h similarity index 84% rename from include/RestState.h rename to include/libshell/RestState.h index e6bb03f..dbd8386 100644 --- a/include/RestState.h +++ b/include/libshell/RestState.h @@ -13,7 +13,7 @@ namespace LibShell { struct RestState { public: - virtual RestStateType type() { return RestStateType::RST_NONE; } + virtual RestStateType type() const { return RestStateType::RST_NONE; } }; /* Encodes the rest state information for an elastic monolayer. @@ -25,7 +25,7 @@ namespace LibShell { struct MonolayerRestState : public RestState { public: - virtual RestStateType type() { return RestStateType::RST_MONOLAYER; } + virtual RestStateType type() const { return RestStateType::RST_MONOLAYER; } std::vector thicknesses; std::vector abars; @@ -40,10 +40,10 @@ namespace LibShell { struct BilayerRestState : public RestState { public: - virtual RestStateType type() { return RestStateType::RST_BILAYER; } + virtual RestStateType type() const { return RestStateType::RST_BILAYER; } MonolayerRestState layers[2]; }; -}; +} #endif \ No newline at end of file diff --git a/include/StVKMaterial.h b/include/libshell/StVKMaterial.h similarity index 99% rename from include/StVKMaterial.h rename to include/libshell/StVKMaterial.h index be84481..b6a699e 100644 --- a/include/StVKMaterial.h +++ b/include/libshell/StVKMaterial.h @@ -45,6 +45,6 @@ namespace LibShell { }; -}; +} #endif \ No newline at end of file diff --git a/include/TensionFieldStVKMaterial.h b/include/libshell/TensionFieldStVKMaterial.h similarity index 99% rename from include/TensionFieldStVKMaterial.h rename to include/libshell/TensionFieldStVKMaterial.h index 8877235..3a6e769 100644 --- a/include/TensionFieldStVKMaterial.h +++ b/include/libshell/TensionFieldStVKMaterial.h @@ -45,6 +45,6 @@ namespace LibShell { Eigen::Matrix* derivative, // F(face, i), then the three vertices opposite F(face,i), then the extra DOFs on oppositeEdge(face,i) Eigen::Matrix* hessian) const; }; -}; +} #endif \ No newline at end of file diff --git a/src/ElasticShell.cpp b/src/ElasticShell.cpp index b59c13a..f31f1ba 100644 --- a/src/ElasticShell.cpp +++ b/src/ElasticShell.cpp @@ -1,19 +1,12 @@ -#include "../include/ElasticShell.h" -#include -#include -#include -#include +#include "libshell/ElasticShell.h" +#include "libshell/MaterialModel.h" +#include "libshell/MeshConnectivity.h" +#include "libshell/MidedgeAngleSinFormulation.h" +#include "libshell/MidedgeAngleTanFormulation.h" +#include "libshell/MidedgeAverageFormulation.h" +#include "libshell/RestState.h" #include "GeometryDerivatives.h" -#include -#include #include -#include -#include "../include/MeshConnectivity.h" -#include "../include/MaterialModel.h" -#include "../include/RestState.h" -#include "../include/MidedgeAngleSinFormulation.h" -#include "../include/MidedgeAngleTanFormulation.h" -#include "../include/MidedgeAverageFormulation.h" namespace LibShell { @@ -188,9 +181,9 @@ namespace LibShell { } } - // instantions + // instantiations template class ElasticShell; template class ElasticShell; template class ElasticShell; -}; \ No newline at end of file +} \ No newline at end of file diff --git a/src/GeometryDerivatives.cpp b/src/GeometryDerivatives.cpp index 3d0a2dd..48449ce 100644 --- a/src/GeometryDerivatives.cpp +++ b/src/GeometryDerivatives.cpp @@ -1,8 +1,5 @@ #include "GeometryDerivatives.h" -#include "../include/MeshConnectivity.h" -#include -#include -#include +#include "libshell/MeshConnectivity.h" namespace LibShell { @@ -230,4 +227,4 @@ namespace LibShell { return result; } -}; \ No newline at end of file +} \ No newline at end of file diff --git a/src/GeometryDerivatives.h b/src/GeometryDerivatives.h index e82cada..76e2c95 100644 --- a/src/GeometryDerivatives.h +++ b/src/GeometryDerivatives.h @@ -1,7 +1,7 @@ #ifndef GEOMETRYDERIVATIVES_H #define GEOMETRYDERIVATIVES_H -#include +#include #include namespace LibShell { @@ -52,8 +52,8 @@ namespace LibShell { const Eigen::MatrixXd& curPos, int face, Eigen::Matrix* derivative, // F(face, i) - std::vector >* hessian); + std::vector >* hessian); -}; +} #endif diff --git a/src/MaterialModel/BilayerStVKMaterial.cpp b/src/MaterialModel/BilayerStVKMaterial.cpp index e4de0a4..6542171 100644 --- a/src/MaterialModel/BilayerStVKMaterial.cpp +++ b/src/MaterialModel/BilayerStVKMaterial.cpp @@ -1,12 +1,12 @@ -#include "../../include/BilayerStVKMaterial.h" -#include "../../include/MeshConnectivity.h" -#include +#include "libshell/BilayerStVKMaterial.h" +#include "libshell/MeshConnectivity.h" +#include "libshell/MidedgeAngleSinFormulation.h" +#include "libshell/MidedgeAngleTanFormulation.h" +#include "libshell/MidedgeAverageFormulation.h" +#include "libshell/RestState.h" #include "../GeometryDerivatives.h" #include -#include "../../include/MidedgeAngleSinFormulation.h" -#include "../../include/MidedgeAngleTanFormulation.h" -#include "../../include/MidedgeAverageFormulation.h" -#include "../../include/RestState.h" +#include namespace LibShell { @@ -263,4 +263,4 @@ namespace LibShell { template class BilayerStVKMaterial; template class BilayerStVKMaterial; -}; \ No newline at end of file +} \ No newline at end of file diff --git a/src/MaterialModel/NeoHookeanMaterial.cpp b/src/MaterialModel/NeoHookeanMaterial.cpp index 6028a17..b3644c5 100644 --- a/src/MaterialModel/NeoHookeanMaterial.cpp +++ b/src/MaterialModel/NeoHookeanMaterial.cpp @@ -1,13 +1,12 @@ -#include "../../include/NeoHookeanMaterial.h" -#include "../../include/MeshConnectivity.h" -#include +#include "libshell/NeoHookeanMaterial.h" +#include "libshell/MeshConnectivity.h" +#include "libshell/MidedgeAngleSinFormulation.h" +#include "libshell/MidedgeAngleTanFormulation.h" +#include "libshell/MidedgeAverageFormulation.h" +#include "libshell/RestState.h" #include "../GeometryDerivatives.h" #include -#include -#include "../../include/MidedgeAngleSinFormulation.h" -#include "../../include/MidedgeAngleTanFormulation.h" -#include "../../include/MidedgeAverageFormulation.h" -#include "../../include/RestState.h" +#include namespace LibShell { @@ -425,4 +424,4 @@ namespace LibShell { template class NeoHookeanMaterial; template class NeoHookeanMaterial; -}; \ No newline at end of file +} \ No newline at end of file diff --git a/src/MaterialModel/StVKMaterial.cpp b/src/MaterialModel/StVKMaterial.cpp index 72c41d8..61a9b21 100644 --- a/src/MaterialModel/StVKMaterial.cpp +++ b/src/MaterialModel/StVKMaterial.cpp @@ -1,12 +1,12 @@ -#include "../../include/StVKMaterial.h" -#include "../../include/MeshConnectivity.h" -#include +#include "libshell/StVKMaterial.h" +#include "libshell/MeshConnectivity.h" +#include "libshell/MidedgeAngleSinFormulation.h" +#include "libshell/MidedgeAngleTanFormulation.h" +#include "libshell/MidedgeAverageFormulation.h" +#include "libshell/RestState.h" #include "../GeometryDerivatives.h" #include -#include "../../include/MidedgeAngleSinFormulation.h" -#include "../../include/MidedgeAngleTanFormulation.h" -#include "../../include/MidedgeAverageFormulation.h" -#include "../../include/RestState.h" +#include namespace LibShell { @@ -125,4 +125,4 @@ namespace LibShell { template class StVKMaterial; template class StVKMaterial; -}; \ No newline at end of file +} \ No newline at end of file diff --git a/src/MaterialModel/TensionFieldStVKMaterial.cpp b/src/MaterialModel/TensionFieldStVKMaterial.cpp index d75aef7..00f9517 100644 --- a/src/MaterialModel/TensionFieldStVKMaterial.cpp +++ b/src/MaterialModel/TensionFieldStVKMaterial.cpp @@ -1,12 +1,12 @@ -#include "../../include/TensionFieldStVKMaterial.h" -#include "../../include/MeshConnectivity.h" -#include +#include "libshell/TensionFieldStVKMaterial.h" +#include "libshell/MeshConnectivity.h" +#include "libshell/MidedgeAngleSinFormulation.h" +#include "libshell/MidedgeAngleTanFormulation.h" +#include "libshell/MidedgeAverageFormulation.h" +#include "libshell/RestState.h" #include "../GeometryDerivatives.h" #include -#include "../../include/MidedgeAngleSinFormulation.h" -#include "../../include/MidedgeAngleTanFormulation.h" -#include "../../include/MidedgeAverageFormulation.h" -#include "../../include/RestState.h" +#include namespace LibShell { @@ -197,4 +197,4 @@ namespace LibShell { template class TensionFieldStVKMaterial; template class TensionFieldStVKMaterial; -}; \ No newline at end of file +} \ No newline at end of file diff --git a/src/MeshConnectivity.cpp b/src/MeshConnectivity.cpp index 1a3c41d..eff465f 100644 --- a/src/MeshConnectivity.cpp +++ b/src/MeshConnectivity.cpp @@ -1,4 +1,4 @@ -#include "../include/MeshConnectivity.h" +#include "libshell/MeshConnectivity.h" #include #include @@ -129,4 +129,4 @@ namespace LibShell { return edgeOppositeVertex(edge, 1 - edgeorient); } -}; \ No newline at end of file +} \ No newline at end of file diff --git a/src/SecondFundamentalForm/MidedgeAngleSinFormulation.cpp b/src/SecondFundamentalForm/MidedgeAngleSinFormulation.cpp index 2585308..a2ad49e 100644 --- a/src/SecondFundamentalForm/MidedgeAngleSinFormulation.cpp +++ b/src/SecondFundamentalForm/MidedgeAngleSinFormulation.cpp @@ -1,9 +1,6 @@ -#include "../../include/MidedgeAngleSinFormulation.h" -#include +#include "libshell/MeshConnectivity.h" +#include "libshell/MidedgeAngleSinFormulation.h" #include "../GeometryDerivatives.h" -#include "../../include/MeshConnectivity.h" -#include -#include #include namespace LibShell { @@ -301,4 +298,4 @@ namespace LibShell { extraDOFs.setZero(); } -}; \ No newline at end of file +} \ No newline at end of file diff --git a/src/SecondFundamentalForm/MidedgeAngleTanFormulation.cpp b/src/SecondFundamentalForm/MidedgeAngleTanFormulation.cpp index cfe64c2..df294b7 100644 --- a/src/SecondFundamentalForm/MidedgeAngleTanFormulation.cpp +++ b/src/SecondFundamentalForm/MidedgeAngleTanFormulation.cpp @@ -1,9 +1,6 @@ -#include "../../include/MidedgeAngleTanFormulation.h" -#include +#include "libshell/MeshConnectivity.h" +#include "libshell/MidedgeAngleTanFormulation.h" #include "../GeometryDerivatives.h" -#include "../../include/MeshConnectivity.h" -#include -#include #include namespace LibShell { @@ -301,4 +298,4 @@ namespace LibShell { extraDOFs.setZero(); } -}; \ No newline at end of file +} \ No newline at end of file diff --git a/src/SecondFundamentalForm/MidedgeAverageFormulation.cpp b/src/SecondFundamentalForm/MidedgeAverageFormulation.cpp index 20d3316..bb5cee1 100644 --- a/src/SecondFundamentalForm/MidedgeAverageFormulation.cpp +++ b/src/SecondFundamentalForm/MidedgeAverageFormulation.cpp @@ -1,8 +1,6 @@ -#include "../../include/MidedgeAverageFormulation.h" +#include "libshell/MeshConnectivity.h" +#include "libshell/MidedgeAverageFormulation.h" #include "../GeometryDerivatives.h" -#include "../../include/MeshConnectivity.h" -#include -#include namespace LibShell { @@ -254,4 +252,4 @@ namespace LibShell { extraDOFs.resize(0); } -}; \ No newline at end of file +} \ No newline at end of file diff --git a/tests/main.cpp b/tests/main.cpp index 04e7f16..4dab883 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -1,18 +1,18 @@ +#include "findiff.h" +#include "libshell/BilayerStVKMaterial.h" +#include "libshell/ElasticShell.h" +#include "libshell/MeshConnectivity.h" +#include "libshell/MidedgeAngleTanFormulation.h" +#include "libshell/MidedgeAngleSinFormulation.h" +#include "libshell/MidedgeAverageFormulation.h" +#include "libshell/NeoHookeanMaterial.h" +#include "libshell/RestState.h" +#include "libshell/StVKMaterial.h" +#include "libshell/TensionFieldStVKMaterial.h" +#include #include #include #include -#include -#include "../include/MeshConnectivity.h" -#include "../include/ElasticShell.h" -#include "../include/MidedgeAngleTanFormulation.h" -#include "../include/MidedgeAngleSinFormulation.h" -#include "../include/MidedgeAverageFormulation.h" -#include "../include/StVKMaterial.h" -#include "../include/BilayerStVKMaterial.h" -#include "../include/TensionFieldStVKMaterial.h" -#include "../include/NeoHookeanMaterial.h" -#include "../include/RestState.h" -#include "findiff.h" #include std::default_random_engine rng;